@markless/serializer 0.1.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.
@@ -0,0 +1,251 @@
1
+ //#region src/protocol.d.ts
2
+ declare const ASYNC_PROTOCOL_VERSION = 1;
3
+ type ProtocolSyncPolicyCondition = {
4
+ readonly type: 'and';
5
+ readonly conditions: ReadonlyArray<ProtocolSyncPolicyCondition>;
6
+ } | {
7
+ readonly type: 'or';
8
+ readonly conditions: ReadonlyArray<ProtocolSyncPolicyCondition>;
9
+ } | {
10
+ readonly type: 'not';
11
+ readonly condition: ProtocolSyncPolicyCondition;
12
+ } | {
13
+ readonly type: 'graph-truthy';
14
+ readonly graphNodeId: string;
15
+ readonly path?: ReadonlyArray<string>;
16
+ } | {
17
+ readonly type: 'constant-truthy';
18
+ readonly value: unknown;
19
+ } | {
20
+ readonly type: 'event-equals';
21
+ readonly field: string;
22
+ readonly value: unknown;
23
+ };
24
+ type ProtocolSyncPolicyBranch = {
25
+ readonly when: ProtocolSyncPolicyCondition;
26
+ readonly actions: ReadonlyArray<'preventDefault' | 'stopPropagation'>;
27
+ };
28
+ type ProtocolSyncPolicy = ProtocolSyncPolicyBranch | {
29
+ readonly branches: ReadonlyArray<ProtocolSyncPolicyBranch>;
30
+ };
31
+ type ProtocolStatePayload = {
32
+ readonly version: typeof ASYNC_PROTOCOL_VERSION;
33
+ readonly cells: ReadonlyArray<{
34
+ readonly graphNodeId: string;
35
+ readonly name: string;
36
+ readonly valueKind: 'scalar' | 'object' | 'array' | 'unknown';
37
+ readonly value?: unknown;
38
+ readonly directValue?: unknown;
39
+ }>;
40
+ readonly computed: ReadonlyArray<{
41
+ readonly graphNodeId: string;
42
+ readonly name: string;
43
+ readonly async: boolean;
44
+ readonly dependencies?: ReadonlyArray<{
45
+ readonly graphNodeId: string;
46
+ readonly path: ReadonlyArray<string>;
47
+ }>;
48
+ readonly snapshot?: {
49
+ readonly status: 'idle';
50
+ readonly version: 0;
51
+ } | {
52
+ readonly status: 'pending';
53
+ readonly version: number;
54
+ readonly key: unknown;
55
+ } | {
56
+ readonly status: 'fulfilled';
57
+ readonly version: number;
58
+ readonly key: unknown;
59
+ readonly value: unknown;
60
+ } | {
61
+ readonly status: 'rejected';
62
+ readonly version: number;
63
+ readonly key: unknown;
64
+ readonly error: unknown;
65
+ };
66
+ }>;
67
+ readonly sharedDefinitions?: ReadonlyArray<{
68
+ readonly id: string;
69
+ readonly name: string;
70
+ readonly exportedName: string;
71
+ readonly scope?: 'request' | 'container' | 'page';
72
+ readonly version: number;
73
+ readonly graphNodeIds: ReadonlyArray<string>;
74
+ readonly dependencies?: ReadonlyArray<{
75
+ readonly definitionId: string;
76
+ readonly definitionName: string;
77
+ }>;
78
+ readonly returnProperties?: ReadonlyArray<{
79
+ readonly kind: 'graph';
80
+ readonly name: string;
81
+ readonly graphNodeId: string;
82
+ readonly path: ReadonlyArray<string>;
83
+ } | {
84
+ readonly kind: 'method';
85
+ readonly name: string;
86
+ }>;
87
+ }>;
88
+ };
89
+ type ProtocolArmBranchRecord = {
90
+ readonly id: string;
91
+ readonly testReads: ReadonlyArray<{
92
+ readonly source: string;
93
+ readonly graphNodeId: string;
94
+ readonly path: ReadonlyArray<string>;
95
+ }>;
96
+ readonly symbolId?: string;
97
+ readonly armTests?: ReadonlyArray<unknown>;
98
+ readonly declaredEmptyArms?: ReadonlyArray<number>;
99
+ readonly startAnchor?: {
100
+ readonly strategy: 'arm-branch-comment';
101
+ readonly index: number;
102
+ };
103
+ readonly endAnchor?: {
104
+ readonly strategy: 'arm-branch-comment';
105
+ readonly index: number;
106
+ };
107
+ readonly armRecords?: NonNullable<ProtocolViewPayload['branches']>[number]['armRecords'];
108
+ };
109
+ type ProtocolArmRecordSet = {
110
+ readonly locators: ReadonlyArray<{
111
+ readonly hostNodeId: string;
112
+ readonly strategy: 'arm-relative';
113
+ readonly index: number;
114
+ readonly tagName: string;
115
+ }>;
116
+ readonly events: ProtocolViewPayload['events'];
117
+ readonly behaviors: ProtocolViewPayload['behaviors'];
118
+ readonly elementHandles: ProtocolViewPayload['elementHandles'];
119
+ readonly branches?: ReadonlyArray<ProtocolArmBranchRecord>;
120
+ };
121
+ type ProtocolViewPayload = {
122
+ readonly version: typeof ASYNC_PROTOCOL_VERSION;
123
+ readonly locators: ReadonlyArray<{
124
+ readonly hostNodeId: string;
125
+ readonly strategy: 'dom-order';
126
+ readonly index: number;
127
+ readonly tagName: string;
128
+ }>;
129
+ readonly events: ReadonlyArray<{
130
+ readonly hostNodeId: string;
131
+ readonly eventName: string;
132
+ readonly syncPolicy?: ProtocolSyncPolicy;
133
+ readonly symbolIds: ReadonlyArray<string>;
134
+ }>;
135
+ readonly domUpdates: ReadonlyArray<{
136
+ readonly hostNodeId: string;
137
+ readonly source: string;
138
+ readonly graphNodeId: string;
139
+ readonly path: ReadonlyArray<string>;
140
+ readonly target?: {
141
+ readonly kind: 'text';
142
+ readonly prefix?: string;
143
+ readonly suffix?: string;
144
+ readonly trueValue?: string;
145
+ readonly falseValue?: string;
146
+ } | {
147
+ readonly kind: 'attribute';
148
+ readonly name: string;
149
+ } | {
150
+ readonly kind: 'property';
151
+ readonly name: string;
152
+ } | {
153
+ readonly kind: 'class';
154
+ readonly trueValue?: string;
155
+ readonly falseValue?: string;
156
+ } | {
157
+ readonly kind: 'style';
158
+ };
159
+ readonly symbolId?: string;
160
+ }>;
161
+ readonly behaviors: ReadonlyArray<{
162
+ readonly hostNodeId: string;
163
+ readonly source: string;
164
+ readonly functionSource: string;
165
+ readonly inputSources: ReadonlyArray<string>;
166
+ readonly inputValues?: ReadonlyArray<unknown>;
167
+ readonly inputGraphReads?: ReadonlyArray<{
168
+ readonly inputIndex: number;
169
+ readonly source: string;
170
+ readonly graphNodeId: string;
171
+ readonly path: ReadonlyArray<string>;
172
+ }>;
173
+ readonly symbolId?: string;
174
+ }>;
175
+ readonly elementHandles: ReadonlyArray<{
176
+ readonly hostNodeId: string;
177
+ readonly handleId: string;
178
+ readonly name: string;
179
+ }>;
180
+ readonly keyedRepeats?: ReadonlyArray<{
181
+ readonly id: string;
182
+ readonly parentHostNodeId: string;
183
+ readonly collectionGraphNodeId?: string;
184
+ readonly collectionPath: ReadonlyArray<string>;
185
+ readonly keyPath: ReadonlyArray<string>;
186
+ readonly itemName: string;
187
+ readonly rowElementCount: number;
188
+ readonly rowEvents: ReadonlyArray<{
189
+ readonly hostPath: ReadonlyArray<number>;
190
+ readonly eventName: string;
191
+ readonly symbolIds: ReadonlyArray<string>;
192
+ readonly syncPolicy?: ProtocolSyncPolicy;
193
+ }>;
194
+ }>;
195
+ readonly branches?: ReadonlyArray<{
196
+ readonly id: string;
197
+ readonly startAnchor: {
198
+ readonly strategy: 'dom-order-comment';
199
+ readonly index: number;
200
+ };
201
+ readonly endAnchor: {
202
+ readonly strategy: 'dom-order-comment';
203
+ readonly index: number;
204
+ };
205
+ readonly symbolId?: string;
206
+ readonly armTests?: ReadonlyArray<unknown>;
207
+ readonly armRecords?: ReadonlyArray<{
208
+ readonly events: ReadonlyArray<{
209
+ readonly hostPath: ReadonlyArray<number>;
210
+ readonly eventName: string;
211
+ readonly symbolIds: ReadonlyArray<string>;
212
+ readonly syncPolicy?: ProtocolSyncPolicy;
213
+ }>;
214
+ readonly domUpdates: ReadonlyArray<Record<string, unknown>>;
215
+ readonly behaviors: ReadonlyArray<Record<string, unknown>>;
216
+ readonly elementHandles: ReadonlyArray<Record<string, unknown>>;
217
+ }>;
218
+ readonly testReads?: ReadonlyArray<{
219
+ readonly source: string;
220
+ readonly graphNodeId: string;
221
+ readonly path: ReadonlyArray<string>;
222
+ }>;
223
+ }>;
224
+ readonly asyncBoundaries: ReadonlyArray<{
225
+ readonly id: string;
226
+ readonly updateSymbolId?: string;
227
+ readonly armRecords?: ProtocolArmRecordSet | ReadonlyArray<ProtocolArmRecordSet>;
228
+ readonly startAnchor: {
229
+ readonly strategy: 'dom-order-comment';
230
+ readonly index: number;
231
+ };
232
+ readonly endAnchor: {
233
+ readonly strategy: 'dom-order-comment';
234
+ readonly index: number;
235
+ };
236
+ readonly asyncReads: ReadonlyArray<{
237
+ readonly source: string;
238
+ readonly graphNodeId: string;
239
+ readonly path: ReadonlyArray<string>;
240
+ readonly runnerSymbolId?: string;
241
+ }>;
242
+ }>;
243
+ };
244
+ type ProtocolPayloadScripts = {
245
+ readonly state: ProtocolStatePayload;
246
+ readonly view: ProtocolViewPayload;
247
+ readonly stateScript: string;
248
+ readonly viewScript: string;
249
+ };
250
+ //#endregion
251
+ export { ASYNC_PROTOCOL_VERSION, ProtocolArmBranchRecord, ProtocolArmRecordSet, ProtocolPayloadScripts, ProtocolStatePayload, ProtocolSyncPolicy, ProtocolSyncPolicyBranch, ProtocolSyncPolicyCondition, ProtocolViewPayload };
@@ -0,0 +1,4 @@
1
+ //#region src/protocol.ts
2
+ const ASYNC_PROTOCOL_VERSION = 1;
3
+ //#endregion
4
+ export { ASYNC_PROTOCOL_VERSION };
@@ -0,0 +1,102 @@
1
+ //#region src/value-decode.d.ts
2
+ declare function deserializeGraphValue(payload: SerializedGraphPayload): unknown;
3
+ //#endregion
4
+ //#region src/value.d.ts
5
+ type SerializedPrimitive = null | string | number | boolean | {
6
+ readonly $type: 'undefined';
7
+ } | {
8
+ readonly $type: 'bigint';
9
+ readonly value: string;
10
+ };
11
+ type SerializedSlot = SerializedPrimitive | {
12
+ readonly $ref: number;
13
+ } | {
14
+ readonly $type: 'date';
15
+ readonly value: string;
16
+ } | {
17
+ readonly $type: 'regexp';
18
+ readonly source: string;
19
+ readonly flags: string;
20
+ } | {
21
+ readonly $type: 'url';
22
+ readonly value: string;
23
+ };
24
+ type SerializedRecord = {
25
+ readonly id: number;
26
+ readonly type: 'object';
27
+ readonly fields: ReadonlyArray<readonly [string, SerializedSlot]>;
28
+ } | {
29
+ readonly id: number;
30
+ readonly type: 'array';
31
+ readonly items: ReadonlyArray<SerializedSlot>;
32
+ } | {
33
+ readonly id: number;
34
+ readonly type: 'map';
35
+ readonly entries: ReadonlyArray<readonly [SerializedSlot, SerializedSlot]>;
36
+ } | {
37
+ readonly id: number;
38
+ readonly type: 'set';
39
+ readonly values: ReadonlyArray<SerializedSlot>;
40
+ } | {
41
+ readonly id: number;
42
+ readonly type: 'date';
43
+ readonly value: string;
44
+ } | {
45
+ readonly id: number;
46
+ readonly type: 'regexp';
47
+ readonly source: string;
48
+ readonly flags: string;
49
+ } | {
50
+ readonly id: number;
51
+ readonly type: 'url';
52
+ readonly value: string;
53
+ } | {
54
+ readonly id: number;
55
+ readonly type: 'array-buffer';
56
+ readonly bytes: ReadonlyArray<number>;
57
+ } | {
58
+ readonly id: number;
59
+ readonly type: 'typed-array';
60
+ readonly arrayType: TypedArrayName;
61
+ readonly buffer: SerializedSlot;
62
+ readonly byteOffset: number;
63
+ readonly length: number;
64
+ } | {
65
+ readonly id: number;
66
+ readonly type: 'data-view';
67
+ readonly buffer: SerializedSlot;
68
+ readonly byteOffset: number;
69
+ readonly byteLength: number;
70
+ };
71
+ type TypedArrayName = 'Int8Array' | 'Uint8Array' | 'Uint8ClampedArray' | 'Int16Array' | 'Uint16Array' | 'Int32Array' | 'Uint32Array' | 'Float32Array' | 'Float64Array' | 'BigInt64Array' | 'BigUint64Array';
72
+ type SerializedGraphPayload = {
73
+ readonly version: 1;
74
+ readonly root: SerializedSlot;
75
+ readonly records: ReadonlyArray<SerializedRecord>;
76
+ };
77
+ type SerializationDiagnostic = {
78
+ readonly code: 'MARKLESS_SERIALIZE_UNSUPPORTED_VALUE';
79
+ readonly severity: 'error';
80
+ readonly phase: 'serialization';
81
+ readonly title: 'Cannot serialize graph state value';
82
+ readonly path: ReadonlyArray<string>;
83
+ readonly statePath: string;
84
+ readonly valueKind: string;
85
+ readonly message: string;
86
+ readonly why: string;
87
+ readonly suggestions: ReadonlyArray<{
88
+ readonly message: string;
89
+ }>;
90
+ readonly docsUrl: string;
91
+ };
92
+ type SerializationResult = {
93
+ readonly ok: true;
94
+ readonly payload: SerializedGraphPayload;
95
+ readonly diagnostics: readonly [];
96
+ } | {
97
+ readonly ok: false;
98
+ readonly diagnostics: ReadonlyArray<SerializationDiagnostic>;
99
+ };
100
+ declare function serializeGraphValue(value: unknown): SerializationResult;
101
+ //#endregion
102
+ export { SerializedRecord as a, serializeGraphValue as c, SerializedPrimitive as i, deserializeGraphValue as l, SerializationResult as n, SerializedSlot as o, SerializedGraphPayload as r, TypedArrayName as s, SerializationDiagnostic as t };
@@ -0,0 +1,33 @@
1
+ //#region src/value-decode-extensions.ts
2
+ const valueDecodeExtensions = {
3
+ recordShell(record, shells) {
4
+ if (record.type === "regexp") return new RegExp(record.source, record.flags);
5
+ if (record.type === "url") return new URL(record.value);
6
+ if (record.type === "array-buffer") return new Uint8Array(record.bytes).buffer;
7
+ if (record.type === "typed-array") return createTypedArray(record, shells);
8
+ if (record.type === "data-view") return createDataView(record, shells);
9
+ },
10
+ slot(slot) {
11
+ if (typeof slot !== "object" || slot === null || !("$type" in slot)) return void 0;
12
+ if (slot.$type === "regexp") return new RegExp(slot.source, slot.flags);
13
+ if (slot.$type === "url") return new URL(slot.value);
14
+ }
15
+ };
16
+ function createTypedArray(record, shells) {
17
+ const buffer = decodeSlot(record.buffer, shells);
18
+ if (!(buffer instanceof ArrayBuffer)) return void 0;
19
+ const constructor = globalThis[record.arrayType];
20
+ return typeof constructor === "function" ? new constructor(buffer, record.byteOffset, record.length) : void 0;
21
+ }
22
+ function createDataView(record, shells) {
23
+ const buffer = decodeSlot(record.buffer, shells);
24
+ return buffer instanceof ArrayBuffer ? new DataView(buffer, record.byteOffset, record.byteLength) : void 0;
25
+ }
26
+ function decodeSlot(slot, shells) {
27
+ if (typeof slot !== "object" || slot === null) return slot;
28
+ if ("$ref" in slot) return shells.get(slot.$ref);
29
+ if (slot.$type === "regexp") return new RegExp(slot.source, slot.flags);
30
+ if (slot.$type === "url") return new URL(slot.value);
31
+ }
32
+ //#endregion
33
+ export { valueDecodeExtensions };
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@markless/serializer",
3
+ "version": "0.1.0",
4
+ "description": "Markless serialization tiers and resumability payload protocol.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/markless-dev/markless.git",
9
+ "directory": "packages/serializer"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "type": "module",
15
+ "sideEffects": false,
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ },
21
+ "./decode": {
22
+ "types": "./dist/decode.d.ts",
23
+ "default": "./dist/decode.js"
24
+ },
25
+ "./decode-client": {
26
+ "types": "./dist/decode-client.d.ts",
27
+ "default": "./dist/decode-client.js"
28
+ },
29
+ "./protocol": {
30
+ "types": "./dist/protocol.d.ts",
31
+ "default": "./dist/protocol.js"
32
+ },
33
+ "./protocol-validation": {
34
+ "types": "./dist/protocol-validation.d.ts",
35
+ "default": "./dist/protocol-validation.js"
36
+ }
37
+ },
38
+ "files": [
39
+ "dist"
40
+ ],
41
+ "scripts": {}
42
+ }