@xylabs/creatable 5.0.67 → 5.0.70

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.
@@ -1,20 +1,20 @@
1
- import type { BaseEmitterParamsV2, EventData } from '@xylabs/events';
1
+ import type { EventData } from '@xylabs/events';
2
2
  import { BaseEmitterV2 } from '@xylabs/events';
3
3
  import { type Logger } from '@xylabs/logger';
4
4
  import type { Promisable } from '@xylabs/promise';
5
5
  import type { SpanConfig } from '@xylabs/telemetry';
6
6
  import type { CreatableFactoryV2, CreatableV2 } from './CreatableV2.ts';
7
7
  import type { CreatableInstanceV2, CreatableName, CreatableParamsV2, CreatableStatusV2, Labels } from './model/index.ts';
8
- export declare abstract class AbstractCreatableV2<TParams extends CreatableParamsV2 = CreatableParamsV2, TEventData extends EventData = EventData> extends BaseEmitterV2<TParams, TEventData> {
8
+ export declare abstract class AbstractCreatableV2<TParams extends CreatableParamsV2 = CreatableParamsV2, TEventData extends EventData = EventData> extends BaseEmitterV2<TParams, TEventData> implements CreatableInstanceV2<TParams, TEventData> {
9
9
  defaultLogger?: Logger;
10
10
  protected _startPromise: Promisable<boolean> | undefined;
11
11
  private _status;
12
12
  private _statusMutex;
13
13
  private _validatedParams?;
14
14
  constructor(key: unknown, params: TParams);
15
- get context(): TParams['context'] & BaseEmitterParamsV2['context'];
15
+ get context(): TParams['context'];
16
16
  get name(): CreatableName;
17
- get params(): TParams & BaseEmitterParamsV2;
17
+ get params(): TParams;
18
18
  get startable(): boolean;
19
19
  get status(): CreatableStatusV2 | null;
20
20
  get statusReporter(): {
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractCreatableV2.d.ts","sourceRoot":"","sources":["../../src/AbstractCreatableV2.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,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M,CAAC,OAAO,CAAC,CAAC,SAAS,mBAAmB,EAC1C,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EACpB,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAC7B,MAAM,CAAC,EAAE,MAAM,GACd,kBAAkB,CAAC,CAAC,CAAC;CAGzB"}
@@ -332,6 +332,7 @@ var AbstractCreatableV2 = class extends BaseEmitterV2 {
332
332
  constructor(key, params) {
333
333
  assertEx2(key === AbstractCreatableConstructorKey2, () => "AbstractCreatable should not be instantiated directly, use the static create method instead");
334
334
  super(params);
335
+ this.setStatus("creating");
335
336
  }
336
337
  get context() {
337
338
  return this.params.context;
@@ -357,10 +358,8 @@ var AbstractCreatableV2 = class extends BaseEmitterV2 {
357
358
  const name = params.name ?? this.name;
358
359
  try {
359
360
  const instance = new this(AbstractCreatableConstructorKey2, params);
360
- instance.setStatus("creating");
361
361
  const initializedInstance = await this.createHandler(instance);
362
362
  await instance.createHandler();
363
- instance.setStatus("created");
364
363
  return initializedInstance;
365
364
  } catch (ex) {
366
365
  params.context.statusReporter?.report(name, "error", isError2(ex) ? ex : new Error(`Error creating: ${name}`));
@@ -376,6 +375,7 @@ var AbstractCreatableV2 = class extends BaseEmitterV2 {
376
375
  }
377
376
  createHandler() {
378
377
  assertEx2(this._status === "creating", () => `createHandler can not be called [status = ${this.status}]`);
378
+ this.setStatus("created");
379
379
  }
380
380
  paramsValidator(params) {
381
381
  return { ...params, name: params.name };
@@ -566,8 +566,8 @@ var CreatableStatusReporterV2Zod = z.object({
566
566
  });
567
567
 
568
568
  // src/model/CreatableParamsV2.ts
569
- var CreatableContext = z2.intersection(BaseContextZod, z2.object({ name: z2.string(), statusReporter: CreatableStatusReporterV2Zod.optional() }));
570
- var CreatableParamsV2Zod = BaseEmitterParamsV2Zod.extend(z2.object({ context: CreatableContext, name: z2.string() }).shape);
569
+ var CreatableContextZod = BaseContextZod.extend(z2.object({ name: z2.string(), statusReporter: CreatableStatusReporterV2Zod.optional() }).shape);
570
+ var CreatableParamsV2Zod = BaseEmitterParamsV2Zod.extend(z2.object({ context: CreatableContextZod, name: z2.string() }).shape);
571
571
 
572
572
  // src/model/Labels.ts
573
573
  var hasAllLabels = (source, required) => {
@@ -581,7 +581,7 @@ export {
581
581
  AbstractCreatableV2,
582
582
  AbstractCreatableWithFactory,
583
583
  AbstractCreatableWithFactoryV2,
584
- CreatableContext,
584
+ CreatableContextZod,
585
585
  CreatableParamsV2Zod,
586
586
  CreatableStatusErrorZod,
587
587
  CreatableStatusReporterV2Zod,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/AbstractCreatable.ts","../../src/Creatable.ts","../../src/Factory.ts","../../src/lib/getFunctionName.ts","../../src/lib/getRootFunction.ts","../../src/AbstractCreatableV2.ts","../../src/FactoryV2.ts","../../src/CreatableV2.ts","../../src/model/CreatableParamsV2.ts","../../src/model/CreatableStatusReporter.zod.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 {\n SpanConfig, spanRoot, spanRootAsync,\n} from '@xylabs/telemetry'\nimport {\n isError, isNumber, isString,\n isUndefined,\n} from '@xylabs/typeof'\nimport { Mutex } from 'async-mutex'\n\nimport {\n type Creatable, creatable, CreatableFactory,\n} from './Creatable.ts'\nimport { Factory } from './Factory.ts'\nimport { getFunctionName, getRootFunction } from './lib/index.ts'\nimport { CreatableName } from './model/CreatableName.ts'\nimport type {\n CreatableInstance, CreatableParams,\n CreatableStatus,\n Labels,\n RequiredCreatableParams,\n} from './model/index.ts'\n\nconst AbstractCreatableConstructorKey = Symbol.for('AbstractCreatableConstructor')\nconst CREATABLE_NOT_STARTED = 'Creatable not Started' as const\n\n/** @deprecated use AbstractCreatableV2 instead */\n@creatable()\nexport class AbstractCreatable<TParams extends CreatableParams = CreatableParams,\n TEventData extends EventData = EventData> extends BaseEmitter<Partial<TParams & RequiredCreatableParams>, TEventData> {\n defaultLogger?: Logger\n\n protected _startPromise: Promisable<boolean> | undefined\n private _status: CreatableStatus | null = null\n private _statusMutex = new Mutex()\n private _validatedParams?: TParams & RequiredCreatableParams\n\n constructor(key: unknown, params: Partial<TParams & RequiredCreatableParams>) {\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 as CreatableName\n }\n\n override get params(): TParams & RequiredCreatableParams {\n this._validatedParams = this._validatedParams ?? this.paramsValidator(super.params)\n return this._validatedParams\n }\n\n get startable() {\n return this.status === 'created' || this.status === 'stopped'\n }\n\n get status(): CreatableStatus | null {\n return this._status\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 as CreatableName\n try {\n const instance = new this(AbstractCreatableConstructorKey, params)\n instance.setStatus('creating')\n const initializedInstance = await this.createHandler(instance)\n await instance.createHandler()\n instance.setStatus('created')\n return initializedInstance\n } catch (ex) {\n params.statusReporter?.report(name, 'error', isError(ex) ? ex : new Error(`Error creating: ${name}`))\n params.logger?.error(`Error creating creatable [${name}]: ${(isError(ex) ? `${ex.message} ${ex.stack}` : ex)}`)\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<T['params']> {\n return { ...params }\n }\n\n createHandler(): Promisable<void> {\n assertEx(this._status === 'creating', () => `createHandler can not be called [status = ${this.status}]`)\n }\n\n paramsValidator(params: Partial<TParams & RequiredCreatableParams>): TParams & RequiredCreatableParams {\n return { ...params, name: params.name } as TParams & RequiredCreatableParams\n }\n\n span<T>(name: string, fn: () => T): T {\n return spanRoot(name, fn, this.tracer)\n }\n\n async spanAsync<T>(name: string, fn: () => Promise<T>, config: SpanConfig = {}): Promise<T> {\n return await spanRootAsync(name, fn, {\n ...config, tracer: config.tracer ?? this.tracer, logger: config.logger ?? this.defaultLogger,\n })\n }\n\n async start(): Promise<boolean> {\n this._noOverride('start')\n if (this.status === 'started') {\n return true\n }\n return await this._statusMutex.runExclusive(async () => {\n try {\n // check again in case it changed\n if (this.status === 'started') {\n return true\n }\n assertEx(this.startable, () => `Creatable [${this.name}] is not startable in status [${this.status}]`)\n this.setStatus('starting')\n await this.startHandler()\n this.setStatus('started')\n return true\n } catch (ex) {\n this.setStatus('error', isError(ex) ? ex : new Error(`Error starting: ${ex}`))\n this.logger?.error(`Error starting creatable [${this.name}]: ${(isError(ex) ? `${ex.message} ${ex.stack}` : ex)}`)\n return false\n }\n })\n }\n\n started(notStartedAction: 'error' | 'throw' | 'warn' | 'log' | 'none' = 'log'): boolean {\n if (isString(this.status) && this.status === 'started') {\n return true\n } else {\n const message = () => `${CREATABLE_NOT_STARTED} [${this.name}] current state: ${this.status}`\n switch (notStartedAction) {\n case 'error': {\n throw new Error(message())\n }\n case 'throw': {\n throw new Error(message())\n }\n case 'warn': {\n this.logger?.warn(message())\n break\n }\n case 'log': {\n this.logger?.log(message())\n break\n }\n case 'none': {\n break\n }\n default: {\n throw new Error(`Unknown notStartedAction: ${notStartedAction}`)\n }\n }\n return false\n }\n }\n\n async startedAsync(notStartedAction: 'error' | 'throw' | 'warn' | 'log' | 'none' = 'log', tryStart = true): Promise<boolean> {\n if (isString(this.status) && this.status === 'started') {\n return true\n } else if (this.status === 'created' || this.status === 'stopped' || this.status === 'starting') {\n // using promise as mutex\n this._startPromise = this._startPromise ?? (async () => {\n if (tryStart) {\n try {\n return await this.start()\n } finally {\n this._startPromise = undefined\n }\n }\n return this.started(notStartedAction)\n })()\n } else {\n const message = `${CREATABLE_NOT_STARTED} [${this.name}] current state: ${this.status}`\n throw new Error(message)\n }\n\n if (isUndefined(this._startPromise)) {\n throw new Error(`Failed to create start promise: ${this.status}`)\n }\n return await this._startPromise\n }\n\n async stop(): Promise<boolean> {\n this._noOverride('stop')\n if (this.status === 'stopped') {\n return true\n }\n return await this._statusMutex.runExclusive(async () => {\n try {\n // check again in case it changed\n if (this.status === 'stopped') {\n return true\n }\n assertEx(this.status === 'started', () => `Creatable [${this.name}] is not stoppable in status [${this.status}]`)\n this.setStatus('stopping')\n await this.stopHandler()\n this.setStatus('stopped')\n return true\n } catch (ex) {\n this.setStatus('error', isError(ex) ? ex : new Error(`Error stopping: ${ex}`))\n return false\n }\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 setStatus(value: Exclude<CreatableStatus, 'error'>, progress?: number): void\n protected setStatus(value: Extract<CreatableStatus, 'error'>, error?: Error): void\n protected setStatus(value: CreatableStatus, progressOrError?: number | Error): void {\n this._status = value\n if (value !== null) {\n if (value === 'error') {\n if (isError(progressOrError)) {\n this.statusReporter?.report(this.name, value, progressOrError)\n return\n }\n } else {\n if (isNumber(progressOrError)) {\n this.statusReporter?.report(this.name, value, progressOrError)\n return\n }\n }\n this.statusReporter?.report(this.name, value)\n }\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\n@creatable()\nexport class AbstractCreatableWithFactory<TParams extends CreatableParams = CreatableParams,\n TEventData extends EventData = EventData> extends AbstractCreatable<TParams, TEventData> {\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","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 RequiredCreatableParams,\n} from './model/index.ts'\n\n/** @deprecated use CreatableFactoryV2 instead */\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\n/** @deprecated use CreatableV2 instead */\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<T['params'] & RequiredCreatableParams>\n}\n\n/** @deprecated use CreatableWithFactoryV2 instead */\nexport interface CreatableWithFactory<T extends CreatableInstance = CreatableInstance> extends Creatable<T> {\n factory<T extends CreatableInstance>(\n this: Creatable<T>,\n params?: Partial<T['params']>,\n labels?: Labels): CreatableFactory<T>\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 */\n/** @deprecated use creatableV2 instead */\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/** @deprecated use creatableFactoryV2 instead */\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","import { assertEx } from '@xylabs/assert'\nimport type { BaseEmitterParamsV2, EventData } from '@xylabs/events'\nimport { BaseEmitterV2 } from '@xylabs/events'\nimport { type Logger } from '@xylabs/logger'\nimport type { Promisable } from '@xylabs/promise'\nimport type { SpanConfig } from '@xylabs/telemetry'\nimport { spanRoot, spanRootAsync } from '@xylabs/telemetry'\nimport {\n isError, isNumber, isString,\n isUndefined,\n} from '@xylabs/typeof'\nimport { Mutex } from 'async-mutex'\n\nimport type { CreatableFactoryV2, CreatableV2 } from './CreatableV2.ts'\nimport { FactoryV2 } from './FactoryV2.ts'\nimport { getFunctionName, getRootFunction } from './lib/index.ts'\nimport type {\n CreatableInstanceV2,\n CreatableName, CreatableParamsV2,\n CreatableStatusV2,\n Labels,\n} from './model/index.ts'\n\nconst AbstractCreatableConstructorKey = Symbol.for('AbstractCreatableConstructor')\nconst CREATABLE_NOT_STARTED = 'Creatable not Started' as const\n\nexport abstract class AbstractCreatableV2<TParams extends CreatableParamsV2 = CreatableParamsV2,\n TEventData extends EventData = EventData> extends BaseEmitterV2<TParams, TEventData> {\n defaultLogger?: Logger\n\n protected _startPromise: Promisable<boolean> | undefined\n private _status: CreatableStatusV2 | null = null\n private _statusMutex = new Mutex()\n private _validatedParams?: TParams & BaseEmitterParamsV2\n\n constructor(key: unknown, params: TParams) {\n assertEx(key === AbstractCreatableConstructorKey, () => 'AbstractCreatable should not be instantiated directly, use the static create method instead')\n super(params)\n }\n\n override get context(): TParams['context'] & BaseEmitterParamsV2['context'] {\n return this.params.context\n }\n\n get name(): CreatableName {\n return this.params.name as CreatableName\n }\n\n override get params(): TParams & BaseEmitterParamsV2 {\n this._validatedParams = this._validatedParams ?? this.paramsValidator(super.params)\n return assertEx(this._validatedParams)\n }\n\n get startable() {\n return this.status === 'created' || this.status === 'stopped'\n }\n\n get status(): CreatableStatusV2 | null {\n return this._status\n }\n\n get statusReporter() {\n return this.context.statusReporter\n }\n\n abstract override get className(): CreatableName\n\n static async create<T extends CreatableInstanceV2>(\n this: CreatableV2<T>,\n inParams: Partial<T['params']> = {},\n ): Promise<T> {\n const params = await this.paramsHandler(inParams)\n const name = (params.name ?? this.name) as CreatableName\n try {\n const instance = new this(AbstractCreatableConstructorKey, params)\n instance.setStatus('creating')\n const initializedInstance = await this.createHandler(instance)\n await instance.createHandler()\n instance.setStatus('created')\n return initializedInstance\n } catch (ex) {\n params.context.statusReporter?.report(name, 'error', isError(ex) ? ex : new Error(`Error creating: ${name}`))\n params.context.logger?.error(`Error creating creatable [${name}]: ${(isError(ex) ? `${ex.message} ${ex.stack}` : ex)}`)\n throw isError(ex) ? ex : new Error(`Error creating: ${name}`)\n }\n }\n\n static createHandler<T extends CreatableInstanceV2>(\n this: CreatableV2<T>,\n instance: T,\n ): Promisable<T> {\n return instance\n }\n\n static paramsHandler<T extends CreatableInstanceV2>(\n this: CreatableV2<T>,\n params: Partial<T['params']> = {},\n ): Promisable<T['params']> {\n return { ...params } as T['params']\n }\n\n createHandler(): Promisable<void> {\n assertEx(this._status === 'creating', () => `createHandler can not be called [status = ${this.status}]`)\n }\n\n paramsValidator(params: Partial<TParams>): TParams {\n return { ...params, name: params.name } as TParams\n }\n\n span<T>(name: string, fn: () => T): T {\n return spanRoot(name, fn, this.tracer)\n }\n\n async spanAsync<T>(name: string, fn: () => Promise<T>, config: SpanConfig = {}): Promise<T> {\n return await spanRootAsync(name, fn, {\n ...config, tracer: config.tracer ?? this.tracer, logger: config.logger ?? this.defaultLogger,\n })\n }\n\n async start(): Promise<boolean> {\n this._noOverride('start')\n if (this.status === 'started') {\n return true\n }\n return await this._statusMutex.runExclusive(async () => {\n try {\n // check again in case it changed\n if (this.status === 'started') {\n return true\n }\n assertEx(this.startable, () => `Creatable [${this.name}] is not startable in status [${this.status}]`)\n this.setStatus('starting')\n await this.startHandler()\n this.setStatus('started')\n return true\n } catch (ex) {\n this.setStatus('error', isError(ex) ? ex : new Error(`Error starting: ${ex}`))\n this.logger?.error(`Error starting creatable [${this.name}]: ${(isError(ex) ? `${ex.message} ${ex.stack}` : ex)}`)\n return false\n }\n })\n }\n\n started(notStartedAction: 'error' | 'throw' | 'warn' | 'log' | 'none' = 'log'): boolean {\n if (isString(this.status) && this.status === 'started') {\n return true\n } else {\n const message = () => `${CREATABLE_NOT_STARTED} [${this.name}] current state: ${this.status}`\n switch (notStartedAction) {\n case 'error': {\n throw new Error(message())\n }\n case 'throw': {\n throw new Error(message())\n }\n case 'warn': {\n this.logger?.warn(message())\n break\n }\n case 'log': {\n this.logger?.log(message())\n break\n }\n case 'none': {\n break\n }\n default: {\n throw new Error(`Unknown notStartedAction: ${notStartedAction}`)\n }\n }\n return false\n }\n }\n\n async startedAsync(notStartedAction: 'error' | 'throw' | 'warn' | 'log' | 'none' = 'log', tryStart = true): Promise<boolean> {\n if (isString(this.status) && this.status === 'started') {\n return true\n } else if (this.status === 'created' || this.status === 'stopped' || this.status === 'starting') {\n // using promise as mutex\n this._startPromise = this._startPromise ?? (async () => {\n if (tryStart) {\n try {\n return await this.start()\n } finally {\n this._startPromise = undefined\n }\n }\n return this.started(notStartedAction)\n })()\n } else {\n const message = `${CREATABLE_NOT_STARTED} [${this.name}] current state: ${this.status}`\n throw new Error(message)\n }\n\n if (isUndefined(this._startPromise)) {\n throw new Error(`Failed to create start promise: ${this.status}`)\n }\n return await this._startPromise\n }\n\n async stop(): Promise<boolean> {\n this._noOverride('stop')\n if (this.status === 'stopped') {\n return true\n }\n return await this._statusMutex.runExclusive(async () => {\n try {\n // check again in case it changed\n if (this.status === 'stopped') {\n return true\n }\n assertEx(this.status === 'started', () => `Creatable [${this.name}] is not stoppable in status [${this.status}]`)\n this.setStatus('stopping')\n await this.stopHandler()\n this.setStatus('stopped')\n return true\n } catch (ex) {\n this.setStatus('error', isError(ex) ? ex : new Error(`Error stopping: ${ex}`))\n return false\n }\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 setStatus(value: Exclude<CreatableStatusV2, 'error'>, progress?: number): void\n protected setStatus(value: Extract<CreatableStatusV2, 'error'>, error?: Error): void\n protected setStatus(value: CreatableStatusV2, progressOrError?: number | Error): void {\n this._status = value\n if (value !== null) {\n if (value === 'error') {\n if (isError(progressOrError)) {\n this.statusReporter?.report(this.name, value, progressOrError)\n return\n }\n } else {\n if (isNumber(progressOrError)) {\n this.statusReporter?.report(this.name, value, progressOrError)\n return\n }\n }\n this.statusReporter?.report(this.name, value)\n }\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\nexport abstract class AbstractCreatableWithFactoryV2<TParams extends CreatableParamsV2 = CreatableParamsV2,\n TEventData extends EventData = EventData> extends AbstractCreatableV2<TParams, TEventData> {\n static factory<T extends CreatableInstanceV2>(\n this: CreatableV2<T>,\n params?: Partial<T['params']>,\n labels?: Labels,\n ): CreatableFactoryV2<T> {\n return FactoryV2.withParams<T>(this, params, labels)\n }\n}\n","import type { CreatableFactoryV2, CreatableV2 } from './CreatableV2.ts'\nimport type {\n CreatableInstanceV2, Labels, WithOptionalLabels,\n} from './model/index.ts'\n\nexport class FactoryV2<T extends CreatableInstanceV2 = CreatableInstanceV2> implements CreatableFactoryV2<T> {\n creatable: CreatableV2<T>\n\n defaultParams?: Partial<T['params']>\n\n labels?: Labels\n\n constructor(\n creatable: CreatableV2<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 CreatableInstanceV2>(\n creatableModule: CreatableV2<T>,\n params?: Partial<T['params']>,\n labels: Labels = {},\n ) {\n return new FactoryV2<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 type { Logger } from '@xylabs/logger'\nimport type { Promisable } from '@xylabs/promise'\n\nimport type {\n CreatableInstanceV2, CreatableParamsV2, Labels,\n} from './model/index.ts'\n\nexport interface CreatableFactoryV2<T extends CreatableInstanceV2 = CreatableInstanceV2>\n extends Omit<CreatableV2<T>, 'create' | 'createHandler' | 'paramsHandler' | 'defaultLogger' | 'factory'> {\n\n create(\n this: CreatableFactoryV2<T>,\n params?: Partial<T['params']>): Promise<T>\n}\n\nexport interface CreatableV2<T extends CreatableInstanceV2 = CreatableInstanceV2> {\n\n defaultLogger?: Logger\n\n new(key: unknown, params: Partial<CreatableParamsV2>): T\n\n create<T extends CreatableInstanceV2>(\n this: CreatableV2<T>,\n params?: Partial<T['params']>): Promise<T>\n\n createHandler<T extends CreatableInstanceV2>(\n this: CreatableV2<T>,\n instance: T\n ): Promisable<T>\n\n paramsHandler<T extends CreatableInstanceV2>(\n this: CreatableV2<T>, params?: Partial<T['params']>): Promisable<T['params']>\n}\n\nexport interface CreatableWithFactoryV2<T extends CreatableInstanceV2 = CreatableInstanceV2> extends CreatableV2<T> {\n factory<T extends CreatableInstanceV2>(\n this: CreatableV2<T>,\n params?: Partial<T['params']>,\n labels?: Labels): CreatableFactoryV2<T>\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 creatableV2<T extends CreatableInstanceV2>() {\n return <U extends CreatableV2<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 creatableFactoryV2() {\n return <U extends CreatableFactoryV2>(constructor: U) => {\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n constructor\n }\n}\n","import { BaseContextZod } from '@xylabs/base'\nimport { BaseEmitterParamsV2Zod } from '@xylabs/events'\nimport z from 'zod'\n\nimport { CreatableStatusReporterV2Zod } from './CreatableStatusReporter.zod.ts'\n\nexport const CreatableContext = z.intersection(BaseContextZod, z.object({ name: z.string(), statusReporter: CreatableStatusReporterV2Zod.optional() }))\n\nexport const CreatableParamsV2Zod = BaseEmitterParamsV2Zod.extend(z.object({ context: CreatableContext, name: z.string() }).shape)\n\nexport type CreatableParamsV2 = z.infer<typeof CreatableParamsV2Zod>\n","import { z } from 'zod'\n\nexport const CreatableStatusSuccessZod = z.enum(['creating', 'created', 'starting', 'started', 'stopping', 'stopped'])\n\nexport const CreatableStatusErrorZod = z.enum(['error'])\n\nexport const CreatableStatusZod = z.union([CreatableStatusSuccessZod, CreatableStatusErrorZod])\n\nexport const CreatableStatusReporterV2Zod = z.object({\n report: z.union([\n z.function({\n input: z.union([\n z.tuple([\n z.string(),\n CreatableStatusSuccessZod,\n z.number().optional(),\n ]),\n z.tuple([\n z.string(),\n CreatableStatusErrorZod,\n z.instanceof(Error),\n ]),\n z.tuple([\n z.string(),\n CreatableStatusZod,\n ]),\n ]),\n output: z.void(),\n }),\n ]),\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;AAG5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EAAE,MAAM;AAAA,UACN,EAAE,OAAO;AAAA,UACT;AAAA,UACA,EAAE,WAAW,KAAK;AAAA,QACpB,CAAC;AAAA,QACD,EAAE,MAAM;AAAA,UACN,EAAE,OAAO;AAAA,UACT;AAAA,QACF,CAAC;AAAA,MACH,CAAC;AAAA,MACD,QAAQ,EAAE,KAAK;AAAA,IACjB,CAAC;AAAA,EACH,CAAC;AACH,CAAC;;;ADxBM,IAAM,mBAAmBC,GAAE,aAAa,gBAAgBA,GAAE,OAAO,EAAE,MAAMA,GAAE,OAAO,GAAG,gBAAgB,6BAA6B,SAAS,EAAE,CAAC,CAAC;AAE/I,IAAM,uBAAuB,uBAAuB,OAAOA,GAAE,OAAO,EAAE,SAAS,kBAAkB,MAAMA,GAAE,OAAO,EAAE,CAAC,EAAE,KAAK;;;AEmB1H,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":["isNumber","creatable","isNumber","assertEx","spanRoot","spanRootAsync","isError","isNumber","isString","isUndefined","Mutex","creatable","AbstractCreatableConstructorKey","CREATABLE_NOT_STARTED","Mutex","assertEx","isError","spanRoot","spanRootAsync","isString","isUndefined","isNumber","z","z"]}
1
+ {"version":3,"sources":["../../src/AbstractCreatable.ts","../../src/Creatable.ts","../../src/Factory.ts","../../src/lib/getFunctionName.ts","../../src/lib/getRootFunction.ts","../../src/AbstractCreatableV2.ts","../../src/FactoryV2.ts","../../src/CreatableV2.ts","../../src/model/CreatableParamsV2.ts","../../src/model/CreatableStatusReporter.zod.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 {\n SpanConfig, spanRoot, spanRootAsync,\n} from '@xylabs/telemetry'\nimport {\n isError, isNumber, isString,\n isUndefined,\n} from '@xylabs/typeof'\nimport { Mutex } from 'async-mutex'\n\nimport {\n type Creatable, creatable, CreatableFactory,\n} from './Creatable.ts'\nimport { Factory } from './Factory.ts'\nimport { getFunctionName, getRootFunction } from './lib/index.ts'\nimport { CreatableName } from './model/CreatableName.ts'\nimport type {\n CreatableInstance, CreatableParams,\n CreatableStatus,\n Labels,\n RequiredCreatableParams,\n} from './model/index.ts'\n\nconst AbstractCreatableConstructorKey = Symbol.for('AbstractCreatableConstructor')\nconst CREATABLE_NOT_STARTED = 'Creatable not Started' as const\n\n/** @deprecated use AbstractCreatableV2 instead */\n@creatable()\nexport class AbstractCreatable<TParams extends CreatableParams = CreatableParams,\n TEventData extends EventData = EventData> extends BaseEmitter<Partial<TParams & RequiredCreatableParams>, TEventData> {\n defaultLogger?: Logger\n\n protected _startPromise: Promisable<boolean> | undefined\n private _status: CreatableStatus | null = null\n private _statusMutex = new Mutex()\n private _validatedParams?: TParams & RequiredCreatableParams\n\n constructor(key: unknown, params: Partial<TParams & RequiredCreatableParams>) {\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 as CreatableName\n }\n\n override get params(): TParams & RequiredCreatableParams {\n this._validatedParams = this._validatedParams ?? this.paramsValidator(super.params)\n return this._validatedParams\n }\n\n get startable() {\n return this.status === 'created' || this.status === 'stopped'\n }\n\n get status(): CreatableStatus | null {\n return this._status\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 as CreatableName\n try {\n const instance = new this(AbstractCreatableConstructorKey, params)\n instance.setStatus('creating')\n const initializedInstance = await this.createHandler(instance)\n await instance.createHandler()\n instance.setStatus('created')\n return initializedInstance\n } catch (ex) {\n params.statusReporter?.report(name, 'error', isError(ex) ? ex : new Error(`Error creating: ${name}`))\n params.logger?.error(`Error creating creatable [${name}]: ${(isError(ex) ? `${ex.message} ${ex.stack}` : ex)}`)\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<T['params']> {\n return { ...params }\n }\n\n createHandler(): Promisable<void> {\n assertEx(this._status === 'creating', () => `createHandler can not be called [status = ${this.status}]`)\n }\n\n paramsValidator(params: Partial<TParams & RequiredCreatableParams>): TParams & RequiredCreatableParams {\n return { ...params, name: params.name } as TParams & RequiredCreatableParams\n }\n\n span<T>(name: string, fn: () => T): T {\n return spanRoot(name, fn, this.tracer)\n }\n\n async spanAsync<T>(name: string, fn: () => Promise<T>, config: SpanConfig = {}): Promise<T> {\n return await spanRootAsync(name, fn, {\n ...config, tracer: config.tracer ?? this.tracer, logger: config.logger ?? this.defaultLogger,\n })\n }\n\n async start(): Promise<boolean> {\n this._noOverride('start')\n if (this.status === 'started') {\n return true\n }\n return await this._statusMutex.runExclusive(async () => {\n try {\n // check again in case it changed\n if (this.status === 'started') {\n return true\n }\n assertEx(this.startable, () => `Creatable [${this.name}] is not startable in status [${this.status}]`)\n this.setStatus('starting')\n await this.startHandler()\n this.setStatus('started')\n return true\n } catch (ex) {\n this.setStatus('error', isError(ex) ? ex : new Error(`Error starting: ${ex}`))\n this.logger?.error(`Error starting creatable [${this.name}]: ${(isError(ex) ? `${ex.message} ${ex.stack}` : ex)}`)\n return false\n }\n })\n }\n\n started(notStartedAction: 'error' | 'throw' | 'warn' | 'log' | 'none' = 'log'): boolean {\n if (isString(this.status) && this.status === 'started') {\n return true\n } else {\n const message = () => `${CREATABLE_NOT_STARTED} [${this.name}] current state: ${this.status}`\n switch (notStartedAction) {\n case 'error': {\n throw new Error(message())\n }\n case 'throw': {\n throw new Error(message())\n }\n case 'warn': {\n this.logger?.warn(message())\n break\n }\n case 'log': {\n this.logger?.log(message())\n break\n }\n case 'none': {\n break\n }\n default: {\n throw new Error(`Unknown notStartedAction: ${notStartedAction}`)\n }\n }\n return false\n }\n }\n\n async startedAsync(notStartedAction: 'error' | 'throw' | 'warn' | 'log' | 'none' = 'log', tryStart = true): Promise<boolean> {\n if (isString(this.status) && this.status === 'started') {\n return true\n } else if (this.status === 'created' || this.status === 'stopped' || this.status === 'starting') {\n // using promise as mutex\n this._startPromise = this._startPromise ?? (async () => {\n if (tryStart) {\n try {\n return await this.start()\n } finally {\n this._startPromise = undefined\n }\n }\n return this.started(notStartedAction)\n })()\n } else {\n const message = `${CREATABLE_NOT_STARTED} [${this.name}] current state: ${this.status}`\n throw new Error(message)\n }\n\n if (isUndefined(this._startPromise)) {\n throw new Error(`Failed to create start promise: ${this.status}`)\n }\n return await this._startPromise\n }\n\n async stop(): Promise<boolean> {\n this._noOverride('stop')\n if (this.status === 'stopped') {\n return true\n }\n return await this._statusMutex.runExclusive(async () => {\n try {\n // check again in case it changed\n if (this.status === 'stopped') {\n return true\n }\n assertEx(this.status === 'started', () => `Creatable [${this.name}] is not stoppable in status [${this.status}]`)\n this.setStatus('stopping')\n await this.stopHandler()\n this.setStatus('stopped')\n return true\n } catch (ex) {\n this.setStatus('error', isError(ex) ? ex : new Error(`Error stopping: ${ex}`))\n return false\n }\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 setStatus(value: Exclude<CreatableStatus, 'error'>, progress?: number): void\n protected setStatus(value: Extract<CreatableStatus, 'error'>, error?: Error): void\n protected setStatus(value: CreatableStatus, progressOrError?: number | Error): void {\n this._status = value\n if (value !== null) {\n if (value === 'error') {\n if (isError(progressOrError)) {\n this.statusReporter?.report(this.name, value, progressOrError)\n return\n }\n } else {\n if (isNumber(progressOrError)) {\n this.statusReporter?.report(this.name, value, progressOrError)\n return\n }\n }\n this.statusReporter?.report(this.name, value)\n }\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\n@creatable()\nexport class AbstractCreatableWithFactory<TParams extends CreatableParams = CreatableParams,\n TEventData extends EventData = EventData> extends AbstractCreatable<TParams, TEventData> {\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","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 RequiredCreatableParams,\n} from './model/index.ts'\n\n/** @deprecated use CreatableFactoryV2 instead */\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\n/** @deprecated use CreatableV2 instead */\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<T['params'] & RequiredCreatableParams>\n}\n\n/** @deprecated use CreatableWithFactoryV2 instead */\nexport interface CreatableWithFactory<T extends CreatableInstance = CreatableInstance> extends Creatable<T> {\n factory<T extends CreatableInstance>(\n this: Creatable<T>,\n params?: Partial<T['params']>,\n labels?: Labels): CreatableFactory<T>\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 */\n/** @deprecated use creatableV2 instead */\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/** @deprecated use creatableFactoryV2 instead */\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","import { assertEx } from '@xylabs/assert'\nimport type { EventData } from '@xylabs/events'\nimport { BaseEmitterV2 } from '@xylabs/events'\nimport { type Logger } from '@xylabs/logger'\nimport type { Promisable } from '@xylabs/promise'\nimport type { SpanConfig } from '@xylabs/telemetry'\nimport { spanRoot, spanRootAsync } from '@xylabs/telemetry'\nimport {\n isError, isNumber, isString,\n isUndefined,\n} from '@xylabs/typeof'\nimport { Mutex } from 'async-mutex'\n\nimport type { CreatableFactoryV2, CreatableV2 } from './CreatableV2.ts'\nimport { FactoryV2 } from './FactoryV2.ts'\nimport { getFunctionName, getRootFunction } from './lib/index.ts'\nimport type {\n CreatableInstanceV2,\n CreatableName, CreatableParamsV2,\n CreatableStatusV2,\n Labels,\n} from './model/index.ts'\n\nconst AbstractCreatableConstructorKey = Symbol.for('AbstractCreatableConstructor')\nconst CREATABLE_NOT_STARTED = 'Creatable not Started' as const\n\nexport abstract class AbstractCreatableV2<TParams extends CreatableParamsV2 = CreatableParamsV2,\n TEventData extends EventData = EventData> extends BaseEmitterV2<TParams, TEventData> implements CreatableInstanceV2<TParams, TEventData> {\n defaultLogger?: Logger\n\n protected _startPromise: Promisable<boolean> | undefined\n private _status: CreatableStatusV2 | null = null\n private _statusMutex = new Mutex()\n private _validatedParams?: TParams\n\n constructor(key: unknown, params: TParams) {\n assertEx(key === AbstractCreatableConstructorKey, () => 'AbstractCreatable should not be instantiated directly, use the static create method instead')\n super(params)\n this.setStatus('creating')\n }\n\n override get context(): TParams['context'] {\n return this.params.context\n }\n\n get name(): CreatableName {\n return this.params.name as CreatableName\n }\n\n override get params(): TParams {\n this._validatedParams = this._validatedParams ?? this.paramsValidator(super.params)\n return assertEx(this._validatedParams)\n }\n\n get startable() {\n return this.status === 'created' || this.status === 'stopped'\n }\n\n get status(): CreatableStatusV2 | null {\n return this._status\n }\n\n get statusReporter() {\n return this.context.statusReporter\n }\n\n abstract override get className(): CreatableName\n\n static async create<T extends CreatableInstanceV2>(\n this: CreatableV2<T>,\n inParams: Partial<T['params']> = {},\n ): Promise<T> {\n const params = await this.paramsHandler(inParams)\n const name = (params.name ?? this.name) as CreatableName\n try {\n const instance = new this(AbstractCreatableConstructorKey, params)\n const initializedInstance = await this.createHandler(instance)\n await instance.createHandler()\n return initializedInstance\n } catch (ex) {\n params.context.statusReporter?.report(name, 'error', isError(ex) ? ex : new Error(`Error creating: ${name}`))\n params.context.logger?.error(`Error creating creatable [${name}]: ${(isError(ex) ? `${ex.message} ${ex.stack}` : ex)}`)\n throw isError(ex) ? ex : new Error(`Error creating: ${name}`)\n }\n }\n\n static createHandler<T extends CreatableInstanceV2>(\n this: CreatableV2<T>,\n instance: T,\n ): Promisable<T> {\n return instance\n }\n\n static paramsHandler<T extends CreatableInstanceV2>(\n this: CreatableV2<T>,\n params: Partial<T['params']> = {},\n ): Promisable<T['params']> {\n return { ...params } as T['params']\n }\n\n createHandler(): Promisable<void> {\n assertEx(this._status === 'creating', () => `createHandler can not be called [status = ${this.status}]`)\n this.setStatus('created')\n }\n\n paramsValidator(params: Partial<TParams>): TParams {\n return { ...params, name: params.name } as TParams\n }\n\n span<T>(name: string, fn: () => T): T {\n return spanRoot(name, fn, this.tracer)\n }\n\n async spanAsync<T>(name: string, fn: () => Promise<T>, config: SpanConfig = {}): Promise<T> {\n return await spanRootAsync(name, fn, {\n ...config, tracer: config.tracer ?? this.tracer, logger: config.logger ?? this.defaultLogger,\n })\n }\n\n async start(): Promise<boolean> {\n this._noOverride('start')\n if (this.status === 'started') {\n return true\n }\n return await this._statusMutex.runExclusive(async () => {\n try {\n // check again in case it changed\n if (this.status === 'started') {\n return true\n }\n assertEx(this.startable, () => `Creatable [${this.name}] is not startable in status [${this.status}]`)\n this.setStatus('starting')\n await this.startHandler()\n this.setStatus('started')\n return true\n } catch (ex) {\n this.setStatus('error', isError(ex) ? ex : new Error(`Error starting: ${ex}`))\n this.logger?.error(`Error starting creatable [${this.name}]: ${(isError(ex) ? `${ex.message} ${ex.stack}` : ex)}`)\n return false\n }\n })\n }\n\n started(notStartedAction: 'error' | 'throw' | 'warn' | 'log' | 'none' = 'log'): boolean {\n if (isString(this.status) && this.status === 'started') {\n return true\n } else {\n const message = () => `${CREATABLE_NOT_STARTED} [${this.name}] current state: ${this.status}`\n switch (notStartedAction) {\n case 'error': {\n throw new Error(message())\n }\n case 'throw': {\n throw new Error(message())\n }\n case 'warn': {\n this.logger?.warn(message())\n break\n }\n case 'log': {\n this.logger?.log(message())\n break\n }\n case 'none': {\n break\n }\n default: {\n throw new Error(`Unknown notStartedAction: ${notStartedAction}`)\n }\n }\n return false\n }\n }\n\n async startedAsync(notStartedAction: 'error' | 'throw' | 'warn' | 'log' | 'none' = 'log', tryStart = true): Promise<boolean> {\n if (isString(this.status) && this.status === 'started') {\n return true\n } else if (this.status === 'created' || this.status === 'stopped' || this.status === 'starting') {\n // using promise as mutex\n this._startPromise = this._startPromise ?? (async () => {\n if (tryStart) {\n try {\n return await this.start()\n } finally {\n this._startPromise = undefined\n }\n }\n return this.started(notStartedAction)\n })()\n } else {\n const message = `${CREATABLE_NOT_STARTED} [${this.name}] current state: ${this.status}`\n throw new Error(message)\n }\n\n if (isUndefined(this._startPromise)) {\n throw new Error(`Failed to create start promise: ${this.status}`)\n }\n return await this._startPromise\n }\n\n async stop(): Promise<boolean> {\n this._noOverride('stop')\n if (this.status === 'stopped') {\n return true\n }\n return await this._statusMutex.runExclusive(async () => {\n try {\n // check again in case it changed\n if (this.status === 'stopped') {\n return true\n }\n assertEx(this.status === 'started', () => `Creatable [${this.name}] is not stoppable in status [${this.status}]`)\n this.setStatus('stopping')\n await this.stopHandler()\n this.setStatus('stopped')\n return true\n } catch (ex) {\n this.setStatus('error', isError(ex) ? ex : new Error(`Error stopping: ${ex}`))\n return false\n }\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 setStatus(value: Exclude<CreatableStatusV2, 'error'>, progress?: number): void\n protected setStatus(value: Extract<CreatableStatusV2, 'error'>, error?: Error): void\n protected setStatus(value: CreatableStatusV2, progressOrError?: number | Error): void {\n this._status = value\n if (value !== null) {\n if (value === 'error') {\n if (isError(progressOrError)) {\n this.statusReporter?.report(this.name, value, progressOrError)\n return\n }\n } else {\n if (isNumber(progressOrError)) {\n this.statusReporter?.report(this.name, value, progressOrError)\n return\n }\n }\n this.statusReporter?.report(this.name, value)\n }\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\nexport abstract class AbstractCreatableWithFactoryV2<TParams extends CreatableParamsV2 = CreatableParamsV2,\n TEventData extends EventData = EventData> extends AbstractCreatableV2<TParams, TEventData> {\n static factory<T extends CreatableInstanceV2>(\n this: CreatableV2<T>,\n params?: Partial<T['params']>,\n labels?: Labels,\n ): CreatableFactoryV2<T> {\n return FactoryV2.withParams<T>(this, params, labels)\n }\n}\n","import type { CreatableFactoryV2, CreatableV2 } from './CreatableV2.ts'\nimport type {\n CreatableInstanceV2, Labels, WithOptionalLabels,\n} from './model/index.ts'\n\nexport class FactoryV2<T extends CreatableInstanceV2 = CreatableInstanceV2> implements CreatableFactoryV2<T> {\n creatable: CreatableV2<T>\n\n defaultParams?: Partial<T['params']>\n\n labels?: Labels\n\n constructor(\n creatable: CreatableV2<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 CreatableInstanceV2>(\n creatableModule: CreatableV2<T>,\n params?: Partial<T['params']>,\n labels: Labels = {},\n ) {\n return new FactoryV2<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 type { Logger } from '@xylabs/logger'\nimport type { Promisable } from '@xylabs/promise'\n\nimport type {\n CreatableInstanceV2, CreatableParamsV2, Labels,\n} from './model/index.ts'\n\nexport interface CreatableFactoryV2<T extends CreatableInstanceV2 = CreatableInstanceV2>\n extends Omit<CreatableV2<T>, 'create' | 'createHandler' | 'paramsHandler' | 'defaultLogger' | 'factory'> {\n\n create(\n this: CreatableFactoryV2<T>,\n params?: Partial<T['params']>): Promise<T>\n}\n\nexport interface CreatableV2<T extends CreatableInstanceV2 = CreatableInstanceV2> {\n\n defaultLogger?: Logger\n\n new(key: unknown, params: Partial<CreatableParamsV2>): T\n\n create<T extends CreatableInstanceV2>(\n this: CreatableV2<T>,\n params?: Partial<T['params']>): Promise<T>\n\n createHandler<T extends CreatableInstanceV2>(\n this: CreatableV2<T>,\n instance: T\n ): Promisable<T>\n\n paramsHandler<T extends CreatableInstanceV2>(\n this: CreatableV2<T>, params?: Partial<T['params']>): Promisable<T['params']>\n}\n\nexport interface CreatableWithFactoryV2<T extends CreatableInstanceV2 = CreatableInstanceV2> extends CreatableV2<T> {\n factory<T extends CreatableInstanceV2>(\n this: CreatableV2<T>,\n params?: Partial<T['params']>,\n labels?: Labels): CreatableFactoryV2<T>\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 creatableV2<T extends CreatableInstanceV2>() {\n return <U extends CreatableV2<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 creatableFactoryV2() {\n return <U extends CreatableFactoryV2>(constructor: U) => {\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n constructor\n }\n}\n","import { BaseContextZod } from '@xylabs/base'\nimport { BaseEmitterParamsV2Zod } from '@xylabs/events'\nimport z from 'zod'\n\nimport { CreatableStatusReporterV2Zod } from './CreatableStatusReporter.zod.ts'\n\nexport const CreatableContextZod = BaseContextZod.extend(z.object({ name: z.string(), statusReporter: CreatableStatusReporterV2Zod.optional() }).shape)\n\nexport const CreatableParamsV2Zod = BaseEmitterParamsV2Zod.extend(z.object({ context: CreatableContextZod, name: z.string() }).shape)\n\nexport type CreatableParamsV2 = z.infer<typeof CreatableParamsV2Zod>\n","import { z } from 'zod'\n\nexport const CreatableStatusSuccessZod = z.enum(['creating', 'created', 'starting', 'started', 'stopping', 'stopped'])\n\nexport const CreatableStatusErrorZod = z.enum(['error'])\n\nexport const CreatableStatusZod = z.union([CreatableStatusSuccessZod, CreatableStatusErrorZod])\n\nexport const CreatableStatusReporterV2Zod = z.object({\n report: z.union([\n z.function({\n input: z.union([\n z.tuple([\n z.string(),\n CreatableStatusSuccessZod,\n z.number().optional(),\n ]),\n z.tuple([\n z.string(),\n CreatableStatusErrorZod,\n z.instanceof(Error),\n ]),\n z.tuple([\n z.string(),\n CreatableStatusZod,\n ]),\n ]),\n output: z.void(),\n }),\n ]),\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;AAAA,EACc;AAAA,EAAU;AAAA,OACjB;AACP;AAAA,EACE;AAAA,EAAS,YAAAA;AAAA,EAAU;AAAA,EACnB;AAAA,OACK;AACP,SAAS,aAAa;;;ACyCf,SAAS,YAAyC;AACvD,SAAO,CAAyB,gBAAmB;AAEjD;AAAA,EACF;AACF;AAUO,SAAS,mBAAmB;AACjC,SAAO,CAA6B,gBAAmB;AAErD;AAAA,EACF;AACF;;;ACpEO,IAAM,UAAN,MAAM,SAAwF;AAAA,EACnG;AAAA,EAEA;AAAA,EAEA;AAAA,EAEA,YACEC,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,K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creatable","isNumber","assertEx","spanRoot","spanRootAsync","isError","isNumber","isString","isUndefined","Mutex","creatable","AbstractCreatableConstructorKey","CREATABLE_NOT_STARTED","Mutex","assertEx","isError","spanRoot","spanRootAsync","isString","isUndefined","isNumber","z","z"]}
@@ -7,7 +7,6 @@ export interface CreatableInstanceV2<TParams extends CreatableParamsV2 = Creatab
7
7
  eventData: TEventData;
8
8
  name: CreatableName;
9
9
  params: TParams;
10
- setStatus: (status: string) => void;
11
10
  start: () => Promise<boolean>;
12
11
  stop: () => Promise<boolean>;
13
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"CreatableInstanceV2.d.ts","sourceRoot":"","sources":["../../../src/model/CreatableInstanceV2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE/D,MAAM,WAAW,mBAAmB,CAAC,OAAO,SAAS,iBAAiB,GAAG,iBAAiB,EACxF,UAAU,SAAS,SAAS,GAAG,SAAS,CAAE,SAAQ,YAAY,CAAC,UAAU,CAAC;IAC1E,aAAa,EAAE,MAAM,UAAU,CAAC,IAAI,CAAC,CAAA;IACrC,SAAS,EAAE,UAAU,CAAA;IACrB,IAAI,EAAE,aAAa,CAAA;IACnB,MAAM,EAAE,OAAO,CAAA;IACf,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;IACnC,KAAK,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;IAC7B,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;CAC7B"}
1
+ {"version":3,"file":"CreatableInstanceV2.d.ts","sourceRoot":"","sources":["../../../src/model/CreatableInstanceV2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE/D,MAAM,WAAW,mBAAmB,CAAC,OAAO,SAAS,iBAAiB,GAAG,iBAAiB,EACxF,UAAU,SAAS,SAAS,GAAG,SAAS,CAAE,SAAQ,YAAY,CAAC,UAAU,CAAC;IAC1E,aAAa,EAAE,MAAM,UAAU,CAAC,IAAI,CAAC,CAAA;IACrC,SAAS,EAAE,UAAU,CAAA;IACrB,IAAI,EAAE,aAAa,CAAA;IACnB,MAAM,EAAE,OAAO,CAAA;IACf,KAAK,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;IAC7B,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;CAC7B"}
@@ -1,12 +1,11 @@
1
1
  import z from 'zod';
2
- export declare const CreatableContext: z.ZodIntersection<z.ZodObject<{
2
+ export declare const CreatableContextZod: z.ZodObject<{
3
3
  caches: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodCustom<import("@xylabs/base").MapType<string, unknown>, import("@xylabs/base").MapType<string, unknown>>>>;
4
4
  logger: z.ZodOptional<z.ZodCustom<import("@xylabs/logger").Logger, import("@xylabs/logger").Logger>>;
5
5
  meterProvider: z.ZodOptional<z.ZodCustom<import("@opentelemetry/api").MeterProvider, import("@opentelemetry/api").MeterProvider>>;
6
6
  singletons: z.ZodRecord<z.ZodString, z.ZodUnknown>;
7
7
  timeBudgetLimit: z.ZodOptional<z.ZodNumber>;
8
8
  traceProvider: z.ZodOptional<z.ZodCustom<import("@opentelemetry/api").TracerProvider, import("@opentelemetry/api").TracerProvider>>;
9
- }, z.z.core.$strip>, z.ZodObject<{
10
9
  name: z.ZodString;
11
10
  statusReporter: z.ZodOptional<z.ZodObject<{
12
11
  report: z.ZodUnion<readonly [z.ZodFunction<z.ZodUnion<readonly [z.ZodTuple<[z.ZodString, z.ZodEnum<{
@@ -29,16 +28,15 @@ export declare const CreatableContext: z.ZodIntersection<z.ZodObject<{
29
28
  error: "error";
30
29
  }>]>], null>]>, z.ZodVoid>]>;
31
30
  }, z.z.core.$strip>>;
32
- }, z.z.core.$strip>>;
31
+ }, z.z.core.$strip>;
33
32
  export declare const CreatableParamsV2Zod: z.ZodObject<{
34
- context: z.ZodIntersection<z.ZodObject<{
33
+ context: z.ZodObject<{
35
34
  caches: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodCustom<import("@xylabs/base").MapType<string, unknown>, import("@xylabs/base").MapType<string, unknown>>>>;
36
35
  logger: z.ZodOptional<z.ZodCustom<import("@xylabs/logger").Logger, import("@xylabs/logger").Logger>>;
37
36
  meterProvider: z.ZodOptional<z.ZodCustom<import("@opentelemetry/api").MeterProvider, import("@opentelemetry/api").MeterProvider>>;
38
37
  singletons: z.ZodRecord<z.ZodString, z.ZodUnknown>;
39
38
  timeBudgetLimit: z.ZodOptional<z.ZodNumber>;
40
39
  traceProvider: z.ZodOptional<z.ZodCustom<import("@opentelemetry/api").TracerProvider, import("@opentelemetry/api").TracerProvider>>;
41
- }, z.z.core.$strip>, z.ZodObject<{
42
40
  name: z.ZodString;
43
41
  statusReporter: z.ZodOptional<z.ZodObject<{
44
42
  report: z.ZodUnion<readonly [z.ZodFunction<z.ZodUnion<readonly [z.ZodTuple<[z.ZodString, z.ZodEnum<{
@@ -61,7 +59,7 @@ export declare const CreatableParamsV2Zod: z.ZodObject<{
61
59
  error: "error";
62
60
  }>]>], null>]>, z.ZodVoid>]>;
63
61
  }, z.z.core.$strip>>;
64
- }, z.z.core.$strip>>;
62
+ }, z.z.core.$strip>;
65
63
  name: z.ZodString;
66
64
  }, z.z.core.$strip>;
67
65
  export type CreatableParamsV2 = z.infer<typeof CreatableParamsV2Zod>;
@@ -1 +1 @@
1
- {"version":3,"file":"CreatableParamsV2.d.ts","sourceRoot":"","sources":["../../../src/model/CreatableParamsV2.ts"],"names":[],"mappings":"AAEA,OAAO,CAAC,MAAM,KAAK,CAAA;AAInB,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAA0H,CAAA;AAEvJ,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAAiG,CAAA;AAElI,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA"}
1
+ {"version":3,"file":"CreatableParamsV2.d.ts","sourceRoot":"","sources":["../../../src/model/CreatableParamsV2.ts"],"names":[],"mappings":"AAEA,OAAO,CAAC,MAAM,KAAK,CAAA;AAInB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAAuH,CAAA;AAEvJ,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAAoG,CAAA;AAErI,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/creatable",
3
- "version": "5.0.67",
3
+ "version": "5.0.70",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -38,13 +38,13 @@
38
38
  "!**/*.test.*"
39
39
  ],
40
40
  "dependencies": {
41
- "@xylabs/assert": "~5.0.67",
42
- "@xylabs/base": "~5.0.67",
43
- "@xylabs/events": "~5.0.67",
44
- "@xylabs/logger": "~5.0.67",
45
- "@xylabs/promise": "~5.0.67",
46
- "@xylabs/telemetry": "~5.0.67",
47
- "@xylabs/typeof": "~5.0.67",
41
+ "@xylabs/assert": "~5.0.70",
42
+ "@xylabs/base": "~5.0.70",
43
+ "@xylabs/events": "~5.0.70",
44
+ "@xylabs/logger": "~5.0.70",
45
+ "@xylabs/promise": "~5.0.70",
46
+ "@xylabs/telemetry": "~5.0.70",
47
+ "@xylabs/typeof": "~5.0.70",
48
48
  "async-mutex": "~0.5.0"
49
49
  },
50
50
  "devDependencies": {
@@ -1,5 +1,5 @@
1
1
  import { assertEx } from '@xylabs/assert'
2
- import type { BaseEmitterParamsV2, EventData } from '@xylabs/events'
2
+ import type { EventData } from '@xylabs/events'
3
3
  import { BaseEmitterV2 } from '@xylabs/events'
4
4
  import { type Logger } from '@xylabs/logger'
5
5
  import type { Promisable } from '@xylabs/promise'
@@ -25,20 +25,21 @@ const AbstractCreatableConstructorKey = Symbol.for('AbstractCreatableConstructor
25
25
  const CREATABLE_NOT_STARTED = 'Creatable not Started' as const
26
26
 
27
27
  export abstract class AbstractCreatableV2<TParams extends CreatableParamsV2 = CreatableParamsV2,
28
- TEventData extends EventData = EventData> extends BaseEmitterV2<TParams, TEventData> {
28
+ TEventData extends EventData = EventData> extends BaseEmitterV2<TParams, TEventData> implements CreatableInstanceV2<TParams, TEventData> {
29
29
  defaultLogger?: Logger
30
30
 
31
31
  protected _startPromise: Promisable<boolean> | undefined
32
32
  private _status: CreatableStatusV2 | null = null
33
33
  private _statusMutex = new Mutex()
34
- private _validatedParams?: TParams & BaseEmitterParamsV2
34
+ private _validatedParams?: TParams
35
35
 
36
36
  constructor(key: unknown, params: TParams) {
37
37
  assertEx(key === AbstractCreatableConstructorKey, () => 'AbstractCreatable should not be instantiated directly, use the static create method instead')
38
38
  super(params)
39
+ this.setStatus('creating')
39
40
  }
40
41
 
41
- override get context(): TParams['context'] & BaseEmitterParamsV2['context'] {
42
+ override get context(): TParams['context'] {
42
43
  return this.params.context
43
44
  }
44
45
 
@@ -46,7 +47,7 @@ export abstract class AbstractCreatableV2<TParams extends CreatableParamsV2 = Cr
46
47
  return this.params.name as CreatableName
47
48
  }
48
49
 
49
- override get params(): TParams & BaseEmitterParamsV2 {
50
+ override get params(): TParams {
50
51
  this._validatedParams = this._validatedParams ?? this.paramsValidator(super.params)
51
52
  return assertEx(this._validatedParams)
52
53
  }
@@ -73,10 +74,8 @@ export abstract class AbstractCreatableV2<TParams extends CreatableParamsV2 = Cr
73
74
  const name = (params.name ?? this.name) as CreatableName
74
75
  try {
75
76
  const instance = new this(AbstractCreatableConstructorKey, params)
76
- instance.setStatus('creating')
77
77
  const initializedInstance = await this.createHandler(instance)
78
78
  await instance.createHandler()
79
- instance.setStatus('created')
80
79
  return initializedInstance
81
80
  } catch (ex) {
82
81
  params.context.statusReporter?.report(name, 'error', isError(ex) ? ex : new Error(`Error creating: ${name}`))
@@ -101,6 +100,7 @@ export abstract class AbstractCreatableV2<TParams extends CreatableParamsV2 = Cr
101
100
 
102
101
  createHandler(): Promisable<void> {
103
102
  assertEx(this._status === 'creating', () => `createHandler can not be called [status = ${this.status}]`)
103
+ this.setStatus('created')
104
104
  }
105
105
 
106
106
  paramsValidator(params: Partial<TParams>): TParams {
@@ -10,7 +10,6 @@ export interface CreatableInstanceV2<TParams extends CreatableParamsV2 = Creatab
10
10
  eventData: TEventData
11
11
  name: CreatableName
12
12
  params: TParams
13
- setStatus: (status: string) => void
14
13
  start: () => Promise<boolean>
15
14
  stop: () => Promise<boolean>
16
15
  }
@@ -4,8 +4,8 @@ import z from 'zod'
4
4
 
5
5
  import { CreatableStatusReporterV2Zod } from './CreatableStatusReporter.zod.ts'
6
6
 
7
- export const CreatableContext = z.intersection(BaseContextZod, z.object({ name: z.string(), statusReporter: CreatableStatusReporterV2Zod.optional() }))
7
+ export const CreatableContextZod = BaseContextZod.extend(z.object({ name: z.string(), statusReporter: CreatableStatusReporterV2Zod.optional() }).shape)
8
8
 
9
- export const CreatableParamsV2Zod = BaseEmitterParamsV2Zod.extend(z.object({ context: CreatableContext, name: z.string() }).shape)
9
+ export const CreatableParamsV2Zod = BaseEmitterParamsV2Zod.extend(z.object({ context: CreatableContextZod, name: z.string() }).shape)
10
10
 
11
11
  export type CreatableParamsV2 = z.infer<typeof CreatableParamsV2Zod>