@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,401 @@
|
|
|
1
|
+
import { existsSync as S, readFileSync as g, readdirSync as q } from "node:fs";
|
|
2
|
+
import { relative as b, resolve as w, sep as P, dirname as D, join as k } from "node:path";
|
|
3
|
+
import { pathToFileURL as $ } from "node:url";
|
|
4
|
+
import "./kits/index.js";
|
|
5
|
+
import { M as T, o as C, p as O } from "../chunks/document-B5MMuYyN.js";
|
|
6
|
+
import { E as oe, e as ce, i as ae, k as de, a as le } from "../chunks/document-B5MMuYyN.js";
|
|
7
|
+
import { spawn as j, execFile as L } from "node:child_process";
|
|
8
|
+
import { createInterface as N } from "node:readline";
|
|
9
|
+
import { s as A, B } from "../chunks/batch-CAGYk6m4.js";
|
|
10
|
+
import { O as he } from "../chunks/batch-CAGYk6m4.js";
|
|
11
|
+
import "../chunks/envelope-GX4Cynkx.js";
|
|
12
|
+
import { p as M } from "../chunks/replica-Di2iCPiD.js";
|
|
13
|
+
import { k as K } from "../chunks/kits-Cp51mDlw.js";
|
|
14
|
+
import { r as fe } from "../chunks/kits-Cp51mDlw.js";
|
|
15
|
+
import { CAPABILITY_SETS as we, RoomDocument as ke, advertiseCapabilitySets as ve, capabilitySets as ye, createRoom as ge, openRoom as xe, supports as Ee, syncEndpoint as Ie, webSocketTransport as Se } from "./index.js";
|
|
16
|
+
import { NotSyncedError as Pe, PropertyNotLoadedError as qe, RequestContext as De } from "./proxy.js";
|
|
17
|
+
const E = 1;
|
|
18
|
+
class x extends Error {
|
|
19
|
+
constructor(e, t, r) {
|
|
20
|
+
super(r?.detail ? `${t}: ${r.detail}` : t), this.code = e, this.data = r, this.name = "KitProtocolError";
|
|
21
|
+
}
|
|
22
|
+
get reason() {
|
|
23
|
+
return this.data?.reason;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
class R {
|
|
27
|
+
constructor(e, t) {
|
|
28
|
+
this.output = t, N({ input: e }).on("line", (r) => this.message(r)), e.on("error", (r) => this.fail(r)), e.on("close", () => this.fail(new Error("kition-kits closed the connection")));
|
|
29
|
+
}
|
|
30
|
+
next = 1;
|
|
31
|
+
pending = /* @__PURE__ */ new Map();
|
|
32
|
+
closedWith = null;
|
|
33
|
+
/** Sends a request; answers its `result`, or throws its `error` as a `KitProtocolError`. */
|
|
34
|
+
request(e, t = {}) {
|
|
35
|
+
if (this.closedWith) return Promise.reject(this.closedWith);
|
|
36
|
+
const r = this.next++;
|
|
37
|
+
return new Promise((s, c) => {
|
|
38
|
+
this.pending.set(r, { resolve: s, reject: c }), this.output.write(`${JSON.stringify({ jsonrpc: "2.0", id: r, method: e, params: t })}
|
|
39
|
+
`);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/** Ends the connection: the service shuts its kits down and exits. */
|
|
43
|
+
close() {
|
|
44
|
+
this.output.end(), this.fail(new Error("the connection is closed"));
|
|
45
|
+
}
|
|
46
|
+
message(e) {
|
|
47
|
+
let t;
|
|
48
|
+
try {
|
|
49
|
+
t = JSON.parse(e);
|
|
50
|
+
} catch {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const r = typeof t.id == "number" ? this.pending.get(t.id) : void 0;
|
|
54
|
+
!r || typeof t.id != "number" || (this.pending.delete(t.id), t.error ? r.reject(new x(t.error.code, t.error.message, t.error.data)) : r.resolve(t.result));
|
|
55
|
+
}
|
|
56
|
+
fail(e) {
|
|
57
|
+
this.closedWith || (this.closedWith = e);
|
|
58
|
+
for (const t of this.pending.values()) t.reject(e);
|
|
59
|
+
this.pending.clear();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
class y {
|
|
63
|
+
constructor(e, t, r, s) {
|
|
64
|
+
this.connection = e, this.workspace = t, this.kits = r, this.child = s;
|
|
65
|
+
}
|
|
66
|
+
/** Starts `kition-kits serve` on `options.workspace` and initializes it. */
|
|
67
|
+
static async launch(e) {
|
|
68
|
+
const t = w(e.workspace), r = ["serve", "--workspace", t];
|
|
69
|
+
e.kitsDir && r.push("--kits-dir", w(e.kitsDir));
|
|
70
|
+
for (const n of e.kits ?? []) r.push("--kit", w(n));
|
|
71
|
+
const s = e.executable ?? process.env.KITION_KITS ?? "kition-kits", c = j(s, r, { env: { ...process.env, ...e.env }, stdio: ["pipe", "pipe", e.stderr ?? "ignore"] }), d = new Promise((n) => {
|
|
72
|
+
c.once("error", (l) => n(new Error(`cannot start ${s}: ${l.message}`))), c.once("exit", (l) => n(new Error(`${s} exited (${l}) before it answered`)));
|
|
73
|
+
}), o = new R(c.stdout, c.stdin);
|
|
74
|
+
try {
|
|
75
|
+
return await Promise.race([y.connect(o, t, c), d.then((n) => Promise.reject(n))]);
|
|
76
|
+
} catch (n) {
|
|
77
|
+
const l = await Promise.race([d, new Promise((h) => setTimeout(() => h(null), 2e3))]);
|
|
78
|
+
throw c.kill(), l ?? n;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** Initializes a service over an existing connection (tests, or one another process started). */
|
|
82
|
+
static async connect(e, t, r = null) {
|
|
83
|
+
const s = await e.request("kits.initialize", { client: { name: "@kition/script", version: "0" } });
|
|
84
|
+
if (s.serviceVersion !== E)
|
|
85
|
+
throw e.close(), new Error(`kition-kits speaks Kits Service API ${s.serviceVersion}; this client speaks ${E}`);
|
|
86
|
+
return new y(e, w(t), s.kits, r);
|
|
87
|
+
}
|
|
88
|
+
/** The workspace path of `path` (absolute, or already relative to the workspace). */
|
|
89
|
+
relative(e) {
|
|
90
|
+
return b(this.workspace, w(this.workspace, e)).split(P).join("/");
|
|
91
|
+
}
|
|
92
|
+
/** Opens the workspace file `path` in the kit that handles its extension. */
|
|
93
|
+
async open(e) {
|
|
94
|
+
const t = await this.connection.request("documents.open", { path: this.relative(e) });
|
|
95
|
+
return new I(this, t);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* A new document at `path`, saved so the file exists. A new file never replaces one: when
|
|
99
|
+
* `path` exists, the next free name (`Title 2.kslide`) is used; the document's `state.path` says.
|
|
100
|
+
*/
|
|
101
|
+
async create(e, t = {}) {
|
|
102
|
+
const r = await this.connection.request("documents.create", { path: this.relative(e), options: t.options ?? {} });
|
|
103
|
+
return new I(this, r);
|
|
104
|
+
}
|
|
105
|
+
/** Ends the service, which shuts its kits down (documents close unsaved), and waits for it. */
|
|
106
|
+
async shutdown() {
|
|
107
|
+
this.connection.close();
|
|
108
|
+
const e = this.child;
|
|
109
|
+
if (e && e.exitCode === null && e.signalCode === null) {
|
|
110
|
+
const t = new Promise((s) => e.once("exit", () => s())), r = setTimeout(() => e.kill(), 1e4);
|
|
111
|
+
await t, clearTimeout(r);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
class I {
|
|
116
|
+
constructor(e, t) {
|
|
117
|
+
this.service = e, this.current = t;
|
|
118
|
+
}
|
|
119
|
+
savedListeners = /* @__PURE__ */ new Set();
|
|
120
|
+
conflictListeners = /* @__PURE__ */ new Set();
|
|
121
|
+
get id() {
|
|
122
|
+
return this.current.documentId;
|
|
123
|
+
}
|
|
124
|
+
get kitId() {
|
|
125
|
+
return this.current.kitId;
|
|
126
|
+
}
|
|
127
|
+
/** The document's state as the service last answered it. */
|
|
128
|
+
get state() {
|
|
129
|
+
return this.current;
|
|
130
|
+
}
|
|
131
|
+
/** Asks the service for the document's state again. */
|
|
132
|
+
async refresh() {
|
|
133
|
+
return this.current = await this.request("documents.get"), this.current;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The object model over this document, served by the kit (`model.describe`, `model.batch`).
|
|
137
|
+
* The schema is the one registered for the kit (`@kition/sdk/script/kits/*`), else the kit's own
|
|
138
|
+
* (`model.describe`).
|
|
139
|
+
*/
|
|
140
|
+
async model(e = {}) {
|
|
141
|
+
const t = e.schema ?? K(this.kitId)?.schema, r = t ? M(t) : A(await this.request("model.describe"));
|
|
142
|
+
return new T(W(this, r), e.origin);
|
|
143
|
+
}
|
|
144
|
+
/** `commands.list` for this document. */
|
|
145
|
+
async commands() {
|
|
146
|
+
return (await this.request("commands.list")).commands;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Runs a command outside the object model: as the host's person (`user`), the agent, or the
|
|
150
|
+
* host itself on the person's behalf (`system`, by the host feature `originLabel`, `emailsync`).
|
|
151
|
+
* A `system` change is no undo step: neither the person's undo nor an agent's takes it back.
|
|
152
|
+
*/
|
|
153
|
+
async execute(e, t = {}, r = "user", s) {
|
|
154
|
+
const c = await this.request("commands.execute", {
|
|
155
|
+
command: e,
|
|
156
|
+
params: t,
|
|
157
|
+
origin: r,
|
|
158
|
+
...s ? { originLabel: s } : {}
|
|
159
|
+
});
|
|
160
|
+
return this.current = c.document, c.result;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Writes the document to its file. The save commits only while the file is the version the
|
|
164
|
+
* kit read: a file changed meanwhile is a `KitProtocolError` with reason `file_conflict`.
|
|
165
|
+
*/
|
|
166
|
+
async save() {
|
|
167
|
+
try {
|
|
168
|
+
this.current = await this.request("documents.save");
|
|
169
|
+
} catch (e) {
|
|
170
|
+
if (e instanceof x && e.reason === "file_conflict") for (const t of [...this.conflictListeners]) t({ message: e.message });
|
|
171
|
+
throw e;
|
|
172
|
+
}
|
|
173
|
+
this.saved();
|
|
174
|
+
}
|
|
175
|
+
/** Writes it to the workspace file `path`, in `format` or the file's; the document then lives there. */
|
|
176
|
+
async saveAs(e, t) {
|
|
177
|
+
this.current = await this.request("documents.saveAs", { path: b(this.service.workspace, w(this.service.workspace, e)).split(P).join("/"), ...t ? { format: t } : {} }), this.saved();
|
|
178
|
+
}
|
|
179
|
+
/** Reads the file again, dropping unsaved edits: resolves a conflict in favour of the file. */
|
|
180
|
+
async reload() {
|
|
181
|
+
this.current = await this.request("documents.reload");
|
|
182
|
+
}
|
|
183
|
+
async close(e = !1) {
|
|
184
|
+
await this.request("documents.close", { discardChanges: e });
|
|
185
|
+
}
|
|
186
|
+
/** Hears this document's saves made through this handle. */
|
|
187
|
+
onSaved(e) {
|
|
188
|
+
return this.savedListeners.add(e), () => {
|
|
189
|
+
this.savedListeners.delete(e);
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
/** Hears this handle's saves refused because the file changed since the kit read it. */
|
|
193
|
+
onConflict(e) {
|
|
194
|
+
return this.conflictListeners.add(e), () => {
|
|
195
|
+
this.conflictListeners.delete(e);
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
saved() {
|
|
199
|
+
for (const e of [...this.savedListeners]) e({ version: null, ...this.current.path ? { uri: this.current.path } : {} });
|
|
200
|
+
}
|
|
201
|
+
request(e, t = {}) {
|
|
202
|
+
return this.service.connection.request(e, { kit: this.kitId, documentId: this.id, ...t });
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function W(i, e) {
|
|
206
|
+
const t = async (r, s) => {
|
|
207
|
+
try {
|
|
208
|
+
return await i.request(r, s);
|
|
209
|
+
} catch (c) {
|
|
210
|
+
const d = c instanceof x ? c.data?.model : void 0;
|
|
211
|
+
throw d ? new B(d.code, d.index, d.message) : c;
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
return {
|
|
215
|
+
kitId: i.kitId,
|
|
216
|
+
schema: e,
|
|
217
|
+
batch: async (r) => {
|
|
218
|
+
const s = await t("model.batch", r);
|
|
219
|
+
return (r.ops?.length ?? 0) > 0 && await i.refresh(), s;
|
|
220
|
+
},
|
|
221
|
+
describe: () => t("model.describe", {}),
|
|
222
|
+
commands: () => i.commands(),
|
|
223
|
+
version: () => null,
|
|
224
|
+
// Saves through this handle (`uri` is the file's workspace path), and saves refused because
|
|
225
|
+
// the file changed meanwhile.
|
|
226
|
+
events: ["saved", "conflict"],
|
|
227
|
+
on: (r, s) => r === "saved" ? i.onSaved(s) : r === "conflict" ? i.onConflict(s) : () => {
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
async function ee(i, e, t = {}) {
|
|
232
|
+
const r = w(e), s = await y.launch({ ...t, kits: [i], workspace: t.workspace ?? D(r) });
|
|
233
|
+
try {
|
|
234
|
+
const c = S(r) ? await s.open(r) : await s.create(r, t.create);
|
|
235
|
+
return Object.assign(c, { shutdown: () => s.shutdown() });
|
|
236
|
+
} catch (c) {
|
|
237
|
+
throw await s.shutdown(), c;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function te() {
|
|
241
|
+
const i = [], e = [], t = /* @__PURE__ */ new Map();
|
|
242
|
+
let r = 0, s = -1 / 0, c = !1;
|
|
243
|
+
const d = (o) => {
|
|
244
|
+
const n = e.shift();
|
|
245
|
+
n ? n(o) : i.push(o);
|
|
246
|
+
};
|
|
247
|
+
return {
|
|
248
|
+
request: (o, n) => {
|
|
249
|
+
if (c) return Promise.reject(new Error("the agent relay is closed"));
|
|
250
|
+
if (o.id === void 0 || o.id === null)
|
|
251
|
+
return d(o), Promise.resolve(null);
|
|
252
|
+
r += 1;
|
|
253
|
+
const l = r;
|
|
254
|
+
return new Promise((h, a) => {
|
|
255
|
+
const u = setTimeout(() => {
|
|
256
|
+
t.delete(l);
|
|
257
|
+
const p = i.findIndex((f) => f.id === l);
|
|
258
|
+
p >= 0 && i.splice(p, 1), a(new Error(`no page answered ${o.method ?? "the request"} in time: is the document open in the page?`));
|
|
259
|
+
}, n?.timeoutMs ?? 6e4);
|
|
260
|
+
t.set(l, { id: o.id, resolve: h, reject: a, timer: u }), d({ ...o, id: l });
|
|
261
|
+
});
|
|
262
|
+
},
|
|
263
|
+
next: (o) => {
|
|
264
|
+
s = Date.now();
|
|
265
|
+
const n = o?.signal;
|
|
266
|
+
if (c || n?.aborted) return Promise.resolve(null);
|
|
267
|
+
const l = i.shift();
|
|
268
|
+
return l ? Promise.resolve(l) : new Promise((h) => {
|
|
269
|
+
const a = () => {
|
|
270
|
+
clearTimeout(f), n?.removeEventListener("abort", p);
|
|
271
|
+
const m = e.indexOf(u);
|
|
272
|
+
m >= 0 && e.splice(m, 1);
|
|
273
|
+
}, u = (m) => {
|
|
274
|
+
a(), m && n?.aborted ? (i.unshift(m), h(null)) : h(m);
|
|
275
|
+
}, p = () => {
|
|
276
|
+
a(), h(null);
|
|
277
|
+
}, f = setTimeout(() => {
|
|
278
|
+
a(), s = Date.now(), h(null);
|
|
279
|
+
}, o?.waitMs ?? 25e3);
|
|
280
|
+
n?.addEventListener("abort", p, { once: !0 }), e.push(u);
|
|
281
|
+
});
|
|
282
|
+
},
|
|
283
|
+
reply: (o) => {
|
|
284
|
+
const n = typeof o.id == "number" ? t.get(o.id) : void 0;
|
|
285
|
+
n && (t.delete(o.id), clearTimeout(n.timer), n.resolve({ ...o, id: n.id }));
|
|
286
|
+
},
|
|
287
|
+
connected: (o = 3e4) => e.length > 0 || Date.now() - s < o,
|
|
288
|
+
close: () => {
|
|
289
|
+
c = !0;
|
|
290
|
+
for (const o of e.splice(0)) o(null);
|
|
291
|
+
for (const { reject: o, timer: n } of t.values())
|
|
292
|
+
clearTimeout(n), o(new Error("the agent relay is closed"));
|
|
293
|
+
t.clear(), i.length = 0;
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
class J extends Error {
|
|
298
|
+
constructor(e, t) {
|
|
299
|
+
super(t), this.code = e, this.name = "DraftCommandError";
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
function re(i) {
|
|
303
|
+
const e = ["--workspace", i.workspace];
|
|
304
|
+
for (const [r, s] of Object.entries(i.kits ?? {})) e.push("--kit", `${r}=${s}`);
|
|
305
|
+
i.kitsDir && e.push("--kits-dir", i.kitsDir);
|
|
306
|
+
const t = (r) => new Promise((s, c) => {
|
|
307
|
+
L(i.server, [...i.serverArgs ?? [], "drafts", ...r, ...e], { env: i.env ?? process.env, maxBuffer: 64 * 1024 * 1024 }, (d, o) => {
|
|
308
|
+
let n;
|
|
309
|
+
try {
|
|
310
|
+
n = JSON.parse(o);
|
|
311
|
+
} catch {
|
|
312
|
+
c(d ?? new Error(`kition-kits-mcp drafts printed no JSON: ${o.slice(0, 200)}`));
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
n?.error ? c(new J(n.error.code ?? "failed", n.error.message ?? "refused")) : d ? c(d) : s(n);
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
return {
|
|
319
|
+
list: async () => (await t(["list"])).drafts,
|
|
320
|
+
compare: async (r, s) => await t(["compare", r, ...s?.previews ? ["--previews"] : []]),
|
|
321
|
+
merge: async (r, s) => await t(["merge", r, ...s?.overwrite ? ["--overwrite"] : []]),
|
|
322
|
+
discard: async (r) => await t(["discard", r])
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
async function se(i) {
|
|
326
|
+
const e = JSON.parse(g(k(i, "kit-ui.json"), "utf8")), t = k(i, "model", "schema.json"), r = S(t) ? JSON.parse(g(t, "utf8")) : void 0;
|
|
327
|
+
if (r && r.kit !== e.kitId) throw new Error(`${t} is the schema of ${String(r.kit)}, not of ${e.kitId}`);
|
|
328
|
+
const s = k(i, "engine"), c = q(s), d = c.find((a) => a.endsWith(".js") && !a.endsWith(".worker.js")), o = c.find((a) => a.endsWith("_bg.wasm"));
|
|
329
|
+
if (!d || !o) throw new Error(`${s} holds no engine (a wasm-bindgen module and its .wasm)`);
|
|
330
|
+
const n = await import($(k(s, d)).href);
|
|
331
|
+
n.initSync({ module: g(k(s, o)) });
|
|
332
|
+
const l = Object.values(n).find(
|
|
333
|
+
(a) => typeof a == "function" && typeof a.open == "function" && "exportChanges" in (a.prototype ?? {})
|
|
334
|
+
);
|
|
335
|
+
if (!l) throw new Error(`${d} exports no contract 2 engine class`);
|
|
336
|
+
const h = (a) => {
|
|
337
|
+
const u = /* @__PURE__ */ new Set(), p = (f, m) => {
|
|
338
|
+
if (f !== "saved") return () => {
|
|
339
|
+
};
|
|
340
|
+
const v = m;
|
|
341
|
+
return u.add(v), () => {
|
|
342
|
+
u.delete(v);
|
|
343
|
+
};
|
|
344
|
+
};
|
|
345
|
+
return {
|
|
346
|
+
kitId: e.kitId,
|
|
347
|
+
engine: a,
|
|
348
|
+
model: (f) => C(O(a, e.kitId, { events: ["saved"], on: p }), { kit: e.kitId, ...r ? { schema: r } : {}, ...f }),
|
|
349
|
+
save: (f) => {
|
|
350
|
+
const m = a.save(f);
|
|
351
|
+
a.markSaved();
|
|
352
|
+
for (const v of [...u]) v({ version: null });
|
|
353
|
+
return m;
|
|
354
|
+
},
|
|
355
|
+
close: () => a.free?.()
|
|
356
|
+
};
|
|
357
|
+
};
|
|
358
|
+
return {
|
|
359
|
+
kitId: e.kitId,
|
|
360
|
+
version: e.version,
|
|
361
|
+
...r ? { schema: r } : {},
|
|
362
|
+
open: (a, u) => h(l.open(a, u)),
|
|
363
|
+
create: (a, u = { width: 960, height: 540 }) => h(l.create(a, u.width, u.height))
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
export {
|
|
367
|
+
B as BatchError,
|
|
368
|
+
we as CAPABILITY_SETS,
|
|
369
|
+
J as DraftCommandError,
|
|
370
|
+
oe as Exchange,
|
|
371
|
+
I as HeadlessDocument,
|
|
372
|
+
E as KITS_SERVICE_VERSION,
|
|
373
|
+
R as KitProtocolConnection,
|
|
374
|
+
x as KitProtocolError,
|
|
375
|
+
y as KitsService,
|
|
376
|
+
T as ModelDocument,
|
|
377
|
+
Pe as NotSyncedError,
|
|
378
|
+
he as OBJECT_MODEL_CAPABILITY,
|
|
379
|
+
qe as PropertyNotLoadedError,
|
|
380
|
+
De as RequestContext,
|
|
381
|
+
ke as RoomDocument,
|
|
382
|
+
ve as advertiseCapabilitySets,
|
|
383
|
+
ye as capabilitySets,
|
|
384
|
+
te as createAgentRelay,
|
|
385
|
+
ge as createRoom,
|
|
386
|
+
ce as exchangeBackend,
|
|
387
|
+
ae as isModelPort,
|
|
388
|
+
K as kitDescriptor,
|
|
389
|
+
de as kitModelBackend,
|
|
390
|
+
C as openDocument,
|
|
391
|
+
ee as openHeadless,
|
|
392
|
+
se as openKitPackage,
|
|
393
|
+
xe as openRoom,
|
|
394
|
+
le as portFromConnection,
|
|
395
|
+
O as portFromEngine,
|
|
396
|
+
fe as registerKit,
|
|
397
|
+
Ee as supports,
|
|
398
|
+
Ie as syncEndpoint,
|
|
399
|
+
Se as webSocketTransport,
|
|
400
|
+
re as workspaceDrafts
|
|
401
|
+
};
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
class $ extends Error {
|
|
2
|
+
constructor(t, e) {
|
|
3
|
+
super(`${t}.${e} is not loaded: call load(['${e}']) and await sync() first`), this.name = "PropertyNotLoadedError";
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
class b extends Error {
|
|
7
|
+
constructor(t) {
|
|
8
|
+
super(`${t} is known after the next sync()`), this.name = "NotSyncedError";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const m = Symbol("kition.object"), k = (d) => typeof d == "object" && d !== null && m in d;
|
|
12
|
+
function l(d) {
|
|
13
|
+
return k(d) ? d[m].target : Array.isArray(d) ? d.map(l) : typeof d == "object" && d !== null ? Object.fromEntries(Object.entries(d).map(([t, e]) => [t, l(e)])) : d;
|
|
14
|
+
}
|
|
15
|
+
class j {
|
|
16
|
+
constructor(t, e, c) {
|
|
17
|
+
this.schema = t, this.send = e, this.origin = c, this.root = this.proxy({ target: "root", type: t.root, id: null, fields: /* @__PURE__ */ new Map() }), this.commands = {
|
|
18
|
+
run: (p, n) => {
|
|
19
|
+
let s, r = !1;
|
|
20
|
+
return this.pending.push({
|
|
21
|
+
index: this.ops.length,
|
|
22
|
+
set: (f) => {
|
|
23
|
+
s = f, r = !0;
|
|
24
|
+
}
|
|
25
|
+
}), this.ops.push({ op: "command", id: p, ...n === void 0 ? {} : { params: l(n) } }), {
|
|
26
|
+
get value() {
|
|
27
|
+
if (!r) throw new b(`the result of ${p}`);
|
|
28
|
+
return s;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
ops = [];
|
|
35
|
+
loads = [];
|
|
36
|
+
created = [];
|
|
37
|
+
pending = [];
|
|
38
|
+
proxies = /* @__PURE__ */ new Map();
|
|
39
|
+
refs = 0;
|
|
40
|
+
/** The document's root object. */
|
|
41
|
+
root;
|
|
42
|
+
commands;
|
|
43
|
+
/** A proxy of an existing object of type `type`. */
|
|
44
|
+
object(t, e) {
|
|
45
|
+
const c = this.proxies.get(t);
|
|
46
|
+
if (c) return c;
|
|
47
|
+
if (!this.schema.types[e]) throw new Error(`the kit has no type \`${e}\``);
|
|
48
|
+
const p = this.proxy({ target: t, type: e, id: t, fields: /* @__PURE__ */ new Map() });
|
|
49
|
+
return this.proxies.set(t, p), p;
|
|
50
|
+
}
|
|
51
|
+
/** Whether operations or reads wait for `sync()`. */
|
|
52
|
+
get queued() {
|
|
53
|
+
return this.ops.length > 0 || this.loads.length > 0;
|
|
54
|
+
}
|
|
55
|
+
/** Sends the queued operations and reads as one batch, then fills the loaded proxies. */
|
|
56
|
+
async sync() {
|
|
57
|
+
const t = this.ops, e = this.loads, c = this.created, p = this.pending;
|
|
58
|
+
if (this.ops = [], this.loads = [], this.created = [], this.pending = [], t.length === 0 && e.length === 0) return;
|
|
59
|
+
const n = await this.send({
|
|
60
|
+
...this.origin ? { origin: this.origin } : {},
|
|
61
|
+
ops: t,
|
|
62
|
+
load: e.map(({ state: s, fields: r }) => ({ target: s.target, ...r ? { fields: r } : {} }))
|
|
63
|
+
});
|
|
64
|
+
for (const s of c) {
|
|
65
|
+
const r = n.refs[s.target];
|
|
66
|
+
r !== void 0 && (s.id = r, s.target = r, this.proxies.set(r, this.proxyOf(s)));
|
|
67
|
+
}
|
|
68
|
+
for (const { index: s, set: r } of p) r(n.results[s]);
|
|
69
|
+
e.forEach(({ state: s }, r) => this.fill(s, n.loaded[r]));
|
|
70
|
+
}
|
|
71
|
+
fill(t, e) {
|
|
72
|
+
if (e) {
|
|
73
|
+
t.id = e.id, t.type = e.type, t.target === "root" && this.proxies.set(e.id, this.proxyOf(t));
|
|
74
|
+
for (const [c, p] of Object.entries(e.fields)) t.fields.set(c, p);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
byState = /* @__PURE__ */ new WeakMap();
|
|
78
|
+
proxyOf(t) {
|
|
79
|
+
return this.byState.get(t) ?? this.proxy(t);
|
|
80
|
+
}
|
|
81
|
+
push(t) {
|
|
82
|
+
this.ops.push(t);
|
|
83
|
+
}
|
|
84
|
+
field(t, e) {
|
|
85
|
+
return this.schema.types[t.type]?.fields[e];
|
|
86
|
+
}
|
|
87
|
+
proxy(t) {
|
|
88
|
+
const e = this, c = /* @__PURE__ */ new Map(), p = {
|
|
89
|
+
[m]: t,
|
|
90
|
+
get id() {
|
|
91
|
+
if (t.id === null) throw new b(`the id of a new ${t.type}`);
|
|
92
|
+
return t.id;
|
|
93
|
+
},
|
|
94
|
+
get type() {
|
|
95
|
+
return t.type;
|
|
96
|
+
},
|
|
97
|
+
load(s) {
|
|
98
|
+
return e.loads.push({ state: t, ...s ? { fields: s } : {} }), n;
|
|
99
|
+
},
|
|
100
|
+
delete() {
|
|
101
|
+
e.push({ op: "delete", target: t.target });
|
|
102
|
+
},
|
|
103
|
+
isLoaded(s) {
|
|
104
|
+
return t.fields.has(s);
|
|
105
|
+
},
|
|
106
|
+
toJSON() {
|
|
107
|
+
return { id: t.id, type: t.type, ...Object.fromEntries(t.fields) };
|
|
108
|
+
}
|
|
109
|
+
}, n = new Proxy(p, {
|
|
110
|
+
get(s, r, f) {
|
|
111
|
+
if (typeof r == "symbol" || r in s) return Reflect.get(s, r, f);
|
|
112
|
+
const o = e.field(t, r);
|
|
113
|
+
if (o) {
|
|
114
|
+
if (o.kind === "list" || o.kind === "text" || o.kind === "map" || o.kind === "tree") {
|
|
115
|
+
let u = c.get(r);
|
|
116
|
+
return u || c.set(r, u = e.container(t, r, o, n)), u;
|
|
117
|
+
}
|
|
118
|
+
if (!t.fields.has(r)) throw new $(t.type, r);
|
|
119
|
+
return t.fields.get(r);
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
set(s, r, f) {
|
|
123
|
+
if (typeof r == "symbol") return !1;
|
|
124
|
+
const o = e.field(t, r);
|
|
125
|
+
if (!o) throw new Error(`${t.type} has no field \`${r}\``);
|
|
126
|
+
if (o.kind === "text")
|
|
127
|
+
return e.push({ op: "text.set", target: t.target, field: r, text: String(f) }), !0;
|
|
128
|
+
if (o.kind === "list" || o.kind === "map" || o.kind === "tree") throw new Error(`${t.type}.${r} is a ${o.kind}; use its methods`);
|
|
129
|
+
const u = l(f);
|
|
130
|
+
return e.push({ op: "set", target: t.target, field: r, value: u ?? null }), t.fields.set(r, u ?? null), !0;
|
|
131
|
+
},
|
|
132
|
+
has(s, r) {
|
|
133
|
+
return r in s || typeof r == "string" && e.field(t, r) !== void 0;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
return this.byState.set(t, n), n;
|
|
137
|
+
}
|
|
138
|
+
container(t, e, c, p) {
|
|
139
|
+
const n = this, s = () => {
|
|
140
|
+
if (!t.fields.has(e)) throw new $(t.type, e);
|
|
141
|
+
return t.fields.get(e);
|
|
142
|
+
}, r = () => t.target;
|
|
143
|
+
if (c.kind === "list") {
|
|
144
|
+
const o = c.of ?? "", u = {
|
|
145
|
+
add(a, h) {
|
|
146
|
+
const y = `$${n.refs += 1}`, i = { target: y, type: o, id: null, fields: /* @__PURE__ */ new Map() };
|
|
147
|
+
return n.created.push(i), n.push({ op: "create", type: o, in: `${r()}.${e}`, ref: y, ...a ? { fields: l(a) } : {}, ...h?.at !== void 0 ? { at: h.at } : {} }), n.proxy(i);
|
|
148
|
+
},
|
|
149
|
+
insert(a, h) {
|
|
150
|
+
n.push({ op: "list.insert", target: r(), field: e, index: a, item: typeof h == "string" ? h : l(h) });
|
|
151
|
+
},
|
|
152
|
+
move(a, h) {
|
|
153
|
+
n.push({ op: "list.move", target: r(), field: e, from: a, to: h });
|
|
154
|
+
},
|
|
155
|
+
remove(a) {
|
|
156
|
+
n.push({ op: "list.remove", target: r(), field: e, index: a });
|
|
157
|
+
},
|
|
158
|
+
load() {
|
|
159
|
+
return p.load([e]), u;
|
|
160
|
+
},
|
|
161
|
+
get items() {
|
|
162
|
+
return s().map((a) => n.object(a, o));
|
|
163
|
+
},
|
|
164
|
+
get length() {
|
|
165
|
+
return s().length;
|
|
166
|
+
},
|
|
167
|
+
at(a) {
|
|
168
|
+
const h = s()[a];
|
|
169
|
+
if (h === void 0) throw new RangeError(`${t.type}.${e} has no item ${a}`);
|
|
170
|
+
return n.object(h, o);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
return u;
|
|
174
|
+
}
|
|
175
|
+
if (c.kind === "tree") {
|
|
176
|
+
const o = c.of ?? "", u = (i) => i?.parent === void 0 || i.parent === null ? {} : { parent: typeof i.parent == "string" ? i.parent : l(i.parent) }, a = () => s(), h = (i, g) => n.object(i, g), y = {
|
|
177
|
+
add(i, g) {
|
|
178
|
+
const x = `$${n.refs += 1}`, w = { target: x, type: o, id: null, fields: /* @__PURE__ */ new Map() };
|
|
179
|
+
return n.created.push(w), n.push({ op: "create", type: o, in: `${r()}.${e}`, ref: x, ...i ? { fields: l(i) } : {}, ...u(g) }), n.proxy(w);
|
|
180
|
+
},
|
|
181
|
+
insert(i, g) {
|
|
182
|
+
n.push({ op: "tree.insert", target: r(), field: e, item: typeof i == "string" ? i : l(i), ...u(g) });
|
|
183
|
+
},
|
|
184
|
+
move(i, g) {
|
|
185
|
+
n.push({ op: "tree.move", target: r(), field: e, item: typeof i == "string" ? i : l(i), parent: g === null ? null : typeof g == "string" ? g : l(g) });
|
|
186
|
+
},
|
|
187
|
+
load() {
|
|
188
|
+
return p.load([e]), y;
|
|
189
|
+
},
|
|
190
|
+
get nodes() {
|
|
191
|
+
return a().map((i) => ({ object: h(i.object, o), parent: i.parent === null ? null : h(i.parent, o) }));
|
|
192
|
+
},
|
|
193
|
+
children(i) {
|
|
194
|
+
const g = i == null ? null : typeof i == "string" ? i : i.id;
|
|
195
|
+
return a().filter((x) => x.parent === g).map((x) => h(x.object, o));
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
return y;
|
|
199
|
+
}
|
|
200
|
+
if (c.kind === "text") {
|
|
201
|
+
const o = {
|
|
202
|
+
insert(u, a) {
|
|
203
|
+
n.push({ op: "text.insert", target: r(), field: e, index: u, text: a });
|
|
204
|
+
},
|
|
205
|
+
delete(u, a) {
|
|
206
|
+
n.push({ op: "text.delete", target: r(), field: e, index: u, count: a });
|
|
207
|
+
},
|
|
208
|
+
set(u) {
|
|
209
|
+
n.push({ op: "text.set", target: r(), field: e, text: u });
|
|
210
|
+
},
|
|
211
|
+
mark(u, a, h, y) {
|
|
212
|
+
n.push({ op: "text.mark", target: r(), field: e, start: u, end: a, key: h, value: l(y) });
|
|
213
|
+
},
|
|
214
|
+
unmark(u, a, h) {
|
|
215
|
+
n.push({ op: "text.unmark", target: r(), field: e, start: u, end: a, key: h });
|
|
216
|
+
},
|
|
217
|
+
load() {
|
|
218
|
+
return p.load([e]), o;
|
|
219
|
+
},
|
|
220
|
+
get value() {
|
|
221
|
+
return s();
|
|
222
|
+
},
|
|
223
|
+
toString() {
|
|
224
|
+
const u = s();
|
|
225
|
+
return typeof u == "string" ? u : u.map((a) => a.insert).join("");
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
return o;
|
|
229
|
+
}
|
|
230
|
+
const f = {
|
|
231
|
+
set(o, u) {
|
|
232
|
+
n.push({ op: "map.set", target: r(), field: e, key: o, value: l(u) });
|
|
233
|
+
},
|
|
234
|
+
delete(o) {
|
|
235
|
+
n.push({ op: "map.delete", target: r(), field: e, key: o });
|
|
236
|
+
},
|
|
237
|
+
load() {
|
|
238
|
+
return p.load([e]), f;
|
|
239
|
+
},
|
|
240
|
+
get(o) {
|
|
241
|
+
return s()[o];
|
|
242
|
+
},
|
|
243
|
+
get value() {
|
|
244
|
+
return s();
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
return f;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
export {
|
|
251
|
+
b as NotSyncedError,
|
|
252
|
+
$ as PropertyNotLoadedError,
|
|
253
|
+
j as RequestContext
|
|
254
|
+
};
|