@lunora/do 1.0.0-alpha.7 → 1.0.0-alpha.9

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 (20) hide show
  1. package/dist/index.d.mts +627 -21
  2. package/dist/index.d.ts +627 -21
  3. package/dist/index.mjs +11 -10
  4. package/dist/packem_shared/{ADMIN_FUNCTIONS-CHcC8fKV.mjs → ADMIN_FUNCTIONS-D_UiYJFk.mjs} +3 -1
  5. package/dist/packem_shared/{CDC_LOG_TABLE-Ctdmxmrv.mjs → CDC_LOG_TABLE-DSycmnDf.mjs} +5 -1
  6. package/dist/packem_shared/{DEFAULT_MAX_RELATION_KEYS-Dou2PWdO.mjs → DEFAULT_MAX_RELATION_KEYS-CHEvKjZt.mjs} +50 -1
  7. package/dist/packem_shared/{NotUniqueError-h_thNFSZ.mjs → NotUniqueError-Cwv7Pe7J.mjs} +9 -7
  8. package/dist/packem_shared/{rank-CrkEIpF4.mjs → RANK_TIEBREAK-CXhdcA1o.mjs} +2 -13
  9. package/dist/packem_shared/{ROOT_DO_SIZE_WARN_BYTES-2DxWrdla.mjs → ROOT_DO_SIZE_WARN_BYTES-DKwBF3Jp.mjs} +1067 -29
  10. package/dist/packem_shared/{ReactiveCache-ByVzgH3d.mjs → ReactiveCache-1hDydFyv.mjs} +1 -28
  11. package/dist/packem_shared/{backfillAggregateIndexes-BbVPvciS.mjs → backfillAggregateIndexes-BZsOqDXP.mjs} +2 -1
  12. package/dist/packem_shared/ctx-db-idempotency-BdcNpvY4.mjs +108 -0
  13. package/dist/packem_shared/ctx-db-shapes-DVoeZpo-.mjs +53 -0
  14. package/dist/packem_shared/{runShardMigrations-PabobOjF.mjs → runShardMigrations-nIwoQeOK.mjs} +5 -3
  15. package/dist/packem_shared/serialize-sql-BlRUoiQe.mjs +14 -0
  16. package/dist/packem_shared/{serveRelationFanout-oxaM6_WL.mjs → serveRelationFanout-C6lDaesn.mjs} +1 -1
  17. package/dist/packem_shared/stableStringify-CyHKJXre.mjs +30 -0
  18. package/package.json +1 -1
  19. package/dist/packem_shared/RANK_TIEBREAK-C6blLR5K.mjs +0 -1
  20. package/dist/packem_shared/ctx-db-idempotency-DkC9rP91.mjs +0 -35
package/dist/index.mjs CHANGED
@@ -3,34 +3,35 @@ export { AGGREGATE_SQL_FUNCTION, aggregateSqlFunction, matchesStaticWhere, norma
3
3
  export { aggregateTableName, coerceAggregateNumber, encodeAggregateKey, foldAggregateTally, readAggregateValue } from './packem_shared/aggregateTableName-CxNqY1Sl.mjs';
4
4
  export { CountRlsUnsupportedError, mergeWhere, planAggregateLookup, selectIndexForAggregate, selectIndexForCount, selectIndexForGroupBy } from './packem_shared/CountRlsUnsupportedError-28ZvvwKS.mjs';
5
5
  export { AUTH_METRICS_BUCKETS_TABLE, AUTH_METRICS_BUCKET_MS, AUTH_METRICS_BUCKET_RETENTION, AUTH_METRICS_TABLE, ensureAuthMetricsTables, readAuthMetrics, recordAuthEvent } from './packem_shared/AUTH_METRICS_BUCKETS_TABLE-CiHHYeJi.mjs';
6
- export { NotUniqueError, assertValidClientId, createShardCtxDb, normalizeIdStructurally } from './packem_shared/NotUniqueError-h_thNFSZ.mjs';
6
+ export { NotUniqueError, assertValidClientId, createShardCtxDb, normalizeIdStructurally } from './packem_shared/NotUniqueError-Cwv7Pe7J.mjs';
7
7
  export { DATA_MIGRATION_STATE_TABLE, readMigrationStatus, runDataMigration } from './packem_shared/DATA_MIGRATION_STATE_TABLE-PTtTiQ7U.mjs';
8
8
  export { SCAN_DEP, createDependencyTracker, depKey } from './packem_shared/SCAN_DEP-DLJF8dsj.mjs';
9
9
  export { renderSql } from './packem_shared/renderSql-D6eUcn2N.mjs';
10
10
  export { FUNCTION_METRICS_BUCKETS_TABLE, FUNCTION_METRICS_BUCKET_MS, FUNCTION_METRICS_BUCKET_RETENTION, FUNCTION_METRICS_INDEX_TABLE, FUNCTION_METRICS_TABLE, ensureFunctionMetricsTables, readFunctionMetricBuckets, readFunctionMetricIndexHits, readFunctionMetrics, readFunctionMetricsTotals, recordFunctionMetric } from './packem_shared/FUNCTION_METRICS_BUCKETS_TABLE-UDNVD7FS.mjs';
11
- export { ADMIN_FUNCTIONS, ADMIN_FUNCTION_PREFIX, RELATION_FUNCTION_PREFIX, facetColumn, listTables, readTablePage, selectMatchingIds } from './packem_shared/ADMIN_FUNCTIONS-CHcC8fKV.mjs';
11
+ export { ADMIN_FUNCTIONS, ADMIN_FUNCTION_PREFIX, FLAGS_FUNCTION_PREFIX, RELATION_FUNCTION_PREFIX, facetColumn, listTables, readTablePage, selectMatchingIds } from './packem_shared/ADMIN_FUNCTIONS-D_UiYJFk.mjs';
12
12
  export { LogBuffer } from './packem_shared/LogBuffer-B_Ezju_N.mjs';
13
13
  export { MAIL_RETENTION, MAIL_TABLE, clearCapturedMail, ensureMailTable, readCapturedMail, recordCapturedMail } from './packem_shared/MAIL_RETENTION-CPpgl-dX.mjs';
14
14
  export { default as NotFoundError } from './packem_shared/NotFoundError-CMuMZt81.mjs';
15
15
  export { armRestore, readBookmark } from './packem_shared/armRestore-BJk53Ro8.mjs';
16
16
  export { applySelect, buildSeekWhere, decodeCursor, encodeCursor, normalizeOrderKeys, softDeleteScope } from './packem_shared/applySelect-BvZdFUBT.mjs';
17
- export { R as RANK_TIEBREAK, e as encodePartitionKey, m as matchesRankStaticWhere, r as rankTableName, a as resolveRankPartition, s as sortColumnName } from './packem_shared/rank-CrkEIpF4.mjs';
18
- export { ReactiveCache, reactiveCacheKey, stableStringify } from './packem_shared/ReactiveCache-ByVzgH3d.mjs';
19
- export { serveRelationFanout } from './packem_shared/serveRelationFanout-oxaM6_WL.mjs';
20
- export { DEFAULT_MAX_RELATION_KEYS, assertFlatPredicate, containsRelationPredicate, isRelationPredicate, resolveRelationPredicates } from './packem_shared/DEFAULT_MAX_RELATION_KEYS-Dou2PWdO.mjs';
17
+ export { RANK_TIEBREAK, encodePartitionKey, matchesRankStaticWhere, rankTableName, resolveRankPartition, sortColumnName } from './packem_shared/RANK_TIEBREAK-CXhdcA1o.mjs';
18
+ export { ReactiveCache, reactiveCacheKey } from './packem_shared/ReactiveCache-1hDydFyv.mjs';
19
+ export { serveRelationFanout } from './packem_shared/serveRelationFanout-C6lDaesn.mjs';
20
+ export { DEFAULT_MAX_RELATION_KEYS, assertFlatPredicate, assertShapeShardable, containsRelationPredicate, isRelationPredicate, resolveRelationPredicates } from './packem_shared/DEFAULT_MAX_RELATION_KEYS-CHEvKjZt.mjs';
21
21
  export { applyOnDelete, resolveWith, runRowValidators } from './packem_shared/applyOnDelete-sA7o1CqD.mjs';
22
22
  export { RLS_UNWRAP_SYMBOL, RlsRequiredError, guardWriter } from './packem_shared/RLS_UNWRAP_SYMBOL-EtGQdC9d.mjs';
23
23
  export { buildFtsMatch, ftsTableName, scoreDocument, stringifySearchText, tokenizeSearch } from './packem_shared/buildFtsMatch-BLEMawrp.mjs';
24
24
  export { M as MIN_ADMIN_TOKEN_LENGTH, a as MIN_AUTH_SECRET_LENGTH, b as buildSecurityAudit } from './packem_shared/security-audit-CucgBice.mjs';
25
25
  export { SESSION_DO_TTL_DEFAULT, SessionDO } from './packem_shared/SESSION_DO_TTL_DEFAULT-ilPZsVwu.mjs';
26
- export { ROOT_DO_SIZE_WARN_BYTES, ROOT_SHARD_NAME, ShardDO } from './packem_shared/ROOT_DO_SIZE_WARN_BYTES-2DxWrdla.mjs';
26
+ export { ROOT_DO_SIZE_WARN_BYTES, ROOT_SHARD_NAME, ShardDO } from './packem_shared/ROOT_DO_SIZE_WARN_BYTES-DKwBF3Jp.mjs';
27
27
  export { SHARD_REGISTRY_DO_NAME, ShardRegistryDO } from './packem_shared/SHARD_REGISTRY_DO_NAME-BsAbi5Mn.mjs';
28
28
  export { MAX_SQL_ROWS, assertReadonly, runReadonlySql } from './packem_shared/MAX_SQL_ROWS-dDcFE1YZ.mjs';
29
29
  export { createSystemReader } from './packem_shared/createSystemReader-8CzSZP9V.mjs';
30
30
  export { ConflictError } from './packem_shared/ConflictError-C0STs6bU.mjs';
31
31
  export { hasTrigger, runTriggers } from './packem_shared/hasTrigger-5N6_Fx0A.mjs';
32
32
  export { compileWhereSql } from './packem_shared/compileWhereSql-CXrhFA3G.mjs';
33
- export { CDC_LOG_TABLE, applyCdcChanges, readCdcChanges, trimCdcChanges } from './packem_shared/CDC_LOG_TABLE-Ctdmxmrv.mjs';
34
- export { backfillAggregateIndexes, backfillRankIndexes } from './packem_shared/backfillAggregateIndexes-BbVPvciS.mjs';
35
- export { runShardMigrations } from './packem_shared/runShardMigrations-PabobOjF.mjs';
33
+ export { CDC_LOG_TABLE, applyCdcChanges, readCdcChanges, trimCdcChanges } from './packem_shared/CDC_LOG_TABLE-DSycmnDf.mjs';
34
+ export { backfillAggregateIndexes, backfillRankIndexes } from './packem_shared/backfillAggregateIndexes-BZsOqDXP.mjs';
35
+ export { runShardMigrations } from './packem_shared/runShardMigrations-nIwoQeOK.mjs';
36
+ export { stableStringify } from './packem_shared/stableStringify-CyHKJXre.mjs';
36
37
  export { subscriptionListDeltas } from './packem_shared/subscriptionListDeltas-ce84gpwL.mjs';
@@ -1,5 +1,6 @@
1
1
  const ADMIN_FUNCTION_PREFIX = "__lunora_admin__:";
2
2
  const RELATION_FUNCTION_PREFIX = "__lunora_relation__:";
3
+ const FLAGS_FUNCTION_PREFIX = "__lunora_flags__:";
3
4
  const ADMIN_FUNCTIONS = {
4
5
  applyCdc: "__lunora_admin__:applyCdc",
5
6
  cdcSync: "__lunora_admin__:cdcSync",
@@ -27,6 +28,7 @@ const ADMIN_FUNCTIONS = {
27
28
  // eslint-disable-next-line no-secrets/no-secrets -- reserved admin RPC path constant, not a credential
28
29
  getWorkflowInstanceStatus: "__lunora_admin__:getWorkflowInstanceStatus",
29
30
  importShard: "__lunora_admin__:importShard",
31
+ listFlags: "__lunora_admin__:listFlags",
30
32
  listQueues: "__lunora_admin__:listQueues",
31
33
  listTables: "__lunora_admin__:listTables",
32
34
  listWorkflows: "__lunora_admin__:listWorkflows",
@@ -311,4 +313,4 @@ const summarizeSubscriptions = (attachments) => {
311
313
  return { connections, totalConnections: connections.length, totalSubscriptions };
312
314
  };
313
315
 
314
- export { ADMIN_FUNCTIONS, ADMIN_FUNCTION_PREFIX, MAX_PAGE_SIZE, RELATION_FUNCTION_PREFIX, facetColumn, findStorageReferences, listTables, readTablePage, selectMatchingIds, summarizeSubscriptions };
316
+ export { ADMIN_FUNCTIONS, ADMIN_FUNCTION_PREFIX, FLAGS_FUNCTION_PREFIX, MAX_PAGE_SIZE, RELATION_FUNCTION_PREFIX, facetColumn, findStorageReferences, listTables, readTablePage, selectMatchingIds, summarizeSubscriptions };
@@ -26,9 +26,13 @@ const appendCdcChange = (sql$1, ts, table, id, op, doc) => {
26
26
  const readCdcChanges = (sql$1, options = {}) => {
27
27
  const sinceSeq = options.sinceSeq ?? 0;
28
28
  const limit = Math.max(1, Math.min(options.limit ?? 1e3, 1e4));
29
+ const tableFilter = options.tables && options.tables.size > 0 ? sql` AND ${sql.identifier("table")} IN (${sql.join(
30
+ [...options.tables].map((table) => sql`${table}`),
31
+ sql`, `
32
+ )})` : sql``;
29
33
  const rows = runDrizzle(
30
34
  sql$1,
31
- sql`SELECT seq, ts, ${sql.identifier("table")}, id, op, doc FROM ${sql.identifier(CDC_LOG_TABLE)} WHERE seq > ${sinceSeq} ORDER BY seq ASC LIMIT ${limit}`
35
+ sql`SELECT seq, ts, ${sql.identifier("table")}, id, op, doc FROM ${sql.identifier(CDC_LOG_TABLE)} WHERE seq > ${sinceSeq}${tableFilter} ORDER BY seq ASC LIMIT ${limit}`
32
36
  ).toArray();
33
37
  const changes = rows.map((row) => {
34
38
  const base = { id: row.id, op: row.op, seq: row.seq, table: row.table, ts: row.ts };
@@ -156,5 +156,54 @@ const resolveRelationPredicates = async (where, options) => {
156
156
  schema: options.schema
157
157
  });
158
158
  };
159
+ const firstShardedHit = (branches, schema, tableName) => {
160
+ for (const branch of branches) {
161
+ const hit = findShardedRelationTarget(branch, schema, tableName);
162
+ if (hit) {
163
+ return hit;
164
+ }
165
+ }
166
+ return void 0;
167
+ };
168
+ const inspectKey = (key, value, schema, tableName) => {
169
+ if (key === "AND" || key === "OR") {
170
+ return firstShardedHit(branchesOf(value), schema, tableName);
171
+ }
172
+ if (key === "NOT") {
173
+ return firstShardedHit([value ?? {}], schema, tableName);
174
+ }
175
+ const relation = schema.tables[tableName]?.relationMap?.[key];
176
+ if (!relation || !isRelationPredicate(value)) {
177
+ return void 0;
178
+ }
179
+ if (schema.tables[relation.table]?.shardMode?.kind === "shardBy") {
180
+ return { relation: key, target: relation.table };
181
+ }
182
+ return firstShardedHit(Object.values(value), schema, relation.table);
183
+ };
184
+ const findShardedRelationTarget = (where, schema, tableName) => {
185
+ for (const key of Object.keys(where)) {
186
+ const hit = inspectKey(key, where[key], schema, tableName);
187
+ if (hit) {
188
+ return hit;
189
+ }
190
+ }
191
+ return void 0;
192
+ };
193
+ const assertShapeShardable = (effectiveWhere, schema, table) => {
194
+ if (!effectiveWhere) {
195
+ return;
196
+ }
197
+ const offending = findShardedRelationTarget(effectiveWhere, schema, table);
198
+ if (!offending) {
199
+ return;
200
+ }
201
+ throw Object.assign(
202
+ new Error(
203
+ `shape on "${table}" joins the sharded table "${offending.target}" via relation "${offending.relation}" — a live shape cannot replicate rows that live in another shard's Durable Object. Fix it by (a) denormalizing the joined columns into "${table}", or (b) moving "${offending.target}" to .global() so it is served through the latency-tiered D1 shape tier.`
204
+ ),
205
+ { code: "SHAPE_CROSS_SHARD_JOIN", name: "LunoraError", status: 400 }
206
+ );
207
+ };
159
208
 
160
- export { DEFAULT_MAX_RELATION_KEYS, assertFlatPredicate, containsRelationPredicate, isRelationPredicate, resolveRelationPredicates };
209
+ export { DEFAULT_MAX_RELATION_KEYS, assertFlatPredicate, assertShapeShardable, containsRelationPredicate, isRelationPredicate, resolveRelationPredicates };
@@ -2,26 +2,28 @@ import { sql } from 'drizzle-orm';
2
2
  import { matchesStaticWhere, aggregateSqlFunction, normalizeCountArgument, throwingScheduler } from './AGGREGATE_SQL_FUNCTION-CFk6adSu.mjs';
3
3
  import { encodeAggregateKey, foldAggregateTally, aggregateTableName, coerceAggregateNumber, readAggregateValue } from './aggregateTableName-CxNqY1Sl.mjs';
4
4
  import { mergeWhere, CountRlsUnsupportedError, selectIndexForGroupBy, selectIndexForCount, selectIndexForAggregate } from './CountRlsUnsupportedError-28ZvvwKS.mjs';
5
- import { appendCdcChange } from './CDC_LOG_TABLE-Ctdmxmrv.mjs';
6
- export { CDC_LOG_TABLE, applyCdcChanges, bumpCdcEpoch, minCdcSeq, readCdcChanges, readCdcCursor, readCdcEpoch, trimCdcChanges } from './CDC_LOG_TABLE-Ctdmxmrv.mjs';
5
+ import { appendCdcChange } from './CDC_LOG_TABLE-DSycmnDf.mjs';
6
+ export { CDC_LOG_TABLE, applyCdcChanges, bumpCdcEpoch, minCdcSeq, readCdcChanges, readCdcCursor, readCdcEpoch, trimCdcChanges } from './CDC_LOG_TABLE-DSycmnDf.mjs';
7
7
  import { r as runDrizzle } from './do-exec-5eQy5cEi.mjs';
8
8
  import { i as isFtsAvailable, D as DOC_COLUMN$1, r as rowToDocument, A as AGG_KEY, a as AGG_VALUE, b as AGG_COUNT, d as aggUpsertSql, j as jsonPathSql, q as quoteIdentifier, t as tableColumns, e as qualifiedJsonPathSql } from './do-sql-BCHCWtrD.mjs';
9
9
  import { param } from './renderSql-D6eUcn2N.mjs';
10
- import { s as sortColumnName, m as matchesRankStaticWhere, e as encodePartitionKey, b as serializeSqlValue, r as rankTableName, a as resolveRankPartition, R as RANK_TIEBREAK } from './rank-CrkEIpF4.mjs';
10
+ import { sortColumnName, matchesRankStaticWhere, encodePartitionKey, rankTableName, resolveRankPartition, RANK_TIEBREAK } from './RANK_TIEBREAK-CXhdcA1o.mjs';
11
11
  import { stringifySearchText, ftsTableName, tokenizeSearch, buildFtsMatch, scoreDocument } from './buildFtsMatch-BLEMawrp.mjs';
12
+ import { s as serializeSqlValue } from './serialize-sql-BlRUoiQe.mjs';
12
13
  import { SCAN_DEP } from './SCAN_DEP-DLJF8dsj.mjs';
13
14
  import { decodeCursor, normalizeOrderKeys, buildSeekWhere, applySelect, encodeCursor, softDeleteScope, buildSeekBeforeWhere } from './applySelect-BvZdFUBT.mjs';
14
15
  import NotFoundError from './NotFoundError-CMuMZt81.mjs';
15
- import { assertFlatPredicate, resolveRelationPredicates } from './DEFAULT_MAX_RELATION_KEYS-Dou2PWdO.mjs';
16
+ import { assertFlatPredicate, resolveRelationPredicates } from './DEFAULT_MAX_RELATION_KEYS-CHEvKjZt.mjs';
16
17
  import { runRowValidators, resolveWith, applyOnDelete } from './applyOnDelete-sA7o1CqD.mjs';
17
18
  import { guardWriter } from './RLS_UNWRAP_SYMBOL-EtGQdC9d.mjs';
18
19
  import { createSystemReader } from './createSystemReader-8CzSZP9V.mjs';
19
20
  import { ConflictError } from './ConflictError-C0STs6bU.mjs';
20
21
  import { runTriggers } from './hasTrigger-5N6_Fx0A.mjs';
21
22
  import { compileWhereSql } from './compileWhereSql-CXrhFA3G.mjs';
22
- export { backfillAggregateIndexes, backfillRankIndexes } from './backfillAggregateIndexes-BbVPvciS.mjs';
23
- export { I as IDEMPOTENCY_TABLE, r as readIdempotent, t as trimIdempotent, w as writeIdempotent } from './ctx-db-idempotency-DkC9rP91.mjs';
24
- export { runShardMigrations } from './runShardMigrations-PabobOjF.mjs';
23
+ export { backfillAggregateIndexes, backfillRankIndexes } from './backfillAggregateIndexes-BZsOqDXP.mjs';
24
+ export { C as CLIENT_WATERMARK_TABLE, G as GLOBAL_SHAPE_SNAPSHOT_TABLE, I as IDEMPOTENCY_TABLE, c as advanceClientWatermark, d as deleteGlobalShapeSnapshot, e as deleteGlobalShapeSnapshotsForConnection, m as migrateClientWatermark, b as migrateGlobalShapeSnapshot, r as readClientWatermark, f as readGlobalShapeSnapshot, g as readIdempotent, t as trimIdempotent, w as writeGlobalShapeSnapshot, h as writeIdempotent } from './ctx-db-idempotency-BdcNpvY4.mjs';
25
+ export { runShardMigrations } from './runShardMigrations-nIwoQeOK.mjs';
26
+ export { s as selectShapeMemberIds, a as selectShapeRows } from './ctx-db-shapes-DVoeZpo-.mjs';
25
27
 
26
28
  const rankIndexFieldsUnchanged = (index, previous, next) => {
27
29
  const fields = [...index.partitionBy ?? [], ...index.sortBy.map((key) => key.field), ...index.where ? Object.keys(index.where) : []];
@@ -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 };