@happyvertical/smrt-core 0.48.0 → 0.49.1
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/agents/object-runtime.md +7 -0
- package/agents/schema-paths.md +17 -0
- package/dist/cascade.d.ts.map +1 -1
- package/dist/cascade.js +9 -6
- package/dist/cascade.js.map +1 -1
- package/dist/collection.d.ts +0 -1
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +32 -44
- package/dist/collection.js.map +1 -1
- package/dist/decorators/compatibility.d.ts +1 -1
- package/dist/decorators/compatibility.d.ts.map +1 -1
- package/dist/decorators/compatibility.js +2 -2
- package/dist/decorators/compatibility.js.map +1 -1
- package/dist/decorators/index.d.ts.map +1 -1
- package/dist/decorators/index.js +33 -24
- package/dist/decorators/index.js.map +1 -1
- package/dist/interceptors.d.ts +3 -1
- package/dist/interceptors.d.ts.map +1 -1
- package/dist/interceptors.js +3 -2
- package/dist/interceptors.js.map +1 -1
- package/dist/manifest/static-manifest.js +1 -1
- package/dist/manifest/static-manifest.js.map +1 -1
- package/dist/manifest/store.js +1 -1
- package/dist/manifest.json +1 -1
- package/dist/object.d.ts +1 -5
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +28 -37
- package/dist/object.js.map +1 -1
- package/dist/registry/class-registration.d.ts +2 -1
- package/dist/registry/class-registration.d.ts.map +1 -1
- package/dist/registry/class-registration.js +47 -16
- package/dist/registry/class-registration.js.map +1 -1
- package/dist/registry/name-resolver.d.ts.map +1 -1
- package/dist/registry/name-resolver.js +3 -3
- package/dist/registry/name-resolver.js.map +1 -1
- package/dist/registry/relationship-graph.d.ts +2 -0
- package/dist/registry/relationship-graph.d.ts.map +1 -1
- package/dist/registry/relationship-graph.js +60 -5
- package/dist/registry/relationship-graph.js.map +1 -1
- package/dist/registry/schema-builder.d.ts.map +1 -1
- package/dist/registry/schema-builder.js +4 -1
- package/dist/registry/schema-builder.js.map +1 -1
- package/dist/registry/shared-state.d.ts +18 -0
- package/dist/registry/shared-state.d.ts.map +1 -1
- package/dist/registry/shared-state.js +25 -1
- package/dist/registry/shared-state.js.map +1 -1
- package/dist/registry/types.d.ts +8 -0
- package/dist/registry/types.d.ts.map +1 -1
- package/dist/registry.d.ts +32 -5
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +120 -12
- package/dist/registry.js.map +1 -1
- package/dist/relationship-loader.d.ts +6 -0
- package/dist/relationship-loader.d.ts.map +1 -0
- package/dist/relationship-loader.js +35 -0
- package/dist/relationship-loader.js.map +1 -0
- package/dist/scanner/manifest-generator.d.ts.map +1 -1
- package/dist/scanner/manifest-generator.js +6 -3
- package/dist/scanner/manifest-generator.js.map +1 -1
- package/dist/schema/generator.d.ts +2 -0
- package/dist/schema/generator.d.ts.map +1 -1
- package/dist/schema/generator.js +16 -9
- package/dist/schema/generator.js.map +1 -1
- package/dist/schema/utils.d.ts.map +1 -1
- package/dist/schema/utils.js +2 -1
- package/dist/schema/utils.js.map +1 -1
- package/dist/smrt-knowledge.json +7 -7
- package/dist/test-utils.d.ts.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +2 -1
- package/dist/utils.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"name-resolver.js","names":[],"sources":["../../src/registry/name-resolver.ts"],"sourcesContent":["/**\n * Name resolution module for the SMRT ObjectRegistry.\n *\n * Handles class lookup, disambiguation, and qualified name resolution.\n * All functions operate on the shared globalThis state.\n *\n * Release B (#1133): classNameMap is gone — the eagerly-maintained\n * lowercase-simple-name → qualified-key[] index was removed in favor of\n * on-demand iteration over the `classes` Map. Production SMRT apps carry\n * a few hundred classes at most, so the linear scan is negligible and\n * removes an entire class of cache-sync bugs (#584, #847, #951).\n *\n * Extracted from registry.ts as part of issue #1006.\n * @see https://github.com/happyvertical/smrt/issues/1006\n * @see https://github.com/happyvertical/smrt/issues/1133\n */\n\nimport { ConfigurationError } from '../errors';\nimport type { QualifiedClassName, SmrtVisibility } from '../scanner/types.js';\nimport {\n createQualifiedName,\n isQualifiedName,\n parseQualifiedName,\n} from '../utils/qualified-names.js';\nimport { getClasses, getConstructorIndex, verboseLog } from './shared-state';\nimport type { RegisteredClass, SmrtObjectConstructor } from './types';\n\n// ── Simple-name iteration (replaces classNameMap reads) ─────────────\n\n/**\n * Return every registry key whose registered class has the given simple\n * name (case-insensitive). Replaces the old eagerly-maintained\n * `__smrtRegistryClassNameMap` lookup: we iterate `classes` instead.\n *\n * Cost is O(n) over the classes map; production SMRT apps hold low-\n * hundreds of entries so this is trivially fast. Returned keys preserve\n * insertion order, which makes the \"first match wins\" behavior of the old\n * map-based lookup deterministic in the same way.\n *\n * De-duplicates by RegisteredClass object identity so a class registered\n * under both a simple key and a promoted qualified key (a transitional\n * state during manifest merge) counts as a single entry — matching the\n * old classNameMap's behavior of storing each canonical qualified key once.\n * When that happens, the qualified key wins over the simple one.\n */\nfunction registryKeysBySimpleName(simpleName: string): string[] {\n const lower = simpleName.toLowerCase();\n const classes = getClasses();\n const seen = new Map<unknown, string>();\n\n for (const [key, value] of classes.entries()) {\n if (value.name?.toLowerCase() !== lower) continue;\n\n const existing = seen.get(value);\n if (!existing) {\n seen.set(value, key);\n continue;\n }\n\n // Two keys for the same object: prefer the qualified form.\n if (key.includes(':') && !existing.includes(':')) {\n seen.set(value, key);\n }\n }\n\n return [...seen.values()];\n}\n\n// ── Lookup functions ────────────────────────────────────────\n\n/**\n * Check if a class is already registered (case-insensitive).\n * Returns the canonical name if found, undefined otherwise. Returns\n * undefined if the simple name is ambiguous across multiple packages.\n */\nexport function getCanonicalClassName(name: string): string | undefined {\n const keys = registryKeysBySimpleName(name);\n if (keys.length === 1) return keys[0];\n // Zero matches, or ambiguous with >1 entries\n return undefined;\n}\n\n/**\n * Check if a class exists by name (case-insensitive).\n */\nexport function hasClassCaseInsensitive(name: string): boolean {\n const lower = name.toLowerCase();\n for (const value of getClasses().values()) {\n if (value.name?.toLowerCase() === lower) return true;\n }\n return false;\n}\n\n/**\n * Helper for class lookup with qualified name support.\n *\n * Lookup priority:\n * 1. Direct hit on classes map (works for qualified names as keys)\n * 2. If input contains ':', prefer direct qualified lookup, then fall back\n * to an exact/simple registration when runtime source imports registered\n * the class before package-qualified promotion happened\n * 3. Simple-name iteration by lowercase\n * - Unambiguous (1 match) → return it\n * - Ambiguous (>1 matches) → log warning, return first\n */\nexport function findClass(name: string): RegisteredClass | undefined {\n const classes = getClasses();\n\n // 1. Direct hit on classes map (fast path, works for qualified keys)\n const registered = classes.get(name);\n if (registered) {\n return registered;\n }\n\n // 2. Qualified lookup fallback for source-registered classes.\n // In workspace/dev mode a package can be imported from source before a\n // manifest-promoted qualified key exists. If we already have exactly the\n // requested package or a single unqualified registration for this class\n // name, treat it as the same class instead of forcing node_modules manifest\n // discovery.\n if (isQualifiedName(name)) {\n const { packageName, className } = parseQualifiedName(name);\n const keys = registryKeysBySimpleName(className);\n\n if (keys.length > 0) {\n const exactPackageMatch = keys\n .map((key) => classes.get(key))\n .find((candidate) => candidate?.packageName === packageName);\n\n if (exactPackageMatch) {\n return exactPackageMatch;\n }\n\n if (keys.length === 1) {\n const fallback = classes.get(keys[0]);\n if (fallback && !fallback.packageName) {\n return fallback;\n }\n }\n }\n\n return undefined;\n }\n\n // 3. Simple-name lookup\n const keys = registryKeysBySimpleName(name);\n if (keys.length > 0) {\n if (keys.length === 1) {\n return classes.get(keys[0]);\n }\n // Ambiguous — multiple packages define this class name\n // Return first match but log a warning (use resolveType() for strict behavior)\n verboseLog(\n `[registry] findClass(\"${name}\") is ambiguous — ${keys.length} matches. ` +\n `Use qualified name (e.g., ${keys[0]}) for precision.`,\n );\n return classes.get(keys[0]);\n }\n\n return undefined;\n}\n\n/**\n * Strict class lookup with package-aware disambiguation.\n *\n * Unlike `findClass()` which silently returns the first match when a simple\n * name is ambiguous, this method throws a `ConfigurationError` — making it\n * safe for inheritance-critical paths.\n *\n * @throws {ConfigurationError} When simple name is ambiguous and no package context resolves it\n * @see https://github.com/happyvertical/smrt/issues/1005\n */\nexport function findClassStrict(\n name: string,\n fromPackage?: string,\n): RegisteredClass | undefined {\n const classes = getClasses();\n\n // 1. Direct hit on classes map (fast path, works for qualified keys)\n const registered = classes.get(name);\n if (registered) {\n return registered;\n }\n\n // 2. If input is a qualified name, no fallback — it's not found\n if (isQualifiedName(name)) {\n return undefined;\n }\n\n // 3. If fromPackage provided, try constructing qualified name for direct lookup\n if (fromPackage) {\n const qualifiedAttempt = createQualifiedName(fromPackage, name);\n const byQualified = classes.get(qualifiedAttempt);\n if (byQualified) {\n return byQualified;\n }\n }\n\n // 4. Simple-name lookup\n const keys = registryKeysBySimpleName(name);\n if (keys.length > 0) {\n if (keys.length === 1) {\n return classes.get(keys[0]);\n }\n // Ambiguous — multiple packages define this class name\n // In strict mode, throw instead of silently returning first match\n throw new ConfigurationError(\n `Ambiguous class name \"${name}\" — found in ${keys.length} packages: ` +\n `${keys.join(', ')}. ` +\n `Use a qualified name (e.g., ${keys[0]}) to disambiguate.`,\n 'CONFIG_AMBIGUOUS_CLASS',\n { className: name, candidates: keys },\n );\n }\n\n return undefined;\n}\n\n/**\n * Qualify an `extends` value with the parent class's package name.\n *\n * @see https://github.com/happyvertical/smrt/issues/1004\n */\nexport function qualifyExtendsName(\n extendsValue: string,\n currentPackage: string,\n): string {\n const classes = getClasses();\n\n // Already qualified → pass through\n if (isQualifiedName(extendsValue)) {\n return extendsValue;\n }\n\n // Skip framework base classes (never registered with qualified names)\n if (\n extendsValue === 'SmrtObject' ||\n extendsValue === 'SmrtClass' ||\n extendsValue === 'SmrtCollection'\n ) {\n return extendsValue;\n }\n\n // Try same-package first (common case: child and parent in same package)\n const samePackageQualified = createQualifiedName(\n currentPackage,\n extendsValue,\n );\n if (classes.has(samePackageQualified)) {\n return samePackageQualified;\n }\n\n // Try to find the parent in any registered package\n const keys = registryKeysBySimpleName(extendsValue);\n if (keys.length === 1) {\n return keys[0];\n }\n\n // Fallback: return unmodified (backward compat)\n return extendsValue;\n}\n\n// ── Public lookup functions ─────────────────────────────────\n\n/**\n * Get a registered class by name (case-insensitive).\n */\nexport function getClass(name: string): RegisteredClass | undefined {\n return findClass(name);\n}\n\n/**\n * Get a registered class by its constructor reference (O(1) WeakMap lookup).\n */\nexport function getClassByConstructor(\n ctor: SmrtObjectConstructor,\n): RegisteredClass | undefined {\n const registeredName = getConstructorIndex().get(ctor);\n if (registeredName) {\n return getClasses().get(registeredName);\n }\n return undefined;\n}\n\n/**\n * Get a registered class by its qualified name (O(1) direct lookup).\n */\nexport function getClassByQualifiedName(\n qualifiedName: string,\n): RegisteredClass | undefined {\n return getClasses().get(qualifiedName);\n}\n\n/**\n * Get a registered class by package name and class name.\n */\nexport function getClassInPackage(\n packageName: string,\n className: string,\n): RegisteredClass | undefined {\n const qualifiedName = createQualifiedName(packageName, className);\n return getClasses().get(qualifiedName);\n}\n\n/**\n * Find all registered classes with a given simple class name.\n */\nexport function findClassesByName(className: string): RegisteredClass[] {\n const matches: RegisteredClass[] = [];\n const lowerName = className.toLowerCase();\n\n for (const registered of getClasses().values()) {\n if (registered.name.toLowerCase() === lowerName) {\n matches.push(registered);\n }\n }\n\n return matches;\n}\n\n/**\n * Resolve a short class name to its qualified name.\n * @throws {Error} If no class or ambiguous classes registered\n */\nexport function resolveType(shortName: string): QualifiedClassName {\n // If already qualified, validate and return\n if (shortName.includes(':') && shortName.startsWith('@')) {\n const registered = getClassByQualifiedName(shortName as QualifiedClassName);\n if (!registered) {\n throw new Error(\n `Class \"${shortName}\" is not registered. ` +\n `Make sure the package is installed and the class is decorated with @smrt().`,\n );\n }\n return shortName as QualifiedClassName;\n }\n\n // Find all classes with this short name\n const matches = findClassesByName(shortName);\n\n if (matches.length === 0) {\n throw new Error(\n `Class \"${shortName}\" is not registered. ` +\n `Make sure the package is installed and the class is decorated with @smrt().`,\n );\n }\n\n if (matches.length > 1) {\n const packageList = matches.map((m) => ` - ${m.qualifiedName}`).join('\\n');\n throw new Error(\n `\"${shortName}\" is ambiguous. Found in multiple packages:\\n${packageList}\\n` +\n `Use the fully qualified name instead.`,\n );\n }\n\n return matches[0].qualifiedName as QualifiedClassName;\n}\n\n/**\n * Get all registered classes from a specific package.\n */\nexport function getClassesByPackage(\n packageName: string,\n): Map<string, RegisteredClass> {\n const result = new Map<string, RegisteredClass>();\n\n for (const [name, registered] of getClasses().entries()) {\n if (registered.packageName === packageName) {\n result.set(name, registered);\n }\n }\n\n return result;\n}\n\n/**\n * Get all registered classes with a specific visibility level.\n */\nexport function getClassesByVisibility(\n visibility: SmrtVisibility,\n): Map<string, RegisteredClass> {\n const result = new Map<string, RegisteredClass>();\n\n for (const [name, registered] of getClasses().entries()) {\n const classVisibility = registered.visibility || 'public';\n if (classVisibility === visibility) {\n result.set(name, registered);\n }\n }\n\n return result;\n}\n\n/**\n * Get all public registered classes.\n */\nexport function getPublicClasses(): Map<string, RegisteredClass> {\n return getClassesByVisibility('public');\n}\n\n/**\n * Get all registered classes.\n */\nexport function getAllClasses(): Map<string, RegisteredClass> {\n return new Map(getClasses());\n}\n\n/**\n * Get class names (simple names, deduplicated).\n */\nexport function getClassNames(): string[] {\n const names = Array.from(getClasses().values()).map((entry) => entry.name);\n return Array.from(new Set(names));\n}\n\n/**\n * Get lookup names for every registered class without collapsing\n * cross-package simple-name collisions.\n *\n * Prefer each registration's qualified name when available, fall back to the\n * registry key, then to the simple class name for package-less registrations.\n * De-duplicates aliases that point to the same RegisteredClass object while\n * preserving distinct packages that intentionally share a simple class name.\n */\nexport function getQualifiedClassNames(): string[] {\n const names: string[] = [];\n const seenRegistrations = new Set<RegisteredClass>();\n const seenNames = new Set<string>();\n\n for (const [key, entry] of getClasses().entries()) {\n if (seenRegistrations.has(entry)) {\n continue;\n }\n seenRegistrations.add(entry);\n\n const lookupName = entry.qualifiedName || key || entry.name;\n if (seenNames.has(lookupName)) {\n continue;\n }\n\n seenNames.add(lookupName);\n names.push(lookupName);\n }\n\n return names;\n}\n\n/**\n * Check if a class is registered (case-insensitive).\n */\nexport function hasClass(name: string): boolean {\n return findClass(name) !== undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAS,yBAAyB,YAA8B;CAC9D,MAAM,QAAQ,WAAW,YAAY;CACrC,MAAM,UAAU,WAAW;CAC3B,MAAM,uBAAO,IAAI,IAAqB;CAEtC,KAAK,MAAM,CAAC,KAAK,UAAU,QAAQ,QAAQ,GAAG;EAC5C,IAAI,MAAM,MAAM,YAAY,MAAM,OAAO;EAEzC,MAAM,WAAW,KAAK,IAAI,KAAK;EAC/B,IAAI,CAAC,UAAU;GACb,KAAK,IAAI,OAAO,GAAG;GACnB;EACF;EAGA,IAAI,IAAI,SAAS,GAAG,KAAK,CAAC,SAAS,SAAS,GAAG,GAC7C,KAAK,IAAI,OAAO,GAAG;CAEvB;CAEA,OAAO,CAAC,GAAG,KAAK,OAAO,CAAC;AAC1B;;;;;;AASA,SAAgB,sBAAsB,MAAkC;CACtE,MAAM,OAAO,yBAAyB,IAAI;CAC1C,IAAI,KAAK,WAAW,GAAG,OAAO,KAAK;AAGrC;;;;AAKA,SAAgB,wBAAwB,MAAuB;CAC7D,MAAM,QAAQ,KAAK,YAAY;CAC/B,KAAK,MAAM,SAAS,WAAW,CAAC,CAAC,OAAO,GACtC,IAAI,MAAM,MAAM,YAAY,MAAM,OAAO,OAAO;CAElD,OAAO;AACT;;;;;;;;;;;;;AAcA,SAAgB,UAAU,MAA2C;CACnE,MAAM,UAAU,WAAW;CAG3B,MAAM,aAAa,QAAQ,IAAI,IAAI;CACnC,IAAI,YACF,OAAO;CAST,IAAI,gBAAgB,IAAI,GAAG;EACzB,MAAM,EAAE,aAAa,cAAc,mBAAmB,IAAI;EAC1D,MAAM,OAAO,yBAAyB,SAAS;EAE/C,IAAI,KAAK,SAAS,GAAG;GACnB,MAAM,oBAAoB,KACvB,KAAK,QAAQ,QAAQ,IAAI,GAAG,CAAC,CAAC,CAC9B,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
|
+
{"version":3,"file":"name-resolver.js","names":[],"sources":["../../src/registry/name-resolver.ts"],"sourcesContent":["/**\n * Name resolution module for the SMRT ObjectRegistry.\n *\n * Handles class lookup, disambiguation, and qualified name resolution.\n * All functions operate on the shared globalThis state.\n *\n * Release B (#1133): classNameMap is gone — the eagerly-maintained\n * lowercase-simple-name → qualified-key[] index was removed in favor of\n * on-demand iteration over the `classes` Map. Production SMRT apps carry\n * a few hundred classes at most, so the linear scan is negligible and\n * removes an entire class of cache-sync bugs (#584, #847, #951).\n *\n * Extracted from registry.ts as part of issue #1006.\n * @see https://github.com/happyvertical/smrt/issues/1006\n * @see https://github.com/happyvertical/smrt/issues/1133\n */\n\nimport { ConfigurationError } from '../errors';\nimport type { QualifiedClassName, SmrtVisibility } from '../scanner/types.js';\nimport {\n createQualifiedName,\n isQualifiedName,\n parseQualifiedName,\n} from '../utils/qualified-names.js';\nimport { getClasses, getConstructorIndex, verboseLog } from './shared-state';\nimport type { RegisteredClass, SmrtObjectConstructor } from './types';\n\n// ── Simple-name iteration (replaces classNameMap reads) ─────────────\n\n/**\n * Return every registry key whose registered class has the given simple\n * name (case-insensitive). Replaces the old eagerly-maintained\n * `__smrtRegistryClassNameMap` lookup: we iterate `classes` instead.\n *\n * Cost is O(n) over the classes map; production SMRT apps hold low-\n * hundreds of entries so this is trivially fast. Returned keys preserve\n * insertion order, which makes the \"first match wins\" behavior of the old\n * map-based lookup deterministic in the same way.\n *\n * De-duplicates by RegisteredClass object identity so a class registered\n * under both a simple key and a promoted qualified key (a transitional\n * state during manifest merge) counts as a single entry — matching the\n * old classNameMap's behavior of storing each canonical qualified key once.\n * When that happens, the qualified key wins over the simple one.\n */\nfunction registryKeysBySimpleName(simpleName: string): string[] {\n const lower = simpleName.toLowerCase();\n const classes = getClasses();\n const seen = new Map<unknown, string>();\n\n for (const [key, value] of classes.entries()) {\n if (value.name?.toLowerCase() !== lower) continue;\n\n const existing = seen.get(value);\n if (!existing) {\n seen.set(value, key);\n continue;\n }\n\n // Two keys for the same object: prefer the qualified form.\n if (key.includes(':') && !existing.includes(':')) {\n seen.set(value, key);\n }\n }\n\n return [...seen.values()];\n}\n\n// ── Lookup functions ────────────────────────────────────────\n\n/**\n * Check if a class is already registered (case-insensitive).\n * Returns the canonical name if found, undefined otherwise. Returns\n * undefined if the simple name is ambiguous across multiple packages.\n */\nexport function getCanonicalClassName(name: string): string | undefined {\n const keys = registryKeysBySimpleName(name);\n if (keys.length === 1) return keys[0];\n // Zero matches, or ambiguous with >1 entries\n return undefined;\n}\n\n/**\n * Check if a class exists by name (case-insensitive).\n */\nexport function hasClassCaseInsensitive(name: string): boolean {\n const lower = name.toLowerCase();\n for (const value of getClasses().values()) {\n if (value.name?.toLowerCase() === lower) return true;\n }\n return false;\n}\n\n/**\n * Helper for class lookup with qualified name support.\n *\n * Lookup priority:\n * 1. Direct hit on classes map (works for qualified names as keys)\n * 2. If input contains ':', prefer direct qualified lookup, then fall back\n * to an exact/simple registration when runtime source imports registered\n * the class before package-qualified promotion happened\n * 3. Simple-name iteration by lowercase\n * - Unambiguous (1 match) → return it\n * - Ambiguous (>1 matches) → log warning, return first\n */\nexport function findClass(name: string): RegisteredClass | undefined {\n const classes = getClasses();\n\n // 1. Direct hit on classes map (fast path, works for qualified keys)\n const registered = classes.get(name);\n if (registered) {\n return registered;\n }\n\n // 2. Qualified lookup fallback for source-registered classes.\n // In workspace/dev mode a package can be imported from source before a\n // manifest-promoted qualified key exists. If we already have exactly the\n // requested package or a single unqualified registration for this class\n // name, treat it as the same class instead of forcing node_modules manifest\n // discovery.\n if (isQualifiedName(name)) {\n const { packageName, className } = parseQualifiedName(name);\n const keys = registryKeysBySimpleName(className);\n\n if (keys.length > 0) {\n const exactPackageMatch = keys\n .map((key) => classes.get(key))\n .find((candidate) => candidate?.packageName === packageName);\n\n if (exactPackageMatch) {\n return exactPackageMatch;\n }\n\n if (keys.length === 1) {\n const fallback = classes.get(keys[0]);\n if (fallback && !fallback.packageName) {\n return fallback;\n }\n }\n }\n\n return undefined;\n }\n\n // 3. Simple-name lookup\n const keys = registryKeysBySimpleName(name);\n if (keys.length > 0) {\n if (keys.length === 1) {\n return classes.get(keys[0]);\n }\n // Ambiguous — multiple packages define this class name\n // Return first match but log a warning (use resolveType() for strict behavior)\n verboseLog(\n `[registry] findClass(\"${name}\") is ambiguous — ${keys.length} matches. ` +\n `Use qualified name (e.g., ${keys[0]}) for precision.`,\n );\n return classes.get(keys[0]);\n }\n\n return undefined;\n}\n\n/**\n * Strict class lookup with package-aware disambiguation.\n *\n * Unlike `findClass()` which silently returns the first match when a simple\n * name is ambiguous, this method throws a `ConfigurationError` — making it\n * safe for inheritance-critical paths.\n *\n * @throws {ConfigurationError} When simple name is ambiguous and no package context resolves it\n * @see https://github.com/happyvertical/smrt/issues/1005\n */\nexport function findClassStrict(\n name: string,\n fromPackage?: string,\n): RegisteredClass | undefined {\n const classes = getClasses();\n\n // 1. Direct hit on classes map (fast path, works for qualified keys)\n const registered = classes.get(name);\n if (registered) {\n return registered;\n }\n\n // 2. If input is a qualified name, no fallback — it's not found\n if (isQualifiedName(name)) {\n return undefined;\n }\n\n // 3. If fromPackage provided, try constructing qualified name for direct lookup\n if (fromPackage) {\n const qualifiedAttempt = createQualifiedName(fromPackage, name);\n const byQualified = classes.get(qualifiedAttempt);\n if (byQualified) {\n return byQualified;\n }\n }\n\n // 4. Simple-name lookup\n const keys = registryKeysBySimpleName(name);\n if (keys.length > 0) {\n if (keys.length === 1) {\n return classes.get(keys[0]);\n }\n // Ambiguous — multiple packages define this class name\n // In strict mode, throw instead of silently returning first match\n throw new ConfigurationError(\n `Ambiguous class name \"${name}\" — found in ${keys.length} packages: ` +\n `${keys.join(', ')}. ` +\n `Use a qualified name (e.g., ${keys[0]}) to disambiguate.`,\n 'CONFIG_AMBIGUOUS_CLASS',\n { className: name, candidates: keys },\n );\n }\n\n return undefined;\n}\n\n/**\n * Qualify an `extends` value with the parent class's package name.\n *\n * @see https://github.com/happyvertical/smrt/issues/1004\n */\nexport function qualifyExtendsName(\n extendsValue: string,\n currentPackage: string,\n): string {\n const classes = getClasses();\n\n // Already qualified → pass through\n if (isQualifiedName(extendsValue)) {\n return extendsValue;\n }\n\n // Skip framework base classes (never registered with qualified names)\n if (\n extendsValue === 'SmrtObject' ||\n extendsValue === 'SmrtClass' ||\n extendsValue === 'SmrtCollection'\n ) {\n return extendsValue;\n }\n\n // Try same-package first (common case: child and parent in same package)\n const samePackageQualified = createQualifiedName(\n currentPackage,\n extendsValue,\n );\n if (classes.has(samePackageQualified)) {\n return samePackageQualified;\n }\n\n // Try to find the parent in any registered package\n const keys = registryKeysBySimpleName(extendsValue);\n if (keys.length === 1) {\n return keys[0];\n }\n\n // Fallback: return unmodified (backward compat)\n return extendsValue;\n}\n\n// ── Public lookup functions ─────────────────────────────────\n\n/**\n * Get a registered class by name (case-insensitive).\n */\nexport function getClass(name: string): RegisteredClass | undefined {\n return findClass(name);\n}\n\n/**\n * Get a registered class by its constructor reference (O(1) WeakMap lookup).\n */\nexport function getClassByConstructor(\n ctor: SmrtObjectConstructor,\n): RegisteredClass | undefined {\n const registeredName = getConstructorIndex().get(ctor);\n if (registeredName) {\n return getClasses().get(registeredName);\n }\n return undefined;\n}\n\n/**\n * Get a registered class by its qualified name (O(1) direct lookup).\n */\nexport function getClassByQualifiedName(\n qualifiedName: string,\n): RegisteredClass | undefined {\n return getClasses().get(qualifiedName);\n}\n\n/**\n * Get a registered class by package name and class name.\n */\nexport function getClassInPackage(\n packageName: string,\n className: string,\n): RegisteredClass | undefined {\n const qualifiedName = createQualifiedName(packageName, className);\n return getClasses().get(qualifiedName);\n}\n\n/**\n * Find all registered classes with a given simple class name.\n */\nexport function findClassesByName(className: string): RegisteredClass[] {\n const matches = new Set<RegisteredClass>();\n const lowerName = className.toLowerCase();\n\n for (const registered of getClasses().values()) {\n if (registered.name.toLowerCase() === lowerName) {\n // A source registration can retain its simple key while manifest\n // hydration adds its canonical qualified key. Both aliases designate\n // one class, so ambiguity means distinct RegisteredClass identities.\n matches.add(registered);\n }\n }\n\n return [...matches];\n}\n\n/**\n * Resolve a short class name to its qualified name.\n * @throws {Error} If no class or ambiguous classes registered\n */\nexport function resolveType(shortName: string): QualifiedClassName {\n // If already qualified, validate and return\n if (shortName.includes(':') && shortName.startsWith('@')) {\n const registered = getClassByQualifiedName(shortName as QualifiedClassName);\n if (!registered) {\n throw new Error(\n `Class \"${shortName}\" is not registered. ` +\n `Make sure the package is installed and the class is decorated with @smrt().`,\n );\n }\n return shortName as QualifiedClassName;\n }\n\n // Find all classes with this short name\n const matches = findClassesByName(shortName);\n\n if (matches.length === 0) {\n throw new Error(\n `Class \"${shortName}\" is not registered. ` +\n `Make sure the package is installed and the class is decorated with @smrt().`,\n );\n }\n\n if (matches.length > 1) {\n const packageList = matches.map((m) => ` - ${m.qualifiedName}`).join('\\n');\n throw new Error(\n `\"${shortName}\" is ambiguous. Found in multiple packages:\\n${packageList}\\n` +\n `Use the fully qualified name instead.`,\n );\n }\n\n return matches[0].qualifiedName as QualifiedClassName;\n}\n\n/**\n * Get all registered classes from a specific package.\n */\nexport function getClassesByPackage(\n packageName: string,\n): Map<string, RegisteredClass> {\n const result = new Map<string, RegisteredClass>();\n\n for (const [name, registered] of getClasses().entries()) {\n if (registered.packageName === packageName) {\n result.set(name, registered);\n }\n }\n\n return result;\n}\n\n/**\n * Get all registered classes with a specific visibility level.\n */\nexport function getClassesByVisibility(\n visibility: SmrtVisibility,\n): Map<string, RegisteredClass> {\n const result = new Map<string, RegisteredClass>();\n\n for (const [name, registered] of getClasses().entries()) {\n const classVisibility = registered.visibility || 'public';\n if (classVisibility === visibility) {\n result.set(name, registered);\n }\n }\n\n return result;\n}\n\n/**\n * Get all public registered classes.\n */\nexport function getPublicClasses(): Map<string, RegisteredClass> {\n return getClassesByVisibility('public');\n}\n\n/**\n * Get all registered classes.\n */\nexport function getAllClasses(): Map<string, RegisteredClass> {\n return new Map(getClasses());\n}\n\n/**\n * Get class names (simple names, deduplicated).\n */\nexport function getClassNames(): string[] {\n const names = Array.from(getClasses().values()).map((entry) => entry.name);\n return Array.from(new Set(names));\n}\n\n/**\n * Get lookup names for every registered class without collapsing\n * cross-package simple-name collisions.\n *\n * Prefer each registration's qualified name when available, fall back to the\n * registry key, then to the simple class name for package-less registrations.\n * De-duplicates aliases that point to the same RegisteredClass object while\n * preserving distinct packages that intentionally share a simple class name.\n */\nexport function getQualifiedClassNames(): string[] {\n const names: string[] = [];\n const seenRegistrations = new Set<RegisteredClass>();\n const seenNames = new Set<string>();\n\n for (const [key, entry] of getClasses().entries()) {\n if (seenRegistrations.has(entry)) {\n continue;\n }\n seenRegistrations.add(entry);\n\n const lookupName = entry.qualifiedName || key || entry.name;\n if (seenNames.has(lookupName)) {\n continue;\n }\n\n seenNames.add(lookupName);\n names.push(lookupName);\n }\n\n return names;\n}\n\n/**\n * Check if a class is registered (case-insensitive).\n */\nexport function hasClass(name: string): boolean {\n return findClass(name) !== undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAS,yBAAyB,YAA8B;CAC9D,MAAM,QAAQ,WAAW,YAAY;CACrC,MAAM,UAAU,WAAW;CAC3B,MAAM,uBAAO,IAAI,IAAqB;CAEtC,KAAK,MAAM,CAAC,KAAK,UAAU,QAAQ,QAAQ,GAAG;EAC5C,IAAI,MAAM,MAAM,YAAY,MAAM,OAAO;EAEzC,MAAM,WAAW,KAAK,IAAI,KAAK;EAC/B,IAAI,CAAC,UAAU;GACb,KAAK,IAAI,OAAO,GAAG;GACnB;EACF;EAGA,IAAI,IAAI,SAAS,GAAG,KAAK,CAAC,SAAS,SAAS,GAAG,GAC7C,KAAK,IAAI,OAAO,GAAG;CAEvB;CAEA,OAAO,CAAC,GAAG,KAAK,OAAO,CAAC;AAC1B;;;;;;AASA,SAAgB,sBAAsB,MAAkC;CACtE,MAAM,OAAO,yBAAyB,IAAI;CAC1C,IAAI,KAAK,WAAW,GAAG,OAA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K,UAAU,MAAM,IAAI;CACzE,OAAO,MAAM,KAAK,IAAI,IAAI,KAAK,CAAC;AAClC;;;;;;;;;;AAWA,SAAgB,yBAAmC;CACjD,MAAM,QAAkB,CAAC;CACzB,MAAM,oCAAoB,IAAI,IAAqB;CACnD,MAAM,4BAAY,IAAI,IAAY;CAElC,KAAK,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,CAAC,QAAQ,GAAG;EACjD,IAAI,kBAAkB,IAAI,KAAK,GAC7B;EAEF,kBAAkB,IAAI,KAAK;EAE3B,MAAM,aAAa,MAAM,iBAAiB,OAAO,MAAM;EACvD,IAAI,UAAU,IAAI,UAAU,GAC1B;EAGF,UAAU,IAAI,UAAU;EACxB,MAAM,KAAK,UAAU;CACvB;CAEA,OAAO;AACT;;;;AAKA,SAAgB,SAAS,MAAuB;CAC9C,OAAO,UAAU,IAAI,MAAM,KAAA;AAC7B"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { RelationshipMetadata } from './types';
|
|
2
|
+
/** Canonical target of the field's declaring class, including inherited fields. */
|
|
3
|
+
export declare function resolveRelationshipTarget(className: string, fieldName: string): string | null | undefined;
|
|
2
4
|
/**
|
|
3
5
|
* Build dependency graph from foreignKey relationships.
|
|
4
6
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relationship-graph.d.ts","sourceRoot":"","sources":["../../src/registry/relationship-graph.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"relationship-graph.d.ts","sourceRoot":"","sources":["../../src/registry/relationship-graph.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EAGV,oBAAoB,EACrB,MAAM,SAAS,CAAC;AAkCjB,mFAAmF;AACnF,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,MAAM,GAAG,IAAI,GAAG,SAAS,CAe3B;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAgC1D;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,GAAG,CAAC,MAAM,EAAE,oBAAoB,EAAE,CAAC,CA6FxE"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getClasses } from "./shared-state.js";
|
|
2
2
|
import { findClass } from "./name-resolver.js";
|
|
3
|
+
import { getInheritanceChain } from "./inheritance-resolver.js";
|
|
3
4
|
//#region src/registry/relationship-graph.ts
|
|
4
5
|
/**
|
|
5
6
|
* Relationship graph and dependency resolution module for the SMRT ObjectRegistry.
|
|
@@ -9,6 +10,37 @@ import { findClass } from "./name-resolver.js";
|
|
|
9
10
|
* Extracted from registry.ts as part of issue #1006.
|
|
10
11
|
* @see https://github.com/happyvertical/smrt/issues/1006
|
|
11
12
|
*/
|
|
13
|
+
/** Resolve lazily: the target may register after the decorated child. */
|
|
14
|
+
function resolveTarget(registered, field) {
|
|
15
|
+
const classes = getClasses();
|
|
16
|
+
const ctor = field._meta?.relatedConstructor;
|
|
17
|
+
if (typeof ctor === "function") {
|
|
18
|
+
const match = Array.from(classes).find(([, entry]) => entry.constructor === ctor);
|
|
19
|
+
return match ? match[1].qualifiedName ?? match[0] : null;
|
|
20
|
+
}
|
|
21
|
+
const related = field.related;
|
|
22
|
+
if (!related) return null;
|
|
23
|
+
if (related.includes(":")) return findClass(related)?.qualifiedName ?? related;
|
|
24
|
+
const local = classes.get(`${registered.packageName}:${related}`);
|
|
25
|
+
if (local) return local.qualifiedName ?? `${registered.packageName}:${related}`;
|
|
26
|
+
const matches = Array.from(classes).filter(([, entry]) => entry.name === related);
|
|
27
|
+
const distinct = [...new Map(matches.map((match) => [match[1], match])).values()];
|
|
28
|
+
if (distinct.length === 0) return void 0;
|
|
29
|
+
if (distinct.length !== 1) return null;
|
|
30
|
+
const match = matches.find(([key]) => key.includes(":")) ?? distinct[0];
|
|
31
|
+
return match[1].qualifiedName ?? match[0];
|
|
32
|
+
}
|
|
33
|
+
/** Canonical target of the field's declaring class, including inherited fields. */
|
|
34
|
+
function resolveRelationshipTarget(className, fieldName) {
|
|
35
|
+
for (const name of [className, ...[...getInheritanceChain(className)].reverse()]) {
|
|
36
|
+
const registered = findClass(name);
|
|
37
|
+
const field = registered?.fields.get(fieldName);
|
|
38
|
+
if (registered && field) return resolveTarget(registered, {
|
|
39
|
+
...field,
|
|
40
|
+
related: field.related?.split(".")[0]
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
12
44
|
/**
|
|
13
45
|
* Build dependency graph from foreignKey relationships.
|
|
14
46
|
*
|
|
@@ -39,45 +71,68 @@ function getDependencyGraph() {
|
|
|
39
71
|
function getRelationshipMap() {
|
|
40
72
|
const classes = getClasses();
|
|
41
73
|
const relationshipMap = /* @__PURE__ */ new Map();
|
|
42
|
-
|
|
43
|
-
for (const [
|
|
44
|
-
|
|
74
|
+
const simpleNameEntries = /* @__PURE__ */ new Map();
|
|
75
|
+
for (const [key, entry] of classes) {
|
|
76
|
+
relationshipMap.set(entry.qualifiedName || key, []);
|
|
77
|
+
const simpleName = entry.name || key;
|
|
78
|
+
const entries = simpleNameEntries.get(simpleName) ?? /* @__PURE__ */ new Set();
|
|
79
|
+
entries.add(entry);
|
|
80
|
+
simpleNameEntries.set(simpleName, entries);
|
|
81
|
+
}
|
|
82
|
+
for (const [key, registered] of classes) {
|
|
83
|
+
const simpleName = registered.name || key;
|
|
84
|
+
const sourceQualifiedClass = registered.qualifiedName || key;
|
|
45
85
|
const relationships = [];
|
|
46
86
|
for (const [fieldName, field] of registered.fields) {
|
|
47
87
|
if (field.type === "foreignKey" && field.related) relationships.push({
|
|
48
88
|
sourceClass: simpleName,
|
|
89
|
+
sourceQualifiedClass,
|
|
49
90
|
fieldName,
|
|
50
91
|
targetClass: field.related,
|
|
92
|
+
targetQualifiedClass: resolveTarget(registered, field),
|
|
51
93
|
type: "foreignKey",
|
|
52
94
|
options: field._meta
|
|
53
95
|
});
|
|
54
96
|
if (field.type === "crossPackageRef" && field.related) relationships.push({
|
|
55
97
|
sourceClass: simpleName,
|
|
98
|
+
sourceQualifiedClass,
|
|
56
99
|
fieldName,
|
|
57
100
|
targetClass: field.related,
|
|
101
|
+
targetQualifiedClass: resolveTarget(registered, field),
|
|
58
102
|
type: "crossPackageRef",
|
|
59
103
|
options: field._meta
|
|
60
104
|
});
|
|
61
105
|
if (field.type === "oneToMany" && field.related) relationships.push({
|
|
62
106
|
sourceClass: simpleName,
|
|
107
|
+
sourceQualifiedClass,
|
|
63
108
|
fieldName,
|
|
64
109
|
targetClass: field.related,
|
|
110
|
+
targetQualifiedClass: resolveTarget(registered, field),
|
|
65
111
|
type: "oneToMany",
|
|
66
112
|
options: field._meta
|
|
67
113
|
});
|
|
68
114
|
if (field.type === "manyToMany" && field.related) relationships.push({
|
|
69
115
|
sourceClass: simpleName,
|
|
116
|
+
sourceQualifiedClass,
|
|
70
117
|
fieldName,
|
|
71
118
|
targetClass: field.related,
|
|
119
|
+
targetQualifiedClass: resolveTarget(registered, field),
|
|
72
120
|
type: "manyToMany",
|
|
73
121
|
options: field._meta
|
|
74
122
|
});
|
|
75
123
|
}
|
|
76
|
-
relationshipMap.set(
|
|
124
|
+
relationshipMap.set(registered.qualifiedName || key, relationships);
|
|
125
|
+
}
|
|
126
|
+
for (const [key, registered] of classes) {
|
|
127
|
+
const simpleName = registered.name || key;
|
|
128
|
+
if (simpleNameEntries.get(simpleName)?.size !== 1) continue;
|
|
129
|
+
const qualifiedName = registered.qualifiedName || key;
|
|
130
|
+
const relationships = relationshipMap.get(qualifiedName);
|
|
131
|
+
if (relationships) relationshipMap.set(simpleName, relationships);
|
|
77
132
|
}
|
|
78
133
|
return relationshipMap;
|
|
79
134
|
}
|
|
80
135
|
//#endregion
|
|
81
|
-
export { getDependencyGraph, getRelationshipMap };
|
|
136
|
+
export { getDependencyGraph, getRelationshipMap, resolveRelationshipTarget };
|
|
82
137
|
|
|
83
138
|
//# sourceMappingURL=relationship-graph.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relationship-graph.js","names":[],"sources":["../../src/registry/relationship-graph.ts"],"sourcesContent":["/**\n * Relationship graph and dependency resolution module for the SMRT ObjectRegistry.\n *\n * Builds relationship maps and dependency graphs from registered class fields.\n *\n * Extracted from registry.ts as part of issue #1006.\n * @see https://github.com/happyvertical/smrt/issues/1006\n */\n\nimport { findClass } from './name-resolver';\nimport { getClasses } from './shared-state';\nimport type { RelationshipMetadata } from './types';\n\n/**\n * Build dependency graph from foreignKey relationships.\n *\n * Returns a map where keys are class names and values are arrays\n * of class names that the key depends on (via foreignKey fields).\n */\nexport function getDependencyGraph(): Map<string, string[]> {\n const classes = getClasses();\n const graph = new Map<string, string[]>();\n\n // Initialize graph with all registered classes\n for (const [_key, entry] of classes) {\n graph.set(entry.name || _key, []);\n }\n\n // Scan all fields for foreignKey relationships\n for (const [_key, registered] of classes) {\n const simpleName = registered.name || _key;\n const dependencies: string[] = [];\n\n for (const [_fieldName, field] of registered.fields) {\n if (field.type === 'foreignKey' && field.related) {\n const relatedClass = field.related;\n // Skip self-references (table can reference itself after creation)\n // Only add if the related class is registered and not self\n if (\n relatedClass !== simpleName &&\n findClass(relatedClass) !== undefined\n ) {\n dependencies.push(relatedClass);\n }\n }\n }\n\n graph.set(simpleName, dependencies);\n }\n\n return graph;\n}\n\n/**\n * Build comprehensive relationship map from all field types.\n *\n * Returns a map containing all relationships (foreignKey, oneToMany, manyToMany)\n * discovered in registered classes.\n */\nexport function getRelationshipMap(): Map<string, RelationshipMetadata[]> {\n const classes = getClasses();\n const relationshipMap = new Map<string, RelationshipMetadata[]>();\n\n // Initialize map with all registered classes\n for (const [_key, entry] of classes) {\n relationshipMap.set(entry.name || _key, []);\n }\n\n // Scan all fields for relationship types\n for (const [_key, registered] of classes) {\n const simpleName = registered.name || _key;\n const relationships: RelationshipMetadata[] = [];\n\n for (const [fieldName, field] of registered.fields) {\n // Check for foreignKey relationships\n if (field.type === 'foreignKey' && field.related) {\n relationships.push({\n sourceClass: simpleName,\n fieldName,\n targetClass: field.related,\n type: 'foreignKey',\n options: field._meta,\n });\n }\n\n // Check for crossPackageRef relationships (cross-package, no DDL FK)\n if (field.type === 'crossPackageRef' && field.related) {\n relationships.push({\n sourceClass: simpleName,\n fieldName,\n targetClass: field.related,\n type: 'crossPackageRef',\n options: field._meta,\n });\n }\n\n // Check for oneToMany relationships\n if (field.type === 'oneToMany' && field.related) {\n relationships.push({\n sourceClass: simpleName,\n fieldName,\n targetClass: field.related,\n type: 'oneToMany',\n options: field._meta,\n });\n }\n\n // Check for manyToMany relationships\n if (field.type === 'manyToMany' && field.related) {\n relationships.push({\n sourceClass: simpleName,\n fieldName,\n targetClass: field.related,\n type: 'manyToMany',\n options: field._meta,\n });\n }\n }\n\n relationshipMap.set(simpleName, relationships);\n }\n\n return relationshipMap;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAmBA,SAAgB,qBAA4C;CAC1D,MAAM,UAAU,WAAW;CAC3B,MAAM,wBAAQ,IAAI,IAAsB;CAGxC,KAAK,MAAM,CAAC,MAAM,UAAU,SAC1B,MAAM,IAAI,MAAM,QAAQ,MAAM,CAAC,CAAC;CAIlC,KAAK,MAAM,CAAC,MAAM,eAAe,SAAS;EACxC,MAAM,aAAa,WAAW,QAAQ;EACtC,MAAM,eAAyB,CAAC;EAEhC,KAAK,MAAM,CAAC,YAAY,UAAU,WAAW,QAC3C,IAAI,MAAM,SAAS,gBAAgB,MAAM,SAAS;GAChD,MAAM,eAAe,MAAM;GAG3B,IACE,iBAAiB,cACjB,UAAU,YAAY,MAAM,KAAA,GAE5B,aAAa,KAAK,YAAY;EAElC;EAGF,MAAM,IAAI,YAAY,YAAY;CACpC;CAEA,OAAO;AACT;;;;;;;AAQA,SAAgB,qBAA0D;CACxE,MAAM,UAAU,WAAW;CAC3B,MAAM,kCAAkB,IAAI,IAAoC;CAGhE,KAAK,MAAM,CAAC,MAAM,UAAU,SAC1B,gBAAgB,IAAI,MAAM,QAAQ,MAAM,CAAC,CAAC;CAI5C,KAAK,MAAM,CAAC,MAAM,eAAe,SAAS;EACxC,MAAM,aAAa,WAAW,QAAQ;EACtC,MAAM,gBAAwC,CAAC;EAE/C,KAAK,MAAM,CAAC,WAAW,UAAU,WAAW,QAAQ;GAElD,IAAI,MAAM,SAAS,gBAAgB,MAAM,SACvC,cAAc,KAAK;IACjB,aAAa;IACb;IACA,aAAa,MAAM;IACnB,MAAM;IACN,SAAS,MAAM;GACjB,CAAC;GAIH,IAAI,MAAM,SAAS,qBAAqB,MAAM,SAC5C,cAAc,KAAK;IACjB,aAAa;IACb;IACA,aAAa,MAAM;IACnB,MAAM;IACN,SAAS,MAAM;GACjB,CAAC;GAIH,IAAI,MAAM,SAAS,eAAe,MAAM,SACtC,cAAc,KAAK;IACjB,aAAa;IACb;IACA,aAAa,MAAM;IACnB,MAAM;IACN,SAAS,MAAM;GACjB,CAAC;GAIH,IAAI,MAAM,SAAS,gBAAgB,MAAM,SACvC,cAAc,KAAK;IACjB,aAAa;IACb;IACA,aAAa,MAAM;IACnB,MAAM;IACN,SAAS,MAAM;GACjB,CAAC;EAEL;EAEA,gBAAgB,IAAI,YAAY,aAAa;CAC/C;CAEA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"relationship-graph.js","names":[],"sources":["../../src/registry/relationship-graph.ts"],"sourcesContent":["/**\n * Relationship graph and dependency resolution module for the SMRT ObjectRegistry.\n *\n * Builds relationship maps and dependency graphs from registered class fields.\n *\n * Extracted from registry.ts as part of issue #1006.\n * @see https://github.com/happyvertical/smrt/issues/1006\n */\n\nimport { getInheritanceChain } from './inheritance-resolver';\nimport { findClass } from './name-resolver';\nimport { getClasses } from './shared-state';\nimport type {\n RegisteredClass,\n RegisteredField,\n RelationshipMetadata,\n} from './types';\n\n/** Resolve lazily: the target may register after the decorated child. */\nfunction resolveTarget(\n registered: RegisteredClass,\n field: RegisteredField,\n): string | null | undefined {\n const classes = getClasses();\n const ctor = field._meta?.relatedConstructor;\n if (typeof ctor === 'function') {\n const match = Array.from(classes).find(\n ([, entry]) => entry.constructor === ctor,\n );\n return match ? (match[1].qualifiedName ?? match[0]) : null;\n }\n const related = field.related;\n if (!related) return null;\n if (related.includes(':'))\n return findClass(related)?.qualifiedName ?? related;\n const local = classes.get(`${registered.packageName}:${related}`);\n if (local)\n return local.qualifiedName ?? `${registered.packageName}:${related}`;\n const matches = Array.from(classes).filter(\n ([, entry]) => entry.name === related,\n );\n const distinct = [\n ...new Map(matches.map((match) => [match[1], match])).values(),\n ];\n if (distinct.length === 0) return undefined;\n if (distinct.length !== 1) return null;\n const match = matches.find(([key]) => key.includes(':')) ?? distinct[0];\n return match[1].qualifiedName ?? match[0];\n}\n\n/** Canonical target of the field's declaring class, including inherited fields. */\nexport function resolveRelationshipTarget(\n className: string,\n fieldName: string,\n): string | null | undefined {\n for (const name of [\n className,\n ...[...getInheritanceChain(className)].reverse(),\n ]) {\n const registered = findClass(name);\n const field = registered?.fields.get(fieldName);\n if (registered && field) {\n return resolveTarget(registered, {\n ...field,\n related: field.related?.split('.')[0],\n });\n }\n }\n return undefined;\n}\n\n/**\n * Build dependency graph from foreignKey relationships.\n *\n * Returns a map where keys are class names and values are arrays\n * of class names that the key depends on (via foreignKey fields).\n */\nexport function getDependencyGraph(): Map<string, string[]> {\n const classes = getClasses();\n const graph = new Map<string, string[]>();\n\n // Initialize graph with all registered classes\n for (const [_key, entry] of classes) {\n graph.set(entry.name || _key, []);\n }\n\n // Scan all fields for foreignKey relationships\n for (const [_key, registered] of classes) {\n const simpleName = registered.name || _key;\n const dependencies: string[] = [];\n\n for (const [_fieldName, field] of registered.fields) {\n if (field.type === 'foreignKey' && field.related) {\n const relatedClass = field.related;\n // Skip self-references (table can reference itself after creation)\n // Only add if the related class is registered and not self\n if (\n relatedClass !== simpleName &&\n findClass(relatedClass) !== undefined\n ) {\n dependencies.push(relatedClass);\n }\n }\n }\n\n graph.set(simpleName, dependencies);\n }\n\n return graph;\n}\n\n/**\n * Build comprehensive relationship map from all field types.\n *\n * Returns a map containing all relationships (foreignKey, oneToMany, manyToMany)\n * discovered in registered classes.\n */\nexport function getRelationshipMap(): Map<string, RelationshipMetadata[]> {\n const classes = getClasses();\n const relationshipMap = new Map<string, RelationshipMetadata[]>();\n const simpleNameEntries = new Map<string, Set<RegisteredClass>>();\n\n // Initialize map with all registered classes\n for (const [key, entry] of classes) {\n // The registry is qualified-name keyed. Keep relationship buckets on that\n // canonical identity as well: classes in separate packages may share a\n // simple name, and a later empty declaration must not overwrite an earlier\n // class's relationships.\n relationshipMap.set(entry.qualifiedName || key, []);\n const simpleName = entry.name || key;\n const entries = simpleNameEntries.get(simpleName) ?? new Set();\n entries.add(entry);\n simpleNameEntries.set(simpleName, entries);\n }\n\n // Scan all fields for relationship types\n for (const [key, registered] of classes) {\n const simpleName = registered.name || key;\n const sourceQualifiedClass = registered.qualifiedName || key;\n const relationships: RelationshipMetadata[] = [];\n\n for (const [fieldName, field] of registered.fields) {\n // Check for foreignKey relationships\n if (field.type === 'foreignKey' && field.related) {\n relationships.push({\n sourceClass: simpleName,\n sourceQualifiedClass,\n fieldName,\n targetClass: field.related,\n targetQualifiedClass: resolveTarget(registered, field),\n type: 'foreignKey',\n options: field._meta,\n });\n }\n\n // Check for crossPackageRef relationships (cross-package, no DDL FK)\n if (field.type === 'crossPackageRef' && field.related) {\n relationships.push({\n sourceClass: simpleName,\n sourceQualifiedClass,\n fieldName,\n targetClass: field.related,\n targetQualifiedClass: resolveTarget(registered, field),\n type: 'crossPackageRef',\n options: field._meta,\n });\n }\n\n // Check for oneToMany relationships\n if (field.type === 'oneToMany' && field.related) {\n relationships.push({\n sourceClass: simpleName,\n sourceQualifiedClass,\n fieldName,\n targetClass: field.related,\n targetQualifiedClass: resolveTarget(registered, field),\n type: 'oneToMany',\n options: field._meta,\n });\n }\n\n // Check for manyToMany relationships\n if (field.type === 'manyToMany' && field.related) {\n relationships.push({\n sourceClass: simpleName,\n sourceQualifiedClass,\n fieldName,\n targetClass: field.related,\n targetQualifiedClass: resolveTarget(registered, field),\n type: 'manyToMany',\n options: field._meta,\n });\n }\n }\n\n relationshipMap.set(registered.qualifiedName || key, relationships);\n }\n\n // Preserve the public simple-name map contract where that name identifies\n // exactly one registered class. Colliding names intentionally have no alias:\n // callers with a constructor must use the qualified bucket above.\n for (const [key, registered] of classes) {\n const simpleName = registered.name || key;\n if (simpleNameEntries.get(simpleName)?.size !== 1) continue;\n const qualifiedName = registered.qualifiedName || key;\n const relationships = relationshipMap.get(qualifiedName);\n if (relationships) relationshipMap.set(simpleName, relationships);\n }\n\n return relationshipMap;\n}\n"],"mappings":";;;;;;;;;;;;;AAmBA,SAAS,cACP,YACA,OAC2B;CAC3B,MAAM,UAAU,WAAW;CAC3B,MAAM,OAAO,MAAM,OAAO;CAC1B,IAAI,OAAO,SAAS,YAAY;EAC9B,MAAM,QAAQ,MAAM,KAAK,OAAO,CAAC,CAAC,MAC/B,GAAG,WAAW,MAAM,gBAAgB,IACvC;EACA,OAAO,QAAS,MAAM,EAAE,CAAC,iBAAiB,MAAM,KAAM;CACxD;CACA,MAAM,UAAU,MAAM;CACtB,IAAI,CAAC,SAAS,OAAO;CACrB,IAAI,QAAQ,SAAS,GAAG,GACtB,OAAO,UAAU,OAAO,CAAC,EAAE,iBAAiB;CAC9C,MAAM,QAAQ,QAAQ,IAAI,GAAG,WAAW,YAAY,GAAG,SAAS;CAChE,IAAI,OACF,OAAO,MAAM,iBAAiB,GAAG,WAAW,YAAY,GAAG;CAC7D,MAAM,UAAU,MAAM,KAAK,OAAO,CAAC,CAAC,QACjC,GAAG,WAAW,MAAM,SAAS,OAChC;CACA,MAAM,WAAW,CACf,GAAG,IAAI,IAAI,QAAQ,KAAK,UAAU,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAC/D;CACA,IAAI,SAAS,WAAW,GAAG,OAAO,KAAA;CA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AAgB,WAAW,iBAAiB;EAClD,MAAM,gBAAgB,gBAAgB,IAAI,aAAa;EACvD,IAAI,eAAe,gBAAgB,IAAI,YAAY,aAAa;CAClE;CAEA,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-builder.d.ts","sourceRoot":"","sources":["../../src/registry/schema-builder.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAc7D,OAAO,KAAK,EACV,gBAAgB,EAEhB,gBAAgB,EAChB,WAAW,EACZ,MAAM,oBAAoB,CAAC;AAoL5B;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAIpE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,cAAc,GACtB,MAAM,GAAG,SAAS,CAWpB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAkB7D;
|
|
1
|
+
{"version":3,"file":"schema-builder.d.ts","sourceRoot":"","sources":["../../src/registry/schema-builder.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAc7D,OAAO,KAAK,EACV,gBAAgB,EAEhB,gBAAgB,EAChB,WAAW,EACZ,MAAM,oBAAoB,CAAC;AAoL5B;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAIpE;AAED;;;;;;;;;;;;;;;;GAgBG;A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EAAE,eAAe,CAAC,MAAM,CAAC,GACjC,WAAW,CAqBb"}
|
|
@@ -203,7 +203,10 @@ function applyContributorForeignKeys(tableSchema, contributor) {
|
|
|
203
203
|
column.foreignKey = void 0;
|
|
204
204
|
continue;
|
|
205
205
|
}
|
|
206
|
-
const [
|
|
206
|
+
const [legacyTargetName, declaredTargetColumn] = field.related.split(".");
|
|
207
|
+
const resolvedTarget = ObjectRegistry.resolveRelationshipTarget(contributor.qualifiedName, fieldName);
|
|
208
|
+
if (resolvedTarget === null) throw new Error(`Cannot resolve foreign key ${contributor.qualifiedName}.${fieldName}: target constructor is unregistered or the target name is ambiguous`);
|
|
209
|
+
const targetName = resolvedTarget ?? legacyTargetName;
|
|
207
210
|
const targetBase = ObjectRegistry.getSTIBase(targetName) || targetName;
|
|
208
211
|
const registeredTarget = ObjectRegistry.getClass(targetBase);
|
|
209
212
|
const targetColumn = declaredTargetColumn || Array.from(ObjectRegistry.getFields(targetBase).entries()).find(([, targetField]) => targetField._meta?.primaryKey === true)?.[0] || "id";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-builder.js","names":[],"sources":["../../src/registry/schema-builder.ts"],"sourcesContent":["/**\n * Schema building logic for the SMRT ObjectRegistry.\n *\n * Extracted from registry.ts as part of issue #1006.\n */\n\nimport { ObjectRegistry } from '../registry';\nimport type { FieldDefinition } from '../scanner/types.js';\nimport { conflictIndexName } from '../schema/conflict-target.js';\nimport { getDDLStrategy } from '../schema/ddl/index.js';\nimport type { DatabaseEngine } from '../schema/ddl/types.js';\nimport {\n renderForeignKeyConstraint,\n schemaForeignKeys,\n} from '../schema/foreign-key-ddl.js';\nimport {\n requireForeignKeyAction,\n resolveForeignKeyDeleteAction,\n} from '../schema/foreign-key-policy.js';\nimport { shortenIdentifier } from '../schema/index-utils.js';\nimport {\n formatDefaultValue as formatDefaultValueShared,\n quoteIdentifier,\n} from '../schema/sql-identifiers.js';\nimport type {\n ColumnDefinition,\n IndexDefinition,\n SchemaDefinition,\n SQLDataType,\n} from '../schema/types.js';\nimport { classnameToTablename, toSnakeCase } from '../utils';\nimport {\n type CollectionRegistrationLookup,\n isCollectionRegistration,\n} from './collection-resolution';\nimport { isFrameworkBaseClass } from './framework-base-classes';\nimport { readFieldAttribute } from './manifest-field-merge';\nimport { findClass } from './name-resolver';\nimport { getClasses, getCollectionTableNames } from './shared-state';\nimport type { RegisteredClass } from './types';\n\ntype ForeignKeyAction = NonNullable<\n NonNullable<ColumnDefinition['foreignKey']>['onDelete']\n>;\n\nconst collectionRegistrationLookup: CollectionRegistrationLookup = {\n findClass,\n findClassInPackage: (packageName, className) =>\n ObjectRegistry.getClassInPackage(packageName, className),\n getInheritanceChain: (className) =>\n ObjectRegistry.getInheritanceChain(className),\n};\n\nfunction applyDecoratorSqlTypeOverrides(\n className: string,\n columns: Record<string, ColumnDefinition>,\n): Record<string, ColumnDefinition> {\n const decorators = ObjectRegistry.getFieldDecorators(className);\n if (!decorators.size) {\n return columns;\n }\n\n for (const [fieldName, options] of decorators) {\n if (!options?.sqlType) {\n continue;\n }\n\n const columnName = toSnakeCase(fieldName);\n const existing = columns[columnName];\n if (!existing) {\n continue;\n }\n\n const referenceKind = getReferenceKind(options as FieldDefinition);\n columns[columnName] = {\n ...existing,\n type: String(options.sqlType).toUpperCase() as SQLDataType,\n ...(referenceKind ? { referenceKind } : {}),\n };\n }\n\n return columns;\n}\n\nfunction mergeRuntimeFieldColumns(\n className: string,\n schemaColumns: Record<string, ColumnDefinition> | undefined,\n fields: Map<string, FieldDefinition>,\n options?: FieldsToColumnsOptions,\n): Record<string, ColumnDefinition> {\n const columnsToUse = { ...(schemaColumns || {}) };\n\n if (fields.size > 0) {\n const fieldColumns = fieldsToColumns(fields, options);\n for (const [columnName, columnDef] of Object.entries(fieldColumns)) {\n if (!columnsToUse[columnName]) {\n columnsToUse[columnName] = columnDef;\n }\n }\n\n for (const [fieldName, fieldDef] of fields) {\n const columnName = toSnakeCase(fieldName);\n const existing = columnsToUse[columnName];\n if (!existing) {\n continue;\n }\n\n const sqlType =\n fieldDef._meta?.sqlType ||\n (fieldDef as unknown as { sqlType?: string }).sqlType;\n const referenceKind = getReferenceKind(fieldDef);\n columnsToUse[columnName] = {\n ...existing,\n ...(sqlType\n ? { type: String(sqlType).toUpperCase() as SQLDataType }\n : {}),\n ...(referenceKind ? { referenceKind } : {}),\n };\n }\n }\n\n applyDecoratorSqlTypeOverrides(className, columnsToUse);\n return columnsToUse;\n}\n\nfunction getReferenceKind(\n fieldDef: FieldDefinition,\n): ColumnDefinition['referenceKind'] | undefined {\n if (\n (\n fieldDef as unknown as {\n __tenancy?: { isTenantIdField?: boolean };\n }\n ).__tenancy?.isTenantIdField ||\n fieldDef._meta?.__tenancy?.isTenantIdField\n ) {\n return 'tenantId';\n }\n\n if (fieldDef.type === 'foreignKey') {\n return 'foreignKey';\n }\n\n if (fieldDef.type === 'crossPackageRef') {\n return 'crossPackageRef';\n }\n\n return undefined;\n}\n\nfunction shouldEmitDefault(\n fieldDef: FieldDefinition,\n sqlType: SQLDataType,\n defaultValue: unknown,\n) {\n return !(\n getReferenceKind(fieldDef) === 'tenantId' &&\n sqlType === 'UUID' &&\n defaultValue === ''\n );\n}\n\n/**\n * Fallback base columns for a table whose contributing class carries no\n * manifest columns.\n *\n * These mirror what the manifest schema generators emit for the same table\n * (`generateSchemaFromManifest` / `generateSTISchemaFromManifest`), so a table\n * assembled from runtime field metadata alone has the same NOT NULL and\n * DEFAULT shape as one assembled from a manifest. Divergence here is what made\n * the merged table shape depend on which class registered first (#2372).\n */\nfunction createBaseColumns(\n registered: {\n config?: { idType?: 'uuid' | 'text' };\n },\n isSTI: boolean,\n): Record<string, ColumnDefinition> {\n const baseColumns: Record<string, ColumnDefinition> = {\n id: {\n type: registered.config?.idType === 'text' ? 'TEXT' : 'UUID',\n primaryKey: true,\n notNull: true,\n referenceKind: 'id',\n },\n slug: { type: 'TEXT', notNull: true },\n context: { type: 'TEXT', notNull: true, defaultValue: '' },\n created_at: {\n type: 'TIMESTAMP',\n notNull: true,\n defaultValue: 'current_timestamp',\n },\n updated_at: {\n type: 'TIMESTAMP',\n notNull: true,\n defaultValue: 'current_timestamp',\n },\n };\n\n // STI tables also carry the discriminator and the meta payload column\n // (issue #690: db:diff needs them to detect schema changes).\n if (isSTI) {\n baseColumns._meta_type = { type: 'TEXT', notNull: true };\n baseColumns._meta_data = { type: 'JSON', notNull: false };\n }\n\n return baseColumns;\n}\n\n/**\n * Get cached schema definition for a registered class\n *\n * @param name - Name of the registered class\n * @returns Schema definition or undefined if not found\n * @example\n * ```typescript\n * const schema = getSchema('Product');\n * console.log(schema.tableName); // 'products'\n * console.log(schema.ddl); // 'CREATE TABLE...'\n * ```\n */\nexport function getSchema(name: string): SchemaDefinition | undefined {\n // Issue #951: Use findClass for multi-strategy lookup\n const registered = findClass(name);\n return registered?.schema;\n}\n\n/**\n * Get SQL DDL statement for a registered class\n *\n * @param name - Name of the registered class\n * Cached manifest DDL contains abstract types and is not safe to execute on\n * PostgreSQL. New executable paths must pass a target engine. Omitting it is\n * retained for backward compatibility with consumers that only inspect the\n * legacy engine-neutral manifest string.\n *\n * @param engine - Database engine that will execute the DDL\n * @returns Engine-specific SQL DDL, or the legacy cached DDL when omitted\n * @example\n * ```typescript\n * const ddl = ObjectRegistry.getSchemaDDL('Product', 'postgres');\n * await db.query(ddl);\n * ```\n */\nexport function getSchemaDDL(\n name: string,\n engine?: DatabaseEngine,\n): string | undefined {\n const schema = getSchema(name);\n if (!schema) return undefined;\n if (engine && Object.keys(schema.columns).length === 0) {\n throw new Error(\n `Cannot materialize schema '${name}' for ${engine}: the manifest has no structured columns`,\n );\n }\n return engine\n ? getDDLStrategy(engine).generateCreateTable(schema)\n : schema.ddl;\n}\n\n/**\n * Get table name for a registered class\n *\n * @param name - Name of the registered class\n * @returns Table name or undefined if not found\n * @example\n * ```typescript\n * const tableName = getTableName('Product');\n * console.log(tableName); // 'products'\n * ```\n */\nexport function getTableName(name: string): string | undefined {\n // Check if this is a collection class - collections have their own tableName mapping\n const collectionTableName = getCollectionTableNames().get(name);\n if (collectionTableName) {\n return collectionTableName;\n }\n\n // For STI classes, return the STI base class's table name.\n // R5-canon: `getSTIBase` returns the qualified name; resolve `name`\n // (which may be simple) to its registration's qualified form for the\n // comparison.\n const stiBase = ObjectRegistry.getSTIBase(name);\n const registered = ObjectRegistry.getClass(name);\n const qualifiedName = registered?.qualifiedName ?? registered?.name ?? name;\n if (stiBase && stiBase !== qualifiedName) {\n return getSchema(stiBase)?.tableName;\n }\n return getSchema(name)?.tableName;\n}\n\nfunction withConflictIndex(\n tableName: string,\n columns: Record<string, ColumnDefinition>,\n indexes: IndexDefinition[],\n conflictColumns: string[],\n): IndexDefinition[] {\n if (\n conflictColumns.length === 0 ||\n !conflictColumns.every((column) => columns[column])\n ) {\n return indexes;\n }\n\n // `ON CONFLICT (id)` binds to the primary-key constraint itself; a second\n // unique index over the primary key column set adds nothing (#2359, A5).\n // Kept in step with SchemaGenerator.conflictColumnsArePrimaryKey().\n const primaryKeyColumns = Object.entries(columns)\n .filter(([, column]) => column.primaryKey === true)\n .map(([name]) => name);\n if (\n primaryKeyColumns.length > 0 &&\n primaryKeyColumns.length === conflictColumns.length &&\n primaryKeyColumns.every((column) => conflictColumns.includes(column))\n ) {\n return indexes;\n }\n\n const hasConflictIndex = indexes.some(\n (index) =>\n index.unique === true &&\n !index.where &&\n !index.jsonPath &&\n index.columns.length === conflictColumns.length &&\n index.columns.every((column) => conflictColumns.includes(column)),\n );\n if (hasConflictIndex) return indexes;\n\n // Same stable naming as SchemaGenerator (`schema/conflict-target.ts`), so\n // a manifest built before the runtime learned the tenant-aware default\n // (#2360) has its stale `<table>_slug_context_idx` REPLACED in place here\n // — the differ then swaps the live index by name — instead of a second,\n // suffixed unique index being appended beside the old global one.\n const tenantColumn = Object.entries(columns).find(\n ([, column]) => column.referenceKind === 'tenantId',\n )?.[0];\n // The composed name can exceed PostgreSQL's 63-byte limit on a long table.\n // Shortening here (rather than inside conflictIndexName) keeps the generator\n // paths, which run enforceIdentifierLimits() over their whole index list,\n // and this migrate leg agreeing on the final name (#2374).\n const name = shortenIdentifier(\n conflictIndexName(tableName, conflictColumns, tenantColumn),\n );\n const conflictIndex: IndexDefinition = {\n name,\n columns: conflictColumns,\n unique: true,\n };\n if (indexes.some((index) => index.name === name)) {\n return indexes.map((index) =>\n index.name === name ? conflictIndex : index,\n );\n }\n return [...indexes, conflictIndex];\n}\n\n/**\n * A registered class that contributes columns to one physical table.\n *\n * For a single-table-inheritance hierarchy every class in the hierarchy is a\n * contributor to the same table.\n */\ninterface TableContributor {\n registered: RegisteredClass;\n simpleName: string;\n qualifiedName: string;\n isSTI: boolean;\n /** True when this class is the STI base that owns the table. */\n isSTIBase: boolean;\n /** Inheritance depth; ancestors sort before descendants. */\n depth: number;\n /** Conflict-column lookup key (the STI base for STI members). */\n conflictKey: string;\n}\n\n/**\n * A merged physical table assembled from every class that contributes to it.\n */\ninterface MergedTableSchema {\n tableName: string;\n columns: Record<string, ColumnDefinition>;\n indexes: IndexDefinition[];\n ddl: string;\n isSTI: boolean;\n conflictColumns: string[];\n}\n\nfunction applyContributorForeignKeys(\n tableSchema: MergedTableSchema,\n contributor: TableContributor,\n): void {\n const conflictColumns = new Set(tableSchema.conflictColumns);\n for (const [fieldName, field] of contributor.registered.fields) {\n if (field.type !== 'foreignKey' || !field.related) continue;\n const columnName = toSnakeCase(fieldName);\n const column = tableSchema.columns[columnName];\n if (!column) continue;\n if (\n field._meta?.__tenancy?.isTenantIdField === true ||\n (\n field as FieldDefinition & {\n __tenancy?: { isTenantIdField?: boolean };\n }\n ).__tenancy?.isTenantIdField === true\n ) {\n column.foreignKey = undefined;\n continue;\n }\n const [targetName, declaredTargetColumn] = field.related.split('.');\n const targetBase = ObjectRegistry.getSTIBase(targetName) || targetName;\n const registeredTarget = ObjectRegistry.getClass(targetBase);\n const targetColumn =\n declaredTargetColumn ||\n Array.from(ObjectRegistry.getFields(targetBase).entries()).find(\n ([, targetField]) => targetField._meta?.primaryKey === true,\n )?.[0] ||\n 'id';\n if (registeredTarget && !field._meta?.sqlType) {\n const targetColumnName = toSnakeCase(targetColumn);\n const targetColumnType =\n registeredTarget.schema?.columns?.[targetColumnName]?.type ||\n (targetColumnName === 'id'\n ? registeredTarget.config.idType === 'text'\n ? 'TEXT'\n : 'UUID'\n : undefined);\n if (targetColumnType) {\n column.type = targetColumnType;\n }\n }\n if (field._meta?.constraint === false) {\n column.foreignKey = undefined;\n continue;\n }\n // A manifest may carry explicit actions that predate or differ from the\n // runtime decorator defaults. Merging runtime fields must not erase them.\n // The fallback produced from runtime fields, however, must be replaced so\n // conflict columns receive the same default CASCADE as app-side cleanup.\n const manifestForeignKey =\n contributor.registered.schema?.columns?.[columnName]?.foreignKey;\n if (manifestForeignKey) {\n column.foreignKey = manifestForeignKey;\n continue;\n }\n // A decorator-only runtime field has no authoritative physical target\n // until that target is registered. Scanner-produced manifests clear this\n // shape too; only an explicit manifest FK above may survive unloaded\n // runtime classes (the manifest-authority contract from #1120).\n if (!registeredTarget) {\n column.foreignKey = undefined;\n continue;\n }\n const targetTable =\n ObjectRegistry.getTableName(targetBase) ||\n classnameToTablename(targetBase);\n const { action } = resolveForeignKeyDeleteAction({\n declared: field._meta?.onDelete,\n isConflictColumn: conflictColumns.has(columnName),\n isTenantIdField: false,\n });\n column.foreignKey = {\n table: targetTable,\n column: toSnakeCase(targetColumn),\n onDelete: action,\n onUpdate: 'CASCADE',\n ...(typeof field._meta?.constraint === 'object'\n ? { engines: [...field._meta.constraint.engines] }\n : {}),\n };\n }\n}\n\n/**\n * Resolve the physical table a registered class writes to.\n *\n * STI subclasses are folded onto their base's table. Returns `undefined` when\n * the class has no table (for example an unresolvable manifest stub).\n *\n * R5-canon: STI lookups use the qualified key so a colliding simple name in\n * another package cannot yield the wrong table strategy or STI base and move\n * this class's columns under that other package's table.\n */\nfunction resolveContributorTable(\n registered: RegisteredClass,\n fallbackName: string,\n): { tableName: string; contributor: TableContributor } | undefined {\n const simpleName = registered.name || fallbackName;\n const qualifiedName = registered.qualifiedName ?? simpleName;\n\n // STI subclasses loaded from external manifests can arrive with a null\n // tableName; registerFromManifest() then derives one from the class name.\n // Adopt the STI base's tableName instead so the subclass lands on the\n // shared table (issue #703).\n if (!registered.schema?.tableName && registered.extends) {\n if (ObjectRegistry.getTableStrategy(qualifiedName) === 'sti') {\n const stiBaseName = ObjectRegistry.getSTIBase(qualifiedName);\n if (stiBaseName && stiBaseName !== qualifiedName) {\n const stiBaseClass = findClass(stiBaseName);\n if (stiBaseClass?.schema?.tableName) {\n if (!registered.schema) {\n registered.schema = {\n tableName: '',\n ddl: '',\n columns: {},\n indexes: [],\n triggers: [],\n foreignKeys: [],\n dependencies: [],\n version: '',\n };\n }\n registered.schema.tableName = stiBaseClass.schema.tableName;\n }\n }\n }\n }\n\n if (!registered.schema?.tableName) {\n return undefined;\n }\n\n let tableName = registered.schema.tableName;\n const tableStrategy = ObjectRegistry.getTableStrategy(qualifiedName);\n const isSTI = tableStrategy === 'sti';\n let isSTIBase = isSTI;\n let conflictKey = qualifiedName;\n\n if (isSTI) {\n const stiBaseName = ObjectRegistry.getSTIBase(qualifiedName);\n if (stiBaseName) {\n conflictKey = stiBaseName;\n if (stiBaseName !== qualifiedName) {\n isSTIBase = false;\n // STI subclasses serialize to the base class's table even when they\n // carry a tableName of their own (issue #693).\n const stiBaseClass = findClass(stiBaseName);\n if (stiBaseClass?.schema?.tableName) {\n tableName = stiBaseClass.schema.tableName;\n }\n }\n }\n }\n\n return {\n tableName,\n contributor: {\n registered,\n simpleName,\n qualifiedName,\n isSTI,\n isSTIBase,\n depth: ObjectRegistry.getInheritanceChain(qualifiedName).length,\n conflictKey,\n },\n };\n}\n\n/**\n * Order the classes that share one table deterministically.\n *\n * The first contributor seeds the table: it supplies the base columns, the\n * `idType`, the conflict columns and the cached DDL, and its columns win every\n * merge conflict. Registration order must not decide that, or the same\n * hierarchy yields a different table shape depending on which class a manifest\n * happens to list first — child-first dropped NOT NULL and DEFAULT from the\n * base columns (#2372).\n *\n * Order: the STI base first, then ancestors before descendants, then by\n * qualified name so the result is a total order.\n */\nfunction sortTableContributors(contributors: TableContributor[]) {\n return [...contributors].sort((a, b) => {\n if (a.isSTIBase !== b.isSTIBase) {\n return a.isSTIBase ? -1 : 1;\n }\n if (a.depth !== b.depth) {\n return a.depth - b.depth;\n }\n return a.qualifiedName.localeCompare(b.qualifiedName);\n });\n}\n\n/**\n * Assemble every physical table from the classes that contribute to it.\n *\n * Shared by {@link getAllSchemas} and {@link getAllSchemasAsDefinitions} so\n * both produce the same merged shape. The result depends only on what is\n * registered, never on the order it was registered in.\n */\nfunction buildMergedTableSchemas(): Record<string, MergedTableSchema> {\n // Pass 1: group contributing classes by physical table.\n const contributorsByTable = new Map<string, TableContributor[]>();\n\n for (const [className, registered] of getClasses()) {\n // Collection classes have no table of their own; their schemas carry\n // collection properties (loaded, options, ...) rather than columns.\n if (\n isCollectionRegistration(\n className,\n registered,\n collectionRegistrationLookup,\n )\n ) {\n continue;\n }\n\n // Framework abstract base classes (SmrtObject, SmrtClass, ...) are\n // scaffolding, not resources — they produce no table (#2642).\n if (isFrameworkBaseClass(registered.name, registered.packageName)) {\n continue;\n }\n\n const resolved = resolveContributorTable(registered, className);\n if (!resolved) {\n continue;\n }\n\n const existing = contributorsByTable.get(resolved.tableName);\n if (existing) {\n existing.push(resolved.contributor);\n } else {\n contributorsByTable.set(resolved.tableName, [resolved.contributor]);\n }\n }\n\n // Pass 2: merge each table's contributors in deterministic order.\n const tableSchemas: Record<string, MergedTableSchema> = {};\n\n for (const [tableName, contributors] of contributorsByTable) {\n for (const contributor of sortTableContributors(contributors)) {\n const { registered, simpleName, isSTI } = contributor;\n const conflictColumns = ObjectRegistry.getConflictColumns(\n contributor.conflictKey,\n );\n\n // The manifest schema stays authoritative for the columns it defines.\n // Runtime field metadata backfills columns the manifest never had (for\n // example tenantScoped injections) and applies explicit sqlType\n // overrides, without erasing richer manifest metadata.\n const columnsToUse = mergeRuntimeFieldColumns(\n simpleName,\n registered.schema?.columns,\n registered.fields,\n { stiUnionColumns: isSTI, conflictColumns },\n );\n\n let tableSchema = tableSchemas[tableName];\n if (!tableSchema) {\n tableSchema = {\n tableName,\n columns: {\n ...createBaseColumns(registered, isSTI),\n ...columnsToUse,\n },\n indexes: [],\n ddl: registered.schema?.ddl || '',\n isSTI,\n conflictColumns,\n };\n tableSchemas[tableName] = tableSchema;\n } else {\n // Another class sharing this table (STI): add only columns the\n // seeding contributor did not already define.\n for (const [colName, colDef] of Object.entries(columnsToUse)) {\n if (!tableSchema.columns[colName]) {\n tableSchema.columns[colName] = colDef;\n }\n }\n }\n\n applyContributorForeignKeys(tableSchema, contributor);\n\n // Merge indexes, keeping the first definition of each name.\n const schemaIndexes = registered.schema?.indexes;\n if (schemaIndexes && schemaIndexes.length > 0) {\n const existingNames = new Set(\n tableSchema.indexes.map((index) => index.name),\n );\n for (const index of schemaIndexes) {\n // Legacy string-format indexes carry no columns and cannot be merged.\n if (typeof index === 'string') {\n continue;\n }\n if (!existingNames.has(index.name)) {\n tableSchema.indexes.push(index);\n existingNames.add(index.name);\n }\n }\n }\n }\n }\n\n return tableSchemas;\n}\n\n/**\n * Get all pre-generated schemas for explicit adapter bootstrap paths.\n *\n * Returns schemas in SDK SchemaProvider format for all registered classes.\n * Tooling and test helpers can pass these to `getDatabase()` when they want\n * to bootstrap schema before runtime. Core runtime no longer does this\n * implicitly.\n *\n * @returns Record of table names to schema definitions\n * @example\n * ```typescript\n * const schemas = ObjectRegistry.getAllSchemas('json');\n * const db = await getDatabase({ type: 'json', url: './data', schemas });\n * ```\n */\nexport function getAllSchemas(\n engine?: DatabaseEngine,\n): Record<string, { tableName: string; ddl: string; indexes?: string[] }> {\n // Step 1: Assemble every table from its contributing classes. The merge is\n // deterministic, so the shape does not depend on registration order (#2372).\n const tableSchemas = buildMergedTableSchemas();\n\n // Step 2: Convert to output format, regenerating DDL for merged schemas\n const schemas: Record<\n string,\n { tableName: string; ddl: string; indexes?: string[] }\n > = {};\n\n for (const [tableName, tableSchema] of Object.entries(tableSchemas)) {\n const engineIndexes = engine\n ? withConflictIndex(\n tableName,\n tableSchema.columns,\n tableSchema.indexes,\n tableSchema.conflictColumns,\n )\n : tableSchema.indexes;\n const mergedSchema: SchemaDefinition = {\n tableName,\n ddl: tableSchema.ddl,\n columns: tableSchema.columns,\n indexes: engineIndexes,\n triggers: [],\n foreignKeys: [],\n version: '',\n dependencies: [],\n };\n mergedSchema.foreignKeys = schemaForeignKeys(mergedSchema);\n mergedSchema.dependencies = mergedSchema.foreignKeys\n .map((foreignKey) => foreignKey.referencesTable)\n .filter((dependency) => dependency !== tableName);\n\n // Generate DDL from merged columns (or use original DDL if columns are empty)\n let ddl: string;\n if (Object.keys(tableSchema.columns).length === 0 && tableSchema.ddl) {\n if (engine) {\n throw new Error(\n `Cannot materialize schema '${tableName}' for ${engine}: the manifest has no structured columns`,\n );\n }\n // Preserve legacy inspection of cached engine-neutral DDL. Executable\n // target-engine paths fail above rather than returning unsafe SQL.\n ddl = tableSchema.ddl;\n } else if (Object.keys(tableSchema.columns).length === 0) {\n // Skip schemas with no columns and no original DDL\n continue;\n } else if (engine) {\n // Target-engine materialization must route the complete structured\n // schema through its strategy. In particular, DuckDB/JSON require\n // UNIQUE constraints inline for ON CONFLICT, and every strategy owns\n // CHECK/default/index-expression rendering.\n ddl = getDDLStrategy(engine).generateCreateTable(mergedSchema);\n } else {\n ddl = generateDDLFromColumns(\n tableName,\n tableSchema.columns,\n tableSchema.isSTI,\n );\n }\n\n // Convert index definitions to SQL strings for SDK compatibility\n let indexSQL: string[] | undefined;\n if (engineIndexes.length > 0) {\n indexSQL = engine\n ? getDDLStrategy(engine).generateIndexes(mergedSchema)\n : engineIndexes.map((idx) => {\n const indexType = idx.unique ? 'UNIQUE INDEX' : 'INDEX';\n const columnList = idx.columns\n .map((col) => quoteIdentifier(col))\n .join(', ');\n return `CREATE ${indexType} IF NOT EXISTS ${quoteIdentifier(\n idx.name,\n )} ON ${quoteIdentifier(tableName)} (${columnList});`;\n });\n }\n\n schemas[tableName] = {\n tableName,\n ddl,\n indexes: indexSQL,\n };\n }\n\n return schemas;\n}\n\n/**\n * Get all registered schemas as SchemaDefinition objects\n *\n * Similar to getAllSchemas(), but returns SchemaDefinition format suitable\n * for use with SchemaComparer (migrations/differ.ts).\n *\n * Key difference: Indexes are kept as IndexDefinition objects instead of\n * being converted to SQL strings.\n *\n * @returns Map of tableName to SchemaDefinition\n */\nexport function getAllSchemasAsDefinitions(): Record<string, SchemaDefinition> {\n // Step 1: Assemble every table from its contributing classes. The merge is\n // deterministic, so the shape does not depend on registration order (#2372).\n const tableSchemas = buildMergedTableSchemas();\n\n // Step 2: Convert to SchemaDefinition format\n const schemas: Record<string, SchemaDefinition> = {};\n\n for (const [tableName, tableSchema] of Object.entries(tableSchemas)) {\n if (Object.keys(tableSchema.columns).length === 0) {\n continue;\n }\n\n // Generate DDL from columns\n const ddl = generateDDLFromColumns(\n tableName,\n tableSchema.columns,\n tableSchema.isSTI,\n );\n const foreignKeys = schemaForeignKeys({\n columns: tableSchema.columns,\n foreignKeys: [],\n });\n\n schemas[tableName] = {\n tableName,\n ddl,\n columns: tableSchema.columns,\n indexes: withConflictIndex(\n tableName,\n tableSchema.columns,\n tableSchema.indexes,\n tableSchema.conflictColumns,\n ),\n triggers: [],\n foreignKeys,\n version: '',\n dependencies: foreignKeys\n .map((foreignKey) => foreignKey.referencesTable)\n .filter((dependency) => dependency !== tableName),\n };\n }\n\n return schemas;\n}\n\n/**\n * Generate DDL CREATE TABLE statement from columns\n *\n * Used internally by getAllSchemas() to regenerate DDL after merging\n * columns from multiple STI subtypes that share the same table.\n *\n * @param tableName - Name of the table\n * @param columns - Column definitions\n * @returns DDL CREATE TABLE statement\n */\nexport function generateDDLFromColumns(\n tableName: string,\n columns: Record<string, ColumnDefinition>,\n isSTI = false,\n engine?: DatabaseEngine,\n): string {\n let sql = `CREATE TABLE IF NOT EXISTS ${quoteIdentifier(tableName)} (\\n`;\n\n const columnLines: string[] = [];\n for (const [columnName, columnDef] of Object.entries(columns)) {\n const parts: string[] = [];\n\n // Column name and type\n const strategy = engine ? getDDLStrategy(engine) : undefined;\n const columnType = strategy\n ? strategy.mapType(columnDef.type)\n : columnDef.type;\n parts.push(` ${quoteIdentifier(columnName)} ${columnType}`);\n\n // Primary key\n if (columnDef.primaryKey) {\n parts.push('PRIMARY KEY');\n }\n\n // Not null constraint\n if (columnDef.notNull) {\n parts.push('NOT NULL');\n }\n\n // Unique constraint (skip if primary key already implies uniqueness)\n if (columnDef.unique && !columnDef.primaryKey) {\n parts.push('UNIQUE');\n }\n\n // Default value\n if (columnDef.defaultValue !== undefined) {\n const defaultSQL = strategy\n ? strategy.formatDefaultValue(columnDef.defaultValue, columnDef.type)\n : formatDefaultValue(columnDef.defaultValue, columnDef.type);\n parts.push(`DEFAULT ${defaultSQL}`);\n }\n\n columnLines.push(parts.join(' '));\n }\n for (const foreignKey of schemaForeignKeys({ columns, foreignKeys: [] })) {\n columnLines.push(` ${renderForeignKeyConstraint(tableName, foreignKey)}`);\n }\n\n sql += columnLines.join(',\\n');\n\n // Add UNIQUE constraint for UPSERT operations\n // For STI tables: UNIQUE(slug, context, _meta_type) - different types can have same slug+context\n // For non-STI tables: UNIQUE(slug, context)\n if (columns.slug && columns.context) {\n if (isSTI && columns._meta_type) {\n sql += ',\\n UNIQUE(slug, context, _meta_type)';\n } else {\n sql += ',\\n UNIQUE(slug, context)';\n }\n }\n\n sql += '\\n);';\n\n return sql;\n}\n\n/**\n * Format default value for SQL DDL.\n *\n * Thin wrapper over the shared, injection-safe formatter\n * (`schema/sql-identifiers.ts`) so the registry schema-builder uses the same\n * rules as the DDL strategies and schema generator: an allowlist of SQL\n * keyword/function defaults (not \"contains `(`\"), type-driven literal quoting,\n * and no folding of a literal string `\"null\"` into the SQL NULL keyword.\n *\n * @param value - Default value\n * @param type - Column SQL type\n * @returns Formatted SQL default value\n */\nexport function formatDefaultValue(value: unknown, type: string): string {\n return formatDefaultValueShared(value, type);\n}\n\n/**\n * Options for {@link fieldsToColumns}.\n */\nexport interface FieldsToColumnsOptions {\n /**\n * Shape the columns for a single-table-inheritance table.\n *\n * An STI table holds the union of every subtype's fields, so a column that\n * only one subtype declares must stay nullable — rows of sibling subtypes\n * never populate it. This matches `generateSTISchemaFromManifest`, which\n * emits `notNull: false` for every non-system column on an STI table.\n * Declared defaults are still emitted.\n */\n stiUnionColumns?: boolean;\n /**\n * Physical column names that form the table's natural conflict key.\n * Undeclared delete actions on foreign-key members use the shared CASCADE\n * default, matching app-side relationship cleanup.\n */\n conflictColumns?: readonly string[];\n}\n\n/**\n * Convert a Map of field definitions to column definitions\n *\n * Used by getAllSchemas() to generate columns from fields when a class\n * has no pre-generated schema (e.g., STI subclasses registered from manifest).\n *\n * `required`, `default`, and `description` are read from either the top level\n * or `_meta`: registry-sourced fields normalize them into `_meta`, so reading\n * only the top level dropped NOT NULL and DEFAULT for every such field\n * (#2372).\n *\n * @param fields - Map of field name to field definition\n * @param options - Table-shape options (see {@link FieldsToColumnsOptions})\n * @returns Record of column name to column definition\n * @private\n */\nexport function fieldsToColumns(\n fields: Map<string, FieldDefinition>,\n options?: FieldsToColumnsOptions,\n): Record<string, ColumnDefinition> {\n const columns: Record<string, ColumnDefinition> = {};\n const conflictColumns = new Set(\n (options?.conflictColumns ?? []).map((column) => toSnakeCase(column)),\n );\n\n for (const [fieldName, fieldDef] of fields) {\n // Skip id, timestamps - they're on the base table\n if (\n fieldName === 'id' ||\n fieldName === 'created_at' ||\n fieldName === 'updated_at' ||\n fieldName === 'slug' ||\n fieldName === 'context'\n ) {\n continue;\n }\n\n // Skip transient fields (non-persisted)\n if (fieldDef.transient || fieldDef._meta?.transient) {\n continue;\n }\n\n // Skip relationship fields that don't create columns\n // oneToMany and manyToMany are relationship metadata, not actual database columns\n if (fieldDef.type === 'oneToMany' || fieldDef.type === 'manyToMany') {\n continue;\n }\n\n // Skip meta fields - they're stored in _meta_data JSONB column\n if (fieldDef.type === 'meta') {\n continue;\n }\n\n // Map field type to SQL type\n const sqlType =\n fieldDef._meta?.sqlType ||\n (fieldDef.type === 'crossPackageRef' &&\n (fieldDef._meta?.idType === 'text' ||\n (fieldDef as unknown as { idType?: string }).idType === 'text')\n ? 'TEXT'\n : mapFieldTypeToSQL(fieldDef.type));\n const normalizedSqlType = String(sqlType).toUpperCase() as SQLDataType;\n const referenceKind = getReferenceKind(fieldDef);\n\n const required = readFieldAttribute(fieldDef, 'required');\n const defaultValue = readFieldAttribute(fieldDef, 'default');\n const description = readFieldAttribute(fieldDef, 'description');\n\n const column: ColumnDefinition = {\n type: normalizedSqlType,\n referenceKind,\n notNull: options?.stiUnionColumns\n ? false\n : fieldDef._meta?.nullable\n ? false\n : Boolean(required),\n unique: fieldDef._meta?.unique || false,\n description: description as string | undefined,\n };\n\n // Handle default values\n if (\n defaultValue !== undefined &&\n shouldEmitDefault(fieldDef, normalizedSqlType, defaultValue)\n ) {\n column.defaultValue = defaultValue;\n }\n\n // Handle foreign keys\n if (\n fieldDef.type === 'foreignKey' &&\n fieldDef.related &&\n fieldDef._meta?.constraint !== false &&\n fieldDef._meta?.__tenancy?.isTenantIdField !== true &&\n !(\n fieldDef as FieldDefinition & {\n __tenancy?: { isTenantIdField?: boolean };\n }\n ).__tenancy?.isTenantIdField\n ) {\n const [table, columnName = 'id'] = fieldDef.related.split('.');\n const fieldMeta = fieldDef._meta as\n | {\n onDelete?: ForeignKeyAction;\n onUpdate?: ForeignKeyAction;\n }\n | undefined;\n column.foreignKey = {\n table: classnameToTablename(table),\n column: columnName,\n onDelete: resolveForeignKeyDeleteAction({\n declared: fieldMeta?.onDelete,\n isConflictColumn: conflictColumns.has(toSnakeCase(fieldName)),\n isTenantIdField: false,\n }).action,\n onUpdate:\n fieldMeta?.onUpdate === undefined\n ? 'CASCADE'\n : requireForeignKeyAction(\n fieldMeta.onUpdate,\n `${fieldName} ON UPDATE`,\n ),\n ...(typeof fieldDef._meta?.constraint === 'object'\n ? { engines: [...fieldDef._meta.constraint.engines] }\n : {}),\n };\n }\n\n // Use snake_case for column names\n columns[toSnakeCase(fieldName)] = column;\n }\n\n return columns;\n}\n\n/**\n * Map field type to SQL data type\n * @private\n */\nexport function mapFieldTypeToSQL(\n fieldType: FieldDefinition['type'],\n): SQLDataType {\n switch (fieldType) {\n case 'text':\n return 'TEXT';\n case 'integer':\n return 'INTEGER';\n case 'decimal':\n return 'REAL';\n case 'boolean':\n return 'BOOLEAN';\n case 'datetime':\n return 'TIMESTAMP';\n case 'json':\n return 'JSON';\n case 'foreignKey':\n return 'UUID';\n case 'crossPackageRef':\n return 'UUID';\n default:\n return 'TEXT';\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA6CA,IAAM,+BAA6D;CACjE;CACA,qBAAqB,aAAa,cAChC,eAAe,kBAAkB,aAAa,SAAS;CACzD,sBAAsB,cACpB,eAAe,oBAAoB,SAAS;AAChD;AAEA,SAAS,+BACP,WACA,SACkC;CAClC,MAAM,aAAa,eAAe,mBAAmB,SAAS;CAC9D,IAAI,CAAC,WAAW,MACd,OAAO;CAGT,KAAK,MAAM,CAAC,WAAW,YAAY,YAAY;EAC7C,IAAI,CAAC,SAAS,SACZ;EAGF,MAAM,aAAa,YAAY,SAAS;EACxC,MAAM,WAAW,QAAQ;EACzB,IAAI,CAAC,UACH;EAGF,MAAM,gBAAgB,iBAAiB,OAA0B;EACjE,QAAQ,cAAc;GACpB,GAAG;GACH,MAAM,OAAO,QAAQ,OAAO,CAAC,CAAC,YAAY;GAC1C,GAAI,gBAAgB,EAAE,cAAc,IAAI,CAAC;EAC3C;CACF;CAEA,OAAO;AACT;AAEA,SAAS,yBACP,WACA,eACA,QACA,SACkC;CAClC,MAAM,eAAe,EAAE,GAAI,iBAAiB,CAAC,EAAG;CAEhD,IAAI,OAAO,OAAO,GAAG;EACnB,MAAM,eAAe,gBAAgB,QAAQ,OAAO;E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,mBAAmB,YAAY,GAE3D,OAAO,eAAe;EAIxB,IACE,SAAS,SAAS,gBAClB,SAAS,WACT,SAAS,OAAO,eAAe,SAC/B,SAAS,OAAO,WAAW,oBAAoB,QAC/C,CACE,SAGA,WAAW,iBACb;GACA,MAAM,CAAC,OAAO,aAAa,QAAQ,SAAS,QAAQ,MAAM,GAAG;GAC7D,MAAM,YAAY,SAAS;GAM3B,OAAO,aAAa;IAClB,OAAO,qBAAqB,KAAK;IACjC,QAAQ;IACR,UAAU,8BAA8B;KACtC,UAAU,WAAW;KACrB,kBAAkB,gBAAgB,IAAI,YAAY,SAAS,CAAC;KAC5D,iBAAiB;IACnB,CAAC,CAAC,CAAC;IACH,UACE,WAAW,aAAa,KAAA,IACpB,YACA,wBACE,UAAU,UACV,GAAG,UAAU,WACf;IACN,GAAI,OAAO,SAAS,OAAO,eAAe,WACtC,EAAE,SAAS,CAAC,GAAG,SAAS,MAAM,WAAW,OAAO,EAAE,IAClD,CAAC;GACP;EACF;EAGA,QAAQ,YAAY,SAAS,KAAK;CACpC;CAEA,OAAO;AACT;;;;;AAMA,SAAgB,kBACd,WACa;CACb,QAAQ,WAAR;EACE,KAAK,QACH,OAAO;EACT,KAAK,WACH,OAAO;EACT,KAAK,WACH,OAAO;EACT,KAAK,WACH,OAAO;EACT,KAAK,YACH,OAAO;EACT,KAAK,QACH,OAAO;EACT,KAAK,cACH,OAAO;EACT,KAAK,mBACH,OAAO;EACT,SACE,OAAO;CACX;AACF"}
|
|
1
|
+
{"version":3,"file":"schema-builder.js","names":[],"sources":["../../src/registry/schema-builder.ts"],"sourcesContent":["/**\n * Schema building logic for the SMRT ObjectRegistry.\n *\n * Extracted from registry.ts as part of issue #1006.\n */\n\nimport { ObjectRegistry } from '../registry';\nimport type { FieldDefinition } from '../scanner/types.js';\nimport { conflictIndexName } from '../schema/conflict-target.js';\nimport { getDDLStrategy } from '../schema/ddl/index.js';\nimport type { DatabaseEngine } from '../schema/ddl/types.js';\nimport {\n renderForeignKeyConstraint,\n schemaForeignKeys,\n} from '../schema/foreign-key-ddl.js';\nimport {\n requireForeignKeyAction,\n resolveForeignKeyDeleteAction,\n} from '../schema/foreign-key-policy.js';\nimport { shortenIdentifier } from '../schema/index-utils.js';\nimport {\n formatDefaultValue as formatDefaultValueShared,\n quoteIdentifier,\n} from '../schema/sql-identifiers.js';\nimport type {\n ColumnDefinition,\n IndexDefinition,\n SchemaDefinition,\n SQLDataType,\n} from '../schema/types.js';\nimport { classnameToTablename, toSnakeCase } from '../utils';\nimport {\n type CollectionRegistrationLookup,\n isCollectionRegistration,\n} from './collection-resolution';\nimport { isFrameworkBaseClass } from './framework-base-classes';\nimport { readFieldAttribute } from './manifest-field-merge';\nimport { findClass } from './name-resolver';\nimport { getClasses, getCollectionTableNames } from './shared-state';\nimport type { RegisteredClass } from './types';\n\ntype ForeignKeyAction = NonNullable<\n NonNullable<ColumnDefinition['foreignKey']>['onDelete']\n>;\n\nconst collectionRegistrationLookup: CollectionRegistrationLookup = {\n findClass,\n findClassInPackage: (packageName, className) =>\n ObjectRegistry.getClassInPackage(packageName, className),\n getInheritanceChain: (className) =>\n ObjectRegistry.getInheritanceChain(className),\n};\n\nfunction applyDecoratorSqlTypeOverrides(\n className: string,\n columns: Record<string, ColumnDefinition>,\n): Record<string, ColumnDefinition> {\n const decorators = ObjectRegistry.getFieldDecorators(className);\n if (!decorators.size) {\n return columns;\n }\n\n for (const [fieldName, options] of decorators) {\n if (!options?.sqlType) {\n continue;\n }\n\n const columnName = toSnakeCase(fieldName);\n const existing = columns[columnName];\n if (!existing) {\n continue;\n }\n\n const referenceKind = getReferenceKind(options as FieldDefinition);\n columns[columnName] = {\n ...existing,\n type: String(options.sqlType).toUpperCase() as SQLDataType,\n ...(referenceKind ? { referenceKind } : {}),\n };\n }\n\n return columns;\n}\n\nfunction mergeRuntimeFieldColumns(\n className: string,\n schemaColumns: Record<string, ColumnDefinition> | undefined,\n fields: Map<string, FieldDefinition>,\n options?: FieldsToColumnsOptions,\n): Record<string, ColumnDefinition> {\n const columnsToUse = { ...(schemaColumns || {}) };\n\n if (fields.size > 0) {\n const fieldColumns = fieldsToColumns(fields, options);\n for (const [columnName, columnDef] of Object.entries(fieldColumns)) {\n if (!columnsToUse[columnName]) {\n columnsToUse[columnName] = columnDef;\n }\n }\n\n for (const [fieldName, fieldDef] of fields) {\n const columnName = toSnakeCase(fieldName);\n const existing = columnsToUse[columnName];\n if (!existing) {\n continue;\n }\n\n const sqlType =\n fieldDef._meta?.sqlType ||\n (fieldDef as unknown as { sqlType?: string }).sqlType;\n const referenceKind = getReferenceKind(fieldDef);\n columnsToUse[columnName] = {\n ...existing,\n ...(sqlType\n ? { type: String(sqlType).toUpperCase() as SQLDataType }\n : {}),\n ...(referenceKind ? { referenceKind } : {}),\n };\n }\n }\n\n applyDecoratorSqlTypeOverrides(className, columnsToUse);\n return columnsToUse;\n}\n\nfunction getReferenceKind(\n fieldDef: FieldDefinition,\n): ColumnDefinition['referenceKind'] | undefined {\n if (\n (\n fieldDef as unknown as {\n __tenancy?: { isTenantIdField?: boolean };\n }\n ).__tenancy?.isTenantIdField ||\n fieldDef._meta?.__tenancy?.isTenantIdField\n ) {\n return 'tenantId';\n }\n\n if (fieldDef.type === 'foreignKey') {\n return 'foreignKey';\n }\n\n if (fieldDef.type === 'crossPackageRef') {\n return 'crossPackageRef';\n }\n\n return undefined;\n}\n\nfunction shouldEmitDefault(\n fieldDef: FieldDefinition,\n sqlType: SQLDataType,\n defaultValue: unknown,\n) {\n return !(\n getReferenceKind(fieldDef) === 'tenantId' &&\n sqlType === 'UUID' &&\n defaultValue === ''\n );\n}\n\n/**\n * Fallback base columns for a table whose contributing class carries no\n * manifest columns.\n *\n * These mirror what the manifest schema generators emit for the same table\n * (`generateSchemaFromManifest` / `generateSTISchemaFromManifest`), so a table\n * assembled from runtime field metadata alone has the same NOT NULL and\n * DEFAULT shape as one assembled from a manifest. Divergence here is what made\n * the merged table shape depend on which class registered first (#2372).\n */\nfunction createBaseColumns(\n registered: {\n config?: { idType?: 'uuid' | 'text' };\n },\n isSTI: boolean,\n): Record<string, ColumnDefinition> {\n const baseColumns: Record<string, ColumnDefinition> = {\n id: {\n type: registered.config?.idType === 'text' ? 'TEXT' : 'UUID',\n primaryKey: true,\n notNull: true,\n referenceKind: 'id',\n },\n slug: { type: 'TEXT', notNull: true },\n context: { type: 'TEXT', notNull: true, defaultValue: '' },\n created_at: {\n type: 'TIMESTAMP',\n notNull: true,\n defaultValue: 'current_timestamp',\n },\n updated_at: {\n type: 'TIMESTAMP',\n notNull: true,\n defaultValue: 'current_timestamp',\n },\n };\n\n // STI tables also carry the discriminator and the meta payload column\n // (issue #690: db:diff needs them to detect schema changes).\n if (isSTI) {\n baseColumns._meta_type = { type: 'TEXT', notNull: true };\n baseColumns._meta_data = { type: 'JSON', notNull: false };\n }\n\n return baseColumns;\n}\n\n/**\n * Get cached schema definition for a registered class\n *\n * @param name - Name of the registered class\n * @returns Schema definition or undefined if not found\n * @example\n * ```typescript\n * const schema = getSchema('Product');\n * console.log(schema.tableName); // 'products'\n * console.log(schema.ddl); // 'CREATE TABLE...'\n * ```\n */\nexport function getSchema(name: string): SchemaDefinition | undefined {\n // Issue #951: Use findClass for multi-strategy lookup\n const registered = findClass(name);\n return registered?.schema;\n}\n\n/**\n * Get SQL DDL statement for a registered class\n *\n * @param name - Name of the registered class\n * Cached manifest DDL contains abstract types and is not safe to execute on\n * PostgreSQL. New executable paths must pass a target engine. Omitting it is\n * retained for backward compatibility with consumers that only inspect the\n * legacy engine-neutral manifest string.\n *\n * @param engine - Database engine that will execute the DDL\n * @returns Engine-specific SQL DDL, or the legacy cached DDL when omitted\n * @example\n * ```typescript\n * const ddl = ObjectRegistry.getSchemaDDL('Product', 'postgres');\n * await db.query(ddl);\n * ```\n */\nexport function getSchemaDDL(\n name: string,\n engine?: DatabaseEngine,\n): string | undefined {\n const schema = getSchema(name);\n if (!schema) return undefined;\n if (engine && Object.keys(schema.columns).length === 0) {\n throw new Error(\n `Cannot materialize schema '${name}' for ${engine}: the manifest has no structured columns`,\n );\n }\n return engine\n ? getDDLStrategy(engine).generateCreateTable(schema)\n : schema.ddl;\n}\n\n/**\n * Get table name for a registered class\n *\n * @param name - Name of the registered class\n * @returns Table name or undefined if not found\n * @example\n * ```typescript\n * const tableName = getTableName('Product');\n * console.log(tableName); // 'products'\n * ```\n */\nexport function getTableName(name: string): string | undefined {\n // Check if this is a collection class - collections have their own tableName mapping\n const collectionTableName = getCollectionTableNames().get(name);\n if (collectionTableName) {\n return collectionTableName;\n }\n\n // For STI classes, return the STI base class's table name.\n // R5-canon: `getSTIBase` returns the qualified name; resolve `name`\n // (which may be simple) to its registration's qualified form for the\n // comparison.\n const stiBase = ObjectRegistry.getSTIBase(name);\n const registered = ObjectRegistry.getClass(name);\n const qualifiedName = registered?.qualifiedName ?? registered?.name ?? name;\n if (stiBase && stiBase !== qualifiedName) {\n return getSchema(stiBase)?.tableName;\n }\n return getSchema(name)?.tableName;\n}\n\nfunction withConflictIndex(\n tableName: string,\n columns: Record<string, ColumnDefinition>,\n indexes: IndexDefinition[],\n conflictColumns: string[],\n): IndexDefinition[] {\n if (\n conflictColumns.length === 0 ||\n !conflictColumns.every((column) => columns[column])\n ) {\n return indexes;\n }\n\n // `ON CONFLICT (id)` binds to the primary-key constraint itself; a second\n // unique index over the primary key column set adds nothing (#2359, A5).\n // Kept in step with SchemaGenerator.conflictColumnsArePrimaryKey().\n const primaryKeyColumns = Object.entries(columns)\n .filter(([, column]) => column.primaryKey === true)\n .map(([name]) => name);\n if (\n primaryKeyColumns.length > 0 &&\n primaryKeyColumns.length === conflictColumns.length &&\n primaryKeyColumns.every((column) => conflictColumns.includes(column))\n ) {\n return indexes;\n }\n\n const hasConflictIndex = indexes.some(\n (index) =>\n index.unique === true &&\n !index.where &&\n !index.jsonPath &&\n index.columns.length === conflictColumns.length &&\n index.columns.every((column) => conflictColumns.includes(column)),\n );\n if (hasConflictIndex) return indexes;\n\n // Same stable naming as SchemaGenerator (`schema/conflict-target.ts`), so\n // a manifest built before the runtime learned the tenant-aware default\n // (#2360) has its stale `<table>_slug_context_idx` REPLACED in place here\n // — the differ then swaps the live index by name — instead of a second,\n // suffixed unique index being appended beside the old global one.\n const tenantColumn = Object.entries(columns).find(\n ([, column]) => column.referenceKind === 'tenantId',\n )?.[0];\n // The composed name can exceed PostgreSQL's 63-byte limit on a long table.\n // Shortening here (rather than inside conflictIndexName) keeps the generator\n // paths, which run enforceIdentifierLimits() over their whole index list,\n // and this migrate leg agreeing on the final name (#2374).\n const name = shortenIdentifier(\n conflictIndexName(tableName, conflictColumns, tenantColumn),\n );\n const conflictIndex: IndexDefinition = {\n name,\n columns: conflictColumns,\n unique: true,\n };\n if (indexes.some((index) => index.name === name)) {\n return indexes.map((index) =>\n index.name === name ? conflictIndex : index,\n );\n }\n return [...indexes, conflictIndex];\n}\n\n/**\n * A registered class that contributes columns to one physical table.\n *\n * For a single-table-inheritance hierarchy every class in the hierarchy is a\n * contributor to the same table.\n */\ninterface TableContributor {\n registered: RegisteredClass;\n simpleName: string;\n qualifiedName: string;\n isSTI: boolean;\n /** True when this class is the STI base that owns the table. */\n isSTIBase: boolean;\n /** Inheritance depth; ancestors sort before descendants. */\n depth: number;\n /** Conflict-column lookup key (the STI base for STI members). */\n conflictKey: string;\n}\n\n/**\n * A merged physical table assembled from every class that contributes to it.\n */\ninterface MergedTableSchema {\n tableName: string;\n columns: Record<string, ColumnDefinition>;\n indexes: IndexDefinition[];\n ddl: string;\n isSTI: boolean;\n conflictColumns: string[];\n}\n\nfunction applyContributorForeignKeys(\n tableSchema: MergedTableSchema,\n contributor: TableContributor,\n): void {\n const conflictColumns = new Set(tableSchema.conflictColumns);\n for (const [fieldName, field] of contributor.registered.fields) {\n if (field.type !== 'foreignKey' || !field.related) continue;\n const columnName = toSnakeCase(fieldName);\n const column = tableSchema.columns[columnName];\n if (!column) continue;\n if (\n field._meta?.__tenancy?.isTenantIdField === true ||\n (\n field as FieldDefinition & {\n __tenancy?: { isTenantIdField?: boolean };\n }\n ).__tenancy?.isTenantIdField === true\n ) {\n column.foreignKey = undefined;\n continue;\n }\n const [legacyTargetName, declaredTargetColumn] = field.related.split('.');\n const resolvedTarget = ObjectRegistry.resolveRelationshipTarget(\n contributor.qualifiedName,\n fieldName,\n );\n if (resolvedTarget === null) {\n throw new Error(\n `Cannot resolve foreign key ${contributor.qualifiedName}.${fieldName}: target constructor is unregistered or the target name is ambiguous`,\n );\n }\n const targetName = resolvedTarget ?? legacyTargetName;\n const targetBase = ObjectRegistry.getSTIBase(targetName) || targetName;\n const registeredTarget = ObjectRegistry.getClass(targetBase);\n const targetColumn =\n declaredTargetColumn ||\n Array.from(ObjectRegistry.getFields(targetBase).entries()).find(\n ([, targetField]) => targetField._meta?.primaryKey === true,\n )?.[0] ||\n 'id';\n if (registeredTarget && !field._meta?.sqlType) {\n const targetColumnName = toSnakeCase(targetColumn);\n const targetColumnType =\n registeredTarget.schema?.columns?.[targetColumnName]?.type ||\n (targetColumnName === 'id'\n ? registeredTarget.config.idType === 'text'\n ? 'TEXT'\n : 'UUID'\n : undefined);\n if (targetColumnType) {\n column.type = targetColumnType;\n }\n }\n if (field._meta?.constraint === false) {\n column.foreignKey = undefined;\n continue;\n }\n // A manifest may carry explicit actions that predate or differ from the\n // runtime decorator defaults. Merging runtime fields must not erase them.\n // The fallback produced from runtime fields, however, must be replaced so\n // conflict columns receive the same default CASCADE as app-side cleanup.\n const manifestForeignKey =\n contributor.registered.schema?.columns?.[columnName]?.foreignKey;\n if (manifestForeignKey) {\n column.foreignKey = manifestForeignKey;\n continue;\n }\n // A decorator-only runtime field has no authoritative physical target\n // until that target is registered. Scanner-produced manifests clear this\n // shape too; only an explicit manifest FK above may survive unloaded\n // runtime classes (the manifest-authority contract from #1120).\n if (!registeredTarget) {\n column.foreignKey = undefined;\n continue;\n }\n const targetTable =\n ObjectRegistry.getTableName(targetBase) ||\n classnameToTablename(targetBase);\n const { action } = resolveForeignKeyDeleteAction({\n declared: field._meta?.onDelete,\n isConflictColumn: conflictColumns.has(columnName),\n isTenantIdField: false,\n });\n column.foreignKey = {\n table: targetTable,\n column: toSnakeCase(targetColumn),\n onDelete: action,\n onUpdate: 'CASCADE',\n ...(typeof field._meta?.constraint === 'object'\n ? { engines: [...field._meta.constraint.engines] }\n : {}),\n };\n }\n}\n\n/**\n * Resolve the physical table a registered class writes to.\n *\n * STI subclasses are folded onto their base's table. Returns `undefined` when\n * the class has no table (for example an unresolvable manifest stub).\n *\n * R5-canon: STI lookups use the qualified key so a colliding simple name in\n * another package cannot yield the wrong table strategy or STI base and move\n * this class's columns under that other package's table.\n */\nfunction resolveContributorTable(\n registered: RegisteredClass,\n fallbackName: string,\n): { tableName: string; contributor: TableContributor } | undefined {\n const simpleName = registered.name || fallbackName;\n const qualifiedName = registered.qualifiedName ?? simpleName;\n\n // STI subclasses loaded from external manifests can arrive with a null\n // tableName; registerFromManifest() then derives one from the class name.\n // Adopt the STI base's tableName instead so the subclass lands on the\n // shared table (issue #703).\n if (!registered.schema?.tableName && registered.extends) {\n if (ObjectRegistry.getTableStrategy(qualifiedName) === 'sti') {\n const stiBaseName = ObjectRegistry.getSTIBase(qualifiedName);\n if (stiBaseName && stiBaseName !== qualifiedName) {\n const stiBaseClass = findClass(stiBaseName);\n if (stiBaseClass?.schema?.tableName) {\n if (!registered.schema) {\n registered.schema = {\n tableName: '',\n ddl: '',\n columns: {},\n indexes: [],\n triggers: [],\n foreignKeys: [],\n dependencies: [],\n version: '',\n };\n }\n registered.schema.tableName = stiBaseClass.schema.tableName;\n }\n }\n }\n }\n\n if (!registered.schema?.tableName) {\n return undefined;\n }\n\n let tableName = registered.schema.tableName;\n const tableStrategy = ObjectRegistry.getTableStrategy(qualifiedName);\n const isSTI = tableStrategy === 'sti';\n let isSTIBase = isSTI;\n let conflictKey = qualifiedName;\n\n if (isSTI) {\n const stiBaseName = ObjectRegistry.getSTIBase(qualifiedName);\n if (stiBaseName) {\n conflictKey = stiBaseName;\n if (stiBaseName !== qualifiedName) {\n isSTIBase = false;\n // STI subclasses serialize to the base class's table even when they\n // carry a tableName of their own (issue #693).\n const stiBaseClass = findClass(stiBaseName);\n if (stiBaseClass?.schema?.tableName) {\n tableName = stiBaseClass.schema.tableName;\n }\n }\n }\n }\n\n return {\n tableName,\n contributor: {\n registered,\n simpleName,\n qualifiedName,\n isSTI,\n isSTIBase,\n depth: ObjectRegistry.getInheritanceChain(qualifiedName).length,\n conflictKey,\n },\n };\n}\n\n/**\n * Order the classes that share one table deterministically.\n *\n * The first contributor seeds the table: it supplies the base columns, the\n * `idType`, the conflict columns and the cached DDL, and its columns win every\n * merge conflict. Registration order must not decide that, or the same\n * hierarchy yields a different table shape depending on which class a manifest\n * happens to list first — child-first dropped NOT NULL and DEFAULT from the\n * base columns (#2372).\n *\n * Order: the STI base first, then ancestors before descendants, then by\n * qualified name so the result is a total order.\n */\nfunction sortTableContributors(contributors: TableContributor[]) {\n return [...contributors].sort((a, b) => {\n if (a.isSTIBase !== b.isSTIBase) {\n return a.isSTIBase ? -1 : 1;\n }\n if (a.depth !== b.depth) {\n return a.depth - b.depth;\n }\n return a.qualifiedName.localeCompare(b.qualifiedName);\n });\n}\n\n/**\n * Assemble every physical table from the classes that contribute to it.\n *\n * Shared by {@link getAllSchemas} and {@link getAllSchemasAsDefinitions} so\n * both produce the same merged shape. The result depends only on what is\n * registered, never on the order it was registered in.\n */\nfunction buildMergedTableSchemas(): Record<string, MergedTableSchema> {\n // Pass 1: group contributing classes by physical table.\n const contributorsByTable = new Map<string, TableContributor[]>();\n\n for (const [className, registered] of getClasses()) {\n // Collection classes have no table of their own; their schemas carry\n // collection properties (loaded, options, ...) rather than columns.\n if (\n isCollectionRegistration(\n className,\n registered,\n collectionRegistrationLookup,\n )\n ) {\n continue;\n }\n\n // Framework abstract base classes (SmrtObject, SmrtClass, ...) are\n // scaffolding, not resources — they produce no table (#2642).\n if (isFrameworkBaseClass(registered.name, registered.packageName)) {\n continue;\n }\n\n const resolved = resolveContributorTable(registered, className);\n if (!resolved) {\n continue;\n }\n\n const existing = contributorsByTable.get(resolved.tableName);\n if (existing) {\n existing.push(resolved.contributor);\n } else {\n contributorsByTable.set(resolved.tableName, [resolved.contributor]);\n }\n }\n\n // Pass 2: merge each table's contributors in deterministic order.\n const tableSchemas: Record<string, MergedTableSchema> = {};\n\n for (const [tableName, contributors] of contributorsByTable) {\n for (const contributor of sortTableContributors(contributors)) {\n const { registered, simpleName, isSTI } = contributor;\n const conflictColumns = ObjectRegistry.getConflictColumns(\n contributor.conflictKey,\n );\n\n // The manifest schema stays authoritative for the columns it defines.\n // Runtime field metadata backfills columns the manifest never had (for\n // example tenantScoped injections) and applies explicit sqlType\n // overrides, without erasing richer manifest metadata.\n const columnsToUse = mergeRuntimeFieldColumns(\n simpleName,\n registered.schema?.columns,\n registered.fields,\n { stiUnionColumns: isSTI, conflictColumns },\n );\n\n let tableSchema = tableSchemas[tableName];\n if (!tableSchema) {\n tableSchema = {\n tableName,\n columns: {\n ...createBaseColumns(registered, isSTI),\n ...columnsToUse,\n },\n indexes: [],\n ddl: registered.schema?.ddl || '',\n isSTI,\n conflictColumns,\n };\n tableSchemas[tableName] = tableSchema;\n } else {\n // Another class sharing this table (STI): add only columns the\n // seeding contributor did not already define.\n for (const [colName, colDef] of Object.entries(columnsToUse)) {\n if (!tableSchema.columns[colName]) {\n tableSchema.columns[colName] = colDef;\n }\n }\n }\n\n applyContributorForeignKeys(tableSchema, contributor);\n\n // Merge indexes, keeping the first definition of each name.\n const schemaIndexes = registered.schema?.indexes;\n if (schemaIndexes && schemaIndexes.length > 0) {\n const existingNames = new Set(\n tableSchema.indexes.map((index) => index.name),\n );\n for (const index of schemaIndexes) {\n // Legacy string-format indexes carry no columns and cannot be merged.\n if (typeof index === 'string') {\n continue;\n }\n if (!existingNames.has(index.name)) {\n tableSchema.indexes.push(index);\n existingNames.add(index.name);\n }\n }\n }\n }\n }\n\n return tableSchemas;\n}\n\n/**\n * Get all pre-generated schemas for explicit adapter bootstrap paths.\n *\n * Returns schemas in SDK SchemaProvider format for all registered classes.\n * Tooling and test helpers can pass these to `getDatabase()` when they want\n * to bootstrap schema before runtime. Core runtime no longer does this\n * implicitly.\n *\n * @returns Record of table names to schema definitions\n * @example\n * ```typescript\n * const schemas = ObjectRegistry.getAllSchemas('json');\n * const db = await getDatabase({ type: 'json', url: './data', schemas });\n * ```\n */\nexport function getAllSchemas(\n engine?: DatabaseEngine,\n): Record<string, { tableName: string; ddl: string; indexes?: string[] }> {\n // Step 1: Assemble every table from its contributing classes. The merge is\n // deterministic, so the shape does not depend on registration order (#2372).\n const tableSchemas = buildMergedTableSchemas();\n\n // Step 2: Convert to output format, regenerating DDL for merged schemas\n const schemas: Record<\n string,\n { tableName: string; ddl: string; indexes?: string[] }\n > = {};\n\n for (const [tableName, tableSchema] of Object.entries(tableSchemas)) {\n const engineIndexes = engine\n ? withConflictIndex(\n tableName,\n tableSchema.columns,\n tableSchema.indexes,\n tableSchema.conflictColumns,\n )\n : tableSchema.indexes;\n const mergedSchema: SchemaDefinition = {\n tableName,\n ddl: tableSchema.ddl,\n columns: tableSchema.columns,\n indexes: engineIndexes,\n triggers: [],\n foreignKeys: [],\n version: '',\n dependencies: [],\n };\n mergedSchema.foreignKeys = schemaForeignKeys(mergedSchema);\n mergedSchema.dependencies = mergedSchema.foreignKeys\n .map((foreignKey) => foreignKey.referencesTable)\n .filter((dependency) => dependency !== tableName);\n\n // Generate DDL from merged columns (or use original DDL if columns are empty)\n let ddl: string;\n if (Object.keys(tableSchema.columns).length === 0 && tableSchema.ddl) {\n if (engine) {\n throw new Error(\n `Cannot materialize schema '${tableName}' for ${engine}: the manifest has no structured columns`,\n );\n }\n // Preserve legacy inspection of cached engine-neutral DDL. Executable\n // target-engine paths fail above rather than returning unsafe SQL.\n ddl = tableSchema.ddl;\n } else if (Object.keys(tableSchema.columns).length === 0) {\n // Skip schemas with no columns and no original DDL\n continue;\n } else if (engine) {\n // Target-engine materialization must route the complete structured\n // schema through its strategy. In particular, DuckDB/JSON require\n // UNIQUE constraints inline for ON CONFLICT, and every strategy owns\n // CHECK/default/index-expression rendering.\n ddl = getDDLStrategy(engine).generateCreateTable(mergedSchema);\n } else {\n ddl = generateDDLFromColumns(\n tableName,\n tableSchema.columns,\n tableSchema.isSTI,\n );\n }\n\n // Convert index definitions to SQL strings for SDK compatibility\n let indexSQL: string[] | undefined;\n if (engineIndexes.length > 0) {\n indexSQL = engine\n ? getDDLStrategy(engine).generateIndexes(mergedSchema)\n : engineIndexes.map((idx) => {\n const indexType = idx.unique ? 'UNIQUE INDEX' : 'INDEX';\n const columnList = idx.columns\n .map((col) => quoteIdentifier(col))\n .join(', ');\n return `CREATE ${indexType} IF NOT EXISTS ${quoteIdentifier(\n idx.name,\n )} ON ${quoteIdentifier(tableName)} (${columnList});`;\n });\n }\n\n schemas[tableName] = {\n tableName,\n ddl,\n indexes: indexSQL,\n };\n }\n\n return schemas;\n}\n\n/**\n * Get all registered schemas as SchemaDefinition objects\n *\n * Similar to getAllSchemas(), but returns SchemaDefinition format suitable\n * for use with SchemaComparer (migrations/differ.ts).\n *\n * Key difference: Indexes are kept as IndexDefinition objects instead of\n * being converted to SQL strings.\n *\n * @returns Map of tableName to SchemaDefinition\n */\nexport function getAllSchemasAsDefinitions(): Record<string, SchemaDefinition> {\n // Step 1: Assemble every table from its contributing classes. The merge is\n // deterministic, so the shape does not depend on registration order (#2372).\n const tableSchemas = buildMergedTableSchemas();\n\n // Step 2: Convert to SchemaDefinition format\n const schemas: Record<string, SchemaDefinition> = {};\n\n for (const [tableName, tableSchema] of Object.entries(tableSchemas)) {\n if (Object.keys(tableSchema.columns).length === 0) {\n continue;\n }\n\n // Generate DDL from columns\n const ddl = generateDDLFromColumns(\n tableName,\n tableSchema.columns,\n tableSchema.isSTI,\n );\n const foreignKeys = schemaForeignKeys({\n columns: tableSchema.columns,\n foreignKeys: [],\n });\n\n schemas[tableName] = {\n tableName,\n ddl,\n columns: tableSchema.columns,\n indexes: withConflictIndex(\n tableName,\n tableSchema.columns,\n tableSchema.indexes,\n tableSchema.conflictColumns,\n ),\n triggers: [],\n foreignKeys,\n version: '',\n dependencies: foreignKeys\n .map((foreignKey) => foreignKey.referencesTable)\n .filter((dependency) => dependency !== tableName),\n };\n }\n\n return schemas;\n}\n\n/**\n * Generate DDL CREATE TABLE statement from columns\n *\n * Used internally by getAllSchemas() to regenerate DDL after merging\n * columns from multiple STI subtypes that share the same table.\n *\n * @param tableName - Name of the table\n * @param columns - Column definitions\n * @returns DDL CREATE TABLE statement\n */\nexport function generateDDLFromColumns(\n tableName: string,\n columns: Record<string, ColumnDefinition>,\n isSTI = false,\n engine?: DatabaseEngine,\n): string {\n let sql = `CREATE TABLE IF NOT EXISTS ${quoteIdentifier(tableName)} (\\n`;\n\n const columnLines: string[] = [];\n for (const [columnName, columnDef] of Object.entries(columns)) {\n const parts: string[] = [];\n\n // Column name and type\n const strategy = engine ? getDDLStrategy(engine) : undefined;\n const columnType = strategy\n ? strategy.mapType(columnDef.type)\n : columnDef.type;\n parts.push(` ${quoteIdentifier(columnName)} ${columnType}`);\n\n // Primary key\n if (columnDef.primaryKey) {\n parts.push('PRIMARY KEY');\n }\n\n // Not null constraint\n if (columnDef.notNull) {\n parts.push('NOT NULL');\n }\n\n // Unique constraint (skip if primary key already implies uniqueness)\n if (columnDef.unique && !columnDef.primaryKey) {\n parts.push('UNIQUE');\n }\n\n // Default value\n if (columnDef.defaultValue !== undefined) {\n const defaultSQL = strategy\n ? strategy.formatDefaultValue(columnDef.defaultValue, columnDef.type)\n : formatDefaultValue(columnDef.defaultValue, columnDef.type);\n parts.push(`DEFAULT ${defaultSQL}`);\n }\n\n columnLines.push(parts.join(' '));\n }\n for (const foreignKey of schemaForeignKeys({ columns, foreignKeys: [] })) {\n columnLines.push(` ${renderForeignKeyConstraint(tableName, foreignKey)}`);\n }\n\n sql += columnLines.join(',\\n');\n\n // Add UNIQUE constraint for UPSERT operations\n // For STI tables: UNIQUE(slug, context, _meta_type) - different types can have same slug+context\n // For non-STI tables: UNIQUE(slug, context)\n if (columns.slug && columns.context) {\n if (isSTI && columns._meta_type) {\n sql += ',\\n UNIQUE(slug, context, _meta_type)';\n } else {\n sql += ',\\n UNIQUE(slug, context)';\n }\n }\n\n sql += '\\n);';\n\n return sql;\n}\n\n/**\n * Format default value for SQL DDL.\n *\n * Thin wrapper over the shared, injection-safe formatter\n * (`schema/sql-identifiers.ts`) so the registry schema-builder uses the same\n * rules as the DDL strategies and schema generator: an allowlist of SQL\n * keyword/function defaults (not \"contains `(`\"), type-driven literal quoting,\n * and no folding of a literal string `\"null\"` into the SQL NULL keyword.\n *\n * @param value - Default value\n * @param type - Column SQL type\n * @returns Formatted SQL default value\n */\nexport function formatDefaultValue(value: unknown, type: string): string {\n return formatDefaultValueShared(value, type);\n}\n\n/**\n * Options for {@link fieldsToColumns}.\n */\nexport interface FieldsToColumnsOptions {\n /**\n * Shape the columns for a single-table-inheritance table.\n *\n * An STI table holds the union of every subtype's fields, so a column that\n * only one subtype declares must stay nullable — rows of sibling subtypes\n * never populate it. This matches `generateSTISchemaFromManifest`, which\n * emits `notNull: false` for every non-system column on an STI table.\n * Declared defaults are still emitted.\n */\n stiUnionColumns?: boolean;\n /**\n * Physical column names that form the table's natural conflict key.\n * Undeclared delete actions on foreign-key members use the shared CASCADE\n * default, matching app-side relationship cleanup.\n */\n conflictColumns?: readonly string[];\n}\n\n/**\n * Convert a Map of field definitions to column definitions\n *\n * Used by getAllSchemas() to generate columns from fields when a class\n * has no pre-generated schema (e.g., STI subclasses registered from manifest).\n *\n * `required`, `default`, and `description` are read from either the top level\n * or `_meta`: registry-sourced fields normalize them into `_meta`, so reading\n * only the top level dropped NOT NULL and DEFAULT for every such field\n * (#2372).\n *\n * @param fields - Map of field name to field definition\n * @param options - Table-shape options (see {@link FieldsToColumnsOptions})\n * @returns Record of column name to column definition\n * @private\n */\nexport function fieldsToColumns(\n fields: Map<string, FieldDefinition>,\n options?: FieldsToColumnsOptions,\n): Record<string, ColumnDefinition> {\n const columns: Record<string, ColumnDefinition> = {};\n const conflictColumns = new Set(\n (options?.conflictColumns ?? []).map((column) => toSnakeCase(column)),\n );\n\n for (const [fieldName, fieldDef] of fields) {\n // Skip id, timestamps - they're on the base table\n if (\n fieldName === 'id' ||\n fieldName === 'created_at' ||\n fieldName === 'updated_at' ||\n fieldName === 'slug' ||\n fieldName === 'context'\n ) {\n continue;\n }\n\n // Skip transient fields (non-persisted)\n if (fieldDef.transient || fieldDef._meta?.transient) {\n continue;\n }\n\n // Skip relationship fields that don't create columns\n // oneToMany and manyToMany are relationship metadata, not actual database columns\n if (fieldDef.type === 'oneToMany' || fieldDef.type === 'manyToMany') {\n continue;\n }\n\n // Skip meta fields - they're stored in _meta_data JSONB column\n if (fieldDef.type === 'meta') {\n continue;\n }\n\n // Map field type to SQL type\n const sqlType =\n fieldDef._meta?.sqlType ||\n (fieldDef.type === 'crossPackageRef' &&\n (fieldDef._meta?.idType === 'text' ||\n (fieldDef as unknown as { idType?: string }).idType === 'text')\n ? 'TEXT'\n : mapFieldTypeToSQL(fieldDef.type));\n const normalizedSqlType = String(sqlType).toUpperCase() as SQLDataType;\n const referenceKind = getReferenceKind(fieldDef);\n\n const required = readFieldAttribute(fieldDef, 'required');\n const defaultValue = readFieldAttribute(fieldDef, 'default');\n const description = readFieldAttribute(fieldDef, 'description');\n\n const column: ColumnDefinition = {\n type: normalizedSqlType,\n referenceKind,\n notNull: options?.stiUnionColumns\n ? false\n : fieldDef._meta?.nullable\n ? false\n : Boolean(required),\n unique: fieldDef._meta?.unique || false,\n description: description as string | undefined,\n };\n\n // Handle default values\n if (\n defaultValue !== undefined &&\n shouldEmitDefault(fieldDef, normalizedSqlType, defaultValue)\n ) {\n column.defaultValue = defaultValue;\n }\n\n // Handle foreign keys\n if (\n fieldDef.type === 'foreignKey' &&\n fieldDef.related &&\n fieldDef._meta?.constraint !== false &&\n fieldDef._meta?.__tenancy?.isTenantIdField !== true &&\n !(\n fieldDef as FieldDefinition & {\n __tenancy?: { isTenantIdField?: boolean };\n }\n ).__tenancy?.isTenantIdField\n ) {\n const [table, columnName = 'id'] = fieldDef.related.split('.');\n const fieldMeta = fieldDef._meta as\n | {\n onDelete?: ForeignKeyAction;\n onUpdate?: ForeignKeyAction;\n }\n | undefined;\n column.foreignKey = {\n table: classnameToTablename(table),\n column: columnName,\n onDelete: resolveForeignKeyDeleteAction({\n declared: fieldMeta?.onDelete,\n isConflictColumn: conflictColumns.has(toSnakeCase(fieldName)),\n isTenantIdField: false,\n }).action,\n onUpdate:\n fieldMeta?.onUpdate === undefined\n ? 'CASCADE'\n : requireForeignKeyAction(\n fieldMeta.onUpdate,\n `${fieldName} ON UPDATE`,\n ),\n ...(typeof fieldDef._meta?.constraint === 'object'\n ? { engines: [...fieldDef._meta.constraint.engines] }\n : {}),\n };\n }\n\n // Use snake_case for column names\n columns[toSnakeCase(fieldName)] = column;\n }\n\n return columns;\n}\n\n/**\n * Map field type to SQL data type\n * @private\n */\nexport function mapFieldTypeToSQL(\n fieldType: FieldDefinition['type'],\n): SQLDataType {\n switch (fieldType) {\n case 'text':\n return 'TEXT';\n case 'integer':\n return 'INTEGER';\n case 'decimal':\n return 'REAL';\n case 'boolean':\n return 'BOOLEAN';\n case 'datetime':\n return 'TIMESTAMP';\n case 'json':\n return 'JSON';\n case 'foreignKey':\n return 'UUID';\n case 'crossPackageRef':\n return 'UUID';\n default:\n return 'TEXT';\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA6CA,IAAM,+BAA6D;CACjE;CACA,qBAAqB,aAAa,cAChC,eAAe,kBAAkB,aAAa,SAAS;CACzD,sBAAsB,cACpB,eAAe,oBAAoB,SAAS;AAChD;AAEA,SAAS,+BACP,WACA,SACkC;CAClC,MAAM,aAAa,eAAe,mBAAmB,SAAS;CAC9D,IAAI,CAAC,WAAW,MACd,OAAO;CAGT,KAAK,MAAM,CAAC,WAAW,YAAY,YAAY;EA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EACF;EAGA,QAAQ,YAAY,SAAS,KAAK;CACpC;CAEA,OAAO;AACT;;;;;AAMA,SAAgB,kBACd,WACa;CACb,QAAQ,WAAR;EACE,KAAK,QACH,OAAO;EACT,KAAK,WACH,OAAO;EACT,KAAK,WACH,OAAO;EACT,KAAK,WACH,OAAO;EACT,KAAK,YACH,OAAO;EACT,KAAK,QACH,OAAO;EACT,KAAK,cACH,OAAO;EACT,KAAK,mBACH,OAAO;EACT,SACE,OAAO;CACX;AACF"}
|
|
@@ -10,6 +10,9 @@ declare global {
|
|
|
10
10
|
var __smrtRegistryNextDbId: number | undefined;
|
|
11
11
|
var __smrtRegistryInheritanceChainCache: LRUCache<string, string[]> | undefined;
|
|
12
12
|
var __smrtRegistryFieldDecorators: Map<string, Map<string, Record<string, unknown>>> | undefined;
|
|
13
|
+
var __smrtRegistryLegacyFieldDecorators: Map<string, Map<string, Record<string, unknown>>> | undefined;
|
|
14
|
+
var __smrtRegistryConstructorFieldDecorators: Map<Function, Map<string, Record<string, unknown>>> | undefined;
|
|
15
|
+
var __smrtRegistryConstructorTenantScopedDeclarations: Map<Function, Record<string, unknown>> | undefined;
|
|
13
16
|
var __smrtRegistryMethodDecorators: WeakMap<Function, Map<string, {
|
|
14
17
|
options: Record<string, unknown>;
|
|
15
18
|
isStatic: boolean;
|
|
@@ -66,6 +69,21 @@ export declare function getDbInstanceIds(): WeakMap<object, number>;
|
|
|
66
69
|
export declare function getNextDbId(): number;
|
|
67
70
|
export declare function setNextDbId(value: number): void;
|
|
68
71
|
export declare function getFieldDecorators(): Map<string, Map<string, Record<string, unknown>>>;
|
|
72
|
+
/**
|
|
73
|
+
* Field-decorator metadata keyed by the exact runtime constructor. This is
|
|
74
|
+
* used for identity-sensitive declarations while the string-keyed map remains
|
|
75
|
+
* the compatibility store for legacy decorator consumers.
|
|
76
|
+
*/
|
|
77
|
+
export declare function getConstructorFieldDecorators(): Map<Function, Map<string, Record<string, unknown>>>;
|
|
78
|
+
/** Explicit string-only registrations, excluding constructor-owned mirrors. */
|
|
79
|
+
export declare function getLegacyFieldDecorators(): Map<string, Map<string, Record<string, unknown>>>;
|
|
80
|
+
/**
|
|
81
|
+
* Class-level tenancy declarations keyed by their exact constructor.
|
|
82
|
+
*
|
|
83
|
+
* Unlike method metadata, these declarations participate in the registry's
|
|
84
|
+
* explicit clear and test snapshot lifecycle, so they use an iterable Map.
|
|
85
|
+
*/
|
|
86
|
+
export declare function getConstructorTenantScopedDeclarations(): Map<Function, Record<string, unknown>>;
|
|
69
87
|
/**
|
|
70
88
|
* `@method()` decorator metadata,
|
|
71
89
|
* `constructor -> methodName -> { options, isStatic }`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-state.d.ts","sourceRoot":"","sources":["../../src/registry/shared-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAKpD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAGtE,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,qBAAqB,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,SAAS,CAAC;IAEpE,IAAI,yBAAyB,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,cAAc,CAAC,GAAG,SAAS,CAAC;IAO9E,IAAI,6BAA6B,EACjC,AADmC,oNAAoN;IACvP,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC;IAElD,IAAI,2BAA2B,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IAErE,IAAI,sBAAsB,EAAE,MAAM,GAAG,SAAS,CAAC;IAE/C,IAAI,mCAAmC,EACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAC1B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