@kitionstage/sdk 0.0.0-stage → 0.5.2-stage.2
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.
- package/README.md +73 -2
- package/dist/LICENSE +177 -0
- package/dist/THIRD_PARTY_NOTICES +28 -0
- package/dist/lib/assets/kitEngine.worker-3iMvwtlI.js +12732 -0
- package/dist/lib/assets/loro_wasm_bg-Gulzks_0.wasm +0 -0
- package/dist/lib/chunks/batch-BWpAyHvP.js +789 -0
- package/dist/lib/chunks/canonical-BIWfVCL-.js +87 -0
- package/dist/lib/chunks/envelope-D6MGY-ZN.js +61 -0
- package/dist/lib/chunks/replica-D8w3I4sn.js +2472 -0
- package/dist/lib/chunks/runtime-BVJHE1Pg.js +997 -0
- package/dist/lib/chunks/session-BqXC9a1-.js +281 -0
- package/dist/lib/chunks/toolIds-BCeSGHpV.js +821 -0
- package/dist/lib/chunks/workspaceTree-Destqupf.js +23 -0
- package/dist/lib/convergence/index.js +1035 -0
- package/dist/lib/convergence/node.js +8 -0
- package/dist/lib/embed-server/callbacks.js +37 -0
- package/dist/lib/embed-server/cli.js +19 -0
- package/dist/lib/embed-server/index.js +272 -0
- package/dist/lib/extensions/index.js +439 -0
- package/dist/lib/extensions/panel.html +208 -0
- package/dist/lib/extensions/runtime.js +198 -0
- package/dist/lib/extensions/sandbox.html +35 -0
- package/dist/lib/kdm/index.js +437 -0
- package/dist/lib/kit-dev-host/checkUiIds.mjs +44 -0
- package/dist/lib/kit-dev-host/index.js +308 -0
- package/dist/lib/kit-dev-host/lineRow.mjs +47 -0
- package/dist/lib/kit-dev-host/modeSmoke.mjs +178 -0
- package/dist/lib/kit-editor/index.js +6481 -0
- package/dist/lib/kit-editor/styles.css +807 -0
- package/dist/lib/kit-editor/workspaceTree.js +1 -0
- package/dist/lib/kit-engine/index.js +7 -0
- package/dist/lib/kit-host/index.js +530 -0
- package/dist/lib/kit-ui-protocol/index.js +336 -0
- package/dist/lib/node-only/embed-server-callbacks.js +2 -0
- package/dist/lib/node-only/embed-server.js +2 -0
- package/dist/lib/sync/index.js +1008 -0
- package/dist/lib/sync/openToken.js +201 -0
- package/dist/lib/sync/replicaVersions.js +51 -0
- package/dist/standalone/chunks/batch-CAGYk6m4.js +789 -0
- package/dist/standalone/chunks/client-B9xkOcvf.js +772 -0
- package/dist/standalone/chunks/collab-CTQZ9h7J.js +1022 -0
- package/dist/standalone/chunks/comment-Ds9t8xSE.js +94 -0
- package/dist/standalone/chunks/comments-uVDS8Wxp.js +41 -0
- package/dist/standalone/chunks/document-B5MMuYyN.js +324 -0
- package/dist/standalone/chunks/envelope-GX4Cynkx.js +7612 -0
- package/dist/standalone/chunks/index-BEgEEnhU.js +287 -0
- package/dist/standalone/chunks/index-EEl8hGbP.js +1967 -0
- package/dist/standalone/chunks/kits-Cp51mDlw.js +9 -0
- package/dist/standalone/chunks/replica-Di2iCPiD.js +3281 -0
- package/dist/standalone/chunks/replicaVersions-C3rJxnk9.js +50 -0
- package/dist/standalone/chunks/touched-T9jKJjxn.js +78 -0
- package/dist/standalone/index.js +12 -0
- package/dist/standalone/script/index.js +339 -0
- package/dist/standalone/script/kits/board.js +5 -0
- package/dist/standalone/script/kits/cad.js +5 -0
- package/dist/standalone/script/kits/design.js +5 -0
- package/dist/standalone/script/kits/doc.js +5 -0
- package/dist/standalone/script/kits/film.js +5 -0
- package/dist/standalone/script/kits/html.js +5 -0
- package/dist/standalone/script/kits/index.js +38 -0
- package/dist/standalone/script/kits/layout.js +5 -0
- package/dist/standalone/script/kits/motion.js +5 -0
- package/dist/standalone/script/kits/note.js +5 -0
- package/dist/standalone/script/kits/pdf.js +5 -0
- package/dist/standalone/script/kits/photo.js +5 -0
- package/dist/standalone/script/kits/scene.js +5 -0
- package/dist/standalone/script/kits/sheet.js +5 -0
- package/dist/standalone/script/kits/slide.js +5 -0
- package/dist/standalone/script/kits/table.js +5 -0
- package/dist/standalone/script/kits/vector.js +5 -0
- package/dist/standalone/script/node.js +401 -0
- package/dist/standalone/script/proxy.js +254 -0
- package/dist/types/convergence/src/adapter.d.ts +131 -0
- package/dist/types/convergence/src/engine.d.ts +66 -0
- package/dist/types/convergence/src/index.d.ts +21 -0
- package/dist/types/convergence/src/net.d.ts +52 -0
- package/dist/types/convergence/src/node.d.ts +6 -0
- package/dist/types/convergence/src/report.d.ts +56 -0
- package/dist/types/convergence/src/rng.d.ts +12 -0
- package/dist/types/convergence/src/scenarios.d.ts +15 -0
- package/dist/types/convergence/src/state.d.ts +67 -0
- package/dist/types/embed/src/agent.d.ts +88 -0
- package/dist/types/embed/src/blobs.d.ts +2 -0
- package/dist/types/embed/src/collab.d.ts +250 -0
- package/dist/types/embed/src/comments.d.ts +30 -0
- package/dist/types/embed/src/errors.d.ts +24 -0
- package/dist/types/embed/src/handlers.d.ts +92 -0
- package/dist/types/embed/src/index.d.ts +20 -0
- package/dist/types/embed/src/mount.d.ts +39 -0
- package/dist/types/embed/src/replicaStore.d.ts +3 -0
- package/dist/types/embed/src/rooms.d.ts +40 -0
- package/dist/types/embed/src/schemas.d.ts +7 -0
- package/dist/types/embed/src/syncClients.d.ts +28 -0
- package/dist/types/embed/src/theme.d.ts +7 -0
- package/dist/types/embed/src/types.d.ts +596 -0
- package/dist/types/embed/src/ui.d.ts +33 -0
- package/dist/types/embed/src/version.d.ts +2 -0
- package/dist/types/embed-server/src/callbacks.d.ts +30 -0
- package/dist/types/embed-server/src/cli.d.ts +1 -0
- package/dist/types/embed-server/src/index.d.ts +19 -0
- package/dist/types/embed-server/src/page.d.ts +15 -0
- package/dist/types/embed-server/src/server.d.ts +39 -0
- package/dist/types/embed-server/src/session.d.ts +22 -0
- package/dist/types/extensions/src/gate.d.ts +17 -0
- package/dist/types/extensions/src/generated/runtime.d.ts +8 -0
- package/dist/types/extensions/src/host.d.ts +135 -0
- package/dist/types/extensions/src/index.d.ts +13 -0
- package/dist/types/extensions/src/manifest.d.ts +82 -0
- package/dist/types/extensions/src/protocol.d.ts +159 -0
- package/dist/types/extensions/src/rpc.d.ts +52 -0
- package/dist/types/extensions/src/runtime/document.d.ts +40 -0
- package/dist/types/extensions/src/runtime/index.d.ts +10 -0
- package/dist/types/extensions/src/runtime/panel.d.ts +19 -0
- package/dist/types/extensions/src/runtime/runtime.d.ts +54 -0
- package/dist/types/extensions/src/runtime/worker.d.ts +1 -0
- package/dist/types/extensions/src/sandbox.d.ts +41 -0
- package/dist/types/kdm/src/args.d.ts +12 -0
- package/dist/types/kdm/src/batch.d.ts +118 -0
- package/dist/types/kdm/src/canonical.d.ts +25 -0
- package/dist/types/kdm/src/comment.d.ts +114 -0
- package/dist/types/kdm/src/diff.d.ts +125 -0
- package/dist/types/kdm/src/envelope.d.ts +27 -0
- package/dist/types/kdm/src/errors.d.ts +28 -0
- package/dist/types/kdm/src/footprint.d.ts +21 -0
- package/dist/types/kdm/src/ids.d.ts +57 -0
- package/dist/types/kdm/src/index.d.ts +18 -0
- package/dist/types/kdm/src/marks.d.ts +32 -0
- package/dist/types/kdm/src/op.d.ts +124 -0
- package/dist/types/kdm/src/origin.d.ts +41 -0
- package/dist/types/kdm/src/overlay.d.ts +92 -0
- package/dist/types/kdm/src/projection.d.ts +29 -0
- package/dist/types/kdm/src/read.d.ts +90 -0
- package/dist/types/kdm/src/replica.d.ts +403 -0
- package/dist/types/kdm/src/schema.d.ts +185 -0
- package/dist/types/kdm/src/testing.d.ts +28 -0
- package/dist/types/kdm/src/toolIds.d.ts +61 -0
- package/dist/types/kdm/src/touched.d.ts +24 -0
- package/dist/types/kdm/src/tx.d.ts +215 -0
- package/dist/types/kdm/src/value.d.ts +23 -0
- package/dist/types/kit-dev-host/src/checkNoPaths.d.ts +19 -0
- package/dist/types/kit-dev-host/src/checkUiIds.d.mts +2 -0
- package/dist/types/kit-dev-host/src/index.d.ts +179 -0
- package/dist/types/kit-dev-host/src/lineRow.d.mts +14 -0
- package/dist/types/kit-dev-host/src/memoryFiles.d.ts +15 -0
- package/dist/types/kit-dev-host/src/modeSmoke.d.mts +8 -0
- package/dist/types/kit-editor/src/CommandDialog.d.ts +22 -0
- package/dist/types/kit-editor/src/CommentsPanel.d.ts +45 -0
- package/dist/types/kit-editor/src/CustomizeDialog.d.ts +32 -0
- package/dist/types/kit-editor/src/HostButtons.d.ts +11 -0
- package/dist/types/kit-editor/src/RenderFailure.d.ts +7 -0
- package/dist/types/kit-editor/src/TextSink.d.ts +6 -0
- package/dist/types/kit-editor/src/brand.d.ts +2 -0
- package/dist/types/kit-editor/src/catalogMenus.d.ts +27 -0
- package/dist/types/kit-editor/src/chart.d.ts +138 -0
- package/dist/types/kit-editor/src/conflicts.d.ts +12 -0
- package/dist/types/kit-editor/src/drawing.d.ts +83 -0
- package/dist/types/kit-editor/src/editor.d.ts +544 -0
- package/dist/types/kit-editor/src/engine/KitCanvas.d.ts +70 -0
- package/dist/types/kit-editor/src/engine/backdrop.d.ts +32 -0
- package/dist/types/kit-editor/src/engine/createKitFile.d.ts +12 -0
- package/dist/types/kit-editor/src/engine/decorations.d.ts +14 -0
- package/dist/types/kit-editor/src/engine/engineOverlays.d.ts +197 -0
- package/dist/types/kit-editor/src/engine/engineTools.d.ts +116 -0
- package/dist/types/kit-editor/src/engine/kitDraft.d.ts +70 -0
- package/dist/types/kit-editor/src/engine/kitEngine.d.ts +390 -0
- package/dist/types/kit-editor/src/engine/kitEngine.worker.d.ts +30 -0
- package/dist/types/kit-editor/src/engine/kitHost.d.ts +41 -0
- package/dist/types/kit-editor/src/engine/kitModel.d.ts +32 -0
- package/dist/types/kit-editor/src/engine/kitModelRunner.d.ts +99 -0
- package/dist/types/kit-editor/src/engine/kitModule.d.ts +185 -0
- package/dist/types/kit-editor/src/engine/kitShortcuts.d.ts +32 -0
- package/dist/types/kit-editor/src/engine/kitTools.d.ts +79 -0
- package/dist/types/kit-editor/src/engine/lazyFonts.d.ts +34 -0
- package/dist/types/kit-editor/src/engine/lentFiles.d.ts +29 -0
- package/dist/types/kit-editor/src/engine/rasterViewport.d.ts +178 -0
- package/dist/types/kit-editor/src/engine/readOnly.d.ts +78 -0
- package/dist/types/kit-editor/src/engine/refusal.d.ts +39 -0
- package/dist/types/kit-editor/src/engine/replica.d.ts +23 -0
- package/dist/types/kit-editor/src/engine/useKitDocument.d.ts +154 -0
- package/dist/types/kit-editor/src/engine/workerRelay.d.ts +62 -0
- package/dist/types/kit-editor/src/files.d.ts +74 -0
- package/dist/types/kit-editor/src/frame/EditorFrame.d.ts +74 -0
- package/dist/types/kit-editor/src/frame/FocusBar.d.ts +10 -0
- package/dist/types/kit-editor/src/frame/MenuNodes.d.ts +20 -0
- package/dist/types/kit-editor/src/frame/MenuRibbon.d.ts +8 -0
- package/dist/types/kit-editor/src/frame/ModeButton.d.ts +7 -0
- package/dist/types/kit-editor/src/frame/menus.d.ts +64 -0
- package/dist/types/kit-editor/src/frame/modes.d.ts +51 -0
- package/dist/types/kit-editor/src/frame/useFrameLayout.d.ts +34 -0
- package/dist/types/kit-editor/src/host.d.ts +127 -0
- package/dist/types/kit-editor/src/index.d.ts +85 -0
- package/dist/types/kit-editor/src/ink.d.ts +26 -0
- package/dist/types/kit-editor/src/lease.d.ts +53 -0
- package/dist/types/kit-editor/src/oneInFlight.d.ts +7 -0
- package/dist/types/kit-editor/src/phrases.d.ts +25 -0
- package/dist/types/kit-editor/src/presence.d.ts +79 -0
- package/dist/types/kit-editor/src/strings.d.ts +6 -0
- package/dist/types/kit-editor/src/toolIcons.d.ts +32 -0
- package/dist/types/kit-editor/src/uiCatalog.d.ts +59 -0
- package/dist/types/kit-editor/src/uiConfig.d.ts +53 -0
- package/dist/types/kit-editor/src/uiContext.d.ts +65 -0
- package/dist/types/kit-editor/src/uiStore.d.ts +20 -0
- package/dist/types/kit-editor/src/useCommentAnchors.d.ts +29 -0
- package/dist/types/kit-editor/src/useKitSession.d.ts +115 -0
- package/dist/types/kit-editor/src/workspaceTree.d.ts +5 -0
- package/dist/types/kit-engine/src/contract.d.ts +154 -0
- package/dist/types/kit-engine/src/index.d.ts +2 -0
- package/dist/types/kit-engine/src/session.d.ts +133 -0
- package/dist/types/kit-host/src/files.d.ts +163 -0
- package/dist/types/kit-host/src/index.d.ts +315 -0
- package/dist/types/kit-ui-protocol/src/index.d.ts +1145 -0
- package/dist/types/loro-crdt.d.ts +9 -0
- package/dist/types/script/kits/board.d.ts +534 -0
- package/dist/types/script/kits/cad.d.ts +2937 -0
- package/dist/types/script/kits/design.d.ts +3213 -0
- package/dist/types/script/kits/doc.d.ts +2575 -0
- package/dist/types/script/kits/film.d.ts +4067 -0
- package/dist/types/script/kits/html.d.ts +38 -0
- package/dist/types/script/kits/index.d.ts +20 -0
- package/dist/types/script/kits/layout.d.ts +3483 -0
- package/dist/types/script/kits/motion.d.ts +4826 -0
- package/dist/types/script/kits/note.d.ts +631 -0
- package/dist/types/script/kits/pdf.d.ts +829 -0
- package/dist/types/script/kits/photo.d.ts +7574 -0
- package/dist/types/script/kits/scene.d.ts +2962 -0
- package/dist/types/script/kits/sheet.d.ts +2419 -0
- package/dist/types/script/kits/slide.d.ts +1894 -0
- package/dist/types/script/kits/table.d.ts +654 -0
- package/dist/types/script/kits/vector.d.ts +5167 -0
- package/dist/types/script/src/agentRelay.d.ts +48 -0
- package/dist/types/script/src/capabilities.d.ts +21 -0
- package/dist/types/script/src/document.d.ts +87 -0
- package/dist/types/script/src/drafts.d.ts +141 -0
- package/dist/types/script/src/exchange.d.ts +30 -0
- package/dist/types/script/src/headless.d.ts +190 -0
- package/dist/types/script/src/index.d.ts +15 -0
- package/dist/types/script/src/kitModel.d.ts +17 -0
- package/dist/types/script/src/kits.d.ts +8 -0
- package/dist/types/script/src/node.d.ts +42 -0
- package/dist/types/script/src/port.d.ts +89 -0
- package/dist/types/script/src/proxy.d.ts +132 -0
- package/dist/types/script/src/room.d.ts +162 -0
- package/dist/types/script/src/sources.d.ts +73 -0
- package/dist/types/sync/src/backoff.d.ts +9 -0
- package/dist/types/sync/src/blobSection.d.ts +23 -0
- package/dist/types/sync/src/capabilities.d.ts +20 -0
- package/dist/types/sync/src/client.d.ts +253 -0
- package/dist/types/sync/src/framing.d.ts +35 -0
- package/dist/types/sync/src/hash.d.ts +2 -0
- package/dist/types/sync/src/index.d.ts +19 -0
- package/dist/types/sync/src/leases.d.ts +82 -0
- package/dist/types/sync/src/openToken.d.ts +104 -0
- package/dist/types/sync/src/protocol.d.ts +484 -0
- package/dist/types/sync/src/relay.d.ts +52 -0
- package/dist/types/sync/src/replicaVersions.d.ts +17 -0
- package/dist/types/sync/src/saveMachine.d.ts +83 -0
- package/dist/types/sync/src/saveRun.d.ts +52 -0
- package/dist/types/sync/src/transport.d.ts +19 -0
- package/package.json +229 -4
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marks on text (Standard 2.0 rule M19): rich-text run properties a `text` field declares in the
|
|
3
|
+
* schema; the twin of the Rust crate's `marks` module. Each mark key is its own last-writer-wins
|
|
4
|
+
* value over ranges of characters; the schema's `expand` decides whether text typed at a marked
|
|
5
|
+
* range's ends takes the mark.
|
|
6
|
+
*/
|
|
7
|
+
import type { LoroDoc, LoroText } from '../../loro-crdt.js';
|
|
8
|
+
import { type FieldDef, type Schema } from './schema.js';
|
|
9
|
+
import type { JsonValue } from './value.js';
|
|
10
|
+
/**
|
|
11
|
+
* One run of a text field: characters that carry the same marks. `Replica.textDelta` reads a
|
|
12
|
+
* text field as runs in order; adjacent runs differ in their marks, no run is empty, and
|
|
13
|
+
* `attributes` holds only the field's declared marks, keys sorted, values in canonical form. A run
|
|
14
|
+
* without marks has no `attributes`.
|
|
15
|
+
*/
|
|
16
|
+
export interface TextRun {
|
|
17
|
+
insert: string;
|
|
18
|
+
attributes?: Record<string, JsonValue>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Tells the engine every mark key of the schema and its expand. The configuration is local to a
|
|
22
|
+
* replica (the engine does not replicate it); every replica of a document configures it from the
|
|
23
|
+
* same schema before it marks anything.
|
|
24
|
+
*/
|
|
25
|
+
export declare function configure(doc: LoroDoc, schema: Schema): void;
|
|
26
|
+
/** Appends a run, merging it into the last one when their marks are equal. */
|
|
27
|
+
export declare function pushRun(out: TextRun[], insert: string, attributes: Record<string, JsonValue> | undefined): void;
|
|
28
|
+
/**
|
|
29
|
+
* A text field's runs as the canonical state reads them: only `def`'s declared marks, null
|
|
30
|
+
* values (unmarked) dropped, empty runs dropped, adjacent runs with equal marks merged.
|
|
31
|
+
*/
|
|
32
|
+
export declare function runs(text: LoroText, def: FieldDef): TextRun[];
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A transaction's buffered operations and their application to the engine. `Tx` validates each
|
|
3
|
+
* operation when it is called and records it here; nothing reaches the engine until the
|
|
4
|
+
* transaction's function has returned. The engine cannot abort a transaction (its operations take
|
|
5
|
+
* effect as they are applied), so staging is what makes a failed transaction leave no operations.
|
|
6
|
+
*/
|
|
7
|
+
import type { LoroDoc } from '../../loro-crdt.js';
|
|
8
|
+
import { type NodeRef, type ObjectId } from './ids.js';
|
|
9
|
+
import { type NodeKey } from './overlay.js';
|
|
10
|
+
import { type Schema } from './schema.js';
|
|
11
|
+
import type { JsonValue } from './value.js';
|
|
12
|
+
export type JsonFields = Record<string, JsonValue>;
|
|
13
|
+
export type Op = {
|
|
14
|
+
op: 'create';
|
|
15
|
+
id: ObjectId;
|
|
16
|
+
ty: string;
|
|
17
|
+
fields: JsonFields;
|
|
18
|
+
} | {
|
|
19
|
+
op: 'set';
|
|
20
|
+
id: ObjectId;
|
|
21
|
+
field: string;
|
|
22
|
+
value: JsonValue;
|
|
23
|
+
} | {
|
|
24
|
+
op: 'delete';
|
|
25
|
+
id: ObjectId;
|
|
26
|
+
} | {
|
|
27
|
+
op: 'textInsert';
|
|
28
|
+
id: ObjectId;
|
|
29
|
+
field: string;
|
|
30
|
+
index: number;
|
|
31
|
+
content: string;
|
|
32
|
+
} | {
|
|
33
|
+
op: 'textDelete';
|
|
34
|
+
id: ObjectId;
|
|
35
|
+
field: string;
|
|
36
|
+
index: number;
|
|
37
|
+
count: number;
|
|
38
|
+
}
|
|
39
|
+
/** Sets mark `key` to `value` over `start..end` (UTF-16 code units; never empty). */
|
|
40
|
+
| {
|
|
41
|
+
op: 'textMark';
|
|
42
|
+
id: ObjectId;
|
|
43
|
+
field: string;
|
|
44
|
+
start: number;
|
|
45
|
+
end: number;
|
|
46
|
+
key: string;
|
|
47
|
+
value: JsonValue;
|
|
48
|
+
}
|
|
49
|
+
/** Removes mark `key` from `start..end` (never empty). */
|
|
50
|
+
| {
|
|
51
|
+
op: 'textUnmark';
|
|
52
|
+
id: ObjectId;
|
|
53
|
+
field: string;
|
|
54
|
+
start: number;
|
|
55
|
+
end: number;
|
|
56
|
+
key: string;
|
|
57
|
+
} | {
|
|
58
|
+
op: 'listInsert';
|
|
59
|
+
id: ObjectId;
|
|
60
|
+
field: string;
|
|
61
|
+
index: number;
|
|
62
|
+
item: ObjectId;
|
|
63
|
+
} | {
|
|
64
|
+
op: 'listMove';
|
|
65
|
+
id: ObjectId;
|
|
66
|
+
field: string;
|
|
67
|
+
from: number;
|
|
68
|
+
to: number;
|
|
69
|
+
} | {
|
|
70
|
+
op: 'listRemove';
|
|
71
|
+
id: ObjectId;
|
|
72
|
+
field: string;
|
|
73
|
+
index: number;
|
|
74
|
+
} | {
|
|
75
|
+
op: 'mapSet';
|
|
76
|
+
id: ObjectId;
|
|
77
|
+
field: string;
|
|
78
|
+
key: string;
|
|
79
|
+
value: JsonValue;
|
|
80
|
+
} | {
|
|
81
|
+
op: 'mapDelete';
|
|
82
|
+
id: ObjectId;
|
|
83
|
+
field: string;
|
|
84
|
+
key: string;
|
|
85
|
+
}
|
|
86
|
+
/** Creates the transaction's `node`-th node. */
|
|
87
|
+
| {
|
|
88
|
+
op: 'treeCreate';
|
|
89
|
+
id: ObjectId;
|
|
90
|
+
field: string;
|
|
91
|
+
parent: NodeKey | null;
|
|
92
|
+
object: ObjectId;
|
|
93
|
+
node: number;
|
|
94
|
+
} | {
|
|
95
|
+
op: 'treeMove';
|
|
96
|
+
id: ObjectId;
|
|
97
|
+
field: string;
|
|
98
|
+
node: NodeKey;
|
|
99
|
+
parent: NodeKey | null;
|
|
100
|
+
}
|
|
101
|
+
/** Deletes a node that has no children: only `Tx.treeDedupe` makes it (M10b). */
|
|
102
|
+
| {
|
|
103
|
+
op: 'treeDelete';
|
|
104
|
+
id: ObjectId;
|
|
105
|
+
field: string;
|
|
106
|
+
node: NodeKey;
|
|
107
|
+
}
|
|
108
|
+
/** Raises the document's minimum schema version (rule M20); a no-op when it is already at least `version` when applied. */
|
|
109
|
+
| {
|
|
110
|
+
op: 'raiseSchema';
|
|
111
|
+
version: number;
|
|
112
|
+
};
|
|
113
|
+
/** Applies validated operations in order and resolves the created nodes' handles. Does not commit. */
|
|
114
|
+
export declare function apply(doc: LoroDoc, schema: Schema, ops: Op[], nodes: NodeRef[], touched: (id: ObjectId) => void): void;
|
|
115
|
+
/**
|
|
116
|
+
* The most UTF-16 code units one engine text element is given by an insert (the Rust crate's
|
|
117
|
+
* `TEXT_PIECE` counts 1024 Unicode scalar values). The engine keeps a text as elements of
|
|
118
|
+
* inserted runs and scans an element holding non-ASCII text on every edit inside it, so an edit
|
|
119
|
+
* costs the length of its element: a file imported in one insert would make every later edit cost
|
|
120
|
+
* the whole file. Longer content goes in pieces, last piece first, so each piece stays its own
|
|
121
|
+
* element (a piece placed before the one inserted just before it is never merged with it). The
|
|
122
|
+
* text and every replica's result are the same; the history holds one insert per piece.
|
|
123
|
+
*/
|
|
124
|
+
export declare const TEXT_PIECE = 1024;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Who caused a transaction. */
|
|
2
|
+
export type OriginKind = 'person' | 'agent' | 'extension' | 'import' | 'system';
|
|
3
|
+
/**
|
|
4
|
+
* The origin of a transaction: its kind, the principal it acts for, and a label for history.
|
|
5
|
+
* Authorization never trusts it; a server checks the authenticated principal instead.
|
|
6
|
+
*/
|
|
7
|
+
export interface Origin {
|
|
8
|
+
kind: OriginKind;
|
|
9
|
+
principal: string;
|
|
10
|
+
label?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The undo history a transaction joins (rule M12a): a person's undo and an agent's undo on one
|
|
14
|
+
* replica each take back only their own steps, and keep the other's like another replica's.
|
|
15
|
+
*/
|
|
16
|
+
export type UndoScope = 'person' | 'agent';
|
|
17
|
+
/** The scope of a transaction of `kind`; `null` for `import` and `system`, which are no undo step. */
|
|
18
|
+
export declare function undoScopeOf(kind: OriginKind): UndoScope | null;
|
|
19
|
+
export declare const person: (principal: string, label?: string) => Origin;
|
|
20
|
+
export declare const agent: (principal: string, label?: string) => Origin;
|
|
21
|
+
export declare const system: (label: string) => Origin;
|
|
22
|
+
/** The commit message form, identical to the Rust encoding: a JSON array `[kind, principal, label]`. */
|
|
23
|
+
export declare function encodeOrigin(origin: Origin): string;
|
|
24
|
+
/** Checks an origin given at run time: one of the five kinds, a string principal, and an optional string label. */
|
|
25
|
+
export declare function checkOrigin(origin: unknown): asserts origin is Origin;
|
|
26
|
+
/**
|
|
27
|
+
* The commit message of every transaction (standard 2.0 rule M5a): its origin and the schema version
|
|
28
|
+
* of the replica that made it, a JSON array `[kind, principal, label, schemaVersion]`, identical to
|
|
29
|
+
* the Rust encoding. `decodeOrigin` reads it too (it reads the first three elements); a message
|
|
30
|
+
* written before rule M5a has no fourth element.
|
|
31
|
+
*/
|
|
32
|
+
export declare function encodeCommit(origin: Origin, schemaVersion: number): string;
|
|
33
|
+
/**
|
|
34
|
+
* A commit message's origin and author schema version (`null` when the message predates rule
|
|
35
|
+
* M5a or names none), or `null` when the message is not a KDM commit message.
|
|
36
|
+
*/
|
|
37
|
+
export declare function decodeCommit(text: string): {
|
|
38
|
+
origin: Origin;
|
|
39
|
+
schemaVersion: number | null;
|
|
40
|
+
} | null;
|
|
41
|
+
export declare function decodeOrigin(text: string): Origin | null;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pending effects of one transaction. `Tx` validates every operation against the committed
|
|
3
|
+
* document plus this overlay, so a transaction sees its own earlier operations while nothing is
|
|
4
|
+
* written to the engine until it succeeds.
|
|
5
|
+
*
|
|
6
|
+
* The overlay never copies a whole container, with one exception: a list keeps its length and its
|
|
7
|
+
* pending edits, a text its UTF-16 length and its pending edits (and reads the committed text once
|
|
8
|
+
* when a transaction checks more positions in it than the engine answers cheaply), a tree the
|
|
9
|
+
* parents of the nodes this transaction created or moved. The engine is asked for the rest.
|
|
10
|
+
*/
|
|
11
|
+
import type { LoroText, LoroTree, TreeID } from '../../loro-crdt.js';
|
|
12
|
+
import type { ObjectId } from './ids.js';
|
|
13
|
+
/** A tree node as a transaction sees it, tagged: `c:<TreeID>` for a node in the document, `p:<n>` for its n-th created node. */
|
|
14
|
+
export type NodeKey = `c:${string}` | `p:${number}`;
|
|
15
|
+
export declare const committedKey: (id: string) => NodeKey;
|
|
16
|
+
export declare const pendingKey: (index: number) => NodeKey;
|
|
17
|
+
export declare const pendingIndex: (key: NodeKey) => number | null;
|
|
18
|
+
export declare const treeId: (key: NodeKey) => TreeID;
|
|
19
|
+
/**
|
|
20
|
+
* A text as a transaction sees it: the committed text (`null`: empty), its pending length, and
|
|
21
|
+
* the pending edits, kept as a sequence of pieces of the committed text and of inserted strings.
|
|
22
|
+
* The sequence is a gap buffer: the pieces before a cursor in order, and those after it in
|
|
23
|
+
* reverse, so that edits at nearby positions (a sorted list of edits, or typing) cost amortised
|
|
24
|
+
* constant time, and moving the cursor costs the pieces it passes.
|
|
25
|
+
*/
|
|
26
|
+
export declare class TextState {
|
|
27
|
+
readonly committed: LoroText | null;
|
|
28
|
+
len: number;
|
|
29
|
+
/** The pieces before the cursor, in order, and their total length (the cursor's position). */
|
|
30
|
+
private readonly before;
|
|
31
|
+
private beforeLength;
|
|
32
|
+
/** The pieces after the cursor, last first: the piece right after the cursor is the last element. */
|
|
33
|
+
private readonly after;
|
|
34
|
+
/** The committed text, once read. */
|
|
35
|
+
private committedString;
|
|
36
|
+
private engineChecks;
|
|
37
|
+
constructor(committed: LoroText | null, len: number);
|
|
38
|
+
/**
|
|
39
|
+
* Whether `position` falls between the two halves of a surrogate pair. Every stored string is
|
|
40
|
+
* well formed, so that is when the code unit at `position` is a low surrogate, in an inserted
|
|
41
|
+
* string or in the committed text.
|
|
42
|
+
*/
|
|
43
|
+
splits(position: number): boolean;
|
|
44
|
+
/** Inserts `content` (well formed) at `index`. */
|
|
45
|
+
insert(index: number, content: string): void;
|
|
46
|
+
/** Deletes `count` code units from `index`. */
|
|
47
|
+
delete(index: number, count: number): void;
|
|
48
|
+
/** The text with the pending edits applied. */
|
|
49
|
+
text(): string;
|
|
50
|
+
private committedText;
|
|
51
|
+
/** Whether position `at` of the committed text falls inside a surrogate pair. */
|
|
52
|
+
private committedSplits;
|
|
53
|
+
/**
|
|
54
|
+
* Moves the cursor to the start of the piece holding `position` (`position` < `len`), or to the
|
|
55
|
+
* end when `position` is the length.
|
|
56
|
+
*/
|
|
57
|
+
private seek;
|
|
58
|
+
/** Moves the cursor to `position`, splitting the piece there if `position` falls inside it. */
|
|
59
|
+
private cut;
|
|
60
|
+
}
|
|
61
|
+
/** One pending change of a list, with the same index meaning as the engine's operation (`move` leaves the item at `to`). */
|
|
62
|
+
type ListEdit = {
|
|
63
|
+
insert: number;
|
|
64
|
+
item: ObjectId;
|
|
65
|
+
} | {
|
|
66
|
+
move: number;
|
|
67
|
+
to: number;
|
|
68
|
+
} | {
|
|
69
|
+
remove: number;
|
|
70
|
+
};
|
|
71
|
+
/** A list as a transaction sees it: its length (the engine's on first touch plus pending edits) and the edits, replayed only when the items are read. */
|
|
72
|
+
export declare class ListState {
|
|
73
|
+
len: number;
|
|
74
|
+
readonly edits: ListEdit[];
|
|
75
|
+
constructor(len: number);
|
|
76
|
+
replay(items: ObjectId[]): ObjectId[];
|
|
77
|
+
}
|
|
78
|
+
/** A tree as a transaction sees it: the engine's tree (`null` for a new one) plus the parents of the nodes this transaction created or moved. */
|
|
79
|
+
export declare class TreeState {
|
|
80
|
+
readonly committed: LoroTree | null;
|
|
81
|
+
/** `null` as a value: the node is a root. */
|
|
82
|
+
readonly parents: Map<NodeKey, NodeKey | null>;
|
|
83
|
+
/** Nodes this transaction deleted (M10b). */
|
|
84
|
+
readonly deleted: Set<NodeKey>;
|
|
85
|
+
constructor(committed: LoroTree | null);
|
|
86
|
+
/** The node's parent (`null`: a root), or `undefined` if the tree has no such live node. */
|
|
87
|
+
parent(node: NodeKey): NodeKey | null | undefined;
|
|
88
|
+
contains(node: NodeKey): boolean;
|
|
89
|
+
/** Whether making `parent` the parent of `node` makes `node` its own ancestor. A looping chain (a corrupt tree) counts as a cycle. */
|
|
90
|
+
wouldCycle(node: NodeKey, parent: NodeKey): boolean;
|
|
91
|
+
}
|
|
92
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type LoadedObject } from './batch.js';
|
|
2
|
+
import type { Replica } from './replica.js';
|
|
3
|
+
import { type Schema } from './schema.js';
|
|
4
|
+
export interface ProjectedObject {
|
|
5
|
+
id: string;
|
|
6
|
+
type: string;
|
|
7
|
+
fields: Record<string, unknown>;
|
|
8
|
+
at?: {
|
|
9
|
+
parent: string;
|
|
10
|
+
field: string;
|
|
11
|
+
index?: number;
|
|
12
|
+
node?: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export declare const hasProjections: (schema: Schema) => boolean;
|
|
16
|
+
/** A computed read view; never writes to the replica. */
|
|
17
|
+
export declare class ProjectionView {
|
|
18
|
+
readonly state: {
|
|
19
|
+
objects: Record<string, Record<string, unknown>>;
|
|
20
|
+
};
|
|
21
|
+
readonly objects: Map<string, ProjectedObject>;
|
|
22
|
+
constructor(replica: Replica, projected: ProjectedObject[]);
|
|
23
|
+
load(root: string | null, target: string, fields?: unknown): LoadedObject;
|
|
24
|
+
}
|
|
25
|
+
export declare function routeProjection(schema: Schema, view: ProjectionView, root: string, operation: Record<string, unknown>): {
|
|
26
|
+
command: string;
|
|
27
|
+
params: Record<string, unknown>;
|
|
28
|
+
creates?: string;
|
|
29
|
+
} | undefined;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/** Reads shared by `Replica` and `Tx`, mirroring the Rust crate's `read` module. */
|
|
2
|
+
import type { LoroDoc, LoroMap, LoroMovableList, LoroText, LoroTree, LoroTreeNode } from '../../loro-crdt.js';
|
|
3
|
+
import { type KdmError } from './errors.js';
|
|
4
|
+
import type { ObjectId } from './ids.js';
|
|
5
|
+
import { type TextRun } from './marks.js';
|
|
6
|
+
import { type FieldKind, type Schema } from './schema.js';
|
|
7
|
+
export declare const META = "meta";
|
|
8
|
+
export declare const OBJECTS = "objects";
|
|
9
|
+
export declare const TYPE_KEY = "$type";
|
|
10
|
+
export declare const NODE_OBJECT = "object";
|
|
11
|
+
/** The register a document's creation writes its schema version to; a raise rewrites it too. */
|
|
12
|
+
export declare const SCHEMA_VERSION = "schemaVersion";
|
|
13
|
+
/**
|
|
14
|
+
* The root map whose keys are the schema versions transactions raised the document to (rule
|
|
15
|
+
* M20). Concurrent raises all keep their key, so the largest one wins whatever the register says.
|
|
16
|
+
* A root map, not one inside `meta`: replicas that each created a nested map concurrently would
|
|
17
|
+
* keep only one of them.
|
|
18
|
+
*/
|
|
19
|
+
export declare const SCHEMA_RAISES = "schemaRaises";
|
|
20
|
+
/**
|
|
21
|
+
* The root map whose `root` key records a document's birth: the version its first state is at, as
|
|
22
|
+
* `Replica.copyAsNewDocument` makes it (data model, "A copy is a new document"). Only its value in a
|
|
23
|
+
* shallow replica's state at its root counts (`Replica.carriesWholeHistory`). A root map, not a key
|
|
24
|
+
* of `meta`, so the canonical state (`meta` included) stays the source's.
|
|
25
|
+
*/
|
|
26
|
+
export declare const BIRTH = "birth";
|
|
27
|
+
/** The key of `BIRTH` that holds the encoded version. */
|
|
28
|
+
export declare const BIRTH_ROOT = "root";
|
|
29
|
+
/**
|
|
30
|
+
* The document's minimum schema version (rule M20): the largest of `meta.schemaVersion` and the
|
|
31
|
+
* keys of the `schemaRaises` map. `null` when `meta.schemaVersion` is not a non-negative integer.
|
|
32
|
+
*/
|
|
33
|
+
export declare function minSchemaVersion(doc: LoroDoc): number | null;
|
|
34
|
+
/** The engine container class each container kind is stored as. */
|
|
35
|
+
export declare const CONTAINER_CLASS: {
|
|
36
|
+
readonly text: typeof LoroText;
|
|
37
|
+
readonly list: typeof LoroMovableList;
|
|
38
|
+
readonly tree: typeof LoroTree;
|
|
39
|
+
readonly map: typeof LoroMap;
|
|
40
|
+
};
|
|
41
|
+
export type ContainerKind = keyof typeof CONTAINER_CLASS;
|
|
42
|
+
type ContainerOf<K extends ContainerKind> = InstanceType<(typeof CONTAINER_CLASS)[K]>;
|
|
43
|
+
export declare function objectMap(doc: LoroDoc, id: ObjectId): LoroMap;
|
|
44
|
+
export declare function typeOf(map: LoroMap, id: ObjectId): string;
|
|
45
|
+
export declare const objectType: (doc: LoroDoc, id: ObjectId) => string;
|
|
46
|
+
export declare const wrongContainer: (id: ObjectId, field: string) => KdmError;
|
|
47
|
+
/** The error for using a field as a kind it is not. */
|
|
48
|
+
export declare const wrongKind: (ty: string, field: string, kind: FieldKind) => KdmError;
|
|
49
|
+
/** `value` as a container of `kind`, `null` for a missing field, or the wrong-container error. */
|
|
50
|
+
export declare function asContainer<K extends ContainerKind>(value: unknown, kind: K, id: ObjectId, field: string): ContainerOf<K> | null;
|
|
51
|
+
/**
|
|
52
|
+
* A container field of an object, checked against the schema. `null` when the stored object lacks
|
|
53
|
+
* the field: it was written under an older schema version, and the field reads as empty.
|
|
54
|
+
*/
|
|
55
|
+
export declare function container<K extends ContainerKind>(doc: LoroDoc, schema: Schema, id: ObjectId, field: string, kind: K): ContainerOf<K> | null;
|
|
56
|
+
/** A text field's runs (`TextRun`): one unmarked run for a field that declares no marks. */
|
|
57
|
+
export declare function textRuns(doc: LoroDoc, schema: Schema, id: ObjectId, field: string): TextRun[];
|
|
58
|
+
/** A register field's value in canonical form, or `null`. */
|
|
59
|
+
export declare function register(doc: LoroDoc, schema: Schema, id: ObjectId, field: string): unknown;
|
|
60
|
+
/** A value read from the engine in canonical form; a missing value or a container reads as `null`. */
|
|
61
|
+
export declare const storedValue: (value: unknown) => unknown;
|
|
62
|
+
/** A map field's keys and values as `storedValue` reads them, sorted by key in code point order. */
|
|
63
|
+
export declare function mapEntries(map: LoroMap): Array<[string, unknown]>;
|
|
64
|
+
/** Ids of the objects of type `ty`, sorted. One pass over every object of the document. */
|
|
65
|
+
export declare function checkProjectedStorage(doc: LoroDoc, schema: Schema): void;
|
|
66
|
+
export declare function objectsOfType(doc: LoroDoc, ty: string): ObjectId[];
|
|
67
|
+
/**
|
|
68
|
+
* A list's items. Every item of a KDM list is an object id; anything else was written outside the
|
|
69
|
+
* KDM and is an `encoding` error, so indices never disagree with the engine's.
|
|
70
|
+
*/
|
|
71
|
+
export declare function listItems(items: unknown[]): ObjectId[];
|
|
72
|
+
/** The object a tree node names, or `null` for a node without one; tree reads skip it with its subtree. */
|
|
73
|
+
export declare function nodeObject(node: LoroTreeNode): ObjectId | null;
|
|
74
|
+
export declare function objectIds(doc: LoroDoc): ObjectId[];
|
|
75
|
+
/**
|
|
76
|
+
* One object in canonical form by per-field reads, as the Rust `object_json`: for the rare
|
|
77
|
+
* objects the engine's deep JSON cannot represent (an id or a field named `__proto__`).
|
|
78
|
+
*/
|
|
79
|
+
export declare function objectJson(doc: LoroDoc, schema: Schema, id: ObjectId): Record<string, unknown>;
|
|
80
|
+
/**
|
|
81
|
+
* The whole document in canonical form, from one engine read rather than one per field. An
|
|
82
|
+
* object of a type the schema does not declare reads as its `$type` only; a field the stored
|
|
83
|
+
* object lacks reads as empty (`null`, `""`, `[]`, `{}`). Only `canonicalText` of it is the
|
|
84
|
+
* canonical form.
|
|
85
|
+
*
|
|
86
|
+
* Objects are built with their keys already in canonical order, so only the values the engine
|
|
87
|
+
* hands over as objects (JSON registers, map fields, `meta`) go through `canonical`.
|
|
88
|
+
*/
|
|
89
|
+
export declare function stateJson(doc: LoroDoc, schema: Schema): unknown;
|
|
90
|
+
export {};
|