@xylabs/creatable 4.12.16 → 4.12.17
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/dist/neutral/index.mjs.map +1 -1
- package/dist/types/AbstractCreatable.d.ts +2 -2
- package/dist/types/AbstractCreatable.d.ts.map +1 -1
- package/dist/types/Creatable.d.ts +5 -5
- package/dist/types/Creatable.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/AbstractCreatable.ts +5 -5
- package/src/Creatable.ts +11 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/AbstractCreatable.ts","../../src/lib/getFunctionName.ts","../../src/lib/getRootFunction.ts","../../src/Creatable.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport type { EventData } from '@xylabs/events'\nimport { BaseEmitter } from '@xylabs/events'\nimport { type Logger } from '@xylabs/logger'\nimport type { EmptyObject } from '@xylabs/object'\nimport type { Promisable } from '@xylabs/promise'\nimport { isError } from '@xylabs/typeof'\n\nimport type { Creatable } from './Creatable.ts'\nimport { getFunctionName, getRootFunction } from './lib/index.ts'\nimport type {\n CreatableInstance, CreatableName, CreatableParams,\n} from './model/index.ts'\n\nexport abstract class AbstractCreatable<TParams extends CreatableParams = CreatableParams,\n TEventData extends EventData = EventData> extends BaseEmitter<Partial<TParams>, TEventData> {\n defaultLogger?: Logger\n name: CreatableName\n\n private _populatedParams: TParams | undefined\n\n constructor(params: Partial<TParams>) {\n super(params)\n this.name = params.name ?? this.constructor.name as CreatableName\n }\n\n override get params(): CreatableParams<TParams> {\n this._noOverride()\n this._populatedParams = this._populatedParams ?? this.paramsHandler(super.params)\n return this._populatedParams\n }\n\n get statusReporter() {\n return this.params.statusReporter\n }\n\n static async create<T extends EmptyObject | void = void, TParams extends CreatableParams = CreatableParams>(\n this: Creatable<T, TParams
|
|
1
|
+
{"version":3,"sources":["../../src/AbstractCreatable.ts","../../src/lib/getFunctionName.ts","../../src/lib/getRootFunction.ts","../../src/Creatable.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport type { EventData } from '@xylabs/events'\nimport { BaseEmitter } from '@xylabs/events'\nimport { type Logger } from '@xylabs/logger'\nimport type { EmptyObject } from '@xylabs/object'\nimport type { Promisable } from '@xylabs/promise'\nimport { isError } from '@xylabs/typeof'\n\nimport type { Creatable } from './Creatable.ts'\nimport { getFunctionName, getRootFunction } from './lib/index.ts'\nimport type {\n CreatableInstance, CreatableName, CreatableParams,\n} from './model/index.ts'\n\nexport abstract class AbstractCreatable<TParams extends CreatableParams = CreatableParams,\n TEventData extends EventData = EventData> extends BaseEmitter<Partial<TParams>, TEventData> {\n defaultLogger?: Logger\n name: CreatableName\n\n private _populatedParams: TParams | undefined\n\n constructor(params: Partial<TParams>) {\n super(params)\n this.name = params.name ?? this.constructor.name as CreatableName\n }\n\n override get params(): CreatableParams<TParams> {\n this._noOverride()\n this._populatedParams = this._populatedParams ?? this.paramsHandler(super.params)\n return this._populatedParams\n }\n\n get statusReporter() {\n return this.params.statusReporter\n }\n\n static async create<T extends EmptyObject | void = void, TParams extends CreatableParams = CreatableParams>(\n this: Creatable<CreatableInstance<T, TParams>>,\n params: Partial<CreatableParams<TParams>>,\n ): Promise<CreatableInstance<T, TParams>> {\n const name: CreatableName = params.name ?? this.name\n params.statusReporter?.report(name, 'creating')\n try {\n const instance = new this(params)\n const initializedInstance = await this.createHandler(instance)\n await instance.createHandler()\n params.statusReporter?.report(name, 'created')\n return initializedInstance\n } catch (ex) {\n params.statusReporter?.report(name, 'error', isError(ex) ? ex : new Error(`Error creating: ${name}`))\n throw new Error(`Error creating: ${name}`)\n }\n }\n\n /* override this for initialization of instance */\n static createHandler<T extends EmptyObject | void = void, TParams extends CreatableParams = CreatableParams>(\n this: Creatable<CreatableInstance<T, TParams>>,\n instance: CreatableInstance<T, TParams>,\n ): Promisable<CreatableInstance<T, TParams>> {\n return instance\n }\n\n createHandler(): Promisable<void> {}\n\n async start(): Promise<boolean> {\n this._noOverride('start')\n try {\n this.statusReporter?.report(this.name, 'starting')\n await this.startHandler()\n this.statusReporter?.report(this.name, 'started')\n return true\n } catch (ex) {\n this.statusReporter?.report(this.name, 'error', isError(ex) ? ex : new Error(`Error stopping: ${ex}`))\n return false\n }\n }\n\n async stop(): Promise<boolean> {\n this._noOverride('stop')\n try {\n this.statusReporter?.report(this.name, 'stopping')\n await this.stopHandler()\n this.statusReporter?.report(this.name, 'stopped')\n return true\n } catch (ex) {\n this.statusReporter?.report(this.name, 'error', isError(ex) ? ex : new Error(`Error stopping: ${ex}`))\n return false\n }\n }\n\n protected _noOverride(functionName = getFunctionName(3)) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const thisFunc = (this as any)[functionName]\n\n const rootFunc = getRootFunction(this, functionName)\n assertEx(thisFunc === rootFunc, () => `Override not allowed for [${functionName}] - override ${functionName}Handler instead`)\n }\n\n protected startHandler(): Promisable<void> {\n // when overriding this, throw an error on failure\n }\n\n protected stopHandler(): Promisable<void> {\n // when overriding this, throw an error on failure\n }\n\n protected abstract paramsHandler(params?: Partial<CreatableParams<TParams>>): CreatableParams<TParams>\n}\n","import { isNumber } from '@xylabs/typeof'\n\nexport function getFunctionName(depth = 2) {\n const error = new Error('Stack')\n let newIndex: number | undefined\n const stackParts = error.stack?.split('\\n')[depth]?.split(' ')\n const funcName\n = stackParts?.find((item, index) => {\n if (item.length > 0 && item !== 'at') {\n // check if constructor\n if (item === 'new') {\n newIndex = index\n }\n return true\n }\n }) ?? '<unknown>'\n return isNumber(newIndex) ? `${funcName} ${stackParts?.[newIndex + 1]}` : funcName\n}\n","export function getRootFunction(obj: unknown, funcName: string) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let anyObj = obj as any\n while (anyObj.__proto__?.[funcName]) {\n anyObj = anyObj.__proto__\n }\n return anyObj[funcName]\n}\n","import type { Logger } from '@xylabs/logger'\nimport type { EmptyObject } from '@xylabs/object'\n\nimport type { AbstractCreatable } from './AbstractCreatable.ts'\nimport type { CreatableInstance, CreatableParams } from './model/index.ts'\n\n/*\nexport interface CreatableFactory<T extends EmptyObject | void = void,\n TParams extends EmptyObject | void = void> {\n create(params?: CreatableParams<TParams>): Promise<CreatableInstance<T>>\n}\n*/\n\nexport interface Creatable<T extends CreatableInstance = CreatableInstance> {\n\n defaultLogger?: Logger\n\n new (params: Partial<T['params']>): T & AbstractCreatable<T['params']>\n\n create<T extends CreatableInstance>(\n this: Creatable<T>,\n params: Partial<T['params']>): Promise<T>\n\n createHandler<T extends CreatableInstance>(\n this: Creatable<T>,\n instance: T\n ): Promise<T>\n\n /*\n factory<T extends EmptyObject | void = void,\n TParams extends EmptyObject | void = void> (this: Creatable<T, TParams>, params: Partial<CreatableParams<TParams>>): CreatableFactory<T, TParams>\n */\n}\n\n/**\n * Class annotation to be used to decorate Modules which support\n * an asynchronous creation pattern\n * @returns The decorated Module requiring it implement the members\n * of the CreatableModule as statics properties/methods\n */\nexport function creatable<T extends EmptyObject | void = void, TParams extends CreatableParams = CreatableParams>() {\n return <U extends Creatable<CreatableInstance<T, TParams>>>(constructor: U) => {\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n constructor\n }\n}\n\n/**\n * Class annotation to be used to decorate Modules which support\n * an asynchronous creation factory pattern\n * @returns The decorated Module requiring it implement the members\n * of the CreatableModule as statics properties/methods\n */\n\n/*\nexport function creatableFactory() {\n return <U extends CreatableFactory>(constructor: U) => {\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n constructor\n }\n}\n*/\n"],"mappings":";AAAA,SAAS,gBAAgB;AAEzB,SAAS,mBAAmB;AAI5B,SAAS,eAAe;;;ACNxB,SAAS,gBAAgB;AAElB,SAAS,gBAAgB,QAAQ,GAAG;AACzC,QAAM,QAAQ,IAAI,MAAM,OAAO;AAC/B,MAAI;AACJ,QAAM,aAAa,MAAM,OAAO,MAAM,IAAI,EAAE,KAAK,GAAG,MAAM,GAAG;AAC7D,QAAM,WACE,YAAY,KAAK,CAAC,MAA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AA,EAGA,OAAO,cAEL,UAC2C;AAC3C,WAAO;AAAA,EACT;AAAA,EAEA,gBAAkC;AAAA,EAAC;AAAA,EAEnC,MAAM,QAA0B;AAC9B,SAAK,YAAY,OAAO;AACxB,QAAI;AACF,WAAK,gBAAgB,OAAO,KAAK,MAAM,UAAU;AACjD,YAAM,KAAK,aAAa;AACxB,WAAK,gBAAgB,OAAO,KAAK,MAAM,SAAS;AAChD,aAAO;AAAA,IACT,SAAS,IAAI;AACX,WAAK,gBAAgB,OAAO,KAAK,MAAM,SAAS,QAAQ,EAAE,IAAI,KAAK,IAAI,MAAM,mBAAmB,EAAE,EAAE,CAAC;AACrG,aAAO;AAAA,IACT;AAAA,EACF;AAAA,EAEA,MAAM,OAAyB;AAC7B,SAAK,YAAY,MAAM;AACvB,QAAI;AACF,WAAK,gBAAgB,OAAO,KAAK,MAAM,UAAU;AACjD,YAAM,KAAK,YAAY;AACvB,WAAK,gBAAgB,OAAO,KAAK,MAAM,SAAS;AAChD,aAAO;AAAA,IACT,SAAS,IAAI;AACX,WAAK,gBAAgB,OAAO,KAAK,MAAM,SAAS,QAAQ,EAAE,IAAI,KAAK,IAAI,MAAM,mBAAmB,EAAE,EAAE,CAAC;AACrG,aAAO;AAAA,IACT;AAAA,EACF;AAAA,EAEU,YAAY,eAAe,gBAAgB,CAAC,GAAG;AAEvD,UAAM,WAAY,KAAa,YAAY;AAE3C,UAAM,WAAW,gBAAgB,MAAM,YAAY;AACnD,aAAS,aAAa,UAAU,MAAM,6BAA6B,YAAY,gBAAgB,YAAY,iBAAiB;AAAA,EAC9H;AAAA,EAEU,eAAiC;AAAA,EAE3C;AAAA,EAEU,cAAgC;AAAA,EAE1C;AAGF;;;AGnEO,SAAS,YAAoG;AAClH,SAAO,CAAqD,gBAAmB;AAE7E;AAAA,EACF;AACF;","names":[]}
|
|
@@ -12,8 +12,8 @@ export declare abstract class AbstractCreatable<TParams extends CreatableParams
|
|
|
12
12
|
constructor(params: Partial<TParams>);
|
|
13
13
|
get params(): CreatableParams<TParams>;
|
|
14
14
|
get statusReporter(): import("./model/CreatableStatusReporter.ts").CreatableStatusReporter | undefined;
|
|
15
|
-
static create<T extends EmptyObject | void = void, TParams extends CreatableParams = CreatableParams>(this: Creatable<T, TParams
|
|
16
|
-
static createHandler<T extends EmptyObject | void = void, TParams extends CreatableParams = CreatableParams>(this: Creatable<T, TParams
|
|
15
|
+
static create<T extends EmptyObject | void = void, TParams extends CreatableParams = CreatableParams>(this: Creatable<CreatableInstance<T, TParams>>, params: Partial<CreatableParams<TParams>>): Promise<CreatableInstance<T, TParams>>;
|
|
16
|
+
static createHandler<T extends EmptyObject | void = void, TParams extends CreatableParams = CreatableParams>(this: Creatable<CreatableInstance<T, TParams>>, instance: CreatableInstance<T, TParams>): Promisable<CreatableInstance<T, TParams>>;
|
|
17
17
|
createHandler(): Promisable<void>;
|
|
18
18
|
start(): Promise<boolean>;
|
|
19
19
|
stop(): Promise<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractCreatable.d.ts","sourceRoot":"","sources":["../../src/AbstractCreatable.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAGjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE/C,OAAO,KAAK,EACV,iBAAiB,EAAE,aAAa,EAAE,eAAe,EAClD,MAAM,kBAAkB,CAAA;AAEzB,8BAAsB,iBAAiB,CAAC,OAAO,SAAS,eAAe,GAAG,eAAe,EACvF,UAAU,SAAS,SAAS,GAAG,SAAS,CAAE,SAA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
|
import type { AbstractCreatable } from './AbstractCreatable.ts';
|
|
4
4
|
import type { CreatableInstance, CreatableParams } from './model/index.ts';
|
|
5
|
-
export interface Creatable<T extends
|
|
5
|
+
export interface Creatable<T extends CreatableInstance = CreatableInstance> {
|
|
6
6
|
defaultLogger?: Logger;
|
|
7
|
-
new (params: Partial<
|
|
8
|
-
create<T extends
|
|
9
|
-
createHandler<T extends
|
|
7
|
+
new (params: Partial<T['params']>): T & AbstractCreatable<T['params']>;
|
|
8
|
+
create<T extends CreatableInstance>(this: Creatable<T>, params: Partial<T['params']>): Promise<T>;
|
|
9
|
+
createHandler<T extends CreatableInstance>(this: Creatable<T>, instance: T): Promise<T>;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* Class annotation to be used to decorate Modules which support
|
|
@@ -14,7 +14,7 @@ export interface Creatable<T extends EmptyObject | void = void, TParams extends
|
|
|
14
14
|
* @returns The decorated Module requiring it implement the members
|
|
15
15
|
* of the CreatableModule as statics properties/methods
|
|
16
16
|
*/
|
|
17
|
-
export declare function creatable<
|
|
17
|
+
export declare function creatable<T extends EmptyObject | void = void, TParams extends CreatableParams = CreatableParams>(): <U extends Creatable<CreatableInstance<T, TParams>>>(constructor: U) => void;
|
|
18
18
|
/**
|
|
19
19
|
* Class annotation to be used to decorate Modules which support
|
|
20
20
|
* an asynchronous creation factory pattern
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Creatable.d.ts","sourceRoot":"","sources":["../../src/Creatable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAEjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAS1E,MAAM,WAAW,SAAS,CAAC,CAAC,SA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-
"version": "4.12.
|
|
3
|
+
"version": "4.12.17",
|
|
4
4
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
"module": "dist/neutral/index.mjs",
|
|
30
30
|
"types": "dist/types/index.d.ts",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@xylabs/assert": "^4.12.
|
|
33
|
-
"@xylabs/base": "^4.12.
|
|
34
|
-
"@xylabs/events": "^4.12.
|
|
35
|
-
"@xylabs/logger": "^4.12.
|
|
36
|
-
"@xylabs/object": "^4.12.
|
|
37
|
-
"@xylabs/promise": "^4.12.
|
|
38
|
-
"@xylabs/typeof": "^4.12.
|
|
32
|
+
"@xylabs/assert": "^4.12.17",
|
|
33
|
+
"@xylabs/base": "^4.12.17",
|
|
34
|
+
"@xylabs/events": "^4.12.17",
|
|
35
|
+
"@xylabs/logger": "^4.12.17",
|
|
36
|
+
"@xylabs/object": "^4.12.17",
|
|
37
|
+
"@xylabs/promise": "^4.12.17",
|
|
38
|
+
"@xylabs/typeof": "^4.12.17"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@xylabs/ts-scripts-yarn3": "^6.5.9",
|
package/src/AbstractCreatable.ts
CHANGED
|
@@ -35,9 +35,9 @@ export abstract class AbstractCreatable<TParams extends CreatableParams = Creata
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
static async create<T extends EmptyObject | void = void, TParams extends CreatableParams = CreatableParams>(
|
|
38
|
-
this: Creatable<T, TParams
|
|
38
|
+
this: Creatable<CreatableInstance<T, TParams>>,
|
|
39
39
|
params: Partial<CreatableParams<TParams>>,
|
|
40
|
-
): Promise<CreatableInstance<T>> {
|
|
40
|
+
): Promise<CreatableInstance<T, TParams>> {
|
|
41
41
|
const name: CreatableName = params.name ?? this.name
|
|
42
42
|
params.statusReporter?.report(name, 'creating')
|
|
43
43
|
try {
|
|
@@ -54,9 +54,9 @@ export abstract class AbstractCreatable<TParams extends CreatableParams = Creata
|
|
|
54
54
|
|
|
55
55
|
/* override this for initialization of instance */
|
|
56
56
|
static createHandler<T extends EmptyObject | void = void, TParams extends CreatableParams = CreatableParams>(
|
|
57
|
-
this: Creatable<T, TParams
|
|
58
|
-
instance: CreatableInstance<T>,
|
|
59
|
-
): Promisable<CreatableInstance<T>> {
|
|
57
|
+
this: Creatable<CreatableInstance<T, TParams>>,
|
|
58
|
+
instance: CreatableInstance<T, TParams>,
|
|
59
|
+
): Promisable<CreatableInstance<T, TParams>> {
|
|
60
60
|
return instance
|
|
61
61
|
}
|
|
62
62
|
|
package/src/Creatable.ts
CHANGED
|
@@ -11,20 +11,20 @@ export interface CreatableFactory<T extends EmptyObject | void = void,
|
|
|
11
11
|
}
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
export interface Creatable<T extends
|
|
14
|
+
export interface Creatable<T extends CreatableInstance = CreatableInstance> {
|
|
15
15
|
|
|
16
16
|
defaultLogger?: Logger
|
|
17
17
|
|
|
18
|
-
new (params: Partial<
|
|
18
|
+
new (params: Partial<T['params']>): T & AbstractCreatable<T['params']>
|
|
19
19
|
|
|
20
|
-
create<T extends
|
|
21
|
-
this: Creatable<T
|
|
22
|
-
params: Partial<
|
|
20
|
+
create<T extends CreatableInstance>(
|
|
21
|
+
this: Creatable<T>,
|
|
22
|
+
params: Partial<T['params']>): Promise<T>
|
|
23
23
|
|
|
24
|
-
createHandler<T extends
|
|
25
|
-
this: Creatable<T
|
|
26
|
-
instance:
|
|
27
|
-
): Promise<
|
|
24
|
+
createHandler<T extends CreatableInstance>(
|
|
25
|
+
this: Creatable<T>,
|
|
26
|
+
instance: T
|
|
27
|
+
): Promise<T>
|
|
28
28
|
|
|
29
29
|
/*
|
|
30
30
|
factory<T extends EmptyObject | void = void,
|
|
@@ -38,8 +38,8 @@ export interface Creatable<T extends EmptyObject | void = void, TParams extends
|
|
|
38
38
|
* @returns The decorated Module requiring it implement the members
|
|
39
39
|
* of the CreatableModule as statics properties/methods
|
|
40
40
|
*/
|
|
41
|
-
export function creatable<
|
|
42
|
-
return <U extends Creatable<
|
|
41
|
+
export function creatable<T extends EmptyObject | void = void, TParams extends CreatableParams = CreatableParams>() {
|
|
42
|
+
return <U extends Creatable<CreatableInstance<T, TParams>>>(constructor: U) => {
|
|
43
43
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
44
44
|
constructor
|
|
45
45
|
}
|