assemblerjs 0.0.9 → 0.0.92
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 +14 -0
- package/dist/index.d.ts +12 -1
- package/dist/index.js +68 -27
- package/dist/index.mjs +68 -28
- package/package.json +7 -9
package/README.md
CHANGED
|
@@ -1 +1,15 @@
|
|
|
1
1
|
# assembler.js
|
|
2
|
+
|
|
3
|
+
`assembler.js` name is a tribute to Gilles Deleuze and Felix Guattari concept of [_Agencement_](<https://fr.wikipedia.org/wiki/Agencement_(philosophie)>) (in french) that can be translated into [Assemblage](<https://en.wikipedia.org/wiki/Assemblage_(philosophy)>).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
yarn add assemblerjs
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install assemblerjs
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export declare abstract class AbstractAssembler {
|
|
|
16
16
|
abstract register<T>(injection: Injection<T>): void;
|
|
17
17
|
abstract has<T>(identifier: Identifier<T>): boolean;
|
|
18
18
|
abstract require<T>(identifier: Identifier<T>): T;
|
|
19
|
+
abstract tagged(...tags: string[]): any[];
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
/**
|
|
@@ -32,6 +33,7 @@ export declare const Assemblage: (definition?: AssemblageDefinition) => ClassDec
|
|
|
32
33
|
|
|
33
34
|
declare interface AssemblageDefinition {
|
|
34
35
|
singleton?: false;
|
|
36
|
+
events?: string[];
|
|
35
37
|
inject?: Injection<unknown>[][];
|
|
36
38
|
tags?: string | string[];
|
|
37
39
|
controller?: true;
|
|
@@ -64,9 +66,10 @@ export declare class Assembler implements AbstractAssembler {
|
|
|
64
66
|
* @returns { T } An instance of Concrete<T>.
|
|
65
67
|
*/
|
|
66
68
|
require<T>(identifier: Identifier<T>): T;
|
|
69
|
+
tagged(...tags: string[]): any[];
|
|
67
70
|
}
|
|
68
71
|
|
|
69
|
-
declare class AssemblerContext {
|
|
72
|
+
export declare class AssemblerContext {
|
|
70
73
|
/**
|
|
71
74
|
* User-defined data. Can be used to add properties to context after creation.
|
|
72
75
|
*/
|
|
@@ -74,6 +77,7 @@ declare class AssemblerContext {
|
|
|
74
77
|
register: AbstractAssembler['register'];
|
|
75
78
|
has: AbstractAssembler['has'];
|
|
76
79
|
require: AbstractAssembler['require'];
|
|
80
|
+
tagged: AbstractAssembler['tagged'];
|
|
77
81
|
constructor(assembler: AbstractAssembler);
|
|
78
82
|
/**
|
|
79
83
|
* Add a value to user-defined data.
|
|
@@ -172,6 +176,13 @@ declare class Injectable<T> {
|
|
|
172
176
|
* Injectable assemblage's dependencies passed as 'constructor' parameters.
|
|
173
177
|
*/
|
|
174
178
|
get dependencies(): (Identifier<unknown> | any)[];
|
|
179
|
+
/**
|
|
180
|
+
* Tags passed in assemblage's definition or in its parent definition.
|
|
181
|
+
*/
|
|
182
|
+
get tags(): string[];
|
|
183
|
+
/**
|
|
184
|
+
* Metadatas passed in assemblage's definition or in its parent definition.
|
|
185
|
+
*/
|
|
175
186
|
get metadata(): Record<string, any>;
|
|
176
187
|
}
|
|
177
188
|
|
package/dist/index.js
CHANGED
|
@@ -25,39 +25,65 @@ const getOwnCustomMetadata = (a, o)=>{
|
|
|
25
25
|
return Reflect.getOwnMetadata(`${ReflectCustomPrefix}${a}${ReflectCustomSuffix}`, o);
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
const Assemblage = (
|
|
29
|
-
const
|
|
30
|
-
return (
|
|
31
|
-
defineCustomMetadata(ReflectIsAssemblageFlag, true,
|
|
32
|
-
defineCustomMetadata(ReflectIsSingletonFlag, true,
|
|
33
|
-
for(const
|
|
34
|
-
if (
|
|
35
|
-
switch(
|
|
28
|
+
const Assemblage = (o)=>{
|
|
29
|
+
const n = o || {};
|
|
30
|
+
return (o)=>{
|
|
31
|
+
defineCustomMetadata(ReflectIsAssemblageFlag, true, o);
|
|
32
|
+
defineCustomMetadata(ReflectIsSingletonFlag, true, o);
|
|
33
|
+
for(const r in n){
|
|
34
|
+
if (n.hasOwnProperty(r)) {
|
|
35
|
+
switch(r){
|
|
36
36
|
case 'singleton':
|
|
37
37
|
{
|
|
38
|
-
if (
|
|
39
|
-
defineCustomMetadata(ReflectIsSingletonFlag, false,
|
|
38
|
+
if (n.singleton === false) {
|
|
39
|
+
defineCustomMetadata(ReflectIsSingletonFlag, false, o);
|
|
40
40
|
}
|
|
41
41
|
break;
|
|
42
42
|
}
|
|
43
43
|
case 'controller':
|
|
44
44
|
{
|
|
45
|
-
if (
|
|
46
|
-
if (typeof
|
|
47
|
-
throw new Error(`Controller assemblage '${
|
|
45
|
+
if (n.controller === true) {
|
|
46
|
+
if (typeof n.path !== 'string') {
|
|
47
|
+
throw new Error(`Controller assemblage '${o.name}' must define a path.`);
|
|
48
48
|
}
|
|
49
|
-
defineCustomMetadata(ReflectIsControllerFlag, true,
|
|
49
|
+
defineCustomMetadata(ReflectIsControllerFlag, true, o);
|
|
50
50
|
}
|
|
51
51
|
break;
|
|
52
52
|
}
|
|
53
|
+
case 'tags':
|
|
54
|
+
{
|
|
55
|
+
if (typeof n.tags !== 'undefined') {
|
|
56
|
+
if (typeof n.tags === 'string') {
|
|
57
|
+
defineCustomMetadata('tags', [
|
|
58
|
+
n.tags
|
|
59
|
+
], o);
|
|
60
|
+
} else if (Array.isArray(n.tags)) {
|
|
61
|
+
defineCustomMetadata('tags', n.tags, o);
|
|
62
|
+
} else {
|
|
63
|
+
throw new Error(`Assemblage's 'tags' must be o type 'string' or 'Array'.`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
case 'inject':
|
|
69
|
+
{
|
|
70
|
+
if (!Array.isArray(n.inject)) {
|
|
71
|
+
throw new Error(`Assemblage's definition 'inject' property must be an array of 'Injection' tuples.`);
|
|
72
|
+
}
|
|
73
|
+
for (const r of n.inject){
|
|
74
|
+
if (!Array.isArray(r)) {
|
|
75
|
+
throw new Error(`'Injection' must be an 'Array'.`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
53
79
|
default:
|
|
54
80
|
{
|
|
55
|
-
defineCustomMetadata(
|
|
81
|
+
defineCustomMetadata(r, n[r], o);
|
|
56
82
|
}
|
|
57
83
|
}
|
|
58
84
|
}
|
|
59
85
|
}
|
|
60
|
-
return
|
|
86
|
+
return o;
|
|
61
87
|
};
|
|
62
88
|
};
|
|
63
89
|
|
|
@@ -184,6 +210,9 @@ class Injectable {
|
|
|
184
210
|
get dependencies() {
|
|
185
211
|
return Reflect.getMetadata(ReflectParamTypes, this.concrete) || [];
|
|
186
212
|
}
|
|
213
|
+
get tags() {
|
|
214
|
+
return getCustomMetadata('tags', this.concrete) || [];
|
|
215
|
+
}
|
|
187
216
|
get metadata() {
|
|
188
217
|
return getCustomMetadata('metadata', this.concrete) || {};
|
|
189
218
|
}
|
|
@@ -204,38 +233,40 @@ class Injectable {
|
|
|
204
233
|
}
|
|
205
234
|
}
|
|
206
235
|
|
|
207
|
-
function e$2(e,
|
|
208
|
-
if (
|
|
209
|
-
Object.defineProperty(e,
|
|
210
|
-
value:
|
|
236
|
+
function e$2(e, t, r) {
|
|
237
|
+
if (t in e) {
|
|
238
|
+
Object.defineProperty(e, t, {
|
|
239
|
+
value: r,
|
|
211
240
|
enumerable: true,
|
|
212
241
|
configurable: true,
|
|
213
242
|
writable: true
|
|
214
243
|
});
|
|
215
244
|
} else {
|
|
216
|
-
e[
|
|
245
|
+
e[t] = r;
|
|
217
246
|
}
|
|
218
247
|
return e;
|
|
219
248
|
}
|
|
220
249
|
class AssemblerContext {
|
|
221
|
-
set(e,
|
|
250
|
+
set(e, t) {
|
|
222
251
|
if (this.userData[e]) {
|
|
223
252
|
throw new Error(`Key '${e}' is already defined in context's user data.`);
|
|
224
253
|
}
|
|
225
|
-
this.userData[e] =
|
|
254
|
+
this.userData[e] = t;
|
|
226
255
|
return this;
|
|
227
256
|
}
|
|
228
257
|
get(e) {
|
|
229
258
|
return this.userData[e];
|
|
230
259
|
}
|
|
231
|
-
constructor(
|
|
260
|
+
constructor(t){
|
|
232
261
|
e$2(this, "userData", {});
|
|
233
262
|
e$2(this, "register", undefined);
|
|
234
263
|
e$2(this, "has", undefined);
|
|
235
264
|
e$2(this, "require", undefined);
|
|
236
|
-
this
|
|
237
|
-
this.
|
|
238
|
-
this.
|
|
265
|
+
e$2(this, "tagged", undefined);
|
|
266
|
+
this.register = t.register.bind(t);
|
|
267
|
+
this.has = t.has.bind(t);
|
|
268
|
+
this.require = t.require.bind(t);
|
|
269
|
+
this.tagged = t.tagged.bind(t);
|
|
239
270
|
}
|
|
240
271
|
}
|
|
241
272
|
|
|
@@ -274,6 +305,15 @@ class Assembler {
|
|
|
274
305
|
const t = this.injectables.get(e);
|
|
275
306
|
return t.build();
|
|
276
307
|
}
|
|
308
|
+
tagged(...e) {
|
|
309
|
+
const t = [];
|
|
310
|
+
for (const i of e){
|
|
311
|
+
for (const [e, r] of this.injectables){
|
|
312
|
+
if (r.tags.includes(i)) t.push(r.build());
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return t;
|
|
316
|
+
}
|
|
277
317
|
constructor(r){
|
|
278
318
|
e$1(this, "injectables", new Map());
|
|
279
319
|
e$1(this, "context", undefined);
|
|
@@ -301,6 +341,7 @@ exports.AbstractAssemblage = AbstractAssemblage;
|
|
|
301
341
|
exports.AbstractAssembler = AbstractAssembler;
|
|
302
342
|
exports.Assemblage = Assemblage;
|
|
303
343
|
exports.Assembler = Assembler;
|
|
344
|
+
exports.AssemblerContext = AssemblerContext;
|
|
304
345
|
exports.Configuration = e;
|
|
305
346
|
exports.Context = s;
|
|
306
347
|
exports.Metadata = a;
|
package/dist/index.mjs
CHANGED
|
@@ -21,39 +21,65 @@ const getOwnCustomMetadata = (a, o)=>{
|
|
|
21
21
|
return Reflect.getOwnMetadata(`${ReflectCustomPrefix}${a}${ReflectCustomSuffix}`, o);
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
const Assemblage = (
|
|
25
|
-
const
|
|
26
|
-
return (
|
|
27
|
-
defineCustomMetadata(ReflectIsAssemblageFlag, true,
|
|
28
|
-
defineCustomMetadata(ReflectIsSingletonFlag, true,
|
|
29
|
-
for(const
|
|
30
|
-
if (
|
|
31
|
-
switch(
|
|
24
|
+
const Assemblage = (o)=>{
|
|
25
|
+
const n = o || {};
|
|
26
|
+
return (o)=>{
|
|
27
|
+
defineCustomMetadata(ReflectIsAssemblageFlag, true, o);
|
|
28
|
+
defineCustomMetadata(ReflectIsSingletonFlag, true, o);
|
|
29
|
+
for(const r in n){
|
|
30
|
+
if (n.hasOwnProperty(r)) {
|
|
31
|
+
switch(r){
|
|
32
32
|
case 'singleton':
|
|
33
33
|
{
|
|
34
|
-
if (
|
|
35
|
-
defineCustomMetadata(ReflectIsSingletonFlag, false,
|
|
34
|
+
if (n.singleton === false) {
|
|
35
|
+
defineCustomMetadata(ReflectIsSingletonFlag, false, o);
|
|
36
36
|
}
|
|
37
37
|
break;
|
|
38
38
|
}
|
|
39
39
|
case 'controller':
|
|
40
40
|
{
|
|
41
|
-
if (
|
|
42
|
-
if (typeof
|
|
43
|
-
throw new Error(`Controller assemblage '${
|
|
41
|
+
if (n.controller === true) {
|
|
42
|
+
if (typeof n.path !== 'string') {
|
|
43
|
+
throw new Error(`Controller assemblage '${o.name}' must define a path.`);
|
|
44
44
|
}
|
|
45
|
-
defineCustomMetadata(ReflectIsControllerFlag, true,
|
|
45
|
+
defineCustomMetadata(ReflectIsControllerFlag, true, o);
|
|
46
46
|
}
|
|
47
47
|
break;
|
|
48
48
|
}
|
|
49
|
+
case 'tags':
|
|
50
|
+
{
|
|
51
|
+
if (typeof n.tags !== 'undefined') {
|
|
52
|
+
if (typeof n.tags === 'string') {
|
|
53
|
+
defineCustomMetadata('tags', [
|
|
54
|
+
n.tags
|
|
55
|
+
], o);
|
|
56
|
+
} else if (Array.isArray(n.tags)) {
|
|
57
|
+
defineCustomMetadata('tags', n.tags, o);
|
|
58
|
+
} else {
|
|
59
|
+
throw new Error(`Assemblage's 'tags' must be o type 'string' or 'Array'.`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
case 'inject':
|
|
65
|
+
{
|
|
66
|
+
if (!Array.isArray(n.inject)) {
|
|
67
|
+
throw new Error(`Assemblage's definition 'inject' property must be an array of 'Injection' tuples.`);
|
|
68
|
+
}
|
|
69
|
+
for (const r of n.inject){
|
|
70
|
+
if (!Array.isArray(r)) {
|
|
71
|
+
throw new Error(`'Injection' must be an 'Array'.`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
49
75
|
default:
|
|
50
76
|
{
|
|
51
|
-
defineCustomMetadata(
|
|
77
|
+
defineCustomMetadata(r, n[r], o);
|
|
52
78
|
}
|
|
53
79
|
}
|
|
54
80
|
}
|
|
55
81
|
}
|
|
56
|
-
return
|
|
82
|
+
return o;
|
|
57
83
|
};
|
|
58
84
|
};
|
|
59
85
|
|
|
@@ -180,6 +206,9 @@ class Injectable {
|
|
|
180
206
|
get dependencies() {
|
|
181
207
|
return Reflect.getMetadata(ReflectParamTypes, this.concrete) || [];
|
|
182
208
|
}
|
|
209
|
+
get tags() {
|
|
210
|
+
return getCustomMetadata('tags', this.concrete) || [];
|
|
211
|
+
}
|
|
183
212
|
get metadata() {
|
|
184
213
|
return getCustomMetadata('metadata', this.concrete) || {};
|
|
185
214
|
}
|
|
@@ -200,38 +229,40 @@ class Injectable {
|
|
|
200
229
|
}
|
|
201
230
|
}
|
|
202
231
|
|
|
203
|
-
function e$2(e,
|
|
204
|
-
if (
|
|
205
|
-
Object.defineProperty(e,
|
|
206
|
-
value:
|
|
232
|
+
function e$2(e, t, r) {
|
|
233
|
+
if (t in e) {
|
|
234
|
+
Object.defineProperty(e, t, {
|
|
235
|
+
value: r,
|
|
207
236
|
enumerable: true,
|
|
208
237
|
configurable: true,
|
|
209
238
|
writable: true
|
|
210
239
|
});
|
|
211
240
|
} else {
|
|
212
|
-
e[
|
|
241
|
+
e[t] = r;
|
|
213
242
|
}
|
|
214
243
|
return e;
|
|
215
244
|
}
|
|
216
245
|
class AssemblerContext {
|
|
217
|
-
set(e,
|
|
246
|
+
set(e, t) {
|
|
218
247
|
if (this.userData[e]) {
|
|
219
248
|
throw new Error(`Key '${e}' is already defined in context's user data.`);
|
|
220
249
|
}
|
|
221
|
-
this.userData[e] =
|
|
250
|
+
this.userData[e] = t;
|
|
222
251
|
return this;
|
|
223
252
|
}
|
|
224
253
|
get(e) {
|
|
225
254
|
return this.userData[e];
|
|
226
255
|
}
|
|
227
|
-
constructor(
|
|
256
|
+
constructor(t){
|
|
228
257
|
e$2(this, "userData", {});
|
|
229
258
|
e$2(this, "register", undefined);
|
|
230
259
|
e$2(this, "has", undefined);
|
|
231
260
|
e$2(this, "require", undefined);
|
|
232
|
-
this
|
|
233
|
-
this.
|
|
234
|
-
this.
|
|
261
|
+
e$2(this, "tagged", undefined);
|
|
262
|
+
this.register = t.register.bind(t);
|
|
263
|
+
this.has = t.has.bind(t);
|
|
264
|
+
this.require = t.require.bind(t);
|
|
265
|
+
this.tagged = t.tagged.bind(t);
|
|
235
266
|
}
|
|
236
267
|
}
|
|
237
268
|
|
|
@@ -270,6 +301,15 @@ class Assembler {
|
|
|
270
301
|
const t = this.injectables.get(e);
|
|
271
302
|
return t.build();
|
|
272
303
|
}
|
|
304
|
+
tagged(...e) {
|
|
305
|
+
const t = [];
|
|
306
|
+
for (const i of e){
|
|
307
|
+
for (const [e, r] of this.injectables){
|
|
308
|
+
if (r.tags.includes(i)) t.push(r.build());
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return t;
|
|
312
|
+
}
|
|
273
313
|
constructor(r){
|
|
274
314
|
e$1(this, "injectables", new Map());
|
|
275
315
|
e$1(this, "context", undefined);
|
|
@@ -293,4 +333,4 @@ const s = m(ReflectContextParamIndex);
|
|
|
293
333
|
const e = m(ReflectConfigurationParamIndex);
|
|
294
334
|
const a = m(ReflectMetadataParamIndex);
|
|
295
335
|
|
|
296
|
-
export { AbstractAssemblage, AbstractAssembler, Assemblage, Assembler, e as Configuration, s as Context, a as Metadata };
|
|
336
|
+
export { AbstractAssemblage, AbstractAssembler, Assemblage, Assembler, AssemblerContext, e as Configuration, s as Context, a as Metadata };
|
package/package.json
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assemblerjs",
|
|
3
3
|
"description": "A simple and zero-dependency DI package written in typescript.",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.92",
|
|
5
5
|
"author": "Benoît LAHOZ <info@benoitlahoz.io>",
|
|
6
|
-
"
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/benoitlahoz/assemblerjs"
|
|
9
|
-
},
|
|
10
|
-
"bugs": {
|
|
11
|
-
"url": "https://github.com/benoitlahoz/assemblerjs/issues"
|
|
12
|
-
},
|
|
13
|
-
"homepage": "https://github.com/benoitlahoz/assemblerjs#README",
|
|
6
|
+
"bugs": "https://github.com/benoitlahoz/assemblerjs/issues",
|
|
14
7
|
"devDependencies": {
|
|
15
8
|
"@swc/core": "^1.9.3",
|
|
16
9
|
"@types/node": "^22.5.5",
|
|
@@ -36,6 +29,7 @@
|
|
|
36
29
|
"dist/**/*",
|
|
37
30
|
"README.md"
|
|
38
31
|
],
|
|
32
|
+
"homepage": "https://github.com/benoitlahoz/assemblerjs#README",
|
|
39
33
|
"keywords": [
|
|
40
34
|
"composition",
|
|
41
35
|
"decorators",
|
|
@@ -48,6 +42,10 @@
|
|
|
48
42
|
],
|
|
49
43
|
"license": "MIT",
|
|
50
44
|
"main": "dist/index.js",
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "git+https://github.com/benoitlahoz/assemblerjs.git"
|
|
48
|
+
},
|
|
51
49
|
"scripts": {
|
|
52
50
|
"build": "vite build",
|
|
53
51
|
"coverage": "vitest run --coverage --passWithNoTests && istanbul-badges-readme",
|