@lunora/do 1.0.0-alpha.25 → 1.0.0-alpha.250

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.
Files changed (63) hide show
  1. package/README.md +11 -0
  2. package/dist/index.d.mts +6365 -6091
  3. package/dist/index.d.ts +6365 -6091
  4. package/dist/index.mjs +1 -40
  5. package/dist/packem_chunks/sql-assistant.mjs +10 -0
  6. package/dist/packem_shared/MERGED_ROLES-C4RToZ16.mjs +1 -0
  7. package/dist/packem_shared/ROOT_DO_SIZE_WARN_BYTES-D3cjwS_z.mjs +13 -0
  8. package/dist/packem_shared/SESSION_DO_TTL_DEFAULT-DSvTwRjc.mjs +1 -0
  9. package/dist/packem_shared/SHARD_REGISTRY_DO_NAME-YZZk79QR.mjs +2 -0
  10. package/dist/packem_shared/constant-time-equal-BRh9yUCr.mjs +1 -0
  11. package/dist/packem_shared/createStableIdFactory-DPDT_chw.mjs +1 -0
  12. package/dist/packem_shared/installDeliveryFence-B6M9KOnb.mjs +1 -0
  13. package/dist/packem_shared/json-response-0Bq2ky0N.mjs +1 -0
  14. package/dist/packem_shared/serveRelationFanout-DcSjzAZv.mjs +1 -0
  15. package/package.json +9 -4
  16. package/dist/packem_shared/ADMIN_FUNCTIONS-Bxdijn66.mjs +0 -366
  17. package/dist/packem_shared/AGGREGATE_SQL_FUNCTION-CQsu2Xga.mjs +0 -56
  18. package/dist/packem_shared/AUTH_METRICS_BUCKETS_TABLE-CiHHYeJi.mjs +0 -84
  19. package/dist/packem_shared/CDC_LOG_TABLE-DZSVKRr7.mjs +0 -107
  20. package/dist/packem_shared/ConflictError-CLoq37xH.mjs +0 -12
  21. package/dist/packem_shared/CountRlsUnsupportedError-BGxj0pgS.mjs +0 -133
  22. package/dist/packem_shared/DATA_MIGRATION_STATE_TABLE-DB3IYUR3.mjs +0 -243
  23. package/dist/packem_shared/DEFAULT_MAX_RELATION_KEYS-CjM9Y1_G.mjs +0 -211
  24. package/dist/packem_shared/FUNCTION_METRICS_BUCKETS_TABLE-UDNVD7FS.mjs +0 -248
  25. package/dist/packem_shared/LogBuffer-B_Ezju_N.mjs +0 -37
  26. package/dist/packem_shared/MAIL_RETENTION-CPpgl-dX.mjs +0 -104
  27. package/dist/packem_shared/MAX_SQL_ROWS-D57CJaT9.mjs +0 -31
  28. package/dist/packem_shared/MIN_ADMIN_TOKEN_LENGTH-CCAvoFlr.mjs +0 -1
  29. package/dist/packem_shared/NotFoundError-C70b9hLw.mjs +0 -9
  30. package/dist/packem_shared/NotUniqueError-Dmf-HNdQ.mjs +0 -1896
  31. package/dist/packem_shared/RANK_TIEBREAK-CXhdcA1o.mjs +0 -91
  32. package/dist/packem_shared/RLS_UNWRAP_SYMBOL-G1eNK4DQ.mjs +0 -141
  33. package/dist/packem_shared/ROOT_DO_SIZE_WARN_BYTES-CpURtawE.mjs +0 -6436
  34. package/dist/packem_shared/ReactiveCache-BYlSGY0N.mjs +0 -232
  35. package/dist/packem_shared/SCAN_DEP-DLJF8dsj.mjs +0 -19
  36. package/dist/packem_shared/SESSION_DO_TTL_DEFAULT-D71QAL5h.mjs +0 -178
  37. package/dist/packem_shared/SHARD_REGISTRY_DO_NAME-D99roc-r.mjs +0 -144
  38. package/dist/packem_shared/aggregateTableName-CxNqY1Sl.mjs +0 -64
  39. package/dist/packem_shared/applyOnDelete-CAwZfp-5.mjs +0 -176
  40. package/dist/packem_shared/applySelect-BvZdFUBT.mjs +0 -101
  41. package/dist/packem_shared/armRestore-4Px61hHS.mjs +0 -49
  42. package/dist/packem_shared/backfillAggregateIndexes-DDoT-UUI.mjs +0 -81
  43. package/dist/packem_shared/buildFtsMatch-BLEMawrp.mjs +0 -38
  44. package/dist/packem_shared/compileWhereSql-DE6yfRcQ.mjs +0 -129
  45. package/dist/packem_shared/createSystemReader-D12eNH13.mjs +0 -82
  46. package/dist/packem_shared/ctx-db-idempotency-BdcNpvY4.mjs +0 -108
  47. package/dist/packem_shared/ctx-db-shapes-Cz9dHyh1.mjs +0 -53
  48. package/dist/packem_shared/diffExternalSource-Cx9HUPJj.mjs +0 -44
  49. package/dist/packem_shared/do-exec-5eQy5cEi.mjs +0 -12
  50. package/dist/packem_shared/do-sql-BCHCWtrD.mjs +0 -87
  51. package/dist/packem_shared/exportShardRows-Dy3oFZ26.mjs +0 -157
  52. package/dist/packem_shared/hasTrigger-5N6_Fx0A.mjs +0 -20
  53. package/dist/packem_shared/isSourceDue-BptUN8CR.mjs +0 -41
  54. package/dist/packem_shared/json-response-BdbtpOhm.mjs +0 -3
  55. package/dist/packem_shared/materializeExternalRows-DNcvoLRT.mjs +0 -23
  56. package/dist/packem_shared/renderSql-D6eUcn2N.mjs +0 -16
  57. package/dist/packem_shared/runShardMigrations-DeZr0KZp.mjs +0 -105
  58. package/dist/packem_shared/security-audit-CucgBice.mjs +0 -158
  59. package/dist/packem_shared/serialize-sql-BlRUoiQe.mjs +0 -14
  60. package/dist/packem_shared/serveRelationFanout-C56hKu1O.mjs +0 -21
  61. package/dist/packem_shared/stableStringify-MydiuScU.mjs +0 -40
  62. package/dist/packem_shared/subscription-delivery-CK8qga-k.mjs +0 -347
  63. package/dist/packem_shared/subscriptionListDeltas-BxygQlXT.mjs +0 -1
@@ -1,91 +0,0 @@
1
- import { s as serializeSqlValue } from './serialize-sql-BlRUoiQe.mjs';
2
-
3
- const compareStrings = (a, b) => {
4
- if (a < b) {
5
- return -1;
6
- }
7
- return a > b ? 1 : 0;
8
- };
9
- const NOT_RESOLVABLE = /* @__PURE__ */ Symbol("not-resolvable");
10
- const resolvePartitionValue = (value) => {
11
- if (value !== null && typeof value === "object" && !Array.isArray(value)) {
12
- const operatorKeys = Object.keys(value);
13
- if (operatorKeys.length === 1 && operatorKeys[0] === "eq") {
14
- return value.eq;
15
- }
16
- return NOT_RESOLVABLE;
17
- }
18
- return value;
19
- };
20
- const encodePartitionKey = (partitionBy, source) => {
21
- if (partitionBy.length === 0) {
22
- return "";
23
- }
24
- const ordered = {};
25
- for (const field of [...partitionBy].toSorted(compareStrings)) {
26
- ordered[field] = source[field] ?? null;
27
- }
28
- return JSON.stringify(ordered);
29
- };
30
- const RANK_TIEBREAK = "__id__";
31
- const sortColumnName = (i) => `__sort_k${String(i)}__`;
32
- const matchesRankStaticWhere = (document, predicate) => {
33
- for (const [field, expected] of Object.entries(predicate)) {
34
- const actual = document[field];
35
- if (expected !== null && typeof expected === "object" && !Array.isArray(expected)) {
36
- const operatorKeys = Object.keys(expected);
37
- if (operatorKeys.length === 1 && operatorKeys[0] === "eq") {
38
- if (actual !== expected.eq) {
39
- return false;
40
- }
41
- continue;
42
- }
43
- return false;
44
- }
45
- if (actual !== expected) {
46
- return false;
47
- }
48
- }
49
- return true;
50
- };
51
- const resolveRankPartition = (index, where) => {
52
- const partitionBy = index.partitionBy ?? [];
53
- const requested = where ?? {};
54
- for (const key of Object.keys(requested)) {
55
- if (key === "AND" || key === "OR" || key === "NOT") {
56
- return void 0;
57
- }
58
- }
59
- const resolved = {};
60
- for (const field of partitionBy) {
61
- if (field in requested) {
62
- const value = resolvePartitionValue(requested[field]);
63
- if (value === NOT_RESOLVABLE) {
64
- return void 0;
65
- }
66
- resolved[field] = value;
67
- } else if (index.where && field in index.where) {
68
- resolved[field] = index.where[field];
69
- } else {
70
- return void 0;
71
- }
72
- }
73
- return resolved;
74
- };
75
- const rankTableName = (table, indexName) => `${table}__rank_${indexName}`;
76
- const rankKeyFromDocument = (index, document_) => {
77
- return {
78
- partitionKey: encodePartitionKey(index.partitionBy ?? [], document_),
79
- rowId: document_["_id"],
80
- // Serialize each sort value the same way `syncRankIndexEntry` writes the
81
- // stored `__sort_k<i>__` column, so a peer shard's comparison matches
82
- // byte-for-byte. This also makes the values JSON-safe for the
83
- // cross-shard RPC wire — `serializeSqlValue` turns bigint/Date/object
84
- // into a string|number|null, where raw bigint would crash JSON.stringify
85
- // and a raw Date would serialize to a different shape than the store.
86
- // eslint-disable-next-line unicorn/no-null -- mirrors syncRankIndexEntry: a missing field serializes via `?? null` so the stored and wire bytes agree
87
- sortValues: index.sortBy.map((key) => serializeSqlValue(document_[key.field] ?? null))
88
- };
89
- };
90
-
91
- export { RANK_TIEBREAK, encodePartitionKey, matchesRankStaticWhere, rankKeyFromDocument as rankKeyFromDoc, rankTableName, resolveRankPartition, sortColumnName };
@@ -1,141 +0,0 @@
1
- import { LunoraError } from '@lunora/errors';
2
-
3
- const RLS_UNWRAP_SYMBOL = /* @__PURE__ */ Symbol.for("lunora.ctxdb.rls-unwrap");
4
- class RlsRequiredError extends LunoraError {
5
- table;
6
- constructor(table) {
7
- super(
8
- "RLS_REQUIRED",
9
- `ctx.db access to "${table}" is denied: the schema is marked .rls("required"), so this table is protected. Apply RLS with .use(rls(policies)) in the procedure, or mark the table .public() to opt it out.`,
10
- { name: "RlsRequiredError" }
11
- );
12
- this.table = table;
13
- }
14
- }
15
- const guardWriter = (raw, schema, tableOfId) => {
16
- if (schema.rlsMode !== "required") {
17
- return raw;
18
- }
19
- const base = raw;
20
- const isProtected = (tableName) => {
21
- const definition = schema.tables[tableName];
22
- return definition !== void 0 && definition.isPublic !== true;
23
- };
24
- const guardTable = (tableName) => {
25
- if (isProtected(tableName)) {
26
- throw new RlsRequiredError(tableName);
27
- }
28
- };
29
- const guardById = async (id, expectedTable) => {
30
- if (expectedTable !== void 0) {
31
- guardTable(expectedTable);
32
- return;
33
- }
34
- const tableName = await tableOfId(id);
35
- if (tableName !== void 0) {
36
- guardTable(tableName);
37
- }
38
- };
39
- const baseRankBefore = base.rankBefore;
40
- const guarded = {
41
- ...raw,
42
- [RLS_UNWRAP_SYMBOL]: raw,
43
- aggregate: (tableName, options) => {
44
- guardTable(tableName);
45
- return base.aggregate(tableName, options);
46
- },
47
- count: (tableName, whereOrArgs) => {
48
- guardTable(tableName);
49
- return base.count(tableName, whereOrArgs);
50
- },
51
- delete: async (id, expectedTable, options) => {
52
- await guardById(id, expectedTable);
53
- return base.delete(id, expectedTable, options);
54
- },
55
- deleteMany: async (ids, options, expectedTable) => {
56
- for (const id of ids) {
57
- await guardById(id, expectedTable);
58
- }
59
- return base.deleteMany(ids, options, expectedTable);
60
- },
61
- deleteWhere: base.deleteWhere ? async (tableName, where, options) => {
62
- guardTable(tableName);
63
- return await base.deleteWhere?.(tableName, where, options);
64
- } : void 0,
65
- findFirst: (tableName, args) => {
66
- guardTable(tableName);
67
- return base.findFirst(tableName, args);
68
- },
69
- findFirstOrThrow: (tableName, args) => {
70
- guardTable(tableName);
71
- return base.findFirstOrThrow(tableName, args);
72
- },
73
- findMany: (tableName, args) => {
74
- guardTable(tableName);
75
- return base.findMany(tableName, args);
76
- },
77
- get: async (id, expectedTable) => {
78
- await guardById(id, expectedTable);
79
- return base.get(id, expectedTable);
80
- },
81
- groupBy: (tableName, options) => {
82
- guardTable(tableName);
83
- return base.groupBy(tableName, options);
84
- },
85
- insert: (tableName, document, options) => {
86
- guardTable(tableName);
87
- return base.insert(tableName, document, options);
88
- },
89
- insertMany: (tableName, documents, options) => {
90
- guardTable(tableName);
91
- return base.insertMany(tableName, documents, options);
92
- },
93
- insertManyUnsafe: (tableName, documents, options) => {
94
- guardTable(tableName);
95
- return base.insertManyUnsafe(tableName, documents, options);
96
- },
97
- patch: async (id, patch, expectedTable) => {
98
- await guardById(id, expectedTable);
99
- return base.patch(id, patch, expectedTable);
100
- },
101
- patchMany: async (patches, options, expectedTable) => {
102
- for (const entry of patches) {
103
- await guardById(entry.id, expectedTable);
104
- }
105
- return base.patchMany(patches, options, expectedTable);
106
- },
107
- patchWhere: base.patchWhere ? async (tableName, args, options) => {
108
- guardTable(tableName);
109
- return await base.patchWhere?.(tableName, args, options);
110
- } : void 0,
111
- query: (tableName) => {
112
- guardTable(tableName);
113
- return base.query(tableName);
114
- },
115
- rank: (tableName, indexName, options) => {
116
- guardTable(tableName);
117
- return base.rank(tableName, indexName, options);
118
- },
119
- rankPage: (tableName, indexName, options) => {
120
- guardTable(tableName);
121
- return base.rankPage(tableName, indexName, options);
122
- },
123
- replace: async (id, document, expectedTable) => {
124
- await guardById(id, expectedTable);
125
- return base.replace(id, document, expectedTable);
126
- },
127
- restore: async (id, expectedTable) => {
128
- await guardById(id, expectedTable);
129
- return base.restore?.(id, expectedTable);
130
- }
131
- };
132
- if (baseRankBefore) {
133
- guarded["rankBefore"] = (tableName, indexName, options) => {
134
- guardTable(tableName);
135
- return baseRankBefore(tableName, indexName, options);
136
- };
137
- }
138
- return guarded;
139
- };
140
-
141
- export { RLS_UNWRAP_SYMBOL, RlsRequiredError, guardWriter };