durable-db 0.13.0 → 0.13.1

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/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. */
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";
@@ -1,8 +1,8 @@
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
@@ -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.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/eagerpatch/durable-db.git"