@arikajs/foundation 0.0.4 → 0.0.6
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/README.md +25 -23
- package/dist/ObjectPool.d.ts +9 -0
- package/dist/ObjectPool.d.ts.map +1 -0
- package/dist/ObjectPool.js +25 -0
- package/dist/ObjectPool.js.map +1 -0
- package/dist/application/Application.d.ts +47 -15
- package/dist/application/Application.d.ts.map +1 -1
- package/dist/application/Application.js +121 -50
- package/dist/application/Application.js.map +1 -1
- package/dist/container/Container.d.ts +22 -0
- package/dist/container/Container.d.ts.map +1 -1
- package/dist/container/Container.js +60 -7
- package/dist/container/Container.js.map +1 -1
- package/dist/contracts/Application.d.ts +5 -0
- package/dist/contracts/Application.d.ts.map +1 -1
- package/dist/examples/basic.d.ts +3 -0
- package/dist/examples/basic.d.ts.map +1 -0
- package/dist/examples/basic.js +110 -0
- package/dist/examples/basic.js.map +1 -0
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -6
- package/dist/index.js.map +1 -1
- package/dist/src/ObjectPool.d.ts +9 -0
- package/dist/src/ObjectPool.d.ts.map +1 -0
- package/dist/src/ObjectPool.js +25 -0
- package/dist/src/ObjectPool.js.map +1 -0
- package/dist/src/application/Application.d.ts +105 -0
- package/dist/src/application/Application.d.ts.map +1 -0
- package/dist/src/application/Application.js +267 -0
- package/dist/src/application/Application.js.map +1 -0
- package/dist/src/container/Container.d.ts +61 -0
- package/dist/src/container/Container.d.ts.map +1 -0
- package/dist/src/container/Container.js +126 -0
- package/dist/src/container/Container.js.map +1 -0
- package/dist/src/contracts/Application.d.ts +20 -0
- package/dist/src/contracts/Application.d.ts.map +1 -0
- package/dist/src/contracts/Application.js +3 -0
- package/dist/src/contracts/Application.js.map +1 -0
- package/dist/src/contracts/Kernel.d.ts +24 -0
- package/dist/src/contracts/Kernel.d.ts.map +1 -0
- package/dist/src/contracts/Kernel.js +3 -0
- package/dist/src/contracts/Kernel.js.map +1 -0
- package/dist/src/index.d.ts +8 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +28 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/providers/ServiceProvider.d.ts +25 -0
- package/dist/src/providers/ServiceProvider.d.ts.map +1 -0
- package/dist/src/providers/ServiceProvider.js +26 -0
- package/dist/src/providers/ServiceProvider.js.map +1 -0
- package/dist/tests/application.test.d.ts +2 -0
- package/dist/tests/application.test.d.ts.map +1 -0
- package/dist/tests/application.test.js +213 -0
- package/dist/tests/application.test.js.map +1 -0
- package/dist/tests/config.test.d.ts +2 -0
- package/dist/tests/config.test.d.ts.map +1 -0
- package/dist/tests/config.test.js +120 -0
- package/dist/tests/config.test.js.map +1 -0
- package/dist/tests/config_helper.test.d.ts +2 -0
- package/dist/tests/config_helper.test.d.ts.map +1 -0
- package/dist/tests/config_helper.test.js +46 -0
- package/dist/tests/config_helper.test.js.map +1 -0
- package/dist/tests/container.test.d.ts +2 -0
- package/dist/tests/container.test.d.ts.map +1 -0
- package/dist/tests/container.test.js +94 -0
- package/dist/tests/container.test.js.map +1 -0
- package/dist/tests/env.test.d.ts +2 -0
- package/dist/tests/env.test.d.ts.map +1 -0
- package/dist/tests/env.test.js +101 -0
- package/dist/tests/env.test.js.map +1 -0
- package/dist/tests/provider.test.d.ts +2 -0
- package/dist/tests/provider.test.d.ts.map +1 -0
- package/dist/tests/provider.test.js +87 -0
- package/dist/tests/provider.test.js.map +1 -0
- package/dist/tests/timezone.test.d.ts +2 -0
- package/dist/tests/timezone.test.d.ts.map +1 -0
- package/dist/tests/timezone.test.js +47 -0
- package/dist/tests/timezone.test.js.map +1 -0
- package/package.json +13 -11
- package/dist/config/Repository.d.ts +0 -41
- package/dist/config/Repository.d.ts.map +0 -1
- package/dist/config/Repository.js +0 -140
- package/dist/config/Repository.js.map +0 -1
- package/dist/support/EnvLoader.d.ts +0 -15
- package/dist/support/EnvLoader.d.ts.map +0 -1
- package/dist/support/EnvLoader.js +0 -58
- package/dist/support/EnvLoader.js.map +0 -1
- package/dist/support/config.d.ts +0 -18
- package/dist/support/config.d.ts.map +0 -1
- package/dist/support/config.js +0 -29
- package/dist/support/config.js.map +0 -1
- package/dist/support/env.d.ts +0 -9
- package/dist/support/env.d.ts.map +0 -1
- package/dist/support/env.js +0 -32
- package/dist/support/env.js.map +0 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export type Token<T = any> = string | symbol | (new (...args: any[]) => T);
|
|
2
|
+
export type Factory<T = any> = (container: Container) => T;
|
|
3
|
+
/**
|
|
4
|
+
* Lightweight dependency injection container for ArikaJS.
|
|
5
|
+
*
|
|
6
|
+
* Responsible for:
|
|
7
|
+
* - Registering bindings and singletons
|
|
8
|
+
* - Resolving services on demand
|
|
9
|
+
* - Holding pre-built instances
|
|
10
|
+
*/
|
|
11
|
+
export declare class Container {
|
|
12
|
+
private bindings;
|
|
13
|
+
private aliases;
|
|
14
|
+
private tags;
|
|
15
|
+
private extenders;
|
|
16
|
+
/**
|
|
17
|
+
* Bind a token to a factory. Produces a new instance on every resolution.
|
|
18
|
+
*/
|
|
19
|
+
bind<T>(token: Token<T>, factory: Factory<T>): void;
|
|
20
|
+
/**
|
|
21
|
+
* Bind a token as a singleton. The factory runs once and the
|
|
22
|
+
* same instance is returned for all subsequent resolutions.
|
|
23
|
+
*/
|
|
24
|
+
singleton<T>(token: Token<T>, factory: Factory<T>): void;
|
|
25
|
+
/**
|
|
26
|
+
* Directly register an existing instance for a token.
|
|
27
|
+
*/
|
|
28
|
+
instance<T>(token: Token<T>, value: T): void;
|
|
29
|
+
/**
|
|
30
|
+
* Create an alias for a token.
|
|
31
|
+
*/
|
|
32
|
+
alias(token: Token, alias: Token): void;
|
|
33
|
+
/**
|
|
34
|
+
* Assign a tag to a given token.
|
|
35
|
+
*/
|
|
36
|
+
tag(token: Token, tag: string): void;
|
|
37
|
+
/**
|
|
38
|
+
* Resolve all bindings associated with a given tag.
|
|
39
|
+
*/
|
|
40
|
+
tagged<T = any>(tag: string): T[];
|
|
41
|
+
/**
|
|
42
|
+
* Extend a binding in the container.
|
|
43
|
+
*/
|
|
44
|
+
extend<T = any>(token: Token<T>, callback: (instance: T) => T): void;
|
|
45
|
+
/**
|
|
46
|
+
* Resolve a token from the container.
|
|
47
|
+
*/
|
|
48
|
+
make<T>(token: Token<T>): T;
|
|
49
|
+
private getAlias;
|
|
50
|
+
private applyExtenders;
|
|
51
|
+
private instantiate;
|
|
52
|
+
/**
|
|
53
|
+
* Alias for make() - resolves a token from the container.
|
|
54
|
+
*/
|
|
55
|
+
resolve<T>(token: Token<T>): T;
|
|
56
|
+
/**
|
|
57
|
+
* Check whether a token has been registered.
|
|
58
|
+
*/
|
|
59
|
+
has(token: Token): boolean;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=Container.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Container.d.ts","sourceRoot":"","sources":["../../../src/container/Container.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,CAAC,CAAC,GAAG,GAAG,IAAI,MAAM,GAAG,MAAM,GAAG,CAAC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;AAE3E,MAAM,MAAM,OAAO,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,SAAS,EAAE,SAAS,KAAK,CAAC,CAAC;AAQ3D;;;;;;;GAOG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAA6B;IAC7C,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,IAAI,CAA8B;IAC1C,OAAO,CAAC,SAAS,CAAgD;IAEjE;;OAEG;IACH,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI;IAInD;;;OAGG;IACH,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI;IAIxD;;OAEG;IACH,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAQ5C;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI;IAIvC;;OAEG;IACH,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI;IAOpC;;OAEG;IACH,MAAM,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,EAAE;IAKjC;;OAEG;IACH,MAAM,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI;IAQpE;;OAEG;IACH,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;IA0B3B,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,WAAW;IAMnB;;OAEG;IACH,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;IAI9B;;OAEG;IACH,GAAG,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;CAG3B"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Container = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Lightweight dependency injection container for ArikaJS.
|
|
6
|
+
*
|
|
7
|
+
* Responsible for:
|
|
8
|
+
* - Registering bindings and singletons
|
|
9
|
+
* - Resolving services on demand
|
|
10
|
+
* - Holding pre-built instances
|
|
11
|
+
*/
|
|
12
|
+
class Container {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.bindings = new Map();
|
|
15
|
+
this.aliases = new Map();
|
|
16
|
+
this.tags = new Map();
|
|
17
|
+
this.extenders = new Map();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Bind a token to a factory. Produces a new instance on every resolution.
|
|
21
|
+
*/
|
|
22
|
+
bind(token, factory) {
|
|
23
|
+
this.bindings.set(token, { factory, singleton: false });
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Bind a token as a singleton. The factory runs once and the
|
|
27
|
+
* same instance is returned for all subsequent resolutions.
|
|
28
|
+
*/
|
|
29
|
+
singleton(token, factory) {
|
|
30
|
+
this.bindings.set(token, { factory, singleton: true });
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Directly register an existing instance for a token.
|
|
34
|
+
*/
|
|
35
|
+
instance(token, value) {
|
|
36
|
+
this.bindings.set(token, {
|
|
37
|
+
factory: () => value,
|
|
38
|
+
singleton: true,
|
|
39
|
+
instance: value,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Create an alias for a token.
|
|
44
|
+
*/
|
|
45
|
+
alias(token, alias) {
|
|
46
|
+
this.aliases.set(alias, token);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Assign a tag to a given token.
|
|
50
|
+
*/
|
|
51
|
+
tag(token, tag) {
|
|
52
|
+
if (!this.tags.has(tag)) {
|
|
53
|
+
this.tags.set(tag, []);
|
|
54
|
+
}
|
|
55
|
+
this.tags.get(tag)?.push(token);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Resolve all bindings associated with a given tag.
|
|
59
|
+
*/
|
|
60
|
+
tagged(tag) {
|
|
61
|
+
const tokens = this.tags.get(tag) || [];
|
|
62
|
+
return tokens.map(token => this.make(token));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Extend a binding in the container.
|
|
66
|
+
*/
|
|
67
|
+
extend(token, callback) {
|
|
68
|
+
const originalToken = this.getAlias(token);
|
|
69
|
+
if (!this.extenders.has(originalToken)) {
|
|
70
|
+
this.extenders.set(originalToken, []);
|
|
71
|
+
}
|
|
72
|
+
this.extenders.get(originalToken)?.push(callback);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Resolve a token from the container.
|
|
76
|
+
*/
|
|
77
|
+
make(token) {
|
|
78
|
+
const originalToken = this.getAlias(token);
|
|
79
|
+
let binding = this.bindings.get(originalToken);
|
|
80
|
+
if (!binding) {
|
|
81
|
+
if (typeof originalToken === 'function') {
|
|
82
|
+
return this.instantiate(originalToken);
|
|
83
|
+
}
|
|
84
|
+
throw new Error(`Container: no binding found for token "${String(token)}"`);
|
|
85
|
+
}
|
|
86
|
+
let instance;
|
|
87
|
+
if (binding.singleton) {
|
|
88
|
+
if (binding.instance === undefined) {
|
|
89
|
+
binding.instance = binding.factory(this);
|
|
90
|
+
binding.instance = this.applyExtenders(originalToken, binding.instance);
|
|
91
|
+
}
|
|
92
|
+
instance = binding.instance;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
instance = binding.factory(this);
|
|
96
|
+
instance = this.applyExtenders(originalToken, instance);
|
|
97
|
+
}
|
|
98
|
+
return instance;
|
|
99
|
+
}
|
|
100
|
+
getAlias(token) {
|
|
101
|
+
return this.aliases.get(token) || token;
|
|
102
|
+
}
|
|
103
|
+
applyExtenders(token, instance) {
|
|
104
|
+
const extenders = this.extenders.get(token) || [];
|
|
105
|
+
return extenders.reduce((inst, extender) => extender(inst), instance);
|
|
106
|
+
}
|
|
107
|
+
instantiate(constructor) {
|
|
108
|
+
// Basic automatic injection (assumes constructor only takes container)
|
|
109
|
+
// In the future, this will use Reflect metadata for property/param injection
|
|
110
|
+
return new constructor(this);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Alias for make() - resolves a token from the container.
|
|
114
|
+
*/
|
|
115
|
+
resolve(token) {
|
|
116
|
+
return this.make(token);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Check whether a token has been registered.
|
|
120
|
+
*/
|
|
121
|
+
has(token) {
|
|
122
|
+
return this.bindings.has(this.getAlias(token));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.Container = Container;
|
|
126
|
+
//# sourceMappingURL=Container.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Container.js","sourceRoot":"","sources":["../../../src/container/Container.ts"],"names":[],"mappings":";;;AAUA;;;;;;;GAOG;AACH,MAAa,SAAS;IAAtB;QACU,aAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;QACrC,YAAO,GAAG,IAAI,GAAG,EAAgB,CAAC;QAClC,SAAI,GAAG,IAAI,GAAG,EAAmB,CAAC;QAClC,cAAS,GAAG,IAAI,GAAG,EAAqC,CAAC;IAyHnE,CAAC;IAvHC;;OAEG;IACH,IAAI,CAAI,KAAe,EAAE,OAAmB;QAC1C,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACH,SAAS,CAAI,KAAe,EAAE,OAAmB;QAC/C,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACzD,CAAC;IAED;;OAEG;IACH,QAAQ,CAAI,KAAe,EAAE,KAAQ;QACnC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE;YACvB,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK;YACpB,SAAS,EAAE,IAAI;YACf,QAAQ,EAAE,KAAK;SAChB,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAY,EAAE,KAAY;QAC9B,IAAI,CAAC,OAAO,CAA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AC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,OAAO,CAAI,KAAe;QACxB,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,KAAY;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IACjD,CAAC;CACF;AA7HD,8BA6HC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface Application {
|
|
2
|
+
getBasePath(): string;
|
|
3
|
+
getContainer(): any;
|
|
4
|
+
config(): any;
|
|
5
|
+
register(provider: any): void;
|
|
6
|
+
boot(): Promise<void>;
|
|
7
|
+
run(): Promise<void>;
|
|
8
|
+
bind(token: any, factory: any): void;
|
|
9
|
+
singleton(token: any, factory: any): void;
|
|
10
|
+
instance(token: any, value: any): void;
|
|
11
|
+
make<T = any>(token: any): T;
|
|
12
|
+
resolve<T = any>(token: any): T;
|
|
13
|
+
alias(token: any, alias: any): void;
|
|
14
|
+
tag(token: any, tag: string): void;
|
|
15
|
+
tagged<T = any>(tag: string): T[];
|
|
16
|
+
extend<T = any>(token: any, callback: (instance: T) => T): void;
|
|
17
|
+
terminate(): Promise<void>;
|
|
18
|
+
isBooted(): boolean;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=Application.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Application.d.ts","sourceRoot":"","sources":["../../../src/contracts/Application.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,WAAW;IACxB,WAAW,IAAI,MAAM,CAAC;IACtB,YAAY,IAAI,GAAG,CAAC;IACpB,MAAM,IAAI,GAAG,CAAC;IACd,QAAQ,CAAC,QAAQ,EAAE,GAAG,GAAG,IAAI,CAAC;IAC9B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACrB,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,GAAG,IAAI,CAAC;IACrC,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,GAAG,IAAI,CAAC;IAC1C,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI,CAAC;IACvC,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC,CAAC;IAC7B,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC,CAAC;IAChC,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI,CAAC;IACpC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,MAAM,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC;IAClC,MAAM,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;IAChE,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,QAAQ,IAAI,OAAO,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Application.js","sourceRoot":"","sources":["../../../src/contracts/Application.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kernel contract for ArikaJS.
|
|
3
|
+
*
|
|
4
|
+
* Kernels are responsible for handling requests in different contexts:
|
|
5
|
+
* - HTTP kernel handles web requests
|
|
6
|
+
* - CLI kernel handles command-line commands
|
|
7
|
+
* - Queue kernel handles background jobs
|
|
8
|
+
*
|
|
9
|
+
* Foundation only defines the contract - implementations live in
|
|
10
|
+
* higher-level packages like @arikajs/http, @arikajs/cli, etc.
|
|
11
|
+
*/
|
|
12
|
+
export interface Kernel {
|
|
13
|
+
/**
|
|
14
|
+
* Bootstrap the kernel.
|
|
15
|
+
* Called once when the kernel is initialized.
|
|
16
|
+
*/
|
|
17
|
+
bootstrap(): Promise<void> | void;
|
|
18
|
+
/**
|
|
19
|
+
* Handle a request/command/job.
|
|
20
|
+
* The exact signature depends on the kernel type.
|
|
21
|
+
*/
|
|
22
|
+
handle(...args: any[]): Promise<any> | any;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=Kernel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Kernel.d.ts","sourceRoot":"","sources":["../../../src/contracts/Kernel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,WAAW,MAAM;IACrB;;;OAGG;IACH,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAElC;;;OAGG;IACH,MAAM,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;CAC5C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Kernel.js","sourceRoot":"","sources":["../../../src/contracts/Kernel.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { Application } from './application/Application';
|
|
2
|
+
export * from './container/Container';
|
|
3
|
+
export * from './providers/ServiceProvider';
|
|
4
|
+
export * from '@arikajs/config';
|
|
5
|
+
export { Application as ApplicationContract } from './contracts/Application';
|
|
6
|
+
export { Kernel as KernelContract } from './contracts/Kernel';
|
|
7
|
+
export * from './ObjectPool';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAGxD,cAAc,uBAAuB,CAAC;AAGtC,cAAc,6BAA6B,CAAC;AAG5C,cAAc,iBAAiB,CAAC;AAGhC,OAAO,EAAE,WAAW,IAAI,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC7E,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC9D,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Application = void 0;
|
|
18
|
+
// Application
|
|
19
|
+
var Application_1 = require("./application/Application");
|
|
20
|
+
Object.defineProperty(exports, "Application", { enumerable: true, get: function () { return Application_1.Application; } });
|
|
21
|
+
// Container
|
|
22
|
+
__exportStar(require("./container/Container"), exports);
|
|
23
|
+
// Service Providers
|
|
24
|
+
__exportStar(require("./providers/ServiceProvider"), exports);
|
|
25
|
+
// Configuration & Support
|
|
26
|
+
__exportStar(require("@arikajs/config"), exports);
|
|
27
|
+
__exportStar(require("./ObjectPool"), exports);
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,cAAc;AACd,yDAAwD;AAA/C,0GAAA,WAAW,OAAA;AAEpB,YAAY;AACZ,wDAAsC;AAEtC,oBAAoB;AACpB,8DAA4C;AAE5C,0BAA0B;AAC1B,kDAAgC;AAKhC,+CAA6B"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Application } from '../contracts/Application';
|
|
2
|
+
/**
|
|
3
|
+
* Base class for service providers in ArikaJS.
|
|
4
|
+
*
|
|
5
|
+
* Service providers are the primary way to package and register features.
|
|
6
|
+
* They follow a two-phase lifecycle:
|
|
7
|
+
* - register(): Bind services to the container (no heavy side-effects)
|
|
8
|
+
* - boot(): Perform runtime logic after all providers are registered
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class ServiceProvider<T extends Application = Application> {
|
|
11
|
+
protected readonly app: T;
|
|
12
|
+
constructor(app: T);
|
|
13
|
+
/**
|
|
14
|
+
* Register services to the container.
|
|
15
|
+
* This method is called for all providers before any boot() methods run.
|
|
16
|
+
*/
|
|
17
|
+
abstract register(): void | Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Boot the service provider.
|
|
20
|
+
* This method is called after all providers have been registered.
|
|
21
|
+
* Safe to resolve other services here.
|
|
22
|
+
*/
|
|
23
|
+
boot(): void | Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=ServiceProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServiceProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/ServiceProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD;;;;;;;GAOG;AACH,8BAAsB,eAAe,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW;IAC3D,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;gBAAN,GAAG,EAAE,CAAC;IAErC;;;OAGG;IACH,QAAQ,CAAC,QAAQ,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAEzC;;;;OAIG;IACH,IAAI,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;CAG7B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServiceProvider = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Base class for service providers in ArikaJS.
|
|
6
|
+
*
|
|
7
|
+
* Service providers are the primary way to package and register features.
|
|
8
|
+
* They follow a two-phase lifecycle:
|
|
9
|
+
* - register(): Bind services to the container (no heavy side-effects)
|
|
10
|
+
* - boot(): Perform runtime logic after all providers are registered
|
|
11
|
+
*/
|
|
12
|
+
class ServiceProvider {
|
|
13
|
+
constructor(app) {
|
|
14
|
+
this.app = app;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Boot the service provider.
|
|
18
|
+
* This method is called after all providers have been registered.
|
|
19
|
+
* Safe to resolve other services here.
|
|
20
|
+
*/
|
|
21
|
+
boot() {
|
|
22
|
+
// Optional to override
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.ServiceProvider = ServiceProvider;
|
|
26
|
+
//# sourceMappingURL=ServiceProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServiceProvider.js","sourceRoot":"","sources":["../../../src/providers/ServiceProvider.ts"],"names":[],"mappings":";;;AAEA;;;;;;;GAOG;AACH,MAAsB,eAAe;IACnC,YAA+B,GAAM;QAAN,QAAG,GAAH,GAAG,CAAG;IAAI,CAAC;IAQ1C;;;;OAIG;IACH,IAAI;QACF,uBAAuB;IACzB,CAAC;CACF;AAjBD,0CAiBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application.test.d.ts","sourceRoot":"","sources":["../../tests/application.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const node_test_1 = require("node:test");
|
|
40
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
const fs = __importStar(require("fs"));
|
|
43
|
+
const os = __importStar(require("os"));
|
|
44
|
+
const Application_1 = require("../src/application/Application");
|
|
45
|
+
const ServiceProvider_1 = require("../src/providers/ServiceProvider");
|
|
46
|
+
(0, node_test_1.test)('Application: constructor accepts basePath', () => {
|
|
47
|
+
const basePath = __dirname;
|
|
48
|
+
const app = new Application_1.Application(basePath);
|
|
49
|
+
node_assert_1.default.strictEqual(app.getBasePath(), path.resolve(basePath));
|
|
50
|
+
});
|
|
51
|
+
(0, node_test_1.test)('Application: exposes container', () => {
|
|
52
|
+
const app = new Application_1.Application(__dirname);
|
|
53
|
+
const container = app.getContainer();
|
|
54
|
+
node_assert_1.default.ok(container);
|
|
55
|
+
});
|
|
56
|
+
(0, node_test_1.test)('Application: exposes config repository', () => {
|
|
57
|
+
const app = new Application_1.Application(__dirname);
|
|
58
|
+
const config = app.config();
|
|
59
|
+
node_assert_1.default.ok(config);
|
|
60
|
+
});
|
|
61
|
+
(0, node_test_1.test)('Application: can bind services', () => {
|
|
62
|
+
const app = new Application_1.Application(__dirname);
|
|
63
|
+
app.bind('test', () => 'value');
|
|
64
|
+
const value = app.resolve('test');
|
|
65
|
+
node_assert_1.default.strictEqual(value, 'value');
|
|
66
|
+
});
|
|
67
|
+
(0, node_test_1.test)('Application: can register singleton', () => {
|
|
68
|
+
const app = new Application_1.Application(__dirname);
|
|
69
|
+
let callCount = 0;
|
|
70
|
+
app.singleton('counter', () => {
|
|
71
|
+
callCount++;
|
|
72
|
+
return callCount;
|
|
73
|
+
});
|
|
74
|
+
node_assert_1.default.strictEqual(app.resolve('counter'), 1);
|
|
75
|
+
node_assert_1.default.strictEqual(app.resolve('counter'), 1);
|
|
76
|
+
node_assert_1.default.strictEqual(callCount, 1);
|
|
77
|
+
});
|
|
78
|
+
(0, node_test_1.test)('Application: can register instance', () => {
|
|
79
|
+
const app = new Application_1.Application(__dirname);
|
|
80
|
+
const instance = { id: 123 };
|
|
81
|
+
app.instance('instance', instance);
|
|
82
|
+
node_assert_1.default.strictEqual(app.resolve('instance'), instance);
|
|
83
|
+
});
|
|
84
|
+
(0, node_test_1.test)('Application: register() accepts ServiceProvider instance', async () => {
|
|
85
|
+
const app = new Application_1.Application(__dirname);
|
|
86
|
+
let registered = false;
|
|
87
|
+
let booted = false;
|
|
88
|
+
class TestProvider extends ServiceProvider_1.ServiceProvider {
|
|
89
|
+
register() {
|
|
90
|
+
registered = true;
|
|
91
|
+
this.app.instance('test', 'value');
|
|
92
|
+
}
|
|
93
|
+
boot() {
|
|
94
|
+
booted = true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
app.register(new TestProvider(app));
|
|
98
|
+
app.config().set('app.key', 'base64:sm957Y1wUYo8Uj8yL1fD7vX+X6y8gG+E6XpXnJz+I=');
|
|
99
|
+
await app.boot();
|
|
100
|
+
node_assert_1.default.strictEqual(registered, true);
|
|
101
|
+
node_assert_1.default.strictEqual(booted, true);
|
|
102
|
+
node_assert_1.default.strictEqual(app.resolve('test'), 'value');
|
|
103
|
+
});
|
|
104
|
+
(0, node_test_1.test)('Application: register() accepts ServiceProvider class', async () => {
|
|
105
|
+
const app = new Application_1.Application(__dirname);
|
|
106
|
+
let registered = false;
|
|
107
|
+
class TestProvider extends ServiceProvider_1.ServiceProvider {
|
|
108
|
+
register() {
|
|
109
|
+
registered = true;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
app.register(TestProvider);
|
|
113
|
+
app.config().set('app.key', 'base64:sm957Y1wUYo8Uj8yL1fD7vX+X6y8gG+E6XpXnJz+I=');
|
|
114
|
+
await app.boot();
|
|
115
|
+
node_assert_1.default.strictEqual(registered, true);
|
|
116
|
+
});
|
|
117
|
+
(0, node_test_1.test)('Application: boot() runs all register() then all boot()', async () => {
|
|
118
|
+
const app = new Application_1.Application(__dirname);
|
|
119
|
+
const order = [];
|
|
120
|
+
class Provider1 extends ServiceProvider_1.ServiceProvider {
|
|
121
|
+
register() {
|
|
122
|
+
order.push('register1');
|
|
123
|
+
}
|
|
124
|
+
boot() {
|
|
125
|
+
order.push('boot1');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
class Provider2 extends ServiceProvider_1.ServiceProvider {
|
|
129
|
+
register() {
|
|
130
|
+
order.push('register2');
|
|
131
|
+
}
|
|
132
|
+
boot() {
|
|
133
|
+
order.push('boot2');
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
app.register(Provider1);
|
|
137
|
+
app.register(Provider2);
|
|
138
|
+
app.config().set('app.key', 'base64:sm957Y1wUYo8Uj8yL1fD7vX+X6y8gG+E6XpXnJz+I=');
|
|
139
|
+
await app.boot();
|
|
140
|
+
node_assert_1.default.deepStrictEqual(order, ['register1', 'register2', 'boot1', 'boot2']);
|
|
141
|
+
});
|
|
142
|
+
(0, node_test_1.test)('Application: boot() is idempotent', async () => {
|
|
143
|
+
const app = new Application_1.Application(__dirname);
|
|
144
|
+
let bootCount = 0;
|
|
145
|
+
class TestProvider extends ServiceProvider_1.ServiceProvider {
|
|
146
|
+
register() { }
|
|
147
|
+
boot() {
|
|
148
|
+
bootCount++;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
app.register(TestProvider);
|
|
152
|
+
app.config().set('app.key', 'base64:sm957Y1wUYo8Uj8yL1fD7vX+X6y8gG+E6XpXnJz+I=');
|
|
153
|
+
await app.boot();
|
|
154
|
+
await app.boot();
|
|
155
|
+
await app.boot();
|
|
156
|
+
node_assert_1.default.strictEqual(bootCount, 1);
|
|
157
|
+
node_assert_1.default.strictEqual(app.isBooted(), true);
|
|
158
|
+
});
|
|
159
|
+
(0, node_test_1.test)('Application: cannot register providers after boot', async () => {
|
|
160
|
+
const app = new Application_1.Application(__dirname);
|
|
161
|
+
class TestProvider extends ServiceProvider_1.ServiceProvider {
|
|
162
|
+
register() { }
|
|
163
|
+
}
|
|
164
|
+
app.config().set('app.key', 'base64:sm957Y1wUYo8Uj8yL1fD7vX+X6y8gG+E6XpXnJz+I=');
|
|
165
|
+
await app.boot();
|
|
166
|
+
node_assert_1.default.throws(() => {
|
|
167
|
+
app.register(TestProvider);
|
|
168
|
+
}, /Cannot register providers after the application has been booted/);
|
|
169
|
+
});
|
|
170
|
+
(0, node_test_1.test)('Application: run() calls boot() if not booted', async () => {
|
|
171
|
+
const app = new Application_1.Application(__dirname);
|
|
172
|
+
let booted = false;
|
|
173
|
+
class TestProvider extends ServiceProvider_1.ServiceProvider {
|
|
174
|
+
register() { }
|
|
175
|
+
boot() {
|
|
176
|
+
booted = true;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
app.register(TestProvider);
|
|
180
|
+
app.config().set('app.key', 'base64:sm957Y1wUYo8Uj8yL1fD7vX+X6y8gG+E6XpXnJz+I=');
|
|
181
|
+
await app.run();
|
|
182
|
+
node_assert_1.default.strictEqual(booted, true);
|
|
183
|
+
node_assert_1.default.strictEqual(app.isBooted(), true);
|
|
184
|
+
});
|
|
185
|
+
(0, node_test_1.test)('Application: config loads from config directory', async () => {
|
|
186
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'arika-test-'));
|
|
187
|
+
const configDir = path.join(tmpDir, 'config');
|
|
188
|
+
fs.mkdirSync(configDir, { recursive: true });
|
|
189
|
+
// Create a test config file
|
|
190
|
+
const configContent = `module.exports = {
|
|
191
|
+
default: {
|
|
192
|
+
name: 'Test App',
|
|
193
|
+
version: '1.0.0'
|
|
194
|
+
}
|
|
195
|
+
};`;
|
|
196
|
+
fs.writeFileSync(path.join(configDir, 'app.js'), configContent);
|
|
197
|
+
const app = new Application_1.Application(tmpDir);
|
|
198
|
+
app.config().set('app.key', 'base64:sm957Y1wUYo8Uj8yL1fD7vX+X6y8gG+E6XpXnJz+I=');
|
|
199
|
+
await app.boot();
|
|
200
|
+
const name = app.config().get('app.name');
|
|
201
|
+
node_assert_1.default.strictEqual(name, 'Test App');
|
|
202
|
+
// Cleanup
|
|
203
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
204
|
+
});
|
|
205
|
+
(0, node_test_1.test)('Application: config is read-only after boot', async () => {
|
|
206
|
+
const app = new Application_1.Application(__dirname);
|
|
207
|
+
app.config().set('app.key', 'base64:sm957Y1wUYo8Uj8yL1fD7vX+X6y8gG+E6XpXnJz+I=');
|
|
208
|
+
await app.boot();
|
|
209
|
+
node_assert_1.default.throws(() => {
|
|
210
|
+
app.config().loadConfigDirectory(__dirname);
|
|
211
|
+
}, /Configuration cannot be modified after boot/);
|
|
212
|
+
});
|
|
213
|
+
//# sourceMappingURL=application.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application.test.js","sourceRoot":"","sources":["../../tests/application.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAAiC;AACjC,8DAAiC;AACjC,2CAA6B;AAC7B,uCAAyB;AACzB,uCAAyB;AACzB,gEAA6D;AAC7D,sEAAmE;AAEnE,IAAA,gBAAI,EAAC,2CAA2C,EAAE,GAAG,EAAE;IACrD,MAAM,QAAQ,GAAG,SAAS,CAAC;IAC3B,MAAM,GAAG,GAAG,IAAI,yBAAW,CAAC,QAAQ,CAAC,CAAC;IAEtC,qBAAM,CAAC,WAAW,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;AAChE,CAAC,CAAC,CAAC;AAEH,IAAA,gBAAI,EAAC,gCAAgC,EAAE,GAAG,EAAE;IAC1C,MAAM,GAAG,GAAG,IAAI,yBAAW,CAAC,SAAS,CAAC,CAAC;IAE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