@oddington/sdk 0.1.60 → 0.1.62
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 +7 -0
- package/dist/browser.js +21 -15
- package/dist/index.js +2 -2
- package/dist/types/packages/sdk/src/data-schema-types.d.ts +14 -9
- package/dist/types/packages/sdk/src/public.d.ts +7 -1
- package/dist/types/shared/connections.d.ts +1 -1
- package/dist/types/shared/data-contract.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -420,6 +420,13 @@ When the definition selects its collection in `bodies`,
|
|
|
420
420
|
`$body`, without a hosted request. Ordinary reads, queries, pagination, counts
|
|
421
421
|
and nested links omit bodies. Unselected or unretained bodies stay absent;
|
|
422
422
|
a missing Record remains `null`.
|
|
423
|
+
Snapshot `records.all(query, { maxRecords, body: true })` includes exact retained
|
|
424
|
+
`$body` strings, including empty strings, on every selected Record occurrence
|
|
425
|
+
from a body-enabled collection, including expanded links. Other collections
|
|
426
|
+
remain body-free. This is one local bounded selection with the same projection,
|
|
427
|
+
query and graph bounds and required top-level ceiling; it adds no hosted calls
|
|
428
|
+
or per-Record reads. `$body` cannot be queried as a schema field. Ordinary
|
|
429
|
+
snapshot `all`, `query` and `pages`, and hosted Data `all`, remain structured-only.
|
|
423
430
|
Initialization never refreshes the hosted artifact. Sign-out, context replacement and expiry invalidate local reads.
|
|
424
431
|
Snapshot initialization requires a hosted browser app; Node, routines and local
|
|
425
432
|
app contexts receive `DataOperationError` with `context_unavailable`.
|
package/dist/browser.js
CHANGED
|
@@ -324,7 +324,7 @@ function validRecordRef(value) {
|
|
|
324
324
|
}
|
|
325
325
|
|
|
326
326
|
function validDropboxRootPath(value) {
|
|
327
|
-
return typeof value == "string" && value.length <= 2048 && value.startsWith("/") && !/[\\\x00-\x1f\x7f]/.test(value) && value.slice(1).split("/").every((segment) => segment.length > 0 && segment.trim() === segment && segment !== "." && segment !== "..");
|
|
327
|
+
return value === "" || typeof value == "string" && value.length <= 2048 && value.startsWith("/") && !/[\\\x00-\x1f\x7f]/.test(value) && value.slice(1).split("/").every((segment) => segment.length > 0 && segment.trim() === segment && segment !== "." && segment !== "..");
|
|
328
328
|
}
|
|
329
329
|
function validMicrosoftId(value) {
|
|
330
330
|
return typeof value == "string" && /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i.test(value);
|
|
@@ -2288,7 +2288,7 @@ function ordered(a, b, { field, direction }) {
|
|
|
2288
2288
|
let left = a[field], right = b[field], missingLeft = left == null, missingRight = right == null, result2 = 0;
|
|
2289
2289
|
return missingLeft !== missingRight ? missingLeft ? 1 : -1 : (!missingLeft && !missingRight && (result2 = typeof left == "number" && typeof right == "number" ? left - right : typeof left == "boolean" && typeof right == "boolean" ? Number(left) - Number(right) : compare2(left, right), direction === "desc" && (result2 = -result2)), result2 || compare2(a.$ref, b.$ref));
|
|
2290
2290
|
}
|
|
2291
|
-
function* evaluateRecordsQuery(query, catalogue, context, maxRecords, cloneValue) {
|
|
2291
|
+
function* evaluateRecordsQuery(query, catalogue, context, maxRecords, cloneValue, bodyCollections = []) {
|
|
2292
2292
|
let { version } = context, selections = planIndexQuery(query, catalogue), scanned = /* @__PURE__ */ new Map();
|
|
2293
2293
|
for (let { name: name2 } of selections) scanned.set(name2, yield { operation: "scan", collection: name2 });
|
|
2294
2294
|
if (maxRecords !== void 0 && selections.reduce((sum, { name: name2, selection: selection2 }) => sum + scanned.get(name2).filter((record4) => matches(record4, selection2)).length, 0) > maxRecords)
|
|
@@ -2300,13 +2300,13 @@ function* evaluateRecordsQuery(query, catalogue, context, maxRecords, cloneValue
|
|
|
2300
2300
|
{ code: "record_limit_exceeded", maxRecords, collections: selections.map((row) => row.name) }
|
|
2301
2301
|
);
|
|
2302
2302
|
let occurrences = 0;
|
|
2303
|
-
function* expand(record4, selection2, fragment) {
|
|
2303
|
+
function* expand(record4, collection, selection2, fragment) {
|
|
2304
2304
|
if (++occurrences > 2e3) return fail4("too many returned Record occurrences");
|
|
2305
2305
|
let result2 = Object.fromEntries(["$ref", "$version", ...selection2.fields.filter((field) => !["$ref", "$version"].includes(field))].filter((field) => Object.hasOwn(record4, field)).map((field) => [
|
|
2306
2306
|
field,
|
|
2307
2307
|
cloneValue(record4[field])
|
|
2308
2308
|
]));
|
|
2309
|
-
fragment !== void 0 && (result2.$fragment = fragment);
|
|
2309
|
+
bodyCollections.includes(collection) && typeof record4.$body == "string" && (result2.$body = record4.$body), fragment !== void 0 && (result2.$fragment = fragment);
|
|
2310
2310
|
for (let link of selection2.links) {
|
|
2311
2311
|
if (!Object.hasOwn(record4, link.name)) continue;
|
|
2312
2312
|
let value = record4[link.name], expanded;
|
|
@@ -2317,13 +2317,13 @@ function* evaluateRecordsQuery(query, catalogue, context, maxRecords, cloneValue
|
|
|
2317
2317
|
let { ref, fragment: fragment2 } = parseRecordLink(value2) ?? fail4("invalid stored link"), target = yield { operation: "lookup", ref };
|
|
2318
2318
|
if (!target) return fail4("unresolved stored link");
|
|
2319
2319
|
let nested = link.targets.get(target.collection) ?? fail4("incompatible stored link");
|
|
2320
|
-
matches(target.record, nested) && matching.push({ record: target.record, selection: nested, fragment: fragment2 });
|
|
2320
|
+
matches(target.record, nested) && matching.push({ record: target.record, collection: target.collection, selection: nested, fragment: fragment2 });
|
|
2321
2321
|
}
|
|
2322
2322
|
let options = link.targets.values().next().value;
|
|
2323
2323
|
if (options.explicitOrder && matching.sort((a, b) => ordered(a.record, b.record, options.order)), link.many && !options.explicitLimit && matching.length > 100) return fail4("too many matching linked Records");
|
|
2324
2324
|
options.explicitLimit && (matching = matching.slice(0, options.limit));
|
|
2325
2325
|
let records = [];
|
|
2326
|
-
for (let { record: record5, selection: selection3, fragment: fragment2 } of matching) records.push(yield* expand(record5, selection3, fragment2));
|
|
2326
|
+
for (let { record: record5, collection: collection2, selection: selection3, fragment: fragment2 } of matching) records.push(yield* expand(record5, collection2, selection3, fragment2));
|
|
2327
2327
|
expanded = link.many ? records : records[0] ?? null;
|
|
2328
2328
|
}
|
|
2329
2329
|
Object.defineProperty(result2, link.name, { value: expanded, enumerable: !0, writable: !0, configurable: !0 });
|
|
@@ -2334,7 +2334,7 @@ function* evaluateRecordsQuery(query, catalogue, context, maxRecords, cloneValue
|
|
|
2334
2334
|
for (let { name: name2, selection: selection2 } of selections) {
|
|
2335
2335
|
let matching = scanned.get(name2).filter((record4) => matches(record4, selection2)).sort((a, b) => ordered(a, b, selection2.order)), binding = indexSelectionBinding(context, name2, selection2), start = selection2.after === void 0 ? 0 : continuation(yield { operation: "open", token: selection2.after }, binding, matching, selection2.limit), end = maxRecords === void 0 ? Math.min(start + selection2.limit, matching.length) : matching.length, records = [];
|
|
2336
2336
|
for (let index = start; index < end; index++)
|
|
2337
|
-
maxRecords !== void 0 && (index - start) % selection2.limit === 0 && (occurrences = 0), records.push(yield* expand(matching[index], selection2));
|
|
2337
|
+
maxRecords !== void 0 && (index - start) % selection2.limit === 0 && (occurrences = 0), records.push(yield* expand(matching[index], name2, selection2));
|
|
2338
2338
|
let page = selection2.count ? { count: matching.length } : {};
|
|
2339
2339
|
if (maxRecords === void 0 && end < matching.length) {
|
|
2340
2340
|
let token = yield { operation: "seal", payload: { format: 1, binding, position: end, ref: matching[end - 1].$ref } };
|
|
@@ -2666,7 +2666,7 @@ async function openSnapshotStore() {
|
|
|
2666
2666
|
let transaction = database.transaction("changes", "readonly"), done = completed(transaction), rows = await request(transaction.objectStore("changes").get(installation.id));
|
|
2667
2667
|
return await done, !rows || rows.length !== installation.changeCount ? unavailable2() : rows;
|
|
2668
2668
|
},
|
|
2669
|
-
async query(installation, query, maxRecords) {
|
|
2669
|
+
async query(installation, query, maxRecords, body) {
|
|
2670
2670
|
let key = await crypto.subtle.importKey("raw", installation.cursorKey, "AES-GCM", !1, ["encrypt", "decrypt"]), transaction, done, records = () => (transaction || (transaction = database.transaction("records", "readonly"), done = completed(transaction)), transaction.objectStore("records")), finish = async () => {
|
|
2671
2671
|
await done, transaction = void 0, done = void 0;
|
|
2672
2672
|
}, evaluation = evaluateRecordsQuery(
|
|
@@ -2679,7 +2679,8 @@ async function openSnapshotStore() {
|
|
|
2679
2679
|
version: installation.version
|
|
2680
2680
|
},
|
|
2681
2681
|
maxRecords,
|
|
2682
|
-
(value) => value
|
|
2682
|
+
(value) => value,
|
|
2683
|
+
body ? installation.bodyCollections : void 0
|
|
2683
2684
|
);
|
|
2684
2685
|
try {
|
|
2685
2686
|
let step = evaluation.next();
|
|
@@ -2935,7 +2936,12 @@ function captureSelection(input) {
|
|
|
2935
2936
|
|
|
2936
2937
|
var invalid9 = () => {
|
|
2937
2938
|
throw new DataOperationError("invalid_query");
|
|
2938
|
-
}
|
|
2939
|
+
};
|
|
2940
|
+
function captureSnapshotAll(query, options) {
|
|
2941
|
+
let properties = dataProperties(options);
|
|
2942
|
+
return Object.keys(properties).some((key) => key !== "maxRecords" && key !== "body") || properties.body && properties.body.value !== !0 ? invalid9() : { ...captureRecordsAll(query, { maxRecords: properties.maxRecords?.value }), body: properties.body?.value === !0 };
|
|
2943
|
+
}
|
|
2944
|
+
var safeName = (value) => typeof value == "string" && /^[a-z0-9][a-z0-9._-]{0,127}$/.test(value) && !value.includes("..");
|
|
2939
2945
|
function createSnapshotInitializer(resolve = resolveSnapshotContext, open = openSnapshotStore, connect = (url, protocols) => new WebSocket(url, protocols)) {
|
|
2940
2946
|
let pending = /* @__PURE__ */ new WeakMap();
|
|
2941
2947
|
return async function(input) {
|
|
@@ -3072,7 +3078,7 @@ function createSnapshotInitializer(resolve = resolveSnapshotContext, open = open
|
|
|
3072
3078
|
} finally {
|
|
3073
3079
|
store?.close();
|
|
3074
3080
|
}
|
|
3075
|
-
}, query = async (query2, maxRecords) => {
|
|
3081
|
+
}, query = async (query2, maxRecords, body = !1) => {
|
|
3076
3082
|
let pinned = installation;
|
|
3077
3083
|
assertCurrent();
|
|
3078
3084
|
let captured = captureRecordsQuery(query2);
|
|
@@ -3085,7 +3091,7 @@ function createSnapshotInitializer(resolve = resolveSnapshotContext, open = open
|
|
|
3085
3091
|
let store;
|
|
3086
3092
|
try {
|
|
3087
3093
|
store = await open(), assertCurrent();
|
|
3088
|
-
let result2 = await store.query(pinned, captured, maxRecords);
|
|
3094
|
+
let result2 = await store.query(pinned, captured, maxRecords, body);
|
|
3089
3095
|
return assertCurrent(), result2;
|
|
3090
3096
|
} catch (error) {
|
|
3091
3097
|
throw assertCurrent(), error instanceof DataOperationError ? error : error instanceof RecordValidationError ? new DataOperationError("invalid_query") : new DataOperationError("unavailable", !0);
|
|
@@ -3147,9 +3153,9 @@ function createSnapshotInitializer(resolve = resolveSnapshotContext, open = open
|
|
|
3147
3153
|
},
|
|
3148
3154
|
query: queryRecords,
|
|
3149
3155
|
...recordPagination(queryRecords),
|
|
3150
|
-
all: (input2, options) => {
|
|
3151
|
-
let captured =
|
|
3152
|
-
return writes.then(() => query(captured.query, captured.maxRecords));
|
|
3156
|
+
all: async (input2, options) => {
|
|
3157
|
+
let captured = captureSnapshotAll(input2, options);
|
|
3158
|
+
return writes.then(() => query(captured.query, captured.maxRecords, captured.body));
|
|
3153
3159
|
}
|
|
3154
3160
|
} };
|
|
3155
3161
|
};
|