@tensorix/metahub 0.5.0 → 0.5.1
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/cli.js +5121 -14716
- package/dist/cli.js.map +3 -58
- package/dist/db-worker.js +96 -100
- package/dist/edge-worker.js +61 -61
- package/dist/index.js +2297 -11888
- package/dist/index.js.map +3 -58
- package/dist/webui-fmt-clang.js +1 -1
- package/dist/webui-fmt-sh.js +5 -5
- package/dist/webui-fmt.js +113 -113
- package/dist/webui.js +130 -130
- package/package.json +1 -1
package/dist/edge-worker.js
CHANGED
|
@@ -279,9 +279,9 @@ function lcs(a, b) {
|
|
|
279
279
|
const m = a.length;
|
|
280
280
|
const n = b.length;
|
|
281
281
|
const dp = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
|
|
282
|
-
for (let
|
|
283
|
-
for (let
|
|
284
|
-
dp[
|
|
282
|
+
for (let i = m - 1;i >= 0; i--)
|
|
283
|
+
for (let j = n - 1;j >= 0; j--)
|
|
284
|
+
dp[i][j] = a[i] === b[j] ? dp[i + 1][j + 1] + 1 : Math.max(dp[i + 1][j], dp[i][j + 1]);
|
|
285
285
|
const pairs = [];
|
|
286
286
|
let i = 0;
|
|
287
287
|
let j = 0;
|
|
@@ -463,8 +463,8 @@ function materialize(db, dataset, rowId, col, valueJson) {
|
|
|
463
463
|
if (dataset === "records") {
|
|
464
464
|
if (RECORD_META.has(col)) {
|
|
465
465
|
ensureRow(db, "records", rowId);
|
|
466
|
-
const
|
|
467
|
-
db.query(`UPDATE records SET "${col}" = ? WHERE id = ?`).run(encodeScalar(
|
|
466
|
+
const v = decodeMaterializeValue("records", col, valueJson);
|
|
467
|
+
db.query(`UPDATE records SET "${col}" = ? WHERE id = ?`).run(encodeScalar(v), rowId);
|
|
468
468
|
} else {
|
|
469
469
|
ensureRow(db, "records", rowId);
|
|
470
470
|
if (valueJson === null) {
|
|
@@ -603,7 +603,7 @@ function nextPosition(db, databaseId) {
|
|
|
603
603
|
const row = db.query("SELECT MAX(position) AS m FROM properties WHERE database_id = ? AND __deleted = 0").get(databaseId);
|
|
604
604
|
return (row.m ?? 0) + 1;
|
|
605
605
|
}
|
|
606
|
-
var addProperty = grouped(function
|
|
606
|
+
var addProperty = grouped(function addProperty(db, databaseId, opts) {
|
|
607
607
|
if (!getDatabase(db, databaseId))
|
|
608
608
|
throw new MhError("not_found", `no such database: ${databaseId}`);
|
|
609
609
|
if (!PROP_TYPES.has(opts.type))
|
|
@@ -633,7 +633,7 @@ function listProperties(db, databaseId) {
|
|
|
633
633
|
config: r.config ? JSON.parse(r.config) : null
|
|
634
634
|
}));
|
|
635
635
|
}
|
|
636
|
-
var updateProperty = grouped(function
|
|
636
|
+
var updateProperty = grouped(function updateProperty(db, id, fields) {
|
|
637
637
|
const cur = getProperty(db, id);
|
|
638
638
|
if (!cur)
|
|
639
639
|
throw new MhError("not_found", `no such property: ${id}`);
|
|
@@ -677,7 +677,7 @@ function getSelectProperty(db, id) {
|
|
|
677
677
|
throw new MhError("invalid_input", `${prop.type} property has no options`);
|
|
678
678
|
return { prop, options: prop.config?.options ?? [] };
|
|
679
679
|
}
|
|
680
|
-
var renameSelectOption = grouped(function
|
|
680
|
+
var renameSelectOption = grouped(function renameSelectOption(db, id, from, to) {
|
|
681
681
|
const { prop, options } = getSelectProperty(db, id);
|
|
682
682
|
to = to.trim();
|
|
683
683
|
if (!to)
|
|
@@ -710,7 +710,7 @@ var renameSelectOption = grouped(function renameSelectOption2(db, id, from, to)
|
|
|
710
710
|
}
|
|
711
711
|
return { property: getProperty(db, id), renamed };
|
|
712
712
|
});
|
|
713
|
-
var removeSelectOption = grouped(function
|
|
713
|
+
var removeSelectOption = grouped(function removeSelectOption(db, id, name) {
|
|
714
714
|
const { prop, options } = getSelectProperty(db, id);
|
|
715
715
|
if (!options.includes(name))
|
|
716
716
|
throw new MhError("not_found", `no such option: ${name}`);
|
|
@@ -738,7 +738,7 @@ var removeSelectOption = grouped(function removeSelectOption2(db, id, name) {
|
|
|
738
738
|
}
|
|
739
739
|
return { property: getProperty(db, id), cleared };
|
|
740
740
|
});
|
|
741
|
-
var removeProperty = grouped(function
|
|
741
|
+
var removeProperty = grouped(function removeProperty(db, id) {
|
|
742
742
|
const prop = getProperty(db, id);
|
|
743
743
|
if (!prop)
|
|
744
744
|
return false;
|
|
@@ -1041,7 +1041,7 @@ function rebalanceRecordOrderKeys(db, databaseId) {
|
|
|
1041
1041
|
emit(db, "records", row.id, "order_key", keys[i]);
|
|
1042
1042
|
});
|
|
1043
1043
|
}
|
|
1044
|
-
var backfillRecordOrderKeys = grouped(function
|
|
1044
|
+
var backfillRecordOrderKeys = grouped(function backfillRecordOrderKeys(db, databaseId) {
|
|
1045
1045
|
const emitChange = canEmitOrderKeys(db);
|
|
1046
1046
|
const dbRows = databaseId ? [{ database_id: databaseId }] : db.query(`SELECT DISTINCT database_id FROM records
|
|
1047
1047
|
WHERE database_id IS NOT NULL AND __deleted = 0 AND order_key IS NULL`).all();
|
|
@@ -1056,7 +1056,7 @@ var backfillRecordOrderKeys = grouped(function backfillRecordOrderKeys2(db, data
|
|
|
1056
1056
|
missing.forEach((row, i) => writeRecordOrderKey(db, row.id, keys[i], emitChange));
|
|
1057
1057
|
}
|
|
1058
1058
|
});
|
|
1059
|
-
var createRecordPrepared = grouped(function
|
|
1059
|
+
var createRecordPrepared = grouped(function createRecordPrepared(db, database, cells) {
|
|
1060
1060
|
const id = deriveTitle(cells, slugify(database.name, "rec"));
|
|
1061
1061
|
const orderKey = keyBetween(lastRecordOrderKey(db, database.id), null);
|
|
1062
1062
|
const first = emit(db, "records", id, "database_id", database.id);
|
|
@@ -1066,7 +1066,7 @@ var createRecordPrepared = grouped(function createRecordPrepared2(db, database,
|
|
|
1066
1066
|
emit(db, "records", id, prop.id, value);
|
|
1067
1067
|
return getRecord(db, id);
|
|
1068
1068
|
});
|
|
1069
|
-
var createRecord = grouped(function
|
|
1069
|
+
var createRecord = grouped(function createRecord(db, databaseId, data) {
|
|
1070
1070
|
const database = getDatabase(db, databaseId);
|
|
1071
1071
|
if (!database)
|
|
1072
1072
|
throw new MhError("not_found", `no such database: ${databaseId}`);
|
|
@@ -1098,7 +1098,7 @@ function listRecords(db, databaseId, opts = {}) {
|
|
|
1098
1098
|
key = key.slice(1);
|
|
1099
1099
|
}
|
|
1100
1100
|
if (key !== "created" && key !== "created_hlc") {
|
|
1101
|
-
let p = props.find((
|
|
1101
|
+
let p = props.find((p) => p.id === key);
|
|
1102
1102
|
if (!p) {
|
|
1103
1103
|
const matches = props.filter((q) => q.name.toLowerCase() === key.toLowerCase());
|
|
1104
1104
|
if (matches.length > 1)
|
|
@@ -1136,7 +1136,7 @@ function listRecords(db, databaseId, opts = {}) {
|
|
|
1136
1136
|
}
|
|
1137
1137
|
return rows;
|
|
1138
1138
|
}
|
|
1139
|
-
var moveRecord = grouped(function
|
|
1139
|
+
var moveRecord = grouped(function moveRecord(db, id, targetId, where) {
|
|
1140
1140
|
if (where !== "before" && where !== "after")
|
|
1141
1141
|
throw new MhError("invalid_input", `unknown move position: ${where}`);
|
|
1142
1142
|
const src = db.query("SELECT id, database_id FROM records WHERE id = ? AND __deleted = 0").get(id);
|
|
@@ -1166,7 +1166,7 @@ var moveRecord = grouped(function moveRecord2(db, id, targetId, where) {
|
|
|
1166
1166
|
emit(db, "records", id, "order_key", keyBetween(left, right));
|
|
1167
1167
|
return getRecord(db, id);
|
|
1168
1168
|
});
|
|
1169
|
-
var updateRecordPrepared = grouped(function
|
|
1169
|
+
var updateRecordPrepared = grouped(function updateRecordPrepared(db, id, cells) {
|
|
1170
1170
|
const rec = db.query("SELECT id, database_id, data FROM records WHERE id = ? AND __deleted = 0").get(id);
|
|
1171
1171
|
if (!rec)
|
|
1172
1172
|
throw new MhError("not_found", `no such record: ${id}`);
|
|
@@ -1179,13 +1179,13 @@ var updateRecordPrepared = grouped(function updateRecordPrepared2(db, id, cells)
|
|
|
1179
1179
|
}
|
|
1180
1180
|
return getRecord(db, id);
|
|
1181
1181
|
});
|
|
1182
|
-
var updateRecord = grouped(function
|
|
1182
|
+
var updateRecord = grouped(function updateRecord(db, id, data) {
|
|
1183
1183
|
const rec = db.query("SELECT id, database_id FROM records WHERE id = ? AND __deleted = 0").get(id);
|
|
1184
1184
|
if (!rec)
|
|
1185
1185
|
throw new MhError("not_found", `no such record: ${id}`);
|
|
1186
1186
|
return updateRecordPrepared(db, id, prepareRecordCells(db, rec.database_id, data));
|
|
1187
1187
|
});
|
|
1188
|
-
var deleteRecord = grouped(function
|
|
1188
|
+
var deleteRecord = grouped(function deleteRecord(db, id) {
|
|
1189
1189
|
const rec = db.query("SELECT id FROM records WHERE id = ? AND __deleted = 0").get(id);
|
|
1190
1190
|
if (!rec)
|
|
1191
1191
|
return false;
|
|
@@ -1201,7 +1201,7 @@ function rowOut(r) {
|
|
|
1201
1201
|
return null;
|
|
1202
1202
|
return { ...r, meta: r.meta === null ? null : JSON.parse(r.meta) };
|
|
1203
1203
|
}
|
|
1204
|
-
var createDatabase = grouped(function
|
|
1204
|
+
var createDatabase = grouped(function createDatabase(db, opts) {
|
|
1205
1205
|
const id = newId("db", opts.name);
|
|
1206
1206
|
const first = emit(db, "databases", id, "name", opts.name);
|
|
1207
1207
|
emit(db, "databases", id, "created_hlc", first.hlc);
|
|
@@ -1209,7 +1209,7 @@ var createDatabase = grouped(function createDatabase2(db, opts) {
|
|
|
1209
1209
|
emit(db, "databases", id, "icon", opts.icon);
|
|
1210
1210
|
return getDatabase(db, id);
|
|
1211
1211
|
});
|
|
1212
|
-
var updateDatabase = grouped(function
|
|
1212
|
+
var updateDatabase = grouped(function updateDatabase(db, id, fields) {
|
|
1213
1213
|
if (!getDatabase(db, id))
|
|
1214
1214
|
throw new MhError("not_found", `no such database: ${id}`);
|
|
1215
1215
|
if (fields.name !== undefined)
|
|
@@ -1223,7 +1223,7 @@ var updateDatabase = grouped(function updateDatabase2(db, id, fields) {
|
|
|
1223
1223
|
}
|
|
1224
1224
|
return getDatabase(db, id);
|
|
1225
1225
|
});
|
|
1226
|
-
var duplicateDatabase = grouped(function
|
|
1226
|
+
var duplicateDatabase = grouped(function duplicateDatabase(db, id, opts = {}) {
|
|
1227
1227
|
const src = getDatabase(db, id);
|
|
1228
1228
|
if (!src)
|
|
1229
1229
|
throw new MhError("not_found", `no such database: ${id}`);
|
|
@@ -1275,7 +1275,7 @@ var duplicateDatabase = grouped(function duplicateDatabase2(db, id, opts = {}) {
|
|
|
1275
1275
|
function getDatabase(db, id) {
|
|
1276
1276
|
return rowOut(db.query(`SELECT ${DATABASE_SELECT} FROM databases WHERE id = ? AND __deleted = 0`).get(id));
|
|
1277
1277
|
}
|
|
1278
|
-
var deleteDatabase = grouped(function
|
|
1278
|
+
var deleteDatabase = grouped(function deleteDatabase(db, id) {
|
|
1279
1279
|
if (!getDatabase(db, id))
|
|
1280
1280
|
return false;
|
|
1281
1281
|
emit(db, "databases", id, "__deleted", 1);
|
|
@@ -1599,14 +1599,14 @@ function prepareIntent(db, policy, principal, intent, clock) {
|
|
|
1599
1599
|
if (intent.action === "createRecord") {
|
|
1600
1600
|
if (!intent.table || typeof intent.table !== "string")
|
|
1601
1601
|
throw new MhError("invalid_input", "createRecord intent needs a table");
|
|
1602
|
-
const
|
|
1603
|
-
const
|
|
1602
|
+
const database = authorizeDbRef(db, policy.grants, intent.table, "create");
|
|
1603
|
+
const cells = assertGuestPayload(db, policy.grants, principal, database, intent.payload, { limits: policy.limits });
|
|
1604
1604
|
return {
|
|
1605
1605
|
action: intent.action,
|
|
1606
|
-
database
|
|
1607
|
-
cells
|
|
1606
|
+
database,
|
|
1607
|
+
cells,
|
|
1608
1608
|
targetLive: true,
|
|
1609
|
-
fingerprint: fingerprintIntent(intent.action,
|
|
1609
|
+
fingerprint: fingerprintIntent(intent.action, database.id, clock === "submitted" ? intent.recordId ?? null : null, cells)
|
|
1610
1610
|
};
|
|
1611
1611
|
}
|
|
1612
1612
|
if (intent.action !== "updateRecord")
|
|
@@ -1752,10 +1752,10 @@ function isRecordRow(value) {
|
|
|
1752
1752
|
return typeof row.id === "string" && typeof row.database_id === "string" && !!row.values && typeof row.values === "object" && !Array.isArray(row.values) && !!row.cells && typeof row.cells === "object" && !Array.isArray(row.cells);
|
|
1753
1753
|
}
|
|
1754
1754
|
function clampMillis(submittedAt, now) {
|
|
1755
|
-
const
|
|
1756
|
-
const ceil =
|
|
1755
|
+
const safeNow = Math.max(0, Math.trunc(Number.isFinite(now) ? now : Date.now()));
|
|
1756
|
+
const ceil = safeNow + HLC_SKEW_MS;
|
|
1757
1757
|
if (!Number.isFinite(submittedAt))
|
|
1758
|
-
return
|
|
1758
|
+
return safeNow;
|
|
1759
1759
|
return Math.max(0, Math.min(Math.trunc(submittedAt), ceil));
|
|
1760
1760
|
}
|
|
1761
1761
|
function seedCounter(db, node, millis) {
|
|
@@ -1795,12 +1795,12 @@ function stableStringify(value) {
|
|
|
1795
1795
|
|
|
1796
1796
|
// src/core/sync/anti-abuse.ts
|
|
1797
1797
|
function timingSafeEq(a, b) {
|
|
1798
|
-
const
|
|
1798
|
+
const ab = new TextEncoder().encode(a);
|
|
1799
1799
|
const bb = new TextEncoder().encode(b);
|
|
1800
|
-
let diff =
|
|
1801
|
-
const n = Math.max(
|
|
1800
|
+
let diff = ab.length ^ bb.length;
|
|
1801
|
+
const n = Math.max(ab.length, bb.length);
|
|
1802
1802
|
for (let i = 0;i < n; i++)
|
|
1803
|
-
diff |= (
|
|
1803
|
+
diff |= (ab[i] ?? 0) ^ (bb[i] ?? 0);
|
|
1804
1804
|
return diff === 0;
|
|
1805
1805
|
}
|
|
1806
1806
|
var siteverify = async (secret, token, ip) => {
|
|
@@ -2081,7 +2081,7 @@ function assertVisibility(v) {
|
|
|
2081
2081
|
if (v !== "public" && v !== "private")
|
|
2082
2082
|
throw new MhError("invalid_input", `visibility must be "public" or "private", got ${JSON.stringify(v)}`);
|
|
2083
2083
|
}
|
|
2084
|
-
var createSite = grouped(function
|
|
2084
|
+
var createSite = grouped(function createSite(db, opts) {
|
|
2085
2085
|
const name = normalizeSiteName(opts.name);
|
|
2086
2086
|
if (getSiteByName(db, name))
|
|
2087
2087
|
throw new MhError("conflict", `site name already exists: ${name}`);
|
|
@@ -2096,7 +2096,7 @@ var createSite = grouped(function createSite2(db, opts) {
|
|
|
2096
2096
|
emit(db, "sites", id, "visibility", opts.visibility);
|
|
2097
2097
|
return getSite(db, id);
|
|
2098
2098
|
});
|
|
2099
|
-
var updateSite = grouped(function
|
|
2099
|
+
var updateSite = grouped(function updateSite(db, id, opts) {
|
|
2100
2100
|
if (!getSite(db, id))
|
|
2101
2101
|
throw new MhError("not_found", `no such site: ${id}`);
|
|
2102
2102
|
if (opts.visibility !== undefined)
|
|
@@ -2116,14 +2116,14 @@ var updateSite = grouped(function updateSite2(db, id, opts) {
|
|
|
2116
2116
|
emit(db, "sites", id, "spa", opts.spa ? 1 : 0);
|
|
2117
2117
|
return getSite(db, id);
|
|
2118
2118
|
});
|
|
2119
|
-
var setSitePublicGrants = grouped(function
|
|
2119
|
+
var setSitePublicGrants = grouped(function setSitePublicGrants(db, siteId, grants) {
|
|
2120
2120
|
if (!getSite(db, siteId))
|
|
2121
2121
|
throw new MhError("not_found", `no such site: ${siteId}`);
|
|
2122
2122
|
const value = grants == null ? null : serializeGrantSet(validateGrantSetInput(grants));
|
|
2123
2123
|
emit(db, "sites", siteId, "public_grants", value);
|
|
2124
2124
|
return getSite(db, siteId);
|
|
2125
2125
|
});
|
|
2126
|
-
var deleteSite = grouped(function
|
|
2126
|
+
var deleteSite = grouped(function deleteSite(db, id) {
|
|
2127
2127
|
if (!getSite(db, id))
|
|
2128
2128
|
return false;
|
|
2129
2129
|
const files = db.query("SELECT id FROM site_files WHERE site_id = ? AND __deleted = 0").all(id);
|
|
@@ -2136,7 +2136,7 @@ function fileIdFor(db, siteId, path) {
|
|
|
2136
2136
|
const row = db.query("SELECT id FROM site_files WHERE site_id = ? AND path = ? ORDER BY created_hlc LIMIT 1").get(siteId, path);
|
|
2137
2137
|
return row?.id ?? null;
|
|
2138
2138
|
}
|
|
2139
|
-
var deleteFile = grouped(function
|
|
2139
|
+
var deleteFile = grouped(function deleteFile(db, siteId, path) {
|
|
2140
2140
|
const id = fileIdFor(db, siteId, normalizeSitePath(path));
|
|
2141
2141
|
if (!id)
|
|
2142
2142
|
return false;
|
|
@@ -2600,7 +2600,7 @@ function documentVersion(db, id) {
|
|
|
2600
2600
|
OR (dataset = 'doc_blocks' AND row_id IN (SELECT id FROM doc_blocks WHERE doc_id = ?))`).get(id, id);
|
|
2601
2601
|
return row.h ?? "";
|
|
2602
2602
|
}
|
|
2603
|
-
var createDocument = grouped(function
|
|
2603
|
+
var createDocument = grouped(function createDocument(db, opts) {
|
|
2604
2604
|
const id = newId("doc", opts.title);
|
|
2605
2605
|
const first = emit(db, "documents", id, "title", opts.title);
|
|
2606
2606
|
emit(db, "documents", id, "created_hlc", first.hlc);
|
|
@@ -2664,7 +2664,7 @@ function backfillSiblings(db, parentId) {
|
|
|
2664
2664
|
db.query("UPDATE documents SET order_key = ? WHERE id = ?").run(keys[i], row.id);
|
|
2665
2665
|
});
|
|
2666
2666
|
}
|
|
2667
|
-
var backfillDocumentOrderKeys = grouped(function
|
|
2667
|
+
var backfillDocumentOrderKeys = grouped(function backfillDocumentOrderKeys(db) {
|
|
2668
2668
|
const parents = db.query("SELECT DISTINCT parent_id FROM documents WHERE __deleted = 0 AND order_key IS NULL").all();
|
|
2669
2669
|
for (const p of parents)
|
|
2670
2670
|
backfillSiblings(db, p.parent_id);
|
|
@@ -2700,7 +2700,7 @@ function placeInSiblings(db, id, parentId, anchor) {
|
|
|
2700
2700
|
}
|
|
2701
2701
|
emit(db, "documents", id, "order_key", key);
|
|
2702
2702
|
}
|
|
2703
|
-
var moveDocument = grouped(function
|
|
2703
|
+
var moveDocument = grouped(function moveDocument(db, id, targetId, where) {
|
|
2704
2704
|
const src = getDocument(db, id);
|
|
2705
2705
|
if (!src)
|
|
2706
2706
|
throw new MhError("not_found", `no such document: ${id}`);
|
|
@@ -2715,7 +2715,7 @@ var moveDocument = grouped(function moveDocument2(db, id, targetId, where) {
|
|
|
2715
2715
|
placeInSiblings(db, id, target.parent_id, { targetId, where });
|
|
2716
2716
|
return getDocument(db, id);
|
|
2717
2717
|
});
|
|
2718
|
-
var duplicateDocument = grouped(function
|
|
2718
|
+
var duplicateDocument = grouped(function duplicateDocument(db, id, opts = {}) {
|
|
2719
2719
|
const src = getDocument(db, id);
|
|
2720
2720
|
if (!src)
|
|
2721
2721
|
throw new MhError("not_found", `no such document: ${id}`);
|
|
@@ -2733,7 +2733,7 @@ var duplicateDocument = grouped(function duplicateDocument2(db, id, opts = {}) {
|
|
|
2733
2733
|
moveDocument(db, dup.id, src.id, "after");
|
|
2734
2734
|
return getDocument(db, dup.id);
|
|
2735
2735
|
});
|
|
2736
|
-
var updateDocument = grouped(function
|
|
2736
|
+
var updateDocument = grouped(function updateDocument(db, id, fields, opts = {}) {
|
|
2737
2737
|
const doc = getDocument(db, id);
|
|
2738
2738
|
if (!doc)
|
|
2739
2739
|
throw new MhError("not_found", `no such document: ${id}`);
|
|
@@ -2754,7 +2754,7 @@ var updateDocument = grouped(function updateDocument2(db, id, fields, opts = {})
|
|
|
2754
2754
|
}
|
|
2755
2755
|
return getDocument(db, id);
|
|
2756
2756
|
});
|
|
2757
|
-
var editDocument = grouped(function
|
|
2757
|
+
var editDocument = grouped(function editDocument(db, id, opts) {
|
|
2758
2758
|
if (!getDocument(db, id))
|
|
2759
2759
|
throw new MhError("not_found", `no such document: ${id}`);
|
|
2760
2760
|
if (opts.ifMatch !== undefined && documentVersion(db, id) !== opts.ifMatch)
|
|
@@ -2792,7 +2792,7 @@ var editDocument = grouped(function editDocument2(db, id, opts) {
|
|
|
2792
2792
|
reconcileBody(db, id, newBody);
|
|
2793
2793
|
return { id, changed: newBody !== body, replaced: opts.replaceAll ? count : 1, version: documentVersion(db, id) };
|
|
2794
2794
|
});
|
|
2795
|
-
var editDocumentBatch = grouped(function
|
|
2795
|
+
var editDocumentBatch = grouped(function editDocumentBatch(db, id, opts) {
|
|
2796
2796
|
if (!getDocument(db, id))
|
|
2797
2797
|
throw new MhError("not_found", `no such document: ${id}`);
|
|
2798
2798
|
if (opts.edits.length === 0)
|
|
@@ -2819,7 +2819,7 @@ var editDocumentBatch = grouped(function editDocumentBatch2(db, id, opts) {
|
|
|
2819
2819
|
reconcileBody(db, id, body);
|
|
2820
2820
|
return { id, changed: body !== orig, replaced: total, version: documentVersion(db, id) };
|
|
2821
2821
|
});
|
|
2822
|
-
var appendDocument = grouped(function
|
|
2822
|
+
var appendDocument = grouped(function appendDocument(db, id, body) {
|
|
2823
2823
|
if (!getDocument(db, id))
|
|
2824
2824
|
throw new MhError("not_found", `no such document: ${id}`);
|
|
2825
2825
|
ensureBlocks(db, id);
|
|
@@ -2831,7 +2831,7 @@ var appendDocument = grouped(function appendDocument2(db, id, body) {
|
|
|
2831
2831
|
}
|
|
2832
2832
|
return { id, changed: next.length > 0, replaced: next.length, version: documentVersion(db, id) };
|
|
2833
2833
|
});
|
|
2834
|
-
var prependDocument = grouped(function
|
|
2834
|
+
var prependDocument = grouped(function prependDocument(db, id, body) {
|
|
2835
2835
|
if (!getDocument(db, id))
|
|
2836
2836
|
throw new MhError("not_found", `no such document: ${id}`);
|
|
2837
2837
|
ensureBlocks(db, id);
|
|
@@ -2843,7 +2843,7 @@ var prependDocument = grouped(function prependDocument2(db, id, body) {
|
|
|
2843
2843
|
}
|
|
2844
2844
|
return { id, changed: next.length > 0, replaced: next.length, version: documentVersion(db, id) };
|
|
2845
2845
|
});
|
|
2846
|
-
var deleteDocument = grouped(function
|
|
2846
|
+
var deleteDocument = grouped(function deleteDocument(db, id) {
|
|
2847
2847
|
if (!getDocument(db, id))
|
|
2848
2848
|
return false;
|
|
2849
2849
|
emit(db, "documents", id, "__deleted", 1);
|
|
@@ -3543,7 +3543,7 @@ function createRoomFetch(deps) {
|
|
|
3543
3543
|
if (!body || typeof body.guestBase !== "string" || body.guestBase === "")
|
|
3544
3544
|
return json({ error: "provision needs a guestBase", code: "invalid_input" }, 400);
|
|
3545
3545
|
const str = (v) => typeof v === "string" && v !== "" ? v : null;
|
|
3546
|
-
const
|
|
3546
|
+
const cfg = initRoomDb(db, {
|
|
3547
3547
|
slug: typeof body.slug === "string" && body.slug !== "" ? body.slug : pathSlug,
|
|
3548
3548
|
guestBase: body.guestBase,
|
|
3549
3549
|
grants: str(body.grants) ?? "",
|
|
@@ -3551,11 +3551,11 @@ function createRoomFetch(deps) {
|
|
|
3551
3551
|
pwSalt: str(body.pwSalt),
|
|
3552
3552
|
expiresAt: typeof body.expiresAt === "number" ? body.expiresAt : null
|
|
3553
3553
|
});
|
|
3554
|
-
await deps.setAlarm?.(
|
|
3555
|
-
return json({ slug:
|
|
3554
|
+
await deps.setAlarm?.(cfg.expiresAt ?? null);
|
|
3555
|
+
return json({ slug: cfg.slug, room_node: cfg.roomNode, provisioned: true });
|
|
3556
3556
|
}
|
|
3557
|
-
const
|
|
3558
|
-
if (!
|
|
3557
|
+
const cfg = tryConfig(db);
|
|
3558
|
+
if (!cfg)
|
|
3559
3559
|
return json({ error: "room is not provisioned", code: "not_found" }, 404);
|
|
3560
3560
|
if (sub === "owner/sync") {
|
|
3561
3561
|
const body = await req.json().catch(() => null);
|
|
@@ -3563,7 +3563,7 @@ function createRoomFetch(deps) {
|
|
|
3563
3563
|
return json({ error: "malformed sync request", code: "invalid_input" }, 400);
|
|
3564
3564
|
await hlcHeadroom(db, deps);
|
|
3565
3565
|
try {
|
|
3566
|
-
const resp = handleOwnerSync(db, body,
|
|
3566
|
+
const resp = handleOwnerSync(db, body, cfg);
|
|
3567
3567
|
if (resp.share_state === "active" && body.changes.length > 0)
|
|
3568
3568
|
deps.poke?.(maxSeq(db));
|
|
3569
3569
|
return json(resp);
|
|
@@ -3662,10 +3662,10 @@ function serveRoomFile(db, cfg, path) {
|
|
|
3662
3662
|
if (row.encoding === "utf8")
|
|
3663
3663
|
return new Response(row.content ?? "", { status, headers });
|
|
3664
3664
|
if (row.encoding === "base64") {
|
|
3665
|
-
const
|
|
3666
|
-
const
|
|
3667
|
-
|
|
3668
|
-
return new Response(
|
|
3665
|
+
const bytes = base64ToBytes(row.content ?? "");
|
|
3666
|
+
const body = new Uint8Array(bytes.byteLength);
|
|
3667
|
+
body.set(bytes);
|
|
3668
|
+
return new Response(body.buffer, { status, headers });
|
|
3669
3669
|
}
|
|
3670
3670
|
const bytes = row.content ? roomBlobBytes(db, row.content) : null;
|
|
3671
3671
|
if (!bytes)
|
|
@@ -4066,8 +4066,8 @@ var edge_worker_default = {
|
|
|
4066
4066
|
if (slug === null)
|
|
4067
4067
|
return new Response("bad request", { status: 400 });
|
|
4068
4068
|
const id = env.ROOM.idFromName(slug);
|
|
4069
|
-
const
|
|
4070
|
-
return cors ? corsResponse(
|
|
4069
|
+
const res = await env.ROOM.get(id).fetch(req);
|
|
4070
|
+
return cors ? corsResponse(res) : res;
|
|
4071
4071
|
}
|
|
4072
4072
|
const res = await createInboxFetch({ sql: d1Sql(env.DB), ownerToken: env.OWNER_TOKEN })(req);
|
|
4073
4073
|
return cors ? corsResponse(res) : res;
|