@earendil-works/chord 0.0.0

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 (98) hide show
  1. package/README.md +205 -0
  2. package/dist/api.d.ts +15 -0
  3. package/dist/api.d.ts.map +1 -0
  4. package/dist/api.js +72 -0
  5. package/dist/api.js.map +1 -0
  6. package/dist/bundler.d.ts +6 -0
  7. package/dist/bundler.d.ts.map +1 -0
  8. package/dist/bundler.js +3 -0
  9. package/dist/bundler.js.map +1 -0
  10. package/dist/context/index.d.ts +24 -0
  11. package/dist/context/index.d.ts.map +1 -0
  12. package/dist/context/index.js +97 -0
  13. package/dist/context/index.js.map +1 -0
  14. package/dist/delta/index.d.ts +119 -0
  15. package/dist/delta/index.d.ts.map +1 -0
  16. package/dist/delta/index.js +1213 -0
  17. package/dist/delta/index.js.map +1 -0
  18. package/dist/facets/host.d.ts +12 -0
  19. package/dist/facets/host.d.ts.map +1 -0
  20. package/dist/facets/host.js +763 -0
  21. package/dist/facets/host.js.map +1 -0
  22. package/dist/facets/loader.d.ts +3 -0
  23. package/dist/facets/loader.d.ts.map +1 -0
  24. package/dist/facets/loader.js +5 -0
  25. package/dist/facets/loader.js.map +1 -0
  26. package/dist/index.d.ts +11 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +10 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/json.d.ts +4 -0
  31. package/dist/json.d.ts.map +1 -0
  32. package/dist/json.js +57 -0
  33. package/dist/json.js.map +1 -0
  34. package/dist/node/bundle-loader.d.ts +30 -0
  35. package/dist/node/bundle-loader.d.ts.map +1 -0
  36. package/dist/node/bundle-loader.js +377 -0
  37. package/dist/node/bundle-loader.js.map +1 -0
  38. package/dist/node/bundle.d.ts +26 -0
  39. package/dist/node/bundle.d.ts.map +1 -0
  40. package/dist/node/bundle.js +183 -0
  41. package/dist/node/bundle.js.map +1 -0
  42. package/dist/node/manifest.d.ts +36 -0
  43. package/dist/node/manifest.d.ts.map +1 -0
  44. package/dist/node/manifest.js +6 -0
  45. package/dist/node/manifest.js.map +1 -0
  46. package/dist/node/package.d.ts +15 -0
  47. package/dist/node/package.d.ts.map +1 -0
  48. package/dist/node/package.js +199 -0
  49. package/dist/node/package.js.map +1 -0
  50. package/dist/node.d.ts +5 -0
  51. package/dist/node.d.ts.map +1 -0
  52. package/dist/node.js +3 -0
  53. package/dist/node.js.map +1 -0
  54. package/dist/services/consumer.d.ts +11 -0
  55. package/dist/services/consumer.d.ts.map +1 -0
  56. package/dist/services/consumer.js +537 -0
  57. package/dist/services/consumer.js.map +1 -0
  58. package/dist/services/errors.d.ts +8 -0
  59. package/dist/services/errors.d.ts.map +1 -0
  60. package/dist/services/errors.js +22 -0
  61. package/dist/services/errors.js.map +1 -0
  62. package/dist/services/handle.d.ts +15 -0
  63. package/dist/services/handle.d.ts.map +1 -0
  64. package/dist/services/handle.js +99 -0
  65. package/dist/services/handle.js.map +1 -0
  66. package/dist/services/instances.d.ts +25 -0
  67. package/dist/services/instances.d.ts.map +1 -0
  68. package/dist/services/instances.js +137 -0
  69. package/dist/services/instances.js.map +1 -0
  70. package/dist/services/loopback.d.ts +5 -0
  71. package/dist/services/loopback.d.ts.map +1 -0
  72. package/dist/services/loopback.js +15 -0
  73. package/dist/services/loopback.js.map +1 -0
  74. package/dist/services/provider.d.ts +37 -0
  75. package/dist/services/provider.d.ts.map +1 -0
  76. package/dist/services/provider.js +472 -0
  77. package/dist/services/provider.js.map +1 -0
  78. package/dist/services/state-codec.d.ts +15 -0
  79. package/dist/services/state-codec.d.ts.map +1 -0
  80. package/dist/services/state-codec.js +115 -0
  81. package/dist/services/state-codec.js.map +1 -0
  82. package/dist/services/state-internals.d.ts +11 -0
  83. package/dist/services/state-internals.d.ts.map +1 -0
  84. package/dist/services/state-internals.js +10 -0
  85. package/dist/services/state-internals.js.map +1 -0
  86. package/dist/services/state.d.ts +23 -0
  87. package/dist/services/state.d.ts.map +1 -0
  88. package/dist/services/state.js +124 -0
  89. package/dist/services/state.js.map +1 -0
  90. package/dist/services/wire.d.ts +60 -0
  91. package/dist/services/wire.d.ts.map +1 -0
  92. package/dist/services/wire.js +173 -0
  93. package/dist/services/wire.js.map +1 -0
  94. package/dist/types.d.ts +203 -0
  95. package/dist/types.d.ts.map +1 -0
  96. package/dist/types.js +2 -0
  97. package/dist/types.js.map +1 -0
  98. package/package.json +72 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.js","sourceRoot":"","sources":["../../src/facets/host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAA+B,MAAM,0BAA0B,CAAC;AAC1F,OAAO,EAAE,8BAA8B,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,mCAAmC,EAAE,MAAM,yBAAyB,CAAC;AACrG,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAoDlE,MAAM,cAAc;IACV,EAAE,CAAS;IACX,QAAQ,GAAe,EAAE,CAAC;IAC1B,aAAa,GAA0B,EAAE,CAAC;IAC1C,SAAS,GAAsC,EAAE,CAAC;IAC3D,MAAM,GAAmB,YAAY,CAAC;IACtC,cAAc,GAAG,KAAK,CAAC;IAEvB,YAAY,EAAU,EAAE;QACvB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IAAA,CACb;IAED,eAAe,CAAC,SAAiB,EAAQ;QACxC,IAAI,IAAI,CAAC,MAAM,KAAK,YAAY,EAAE,CAAC;YAClC,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,CAAC,EAAE,QAAQ,SAAS,oBAAoB,CAAC,CAAC;QACxE,CAAC;IAAA,CACD;IAED,aAAa,CAAC,SAAiB,EAAQ;QACtC,I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EAAW;IACjH,OAAO,CACN,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM;QAC5B,IAAI,CAAC,KAAK,CAAC,CAAC,SAAS,EAAE,EAAE,CACxB,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,KAAK,SAAS,CAAC,SAAS,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,CAAC,CAC/F,CACD,CAAC;AAAA,CACF;AAED,SAAS,aAAa,CAAC,KAAc,EAAiC;IACrE,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC;AAAA,CAC1G","sourcesContent":["import { BACKGROUND_CONTEXT } from \"../context/index.ts\";\nimport { RemoteServiceBindingImpl } from \"../services/consumer.ts\";\nimport { ServiceSlot } from \"../services/handle.ts\";\nimport { InstanceDirectory, type InstanceDirectoryEntry } from \"../services/instances.ts\";\nimport { createLoopbackServiceTransport } from \"../services/loopback.ts\";\nimport { RemoteServiceProvider, validateRemoteServiceImplementation } from \"../services/provider.ts\";\nimport { MutableReplicatedStateImpl } from \"../services/state.ts\";\nimport type {\n\tContext,\n\tFacet,\n\tFacetEnvironment,\n\tFacetOptions,\n\tRemoteServiceContract,\n\tRemoteServiceSource,\n\tRemoteServices,\n\tService,\n\tServiceMode,\n\tServiceSpawner,\n} from \"../types.ts\";\n\ninterface FacetServiceReference {\n\treadonly serviceId: string;\n\treadonly service: Service<unknown>;\n\treadonly mode: ServiceMode;\n}\n\ninterface ExternalService {\n\treadonly service: Service<unknown>;\n\treadonly mode: ServiceMode;\n\treadonly source: RemoteServiceSource;\n}\n\ninterface FacetShape {\n\tfacetId: string;\n\trequires: readonly FacetServiceReference[];\n\tprovides: readonly FacetServiceReference[];\n}\n\ninterface FacetRuntime extends FacetShape {\n\trequires: FacetServiceReference[];\n\tprovides: FacetServiceReference[];\n\treadonly lifecycle: FacetLifecycle;\n\treadonly provisions: FacetProvision[];\n\treadonly singletonViews: Map<string, unknown>;\n}\n\ntype LifecycleState = \"setting_up\" | \"prepared\" | \"active\" | \"disposing\" | \"dead\";\ntype GenerationPhase =\n\t| \"setup\"\n\t| \"assembling\"\n\t| \"connecting\"\n\t| \"activating\"\n\t| \"active\"\n\t| \"reloading\"\n\t| \"disposing\"\n\t| \"dead\";\ntype Disposal = () => void | Promise<void>;\n\nclass FacetLifecycle {\n\treadonly id: string;\n\treadonly #effects: Disposal[] = [];\n\treadonly #observations: Array<() => Disposal> = [];\n\treadonly #activate: Array<() => void | Promise<void>> = [];\n\t#state: LifecycleState = \"setting_up\";\n\t#serviceAccess = false;\n\n\tconstructor(id: string) {\n\t\tthis.id = id;\n\t}\n\n\tassertSettingUp(operation: string): void {\n\t\tif (this.#state !== \"setting_up\") {\n\t\t\tthrow new Error(`Facet ${this.id} can ${operation} only during setup`);\n\t\t}\n\t}\n\n\tassertRunning(operation: string): void {\n\t\tif (this.#state !== \"setting_up\" && this.#state !== \"active\") {\n\t\t\tthrow new Error(`Facet ${this.id} cannot ${operation} while ${this.#state}`);\n\t\t}\n\t}\n\n\tassertActive(operation: string): void {\n\t\tif (this.#state !== \"active\") throw new Error(`Facet ${this.id} can ${operation} only while active`);\n\t}\n\n\tassertServiceAccess(): void {\n\t\tif (!this.#serviceAccess) {\n\t\t\tthrow new Error(`Facet ${this.id} service handles cannot be used while ${this.#state}`);\n\t\t}\n\t}\n\n\trevoke(): void {\n\t\tthis.#serviceAccess = false;\n\t}\n\n\town(disposal: Disposal): void {\n\t\tthis.assertRunning(\"own resources\");\n\t\tthis.#effects.push(disposal);\n\t}\n\n\tobserve(start: () => Disposal): void {\n\t\tthis.assertSettingUp(\"observe services\");\n\t\tthis.#observations.push(start);\n\t}\n\n\tonActivate(callback: () => void | Promise<void>): void {\n\t\tthis.assertSettingUp(\"register activation callbacks\");\n\t\tthis.#activate.push(callback);\n\t}\n\n\tprepared(): void {\n\t\tthis.assertSettingUp(\"finish setup\");\n\t\tthis.#state = \"prepared\";\n\t}\n\n\tasync activate(): Promise<void> {\n\t\tif (this.#state !== \"prepared\") throw new Error(`Facet ${this.id} is not prepared`);\n\t\tthis.#state = \"active\";\n\t\tthis.#serviceAccess = true;\n\t\tfor (const start of this.#observations) this.#effects.push(start());\n\t\tfor (const callback of this.#activate) await callback();\n\t}\n\n\tasync dispose(): Promise<void> {\n\t\tif (this.#state === \"dead\") return;\n\t\tthis.#state = \"disposing\";\n\t\tconst errors: unknown[] = [];\n\t\tfor (const effect of this.#effects.splice(0).reverse()) {\n\t\t\ttry {\n\t\t\t\tawait effect();\n\t\t\t} catch (error) {\n\t\t\t\terrors.push(error);\n\t\t\t}\n\t\t}\n\t\tthis.#observations.length = 0;\n\t\tthis.#activate.length = 0;\n\t\tthis.#serviceAccess = false;\n\t\tthis.#state = \"dead\";\n\t\tif (errors.length === 1) throw errors[0];\n\t\tif (errors.length > 1) throw new AggregateError(errors, `Failed to dispose facet ${this.id}`);\n\t}\n}\n\ninterface KeyedServiceSource {\n\tobserve<T>(service: Service<T>, handler: (service: T, context: Context) => void | Promise<void>): () => void;\n}\n\ninterface LocalKeyedRegistration {\n\treadonly generations: Map<string, number>;\n\treadonly directory: InstanceDirectory<InstanceDirectoryEntry>;\n}\n\nclass LocalKeyedServiceRegistry implements KeyedServiceSource {\n\treadonly #registrations = new Map<string, LocalKeyedRegistration>();\n\t#disposed = false;\n\n\tconstructor(services: readonly { readonly id: string }[], onError: (error: Error) => void) {\n\t\tconst ids = services.map(({ id }) => id);\n\t\tif (new Set(ids).size !== ids.length) throw new TypeError(\"Local keyed service registry has duplicate IDs\");\n\t\tfor (const serviceId of ids) {\n\t\t\tthis.#registrations.set(serviceId, {\n\t\t\t\tgenerations: new Map(),\n\t\t\t\tdirectory: new InstanceDirectory({ ready: true, onError }),\n\t\t\t});\n\t\t}\n\t}\n\n\tspawn<T>(service: Service<T>, key: string, implementation: T): () => void {\n\t\tthis.#assertActive();\n\t\tif (key.length === 0) throw new TypeError(\"Local service instance key must not be empty\");\n\t\tif (typeof implementation !== \"object\" || implementation === null || Array.isArray(implementation)) {\n\t\t\tthrow new TypeError(`Local service ${service.id} implementation must be an object`);\n\t\t}\n\t\tconst registration = this.#registration(service.id);\n\t\tif (registration.directory.get(key) !== undefined) {\n\t\t\tthrow new Error(`Local service ${service.id} already has a live instance with key ${key}`);\n\t\t}\n\t\tconst generation = (registration.generations.get(key) ?? 0) + 1;\n\t\tregistration.generations.set(key, generation);\n\t\tconst instance: InstanceDirectoryEntry = {\n\t\t\tkey,\n\t\t\tgeneration,\n\t\t\tservice: implementation as object,\n\t\t\tdeactivate() {},\n\t\t};\n\t\tregistration.directory.insert(instance);\n\t\tlet closed = false;\n\t\treturn () => {\n\t\t\tif (closed) return;\n\t\t\tclosed = true;\n\t\t\tregistration.directory.remove(instance);\n\t\t};\n\t}\n\n\tobserve<T>(service: Service<T>, handler: (service: T, context: Context) => void | Promise<void>): () => void {\n\t\tthis.#assertActive();\n\t\treturn this.#registration(service.id).directory.observe(handler);\n\t}\n\n\tdispose(): void {\n\t\tif (this.#disposed) return;\n\t\tthis.#disposed = true;\n\t\tfor (const registration of this.#registrations.values()) registration.directory.dispose();\n\t\tthis.#registrations.clear();\n\t}\n\n\t#registration(serviceId: string): LocalKeyedRegistration {\n\t\tconst registration = this.#registrations.get(serviceId);\n\t\tif (registration === undefined) throw new Error(`Local keyed service ${serviceId} is not registered`);\n\t\treturn registration;\n\t}\n\n\t#assertActive(): void {\n\t\tif (this.#disposed) throw new Error(\"Local keyed service registry is disposed\");\n\t}\n}\n\nclass HostServiceSlots {\n\treadonly #singletons = new Map<string, ServiceSlot>();\n\treadonly #keyedSources = new Map<string, KeyedServiceSource>();\n\n\tgetSingleton<T>(service: Service<T>, assertAccess: () => void): T {\n\t\tlet slot = this.#singletons.get(service.id);\n\t\tif (slot === undefined) {\n\t\t\tslot = new ServiceSlot(service.id, !service.local);\n\t\t\tthis.#singletons.set(service.id, slot);\n\t\t}\n\t\treturn slot.view<T>(assertAccess);\n\t}\n\n\thasSingleton(serviceId: string): boolean {\n\t\treturn this.#singletons.has(serviceId);\n\t}\n\n\tobserve<T>(\n\t\tservice: Service<T>,\n\t\tassertAccess: () => void,\n\t\thandler: (service: T, context: Context) => void | Promise<void>,\n\t): Disposal {\n\t\tconst source = this.#keyedSources.get(service.id);\n\t\tif (source === undefined) throw new Error(`Service ${service.id} is disconnected`);\n\t\tlet stopped = false;\n\t\tconst stop = source.observe(service, (target, context) => {\n\t\t\tconst slot = new ServiceSlot(service.id, !service.local);\n\t\t\tslot.bind(target as object);\n\t\t\treturn handler(\n\t\t\t\tslot.view<T>(() => {\n\t\t\t\t\tassertAccess();\n\t\t\t\t\tif (stopped || context.abortSignal?.aborted) {\n\t\t\t\t\t\tthrow new Error(`Keyed service ${service.id} observation is closed`);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t\tcontext,\n\t\t\t);\n\t\t});\n\t\treturn () => {\n\t\t\tif (stopped) return;\n\t\t\tstopped = true;\n\t\t\tstop();\n\t\t};\n\t}\n\n\tbindSingleton(serviceId: string, target: object): void {\n\t\tthis.#singletons.get(serviceId)?.bind(target);\n\t}\n\n\tbindKeyed(serviceId: string, services: KeyedServiceSource): void {\n\t\tthis.#keyedSources.set(serviceId, services);\n\t}\n\n\tdispose(): void {\n\t\tfor (const slot of this.#singletons.values()) slot.unbind();\n\t\tthis.#singletons.clear();\n\t\tthis.#keyedSources.clear();\n\t}\n}\n\ntype ServiceInstanceInstaller<T> = (key: string, implementation: T) => () => void;\n\ninterface StagedServiceInstance<T> {\n\treadonly key: string;\n\treadonly implementation: T;\n\trelease?: () => void;\n}\n\nclass StagedServiceSpawner<T> implements ServiceSpawner<T> {\n\treadonly #lifecycle: FacetLifecycle;\n\treadonly #validate: (key: string, implementation: T) => void;\n\treadonly #instances = new Map<string, StagedServiceInstance<T>>();\n\t#installer: ServiceInstanceInstaller<T> | undefined;\n\n\tconstructor(lifecycle: FacetLifecycle, validate: (key: string, implementation: T) => void) {\n\t\tthis.#lifecycle = lifecycle;\n\t\tthis.#validate = validate;\n\t}\n\n\tconnect(installer: ServiceInstanceInstaller<T>): void {\n\t\tif (this.#installer !== undefined) throw new Error(\"Facet service provider is already connected\");\n\t\tthis.#installer = installer;\n\t\tfor (const instance of this.#instances.values()) {\n\t\t\tinstance.release = installer(instance.key, instance.implementation);\n\t\t}\n\t}\n\n\tspawn(key: string, implementation: T): () => void {\n\t\tthis.#lifecycle.assertActive(\"spawn service instances\");\n\t\tthis.#validate(key, implementation);\n\t\tif (this.#instances.has(key)) throw new Error(`Facet service already has a live instance with key ${key}`);\n\t\tconst instance: StagedServiceInstance<T> = { key, implementation };\n\t\tthis.#instances.set(key, instance);\n\t\tif (this.#installer !== undefined) instance.release = this.#installer(key, implementation);\n\t\tconst close = (): void => {\n\t\t\tif (this.#instances.get(key) !== instance) return;\n\t\t\tthis.#instances.delete(key);\n\t\t\tinstance.release?.();\n\t\t};\n\t\tthis.#lifecycle.own(close);\n\t\treturn close;\n\t}\n}\n\ntype FacetProvision =\n\t| {\n\t\t\treadonly kind: \"singleton\";\n\t\t\treadonly service: { readonly id: string; readonly local: boolean };\n\t\t\treadonly implementation: object;\n\t\t\tinstall(provider: RemoteServiceProvider): void;\n\t\t\tvalidateReplacement(provider: RemoteServiceProvider): void;\n\t\t\treplace(provider: RemoteServiceProvider): void;\n\t }\n\t| {\n\t\t\treadonly kind: \"keyed\";\n\t\t\treadonly service: { readonly id: string; readonly local: boolean };\n\t\t\tconnectLocal(registry: LocalKeyedServiceRegistry): void;\n\t\t\tconnectRemote(provider: RemoteServiceProvider): void;\n\t };\n\n/** Private lifecycle and dependency kernel behind the atomic host entry point. */\nexport class FacetKernel {\n\treadonly #initialFacets: readonly Facet[];\n\treadonly #serviceSources: readonly RemoteServiceSource[];\n\treadonly #onError: (error: Error) => void;\n\treadonly #facets = new Map<string, FacetRuntime>();\n\treadonly #serviceSlots: HostServiceSlots;\n\treadonly #sourceBindings = new Map<RemoteServiceSource, RemoteServices>();\n\t#activationOrder: readonly string[] = [];\n\t#provider: RemoteServiceProvider | undefined;\n\t#internalServices: RemoteServices | undefined;\n\t#localKeyedServices: LocalKeyedServiceRegistry | undefined;\n\t#phase: GenerationPhase = \"setup\";\n\n\tconstructor(options: FacetOptions) {\n\t\tconst ids = options.facets.map((facet) => facet.id);\n\t\tif (ids.some((id) => id.length === 0)) throw new Error(\"Facet ID must not be empty\");\n\t\tif (new Set(ids).size !== ids.length) throw new Error(\"Facet IDs must be unique within a generation\");\n\t\tthis.#initialFacets = options.facets;\n\t\tthis.#serviceSources = options.serviceSources ?? [];\n\t\tthis.#onError = options.onError ?? (() => {});\n\t\tthis.#serviceSlots = new HostServiceSlots();\n\t}\n\n\tget provider(): RemoteServiceProvider {\n\t\tif (this.#provider === undefined) throw new Error(\"Facet service provider is not assembled\");\n\t\treturn this.#provider;\n\t}\n\n\t#createFacetRuntime(facetId: string): FacetRuntime {\n\t\treturn {\n\t\t\tfacetId,\n\t\t\trequires: [],\n\t\t\tprovides: [],\n\t\t\tlifecycle: new FacetLifecycle(facetId),\n\t\t\tprovisions: [],\n\t\t\tsingletonViews: new Map(),\n\t\t};\n\t}\n\n\t#setupFacet(facet: Facet, record: FacetRuntime): void {\n\t\tconst result: unknown = facet.setup(this.#environment(record));\n\t\tif (isPromiseLike(result)) {\n\t\t\tvoid Promise.resolve(result).catch(() => {});\n\t\t\tthrow new Error(`Facet ${facet.id} setup must be synchronous`);\n\t\t}\n\t\trecord.lifecycle.prepared();\n\t}\n\n\tasync activate(): Promise<void> {\n\t\tconst records: FacetRuntime[] = [];\n\t\ttry {\n\t\t\tfor (const facet of this.#initialFacets) {\n\t\t\t\tconst record = this.#createFacetRuntime(facet.id);\n\t\t\t\tthis.#facets.set(facet.id, record);\n\t\t\t\tthis.#setupFacet(facet, record);\n\t\t\t\trecords.push(record);\n\t\t\t}\n\n\t\t\tthis.#phase = \"assembling\";\n\t\t\tconst externalServices = await this.#resolveExternalServices(records);\n\t\t\tthis.#activationOrder = validateFacets(records, externalServices);\n\t\t\tthis.#assembleProviders();\n\t\t\tthis.#bindServices(externalServices);\n\n\t\t\tthis.#phase = \"connecting\";\n\t\t\tawait Promise.all(\n\t\t\t\t[...this.#sourceBindings.values(), this.#internalServiceBinding].map((services) =>\n\t\t\t\t\tservices.ready(BACKGROUND_CONTEXT),\n\t\t\t\t),\n\t\t\t);\n\n\t\t\tthis.#phase = \"activating\";\n\t\t\tfor (const id of this.#activationOrder) await this.#facets.get(id)!.lifecycle.activate();\n\t\t\tthis.#phase = \"active\";\n\t\t} catch (error) {\n\t\t\tconst cleanupErrors = await this.#terminate();\n\t\t\tif (cleanupErrors.length > 0) {\n\t\t\t\tthrow new AggregateError([error, ...cleanupErrors], \"Facet generation startup and cleanup failed\");\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tasync reload(facets: readonly Facet[]): Promise<void> {\n\t\tif (this.#phase !== \"active\") throw new Error(`Facet host cannot reload while ${this.#phase}`);\n\t\tconst ids = facets.map(({ id }) => id);\n\t\tif (ids.some((id) => id.length === 0)) throw new Error(\"Facet ID must not be empty\");\n\t\tif (new Set(ids).size !== ids.length) throw new Error(\"Reloaded facet IDs must be unique\");\n\t\tfor (const id of ids) {\n\t\t\tif (!this.#facets.has(id)) throw new Error(`Facet ${id} is not active`);\n\t\t}\n\t\tthis.#phase = \"reloading\";\n\n\t\tconst staged: FacetRuntime[] = [];\n\t\tconst candidates: FacetRuntime[] = [];\n\t\ttry {\n\t\t\tfor (const facet of facets) {\n\t\t\t\tconst record = this.#createFacetRuntime(facet.id);\n\t\t\t\tstaged.push(record);\n\t\t\t\tthis.#setupFacet(facet, record);\n\t\t\t\tconst previous = this.#facets.get(facet.id)!;\n\t\t\t\tif (!sameFacetShape(previous, record)) {\n\t\t\t\t\tthrow new Error(`Reloaded facet ${facet.id} must preserve its service requirements and provisions`);\n\t\t\t\t}\n\t\t\t\tthis.#validateReplacementProvisions(record.provisions);\n\t\t\t\tcandidates.push(record);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconst cleanupErrors = await disposeFacetRecords(staged.reverse());\n\t\t\tif (cleanupErrors.length > 0) {\n\t\t\t\tconst abortErrors = await this.#abort();\n\t\t\t\tthrow new AggregateError(\n\t\t\t\t\t[error, ...cleanupErrors, ...abortErrors],\n\t\t\t\t\t\"Facet reload setup and cleanup failed\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.#phase = \"active\";\n\t\t\tthrow error;\n\t\t}\n\n\t\tconst replacements = new Map(candidates.map((record) => [record.facetId, record]));\n\t\tconst candidateOrder = this.#activationOrder.flatMap((id) => {\n\t\t\tconst candidate = replacements.get(id);\n\t\t\treturn candidate === undefined ? [] : [candidate];\n\t\t});\n\t\ttry {\n\t\t\tfor (const candidate of candidateOrder) await candidate.lifecycle.activate();\n\t\t\tfor (const candidate of candidateOrder) this.#validateReplacementProvisions(candidate.provisions);\n\t\t} catch (error) {\n\t\t\tconst cleanupErrors = await disposeFacetRecords([...candidateOrder].reverse());\n\t\t\tif (cleanupErrors.length > 0) {\n\t\t\t\tconst abortErrors = await this.#abort();\n\t\t\t\tthrow new AggregateError(\n\t\t\t\t\t[error, ...cleanupErrors, ...abortErrors],\n\t\t\t\t\t\"Facet reload activation and cleanup failed\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.#phase = \"active\";\n\t\t\tthrow error;\n\t\t}\n\n\t\tconst previous = candidateOrder.map(({ facetId }) => this.#facets.get(facetId)!);\n\t\tfor (const candidate of candidateOrder) this.#facets.set(candidate.facetId, candidate);\n\t\ttry {\n\t\t\tfor (const candidate of candidateOrder) {\n\t\t\t\tfor (const provision of candidate.provisions) {\n\t\t\t\t\tif (provision.kind !== \"singleton\") continue;\n\t\t\t\t\tif (provision.service.local) {\n\t\t\t\t\t\tthis.#serviceSlots.bindSingleton(provision.service.id, provision.implementation);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tprovision.replace(this.provider);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst retirementErrors = await disposeFacetRecords(previous.reverse());\n\t\t\tif (retirementErrors.length === 1) throw retirementErrors[0];\n\t\t\tif (retirementErrors.length > 1) {\n\t\t\t\tthrow new AggregateError(retirementErrors, \"Failed to retire replaced facets\");\n\t\t\t}\n\t\t\tfor (const candidate of candidateOrder) {\n\t\t\t\tfor (const provision of candidate.provisions) {\n\t\t\t\t\tif (provision.kind !== \"keyed\") continue;\n\t\t\t\t\tif (provision.service.local) provision.connectLocal(this.#localKeyedRegistry);\n\t\t\t\t\telse provision.connectRemote(this.provider);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconst abortErrors = await this.#abort(previous);\n\t\t\tthrow new AggregateError([error, ...abortErrors], \"Facet reload failed after cutover\");\n\t\t}\n\t\tthis.#phase = \"active\";\n\t}\n\n\tasync dispose(): Promise<void> {\n\t\tif (this.#phase === \"dead\") return;\n\t\tif (this.#phase !== \"active\") throw new Error(`Facet host cannot be disposed while ${this.#phase}`);\n\t\tconst errors = await this.#terminate();\n\t\tif (errors.length === 1) throw errors[0];\n\t\tif (errors.length > 1) throw new AggregateError(errors, \"Failed to dispose facet generation\");\n\t}\n\n\t#validateReplacementProvisions(provisions: readonly FacetProvision[]): void {\n\t\tfor (const provision of provisions) {\n\t\t\tif (provision.kind !== \"singleton\" || provision.service.local) continue;\n\t\t\tprovision.validateReplacement(this.provider);\n\t\t}\n\t}\n\n\t#environment(runtime: FacetRuntime): FacetEnvironment {\n\t\tconst { lifecycle, provisions } = runtime;\n\t\treturn {\n\t\t\tprovide: <T>(service: Service<T>, implementation: NoInfer<T>): void => {\n\t\t\t\tlifecycle.assertSettingUp(\"provide services\");\n\t\t\t\tif (typeof implementation !== \"object\" || implementation === null || Array.isArray(implementation)) {\n\t\t\t\t\tthrow new TypeError(`Service ${service.id} implementation must be an object`);\n\t\t\t\t}\n\t\t\t\trecordServiceReference(runtime.provides, service, \"singleton\");\n\t\t\t\tprovisions.push({\n\t\t\t\t\tkind: \"singleton\",\n\t\t\t\t\tservice,\n\t\t\t\t\timplementation,\n\t\t\t\t\tinstall: (provider) => provider.provide(service, implementation as NoInfer<RemoteServiceContract<T>>),\n\t\t\t\t\tvalidateReplacement: (provider) =>\n\t\t\t\t\t\tprovider.validateReplacement(service, implementation as NoInfer<RemoteServiceContract<T>>),\n\t\t\t\t\treplace: (provider) => provider.replace(service, implementation as NoInfer<RemoteServiceContract<T>>),\n\t\t\t\t});\n\t\t\t},\n\t\t\tprovideMany: <T>(service: Service<T>): ServiceSpawner<T> => {\n\t\t\t\tlifecycle.assertSettingUp(\"provide service instances\");\n\t\t\t\trecordServiceReference(runtime.provides, service, \"keyed\");\n\t\t\t\tconst instances = new StagedServiceSpawner<T>(lifecycle, (key, implementation) => {\n\t\t\t\t\tif (key.length === 0) throw new TypeError(\"Facet service instance key must not be empty\");\n\t\t\t\t\tif (typeof implementation !== \"object\" || implementation === null || Array.isArray(implementation)) {\n\t\t\t\t\t\tthrow new TypeError(`Facet service ${service.id} implementation must be an object`);\n\t\t\t\t\t}\n\t\t\t\t\tif (!service.local) validateRemoteServiceImplementation(service.id, implementation);\n\t\t\t\t});\n\t\t\t\tprovisions.push({\n\t\t\t\t\tkind: \"keyed\",\n\t\t\t\t\tservice,\n\t\t\t\t\tconnectLocal: (registry) =>\n\t\t\t\t\t\tinstances.connect((key, implementation) => registry.spawn(service, key, implementation)),\n\t\t\t\t\tconnectRemote: (provider) =>\n\t\t\t\t\t\tinstances.connect((key, implementation) =>\n\t\t\t\t\t\t\tprovider.spawn(service, key, implementation as NoInfer<RemoteServiceContract<T>>),\n\t\t\t\t\t\t),\n\t\t\t\t});\n\t\t\t\treturn instances;\n\t\t\t},\n\t\t\tuse: <T>(service: Service<T>): T => {\n\t\t\t\tlifecycle.assertSettingUp(\"acquire services\");\n\t\t\t\trecordServiceReference(runtime.requires, service, \"singleton\");\n\t\t\t\tlet view = runtime.singletonViews.get(service.id);\n\t\t\t\tif (view === undefined) {\n\t\t\t\t\tview = this.#serviceSlots.getSingleton<T>(service, () => lifecycle.assertServiceAccess());\n\t\t\t\t\truntime.singletonViews.set(service.id, view);\n\t\t\t\t}\n\t\t\t\treturn view as T;\n\t\t\t},\n\t\t\tobserve: <T>(service: Service<T>, handler: (service: T, context: Context) => void | Promise<void>): void => {\n\t\t\t\tlifecycle.assertSettingUp(\"observe services\");\n\t\t\t\trecordServiceReference(runtime.requires, service, \"keyed\");\n\t\t\t\tlifecycle.observe(() =>\n\t\t\t\t\tthis.#serviceSlots.observe(service, () => lifecycle.assertServiceAccess(), handler),\n\t\t\t\t);\n\t\t\t},\n\t\t\treplicatedState: <T extends object>(initial: T) => {\n\t\t\t\tlifecycle.assertRunning(\"create replicated state\");\n\t\t\t\treturn new MutableReplicatedStateImpl(initial);\n\t\t\t},\n\t\t\town: (disposal) => lifecycle.own(disposal),\n\t\t\tonActivate: (callback) => lifecycle.onActivate(callback),\n\t\t\tonDeactivate: (callback) => lifecycle.own(callback),\n\t\t};\n\t}\n\n\tasync #resolveExternalServices(records: readonly FacetShape[]): Promise<ReadonlyMap<string, ExternalService>> {\n\t\tconst catalogues = await Promise.all(\n\t\t\tthis.#serviceSources.map(async (source) => ({\n\t\t\t\tsource,\n\t\t\t\tentries: await source.catalogue(BACKGROUND_CONTEXT),\n\t\t\t})),\n\t\t);\n\t\tconst offered = new Map<string, { readonly mode: ServiceMode; readonly source: RemoteServiceSource }>();\n\t\tfor (const { source, entries } of catalogues) {\n\t\t\tfor (const { serviceId, mode } of entries) {\n\t\t\t\tif (offered.has(serviceId)) {\n\t\t\t\t\tthrow new Error(`Facet host service ${serviceId} is offered by more than one source`);\n\t\t\t\t}\n\t\t\t\toffered.set(serviceId, { mode, source });\n\t\t\t}\n\t\t}\n\n\t\tconst local = new Set(records.flatMap(({ provides }) => provides.map(({ serviceId }) => serviceId)));\n\t\tconst external = new Map<string, ExternalService>();\n\t\tfor (const { requires } of records) {\n\t\t\tfor (const requirement of requires) {\n\t\t\t\tif (local.has(requirement.serviceId) || external.has(requirement.serviceId)) continue;\n\t\t\t\tlet source = offered.get(requirement.serviceId);\n\t\t\t\tif (source === undefined) {\n\t\t\t\t\tconst deferred = this.#serviceSources.filter(\n\t\t\t\t\t\t({ acceptsUnavailableServices }) => acceptsUnavailableServices,\n\t\t\t\t\t);\n\t\t\t\t\tif (deferred.length > 1) {\n\t\t\t\t\t\tthrow new Error(`Facet host service ${requirement.serviceId} has more than one deferred source`);\n\t\t\t\t\t}\n\t\t\t\t\tif (deferred.length === 1) source = { mode: requirement.mode, source: deferred[0]! };\n\t\t\t\t}\n\t\t\t\tif (source !== undefined) {\n\t\t\t\t\texternal.set(requirement.serviceId, { ...source, service: requirement.service });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tconst serviceIdsBySource = new Map<RemoteServiceSource, string[]>();\n\t\tfor (const [serviceId, { source }] of external) {\n\t\t\tlet serviceIds = serviceIdsBySource.get(source);\n\t\t\tif (serviceIds === undefined) {\n\t\t\t\tserviceIds = [];\n\t\t\t\tserviceIdsBySource.set(source, serviceIds);\n\t\t\t}\n\t\t\tserviceIds.push(serviceId);\n\t\t}\n\t\tfor (const [source, serviceIds] of serviceIdsBySource) {\n\t\t\tthis.#sourceBindings.set(\n\t\t\t\tsource,\n\t\t\t\tsource.open({\n\t\t\t\t\tservices: serviceIds.map((id) => ({ id })),\n\t\t\t\t\tassertAccess: () => this.#assertServiceTargetAccess(),\n\t\t\t\t\tonError: this.#onError,\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\treturn external;\n\t}\n\n\t#assembleProviders(): void {\n\t\tconst provisions = this.#provisions();\n\t\tconst remoteProvisions = provisions.filter(({ service }) => !service.local);\n\t\tconst provider = new RemoteServiceProvider(\n\t\t\tremoteProvisions.map(({ service, kind }) => ({ service, mode: kind })),\n\t\t);\n\t\tconst internalServices = new RemoteServiceBindingImpl({\n\t\t\tservices: remoteProvisions.map(({ service }) => service),\n\t\t\ttransport: createLoopbackServiceTransport(provider),\n\t\t\tassertAccess: () => this.#assertServiceTargetAccess(),\n\t\t\tonError: this.#onError,\n\t\t});\n\t\tconst localKeyedServices = new LocalKeyedServiceRegistry(\n\t\t\tprovisions.flatMap((provision) =>\n\t\t\t\tprovision.kind === \"keyed\" && provision.service.local ? [provision.service] : [],\n\t\t\t),\n\t\t\tthis.#onError,\n\t\t);\n\t\tthis.#provider = provider;\n\t\tthis.#internalServices = internalServices;\n\t\tthis.#localKeyedServices = localKeyedServices;\n\t\tfor (const provision of provisions) {\n\t\t\tif (provision.kind === \"singleton\") {\n\t\t\t\tif (!provision.service.local) provision.install(provider);\n\t\t\t} else if (provision.service.local) {\n\t\t\t\tprovision.connectLocal(localKeyedServices);\n\t\t\t} else {\n\t\t\t\tprovision.connectRemote(provider);\n\t\t\t}\n\t\t}\n\t}\n\n\t#bindServices(externalServices: ReadonlyMap<string, ExternalService>): void {\n\t\tfor (const provision of this.#provisions()) {\n\t\t\tif (provision.kind === \"singleton\") {\n\t\t\t\tif (!this.#serviceSlots.hasSingleton(provision.service.id)) continue;\n\t\t\t\tconst target = provision.service.local\n\t\t\t\t\t? provision.implementation\n\t\t\t\t\t: (this.#internalServiceBinding.use(provision.service) as object);\n\t\t\t\tthis.#serviceSlots.bindSingleton(provision.service.id, target);\n\t\t\t} else {\n\t\t\t\tthis.#serviceSlots.bindKeyed(\n\t\t\t\t\tprovision.service.id,\n\t\t\t\t\tprovision.service.local ? this.#localKeyedRegistry : this.#internalServiceBinding,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tfor (const [serviceId, { service, mode, source }] of externalServices) {\n\t\t\tconst services = this.#sourceBindings.get(source);\n\t\t\tif (services === undefined) throw new Error(`Service source for ${serviceId} is not open`);\n\t\t\tif (mode === \"singleton\") {\n\t\t\t\tthis.#serviceSlots.bindSingleton(serviceId, services.use(service) as object);\n\t\t\t} else {\n\t\t\t\tthis.#serviceSlots.bindKeyed(serviceId, services);\n\t\t\t}\n\t\t}\n\t}\n\n\t#provisions(): FacetProvision[] {\n\t\treturn [...this.#facets.values()].flatMap(({ provisions }) => provisions);\n\t}\n\n\tget #localKeyedRegistry(): LocalKeyedServiceRegistry {\n\t\tif (this.#localKeyedServices === undefined) throw new Error(\"Facet keyed services are not assembled\");\n\t\treturn this.#localKeyedServices;\n\t}\n\n\tget #internalServiceBinding(): RemoteServices {\n\t\tif (this.#internalServices === undefined) throw new Error(\"Facet remote services are not assembled\");\n\t\treturn this.#internalServices;\n\t}\n\n\tasync #disposeServiceBindings(): Promise<unknown[]> {\n\t\tconst bindings = [...this.#sourceBindings.values()];\n\t\tthis.#sourceBindings.clear();\n\t\tif (this.#internalServices !== undefined) bindings.push(this.#internalServices);\n\t\tthis.#internalServices = undefined;\n\t\tconst results = await Promise.allSettled(bindings.map((services) => services.dispose(BACKGROUND_CONTEXT)));\n\t\treturn results.flatMap((result) => (result.status === \"rejected\" ? [result.reason] : []));\n\t}\n\n\t#assertServiceTargetAccess(): void {\n\t\tif (\n\t\t\tthis.#phase !== \"activating\" &&\n\t\t\tthis.#phase !== \"active\" &&\n\t\t\tthis.#phase !== \"reloading\" &&\n\t\t\tthis.#phase !== \"disposing\"\n\t\t) {\n\t\t\tthrow new Error(`Facet service targets cannot be used during ${this.#phase}`);\n\t\t}\n\t}\n\n\tasync #abort(extraRecords: readonly FacetRuntime[] = []): Promise<unknown[]> {\n\t\tfor (const record of this.#facets.values()) record.lifecycle.revoke();\n\t\tfor (const record of extraRecords) record.lifecycle.revoke();\n\t\treturn this.#terminate(extraRecords);\n\t}\n\n\tasync #terminate(extraRecords: readonly FacetRuntime[] = []): Promise<unknown[]> {\n\t\tthis.#phase = \"disposing\";\n\t\tconst errors = await this.#disposeLifecycles();\n\t\terrors.push(...(await disposeFacetRecords([...extraRecords].reverse())));\n\t\ttry {\n\t\t\tthis.#localKeyedServices?.dispose();\n\t\t} catch (error) {\n\t\t\terrors.push(error);\n\t\t}\n\t\tthis.#localKeyedServices = undefined;\n\t\terrors.push(...(await this.#disposeServiceBindings()));\n\t\ttry {\n\t\t\tthis.#serviceSlots.dispose();\n\t\t} catch (error) {\n\t\t\terrors.push(error);\n\t\t}\n\t\ttry {\n\t\t\tthis.#provider?.dispose();\n\t\t} catch (error) {\n\t\t\terrors.push(error);\n\t\t}\n\t\tthis.#phase = \"dead\";\n\t\treturn errors;\n\t}\n\n\tasync #disposeLifecycles(): Promise<unknown[]> {\n\t\tconst errors: unknown[] = [];\n\t\tconst order =\n\t\t\tthis.#activationOrder.length > 0 ? [...this.#activationOrder].reverse() : [...this.#facets.keys()].reverse();\n\t\tfor (const id of order) {\n\t\t\tconst record = this.#facets.get(id);\n\t\t\tif (record === undefined) continue;\n\t\t\tthis.#facets.delete(id);\n\t\t\ttry {\n\t\t\t\tawait record.lifecycle.dispose();\n\t\t\t} catch (error) {\n\t\t\t\terrors.push(error);\n\t\t\t}\n\t\t}\n\t\treturn errors;\n\t}\n}\n\nasync function disposeFacetRecords(records: readonly FacetRuntime[]): Promise<unknown[]> {\n\tconst errors: unknown[] = [];\n\tfor (const record of records) {\n\t\ttry {\n\t\t\tawait record.lifecycle.dispose();\n\t\t} catch (error) {\n\t\t\terrors.push(error);\n\t\t}\n\t}\n\treturn errors;\n}\n\nfunction validateFacets(\n\trecords: readonly FacetShape[],\n\texternalServices: ReadonlyMap<string, { readonly mode: ServiceMode }>,\n): string[] {\n\tconst providers = new Map<\n\t\tstring,\n\t\t{ readonly facetId: string | undefined; readonly mode: ServiceMode | undefined }\n\t>();\n\tfor (const [serviceId, { mode }] of externalServices) providers.set(serviceId, { facetId: undefined, mode });\n\tfor (const record of records) {\n\t\tfor (const provision of record.provides) {\n\t\t\tconst existing = providers.get(provision.serviceId);\n\t\t\tif (existing !== undefined) {\n\t\t\t\tif (existing.mode !== undefined && existing.mode !== provision.mode) {\n\t\t\t\t\tthrow new Error(`Service ${provision.serviceId} is provided as both singleton and keyed`);\n\t\t\t\t}\n\t\t\t\tif (existing.facetId === undefined) {\n\t\t\t\t\tthrow new Error(`Service ${provision.serviceId} is provided by both the host and ${record.facetId}`);\n\t\t\t\t}\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Service ${provision.serviceId} is provided by both ${existing.facetId} and ${record.facetId}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tproviders.set(provision.serviceId, { facetId: record.facetId, mode: provision.mode });\n\t\t}\n\t}\n\n\tconst dependencies = new Map(records.map((record) => [record.facetId, new Set<string>()]));\n\tconst dependents = new Map(records.map((record) => [record.facetId, new Set<string>()]));\n\tfor (const record of records) {\n\t\tfor (const requirement of record.requires) {\n\t\t\tconst provider = providers.get(requirement.serviceId);\n\t\t\tif (provider === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Facet ${record.facetId} requires local/${requirement.serviceId}/${requirement.mode}, but no facet provides it`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (provider.mode !== undefined && provider.mode !== requirement.mode) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Facet ${record.facetId} requires ${requirement.serviceId} as ${requirement.mode}, but ${provider.facetId ?? \"the host\"} provides it as ${provider.mode}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (provider.facetId === undefined || provider.facetId === record.facetId) continue;\n\t\t\tdependencies.get(record.facetId)!.add(provider.facetId);\n\t\t\tdependents.get(provider.facetId)!.add(record.facetId);\n\t\t}\n\t}\n\treturn topologicalOrder(records, dependencies, dependents);\n}\n\nfunction topologicalOrder(\n\trecords: readonly FacetShape[],\n\tdependencies: ReadonlyMap<string, ReadonlySet<string>>,\n\tdependents: ReadonlyMap<string, ReadonlySet<string>>,\n): string[] {\n\tconst remaining = new Map([...dependencies].map(([id, values]) => [id, values.size]));\n\tconst ready = records.map((record) => record.facetId).filter((id) => remaining.get(id) === 0);\n\tconst order: string[] = [];\n\twhile (ready.length > 0) {\n\t\tconst id = ready.shift()!;\n\t\torder.push(id);\n\t\tfor (const dependent of dependents.get(id) ?? []) {\n\t\t\tconst count = remaining.get(dependent)! - 1;\n\t\t\tremaining.set(dependent, count);\n\t\t\tif (count === 0) ready.push(dependent);\n\t\t}\n\t}\n\tif (order.length !== records.length) {\n\t\tconst cycle = records.map((record) => record.facetId).filter((id) => remaining.get(id)! > 0);\n\t\tthrow new Error(`Facet dependency cycle: ${cycle.join(\", \")}`);\n\t}\n\treturn order;\n}\n\nfunction recordServiceReference(\n\ttarget: FacetServiceReference[],\n\tservice: { readonly id: string },\n\tmode: ServiceMode,\n): void {\n\tif (target.some((reference) => reference.serviceId === service.id && reference.mode === mode)) return;\n\ttarget.push({ serviceId: service.id, service: service as Service<unknown>, mode });\n}\n\nfunction sameFacetShape(left: FacetShape, right: FacetShape): boolean {\n\treturn sameReferences(left.requires, right.requires) && sameReferences(left.provides, right.provides);\n}\n\nfunction sameReferences(left: readonly FacetServiceReference[], right: readonly FacetServiceReference[]): boolean {\n\treturn (\n\t\tleft.length === right.length &&\n\t\tleft.every((reference) =>\n\t\t\tright.some((other) => other.serviceId === reference.serviceId && other.mode === reference.mode),\n\t\t)\n\t);\n}\n\nfunction isPromiseLike(value: unknown): value is PromiseLike<unknown> {\n\treturn typeof value === \"object\" && value !== null && \"then\" in value && typeof value.then === \"function\";\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import type { LoadedFacets } from "../types.ts";
2
+ export declare function disposeLoadedFacets(loaded: readonly LoadedFacets[]): Promise<unknown[]>;
3
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/facets/loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAG7F","sourcesContent":["import type { LoadedFacets } from \"../types.ts\";\n\nexport async function disposeLoadedFacets(loaded: readonly LoadedFacets[]): Promise<unknown[]> {\n\tconst results = await Promise.allSettled(loaded.map((entry) => entry.dispose()));\n\treturn results.flatMap((result) => (result.status === \"rejected\" ? [result.reason] : []));\n}\n"]}
@@ -0,0 +1,5 @@
1
+ export async function disposeLoadedFacets(loaded) {
2
+ const results = await Promise.allSettled(loaded.map((entry) => entry.dispose()));
3
+ return results.flatMap((result) => (result.status === "rejected" ? [result.reason] : []));
4
+ }
5
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/facets/loader.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,MAA+B,EAAsB;IAC9F,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IACjF,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAAA,CAC1F","sourcesContent":["import type { LoadedFacets } from \"../types.ts\";\n\nexport async function disposeLoadedFacets(loaded: readonly LoadedFacets[]): Promise<unknown[]> {\n\tconst results = await Promise.allSettled(loaded.map((entry) => entry.dispose()));\n\treturn results.flatMap((result) => (result.status === \"rejected\" ? [result.reason] : []));\n}\n"]}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Chord is a standalone application-composition runtime for agentic applications.
3
+ */
4
+ export { combineFacetLoaders, createFacetHost, createRemoteServiceBinding, createStaticFacetLoader, defineFacet, defineService, replicatedState, } from "./api.ts";
5
+ export { isJsonValue } from "./json.ts";
6
+ export { isRemoteServiceErrorCode, REMOTE_SERVICE_ERROR_CODES, RemoteServiceError, type RemoteServiceErrorCode, } from "./services/errors.ts";
7
+ export { createRemoteServiceEndpoint, type RemoteServiceEndpoint, RemoteServiceProvider, type ServiceUpdatePublisher, } from "./services/provider.ts";
8
+ export { createServiceStateDecoder, createServiceStateEncoder, type ServiceStateDecoder, type ServiceStateEncoder, } from "./services/state-codec.ts";
9
+ export { createServiceCatalogueCall, createServiceSubscribeCall, createServiceUnsubscribeCall, decodeServiceControlCall, parseServiceCall, parseServiceCatalogue, parseServiceProviderUpdate, parseServiceSubscriptionSnapshot, parseWireServiceProviderUpdate, parseWireServiceSubscriptionSnapshot, type ServiceControlCall, type WireServiceInstanceSnapshot, type WireServiceMemberSnapshot, type WireServiceProviderUpdate, type WireServiceSubscriptionSnapshot, } from "./services/wire.ts";
10
+ export type { Context, ContextKey, Facet, FacetEnvironment, FacetHost, FacetLoader, FacetOptions, JsonRepresentation, JsonValue, LoadedFacets, MutableReplicatedState, RemoteServiceBinding, RemoteServiceBindingOptions, RemoteServiceSource, RemoteServices, RemoteServiceTransport, ReplicatedState, ReplicatedStateDelivery, Service, ServiceCall, ServiceCatalogueEntry, ServiceInstanceAddress, ServiceInstanceSnapshot, ServiceMemberSnapshot, ServiceMode, ServiceProviderUpdate, ServiceSpawner, ServiceSubscription, ServiceSubscriptionSnapshot, } from "./types.ts";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACN,mBAAmB,EACnB,eAAe,EACf,0BAA0B,EAC1B,uBAAuB,EACvB,WAAW,EACX,aAAa,EACb,eAAe,GACf,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EACN,wBAAwB,EACxB,0BAA0B,EAC1B,kBAAkB,EAClB,KAAK,sBAAsB,GAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,2BAA2B,EAC3B,KAAK,qBAAqB,EAC1B,qBAAqB,EACrB,KAAK,sBAAsB,GAC3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,yBAAyB,EACzB,yBAAyB,EACzB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,GACxB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACN,0BAA0B,EAC1B,0BAA0B,EAC1B,4BAA4B,EAC5B,wBAAwB,EACxB,gBAAgB,EAChB,qBAAqB,EACrB,0BAA0B,EAC1B,gCAAgC,EAChC,8BAA8B,EAC9B,oCAAoC,EACpC,KAAK,kBAAkB,EACvB,KAAK,2BAA2B,EAChC,KAAK,yBAAyB,EAC9B,KAAK,yBAAyB,EAC9B,KAAK,+BAA+B,GACpC,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACX,OAAO,EACP,UAAU,EACV,KAAK,EACL,gBAAgB,EAChB,SAAS,EACT,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,SAAS,EACT,YAAY,EACZ,sBAAsB,EACtB,oBAAoB,EACpB,2BAA2B,EAC3B,mBAAmB,EACnB,cAAc,EACd,sBAAsB,EACtB,eAAe,EACf,uBAAuB,EACvB,OAAO,EACP,WAAW,EACX,qBAAqB,EACrB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,WAAW,EACX,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,2BAA2B,GAC3B,MAAM,YAAY,CAAC","sourcesContent":["/**\n * Chord is a standalone application-composition runtime for agentic applications.\n */\nexport {\n\tcombineFacetLoaders,\n\tcreateFacetHost,\n\tcreateRemoteServiceBinding,\n\tcreateStaticFacetLoader,\n\tdefineFacet,\n\tdefineService,\n\treplicatedState,\n} from \"./api.ts\";\nexport { isJsonValue } from \"./json.ts\";\nexport {\n\tisRemoteServiceErrorCode,\n\tREMOTE_SERVICE_ERROR_CODES,\n\tRemoteServiceError,\n\ttype RemoteServiceErrorCode,\n} from \"./services/errors.ts\";\nexport {\n\tcreateRemoteServiceEndpoint,\n\ttype RemoteServiceEndpoint,\n\tRemoteServiceProvider,\n\ttype ServiceUpdatePublisher,\n} from \"./services/provider.ts\";\nexport {\n\tcreateServiceStateDecoder,\n\tcreateServiceStateEncoder,\n\ttype ServiceStateDecoder,\n\ttype ServiceStateEncoder,\n} from \"./services/state-codec.ts\";\nexport {\n\tcreateServiceCatalogueCall,\n\tcreateServiceSubscribeCall,\n\tcreateServiceUnsubscribeCall,\n\tdecodeServiceControlCall,\n\tparseServiceCall,\n\tparseServiceCatalogue,\n\tparseServiceProviderUpdate,\n\tparseServiceSubscriptionSnapshot,\n\tparseWireServiceProviderUpdate,\n\tparseWireServiceSubscriptionSnapshot,\n\ttype ServiceControlCall,\n\ttype WireServiceInstanceSnapshot,\n\ttype WireServiceMemberSnapshot,\n\ttype WireServiceProviderUpdate,\n\ttype WireServiceSubscriptionSnapshot,\n} from \"./services/wire.ts\";\nexport type {\n\tContext,\n\tContextKey,\n\tFacet,\n\tFacetEnvironment,\n\tFacetHost,\n\tFacetLoader,\n\tFacetOptions,\n\tJsonRepresentation,\n\tJsonValue,\n\tLoadedFacets,\n\tMutableReplicatedState,\n\tRemoteServiceBinding,\n\tRemoteServiceBindingOptions,\n\tRemoteServiceSource,\n\tRemoteServices,\n\tRemoteServiceTransport,\n\tReplicatedState,\n\tReplicatedStateDelivery,\n\tService,\n\tServiceCall,\n\tServiceCatalogueEntry,\n\tServiceInstanceAddress,\n\tServiceInstanceSnapshot,\n\tServiceMemberSnapshot,\n\tServiceMode,\n\tServiceProviderUpdate,\n\tServiceSpawner,\n\tServiceSubscription,\n\tServiceSubscriptionSnapshot,\n} from \"./types.ts\";\n"]}
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Chord is a standalone application-composition runtime for agentic applications.
3
+ */
4
+ export { combineFacetLoaders, createFacetHost, createRemoteServiceBinding, createStaticFacetLoader, defineFacet, defineService, replicatedState, } from "./api.js";
5
+ export { isJsonValue } from "./json.js";
6
+ export { isRemoteServiceErrorCode, REMOTE_SERVICE_ERROR_CODES, RemoteServiceError, } from "./services/errors.js";
7
+ export { createRemoteServiceEndpoint, RemoteServiceProvider, } from "./services/provider.js";
8
+ export { createServiceStateDecoder, createServiceStateEncoder, } from "./services/state-codec.js";
9
+ export { createServiceCatalogueCall, createServiceSubscribeCall, createServiceUnsubscribeCall, decodeServiceControlCall, parseServiceCall, parseServiceCatalogue, parseServiceProviderUpdate, parseServiceSubscriptionSnapshot, parseWireServiceProviderUpdate, parseWireServiceSubscriptionSnapshot, } from "./services/wire.js";
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACN,mBAAmB,EACnB,eAAe,EACf,0BAA0B,EAC1B,uBAAuB,EACvB,WAAW,EACX,aAAa,EACb,eAAe,GACf,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EACN,wBAAwB,EACxB,0BAA0B,EAC1B,kBAAkB,GAElB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,2BAA2B,EAE3B,qBAAqB,GAErB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,yBAAyB,EACzB,yBAAyB,GAGzB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACN,0BAA0B,EAC1B,0BAA0B,EAC1B,4BAA4B,EAC5B,wBAAwB,EACxB,gBAAgB,EAChB,qBAAqB,EACrB,0BAA0B,EAC1B,gCAAgC,EAChC,8BAA8B,EAC9B,oCAAoC,GAMpC,MAAM,oBAAoB,CAAC","sourcesContent":["/**\n * Chord is a standalone application-composition runtime for agentic applications.\n */\nexport {\n\tcombineFacetLoaders,\n\tcreateFacetHost,\n\tcreateRemoteServiceBinding,\n\tcreateStaticFacetLoader,\n\tdefineFacet,\n\tdefineService,\n\treplicatedState,\n} from \"./api.ts\";\nexport { isJsonValue } from \"./json.ts\";\nexport {\n\tisRemoteServiceErrorCode,\n\tREMOTE_SERVICE_ERROR_CODES,\n\tRemoteServiceError,\n\ttype RemoteServiceErrorCode,\n} from \"./services/errors.ts\";\nexport {\n\tcreateRemoteServiceEndpoint,\n\ttype RemoteServiceEndpoint,\n\tRemoteServiceProvider,\n\ttype ServiceUpdatePublisher,\n} from \"./services/provider.ts\";\nexport {\n\tcreateServiceStateDecoder,\n\tcreateServiceStateEncoder,\n\ttype ServiceStateDecoder,\n\ttype ServiceStateEncoder,\n} from \"./services/state-codec.ts\";\nexport {\n\tcreateServiceCatalogueCall,\n\tcreateServiceSubscribeCall,\n\tcreateServiceUnsubscribeCall,\n\tdecodeServiceControlCall,\n\tparseServiceCall,\n\tparseServiceCatalogue,\n\tparseServiceProviderUpdate,\n\tparseServiceSubscriptionSnapshot,\n\tparseWireServiceProviderUpdate,\n\tparseWireServiceSubscriptionSnapshot,\n\ttype ServiceControlCall,\n\ttype WireServiceInstanceSnapshot,\n\ttype WireServiceMemberSnapshot,\n\ttype WireServiceProviderUpdate,\n\ttype WireServiceSubscriptionSnapshot,\n} from \"./services/wire.ts\";\nexport type {\n\tContext,\n\tContextKey,\n\tFacet,\n\tFacetEnvironment,\n\tFacetHost,\n\tFacetLoader,\n\tFacetOptions,\n\tJsonRepresentation,\n\tJsonValue,\n\tLoadedFacets,\n\tMutableReplicatedState,\n\tRemoteServiceBinding,\n\tRemoteServiceBindingOptions,\n\tRemoteServiceSource,\n\tRemoteServices,\n\tRemoteServiceTransport,\n\tReplicatedState,\n\tReplicatedStateDelivery,\n\tService,\n\tServiceCall,\n\tServiceCatalogueEntry,\n\tServiceInstanceAddress,\n\tServiceInstanceSnapshot,\n\tServiceMemberSnapshot,\n\tServiceMode,\n\tServiceProviderUpdate,\n\tServiceSpawner,\n\tServiceSubscription,\n\tServiceSubscriptionSnapshot,\n} from \"./types.ts\";\n"]}
package/dist/json.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import type { JsonValue } from "./types.ts";
2
+ /** Return whether a value is finite strict JSON with plain objects and no cycles. */
3
+ export declare function isJsonValue(value: unknown): value is JsonValue;
4
+ //# sourceMappingURL=json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,qFAAqF;AACrF,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAE9D","sourcesContent":["import type { JsonValue } from \"./types.ts\";\n\n/** Return whether a value is finite strict JSON with plain objects and no cycles. */\nexport function isJsonValue(value: unknown): value is JsonValue {\n\treturn check(value, new Set<object>(), 0);\n}\n\nfunction check(value: unknown, ancestors: Set<object>, depth: number): boolean {\n\tif (depth > 512) return false;\n\tif (value === null || typeof value === \"string\" || typeof value === \"boolean\") return true;\n\tif (typeof value === \"number\") return Number.isFinite(value);\n\tif (Array.isArray(value)) {\n\t\tconst keys = Reflect.ownKeys(value);\n\t\tif (keys.length !== value.length + 1 || keys.some((key) => typeof key !== \"string\")) return false;\n\t\tif (ancestors.has(value)) return false;\n\t\tancestors.add(value);\n\t\ttry {\n\t\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, String(index));\n\t\t\t\tif (\n\t\t\t\t\tdescriptor === undefined ||\n\t\t\t\t\t!descriptor.enumerable ||\n\t\t\t\t\t!(\"value\" in descriptor) ||\n\t\t\t\t\t!check(descriptor.value, ancestors, depth + 1)\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t} finally {\n\t\t\tancestors.delete(value);\n\t\t}\n\t}\n\tif (typeof value !== \"object\" || value === null) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\tif (prototype !== Object.prototype && prototype !== null) return false;\n\tif (Reflect.ownKeys(value).some((key) => typeof key !== \"string\")) return false;\n\tif (ancestors.has(value)) return false;\n\tancestors.add(value);\n\ttry {\n\t\tfor (const descriptor of Object.values(Object.getOwnPropertyDescriptors(value))) {\n\t\t\tif (!descriptor.enumerable || !(\"value\" in descriptor) || !check(descriptor.value, ancestors, depth + 1)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t} finally {\n\t\tancestors.delete(value);\n\t}\n}\n"]}
package/dist/json.js ADDED
@@ -0,0 +1,57 @@
1
+ /** Return whether a value is finite strict JSON with plain objects and no cycles. */
2
+ export function isJsonValue(value) {
3
+ return check(value, new Set(), 0);
4
+ }
5
+ function check(value, ancestors, depth) {
6
+ if (depth > 512)
7
+ return false;
8
+ if (value === null || typeof value === "string" || typeof value === "boolean")
9
+ return true;
10
+ if (typeof value === "number")
11
+ return Number.isFinite(value);
12
+ if (Array.isArray(value)) {
13
+ const keys = Reflect.ownKeys(value);
14
+ if (keys.length !== value.length + 1 || keys.some((key) => typeof key !== "string"))
15
+ return false;
16
+ if (ancestors.has(value))
17
+ return false;
18
+ ancestors.add(value);
19
+ try {
20
+ for (let index = 0; index < value.length; index++) {
21
+ const descriptor = Object.getOwnPropertyDescriptor(value, String(index));
22
+ if (descriptor === undefined ||
23
+ !descriptor.enumerable ||
24
+ !("value" in descriptor) ||
25
+ !check(descriptor.value, ancestors, depth + 1)) {
26
+ return false;
27
+ }
28
+ }
29
+ return true;
30
+ }
31
+ finally {
32
+ ancestors.delete(value);
33
+ }
34
+ }
35
+ if (typeof value !== "object" || value === null)
36
+ return false;
37
+ const prototype = Object.getPrototypeOf(value);
38
+ if (prototype !== Object.prototype && prototype !== null)
39
+ return false;
40
+ if (Reflect.ownKeys(value).some((key) => typeof key !== "string"))
41
+ return false;
42
+ if (ancestors.has(value))
43
+ return false;
44
+ ancestors.add(value);
45
+ try {
46
+ for (const descriptor of Object.values(Object.getOwnPropertyDescriptors(value))) {
47
+ if (!descriptor.enumerable || !("value" in descriptor) || !check(descriptor.value, ancestors, depth + 1)) {
48
+ return false;
49
+ }
50
+ }
51
+ return true;
52
+ }
53
+ finally {
54
+ ancestors.delete(value);
55
+ }
56
+ }
57
+ //# sourceMappingURL=json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.js","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAEA,qFAAqF;AACrF,MAAM,UAAU,WAAW,CAAC,KAAc,EAAsB;IAC/D,OAAO,KAAK,CAAC,KAAK,EAAE,IAAI,GAAG,EAAU,EAAE,CAAC,CAAC,CAAC;AAAA,CAC1C;AAED,SAAS,KAAK,CAAC,KAAc,EAAE,SAAsB,EAAE,KAAa,EAAW;IAC9E,IAAI,KAAK,GAAG,GAAG;QAAE,OAAO,KAAK,CAAC;IAC9B,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAC3F,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC7D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACpC,IAAI,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC;YAAE,OAAO,KAAK,CAAC;QAClG,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACvC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACrB,IAAI,CAAC;YACJ,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG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CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;gBAC1G,OAAO,KAAK,CAAC;YACd,CAAC;QACF,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;YAAS,CAAC;QACV,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;AAAA,CACD","sourcesContent":["import type { JsonValue } from \"./types.ts\";\n\n/** Return whether a value is finite strict JSON with plain objects and no cycles. */\nexport function isJsonValue(value: unknown): value is JsonValue {\n\treturn check(value, new Set<object>(), 0);\n}\n\nfunction check(value: unknown, ancestors: Set<object>, depth: number): boolean {\n\tif (depth > 512) return false;\n\tif (value === null || typeof value === \"string\" || typeof value === \"boolean\") return true;\n\tif (typeof value === \"number\") return Number.isFinite(value);\n\tif (Array.isArray(value)) {\n\t\tconst keys = Reflect.ownKeys(value);\n\t\tif (keys.length !== value.length + 1 || keys.some((key) => typeof key !== \"string\")) return false;\n\t\tif (ancestors.has(value)) return false;\n\t\tancestors.add(value);\n\t\ttry {\n\t\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, String(index));\n\t\t\t\tif (\n\t\t\t\t\tdescriptor === undefined ||\n\t\t\t\t\t!descriptor.enumerable ||\n\t\t\t\t\t!(\"value\" in descriptor) ||\n\t\t\t\t\t!check(descriptor.value, ancestors, depth + 1)\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t} finally {\n\t\t\tancestors.delete(value);\n\t\t}\n\t}\n\tif (typeof value !== \"object\" || value === null) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\tif (prototype !== Object.prototype && prototype !== null) return false;\n\tif (Reflect.ownKeys(value).some((key) => typeof key !== \"string\")) return false;\n\tif (ancestors.has(value)) return false;\n\tancestors.add(value);\n\ttry {\n\t\tfor (const descriptor of Object.values(Object.getOwnPropertyDescriptors(value))) {\n\t\t\tif (!descriptor.enumerable || !(\"value\" in descriptor) || !check(descriptor.value, ancestors, depth + 1)) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t} finally {\n\t\tancestors.delete(value);\n\t}\n}\n"]}
@@ -0,0 +1,30 @@
1
+ import type { FacetLoader } from "../types.ts";
2
+ import { type FacetBundleArtifact, type FacetBundleManifest } from "./manifest.ts";
3
+ export type FacetBundleExternalResolver = (specifier: string) => string | URL | undefined;
4
+ export interface FacetBundleLoaderOptions {
5
+ readonly manifestPath: string | URL;
6
+ readonly entry: string;
7
+ /** Verify the entry's SHA-256 integrity before evaluating it. Defaults to true. */
8
+ readonly verifyIntegrity?: boolean;
9
+ /** Resolve host-provided external imports when the bundle is outside the host's package tree. */
10
+ readonly resolveExternal?: FacetBundleExternalResolver;
11
+ }
12
+ export interface FacetBundleArtifactLoaderOptions {
13
+ readonly artifact: unknown;
14
+ /** Resolve host-provided external imports against the receiving application. */
15
+ readonly resolveExternal?: FacetBundleExternalResolver;
16
+ /** Parent directory for materialized module generations. Defaults to the operating system temp directory. */
17
+ readonly temporaryDirectory?: string;
18
+ }
19
+ /** Read and validate a versioned facet bundle manifest. */
20
+ export declare function readFacetBundleManifest(path: string | URL): Promise<FacetBundleManifest>;
21
+ /** Read and verify one transportable entry from a facet bundle on disk. */
22
+ export declare function readFacetBundleArtifact(options: {
23
+ readonly manifestPath: string | URL;
24
+ readonly entry: string;
25
+ }): Promise<FacetBundleArtifact>;
26
+ /** Materialize a transported artifact and create a fresh VM-compiled CommonJS generation for each load. */
27
+ export declare function createFacetBundleArtifactLoader(options: FacetBundleArtifactLoaderOptions): FacetLoader;
28
+ /** Create a reusable loader for one opaque entry in a facet bundle manifest. */
29
+ export declare function createFacetBundleLoader(options: FacetBundleLoaderOptions): FacetLoader;
30
+ //# sourceMappingURL=bundle-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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AAG,WAAW,CAmCtF","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { mkdir, mkdtemp, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { createRequire, isBuiltin } from \"node:module\";\nimport { tmpdir } from \"node:os\";\nimport { basename, dirname, isAbsolute, join, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { compileFunction } from \"node:vm\";\nimport type { Facet, FacetLoader, LoadedFacets } from \"../types.ts\";\nimport {\n\tFACET_BUNDLE_ARTIFACT_FORMAT,\n\tFACET_BUNDLE_ARTIFACT_FORMAT_VERSION,\n\tFACET_BUNDLE_FORMAT,\n\tFACET_BUNDLE_FORMAT_VERSION,\n\tFACET_BUNDLE_MANIFEST_FILE,\n\ttype FacetBundleArtifact,\n\ttype FacetBundleEntry,\n\ttype FacetBundleManifest,\n} from \"./manifest.ts\";\n\nexport type FacetBundleExternalResolver = (specifier: string) => string | URL | undefined;\n\nexport interface FacetBundleLoaderOptions {\n\treadonly manifestPath: string | URL;\n\treadonly entry: string;\n\t/** Verify the entry's SHA-256 integrity before evaluating it. Defaults to true. */\n\treadonly verifyIntegrity?: boolean;\n\t/** Resolve host-provided external imports when the bundle is outside the host's package tree. */\n\treadonly resolveExternal?: FacetBundleExternalResolver;\n}\n\nexport interface FacetBundleArtifactLoaderOptions {\n\treadonly artifact: unknown;\n\t/** Resolve host-provided external imports against the receiving application. */\n\treadonly resolveExternal?: FacetBundleExternalResolver;\n\t/** Parent directory for materialized module generations. Defaults to the operating system temp directory. */\n\treadonly temporaryDirectory?: string;\n}\n\ninterface CommonJsModule {\n\texports: unknown;\n}\n\n/** Read and validate a versioned facet bundle manifest. */\nexport async function readFacetBundleManifest(path: string | URL): Promise<FacetBundleManifest> {\n\tconst manifestPath = toFilePath(path);\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(await readFile(manifestPath, \"utf8\"));\n\t} catch (error) {\n\t\tthrow new Error(`Could not read facet bundle manifest ${manifestPath}`, { cause: error });\n\t}\n\treturn validateManifest(parsed, manifestPath);\n}\n\n/** Read and verify one transportable entry from a facet bundle on disk. */\nexport async function readFacetBundleArtifact(options: {\n\treadonly manifestPath: string | URL;\n\treadonly entry: string;\n}): Promise<FacetBundleArtifact> {\n\tif (options.entry.length === 0) throw new TypeError(\"Facet bundle entry name must not be empty\");\n\tconst manifestPath = toFilePath(options.manifestPath);\n\tconst manifest = await readFacetBundleManifest(manifestPath);\n\tconst entry = manifest.entries[options.entry];\n\tif (entry === undefined) throw new Error(`Facet bundle ${manifest.plugin.id} has no entry named ${options.entry}`);\n\tconst modulePath = resolveBundleFile(manifestPath, entry.file, \"entry\");\n\tconst source = await readFile(modulePath, \"utf8\");\n\tverifySource(source, entry);\n\tconst sourceMapContents =\n\t\tentry.sourceMap === undefined\n\t\t\t? undefined\n\t\t\t: await readFile(resolveBundleFile(manifestPath, entry.sourceMap, \"source map\"), \"utf8\");\n\treturn Object.freeze({\n\t\tformat: FACET_BUNDLE_ARTIFACT_FORMAT,\n\t\tformatVersion: FACET_BUNDLE_ARTIFACT_FORMAT_VERSION,\n\t\tplugin: manifest.plugin,\n\t\tentryName: options.entry,\n\t\tentry,\n\t\tsource,\n\t\t...(sourceMapContents === undefined ? {} : { sourceMapContents }),\n\t});\n}\n\n/** Materialize a transported artifact and create a fresh VM-compiled CommonJS generation for each load. */\nexport function createFacetBundleArtifactLoader(options: FacetBundleArtifactLoaderOptions): FacetLoader {\n\tconst artifact = validateArtifact(options.artifact);\n\tconst temporaryParent = resolve(options.temporaryDirectory ?? tmpdir());\n\treturn {\n\t\tasync load(): Promise<LoadedFacets> {\n\t\t\tawait mkdir(temporaryParent, { recursive: true });\n\t\t\tconst directory = await mkdtemp(join(temporaryParent, \"chord-facet-\"));\n\t\t\ttry {\n\t\t\t\tawait materializeArtifact(directory, artifact);\n\t\t\t\tconst loaded = await createFacetBundleLoader({\n\t\t\t\t\tmanifestPath: join(directory, FACET_BUNDLE_MANIFEST_FILE),\n\t\t\t\t\tentry: artifact.entryName,\n\t\t\t\t\tresolveExternal: options.resolveExternal,\n\t\t\t\t}).load();\n\t\t\t\tlet disposed = false;\n\t\t\t\treturn {\n\t\t\t\t\tget facets() {\n\t\t\t\t\t\treturn loaded.facets;\n\t\t\t\t\t},\n\t\t\t\t\tasync dispose() {\n\t\t\t\t\t\tif (disposed) return;\n\t\t\t\t\t\tdisposed = true;\n\t\t\t\t\t\tconst errors: unknown[] = [];\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait loaded.dispose();\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\terrors.push(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait rm(directory, { force: true, recursive: true });\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\terrors.push(error);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (errors.length === 1) throw errors[0];\n\t\t\t\t\t\tif (errors.length > 1) throw new AggregateError(errors, \"Failed to dispose facet bundle artifact\");\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} catch (error) {\n\t\t\t\ttry {\n\t\t\t\t\tawait rm(directory, { force: true, recursive: true });\n\t\t\t\t} catch (cleanupError) {\n\t\t\t\t\tthrow new AggregateError([error, cleanupError], \"Facet bundle artifact loading and cleanup failed\");\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t};\n}\n\n/** Create a reusable loader for one opaque entry in a facet bundle manifest. */\nexport function createFacetBundleLoader(options: FacetBundleLoaderOptions): FacetLoader {\n\tif (options.entry.length === 0) throw new TypeError(\"Facet bundle entry name must not be empty\");\n\tconst manifestPath = toFilePath(options.manifestPath);\n\treturn {\n\t\tasync load(): Promise<LoadedFacets> {\n\t\t\tconst manifest = await readFacetBundleManifest(manifestPath);\n\t\t\tconst entry = manifest.entries[options.entry];\n\t\t\tif (entry === undefined) {\n\t\t\t\tthrow new Error(`Facet bundle ${manifest.plugin.id} has no entry named ${options.entry}`);\n\t\t\t}\n\t\t\tconst modulePath = resolveBundleFile(manifestPath, entry.file, \"entry\");\n\t\t\ttry {\n\t\t\t\tconst source = await readFile(modulePath, \"utf8\");\n\t\t\t\tif (options.verifyIntegrity !== false) verifySource(source, entry);\n\t\t\t\tconst exported = executeCommonJsModule(source, modulePath, entry.externalImports, options.resolveExternal);\n\t\t\t\tlet facets = facetsFromModule(exported, manifest.plugin.id, options.entry);\n\t\t\t\tlet disposed = false;\n\t\t\t\treturn {\n\t\t\t\t\tget facets() {\n\t\t\t\t\t\treturn facets;\n\t\t\t\t\t},\n\t\t\t\t\tasync dispose() {\n\t\t\t\t\t\tif (disposed) return;\n\t\t\t\t\t\tdisposed = true;\n\t\t\t\t\t\tfacets = Object.freeze([]);\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} catch (error) {\n\t\t\t\tconst detail = error instanceof Error ? `: ${error.message}` : \"\";\n\t\t\t\tthrow new Error(`Could not load facet bundle entry ${manifest.plugin.id}/${options.entry}${detail}`, {\n\t\t\t\t\tcause: error,\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t};\n}\n\nfunction executeCommonJsModule(\n\tsource: string,\n\tmodulePath: string,\n\texternalImports: readonly string[],\n\tresolver?: FacetBundleExternalResolver,\n): unknown {\n\tconst requireFromModule = createRequire(modulePath);\n\tconst externalTargets = new Map<string, string>();\n\tfor (const specifier of externalImports) {\n\t\tif (!isBuiltin(specifier)) validatePackageSpecifier(specifier);\n\t\texternalTargets.set(specifier, toRequireSpecifier(resolveExternalTarget(specifier, resolver)));\n\t}\n\tconst targetFor = (specifier: string): string => {\n\t\tconst target = externalTargets.get(specifier);\n\t\tif (target === undefined) throw new Error(`Facet bundle required undeclared external import: ${specifier}`);\n\t\treturn target;\n\t};\n\tconst requireExternal = Object.assign((specifier: string): unknown => requireFromModule(targetFor(specifier)), {\n\t\tresolve: (specifier: string): string => requireFromModule.resolve(targetFor(specifier)),\n\t});\n\tconst commonJsModule: CommonJsModule = { exports: Object.create(null) };\n\tconst compiled = compileFunction(source, [\"exports\", \"require\", \"module\", \"__filename\", \"__dirname\"], {\n\t\tfilename: modulePath,\n\t});\n\tReflect.apply(compiled, commonJsModule.exports, [\n\t\tcommonJsModule.exports,\n\t\trequireExternal,\n\t\tcommonJsModule,\n\t\tmodulePath,\n\t\tdirname(modulePath),\n\t]);\n\treturn commonJsModule.exports;\n}\n\nfunction toRequireSpecifier(target: string): string {\n\tif (isAbsolute(target) || isBuiltin(target)) return target;\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(target);\n\t} catch {\n\t\treturn target;\n\t}\n\tif (url.protocol === \"file:\") return fileURLToPath(url);\n\tif (url.protocol === \"node:\") return url.href;\n\tthrow new Error(`Facet bundle external target must be a file, package, or built-in module: ${target}`);\n}\n\nfunction toFilePath(path: string | URL): string {\n\tif (typeof path === \"string\") return resolve(path);\n\tif (path.protocol !== \"file:\") throw new TypeError(`Facet bundle manifest must be a file URL, not ${path.protocol}`);\n\treturn fileURLToPath(path);\n}\n\nfunction resolveBundleFile(manifestPath: string, file: string, label: string): string {\n\tif (file.length === 0 || isAbsolute(file) || basename(file) !== file || file === \".\" || file === \"..\") {\n\t\tthrow new Error(`Facet bundle ${label} must be a filename relative to its manifest`);\n\t}\n\treturn resolve(dirname(manifestPath), file);\n}\n\nfunction verifySource(source: string, entry: FacetBundleEntry): void {\n\tconst expected = parseIntegrity(entry.integrity);\n\tconst actual = createHash(\"sha256\").update(source, \"utf8\").digest(\"base64\");\n\tif (actual !== expected) throw new Error(`Facet bundle integrity check failed for ${entry.file}`);\n}\n\nfunction parseIntegrity(integrity: string): string {\n\tconst prefix = \"sha256-\";\n\tif (!integrity.startsWith(prefix) || integrity.length === prefix.length) {\n\t\tthrow new Error(\"Facet bundle entry has an invalid SHA-256 integrity value\");\n\t}\n\treturn integrity.slice(prefix.length);\n}\n\nfunction facetsFromModule(imported: unknown, pluginId: string, entryName: string): readonly Facet[] {\n\tif (!isRecord(imported)) throw new Error(`Facet bundle entry ${pluginId}/${entryName} did not export a module`);\n\tconst exported = imported.default;\n\tconst candidates: readonly unknown[] = Array.isArray(exported) ? (exported as readonly unknown[]) : [exported];\n\tif (candidates.length === 0) {\n\t\tthrow new Error(`Facet bundle entry ${pluginId}/${entryName} exported no facets`);\n\t}\n\tconst facets: Facet[] = [];\n\tfor (const candidate of candidates) {\n\t\tif (!isRecord(candidate) || typeof candidate.id !== \"string\" || candidate.id.length === 0) {\n\t\t\tthrow new Error(`Facet bundle entry ${pluginId}/${entryName} has a facet with an invalid ID`);\n\t\t}\n\t\tif (typeof candidate.setup !== \"function\") {\n\t\t\tthrow new Error(`Facet bundle entry ${pluginId}/${entryName} facet ${candidate.id} has no setup function`);\n\t\t}\n\t\tfacets.push(candidate as unknown as Facet);\n\t}\n\tconst ids = facets.map(({ id }) => id);\n\tif (new Set(ids).size !== ids.length) {\n\t\tthrow new Error(`Facet bundle entry ${pluginId}/${entryName} exports duplicate facet IDs`);\n\t}\n\treturn Object.freeze(facets);\n}\n\nfunction validateArtifact(value: unknown): FacetBundleArtifact {\n\tif (\n\t\t!isRecord(value) ||\n\t\tvalue.format !== FACET_BUNDLE_ARTIFACT_FORMAT ||\n\t\tvalue.formatVersion !== FACET_BUNDLE_ARTIFACT_FORMAT_VERSION ||\n\t\ttypeof value.entryName !== \"string\" ||\n\t\tvalue.entryName.length === 0 ||\n\t\ttypeof value.source !== \"string\"\n\t) {\n\t\tthrow new Error(\"Invalid facet bundle artifact\");\n\t}\n\tconst manifest = validateManifest(\n\t\t{\n\t\t\tformat: FACET_BUNDLE_FORMAT,\n\t\t\tformatVersion: FACET_BUNDLE_FORMAT_VERSION,\n\t\t\tplugin: value.plugin,\n\t\t\tentries: { [value.entryName]: value.entry },\n\t\t},\n\t\t\"facet bundle artifact\",\n\t);\n\tconst entry = manifest.entries[value.entryName]!;\n\tif (entry.sourceMap === undefined) {\n\t\tif (value.sourceMapContents !== undefined) {\n\t\t\tthrow new Error(\"Facet bundle artifact has source map contents without a source map\");\n\t\t}\n\t} else if (typeof value.sourceMapContents !== \"string\") {\n\t\tthrow new Error(\"Facet bundle artifact is missing its source map contents\");\n\t}\n\tverifySource(value.source, entry);\n\treturn Object.freeze({\n\t\tformat: FACET_BUNDLE_ARTIFACT_FORMAT,\n\t\tformatVersion: FACET_BUNDLE_ARTIFACT_FORMAT_VERSION,\n\t\tplugin: manifest.plugin,\n\t\tentryName: value.entryName,\n\t\tentry,\n\t\tsource: value.source,\n\t\t...(value.sourceMapContents === undefined ? {} : { sourceMapContents: value.sourceMapContents }),\n\t});\n}\n\nasync function materializeArtifact(directory: string, artifact: FacetBundleArtifact): Promise<void> {\n\tconst manifest: FacetBundleManifest = {\n\t\tformat: FACET_BUNDLE_FORMAT,\n\t\tformatVersion: FACET_BUNDLE_FORMAT_VERSION,\n\t\tplugin: artifact.plugin,\n\t\tentries: { [artifact.entryName]: artifact.entry },\n\t};\n\tawait Promise.all([\n\t\twriteFile(join(directory, artifact.entry.file), artifact.source, \"utf8\"),\n\t\twriteFile(join(directory, FACET_BUNDLE_MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}\\n`, \"utf8\"),\n\t\t...(artifact.entry.sourceMap === undefined\n\t\t\t? []\n\t\t\t: [writeFile(join(directory, artifact.entry.sourceMap), artifact.sourceMapContents!, \"utf8\")]),\n\t]);\n}\n\nfunction resolveExternalTarget(specifier: string, resolver?: FacetBundleExternalResolver): string {\n\tconst resolved = resolver?.(specifier);\n\tif (resolved !== undefined) return typeof resolved === \"string\" ? resolved : resolved.href;\n\tconst extension = import.meta.url.endsWith(\".ts\") ? \"ts\" : \"js\";\n\tif (specifier === \"@earendil-works/chord\") return new URL(`../index.${extension}`, import.meta.url).href;\n\tif (specifier === \"@earendil-works/chord/context\") {\n\t\treturn new URL(`../context/index.${extension}`, import.meta.url).href;\n\t}\n\tif (specifier === \"@earendil-works/chord/node\") return new URL(`../node.${extension}`, import.meta.url).href;\n\treturn import.meta.resolve(specifier);\n}\n\nfunction validatePackageSpecifier(specifier: string): void {\n\tconst segments = specifier.split(\"/\");\n\tconst packageParts = specifier.startsWith(\"@\") ? 2 : 1;\n\tif (\n\t\tspecifier.startsWith(\".\") ||\n\t\tspecifier.startsWith(\"/\") ||\n\t\tspecifier.startsWith(\"#\") ||\n\t\tspecifier.includes(\":\") ||\n\t\tspecifier.includes(\"\\\\\") ||\n\t\tsegments.length < packageParts ||\n\t\tsegments.some((part) => part.length === 0 || part === \".\" || part === \"..\")\n\t) {\n\t\tthrow new Error(`Facet bundle artifact has an unsupported external import: ${specifier}`);\n\t}\n}\n\nfunction validateManifest(value: unknown, path: string): FacetBundleManifest {\n\tif (!isRecord(value) || value.format !== FACET_BUNDLE_FORMAT) {\n\t\tthrow new Error(`Invalid facet bundle manifest format in ${path}`);\n\t}\n\tif (value.formatVersion !== FACET_BUNDLE_FORMAT_VERSION) {\n\t\tthrow new Error(`Unsupported facet bundle manifest version in ${path}: ${String(value.formatVersion)}`);\n\t}\n\tif (!isRecord(value.plugin) || typeof value.plugin.id !== \"string\" || value.plugin.id.length === 0) {\n\t\tthrow new Error(`Facet bundle manifest has an invalid plugin identity in ${path}`);\n\t}\n\tif (\n\t\tvalue.plugin.version !== undefined &&\n\t\t(typeof value.plugin.version !== \"string\" || value.plugin.version.length === 0)\n\t) {\n\t\tthrow new Error(`Facet bundle manifest has an invalid plugin version in ${path}`);\n\t}\n\tif (!isRecord(value.entries) || Object.keys(value.entries).length === 0) {\n\t\tthrow new Error(`Facet bundle manifest has no entries in ${path}`);\n\t}\n\tconst entries: Record<string, FacetBundleEntry> = {};\n\tfor (const [name, candidate] of Object.entries(value.entries)) {\n\t\tif (name.length === 0 || !isRecord(candidate)) {\n\t\t\tthrow new Error(`Facet bundle manifest has an invalid entry in ${path}`);\n\t\t}\n\t\tif (typeof candidate.file !== \"string\") throw new Error(`Facet bundle entry ${name} has no file`);\n\t\tresolveBundleFile(path, candidate.file, `entry ${name}`);\n\t\tif (typeof candidate.integrity !== \"string\") throw new Error(`Facet bundle entry ${name} has no integrity`);\n\t\tparseIntegrity(candidate.integrity);\n\t\tif (\n\t\t\t!Array.isArray(candidate.externalImports) ||\n\t\t\tcandidate.externalImports.some((item) => typeof item !== \"string\")\n\t\t) {\n\t\t\tthrow new Error(`Facet bundle entry ${name} has invalid external imports`);\n\t\t}\n\t\tconst externalImports = Object.freeze([...(candidate.externalImports as readonly string[])]);\n\t\tif (new Set(externalImports).size !== externalImports.length) {\n\t\t\tthrow new Error(`Facet bundle entry ${name} has duplicate external imports`);\n\t\t}\n\t\tif (candidate.sourceMap !== undefined) {\n\t\t\tif (typeof candidate.sourceMap !== \"string\")\n\t\t\t\tthrow new Error(`Facet bundle entry ${name} has an invalid source map`);\n\t\t\tresolveBundleFile(path, candidate.sourceMap, `entry ${name} source map`);\n\t\t}\n\t\tentries[name] = Object.freeze({\n\t\t\tfile: candidate.file,\n\t\t\tintegrity: candidate.integrity,\n\t\t\texternalImports,\n\t\t\t...(candidate.sourceMap === undefined ? {} : { sourceMap: candidate.sourceMap }),\n\t\t});\n\t}\n\treturn Object.freeze({\n\t\tformat: FACET_BUNDLE_FORMAT,\n\t\tformatVersion: FACET_BUNDLE_FORMAT_VERSION,\n\t\tplugin: Object.freeze({\n\t\t\tid: value.plugin.id,\n\t\t\t...(value.plugin.version === undefined ? {} : { version: value.plugin.version }),\n\t\t}),\n\t\tentries: Object.freeze(entries),\n\t});\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n"]}