@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,254 @@
1
+ import { type HistoryLayout } from './history.js';
2
+ import type { SubjectFields } from './hash.js';
3
+ import type { WorldServiceEvent } from './types.js';
4
+ import type { TwinResource } from './serve.js';
5
+ /** The vendor's answer to one entry, on the entry itself. `landed` = on the parent, waiting;
6
+ * `deployed` = performed against the vendor; `refused` = a check said no; `failed` = the vendor
7
+ * said no; `skipped` = after a failure. */
8
+ export type Receipt = {
9
+ status: 'landed' | 'deployed' | 'refused' | 'failed' | 'skipped';
10
+ at: string;
11
+ /** the id the vendor minted, when it differs from the local one */
12
+ externalId?: string;
13
+ url?: string;
14
+ /** the check that refused, or the vendor's words */
15
+ reason?: string;
16
+ data?: Record<string, unknown>;
17
+ };
18
+ export type EntryOp = 'set' | 'revert';
19
+ /** One line of a log. `TwinAction` in actions.ts is this type by another name; every field a
20
+ * write records lives here. */
21
+ export type Entry = {
22
+ /** where the entry came from when not this branch's own write: the placeholder origin (the default data) */
23
+ provenance?: 'placeholder';
24
+ /** the observation this entry was folded in (a refresh): one id per look; no position falls inside one */
25
+ batch?: string;
26
+ id: string;
27
+ service: string;
28
+ op: EntryOp;
29
+ subject: {
30
+ type: string;
31
+ id: string;
32
+ };
33
+ occurredAt: string;
34
+ operation?: string;
35
+ actor?: {
36
+ kind: 'agent' | 'human' | 'bot' | 'system';
37
+ id?: string;
38
+ };
39
+ fields?: SubjectFields;
40
+ projection?: {
41
+ creates?: Array<{
42
+ type: string;
43
+ id: string;
44
+ fields: SubjectFields;
45
+ }>;
46
+ updates?: Array<{
47
+ type: string;
48
+ id: string;
49
+ fields: SubjectFields;
50
+ }>;
51
+ deletes?: Array<{
52
+ type: string;
53
+ id: string;
54
+ }>;
55
+ emits?: Array<{
56
+ kind: 'webhook' | 'event' | 'notification';
57
+ target: string;
58
+ payload: Record<string, unknown>;
59
+ }>;
60
+ };
61
+ revertsActionId?: string;
62
+ /** a landed copy: the local entry id this row lands (its subject may carry the vendor's id) */
63
+ landsId?: string;
64
+ /** a landed copy under the vendor's id: the local subject id it stands for */
65
+ aliasOf?: string;
66
+ receipt?: Receipt;
67
+ /** a v1 observed row kept verbatim for `listEvents`; folds nothing unless `fields` was derived */
68
+ event?: WorldServiceEvent;
69
+ [extra: string]: unknown;
70
+ };
71
+ /** A BRANCH IS A POINTER (contract "Just like Neon", 1): its parent — a world at a path, or an origin at
72
+ * a URL — and the POSITION in the parent's whole log this branch starts from. A path parent is read
73
+ * through its immutable view, never its mutable current pointer; a URL parent uses a retained
74
+ * cache view. Only rebase or acknowledged push moves the selected view and position. */
75
+ export type BranchMeta = {
76
+ parent?: {
77
+ at: string;
78
+ position: number;
79
+ view?: string;
80
+ remoteView?: string;
81
+ generation?: string;
82
+ directory?: string;
83
+ viewDirectory?: string;
84
+ };
85
+ branchedAt?: string;
86
+ origin?: import('./history.js').HistoryOrigin;
87
+ fetchedOrigin?: import('./history.js').HistoryOrigin;
88
+ previousParents?: Array<{
89
+ directory: string;
90
+ generation: string;
91
+ }>;
92
+ };
93
+ export declare const CHECKPOINT_EVERY = 100;
94
+ export declare const DELTA_SUFFIX = ".delta";
95
+ export declare function parentLogPath(service: string, root?: string): string;
96
+ export declare function branchLogPath(service: string, root?: string): string;
97
+ export declare function branchMetaPath(service: string, root?: string): string;
98
+ /** The fetched cache of a URL parent's whole log — what `fetch` extends and a read folds up to the position. */
99
+ export declare function originLogPath(service: string, root?: string): string;
100
+ /** A parent is at a URL when it is not a path on this machine. */
101
+ export declare function isUrlParent(at: string): boolean;
102
+ export declare function checkpointPath(service: string, root?: string): string;
103
+ export declare function readBranchMeta(service: string, root?: string): BranchMeta | null;
104
+ export declare function writeBranchMeta(service: string, meta: BranchMeta, root?: string): void;
105
+ /** A v1 observed row as an entry: a delta event folds its `changed.*.after`; anything else folds
106
+ * nothing and rides along for `listEvents`. An entry row is itself. */
107
+ export declare function toEntry(row: Record<string, unknown>): Entry;
108
+ /** An entry as a v1 observed row: its own row when it came from one, else a delta event. */
109
+ export declare function toEvent(entry: Entry): WorldServiceEvent;
110
+ /** This root's own branch-log rows. */
111
+ export declare function branchEntries(service: string, root?: string): Entry[];
112
+ /** The parent as this branch sees it: the base world's view at the branch position (its parent
113
+ * log to `parentCount`, its branch log to `branchCount`), then everything this root's own parent
114
+ * log holds (fetched, refreshed or landed since). An unbranched root is just its own parent log. */
115
+ export declare function parentEntries(service: string, root?: string, seen?: Set<string>): Entry[];
116
+ /** The fetched cache of a URL parent's whole log (every entry fetched so far, past the position too). */
117
+ export declare function originEntries(service: string, root?: string): Entry[];
118
+ /** Extend the cache with one of the parent's entries; deduplicated by id. */
119
+ export declare function appendOriginEntry(entry: Entry, root?: string): {
120
+ appended: boolean;
121
+ };
122
+ /** Where the parent stands now: the length of its whole log (live at a path, the cache for a URL). */
123
+ export declare function parentPosition(service: string, root?: string): number | null;
124
+ /** Ids the parent holds, including the local ids its landed copies stand for. */
125
+ export declare function landedIds(parent: Entry[]): Set<string>;
126
+ /** The vendor-minted id per local subject: every landed copy that carries `aliasOf`. A local id the
127
+ * vendor itself holds names the vendor's subject, never the alias: a World that minted a local id
128
+ * before it had observed the vendor's own subject under that id (its tree was behind) must not fold
129
+ * the vendor's subject onto the landed one, nor send a caller who addresses the vendor's id there. */
130
+ export declare function aliasesFrom(parent: Entry[]): Map<string, string>;
131
+ type Subject = {
132
+ type: string;
133
+ id: string;
134
+ updatedAt: string;
135
+ fields: SubjectFields;
136
+ };
137
+ export type Tree = Map<string, Subject>;
138
+ /** Fold entries onto a tree, in order: `set` overlays its fields and applies its projection; a
139
+ * reverted entry folds nothing; a `confirm` row (v1) folds nothing. `skip` names entries the
140
+ * parent already holds. */
141
+ export declare function foldEntries(tree: Tree, entries: Entry[], skip?: Set<string>): void;
142
+ /** Fold aliases: whatever still sits under a local id (a later local update against the id the
143
+ * caller holds) folds onto the vendor's row. */
144
+ export declare function foldAliases(tree: Tree, aliases: Map<string, string>, service?: string, only?: Set<string>): void;
145
+ export declare function treeResources(tree: Tree): TwinResource[];
146
+ /** A copy of a resource a reader may change: its fields, and the vendor's own id/type/updatedAt it keeps beside them. */
147
+ export declare function copyResource(r: TwinResource): TwinResource;
148
+ /** A resource's own fields, the vendor's way: the subject's address stripped, its own `id`/`type`/`updatedAt` restored when it had them. */
149
+ export declare function ownFields(r: TwinResource): Record<string, unknown>;
150
+ export declare function dropCheckpoint(service: string, root?: string): void;
151
+ /** Preserve each ancestor's observed-then-local overlay, including landed IDs and aliases. */
152
+ export declare function foldHistory(entries: Entry[], layout: HistoryLayout, service?: string): Tree;
153
+ export declare function readTree(service: string, root?: string, opts?: {
154
+ until?: string;
155
+ at?: number;
156
+ view?: string;
157
+ }): TwinResource[];
158
+ /** The upstream view for observation diffing, without this root's local overlay. Inherited
159
+ * history keeps its own layout: an ancestor's local writes are part of our pinned base. */
160
+ export declare function readParentTreeMap(service: string, root?: string): Tree;
161
+ /** What a service's PARENT side at `root` is folded from (its parent log, branch.json and inherited history), as one
162
+ * string: while it stands, its aliases and landed ids are the same, whatever the branch's own log does. */
163
+ export declare function parentStamp(service: string, root?: string): string;
164
+ /** What a service's tree (and every subject's history) at `root` is folded from, as one string: while it
165
+ * stands, nothing was written. A pack that projects the tree into its own state memoizes on it. */
166
+ export declare function treeStamp(service: string, root?: string): string;
167
+ export declare function readTreeMap(service: string, root?: string, opts?: {
168
+ until?: string;
169
+ at?: number;
170
+ view?: string;
171
+ }): Tree;
172
+ /** What changed in a service's tree since `since` (a `treeStamp` an earlier read was made at): the subjects
173
+ * written since, as resources; the keys (`type:id`) of those no longer in the tree; and, of the changed, the keys
174
+ * now at the tree's end in the order they stand there (new to the tree, or deleted and made again), which a
175
+ * projection kept in the tree's order moves to its end in that order, updating the rest where they stand.
176
+ * `undefined` when this process cannot say (no memo, the parent moved, a revert, or `since` older than the memo
177
+ * remembers): the caller refolds. `stamp` is the state the answer brings the caller to. */
178
+ export declare function treeChangesSince(service: string, root: string | undefined, since: string): {
179
+ stamp: string;
180
+ changed: TwinResource[];
181
+ removed: string[];
182
+ appended: string[];
183
+ } | undefined;
184
+ export declare function cutCheckpoint(service: string, root?: string): void;
185
+ /** The branch's entries the parent does not hold: `set` rows, not reverted, not landed. */
186
+ export declare function unpushedEntries(service: string, root?: string): Entry[];
187
+ /** The position a branch is cut at: how far the parent view and the branch log reach right now. */
188
+ /** THE POSITION (contract "Just like Neon", 2): where this twin's whole log stands — one number, the
189
+ * count of entries, parent view then branch. Durable cuts pair it with an immutable view ID. */
190
+ export declare function position(service: string, root?: string): number;
191
+ /** The position of a twin's log at an instant: the entries that had occurred by then. */
192
+ export declare function positionAt(service: string, instant: string, root?: string, view?: string): number;
193
+ /** The batch a position would split, if any: `position` entries taken, and the next entry belongs to the
194
+ * same observation as the last one taken. Answers the boundaries a caller may use instead. */
195
+ export declare function splitsBatch(service: string, position: number, root?: string): {
196
+ batch: string;
197
+ from: number;
198
+ to: number;
199
+ } | null;
200
+ /** Refuse a position inside an observation, naming the boundaries. */
201
+ export declare function assertBatchBoundary(service: string, position: number, root?: string): void;
202
+ /** A landed copy of `entry` for the parent log: the receipt on it, the vendor's id as its subject
203
+ * when one was minted. Deterministic id, so landing twice is the same row. */
204
+ export declare function landedCopy(entry: Entry, receipt: Receipt, opts?: {
205
+ vendorSubjectId?: string;
206
+ fields?: SubjectFields;
207
+ subject?: {
208
+ type: string;
209
+ id: string;
210
+ };
211
+ }): Entry;
212
+ export declare function appendParentEntry(entry: Entry, root?: string): {
213
+ appended: boolean;
214
+ };
215
+ /** The whole log of a twin as a served world hands it out: the parent view, then the branch's own
216
+ * entries, one sequence with a position. A clone's parent is exactly this. */
217
+ export declare function wholeLog(service: string, root?: string): Entry[];
218
+ /**
219
+ * REBASE a branch onto its base's current position (contract: "rebase replays the branch's
220
+ * entries over a newer base, conflicts per subject and field"). A branch is a pointer, so the
221
+ * base moving is invisible until this: the pointer advances to the base's present position, the
222
+ * branch's own entries stay in place and now fold over the moved base, and every entry whose
223
+ * preconditions no longer hold against the new parent tree is named as a conflict — data on the
224
+ * result, never a stop. An unbranched world (no pointer) has nothing to rebase.
225
+ */
226
+ export declare function rebaseBranch(service: string, root?: string, opts?: {
227
+ origin?: boolean;
228
+ }): {
229
+ moved: boolean;
230
+ from: number;
231
+ to: number;
232
+ conflicts: Array<{
233
+ entryId: string;
234
+ subject: {
235
+ type: string;
236
+ id: string;
237
+ };
238
+ field: string;
239
+ op: string;
240
+ expected?: unknown;
241
+ actual?: unknown;
242
+ }>;
243
+ };
244
+ /**
245
+ * HISTORY through the kernel: every entry that touched a subject (or every subject of a type), parent
246
+ * log then branch log, in order, with reverted entries dropped and landed copies shown once. A pack
247
+ * that serves a changelog (Jira's), or must never reuse an id it once minted, reads this — never a
248
+ * log file. Each entry's `fields` is what it set; the fold is the reader's.
249
+ */
250
+ export declare function subjectHistory(service: string, subject: {
251
+ type: string;
252
+ id?: string;
253
+ }, root?: string): Entry[];
254
+ export {};