joist-core 2.4.0-next.42 → 2.4.0-next.44
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/build/config.cjs +6 -4
- package/build/config.cjs.map +1 -1
- package/build/config.d.cts +2 -2
- package/build/config.d.cts.map +1 -1
- package/build/config.d.mts +2 -2
- package/build/config.d.mts.map +1 -1
- package/build/config.js +6 -4
- package/build/config.js.map +1 -1
- package/build/logging/FactoryLogger.cjs +1 -1
- package/build/logging/FactoryLogger.cjs.map +1 -1
- package/build/logging/FactoryLogger.js +2 -2
- package/build/logging/FactoryLogger.js.map +1 -1
- package/package.json +3 -3
package/build/config.cjs
CHANGED
|
@@ -293,8 +293,8 @@ function getCallerName(extraFrames = 0) {
|
|
|
293
293
|
const parts = getStack().stack.split("\n").filter((line) => line.includes(" at "))[3 + extraFrames].split("/");
|
|
294
294
|
return parts[parts.length - 1].replace(/:\d+\)?$/, "");
|
|
295
295
|
}
|
|
296
|
-
function getFuzzyCallerName() {
|
|
297
|
-
return getFilePath(findUserCodeLine(getStack().stack.split("\n").filter((line) => line.includes(" at "))));
|
|
296
|
+
function getFuzzyCallerName(ignoreFactoryFrames = false) {
|
|
297
|
+
return getFilePath(findUserCodeLine(getStack().stack.split("\n").filter((line) => line.includes(" at ")), ignoreFactoryFrames));
|
|
298
298
|
}
|
|
299
299
|
/**
|
|
300
300
|
* Given a callstack line return the file name.
|
|
@@ -306,7 +306,7 @@ function getFilePath(line) {
|
|
|
306
306
|
return parts[parts.length - 1].replace(/:\d+\)?$/, "");
|
|
307
307
|
}
|
|
308
308
|
/** Given a callstack, uses heuristics to find the first line that looks like user code. */
|
|
309
|
-
function findUserCodeLine(lines) {
|
|
309
|
+
function findUserCodeLine(lines, ignoreFactoryFrames = false) {
|
|
310
310
|
return lines.find((line) => {
|
|
311
311
|
const withinWorkingCopyJoist = line.includes("/packages/orm/") || line.includes("/packages/core");
|
|
312
312
|
const withinProductionJoist = !withinWorkingCopyJoist && (line.includes("/joist-orm/src/") || line.includes("/joist-core/src"));
|
|
@@ -314,7 +314,9 @@ function findUserCodeLine(lines) {
|
|
|
314
314
|
const isUserCode = !withinWorkingCopyJoist && !withinProductionJoist && !nodeInternals;
|
|
315
315
|
const isDefault = line.includes("/defaults.ts");
|
|
316
316
|
const isDataloader = line.includes("/dataloaders/");
|
|
317
|
-
|
|
317
|
+
const isJestInternal = line.includes("jestAdapterInit.js");
|
|
318
|
+
const isFactoryHelper = line.includes("/factories/");
|
|
319
|
+
return (isDefault || isDataloader || isUserCode) && !line.includes("Codegen.ts") && !isJestInternal && !(ignoreFactoryFrames && isFactoryHelper) && !line.includes("at Array") && !line.includes("at new ");
|
|
318
320
|
}) ?? require_utils.fail("Could not find caller name");
|
|
319
321
|
}
|
|
320
322
|
const getStack = "captureStackTrace" in Error ? getStackFromCapture : getStackFromObject;
|
package/build/config.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.cjs","names":["getMetadata","convertToLoadHint","toTransition","AsyncDefault","fail"],"sources":["../src/config.ts"],"sourcesContent":["import { resetConstructorMap } from \"src/configure.ts\";\nimport { AsyncDefault } from \"src/defaults.ts\";\nimport { type Entity } from \"src/Entity.ts\";\nimport { assertHintUnchanged } from \"src/flush/ReadDrift.ts\";\nimport {\n type EntityConstructor,\n type EntityField,\n type EntityMetadata,\n type FieldsOf,\n type LoadHint,\n type Loaded,\n type MaybeAbstractEntityConstructor,\n type Reacted,\n type ReactiveHint,\n type RelationsIn,\n type SettableFields,\n fail,\n getMetadata,\n} from \"src/index.ts\";\nimport { convertToLoadHint } from \"src/reactivity/reactiveHints.ts\";\nimport { type ValidationRule, type ValidationRuleInternal, type ValidationRuleResult } from \"src/rules.ts\";\nimport {\n type FieldTransitionsConfig,\n type GuardTransitionMatch,\n type OnTransitionMatch,\n type Transition,\n type TransitionTable,\n toTransition,\n} from \"src/transitions.ts\";\nimport { type MaybePromise } from \"src/utils.ts\";\n\nexport type EntityHook =\n | \"beforeFlush\"\n | \"beforeCreate\"\n | \"beforeUpdate\"\n | \"beforeDelete\"\n | \"afterValidation\"\n | \"beforeCommit\"\n | \"afterCommit\";\ntype HookFn<T extends Entity, C> = (entity: T, ctx: C) => MaybePromise<unknown>;\n\ntype AssertUnchangedOpts = {\n /** Protect reached rows at flush; does not protect collection membership or predicates. */\n assertUnchanged?: boolean;\n};\ntype AddReactionOpts = AssertUnchangedOpts & { runOnce?: boolean; name?: string };\n\n/** An `addTransitionRule` rule, which also gets the transition it is checking, since the entity may have moved on. */\nexport type TransitionGuardFn<T extends Entity, V> = (\n entity: T,\n transition: Transition<V>,\n) => MaybePromise<ValidationRuleResult>;\n\n/** An `addTransitionReaction` function, which also gets the transition it is handling, since the entity may have moved on. */\ntype TransitionFn<T extends Entity, C, V> = (entity: T, ctx: C, transition: Transition<V>) => MaybePromise<unknown>;\n\n/** The enum type of a transition field, i.e. `PublisherStatus`. */\ntype TransitionType<T extends Entity, K extends keyof FieldsOf<T>> = FieldsOf<T>[K] extends EntityField\n ? NonNullable<FieldsOf<T>[K][\"type\"]>\n : never;\n\n/**\n * The state names that `transitions` tables and `match`es accept for an enum field, i.e. `\"Draft\"` for\n * `PublisherStatus.Draft`.\n *\n * We only accept the enum's accessors, not its codes or members, so every table reads the same way.\n */\ntype TransitionStates<T extends Entity, K extends keyof FieldsOf<T>> = FieldsOf<T>[K] extends {\n accessors: infer A extends string;\n}\n ? A\n : never;\n\nexport const constraintNameToValidationError: Record<string, string> = {};\n\ntype Settable<T extends Entity> = keyof SettableFields<FieldsOf<T>> & string;\n\nlet booted = false;\nlet afterMetadataLocked = false;\n\n/**\n * Called at the end of `configureMetadata` to indicate the boot process is complete.\n *\n * We use this flag to prevent users from mistakenly calling `config` methods after the boot\n * process is complete, i.e. from hooks or other post-boot invocations, where the calls are\n * not guaranteed to work because Joist's reactivity graph has already been initialized.\n */\nexport function setBooted(): void {\n booted = true;\n}\n\nexport function setAfterMetadataLocked(): void {\n afterMetadataLocked = true;\n}\n\n/** The public API to configure an Entity's hooks & validation rules. */\nexport class ConfigApi<T extends Entity, C> {\n __data = new ConfigData<T, C>();\n\n /**\n * Maps a given `constraintName`, i.e. `authors_publisher_id_unique_index`, to a hard-coded-but-pretty validation errors.\n *\n * Note that the validationError must be hard-coded b/c we cannot tease out \"which entity\" caused a given\n * constraint failure from the SQL database. If you really need pretty-and-custom validation errors, you'll\n * need to check the constraint by hand ahead of time, before calling `em.flush`.\n */\n addConstraintMessage(constraintName: string, validationError: string) {\n this.ensurePreBoot(getCallerName(), \"addConstraintMessage\");\n constraintNameToValidationError[constraintName] = validationError;\n }\n\n /**\n * Maps a `RecursiveCycleError` on the given recursive collection field to a custom validation error.\n *\n * When a cycle is detected in a recursive collection (e.g. `parentsRecursive`), instead of\n * throwing a raw `RecursiveCycleError`, `em.flush` will convert it into a `ValidationErrors`\n * using the provided message function.\n *\n * The `messageFn` receives the entity that detected the cycle and the cycle path (array of\n * entities forming the cycle), and should return a validation error string.\n */\n addCycleRule(fieldName: string & keyof T, messageFn: (entity: T, cyclePath: Entity[]) => string) {\n this.ensurePreBoot(getCallerName(), \"addCycleRule\");\n this.__data.cycleMessages[fieldName] = messageFn;\n // Register a reactive rule that loads the recursive collection and catches cycle errors.\n // The rule uses the recursive collection's underlying relation as a reactive hint so it\n // triggers when the collection changes.\n const hint = fieldName as any;\n const fn = () => {\n // We don't actually need a try/catch/anything here, b/c if there is a cycle, it\n // will cause a CycleError during followReverseHint, and never even get to calling this fn.\n };\n this.__data.rules.push({ name: `addCycleRule(${getCallerName()})`, fn, hint });\n }\n\n /**\n * Adds a validation rule for this entity.\n *\n * If `hint` is passed, then the rule's lambda will be: 1) passed a view of the entity with only\n * the fields included in `hint` marked as accessible, and 2) the rule will be called reactively any\n * time any field in the `hint` changes.\n *\n * If lambdas want to access fields w/o having them marked for reactivity, the rule can either\n * include the field as readonly with a `:ro` suffix, i.e. `firstName:ro`, or the lambda can\n * access the `reacted.entity` property to get a full view of the entity's fields and methods.\n */\n addRule<H extends ReactiveHint<T>>(hint: H, rule: ValidationRule<Reacted<T, H>>): void;\n addRule<H extends ReactiveHint<T>>(opts: AssertUnchangedOpts, hint: H, rule: ValidationRule<Reacted<T, H>>): void;\n addRule(rule: ValidationRule<T>): void;\n addRule(\n ruleOrHint: ValidationRule<T> | any,\n hintOrRule?: ReactiveHint<T> | ValidationRule<any>,\n maybeRule?: ValidationRule<any>,\n ): void {\n // Keep the name for easy debugging/tracing later\n const name = `addRule(${getCallerName()})`;\n this.ensurePreBoot(name, \"addRule\");\n pushValidationRule(\n this.__data.rules,\n name,\n maybeRule ? hintOrRule : ruleOrHint,\n maybeRule ?? (hintOrRule as ValidationRule<any> | undefined),\n maybeRule ? ruleOrHint : {},\n );\n }\n\n /**\n * Adds a \"commit rule\" that runs like a regular validation rule (see {@link addRule}), but *after*\n * the entity's `INSERT`/`UPDATE`/`DELETE` has been flushed to the database and *before* the\n * transaction `COMMIT`s, i.e. still within the transaction.\n *\n * The point of running this late is that any `em.find`s the rule makes will query the _changed_\n * state (the just-flushed rows), instead of the pre-flush state that regular `addRule` rules see.\n * This is useful for cross-row invariants that are easiest to express as a query, e.g. \"at most\n * one active `AuthorSchedule` per author\", where the rule wants to `em.find` the sibling rows\n * that were themselves just inserted/updated in this same flush.\n *\n * Like `addRule`, if a `hint` is passed the rule is reactive: it runs whenever any field in the\n * hint changes (walking back to the owning entity), and the lambda gets a `Reacted` view.\n */\n addCommitRule<H extends ReactiveHint<T>>(hint: H, rule: ValidationRule<Reacted<T, H>>): void;\n addCommitRule<H extends ReactiveHint<T>>(\n opts: AssertUnchangedOpts,\n hint: H,\n rule: ValidationRule<Reacted<T, H>>,\n ): void;\n addCommitRule(rule: ValidationRule<T>): void;\n addCommitRule(\n ruleOrHint: ValidationRule<T> | any,\n hintOrRule?: ReactiveHint<T> | ValidationRule<any>,\n maybeRule?: ValidationRule<any>,\n ): void {\n // Keep the name for easy debugging/tracing later\n const name = `addCommitRule(${getCallerName()})`;\n this.ensurePreBoot(name, \"addCommitRule\");\n pushValidationRule(\n this.__data.commitRules,\n name,\n maybeRule ? hintOrRule : ruleOrHint,\n maybeRule ?? (hintOrRule as ValidationRule<any> | undefined),\n maybeRule ? ruleOrHint : {},\n );\n }\n\n /** If both this entity, and `cstr` entities, are in the same `em.flush`, run us first. */\n runHooksBefore(cstr: EntityConstructor<any>): void {\n this.__data.runHooksBefore.push(cstr);\n }\n\n /** Deletes any entity/entities pointed to by `relation` when this entity is deleted. */\n cascadeDelete(relation: keyof RelationsIn<T> & LoadHint<T>): void {\n this.ensurePreBoot(getCallerName(), \"cascadeDelete\");\n this.__data.cascadeDeleteFields.push(relation);\n }\n\n touchOnChange(relation: keyof RelationsIn<T>): void {\n this.ensurePreBoot(getCallerName(), \"touchOnChange\");\n this.__data.touchOnChange.add(relation);\n }\n\n private addHook(hook: EntityHook, ruleOrHint: HookFn<T, C> | any, maybeFn?: HookFn<Loaded<T, any>, C>) {\n this.ensurePreBoot(getCallerName(), \"addHook\");\n if (typeof ruleOrHint === \"function\") {\n this.__data.hooks[hook].push(ruleOrHint);\n } else {\n const fn = async (entity: T, ctx: C) => {\n // TODO Use this for reactive beforeFlush\n const loaded = await entity.em.populate(entity, ruleOrHint);\n return maybeFn!(loaded, ctx);\n };\n // Squirrel our hint away where configureMetadata can find it\n (fn as any).hint = ruleOrHint;\n this.__data.hooks[hook].push(fn);\n }\n }\n\n afterMetadata(fn: AfterMetadataCallback<T>): void {\n if (afterMetadataLocked) {\n throw new Error(\n `config.afterMetadata on ${getCallerName()} must only be called on boot, before calling \\`configureMetadata\\` and not from other \\`afterMetadata\\` hooks.`,\n );\n }\n this.__data.afterMetadataCallbacks.push(fn);\n }\n\n beforeDelete<H extends LoadHint<T>>(populate: H, fn: HookFn<Loaded<T, H>, C>): void;\n beforeDelete(fn: HookFn<T, C>): void;\n beforeDelete(ruleOrHint: HookFn<T, C> | any, maybeFn?: HookFn<Loaded<T, any>, C>): void {\n this.addHook(\"beforeDelete\", ruleOrHint, maybeFn);\n }\n\n beforeFlush<H extends LoadHint<T>>(populate: H, fn: HookFn<Loaded<T, H>, C>): void;\n beforeFlush(fn: HookFn<T, C>): void;\n beforeFlush(ruleOrHint: HookFn<T, C> | any, maybeFn?: HookFn<Loaded<T, any>, C>): void {\n this.addHook(\"beforeFlush\", ruleOrHint, maybeFn);\n }\n\n // beforeCreate still needs to take a hint because even though the entity itself is New<T>, we might want to load\n // a nested relation that isn't loaded yet\n beforeCreate<H extends LoadHint<T>>(populate: H, fn: HookFn<Loaded<T, H>, C>): void;\n beforeCreate(fn: HookFn<T, C>): void;\n beforeCreate(ruleOrHint: HookFn<T, C> | any, maybeFn?: HookFn<Loaded<T, any>, C>): void {\n this.addHook(\"beforeCreate\", ruleOrHint, maybeFn);\n }\n\n beforeUpdate<H extends LoadHint<T>>(populate: H, fn: HookFn<Loaded<T, H>, C>): void;\n beforeUpdate(fn: HookFn<T, C>): void;\n beforeUpdate(ruleOrHint: HookFn<T, C> | any, maybeFn?: HookFn<Loaded<T, any>, C>): void {\n this.addHook(\"beforeUpdate\", ruleOrHint, maybeFn);\n }\n\n afterValidation<H extends LoadHint<T>>(populate: H, fn: HookFn<Loaded<T, H>, C>): void;\n afterValidation(fn: HookFn<T, C>): void;\n afterValidation(ruleOrHint: HookFn<T, C> | any, maybeFn?: HookFn<Loaded<T, any>, C>): void {\n this.addHook(\"afterValidation\", ruleOrHint, maybeFn);\n }\n\n beforeCommit(fn: HookFn<T, C>): void {\n this.addHook(\"beforeCommit\", fn);\n }\n\n afterCommit(fn: HookFn<T, C>): void {\n this.addHook(\"afterCommit\", fn);\n }\n\n /**\n * Adds a reaction that runs during flush whenever fields in the `hint` change.\n *\n * Reactions are somewhere in between hooks and reactive fields/references:\n * 1. Can make arbitrary changes to any entity like a hook\n * 2. Only run when the provided hint has changes, not on every flush, like an RF/RR\n * 3. Run when the entity itself has no changes, like an RF/RF\n * 4. Can run multiple times per flush, like an RF/RF. Be careful to avoid creating\n * circular dependencies in the hint and to make the function idempotent.\n *\n * Names default to the registration's source location. Pass unique names when registering multiple\n * reactions from a shared helper or loop; duplicate names on the same config are rejected.\n *\n * @param hint The fields to watch for changes and load before running the reaction\n * @param fn The reaction function to run\n */\n addReaction<H extends ReactiveHint<T>>(hint: H, fn: HookFn<Loaded<T, H>, C>): void;\n /**\n * Adds a named reaction that runs during flush whenever fields in the `hint` change.\n *\n * Reactions are somewhere in between hooks and reactive fields/references:\n * 1. Can make arbitrary changes to any entity like a hook\n * 2. Only run when `hint` has changes, not on every flush, like an RF/RR\n * 3. Can run when the entity itself has no changes, like an RF/RF\n * 4. Can run multiple times per flush, like an RF/RF. Be careful to avoid creating\n * circular dependencies in the hint and to make the function idempotent.\n *\n * @param name A name to identify this reaction for debugging\n * @param hint The fields to watch for changes and load before running the reaction\n * @param fn The reaction function to run\n */\n addReaction<H extends ReactiveHint<T>>(name: string, hint: H, fn: HookFn<Loaded<T, H>, C>): void;\n /**\n * Adds a reaction that runs during flush whenever fields in the `hint` change.\n *\n * Reactions are somewhere in between hooks and reactive fields/references:\n * 1. Can make arbitrary changes to any entity like a hook\n * 2. Only run when `hint` has changes, not on every flush, like an RF/RR\n * 3. Can run when the entity itself has no changes, like an RF/RF\n * 4. Can run multiple times per flush, like an RF/RF. Be careful to avoid creating\n * circular dependencies in the hint and to make the function idempotent.\n *\n * @param opts Options object containing:\n * - runOnce - If true, the reaction will only run once per flush, not every time the hint changes. Optional.\n * default: false.\n * - name - A name to identify this reaction for debugging\n * @param hint The fields to watch for changes and load before running the reaction\n * @param fn The reaction function to run\n */\n addReaction<H extends ReactiveHint<T>>(opts: AddReactionOpts, hint: H, fn: HookFn<Loaded<T, H>, C>): void;\n addReaction<H extends ReactiveHint<T>>(\n nameOrOptsOrHint: string | AddReactionOpts | H,\n hintOrFn: H | HookFn<Loaded<T, H>, C>,\n maybeFn?: HookFn<Loaded<T, H>, C>,\n ): void {\n // Keep the name so we can uniquely identify this reaction later and also aid debugging/tracing\n const fn = maybeFn ?? (hintOrFn as HookFn<Loaded<T, H>, C>);\n const hint = (maybeFn ? hintOrFn : nameOrOptsOrHint) as H;\n const opts = maybeFn\n ? typeof nameOrOptsOrHint === \"string\"\n ? { name: nameOrOptsOrHint }\n : (nameOrOptsOrHint as AddReactionOpts)\n : {};\n const { name = getCallerName(), runOnce = false } = opts;\n this.ensurePreBoot(name, \"addReaction\");\n this.ensureUniqueReactionName(name, \"addReaction\");\n // Cache load hints per-meta because CTI subtypes may resolve `hint` to different\n // load hints (e.g. an AsyncProperty overridden in the subtype with subtype-only relations).\n const loadHints = new Map<EntityMetadata, LoadHint<T>>();\n async function wrappedFn(entity: T, ctx: C) {\n const meta = getMetadata(entity);\n let loadHint = loadHints.get(meta);\n if (loadHint === undefined) {\n loadHint = convertToLoadHint<T>(meta, hint);\n loadHints.set(meta, loadHint);\n }\n if (Object.keys(loadHint).length > 0) {\n await entity.em.populate(entity, loadHint);\n }\n if (opts.assertUnchanged) assertHintUnchanged(entity, loadHint);\n return fn(entity as Loaded<T, H>, ctx);\n }\n this.__data.reactions.push({ name, fn: wrappedFn, hint, runOnce });\n }\n\n /**\n * Declares which state transitions of the enum `fieldName` are allowed, i.e. `{ Draft: [\"Open\"], Open: [\"Closed\"] }`.\n *\n * Keys and values are the enum's accessors as strings, i.e. `\"Draft\"` for `AuthorStatus.Draft`.\n *\n * A state that is missing from the table, or maps to `[]`, is treated as a terminal state & cannot be\n * changed. Creating an entity is not a transition, so a new entity may start in any state.\n *\n * The table is checked by the field's setter, so a disallowed transition throws a `ValidationErrors`\n * immediately, instead of failing the next `em.flush`.\n */\n setTransitions<K extends Settable<T>>(fieldName: K, table: TransitionTable<TransitionStates<T, K>>): void {\n const name = `setTransitions(${getCallerName()})`;\n this.ensurePreBoot(name, \"setTransitions\");\n const config = this.fieldTransitions(fieldName);\n // Subtypes add their own tables on their own configs, so a 2nd table on this config is a mistake\n if (config.table) fail(`config.setTransitions was already called for ${fieldName}, use one table per field`);\n // Accessors are converted to codes after boot, see `buildFieldTransitions`\n config.table = table;\n }\n\n /**\n * Checks each matching transition before its callbacks run, and rejects it if the guard returns an error.\n *\n * Use this for \"a transition is allowed only when ...\" checks that depend on other data, while\n * `setTransitions` declares the transitions that are possible at all. The `hint` is a load hint, like\n * `beforeFlush`'s, so it's loaded before `rule` runs, but only `fieldName` itself triggers the guard.\n *\n * Guards run with reactions, for every matching transition, even if the\n * field has moved on since. The entity is in its current state, so `rule` also gets the `transition`\n * it is checking. Guards never run on creation and are not rechecked during final validation.\n */\n addTransitionRule<K extends Settable<T>, H extends LoadHint<T>>(\n fieldName: K,\n match: GuardTransitionMatch<TransitionStates<T, K>>,\n hint: H,\n rule: TransitionGuardFn<Loaded<T, H>, TransitionType<T, K>>,\n ): void;\n addTransitionRule<K extends Settable<T>>(\n fieldName: K,\n match: GuardTransitionMatch<TransitionStates<T, K>>,\n rule: TransitionGuardFn<T, TransitionType<T, K>>,\n ): void;\n addTransitionRule(fieldName: string, match: GuardTransitionMatch<any>, hintOrRule: any, maybeRule?: any): void {\n const name = `addTransitionRule(${getCallerName()})`;\n this.ensurePreBoot(name, \"addTransitionRule\");\n const rule: TransitionGuardFn<T, any> = maybeRule ?? hintOrRule;\n const hint: LoadHint<T> | undefined = maybeRule ? hintOrRule : undefined;\n // The dispatcher evaluates matching guards once before invoking any callbacks for the transition.\n this.fieldTransitions(fieldName).guards.push({\n match,\n run(entity, step) {\n const transition = toTransition(step);\n return hint === undefined\n ? rule(entity, transition)\n : entity.em.populate(entity, hint).then((loaded) => rule(loaded, transition));\n },\n });\n }\n\n /**\n * Runs `fn` for each state transition of `fieldName` that matches `match`.\n *\n * This runs alongside reactions (see `addReaction`), but only state changes queue callbacks.\n * The `hint` is a load hint, like `beforeFlush`'s, so it is loaded but not reacted to.\n *\n * Callbacks run with reactions, once for every matching transition, in order,\n * even if the field has moved on since. The entity is in its current state, so `fn` also gets the\n * `transition` it is handling. Transitions that an `addTransitionRule` rejects don't fire.\n *\n * Creating an entity with a matching `to` state fires too, unless `match.from` is set or\n * `match.onCreate` is `false`. Set `match.phase: \"commit\"` to run in `beforeCommit` instead, i.e.\n * for enqueueing jobs.\n *\n * Callbacks that read a new entity's `id` should use `match.phase: \"commit\"`. Other callbacks may run\n * before ids are assigned, and Joist does not rerun them on a `NoIdError` because their side effects\n * could repeat.\n *\n * Pass a unique name as the first argument when registering multiple callbacks from a shared\n * helper or loop. Duplicate names on the same config are rejected when registered.\n */\n addTransitionReaction<K extends Settable<T>, H extends LoadHint<T>>(\n fieldName: K,\n match: OnTransitionMatch<TransitionStates<T, K>>,\n hint: H,\n fn: TransitionFn<Loaded<T, H>, C, TransitionType<T, K>>,\n ): void;\n addTransitionReaction<K extends Settable<T>>(\n fieldName: K,\n match: OnTransitionMatch<TransitionStates<T, K>>,\n fn: TransitionFn<T, C, TransitionType<T, K>>,\n ): void;\n addTransitionReaction<K extends Settable<T>, H extends LoadHint<T>>(\n name: string,\n fieldName: K,\n match: OnTransitionMatch<TransitionStates<T, K>>,\n hint: H,\n fn: TransitionFn<Loaded<T, H>, C, TransitionType<T, K>>,\n ): void;\n addTransitionReaction<K extends Settable<T>>(\n name: string,\n fieldName: K,\n match: OnTransitionMatch<TransitionStates<T, K>>,\n fn: TransitionFn<T, C, TransitionType<T, K>>,\n ): void;\n addTransitionReaction(\n nameOrFieldName: string,\n fieldNameOrMatch: string | OnTransitionMatch<any>,\n matchOrHintOrFn: any,\n hintOrFn?: any,\n maybeFn?: any,\n ): void {\n const named = typeof fieldNameOrMatch === \"string\";\n const name = named ? nameOrFieldName : `addTransitionReaction(${getCallerName()})`;\n this.ensurePreBoot(name, \"addTransitionReaction\");\n this.ensureUniqueReactionName(name, \"addTransitionReaction\");\n\n // Resolve the overloads\n const fieldName = named ? fieldNameOrMatch : nameOrFieldName;\n const match: OnTransitionMatch<any> = named ? matchOrHintOrFn : fieldNameOrMatch;\n const hintOrCallback = named ? hintOrFn : matchOrHintOrFn;\n const callback = named ? maybeFn : hintOrFn;\n const fn: TransitionFn<T, C, any> = callback ?? hintOrCallback;\n const hint: LoadHint<T> | undefined = callback ? hintOrCallback : undefined;\n\n // Transition queues trigger callbacks; hinted data is only loaded, not watched for changes.\n this.fieldTransitions(fieldName).callbacks.push({\n name,\n match,\n run(entity, ctx, step) {\n const transition = toTransition(step);\n return hint === undefined\n ? fn(entity, ctx, transition)\n : entity.em.populate(entity, hint).then((loaded) => fn(loaded, ctx, transition));\n },\n });\n }\n\n /** Adds a synchronous default for `fieldName` to a hard-coded `value`. */\n setDefault<K extends Settable<T>, F = FieldsOf<T>[K]>(\n fieldName: K,\n // Allow returning undefined to mean \"no default\"\n value: F extends EntityField ? F[\"type\"] : never,\n ): void;\n /** Adds a synchronous default for `fieldName` to the result of simple sync lambda. */\n setDefault<K extends Settable<T>, F = FieldsOf<T>[K]>(\n fieldName: K,\n // ...this doesn't technically declare what other fields of `entity` we depend on,\n // which ideally we want to drive \"which default to set first?\" precedence decisions.\n fn: (entity: T) => F extends EntityField ? F[\"type\"] | undefined : never,\n ): void;\n /** Adds an asynchronous default for `fieldName` to the result of a hinted lambda. */\n setDefault<K extends Settable<T>, const H extends ReactiveHint<T>, F = FieldsOf<T>[K]>(\n fieldName: K,\n // We use a ReactiveHint so that we get field-level dependencies that means someday\n // we could drive \"which default to set first?\" precedence decisions.\n hint: H,\n fn: (\n entity: Reacted<T, H>,\n ctx: C,\n ) => F extends { kind: \"m2o\"; type: infer T extends Entity }\n ? MaybePromise<T | Reacted<T, {}> | undefined>\n : F extends EntityField\n ? MaybePromise<F[\"type\"] | undefined>\n : never,\n ): void;\n setDefault<K extends keyof SettableFields<FieldsOf<T>> & string>(fieldName: K, hintOrFnOrValue: any, fn?: any): void {\n this.ensurePreBoot(getCallerName(), \"setDefault\");\n if (fn) {\n // If we're called once by the codegen, and again by the user, override the syncDefault\n delete this.__data.syncDefaults[fieldName];\n this.__data.asyncDefaults[fieldName] = new AsyncDefault(fieldName, hintOrFnOrValue, fn);\n } else {\n this.__data.syncDefaults[fieldName] = hintOrFnOrValue;\n }\n }\n\n /**\n * A noop method that exists solely to keep the `config.placeholder()` line in the initial entity file,\n * until the user is ready to use it. */\n placeholder(): void {}\n\n /** Returns `fieldName`'s transition config, creating it on first use. */\n private fieldTransitions(fieldName: string): FieldTransitionsConfig<T, C> {\n return (this.__data.transitions[fieldName] ??= { guards: [], callbacks: [] });\n }\n\n /** Requires unique names across ordinary reactions and transition callbacks. */\n private ensureUniqueReactionName(name: string, op: string): void {\n if (this.__data.reactionNames.has(name)) {\n throw new Error(\n `Duplicate reaction name \"${name}\" in config.${op}. Pass a unique name when registering reactions from a shared helper or loop.`,\n );\n }\n this.__data.reactionNames.add(name);\n }\n\n private ensurePreBoot(name: string, op: string): void {\n if (booted) {\n // Detect if this is NextJS and we're in a hot-reload situation\n if (isRunningInNextJs()) {\n // Reset our bag of config data to collect only the new rules/hooks\n this.__data = new ConfigData();\n resetBootFlag();\n } else {\n throw new Error(\n `config.${op} call on ${name} must only be called on boot, before calling \\`configureMetadata\\`.`,\n );\n }\n }\n }\n}\n\nfunction isRunningInNextJs(): boolean {\n return \"__NEXT_HTTP_AGENT\" in globalThis || \"__NEXT_HTTPS_AGENT\" in globalThis;\n}\n\n/**\n * Allows projects to manually reset the internal `booted` flag.\n *\n * This is only necessary if they're using hot-reloading and reloading their entity files\n * without restarting the server.\n *\n * Generally most tools like tsx or ts-node-dev reload the whole process, so don't need\n * to call this, but if Joist is used in a framework that does actual-hot-reloading, this\n * it will be necessary.\n */\nexport function resetBootFlag(): void {\n booted = false;\n afterMetadataLocked = false;\n resetConstructorMap();\n}\n\n/**\n * Stores a path back to a reactive rule.\n *\n * I.e. if `Book` has a `ruleFn` that reacts to `Author.title`, then `Author`'s config will have\n * a `ReactiveRule` with fields `[\"title\"]`, path `books`, and rule `ruleFn`.\n */\nexport interface ReactiveRule {\n /** The source we're reacting to, specifically which base/subtype cstr. */\n source: MaybeAbstractEntityConstructor<any>;\n /** The fields on this source entity that would trigger the downstream rule's eval. */\n fields: string[];\n /** The constructor of downstream entity that owns the reactive rule. */\n cstr: MaybeAbstractEntityConstructor<any>;\n /** The name (source location) of the downstream reactive rule. */\n name: string;\n /** The path from this source entity to the downstream entity that needs evaled. */\n path: string[];\n /** The downstream validation rule to eval. */\n fn: ValidationRule<any>;\n}\n\n/**\n * Stores a path back to a reactive derived field.\n *\n * I.e. if `Book.displayName` is an `asyncField` that reacts to `Author.title`, then `Author`'s config will have\n * a `ReactiveFields` with fields `[\"title\"]`, path `books`, and name `displayName`.\n */\nexport interface ReactiveField {\n kind: \"populate\" | \"query\";\n /** The fields on this source entity that would trigger the downstream field's recalc. */\n fields: string[];\n /** Read-only/immutable fields that are used in the derived field. */\n isReadOnly: boolean;\n /** The constructor of downstream entity that owns the derived field. */\n cstr: MaybeAbstractEntityConstructor<any>;\n /** The path from this source entity to the downstream entity that needs recalced. */\n path: string[];\n /** The name of the reactive field in the downstream entity to recalc. */\n name: string;\n runOnce: false;\n}\n\nexport interface Reaction {\n kind: \"reaction\";\n /** The source we're reacting to, specifically which base/subtype cstr. */\n source: MaybeAbstractEntityConstructor<any>;\n /** The fields on this source entity that would trigger the downstream hook's eval. */\n fields: string[];\n /** Read-only/immutable fields that are used in the function. */\n isReadOnly: boolean;\n /** The constructor of downstream entity that owns the reaction. */\n cstr: MaybeAbstractEntityConstructor<any>;\n /** The name (source location) of the downstream reaction. */\n name: string;\n /** The path from this source entity to the downstream entity for this reaction. */\n path: string[];\n /** The downstream reaction function. */\n fn: HookFn<any, any>;\n /** If true, the reaction should only run once per flush, not every time the hint changes. */\n runOnce: boolean;\n}\n\nexport type Reactable = ReactiveField | Reaction;\n\ninterface ReactionInternal<T extends Entity, H extends ReactiveHint<T>, C> {\n name: string;\n fn: HookFn<T, C>;\n hint: H;\n runOnce: boolean;\n}\n\ntype AfterMetadataCallback<T extends Entity> = (meta: EntityMetadata<T>) => void;\n\n/** The internal state of an entity's configuration data, i.e. validation rules/hooks. */\nexport class ConfigData<T extends Entity, C> {\n afterMetadataCallbacks: AfterMetadataCallback<T>[] = [];\n runHooksBefore: EntityConstructor<any>[] = [];\n /** The validation rules for this entity type. */\n rules: ValidationRuleInternal<T>[] = [];\n /** The \"commit rules\" for this entity type, i.e. validation rules that run post-flush/pre-commit. */\n commitRules: ValidationRuleInternal<T>[] = [];\n /** The reactions for this entity type. */\n reactions: ReactionInternal<T, any, C>[] = [];\n /** Names shared by addReaction and addTransitionReaction, including commit-phase callbacks. */\n reactionNames: Set<string> = new Set();\n /**\n * Field name -> its `setTransitions`, `addTransitionRule`, and `addTransitionReaction` config, with\n * accessors not yet converted.\n *\n * The keys are also the fields whose factories accept `withX` opts.\n */\n transitions: Record<string, FieldTransitionsConfig<T, C>> = {};\n /** The hooks for this entity type. */\n hooks: Record<EntityHook, HookFn<T, C>[]> = {\n beforeDelete: [],\n beforeFlush: [],\n beforeCreate: [],\n beforeUpdate: [],\n afterValidation: [],\n beforeCommit: [],\n afterCommit: [],\n };\n /** Synchronous defaults for this entity type, invoked on `em.create`. */\n syncDefaults: Record<string, ((entity: T) => void) | unknown> = {};\n /** Asynchronous defaults for this entity type, invoked on `em.flush`. */\n asyncDefaults: Record<string, AsyncDefault<T>> = {};\n\n // An array of the reactive rules that depend on this entity\n reactiveRules: ReactiveRule[] = [];\n // An array of the reactive *commit* rules (post-flush/pre-commit) that depend on this entity\n reactiveCommitRules: ReactiveRule[] = [];\n // An array of the reactive fields and reactions that depend on this entity\n reactables: Reactable[] = [];\n cascadeDeleteFields: Array<keyof RelationsIn<T>> = [];\n touchOnChange: Set<keyof RelationsIn<T>> = new Set();\n // Constantly converting reactive hints to load hints is expense, so cache them here\n cachedReactiveLoadHints: Record<string, any> = {};\n /** Maps recursive collection fieldNames to custom cycle error message functions. */\n cycleMessages: Record<string, (entity: T, cyclePath: Entity[]) => string> = {};\n}\n\nexport function getCallerName(extraFrames: number = 0): string {\n const err = getStack();\n // E.g. at Object.<anonymous> (/home/stephen/homebound/graphql-service/src/entities/Activity.ts:86:8)\n // (Make sure to drop lines that don't start with 'at' b/c the stack format can differ\n // slightly i.e. if running via tsx/using a node loader (probably?)\n const line = err.stack!.split(\"\\n\").filter((line) => line.includes(\" at \"))[3 + extraFrames];\n const parts = line.split(\"/\");\n // Get the last part, which will be the file name, i.e. Activity.ts:86:8\n return parts[parts.length - 1].replace(/:\\d+\\)?$/, \"\");\n}\n\nexport function getFuzzyCallerName(): string {\n const err = getStack();\n const lines = err\n .stack!.split(\"\\n\")\n // E.g. at Object.<anonymous> (/home/stephen/homebound/graphql-service/src/entities/Activity.ts:86:8)\n .filter((line) => line.includes(\" at \"));\n const line = findUserCodeLine(lines);\n return getFilePath(line);\n}\n\n/**\n * Given a callstack line return the file name.\n *\n * I.e. `at Object.<anonymous> (/home/stephen/homebound/graphql-service/src/entities/Activity.ts:86:8)`\n */\nexport function getFilePath(line: string): string {\n const parts = line.split(\"/\");\n return parts[parts.length - 1].replace(/:\\d+\\)?$/, \"\"); // Drop the `:8)`at the end\n}\n\n/** Given a callstack, uses heuristics to find the first line that looks like user code. */\nexport function findUserCodeLine(lines: string[]): string {\n return (\n lines.find((line) => {\n // When running Joist's own integration tests, if we ignore `/joist-orm/`, we'll end up ignoring\n // everything because `joist-orm` is the name of the repository/working copy itself.\n const withinWorkingCopyJoist = line.includes(\"/packages/orm/\") || line.includes(\"/packages/core\");\n // But once we're not in a working copy, assume any `/joist-orm/` in the path === internal orm stack frames\n const withinProductionJoist =\n !withinWorkingCopyJoist && (line.includes(\"/joist-orm/src/\") || line.includes(\"/joist-core/src\"));\n const nodeInternals = line.includes(\"node:internal/\") || line.includes(\"Promise.all\");\n const isUserCode = !withinWorkingCopyJoist && !withinProductionJoist && !nodeInternals;\n // const isRecalc = line.includes(\".recalcPending\");\n const isDefault = line.includes(\"/defaults.ts\");\n // Batched calls like findOrCreate won't have a stack trace back to the true caller, so just stop there\n const isDataloader = line.includes(\"/dataloaders/\");\n // If this is the `newTestInstance` call\n // What about:\n // recalcSynchronousDerivedFields\n return (\n (isDefault || isDataloader || isUserCode) &&\n !line.includes(\"Codegen.ts\") &&\n // I wanted to exclude this, but it was actually our utils/entities.ts maybeSetDefault helper method\n // !line.includes(\"entities.ts\") &&\n // Ignore loops in joist code like setOpts\n !line.includes(\"at Array\") &&\n // Ignore the Author.ts constructor calling setOpts\n !line.includes(\"at new \")\n );\n }) ?? fail(\"Could not find caller name\")\n );\n}\n\nconst getStack: () => { stack?: string } = \"captureStackTrace\" in Error ? getStackFromCapture : getStackFromObject;\n\nfunction getStackFromCapture(): { stack?: string } {\n const obj = {};\n Error.captureStackTrace(obj);\n return obj as any;\n}\n\nfunction getStackFromObject(): { stack?: string } {\n try {\n throw Error(\"\");\n } catch (err) {\n return err as Error;\n }\n}\n\n/** Pushes a validation rule (either the raw or hinted/reactive form) onto `rules`, shared by `addRule`/`addCommitRule`. */\nfunction pushValidationRule<T extends Entity>(\n rules: ValidationRuleInternal<T>[],\n name: string,\n ruleOrHint: ValidationRule<T> | any,\n maybeRule: ValidationRule<any> | undefined,\n opts: AssertUnchangedOpts = {},\n): void {\n if (typeof ruleOrHint === \"function\") {\n rules.push({ name, fn: ruleOrHint, hint: undefined });\n } else {\n const hint = ruleOrHint;\n // Cache load hints per-meta because CTI subtypes may resolve `hint` to different\n // load hints (e.g. an AsyncProperty overridden in the subtype with subtype-only relations).\n const loadHints = new Map<EntityMetadata, LoadHint<T>>();\n async function fn(entity: T) {\n const meta = getMetadata(entity);\n let loadHint = loadHints.get(meta);\n if (loadHint === undefined) {\n loadHint = convertToLoadHint<T>(meta, hint);\n loadHints.set(meta, loadHint);\n }\n if (Object.keys(loadHint).length > 0) {\n await entity.em.populate(entity, loadHint);\n }\n if (opts.assertUnchanged) assertHintUnchanged(entity, loadHint);\n return maybeRule!(entity);\n }\n rules.push({ name, fn, hint });\n }\n}\n"],"mappings":";;;;;;;;;;;;AAyEA,MAAa,kCAA0D,CAAC;AAIxE,IAAI,SAAS;AACb,IAAI,sBAAsB;;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kBAAqB,MAAM,IAAI;IAC1C,UAAU,IAAI,MAAM,QAAQ;GAC9B;GACA,IAAI,OAAO,KAAK,QAAQ,CAAC,CAAC,SAAS,GACjC,MAAM,OAAO,GAAG,SAAS,QAAQ,QAAQ;GAE3C,IAAI,KAAK,iBAAiB,wBAAA,oBAAoB,QAAQ,QAAQ;GAC9D,OAAO,UAAW,MAAM;EAC1B;EACA,MAAM,KAAK;GAAE;GAAM;GAAI;EAAK,CAAC;CAC/B;AACF"}
|
|
1
|
+
{"version":3,"file":"config.cjs","names":["getMetadata","convertToLoadHint","toTransition","AsyncDefault","fail"],"sources":["../src/config.ts"],"sourcesContent":["import { resetConstructorMap } from \"src/configure.ts\";\nimport { AsyncDefault } from \"src/defaults.ts\";\nimport { type Entity } from \"src/Entity.ts\";\nimport { assertHintUnchanged } from \"src/flush/ReadDrift.ts\";\nimport {\n type EntityConstructor,\n type EntityField,\n type EntityMetadata,\n type FieldsOf,\n type LoadHint,\n type Loaded,\n type MaybeAbstractEntityConstructor,\n type Reacted,\n type ReactiveHint,\n type RelationsIn,\n type SettableFields,\n fail,\n getMetadata,\n} from \"src/index.ts\";\nimport { convertToLoadHint } from \"src/reactivity/reactiveHints.ts\";\nimport { type ValidationRule, type ValidationRuleInternal, type ValidationRuleResult } from \"src/rules.ts\";\nimport {\n type FieldTransitionsConfig,\n type GuardTransitionMatch,\n type OnTransitionMatch,\n type Transition,\n type TransitionTable,\n toTransition,\n} from \"src/transitions.ts\";\nimport { type MaybePromise } from \"src/utils.ts\";\n\nexport type EntityHook =\n | \"beforeFlush\"\n | \"beforeCreate\"\n | \"beforeUpdate\"\n | \"beforeDelete\"\n | \"afterValidation\"\n | \"beforeCommit\"\n | \"afterCommit\";\ntype HookFn<T extends Entity, C> = (entity: T, ctx: C) => MaybePromise<unknown>;\n\ntype AssertUnchangedOpts = {\n /** Protect reached rows at flush; does not protect collection membership or predicates. */\n assertUnchanged?: boolean;\n};\ntype AddReactionOpts = AssertUnchangedOpts & { runOnce?: boolean; name?: string };\n\n/** An `addTransitionRule` rule, which also gets the transition it is checking, since the entity may have moved on. */\nexport type TransitionGuardFn<T extends Entity, V> = (\n entity: T,\n transition: Transition<V>,\n) => MaybePromise<ValidationRuleResult>;\n\n/** An `addTransitionReaction` function, which also gets the transition it is handling, since the entity may have moved on. */\ntype TransitionFn<T extends Entity, C, V> = (entity: T, ctx: C, transition: Transition<V>) => MaybePromise<unknown>;\n\n/** The enum type of a transition field, i.e. `PublisherStatus`. */\ntype TransitionType<T extends Entity, K extends keyof FieldsOf<T>> = FieldsOf<T>[K] extends EntityField\n ? NonNullable<FieldsOf<T>[K][\"type\"]>\n : never;\n\n/**\n * The state names that `transitions` tables and `match`es accept for an enum field, i.e. `\"Draft\"` for\n * `PublisherStatus.Draft`.\n *\n * We only accept the enum's accessors, not its codes or members, so every table reads the same way.\n */\ntype TransitionStates<T extends Entity, K extends keyof FieldsOf<T>> = FieldsOf<T>[K] extends {\n accessors: infer A extends string;\n}\n ? A\n : never;\n\nexport const constraintNameToValidationError: Record<string, string> = {};\n\ntype Settable<T extends Entity> = keyof SettableFields<FieldsOf<T>> & string;\n\nlet booted = false;\nlet afterMetadataLocked = false;\n\n/**\n * Called at the end of `configureMetadata` to indicate the boot process is complete.\n *\n * We use this flag to prevent users from mistakenly calling `config` methods after the boot\n * process is complete, i.e. from hooks or other post-boot invocations, where the calls are\n * not guaranteed to work because Joist's reactivity graph has already been initialized.\n */\nexport function setBooted(): void {\n booted = true;\n}\n\nexport function setAfterMetadataLocked(): void {\n afterMetadataLocked = true;\n}\n\n/** The public API to configure an Entity's hooks & validation rules. */\nexport class ConfigApi<T extends Entity, C> {\n __data = new ConfigData<T, C>();\n\n /**\n * Maps a given `constraintName`, i.e. `authors_publisher_id_unique_index`, to a hard-coded-but-pretty validation errors.\n *\n * Note that the validationError must be hard-coded b/c we cannot tease out \"which entity\" caused a given\n * constraint failure from the SQL database. If you really need pretty-and-custom validation errors, you'll\n * need to check the constraint by hand ahead of time, before calling `em.flush`.\n */\n addConstraintMessage(constraintName: string, validationError: string) {\n this.ensurePreBoot(getCallerName(), \"addConstraintMessage\");\n constraintNameToValidationError[constraintName] = validationError;\n }\n\n /**\n * Maps a `RecursiveCycleError` on the given recursive collection field to a custom validation error.\n *\n * When a cycle is detected in a recursive collection (e.g. `parentsRecursive`), instead of\n * throwing a raw `RecursiveCycleError`, `em.flush` will convert it into a `ValidationErrors`\n * using the provided message function.\n *\n * The `messageFn` receives the entity that detected the cycle and the cycle path (array of\n * entities forming the cycle), and should return a validation error string.\n */\n addCycleRule(fieldName: string & keyof T, messageFn: (entity: T, cyclePath: Entity[]) => string) {\n this.ensurePreBoot(getCallerName(), \"addCycleRule\");\n this.__data.cycleMessages[fieldName] = messageFn;\n // Register a reactive rule that loads the recursive collection and catches cycle errors.\n // The rule uses the recursive collection's underlying relation as a reactive hint so it\n // triggers when the collection changes.\n const hint = fieldName as any;\n const fn = () => {\n // We don't actually need a try/catch/anything here, b/c if there is a cycle, it\n // will cause a CycleError during followReverseHint, and never even get to calling this fn.\n };\n this.__data.rules.push({ name: `addCycleRule(${getCallerName()})`, fn, hint });\n }\n\n /**\n * Adds a validation rule for this entity.\n *\n * If `hint` is passed, then the rule's lambda will be: 1) passed a view of the entity with only\n * the fields included in `hint` marked as accessible, and 2) the rule will be called reactively any\n * time any field in the `hint` changes.\n *\n * If lambdas want to access fields w/o having them marked for reactivity, the rule can either\n * include the field as readonly with a `:ro` suffix, i.e. `firstName:ro`, or the lambda can\n * access the `reacted.entity` property to get a full view of the entity's fields and methods.\n */\n addRule<H extends ReactiveHint<T>>(hint: H, rule: ValidationRule<Reacted<T, H>>): void;\n addRule<H extends ReactiveHint<T>>(opts: AssertUnchangedOpts, hint: H, rule: ValidationRule<Reacted<T, H>>): void;\n addRule(rule: ValidationRule<T>): void;\n addRule(\n ruleOrHint: ValidationRule<T> | any,\n hintOrRule?: ReactiveHint<T> | ValidationRule<any>,\n maybeRule?: ValidationRule<any>,\n ): void {\n // Keep the name for easy debugging/tracing later\n const name = `addRule(${getCallerName()})`;\n this.ensurePreBoot(name, \"addRule\");\n pushValidationRule(\n this.__data.rules,\n name,\n maybeRule ? hintOrRule : ruleOrHint,\n maybeRule ?? (hintOrRule as ValidationRule<any> | undefined),\n maybeRule ? ruleOrHint : {},\n );\n }\n\n /**\n * Adds a \"commit rule\" that runs like a regular validation rule (see {@link addRule}), but *after*\n * the entity's `INSERT`/`UPDATE`/`DELETE` has been flushed to the database and *before* the\n * transaction `COMMIT`s, i.e. still within the transaction.\n *\n * The point of running this late is that any `em.find`s the rule makes will query the _changed_\n * state (the just-flushed rows), instead of the pre-flush state that regular `addRule` rules see.\n * This is useful for cross-row invariants that are easiest to express as a query, e.g. \"at most\n * one active `AuthorSchedule` per author\", where the rule wants to `em.find` the sibling rows\n * that were themselves just inserted/updated in this same flush.\n *\n * Like `addRule`, if a `hint` is passed the rule is reactive: it runs whenever any field in the\n * hint changes (walking back to the owning entity), and the lambda gets a `Reacted` view.\n */\n addCommitRule<H extends ReactiveHint<T>>(hint: H, rule: ValidationRule<Reacted<T, H>>): void;\n addCommitRule<H extends ReactiveHint<T>>(\n opts: AssertUnchangedOpts,\n hint: H,\n rule: ValidationRule<Reacted<T, H>>,\n ): void;\n addCommitRule(rule: ValidationRule<T>): void;\n addCommitRule(\n ruleOrHint: ValidationRule<T> | any,\n hintOrRule?: ReactiveHint<T> | ValidationRule<any>,\n maybeRule?: ValidationRule<any>,\n ): void {\n // Keep the name for easy debugging/tracing later\n const name = `addCommitRule(${getCallerName()})`;\n this.ensurePreBoot(name, \"addCommitRule\");\n pushValidationRule(\n this.__data.commitRules,\n name,\n maybeRule ? hintOrRule : ruleOrHint,\n maybeRule ?? (hintOrRule as ValidationRule<any> | undefined),\n maybeRule ? ruleOrHint : {},\n );\n }\n\n /** If both this entity, and `cstr` entities, are in the same `em.flush`, run us first. */\n runHooksBefore(cstr: EntityConstructor<any>): void {\n this.__data.runHooksBefore.push(cstr);\n }\n\n /** Deletes any entity/entities pointed to by `relation` when this entity is deleted. */\n cascadeDelete(relation: keyof RelationsIn<T> & LoadHint<T>): void {\n this.ensurePreBoot(getCallerName(), \"cascadeDelete\");\n this.__data.cascadeDeleteFields.push(relation);\n }\n\n touchOnChange(relation: keyof RelationsIn<T>): void {\n this.ensurePreBoot(getCallerName(), \"touchOnChange\");\n this.__data.touchOnChange.add(relation);\n }\n\n private addHook(hook: EntityHook, ruleOrHint: HookFn<T, C> | any, maybeFn?: HookFn<Loaded<T, any>, C>) {\n this.ensurePreBoot(getCallerName(), \"addHook\");\n if (typeof ruleOrHint === \"function\") {\n this.__data.hooks[hook].push(ruleOrHint);\n } else {\n const fn = async (entity: T, ctx: C) => {\n // TODO Use this for reactive beforeFlush\n const loaded = await entity.em.populate(entity, ruleOrHint);\n return maybeFn!(loaded, ctx);\n };\n // Squirrel our hint away where configureMetadata can find it\n (fn as any).hint = ruleOrHint;\n this.__data.hooks[hook].push(fn);\n }\n }\n\n afterMetadata(fn: AfterMetadataCallback<T>): void {\n if (afterMetadataLocked) {\n throw new Error(\n `config.afterMetadata on ${getCallerName()} must only be called on boot, before calling \\`configureMetadata\\` and not from other \\`afterMetadata\\` hooks.`,\n );\n }\n this.__data.afterMetadataCallbacks.push(fn);\n }\n\n beforeDelete<H extends LoadHint<T>>(populate: H, fn: HookFn<Loaded<T, H>, C>): void;\n beforeDelete(fn: HookFn<T, C>): void;\n beforeDelete(ruleOrHint: HookFn<T, C> | any, maybeFn?: HookFn<Loaded<T, any>, C>): void {\n this.addHook(\"beforeDelete\", ruleOrHint, maybeFn);\n }\n\n beforeFlush<H extends LoadHint<T>>(populate: H, fn: HookFn<Loaded<T, H>, C>): void;\n beforeFlush(fn: HookFn<T, C>): void;\n beforeFlush(ruleOrHint: HookFn<T, C> | any, maybeFn?: HookFn<Loaded<T, any>, C>): void {\n this.addHook(\"beforeFlush\", ruleOrHint, maybeFn);\n }\n\n // beforeCreate still needs to take a hint because even though the entity itself is New<T>, we might want to load\n // a nested relation that isn't loaded yet\n beforeCreate<H extends LoadHint<T>>(populate: H, fn: HookFn<Loaded<T, H>, C>): void;\n beforeCreate(fn: HookFn<T, C>): void;\n beforeCreate(ruleOrHint: HookFn<T, C> | any, maybeFn?: HookFn<Loaded<T, any>, C>): void {\n this.addHook(\"beforeCreate\", ruleOrHint, maybeFn);\n }\n\n beforeUpdate<H extends LoadHint<T>>(populate: H, fn: HookFn<Loaded<T, H>, C>): void;\n beforeUpdate(fn: HookFn<T, C>): void;\n beforeUpdate(ruleOrHint: HookFn<T, C> | any, maybeFn?: HookFn<Loaded<T, any>, C>): void {\n this.addHook(\"beforeUpdate\", ruleOrHint, maybeFn);\n }\n\n afterValidation<H extends LoadHint<T>>(populate: H, fn: HookFn<Loaded<T, H>, C>): void;\n afterValidation(fn: HookFn<T, C>): void;\n afterValidation(ruleOrHint: HookFn<T, C> | any, maybeFn?: HookFn<Loaded<T, any>, C>): void {\n this.addHook(\"afterValidation\", ruleOrHint, maybeFn);\n }\n\n beforeCommit(fn: HookFn<T, C>): void {\n this.addHook(\"beforeCommit\", fn);\n }\n\n afterCommit(fn: HookFn<T, C>): void {\n this.addHook(\"afterCommit\", fn);\n }\n\n /**\n * Adds a reaction that runs during flush whenever fields in the `hint` change.\n *\n * Reactions are somewhere in between hooks and reactive fields/references:\n * 1. Can make arbitrary changes to any entity like a hook\n * 2. Only run when the provided hint has changes, not on every flush, like an RF/RR\n * 3. Run when the entity itself has no changes, like an RF/RF\n * 4. Can run multiple times per flush, like an RF/RF. Be careful to avoid creating\n * circular dependencies in the hint and to make the function idempotent.\n *\n * Names default to the registration's source location. Pass unique names when registering multiple\n * reactions from a shared helper or loop; duplicate names on the same config are rejected.\n *\n * @param hint The fields to watch for changes and load before running the reaction\n * @param fn The reaction function to run\n */\n addReaction<H extends ReactiveHint<T>>(hint: H, fn: HookFn<Loaded<T, H>, C>): void;\n /**\n * Adds a named reaction that runs during flush whenever fields in the `hint` change.\n *\n * Reactions are somewhere in between hooks and reactive fields/references:\n * 1. Can make arbitrary changes to any entity like a hook\n * 2. Only run when `hint` has changes, not on every flush, like an RF/RR\n * 3. Can run when the entity itself has no changes, like an RF/RF\n * 4. Can run multiple times per flush, like an RF/RF. Be careful to avoid creating\n * circular dependencies in the hint and to make the function idempotent.\n *\n * @param name A name to identify this reaction for debugging\n * @param hint The fields to watch for changes and load before running the reaction\n * @param fn The reaction function to run\n */\n addReaction<H extends ReactiveHint<T>>(name: string, hint: H, fn: HookFn<Loaded<T, H>, C>): void;\n /**\n * Adds a reaction that runs during flush whenever fields in the `hint` change.\n *\n * Reactions are somewhere in between hooks and reactive fields/references:\n * 1. Can make arbitrary changes to any entity like a hook\n * 2. Only run when `hint` has changes, not on every flush, like an RF/RR\n * 3. Can run when the entity itself has no changes, like an RF/RF\n * 4. Can run multiple times per flush, like an RF/RF. Be careful to avoid creating\n * circular dependencies in the hint and to make the function idempotent.\n *\n * @param opts Options object containing:\n * - runOnce - If true, the reaction will only run once per flush, not every time the hint changes. Optional.\n * default: false.\n * - name - A name to identify this reaction for debugging\n * @param hint The fields to watch for changes and load before running the reaction\n * @param fn The reaction function to run\n */\n addReaction<H extends ReactiveHint<T>>(opts: AddReactionOpts, hint: H, fn: HookFn<Loaded<T, H>, C>): void;\n addReaction<H extends ReactiveHint<T>>(\n nameOrOptsOrHint: string | AddReactionOpts | H,\n hintOrFn: H | HookFn<Loaded<T, H>, C>,\n maybeFn?: HookFn<Loaded<T, H>, C>,\n ): void {\n // Keep the name so we can uniquely identify this reaction later and also aid debugging/tracing\n const fn = maybeFn ?? (hintOrFn as HookFn<Loaded<T, H>, C>);\n const hint = (maybeFn ? hintOrFn : nameOrOptsOrHint) as H;\n const opts = maybeFn\n ? typeof nameOrOptsOrHint === \"string\"\n ? { name: nameOrOptsOrHint }\n : (nameOrOptsOrHint as AddReactionOpts)\n : {};\n const { name = getCallerName(), runOnce = false } = opts;\n this.ensurePreBoot(name, \"addReaction\");\n this.ensureUniqueReactionName(name, \"addReaction\");\n // Cache load hints per-meta because CTI subtypes may resolve `hint` to different\n // load hints (e.g. an AsyncProperty overridden in the subtype with subtype-only relations).\n const loadHints = new Map<EntityMetadata, LoadHint<T>>();\n async function wrappedFn(entity: T, ctx: C) {\n const meta = getMetadata(entity);\n let loadHint = loadHints.get(meta);\n if (loadHint === undefined) {\n loadHint = convertToLoadHint<T>(meta, hint);\n loadHints.set(meta, loadHint);\n }\n if (Object.keys(loadHint).length > 0) {\n await entity.em.populate(entity, loadHint);\n }\n if (opts.assertUnchanged) assertHintUnchanged(entity, loadHint);\n return fn(entity as Loaded<T, H>, ctx);\n }\n this.__data.reactions.push({ name, fn: wrappedFn, hint, runOnce });\n }\n\n /**\n * Declares which state transitions of the enum `fieldName` are allowed, i.e. `{ Draft: [\"Open\"], Open: [\"Closed\"] }`.\n *\n * Keys and values are the enum's accessors as strings, i.e. `\"Draft\"` for `AuthorStatus.Draft`.\n *\n * A state that is missing from the table, or maps to `[]`, is treated as a terminal state & cannot be\n * changed. Creating an entity is not a transition, so a new entity may start in any state.\n *\n * The table is checked by the field's setter, so a disallowed transition throws a `ValidationErrors`\n * immediately, instead of failing the next `em.flush`.\n */\n setTransitions<K extends Settable<T>>(fieldName: K, table: TransitionTable<TransitionStates<T, K>>): void {\n const name = `setTransitions(${getCallerName()})`;\n this.ensurePreBoot(name, \"setTransitions\");\n const config = this.fieldTransitions(fieldName);\n // Subtypes add their own tables on their own configs, so a 2nd table on this config is a mistake\n if (config.table) fail(`config.setTransitions was already called for ${fieldName}, use one table per field`);\n // Accessors are converted to codes after boot, see `buildFieldTransitions`\n config.table = table;\n }\n\n /**\n * Checks each matching transition before its callbacks run, and rejects it if the guard returns an error.\n *\n * Use this for \"a transition is allowed only when ...\" checks that depend on other data, while\n * `setTransitions` declares the transitions that are possible at all. The `hint` is a load hint, like\n * `beforeFlush`'s, so it's loaded before `rule` runs, but only `fieldName` itself triggers the guard.\n *\n * Guards run with reactions, for every matching transition, even if the\n * field has moved on since. The entity is in its current state, so `rule` also gets the `transition`\n * it is checking. Guards never run on creation and are not rechecked during final validation.\n */\n addTransitionRule<K extends Settable<T>, H extends LoadHint<T>>(\n fieldName: K,\n match: GuardTransitionMatch<TransitionStates<T, K>>,\n hint: H,\n rule: TransitionGuardFn<Loaded<T, H>, TransitionType<T, K>>,\n ): void;\n addTransitionRule<K extends Settable<T>>(\n fieldName: K,\n match: GuardTransitionMatch<TransitionStates<T, K>>,\n rule: TransitionGuardFn<T, TransitionType<T, K>>,\n ): void;\n addTransitionRule(fieldName: string, match: GuardTransitionMatch<any>, hintOrRule: any, maybeRule?: any): void {\n const name = `addTransitionRule(${getCallerName()})`;\n this.ensurePreBoot(name, \"addTransitionRule\");\n const rule: TransitionGuardFn<T, any> = maybeRule ?? hintOrRule;\n const hint: LoadHint<T> | undefined = maybeRule ? hintOrRule : undefined;\n // The dispatcher evaluates matching guards once before invoking any callbacks for the transition.\n this.fieldTransitions(fieldName).guards.push({\n match,\n run(entity, step) {\n const transition = toTransition(step);\n return hint === undefined\n ? rule(entity, transition)\n : entity.em.populate(entity, hint).then((loaded) => rule(loaded, transition));\n },\n });\n }\n\n /**\n * Runs `fn` for each state transition of `fieldName` that matches `match`.\n *\n * This runs alongside reactions (see `addReaction`), but only state changes queue callbacks.\n * The `hint` is a load hint, like `beforeFlush`'s, so it is loaded but not reacted to.\n *\n * Callbacks run with reactions, once for every matching transition, in order,\n * even if the field has moved on since. The entity is in its current state, so `fn` also gets the\n * `transition` it is handling. Transitions that an `addTransitionRule` rejects don't fire.\n *\n * Creating an entity with a matching `to` state fires too, unless `match.from` is set or\n * `match.onCreate` is `false`. Set `match.phase: \"commit\"` to run in `beforeCommit` instead, i.e.\n * for enqueueing jobs.\n *\n * Callbacks that read a new entity's `id` should use `match.phase: \"commit\"`. Other callbacks may run\n * before ids are assigned, and Joist does not rerun them on a `NoIdError` because their side effects\n * could repeat.\n *\n * Pass a unique name as the first argument when registering multiple callbacks from a shared\n * helper or loop. Duplicate names on the same config are rejected when registered.\n */\n addTransitionReaction<K extends Settable<T>, H extends LoadHint<T>>(\n fieldName: K,\n match: OnTransitionMatch<TransitionStates<T, K>>,\n hint: H,\n fn: TransitionFn<Loaded<T, H>, C, TransitionType<T, K>>,\n ): void;\n addTransitionReaction<K extends Settable<T>>(\n fieldName: K,\n match: OnTransitionMatch<TransitionStates<T, K>>,\n fn: TransitionFn<T, C, TransitionType<T, K>>,\n ): void;\n addTransitionReaction<K extends Settable<T>, H extends LoadHint<T>>(\n name: string,\n fieldName: K,\n match: OnTransitionMatch<TransitionStates<T, K>>,\n hint: H,\n fn: TransitionFn<Loaded<T, H>, C, TransitionType<T, K>>,\n ): void;\n addTransitionReaction<K extends Settable<T>>(\n name: string,\n fieldName: K,\n match: OnTransitionMatch<TransitionStates<T, K>>,\n fn: TransitionFn<T, C, TransitionType<T, K>>,\n ): void;\n addTransitionReaction(\n nameOrFieldName: string,\n fieldNameOrMatch: string | OnTransitionMatch<any>,\n matchOrHintOrFn: any,\n hintOrFn?: any,\n maybeFn?: any,\n ): void {\n const named = typeof fieldNameOrMatch === \"string\";\n const name = named ? nameOrFieldName : `addTransitionReaction(${getCallerName()})`;\n this.ensurePreBoot(name, \"addTransitionReaction\");\n this.ensureUniqueReactionName(name, \"addTransitionReaction\");\n\n // Resolve the overloads\n const fieldName = named ? fieldNameOrMatch : nameOrFieldName;\n const match: OnTransitionMatch<any> = named ? matchOrHintOrFn : fieldNameOrMatch;\n const hintOrCallback = named ? hintOrFn : matchOrHintOrFn;\n const callback = named ? maybeFn : hintOrFn;\n const fn: TransitionFn<T, C, any> = callback ?? hintOrCallback;\n const hint: LoadHint<T> | undefined = callback ? hintOrCallback : undefined;\n\n // Transition queues trigger callbacks; hinted data is only loaded, not watched for changes.\n this.fieldTransitions(fieldName).callbacks.push({\n name,\n match,\n run(entity, ctx, step) {\n const transition = toTransition(step);\n return hint === undefined\n ? fn(entity, ctx, transition)\n : entity.em.populate(entity, hint).then((loaded) => fn(loaded, ctx, transition));\n },\n });\n }\n\n /** Adds a synchronous default for `fieldName` to a hard-coded `value`. */\n setDefault<K extends Settable<T>, F = FieldsOf<T>[K]>(\n fieldName: K,\n // Allow returning undefined to mean \"no default\"\n value: F extends EntityField ? F[\"type\"] : never,\n ): void;\n /** Adds a synchronous default for `fieldName` to the result of simple sync lambda. */\n setDefault<K extends Settable<T>, F = FieldsOf<T>[K]>(\n fieldName: K,\n // ...this doesn't technically declare what other fields of `entity` we depend on,\n // which ideally we want to drive \"which default to set first?\" precedence decisions.\n fn: (entity: T) => F extends EntityField ? F[\"type\"] | undefined : never,\n ): void;\n /** Adds an asynchronous default for `fieldName` to the result of a hinted lambda. */\n setDefault<K extends Settable<T>, const H extends ReactiveHint<T>, F = FieldsOf<T>[K]>(\n fieldName: K,\n // We use a ReactiveHint so that we get field-level dependencies that means someday\n // we could drive \"which default to set first?\" precedence decisions.\n hint: H,\n fn: (\n entity: Reacted<T, H>,\n ctx: C,\n ) => F extends { kind: \"m2o\"; type: infer T extends Entity }\n ? MaybePromise<T | Reacted<T, {}> | undefined>\n : F extends EntityField\n ? MaybePromise<F[\"type\"] | undefined>\n : never,\n ): void;\n setDefault<K extends keyof SettableFields<FieldsOf<T>> & string>(fieldName: K, hintOrFnOrValue: any, fn?: any): void {\n this.ensurePreBoot(getCallerName(), \"setDefault\");\n if (fn) {\n // If we're called once by the codegen, and again by the user, override the syncDefault\n delete this.__data.syncDefaults[fieldName];\n this.__data.asyncDefaults[fieldName] = new AsyncDefault(fieldName, hintOrFnOrValue, fn);\n } else {\n this.__data.syncDefaults[fieldName] = hintOrFnOrValue;\n }\n }\n\n /**\n * A noop method that exists solely to keep the `config.placeholder()` line in the initial entity file,\n * until the user is ready to use it. */\n placeholder(): void {}\n\n /** Returns `fieldName`'s transition config, creating it on first use. */\n private fieldTransitions(fieldName: string): FieldTransitionsConfig<T, C> {\n return (this.__data.transitions[fieldName] ??= { guards: [], callbacks: [] });\n }\n\n /** Requires unique names across ordinary reactions and transition callbacks. */\n private ensureUniqueReactionName(name: string, op: string): void {\n if (this.__data.reactionNames.has(name)) {\n throw new Error(\n `Duplicate reaction name \"${name}\" in config.${op}. Pass a unique name when registering reactions from a shared helper or loop.`,\n );\n }\n this.__data.reactionNames.add(name);\n }\n\n private ensurePreBoot(name: string, op: string): void {\n if (booted) {\n // Detect if this is NextJS and we're in a hot-reload situation\n if (isRunningInNextJs()) {\n // Reset our bag of config data to collect only the new rules/hooks\n this.__data = new ConfigData();\n resetBootFlag();\n } else {\n throw new Error(\n `config.${op} call on ${name} must only be called on boot, before calling \\`configureMetadata\\`.`,\n );\n }\n }\n }\n}\n\nfunction isRunningInNextJs(): boolean {\n return \"__NEXT_HTTP_AGENT\" in globalThis || \"__NEXT_HTTPS_AGENT\" in globalThis;\n}\n\n/**\n * Allows projects to manually reset the internal `booted` flag.\n *\n * This is only necessary if they're using hot-reloading and reloading their entity files\n * without restarting the server.\n *\n * Generally most tools like tsx or ts-node-dev reload the whole process, so don't need\n * to call this, but if Joist is used in a framework that does actual-hot-reloading, this\n * it will be necessary.\n */\nexport function resetBootFlag(): void {\n booted = false;\n afterMetadataLocked = false;\n resetConstructorMap();\n}\n\n/**\n * Stores a path back to a reactive rule.\n *\n * I.e. if `Book` has a `ruleFn` that reacts to `Author.title`, then `Author`'s config will have\n * a `ReactiveRule` with fields `[\"title\"]`, path `books`, and rule `ruleFn`.\n */\nexport interface ReactiveRule {\n /** The source we're reacting to, specifically which base/subtype cstr. */\n source: MaybeAbstractEntityConstructor<any>;\n /** The fields on this source entity that would trigger the downstream rule's eval. */\n fields: string[];\n /** The constructor of downstream entity that owns the reactive rule. */\n cstr: MaybeAbstractEntityConstructor<any>;\n /** The name (source location) of the downstream reactive rule. */\n name: string;\n /** The path from this source entity to the downstream entity that needs evaled. */\n path: string[];\n /** The downstream validation rule to eval. */\n fn: ValidationRule<any>;\n}\n\n/**\n * Stores a path back to a reactive derived field.\n *\n * I.e. if `Book.displayName` is an `asyncField` that reacts to `Author.title`, then `Author`'s config will have\n * a `ReactiveFields` with fields `[\"title\"]`, path `books`, and name `displayName`.\n */\nexport interface ReactiveField {\n kind: \"populate\" | \"query\";\n /** The fields on this source entity that would trigger the downstream field's recalc. */\n fields: string[];\n /** Read-only/immutable fields that are used in the derived field. */\n isReadOnly: boolean;\n /** The constructor of downstream entity that owns the derived field. */\n cstr: MaybeAbstractEntityConstructor<any>;\n /** The path from this source entity to the downstream entity that needs recalced. */\n path: string[];\n /** The name of the reactive field in the downstream entity to recalc. */\n name: string;\n runOnce: false;\n}\n\nexport interface Reaction {\n kind: \"reaction\";\n /** The source we're reacting to, specifically which base/subtype cstr. */\n source: MaybeAbstractEntityConstructor<any>;\n /** The fields on this source entity that would trigger the downstream hook's eval. */\n fields: string[];\n /** Read-only/immutable fields that are used in the function. */\n isReadOnly: boolean;\n /** The constructor of downstream entity that owns the reaction. */\n cstr: MaybeAbstractEntityConstructor<any>;\n /** The name (source location) of the downstream reaction. */\n name: string;\n /** The path from this source entity to the downstream entity for this reaction. */\n path: string[];\n /** The downstream reaction function. */\n fn: HookFn<any, any>;\n /** If true, the reaction should only run once per flush, not every time the hint changes. */\n runOnce: boolean;\n}\n\nexport type Reactable = ReactiveField | Reaction;\n\ninterface ReactionInternal<T extends Entity, H extends ReactiveHint<T>, C> {\n name: string;\n fn: HookFn<T, C>;\n hint: H;\n runOnce: boolean;\n}\n\ntype AfterMetadataCallback<T extends Entity> = (meta: EntityMetadata<T>) => void;\n\n/** The internal state of an entity's configuration data, i.e. validation rules/hooks. */\nexport class ConfigData<T extends Entity, C> {\n afterMetadataCallbacks: AfterMetadataCallback<T>[] = [];\n runHooksBefore: EntityConstructor<any>[] = [];\n /** The validation rules for this entity type. */\n rules: ValidationRuleInternal<T>[] = [];\n /** The \"commit rules\" for this entity type, i.e. validation rules that run post-flush/pre-commit. */\n commitRules: ValidationRuleInternal<T>[] = [];\n /** The reactions for this entity type. */\n reactions: ReactionInternal<T, any, C>[] = [];\n /** Names shared by addReaction and addTransitionReaction, including commit-phase callbacks. */\n reactionNames: Set<string> = new Set();\n /**\n * Field name -> its `setTransitions`, `addTransitionRule`, and `addTransitionReaction` config, with\n * accessors not yet converted.\n *\n * The keys are also the fields whose factories accept `withX` opts.\n */\n transitions: Record<string, FieldTransitionsConfig<T, C>> = {};\n /** The hooks for this entity type. */\n hooks: Record<EntityHook, HookFn<T, C>[]> = {\n beforeDelete: [],\n beforeFlush: [],\n beforeCreate: [],\n beforeUpdate: [],\n afterValidation: [],\n beforeCommit: [],\n afterCommit: [],\n };\n /** Synchronous defaults for this entity type, invoked on `em.create`. */\n syncDefaults: Record<string, ((entity: T) => void) | unknown> = {};\n /** Asynchronous defaults for this entity type, invoked on `em.flush`. */\n asyncDefaults: Record<string, AsyncDefault<T>> = {};\n\n // An array of the reactive rules that depend on this entity\n reactiveRules: ReactiveRule[] = [];\n // An array of the reactive *commit* rules (post-flush/pre-commit) that depend on this entity\n reactiveCommitRules: ReactiveRule[] = [];\n // An array of the reactive fields and reactions that depend on this entity\n reactables: Reactable[] = [];\n cascadeDeleteFields: Array<keyof RelationsIn<T>> = [];\n touchOnChange: Set<keyof RelationsIn<T>> = new Set();\n // Constantly converting reactive hints to load hints is expense, so cache them here\n cachedReactiveLoadHints: Record<string, any> = {};\n /** Maps recursive collection fieldNames to custom cycle error message functions. */\n cycleMessages: Record<string, (entity: T, cyclePath: Entity[]) => string> = {};\n}\n\nexport function getCallerName(extraFrames: number = 0): string {\n const err = getStack();\n // E.g. at Object.<anonymous> (/home/stephen/homebound/graphql-service/src/entities/Activity.ts:86:8)\n // (Make sure to drop lines that don't start with 'at' b/c the stack format can differ\n // slightly i.e. if running via tsx/using a node loader (probably?)\n const line = err.stack!.split(\"\\n\").filter((line) => line.includes(\" at \"))[3 + extraFrames];\n const parts = line.split(\"/\");\n // Get the last part, which will be the file name, i.e. Activity.ts:86:8\n return parts[parts.length - 1].replace(/:\\d+\\)?$/, \"\");\n}\n\nexport function getFuzzyCallerName(\n // FactoryLogger wants the test line that called into the factories, i.e. newAuthor(em) at\n // SomeTest.test.ts:42, so passes true to skip the application's misc /factories/ internals\n // and find the first \"actually a test\" line.\n //\n // But otherwise other loggers like FieldLogger do want to see \"what exact line, even if it's\n // in a factory, is calling field.set\".\n ignoreFactoryFrames = false,\n): string {\n const err = getStack();\n const lines = err\n .stack!.split(\"\\n\")\n // E.g. at Object.<anonymous> (/home/stephen/homebound/graphql-service/src/entities/Activity.ts:86:8)\n .filter((line) => line.includes(\" at \"));\n const line = findUserCodeLine(lines, ignoreFactoryFrames);\n return getFilePath(line);\n}\n\n/**\n * Given a callstack line return the file name.\n *\n * I.e. `at Object.<anonymous> (/home/stephen/homebound/graphql-service/src/entities/Activity.ts:86:8)`\n */\nexport function getFilePath(line: string): string {\n const parts = line.split(\"/\");\n return parts[parts.length - 1].replace(/:\\d+\\)?$/, \"\"); // Drop the `:8)`at the end\n}\n\n/** Given a callstack, uses heuristics to find the first line that looks like user code. */\nexport function findUserCodeLine(lines: string[], ignoreFactoryFrames = false): string {\n return (\n lines.find((line) => {\n // When running Joist's own integration tests, if we ignore `/joist-orm/`, we'll end up ignoring\n // everything because `joist-orm` is the name of the repository/working copy itself.\n const withinWorkingCopyJoist = line.includes(\"/packages/orm/\") || line.includes(\"/packages/core\");\n // But once we're not in a working copy, assume any `/joist-orm/` in the path === internal orm stack frames\n const withinProductionJoist =\n !withinWorkingCopyJoist && (line.includes(\"/joist-orm/src/\") || line.includes(\"/joist-core/src\"));\n const nodeInternals = line.includes(\"node:internal/\") || line.includes(\"Promise.all\");\n const isUserCode = !withinWorkingCopyJoist && !withinProductionJoist && !nodeInternals;\n // const isRecalc = line.includes(\".recalcPending\");\n const isDefault = line.includes(\"/defaults.ts\");\n // Batched calls like findOrCreate won't have a stack trace back to the true caller, so just stop there\n const isDataloader = line.includes(\"/dataloaders/\");\n // If this is the `newTestInstance` call\n // What about:\n // recalcSynchronousDerivedFields\n // Jest's adapter is an implementation detail, not a meaningful source location.\n const isJestInternal = line.includes(\"jestAdapterInit.js\");\n const isFactoryHelper = line.includes(\"/factories/\");\n return (\n (isDefault || isDataloader || isUserCode) &&\n !line.includes(\"Codegen.ts\") &&\n !isJestInternal &&\n !(ignoreFactoryFrames && isFactoryHelper) &&\n // I wanted to exclude this, but it was actually our utils/entities.ts maybeSetDefault helper method\n // !line.includes(\"entities.ts\") &&\n // Ignore loops in joist code like setOpts\n !line.includes(\"at Array\") &&\n // Ignore the Author.ts constructor calling setOpts\n !line.includes(\"at new \")\n );\n }) ?? fail(\"Could not find caller name\")\n );\n}\n\nconst getStack: () => { stack?: string } = \"captureStackTrace\" in Error ? getStackFromCapture : getStackFromObject;\n\nfunction getStackFromCapture(): { stack?: string } {\n const obj = {};\n Error.captureStackTrace(obj);\n return obj as any;\n}\n\nfunction getStackFromObject(): { stack?: string } {\n try {\n throw Error(\"\");\n } catch (err) {\n return err as Error;\n }\n}\n\n/** Pushes a validation rule (either the raw or hinted/reactive form) onto `rules`, shared by `addRule`/`addCommitRule`. */\nfunction pushValidationRule<T extends Entity>(\n rules: ValidationRuleInternal<T>[],\n name: string,\n ruleOrHint: ValidationRule<T> | any,\n maybeRule: ValidationRule<any> | undefined,\n opts: AssertUnchangedOpts = {},\n): void {\n if (typeof ruleOrHint === \"function\") {\n rules.push({ name, fn: ruleOrHint, hint: undefined });\n } else {\n const hint = ruleOrHint;\n // Cache load hints per-meta because CTI subtypes may resolve `hint` to different\n // load hints (e.g. an AsyncProperty overridden in the subtype with subtype-only relations).\n const loadHints = new Map<EntityMetadata, LoadHint<T>>();\n async function fn(entity: T) {\n const meta = getMetadata(entity);\n let loadHint = loadHints.get(meta);\n if (loadHint === undefined) {\n loadHint = convertToLoadHint<T>(meta, hint);\n loadHints.set(meta, loadHint);\n }\n if (Object.keys(loadHint).length > 0) {\n await entity.em.populate(entity, loadHint);\n }\n if (opts.assertUnchanged) assertHintUnchanged(entity, loadHint);\n return maybeRule!(entity);\n }\n rules.push({ name, fn, hint });\n }\n}\n"],"mappings":";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;CAAU,CAAC;MAC/C;EACL,MAAM,OAAO;EAGb,MAAM,4BAAY,IAAI,IAAiC;EACvD,eAAe,GAAG,QAAW;GAC3B,MAAM,OAAOJ,uBAAAA,YAAY,MAAM;GAC/B,IAAI,WAAW,UAAU,IAAI,IAAI;GACjC,IAAI,aAAa,KAAA,GAAW;IAC1B,WAAWC,iCAAAA,kBAAqB,MAAM,IAAI;IAC1C,UAAU,IAAI,MAAM,QAAQ;GAC9B;GACA,IAAI,OAAO,KAAK,QAAQ,CAAC,CAAC,SAAS,GACjC,MAAM,OAAO,GAAG,SAAS,QAAQ,QAAQ;GAE3C,IAAI,KAAK,iBAAiB,wBAAA,oBAAoB,QAAQ,QAAQ;GAC9D,OAAO,UAAW,MAAM;EAC1B;EACA,MAAM,KAAK;GAAE;GAAM;GAAI;EAAK,CAAC;CAC/B;AACF"}
|
package/build/config.d.cts
CHANGED
|
@@ -351,7 +351,7 @@ export declare class ConfigData<T extends Entity, C> {
|
|
|
351
351
|
cycleMessages: Record<string, (entity: T, cyclePath: Entity[]) => string>;
|
|
352
352
|
}
|
|
353
353
|
export declare function getCallerName(extraFrames?: number): string;
|
|
354
|
-
export declare function getFuzzyCallerName(): string;
|
|
354
|
+
export declare function getFuzzyCallerName(ignoreFactoryFrames?: boolean): string;
|
|
355
355
|
/**
|
|
356
356
|
* Given a callstack line return the file name.
|
|
357
357
|
*
|
|
@@ -359,7 +359,7 @@ export declare function getFuzzyCallerName(): string;
|
|
|
359
359
|
*/
|
|
360
360
|
export declare function getFilePath(line: string): string;
|
|
361
361
|
/** Given a callstack, uses heuristics to find the first line that looks like user code. */
|
|
362
|
-
export declare function findUserCodeLine(lines: string[]): string;
|
|
362
|
+
export declare function findUserCodeLine(lines: string[], ignoreFactoryFrames?: boolean): string;
|
|
363
363
|
//#endregion
|
|
364
364
|
export {};
|
|
365
365
|
//# sourceMappingURL=config.d.cts.map
|
package/build/config.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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;EAEf,qBAAqB;EAErB,YAAY;EACZ,qBAAqB,YAAY,YAAY;EAC7C,eAAe,UAAU,YAAY;EAErC,yBAAyB;;EAEzB,eAAe,gBAAgB,QAAQ,GAAG,WAAW;;wBAGvC,cAAc;wBAWd,mBAOd;;;;;;wBAgBc,YAAY;;wBAMZ,iBAAiB,iBAAiB"}
|
package/build/config.d.mts
CHANGED
|
@@ -351,7 +351,7 @@ export declare class ConfigData<T extends Entity, C> {
|
|
|
351
351
|
cycleMessages: Record<string, (entity: T, cyclePath: Entity[]) => string>;
|
|
352
352
|
}
|
|
353
353
|
export declare function getCallerName(extraFrames?: number): string;
|
|
354
|
-
export declare function getFuzzyCallerName(): string;
|
|
354
|
+
export declare function getFuzzyCallerName(ignoreFactoryFrames?: boolean): string;
|
|
355
355
|
/**
|
|
356
356
|
* Given a callstack line return the file name.
|
|
357
357
|
*
|
|
@@ -359,7 +359,7 @@ export declare function getFuzzyCallerName(): string;
|
|
|
359
359
|
*/
|
|
360
360
|
export declare function getFilePath(line: string): string;
|
|
361
361
|
/** Given a callstack, uses heuristics to find the first line that looks like user code. */
|
|
362
|
-
export declare function findUserCodeLine(lines: string[]): string;
|
|
362
|
+
export declare function findUserCodeLine(lines: string[], ignoreFactoryFrames?: boolean): string;
|
|
363
363
|
//#endregion
|
|
364
364
|
export {};
|
|
365
365
|
//# sourceMappingURL=config.d.mts.map
|
package/build/config.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.mts","names":[],"sources":["../src/config.ts"],"mappings":";;;;;;;;;;;;;YA+BY;KAQP,OAAO,UAAU,QAAQ,MAAM,QAAQ,GAAG,KAAK,MAAM;KAErD;;EAEH;;KAEG,kBAAkB;EAAwB;EAAmB;;;YAGtD,kBAAkB,UAAU,QAAQ,MAC9C,QAAQ,GACR,YAAY,WAAW,OACpB,aAAa;;KAGb,aAAa,UAAU,QAAQ,GAAG,MAAM,QAAQ,GAAG,KAAK,GAAG,YAAY,WA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line) => line.includes(" at "))[3 + extraFrames].split("/");
|
|
293
293
|
return parts[parts.length - 1].replace(/:\d+\)?$/, "");
|
|
294
294
|
}
|
|
295
|
-
function getFuzzyCallerName() {
|
|
296
|
-
return getFilePath(findUserCodeLine(getStack().stack.split("\n").filter((line) => line.includes(" at "))));
|
|
295
|
+
function getFuzzyCallerName(ignoreFactoryFrames = false) {
|
|
296
|
+
return getFilePath(findUserCodeLine(getStack().stack.split("\n").filter((line) => line.includes(" at ")), ignoreFactoryFrames));
|
|
297
297
|
}
|
|
298
298
|
/**
|
|
299
299
|
* Given a callstack line return the file name.
|
|
@@ -305,7 +305,7 @@ function getFilePath(line) {
|
|
|
305
305
|
return parts[parts.length - 1].replace(/:\d+\)?$/, "");
|
|
306
306
|
}
|
|
307
307
|
/** Given a callstack, uses heuristics to find the first line that looks like user code. */
|
|
308
|
-
function findUserCodeLine(lines) {
|
|
308
|
+
function findUserCodeLine(lines, ignoreFactoryFrames = false) {
|
|
309
309
|
return lines.find((line) => {
|
|
310
310
|
const withinWorkingCopyJoist = line.includes("/packages/orm/") || line.includes("/packages/core");
|
|
311
311
|
const withinProductionJoist = !withinWorkingCopyJoist && (line.includes("/joist-orm/src/") || line.includes("/joist-core/src"));
|
|
@@ -313,7 +313,9 @@ function findUserCodeLine(lines) {
|
|
|
313
313
|
const isUserCode = !withinWorkingCopyJoist && !withinProductionJoist && !nodeInternals;
|
|
314
314
|
const isDefault = line.includes("/defaults.ts");
|
|
315
315
|
const isDataloader = line.includes("/dataloaders/");
|
|
316
|
-
|
|
316
|
+
const isJestInternal = line.includes("jestAdapterInit.js");
|
|
317
|
+
const isFactoryHelper = line.includes("/factories/");
|
|
318
|
+
return (isDefault || isDataloader || isUserCode) && !line.includes("Codegen.ts") && !isJestInternal && !(ignoreFactoryFrames && isFactoryHelper) && !line.includes("at Array") && !line.includes("at new ");
|
|
317
319
|
}) ?? fail("Could not find caller name");
|
|
318
320
|
}
|
|
319
321
|
const getStack = "captureStackTrace" in Error ? getStackFromCapture : getStackFromObject;
|
package/build/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","names":[],"sources":["../src/config.ts"],"sourcesContent":["import { resetConstructorMap } from \"src/configure.ts\";\nimport { AsyncDefault } from \"src/defaults.ts\";\nimport { type Entity } from \"src/Entity.ts\";\nimport { assertHintUnchanged } from \"src/flush/ReadDrift.ts\";\nimport {\n type EntityConstructor,\n type EntityField,\n type EntityMetadata,\n type FieldsOf,\n type LoadHint,\n type Loaded,\n type MaybeAbstractEntityConstructor,\n type Reacted,\n type ReactiveHint,\n type RelationsIn,\n type SettableFields,\n fail,\n getMetadata,\n} from \"src/index.ts\";\nimport { convertToLoadHint } from \"src/reactivity/reactiveHints.ts\";\nimport { type ValidationRule, type ValidationRuleInternal, type ValidationRuleResult } from \"src/rules.ts\";\nimport {\n type FieldTransitionsConfig,\n type GuardTransitionMatch,\n type OnTransitionMatch,\n type Transition,\n type TransitionTable,\n toTransition,\n} from \"src/transitions.ts\";\nimport { type MaybePromise } from \"src/utils.ts\";\n\nexport type EntityHook =\n | \"beforeFlush\"\n | \"beforeCreate\"\n | \"beforeUpdate\"\n | \"beforeDelete\"\n | \"afterValidation\"\n | \"beforeCommit\"\n | \"afterCommit\";\ntype HookFn<T extends Entity, C> = (entity: T, ctx: C) => MaybePromise<unknown>;\n\ntype AssertUnchangedOpts = {\n /** Protect reached rows at flush; does not protect collection membership or predicates. */\n assertUnchanged?: boolean;\n};\ntype AddReactionOpts = AssertUnchangedOpts & { runOnce?: boolean; name?: string };\n\n/** An `addTransitionRule` rule, which also gets the transition it is checking, since the entity may have moved on. */\nexport type TransitionGuardFn<T extends Entity, V> = (\n entity: T,\n transition: Transition<V>,\n) => MaybePromise<ValidationRuleResult>;\n\n/** An `addTransitionReaction` function, which also gets the transition it is handling, since the entity may have moved on. */\ntype TransitionFn<T extends Entity, C, V> = (entity: T, ctx: C, transition: Transition<V>) => MaybePromise<unknown>;\n\n/** The enum type of a transition field, i.e. `PublisherStatus`. */\ntype TransitionType<T extends Entity, K extends keyof FieldsOf<T>> = FieldsOf<T>[K] extends EntityField\n ? NonNullable<FieldsOf<T>[K][\"type\"]>\n : never;\n\n/**\n * The state names that `transitions` tables and `match`es accept for an enum field, i.e. `\"Draft\"` for\n * `PublisherStatus.Draft`.\n *\n * We only accept the enum's accessors, not its codes or members, so every table reads the same way.\n */\ntype TransitionStates<T extends Entity, K extends keyof FieldsOf<T>> = FieldsOf<T>[K] extends {\n accessors: infer A extends string;\n}\n ? A\n : never;\n\nexport const constraintNameToValidationError: Record<string, string> = {};\n\ntype Settable<T extends Entity> = keyof SettableFields<FieldsOf<T>> & string;\n\nlet booted = false;\nlet afterMetadataLocked = false;\n\n/**\n * Called at the end of `configureMetadata` to indicate the boot process is complete.\n *\n * We use this flag to prevent users from mistakenly calling `config` methods after the boot\n * process is complete, i.e. from hooks or other post-boot invocations, where the calls are\n * not guaranteed to work because Joist's reactivity graph has already been initialized.\n */\nexport function setBooted(): void {\n booted = true;\n}\n\nexport function setAfterMetadataLocked(): void {\n afterMetadataLocked = true;\n}\n\n/** The public API to configure an Entity's hooks & validation rules. */\nexport class ConfigApi<T extends Entity, C> {\n __data = new ConfigData<T, C>();\n\n /**\n * Maps a given `constraintName`, i.e. `authors_publisher_id_unique_index`, to a hard-coded-but-pretty validation errors.\n *\n * Note that the validationError must be hard-coded b/c we cannot tease out \"which entity\" caused a given\n * constraint failure from the SQL database. If you really need pretty-and-custom validation errors, you'll\n * need to check the constraint by hand ahead of time, before calling `em.flush`.\n */\n addConstraintMessage(constraintName: string, validationError: string) {\n this.ensurePreBoot(getCallerName(), \"addConstraintMessage\");\n constraintNameToValidationError[constraintName] = validationError;\n }\n\n /**\n * Maps a `RecursiveCycleError` on the given recursive collection field to a custom validation error.\n *\n * When a cycle is detected in a recursive collection (e.g. `parentsRecursive`), instead of\n * throwing a raw `RecursiveCycleError`, `em.flush` will convert it into a `ValidationErrors`\n * using the provided message function.\n *\n * The `messageFn` receives the entity that detected the cycle and the cycle path (array of\n * entities forming the cycle), and should return a validation error string.\n */\n addCycleRule(fieldName: string & keyof T, messageFn: (entity: T, cyclePath: Entity[]) => string) {\n this.ensurePreBoot(getCallerName(), \"addCycleRule\");\n this.__data.cycleMessages[fieldName] = messageFn;\n // Register a reactive rule that loads the recursive collection and catches cycle errors.\n // The rule uses the recursive collection's underlying relation as a reactive hint so it\n // triggers when the collection changes.\n const hint = fieldName as any;\n const fn = () => {\n // We don't actually need a try/catch/anything here, b/c if there is a cycle, it\n // will cause a CycleError during followReverseHint, and never even get to calling this fn.\n };\n this.__data.rules.push({ name: `addCycleRule(${getCallerName()})`, fn, hint });\n }\n\n /**\n * Adds a validation rule for this entity.\n *\n * If `hint` is passed, then the rule's lambda will be: 1) passed a view of the entity with only\n * the fields included in `hint` marked as accessible, and 2) the rule will be called reactively any\n * time any field in the `hint` changes.\n *\n * If lambdas want to access fields w/o having them marked for reactivity, the rule can either\n * include the field as readonly with a `:ro` suffix, i.e. `firstName:ro`, or the lambda can\n * access the `reacted.entity` property to get a full view of the entity's fields and methods.\n */\n addRule<H extends ReactiveHint<T>>(hint: H, rule: ValidationRule<Reacted<T, H>>): void;\n addRule<H extends ReactiveHint<T>>(opts: AssertUnchangedOpts, hint: H, rule: ValidationRule<Reacted<T, H>>): void;\n addRule(rule: ValidationRule<T>): void;\n addRule(\n ruleOrHint: ValidationRule<T> | any,\n hintOrRule?: ReactiveHint<T> | ValidationRule<any>,\n maybeRule?: ValidationRule<any>,\n ): void {\n // Keep the name for easy debugging/tracing later\n const name = `addRule(${getCallerName()})`;\n this.ensurePreBoot(name, \"addRule\");\n pushValidationRule(\n this.__data.rules,\n name,\n maybeRule ? hintOrRule : ruleOrHint,\n maybeRule ?? (hintOrRule as ValidationRule<any> | undefined),\n maybeRule ? ruleOrHint : {},\n );\n }\n\n /**\n * Adds a \"commit rule\" that runs like a regular validation rule (see {@link addRule}), but *after*\n * the entity's `INSERT`/`UPDATE`/`DELETE` has been flushed to the database and *before* the\n * transaction `COMMIT`s, i.e. still within the transaction.\n *\n * The point of running this late is that any `em.find`s the rule makes will query the _changed_\n * state (the just-flushed rows), instead of the pre-flush state that regular `addRule` rules see.\n * This is useful for cross-row invariants that are easiest to express as a query, e.g. \"at most\n * one active `AuthorSchedule` per author\", where the rule wants to `em.find` the sibling rows\n * that were themselves just inserted/updated in this same flush.\n *\n * Like `addRule`, if a `hint` is passed the rule is reactive: it runs whenever any field in the\n * hint changes (walking back to the owning entity), and the lambda gets a `Reacted` view.\n */\n addCommitRule<H extends ReactiveHint<T>>(hint: H, rule: ValidationRule<Reacted<T, H>>): void;\n addCommitRule<H extends ReactiveHint<T>>(\n opts: AssertUnchangedOpts,\n hint: H,\n rule: ValidationRule<Reacted<T, H>>,\n ): void;\n addCommitRule(rule: ValidationRule<T>): void;\n addCommitRule(\n ruleOrHint: ValidationRule<T> | any,\n hintOrRule?: ReactiveHint<T> | ValidationRule<any>,\n maybeRule?: ValidationRule<any>,\n ): void {\n // Keep the name for easy debugging/tracing later\n const name = `addCommitRule(${getCallerName()})`;\n this.ensurePreBoot(name, \"addCommitRule\");\n pushValidationRule(\n this.__data.commitRules,\n name,\n maybeRule ? hintOrRule : ruleOrHint,\n maybeRule ?? (hintOrRule as ValidationRule<any> | undefined),\n maybeRule ? ruleOrHint : {},\n );\n }\n\n /** If both this entity, and `cstr` entities, are in the same `em.flush`, run us first. */\n runHooksBefore(cstr: EntityConstructor<any>): void {\n this.__data.runHooksBefore.push(cstr);\n }\n\n /** Deletes any entity/entities pointed to by `relation` when this entity is deleted. */\n cascadeDelete(relation: keyof RelationsIn<T> & LoadHint<T>): void {\n this.ensurePreBoot(getCallerName(), \"cascadeDelete\");\n this.__data.cascadeDeleteFields.push(relation);\n }\n\n touchOnChange(relation: keyof RelationsIn<T>): void {\n this.ensurePreBoot(getCallerName(), \"touchOnChange\");\n this.__data.touchOnChange.add(relation);\n }\n\n private addHook(hook: EntityHook, ruleOrHint: HookFn<T, C> | any, maybeFn?: HookFn<Loaded<T, any>, C>) {\n this.ensurePreBoot(getCallerName(), \"addHook\");\n if (typeof ruleOrHint === \"function\") {\n this.__data.hooks[hook].push(ruleOrHint);\n } else {\n const fn = async (entity: T, ctx: C) => {\n // TODO Use this for reactive beforeFlush\n const loaded = await entity.em.populate(entity, ruleOrHint);\n return maybeFn!(loaded, ctx);\n };\n // Squirrel our hint away where configureMetadata can find it\n (fn as any).hint = ruleOrHint;\n this.__data.hooks[hook].push(fn);\n }\n }\n\n afterMetadata(fn: AfterMetadataCallback<T>): void {\n if (afterMetadataLocked) {\n throw new Error(\n `config.afterMetadata on ${getCallerName()} must only be called on boot, before calling \\`configureMetadata\\` and not from other \\`afterMetadata\\` hooks.`,\n );\n }\n this.__data.afterMetadataCallbacks.push(fn);\n }\n\n beforeDelete<H extends LoadHint<T>>(populate: H, fn: HookFn<Loaded<T, H>, C>): void;\n beforeDelete(fn: HookFn<T, C>): void;\n beforeDelete(ruleOrHint: HookFn<T, C> | any, maybeFn?: HookFn<Loaded<T, any>, C>): void {\n this.addHook(\"beforeDelete\", ruleOrHint, maybeFn);\n }\n\n beforeFlush<H extends LoadHint<T>>(populate: H, fn: HookFn<Loaded<T, H>, C>): void;\n beforeFlush(fn: HookFn<T, C>): void;\n beforeFlush(ruleOrHint: HookFn<T, C> | any, maybeFn?: HookFn<Loaded<T, any>, C>): void {\n this.addHook(\"beforeFlush\", ruleOrHint, maybeFn);\n }\n\n // beforeCreate still needs to take a hint because even though the entity itself is New<T>, we might want to load\n // a nested relation that isn't loaded yet\n beforeCreate<H extends LoadHint<T>>(populate: H, fn: HookFn<Loaded<T, H>, C>): void;\n beforeCreate(fn: HookFn<T, C>): void;\n beforeCreate(ruleOrHint: HookFn<T, C> | any, maybeFn?: HookFn<Loaded<T, any>, C>): void {\n this.addHook(\"beforeCreate\", ruleOrHint, maybeFn);\n }\n\n beforeUpdate<H extends LoadHint<T>>(populate: H, fn: HookFn<Loaded<T, H>, C>): void;\n beforeUpdate(fn: HookFn<T, C>): void;\n beforeUpdate(ruleOrHint: HookFn<T, C> | any, maybeFn?: HookFn<Loaded<T, any>, C>): void {\n this.addHook(\"beforeUpdate\", ruleOrHint, maybeFn);\n }\n\n afterValidation<H extends LoadHint<T>>(populate: H, fn: HookFn<Loaded<T, H>, C>): void;\n afterValidation(fn: HookFn<T, C>): void;\n afterValidation(ruleOrHint: HookFn<T, C> | any, maybeFn?: HookFn<Loaded<T, any>, C>): void {\n this.addHook(\"afterValidation\", ruleOrHint, maybeFn);\n }\n\n beforeCommit(fn: HookFn<T, C>): void {\n this.addHook(\"beforeCommit\", fn);\n }\n\n afterCommit(fn: HookFn<T, C>): void {\n this.addHook(\"afterCommit\", fn);\n }\n\n /**\n * Adds a reaction that runs during flush whenever fields in the `hint` change.\n *\n * Reactions are somewhere in between hooks and reactive fields/references:\n * 1. Can make arbitrary changes to any entity like a hook\n * 2. Only run when the provided hint has changes, not on every flush, like an RF/RR\n * 3. Run when the entity itself has no changes, like an RF/RF\n * 4. Can run multiple times per flush, like an RF/RF. Be careful to avoid creating\n * circular dependencies in the hint and to make the function idempotent.\n *\n * Names default to the registration's source location. Pass unique names when registering multiple\n * reactions from a shared helper or loop; duplicate names on the same config are rejected.\n *\n * @param hint The fields to watch for changes and load before running the reaction\n * @param fn The reaction function to run\n */\n addReaction<H extends ReactiveHint<T>>(hint: H, fn: HookFn<Loaded<T, H>, C>): void;\n /**\n * Adds a named reaction that runs during flush whenever fields in the `hint` change.\n *\n * Reactions are somewhere in between hooks and reactive fields/references:\n * 1. Can make arbitrary changes to any entity like a hook\n * 2. Only run when `hint` has changes, not on every flush, like an RF/RR\n * 3. Can run when the entity itself has no changes, like an RF/RF\n * 4. Can run multiple times per flush, like an RF/RF. Be careful to avoid creating\n * circular dependencies in the hint and to make the function idempotent.\n *\n * @param name A name to identify this reaction for debugging\n * @param hint The fields to watch for changes and load before running the reaction\n * @param fn The reaction function to run\n */\n addReaction<H extends ReactiveHint<T>>(name: string, hint: H, fn: HookFn<Loaded<T, H>, C>): void;\n /**\n * Adds a reaction that runs during flush whenever fields in the `hint` change.\n *\n * Reactions are somewhere in between hooks and reactive fields/references:\n * 1. Can make arbitrary changes to any entity like a hook\n * 2. Only run when `hint` has changes, not on every flush, like an RF/RR\n * 3. Can run when the entity itself has no changes, like an RF/RF\n * 4. Can run multiple times per flush, like an RF/RF. Be careful to avoid creating\n * circular dependencies in the hint and to make the function idempotent.\n *\n * @param opts Options object containing:\n * - runOnce - If true, the reaction will only run once per flush, not every time the hint changes. Optional.\n * default: false.\n * - name - A name to identify this reaction for debugging\n * @param hint The fields to watch for changes and load before running the reaction\n * @param fn The reaction function to run\n */\n addReaction<H extends ReactiveHint<T>>(opts: AddReactionOpts, hint: H, fn: HookFn<Loaded<T, H>, C>): void;\n addReaction<H extends ReactiveHint<T>>(\n nameOrOptsOrHint: string | AddReactionOpts | H,\n hintOrFn: H | HookFn<Loaded<T, H>, C>,\n maybeFn?: HookFn<Loaded<T, H>, C>,\n ): void {\n // Keep the name so we can uniquely identify this reaction later and also aid debugging/tracing\n const fn = maybeFn ?? (hintOrFn as HookFn<Loaded<T, H>, C>);\n const hint = (maybeFn ? hintOrFn : nameOrOptsOrHint) as H;\n const opts = maybeFn\n ? typeof nameOrOptsOrHint === \"string\"\n ? { name: nameOrOptsOrHint }\n : (nameOrOptsOrHint as AddReactionOpts)\n : {};\n const { name = getCallerName(), runOnce = false } = opts;\n this.ensurePreBoot(name, \"addReaction\");\n this.ensureUniqueReactionName(name, \"addReaction\");\n // Cache load hints per-meta because CTI subtypes may resolve `hint` to different\n // load hints (e.g. an AsyncProperty overridden in the subtype with subtype-only relations).\n const loadHints = new Map<EntityMetadata, LoadHint<T>>();\n async function wrappedFn(entity: T, ctx: C) {\n const meta = getMetadata(entity);\n let loadHint = loadHints.get(meta);\n if (loadHint === undefined) {\n loadHint = convertToLoadHint<T>(meta, hint);\n loadHints.set(meta, loadHint);\n }\n if (Object.keys(loadHint).length > 0) {\n await entity.em.populate(entity, loadHint);\n }\n if (opts.assertUnchanged) assertHintUnchanged(entity, loadHint);\n return fn(entity as Loaded<T, H>, ctx);\n }\n this.__data.reactions.push({ name, fn: wrappedFn, hint, runOnce });\n }\n\n /**\n * Declares which state transitions of the enum `fieldName` are allowed, i.e. `{ Draft: [\"Open\"], Open: [\"Closed\"] }`.\n *\n * Keys and values are the enum's accessors as strings, i.e. `\"Draft\"` for `AuthorStatus.Draft`.\n *\n * A state that is missing from the table, or maps to `[]`, is treated as a terminal state & cannot be\n * changed. Creating an entity is not a transition, so a new entity may start in any state.\n *\n * The table is checked by the field's setter, so a disallowed transition throws a `ValidationErrors`\n * immediately, instead of failing the next `em.flush`.\n */\n setTransitions<K extends Settable<T>>(fieldName: K, table: TransitionTable<TransitionStates<T, K>>): void {\n const name = `setTransitions(${getCallerName()})`;\n this.ensurePreBoot(name, \"setTransitions\");\n const config = this.fieldTransitions(fieldName);\n // Subtypes add their own tables on their own configs, so a 2nd table on this config is a mistake\n if (config.table) fail(`config.setTransitions was already called for ${fieldName}, use one table per field`);\n // Accessors are converted to codes after boot, see `buildFieldTransitions`\n config.table = table;\n }\n\n /**\n * Checks each matching transition before its callbacks run, and rejects it if the guard returns an error.\n *\n * Use this for \"a transition is allowed only when ...\" checks that depend on other data, while\n * `setTransitions` declares the transitions that are possible at all. The `hint` is a load hint, like\n * `beforeFlush`'s, so it's loaded before `rule` runs, but only `fieldName` itself triggers the guard.\n *\n * Guards run with reactions, for every matching transition, even if the\n * field has moved on since. The entity is in its current state, so `rule` also gets the `transition`\n * it is checking. Guards never run on creation and are not rechecked during final validation.\n */\n addTransitionRule<K extends Settable<T>, H extends LoadHint<T>>(\n fieldName: K,\n match: GuardTransitionMatch<TransitionStates<T, K>>,\n hint: H,\n rule: TransitionGuardFn<Loaded<T, H>, TransitionType<T, K>>,\n ): void;\n addTransitionRule<K extends Settable<T>>(\n fieldName: K,\n match: GuardTransitionMatch<TransitionStates<T, K>>,\n rule: TransitionGuardFn<T, TransitionType<T, K>>,\n ): void;\n addTransitionRule(fieldName: string, match: GuardTransitionMatch<any>, hintOrRule: any, maybeRule?: any): void {\n const name = `addTransitionRule(${getCallerName()})`;\n this.ensurePreBoot(name, \"addTransitionRule\");\n const rule: TransitionGuardFn<T, any> = maybeRule ?? hintOrRule;\n const hint: LoadHint<T> | undefined = maybeRule ? hintOrRule : undefined;\n // The dispatcher evaluates matching guards once before invoking any callbacks for the transition.\n this.fieldTransitions(fieldName).guards.push({\n match,\n run(entity, step) {\n const transition = toTransition(step);\n return hint === undefined\n ? rule(entity, transition)\n : entity.em.populate(entity, hint).then((loaded) => rule(loaded, transition));\n },\n });\n }\n\n /**\n * Runs `fn` for each state transition of `fieldName` that matches `match`.\n *\n * This runs alongside reactions (see `addReaction`), but only state changes queue callbacks.\n * The `hint` is a load hint, like `beforeFlush`'s, so it is loaded but not reacted to.\n *\n * Callbacks run with reactions, once for every matching transition, in order,\n * even if the field has moved on since. The entity is in its current state, so `fn` also gets the\n * `transition` it is handling. Transitions that an `addTransitionRule` rejects don't fire.\n *\n * Creating an entity with a matching `to` state fires too, unless `match.from` is set or\n * `match.onCreate` is `false`. Set `match.phase: \"commit\"` to run in `beforeCommit` instead, i.e.\n * for enqueueing jobs.\n *\n * Callbacks that read a new entity's `id` should use `match.phase: \"commit\"`. Other callbacks may run\n * before ids are assigned, and Joist does not rerun them on a `NoIdError` because their side effects\n * could repeat.\n *\n * Pass a unique name as the first argument when registering multiple callbacks from a shared\n * helper or loop. Duplicate names on the same config are rejected when registered.\n */\n addTransitionReaction<K extends Settable<T>, H extends LoadHint<T>>(\n fieldName: K,\n match: OnTransitionMatch<TransitionStates<T, K>>,\n hint: H,\n fn: TransitionFn<Loaded<T, H>, C, TransitionType<T, K>>,\n ): void;\n addTransitionReaction<K extends Settable<T>>(\n fieldName: K,\n match: OnTransitionMatch<TransitionStates<T, K>>,\n fn: TransitionFn<T, C, TransitionType<T, K>>,\n ): void;\n addTransitionReaction<K extends Settable<T>, H extends LoadHint<T>>(\n name: string,\n fieldName: K,\n match: OnTransitionMatch<TransitionStates<T, K>>,\n hint: H,\n fn: TransitionFn<Loaded<T, H>, C, TransitionType<T, K>>,\n ): void;\n addTransitionReaction<K extends Settable<T>>(\n name: string,\n fieldName: K,\n match: OnTransitionMatch<TransitionStates<T, K>>,\n fn: TransitionFn<T, C, TransitionType<T, K>>,\n ): void;\n addTransitionReaction(\n nameOrFieldName: string,\n fieldNameOrMatch: string | OnTransitionMatch<any>,\n matchOrHintOrFn: any,\n hintOrFn?: any,\n maybeFn?: any,\n ): void {\n const named = typeof fieldNameOrMatch === \"string\";\n const name = named ? nameOrFieldName : `addTransitionReaction(${getCallerName()})`;\n this.ensurePreBoot(name, \"addTransitionReaction\");\n this.ensureUniqueReactionName(name, \"addTransitionReaction\");\n\n // Resolve the overloads\n const fieldName = named ? fieldNameOrMatch : nameOrFieldName;\n const match: OnTransitionMatch<any> = named ? matchOrHintOrFn : fieldNameOrMatch;\n const hintOrCallback = named ? hintOrFn : matchOrHintOrFn;\n const callback = named ? maybeFn : hintOrFn;\n const fn: TransitionFn<T, C, any> = callback ?? hintOrCallback;\n const hint: LoadHint<T> | undefined = callback ? hintOrCallback : undefined;\n\n // Transition queues trigger callbacks; hinted data is only loaded, not watched for changes.\n this.fieldTransitions(fieldName).callbacks.push({\n name,\n match,\n run(entity, ctx, step) {\n const transition = toTransition(step);\n return hint === undefined\n ? fn(entity, ctx, transition)\n : entity.em.populate(entity, hint).then((loaded) => fn(loaded, ctx, transition));\n },\n });\n }\n\n /** Adds a synchronous default for `fieldName` to a hard-coded `value`. */\n setDefault<K extends Settable<T>, F = FieldsOf<T>[K]>(\n fieldName: K,\n // Allow returning undefined to mean \"no default\"\n value: F extends EntityField ? F[\"type\"] : never,\n ): void;\n /** Adds a synchronous default for `fieldName` to the result of simple sync lambda. */\n setDefault<K extends Settable<T>, F = FieldsOf<T>[K]>(\n fieldName: K,\n // ...this doesn't technically declare what other fields of `entity` we depend on,\n // which ideally we want to drive \"which default to set first?\" precedence decisions.\n fn: (entity: T) => F extends EntityField ? F[\"type\"] | undefined : never,\n ): void;\n /** Adds an asynchronous default for `fieldName` to the result of a hinted lambda. */\n setDefault<K extends Settable<T>, const H extends ReactiveHint<T>, F = FieldsOf<T>[K]>(\n fieldName: K,\n // We use a ReactiveHint so that we get field-level dependencies that means someday\n // we could drive \"which default to set first?\" precedence decisions.\n hint: H,\n fn: (\n entity: Reacted<T, H>,\n ctx: C,\n ) => F extends { kind: \"m2o\"; type: infer T extends Entity }\n ? MaybePromise<T | Reacted<T, {}> | undefined>\n : F extends EntityField\n ? MaybePromise<F[\"type\"] | undefined>\n : never,\n ): void;\n setDefault<K extends keyof SettableFields<FieldsOf<T>> & string>(fieldName: K, hintOrFnOrValue: any, fn?: any): void {\n this.ensurePreBoot(getCallerName(), \"setDefault\");\n if (fn) {\n // If we're called once by the codegen, and again by the user, override the syncDefault\n delete this.__data.syncDefaults[fieldName];\n this.__data.asyncDefaults[fieldName] = new AsyncDefault(fieldName, hintOrFnOrValue, fn);\n } else {\n this.__data.syncDefaults[fieldName] = hintOrFnOrValue;\n }\n }\n\n /**\n * A noop method that exists solely to keep the `config.placeholder()` line in the initial entity file,\n * until the user is ready to use it. */\n placeholder(): void {}\n\n /** Returns `fieldName`'s transition config, creating it on first use. */\n private fieldTransitions(fieldName: string): FieldTransitionsConfig<T, C> {\n return (this.__data.transitions[fieldName] ??= { guards: [], callbacks: [] });\n }\n\n /** Requires unique names across ordinary reactions and transition callbacks. */\n private ensureUniqueReactionName(name: string, op: string): void {\n if (this.__data.reactionNames.has(name)) {\n throw new Error(\n `Duplicate reaction name \"${name}\" in config.${op}. Pass a unique name when registering reactions from a shared helper or loop.`,\n );\n }\n this.__data.reactionNames.add(name);\n }\n\n private ensurePreBoot(name: string, op: string): void {\n if (booted) {\n // Detect if this is NextJS and we're in a hot-reload situation\n if (isRunningInNextJs()) {\n // Reset our bag of config data to collect only the new rules/hooks\n this.__data = new ConfigData();\n resetBootFlag();\n } else {\n throw new Error(\n `config.${op} call on ${name} must only be called on boot, before calling \\`configureMetadata\\`.`,\n );\n }\n }\n }\n}\n\nfunction isRunningInNextJs(): boolean {\n return \"__NEXT_HTTP_AGENT\" in globalThis || \"__NEXT_HTTPS_AGENT\" in globalThis;\n}\n\n/**\n * Allows projects to manually reset the internal `booted` flag.\n *\n * This is only necessary if they're using hot-reloading and reloading their entity files\n * without restarting the server.\n *\n * Generally most tools like tsx or ts-node-dev reload the whole process, so don't need\n * to call this, but if Joist is used in a framework that does actual-hot-reloading, this\n * it will be necessary.\n */\nexport function resetBootFlag(): void {\n booted = false;\n afterMetadataLocked = false;\n resetConstructorMap();\n}\n\n/**\n * Stores a path back to a reactive rule.\n *\n * I.e. if `Book` has a `ruleFn` that reacts to `Author.title`, then `Author`'s config will have\n * a `ReactiveRule` with fields `[\"title\"]`, path `books`, and rule `ruleFn`.\n */\nexport interface ReactiveRule {\n /** The source we're reacting to, specifically which base/subtype cstr. */\n source: MaybeAbstractEntityConstructor<any>;\n /** The fields on this source entity that would trigger the downstream rule's eval. */\n fields: string[];\n /** The constructor of downstream entity that owns the reactive rule. */\n cstr: MaybeAbstractEntityConstructor<any>;\n /** The name (source location) of the downstream reactive rule. */\n name: string;\n /** The path from this source entity to the downstream entity that needs evaled. */\n path: string[];\n /** The downstream validation rule to eval. */\n fn: ValidationRule<any>;\n}\n\n/**\n * Stores a path back to a reactive derived field.\n *\n * I.e. if `Book.displayName` is an `asyncField` that reacts to `Author.title`, then `Author`'s config will have\n * a `ReactiveFields` with fields `[\"title\"]`, path `books`, and name `displayName`.\n */\nexport interface ReactiveField {\n kind: \"populate\" | \"query\";\n /** The fields on this source entity that would trigger the downstream field's recalc. */\n fields: string[];\n /** Read-only/immutable fields that are used in the derived field. */\n isReadOnly: boolean;\n /** The constructor of downstream entity that owns the derived field. */\n cstr: MaybeAbstractEntityConstructor<any>;\n /** The path from this source entity to the downstream entity that needs recalced. */\n path: string[];\n /** The name of the reactive field in the downstream entity to recalc. */\n name: string;\n runOnce: false;\n}\n\nexport interface Reaction {\n kind: \"reaction\";\n /** The source we're reacting to, specifically which base/subtype cstr. */\n source: MaybeAbstractEntityConstructor<any>;\n /** The fields on this source entity that would trigger the downstream hook's eval. */\n fields: string[];\n /** Read-only/immutable fields that are used in the function. */\n isReadOnly: boolean;\n /** The constructor of downstream entity that owns the reaction. */\n cstr: MaybeAbstractEntityConstructor<any>;\n /** The name (source location) of the downstream reaction. */\n name: string;\n /** The path from this source entity to the downstream entity for this reaction. */\n path: string[];\n /** The downstream reaction function. */\n fn: HookFn<any, any>;\n /** If true, the reaction should only run once per flush, not every time the hint changes. */\n runOnce: boolean;\n}\n\nexport type Reactable = ReactiveField | Reaction;\n\ninterface ReactionInternal<T extends Entity, H extends ReactiveHint<T>, C> {\n name: string;\n fn: HookFn<T, C>;\n hint: H;\n runOnce: boolean;\n}\n\ntype AfterMetadataCallback<T extends Entity> = (meta: EntityMetadata<T>) => void;\n\n/** The internal state of an entity's configuration data, i.e. validation rules/hooks. */\nexport class ConfigData<T extends Entity, C> {\n afterMetadataCallbacks: AfterMetadataCallback<T>[] = [];\n runHooksBefore: EntityConstructor<any>[] = [];\n /** The validation rules for this entity type. */\n rules: ValidationRuleInternal<T>[] = [];\n /** The \"commit rules\" for this entity type, i.e. validation rules that run post-flush/pre-commit. */\n commitRules: ValidationRuleInternal<T>[] = [];\n /** The reactions for this entity type. */\n reactions: ReactionInternal<T, any, C>[] = [];\n /** Names shared by addReaction and addTransitionReaction, including commit-phase callbacks. */\n reactionNames: Set<string> = new Set();\n /**\n * Field name -> its `setTransitions`, `addTransitionRule`, and `addTransitionReaction` config, with\n * accessors not yet converted.\n *\n * The keys are also the fields whose factories accept `withX` opts.\n */\n transitions: Record<string, FieldTransitionsConfig<T, C>> = {};\n /** The hooks for this entity type. */\n hooks: Record<EntityHook, HookFn<T, C>[]> = {\n beforeDelete: [],\n beforeFlush: [],\n beforeCreate: [],\n beforeUpdate: [],\n afterValidation: [],\n beforeCommit: [],\n afterCommit: [],\n };\n /** Synchronous defaults for this entity type, invoked on `em.create`. */\n syncDefaults: Record<string, ((entity: T) => void) | unknown> = {};\n /** Asynchronous defaults for this entity type, invoked on `em.flush`. */\n asyncDefaults: Record<string, AsyncDefault<T>> = {};\n\n // An array of the reactive rules that depend on this entity\n reactiveRules: ReactiveRule[] = [];\n // An array of the reactive *commit* rules (post-flush/pre-commit) that depend on this entity\n reactiveCommitRules: ReactiveRule[] = [];\n // An array of the reactive fields and reactions that depend on this entity\n reactables: Reactable[] = [];\n cascadeDeleteFields: Array<keyof RelationsIn<T>> = [];\n touchOnChange: Set<keyof RelationsIn<T>> = new Set();\n // Constantly converting reactive hints to load hints is expense, so cache them here\n cachedReactiveLoadHints: Record<string, any> = {};\n /** Maps recursive collection fieldNames to custom cycle error message functions. */\n cycleMessages: Record<string, (entity: T, cyclePath: Entity[]) => string> = {};\n}\n\nexport function getCallerName(extraFrames: number = 0): string {\n const err = getStack();\n // E.g. at Object.<anonymous> (/home/stephen/homebound/graphql-service/src/entities/Activity.ts:86:8)\n // (Make sure to drop lines that don't start with 'at' b/c the stack format can differ\n // slightly i.e. if running via tsx/using a node loader (probably?)\n const line = err.stack!.split(\"\\n\").filter((line) => line.includes(\" at \"))[3 + extraFrames];\n const parts = line.split(\"/\");\n // Get the last part, which will be the file name, i.e. Activity.ts:86:8\n return parts[parts.length - 1].replace(/:\\d+\\)?$/, \"\");\n}\n\nexport function getFuzzyCallerName(): string {\n const err = getStack();\n const lines = err\n .stack!.split(\"\\n\")\n // E.g. at Object.<anonymous> (/home/stephen/homebound/graphql-service/src/entities/Activity.ts:86:8)\n .filter((line) => line.includes(\" at \"));\n const line = findUserCodeLine(lines);\n return getFilePath(line);\n}\n\n/**\n * Given a callstack line return the file name.\n *\n * I.e. `at Object.<anonymous> (/home/stephen/homebound/graphql-service/src/entities/Activity.ts:86:8)`\n */\nexport function getFilePath(line: string): string {\n const parts = line.split(\"/\");\n return parts[parts.length - 1].replace(/:\\d+\\)?$/, \"\"); // Drop the `:8)`at the end\n}\n\n/** Given a callstack, uses heuristics to find the first line that looks like user code. */\nexport function findUserCodeLine(lines: string[]): string {\n return (\n lines.find((line) => {\n // When running Joist's own integration tests, if we ignore `/joist-orm/`, we'll end up ignoring\n // everything because `joist-orm` is the name of the repository/working copy itself.\n const withinWorkingCopyJoist = line.includes(\"/packages/orm/\") || line.includes(\"/packages/core\");\n // But once we're not in a working copy, assume any `/joist-orm/` in the path === internal orm stack frames\n const withinProductionJoist =\n !withinWorkingCopyJoist && (line.includes(\"/joist-orm/src/\") || line.includes(\"/joist-core/src\"));\n const nodeInternals = line.includes(\"node:internal/\") || line.includes(\"Promise.all\");\n const isUserCode = !withinWorkingCopyJoist && !withinProductionJoist && !nodeInternals;\n // const isRecalc = line.includes(\".recalcPending\");\n const isDefault = line.includes(\"/defaults.ts\");\n // Batched calls like findOrCreate won't have a stack trace back to the true caller, so just stop there\n const isDataloader = line.includes(\"/dataloaders/\");\n // If this is the `newTestInstance` call\n // What about:\n // recalcSynchronousDerivedFields\n return (\n (isDefault || isDataloader || isUserCode) &&\n !line.includes(\"Codegen.ts\") &&\n // I wanted to exclude this, but it was actually our utils/entities.ts maybeSetDefault helper method\n // !line.includes(\"entities.ts\") &&\n // Ignore loops in joist code like setOpts\n !line.includes(\"at Array\") &&\n // Ignore the Author.ts constructor calling setOpts\n !line.includes(\"at new \")\n );\n }) ?? fail(\"Could not find caller name\")\n );\n}\n\nconst getStack: () => { stack?: string } = \"captureStackTrace\" in Error ? getStackFromCapture : getStackFromObject;\n\nfunction getStackFromCapture(): { stack?: string } {\n const obj = {};\n Error.captureStackTrace(obj);\n return obj as any;\n}\n\nfunction getStackFromObject(): { stack?: string } {\n try {\n throw Error(\"\");\n } catch (err) {\n return err as Error;\n }\n}\n\n/** Pushes a validation rule (either the raw or hinted/reactive form) onto `rules`, shared by `addRule`/`addCommitRule`. */\nfunction pushValidationRule<T extends Entity>(\n rules: ValidationRuleInternal<T>[],\n name: string,\n ruleOrHint: ValidationRule<T> | any,\n maybeRule: ValidationRule<any> | undefined,\n opts: AssertUnchangedOpts = {},\n): void {\n if (typeof ruleOrHint === \"function\") {\n rules.push({ name, fn: ruleOrHint, hint: undefined });\n } else {\n const hint = ruleOrHint;\n // Cache load hints per-meta because CTI subtypes may resolve `hint` to different\n // load hints (e.g. an AsyncProperty overridden in the subtype with subtype-only relations).\n const loadHints = new Map<EntityMetadata, LoadHint<T>>();\n async function fn(entity: T) {\n const meta = getMetadata(entity);\n let loadHint = loadHints.get(meta);\n if (loadHint === undefined) {\n loadHint = convertToLoadHint<T>(meta, hint);\n loadHints.set(meta, loadHint);\n }\n if (Object.keys(loadHint).length > 0) {\n await entity.em.populate(entity, loadHint);\n }\n if (opts.assertUnchanged) assertHintUnchanged(entity, loadHint);\n return maybeRule!(entity);\n }\n rules.push({ name, fn, hint });\n }\n}\n"],"mappings":";;;;;;;;;;;AAyEA,MAAa,kCAA0D,CAAC;AAIxE,IAAI,SAAS;AACb,IAAI,sBAAsB;;;;;;;;AAS1B,SAAgB,YAAkB;CAChC,SAAS;AACX;AAEA,SAAgB,yBAA+B;CAC7C,sBAAsB;AACxB;;AAGA,IAAa,YAAb,MAA4C;CAC1C,SAAS,IAAI,WAAiB;;;;;;;;CAS9B,qBAAqB,gBAAwB,iBAAyB;EACpE,KAAK,cAAc,cAAc,GAAG,sBAAsB;EAC1D,gCAAgC,kBAAkB;CACpD;;;;;;;;;;;CAYA,aAAa,WAA6B,WAAuD;EAC/F,KAAK,cAAc,cAAc,GAAG,cAAc;EAClD,KAAK,OAAO,cAAc,aAAa;EAIvC,MAAM,OAAO;EACb,MAAM,WAAW,CAGjB;EACA,KAAK,OAAO,MAAM,KAAK;GAAE,MAAM,gBAAgB,cAAc,EAAE;GAAI;GAAI;EAAK,CAAC;CAC/E;CAgBA,QACE,YACA,YACA,WACM;EAEN,MAAM,OAAO,WAAW,cAAc,EAAE;EACxC,K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E3C;AAEA,MAAM,WAAqC,uBAAuB,QAAQ,sBAAsB;AAEhG,SAAS,sBAA0C;CACjD,MAAM,MAAM,CAAC;CACb,MAAM,kBAAkB,GAAG;CAC3B,OAAO;AACT;AAEA,SAAS,qBAAyC;CAChD,IAAI;EACF,MAAM,MAAM,EAAE;CAChB,SAAS,KAAK;EACZ,OAAO;CACT;AACF;;AAGA,SAAS,mBACP,OACA,MACA,YACA,WACA,OAA4B,CAAC,GACvB;CACN,IAAI,OAAO,eAAe,YACxB,MAAM,KAAK;EAAE;EAAM,IAAI;EAAY,MAAM,KAAA;CAAU,CAAC;MAC/C;EACL,MAAM,OAAO;EAGb,MAAM,4BAAY,IAAI,IAAiC;EACvD,eAAe,GAAG,QAAW;GAC3B,MAAM,OAAO,YAAY,MAAM;GAC/B,IAAI,WAAW,UAAU,IAAI,IAAI;GACjC,IAAI,aAAa,KAAA,GAAW;IAC1B,WAAW,kBAAqB,MAAM,IAAI;IAC1C,UAAU,IAAI,MAAM,QAAQ;GAC9B;GACA,IAAI,OAAO,KAAK,QAAQ,CAAC,CAAC,SAAS,GACjC,MAAM,OAAO,GAAG,SAAS,QAAQ,QAAQ;GAE3C,IAAI,KAAK,iBAAiB,oBAAoB,QAAQ,QAAQ;GAC9D,OAAO,UAAW,MAAM;EAC1B;EACA,MAAM,KAAK;GAAE;GAAM;GAAI;EAAK,CAAC;CAC/B;AACF"}
|
|
1
|
+
{"version":3,"file":"config.js","names":[],"sources":["../src/config.ts"],"sourcesContent":["import { resetConstructorMap } from \"src/configure.ts\";\nimport { AsyncDefault } from \"src/defaults.ts\";\nimport { type Entity } from \"src/Entity.ts\";\nimport { assertHintUnchanged } from \"src/flush/ReadDrift.ts\";\nimport {\n type EntityConstructor,\n type EntityField,\n type EntityMetadata,\n type FieldsOf,\n type LoadHint,\n type Loaded,\n type MaybeAbstractEntityConstructor,\n type Reacted,\n type ReactiveHint,\n type RelationsIn,\n type SettableFields,\n fail,\n getMetadata,\n} from \"src/index.ts\";\nimport { convertToLoadHint } from \"src/reactivity/reactiveHints.ts\";\nimport { type ValidationRule, type ValidationRuleInternal, type ValidationRuleResult } from \"src/rules.ts\";\nimport {\n type FieldTransitionsConfig,\n type GuardTransitionMatch,\n type OnTransitionMatch,\n type Transition,\n type TransitionTable,\n toTransition,\n} from \"src/transitions.ts\";\nimport { type MaybePromise } from \"src/utils.ts\";\n\nexport type EntityHook =\n | \"beforeFlush\"\n | \"beforeCreate\"\n | \"beforeUpdate\"\n | \"beforeDelete\"\n | \"afterValidation\"\n | \"beforeCommit\"\n | \"afterCommit\";\ntype HookFn<T extends Entity, C> = (entity: T, ctx: C) => MaybePromise<unknown>;\n\ntype AssertUnchangedOpts = {\n /** Protect reached rows at flush; does not protect collection membership or predicates. */\n assertUnchanged?: boolean;\n};\ntype AddReactionOpts = AssertUnchangedOpts & { runOnce?: boolean; name?: string };\n\n/** An `addTransitionRule` rule, which also gets the transition it is checking, since the entity may have moved on. */\nexport type TransitionGuardFn<T extends Entity, V> = (\n entity: T,\n transition: Transition<V>,\n) => MaybePromise<ValidationRuleResult>;\n\n/** An `addTransitionReaction` function, which also gets the transition it is handling, since the entity may have moved on. */\ntype TransitionFn<T extends Entity, C, V> = (entity: T, ctx: C, transition: Transition<V>) => MaybePromise<unknown>;\n\n/** The enum type of a transition field, i.e. `PublisherStatus`. */\ntype TransitionType<T extends Entity, K extends keyof FieldsOf<T>> = FieldsOf<T>[K] extends EntityField\n ? NonNullable<FieldsOf<T>[K][\"type\"]>\n : never;\n\n/**\n * The state names that `transitions` tables and `match`es accept for an enum field, i.e. `\"Draft\"` for\n * `PublisherStatus.Draft`.\n *\n * We only accept the enum's accessors, not its codes or members, so every table reads the same way.\n */\ntype TransitionStates<T extends Entity, K extends keyof FieldsOf<T>> = FieldsOf<T>[K] extends {\n accessors: infer A extends string;\n}\n ? A\n : never;\n\nexport const constraintNameToValidationError: Record<string, string> = {};\n\ntype Settable<T extends Entity> = keyof SettableFields<FieldsOf<T>> & string;\n\nlet booted = false;\nlet afterMetadataLocked = false;\n\n/**\n * Called at the end of `configureMetadata` to indicate the boot process is complete.\n *\n * We use this flag to prevent users from mistakenly calling `config` methods after the boot\n * process is complete, i.e. from hooks or other post-boot invocations, where the calls are\n * not guaranteed to work because Joist's reactivity graph has already been initialized.\n */\nexport function setBooted(): void {\n booted = true;\n}\n\nexport function setAfterMetadataLocked(): void {\n afterMetadataLocked = true;\n}\n\n/** The public API to configure an Entity's hooks & validation rules. */\nexport class ConfigApi<T extends Entity, C> {\n __data = new ConfigData<T, C>();\n\n /**\n * Maps a given `constraintName`, i.e. `authors_publisher_id_unique_index`, to a hard-coded-but-pretty validation errors.\n *\n * Note that the validationError must be hard-coded b/c we cannot tease out \"which entity\" caused a given\n * constraint failure from the SQL database. If you really need pretty-and-custom validation errors, you'll\n * need to check the constraint by hand ahead of time, before calling `em.flush`.\n */\n addConstraintMessage(constraintName: string, validationError: string) {\n this.ensurePreBoot(getCallerName(), \"addConstraintMessage\");\n constraintNameToValidationError[constraintName] = validationError;\n }\n\n /**\n * Maps a `RecursiveCycleError` on the given recursive collection field to a custom validation error.\n *\n * When a cycle is detected in a recursive collection (e.g. `parentsRecursive`), instead of\n * throwing a raw `RecursiveCycleError`, `em.flush` will convert it into a `ValidationErrors`\n * using the provided message function.\n *\n * The `messageFn` receives the entity that detected the cycle and the cycle path (array of\n * entities forming the cycle), and should return a validation error string.\n */\n addCycleRule(fieldName: string & keyof T, messageFn: (entity: T, cyclePath: Entity[]) => string) {\n this.ensurePreBoot(getCallerName(), \"addCycleRule\");\n this.__data.cycleMessages[fieldName] = messageFn;\n // Register a reactive rule that loads the recursive collection and catches cycle errors.\n // The rule uses the recursive collection's underlying relation as a reactive hint so it\n // triggers when the collection changes.\n const hint = fieldName as any;\n const fn = () => {\n // We don't actually need a try/catch/anything here, b/c if there is a cycle, it\n // will cause a CycleError during followReverseHint, and never even get to calling this fn.\n };\n this.__data.rules.push({ name: `addCycleRule(${getCallerName()})`, fn, hint });\n }\n\n /**\n * Adds a validation rule for this entity.\n *\n * If `hint` is passed, then the rule's lambda will be: 1) passed a view of the entity with only\n * the fields included in `hint` marked as accessible, and 2) the rule will be called reactively any\n * time any field in the `hint` changes.\n *\n * If lambdas want to access fields w/o having them marked for reactivity, the rule can either\n * include the field as readonly with a `:ro` suffix, i.e. `firstName:ro`, or the lambda can\n * access the `reacted.entity` property to get a full view of the entity's fields and methods.\n */\n addRule<H extends ReactiveHint<T>>(hint: H, rule: ValidationRule<Reacted<T, H>>): void;\n addRule<H extends ReactiveHint<T>>(opts: AssertUnchangedOpts, hint: H, rule: ValidationRule<Reacted<T, H>>): void;\n addRule(rule: ValidationRule<T>): void;\n addRule(\n ruleOrHint: ValidationRule<T> | any,\n hintOrRule?: ReactiveHint<T> | ValidationRule<any>,\n maybeRule?: ValidationRule<any>,\n ): void {\n // Keep the name for easy debugging/tracing later\n const name = `addRule(${getCallerName()})`;\n this.ensurePreBoot(name, \"addRule\");\n pushValidationRule(\n this.__data.rules,\n name,\n maybeRule ? hintOrRule : ruleOrHint,\n maybeRule ?? (hintOrRule as ValidationRule<any> | undefined),\n maybeRule ? ruleOrHint : {},\n );\n }\n\n /**\n * Adds a \"commit rule\" that runs like a regular validation rule (see {@link addRule}), but *after*\n * the entity's `INSERT`/`UPDATE`/`DELETE` has been flushed to the database and *before* the\n * transaction `COMMIT`s, i.e. still within the transaction.\n *\n * The point of running this late is that any `em.find`s the rule makes will query the _changed_\n * state (the just-flushed rows), instead of the pre-flush state that regular `addRule` rules see.\n * This is useful for cross-row invariants that are easiest to express as a query, e.g. \"at most\n * one active `AuthorSchedule` per author\", where the rule wants to `em.find` the sibling rows\n * that were themselves just inserted/updated in this same flush.\n *\n * Like `addRule`, if a `hint` is passed the rule is reactive: it runs whenever any field in the\n * hint changes (walking back to the owning entity), and the lambda gets a `Reacted` view.\n */\n addCommitRule<H extends ReactiveHint<T>>(hint: H, rule: ValidationRule<Reacted<T, H>>): void;\n addCommitRule<H extends ReactiveHint<T>>(\n opts: AssertUnchangedOpts,\n hint: H,\n rule: ValidationRule<Reacted<T, H>>,\n ): void;\n addCommitRule(rule: ValidationRule<T>): void;\n addCommitRule(\n ruleOrHint: ValidationRule<T> | any,\n hintOrRule?: ReactiveHint<T> | ValidationRule<any>,\n maybeRule?: ValidationRule<any>,\n ): void {\n // Keep the name for easy debugging/tracing later\n const name = `addCommitRule(${getCallerName()})`;\n this.ensurePreBoot(name, \"addCommitRule\");\n pushValidationRule(\n this.__data.commitRules,\n name,\n maybeRule ? hintOrRule : ruleOrHint,\n maybeRule ?? (hintOrRule as ValidationRule<any> | undefined),\n maybeRule ? ruleOrHint : {},\n );\n }\n\n /** If both this entity, and `cstr` entities, are in the same `em.flush`, run us first. */\n runHooksBefore(cstr: EntityConstructor<any>): void {\n this.__data.runHooksBefore.push(cstr);\n }\n\n /** Deletes any entity/entities pointed to by `relation` when this entity is deleted. */\n cascadeDelete(relation: keyof RelationsIn<T> & LoadHint<T>): void {\n this.ensurePreBoot(getCallerName(), \"cascadeDelete\");\n this.__data.cascadeDeleteFields.push(relation);\n }\n\n touchOnChange(relation: keyof RelationsIn<T>): void {\n this.ensurePreBoot(getCallerName(), \"touchOnChange\");\n this.__data.touchOnChange.add(relation);\n }\n\n private addHook(hook: EntityHook, ruleOrHint: HookFn<T, C> | any, maybeFn?: HookFn<Loaded<T, any>, C>) {\n this.ensurePreBoot(getCallerName(), \"addHook\");\n if (typeof ruleOrHint === \"function\") {\n this.__data.hooks[hook].push(ruleOrHint);\n } else {\n const fn = async (entity: T, ctx: C) => {\n // TODO Use this for reactive beforeFlush\n const loaded = await entity.em.populate(entity, ruleOrHint);\n return maybeFn!(loaded, ctx);\n };\n // Squirrel our hint away where configureMetadata can find it\n (fn as any).hint = ruleOrHint;\n this.__data.hooks[hook].push(fn);\n }\n }\n\n afterMetadata(fn: AfterMetadataCallback<T>): void {\n if (afterMetadataLocked) {\n throw new Error(\n `config.afterMetadata on ${getCallerName()} must only be called on boot, before calling \\`configureMetadata\\` and not from other \\`afterMetadata\\` hooks.`,\n );\n }\n this.__data.afterMetadataCallbacks.push(fn);\n }\n\n beforeDelete<H extends LoadHint<T>>(populate: H, fn: HookFn<Loaded<T, H>, C>): void;\n beforeDelete(fn: HookFn<T, C>): void;\n beforeDelete(ruleOrHint: HookFn<T, C> | any, maybeFn?: HookFn<Loaded<T, any>, C>): void {\n this.addHook(\"beforeDelete\", ruleOrHint, maybeFn);\n }\n\n beforeFlush<H extends LoadHint<T>>(populate: H, fn: HookFn<Loaded<T, H>, C>): void;\n beforeFlush(fn: HookFn<T, C>): void;\n beforeFlush(ruleOrHint: HookFn<T, C> | any, maybeFn?: HookFn<Loaded<T, any>, C>): void {\n this.addHook(\"beforeFlush\", ruleOrHint, maybeFn);\n }\n\n // beforeCreate still needs to take a hint because even though the entity itself is New<T>, we might want to load\n // a nested relation that isn't loaded yet\n beforeCreate<H extends LoadHint<T>>(populate: H, fn: HookFn<Loaded<T, H>, C>): void;\n beforeCreate(fn: HookFn<T, C>): void;\n beforeCreate(ruleOrHint: HookFn<T, C> | any, maybeFn?: HookFn<Loaded<T, any>, C>): void {\n this.addHook(\"beforeCreate\", ruleOrHint, maybeFn);\n }\n\n beforeUpdate<H extends LoadHint<T>>(populate: H, fn: HookFn<Loaded<T, H>, C>): void;\n beforeUpdate(fn: HookFn<T, C>): void;\n beforeUpdate(ruleOrHint: HookFn<T, C> | any, maybeFn?: HookFn<Loaded<T, any>, C>): void {\n this.addHook(\"beforeUpdate\", ruleOrHint, maybeFn);\n }\n\n afterValidation<H extends LoadHint<T>>(populate: H, fn: HookFn<Loaded<T, H>, C>): void;\n afterValidation(fn: HookFn<T, C>): void;\n afterValidation(ruleOrHint: HookFn<T, C> | any, maybeFn?: HookFn<Loaded<T, any>, C>): void {\n this.addHook(\"afterValidation\", ruleOrHint, maybeFn);\n }\n\n beforeCommit(fn: HookFn<T, C>): void {\n this.addHook(\"beforeCommit\", fn);\n }\n\n afterCommit(fn: HookFn<T, C>): void {\n this.addHook(\"afterCommit\", fn);\n }\n\n /**\n * Adds a reaction that runs during flush whenever fields in the `hint` change.\n *\n * Reactions are somewhere in between hooks and reactive fields/references:\n * 1. Can make arbitrary changes to any entity like a hook\n * 2. Only run when the provided hint has changes, not on every flush, like an RF/RR\n * 3. Run when the entity itself has no changes, like an RF/RF\n * 4. Can run multiple times per flush, like an RF/RF. Be careful to avoid creating\n * circular dependencies in the hint and to make the function idempotent.\n *\n * Names default to the registration's source location. Pass unique names when registering multiple\n * reactions from a shared helper or loop; duplicate names on the same config are rejected.\n *\n * @param hint The fields to watch for changes and load before running the reaction\n * @param fn The reaction function to run\n */\n addReaction<H extends ReactiveHint<T>>(hint: H, fn: HookFn<Loaded<T, H>, C>): void;\n /**\n * Adds a named reaction that runs during flush whenever fields in the `hint` change.\n *\n * Reactions are somewhere in between hooks and reactive fields/references:\n * 1. Can make arbitrary changes to any entity like a hook\n * 2. Only run when `hint` has changes, not on every flush, like an RF/RR\n * 3. Can run when the entity itself has no changes, like an RF/RF\n * 4. Can run multiple times per flush, like an RF/RF. Be careful to avoid creating\n * circular dependencies in the hint and to make the function idempotent.\n *\n * @param name A name to identify this reaction for debugging\n * @param hint The fields to watch for changes and load before running the reaction\n * @param fn The reaction function to run\n */\n addReaction<H extends ReactiveHint<T>>(name: string, hint: H, fn: HookFn<Loaded<T, H>, C>): void;\n /**\n * Adds a reaction that runs during flush whenever fields in the `hint` change.\n *\n * Reactions are somewhere in between hooks and reactive fields/references:\n * 1. Can make arbitrary changes to any entity like a hook\n * 2. Only run when `hint` has changes, not on every flush, like an RF/RR\n * 3. Can run when the entity itself has no changes, like an RF/RF\n * 4. Can run multiple times per flush, like an RF/RF. Be careful to avoid creating\n * circular dependencies in the hint and to make the function idempotent.\n *\n * @param opts Options object containing:\n * - runOnce - If true, the reaction will only run once per flush, not every time the hint changes. Optional.\n * default: false.\n * - name - A name to identify this reaction for debugging\n * @param hint The fields to watch for changes and load before running the reaction\n * @param fn The reaction function to run\n */\n addReaction<H extends ReactiveHint<T>>(opts: AddReactionOpts, hint: H, fn: HookFn<Loaded<T, H>, C>): void;\n addReaction<H extends ReactiveHint<T>>(\n nameOrOptsOrHint: string | AddReactionOpts | H,\n hintOrFn: H | HookFn<Loaded<T, H>, C>,\n maybeFn?: HookFn<Loaded<T, H>, C>,\n ): void {\n // Keep the name so we can uniquely identify this reaction later and also aid debugging/tracing\n const fn = maybeFn ?? (hintOrFn as HookFn<Loaded<T, H>, C>);\n const hint = (maybeFn ? hintOrFn : nameOrOptsOrHint) as H;\n const opts = maybeFn\n ? typeof nameOrOptsOrHint === \"string\"\n ? { name: nameOrOptsOrHint }\n : (nameOrOptsOrHint as AddReactionOpts)\n : {};\n const { name = getCallerName(), runOnce = false } = opts;\n this.ensurePreBoot(name, \"addReaction\");\n this.ensureUniqueReactionName(name, \"addReaction\");\n // Cache load hints per-meta because CTI subtypes may resolve `hint` to different\n // load hints (e.g. an AsyncProperty overridden in the subtype with subtype-only relations).\n const loadHints = new Map<EntityMetadata, LoadHint<T>>();\n async function wrappedFn(entity: T, ctx: C) {\n const meta = getMetadata(entity);\n let loadHint = loadHints.get(meta);\n if (loadHint === undefined) {\n loadHint = convertToLoadHint<T>(meta, hint);\n loadHints.set(meta, loadHint);\n }\n if (Object.keys(loadHint).length > 0) {\n await entity.em.populate(entity, loadHint);\n }\n if (opts.assertUnchanged) assertHintUnchanged(entity, loadHint);\n return fn(entity as Loaded<T, H>, ctx);\n }\n this.__data.reactions.push({ name, fn: wrappedFn, hint, runOnce });\n }\n\n /**\n * Declares which state transitions of the enum `fieldName` are allowed, i.e. `{ Draft: [\"Open\"], Open: [\"Closed\"] }`.\n *\n * Keys and values are the enum's accessors as strings, i.e. `\"Draft\"` for `AuthorStatus.Draft`.\n *\n * A state that is missing from the table, or maps to `[]`, is treated as a terminal state & cannot be\n * changed. Creating an entity is not a transition, so a new entity may start in any state.\n *\n * The table is checked by the field's setter, so a disallowed transition throws a `ValidationErrors`\n * immediately, instead of failing the next `em.flush`.\n */\n setTransitions<K extends Settable<T>>(fieldName: K, table: TransitionTable<TransitionStates<T, K>>): void {\n const name = `setTransitions(${getCallerName()})`;\n this.ensurePreBoot(name, \"setTransitions\");\n const config = this.fieldTransitions(fieldName);\n // Subtypes add their own tables on their own configs, so a 2nd table on this config is a mistake\n if (config.table) fail(`config.setTransitions was already called for ${fieldName}, use one table per field`);\n // Accessors are converted to codes after boot, see `buildFieldTransitions`\n config.table = table;\n }\n\n /**\n * Checks each matching transition before its callbacks run, and rejects it if the guard returns an error.\n *\n * Use this for \"a transition is allowed only when ...\" checks that depend on other data, while\n * `setTransitions` declares the transitions that are possible at all. The `hint` is a load hint, like\n * `beforeFlush`'s, so it's loaded before `rule` runs, but only `fieldName` itself triggers the guard.\n *\n * Guards run with reactions, for every matching transition, even if the\n * field has moved on since. The entity is in its current state, so `rule` also gets the `transition`\n * it is checking. Guards never run on creation and are not rechecked during final validation.\n */\n addTransitionRule<K extends Settable<T>, H extends LoadHint<T>>(\n fieldName: K,\n match: GuardTransitionMatch<TransitionStates<T, K>>,\n hint: H,\n rule: TransitionGuardFn<Loaded<T, H>, TransitionType<T, K>>,\n ): void;\n addTransitionRule<K extends Settable<T>>(\n fieldName: K,\n match: GuardTransitionMatch<TransitionStates<T, K>>,\n rule: TransitionGuardFn<T, TransitionType<T, K>>,\n ): void;\n addTransitionRule(fieldName: string, match: GuardTransitionMatch<any>, hintOrRule: any, maybeRule?: any): void {\n const name = `addTransitionRule(${getCallerName()})`;\n this.ensurePreBoot(name, \"addTransitionRule\");\n const rule: TransitionGuardFn<T, any> = maybeRule ?? hintOrRule;\n const hint: LoadHint<T> | undefined = maybeRule ? hintOrRule : undefined;\n // The dispatcher evaluates matching guards once before invoking any callbacks for the transition.\n this.fieldTransitions(fieldName).guards.push({\n match,\n run(entity, step) {\n const transition = toTransition(step);\n return hint === undefined\n ? rule(entity, transition)\n : entity.em.populate(entity, hint).then((loaded) => rule(loaded, transition));\n },\n });\n }\n\n /**\n * Runs `fn` for each state transition of `fieldName` that matches `match`.\n *\n * This runs alongside reactions (see `addReaction`), but only state changes queue callbacks.\n * The `hint` is a load hint, like `beforeFlush`'s, so it is loaded but not reacted to.\n *\n * Callbacks run with reactions, once for every matching transition, in order,\n * even if the field has moved on since. The entity is in its current state, so `fn` also gets the\n * `transition` it is handling. Transitions that an `addTransitionRule` rejects don't fire.\n *\n * Creating an entity with a matching `to` state fires too, unless `match.from` is set or\n * `match.onCreate` is `false`. Set `match.phase: \"commit\"` to run in `beforeCommit` instead, i.e.\n * for enqueueing jobs.\n *\n * Callbacks that read a new entity's `id` should use `match.phase: \"commit\"`. Other callbacks may run\n * before ids are assigned, and Joist does not rerun them on a `NoIdError` because their side effects\n * could repeat.\n *\n * Pass a unique name as the first argument when registering multiple callbacks from a shared\n * helper or loop. Duplicate names on the same config are rejected when registered.\n */\n addTransitionReaction<K extends Settable<T>, H extends LoadHint<T>>(\n fieldName: K,\n match: OnTransitionMatch<TransitionStates<T, K>>,\n hint: H,\n fn: TransitionFn<Loaded<T, H>, C, TransitionType<T, K>>,\n ): void;\n addTransitionReaction<K extends Settable<T>>(\n fieldName: K,\n match: OnTransitionMatch<TransitionStates<T, K>>,\n fn: TransitionFn<T, C, TransitionType<T, K>>,\n ): void;\n addTransitionReaction<K extends Settable<T>, H extends LoadHint<T>>(\n name: string,\n fieldName: K,\n match: OnTransitionMatch<TransitionStates<T, K>>,\n hint: H,\n fn: TransitionFn<Loaded<T, H>, C, TransitionType<T, K>>,\n ): void;\n addTransitionReaction<K extends Settable<T>>(\n name: string,\n fieldName: K,\n match: OnTransitionMatch<TransitionStates<T, K>>,\n fn: TransitionFn<T, C, TransitionType<T, K>>,\n ): void;\n addTransitionReaction(\n nameOrFieldName: string,\n fieldNameOrMatch: string | OnTransitionMatch<any>,\n matchOrHintOrFn: any,\n hintOrFn?: any,\n maybeFn?: any,\n ): void {\n const named = typeof fieldNameOrMatch === \"string\";\n const name = named ? nameOrFieldName : `addTransitionReaction(${getCallerName()})`;\n this.ensurePreBoot(name, \"addTransitionReaction\");\n this.ensureUniqueReactionName(name, \"addTransitionReaction\");\n\n // Resolve the overloads\n const fieldName = named ? fieldNameOrMatch : nameOrFieldName;\n const match: OnTransitionMatch<any> = named ? matchOrHintOrFn : fieldNameOrMatch;\n const hintOrCallback = named ? hintOrFn : matchOrHintOrFn;\n const callback = named ? maybeFn : hintOrFn;\n const fn: TransitionFn<T, C, any> = callback ?? hintOrCallback;\n const hint: LoadHint<T> | undefined = callback ? hintOrCallback : undefined;\n\n // Transition queues trigger callbacks; hinted data is only loaded, not watched for changes.\n this.fieldTransitions(fieldName).callbacks.push({\n name,\n match,\n run(entity, ctx, step) {\n const transition = toTransition(step);\n return hint === undefined\n ? fn(entity, ctx, transition)\n : entity.em.populate(entity, hint).then((loaded) => fn(loaded, ctx, transition));\n },\n });\n }\n\n /** Adds a synchronous default for `fieldName` to a hard-coded `value`. */\n setDefault<K extends Settable<T>, F = FieldsOf<T>[K]>(\n fieldName: K,\n // Allow returning undefined to mean \"no default\"\n value: F extends EntityField ? F[\"type\"] : never,\n ): void;\n /** Adds a synchronous default for `fieldName` to the result of simple sync lambda. */\n setDefault<K extends Settable<T>, F = FieldsOf<T>[K]>(\n fieldName: K,\n // ...this doesn't technically declare what other fields of `entity` we depend on,\n // which ideally we want to drive \"which default to set first?\" precedence decisions.\n fn: (entity: T) => F extends EntityField ? F[\"type\"] | undefined : never,\n ): void;\n /** Adds an asynchronous default for `fieldName` to the result of a hinted lambda. */\n setDefault<K extends Settable<T>, const H extends ReactiveHint<T>, F = FieldsOf<T>[K]>(\n fieldName: K,\n // We use a ReactiveHint so that we get field-level dependencies that means someday\n // we could drive \"which default to set first?\" precedence decisions.\n hint: H,\n fn: (\n entity: Reacted<T, H>,\n ctx: C,\n ) => F extends { kind: \"m2o\"; type: infer T extends Entity }\n ? MaybePromise<T | Reacted<T, {}> | undefined>\n : F extends EntityField\n ? MaybePromise<F[\"type\"] | undefined>\n : never,\n ): void;\n setDefault<K extends keyof SettableFields<FieldsOf<T>> & string>(fieldName: K, hintOrFnOrValue: any, fn?: any): void {\n this.ensurePreBoot(getCallerName(), \"setDefault\");\n if (fn) {\n // If we're called once by the codegen, and again by the user, override the syncDefault\n delete this.__data.syncDefaults[fieldName];\n this.__data.asyncDefaults[fieldName] = new AsyncDefault(fieldName, hintOrFnOrValue, fn);\n } else {\n this.__data.syncDefaults[fieldName] = hintOrFnOrValue;\n }\n }\n\n /**\n * A noop method that exists solely to keep the `config.placeholder()` line in the initial entity file,\n * until the user is ready to use it. */\n placeholder(): void {}\n\n /** Returns `fieldName`'s transition config, creating it on first use. */\n private fieldTransitions(fieldName: string): FieldTransitionsConfig<T, C> {\n return (this.__data.transitions[fieldName] ??= { guards: [], callbacks: [] });\n }\n\n /** Requires unique names across ordinary reactions and transition callbacks. */\n private ensureUniqueReactionName(name: string, op: string): void {\n if (this.__data.reactionNames.has(name)) {\n throw new Error(\n `Duplicate reaction name \"${name}\" in config.${op}. Pass a unique name when registering reactions from a shared helper or loop.`,\n );\n }\n this.__data.reactionNames.add(name);\n }\n\n private ensurePreBoot(name: string, op: string): void {\n if (booted) {\n // Detect if this is NextJS and we're in a hot-reload situation\n if (isRunningInNextJs()) {\n // Reset our bag of config data to collect only the new rules/hooks\n this.__data = new ConfigData();\n resetBootFlag();\n } else {\n throw new Error(\n `config.${op} call on ${name} must only be called on boot, before calling \\`configureMetadata\\`.`,\n );\n }\n }\n }\n}\n\nfunction isRunningInNextJs(): boolean {\n return \"__NEXT_HTTP_AGENT\" in globalThis || \"__NEXT_HTTPS_AGENT\" in globalThis;\n}\n\n/**\n * Allows projects to manually reset the internal `booted` flag.\n *\n * This is only necessary if they're using hot-reloading and reloading their entity files\n * without restarting the server.\n *\n * Generally most tools like tsx or ts-node-dev reload the whole process, so don't need\n * to call this, but if Joist is used in a framework that does actual-hot-reloading, this\n * it will be necessary.\n */\nexport function resetBootFlag(): void {\n booted = false;\n afterMetadataLocked = false;\n resetConstructorMap();\n}\n\n/**\n * Stores a path back to a reactive rule.\n *\n * I.e. if `Book` has a `ruleFn` that reacts to `Author.title`, then `Author`'s config will have\n * a `ReactiveRule` with fields `[\"title\"]`, path `books`, and rule `ruleFn`.\n */\nexport interface ReactiveRule {\n /** The source we're reacting to, specifically which base/subtype cstr. */\n source: MaybeAbstractEntityConstructor<any>;\n /** The fields on this source entity that would trigger the downstream rule's eval. */\n fields: string[];\n /** The constructor of downstream entity that owns the reactive rule. */\n cstr: MaybeAbstractEntityConstructor<any>;\n /** The name (source location) of the downstream reactive rule. */\n name: string;\n /** The path from this source entity to the downstream entity that needs evaled. */\n path: string[];\n /** The downstream validation rule to eval. */\n fn: ValidationRule<any>;\n}\n\n/**\n * Stores a path back to a reactive derived field.\n *\n * I.e. if `Book.displayName` is an `asyncField` that reacts to `Author.title`, then `Author`'s config will have\n * a `ReactiveFields` with fields `[\"title\"]`, path `books`, and name `displayName`.\n */\nexport interface ReactiveField {\n kind: \"populate\" | \"query\";\n /** The fields on this source entity that would trigger the downstream field's recalc. */\n fields: string[];\n /** Read-only/immutable fields that are used in the derived field. */\n isReadOnly: boolean;\n /** The constructor of downstream entity that owns the derived field. */\n cstr: MaybeAbstractEntityConstructor<any>;\n /** The path from this source entity to the downstream entity that needs recalced. */\n path: string[];\n /** The name of the reactive field in the downstream entity to recalc. */\n name: string;\n runOnce: false;\n}\n\nexport interface Reaction {\n kind: \"reaction\";\n /** The source we're reacting to, specifically which base/subtype cstr. */\n source: MaybeAbstractEntityConstructor<any>;\n /** The fields on this source entity that would trigger the downstream hook's eval. */\n fields: string[];\n /** Read-only/immutable fields that are used in the function. */\n isReadOnly: boolean;\n /** The constructor of downstream entity that owns the reaction. */\n cstr: MaybeAbstractEntityConstructor<any>;\n /** The name (source location) of the downstream reaction. */\n name: string;\n /** The path from this source entity to the downstream entity for this reaction. */\n path: string[];\n /** The downstream reaction function. */\n fn: HookFn<any, any>;\n /** If true, the reaction should only run once per flush, not every time the hint changes. */\n runOnce: boolean;\n}\n\nexport type Reactable = ReactiveField | Reaction;\n\ninterface ReactionInternal<T extends Entity, H extends ReactiveHint<T>, C> {\n name: string;\n fn: HookFn<T, C>;\n hint: H;\n runOnce: boolean;\n}\n\ntype AfterMetadataCallback<T extends Entity> = (meta: EntityMetadata<T>) => void;\n\n/** The internal state of an entity's configuration data, i.e. validation rules/hooks. */\nexport class ConfigData<T extends Entity, C> {\n afterMetadataCallbacks: AfterMetadataCallback<T>[] = [];\n runHooksBefore: EntityConstructor<any>[] = [];\n /** The validation rules for this entity type. */\n rules: ValidationRuleInternal<T>[] = [];\n /** The \"commit rules\" for this entity type, i.e. validation rules that run post-flush/pre-commit. */\n commitRules: ValidationRuleInternal<T>[] = [];\n /** The reactions for this entity type. */\n reactions: ReactionInternal<T, any, C>[] = [];\n /** Names shared by addReaction and addTransitionReaction, including commit-phase callbacks. */\n reactionNames: Set<string> = new Set();\n /**\n * Field name -> its `setTransitions`, `addTransitionRule`, and `addTransitionReaction` config, with\n * accessors not yet converted.\n *\n * The keys are also the fields whose factories accept `withX` opts.\n */\n transitions: Record<string, FieldTransitionsConfig<T, C>> = {};\n /** The hooks for this entity type. */\n hooks: Record<EntityHook, HookFn<T, C>[]> = {\n beforeDelete: [],\n beforeFlush: [],\n beforeCreate: [],\n beforeUpdate: [],\n afterValidation: [],\n beforeCommit: [],\n afterCommit: [],\n };\n /** Synchronous defaults for this entity type, invoked on `em.create`. */\n syncDefaults: Record<string, ((entity: T) => void) | unknown> = {};\n /** Asynchronous defaults for this entity type, invoked on `em.flush`. */\n asyncDefaults: Record<string, AsyncDefault<T>> = {};\n\n // An array of the reactive rules that depend on this entity\n reactiveRules: ReactiveRule[] = [];\n // An array of the reactive *commit* rules (post-flush/pre-commit) that depend on this entity\n reactiveCommitRules: ReactiveRule[] = [];\n // An array of the reactive fields and reactions that depend on this entity\n reactables: Reactable[] = [];\n cascadeDeleteFields: Array<keyof RelationsIn<T>> = [];\n touchOnChange: Set<keyof RelationsIn<T>> = new Set();\n // Constantly converting reactive hints to load hints is expense, so cache them here\n cachedReactiveLoadHints: Record<string, any> = {};\n /** Maps recursive collection fieldNames to custom cycle error message functions. */\n cycleMessages: Record<string, (entity: T, cyclePath: Entity[]) => string> = {};\n}\n\nexport function getCallerName(extraFrames: number = 0): string {\n const err = getStack();\n // E.g. at Object.<anonymous> (/home/stephen/homebound/graphql-service/src/entities/Activity.ts:86:8)\n // (Make sure to drop lines that don't start with 'at' b/c the stack format can differ\n // slightly i.e. if running via tsx/using a node loader (probably?)\n const line = err.stack!.split(\"\\n\").filter((line) => line.includes(\" at \"))[3 + extraFrames];\n const parts = line.split(\"/\");\n // Get the last part, which will be the file name, i.e. Activity.ts:86:8\n return parts[parts.length - 1].replace(/:\\d+\\)?$/, \"\");\n}\n\nexport function getFuzzyCallerName(\n // FactoryLogger wants the test line that called into the factories, i.e. newAuthor(em) at\n // SomeTest.test.ts:42, so passes true to skip the application's misc /factories/ internals\n // and find the first \"actually a test\" line.\n //\n // But otherwise other loggers like FieldLogger do want to see \"what exact line, even if it's\n // in a factory, is calling field.set\".\n ignoreFactoryFrames = false,\n): string {\n const err = getStack();\n const lines = err\n .stack!.split(\"\\n\")\n // E.g. at Object.<anonymous> (/home/stephen/homebound/graphql-service/src/entities/Activity.ts:86:8)\n .filter((line) => line.includes(\" at \"));\n const line = findUserCodeLine(lines, ignoreFactoryFrames);\n return getFilePath(line);\n}\n\n/**\n * Given a callstack line return the file name.\n *\n * I.e. `at Object.<anonymous> (/home/stephen/homebound/graphql-service/src/entities/Activity.ts:86:8)`\n */\nexport function getFilePath(line: string): string {\n const parts = line.split(\"/\");\n return parts[parts.length - 1].replace(/:\\d+\\)?$/, \"\"); // Drop the `:8)`at the end\n}\n\n/** Given a callstack, uses heuristics to find the first line that looks like user code. */\nexport function findUserCodeLine(lines: string[], ignoreFactoryFrames = false): string {\n return (\n lines.find((line) => {\n // When running Joist's own integration tests, if we ignore `/joist-orm/`, we'll end up ignoring\n // everything because `joist-orm` is the name of the repository/working copy itself.\n const withinWorkingCopyJoist = line.includes(\"/packages/orm/\") || line.includes(\"/packages/core\");\n // But once we're not in a working copy, assume any `/joist-orm/` in the path === internal orm stack frames\n const withinProductionJoist =\n !withinWorkingCopyJoist && (line.includes(\"/joist-orm/src/\") || line.includes(\"/joist-core/src\"));\n const nodeInternals = line.includes(\"node:internal/\") || line.includes(\"Promise.all\");\n const isUserCode = !withinWorkingCopyJoist && !withinProductionJoist && !nodeInternals;\n // const isRecalc = line.includes(\".recalcPending\");\n const isDefault = line.includes(\"/defaults.ts\");\n // Batched calls like findOrCreate won't have a stack trace back to the true caller, so just stop there\n const isDataloader = line.includes(\"/dataloaders/\");\n // If this is the `newTestInstance` call\n // What about:\n // recalcSynchronousDerivedFields\n // Jest's adapter is an implementation detail, not a meaningful source location.\n const isJestInternal = line.includes(\"jestAdapterInit.js\");\n const isFactoryHelper = line.includes(\"/factories/\");\n return (\n (isDefault || isDataloader || isUserCode) &&\n !line.includes(\"Codegen.ts\") &&\n !isJestInternal &&\n !(ignoreFactoryFrames && isFactoryHelper) &&\n // I wanted to exclude this, but it was actually our utils/entities.ts maybeSetDefault helper method\n // !line.includes(\"entities.ts\") &&\n // Ignore loops in joist code like setOpts\n !line.includes(\"at Array\") &&\n // Ignore the Author.ts constructor calling setOpts\n !line.includes(\"at new \")\n );\n }) ?? fail(\"Could not find caller name\")\n );\n}\n\nconst getStack: () => { stack?: string } = \"captureStackTrace\" in Error ? getStackFromCapture : getStackFromObject;\n\nfunction getStackFromCapture(): { stack?: string } {\n const obj = {};\n Error.captureStackTrace(obj);\n return obj as any;\n}\n\nfunction getStackFromObject(): { stack?: string } {\n try {\n throw Error(\"\");\n } catch (err) {\n return err as Error;\n }\n}\n\n/** Pushes a validation rule (either the raw or hinted/reactive form) onto `rules`, shared by `addRule`/`addCommitRule`. */\nfunction pushValidationRule<T extends Entity>(\n rules: ValidationRuleInternal<T>[],\n name: string,\n ruleOrHint: ValidationRule<T> | any,\n maybeRule: ValidationRule<any> | undefined,\n opts: AssertUnchangedOpts = {},\n): void {\n if (typeof ruleOrHint === \"function\") {\n rules.push({ name, fn: ruleOrHint, hint: undefined });\n } else {\n const hint = ruleOrHint;\n // Cache load hints per-meta because CTI subtypes may resolve `hint` to different\n // load hints (e.g. an AsyncProperty overridden in the subtype with subtype-only relations).\n const loadHints = new Map<EntityMetadata, LoadHint<T>>();\n async function fn(entity: T) {\n const meta = getMetadata(entity);\n let loadHint = loadHints.get(meta);\n if (loadHint === undefined) {\n loadHint = convertToLoadHint<T>(meta, hint);\n loadHints.set(meta, loadHint);\n }\n if (Object.keys(loadHint).length > 0) {\n await entity.em.populate(entity, loadHint);\n }\n if (opts.assertUnchanged) assertHintUnchanged(entity, loadHint);\n return maybeRule!(entity);\n }\n rules.push({ name, fn, hint });\n }\n}\n"],"mappings":";;;;;;;;;;;AAyEA,MAAa,kCAA0D,CAAC;AAIxE,IAAI,SAAS;AACb,IAAI,sBAAsB;;;;;;;;AAS1B,SAAgB,YAAkB;CAChC,SAAS;AACX;AAEA,SAAgB,yBAA+B;CAC7C,sBAAsB;AACxB;;AAGA,IAAa,YAAb,MAA4C;CAC1C,SAAS,IAAI,WAAiB;;;;;;;;CAS9B,qBAAqB,gBAAwB,iBAAyB;EACpE,KAAK,cAAc,cAAc,GAAG,sBAAsB;EAC1D,gCAAgC,kBAAkB;CACpD;;;;;;;;;;;CAYA,aAAa,WAA6B,WAAuD;EAC/F,KAAK,cAAc,cAAc,GAAG,cAAc;EAClD,KAAK,OAAO,cAAc,aAAa;EAIvC,MAAM,OAAO;EACb,MAAM,WAAW,CAGjB;EACA,KAAK,OAAO,MAAM,KAAK;GAAE,MAAM,gBAAgB,cAAc,EAAE;GAAI;GAAI;EAAK,CAAC;CAC/E;CAgBA,QACE,YACA,YACA,WACM;EAEN,MAAM,OAAO,WAAW,cAAc,EAAE;EACxC,KAAK,cAAc,MAAM,SAAS;EAClC,mBACE,KAAK,OAAO,OACZ,MACA,YAAY,a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,SAAS,UAAU,KAEzB,CAAC,KAAK,SAAS,SAAS;CAE5B,CAAC,KAAK,KAAK,4BAA4B;AAE3C;AAEA,MAAM,WAAqC,uBAAuB,QAAQ,sBAAsB;AAEhG,SAAS,sBAA0C;CACjD,MAAM,MAAM,CAAC;CACb,MAAM,kBAAkB,GAAG;CAC3B,OAAO;AACT;AAEA,SAAS,qBAAyC;CAChD,IAAI;EACF,MAAM,MAAM,EAAE;CAChB,SAAS,KAAK;EACZ,OAAO;CACT;AACF;;AAGA,SAAS,mBACP,OACA,MACA,YACA,WACA,OAA4B,CAAC,GACvB;CACN,IAAI,OAAO,eAAe,YACxB,MAAM,KAAK;EAAE;EAAM,IAAI;EAAY,MAAM,KAAA;CAAU,CAAC;MAC/C;EACL,MAAM,OAAO;EAGb,MAAM,4BAAY,IAAI,IAAiC;EACvD,eAAe,GAAG,QAAW;GAC3B,MAAM,OAAO,YAAY,MAAM;GAC/B,IAAI,WAAW,UAAU,IAAI,IAAI;GACjC,IAAI,aAAa,KAAA,GAAW;IAC1B,WAAW,kBAAqB,MAAM,IAAI;IAC1C,UAAU,IAAI,MAAM,QAAQ;GAC9B;GACA,IAAI,OAAO,KAAK,QAAQ,CAAC,CAAC,SAAS,GACjC,MAAM,OAAO,GAAG,SAAS,QAAQ,QAAQ;GAE3C,IAAI,KAAK,iBAAiB,oBAAoB,QAAQ,QAAQ;GAC9D,OAAO,UAAW,MAAM;EAC1B;EACA,MAAM,KAAK;GAAE;GAAM;GAAI;EAAK,CAAC;CAC/B;AACF"}
|
|
@@ -18,7 +18,7 @@ var FactoryLogger = class {
|
|
|
18
18
|
}
|
|
19
19
|
logCreating(cstr) {
|
|
20
20
|
if (this.skipNextLogCreating) this.skipNextLogCreating = false;
|
|
21
|
-
else this.write("Creating", green.bold(`new ${cstr.name}`), gray(`at ${require_config.
|
|
21
|
+
else this.write("Creating", green.bold(`new ${cstr.name}`), gray(`at ${require_config.getFuzzyCallerName(true)}`));
|
|
22
22
|
}
|
|
23
23
|
logAddToUseMap(e, source) {
|
|
24
24
|
if (source === "sameBranch" || source === "diffBranch") this.write(`${gray(`created`)} ${e.toString()} ${gray("added to scope")}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FactoryLogger.cjs","names":["
|
|
1
|
+
{"version":3,"file":"FactoryLogger.cjs","names":["getFuzzyCallerName"],"sources":["../../src/logging/FactoryLogger.ts"],"sourcesContent":["import ansis from \"ansis\";\nimport { getFuzzyCallerName } from \"src/config.ts\";\nimport { type Entity } from \"src/Entity.ts\";\nimport { type EntityMetadata } from \"src/EntityMetadata.ts\";\nimport { type UseMapSource } from \"src/newTestInstance.ts\";\n\nlet writer: WriteFn | undefined = undefined;\nexport type WriteFn = (line: string) => void;\n\nconst { gray, green, yellow } = ansis;\n\nexport class FactoryLogger {\n private level = 0;\n private writeFn: WriteFn;\n private skipNextLogCreating = false;\n\n // We default to process.stdout.write to side-step around Jest's console.log instrumentation\n // adding \"...at...\" stack traces to our output.\n constructor() {\n this.writeFn = writer ?? process.stdout.write.bind(process.stdout);\n }\n\n logCreating(cstr: any): void {\n // This was already logged by the parent `field = creating new`\n if (this.skipNextLogCreating) {\n this.skipNextLogCreating = false;\n } else {\n this.write(\"Creating\", green.bold(`new ${cstr.name}`), gray(`at ${getFuzzyCallerName(true)}`));\n }\n }\n\n logAddToUseMap(e: Entity, source: UseMapSource): void {\n if (source === \"sameBranch\" || source === \"diffBranch\") {\n this.write(`${gray(`created`)} ${e.toString()} ${gray(\"added to scope\")}`);\n } else {\n this.write(`${gray(`...adding`)} ${e.toString()} ${gray(\"opt to scope\")}`);\n }\n }\n\n logCreated(e: Entity): void {\n // This matches the `logAddToUseMap` but for entities not going into scope\n this.write(`${gray(`created`)} ${e.toString()}`);\n }\n\n logFoundExisting(e: Entity): void {\n // Make this yellow because it reverses the \"new Entity\" we thought we were going to do\n this.write(`${yellow(`using existing`)} ${e.toString()}`);\n }\n\n logFoundOpt(fieldName: string, e: Entity): void {\n this.write(`${gray(`${fieldName} =`)} ${e.toString()} ${gray(\"from opt\")}`);\n }\n\n logNotFoundAndCreating(fieldName: string, meta: EntityMetadata): void {\n this.write(`${gray(`${fieldName} =`)} creating ${green.bold(`new ${meta.type}`)}`);\n this.skipNextLogCreating = true;\n }\n\n logFoundInUseMap(fieldName: string, e: Entity): void {\n this.write(`${gray(`${fieldName} =`)} ${e.toString()} ${gray(\"from scope\")}`);\n }\n\n logFoundSingleEntity(fieldName: string, e: Entity): void {\n this.write(`${gray(`${fieldName} =`)} ${e.toString()} ${gray(\"from em\")}`);\n }\n\n indent() {\n this.level++;\n }\n\n dedent() {\n this.level--;\n }\n\n private write(...line: string[]): void {\n this.writeFn(this.prefix() + line.join(\" \") + \"\\n\");\n }\n\n private prefix() {\n return \" \".repeat(this.level);\n }\n}\n\n// Allow our test suite observe the logger behavior\nexport function setFactoryWriter(write: WriteFn | undefined): void {\n writer = write;\n}\n"],"mappings":";;;;;;;;;AAMA,IAAI,SAA8B,KAAA;AAGlC,MAAM,EAAE,MAAM,OAAO,WAAW,MAAA;AAEhC,IAAa,gBAAb,MAA2B;CACzB,QAAgB;CAChB;CACA,sBAA8B;CAI9B,cAAc;EACZ,KAAK,UAAU,UAAU,QAAQ,OAAO,MAAM,KAAK,QAAQ,MAAM;CACnE;CAEA,YAAY,MAAiB;EAE3B,IAAI,KAAK,qBACP,KAAK,sBAAsB;OAE3B,KAAK,MAAM,YAAY,MAAM,KAAK,OAAO,KAAK,MAAM,GAAG,KAAK,MAAMA,eAAAA,mBAAmB,IAAI,GAAG,CAAC;CAEjG;CAEA,eAAe,GAAW,QAA4B;EACpD,IAAI,WAAW,gBAAgB,WAAW,cACxC,KAAK,MAAM,GAAG,KAAK,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,KAAK,gBAAgB,GAAG;OAEzE,KAAK,MAAM,GAAG,KAAK,WAAW,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,KAAK,cAAc,GAAG;CAE7E;CAEA,WAAW,GAAiB;EAE1B,KAAK,MAAM,GAAG,KAAK,SAAS,EAAE,GAAG,EAAE,SAAS,GAAG;CACjD;CAEA,iBAAiB,GAAiB;EAEhC,KAAK,MAAM,GAAG,OAAO,gBAAgB,EAAE,GAAG,EAAE,SAAS,GAAG;CAC1D;CAEA,YAAY,WAAmB,GAAiB;EAC9C,KAAK,MAAM,GAAG,KAAK,GAAG,UAAU,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,KAAK,UAAU,GAAG;CAC5E;CAEA,uBAAuB,WAAmB,MAA4B;EACpE,KAAK,MAAM,GAAG,KAAK,GAAG,UAAU,GAAG,EAAE,YAAY,MAAM,KAAK,OAAO,KAAK,MAAM,GAAG;EACjF,KAAK,sBAAsB;CAC7B;CAEA,iBAAiB,WAAmB,GAAiB;EACnD,KAAK,MAAM,GAAG,KAAK,GAAG,UAAU,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,KAAK,YAAY,GAAG;CAC9E;CAEA,qBAAqB,WAAmB,GAAiB;EACvD,KAAK,MAAM,GAAG,KAAK,GAAG,UAAU,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,KAAK,SAAS,GAAG;CAC3E;CAEA,SAAS;EACP,KAAK;CACP;CAEA,SAAS;EACP,KAAK;CACP;CAEA,MAAc,GAAG,MAAsB;EACrC,KAAK,QAAQ,KAAK,OAAO,IAAI,KAAK,KAAK,GAAG,IAAI,IAAI;CACpD;CAEA,SAAiB;EACf,OAAO,KAAK,OAAO,KAAK,KAAK;CAC/B;AACF;AAGA,SAAgB,iBAAiB,OAAkC;CACjE,SAAS;AACX"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getFuzzyCallerName } from "../config.js";
|
|
2
2
|
import "../EntityMetadata.js";
|
|
3
3
|
import "../newTestInstance.js";
|
|
4
4
|
import "../Entity.js";
|
|
@@ -15,7 +15,7 @@ var FactoryLogger = class {
|
|
|
15
15
|
}
|
|
16
16
|
logCreating(cstr) {
|
|
17
17
|
if (this.skipNextLogCreating) this.skipNextLogCreating = false;
|
|
18
|
-
else this.write("Creating", green.bold(`new ${cstr.name}`), gray(`at ${
|
|
18
|
+
else this.write("Creating", green.bold(`new ${cstr.name}`), gray(`at ${getFuzzyCallerName(true)}`));
|
|
19
19
|
}
|
|
20
20
|
logAddToUseMap(e, source) {
|
|
21
21
|
if (source === "sameBranch" || source === "diffBranch") this.write(`${gray(`created`)} ${e.toString()} ${gray("added to scope")}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FactoryLogger.js","names":[],"sources":["../../src/logging/FactoryLogger.ts"],"sourcesContent":["import ansis from \"ansis\";\nimport {
|
|
1
|
+
{"version":3,"file":"FactoryLogger.js","names":[],"sources":["../../src/logging/FactoryLogger.ts"],"sourcesContent":["import ansis from \"ansis\";\nimport { getFuzzyCallerName } from \"src/config.ts\";\nimport { type Entity } from \"src/Entity.ts\";\nimport { type EntityMetadata } from \"src/EntityMetadata.ts\";\nimport { type UseMapSource } from \"src/newTestInstance.ts\";\n\nlet writer: WriteFn | undefined = undefined;\nexport type WriteFn = (line: string) => void;\n\nconst { gray, green, yellow } = ansis;\n\nexport class FactoryLogger {\n private level = 0;\n private writeFn: WriteFn;\n private skipNextLogCreating = false;\n\n // We default to process.stdout.write to side-step around Jest's console.log instrumentation\n // adding \"...at...\" stack traces to our output.\n constructor() {\n this.writeFn = writer ?? process.stdout.write.bind(process.stdout);\n }\n\n logCreating(cstr: any): void {\n // This was already logged by the parent `field = creating new`\n if (this.skipNextLogCreating) {\n this.skipNextLogCreating = false;\n } else {\n this.write(\"Creating\", green.bold(`new ${cstr.name}`), gray(`at ${getFuzzyCallerName(true)}`));\n }\n }\n\n logAddToUseMap(e: Entity, source: UseMapSource): void {\n if (source === \"sameBranch\" || source === \"diffBranch\") {\n this.write(`${gray(`created`)} ${e.toString()} ${gray(\"added to scope\")}`);\n } else {\n this.write(`${gray(`...adding`)} ${e.toString()} ${gray(\"opt to scope\")}`);\n }\n }\n\n logCreated(e: Entity): void {\n // This matches the `logAddToUseMap` but for entities not going into scope\n this.write(`${gray(`created`)} ${e.toString()}`);\n }\n\n logFoundExisting(e: Entity): void {\n // Make this yellow because it reverses the \"new Entity\" we thought we were going to do\n this.write(`${yellow(`using existing`)} ${e.toString()}`);\n }\n\n logFoundOpt(fieldName: string, e: Entity): void {\n this.write(`${gray(`${fieldName} =`)} ${e.toString()} ${gray(\"from opt\")}`);\n }\n\n logNotFoundAndCreating(fieldName: string, meta: EntityMetadata): void {\n this.write(`${gray(`${fieldName} =`)} creating ${green.bold(`new ${meta.type}`)}`);\n this.skipNextLogCreating = true;\n }\n\n logFoundInUseMap(fieldName: string, e: Entity): void {\n this.write(`${gray(`${fieldName} =`)} ${e.toString()} ${gray(\"from scope\")}`);\n }\n\n logFoundSingleEntity(fieldName: string, e: Entity): void {\n this.write(`${gray(`${fieldName} =`)} ${e.toString()} ${gray(\"from em\")}`);\n }\n\n indent() {\n this.level++;\n }\n\n dedent() {\n this.level--;\n }\n\n private write(...line: string[]): void {\n this.writeFn(this.prefix() + line.join(\" \") + \"\\n\");\n }\n\n private prefix() {\n return \" \".repeat(this.level);\n }\n}\n\n// Allow our test suite observe the logger behavior\nexport function setFactoryWriter(write: WriteFn | undefined): void {\n writer = write;\n}\n"],"mappings":";;;;;;AAMA,IAAI,SAA8B,KAAA;AAGlC,MAAM,EAAE,MAAM,OAAO,WAAW;AAEhC,IAAa,gBAAb,MAA2B;CACzB,QAAgB;CAChB;CACA,sBAA8B;CAI9B,cAAc;EACZ,KAAK,UAAU,UAAU,QAAQ,OAAO,MAAM,KAAK,QAAQ,MAAM;CACnE;CAEA,YAAY,MAAiB;EAE3B,IAAI,KAAK,qBACP,KAAK,sBAAsB;OAE3B,KAAK,MAAM,YAAY,MAAM,KAAK,OAAO,KAAK,MAAM,GAAG,KAAK,MAAM,mBAAmB,IAAI,GAAG,CAAC;CAEjG;CAEA,eAAe,GAAW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;CACjE,SAAS;AACX"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "joist-core",
|
|
3
|
-
"version": "2.4.0-next.
|
|
3
|
+
"version": "2.4.0-next.44",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"build"
|
|
43
43
|
],
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"joist-utils": "2.4.0-next.
|
|
45
|
+
"joist-utils": "2.4.0-next.44"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"ansis": "^4.4.0",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"@types/jest": "^30.0.0",
|
|
56
56
|
"@types/node": "^26.6.5",
|
|
57
57
|
"jest": "30.4.2",
|
|
58
|
-
"temporal-polyfill": "^1.0.
|
|
58
|
+
"temporal-polyfill": "^1.0.6",
|
|
59
59
|
"tsconfig-paths": "^4.2.0",
|
|
60
60
|
"typescript": "7.0.2"
|
|
61
61
|
}
|