@carbonenginejs/runtime 0.1.0-alpha.2 → 0.1.0-alpha.3
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/dist/global/model/CjsModel.js +3 -1
- package/dist/global/model/CjsModel.js.map +1 -1
- package/dist/global/model/document/CjsDocumentHydrator.js +5 -1
- package/dist/global/model/document/CjsDocumentHydrator.js.map +1 -1
- package/dist/global/schema/CjsSchema.js +98 -18
- package/dist/global/schema/CjsSchema.js.map +1 -1
- package/dist/global/schema/hydration.js +10 -8
- package/dist/global/schema/hydration.js.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/resource/CjsResMan.js +177 -4
- package/dist/resource/CjsResMan.js.map +1 -1
- package/dist/resource/format/CjsBlueReader.js +8 -1
- package/dist/resource/format/CjsBlueReader.js.map +1 -1
- package/dist/resource/formats/webgl/core/glsl/DxbcGlslEmitter.js +7 -1
- package/dist/resource/formats/webgl/core/glsl/DxbcGlslEmitter.js.map +1 -1
- package/dist/resource/index.js +2 -0
- package/dist/resource/index.js.map +1 -1
- package/dist/resource/texture/SolidColorTextureConstructor.js +46 -0
- package/dist/resource/texture/SolidColorTextureConstructor.js.map +1 -0
- package/dist/resource/texture/TriTextureRes.js +43 -0
- package/dist/resource/texture/TriTextureRes.js.map +1 -1
- package/dist/resource/texture/index.js +2 -0
- package/dist/resource/texture/index.js.map +1 -1
- package/dist/resource/texture/solidColorTexture.js +111 -0
- package/dist/resource/texture/solidColorTexture.js.map +1 -0
- package/dist/trinity/eve/attachment/decal/EveSpaceObjectDecal.js +19 -8
- package/dist/trinity/eve/attachment/decal/EveSpaceObjectDecal.js.map +1 -1
- package/dist/trinity/eve/child/EveChildMesh.js +17 -3
- package/dist/trinity/eve/child/EveChildMesh.js.map +1 -1
- package/dist/trinity/eve/locator/EveLocatorSets.js +12 -3
- package/dist/trinity/eve/locator/EveLocatorSets.js.map +1 -1
- package/dist/trinity/eve/spaceObject/EveSpaceObject2.js +15 -2
- package/dist/trinity/eve/spaceObject/EveSpaceObject2.js.map +1 -1
- package/dist/trinity/eve/spaceObject/IEveSpaceObject2ParentData.js +44 -52
- package/dist/trinity/eve/spaceObject/IEveSpaceObject2ParentData.js.map +1 -1
- package/docs/resource/concepts/resource-lifecycle.md +10 -8
- package/docs/resource/formats/geometry-interchange.md +50 -0
- package/docs/resource/formats/webgl/decl-io.md +241 -397
- package/docs/resource/formats/webgl/memory-structured.md +91 -128
- package/docs/resource/formats/webgl/texture-sample.md +306 -469
- package/docs/resource/reference/classes/texture.md +11 -1
- package/docs/resource/reference/motherlode-cache.md +24 -11
- package/docs/resource/reference/queues.md +23 -1
- package/package.json +1 -1
|
@@ -124,7 +124,11 @@ class CjsDocumentHydrator {
|
|
|
124
124
|
kind: node.kind,
|
|
125
125
|
shape,
|
|
126
126
|
node,
|
|
127
|
-
options
|
|
127
|
+
options,
|
|
128
|
+
// The class this hydrator resolved for the kind, asked of the schema:
|
|
129
|
+
// does it declare fields to populate? A caller-supplied plain class
|
|
130
|
+
// does not, and keeps raw assignment.
|
|
131
|
+
declared: CjsSchema.getClassName(CjsDocumentHydrator.resolveClass(node.kind, options)) !== null
|
|
128
132
|
});
|
|
129
133
|
Object.assign(target, rawValues);
|
|
130
134
|
return target;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CjsDocumentHydrator.js","sources":["../../../../../src/global/model/document/CjsDocumentHydrator.js"],"sourcesContent":["// DEPRECATED carbon.document boundary. The collapse into plain CjsModel\n// values is decided and partially executed - the envelope was\n// over-engineered, and a _type-tagged values graph carries everything it\n// did. Kept only until the interchange retirement completes its inventory\n// (docs/contracts/model-values-interchange.md owns the rule: no document\n// producer or consumer retires without inventory and replacement proof;\n// docs/research/schema-hydration-consolidation-plan-2026-09-05.md holds\n// the enumerated remaining surfaces). Do not add new consumers.\nimport { normalizeCarbonValue } from \"../../schema/types/index.js\";\r\nimport { CjsSchema } from \"../../schema/index.js\";\r\nimport { CjsCarbonDocument } from \"./CjsCarbonDocument.js\";\r\nimport { resolveHydrationAdapter } from \"../../schema/hydration.js\";\r\n\r\n/** Constructs runtime object graphs from neutral Carbon documents. */\r\nexport class CjsDocumentHydrator\r\n{\r\n /**\r\n * Hydrates every node in a Carbon document through the selected registry and\r\n * adapter.\r\n */\r\n Hydrate(document, options = {})\r\n {\r\n return CjsDocumentHydrator.hydrate(document, options);\r\n }\r\n\r\n /** Hydrates a Carbon document and returns its first root. */\r\n HydrateRoot(document, options = {})\r\n {\r\n return CjsDocumentHydrator.hydrateRoot(document, options);\r\n }\r\n\r\n /** Hydrates a normalized document into constructed runtime objects and roots. */\r\n static hydrate(document, options = {})\r\n {\r\n const normalized = CjsCarbonDocument.normalize(document);\r\n const nodeById = new Map(normalized.nodes.map(node => [node.id, node]));\r\n const instanceById = new Map();\r\n const reports = [];\r\n const adapter = resolveHydrationAdapter(options);\r\n\r\n for (const node of normalized.nodes)\r\n {\r\n instanceById.set(node.id, CjsDocumentHydrator.createNodeTarget(node, options, reports, adapter));\r\n }\r\n\r\n for (const node of normalized.nodes)\r\n {\r\n CjsDocumentHydrator.applyNodeValues(instanceById.get(node.id), node, instanceById, options, adapter);\r\n }\r\n\r\n // Phase 3: every instance is constructed and valued, so references are\r\n // resolved - now let callers run their own post-graph init.\r\n for (const node of normalized.nodes)\r\n {\r\n adapter.finalize(instanceById.get(node.id), { kind: node.kind, node, options });\r\n }\r\n\r\n const roots = normalized.roots.map(root => ({\r\n name: root.name,\r\n value: CjsDocumentHydrator.resolveDocumentValue(root.ref, instanceById, options)\r\n }));\r\n\r\n return {\r\n root: roots[0]?.value ?? null,\r\n roots,\r\n document: normalized,\r\n reports,\r\n get(id)\r\n {\r\n return instanceById.get(Number(id)) || null;\r\n },\r\n getNode(id)\r\n {\r\n return nodeById.get(Number(id)) || null;\r\n }\r\n };\r\n }\r\n\r\n /** Returns the first hydrated root in document order. */\r\n static hydrateRoot(document, options = {})\r\n {\r\n return CjsDocumentHydrator.hydrate(document, options).root;\r\n }\r\n\r\n /**\r\n * Constructs the runtime target appropriate for one normalized document\r\n * node.\r\n */\r\n static createNodeTarget(node, options, reports, adapter)\r\n {\r\n if (adapter)\r\n {\r\n const built = adapter.construct(node.kind, { kind: node.kind, node, options });\r\n if (built !== undefined) return built;\r\n }\r\n\r\n const ClassConstructor = CjsDocumentHydrator.resolveClass(node.kind, options);\r\n if (ClassConstructor)\r\n {\r\n return new ClassConstructor();\r\n }\r\n\r\n throw new TypeError(`No class is registered for hydratable type ${node.kind}.`);\r\n }\r\n\r\n /**\r\n * Applies resolved field values to a constructed node through the hydration\r\n * adapter.\r\n */\r\n static applyNodeValues(target, node, instanceById, options, adapter)\r\n {\r\n const registeredSchema = target?.constructor\r\n ? CjsSchema.getSchema(target.constructor)\r\n : null;\r\n const shape = target?._sourceShape || (registeredSchema?.className ? registeredSchema : null);\r\n const fieldByName = new Map((shape?.fields || []).map(field => [field.name, field]));\r\n const values = {};\r\n\r\n for (const [key, item] of Object.entries(node.fields || {}))\r\n {\r\n if (CjsSchema.isFieldHidden(target?.constructor, key)) continue;\r\n const field = fieldByName.get(key) || null;\r\n values[key] = CjsDocumentHydrator.hydrateFieldValue(item, field, instanceById, options);\r\n }\r\n\r\n // node.raw is enumerable NON-SCHEMA state, and its preservation is this\r\n // deprecated path's documented contract (model-values-interchange.md).\r\n // It is applied by direct assignment AFTER the adapter: a validated\r\n // setter rightly ignores undeclared keys, so raw state is the\r\n // hydrator's own job, exactly as it is for plain fallback carriers.\r\n const rawValues = {};\r\n for (const [key, item] of Object.entries(node.raw || {}))\r\n {\r\n if (CjsSchema.isFieldHidden(target?.constructor, key)) continue;\r\n rawValues[key] = CjsDocumentHydrator.resolveDocumentValue(item, instanceById, options);\r\n }\r\n\r\n const apply = adapter || resolveHydrationAdapter(options);\r\n apply.applyValues(target, values, { kind: node.kind, shape, node, options });\r\n Object.assign(target, rawValues);\r\n return target;\r\n }\r\n\r\n /** Hydrates one field value according to its schema descriptor. */\r\n static hydrateFieldValue(value, field, instanceById, options)\r\n {\r\n const resolved = CjsDocumentHydrator.resolveDocumentValue(value, instanceById, options);\r\n const descriptor = field?.type || field?.jsType || null;\r\n const kind = descriptor?.kind;\r\n\r\n if ((kind === \"array\" || kind === \"list\") && Array.isArray(resolved)) return resolved;\r\n if ((kind === \"model\" || kind === \"objectRef\" || kind === \"struct\" || kind === \"rawStruct\" || kind === \"unknown\") && resolved && typeof resolved === \"object\") return resolved;\r\n if (CjsDocumentHydrator.isShapeIncompatibleMathArray(resolved, descriptor)) return resolved;\r\n\r\n return descriptor ? normalizeCarbonValue(resolved, descriptor) : resolved;\r\n }\r\n\r\n /** Recursively resolves document references and nested portable values. */\r\n static resolveDocumentValue(value, instanceById, options)\r\n {\r\n if (CjsCarbonDocument.isRef(value))\r\n {\r\n const id = Number(value.$ref);\r\n if (instanceById.has(id)) return instanceById.get(id);\r\n if (options.allowMissingRefs) return null;\r\n throw new TypeError(`CarbonDocument ref ${id} does not exist`);\r\n }\r\n\r\n if (Array.isArray(value)) return value.map(item => CjsDocumentHydrator.resolveDocumentValue(item, instanceById, options));\r\n if (value && typeof value === \"object\")\r\n {\r\n return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, CjsDocumentHydrator.resolveDocumentValue(item, instanceById, options)]));\r\n }\r\n return value;\r\n }\r\n\r\n /** Resolves a node's serialized type through the active class registry. */\r\n static resolveClass(kind, options)\r\n {\r\n const Schema = options.registry || CjsSchema;\r\n return Schema.GetConstructor(kind);\r\n }\r\n\r\n /**\r\n * Reports when source-shape metadata prevents coercion to a declared math\r\n * container.\r\n */\r\n static isShapeIncompatibleMathArray(value, descriptor)\r\n {\r\n const expectedLength = descriptor?.length;\r\n return Array.isArray(value) && Number.isInteger(expectedLength) && value.length !== expectedLength;\r\n }\r\n}\r\n"],"names":["CjsDocumentHydrator","Hydrate","document","options","hydrate","HydrateRoot","hydrateRoot","normalized","CjsCarbonDocument","normalize","nodeById","Map","nodes","map","node","id","instanceById","reports","adapter","resolveHydrationAdapter","set","createNodeTarget","applyNodeValues","get","finalize","kind","roots","root","name","value","resolveDocumentValue","ref","Number","getNode","built","construct","undefined","ClassConstructor","resolveClass","TypeError","target","registeredSchema","constructor","CjsSchema","getSchema","shape","_sourceShape","className","fieldByName","fields","field","values","key","item","Object","entries","isFieldHidden","hydrateFieldValue","rawValues","raw","apply","applyValues","assign","resolved","descriptor","type","jsType","Array","isArray","isShapeIncompatibleMathArray","normalizeCarbonValue","isRef","$ref","has","allowMissingRefs","fromEntries","Schema","registry","GetConstructor","expectedLength","length","isInteger"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA;AACO,MAAMA,mBAAmB,CAChC;AACI;AACJ;AACA;AACA;AACIC,EAAAA,OAAOA,CAACC,QAAQ,EAAEC,OAAO,GAAG,EAAE,EAC9B;AACI,IAAA,OAAOH,mBAAmB,CAACI,OAAO,CAACF,QAAQ,EAAEC,OAAO,CAAC;AACzD,EAAA;;AAEA;AACAE,EAAAA,WAAWA,CAACH,QAAQ,EAAEC,OAAO,GAAG,EAAE,EAClC;AACI,IAAA,OAAOH,mBAAmB,CAACM,WAAW,CAACJ,QAAQ,EAAEC,OAAO,CAAC;AAC7D,EAAA;;AAEA;EACA,OAAOC,OAAOA,CAACF,QAAQ,EAAEC,OAAO,GAAG,EAAE,EACrC;AACI,IAAA,MAAMI,UAAU,GAAGC,iBAAiB,CAACC,SAAS,CAACP,QAAQ,CAAC;IACxD,MAAMQ,QAAQ,GAAG,IAAIC,GAAG,CAACJ,UAAU,CAACK,KAAK,CAACC,GAAG,CAACC,IAAI,IAAI,CAACA,IAAI,CAACC,EAAE,EAAED,IAAI,CAAC,CAAC,CAAC;AACvE,IAAA,MAAME,YAAY,GAAG,IAAIL,GAAG,EAAE;IAC9B,MAAMM,OAAO,GAAG,EAAE;AAClB,IAAA,MAAMC,OAAO,GAAGC,uBAAuB,CAAChB,OAAO,CAAC;AAEhD,IAAA,K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AAOb,KAAK,CAACC,OAAO,CAACvC,KAAK,CAAC,IAAIG,MAAM,CAACiD,SAAS,CAACF,cAAc,CAAC,IAAIlD,KAAK,CAACmD,MAAM,KAAKD,cAAc;AACtG,EAAA;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"CjsDocumentHydrator.js","sources":["../../../../../src/global/model/document/CjsDocumentHydrator.js"],"sourcesContent":["// DEPRECATED carbon.document boundary. The collapse into plain CjsModel\r\n// values is decided and partially executed - the envelope was\r\n// over-engineered, and a _type-tagged values graph carries everything it\r\n// did. Kept only until the interchange retirement completes its inventory\r\n// (docs/contracts/model-values-interchange.md owns the rule: no document\r\n// producer or consumer retires without inventory and replacement proof;\r\n// docs/research/schema-hydration-consolidation-plan-2026-09-05.md holds\r\n// the enumerated remaining surfaces). Do not add new consumers.\r\nimport { normalizeCarbonValue } from \"../../schema/types/index.js\";\r\nimport { CjsSchema } from \"../../schema/index.js\";\r\nimport { CjsCarbonDocument } from \"./CjsCarbonDocument.js\";\r\nimport { resolveHydrationAdapter } from \"../../schema/hydration.js\";\r\n\r\n/** Constructs runtime object graphs from neutral Carbon documents. */\r\nexport class CjsDocumentHydrator\r\n{\r\n /**\r\n * Hydrates every node in a Carbon document through the selected registry and\r\n * adapter.\r\n */\r\n Hydrate(document, options = {})\r\n {\r\n return CjsDocumentHydrator.hydrate(document, options);\r\n }\r\n\r\n /** Hydrates a Carbon document and returns its first root. */\r\n HydrateRoot(document, options = {})\r\n {\r\n return CjsDocumentHydrator.hydrateRoot(document, options);\r\n }\r\n\r\n /** Hydrates a normalized document into constructed runtime objects and roots. */\r\n static hydrate(document, options = {})\r\n {\r\n const normalized = CjsCarbonDocument.normalize(document);\r\n const nodeById = new Map(normalized.nodes.map(node => [node.id, node]));\r\n const instanceById = new Map();\r\n const reports = [];\r\n const adapter = resolveHydrationAdapter(options);\r\n\r\n for (const node of normalized.nodes)\r\n {\r\n instanceById.set(node.id, CjsDocumentHydrator.createNodeTarget(node, options, reports, adapter));\r\n }\r\n\r\n for (const node of normalized.nodes)\r\n {\r\n CjsDocumentHydrator.applyNodeValues(instanceById.get(node.id), node, instanceById, options, adapter);\r\n }\r\n\r\n // Phase 3: every instance is constructed and valued, so references are\r\n // resolved - now let callers run their own post-graph init.\r\n for (const node of normalized.nodes)\r\n {\r\n adapter.finalize(instanceById.get(node.id), { kind: node.kind, node, options });\r\n }\r\n\r\n const roots = normalized.roots.map(root => ({\r\n name: root.name,\r\n value: CjsDocumentHydrator.resolveDocumentValue(root.ref, instanceById, options)\r\n }));\r\n\r\n return {\r\n root: roots[0]?.value ?? null,\r\n roots,\r\n document: normalized,\r\n reports,\r\n get(id)\r\n {\r\n return instanceById.get(Number(id)) || null;\r\n },\r\n getNode(id)\r\n {\r\n return nodeById.get(Number(id)) || null;\r\n }\r\n };\r\n }\r\n\r\n /** Returns the first hydrated root in document order. */\r\n static hydrateRoot(document, options = {})\r\n {\r\n return CjsDocumentHydrator.hydrate(document, options).root;\r\n }\r\n\r\n /**\r\n * Constructs the runtime target appropriate for one normalized document\r\n * node.\r\n */\r\n static createNodeTarget(node, options, reports, adapter)\r\n {\r\n if (adapter)\r\n {\r\n const built = adapter.construct(node.kind, { kind: node.kind, node, options });\r\n if (built !== undefined) return built;\r\n }\r\n\r\n const ClassConstructor = CjsDocumentHydrator.resolveClass(node.kind, options);\r\n if (ClassConstructor)\r\n {\r\n return new ClassConstructor();\r\n }\r\n\r\n throw new TypeError(`No class is registered for hydratable type ${node.kind}.`);\r\n }\r\n\r\n /**\r\n * Applies resolved field values to a constructed node through the hydration\r\n * adapter.\r\n */\r\n static applyNodeValues(target, node, instanceById, options, adapter)\r\n {\r\n const registeredSchema = target?.constructor\r\n ? CjsSchema.getSchema(target.constructor)\r\n : null;\r\n const shape = target?._sourceShape || (registeredSchema?.className ? registeredSchema : null);\r\n const fieldByName = new Map((shape?.fields || []).map(field => [field.name, field]));\r\n const values = {};\r\n\r\n for (const [key, item] of Object.entries(node.fields || {}))\r\n {\r\n if (CjsSchema.isFieldHidden(target?.constructor, key)) continue;\r\n const field = fieldByName.get(key) || null;\r\n values[key] = CjsDocumentHydrator.hydrateFieldValue(item, field, instanceById, options);\r\n }\r\n\r\n // node.raw is enumerable NON-SCHEMA state, and its preservation is this\r\n // deprecated path's documented contract (model-values-interchange.md).\r\n // It is applied by direct assignment AFTER the adapter: a validated\r\n // setter rightly ignores undeclared keys, so raw state is the\r\n // hydrator's own job, exactly as it is for plain fallback carriers.\r\n const rawValues = {};\r\n for (const [key, item] of Object.entries(node.raw || {}))\r\n {\r\n if (CjsSchema.isFieldHidden(target?.constructor, key)) continue;\r\n rawValues[key] = CjsDocumentHydrator.resolveDocumentValue(item, instanceById, options);\r\n }\r\n\r\n const apply = adapter || resolveHydrationAdapter(options);\r\n apply.applyValues(target, values, {\r\n kind: node.kind,\r\n shape,\r\n node,\r\n options,\r\n // The class this hydrator resolved for the kind, asked of the schema:\r\n // does it declare fields to populate? A caller-supplied plain class\r\n // does not, and keeps raw assignment.\r\n declared: CjsSchema.getClassName(CjsDocumentHydrator.resolveClass(node.kind, options)) !== null\r\n });\r\n Object.assign(target, rawValues);\r\n return target;\r\n }\r\n\r\n /** Hydrates one field value according to its schema descriptor. */\r\n static hydrateFieldValue(value, field, instanceById, options)\r\n {\r\n const resolved = CjsDocumentHydrator.resolveDocumentValue(value, instanceById, options);\r\n const descriptor = field?.type || field?.jsType || null;\r\n const kind = descriptor?.kind;\r\n\r\n if ((kind === \"array\" || kind === \"list\") && Array.isArray(resolved)) return resolved;\r\n if ((kind === \"model\" || kind === \"objectRef\" || kind === \"struct\" || kind === \"rawStruct\" || kind === \"unknown\") && resolved && typeof resolved === \"object\") return resolved;\r\n if (CjsDocumentHydrator.isShapeIncompatibleMathArray(resolved, descriptor)) return resolved;\r\n\r\n return descriptor ? normalizeCarbonValue(resolved, descriptor) : resolved;\r\n }\r\n\r\n /** Recursively resolves document references and nested portable values. */\r\n static resolveDocumentValue(value, instanceById, options)\r\n {\r\n if (CjsCarbonDocument.isRef(value))\r\n {\r\n const id = Number(value.$ref);\r\n if (instanceById.has(id)) return instanceById.get(id);\r\n if (options.allowMissingRefs) return null;\r\n throw new TypeError(`CarbonDocument ref ${id} does not exist`);\r\n }\r\n\r\n if (Array.isArray(value)) return value.map(item => CjsDocumentHydrator.resolveDocumentValue(item, instanceById, options));\r\n if (value && typeof value === \"object\")\r\n {\r\n return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, CjsDocumentHydrator.resolveDocumentValue(item, instanceById, options)]));\r\n }\r\n return value;\r\n }\r\n\r\n /** Resolves a node's serialized type through the active class registry. */\r\n static resolveClass(kind, options)\r\n {\r\n const Schema = options.registry || CjsSchema;\r\n return Schema.GetConstructor(kind);\r\n }\r\n\r\n /**\r\n * Reports when source-shape metadata prevents coercion to a declared math\r\n * container.\r\n */\r\n static isShapeIncompatibleMathArray(value, descriptor)\r\n {\r\n const expectedLength = descriptor?.length;\r\n return Array.isArray(value) && Number.isInteger(expectedLength) && value.length !== expectedLength;\r\n }\r\n}\r\n"],"names":["CjsDocumentHydrator","Hydrate","document","options","hydrate","HydrateRoot","hydrateRoot","normalized","CjsCarbonDocument","normalize","nodeById","Map","nodes","map","node","id","instanceById","reports","adapter","resolveHydrationAdapter","set","createNodeTarget","applyNodeValues","get","finalize","kind","roots","root","name","value","resolveDocumentValue","ref","Number","getNode","built","construct","undefined","ClassConstructor","resolveClass","TypeError","target","registeredSchema","constructor","CjsSchema","getSchema","shape","_sourceShape","className","fieldByName","fields","field","values","key","item","Object","entries","isFieldHidden","hydrateFieldValue","rawValues","raw","apply","applyValues","declared","getClassName","assign","resolved","descriptor","type","jsType","Array","isArray","isShapeIncompatibleMathArray","normalizeCarbonValue","isRef","$ref","has","allowMissingRefs","fromEntries","Schema","registry","GetConstructor","expectedLength","length","isInteger"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA;AACO,MAAMA,mBAAmB,CAChC;AACI;AACJ;AACA;AACA;AAC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IsD,KAAK,CAACC,OAAO,CAACzC,KAAK,CAAC,EAAE,OAAOA,KAAK,CAAChB,GAAG,CAACwC,IAAI,IAAIrD,mBAAmB,CAAC8B,oBAAoB,CAACuB,IAAI,EAAErC,YAAY,EAAEb,OAAO,CAAC,CAAC;AACzH,IAAA,IAAI0B,KAAK,IAAI,OAAOA,KAAK,KAAK,QAAQ,EACtC;AACI,MAAA,OAAOyB,MAAM,CAACuB,WAAW,CAACvB,MAAM,CAACC,OAAO,CAAC1B,KAAK,CAAC,CAAChB,GAAG,CAAC,CAAC,CAACuC,GAAG,EAAEC,IAAI,CAAC,KAAK,CAACD,GAAG,EAAEpD,mBAAmB,CAAC8B,oBAAoB,CAACuB,IAAI,EAAErC,YAAY,EAAEb,OAAO,CAAC,CAAC,CAAC,CAAC;AACvJ,IAAA;AACA,IAAA,OAAO0B,KAAK;AAChB,EAAA;;AAEA;AACA,EAAA,OAAOS,YAAYA,CAACb,IAAI,EAAEtB,OAAO,EACjC;AACI,IAAA,MAAM2E,MAAM,GAAG3E,OAAO,CAAC4E,QAAQ,IAAIpC,SAAS;AAC5C,IAAA,OAAOmC,MAAM,CAACE,cAAc,CAACvD,IAAI,CAAC;AACtC,EAAA;;AAEA;AACJ;AACA;AACA;AACI,EAAA,OAAO8C,4BAA4BA,CAAC1C,KAAK,EAAEqC,UAAU,EACrD;AACI,IAAA,MAAMe,cAAc,GAAGf,UAAU,EAAEgB,MAAM;AACzC,IAAA,OAAOb,KAAK,CAACC,OAAO,CAACzC,KAAK,CAAC,IAAIG,MAAM,CAACmD,SAAS,CAACF,cAAc,CAAC,IAAIpD,KAAK,CAACqD,MAAM,KAAKD,cAAc;AACtG,EAAA;AACJ;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defaultValueForCarbonField, coerceCarbonMathInto, coerceCarbonTypedArrayInto, cloneCarbonValue, normalizeCarbonValue
|
|
1
|
+
import { defaultValueForCarbonField, coerceCarbonMathInto, coerceCarbonTypedArrayInto, exportCarbonValue, cloneCarbonValue, normalizeCarbonValue } from './types/carbonTypes.js';
|
|
2
2
|
import { composeNotifyDecorator } from '../compose/notify.js';
|
|
3
3
|
import { cast, composeInterfaceDecorator } from '../compose/interface.js';
|
|
4
4
|
import { createValuesTransport, composeValuesDecorator } from '../compose/values.js';
|
|
@@ -346,6 +346,51 @@ class CjsSchema {
|
|
|
346
346
|
return service ? service.getValues(target, out, options) : CjsSchema.getValuesFromSchema(target, out, options);
|
|
347
347
|
}
|
|
348
348
|
|
|
349
|
+
/**
|
|
350
|
+
* The top-level values rule for from/set: a plain object, or null for "no
|
|
351
|
+
* values".
|
|
352
|
+
*
|
|
353
|
+
* SetValues and from exist for hydration and dehydration, so what arrives
|
|
354
|
+
* at the top is data. A live object there is refused rather than read as
|
|
355
|
+
* a bag: measured before this rule, `X.constructor.from(X)` built a new
|
|
356
|
+
* object that aliased X's children and flattened its Map-held models.
|
|
357
|
+
* Child fields are different - a non-plain value there is a reference, and
|
|
358
|
+
* the field's declared type decides that. The one rule lives here so every
|
|
359
|
+
* entry point asks the same question in the same place.
|
|
360
|
+
*
|
|
361
|
+
* @param {*} values Incoming top-level values.
|
|
362
|
+
* @param {string} label Entry point named in the error.
|
|
363
|
+
* @returns {boolean} False for null (nothing to apply), true for a plain bag.
|
|
364
|
+
* @throws {TypeError} For anything that is not a plain object or null.
|
|
365
|
+
*/
|
|
366
|
+
static assertValues(values, label) {
|
|
367
|
+
if (values === null) return false;
|
|
368
|
+
if (!isPlainObject(values)) {
|
|
369
|
+
throw new TypeError(`${label} requires a plain values object; received ${describeValuesInput(values)}.`);
|
|
370
|
+
}
|
|
371
|
+
return true;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Copies a source's values into a target - the explicit copy helper.
|
|
376
|
+
*
|
|
377
|
+
* The top-level from/set rule refuses a live object as values, so copying
|
|
378
|
+
* one says so here instead: a plain source already IS values, anything
|
|
379
|
+
* else is exported first. Both then go through the target's validated
|
|
380
|
+
* setter, so the target keeps its own identity and in-place buffers. This
|
|
381
|
+
* is a value copy, not Carbon's Copier: no topology is preserved and
|
|
382
|
+
* reference fields carry the source's references across as references.
|
|
383
|
+
*
|
|
384
|
+
* @param {object} target The object receiving the values.
|
|
385
|
+
* @param {object} source A live object or a plain values object.
|
|
386
|
+
* @param {object} [options={}] Population options.
|
|
387
|
+
* @returns {Set<string>|boolean} Changed fields, or a boolean result.
|
|
388
|
+
*/
|
|
389
|
+
static copy(target, source, options = {}) {
|
|
390
|
+
const values = isPlainObject(source) ? source : CjsSchema.getValues(source, {}, options);
|
|
391
|
+
return CjsSchema.setValues(target, values, options);
|
|
392
|
+
}
|
|
393
|
+
|
|
349
394
|
/**
|
|
350
395
|
* Applies a plain value bag to a target through its validated setter.
|
|
351
396
|
*
|
|
@@ -355,6 +400,7 @@ class CjsSchema {
|
|
|
355
400
|
* @returns {Set<string>|boolean} Changed fields, or a boolean result.
|
|
356
401
|
*/
|
|
357
402
|
static setValues(target, values = {}, options = {}) {
|
|
403
|
+
if (!CjsSchema.assertValues(values, "CjsSchema.setValues")) return false;
|
|
358
404
|
const service = CjsSchema.#valuesService;
|
|
359
405
|
return service ? service.setValues(target, values, options) : CjsSchema.setValuesFromSchema(target, values, options);
|
|
360
406
|
}
|
|
@@ -372,18 +418,7 @@ class CjsSchema {
|
|
|
372
418
|
static #statelessTransport = createValuesTransport({
|
|
373
419
|
GetFields: Constructor => getEffectiveFields(Constructor),
|
|
374
420
|
Export: (value, field, options) => exportCarbonValue(value, field.type),
|
|
375
|
-
|
|
376
|
-
// rule the model path applies through its brand (CjsModel.js, the
|
|
377
|
-
// isModelInstance early return). A class off the base carries no brand,
|
|
378
|
-
// so without this a reference field would receive a plain-object copy
|
|
379
|
-
// and shared identity across the graph would silently split.
|
|
380
|
-
Import: (value, field) => {
|
|
381
|
-
if (isLiveSchemaInstance(value)) return value;
|
|
382
|
-
if (Array.isArray(value) && value.some(isLiveSchemaInstance)) {
|
|
383
|
-
return value.map(item => isLiveSchemaInstance(item) ? item : cloneCarbonValue(item));
|
|
384
|
-
}
|
|
385
|
-
return normalizeCarbonValue(value, field.type);
|
|
386
|
-
},
|
|
421
|
+
Import: (value, field) => importDeclaredValue(value, field),
|
|
387
422
|
CoerceInto: (current, incoming, field) => coerceCarbonMathInto(current, incoming, field.type) ?? coerceCarbonTypedArrayInto(current, incoming, field.type),
|
|
388
423
|
IsEquivalent: (a, b) => a === b
|
|
389
424
|
});
|
|
@@ -410,6 +445,7 @@ class CjsSchema {
|
|
|
410
445
|
* @returns {object} The constructed instance.
|
|
411
446
|
*/
|
|
412
447
|
static from(className, values = {}, options = {}) {
|
|
448
|
+
if (!CjsSchema.assertValues(values, "CjsSchema.from")) values = {};
|
|
413
449
|
return CjsSchema.#requireValuesService("from").from(className, values, options);
|
|
414
450
|
}
|
|
415
451
|
|
|
@@ -1225,11 +1261,46 @@ function defineHiddenInheritedFields(Constructor, fieldNames) {
|
|
|
1225
1261
|
}
|
|
1226
1262
|
}
|
|
1227
1263
|
|
|
1228
|
-
//
|
|
1229
|
-
//
|
|
1230
|
-
// and
|
|
1231
|
-
|
|
1232
|
-
|
|
1264
|
+
// The state-free transport's import. A declared REFERENCE field - model or
|
|
1265
|
+
// objectRef, or a list or Map of them - treats a non-plain object as the
|
|
1266
|
+
// reference itself and assigns it, Carbon's IRoot* member (operator ruling,
|
|
1267
|
+
// 2026-09-14). The DECLARED TYPE decides that the field holds references; the
|
|
1268
|
+
// value's class is never inspected. Plain bags, and every other field kind,
|
|
1269
|
+
// import by value exactly as before.
|
|
1270
|
+
function importDeclaredValue(value, field) {
|
|
1271
|
+
const type = field.type;
|
|
1272
|
+
switch (type?.kind) {
|
|
1273
|
+
case "model":
|
|
1274
|
+
case "objectRef":
|
|
1275
|
+
if (isObjectReference(value)) return value;
|
|
1276
|
+
break;
|
|
1277
|
+
case "list":
|
|
1278
|
+
case "array":
|
|
1279
|
+
if (Array.isArray(value) && isReferenceType(type.itemType)) {
|
|
1280
|
+
return value.map(item => isObjectReference(item) ? item : cloneCarbonValue(item));
|
|
1281
|
+
}
|
|
1282
|
+
break;
|
|
1283
|
+
case "map":
|
|
1284
|
+
if (value instanceof Map && isReferenceType(type.valueType)) {
|
|
1285
|
+
return new Map(Array.from(value, ([key, item]) => [key, isObjectReference(item) ? item : cloneCarbonValue(item)]));
|
|
1286
|
+
}
|
|
1287
|
+
break;
|
|
1288
|
+
}
|
|
1289
|
+
return normalizeCarbonValue(value, type);
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
// A declared item type that holds references: a model or objectRef
|
|
1293
|
+
// descriptor, or a bare name registered as a class. "string" and "unknown"
|
|
1294
|
+
// are not registered, so they stay values.
|
|
1295
|
+
function isReferenceType(type) {
|
|
1296
|
+
if (typeof type === "string") return CjsSchema.GetConstructor(type) !== null;
|
|
1297
|
+
return type?.kind === "model" || type?.kind === "objectRef";
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
// Not a values bag: an object that is neither plain, an array nor a typed
|
|
1301
|
+
// array. Asks only what the value is made of, never which class built it.
|
|
1302
|
+
function isObjectReference(value) {
|
|
1303
|
+
return value !== null && typeof value === "object" && !isPlainObject(value) && !Array.isArray(value) && !ArrayBuffer.isView(value);
|
|
1233
1304
|
}
|
|
1234
1305
|
function getEffectiveFields(Constructor) {
|
|
1235
1306
|
const ordered = [];
|
|
@@ -1785,5 +1856,14 @@ function isPlainObject(value) {
|
|
|
1785
1856
|
return Boolean(value) && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype;
|
|
1786
1857
|
}
|
|
1787
1858
|
|
|
1859
|
+
// Names what arrived where a values bag was required, for assertValues' error.
|
|
1860
|
+
function describeValuesInput(value) {
|
|
1861
|
+
if (value === undefined) return "undefined";
|
|
1862
|
+
if (Array.isArray(value)) return "an array";
|
|
1863
|
+
if (typeof value !== "object") return `a ${typeof value}`;
|
|
1864
|
+
const name = value.constructor?.name;
|
|
1865
|
+
return name ? `an instance of ${name}` : "an object without Object.prototype";
|
|
1866
|
+
}
|
|
1867
|
+
|
|
1788
1868
|
export { CJS_CLASS_NAME, CJS_ENUM_NAME, CJS_MODEL_BRAND, CjsSchema };
|
|
1789
1869
|
//# sourceMappingURL=CjsSchema.js.map
|