@carbonenginejs/runtime-resource 0.1.0
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/FORMAT-PROVENANCE.md +135 -0
- package/LICENSE +21 -0
- package/NOTICE +29 -0
- package/README.md +241 -0
- package/dist/CjsMotherLode.js +56 -0
- package/dist/CjsMotherLode.js.map +1 -0
- package/dist/CjsResMan.js +740 -0
- package/dist/CjsResMan.js.map +1 -0
- package/dist/CjsResManQueue.js +214 -0
- package/dist/CjsResManQueue.js.map +1 -0
- package/dist/CjsResource.js +366 -0
- package/dist/CjsResource.js.map +1 -0
- package/dist/CjsResourceSource.js +59 -0
- package/dist/CjsResourceSource.js.map +1 -0
- package/dist/_virtual/_rollupPluginBabelHelpers.js +153 -0
- package/dist/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
- package/dist/format/CjsFormat.js +178 -0
- package/dist/format/CjsFormat.js.map +1 -0
- package/dist/format/CjsResourceProbe.js +269 -0
- package/dist/format/CjsResourceProbe.js.map +1 -0
- package/dist/format/payloadContract.js +173 -0
- package/dist/format/payloadContract.js.map +1 -0
- package/dist/formats/black/CjsBlackFormat.js +272 -0
- package/dist/formats/black/CjsBlackFormat.js.map +1 -0
- package/dist/formats/black/core/CjsBlackBinaryReader.js +153 -0
- package/dist/formats/black/core/CjsBlackBinaryReader.js.map +1 -0
- package/dist/formats/black/core/CjsBlackPropertyReaders.js +382 -0
- package/dist/formats/black/core/CjsBlackPropertyReaders.js.map +1 -0
- package/dist/formats/black/core/CjsBlackReader.js +760 -0
- package/dist/formats/black/core/CjsBlackReader.js.map +1 -0
- package/dist/formats/black/core/CjsBlackSchemaRegistry.js +433 -0
- package/dist/formats/black/core/CjsBlackSchemaRegistry.js.map +1 -0
- package/dist/formats/black/core/black-schema-v1-2026-07-11.json.js +4 -0
- package/dist/formats/black/core/black-schema-v1-2026-07-11.json.js.map +1 -0
- package/dist/formats/black/core/blackConstants.js +7 -0
- package/dist/formats/black/core/blackConstants.js.map +1 -0
- package/dist/formats/black/core/blackDefinitions.js +10 -0
- package/dist/formats/black/core/blackDefinitions.js.map +1 -0
- package/dist/formats/black/core/blackEnums.js +6 -0
- package/dist/formats/black/core/blackEnums.js.map +1 -0
- package/dist/formats/black/core/blackSchema.js +3 -0
- package/dist/formats/black/core/blackSchema.js.map +1 -0
- package/dist/formats/black/core/blackVersion.js +22 -0
- package/dist/formats/black/core/blackVersion.js.map +1 -0
- package/dist/formats/black/core/helpers.js +182 -0
- package/dist/formats/black/core/helpers.js.map +1 -0
- package/dist/formats/black/core/schema.js +4 -0
- package/dist/formats/black/core/schema.js.map +1 -0
- package/dist/formats/black/index.js +2 -0
- package/dist/formats/black/index.js.map +1 -0
- package/dist/formats/bnk/CjsBnkFormat.js +245 -0
- package/dist/formats/bnk/CjsBnkFormat.js.map +1 -0
- package/dist/formats/bnk/core/helpers.js +354 -0
- package/dist/formats/bnk/core/helpers.js.map +1 -0
- package/dist/formats/bnk/core/soundbanksInfo.js +246 -0
- package/dist/formats/bnk/core/soundbanksInfo.js.map +1 -0
- package/dist/formats/bnk/index.js +3 -0
- package/dist/formats/bnk/index.js.map +1 -0
- package/dist/formats/cmf/CjsCmfFormat.js +491 -0
- package/dist/formats/cmf/CjsCmfFormat.js.map +1 -0
- package/dist/formats/cmf/core/binary.js +118 -0
- package/dist/formats/cmf/core/binary.js.map +1 -0
- package/dist/formats/cmf/core/buffers.js +233 -0
- package/dist/formats/cmf/core/buffers.js.map +1 -0
- package/dist/formats/cmf/core/constants.js +47 -0
- package/dist/formats/cmf/core/constants.js.map +1 -0
- package/dist/formats/cmf/core/gr2Anim.js +453 -0
- package/dist/formats/cmf/core/gr2Anim.js.map +1 -0
- package/dist/formats/cmf/core/helpers.js +287 -0
- package/dist/formats/cmf/core/helpers.js.map +1 -0
- package/dist/formats/cmf/core/pack.js +276 -0
- package/dist/formats/cmf/core/pack.js.map +1 -0
- package/dist/formats/cmf/core/schema.js +364 -0
- package/dist/formats/cmf/core/schema.js.map +1 -0
- package/dist/formats/cmf/core/shared.js +268 -0
- package/dist/formats/cmf/core/shared.js.map +1 -0
- package/dist/formats/cmf/core/writer.js +517 -0
- package/dist/formats/cmf/core/writer.js.map +1 -0
- package/dist/formats/cmf/index.js +2 -0
- package/dist/formats/cmf/index.js.map +1 -0
- package/dist/formats/dds/CjsDdsFormat.js +187 -0
- package/dist/formats/dds/CjsDdsFormat.js.map +1 -0
- package/dist/formats/dds/core/helpers.js +812 -0
- package/dist/formats/dds/core/helpers.js.map +1 -0
- package/dist/formats/dds/index.js +2 -0
- package/dist/formats/dds/index.js.map +1 -0
- package/dist/formats/fbx/CjsFbxFormat.js +260 -0
- package/dist/formats/fbx/CjsFbxFormat.js.map +1 -0
- package/dist/formats/fbx/core/helpers.js +3901 -0
- package/dist/formats/fbx/core/helpers.js.map +1 -0
- package/dist/formats/fbx/index.js +2 -0
- package/dist/formats/fbx/index.js.map +1 -0
- package/dist/formats/flac/CjsFlacFormat.js +81 -0
- package/dist/formats/flac/CjsFlacFormat.js.map +1 -0
- package/dist/formats/flac/core/helpers.js +295 -0
- package/dist/formats/flac/core/helpers.js.map +1 -0
- package/dist/formats/flac/index.js +2 -0
- package/dist/formats/flac/index.js.map +1 -0
- package/dist/formats/gif/CjsGifFormat.js +81 -0
- package/dist/formats/gif/CjsGifFormat.js.map +1 -0
- package/dist/formats/gif/core/helpers.js +360 -0
- package/dist/formats/gif/core/helpers.js.map +1 -0
- package/dist/formats/gif/index.js +2 -0
- package/dist/formats/gif/index.js.map +1 -0
- package/dist/formats/gltf/CjsGltfFormat.js +284 -0
- package/dist/formats/gltf/CjsGltfFormat.js.map +1 -0
- package/dist/formats/gltf/core/helpers.js +292 -0
- package/dist/formats/gltf/core/helpers.js.map +1 -0
- package/dist/formats/gltf/core/json.js +79 -0
- package/dist/formats/gltf/core/json.js.map +1 -0
- package/dist/formats/gltf/core/parser.js +666 -0
- package/dist/formats/gltf/core/parser.js.map +1 -0
- package/dist/formats/gltf/core/targets.js +163 -0
- package/dist/formats/gltf/core/targets.js.map +1 -0
- package/dist/formats/gltf/index.js +2 -0
- package/dist/formats/gltf/index.js.map +1 -0
- package/dist/formats/index.js +23 -0
- package/dist/formats/index.js.map +1 -0
- package/dist/formats/jpeg/CjsJpegFormat.js +200 -0
- package/dist/formats/jpeg/CjsJpegFormat.js.map +1 -0
- package/dist/formats/jpeg/core/helpers.js +350 -0
- package/dist/formats/jpeg/core/helpers.js.map +1 -0
- package/dist/formats/jpeg/core/jpeg.js +377 -0
- package/dist/formats/jpeg/core/jpeg.js.map +1 -0
- package/dist/formats/jpeg/index.js +2 -0
- package/dist/formats/jpeg/index.js.map +1 -0
- package/dist/formats/mp3/CjsMp3Format.js +186 -0
- package/dist/formats/mp3/CjsMp3Format.js.map +1 -0
- package/dist/formats/mp3/core/helpers.js +338 -0
- package/dist/formats/mp3/core/helpers.js.map +1 -0
- package/dist/formats/mp3/index.js +2 -0
- package/dist/formats/mp3/index.js.map +1 -0
- package/dist/formats/mp4/CjsMp4Format.js +185 -0
- package/dist/formats/mp4/CjsMp4Format.js.map +1 -0
- package/dist/formats/mp4/core/helpers.js +449 -0
- package/dist/formats/mp4/core/helpers.js.map +1 -0
- package/dist/formats/mp4/index.js +2 -0
- package/dist/formats/mp4/index.js.map +1 -0
- package/dist/formats/obj/CjsObjFormat.js +247 -0
- package/dist/formats/obj/CjsObjFormat.js.map +1 -0
- package/dist/formats/obj/core/helpers.js +573 -0
- package/dist/formats/obj/core/helpers.js.map +1 -0
- package/dist/formats/obj/core/json.js +64 -0
- package/dist/formats/obj/core/json.js.map +1 -0
- package/dist/formats/obj/core/parser.js +321 -0
- package/dist/formats/obj/core/parser.js.map +1 -0
- package/dist/formats/obj/index.js +2 -0
- package/dist/formats/obj/index.js.map +1 -0
- package/dist/formats/ogg/CjsOggFormat.js +82 -0
- package/dist/formats/ogg/CjsOggFormat.js.map +1 -0
- package/dist/formats/ogg/core/helpers.js +387 -0
- package/dist/formats/ogg/core/helpers.js.map +1 -0
- package/dist/formats/ogg/core/imdct.js +178 -0
- package/dist/formats/ogg/core/imdct.js.map +1 -0
- package/dist/formats/ogg/core/vorbis.js +999 -0
- package/dist/formats/ogg/core/vorbis.js.map +1 -0
- package/dist/formats/ogg/index.js +2 -0
- package/dist/formats/ogg/index.js.map +1 -0
- package/dist/formats/png/CjsPngFormat.js +189 -0
- package/dist/formats/png/CjsPngFormat.js.map +1 -0
- package/dist/formats/png/core/helpers.js +583 -0
- package/dist/formats/png/core/helpers.js.map +1 -0
- package/dist/formats/png/index.js +2 -0
- package/dist/formats/png/index.js.map +1 -0
- package/dist/formats/red/CjsRedFormat.js +247 -0
- package/dist/formats/red/CjsRedFormat.js.map +1 -0
- package/dist/formats/red/core/CjsRedReader.js +201 -0
- package/dist/formats/red/core/CjsRedReader.js.map +1 -0
- package/dist/formats/red/core/blackDefinitions.js +3 -0
- package/dist/formats/red/core/blackDefinitions.js.map +1 -0
- package/dist/formats/red/core/helpers.js +136 -0
- package/dist/formats/red/core/helpers.js.map +1 -0
- package/dist/formats/red/core/redGraph.js +68 -0
- package/dist/formats/red/core/redGraph.js.map +1 -0
- package/dist/formats/red/core/schema.js +4 -0
- package/dist/formats/red/core/schema.js.map +1 -0
- package/dist/formats/red/index.js +2 -0
- package/dist/formats/red/index.js.map +1 -0
- package/dist/formats/stl/CjsStlFormat.js +304 -0
- package/dist/formats/stl/CjsStlFormat.js.map +1 -0
- package/dist/formats/stl/core/helpers.js +257 -0
- package/dist/formats/stl/core/helpers.js.map +1 -0
- package/dist/formats/stl/core/json.js +51 -0
- package/dist/formats/stl/core/json.js.map +1 -0
- package/dist/formats/stl/core/stl.js +544 -0
- package/dist/formats/stl/core/stl.js.map +1 -0
- package/dist/formats/stl/core/targets.js +163 -0
- package/dist/formats/stl/core/targets.js.map +1 -0
- package/dist/formats/stl/index.js +2 -0
- package/dist/formats/stl/index.js.map +1 -0
- package/dist/formats/tga/CjsTgaFormat.js +186 -0
- package/dist/formats/tga/CjsTgaFormat.js.map +1 -0
- package/dist/formats/tga/core/helpers.js +446 -0
- package/dist/formats/tga/core/helpers.js.map +1 -0
- package/dist/formats/tga/index.js +2 -0
- package/dist/formats/tga/index.js.map +1 -0
- package/dist/formats/wav/CjsWavFormat.js +186 -0
- package/dist/formats/wav/CjsWavFormat.js.map +1 -0
- package/dist/formats/wav/core/helpers.js +328 -0
- package/dist/formats/wav/core/helpers.js.map +1 -0
- package/dist/formats/wav/index.js +2 -0
- package/dist/formats/wav/index.js.map +1 -0
- package/dist/formats/webm/CjsWebmFormat.js +185 -0
- package/dist/formats/webm/CjsWebmFormat.js.map +1 -0
- package/dist/formats/webm/core/helpers.js +537 -0
- package/dist/formats/webm/core/helpers.js.map +1 -0
- package/dist/formats/webm/index.js +2 -0
- package/dist/formats/webm/index.js.map +1 -0
- package/dist/formats/webp/CjsWebpFormat.js +80 -0
- package/dist/formats/webp/CjsWebpFormat.js.map +1 -0
- package/dist/formats/webp/core/helpers.js +214 -0
- package/dist/formats/webp/core/helpers.js.map +1 -0
- package/dist/formats/webp/index.js +2 -0
- package/dist/formats/webp/index.js.map +1 -0
- package/dist/formats/wem/CjsWemFormat.js +197 -0
- package/dist/formats/wem/CjsWemFormat.js.map +1 -0
- package/dist/formats/wem/core/bitStream.js +259 -0
- package/dist/formats/wem/core/bitStream.js.map +1 -0
- package/dist/formats/wem/core/codebookLibrary.js +164 -0
- package/dist/formats/wem/core/codebookLibrary.js.map +1 -0
- package/dist/formats/wem/core/helpers.js +336 -0
- package/dist/formats/wem/core/helpers.js.map +1 -0
- package/dist/formats/wem/core/packedCodebooksAotuv603.js +30 -0
- package/dist/formats/wem/core/packedCodebooksAotuv603.js.map +1 -0
- package/dist/formats/wem/core/wemToOgg.js +485 -0
- package/dist/formats/wem/core/wemToOgg.js.map +1 -0
- package/dist/formats/wem/index.js +2 -0
- package/dist/formats/wem/index.js.map +1 -0
- package/dist/formats/yaml/CjsYamlFormat.js +77 -0
- package/dist/formats/yaml/CjsYamlFormat.js.map +1 -0
- package/dist/formats/yaml/core/CjsYamlReader.js +304 -0
- package/dist/formats/yaml/core/CjsYamlReader.js.map +1 -0
- package/dist/formats/yaml/core/helpers.js +160 -0
- package/dist/formats/yaml/core/helpers.js.map +1 -0
- package/dist/formats/yaml/index.js +2 -0
- package/dist/formats/yaml/index.js.map +1 -0
- package/dist/generated/resources/AudioGeometryResData.js +47 -0
- package/dist/generated/resources/AudioGeometryResData.js.map +1 -0
- package/dist/generated/resources/CmfVertexReader.js +46 -0
- package/dist/generated/resources/CmfVertexReader.js.map +1 -0
- package/dist/generated/resources/GStateBindingCallbackData.js +31 -0
- package/dist/generated/resources/GStateBindingCallbackData.js.map +1 -0
- package/dist/generated/resources/MeshDecalData.js +37 -0
- package/dist/generated/resources/MeshDecalData.js.map +1 -0
- package/dist/generated/resources/MeshDecalLodData.js +34 -0
- package/dist/generated/resources/MeshDecalLodData.js.map +1 -0
- package/dist/generated/resources/Tr2AsyncSave.js +46 -0
- package/dist/generated/resources/Tr2AsyncSave.js.map +1 -0
- package/dist/generated/resources/Tr2CmfContents.js +37 -0
- package/dist/generated/resources/Tr2CmfContents.js.map +1 -0
- package/dist/generated/resources/Tr2GrannyIntersectionResult.js +58 -0
- package/dist/generated/resources/Tr2GrannyIntersectionResult.js.map +1 -0
- package/dist/generated/resources/Tr2LoadPrepareFence.js +37 -0
- package/dist/generated/resources/Tr2LoadPrepareFence.js.map +1 -0
- package/dist/generated/resources/Tr2MaterialArea.js +34 -0
- package/dist/generated/resources/Tr2MaterialArea.js.map +1 -0
- package/dist/generated/resources/Tr2MaterialMesh.js +31 -0
- package/dist/generated/resources/Tr2MaterialMesh.js.map +1 -0
- package/dist/generated/resources/Tr2MaterialRes.js +34 -0
- package/dist/generated/resources/Tr2MaterialRes.js.map +1 -0
- package/dist/generated/resources/Tr2ShaderPermutation.js +43 -0
- package/dist/generated/resources/Tr2ShaderPermutation.js.map +1 -0
- package/dist/generated/resources/Tr2TextureLodManager.js +60 -0
- package/dist/generated/resources/Tr2TextureLodManager.js.map +1 -0
- package/dist/generated/resources/Tr2TextureLodUpdateRequest.js +37 -0
- package/dist/generated/resources/Tr2TextureLodUpdateRequest.js.map +1 -0
- package/dist/generated/resources/Tr2TexturePackChannel.js +37 -0
- package/dist/generated/resources/Tr2TexturePackChannel.js.map +1 -0
- package/dist/generated/resources/Tr2TexturePipeline.js +44 -0
- package/dist/generated/resources/Tr2TexturePipeline.js.map +1 -0
- package/dist/generated/resources/Tr2TexturePipelineParams.js +34 -0
- package/dist/generated/resources/Tr2TexturePipelineParams.js.map +1 -0
- package/dist/generated/resources/Tr2TexturePipelineStepCompress.js +40 -0
- package/dist/generated/resources/Tr2TexturePipelineStepCompress.js.map +1 -0
- package/dist/generated/resources/Tr2TexturePipelineStepLimitSize.js +34 -0
- package/dist/generated/resources/Tr2TexturePipelineStepLimitSize.js.map +1 -0
- package/dist/generated/resources/Tr2TexturePipelineStepLoad.js +31 -0
- package/dist/generated/resources/Tr2TexturePipelineStepLoad.js.map +1 -0
- package/dist/generated/resources/Tr2TexturePipelineStepPack.js +43 -0
- package/dist/generated/resources/Tr2TexturePipelineStepPack.js.map +1 -0
- package/dist/generated/resources/TriGeometryResAreaData.js +59 -0
- package/dist/generated/resources/TriGeometryResAreaData.js.map +1 -0
- package/dist/generated/resources/TriGeometryResJointData.js +38 -0
- package/dist/generated/resources/TriGeometryResJointData.js.map +1 -0
- package/dist/generated/resources/TriGeometryResLodData.js +88 -0
- package/dist/generated/resources/TriGeometryResLodData.js.map +1 -0
- package/dist/generated/resources/TriGeometryResMeshData.js +63 -0
- package/dist/generated/resources/TriGeometryResMeshData.js.map +1 -0
- package/dist/generated/resources/TriGeometryResSkeletonData.js +34 -0
- package/dist/generated/resources/TriGeometryResSkeletonData.js.map +1 -0
- package/dist/generated/resources/TriJointBinding.js +38 -0
- package/dist/generated/resources/TriJointBinding.js.map +1 -0
- package/dist/generated/resources/TriMorphTargetGeometryConstants.js +46 -0
- package/dist/generated/resources/TriMorphTargetGeometryConstants.js.map +1 -0
- package/dist/generated/resources/TriRtGeometryConstants.js +88 -0
- package/dist/generated/resources/TriRtGeometryConstants.js.map +1 -0
- package/dist/generated/resources/enums.js +18 -0
- package/dist/generated/resources/enums.js.map +1 -0
- package/dist/generated/resources/index.js +32 -0
- package/dist/generated/resources/index.js.map +1 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/resourcePath.js +18 -0
- package/dist/resourcePath.js.map +1 -0
- package/dist/resourceStates.js +9 -0
- package/dist/resourceStates.js.map +1 -0
- package/dist/resources/Tr2EffectRes.js +71 -0
- package/dist/resources/Tr2EffectRes.js.map +1 -0
- package/dist/resources/Tr2GrannyStateRes.js +44 -0
- package/dist/resources/Tr2GrannyStateRes.js.map +1 -0
- package/dist/resources/Tr2ImageRes.js +114 -0
- package/dist/resources/Tr2ImageRes.js.map +1 -0
- package/dist/resources/Tr2LightProfileRes.js +40 -0
- package/dist/resources/Tr2LightProfileRes.js.map +1 -0
- package/dist/resources/TriGeometryRes.js +216 -0
- package/dist/resources/TriGeometryRes.js.map +1 -0
- package/dist/resources/TriGrannyRes.js +43 -0
- package/dist/resources/TriGrannyRes.js.map +1 -0
- package/dist/resources/TriTextureRes.js +304 -0
- package/dist/resources/TriTextureRes.js.map +1 -0
- package/dist/resources/resourceBoundary.js +47 -0
- package/dist/resources/resourceBoundary.js.map +1 -0
- package/dist/texture/CjsTextureArrayRes.js +406 -0
- package/dist/texture/CjsTextureArrayRes.js.map +1 -0
- package/dist/texture/CjsTextureParameterProxy.js +133 -0
- package/dist/texture/CjsTextureParameterProxy.js.map +1 -0
- package/format-notices/black/LICENSE +21 -0
- package/format-notices/black/NOTICE +47 -0
- package/format-notices/bnk/LICENSE +21 -0
- package/format-notices/bnk/NOTICE +17 -0
- package/format-notices/cmf/LICENSE +21 -0
- package/format-notices/cmf/NOTICE +36 -0
- package/format-notices/dds/LICENSE +21 -0
- package/format-notices/dds/NOTICE +14 -0
- package/format-notices/fbx/LICENSE +21 -0
- package/format-notices/fbx/NOTICE +14 -0
- package/format-notices/flac/LICENSE +21 -0
- package/format-notices/flac/NOTICE +14 -0
- package/format-notices/gif/LICENSE +21 -0
- package/format-notices/gif/NOTICE +14 -0
- package/format-notices/gltf/LICENSE +21 -0
- package/format-notices/gltf/NOTICE +27 -0
- package/format-notices/jpeg/LICENSE +21 -0
- package/format-notices/jpeg/NOTICE +14 -0
- package/format-notices/mp3/LICENSE +21 -0
- package/format-notices/mp3/NOTICE +14 -0
- package/format-notices/mp4/LICENSE +21 -0
- package/format-notices/mp4/NOTICE +14 -0
- package/format-notices/obj/LICENSE +21 -0
- package/format-notices/obj/NOTICE +26 -0
- package/format-notices/ogg/LICENSE +21 -0
- package/format-notices/ogg/NOTICE +28 -0
- package/format-notices/png/LICENSE +21 -0
- package/format-notices/png/NOTICE +14 -0
- package/format-notices/red/LICENSE +21 -0
- package/format-notices/red/NOTICE +31 -0
- package/format-notices/stl/LICENSE +21 -0
- package/format-notices/stl/NOTICE +21 -0
- package/format-notices/tga/LICENSE +21 -0
- package/format-notices/tga/NOTICE +14 -0
- package/format-notices/wav/LICENSE +21 -0
- package/format-notices/wav/NOTICE +14 -0
- package/format-notices/webm/LICENSE +21 -0
- package/format-notices/webm/NOTICE +14 -0
- package/format-notices/webp/LICENSE +21 -0
- package/format-notices/webp/NOTICE +14 -0
- package/format-notices/wem/LICENSE +57 -0
- package/format-notices/wem/NOTICE +33 -0
- package/format-notices/yaml/LICENSE +21 -0
- package/format-notices/yaml/NOTICE +44 -0
- package/package.json +51 -0
- package/resource-lifecycle.md +487 -0
|
@@ -0,0 +1,760 @@
|
|
|
1
|
+
import { resolveHydrationAdapter, CjsCarbonDocument, normalizeCarbonTypeDescriptor, CARBON_TYPE, normalizeCarbonValue, CjsSchema } from '@carbonenginejs/core-types';
|
|
2
|
+
import { CJS_BLACK_FOURCC, CJS_BLACK_VERSION, CJS_BLACK_FORMAT_ID } from './blackConstants.js';
|
|
3
|
+
import { CjsBlackBinaryReader } from './CjsBlackBinaryReader.js';
|
|
4
|
+
import { CjsBlackPropertyReaders } from './CjsBlackPropertyReaders.js';
|
|
5
|
+
import { CjsBlackSchemaRegistry } from './CjsBlackSchemaRegistry.js';
|
|
6
|
+
|
|
7
|
+
class CjsBlackReader {
|
|
8
|
+
constructor(input, options = {}) {
|
|
9
|
+
this.options = {
|
|
10
|
+
...options
|
|
11
|
+
};
|
|
12
|
+
this.reader = CjsBlackBinaryReader.from(input, this);
|
|
13
|
+
this.schemaShapes = CjsBlackSchemaRegistry.createShapeMap(options.schema);
|
|
14
|
+
this.references = new Map();
|
|
15
|
+
this.nodes = [];
|
|
16
|
+
this.reports = [];
|
|
17
|
+
this.nextNodeId = 1;
|
|
18
|
+
this.info = null;
|
|
19
|
+
this.readMode = "payload";
|
|
20
|
+
this.payloadDepth = 0;
|
|
21
|
+
this.payloadRootFields = null;
|
|
22
|
+
this.hydrationAdapter = resolveHydrationAdapter(options);
|
|
23
|
+
this.hydrationOptions = {
|
|
24
|
+
...options,
|
|
25
|
+
markDirty: false,
|
|
26
|
+
skipUpdate: true,
|
|
27
|
+
skipEvents: true
|
|
28
|
+
};
|
|
29
|
+
this.runtimeInstances = [];
|
|
30
|
+
}
|
|
31
|
+
Inspect() {
|
|
32
|
+
if (this.info) return this.info;
|
|
33
|
+
const reader = this.reader;
|
|
34
|
+
reader.ExpectU32(CJS_BLACK_FOURCC, "Invalid Black FOURCC");
|
|
35
|
+
const version = reader.ReadU32();
|
|
36
|
+
if (version !== CJS_BLACK_VERSION) {
|
|
37
|
+
throw new RangeError(`Unsupported Black version: ${version}`);
|
|
38
|
+
}
|
|
39
|
+
const strings = CjsBlackReader.readStringTable(reader);
|
|
40
|
+
const wideStrings = CjsBlackReader.readWideStringTable(reader);
|
|
41
|
+
this.info = {
|
|
42
|
+
format: {
|
|
43
|
+
id: CJS_BLACK_FORMAT_ID,
|
|
44
|
+
version
|
|
45
|
+
},
|
|
46
|
+
byteLength: reader.data.byteLength,
|
|
47
|
+
dataOffset: reader.offset,
|
|
48
|
+
strings,
|
|
49
|
+
wideStrings
|
|
50
|
+
};
|
|
51
|
+
return this.info;
|
|
52
|
+
}
|
|
53
|
+
Read() {
|
|
54
|
+
return this.ReadPayload();
|
|
55
|
+
}
|
|
56
|
+
ReadDocument() {
|
|
57
|
+
const info = this.Inspect();
|
|
58
|
+
this.ResetReadState();
|
|
59
|
+
this.readMode = "document";
|
|
60
|
+
this.reader.offset = info.dataOffset;
|
|
61
|
+
const rootRef = this.ReadObject(this.reader);
|
|
62
|
+
if (!CjsCarbonDocument.isRef(rootRef)) {
|
|
63
|
+
throw new TypeError("Black root object is null");
|
|
64
|
+
}
|
|
65
|
+
this.reader.ExpectEnd("Black object graph did not read to end");
|
|
66
|
+
const includeRefIndex = this.ShouldIncludeRefIndex();
|
|
67
|
+
const refs = {};
|
|
68
|
+
if (includeRefIndex) {
|
|
69
|
+
for (const node of this.nodes) {
|
|
70
|
+
refs[String(node.id)] = {
|
|
71
|
+
kind: node.kind
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return CjsCarbonDocument.create({
|
|
76
|
+
format: info.format,
|
|
77
|
+
roots: [{
|
|
78
|
+
name: this.options.rootName || "default",
|
|
79
|
+
ref: rootRef
|
|
80
|
+
}],
|
|
81
|
+
nodes: this.nodes,
|
|
82
|
+
refs: includeRefIndex ? refs : null,
|
|
83
|
+
metadata: this.CreateDocumentMetadata(info),
|
|
84
|
+
reports: this.reports
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
ReadRuntime() {
|
|
88
|
+
const info = this.Inspect();
|
|
89
|
+
this.ResetReadState();
|
|
90
|
+
this.readMode = "runtime";
|
|
91
|
+
this.reader.offset = info.dataOffset;
|
|
92
|
+
const root = this.ReadObject(this.reader);
|
|
93
|
+
if (root === null) {
|
|
94
|
+
throw new TypeError("Black root object is null");
|
|
95
|
+
}
|
|
96
|
+
this.reader.ExpectEnd("Black object graph did not read to end");
|
|
97
|
+
|
|
98
|
+
// Phase 3: the whole graph is constructed and valued (references
|
|
99
|
+
// resolved), so run the adapter's post-graph init once per instance.
|
|
100
|
+
// Instances are collected in completion order, so children finalize
|
|
101
|
+
// before their parents.
|
|
102
|
+
for (const record of this.runtimeInstances) {
|
|
103
|
+
this.hydrationAdapter.finalize(record.instance, {
|
|
104
|
+
kind: record.kind,
|
|
105
|
+
shape: record.shape
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
root,
|
|
110
|
+
format: info.format,
|
|
111
|
+
reports: this.reports
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
ReadPayload() {
|
|
115
|
+
const info = this.Inspect();
|
|
116
|
+
this.ResetReadState();
|
|
117
|
+
this.readMode = "payload";
|
|
118
|
+
this.reader.offset = info.dataOffset;
|
|
119
|
+
const object = this.ReadObject(this.reader);
|
|
120
|
+
if (object === null) {
|
|
121
|
+
throw new TypeError("Black root object is null");
|
|
122
|
+
}
|
|
123
|
+
this.reader.ExpectEnd("Black object graph did not read to end");
|
|
124
|
+
const payload = {
|
|
125
|
+
comments: this.reports,
|
|
126
|
+
object
|
|
127
|
+
};
|
|
128
|
+
if (this.ShouldIncludeDocumentMetadata()) {
|
|
129
|
+
payload.metadata = this.CreateDocumentMetadata(info);
|
|
130
|
+
}
|
|
131
|
+
return payload;
|
|
132
|
+
}
|
|
133
|
+
ReadObject(reader) {
|
|
134
|
+
if (this.readMode === "runtime") return this.ReadRuntimeObject(reader);
|
|
135
|
+
if (this.readMode === "payload") return this.ReadPayloadObject(reader);
|
|
136
|
+
const blackReference = reader.ReadU32();
|
|
137
|
+
if (blackReference === 0) return null;
|
|
138
|
+
const existing = this.references.get(blackReference);
|
|
139
|
+
if (existing) return CjsCarbonDocument.createRef(existing);
|
|
140
|
+
return this.ReadObjectPayload(reader, {
|
|
141
|
+
blackReference,
|
|
142
|
+
embedded: false
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
ReadEmbeddedObject(reader) {
|
|
146
|
+
if (this.readMode === "runtime") return this.ReadRuntimeObjectPayload(reader, {
|
|
147
|
+
blackReference: null,
|
|
148
|
+
embedded: true
|
|
149
|
+
});
|
|
150
|
+
if (this.readMode === "payload") return this.ReadPayloadObjectPayload(reader, {
|
|
151
|
+
blackReference: null,
|
|
152
|
+
embedded: true
|
|
153
|
+
});
|
|
154
|
+
return this.ReadObjectPayload(reader, {
|
|
155
|
+
blackReference: null,
|
|
156
|
+
embedded: true
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
ReadObjectPayload(reader, options) {
|
|
160
|
+
const payloadSize = reader.ReadU32();
|
|
161
|
+
const objectReader = reader.ReadBinaryReader(payloadSize);
|
|
162
|
+
const kind = objectReader.ReadStringRef();
|
|
163
|
+
const shape = this.ResolveSourceShape(kind);
|
|
164
|
+
const includeClassMetadata = this.ShouldIncludeClassMetadata();
|
|
165
|
+
const includeFieldTrace = this.ShouldIncludeFieldTrace();
|
|
166
|
+
const node = {
|
|
167
|
+
id: this.nextNodeId++,
|
|
168
|
+
kind,
|
|
169
|
+
fields: {},
|
|
170
|
+
...(includeClassMetadata ? {
|
|
171
|
+
source: shape?.source || {},
|
|
172
|
+
meta: {
|
|
173
|
+
family: shape?.family || null,
|
|
174
|
+
hashes: shape?.hashes || null,
|
|
175
|
+
blue: shape?.blue || null
|
|
176
|
+
}
|
|
177
|
+
} : {}),
|
|
178
|
+
...(includeFieldTrace ? {
|
|
179
|
+
meta: {
|
|
180
|
+
...(includeClassMetadata ? {
|
|
181
|
+
family: shape?.family || null,
|
|
182
|
+
hashes: shape?.hashes || null,
|
|
183
|
+
blue: shape?.blue || null
|
|
184
|
+
} : {}),
|
|
185
|
+
black: {
|
|
186
|
+
reference: options.blackReference,
|
|
187
|
+
embedded: options.embedded,
|
|
188
|
+
payloadSize,
|
|
189
|
+
fields: {}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
} : {}),
|
|
193
|
+
raw: null
|
|
194
|
+
};
|
|
195
|
+
this.nodes.push(node);
|
|
196
|
+
if (options.blackReference !== null) {
|
|
197
|
+
this.references.set(options.blackReference, node.id);
|
|
198
|
+
}
|
|
199
|
+
let previousBlackName = null;
|
|
200
|
+
while (!objectReader.AtEnd()) {
|
|
201
|
+
const blackName = objectReader.ReadStringRef();
|
|
202
|
+
const target = this.ResolveFieldTargetWithContext(kind, shape, blackName, previousBlackName);
|
|
203
|
+
const value = this.ReadFieldValueWithContext(objectReader, kind, blackName, target);
|
|
204
|
+
this.AssignFieldValue(node, target, value);
|
|
205
|
+
previousBlackName = blackName;
|
|
206
|
+
}
|
|
207
|
+
objectReader.ExpectEnd(`${kind} did not read to end`);
|
|
208
|
+
return CjsCarbonDocument.createRef(node.id);
|
|
209
|
+
}
|
|
210
|
+
ReadRuntimeObject(reader) {
|
|
211
|
+
const blackReference = reader.ReadU32();
|
|
212
|
+
if (blackReference === 0) return null;
|
|
213
|
+
if (this.references.has(blackReference)) {
|
|
214
|
+
return this.references.get(blackReference);
|
|
215
|
+
}
|
|
216
|
+
return this.ReadRuntimeObjectPayload(reader, {
|
|
217
|
+
blackReference,
|
|
218
|
+
embedded: false
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
ReadRuntimeObjectPayload(reader, options) {
|
|
222
|
+
const payloadSize = reader.ReadU32();
|
|
223
|
+
const objectReader = reader.ReadBinaryReader(payloadSize);
|
|
224
|
+
const kind = objectReader.ReadStringRef();
|
|
225
|
+
const shape = this.ResolveSourceShape(kind);
|
|
226
|
+
const target = this.CreateRuntimeTarget(kind, shape);
|
|
227
|
+
if (options.blackReference !== null) {
|
|
228
|
+
this.references.set(options.blackReference, target);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Accumulate this object's fields into a plain values map, then hand
|
|
232
|
+
// the whole map to the hydration adapter. The adapter (default:
|
|
233
|
+
// Object.assign) decides how the caller's class receives its values -
|
|
234
|
+
// direct assignment, SetValues, etc. The target instance is already
|
|
235
|
+
// registered above, so back-references resolve to it while its values
|
|
236
|
+
// are still being collected (the adapter must mutate in place).
|
|
237
|
+
const values = {};
|
|
238
|
+
let previousBlackName = null;
|
|
239
|
+
while (!objectReader.AtEnd()) {
|
|
240
|
+
const blackName = objectReader.ReadStringRef();
|
|
241
|
+
const fieldTarget = this.ResolveFieldTargetWithContext(kind, shape, blackName, previousBlackName);
|
|
242
|
+
const value = this.ReadFieldValueWithContext(objectReader, kind, blackName, fieldTarget);
|
|
243
|
+
this.AssignRuntimeFieldValue(values, fieldTarget, value);
|
|
244
|
+
previousBlackName = blackName;
|
|
245
|
+
}
|
|
246
|
+
objectReader.ExpectEnd(`${kind} did not read to end`);
|
|
247
|
+
this.hydrationAdapter.applyValues(target, values, {
|
|
248
|
+
kind,
|
|
249
|
+
shape,
|
|
250
|
+
options: this.hydrationOptions
|
|
251
|
+
});
|
|
252
|
+
this.runtimeInstances.push({
|
|
253
|
+
instance: target,
|
|
254
|
+
kind,
|
|
255
|
+
shape
|
|
256
|
+
});
|
|
257
|
+
return target;
|
|
258
|
+
}
|
|
259
|
+
ReadPayloadObject(reader) {
|
|
260
|
+
const blackReference = reader.ReadU32();
|
|
261
|
+
if (blackReference === 0) return null;
|
|
262
|
+
if (this.references.has(blackReference)) {
|
|
263
|
+
return this.CreatePayloadReference(this.references.get(blackReference), blackReference);
|
|
264
|
+
}
|
|
265
|
+
return this.ReadPayloadObjectPayload(reader, {
|
|
266
|
+
blackReference,
|
|
267
|
+
embedded: false
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
ReadPayloadObjectPayload(reader, options) {
|
|
271
|
+
const payloadSize = reader.ReadU32();
|
|
272
|
+
const objectReader = reader.ReadBinaryReader(payloadSize);
|
|
273
|
+
const kind = objectReader.ReadStringRef();
|
|
274
|
+
const shape = this.ResolveSourceShape(kind);
|
|
275
|
+
const target = this.CreatePayloadTarget(kind);
|
|
276
|
+
if (options.blackReference !== null) {
|
|
277
|
+
this.references.set(options.blackReference, target);
|
|
278
|
+
}
|
|
279
|
+
this.payloadDepth++;
|
|
280
|
+
try {
|
|
281
|
+
let previousBlackName = null;
|
|
282
|
+
while (!objectReader.AtEnd()) {
|
|
283
|
+
const blackName = objectReader.ReadStringRef();
|
|
284
|
+
const fieldTarget = this.ResolveFieldTargetWithContext(kind, shape, blackName, previousBlackName);
|
|
285
|
+
if (this.ShouldSkipPayloadField(fieldTarget)) {
|
|
286
|
+
this.SkipFieldValue(objectReader, fieldTarget);
|
|
287
|
+
previousBlackName = blackName;
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
const value = this.ReadFieldValueWithContext(objectReader, kind, blackName, fieldTarget);
|
|
291
|
+
this.AssignPayloadFieldValue(target, fieldTarget, value);
|
|
292
|
+
previousBlackName = blackName;
|
|
293
|
+
}
|
|
294
|
+
} finally {
|
|
295
|
+
this.payloadDepth--;
|
|
296
|
+
}
|
|
297
|
+
objectReader.ExpectEnd(`${kind} did not read to end`);
|
|
298
|
+
return target;
|
|
299
|
+
}
|
|
300
|
+
CreateRuntimeTarget(kind, shape) {
|
|
301
|
+
const built = this.hydrationAdapter.construct(kind, {
|
|
302
|
+
kind,
|
|
303
|
+
shape,
|
|
304
|
+
options: this.options
|
|
305
|
+
});
|
|
306
|
+
if (built !== undefined) return built;
|
|
307
|
+
const ClassConstructor = this.ResolveClass(kind);
|
|
308
|
+
if (ClassConstructor) {
|
|
309
|
+
return new ClassConstructor();
|
|
310
|
+
}
|
|
311
|
+
return {
|
|
312
|
+
_sourceClassName: kind,
|
|
313
|
+
_sourceShape: shape || null
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
CreatePayloadTarget(kind) {
|
|
317
|
+
const typeField = this.GetPayloadTypeField();
|
|
318
|
+
return typeField ? {
|
|
319
|
+
[typeField]: kind
|
|
320
|
+
} : {};
|
|
321
|
+
}
|
|
322
|
+
CreateSkippedPayloadTarget() {
|
|
323
|
+
return {};
|
|
324
|
+
}
|
|
325
|
+
CreatePayloadReference(targetObject, blackReference) {
|
|
326
|
+
const idField = this.GetPayloadIdField();
|
|
327
|
+
const referenceField = this.GetPayloadReferenceField();
|
|
328
|
+
if (idField && !Object.hasOwn(targetObject, idField)) {
|
|
329
|
+
targetObject[idField] = blackReference;
|
|
330
|
+
}
|
|
331
|
+
return referenceField ? {
|
|
332
|
+
[referenceField]: blackReference
|
|
333
|
+
} : targetObject;
|
|
334
|
+
}
|
|
335
|
+
GetPayloadTypeField() {
|
|
336
|
+
return this.options.payloadTypeField === false ? null : this.options.payloadTypeField || "_type";
|
|
337
|
+
}
|
|
338
|
+
GetPayloadIdField() {
|
|
339
|
+
return this.options.payloadIdField === false ? null : this.options.payloadIdField || "_id";
|
|
340
|
+
}
|
|
341
|
+
GetPayloadReferenceField() {
|
|
342
|
+
return this.options.payloadReferenceField === false ? null : this.options.payloadReferenceField || "_reference";
|
|
343
|
+
}
|
|
344
|
+
GetPayloadRootFields() {
|
|
345
|
+
if (this.payloadRootFields !== null) return this.payloadRootFields;
|
|
346
|
+
const fields = this.options.payloadRootFields ?? this.options.rootFields ?? null;
|
|
347
|
+
if (!fields) {
|
|
348
|
+
this.payloadRootFields = false;
|
|
349
|
+
return this.payloadRootFields;
|
|
350
|
+
}
|
|
351
|
+
this.payloadRootFields = new Set((Array.isArray(fields) ? fields : [fields]).map(String));
|
|
352
|
+
return this.payloadRootFields;
|
|
353
|
+
}
|
|
354
|
+
ShouldSkipPayloadField(target) {
|
|
355
|
+
if (this.readMode !== "payload" || this.payloadDepth !== 1) return false;
|
|
356
|
+
const rootFields = this.GetPayloadRootFields();
|
|
357
|
+
if (!rootFields) return false;
|
|
358
|
+
const fieldName = target.unknown ? target.blackName : target.field.name;
|
|
359
|
+
return !rootFields.has(fieldName);
|
|
360
|
+
}
|
|
361
|
+
SkipFieldValue(reader, target) {
|
|
362
|
+
if (target.unknown) {
|
|
363
|
+
this.ReadUnknownFieldValue(reader, null, target.blackName);
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
CjsBlackPropertyReaders.skipValue(reader, target.field);
|
|
367
|
+
}
|
|
368
|
+
SkipObject(reader) {
|
|
369
|
+
const blackReference = reader.ReadU32();
|
|
370
|
+
if (blackReference === 0) return;
|
|
371
|
+
if (this.references.has(blackReference)) return;
|
|
372
|
+
this.references.set(blackReference, this.CreateSkippedPayloadTarget());
|
|
373
|
+
this.SkipObjectPayload(reader);
|
|
374
|
+
}
|
|
375
|
+
SkipEmbeddedObject(reader) {
|
|
376
|
+
this.SkipObjectPayload(reader);
|
|
377
|
+
}
|
|
378
|
+
SkipObjectPayload(reader) {
|
|
379
|
+
const payloadSize = reader.ReadU32();
|
|
380
|
+
const objectReader = reader.ReadBinaryReader(payloadSize);
|
|
381
|
+
const kind = objectReader.ReadStringRef();
|
|
382
|
+
const shape = this.ResolveSourceShape(kind);
|
|
383
|
+
while (!objectReader.AtEnd()) {
|
|
384
|
+
const blackName = objectReader.ReadStringRef();
|
|
385
|
+
const fieldTarget = this.ResolveFieldTarget(kind, shape, blackName);
|
|
386
|
+
this.SkipFieldValue(objectReader, fieldTarget);
|
|
387
|
+
}
|
|
388
|
+
objectReader.ExpectEnd(`${kind} did not read to end`);
|
|
389
|
+
}
|
|
390
|
+
ShouldIncludeClassMetadata() {
|
|
391
|
+
return Boolean(this.options.includeClassMetadata || this.options.trace || this.options.debug);
|
|
392
|
+
}
|
|
393
|
+
ShouldIncludeFieldTrace() {
|
|
394
|
+
return Boolean(this.options.includeFieldTrace || this.options.trace || this.options.debug);
|
|
395
|
+
}
|
|
396
|
+
ShouldIncludeDocumentMetadata() {
|
|
397
|
+
return Boolean(this.options.includeMetadata || this.options.trace || this.options.debug || this.options.metadata);
|
|
398
|
+
}
|
|
399
|
+
ShouldIncludeRefIndex() {
|
|
400
|
+
return Boolean(this.options.includeRefIndex || this.options.trace || this.options.debug);
|
|
401
|
+
}
|
|
402
|
+
CreateDocumentMetadata(info) {
|
|
403
|
+
if (!this.ShouldIncludeDocumentMetadata()) return this.options.metadata || null;
|
|
404
|
+
return {
|
|
405
|
+
black: {
|
|
406
|
+
stringCount: info.strings.length,
|
|
407
|
+
wideStringCount: info.wideStrings.length,
|
|
408
|
+
wideStrings: info.wideStrings.slice()
|
|
409
|
+
},
|
|
410
|
+
...(this.options.metadata || {})
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
ResolveFieldTargetWithContext(kind, shape, blackName, previousBlackName = null) {
|
|
414
|
+
try {
|
|
415
|
+
return this.ResolveFieldTarget(kind, shape, blackName);
|
|
416
|
+
} catch (error) {
|
|
417
|
+
error.message = `${kind}.${blackName} after ${previousBlackName || "<start>"}: ${error.message}`;
|
|
418
|
+
throw error;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
ReadFieldValueWithContext(reader, kind, blackName, target) {
|
|
422
|
+
try {
|
|
423
|
+
return target.unknown ? this.ReadUnknownFieldValue(reader, kind, blackName) : CjsBlackPropertyReaders.readValue(reader, target.field);
|
|
424
|
+
} catch (error) {
|
|
425
|
+
error.message = `${kind}.${blackName}: ${error.message}`;
|
|
426
|
+
throw error;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
AssignFieldValue(node, target, value) {
|
|
430
|
+
if (target.unknown) {
|
|
431
|
+
node.raw = node.raw || {};
|
|
432
|
+
node.raw[target.blackName] = value;
|
|
433
|
+
this.AssignFieldTrace(node, target);
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
if (target.indexed) {
|
|
437
|
+
let current = node.fields[target.field.name];
|
|
438
|
+
if (!current || typeof current !== "object" || CjsCarbonDocument.isRef(current)) {
|
|
439
|
+
current = Number.isInteger(target.index) ? [] : {};
|
|
440
|
+
node.fields[target.field.name] = current;
|
|
441
|
+
}
|
|
442
|
+
current[target.key] = value;
|
|
443
|
+
} else {
|
|
444
|
+
node.fields[target.field.name] = value;
|
|
445
|
+
}
|
|
446
|
+
this.AssignFieldTrace(node, target);
|
|
447
|
+
}
|
|
448
|
+
AssignFieldTrace(node, target) {
|
|
449
|
+
if (!this.ShouldIncludeFieldTrace()) return;
|
|
450
|
+
node.meta.black.fields[target.blackName] = {
|
|
451
|
+
field: target.field.name,
|
|
452
|
+
cppName: target.field.cppName || null,
|
|
453
|
+
member: target.member,
|
|
454
|
+
indexed: target.indexed,
|
|
455
|
+
indexToken: target.indexToken,
|
|
456
|
+
key: target.key
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
AssignRuntimeFieldValue(targetObject, target, value) {
|
|
460
|
+
if (target.unknown) {
|
|
461
|
+
targetObject[target.blackName] = value;
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
if (target.indexed) {
|
|
465
|
+
let current = targetObject[target.field.name];
|
|
466
|
+
if (!current || typeof current !== "object") {
|
|
467
|
+
current = Number.isInteger(target.index) ? [] : {};
|
|
468
|
+
targetObject[target.field.name] = current;
|
|
469
|
+
}
|
|
470
|
+
current[target.key] = this.NormalizeRuntimeFieldValue(value, target.field);
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
targetObject[target.field.name] = this.NormalizeRuntimeFieldValue(value, target.field);
|
|
474
|
+
}
|
|
475
|
+
AssignPayloadFieldValue(targetObject, target, value) {
|
|
476
|
+
if (target.unknown) {
|
|
477
|
+
targetObject[target.blackName] = value;
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
if (target.indexed) {
|
|
481
|
+
let current = targetObject[target.field.name];
|
|
482
|
+
if (!current || typeof current !== "object") {
|
|
483
|
+
current = Number.isInteger(target.index) ? [] : {};
|
|
484
|
+
targetObject[target.field.name] = current;
|
|
485
|
+
}
|
|
486
|
+
current[target.key] = value;
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
targetObject[target.field.name] = value;
|
|
490
|
+
}
|
|
491
|
+
NormalizeRuntimeFieldValue(value, field) {
|
|
492
|
+
if (!field) return value;
|
|
493
|
+
|
|
494
|
+
// In runtime mode, object-graph fields already hold constructed class
|
|
495
|
+
// instances (or arrays/dicts of them) produced by ReadObject. Passing
|
|
496
|
+
// those back through normalizeCarbonValue would deep-clone and flatten
|
|
497
|
+
// them into plain objects, dropping the constructed classes. Preserve
|
|
498
|
+
// them - matching CjsDocumentHydrator.hydrateFieldValue - and only
|
|
499
|
+
// normalize scalar/math leaf values.
|
|
500
|
+
const descriptor = normalizeCarbonTypeDescriptor(field);
|
|
501
|
+
const kind = descriptor.kind;
|
|
502
|
+
if (kind === CARBON_TYPE.ARRAY && Array.isArray(value)) return value;
|
|
503
|
+
if ((kind === CARBON_TYPE.OBJECT_REF || kind === CARBON_TYPE.STRUCT || kind === CARBON_TYPE.RAW_STRUCT || kind === CARBON_TYPE.UNKNOWN) && value && typeof value === "object") {
|
|
504
|
+
return value;
|
|
505
|
+
}
|
|
506
|
+
if (CjsBlackReader.isShapeIncompatibleMathArray(value, descriptor)) return value;
|
|
507
|
+
return normalizeCarbonValue(value, field);
|
|
508
|
+
}
|
|
509
|
+
ResolveFieldTarget(kind, shape, blackName) {
|
|
510
|
+
if (!shape) {
|
|
511
|
+
throw new TypeError(`No source shape registered for Black type ${kind}`);
|
|
512
|
+
}
|
|
513
|
+
const fields = shape.fields || [];
|
|
514
|
+
const blackField = (shape.black?.fields || []).find(item => CjsBlackSchemaRegistry.matchesBlackFieldName(item, blackName));
|
|
515
|
+
if (blackField) {
|
|
516
|
+
return this.ResolveBlackFieldTarget(blackName, blackField, fields);
|
|
517
|
+
}
|
|
518
|
+
const field = fields.find(item => item.name === blackName || item.cppName === blackName);
|
|
519
|
+
if (field) {
|
|
520
|
+
return {
|
|
521
|
+
blackName,
|
|
522
|
+
field,
|
|
523
|
+
member: blackName,
|
|
524
|
+
indexed: false,
|
|
525
|
+
indexToken: null,
|
|
526
|
+
index: null,
|
|
527
|
+
key: null
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
const indexed = CjsBlackReader.parseIndexedMember(blackName);
|
|
531
|
+
if (indexed) {
|
|
532
|
+
const indexedField = fields.find(item => item.cppName === indexed.member || item.name === CjsBlackReader.toJsFieldName(indexed.member));
|
|
533
|
+
if (indexedField) {
|
|
534
|
+
const key = CjsBlackReader.normalizeIndexedKey(indexed.indexToken, indexedField);
|
|
535
|
+
return {
|
|
536
|
+
blackName,
|
|
537
|
+
field: indexedField,
|
|
538
|
+
member: blackName,
|
|
539
|
+
indexed: true,
|
|
540
|
+
indexToken: indexed.indexToken,
|
|
541
|
+
index: Number.isInteger(key) ? key : null,
|
|
542
|
+
key
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
if (this.ShouldCaptureUnknownField(blackName, kind, shape)) {
|
|
547
|
+
return this.ResolveUnknownFieldTarget(kind, shape, blackName);
|
|
548
|
+
}
|
|
549
|
+
throw new TypeError(`Unknown Black property ${blackName} for ${kind}`);
|
|
550
|
+
}
|
|
551
|
+
ReadUnknownFieldValue(reader, kind, blackName) {
|
|
552
|
+
const readers = this.GetUnknownFieldReaders(blackName);
|
|
553
|
+
const errors = [];
|
|
554
|
+
for (const readValue of readers) {
|
|
555
|
+
const startOffset = reader.offset;
|
|
556
|
+
try {
|
|
557
|
+
return readValue(reader);
|
|
558
|
+
} catch (error) {
|
|
559
|
+
reader.offset = startOffset;
|
|
560
|
+
errors.push(error);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
this.reports.push({
|
|
564
|
+
level: "warning",
|
|
565
|
+
code: "unknown-black-property-unreadable",
|
|
566
|
+
kind,
|
|
567
|
+
blackName
|
|
568
|
+
});
|
|
569
|
+
throw errors[0] || new TypeError(`Unable to read unknown Black field ${blackName} for ${kind}`);
|
|
570
|
+
}
|
|
571
|
+
GetUnknownFieldReaders(blackName) {
|
|
572
|
+
const readers = [];
|
|
573
|
+
const readByKind = (kind, options = null) => {
|
|
574
|
+
const field = options ? {
|
|
575
|
+
...options,
|
|
576
|
+
kind
|
|
577
|
+
} : {
|
|
578
|
+
kind
|
|
579
|
+
};
|
|
580
|
+
readers.push(streamReader => CjsBlackPropertyReaders.readValue(streamReader, field));
|
|
581
|
+
};
|
|
582
|
+
const readByDescriptor = (descriptor = {}) => {
|
|
583
|
+
readers.push(streamReader => CjsBlackPropertyReaders.readValue(streamReader, descriptor));
|
|
584
|
+
};
|
|
585
|
+
if (this.options.allowUnknownStringFallback) {
|
|
586
|
+
readByKind("string");
|
|
587
|
+
readByKind("path");
|
|
588
|
+
}
|
|
589
|
+
const name = String(blackName || "");
|
|
590
|
+
if (name.endsWith(".dds") || name.endsWith(".png") || name.endsWith(".jpg") || /^res:\//.test(name)) {
|
|
591
|
+
readers.unshift(streamReader => CjsBlackPropertyReaders.readValue(streamReader, {
|
|
592
|
+
kind: "path"
|
|
593
|
+
}));
|
|
594
|
+
readByKind("uint32");
|
|
595
|
+
readByKind("float32");
|
|
596
|
+
}
|
|
597
|
+
if (!this.options.allowUnknownStringFallback) {
|
|
598
|
+
readByKind("path");
|
|
599
|
+
readByKind("string");
|
|
600
|
+
}
|
|
601
|
+
readByKind("objectRef");
|
|
602
|
+
readByKind("boolean");
|
|
603
|
+
readByKind("float32");
|
|
604
|
+
readByKind("float64");
|
|
605
|
+
readByKind("int32");
|
|
606
|
+
readByKind("uint32");
|
|
607
|
+
readByKind("int16");
|
|
608
|
+
readByKind("uint16");
|
|
609
|
+
readByKind("int8");
|
|
610
|
+
readByKind("uint8");
|
|
611
|
+
readByDescriptor({
|
|
612
|
+
kind: "vector3"
|
|
613
|
+
});
|
|
614
|
+
readByDescriptor({
|
|
615
|
+
kind: "vector4"
|
|
616
|
+
});
|
|
617
|
+
readByDescriptor({
|
|
618
|
+
kind: "array",
|
|
619
|
+
elementType: {
|
|
620
|
+
kind: "uint32"
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
return readers;
|
|
624
|
+
}
|
|
625
|
+
ResolveBlackFieldTarget(blackName, blackField, fields) {
|
|
626
|
+
const sourceField = fields.find(item => item.name === blackField.fieldName || item.name === blackField.name || item.cppName === blackField.cppName || item.cppName === blackField.memberPath || item.cppName === blackField.memberRoot);
|
|
627
|
+
const fieldName = blackField.fieldName || sourceField?.name || blackField.name || CjsBlackReader.toJsFieldName(blackName);
|
|
628
|
+
Boolean(blackField.name && blackField.name !== blackField.fieldName);
|
|
629
|
+
const field = {
|
|
630
|
+
...(sourceField || {}),
|
|
631
|
+
name: fieldName,
|
|
632
|
+
cppName: blackField.cppName || sourceField?.cppName || null,
|
|
633
|
+
cppType: blackField.cppType || sourceField?.cppType || null,
|
|
634
|
+
black: blackField
|
|
635
|
+
};
|
|
636
|
+
const hasIndex = Boolean(blackField.indexToken || blackField.indexKey !== undefined);
|
|
637
|
+
const storageKey = hasIndex ? blackField.indexKey ?? CjsBlackReader.normalizeIndexedKey(blackField.indexToken, field) : null;
|
|
638
|
+
const indexed = Boolean(hasIndex);
|
|
639
|
+
return {
|
|
640
|
+
blackName,
|
|
641
|
+
field,
|
|
642
|
+
member: blackField.member || blackName,
|
|
643
|
+
indexed,
|
|
644
|
+
indexToken: blackField.indexToken || null,
|
|
645
|
+
index: Number.isInteger(storageKey) ? storageKey : null,
|
|
646
|
+
key: storageKey
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
ResolveUnknownFieldTarget(_kind, _shape, blackName) {
|
|
650
|
+
return {
|
|
651
|
+
blackName,
|
|
652
|
+
field: {
|
|
653
|
+
name: "__blackUnknown",
|
|
654
|
+
cppName: null,
|
|
655
|
+
cppType: null,
|
|
656
|
+
black: {
|
|
657
|
+
fieldName: "__blackUnknown",
|
|
658
|
+
name: blackName,
|
|
659
|
+
memberPath: blackName,
|
|
660
|
+
memberRoot: blackName,
|
|
661
|
+
beType: "UNKNOWN"
|
|
662
|
+
}
|
|
663
|
+
},
|
|
664
|
+
member: blackName,
|
|
665
|
+
indexed: false,
|
|
666
|
+
indexToken: null,
|
|
667
|
+
index: null,
|
|
668
|
+
key: blackName,
|
|
669
|
+
unknown: true
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
ShouldCaptureUnknownField(blackName, _kind, shape) {
|
|
673
|
+
if (this.options.captureUnknownBlackFields) return true;
|
|
674
|
+
if (this.options.captureUnknownResourceFields && /^res:\//.test(String(blackName || ""))) return true;
|
|
675
|
+
if (this.options.captureUnknownWhenNoBlackFields && (!shape?.black || !shape.black.fields || !shape.black.fields.length)) return true;
|
|
676
|
+
return false;
|
|
677
|
+
}
|
|
678
|
+
ResolveSourceShape(kind) {
|
|
679
|
+
const registry = this.options.registry || null;
|
|
680
|
+
if (registry?.GetSourceShape) return registry.GetSourceShape(kind);
|
|
681
|
+
const sourceShapes = this.options.sourceShapes || null;
|
|
682
|
+
if (sourceShapes?.GetSourceShape) return sourceShapes.GetSourceShape(kind);
|
|
683
|
+
if (sourceShapes) {
|
|
684
|
+
const shape = sourceShapes instanceof Map ? sourceShapes.get(kind) : sourceShapes[kind];
|
|
685
|
+
if (shape) return CjsBlackSchemaRegistry.normalizeShape(shape);
|
|
686
|
+
}
|
|
687
|
+
return this.schemaShapes.get(kind) || null;
|
|
688
|
+
}
|
|
689
|
+
ResolveClass(kind) {
|
|
690
|
+
const classes = this.options.classes || {};
|
|
691
|
+
const Schema = this.options.registry || CjsSchema;
|
|
692
|
+
return classes[kind] || Schema.GetConstructor(kind);
|
|
693
|
+
}
|
|
694
|
+
ResetReadState() {
|
|
695
|
+
this.references = new Map();
|
|
696
|
+
this.nodes = [];
|
|
697
|
+
this.reports = [];
|
|
698
|
+
this.nextNodeId = this.options.firstId || 1;
|
|
699
|
+
this.payloadDepth = 0;
|
|
700
|
+
this.payloadRootFields = null;
|
|
701
|
+
this.runtimeInstances = [];
|
|
702
|
+
}
|
|
703
|
+
TransformPath(value) {
|
|
704
|
+
const handler = this.options.pathHandler;
|
|
705
|
+
return typeof handler === "function" ? handler(value) : value;
|
|
706
|
+
}
|
|
707
|
+
static readStringTable(reader) {
|
|
708
|
+
const stringsReader = reader.ReadBinaryReader(reader.ReadU32());
|
|
709
|
+
const count = stringsReader.ReadU16();
|
|
710
|
+
const strings = [];
|
|
711
|
+
for (let i = 0; i < count; i++) {
|
|
712
|
+
strings[i] = stringsReader.ReadCString();
|
|
713
|
+
}
|
|
714
|
+
stringsReader.ExpectEnd("Black string table did not read to end");
|
|
715
|
+
return strings;
|
|
716
|
+
}
|
|
717
|
+
static readWideStringTable(reader) {
|
|
718
|
+
const wideStringsReader = reader.ReadBinaryReader(reader.ReadU32());
|
|
719
|
+
const count = wideStringsReader.ReadU16();
|
|
720
|
+
const wideStrings = [];
|
|
721
|
+
for (let i = 0; i < count; i++) {
|
|
722
|
+
wideStrings[i] = wideStringsReader.ReadCWString();
|
|
723
|
+
}
|
|
724
|
+
wideStringsReader.ExpectEnd("Black wide string table did not read to end");
|
|
725
|
+
return wideStrings;
|
|
726
|
+
}
|
|
727
|
+
static normalizeIndexedKey(indexToken, field) {
|
|
728
|
+
const number = Number(indexToken);
|
|
729
|
+
if (Number.isInteger(number) && String(indexToken).trim() === String(number)) return number;
|
|
730
|
+
let text = String(indexToken || "").trim();
|
|
731
|
+
text = text.replace(/^.*::/, "");
|
|
732
|
+
text = text.replace(/^TYPE_/, "");
|
|
733
|
+
const pascal = text.split(/[^A-Za-z0-9]+/).filter(Boolean).map(part => CJS_BLACK_INDEX_TOKEN_NAMES[part] || (part === "FX" ? "FX" : part.charAt(0).toUpperCase() + part.slice(1).toLowerCase())).join("");
|
|
734
|
+
if (field?.jsType?.kind === "objectRef") {
|
|
735
|
+
return pascal ? pascal.charAt(0).toLowerCase() + pascal.slice(1) : text;
|
|
736
|
+
}
|
|
737
|
+
return pascal || text;
|
|
738
|
+
}
|
|
739
|
+
static parseIndexedMember(value) {
|
|
740
|
+
const match = String(value || "").match(/^(.+)\[([^\]]+)\]$/);
|
|
741
|
+
if (!match) return null;
|
|
742
|
+
return {
|
|
743
|
+
member: match[1],
|
|
744
|
+
indexToken: match[2]
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
static toJsFieldName(value) {
|
|
748
|
+
return String(value || "").replace(/^m_/, "");
|
|
749
|
+
}
|
|
750
|
+
static isShapeIncompatibleMathArray(value, descriptor) {
|
|
751
|
+
const expectedLength = descriptor?.length;
|
|
752
|
+
return Array.isArray(value) && Number.isInteger(expectedLength) && value.length !== expectedLength;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
const CJS_BLACK_INDEX_TOKEN_NAMES = Object.freeze({
|
|
756
|
+
SIMPLEPRIMARY: "SimplePrimary"
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
export { CjsBlackReader };
|
|
760
|
+
//# sourceMappingURL=CjsBlackReader.js.map
|