@earendil-works/chord 0.87.0 → 0.99.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 (99) hide show
  1. package/README.md +80 -27
  2. package/dist/api.d.ts +6 -1
  3. package/dist/api.d.ts.map +1 -1
  4. package/dist/api.js +8 -3
  5. package/dist/api.js.map +1 -1
  6. package/dist/bundler.d.ts.map +1 -1
  7. package/dist/context/index.d.ts.map +1 -1
  8. package/dist/context/index.js.map +1 -1
  9. package/dist/delta/apply-immutable-trusted.d.ts +4 -0
  10. package/dist/delta/apply-immutable-trusted.d.ts.map +1 -0
  11. package/dist/delta/apply-immutable-trusted.js +127 -0
  12. package/dist/delta/apply-immutable-trusted.js.map +1 -0
  13. package/dist/{state → delta}/diff.d.ts +1 -1
  14. package/dist/delta/diff.d.ts.map +1 -0
  15. package/dist/delta/diff.js +433 -0
  16. package/dist/delta/diff.js.map +1 -0
  17. package/dist/delta/draft.d.ts +5 -0
  18. package/dist/delta/draft.d.ts.map +1 -0
  19. package/dist/delta/draft.js +2 -0
  20. package/dist/delta/draft.js.map +1 -0
  21. package/dist/delta/index.d.ts +11 -21
  22. package/dist/delta/index.d.ts.map +1 -1
  23. package/dist/delta/index.js +43 -1341
  24. package/dist/delta/index.js.map +1 -1
  25. package/dist/delta/revision-validator.d.ts +7 -0
  26. package/dist/delta/revision-validator.d.ts.map +1 -0
  27. package/dist/delta/revision-validator.js +71 -0
  28. package/dist/delta/revision-validator.js.map +1 -0
  29. package/dist/delta/tracker.d.ts +26 -0
  30. package/dist/delta/tracker.d.ts.map +1 -0
  31. package/dist/delta/tracker.js +2069 -0
  32. package/dist/delta/tracker.js.map +1 -0
  33. package/dist/facets/host.d.ts.map +1 -1
  34. package/dist/facets/host.js.map +1 -1
  35. package/dist/facets/loader.d.ts.map +1 -1
  36. package/dist/facets/loader.js.map +1 -1
  37. package/dist/index.d.ts +3 -3
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +1 -1
  40. package/dist/index.js.map +1 -1
  41. package/dist/json.d.ts +6 -0
  42. package/dist/json.d.ts.map +1 -1
  43. package/dist/json.js +73 -6
  44. package/dist/json.js.map +1 -1
  45. package/dist/node/bundle-loader.d.ts.map +1 -1
  46. package/dist/node/bundle-loader.js.map +1 -1
  47. package/dist/node/bundle.d.ts.map +1 -1
  48. package/dist/node/bundle.js.map +1 -1
  49. package/dist/node/manifest.d.ts.map +1 -1
  50. package/dist/node/package.d.ts.map +1 -1
  51. package/dist/node/package.js.map +1 -1
  52. package/dist/node.d.ts.map +1 -1
  53. package/dist/services/consumer.d.ts.map +1 -1
  54. package/dist/services/consumer.js +49 -1
  55. package/dist/services/consumer.js.map +1 -1
  56. package/dist/services/errors.d.ts.map +1 -1
  57. package/dist/services/errors.js.map +1 -1
  58. package/dist/services/handle.d.ts.map +1 -1
  59. package/dist/services/handle.js +3 -1
  60. package/dist/services/handle.js.map +1 -1
  61. package/dist/services/instances.d.ts +1 -0
  62. package/dist/services/instances.d.ts.map +1 -1
  63. package/dist/services/instances.js +3 -0
  64. package/dist/services/instances.js.map +1 -1
  65. package/dist/services/loopback.d.ts.map +1 -1
  66. package/dist/services/loopback.js.map +1 -1
  67. package/dist/services/provider.d.ts.map +1 -1
  68. package/dist/services/provider.js +48 -29
  69. package/dist/services/provider.js.map +1 -1
  70. package/dist/services/state-codec.d.ts.map +1 -1
  71. package/dist/services/state-codec.js +18 -0
  72. package/dist/services/state-codec.js.map +1 -1
  73. package/dist/services/state-internals.d.ts +5 -2
  74. package/dist/services/state-internals.d.ts.map +1 -1
  75. package/dist/services/state-internals.js.map +1 -1
  76. package/dist/services/state.d.ts +8 -3
  77. package/dist/services/state.d.ts.map +1 -1
  78. package/dist/services/state.js +288 -88
  79. package/dist/services/state.js.map +1 -1
  80. package/dist/services/wire.d.ts +3 -0
  81. package/dist/services/wire.d.ts.map +1 -1
  82. package/dist/services/wire.js +13 -0
  83. package/dist/services/wire.js.map +1 -1
  84. package/dist/types.d.ts +74 -8
  85. package/dist/types.d.ts.map +1 -1
  86. package/dist/types.js.map +1 -1
  87. package/package.json +3 -3
  88. package/src/delta/README.md +143 -360
  89. package/dist/state/diff.d.ts.map +0 -1
  90. package/dist/state/diff.js +0 -259
  91. package/dist/state/diff.js.map +0 -1
  92. package/dist/state/draft.d.ts +0 -13
  93. package/dist/state/draft.d.ts.map +0 -1
  94. package/dist/state/draft.js +0 -540
  95. package/dist/state/draft.js.map +0 -1
  96. package/dist/state/value.d.ts +0 -9
  97. package/dist/state/value.d.ts.map +0 -1
  98. package/dist/state/value.js +0 -175
  99. package/dist/state/value.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"wire.js","sourceRoot":"","sources":["../../src/services/wire.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAe,MAAM,mBAAmB,CAAC;AAsClF,MAAM,kBAAkB,GAAG,gBAAgB,CAAC;AAC5C,MAAM,wBAAwB,GAAG,WAAW,CAAC;AAC7C,MAAM,wBAAwB,GAAG,WAAW,CAAC;AAC7C,MAAM,0BAA0B,GAAG,aAAa,CAAC;AAYjD,MAAM,UAAU,0BAA0B,GAAgB;IACzD,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,EAAE,wBAAwB,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AAAA,CACrF;AAED,MAAM,UAAU,0BAA0B,CAAC,cAAsB,EAAE,SAAiB,EAAE,IAAiB,EAAe;IACrH,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,EAAE,wBAAwB,EAAE,IAAI,EAAE,CAAC,cAAc,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC;AAAA,CACpH;AAED,MAAM,UAAU,4BAA4B,CAAC,cAAsB,EAAe;IACjF,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,EAAE,0BAA0B,EAAE,IAAI,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC;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B,EAC3B,WAAmB,EACZ;IACP,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,QAAQ,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC;IACpD,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QAC/G,MAAM,IAAI,SAAS,CAAC,WAAW,WAAW,EAAE,CAAC,CAAC;IAC/C,CAAC;AAAA,CACD;AAED,SAAS,IAAI,CAAC,KAAc,EAAmB;IAC9C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;AAAA,CACrD;AAED,SAAS,MAAM,CAAC,KAAc,EAAwB;IACrD,OAAO,KAAK,KAAK,WAAW,IAAI,KAAK,KAAK,OAAO,CAAC;AAAA,CAClD;AAED,SAAS,SAAS,CAAC,KAAc,EAAE,OAAe,EAAmB;IACpE,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,OAAO,CAAC;AAAA,CAChF","sourcesContent":["import { assertValidOp, assertValidWireOp, type WireOp } from \"../delta/index.ts\";\nimport type {\n\tServiceCall,\n\tServiceCatalogueEntry,\n\tServiceInstanceAddress,\n\tServiceMode,\n\tServiceProviderUpdate,\n\tServiceSubscriptionSnapshot,\n} from \"../types.ts\";\n\nexport type WireServiceMemberSnapshot =\n\t| { readonly name: string; readonly kind: \"method\" }\n\t| { readonly name: string; readonly kind: \"state\"; readonly sequence: number; readonly ops: readonly WireOp[] };\n\nexport type WireServiceInstanceSnapshot = {\n\treadonly instance?: ServiceInstanceAddress;\n\treadonly members: readonly WireServiceMemberSnapshot[];\n};\n\nexport type WireServiceSubscriptionSnapshot = {\n\treadonly serviceId: string;\n\treadonly mode: ServiceMode;\n\treadonly instances: readonly WireServiceInstanceSnapshot[];\n};\n\nexport type WireServiceProviderUpdate =\n\t| {\n\t\t\treadonly type: \"state\";\n\t\t\treadonly instance?: ServiceInstanceAddress;\n\t\t\treadonly member: string;\n\t\t\treadonly sequence: number;\n\t\t\treadonly ops: readonly WireOp[];\n\t }\n\t| { readonly type: \"unavailable\" }\n\t| { readonly type: \"replaced\"; readonly snapshot: WireServiceInstanceSnapshot }\n\t| { readonly type: \"spawned\"; readonly instance: WireServiceInstanceSnapshot }\n\t| { readonly type: \"closed\"; readonly instance: ServiceInstanceAddress };\n\nconst SERVICE_CONTROL_ID = \"$chord.service\";\nconst SERVICE_CATALOGUE_MEMBER = \"catalogue\";\nconst SERVICE_SUBSCRIBE_MEMBER = \"subscribe\";\nconst SERVICE_UNSUBSCRIBE_MEMBER = \"unsubscribe\";\n\nexport type ServiceControlCall =\n\t| { readonly type: \"catalogue\" }\n\t| {\n\t\t\treadonly type: \"subscribe\";\n\t\t\treadonly subscriptionId: string;\n\t\t\treadonly serviceId: string;\n\t\t\treadonly mode: ServiceMode;\n\t }\n\t| { readonly type: \"unsubscribe\"; readonly subscriptionId: string };\n\nexport function createServiceCatalogueCall(): ServiceCall {\n\treturn { serviceId: SERVICE_CONTROL_ID, member: SERVICE_CATALOGUE_MEMBER, args: [] };\n}\n\nexport function createServiceSubscribeCall(subscriptionId: string, serviceId: string, mode: ServiceMode): ServiceCall {\n\treturn { serviceId: SERVICE_CONTROL_ID, member: SERVICE_SUBSCRIBE_MEMBER, args: [subscriptionId, serviceId, mode] };\n}\n\nexport function createServiceUnsubscribeCall(subscriptionId: string): ServiceCall {\n\treturn { serviceId: SERVICE_CONTROL_ID, member: SERVICE_UNSUBSCRIBE_MEMBER, args: [subscriptionId] };\n}\n\nexport function decodeServiceControlCall(call: ServiceCall): ServiceControlCall | undefined {\n\tif (call.serviceId !== SERVICE_CONTROL_ID || call.instance !== undefined) return undefined;\n\tif (call.member === SERVICE_CATALOGUE_MEMBER && call.args.length === 0) return { type: \"catalogue\" };\n\tif (\n\t\tcall.member === SERVICE_SUBSCRIBE_MEMBER &&\n\t\tcall.args.length === 3 &&\n\t\tisId(call.args[0]) &&\n\t\tisId(call.args[1]) &&\n\t\t(call.args[2] === \"singleton\" || call.args[2] === \"keyed\")\n\t) {\n\t\treturn {\n\t\t\ttype: \"subscribe\",\n\t\t\tsubscriptionId: call.args[0],\n\t\t\tserviceId: call.args[1],\n\t\t\tmode: call.args[2],\n\t\t};\n\t}\n\tif (call.member === SERVICE_UNSUBSCRIBE_MEMBER && call.args.length === 1 && isId(call.args[0])) {\n\t\treturn { type: \"unsubscribe\", subscriptionId: call.args[0] };\n\t}\n\treturn undefined;\n}\n\nexport function parseServiceCall(value: unknown): ServiceCall {\n\tconst call = record(value, \"service call\");\n\tassertKeys(call, [\"serviceId\", \"member\", \"args\"], [\"instance\"], \"service call\");\n\tif (!isId(call.serviceId) || !isId(call.member) || !Array.isArray(call.args)) {\n\t\tthrow new TypeError(\"Invalid service call\");\n\t}\n\tif (call.instance !== undefined) assertAddress(call.instance);\n\treturn value as ServiceCall;\n}\n\nexport function parseServiceCatalogue(value: unknown): readonly ServiceCatalogueEntry[] {\n\tif (!Array.isArray(value)) throw new TypeError(\"Invalid service catalogue\");\n\tconst ids = new Set<string>();\n\tfor (const candidate of value) {\n\t\tconst entry = record(candidate, \"service catalogue entry\");\n\t\tassertKeys(entry, [\"serviceId\", \"mode\"], [], \"service catalogue entry\");\n\t\tif (!isId(entry.serviceId) || !isMode(entry.mode) || ids.has(entry.serviceId)) {\n\t\t\tthrow new TypeError(\"Invalid service catalogue\");\n\t\t}\n\t\tids.add(entry.serviceId);\n\t}\n\treturn value as unknown as readonly ServiceCatalogueEntry[];\n}\n\nexport function parseServiceSubscriptionSnapshot(value: unknown): ServiceSubscriptionSnapshot {\n\tassertSubscriptionSnapshot(value, assertValidOp);\n\treturn value as ServiceSubscriptionSnapshot;\n}\n\nexport function parseWireServiceSubscriptionSnapshot(value: unknown): WireServiceSubscriptionSnapshot {\n\tassertSubscriptionSnapshot(value, assertValidWireOp);\n\treturn value as WireServiceSubscriptionSnapshot;\n}\n\nexport function parseServiceProviderUpdate(value: unknown): ServiceProviderUpdate {\n\tassertProviderUpdate(value, assertValidOp);\n\treturn value as ServiceProviderUpdate;\n}\n\nexport function parseWireServiceProviderUpdate(value: unknown): WireServiceProviderUpdate {\n\tassertProviderUpdate(value, assertValidWireOp);\n\treturn value as WireServiceProviderUpdate;\n}\n\nfunction assertSubscriptionSnapshot(value: unknown, assertOp: (value: unknown) => void): void {\n\tconst snapshot = record(value, \"service subscription snapshot\");\n\tassertKeys(snapshot, [\"serviceId\", \"mode\", \"instances\"], [], \"service subscription snapshot\");\n\tif (!isId(snapshot.serviceId) || !isMode(snapshot.mode) || !Array.isArray(snapshot.instances)) {\n\t\tthrow new TypeError(\"Invalid service subscription snapshot\");\n\t}\n\tfor (const instance of snapshot.instances) assertInstance(instance, assertOp);\n}\n\nfunction assertProviderUpdate(value: unknown, assertOp: (value: unknown) => void): void {\n\tconst update = record(value, \"service provider update\");\n\tswitch (update.type) {\n\t\tcase \"state\":\n\t\t\tassertKeys(update, [\"type\", \"member\", \"sequence\", \"ops\"], [\"instance\"], \"state update\");\n\t\t\tif (!isId(update.member) || !isInteger(update.sequence, 1) || !Array.isArray(update.ops)) {\n\t\t\t\tthrow new TypeError(\"Invalid service state update\");\n\t\t\t}\n\t\t\tif (update.instance !== undefined) assertAddress(update.instance);\n\t\t\tfor (const op of update.ops) assertOp(op);\n\t\t\treturn;\n\t\tcase \"unavailable\":\n\t\t\tassertKeys(update, [\"type\"], [], \"unavailable update\");\n\t\t\treturn;\n\t\tcase \"replaced\":\n\t\t\tassertKeys(update, [\"type\", \"snapshot\"], [], \"replacement update\");\n\t\t\tassertInstance(update.snapshot, assertOp);\n\t\t\treturn;\n\t\tcase \"spawned\":\n\t\t\tassertKeys(update, [\"type\", \"instance\"], [], \"spawn update\");\n\t\t\tassertInstance(update.instance, assertOp);\n\t\t\treturn;\n\t\tcase \"closed\":\n\t\t\tassertKeys(update, [\"type\", \"instance\"], [], \"close update\");\n\t\t\tassertAddress(update.instance);\n\t\t\treturn;\n\t\tdefault:\n\t\t\tthrow new TypeError(\"Invalid service provider update\");\n\t}\n}\n\nfunction assertInstance(value: unknown, assertOp: (value: unknown) => void): void {\n\tconst instance = record(value, \"service instance snapshot\");\n\tassertKeys(instance, [\"members\"], [\"instance\"], \"service instance snapshot\");\n\tif (instance.instance !== undefined) assertAddress(instance.instance);\n\tif (!Array.isArray(instance.members)) throw new TypeError(\"Invalid service instance snapshot\");\n\tfor (const candidate of instance.members) {\n\t\tconst member = record(candidate, \"service member snapshot\");\n\t\tif (member.kind === \"method\") {\n\t\t\tassertKeys(member, [\"name\", \"kind\"], [], \"service method snapshot\");\n\t\t\tif (!isId(member.name)) throw new TypeError(\"Invalid service method snapshot\");\n\t\t\tcontinue;\n\t\t}\n\t\tif (member.kind === \"state\") {\n\t\t\tassertKeys(member, [\"name\", \"kind\", \"sequence\", \"ops\"], [], \"service state snapshot\");\n\t\t\tif (!isId(member.name) || !isInteger(member.sequence, 0) || !Array.isArray(member.ops)) {\n\t\t\t\tthrow new TypeError(\"Invalid service state snapshot\");\n\t\t\t}\n\t\t\tfor (const op of member.ops) assertOp(op);\n\t\t\tcontinue;\n\t\t}\n\t\tthrow new TypeError(\"Invalid service member snapshot\");\n\t}\n}\n\nfunction assertAddress(value: unknown): asserts value is ServiceInstanceAddress {\n\tconst address = record(value, \"service instance address\");\n\tassertKeys(address, [\"key\", \"generation\"], [], \"service instance address\");\n\tif (!isId(address.key) || !isInteger(address.generation, 1)) {\n\t\tthrow new TypeError(\"Invalid service instance address\");\n\t}\n}\n\nfunction record(value: unknown, description: string): Record<string, unknown> {\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n\t\tthrow new TypeError(`Invalid ${description}`);\n\t}\n\treturn value as Record<string, unknown>;\n}\n\nfunction assertKeys(\n\tvalue: Record<string, unknown>,\n\trequired: readonly string[],\n\toptional: readonly string[],\n\tdescription: string,\n): void {\n\tconst allowed = new Set([...required, ...optional]);\n\tif (required.some((key) => !Object.hasOwn(value, key)) || Object.keys(value).some((key) => !allowed.has(key))) {\n\t\tthrow new TypeError(`Invalid ${description}`);\n\t}\n}\n\nfunction isId(value: unknown): value is string {\n\treturn typeof value === \"string\" && value.length > 0;\n}\n\nfunction isMode(value: unknown): value is ServiceMode {\n\treturn value === \"singleton\" || value === \"keyed\";\n}\n\nfunction isInteger(value: unknown, minimum: number): value is number {\n\treturn typeof value === \"number\" && Number.isInteger(value) && value >= minimum;\n}\n"]}
1
+ {"version":3,"file":"wire.js","sourceRoot":"","sources":["../../src/services/wire.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAe,MAAM,mBAAmB,CAAC;AAuClF,MAAM,kBAAkB,GAAG,gBAAgB,CAAC;AAC5C,MAAM,wBAAwB,GAAG,WAAW,CAAC;AAC7C,MAAM,wBAAwB,GAAG,WAAW,CAAC;AAC7C,MAAM,0BAA0B,GAAG,aAAa,CAAC;AAYjD,MAAM,UAAU,0BAA0B;IACzC,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,EAAE,wBAAwB,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AACtF,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,cAAsB,EAAE,SAAiB,EAAE,IAAiB;IACtG,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,EAAE,wBAAwB,EAAE,IAAI,EAAE,CAAC,cAAc,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC;AACrH,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,cAAsB;IAClE,OAAO,EAAE,SAAS,EAAE,kBAAkB,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AG,CAAC,CAAC;AACtD,CAAC;AAED,SAAS,MAAM,CAAC,KAAc;IAC7B,OAAO,KAAK,KAAK,WAAW,IAAI,KAAK,KAAK,OAAO,CAAC;AACnD,CAAC;AAED,SAAS,SAAS,CAAC,KAAc,EAAE,OAAe;IACjD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,OAAO,CAAC;AACjF,CAAC","sourcesContent":["import { assertValidOp, assertValidWireOp, type WireOp } from \"../delta/index.ts\";\nimport type {\n\tServiceCall,\n\tServiceCatalogueEntry,\n\tServiceInstanceAddress,\n\tServiceMode,\n\tServiceProviderUpdate,\n\tServiceSubscriptionSnapshot,\n} from \"../types.ts\";\n\nexport type WireServiceMemberSnapshot =\n\t| { readonly name: string; readonly kind: \"method\" }\n\t| { readonly name: string; readonly kind: \"state\"; readonly sequence: number; readonly ops: readonly WireOp[] };\n\nexport type WireServiceInstanceSnapshot = {\n\treadonly instance?: ServiceInstanceAddress;\n\treadonly members: readonly WireServiceMemberSnapshot[];\n};\n\nexport type WireServiceSubscriptionSnapshot = {\n\treadonly serviceId: string;\n\treadonly mode: ServiceMode;\n\treadonly instances: readonly WireServiceInstanceSnapshot[];\n};\n\nexport type WireServiceProviderUpdate =\n\t| {\n\t\t\treadonly type: \"state\";\n\t\t\treadonly instance?: ServiceInstanceAddress;\n\t\t\treadonly member: string;\n\t\t\treadonly sequence: number;\n\t\t\treadonly ops: readonly WireOp[];\n\t }\n\t| { readonly type: \"reset\"; readonly snapshot: WireServiceSubscriptionSnapshot }\n\t| { readonly type: \"unavailable\" }\n\t| { readonly type: \"replaced\"; readonly snapshot: WireServiceInstanceSnapshot }\n\t| { readonly type: \"spawned\"; readonly instance: WireServiceInstanceSnapshot }\n\t| { readonly type: \"closed\"; readonly instance: ServiceInstanceAddress };\n\nconst SERVICE_CONTROL_ID = \"$chord.service\";\nconst SERVICE_CATALOGUE_MEMBER = \"catalogue\";\nconst SERVICE_SUBSCRIBE_MEMBER = \"subscribe\";\nconst SERVICE_UNSUBSCRIBE_MEMBER = \"unsubscribe\";\n\nexport type ServiceControlCall =\n\t| { readonly type: \"catalogue\" }\n\t| {\n\t\t\treadonly type: \"subscribe\";\n\t\t\treadonly subscriptionId: string;\n\t\t\treadonly serviceId: string;\n\t\t\treadonly mode: ServiceMode;\n\t }\n\t| { readonly type: \"unsubscribe\"; readonly subscriptionId: string };\n\nexport function createServiceCatalogueCall(): ServiceCall {\n\treturn { serviceId: SERVICE_CONTROL_ID, member: SERVICE_CATALOGUE_MEMBER, args: [] };\n}\n\nexport function createServiceSubscribeCall(subscriptionId: string, serviceId: string, mode: ServiceMode): ServiceCall {\n\treturn { serviceId: SERVICE_CONTROL_ID, member: SERVICE_SUBSCRIBE_MEMBER, args: [subscriptionId, serviceId, mode] };\n}\n\nexport function createServiceUnsubscribeCall(subscriptionId: string): ServiceCall {\n\treturn { serviceId: SERVICE_CONTROL_ID, member: SERVICE_UNSUBSCRIBE_MEMBER, args: [subscriptionId] };\n}\n\nexport function decodeServiceControlCall(call: ServiceCall): ServiceControlCall | undefined {\n\tif (call.serviceId !== SERVICE_CONTROL_ID || call.instance !== undefined) return undefined;\n\tif (call.member === SERVICE_CATALOGUE_MEMBER && call.args.length === 0) return { type: \"catalogue\" };\n\tif (\n\t\tcall.member === SERVICE_SUBSCRIBE_MEMBER &&\n\t\tcall.args.length === 3 &&\n\t\tisId(call.args[0]) &&\n\t\tisId(call.args[1]) &&\n\t\t(call.args[2] === \"singleton\" || call.args[2] === \"keyed\")\n\t) {\n\t\treturn {\n\t\t\ttype: \"subscribe\",\n\t\t\tsubscriptionId: call.args[0],\n\t\t\tserviceId: call.args[1],\n\t\t\tmode: call.args[2],\n\t\t};\n\t}\n\tif (call.member === SERVICE_UNSUBSCRIBE_MEMBER && call.args.length === 1 && isId(call.args[0])) {\n\t\treturn { type: \"unsubscribe\", subscriptionId: call.args[0] };\n\t}\n\treturn undefined;\n}\n\nexport function parseServiceCall(value: unknown): ServiceCall {\n\tconst call = record(value, \"service call\");\n\tassertKeys(call, [\"serviceId\", \"member\", \"args\"], [\"instance\"], \"service call\");\n\tif (!isId(call.serviceId) || !isId(call.member) || !Array.isArray(call.args)) {\n\t\tthrow new TypeError(\"Invalid service call\");\n\t}\n\tif (call.instance !== undefined) assertAddress(call.instance);\n\treturn value as ServiceCall;\n}\n\nexport function parseServiceCatalogue(value: unknown): readonly ServiceCatalogueEntry[] {\n\tif (!Array.isArray(value)) throw new TypeError(\"Invalid service catalogue\");\n\tconst ids = new Set<string>();\n\tfor (const candidate of value) {\n\t\tconst entry = record(candidate, \"service catalogue entry\");\n\t\tassertKeys(entry, [\"serviceId\", \"mode\"], [], \"service catalogue entry\");\n\t\tif (!isId(entry.serviceId) || !isMode(entry.mode) || ids.has(entry.serviceId)) {\n\t\t\tthrow new TypeError(\"Invalid service catalogue\");\n\t\t}\n\t\tids.add(entry.serviceId);\n\t}\n\treturn value as unknown as readonly ServiceCatalogueEntry[];\n}\n\nexport function parseServiceSubscriptionSnapshot(value: unknown): ServiceSubscriptionSnapshot {\n\tassertSubscriptionSnapshot(value, assertValidOp);\n\treturn value as ServiceSubscriptionSnapshot;\n}\n\nexport function parseWireServiceSubscriptionSnapshot(value: unknown): WireServiceSubscriptionSnapshot {\n\tassertSubscriptionSnapshot(value, assertValidWireOp);\n\treturn value as WireServiceSubscriptionSnapshot;\n}\n\nexport function parseServiceProviderUpdate(value: unknown): ServiceProviderUpdate {\n\tassertProviderUpdate(value, assertValidOp);\n\treturn value as ServiceProviderUpdate;\n}\n\nexport function parseWireServiceProviderUpdate(value: unknown): WireServiceProviderUpdate {\n\tassertProviderUpdate(value, assertValidWireOp);\n\treturn value as WireServiceProviderUpdate;\n}\n\nfunction assertSubscriptionSnapshot(value: unknown, assertOp: (value: unknown) => void): void {\n\tconst snapshot = record(value, \"service subscription snapshot\");\n\tassertKeys(snapshot, [\"serviceId\", \"mode\", \"instances\"], [], \"service subscription snapshot\");\n\tif (!isId(snapshot.serviceId) || !isMode(snapshot.mode) || !Array.isArray(snapshot.instances)) {\n\t\tthrow new TypeError(\"Invalid service subscription snapshot\");\n\t}\n\tfor (const instance of snapshot.instances) assertInstance(instance, assertOp);\n}\n\nfunction assertProviderUpdate(value: unknown, assertOp: (value: unknown) => void): void {\n\tconst update = record(value, \"service provider update\");\n\tswitch (update.type) {\n\t\tcase \"state\":\n\t\t\tassertKeys(update, [\"type\", \"member\", \"sequence\", \"ops\"], [\"instance\"], \"state update\");\n\t\t\tif (!isId(update.member) || !isInteger(update.sequence, 1) || !Array.isArray(update.ops)) {\n\t\t\t\tthrow new TypeError(\"Invalid service state update\");\n\t\t\t}\n\t\t\tif (update.instance !== undefined) assertAddress(update.instance);\n\t\t\tfor (const op of update.ops) assertOp(op);\n\t\t\treturn;\n\t\tcase \"reset\": {\n\t\t\tassertKeys(update, [\"type\", \"snapshot\"], [], \"reset update\");\n\t\t\tassertSubscriptionSnapshot(update.snapshot, assertOp);\n\t\t\tconst snapshot = update.snapshot as WireServiceSubscriptionSnapshot;\n\t\t\tfor (const instance of snapshot.instances) {\n\t\t\t\tfor (const member of instance.members) {\n\t\t\t\t\tif (member.kind === \"state\" && (member.ops.length !== 1 || member.ops[0]?.[0] !== \"r\")) {\n\t\t\t\t\t\tthrow new TypeError(\"Service reset must contain full root replacements\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tcase \"unavailable\":\n\t\t\tassertKeys(update, [\"type\"], [], \"unavailable update\");\n\t\t\treturn;\n\t\tcase \"replaced\":\n\t\t\tassertKeys(update, [\"type\", \"snapshot\"], [], \"replacement update\");\n\t\t\tassertInstance(update.snapshot, assertOp);\n\t\t\treturn;\n\t\tcase \"spawned\":\n\t\t\tassertKeys(update, [\"type\", \"instance\"], [], \"spawn update\");\n\t\t\tassertInstance(update.instance, assertOp);\n\t\t\treturn;\n\t\tcase \"closed\":\n\t\t\tassertKeys(update, [\"type\", \"instance\"], [], \"close update\");\n\t\t\tassertAddress(update.instance);\n\t\t\treturn;\n\t\tdefault:\n\t\t\tthrow new TypeError(\"Invalid service provider update\");\n\t}\n}\n\nfunction assertInstance(value: unknown, assertOp: (value: unknown) => void): void {\n\tconst instance = record(value, \"service instance snapshot\");\n\tassertKeys(instance, [\"members\"], [\"instance\"], \"service instance snapshot\");\n\tif (instance.instance !== undefined) assertAddress(instance.instance);\n\tif (!Array.isArray(instance.members)) throw new TypeError(\"Invalid service instance snapshot\");\n\tfor (const candidate of instance.members) {\n\t\tconst member = record(candidate, \"service member snapshot\");\n\t\tif (member.kind === \"method\") {\n\t\t\tassertKeys(member, [\"name\", \"kind\"], [], \"service method snapshot\");\n\t\t\tif (!isId(member.name)) throw new TypeError(\"Invalid service method snapshot\");\n\t\t\tcontinue;\n\t\t}\n\t\tif (member.kind === \"state\") {\n\t\t\tassertKeys(member, [\"name\", \"kind\", \"sequence\", \"ops\"], [], \"service state snapshot\");\n\t\t\tif (!isId(member.name) || !isInteger(member.sequence, 0) || !Array.isArray(member.ops)) {\n\t\t\t\tthrow new TypeError(\"Invalid service state snapshot\");\n\t\t\t}\n\t\t\tfor (const op of member.ops) assertOp(op);\n\t\t\tcontinue;\n\t\t}\n\t\tthrow new TypeError(\"Invalid service member snapshot\");\n\t}\n}\n\nfunction assertAddress(value: unknown): asserts value is ServiceInstanceAddress {\n\tconst address = record(value, \"service instance address\");\n\tassertKeys(address, [\"key\", \"generation\"], [], \"service instance address\");\n\tif (!isId(address.key) || !isInteger(address.generation, 1)) {\n\t\tthrow new TypeError(\"Invalid service instance address\");\n\t}\n}\n\nfunction record(value: unknown, description: string): Record<string, unknown> {\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n\t\tthrow new TypeError(`Invalid ${description}`);\n\t}\n\treturn value as Record<string, unknown>;\n}\n\nfunction assertKeys(\n\tvalue: Record<string, unknown>,\n\trequired: readonly string[],\n\toptional: readonly string[],\n\tdescription: string,\n): void {\n\tconst allowed = new Set([...required, ...optional]);\n\tif (required.some((key) => !Object.hasOwn(value, key)) || Object.keys(value).some((key) => !allowed.has(key))) {\n\t\tthrow new TypeError(`Invalid ${description}`);\n\t}\n}\n\nfunction isId(value: unknown): value is string {\n\treturn typeof value === \"string\" && value.length > 0;\n}\n\nfunction isMode(value: unknown): value is ServiceMode {\n\treturn value === \"singleton\" || value === \"keyed\";\n}\n\nfunction isInteger(value: unknown, minimum: number): value is number {\n\treturn typeof value === \"number\" && Number.isInteger(value) && value >= minimum;\n}\n"]}
package/dist/types.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import type { Op } from "./delta/index.ts";
1
+ import type { Draft, Op } from "./delta/index.ts";
2
2
  import type { RemoteServiceProvider } from "./services/provider.ts";
3
- import type { Draft } from "./state/draft.ts";
4
3
  export type { RemoteServiceError } from "./services/errors.ts";
5
4
  export type { RemoteServiceProvider } from "./services/provider.ts";
6
5
  /** Typed identity for one value carried by a {@link Context}. */
@@ -28,21 +27,79 @@ export interface ReplicatedStateDelivery {
28
27
  readonly sequence: number;
29
28
  }
30
29
  export interface ReplicatedState<T> {
31
- /** Immutable value, or undefined until hydration. Later updates do not mutate previously returned values. */
30
+ /**
31
+ * Contract-immutable value, or undefined until hydration. It is not frozen and may share containers with an
32
+ * in-process provider; consumers must not mutate it. Later updates do not mutate previously returned values.
33
+ */
32
34
  readonly value: T | undefined;
33
- /** Listener values are immutable and may structurally share unchanged data with other revisions. */
35
+ /**
36
+ * Each subscription serializes callbacks, awaiting hydration before updates. Values are immutable and may
37
+ * share unchanged revision data. At most 100 deliveries wait behind the running callback; overflow keeps
38
+ * only the newest pending value/context/delivery, so update sequences may skip. Failures are reported in
39
+ * isolation and delivery continues. Unsubscribe discards pending work without aborting or joining a callback.
40
+ */
41
+ subscribe(listener: (value: T, context: Context, delivery: ReplicatedStateDelivery) => Promise<void>): () => void;
34
42
  subscribe(listener: (value: T, context: Context, delivery: ReplicatedStateDelivery) => void): () => void;
35
43
  }
36
44
  export interface MutableReplicatedState<T extends object> extends ReplicatedState<T> {
37
45
  readonly value: T;
38
46
  /**
39
- * Atomically publish one synchronous copy-on-write mutation. Draft handles are revoked when the callback returns.
40
- * Async callbacks and non-JSON assignments, including `undefined`, throw without changing the value.
47
+ * Atomically publish one synchronous overlay mutation. Draft handles are unusable after the callback returns.
48
+ * Values placed through the draft are cloned by value; assigning `undefined` to an object property deletes it.
41
49
  */
42
50
  change(context: Context, mutate: (draft: Draft<T>) => void): void;
43
- /** Atomically replace the complete value with a detached immutable JSON snapshot. */
51
+ /**
52
+ * Atomically take immutable ownership of an alias-free strict-JSON replacement.
53
+ * The caller must not mutate the transferred root after this call.
54
+ */
44
55
  replace(context: Context, value: T): void;
45
56
  }
57
+ /** One immutable authoritative revision committed after an attachment snapshot. */
58
+ export interface ReplicatedStateSourceFrame<T> {
59
+ /** Monotonic source cursor. The first frame after a snapshot must be `snapshot.cursor + 1`. */
60
+ readonly cursor: number;
61
+ /** The exact immutable value produced by this commit. */
62
+ readonly value: T;
63
+ /** The exact immutable operation batch that produced `value` from the preceding source revision. */
64
+ readonly ops: readonly Op[];
65
+ readonly context: Context;
66
+ }
67
+ export interface ReplicatedStateSourceAttachment<T> {
68
+ /** Fixed immutable snapshot captured at the atomic attachment boundary. */
69
+ readonly snapshot: {
70
+ readonly value: T;
71
+ readonly cursor: number;
72
+ };
73
+ /**
74
+ * Install the sole listener and synchronously drain every buffered frame in source commit order.
75
+ * This method is single-use. After it begins, every new committed frame must also be delivered in order
76
+ * until disposal, including commits made reentrantly while a prior frame is being delivered.
77
+ */
78
+ activate(listener: (frame: ReplicatedStateSourceFrame<T>) => void): void;
79
+ /** Stop delivery and release source resources. Disposal must be idempotent. */
80
+ dispose(): void;
81
+ }
82
+ /**
83
+ * An authoritative immutable revision source.
84
+ *
85
+ * `attach()` must synchronously and atomically capture one snapshot and register the returned attachment to buffer
86
+ * every later committed frame. The snapshot must include every commit before that boundary; buffered frames must
87
+ * include every commit after it, with no overlap or gap. Snapshot values, frame values, and operation batches are
88
+ * immutable and remain valid after delivery. Chord only publishes these references; it never applies or re-diffs them.
89
+ */
90
+ export interface ReplicatedStateSource<T> {
91
+ attach(): ReplicatedStateSourceAttachment<T>;
92
+ }
93
+ export interface ReplicatedStateSourceOptions {
94
+ /** Receives source-contract and publication-listener failures without throwing them into the source. */
95
+ readonly onError?: (error: Error) => void;
96
+ }
97
+ /** A synchronously hydrated publication-only state backed by one source attachment. */
98
+ export interface AttachedReplicatedState<T> extends ReplicatedState<T> {
99
+ readonly value: T;
100
+ /** Idempotently release the source attachment. The last published value remains readable. */
101
+ dispose(): void;
102
+ }
46
103
  declare const SERVICE_TYPE: unique symbol;
47
104
  export type ServiceMode = "singleton" | "keyed";
48
105
  /** Stable identity for one shared TypeScript service contract. */
@@ -104,6 +161,11 @@ export type ServiceProviderUpdate = {
104
161
  readonly member: string;
105
162
  readonly sequence: number;
106
163
  readonly ops: readonly Op[];
164
+ }
165
+ /** Full subscription rebaseline after overflow; every state is a root replacement at its new sequence. */
166
+ | {
167
+ readonly type: "reset";
168
+ readonly snapshot: ServiceSubscriptionSnapshot;
107
169
  } | {
108
170
  readonly type: "unavailable";
109
171
  } | {
@@ -124,6 +186,7 @@ export type ServiceCall = {
124
186
  readonly args: readonly JsonValue[];
125
187
  };
126
188
  export interface ServiceSubscription {
189
+ /** Atomic baseline. Later updates buffer until activation, with a full reset on pending delivery 101. */
127
190
  readonly snapshot: ServiceSubscriptionSnapshot;
128
191
  activate(): void;
129
192
  close(context?: Context): void | Promise<void>;
@@ -161,7 +224,10 @@ export interface FacetEnvironment {
161
224
  provide<T>(service: Service<T>, implementation: NoInfer<T>): void;
162
225
  /** Declare ownership of a multi-instance service and return its deferred spawning capability. */
163
226
  provideMany<T>(service: Service<T>): ServiceSpawner<T>;
164
- /** Create initialized mutable state suitable for exposing through a service implementation. */
227
+ /**
228
+ * Create initialized mutable state by taking immutable ownership of an alias-free strict-JSON root.
229
+ * The caller must not mutate `initial` after this call.
230
+ */
165
231
  replicatedState<T extends object>(initial: T): MutableReplicatedState<T>;
166
232
  /** Give the facet ownership of a resource cleanup function. */
167
233
  own(disposal: () => void | Promise<void>): void;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9C,YAAY,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,YAAY,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAEpE,iEAAiE;AACjE,MAAM,WAAW,UAAU,CAAC,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,iGAAiG;IACjG,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;CACrC;AAED,+EAA+E;AAC/E,MAAM,WAAW,OAAO;IACvB,QAAQ,CAAC,WAAW,EAAE,WAAW,GAAG,SAAS,CAAC;IAC9C,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;IAC5C,QAAQ,IAAI,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEtG,KAAK,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;AAE/C,iGAAiG;AACjG,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,KAAK,CA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GAAoG;IACpG,MAAM,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAED,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IAClC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC3B,IAAI,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC;CAC9B","sourcesContent":["import type { Op } from \"./delta/index.ts\";\nimport type { RemoteServiceProvider } from \"./services/provider.ts\";\nimport type { Draft } from \"./state/draft.ts\";\n\nexport type { RemoteServiceError } from \"./services/errors.ts\";\nexport type { RemoteServiceProvider } from \"./services/provider.ts\";\n\n/** Typed identity for one value carried by a {@link Context}. */\nexport interface ContextKey<T> {\n\treadonly token: symbol;\n\t/** Type-only marker that prevents keys with different value types from being interchangeable. */\n\treadonly valueType?: (value: T) => T;\n}\n\n/** Immutable invocation-scoped values passed explicitly through operations. */\nexport interface Context {\n\treadonly abortSignal: AbortSignal | undefined;\n\tvalue<T>(key: ContextKey<T>): T | undefined;\n\ttoString(): string;\n}\n\nexport type JsonValue = null | boolean | number | string | JsonValue[] | { [key: string]: JsonValue };\n\ntype IsAny<T> = 0 extends 1 & T ? true : false;\n\n/** Strict-JSON representation of an application data type. Unknown payloads become JsonValue. */\nexport type JsonRepresentation<T> = IsAny<T> extends true\n\t? JsonValue\n\t: unknown extends T\n\t\t? JsonValue\n\t\t: T extends null | boolean | number | string\n\t\t\t? T\n\t\t\t: T extends readonly (infer TItem)[]\n\t\t\t\t? JsonRepresentation<TItem>[]\n\t\t\t\t: T extends object\n\t\t\t\t\t? { [TKey in keyof T]: JsonRepresentation<T[TKey]> }\n\t\t\t\t\t: never;\n\nexport interface ReplicatedStateDelivery {\n\treadonly kind: \"hydrate\" | \"update\";\n\treadonly sequence: number;\n}\n\nexport interface ReplicatedState<T> {\n\t/** Immutable value, or undefined until hydration. Later updates do not mutate previously returned values. */\n\treadonly value: T | undefined;\n\t/** Listener values are immutable and may structurally share unchanged data with other revisions. */\n\tsubscribe(listener: (value: T, context: Context, delivery: ReplicatedStateDelivery) => void): () => void;\n}\n\nexport interface MutableReplicatedState<T extends object> extends ReplicatedState<T> {\n\treadonly value: T;\n\t/**\n\t * Atomically publish one synchronous copy-on-write mutation. Draft handles are revoked when the callback returns.\n\t * Async callbacks and non-JSON assignments, including `undefined`, throw without changing the value.\n\t */\n\tchange(context: Context, mutate: (draft: Draft<T>) => void): void;\n\t/** Atomically replace the complete value with a detached immutable JSON snapshot. */\n\treplace(context: Context, value: T): void;\n}\n\ndeclare const SERVICE_TYPE: unique symbol;\n\nexport type ServiceMode = \"singleton\" | \"keyed\";\n\n/** Stable identity for one shared TypeScript service contract. */\nexport interface Service<T> {\n\treadonly id: string;\n\t/** Process-local services accept unrestricted object contracts and are never published remotely. */\n\treadonly local: boolean;\n\treadonly [SERVICE_TYPE]?: (value: T) => T;\n}\n\ntype InvalidJsonPart<T> = IsAny<T> extends true\n\t? T\n\t: unknown extends T\n\t\t? never\n\t\t: [T] extends [JsonValue]\n\t\t\t? [JsonValue] extends [T]\n\t\t\t\t? never\n\t\t\t\t: InvalidJsonStructure<T>\n\t\t\t: InvalidJsonStructure<T>;\n\ntype InvalidJsonProperty<T> = [Exclude<T, undefined>] extends [never] ? T : InvalidJsonPart<Exclude<T, undefined>>;\n\ntype InvalidJsonStructure<T> = T extends null | boolean | number | string\n\t? never\n\t: T extends readonly (infer TItem)[]\n\t\t? InvalidJsonPart<TItem>\n\t\t: T extends (...args: never[]) => unknown\n\t\t\t? T\n\t\t\t: T extends object\n\t\t\t\t? { [TKey in keyof T]-?: InvalidJsonProperty<T[TKey]> }[keyof T]\n\t\t\t\t: T;\n\ntype InvalidRemoteMember<T> = T extends ReplicatedState<infer TValue>\n\t? InvalidJsonPart<TValue> extends never\n\t\t? never\n\t\t: \"state value is not JSON\"\n\t: T extends (...args: [...infer TArgs, Context]) => Promise<infer TResult>\n\t\t? InvalidJsonPart<TArgs[number]> extends never\n\t\t\t? TResult extends void\n\t\t\t\t? never\n\t\t\t\t: InvalidJsonPart<TResult> extends never\n\t\t\t\t\t? never\n\t\t\t\t\t: \"method result is not JSON or void\"\n\t\t\t: \"method argument is not JSON\"\n\t\t: \"member is not a remote method or ReplicatedState\";\n\ntype InvalidRemoteMemberNames<T> = {\n\t[TKey in keyof T]-?: InvalidRemoteMember<T[TKey]> extends never ? never : TKey;\n}[keyof T];\n\nexport type RemoteServiceContract<T> = InvalidRemoteMemberNames<T> extends never ? T : never;\n\nexport interface ServiceSpawner<T> {\n\tspawn(key: string, implementation: T): () => void;\n}\n\nexport interface RemoteServices {\n\tuse<T>(service: Service<T>): T;\n\tobserve<T>(service: Service<T>, handler: (service: T, context: Context) => void | Promise<void>): () => void;\n\t/** Wait until every currently acquired service has installed its initial snapshot. */\n\tready(context: Context): Promise<void>;\n\tdispose(context: Context): Promise<void>;\n}\n\nexport type ServiceCatalogueEntry = {\n\treadonly serviceId: string;\n\treadonly mode: ServiceMode;\n};\n\nexport type ServiceInstanceAddress = {\n\treadonly key: string;\n\treadonly generation: number;\n};\n\nexport type ServiceMemberSnapshot =\n\t| { readonly name: string; readonly kind: \"method\" }\n\t| { readonly name: string; readonly kind: \"state\"; readonly sequence: number; readonly ops: readonly Op[] };\n\nexport type ServiceInstanceSnapshot = {\n\treadonly instance?: ServiceInstanceAddress;\n\treadonly members: readonly ServiceMemberSnapshot[];\n};\n\nexport type ServiceSubscriptionSnapshot = {\n\treadonly serviceId: string;\n\treadonly mode: ServiceMode;\n\treadonly instances: readonly ServiceInstanceSnapshot[];\n};\n\nexport type ServiceProviderUpdate =\n\t| {\n\t\t\treadonly type: \"state\";\n\t\t\treadonly instance?: ServiceInstanceAddress;\n\t\t\treadonly member: string;\n\t\t\treadonly sequence: number;\n\t\t\treadonly ops: readonly Op[];\n\t }\n\t| { readonly type: \"unavailable\" }\n\t| { readonly type: \"replaced\"; readonly snapshot: ServiceInstanceSnapshot }\n\t| { readonly type: \"spawned\"; readonly instance: ServiceInstanceSnapshot }\n\t| { readonly type: \"closed\"; readonly instance: ServiceInstanceAddress };\n\nexport type ServiceCall = {\n\treadonly serviceId: string;\n\treadonly instance?: ServiceInstanceAddress;\n\treadonly member: string;\n\t/** Borrowed immutable values. Chord validates but does not clone them. */\n\treadonly args: readonly JsonValue[];\n};\n\nexport interface ServiceSubscription {\n\treadonly snapshot: ServiceSubscriptionSnapshot;\n\tactivate(): void;\n\tclose(context?: Context): void | Promise<void>;\n}\n\n/**\n * Pluggable wire boundary consumed by a remote service binding.\n *\n * Implementations choose transport, framing, routing, and envelope encoding. Values crossing this\n * boundary must remain strict JSON. Chord does not clone values or require a particular application wire protocol;\n * adapters own serialization and any isolation copies they require.\n *\n */\nexport interface RemoteServiceTransport {\n\tinvoke(call: ServiceCall, context: Context): Promise<JsonValue | undefined>;\n\tsubscribe(\n\t\tserviceId: string,\n\t\tmode: ServiceMode,\n\t\tlistener: (update: ServiceProviderUpdate, context: Context) => void,\n\t\tcontext: Context,\n\t): Promise<ServiceSubscription>;\n}\n\nexport interface RemoteServiceBindingOptions {\n\treadonly services: readonly { readonly id: string }[];\n\treadonly transport: RemoteServiceTransport;\n\treadonly bound?: boolean;\n\treadonly onError?: (error: Error) => void;\n\treadonly assertAccess?: () => void;\n}\n\nexport interface RemoteServiceBinding extends RemoteServices {\n\trebind(bound: boolean, context: Context): Promise<void>;\n}\n\nexport interface FacetEnvironment {\n\t/** Declare a hard dependency on one singleton service and return its stable handle. */\n\tuse<T>(service: Service<T>): T;\n\t/** Declare a hard dependency on a keyed service and observe each live instance. */\n\tobserve<T>(service: Service<T>, handler: (service: T, context: Context) => void | Promise<void>): void;\n\t/** Declare and install this facet's singleton implementation of a service. */\n\tprovide<T>(service: Service<T>, implementation: NoInfer<T>): void;\n\t/** Declare ownership of a multi-instance service and return its deferred spawning capability. */\n\tprovideMany<T>(service: Service<T>): ServiceSpawner<T>;\n\t/** Create initialized mutable state suitable for exposing through a service implementation. */\n\treplicatedState<T extends object>(initial: T): MutableReplicatedState<T>;\n\t/** Give the facet ownership of a resource cleanup function. */\n\town(disposal: () => void | Promise<void>): void;\n\t/** Register asynchronous initialization after dependencies are bound and ready. */\n\tonActivate(callback: () => void | Promise<void>): void;\n\t/** Register final facet teardown. */\n\tonDeactivate(callback: () => void | Promise<void>): void;\n}\n\nexport interface Facet {\n\treadonly id: string;\n\tsetup(env: FacetEnvironment): void;\n}\n\nexport interface RemoteServiceSource {\n\t/** Whether this currently unavailable source may provisionally own absent requirements. */\n\treadonly acceptsUnavailableServices: boolean;\n\tcatalogue(context: Context): Promise<readonly ServiceCatalogueEntry[]>;\n\topen(options: {\n\t\treadonly services: readonly { readonly id: string }[];\n\t\tassertAccess(): void;\n\t\tonError(error: Error): void;\n\t}): RemoteServices;\n}\n\nexport interface FacetOptions {\n\treadonly facets: readonly Facet[];\n\treadonly serviceSources?: readonly RemoteServiceSource[];\n\treadonly onError?: (error: Error) => void;\n}\n\nexport interface FacetHost {\n\treadonly services: RemoteServiceProvider;\n\t/** Activate and replace facets with matching IDs without disconnecting consumer service handles. */\n\treload(facets: readonly Facet[]): Promise<void>;\n\tdispose(): Promise<void>;\n}\n\nexport interface LoadedFacets {\n\treadonly facets: readonly Facet[];\n\tdispose(): Promise<void>;\n}\n\nexport interface FacetLoader {\n\tload(): Promise<LoadedFacets>;\n}\n"]}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAEpE,YAAY,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,YAAY,EAAE,qBAAqB,EAAE,M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AY,CAAC,CAAC;CAC9B"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Op } from \"./delta/index.ts\";\nimport type { RemoteServiceProvider } from \"./services/provider.ts\";\nimport type { Draft } from \"./state/draft.ts\";\n\nexport type { RemoteServiceError } from \"./services/errors.ts\";\nexport type { RemoteServiceProvider } from \"./services/provider.ts\";\n\n/** Typed identity for one value carried by a {@link Context}. */\nexport interface ContextKey<T> {\n\treadonly token: symbol;\n\t/** Type-only marker that prevents keys with different value types from being interchangeable. */\n\treadonly valueType?: (value: T) => T;\n}\n\n/** Immutable invocation-scoped values passed explicitly through operations. */\nexport interface Context {\n\treadonly abortSignal: AbortSignal | undefined;\n\tvalue<T>(key: ContextKey<T>): T | undefined;\n\ttoString(): string;\n}\n\nexport type JsonValue = null | boolean | number | string | JsonValue[] | { [key: string]: JsonValue };\n\ntype IsAny<T> = 0 extends 1 & T ? true : false;\n\n/** Strict-JSON representation of an application data type. Unknown payloads become JsonValue. */\nexport type JsonRepresentation<T> = IsAny<T> extends true\n\t? JsonValue\n\t: unknown extends T\n\t\t? JsonValue\n\t\t: T extends null | boolean | number | string\n\t\t\t? T\n\t\t\t: T extends readonly (infer TItem)[]\n\t\t\t\t? JsonRepresentation<TItem>[]\n\t\t\t\t: T extends object\n\t\t\t\t\t? { [TKey in keyof T]: JsonRepresentation<T[TKey]> }\n\t\t\t\t\t: never;\n\nexport interface ReplicatedStateDelivery {\n\treadonly kind: \"hydrate\" | \"update\";\n\treadonly sequence: number;\n}\n\nexport interface ReplicatedState<T> {\n\t/** Immutable value, or undefined until hydration. Later updates do not mutate previously returned values. */\n\treadonly value: T | undefined;\n\t/** Listener values are immutable and may structurally share unchanged data with other revisions. */\n\tsubscribe(listener: (value: T, context: Context, delivery: ReplicatedStateDelivery) => void): () => void;\n}\n\nexport interface MutableReplicatedState<T extends object> extends ReplicatedState<T> {\n\treadonly value: T;\n\t/**\n\t * Atomically publish one synchronous copy-on-write mutation. Draft handles are revoked when the callback returns.\n\t * Async callbacks and non-JSON assignments, including `undefined`, throw without changing the value.\n\t */\n\tchange(context: Context, mutate: (draft: Draft<T>) => void): void;\n\t/** Atomically replace the complete value with a detached immutable JSON snapshot. */\n\treplace(context: Context, value: T): void;\n}\n\ndeclare const SERVICE_TYPE: unique symbol;\n\nexport type ServiceMode = \"singleton\" | \"keyed\";\n\n/** Stable identity for one shared TypeScript service contract. */\nexport interface Service<T> {\n\treadonly id: string;\n\t/** Process-local services accept unrestricted object contracts and are never published remotely. */\n\treadonly local: boolean;\n\treadonly [SERVICE_TYPE]?: (value: T) => T;\n}\n\ntype InvalidJsonPart<T> = IsAny<T> extends true\n\t? T\n\t: unknown extends T\n\t\t? never\n\t\t: [T] extends [JsonValue]\n\t\t\t? [JsonValue] extends [T]\n\t\t\t\t? never\n\t\t\t\t: InvalidJsonStructure<T>\n\t\t\t: InvalidJsonStructure<T>;\n\ntype InvalidJsonProperty<T> = [Exclude<T, undefined>] extends [never] ? T : InvalidJsonPart<Exclude<T, undefined>>;\n\ntype InvalidJsonStructure<T> = T extends null | boolean | number | string\n\t? never\n\t: T extends readonly (infer TItem)[]\n\t\t? InvalidJsonPart<TItem>\n\t\t: T extends (...args: never[]) => unknown\n\t\t\t? T\n\t\t\t: T extends object\n\t\t\t\t? { [TKey in keyof T]-?: InvalidJsonProperty<T[TKey]> }[keyof T]\n\t\t\t\t: T;\n\ntype InvalidRemoteMember<T> = T extends ReplicatedState<infer TValue>\n\t? InvalidJsonPart<TValue> extends never\n\t\t? never\n\t\t: \"state value is not JSON\"\n\t: T extends (...args: [...infer TArgs, Context]) => Promise<infer TResult>\n\t\t? InvalidJsonPart<TArgs[number]> extends never\n\t\t\t? TResult extends void\n\t\t\t\t? never\n\t\t\t\t: InvalidJsonPart<TResult> extends never\n\t\t\t\t\t? never\n\t\t\t\t\t: \"method result is not JSON or void\"\n\t\t\t: \"method argument is not JSON\"\n\t\t: \"member is not a remote method or ReplicatedState\";\n\ntype InvalidRemoteMemberNames<T> = {\n\t[TKey in keyof T]-?: InvalidRemoteMember<T[TKey]> extends never ? never : TKey;\n}[keyof T];\n\nexport type RemoteServiceContract<T> = InvalidRemoteMemberNames<T> extends never ? T : never;\n\nexport interface ServiceSpawner<T> {\n\tspawn(key: string, implementation: T): () => void;\n}\n\nexport interface RemoteServices {\n\tuse<T>(service: Service<T>): T;\n\tobserve<T>(service: Service<T>, handler: (service: T, context: Context) => void | Promise<void>): () => void;\n\t/** Wait until every currently acquired service has installed its initial snapshot. */\n\tready(context: Context): Promise<void>;\n\tdispose(context: Context): Promise<void>;\n}\n\nexport type ServiceCatalogueEntry = {\n\treadonly serviceId: string;\n\treadonly mode: ServiceMode;\n};\n\nexport type ServiceInstanceAddress = {\n\treadonly key: string;\n\treadonly generation: number;\n};\n\nexport type ServiceMemberSnapshot =\n\t| { readonly name: string; readonly kind: \"method\" }\n\t| { readonly name: string; readonly kind: \"state\"; readonly sequence: number; readonly ops: readonly Op[] };\n\nexport type ServiceInstanceSnapshot = {\n\treadonly instance?: ServiceInstanceAddress;\n\treadonly members: readonly ServiceMemberSnapshot[];\n};\n\nexport type ServiceSubscriptionSnapshot = {\n\treadonly serviceId: string;\n\treadonly mode: ServiceMode;\n\treadonly instances: readonly ServiceInstanceSnapshot[];\n};\n\nexport type ServiceProviderUpdate =\n\t| {\n\t\t\treadonly type: \"state\";\n\t\t\treadonly instance?: ServiceInstanceAddress;\n\t\t\treadonly member: string;\n\t\t\treadonly sequence: number;\n\t\t\treadonly ops: readonly Op[];\n\t }\n\t| { readonly type: \"unavailable\" }\n\t| { readonly type: \"replaced\"; readonly snapshot: ServiceInstanceSnapshot }\n\t| { readonly type: \"spawned\"; readonly instance: ServiceInstanceSnapshot }\n\t| { readonly type: \"closed\"; readonly instance: ServiceInstanceAddress };\n\nexport type ServiceCall = {\n\treadonly serviceId: string;\n\treadonly instance?: ServiceInstanceAddress;\n\treadonly member: string;\n\t/** Borrowed immutable values. Chord validates but does not clone them. */\n\treadonly args: readonly JsonValue[];\n};\n\nexport interface ServiceSubscription {\n\treadonly snapshot: ServiceSubscriptionSnapshot;\n\tactivate(): void;\n\tclose(context?: Context): void | Promise<void>;\n}\n\n/**\n * Pluggable wire boundary consumed by a remote service binding.\n *\n * Implementations choose transport, framing, routing, and envelope encoding. Values crossing this\n * boundary must remain strict JSON. Chord does not clone values or require a particular application wire protocol;\n * adapters own serialization and any isolation copies they require.\n *\n */\nexport interface RemoteServiceTransport {\n\tinvoke(call: ServiceCall, context: Context): Promise<JsonValue | undefined>;\n\tsubscribe(\n\t\tserviceId: string,\n\t\tmode: ServiceMode,\n\t\tlistener: (update: ServiceProviderUpdate, context: Context) => void,\n\t\tcontext: Context,\n\t): Promise<ServiceSubscription>;\n}\n\nexport interface RemoteServiceBindingOptions {\n\treadonly services: readonly { readonly id: string }[];\n\treadonly transport: RemoteServiceTransport;\n\treadonly bound?: boolean;\n\treadonly onError?: (error: Error) => void;\n\treadonly assertAccess?: () => void;\n}\n\nexport interface RemoteServiceBinding extends RemoteServices {\n\trebind(bound: boolean, context: Context): Promise<void>;\n}\n\nexport interface FacetEnvironment {\n\t/** Declare a hard dependency on one singleton service and return its stable handle. */\n\tuse<T>(service: Service<T>): T;\n\t/** Declare a hard dependency on a keyed service and observe each live instance. */\n\tobserve<T>(service: Service<T>, handler: (service: T, context: Context) => void | Promise<void>): void;\n\t/** Declare and install this facet's singleton implementation of a service. */\n\tprovide<T>(service: Service<T>, implementation: NoInfer<T>): void;\n\t/** Declare ownership of a multi-instance service and return its deferred spawning capability. */\n\tprovideMany<T>(service: Service<T>): ServiceSpawner<T>;\n\t/** Create initialized mutable state suitable for exposing through a service implementation. */\n\treplicatedState<T extends object>(initial: T): MutableReplicatedState<T>;\n\t/** Give the facet ownership of a resource cleanup function. */\n\town(disposal: () => void | Promise<void>): void;\n\t/** Register asynchronous initialization after dependencies are bound and ready. */\n\tonActivate(callback: () => void | Promise<void>): void;\n\t/** Register final facet teardown. */\n\tonDeactivate(callback: () => void | Promise<void>): void;\n}\n\nexport interface Facet {\n\treadonly id: string;\n\tsetup(env: FacetEnvironment): void;\n}\n\nexport interface RemoteServiceSource {\n\t/** Whether this currently unavailable source may provisionally own absent requirements. */\n\treadonly acceptsUnavailableServices: boolean;\n\tcatalogue(context: Context): Promise<readonly ServiceCatalogueEntry[]>;\n\topen(options: {\n\t\treadonly services: readonly { readonly id: string }[];\n\t\tassertAccess(): void;\n\t\tonError(error: Error): void;\n\t}): RemoteServices;\n}\n\nexport interface FacetOptions {\n\treadonly facets: readonly Facet[];\n\treadonly serviceSources?: readonly RemoteServiceSource[];\n\treadonly onError?: (error: Error) => void;\n}\n\nexport interface FacetHost {\n\treadonly services: RemoteServiceProvider;\n\t/** Activate and replace facets with matching IDs without disconnecting consumer service handles. */\n\treload(facets: readonly Facet[]): Promise<void>;\n\tdispose(): Promise<void>;\n}\n\nexport interface LoadedFacets {\n\treadonly facets: readonly Facet[];\n\tdispose(): Promise<void>;\n}\n\nexport interface FacetLoader {\n\tload(): Promise<LoadedFacets>;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Draft, Op } from \"./delta/index.ts\";\nimport type { RemoteServiceProvider } from \"./services/provider.ts\";\n\nexport type { RemoteServiceError } from \"./services/errors.ts\";\nexport type { RemoteServiceProvider } from \"./services/provider.ts\";\n\n/** Typed identity for one value carried by a {@link Context}. */\nexport interface ContextKey<T> {\n\treadonly token: symbol;\n\t/** Type-only marker that prevents keys with different value types from being interchangeable. */\n\treadonly valueType?: (value: T) => T;\n}\n\n/** Immutable invocation-scoped values passed explicitly through operations. */\nexport interface Context {\n\treadonly abortSignal: AbortSignal | undefined;\n\tvalue<T>(key: ContextKey<T>): T | undefined;\n\ttoString(): string;\n}\n\nexport type JsonValue = null | boolean | number | string | JsonValue[] | { [key: string]: JsonValue };\n\ntype IsAny<T> = 0 extends 1 & T ? true : false;\n\n/** Strict-JSON representation of an application data type. Unknown payloads become JsonValue. */\nexport type JsonRepresentation<T> = IsAny<T> extends true\n\t? JsonValue\n\t: unknown extends T\n\t\t? JsonValue\n\t\t: T extends null | boolean | number | string\n\t\t\t? T\n\t\t\t: T extends readonly (infer TItem)[]\n\t\t\t\t? JsonRepresentation<TItem>[]\n\t\t\t\t: T extends object\n\t\t\t\t\t? { [TKey in keyof T]: JsonRepresentation<T[TKey]> }\n\t\t\t\t\t: never;\n\nexport interface ReplicatedStateDelivery {\n\treadonly kind: \"hydrate\" | \"update\";\n\treadonly sequence: number;\n}\n\nexport interface ReplicatedState<T> {\n\t/**\n\t * Contract-immutable value, or undefined until hydration. It is not frozen and may share containers with an\n\t * in-process provider; consumers must not mutate it. Later updates do not mutate previously returned values.\n\t */\n\treadonly value: T | undefined;\n\t/**\n\t * Each subscription serializes callbacks, awaiting hydration before updates. Values are immutable and may\n\t * share unchanged revision data. At most 100 deliveries wait behind the running callback; overflow keeps\n\t * only the newest pending value/context/delivery, so update sequences may skip. Failures are reported in\n\t * isolation and delivery continues. Unsubscribe discards pending work without aborting or joining a callback.\n\t */\n\tsubscribe(listener: (value: T, context: Context, delivery: ReplicatedStateDelivery) => Promise<void>): () => void;\n\tsubscribe(listener: (value: T, context: Context, delivery: ReplicatedStateDelivery) => void): () => void;\n}\n\nexport interface MutableReplicatedState<T extends object> extends ReplicatedState<T> {\n\treadonly value: T;\n\t/**\n\t * Atomically publish one synchronous overlay mutation. Draft handles are unusable after the callback returns.\n\t * Values placed through the draft are cloned by value; assigning `undefined` to an object property deletes it.\n\t */\n\tchange(context: Context, mutate: (draft: Draft<T>) => void): void;\n\t/**\n\t * Atomically take immutable ownership of an alias-free strict-JSON replacement.\n\t * The caller must not mutate the transferred root after this call.\n\t */\n\treplace(context: Context, value: T): void;\n}\n\n/** One immutable authoritative revision committed after an attachment snapshot. */\nexport interface ReplicatedStateSourceFrame<T> {\n\t/** Monotonic source cursor. The first frame after a snapshot must be `snapshot.cursor + 1`. */\n\treadonly cursor: number;\n\t/** The exact immutable value produced by this commit. */\n\treadonly value: T;\n\t/** The exact immutable operation batch that produced `value` from the preceding source revision. */\n\treadonly ops: readonly Op[];\n\treadonly context: Context;\n}\n\nexport interface ReplicatedStateSourceAttachment<T> {\n\t/** Fixed immutable snapshot captured at the atomic attachment boundary. */\n\treadonly snapshot: { readonly value: T; readonly cursor: number };\n\t/**\n\t * Install the sole listener and synchronously drain every buffered frame in source commit order.\n\t * This method is single-use. After it begins, every new committed frame must also be delivered in order\n\t * until disposal, including commits made reentrantly while a prior frame is being delivered.\n\t */\n\tactivate(listener: (frame: ReplicatedStateSourceFrame<T>) => void): void;\n\t/** Stop delivery and release source resources. Disposal must be idempotent. */\n\tdispose(): void;\n}\n\n/**\n * An authoritative immutable revision source.\n *\n * `attach()` must synchronously and atomically capture one snapshot and register the returned attachment to buffer\n * every later committed frame. The snapshot must include every commit before that boundary; buffered frames must\n * include every commit after it, with no overlap or gap. Snapshot values, frame values, and operation batches are\n * immutable and remain valid after delivery. Chord only publishes these references; it never applies or re-diffs them.\n */\nexport interface ReplicatedStateSource<T> {\n\tattach(): ReplicatedStateSourceAttachment<T>;\n}\n\nexport interface ReplicatedStateSourceOptions {\n\t/** Receives source-contract and publication-listener failures without throwing them into the source. */\n\treadonly onError?: (error: Error) => void;\n}\n\n/** A synchronously hydrated publication-only state backed by one source attachment. */\nexport interface AttachedReplicatedState<T> extends ReplicatedState<T> {\n\treadonly value: T;\n\t/** Idempotently release the source attachment. The last published value remains readable. */\n\tdispose(): void;\n}\n\ndeclare const SERVICE_TYPE: unique symbol;\n\nexport type ServiceMode = \"singleton\" | \"keyed\";\n\n/** Stable identity for one shared TypeScript service contract. */\nexport interface Service<T> {\n\treadonly id: string;\n\t/** Process-local services accept unrestricted object contracts and are never published remotely. */\n\treadonly local: boolean;\n\treadonly [SERVICE_TYPE]?: (value: T) => T;\n}\n\ntype InvalidJsonPart<T> = IsAny<T> extends true\n\t? T\n\t: unknown extends T\n\t\t? never\n\t\t: [T] extends [JsonValue]\n\t\t\t? [JsonValue] extends [T]\n\t\t\t\t? never\n\t\t\t\t: InvalidJsonStructure<T>\n\t\t\t: InvalidJsonStructure<T>;\n\ntype InvalidJsonProperty<T> = [Exclude<T, undefined>] extends [never] ? T : InvalidJsonPart<Exclude<T, undefined>>;\n\ntype InvalidJsonStructure<T> = T extends null | boolean | number | string\n\t? never\n\t: T extends readonly (infer TItem)[]\n\t\t? InvalidJsonPart<TItem>\n\t\t: T extends (...args: never[]) => unknown\n\t\t\t? T\n\t\t\t: T extends object\n\t\t\t\t? { [TKey in keyof T]-?: InvalidJsonProperty<T[TKey]> }[keyof T]\n\t\t\t\t: T;\n\ntype InvalidRemoteMember<T> = T extends ReplicatedState<infer TValue>\n\t? InvalidJsonPart<TValue> extends never\n\t\t? never\n\t\t: \"state value is not JSON\"\n\t: T extends (...args: [...infer TArgs, Context]) => Promise<infer TResult>\n\t\t? InvalidJsonPart<TArgs[number]> extends never\n\t\t\t? TResult extends void\n\t\t\t\t? never\n\t\t\t\t: InvalidJsonPart<TResult> extends never\n\t\t\t\t\t? never\n\t\t\t\t\t: \"method result is not JSON or void\"\n\t\t\t: \"method argument is not JSON\"\n\t\t: \"member is not a remote method or ReplicatedState\";\n\ntype InvalidRemoteMemberNames<T> = {\n\t[TKey in keyof T]-?: InvalidRemoteMember<T[TKey]> extends never ? never : TKey;\n}[keyof T];\n\nexport type RemoteServiceContract<T> = InvalidRemoteMemberNames<T> extends never ? T : never;\n\nexport interface ServiceSpawner<T> {\n\tspawn(key: string, implementation: T): () => void;\n}\n\nexport interface RemoteServices {\n\tuse<T>(service: Service<T>): T;\n\tobserve<T>(service: Service<T>, handler: (service: T, context: Context) => void | Promise<void>): () => void;\n\t/** Wait until every currently acquired service has installed its initial snapshot. */\n\tready(context: Context): Promise<void>;\n\tdispose(context: Context): Promise<void>;\n}\n\nexport type ServiceCatalogueEntry = {\n\treadonly serviceId: string;\n\treadonly mode: ServiceMode;\n};\n\nexport type ServiceInstanceAddress = {\n\treadonly key: string;\n\treadonly generation: number;\n};\n\nexport type ServiceMemberSnapshot =\n\t| { readonly name: string; readonly kind: \"method\" }\n\t| { readonly name: string; readonly kind: \"state\"; readonly sequence: number; readonly ops: readonly Op[] };\n\nexport type ServiceInstanceSnapshot = {\n\treadonly instance?: ServiceInstanceAddress;\n\treadonly members: readonly ServiceMemberSnapshot[];\n};\n\nexport type ServiceSubscriptionSnapshot = {\n\treadonly serviceId: string;\n\treadonly mode: ServiceMode;\n\treadonly instances: readonly ServiceInstanceSnapshot[];\n};\n\nexport type ServiceProviderUpdate =\n\t| {\n\t\t\treadonly type: \"state\";\n\t\t\treadonly instance?: ServiceInstanceAddress;\n\t\t\treadonly member: string;\n\t\t\treadonly sequence: number;\n\t\t\treadonly ops: readonly Op[];\n\t }\n\t/** Full subscription rebaseline after overflow; every state is a root replacement at its new sequence. */\n\t| { readonly type: \"reset\"; readonly snapshot: ServiceSubscriptionSnapshot }\n\t| { readonly type: \"unavailable\" }\n\t| { readonly type: \"replaced\"; readonly snapshot: ServiceInstanceSnapshot }\n\t| { readonly type: \"spawned\"; readonly instance: ServiceInstanceSnapshot }\n\t| { readonly type: \"closed\"; readonly instance: ServiceInstanceAddress };\n\nexport type ServiceCall = {\n\treadonly serviceId: string;\n\treadonly instance?: ServiceInstanceAddress;\n\treadonly member: string;\n\t/** Borrowed immutable values. Chord validates but does not clone them. */\n\treadonly args: readonly JsonValue[];\n};\n\nexport interface ServiceSubscription {\n\t/** Atomic baseline. Later updates buffer until activation, with a full reset on pending delivery 101. */\n\treadonly snapshot: ServiceSubscriptionSnapshot;\n\tactivate(): void;\n\tclose(context?: Context): void | Promise<void>;\n}\n\n/**\n * Pluggable wire boundary consumed by a remote service binding.\n *\n * Implementations choose transport, framing, routing, and envelope encoding. Values crossing this\n * boundary must remain strict JSON. Chord does not clone values or require a particular application wire protocol;\n * adapters own serialization and any isolation copies they require.\n *\n */\nexport interface RemoteServiceTransport {\n\tinvoke(call: ServiceCall, context: Context): Promise<JsonValue | undefined>;\n\tsubscribe(\n\t\tserviceId: string,\n\t\tmode: ServiceMode,\n\t\tlistener: (update: ServiceProviderUpdate, context: Context) => void,\n\t\tcontext: Context,\n\t): Promise<ServiceSubscription>;\n}\n\nexport interface RemoteServiceBindingOptions {\n\treadonly services: readonly { readonly id: string }[];\n\treadonly transport: RemoteServiceTransport;\n\treadonly bound?: boolean;\n\treadonly onError?: (error: Error) => void;\n\treadonly assertAccess?: () => void;\n}\n\nexport interface RemoteServiceBinding extends RemoteServices {\n\trebind(bound: boolean, context: Context): Promise<void>;\n}\n\nexport interface FacetEnvironment {\n\t/** Declare a hard dependency on one singleton service and return its stable handle. */\n\tuse<T>(service: Service<T>): T;\n\t/** Declare a hard dependency on a keyed service and observe each live instance. */\n\tobserve<T>(service: Service<T>, handler: (service: T, context: Context) => void | Promise<void>): void;\n\t/** Declare and install this facet's singleton implementation of a service. */\n\tprovide<T>(service: Service<T>, implementation: NoInfer<T>): void;\n\t/** Declare ownership of a multi-instance service and return its deferred spawning capability. */\n\tprovideMany<T>(service: Service<T>): ServiceSpawner<T>;\n\t/**\n\t * Create initialized mutable state by taking immutable ownership of an alias-free strict-JSON root.\n\t * The caller must not mutate `initial` after this call.\n\t */\n\treplicatedState<T extends object>(initial: T): MutableReplicatedState<T>;\n\t/** Give the facet ownership of a resource cleanup function. */\n\town(disposal: () => void | Promise<void>): void;\n\t/** Register asynchronous initialization after dependencies are bound and ready. */\n\tonActivate(callback: () => void | Promise<void>): void;\n\t/** Register final facet teardown. */\n\tonDeactivate(callback: () => void | Promise<void>): void;\n}\n\nexport interface Facet {\n\treadonly id: string;\n\tsetup(env: FacetEnvironment): void;\n}\n\nexport interface RemoteServiceSource {\n\t/** Whether this currently unavailable source may provisionally own absent requirements. */\n\treadonly acceptsUnavailableServices: boolean;\n\tcatalogue(context: Context): Promise<readonly ServiceCatalogueEntry[]>;\n\topen(options: {\n\t\treadonly services: readonly { readonly id: string }[];\n\t\tassertAccess(): void;\n\t\tonError(error: Error): void;\n\t}): RemoteServices;\n}\n\nexport interface FacetOptions {\n\treadonly facets: readonly Facet[];\n\treadonly serviceSources?: readonly RemoteServiceSource[];\n\treadonly onError?: (error: Error) => void;\n}\n\nexport interface FacetHost {\n\treadonly services: RemoteServiceProvider;\n\t/** Activate and replace facets with matching IDs without disconnecting consumer service handles. */\n\treload(facets: readonly Facet[]): Promise<void>;\n\tdispose(): Promise<void>;\n}\n\nexport interface LoadedFacets {\n\treadonly facets: readonly Facet[];\n\tdispose(): Promise<void>;\n}\n\nexport interface FacetLoader {\n\tload(): Promise<LoadedFacets>;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@earendil-works/chord",
3
- "version": "0.87.0",
3
+ "version": "0.99.0",
4
4
  "description": "Application composition runtime for services, replicated state, RPC, and plugins",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -41,7 +41,7 @@
41
41
  ],
42
42
  "scripts": {
43
43
  "clean": "shx rm -rf dist",
44
- "build": "tsgo -p tsconfig.build.json",
44
+ "build": "tsc -p tsconfig.build.json",
45
45
  "test": "vitest --run",
46
46
  "prepublishOnly": "npm run clean && npm run build"
47
47
  },
@@ -67,6 +67,6 @@
67
67
  },
68
68
  "devDependencies": {
69
69
  "shx": "0.4.0",
70
- "vitest": "4.1.9"
70
+ "vitest": "4.1.11"
71
71
  }
72
72
  }