@spinajs/templates 2.0.46 → 2.0.51

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.
Files changed (52) hide show
  1. package/README.md +11 -11
  2. package/lib/cli/render.d.ts +1 -0
  3. package/lib/cli/render.d.ts.map +1 -0
  4. package/lib/cli/render.js +15 -41
  5. package/lib/cli/render.js.map +1 -1
  6. package/lib/config/templates.d.ts +1 -0
  7. package/lib/config/templates.d.ts.map +1 -0
  8. package/lib/config/templates.js +3 -5
  9. package/lib/config/templates.js.map +1 -1
  10. package/lib/index.d.ts +3 -2
  11. package/lib/index.d.ts.map +1 -0
  12. package/lib/index.js +18 -35
  13. package/lib/index.js.map +1 -1
  14. package/lib/interfaces.d.ts +4 -1
  15. package/lib/interfaces.d.ts.map +1 -0
  16. package/lib/interfaces.js +14 -14
  17. package/lib/interfaces.js.map +1 -1
  18. package/package.json +60 -60
  19. package/lib/di/src/array.d.ts +0 -10
  20. package/lib/di/src/array.js +0 -14
  21. package/lib/di/src/array.js.map +0 -1
  22. package/lib/di/src/container-cache.d.ts +0 -17
  23. package/lib/di/src/container-cache.js +0 -64
  24. package/lib/di/src/container-cache.js.map +0 -1
  25. package/lib/di/src/enums.d.ts +0 -31
  26. package/lib/di/src/enums.js +0 -36
  27. package/lib/di/src/enums.js.map +0 -1
  28. package/lib/di/src/helpers.d.ts +0 -25
  29. package/lib/di/src/helpers.js +0 -69
  30. package/lib/di/src/helpers.js.map +0 -1
  31. package/lib/di/src/interfaces.d.ts +0 -150
  32. package/lib/di/src/interfaces.js +0 -48
  33. package/lib/di/src/interfaces.js.map +0 -1
  34. package/lib/di/src/registry.d.ts +0 -14
  35. package/lib/di/src/registry.js +0 -81
  36. package/lib/di/src/registry.js.map +0 -1
  37. package/lib/di/src/types.d.ts +0 -13
  38. package/lib/di/src/types.js +0 -3
  39. package/lib/di/src/types.js.map +0 -1
  40. package/lib/templates/src/cli/render.d.ts +0 -12
  41. package/lib/templates/src/cli/render.js +0 -86
  42. package/lib/templates/src/cli/render.js.map +0 -1
  43. package/lib/templates/src/config/templates.d.ts +0 -9
  44. package/lib/templates/src/config/templates.js +0 -16
  45. package/lib/templates/src/config/templates.js.map +0 -1
  46. package/lib/templates/src/index.d.ts +0 -13
  47. package/lib/templates/src/index.js +0 -67
  48. package/lib/templates/src/index.js.map +0 -1
  49. package/lib/templates/src/interfaces.d.ts +0 -21
  50. package/lib/templates/src/interfaces.js +0 -71
  51. package/lib/templates/src/interfaces.js.map +0 -1
  52. package/lib/templates.js +0 -7
@@ -1,31 +0,0 @@
1
- /**
2
- * How to resolve class
3
- */
4
- export declare enum ResolveType {
5
- /**
6
- * Application wise single instance. Default behaviour
7
- */
8
- Singleton = 0,
9
- /**
10
- * New instance every time is requested
11
- */
12
- NewInstance = 1,
13
- /**
14
- * New instance per child DI container.
15
- */
16
- PerChildContainer = 2,
17
- /**
18
- * Singleton per target type
19
- *
20
- * eg. if we have multiple registered types at one base type
21
- * we can resolve any of it once
22
- *
23
- * In comparison, Singleton flag means that only one instance can be resolved
24
- * for base class
25
- */
26
- PerInstance = 3,
27
- /**
28
- * Only one instance with given name can exists of the same service
29
- */
30
- PerInstanceCheck = 4
31
- }
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ResolveType = void 0;
4
- /**
5
- * How to resolve class
6
- */
7
- var ResolveType;
8
- (function (ResolveType) {
9
- /**
10
- * Application wise single instance. Default behaviour
11
- */
12
- ResolveType[ResolveType["Singleton"] = 0] = "Singleton";
13
- /**
14
- * New instance every time is requested
15
- */
16
- ResolveType[ResolveType["NewInstance"] = 1] = "NewInstance";
17
- /**
18
- * New instance per child DI container.
19
- */
20
- ResolveType[ResolveType["PerChildContainer"] = 2] = "PerChildContainer";
21
- /**
22
- * Singleton per target type
23
- *
24
- * eg. if we have multiple registered types at one base type
25
- * we can resolve any of it once
26
- *
27
- * In comparison, Singleton flag means that only one instance can be resolved
28
- * for base class
29
- */
30
- ResolveType[ResolveType["PerInstance"] = 3] = "PerInstance";
31
- /**
32
- * Only one instance with given name can exists of the same service
33
- */
34
- ResolveType[ResolveType["PerInstanceCheck"] = 4] = "PerInstanceCheck";
35
- })(ResolveType = exports.ResolveType || (exports.ResolveType = {}));
36
- //# sourceMappingURL=enums.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"enums.js","sourceRoot":"","sources":["../../../../di/src/enums.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,IAAY,WA+BX;AA/BD,WAAY,WAAW;IACrB;;OAEG;IACH,uDAAS,CAAA;IAET;;OAEG;IACH,2DAAW,CAAA;IAEX;;OAEG;IACH,uEAAiB,CAAA;IAEjB;;;;;;;;OAQG;IACH,2DAAW,CAAA;IAEX;;OAEG;IACH,qEAAgB,CAAA;AAClB,CAAC,EA/BW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QA+BtB"}
@@ -1,25 +0,0 @@
1
- import { TypedArray } from './array';
2
- import { AsyncService, SyncService } from './interfaces';
3
- import { Factory, Class } from './types';
4
- /**
5
- * Checks if value is constructable type.
6
- * Checks for [[Construct]] internal function in object.
7
- *
8
- * @param value - value to test
9
- */
10
- export declare function isConstructor(value: any): value is Class<unknown>;
11
- export declare function isFactory(value: any): value is Factory<any>;
12
- export declare function isObject(value: any): value is object;
13
- export declare function isAsyncService(value: any): value is AsyncService;
14
- export declare function isPromise(value: any): value is Promise<any>;
15
- export declare function isSyncService(value: any): value is SyncService;
16
- /**
17
- * For DI purpose we treat Map as array to inject. Difference is, that we fill map by some key
18
- * provided by mapFunc in \@Autoinject
19
- * @param value - value to check type
20
- * @returns
21
- */
22
- export declare function isTypedArray(value: any): value is TypedArray<any>;
23
- export declare function isMap(value: any): value is Map<string, any>;
24
- export declare function uniqBy<T>(arr: T[], comparator: (a: T, b: T) => boolean): T[];
25
- export declare function getTypeName(type: TypedArray<any> | Class<any> | string | object): string;
@@ -1,69 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTypeName = exports.uniqBy = exports.isMap = exports.isTypedArray = exports.isSyncService = exports.isPromise = exports.isAsyncService = exports.isObject = exports.isFactory = exports.isConstructor = void 0;
4
- const interfaces_1 = require("./interfaces");
5
- /**
6
- * Checks if value is constructable type.
7
- * Checks for [[Construct]] internal function in object.
8
- *
9
- * @param value - value to test
10
- */
11
- function isConstructor(value) {
12
- try {
13
- Reflect.construct(String, [], value);
14
- }
15
- catch (e) {
16
- return false;
17
- }
18
- return true;
19
- }
20
- exports.isConstructor = isConstructor;
21
- function isFactory(value) {
22
- return !isConstructor(value) && typeof value === 'function';
23
- }
24
- exports.isFactory = isFactory;
25
- function isObject(value) {
26
- return typeof value === 'object';
27
- }
28
- exports.isObject = isObject;
29
- function isAsyncService(value) {
30
- return value instanceof interfaces_1.AsyncService;
31
- }
32
- exports.isAsyncService = isAsyncService;
33
- function isPromise(value) {
34
- return value instanceof Promise;
35
- }
36
- exports.isPromise = isPromise;
37
- function isSyncService(value) {
38
- return value instanceof interfaces_1.SyncService;
39
- }
40
- exports.isSyncService = isSyncService;
41
- /**
42
- * For DI purpose we treat Map as array to inject. Difference is, that we fill map by some key
43
- * provided by mapFunc in \@Autoinject
44
- * @param value - value to check type
45
- * @returns
46
- */
47
- function isTypedArray(value) {
48
- return (value instanceof Array && value.constructor.name === 'TypedArray') || isMap(value);
49
- }
50
- exports.isTypedArray = isTypedArray;
51
- function isMap(value) {
52
- return value instanceof Map && value.constructor.name === 'Map';
53
- }
54
- exports.isMap = isMap;
55
- function uniqBy(arr, comparator) {
56
- const uniques = [];
57
- for (const a of arr) {
58
- if (uniques.findIndex((u) => comparator(a, u)) === -1) {
59
- uniques.push(a);
60
- }
61
- }
62
- return uniques;
63
- }
64
- exports.uniqBy = uniqBy;
65
- function getTypeName(type) {
66
- return typeof type === 'string' ? type : isTypedArray(type) ? getTypeName(type.Type) : isConstructor(type) ? type.name : type.constructor.name;
67
- }
68
- exports.getTypeName = getTypeName;
69
- //# sourceMappingURL=helpers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../di/src/helpers.ts"],"names":[],"mappings":";;;AACA,6CAAyD;AAGzD;;;;;GAKG;AACH,SAAgB,aAAa,CAAC,KAAU;IACtC,IAAI;QACF,OAAO,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;KACtC;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AARD,sCAQC;AAED,SAAgB,SAAS,CAAC,KAAU;IAClC,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,UAAU,CAAC;AAC9D,CAAC;AAFD,8BAEC;AAED,SAAgB,QAAQ,CAAC,KAAU;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAFD,4BAEC;AAED,SAAgB,cAAc,CAAC,KAAU;IACvC,OAAO,KAAK,YAAY,yBAAY,CAAC;AACvC,CAAC;AAFD,wCAEC;AAED,SAAgB,SAAS,CAAC,KAAU;IAClC,OAAO,KAAK,YAAY,OAAO,CAAC;AAClC,CAAC;AAFD,8BAEC;AAED,SAAgB,aAAa,CAAC,KAAU;IACtC,OAAO,KAAK,YAAY,wBAAW,CAAC;AACtC,CAAC;AAFD,sCAEC;AAED;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,KAAU;IACrC,OAAO,CAAC,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,WAAW,CAAC,IAAI,KAAK,YAAY,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;AAC7F,CAAC;AAFD,oCAEC;AAED,SAAgB,KAAK,CAAC,KAAU;IAC9B,OAAO,KAAK,YAAY,GAAG,IAAI,KAAK,CAAC,WAAW,CAAC,IAAI,KAAK,KAAK,CAAC;AAClE,CAAC;AAFD,sBAEC;AAED,SAAgB,MAAM,CAAI,GAAQ,EAAE,UAAmC;IACrE,MAAM,OAAO,GAAG,EAAE,CAAC;IACnB,KAAK,MAAM,CAAC,IAAI,GAAG,EAAE;QACnB,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE;YACrD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;KACF;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AARD,wBAQC;AAED,SAAgB,WAAW,CAAC,IAAoD;IAC9E,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;AACjJ,CAAC;AAFD,kCAEC"}
@@ -1,150 +0,0 @@
1
- /// <reference types="node" />
2
- import { ResolveType } from './enums';
3
- import { Class, Factory } from './types';
4
- import { EventEmitter } from 'events';
5
- import { TypedArray } from './array';
6
- import { Registry } from './registry';
7
- import { ContainerCache } from './container-cache';
8
- export interface IInstanceCheck {
9
- __checkInstance__(creationOptions: any): boolean;
10
- }
11
- /**
12
- * Interface to describe DI binding behaviour
13
- */
14
- export interface IBind {
15
- /**
16
- * `as` binding (alias)
17
- *
18
- * @param type - base class that is being registered
19
- */
20
- as(type: Class<any> | string): this;
21
- /**
22
- * self bind, class should be resolved by its name. Its default behaviour.
23
- */
24
- asSelf(): this;
25
- /**
26
- * Registers as value, it wont be resolved or called, just stored as is in container
27
- * @param type - name of type / key after whitch implementation will be resolved
28
- * @param override - if true, any value registered before is overriden by new one
29
- */
30
- asValue(type: string, override: boolean): this;
31
- asValue(type: string): this;
32
- /**
33
- *
34
- * Add plain value to container, value is stored in hashmap for quick access
35
- * eg. we have multiple value converters and we wanc o(1) access, instead searching for
36
- * converter for specific type
37
- *
38
- * @param type - name of added value
39
- * @param key - hashmap key
40
- */
41
- asMapValue(type: string, hashKey: string): this;
42
- /**
43
- * Registers object as single instance ( singleton )
44
- */
45
- singleInstance(): this;
46
- }
47
- export interface ResolvableObject {
48
- [key: string]: any;
49
- }
50
- export interface IContainer extends EventEmitter {
51
- Cache: ContainerCache;
52
- Registry: Registry;
53
- Parent: IContainer;
54
- clear(): void;
55
- clearRegistry(): void;
56
- clearCache(): void;
57
- register<T>(implementation: Class<T> | Factory<T> | ResolvableObject): IBind;
58
- unregister<T>(implementation: string | Class<T> | Factory<T> | ResolvableObject): void;
59
- uncache<T>(source: string | Class<T> | TypedArray<T>, parent?: boolean): void;
60
- child(): IContainer;
61
- get<T>(service: TypedArray<T>, parent?: boolean): T[] | null;
62
- get<T>(service: string | Class<T>, parent?: boolean): T | null;
63
- get<T>(service: string | Class<T> | TypedArray<T>, parent?: boolean): T | T[] | null;
64
- getRegisteredTypes<T>(service: string | Class<T> | TypedArray<T>, parent?: boolean): Array<Class<unknown> | Factory<unknown>>;
65
- isResolved<T>(service: string | Class<T>, parent?: boolean): boolean;
66
- hasRegistered<T>(service: Class<T> | string | TypedArray<T>, parent?: boolean): boolean;
67
- hasRegisteredType<T>(source: Class<any> | string | TypedArray<any>, type: Class<T> | string | TypedArray<T> | object, parent?: boolean): boolean;
68
- resolve<T>(type: string, options?: unknown[], check?: boolean): T;
69
- resolve<T>(type: string, check?: boolean): T;
70
- resolve<T>(type: Class<T> | Factory<T>, options?: unknown[] | boolean, check?: boolean): T extends AsyncService ? Promise<T> : T;
71
- resolve<T>(type: TypedArray<T>, options?: unknown[] | boolean, check?: boolean): T extends AsyncService ? Promise<T[]> : T[];
72
- resolve<T>(type: Class<T> | Factory<T>, check?: boolean): T extends AsyncService ? Promise<T> : T;
73
- resolve<T>(type: TypedArray<T>, check?: boolean): T extends AsyncService ? Promise<T[]> : T[];
74
- resolve<T>(type: Class<T> | TypedArray<T> | string, options?: unknown[] | boolean, check?: boolean): Promise<T | T[]> | T | T[];
75
- dispose(): Promise<void>;
76
- }
77
- /**
78
- * Injection description definition structure
79
- */
80
- export interface IInjectDescriptor<T> {
81
- inject: IToInject<T>[];
82
- resolver: ResolveType;
83
- }
84
- export interface IToInject<T> {
85
- inject: Class<T> | TypedArray<T>;
86
- autoinject: boolean;
87
- autoinjectKey: string;
88
- /**
89
- * additional data passed to DI when resolving
90
- */
91
- data?: any;
92
- /**
93
- * Additional options passed to resolved options
94
- */
95
- options?: any;
96
- /**
97
- * Callback used to resolve service
98
- * name of service we want to resolve
99
- * eg. we have multiple \@injectable registered
100
- * and we want specific one
101
- *
102
- * It is specifically for use with configuration module
103
- * where services can be changed in configuration files
104
- * and allows to use @AutoinjectService() decorator
105
- */
106
- serviceFunc?: (data: string | any[], container: IContainer) => IServiceFuncResult | IServiceFuncResult[];
107
- mapFunc?: (x: IMappableService) => string;
108
- }
109
- export interface IMappableService {
110
- ServiceName: string;
111
- }
112
- export interface IServiceFuncResult {
113
- service: string;
114
- options?: any;
115
- }
116
- export interface IResolvedInjection {
117
- instance: unknown;
118
- autoinject: boolean;
119
- autoinjectKey: string;
120
- }
121
- /**
122
- * Interface to describe DI resolve strategies. Strategies are used do
123
- * do some work at object creation eg. initialize objects that inherits from same class
124
- * specific way but without need for factory function.
125
- *
126
- *
127
- * @see FrameworkModuleSyncService implementation
128
- */
129
- export declare class Service {
130
- protected resolved: boolean;
131
- get Resolved(): boolean;
132
- /**
133
- * Use to dispose service, relase all resources, stop timers etc.
134
- *
135
- */
136
- dispose(): Promise<void>;
137
- }
138
- export declare abstract class SyncService extends Service {
139
- resolve(): void;
140
- }
141
- export declare class AsyncService extends Service {
142
- resolve(): Promise<void>;
143
- }
144
- export declare abstract class Bootstrapper {
145
- abstract bootstrap(): Promise<void> | void;
146
- }
147
- export interface IAutoinjectOptions {
148
- mapFunc?: (x: IMappableService) => string;
149
- options?: any;
150
- }
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Bootstrapper = exports.AsyncService = exports.SyncService = exports.Service = void 0;
4
- /**
5
- * Interface to describe DI resolve strategies. Strategies are used do
6
- * do some work at object creation eg. initialize objects that inherits from same class
7
- * specific way but without need for factory function.
8
- *
9
- *
10
- * @see FrameworkModuleSyncService implementation
11
- */
12
- // export interface IStrategy {
13
- // resolve: (target: any, container: IContainer) => void;
14
- // }
15
- // export interface IAsyncStrategy {
16
- // resolveA: (target: any, container: IContainer) => Promise<void>;
17
- // }
18
- class Service {
19
- constructor() {
20
- this.resolved = false;
21
- }
22
- get Resolved() {
23
- return this.resolved;
24
- }
25
- /**
26
- * Use to dispose service, relase all resources, stop timers etc.
27
- *
28
- */
29
- async dispose() { }
30
- }
31
- exports.Service = Service;
32
- class SyncService extends Service {
33
- resolve() {
34
- this.resolved = true;
35
- }
36
- }
37
- exports.SyncService = SyncService;
38
- class AsyncService extends Service {
39
- /* eslint-disable */
40
- async resolve() {
41
- this.resolved = true;
42
- }
43
- }
44
- exports.AsyncService = AsyncService;
45
- class Bootstrapper {
46
- }
47
- exports.Bootstrapper = Bootstrapper;
48
- //# sourceMappingURL=interfaces.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../di/src/interfaces.ts"],"names":[],"mappings":";;;AA+IA;;;;;;;GAOG;AACH,+BAA+B;AAC/B,6DAA6D;AAC7D,IAAI;AAEJ,oCAAoC;AACpC,uEAAuE;AACvE,IAAI;AAEJ,MAAa,OAAO;IAApB;QACY,aAAQ,GAAG,KAAK,CAAC;IAU7B,CAAC;IATC,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,OAAO,KAAI,CAAC;CAC1B;AAXD,0BAWC;AAED,MAAsB,WAAY,SAAQ,OAAO;IACxC,OAAO;QACZ,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACvB,CAAC;CACF;AAJD,kCAIC;AAED,MAAa,YAAa,SAAQ,OAAO;IACvC,oBAAoB;IACb,KAAK,CAAC,OAAO;QAClB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACvB,CAAC;CACF;AALD,oCAKC;AAED,MAAsB,YAAY;CAEjC;AAFD,oCAEC"}
@@ -1,14 +0,0 @@
1
- import { TypedArray } from './array';
2
- import { IContainer } from './interfaces';
3
- import { Class, Factory } from './types';
4
- export declare class Registry {
5
- protected container: IContainer;
6
- protected registry: Map<string, any[]>;
7
- constructor(container: IContainer);
8
- clear(): void;
9
- unregister(type: any): void;
10
- register(name: string | Class<any> | TypedArray<any>, type: any): void;
11
- hasRegisteredType(source: Class<any> | string | TypedArray<any>, type: Class<any> | string | TypedArray<any> | object, parent?: boolean): boolean;
12
- getTypes<T>(service: string | Class<T> | TypedArray<T>, parent?: boolean): Array<Class<unknown> | Factory<unknown>>;
13
- hasRegistered<T>(service: TypedArray<T> | Class<T> | string, parent?: boolean): boolean;
14
- }
@@ -1,81 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Registry = void 0;
4
- const exceptions_1 = require("@spinajs/exceptions");
5
- const helpers_1 = require("./helpers");
6
- class Registry {
7
- constructor(container) {
8
- this.container = container;
9
- this.registry = new Map();
10
- }
11
- clear() {
12
- this.registry.clear();
13
- }
14
- unregister(type) {
15
- const tname = (0, helpers_1.getTypeName)(type);
16
- this.registry.forEach((value) => {
17
- const index = value.findIndex((x) => (0, helpers_1.getTypeName)(x) === tname);
18
- if (index !== -1) {
19
- value.splice(index, 1);
20
- }
21
- });
22
- }
23
- register(name, type) {
24
- if (!(0, helpers_1.isConstructor)(type) && !(0, helpers_1.isFactory)(type) && !(0, helpers_1.isObject)(type)) {
25
- throw new exceptions_1.InvalidOperation('cannot register type if its not an class or factory function');
26
- }
27
- else {
28
- const tname = (0, helpers_1.getTypeName)(name);
29
- const value = this.registry.get(tname);
30
- if (value) {
31
- // factory functions, we always add to registry
32
- // its impossible to check for duplicates
33
- // all would return 'Function' type
34
- if ((0, helpers_1.isFactory)(type)) {
35
- value.push(type);
36
- }
37
- else if (!value.find((v) => (0, helpers_1.getTypeName)(v) === (0, helpers_1.getTypeName)(type))) {
38
- value.push(type);
39
- }
40
- }
41
- else {
42
- this.registry.set(tname, [type]);
43
- }
44
- }
45
- }
46
- hasRegisteredType(source, type, parent) {
47
- const sourceName = (0, helpers_1.getTypeName)(source);
48
- const targetName = (0, helpers_1.getTypeName)(type);
49
- if (this.registry.has(sourceName)) {
50
- return this.registry.get(sourceName).find((s) => s.name === targetName) !== undefined;
51
- }
52
- else if (parent && this.container.Parent) {
53
- return this.container.Parent.hasRegisteredType(source, type, parent);
54
- }
55
- return false;
56
- }
57
- getTypes(service, parent = true) {
58
- if (!service) {
59
- throw new exceptions_1.InvalidArgument('argument "service" cannot be null or empty');
60
- }
61
- const name = (0, helpers_1.getTypeName)(service);
62
- if (this.registry.has(name)) {
63
- return this.registry.get(name);
64
- }
65
- if (this.container.Parent && parent) {
66
- return this.container.Parent.getRegisteredTypes(service, parent);
67
- }
68
- return null;
69
- }
70
- hasRegistered(service, parent = true) {
71
- if (this.registry.has((0, helpers_1.getTypeName)(service))) {
72
- return true;
73
- }
74
- else if (parent && this.container.Parent) {
75
- return this.container.Parent.hasRegistered(service, parent);
76
- }
77
- return false;
78
- }
79
- }
80
- exports.Registry = Registry;
81
- //# sourceMappingURL=registry.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../../di/src/registry.ts"],"names":[],"mappings":";;;AAAA,oDAAwE;AAExE,uCAA4E;AAI5E,MAAa,QAAQ;IAGnB,YAAsB,SAAqB;QAArB,cAAS,GAAT,SAAS,CAAY;QAFjC,aAAQ,GAAuB,IAAI,GA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,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;SAClE;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,aAAa,CAAI,OAA0C,EAAE,MAAM,GAAG,IAAI;QAC/E,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAA,qBAAW,EAAC,OAAO,CAAC,CAAC,EAAE;YAC3C,OAAO,IAAI,CAAC;SACb;aAAM,IAAI,MAAM,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE;YAC1C,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;SAC7D;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA/ED,4BA+EC"}
@@ -1,13 +0,0 @@
1
- import { IContainer } from './interfaces';
2
- export declare type Abstract<T> = Function & {
3
- prototype: T;
4
- };
5
- export declare type Constructor<T> = new (...args: any[]) => T;
6
- export declare type Class<T> = Abstract<T> | Constructor<T>;
7
- /**
8
- * Factory functions should not be normal functions,
9
- * but arrow functions. Its is by js limitation
10
- * to detect if object is constructable
11
- */
12
- export declare type Factory<T> = (container: IContainer, ...args: any[]) => T;
13
- export declare type ClassArray<T> = Class<T>[];
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../di/src/types.ts"],"names":[],"mappings":""}
@@ -1,12 +0,0 @@
1
- import { CliCommand } from '@spinajs/cli';
2
- import { ILog } from '@spinajs/log';
3
- interface RenderOptions {
4
- file?: string;
5
- model?: string;
6
- lang?: string;
7
- }
8
- export declare class RenderTemplateCommand extends CliCommand {
9
- protected Log: ILog;
10
- execute(template: string, options: RenderOptions): Promise<void>;
11
- }
12
- export {};
@@ -1,86 +0,0 @@
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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
- return c > 3 && r && Object.defineProperty(target, key, r), r;
23
- };
24
- var __importStar = (this && this.__importStar) || function (mod) {
25
- if (mod && mod.__esModule) return mod;
26
- var result = {};
27
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
- __setModuleDefault(result, mod);
29
- return result;
30
- };
31
- var __metadata = (this && this.__metadata) || function (k, v) {
32
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33
- };
34
- Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.RenderTemplateCommand = void 0;
36
- const index_1 = require("./../index");
37
- const cli_1 = require("@spinajs/cli");
38
- const di_1 = require("@spinajs/di");
39
- const path = __importStar(require("path"));
40
- const fs = __importStar(require("fs"));
41
- const log_1 = require("@spinajs/log");
42
- let RenderTemplateCommand = class RenderTemplateCommand extends cli_1.CliCommand {
43
- async execute(template, options) {
44
- this.Log.trace(`Rendering ${template}, options: ${JSON.stringify(options)}`);
45
- try {
46
- const templates = await di_1.DI.resolve(index_1.Templates);
47
- let model = {};
48
- if (options.model && fs.existsSync(options.model)) {
49
- this.Log.trace(`Found model file at ${options.model}, trying to load model data ... `);
50
- const mText = fs.readFileSync(options.model, { encoding: 'utf-8' });
51
- model = JSON.parse(mText);
52
- }
53
- if (options && options.file) {
54
- this.Log.trace(`Rendering template to file ${options.file} ...`);
55
- const dir = path.dirname(options.file);
56
- if (!fs.existsSync(dir)) {
57
- this.Log.trace(`Directory ${dir} not exits, creating ...`);
58
- fs.mkdirSync(dir, { recursive: true });
59
- }
60
- await templates.renderToFile(template, model, options.file, options.lang);
61
- this.Log.success(`Rendering template ${template} to file ${options.file} succeded !`);
62
- return;
63
- }
64
- const result = await templates.render(template, model, options.lang);
65
- this.Log.success(`Rendering template ${template} succeded !`);
66
- // print out to console in raw format
67
- console.log(result);
68
- }
69
- catch (err) {
70
- this.Log.error(`Cannot render template ${template}, reason: ${err.message}, stack: ${err.stack}`);
71
- }
72
- }
73
- };
74
- __decorate([
75
- (0, log_1.Logger)('templates'),
76
- __metadata("design:type", Object)
77
- ], RenderTemplateCommand.prototype, "Log", void 0);
78
- RenderTemplateCommand = __decorate([
79
- (0, cli_1.Command)('template-render', 'Renders template, usefull for template testing'),
80
- (0, cli_1.Argument)('template', 'template path, must be in one of directory provided in configs'),
81
- (0, cli_1.Option)('-f, --file [file]', false, 'path for file, where parsing result will be saved'),
82
- (0, cli_1.Option)('-m, --model [model]', false, 'path to optional model data, passed to template, in json format'),
83
- (0, cli_1.Option)('-l, --lang [lang]', false, 'optional language. Language data must be in directories configured in intl module. If none provided, default language is used')
84
- ], RenderTemplateCommand);
85
- exports.RenderTemplateCommand = RenderTemplateCommand;
86
- //# sourceMappingURL=render.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"render.js","sourceRoot":"","sources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
- cli: string[];
6
- };
7
- };
8
- };
9
- export default templates;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const path_1 = require("path");
4
- function dir(path) {
5
- return (0, path_1.resolve)((0, path_1.normalize)((0, path_1.join)(__dirname, path)));
6
- }
7
- const templates = {
8
- system: {
9
- dirs: {
10
- templates: [dir('./../templates')],
11
- cli: [dir('./../cli')],
12
- },
13
- },
14
- };
15
- exports.default = templates;
16
- //# sourceMappingURL=templates.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"templates.js","sourceRoot":"","sources":["../../../../src/config/templates.ts"],"names":[],"mappings":";;AAAA,+BAAgD;AAEhD,SAAS,GAAG,CAAC,IAAY;IACvB,OAAO,IAAA,cAAO,EAAC,IAAA,gBAAS,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,SAAS,GAAG;IAChB,MAAM,EAAE;QACN,IAAI,EAAE;YACJ,SAAS,EAAE,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;YAClC,GAAG,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;SACvB;KACF;CACF,CAAC;AAEF,kBAAe,SAAS,CAAC"}
@@ -1,13 +0,0 @@
1
- import { AsyncService } from '@spinajs/di';
2
- import { Log } from '@spinajs/log';
3
- import { TemplateRenderer } from './interfaces';
4
- export * from './interfaces';
5
- /**
6
- * Inject INTL module for language support. We does nothing but to initialize module for use in templates.
7
- */
8
- export declare class Templates extends AsyncService {
9
- protected Log: Log;
10
- protected Renderers: Map<string, TemplateRenderer>;
11
- render(template: string, model: unknown, language?: string): Promise<string>;
12
- renderToFile(template: string, model: unknown, filePath: string, language?: string): Promise<void>;
13
- }