@highstate/cli 0.9.18 → 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
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "sourceHashes": {
3
- "./dist/main.js": 264201095
3
+ "./dist/main.js": 1411190614
4
4
  }
5
5
  }
@@ -1,5 +1,5 @@
1
1
  import { int32ToBytes } from './chunk-CMECLVT7.js';
2
- import console from 'console';
2
+ import console from 'node:console';
3
3
  import { isComponent, isEntity, isUnitModel } from '@highstate/contract';
4
4
  import { Crc32, crc32 } from '@aws-crypto/crc32';
5
5
  import { encode } from '@msgpack/msgpack';
@@ -79,5 +79,5 @@ function calculateEntityDefinitionHash(entity) {
79
79
  }
80
80
 
81
81
  export { loadLibrary };
82
- //# sourceMappingURL=library-loader-ZABUULFB.js.map
83
- //# sourceMappingURL=library-loader-ZABUULFB.js.map
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,CAA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A,EAAA,KAAA,MAAW,cAAc,YAAA,EAAc;AACrC,IAAA,MAAA,CAAO,MAAA,CAAO,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"]}