@earendil-works/chord 1.2.0 → 1.4.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 (122) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/README.md +69 -14
  3. package/dist/cell.d.ts +30 -9
  4. package/dist/cell.d.ts.map +1 -1
  5. package/dist/cell.js +52 -12
  6. package/dist/cell.js.map +1 -1
  7. package/dist/cluster.d.ts +4 -3
  8. package/dist/cluster.d.ts.map +1 -1
  9. package/dist/cluster.js +58 -42
  10. package/dist/cluster.js.map +1 -1
  11. package/dist/connection.d.ts +171 -58
  12. package/dist/connection.d.ts.map +1 -1
  13. package/dist/connection.js +676 -217
  14. package/dist/connection.js.map +1 -1
  15. package/dist/context/index.d.ts +8 -0
  16. package/dist/context/index.d.ts.map +1 -1
  17. package/dist/context/index.js +15 -0
  18. package/dist/context/index.js.map +1 -1
  19. package/dist/contract.d.ts +120 -45
  20. package/dist/contract.d.ts.map +1 -1
  21. package/dist/contract.js +104 -15
  22. package/dist/contract.js.map +1 -1
  23. package/dist/declare.d.ts +11 -48
  24. package/dist/declare.d.ts.map +1 -1
  25. package/dist/declare.js +1 -21
  26. package/dist/declare.js.map +1 -1
  27. package/dist/delta/index.d.ts +2 -1
  28. package/dist/delta/index.d.ts.map +1 -1
  29. package/dist/delta/index.js +4 -0
  30. package/dist/delta/index.js.map +1 -1
  31. package/dist/errors.d.ts +4 -3
  32. package/dist/errors.d.ts.map +1 -1
  33. package/dist/errors.js +15 -0
  34. package/dist/errors.js.map +1 -1
  35. package/dist/host.d.ts +214 -120
  36. package/dist/host.d.ts.map +1 -1
  37. package/dist/host.js +446 -241
  38. package/dist/host.js.map +1 -1
  39. package/dist/index.d.ts +8 -8
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +4 -4
  42. package/dist/index.js.map +1 -1
  43. package/dist/link.d.ts +47 -12
  44. package/dist/link.d.ts.map +1 -1
  45. package/dist/link.js +200 -14
  46. package/dist/link.js.map +1 -1
  47. package/dist/loader.d.ts.map +1 -1
  48. package/dist/loader.js +7 -2
  49. package/dist/loader.js.map +1 -1
  50. package/dist/manager.d.ts.map +1 -1
  51. package/dist/manager.js +35 -9
  52. package/dist/manager.js.map +1 -1
  53. package/dist/object.d.ts +438 -0
  54. package/dist/object.d.ts.map +1 -0
  55. package/dist/{record.js → object.js} +614 -335
  56. package/dist/object.js.map +1 -0
  57. package/dist/output.d.ts +91 -0
  58. package/dist/output.d.ts.map +1 -0
  59. package/dist/output.js +360 -0
  60. package/dist/output.js.map +1 -0
  61. package/dist/registry.d.ts +3 -3
  62. package/dist/registry.d.ts.map +1 -1
  63. package/dist/registry.js +1 -1
  64. package/dist/registry.js.map +1 -1
  65. package/dist/reload.d.ts +35 -27
  66. package/dist/reload.d.ts.map +1 -1
  67. package/dist/reload.js +256 -192
  68. package/dist/reload.js.map +1 -1
  69. package/dist/remote.d.ts +130 -35
  70. package/dist/remote.d.ts.map +1 -1
  71. package/dist/remote.js +493 -189
  72. package/dist/remote.js.map +1 -1
  73. package/dist/sqlite/cloudflare.d.ts +52 -0
  74. package/dist/sqlite/cloudflare.d.ts.map +1 -0
  75. package/dist/sqlite/cloudflare.js +134 -0
  76. package/dist/sqlite/cloudflare.js.map +1 -0
  77. package/dist/sqlite/database.d.ts +37 -0
  78. package/dist/sqlite/database.d.ts.map +1 -0
  79. package/dist/sqlite/database.js +2 -0
  80. package/dist/sqlite/database.js.map +1 -0
  81. package/dist/sqlite/index.d.ts +4 -0
  82. package/dist/sqlite/index.d.ts.map +1 -0
  83. package/dist/sqlite/index.js +3 -0
  84. package/dist/sqlite/index.js.map +1 -0
  85. package/dist/sqlite/migrations.d.ts +10 -0
  86. package/dist/sqlite/migrations.d.ts.map +1 -0
  87. package/dist/sqlite/migrations.js +33 -0
  88. package/dist/sqlite/migrations.js.map +1 -0
  89. package/dist/sqlite/node.d.ts +38 -0
  90. package/dist/sqlite/node.d.ts.map +1 -0
  91. package/dist/sqlite/node.js +174 -0
  92. package/dist/sqlite/node.js.map +1 -0
  93. package/dist/sqlite/schema.d.ts +3 -0
  94. package/dist/sqlite/schema.d.ts.map +1 -0
  95. package/dist/sqlite/schema.js +10 -0
  96. package/dist/sqlite/schema.js.map +1 -0
  97. package/dist/telemetry-sqlite/index.d.ts +24 -0
  98. package/dist/telemetry-sqlite/index.d.ts.map +1 -0
  99. package/dist/telemetry-sqlite/index.js +273 -0
  100. package/dist/telemetry-sqlite/index.js.map +1 -0
  101. package/dist/telemetry-sqlite/store.d.ts +9 -0
  102. package/dist/telemetry-sqlite/store.d.ts.map +1 -0
  103. package/dist/telemetry-sqlite/store.js +110 -0
  104. package/dist/telemetry-sqlite/store.js.map +1 -0
  105. package/dist/types.d.ts +39 -28
  106. package/dist/types.d.ts.map +1 -1
  107. package/dist/types.js.map +1 -1
  108. package/dist/websocket.d.ts +4 -5
  109. package/dist/websocket.d.ts.map +1 -1
  110. package/dist/websocket.js +3 -2
  111. package/dist/websocket.js.map +1 -1
  112. package/dist/wire.d.ts +210 -129
  113. package/dist/wire.d.ts.map +1 -1
  114. package/dist/wire.js +108 -55
  115. package/dist/wire.js.map +1 -1
  116. package/docs/guide.md +267 -203
  117. package/docs/spec.md +141 -114
  118. package/docs/tutorial.md +257 -235
  119. package/package.json +27 -1
  120. package/dist/record.d.ts +0 -320
  121. package/dist/record.d.ts.map +0 -1
  122. package/dist/record.js.map +0 -1
@@ -1,7 +1,8 @@
1
- import type { Static, TSchema } from "typebox";
2
- import type { Ctx, Exposed, HandleBase, Readable, StateSource } from "./types.ts";
1
+ import { type Static, type TSchema, Type } from "typebox";
2
+ import type { Ctx, Exposed, Readable, RefBase, StateSource } from "./types.ts";
3
3
  declare const MEMBER: unique symbol;
4
- export interface MethodSpec<A extends TSchema = TSchema, R extends TSchema = TSchema> {
4
+ /** A method's arguments and result; `undefined`: it takes no arguments, or returns nothing (void). */
5
+ export interface MethodSpec<A extends TSchema | undefined = TSchema | undefined, R extends TSchema | undefined = TSchema | undefined> {
5
6
  readonly [MEMBER]: "method";
6
7
  readonly args: A;
7
8
  readonly result: R;
@@ -12,16 +13,54 @@ export interface OpaqueSpec<T = unknown> {
12
13
  /** Type carrier only; never set. */
13
14
  readonly type?: T;
14
15
  }
15
- export declare const method: <A extends TSchema, R extends TSchema>(args: A, result: R) => MethodSpec<A, R>;
16
+ /**
17
+ * A method. `method()`: no arguments (called as `ref.name(ctx)`, implemented as `(ctx) => …`) and no result.
18
+ * `method(args)`: no result, the handler returns nothing (void). `method(args, result)`, or `method(undefined, result)`
19
+ * for a method without arguments that returns something.
20
+ */
21
+ export declare function method(): MethodSpec<undefined, undefined>;
22
+ export declare function method<A extends TSchema>(args: A): MethodSpec<A, undefined>;
23
+ export declare function method<A extends TSchema | undefined, R extends TSchema>(args: A, result: R): MethodSpec<A, R>;
16
24
  /** A native in-process object identified by `name@version` (local contracts only). */
17
25
  export declare const opaque: <T = unknown>(id: string) => OpaqueSpec<T>;
18
26
  export interface VariantDef {
19
27
  readonly state?: Readonly<Record<string, TSchema>>;
20
28
  readonly methods?: Readonly<Record<string, MethodSpec>>;
21
29
  }
30
+ /** Where objects of a remote type live: one named host. */
31
+ export interface HostNamed {
32
+ readonly name: string;
33
+ }
34
+ /** Where objects of a remote type live: the host `prefix` + the input's string field `key` (`session:` + `session`). */
35
+ export interface HostFamily<K extends string = string> {
36
+ readonly prefix: string;
37
+ readonly key: K;
38
+ }
39
+ /** A remote type's placement: data only, so a description carries it and every host can check it. */
40
+ export type Placement = HostNamed | HostFamily;
41
+ /** Objects of the type live on the host named `name` (`hostNamed("server")`). */
42
+ export declare function hostNamed(name: string): HostNamed;
43
+ /**
44
+ * Objects of the type live on `prefix` + the value of the input's string field `key`: `hostFamily("session:",
45
+ * "session")` puts `{ session: "S1", … }` on `session:S1`. The field is required and must be a non-empty string.
46
+ */
47
+ export declare function hostFamily<const K extends string>(prefix: string, key: K): HostFamily<K>;
48
+ /** Required string fields of `I`: what a `hostFamily` may name. */
49
+ type StringKeys<I> = {
50
+ [K in keyof I]-?: I[K] extends string ? K : never;
51
+ }[keyof I] & string;
52
+ /** The placements a remote type with input `I` may have. */
53
+ export type PlacementFor<I> = HostNamed | HostFamily<StringKeys<I>>;
54
+ /** The host an object of `placement` with this (normalized) input lives on. Throws `invalid/placement`. */
55
+ export declare function resolveHost(typeName: string, placement: Placement, input: unknown): string;
56
+ /** Whether the host named `hostName` may serve a type of `placement`. */
57
+ export declare const placedOn: (placement: Placement, hostName: string) => boolean;
58
+ export declare const placementText: (placement: Placement) => string;
22
59
  export interface RemoteDef {
23
60
  readonly version: number;
24
61
  readonly input: TSchema;
62
+ /** Where its objects live: `hostNamed(…)` or `hostFamily(…)`. Part of the contract (and its fingerprint). */
63
+ readonly host: Placement;
25
64
  readonly variants: Readonly<Record<string, VariantDef>>;
26
65
  }
27
66
  /** A local member: a method, an opaque native object, or a state member described by its schema. */
@@ -31,26 +70,45 @@ export interface LocalDef {
31
70
  readonly input: TSchema;
32
71
  readonly members?: Readonly<Record<string, LocalMember>>;
33
72
  }
34
- export type MemberDescription = {
35
- readonly kind: "method";
36
- readonly args: TSchema;
37
- readonly result: TSchema;
38
- } | {
39
- readonly kind: "state";
40
- readonly schema: TSchema;
41
- } | {
42
- readonly kind: "opaque";
43
- readonly id: string;
44
- };
73
+ declare const MemberDescriptionSchema: Type.TUnion<[Type.TObject<{
74
+ kind: Type.TLiteral<"method">;
75
+ args: Type.TOptional<Type.TUnsafe<TSchema>>;
76
+ result: Type.TOptional<Type.TUnsafe<TSchema>>;
77
+ }>, Type.TObject<{
78
+ kind: Type.TLiteral<"state">;
79
+ schema: Type.TUnsafe<TSchema>;
80
+ }>, Type.TObject<{
81
+ kind: Type.TLiteral<"opaque">;
82
+ id: Type.TString;
83
+ }>]>;
84
+ export type MemberDescription = Static<typeof MemberDescriptionSchema>;
45
85
  /** Local contracts have one unnamed variant. */
46
86
  export declare const LOCAL_VARIANT = "";
47
- export interface Description {
48
- readonly name: string;
49
- readonly scope: "remote" | "local";
50
- readonly version: number;
51
- readonly input: TSchema;
52
- readonly variants: Readonly<Record<string, Readonly<Record<string, MemberDescription>>>>;
53
- }
87
+ export declare const DescriptionSchema: Type.TObject<{
88
+ name: Type.TString;
89
+ scope: Type.TUnion<[Type.TLiteral<"remote">, Type.TLiteral<"local">]>;
90
+ version: Type.TInteger;
91
+ input: Type.TUnsafe<TSchema>;
92
+ /** Remote types only (required there): where their objects live. */
93
+ host: Type.TOptional<Type.TUnion<[Type.TObject<{
94
+ name: Type.TString;
95
+ }>, Type.TObject<{
96
+ prefix: Type.TString;
97
+ key: Type.TString;
98
+ }>]>>;
99
+ variants: Type.TRecord<"^.*$", Type.TRecord<"^.*$", Type.TUnion<[Type.TObject<{
100
+ kind: Type.TLiteral<"method">;
101
+ args: Type.TOptional<Type.TUnsafe<TSchema>>;
102
+ result: Type.TOptional<Type.TUnsafe<TSchema>>;
103
+ }>, Type.TObject<{
104
+ kind: Type.TLiteral<"state">;
105
+ schema: Type.TUnsafe<TSchema>;
106
+ }>, Type.TObject<{
107
+ kind: Type.TLiteral<"opaque">;
108
+ id: Type.TString;
109
+ }>]>>>;
110
+ }>;
111
+ export type Description = Static<typeof DescriptionSchema>;
54
112
  interface ContractBase {
55
113
  readonly name: string;
56
114
  readonly version: number;
@@ -67,9 +125,11 @@ export interface LocalContract<D extends LocalDef = LocalDef> extends ContractBa
67
125
  readonly def: D;
68
126
  }
69
127
  export type AnyContract = RemoteContract | LocalContract;
70
- /** Names a handle uses itself; members may not use them. */
128
+ /** Names a reference uses itself; members may not use them. */
71
129
  export declare const RESERVED_MEMBERS: ReadonlySet<string>;
72
- export declare function remote<const D extends RemoteDef>(name: string, def: D): RemoteContract<D>;
130
+ export declare function remote<const D extends RemoteDef>(name: string, def: D & {
131
+ readonly host: PlacementFor<Static<D["input"]>>;
132
+ }): RemoteContract<D>;
73
133
  export declare function local<const D extends LocalDef>(name: string, def: D): LocalContract<D>;
74
134
  /**
75
135
  * A consumer token received over a link (only its description travels). Has no `def`, so it is only good for binding
@@ -78,12 +138,11 @@ export declare function local<const D extends LocalDef>(name: string, def: D): L
78
138
  export declare function contractFromDescription(description: Description): AnyContract;
79
139
  /** Returns why `provider` does not cover `consumer`, or undefined when it does. */
80
140
  export declare function coverage(provider: Description, consumer: Description): string | undefined;
81
- /** Maps the provider's current behavior to the view a consumer of an older contract version expects. */
141
+ /** Maps the provider's current implementation to the view a consumer of an older contract version expects. */
82
142
  export type Adapter = (current: Record<string, unknown>) => Record<string, unknown>;
83
143
  export type Accepts = Readonly<Record<number, Adapter>>;
84
144
  /** How a consumer token binds to a provider: directly or through an `accepts` adapter. Throws contract_mismatch. */
85
145
  export declare function bind(provider: AnyContract, accepts: Accepts | undefined, consumer: AnyContract): Adapter | undefined;
86
- type UnionToIntersection<U> = (U extends unknown ? (value: U) => void : never) extends (value: infer I) => void ? I : never;
87
146
  type Empty = Record<never, never>;
88
147
  type StateOf<V> = V extends {
89
148
  readonly state: infer S extends Readonly<Record<string, TSchema>>;
@@ -92,22 +151,35 @@ type StaticOf<S> = S extends TSchema ? Static<S> : never;
92
151
  type MethodsOf<V> = V extends {
93
152
  readonly methods: infer M extends Readonly<Record<string, MethodSpec>>;
94
153
  } ? M : Empty;
95
- export type Implementation<M> = M extends MethodSpec<infer A, infer R> ? (args: Static<A>, ctx: Ctx) => Static<R> | Promise<Static<R>> : never;
96
- export type Call<M> = M extends MethodSpec<infer A, infer R> ? (args: Static<A>, ctx?: Ctx) => Promise<Static<R>> : never;
97
- type VariantBehavior<K, V> = {
98
- readonly kind: K;
154
+ /** What a handler returns: the result's value, or nothing for a void method. */
155
+ type Returned<R> = [R] extends [TSchema] ? Static<R> | Promise<Static<R>> : void | Promise<void>;
156
+ /** What a call resolves to. */
157
+ type Resolved<R> = [R] extends [TSchema] ? Static<R> : undefined;
158
+ /** A method's handler; `P` is the app's principal type (`ctx.principal`). */
159
+ export type MethodImplementation<M, P = unknown> = M extends MethodSpec<infer A, infer R> ? [A] extends [TSchema] ? (args: Static<A>, ctx: Ctx<P>) => Returned<R> : (ctx: Ctx<P>) => Returned<R> : never;
160
+ export type Call<M> = M extends MethodSpec<infer A, infer R> ? [A] extends [TSchema] ? (args: Static<A>, ctx?: Ctx) => Promise<Resolved<R>> : (ctx?: Ctx) => Promise<Resolved<R>> : never;
161
+ /** Whether `contract`'s method `name` takes no arguments (it is called as `ref.name(ctx)`). */
162
+ export declare function takesNoArgs(contract: AnyContract, name: string): boolean;
163
+ type VariantImplementation<K, V, P> = {
164
+ readonly variant: K;
99
165
  } & {
100
166
  readonly [S in keyof StateOf<V>]: StateSource<StaticOf<StateOf<V>[S]>>;
101
167
  } & {
102
- readonly [M in keyof MethodsOf<V>]: Implementation<MethodsOf<V>[M]>;
168
+ readonly [M in keyof MethodsOf<V>]: MethodImplementation<MethodsOf<V>[M], P>;
103
169
  };
104
- type VariantHandle<V> = {
105
- readonly [S in keyof StateOf<V>]: Readable<StaticOf<StateOf<V>[S]> | undefined>;
170
+ /**
171
+ * A reference in one variant: its state members are plain readables (a reference you hold has its state) and its
172
+ * methods calls. `variant` discriminates the union `Ref` is for a multi-variant type.
173
+ */
174
+ type VariantRef<C extends AnyContract, K, V> = RefBase<C> & {
175
+ readonly variant: K;
176
+ } & {
177
+ readonly [S in keyof StateOf<V>]: Readable<StaticOf<StateOf<V>[S]>>;
106
178
  } & {
107
179
  readonly [M in keyof MethodsOf<V>]: Call<MethodsOf<V>[M]>;
108
180
  };
109
- type LocalBehaviorMember<M> = M extends MethodSpec ? Implementation<M> : M extends OpaqueSpec<infer T> ? T | Exposed<T> : M extends TSchema ? StateSource<Static<M>> : never;
110
- type LocalHandleMember<M> = M extends MethodSpec ? Call<M> : M extends OpaqueSpec<infer T> ? T | undefined : M extends TSchema ? Readable<Static<M> | undefined> : never;
181
+ type LocalImplementationMember<M, P> = M extends MethodSpec ? MethodImplementation<M, P> : M extends OpaqueSpec<infer T> ? T | Exposed<T> : M extends TSchema ? StateSource<Static<M>> : never;
182
+ type LocalRefMember<M> = M extends MethodSpec ? Call<M> : M extends OpaqueSpec<infer T> ? T | undefined : M extends TSchema ? Readable<Static<M>> : never;
111
183
  type LocalMembers<D> = D extends {
112
184
  readonly members: infer M extends Readonly<Record<string, LocalMember>>;
113
185
  } ? M : Empty;
@@ -116,18 +188,21 @@ export type InputOf<C> = C extends {
116
188
  readonly input: infer I extends TSchema;
117
189
  };
118
190
  } ? Static<I> : never;
119
- /** What a factory returns for contract C. */
120
- export type BehaviorOf<C> = C extends RemoteContract<infer D> ? {
121
- [K in keyof D["variants"]]: VariantBehavior<K, D["variants"][K]>;
191
+ /** What a factory returns for contract C; its methods' `ctx.principal` is `P`. */
192
+ export type ImplementationOf<C, P = unknown> = C extends RemoteContract<infer D> ? {
193
+ [K in keyof D["variants"]]: VariantImplementation<K, D["variants"][K], P>;
122
194
  }[keyof D["variants"]] : C extends LocalContract<infer D> ? {
123
- readonly [K in keyof LocalMembers<D>]: LocalBehaviorMember<LocalMembers<D>[K]>;
195
+ readonly [K in keyof LocalMembers<D>]: LocalImplementationMember<LocalMembers<D>[K], P>;
124
196
  } & Record<string, unknown> : never;
125
- /** Late-bound members a handle exposes for contract C (all variants merged). */
126
- export type MembersOf<C> = C extends RemoteContract<infer D> ? UnionToIntersection<{
127
- [K in keyof D["variants"]]: VariantHandle<D["variants"][K]>;
128
- }[keyof D["variants"]]> : C extends LocalContract<infer D> ? {
129
- readonly [K in keyof LocalMembers<D>]: LocalHandleMember<LocalMembers<D>[K]>;
197
+ /**
198
+ * What `get` returns for contract C. A remote type's reference is a union discriminated by `variant`: another variant's
199
+ * members are reachable only after narrowing (`if (ref.variant === "editor") ref.add(…)`). A local type's reference has
200
+ * its members.
201
+ */
202
+ export type Ref<C extends AnyContract = AnyContract> = C extends RemoteContract<infer D> ? {
203
+ [K in keyof D["variants"]]: VariantRef<C, K, D["variants"][K]>;
204
+ }[keyof D["variants"]] : C extends LocalContract<infer D> ? RefBase<C> & {
205
+ readonly [K in keyof LocalMembers<D>]: LocalRefMember<LocalMembers<D>[K]>;
130
206
  } : never;
131
- export type Handle<C extends AnyContract = AnyContract> = HandleBase<C> & MembersOf<C>;
132
207
  export {};
133
208
  //# sourceMappingURL=contract.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAG/C,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAElF,QAAA,MAAM,MAAM,eAAyB,CAAC;AAEtC,MAAM,WAAW,UAAU,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,CAAC,SAAS,OAAO,GAAG,OAAO;IACnF,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IACjB,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;CACnB;AAED,MAAM,WAAW,UAAU,CAAC,CAAC,GAAG,OAAO;IACtC,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,oCAAoC;IACpC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;CAClB;AAED,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,OAAO,EAAE,CAAC,SAAS,OAAO,QAAQ,CAAC,UAAU,CAAC,KAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAI/F,CAAC;AAEH,sFAAsF;AACtF,eAAO,MAAM,MAAM,GAAI,CAAC,GAAG,OAAO,MAAM,MAAM,KAAG,UAAU,CAAC,CAAC,CAG5D,CAAC;AAEF,MAAM,WAAW,UAAU;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,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KAAK,CAAC"}
package/dist/contract.js CHANGED
@@ -1,22 +1,79 @@
1
- import { ChordError } from "./errors.js";
1
+ import { Type } from "typebox";
2
+ import { Value } from "typebox/value";
3
+ import { ChordError, invalid } from "./errors.js";
2
4
  import { canonicalJson, fits, hash64 } from "./schema.js";
3
5
  const MEMBER = Symbol("chord.member");
4
- export const method = (args, result) => ({
5
- [MEMBER]: "method",
6
- args,
7
- result,
8
- });
6
+ export function method(args, result) {
7
+ return { [MEMBER]: "method", args, result };
8
+ }
9
9
  /** A native in-process object identified by `name@version` (local contracts only). */
10
10
  export const opaque = (id) => {
11
11
  if (!/^[^@\s]+@\d+$/.test(id))
12
12
  throw new TypeError(`opaque id must be name@version: ${id}`);
13
13
  return { [MEMBER]: "opaque", id };
14
14
  };
15
+ /** Objects of the type live on the host named `name` (`hostNamed("server")`). */
16
+ export function hostNamed(name) {
17
+ if (typeof name !== "string" || name === "")
18
+ throw new TypeError("hostNamed needs a host name");
19
+ return { name };
20
+ }
21
+ /**
22
+ * Objects of the type live on `prefix` + the value of the input's string field `key`: `hostFamily("session:",
23
+ * "session")` puts `{ session: "S1", … }` on `session:S1`. The field is required and must be a non-empty string.
24
+ */
25
+ export function hostFamily(prefix, key) {
26
+ if (typeof prefix !== "string" || prefix === "")
27
+ throw new TypeError("hostFamily needs a host-name prefix");
28
+ if (typeof key !== "string" || key === "")
29
+ throw new TypeError("hostFamily needs an input field name");
30
+ return { prefix, key };
31
+ }
32
+ /** The host an object of `placement` with this (normalized) input lives on. Throws `invalid/placement`. */
33
+ export function resolveHost(typeName, placement, input) {
34
+ if ("name" in placement)
35
+ return placement.name;
36
+ const value = input !== null && typeof input === "object" ? input[placement.key] : undefined;
37
+ if (typeof value !== "string" || value === "")
38
+ throw invalid("placement", `${typeName}: input field ${placement.key} names no host`);
39
+ return placement.prefix + value;
40
+ }
41
+ /** Whether the host named `hostName` may serve a type of `placement`. */
42
+ export const placedOn = (placement, hostName) => "name" in placement
43
+ ? placement.name === hostName
44
+ : hostName.startsWith(placement.prefix) && hostName.length > placement.prefix.length;
45
+ export const placementText = (placement) => "name" in placement ? placement.name : `${placement.prefix}<${placement.key}>`;
46
+ // A description travels as a reference's contract token (wire.ts), so it is declared once, as the schema that validates it.
47
+ // `TSchema` is an empty interface: any object is one, which is all a peer's schema is checked for here.
48
+ const SchemaObject = Type.Unsafe(Type.Object({}));
49
+ const MemberDescriptionSchema = Type.Union([
50
+ // Absent `args`: the method takes none. Absent `result`: it returns nothing.
51
+ Type.Object({
52
+ kind: Type.Literal("method"),
53
+ args: Type.Optional(SchemaObject),
54
+ result: Type.Optional(SchemaObject),
55
+ }),
56
+ Type.Object({ kind: Type.Literal("state"), schema: SchemaObject }),
57
+ Type.Object({ kind: Type.Literal("opaque"), id: Type.String() }),
58
+ ]);
15
59
  /** Local contracts have one unnamed variant. */
16
60
  export const LOCAL_VARIANT = "";
17
- /** Names a handle uses itself; members may not use them. */
61
+ const PlacementSchema = Type.Union([
62
+ Type.Object({ name: Type.String({ minLength: 1 }) }, { additionalProperties: false }),
63
+ Type.Object({ prefix: Type.String({ minLength: 1 }), key: Type.String({ minLength: 1 }) }, { additionalProperties: false }),
64
+ ]);
65
+ export const DescriptionSchema = Type.Object({
66
+ name: Type.String({ minLength: 1 }),
67
+ scope: Type.Union([Type.Literal("remote"), Type.Literal("local")]),
68
+ version: Type.Integer(),
69
+ input: SchemaObject,
70
+ /** Remote types only (required there): where their objects live. */
71
+ host: Type.Optional(PlacementSchema),
72
+ variants: Type.Record(Type.String(), Type.Record(Type.String(), MemberDescriptionSchema)),
73
+ });
74
+ /** Names a reference uses itself; members may not use them. */
18
75
  export const RESERVED_MEMBERS = new Set([
19
- "kind",
76
+ "variant",
20
77
  "status",
21
78
  "ready",
22
79
  "shape",
@@ -33,7 +90,11 @@ function describeMember(name, member, scope) {
33
90
  const brand = member[MEMBER];
34
91
  if (brand === "method") {
35
92
  const spec = member;
36
- return { kind: "method", args: spec.args, result: spec.result };
93
+ return {
94
+ kind: "method",
95
+ ...(spec.args === undefined ? {} : { args: spec.args }),
96
+ ...(spec.result === undefined ? {} : { result: spec.result }),
97
+ };
37
98
  }
38
99
  if (brand === "opaque") {
39
100
  if (scope === "remote")
@@ -53,6 +114,11 @@ function checkHeader(name, version) {
53
114
  }
54
115
  export function remote(name, def) {
55
116
  checkHeader(name, def.version);
117
+ const placement = def.host;
118
+ if (placement === undefined || !Value.Check(PlacementSchema, placement))
119
+ throw new TypeError(`remote contract ${name} needs \`host\`: hostNamed(…) or hostFamily(…)`);
120
+ // A JSON copy: the description travels, and a placement object may carry nothing else.
121
+ const host = "name" in placement ? { name: placement.name } : { prefix: placement.prefix, key: placement.key };
56
122
  const variants = {};
57
123
  if (Object.keys(def.variants).length === 0)
58
124
  throw new TypeError(`remote contract ${name} has no variants`);
@@ -69,7 +135,7 @@ export function remote(name, def) {
69
135
  }
70
136
  variants[kind] = members;
71
137
  }
72
- const description = { name, scope: "remote", version: def.version, input: def.input, variants };
138
+ const description = { name, scope: "remote", version: def.version, input: def.input, host, variants };
73
139
  return finish({
74
140
  scope: "remote",
75
141
  name,
@@ -98,19 +164,24 @@ export function local(name, def) {
98
164
  * and validation, never for TypeScript types.
99
165
  */
100
166
  export function contractFromDescription(description) {
101
- const { name, scope, version, input } = description;
102
- if (typeof name !== "string" || (scope !== "remote" && scope !== "local") || !Number.isInteger(version)) {
167
+ const { name, scope, version, input, host } = description;
168
+ if (typeof name !== "string" ||
169
+ (scope !== "remote" && scope !== "local") ||
170
+ !Number.isInteger(version) ||
171
+ (scope === "remote") !== (host !== undefined)) {
103
172
  throw new ChordError("invalid", "malformed contract token", { reason: "token" });
104
173
  }
105
174
  const base = { name, version, input, description, fingerprint: hash64(canonicalJson(description)) };
106
175
  return scope === "remote"
107
- ? { ...base, scope, def: { version, input, variants: {} } }
176
+ ? { ...base, scope, def: { version, input, host: host, variants: {} } }
108
177
  : { ...base, scope, def: { version, input } };
109
178
  }
110
179
  /** Returns why `provider` does not cover `consumer`, or undefined when it does. */
111
180
  export function coverage(provider, consumer) {
112
181
  if (provider.name !== consumer.name || provider.scope !== consumer.scope)
113
182
  return "different type";
183
+ if (!samePlacement(provider, consumer))
184
+ return "host";
114
185
  if (!fits(consumer.input, provider.input))
115
186
  return "input";
116
187
  for (const [kind, consumerMembers] of Object.entries(consumer.variants)) {
@@ -122,9 +193,12 @@ export function coverage(provider, consumer) {
122
193
  if (offered === undefined || offered.kind !== wanted.kind)
123
194
  return `${kind}.${name} missing or of another kind`;
124
195
  if (offered.kind === "method" && wanted.kind === "method") {
125
- if (!fits(wanted.args, offered.args))
196
+ // Both take arguments or neither does; a consumer that expects no result accepts any.
197
+ if ((wanted.args === undefined) !== (offered.args === undefined))
198
+ return `${kind}.${name} arguments`;
199
+ if (wanted.args !== undefined && offered.args !== undefined && !fits(wanted.args, offered.args))
126
200
  return `${kind}.${name} arguments`;
127
- if (!fits(offered.result, wanted.result))
201
+ if (wanted.result !== undefined && (offered.result === undefined || !fits(offered.result, wanted.result)))
128
202
  return `${kind}.${name} result`;
129
203
  }
130
204
  else if (offered.kind === "state" && wanted.kind === "state") {
@@ -138,10 +212,16 @@ export function coverage(provider, consumer) {
138
212
  }
139
213
  return undefined;
140
214
  }
215
+ const samePlacement = (a, b) => canonicalJson(a.host ?? null) === canonicalJson(b.host ?? null);
216
+ const placementOf = (description) => description.host === undefined ? "(local)" : placementText(description.host);
141
217
  /** How a consumer token binds to a provider: directly or through an `accepts` adapter. Throws contract_mismatch. */
142
218
  export function bind(provider, accepts, consumer) {
143
219
  if (provider.fingerprint === consumer.fingerprint)
144
220
  return undefined;
221
+ // A moved type is another type for its consumers: no adapter reaches across hosts.
222
+ if (!samePlacement(provider.description, consumer.description)) {
223
+ throw new ChordError("contract_mismatch", `${provider.name} lives on ${placementOf(provider.description)}, the consumer expects ${placementOf(consumer.description)}`);
224
+ }
145
225
  if (provider.version === consumer.version) {
146
226
  const reason = coverage(provider.description, consumer.description);
147
227
  if (reason === undefined)
@@ -154,4 +234,13 @@ export function bind(provider, accepts, consumer) {
154
234
  }
155
235
  return adapter;
156
236
  }
237
+ /** Whether `contract`'s method `name` takes no arguments (it is called as `ref.name(ctx)`). */
238
+ export function takesNoArgs(contract, name) {
239
+ for (const members of Object.values(contract.description.variants)) {
240
+ const member = members[name];
241
+ if (member?.kind === "method")
242
+ return member.args === undefined;
243
+ }
244
+ return false;
245
+ }
157
246
  //# sourceMappingURL=contract.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAG1D,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AAetC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAuC,IAAO,EAAE,MAAS,EAAoB,EAAE,CAAC,CAAC;IACtG,CAAC,MAAM,CAAC,EAAE,QAAQ;IAClB,IAAI;IACJ,MAAM;CACN,CAAC,CAAC;AAEH,sFAAsF;AACtF,MAAM,CAAC,MAAM,MAAM,GAAG,CAAc,EAAU,EAAiB,EAAE;IAChE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,mCAAmC,EAAE,EAAE,CAAC,CAAC;IAC5F,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;AACnC,CAAC,CAAC;AA2BF,gDAAgD;AAChD,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,CAAC;AA8BhC,4DAA4D;AAC5D,MAAM,CAAC,MAAM,gBAAgB,GAAwB,IAAI,GAAG,CAAC;IAC5D,MAAM;IACN,QAAQ;IACR,OAAO;IACP,OAAO;IACP,OAAO;IACP,SAAS;IACT,UAAU;IACV,SAAS;IACT,MAAM;IACN,UAAU;CACV,CAAC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W,KAAK,QAAQ,CAAC,WAAW;QAAE,OAAO,SAAS,CAAC;IACpE,IAAI,QAAQ,CAAC,OAAO,KAAK,QAAQ,CAAC,OAAO,EAAE,CAAC;QAC3C,MAAM,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;QACpE,IAAI,MAAM,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QAC3C,MAAM,IAAI,UAAU,CACnB,mBAAmB,EACnB,GAAG,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,OAAO,+CAA+C,MAAM,4BAA4B,CACrH,CAAC;IACH,CAAC;IACD,MAAM,OAAO,GAAG,OAAO,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC5C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,IAAI,UAAU,CACnB,mBAAmB,EACnB,GAAG,QAAQ,CAAC,IAAI,sBAAsB,QAAQ,CAAC,OAAO,sBAAsB,QAAQ,CAAC,OAAO,sBAAsB,CAClH,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["import type { Static, TSchema } from \"typebox\";\nimport { ChordError } from \"./errors.ts\";\nimport { canonicalJson, fits, hash64 } from \"./schema.ts\";\nimport type { Ctx, Exposed, HandleBase, Readable, StateSource } from \"./types.ts\";\n\nconst MEMBER = Symbol(\"chord.member\");\n\nexport interface MethodSpec<A extends TSchema = TSchema, R extends TSchema = TSchema> {\n\treadonly [MEMBER]: \"method\";\n\treadonly args: A;\n\treadonly result: R;\n}\n\nexport interface OpaqueSpec<T = unknown> {\n\treadonly [MEMBER]: \"opaque\";\n\treadonly id: string;\n\t/** Type carrier only; never set. */\n\treadonly type?: T;\n}\n\nexport const method = <A extends TSchema, R extends TSchema>(args: A, result: R): MethodSpec<A, R> => ({\n\t[MEMBER]: \"method\",\n\targs,\n\tresult,\n});\n\n/** A native in-process object identified by `name@version` (local contracts only). */\nexport const opaque = <T = unknown>(id: string): OpaqueSpec<T> => {\n\tif (!/^[^@\\s]+@\\d+$/.test(id)) throw new TypeError(`opaque id must be name@version: ${id}`);\n\treturn { [MEMBER]: \"opaque\", id };\n};\n\nexport interface VariantDef {\n\treadonly state?: Readonly<Record<string, TSchema>>;\n\treadonly methods?: Readonly<Record<string, MethodSpec>>;\n}\n\nexport interface RemoteDef {\n\treadonly version: number;\n\treadonly input: TSchema;\n\treadonly variants: Readonly<Record<string, VariantDef>>;\n}\n\n/** A local member: a method, an opaque native object, or a state member described by its schema. */\nexport type LocalMember = MethodSpec | OpaqueSpec | TSchema;\n\nexport interface LocalDef {\n\treadonly version: number;\n\treadonly input: TSchema;\n\treadonly members?: Readonly<Record<string, LocalMember>>;\n}\n\nexport type MemberDescription =\n\t| { readonly kind: \"method\"; readonly args: TSchema; readonly result: TSchema }\n\t| { readonly kind: \"state\"; readonly schema: TSchema }\n\t| { readonly kind: \"opaque\"; readonly id: string };\n\n/** Local contracts have one unnamed variant. */\nexport const LOCAL_VARIANT = \"\";\n\nexport interface Description {\n\treadonly name: string;\n\treadonly scope: \"remote\" | \"local\";\n\treadonly version: number;\n\treadonly input: TSchema;\n\treadonly variants: Readonly<Record<string, Readonly<Record<string, MemberDescription>>>>;\n}\n\ninterface ContractBase {\n\treadonly name: string;\n\treadonly version: number;\n\treadonly input: TSchema;\n\treadonly description: Description;\n\treadonly fingerprint: string;\n}\n\nexport interface RemoteContract<D extends RemoteDef = RemoteDef> extends ContractBase {\n\treadonly scope: \"remote\";\n\treadonly def: D;\n}\n\nexport interface LocalContract<D extends LocalDef = LocalDef> extends ContractBase {\n\treadonly scope: \"local\";\n\treadonly def: D;\n}\n\nexport type AnyContract = RemoteContract | LocalContract;\n\n/** Names a handle uses itself; members may not use them. */\nexport const RESERVED_MEMBERS: ReadonlySet<string> = new Set([\n\t\"kind\",\n\t\"status\",\n\t\"ready\",\n\t\"shape\",\n\t\"error\",\n\t\"onShape\",\n\t\"onStatus\",\n\t\"release\",\n\t\"then\",\n\t\"contract\",\n]);\n\nfunction describeMember(name: string, member: unknown, scope: \"remote\" | \"local\"): MemberDescription {\n\tif (RESERVED_MEMBERS.has(name)) throw new TypeError(`member name is reserved: ${name}`);\n\tconst brand = (member as { [MEMBER]?: string })[MEMBER];\n\tif (brand === \"method\") {\n\t\tconst spec = member as MethodSpec;\n\t\treturn { kind: \"method\", args: spec.args, result: spec.result };\n\t}\n\tif (brand === \"opaque\") {\n\t\tif (scope === \"remote\") throw new TypeError(`remote contracts cannot expose opaque members: ${name}`);\n\t\treturn { kind: \"opaque\", id: (member as OpaqueSpec).id };\n\t}\n\treturn { kind: \"state\", schema: member as TSchema };\n}\n\nfunction finish<C extends AnyContract>(contract: Omit<C, \"fingerprint\">): C {\n\treturn { ...contract, fingerprint: hash64(canonicalJson(contract.description)) } as C;\n}\n\nfunction checkHeader(name: string, version: number): void {\n\tif (!name) throw new TypeError(\"contract name is empty\");\n\tif (!Number.isInteger(version) || version < 1) throw new TypeError(`contract version must be a positive integer`);\n}\n\nexport function remote<const D extends RemoteDef>(name: string, def: D): RemoteContract<D> {\n\tcheckHeader(name, def.version);\n\tconst variants: Record<string, Record<string, MemberDescription>> = {};\n\tif (Object.keys(def.variants).length === 0) throw new TypeError(`remote contract ${name} has no variants`);\n\tfor (const [kind, variant] of Object.entries(def.variants)) {\n\t\tconst members: Record<string, MemberDescription> = {};\n\t\tfor (const [key, schema] of Object.entries(variant.state ?? {}))\n\t\t\tmembers[key] = describeMember(key, schema, \"remote\");\n\t\tfor (const [key, spec] of Object.entries(variant.methods ?? {})) {\n\t\t\tif (key in members) throw new TypeError(`member ${key} is both state and method in ${name}.${kind}`);\n\t\t\tmembers[key] = describeMember(key, spec, \"remote\");\n\t\t\tif (members[key].kind !== \"method\") throw new TypeError(`methods.${key} is not a method()`);\n\t\t}\n\t\tvariants[kind] = members;\n\t}\n\tconst description: Description = { name, scope: \"remote\", version: def.version, input: def.input, variants };\n\treturn finish<RemoteContract<D>>({\n\t\tscope: \"remote\",\n\t\tname,\n\t\tversion: def.version,\n\t\tinput: def.input,\n\t\tdef,\n\t\tdescription,\n\t});\n}\n\nexport function local<const D extends LocalDef>(name: string, def: D): LocalContract<D> {\n\tcheckHeader(name, def.version);\n\tconst members: Record<string, MemberDescription> = {};\n\tfor (const [key, member] of Object.entries(def.members ?? {})) members[key] = describeMember(key, member, \"local\");\n\tconst description: Description = {\n\t\tname,\n\t\tscope: \"local\",\n\t\tversion: def.version,\n\t\tinput: def.input,\n\t\tvariants: { [LOCAL_VARIANT]: members },\n\t};\n\treturn finish<LocalContract<D>>({ scope: \"local\", name, version: def.version, input: def.input, def, description });\n}\n\n/**\n * A consumer token received over a link (only its description travels). Has no `def`, so it is only good for binding\n * and validation, never for TypeScript types.\n */\nexport function contractFromDescription(description: Description): AnyContract {\n\tconst { name, scope, version, input } = description;\n\tif (typeof name !== \"string\" || (scope !== \"remote\" && scope !== \"local\") || !Number.isInteger(version)) {\n\t\tthrow new ChordError(\"invalid\", \"malformed contract token\", { reason: \"token\" });\n\t}\n\tconst base = { name, version, input, description, fingerprint: hash64(canonicalJson(description)) };\n\treturn scope === \"remote\"\n\t\t? { ...base, scope, def: { version, input, variants: {} } }\n\t\t: { ...base, scope, def: { version, input } };\n}\n\n/** Returns why `provider` does not cover `consumer`, or undefined when it does. */\nexport function coverage(provider: Description, consumer: Description): string | undefined {\n\tif (provider.name !== consumer.name || provider.scope !== consumer.scope) return \"different type\";\n\tif (!fits(consumer.input, provider.input)) return \"input\";\n\tfor (const [kind, consumerMembers] of Object.entries(consumer.variants)) {\n\t\tconst providerMembers = provider.variants[kind];\n\t\tif (providerMembers === undefined) return `variant ${kind} missing`;\n\t\tfor (const [name, wanted] of Object.entries(consumerMembers)) {\n\t\t\tconst offered = providerMembers[name];\n\t\t\tif (offered === undefined || offered.kind !== wanted.kind) return `${kind}.${name} missing or of another kind`;\n\t\t\tif (offered.kind === \"method\" && wanted.kind === \"method\") {\n\t\t\t\tif (!fits(wanted.args, offered.args)) return `${kind}.${name} arguments`;\n\t\t\t\tif (!fits(offered.result, wanted.result)) return `${kind}.${name} result`;\n\t\t\t} else if (offered.kind === \"state\" && wanted.kind === \"state\") {\n\t\t\t\tif (!fits(offered.schema, wanted.schema)) return `${kind}.${name} state`;\n\t\t\t} else if (offered.kind === \"opaque\" && wanted.kind === \"opaque\" && offered.id !== wanted.id) {\n\t\t\t\treturn `${kind}.${name} opaque ${offered.id} != ${wanted.id}`;\n\t\t\t}\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/** Maps the provider's current behavior to the view a consumer of an older contract version expects. */\nexport type Adapter = (current: Record<string, unknown>) => Record<string, unknown>;\nexport type Accepts = Readonly<Record<number, Adapter>>;\n\n/** How a consumer token binds to a provider: directly or through an `accepts` adapter. Throws contract_mismatch. */\nexport function bind(provider: AnyContract, accepts: Accepts | undefined, consumer: AnyContract): Adapter | undefined {\n\tif (provider.fingerprint === consumer.fingerprint) return undefined;\n\tif (provider.version === consumer.version) {\n\t\tconst reason = coverage(provider.description, consumer.description);\n\t\tif (reason === undefined) return undefined;\n\t\tthrow new ChordError(\n\t\t\t\"contract_mismatch\",\n\t\t\t`${provider.name}@${provider.version} does not cover the consumer's description (${reason}); forgotten version bump?`,\n\t\t);\n\t}\n\tconst adapter = accepts?.[consumer.version];\n\tif (adapter === undefined) {\n\t\tthrow new ChordError(\n\t\t\t\"contract_mismatch\",\n\t\t\t`${provider.name}: provider version ${provider.version}, consumer version ${consumer.version}, no accepts adapter`,\n\t\t);\n\t}\n\treturn adapter;\n}\n\n// ─── Static types ────────────────────────────────────────────────────────────\n\ntype UnionToIntersection<U> = (U extends unknown ? (value: U) => void : never) extends (value: infer I) => void\n\t? I\n\t: never;\ntype Empty = Record<never, never>;\ntype StateOf<V> = V extends { readonly state: infer S extends Readonly<Record<string, TSchema>> } ? S : Empty;\ntype StaticOf<S> = S extends TSchema ? Static<S> : never;\ntype MethodsOf<V> = V extends { readonly methods: infer M extends Readonly<Record<string, MethodSpec>> } ? M : Empty;\n\nexport type Implementation<M> = M extends MethodSpec<infer A, infer R>\n\t? (args: Static<A>, ctx: Ctx) => Static<R> | Promise<Static<R>>\n\t: never;\nexport type Call<M> = M extends MethodSpec<infer A, infer R>\n\t? (args: Static<A>, ctx?: Ctx) => Promise<Static<R>>\n\t: never;\n\ntype VariantBehavior<K, V> = { readonly kind: K } & {\n\treadonly [S in keyof StateOf<V>]: StateSource<StaticOf<StateOf<V>[S]>>;\n} & {\n\treadonly [M in keyof MethodsOf<V>]: Implementation<MethodsOf<V>[M]>;\n};\ntype VariantHandle<V> = { readonly [S in keyof StateOf<V>]: Readable<StaticOf<StateOf<V>[S]> | undefined> } & {\n\treadonly [M in keyof MethodsOf<V>]: Call<MethodsOf<V>[M]>;\n};\n\ntype LocalBehaviorMember<M> = M extends MethodSpec\n\t? Implementation<M>\n\t: M extends OpaqueSpec<infer T>\n\t\t? T | Exposed<T>\n\t\t: M extends TSchema\n\t\t\t? StateSource<Static<M>>\n\t\t\t: never;\ntype LocalHandleMember<M> = M extends MethodSpec\n\t? Call<M>\n\t: M extends OpaqueSpec<infer T>\n\t\t? T | undefined\n\t\t: M extends TSchema\n\t\t\t? Readable<Static<M> | undefined>\n\t\t\t: never;\ntype LocalMembers<D> = D extends { readonly members: infer M extends Readonly<Record<string, LocalMember>> }\n\t? M\n\t: Empty;\n\nexport type InputOf<C> = C extends { readonly def: { readonly input: infer I extends TSchema } } ? Static<I> : never;\n\n/** What a factory returns for contract C. */\nexport type BehaviorOf<C> = C extends RemoteContract<infer D>\n\t? { [K in keyof D[\"variants\"]]: VariantBehavior<K, D[\"variants\"][K]> }[keyof D[\"variants\"]]\n\t: C extends LocalContract<infer D>\n\t\t? { readonly [K in keyof LocalMembers<D>]: LocalBehaviorMember<LocalMembers<D>[K]> } & Record<string, unknown>\n\t\t: never;\n\n/** Late-bound members a handle exposes for contract C (all variants merged). */\nexport type MembersOf<C> = C extends RemoteContract<infer D>\n\t? UnionToIntersection<{ [K in keyof D[\"variants\"]]: VariantHandle<D[\"variants\"][K]> }[keyof D[\"variants\"]]>\n\t: C extends LocalContract<infer D>\n\t\t? { readonly [K in keyof LocalMembers<D>]: LocalHandleMember<LocalMembers<D>[K]> }\n\t\t: never;\n\nexport type Handle<C extends AnyContract = AnyContract> = HandleBase<C> & MembersOf<C>;\n"]}
1
+ {"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,IAAI,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAG1D,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AA2BtC,MAAM,UAAU,MAAM,CAAC,IAAc,EAAE,MAAgB;IACtD,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC7C,CAAC;AAED,sFAAsF;AACtF,MAAM,CAAC,MAAM,MAAM,GAAG,CAAc,EAAU,EAAiB,EAAE;IAChE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,mCAAmC,EAAE,EAAE,CAAC,CAAC;IAC5F,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;AACnC,CAAC,CAAC;AAqBF,iFAAiF;AACjF,MAAM,UAAU,SAAS,CAAC,IAAY;IACrC,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,EAAE;QAAE,MAAM,IAAI,SAAS,CAAC,6BAA6B,CAAC,CAAC;IAChG,OAAO,EAAE,IAAI,EAAE,CAAC;AACjB,CAAC;AAED;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IAAI,KAAK,SAAS,CAAC;IACjE,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import { type Static, type TSchema, Type } from \"typebox\";\nimport { Value } from \"typebox/value\";\nimport { ChordError, invalid } from \"./errors.ts\";\nimport { canonicalJson, fits, hash64 } from \"./schema.ts\";\nimport type { Ctx, Exposed, Readable, RefBase, StateSource } from \"./types.ts\";\n\nconst MEMBER = Symbol(\"chord.member\");\n\n/** A method's arguments and result; `undefined`: it takes no arguments, or returns nothing (void). */\nexport interface MethodSpec<\n\tA extends TSchema | undefined = TSchema | undefined,\n\tR extends TSchema | undefined = TSchema | undefined,\n> {\n\treadonly [MEMBER]: \"method\";\n\treadonly args: A;\n\treadonly result: R;\n}\n\nexport interface OpaqueSpec<T = unknown> {\n\treadonly [MEMBER]: \"opaque\";\n\treadonly id: string;\n\t/** Type carrier only; never set. */\n\treadonly type?: T;\n}\n\n/**\n * A method. `method()`: no arguments (called as `ref.name(ctx)`, implemented as `(ctx) => …`) and no result.\n * `method(args)`: no result, the handler returns nothing (void). `method(args, result)`, or `method(undefined, result)`\n * for a method without arguments that returns something.\n */\nexport function method(): MethodSpec<undefined, undefined>;\nexport function method<A extends TSchema>(args: A): MethodSpec<A, undefined>;\nexport function method<A extends TSchema | undefined, R extends TSchema>(args: A, result: R): MethodSpec<A, R>;\nexport function method(args?: TSchema, result?: TSchema): MethodSpec {\n\treturn { [MEMBER]: \"method\", args, result };\n}\n\n/** A native in-process object identified by `name@version` (local contracts only). */\nexport const opaque = <T = unknown>(id: string): OpaqueSpec<T> => {\n\tif (!/^[^@\\s]+@\\d+$/.test(id)) throw new TypeError(`opaque id must be name@version: ${id}`);\n\treturn { [MEMBER]: \"opaque\", id };\n};\n\nexport interface VariantDef {\n\treadonly state?: Readonly<Record<string, TSchema>>;\n\treadonly methods?: Readonly<Record<string, MethodSpec>>;\n}\n\n/** Where objects of a remote type live: one named host. */\nexport interface HostNamed {\n\treadonly name: string;\n}\n\n/** Where objects of a remote type live: the host `prefix` + the input's string field `key` (`session:` + `session`). */\nexport interface HostFamily<K extends string = string> {\n\treadonly prefix: string;\n\treadonly key: K;\n}\n\n/** A remote type's placement: data only, so a description carries it and every host can check it. */\nexport type Placement = HostNamed | HostFamily;\n\n/** Objects of the type live on the host named `name` (`hostNamed(\"server\")`). */\nexport function hostNamed(name: string): HostNamed {\n\tif (typeof name !== \"string\" || name === \"\") throw new TypeError(\"hostNamed needs a host name\");\n\treturn { name };\n}\n\n/**\n * Objects of the type live on `prefix` + the value of the input's string field `key`: `hostFamily(\"session:\",\n * \"session\")` puts `{ session: \"S1\", … }` on `session:S1`. The field is required and must be a non-empty string.\n */\nexport function hostFamily<const K extends string>(prefix: string, key: K): HostFamily<K> {\n\tif (typeof prefix !== \"string\" || prefix === \"\") throw new TypeError(\"hostFamily needs a host-name prefix\");\n\tif (typeof key !== \"string\" || key === \"\") throw new TypeError(\"hostFamily needs an input field name\");\n\treturn { prefix, key };\n}\n\n/** Required string fields of `I`: what a `hostFamily` may name. */\ntype StringKeys<I> = { [K in keyof I]-?: I[K] extends string ? K : never }[keyof I] & string;\n/** The placements a remote type with input `I` may have. */\nexport type PlacementFor<I> = HostNamed | HostFamily<StringKeys<I>>;\n\n/** The host an object of `placement` with this (normalized) input lives on. Throws `invalid/placement`. */\nexport function resolveHost(typeName: string, placement: Placement, input: unknown): string {\n\tif (\"name\" in placement) return placement.name;\n\tconst value =\n\t\tinput !== null && typeof input === \"object\" ? (input as Record<string, unknown>)[placement.key] : undefined;\n\tif (typeof value !== \"string\" || value === \"\")\n\t\tthrow invalid(\"placement\", `${typeName}: input field ${placement.key} names no host`);\n\treturn placement.prefix + value;\n}\n\n/** Whether the host named `hostName` may serve a type of `placement`. */\nexport const placedOn = (placement: Placement, hostName: string): boolean =>\n\t\"name\" in placement\n\t\t? placement.name === hostName\n\t\t: hostName.startsWith(placement.prefix) && hostName.length > placement.prefix.length;\n\nexport const placementText = (placement: Placement): string =>\n\t\"name\" in placement ? placement.name : `${placement.prefix}<${placement.key}>`;\n\nexport interface RemoteDef {\n\treadonly version: number;\n\treadonly input: TSchema;\n\t/** Where its objects live: `hostNamed(…)` or `hostFamily(…)`. Part of the contract (and its fingerprint). */\n\treadonly host: Placement;\n\treadonly variants: Readonly<Record<string, VariantDef>>;\n}\n\n/** A local member: a method, an opaque native object, or a state member described by its schema. */\nexport type LocalMember = MethodSpec | OpaqueSpec | TSchema;\n\nexport interface LocalDef {\n\treadonly version: number;\n\treadonly input: TSchema;\n\treadonly members?: Readonly<Record<string, LocalMember>>;\n}\n\n// A description travels as a reference's contract token (wire.ts), so it is declared once, as the schema that validates it.\n// `TSchema` is an empty interface: any object is one, which is all a peer's schema is checked for here.\nconst SchemaObject = Type.Unsafe<TSchema>(Type.Object({}));\n\nconst MemberDescriptionSchema = Type.Union([\n\t// Absent `args`: the method takes none. Absent `result`: it returns nothing.\n\tType.Object({\n\t\tkind: Type.Literal(\"method\"),\n\t\targs: Type.Optional(SchemaObject),\n\t\tresult: Type.Optional(SchemaObject),\n\t}),\n\tType.Object({ kind: Type.Literal(\"state\"), schema: SchemaObject }),\n\tType.Object({ kind: Type.Literal(\"opaque\"), id: Type.String() }),\n]);\nexport type MemberDescription = Static<typeof MemberDescriptionSchema>;\n\n/** Local contracts have one unnamed variant. */\nexport const LOCAL_VARIANT = \"\";\n\nconst PlacementSchema = Type.Union([\n\tType.Object({ name: Type.String({ minLength: 1 }) }, { additionalProperties: false }),\n\tType.Object(\n\t\t{ prefix: Type.String({ minLength: 1 }), key: Type.String({ minLength: 1 }) },\n\t\t{ additionalProperties: false },\n\t),\n]);\n\nexport const DescriptionSchema = Type.Object({\n\tname: Type.String({ minLength: 1 }),\n\tscope: Type.Union([Type.Literal(\"remote\"), Type.Literal(\"local\")]),\n\tversion: Type.Integer(),\n\tinput: SchemaObject,\n\t/** Remote types only (required there): where their objects live. */\n\thost: Type.Optional(PlacementSchema),\n\tvariants: Type.Record(Type.String(), Type.Record(Type.String(), MemberDescriptionSchema)),\n});\nexport type Description = Static<typeof DescriptionSchema>;\n\ninterface ContractBase {\n\treadonly name: string;\n\treadonly version: number;\n\treadonly input: TSchema;\n\treadonly description: Description;\n\treadonly fingerprint: string;\n}\n\nexport interface RemoteContract<D extends RemoteDef = RemoteDef> extends ContractBase {\n\treadonly scope: \"remote\";\n\treadonly def: D;\n}\n\nexport interface LocalContract<D extends LocalDef = LocalDef> extends ContractBase {\n\treadonly scope: \"local\";\n\treadonly def: D;\n}\n\nexport type AnyContract = RemoteContract | LocalContract;\n\n/** Names a reference uses itself; members may not use them. */\nexport const RESERVED_MEMBERS: ReadonlySet<string> = new Set([\n\t\"variant\",\n\t\"status\",\n\t\"ready\",\n\t\"shape\",\n\t\"error\",\n\t\"onShape\",\n\t\"onStatus\",\n\t\"release\",\n\t\"then\",\n\t\"contract\",\n]);\n\nfunction describeMember(name: string, member: unknown, scope: \"remote\" | \"local\"): MemberDescription {\n\tif (RESERVED_MEMBERS.has(name)) throw new TypeError(`member name is reserved: ${name}`);\n\tconst brand = (member as { [MEMBER]?: string })[MEMBER];\n\tif (brand === \"method\") {\n\t\tconst spec = member as MethodSpec;\n\t\treturn {\n\t\t\tkind: \"method\",\n\t\t\t...(spec.args === undefined ? {} : { args: spec.args }),\n\t\t\t...(spec.result === undefined ? {} : { result: spec.result }),\n\t\t};\n\t}\n\tif (brand === \"opaque\") {\n\t\tif (scope === \"remote\") throw new TypeError(`remote contracts cannot expose opaque members: ${name}`);\n\t\treturn { kind: \"opaque\", id: (member as OpaqueSpec).id };\n\t}\n\treturn { kind: \"state\", schema: member as TSchema };\n}\n\nfunction finish<C extends AnyContract>(contract: Omit<C, \"fingerprint\">): C {\n\treturn { ...contract, fingerprint: hash64(canonicalJson(contract.description)) } as C;\n}\n\nfunction checkHeader(name: string, version: number): void {\n\tif (!name) throw new TypeError(\"contract name is empty\");\n\tif (!Number.isInteger(version) || version < 1) throw new TypeError(`contract version must be a positive integer`);\n}\n\nexport function remote<const D extends RemoteDef>(\n\tname: string,\n\tdef: D & { readonly host: PlacementFor<Static<D[\"input\"]>> },\n): RemoteContract<D> {\n\tcheckHeader(name, def.version);\n\tconst placement = def.host as Placement | undefined;\n\tif (placement === undefined || !Value.Check(PlacementSchema, placement))\n\t\tthrow new TypeError(`remote contract ${name} needs \\`host\\`: hostNamed(…) or hostFamily(…)`);\n\t// A JSON copy: the description travels, and a placement object may carry nothing else.\n\tconst host: Placement =\n\t\t\"name\" in placement ? { name: placement.name } : { prefix: placement.prefix, key: placement.key };\n\tconst variants: Record<string, Record<string, MemberDescription>> = {};\n\tif (Object.keys(def.variants).length === 0) throw new TypeError(`remote contract ${name} has no variants`);\n\tfor (const [kind, variant] of Object.entries(def.variants)) {\n\t\tconst members: Record<string, MemberDescription> = {};\n\t\tfor (const [key, schema] of Object.entries(variant.state ?? {}))\n\t\t\tmembers[key] = describeMember(key, schema, \"remote\");\n\t\tfor (const [key, spec] of Object.entries(variant.methods ?? {})) {\n\t\t\tif (key in members) throw new TypeError(`member ${key} is both state and method in ${name}.${kind}`);\n\t\t\tmembers[key] = describeMember(key, spec, \"remote\");\n\t\t\tif (members[key].kind !== \"method\") throw new TypeError(`methods.${key} is not a method()`);\n\t\t}\n\t\tvariants[kind] = members;\n\t}\n\tconst description: Description = { name, scope: \"remote\", version: def.version, input: def.input, host, variants };\n\treturn finish<RemoteContract<D>>({\n\t\tscope: \"remote\",\n\t\tname,\n\t\tversion: def.version,\n\t\tinput: def.input,\n\t\tdef,\n\t\tdescription,\n\t});\n}\n\nexport function local<const D extends LocalDef>(name: string, def: D): LocalContract<D> {\n\tcheckHeader(name, def.version);\n\tconst members: Record<string, MemberDescription> = {};\n\tfor (const [key, member] of Object.entries(def.members ?? {})) members[key] = describeMember(key, member, \"local\");\n\tconst description: Description = {\n\t\tname,\n\t\tscope: \"local\",\n\t\tversion: def.version,\n\t\tinput: def.input,\n\t\tvariants: { [LOCAL_VARIANT]: members },\n\t};\n\treturn finish<LocalContract<D>>({ scope: \"local\", name, version: def.version, input: def.input, def, description });\n}\n\n/**\n * A consumer token received over a link (only its description travels). Has no `def`, so it is only good for binding\n * and validation, never for TypeScript types.\n */\nexport function contractFromDescription(description: Description): AnyContract {\n\tconst { name, scope, version, input, host } = description;\n\tif (\n\t\ttypeof name !== \"string\" ||\n\t\t(scope !== \"remote\" && scope !== \"local\") ||\n\t\t!Number.isInteger(version) ||\n\t\t(scope === \"remote\") !== (host !== undefined)\n\t) {\n\t\tthrow new ChordError(\"invalid\", \"malformed contract token\", { reason: \"token\" });\n\t}\n\tconst base = { name, version, input, description, fingerprint: hash64(canonicalJson(description)) };\n\treturn scope === \"remote\"\n\t\t? { ...base, scope, def: { version, input, host: host!, variants: {} } }\n\t\t: { ...base, scope, def: { version, input } };\n}\n\n/** Returns why `provider` does not cover `consumer`, or undefined when it does. */\nexport function coverage(provider: Description, consumer: Description): string | undefined {\n\tif (provider.name !== consumer.name || provider.scope !== consumer.scope) return \"different type\";\n\tif (!samePlacement(provider, consumer)) return \"host\";\n\tif (!fits(consumer.input, provider.input)) return \"input\";\n\tfor (const [kind, consumerMembers] of Object.entries(consumer.variants)) {\n\t\tconst providerMembers = provider.variants[kind];\n\t\tif (providerMembers === undefined) return `variant ${kind} missing`;\n\t\tfor (const [name, wanted] of Object.entries(consumerMembers)) {\n\t\t\tconst offered = providerMembers[name];\n\t\t\tif (offered === undefined || offered.kind !== wanted.kind) return `${kind}.${name} missing or of another kind`;\n\t\t\tif (offered.kind === \"method\" && wanted.kind === \"method\") {\n\t\t\t\t// Both take arguments or neither does; a consumer that expects no result accepts any.\n\t\t\t\tif ((wanted.args === undefined) !== (offered.args === undefined)) return `${kind}.${name} arguments`;\n\t\t\t\tif (wanted.args !== undefined && offered.args !== undefined && !fits(wanted.args, offered.args))\n\t\t\t\t\treturn `${kind}.${name} arguments`;\n\t\t\t\tif (wanted.result !== undefined && (offered.result === undefined || !fits(offered.result, wanted.result)))\n\t\t\t\t\treturn `${kind}.${name} result`;\n\t\t\t} else if (offered.kind === \"state\" && wanted.kind === \"state\") {\n\t\t\t\tif (!fits(offered.schema, wanted.schema)) return `${kind}.${name} state`;\n\t\t\t} else if (offered.kind === \"opaque\" && wanted.kind === \"opaque\" && offered.id !== wanted.id) {\n\t\t\t\treturn `${kind}.${name} opaque ${offered.id} != ${wanted.id}`;\n\t\t\t}\n\t\t}\n\t}\n\treturn undefined;\n}\n\nconst samePlacement = (a: Description, b: Description): boolean =>\n\tcanonicalJson(a.host ?? null) === canonicalJson(b.host ?? null);\nconst placementOf = (description: Description): string =>\n\tdescription.host === undefined ? \"(local)\" : placementText(description.host);\n\n/** Maps the provider's current implementation to the view a consumer of an older contract version expects. */\nexport type Adapter = (current: Record<string, unknown>) => Record<string, unknown>;\nexport type Accepts = Readonly<Record<number, Adapter>>;\n\n/** How a consumer token binds to a provider: directly or through an `accepts` adapter. Throws contract_mismatch. */\nexport function bind(provider: AnyContract, accepts: Accepts | undefined, consumer: AnyContract): Adapter | undefined {\n\tif (provider.fingerprint === consumer.fingerprint) return undefined;\n\t// A moved type is another type for its consumers: no adapter reaches across hosts.\n\tif (!samePlacement(provider.description, consumer.description)) {\n\t\tthrow new ChordError(\n\t\t\t\"contract_mismatch\",\n\t\t\t`${provider.name} lives on ${placementOf(provider.description)}, the consumer expects ${placementOf(consumer.description)}`,\n\t\t);\n\t}\n\tif (provider.version === consumer.version) {\n\t\tconst reason = coverage(provider.description, consumer.description);\n\t\tif (reason === undefined) return undefined;\n\t\tthrow new ChordError(\n\t\t\t\"contract_mismatch\",\n\t\t\t`${provider.name}@${provider.version} does not cover the consumer's description (${reason}); forgotten version bump?`,\n\t\t);\n\t}\n\tconst adapter = accepts?.[consumer.version];\n\tif (adapter === undefined) {\n\t\tthrow new ChordError(\n\t\t\t\"contract_mismatch\",\n\t\t\t`${provider.name}: provider version ${provider.version}, consumer version ${consumer.version}, no accepts adapter`,\n\t\t);\n\t}\n\treturn adapter;\n}\n\n// ─── Static types ────────────────────────────────────────────────────────────\n\ntype Empty = Record<never, never>;\ntype StateOf<V> = V extends { readonly state: infer S extends Readonly<Record<string, TSchema>> } ? S : Empty;\ntype StaticOf<S> = S extends TSchema ? Static<S> : never;\ntype MethodsOf<V> = V extends { readonly methods: infer M extends Readonly<Record<string, MethodSpec>> } ? M : Empty;\n\n/** What a handler returns: the result's value, or nothing for a void method. */\ntype Returned<R> = [R] extends [TSchema] ? Static<R> | Promise<Static<R>> : void | Promise<void>;\n/** What a call resolves to. */\ntype Resolved<R> = [R] extends [TSchema] ? Static<R> : undefined;\n\n/** A method's handler; `P` is the app's principal type (`ctx.principal`). */\nexport type MethodImplementation<M, P = unknown> = M extends MethodSpec<infer A, infer R>\n\t? [A] extends [TSchema]\n\t\t? (args: Static<A>, ctx: Ctx<P>) => Returned<R>\n\t\t: (ctx: Ctx<P>) => Returned<R>\n\t: never;\nexport type Call<M> = M extends MethodSpec<infer A, infer R>\n\t? [A] extends [TSchema]\n\t\t? (args: Static<A>, ctx?: Ctx) => Promise<Resolved<R>>\n\t\t: (ctx?: Ctx) => Promise<Resolved<R>>\n\t: never;\n\n/** Whether `contract`'s method `name` takes no arguments (it is called as `ref.name(ctx)`). */\nexport function takesNoArgs(contract: AnyContract, name: string): boolean {\n\tfor (const members of Object.values(contract.description.variants)) {\n\t\tconst member = members[name];\n\t\tif (member?.kind === \"method\") return member.args === undefined;\n\t}\n\treturn false;\n}\n\ntype VariantImplementation<K, V, P> = { readonly variant: K } & {\n\treadonly [S in keyof StateOf<V>]: StateSource<StaticOf<StateOf<V>[S]>>;\n} & {\n\treadonly [M in keyof MethodsOf<V>]: MethodImplementation<MethodsOf<V>[M], P>;\n};\n/**\n * A reference in one variant: its state members are plain readables (a reference you hold has its state) and its\n * methods calls. `variant` discriminates the union `Ref` is for a multi-variant type.\n */\ntype VariantRef<C extends AnyContract, K, V> = RefBase<C> & { readonly variant: K } & {\n\treadonly [S in keyof StateOf<V>]: Readable<StaticOf<StateOf<V>[S]>>;\n} & {\n\treadonly [M in keyof MethodsOf<V>]: Call<MethodsOf<V>[M]>;\n};\n\ntype LocalImplementationMember<M, P> = M extends MethodSpec\n\t? MethodImplementation<M, P>\n\t: M extends OpaqueSpec<infer T>\n\t\t? T | Exposed<T>\n\t\t: M extends TSchema\n\t\t\t? StateSource<Static<M>>\n\t\t\t: never;\ntype LocalRefMember<M> = M extends MethodSpec\n\t? Call<M>\n\t: M extends OpaqueSpec<infer T>\n\t\t? T | undefined\n\t\t: M extends TSchema\n\t\t\t? Readable<Static<M>>\n\t\t\t: never;\ntype LocalMembers<D> = D extends { readonly members: infer M extends Readonly<Record<string, LocalMember>> }\n\t? M\n\t: Empty;\n\nexport type InputOf<C> = C extends { readonly def: { readonly input: infer I extends TSchema } } ? Static<I> : never;\n\n/** What a factory returns for contract C; its methods' `ctx.principal` is `P`. */\nexport type ImplementationOf<C, P = unknown> = C extends RemoteContract<infer D>\n\t? { [K in keyof D[\"variants\"]]: VariantImplementation<K, D[\"variants\"][K], P> }[keyof D[\"variants\"]]\n\t: C extends LocalContract<infer D>\n\t\t? { readonly [K in keyof LocalMembers<D>]: LocalImplementationMember<LocalMembers<D>[K], P> } & Record<\n\t\t\t\tstring,\n\t\t\t\tunknown\n\t\t\t>\n\t\t: never;\n\n/**\n * What `get` returns for contract C. A remote type's reference is a union discriminated by `variant`: another variant's\n * members are reachable only after narrowing (`if (ref.variant === \"editor\") ref.add(…)`). A local type's reference has\n * its members.\n */\nexport type Ref<C extends AnyContract = AnyContract> = C extends RemoteContract<infer D>\n\t? { [K in keyof D[\"variants\"]]: VariantRef<C, K, D[\"variants\"][K]> }[keyof D[\"variants\"]]\n\t: C extends LocalContract<infer D>\n\t\t? RefBase<C> & { readonly [K in keyof LocalMembers<D>]: LocalRefMember<LocalMembers<D>[K]> }\n\t\t: never;\n"]}