durable-db 0.13.0 → 0.13.2

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.
package/README.md CHANGED
@@ -264,7 +264,7 @@ Invoice.toJsonSchema(); // JSON Schema (2020-12 or draft-07)
264
264
  Invoice['~standard']; // a Standard Schema, with its JSON Schema converter
265
265
  ```
266
266
 
267
- It has ArkType's keywords (`string.email`, `string.uuid`, `number.integer`, `string.numeric.parse`, `string.date.iso.parse`, …), bounds (`'string > 0'`, `'0 < number <= 10'`, `'number % 2'`), unions, intersections, literals, regexes, arrays, tuples (`['string', 'number?']`, `['string', '...', 'number[]']`), `Record<K, V>`, object keys (`'key?'`, `'[string]'`, `'+'`, `'...'`), defaults (`'number = 0'`), tuple expressions (`'[]'`, `'|'`, `'&'`, `'=>'`, `':'`, `'|>'`, `'@'`, `'==='`, `'instanceof'`, `'keyof'`) and a Type's methods (`array`, `or`, `and`, `merge`, `pick`, `omit`, `partial`, `required`, `keyof`, `get`, `optional`, `default`, `narrow`, `pipe`, `to`, `describe`, `configure`, `brand`, `onUndeclaredKey`, `props`, `assert`, `allows`, `from`, `toJsonSchema`). ArkType's scopes, generics, `match` and `fn` are not there: a definition it does not know fails with a `ParseError` naming it, never a validator that checks something else. `tests/type/conformance.test.ts` runs every supported definition through both against the same values. A Type of `durable-db/type` nests in ArkType's own definitions and the other way round.
267
+ It has ArkType's keywords (`string.email`, `string.uuid`, `number.integer`, `string.numeric.parse`, `string.date.iso.parse`, …), bounds (`'string > 0'`, `'0 < number <= 10'`, `'number % 2'`), unions, intersections, literals, regexes, arrays, tuples (`['string', 'number?']`, `['string', '...', 'number[]']`), `Record<K, V>`, object keys (`'key?'`, `'[string]'`, `'+'`, `'...'`), defaults (`'number = 0'`), tuple expressions (`'[]'`, `'|'`, `'&'`, `'=>'`, `':'`, `'|>'`, `'@'`, `'==='`, `'instanceof'`, `'keyof'`) and a Type's methods (`array`, `or`, `and`, `merge`, `pick`, `omit`, `partial`, `required`, `keyof`, `get`, `optional`, `default`, `narrow`, `pipe`, `to`, `describe`, `configure`, `brand`, `onUndeclaredKey`, `props`, `assert`, `allows`, `from`, `toJsonSchema`). ArkType's scopes, generics, `match` and `fn` are not there: a definition it does not know fails with a `ParseError` naming it, never a validator that checks something else. `tests/type/conformance.test.ts` runs every supported definition through both against the same values. One difference is on purpose: a JSON Schema lists an object's `properties` in the order the keys were declared, where ArkType sorts them (its `required` list stays sorted). A Type of `durable-db/type` nests in ArkType's own definitions and the other way round.
268
268
 
269
269
  ### The `handler` function
270
270
 
@@ -1,4 +1,4 @@
1
- import { t as createTypeParser } from "./type-CUgZsZp3.js";
1
+ import { t as createTypeParser } from "./type-pAQ37iEL.js";
2
2
  //#region src/db/actionArgs.ts
3
3
  /**
4
4
  * `type` (durable-db/type: ArkType's definitions and types), for an
package/dist/cli/bin.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { n as registerDbCommands } from "../cli--9cKeEka.js";
2
+ import { n as registerDbCommands } from "../cli-B_bNgIGE.js";
3
3
  import { Command } from "commander";
4
4
  //#region src/cli/bin.ts
5
5
  const program = new Command();
package/dist/cli/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { c as getDatabaseEpochs, d as getInstanceKey, f as init_state, g as runningDevServer, l as getDevEpoch, m as loadDevState, o as generateEpoch, p as loadDevMigrations, s as getDatabaseEpoch, u as getDevPaths, v as saveDevState } from "../state-UT6GH0JD.js";
2
2
  import { _ as parseRenameSpec, u as SchemaRenameRequiredError } from "../snapshot-CY4FLqAo.js";
3
3
  import { n as declaresSchema } from "../parser-mUnAtllk.js";
4
- import { C as diffSchema, D as reportCliError, E as loadSchemaTables, O as selectDatabases, S as diffDatabases, T as loadSchema, _ as sift, a as reset, b as pushOne, c as status, d as generate, f as generateOne, g as replayWithRows, h as readAccepted, i as DevServerRunningError, l as MigrationFailsOnRowsError, m as accept, n as registerDbCommands, o as resetAndPush, p as ACCEPTED_FILE, r as validate, s as formatStatus, t as createDbCommand, u as UnsafeMigrationError, v as writeAccepted, w as discoverDatabases, x as UnknownDatabaseError, y as push } from "../cli--9cKeEka.js";
4
+ import { C as diffSchema, D as reportCliError, E as loadSchemaTables, O as selectDatabases, S as diffDatabases, T as loadSchema, _ as sift, a as reset, b as pushOne, c as status, d as generate, f as generateOne, g as replayWithRows, h as readAccepted, i as DevServerRunningError, l as MigrationFailsOnRowsError, m as accept, n as registerDbCommands, o as resetAndPush, p as ACCEPTED_FILE, r as validate, s as formatStatus, t as createDbCommand, u as UnsafeMigrationError, v as writeAccepted, w as discoverDatabases, x as UnknownDatabaseError, y as push } from "../cli-B_bNgIGE.js";
5
5
  init_state();
6
6
  export { ACCEPTED_FILE, DevServerRunningError, MigrationFailsOnRowsError, SchemaRenameRequiredError, UnknownDatabaseError, UnsafeMigrationError, accept, createDbCommand, declaresSchema, diffDatabases, diffSchema, discoverDatabases, formatStatus, generate, generateEpoch, generateOne, getDatabaseEpoch, getDatabaseEpochs, getDevEpoch, getDevPaths, getInstanceKey, loadDevMigrations, loadDevState, loadSchema, loadSchemaTables, parseRenameSpec, push, pushOne, readAccepted, registerDbCommands, replayWithRows, reportCliError, reset, resetAndPush, runningDevServer, saveDevState, selectDatabases, sift, status, validate, writeAccepted };
@@ -486,7 +486,7 @@ function compare(migration, statements, before, after) {
486
486
  /** What to do about a failure, by what SQLite said. */
487
487
  function remedy(error) {
488
488
  if (/NOT NULL constraint failed/i.test(error)) return "a row holds NULL there — give those rows a value in this migration, before the statement: UPDATE … SET … WHERE … IS NULL";
489
- if (/FOREIGN KEY constraint failed|foreign key mismatch|references a row that is not there/i.test(error)) return "a row references a row that is not there — remove or repair those rows in this migration, before the statement: DELETE FROM … WHERE … NOT IN (SELECT …)";
489
+ if (/FOREIGN KEY constraint failed|foreign key mismatch|references a row that is not there/i.test(error)) return "a row references a row that is not there — remove or repair those rows in this migration, before the statement: add the rows they reference (INSERT INTO … SELECT DISTINCT … WHERE … NOT IN (SELECT …)), or remove the ones that reference nothing (DELETE FROM … WHERE … NOT IN (SELECT …))";
490
490
  if (/UNIQUE constraint failed/i.test(error)) return "two rows hold the same value there — make them distinct, or remove one, in this migration before the statement";
491
491
  if (/CHECK constraint failed/i.test(error)) return "a row does not meet the check — repair those rows in this migration, before the statement";
492
492
  return "it passes on an empty database and fails on one with rows";
package/dist/db/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { i as init_debug, n as debugMigrations } from "../debug-Cz8KzMft.js";
2
- import { a as createRelated, c as DrizzleDefaultsPlugin, d as createJsonPlugins, f as dateSerializers, h as relationsOf, i as RelatedExpression, l as SchemaPlugin, m as relationOf, n as defineDatabase, p as parseJsonValue, s as DateSerializePlugin, u as createDrizzlePlugins } from "../defineDatabase-DypFFfjn.js";
3
- import { r as type } from "../type-CUgZsZp3.js";
4
- import "../actionArgs-DP2tQrlf.js";
5
- import { a as outboxRetryDelay, c as tenantOfInstanceKey, i as createActionOutbox, n as OUTBOX_DDL, o as outboxSink, r as OUTBOX_TABLE, s as queueOutboxSink, t as createKyselyFromSql } from "../kysely-DGc-CG_v.js";
2
+ import { a as createRelated, c as DrizzleDefaultsPlugin, d as createJsonPlugins, f as dateSerializers, h as relationsOf, i as RelatedExpression, l as SchemaPlugin, m as relationOf, n as defineDatabase, p as parseJsonValue, s as DateSerializePlugin, u as createDrizzlePlugins } from "../defineDatabase-B1pKzO-V.js";
3
+ import { r as type } from "../type-pAQ37iEL.js";
4
+ import "../actionArgs-oUWwX6Xn.js";
5
+ import { a as outboxRetryDelay, c as tenantOfInstanceKey, i as createActionOutbox, n as OUTBOX_DDL, o as outboxSink, r as OUTBOX_TABLE, s as queueOutboxSink, t as createKyselyFromSql } from "../kysely-D07wMKZZ.js";
6
6
  import { t as guardReferencingRows } from "../referencingRows-B6rU7TDW.js";
7
7
  import { CamelCasePlugin } from "kysely";
8
8
  import { DurableObject } from "cloudflare:workers";
@@ -1,5 +1,5 @@
1
- import { r as type } from "./type-CUgZsZp3.js";
2
- import { t as actionArgsType } from "./actionArgs-DP2tQrlf.js";
1
+ import { r as type } from "./type-pAQ37iEL.js";
2
+ import { t as actionArgsType } from "./actionArgs-oUWwX6Xn.js";
3
3
  import { Table, getTableColumns, getTableName, is, isSQLWrapper } from "drizzle-orm";
4
4
  import { SQLiteSyncDialect, getTableConfig } from "drizzle-orm/sqlite-core";
5
5
  import { AliasNode, CamelCasePlugin, ColumnNode, ColumnUpdateNode, DeleteQueryNode, IdentifierNode, InsertQueryNode, OperationNodeTransformer, PrimitiveValueListNode, ReferenceNode, SelectAllNode, SelectQueryNode, TableNode, UpdateQueryNode, ValueListNode, ValueNode, ValuesNode, expressionBuilder, sql } from "kysely";
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { a as createRelated, h as relationsOf, i as RelatedExpression, m as relationOf, n as defineDatabase } from "./defineDatabase-DypFFfjn.js";
2
- import { r as type } from "./type-CUgZsZp3.js";
3
- import "./actionArgs-DP2tQrlf.js";
1
+ import { a as createRelated, h as relationsOf, i as RelatedExpression, m as relationOf, n as defineDatabase } from "./defineDatabase-B1pKzO-V.js";
2
+ import { r as type } from "./type-pAQ37iEL.js";
3
+ import "./actionArgs-oUWwX6Xn.js";
4
4
  import { blob, foreignKey, index, integer, numeric, primaryKey, real, table, text, uniqueIndex } from "./schema.js";
5
5
  import { n as describeAction } from "./describeAction-CEKfxTQ4.js";
6
6
  import { getTenantId, hasTenantId, setTenantIdResolver } from "./context/index.js";
@@ -1,4 +1,4 @@
1
- import { l as SchemaPlugin, o as createRelatedPlugins, s as DateSerializePlugin, u as createDrizzlePlugins } from "./defineDatabase-DypFFfjn.js";
1
+ import { l as SchemaPlugin, o as createRelatedPlugins, s as DateSerializePlugin, u as createDrizzlePlugins } from "./defineDatabase-B1pKzO-V.js";
2
2
  import { CamelCasePlugin, Kysely, SqliteDialect, SqliteQueryCompiler } from "kysely";
3
3
  //#region src/db/outbox.ts
4
4
  /** A sink module's default export as a sink: a deliver function, or an object with one. */
@@ -172,7 +172,8 @@ async function buildAndLoadSchema(schemaPath, tableNames) {
172
172
  format: "esm",
173
173
  platform: "node",
174
174
  packages: "external",
175
- target: "node18"
175
+ target: "node18",
176
+ logLevel: "silent"
176
177
  });
177
178
  if (result.outputFiles?.length !== 1) throw new Error(`Unexpected esbuild output for ${schemaPath}`);
178
179
  const tempDir = resolveTempDir(schemaPath);
package/dist/registry.js CHANGED
@@ -1,5 +1,5 @@
1
- import { r as type } from "./type-CUgZsZp3.js";
2
- import { t as actionArgsType } from "./actionArgs-DP2tQrlf.js";
1
+ import { r as type } from "./type-pAQ37iEL.js";
2
+ import { t as actionArgsType } from "./actionArgs-oUWwX6Xn.js";
3
3
  import { t as ACTION_INFO } from "./describeAction-CEKfxTQ4.js";
4
4
  import { WebSocketTransport } from "./transport/websocket.js";
5
5
  import { AsyncLocalStorage } from "node:async_hooks";
@@ -3,6 +3,8 @@ import { SQLiteTableWithColumns } from "drizzle-orm/sqlite-core";
3
3
  import { Kysely } from "kysely";
4
4
  import { DatabaseSync } from "node:sqlite";
5
5
  //#region src/testing/index.d.ts
6
+ /** `node:sqlite`, loaded without Node 22's experimental notice: for a test that opens a database of its own. */
7
+ export declare const loadSqlite: () => typeof import('node:sqlite');
6
8
  type Schema = Record<string, SQLiteTableWithColumns<any>>;
7
9
  export interface CreateTestDatabaseOptions {
8
10
  /**
@@ -1,12 +1,30 @@
1
- import { r as liveTestDatabases, t as ACTION_TEST_META } from "../defineDatabase-DypFFfjn.js";
2
- import { r as type } from "../type-CUgZsZp3.js";
3
- import "../actionArgs-DP2tQrlf.js";
1
+ import { r as liveTestDatabases, t as ACTION_TEST_META } from "../defineDatabase-B1pKzO-V.js";
2
+ import { r as type } from "../type-pAQ37iEL.js";
3
+ import "../actionArgs-oUWwX6Xn.js";
4
4
  import { setTenantIdResolver } from "../context/index.js";
5
- import { c as tenantOfInstanceKey, i as createActionOutbox, t as createKyselyFromSql } from "../kysely-DGc-CG_v.js";
5
+ import { c as tenantOfInstanceKey, i as createActionOutbox, t as createKyselyFromSql } from "../kysely-D07wMKZZ.js";
6
6
  import { i as generateSnapshotFromSchema, n as createEmptySnapshot, r as generateMigrationStatements } from "../snapshot-CY4FLqAo.js";
7
7
  import { createRequire } from "node:module";
8
8
  //#region src/testing/index.ts
9
- const loadSqlite = () => createRequire(import.meta.url)("node:sqlite");
9
+ let sqlite;
10
+ /** `node:sqlite`, loaded without Node 22's experimental notice: for a test that opens a database of its own. */
11
+ const loadSqlite = () => {
12
+ if (sqlite) return sqlite;
13
+ const emit = process.emitWarning;
14
+ process.emitWarning = function(warning, ...rest) {
15
+ const option = rest[0];
16
+ const type = typeof option === "string" ? option : option?.type ?? (warning instanceof Error ? warning.name : void 0);
17
+ const text = warning instanceof Error ? warning.message : String(warning);
18
+ if (type === "ExperimentalWarning" && text.startsWith("SQLite ")) return;
19
+ return emit.call(process, warning, ...rest);
20
+ };
21
+ try {
22
+ sqlite = createRequire(import.meta.url)("node:sqlite");
23
+ } finally {
24
+ process.emitWarning = emit;
25
+ }
26
+ return sqlite;
27
+ };
10
28
  /**
11
29
  * A `SqlStorage`-shaped shim over a synchronous `node:sqlite` connection — the
12
30
  * minimal surface `createKyselyFromSql` drives (`exec(sql, …params).toArray()`).
@@ -113,4 +131,4 @@ async function createTestDatabase(options) {
113
131
  };
114
132
  }
115
133
  //#endregion
116
- export { createTestDatabase };
134
+ export { createTestDatabase, loadSqlite };
@@ -1 +1 @@
1
- export { o as ArkError, s as ArkErrors, i as ParseError, a as ToJsonSchemaError, c as TraversalError, t as createTypeParser, n as isType, r as type } from "../type-CUgZsZp3.js";
1
+ export { o as ArkError, s as ArkErrors, i as ParseError, a as ToJsonSchemaError, c as TraversalError, t as createTypeParser, n as isType, r as type } from "../type-pAQ37iEL.js";
@@ -860,11 +860,14 @@ var ObjectNode = class extends Node {
860
860
  expected = "an object";
861
861
  /** Required keys, then optional ones, each sorted — the order ArkType checks and prints them in. */
862
862
  props;
863
+ /** The keys in the order they were declared — what a JSON Schema's `properties` lists, so a form or an API shows them as written. */
864
+ declaredProps;
863
865
  declared;
864
866
  constructor(props, index = [], undeclared) {
865
867
  super();
866
868
  this.index = index;
867
869
  this.undeclared = undeclared;
870
+ this.declaredProps = [...props];
868
871
  const required = props.filter((p) => p.kind === "required").sort(byKey);
869
872
  const optional = props.filter((p) => p.kind === "optional").sort(byKey);
870
873
  this.props = [...required, ...optional];
@@ -956,7 +959,7 @@ var ObjectNode = class extends Node {
956
959
  const schema = { type: "object" };
957
960
  if (this.props.length > 0) {
958
961
  const properties = {};
959
- for (const prop of this.props) {
962
+ for (const prop of this.declaredProps) {
960
963
  const value = this.valueOf(prop, js.config).json(js);
961
964
  properties[prop.key] = prop.default ? {
962
965
  ...value,
@@ -1645,7 +1648,7 @@ function parseObject(def, ctx) {
1645
1648
  if (key === "...") {
1646
1649
  const spread = parseDefinition(value, ctx);
1647
1650
  if (!(spread instanceof ObjectNode)) throw new ParseError(`'...' must spread an object (was ${spread.expression})`);
1648
- props = mergeProps(props, spread.props);
1651
+ props = mergeProps(props, spread.declaredProps);
1649
1652
  index.push(...spread.index);
1650
1653
  continue;
1651
1654
  }
@@ -1676,9 +1679,12 @@ function parseObject(def, ctx) {
1676
1679
  return new ObjectNode(props, index, undeclared);
1677
1680
  }
1678
1681
  /** Later props replace earlier ones with the same key (`'...'`, `.merge()`). */
1682
+ /** `base` with `over`'s keys: a key both have keeps its place and takes `over`'s prop (like an object spread), new keys follow. */
1679
1683
  function mergeProps(base, over) {
1680
- const keys = new Set(over.map((p) => p.key));
1681
- return [...base.filter((p) => !keys.has(p.key)), ...over];
1684
+ const byKey = new Map(over.map((p) => [p.key, p]));
1685
+ const merged = base.map((p) => byKey.get(p.key) ?? p);
1686
+ const known = new Set(base.map((p) => p.key));
1687
+ return [...merged, ...over.filter((p) => !known.has(p.key))];
1682
1688
  }
1683
1689
  /** `'number = 5'` → `{ def: 'number', value: '5' }`: the top-level `=` that is not `<=`, `>=` or `==`. */
1684
1690
  function defaultSplit(text) {
@@ -1781,8 +1787,8 @@ function union(branches) {
1781
1787
  /** `a & b`: one object of both's keys, one base with both's rules, or both checks in turn. */
1782
1788
  function intersect(a, b) {
1783
1789
  if (a instanceof ObjectNode && b instanceof ObjectNode) {
1784
- const props = [...a.props];
1785
- for (const prop of b.props) {
1790
+ const props = [...a.declaredProps];
1791
+ for (const prop of b.declaredProps) {
1786
1792
  const i = props.findIndex((p) => p.key === prop.key);
1787
1793
  if (i < 0) props.push(prop);
1788
1794
  else {
@@ -2144,22 +2150,22 @@ const prototype = {
2144
2150
  const node = objectNode(this, "merge");
2145
2151
  const other = parseDefinition(def, contextFor(this[CONFIG]));
2146
2152
  if (!(other instanceof ObjectNode)) throw new TypeError(`.merge() needs an object (was ${other.expression})`);
2147
- return makeType(new ObjectNode(mergeProps(node.props, other.props), [...node.index, ...other.index], other.undeclared ?? node.undeclared), this[CONFIG]);
2153
+ return makeType(new ObjectNode(mergeProps(node.declaredProps, other.declaredProps), [...node.index, ...other.index], other.undeclared ?? node.undeclared), this[CONFIG]);
2148
2154
  },
2149
2155
  pick(...keys) {
2150
- return withProps(this, objectNode(this, "pick").props.filter((p) => keys.includes(p.key)));
2156
+ return withProps(this, objectNode(this, "pick").declaredProps.filter((p) => keys.includes(p.key)));
2151
2157
  },
2152
2158
  omit(...keys) {
2153
- return withProps(this, objectNode(this, "omit").props.filter((p) => !keys.includes(p.key)));
2159
+ return withProps(this, objectNode(this, "omit").declaredProps.filter((p) => !keys.includes(p.key)));
2154
2160
  },
2155
2161
  partial() {
2156
- return withProps(this, objectNode(this, "partial").props.map((p) => ({
2162
+ return withProps(this, objectNode(this, "partial").declaredProps.map((p) => ({
2157
2163
  ...p,
2158
2164
  kind: "optional"
2159
2165
  })));
2160
2166
  },
2161
2167
  required() {
2162
- return withProps(this, objectNode(this, "required").props.map(({ default: _default, ...p }) => ({
2168
+ return withProps(this, objectNode(this, "required").declaredProps.map(({ default: _default, ...p }) => ({
2163
2169
  ...p,
2164
2170
  kind: "required"
2165
2171
  })));
@@ -2202,7 +2208,7 @@ const prototype = {
2202
2208
  },
2203
2209
  onUndeclaredKey(behavior) {
2204
2210
  const node = objectNode(this, "onUndeclaredKey");
2205
- return makeType(new ObjectNode(node.props, node.index, behavior), this[CONFIG]);
2211
+ return makeType(new ObjectNode(node.declaredProps, node.index, behavior), this[CONFIG]);
2206
2212
  },
2207
2213
  atLeast(limit) {
2208
2214
  return bounded(this, ">=", limit, "value");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "durable-db",
3
- "version": "0.13.0",
3
+ "version": "0.13.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/eagerpatch/durable-db.git"