@lunora/do 1.0.0-alpha.3 → 1.0.0-alpha.30

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 (51) hide show
  1. package/LICENSE.md +6 -0
  2. package/__assets__/package-og.svg +1 -1
  3. package/dist/index.d.mts +1375 -289
  4. package/dist/index.d.ts +1375 -289
  5. package/dist/index.mjs +35 -30
  6. package/dist/packem_shared/{ADMIN_FUNCTION_PREFIX-Dzdqq5J2.mjs → ADMIN_FUNCTIONS-CAHLZMj8.mjs} +62 -8
  7. package/dist/packem_shared/{matchesStaticWhere-CFk6adSu.mjs → AGGREGATE_SQL_FUNCTION-CQsu2Xga.mjs} +5 -3
  8. package/dist/packem_shared/{applyCdcChanges-Ctdmxmrv.mjs → CDC_LOG_TABLE-DjJEHiM2.mjs} +7 -3
  9. package/dist/packem_shared/{ConflictError-C0STs6bU.mjs → ConflictError-CLoq37xH.mjs} +4 -5
  10. package/dist/packem_shared/{CountRlsUnsupportedError-28ZvvwKS.mjs → CountRlsUnsupportedError-BGxj0pgS.mjs} +4 -4
  11. package/dist/packem_shared/{DATA_MIGRATION_STATE_TABLE-PTtTiQ7U.mjs → DATA_MIGRATION_STATE_TABLE-CYwBpyTr.mjs} +11 -3
  12. package/dist/packem_shared/{assertFlatPredicate-DyVYReuT.mjs → DEFAULT_MAX_RELATION_KEYS-BEan1CRD.mjs} +58 -7
  13. package/dist/packem_shared/{assertReadonly-dDcFE1YZ.mjs → MAX_SQL_ROWS-D57CJaT9.mjs} +3 -1
  14. package/dist/packem_shared/NotFoundError-C70b9hLw.mjs +9 -0
  15. package/dist/packem_shared/{assertValidClientId-CBZ1zC96.mjs → NotUniqueError-BigrdT_W.mjs} +241 -90
  16. package/dist/packem_shared/{rank-CrkEIpF4.mjs → RANK_TIEBREAK-CXhdcA1o.mjs} +2 -13
  17. package/dist/packem_shared/{guardWriter-u3UlnCH5.mjs → RLS_UNWRAP_SYMBOL-DTvHvRzY.mjs} +22 -9
  18. package/dist/packem_shared/{ROOT_DO_SIZE_WARN_BYTES-DQkmGiCS.mjs → ROOT_DO_SIZE_WARN_BYTES-BA8QOChj.mjs} +2878 -326
  19. package/dist/packem_shared/{ReactiveCache-ByVzgH3d.mjs → ReactiveCache-BYlSGY0N.mjs} +1 -28
  20. package/dist/packem_shared/{SESSION_DO_TTL_DEFAULT-ilPZsVwu.mjs → SESSION_DO_TTL_DEFAULT-BnSKgVO4.mjs} +16 -27
  21. package/dist/packem_shared/{SHARD_REGISTRY_DO_NAME-BsAbi5Mn.mjs → SHARD_REGISTRY_DO_NAME-D99roc-r.mjs} +12 -14
  22. package/dist/packem_shared/{applyOnDelete-CMif2RKw.mjs → applyOnDelete-BXSq3S70.mjs} +23 -12
  23. package/dist/packem_shared/{buildSeekWhere-lVsNXSLy.mjs → applySelect-WQY8m62C.mjs} +21 -2
  24. package/dist/packem_shared/{armRestore-BJk53Ro8.mjs → armRestore-4Px61hHS.mjs} +4 -10
  25. package/dist/packem_shared/{backfillAggregateIndexes-BF5eL7kW.mjs → backfillAggregateIndexes-DDoT-UUI.mjs} +3 -2
  26. package/dist/packem_shared/{compileWhereSql-CXrhFA3G.mjs → compileWhereSql-DE6yfRcQ.mjs} +5 -3
  27. package/dist/packem_shared/constant-time-equal-BVRWZgES.mjs +12 -0
  28. package/dist/packem_shared/{createSystemReader-8CzSZP9V.mjs → createSystemReader-D12eNH13.mjs} +4 -2
  29. package/dist/packem_shared/ctx-db-idempotency-BdcNpvY4.mjs +108 -0
  30. package/dist/packem_shared/ctx-db-shapes-Cz9dHyh1.mjs +53 -0
  31. package/dist/packem_shared/diffExternalSource-Cx9HUPJj.mjs +44 -0
  32. package/dist/packem_shared/{exportShardRows-DZEhUeyI.mjs → exportShardRows-Dy3oFZ26.mjs} +4 -3
  33. package/dist/packem_shared/isSourceDue-CYkt7Ru8.mjs +41 -0
  34. package/dist/packem_shared/json-response-BdbtpOhm.mjs +3 -0
  35. package/dist/packem_shared/materializeExternalRows-CTqZisSC.mjs +23 -0
  36. package/dist/packem_shared/{runShardMigrations-C3bn5r93.mjs → runShardMigrations-BGx4v2B6.mjs} +6 -4
  37. package/dist/packem_shared/serialize-sql-BlRUoiQe.mjs +14 -0
  38. package/dist/packem_shared/{serveRelationFanout-Clr1a05L.mjs → serveRelationFanout-BgaNg3Hu.mjs} +4 -7
  39. package/dist/packem_shared/stableStringify-MydiuScU.mjs +40 -0
  40. package/dist/packem_shared/subscription-delivery-CWigSEr3.mjs +348 -0
  41. package/dist/packem_shared/subscriptionListDeltas-DRLvFlM1.mjs +1 -0
  42. package/package.json +5 -3
  43. package/dist/packem_shared/NotFoundError-CMuMZt81.mjs +0 -10
  44. package/dist/packem_shared/ctx-db-idempotency-DkC9rP91.mjs +0 -35
  45. package/dist/packem_shared/encodePartitionKey-C6blLR5K.mjs +0 -1
  46. /package/dist/packem_shared/{AUTH_METRICS_BUCKET_MS-CiHHYeJi.mjs → AUTH_METRICS_BUCKETS_TABLE-CiHHYeJi.mjs} +0 -0
  47. /package/dist/packem_shared/{ensureFunctionMetricsTables-UDNVD7FS.mjs → FUNCTION_METRICS_BUCKETS_TABLE-UDNVD7FS.mjs} +0 -0
  48. /package/dist/packem_shared/{clearCapturedMail-CPpgl-dX.mjs → MAIL_RETENTION-CPpgl-dX.mjs} +0 -0
  49. /package/dist/packem_shared/{buildSecurityAudit-CCAvoFlr.mjs → MIN_ADMIN_TOKEN_LENGTH-CCAvoFlr.mjs} +0 -0
  50. /package/dist/packem_shared/{ftsTableName-BLEMawrp.mjs → buildFtsMatch-BLEMawrp.mjs} +0 -0
  51. /package/dist/packem_shared/{runTriggers-5N6_Fx0A.mjs → hasTrigger-5N6_Fx0A.mjs} +0 -0
@@ -1,15 +1,4 @@
1
- const serializeSqlValue = (value) => {
2
- if (typeof value === "boolean") {
3
- return value ? 1 : 0;
4
- }
5
- if (value === null || typeof value === "string" || typeof value === "number") {
6
- return value;
7
- }
8
- if (typeof value === "bigint") {
9
- return value.toString();
10
- }
11
- return JSON.stringify(value);
12
- };
1
+ import { s as serializeSqlValue } from './serialize-sql-BlRUoiQe.mjs';
13
2
 
14
3
  const compareStrings = (a, b) => {
15
4
  if (a < b) {
@@ -99,4 +88,4 @@ const rankKeyFromDocument = (index, document_) => {
99
88
  };
100
89
  };
101
90
 
102
- export { RANK_TIEBREAK as R, resolveRankPartition as a, serializeSqlValue as b, rankKeyFromDocument as c, encodePartitionKey as e, matchesRankStaticWhere as m, rankTableName as r, sortColumnName as s };
91
+ export { RANK_TIEBREAK, encodePartitionKey, matchesRankStaticWhere, rankKeyFromDocument as rankKeyFromDoc, rankTableName, resolveRankPartition, sortColumnName };
@@ -1,13 +1,14 @@
1
+ import { LunoraError } from '@lunora/errors';
2
+
1
3
  const RLS_UNWRAP_SYMBOL = /* @__PURE__ */ Symbol.for("lunora.ctxdb.rls-unwrap");
2
- class RlsRequiredError extends Error {
3
- code = "RLS_REQUIRED";
4
- status = 403;
4
+ class RlsRequiredError extends LunoraError {
5
5
  table;
6
6
  constructor(table) {
7
7
  super(
8
- `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.`
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" }
9
11
  );
10
- this.name = "RlsRequiredError";
11
12
  this.table = table;
12
13
  }
13
14
  }
@@ -47,9 +48,9 @@ const guardWriter = (raw, schema, tableOfId) => {
47
48
  guardTable(tableName);
48
49
  return base.count(tableName, whereOrArgs);
49
50
  },
50
- delete: async (id, expectedTable) => {
51
+ delete: async (id, expectedTable, options) => {
51
52
  await guardById(id, expectedTable);
52
- return base.delete(id, expectedTable);
53
+ return base.delete(id, expectedTable, options);
53
54
  },
54
55
  deleteMany: async (ids, options, expectedTable) => {
55
56
  for (const id of ids) {
@@ -57,6 +58,10 @@ const guardWriter = (raw, schema, tableOfId) => {
57
58
  }
58
59
  return base.deleteMany(ids, options, expectedTable);
59
60
  },
61
+ deleteWhere: base.deleteWhere ? async (tableName, where, options) => {
62
+ guardTable(tableName);
63
+ return await base.deleteWhere?.(tableName, where, options);
64
+ } : void 0,
60
65
  findFirst: (tableName, args) => {
61
66
  guardTable(tableName);
62
67
  return base.findFirst(tableName, args);
@@ -99,6 +104,10 @@ const guardWriter = (raw, schema, tableOfId) => {
99
104
  }
100
105
  return base.patchMany(patches, options, expectedTable);
101
106
  },
107
+ patchWhere: base.patchWhere ? async (tableName, args, options) => {
108
+ guardTable(tableName);
109
+ return await base.patchWhere?.(tableName, args, options);
110
+ } : void 0,
102
111
  query: (tableName) => {
103
112
  guardTable(tableName);
104
113
  return base.query(tableName);
@@ -111,9 +120,13 @@ const guardWriter = (raw, schema, tableOfId) => {
111
120
  guardTable(tableName);
112
121
  return base.rankPage(tableName, indexName, options);
113
122
  },
114
- replace: async (id, document, expectedTable) => {
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) => {
115
128
  await guardById(id, expectedTable);
116
- return base.replace(id, document, expectedTable);
129
+ return base.restore?.(id, expectedTable);
117
130
  }
118
131
  };
119
132
  if (baseRankBefore) {