@lunora/do 1.0.0-alpha.28 → 1.0.0-alpha.281

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 (69) hide show
  1. package/README.md +11 -0
  2. package/dist/index.d.mts +6779 -6109
  3. package/dist/index.d.ts +6779 -6109
  4. package/dist/index.mjs +1 -40
  5. package/dist/packem_chunks/ai-opt-in.mjs +1 -0
  6. package/dist/packem_chunks/sql-assistant.mjs +14 -0
  7. package/dist/packem_shared/ADMIN_REVOCATION_DO_NAME-D43bQNiT.mjs +1 -0
  8. package/dist/packem_shared/AdminRevocationDO-DHjoZWfF.mjs +1 -0
  9. package/dist/packem_shared/MERGED_ROLES-BAMAmIcW.mjs +1 -0
  10. package/dist/packem_shared/ROOT_DO_SIZE_WARN_BYTES-BWAlPGt_.mjs +13 -0
  11. package/dist/packem_shared/SESSION_DO_TTL_DEFAULT-DSvTwRjc.mjs +1 -0
  12. package/dist/packem_shared/SHARD_REGISTRY_DO_NAME-Dbh8JQJQ.mjs +2 -0
  13. package/dist/packem_shared/admin-token-DrufJIZV.mjs +1 -0
  14. package/dist/packem_shared/constant-time-equal-BRh9yUCr.mjs +1 -0
  15. package/dist/packem_shared/createStableIdFactory-DPDT_chw.mjs +1 -0
  16. package/dist/packem_shared/installDeliveryFence-B6M9KOnb.mjs +1 -0
  17. package/dist/packem_shared/json-response-0Bq2ky0N.mjs +1 -0
  18. package/dist/packem_shared/read-body-text-capped-C6-sQo-i.mjs +1 -0
  19. package/dist/packem_shared/serveRelationFanout-DcSjzAZv.mjs +1 -0
  20. package/package.json +9 -4
  21. package/dist/packem_shared/ADMIN_FUNCTIONS-Bxdijn66.mjs +0 -366
  22. package/dist/packem_shared/AGGREGATE_SQL_FUNCTION-CQsu2Xga.mjs +0 -56
  23. package/dist/packem_shared/AUTH_METRICS_BUCKETS_TABLE-CiHHYeJi.mjs +0 -84
  24. package/dist/packem_shared/CDC_LOG_TABLE-DjJEHiM2.mjs +0 -107
  25. package/dist/packem_shared/ConflictError-CLoq37xH.mjs +0 -12
  26. package/dist/packem_shared/CountRlsUnsupportedError-BGxj0pgS.mjs +0 -133
  27. package/dist/packem_shared/DATA_MIGRATION_STATE_TABLE-CYwBpyTr.mjs +0 -245
  28. package/dist/packem_shared/DEFAULT_MAX_RELATION_KEYS-BEan1CRD.mjs +0 -211
  29. package/dist/packem_shared/FUNCTION_METRICS_BUCKETS_TABLE-UDNVD7FS.mjs +0 -248
  30. package/dist/packem_shared/LogBuffer-B_Ezju_N.mjs +0 -37
  31. package/dist/packem_shared/MAIL_RETENTION-CPpgl-dX.mjs +0 -104
  32. package/dist/packem_shared/MAX_SQL_ROWS-D57CJaT9.mjs +0 -31
  33. package/dist/packem_shared/MIN_ADMIN_TOKEN_LENGTH-CCAvoFlr.mjs +0 -1
  34. package/dist/packem_shared/NotFoundError-C70b9hLw.mjs +0 -9
  35. package/dist/packem_shared/NotUniqueError-BigrdT_W.mjs +0 -1896
  36. package/dist/packem_shared/RANK_TIEBREAK-CXhdcA1o.mjs +0 -91
  37. package/dist/packem_shared/RLS_UNWRAP_SYMBOL-DTvHvRzY.mjs +0 -141
  38. package/dist/packem_shared/ROOT_DO_SIZE_WARN_BYTES-CszdLJhN.mjs +0 -6436
  39. package/dist/packem_shared/ReactiveCache-BYlSGY0N.mjs +0 -232
  40. package/dist/packem_shared/SCAN_DEP-DLJF8dsj.mjs +0 -19
  41. package/dist/packem_shared/SESSION_DO_TTL_DEFAULT-BnSKgVO4.mjs +0 -169
  42. package/dist/packem_shared/SHARD_REGISTRY_DO_NAME-D99roc-r.mjs +0 -144
  43. package/dist/packem_shared/aggregateTableName-CxNqY1Sl.mjs +0 -64
  44. package/dist/packem_shared/applyOnDelete-BXSq3S70.mjs +0 -176
  45. package/dist/packem_shared/applySelect-WQY8m62C.mjs +0 -103
  46. package/dist/packem_shared/armRestore-4Px61hHS.mjs +0 -49
  47. package/dist/packem_shared/backfillAggregateIndexes-DDoT-UUI.mjs +0 -81
  48. package/dist/packem_shared/buildFtsMatch-BLEMawrp.mjs +0 -38
  49. package/dist/packem_shared/compileWhereSql-DE6yfRcQ.mjs +0 -129
  50. package/dist/packem_shared/constant-time-equal-BVRWZgES.mjs +0 -12
  51. package/dist/packem_shared/createSystemReader-D12eNH13.mjs +0 -82
  52. package/dist/packem_shared/ctx-db-idempotency-BdcNpvY4.mjs +0 -108
  53. package/dist/packem_shared/ctx-db-shapes-Cz9dHyh1.mjs +0 -53
  54. package/dist/packem_shared/diffExternalSource-Cx9HUPJj.mjs +0 -44
  55. package/dist/packem_shared/do-exec-5eQy5cEi.mjs +0 -12
  56. package/dist/packem_shared/do-sql-BCHCWtrD.mjs +0 -87
  57. package/dist/packem_shared/exportShardRows-Dy3oFZ26.mjs +0 -157
  58. package/dist/packem_shared/hasTrigger-5N6_Fx0A.mjs +0 -20
  59. package/dist/packem_shared/isSourceDue-CYkt7Ru8.mjs +0 -41
  60. package/dist/packem_shared/json-response-BdbtpOhm.mjs +0 -3
  61. package/dist/packem_shared/materializeExternalRows-CTqZisSC.mjs +0 -23
  62. package/dist/packem_shared/renderSql-D6eUcn2N.mjs +0 -16
  63. package/dist/packem_shared/runShardMigrations-BGx4v2B6.mjs +0 -105
  64. package/dist/packem_shared/security-audit-CucgBice.mjs +0 -158
  65. package/dist/packem_shared/serialize-sql-BlRUoiQe.mjs +0 -14
  66. package/dist/packem_shared/serveRelationFanout-C56hKu1O.mjs +0 -21
  67. package/dist/packem_shared/stableStringify-MydiuScU.mjs +0 -40
  68. package/dist/packem_shared/subscription-delivery-CK8qga-k.mjs +0 -347
  69. 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, options) => {
124
- await guardById(id, expectedTable);
125
- return base.replace(id, document, expectedTable, options);
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 };