@forgeax/engine-import 0.1.29 → 0.1.30

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.
@@ -1,6 +1,6 @@
1
1
  import { AssetGuid } from '@forgeax/engine-pack/guid';
2
2
  import type { PackAuthoringError } from '@forgeax/engine-pack/source';
3
- import type { Asset, AssetGuid as AssetGuidType, ImportError, Result } from '@forgeax/engine-types';
3
+ import type { AssetGuid as AssetGuidType, ImportError, Result } from '@forgeax/engine-types';
4
4
  import { AssetError, err, ok } from '@forgeax/engine-types';
5
5
  import type {
6
6
  ScriptablePackAssetSnapshot,
@@ -8,6 +8,7 @@ import type {
8
8
  ScriptablePackDomainError,
9
9
  ScriptablePackStagedOutput,
10
10
  } from './scriptable-pack.js';
11
+ import { scriptablePackFingerprint as assetDigest } from './scriptable-pack-fingerprint.js';
11
12
 
12
13
  export type ScriptablePackSnapshotError =
13
14
  | AssetError
@@ -29,27 +30,6 @@ export interface ScriptablePackStagedSnapshotOptions {
29
30
  readonly declaredExternalOutputs?: readonly ScriptablePackStagedOutput[];
30
31
  }
31
32
 
32
- function stable(value: unknown): string {
33
- if (ArrayBuffer.isView(value)) {
34
- return `${value.constructor.name}:${JSON.stringify(Array.from(new Uint8Array(value.buffer, value.byteOffset, value.byteLength)))}`;
35
- }
36
- if (Array.isArray(value)) return `[${value.map(stable).join(',')}]`;
37
- if (value !== null && typeof value === 'object') {
38
- const record = value as Record<string, unknown>;
39
- return `{${Object.keys(record)
40
- .sort()
41
- .map((key) => `${JSON.stringify(key)}:${stable(record[key])}`)
42
- .join(',')}}`;
43
- }
44
- return JSON.stringify(value) ?? 'null';
45
- }
46
-
47
- async function assetDigest(asset: Asset): Promise<string> {
48
- const bytes = new TextEncoder().encode(stable(asset));
49
- const digest = await globalThis.crypto.subtle.digest('SHA-256', bytes);
50
- return `sha256:${Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, '0')).join('')}`;
51
- }
52
-
53
33
  function cycleError(
54
34
  stack: readonly string[],
55
35
  owner: string,
@@ -2,6 +2,7 @@ import type { ScriptablePackAssetKind } from '@forgeax/engine-pack';
2
2
  import type {
3
3
  AssetReader,
4
4
  PackAuthoringError,
5
+ PackCookSource,
5
6
  ScriptablePackReadError,
6
7
  } from '@forgeax/engine-pack/source';
7
8
  import type {
@@ -22,7 +23,7 @@ import type { ImportAssetProduct, TerminalImportProduct } from './import-product
22
23
  export type { ScriptablePackSourceClosureEntry } from '@forgeax/engine-pack/source';
23
24
 
24
25
  export interface ScriptablePackAssetSnapshot {
25
- readonly asset: Asset;
26
+ readonly asset: Asset | PackCookSource;
26
27
  readonly generation: number;
27
28
  readonly digest: string;
28
29
  }
@@ -30,7 +31,7 @@ export interface ScriptablePackAssetSnapshot {
30
31
  export interface ScriptablePackStagedOutput {
31
32
  readonly guid: AssetGuidType;
32
33
  readonly sourceKey: string;
33
- readonly asset: Asset;
34
+ readonly asset: Asset | PackCookSource;
34
35
  readonly digest?: string;
35
36
  }
36
37