@microphi/json-db 2.2.0
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 +12 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/lib/lib/aspects/after.decorator.d.ts +35 -0
- package/lib/lib/aspects/after.decorator.d.ts.map +1 -0
- package/lib/lib/aspects/after.decorator.js +45 -0
- package/lib/lib/aspects/after.decorator.js.map +1 -0
- package/lib/lib/aspects/before.decorator.d.ts +28 -0
- package/lib/lib/aspects/before.decorator.d.ts.map +1 -0
- package/lib/lib/aspects/before.decorator.js +46 -0
- package/lib/lib/aspects/before.decorator.js.map +1 -0
- package/lib/lib/container/bootstrap.d.ts +3 -0
- package/lib/lib/container/bootstrap.d.ts.map +1 -0
- package/lib/lib/container/bootstrap.js +15 -0
- package/lib/lib/container/bootstrap.js.map +1 -0
- package/lib/lib/container/di.decorator.d.ts +10 -0
- package/lib/lib/container/di.decorator.d.ts.map +1 -0
- package/lib/lib/container/di.decorator.js +15 -0
- package/lib/lib/container/di.decorator.js.map +1 -0
- package/lib/lib/container/graph.d.ts +171 -0
- package/lib/lib/container/graph.d.ts.map +1 -0
- package/lib/lib/container/graph.js +429 -0
- package/lib/lib/container/graph.js.map +1 -0
- package/lib/lib/injctable/inject.decorator.d.ts +7 -0
- package/lib/lib/injctable/inject.decorator.d.ts.map +1 -0
- package/lib/lib/injctable/inject.decorator.js +31 -0
- package/lib/lib/injctable/inject.decorator.js.map +1 -0
- package/lib/lib/injctable/injectable.decorator.d.ts +16 -0
- package/lib/lib/injctable/injectable.decorator.d.ts.map +1 -0
- package/lib/lib/injctable/injectable.decorator.js +52 -0
- package/lib/lib/injctable/injectable.decorator.js.map +1 -0
- package/lib/lib/injctable/injector.d.ts +4 -0
- package/lib/lib/injctable/injector.d.ts.map +1 -0
- package/lib/lib/injctable/injector.js +25 -0
- package/lib/lib/injctable/injector.js.map +1 -0
- package/lib/lib/list/list.d.ts +28 -0
- package/lib/lib/list/list.d.ts.map +1 -0
- package/lib/lib/list/list.js +94 -0
- package/lib/lib/list/list.js.map +1 -0
- package/lib/lib/provider/providers.d.ts +15 -0
- package/lib/lib/provider/providers.d.ts.map +1 -0
- package/lib/lib/provider/providers.js +80 -0
- package/lib/lib/provider/providers.js.map +1 -0
- package/lib/lib/scan.d.ts +3 -0
- package/lib/lib/scan.d.ts.map +1 -0
- package/lib/lib/scan.js +19 -0
- package/lib/lib/scan.js.map +1 -0
- package/lib/lib/testing/mocked.d.ts +9 -0
- package/lib/lib/testing/mocked.d.ts.map +1 -0
- package/lib/lib/testing/mocked.js +58 -0
- package/lib/lib/testing/mocked.js.map +1 -0
- package/lib/lib/testing/test-bed.d.ts +7 -0
- package/lib/lib/testing/test-bed.d.ts.map +1 -0
- package/lib/lib/testing/test-bed.js +20 -0
- package/lib/lib/testing/test-bed.js.map +1 -0
- package/lib/lib/types.d.ts +10 -0
- package/lib/lib/types.d.ts.map +1 -0
- package/lib/lib/types.js +4 -0
- package/lib/lib/types.js.map +1 -0
- package/package.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @microphi/json-db [](https://badge.fury.io/js/%40microphi%2Fjson-db)
|
|
2
|
+
|
|
3
|
+
> Small, fast and simple file based json-db
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
With your preferend package manager install
|
|
7
|
+
```
|
|
8
|
+
@microphi/json-db
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## How to use
|
|
12
|
+
> TBD
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
package/lib/index.js
ADDED
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC","sourcesContent":["export * from './lib/list/list';\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs the `fn` after the annotated method
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Decorate a method to execute `fn` after it.
|
|
6
|
+
* `fn` params will be the same type as the decorated return type and it __must__ return this same type.
|
|
7
|
+
* To have type checking you need to provide type information into this decorator generics.
|
|
8
|
+
* `fn` can __must__ return that same type or void.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* class TestClass {
|
|
13
|
+
*
|
|
14
|
+
* @After<string>((salutation) => {
|
|
15
|
+
* return salutation.toUpperCase();
|
|
16
|
+
* })
|
|
17
|
+
* public testA(name: string): string {
|
|
18
|
+
* return `Hello ${name}!`;
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* @After<string>((salutation) => {
|
|
22
|
+
* return salutation.toLowerCase();
|
|
23
|
+
* })
|
|
24
|
+
* public testB(name: string, nickname: string): string {
|
|
25
|
+
* return `Hello ${name} aka ${nickname}!`;
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @param fn
|
|
33
|
+
*/
|
|
34
|
+
export declare function After<I, O = I>(fn: (args: I) => O): MethodDecorator;
|
|
35
|
+
//# sourceMappingURL=after.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"after.decorator.d.ts","sourceRoot":"","sources":["../../../src/lib/aspects/after.decorator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,eAAe,CAqBnE"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs the `fn` after the annotated method
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Decorate a method to execute `fn` after it.
|
|
6
|
+
* `fn` params will be the same type as the decorated return type and it __must__ return this same type.
|
|
7
|
+
* To have type checking you need to provide type information into this decorator generics.
|
|
8
|
+
* `fn` can __must__ return that same type or void.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* class TestClass {
|
|
13
|
+
*
|
|
14
|
+
* @After<string>((salutation) => {
|
|
15
|
+
* return salutation.toUpperCase();
|
|
16
|
+
* })
|
|
17
|
+
* public testA(name: string): string {
|
|
18
|
+
* return `Hello ${name}!`;
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* @After<string>((salutation) => {
|
|
22
|
+
* return salutation.toLowerCase();
|
|
23
|
+
* })
|
|
24
|
+
* public testB(name: string, nickname: string): string {
|
|
25
|
+
* return `Hello ${name} aka ${nickname}!`;
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @param fn
|
|
33
|
+
*/
|
|
34
|
+
export function After(fn) {
|
|
35
|
+
return (target, key, descriptor) => {
|
|
36
|
+
const originalMethod = descriptor.value;
|
|
37
|
+
descriptor.value = function () {
|
|
38
|
+
// eslint-disable-next-line prefer-rest-params
|
|
39
|
+
const retValue = originalMethod.apply(this, arguments);
|
|
40
|
+
return fn.apply(this, [retValue]);
|
|
41
|
+
};
|
|
42
|
+
return descriptor;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=after.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"after.decorator.js","sourceRoot":"","sources":["../../../src/lib/aspects/after.decorator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,UAAU,KAAK,CAAW,EAAkB;IAGhD,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,UAA8B,EAAE,EAAE;QAGrD,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,UAAU,CAAC,KAAK,GAAG;YAGjB,8CAA8C;YAC9C,MAAM,QAAQ,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;YAEvD,OAAO,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;QAGpC,CAAC,CAAC;QAEF,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Runs the `fn` after the annotated method\n *\n * @remarks\n * Decorate a method to execute `fn` after it.\n * `fn` params will be the same type as the decorated return type and it __must__ return this same type.\n * To have type checking you need to provide type information into this decorator generics.\n * `fn` can __must__ return that same type or void.\n *\n * @example\n * ```typescript\n * class TestClass {\n *\n * @After<string>((salutation) => {\n * return salutation.toUpperCase();\n * })\n * public testA(name: string): string {\n * return `Hello ${name}!`;\n * }\n *\n * @After<string>((salutation) => {\n * return salutation.toLowerCase();\n * })\n * public testB(name: string, nickname: string): string {\n * return `Hello ${name} aka ${nickname}!`;\n * }\n *\n * }\n *\n * ```\n *\n * @param fn\n */\nexport function After<I, O = I>(fn: (args: I) => O): MethodDecorator {\n\n\n return (target, key, descriptor: PropertyDescriptor) => {\n\n\n const originalMethod = descriptor.value;\n\n descriptor.value = function() {\n\n\n // eslint-disable-next-line prefer-rest-params\n const retValue = originalMethod.apply(this, arguments);\n\n return fn.apply(this, [retValue]);\n\n\n };\n\n return descriptor;\n };\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs the `fn` before the annotated method
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Decorate a method to execute `fn` before it.
|
|
6
|
+
* `fn` params will be the same type as the decorated function and it __must__ return the same type.
|
|
7
|
+
* To have type checking you need to provide type information into this decorator generics.
|
|
8
|
+
* `fn` can __must__ return this same type or void.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // basic example
|
|
13
|
+
* class TestClass {
|
|
14
|
+
*
|
|
15
|
+
* @Before<string>((name) => {
|
|
16
|
+
* return name.toUpperCase();
|
|
17
|
+
* })
|
|
18
|
+
* public simpleParamSimpleType(name: string) {
|
|
19
|
+
* return `hello ${name}`;
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
* For more example see `before.decorator.spec.ts`
|
|
24
|
+
*
|
|
25
|
+
* @param fn
|
|
26
|
+
*/
|
|
27
|
+
export declare function Before<P>(fn: (args: P) => P): MethodDecorator;
|
|
28
|
+
//# sourceMappingURL=before.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"before.decorator.d.ts","sourceRoot":"","sources":["../../../src/lib/aspects/before.decorator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,eAAe,CAyB7D"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs the `fn` before the annotated method
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Decorate a method to execute `fn` before it.
|
|
6
|
+
* `fn` params will be the same type as the decorated function and it __must__ return the same type.
|
|
7
|
+
* To have type checking you need to provide type information into this decorator generics.
|
|
8
|
+
* `fn` can __must__ return this same type or void.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // basic example
|
|
13
|
+
* class TestClass {
|
|
14
|
+
*
|
|
15
|
+
* @Before<string>((name) => {
|
|
16
|
+
* return name.toUpperCase();
|
|
17
|
+
* })
|
|
18
|
+
* public simpleParamSimpleType(name: string) {
|
|
19
|
+
* return `hello ${name}`;
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
* For more example see `before.decorator.spec.ts`
|
|
24
|
+
*
|
|
25
|
+
* @param fn
|
|
26
|
+
*/
|
|
27
|
+
export function Before(fn) {
|
|
28
|
+
return (target, key, descriptor) => {
|
|
29
|
+
const originalMethod = descriptor.value;
|
|
30
|
+
// use function() to keep original `this`
|
|
31
|
+
descriptor.value = function () {
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
// eslint-disable-next-line prefer-rest-params
|
|
34
|
+
const retValue = fn.bind(this).apply(this, arguments);
|
|
35
|
+
// so here we can call originalMethod with retValue
|
|
36
|
+
// doing so beforeFn has the ability to change original arguments's values
|
|
37
|
+
if (retValue === undefined) {
|
|
38
|
+
// eslint-disable-next-line prefer-rest-params
|
|
39
|
+
return originalMethod.apply(this, arguments);
|
|
40
|
+
}
|
|
41
|
+
return originalMethod.apply(this, [].concat(retValue));
|
|
42
|
+
};
|
|
43
|
+
return descriptor;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=before.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"before.decorator.js","sourceRoot":"","sources":["../../../src/lib/aspects/before.decorator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,MAAM,CAAI,EAAkB;IAE1C,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,UAA8B,EAAE,EAAE;QAErD,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,yCAAyC;QACzC,UAAU,CAAC,KAAK,GAAG;YAEjB,aAAa;YACb,8CAA8C;YAC9C,MAAM,QAAQ,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAQ,CAAC;YAE7D,mDAAmD;YACnD,0EAA0E;YAC1E,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC3B,8CAA8C;gBAC9C,OAAO,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;YAC/C,CAAC;YAED,OAAO,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QACzD,CAAC,CAAC;QAEF,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Runs the `fn` before the annotated method\n *\n * @remarks\n * Decorate a method to execute `fn` before it.\n * `fn` params will be the same type as the decorated function and it __must__ return the same type.\n * To have type checking you need to provide type information into this decorator generics.\n * `fn` can __must__ return this same type or void.\n *\n * @example\n * ```typescript\n * // basic example\n * class TestClass {\n *\n * @Before<string>((name) => {\n * return name.toUpperCase();\n * })\n * public simpleParamSimpleType(name: string) {\n * return `hello ${name}`;\n * }\n * }\n * ```\n * For more example see `before.decorator.spec.ts`\n *\n * @param fn\n */\nexport function Before<P>(fn: (args: P) => P): MethodDecorator {\n\n return (target, key, descriptor: PropertyDescriptor) => {\n\n const originalMethod = descriptor.value;\n\n // use function() to keep original `this`\n descriptor.value = function() {\n\n // @ts-ignore\n // eslint-disable-next-line prefer-rest-params\n const retValue = fn.bind(this).apply(this, arguments) as any;\n\n // so here we can call originalMethod with retValue\n // doing so beforeFn has the ability to change original arguments's values\n if (retValue === undefined) {\n // eslint-disable-next-line prefer-rest-params\n return originalMethod.apply(this, arguments);\n }\n\n return originalMethod.apply(this, [].concat(retValue));\n };\n\n return descriptor;\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../../src/lib/container/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAO3C,wBAAgB,SAAS,CAAC,GAAG,EAAE,KAAK,GAAG,QAAQ,CAc9C"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getDIMetadata, providers } from '../container/di.decorator';
|
|
2
|
+
import { getDebugger } from '@microphi/debug';
|
|
3
|
+
import { injector } from '../injctable/injector';
|
|
4
|
+
const d = getDebugger('microphi:di:bootstrap');
|
|
5
|
+
export function bootstrap(app) {
|
|
6
|
+
const options = getDIMetadata(app);
|
|
7
|
+
d('adding', app, 'to providers');
|
|
8
|
+
providers.addInjectable(app);
|
|
9
|
+
options.providers?.forEach((provider) => {
|
|
10
|
+
d('configuring provider', provider);
|
|
11
|
+
providers.addInjectable(provider);
|
|
12
|
+
});
|
|
13
|
+
return injector(app);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=bootstrap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../../src/lib/container/bootstrap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,MAAM,CAAC,GAAG,WAAW,CAAC,uBAAuB,CAAC,CAAC;AAE/C,MAAM,UAAU,SAAS,CAAC,GAAU;IAClC,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IAEnC,CAAC,CAAC,QAAQ,EAAE,GAAG,EAAE,cAAc,CAAC,CAAC;IAGjC,SAAS,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAE7B,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;QACtC,CAAC,CAAC,sBAAsB,EAAE,QAAQ,CAAC,CAAC;QACpC,SAAS,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC","sourcesContent":["import { Instance, Klass } from '../types';\nimport { getDIMetadata, providers } from '../container/di.decorator';\nimport { getDebugger } from '@microphi/debug';\nimport { injector } from '../injctable/injector';\n\nconst d = getDebugger('microphi:di:bootstrap');\n\nexport function bootstrap(app: Klass): Instance {\n const options = getDIMetadata(app);\n\n d('adding', app, 'to providers');\n\n\n providers.addInjectable(app);\n\n options.providers?.forEach((provider) => {\n d('configuring provider', provider);\n providers.addInjectable(provider);\n });\n\n return injector(app);\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Klass, Provider } from '../types';
|
|
2
|
+
import { Providers } from '../provider/providers';
|
|
3
|
+
export declare const providers: Providers;
|
|
4
|
+
export interface DIOptions {
|
|
5
|
+
providers: Provider[];
|
|
6
|
+
}
|
|
7
|
+
export declare const DISymbol: unique symbol;
|
|
8
|
+
export declare function DI(options: DIOptions): (target: any) => any;
|
|
9
|
+
export declare function getDIMetadata(target: Klass): DIOptions;
|
|
10
|
+
//# sourceMappingURL=di.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"di.decorator.d.ts","sourceRoot":"","sources":["../../../src/lib/container/di.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGlD,eAAO,MAAM,SAAS,WAAkB,CAAC;AAEzC,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,QAAQ,EAAE,CAAC;CACvB;AAED,eAAO,MAAM,QAAQ,eAAgB,CAAC;AAEtC,wBAAgB,EAAE,CAAC,OAAO,EAAE,SAAS,wBAMpC;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,KAAK,GAAG,SAAS,CAEtD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Providers } from '../provider/providers';
|
|
2
|
+
import { ClassNameSymbol, InjectableDecorator } from '../injctable/injectable.decorator';
|
|
3
|
+
export const providers = new Providers();
|
|
4
|
+
export const DISymbol = Symbol('@DI');
|
|
5
|
+
export function DI(options) {
|
|
6
|
+
return (target) => {
|
|
7
|
+
target[ClassNameSymbol] = 'root';
|
|
8
|
+
Reflect.metadata(DISymbol, options)(target);
|
|
9
|
+
return InjectableDecorator(target);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export function getDIMetadata(target) {
|
|
13
|
+
return Reflect.getMetadata(DISymbol, target);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=di.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"di.decorator.js","sourceRoot":"","sources":["../../../src/lib/container/di.decorator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAEzF,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC;AAMzC,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AAEtC,MAAM,UAAU,EAAE,CAAC,OAAkB;IACnC,OAAO,CAAC,MAAM,EAAE,EAAE;QAChB,MAAM,CAAC,eAAe,CAAC,GAAG,MAAM,CAAC;QACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;QAC5C,OAAO,mBAAmB,CAAC,MAAM,CAAC,CAAC;IACrC,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,MAAa;IACzC,OAAO,OAAO,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import { Klass, Provider } from '../types';\nimport { Providers } from '../provider/providers';\nimport { ClassNameSymbol, InjectableDecorator } from '../injctable/injectable.decorator';\n\nexport const providers = new Providers();\n\nexport interface DIOptions {\n providers: Provider[];\n}\n\nexport const DISymbol = Symbol('@DI');\n\nexport function DI(options: DIOptions) {\n return (target) => {\n target[ClassNameSymbol] = 'root';\n Reflect.metadata(DISymbol, options)(target);\n return InjectableDecorator(target);\n };\n}\n\nexport function getDIMetadata(target: Klass): DIOptions {\n return Reflect.getMetadata(DISymbol, target);\n}\n"]}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
export type NodeId = string;
|
|
2
|
+
export type EdgeWeight = number;
|
|
3
|
+
export type EncodedEdge = string;
|
|
4
|
+
export interface Serialized {
|
|
5
|
+
nodes: {
|
|
6
|
+
id: NodeId;
|
|
7
|
+
}[];
|
|
8
|
+
links: {
|
|
9
|
+
source: NodeId;
|
|
10
|
+
target: NodeId;
|
|
11
|
+
weight: EdgeWeight;
|
|
12
|
+
}[];
|
|
13
|
+
}
|
|
14
|
+
export declare class CycleError extends Error {
|
|
15
|
+
constructor(message: string);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A graph data structure with depth-first search and topological sort.
|
|
19
|
+
*/
|
|
20
|
+
export declare class Graph {
|
|
21
|
+
/**
|
|
22
|
+
* The adjacency list of the graph.
|
|
23
|
+
* Keys are node ids.
|
|
24
|
+
* Values are adjacent node id arrays.
|
|
25
|
+
*/
|
|
26
|
+
edges: Record<NodeId, NodeId[]>;
|
|
27
|
+
/**
|
|
28
|
+
* The weights of edges.
|
|
29
|
+
* Keys are string encodings of edges.
|
|
30
|
+
* Values are weights (numbers).
|
|
31
|
+
*/
|
|
32
|
+
edgeWeights: Record<EncodedEdge, EdgeWeight>;
|
|
33
|
+
constructor(serialized?: Serialized);
|
|
34
|
+
/**
|
|
35
|
+
* Deserializes the given serialized graph.
|
|
36
|
+
* @param serialized
|
|
37
|
+
*/
|
|
38
|
+
deserialize(serialized: Serialized): this;
|
|
39
|
+
/**
|
|
40
|
+
* Gets the adjacent node list for the given node.
|
|
41
|
+
* Returns an empty array for unknown nodes.
|
|
42
|
+
* @param node
|
|
43
|
+
*/
|
|
44
|
+
adjacent(node: NodeId): NodeId[];
|
|
45
|
+
/**
|
|
46
|
+
* Adds a node to the graph.
|
|
47
|
+
* If node was already added, this function does nothing.
|
|
48
|
+
* If node was not already added, this function sets up an empty adjacency list.
|
|
49
|
+
* @param node
|
|
50
|
+
*/
|
|
51
|
+
addNode(node: NodeId): this;
|
|
52
|
+
/**
|
|
53
|
+
* Adds an edge from node u to node v.
|
|
54
|
+
* Implicitly adds the nodes if they were not already added.
|
|
55
|
+
* @param u
|
|
56
|
+
* @param v
|
|
57
|
+
* @param weight
|
|
58
|
+
*/
|
|
59
|
+
addEdge(u: NodeId, v: NodeId, weight?: EdgeWeight): this;
|
|
60
|
+
/**
|
|
61
|
+
* Sets the weight of the given edge.
|
|
62
|
+
* @param u
|
|
63
|
+
* @param v
|
|
64
|
+
* @param weight
|
|
65
|
+
*/
|
|
66
|
+
setEdgeWeight(u: NodeId, v: NodeId, weight: EdgeWeight): this;
|
|
67
|
+
/**
|
|
68
|
+
* Computes a string encoding of an edge,
|
|
69
|
+
* for use as a key in an object.
|
|
70
|
+
* @param u
|
|
71
|
+
* @param v
|
|
72
|
+
*/
|
|
73
|
+
encodeEdge(u: NodeId, v: NodeId): EncodedEdge;
|
|
74
|
+
/**
|
|
75
|
+
* Removes a node from the graph.
|
|
76
|
+
* Also removes incoming and outgoing edges.
|
|
77
|
+
* @param node
|
|
78
|
+
*/
|
|
79
|
+
removeNode(node: NodeId): this;
|
|
80
|
+
/**
|
|
81
|
+
* Gets the list of nodes that have been added to the graph.
|
|
82
|
+
*/
|
|
83
|
+
nodes(): NodeId[];
|
|
84
|
+
/**
|
|
85
|
+
* Gets the weight of the given edge.
|
|
86
|
+
* Returns 1 if no weight was previously set.
|
|
87
|
+
* @param u
|
|
88
|
+
* @param v
|
|
89
|
+
*/
|
|
90
|
+
getEdgeWeight(u: NodeId, v: NodeId): EdgeWeight;
|
|
91
|
+
/**
|
|
92
|
+
* Removes the edge from node u to node v.
|
|
93
|
+
* Does not remove the nodes.
|
|
94
|
+
* Does nothing if the edge does not exist.
|
|
95
|
+
* @param u
|
|
96
|
+
* @param v
|
|
97
|
+
*/
|
|
98
|
+
removeEdge(u: NodeId, v: NodeId): this;
|
|
99
|
+
/**
|
|
100
|
+
* Returns true if there is an edge from node u to node v.
|
|
101
|
+
* @param u
|
|
102
|
+
* @param v
|
|
103
|
+
*/
|
|
104
|
+
hasEdge(u: NodeId, v: NodeId): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Computes the indegree for the given node.
|
|
107
|
+
* Not very efficient, costs O(E) where E = number of edges.
|
|
108
|
+
*
|
|
109
|
+
* @param node
|
|
110
|
+
*/
|
|
111
|
+
inDegree(node: NodeId): number;
|
|
112
|
+
/**
|
|
113
|
+
* Computes the outdegree for the given node.
|
|
114
|
+
*
|
|
115
|
+
* @param node
|
|
116
|
+
*/
|
|
117
|
+
outDegree(node: NodeId): number;
|
|
118
|
+
/**
|
|
119
|
+
* Depth First Search algorithm, inspired by
|
|
120
|
+
* Cormen et al. 'Introduction to Algorithms' 3rd Ed. p. 604
|
|
121
|
+
* The additional option `includeSourceNodes` specifies whether to
|
|
122
|
+
* include or exclude the source nodes from the result (true by default).
|
|
123
|
+
* If `sourceNodes` is not specified, all nodes in the graph
|
|
124
|
+
* are used as source nodes.
|
|
125
|
+
*
|
|
126
|
+
* @param sourceNodes
|
|
127
|
+
* @param includeSourceNodes
|
|
128
|
+
* @param errorOnCycle
|
|
129
|
+
*/
|
|
130
|
+
depthFirstSearch(sourceNodes: NodeId[] | undefined, includeSourceNodes?: boolean, errorOnCycle?: boolean): string[];
|
|
131
|
+
/**
|
|
132
|
+
* Returns true if the graph has one or more cycles and false otherwise
|
|
133
|
+
*/
|
|
134
|
+
hasCycle(): boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Least Common Ancestors
|
|
137
|
+
* Inspired by https://github.com/relaxedws/lca/blob/master/src/LowestCommonAncestor.php code
|
|
138
|
+
* but uses depth search instead of breadth. Also uses some optimizations
|
|
139
|
+
*
|
|
140
|
+
* @param node1
|
|
141
|
+
* @param node2
|
|
142
|
+
*/
|
|
143
|
+
lowestCommonAncestors(node1: NodeId, node2: NodeId): string[];
|
|
144
|
+
/**
|
|
145
|
+
* The topological sort algorithm yields a list of visited nodes
|
|
146
|
+
* such that for each visited edge (u, v), u comes before v in the list.
|
|
147
|
+
* Amazingly, this comes from just reversing the result from depth first search.
|
|
148
|
+
* Cormen et al. 'Introduction to Algorithms' 3rd Ed. p. 613
|
|
149
|
+
*
|
|
150
|
+
* @param sourceNodes
|
|
151
|
+
* @param includeSourceNodes
|
|
152
|
+
*/
|
|
153
|
+
topologicalSort(sourceNodes?: NodeId[], includeSourceNodes?: boolean): string[];
|
|
154
|
+
/**
|
|
155
|
+
* Dijkstra's Shortest Path Algorithm.
|
|
156
|
+
* Cormen et al. 'Introduction to Algorithms' 3rd Ed. p. 658
|
|
157
|
+
* Variable and function names correspond to names in the book.
|
|
158
|
+
*
|
|
159
|
+
* @param source
|
|
160
|
+
* @param destination
|
|
161
|
+
*/
|
|
162
|
+
shortestPath(source: NodeId, destination: NodeId): {
|
|
163
|
+
path: NodeId[];
|
|
164
|
+
weight: EdgeWeight;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Serializes the graph.
|
|
168
|
+
*/
|
|
169
|
+
serialize(): Serialized;
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../../src/lib/container/graph.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC;AAC5B,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAChC,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC;AAEjC,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACxB,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,UAAU,CAAA;KAAE,EAAE,CAAC;CACjE;AAED,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM;CAI5B;AAED;;GAEG;AACH,qBAAa,KAAK;IAChB;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAM;IAErC;;;;OAIG;IACH,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,CAAM;gBAEtC,UAAU,CAAC,EAAE,UAAU;IAMnC;;;OAGG;IACH,WAAW,CAAC,UAAU,EAAE,UAAU;IAUlC;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE;IAIhC;;;;;OAKG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM;IAKpB;;;;;;OAMG;IACH,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,UAAU;IAYjD;;;;;OAKG;IACH,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU;IAKtD;;;;;OAKG;IACH,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,WAAW;IAI7C;;;;OAIG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM;IAgBvB;;OAEG;IACH,KAAK,IAAI,MAAM,EAAE;IAajB;;;;;OAKG;IACH,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,UAAU;IAK/C;;;;;;OAMG;IACH,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;IAS/B;;;;OAIG;IACH,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;IAI5B;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM;IAarB;;;;OAIG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM;IAKtB;;;;;;;;;;;OAWG;IACH,gBAAgB,CACd,WAAW,EAAE,MAAM,EAAE,GAAC,SAAS,EAC/B,kBAAkB,GAAE,OAAc,EAClC,YAAY,GAAE,OAAe;IA0C/B;;OAEG;IACH,QAAQ,IAAI,OAAO;IAgBnB;;;;;;;OAOG;IACH,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IA4ClD;;;;;;;;OAQG;IACH,eAAe,CACb,WAAW,CAAC,EAAE,MAAM,EAAE,EACtB,kBAAkB,GAAE,OAAc;IAKpC;;;;;;;OAOG;IACH,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;cA6EpB,MAAM,EAAE;gBAAU,UAAU;;IAwBxD;;OAEG;IACH,SAAS;CAqBV"}
|