@volter/world-core 2.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 (180) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +29 -0
  3. package/app-route.cjs +154 -0
  4. package/app-route.d.cts +7 -0
  5. package/attach.cjs +80 -0
  6. package/dist/app-route.cjs +154 -0
  7. package/dist/app-route.d.cts +7 -0
  8. package/dist/attach.cjs +80 -0
  9. package/dist/generated/pack-facts.json +4306 -0
  10. package/dist/inject.cjs +1097 -0
  11. package/dist/network-policy.cjs +92 -0
  12. package/dist/network-policy.d.cts +10 -0
  13. package/dist/src/actions.d.ts +276 -0
  14. package/dist/src/actions.js +436 -0
  15. package/dist/src/ancestry.d.ts +22 -0
  16. package/dist/src/ancestry.js +238 -0
  17. package/dist/src/args.d.ts +3 -0
  18. package/dist/src/args.js +12 -0
  19. package/dist/src/blob-store.d.ts +55 -0
  20. package/dist/src/blob-store.js +186 -0
  21. package/dist/src/brand-tokens.d.ts +2 -0
  22. package/dist/src/brand-tokens.js +17 -0
  23. package/dist/src/changeset.d.ts +431 -0
  24. package/dist/src/changeset.js +0 -0
  25. package/dist/src/client-bundle.d.ts +1 -0
  26. package/dist/src/client-bundle.js +28 -0
  27. package/dist/src/credential.d.ts +38 -0
  28. package/dist/src/credential.js +114 -0
  29. package/dist/src/derived-core.d.ts +452 -0
  30. package/dist/src/derived-core.js +782 -0
  31. package/dist/src/derived.d.ts +84 -0
  32. package/dist/src/derived.js +122 -0
  33. package/dist/src/emit.d.ts +106 -0
  34. package/dist/src/emit.js +157 -0
  35. package/dist/src/executor.d.ts +120 -0
  36. package/dist/src/executor.js +387 -0
  37. package/dist/src/file-response.d.ts +3 -0
  38. package/dist/src/file-response.js +22 -0
  39. package/dist/src/fork.d.ts +26 -0
  40. package/dist/src/fork.js +68 -0
  41. package/dist/src/git/history.d.ts +36 -0
  42. package/dist/src/git/history.js +298 -0
  43. package/dist/src/git/index.d.ts +6 -0
  44. package/dist/src/git/index.js +6 -0
  45. package/dist/src/git/inflate.d.ts +11 -0
  46. package/dist/src/git/inflate.js +194 -0
  47. package/dist/src/git/objects.d.ts +64 -0
  48. package/dist/src/git/objects.js +161 -0
  49. package/dist/src/git/pack.d.ts +14 -0
  50. package/dist/src/git/pack.js +199 -0
  51. package/dist/src/git/refs.d.ts +19 -0
  52. package/dist/src/git/refs.js +35 -0
  53. package/dist/src/git/smart-http.d.ts +45 -0
  54. package/dist/src/git/smart-http.js +223 -0
  55. package/dist/src/hash.d.ts +38 -0
  56. package/dist/src/hash.js +48 -0
  57. package/dist/src/head.d.ts +140 -0
  58. package/dist/src/head.js +313 -0
  59. package/dist/src/history.d.ts +76 -0
  60. package/dist/src/history.js +322 -0
  61. package/dist/src/index.d.ts +73 -0
  62. package/dist/src/index.js +98 -0
  63. package/dist/src/lifecycle.d.ts +1 -0
  64. package/dist/src/lifecycle.js +8 -0
  65. package/dist/src/log.d.ts +254 -0
  66. package/dist/src/log.js +801 -0
  67. package/dist/src/mirror-shell.d.ts +2 -0
  68. package/dist/src/mirror-shell.js +13 -0
  69. package/dist/src/observe.d.ts +49 -0
  70. package/dist/src/observe.js +148 -0
  71. package/dist/src/pack-assets.d.ts +30 -0
  72. package/dist/src/pack-assets.js +88 -0
  73. package/dist/src/packRegistry.d.ts +374 -0
  74. package/dist/src/packRegistry.js +142 -0
  75. package/dist/src/placeholder-remote.d.ts +22 -0
  76. package/dist/src/placeholder-remote.js +86 -0
  77. package/dist/src/proxy.d.ts +25 -0
  78. package/dist/src/proxy.js +155 -0
  79. package/dist/src/rateBudget.d.ts +367 -0
  80. package/dist/src/rateBudget.js +925 -0
  81. package/dist/src/references.d.ts +18 -0
  82. package/dist/src/references.js +27 -0
  83. package/dist/src/remote-execute.d.ts +22 -0
  84. package/dist/src/remote-execute.js +1 -0
  85. package/dist/src/resource-blob.d.ts +10 -0
  86. package/dist/src/resource-blob.js +56 -0
  87. package/dist/src/scenario.d.ts +197 -0
  88. package/dist/src/scenario.js +425 -0
  89. package/dist/src/schemas.d.ts +78 -0
  90. package/dist/src/schemas.js +50 -0
  91. package/dist/src/serve-http.d.ts +48 -0
  92. package/dist/src/serve-http.js +340 -0
  93. package/dist/src/serve.d.ts +147 -0
  94. package/dist/src/serve.js +507 -0
  95. package/dist/src/shared-blob-index.d.ts +4 -0
  96. package/dist/src/shared-blob-index.js +126 -0
  97. package/dist/src/state-system.d.ts +70 -0
  98. package/dist/src/state-system.js +90 -0
  99. package/dist/src/storage.d.ts +101 -0
  100. package/dist/src/storage.js +337 -0
  101. package/dist/src/twin-fetch.d.ts +64 -0
  102. package/dist/src/twin-fetch.js +91 -0
  103. package/dist/src/types.d.ts +40 -0
  104. package/dist/src/types.js +1 -0
  105. package/dist/src/v1-removed.d.ts +159 -0
  106. package/dist/src/v1-removed.js +124 -0
  107. package/dist/src/volter-home.d.ts +5 -0
  108. package/dist/src/volter-home.js +10 -0
  109. package/dist/src/world-clock.d.ts +4 -0
  110. package/dist/src/world-clock.js +32 -0
  111. package/dist/src/world-env.d.ts +3 -0
  112. package/dist/src/world-env.js +22 -0
  113. package/dist/src/world-store-sql.d.ts +27 -0
  114. package/dist/src/world-store-sql.js +86 -0
  115. package/dist/src/world-store.d.ts +168 -0
  116. package/dist/src/world-store.js +475 -0
  117. package/dist/src/worldConfig.d.ts +9 -0
  118. package/dist/src/worldConfig.js +17 -0
  119. package/dist/stream-bridge.cjs +80 -0
  120. package/dist/vendor-hosts.cjs +200 -0
  121. package/generated/pack-facts.json +4306 -0
  122. package/inject.cjs +1097 -0
  123. package/network-policy.cjs +92 -0
  124. package/network-policy.d.cts +10 -0
  125. package/package.json +103 -0
  126. package/src/actions.ts +564 -0
  127. package/src/ancestry.ts +213 -0
  128. package/src/args.ts +14 -0
  129. package/src/blob-store.ts +185 -0
  130. package/src/brand-tokens.ts +17 -0
  131. package/src/changeset.ts +1032 -0
  132. package/src/client-bundle.ts +29 -0
  133. package/src/credential.ts +140 -0
  134. package/src/derived-core.ts +1004 -0
  135. package/src/derived.ts +176 -0
  136. package/src/emit.ts +242 -0
  137. package/src/executor.ts +431 -0
  138. package/src/file-response.ts +22 -0
  139. package/src/fork.ts +89 -0
  140. package/src/git/history.ts +177 -0
  141. package/src/git/index.ts +6 -0
  142. package/src/git/inflate.ts +125 -0
  143. package/src/git/objects.ts +110 -0
  144. package/src/git/pack.ts +105 -0
  145. package/src/git/refs.ts +25 -0
  146. package/src/git/smart-http.ts +149 -0
  147. package/src/hash.ts +66 -0
  148. package/src/head.ts +318 -0
  149. package/src/history.ts +246 -0
  150. package/src/index.ts +323 -0
  151. package/src/lifecycle.ts +8 -0
  152. package/src/log.ts +793 -0
  153. package/src/mirror-shell.ts +15 -0
  154. package/src/observe.ts +130 -0
  155. package/src/pack-assets.ts +81 -0
  156. package/src/packRegistry.ts +408 -0
  157. package/src/placeholder-remote.ts +81 -0
  158. package/src/proxy.ts +183 -0
  159. package/src/rateBudget.ts +1115 -0
  160. package/src/references.ts +46 -0
  161. package/src/remote-execute.ts +26 -0
  162. package/src/resource-blob.ts +57 -0
  163. package/src/scenario.ts +479 -0
  164. package/src/schemas.ts +56 -0
  165. package/src/serve-http.ts +299 -0
  166. package/src/serve.ts +618 -0
  167. package/src/shared-blob-index.ts +108 -0
  168. package/src/state-system.ts +115 -0
  169. package/src/storage.ts +407 -0
  170. package/src/twin-fetch.ts +147 -0
  171. package/src/types.ts +50 -0
  172. package/src/v1-removed.ts +172 -0
  173. package/src/volter-home.ts +11 -0
  174. package/src/world-clock.ts +33 -0
  175. package/src/world-env.ts +18 -0
  176. package/src/world-store-sql.ts +118 -0
  177. package/src/world-store.ts +572 -0
  178. package/src/worldConfig.ts +27 -0
  179. package/stream-bridge.cjs +80 -0
  180. package/vendor-hosts.cjs +200 -0
@@ -0,0 +1,452 @@
1
+ import { type TwinResource } from './serve.js';
2
+ import type { DerivedCall, DerivedCoreOutcome, DerivedHandler, DerivedOperation } from './derived.js';
3
+ /** How a stored field gets its value when the server assigns it. `now` is the world clock in the
4
+ * manifest's time format; `id` the subject's id; a `value` is stored as given. */
5
+ export type FieldRule = {
6
+ now: true;
7
+ } | {
8
+ id: true;
9
+ } | {
10
+ value: unknown;
11
+ } | {
12
+ template: string;
13
+ };
14
+ /** A move of one state field, as data. `operation` is the operationId that causes it (an update
15
+ * that requests `to` when absent); `from` the values it leaves; `effects` the other fields it writes;
16
+ * `refusal` what the vendor answers when `from` does not hold. */
17
+ /** Who moves a state: a caller of the API (the default), the person on a vendor's hosted page or
18
+ * another outside party (`external`), the vendor on its own (`vendor`), or time (`time`). A move
19
+ * that is not the API's never answers an API call's legality. */
20
+ export type Actor = 'api' | 'external' | 'vendor' | 'time';
21
+ export type Transition = {
22
+ operation?: string;
23
+ actor?: Actor;
24
+ from: string[] | '*';
25
+ /** the value it moves to; absent, the value stays (a guard that moves nothing) */
26
+ to?: string;
27
+ effects?: Record<string, FieldRule>;
28
+ /** placeholders `{from}`, `{to}`, `{field}`, `{id}` */
29
+ refusal?: {
30
+ status: number;
31
+ code?: string;
32
+ message: string;
33
+ };
34
+ /** a refusal of its own for a particular current value (an invoice already `paid`) */
35
+ refusals?: Record<string, {
36
+ status: number;
37
+ code?: string;
38
+ message: string;
39
+ }>;
40
+ /** where the rule comes from: a docs URL, the SDK's types, or a recording */
41
+ source: string;
42
+ };
43
+ /** A state field's machine. Values compare as strings, so a boolean field reads `'true'`/`'false'`, and
44
+ * a field that is absent reads as `initial`. `derive` names states a stored value only implies (a
45
+ * timestamp that is 0 until something happens), tried in order. `vendorInitial` is where the vendor
46
+ * starts a subject when the twin starts it elsewhere. */
47
+ export type StateField = {
48
+ initial: string | boolean;
49
+ transitions: Transition[];
50
+ derive?: Array<{
51
+ state: string;
52
+ when: {
53
+ equals?: unknown;
54
+ gt?: number;
55
+ truthy?: boolean;
56
+ absent?: boolean;
57
+ };
58
+ }>;
59
+ vendorInitial?: string;
60
+ };
61
+ /** What a move to `to` stores in the field: a boolean field's value is a boolean, and a derived field's
62
+ * value is written by the move's effects (a state name is not a timestamp), so it stores nothing itself. */
63
+ export declare function storedState(decl: StateField, to: string | undefined): unknown;
64
+ /** The state a stored value is in, by the field's machine. */
65
+ export declare function stateOf(decl: StateField, value: unknown): string;
66
+ export type ResourceDecl = {
67
+ /** the tree's subject type, when it differs from the resource name */
68
+ storedAs?: string;
69
+ idPrefix: string;
70
+ /** fields the server assigns on create */
71
+ assigned?: Record<string, FieldRule>;
72
+ state?: Record<string, StateField>;
73
+ /** state candidates the manifest rules are not state */
74
+ notState?: string[];
75
+ /** id-holding fields a caller may ask to receive embedded, and the resource each holds */
76
+ embeds?: Record<string, string>;
77
+ /** this resource's deletion answer, when it is not the manifest's (`vector_store.deleted`) */
78
+ deleted?: unknown;
79
+ /** a child addressed under its parent: the path parameter naming the parent, the stored field that
80
+ * holds it, and the parent resource, whose not-found answers a missing parent */
81
+ /** `param` is the path parameter naming the parent, or `params` several with `value` the template
82
+ * that joins them into what `field` stores (`{owner}/{repo}`). `where` finds the parent by its stored
83
+ * fields when its stored id is not what the path names (a repository stored as `repo:7` with `owner`
84
+ * and `name`, addressed as `{owner}/{repo}`): each stored field against a template over the path. */
85
+ parent?: {
86
+ param?: string;
87
+ params?: string[];
88
+ value?: string;
89
+ field: string;
90
+ resource: string;
91
+ allowDeleted?: boolean;
92
+ where?: Record<string, string>;
93
+ };
94
+ /** a number the resource counts per parent (a repository's issue numbers, a thread's messages):
95
+ * the stored field, set on create to one past the highest among its siblings */
96
+ number?: {
97
+ field: string;
98
+ };
99
+ /** how this resource renders a stored subject, when it differs from the pack's; it sees the subject's
100
+ * address, which a stored shape may not carry */
101
+ view?: (body: Record<string, unknown>, subject: {
102
+ id: string;
103
+ type: string;
104
+ }) => Record<string, unknown>;
105
+ /** an update replaces the fields it names (`replace`) or merges nested objects into them (`merge`, the default) */
106
+ update?: 'merge' | 'replace';
107
+ /** the stored subject id when it is not the path's last parameter: a template over the path
108
+ * parameters (`{vector_store_id}::{file_id}`) */
109
+ key?: string;
110
+ /** only subjects whose stored fields match are readable (a resource stored for every call but
111
+ * answered only when asked to be kept) */
112
+ readableWhen?: Record<string, unknown>;
113
+ /** this resource's not-found answer when it is not the manifest's: a message (`{id}`), or an
114
+ * error code (an RPC vendor's `channel_not_found`) */
115
+ notFound?: string | {
116
+ code: string;
117
+ message?: string;
118
+ };
119
+ /** query parameters of the list operation that filter on the same-named field */
120
+ filters?: string[];
121
+ order?: {
122
+ field: string;
123
+ direction: 'asc' | 'desc';
124
+ };
125
+ };
126
+ export type ErrorSpec = {
127
+ status: number;
128
+ message: string;
129
+ code?: string;
130
+ param?: string;
131
+ kind?: string;
132
+ };
133
+ /** A vendor screen a World serves (docs/contributing/architecture.md, "Screens"). A `flow` is a hosted
134
+ * page an application sends its user through, held to its documented round trip; a `workspace` is a
135
+ * screen people work in. `demand` says who reaches it; `controls` names what a person acts on, the
136
+ * vendor's way, each a (screen, control) cell. */
137
+ export type ScreenDecl = {
138
+ id: string;
139
+ kind: 'flow' | 'workspace';
140
+ host: string;
141
+ path: string;
142
+ demand: string;
143
+ status: 'done' | 'todo';
144
+ controls?: string[];
145
+ /** the vendor's documentation of the round trip or the screen */
146
+ source: string;
147
+ };
148
+ export type DerivedManifest = {
149
+ vendor: string;
150
+ /** the kernel service the pack writes */
151
+ service: string;
152
+ /** `json: 'always'` reads a body as JSON whatever its content type (GitHub does) */
153
+ body: {
154
+ form?: {
155
+ coerce: boolean;
156
+ };
157
+ json?: 'always';
158
+ };
159
+ /** `acceptProvided`: a create that names its own `id` keeps it (a vendor that seeds by id). The template counts
160
+ * (`{prefix}_{n}`), or is `{uuid}` for a vendor whose ids are UUIDs: the next is derived from the resource and its
161
+ * count, so a World mints the same ids every run */
162
+ ids: {
163
+ template: string;
164
+ acceptProvided?: boolean;
165
+ };
166
+ /** operations the derived core must not claim though their resource is declared: served by
167
+ * the pack's existing code, or a gap, until someone models them */
168
+ unmodeled?: string[];
169
+ /** operations that only read though nothing in the spec says so (a POST that returns data):
170
+ * a read-only twin answers them */
171
+ reads?: string[];
172
+ time: 'unix' | 'iso';
173
+ /** the vendor's error body, with `{message}`, `{code}`, `{param}`, `{kind}` placeholders; a
174
+ * placeholder with no value is left out when `errorOmitsAbsent` */
175
+ error: unknown;
176
+ errorOmitsAbsent?: boolean;
177
+ /** the `{kind}` an error takes when it names none */
178
+ defaultKind?: string;
179
+ /** what a write to a read-only twin answers */
180
+ readOnly: ErrorSpec;
181
+ /** what a body labelled JSON that does not parse answers; absent, a 400 in the vendor's error body */
182
+ malformedBody?: ErrorSpec;
183
+ /** a request header that selects the vendor's API version, and the answer to a malformed one
184
+ * (`{value}` in its message is the header's value) */
185
+ version?: {
186
+ header: string;
187
+ pattern: string;
188
+ error: ErrorSpec;
189
+ };
190
+ /** `withParam`: the error names the path parameter that held the unknown id */
191
+ notFound: {
192
+ status: number;
193
+ message: string;
194
+ code?: string;
195
+ kind?: string;
196
+ withParam?: boolean;
197
+ };
198
+ /** the list envelope (placeholders `{data}`, `{has_more}`, `{url}`, `{first_id}`, `{last_id}`),
199
+ * its page size, its cursors, and where an unknown cursor starts: the first page or past the end */
200
+ list: {
201
+ style: 'envelope';
202
+ envelope: unknown;
203
+ limit: {
204
+ param: string;
205
+ default: number;
206
+ max: number;
207
+ };
208
+ after?: string;
209
+ before?: string;
210
+ unknownCursor?: 'start' | 'end';
211
+ /** an opaque cursor over positions (`{next_cursor}` in the envelope; empty on the last page),
212
+ * in place of id cursors: `base64-offset` is base64 of `{"o":<offset>}` */
213
+ cursor?: {
214
+ param: string;
215
+ encoding: 'base64-offset';
216
+ };
217
+ /** numbered pages (1-based `page`, the size in `limit.param`), with the vendor's `Link` header
218
+ * naming the first, previous, next and last pages */
219
+ page?: {
220
+ param: string;
221
+ link: boolean;
222
+ };
223
+ /** offset paging: `param` names how many items to skip; the page sits under the operation's envelope key beside the
224
+ * envelope, whose `{total_count}` is the count before paging (Tremendous's `{ orders: [...], total_count }`) */
225
+ offset?: {
226
+ param: string;
227
+ };
228
+ /** page sizes by operationId, where a vendor's lists differ from `limit` (Tremendous: orders 10/500, invoices 10/10) */
229
+ limits?: Record<string, {
230
+ default: number;
231
+ max: number;
232
+ }>;
233
+ /** envelopes by operationId, where a vendor's lists differ from `envelope` (Tremendous gives `total_count` on orders,
234
+ * rewards and invoices, and none on campaigns, funding sources or webhooks) */
235
+ envelopes?: Record<string, unknown>;
236
+ };
237
+ /** an RPC vendor's success envelope, merged into every answer, with the resource under the
238
+ * operation's envelope key (`{ ok: true, channel: {...} }`) */
239
+ success?: Record<string, unknown>;
240
+ /** who is calling, from the request's credential (and the tree, where the vendor keeps tokens) */
241
+ identity?: (authorization: string | null, root?: string) => string;
242
+ deleted: unknown;
243
+ expandParam?: string;
244
+ /** server-sent events: `data` lines, optionally `event:` lines named by each event, and the
245
+ * sentinel a finished stream ends with */
246
+ sse?: {
247
+ named: boolean;
248
+ done?: string;
249
+ };
250
+ /** an operation whose stream is framed otherwise (named events, no sentinel) */
251
+ streamFor?: Record<string, {
252
+ named: boolean;
253
+ done?: string;
254
+ }>;
255
+ /** the vendor's idempotency header: a write repeated with the same key answers the stored
256
+ * answer; the same key with other parameters answers `conflict` */
257
+ /** `methods` defaults to POST; `onlySuccess` (replay only 2xx answers) to false; without
258
+ * `conflict`, a key replays its first answer whatever the parameters */
259
+ idempotency?: {
260
+ header: string;
261
+ storedAs: string;
262
+ conflict?: ErrorSpec;
263
+ methods?: string[];
264
+ onlySuccess?: boolean;
265
+ };
266
+ /** how the vendor reads its credential, and what it answers without one or with a key the twin
267
+ * reserves as invalid, or one of a shape the vendor never issues (`keyFormat`, a pattern every key it issues
268
+ * matches: Resend's begin `re_`); a request that presents no such header at all is a trusted in-process call */
269
+ auth?: {
270
+ header: string;
271
+ scheme: string;
272
+ missing: ErrorSpec;
273
+ invalidKeys: string[];
274
+ keyFormat?: string;
275
+ invalid: ErrorSpec;
276
+ gateWhenAbsent: boolean;
277
+ };
278
+ /** the twin door that makes the next request answer the vendor's rate-limit refusal */
279
+ /** headers every answer carries (a request id) */
280
+ answerHeaders?: Record<string, string>;
281
+ /** an origin the pack writes into URLs it mints, rewritten in every JSON answer to where this
282
+ * twin is reached for the request (twinPublicBase) */
283
+ origin?: {
284
+ placeholder: string;
285
+ };
286
+ /** while a pack moves, how its existing code renders a stored subject (named by its stored
287
+ * type), so moved and unmoved operations answer the same shape */
288
+ view?: (storedType: string, body: Record<string, unknown>) => Record<string, unknown>;
289
+ resources: Record<string, ResourceDecl>;
290
+ /** the vendor's screens this pack serves or owes (demand decides which exist) */
291
+ screens?: ScreenDecl[];
292
+ /** called after every stored write with the rendered resource, its stored type and the kernel operation name */
293
+ onWrite?: (write: {
294
+ operation: string;
295
+ storedType: string;
296
+ body: Record<string, unknown>;
297
+ root?: string;
298
+ occurredAt: string;
299
+ request: Request;
300
+ }) => Promise<void>;
301
+ };
302
+ /** A form body's bracket notation (`a[b][0][c]=v`, `expand[]=x`) as nested objects and arrays. A form carries only
303
+ * text: a field the operation's spec types as a number or a boolean (`scalars`, by bracket path, written by
304
+ * world-tooling's formScalarsOf) is read as one when its text is that literal; every other field stays the text sent
305
+ * (`metadata[order]=007`, `name=2024`). */
306
+ export declare function parseBracketForm(text: string, scalars?: Readonly<Record<string, string | undefined>>): Record<string, unknown>;
307
+ /** A request's parameters, its query's and its body's. With the manifest's `body.form.coerce`, a form's fields the
308
+ * operation's spec types as numbers or booleans are read as them (parseBracketForm); without an operation (a twin door)
309
+ * every form value is its text. */
310
+ export declare function readParams(manifest: DerivedManifest, request: Request, operation?: DerivedOperation): Promise<Record<string, unknown>>;
311
+ export declare function vendorError(manifest: DerivedManifest, e: ErrorSpec): Response;
312
+ /** A service's resources of one type, each the reader's own copy: `twinResources` filtered by type, from an index
313
+ * that follows each write rather than projecting the whole tree per call. */
314
+ export declare function resourcesOfType(service: string, type: string, root?: string): TwinResource[];
315
+ /** The vendor's view of a stored subject: its own fields, bookkeeping (`_`) left out. */
316
+ /** A stored subject as the vendor's object: its id first (the subject's, unless the pack kept an id of its own), then
317
+ * the fields the pack wrote, bookkeeping (`_`) and the kernel's updatedAt left out. */
318
+ export declare function render(r: TwinResource): Record<string, unknown>;
319
+ /** Where the core runs: the World root it reads and writes, and its clock (the World's by default;
320
+ * a caller that pins an instant passes its own). */
321
+ export type CoreScope = {
322
+ root?: string;
323
+ clock?: () => string;
324
+ };
325
+ /** What a coverage measurement sees of a pack's declared state logic: each move a request made and each refusal a
326
+ * guard gave, by the transition that decided it. Nothing is observed unless a measurement installs an observer
327
+ * (scripts/life-coverage.ts); serving never depends on it. */
328
+ export type TransitionObserver = (decl: StateField, transition: Transition, outcome: 'moved' | 'refused', from: string) => void;
329
+ export declare function observeTransitions(observer: TransitionObserver | undefined): void;
330
+ /** The transition a request asks for on one state field, or the vendor's refusal when none applies. */
331
+ /** What a declared machine says to one move: the transition that allows it, or the refusal it gives (and
332
+ * nothing when it declares neither). The derived core and `legal` ask it; so does an engine that is not
333
+ * HTTP-shaped (a line protocol's session), so one machine rules every wire. */
334
+ export declare function transitionFor(field: string, decl: StateField, operationId: string, current: unknown, requested: unknown, id?: string, actor?: Actor): {
335
+ move?: Transition;
336
+ refusal?: ErrorSpec;
337
+ };
338
+ export type CoreOutcome = {
339
+ served: Response;
340
+ } | {
341
+ unmodeled: string;
342
+ };
343
+ /** Serve one operation from the manifest, or say why the core cannot. */
344
+ export declare function serveCore(m: DerivedManifest, call: DerivedCall, scope?: CoreScope): Promise<CoreOutcome>;
345
+ /** Server-sent events in the manifest's framing. The events are known when the answer starts: the
346
+ * twin decides deterministically, so the stream carries a decided answer, never a model's. */
347
+ export declare function sse(m: DerivedManifest, events: Array<{
348
+ event?: string;
349
+ data: unknown;
350
+ }>, operationId?: string): Response;
351
+ /** What a semantics handler works with: the request's parameters, the tree through the pack's view,
352
+ * the write path (which runs the manifest's write hook), and the declared machine. A handler never
353
+ * imports the kernel; this is its whole interface. */
354
+ export type SemanticsContext = {
355
+ call: DerivedCall;
356
+ params: Record<string, unknown>;
357
+ /** the last path parameter: the subject an item operation names */
358
+ id: string | undefined;
359
+ /** the request body as the vendor reads it (an array, where the vendor takes one), and its text */
360
+ body: unknown;
361
+ text: string;
362
+ root: string | undefined;
363
+ occurredAt: string;
364
+ /** who is calling, when the manifest says how to tell */
365
+ actor: string | undefined;
366
+ now(): unknown;
367
+ get(resource: string, id: string): Record<string, unknown> | undefined;
368
+ rows(resource: string): Array<Record<string, unknown>>;
369
+ mint(resource: string): string;
370
+ write(resource: string, id: string, fields: Record<string, unknown>, operation: string): Promise<Record<string, unknown>>;
371
+ /** `write`, with what a live vendor answered when the head performed it */
372
+ writeDetailed(resource: string, id: string, fields: Record<string, unknown>, operation: string): Promise<{
373
+ body: Record<string, unknown>;
374
+ id: string;
375
+ vendorData?: unknown;
376
+ }>;
377
+ /** The id a subject has now, for an id a caller may still use from before the vendor minted its own
378
+ * (a branch naming a message by the ts it minted locally). */
379
+ resolve(resource: string, id: string): string;
380
+ /** Answer the vendor's success envelope around several fields (`{ ok: true, ts, channel, message }`). */
381
+ ok(fields: Record<string, unknown>): Response;
382
+ /** A stored row as it is kept, bookkeeping (`_`) fields and tombstones included. */
383
+ row(resource: string, id: string, opts?: {
384
+ withDeleted?: boolean;
385
+ }): Record<string, unknown> | undefined;
386
+ rowsRaw(resource: string, opts?: {
387
+ withDeleted?: boolean;
388
+ }): Array<Record<string, unknown>>;
389
+ /** Every stored subject of the pack, of every type, in the tree's order (a projection folding many types at once). */
390
+ tree(): Array<Record<string, unknown>>;
391
+ /** The writes that touched a subject, in order: its history. */
392
+ history(resource: string, id: string): Array<{
393
+ operation?: string;
394
+ fields?: Record<string, unknown>;
395
+ occurredAt?: string;
396
+ }>;
397
+ /** Write a bookkeeping subject (a `_`-prefixed type the vendor never serves), minting its id when none is given. */
398
+ record(type: string, fields: Record<string, unknown>, id?: string): Promise<string>;
399
+ /** Decide a write from the tree as it stands and make it, with nothing written between the read
400
+ * and the write (a minted number, a first poll that moves a subject). `decide` returns the write,
401
+ * or nothing to write; the answer is its `value`. */
402
+ atomically<T>(decide: (rows: (resource: string) => Array<Record<string, unknown>>) => {
403
+ value: T;
404
+ write?: {
405
+ resource: string;
406
+ id: string;
407
+ fields: Record<string, unknown>;
408
+ operation: string;
409
+ };
410
+ }): Promise<T>;
411
+ /** Answer bytes or text as they are (a file's content), with the vendor's headers. */
412
+ raw(body: BodyInit | null, init?: {
413
+ status?: number;
414
+ headers?: Record<string, string>;
415
+ }): Response;
416
+ /** Whether the machine lets `operationId` move `field` from `current` (to `to`): nothing when it
417
+ * does, the vendor's refusal when it does not. A move the machine does not declare throws. */
418
+ legal(resource: string, field: string, operationId: string, current: unknown, to?: string, id?: string, actor?: Actor): ErrorSpec | undefined;
419
+ refuse(e: ErrorSpec): Response;
420
+ notFound(resource: string, id: string, param?: string): Response;
421
+ reply(body: unknown, status?: number): Response;
422
+ /** Answer in the vendor's success envelope under this operation's key (`{ ok: true, channel }`). */
423
+ wrap(body: Record<string, unknown>, extra?: Record<string, unknown>): Response;
424
+ /** Answer as a server-sent event stream, framed as the manifest says. */
425
+ sse(events: Array<{
426
+ event?: string;
427
+ data: unknown;
428
+ }>): Response;
429
+ expand(resource: string, body: Record<string, unknown>): Record<string, unknown>;
430
+ /** This context at another moment of the World clock (ISO): a move time makes is written at the moment it fell due. */
431
+ at(when: string): Promise<SemanticsContext>;
432
+ /** The generic core's answer to this call, or undefined where the core does not serve it. */
433
+ core(): Promise<Response | undefined>;
434
+ /** A stored row's own fields, as the vendor's object carries them (an `id`, `type` or `updatedAt` of its own restored). */
435
+ own(row: Record<string, unknown>): Record<string, unknown>;
436
+ };
437
+ export type Semantics = (ctx: SemanticsContext) => Promise<Response>;
438
+ /** A pack's semantics handlers as the dispatch's handlers. */
439
+ export declare function bindSemantics(m: DerivedManifest, handlers: Record<string, Semantics>, scope?: CoreScope): Record<string, DerivedHandler>;
440
+ /** The derived core as the dispatch's core: it owns every operation on a resource the manifest declares. */
441
+ export declare function coreFor(m: DerivedManifest, scope?: CoreScope): {
442
+ owns: (o: DerivedOperation) => boolean;
443
+ serve: (call: DerivedCall) => Promise<DerivedCoreOutcome>;
444
+ };
445
+ /** Read-only refusal, API-version validation and idempotent replay, applied once around every
446
+ * operation a handler or the core serves. */
447
+ export declare function crossCutting(m: DerivedManifest, opts?: CoreScope & {
448
+ readOnly?: boolean;
449
+ }): (call: DerivedCall, next: () => Promise<Response>) => Promise<Response>;
450
+ /** A semantics context for a request no surface operation names: another wire's (GraphQL) resolvers
451
+ * get the same interface as a handler, named by the operation id the wire gives. */
452
+ export declare function semanticsContext(m: DerivedManifest, request: Request, operation: DerivedOperation, scope?: CoreScope): Promise<SemanticsContext>;