@highstate/cli 0.9.16 → 0.9.19

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.
@@ -14,6 +14,11 @@
14
14
  "resolveJsonModule": true,
15
15
  "esModuleInterop": true,
16
16
  "allowJs": true,
17
- "verbatimModuleSyntax": true
17
+ "verbatimModuleSyntax": true,
18
+ "paths": {
19
+ "@/*": [
20
+ "./src/*"
21
+ ],
22
+ }
18
23
  },
19
- }
24
+ }
@@ -0,0 +1,11 @@
1
+ // src/shared/utils.ts
2
+ function int32ToBytes(value) {
3
+ const buffer = new ArrayBuffer(4);
4
+ const view = new DataView(buffer);
5
+ view.setInt32(0, value, true);
6
+ return new Uint8Array(buffer);
7
+ }
8
+
9
+ export { int32ToBytes };
10
+ //# sourceMappingURL=chunk-CMECLVT7.js.map
11
+ //# sourceMappingURL=chunk-CMECLVT7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/shared/utils.ts"],"names":[],"mappings":";AAAO,SAAS,aAAa,KAAA,EAA2B;AACtD,EAAA,MAAM,MAAA,GAAS,IAAI,WAAA,CAAY,CAAC,CAAA;AAChC,EAAA,MAAM,IAAA,GAAO,IAAI,QAAA,CAAS,MAAM,CAAA;AAChC,EAAA,IAAA,CAAK,QAAA,CAAS,CAAA,EAAG,KAAA,EAAO,IAAI,CAAA;AAC5B,EAAA,OAAO,IAAI,WAAW,MAAM,CAAA;AAC9B","file":"chunk-CMECLVT7.js","sourcesContent":["export function int32ToBytes(value: number): Uint8Array {\n const buffer = new ArrayBuffer(4)\n const view = new DataView(buffer)\n view.setInt32(0, value, true) // true for little-endian\n return new Uint8Array(buffer)\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "sourceHashes": {
3
- "./dist/main.js": "9fd51e93203bb202368349807424add573043c4fe8254095b4f5e4dfa76fedc0"
3
+ "./dist/main.js": 1411190614
4
4
  }
5
5
  }
@@ -1,14 +1,9 @@
1
- // src/shared/library-loader.ts
2
- import {
3
- isComponent,
4
- isEntity,
5
- isUnitModel,
6
- originalCreate
7
- } from "@highstate/contract";
8
- import { serializeFunction } from "@pulumi/pulumi/runtime/index.js";
9
- import { Crc32, crc32 } from "@aws-crypto/crc32";
10
- import { encode } from "@msgpack/msgpack";
11
- import { int32ToBytes } from "@highstate/backend/shared";
1
+ import { int32ToBytes } from './chunk-CMECLVT7.js';
2
+ import console from 'node:console';
3
+ import { isComponent, isEntity, isUnitModel } from '@highstate/contract';
4
+ import { Crc32, crc32 } from '@aws-crypto/crc32';
5
+ import { encode } from '@msgpack/msgpack';
6
+
12
7
  async function loadLibrary(logger, modulePaths) {
13
8
  const modules = {};
14
9
  for (const modulePath of modulePaths) {
@@ -16,8 +11,9 @@ async function loadLibrary(logger, modulePaths) {
16
11
  logger.debug({ modulePath }, "loading module");
17
12
  modules[modulePath] = await import(modulePath);
18
13
  logger.debug({ modulePath }, "module loaded");
19
- } catch (err) {
20
- logger.error({ modulePath, err }, "module load failed");
14
+ } catch (error) {
15
+ console.error(error);
16
+ throw new Error(`Failed to load module "${modulePath}"`, { cause: error });
21
17
  }
22
18
  }
23
19
  const components = {};
@@ -37,22 +33,31 @@ async function _loadLibrary(value, components, entities) {
37
33
  if (isComponent(value)) {
38
34
  const entityHashes = [];
39
35
  for (const entity of value.entities.values()) {
40
- entity.definitionHash ??= calculateEntityDefinitionHash(entity);
41
- entityHashes.push(entity.definitionHash);
36
+ entity.model.definitionHash ??= calculateEntityDefinitionHash(entity);
37
+ entityHashes.push(entity.model.definitionHash);
42
38
  }
43
39
  components[value.model.type] = value.model;
44
40
  value.model.definitionHash = await calculateComponentDefinitionHash(value, entityHashes);
45
41
  return;
46
42
  }
47
43
  if (isEntity(value)) {
48
- entities[value.type] = value;
44
+ entities[value.type] = value.model;
49
45
  entities[value.type].definitionHash ??= calculateEntityDefinitionHash(value);
50
- delete value.schema;
46
+ delete value.model.schema;
51
47
  return;
52
48
  }
53
49
  if (typeof value !== "object" || value === null) {
54
50
  return;
55
51
  }
52
+ if ("_zod" in value) {
53
+ return;
54
+ }
55
+ if (Array.isArray(value)) {
56
+ for (const item of value) {
57
+ await _loadLibrary(item, components, entities);
58
+ }
59
+ return;
60
+ }
56
61
  for (const key in value) {
57
62
  await _loadLibrary(value[key], components, entities);
58
63
  }
@@ -61,7 +66,7 @@ async function calculateComponentDefinitionHash(component, entityHashes) {
61
66
  const result = new Crc32();
62
67
  result.update(encode(component.model));
63
68
  if (!isUnitModel(component.model)) {
64
- const serializedCreate = await serializeFunction(component[originalCreate]);
69
+ const serializedCreate = { text: "TODO: investigate why serializeFunction hangs" };
65
70
  result.update(Buffer.from(serializedCreate.text));
66
71
  }
67
72
  for (const entityHash of entityHashes) {
@@ -70,9 +75,9 @@ async function calculateComponentDefinitionHash(component, entityHashes) {
70
75
  return result.digest();
71
76
  }
72
77
  function calculateEntityDefinitionHash(entity) {
73
- return crc32(encode(entity));
78
+ return crc32(encode(entity.model));
74
79
  }
75
- export {
76
- loadLibrary
77
- };
78
- //# sourceMappingURL=library-loader-CGEPTS4L.js.map
80
+
81
+ export { loadLibrary };
82
+ //# sourceMappingURL=library-loader-6TJTW2HX.js.map
83
+ //# sourceMappingURL=library-loader-6TJTW2HX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/shared/library-loader.ts"],"names":[],"mappings":";;;;;;AAoBA,eAAsB,WAAA,CAAY,QAAgB,WAAA,EAAyC;AACzF,EAAA,MAAM,UAAmC,EAAC;AAC1C,EAAA,KAAA,MAAW,cAAc,WAAA,EAAa;AACpC,IAAA,IAAI;AACF,MAAA,MAAA,CAAO,KAAA,CAAM,EAAE,UAAA,EAAW,EAAG,gBAAgB,CAAA;AAC7C,MAAA,OAAA,CAAQ,UAAU,CAAA,GAAI,MAAM,OAAO,UAAA,CAAA;AAEnC,MAAA,MAAA,CAAO,KAAA,CAAM,EAAE,UAAA,EAAW,EAAG,eAAe,CAAA;AAAA,IAC9C,SAAS,KAAA,EAAO;AAC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O,YAAA,CAAa,UAAU,CAAC,CAAA;AAAA,EACxC;AAEA,EAAA,OAAO,OAAO,MAAA,EAAO;AACvB;AAEA,SAAS,8BAA8B,MAAA,EAAwB;AAC7D,EAAA,OAAO,KAAA,CAAM,MAAA,CAAO,MAAA,CAAO,KAAK,CAAC,CAAA;AACnC","file":"library-loader-6TJTW2HX.js","sourcesContent":["import type { Logger } from \"pino\"\nimport console from \"node:console\"\nimport {\n type Component,\n type ComponentModel,\n type Entity,\n type EntityModel,\n isComponent,\n isEntity,\n isUnitModel,\n} from \"@highstate/contract\"\nimport { Crc32, crc32 } from \"@aws-crypto/crc32\"\nimport { encode } from \"@msgpack/msgpack\"\nimport { int32ToBytes } from \"./utils\"\n\nexport type Library = Readonly<{\n components: Readonly<Record<string, ComponentModel>>\n entities: Readonly<Record<string, EntityModel>>\n}>\n\nexport async function loadLibrary(logger: Logger, modulePaths: string[]): Promise<Library> {\n const modules: Record<string, unknown> = {}\n for (const modulePath of modulePaths) {\n try {\n logger.debug({ modulePath }, \"loading module\")\n modules[modulePath] = await import(modulePath)\n\n logger.debug({ modulePath }, \"module loaded\")\n } catch (error) {\n console.error(error)\n\n throw new Error(`Failed to load module \"${modulePath}\"`, { cause: error })\n }\n }\n\n const components: Record<string, ComponentModel> = {}\n const entities: Record<string, EntityModel> = {}\n\n await _loadLibrary(modules, components, entities)\n\n logger.info(\n {\n componentCount: Object.keys(components).length,\n entityCount: Object.keys(entities).length,\n },\n \"library loaded\",\n )\n\n logger.trace({ components, entities }, \"library content\")\n\n return { components, entities }\n}\n\nasync function _loadLibrary(\n value: unknown,\n components: Record<string, ComponentModel>,\n entities: Record<string, EntityModel>,\n): Promise<void> {\n if (isComponent(value)) {\n const entityHashes: number[] = []\n for (const entity of value.entities.values()) {\n entity.model.definitionHash ??= calculateEntityDefinitionHash(entity)\n entityHashes.push(entity.model.definitionHash)\n }\n\n components[value.model.type] = value.model\n value.model.definitionHash = await calculateComponentDefinitionHash(value, entityHashes)\n\n return\n }\n\n if (isEntity(value)) {\n entities[value.type] = value.model\n entities[value.type].definitionHash ??= calculateEntityDefinitionHash(value)\n\n // @ts-expect-error remove the schema since it's not needed in the designer\n delete value.model.schema\n return\n }\n\n if (typeof value !== \"object\" || value === null) {\n return\n }\n\n if (\"_zod\" in value) {\n // this is a zod schema, we can skip it\n return\n }\n\n if (Array.isArray(value)) {\n for (const item of value) {\n await _loadLibrary(item, components, entities)\n }\n\n return\n }\n\n for (const key in value) {\n await _loadLibrary((value as Record<string, unknown>)[key], components, entities)\n }\n}\n\nasync function calculateComponentDefinitionHash(\n component: Component,\n entityHashes: number[],\n): Promise<number> {\n const result = new Crc32()\n\n // 1. include the full component model\n result.update(encode(component.model))\n\n if (!isUnitModel(component.model)) {\n // 2. for composite components, include the content of the serialized create function\n // const serializedCreate = await serializeFunction(component[originalCreate])\n const serializedCreate = { text: \"TODO: investigate why serializeFunction hangs\" }\n result.update(Buffer.from(serializedCreate.text))\n }\n\n // 3. include the hashes of all entities\n for (const entityHash of entityHashes) {\n result.update(int32ToBytes(entityHash))\n }\n\n return result.digest()\n}\n\nfunction calculateEntityDefinitionHash(entity: Entity): number {\n return crc32(encode(entity.model))\n}\n"]}