@markless/serializer 0.6.0 → 0.7.0

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/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { A as protocolRowSegment, B as ASYNC_BOUNDARY_ARM, C as PROTOCOL_PAGE_SPACE_ID_PREFIXES, D as protocolInstanceQualifies, E as protocolInstancePath, F as PROTOCOL_CONTAINER_HOST_NODE_ID, I as PROTOCOL_CONTAINER_START_COMMENT, L as PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, M as PROTOCOL_PROP_GRAPH_NODE_PREFIX, N as PROTOCOL_SYNC_POLICY_HOST_ATTRIBUTE, O as protocolInstanceSegment, P as PROTOCOL_CONTAINER_END_COMMENT, R as PROTOCOL_IDLE_EVENT_NAME, S as PROTOCOL_EVENT_ACTION_KIND, T as STORAGE_PROTOCOL_VERSION, _ as ProtocolViewPayload, a as ProtocolBranchIdrefSite, b as protocolEventDispatchesMarkless, c as ProtocolEventActionKind, d as ProtocolRowTemplateSlotValue, f as ProtocolStatePayload, g as ProtocolSyncPolicyCondition, h as ProtocolSyncPolicyBranch, i as ProtocolBranchContentRead, j as protocolStateVersion, k as protocolProjectionSegment, l as ProtocolEventRecord, m as ProtocolSyncPolicy, n as ProtocolArmRecordSet, o as ProtocolComposedGraphProp, p as ProtocolStreamedArmPatch, r as ProtocolAsyncBoundaryArm, s as ProtocolEventAction, t as ProtocolArmBranchRecord, u as ProtocolPayloadScripts, v as protocolElementHandleReadId, w as PROTOCOL_PROPS_GRAPH_NODE_ID, x as ASYNC_PROTOCOL_VERSION, y as protocolEventActionKind, z as PROTOCOL_VISIBLE_EVENT_NAME } from "./protocol-BNO5JLsK.js";
2
+ import { a as PROTOCOL_TEMPLATED_LISTS, i as expandRecordTemplates, n as ProtocolTemplatedRecords, o as RuntimePayloadType$1, r as decodeProtocolPayloadLists } from "./protocol-record-templates-pAcSQYqD.js";
2
3
  import { a as SerializedPrimitive, c as TypedArrayName, d as serializeGraphValue, f as deserializeGraphValue, i as SerializedGraphPayload, l as jsonSourceWithNonFiniteNumbers, n as SerializationDiagnostic, o as SerializedRecord, r as SerializationResult, s as SerializedSlot, t as NonFiniteNumberName, u as nonFiniteName } from "./value-CRkHmkRz.js";
3
4
  import { a as RuntimePayloadError, c as assertProtocolStateCellPayload, d as decodePayloadScriptsWithVersion, f as invalidPayloadShapeError, i as RuntimePayloadDiagnostic, l as assertProtocolStatePayload, m as payloadScriptSelector, n as DecodedPayloadScripts, o as RuntimePayloadErrorCode, p as payloadInvalidError, r as EncodedPayloadScripts, s as RuntimePayloadType, t as decodePayloadScripts, u as assertProtocolViewPayload } from "./protocol-validation-storage-B4dATVQ_.js";
4
5
  //#region src/payload-scripts.d.ts
@@ -12,7 +13,9 @@ export type RenderedPayloadScripts = {
12
13
  readonly stateScript: string;
13
14
  readonly viewScript: string;
14
15
  };
15
- export declare function renderPayloadScripts(input: RenderPayloadScriptsInput): RenderedPayloadScripts;
16
+ /** How a payload's record lists are written; a served page passes encodeProtocolPayloadLists. */
17
+ export type PayloadListEncoder = <T extends object>(type: RuntimePayloadType$1, payload: T) => T;
18
+ export declare function renderPayloadScripts(input: RenderPayloadScriptsInput, encodeLists?: PayloadListEncoder): RenderedPayloadScripts;
16
19
  export declare function escapeScriptJson(value: string): string;
17
20
  //#endregion
18
21
  //#region src/protocol-state.d.ts
@@ -71,6 +74,16 @@ export declare function createProtocolStatePayload(input: ProtocolStatePayloadIn
71
74
  export declare function serializeRuntimeStateCells(cells: ProtocolStatePayload['cells']): ProtocolStatePayload['cells'];
72
75
  export declare function serializeRuntimeAsyncSnapshots(computed: ProtocolStatePayload['computed']): ProtocolStatePayload['computed'];
73
76
  //#endregion
77
+ //#region src/protocol-record-templates-encode.d.ts
78
+ /**
79
+ * Serves a record list as templates when that is shorter: records that differ only in their
80
+ * values share one shape, each carries only the values that differ between them, and every field
81
+ * name the list's key table spells becomes its index there.
82
+ */
83
+ export declare function encodeRecordTemplates<T extends object>(records: ReadonlyArray<T>, keys?: string): ReadonlyArray<T> | ProtocolTemplatedRecords;
84
+ /** The payload with each templated list served in its shorter form, for JSON.stringify. */
85
+ export declare function encodeProtocolPayloadLists<T extends object>(type: RuntimePayloadType$1, payload: T): T;
86
+ //#endregion
74
87
  //#region src/resume-record-merge.d.ts
75
88
  type ResumeRecordSet = {
76
89
  readonly state: ProtocolStatePayload;
@@ -110,4 +123,4 @@ export declare function storageSlotEntryKeyFromGraphNodeId(graphNodeId: string):
110
123
  export declare function createStorageSeedMetadata(moduleId: string, driverKey: string, fallback: string): StorageSeedMetadata;
111
124
  export declare function createStorageSeedMetadataFromGraphNodeId(graphNodeId: string, driverKey: string, fallback: string): StorageSeedMetadata;
112
125
  //#endregion
113
- export { ASYNC_BOUNDARY_ARM, ASYNC_PROTOCOL_VERSION, DecodedPayloadScripts, EncodedPayloadScripts, NonFiniteNumberName, PROTOCOL_CONTAINER_END_COMMENT, PROTOCOL_CONTAINER_HOST_NODE_ID, PROTOCOL_CONTAINER_START_COMMENT, PROTOCOL_EVENT_ACTION_KIND, PROTOCOL_IDLE_EVENT_NAME, PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, PROTOCOL_PAGE_SPACE_ID_PREFIXES, PROTOCOL_PROPS_GRAPH_NODE_ID, PROTOCOL_PROP_GRAPH_NODE_PREFIX, PROTOCOL_SYNC_POLICY_HOST_ATTRIBUTE, PROTOCOL_VISIBLE_EVENT_NAME, ProtocolArmBranchRecord, ProtocolArmRecordSet, ProtocolAsyncBoundaryArm, ProtocolBranchContentRead, ProtocolBranchIdrefSite, ProtocolComposedGraphProp, ProtocolEventAction, ProtocolEventActionKind, ProtocolEventRecord, ProtocolPayloadScripts, ProtocolRowTemplateSlotValue, ProtocolStatePayload, ProtocolStreamedArmPatch, ProtocolSyncPolicy, ProtocolSyncPolicyBranch, ProtocolSyncPolicyCondition, ProtocolViewPayload, type ResumeRecordSet, RuntimePayloadDiagnostic, RuntimePayloadError, RuntimePayloadErrorCode, RuntimePayloadType, STORAGE_PROTOCOL_VERSION, SerializationDiagnostic, SerializationResult, SerializedGraphPayload, SerializedPrimitive, SerializedRecord, SerializedSlot, TypedArrayName, assertProtocolStateCellPayload, assertProtocolStatePayload, assertProtocolViewPayload, decodePayloadScripts, decodePayloadScriptsWithVersion, deserializeGraphValue, invalidPayloadShapeError, jsonSourceWithNonFiniteNumbers, nonFiniteName, payloadInvalidError, payloadScriptSelector, protocolElementHandleReadId, protocolEventActionKind, protocolEventDispatchesMarkless, protocolInstancePath, protocolInstanceQualifies, protocolInstanceSegment, protocolProjectionSegment, protocolRowSegment, protocolStateVersion, serializeGraphValue };
126
+ export { ASYNC_BOUNDARY_ARM, ASYNC_PROTOCOL_VERSION, DecodedPayloadScripts, EncodedPayloadScripts, NonFiniteNumberName, PROTOCOL_CONTAINER_END_COMMENT, PROTOCOL_CONTAINER_HOST_NODE_ID, PROTOCOL_CONTAINER_START_COMMENT, PROTOCOL_EVENT_ACTION_KIND, PROTOCOL_IDLE_EVENT_NAME, PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, PROTOCOL_PAGE_SPACE_ID_PREFIXES, PROTOCOL_PROPS_GRAPH_NODE_ID, PROTOCOL_PROP_GRAPH_NODE_PREFIX, PROTOCOL_SYNC_POLICY_HOST_ATTRIBUTE, PROTOCOL_TEMPLATED_LISTS, PROTOCOL_VISIBLE_EVENT_NAME, ProtocolArmBranchRecord, ProtocolArmRecordSet, ProtocolAsyncBoundaryArm, ProtocolBranchContentRead, ProtocolBranchIdrefSite, ProtocolComposedGraphProp, ProtocolEventAction, ProtocolEventActionKind, ProtocolEventRecord, ProtocolPayloadScripts, ProtocolRowTemplateSlotValue, ProtocolStatePayload, ProtocolStreamedArmPatch, ProtocolSyncPolicy, ProtocolSyncPolicyBranch, ProtocolSyncPolicyCondition, type ProtocolTemplatedRecords, ProtocolViewPayload, type ResumeRecordSet, RuntimePayloadDiagnostic, RuntimePayloadError, RuntimePayloadErrorCode, RuntimePayloadType, STORAGE_PROTOCOL_VERSION, SerializationDiagnostic, SerializationResult, SerializedGraphPayload, SerializedPrimitive, SerializedRecord, SerializedSlot, TypedArrayName, assertProtocolStateCellPayload, assertProtocolStatePayload, assertProtocolViewPayload, decodePayloadScripts, decodePayloadScriptsWithVersion, decodeProtocolPayloadLists, deserializeGraphValue, expandRecordTemplates, invalidPayloadShapeError, jsonSourceWithNonFiniteNumbers, nonFiniteName, payloadInvalidError, payloadScriptSelector, protocolElementHandleReadId, protocolEventActionKind, protocolEventDispatchesMarkless, protocolInstancePath, protocolInstanceQualifies, protocolInstanceSegment, protocolProjectionSegment, protocolRowSegment, protocolStateVersion, serializeGraphValue };
package/dist/index.js CHANGED
@@ -1,17 +1,19 @@
1
1
  import { C as PROTOCOL_VISIBLE_EVENT_NAME, S as PROTOCOL_IDLE_EVENT_NAME, _ as PROTOCOL_SYNC_POLICY_HOST_ATTRIBUTE, a as ASYNC_PROTOCOL_VERSION, b as PROTOCOL_CONTAINER_START_COMMENT, c as PROTOCOL_PROPS_GRAPH_NODE_ID, d as protocolInstanceQualifies, f as protocolInstanceSegment, g as PROTOCOL_PROP_GRAPH_NODE_PREFIX, h as protocolStateVersion, i as ASYNC_BOUNDARY_ARM, l as STORAGE_PROTOCOL_VERSION, m as protocolRowSegment, n as protocolEventActionKind, o as PROTOCOL_EVENT_ACTION_KIND, p as protocolProjectionSegment, r as protocolEventDispatchesMarkless, s as PROTOCOL_PAGE_SPACE_ID_PREFIXES, t as protocolElementHandleReadId, u as protocolInstancePath, v as PROTOCOL_CONTAINER_END_COMMENT, x as PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, y as PROTOCOL_CONTAINER_HOST_NODE_ID } from "./protocol-9Mv28nr_.js";
2
2
  import { deserializeGraphValue } from "./decode.js";
3
- import { a as assertProtocolStatePayload, c as invalidPayloadShapeError, i as assertProtocolStateCellPayload, l as payloadInvalidError, n as isValidStorageKey, o as assertProtocolViewPayload, r as RuntimePayloadError, s as decodePayloadScriptsWithVersion, t as decodePayloadScripts, u as payloadScriptSelector } from "./protocol-validation-storage-ycVVe95T.js";
3
+ import { i as PROTOCOL_RECORD_KEYS, n as expandRecordTemplates, r as PROTOCOL_TEMPLATED_LISTS, t as decodeProtocolPayloadLists } from "./protocol-record-templates-B0Ay3OCd.js";
4
+ import { a as assertProtocolStatePayload, c as invalidPayloadShapeError, i as assertProtocolStateCellPayload, l as payloadInvalidError, n as isValidStorageKey, o as assertProtocolViewPayload, r as RuntimePayloadError, s as decodePayloadScriptsWithVersion, t as decodePayloadScripts, u as payloadScriptSelector } from "./protocol-validation-storage-D9VzvR9i.js";
4
5
  //#region src/payload-scripts.ts
5
- function renderPayloadScripts(input) {
6
+ function renderPayloadScripts(input, encodeLists) {
6
7
  return {
7
8
  state: input.state,
8
9
  view: input.view,
9
- stateScript: renderDataScript("markless/state", input.state),
10
- viewScript: renderDataScript("markless/view", input.view)
10
+ stateScript: renderDataScript("markless/state", input.state, encodeLists),
11
+ viewScript: renderDataScript("markless/view", input.view, encodeLists)
11
12
  };
12
13
  }
13
- function renderDataScript(type, payload) {
14
- return `<script type="${type}">${escapeScriptJson(JSON.stringify(payload))}<\/script>`;
14
+ function renderDataScript(type, payload, encodeLists) {
15
+ const served = encodeLists ? encodeLists(type, payload) : payload;
16
+ return `<script type="${type}">${escapeScriptJson(JSON.stringify(served))}<\/script>`;
15
17
  }
16
18
  function escapeScriptJson(value) {
17
19
  return value.replace(/<(?=[/!])/g, "\\u003C");
@@ -437,6 +439,118 @@ function protocolStateSerializationError(cell, diagnostic) {
437
439
  });
438
440
  }
439
441
  //#endregion
442
+ //#region src/protocol-record-templates-encode.ts
443
+ const HOLE = /\d+|r:[^:"\\]*:/g;
444
+ const WHOLE_NUMBER = /^(?:0|[1-9]\d{0,14})$/;
445
+ const TEMPLATED_SHARE = .75;
446
+ const keyRefsByTable = /* @__PURE__ */ new Map();
447
+ function keyRefs(keys) {
448
+ let refs = keyRefsByTable.get(keys);
449
+ if (!refs) {
450
+ const names = keys.split(" ");
451
+ const index = new Map(names.map((name, at) => [name, at]));
452
+ const pattern = new RegExp(`"(${names.map((name) => name.replace(/[$]/g, "\\$&")).join("|")})":`, "g");
453
+ refs = (text) => text.replace(pattern, (_, name) => `~${index.get(name)}:`);
454
+ keyRefsByTable.set(keys, refs);
455
+ }
456
+ return refs;
457
+ }
458
+ /**
459
+ * Serves a record list as templates when that is shorter: records that differ only in their
460
+ * values share one shape, each carries only the values that differ between them, and every field
461
+ * name the list's key table spells becomes its index there.
462
+ */
463
+ function encodeRecordTemplates(records, keys = "") {
464
+ if (records.length < 2) return records;
465
+ const refer = keys ? keyRefs(keys) : (text) => text;
466
+ const groups = /* @__PURE__ */ new Map();
467
+ const texts = [];
468
+ for (let index = 0; index < records.length; index++) {
469
+ let text = JSON.stringify(records[index]);
470
+ if (text.includes("^")) text = text.replaceAll("^", "\\u005e");
471
+ if (text.includes("~")) text = text.replaceAll("~", "\\u007e");
472
+ texts.push(text);
473
+ const values = text.match(HOLE);
474
+ const key = values ? text.replace(HOLE, "^") : text;
475
+ let group = groups.get(key);
476
+ if (!group) groups.set(key, group = {
477
+ key,
478
+ rows: [],
479
+ members: []
480
+ });
481
+ group.rows.push(values);
482
+ group.members.push(index);
483
+ }
484
+ const templates = [];
485
+ const refs = [];
486
+ for (const group of groups.values()) {
487
+ if (group.rows.length === 1) {
488
+ const member = group.members[0];
489
+ const template = refer(texts[member]);
490
+ if (JSON.stringify(template).length < texts[member].length) {
491
+ refs[member] = templates.length;
492
+ templates.push(template);
493
+ } else refs[member] = records[member];
494
+ continue;
495
+ }
496
+ const index = templates.length;
497
+ const first = group.rows[0];
498
+ const slots = first ? valueSlots(group.rows) : {
499
+ of: [],
500
+ columns: []
501
+ };
502
+ const parts = group.key.split("^");
503
+ let text = parts[0];
504
+ for (let column = 0; column < parts.length - 1; column++) {
505
+ const slot = slots.of[column];
506
+ text += (slot < 0 ? first[column] : `^${slot}`) + parts[column + 1];
507
+ }
508
+ templates.push(refer(text));
509
+ group.rows.forEach((values, row) => {
510
+ refs[group.members[row]] = slots.columns.length ? [index, ...slots.columns.map((column) => {
511
+ const value = values[column];
512
+ return WHOLE_NUMBER.test(value) ? Number(value) : value;
513
+ })] : index;
514
+ });
515
+ }
516
+ const encoded = {
517
+ t: templates,
518
+ r: refs
519
+ };
520
+ const plain = texts.reduce((total, text) => total + text.length + 1, 1);
521
+ return JSON.stringify(encoded).length <= plain * TEMPLATED_SHARE ? encoded : records;
522
+ }
523
+ function valueSlots(rows) {
524
+ const width = rows[0].length;
525
+ const of = [];
526
+ const columns = [];
527
+ for (let column = 0; column < width; column++) {
528
+ const value = rows[0][column];
529
+ if (rows.every((row) => row[column] === value)) {
530
+ of.push(-1);
531
+ continue;
532
+ }
533
+ const same = columns.findIndex((held) => rows.every((row) => row[held] === row[column]));
534
+ of.push(same >= 0 ? same : columns.push(column) - 1);
535
+ }
536
+ return {
537
+ of,
538
+ columns
539
+ };
540
+ }
541
+ /** The payload with each templated list served in its shorter form, for JSON.stringify. */
542
+ function encodeProtocolPayloadLists(type, payload) {
543
+ const keys = PROTOCOL_RECORD_KEYS[type];
544
+ let encoded;
545
+ for (const key of PROTOCOL_TEMPLATED_LISTS[type]) {
546
+ const list = payload[key];
547
+ if (!Array.isArray(list)) continue;
548
+ const served = encodeRecordTemplates(list, keys[key]);
549
+ if (served !== list) (encoded ??= { ...payload })[key] = served;
550
+ }
551
+ return encoded ?? payload;
552
+ }
553
+ //#endregion
440
554
  //#region src/resume-record-merge.ts
441
555
  function mergeResumeRecordDelta(baseline, delta) {
442
556
  assertMatchingVersion$1(baseline.state.version, delta.state.version, "state");
@@ -641,4 +755,4 @@ function createStorageCookieReader(cookieHeader) {
641
755
  return (driverKey) => values.get(storageCookieName(driverKey));
642
756
  }
643
757
  //#endregion
644
- export { ASYNC_BOUNDARY_ARM, ASYNC_PROTOCOL_VERSION, PROTOCOL_CONTAINER_END_COMMENT, PROTOCOL_CONTAINER_HOST_NODE_ID, PROTOCOL_CONTAINER_START_COMMENT, PROTOCOL_EVENT_ACTION_KIND, PROTOCOL_IDLE_EVENT_NAME, PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, PROTOCOL_PAGE_SPACE_ID_PREFIXES, PROTOCOL_PROPS_GRAPH_NODE_ID, PROTOCOL_PROP_GRAPH_NODE_PREFIX, PROTOCOL_SYNC_POLICY_HOST_ATTRIBUTE, PROTOCOL_VISIBLE_EVENT_NAME, ProtocolStateSerializationError, RuntimePayloadError, STORAGE_PROTOCOL_VERSION, STORAGE_RENDER_CONTEXT_READER, STORAGE_SLOT_SYMBOL_KEY, assertProtocolStateCellPayload, assertProtocolStatePayload, assertProtocolViewPayload, classifyResumeRecordDelta, createProtocolStatePayload, createStorageCookieReader, createStorageSeedMetadata, createStorageSeedMetadataFromGraphNodeId, decodePayloadScripts, decodePayloadScriptsWithVersion, decodeStorageCookieValue, deserializeGraphValue, escapeScriptJson, invalidPayloadShapeError, isValidStorageKey, jsonSourceWithNonFiniteNumbers, mergeResumeRecordDelta, nonFiniteName, payloadInvalidError, payloadScriptSelector, protocolElementHandleReadId, protocolEventActionKind, protocolEventDispatchesMarkless, protocolInstancePath, protocolInstanceQualifies, protocolInstanceSegment, protocolProjectionSegment, protocolRowSegment, protocolStateVersion, renderPayloadScripts, serializeGraphValue, serializeRuntimeAsyncSnapshots, serializeRuntimeStateCells, storageAttributeName, storageCookieAssignment, storageCookieName, storageSlotEntryKey, storageSlotEntryKeyFromGraphNodeId };
758
+ export { ASYNC_BOUNDARY_ARM, ASYNC_PROTOCOL_VERSION, PROTOCOL_CONTAINER_END_COMMENT, PROTOCOL_CONTAINER_HOST_NODE_ID, PROTOCOL_CONTAINER_START_COMMENT, PROTOCOL_EVENT_ACTION_KIND, PROTOCOL_IDLE_EVENT_NAME, PROTOCOL_LOCATOR_PATHS_ATTRIBUTE, PROTOCOL_PAGE_SPACE_ID_PREFIXES, PROTOCOL_PROPS_GRAPH_NODE_ID, PROTOCOL_PROP_GRAPH_NODE_PREFIX, PROTOCOL_SYNC_POLICY_HOST_ATTRIBUTE, PROTOCOL_TEMPLATED_LISTS, PROTOCOL_VISIBLE_EVENT_NAME, ProtocolStateSerializationError, RuntimePayloadError, STORAGE_PROTOCOL_VERSION, STORAGE_RENDER_CONTEXT_READER, STORAGE_SLOT_SYMBOL_KEY, assertProtocolStateCellPayload, assertProtocolStatePayload, assertProtocolViewPayload, classifyResumeRecordDelta, createProtocolStatePayload, createStorageCookieReader, createStorageSeedMetadata, createStorageSeedMetadataFromGraphNodeId, decodePayloadScripts, decodePayloadScriptsWithVersion, decodeProtocolPayloadLists, decodeStorageCookieValue, deserializeGraphValue, encodeProtocolPayloadLists, encodeRecordTemplates, escapeScriptJson, expandRecordTemplates, invalidPayloadShapeError, isValidStorageKey, jsonSourceWithNonFiniteNumbers, mergeResumeRecordDelta, nonFiniteName, payloadInvalidError, payloadScriptSelector, protocolElementHandleReadId, protocolEventActionKind, protocolEventDispatchesMarkless, protocolInstancePath, protocolInstanceQualifies, protocolInstanceSegment, protocolProjectionSegment, protocolRowSegment, protocolStateVersion, renderPayloadScripts, serializeGraphValue, serializeRuntimeAsyncSnapshots, serializeRuntimeStateCells, storageAttributeName, storageCookieAssignment, storageCookieName, storageSlotEntryKey, storageSlotEntryKeyFromGraphNodeId };
@@ -0,0 +1,60 @@
1
+ //#region src/protocol-record-keys.ts
2
+ /** The field names each templated record list may spell, in the order its templates index them. */
3
+ const PROTOCOL_RECORD_KEYS = {
4
+ "markless/state": {
5
+ computed: "graphNodeId name async deriveSymbolId value version root $type $ref source flags records id type fields items entries values bytes arrayType buffer byteOffset length byteLength directValue dependencies path snapshot status key error",
6
+ sharedSeeds: "graphNodeId deriveSymbolId dependencies path reads",
7
+ sharedDefinitions: "id name exportedName scope version graphNodeIds projectionIds dependencies definitionId definitionName returnProperties kind graphNodeId path"
8
+ },
9
+ "markless/view": {
10
+ domUpdates: "hostNodeId source graphNodeId path target kind prefix suffix trueValue falseValue textNode name constantClass leadingClass symbolId",
11
+ behaviors: "hostNodeId source functionSource inputSources inputValues inputGraphReads inputIndex graphNodeId path symbolId usesGraph",
12
+ elementHandles: "hostNodeId handleId name plural"
13
+ }
14
+ };
15
+ //#endregion
16
+ //#region src/protocol-templated-lists.ts
17
+ /**
18
+ * The record lists a payload script may serve as record templates instead of a plain array. The
19
+ * inline resumer reads the others at page load, before any decoder has loaded, so they stay plain.
20
+ */
21
+ const PROTOCOL_TEMPLATED_LISTS = {
22
+ "markless/state": [
23
+ "computed",
24
+ "sharedSeeds",
25
+ "sharedDefinitions"
26
+ ],
27
+ "markless/view": [
28
+ "domUpdates",
29
+ "behaviors",
30
+ "elementHandles"
31
+ ]
32
+ };
33
+ //#endregion
34
+ //#region src/protocol-record-templates.ts
35
+ function expandRecordTemplates(list, keys = "") {
36
+ if (Array.isArray(list)) return list;
37
+ const { t, r } = list;
38
+ const names = keys.split(" ");
39
+ const parts = t.map((text) => text.replace(/~(\d+):/g, (_, at) => `"${names[+at]}":`).split(/\^(\d+)/));
40
+ return r.map((ref) => {
41
+ if (typeof ref === "number") return JSON.parse(parts[ref][0]);
42
+ if (!Array.isArray(ref)) return ref;
43
+ const part = parts[ref[0]];
44
+ let text = part[0];
45
+ for (let at = 1; at < part.length; at += 2) text += ref[+part[at] + 1] + part[at + 1];
46
+ return JSON.parse(text);
47
+ });
48
+ }
49
+ /** Expands, in place, every templated list of a freshly parsed payload script. */
50
+ function decodeProtocolPayloadLists(type, payload) {
51
+ const record = payload;
52
+ const keys = PROTOCOL_RECORD_KEYS[type];
53
+ if (record) for (const key of PROTOCOL_TEMPLATED_LISTS[type]) {
54
+ const list = record[key];
55
+ if (list && !Array.isArray(list)) record[key] = expandRecordTemplates(list, keys[key]);
56
+ }
57
+ return payload;
58
+ }
59
+ //#endregion
60
+ export { PROTOCOL_RECORD_KEYS as i, expandRecordTemplates as n, PROTOCOL_TEMPLATED_LISTS as r, decodeProtocolPayloadLists as t };
@@ -0,0 +1,31 @@
1
+ //#region src/protocol-client.d.ts
2
+ type RuntimePayloadType = 'markless/state' | 'markless/view';
3
+ //#endregion
4
+ //#region src/protocol-templated-lists.d.ts
5
+ /**
6
+ * The record lists a payload script may serve as record templates instead of a plain array. The
7
+ * inline resumer reads the others at page load, before any decoder has loaded, so they stay plain.
8
+ */
9
+ declare const PROTOCOL_TEMPLATED_LISTS: {
10
+ readonly 'markless/state': readonly ["computed", "sharedSeeds", "sharedDefinitions"];
11
+ readonly 'markless/view': readonly ["domUpdates", "behaviors", "elementHandles"];
12
+ };
13
+ //#endregion
14
+ //#region src/protocol-record-templates.d.ts
15
+ /**
16
+ * A record list served as templates. `t` holds each distinct record shape as JSON text whose
17
+ * per-record values are `^<slot>` holes and whose field names the list's generated key table
18
+ * spells are `~<index>:` references; each `r` entry is a template index (no values), a
19
+ * `[template, ...values]` row filling the holes in order, or a record no other record shares.
20
+ */
21
+ type ProtocolTemplatedRecords = {
22
+ readonly t: ReadonlyArray<string>;
23
+ readonly r: ReadonlyArray<number | ReadonlyArray<number | string> | object>;
24
+ };
25
+ /** A record list as a payload script serves it: a plain array, or templates. */
26
+ type ProtocolServedRecords = ReadonlyArray<unknown> | ProtocolTemplatedRecords;
27
+ declare function expandRecordTemplates(list: ProtocolServedRecords, keys?: string): unknown[];
28
+ /** Expands, in place, every templated list of a freshly parsed payload script. */
29
+ declare function decodeProtocolPayloadLists<T>(type: RuntimePayloadType, payload: T): T;
30
+ //#endregion
31
+ export { PROTOCOL_TEMPLATED_LISTS as a, expandRecordTemplates as i, ProtocolTemplatedRecords as n, RuntimePayloadType as o, decodeProtocolPayloadLists as r, ProtocolServedRecords as t };
@@ -1,4 +1,5 @@
1
1
  import { i as ASYNC_BOUNDARY_ARM, o as PROTOCOL_EVENT_ACTION_KIND } from "./protocol-9Mv28nr_.js";
2
+ import { t as decodeProtocolPayloadLists } from "./protocol-record-templates-B0Ay3OCd.js";
2
3
  //#region src/protocol-validation.ts
3
4
  var RuntimePayloadError = class extends Error {
4
5
  constructor(diagnostic) {
@@ -25,7 +26,7 @@ function parseDataScript(script, type) {
25
26
  const prefix = `<script type="${type}">`;
26
27
  if (!script.startsWith(prefix) || !script.endsWith("<\/script>")) throw payloadInvalidError(type, `Expected ${type} payload script.`, `Browser resume expects the ${type} data to arrive in a canonical ${payloadScriptSelector(type)} script wrapper before decoding the resumability protocol.`, [{ message: `Emit the ${type} payload with renderPayloadScripts or an equivalent canonical script wrapper.` }]);
27
28
  try {
28
- return JSON.parse(script.slice(prefix.length, -9));
29
+ return decodeProtocolPayloadLists(type, JSON.parse(script.slice(prefix.length, -9)));
29
30
  } catch {
30
31
  throw payloadInvalidError(type, `Invalid ${type} payload JSON.`, `The ${type} payload script must contain valid JSON before the runtime can validate the resumability protocol fields.`, [{ message: `Emit valid JSON inside the ${payloadScriptSelector(type)} script content.` }]);
31
32
  }
@@ -1,2 +1,2 @@
1
- import { a as assertProtocolStatePayload, c as invalidPayloadShapeError, i as assertProtocolStateCellPayload, l as payloadInvalidError, o as assertProtocolViewPayload, r as RuntimePayloadError, s as decodePayloadScriptsWithVersion, t as decodePayloadScripts, u as payloadScriptSelector } from "./protocol-validation-storage-ycVVe95T.js";
1
+ import { a as assertProtocolStatePayload, c as invalidPayloadShapeError, i as assertProtocolStateCellPayload, l as payloadInvalidError, o as assertProtocolViewPayload, r as RuntimePayloadError, s as decodePayloadScriptsWithVersion, t as decodePayloadScripts, u as payloadScriptSelector } from "./protocol-validation-storage-D9VzvR9i.js";
2
2
  export { RuntimePayloadError, assertProtocolStateCellPayload, assertProtocolStatePayload, assertProtocolViewPayload, decodePayloadScripts, decodePayloadScriptsWithVersion, invalidPayloadShapeError, payloadInvalidError, payloadScriptSelector };
@@ -0,0 +1,2 @@
1
+ import { a as PROTOCOL_TEMPLATED_LISTS, i as expandRecordTemplates, n as ProtocolTemplatedRecords, o as RuntimePayloadType, r as decodeProtocolPayloadLists, t as ProtocolServedRecords } from "./protocol-record-templates-pAcSQYqD.js";
2
+ export { PROTOCOL_TEMPLATED_LISTS, ProtocolServedRecords, ProtocolTemplatedRecords, type RuntimePayloadType, decodeProtocolPayloadLists, expandRecordTemplates };
@@ -0,0 +1,2 @@
1
+ import { n as expandRecordTemplates, r as PROTOCOL_TEMPLATED_LISTS, t as decodeProtocolPayloadLists } from "./protocol-record-templates-B0Ay3OCd.js";
2
+ export { PROTOCOL_TEMPLATED_LISTS, decodeProtocolPayloadLists, expandRecordTemplates };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markless/serializer",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Markless serialization tiers and resumability payload protocol.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -42,6 +42,10 @@
42
42
  "types": "./dist/protocol.d.ts",
43
43
  "default": "./dist/protocol.js"
44
44
  },
45
+ "./record-templates": {
46
+ "types": "./dist/record-templates.d.ts",
47
+ "default": "./dist/record-templates.js"
48
+ },
45
49
  "./protocol-validation": {
46
50
  "types": "./dist/protocol-validation.d.ts",
47
51
  "default": "./dist/protocol-validation.js"