@happyvertical/smrt-core 0.51.25 → 0.51.26
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.md +14 -5
- package/dist/manifest/manifest-loader.d.ts +37 -0
- package/dist/manifest/manifest-loader.d.ts.map +1 -1
- package/dist/manifest/manifest-loader.js +45 -14
- package/dist/manifest/manifest-loader.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/registry/__tests__/helpers/consumer-workspace.d.ts +42 -0
- package/dist/registry/__tests__/helpers/consumer-workspace.d.ts.map +1 -0
- package/dist/registry/class-registration.d.ts +15 -0
- package/dist/registry/class-registration.d.ts.map +1 -1
- package/dist/registry/class-registration.js +129 -19
- package/dist/registry/class-registration.js.map +1 -1
- package/dist/registry/collection-resolution.d.ts +8 -2
- package/dist/registry/collection-resolution.d.ts.map +1 -1
- package/dist/registry/collection-resolution.js +12 -2
- package/dist/registry/collection-resolution.js.map +1 -1
- package/dist/registry/collision-policy.d.ts +10 -0
- package/dist/registry/collision-policy.d.ts.map +1 -1
- package/dist/registry/collision-policy.js +7 -1
- package/dist/registry/collision-policy.js.map +1 -1
- package/dist/registry/shared-state.d.ts.map +1 -1
- package/dist/registry/shared-state.js +3 -4
- package/dist/registry/shared-state.js.map +1 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +16 -3
- package/dist/registry.js.map +1 -1
- package/dist/smrt-knowledge.json +5 -5
- package/dist/utils/stack-frames.d.ts +19 -0
- package/dist/utils/stack-frames.d.ts.map +1 -1
- package/dist/utils/stack-frames.js +59 -1
- package/dist/utils/stack-frames.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export interface ConsumerWorkspace {
|
|
2
|
+
root: string;
|
|
3
|
+
path: (...segments: string[]) => string;
|
|
4
|
+
write: (relativePath: string, content: string) => string;
|
|
5
|
+
writePackage: (relativeDir: string, name: string) => void;
|
|
6
|
+
/** A fixture module declaring one class via `define({ smrt, SmrtObject })`. */
|
|
7
|
+
writeModel: (relativePath: string, className: string, config?: Record<string, unknown>) => string;
|
|
8
|
+
dispose: () => void;
|
|
9
|
+
}
|
|
10
|
+
export declare function createConsumerWorkspace(prefix: string): ConsumerWorkspace;
|
|
11
|
+
/** A manifest entry as an app's scanner writes it. */
|
|
12
|
+
export declare function manifestEntry(options: {
|
|
13
|
+
className: string;
|
|
14
|
+
packageName: string;
|
|
15
|
+
filePath: string;
|
|
16
|
+
tableName: string;
|
|
17
|
+
fields: Record<string, {
|
|
18
|
+
type: string;
|
|
19
|
+
}>;
|
|
20
|
+
}): {
|
|
21
|
+
name: string;
|
|
22
|
+
className: string;
|
|
23
|
+
qualifiedName: string;
|
|
24
|
+
packageName: string;
|
|
25
|
+
filePath: string;
|
|
26
|
+
extends: string;
|
|
27
|
+
fields: Record<string, {
|
|
28
|
+
type: string;
|
|
29
|
+
}>;
|
|
30
|
+
methods: {};
|
|
31
|
+
decoratorConfig: {
|
|
32
|
+
tableName: string;
|
|
33
|
+
};
|
|
34
|
+
schema: {
|
|
35
|
+
tableName: string;
|
|
36
|
+
ddl: string;
|
|
37
|
+
columns: {};
|
|
38
|
+
indexes: never[];
|
|
39
|
+
version: string;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=consumer-workspace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consumer-workspace.d.ts","sourceRoot":"","sources":["../../../../src/registry/__tests__/helpers/consumer-workspace.ts"],"names":[],"mappings":"AAyBA,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC;IACxC,KAAK,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;IACzD,YAAY,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1D,+EAA+E;IAC/E,UAAU,EAAE,CACV,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAiCzE;AAED,sDAAsD;AACtD,wBAAgB,aAAa,CAAC,OAAO,EAAE;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC1C;;;;;;;;cADgC,MAAM;;;;;;;;;;;;;EAqBtC"}
|
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import { SmrtObject } from '../object';
|
|
2
2
|
import { SmartObjectDefinition } from '../scanner/types.js';
|
|
3
3
|
import { RegisteredClass, RegisteredField, SmartObjectConfig } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Shared bundled-context detector. Source files in these output
|
|
6
|
+
* directories come from a bundler (Vite library mode, webpack, Next.js,
|
|
7
|
+
* Nuxt, svelte-kit) that can duplicate module code across chunks.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isBundledOutputPath(sourceFile: string | undefined): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Whether two source paths name the same file. A stack frame reports an
|
|
12
|
+
* absolute path; a manifest's `filePath` is absolute or relative to the
|
|
13
|
+
* project or workspace root it was scanned from (anytown scans
|
|
14
|
+
* `packages/cloud-network/src/models/*.ts` into the dashboard's manifest,
|
|
15
|
+
* #3110), so a relative path is resolved against those roots, never matched by
|
|
16
|
+
* suffix alone.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isSameSourcePath(left: string | undefined, right: string | undefined): boolean;
|
|
4
19
|
/**
|
|
5
20
|
* Register (or re-register) a class. Every registration can add, replace or
|
|
6
21
|
* mutate a registered class in place, so it invalidates the generation-keyed
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"class-registration.d.ts","sourceRoot":"","sources":["../../src/registry/class-registration.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"class-registration.d.ts","sourceRoot":"","sources":["../../src/registry/class-registration.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAuBH,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAKV,qBAAqB,EAGtB,MAAM,qBAAqB,CAAC;AA2C7B,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EACf,iBAAiB,EAElB,MAAM,YAAY,CAAC;AA0BpB;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAS3E;AA4BD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,KAAK,EAAE,MAAM,GAAG,SAAS,GACxB,OAAO,CAeT;AA+mBD;;;;GAIG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,OAAO,UAAU,EACvB,MAAM,GAAE,iBAAsB,GAC7B,IAAI,CAON;AA0gCD,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,MAAM,EAMlB,qBAAqB,EAAE,WAAW,CAAC,eAAe,CAAC,uBAAuB,CAAC,CAAC,GAC3E,IAAI,CAeN;AA+BD,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,EACpC,kBAAkB,EAAE,eAAe,CAAC,oBAAoB,CAAC,GAAG,SAAS,GACpE,IAAI,CAyCN;AAoHD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,eAAe,EACzB,gBAAgB,CAAC,EAAE;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,GACA,IAAI,CA4CN;AA2KD,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,qBAAqB,EAChC,mBAAmB,CAAC,EAAE,MAAM,GAC3B,IAAI,CAQN"}
|
|
@@ -2,10 +2,10 @@ import { ConfigurationError } from "../errors.js";
|
|
|
2
2
|
import { toSnakeCase } from "../utils/naming.js";
|
|
3
3
|
import { declareChangeFeedSensitiveTable, setChangeFeedSensitiveClassResolver } from "../change-feed-sensitivity.js";
|
|
4
4
|
import { bumpRegistryGeneration } from "./generation.js";
|
|
5
|
-
import { createQualifiedName, isQualifiedName } from "../utils/qualified-names.js";
|
|
5
|
+
import { createQualifiedName, isQualifiedName, parseQualifiedName } from "../utils/qualified-names.js";
|
|
6
6
|
import { getClasses, getCollections, getConstructorFieldDecorators, getConstructorIndex, getConstructorTenantScopedDeclarations, getInheritanceCache, getLegacyFieldDecorators, getSourceFileFromStack, getStiSiblingsLoaded, verboseLog } from "./shared-state.js";
|
|
7
|
-
import { cloneManifestSchemaColumns } from "../manifest/store.js";
|
|
8
|
-
import { discoverManifestSync, discoverSTISiblingsSync, getPackageName, lookupInManifest } from "../manifest/manifest-loader.js";
|
|
7
|
+
import { cloneManifestSchemaColumns, findWorkspaceRootSync, getLocalTestManifestCache, getManifestCache, getNodeBuiltins, getStaticManifestCache, getTestManifestCache } from "../manifest/store.js";
|
|
8
|
+
import { discoverManifestSync, discoverSTISiblingsSync, getPackageName, lookupInManifest, readProjectManifestSync } from "../manifest/manifest-loader.js";
|
|
9
9
|
import { findClass, findClassesByName, getCanonicalClassName, hasClassCaseInsensitive, qualifyExtendsName } from "./name-resolver.js";
|
|
10
10
|
import { buildInheritanceChain } from "./inheritance-resolver.js";
|
|
11
11
|
import { compileValidators } from "./validator.js";
|
|
@@ -52,12 +52,100 @@ function isBundledOutputPath(sourceFile) {
|
|
|
52
52
|
if (!sourceFile) return false;
|
|
53
53
|
return sourceFile.includes(".svelte-kit/output/") || sourceFile.includes("/dist/") || sourceFile.includes("/build/") || sourceFile.includes(".next/") || sourceFile.includes(".nuxt/");
|
|
54
54
|
}
|
|
55
|
+
function normalizeSourcePath(path) {
|
|
56
|
+
return path.replace(/^file:\/\//, "").replace(/\\/g, "/").replace(/^\.\//, "");
|
|
57
|
+
}
|
|
58
|
+
function isAbsoluteSourcePath(path) {
|
|
59
|
+
return path.startsWith("/") || /^[a-z]:\//i.test(path);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Directories a relative manifest `filePath` can be relative to: the scanned
|
|
63
|
+
* project (the process's working directory) and its workspace root.
|
|
64
|
+
*/
|
|
65
|
+
function relativeSourceRoots() {
|
|
66
|
+
if (typeof process === "undefined" || typeof process.cwd !== "function") return [];
|
|
67
|
+
const cwd = normalizeSourcePath(process.cwd());
|
|
68
|
+
const workspaceRoot = findWorkspaceRootSync(process.cwd());
|
|
69
|
+
return workspaceRoot && normalizeSourcePath(workspaceRoot) !== cwd ? [cwd, normalizeSourcePath(workspaceRoot)] : [cwd];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Whether two source paths name the same file. A stack frame reports an
|
|
73
|
+
* absolute path; a manifest's `filePath` is absolute or relative to the
|
|
74
|
+
* project or workspace root it was scanned from (anytown scans
|
|
75
|
+
* `packages/cloud-network/src/models/*.ts` into the dashboard's manifest,
|
|
76
|
+
* #3110), so a relative path is resolved against those roots, never matched by
|
|
77
|
+
* suffix alone.
|
|
78
|
+
*/
|
|
79
|
+
function isSameSourcePath(left, right) {
|
|
80
|
+
if (!left || !right) return false;
|
|
81
|
+
const a = normalizeSourcePath(left);
|
|
82
|
+
const b = normalizeSourcePath(right);
|
|
83
|
+
if (a === b) return true;
|
|
84
|
+
const aAbsolute = isAbsoluteSourcePath(a);
|
|
85
|
+
if (aAbsolute === isAbsoluteSourcePath(b)) return false;
|
|
86
|
+
const [absolute, relative] = aAbsolute ? [a, b] : [b, a];
|
|
87
|
+
const path = getNodeBuiltins()?.path;
|
|
88
|
+
if (!path) return false;
|
|
89
|
+
return relativeSourceRoots().some((root) => normalizeSourcePath(path.resolve(root, relative)) === absolute);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The package whose loaded manifest describes the class declared in
|
|
93
|
+
* `sourceFile` — the class's identity when its nearest `package.json` is not
|
|
94
|
+
* the package that scanned it (#3110). An app manifest commonly scans workspace
|
|
95
|
+
* packages' sources under the app's own package name (anytown's
|
|
96
|
+
* `packages/cloud-network` models are `@anytown/dashboard:*`), so the
|
|
97
|
+
* stack-derived package of a source-consumed class (Vite dev server, Vitest,
|
|
98
|
+
* tsx) never declares it.
|
|
99
|
+
*
|
|
100
|
+
* When several packages' entries describe the file, the stack-derived package
|
|
101
|
+
* wins if it is one of them; otherwise a single candidate, or the one owned by
|
|
102
|
+
* the manifest it appears in. Anything else is ambiguous and yields
|
|
103
|
+
* `undefined`.
|
|
104
|
+
*/
|
|
105
|
+
function findManifestPackageForSource(name, sourceFile, stackPackageName) {
|
|
106
|
+
if (!sourceFile) return void 0;
|
|
107
|
+
const manifests = /* @__PURE__ */ new Set();
|
|
108
|
+
for (const manifest of [
|
|
109
|
+
getLocalTestManifestCache(),
|
|
110
|
+
getTestManifestCache(),
|
|
111
|
+
getStaticManifestCache(),
|
|
112
|
+
...getManifestCache().values()
|
|
113
|
+
]) if (manifest?.objects) manifests.add(manifest);
|
|
114
|
+
const resolved = resolveSourceManifestPackage(name, sourceFile, stackPackageName, manifests);
|
|
115
|
+
if (resolved) return resolved;
|
|
116
|
+
const projectManifest = readProjectManifestSync();
|
|
117
|
+
return projectManifest?.objects && !manifests.has(projectManifest) ? resolveSourceManifestPackage(name, sourceFile, stackPackageName, /* @__PURE__ */ new Set([projectManifest])) : void 0;
|
|
118
|
+
}
|
|
119
|
+
function resolveSourceManifestPackage(name, sourceFile, stackPackageName, manifests) {
|
|
120
|
+
const candidates = /* @__PURE__ */ new Map();
|
|
121
|
+
const ownedByTheirManifest = /* @__PURE__ */ new Set();
|
|
122
|
+
for (const manifest of manifests) for (const [key, entry] of Object.entries(manifest.objects)) {
|
|
123
|
+
const qualified = isQualifiedName(key) ? parseQualifiedName(key) : void 0;
|
|
124
|
+
if ((entry.className ?? qualified?.className ?? key) !== name) continue;
|
|
125
|
+
if (!isSameSourcePath(sourceFile, entry.filePath)) continue;
|
|
126
|
+
const entryPackage = entry.packageName ?? qualified?.packageName ?? manifest.packageName;
|
|
127
|
+
if (!entryPackage) continue;
|
|
128
|
+
if (!candidates.has(entryPackage)) candidates.set(entryPackage, {
|
|
129
|
+
...entry,
|
|
130
|
+
packageName: entryPackage
|
|
131
|
+
});
|
|
132
|
+
if (entryPackage === manifest.packageName) ownedByTheirManifest.add(entryPackage);
|
|
133
|
+
}
|
|
134
|
+
const pick = (packageName) => ({
|
|
135
|
+
packageName,
|
|
136
|
+
entry: candidates.get(packageName)
|
|
137
|
+
});
|
|
138
|
+
if (stackPackageName && candidates.has(stackPackageName)) return pick(stackPackageName);
|
|
139
|
+
if (candidates.size === 1) return pick([...candidates.keys()][0]);
|
|
140
|
+
if (ownedByTheirManifest.size === 1) return pick([...ownedByTheirManifest][0]);
|
|
141
|
+
}
|
|
55
142
|
/**
|
|
56
143
|
* Build `CollisionInputs` for the decorator-origin path (`register()`).
|
|
57
144
|
* Manifest-origin inputs are built separately inside `registerFromManifest`.
|
|
58
145
|
*/
|
|
59
146
|
function buildDecoratorCollisionInputs(args) {
|
|
60
|
-
const { ctor, name, newPackageName, newSourceFile, newInBundledContext, existing, existingKey, matchKind } = args;
|
|
147
|
+
const { ctor, name, newPackageName, newSourceFile, newInBundledContext, newDeclaredTableName, existing, existingKey, matchKind } = args;
|
|
148
|
+
const existingTableName = existing.schema?.tableName || existing.config?.tableName;
|
|
61
149
|
let newExtendsExisting = false;
|
|
62
150
|
let existingExtendsNew = false;
|
|
63
151
|
try {
|
|
@@ -65,7 +153,7 @@ function buildDecoratorCollisionInputs(args) {
|
|
|
65
153
|
existingExtendsNew = existing.constructor.prototype instanceof ctor;
|
|
66
154
|
} catch {}
|
|
67
155
|
const bothSourceFilesKnown = !!(newSourceFile && existing.sourceFilePath);
|
|
68
|
-
const sameSourceFile = bothSourceFilesKnown && newSourceFile
|
|
156
|
+
const sameSourceFile = bothSourceFilesKnown && isSameSourcePath(newSourceFile, existing.sourceFilePath);
|
|
69
157
|
const existingIsPackageQualified = !!existing.packageName?.startsWith("@");
|
|
70
158
|
const samePackage = !!newPackageName && !!existing.packageName && newPackageName === existing.packageName;
|
|
71
159
|
const hasNewQualifiedKey = !!newPackageName;
|
|
@@ -88,7 +176,8 @@ function buildDecoratorCollisionInputs(args) {
|
|
|
88
176
|
existingHasAnyPackage: !!existing.packageName,
|
|
89
177
|
hasManifestContent: false,
|
|
90
178
|
registrationKeyDiffersFromExistingKey: false,
|
|
91
|
-
existingHasNoPackage: !existing.packageName
|
|
179
|
+
existingHasNoPackage: !existing.packageName,
|
|
180
|
+
declaresDifferentTable: !!newDeclaredTableName && !!existingTableName && newDeclaredTableName !== existingTableName
|
|
92
181
|
};
|
|
93
182
|
}
|
|
94
183
|
/**
|
|
@@ -116,8 +205,10 @@ function applyRegisterCollisionPolicy(args) {
|
|
|
116
205
|
const matchSuffix = args.matchKind === "case-insensitive" ? ` (case-insensitive match with "${args.existingKey}")` : "";
|
|
117
206
|
throw new Error(`SMRT Class Name Collision: "${args.name}"${matchSuffix}\n\nA class with this name is already registered, but with a different constructor.\nThis usually happens when:\n 1. Multiple test files define classes with the same name\n 2. Different packages export classes with the same name\n\nThe collision will cause the wrong field definitions to be used,\nleading to properties not being initialized correctly.\n\nTo fix:\n - Use unique class names (e.g., ${args.name}_UniqueId)\n - Or use @smrt({ name: 'unique_name' }) to override the registration name`);
|
|
118
207
|
}
|
|
119
|
-
case "
|
|
120
|
-
|
|
208
|
+
case "coexist-qualified":
|
|
209
|
+
verboseLog(`[registry] ${decision.scenario}: '${args.name}' coexists with '${args.existingKey}' (${decision.reason})`);
|
|
210
|
+
return false;
|
|
211
|
+
case "merge-manifest": throw new Error(`decideCollisionPolicy returned '${decision.policy}' for decorator origin (scenario: ${decision.scenario}). This is a bug.`);
|
|
121
212
|
}
|
|
122
213
|
}
|
|
123
214
|
/**
|
|
@@ -155,7 +246,8 @@ function buildManifestCollisionInputs(args) {
|
|
|
155
246
|
existingHasAnyPackage: !!existing.packageName,
|
|
156
247
|
hasManifestContent: !!(objectDef.fields || objectDef.methods || objectDef.schema || objectDef.decoratorConfig),
|
|
157
248
|
registrationKeyDiffersFromExistingKey: registrationKey !== existingKey,
|
|
158
|
-
existingHasNoPackage: !existing.packageName
|
|
249
|
+
existingHasNoPackage: !existing.packageName,
|
|
250
|
+
declaresDifferentTable: false
|
|
159
251
|
};
|
|
160
252
|
}
|
|
161
253
|
/**
|
|
@@ -353,6 +445,7 @@ function registerUntracked(ctor, config = {}) {
|
|
|
353
445
|
version: ""
|
|
354
446
|
};
|
|
355
447
|
existing.schema.tableName = nextTableName;
|
|
448
|
+
if (existing.constructor._isManifestStub === true && newSourceFile) existing.sourceFilePath = newSourceFile;
|
|
356
449
|
existing.constructor = ctor;
|
|
357
450
|
setSmrtTableName(ctor, nextTableName);
|
|
358
451
|
declareSensitiveTable(existing.config, nextTableName, existing.schema?.tableName);
|
|
@@ -373,7 +466,6 @@ function registerUntracked(ctor, config = {}) {
|
|
|
373
466
|
return nextKey;
|
|
374
467
|
}
|
|
375
468
|
const newSourceFile = getSourceFileFromStack();
|
|
376
|
-
const newPackageName = explicitPackageName || getPackageName(ctor, true) || void 0;
|
|
377
469
|
const newInBundledContext = isBundledOutputPath(newSourceFile);
|
|
378
470
|
const constructorKey = getConstructorIndex().get(ctor);
|
|
379
471
|
const constructorEntry = constructorKey ? getClasses().get(constructorKey) : void 0;
|
|
@@ -399,18 +491,24 @@ function registerUntracked(ctor, config = {}) {
|
|
|
399
491
|
upsertExistingEntry(constructorKey, constructorEntry);
|
|
400
492
|
return;
|
|
401
493
|
}
|
|
494
|
+
const stackPackageName = explicitPackageName ? void 0 : getPackageName(ctor, true) || void 0;
|
|
495
|
+
const stackPackageDeclaresClass = !!stackPackageName && packageDeclaresClass(stackPackageName, createQualifiedName(stackPackageName, name));
|
|
496
|
+
const sourceManifestPackage = explicitPackageName || stackPackageDeclaresClass ? void 0 : findManifestPackageForSource(name, newSourceFile, stackPackageName);
|
|
497
|
+
const newPackageName = explicitPackageName || sourceManifestPackage?.packageName || stackPackageName;
|
|
402
498
|
const ownQualifiedKey = newPackageName ? createQualifiedName(newPackageName, name) : void 0;
|
|
403
|
-
const ownPackageDeclaresClass = !!ownQualifiedKey &&
|
|
499
|
+
const ownPackageDeclaresClass = !!ownQualifiedKey && (!!explicitPackageName || stackPackageDeclaresClass || !!sourceManifestPackage);
|
|
404
500
|
const belongsToAnotherPackage = (existing) => ownPackageDeclaresClass && !!existing.packageName && existing.packageName !== newPackageName;
|
|
405
501
|
const exactExisting = getClasses().get(name);
|
|
406
502
|
if (exactExisting && !belongsToAnotherPackage(exactExisting)) {
|
|
503
|
+
const existing = exactExisting;
|
|
407
504
|
if (applyRegisterCollisionPolicy({
|
|
408
505
|
ctor,
|
|
409
506
|
name,
|
|
410
507
|
newPackageName,
|
|
411
508
|
newSourceFile,
|
|
412
509
|
newInBundledContext,
|
|
413
|
-
|
|
510
|
+
newDeclaredTableName: config.tableName,
|
|
511
|
+
existing,
|
|
414
512
|
existingKey: name,
|
|
415
513
|
matchKind: "exact-key",
|
|
416
514
|
upsertExistingEntry
|
|
@@ -429,17 +527,32 @@ function registerUntracked(ctor, config = {}) {
|
|
|
429
527
|
newPackageName,
|
|
430
528
|
newSourceFile,
|
|
431
529
|
newInBundledContext,
|
|
530
|
+
newDeclaredTableName: config.tableName,
|
|
432
531
|
existing,
|
|
433
532
|
existingKey,
|
|
434
533
|
matchKind: "case-insensitive",
|
|
435
534
|
upsertExistingEntry
|
|
436
535
|
})) return;
|
|
437
536
|
}
|
|
438
|
-
const packageNameFromStack =
|
|
537
|
+
const packageNameFromStack = newPackageName;
|
|
439
538
|
const sourceFilePath = getSourceFileFromStack();
|
|
539
|
+
const unknownPackageManifestEntry = () => {
|
|
540
|
+
const entry = discoverManifestSync(name);
|
|
541
|
+
if (!entry?.packageName || newInBundledContext || isSameSourcePath(newSourceFile, entry.filePath)) return entry;
|
|
542
|
+
};
|
|
543
|
+
const simpleNameManifestFallback = () => {
|
|
544
|
+
if (findClassesByName(name).some((candidate) => !!candidate.packageName && candidate.packageName !== newPackageName)) return;
|
|
545
|
+
const entry = discoverManifestSync(name);
|
|
546
|
+
if (!(!!entry?.packageName && entry.packageName !== newPackageName)) return entry;
|
|
547
|
+
if (isSameSourcePath(newSourceFile, entry?.filePath)) return entry;
|
|
548
|
+
if (ownPackageDeclaresClass) return void 0;
|
|
549
|
+
const entryTable = entry?.schema?.tableName || entry?.decoratorConfig?.tableName;
|
|
550
|
+
const declaresOtherTable = !!config.tableName && !!entryTable && config.tableName !== entryTable;
|
|
551
|
+
return !newInBundledContext || declaresOtherTable ? void 0 : entry;
|
|
552
|
+
};
|
|
440
553
|
let manifestEntry;
|
|
441
554
|
if (config._manifest) manifestEntry = lookupRegistrationManifest(config._manifest, name, explicitPackageName, config._manifestKey);
|
|
442
|
-
if (!manifestEntry) manifestEntry = ownQualifiedKey
|
|
555
|
+
if (!manifestEntry) manifestEntry = ownQualifiedKey ? discoverManifestSync(ownQualifiedKey) ?? sourceManifestPackage?.entry ?? simpleNameManifestFallback() : unknownPackageManifestEntry();
|
|
443
556
|
const runtimeTenantScopedDeclaration = getConstructorTenantScopedDeclarations().get(ctor);
|
|
444
557
|
if (manifestEntry && config.tenantScoped === void 0 && normalizeTenantScopedConfig(manifestEntry.decoratorConfig?.tenantScoped) === void 0 && runtimeTenantScopedDeclaration) throw new ConfigurationError(`Manifest for '${name}' omits or disables tenantScoped but its runtime constructor is decorated with @TenantScoped(). Regenerate the manifest so tenancy schema and runtime enforcement agree.`, "CONFIG_TENANT_MANIFEST_CONFLICT");
|
|
445
558
|
const fields = /* @__PURE__ */ new Map();
|
|
@@ -569,10 +682,7 @@ function registerUntracked(ctor, config = {}) {
|
|
|
569
682
|
if (childStrategy !== void 0 && parentStrategy !== childStrategy) throw ConfigurationError.incompatibleStrategy(name, childStrategy, parentName, parentStrategy);
|
|
570
683
|
}
|
|
571
684
|
}
|
|
572
|
-
const tableName =
|
|
573
|
-
...config,
|
|
574
|
-
...ownPackageDeclaresClass && newPackageName ? { packageName: newPackageName } : {}
|
|
575
|
-
});
|
|
685
|
+
const tableName = manifestEntry?.schema?.tableName || manifestEntry?.decoratorConfig?.tableName || config.tableName || tableNameFromClass(ctor);
|
|
576
686
|
setSmrtTableName(ctor, tableName);
|
|
577
687
|
let schema;
|
|
578
688
|
if (manifestEntry?.schema) {
|
|
@@ -1047,6 +1157,6 @@ function registerFromManifestUntracked(name, objectDef, manifestPackageName) {
|
|
|
1047
1157
|
}
|
|
1048
1158
|
}
|
|
1049
1159
|
//#endregion
|
|
1050
|
-
export { ensureTenantScopedField, invalidateInheritanceEntries, register, registerCollection, registerFromManifest };
|
|
1160
|
+
export { ensureTenantScopedField, invalidateInheritanceEntries, isBundledOutputPath, isSameSourcePath, register, registerCollection, registerFromManifest };
|
|
1051
1161
|
|
|
1052
1162
|
//# sourceMappingURL=class-registration.js.map
|