appwrite-cli 12.0.0 → 13.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +2 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +145 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/client.d.ts +89 -0
- package/dist/lib/client.d.ts.map +1 -0
- package/dist/lib/client.js +227 -0
- package/dist/lib/client.js.map +1 -0
- package/dist/lib/commands/account.d.ts +379 -0
- package/dist/lib/commands/account.d.ts.map +1 -0
- package/dist/lib/commands/account.js +1228 -0
- package/dist/lib/commands/account.js.map +1 -0
- package/dist/lib/commands/console.d.ts +20 -0
- package/dist/lib/commands/console.d.ts.map +1 -0
- package/dist/lib/commands/console.js +78 -0
- package/dist/lib/commands/console.js.map +1 -0
- package/dist/lib/commands/databases.d.ts +732 -0
- package/dist/lib/commands/databases.d.ts.map +1 -0
- package/dist/lib/commands/databases.js +2196 -0
- package/dist/lib/commands/databases.js.map +1 -0
- package/dist/lib/commands/functions.d.ts +310 -0
- package/dist/lib/commands/functions.d.ts.map +1 -0
- package/dist/lib/commands/functions.js +1100 -0
- package/dist/lib/commands/functions.js.map +1 -0
- package/dist/lib/commands/generic.d.ts +17 -0
- package/dist/lib/commands/generic.d.ts.map +1 -0
- package/dist/lib/commands/generic.js +279 -0
- package/dist/lib/commands/generic.js.map +1 -0
- package/dist/lib/commands/graphql.d.ts +19 -0
- package/dist/lib/commands/graphql.d.ts.map +1 -0
- package/dist/lib/commands/graphql.js +77 -0
- package/dist/lib/commands/graphql.js.map +1 -0
- package/dist/lib/commands/health.d.ts +153 -0
- package/dist/lib/commands/health.d.ts.map +1 -0
- package/dist/lib/commands/health.js +464 -0
- package/dist/lib/commands/health.js.map +1 -0
- package/dist/lib/commands/init.d.ts +3 -0
- package/dist/lib/commands/init.d.ts.map +1 -0
- package/dist/lib/commands/init.js +518 -0
- package/dist/lib/commands/init.js.map +1 -0
- package/dist/lib/commands/locale.d.ts +53 -0
- package/dist/lib/commands/locale.d.ts.map +1 -0
- package/dist/lib/commands/locale.js +165 -0
- package/dist/lib/commands/locale.js.map +1 -0
- package/dist/lib/commands/messaging.d.ts +588 -0
- package/dist/lib/commands/messaging.d.ts.map +1 -0
- package/dist/lib/commands/messaging.js +2042 -0
- package/dist/lib/commands/messaging.js.map +1 -0
- package/dist/lib/commands/migrations.d.ts +150 -0
- package/dist/lib/commands/migrations.d.ts.map +1 -0
- package/dist/lib/commands/migrations.js +524 -0
- package/dist/lib/commands/migrations.js.map +1 -0
- package/dist/lib/commands/organizations.d.ts +11 -0
- package/dist/lib/commands/organizations.d.ts.map +1 -0
- package/dist/lib/commands/organizations.js +31 -0
- package/dist/lib/commands/organizations.js.map +1 -0
- package/dist/lib/commands/project.d.ts +53 -0
- package/dist/lib/commands/project.d.ts.map +1 -0
- package/dist/lib/commands/project.js +176 -0
- package/dist/lib/commands/project.js.map +1 -0
- package/dist/lib/commands/projects.d.ts +516 -0
- package/dist/lib/commands/projects.d.ts.map +1 -0
- package/dist/lib/commands/projects.js +1590 -0
- package/dist/lib/commands/projects.js.map +1 -0
- package/dist/lib/commands/proxy.d.ts +71 -0
- package/dist/lib/commands/proxy.d.ts.map +1 -0
- package/dist/lib/commands/proxy.js +240 -0
- package/dist/lib/commands/proxy.js.map +1 -0
- package/dist/lib/commands/pull.d.ts +8 -0
- package/dist/lib/commands/pull.d.ts.map +1 -0
- package/dist/lib/commands/pull.js +455 -0
- package/dist/lib/commands/pull.js.map +1 -0
- package/dist/lib/commands/push.d.ts +4 -0
- package/dist/lib/commands/push.d.ts.map +1 -0
- package/dist/lib/commands/push.js +2154 -0
- package/dist/lib/commands/push.js.map +1 -0
- package/dist/lib/commands/run.d.ts +3 -0
- package/dist/lib/commands/run.d.ts.map +1 -0
- package/dist/lib/commands/run.js +287 -0
- package/dist/lib/commands/run.js.map +1 -0
- package/dist/lib/commands/sites.d.ts +296 -0
- package/dist/lib/commands/sites.d.ts.map +1 -0
- package/dist/lib/commands/sites.js +1046 -0
- package/dist/lib/commands/sites.js.map +1 -0
- package/dist/lib/commands/storage.d.ts +170 -0
- package/dist/lib/commands/storage.d.ts.map +1 -0
- package/dist/lib/commands/storage.js +651 -0
- package/dist/lib/commands/storage.js.map +1 -0
- package/dist/lib/commands/tables-db.d.ts +728 -0
- package/dist/lib/commands/tables-db.d.ts.map +1 -0
- package/dist/lib/commands/tables-db.js +2198 -0
- package/dist/lib/commands/tables-db.js.map +1 -0
- package/dist/lib/commands/teams.d.ts +129 -0
- package/dist/lib/commands/teams.d.ts.map +1 -0
- package/dist/lib/commands/teams.js +403 -0
- package/dist/lib/commands/teams.js.map +1 -0
- package/dist/lib/commands/tokens.d.ts +48 -0
- package/dist/lib/commands/tokens.d.ts.map +1 -0
- package/dist/lib/commands/tokens.js +156 -0
- package/dist/lib/commands/tokens.js.map +1 -0
- package/dist/lib/commands/types.d.ts +3 -0
- package/dist/lib/commands/types.d.ts.map +1 -0
- package/dist/lib/commands/types.js +155 -0
- package/dist/lib/commands/types.js.map +1 -0
- package/dist/lib/commands/update.d.ts +3 -0
- package/dist/lib/commands/update.d.ts.map +1 -0
- package/dist/lib/commands/update.js +202 -0
- package/dist/lib/commands/update.js.map +1 -0
- package/dist/lib/commands/users.d.ts +382 -0
- package/dist/lib/commands/users.d.ts.map +1 -0
- package/dist/lib/commands/users.js +1195 -0
- package/dist/lib/commands/users.js.map +1 -0
- package/dist/lib/commands/vcs.d.ts +92 -0
- package/dist/lib/commands/vcs.d.ts.map +1 -0
- package/dist/lib/commands/vcs.js +276 -0
- package/dist/lib/commands/vcs.js.map +1 -0
- package/dist/lib/config.d.ts +118 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/{lib → dist/lib}/config.js +204 -325
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/emulation/docker.d.ts +15 -0
- package/dist/lib/emulation/docker.d.ts.map +1 -0
- package/dist/lib/emulation/docker.js +220 -0
- package/dist/lib/emulation/docker.js.map +1 -0
- package/dist/lib/emulation/utils.d.ts +29 -0
- package/dist/lib/emulation/utils.d.ts.map +1 -0
- package/dist/lib/emulation/utils.js +168 -0
- package/dist/lib/emulation/utils.js.map +1 -0
- package/dist/lib/exception.d.ts +8 -0
- package/dist/lib/exception.d.ts.map +1 -0
- package/dist/lib/exception.js +16 -0
- package/dist/lib/exception.js.map +1 -0
- package/dist/lib/id.d.ts +7 -0
- package/dist/lib/id.d.ts.map +1 -0
- package/dist/lib/id.js +32 -0
- package/dist/lib/id.js.map +1 -0
- package/dist/lib/paginate.d.ts +10 -0
- package/dist/lib/paginate.d.ts.map +1 -0
- package/{lib → dist/lib}/paginate.js +9 -15
- package/dist/lib/paginate.js.map +1 -0
- package/dist/lib/parser.d.ts +18 -0
- package/dist/lib/parser.d.ts.map +1 -0
- package/dist/lib/parser.js +237 -0
- package/dist/lib/parser.js.map +1 -0
- package/dist/lib/questions.d.ts +59 -0
- package/dist/lib/questions.d.ts.map +1 -0
- package/dist/lib/questions.js +995 -0
- package/dist/lib/questions.js.map +1 -0
- package/dist/lib/sdks.d.ts +4 -0
- package/dist/lib/sdks.d.ts.map +1 -0
- package/dist/lib/sdks.js +51 -0
- package/dist/lib/sdks.js.map +1 -0
- package/dist/lib/spinner.d.ts +28 -0
- package/dist/lib/spinner.d.ts.map +1 -0
- package/{lib → dist/lib}/spinner.js +34 -45
- package/dist/lib/spinner.js.map +1 -0
- package/dist/lib/type-generation/attribute.d.ts +17 -0
- package/dist/lib/type-generation/attribute.d.ts.map +1 -0
- package/dist/lib/type-generation/attribute.js +19 -0
- package/dist/lib/type-generation/attribute.js.map +1 -0
- package/dist/lib/type-generation/languages/csharp.d.ts +7 -0
- package/dist/lib/type-generation/languages/csharp.d.ts.map +1 -0
- package/dist/lib/type-generation/languages/csharp.js +180 -0
- package/dist/lib/type-generation/languages/csharp.js.map +1 -0
- package/dist/lib/type-generation/languages/dart.d.ts +8 -0
- package/dist/lib/type-generation/languages/dart.d.ts.map +1 -0
- package/dist/lib/type-generation/languages/dart.js +197 -0
- package/dist/lib/type-generation/languages/dart.js.map +1 -0
- package/dist/lib/type-generation/languages/java.d.ts +7 -0
- package/dist/lib/type-generation/languages/java.d.ts.map +1 -0
- package/dist/lib/type-generation/languages/java.js +140 -0
- package/dist/lib/type-generation/languages/java.js.map +1 -0
- package/dist/lib/type-generation/languages/javascript.d.ts +9 -0
- package/dist/lib/type-generation/languages/javascript.d.ts.map +1 -0
- package/dist/lib/type-generation/languages/javascript.js +108 -0
- package/dist/lib/type-generation/languages/javascript.js.map +1 -0
- package/dist/lib/type-generation/languages/kotlin.d.ts +7 -0
- package/dist/lib/type-generation/languages/kotlin.d.ts.map +1 -0
- package/dist/lib/type-generation/languages/kotlin.js +95 -0
- package/dist/lib/type-generation/languages/kotlin.js.map +1 -0
- package/dist/lib/type-generation/languages/language.d.ts +43 -0
- package/dist/lib/type-generation/languages/language.d.ts.map +1 -0
- package/dist/lib/type-generation/languages/language.js +82 -0
- package/dist/lib/type-generation/languages/language.js.map +1 -0
- package/dist/lib/type-generation/languages/php.d.ts +7 -0
- package/dist/lib/type-generation/languages/php.d.ts.map +1 -0
- package/dist/lib/type-generation/languages/php.js +116 -0
- package/dist/lib/type-generation/languages/php.js.map +1 -0
- package/dist/lib/type-generation/languages/swift.d.ts +7 -0
- package/dist/lib/type-generation/languages/swift.d.ts.map +1 -0
- package/dist/lib/type-generation/languages/swift.js +179 -0
- package/dist/lib/type-generation/languages/swift.js.map +1 -0
- package/dist/lib/type-generation/languages/typescript.d.ts +9 -0
- package/dist/lib/type-generation/languages/typescript.d.ts.map +1 -0
- package/dist/lib/type-generation/languages/typescript.js +112 -0
- package/dist/lib/type-generation/languages/typescript.js.map +1 -0
- package/dist/lib/types.d.ts +133 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +3 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/utils.d.ts +15 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/{lib → dist/lib}/utils.js +74 -120
- package/dist/lib/utils.js.map +1 -0
- package/dist/lib/validations.d.ts +2 -0
- package/dist/lib/validations.d.ts.map +1 -0
- package/dist/lib/validations.js +20 -0
- package/dist/lib/validations.js.map +1 -0
- package/docs/examples/databases/upsert-document.md +1 -2
- package/index.ts +152 -0
- package/install.ps1 +2 -5
- package/install.sh +1 -2
- package/lib/client.ts +259 -0
- package/lib/commands/{account.js → account.ts} +410 -664
- package/lib/commands/console.ts +112 -0
- package/lib/commands/{databases.js → databases.ts} +818 -1136
- package/lib/commands/{functions.js → functions.ts} +381 -526
- package/lib/commands/{generic.js → generic.ts} +47 -39
- package/lib/commands/graphql.ts +110 -0
- package/lib/commands/{health.js → health.ts} +168 -284
- package/lib/commands/{init.js → init.ts} +68 -66
- package/lib/commands/{locale.js → locale.ts} +75 -121
- package/lib/commands/{messaging.js → messaging.ts} +699 -937
- package/lib/commands/{migrations.js → migrations.ts} +182 -258
- package/lib/commands/organizations.ts +46 -0
- package/lib/commands/{project.js → project.ts} +75 -111
- package/lib/commands/{projects.js → projects.ts} +587 -843
- package/lib/commands/{proxy.js → proxy.ts} +94 -140
- package/lib/commands/{pull.js → pull.ts} +54 -44
- package/lib/commands/{push.js → push.ts} +235 -191
- package/lib/commands/{run.js → run.ts} +61 -55
- package/lib/commands/{sites.js → sites.ts} +364 -504
- package/lib/commands/{storage.js → storage.ts} +216 -292
- package/lib/commands/{tables-db.js → tables-db.ts} +817 -1126
- package/lib/commands/{teams.js → teams.ts} +162 -236
- package/lib/commands/{tokens.js → tokens.ts} +70 -99
- package/lib/commands/{types.js → types.ts} +37 -35
- package/lib/commands/{update.js → update.ts} +25 -27
- package/lib/commands/{users.js → users.ts} +426 -644
- package/lib/commands/{vcs.js → vcs.ts} +122 -173
- package/lib/config.ts +854 -0
- package/lib/emulation/{docker.js → docker.ts} +39 -38
- package/lib/emulation/utils.ts +193 -0
- package/lib/exception.ts +20 -0
- package/lib/{id.js → id.ts} +5 -5
- package/lib/paginate.ts +63 -0
- package/lib/parser.ts +238 -0
- package/lib/{questions.js → questions.ts} +148 -156
- package/lib/sdks.ts +55 -0
- package/lib/spinner.ts +118 -0
- package/lib/type-generation/attribute.ts +17 -0
- package/lib/type-generation/languages/{csharp.js → csharp.ts} +59 -48
- package/lib/type-generation/languages/{dart.js → dart.ts} +91 -80
- package/lib/type-generation/languages/{java.js → java.ts} +58 -47
- package/lib/type-generation/languages/javascript.ts +111 -0
- package/lib/type-generation/languages/kotlin.ts +96 -0
- package/lib/type-generation/languages/language.ts +119 -0
- package/lib/type-generation/languages/{php.js → php.ts} +55 -48
- package/lib/type-generation/languages/{swift.js → swift.ts} +59 -48
- package/lib/type-generation/languages/typescript.ts +116 -0
- package/lib/types.ts +150 -0
- package/lib/utils.ts +322 -0
- package/lib/validations.ts +17 -0
- package/package.json +21 -12
- package/scoop/appwrite.config.json +3 -3
- package/tsconfig.json +30 -0
- package/index.js +0 -147
- package/lib/client.js +0 -254
- package/lib/commands/console.js +0 -127
- package/lib/commands/graphql.js +0 -126
- package/lib/commands/organizations.js +0 -48
- package/lib/emulation/utils.js +0 -186
- package/lib/exception.js +0 -9
- package/lib/parser.js +0 -250
- package/lib/sdks.js +0 -60
- package/lib/type-generation/attribute.js +0 -16
- package/lib/type-generation/languages/javascript.js +0 -102
- package/lib/type-generation/languages/kotlin.js +0 -85
- package/lib/type-generation/languages/language.js +0 -125
- package/lib/type-generation/languages/typescript.js +0 -107
- package/lib/validations.js +0 -17
package/lib/config.ts
ADDED
|
@@ -0,0 +1,854 @@
|
|
|
1
|
+
import os = require('os');
|
|
2
|
+
import fs = require('fs');
|
|
3
|
+
import _path = require('path');
|
|
4
|
+
import process = require('process');
|
|
5
|
+
import JSONbig = require('json-bigint');
|
|
6
|
+
import type { ConfigData, SessionData, GlobalConfigData, ProjectConfigData } from './types';
|
|
7
|
+
|
|
8
|
+
const JSONBigInt = JSONbig({ storeAsString: false });
|
|
9
|
+
|
|
10
|
+
const KeysVars = new Set(['key', 'value']);
|
|
11
|
+
const KeysSite = new Set(['path', '$id', 'name', 'enabled', 'logging', 'timeout', 'framework', 'buildRuntime', 'adapter', 'installCommand', 'buildCommand', 'outputDirectory', 'fallbackFile', 'specification', 'vars']);
|
|
12
|
+
const KeysFunction = new Set(['path', '$id', 'execute', 'name', 'enabled', 'logging', 'runtime', 'specification', 'scopes', 'events', 'schedule', 'timeout', 'entrypoint', 'commands', 'vars']);
|
|
13
|
+
const KeysDatabase = new Set(['$id', 'name', 'enabled']);
|
|
14
|
+
const KeysCollection = new Set(['$id', '$permissions', 'databaseId', 'name', 'enabled', 'documentSecurity', 'attributes', 'indexes']);
|
|
15
|
+
const KeysTable = new Set(['$id', '$permissions', 'databaseId', 'name', 'enabled', 'rowSecurity', 'columns', 'indexes']);
|
|
16
|
+
const KeysStorage = new Set(['$id', '$permissions', 'fileSecurity', 'name', 'enabled', 'maximumFileSize', 'allowedFileExtensions', 'compression', 'encryption', 'antivirus']);
|
|
17
|
+
const KeysTopics = new Set(['$id', 'name', 'subscribe']);
|
|
18
|
+
const KeysTeams = new Set(['$id', 'name']);
|
|
19
|
+
const KeysAttributes = new Set([
|
|
20
|
+
'key',
|
|
21
|
+
'type',
|
|
22
|
+
'required',
|
|
23
|
+
'array',
|
|
24
|
+
'size',
|
|
25
|
+
'default',
|
|
26
|
+
// integer and float
|
|
27
|
+
'min',
|
|
28
|
+
'max',
|
|
29
|
+
// email, enum, URL, IP, and datetime
|
|
30
|
+
'format',
|
|
31
|
+
// enum
|
|
32
|
+
'elements',
|
|
33
|
+
// relationship
|
|
34
|
+
'relatedCollection',
|
|
35
|
+
'relationType',
|
|
36
|
+
'twoWay',
|
|
37
|
+
'twoWayKey',
|
|
38
|
+
'onDelete',
|
|
39
|
+
'side',
|
|
40
|
+
// Indexes
|
|
41
|
+
'attributes',
|
|
42
|
+
'orders',
|
|
43
|
+
// Strings
|
|
44
|
+
'encrypt',
|
|
45
|
+
]);
|
|
46
|
+
const KeysColumns = new Set([
|
|
47
|
+
'key',
|
|
48
|
+
'type',
|
|
49
|
+
'required',
|
|
50
|
+
'array',
|
|
51
|
+
'size',
|
|
52
|
+
'default',
|
|
53
|
+
// integer and float
|
|
54
|
+
'min',
|
|
55
|
+
'max',
|
|
56
|
+
// email, enum, URL, IP, and datetime
|
|
57
|
+
'format',
|
|
58
|
+
// enum
|
|
59
|
+
'elements',
|
|
60
|
+
// relationship
|
|
61
|
+
'relatedTable',
|
|
62
|
+
'relationType',
|
|
63
|
+
'twoWay',
|
|
64
|
+
'twoWayKey',
|
|
65
|
+
'onDelete',
|
|
66
|
+
'side',
|
|
67
|
+
// Indexes
|
|
68
|
+
'columns',
|
|
69
|
+
'orders',
|
|
70
|
+
// Strings
|
|
71
|
+
'encrypt',
|
|
72
|
+
]);
|
|
73
|
+
const KeyIndexes = new Set(['key', 'type', 'status', 'attributes', 'orders']);
|
|
74
|
+
const KeyIndexesColumns = new Set(['key', 'type', 'status', 'columns', 'orders']);
|
|
75
|
+
|
|
76
|
+
function whitelistKeys<T = any>(
|
|
77
|
+
value: T,
|
|
78
|
+
keys: Set<string>,
|
|
79
|
+
nestedKeys: Record<string, Set<string>> = {}
|
|
80
|
+
): T {
|
|
81
|
+
if (Array.isArray(value)) {
|
|
82
|
+
const newValue: any[] = [];
|
|
83
|
+
|
|
84
|
+
for (const item of value) {
|
|
85
|
+
newValue.push(whitelistKeys(item, keys, nestedKeys));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return newValue as T;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const newValue: Record<string, any> = {};
|
|
92
|
+
Object.keys(value as any).forEach((key) => {
|
|
93
|
+
if (keys.has(key)) {
|
|
94
|
+
if (nestedKeys[key]) {
|
|
95
|
+
newValue[key] = whitelistKeys((value as any)[key], nestedKeys[key]);
|
|
96
|
+
} else {
|
|
97
|
+
newValue[key] = (value as any)[key];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
return newValue as T;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
class Config<T extends ConfigData = ConfigData> {
|
|
105
|
+
protected path: string;
|
|
106
|
+
protected data: T;
|
|
107
|
+
|
|
108
|
+
constructor(path: string) {
|
|
109
|
+
this.path = path;
|
|
110
|
+
this.data = {} as T;
|
|
111
|
+
this.read();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
read(): void {
|
|
115
|
+
try {
|
|
116
|
+
const file = fs.readFileSync(this.path).toString();
|
|
117
|
+
this.data = JSONBigInt.parse(file);
|
|
118
|
+
} catch (e) {
|
|
119
|
+
this.data = {} as T;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
write(): void {
|
|
124
|
+
const dir = _path.dirname(this.path);
|
|
125
|
+
if (!fs.existsSync(dir)) {
|
|
126
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
127
|
+
}
|
|
128
|
+
fs.writeFileSync(this.path, JSONBigInt.stringify(this.data, null, 4), { mode: 0o600 });
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
get<K extends keyof T>(key: K): T[K];
|
|
132
|
+
get(key: string): any {
|
|
133
|
+
return this.data[key as keyof T];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
set<K extends keyof T>(key: K, value: T[K]): void;
|
|
137
|
+
set(key: string, value: any): void {
|
|
138
|
+
(this.data as any)[key] = value;
|
|
139
|
+
this.write();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
delete(key: string): void {
|
|
143
|
+
delete (this.data as any)[key];
|
|
144
|
+
this.write();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
clear(): void {
|
|
148
|
+
this.data = {} as T;
|
|
149
|
+
this.write();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
has(key: string): boolean {
|
|
153
|
+
return this.data[key as keyof T] !== undefined;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
keys(): string[] {
|
|
157
|
+
return Object.keys(this.data);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
values(): unknown[] {
|
|
161
|
+
return Object.values(this.data);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
toString(): string {
|
|
165
|
+
return JSONBigInt.stringify(this.data, null, 4);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
protected _getDBEntities(entityType: string): any[] {
|
|
169
|
+
if (!this.has(entityType)) {
|
|
170
|
+
return [];
|
|
171
|
+
}
|
|
172
|
+
return this.get(entityType);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
protected _getDBEntity(entityType: string, $id: string): any {
|
|
176
|
+
if (!this.has(entityType)) {
|
|
177
|
+
return {};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const entities = this.get(entityType);
|
|
181
|
+
for (let i = 0; i < entities.length; i++) {
|
|
182
|
+
if (entities[i]['$id'] == $id) {
|
|
183
|
+
return entities[i];
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return {};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
protected _addDBEntity(
|
|
191
|
+
entityType: string,
|
|
192
|
+
props: any,
|
|
193
|
+
keysSet: Set<string>,
|
|
194
|
+
nestedKeys: Record<string, Set<string>> = {}
|
|
195
|
+
): void {
|
|
196
|
+
props = whitelistKeys(props, keysSet, nestedKeys);
|
|
197
|
+
|
|
198
|
+
if (!this.has(entityType)) {
|
|
199
|
+
this.set(entityType, []);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const entities = this.get(entityType);
|
|
203
|
+
for (let i = 0; i < entities.length; i++) {
|
|
204
|
+
if (entities[i]['$id'] == props['$id']) {
|
|
205
|
+
entities[i] = props;
|
|
206
|
+
this.set(entityType, entities);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
entities.push(props);
|
|
211
|
+
this.set(entityType, entities);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
class Local extends Config<ProjectConfigData> {
|
|
216
|
+
static CONFIG_FILE_PATH = 'appwrite.config.json';
|
|
217
|
+
static CONFIG_FILE_PATH_LEGACY = 'appwrite.json';
|
|
218
|
+
configDirectoryPath = '';
|
|
219
|
+
|
|
220
|
+
constructor(path: string = Local.CONFIG_FILE_PATH, legacyPath: string = Local.CONFIG_FILE_PATH_LEGACY) {
|
|
221
|
+
let absolutePath = Local.findConfigFile(path) || Local.findConfigFile(legacyPath);
|
|
222
|
+
|
|
223
|
+
if (!absolutePath) {
|
|
224
|
+
absolutePath = `${process.cwd()}/${path}`;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
super(absolutePath);
|
|
228
|
+
this.configDirectoryPath = _path.dirname(absolutePath);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
static findConfigFile(filename: string): string | null {
|
|
232
|
+
let currentPath = process.cwd();
|
|
233
|
+
|
|
234
|
+
while (true) {
|
|
235
|
+
const filePath = `${currentPath}/${filename}`;
|
|
236
|
+
|
|
237
|
+
if (fs.existsSync(filePath)) {
|
|
238
|
+
return filePath;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const parentDirectory = _path.dirname(currentPath);
|
|
242
|
+
if (parentDirectory === currentPath) {
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
currentPath = parentDirectory;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
getDirname(): string {
|
|
252
|
+
return _path.dirname(this.path);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
getEndpoint(): string {
|
|
256
|
+
return this.get('endpoint' as any) || '';
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
setEndpoint(endpoint: string): void {
|
|
260
|
+
this.set('endpoint' as any, endpoint);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
getSites(): any[] {
|
|
264
|
+
if (!this.has('sites')) {
|
|
265
|
+
return [];
|
|
266
|
+
}
|
|
267
|
+
return this.get('sites' as any);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
getSite($id: string): any {
|
|
271
|
+
if (!this.has('sites')) {
|
|
272
|
+
return {};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const sites = this.get('sites' as any);
|
|
276
|
+
for (let i = 0; i < sites.length; i++) {
|
|
277
|
+
if (sites[i]['$id'] == $id) {
|
|
278
|
+
return sites[i];
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return {};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
addSite(props: any): void {
|
|
286
|
+
props = whitelistKeys(props, KeysSite, {
|
|
287
|
+
vars: KeysVars,
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
if (!this.has('sites')) {
|
|
291
|
+
this.set('sites' as any, []);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const sites = this.get('sites' as any);
|
|
295
|
+
for (let i = 0; i < sites.length; i++) {
|
|
296
|
+
if (sites[i]['$id'] == props['$id']) {
|
|
297
|
+
sites[i] = {
|
|
298
|
+
...sites[i],
|
|
299
|
+
...props,
|
|
300
|
+
};
|
|
301
|
+
this.set('sites' as any, sites);
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
sites.push(props);
|
|
307
|
+
this.set('sites' as any, sites);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
getFunctions(): any[] {
|
|
311
|
+
if (!this.has('functions')) {
|
|
312
|
+
return [];
|
|
313
|
+
}
|
|
314
|
+
return this.get('functions' as any);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
getFunction($id: string): any {
|
|
318
|
+
if (!this.has('functions')) {
|
|
319
|
+
return {};
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const functions = this.get('functions' as any);
|
|
323
|
+
for (let i = 0; i < functions.length; i++) {
|
|
324
|
+
if (functions[i]['$id'] == $id) {
|
|
325
|
+
return functions[i];
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return {};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
addFunction(props: any): void {
|
|
333
|
+
props = whitelistKeys(props, KeysFunction, {
|
|
334
|
+
vars: KeysVars,
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
if (!this.has('functions')) {
|
|
338
|
+
this.set('functions' as any, []);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const functions = this.get('functions' as any);
|
|
342
|
+
for (let i = 0; i < functions.length; i++) {
|
|
343
|
+
if (functions[i]['$id'] == props['$id']) {
|
|
344
|
+
functions[i] = {
|
|
345
|
+
...functions[i],
|
|
346
|
+
...props,
|
|
347
|
+
};
|
|
348
|
+
this.set('functions' as any, functions);
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
functions.push(props);
|
|
354
|
+
this.set('functions' as any, functions);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
getCollections(): any[] {
|
|
358
|
+
if (!this.has('collections')) {
|
|
359
|
+
return [];
|
|
360
|
+
}
|
|
361
|
+
return this.get('collections' as any);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
getCollection($id: string): any {
|
|
365
|
+
if (!this.has('collections')) {
|
|
366
|
+
return {};
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const collections = this.get('collections' as any);
|
|
370
|
+
for (let i = 0; i < collections.length; i++) {
|
|
371
|
+
if (collections[i]['$id'] == $id) {
|
|
372
|
+
return collections[i];
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
return {};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
addCollection(props: any): void {
|
|
380
|
+
props = whitelistKeys(props, KeysCollection, {
|
|
381
|
+
attributes: KeysAttributes,
|
|
382
|
+
indexes: KeyIndexes,
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
if (!this.has('collections')) {
|
|
386
|
+
this.set('collections' as any, []);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
const collections = this.get('collections' as any);
|
|
390
|
+
for (let i = 0; i < collections.length; i++) {
|
|
391
|
+
if (collections[i]['$id'] == props['$id'] && collections[i]['databaseId'] == props['databaseId']) {
|
|
392
|
+
collections[i] = props;
|
|
393
|
+
this.set('collections' as any, collections);
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
collections.push(props);
|
|
398
|
+
this.set('collections' as any, collections);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
getTables(): any[] {
|
|
402
|
+
if (!this.has('tables')) {
|
|
403
|
+
return [];
|
|
404
|
+
}
|
|
405
|
+
return this.get('tables' as any);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
getTable($id: string): any {
|
|
409
|
+
if (!this.has('tables')) {
|
|
410
|
+
return {};
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
const tables = this.get('tables' as any);
|
|
414
|
+
for (let i = 0; i < tables.length; i++) {
|
|
415
|
+
if (tables[i]['$id'] == $id) {
|
|
416
|
+
return tables[i];
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
return {};
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
addTable(props: any): void {
|
|
424
|
+
props = whitelistKeys(props, KeysTable, {
|
|
425
|
+
columns: KeysColumns,
|
|
426
|
+
indexes: KeyIndexesColumns,
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
if (!this.has('tables')) {
|
|
430
|
+
this.set('tables' as any, []);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
const tables = this.get('tables' as any);
|
|
434
|
+
for (let i = 0; i < tables.length; i++) {
|
|
435
|
+
if (tables[i]['$id'] == props['$id'] && tables[i]['databaseId'] == props['databaseId']) {
|
|
436
|
+
tables[i] = props;
|
|
437
|
+
this.set('tables' as any, tables);
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
tables.push(props);
|
|
442
|
+
this.set('tables' as any, tables);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
getBuckets(): any[] {
|
|
446
|
+
if (!this.has('buckets')) {
|
|
447
|
+
return [];
|
|
448
|
+
}
|
|
449
|
+
return this.get('buckets' as any);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
getBucket($id: string): any {
|
|
453
|
+
if (!this.has('buckets')) {
|
|
454
|
+
return {};
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
const buckets = this.get('buckets' as any);
|
|
458
|
+
for (let i = 0; i < buckets.length; i++) {
|
|
459
|
+
if (buckets[i]['$id'] == $id) {
|
|
460
|
+
return buckets[i];
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
return {};
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
addBucket(props: any): void {
|
|
468
|
+
props = whitelistKeys(props, KeysStorage);
|
|
469
|
+
|
|
470
|
+
if (!this.has('buckets')) {
|
|
471
|
+
this.set('buckets' as any, []);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
const buckets = this.get('buckets' as any);
|
|
475
|
+
for (let i = 0; i < buckets.length; i++) {
|
|
476
|
+
if (buckets[i]['$id'] == props['$id']) {
|
|
477
|
+
buckets[i] = props;
|
|
478
|
+
this.set('buckets' as any, buckets);
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
buckets.push(props);
|
|
483
|
+
this.set('buckets' as any, buckets);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
getMessagingTopics(): any[] {
|
|
487
|
+
if (!this.has('topics')) {
|
|
488
|
+
return [];
|
|
489
|
+
}
|
|
490
|
+
return this.get('topics' as any);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
getMessagingTopic($id: string): any {
|
|
494
|
+
if (!this.has('topics')) {
|
|
495
|
+
return {};
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
const topic = this.get('topics' as any);
|
|
499
|
+
for (let i = 0; i < topic.length; i++) {
|
|
500
|
+
if (topic[i]['$id'] == $id) {
|
|
501
|
+
return topic[i];
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
return {};
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
addMessagingTopic(props: any): void {
|
|
509
|
+
props = whitelistKeys(props, KeysTopics);
|
|
510
|
+
|
|
511
|
+
if (!this.has('topics')) {
|
|
512
|
+
this.set('topics' as any, []);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
const topics = this.get('topics' as any);
|
|
516
|
+
for (let i = 0; i < topics.length; i++) {
|
|
517
|
+
if (topics[i]['$id'] === props['$id']) {
|
|
518
|
+
topics[i] = props;
|
|
519
|
+
this.set('topics' as any, topics);
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
topics.push(props);
|
|
524
|
+
this.set('topics' as any, topics);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
getTablesDBs(): any[] {
|
|
528
|
+
return this._getDBEntities('tablesDB');
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
getTablesDB($id: string): any {
|
|
532
|
+
return this._getDBEntity('tablesDB', $id);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
addTablesDB(props: any): void {
|
|
536
|
+
this._addDBEntity('tablesDB', props, KeysDatabase);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
getDatabases(): any[] {
|
|
540
|
+
return this._getDBEntities('databases');
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
getDatabase($id: string): any {
|
|
544
|
+
return this._getDBEntity('databases', $id);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
addDatabase(props: any): void {
|
|
548
|
+
this._addDBEntity('databases', props, KeysDatabase);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
getTeams(): any[] {
|
|
552
|
+
if (!this.has('teams')) {
|
|
553
|
+
return [];
|
|
554
|
+
}
|
|
555
|
+
return this.get('teams' as any);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
getTeam($id: string): any {
|
|
559
|
+
if (!this.has('teams')) {
|
|
560
|
+
return {};
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
const teams = this.get('teams' as any);
|
|
564
|
+
for (let i = 0; i < teams.length; i++) {
|
|
565
|
+
if (teams[i]['$id'] == $id) {
|
|
566
|
+
return teams[i];
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
return {};
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
addTeam(props: any): void {
|
|
574
|
+
props = whitelistKeys(props, KeysTeams);
|
|
575
|
+
if (!this.has('teams')) {
|
|
576
|
+
this.set('teams' as any, []);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
const teams = this.get('teams' as any);
|
|
580
|
+
for (let i = 0; i < teams.length; i++) {
|
|
581
|
+
if (teams[i]['$id'] == props['$id']) {
|
|
582
|
+
teams[i] = props;
|
|
583
|
+
this.set('teams' as any, teams);
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
teams.push(props);
|
|
588
|
+
this.set('teams' as any, teams);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
getProject(): { projectId?: string; projectName?: string; projectSettings?: any } {
|
|
592
|
+
if (!this.has('projectId')) {
|
|
593
|
+
return {};
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
return {
|
|
597
|
+
projectId: this.get('projectId' as any),
|
|
598
|
+
projectName: this.get('projectName' as any),
|
|
599
|
+
projectSettings: this.get('settings' as any),
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
setProject(projectId: string, projectName: string = '', projectSettings: any = undefined): void {
|
|
604
|
+
this.set('projectId' as any, projectId);
|
|
605
|
+
|
|
606
|
+
if (projectName !== '') {
|
|
607
|
+
this.set('projectName' as any, projectName);
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
if (projectSettings === undefined) {
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
this.set('settings' as any, this.createSettingsObject(projectSettings));
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
createSettingsObject(projectSettings: any): any {
|
|
618
|
+
return {
|
|
619
|
+
services: {
|
|
620
|
+
account: projectSettings.serviceStatusForAccount,
|
|
621
|
+
avatars: projectSettings.serviceStatusForAvatars,
|
|
622
|
+
databases: projectSettings.serviceStatusForDatabases,
|
|
623
|
+
locale: projectSettings.serviceStatusForLocale,
|
|
624
|
+
health: projectSettings.serviceStatusForHealth,
|
|
625
|
+
storage: projectSettings.serviceStatusForStorage,
|
|
626
|
+
teams: projectSettings.serviceStatusForTeams,
|
|
627
|
+
users: projectSettings.serviceStatusForUsers,
|
|
628
|
+
sites: projectSettings.serviceStatusForSites,
|
|
629
|
+
functions: projectSettings.serviceStatusForFunctions,
|
|
630
|
+
graphql: projectSettings.serviceStatusForGraphql,
|
|
631
|
+
messaging: projectSettings.serviceStatusForMessaging,
|
|
632
|
+
},
|
|
633
|
+
auth: {
|
|
634
|
+
methods: {
|
|
635
|
+
jwt: projectSettings.authJWT,
|
|
636
|
+
phone: projectSettings.authPhone,
|
|
637
|
+
invites: projectSettings.authInvites,
|
|
638
|
+
anonymous: projectSettings.authAnonymous,
|
|
639
|
+
'email-otp': projectSettings.authEmailOtp,
|
|
640
|
+
'magic-url': projectSettings.authUsersAuthMagicURL,
|
|
641
|
+
'email-password': projectSettings.authEmailPassword,
|
|
642
|
+
},
|
|
643
|
+
security: {
|
|
644
|
+
duration: projectSettings.authDuration,
|
|
645
|
+
limit: projectSettings.authLimit,
|
|
646
|
+
sessionsLimit: projectSettings.authSessionsLimit,
|
|
647
|
+
passwordHistory: projectSettings.authPasswordHistory,
|
|
648
|
+
passwordDictionary: projectSettings.authPasswordDictionary,
|
|
649
|
+
personalDataCheck: projectSettings.authPersonalDataCheck,
|
|
650
|
+
sessionAlerts: projectSettings.authSessionAlerts,
|
|
651
|
+
mockNumbers: projectSettings.authMockNumbers,
|
|
652
|
+
},
|
|
653
|
+
},
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
class Global extends Config<GlobalConfigData> {
|
|
659
|
+
static CONFIG_FILE_PATH = '.appwrite/prefs.json';
|
|
660
|
+
|
|
661
|
+
static PREFERENCE_CURRENT = 'current';
|
|
662
|
+
static PREFERENCE_ENDPOINT = 'endpoint';
|
|
663
|
+
static PREFERENCE_EMAIL = 'email';
|
|
664
|
+
static PREFERENCE_SELF_SIGNED = 'selfSigned';
|
|
665
|
+
static PREFERENCE_COOKIE = 'cookie';
|
|
666
|
+
static PREFERENCE_PROJECT = 'project';
|
|
667
|
+
static PREFERENCE_KEY = 'key';
|
|
668
|
+
static PREFERENCE_LOCALE = 'locale';
|
|
669
|
+
static PREFERENCE_MODE = 'mode';
|
|
670
|
+
|
|
671
|
+
static IGNORE_ATTRIBUTES = [
|
|
672
|
+
Global.PREFERENCE_CURRENT,
|
|
673
|
+
Global.PREFERENCE_SELF_SIGNED,
|
|
674
|
+
Global.PREFERENCE_ENDPOINT,
|
|
675
|
+
Global.PREFERENCE_COOKIE,
|
|
676
|
+
Global.PREFERENCE_PROJECT,
|
|
677
|
+
Global.PREFERENCE_KEY,
|
|
678
|
+
Global.PREFERENCE_LOCALE,
|
|
679
|
+
Global.PREFERENCE_MODE,
|
|
680
|
+
];
|
|
681
|
+
|
|
682
|
+
static MODE_ADMIN = 'admin';
|
|
683
|
+
static MODE_DEFAULT = 'default';
|
|
684
|
+
|
|
685
|
+
static PROJECT_CONSOLE = 'console';
|
|
686
|
+
|
|
687
|
+
constructor(path: string = Global.CONFIG_FILE_PATH) {
|
|
688
|
+
const homeDir = os.homedir();
|
|
689
|
+
super(`${homeDir}/${path}`);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
getCurrentSession(): string {
|
|
693
|
+
if (!this.has(Global.PREFERENCE_CURRENT)) {
|
|
694
|
+
return '';
|
|
695
|
+
}
|
|
696
|
+
return this.get(Global.PREFERENCE_CURRENT as any);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
setCurrentSession(session: string): void {
|
|
700
|
+
if (session !== undefined) {
|
|
701
|
+
this.set(Global.PREFERENCE_CURRENT as any, session);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
getSessionIds(): string[] {
|
|
706
|
+
return Object.keys(this.data).filter((key) => !Global.IGNORE_ATTRIBUTES.includes(key));
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
getSessions(): Array<{ id: string; endpoint: string; email: string }> {
|
|
710
|
+
const sessions = Object.keys(this.data).filter((key) => !Global.IGNORE_ATTRIBUTES.includes(key));
|
|
711
|
+
const current = this.getCurrentSession();
|
|
712
|
+
|
|
713
|
+
const sessionMap = new Map<string, { id: string; endpoint: string; email: string }>();
|
|
714
|
+
|
|
715
|
+
sessions.forEach((sessionId) => {
|
|
716
|
+
const sessionData = (this.data as any)[sessionId];
|
|
717
|
+
const email = sessionData[Global.PREFERENCE_EMAIL];
|
|
718
|
+
const endpoint = sessionData[Global.PREFERENCE_ENDPOINT];
|
|
719
|
+
const key = `${email}|${endpoint}`;
|
|
720
|
+
|
|
721
|
+
if (sessionId === current || !sessionMap.has(key)) {
|
|
722
|
+
sessionMap.set(key, {
|
|
723
|
+
id: sessionId,
|
|
724
|
+
endpoint: sessionData[Global.PREFERENCE_ENDPOINT],
|
|
725
|
+
email: sessionData[Global.PREFERENCE_EMAIL],
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
});
|
|
729
|
+
|
|
730
|
+
return Array.from(sessionMap.values());
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
addSession(session: string, data: SessionData): void {
|
|
734
|
+
this.set(session as any, data as any);
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
removeSession(session: string): void {
|
|
738
|
+
this.delete(session);
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
getEmail(): string {
|
|
742
|
+
if (!this.hasFrom(Global.PREFERENCE_EMAIL)) {
|
|
743
|
+
return '';
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
return this.getFrom(Global.PREFERENCE_EMAIL);
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
setEmail(email: string): void {
|
|
750
|
+
this.setTo(Global.PREFERENCE_EMAIL, email);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
getEndpoint(): string {
|
|
754
|
+
if (!this.hasFrom(Global.PREFERENCE_ENDPOINT)) {
|
|
755
|
+
return '';
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
return this.getFrom(Global.PREFERENCE_ENDPOINT);
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
setEndpoint(endpoint: string): void {
|
|
762
|
+
this.setTo(Global.PREFERENCE_ENDPOINT, endpoint);
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
getSelfSigned(): boolean {
|
|
766
|
+
if (!this.hasFrom(Global.PREFERENCE_SELF_SIGNED)) {
|
|
767
|
+
return false;
|
|
768
|
+
}
|
|
769
|
+
return this.getFrom(Global.PREFERENCE_SELF_SIGNED);
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
setSelfSigned(selfSigned: boolean): void {
|
|
773
|
+
this.setTo(Global.PREFERENCE_SELF_SIGNED, selfSigned);
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
getCookie(): string {
|
|
777
|
+
if (!this.hasFrom(Global.PREFERENCE_COOKIE)) {
|
|
778
|
+
return '';
|
|
779
|
+
}
|
|
780
|
+
return this.getFrom(Global.PREFERENCE_COOKIE);
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
setCookie(cookie: string): void {
|
|
784
|
+
this.setTo(Global.PREFERENCE_COOKIE, cookie);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
getProject(): string {
|
|
788
|
+
if (!this.hasFrom(Global.PREFERENCE_PROJECT)) {
|
|
789
|
+
return '';
|
|
790
|
+
}
|
|
791
|
+
return this.getFrom(Global.PREFERENCE_PROJECT);
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
setProject(project: string): void {
|
|
795
|
+
this.setTo(Global.PREFERENCE_PROJECT, project);
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
getKey(): string {
|
|
799
|
+
if (!this.hasFrom(Global.PREFERENCE_KEY)) {
|
|
800
|
+
return '';
|
|
801
|
+
}
|
|
802
|
+
return this.getFrom(Global.PREFERENCE_KEY);
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
setKey(key: string): void {
|
|
806
|
+
this.setTo(Global.PREFERENCE_KEY, key);
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
hasFrom(key: string): boolean {
|
|
810
|
+
const current = this.getCurrentSession();
|
|
811
|
+
|
|
812
|
+
if (current) {
|
|
813
|
+
const config = this.get(current as any) ?? {};
|
|
814
|
+
|
|
815
|
+
return (config as any)[key] !== undefined;
|
|
816
|
+
}
|
|
817
|
+
return false;
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
getFrom(key: string): any {
|
|
821
|
+
const current = this.getCurrentSession();
|
|
822
|
+
|
|
823
|
+
if (current) {
|
|
824
|
+
const config = this.get(current as any) ?? {};
|
|
825
|
+
|
|
826
|
+
return (config as any)[key];
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
setTo(key: string, value: any): void {
|
|
831
|
+
const current = this.getCurrentSession();
|
|
832
|
+
|
|
833
|
+
if (current) {
|
|
834
|
+
const config = this.get(current as any);
|
|
835
|
+
|
|
836
|
+
(config as any)[key] = value;
|
|
837
|
+
this.write();
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
export const localConfig = new Local();
|
|
843
|
+
export const globalConfig = new Global();
|
|
844
|
+
export {
|
|
845
|
+
KeysAttributes,
|
|
846
|
+
KeysSite,
|
|
847
|
+
KeysFunction,
|
|
848
|
+
KeysTopics,
|
|
849
|
+
KeysStorage,
|
|
850
|
+
KeysTeams,
|
|
851
|
+
KeysCollection,
|
|
852
|
+
KeysTable,
|
|
853
|
+
whitelistKeys,
|
|
854
|
+
};
|