import AttributesForStrategy from "./strategies/attributes-for.js"; import BuildStrategy from "./strategies/build.js"; import CreateStrategy from "./strategies/create.js"; import FactoryEventEmitter from "./events.js"; import FactoryRunner from "./factory-runner.js"; /** * Owns all factories, traits, sequences, callbacks and construction defaults for * one isolated scope, and exposes the strategy entry points. Registry mutation is * setup-time only and is rejected while evaluations are active. */ export default class FactoryRegistry { /** @type {Map} - Factories and aliases. */ _factories: Map; /** @type {Map} - Global traits. */ _globalTraits: Map; /** @type {Map} - Global sequences and aliases. */ _sequences: Map; /** @type {Map>} - Factory-scoped sequences. */ _factorySequences: Map>; /** @type {import("./declarations.js").Declaration[]} - Registry-level default declarations. */ _globalDeclarations: import("./declarations.js").Declaration[]; /** @type {number} - In-flight evaluation count (mutation guard). */ _activeEvaluations: number; /** @type {FactoryRunner} - Plan compiler. */ _runner: FactoryRunner; /** @type {FactoryEventEmitter} - Debug/performance event emitter. */ _events: FactoryEventEmitter; /** @type {{attributesFor: AttributesForStrategy, build: BuildStrategy, create: CreateStrategy}} - Installed strategies. */ _strategies: { attributesFor: AttributesForStrategy; build: BuildStrategy; create: CreateStrategy; }; /** Builds an empty registry with the built-in strategies installed. */ constructor(); /** * Registers factories/traits/sequences/callbacks via a builder callback. * @param {(builder: object) => void} callback - The definition callback. * @returns {this} - This registry (for chaining). */ define(callback: (builder: object) => void): this; /** * Reopens existing factories to append/override declarations, recompiling each * into a fresh immutable definition. Rejected while evaluations are active. * @param {(builder: object) => void} callback - The modify callback. * @returns {this} - This registry (for chaining). */ modify(callback: (builder: object) => void): this; /** * Lints factories/traits, aggregating every failure. Create-strategy cases roll * back their database writes. * @param {object} [options] - Lint options (factories, traits, strategy). * @returns {Promise} - Resolves when all cases pass; rejects with an aggregate otherwise. */ lint(options?: object): Promise; /** * Subscribes to factory debug events (`start`, `success`, `failure`). * @param {string} event - Event name. * @param {(payload: {invocationId: string, factory: string, strategy: string, traits: string[], durationMs?: number, error?: ReturnType}) => void} handler - Event handler. * @returns {this} - This registry (for chaining). */ on(event: string, handler: (payload: { invocationId: string; factory: string; strategy: string; traits: string[]; durationMs?: number; error?: ReturnType; }) => void): this; /** * Unsubscribes a previously-registered event handler. * @param {string} event - Event name. * @param {(payload: ReturnType) => void} handler - Event handler to remove. * @returns {this} - This registry (for chaining). */ off(event: string, handler: (payload: ReturnType) => void): this; /** * Resolves attributes without constructing a model or building associations. * @param {string} factoryName - Factory name. * @param {Array>} args - Trait names then an optional overrides object. * @returns {Promise>>} - The resolved attributes. */ attributesFor(factoryName: string, ...args: Array>): Promise>>; /** * Builds an unsaved record graph. * @param {string} factoryName - Factory name. * @param {Array>} args - Trait names then an optional overrides object. * @returns {Promise>} - The built record. */ build(factoryName: string, ...args: Array>): Promise>; /** * Builds and persists a record graph. * @param {string} factoryName - Factory name. * @param {Array>} args - Trait names then an optional overrides object. * @returns {Promise>} - The persisted record. */ create(factoryName: string, ...args: Array>): Promise>; /** * Resolves attributes for a list of records sequentially. * @param {string} factoryName - Factory name. * @param {number} count - Number of entries. * @param {Array>} args - Trait names then an optional overrides object. * @returns {Promise>>>} - The resolved attribute objects. */ attributesForList(factoryName: string, count: number, ...args: Array>): Promise>>>; /** * Builds a list of unsaved records sequentially. * @param {string} factoryName - Factory name. * @param {number} count - Number of records. * @param {Array>} args - Trait names then an optional overrides object. * @returns {Promise>>} - The built records. */ buildList(factoryName: string, count: number, ...args: Array>): Promise>>; /** * Creates a list of persisted records sequentially. * @param {string} factoryName - Factory name. * @param {number} count - Number of records. * @param {Array>} args - Trait names then an optional overrides object. * @returns {Promise>>} - The persisted records. */ createList(factoryName: string, count: number, ...args: Array>): Promise>>; /** * Resolves attributes for exactly two records. * @param {string} factoryName - Factory name. * @param {Array>} args - Trait names then an optional overrides object. * @returns {Promise>>>} - The two resolved attribute objects. */ attributesForPair(factoryName: string, ...args: Array>): Promise>>>; /** * Builds exactly two unsaved records. * @param {string} factoryName - Factory name. * @param {Array>} args - Trait names then an optional overrides object. * @returns {Promise>>} - The two built records. */ buildPair(factoryName: string, ...args: Array>): Promise>>; /** * Creates exactly two persisted records. * @param {string} factoryName - Factory name. * @param {Array>} args - Trait names then an optional overrides object. * @returns {Promise>>} - The two persisted records. */ createPair(factoryName: string, ...args: Array>): Promise>>; /** * Advances a sequence and returns its formatted value. * @param {string} sequenceName - Sequence name. * @returns {Promise>} - The formatted value. */ generate(sequenceName: string): Promise>; /** * Advances a sequence `count` times and returns the formatted values. * @param {string} sequenceName - Sequence name. * @param {number} count - Number of values. * @returns {Promise>>} - The formatted values. */ generateList(sequenceName: string, count: number): Promise>>; /** * Returns the next raw value a global sequence would allocate without consuming it. * @param {string} sequenceName - Sequence name. * @returns {number} - The upcoming raw value. */ peekSequence(sequenceName: string): number; /** * Sets the next value a global sequence will allocate. * @param {string} sequenceName - Sequence name. * @param {number} value - Next raw value. * @returns {void} */ setSequence(sequenceName: string, value: number): void; /** * Rewinds a single global sequence to its initial value. * @param {string} sequenceName - Sequence name. * @returns {void} */ rewindSequence(sequenceName: string): void; /** * Rewinds every global and factory-scoped sequence to its initial value while * leaving all definitions intact. * @returns {void} */ rewindSequences(): void; /** * Clears all definitions, traits, sequences and registry defaults, restoring an * empty registry with the built-in strategies. * @returns {void} */ reset(): void; /** * Runs `count` sequential strategy invocations. * @param {"attributesFor" | "build" | "create"} strategy - Strategy name. * @param {string} factoryName - Factory name. * @param {number} count - Number of entries. * @param {Array>} args - Trait names then an optional overrides object. * @returns {Promise>>} - The results. */ _runList(strategy: "attributesFor" | "build" | "create", factoryName: string, count: number, args: Array>): Promise>>; /** * Compiles and runs a factory invocation under a strategy. * @param {object} args - Options. * @param {string} args.factoryName - Factory name. * @param {string[]} args.traits - Ordered traits. * @param {Record>} args.overrides - Overrides. * @param {"attributesFor" | "build" | "create"} args.strategy - Strategy name. * @returns {Promise>} - The strategy result. */ _runFactory(args: { factoryName: string; traits: string[]; overrides: Record>; strategy: "attributesFor" | "build" | "create"; }): Promise>; /** * Runs one event-tracked invocation, optionally reusing declaration planning. * @param {object} args - Options. * @param {string} args.factoryName - Factory name. * @param {string[]} args.traits - Ordered traits. * @param {Record>} args.overrides - Overrides. * @param {"attributesFor" | "build" | "create"} args.strategy - Strategy name. * @param {import("./factory-runner.js").CompiledPlan} [args.planTemplate] - Reusable declaration plan. * @returns {Promise<{result: ReturnType, planTemplate: import("./factory-runner.js").CompiledPlan}>} - Result and declaration plan. */ _runFactoryInvocation({ factoryName, traits, overrides, strategy, planTemplate }: { factoryName: string; traits: string[]; overrides: Record>; strategy: "attributesFor" | "build" | "create"; planTemplate?: import("./factory-runner.js").CompiledPlan; }): Promise<{ result: ReturnType; planTemplate: import("./factory-runner.js").CompiledPlan; }>; /** * Registers an immutable factory definition and its aliases. * @param {import("./factory-definition.js").default} definition - Compiled factory. * @returns {void} */ _registerFactoryDefinition(definition: import("./factory-definition.js").default): void; /** * Replaces an existing factory definition (and its aliases) with a recompiled * one. Used by `modify`; no duplicate check because it intentionally overwrites. * @param {import("./factory-definition.js").default} definition - Recompiled factory. * @returns {void} */ _replaceFactoryDefinition(definition: import("./factory-definition.js").default): void; /** * Registers a global trait. * @param {import("./trait-definition.js").default} trait - Compiled trait. * @returns {void} */ _registerGlobalTrait(trait: import("./trait-definition.js").default): void; /** * Registers a sequence (and its aliases) either globally or under a factory scope. * @param {import("./sequence.js").default} sequence - Sequence instance. * @param {string | null} factoryScope - Factory name to scope under, or null for global. * @returns {void} */ _registerSequence(sequence: import("./sequence.js").default, factoryScope: string | null): void; /** * Appends a registry-level default declaration (callbacks/construction defaults). * @param {import("./declarations.js").Declaration} declaration - Declaration to add. * @returns {void} */ _addGlobalDeclaration(declaration: import("./declarations.js").Declaration): void; /** * Resolves a sequence name against a factory scope chain (child first) then the * global scope and advances it. * @param {string} sequenceName - Sequence name. * @param {string[]} chainNames - Inheritance chain names (child last). * @returns {Promise>} - The formatted value. */ _generateScoped(sequenceName: string, chainNames: string[]): Promise>; /** * Resolves a global sequence by name. * @param {string} sequenceName - Sequence name. * @returns {import("./sequence.js").default} - The sequence. */ _resolveGlobalSequence(sequenceName: string): import("./sequence.js").default; /** * Rejects setup-time mutation while evaluations are active. * @param {string} operation - Operation name, for the error message. * @returns {void} */ _assertNotEvaluating(operation: string): void; } //# sourceMappingURL=factory-registry.d.ts.map