@forgeax/engine-import 0.1.2

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.
Files changed (75) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +226 -0
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/__tests__/decode-image-owner.test-d.d.ts +2 -0
  5. package/dist/__tests__/decode-image-owner.test-d.d.ts.map +1 -0
  6. package/dist/__tests__/import-contract-migration.test.d.ts +2 -0
  7. package/dist/__tests__/import-contract-migration.test.d.ts.map +1 -0
  8. package/dist/__tests__/import-dependencies.test.d.ts +2 -0
  9. package/dist/__tests__/import-dependencies.test.d.ts.map +1 -0
  10. package/dist/__tests__/import-finalizer-digest-retry.test.d.ts +2 -0
  11. package/dist/__tests__/import-finalizer-digest-retry.test.d.ts.map +1 -0
  12. package/dist/__tests__/import-local-artifacts.test.d.ts +2 -0
  13. package/dist/__tests__/import-local-artifacts.test.d.ts.map +1 -0
  14. package/dist/__tests__/import.unit.test.d.ts +2 -0
  15. package/dist/__tests__/import.unit.test.d.ts.map +1 -0
  16. package/dist/__tests__/material-import-product.unit.test.d.ts +2 -0
  17. package/dist/__tests__/material-import-product.unit.test.d.ts.map +1 -0
  18. package/dist/__tests__/mesh-bin-contract.test.d.ts +2 -0
  19. package/dist/__tests__/mesh-bin-contract.test.d.ts.map +1 -0
  20. package/dist/__tests__/mesh-bin-morph-v3.test.d.ts +2 -0
  21. package/dist/__tests__/mesh-bin-morph-v3.test.d.ts.map +1 -0
  22. package/dist/__tests__/mesh-bin.test.d.ts +2 -0
  23. package/dist/__tests__/mesh-bin.test.d.ts.map +1 -0
  24. package/dist/__tests__/scriptable-pack-output-producers.unit.test.d.ts +2 -0
  25. package/dist/__tests__/scriptable-pack-output-producers.unit.test.d.ts.map +1 -0
  26. package/dist/__tests__/scriptable-pack-production-producers.unit.test.d.ts +2 -0
  27. package/dist/__tests__/scriptable-pack-production-producers.unit.test.d.ts.map +1 -0
  28. package/dist/__tests__/scriptable-pack-staged-snapshot.unit.test.d.ts +2 -0
  29. package/dist/__tests__/scriptable-pack-staged-snapshot.unit.test.d.ts.map +1 -0
  30. package/dist/__tests__/scriptable-pack.integration.test.d.ts +2 -0
  31. package/dist/__tests__/scriptable-pack.integration.test.d.ts.map +1 -0
  32. package/dist/__tests__/source-overrides-import-context.unit.test.d.ts +2 -0
  33. package/dist/__tests__/source-overrides-import-context.unit.test.d.ts.map +1 -0
  34. package/dist/import-product.d.ts +36 -0
  35. package/dist/import-product.d.ts.map +1 -0
  36. package/dist/import-runner.d.ts +133 -0
  37. package/dist/import-runner.d.ts.map +1 -0
  38. package/dist/importer-registry.d.ts +40 -0
  39. package/dist/importer-registry.d.ts.map +1 -0
  40. package/dist/index.d.ts +10 -0
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/index.mjs +1607 -0
  43. package/dist/index.mjs.map +1 -0
  44. package/dist/mesh-bin.d.ts +19 -0
  45. package/dist/mesh-bin.d.ts.map +1 -0
  46. package/dist/scriptable-pack-output-producers.d.ts +6 -0
  47. package/dist/scriptable-pack-output-producers.d.ts.map +1 -0
  48. package/dist/scriptable-pack-staged-snapshot.d.ts +22 -0
  49. package/dist/scriptable-pack-staged-snapshot.d.ts.map +1 -0
  50. package/dist/scriptable-pack.d.ts +153 -0
  51. package/dist/scriptable-pack.d.ts.map +1 -0
  52. package/package.json +63 -0
  53. package/src/__tests__/decode-image-owner.test-d.ts +53 -0
  54. package/src/__tests__/import-contract-migration.test.ts +190 -0
  55. package/src/__tests__/import-dependencies.test.ts +65 -0
  56. package/src/__tests__/import-finalizer-digest-retry.test.ts +113 -0
  57. package/src/__tests__/import-local-artifacts.test.ts +100 -0
  58. package/src/__tests__/import.unit.test.ts +429 -0
  59. package/src/__tests__/material-import-product.unit.test.ts +56 -0
  60. package/src/__tests__/mesh-bin-contract.test.ts +95 -0
  61. package/src/__tests__/mesh-bin-morph-v3.test.ts +44 -0
  62. package/src/__tests__/mesh-bin.test.ts +102 -0
  63. package/src/__tests__/scriptable-pack-output-producers.unit.test.ts +190 -0
  64. package/src/__tests__/scriptable-pack-production-producers.unit.test.ts +429 -0
  65. package/src/__tests__/scriptable-pack-staged-snapshot.unit.test.ts +258 -0
  66. package/src/__tests__/scriptable-pack.integration.test.ts +435 -0
  67. package/src/__tests__/source-overrides-import-context.unit.test.ts +92 -0
  68. package/src/import-product.ts +195 -0
  69. package/src/import-runner.ts +720 -0
  70. package/src/importer-registry.ts +80 -0
  71. package/src/index.ts +103 -0
  72. package/src/mesh-bin.ts +229 -0
  73. package/src/scriptable-pack-output-producers.ts +466 -0
  74. package/src/scriptable-pack-staged-snapshot.ts +161 -0
  75. package/src/scriptable-pack.ts +615 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,226 @@
1
+ # @forgeax/engine-import
2
+
3
+ ## Authoring and recovery index
4
+
5
+ ScriptablePack sources use the public `@forgeax/engine-import` producer bridge.
6
+ The output is the same Pack v2 durable payload used by ordinary importers. The
7
+ 16 `SCRIPTABLE_PACK_ASSET_KINDS` are `mesh`, `material`, `scene`, `texture`,
8
+ `equirect`, `sampler`, `font`, `render-pipeline`, `tileset`, `video`,
9
+ `skeleton`, `skin`, `animation-clip`, `animation-graph`, `audio`, and
10
+ `particle-effect`; all are loadable by GUID, while `refs`,
11
+ `artifacts`, `mediaType`, and `programFingerprint` remain producer facts.
12
+ Producer or dependency failures return `code`, `expected`, `hint`, and
13
+ `detail`; inspect the owning evidence, rebuild or cold-cook, and retry.
14
+
15
+ The import contract is [`asset-authority.schema.json`](../../asset-authority.schema.json). `ImporterRegistry` and `runImport` are the build-time owner for external source plus Meta; every writable multi-output declaration uses a stable `sourceKey`, while `sourceIndex` remains diagnostic evidence only.
16
+
17
+ | Need | Entry | Boundary |
18
+ |:--|:--|:--|
19
+ | Inspect producer evidence | Pack CLI `lookup` and `verify` JSON output | Read Catalog and receipt facts; do not parse messages |
20
+ | Rebuild | Registered importer through `runImport` | Write Pack/DDC output through the shared finalizer |
21
+ | Recover failed output | Fix source or Meta, then cold cook | Never return raw source as a runtime projection |
22
+ | Preview old output | Explicit Catalog last-known-good locator | Read-only preview; not current and not publishable |
23
+
24
+ The Importer owns neither DDC lifecycle nor Editor authoring writes. Editor writes go through its asset-authoring gateway, and runtime consumes the validated projection.
25
+
26
+ Build-time asset **import** runner + `ImporterRegistry` — the build-time half of
27
+ the engine's import/load split.
28
+
29
+ > [!IMPORTANT]
30
+ > **Build-time only.** This package never enters the player runtime bundle
31
+ > (AC-06). `@forgeax/engine-runtime` and `@forgeax/engine-app` do not depend on
32
+ > it. Its consumers are build tooling (the Vite pack plugin, the asset CLI).
33
+
34
+ ## The DIP (dependency-inversion principle) shape
35
+
36
+ This is the engine's **third DIP instance** after RHI and Console. The engine
37
+ owns the contract (`Importer` / `ImportContext` / `ImportTransport` in
38
+ `@forgeax/engine-types`); concrete importers are injected by the host.
39
+
40
+ ```ts
41
+ // Host assembly (vite.config.ts or build script)
42
+ import { pluginPack } from '@forgeax/engine-vite-plugin-pack';
43
+ import { gltfImporter } from '@forgeax/engine-gltf';
44
+ import { imageImporter } from '@forgeax/engine-image/image-importer';
45
+
46
+ export default {
47
+ plugins: [
48
+ pluginPack({
49
+ importers: [gltfImporter, imageImporter],
50
+ }),
51
+ ],
52
+ };
53
+ ```
54
+
55
+ ### Three iron laws (architecture invariants)
56
+
57
+ 1. **GUID import-stable**. The `*.meta.json` sidecar pins every target GUID at
58
+ declare time. Import only reproduces those GUIDs, never mints new ones.
59
+ 2. **Lazy**. The runtime reads meta only to build a *catalog* (which GUIDs
60
+ exist, with which `kind`). Only a real `AssetRegistry.load(guid, kind)` triggers import
61
+ (when the DDC is absent) + load. No eager full-import on startup.
62
+ 3. **One-way dependency**. The engine owns the `Importer` interface; concrete
63
+ importers are injected. The engine never reverse-imports `gltfImporter` /
64
+ `imageImporter` / etc.
65
+
66
+ ## The import/load split
67
+
68
+ ```mermaid
69
+ flowchart LR
70
+ src["source\n(.gltf / .png / .ttf)"] -->|"importer.import(ctx)"| ia["ImportedAsset[]\n(Asset PODs + GUIDs)"]
71
+ meta["*.meta.json\nimporter + subAssets[].guid"] --> ia
72
+ ia -->|"import runner\n(GUID iron law)"| ddc["DDC\n.pack.json / .bin"]
73
+ ddc -->|"AssetRegistry.load(guid, kind)"| runtime["runtime Loader\n(@forgeax/engine-assets-runtime)"]
74
+ ```
75
+
76
+ - An **`Importer`** (`{ key, import }`) turns one external source + its
77
+ `*.meta.json` GUID declarations into in-memory `ImportedAsset[]` PODs. It is
78
+ pure of disk write + GUID minting — it reads the GUIDs declared in the meta
79
+ (the **GUID import-stable iron law**) and stamps them onto the PODs.
80
+ - The **import runner** (`runImport(meta, registry, fs)`) dispatches a sidecar
81
+ by its top-level `importer` string key to the registered `Importer`,
82
+ validates the produced GUID set against the declared set, and folds the
83
+ result into a DDC `.pack.json` document. The reserved key **`importer:
84
+ 'shader'`** is skipped — shader sidecars are consumed by
85
+ `@forgeax/engine-vite-plugin-shader`'s orthogonal transform pipeline.
86
+ - **`ImportTransport`** (interface in `@forgeax/engine-types`) bridges the
87
+ build-time importer to the runtime: the shipped form wires `null` transport
88
+ (pre-import at build time, DDC miss -> fail-fast `asset-not-imported`); the
89
+ studio form wires an HTTP adapter (`POST /__import/:guid`) for lazy on-demand
90
+ import.
91
+
92
+ ## Injection shape
93
+
94
+ ### ScriptablePack build bridge
95
+
96
+ `buildScriptablePack` decorates a host-provided Asset snapshot source with the ordinary `AssetReader`. Each GUID is fixed to one generation/digest and cloned for the current Build. The adapter validates the exact output-key/kind closure, stamps descriptor identity, dispatches each Asset to the reusable `AssetOutputProducerRegistry`, and derives external usage from actual reads plus serialized refs.
97
+
98
+ | Derived usage | Input fingerprint | Runtime ref |
99
+ |:--|:--|:--|
100
+ | `content` | Asset generation and digest | No |
101
+ | `reference` | GUID only | Yes |
102
+ | `both` | Asset generation and digest | Yes |
103
+
104
+ Domain producers return structured `ImportError`; the generic bridge contains no per-kind switch. `createStandardAssetOutputProducerRegistry()` composes the production Scene, Material, and Mesh owners. Scene refs use the ECS externalization kernel shared with runtime save, Material refs cover parent/texture/sampler GUIDs, and Mesh emits the versioned binary artifact. The fingerprint covers canonical Meta, the recursive source closure, observed external evidence, authoring contract version, and registered producer versions.
105
+
106
+ `createScriptablePackStagedAssetSnapshotSource()` owns clean-build content reads. It resolves a GUID to its local source owner, lazily builds that owner inside one fixed generation, memoizes private clones and digests, and reports `pack-source-build-cycle` without consulting an older fallback generation. A fallback is only an explicit prebuilt authority for GUIDs with no local owner.
107
+
108
+ `createStandardAssetOutputProducerRegistry()` registers the production
109
+ Material, Mesh, and Scene producers. Material output derives
110
+ parent/texture/sampler refs; Mesh output derives default-material refs and emits
111
+ the `mesh-binary/4` body; Scene output uses the shared ECS externalization
112
+ contract. A specialized host may instead register only the admitted kinds:
113
+
114
+ ```ts
115
+ const outputs = new AssetOutputProducerRegistry();
116
+ outputs.register(materialAssetOutputProducer);
117
+ outputs.register(meshAssetOutputProducer);
118
+ ```
119
+
120
+ ### Mesh binary v4 producer contract
121
+
122
+ The Mesh producer calls [`packMeshBinV4`](src/mesh-bin.ts), which delegates
123
+ projection facts to geometry and records one stable digest, mask, stride,
124
+ cardinality, and payload length in the artifact header. Material defaults are
125
+ references into the producer refs table; GUID strings are not duplicated in the
126
+ binary metadata.
127
+
128
+ > [!IMPORTANT]
129
+ > A producer Result error contains `subject`, `sourceKey`, `expected`,
130
+ > `actual`, and a re-cook recovery hint. Failed validation returns no artifact,
131
+ > so the importer cannot publish a partial mesh product. v2/v3 mesh binaries
132
+ > are not compatibility inputs.
133
+
134
+ At the low-level `buildScriptablePack` boundary, `assetSource` is optional only
135
+ when `build` never calls `reader.readByGuid`. The first attempted content read
136
+ without a source returns structured `asset-not-found`; no empty snapshot or
137
+ stale content is invented. Production Vite hosts provide the staged generation
138
+ source described above.
139
+
140
+ `ImporterRegistry` mirrors the runtime `LoaderRegistry` and the Console
141
+ `Registry`: `register(importer)` (fail-fast on a malformed importer, idempotent
142
+ on a repeated key) + `get(key)` (returns `undefined`, which the runner maps to a
143
+ structured `ImportError(code='importer-not-registered')`).
144
+
145
+ ```ts
146
+ import { ImporterRegistry, runImport } from '@forgeax/engine-import';
147
+ import { readFile } from 'node:fs/promises';
148
+
149
+ const registry = new ImporterRegistry();
150
+ registry.register(gltfImporter);
151
+
152
+ const fs = {
153
+ async readSource(path: string) {
154
+ try {
155
+ const buf = await readFile(path);
156
+ return { ok: true, value: new Uint8Array(buf) };
157
+ } catch (e) {
158
+ return { ok: false, error: e };
159
+ }
160
+ },
161
+ };
162
+
163
+ const result = await runImport(
164
+ { importer: 'gltf', source: 'assets/box.gltf', subAssets: [...] },
165
+ registry,
166
+ fs,
167
+ );
168
+ if (result.ok) {
169
+ console.log('DDC .pack.json:', result.value.pack);
170
+ }
171
+ ```
172
+
173
+ ## Error model
174
+
175
+ `ImportErrorCode` is a closed 5-member union (exhaustive `switch (err.code)`,
176
+ no `default:`). `ImportError` carries the four-field structured surface
177
+ (`.code` / `.expected` / `.hint` / `.detail`); SSOT lives in
178
+ `@forgeax/engine-types`.
179
+
180
+ | code | trigger |
181
+ |:--|:--|
182
+ | `importer-not-registered` | `meta.importer` has no registered importer |
183
+ | `source-read-failed` | `meta.source` could not be read |
184
+ | `import-produced-no-assets` | importer produced nothing, or omitted a declared GUID |
185
+ | `guid-mismatch` | importer produced a GUID not declared in `meta.subAssets[]` |
186
+ | `import-internal-error` | importer conversion or finalization failed; the runner wraps it in the existing structured Result. Finalization/digest failures carry a `detail.reason` prefixed with `finalization/digest`, and no CookProduct or Pack is returned for the failed attempt |
187
+
188
+ ## Dual-form transport (M4)
189
+
190
+ | Form | `ImportTransport` | DDC source | DDC miss behavior |
191
+ |:--|:--|:--|:--|
192
+ | **studio** (dev server) | HTTP adapter `POST /__import/:guid` | lazily imported on demand | `transport.fetchPack(guid)` -> import -> load |
193
+ | **shipped** (player bundle) | `undefined` (null transport) | build-time pre-import via `generateBundle` | `asset-not-imported` fail-fast (never downgrades to runtime import) |
194
+
195
+ The runtime load path is **identical** in both forms — `ddcLoad` has zero
196
+ branches on transport. The only difference is whether `transportOrFail` is
197
+ reached on DDC miss (studio: it calls the transport; shipped: it returns the
198
+ error immediately).
199
+
200
+ ## Indexed source-package lifecycle
201
+
202
+ Use this sequence when an import or Pack consumer reports a missing product:
203
+
204
+ 1. **Inspect** the source Meta, declared GUID closure, Catalog row, DDC head,
205
+ and producer receipt. Read the closed error union's `code` and `detail`.
206
+ 2. **Repair** the source, Meta, or registered importer named by the detail.
207
+ `ImporterRegistry` owns dispatch, while the source plus Meta remains the
208
+ author authority.
209
+ 3. **Rebuild** when the existing DDC entry can be replaced safely; **cold-cook**
210
+ when integrity, receipt, or lifecycle state says the derived entry is
211
+ invalid. Both paths use `runImport` and the shared finalizer.
212
+ 4. **Verify** GUID closure, receipt freshness, DDC integrity, Pack artifacts,
213
+ and the projected Catalog row.
214
+ 5. **Retry** the same GUID after verification. Never parse an error message or
215
+ turn an unverified source file into a runtime payload.
216
+
217
+ `runImport` keeps conversion and finalization failures inside its structured
218
+ Result boundary. A digest-capability refusal during CookProduct finalization
219
+ does not publish a partial product; repair that capability and retry the same
220
+ Meta/GUID through the same `ImporterRegistry`.
221
+
222
+ The import package stops at build-time source conversion and product
223
+ publication. It does not write authoring state, own Editor operations, or add
224
+ runtime transport branches. A dev `ImportTransport` is an explicit host
225
+ adapter; a shipped bundle must carry its build-time product and keeps
226
+ `asset-not-imported` fail-fast semantics.