@mengine/medeo-client 2.0.1-alpha.14 → 2.0.1-alpha.15

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.
@@ -1462,8 +1462,9 @@ function emptyLaneTracks() {
1462
1462
  * `Voice` declares no `Sequence` — it is a timbre identity, not playable
1463
1463
  * content; a rendered voiceover is an `audio` entity.
1464
1464
  *
1465
- * No declaration says anything about resources: whether an entity has one, and
1466
- * which, is the `from-asset` Relation's answer alone.
1465
+ * `Asset` says only that an entity of that kind may be bound to stored bytes,
1466
+ * and asks nothing of its payload. Which bytes, and which way the content
1467
+ * flowed, is the `from-asset` / `to-asset` Relation's answer alone.
1467
1468
  */
1468
1469
  const ENTITY_KINDS = Object.freeze({
1469
1470
  axvideo: Object.freeze([
@@ -1480,27 +1481,27 @@ const ENTITY_KINDS = Object.freeze({
1480
1481
  "Sequence",
1481
1482
  "Visual",
1482
1483
  "Audible",
1483
- "FromAsset"
1484
+ "Asset"
1484
1485
  ]),
1485
1486
  audio: Object.freeze([
1486
1487
  "Sequence",
1487
1488
  "Audible",
1488
- "FromAsset"
1489
+ "Asset"
1489
1490
  ]),
1490
1491
  image: Object.freeze([
1491
1492
  "Sequence",
1492
1493
  "Visual",
1493
- "FromAsset"
1494
+ "Asset"
1494
1495
  ]),
1495
1496
  voice: Object.freeze(["Container", "IPBound"]),
1496
1497
  "sequence-marker": Object.freeze([]),
1497
1498
  viewport: Object.freeze([]),
1498
- "audio-script": Object.freeze(["SegmentText", "FromAsset"]),
1499
- "phonetic-script": Object.freeze(["SegmentText"]),
1499
+ "audio-script": Object.freeze(["SegmentText", "Asset"]),
1500
+ "phonetic-script": Object.freeze(["SegmentText", "Asset"]),
1500
1501
  caption: Object.freeze([
1501
1502
  "SegmentText",
1502
1503
  "Sequence",
1503
- "FromAsset"
1504
+ "Asset"
1504
1505
  ])
1505
1506
  });
1506
1507
  /** What a known kind declares; extension kinds declare nothing through this table. */
@@ -1798,15 +1799,6 @@ function entityToRow(entity) {
1798
1799
  //#endregion
1799
1800
  //#region ../medeo-dsl/src/invariants.ts
1800
1801
  /** An entity is made from at most one Asset; two would leave its bytes ambiguous. */
1801
- function validateAssetSource(entity, index) {
1802
- if (entity.current().entityKind === "asset") return [];
1803
- if ([...index.relationsOf(entity)].filter((relation) => relation.kind === "from-asset").length <= 1) return [];
1804
- return [{
1805
- code: "asset_source_cardinality",
1806
- entityId: entity.entityId,
1807
- message: `Entity "${entity.entityId}" is made from more than one Asset`
1808
- }];
1809
- }
1810
1802
  /** Validates one complete set of entities and its authoritative Relation rows. */
1811
1803
  function validateEntityRelationSet(entityRefs, index, options) {
1812
1804
  const { entities, issues } = collectRelatedEntities(entityRefs, index);
@@ -1828,7 +1820,6 @@ function validateEntityRelationSet(entityRefs, index, options) {
1828
1820
  const current = entity.current();
1829
1821
  const entityIssues = validateEntity(entity, entityIds);
1830
1822
  issues.push(...entityIssues);
1831
- issues.push(...validateAssetSource(entity, index));
1832
1823
  if (entityIssues.some((issue) => issue.code === "invalid_entity_payload")) continue;
1833
1824
  if (current.entityKind === "sequence-marker") {
1834
1825
  const marker = entity;
@@ -2472,10 +2463,10 @@ const markerContentRelationSpec = Object.freeze({
2472
2463
  /**
2473
2464
  * `from-asset(entity, asset)` — the entity was made from that stored resource.
2474
2465
  *
2475
- * Eligibility is declared: the non-Asset endpoint must carry the `FromAsset`
2476
- * kind, which says an entity of that kind can be made from stored bytes and
2477
- * asks nothing of its payload. The bytes stay named in exactly one place, so
2478
- * no entity copies the locator into its own row and one Asset can back several
2466
+ * Eligibility is declared: the non-Asset endpoint must carry the `Asset` kind,
2467
+ * which says an entity of that kind can be bound to stored bytes and asks
2468
+ * nothing of its payload. The bytes stay named in exactly one place, so no
2469
+ * entity copies the locator into its own row and one Asset can back several
2479
2470
  * entities.
2480
2471
  */
2481
2472
  const fromAssetRelationSpec = Object.freeze({
@@ -2483,6 +2474,26 @@ const fromAssetRelationSpec = Object.freeze({
2483
2474
  validateEndpoints: (endpoints) => hasExactlyOneAsset(endpoints),
2484
2475
  validateMetadata: isAssetBinding
2485
2476
  });
2477
+ /**
2478
+ * `to-asset(entity, asset)` — the entity's content was written out to that
2479
+ * stored resource.
2480
+ *
2481
+ * The mirror of `from-asset`, and deliberately a separate relation kind rather
2482
+ * than a second declared kind: eligibility is the same either way, but which
2483
+ * way the content flowed is what says whether an entity may still be edited.
2484
+ * An entity reached by `from-asset` was produced from bytes it does not own,
2485
+ * so changing it would contradict them. An entity with a `to-asset` owns its
2486
+ * content and the resource is a snapshot of it, which is what goes stale and
2487
+ * gets written again. A transcript that is later edited carries both at once,
2488
+ * and only the distinct relation kinds keep them apart.
2489
+ *
2490
+ * Writing a snapshot is host assembly; nothing a script authors creates one.
2491
+ */
2492
+ const toAssetRelationSpec = Object.freeze({
2493
+ kind: "to-asset",
2494
+ validateEndpoints: (endpoints) => hasExactlyOneAsset(endpoints),
2495
+ validateMetadata: isAssetBinding
2496
+ });
2486
2497
  /** `generated(output, input)` means endpoint 0 was generated from endpoint 1. */
2487
2498
  const generatedRelationSpec = Object.freeze({
2488
2499
  kind: "generated",
@@ -2545,6 +2556,7 @@ const builtInRelationSpecs = Object.freeze([
2545
2556
  axVideoMarkerRelationSpec,
2546
2557
  markerTimelineRelationSpec,
2547
2558
  fromAssetRelationSpec,
2559
+ toAssetRelationSpec,
2548
2560
  generatedRelationSpec,
2549
2561
  captionAlignmentRelationSpec,
2550
2562
  clipAnchorRelationSpec,
@@ -2573,12 +2585,12 @@ function hasMarkerAndSequence(endpoints) {
2573
2585
  const second = endpoints[1].current();
2574
2586
  return first.entityKind === "sequence-marker" && hasSequence(second) || second.entityKind === "sequence-marker" && hasSequence(first);
2575
2587
  }
2576
- /** Exactly one end is the Asset, so the other end is unambiguously the maker. */
2588
+ /** Exactly one end is the Asset, so the other end is unambiguously the bound entity. */
2577
2589
  function hasExactlyOneAsset(endpoints) {
2578
2590
  const kinds = endpoints.map((endpoint) => endpoint.current().entityKind);
2579
2591
  const assets = kinds.map((kind) => kind === "asset");
2580
2592
  if (assets[0] === assets[1]) return false;
2581
- return declaresKind(assets[0] ? kinds[1] : kinds[0], "FromAsset");
2593
+ return declaresKind(assets[0] ? kinds[1] : kinds[0], "Asset");
2582
2594
  }
2583
2595
  function isGeneratedMedia(entity) {
2584
2596
  return entity.entityKind === "video" || entity.entityKind === "image" || entity.entityKind === "audio";
@@ -3608,12 +3620,23 @@ function audioScriptAssetHash(payload) {
3608
3620
  return bytesToHex(sha256(new TextEncoder().encode(canonicalJson(audioScriptAssetContent(payload)))));
3609
3621
  }
3610
3622
  /**
3611
- * The Asset a script was written out to, read from the graph rather than the
3612
- * script's own row: like every other entity, a script names its bytes through
3613
- * a `from-asset` Relation and stores no locator itself.
3623
+ * The Asset a script was written out to. It is a snapshot the script owns, so
3624
+ * it is reached by `to-asset` — not `from-asset`, which would say the script
3625
+ * was produced from bytes it cannot change.
3614
3626
  */
3615
3627
  function audioScriptAssetOf(rows, entityId) {
3616
- const link = rows.relations.find((relation) => relation.relationKind === "from-asset" && (String(relation.endpoint0EntityId) === entityId || String(relation.endpoint1EntityId) === entityId));
3628
+ return boundAsset(rows, entityId, "to-asset");
3629
+ }
3630
+ /**
3631
+ * The Asset a script was made from — a transcript it does not own. A script
3632
+ * that has one never writes a snapshot of its own: the bytes it would describe
3633
+ * are already named, and rewriting them would contradict their source.
3634
+ */
3635
+ function scriptSourceAssetOf(rows, entityId) {
3636
+ return boundAsset(rows, entityId, "from-asset");
3637
+ }
3638
+ function boundAsset(rows, entityId, relationKind) {
3639
+ const link = rows.relations.find((relation) => relation.relationKind === relationKind && (String(relation.endpoint0EntityId) === entityId || String(relation.endpoint1EntityId) === entityId));
3617
3640
  if (link === void 0) return void 0;
3618
3641
  const otherId = String(link.endpoint0EntityId) === entityId ? link.endpoint1EntityId : link.endpoint0EntityId;
3619
3642
  return rows.entities.find((row) => String(row.entityId) === String(otherId) && row.entityKind === "asset");
@@ -3622,6 +3645,33 @@ function audioScriptAssetOf(rows, entityId) {
3622
3645
  function audioScriptAssetFields(payload) {
3623
3646
  return { assetContentHash: audioScriptAssetHash(payload) };
3624
3647
  }
3648
+ /**
3649
+ * What a PhoneticScript hands to synthesis: the base AudioScript's text as the
3650
+ * variant pronounces it, plus the variant's own phoneme and prosody control.
3651
+ *
3652
+ * The variant's content is written by a model — deciding how words are said is
3653
+ * text work, not a mechanical copy — but the bytes a synthesizer reads have to
3654
+ * leave the entity graph to reach it, because synthesis does not handle
3655
+ * entities. Writing this resource down is that crossing, and it is why speech
3656
+ * can only come from a PhoneticScript.
3657
+ */
3658
+ function phoneticScriptAssetContent(rows, entityId) {
3659
+ const assembled = assemblePhoneticScriptContent(rows, createEntityId(entityId));
3660
+ const own = assembled.phoneticScript.payload;
3661
+ return {
3662
+ text: assembled.text,
3663
+ segments: structuredClone(assembled.segments),
3664
+ ...typeof own.phonemeScript === "string" ? { phonemeScript: own.phonemeScript } : {},
3665
+ ...isJsonObject(own.prosody) ? { prosody: structuredClone(own.prosody) } : {}
3666
+ };
3667
+ }
3668
+ function phoneticScriptAssetHash(rows, entityId) {
3669
+ return bytesToHex(sha256(new TextEncoder().encode(canonicalJson(phoneticScriptAssetContent(rows, entityId)))));
3670
+ }
3671
+ /** The Asset a PhoneticScript was written out to, read from the graph. */
3672
+ function phoneticScriptAssetOf(rows, entityId) {
3673
+ return audioScriptAssetOf(rows, entityId);
3674
+ }
3625
3675
  //#endregion
3626
3676
  //#region src/entity-crdt/ordering.ts
3627
3677
  /** Domain order is scoped by membership; relation storage has no global order. */
@@ -3925,8 +3975,10 @@ var LoroEntityDocument = class LoroEntityDocument {
3925
3975
  /**
3926
3976
  * Bind a saved snapshot without rewriting text operations or resolving
3927
3977
  * selection conflicts. The script names the bytes the same way everything
3928
- * else does — an Asset entity plus a `from-asset` Relation — and keeps only
3929
- * the fingerprint that tells a stale snapshot from a current one.
3978
+ * else does — an Asset entity plus a Relation — and keeps only the
3979
+ * fingerprint that tells a stale snapshot from a current one. The Relation is
3980
+ * `to-asset`: these bytes are the script's own content written out, not a
3981
+ * source it was made from.
3930
3982
  */
3931
3983
  bindAudioScriptAsset(entityId, assetId, expectedContentHash) {
3932
3984
  const key = family(this.doc, entityId);
@@ -3949,10 +4001,10 @@ var LoroEntityDocument = class LoroEntityDocument {
3949
4001
  this.transact((draft) => {
3950
4002
  const current = readEntityDocument(this.doc, true).rows;
3951
4003
  if (audioScriptAssetOf(current, entityId)?.entityId !== assetEntityId) {
3952
- for (const relation of current.relations) if (relation.relationKind === "from-asset" && (String(relation.endpoint0EntityId) === String(entityId) || String(relation.endpoint1EntityId) === String(entityId))) draft.unlink(String(relation.relationId));
4004
+ for (const relation of current.relations) if (relation.relationKind === "to-asset" && (String(relation.endpoint0EntityId) === String(entityId) || String(relation.endpoint1EntityId) === String(entityId))) draft.unlink(String(relation.relationId));
3953
4005
  draft.link({
3954
- relationId: createRelationId(`relation_from-asset_${entityId}_${assetId}`),
3955
- relationKind: "from-asset",
4006
+ relationId: createRelationId(`relation_to-asset_${entityId}_${assetId}`),
4007
+ relationKind: "to-asset",
3956
4008
  endpoint0EntityId: createEntityId(entityId),
3957
4009
  endpoint1EntityId: assetEntityId,
3958
4010
  metadata: {},
@@ -4663,4 +4715,4 @@ function createPlainMemoryAdapter(document, options) {
4663
4715
  return new PlainMemoryAdapter(document, options);
4664
4716
  }
4665
4717
  //#endregion
4666
- export { ensureLaneTrack as $, assembleEntityContent as A, hasSequence as B, projectEntityTimeline as C, bytesToBase64 as Ct, decodeEntityRelationRows as D, EntityTimelineProjectionError as E, updateEntityFields as F, fromVideoDocument as G, buildInitialVideoDocument as H, variantBaseEntityIds as I, assertValidVideoDocument as J, toVideoDocument as K, isJsonObject as L, assembleScriptText as M, findComposedAudioScript as N, ScriptCompositionError as O, selectAudioScriptSegment as P, LANE_KINDS_IN_STACK_ORDER as Q, createEntityId as R, resolveFieldPath as S, base64ToBytes as St, resolveEntityTimelineLayout as T, buildSpeechHostMap as U, isMediaAssetVariantKind as V, derivePositionFromAbs as W, partUnionSchema as X, validateVideoDocument as Y, videoDocumentSchema as Z, audioScriptAssetOf as _, effectiveVideoClipDurationMs as _t, createMirrorVideoDocument as a, arrangeMainTrackSeamlessly as at, applyFieldChanges as b, recordEntries as bt, DocumentMutationGuard as c, recalculateTimelineDuration as ct, LoroEntityDraft as d, syncAggregatedClipsTimePosition as dt, findLaneTrack as et, readEntityDocument as f, TIMELINE_SKELETON_DURATION_MS as ft, audioScriptAssetHash as g, DEFAULT_UNIT_TIME_MS as gt, audioScriptAssetFields as h, safeDurationMs as ht, MirrorVideoDocumentAdapter as i, cascadeAfterVideoClipChanges as it, assemblePhoneticScriptContent as j, assembleCaptionContent as k, LORO_ENTITY_SCHEMA as l, resolveAllSpeechOverlaps as lt, audioScriptAssetContent as m, partDurationMs as mt, createPlainMemoryAdapter as n, laneTrackId as nt, createMirrorVideoDocumentAdapter as o, fillMainTrackTimeGaps as ot, entityOrderGroups as p, isEmptyVideoClip as pt, VideoDocumentValidationError as q, generatePartId as r, solveVideoDocument as rt, readVideoDocumentFromDraft as s, reassignSpeechesToVideoClipsByTime as st, PlainMemoryAdapter as t, hasResolvedPlacement as tt, LoroEntityDocument as u, resolveSpeechOverlapByShiftingVideos as ut, canonicalJson as v, speedOf as vt, EntityProjectionGraph as w, assertFieldChanges as x, videoDocumentMirrorSchema as xt, equalJson as y, partUnionToDraft as yt, createRelationId as z };
4718
+ export { partUnionSchema as $, decodeEntityRelationRows as A, isJsonObject as B, applyFieldChanges as C, recordEntries as Ct, EntityProjectionGraph as D, projectEntityTimeline as E, bytesToBase64 as Et, assembleScriptText as F, buildInitialVideoDocument as G, createRelationId as H, findComposedAudioScript as I, fromVideoDocument as J, buildSpeechHostMap as K, selectAudioScriptSegment as L, assembleCaptionContent as M, assembleEntityContent as N, resolveEntityTimelineLayout as O, assemblePhoneticScriptContent as P, validateVideoDocument as Q, updateEntityFields as R, equalJson as S, partUnionToDraft as St, resolveFieldPath as T, base64ToBytes as Tt, hasSequence as U, createEntityId as V, isMediaAssetVariantKind as W, VideoDocumentValidationError as X, toVideoDocument as Y, assertValidVideoDocument as Z, audioScriptAssetOf as _, partDurationMs as _t, createMirrorVideoDocument as a, laneTrackId as at, phoneticScriptAssetOf as b, effectiveVideoClipDurationMs as bt, DocumentMutationGuard as c, arrangeMainTrackSeamlessly as ct, LoroEntityDraft as d, recalculateTimelineDuration as dt, videoDocumentSchema as et, readEntityDocument as f, resolveAllSpeechOverlaps as ft, audioScriptAssetHash as g, isEmptyVideoClip as gt, audioScriptAssetFields as h, TIMELINE_SKELETON_DURATION_MS as ht, MirrorVideoDocumentAdapter as i, hasResolvedPlacement as it, ScriptCompositionError as j, EntityTimelineProjectionError as k, LORO_ENTITY_SCHEMA as l, fillMainTrackTimeGaps as lt, audioScriptAssetContent as m, syncAggregatedClipsTimePosition as mt, createPlainMemoryAdapter as n, ensureLaneTrack as nt, createMirrorVideoDocumentAdapter as o, solveVideoDocument as ot, entityOrderGroups as p, resolveSpeechOverlapByShiftingVideos as pt, derivePositionFromAbs as q, generatePartId as r, findLaneTrack as rt, readVideoDocumentFromDraft as s, cascadeAfterVideoClipChanges as st, PlainMemoryAdapter as t, LANE_KINDS_IN_STACK_ORDER as tt, LoroEntityDocument as u, reassignSpeechesToVideoClipsByTime as ut, phoneticScriptAssetContent as v, safeDurationMs as vt, assertFieldChanges as w, videoDocumentMirrorSchema as wt, scriptSourceAssetOf as x, speedOf as xt, phoneticScriptAssetHash as y, DEFAULT_UNIT_TIME_MS as yt, variantBaseEntityIds as z };
@@ -1104,7 +1104,7 @@ type CaptionSegmentSelection = JsonObject & {
1104
1104
  };
1105
1105
  //#endregion
1106
1106
  //#region ../medeo-dsl/src/relations.d.ts
1107
- type KnownRelationKind = 'timeline-track' | 'track-clip' | 'clip-marker' | 'marker-content' | 'axvideo-marker' | 'marker-timeline' | 'from-asset' | 'generated' | 'caption-alignment' | 'clip-anchor' | 'phonetic-script-render' | 'audio-script-source' | 'audio-script-marker';
1107
+ type KnownRelationKind = 'timeline-track' | 'track-clip' | 'clip-marker' | 'marker-content' | 'axvideo-marker' | 'marker-timeline' | 'from-asset' | 'to-asset' | 'generated' | 'caption-alignment' | 'clip-anchor' | 'phonetic-script-render' | 'audio-script-source' | 'audio-script-marker';
1108
1108
  type RelationKind = KnownRelationKind | (string & {});
1109
1109
  type RelationTrace = JsonObject;
1110
1110
  /**