@kitionstage/sdk 0.0.0-stage → 0.5.2-stage.1

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 (258) hide show
  1. package/README.md +69 -2
  2. package/dist/LICENSE +177 -0
  3. package/dist/THIRD_PARTY_NOTICES +28 -0
  4. package/dist/lib/assets/kitEngine.worker-9haDiVHZ.js +13220 -0
  5. package/dist/lib/chunks/batch-BWpAyHvP.js +789 -0
  6. package/dist/lib/chunks/canonical-BIWfVCL-.js +87 -0
  7. package/dist/lib/chunks/envelope-D6MGY-ZN.js +61 -0
  8. package/dist/lib/chunks/replica-D8w3I4sn.js +2472 -0
  9. package/dist/lib/chunks/runtime-BVJHE1Pg.js +997 -0
  10. package/dist/lib/chunks/session-BqXC9a1-.js +281 -0
  11. package/dist/lib/chunks/toolIds-BCeSGHpV.js +821 -0
  12. package/dist/lib/chunks/workspaceTree-Destqupf.js +23 -0
  13. package/dist/lib/convergence/index.js +1035 -0
  14. package/dist/lib/convergence/node.js +8 -0
  15. package/dist/lib/embed-server/callbacks.js +37 -0
  16. package/dist/lib/embed-server/cli.js +19 -0
  17. package/dist/lib/embed-server/index.js +272 -0
  18. package/dist/lib/extensions/index.js +439 -0
  19. package/dist/lib/extensions/panel.html +208 -0
  20. package/dist/lib/extensions/runtime.js +198 -0
  21. package/dist/lib/extensions/sandbox.html +35 -0
  22. package/dist/lib/kdm/index.js +437 -0
  23. package/dist/lib/kit-dev-host/checkUiIds.mjs +44 -0
  24. package/dist/lib/kit-dev-host/index.js +308 -0
  25. package/dist/lib/kit-dev-host/lineRow.mjs +47 -0
  26. package/dist/lib/kit-dev-host/modeSmoke.mjs +178 -0
  27. package/dist/lib/kit-editor/index.js +6489 -0
  28. package/dist/lib/kit-editor/styles.css +807 -0
  29. package/dist/lib/kit-editor/workspaceTree.js +1 -0
  30. package/dist/lib/kit-engine/index.js +7 -0
  31. package/dist/lib/kit-host/index.js +530 -0
  32. package/dist/lib/kit-ui-protocol/index.js +336 -0
  33. package/dist/lib/node-only/embed-server-callbacks.js +2 -0
  34. package/dist/lib/node-only/embed-server.js +2 -0
  35. package/dist/lib/sync/index.js +1008 -0
  36. package/dist/lib/sync/openToken.js +201 -0
  37. package/dist/lib/sync/replicaVersions.js +51 -0
  38. package/dist/standalone/chunks/batch-CAGYk6m4.js +789 -0
  39. package/dist/standalone/chunks/client-B9xkOcvf.js +772 -0
  40. package/dist/standalone/chunks/collab-B5TbpTyO.js +1022 -0
  41. package/dist/standalone/chunks/comment-Ds9t8xSE.js +94 -0
  42. package/dist/standalone/chunks/comments-uVDS8Wxp.js +41 -0
  43. package/dist/standalone/chunks/document-CuIGSDsY.js +324 -0
  44. package/dist/standalone/chunks/envelope-GX4Cynkx.js +7612 -0
  45. package/dist/standalone/chunks/index-BEgEEnhU.js +287 -0
  46. package/dist/standalone/chunks/index-Blc_B6iX.js +1967 -0
  47. package/dist/standalone/chunks/kits-Cp51mDlw.js +9 -0
  48. package/dist/standalone/chunks/replica-Di2iCPiD.js +3281 -0
  49. package/dist/standalone/chunks/replicaVersions-C3rJxnk9.js +50 -0
  50. package/dist/standalone/chunks/touched-T9jKJjxn.js +78 -0
  51. package/dist/standalone/index.js +12 -0
  52. package/dist/standalone/script/index.js +339 -0
  53. package/dist/standalone/script/kits/board.js +5 -0
  54. package/dist/standalone/script/kits/cad.js +5 -0
  55. package/dist/standalone/script/kits/design.js +5 -0
  56. package/dist/standalone/script/kits/doc.js +5 -0
  57. package/dist/standalone/script/kits/film.js +5 -0
  58. package/dist/standalone/script/kits/html.js +5 -0
  59. package/dist/standalone/script/kits/index.js +38 -0
  60. package/dist/standalone/script/kits/layout.js +5 -0
  61. package/dist/standalone/script/kits/motion.js +5 -0
  62. package/dist/standalone/script/kits/note.js +5 -0
  63. package/dist/standalone/script/kits/pdf.js +5 -0
  64. package/dist/standalone/script/kits/photo.js +5 -0
  65. package/dist/standalone/script/kits/scene.js +5 -0
  66. package/dist/standalone/script/kits/sheet.js +5 -0
  67. package/dist/standalone/script/kits/slide.js +5 -0
  68. package/dist/standalone/script/kits/table.js +5 -0
  69. package/dist/standalone/script/kits/vector.js +5 -0
  70. package/dist/standalone/script/node.js +401 -0
  71. package/dist/standalone/script/proxy.js +254 -0
  72. package/dist/types/convergence/src/adapter.d.ts +131 -0
  73. package/dist/types/convergence/src/engine.d.ts +66 -0
  74. package/dist/types/convergence/src/index.d.ts +21 -0
  75. package/dist/types/convergence/src/net.d.ts +52 -0
  76. package/dist/types/convergence/src/node.d.ts +6 -0
  77. package/dist/types/convergence/src/report.d.ts +56 -0
  78. package/dist/types/convergence/src/rng.d.ts +12 -0
  79. package/dist/types/convergence/src/scenarios.d.ts +15 -0
  80. package/dist/types/convergence/src/state.d.ts +67 -0
  81. package/dist/types/embed/src/agent.d.ts +88 -0
  82. package/dist/types/embed/src/blobs.d.ts +2 -0
  83. package/dist/types/embed/src/collab.d.ts +250 -0
  84. package/dist/types/embed/src/comments.d.ts +30 -0
  85. package/dist/types/embed/src/errors.d.ts +24 -0
  86. package/dist/types/embed/src/handlers.d.ts +92 -0
  87. package/dist/types/embed/src/index.d.ts +20 -0
  88. package/dist/types/embed/src/mount.d.ts +39 -0
  89. package/dist/types/embed/src/replicaStore.d.ts +3 -0
  90. package/dist/types/embed/src/rooms.d.ts +40 -0
  91. package/dist/types/embed/src/schemas.d.ts +7 -0
  92. package/dist/types/embed/src/syncClients.d.ts +28 -0
  93. package/dist/types/embed/src/theme.d.ts +7 -0
  94. package/dist/types/embed/src/types.d.ts +596 -0
  95. package/dist/types/embed/src/ui.d.ts +33 -0
  96. package/dist/types/embed/src/version.d.ts +2 -0
  97. package/dist/types/embed-server/src/callbacks.d.ts +30 -0
  98. package/dist/types/embed-server/src/cli.d.ts +1 -0
  99. package/dist/types/embed-server/src/index.d.ts +19 -0
  100. package/dist/types/embed-server/src/page.d.ts +15 -0
  101. package/dist/types/embed-server/src/server.d.ts +39 -0
  102. package/dist/types/embed-server/src/session.d.ts +22 -0
  103. package/dist/types/extensions/src/gate.d.ts +17 -0
  104. package/dist/types/extensions/src/generated/runtime.d.ts +8 -0
  105. package/dist/types/extensions/src/host.d.ts +135 -0
  106. package/dist/types/extensions/src/index.d.ts +13 -0
  107. package/dist/types/extensions/src/manifest.d.ts +82 -0
  108. package/dist/types/extensions/src/protocol.d.ts +159 -0
  109. package/dist/types/extensions/src/rpc.d.ts +52 -0
  110. package/dist/types/extensions/src/runtime/document.d.ts +40 -0
  111. package/dist/types/extensions/src/runtime/index.d.ts +10 -0
  112. package/dist/types/extensions/src/runtime/panel.d.ts +19 -0
  113. package/dist/types/extensions/src/runtime/runtime.d.ts +54 -0
  114. package/dist/types/extensions/src/runtime/worker.d.ts +1 -0
  115. package/dist/types/extensions/src/sandbox.d.ts +41 -0
  116. package/dist/types/kdm/src/args.d.ts +12 -0
  117. package/dist/types/kdm/src/batch.d.ts +118 -0
  118. package/dist/types/kdm/src/canonical.d.ts +25 -0
  119. package/dist/types/kdm/src/comment.d.ts +114 -0
  120. package/dist/types/kdm/src/diff.d.ts +125 -0
  121. package/dist/types/kdm/src/envelope.d.ts +27 -0
  122. package/dist/types/kdm/src/errors.d.ts +28 -0
  123. package/dist/types/kdm/src/footprint.d.ts +21 -0
  124. package/dist/types/kdm/src/ids.d.ts +57 -0
  125. package/dist/types/kdm/src/index.d.ts +18 -0
  126. package/dist/types/kdm/src/marks.d.ts +32 -0
  127. package/dist/types/kdm/src/op.d.ts +124 -0
  128. package/dist/types/kdm/src/origin.d.ts +41 -0
  129. package/dist/types/kdm/src/overlay.d.ts +92 -0
  130. package/dist/types/kdm/src/projection.d.ts +29 -0
  131. package/dist/types/kdm/src/read.d.ts +90 -0
  132. package/dist/types/kdm/src/replica.d.ts +403 -0
  133. package/dist/types/kdm/src/schema.d.ts +185 -0
  134. package/dist/types/kdm/src/testing.d.ts +28 -0
  135. package/dist/types/kdm/src/toolIds.d.ts +61 -0
  136. package/dist/types/kdm/src/touched.d.ts +24 -0
  137. package/dist/types/kdm/src/tx.d.ts +215 -0
  138. package/dist/types/kdm/src/value.d.ts +23 -0
  139. package/dist/types/kit-dev-host/src/checkNoPaths.d.ts +19 -0
  140. package/dist/types/kit-dev-host/src/checkUiIds.d.mts +2 -0
  141. package/dist/types/kit-dev-host/src/index.d.ts +179 -0
  142. package/dist/types/kit-dev-host/src/lineRow.d.mts +14 -0
  143. package/dist/types/kit-dev-host/src/memoryFiles.d.ts +15 -0
  144. package/dist/types/kit-dev-host/src/modeSmoke.d.mts +8 -0
  145. package/dist/types/kit-editor/src/CommandDialog.d.ts +22 -0
  146. package/dist/types/kit-editor/src/CommentsPanel.d.ts +45 -0
  147. package/dist/types/kit-editor/src/CustomizeDialog.d.ts +32 -0
  148. package/dist/types/kit-editor/src/HostButtons.d.ts +11 -0
  149. package/dist/types/kit-editor/src/RenderFailure.d.ts +7 -0
  150. package/dist/types/kit-editor/src/TextSink.d.ts +6 -0
  151. package/dist/types/kit-editor/src/brand.d.ts +2 -0
  152. package/dist/types/kit-editor/src/catalogMenus.d.ts +27 -0
  153. package/dist/types/kit-editor/src/chart.d.ts +138 -0
  154. package/dist/types/kit-editor/src/conflicts.d.ts +12 -0
  155. package/dist/types/kit-editor/src/drawing.d.ts +83 -0
  156. package/dist/types/kit-editor/src/editor.d.ts +544 -0
  157. package/dist/types/kit-editor/src/engine/KitCanvas.d.ts +70 -0
  158. package/dist/types/kit-editor/src/engine/backdrop.d.ts +32 -0
  159. package/dist/types/kit-editor/src/engine/createKitFile.d.ts +12 -0
  160. package/dist/types/kit-editor/src/engine/decorations.d.ts +14 -0
  161. package/dist/types/kit-editor/src/engine/engineOverlays.d.ts +197 -0
  162. package/dist/types/kit-editor/src/engine/engineTools.d.ts +116 -0
  163. package/dist/types/kit-editor/src/engine/kitDraft.d.ts +70 -0
  164. package/dist/types/kit-editor/src/engine/kitEngine.d.ts +390 -0
  165. package/dist/types/kit-editor/src/engine/kitEngine.worker.d.ts +30 -0
  166. package/dist/types/kit-editor/src/engine/kitHost.d.ts +41 -0
  167. package/dist/types/kit-editor/src/engine/kitModel.d.ts +32 -0
  168. package/dist/types/kit-editor/src/engine/kitModelRunner.d.ts +99 -0
  169. package/dist/types/kit-editor/src/engine/kitModule.d.ts +185 -0
  170. package/dist/types/kit-editor/src/engine/kitShortcuts.d.ts +32 -0
  171. package/dist/types/kit-editor/src/engine/kitTools.d.ts +79 -0
  172. package/dist/types/kit-editor/src/engine/lazyFonts.d.ts +34 -0
  173. package/dist/types/kit-editor/src/engine/lentFiles.d.ts +29 -0
  174. package/dist/types/kit-editor/src/engine/rasterViewport.d.ts +178 -0
  175. package/dist/types/kit-editor/src/engine/readOnly.d.ts +78 -0
  176. package/dist/types/kit-editor/src/engine/refusal.d.ts +39 -0
  177. package/dist/types/kit-editor/src/engine/replica.d.ts +23 -0
  178. package/dist/types/kit-editor/src/engine/useKitDocument.d.ts +154 -0
  179. package/dist/types/kit-editor/src/engine/workerRelay.d.ts +62 -0
  180. package/dist/types/kit-editor/src/files.d.ts +74 -0
  181. package/dist/types/kit-editor/src/frame/EditorFrame.d.ts +74 -0
  182. package/dist/types/kit-editor/src/frame/FocusBar.d.ts +10 -0
  183. package/dist/types/kit-editor/src/frame/MenuNodes.d.ts +20 -0
  184. package/dist/types/kit-editor/src/frame/MenuRibbon.d.ts +8 -0
  185. package/dist/types/kit-editor/src/frame/ModeButton.d.ts +7 -0
  186. package/dist/types/kit-editor/src/frame/menus.d.ts +64 -0
  187. package/dist/types/kit-editor/src/frame/modes.d.ts +51 -0
  188. package/dist/types/kit-editor/src/frame/useFrameLayout.d.ts +34 -0
  189. package/dist/types/kit-editor/src/host.d.ts +127 -0
  190. package/dist/types/kit-editor/src/index.d.ts +85 -0
  191. package/dist/types/kit-editor/src/ink.d.ts +26 -0
  192. package/dist/types/kit-editor/src/lease.d.ts +53 -0
  193. package/dist/types/kit-editor/src/oneInFlight.d.ts +7 -0
  194. package/dist/types/kit-editor/src/phrases.d.ts +25 -0
  195. package/dist/types/kit-editor/src/presence.d.ts +79 -0
  196. package/dist/types/kit-editor/src/strings.d.ts +6 -0
  197. package/dist/types/kit-editor/src/toolIcons.d.ts +32 -0
  198. package/dist/types/kit-editor/src/uiCatalog.d.ts +59 -0
  199. package/dist/types/kit-editor/src/uiConfig.d.ts +53 -0
  200. package/dist/types/kit-editor/src/uiContext.d.ts +65 -0
  201. package/dist/types/kit-editor/src/uiStore.d.ts +20 -0
  202. package/dist/types/kit-editor/src/useCommentAnchors.d.ts +29 -0
  203. package/dist/types/kit-editor/src/useKitSession.d.ts +115 -0
  204. package/dist/types/kit-editor/src/workspaceTree.d.ts +5 -0
  205. package/dist/types/kit-engine/src/contract.d.ts +154 -0
  206. package/dist/types/kit-engine/src/index.d.ts +2 -0
  207. package/dist/types/kit-engine/src/session.d.ts +133 -0
  208. package/dist/types/kit-host/src/files.d.ts +163 -0
  209. package/dist/types/kit-host/src/index.d.ts +315 -0
  210. package/dist/types/kit-ui-protocol/src/index.d.ts +1145 -0
  211. package/dist/types/loro-crdt.d.ts +9 -0
  212. package/dist/types/script/kits/board.d.ts +534 -0
  213. package/dist/types/script/kits/cad.d.ts +2937 -0
  214. package/dist/types/script/kits/design.d.ts +3213 -0
  215. package/dist/types/script/kits/doc.d.ts +2575 -0
  216. package/dist/types/script/kits/film.d.ts +4067 -0
  217. package/dist/types/script/kits/html.d.ts +38 -0
  218. package/dist/types/script/kits/index.d.ts +20 -0
  219. package/dist/types/script/kits/layout.d.ts +3483 -0
  220. package/dist/types/script/kits/motion.d.ts +4826 -0
  221. package/dist/types/script/kits/note.d.ts +631 -0
  222. package/dist/types/script/kits/pdf.d.ts +829 -0
  223. package/dist/types/script/kits/photo.d.ts +7574 -0
  224. package/dist/types/script/kits/scene.d.ts +2962 -0
  225. package/dist/types/script/kits/sheet.d.ts +2419 -0
  226. package/dist/types/script/kits/slide.d.ts +1894 -0
  227. package/dist/types/script/kits/table.d.ts +654 -0
  228. package/dist/types/script/kits/vector.d.ts +5167 -0
  229. package/dist/types/script/src/agentRelay.d.ts +48 -0
  230. package/dist/types/script/src/capabilities.d.ts +21 -0
  231. package/dist/types/script/src/document.d.ts +87 -0
  232. package/dist/types/script/src/drafts.d.ts +141 -0
  233. package/dist/types/script/src/exchange.d.ts +30 -0
  234. package/dist/types/script/src/headless.d.ts +190 -0
  235. package/dist/types/script/src/index.d.ts +15 -0
  236. package/dist/types/script/src/kitModel.d.ts +17 -0
  237. package/dist/types/script/src/kits.d.ts +8 -0
  238. package/dist/types/script/src/node.d.ts +42 -0
  239. package/dist/types/script/src/port.d.ts +89 -0
  240. package/dist/types/script/src/proxy.d.ts +132 -0
  241. package/dist/types/script/src/room.d.ts +162 -0
  242. package/dist/types/script/src/sources.d.ts +73 -0
  243. package/dist/types/sync/src/backoff.d.ts +9 -0
  244. package/dist/types/sync/src/blobSection.d.ts +23 -0
  245. package/dist/types/sync/src/capabilities.d.ts +20 -0
  246. package/dist/types/sync/src/client.d.ts +253 -0
  247. package/dist/types/sync/src/framing.d.ts +35 -0
  248. package/dist/types/sync/src/hash.d.ts +2 -0
  249. package/dist/types/sync/src/index.d.ts +19 -0
  250. package/dist/types/sync/src/leases.d.ts +82 -0
  251. package/dist/types/sync/src/openToken.d.ts +104 -0
  252. package/dist/types/sync/src/protocol.d.ts +484 -0
  253. package/dist/types/sync/src/relay.d.ts +52 -0
  254. package/dist/types/sync/src/replicaVersions.d.ts +17 -0
  255. package/dist/types/sync/src/saveMachine.d.ts +83 -0
  256. package/dist/types/sync/src/saveRun.d.ts +52 -0
  257. package/dist/types/sync/src/transport.d.ts +19 -0
  258. package/package.json +229 -4
@@ -0,0 +1,403 @@
1
+ import { Version } from './envelope.js';
2
+ import { type ObjectId, type TreeEntry } from './ids.js';
3
+ import { type TextRun } from './marks.js';
4
+ import { type Origin, type UndoScope } from './origin.js';
5
+ import { type Schema } from './schema.js';
6
+ import { type StateDiff } from './diff.js';
7
+ import { Tx } from './tx.js';
8
+ /** A text change as the engine reports it, in UTF-16 code units; `attributes` are the marks it sets (`null`: removed). */
9
+ export type TextDelta = {
10
+ retain: number;
11
+ attributes?: Record<string, unknown>;
12
+ } | {
13
+ insert: string;
14
+ attributes?: Record<string, unknown>;
15
+ } | {
16
+ delete: number;
17
+ };
18
+ /** One copy of one document; the TypeScript twin of the Rust `Replica`. */
19
+ export declare class Replica {
20
+ private doc;
21
+ readonly schema: Schema;
22
+ readonly actor: bigint;
23
+ private readonly docIdBytes;
24
+ private undoManagers;
25
+ private changed;
26
+ /** Set while a transaction's function runs: nothing else may change the document then. */
27
+ private busy;
28
+ /** Set between `beginUndoGroup` and `endUndoGroup`. */
29
+ private grouping;
30
+ /** The open undo group's run, which its undo steps carry (rule M12b). */
31
+ private readonly runs;
32
+ /**
33
+ * Set when a shallow replica refused an import (`newer-schema`) after the engine applied it: the
34
+ * engine cannot rebuild a shallow document at an earlier version, so the replica refuses every
35
+ * later change and export with the same error (standard 2.0 rule M16a).
36
+ */
37
+ private closedBy;
38
+ /**
39
+ * For each replica whose changes an import could not apply yet, the counter just past the last
40
+ * of them. They are applied (and no longer pending) once `version` reaches it.
41
+ */
42
+ private readonly pending;
43
+ /**
44
+ * Registers an import changed: the candidates for another replica's later write, which an undo
45
+ * or redo must keep (M12). Pruned at each undo and redo.
46
+ */
47
+ private importedRegisters;
48
+ /**
49
+ * Registers an undo or redo put back to another replica's value, with that value: still that
50
+ * replica's write for the next undo or redo, though this replica wrote it last.
51
+ */
52
+ private keptRegisters;
53
+ /**
54
+ * The value this replica last wrote to each register (`undefined`: deleted it). Another
55
+ * replica's later write of the same value is not a change an undo must keep (a script's own undo
56
+ * that puts back this replica's value, for instance).
57
+ */
58
+ private ownRegisters;
59
+ /**
60
+ * The undo scope of this replica's last write to each register (`null`: a `system` or `import`
61
+ * transaction), with the value written. An undo in one scope keeps the value another scope wrote
62
+ * later, as it keeps another replica's (M12a). Pruned at each undo and redo.
63
+ */
64
+ private localWrites;
65
+ private constructor();
66
+ /** A new, empty document. Only one replica creates a document; others `load` it. */
67
+ static create(schema: Schema, docId: string, actor: bigint): Replica;
68
+ /**
69
+ * A new document whose initial content `build` writes in the creating commit, before undo
70
+ * history starts: file imports and other bulk builds. Undo bookkeeping grows faster than
71
+ * linearly with a transaction's size, so bulk content must not go through `transact`.
72
+ * `build` is staged like a transaction; if it throws, no document is made.
73
+ */
74
+ static createWith<R>(schema: Schema, docId: string, actor: bigint, origin: Origin, build: (tx: Tx) => R): {
75
+ replica: Replica;
76
+ result: R;
77
+ };
78
+ /**
79
+ * Opens a snapshot (or a full change export) as a new writable replica of `actor`. Refuses
80
+ * (`schema`) a document of another kit or of another KDM version, and (`newer-schema`) one whose
81
+ * minimum schema version (rule M20) is newer than `schema`'s; bytes that are not a KDM snapshot
82
+ * are `encoding` errors.
83
+ *
84
+ * A snapshot holds the changes its replica applied, not those still pending on it (see
85
+ * `hasPendingChanges`): the loaded replica has none pending, and fetches those changes again
86
+ * when it syncs.
87
+ */
88
+ static load(schema: Schema, bytes: Uint8Array, actor: bigint): Replica;
89
+ /** The document's durable identity, as a lowercase hyphenated UUID. */
90
+ get docId(): string;
91
+ version(): Version;
92
+ /**
93
+ * The document's minimum schema version (rule M20): the version it was created with, or the
94
+ * largest one a transaction raised it to (`Tx.raiseSchemaVersion`). Never more than this
95
+ * replica's schema version: loads and imports refuse such documents.
96
+ */
97
+ minSchemaVersion(): number;
98
+ /**
99
+ * The newest schema version any change of this replica was written under (rule M5a: every
100
+ * commit records its author's schema version), or `null` when no change records one (they all
101
+ * predate the rule). A version above this replica's schema means someone edits the document
102
+ * with a newer kit: objects of types this schema lacks read as their `$type` only and refuse
103
+ * edits here (`unknown-type`), and a host asks the person to update the kit. A shallow replica
104
+ * (rule M16a) sees only the changes after its root.
105
+ */
106
+ authorSchemaVersion(): number | null;
107
+ /**
108
+ * Runs `f` as one transaction: one commit, one undo step, one origin. Operations are staged while
109
+ * `f` runs and applied only if it returns: if `f` throws, the document, its version, and its
110
+ * exports are unchanged and the error propagates. `f` must be synchronous.
111
+ */
112
+ transact<R>(origin: Origin, f: (tx: Tx) => R): R;
113
+ exists(id: ObjectId): boolean;
114
+ objectType(id: ObjectId): string;
115
+ get(id: ObjectId, field: string): unknown;
116
+ text(id: ObjectId, field: string): string;
117
+ /**
118
+ * A text field as runs of characters with equal marks (rule M19), in order: adjacent runs differ
119
+ * in their marks, no run is empty, and only the field's declared marks appear. A field that
120
+ * declares no marks reads as one unmarked run (none when empty). Positions are counted in UTF-16
121
+ * code units (`insert.length`).
122
+ */
123
+ textDelta(id: ObjectId, field: string): TextRun[];
124
+ /** The length of a text field in UTF-16 code units. */
125
+ textLength(id: ObjectId, field: string): number;
126
+ list(id: ObjectId, field: string): ObjectId[];
127
+ /** One key of a map field, or `null`. */
128
+ mapGet(id: ObjectId, field: string, key: string): unknown;
129
+ /**
130
+ * A map field's keys and values, sorted by key (code point order, as in the canonical state),
131
+ * each as `mapGet` reads it. Reads the whole map.
132
+ */
133
+ mapEntries(id: ObjectId, field: string): Array<[string, unknown]>;
134
+ /**
135
+ * The tree's nodes in pre-order (each parent before its children, siblings in order). A node
136
+ * that names no object is skipped with its subtree, as in `stateJson`.
137
+ */
138
+ tree(id: ObjectId, field: string): TreeEntry[];
139
+ /**
140
+ * Ids of the objects of type `ty`, sorted. One pass over the objects, so it suits large
141
+ * documents; it costs O(objects) per call.
142
+ */
143
+ objectsOfType(ty: string): ObjectId[];
144
+ /**
145
+ * The changes this replica has that a replica at `since` lacks, labelled with this document's id.
146
+ *
147
+ * With `Version.empty()` (every change) the bytes always `load` as this document. A shallow
148
+ * replica (rule M16a) has no changes before its root, so for a `since` that does not reach its
149
+ * root (the empty version above all) it answers its snapshot: its state at the root with every
150
+ * change after it, which loads as a shallow replica with the same root and imports into any
151
+ * replica that has the root, as these changes would. On a full replica, and for a `since` at or
152
+ * after the root, the bytes are the changes alone.
153
+ */
154
+ exportChanges(since?: Version): Uint8Array;
155
+ /**
156
+ * Applies changes from another replica or from storage, in any order, any number of times.
157
+ * Answers the objects whose state changed. Bytes that are not a KDM export are `encoding`
158
+ * errors; changes of another document are `wrong-document` errors and change nothing.
159
+ *
160
+ * Changes that raise the document's minimum schema version (rule M20) above this replica's
161
+ * schema are `newer-schema` errors and change nothing: the state, the version, the exports, and
162
+ * the changes still pending are as before the import. The engine cannot check changes without
163
+ * applying them, so the replica is rebuilt from its history before the import; that clears its
164
+ * undo and redo history, and `subscribeText` listeners stop receiving changes. A build that
165
+ * meets this error is too old for the document: the host stops syncing and asks for an update.
166
+ * A shallow replica cannot be rebuilt so: it keeps the changes and refuses every later change
167
+ * and export with this error, and the host reopens the document from what it stored.
168
+ *
169
+ * On a shallow replica, changes that depend on history before its root (made by a replica that
170
+ * had not seen the root yet) are `history-missing` errors and change nothing; see `rebase`.
171
+ */
172
+ importChanges(bytes: Uint8Array): Set<ObjectId>;
173
+ /**
174
+ * Whether this replica holds imported changes it could not apply yet, because they depend on
175
+ * changes it has not received. Importing changes out of order is legitimate (they are applied as
176
+ * soon as what they depend on arrives); a replica that stays in this state is missing changes,
177
+ * which a sync from `version` fetches. Pending changes are not in `version`, the state, or the
178
+ * exports.
179
+ */
180
+ hasPendingChanges(): boolean;
181
+ /** The objects changed since the last call, by local transactions, imports, undo, and redo. */
182
+ takeChanged(): Set<ObjectId>;
183
+ /** A compacted copy of the whole document, for fast loading and new replicas. */
184
+ snapshot(): Uint8Array;
185
+ /**
186
+ * A **shallow snapshot** (standard 2.0 rule M16a): the document's current state with only the
187
+ * history after `at`, for a device that holds a large document without its whole history. `load`
188
+ * opens it as a shallow replica, which edits, exports, imports, and merges like a full one;
189
+ * history before its root stays with whoever holds it (the sync server).
190
+ *
191
+ * The root is the latest version at or before `at` that every later change descends from (the
192
+ * engine moves it back past changes made concurrently with `at`, so they stay in the retained
193
+ * history); `Version.empty()` keeps the whole history. `at` must be a version this replica has
194
+ * (`invalid-value` otherwise); on a shallow replica, an `at` before its own root is its root.
195
+ */
196
+ shallowSnapshot(at: Version): Uint8Array;
197
+ /** Whether this replica holds only part of the document's history: it was loaded from a `shallowSnapshot` (or a snapshot of a shallow replica). */
198
+ isShallow(): boolean;
199
+ /**
200
+ * The version a shallow replica's retained history starts at (its root): it has every change
201
+ * after it, and none of the history it summarizes. `null` for a full replica.
202
+ */
203
+ shallowRoot(): Version | null;
204
+ /**
205
+ * Whether this replica carries the **document's whole history** (sync protocol S20): it is full,
206
+ * or it is shallow and its root is the document's birth, so no replica of the document can hold
207
+ * changes before it. A copy made by `copyAsNewDocument` is born at its root, and every replica
208
+ * loaded from it, its snapshots and its drafts keep that root; a shallow snapshot taken later
209
+ * (`shallowSnapshot` after more changes) does not.
210
+ *
211
+ * The birth is the version the copy recorded in the change that made it, read from this
212
+ * replica's state **at its root**: a change after the root, which any client may make, never
213
+ * counts, and a value written in such a change could only name a version before the root it is
214
+ * part of. A server that trusts no client decides from the bytes alone. Shallow documents that
215
+ * record no birth (copies made before it was recorded) do not carry it. As the Rust
216
+ * `Replica::carries_whole_history`.
217
+ */
218
+ carriesWholeHistory(): boolean;
219
+ /**
220
+ * `carriesWholeHistory` of the document `bytes` (a snapshot or a full export) hold, read without
221
+ * a schema, as a sync server reads a room's first state (rule S20). Bytes that are not a KDM
222
+ * export, or that do not decode, are `encoding` errors. As the Rust
223
+ * `Replica::snapshot_carries_whole_history`.
224
+ */
225
+ static snapshotCarriesWholeHistory(bytes: Uint8Array): boolean;
226
+ /** Whether `version` is at or after this replica's shallow root: always, on a full replica. */
227
+ private reaches;
228
+ /**
229
+ * Replaces this replica's document with `snapshot` (a full or shallow snapshot of the same
230
+ * document, as a server answers it) plus every change this replica has that `snapshot` lacks,
231
+ * and answers the objects whose state changed. For a shallow replica whose import failed with
232
+ * `history-missing`: a newer snapshot from the server holds the changes it could not take,
233
+ * rooted early enough for them, and this replica's own changes (pushed or not) are kept on top.
234
+ * The state is what importing every change of both would give.
235
+ *
236
+ * Refuses (`wrong-document`) a snapshot of another document, what `load` refuses, and
237
+ * (`history-missing`) a shallow snapshot whose root is after changes of this replica it lacks; a
238
+ * refused rebase changes nothing. Clears the undo and redo history, like any load, and
239
+ * `subscribeText` listeners stop receiving changes.
240
+ */
241
+ rebase(snapshot: Uint8Array): Set<ObjectId>;
242
+ /**
243
+ * Undoes the person's last transaction on this replica (the `person` scope, M12a). Changes from
244
+ * other replicas and from other scopes (an agent's) are kept, including later changes to the
245
+ * same object and to the same field: a register another replica or scope wrote after the undone
246
+ * transaction keeps that value (M12). The objects it changes are reported by `takeChanged`.
247
+ */
248
+ undo(): boolean;
249
+ /** Redoes the person's last undone transaction, keeping other replicas' and scopes' later changes and reporting what it changes like `undo`. */
250
+ redo(): boolean;
251
+ /** Undoes the last transaction of `scope` on this replica, like `undo` for the person. */
252
+ undoIn(scope: UndoScope): boolean;
253
+ /** Redoes the last undone transaction of `scope`, like `redo` for the person. */
254
+ redoIn(scope: UndoScope): boolean;
255
+ /**
256
+ * One undo (or redo) of a run (rule M12b): the top step, and every step under it of the same undo
257
+ * group, which an import split. Each undo or redo step it makes carries the run on.
258
+ */
259
+ private replayRun;
260
+ /** Whether `undo` has a transaction of the person to undo. */
261
+ canUndo(): boolean;
262
+ /** Whether `redo` has an undone transaction of the person to redo. */
263
+ canRedo(): boolean;
264
+ /** Whether `undoIn(scope)` has a transaction to undo. */
265
+ canUndoIn(scope: UndoScope): boolean;
266
+ /** Whether `redoIn(scope)` has an undone transaction to redo. */
267
+ canRedoIn(scope: UndoScope): boolean;
268
+ /** The original objects and fields of the next undo step, including its whole group. */
269
+ undoTouchesIn(scope: UndoScope): UndoTouch[];
270
+ /** The original objects and fields of the next redo step. Reading leaves both histories intact. */
271
+ redoTouchesIn(scope: UndoScope): UndoTouch[];
272
+ private historyTouches;
273
+ /**
274
+ * Starts an undo group: the transactions until `endUndoGroup` undo and redo as one step. Groups
275
+ * do not nest (`invalid-value`). An undo or a redo ends the open group first, so undo while
276
+ * grouping reverts the group as one step. It stays one undo step when other replicas' changes
277
+ * arrive while it is open, also when they touch what the group changed (rule M12b): one undo
278
+ * takes back all of it and keeps their changes. A group spans
279
+ * both undo scopes (M12a): the person's transactions in it are one person step, and an agent's
280
+ * are one agent step.
281
+ */
282
+ beginUndoGroup(): void;
283
+ /** Ends the open undo group; does nothing when none is open. */
284
+ endUndoGroup(): void;
285
+ /** Drops the person's redo stack, keeping the undo stack. */
286
+ clearRedo(): void;
287
+ /** Follows one text field: `listener` gets each change with whether this replica made it. */
288
+ subscribeText(id: ObjectId, field: string, listener: (delta: TextDelta[], local: boolean) => void): () => void;
289
+ /**
290
+ * A draft of this document (standard 2.0 A12): a new writable replica of `actor` holding every
291
+ * change this one has, with no undo history. Edits made on it stay there until `mergeChanges`
292
+ * takes them into another replica of the document.
293
+ */
294
+ fork(actor: bigint): Replica;
295
+ /** A draft of this document as it was at `version` (see `fork`); `version` must be one this replica has reached. */
296
+ forkAt(version: Version, actor: bigint): Replica;
297
+ /**
298
+ * A copy of this document as a **new document** (data model, "A copy is a new document"): the
299
+ * same objects, ids and content under the new permanent `docId`, as a writable replica of
300
+ * `actor`. For a template instantiated twice, a copied file, or the same bytes stored twice: each
301
+ * copy is its own document, with its own co-editing room. Unlike `fork` (a draft of the same
302
+ * document, merged back), a copy never merges with its source or another copy: `importChanges`,
303
+ * `mergeChanges` and `rebase` refuse each other's bytes (`wrong-document`).
304
+ *
305
+ * Answers a replica, as `fork` does, so a host edits it or stores its `snapshot`. The copy is a
306
+ * shallow replica (rule M16a) rooted at its own first change: it holds the current state and no
307
+ * history, so no deleted content, no earlier version and not the source's `docId` travel with
308
+ * it; it forks only at its current version, and `changesSince` a version before the copy is
309
+ * `history-missing`. Its undo and redo histories are empty. Object ids, tree node ids and every
310
+ * value are kept; a blob is its content-addressed reference, so it resolves wherever the
311
+ * source's blobs do (a host whose blob store is per document copies the referenced blobs too).
312
+ *
313
+ * There is no option to keep the history: the copy would share the source's change ids with
314
+ * another document's, every earlier version of it would name the source's `docId`, and deleted
315
+ * content would travel. Refuses (`invalid-value`) a `docId` equal to this document's. The
316
+ * changes still pending on this replica are not in the copy. The Rust crate's
317
+ * `Replica::copy_as_new_document` does the same.
318
+ */
319
+ copyAsNewDocument(docId: string, actor: bigint): Replica;
320
+ /**
321
+ * The canonical state this replica would have after importing `changes`, without changing it:
322
+ * the "after" of a draft's comparison (`diffStates`). Refuses what `mergeChanges` refuses.
323
+ */
324
+ mergedState(changes: Uint8Array): unknown;
325
+ /**
326
+ * Takes another replica's changes (a draft's, made on a `fork`) into this one as one transaction
327
+ * of its own, with `origin`: one undo step of the person (unless `origin` is `system` or `import`; M12a). The result
328
+ * is the state a CRDT import would give, so edits made here (or imported) since the draft was
329
+ * forked are kept; only the operations that turn this state into the merged one are written,
330
+ * under this replica's actor. Answers the objects that changed.
331
+ *
332
+ * The draft's changes themselves are not imported: merging the same changes twice writes their
333
+ * effect twice, so a host merges a draft once. Refuses (`invalid-value`) changes that depend on
334
+ * changes this replica lacks, changes of another document (`wrong-document`), and changes that
335
+ * raise the minimum schema version beyond this replica's (`newer-schema`); a refused merge
336
+ * changes nothing.
337
+ */
338
+ mergeChanges(changes: Uint8Array, origin: Origin): Set<ObjectId>;
339
+ /** A copy of this document with `changes` imported, checked as `mergeChanges` checks them. */
340
+ private mergedDoc;
341
+ /**
342
+ * What changed since `since` (a version this replica reached), as a write's receipt: a
343
+ * `StateDiff` without `texts`, values cut to excerpts, objects named by their tool ids where the
344
+ * schema declares them (OM9). Only the objects the changes since then touched are read, here and
345
+ * in a fork at `since`; the answer equals `diffStates` of the two whole states. A version this
346
+ * replica's history does not hold is a `history-missing` error. As the Rust `changes_since`.
347
+ */
348
+ changesSince(since: Version, options?: {
349
+ textSpans?: boolean;
350
+ }): StateDiff;
351
+ /** The whole document in canonical form; see `stateText`. */
352
+ stateJson(): unknown;
353
+ /** The canonical state as text; equal to the Rust `state_json().to_string()` for the same changes. */
354
+ stateText(): string;
355
+ /**
356
+ * Replaces the document with its history up to `frontiers`, dropping every change applied since.
357
+ * Changes still pending stay recorded in `pending`: they are missing again, and a sync fetches
358
+ * them.
359
+ */
360
+ private restore;
361
+ /** Records the changes an import left pending, and forgets those applied since. */
362
+ private notePending;
363
+ /** Forgets the pending changes applied since they were recorded. */
364
+ private prunePending;
365
+ /** Throws the error that closed this shallow replica, if one did (see `importChanges`). */
366
+ private checkOpen;
367
+ private idle;
368
+ private closeUndoGroup;
369
+ /**
370
+ * After an import, makes sure the open group is still open in the engine: the engine ends it
371
+ * when the import changes what the group changed, and then the group goes on as a new one.
372
+ * Starting a group the engine still has open changes nothing; if the engine can start none, no
373
+ * group is open any more.
374
+ */
375
+ private reopenUndoGroup;
376
+ private history;
377
+ /**
378
+ * The registers whose current value this replica wrote in another scope than `scope` (or in a
379
+ * `system` or `import` transaction), with that value and its scope. Forgets the writes whose value
380
+ * was changed since by anyone.
381
+ */
382
+ private otherScopesRegisters;
383
+ /** A register's value now (`undefined`: absent), and whether it holds a container instead. */
384
+ private registerValue;
385
+ /**
386
+ * The registers whose current value another replica wrote, with that value (`undefined`:
387
+ * deleted there): an import changed them and another peer wrote them last, or an earlier undo or
388
+ * redo kept them for another replica and nothing changed them since. Prunes both candidate sets
389
+ * of registers that are this replica's own again.
390
+ */
391
+ private othersRegisters;
392
+ /** Records the registers a local transaction of `scope` wrote, with their values. */
393
+ private noteOwnWrites;
394
+ }
395
+ /**
396
+ * The undo group runs of a replica (rule M12b): `current` is the open group's, which each new undo
397
+ * step takes; while an undo or redo replays (`replaying`), the step it makes takes the run of the
398
+ * step it popped (`popped`), so a run undone stays one run to redo.
399
+ */
400
+ export type UndoTouch = {
401
+ id: ObjectId;
402
+ fields: string[] | null;
403
+ };
@@ -0,0 +1,185 @@
1
+ import { type JsonValue } from './value.js';
2
+ /** The KDM schema format version this build reads. */
3
+ export declare const KDM_VERSION = 1;
4
+ /**
5
+ * What a field holds. Registers hold one value (last writer wins); containers merge their
6
+ * contents (text characters, list items, tree nodes, map keys).
7
+ */
8
+ export type FieldKind = 'string' | 'number' | 'integer' | 'boolean' | 'enum' | 'json' | 'blob' | 'ref' | 'text' | 'list' | 'tree' | 'map';
9
+ export interface FieldDef {
10
+ kind: FieldKind;
11
+ /** The field's wording in instructions; a boolean's positive state. */
12
+ label?: string;
13
+ minimum?: number;
14
+ maximum?: number;
15
+ multipleOf?: number;
16
+ members?: Record<string, {
17
+ minimum?: number;
18
+ maximum?: number;
19
+ multipleOf?: number;
20
+ nullable?: boolean;
21
+ }>;
22
+ /** The type a ref, list, tree or typed owning map names. Typed map entries are object IDs. */
23
+ of?: string;
24
+ /** The allowed values of an `enum` field. */
25
+ values?: string[];
26
+ optional?: boolean;
27
+ /**
28
+ * The marks a `text` field takes (rich-text run properties), by key (rule M19). A field without
29
+ * marks reads as a plain string in the canonical state; one with marks reads as its runs.
30
+ */
31
+ marks?: Record<string, MarkDef>;
32
+ /**
33
+ * Content the kit keeps verbatim but does not model (rule OM8): the object model reads the
34
+ * field and never writes it. The kit's own transactions and commands still do.
35
+ */
36
+ readOnly?: boolean;
37
+ /**
38
+ * A `ref` field whose object is part of the object holding it (a shape's text body), as the items
39
+ * of a `list` or `tree` field always are; a ref without it only points (a picture's shared media).
40
+ * A `map` field declared `owns` holds, under each key, the objects its value names (`mapHeld`):
41
+ * a table's cells, each value naming the cell's text body. Change sets attribute a change of an
42
+ * object without a tool id to the nearest object holding it (`diffWithToolIds`).
43
+ */
44
+ owns?: boolean;
45
+ /** Batch deletion of a node also deletes descendants of this tree, child-first. */
46
+ cascade?: boolean;
47
+ /**
48
+ * A field that says where its object is rather than what it is (a clip's `start` and `duration`
49
+ * on its track): agent tools treat its change as a move of the object, never as a change of its
50
+ * content (as the Rust `FieldDef::position`).
51
+ */
52
+ position?: boolean;
53
+ /** How a person reads the value, as the Rust `FieldDef::display`. */
54
+ display?: {
55
+ kind: 'time';
56
+ perSecond: number;
57
+ fps?: number;
58
+ };
59
+ /** Whether a training environment may sample an edit of it, as the Rust `FieldDef::sample`. */
60
+ sample?: boolean;
61
+ }
62
+ /** Whether the objects `def` holds are parts of its object: a `list` or `tree` field, or a `ref` or `map` declared `owns` (as the Rust `FieldDef::owning`). */
63
+ export declare const owning: (def: FieldDef) => boolean;
64
+ /**
65
+ * As the Rust `FieldDef::map_held`: the objects an owning `map` field's value `map` holds, each with
66
+ * its place: the value under a key when it is a string naming an object (`<key>`), else each member
67
+ * of an object value that is one (`<key>.<member>`), keys and members in order.
68
+ */
69
+ export declare function mapHeld(map: unknown, exists: (id: string) => boolean): Array<[string, string]>;
70
+ /** How a mark grows when text is inserted at one of its ends. */
71
+ export type Expand = 'after' | 'before' | 'both' | 'none';
72
+ /** One mark a `text` field declares. */
73
+ export interface MarkDef {
74
+ expand: Expand;
75
+ }
76
+ export interface TypeDef {
77
+ fields: Record<string, FieldDef>;
78
+ projected?: boolean;
79
+ projectedOps?: Record<string, {
80
+ command: string;
81
+ params?: Record<string, string>;
82
+ }>;
83
+ batchOps?: Record<string, {
84
+ direct: true;
85
+ } | {
86
+ command: string;
87
+ params?: Record<string, string>;
88
+ }>;
89
+ creation?: {
90
+ fields?: Record<string, unknown>;
91
+ command?: {
92
+ command: string;
93
+ params?: Record<string, string>;
94
+ };
95
+ fixtures?: Record<string, unknown>;
96
+ };
97
+ /** Position field paths regenerated by a move, including on owned descendants. */
98
+ moveConsequences?: string[];
99
+ structuralConsequences?: Array<{
100
+ container: string;
101
+ on: Array<'create' | 'delete' | 'move' | 'rename' | 'set'>;
102
+ fields: string[];
103
+ }>;
104
+ /** Every object of the type is read-only through the object model (rule OM8). */
105
+ readOnly?: boolean;
106
+ /** The objects whose enum `field` holds one of `values` are read-only through the object model (rule OM8). */
107
+ readOnlyWhen?: ReadOnlyWhen;
108
+ /**
109
+ * The type's tool id (rule OM9): the field holding the id the kit's own tools give its objects,
110
+ * which the object model then answers and takes as their `id`.
111
+ */
112
+ toolId?: ToolIdDef;
113
+ /**
114
+ * How an object of the type is named in a path, as the kit's commands name it: a
115
+ * field (`name`), or a member of a json field (`meta.match`); change sets then give an edit inside
116
+ * a held object `named` beside its `field` (as the Rust `TypeDef::path_name`).
117
+ */
118
+ pathName?: string;
119
+ /** What names an object of the type to a person, as the Rust `TypeDef::label`. */
120
+ label?: string;
121
+ /**
122
+ * Values the kit computes for an object of the type on request and never stores: a
123
+ * mesh's topology, its local bounds; change sets name one `~<name>` (as the Rust
124
+ * `TypeDef::derived`).
125
+ */
126
+ derived?: Record<string, DerivedDef>;
127
+ /** The field or JSON member path containing the object's displayed text. */
128
+ text?: string;
129
+ /** Raw field writes depend only on identity and the written fields, not placement. */
130
+ batchIndependent?: boolean;
131
+ }
132
+ /** One derived value a type declares: what it says, for the agent (as the Rust `DerivedDef`). */
133
+ export interface DerivedDef {
134
+ description?: string;
135
+ premiseOnly?: boolean;
136
+ onDemand?: boolean;
137
+ }
138
+ /**
139
+ * `{ field, prefix?, parent? }`: an object of the type is named at the tool interface by `prefix`
140
+ * and the value of its read-only `integer` or `string` `field` (`item:` and `10` give `item:10`),
141
+ * after its `parent`'s tool id and a `/` when the type's values are unique only within a parent
142
+ * (`story:11/table:2`). As the Rust `ToolIdDef`.
143
+ */
144
+ export interface ToolIdDef {
145
+ field: string;
146
+ prefix: string;
147
+ /** The type whose object holds an object of this type in a `list`, `tree`, or `ref` field. */
148
+ parent?: string;
149
+ }
150
+ /** Whether any type declares a tool id (rule OM9). */
151
+ export declare const hasToolIds: (schema: Schema) => boolean;
152
+ /** `{ field: <an enum field of the type>, values }`: the objects holding one of the values are read-only. */
153
+ export interface ReadOnlyWhen {
154
+ field: string;
155
+ values: string[];
156
+ }
157
+ /**
158
+ * Whether the object model may not write an object of type `def` (rule OM8). `field` answers a
159
+ * register's value (for `readOnlyWhen`).
160
+ */
161
+ export declare function objectReadOnly(def: TypeDef, field: (name: string) => unknown): boolean;
162
+ /** A kit's document schema (`model/schema.json` in its package). Built by `parseSchema`, which checks it. */
163
+ export interface Schema {
164
+ readonly kdm: number;
165
+ readonly kit: string;
166
+ readonly schemaVersion: number;
167
+ readonly root: string;
168
+ readonly types: Readonly<Record<string, TypeDef>>;
169
+ }
170
+ export declare const isContainer: (kind: FieldKind) => boolean;
171
+ /** Keys in the order the Rust crate visits them (`BTreeMap`: code point order), whatever JavaScript's own order. */
172
+ export declare const sortedKeys: (value: object) => string[];
173
+ /** Whether `def` is a `text` field that declares marks. */
174
+ export declare const hasMarks: (def: FieldDef) => boolean;
175
+ /** Every mark key the schema declares with its expand: each key has one expand in a schema. */
176
+ export declare function markExpands(schema: Schema): Map<string, Expand>;
177
+ /** Parses and checks a schema with the same rules as the Rust `Schema::parse`. The result is a checked copy. */
178
+ export declare function parseSchema(input: string | object): Schema;
179
+ export declare function typeDef(schema: Schema, ty: string): TypeDef;
180
+ export declare function fieldDef(schema: Schema, ty: string, field: string): FieldDef;
181
+ /** Checks a value for a register field, as the Rust `Schema::check_value`. Container fields take no value. */
182
+ export declare function checkValue(schema: Schema, ty: string, field: string, value: unknown): void;
183
+ /** `checkValue` answering the value as the KDM stores it: a checked JSON copy (see `toJson`). */
184
+ export declare function checkedValue(schema: Schema, ty: string, field: string, value: unknown): JsonValue;
185
+ export declare function checkMapEntry(schema: Schema, ty: string, field: string, key: string, value: JsonValue): void;
@@ -0,0 +1,28 @@
1
+ import { Replica } from './replica.js';
2
+ import type { Schema } from './schema.js';
3
+ /** A small deterministic random generator (xorshift64*), the same as the Rust one, so failing seeds reproduce. */
4
+ export declare class Rng {
5
+ private state;
6
+ constructor(seed: number | bigint);
7
+ nextU64(): bigint;
8
+ /** A value in `0..bound`, or 0 when `bound` is 0. */
9
+ below(bound: number): number;
10
+ shuffle<T>(items: T[]): void;
11
+ }
12
+ /** `count` replicas of one new document, each with its own actor (1, 2, 3, ...). */
13
+ export declare class Network {
14
+ readonly replicas: Replica[];
15
+ readonly rng: Rng;
16
+ /** Fails with `out-of-range` when `count` is 0: a network has at least one replica. */
17
+ constructor(schema: Schema, count: number, seed?: number | bigint);
18
+ /** Sends what `to` lacks from `from`. */
19
+ deliver(from: number, to: number): void;
20
+ /**
21
+ * Delivers every replica's changes to every other replica in a seeded order, then sends
22
+ * everything again from scratch to prove that duplicates are harmless.
23
+ */
24
+ syncAll(): void;
25
+ /** The common canonical state; throws with both states when two replicas differ, or when there are no replicas. */
26
+ converged(): string;
27
+ private replica;
28
+ }