@xylabs/creatable 4.12.33 → 4.12.35
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 +41 -1
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/types/AbstractCreatable.d.ts +4 -3
- package/dist/types/AbstractCreatable.d.ts.map +1 -1
- package/dist/types/Creatable.d.ts +8 -3
- package/dist/types/Creatable.d.ts.map +1 -1
- package/dist/types/Factory.d.ts +11 -0
- package/dist/types/Factory.d.ts.map +1 -0
- package/dist/types/model/Labels.d.ts +26 -0
- package/dist/types/model/Labels.d.ts.map +1 -0
- package/dist/types/model/index.d.ts +1 -0
- package/dist/types/model/index.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/AbstractCreatable.ts +14 -2
- package/src/Creatable.ts +16 -15
- package/src/Factory.ts +38 -0
- package/src/model/Labels.ts +33 -0
- package/src/model/index.ts +1 -0
- package/dist/types/TestCreatable.d.ts +0 -13
- package/dist/types/TestCreatable.d.ts.map +0 -1
- package/dist/types/TestCreatable2.d.ts +0 -14
- package/dist/types/TestCreatable2.d.ts.map +0 -1
- package/src/TestCreatable.ts +0 -28
- package/src/TestCreatable2.ts +0 -28
package/dist/neutral/index.mjs
CHANGED
|
@@ -20,6 +20,33 @@ function creatable() {
|
|
|
20
20
|
constructor;
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
+
function creatableFactory() {
|
|
24
|
+
return (constructor) => {
|
|
25
|
+
constructor;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// src/Factory.ts
|
|
30
|
+
var Factory = class _Factory {
|
|
31
|
+
creatable;
|
|
32
|
+
defaultParams;
|
|
33
|
+
labels;
|
|
34
|
+
constructor(creatable2, params, labels = {}) {
|
|
35
|
+
this.creatable = creatable2;
|
|
36
|
+
this.defaultParams = params;
|
|
37
|
+
this.labels = Object.assign({}, creatable2.labels ?? {}, labels ?? {});
|
|
38
|
+
}
|
|
39
|
+
static withParams(creatableModule, params, labels = {}) {
|
|
40
|
+
return new _Factory(creatableModule, params, labels);
|
|
41
|
+
}
|
|
42
|
+
create(params) {
|
|
43
|
+
const mergedParams = {
|
|
44
|
+
...this.defaultParams,
|
|
45
|
+
...params
|
|
46
|
+
};
|
|
47
|
+
return this.creatable.create(mergedParams);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
23
50
|
|
|
24
51
|
// src/lib/getFunctionName.ts
|
|
25
52
|
import { isNumber } from "@xylabs/typeof";
|
|
@@ -84,6 +111,9 @@ var AbstractCreatable = class extends BaseEmitter {
|
|
|
84
111
|
static createHandler(instance) {
|
|
85
112
|
return instance;
|
|
86
113
|
}
|
|
114
|
+
static factory(params, labels) {
|
|
115
|
+
return Factory.withParams(this, params, labels);
|
|
116
|
+
}
|
|
87
117
|
static paramsHandler(params = {}) {
|
|
88
118
|
return { ...params };
|
|
89
119
|
}
|
|
@@ -129,8 +159,18 @@ var AbstractCreatable = class extends BaseEmitter {
|
|
|
129
159
|
AbstractCreatable = __decorateClass([
|
|
130
160
|
creatable()
|
|
131
161
|
], AbstractCreatable);
|
|
162
|
+
|
|
163
|
+
// src/model/Labels.ts
|
|
164
|
+
var hasAllLabels = (source, required) => {
|
|
165
|
+
if (!required) return true;
|
|
166
|
+
return Object.entries(required).every(([key, value]) => {
|
|
167
|
+
return source?.hasOwnProperty(key) && source?.[key] === value;
|
|
168
|
+
});
|
|
169
|
+
};
|
|
132
170
|
export {
|
|
133
171
|
AbstractCreatable,
|
|
134
|
-
creatable
|
|
172
|
+
creatable,
|
|
173
|
+
creatableFactory,
|
|
174
|
+
hasAllLabels
|
|
135
175
|
};
|
|
136
176
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/AbstractCreatable.ts","../../src/Creatable.ts","../../src/lib/getFunctionName.ts","../../src/lib/getRootFunction.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 { Promisable } from '@xylabs/promise'\nimport { isError } from '@xylabs/typeof'\n\nimport { type Creatable, creatable } from './Creatable.ts'\nimport { getFunctionName, getRootFunction } from './lib/index.ts'\nimport type {\n CreatableInstance, CreatableName, CreatableParams,\n} from './model/index.ts'\n\nconst AbstractCreatableConstructorKey = Symbol.for('AbstractCreatableConstructor')\n\n@creatable()\nexport class AbstractCreatable<TParams extends CreatableParams = CreatableParams,\n TEventData extends EventData = EventData> extends BaseEmitter<Partial<TParams>, TEventData> {\n defaultLogger?: Logger\n\n private _validatedParams?: TParams\n\n constructor(key: unknown, params: Partial<TParams>) {\n assertEx(key === AbstractCreatableConstructorKey, () => 'AbstractCreatable should not be instantiated directly, use the static create method instead')\n super(params)\n }\n\n get name(): CreatableName {\n return this.params.name ?? this.constructor.name\n }\n\n override get params(): TParams {\n this._validatedParams = this._validatedParams ?? this.paramsValidator(super.params)\n return this._validatedParams\n }\n\n get statusReporter() {\n return this.params.statusReporter\n }\n\n static async create<T extends CreatableInstance>(\n this: Creatable<T>,\n inParams: Partial<T['params']> = {},\n ): Promise<T> {\n const params = await this.paramsHandler(inParams)\n const name: CreatableName = params.name ?? this.name\n params.statusReporter?.report(name, 'creating')\n try {\n const instance = new this(AbstractCreatableConstructorKey, 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 isError(ex) ? ex : new Error(`Error creating: ${name}`)\n }\n }\n\n static createHandler<T extends CreatableInstance>(\n this: Creatable<T>,\n instance: T,\n ): Promisable<T> {\n return instance\n }\n\n static paramsHandler<T extends CreatableInstance>(\n this: Creatable<T>,\n params: Partial<T['params']> = {},\n ): Promisable<Partial<T['params']>> {\n return { ...params }\n }\n\n createHandler(): Promisable<void> {}\n\n paramsValidator(params: Partial<TParams>): TParams {\n return { ...params, name: params.name ?? this.constructor.name } as TParams\n }\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","import type { Logger } from '@xylabs/logger'\nimport type { Promisable } from '@xylabs/promise'\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(key: unknown, params: Partial<CreatableParams>): 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 ): Promisable<T>\n\n paramsHandler<T extends CreatableInstance>(\n this: Creatable<T>, params?: Partial<T['params']>): Promisable<Partial<T['params']>>\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 CreatableInstance>() {\n return <U extends Creatable<T>>(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","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"],"mappings":";;;;;;;;;;;;AAAA,SAAS,gBAAgB;AAEzB,SAAS,mBAAmB;AAG5B,SAAS,eAAe;;;ACsCjB,SAAS,YAAyC;AACvD,SAAO,CAAyB,gBAAmB;AAEjD;AAAA,EACF;AACF;;;AChDA,SAAS,gBAAgB;AAElB,SAAS,gBAAgB,QAAQ,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AAQ,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;AACF;AAxGa,oBAAN;AAAA,EADN,UAAU;AAAA,GACE;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/AbstractCreatable.ts","../../src/Creatable.ts","../../src/Factory.ts","../../src/lib/getFunctionName.ts","../../src/lib/getRootFunction.ts","../../src/model/Labels.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 { Promisable } from '@xylabs/promise'\nimport { isError } from '@xylabs/typeof'\n\nimport {\n type Creatable, creatable, CreatableFactory,\n} from './Creatable.ts'\nimport { Factory } from './Factory.ts'\nimport { getFunctionName, getRootFunction } from './lib/index.ts'\nimport type {\n CreatableInstance, CreatableName, CreatableParams,\n Labels,\n} from './model/index.ts'\n\nconst AbstractCreatableConstructorKey = Symbol.for('AbstractCreatableConstructor')\n\n@creatable()\nexport class AbstractCreatable<TParams extends CreatableParams = CreatableParams,\n TEventData extends EventData = EventData> extends BaseEmitter<Partial<TParams>, TEventData> {\n defaultLogger?: Logger\n\n private _validatedParams?: TParams\n\n constructor(key: unknown, params: Partial<TParams>) {\n assertEx(key === AbstractCreatableConstructorKey, () => 'AbstractCreatable should not be instantiated directly, use the static create method instead')\n super(params)\n }\n\n get name(): CreatableName {\n return this.params.name ?? this.constructor.name\n }\n\n override get params(): TParams {\n this._validatedParams = this._validatedParams ?? this.paramsValidator(super.params)\n return this._validatedParams\n }\n\n get statusReporter() {\n return this.params.statusReporter\n }\n\n static async create<T extends CreatableInstance>(\n this: Creatable<T>,\n inParams: Partial<T['params']> = {},\n ): Promise<T> {\n const params = await this.paramsHandler(inParams)\n const name: CreatableName = params.name ?? this.name\n params.statusReporter?.report(name, 'creating')\n try {\n const instance = new this(AbstractCreatableConstructorKey, 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 isError(ex) ? ex : new Error(`Error creating: ${name}`)\n }\n }\n\n static createHandler<T extends CreatableInstance>(\n this: Creatable<T>,\n instance: T,\n ): Promisable<T> {\n return instance\n }\n\n static factory<T extends CreatableInstance>(\n this: Creatable<T>,\n params?: Partial<T['params']>,\n labels?: Labels,\n ): CreatableFactory<T> {\n return Factory.withParams<T>(this, params, labels)\n }\n\n static paramsHandler<T extends CreatableInstance>(\n this: Creatable<T>,\n params: Partial<T['params']> = {},\n ): Promisable<T['params']> {\n return { ...params }\n }\n\n createHandler(): Promisable<void> {}\n\n paramsValidator(params: Partial<TParams>): TParams {\n return { ...params, name: params.name ?? this.constructor.name } as TParams\n }\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","import type { Logger } from '@xylabs/logger'\nimport type { Promisable } from '@xylabs/promise'\n\nimport type { AbstractCreatable } from './AbstractCreatable.ts'\nimport type {\n CreatableInstance, CreatableParams, Labels,\n} from './model/index.ts'\n\nexport interface CreatableFactory<T extends CreatableInstance = CreatableInstance>\n extends Omit<Creatable<T>, 'create' | 'createHandler' | 'paramsHandler' | 'defaultLogger' | 'factory'> {\n\n create(\n this: CreatableFactory<T>,\n params?: Partial<T['params']>): Promise<T>\n}\n\nexport interface Creatable<T extends CreatableInstance = CreatableInstance> {\n\n defaultLogger?: Logger\n\n new(key: unknown, params: Partial<CreatableParams>): 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 ): Promisable<T>\n\n factory<T extends CreatableInstance>(\n this: Creatable<T>,\n params?: Partial<T['params']>,\n labels?: Labels): CreatableFactory<T>\n\n paramsHandler<T extends CreatableInstance>(\n this: Creatable<T>, params?: Partial<T['params']>): Promisable<T['params']>\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 CreatableInstance>() {\n return <U extends Creatable<T>>(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\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","import { type Creatable, type CreatableFactory } from './Creatable.ts'\nimport type {\n CreatableInstance, Labels, WithOptionalLabels,\n} from './model/index.ts'\n\nexport class Factory<T extends CreatableInstance = CreatableInstance> implements CreatableFactory<T> {\n creatable: Creatable<T>\n\n defaultParams?: Partial<T['params']>\n\n labels?: Labels\n\n constructor(\n creatable: Creatable<T>,\n params?: Partial<T['params']>,\n labels: Labels = {},\n ) {\n this.creatable = creatable\n this.defaultParams = params\n this.labels = Object.assign({}, (creatable as WithOptionalLabels).labels ?? {}, labels ?? {})\n }\n\n static withParams<T extends CreatableInstance>(\n creatableModule: Creatable<T>,\n params?: Partial<T['params']>,\n labels: Labels = {},\n ) {\n return new Factory<T>(creatableModule, params, labels)\n }\n\n create(params?: Partial<T['params']>): Promise<T> {\n const mergedParams: T['params'] = {\n ...this.defaultParams,\n ...params,\n } as T['params']\n return this.creatable.create<T>(mergedParams)\n }\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","/**\n * Object used to represent labels identifying a resource.\n */\nexport interface Labels {\n [key: string]: string | undefined\n}\n\n/**\n * Interface for objects that have labels.\n */\nexport interface WithLabels<T extends Labels = Labels> {\n labels: T\n}\n\n/**\n * Interface for objects that have labels.\n */\nexport interface WithOptionalLabels<T extends Labels = Labels> {\n labels?: T\n}\n\n/**\n * Returns true if the source object has all the labels from the required set\n * @param source Source object to check against\n * @param required Set of labels to check for in source\n * @returns True of the source object has all the labels from the required set\n */\nexport const hasAllLabels = (source?: Labels, required?: Labels): boolean => {\n if (!required) return true\n return Object.entries(required).every(([key, value]) => {\n return source?.hasOwnProperty(key as keyof typeof source) && source?.[key as keyof typeof source] === value\n })\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,gBAAgB;AAEzB,SAAS,mBAAmB;AAG5B,SAAS,eAAe;;;ACyCjB,SAAS,YAAyC;AACvD,SAAO,CAAyB,gBAAmB;AAEjD;AAAA,EACF;AACF;AASO,SAAS,mBAAmB;AACjC,SAAO,CAA6B,gBAAmB;AAErD;AAAA,EACF;AACF;;;AC5DO,IAAM,UAAN,MAAM,SAAwF;AAAA,EACnG;AAAA,EAEA;AAAA,EAEA;AAAA,EAEA,YACEA,YACA,QACA,SAAiB,CAAC,GAClB;AACA,SAAK,YAAYA;AACjB,SAAK,gBAAgB;AACrB,SAAK,SAAS,OAAO,OAAO,CAAC,GAAIA,WAAiC,UAAU,CAAC,GAAG,UAAU,CAAC,CAAC;AAAA,EAC9F;AAAA,EAEA,OAAO,WACL,iBACA,QACA,SAAiB,CAAC,GAClB;AACA,WAAO,IAAI,SAAW,iBAAiB,QAAQ,MAAM;AAAA,EACvD;AAAA,EAEA,OAAO,QAA2C;AAChD,UAAM,eAA4B;AAAA,MAChC,GAAG,KAAK;AAAA,MACR,GAAG;AAAA,IACL;AACA,WAAO,KAAK,UAAU,OAAU,YAAY;AAAA,EAC9C;AACF;;;ACrCA,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,Q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AAE,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;AACF;AAhHa,oBAAN;AAAA,EADN,UAAU;AAAA,GACE;;;AKON,IAAM,eAAe,CAAC,QAAiB,aAA+B;AAC3E,MAAI,CAAC,SAAU,QAAO;AACtB,SAAO,OAAO,QAAQ,QAAQ,EAAE,MAAM,CAAC,CAAC,KAAK,KAAK,MAAM;AACtD,WAAO,QAAQ,eAAe,GAA0B,KAAK,SAAS,GAA0B,MAAM;AAAA,EACxG,CAAC;AACH;","names":["creatable"]}
|
|
@@ -2,8 +2,8 @@ import type { EventData } from '@xylabs/events';
|
|
|
2
2
|
import { BaseEmitter } from '@xylabs/events';
|
|
3
3
|
import { type Logger } from '@xylabs/logger';
|
|
4
4
|
import type { Promisable } from '@xylabs/promise';
|
|
5
|
-
import { type Creatable } from './Creatable.ts';
|
|
6
|
-
import type { CreatableInstance, CreatableName, CreatableParams } from './model/index.ts';
|
|
5
|
+
import { type Creatable, CreatableFactory } from './Creatable.ts';
|
|
6
|
+
import type { CreatableInstance, CreatableName, CreatableParams, Labels } from './model/index.ts';
|
|
7
7
|
export declare class AbstractCreatable<TParams extends CreatableParams = CreatableParams, TEventData extends EventData = EventData> extends BaseEmitter<Partial<TParams>, TEventData> {
|
|
8
8
|
defaultLogger?: Logger;
|
|
9
9
|
private _validatedParams?;
|
|
@@ -13,7 +13,8 @@ export declare class AbstractCreatable<TParams extends CreatableParams = Creatab
|
|
|
13
13
|
get statusReporter(): import("./model/CreatableStatusReporter.ts").CreatableStatusReporter<void> | undefined;
|
|
14
14
|
static create<T extends CreatableInstance>(this: Creatable<T>, inParams?: Partial<T['params']>): Promise<T>;
|
|
15
15
|
static createHandler<T extends CreatableInstance>(this: Creatable<T>, instance: T): Promisable<T>;
|
|
16
|
-
static
|
|
16
|
+
static factory<T extends CreatableInstance>(this: Creatable<T>, params?: Partial<T['params']>, labels?: Labels): CreatableFactory<T>;
|
|
17
|
+
static paramsHandler<T extends CreatableInstance>(this: Creatable<T>, params?: Partial<T['params']>): Promisable<T['params']>;
|
|
17
18
|
createHandler(): Promisable<void>;
|
|
18
19
|
paramsValidator(params: Partial<TParams>): TParams;
|
|
19
20
|
start(): 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,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAGjD,OAAO,
|
|
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,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAGjD,OAAO,EACL,KAAK,SAAS,EAAa,gBAAgB,EAC5C,MAAM,gBAAgB,CAAA;AAGvB,OAAO,KAAK,EACV,iBAAiB,EAAE,aAAa,EAAE,eAAe,EACjD,MAAM,EACP,MAAM,kBAAkB,CAAA;AAIzB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,CAAC,OAAO,CAAC,GAAG,OAAO;IAI5C,KAAK,IAAI,OAAO,CAAC,OAAO,CAAC;IAazB,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAa9B,SAAS,CAAC,WAAW,CAAC,YAAY,SAAqB;IAQvD,SAAS,CAAC,YAAY,IAAI,UAAU,CAAC,IAAI,CAAC;IAI1C,SAAS,CAAC,WAAW,IAAI,UAAU,CAAC,IAAI,CAAC;CAG1C"}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import type { Logger } from '@xylabs/logger';
|
|
2
2
|
import type { Promisable } from '@xylabs/promise';
|
|
3
3
|
import type { AbstractCreatable } from './AbstractCreatable.ts';
|
|
4
|
-
import type { CreatableInstance, CreatableParams } from './model/index.ts';
|
|
4
|
+
import type { CreatableInstance, CreatableParams, Labels } from './model/index.ts';
|
|
5
|
+
export interface CreatableFactory<T extends CreatableInstance = CreatableInstance> extends Omit<Creatable<T>, 'create' | 'createHandler' | 'paramsHandler' | 'defaultLogger' | 'factory'> {
|
|
6
|
+
create(this: CreatableFactory<T>, params?: Partial<T['params']>): Promise<T>;
|
|
7
|
+
}
|
|
5
8
|
export interface Creatable<T extends CreatableInstance = CreatableInstance> {
|
|
6
9
|
defaultLogger?: Logger;
|
|
7
10
|
new (key: unknown, params: Partial<CreatableParams>): T & AbstractCreatable<T['params']>;
|
|
8
|
-
create<T extends CreatableInstance>(this: Creatable<T>, params
|
|
11
|
+
create<T extends CreatableInstance>(this: Creatable<T>, params?: Partial<T['params']>): Promise<T>;
|
|
9
12
|
createHandler<T extends CreatableInstance>(this: Creatable<T>, instance: T): Promisable<T>;
|
|
10
|
-
|
|
13
|
+
factory<T extends CreatableInstance>(this: Creatable<T>, params?: Partial<T['params']>, labels?: Labels): CreatableFactory<T>;
|
|
14
|
+
paramsHandler<T extends CreatableInstance>(this: Creatable<T>, params?: Partial<T['params']>): Promisable<T['params']>;
|
|
11
15
|
}
|
|
12
16
|
/**
|
|
13
17
|
* Class annotation to be used to decorate Modules which support
|
|
@@ -22,4 +26,5 @@ export declare function creatable<T extends CreatableInstance>(): <U extends Cre
|
|
|
22
26
|
* @returns The decorated Module requiring it implement the members
|
|
23
27
|
* of the CreatableModule as statics properties/methods
|
|
24
28
|
*/
|
|
29
|
+
export declare function creatableFactory(): <U extends CreatableFactory>(constructor: U) => void;
|
|
25
30
|
//# sourceMappingURL=Creatable.d.ts.map
|
|
@@ -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,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC/D,OAAO,KAAK,
|
|
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,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC/D,OAAO,KAAK,EACV,iBAAiB,EAAE,eAAe,EAAE,MAAM,EAC3C,MAAM,kBAAkB,CAAA;AAEzB,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,iBAAiB,GAAG,iBAAiB,CAC/E,SAAQ,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,GAAG,eAAe,GAAG,eAAe,GAAG,eAAe,GAAG,SAAS,CAAC;IAEtG,MAAM,CACJ,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,EACzB,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,C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}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Creatable, type CreatableFactory } from './Creatable.ts';
|
|
2
|
+
import type { CreatableInstance, Labels } from './model/index.ts';
|
|
3
|
+
export declare class Factory<T extends CreatableInstance = CreatableInstance> implements CreatableFactory<T> {
|
|
4
|
+
creatable: Creatable<T>;
|
|
5
|
+
defaultParams?: Partial<T['params']>;
|
|
6
|
+
labels?: Labels;
|
|
7
|
+
constructor(creatable: Creatable<T>, params?: Partial<T['params']>, labels?: Labels);
|
|
8
|
+
static withParams<T extends CreatableInstance>(creatableModule: Creatable<T>, params?: Partial<T['params']>, labels?: Labels): Factory<T>;
|
|
9
|
+
create(params?: Partial<T['params']>): Promise<T>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=Factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Factory.d.ts","sourceRoot":"","sources":["../../src/Factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACtE,OAAO,KAAK,EACV,iBAAiB,EAAE,MAAM,EAC1B,MAAM,kBAAkB,CAAA;AAEzB,qBAAa,OAAO,CAAC,CAAC,SAAS,iBAAiB,GAAG,iBAAiB,CAAE,YAAW,gBAAgB,CAAC,CAAC,CAAC;IAClG,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,CAAA;IAEvB,aAAa,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAA;IAEpC,MAAM,CAAC,EAAE,MAAM,CAAA;gBAGb,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,EACvB,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAC7B,MAAM,GAAE,MAAW;IAOrB,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS,iBAAiB,EAC3C,eAAe,EAAE,SAAS,CAAC,CAAC,CAAC,EAC7B,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAC7B,MAAM,GAAE,MAAW;IAKrB,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAOlD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Object used to represent labels identifying a resource.
|
|
3
|
+
*/
|
|
4
|
+
export interface Labels {
|
|
5
|
+
[key: string]: string | undefined;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Interface for objects that have labels.
|
|
9
|
+
*/
|
|
10
|
+
export interface WithLabels<T extends Labels = Labels> {
|
|
11
|
+
labels: T;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Interface for objects that have labels.
|
|
15
|
+
*/
|
|
16
|
+
export interface WithOptionalLabels<T extends Labels = Labels> {
|
|
17
|
+
labels?: T;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Returns true if the source object has all the labels from the required set
|
|
21
|
+
* @param source Source object to check against
|
|
22
|
+
* @param required Set of labels to check for in source
|
|
23
|
+
* @returns True of the source object has all the labels from the required set
|
|
24
|
+
*/
|
|
25
|
+
export declare const hasAllLabels: (source?: Labels, required?: Labels) => boolean;
|
|
26
|
+
//# sourceMappingURL=Labels.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Labels.d.ts","sourceRoot":"","sources":["../../../src/model/Labels.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IACnD,MAAM,EAAE,CAAC,CAAA;CACV;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IAC3D,MAAM,CAAC,EAAE,CAAC,CAAA;CACX;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,MAAM,EAAE,WAAW,MAAM,KAAG,OAKjE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/model/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,sBAAsB,CAAA;AACpC,cAAc,8BAA8B,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/model/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,sBAAsB,CAAA;AACpC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,aAAa,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/creatable",
|
|
3
|
-
"version": "4.12.
|
|
3
|
+
"version": "4.12.35",
|
|
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.35",
|
|
33
|
+
"@xylabs/base": "^4.12.35",
|
|
34
|
+
"@xylabs/events": "^4.12.35",
|
|
35
|
+
"@xylabs/logger": "^4.12.35",
|
|
36
|
+
"@xylabs/object": "^4.12.35",
|
|
37
|
+
"@xylabs/promise": "^4.12.35",
|
|
38
|
+
"@xylabs/typeof": "^4.12.35"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@xylabs/ts-scripts-yarn3": "^6.5.12",
|
package/src/AbstractCreatable.ts
CHANGED
|
@@ -5,10 +5,14 @@ import { type Logger } from '@xylabs/logger'
|
|
|
5
5
|
import type { Promisable } from '@xylabs/promise'
|
|
6
6
|
import { isError } from '@xylabs/typeof'
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
type Creatable, creatable, CreatableFactory,
|
|
10
|
+
} from './Creatable.ts'
|
|
11
|
+
import { Factory } from './Factory.ts'
|
|
9
12
|
import { getFunctionName, getRootFunction } from './lib/index.ts'
|
|
10
13
|
import type {
|
|
11
14
|
CreatableInstance, CreatableName, CreatableParams,
|
|
15
|
+
Labels,
|
|
12
16
|
} from './model/index.ts'
|
|
13
17
|
|
|
14
18
|
const AbstractCreatableConstructorKey = Symbol.for('AbstractCreatableConstructor')
|
|
@@ -64,10 +68,18 @@ export class AbstractCreatable<TParams extends CreatableParams = CreatableParams
|
|
|
64
68
|
return instance
|
|
65
69
|
}
|
|
66
70
|
|
|
71
|
+
static factory<T extends CreatableInstance>(
|
|
72
|
+
this: Creatable<T>,
|
|
73
|
+
params?: Partial<T['params']>,
|
|
74
|
+
labels?: Labels,
|
|
75
|
+
): CreatableFactory<T> {
|
|
76
|
+
return Factory.withParams<T>(this, params, labels)
|
|
77
|
+
}
|
|
78
|
+
|
|
67
79
|
static paramsHandler<T extends CreatableInstance>(
|
|
68
80
|
this: Creatable<T>,
|
|
69
81
|
params: Partial<T['params']> = {},
|
|
70
|
-
): Promisable<
|
|
82
|
+
): Promisable<T['params']> {
|
|
71
83
|
return { ...params }
|
|
72
84
|
}
|
|
73
85
|
|
package/src/Creatable.ts
CHANGED
|
@@ -2,14 +2,17 @@ import type { Logger } from '@xylabs/logger'
|
|
|
2
2
|
import type { Promisable } from '@xylabs/promise'
|
|
3
3
|
|
|
4
4
|
import type { AbstractCreatable } from './AbstractCreatable.ts'
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
CreatableInstance, CreatableParams, Labels,
|
|
7
|
+
} from './model/index.ts'
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
create(
|
|
9
|
+
export interface CreatableFactory<T extends CreatableInstance = CreatableInstance>
|
|
10
|
+
extends Omit<Creatable<T>, 'create' | 'createHandler' | 'paramsHandler' | 'defaultLogger' | 'factory'> {
|
|
11
|
+
|
|
12
|
+
create(
|
|
13
|
+
this: CreatableFactory<T>,
|
|
14
|
+
params?: Partial<T['params']>): Promise<T>
|
|
11
15
|
}
|
|
12
|
-
*/
|
|
13
16
|
|
|
14
17
|
export interface Creatable<T extends CreatableInstance = CreatableInstance> {
|
|
15
18
|
|
|
@@ -19,20 +22,20 @@ export interface Creatable<T extends CreatableInstance = CreatableInstance> {
|
|
|
19
22
|
|
|
20
23
|
create<T extends CreatableInstance>(
|
|
21
24
|
this: Creatable<T>,
|
|
22
|
-
params
|
|
25
|
+
params?: Partial<T['params']>): Promise<T>
|
|
23
26
|
|
|
24
27
|
createHandler<T extends CreatableInstance>(
|
|
25
28
|
this: Creatable<T>,
|
|
26
29
|
instance: T
|
|
27
30
|
): Promisable<T>
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
this: Creatable<T>,
|
|
32
|
+
factory<T extends CreatableInstance>(
|
|
33
|
+
this: Creatable<T>,
|
|
34
|
+
params?: Partial<T['params']>,
|
|
35
|
+
labels?: Labels): CreatableFactory<T>
|
|
31
36
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
TParams extends EmptyObject | void = void> (this: Creatable<T, TParams>, params: Partial<CreatableParams<TParams>>): CreatableFactory<T, TParams>
|
|
35
|
-
*/
|
|
37
|
+
paramsHandler<T extends CreatableInstance>(
|
|
38
|
+
this: Creatable<T>, params?: Partial<T['params']>): Promisable<T['params']>
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
/**
|
|
@@ -55,11 +58,9 @@ export function creatable<T extends CreatableInstance>() {
|
|
|
55
58
|
* of the CreatableModule as statics properties/methods
|
|
56
59
|
*/
|
|
57
60
|
|
|
58
|
-
/*
|
|
59
61
|
export function creatableFactory() {
|
|
60
62
|
return <U extends CreatableFactory>(constructor: U) => {
|
|
61
63
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
62
64
|
constructor
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
|
-
*/
|
package/src/Factory.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type Creatable, type CreatableFactory } from './Creatable.ts'
|
|
2
|
+
import type {
|
|
3
|
+
CreatableInstance, Labels, WithOptionalLabels,
|
|
4
|
+
} from './model/index.ts'
|
|
5
|
+
|
|
6
|
+
export class Factory<T extends CreatableInstance = CreatableInstance> implements CreatableFactory<T> {
|
|
7
|
+
creatable: Creatable<T>
|
|
8
|
+
|
|
9
|
+
defaultParams?: Partial<T['params']>
|
|
10
|
+
|
|
11
|
+
labels?: Labels
|
|
12
|
+
|
|
13
|
+
constructor(
|
|
14
|
+
creatable: Creatable<T>,
|
|
15
|
+
params?: Partial<T['params']>,
|
|
16
|
+
labels: Labels = {},
|
|
17
|
+
) {
|
|
18
|
+
this.creatable = creatable
|
|
19
|
+
this.defaultParams = params
|
|
20
|
+
this.labels = Object.assign({}, (creatable as WithOptionalLabels).labels ?? {}, labels ?? {})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static withParams<T extends CreatableInstance>(
|
|
24
|
+
creatableModule: Creatable<T>,
|
|
25
|
+
params?: Partial<T['params']>,
|
|
26
|
+
labels: Labels = {},
|
|
27
|
+
) {
|
|
28
|
+
return new Factory<T>(creatableModule, params, labels)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
create(params?: Partial<T['params']>): Promise<T> {
|
|
32
|
+
const mergedParams: T['params'] = {
|
|
33
|
+
...this.defaultParams,
|
|
34
|
+
...params,
|
|
35
|
+
} as T['params']
|
|
36
|
+
return this.creatable.create<T>(mergedParams)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Object used to represent labels identifying a resource.
|
|
3
|
+
*/
|
|
4
|
+
export interface Labels {
|
|
5
|
+
[key: string]: string | undefined
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Interface for objects that have labels.
|
|
10
|
+
*/
|
|
11
|
+
export interface WithLabels<T extends Labels = Labels> {
|
|
12
|
+
labels: T
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Interface for objects that have labels.
|
|
17
|
+
*/
|
|
18
|
+
export interface WithOptionalLabels<T extends Labels = Labels> {
|
|
19
|
+
labels?: T
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Returns true if the source object has all the labels from the required set
|
|
24
|
+
* @param source Source object to check against
|
|
25
|
+
* @param required Set of labels to check for in source
|
|
26
|
+
* @returns True of the source object has all the labels from the required set
|
|
27
|
+
*/
|
|
28
|
+
export const hasAllLabels = (source?: Labels, required?: Labels): boolean => {
|
|
29
|
+
if (!required) return true
|
|
30
|
+
return Object.entries(required).every(([key, value]) => {
|
|
31
|
+
return source?.hasOwnProperty(key as keyof typeof source) && source?.[key as keyof typeof source] === value
|
|
32
|
+
})
|
|
33
|
+
}
|
package/src/model/index.ts
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { EventData } from '@xylabs/events';
|
|
2
|
-
import { Promisable } from '@xylabs/promise';
|
|
3
|
-
import { AbstractCreatable } from './AbstractCreatable.ts';
|
|
4
|
-
import { Creatable } from './Creatable.ts';
|
|
5
|
-
import type { CreatableInstance, CreatableParams } from './model/index.ts';
|
|
6
|
-
export interface TestCreatableParams extends CreatableParams {
|
|
7
|
-
testParam: string;
|
|
8
|
-
}
|
|
9
|
-
export declare class TestCreatable<TParams extends TestCreatableParams = TestCreatableParams, TEventData extends EventData = EventData> extends AbstractCreatable<TParams, TEventData> {
|
|
10
|
-
static createHandler<T extends CreatableInstance>(this: Creatable<T>, instance: T): Promisable<T>;
|
|
11
|
-
paramsValidator(params?: Partial<TParams>): TParams;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=TestCreatable.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TestCreatable.d.ts","sourceRoot":"","sources":["../../src/TestCreatable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,SAAS,EAAa,MAAM,gBAAgB,CAAA;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAE1E,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,qBACa,aAAa,CAAC,OAAO,SAAS,mBAAmB,GAAG,mBAAmB,EAAE,UAAU,SAAS,SAAS,GAAG,SAAS,CAC5H,SAAQ,iBAAiB,CAAC,OAAO,EAAE,UAAU,CAAC;WAC9B,aAAa,CAAC,CAAC,SAAS,iBAAiB,EACvD,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,EAClB,QAAQ,EAAE,CAAC,GACV,UAAU,CAAC,CAAC,CAAC;IAIP,eAAe,CAAC,MAAM,GAAE,OAAO,CAAC,OAAO,CAAM,GAAG,OAAO;CAMjE"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { EventData } from '@xylabs/events';
|
|
2
|
-
import { Promisable } from '@xylabs/promise';
|
|
3
|
-
import { Creatable } from './Creatable.ts';
|
|
4
|
-
import type { CreatableInstance } from './model/index.ts';
|
|
5
|
-
import { TestCreatable, TestCreatableParams } from './TestCreatable.ts';
|
|
6
|
-
interface TestCreatableParams2 extends TestCreatableParams {
|
|
7
|
-
testParam2: number;
|
|
8
|
-
}
|
|
9
|
-
export declare class TestCreatable2<TParams extends TestCreatableParams2 = TestCreatableParams2, TEventData extends EventData = EventData> extends TestCreatable<TParams, TEventData> {
|
|
10
|
-
static createHandler<T extends CreatableInstance>(this: Creatable<T>, instance: T): Promisable<T>;
|
|
11
|
-
paramsValidator(params?: Partial<TParams>): TParams;
|
|
12
|
-
}
|
|
13
|
-
export {};
|
|
14
|
-
//# sourceMappingURL=TestCreatable2.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TestCreatable2.d.ts","sourceRoot":"","sources":["../../src/TestCreatable2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C,OAAO,EAAE,SAAS,EAAa,MAAM,gBAAgB,CAAA;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAEvE,UAAU,oBAAqB,SAAQ,mBAAmB;IACxD,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,qBACa,cAAc,CAAC,OAAO,SAAS,oBAAoB,GAAG,oBAAoB,EAAE,UAAU,SAAS,SAAS,GAAG,SAAS,CAC/H,SAAQ,aAAa,CAAC,OAAO,EAAE,UAAU,CAAC;WAC1B,aAAa,CAAC,CAAC,SAAS,iBAAiB,EACvD,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,EAClB,QAAQ,EAAE,CAAC,GACV,UAAU,CAAC,CAAC,CAAC;IAIP,eAAe,CAAC,MAAM,GAAE,OAAO,CAAC,OAAO,CAAM,GAAG,OAAO;CAMjE"}
|
package/src/TestCreatable.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { EventData } from '@xylabs/events'
|
|
2
|
-
import { Promisable } from '@xylabs/promise'
|
|
3
|
-
|
|
4
|
-
import { AbstractCreatable } from './AbstractCreatable.ts'
|
|
5
|
-
import { Creatable, creatable } from './Creatable.ts'
|
|
6
|
-
import type { CreatableInstance, CreatableParams } from './model/index.ts'
|
|
7
|
-
|
|
8
|
-
export interface TestCreatableParams extends CreatableParams {
|
|
9
|
-
testParam: string
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
@creatable()
|
|
13
|
-
export class TestCreatable<TParams extends TestCreatableParams = TestCreatableParams, TEventData extends EventData = EventData>
|
|
14
|
-
extends AbstractCreatable<TParams, TEventData> {
|
|
15
|
-
static override createHandler<T extends CreatableInstance>(
|
|
16
|
-
this: Creatable<T>,
|
|
17
|
-
instance: T,
|
|
18
|
-
): Promisable<T> {
|
|
19
|
-
return instance
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
override paramsValidator(params: Partial<TParams> = {}): TParams {
|
|
23
|
-
const result: TestCreatableParams = {
|
|
24
|
-
...params, name: params.name ?? this.constructor.name, testParam: 'yo',
|
|
25
|
-
}
|
|
26
|
-
return result as TParams
|
|
27
|
-
}
|
|
28
|
-
}
|
package/src/TestCreatable2.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { EventData } from '@xylabs/events'
|
|
2
|
-
import { Promisable } from '@xylabs/promise'
|
|
3
|
-
|
|
4
|
-
import { Creatable, creatable } from './Creatable.ts'
|
|
5
|
-
import type { CreatableInstance } from './model/index.ts'
|
|
6
|
-
import { TestCreatable, TestCreatableParams } from './TestCreatable.ts'
|
|
7
|
-
|
|
8
|
-
interface TestCreatableParams2 extends TestCreatableParams {
|
|
9
|
-
testParam2: number
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
@creatable()
|
|
13
|
-
export class TestCreatable2<TParams extends TestCreatableParams2 = TestCreatableParams2, TEventData extends EventData = EventData>
|
|
14
|
-
extends TestCreatable<TParams, TEventData> {
|
|
15
|
-
static override createHandler<T extends CreatableInstance>(
|
|
16
|
-
this: Creatable<T>,
|
|
17
|
-
instance: T,
|
|
18
|
-
): Promisable<T> {
|
|
19
|
-
return instance
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
override paramsValidator(params: Partial<TParams> = {}): TParams {
|
|
23
|
-
const result: TestCreatableParams = {
|
|
24
|
-
...params, name: params.name ?? this.constructor.name, testParam: 'yo',
|
|
25
|
-
}
|
|
26
|
-
return result as TParams
|
|
27
|
-
}
|
|
28
|
-
}
|