Split up jamid.ts into multiple files

Change-Id: I792eceb81c033b8f17183de2686af1227982e779
diff --git a/server/src/jamid/jami-signal-interfaces.ts b/server/src/jamid/jami-signal-interfaces.ts
new file mode 100644
index 0000000..5c62482
--- /dev/null
+++ b/server/src/jamid/jami-signal-interfaces.ts
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2022 Savoir-faire Linux Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this program.  If not, see
+ * <https://www.gnu.org/licenses/>.
+ */
+export interface VolatileDetailsChanged {
+  accountId: string;
+  details: Map<string, string>;
+}
+
+export interface RegistrationStateChanged {
+  accountId: string;
+  state: string;
+  code: number;
+  details: string;
+}
+
+export interface NameRegistrationEnded {
+  accountId: string;
+  state: number;
+  username: string;
+}
+
+export interface RegisteredNameFound {
+  accountId: string;
+  state: number;
+  address: string;
+  username: string;
+}
diff --git a/server/src/jamid/jami-signal.ts b/server/src/jamid/jami-signal.ts
new file mode 100644
index 0000000..f76127b
--- /dev/null
+++ b/server/src/jamid/jami-signal.ts
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2022 Savoir-faire Linux Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this program.  If not, see
+ * <https://www.gnu.org/licenses/>.
+ */
+export enum JamiSignal {
+  // using DRing::ConfigurationSignal;
+  AccountsChanged = 'AccountsChanged',
+  AccountDetailsChanged = 'AccountDetailsChanged',
+  RegistrationStateChanged = 'RegistrationStateChanged',
+  ContactAdded = 'ContactAdded',
+  ContactRemoved = 'ContactRemoved',
+  ExportOnRingEnded = 'ExportOnRingEnded',
+  NameRegistrationEnded = 'NameRegistrationEnded',
+  RegisteredNameFound = 'RegisteredNameFound',
+  VolatileDetailsChanged = 'VolatileDetailsChanged',
+  KnownDevicesChanged = 'KnownDevicesChanged',
+  IncomingAccountMessage = 'IncomingAccountMessage',
+  AccountMessageStatusChanged = 'AccountMessageStatusChanged',
+
+  // using DRing::CallSignal;
+  StateChange = 'StateChange',
+  IncomingMessage = 'IncomingMessage',
+  IncomingCall = 'IncomingCall',
+  IncomingCallWithMedia = 'IncomingCallWithMedia',
+  MediaChangeRequested = 'MediaChangeRequested',
+
+  // using DRing::ConversationSignal;
+  ConversationLoaded = 'ConversationLoaded',
+  MessagesFound = 'MessagesFound',
+  MessageReceived = 'MessageReceived',
+  ConversationProfileUpdated = 'ConversationProfileUpdated',
+  ConversationRequestReceived = 'ConversationRequestReceived',
+  ConversationRequestDeclined = 'ConversationRequestDeclined',
+  ConversationReady = 'ConversationReady',
+  ConversationRemoved = 'ConversationRemoved',
+  ConversationMemberEvent = 'ConversationMemberEvent',
+  OnConversationError = 'OnConversationError',
+  OnConferenceInfosUpdated = 'OnConferenceInfosUpdated',
+}
diff --git a/server/src/jamid/jami-swig.ts b/server/src/jamid/jami-swig.ts
new file mode 100644
index 0000000..3f48fbc
--- /dev/null
+++ b/server/src/jamid/jami-swig.ts
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2022 Savoir-faire Linux Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this program.  If not, see
+ * <https://www.gnu.org/licenses/>.
+ */
+import { itMap, itRange, itToArr, itToMap } from '../utils.js';
+
+enum Bool {
+  False = 'false',
+  True = 'true',
+}
+
+interface SwigVec<T> {
+  size(): number;
+  get(i: number): T; // TODO: | undefined;
+}
+
+interface SwigMap<T, U> {
+  keys(): SwigVec<T>;
+  get(k: T): U; // TODO: | undefined;
+  set(k: T, v: U): void;
+}
+
+const swigVecToIt = <T>(v: SwigVec<T>) => itMap(itRange(0, v.size()), (i) => v.get(i));
+const swigMapToIt = <T, U>(m: SwigMap<T, U>) => itMap(swigVecToIt(m.keys()), (k): [T, U] => [k, m.get(k)]);
+
+// type IntVect = SwigVec<number>;
+// type UintVect = SwigVec<number>;
+// type FloatVect = SwigVec<number>;
+export type StringVect = SwigVec<string>;
+// type IntegerMap = SwigMap<string, number>;
+export type StringMap = SwigMap<string, string>;
+// type VectMap = SwigVec<StringMap>;
+// type Blob = SwigVec<number>;
+
+export const stringVectToArr = (sv: StringVect) => itToArr(swigVecToIt(sv));
+export const stringMapToMap = (sm: StringMap) => itToMap(swigMapToIt(sm));
+// const vectMapToJs = (vm: VectMap) => itToArr(itMap(swigVecToIt(vm), stringMapToMap));
+
+export interface JamiSwig {
+  init(args: Record<string, unknown>): void;
+
+  // IntVect(): IntVect;
+  // UintVect(): UintVect;
+  // FloatVect(): FloatVect;
+  // StringVect(): StringVect;
+  // IntegerMap(): IntegerMap
+  // StringMap(): StringMap;
+  // VectMap(): VectMap;
+  // IntegerMap(): IntegerMap;
+
+  addAccount(details: StringMap): string;
+  removeAccount(id: string): void;
+
+  getAccountList(): StringVect;
+
+  registerName(id: string, password: string, username: string): boolean;
+  lookupName(id: string, nameserver: string, username: string): boolean;
+  lookupAddress(id: string, nameserver: string, address: string): boolean;
+
+  getAccountDetails(id: string): StringMap;
+  setAccountDetails(id: string, details: StringMap): void;
+  setAccountActive(id: string, active: Bool): void;
+}
diff --git a/server/src/jamid.ts b/server/src/jamid/jamid.ts
similarity index 60%
rename from server/src/jamid.ts
rename to server/src/jamid/jamid.ts
index 34531cd..5583f5c 100644
--- a/server/src/jamid.ts
+++ b/server/src/jamid/jamid.ts
@@ -19,126 +19,15 @@
 import { filter, firstValueFrom, Subject } from 'rxjs';
 import { Service } from 'typedi';
 
-import { itMap, itRange, itToArr, itToMap, require } from './utils.js';
-
-enum Bool {
-  False = 'false',
-  True = 'true',
-}
-
-interface SwigVec<T> {
-  size(): number;
-  get(i: number): T; // TODO: | undefined;
-}
-
-interface SwigMap<T, U> {
-  keys(): SwigVec<T>;
-  get(k: T): U; // TODO: | undefined;
-  set(k: T, v: U): void;
-}
-
-const swigVecToIt = <T>(v: SwigVec<T>) => itMap(itRange(0, v.size()), (i) => v.get(i));
-const swigMapToIt = <T, U>(m: SwigMap<T, U>) => itMap(swigVecToIt(m.keys()), (k): [T, U] => [k, m.get(k)]);
-
-// type IntVect = SwigVec<number>;
-// type UintVect = SwigVec<number>;
-// type FloatVect = SwigVec<number>;
-type StringVect = SwigVec<string>;
-// type IntegerMap = SwigMap<string, number>;
-type StringMap = SwigMap<string, string>;
-// type VectMap = SwigVec<StringMap>;
-// type Blob = SwigVec<number>;
-
-const stringVectToArr = (sv: StringVect) => itToArr(swigVecToIt(sv));
-const stringMapToMap = (sm: StringMap) => itToMap(swigMapToIt(sm));
-// const vectMapToJs = (vm: VectMap) => itToArr(itMap(swigVecToIt(vm), stringMapToMap));
-
-interface JamiSwig {
-  init(args: Record<string, unknown>): void;
-
-  // IntVect(): IntVect;
-  // UintVect(): UintVect;
-  // FloatVect(): FloatVect;
-  // StringVect(): StringVect;
-  // IntegerMap(): IntegerMap
-  // StringMap(): StringMap;
-  // VectMap(): VectMap;
-  // IntegerMap(): IntegerMap;
-
-  addAccount(details: StringMap): string;
-  removeAccount(id: string): void;
-
-  getAccountList(): StringVect;
-
-  registerName(id: string, password: string, username: string): boolean;
-  lookupName(id: string, nameserver: string, username: string): boolean;
-  lookupAddress(id: string, nameserver: string, address: string): boolean;
-
-  getAccountDetails(id: string): StringMap;
-  setAccountDetails(id: string, details: StringMap): void;
-  setAccountActive(id: string, active: Bool): void;
-}
-
-enum JamiSignal {
-  // using DRing::ConfigurationSignal;
-  AccountsChanged = 'AccountsChanged',
-  AccountDetailsChanged = 'AccountDetailsChanged',
-  RegistrationStateChanged = 'RegistrationStateChanged',
-  ContactAdded = 'ContactAdded',
-  ContactRemoved = 'ContactRemoved',
-  ExportOnRingEnded = 'ExportOnRingEnded',
-  NameRegistrationEnded = 'NameRegistrationEnded',
-  RegisteredNameFound = 'RegisteredNameFound',
-  VolatileDetailsChanged = 'VolatileDetailsChanged',
-  KnownDevicesChanged = 'KnownDevicesChanged',
-  IncomingAccountMessage = 'IncomingAccountMessage',
-  AccountMessageStatusChanged = 'AccountMessageStatusChanged',
-
-  // using DRing::CallSignal;
-  StateChange = 'StateChange',
-  IncomingMessage = 'IncomingMessage',
-  IncomingCall = 'IncomingCall',
-  IncomingCallWithMedia = 'IncomingCallWithMedia',
-  MediaChangeRequested = 'MediaChangeRequested',
-
-  // using DRing::ConversationSignal;
-  ConversationLoaded = 'ConversationLoaded',
-  MessagesFound = 'MessagesFound',
-  MessageReceived = 'MessageReceived',
-  ConversationProfileUpdated = 'ConversationProfileUpdated',
-  ConversationRequestReceived = 'ConversationRequestReceived',
-  ConversationRequestDeclined = 'ConversationRequestDeclined',
-  ConversationReady = 'ConversationReady',
-  ConversationRemoved = 'ConversationRemoved',
-  ConversationMemberEvent = 'ConversationMemberEvent',
-  OnConversationError = 'OnConversationError',
-  OnConferenceInfosUpdated = 'OnConferenceInfosUpdated',
-}
-
-interface VolatileDetailsChanged {
-  accountId: string;
-  details: Map<string, string>;
-}
-
-interface RegistrationStateChanged {
-  accountId: string;
-  state: string;
-  code: number;
-  details: string;
-}
-
-interface NameRegistrationEnded {
-  accountId: string;
-  state: number;
-  username: string;
-}
-
-interface RegisteredNameFound {
-  accountId: string;
-  state: number;
-  address: string;
-  username: string;
-}
+import { itMap, require } from '../utils.js';
+import { JamiSignal } from './jami-signal.js';
+import {
+  NameRegistrationEnded,
+  RegisteredNameFound,
+  RegistrationStateChanged,
+  VolatileDetailsChanged,
+} from './jami-signal-interfaces.js';
+import { JamiSwig, StringMap, stringMapToMap, stringVectToArr } from './jami-swig.js';
 
 @Service()
 export class Jamid {
diff --git a/server/src/routers/account-router.ts b/server/src/routers/account-router.ts
index 38d0d80..e1d4adc 100644
--- a/server/src/routers/account-router.ts
+++ b/server/src/routers/account-router.ts
@@ -19,7 +19,7 @@
 import log from 'loglevel';
 import { Container } from 'typedi';
 
-import { Jamid } from '../jamid.js';
+import { Jamid } from '../jamid/jamid.js';
 import { authenticateToken } from '../middleware/auth.js';
 
 const jamid = Container.get(Jamid);
diff --git a/server/src/routers/auth-router.ts b/server/src/routers/auth-router.ts
index 26584f0..2aab780 100644
--- a/server/src/routers/auth-router.ts
+++ b/server/src/routers/auth-router.ts
@@ -25,7 +25,7 @@
 
 import { StatusCode } from '../constants.js';
 import { Creds } from '../creds.js';
-import { Jamid } from '../jamid.js';
+import { Jamid } from '../jamid/jamid.js';
 import { Vault } from '../vault.js';
 
 interface Credentials {