@forgeax/engine-pack 0.1.21 → 0.1.23
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/README.md +159 -46
- package/dist/__tests__/inventory-schema.test.d.ts +2 -0
- package/dist/__tests__/inventory-schema.test.d.ts.map +1 -0
- package/dist/__tests__/parameterized-pack-authoring-gateway.unit.test.d.ts +2 -0
- package/dist/__tests__/parameterized-pack-authoring-gateway.unit.test.d.ts.map +1 -0
- package/dist/__tests__/parameterized-pack-scanner.unit.test.d.ts +2 -0
- package/dist/__tests__/parameterized-pack-scanner.unit.test.d.ts.map +1 -0
- package/dist/__tests__/parameterized-pack.unit.test.d.ts +2 -0
- package/dist/__tests__/parameterized-pack.unit.test.d.ts.map +1 -0
- package/dist/__tests__/scanner-blacklist.test.d.ts +2 -0
- package/dist/__tests__/scanner-blacklist.test.d.ts.map +1 -0
- package/dist/build.d.ts +9 -4
- package/dist/build.d.ts.map +1 -1
- package/dist/build.mjs +3314 -803
- package/dist/build.mjs.map +1 -1
- package/dist/builtin.mjs +37 -4
- package/dist/builtin.mjs.map +1 -1
- package/dist/catalog-builder.d.ts.map +1 -1
- package/dist/cli-asset.d.ts.map +1 -1
- package/dist/cli-asset.mjs +1368 -850
- package/dist/cli-asset.mjs.map +1 -1
- package/dist/deriveAssetName.d.ts +11 -7
- package/dist/deriveAssetName.d.ts.map +1 -1
- package/dist/evidence/source-inventory.d.ts.map +1 -1
- package/dist/guid.d.ts +15 -0
- package/dist/guid.d.ts.map +1 -1
- package/dist/guid.mjs +53 -5
- package/dist/guid.mjs.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +1252 -560
- package/dist/index.mjs.map +1 -1
- package/dist/inventory/binding.d.ts +6 -0
- package/dist/inventory/binding.d.ts.map +1 -0
- package/dist/inventory/declaration.d.ts +24 -0
- package/dist/inventory/declaration.d.ts.map +1 -0
- package/dist/inventory/index.d.ts +3 -0
- package/dist/inventory/index.d.ts.map +1 -0
- package/dist/inventory/sync.d.ts +5 -0
- package/dist/inventory/sync.d.ts.map +1 -0
- package/dist/name.mjs +4 -7
- package/dist/name.mjs.map +1 -1
- package/dist/package-finalizer.d.ts +2 -20
- package/dist/package-finalizer.d.ts.map +1 -1
- package/dist/parameterized-pack-node.d.ts +26 -0
- package/dist/parameterized-pack-node.d.ts.map +1 -0
- package/dist/parameterized-pack-node.mjs +11093 -0
- package/dist/parameterized-pack-node.mjs.map +1 -0
- package/dist/parameterized-pack.d.ts +233 -0
- package/dist/parameterized-pack.d.ts.map +1 -0
- package/dist/resolve-asset-source.d.ts +1 -3
- package/dist/resolve-asset-source.d.ts.map +1 -1
- package/dist/resolve-asset-source.mjs +6 -81
- package/dist/resolve-asset-source.mjs.map +1 -1
- package/dist/runtime.mjs +77 -7
- package/dist/runtime.mjs.map +1 -1
- package/dist/scanner.d.ts +19 -8
- package/dist/scanner.d.ts.map +1 -1
- package/dist/scanner.mjs +1169 -690
- package/dist/scanner.mjs.map +1 -1
- package/dist/schema-compiled.d.ts.map +1 -1
- package/dist/schema.mjs +79 -7
- package/dist/schema.mjs.map +1 -1
- package/dist/scriptable-pack-node.d.ts +8 -32
- package/dist/scriptable-pack-node.d.ts.map +1 -1
- package/dist/scriptable-pack-node.mjs +576 -1021
- package/dist/scriptable-pack-node.mjs.map +1 -1
- package/dist/scriptable-pack-worker.mjs +29 -11
- package/dist/scriptable-pack-worker.mjs.map +1 -1
- package/dist/scriptable-pack.d.ts +19 -532
- package/dist/scriptable-pack.d.ts.map +1 -1
- package/dist/scriptable-pack.mjs +1042 -527
- package/dist/scriptable-pack.mjs.map +1 -1
- package/package.json +7 -7
- package/schema/meta.schema.json +1 -1
- package/schema/pack.schema.json +76 -6
- package/src/__tests__/guid-collision.unit.test.ts +18 -9
- package/src/__tests__/inventory-schema.test.ts +109 -0
- package/src/__tests__/pack.unit.test.ts +1 -238
- package/src/__tests__/package-finalizer.contract.test.ts +55 -0
- package/src/__tests__/parameterized-pack-authoring-gateway.unit.test.ts +249 -0
- package/src/__tests__/parameterized-pack-scanner.unit.test.ts +123 -0
- package/src/__tests__/parameterized-pack.unit.test.ts +266 -0
- package/src/__tests__/resolve-asset-source.test.ts +15 -98
- package/src/__tests__/scanner-blacklist.test.ts +55 -0
- package/src/__tests__/scanner-inventory.contract.test.ts +14 -15
- package/src/__tests__/scanner-inventory.test.ts +24 -12
- package/src/__tests__/scriptable-pack-cli.integration.test.ts +4 -9
- package/src/__tests__/topology.unit.test.ts +23 -0
- package/src/build.ts +28 -18
- package/src/catalog-builder.ts +61 -34
- package/src/cli-asset.ts +70 -85
- package/src/deriveAssetName.ts +14 -13
- package/src/evidence/source-inventory.ts +34 -21
- package/src/guid.ts +65 -4
- package/src/index.ts +12 -11
- package/src/inventory/binding.ts +25 -0
- package/src/inventory/declaration.ts +168 -0
- package/src/inventory/index.ts +18 -0
- package/src/inventory/sync.ts +22 -0
- package/src/package-finalizer.ts +2 -42
- package/src/parameterized-pack-node.ts +1968 -0
- package/src/parameterized-pack.ts +1493 -0
- package/src/resolve-asset-source.ts +4 -76
- package/src/scanner.ts +241 -59
- package/src/schema-compiled.ts +2 -0
- package/src/scriptable-pack-node.ts +111 -722
- package/src/scriptable-pack-worker.ts +48 -16
- package/src/scriptable-pack.ts +27 -939
- package/dist/.tsbuildinfo +0 -1
- package/dist/__tests__/load-asset-config.test.d.ts +0 -2
- package/dist/__tests__/load-asset-config.test.d.ts.map +0 -1
- package/dist/__tests__/scriptable-pack.test-d.d.ts +0 -2
- package/dist/__tests__/scriptable-pack.test-d.d.ts.map +0 -1
- package/dist/__tests__/scriptable-pack.unit.test.d.ts +0 -2
- package/dist/__tests__/scriptable-pack.unit.test.d.ts.map +0 -1
- package/dist/config.d.ts +0 -6
- package/dist/config.d.ts.map +0 -1
- package/dist/config.mjs +0 -29
- package/dist/config.mjs.map +0 -1
- package/src/__tests__/load-asset-config.test.ts +0 -121
- package/src/__tests__/scriptable-pack.test-d.ts +0 -131
- package/src/__tests__/scriptable-pack.unit.test.ts +0 -789
- package/src/config.ts +0 -36
package/src/scriptable-pack.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import type { Asset, AssetGuid,
|
|
2
|
-
import { err, ok } from '@forgeax/engine-types';
|
|
3
|
-
import { AssetGuid as AssetGuidCodec } from './guid.js';
|
|
1
|
+
import type { Asset, AssetGuid, Result } from '@forgeax/engine-types';
|
|
4
2
|
|
|
5
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Build-time Pack vocabulary shared by the source loader and output
|
|
5
|
+
* producers. Authoring definitions themselves live in parameterized-pack.ts.
|
|
6
|
+
*/
|
|
7
|
+
export * from './guid.js';
|
|
8
|
+
export * from './parameterized-pack.js';
|
|
9
|
+
|
|
10
|
+
/** Closed ordinary kind vocabulary shared by Pack discovery and producers. */
|
|
6
11
|
export type ScriptablePackAssetKind = Asset['kind'];
|
|
7
12
|
|
|
8
|
-
/** Complete ordinary Asset kind vocabulary exposed by ScriptablePack discovery. */
|
|
9
13
|
export const SCRIPTABLE_PACK_ASSET_KINDS = [
|
|
10
14
|
'mesh',
|
|
11
15
|
'material',
|
|
@@ -23,9 +27,13 @@ export const SCRIPTABLE_PACK_ASSET_KINDS = [
|
|
|
23
27
|
'animation-graph',
|
|
24
28
|
'audio',
|
|
25
29
|
'particle-effect',
|
|
30
|
+
'ies-profile',
|
|
26
31
|
] as const satisfies readonly ScriptablePackAssetKind[];
|
|
27
32
|
|
|
28
|
-
|
|
33
|
+
export function isScriptablePackAssetKind(value: string): value is ScriptablePackAssetKind {
|
|
34
|
+
return (SCRIPTABLE_PACK_ASSET_KINDS as readonly string[]).includes(value);
|
|
35
|
+
}
|
|
36
|
+
|
|
29
37
|
export const SCRIPTABLE_PACK_CAPABILITY_MANIFEST = {
|
|
30
38
|
assetKinds: SCRIPTABLE_PACK_ASSET_KINDS,
|
|
31
39
|
durablePayload: true,
|
|
@@ -34,35 +42,11 @@ export const SCRIPTABLE_PACK_CAPABILITY_MANIFEST = {
|
|
|
34
42
|
hostCapabilities: ['audio-install', 'video-play', 'particle-execute'] as const,
|
|
35
43
|
} as const;
|
|
36
44
|
|
|
37
|
-
export function isScriptablePackAssetKind(value: string): value is ScriptablePackAssetKind {
|
|
38
|
-
return (SCRIPTABLE_PACK_ASSET_KINDS as readonly string[]).includes(value);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface ScriptablePackAssetDeclaration<
|
|
42
|
-
TKind extends ScriptablePackAssetKind = ScriptablePackAssetKind,
|
|
43
|
-
> {
|
|
44
|
-
readonly guid: AssetGuid;
|
|
45
|
-
readonly kind: TKind;
|
|
46
|
-
readonly name?: string;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export type ScriptablePackAssetDeclarations = Readonly<
|
|
50
|
-
Record<string, ScriptablePackAssetDeclaration>
|
|
51
|
-
>;
|
|
52
|
-
|
|
53
|
-
export type ScriptablePackExternalAssets = Readonly<Record<string, AssetGuid>>;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Component-shaped input accepted by a ScriptablePack scene declaration.
|
|
57
|
-
* Engine component tokens satisfy this shape; plain `{ type }` rows keep the
|
|
58
|
-
* Pack contract independent of ECS and survive the isolated module worker.
|
|
59
|
-
*/
|
|
60
45
|
export interface ScriptablePackSceneComponentInput {
|
|
61
46
|
readonly name: string;
|
|
62
47
|
readonly fields: Readonly<Record<string, string | { readonly type: string }>>;
|
|
63
48
|
}
|
|
64
49
|
|
|
65
|
-
/** Neutral scene schema projection owned by the Pack definition. */
|
|
66
50
|
export interface ScriptablePackSceneComponent {
|
|
67
51
|
readonly name: string;
|
|
68
52
|
readonly fields: Readonly<Record<string, string>>;
|
|
@@ -70,11 +54,11 @@ export interface ScriptablePackSceneComponent {
|
|
|
70
54
|
|
|
71
55
|
function sceneComponentFieldType(value: unknown): string | undefined {
|
|
72
56
|
if (typeof value === 'string') return value;
|
|
73
|
-
if (
|
|
74
|
-
|
|
57
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) return undefined;
|
|
58
|
+
const type = (value as { readonly type?: unknown }).type;
|
|
59
|
+
return typeof type === 'string' ? type : undefined;
|
|
75
60
|
}
|
|
76
61
|
|
|
77
|
-
/** Derive the frozen, ECS-neutral schema used by scene output producers. */
|
|
78
62
|
export function projectScriptablePackSceneComponents(
|
|
79
63
|
components: readonly ScriptablePackSceneComponentInput[] | undefined,
|
|
80
64
|
): readonly ScriptablePackSceneComponent[] {
|
|
@@ -89,918 +73,22 @@ export function projectScriptablePackSceneComponents(
|
|
|
89
73
|
}));
|
|
90
74
|
}
|
|
91
75
|
|
|
92
|
-
/**
|
|
93
|
-
export
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
export interface ScriptablePackErrorProvenance {
|
|
97
|
-
/** Published source generation observed by the reader, when available. */
|
|
98
|
-
readonly generation?: number;
|
|
99
|
-
/** Stable producer identity for the failed output, when available. */
|
|
100
|
-
readonly sourceKey?: string;
|
|
101
|
-
/** GUID associated with the failed read or output, when available. */
|
|
102
|
-
readonly guid?: string;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export interface ScriptablePackReadError {
|
|
106
|
-
readonly code: string;
|
|
107
|
-
readonly expected: string;
|
|
108
|
-
readonly hint: string;
|
|
109
|
-
readonly detail?: unknown;
|
|
110
|
-
readonly provenance?: ScriptablePackErrorProvenance;
|
|
76
|
+
/** Source closure evidence used to fence one isolated build generation. */
|
|
77
|
+
export interface ScriptablePackSourceClosureEntry {
|
|
78
|
+
readonly path: string;
|
|
79
|
+
readonly digest: string;
|
|
111
80
|
}
|
|
112
81
|
|
|
113
|
-
|
|
114
|
-
TDescriptor extends { readonly kind: infer TKind extends ScriptablePackAssetKind }
|
|
115
|
-
? Extract<Asset, { readonly kind: TKind }>
|
|
116
|
-
: never;
|
|
117
|
-
|
|
118
|
-
export type ScriptablePackOutputs<TAssets extends ScriptablePackAssetDeclarations> = {
|
|
119
|
-
readonly [TKey in keyof TAssets]: TAssets[TKey] extends ScriptablePackAssetDeclaration
|
|
120
|
-
? ScriptablePackAssetFor<TAssets[TKey]>
|
|
121
|
-
: never;
|
|
122
|
-
};
|
|
123
|
-
|
|
82
|
+
/** AssetReader is intentionally a small, realm-neutral source boundary. */
|
|
124
83
|
export interface AssetReader {
|
|
125
|
-
/** Load a declared GUID as a durable payload; this never mints a World handle. */
|
|
126
84
|
readByGuid<TAsset extends Asset = Asset>(
|
|
127
85
|
guid: AssetGuid,
|
|
128
86
|
): Promise<Result<TAsset, ScriptablePackReadError>>;
|
|
129
87
|
}
|
|
130
88
|
|
|
131
|
-
export
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
export interface ScriptablePackDefinition<
|
|
137
|
-
TAssets extends ScriptablePackAssetDeclarations = ScriptablePackAssetDeclarations,
|
|
138
|
-
TExternal extends ScriptablePackExternalAssets = ScriptablePackExternalAssets,
|
|
139
|
-
TError = ScriptablePackReadError,
|
|
140
|
-
> {
|
|
141
|
-
readonly schemaVersion: '1.0.0';
|
|
142
|
-
readonly packageId: AssetGuid;
|
|
143
|
-
readonly name?: string;
|
|
144
|
-
readonly assets: TAssets;
|
|
145
|
-
/** Component tokens/schema rows used by scene ref externalization. */
|
|
146
|
-
readonly sceneComponents?: readonly ScriptablePackSceneComponentInput[];
|
|
147
|
-
readonly externalAssets: TExternal;
|
|
148
|
-
readonly build: (
|
|
149
|
-
assetReader: AssetReader,
|
|
150
|
-
) =>
|
|
151
|
-
| ScriptablePackBuildResult<TAssets, TError>
|
|
152
|
-
| Promise<ScriptablePackBuildResult<TAssets, TError>>;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export interface ScriptablePackSourceClosureEntry {
|
|
156
|
-
readonly path: string;
|
|
157
|
-
readonly digest: string;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export interface ScriptablePackMetaJson {
|
|
161
|
-
readonly schemaVersion: '1.0.0';
|
|
162
|
-
readonly kind: 'external-asset-package';
|
|
163
|
-
readonly packageId: string;
|
|
164
|
-
readonly name?: string;
|
|
165
|
-
readonly importer: 'pack-ts';
|
|
166
|
-
readonly source: string;
|
|
167
|
-
readonly importSettings: {
|
|
168
|
-
readonly contractVersion: '1.0.0';
|
|
169
|
-
readonly externalAssets: readonly {
|
|
170
|
-
readonly alias: string;
|
|
171
|
-
readonly guid: string;
|
|
172
|
-
}[];
|
|
173
|
-
};
|
|
174
|
-
readonly subAssets: readonly {
|
|
175
|
-
readonly guid: string;
|
|
176
|
-
readonly sourceIndex: number;
|
|
177
|
-
readonly sourceKey: string;
|
|
178
|
-
readonly kind: ScriptablePackAssetKind;
|
|
179
|
-
readonly name?: string;
|
|
180
|
-
}[];
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export interface ScriptablePackOperationEnvelope {
|
|
184
|
-
readonly requestId: string;
|
|
185
|
-
readonly expectedRevision?: string;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export type ScriptablePackGatewayOperation =
|
|
189
|
-
| (ScriptablePackOperationEnvelope & {
|
|
190
|
-
readonly kind: 'preflight';
|
|
191
|
-
readonly sourcePath: string;
|
|
192
|
-
})
|
|
193
|
-
| (ScriptablePackOperationEnvelope & {
|
|
194
|
-
readonly kind: 'create-scriptable-pack';
|
|
195
|
-
readonly sourcePath: string;
|
|
196
|
-
readonly name?: string;
|
|
197
|
-
readonly initialOutput: {
|
|
198
|
-
readonly sourceKey: string;
|
|
199
|
-
readonly kind: ScriptablePackAssetKind;
|
|
200
|
-
readonly name?: string;
|
|
201
|
-
};
|
|
202
|
-
})
|
|
203
|
-
| (ScriptablePackOperationEnvelope & {
|
|
204
|
-
readonly kind: 'add-output';
|
|
205
|
-
readonly sourcePath: string;
|
|
206
|
-
readonly sourceKey: string;
|
|
207
|
-
readonly assetKind: ScriptablePackAssetKind;
|
|
208
|
-
readonly name?: string;
|
|
209
|
-
})
|
|
210
|
-
| (ScriptablePackOperationEnvelope & {
|
|
211
|
-
readonly kind: 'add-external-asset';
|
|
212
|
-
readonly sourcePath: string;
|
|
213
|
-
readonly alias: string;
|
|
214
|
-
readonly guid: AssetGuid;
|
|
215
|
-
})
|
|
216
|
-
| (ScriptablePackOperationEnvelope & {
|
|
217
|
-
readonly kind: 'rename-display';
|
|
218
|
-
readonly sourcePath: string;
|
|
219
|
-
readonly target:
|
|
220
|
-
| { readonly kind: 'package' }
|
|
221
|
-
| { readonly kind: 'output'; readonly sourceKey: string };
|
|
222
|
-
readonly name: string;
|
|
223
|
-
})
|
|
224
|
-
| (ScriptablePackOperationEnvelope & {
|
|
225
|
-
readonly kind: 'remove-output';
|
|
226
|
-
readonly sourcePath: string;
|
|
227
|
-
readonly sourceKey: string;
|
|
228
|
-
/** Exact incoming reference identities acknowledged by the caller. */
|
|
229
|
-
readonly confirmIncomingRefs?: readonly string[];
|
|
230
|
-
})
|
|
231
|
-
| (ScriptablePackOperationEnvelope & {
|
|
232
|
-
readonly kind: 'clone-scriptable-pack';
|
|
233
|
-
readonly sourcePath: string;
|
|
234
|
-
readonly targetPath: string;
|
|
235
|
-
})
|
|
236
|
-
| (ScriptablePackOperationEnvelope & {
|
|
237
|
-
readonly kind: 'inspect-meta';
|
|
238
|
-
readonly sourcePath: string;
|
|
239
|
-
})
|
|
240
|
-
| (ScriptablePackOperationEnvelope & {
|
|
241
|
-
readonly kind: 'rebuild' | 'cold-cook';
|
|
242
|
-
readonly sourcePath: string;
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
export interface ScriptablePackMutationCapabilities {
|
|
246
|
-
readonly inspect: true;
|
|
247
|
-
readonly rebuild: true;
|
|
248
|
-
readonly coldCook: true;
|
|
249
|
-
readonly create?: true;
|
|
250
|
-
readonly addOutput?: true;
|
|
251
|
-
readonly addExternalAsset?: true;
|
|
252
|
-
readonly renameDisplay?: true;
|
|
253
|
-
readonly removeOutput?: true;
|
|
254
|
-
readonly clone?: true;
|
|
255
|
-
readonly reason?: string;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
export interface ScriptablePackPreflight {
|
|
259
|
-
readonly sourcePath: string;
|
|
260
|
-
readonly revision: string;
|
|
261
|
-
readonly meta: ScriptablePackMetaJson;
|
|
262
|
-
readonly capabilities: ScriptablePackMutationCapabilities;
|
|
263
|
-
readonly incomingRefs: readonly string[];
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
export interface ScriptablePackGatewayMutation {
|
|
267
|
-
readonly sourcePath: string;
|
|
268
|
-
readonly revision: string;
|
|
269
|
-
readonly meta: ScriptablePackMetaJson;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
export interface ScriptablePackAuthoringGateway {
|
|
273
|
-
execute(
|
|
274
|
-
operation: ScriptablePackGatewayOperation,
|
|
275
|
-
): Promise<Result<ScriptablePackGatewayMutation | ScriptablePackPreflight, ScriptablePackError>>;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
export type ScriptablePackAuthoringMutation =
|
|
279
|
-
| (ScriptablePackOperationEnvelope & {
|
|
280
|
-
readonly kind: 'create-scriptable-pack';
|
|
281
|
-
readonly sourcePath: string;
|
|
282
|
-
readonly packageId: AssetGuid;
|
|
283
|
-
readonly name?: string;
|
|
284
|
-
readonly initialOutput: {
|
|
285
|
-
readonly sourceKey: string;
|
|
286
|
-
readonly kind: ScriptablePackAssetKind;
|
|
287
|
-
readonly guid: AssetGuid;
|
|
288
|
-
readonly name?: string;
|
|
289
|
-
};
|
|
290
|
-
})
|
|
291
|
-
| (ScriptablePackOperationEnvelope & {
|
|
292
|
-
readonly kind: 'add-output';
|
|
293
|
-
readonly sourcePath: string;
|
|
294
|
-
readonly sourceKey: string;
|
|
295
|
-
readonly assetKind: ScriptablePackAssetKind;
|
|
296
|
-
readonly guid: AssetGuid;
|
|
297
|
-
readonly name?: string;
|
|
298
|
-
})
|
|
299
|
-
| Extract<
|
|
300
|
-
ScriptablePackGatewayOperation,
|
|
301
|
-
{ readonly kind: 'add-external-asset' | 'rename-display' | 'remove-output' }
|
|
302
|
-
>
|
|
303
|
-
| (ScriptablePackOperationEnvelope & {
|
|
304
|
-
readonly kind: 'clone-scriptable-pack';
|
|
305
|
-
readonly sourcePath: string;
|
|
306
|
-
readonly targetPath: string;
|
|
307
|
-
readonly packageId: AssetGuid;
|
|
308
|
-
readonly outputGuids: Readonly<Record<string, AssetGuid>>;
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
export interface ScriptablePackAuthoringPort {
|
|
312
|
-
preflight(
|
|
313
|
-
sourcePath: string,
|
|
314
|
-
): Promise<Result<Omit<ScriptablePackPreflight, 'sourcePath'>, ScriptablePackError>>;
|
|
315
|
-
mutate(
|
|
316
|
-
operation: ScriptablePackAuthoringMutation,
|
|
317
|
-
): Promise<
|
|
318
|
-
Result<{ readonly sourcePath: string; readonly revision: string }, ScriptablePackError>
|
|
319
|
-
>;
|
|
320
|
-
inspect(
|
|
321
|
-
sourcePath: string,
|
|
322
|
-
): Promise<
|
|
323
|
-
Result<
|
|
324
|
-
{ readonly revision: string; readonly meta: ScriptablePackMetaJson },
|
|
325
|
-
ScriptablePackError
|
|
326
|
-
>
|
|
327
|
-
>;
|
|
328
|
-
rebuild(
|
|
329
|
-
sourcePath: string,
|
|
330
|
-
mode: 'rebuild' | 'cold-cook',
|
|
331
|
-
): Promise<
|
|
332
|
-
Result<
|
|
333
|
-
{ readonly revision: string; readonly meta: ScriptablePackMetaJson },
|
|
334
|
-
ScriptablePackError
|
|
335
|
-
>
|
|
336
|
-
>;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
/** Keep GUID allocation and multi-identity operations in one auditable gateway transaction. */
|
|
340
|
-
export function createScriptablePackAuthoringGateway(
|
|
341
|
-
port: ScriptablePackAuthoringPort,
|
|
342
|
-
allocateGuid: () => AssetGuid = AssetGuidCodec.random,
|
|
343
|
-
): ScriptablePackAuthoringGateway {
|
|
344
|
-
const requests = new Map<
|
|
345
|
-
string,
|
|
346
|
-
{
|
|
347
|
-
readonly fingerprint: string;
|
|
348
|
-
readonly result: Promise<
|
|
349
|
-
Result<ScriptablePackGatewayMutation | ScriptablePackPreflight, ScriptablePackError>
|
|
350
|
-
>;
|
|
351
|
-
}
|
|
352
|
-
>();
|
|
353
|
-
|
|
354
|
-
async function mutationResult(
|
|
355
|
-
result: Awaited<ReturnType<ScriptablePackAuthoringPort['mutate']>>,
|
|
356
|
-
): Promise<Result<ScriptablePackGatewayMutation, ScriptablePackError>> {
|
|
357
|
-
if (!result.ok) return result;
|
|
358
|
-
const inspected = await port.inspect(result.value.sourcePath);
|
|
359
|
-
if (!inspected.ok) return inspected;
|
|
360
|
-
return ok({
|
|
361
|
-
sourcePath: result.value.sourcePath,
|
|
362
|
-
revision: inspected.value.revision,
|
|
363
|
-
meta: inspected.value.meta,
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
async function dispatch(
|
|
368
|
-
operation: ScriptablePackGatewayOperation,
|
|
369
|
-
): Promise<Result<ScriptablePackGatewayMutation | ScriptablePackPreflight, ScriptablePackError>> {
|
|
370
|
-
switch (operation.kind) {
|
|
371
|
-
case 'preflight': {
|
|
372
|
-
const preflight = await port.preflight(operation.sourcePath);
|
|
373
|
-
return preflight.ok
|
|
374
|
-
? ok({ sourcePath: operation.sourcePath, ...preflight.value })
|
|
375
|
-
: preflight;
|
|
376
|
-
}
|
|
377
|
-
case 'inspect-meta': {
|
|
378
|
-
const inspected = await port.inspect(operation.sourcePath);
|
|
379
|
-
return inspected.ok
|
|
380
|
-
? ok({ sourcePath: operation.sourcePath, ...inspected.value })
|
|
381
|
-
: inspected;
|
|
382
|
-
}
|
|
383
|
-
case 'rebuild':
|
|
384
|
-
case 'cold-cook': {
|
|
385
|
-
const preflight = await port.preflight(operation.sourcePath);
|
|
386
|
-
if (!preflight.ok) return preflight;
|
|
387
|
-
if (
|
|
388
|
-
operation.expectedRevision !== undefined &&
|
|
389
|
-
operation.expectedRevision !== preflight.value.revision
|
|
390
|
-
) {
|
|
391
|
-
return err({
|
|
392
|
-
code: 'pack-source-revision-conflict',
|
|
393
|
-
expected: operation.expectedRevision,
|
|
394
|
-
actual: preflight.value.revision,
|
|
395
|
-
hint: 'inspect the current source revision, then retry the build with a new requestId',
|
|
396
|
-
retryable: true,
|
|
397
|
-
recoveryActions: ['asset.preflight', 'mint-request-id'],
|
|
398
|
-
detail: { requestId: operation.requestId, sourcePath: operation.sourcePath },
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
const rebuilt = await port.rebuild(operation.sourcePath, operation.kind);
|
|
402
|
-
return rebuilt.ok ? ok({ sourcePath: operation.sourcePath, ...rebuilt.value }) : rebuilt;
|
|
403
|
-
}
|
|
404
|
-
case 'create-scriptable-pack':
|
|
405
|
-
return mutationResult(
|
|
406
|
-
await port.mutate({
|
|
407
|
-
...operation,
|
|
408
|
-
packageId: allocateGuid(),
|
|
409
|
-
initialOutput: { ...operation.initialOutput, guid: allocateGuid() },
|
|
410
|
-
}),
|
|
411
|
-
);
|
|
412
|
-
case 'add-output':
|
|
413
|
-
return mutationResult(await port.mutate({ ...operation, guid: allocateGuid() }));
|
|
414
|
-
case 'clone-scriptable-pack': {
|
|
415
|
-
const inspected = await port.inspect(operation.sourcePath);
|
|
416
|
-
if (!inspected.ok) return inspected;
|
|
417
|
-
const outputGuids = Object.fromEntries(
|
|
418
|
-
inspected.value.meta.subAssets.map((asset) => [asset.sourceKey, allocateGuid()]),
|
|
419
|
-
);
|
|
420
|
-
return mutationResult(
|
|
421
|
-
await port.mutate({
|
|
422
|
-
...operation,
|
|
423
|
-
packageId: allocateGuid(),
|
|
424
|
-
outputGuids,
|
|
425
|
-
}),
|
|
426
|
-
);
|
|
427
|
-
}
|
|
428
|
-
case 'add-external-asset':
|
|
429
|
-
case 'rename-display':
|
|
430
|
-
case 'remove-output':
|
|
431
|
-
return mutationResult(await port.mutate(operation));
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
return {
|
|
436
|
-
execute(operation) {
|
|
437
|
-
if (operation.requestId.trim().length === 0) {
|
|
438
|
-
return Promise.resolve(
|
|
439
|
-
err({
|
|
440
|
-
code: 'pack-source-operation-committed',
|
|
441
|
-
expected: 'a non-empty caller-minted requestId',
|
|
442
|
-
actual: operation.requestId,
|
|
443
|
-
hint: 'mint a new requestId and retry the operation once',
|
|
444
|
-
retryable: true,
|
|
445
|
-
recoveryActions: ['mint-request-id'],
|
|
446
|
-
detail: { requestId: operation.requestId, sourcePath: operation.sourcePath },
|
|
447
|
-
}),
|
|
448
|
-
);
|
|
449
|
-
}
|
|
450
|
-
const fingerprint = JSON.stringify(operation);
|
|
451
|
-
const prior = requests.get(operation.requestId);
|
|
452
|
-
if (prior !== undefined) {
|
|
453
|
-
if (prior.fingerprint === fingerprint) return prior.result;
|
|
454
|
-
return Promise.resolve(
|
|
455
|
-
err({
|
|
456
|
-
code: 'pack-source-operation-committed',
|
|
457
|
-
expected: 'one immutable operation per requestId',
|
|
458
|
-
actual: operation.kind,
|
|
459
|
-
hint: 'read the original operation result or mint a new requestId',
|
|
460
|
-
retryable: false,
|
|
461
|
-
recoveryActions: ['read-operation-run', 'mint-request-id'],
|
|
462
|
-
detail: { requestId: operation.requestId, sourcePath: operation.sourcePath },
|
|
463
|
-
}),
|
|
464
|
-
);
|
|
465
|
-
}
|
|
466
|
-
const result = dispatch(operation);
|
|
467
|
-
requests.set(operation.requestId, { fingerprint, result });
|
|
468
|
-
return result;
|
|
469
|
-
},
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
const SCRIPTABLE_PACK_REQUEST_ID_SCHEMA = {
|
|
474
|
-
type: 'string',
|
|
475
|
-
minLength: 1,
|
|
476
|
-
maxLength: 128,
|
|
477
|
-
pattern: '^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$',
|
|
478
|
-
description: 'Caller-minted identity for one idempotent ScriptablePack operation.',
|
|
479
|
-
} as const;
|
|
480
|
-
const SCRIPTABLE_PACK_SOURCE_PATH_SCHEMA = {
|
|
481
|
-
type: 'string',
|
|
482
|
-
minLength: 8,
|
|
483
|
-
pattern: '^[^/].*\\.pack\\.ts$',
|
|
484
|
-
description: 'Game-root-relative ScriptablePack source path.',
|
|
485
|
-
} as const;
|
|
486
|
-
const SCRIPTABLE_PACK_OWNER_GUID_SCHEMA = {
|
|
487
|
-
type: 'string',
|
|
488
|
-
format: 'uuid',
|
|
489
|
-
description: 'Catalog GUID used to resolve the producer-owned source subject.',
|
|
490
|
-
} as const;
|
|
491
|
-
const SCRIPTABLE_PACK_REVISION_SCHEMA = {
|
|
492
|
-
type: 'string',
|
|
493
|
-
minLength: 64,
|
|
494
|
-
maxLength: 64,
|
|
495
|
-
pattern: '^[a-f0-9]{64}$',
|
|
496
|
-
description: 'SHA-256 source revision returned by preflight.',
|
|
497
|
-
} as const;
|
|
498
|
-
const SCRIPTABLE_PACK_SOURCE_KEY_SCHEMA = { type: 'string', minLength: 1 } as const;
|
|
499
|
-
const SCRIPTABLE_PACK_ASSET_KIND_SCHEMA = {
|
|
500
|
-
enum: SCRIPTABLE_PACK_ASSET_KINDS,
|
|
501
|
-
description: 'Ordinary Asset kind supported by the ScriptablePack producer/loader matrix.',
|
|
502
|
-
} as const;
|
|
503
|
-
const SCRIPTABLE_PACK_NAME_SCHEMA = { type: 'string', minLength: 1 } as const;
|
|
504
|
-
|
|
505
|
-
function scriptablePackArgsSchema(
|
|
506
|
-
properties: Readonly<Record<string, unknown>>,
|
|
507
|
-
required: readonly string[],
|
|
508
|
-
options: { readonly subject?: boolean; readonly guidSubject?: boolean } = {},
|
|
509
|
-
) {
|
|
510
|
-
const subjectRequired = ['requestId', ...required];
|
|
511
|
-
return {
|
|
512
|
-
type: 'object',
|
|
513
|
-
properties: {
|
|
514
|
-
sourcePath: SCRIPTABLE_PACK_SOURCE_PATH_SCHEMA,
|
|
515
|
-
ownerGuid: SCRIPTABLE_PACK_OWNER_GUID_SCHEMA,
|
|
516
|
-
requestId: SCRIPTABLE_PACK_REQUEST_ID_SCHEMA,
|
|
517
|
-
...properties,
|
|
518
|
-
},
|
|
519
|
-
required: subjectRequired,
|
|
520
|
-
...(options.subject === false
|
|
521
|
-
? {}
|
|
522
|
-
: {
|
|
523
|
-
anyOf: [
|
|
524
|
-
{ required: [...subjectRequired, 'sourcePath'] },
|
|
525
|
-
{ required: [...subjectRequired, 'ownerGuid'] },
|
|
526
|
-
...(options.guidSubject === false ? [] : [{ required: [...subjectRequired, 'guid'] }]),
|
|
527
|
-
],
|
|
528
|
-
}),
|
|
529
|
-
additionalProperties: false,
|
|
530
|
-
} as const;
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
export const SOURCE_AUTHORING_OPERATION_DESCRIPTORS = [
|
|
534
|
-
{
|
|
535
|
-
id: 'asset-source.create',
|
|
536
|
-
kind: 'create',
|
|
537
|
-
domain: 'session',
|
|
538
|
-
title: 'Create Asset Source',
|
|
539
|
-
argsSchema: scriptablePackArgsSchema(
|
|
540
|
-
{
|
|
541
|
-
name: SCRIPTABLE_PACK_NAME_SCHEMA,
|
|
542
|
-
initialOutput: {
|
|
543
|
-
type: 'object',
|
|
544
|
-
properties: {
|
|
545
|
-
sourceKey: SCRIPTABLE_PACK_SOURCE_KEY_SCHEMA,
|
|
546
|
-
kind: SCRIPTABLE_PACK_ASSET_KIND_SCHEMA,
|
|
547
|
-
name: SCRIPTABLE_PACK_NAME_SCHEMA,
|
|
548
|
-
},
|
|
549
|
-
required: ['sourceKey', 'kind'],
|
|
550
|
-
additionalProperties: false,
|
|
551
|
-
},
|
|
552
|
-
},
|
|
553
|
-
['sourcePath', 'initialOutput'],
|
|
554
|
-
{ subject: false },
|
|
555
|
-
),
|
|
556
|
-
},
|
|
557
|
-
{
|
|
558
|
-
id: 'asset-source.add-output',
|
|
559
|
-
kind: 'add-output',
|
|
560
|
-
domain: 'session',
|
|
561
|
-
title: 'Add Asset Source Output',
|
|
562
|
-
argsSchema: scriptablePackArgsSchema(
|
|
563
|
-
{
|
|
564
|
-
sourceKey: SCRIPTABLE_PACK_SOURCE_KEY_SCHEMA,
|
|
565
|
-
assetKind: SCRIPTABLE_PACK_ASSET_KIND_SCHEMA,
|
|
566
|
-
name: SCRIPTABLE_PACK_NAME_SCHEMA,
|
|
567
|
-
expectedRevision: SCRIPTABLE_PACK_REVISION_SCHEMA,
|
|
568
|
-
},
|
|
569
|
-
['sourceKey', 'assetKind', 'expectedRevision'],
|
|
570
|
-
),
|
|
571
|
-
},
|
|
572
|
-
{
|
|
573
|
-
id: 'asset-source.add-external-asset',
|
|
574
|
-
kind: 'add-external-asset',
|
|
575
|
-
domain: 'session',
|
|
576
|
-
title: 'Add Asset Source External Asset',
|
|
577
|
-
argsSchema: scriptablePackArgsSchema(
|
|
578
|
-
{
|
|
579
|
-
alias: SCRIPTABLE_PACK_SOURCE_KEY_SCHEMA,
|
|
580
|
-
guid: { type: 'string', format: 'uuid' },
|
|
581
|
-
expectedRevision: SCRIPTABLE_PACK_REVISION_SCHEMA,
|
|
582
|
-
},
|
|
583
|
-
['alias', 'guid', 'expectedRevision'],
|
|
584
|
-
{ guidSubject: false },
|
|
585
|
-
),
|
|
586
|
-
},
|
|
587
|
-
{
|
|
588
|
-
id: 'asset-source.rename',
|
|
589
|
-
kind: 'rename',
|
|
590
|
-
domain: 'session',
|
|
591
|
-
title: 'Rename Asset Source Display Name',
|
|
592
|
-
argsSchema: scriptablePackArgsSchema(
|
|
593
|
-
{
|
|
594
|
-
target: {
|
|
595
|
-
oneOf: [
|
|
596
|
-
{
|
|
597
|
-
type: 'object',
|
|
598
|
-
properties: { kind: { const: 'package' } },
|
|
599
|
-
required: ['kind'],
|
|
600
|
-
additionalProperties: false,
|
|
601
|
-
},
|
|
602
|
-
{
|
|
603
|
-
type: 'object',
|
|
604
|
-
properties: {
|
|
605
|
-
kind: { const: 'output' },
|
|
606
|
-
sourceKey: SCRIPTABLE_PACK_SOURCE_KEY_SCHEMA,
|
|
607
|
-
},
|
|
608
|
-
required: ['kind', 'sourceKey'],
|
|
609
|
-
additionalProperties: false,
|
|
610
|
-
},
|
|
611
|
-
],
|
|
612
|
-
},
|
|
613
|
-
name: SCRIPTABLE_PACK_NAME_SCHEMA,
|
|
614
|
-
expectedRevision: SCRIPTABLE_PACK_REVISION_SCHEMA,
|
|
615
|
-
},
|
|
616
|
-
['target', 'name', 'expectedRevision'],
|
|
617
|
-
),
|
|
618
|
-
},
|
|
619
|
-
{
|
|
620
|
-
id: 'asset-source.remove-output',
|
|
621
|
-
kind: 'remove-output',
|
|
622
|
-
domain: 'session',
|
|
623
|
-
title: 'Remove Asset Source Output',
|
|
624
|
-
destructive: true,
|
|
625
|
-
argsSchema: scriptablePackArgsSchema(
|
|
626
|
-
{
|
|
627
|
-
sourceKey: SCRIPTABLE_PACK_SOURCE_KEY_SCHEMA,
|
|
628
|
-
confirmIncomingRefs: { type: 'array', items: { type: 'string' } },
|
|
629
|
-
expectedRevision: SCRIPTABLE_PACK_REVISION_SCHEMA,
|
|
630
|
-
},
|
|
631
|
-
['sourceKey', 'expectedRevision'],
|
|
632
|
-
),
|
|
633
|
-
},
|
|
634
|
-
{
|
|
635
|
-
id: 'asset-source.clone',
|
|
636
|
-
kind: 'clone',
|
|
637
|
-
domain: 'session',
|
|
638
|
-
title: 'Clone Asset Source',
|
|
639
|
-
argsSchema: scriptablePackArgsSchema(
|
|
640
|
-
{
|
|
641
|
-
targetPath: SCRIPTABLE_PACK_SOURCE_PATH_SCHEMA,
|
|
642
|
-
expectedRevision: SCRIPTABLE_PACK_REVISION_SCHEMA,
|
|
643
|
-
},
|
|
644
|
-
['targetPath', 'expectedRevision'],
|
|
645
|
-
),
|
|
646
|
-
},
|
|
647
|
-
{
|
|
648
|
-
id: 'asset-source.rebuild',
|
|
649
|
-
kind: 'rebuild',
|
|
650
|
-
domain: 'session',
|
|
651
|
-
title: 'Rebuild Asset Source',
|
|
652
|
-
argsSchema: scriptablePackArgsSchema({ expectedRevision: SCRIPTABLE_PACK_REVISION_SCHEMA }, [
|
|
653
|
-
'expectedRevision',
|
|
654
|
-
]),
|
|
655
|
-
},
|
|
656
|
-
{
|
|
657
|
-
id: 'asset-source.cold-cook',
|
|
658
|
-
kind: 'cold-cook',
|
|
659
|
-
domain: 'session',
|
|
660
|
-
title: 'Cold Cook Asset Source',
|
|
661
|
-
argsSchema: scriptablePackArgsSchema({ expectedRevision: SCRIPTABLE_PACK_REVISION_SCHEMA }, [
|
|
662
|
-
'expectedRevision',
|
|
663
|
-
]),
|
|
664
|
-
},
|
|
665
|
-
] as const;
|
|
666
|
-
|
|
667
|
-
export type ScriptablePackError =
|
|
668
|
-
| {
|
|
669
|
-
readonly code: 'pack-source-load-failed';
|
|
670
|
-
readonly expected: string;
|
|
671
|
-
readonly hint: string;
|
|
672
|
-
readonly detail: {
|
|
673
|
-
readonly sourcePath: string;
|
|
674
|
-
readonly reason: 'module-load' | 'timeout' | 'source-changed';
|
|
675
|
-
readonly phase: 'module-load' | 'build';
|
|
676
|
-
readonly diagnostic: string;
|
|
677
|
-
readonly timeoutMs?: number;
|
|
678
|
-
};
|
|
679
|
-
}
|
|
680
|
-
| {
|
|
681
|
-
readonly code: 'pack-source-definition-invalid';
|
|
682
|
-
readonly expected: string;
|
|
683
|
-
readonly hint: string;
|
|
684
|
-
readonly detail: {
|
|
685
|
-
readonly sourcePath?: string;
|
|
686
|
-
readonly propertyPath: string;
|
|
687
|
-
readonly actual: string;
|
|
688
|
-
};
|
|
689
|
-
}
|
|
690
|
-
| {
|
|
691
|
-
readonly code: 'pack-source-output-invalid';
|
|
692
|
-
readonly expected: string;
|
|
693
|
-
readonly hint: string;
|
|
694
|
-
readonly detail: {
|
|
695
|
-
readonly missingGuids: readonly string[];
|
|
696
|
-
readonly unexpectedSourceKeys: readonly string[];
|
|
697
|
-
readonly kindMismatches: readonly {
|
|
698
|
-
readonly sourceKey: string;
|
|
699
|
-
readonly expected: string;
|
|
700
|
-
readonly actual: string;
|
|
701
|
-
}[];
|
|
702
|
-
};
|
|
703
|
-
}
|
|
704
|
-
| {
|
|
705
|
-
readonly code: 'pack-source-external-closure-mismatch';
|
|
706
|
-
readonly expected: string;
|
|
707
|
-
readonly hint: string;
|
|
708
|
-
readonly detail: {
|
|
709
|
-
readonly undeclaredReferencedGuids: readonly string[];
|
|
710
|
-
readonly undeclaredReadGuids: readonly string[];
|
|
711
|
-
readonly unusedDeclaredGuids: readonly string[];
|
|
712
|
-
};
|
|
713
|
-
}
|
|
714
|
-
| {
|
|
715
|
-
readonly code:
|
|
716
|
-
| 'pack-source-path-invalid'
|
|
717
|
-
| 'pack-source-revision-conflict'
|
|
718
|
-
| 'pack-source-mutation-unsupported'
|
|
719
|
-
| 'pack-source-reference-conflict'
|
|
720
|
-
| 'pack-source-write-failed'
|
|
721
|
-
| 'pack-source-build-cycle'
|
|
722
|
-
| 'pack-source-publication-timeout'
|
|
723
|
-
| 'pack-source-operation-committed';
|
|
724
|
-
readonly expected: string;
|
|
725
|
-
readonly actual?: string;
|
|
726
|
-
readonly hint: string;
|
|
727
|
-
readonly retryable: boolean;
|
|
728
|
-
readonly recoveryActions: readonly string[];
|
|
729
|
-
readonly detail: {
|
|
730
|
-
readonly requestId?: string;
|
|
731
|
-
readonly sourcePath?: string;
|
|
732
|
-
readonly packageId?: string;
|
|
733
|
-
readonly sourceKey?: string;
|
|
734
|
-
readonly incomingRefs?: readonly string[];
|
|
735
|
-
};
|
|
736
|
-
};
|
|
737
|
-
|
|
738
|
-
function actual(value: unknown): string {
|
|
739
|
-
if (value === null) return 'null';
|
|
740
|
-
if (Array.isArray(value)) return 'array';
|
|
741
|
-
if (ArrayBuffer.isView(value)) return value.constructor.name;
|
|
742
|
-
return typeof value;
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
function invalid(
|
|
746
|
-
propertyPath: string,
|
|
747
|
-
expected: string,
|
|
748
|
-
value: unknown,
|
|
749
|
-
sourcePath?: string,
|
|
750
|
-
): Result<never, ScriptablePackError> {
|
|
751
|
-
return err({
|
|
752
|
-
code: 'pack-source-definition-invalid',
|
|
753
|
-
expected,
|
|
754
|
-
hint: 'repair the default exported ScriptablePack definition, then inspect Meta again',
|
|
755
|
-
detail: {
|
|
756
|
-
...(sourcePath === undefined ? {} : { sourcePath }),
|
|
757
|
-
propertyPath,
|
|
758
|
-
actual: actual(value),
|
|
759
|
-
},
|
|
760
|
-
});
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
export function isRecord(value: unknown): value is Record<string, unknown> {
|
|
764
|
-
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
function isAssetGuid(value: unknown): value is AssetGuid {
|
|
768
|
-
return value instanceof Uint8Array && value.byteLength === 16;
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
function guidKey(guid: AssetGuid): string {
|
|
772
|
-
return AssetGuidCodec.format(guid);
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
function freezeDefinition(
|
|
776
|
-
definition: ScriptablePackDefinition,
|
|
777
|
-
): Readonly<ScriptablePackDefinition> {
|
|
778
|
-
const assets = Object.fromEntries(
|
|
779
|
-
Object.entries(definition.assets).map(([sourceKey, descriptor]) => [
|
|
780
|
-
sourceKey,
|
|
781
|
-
Object.freeze({ ...descriptor, guid: descriptor.guid.slice() as AssetGuid }),
|
|
782
|
-
]),
|
|
783
|
-
);
|
|
784
|
-
const externalAssets = Object.fromEntries(
|
|
785
|
-
Object.entries(definition.externalAssets).map(([alias, guid]) => [
|
|
786
|
-
alias,
|
|
787
|
-
guid.slice() as AssetGuid,
|
|
788
|
-
]),
|
|
789
|
-
);
|
|
790
|
-
const sceneComponents =
|
|
791
|
-
definition.sceneComponents === undefined
|
|
792
|
-
? undefined
|
|
793
|
-
: Object.freeze(
|
|
794
|
-
projectScriptablePackSceneComponents(definition.sceneComponents).map((component) =>
|
|
795
|
-
Object.freeze({
|
|
796
|
-
...component,
|
|
797
|
-
fields: Object.freeze({ ...component.fields }),
|
|
798
|
-
}),
|
|
799
|
-
),
|
|
800
|
-
);
|
|
801
|
-
return Object.freeze({
|
|
802
|
-
...definition,
|
|
803
|
-
packageId: definition.packageId.slice() as AssetGuid,
|
|
804
|
-
assets: Object.freeze(assets),
|
|
805
|
-
externalAssets: Object.freeze(externalAssets),
|
|
806
|
-
...(sceneComponents === undefined ? {} : { sceneComponents }),
|
|
807
|
-
});
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
export function validateScriptablePackDefinition(
|
|
811
|
-
value: unknown,
|
|
812
|
-
sourcePath?: string,
|
|
813
|
-
): Result<Readonly<ScriptablePackDefinition>, ScriptablePackError> {
|
|
814
|
-
if (!isRecord(value))
|
|
815
|
-
return invalid('$', 'a ScriptablePack definition object', value, sourcePath);
|
|
816
|
-
if (value.schemaVersion !== '1.0.0') {
|
|
817
|
-
return invalid('$.schemaVersion', "the literal '1.0.0'", value.schemaVersion, sourcePath);
|
|
818
|
-
}
|
|
819
|
-
if (!isAssetGuid(value.packageId)) {
|
|
820
|
-
return invalid('$.packageId', 'a 16-byte AssetGuid', value.packageId, sourcePath);
|
|
821
|
-
}
|
|
822
|
-
if (value.name !== undefined && typeof value.name !== 'string') {
|
|
823
|
-
return invalid('$.name', 'a string when present', value.name, sourcePath);
|
|
824
|
-
}
|
|
825
|
-
if (!isRecord(value.assets) || Object.keys(value.assets).length === 0) {
|
|
826
|
-
return invalid(
|
|
827
|
-
'$.assets',
|
|
828
|
-
'a non-empty sourceKey to descriptor object',
|
|
829
|
-
value.assets,
|
|
830
|
-
sourcePath,
|
|
831
|
-
);
|
|
832
|
-
}
|
|
833
|
-
if (!isRecord(value.externalAssets)) {
|
|
834
|
-
return invalid(
|
|
835
|
-
'$.externalAssets',
|
|
836
|
-
'an alias to AssetGuid object',
|
|
837
|
-
value.externalAssets,
|
|
838
|
-
sourcePath,
|
|
839
|
-
);
|
|
840
|
-
}
|
|
841
|
-
if (value.sceneComponents !== undefined) {
|
|
842
|
-
if (!Array.isArray(value.sceneComponents)) {
|
|
843
|
-
return invalid(
|
|
844
|
-
'$.sceneComponents',
|
|
845
|
-
'an array of component tokens or neutral schema rows when present',
|
|
846
|
-
value.sceneComponents,
|
|
847
|
-
sourcePath,
|
|
848
|
-
);
|
|
849
|
-
}
|
|
850
|
-
const componentNames = new Set<string>();
|
|
851
|
-
for (const [componentIndex, component] of value.sceneComponents.entries()) {
|
|
852
|
-
if (!isRecord(component)) {
|
|
853
|
-
return invalid(
|
|
854
|
-
`$.sceneComponents[${componentIndex}]`,
|
|
855
|
-
'a component token or neutral schema row',
|
|
856
|
-
component,
|
|
857
|
-
sourcePath,
|
|
858
|
-
);
|
|
859
|
-
}
|
|
860
|
-
if (typeof component.name !== 'string' || component.name.trim().length === 0) {
|
|
861
|
-
return invalid(
|
|
862
|
-
`$.sceneComponents[${componentIndex}].name`,
|
|
863
|
-
'a non-empty component name',
|
|
864
|
-
component.name,
|
|
865
|
-
sourcePath,
|
|
866
|
-
);
|
|
867
|
-
}
|
|
868
|
-
if (componentNames.has(component.name)) {
|
|
869
|
-
return invalid(
|
|
870
|
-
`$.sceneComponents[${componentIndex}].name`,
|
|
871
|
-
'component names to be unique within one ScriptablePack',
|
|
872
|
-
component.name,
|
|
873
|
-
sourcePath,
|
|
874
|
-
);
|
|
875
|
-
}
|
|
876
|
-
componentNames.add(component.name);
|
|
877
|
-
if (!isRecord(component.fields)) {
|
|
878
|
-
return invalid(
|
|
879
|
-
`$.sceneComponents[${componentIndex}].fields`,
|
|
880
|
-
'a field-name to schema-type object',
|
|
881
|
-
component.fields,
|
|
882
|
-
sourcePath,
|
|
883
|
-
);
|
|
884
|
-
}
|
|
885
|
-
for (const [fieldName, field] of Object.entries(component.fields)) {
|
|
886
|
-
const type = sceneComponentFieldType(field);
|
|
887
|
-
if (fieldName.trim().length === 0 || type === undefined || type.trim().length === 0) {
|
|
888
|
-
return invalid(
|
|
889
|
-
`$.sceneComponents[${componentIndex}].fields`,
|
|
890
|
-
'field names with non-empty string schema types',
|
|
891
|
-
field,
|
|
892
|
-
sourcePath,
|
|
893
|
-
);
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
if (typeof value.build !== 'function') {
|
|
899
|
-
return invalid('$.build', 'a build(assetReader) function', value.build, sourcePath);
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
const packageGuid = guidKey(value.packageId);
|
|
903
|
-
const localGuids = new Set<string>();
|
|
904
|
-
for (const [sourceKey, descriptor] of Object.entries(value.assets)) {
|
|
905
|
-
if (sourceKey.trim().length === 0) {
|
|
906
|
-
return invalid('$.assets', 'non-empty sourceKey object keys', sourceKey, sourcePath);
|
|
907
|
-
}
|
|
908
|
-
if (!isRecord(descriptor)) {
|
|
909
|
-
return invalid(
|
|
910
|
-
`$.assets[${JSON.stringify(sourceKey)}]`,
|
|
911
|
-
'an asset descriptor',
|
|
912
|
-
descriptor,
|
|
913
|
-
sourcePath,
|
|
914
|
-
);
|
|
915
|
-
}
|
|
916
|
-
if (!isAssetGuid(descriptor.guid)) {
|
|
917
|
-
return invalid(
|
|
918
|
-
`$.assets[${JSON.stringify(sourceKey)}].guid`,
|
|
919
|
-
'a 16-byte AssetGuid',
|
|
920
|
-
descriptor.guid,
|
|
921
|
-
sourcePath,
|
|
922
|
-
);
|
|
923
|
-
}
|
|
924
|
-
if (typeof descriptor.kind !== 'string' || !isScriptablePackAssetKind(descriptor.kind)) {
|
|
925
|
-
return invalid(
|
|
926
|
-
`$.assets[${JSON.stringify(sourceKey)}].kind`,
|
|
927
|
-
'one of SCRIPTABLE_PACK_ASSET_KINDS',
|
|
928
|
-
descriptor.kind,
|
|
929
|
-
sourcePath,
|
|
930
|
-
);
|
|
931
|
-
}
|
|
932
|
-
if (descriptor.name !== undefined && typeof descriptor.name !== 'string') {
|
|
933
|
-
return invalid(
|
|
934
|
-
`$.assets[${JSON.stringify(sourceKey)}].name`,
|
|
935
|
-
'a string when present',
|
|
936
|
-
descriptor.name,
|
|
937
|
-
sourcePath,
|
|
938
|
-
);
|
|
939
|
-
}
|
|
940
|
-
const guid = guidKey(descriptor.guid);
|
|
941
|
-
if (guid === packageGuid || localGuids.has(guid)) {
|
|
942
|
-
return invalid(
|
|
943
|
-
`$.assets[${JSON.stringify(sourceKey)}].guid`,
|
|
944
|
-
'a GUID unique within the package and distinct from packageId',
|
|
945
|
-
descriptor.guid,
|
|
946
|
-
sourcePath,
|
|
947
|
-
);
|
|
948
|
-
}
|
|
949
|
-
localGuids.add(guid);
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
const externalGuids = new Set<string>();
|
|
953
|
-
for (const [alias, guidValue] of Object.entries(value.externalAssets)) {
|
|
954
|
-
if (alias.trim().length === 0) {
|
|
955
|
-
return invalid('$.externalAssets', 'non-empty alias object keys', alias, sourcePath);
|
|
956
|
-
}
|
|
957
|
-
if (!isAssetGuid(guidValue)) {
|
|
958
|
-
return invalid(
|
|
959
|
-
`$.externalAssets[${JSON.stringify(alias)}]`,
|
|
960
|
-
'a 16-byte AssetGuid',
|
|
961
|
-
guidValue,
|
|
962
|
-
sourcePath,
|
|
963
|
-
);
|
|
964
|
-
}
|
|
965
|
-
const guid = guidKey(guidValue);
|
|
966
|
-
if (guid === packageGuid || localGuids.has(guid) || externalGuids.has(guid)) {
|
|
967
|
-
return invalid(
|
|
968
|
-
`$.externalAssets[${JSON.stringify(alias)}]`,
|
|
969
|
-
'a unique foreign GUID not owned by this package',
|
|
970
|
-
guidValue,
|
|
971
|
-
sourcePath,
|
|
972
|
-
);
|
|
973
|
-
}
|
|
974
|
-
externalGuids.add(guid);
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
return ok(freezeDefinition(value as unknown as ScriptablePackDefinition));
|
|
978
|
-
}
|
|
979
|
-
|
|
980
|
-
export function projectScriptablePackMeta(
|
|
981
|
-
definition: ScriptablePackDefinition,
|
|
982
|
-
source: string,
|
|
983
|
-
): ScriptablePackMetaJson {
|
|
984
|
-
const subAssets = Object.entries(definition.assets)
|
|
985
|
-
.sort(([left], [right]) => left.localeCompare(right))
|
|
986
|
-
.map(([sourceKey, descriptor], sourceIndex) => ({
|
|
987
|
-
guid: guidKey(descriptor.guid),
|
|
988
|
-
sourceIndex,
|
|
989
|
-
sourceKey,
|
|
990
|
-
kind: descriptor.kind,
|
|
991
|
-
...(descriptor.name === undefined ? {} : { name: descriptor.name }),
|
|
992
|
-
}));
|
|
993
|
-
const externalAssets = Object.entries(definition.externalAssets)
|
|
994
|
-
.sort(([left], [right]) => left.localeCompare(right))
|
|
995
|
-
.map(([alias, guid]) => ({ alias, guid: guidKey(guid) }));
|
|
996
|
-
return {
|
|
997
|
-
schemaVersion: '1.0.0',
|
|
998
|
-
kind: 'external-asset-package',
|
|
999
|
-
packageId: guidKey(definition.packageId),
|
|
1000
|
-
...(definition.name === undefined ? {} : { name: definition.name }),
|
|
1001
|
-
importer: 'pack-ts',
|
|
1002
|
-
source,
|
|
1003
|
-
importSettings: { contractVersion: '1.0.0', externalAssets },
|
|
1004
|
-
subAssets,
|
|
1005
|
-
};
|
|
89
|
+
export interface ScriptablePackReadError {
|
|
90
|
+
readonly code: string;
|
|
91
|
+
readonly expected: string;
|
|
92
|
+
readonly hint: string;
|
|
93
|
+
readonly detail?: unknown;
|
|
1006
94
|
}
|