@mengine/medeo-client 2.1.0 → 2.1.1-dsl.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.
- package/README.md +126 -25
- package/dist/base64-D-jd-dr5.js +16 -0
- package/dist/dsl-EV6kCdr6.js +5852 -0
- package/dist/dsl.d.ts +3 -0
- package/dist/dsl.js +3 -0
- package/dist/index-B7fC7q7P.d.ts +728 -0
- package/dist/index-Cu7SdKN5.d.ts +940 -0
- package/dist/index-yifEtZSP.d.ts +197 -0
- package/dist/index.d.ts +5 -1141
- package/dist/index.js +109 -2606
- package/dist/legacy.d.ts +1044 -0
- package/dist/legacy.js +4349 -0
- package/dist/{loro-relay-doc-cJSY-uau.js → loro-relay-doc-Bi6JKqtQ.js} +11 -7
- package/dist/relay.js +1 -1
- package/dist/schemas.d.ts +606 -0
- package/dist/schemas.js +442 -0
- package/dist/shared-iWnU2osE.js +39 -0
- package/dist/storage-BW3tI_ER.js +801 -0
- package/dist/testing.d.ts +22 -9
- package/dist/testing.js +168 -50
- package/dist/video-draft-types-TXRv3wS6.js +1419 -0
- package/dist/video-draft-types-c_shaRyq.d.ts +809 -0
- package/package.json +16 -6
- package/dist/chunk-D7D4PA-g.js +0 -13
- package/dist/document-B_JQwrC5.js +0 -1630
- package/dist/index-CnZ9l3rb.d.ts +0 -2077
package/dist/testing.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as VideoDraft } from "./video-draft-types-c_shaRyq.js";
|
|
2
|
+
import { _ as MedeoDsl } from "./index-Cu7SdKN5.js";
|
|
3
|
+
import { LoroDoc } from "loro-crdt";
|
|
2
4
|
|
|
3
5
|
//#region src/testing/in-memory-mengine-server.d.ts
|
|
4
6
|
/**
|
|
@@ -48,14 +50,25 @@ declare class InMemoryMengineServer {
|
|
|
48
50
|
private handleEvents;
|
|
49
51
|
}
|
|
50
52
|
//#endregion
|
|
53
|
+
//#region src/testing/video-draft-fixture.d.ts
|
|
54
|
+
declare function createTestDraft(): VideoDraft;
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/testing/dsl-fixture.d.ts
|
|
57
|
+
interface TestDslOptions {
|
|
58
|
+
peerId?: `${number}`;
|
|
59
|
+
clips?: readonly {
|
|
60
|
+
id: string;
|
|
61
|
+
durationMs: number;
|
|
62
|
+
volume?: number;
|
|
63
|
+
}[];
|
|
64
|
+
withSpeech?: boolean;
|
|
65
|
+
}
|
|
66
|
+
/** Explicit fixture media facts, shared initialization identity and stable business IDs. Caller disposes the handle. */
|
|
67
|
+
declare function createTestDsl(options?: TestDslOptions): MedeoDsl;
|
|
68
|
+
/** Caller owns the returned native document; the temporary Mirror subscriptions are released. */
|
|
69
|
+
declare function createTestLoro(options?: TestDslOptions): LoroDoc;
|
|
70
|
+
//#endregion
|
|
51
71
|
//#region src/testing/index.d.ts
|
|
52
72
|
declare const ACTOR_TEST = "1001";
|
|
53
|
-
interface SeedOptions {
|
|
54
|
-
parts?: Record<string, Record<string, unknown>>;
|
|
55
|
-
mainTrack?: string[];
|
|
56
|
-
}
|
|
57
|
-
declare function createTestDraft(): VideoDraft;
|
|
58
|
-
declare function createSeededDoc(_docId: string, opts?: SeedOptions, actor?: `${number}`): MirrorVideoDocumentAdapter;
|
|
59
|
-
declare function mainTrackPartIds(doc: MirrorVideoDocumentAdapter): string[];
|
|
60
73
|
//#endregion
|
|
61
|
-
export { ACTOR_TEST, InMemoryMengineServer,
|
|
74
|
+
export { ACTOR_TEST, InMemoryMengineServer, createTestDraft, createTestDsl, createTestLoro };
|
package/dist/testing.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { n as bytesToBase64, t as base64ToBytes } from "./base64-D-jd-dr5.js";
|
|
2
|
+
import { a as documentFormat, i as assertDslDocument } from "./video-draft-types-TXRv3wS6.js";
|
|
3
|
+
import { a as MedeoDsl, i as DslEditor, n as toVideoDraft, r as createInitialMedeoDsl } from "./dsl-EV6kCdr6.js";
|
|
4
|
+
import { t as classifyUpdate } from "./loro-relay-doc-Bi6JKqtQ.js";
|
|
3
5
|
import { LoroDoc, VersionVector, encodeFrontiers } from "loro-crdt";
|
|
4
6
|
//#region src/testing/in-memory-mengine-server.ts
|
|
5
7
|
/**
|
|
@@ -32,10 +34,46 @@ var InMemoryMengineServer = class {
|
|
|
32
34
|
const method = (init?.method ?? "GET").toUpperCase();
|
|
33
35
|
const path = this.parsePath(url);
|
|
34
36
|
if (path === "snapshot" && method === "GET") return this.handleSnapshot();
|
|
37
|
+
if (path === "initialize" && method === "POST") {
|
|
38
|
+
if (this.hasSnapshot) return Response.json({ error: { code: "already_exists" } }, { status: 409 });
|
|
39
|
+
const dsl = createInitialMedeoDsl();
|
|
40
|
+
try {
|
|
41
|
+
this.doc.import(dsl.doc.export({ mode: "snapshot" }));
|
|
42
|
+
this.hasSnapshot = true;
|
|
43
|
+
return new Response(await this.handleSnapshot().text(), {
|
|
44
|
+
status: 201,
|
|
45
|
+
headers: { "content-type": "application/json" }
|
|
46
|
+
});
|
|
47
|
+
} finally {
|
|
48
|
+
dsl.dispose();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (path === "draft" && method === "GET") {
|
|
52
|
+
if (!this.hasSnapshot) return this.handleSnapshot();
|
|
53
|
+
assertDslDocument(this.doc);
|
|
54
|
+
const dsl = new MedeoDsl(this.doc);
|
|
55
|
+
try {
|
|
56
|
+
return Response.json({
|
|
57
|
+
...toVideoDraft(dsl.getSnapshot()),
|
|
58
|
+
version: this.version()
|
|
59
|
+
});
|
|
60
|
+
} catch (error) {
|
|
61
|
+
return Response.json({ error: {
|
|
62
|
+
code: "projection_unsupported",
|
|
63
|
+
message: String(error)
|
|
64
|
+
} }, { status: 422 });
|
|
65
|
+
} finally {
|
|
66
|
+
dsl.dispose();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
35
69
|
if (/^\/internal\/mengine\/v1\/docs\/[^/]+\/bootstrap$/.test(new URL(url).pathname) && method === "POST") return this.handleBootstrap(init);
|
|
36
70
|
if (path.startsWith("sync") && method === "GET") return this.handleSync(url);
|
|
37
71
|
if (path === "updates" && method === "POST") return this.handlePush(init);
|
|
38
72
|
if (path === "events" && method === "GET") return this.handleEvents(init);
|
|
73
|
+
if (path === "audit" && method === "GET") return Response.json({ entries: extractAllMeta(this.doc).map((meta, index) => ({
|
|
74
|
+
...meta,
|
|
75
|
+
update_seq: index
|
|
76
|
+
})) });
|
|
39
77
|
return new Response("not found", { status: 404 });
|
|
40
78
|
};
|
|
41
79
|
parsePath(url) {
|
|
@@ -125,6 +163,19 @@ var InMemoryMengineServer = class {
|
|
|
125
163
|
update_seq: null,
|
|
126
164
|
version: serverVersion
|
|
127
165
|
});
|
|
166
|
+
const probe = new LoroDoc();
|
|
167
|
+
try {
|
|
168
|
+
probe.import(this.doc.export({ mode: "snapshot" }));
|
|
169
|
+
probe.import(data);
|
|
170
|
+
if (documentFormat(probe) === "mixed") return Response.json({
|
|
171
|
+
kind: "rejected",
|
|
172
|
+
code: "unsupported_document_format",
|
|
173
|
+
message: "Cannot mix legacy and DSL content roots",
|
|
174
|
+
server_version: serverVersion
|
|
175
|
+
}, { status: 422 });
|
|
176
|
+
} finally {
|
|
177
|
+
probe.free();
|
|
178
|
+
}
|
|
128
179
|
this.doc.import(data);
|
|
129
180
|
this.hasSnapshot = true;
|
|
130
181
|
this.seq += 1;
|
|
@@ -218,6 +269,41 @@ function extractMeta(doc, baseVV) {
|
|
|
218
269
|
frontiers
|
|
219
270
|
};
|
|
220
271
|
}
|
|
272
|
+
/** Mirror the real server audit: one deterministic entry per Loro Change. */
|
|
273
|
+
function extractAllMeta(doc) {
|
|
274
|
+
const json = doc.exportJsonUpdates(new VersionVector(/* @__PURE__ */ new Map()));
|
|
275
|
+
const parsed = typeof json === "string" ? JSON.parse(json) : json;
|
|
276
|
+
const peers = parsed.peers ?? [];
|
|
277
|
+
return (parsed.changes ?? []).map((change) => {
|
|
278
|
+
const [counterPart, peerPart] = change.id.split("@");
|
|
279
|
+
return {
|
|
280
|
+
peer: peers[Number(peerPart)] ?? peerPart ?? "0",
|
|
281
|
+
counter: Number(counterPart),
|
|
282
|
+
opsLen: change.ops?.length ?? 1,
|
|
283
|
+
lamport: change.lamport ?? 0,
|
|
284
|
+
timestamp: change.timestamp ?? 0,
|
|
285
|
+
message: change.msg ?? change.message ?? null
|
|
286
|
+
};
|
|
287
|
+
}).sort((a, b) => a.lamport - b.lamport || a.peer.localeCompare(b.peer)).map((change) => {
|
|
288
|
+
const { semantic_op, payload, intent, actor, parse_error } = parseMessage(change.message);
|
|
289
|
+
return {
|
|
290
|
+
semantic_op,
|
|
291
|
+
payload,
|
|
292
|
+
intent,
|
|
293
|
+
actor,
|
|
294
|
+
message: change.message,
|
|
295
|
+
parse_error,
|
|
296
|
+
peer: change.peer,
|
|
297
|
+
counter: change.counter,
|
|
298
|
+
lamport: change.lamport,
|
|
299
|
+
timestamp: change.timestamp,
|
|
300
|
+
frontiers: bytesToBase64(encodeFrontiers([{
|
|
301
|
+
peer: change.peer,
|
|
302
|
+
counter: change.counter + change.opsLen - 1
|
|
303
|
+
}]))
|
|
304
|
+
};
|
|
305
|
+
});
|
|
306
|
+
}
|
|
221
307
|
/**
|
|
222
308
|
* Mirrors `apps/mengine-server`'s `parseMessage` / `parseActor`. Kept in step
|
|
223
309
|
* deliberately: this double is what harness tests push against, so a divergence
|
|
@@ -268,8 +354,7 @@ function parseActor(actor) {
|
|
|
268
354
|
};
|
|
269
355
|
}
|
|
270
356
|
//#endregion
|
|
271
|
-
//#region src/testing/
|
|
272
|
-
const ACTOR_TEST = "1001";
|
|
357
|
+
//#region src/testing/video-draft-fixture.ts
|
|
273
358
|
function createTestDraft() {
|
|
274
359
|
return {
|
|
275
360
|
id: "draft_test",
|
|
@@ -325,52 +410,85 @@ function createTestDraft() {
|
|
|
325
410
|
version: 1
|
|
326
411
|
};
|
|
327
412
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
|
|
413
|
+
//#endregion
|
|
414
|
+
//#region src/testing/dsl-fixture.ts
|
|
415
|
+
/** Explicit fixture media facts, shared initialization identity and stable business IDs. Caller disposes the handle. */
|
|
416
|
+
function createTestDsl(options = {}) {
|
|
417
|
+
const dsl = createInitialMedeoDsl({
|
|
418
|
+
peerId: options.peerId ?? "1",
|
|
419
|
+
timelineId: "timeline"
|
|
420
|
+
});
|
|
421
|
+
const clips = options.clips ?? [{
|
|
422
|
+
id: "clip_a",
|
|
423
|
+
durationMs: 1e3
|
|
424
|
+
}, {
|
|
425
|
+
id: "clip_b",
|
|
426
|
+
durationMs: 2e3
|
|
427
|
+
}];
|
|
428
|
+
let index = 0;
|
|
429
|
+
const editor = new DslEditor(dsl, (kind) => kind === "clip" ? clips[index++].id : `${kind}_fixture`);
|
|
430
|
+
editor.addClips({
|
|
431
|
+
trackId: "main_track",
|
|
432
|
+
clips: clips.map((clip) => ({
|
|
433
|
+
media: {
|
|
434
|
+
kind: "video",
|
|
435
|
+
system: "memota",
|
|
436
|
+
key: `media_${clip.id}`,
|
|
437
|
+
durationMs: clip.durationMs
|
|
438
|
+
},
|
|
439
|
+
volume: clip.volume ?? 1
|
|
440
|
+
}))
|
|
441
|
+
});
|
|
442
|
+
if (options.withSpeech) editor.applyVoiceover({
|
|
443
|
+
clipId: "speech",
|
|
444
|
+
trackId: "speech_track",
|
|
445
|
+
captionTrackId: "caption_track",
|
|
446
|
+
media: {
|
|
447
|
+
kind: "voiceover-recording",
|
|
448
|
+
system: "memota-speech",
|
|
449
|
+
key: "original",
|
|
450
|
+
durationMs: 1e3,
|
|
451
|
+
storageKey: "speech.mp3"
|
|
452
|
+
},
|
|
453
|
+
script: { body: "hello" },
|
|
454
|
+
volume: 1,
|
|
455
|
+
voice: {
|
|
456
|
+
system: "voice-library",
|
|
457
|
+
key: "voice",
|
|
458
|
+
name: "Voice"
|
|
459
|
+
},
|
|
460
|
+
placement: {
|
|
461
|
+
kind: "anchored",
|
|
462
|
+
clipId: clips[0].id,
|
|
463
|
+
offsetMs: 0
|
|
464
|
+
},
|
|
465
|
+
captions: [{
|
|
466
|
+
clipId: "caption",
|
|
467
|
+
startMs: 0,
|
|
468
|
+
durationMs: 1e3,
|
|
469
|
+
range: {
|
|
470
|
+
start: 0,
|
|
471
|
+
end: 5
|
|
472
|
+
},
|
|
473
|
+
style: {}
|
|
474
|
+
}]
|
|
475
|
+
});
|
|
476
|
+
return dsl;
|
|
371
477
|
}
|
|
372
|
-
|
|
373
|
-
|
|
478
|
+
/** Caller owns the returned native document; the temporary Mirror subscriptions are released. */
|
|
479
|
+
function createTestLoro(options = {}) {
|
|
480
|
+
const dsl = createTestDsl(options);
|
|
481
|
+
try {
|
|
482
|
+
const doc = new LoroDoc();
|
|
483
|
+
doc.import(dsl.doc.export({ mode: "snapshot" }));
|
|
484
|
+
doc.setPeerId(options.peerId ?? "1");
|
|
485
|
+
return doc;
|
|
486
|
+
} finally {
|
|
487
|
+
dsl.dispose();
|
|
488
|
+
}
|
|
374
489
|
}
|
|
375
490
|
//#endregion
|
|
376
|
-
|
|
491
|
+
//#region src/testing/index.ts
|
|
492
|
+
const ACTOR_TEST = "1001";
|
|
493
|
+
//#endregion
|
|
494
|
+
export { ACTOR_TEST, InMemoryMengineServer, createTestDraft, createTestDsl, createTestLoro };
|