durable-db 0.12.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.
@@ -35,6 +35,17 @@ interface SchemaAmbiguity {
35
35
  }
36
36
  /** Every question drizzle-kit would ask to diff `prev` → `cur`. */
37
37
  declare function findAmbiguities(prevSnapshot: Snapshot$2, curSnapshot: Snapshot$2): SchemaAmbiguity[];
38
+ /**
39
+ * The questions that have one answer: a table that lost exactly one column
40
+ * and gained exactly one that is declared the same way — its type, whether it
41
+ * may be null, its default, everything but the name — and a schema that lost
42
+ * exactly one table and gained exactly one with the same columns. That is a
43
+ * rename: the name changed and nothing else did. Taking it for a drop and a
44
+ * create would lose the data for a change nobody made; so it is answered
45
+ * without asking, and said (`renamesFromStatements()` of what was generated).
46
+ * Two candidates, or one that changed in more than its name, stay a question.
47
+ */
48
+ declare function obviousRenames(prevSnapshot: Snapshot$2, curSnapshot: Snapshot$2, ambiguities?: SchemaAmbiguity[]): RenameAnswer[];
38
49
  /** One line per ambiguity: `products: summary added, description removed`. */
39
50
  declare function describeAmbiguity(ambiguity: SchemaAmbiguity): string;
40
51
  /** Example `--rename` answers for an ambiguity (each new name from the first vanished one). */
@@ -177,4 +188,4 @@ declare function snapshotsEqual(a: Snapshot, b: Snapshot): boolean;
177
188
  */
178
189
  declare function hashSnapshot(snapshot: Snapshot): string;
179
190
  //#endregion
180
- export { renamesFromStatements as C, parseRenameSpec as S, applyRenames as _, generateMigrationStatements as a, findAmbiguities as b, hashSnapshot as c, MigrationRiskKind as d, NOT_NULL_WITHOUT_DEFAULT_HINT as f, SchemaRenameRequiredError as g, SchemaAmbiguity as h, createEmptySnapshot as i, snapshotsEqual as l, RenameAnswer as m, Snapshot as n, generateSnapshotFromSchema as o, analyzeMigrationRisks as p, canPrompt as r, generateSnapshotId as s, MigrationResolution as t, MigrationRisk as u, describeAmbiguity as v, unusedRenames as w, formatRename as x, exampleRenames as y };
191
+ export { parseRenameSpec as C, obviousRenames as S, unusedRenames as T, applyRenames as _, generateMigrationStatements as a, findAmbiguities as b, hashSnapshot as c, MigrationRiskKind as d, NOT_NULL_WITHOUT_DEFAULT_HINT as f, SchemaRenameRequiredError as g, SchemaAmbiguity as h, createEmptySnapshot as i, snapshotsEqual as l, RenameAnswer as m, Snapshot as n, generateSnapshotFromSchema as o, analyzeMigrationRisks as p, canPrompt as r, generateSnapshotId as s, MigrationResolution as t, MigrationRisk as u, describeAmbiguity as v, renamesFromStatements as w, formatRename as x, exampleRenames as y };
@@ -1,9 +1,9 @@
1
- import { r as liveTestDatabases, t as ACTION_TEST_META } from "../defineDatabase-Cb5sMNg0.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-q97dtmaQ.js";
6
- import { i as generateSnapshotFromSchema, n as createEmptySnapshot, r as generateMigrationStatements } from "../snapshot-CCIE4_Le.js";
5
+ import { c as tenantOfInstanceKey, i as createActionOutbox, t as createKyselyFromSql } from "../kysely-D07wMKZZ.js";
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
9
  const loadSqlite = () => createRequire(import.meta.url)("node:sqlite");
@@ -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");
@@ -1,5 +1,5 @@
1
1
  import { t as DatabaseSource } from "../discovery-gHeLq8jk.js";
2
- import "../index-CUkSkt7G.js";
2
+ import "../index-B5W4m0Dq.js";
3
3
  import { Plugin } from "vite";
4
4
  import "@babel/types";
5
5
  //#region src/vite/modules/wrangler.d.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "durable-db",
3
- "version": "0.12.0",
3
+ "version": "0.13.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/eagerpatch/durable-db.git"