@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":"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;AAAA,CACrG;AAED,MAAM,UAAU,wBAAwB,CAAC,IAAiB,EAAkC;IAC3F,IAAI,IAAI,CAAC,SAAS,KAAK,kBAAkB,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS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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"]}
@@ -0,0 +1,203 @@
1
+ import type { Op } from "./delta/index.ts";
2
+ import type { RemoteServiceProvider } from "./services/provider.ts";
3
+ export type { RemoteServiceError } from "./services/errors.ts";
4
+ export type { RemoteServiceProvider } from "./services/provider.ts";
5
+ /** Typed identity for one value carried by a {@link Context}. */
6
+ export interface ContextKey<T> {
7
+ readonly token: symbol;
8
+ /** Type-only marker that prevents keys with different value types from being interchangeable. */
9
+ readonly valueType?: (value: T) => T;
10
+ }
11
+ /** Immutable invocation-scoped values passed explicitly through operations. */
12
+ export interface Context {
13
+ readonly abortSignal: AbortSignal | undefined;
14
+ value<T>(key: ContextKey<T>): T | undefined;
15
+ toString(): string;
16
+ }
17
+ export type JsonValue = null | boolean | number | string | JsonValue[] | {
18
+ [key: string]: JsonValue;
19
+ };
20
+ type IsAny<T> = 0 extends 1 & T ? true : false;
21
+ /** Strict-JSON representation of an application data type. Unknown payloads become JsonValue. */
22
+ export type JsonRepresentation<T> = IsAny<T> extends true ? JsonValue : unknown extends T ? JsonValue : T extends null | boolean | number | string ? T : T extends readonly (infer TItem)[] ? JsonRepresentation<TItem>[] : T extends object ? {
23
+ [TKey in keyof T]: JsonRepresentation<T[TKey]>;
24
+ } : never;
25
+ export interface ReplicatedStateDelivery {
26
+ readonly kind: "hydrate" | "update";
27
+ readonly sequence: number;
28
+ }
29
+ export interface ReplicatedState<T> {
30
+ /** Immutable value, or undefined until hydration. Later updates do not mutate previously returned values. */
31
+ readonly value: T | undefined;
32
+ /** Listener values are immutable and may structurally share unchanged data with other revisions. */
33
+ subscribe(listener: (value: T, context: Context, delivery: ReplicatedStateDelivery) => void): () => void;
34
+ }
35
+ export interface MutableReplicatedState<T extends object> extends ReplicatedState<T> {
36
+ readonly value: T;
37
+ /** Mutable tracked state. All writes must go through this proxy. */
38
+ readonly state: T;
39
+ /** Publish the changes made through {@link state} since the previous publication. */
40
+ publish(context: Context): void;
41
+ }
42
+ declare const SERVICE_TYPE: unique symbol;
43
+ export type ServiceMode = "singleton" | "keyed";
44
+ /** Stable identity for one shared TypeScript service contract. */
45
+ export interface Service<T> {
46
+ readonly id: string;
47
+ /** Process-local services accept unrestricted object contracts and are never published remotely. */
48
+ readonly local: boolean;
49
+ readonly [SERVICE_TYPE]?: (value: T) => T;
50
+ }
51
+ type InvalidJsonPart<T> = IsAny<T> extends true ? T : unknown extends T ? never : [T] extends [JsonValue] ? [JsonValue] extends [T] ? never : InvalidJsonStructure<T> : InvalidJsonStructure<T>;
52
+ type InvalidJsonProperty<T> = [Exclude<T, undefined>] extends [never] ? T : InvalidJsonPart<Exclude<T, undefined>>;
53
+ type InvalidJsonStructure<T> = T extends null | boolean | number | string ? never : T extends readonly (infer TItem)[] ? InvalidJsonPart<TItem> : T extends (...args: never[]) => unknown ? T : T extends object ? {
54
+ [TKey in keyof T]-?: InvalidJsonProperty<T[TKey]>;
55
+ }[keyof T] : T;
56
+ type InvalidRemoteMember<T> = T extends ReplicatedState<infer TValue> ? InvalidJsonPart<TValue> extends never ? never : "state value is not JSON" : T extends (...args: [...infer TArgs, Context]) => Promise<infer TResult> ? InvalidJsonPart<TArgs[number]> extends never ? TResult extends void ? never : InvalidJsonPart<TResult> extends never ? never : "method result is not JSON or void" : "method argument is not JSON" : "member is not a remote method or ReplicatedState";
57
+ type InvalidRemoteMemberNames<T> = {
58
+ [TKey in keyof T]-?: InvalidRemoteMember<T[TKey]> extends never ? never : TKey;
59
+ }[keyof T];
60
+ export type RemoteServiceContract<T> = InvalidRemoteMemberNames<T> extends never ? T : never;
61
+ export interface ServiceSpawner<T> {
62
+ spawn(key: string, implementation: T): () => void;
63
+ }
64
+ export interface RemoteServices {
65
+ use<T>(service: Service<T>): T;
66
+ observe<T>(service: Service<T>, handler: (service: T, context: Context) => void | Promise<void>): () => void;
67
+ /** Wait until every currently acquired service has installed its initial snapshot. */
68
+ ready(context: Context): Promise<void>;
69
+ dispose(context: Context): Promise<void>;
70
+ }
71
+ export type ServiceCatalogueEntry = {
72
+ readonly serviceId: string;
73
+ readonly mode: ServiceMode;
74
+ };
75
+ export type ServiceInstanceAddress = {
76
+ readonly key: string;
77
+ readonly generation: number;
78
+ };
79
+ export type ServiceMemberSnapshot = {
80
+ readonly name: string;
81
+ readonly kind: "method";
82
+ } | {
83
+ readonly name: string;
84
+ readonly kind: "state";
85
+ readonly sequence: number;
86
+ readonly ops: readonly Op[];
87
+ };
88
+ export type ServiceInstanceSnapshot = {
89
+ readonly instance?: ServiceInstanceAddress;
90
+ readonly members: readonly ServiceMemberSnapshot[];
91
+ };
92
+ export type ServiceSubscriptionSnapshot = {
93
+ readonly serviceId: string;
94
+ readonly mode: ServiceMode;
95
+ readonly instances: readonly ServiceInstanceSnapshot[];
96
+ };
97
+ export type ServiceProviderUpdate = {
98
+ readonly type: "state";
99
+ readonly instance?: ServiceInstanceAddress;
100
+ readonly member: string;
101
+ readonly sequence: number;
102
+ readonly ops: readonly Op[];
103
+ } | {
104
+ readonly type: "unavailable";
105
+ } | {
106
+ readonly type: "replaced";
107
+ readonly snapshot: ServiceInstanceSnapshot;
108
+ } | {
109
+ readonly type: "spawned";
110
+ readonly instance: ServiceInstanceSnapshot;
111
+ } | {
112
+ readonly type: "closed";
113
+ readonly instance: ServiceInstanceAddress;
114
+ };
115
+ export type ServiceCall = {
116
+ readonly serviceId: string;
117
+ readonly instance?: ServiceInstanceAddress;
118
+ readonly member: string;
119
+ /** Borrowed immutable values. Chord validates but does not clone them. */
120
+ readonly args: readonly JsonValue[];
121
+ };
122
+ export interface ServiceSubscription {
123
+ readonly snapshot: ServiceSubscriptionSnapshot;
124
+ activate(): void;
125
+ close(context?: Context): void | Promise<void>;
126
+ }
127
+ /**
128
+ * Pluggable wire boundary consumed by a remote service binding.
129
+ *
130
+ * Implementations choose transport, framing, routing, and envelope encoding. Values crossing this
131
+ * boundary must remain strict JSON. Chord does not clone values or require a particular application wire protocol;
132
+ * adapters own serialization and any isolation copies they require.
133
+ *
134
+ */
135
+ export interface RemoteServiceTransport {
136
+ invoke(call: ServiceCall, context: Context): Promise<JsonValue | undefined>;
137
+ subscribe(serviceId: string, mode: ServiceMode, listener: (update: ServiceProviderUpdate, context: Context) => void, context: Context): Promise<ServiceSubscription>;
138
+ }
139
+ export interface RemoteServiceBindingOptions {
140
+ readonly services: readonly {
141
+ readonly id: string;
142
+ }[];
143
+ readonly transport: RemoteServiceTransport;
144
+ readonly bound?: boolean;
145
+ readonly onError?: (error: Error) => void;
146
+ readonly assertAccess?: () => void;
147
+ }
148
+ export interface RemoteServiceBinding extends RemoteServices {
149
+ rebind(bound: boolean, context: Context): Promise<void>;
150
+ }
151
+ export interface FacetEnvironment {
152
+ /** Declare a hard dependency on one singleton service and return its stable handle. */
153
+ use<T>(service: Service<T>): T;
154
+ /** Declare a hard dependency on a keyed service and observe each live instance. */
155
+ observe<T>(service: Service<T>, handler: (service: T, context: Context) => void | Promise<void>): void;
156
+ /** Declare and install this facet's singleton implementation of a service. */
157
+ provide<T>(service: Service<T>, implementation: NoInfer<T>): void;
158
+ /** Declare ownership of a multi-instance service and return its deferred spawning capability. */
159
+ provideMany<T>(service: Service<T>): ServiceSpawner<T>;
160
+ /** Create initialized mutable state suitable for exposing through a service implementation. */
161
+ replicatedState<T extends object>(initial: T): MutableReplicatedState<T>;
162
+ /** Give the facet ownership of a resource cleanup function. */
163
+ own(disposal: () => void | Promise<void>): void;
164
+ /** Register asynchronous initialization after dependencies are bound and ready. */
165
+ onActivate(callback: () => void | Promise<void>): void;
166
+ /** Register final facet teardown. */
167
+ onDeactivate(callback: () => void | Promise<void>): void;
168
+ }
169
+ export interface Facet {
170
+ readonly id: string;
171
+ setup(env: FacetEnvironment): void;
172
+ }
173
+ export interface RemoteServiceSource {
174
+ /** Whether this currently unavailable source may provisionally own absent requirements. */
175
+ readonly acceptsUnavailableServices: boolean;
176
+ catalogue(context: Context): Promise<readonly ServiceCatalogueEntry[]>;
177
+ open(options: {
178
+ readonly services: readonly {
179
+ readonly id: string;
180
+ }[];
181
+ assertAccess(): void;
182
+ onError(error: Error): void;
183
+ }): RemoteServices;
184
+ }
185
+ export interface FacetOptions {
186
+ readonly facets: readonly Facet[];
187
+ readonly serviceSources?: readonly RemoteServiceSource[];
188
+ readonly onError?: (error: Error) => void;
189
+ }
190
+ export interface FacetHost {
191
+ readonly services: RemoteServiceProvider;
192
+ /** Activate and replace facets with matching IDs without disconnecting consumer service handles. */
193
+ reload(facets: readonly Facet[]): Promise<void>;
194
+ dispose(): Promise<void>;
195
+ }
196
+ export interface LoadedFacets {
197
+ readonly facets: readonly Facet[];
198
+ dispose(): Promise<void>;
199
+ }
200
+ export interface FacetLoader {
201
+ load(): Promise<LoadedFacets>;
202
+ }
203
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +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;AAEpE,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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b,QAAQ,CAAC,QAAQ,EAAE,SAAS;YAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;QACtD,YAAY,IAAI,IAAI,CAAC;QACrB,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;KAC5B,GAAG,cAAc,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IAClC,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACzD,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAC1C;AAED,MAAM,WAAW,SAAS;IACzB,QAAQ,CAAC,QAAQ,EAAE,qBAAqB,CAAC;IACzC,oGAAoG;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\";\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/** Mutable tracked state. All writes must go through this proxy. */\n\treadonly state: T;\n\t/** Publish the changes made through {@link state} since the previous publication. */\n\tpublish(context: Context): 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"]}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +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\";\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/** Mutable tracked state. All writes must go through this proxy. */\n\treadonly state: T;\n\t/** Publish the changes made through {@link state} since the previous publication. */\n\tpublish(context: Context): 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"]}
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@earendil-works/chord",
3
+ "version": "0.0.0",
4
+ "description": "Application composition runtime for services, replicated state, RPC, and plugins",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "source": "./src/index.ts",
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./context": {
15
+ "source": "./src/context/index.ts",
16
+ "types": "./dist/context/index.d.ts",
17
+ "import": "./dist/context/index.js"
18
+ },
19
+ "./delta": {
20
+ "source": "./src/delta/index.ts",
21
+ "types": "./dist/delta/index.d.ts",
22
+ "import": "./dist/delta/index.js"
23
+ },
24
+ "./bundler": {
25
+ "source": "./src/bundler.ts",
26
+ "types": "./dist/bundler.d.ts",
27
+ "import": "./dist/bundler.js"
28
+ },
29
+ "./node": {
30
+ "source": "./src/node.ts",
31
+ "types": "./dist/node.d.ts",
32
+ "import": "./dist/node.js"
33
+ },
34
+ "./package.json": "./package.json"
35
+ },
36
+ "sideEffects": false,
37
+ "files": [
38
+ "dist",
39
+ "README.md",
40
+ "src/delta/README.md"
41
+ ],
42
+ "scripts": {
43
+ "clean": "shx rm -rf dist",
44
+ "build": "tsgo -p tsconfig.build.json",
45
+ "test": "vitest --run",
46
+ "prepublishOnly": "npm run clean && npm run build"
47
+ },
48
+ "keywords": [
49
+ "application",
50
+ "plugins",
51
+ "rpc",
52
+ "services",
53
+ "state"
54
+ ],
55
+ "author": "Earendil Works",
56
+ "license": "MIT",
57
+ "repository": {
58
+ "type": "git",
59
+ "url": "git+https://github.com/earendil-works/pi.git",
60
+ "directory": "packages/chord"
61
+ },
62
+ "engines": {
63
+ "node": ">=22.19.0"
64
+ },
65
+ "dependencies": {
66
+ "esbuild": "0.28.1"
67
+ },
68
+ "devDependencies": {
69
+ "shx": "0.4.0",
70
+ "vitest": "4.1.9"
71
+ }
72
+ }