@storystick/preview 0.2.0-rc.3 → 0.2.0-rc.4
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/PUBLIC-API.md +2 -2
- package/dist/.source-hash +1 -1
- package/dist/runtime/live-query-overlay.js +66 -4
- package/package.json +4 -4
package/PUBLIC-API.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @storystick/preview API contract
|
|
2
2
|
|
|
3
|
-
Install this candidate explicitly with `@storystick/preview@0.2.0-rc.
|
|
3
|
+
Install this candidate explicitly with `@storystick/preview@0.2.0-rc.4` after registry bootstrap and publication. This repository alone does not make the candidate or beta channel available on npm.
|
|
4
4
|
|
|
5
|
-
Version 0.2.0-rc.
|
|
5
|
+
Version 0.2.0-rc.4, cohort `sdk-0.2.0-rc.4`. ESM distribution; no CommonJS or universal Edge compatibility is promised.
|
|
6
6
|
|
|
7
7
|
This package supports the integration facades; installing it directly is an advanced use. Reserved contracts are required between SDK packages and must be upgraded with the same cohort. Their public export paths do not promise independent stability.
|
|
8
8
|
|
package/dist/.source-hash
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
2860ff9dd781c6c748e99446abe4586964283410949a77842883c7b6dc5f5604
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { decodePreviewProvenanceText, encodePreviewProvenanceText } from '@storystick/types/internal/preview-provenance';
|
|
1
2
|
import { PREVIEW_LIVE_QUERY_MAX_QUERIES, PREVIEW_NAMESPACE, PREVIEW_PROTOCOL_VERSION, validatePreviewEnvelope, } from '@storystick/transport-allowlist';
|
|
2
3
|
import { estimatePreviewPayloadBytes, recordPreviewPerfMetric, } from './perf-metrics.js';
|
|
3
4
|
import { createPreviewRequestId } from './request-id.js';
|
|
@@ -94,9 +95,15 @@ export function createPreviewLiveQueryOverlayRuntime(options = {}) {
|
|
|
94
95
|
return;
|
|
95
96
|
const hadProjection = slot.projection !== null;
|
|
96
97
|
slot.receiptId = receiptId;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
// A receipt refresh does not change this query/context identity. Keep
|
|
99
|
+
// the already received rendering while Studio reauthorizes new sends;
|
|
100
|
+
// otherwise an older confirmed read briefly replaces a newer edit.
|
|
101
|
+
// Losing the receipt, capability, context or final retain still clears it.
|
|
102
|
+
if (receiptId === null) {
|
|
103
|
+
slot.projection = null;
|
|
104
|
+
if (hadProjection)
|
|
105
|
+
notify(slot);
|
|
106
|
+
}
|
|
100
107
|
if (receiptId !== null)
|
|
101
108
|
sendRegister(slot);
|
|
102
109
|
},
|
|
@@ -323,6 +330,10 @@ function updateProjectedPath(root, segments, entry) {
|
|
|
323
330
|
return root;
|
|
324
331
|
if (tail.length === 0) {
|
|
325
332
|
const hasCurrent = Object.prototype.hasOwnProperty.call(root, head);
|
|
333
|
+
// Model sidecars are keyed by authored path. Moving/replacing modeled
|
|
334
|
+
// slices needs a confirmed read with matching sidecars, not a field overlay.
|
|
335
|
+
if (modelReferences(root[head]) !== modelReferences(entry.present ? entry.value : undefined))
|
|
336
|
+
return root;
|
|
326
337
|
if (!entry.present) {
|
|
327
338
|
if (!hasCurrent)
|
|
328
339
|
return root;
|
|
@@ -332,7 +343,7 @@ function updateProjectedPath(root, segments, entry) {
|
|
|
332
343
|
}
|
|
333
344
|
if (hasCurrent && Object.is(root[head], entry.value))
|
|
334
345
|
return root;
|
|
335
|
-
return { ...root, [head]: entry.value };
|
|
346
|
+
return { ...root, [head]: carryTextAddresses(root[head], entry.value) };
|
|
336
347
|
}
|
|
337
348
|
const current = root[head];
|
|
338
349
|
if (!isRecord(current) && !entry.present)
|
|
@@ -343,3 +354,54 @@ function updateProjectedPath(root, segments, entry) {
|
|
|
343
354
|
function isRecord(value) {
|
|
344
355
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
345
356
|
}
|
|
357
|
+
function modelReferences(value) {
|
|
358
|
+
const references = [];
|
|
359
|
+
const visit = (item, path) => {
|
|
360
|
+
if (Array.isArray(item))
|
|
361
|
+
item.forEach((child, index) => visit(child, `${path}[${index}]`));
|
|
362
|
+
else if (isRecord(item)) {
|
|
363
|
+
if (typeof item._model === 'string')
|
|
364
|
+
references.push([path, item._key, item._type, item._model, item._variation]);
|
|
365
|
+
for (const key of Object.keys(item).sort())
|
|
366
|
+
visit(item[key], `${path}.${key}`);
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
visit(value, '');
|
|
370
|
+
return JSON.stringify(references);
|
|
371
|
+
}
|
|
372
|
+
/** Retain an existing complete-field edit address, never infer one for new data.
|
|
373
|
+
* Array items must keep their authored key and type; indexes are not identities. */
|
|
374
|
+
function carryTextAddresses(previous, next) {
|
|
375
|
+
if (typeof previous === 'string' && typeof next === 'string') {
|
|
376
|
+
const { segments } = decodePreviewProvenanceText(previous);
|
|
377
|
+
const segment = segments.length === 1 ? segments[0] : undefined;
|
|
378
|
+
return segment?.markerStart === 0 && segment.markerEnd === previous.length
|
|
379
|
+
? encodePreviewProvenanceText(segment.markerId, decodePreviewProvenanceText(next).text)
|
|
380
|
+
: next;
|
|
381
|
+
}
|
|
382
|
+
if (Array.isArray(previous) && Array.isArray(next)) {
|
|
383
|
+
const keyOf = (value) => isRecord(value) && typeof value._key === 'string'
|
|
384
|
+
? JSON.stringify([value._key, value._type ?? null]) : null;
|
|
385
|
+
const items = new Map();
|
|
386
|
+
const ambiguous = new Set();
|
|
387
|
+
for (const item of previous) {
|
|
388
|
+
const key = keyOf(item);
|
|
389
|
+
if (key === null)
|
|
390
|
+
continue;
|
|
391
|
+
if (items.has(key))
|
|
392
|
+
ambiguous.add(key);
|
|
393
|
+
items.set(key, item);
|
|
394
|
+
}
|
|
395
|
+
return next.map(item => {
|
|
396
|
+
const key = keyOf(item);
|
|
397
|
+
return key !== null && !ambiguous.has(key) ? carryTextAddresses(items.get(key), item) : item;
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
if (isRecord(previous) && isRecord(next)) {
|
|
401
|
+
// A replacement model/variation has different field ownership.
|
|
402
|
+
if (previous._type !== next._type || previous._model !== next._model || previous._variation !== next._variation)
|
|
403
|
+
return next;
|
|
404
|
+
return Object.fromEntries(Object.entries(next).map(([key, value]) => [key, carryTextAddresses(previous[key], value)]));
|
|
405
|
+
}
|
|
406
|
+
return next;
|
|
407
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storystick/preview",
|
|
3
|
-
"version": "0.2.0-rc.
|
|
3
|
+
"version": "0.2.0-rc.4",
|
|
4
4
|
"license": "FSL-1.1-MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -181,9 +181,9 @@
|
|
|
181
181
|
},
|
|
182
182
|
"dependencies": {
|
|
183
183
|
"convex": "1.42.3",
|
|
184
|
-
"@storystick/
|
|
185
|
-
"@storystick/
|
|
186
|
-
"@storystick/
|
|
184
|
+
"@storystick/client": "0.2.0-rc.4",
|
|
185
|
+
"@storystick/types": "0.1.0-rc.3",
|
|
186
|
+
"@storystick/transport-allowlist": "0.1.0-rc.3"
|
|
187
187
|
},
|
|
188
188
|
"devDependencies": {
|
|
189
189
|
"fake-indexeddb": "^6.2.5",
|