@happyvertical/smrt-core 0.40.69 → 0.40.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +29 -4
- package/README.md +20 -1
- package/agents/query-bounds.md +45 -0
- package/agents/schema-paths.md +328 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +2 -1
- package/dist/class.d.ts.map +1 -1
- package/dist/class.js +28 -4
- package/dist/class.js.map +1 -1
- package/dist/collection.d.ts +101 -2
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +224 -43
- package/dist/collection.js.map +1 -1
- package/dist/database.d.ts +8 -0
- package/dist/database.d.ts.map +1 -1
- package/dist/database.js +16 -8
- package/dist/database.js.map +1 -1
- package/dist/db-errors.d.ts +105 -0
- package/dist/db-errors.d.ts.map +1 -0
- package/dist/db-errors.js +382 -0
- package/dist/db-errors.js.map +1 -0
- package/dist/decorators/index.d.ts +17 -1
- package/dist/decorators/index.d.ts.map +1 -1
- package/dist/decorators/index.js +65 -7
- package/dist/decorators/index.js.map +1 -1
- package/dist/dispatch/bus.d.ts.map +1 -1
- package/dist/dispatch/bus.js +4 -3
- package/dist/dispatch/bus.js.map +1 -1
- package/dist/errors.d.ts +30 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +34 -2
- package/dist/errors.js.map +1 -1
- package/dist/generators/changes-route.d.ts.map +1 -1
- package/dist/generators/changes-route.js +6 -3
- package/dist/generators/changes-route.js.map +1 -1
- package/dist/generators/mcp-runtime-template.d.ts +8 -0
- package/dist/generators/mcp-runtime-template.d.ts.map +1 -1
- package/dist/generators/mcp-runtime-template.js +38 -4
- package/dist/generators/mcp-runtime-template.js.map +1 -1
- package/dist/generators/mcp.d.ts +16 -0
- package/dist/generators/mcp.d.ts.map +1 -1
- package/dist/generators/mcp.js +41 -3
- package/dist/generators/mcp.js.map +1 -1
- package/dist/generators/rest.d.ts +22 -0
- package/dist/generators/rest.d.ts.map +1 -1
- package/dist/generators/rest.js +34 -3
- package/dist/generators/rest.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -3
- 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/migrations/differ.d.ts +202 -8
- package/dist/migrations/differ.d.ts.map +1 -1
- package/dist/migrations/differ.js +604 -46
- package/dist/migrations/differ.js.map +1 -1
- package/dist/migrations/generator.d.ts +31 -4
- package/dist/migrations/generator.d.ts.map +1 -1
- package/dist/migrations/generator.js +49 -5
- package/dist/migrations/generator.js.map +1 -1
- package/dist/migrations/index.d.ts +3 -2
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +5 -3
- package/dist/migrations/orchestrate.js +35 -6
- package/dist/migrations/orchestrate.js.map +1 -1
- package/dist/migrations/sqlite-rebuild.d.ts +142 -0
- package/dist/migrations/sqlite-rebuild.d.ts.map +1 -0
- package/dist/migrations/sqlite-rebuild.js +514 -0
- package/dist/migrations/sqlite-rebuild.js.map +1 -0
- package/dist/migrations/tracker.d.ts +114 -1
- package/dist/migrations/tracker.d.ts.map +1 -1
- package/dist/migrations/tracker.js +331 -16
- package/dist/migrations/tracker.js.map +1 -1
- package/dist/migrations/types.d.ts +19 -4
- package/dist/migrations/types.d.ts.map +1 -1
- package/dist/migrations.js +5 -3
- package/dist/object.d.ts +45 -6
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +60 -13
- package/dist/object.js.map +1 -1
- package/dist/postgres-timeouts.d.ts +240 -0
- package/dist/postgres-timeouts.d.ts.map +1 -0
- package/dist/postgres-timeouts.js +204 -0
- package/dist/postgres-timeouts.js.map +1 -0
- package/dist/query-bounds.d.ts +97 -0
- package/dist/query-bounds.d.ts.map +1 -0
- package/dist/query-bounds.js +173 -0
- package/dist/query-bounds.js.map +1 -0
- package/dist/registry/types.d.ts +32 -1
- package/dist/registry/types.d.ts.map +1 -1
- package/dist/registry.js +1 -1
- package/dist/scanner/types.d.ts +5 -0
- package/dist/scanner/types.d.ts.map +1 -1
- package/dist/scanner/types.js.map +1 -1
- package/dist/schema/ddl/base-strategy.d.ts.map +1 -1
- package/dist/schema/ddl/base-strategy.js +2 -2
- package/dist/schema/ddl/base-strategy.js.map +1 -1
- package/dist/schema/generator.d.ts +70 -5
- package/dist/schema/generator.d.ts.map +1 -1
- package/dist/schema/generator.js +124 -6
- package/dist/schema/generator.js.map +1 -1
- package/dist/schema/index.d.ts +3 -0
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +4 -1
- package/dist/schema/live-parity.d.ts +90 -0
- package/dist/schema/live-parity.d.ts.map +1 -0
- package/dist/schema/live-parity.js +600 -0
- package/dist/schema/live-parity.js.map +1 -0
- package/dist/schema/manifest-schema.d.ts +121 -0
- package/dist/schema/manifest-schema.d.ts.map +1 -0
- package/dist/schema/manifest-schema.js +267 -0
- package/dist/schema/manifest-schema.js.map +1 -0
- package/dist/schema/schema-aggregator.d.ts +24 -10
- package/dist/schema/schema-aggregator.d.ts.map +1 -1
- package/dist/schema/schema-aggregator.js +35 -90
- package/dist/schema/schema-aggregator.js.map +1 -1
- package/dist/schema/system-table-shapes.d.ts +52 -0
- package/dist/schema/system-table-shapes.d.ts.map +1 -0
- package/dist/schema/system-table-shapes.js +174 -0
- package/dist/schema/system-table-shapes.js.map +1 -0
- package/dist/schema/types.d.ts +103 -4
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/schema/utils.d.ts +1 -0
- package/dist/schema/utils.d.ts.map +1 -1
- package/dist/schema/utils.js +3 -1
- package/dist/schema/utils.js.map +1 -1
- package/dist/schema.js +4 -1
- package/dist/smrt-knowledge.json +18 -6
- package/dist/sync/apply.d.ts.map +1 -1
- package/dist/sync/apply.js +9 -16
- package/dist/sync/apply.js.map +1 -1
- package/dist/testing/database.d.ts.map +1 -1
- package/dist/testing/database.js +1 -0
- package/dist/testing/database.js.map +1 -1
- package/dist/vite-plugin/sveltekit-generator.d.ts.map +1 -1
- package/dist/vite-plugin/sveltekit-generator.js +71 -5
- package/dist/vite-plugin/sveltekit-generator.js.map +1 -1
- package/dist/vite-plugin/web-collections.d.ts.map +1 -1
- package/dist/vite-plugin/web-collections.js +6 -4
- package/dist/vite-plugin/web-collections.js.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-collections.d.ts","sourceRoot":"","sources":["../../src/vite-plugin/web-collections.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH,OAAO,EAEL,KAAK,cAAc,EAEpB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,qBAAqB,CAAC;AAyB7B;;;;;;;;;GASG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,CAChC,eAAe,CAAC,MAAM,CAAC,EACvB,MAAM,GAAG,WAAW,GAAG,YAAY,CACpC,CAAC;AAEF,4EAA4E;AAC5E,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,YAAY,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,mEAAmE;IACnE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0EAA0E;IAC1E,EAAE,CAAC,EAAE,YAAY,CAAC;CACnB;AAED,iEAAiE;AACjE,MAAM,MAAM,mBAAmB,GAC3B,YAAY,GACZ,iBAAiB,GACjB,WAAW,GACX,YAAY,CAAC;AAEjB;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,+EAA+E;IAC/E,KAAK,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,IAAI,EAAE,mBAAmB,CAAC;IAC1B,oEAAoE;IACpE,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,2EAA2E;AAC3E,MAAM,WAAW,kBAAkB;IACjC,0DAA0D;IAC1D,UAAU,EAAE,MAAM,CAAC;IACnB,kEAAkE;IAClE,GAAG,EAAE,qBAAqB,CAAC;IAC3B,mDAAmD;IACnD,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAkID;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,mBAAmB,EAC7B,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,qBAAqB,GAC5B,qBAAqB,GAAG,SAAS,CAanC;
|
|
1
|
+
{"version":3,"file":"web-collections.d.ts","sourceRoot":"","sources":["../../src/vite-plugin/web-collections.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH,OAAO,EAEL,KAAK,cAAc,EAEpB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,qBAAqB,EACrB,mBAAmB,EACpB,MAAM,qBAAqB,CAAC;AAyB7B;;;;;;;;;GASG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,CAChC,eAAe,CAAC,MAAM,CAAC,EACvB,MAAM,GAAG,WAAW,GAAG,YAAY,CACpC,CAAC;AAEF,4EAA4E;AAC5E,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,YAAY,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,mEAAmE;IACnE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0EAA0E;IAC1E,EAAE,CAAC,EAAE,YAAY,CAAC;CACnB;AAED,iEAAiE;AACjE,MAAM,MAAM,mBAAmB,GAC3B,YAAY,GACZ,iBAAiB,GACjB,WAAW,GACX,YAAY,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Q,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC3C,aAAa,EAAE,eAAe,EAAE,CAAC;CAClC,CAWA;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,qBAAqB,GACzB,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAyBpC;AAwCD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,qBAAqB,EAC1B,QAAQ,EAAE,mBAAmB,GAC5B,eAAe,EAAE,CAsCnB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,kBAAkB,GACxB,cAAc,EAAE,CAiClB;AAyBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,mBAAmB,GAAG,MAAM,CAa5E"}
|
|
@@ -119,10 +119,12 @@ function findManifestObjectByName(manifest, name, owner) {
|
|
|
119
119
|
* Normalize a relationship field's `related` value to a resolvable class name.
|
|
120
120
|
*
|
|
121
121
|
* Thunk forward-ref decorators — `@foreignKey(() => Scene)`, used heavily in
|
|
122
|
-
* video/voice for models that reference a class declared later —
|
|
123
|
-
* the RAW arrow-function source string `"() => Scene"` in the
|
|
124
|
-
* neither `className` nor `qualifiedName` matches.
|
|
125
|
-
*
|
|
122
|
+
* video/voice for models that reference a class declared later — used to
|
|
123
|
+
* serialize as the RAW arrow-function source string `"() => Scene"` in the
|
|
124
|
+
* manifest, which neither `className` nor `qualifiedName` matches. The scanner
|
|
125
|
+
* now unwraps the thunk itself (#2379), so this only has to cover manifests
|
|
126
|
+
* generated before that fix. Extract the target class name from the thunk so
|
|
127
|
+
* the edge resolves. Plain (`"Scene"`) and qualified
|
|
126
128
|
* (`"@happyvertical/smrt-assets:Asset"`) forms contain no `=>` and pass through
|
|
127
129
|
* untouched — the qualified `:` separator is preserved.
|
|
128
130
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-collections.js","names":[],"sources":["../../src/vite-plugin/web-collections.ts"],"sourcesContent":["/**\n * Manifest → web collection selection (single source of truth).\n *\n * The browser client data runtime (`@happyvertical/smrt-web`, #1761) consumes\n * one typed collection definition per API-exposed REST collection. Three\n * emission sites need the SAME selection and field rules, or the emitted\n * runtime values and their declared types drift apart:\n *\n * - the `\\0smrt:web` runtime virtual module (JSON literal — {@link generateWebModule})\n * - the `@happyvertical/smrt-virt-web` ambient d.ts (vite-plugin)\n * - the physical `@smrt/web` d.ts (prebuild, for `tsc`-only consumers)\n *\n * All three import {@link selectWebCollectionEntries} from here so the value\n * emission and the type emission can never disagree. A fourth, hand-written\n * mirror of the field/collection definition types lives in\n * `@happyvertical/smrt-web` (`packages/smrt-web/src/index.ts`) — that package\n * is deliberately smrt-dependency-free, so its copy cannot import these types;\n * keep it textually in sync when the shape here changes. The per-collection SHAPE\n * (name/objectRef/className/endpoint/idField/actions/fields/relationships) is built by the\n * ONE {@link buildWebCollectionDefinition}, shared by the runtime emission AND\n * the #1764 {@link computeWebManifestHash} shape digest — so the emitted shape\n * and the hashed shape can never drift (a drift would let the hash under-cover a\n * change → stale client caches).\n */\n\nimport { createHash } from 'node:crypto';\nimport { resolveCustomActionMetadata } from '../generators/custom-action.js';\nimport {\n buildToolDescriptors,\n type ToolDescriptor,\n type ToolFieldMeta,\n} from '../generators/tool-schema.js';\nimport type {\n FieldDefinition,\n FieldUIHints,\n SmartObjectDefinition,\n SmartObjectManifest,\n} from '../scanner/types.js';\nimport { resolveApiActionSet } from './sveltekit-generator.js';\n\n/**\n * Field types that are relationship pseudo-columns rather than persisted\n * public-DTO columns — they never appear on the wire as scalar values.\n */\nconst RELATIONSHIP_FIELD_TYPES: ReadonlySet<FieldDefinition['type']> = new Set([\n 'oneToMany',\n 'manyToMany',\n]);\n\n/**\n * Field types that describe a relationship to another model. A superset of\n * {@link RELATIONSHIP_FIELD_TYPES}: `foreignKey`/`crossPackageRef` are persisted\n * scalar id columns (they DO appear on the wire), while `oneToMany`/`manyToMany`\n * are pseudo-columns — but all four carry a `related` edge to a sibling model.\n */\nconst RELATIONSHIP_EDGE_TYPES: ReadonlySet<FieldDefinition['type']> = new Set([\n 'foreignKey',\n 'crossPackageRef',\n 'oneToMany',\n 'manyToMany',\n]);\n\n/**\n * The field types that actually reach an emitted web collection definition:\n * everything {@link buildWebFieldDefinitions} does not skip. Relationship\n * pseudo-columns (`oneToMany`/`manyToMany`) and STI `meta` internals never\n * appear on the wire, so they are excluded from the union — keeping the\n * declared type honest about what a client can observe. Co-managed with the\n * `SmrtWebFieldType` unions in the ambient `@happyvertical/smrt-virt-web`\n * d.ts, the physical `@smrt/web` d.ts, and the hand-written\n * `@happyvertical/smrt-web` mirror.\n */\nexport type WebFieldType = Exclude<\n FieldDefinition['type'],\n 'meta' | 'oneToMany' | 'manyToMany'\n>;\n\n/** Informational per-column metadata carried by a collection definition. */\nexport interface WebFieldDefinition {\n type: WebFieldType;\n required?: boolean;\n /** Whether the public field contract explicitly permits `null`. */\n nullable?: boolean;\n default?: unknown;\n /**\n * The developer-authored `@field({ description })` (#2046) — the same text\n * that feeds OpenAPI and MCP schemas, now available to browser UIs as the\n * seed for end-user field help. Sensitive/transient fields are excluded\n * from emission entirely, so their descriptions never ship to the client.\n */\n description?: string;\n /** Static `@field({ ui })` hints (#2046) — the field-policy rail seed. */\n ui?: FieldUIHints;\n}\n\n/** The relationship kinds a web collection edge can describe. */\nexport type WebRelationshipKind =\n | 'foreignKey'\n | 'crossPackageRef'\n | 'oneToMany'\n | 'manyToMany';\n\n/**\n * One manifest-derived relationship edge from a collection to a sibling REST\n * collection. Consumed by the browser client-data runtime to invalidate\n * dependent collection caches when this collection is mutated (#1761) — the\n * cache-invalidation graph is derived entirely from these edges, never\n * hand-wired. SMRT-owned data: no client-engine type appears here.\n */\nexport interface WebRelationship {\n /** The declaring field carrying the relationship (e.g. `groupId`, `items`). */\n field: string;\n /** The relationship kind, mirroring the manifest field type. */\n kind: WebRelationshipKind;\n /** REST collection name the edge resolves to (e.g. `ad_groups`). */\n relatedCollection: string;\n}\n\n/** One selected REST collection and the model that owns its definition. */\nexport interface WebCollectionEntry {\n /** REST collection name (pluralized), e.g. `products`. */\n collection: string;\n /** The manifest object that owns this collection's definition. */\n obj: SmartObjectDefinition;\n /** Sorted set of exposed CRUD + custom actions. */\n actions: string[];\n}\n\nfunction compareText(left: string, right: string): number {\n if (left < right) return -1;\n if (left > right) return 1;\n return 0;\n}\n\nfunction manifestObjectPackage(\n manifestKey: string | undefined,\n obj: SmartObjectDefinition,\n): string | undefined {\n if (obj.packageName) return obj.packageName;\n const qualifiedName = obj.qualifiedName || manifestKey;\n const separator = qualifiedName?.lastIndexOf(':') ?? -1;\n return separator > 0 ? qualifiedName?.slice(0, separator) : undefined;\n}\n\ninterface ManifestObjectIndex {\n byExactName: Map<string, SmartObjectDefinition>;\n byPackageAndClass: Map<string, SmartObjectDefinition>;\n bySimpleName: Map<string, SmartObjectDefinition>;\n packageByObject: WeakMap<SmartObjectDefinition, string>;\n objectRefByObject: WeakMap<SmartObjectDefinition, string>;\n}\n\nconst manifestObjectIndexes = new WeakMap<\n SmartObjectManifest['objects'],\n ManifestObjectIndex\n>();\n\nfunction packageAndClassKey(packageName: string, className: string): string {\n return `${packageName}\\0${className}`;\n}\n\nfunction getManifestObjectIndex(\n manifest: SmartObjectManifest,\n): ManifestObjectIndex {\n const cached = manifestObjectIndexes.get(manifest.objects);\n if (cached) return cached;\n\n const entries = Object.entries(manifest.objects).sort(\n ([leftKey, left], [rightKey, right]) =>\n compareText(\n left.qualifiedName || leftKey,\n right.qualifiedName || rightKey,\n ) || compareText(leftKey, rightKey),\n );\n const index: ManifestObjectIndex = {\n byExactName: new Map(),\n byPackageAndClass: new Map(),\n bySimpleName: new Map(),\n packageByObject: new WeakMap(),\n objectRefByObject: new WeakMap(),\n };\n\n for (const [manifestKey, candidate] of entries) {\n if (!index.byExactName.has(manifestKey)) {\n index.byExactName.set(manifestKey, candidate);\n }\n if (\n candidate.qualifiedName &&\n !index.byExactName.has(candidate.qualifiedName)\n ) {\n index.byExactName.set(candidate.qualifiedName, candidate);\n }\n if (!index.bySimpleName.has(candidate.className)) {\n index.bySimpleName.set(candidate.className, candidate);\n }\n\n const packageName = manifestObjectPackage(manifestKey, candidate);\n if (packageName) {\n if (!index.packageByObject.has(candidate)) {\n index.packageByObject.set(candidate, packageName);\n }\n const packageKey = packageAndClassKey(packageName, candidate.className);\n if (!index.byPackageAndClass.has(packageKey)) {\n index.byPackageAndClass.set(packageKey, candidate);\n }\n }\n\n // New manifests carry `qualifiedName` on each object. Legacy aggregated\n // manifests can omit it from the object body while retaining a qualified\n // manifest key, so retain that equally canonical identity for browser\n // definitions rather than falling back to an ambiguous simple class name.\n const objectRef = candidate.qualifiedName?.includes(':')\n ? candidate.qualifiedName\n : manifestKey.includes(':')\n ? manifestKey\n : packageName\n ? `${packageName}:${candidate.className}`\n : undefined;\n if (objectRef && !index.objectRefByObject.has(candidate)) {\n index.objectRefByObject.set(candidate, objectRef);\n }\n }\n\n manifestObjectIndexes.set(manifest.objects, index);\n return index;\n}\n\nfunction indexedManifestObjectPackage(\n manifest: SmartObjectManifest,\n obj: SmartObjectDefinition,\n): string | undefined {\n const index = getManifestObjectIndex(manifest);\n return (\n index.packageByObject.get(obj) || manifestObjectPackage(undefined, obj)\n );\n}\n\n/**\n * Return the canonical qualified model identity carried by a web collection.\n * Field-policy APIs require this `@package/name:ClassName` reference; a simple\n * class name is ambiguous in aggregated manifests and must never reach a\n * browser definition.\n */\nfunction webCollectionObjectRef(\n manifest: SmartObjectManifest,\n obj: SmartObjectDefinition,\n): string {\n const objectRef = getManifestObjectIndex(manifest).objectRefByObject.get(obj);\n if (objectRef) return objectRef;\n\n throw new Error(\n `[smrt] Cannot emit web collection definition for ${obj.className}: ` +\n 'a qualifiedName, qualified manifest key, or packageName is required',\n );\n}\n\n/**\n * Resolve a manifest object deterministically across aggregated packages.\n *\n * Qualified references win exactly. Simple references prefer the referencing\n * object's package, then fall back to a stable qualified/key identity. This is\n * important because aggregated manifests can contain duplicate class names and\n * their object insertion order reflects package discovery order.\n */\nexport function findManifestObjectByName(\n manifest: SmartObjectManifest,\n name: string,\n owner?: SmartObjectDefinition,\n): SmartObjectDefinition | undefined {\n const index = getManifestObjectIndex(manifest);\n const exact = name.includes(':') ? index.byExactName.get(name) : undefined;\n if (exact) return exact;\n\n const ownerPackage = owner\n ? indexedManifestObjectPackage(manifest, owner)\n : undefined;\n const packageLocal = ownerPackage\n ? index.byPackageAndClass.get(packageAndClassKey(ownerPackage, name))\n : undefined;\n\n return packageLocal || index.bySimpleName.get(name);\n}\n\n/**\n * Normalize a relationship field's `related` value to a resolvable class name.\n *\n * Thunk forward-ref decorators — `@foreignKey(() => Scene)`, used heavily in\n * video/voice for models that reference a class declared later — serialize as\n * the RAW arrow-function source string `\"() => Scene\"` in the manifest, which\n * neither `className` nor `qualifiedName` matches. Extract the target class\n * name from the thunk so the edge resolves. Plain (`\"Scene\"`) and qualified\n * (`\"@happyvertical/smrt-assets:Asset\"`) forms contain no `=>` and pass through\n * untouched — the qualified `:` separator is preserved.\n *\n * Kept local to the relationship-edge path on purpose: extends-chain resolution\n * never sees a thunk, so `findManifestObjectByName` and the scanner stay\n * unchanged.\n */\nfunction normalizeRelatedName(related: string): string {\n const thunk = related.match(/=>\\s*([A-Za-z_$][\\w$]*)/);\n return thunk ? thunk[1] : related.trim();\n}\n\n/**\n * True when `obj` is (transitively) a SmrtCollection subclass. Collection\n * classes describe access, not row shapes, so they never become web\n * collection definitions.\n *\n * NOTE: deliberately stronger than sveltekit-generator's private\n * `isCollectionClass`, which only inspects the direct base / a type argument.\n * A deeper subclass (`SpecialWidgetCollection extends WidgetCollection`)\n * carries no type argument of its own; without walking the extends chain it\n * would be mistaken for a model and claim its base model's REST collection.\n */\nexport function isCollectionManifestClass(\n manifest: SmartObjectManifest,\n obj: SmartObjectDefinition,\n seen: Set<string> = new Set(),\n): boolean {\n // Truthy check (not `!== undefined`) mirrors the scanner's own\n // manifest-generator: a scanner that emits `extendsTypeArg: null` for a\n // non-generic base must not be misread as a collection.\n if (obj.extends === 'SmrtCollection' || obj.extendsTypeArg) {\n return true;\n }\n const parentName = obj.extendsQualified || obj.extends;\n if (!parentName || seen.has(parentName)) return false;\n seen.add(parentName);\n const parent = findManifestObjectByName(manifest, parentName, obj);\n return parent ? isCollectionManifestClass(manifest, parent, seen) : false;\n}\n\n/**\n * Resolve the row model carried by a collection class.\n *\n * An explicit generic on any ancestor is authoritative. Conventional\n * `FooCollection` → `Foo` lookup is only a fallback after the full ancestry\n * has been checked, so an unrelated `SpecialFoo` cannot override an inherited\n * `FooCollection<Foo>` contract.\n */\nfunction collectionAncestry(\n manifest: SmartObjectManifest,\n obj: SmartObjectDefinition,\n): SmartObjectDefinition[] {\n const ancestry: SmartObjectDefinition[] = [];\n const seen = new Set<string>();\n let candidate: SmartObjectDefinition | undefined = obj;\n\n while (candidate) {\n ancestry.push(candidate);\n const parentName = candidate.extendsQualified || candidate.extends;\n if (!parentName || seen.has(parentName)) break;\n seen.add(parentName);\n candidate = findManifestObjectByName(manifest, parentName, candidate);\n }\n return ancestry;\n}\n\n/**\n * Resolve the authoritative collection item type name even when a partial\n * manifest omits the item definition itself.\n */\ninterface CollectionItemReference {\n name: string;\n owner: SmartObjectDefinition;\n object?: SmartObjectDefinition;\n}\n\nfunction resolveCollectionItemCandidate(\n manifest: SmartObjectManifest,\n name: string,\n owner: SmartObjectDefinition,\n): CollectionItemReference {\n const object = findManifestObjectByName(manifest, name, owner);\n const ownerPackage = indexedManifestObjectPackage(manifest, owner);\n\n if (!name.includes(':') && ownerPackage) {\n const objectPackage = object\n ? indexedManifestObjectPackage(manifest, object)\n : undefined;\n if (objectPackage !== ownerPackage) {\n return {\n name: `${ownerPackage}:${name}`,\n owner,\n };\n }\n }\n\n return { name, owner, object };\n}\n\nfunction resolveCollectionItemReference(\n manifest: SmartObjectManifest,\n obj: SmartObjectDefinition,\n): CollectionItemReference | undefined {\n const ancestry = collectionAncestry(manifest, obj);\n for (const collectionClass of ancestry) {\n if (collectionClass.extendsTypeArg) {\n return resolveCollectionItemCandidate(\n manifest,\n collectionClass.extendsTypeArg,\n collectionClass,\n );\n }\n }\n\n let fallback: CollectionItemReference | undefined;\n for (const collectionClass of ancestry) {\n if (!collectionClass.className.endsWith('Collection')) continue;\n const conventionalName = collectionClass.className.slice(\n 0,\n -'Collection'.length,\n );\n const candidate = resolveCollectionItemCandidate(\n manifest,\n conventionalName,\n collectionClass,\n );\n if (candidate.object) return candidate;\n fallback ??= candidate;\n }\n\n return fallback;\n}\n\nexport function resolveCollectionItemTypeName(\n manifest: SmartObjectManifest,\n obj: SmartObjectDefinition,\n): string | undefined {\n return resolveCollectionItemReference(manifest, obj)?.name;\n}\n\nexport function resolveCollectionItemObject(\n manifest: SmartObjectManifest,\n obj: SmartObjectDefinition,\n): SmartObjectDefinition | undefined {\n return resolveCollectionItemReference(manifest, obj)?.object;\n}\n\n/**\n * True when some ancestor model maps to the SAME REST collection (a shared STI\n * table). The STI base model owns the shared table's single definition.\n */\nfunction isStiChildModel(\n manifest: SmartObjectManifest,\n obj: SmartObjectDefinition,\n): boolean {\n const seen = new Set<string>();\n let child = obj;\n let parentName = child.extendsQualified || child.extends;\n while (parentName && !seen.has(parentName)) {\n seen.add(parentName);\n const parent = findManifestObjectByName(manifest, parentName, child);\n if (!parent) return false;\n if (parent.collection === obj.collection) return true;\n child = parent;\n parentName = parent.extendsQualified || parent.extends;\n }\n return false;\n}\n\n/**\n * Select one entry per REST collection whose exposed action set satisfies\n * `qualifies` — STI children folding into their base model, collection classes\n * excluded. Uses the canonical {@link resolveApiActionSet} so the exposed-action\n * set matches exactly what the REST/SvelteKit generators actually emit. Shared\n * by {@link selectWebCollectionEntries} (list-qualified — materializable\n * collections) and {@link selectWebEtagSaltEntries} (get-OR-list — every model\n * with a read route the ETag salt must cover).\n */\nfunction selectEntriesQualifiedBy(\n manifest: SmartObjectManifest,\n qualifies: (actions: ReadonlySet<string>) => boolean,\n): WebCollectionEntry[] {\n const byCollection = new Map<\n string,\n WebCollectionEntry & { isStiChild: boolean }\n >();\n\n for (const obj of Object.values(manifest.objects)) {\n if (isCollectionManifestClass(manifest, obj)) continue;\n\n const exposedActions = resolveApiActionSet(obj);\n if (!qualifies(exposedActions)) continue;\n\n const isStiChild = isStiChildModel(manifest, obj);\n const existing = byCollection.get(obj.collection);\n // One definition per REST collection. The STI BASE model owns it: a child\n // only wins while no base has been recorded yet, so the result is\n // independent of declaration / scan order.\n if (existing && !(existing.isStiChild && !isStiChild)) continue;\n\n byCollection.set(obj.collection, {\n collection: obj.collection,\n obj,\n actions: [...exposedActions].sort(),\n isStiChild,\n });\n }\n\n return [...byCollection.values()].map(({ collection, obj, actions }) => ({\n collection,\n obj,\n actions,\n }));\n}\n\n/**\n * Select the manifest entries that become web collection definitions: one per\n * REST collection, STI children folding into their base model, collection\n * classes excluded, and only models that expose `list` (a read surface is\n * required to MATERIALIZE a client collection — that is what persists).\n */\nexport function selectWebCollectionEntries(\n manifest: SmartObjectManifest,\n): WebCollectionEntry[] {\n return selectEntriesQualifiedBy(manifest, (actions) => actions.has('list'));\n}\n\n/**\n * Select the entries the ETag salt (#1764) must cover: every api-exposed model\n * with a GENERATED READ ROUTE — `list` OR `get`. Broader than\n * {@link selectWebCollectionEntries} on purpose: a get-only model\n * (`api: { include: ['get'] }`) has no materializable client collection (so it\n * never persists), but its generated GET route IS salted, so a shape-only change\n * to it must still change the salt — otherwise a client holding the old concrete\n * ETag would get a zero-query 304 after a shape-only deploy (the #1765 gap the\n * salt closes). Not exported: only {@link computeWebManifestHash} consumes it.\n */\nfunction selectWebEtagSaltEntries(\n manifest: SmartObjectManifest,\n): WebCollectionEntry[] {\n return selectEntriesQualifiedBy(\n manifest,\n (actions) => actions.has('list') || actions.has('get'),\n );\n}\n\n/**\n * Build the per-collection web-collection definition literal — the SINGLE\n * source of truth for the shape emitted by {@link generateWebModule} and hashed\n * by {@link computeWebManifestHash}. Building it in ONE place is a\n * cache-coherency requirement: if the emitted shape and the hashed shape were\n * built independently, adding a field to one and not the other would let the\n * hash silently UNDER-cover a shape change, so persisted caches would not drop\n * and stale rows would hydrate into new code.\n */\nexport function buildWebCollectionDefinition(\n entry: WebCollectionEntry,\n manifest: SmartObjectManifest,\n): {\n name: string;\n objectRef: string;\n className: string;\n endpoint: string;\n idField: string;\n actions: string[];\n fields: Record<string, WebFieldDefinition>;\n relationships: WebRelationship[];\n} {\n return {\n name: entry.collection,\n objectRef: webCollectionObjectRef(manifest, entry.obj),\n className: entry.obj.className,\n endpoint: `/${entry.collection}`,\n idField: 'id',\n actions: entry.actions,\n fields: buildWebFieldDefinitions(entry.obj),\n relationships: buildWebRelationships(entry.obj, manifest),\n };\n}\n\n/**\n * Build the informational per-field metadata for a web collection definition:\n * the persisted public-DTO columns only. Relationship pseudo-fields, STI meta\n * internals, transient (unpersisted) and sensitive (wire-stripped) fields are\n * excluded — they are not columns a client reads back over the REST surface.\n */\nexport function buildWebFieldDefinitions(\n obj: SmartObjectDefinition,\n): Record<string, WebFieldDefinition> {\n const fields: Record<string, WebFieldDefinition> = {};\n for (const [fieldName, field] of Object.entries(obj.fields ?? {})) {\n if (RELATIONSHIP_FIELD_TYPES.has(field.type)) continue;\n if (field.type === 'meta') continue;\n if (field.transient) continue;\n if (field.sensitive) continue;\n const ui = sanitizeFieldUIHints(field._meta?.ui);\n // Scanner manifests expose `description` top-level; runtime-registry\n // manifests (computeRuntimeWebManifestHash → registeredFieldsToManifest)\n // keep it under `_meta` only. Read both so the build-time and runtime\n // shape digests agree — otherwise every described field would latch a\n // false `updateAvailable.contract` signal on APIGenerator SSE connects.\n const description = readFieldDescription(field);\n fields[fieldName] = {\n // Safe: the three skips above are exactly the types WebFieldType excludes.\n type: field.type as WebFieldType,\n ...(field.required !== undefined ? { required: field.required } : {}),\n ...(field._meta?.nullable === true ? { nullable: true } : {}),\n ...(field.default !== undefined ? { default: field.default } : {}),\n ...(description !== undefined ? { description } : {}),\n ...(ui ? { ui } : {}),\n };\n }\n return fields;\n}\n\n/** Top-level `description` with `_meta.description` fallback (see call site). */\nfunction readFieldDescription(field: FieldDefinition): string | undefined {\n if (typeof field.description === 'string' && field.description !== '') {\n return field.description;\n }\n const metaDescription = field._meta?.description;\n if (typeof metaDescription === 'string' && metaDescription !== '') {\n return metaDescription;\n }\n return undefined;\n}\n\n/**\n * Narrow a manifest `_meta.ui` bag to the known {@link FieldUIHints} keys with\n * per-key type guards. `_meta` is an open bag, so authored junk (wrong-typed\n * values, arbitrary extra keys) must not reach the emitted client module — the\n * emitted value also feeds the #1764 shape digest, so unknown unstable keys\n * would churn the hash. Returns undefined when nothing valid remains, so\n * hint-less fields emit no `ui` key at all (existing shapes stay byte-stable).\n */\nfunction sanitizeFieldUIHints(value: unknown): FieldUIHints | undefined {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) {\n return undefined;\n }\n const raw = value as Record<string, unknown>;\n const ui: FieldUIHints = {\n ...(typeof raw.basic === 'boolean' ? { basic: raw.basic } : {}),\n ...(typeof raw.group === 'string' && raw.group !== ''\n ? { group: raw.group }\n : {}),\n ...(typeof raw.order === 'number' && Number.isFinite(raw.order)\n ? { order: raw.order }\n : {}),\n ...(typeof raw.locked === 'boolean' ? { locked: raw.locked } : {}),\n };\n return Object.keys(ui).length > 0 ? ui : undefined;\n}\n\n/**\n * Build the manifest-derived relationship edges for a web collection\n * definition (#1761): one entry per relationship field (`foreignKey`,\n * `crossPackageRef`, `oneToMany`, `manyToMany`) whose `related` target resolves\n * to another API-exposed REST collection.\n *\n * These edges drive relationship-derived cache invalidation in the browser\n * client-data runtime: mutating this collection invalidates the caches of the\n * collections named here. The invalidation graph is thus derived entirely from\n * the manifest — no hand-wired cache keys.\n *\n * An edge is SKIPPED (not emitted) when:\n * - `related` is missing, or\n * - `related` cannot be resolved to a manifest object (e.g. a cross-package\n * target not present in this package's manifest), or\n * - the resolved target is not itself an API-exposed web collection (no read\n * surface to invalidate — it never appears in {@link selectWebCollectionEntries}).\n *\n * Self-referential edges (a collection related to itself) are kept: the runtime\n * always invalidates the mutated collection anyway, so a self edge is harmless\n * and keeping it avoids a special case.\n */\nexport function buildWebRelationships(\n obj: SmartObjectDefinition,\n manifest: SmartObjectManifest,\n): WebRelationship[] {\n // The set of REST collections that are actually materialized as web\n // collections. An edge to a model outside this set has no client cache to\n // invalidate, so it is dropped.\n const exposedCollections = new Set(\n selectWebCollectionEntries(manifest).map((entry) => entry.collection),\n );\n\n const relationships: WebRelationship[] = [];\n const seen = new Set<string>();\n for (const [fieldName, field] of Object.entries(obj.fields ?? {})) {\n if (!RELATIONSHIP_EDGE_TYPES.has(field.type)) continue;\n if (!field.related) continue;\n\n // Normalize first: `@foreignKey(() => Scene)` thunks serialize as the raw\n // \"() => Scene\" source, which findManifestObjectByName cannot match on its\n // own.\n const target = findManifestObjectByName(\n manifest,\n normalizeRelatedName(field.related),\n obj,\n );\n if (!target) continue;\n if (!exposedCollections.has(target.collection)) continue;\n\n // De-dupe on (field, relatedCollection): a model never declares the same\n // field twice, but guard anyway so the emitted edge list is stable.\n const dedupeKey = `${fieldName}:${target.collection}`;\n if (seen.has(dedupeKey)) continue;\n seen.add(dedupeKey);\n\n relationships.push({\n field: fieldName,\n kind: field.type as WebRelationshipKind,\n relatedCollection: target.collection,\n });\n }\n return relationships;\n}\n\n/**\n * Build the WebMCP / MCP tool descriptors for a web collection (#1812): one\n * descriptor per exposed action, over the SAME public-DTO fields the definition\n * already exposes (`buildWebFieldDefinitions`). The tool ids match the Node MCP\n * surface (`<class>_<action>`), so a page's WebMCP tools and its MCP-server\n * tools share one vocabulary.\n *\n * Deliberately NOT part of {@link buildWebCollectionDefinition}: descriptors are\n * layered onto the emitted value by {@link generateWebModule} instead, so the\n * #1764 {@link computeWebManifestHash} shape digest keeps hashing ONLY the row\n * shape. That remains safe because descriptor-only inputs (including `idType`)\n * do not alter persisted public rows or read responses, which are the cache\n * contracts this digest protects.\n */\nexport function buildWebToolDescriptors(\n entry: WebCollectionEntry,\n): ToolDescriptor[] {\n const webFields = buildWebFieldDefinitions(entry.obj);\n const fields: ToolFieldMeta[] = Object.entries(webFields).map(\n ([name, def]) => ({\n name,\n type: def.type,\n ...(def.required !== undefined ? { required: def.required } : {}),\n ...(def.nullable === true ? { nullable: true } : {}),\n ...(def.default !== undefined ? { default: def.default } : {}),\n // #2046: the authored field description flows into the generated JSON\n // Schema (`fieldTypeToJsonSchema` prefers it over the type-derived\n // fallback), so browser-side WebMCP tools document their arguments.\n ...(def.description !== undefined\n ? { description: def.description }\n : {}),\n }),\n );\n return buildToolDescriptors({\n className: entry.obj.className,\n fields,\n actions: entry.actions,\n customActions: Object.fromEntries(\n entry.actions.map((action) => [\n action,\n resolveCustomActionMetadata({\n actionName: action,\n method: entry.obj.methods?.[action],\n apiConfig: entry.obj.decoratorConfig?.api,\n }),\n ]),\n ),\n idType: entry.obj.decoratorConfig.idType,\n });\n}\n\n/**\n * Recursively sort object keys so structurally-equal values serialize to the\n * SAME JSON regardless of insertion order. Arrays keep their order (order is\n * semantic for `actions`/`relationships`); objects are rebuilt with keys sorted.\n * Required for {@link computeWebManifestHash} to be replica-stable: two builds\n * that produce the same schema but visit the manifest in a different order (map\n * insertion, scan order) must still hash identically, which a plain\n * `JSON.stringify` of insertion-ordered objects would NOT guarantee.\n */\nfunction canonicalize(value: unknown): unknown {\n if (Array.isArray(value)) {\n return value.map((entry) => canonicalize(entry));\n }\n if (value && typeof value === 'object') {\n const sorted: Record<string, unknown> = {};\n for (const key of Object.keys(value as Record<string, unknown>).sort()) {\n sorted[key] = canonicalize((value as Record<string, unknown>)[key]);\n }\n return sorted;\n }\n return value;\n}\n\n/**\n * A deterministic, replica-stable digest of the web-collection SHAPE (#1764).\n *\n * The hash covers exactly the thing whose change means either old persisted\n * client rows may mis-hydrate OR a stale read ETag would still 304: the same\n * per-collection definition shape {@link generateWebModule} emits — name,\n * className, endpoint, idField, actions, fields, relationships — built via the\n * SHARED {@link buildWebCollectionDefinition} so the hash can never disagree\n * with what is actually shipped. The shape is CANONICALIZED (keys recursively\n * sorted; see {@link canonicalize}) before hashing, so the same schema always\n * yields the same digest across builds and replicas regardless of manifest\n * iteration order.\n *\n * SCOPE — get-OR-list (broader than materializable collections). Covered by\n * {@link selectWebEtagSaltEntries}, so it includes GET-ONLY models too: those do\n * not persist (no materializable collection), but their generated GET route IS\n * salted with this hash, so a shape-only change to a get-only model must change\n * it or a client holding the old concrete ETag gets a zero-query 304 after a\n * shape-only deploy (the #1765 gap the salt closes). The two consumers both use\n * this one value, so it stays identical between them:\n * - `@happyvertical/smrt-web` persistence (#1764) folds it into the durable\n * namespace, so a contract-changing deploy lands on a fresh namespace and old\n * rows are never found (dropped, not mis-hydrated). Including get-only models\n * here is harmless over-invalidation — only list-materializable collections\n * ever hold a persisted snapshot.\n * - the generated read ETag (#1765 salt, #1764) folds it in so a shape-only\n * deploy (no table write) busts every read validator, get-only routes too.\n *\n * Truncated to the first 16 base64url chars: 96 bits is far more than enough to\n * make an accidental shape collision negligible, and a short constant keeps the\n * emitted module and every persistence key compact.\n */\nexport function computeWebManifestHash(manifest: SmartObjectManifest): string {\n const definitions: Record<string, unknown> = {};\n for (const entry of selectWebEtagSaltEntries(manifest)) {\n definitions[entry.collection] = buildWebCollectionDefinition(\n entry,\n manifest,\n );\n }\n const canonicalJson = JSON.stringify(canonicalize(definitions));\n return createHash('sha256')\n .update(canonicalJson)\n .digest('base64url')\n .slice(0, 16);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,IAAM,2CAAiE,IAAI,IAAI,CAC7E,aACA,YACF,CAAC;;;;;;;AAQD,IAAM,0CAAgE,IAAI,IAAI;CAC5E;CAC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AAa,KAAK,CAAC;CAEjD,IAAI,SAAS,OAAO,UAAU,UAAU;EACtC,MAAM,SAAkC,CAAC;EACzC,KAAK,MAAM,OAAO,OAAO,KAAK,KAAgC,CAAC,CAAC,KAAK,GACnE,OAAO,OAAO,aAAc,MAAkC,IAAI;EAEpE,OAAO;CACT;CACA,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,SAAgB,uBAAuB,UAAuC;CAC5E,MAAM,cAAuC,CAAC;CAC9C,KAAK,MAAM,SAAS,yBAAyB,QAAQ,GACnD,YAAY,MAAM,cAAc,6BAC9B,OACA,QACF;CAEF,MAAM,gBAAgB,KAAK,UAAU,aAAa,WAAW,CAAC;CAC9D,OAAO,WAAW,QAAQ,CAAC,CACxB,OAAO,aAAa,CAAC,CACrB,OAAO,WAAW,CAAC,CACnB,MAAM,GAAG,EAAE;AAChB"}
|
|
1
|
+
{"version":3,"file":"web-collections.js","names":[],"sources":["../../src/vite-plugin/web-collections.ts"],"sourcesContent":["/**\n * Manifest → web collection selection (single source of truth).\n *\n * The browser client data runtime (`@happyvertical/smrt-web`, #1761) consumes\n * one typed collection definition per API-exposed REST collection. Three\n * emission sites need the SAME selection and field rules, or the emitted\n * runtime values and their declared types drift apart:\n *\n * - the `\\0smrt:web` runtime virtual module (JSON literal — {@link generateWebModule})\n * - the `@happyvertical/smrt-virt-web` ambient d.ts (vite-plugin)\n * - the physical `@smrt/web` d.ts (prebuild, for `tsc`-only consumers)\n *\n * All three import {@link selectWebCollectionEntries} from here so the value\n * emission and the type emission can never disagree. A fourth, hand-written\n * mirror of the field/collection definition types lives in\n * `@happyvertical/smrt-web` (`packages/smrt-web/src/index.ts`) — that package\n * is deliberately smrt-dependency-free, so its copy cannot import these types;\n * keep it textually in sync when the shape here changes. The per-collection SHAPE\n * (name/objectRef/className/endpoint/idField/actions/fields/relationships) is built by the\n * ONE {@link buildWebCollectionDefinition}, shared by the runtime emission AND\n * the #1764 {@link computeWebManifestHash} shape digest — so the emitted shape\n * and the hashed shape can never drift (a drift would let the hash under-cover a\n * change → stale client caches).\n */\n\nimport { createHash } from 'node:crypto';\nimport { resolveCustomActionMetadata } from '../generators/custom-action.js';\nimport {\n buildToolDescriptors,\n type ToolDescriptor,\n type ToolFieldMeta,\n} from '../generators/tool-schema.js';\nimport type {\n FieldDefinition,\n FieldUIHints,\n SmartObjectDefinition,\n SmartObjectManifest,\n} from '../scanner/types.js';\nimport { resolveApiActionSet } from './sveltekit-generator.js';\n\n/**\n * Field types that are relationship pseudo-columns rather than persisted\n * public-DTO columns — they never appear on the wire as scalar values.\n */\nconst RELATIONSHIP_FIELD_TYPES: ReadonlySet<FieldDefinition['type']> = new Set([\n 'oneToMany',\n 'manyToMany',\n]);\n\n/**\n * Field types that describe a relationship to another model. A superset of\n * {@link RELATIONSHIP_FIELD_TYPES}: `foreignKey`/`crossPackageRef` are persisted\n * scalar id columns (they DO appear on the wire), while `oneToMany`/`manyToMany`\n * are pseudo-columns — but all four carry a `related` edge to a sibling model.\n */\nconst RELATIONSHIP_EDGE_TYPES: ReadonlySet<FieldDefinition['type']> = new Set([\n 'foreignKey',\n 'crossPackageRef',\n 'oneToMany',\n 'manyToMany',\n]);\n\n/**\n * The field types that actually reach an emitted web collection definition:\n * everything {@link buildWebFieldDefinitions} does not skip. Relationship\n * pseudo-columns (`oneToMany`/`manyToMany`) and STI `meta` internals never\n * appear on the wire, so they are excluded from the union — keeping the\n * declared type honest about what a client can observe. Co-managed with the\n * `SmrtWebFieldType` unions in the ambient `@happyvertical/smrt-virt-web`\n * d.ts, the physical `@smrt/web` d.ts, and the hand-written\n * `@happyvertical/smrt-web` mirror.\n */\nexport type WebFieldType = Exclude<\n FieldDefinition['type'],\n 'meta' | 'oneToMany' | 'manyToMany'\n>;\n\n/** Informational per-column metadata carried by a collection definition. */\nexport interface WebFieldDefinition {\n type: WebFieldType;\n required?: boolean;\n /** Whether the public field contract explicitly permits `null`. */\n nullable?: boolean;\n default?: unknown;\n /**\n * The developer-authored `@field({ description })` (#2046) — the same text\n * that feeds OpenAPI and MCP schemas, now available to browser UIs as the\n * seed for end-user field help. Sensitive/transient fields are excluded\n * from emission entirely, so their descriptions never ship to the client.\n */\n description?: string;\n /** Static `@field({ ui })` hints (#2046) — the field-policy rail seed. */\n ui?: FieldUIHints;\n}\n\n/** The relationship kinds a web collection edge can describe. */\nexport type WebRelationshipKind =\n | 'foreignKey'\n | 'crossPackageRef'\n | 'oneToMany'\n | 'manyToMany';\n\n/**\n * One manifest-derived relationship edge from a collection to a sibling REST\n * collection. Consumed by the browser client-data runtime to invalidate\n * dependent collection caches when this collection is mutated (#1761) — the\n * cache-invalidation graph is derived entirely from these edges, never\n * hand-wired. SMRT-owned data: no client-engine type appears here.\n */\nexport interface WebRelationship {\n /** The declaring field carrying the relationship (e.g. `groupId`, `items`). */\n field: string;\n /** The relationship kind, mirroring the manifest field type. */\n kind: WebRelationshipKind;\n /** REST collection name the edge resolves to (e.g. `ad_groups`). */\n relatedCollection: string;\n}\n\n/** One selected REST collection and the model that owns its definition. */\nexport interface WebCollectionEntry {\n /** REST collection name (pluralized), e.g. `products`. */\n collection: string;\n /** The manifest object that owns this collection's definition. */\n obj: SmartObjectDefinition;\n /** Sorted set of exposed CRUD + custom actions. */\n actions: string[];\n}\n\nfunction compareText(left: string, right: string): number {\n if (left < right) return -1;\n if (left > right) return 1;\n return 0;\n}\n\nfunction manifestObjectPackage(\n manifestKey: string | undefined,\n obj: SmartObjectDefinition,\n): string | undefined {\n if (obj.packageName) return obj.packageName;\n const qualifiedName = obj.qualifiedName || manifestKey;\n const separator = qualifiedName?.lastIndexOf(':') ?? -1;\n return separator > 0 ? qualifiedName?.slice(0, separator) : undefined;\n}\n\ninterface ManifestObjectIndex {\n byExactName: Map<string, SmartObjectDefinition>;\n byPackageAndClass: Map<string, SmartObjectDefinition>;\n bySimpleName: Map<string, SmartObjectDefinition>;\n packageByObject: WeakMap<SmartObjectDefinition, string>;\n objectRefByObject: WeakMap<SmartObjectDefinition, string>;\n}\n\nconst manifestObjectIndexes = new WeakMap<\n SmartObjectManifest['objects'],\n ManifestObjectIndex\n>();\n\nfunction packageAndClassKey(packageName: string, className: string): string {\n return `${packageName}\\0${className}`;\n}\n\nfunction getManifestObjectIndex(\n manifest: SmartObjectManifest,\n): ManifestObjectIndex {\n const cached = manifestObjectIndexes.get(manifest.objects);\n if (cached) return cached;\n\n const entries = Object.entries(manifest.objects).sort(\n ([leftKey, left], [rightKey, right]) =>\n compareText(\n left.qualifiedName || leftKey,\n right.qualifiedName || rightKey,\n ) || compareText(leftKey, rightKey),\n );\n const index: ManifestObjectIndex = {\n byExactName: new Map(),\n byPackageAndClass: new Map(),\n bySimpleName: new Map(),\n packageByObject: new WeakMap(),\n objectRefByObject: new WeakMap(),\n };\n\n for (const [manifestKey, candidate] of entries) {\n if (!index.byExactName.has(manifestKey)) {\n index.byExactName.set(manifestKey, candidate);\n }\n if (\n candidate.qualifiedName &&\n !index.byExactName.has(candidate.qualifiedName)\n ) {\n index.byExactName.set(candidate.qualifiedName, candidate);\n }\n if (!index.bySimpleName.has(candidate.className)) {\n index.bySimpleName.set(candidate.className, candidate);\n }\n\n const packageName = manifestObjectPackage(manifestKey, candidate);\n if (packageName) {\n if (!index.packageByObject.has(candidate)) {\n index.packageByObject.set(candidate, packageName);\n }\n const packageKey = packageAndClassKey(packageName, candidate.className);\n if (!index.byPackageAndClass.has(packageKey)) {\n index.byPackageAndClass.set(packageKey, candidate);\n }\n }\n\n // New manifests carry `qualifiedName` on each object. Legacy aggregated\n // manifests can omit it from the object body while retaining a qualified\n // manifest key, so retain that equally canonical identity for browser\n // definitions rather than falling back to an ambiguous simple class name.\n const objectRef = candidate.qualifiedName?.includes(':')\n ? candidate.qualifiedName\n : manifestKey.includes(':')\n ? manifestKey\n : packageName\n ? `${packageName}:${candidate.className}`\n : undefined;\n if (objectRef && !index.objectRefByObject.has(candidate)) {\n index.objectRefByObject.set(candidate, objectRef);\n }\n }\n\n manifestObjectIndexes.set(manifest.objects, index);\n return index;\n}\n\nfunction indexedManifestObjectPackage(\n manifest: SmartObjectManifest,\n obj: SmartObjectDefinition,\n): string | undefined {\n const index = getManifestObjectIndex(manifest);\n return (\n index.packageByObject.get(obj) || manifestObjectPackage(undefined, obj)\n );\n}\n\n/**\n * Return the canonical qualified model identity carried by a web collection.\n * Field-policy APIs require this `@package/name:ClassName` reference; a simple\n * class name is ambiguous in aggregated manifests and must never reach a\n * browser definition.\n */\nfunction webCollectionObjectRef(\n manifest: SmartObjectManifest,\n obj: SmartObjectDefinition,\n): string {\n const objectRef = getManifestObjectIndex(manifest).objectRefByObject.get(obj);\n if (objectRef) return objectRef;\n\n throw new Error(\n `[smrt] Cannot emit web collection definition for ${obj.className}: ` +\n 'a qualifiedName, qualified manifest key, or packageName is required',\n );\n}\n\n/**\n * Resolve a manifest object deterministically across aggregated packages.\n *\n * Qualified references win exactly. Simple references prefer the referencing\n * object's package, then fall back to a stable qualified/key identity. This is\n * important because aggregated manifests can contain duplicate class names and\n * their object insertion order reflects package discovery order.\n */\nexport function findManifestObjectByName(\n manifest: SmartObjectManifest,\n name: string,\n owner?: SmartObjectDefinition,\n): SmartObjectDefinition | undefined {\n const index = getManifestObjectIndex(manifest);\n const exact = name.includes(':') ? index.byExactName.get(name) : undefined;\n if (exact) return exact;\n\n const ownerPackage = owner\n ? indexedManifestObjectPackage(manifest, owner)\n : undefined;\n const packageLocal = ownerPackage\n ? index.byPackageAndClass.get(packageAndClassKey(ownerPackage, name))\n : undefined;\n\n return packageLocal || index.bySimpleName.get(name);\n}\n\n/**\n * Normalize a relationship field's `related` value to a resolvable class name.\n *\n * Thunk forward-ref decorators — `@foreignKey(() => Scene)`, used heavily in\n * video/voice for models that reference a class declared later — used to\n * serialize as the RAW arrow-function source string `\"() => Scene\"` in the\n * manifest, which neither `className` nor `qualifiedName` matches. The scanner\n * now unwraps the thunk itself (#2379), so this only has to cover manifests\n * generated before that fix. Extract the target class name from the thunk so\n * the edge resolves. Plain (`\"Scene\"`) and qualified\n * (`\"@happyvertical/smrt-assets:Asset\"`) forms contain no `=>` and pass through\n * untouched — the qualified `:` separator is preserved.\n *\n * Kept local to the relationship-edge path on purpose: extends-chain resolution\n * never sees a thunk, so `findManifestObjectByName` and the scanner stay\n * unchanged.\n */\nfunction normalizeRelatedName(related: string): string {\n const thunk = related.match(/=>\\s*([A-Za-z_$][\\w$]*)/);\n return thunk ? thunk[1] : related.trim();\n}\n\n/**\n * True when `obj` is (transitively) a SmrtCollection subclass. Collection\n * classes describe access, not row shapes, so they never become web\n * collection definitions.\n *\n * NOTE: deliberately stronger than sveltekit-generator's private\n * `isCollectionClass`, which only inspects the direct base / a type argument.\n * A deeper subclass (`SpecialWidgetCollection extends WidgetCollection`)\n * carries no type argument of its own; without walking the extends chain it\n * would be mistaken for a model and claim its base model's REST collection.\n */\nexport function isCollectionManifestClass(\n manifest: SmartObjectManifest,\n obj: SmartObjectDefinition,\n seen: Set<string> = new Set(),\n): boolean {\n // Truthy check (not `!== undefined`) mirrors the scanner's own\n // manifest-generator: a scanner that emits `extendsTypeArg: null` for a\n // non-generic base must not be misread as a collection.\n if (obj.extends === 'SmrtCollection' || obj.extendsTypeArg) {\n return true;\n }\n const parentName = obj.extendsQualified || obj.extends;\n if (!parentName || seen.has(parentName)) return false;\n seen.add(parentName);\n const parent = findManifestObjectByName(manifest, parentName, obj);\n return parent ? isCollectionManifestClass(manifest, parent, seen) : false;\n}\n\n/**\n * Resolve the row model carried by a collection class.\n *\n * An explicit generic on any ancestor is authoritative. Conventional\n * `FooCollection` → `Foo` lookup is only a fallback after the full ancestry\n * has been checked, so an unrelated `SpecialFoo` cannot override an inherited\n * `FooCollection<Foo>` contract.\n */\nfunction collectionAncestry(\n manifest: SmartObjectManifest,\n obj: SmartObjectDefinition,\n): SmartObjectDefinition[] {\n const ancestry: SmartObjectDefinition[] = [];\n const seen = new Set<string>();\n let candidate: SmartObjectDefinition | undefined = obj;\n\n while (candidate) {\n ancestry.push(candidate);\n const parentName = candidate.extendsQualified || candidate.extends;\n if (!parentName || seen.has(parentName)) break;\n seen.add(parentName);\n candidate = findManifestObjectByName(manifest, parentName, candidate);\n }\n return ancestry;\n}\n\n/**\n * Resolve the authoritative collection item type name even when a partial\n * manifest omits the item definition itself.\n */\ninterface CollectionItemReference {\n name: string;\n owner: SmartObjectDefinition;\n object?: SmartObjectDefinition;\n}\n\nfunction resolveCollectionItemCandidate(\n manifest: SmartObjectManifest,\n name: string,\n owner: SmartObjectDefinition,\n): CollectionItemReference {\n const object = findManifestObjectByName(manifest, name, owner);\n const ownerPackage = indexedManifestObjectPackage(manifest, owner);\n\n if (!name.includes(':') && ownerPackage) {\n const objectPackage = object\n ? indexedManifestObjectPackage(manifest, object)\n : undefined;\n if (objectPackage !== ownerPackage) {\n return {\n name: `${ownerPackage}:${name}`,\n owner,\n };\n }\n }\n\n return { name, owner, object };\n}\n\nfunction resolveCollectionItemReference(\n manifest: SmartObjectManifest,\n obj: SmartObjectDefinition,\n): CollectionItemReference | undefined {\n const ancestry = collectionAncestry(manifest, obj);\n for (const collectionClass of ancestry) {\n if (collectionClass.extendsTypeArg) {\n return resolveCollectionItemCandidate(\n manifest,\n collectionClass.extendsTypeArg,\n collectionClass,\n );\n }\n }\n\n let fallback: CollectionItemReference | undefined;\n for (const collectionClass of ancestry) {\n if (!collectionClass.className.endsWith('Collection')) continue;\n const conventionalName = collectionClass.className.slice(\n 0,\n -'Collection'.length,\n );\n const candidate = resolveCollectionItemCandidate(\n manifest,\n conventionalName,\n collectionClass,\n );\n if (candidate.object) return candidate;\n fallback ??= candidate;\n }\n\n return fallback;\n}\n\nexport function resolveCollectionItemTypeName(\n manifest: SmartObjectManifest,\n obj: SmartObjectDefinition,\n): string | undefined {\n return resolveCollectionItemReference(manifest, obj)?.name;\n}\n\nexport function resolveCollectionItemObject(\n manifest: SmartObjectManifest,\n obj: SmartObjectDefinition,\n): SmartObjectDefinition | undefined {\n return resolveCollectionItemReference(manifest, obj)?.object;\n}\n\n/**\n * True when some ancestor model maps to the SAME REST collection (a shared STI\n * table). The STI base model owns the shared table's single definition.\n */\nfunction isStiChildModel(\n manifest: SmartObjectManifest,\n obj: SmartObjectDefinition,\n): boolean {\n const seen = new Set<string>();\n let child = obj;\n let parentName = child.extendsQualified || child.extends;\n while (parentName && !seen.has(parentName)) {\n seen.add(parentName);\n const parent = findManifestObjectByName(manifest, parentName, child);\n if (!parent) return false;\n if (parent.collection === obj.collection) return true;\n child = parent;\n parentName = parent.extendsQualified || parent.extends;\n }\n return false;\n}\n\n/**\n * Select one entry per REST collection whose exposed action set satisfies\n * `qualifies` — STI children folding into their base model, collection classes\n * excluded. Uses the canonical {@link resolveApiActionSet} so the exposed-action\n * set matches exactly what the REST/SvelteKit generators actually emit. Shared\n * by {@link selectWebCollectionEntries} (list-qualified — materializable\n * collections) and {@link selectWebEtagSaltEntries} (get-OR-list — every model\n * with a read route the ETag salt must cover).\n */\nfunction selectEntriesQualifiedBy(\n manifest: SmartObjectManifest,\n qualifies: (actions: ReadonlySet<string>) => boolean,\n): WebCollectionEntry[] {\n const byCollection = new Map<\n string,\n WebCollectionEntry & { isStiChild: boolean }\n >();\n\n for (const obj of Object.values(manifest.objects)) {\n if (isCollectionManifestClass(manifest, obj)) continue;\n\n const exposedActions = resolveApiActionSet(obj);\n if (!qualifies(exposedActions)) continue;\n\n const isStiChild = isStiChildModel(manifest, obj);\n const existing = byCollection.get(obj.collection);\n // One definition per REST collection. The STI BASE model owns it: a child\n // only wins while no base has been recorded yet, so the result is\n // independent of declaration / scan order.\n if (existing && !(existing.isStiChild && !isStiChild)) continue;\n\n byCollection.set(obj.collection, {\n collection: obj.collection,\n obj,\n actions: [...exposedActions].sort(),\n isStiChild,\n });\n }\n\n return [...byCollection.values()].map(({ collection, obj, actions }) => ({\n collection,\n obj,\n actions,\n }));\n}\n\n/**\n * Select the manifest entries that become web collection definitions: one per\n * REST collection, STI children folding into their base model, collection\n * classes excluded, and only models that expose `list` (a read surface is\n * required to MATERIALIZE a client collection — that is what persists).\n */\nexport function selectWebCollectionEntries(\n manifest: SmartObjectManifest,\n): WebCollectionEntry[] {\n return selectEntriesQualifiedBy(manifest, (actions) => actions.has('list'));\n}\n\n/**\n * Select the entries the ETag salt (#1764) must cover: every api-exposed model\n * with a GENERATED READ ROUTE — `list` OR `get`. Broader than\n * {@link selectWebCollectionEntries} on purpose: a get-only model\n * (`api: { include: ['get'] }`) has no materializable client collection (so it\n * never persists), but its generated GET route IS salted, so a shape-only change\n * to it must still change the salt — otherwise a client holding the old concrete\n * ETag would get a zero-query 304 after a shape-only deploy (the #1765 gap the\n * salt closes). Not exported: only {@link computeWebManifestHash} consumes it.\n */\nfunction selectWebEtagSaltEntries(\n manifest: SmartObjectManifest,\n): WebCollectionEntry[] {\n return selectEntriesQualifiedBy(\n manifest,\n (actions) => actions.has('list') || actions.has('get'),\n );\n}\n\n/**\n * Build the per-collection web-collection definition literal — the SINGLE\n * source of truth for the shape emitted by {@link generateWebModule} and hashed\n * by {@link computeWebManifestHash}. Building it in ONE place is a\n * cache-coherency requirement: if the emitted shape and the hashed shape were\n * built independently, adding a field to one and not the other would let the\n * hash silently UNDER-cover a shape change, so persisted caches would not drop\n * and stale rows would hydrate into new code.\n */\nexport function buildWebCollectionDefinition(\n entry: WebCollectionEntry,\n manifest: SmartObjectManifest,\n): {\n name: string;\n objectRef: string;\n className: string;\n endpoint: string;\n idField: string;\n actions: string[];\n fields: Record<string, WebFieldDefinition>;\n relationships: WebRelationship[];\n} {\n return {\n name: entry.collection,\n objectRef: webCollectionObjectRef(manifest, entry.obj),\n className: entry.obj.className,\n endpoint: `/${entry.collection}`,\n idField: 'id',\n actions: entry.actions,\n fields: buildWebFieldDefinitions(entry.obj),\n relationships: buildWebRelationships(entry.obj, manifest),\n };\n}\n\n/**\n * Build the informational per-field metadata for a web collection definition:\n * the persisted public-DTO columns only. Relationship pseudo-fields, STI meta\n * internals, transient (unpersisted) and sensitive (wire-stripped) fields are\n * excluded — they are not columns a client reads back over the REST surface.\n */\nexport function buildWebFieldDefinitions(\n obj: SmartObjectDefinition,\n): Record<string, WebFieldDefinition> {\n const fields: Record<string, WebFieldDefinition> = {};\n for (const [fieldName, field] of Object.entries(obj.fields ?? {})) {\n if (RELATIONSHIP_FIELD_TYPES.has(field.type)) continue;\n if (field.type === 'meta') continue;\n if (field.transient) continue;\n if (field.sensitive) continue;\n const ui = sanitizeFieldUIHints(field._meta?.ui);\n // Scanner manifests expose `description` top-level; runtime-registry\n // manifests (computeRuntimeWebManifestHash → registeredFieldsToManifest)\n // keep it under `_meta` only. Read both so the build-time and runtime\n // shape digests agree — otherwise every described field would latch a\n // false `updateAvailable.contract` signal on APIGenerator SSE connects.\n const description = readFieldDescription(field);\n fields[fieldName] = {\n // Safe: the three skips above are exactly the types WebFieldType excludes.\n type: field.type as WebFieldType,\n ...(field.required !== undefined ? { required: field.required } : {}),\n ...(field._meta?.nullable === true ? { nullable: true } : {}),\n ...(field.default !== undefined ? { default: field.default } : {}),\n ...(description !== undefined ? { description } : {}),\n ...(ui ? { ui } : {}),\n };\n }\n return fields;\n}\n\n/** Top-level `description` with `_meta.description` fallback (see call site). */\nfunction readFieldDescription(field: FieldDefinition): string | undefined {\n if (typeof field.description === 'string' && field.description !== '') {\n return field.description;\n }\n const metaDescription = field._meta?.description;\n if (typeof metaDescription === 'string' && metaDescription !== '') {\n return metaDescription;\n }\n return undefined;\n}\n\n/**\n * Narrow a manifest `_meta.ui` bag to the known {@link FieldUIHints} keys with\n * per-key type guards. `_meta` is an open bag, so authored junk (wrong-typed\n * values, arbitrary extra keys) must not reach the emitted client module — the\n * emitted value also feeds the #1764 shape digest, so unknown unstable keys\n * would churn the hash. Returns undefined when nothing valid remains, so\n * hint-less fields emit no `ui` key at all (existing shapes stay byte-stable).\n */\nfunction sanitizeFieldUIHints(value: unknown): FieldUIHints | undefined {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) {\n return undefined;\n }\n const raw = value as Record<string, unknown>;\n const ui: FieldUIHints = {\n ...(typeof raw.basic === 'boolean' ? { basic: raw.basic } : {}),\n ...(typeof raw.group === 'string' && raw.group !== ''\n ? { group: raw.group }\n : {}),\n ...(typeof raw.order === 'number' && Number.isFinite(raw.order)\n ? { order: raw.order }\n : {}),\n ...(typeof raw.locked === 'boolean' ? { locked: raw.locked } : {}),\n };\n return Object.keys(ui).length > 0 ? ui : undefined;\n}\n\n/**\n * Build the manifest-derived relationship edges for a web collection\n * definition (#1761): one entry per relationship field (`foreignKey`,\n * `crossPackageRef`, `oneToMany`, `manyToMany`) whose `related` target resolves\n * to another API-exposed REST collection.\n *\n * These edges drive relationship-derived cache invalidation in the browser\n * client-data runtime: mutating this collection invalidates the caches of the\n * collections named here. The invalidation graph is thus derived entirely from\n * the manifest — no hand-wired cache keys.\n *\n * An edge is SKIPPED (not emitted) when:\n * - `related` is missing, or\n * - `related` cannot be resolved to a manifest object (e.g. a cross-package\n * target not present in this package's manifest), or\n * - the resolved target is not itself an API-exposed web collection (no read\n * surface to invalidate — it never appears in {@link selectWebCollectionEntries}).\n *\n * Self-referential edges (a collection related to itself) are kept: the runtime\n * always invalidates the mutated collection anyway, so a self edge is harmless\n * and keeping it avoids a special case.\n */\nexport function buildWebRelationships(\n obj: SmartObjectDefinition,\n manifest: SmartObjectManifest,\n): WebRelationship[] {\n // The set of REST collections that are actually materialized as web\n // collections. An edge to a model outside this set has no client cache to\n // invalidate, so it is dropped.\n const exposedCollections = new Set(\n selectWebCollectionEntries(manifest).map((entry) => entry.collection),\n );\n\n const relationships: WebRelationship[] = [];\n const seen = new Set<string>();\n for (const [fieldName, field] of Object.entries(obj.fields ?? {})) {\n if (!RELATIONSHIP_EDGE_TYPES.has(field.type)) continue;\n if (!field.related) continue;\n\n // Normalize first: `@foreignKey(() => Scene)` thunks serialize as the raw\n // \"() => Scene\" source, which findManifestObjectByName cannot match on its\n // own.\n const target = findManifestObjectByName(\n manifest,\n normalizeRelatedName(field.related),\n obj,\n );\n if (!target) continue;\n if (!exposedCollections.has(target.collection)) continue;\n\n // De-dupe on (field, relatedCollection): a model never declares the same\n // field twice, but guard anyway so the emitted edge list is stable.\n const dedupeKey = `${fieldName}:${target.collection}`;\n if (seen.has(dedupeKey)) continue;\n seen.add(dedupeKey);\n\n relationships.push({\n field: fieldName,\n kind: field.type as WebRelationshipKind,\n relatedCollection: target.collection,\n });\n }\n return relationships;\n}\n\n/**\n * Build the WebMCP / MCP tool descriptors for a web collection (#1812): one\n * descriptor per exposed action, over the SAME public-DTO fields the definition\n * already exposes (`buildWebFieldDefinitions`). The tool ids match the Node MCP\n * surface (`<class>_<action>`), so a page's WebMCP tools and its MCP-server\n * tools share one vocabulary.\n *\n * Deliberately NOT part of {@link buildWebCollectionDefinition}: descriptors are\n * layered onto the emitted value by {@link generateWebModule} instead, so the\n * #1764 {@link computeWebManifestHash} shape digest keeps hashing ONLY the row\n * shape. That remains safe because descriptor-only inputs (including `idType`)\n * do not alter persisted public rows or read responses, which are the cache\n * contracts this digest protects.\n */\nexport function buildWebToolDescriptors(\n entry: WebCollectionEntry,\n): ToolDescriptor[] {\n const webFields = buildWebFieldDefinitions(entry.obj);\n const fields: ToolFieldMeta[] = Object.entries(webFields).map(\n ([name, def]) => ({\n name,\n type: def.type,\n ...(def.required !== undefined ? { required: def.required } : {}),\n ...(def.nullable === true ? { nullable: true } : {}),\n ...(def.default !== undefined ? { default: def.default } : {}),\n // #2046: the authored field description flows into the generated JSON\n // Schema (`fieldTypeToJsonSchema` prefers it over the type-derived\n // fallback), so browser-side WebMCP tools document their arguments.\n ...(def.description !== undefined\n ? { description: def.description }\n : {}),\n }),\n );\n return buildToolDescriptors({\n className: entry.obj.className,\n fields,\n actions: entry.actions,\n customActions: Object.fromEntries(\n entry.actions.map((action) => [\n action,\n resolveCustomActionMetadata({\n actionName: action,\n method: entry.obj.methods?.[action],\n apiConfig: entry.obj.decoratorConfig?.api,\n }),\n ]),\n ),\n idType: entry.obj.decoratorConfig.idType,\n });\n}\n\n/**\n * Recursively sort object keys so structurally-equal values serialize to the\n * SAME JSON regardless of insertion order. Arrays keep their order (order is\n * semantic for `actions`/`relationships`); objects are rebuilt with keys sorted.\n * Required for {@link computeWebManifestHash} to be replica-stable: two builds\n * that produce the same schema but visit the manifest in a different order (map\n * insertion, scan order) must still hash identically, which a plain\n * `JSON.stringify` of insertion-ordered objects would NOT guarantee.\n */\nfunction canonicalize(value: unknown): unknown {\n if (Array.isArray(value)) {\n return value.map((entry) => canonicalize(entry));\n }\n if (value && typeof value === 'object') {\n const sorted: Record<string, unknown> = {};\n for (const key of Object.keys(value as Record<string, unknown>).sort()) {\n sorted[key] = canonicalize((value as Record<string, unknown>)[key]);\n }\n return sorted;\n }\n return value;\n}\n\n/**\n * A deterministic, replica-stable digest of the web-collection SHAPE (#1764).\n *\n * The hash covers exactly the thing whose change means either old persisted\n * client rows may mis-hydrate OR a stale read ETag would still 304: the same\n * per-collection definition shape {@link generateWebModule} emits — name,\n * className, endpoint, idField, actions, fields, relationships — built via the\n * SHARED {@link buildWebCollectionDefinition} so the hash can never disagree\n * with what is actually shipped. The shape is CANONICALIZED (keys recursively\n * sorted; see {@link canonicalize}) before hashing, so the same schema always\n * yields the same digest across builds and replicas regardless of manifest\n * iteration order.\n *\n * SCOPE — get-OR-list (broader than materializable collections). Covered by\n * {@link selectWebEtagSaltEntries}, so it includes GET-ONLY models too: those do\n * not persist (no materializable collection), but their generated GET route IS\n * salted with this hash, so a shape-only change to a get-only model must change\n * it or a client holding the old concrete ETag gets a zero-query 304 after a\n * shape-only deploy (the #1765 gap the salt closes). The two consumers both use\n * this one value, so it stays identical between them:\n * - `@happyvertical/smrt-web` persistence (#1764) folds it into the durable\n * namespace, so a contract-changing deploy lands on a fresh namespace and old\n * rows are never found (dropped, not mis-hydrated). Including get-only models\n * here is harmless over-invalidation — only list-materializable collections\n * ever hold a persisted snapshot.\n * - the generated read ETag (#1765 salt, #1764) folds it in so a shape-only\n * deploy (no table write) busts every read validator, get-only routes too.\n *\n * Truncated to the first 16 base64url chars: 96 bits is far more than enough to\n * make an accidental shape collision negligible, and a short constant keeps the\n * emitted module and every persistence key compact.\n */\nexport function computeWebManifestHash(manifest: SmartObjectManifest): string {\n const definitions: Record<string, unknown> = {};\n for (const entry of selectWebEtagSaltEntries(manifest)) {\n definitions[entry.collection] = buildWebCollectionDefinition(\n entry,\n manifest,\n );\n }\n const canonicalJson = JSON.stringify(canonicalize(definitions));\n return createHash('sha256')\n .update(canonicalJson)\n .digest('base64url')\n .slice(0, 16);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,IAAM,2CAAiE,IAAI,IAAI,CAC7E,aACA,YACF,CAAC;;;;;;;AAQD,IAAM,0CAAgE,IAAI,IAAI;CAC5E;CACA;CACA;CACA;AACF,CAAC;AAoED,SAAS,YAAY,MAAc,OAAuB;CACxD,IAAI,OAAO,OAAO,OAAO;CACzB,IAAI,OAAO,OAAO,OAAO;CACzB,OAAO;AACT;AAEA,SAAS,sBACP,aACA,KACoB;CACpB,IAAI,IAAI,aAAa,OAAO,IAAI;CAChC,MAAM,gBAAgB,IAAI,iBAAiB;CAC3C,MAAM,YAAY,eAAe,YAAY,GAAG,KAAK;CACrD,OAAO,YAAY,IAAI,eAAe,MAAM,GAAG,SAAS,IAAI,KAAA;AAC9D;AAUA,IAAM,wCAAwB,IAAI,QAGhC;AAEF,SAAS,mBAAmB,aAAqB,WAA2B;CAC1E,OAAO,GAAG,YAAY,IAAI;AAC5B;AAEA,SAAS,uBACP,UACqB;CACrB,MAAM,SAAS,sBAAsB,IAAI,SAAS,OAAO;CACzD,IAAI,QAAQ,OAAO;CAEnB,MAAM,UAAU,OAAO,QAAQ,SAAS,OAAO,CAAC,CAAC,MAC9C,CAAC,SAAS,OAAO,CAAC,UAAU,WAC3B,YACE,KAAK,iBAAiB,SACtB,MAAM,iBAAiB,QACzB,KAAK,YAAY,SAAS,QAAQ,CACtC;CACA,MAAM,QAA6B;EACjC,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IAAI,CAAC;EAI5D,GAAI,IAAI,gBAAgB,KAAA,IACpB,EAAE,aAAa,IAAI,YAAY,IAC/B,CAAC;CACP,EACF;CACA,OAAO,qBAAqB;EAC1B,WAAW,MAAM,IAAI;EACrB;EACA,SAAS,MAAM;EACf,eAAe,OAAO,YACpB,MAAM,QAAQ,KAAK,WAAW,CAC5B,QACA,4BAA4B;GAC1B,YAAY;GACZ,QAAQ,MAAM,IAAI,UAAU;GAC5B,WAAW,MAAM,IAAI,iBAAiB;EACxC,CAAC,CACH,CAAC,CACH;EACA,QAAQ,MAAM,IAAI,gBAAgB;CACpC,CAAC;AACH;;;;;;;;;;AAWA,SAAS,aAAa,OAAyB;CAC7C,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,MAAM,KAAK,UAAU,aAAa,KAAK,CAAC;CAEjD,IAAI,SAAS,OAAO,UAAU,UAAU;EACtC,MAAM,SAAkC,CAAC;EACzC,KAAK,MAAM,OAAO,OAAO,KAAK,KAAgC,CAAC,CAAC,KAAK,GACnE,OAAO,OAAO,aAAc,MAAkC,IAAI;EAEpE,OAAO;CACT;CACA,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,SAAgB,uBAAuB,UAAuC;CAC5E,MAAM,cAAuC,CAAC;CAC9C,KAAK,MAAM,SAAS,yBAAyB,QAAQ,GACnD,YAAY,MAAM,cAAc,6BAC9B,OACA,QACF;CAEF,MAAM,gBAAgB,KAAK,UAAU,aAAa,WAAW,CAAC;CAC9D,OAAO,WAAW,QAAQ,CAAC,CACxB,OAAO,aAAa,CAAC,CACrB,OAAO,WAAW,CAAC,CACnB,MAAM,GAAG,EAAE;AAChB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@happyvertical/smrt-core",
|
|
3
|
-
"version": "0.40.
|
|
3
|
+
"version": "0.40.70",
|
|
4
4
|
"description": "Core AI agent framework with standardized collections, object-relational mapping, and code generators",
|
|
5
5
|
"author": "HappyVertical",
|
|
6
6
|
"type": "module",
|
|
@@ -164,9 +164,9 @@
|
|
|
164
164
|
"tsx": "^4.23.0",
|
|
165
165
|
"typescript": "5.9.3",
|
|
166
166
|
"yaml": "^2.9.0",
|
|
167
|
-
"@happyvertical/smrt-config": "0.40.
|
|
168
|
-
"@happyvertical/smrt-scanner": "0.40.
|
|
169
|
-
"@happyvertical/smrt-types": "0.40.
|
|
167
|
+
"@happyvertical/smrt-config": "0.40.70",
|
|
168
|
+
"@happyvertical/smrt-scanner": "0.40.70",
|
|
169
|
+
"@happyvertical/smrt-types": "0.40.70"
|
|
170
170
|
},
|
|
171
171
|
"peerDependencies": {
|
|
172
172
|
"@huggingface/transformers": ">=3.0.0 <4.0.0",
|
|
@@ -207,7 +207,7 @@
|
|
|
207
207
|
"generate": "node scripts/generate-manifest.js",
|
|
208
208
|
"generate:test": "node scripts/generate-test-manifest.js",
|
|
209
209
|
"test": "node scripts/generate-test-manifest.js && vitest run",
|
|
210
|
-
"test:postgres": "node scripts/generate-test-manifest.js && NODE_OPTIONS=--trace-deprecation node ../../scripts/run-with-ci-postgres.mjs -- pnpm exec vitest run
|
|
210
|
+
"test:postgres": "node scripts/generate-test-manifest.js && NODE_OPTIONS=--trace-deprecation node ../../scripts/run-with-ci-postgres.mjs -- pnpm exec vitest run optional.test.ts",
|
|
211
211
|
"test:integration": "TEST_INTEGRATION=1 vitest run src/__tests__/full-registry-integration.test.ts src/__tests__/manifest-no-leak.test.ts",
|
|
212
212
|
"test:watch": "node scripts/generate-test-manifest.js && vitest",
|
|
213
213
|
"build": "node scripts/generate-manifest.js && vite build && cp -r src/vite-plugin/templates dist/vite-plugin/ && cp -r scripts dist/ && cp src/manifest/static-manifest.json dist/manifest.json && cp src/manifest/smrt-knowledge.json dist/smrt-knowledge.json",
|