@dreamkit/app 0.0.11 → 0.0.12
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/lib/App.d.ts +4 -0
- package/lib/App.d.ts.map +1 -1
- package/lib/App.js +36 -8
- package/package.json +5 -5
package/lib/App.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare class App {
|
|
|
17
17
|
readonly middlewares: Set<MiddlewareConstructor>;
|
|
18
18
|
readonly settings: Set<SettingsConstructor<import("./builders/SettingsBuilder.js").SettingsData<import("./builders/SettingsBuilder.js").SettingsName, import("./builders/SettingsBuilder.js").SettingsParams, import("./builders/SettingsBuilder.js").SettingsDefaults<import("./builders/SettingsBuilder.js").SettingsParams>>>>;
|
|
19
19
|
readonly api: Map<string, Func>;
|
|
20
|
+
protected apiRef: Map<string, string>;
|
|
20
21
|
settingsHandler: SettingsHandlerConstructor | undefined;
|
|
21
22
|
sessionHandler: SessionHandlerConstructor | undefined;
|
|
22
23
|
protected listeners: {
|
|
@@ -56,6 +57,9 @@ export declare class App {
|
|
|
56
57
|
protected stopService(item: AppService): Promise<void>;
|
|
57
58
|
protected normalizeApiPath(path: string): string;
|
|
58
59
|
protected onUnknownObject(id: string, value: unknown): void;
|
|
60
|
+
protected resolveEntry(input: Record<string, any> | any[]): {
|
|
61
|
+
[k: string]: any;
|
|
62
|
+
};
|
|
59
63
|
add(input: Record<string, any> | any[]): Promise<void>;
|
|
60
64
|
createRequestContext(request: Request): RequestContext;
|
|
61
65
|
request(request: Request): Promise<any>;
|
package/lib/App.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../src/App.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,qBAAqB,EACtB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EACL,UAAU,EAEV,kBAAkB,EACnB,MAA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Set();
|
|
26
26
|
settings = new Set();
|
|
27
27
|
api = new Map();
|
|
28
|
+
apiRef = new Map();
|
|
28
29
|
settingsHandler;
|
|
29
30
|
sessionHandler;
|
|
30
31
|
listeners = {
|
|
@@ -94,6 +95,12 @@ export class App {
|
|
|
94
95
|
else if (isSessionHandler(value)) {
|
|
95
96
|
this.sessionHandler = undefined;
|
|
96
97
|
}
|
|
98
|
+
else if (isApi(value)) {
|
|
99
|
+
const path = this.apiRef.get(id);
|
|
100
|
+
this.apiRef.delete(id);
|
|
101
|
+
if (path)
|
|
102
|
+
this.api.delete(path);
|
|
103
|
+
}
|
|
97
104
|
for (const cb of this.listeners.remove)
|
|
98
105
|
await cb({ id, value });
|
|
99
106
|
for (const cb of this.listeners.change)
|
|
@@ -156,16 +163,30 @@ export class App {
|
|
|
156
163
|
onUnknownObject(id, value) {
|
|
157
164
|
console.warn("Unknown object", { id, value, kinds: getKinds(value) });
|
|
158
165
|
}
|
|
159
|
-
|
|
160
|
-
let loadSettingsHandler = false;
|
|
161
|
-
const services = [];
|
|
162
|
-
const settings = [];
|
|
166
|
+
resolveEntry(input) {
|
|
163
167
|
const objects = Array.isArray(input)
|
|
164
168
|
? input.reduce((result, value, index) => {
|
|
165
169
|
result[index] = value;
|
|
166
170
|
return result;
|
|
167
171
|
}, {})
|
|
168
|
-
: input;
|
|
172
|
+
: { ...input };
|
|
173
|
+
const isPlainObject = (input) => !!input && typeof input === "object";
|
|
174
|
+
const entries = Object.entries(objects).flatMap(([id, value]) => {
|
|
175
|
+
if (isPlainObject(value) || Array.isArray(value)) {
|
|
176
|
+
return Object.entries(this.resolveEntry(value)).map(([childId, childValue]) => [
|
|
177
|
+
id === "default" ? childId : `${id}:${childId}`,
|
|
178
|
+
childValue,
|
|
179
|
+
]);
|
|
180
|
+
}
|
|
181
|
+
return [[id, value]];
|
|
182
|
+
});
|
|
183
|
+
return Object.fromEntries(entries);
|
|
184
|
+
}
|
|
185
|
+
async add(input) {
|
|
186
|
+
let loadSettingsHandler = false;
|
|
187
|
+
const services = [];
|
|
188
|
+
const settings = [];
|
|
189
|
+
const objects = this.resolveEntry(input);
|
|
169
190
|
for (const [id, value] of Object.entries(objects)) {
|
|
170
191
|
if (isRoute(value)) {
|
|
171
192
|
this.routes.add(value);
|
|
@@ -198,7 +219,9 @@ export class App {
|
|
|
198
219
|
this.sessionHandler = value;
|
|
199
220
|
}
|
|
200
221
|
else if (isApi(value)) {
|
|
201
|
-
this.
|
|
222
|
+
const path = this.normalizeApiPath(id);
|
|
223
|
+
this.api.set(path, value);
|
|
224
|
+
this.apiRef.set(id, path);
|
|
202
225
|
}
|
|
203
226
|
else {
|
|
204
227
|
this.onUnknownObject(id, value);
|
|
@@ -224,7 +247,7 @@ export class App {
|
|
|
224
247
|
}
|
|
225
248
|
if (this.started) {
|
|
226
249
|
if (loadSettingsHandler)
|
|
227
|
-
await this.context.resolve(SettingsHandler).load();
|
|
250
|
+
await this.context.resolve(SettingsHandler, { abstract: true }).load();
|
|
228
251
|
for (const setting of settings)
|
|
229
252
|
await this.registerSettings(setting);
|
|
230
253
|
for (const service of services)
|
|
@@ -263,6 +286,7 @@ export class App {
|
|
|
263
286
|
async initSettingsValue(constructor) {
|
|
264
287
|
const handler = this.context.resolve(SettingsHandler, {
|
|
265
288
|
optional: true,
|
|
289
|
+
abstract: true,
|
|
266
290
|
});
|
|
267
291
|
if (!handler)
|
|
268
292
|
return;
|
|
@@ -302,7 +326,10 @@ export class App {
|
|
|
302
326
|
this.context.unregister(constructor);
|
|
303
327
|
}
|
|
304
328
|
seettingsHandler() {
|
|
305
|
-
return this.context.resolve(SettingsHandler, {
|
|
329
|
+
return this.context.resolve(SettingsHandler, {
|
|
330
|
+
optional: true,
|
|
331
|
+
abstract: true,
|
|
332
|
+
});
|
|
306
333
|
}
|
|
307
334
|
async start() {
|
|
308
335
|
log("starting app");
|
|
@@ -339,6 +366,7 @@ export class App {
|
|
|
339
366
|
this.middlewares.clear();
|
|
340
367
|
this.settings.clear();
|
|
341
368
|
this.api.clear();
|
|
369
|
+
this.apiRef.clear();
|
|
342
370
|
this.settingsHandler = undefined;
|
|
343
371
|
this.sessionHandler = undefined;
|
|
344
372
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dreamkit/app",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "Set of utils to create applications.",
|
|
5
5
|
"homepage": "https://dreamkit.dev",
|
|
6
6
|
"repository": {
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"debug": "^4.4.1",
|
|
30
|
-
"@dreamkit/func": "0.0.
|
|
31
|
-
"@dreamkit/ioc": "0.
|
|
30
|
+
"@dreamkit/func": "0.0.7",
|
|
31
|
+
"@dreamkit/ioc": "0.2.0",
|
|
32
32
|
"@dreamkit/kind": "0.0.3",
|
|
33
|
-
"@dreamkit/
|
|
34
|
-
"@dreamkit/
|
|
33
|
+
"@dreamkit/schema": "0.0.6",
|
|
34
|
+
"@dreamkit/utils": "0.0.6"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/debug": "^4.1.12",
|