@forestfuture/active-record 0.8.1 → 0.8.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/dist/cli.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { C as pluralize, E as underscore } from "./identifiers-Dh5DFACX.mjs";
2
- import { a as migrationSql, c as migrationPlan, i as withDigits, n as namesInList, o as quotedName, r as withGeneratedEnum, s as indexName, t as generatedSchema } from "./for-adapters-BbIMUNcz.mjs";
3
- import { f as byName, i as attributeName, l as configFileName, n as castDefault, o as exportName, p as byVersion, r as isCastDefaultType, s as listed, t as storageOverride, u as parseJsonc } from "./storage-override-0ZgeP2sc.mjs";
1
+ import { C as pluralize, E as underscore } from "./epoch-storage-C7186hd1.mjs";
2
+ import { a as migrationSql, c as migrationPlan, i as withDigits, n as namesInList, o as quotedName, r as withGeneratedEnum, s as indexName, t as generatedSchema } from "./for-adapters-CgEQfuyD.mjs";
3
+ import { f as byName, i as attributeName, l as configFileName, n as castDefault, o as exportName, p as byVersion, r as isCastDefaultType, s as listed, t as storageOverride, u as parseJsonc } from "./storage-override-BFC-GSR0.mjs";
4
4
  export { attributeName, byName, byVersion, castDefault, configFileName, exportName, generatedSchema, indexName, isCastDefaultType, listed, migrationPlan, migrationSql, namesInList, parseJsonc, pluralize, quotedName, storageOverride, underscore, withDigits, withGeneratedEnum };
package/dist/command.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import { _ as importPath, a as classify, c as moduleName, d as projectDatabases, g as migrationsOf, h as leadingNumber, m as hasNestedMigrations, n as castDefault, p as byVersion, s as listed, t as storageOverride, u as parseJsonc, v as shown$1, y as slashed } from "./storage-override-0ZgeP2sc.mjs";
3
- import { at as tableize, c as methodsOffFixes, d as enumNameProblem, f as enumScopeNames, i as isBase, ot as ancestors, st as staticBelow } from "./generated-model-DJA8vmNE.mjs";
4
- import { C as pluralize, E as underscore, T as camelize, i as digitsProblem, t as isIdentifier, w as singularize } from "./identifiers-Dh5DFACX.mjs";
2
+ import { _ as importPath, a as classify, c as moduleName, d as projectDatabases, g as migrationsOf, h as leadingNumber, m as hasNestedMigrations, n as castDefault, p as byVersion, s as listed, t as storageOverride, u as parseJsonc, v as shown$1, y as slashed } from "./storage-override-BFC-GSR0.mjs";
3
+ import { U as enumNameProblem, W as enumScopeNames, at as tableize, c as methodsOffFixes, i as isBase, ot as ancestors, st as staticBelow } from "./generated-model-FB7oT7V1.mjs";
4
+ import { C as pluralize, E as underscore, T as camelize, h as isIdentifier, n as digitsProblem, w as singularize } from "./epoch-storage-C7186hd1.mjs";
5
5
  import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, watch, writeFileSync } from "node:fs";
6
6
  import { basename, dirname, join, relative, resolve, sep } from "node:path";
7
7
  import { inspect, parseArgs, types } from "node:util";
@@ -68,11 +68,11 @@ function helpFor(subcommands) {
68
68
  const adapters = {
69
69
  d1: {
70
70
  entry: "@forestfuture/active-record/d1",
71
- plugin: async () => (await import("./plugin-CZPDqguF.mjs")).cli
71
+ plugin: async () => (await import("./plugin-BY2QaRpq.mjs")).cli
72
72
  },
73
73
  postgresql: {
74
74
  entry: "@forestfuture/active-record/postgresql",
75
- plugin: async () => (await import("./plugin-Cf-5Z0_h.mjs")).cli
75
+ plugin: async () => (await import("./plugin-IHD0I6Rg.mjs")).cli
76
76
  }
77
77
  };
78
78
  /** The adapters' names, in the registry's order. */
package/dist/d1.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as QueryEvent$1, D as SchemaAdapter, O as AnyDatabase, w as QueryListener$1 } from "./validations-BSZ5gVeI.mjs";
2
- import { i as ActiveRecordError } from "./index-D5getfHx.mjs";
1
+ import { C as QueryEvent$1, D as SchemaAdapter, O as AnyDatabase, w as QueryListener$1 } from "./validations-DFLjJ203.mjs";
2
+ import { i as ActiveRecordError } from "./index-BfX3Dgy_.mjs";
3
3
  /** The D1 database a generated schema's Models query: `adapter: d1({ binding: "DB" })`. */
4
4
  export declare function d1({ binding }: {
5
5
  binding: string;
package/dist/d1.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { a as AnyDatabase, g as DatabaseExecutor, i as withDatabase, o as databaseExecutor } from "./batch-Ms5p9lKq.mjs";
2
- import { n as onlyRequested, t as workersEnv } from "./for-adapters-C-MQxaIx.mjs";
3
- import { O as ActiveRecordError, x as hexOf, z as NoDatabase } from "./identifiers-Dh5DFACX.mjs";
4
- import { U as boundValue } from "./generated-model-DJA8vmNE.mjs";
1
+ import { a as databaseExecutor, i as AnyDatabase, l as DatabaseExecutor, r as withDatabase } from "./batch-D3nP3g83.mjs";
2
+ import { n as onlyRequested, t as workersEnv } from "./for-adapters-l4rNitkK.mjs";
3
+ import { O as ActiveRecordError, p as hexOf, z as NoDatabase } from "./epoch-storage-C7186hd1.mjs";
4
+ import { O as boundValue } from "./generated-model-FB7oT7V1.mjs";
5
5
  // src/adapters/d1/errors.ts
6
6
  /** D1's error for a Session's bookmark it can't use, and the bookmark it repeats (#237). */
7
7
  const rejectedBookmark = /invalid commitToken bookmark provided: (.*)$/s;
@@ -117,8 +117,8 @@ var RecordNotSaved = class extends ActiveRecordError {
117
117
  };
118
118
  /**
119
119
  * `abort()` was thrown from an after-write callback (`afterSave`, `afterCreate`, `afterUpdate`,
120
- * `afterDestroy`, `afterTouch`). That's a mistake: the write already succeeded and nothing rolls
121
- * back.
120
+ * `afterDestroy`, `afterTouch`), or from an around callback once its `next()` resolved. That's a
121
+ * mistake: the write already succeeded and nothing rolls back.
122
122
  */
123
123
  var AbortAfterPersistence = class extends ActiveRecordError {
124
124
  name = "AbortAfterPersistence";
@@ -265,82 +265,6 @@ function pluralize(word) {
265
265
  function singularize(word) {
266
266
  return inflect(word, SINGULARS);
267
267
  }
268
- // src/binary-values.ts
269
- /** An assigned value as bytes: a `Uint8Array` (a `Buffer` is one) or an `ArrayBuffer`. */
270
- function castBinary(value) {
271
- if (value instanceof Uint8Array) return value;
272
- return value instanceof ArrayBuffer ? new Uint8Array(value) : uncastable;
273
- }
274
- /**
275
- * A stored cell as a new plain `Uint8Array`: D1 returns a BLOB as an array of numbers, and `pg`
276
- * a `bytea` as a `Buffer`.
277
- */
278
- function readBinary(cell) {
279
- if (cell instanceof Uint8Array) return Uint8Array.from(cell);
280
- return Array.isArray(cell) ? Uint8Array.from(cell) : uncastable;
281
- }
282
- /** Whether two stored cells are the same: bytes by content (#20), anything else by `===`. */
283
- function isSameCell(a, b) {
284
- if (!(a instanceof Uint8Array && b instanceof Uint8Array)) return a === b;
285
- return a.length === b.length && a.every((byte, index) => byte === b[index]);
286
- }
287
- /** The character codes of the hex digits, `0`–`9` then `a`–`f`. */
288
- const digitCodes = new TextEncoder().encode("0123456789abcdef");
289
- const decoder = new TextDecoder();
290
- /**
291
- * Bytes as hex text, two digits each, for SQL that reads bytes from JSON (`unhex`, `\\x…`). The
292
- * digits' character codes are written into one array and decoded once: mapping each byte to a
293
- * string of its own takes many times the memory and time, which a large file can't afford.
294
- */
295
- function hexOf(bytes) {
296
- const text = new Uint8Array(bytes.length * 2);
297
- for (let index = 0; index < bytes.length; index++) {
298
- const byte = bytes[index];
299
- text[index * 2] = digitCodes[byte >> 4];
300
- text[index * 2 + 1] = digitCodes[byte & 15];
301
- }
302
- return decoder.decode(text);
303
- }
304
- // src/calendar-values.ts
305
- /** A day: a four-digit year from 0001 (Postgres has no year 0), a month and a day. */
306
- const dayText = /^(?!0000)(\d{4})-(\d{2})-(\d{2})$/;
307
- /**
308
- * Text naming a day that exists (`"2026-01-02"`), as it is; anything else, a `Date` included
309
- * (its day depends on the time zone), is `uncastable`. Each database returns a day as this text.
310
- */
311
- function castDay(value) {
312
- if (typeof value !== "string") return uncastable;
313
- const match = dayText.exec(value);
314
- if (match === null) return uncastable;
315
- const [, year, month, day] = match.map(Number);
316
- const date = /* @__PURE__ */ new Date(0);
317
- date.setUTCFullYear(year, month - 1, day);
318
- return date.getUTCMonth() === month - 1 && date.getUTCDate() === day ? value : uncastable;
319
- }
320
- /** A time of day: hours and minutes, then optionally seconds and up to six digits of a fraction. */
321
- const timeText = /^([01]\d|2[0-3]):([0-5]\d)(?::([0-5]\d)(?:\.(\d{1,6}))?)?$/;
322
- /** The end of a day, which Postgres's `time` holds as `24:00:00`, with no time past it. */
323
- const endOfDay = /^24:00(?::00(?:\.0{1,6})?)?$/;
324
- /**
325
- * Text naming a time of day (`"09:30"`, `"09:30:15.5"`) in its one form, as Postgres writes a
326
- * `time`: seconds always, a fraction without trailing zeros (`"09:30:00"`, `"09:30:15.5"`). The
327
- * end of the day is `"24:00:00"`. Anything else, a `Date` included, is `uncastable`.
328
- */
329
- function castTime(value) {
330
- if (typeof value !== "string") return uncastable;
331
- if (endOfDay.test(value)) return "24:00:00";
332
- const match = timeText.exec(value);
333
- if (match === null) return uncastable;
334
- const [, hours, minutes, seconds = "00", fraction = ""] = match;
335
- const digits = withoutTrailingZeros(fraction);
336
- return `${hours}:${minutes}:${seconds}${digits === "" ? "" : `.${digits}`}`;
337
- }
338
- /** `digits` without the zeros it ends with, found by a loop rather than an unanchored `0+$`. */
339
- function withoutTrailingZeros(digits) {
340
- let end = digits.length;
341
- while (digits[end - 1] === "0") end--;
342
- return digits.slice(0, end);
343
- }
344
268
  // src/enum-values.ts
345
269
  /** Whether `value` is an enum's values: a list of names, or an object of names and stored values. */
346
270
  function isEnumValues(value) {
@@ -421,6 +345,89 @@ function enumValuesOf(model, attribute) {
421
345
  if (values === void 0) throw new UnknownAttribute(`${model.name} has no enum attribute "${attribute}"`);
422
346
  return mappingOf(values);
423
347
  }
348
+ // src/identifiers.ts
349
+ /** Whether a name can be written bare: as a `const`, or as an object key without quotes. */
350
+ function isIdentifier(name) {
351
+ return /^[\p{L}_$][\p{L}\p{N}_$]*$/u.test(name);
352
+ }
353
+ /** Words JavaScript doesn't allow as a declaration's name in a module (strict mode). */
354
+ const reservedWords = new Set("break case catch class const continue debugger default delete do else enum export extends false finally for function if import in instanceof new null return super switch this throw true try typeof var void while with yield let static implements interface package private protected public await arguments eval".split(" "));
355
+ // src/binary-values.ts
356
+ /** An assigned value as bytes: a `Uint8Array` (a `Buffer` is one) or an `ArrayBuffer`. */
357
+ function castBinary(value) {
358
+ if (value instanceof Uint8Array) return value;
359
+ return value instanceof ArrayBuffer ? new Uint8Array(value) : uncastable;
360
+ }
361
+ /**
362
+ * A stored cell as a new plain `Uint8Array`: D1 returns a BLOB as an array of numbers, and `pg`
363
+ * a `bytea` as a `Buffer`.
364
+ */
365
+ function readBinary(cell) {
366
+ if (cell instanceof Uint8Array) return Uint8Array.from(cell);
367
+ return Array.isArray(cell) ? Uint8Array.from(cell) : uncastable;
368
+ }
369
+ /** Whether two stored cells are the same: bytes by content (#20), anything else by `===`. */
370
+ function isSameCell(a, b) {
371
+ if (!(a instanceof Uint8Array && b instanceof Uint8Array)) return a === b;
372
+ return a.length === b.length && a.every((byte, index) => byte === b[index]);
373
+ }
374
+ /** The character codes of the hex digits, `0`–`9` then `a`–`f`. */
375
+ const digitCodes = new TextEncoder().encode("0123456789abcdef");
376
+ const decoder = new TextDecoder();
377
+ /**
378
+ * Bytes as hex text, two digits each, for SQL that reads bytes from JSON (`unhex`, `\\x…`). The
379
+ * digits' character codes are written into one array and decoded once: mapping each byte to a
380
+ * string of its own takes many times the memory and time, which a large file can't afford.
381
+ */
382
+ function hexOf(bytes) {
383
+ const text = new Uint8Array(bytes.length * 2);
384
+ for (let index = 0; index < bytes.length; index++) {
385
+ const byte = bytes[index];
386
+ text[index * 2] = digitCodes[byte >> 4];
387
+ text[index * 2 + 1] = digitCodes[byte & 15];
388
+ }
389
+ return decoder.decode(text);
390
+ }
391
+ // src/calendar-values.ts
392
+ /** A day: a four-digit year from 0001 (Postgres has no year 0), a month and a day. */
393
+ const dayText = /^(?!0000)(\d{4})-(\d{2})-(\d{2})$/;
394
+ /**
395
+ * Text naming a day that exists (`"2026-01-02"`), as it is; anything else, a `Date` included
396
+ * (its day depends on the time zone), is `uncastable`. Each database returns a day as this text.
397
+ */
398
+ function castDay(value) {
399
+ if (typeof value !== "string") return uncastable;
400
+ const match = dayText.exec(value);
401
+ if (match === null) return uncastable;
402
+ const [, year, month, day] = match.map(Number);
403
+ const date = /* @__PURE__ */ new Date(0);
404
+ date.setUTCFullYear(year, month - 1, day);
405
+ return date.getUTCMonth() === month - 1 && date.getUTCDate() === day ? value : uncastable;
406
+ }
407
+ /** A time of day: hours and minutes, then optionally seconds and up to six digits of a fraction. */
408
+ const timeText = /^([01]\d|2[0-3]):([0-5]\d)(?::([0-5]\d)(?:\.(\d{1,6}))?)?$/;
409
+ /** The end of a day, which Postgres's `time` holds as `24:00:00`, with no time past it. */
410
+ const endOfDay = /^24:00(?::00(?:\.0{1,6})?)?$/;
411
+ /**
412
+ * Text naming a time of day (`"09:30"`, `"09:30:15.5"`) in its one form, as Postgres writes a
413
+ * `time`: seconds always, a fraction without trailing zeros (`"09:30:00"`, `"09:30:15.5"`). The
414
+ * end of the day is `"24:00:00"`. Anything else, a `Date` included, is `uncastable`.
415
+ */
416
+ function castTime(value) {
417
+ if (typeof value !== "string") return uncastable;
418
+ if (endOfDay.test(value)) return "24:00:00";
419
+ const match = timeText.exec(value);
420
+ if (match === null) return uncastable;
421
+ const [, hours, minutes, seconds = "00", fraction = ""] = match;
422
+ const digits = withoutTrailingZeros(fraction);
423
+ return `${hours}:${minutes}:${seconds}${digits === "" ? "" : `.${digits}`}`;
424
+ }
425
+ /** `digits` without the zeros it ends with, found by a loop rather than an unanchored `0+$`. */
426
+ function withoutTrailingZeros(digits) {
427
+ let end = digits.length;
428
+ while (digits[end - 1] === "0") end--;
429
+ return digits.slice(0, end);
430
+ }
424
431
  // src/conversion.ts
425
432
  /** A value that can't be read as the attribute's type. */
426
433
  const uncastable = Symbol("uncastable");
@@ -979,11 +986,4 @@ function incremented(digits) {
979
986
  // src/epoch-storage.ts
980
987
  /** A datetime held in an `INTEGER` column as seconds or milliseconds since 1970. */
981
988
  const epochStorages = ["unixSeconds", "unixMilliseconds"];
982
- // src/identifiers.ts
983
- /** Whether a name can be written bare: as a `const`, or as an object key without quotes. */
984
- function isIdentifier(name) {
985
- return /^[\p{L}_$][\p{L}\p{N}_$]*$/u.test(name);
986
- }
987
- /** Words JavaScript doesn't allow as a declaration's name in a module (strict mode). */
988
- const reservedWords = new Set("break case catch class const continue debugger default delete do else enum export extends false finally for function if import in instanceof new null return super switch this throw true try typeof var void while with yield let static implements interface package private protected public await arguments eval".split(" "));
989
- export { abort as $, CallbackAbort as A, NotNullViolation as B, pluralize as C, AbortAfterPersistence as D, underscore as E, InvalidForeignKey as F, RecordNotFound as G, RecordDestroyed as H, InvalidModel as I, SoleRecordExceeded as J, RecordNotSaved as K, IrreversibleOrder as L, ConstraintViolation as M, DeleteRestriction as N, ActiveRecordError as O, IncompatibleRelation as P, UnknownModelName as Q, MissingAttribute as R, isSameCell as S, camelize as T, RecordInvalid as U, ReadonlyAssociation as V, RecordNotDestroyed as W, UnknownAssociation as X, StrictValidationFailed as Y, UnknownAttribute as Z, enumValidations as _, orderDecimal as a, listedNames as b, castValue as c, uncastable as d, writeUntypedValue as f, enumProblem as g, enumEntries as h, digitsProblem as i, CheckViolation as j, AssociationNotLoaded as k, isInvalidDate as l, zonelessDateTime as m, reservedWords as n, castCondition as o, writeValue as p, RecordNotUnique as q, epochStorages as r, castKey as s, isIdentifier as t, readValue as u, enumValuesOf as v, singularize as w, hexOf as x, isEnumValues as y, NoDatabase as z };
989
+ export { abort as $, CallbackAbort as A, NotNullViolation as B, pluralize as C, AbortAfterPersistence as D, underscore as E, InvalidForeignKey as F, RecordNotFound as G, RecordDestroyed as H, InvalidModel as I, SoleRecordExceeded as J, RecordNotSaved as K, IrreversibleOrder as L, ConstraintViolation as M, DeleteRestriction as N, ActiveRecordError as O, IncompatibleRelation as P, UnknownModelName as Q, MissingAttribute as R, listedNames as S, camelize as T, RecordInvalid as U, ReadonlyAssociation as V, RecordNotDestroyed as W, UnknownAssociation as X, StrictValidationFailed as Y, UnknownAttribute as Z, enumEntries as _, castKey as a, enumValuesOf as b, readValue as c, writeValue as d, zonelessDateTime as f, reservedWords as g, isIdentifier as h, castCondition as i, CheckViolation as j, AssociationNotLoaded as k, uncastable as l, isSameCell as m, digitsProblem as n, castValue as o, hexOf as p, RecordNotUnique as q, orderDecimal as r, isInvalidDate as s, epochStorages as t, writeUntypedValue as u, enumProblem as v, singularize as w, isEnumValues as x, enumValidations as y, NoDatabase as z };
@@ -1,5 +1,5 @@
1
- import { C as pluralize, E as underscore, i as digitsProblem } from "./identifiers-Dh5DFACX.mjs";
2
- import { f as byName, o as exportName } from "./storage-override-0ZgeP2sc.mjs";
1
+ import { C as pluralize, E as underscore, n as digitsProblem } from "./epoch-storage-C7186hd1.mjs";
2
+ import { f as byName, o as exportName } from "./storage-override-BFC-GSR0.mjs";
3
3
  // cli/generate/migration-plan.ts
4
4
  /** What to do, read from a migration's name: `create_products`, `add_sku_to_products`, …; else empty. */
5
5
  function migrationPlan(name) {
@@ -1,4 +1,4 @@
1
- import { O as AnyDatabase } from "./validations-BSZ5gVeI.mjs";
1
+ import { O as AnyDatabase } from "./validations-DFLjJ203.mjs";
2
2
  /**
3
3
  * Bytes as hex text, two digits each, for SQL that reads bytes from JSON (`unhex`, `\\x…`). The
4
4
  * digits' character codes are written into one array and decoded once: mapping each byte to a
@@ -1,4 +1,4 @@
1
- import { z as NoDatabase } from "./identifiers-Dh5DFACX.mjs";
1
+ import { z as NoDatabase } from "./epoch-storage-C7186hd1.mjs";
2
2
  // src/request-database.ts
3
3
  /**
4
4
  * The request's database for a query on `binding` outside a Worker, or a `NoDatabase` saying what