@lunora/do 1.0.0-alpha.44 → 1.0.0-alpha.45

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 (112) hide show
  1. package/dist/index.d.mts +55 -1
  2. package/dist/index.d.ts +55 -1
  3. package/dist/index.mjs +1 -44
  4. package/dist/packem_shared/ADMIN_FUNCTIONS-PxZ8Lr9e.mjs +1 -0
  5. package/dist/packem_shared/AGGREGATE_SQL_FUNCTION-QYaiuty4.mjs +1 -0
  6. package/dist/packem_shared/AUTH_METRICS_BUCKETS_TABLE-D0wNaez7.mjs +22 -0
  7. package/dist/packem_shared/CDC_LOG_TABLE-E_J5LPoK.mjs +8 -0
  8. package/dist/packem_shared/ConflictError-C8GtJmjS.mjs +1 -0
  9. package/dist/packem_shared/CountRlsUnsupportedError-Cl8XpYDL.mjs +1 -0
  10. package/dist/packem_shared/DATA_MIGRATION_STATE_TABLE-CaO6L0Ee.mjs +31 -0
  11. package/dist/packem_shared/DEFAULT_MAX_RELATION_KEYS-BRdmX7WW.mjs +1 -0
  12. package/dist/packem_shared/FUNCTION_METRICS_BUCKETS_TABLE-BPPeqM11.mjs +56 -0
  13. package/dist/packem_shared/GEO_DEFAULT_PRECISION-CWAm_oYY.mjs +1 -0
  14. package/dist/packem_shared/LogBuffer-bIvCelI-.mjs +1 -0
  15. package/dist/packem_shared/MAIL_RETENTION-KmozO2NQ.mjs +18 -0
  16. package/dist/packem_shared/MAX_SQL_ROWS-Bdu25ASB.mjs +2 -0
  17. package/dist/packem_shared/MIN_ADMIN_TOKEN_LENGTH-Ch6OW6_3.mjs +1 -0
  18. package/dist/packem_shared/NotFoundError-J3tjf4Uo.mjs +1 -0
  19. package/dist/packem_shared/NotUniqueError-BcP6GOem.mjs +1 -0
  20. package/dist/packem_shared/RANK_TIEBREAK-DtX8zQyc.mjs +1 -0
  21. package/dist/packem_shared/RLS_UNWRAP_SYMBOL-C6_WX3dG.mjs +1 -0
  22. package/dist/packem_shared/ROOT_DO_SIZE_WARN_BYTES-CP5wvJOW.mjs +101 -0
  23. package/dist/packem_shared/ReactiveCache-1_9Rs7J_.mjs +1 -0
  24. package/dist/packem_shared/SCAN_DEP-D_yR9EeV.mjs +1 -0
  25. package/dist/packem_shared/SESSION_DO_TTL_DEFAULT-GvBy_DBz.mjs +1 -0
  26. package/dist/packem_shared/SHARD_REGISTRY_DO_NAME-Caa0fR4N.mjs +1 -0
  27. package/dist/packem_shared/aggregateTableName-G-eXyjcz.mjs +1 -0
  28. package/dist/packem_shared/applyOnDelete-BvQN7pDL.mjs +1 -0
  29. package/dist/packem_shared/applySelect-Bq2KOrkL.mjs +1 -0
  30. package/dist/packem_shared/armRestore-BNzdvQ_o.mjs +1 -0
  31. package/dist/packem_shared/backfillAggregateIndexes-BAQ3Fwwh.mjs +1 -0
  32. package/dist/packem_shared/buildFtsMatch-CV0Z7PWv.mjs +1 -0
  33. package/dist/packem_shared/compileWhereSql-BLcfs4QW.mjs +1 -0
  34. package/dist/packem_shared/constant-time-equal-BVG05Guz.mjs +1 -0
  35. package/dist/packem_shared/context-telemetry-8eigmiNQ.mjs +1 -0
  36. package/dist/packem_shared/createMetrics-CyjLFXtA.mjs +1 -0
  37. package/dist/packem_shared/createSystemReader-DcDcrtM3.mjs +1 -0
  38. package/dist/packem_shared/ctx-db-idempotency-wiVoGnpQ.mjs +19 -0
  39. package/dist/packem_shared/ctx-db-shapes-DzX_H5q8.mjs +1 -0
  40. package/dist/packem_shared/diffExternalSource-DMpkJta1.mjs +1 -0
  41. package/dist/packem_shared/do-exec-BLe9lLrN.mjs +1 -0
  42. package/dist/packem_shared/do-sql-BYIQTG3z.mjs +1 -0
  43. package/dist/packem_shared/exportShardRows-kt42wijd.mjs +1 -0
  44. package/dist/packem_shared/hasTrigger-_rexbWMO.mjs +1 -0
  45. package/dist/packem_shared/isSoftDeleted-BvhQov04.mjs +9 -0
  46. package/dist/packem_shared/json-response-wrh9TBPw.mjs +1 -0
  47. package/dist/packem_shared/materializeExternalRows-BFmT9gsw.mjs +1 -0
  48. package/dist/packem_shared/renderSql-B5lF5Jd9.mjs +1 -0
  49. package/dist/packem_shared/runShardMigrations-bxOHpfID.mjs +5 -0
  50. package/dist/packem_shared/security-audit-BKUOgE0x.mjs +1 -0
  51. package/dist/packem_shared/selectExpiredIds-BGVP3d8-.mjs +1 -0
  52. package/dist/packem_shared/serialize-sql-DiRzL7A4.mjs +1 -0
  53. package/dist/packem_shared/serveRelationFanout-Ct5D2Tbk.mjs +1 -0
  54. package/dist/packem_shared/stableStringify-BjLh4gvA.mjs +1 -0
  55. package/dist/packem_shared/stableWireKey-YEHLaX6X.mjs +1 -0
  56. package/dist/packem_shared/subscriptionListDeltas-Bs69JbA8.mjs +1 -0
  57. package/dist/packem_shared/wire-codec-Ctnni0h6.mjs +1 -0
  58. package/package.json +1 -1
  59. package/dist/packem_shared/ADMIN_FUNCTIONS-CnZkbXH_.mjs +0 -374
  60. package/dist/packem_shared/AGGREGATE_SQL_FUNCTION-CQsu2Xga.mjs +0 -56
  61. package/dist/packem_shared/AUTH_METRICS_BUCKETS_TABLE-CiHHYeJi.mjs +0 -84
  62. package/dist/packem_shared/CDC_LOG_TABLE-uwOJxJJZ.mjs +0 -107
  63. package/dist/packem_shared/ConflictError-CLoq37xH.mjs +0 -12
  64. package/dist/packem_shared/CountRlsUnsupportedError-BGxj0pgS.mjs +0 -133
  65. package/dist/packem_shared/DATA_MIGRATION_STATE_TABLE-CYwBpyTr.mjs +0 -245
  66. package/dist/packem_shared/DEFAULT_MAX_RELATION_KEYS-BEan1CRD.mjs +0 -211
  67. package/dist/packem_shared/FUNCTION_METRICS_BUCKETS_TABLE-UDNVD7FS.mjs +0 -248
  68. package/dist/packem_shared/GEO_DEFAULT_PRECISION-BWnsNmpP.mjs +0 -114
  69. package/dist/packem_shared/LogBuffer-B_Ezju_N.mjs +0 -37
  70. package/dist/packem_shared/MAIL_RETENTION-CPpgl-dX.mjs +0 -104
  71. package/dist/packem_shared/MAX_SQL_ROWS-iFAA8FbD.mjs +0 -61
  72. package/dist/packem_shared/MIN_ADMIN_TOKEN_LENGTH-CCAvoFlr.mjs +0 -1
  73. package/dist/packem_shared/NotFoundError-C70b9hLw.mjs +0 -9
  74. package/dist/packem_shared/NotUniqueError-DbtlWwcG.mjs +0 -2031
  75. package/dist/packem_shared/RANK_TIEBREAK-CXhdcA1o.mjs +0 -91
  76. package/dist/packem_shared/RLS_UNWRAP_SYMBOL-DTvHvRzY.mjs +0 -141
  77. package/dist/packem_shared/ROOT_DO_SIZE_WARN_BYTES-B_zt4RQE.mjs +0 -7676
  78. package/dist/packem_shared/ReactiveCache-DnSvbjil.mjs +0 -233
  79. package/dist/packem_shared/SCAN_DEP-DLJF8dsj.mjs +0 -19
  80. package/dist/packem_shared/SESSION_DO_TTL_DEFAULT-BnSKgVO4.mjs +0 -169
  81. package/dist/packem_shared/SHARD_REGISTRY_DO_NAME-D99roc-r.mjs +0 -144
  82. package/dist/packem_shared/aggregateTableName-CxNqY1Sl.mjs +0 -64
  83. package/dist/packem_shared/applyOnDelete-BXSq3S70.mjs +0 -176
  84. package/dist/packem_shared/applySelect-WQY8m62C.mjs +0 -103
  85. package/dist/packem_shared/armRestore-4Px61hHS.mjs +0 -49
  86. package/dist/packem_shared/backfillAggregateIndexes-BGTwynwh.mjs +0 -81
  87. package/dist/packem_shared/buildFtsMatch-BLEMawrp.mjs +0 -38
  88. package/dist/packem_shared/compileWhereSql-DE6yfRcQ.mjs +0 -129
  89. package/dist/packem_shared/constant-time-equal-BVRWZgES.mjs +0 -12
  90. package/dist/packem_shared/context-telemetry-CDpyil58.mjs +0 -223
  91. package/dist/packem_shared/createMetrics-C4I2Yanj.mjs +0 -1
  92. package/dist/packem_shared/createSystemReader-D12eNH13.mjs +0 -82
  93. package/dist/packem_shared/ctx-db-idempotency-BdcNpvY4.mjs +0 -108
  94. package/dist/packem_shared/ctx-db-shapes-DTeFiHYS.mjs +0 -53
  95. package/dist/packem_shared/diffExternalSource-CovHfdyo.mjs +0 -44
  96. package/dist/packem_shared/do-exec-5eQy5cEi.mjs +0 -12
  97. package/dist/packem_shared/do-sql-CGAgiQUz.mjs +0 -88
  98. package/dist/packem_shared/exportShardRows-Dy3oFZ26.mjs +0 -157
  99. package/dist/packem_shared/hasTrigger-5N6_Fx0A.mjs +0 -20
  100. package/dist/packem_shared/isSoftDeleted-CFJmhjFP.mjs +0 -217
  101. package/dist/packem_shared/json-response-BdbtpOhm.mjs +0 -3
  102. package/dist/packem_shared/materializeExternalRows-BtEGs1Fv.mjs +0 -45
  103. package/dist/packem_shared/renderSql-D6eUcn2N.mjs +0 -16
  104. package/dist/packem_shared/runShardMigrations-BVax6rYu.mjs +0 -120
  105. package/dist/packem_shared/security-audit-CucgBice.mjs +0 -158
  106. package/dist/packem_shared/selectExpiredIds-C5W29Upb.mjs +0 -18
  107. package/dist/packem_shared/serialize-sql-BlRUoiQe.mjs +0 -14
  108. package/dist/packem_shared/serveRelationFanout-k7HTh3CC.mjs +0 -21
  109. package/dist/packem_shared/stableStringify-mC40mZts.mjs +0 -40
  110. package/dist/packem_shared/stableWireKey-DKuXO7T5.mjs +0 -6
  111. package/dist/packem_shared/subscriptionListDeltas-CT76bYny.mjs +0 -126
  112. package/dist/packem_shared/wire-codec-CzQc1pvf.mjs +0 -225
@@ -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 };