@lunora/do 1.0.0-alpha.7 → 1.0.0-alpha.71
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/LICENSE.md +6 -0
- package/dist/index.d.mts +3394 -5259
- package/dist/index.d.ts +3394 -5259
- package/dist/index.mjs +1 -36
- package/dist/packem_shared/ROOT_DO_SIZE_WARN_BYTES-Bze_kj6L.mjs +13 -0
- package/dist/packem_shared/SESSION_DO_TTL_DEFAULT-Dan63qLN.mjs +1 -0
- package/dist/packem_shared/SHARD_REGISTRY_DO_NAME-tOQVzDCB.mjs +1 -0
- package/dist/packem_shared/constant-time-equal-BVG05Guz.mjs +1 -0
- package/dist/packem_shared/json-response-wrh9TBPw.mjs +1 -0
- package/dist/packem_shared/serveRelationFanout-Cbmlso1k.mjs +1 -0
- package/package.json +6 -2
- package/dist/packem_shared/ADMIN_FUNCTIONS-CHcC8fKV.mjs +0 -314
- package/dist/packem_shared/AGGREGATE_SQL_FUNCTION-CFk6adSu.mjs +0 -54
- package/dist/packem_shared/AUTH_METRICS_BUCKETS_TABLE-CiHHYeJi.mjs +0 -84
- package/dist/packem_shared/CDC_LOG_TABLE-Ctdmxmrv.mjs +0 -103
- package/dist/packem_shared/ConflictError-C0STs6bU.mjs +0 -13
- package/dist/packem_shared/CountRlsUnsupportedError-28ZvvwKS.mjs +0 -133
- package/dist/packem_shared/DATA_MIGRATION_STATE_TABLE-PTtTiQ7U.mjs +0 -237
- package/dist/packem_shared/DEFAULT_MAX_RELATION_KEYS-Dou2PWdO.mjs +0 -160
- package/dist/packem_shared/FUNCTION_METRICS_BUCKETS_TABLE-UDNVD7FS.mjs +0 -248
- package/dist/packem_shared/LogBuffer-B_Ezju_N.mjs +0 -37
- package/dist/packem_shared/MAIL_RETENTION-CPpgl-dX.mjs +0 -104
- package/dist/packem_shared/MAX_SQL_ROWS-dDcFE1YZ.mjs +0 -29
- package/dist/packem_shared/MIN_ADMIN_TOKEN_LENGTH-CCAvoFlr.mjs +0 -1
- package/dist/packem_shared/NotFoundError-CMuMZt81.mjs +0 -10
- package/dist/packem_shared/NotUniqueError-h_thNFSZ.mjs +0 -1809
- package/dist/packem_shared/RANK_TIEBREAK-C6blLR5K.mjs +0 -1
- package/dist/packem_shared/RLS_UNWRAP_SYMBOL-EtGQdC9d.mjs +0 -132
- package/dist/packem_shared/ROOT_DO_SIZE_WARN_BYTES-2DxWrdla.mjs +0 -3958
- package/dist/packem_shared/ReactiveCache-ByVzgH3d.mjs +0 -259
- package/dist/packem_shared/SCAN_DEP-DLJF8dsj.mjs +0 -19
- package/dist/packem_shared/SESSION_DO_TTL_DEFAULT-ilPZsVwu.mjs +0 -180
- package/dist/packem_shared/SHARD_REGISTRY_DO_NAME-BsAbi5Mn.mjs +0 -146
- package/dist/packem_shared/aggregateTableName-CxNqY1Sl.mjs +0 -64
- package/dist/packem_shared/applyOnDelete-sA7o1CqD.mjs +0 -169
- package/dist/packem_shared/applySelect-BvZdFUBT.mjs +0 -101
- package/dist/packem_shared/armRestore-BJk53Ro8.mjs +0 -55
- package/dist/packem_shared/backfillAggregateIndexes-BbVPvciS.mjs +0 -80
- package/dist/packem_shared/buildFtsMatch-BLEMawrp.mjs +0 -38
- package/dist/packem_shared/compileWhereSql-CXrhFA3G.mjs +0 -127
- package/dist/packem_shared/createSystemReader-8CzSZP9V.mjs +0 -80
- package/dist/packem_shared/ctx-db-idempotency-DkC9rP91.mjs +0 -35
- package/dist/packem_shared/do-exec-5eQy5cEi.mjs +0 -12
- package/dist/packem_shared/do-sql-BCHCWtrD.mjs +0 -87
- package/dist/packem_shared/exportShardRows-DZEhUeyI.mjs +0 -156
- package/dist/packem_shared/hasTrigger-5N6_Fx0A.mjs +0 -20
- package/dist/packem_shared/rank-CrkEIpF4.mjs +0 -102
- package/dist/packem_shared/renderSql-D6eUcn2N.mjs +0 -16
- package/dist/packem_shared/runShardMigrations-PabobOjF.mjs +0 -103
- package/dist/packem_shared/security-audit-CucgBice.mjs +0 -158
- package/dist/packem_shared/serveRelationFanout-oxaM6_WL.mjs +0 -24
- package/dist/packem_shared/subscriptionListDeltas-ce84gpwL.mjs +0 -111
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
const ROW_ID_FIELD = "_id";
|
|
2
|
-
const DELTA_FALLBACK_TABLE = "__lunora__";
|
|
3
|
-
const readRowId = (row) => {
|
|
4
|
-
if (typeof row !== "object" || row === null || Array.isArray(row)) {
|
|
5
|
-
return void 0;
|
|
6
|
-
}
|
|
7
|
-
const id = row[ROW_ID_FIELD];
|
|
8
|
-
return typeof id === "string" ? id : void 0;
|
|
9
|
-
};
|
|
10
|
-
const indexRowsById = (rows) => {
|
|
11
|
-
const byId = /* @__PURE__ */ new Map();
|
|
12
|
-
const order = [];
|
|
13
|
-
for (const row of rows) {
|
|
14
|
-
const id = readRowId(row);
|
|
15
|
-
if (id === void 0 || byId.has(id)) {
|
|
16
|
-
return void 0;
|
|
17
|
-
}
|
|
18
|
-
byId.set(id, row);
|
|
19
|
-
order.push(id);
|
|
20
|
-
}
|
|
21
|
-
return { byId, order };
|
|
22
|
-
};
|
|
23
|
-
const survivorsKeepOrder = (previous, next) => {
|
|
24
|
-
const survivingPrevious = previous.order.filter((id) => next.byId.has(id));
|
|
25
|
-
const survivingNext = next.order.filter((id) => previous.byId.has(id));
|
|
26
|
-
if (survivingPrevious.length !== survivingNext.length) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
return survivingPrevious.every((id, index) => survivingNext[index] === id);
|
|
30
|
-
};
|
|
31
|
-
const collectDeleteDeltas = (previous, next, deltaTable, tableJson) => {
|
|
32
|
-
const out = [];
|
|
33
|
-
for (const id of previous.order) {
|
|
34
|
-
if (!next.byId.has(id)) {
|
|
35
|
-
out.push({
|
|
36
|
-
delta: { key: id, op: "delete", table: deltaTable },
|
|
37
|
-
frame: `{"key":${JSON.stringify(id)},"op":"delete","table":${tableJson}}`
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return out;
|
|
42
|
-
};
|
|
43
|
-
const collectUpsertDeltas = (previous, next, deltaTable, tableJson) => {
|
|
44
|
-
const out = [];
|
|
45
|
-
for (const id of next.order) {
|
|
46
|
-
const nextRow = next.byId.get(id);
|
|
47
|
-
const previousRow = previous.byId.get(id);
|
|
48
|
-
const nextFingerprint = JSON.stringify(nextRow);
|
|
49
|
-
const previousFingerprint = previousRow === void 0 ? void 0 : JSON.stringify(previousRow);
|
|
50
|
-
if (previousFingerprint === nextFingerprint) {
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
const op = previousFingerprint === void 0 ? "insert" : "update";
|
|
54
|
-
out.push({
|
|
55
|
-
delta: { key: id, op, row: nextRow, table: deltaTable },
|
|
56
|
-
frame: `{"key":${JSON.stringify(id)},"op":"${op}","row":${nextFingerprint},"table":${tableJson}}`
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
return out;
|
|
60
|
-
};
|
|
61
|
-
const subscriptionListDeltas = (previousJson, nextResult, table, frames) => {
|
|
62
|
-
let parsed;
|
|
63
|
-
try {
|
|
64
|
-
parsed = JSON.parse(previousJson);
|
|
65
|
-
} catch {
|
|
66
|
-
return void 0;
|
|
67
|
-
}
|
|
68
|
-
if (!Array.isArray(parsed) || !Array.isArray(nextResult)) {
|
|
69
|
-
return void 0;
|
|
70
|
-
}
|
|
71
|
-
const previous = indexRowsById(parsed);
|
|
72
|
-
const next = indexRowsById(nextResult);
|
|
73
|
-
if (previous === void 0 || next === void 0) {
|
|
74
|
-
return void 0;
|
|
75
|
-
}
|
|
76
|
-
if (!survivorsKeepOrder(previous, next)) {
|
|
77
|
-
return void 0;
|
|
78
|
-
}
|
|
79
|
-
const deltaTable = table === "" ? DELTA_FALLBACK_TABLE : table;
|
|
80
|
-
const tableJson = JSON.stringify(deltaTable);
|
|
81
|
-
const framed = [...collectDeleteDeltas(previous, next, deltaTable, tableJson), ...collectUpsertDeltas(previous, next, deltaTable, tableJson)];
|
|
82
|
-
if (framed.length > next.order.length) {
|
|
83
|
-
return void 0;
|
|
84
|
-
}
|
|
85
|
-
if (frames !== void 0) {
|
|
86
|
-
for (const { frame } of framed) {
|
|
87
|
-
frames.push(frame);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return framed.map(({ delta }) => delta);
|
|
91
|
-
};
|
|
92
|
-
const trySendFrame = (ws, frame) => {
|
|
93
|
-
try {
|
|
94
|
-
ws.send(frame);
|
|
95
|
-
return true;
|
|
96
|
-
} catch {
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
const sendDeltaFrames = (ws, subId, deltaFrames, cursorSuffix) => {
|
|
101
|
-
const idJson = JSON.stringify(subId);
|
|
102
|
-
let delivered = true;
|
|
103
|
-
for (const deltaBody of deltaFrames) {
|
|
104
|
-
if (!trySendFrame(ws, `{"type":"delta","id":${idJson},"delta":${deltaBody}${cursorSuffix}}`)) {
|
|
105
|
-
delivered = false;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return delivered;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
export { sendDeltaFrames, subscriptionListDeltas, trySendFrame };
|