blob: 63fc307e1ba3bc9629bbdd48fc8a17a368673b9f [file] [log] [blame]
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -04001/*
2 * Copyright (C) 2022 Savoir-faire Linux Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation; either version 3 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public
15 * License along with this program. If not, see
16 * <https://www.gnu.org/licenses/>.
17 */
18import { itMap, itRange, itToArr, itToMap } from '../utils.js';
19
20enum Bool {
21 False = 'false',
22 True = 'true',
23}
24
25interface SwigVec<T> {
26 size(): number;
27 get(i: number): T; // TODO: | undefined;
28}
29
30interface SwigMap<T, U> {
31 keys(): SwigVec<T>;
32 get(k: T): U; // TODO: | undefined;
33 set(k: T, v: U): void;
34}
35
36const swigVecToIt = <T>(v: SwigVec<T>) => itMap(itRange(0, v.size()), (i) => v.get(i));
37const swigMapToIt = <T, U>(m: SwigMap<T, U>) => itMap(swigVecToIt(m.keys()), (k): [T, U] => [k, m.get(k)]);
38
39// type IntVect = SwigVec<number>;
40// type UintVect = SwigVec<number>;
41// type FloatVect = SwigVec<number>;
42export type StringVect = SwigVec<string>;
43// type IntegerMap = SwigMap<string, number>;
44export type StringMap = SwigMap<string, string>;
45// type VectMap = SwigVec<StringMap>;
46// type Blob = SwigVec<number>;
47
48export const stringVectToArr = (sv: StringVect) => itToArr(swigVecToIt(sv));
49export const stringMapToMap = (sm: StringMap) => itToMap(swigMapToIt(sm));
50// const vectMapToJs = (vm: VectMap) => itToArr(itMap(swigVecToIt(vm), stringMapToMap));
51
52export interface JamiSwig {
53 init(args: Record<string, unknown>): void;
Misha Krieger-Raynauld62a0da92022-10-22 13:46:59 -040054 fini(): void;
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040055
56 // IntVect(): IntVect;
57 // UintVect(): UintVect;
58 // FloatVect(): FloatVect;
59 // StringVect(): StringVect;
60 // IntegerMap(): IntegerMap
61 // StringMap(): StringMap;
62 // VectMap(): VectMap;
63 // IntegerMap(): IntegerMap;
64
65 addAccount(details: StringMap): string;
66 removeAccount(id: string): void;
67
68 getAccountList(): StringVect;
69
70 registerName(id: string, password: string, username: string): boolean;
71 lookupName(id: string, nameserver: string, username: string): boolean;
72 lookupAddress(id: string, nameserver: string, address: string): boolean;
73
74 getAccountDetails(id: string): StringMap;
75 setAccountDetails(id: string, details: StringMap): void;
76 setAccountActive(id: string, active: Bool): void;
77}