@forestfuture/active-record 0.8.0 → 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/adapter.d.mts +2 -2
- package/dist/adapter.mjs +4 -4
- package/dist/{batch-ReqVoCfa.mjs → batch-D3nP3g83.mjs} +1533 -726
- package/dist/cli.mjs +3 -3
- package/dist/command.mjs +5 -5
- package/dist/d1.d.mts +2 -2
- package/dist/d1.mjs +4 -4
- package/dist/{epoch-storage-CDlQZcBB.mjs → epoch-storage-C7186hd1.mjs} +2 -1
- package/dist/{for-adapters-DhNV1mWf.mjs → for-adapters-CgEQfuyD.mjs} +2 -2
- package/dist/{for-adapters-B0xMP6Dq.d.mts → for-adapters-DAn1wSYz.d.mts} +1 -1
- package/dist/{for-adapters-CfXMGeOu.mjs → for-adapters-l4rNitkK.mjs} +1 -1
- package/dist/{generated-model-g5oWsDKE.mjs → generated-model-FB7oT7V1.mjs} +73 -60
- package/dist/{index-BATasvJa.d.mts → index-BfX3Dgy_.d.mts} +27 -5
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +4 -4
- package/dist/{plugin-wOSILvSB.mjs → plugin-BY2QaRpq.mjs} +3 -3
- package/dist/{plugin-x5-d3TSN.mjs → plugin-IHD0I6Rg.mjs} +3 -3
- package/dist/postgresql.d.mts +1 -1
- package/dist/postgresql.mjs +4 -4
- package/dist/{src-D56_3odT.mjs → src-DnuvSHF6.mjs} +2 -2
- package/dist/{storage-override-n4w1cS_M.mjs → storage-override-BFC-GSR0.mjs} +1 -1
- package/dist/{validations-DHDVV8hB.d.mts → validations-DFLjJ203.d.mts} +266 -187
- package/llms-full.txt +1364 -434
- package/package.json +1 -1
- package/skills/active-record/SKILL.md +3 -2
package/dist/cli.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as pluralize, E as underscore } from "./epoch-storage-
|
|
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-
|
|
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-
|
|
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-
|
|
3
|
-
import {
|
|
4
|
-
import { C as pluralize, E as underscore, T as camelize, h as isIdentifier, n as digitsProblem, w as singularize } from "./epoch-storage-
|
|
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-
|
|
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-
|
|
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-
|
|
2
|
-
import { i as ActiveRecordError } from "./index-
|
|
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 databaseExecutor, i as AnyDatabase, l as DatabaseExecutor, r as withDatabase } from "./batch-
|
|
2
|
-
import { n as onlyRequested, t as workersEnv } from "./for-adapters-
|
|
3
|
-
import { O as ActiveRecordError, p as hexOf, z as NoDatabase } from "./epoch-storage-
|
|
4
|
-
import {
|
|
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,7 +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`)
|
|
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.
|
|
121
122
|
*/
|
|
122
123
|
var AbortAfterPersistence = class extends ActiveRecordError {
|
|
123
124
|
name = "AbortAfterPersistence";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as pluralize, E as underscore, n as digitsProblem } from "./epoch-storage-
|
|
2
|
-
import { f as byName, o as exportName } from "./storage-override-
|
|
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-
|
|
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 { C as pluralize, E as underscore, H as RecordDestroyed, I as InvalidModel, R as MissingAttribute, S as listedNames, Z as UnknownAttribute, _ as enumEntries, a as castKey, c as readValue, d as writeValue, g as reservedWords, h as isIdentifier, i as castCondition, l as uncastable, m as isSameCell, n as digitsProblem, o as castValue, s as isInvalidDate, t as epochStorages, v as enumProblem, x as isEnumValues, z as NoDatabase } from "./epoch-storage-
|
|
1
|
+
import { C as pluralize, E as underscore, H as RecordDestroyed, I as InvalidModel, R as MissingAttribute, S as listedNames, Z as UnknownAttribute, _ as enumEntries, a as castKey, c as readValue, d as writeValue, g as reservedWords, h as isIdentifier, i as castCondition, l as uncastable, m as isSameCell, n as digitsProblem, o as castValue, s as isInvalidDate, t as epochStorages, v as enumProblem, x as isEnumValues, z as NoDatabase } from "./epoch-storage-C7186hd1.mjs";
|
|
2
2
|
// src/ancestors.ts
|
|
3
3
|
/** A class and every class (and object) it extends, nearest first. */
|
|
4
4
|
function ancestors(model) {
|
|
@@ -180,6 +180,64 @@ function tableOwnerModelName(model) {
|
|
|
180
180
|
if (base !== void 0) return modelNameBelow(base, model);
|
|
181
181
|
return modelNameOf(boundTableOf(model)?.owner ?? model);
|
|
182
182
|
}
|
|
183
|
+
// src/declarations.ts
|
|
184
|
+
/**
|
|
185
|
+
* Per-Model declarations (validations, callbacks, …), keyed by Model class. A subclass starts
|
|
186
|
+
* from a copy of its parent's list, so declaring on it never changes the parent.
|
|
187
|
+
*
|
|
188
|
+
* Module-level, but not request state (ADR-0003): declarations are made once, when a Model
|
|
189
|
+
* class is defined, and only read afterwards.
|
|
190
|
+
*/
|
|
191
|
+
const registry = /* @__PURE__ */ new WeakMap();
|
|
192
|
+
/** The declarations each class made itself, without its parent's, for reading class by class. */
|
|
193
|
+
const ownRegistry = /* @__PURE__ */ new WeakMap();
|
|
194
|
+
/** Models that have been used; their declarations can no longer change. */
|
|
195
|
+
const sealed = /* @__PURE__ */ new WeakSet();
|
|
196
|
+
/**
|
|
197
|
+
* Called on a Model's first use. From then on, declaring on it throws: declarations belong in
|
|
198
|
+
* the class's `static {}` block, never in request code, where they'd leak into every request.
|
|
199
|
+
*/
|
|
200
|
+
function seal(model) {
|
|
201
|
+
sealed.add(model);
|
|
202
|
+
}
|
|
203
|
+
/** Whether a Model has been used, so its declarations, and its ancestors', can no longer change. */
|
|
204
|
+
function isSealed(model) {
|
|
205
|
+
return sealed.has(model);
|
|
206
|
+
}
|
|
207
|
+
/** The declarations of `kind` for `model`: its own, or else its nearest ancestor's. */
|
|
208
|
+
function declared(model, kind) {
|
|
209
|
+
for (const current of ancestors(model)) {
|
|
210
|
+
const list = registry.get(current)?.get(kind);
|
|
211
|
+
if (list !== void 0) return list;
|
|
212
|
+
}
|
|
213
|
+
return [];
|
|
214
|
+
}
|
|
215
|
+
/** The declarations of `kind` that `model` and each class it extends made themselves, nearest first. */
|
|
216
|
+
function declaredByClass(model, kind) {
|
|
217
|
+
return ancestors(model).flatMap((from) => {
|
|
218
|
+
const values = ownRegistry.get(from)?.get(kind);
|
|
219
|
+
return values === void 0 ? [] : [{
|
|
220
|
+
from,
|
|
221
|
+
values
|
|
222
|
+
}];
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
/** Adds a declaration of `kind` to `model`, copying its inherited list first. */
|
|
226
|
+
function declare(model, kind, entry) {
|
|
227
|
+
if (sealed.has(model)) {
|
|
228
|
+
const { name } = model;
|
|
229
|
+
throw new InvalidModel(`${name} has already been used; declare validations, callbacks and messages in its static {} block`);
|
|
230
|
+
}
|
|
231
|
+
listsOf(registry, model).set(kind, [...declared(model, kind), entry]);
|
|
232
|
+
const own = listsOf(ownRegistry, model);
|
|
233
|
+
own.set(kind, [...own.get(kind) ?? [], entry]);
|
|
234
|
+
}
|
|
235
|
+
/** `model`'s lists in a registry, by kind, made empty the first time. */
|
|
236
|
+
function listsOf(lists, model) {
|
|
237
|
+
const found = lists.get(model) ?? /* @__PURE__ */ new Map();
|
|
238
|
+
lists.set(model, found);
|
|
239
|
+
return found;
|
|
240
|
+
}
|
|
183
241
|
// src/enum-methods.ts
|
|
184
242
|
/** Each name of every enum attribute, with the methods it gives. */
|
|
185
243
|
function enumNames(definitions) {
|
|
@@ -970,64 +1028,6 @@ function plainText(value) {
|
|
|
970
1028
|
return Object.prototype.toString.call(value);
|
|
971
1029
|
}
|
|
972
1030
|
}
|
|
973
|
-
// src/declarations.ts
|
|
974
|
-
/**
|
|
975
|
-
* Per-Model declarations (validations, callbacks, …), keyed by Model class. A subclass starts
|
|
976
|
-
* from a copy of its parent's list, so declaring on it never changes the parent.
|
|
977
|
-
*
|
|
978
|
-
* Module-level, but not request state (ADR-0003): declarations are made once, when a Model
|
|
979
|
-
* class is defined, and only read afterwards.
|
|
980
|
-
*/
|
|
981
|
-
const registry = /* @__PURE__ */ new WeakMap();
|
|
982
|
-
/** The declarations each class made itself, without its parent's, for reading class by class. */
|
|
983
|
-
const ownRegistry = /* @__PURE__ */ new WeakMap();
|
|
984
|
-
/** Models that have been used; their declarations can no longer change. */
|
|
985
|
-
const sealed = /* @__PURE__ */ new WeakSet();
|
|
986
|
-
/**
|
|
987
|
-
* Called on a Model's first use. From then on, declaring on it throws: declarations belong in
|
|
988
|
-
* the class's `static {}` block, never in request code, where they'd leak into every request.
|
|
989
|
-
*/
|
|
990
|
-
function seal(model) {
|
|
991
|
-
sealed.add(model);
|
|
992
|
-
}
|
|
993
|
-
/** Whether a Model has been used, so its declarations, and its ancestors', can no longer change. */
|
|
994
|
-
function isSealed(model) {
|
|
995
|
-
return sealed.has(model);
|
|
996
|
-
}
|
|
997
|
-
/** The declarations of `kind` for `model`: its own, or else its nearest ancestor's. */
|
|
998
|
-
function declared(model, kind) {
|
|
999
|
-
for (const current of ancestors(model)) {
|
|
1000
|
-
const list = registry.get(current)?.get(kind);
|
|
1001
|
-
if (list !== void 0) return list;
|
|
1002
|
-
}
|
|
1003
|
-
return [];
|
|
1004
|
-
}
|
|
1005
|
-
/** The declarations of `kind` that `model` and each class it extends made themselves, nearest first. */
|
|
1006
|
-
function declaredByClass(model, kind) {
|
|
1007
|
-
return ancestors(model).flatMap((from) => {
|
|
1008
|
-
const values = ownRegistry.get(from)?.get(kind);
|
|
1009
|
-
return values === void 0 ? [] : [{
|
|
1010
|
-
from,
|
|
1011
|
-
values
|
|
1012
|
-
}];
|
|
1013
|
-
});
|
|
1014
|
-
}
|
|
1015
|
-
/** Adds a declaration of `kind` to `model`, copying its inherited list first. */
|
|
1016
|
-
function declare(model, kind, entry) {
|
|
1017
|
-
if (sealed.has(model)) {
|
|
1018
|
-
const { name } = model;
|
|
1019
|
-
throw new InvalidModel(`${name} has already been used; declare validations, callbacks and messages in its static {} block`);
|
|
1020
|
-
}
|
|
1021
|
-
listsOf(registry, model).set(kind, [...declared(model, kind), entry]);
|
|
1022
|
-
const own = listsOf(ownRegistry, model);
|
|
1023
|
-
own.set(kind, [...own.get(kind) ?? [], entry]);
|
|
1024
|
-
}
|
|
1025
|
-
/** `model`'s lists in a registry, by kind, made empty the first time. */
|
|
1026
|
-
function listsOf(lists, model) {
|
|
1027
|
-
const found = lists.get(model) ?? /* @__PURE__ */ new Map();
|
|
1028
|
-
lists.set(model, found);
|
|
1029
|
-
return found;
|
|
1030
|
-
}
|
|
1031
1031
|
// src/error-messages.ts
|
|
1032
1032
|
/** @internal Rails' English messages, used where no class has its own (listed in the guide). */
|
|
1033
1033
|
const builtInMessages = {
|
|
@@ -1511,6 +1511,10 @@ var RecordState = class {
|
|
|
1511
1511
|
const { name, primaryKey } = this.#model;
|
|
1512
1512
|
if (this.#lifecycle === "persisted" && !this.#isInSnapshot(primaryKey)) throw new MissingAttribute(`${name} record has no primary key loaded (it came from select(...).distinct()); it can't ${action}`);
|
|
1513
1513
|
}
|
|
1514
|
+
/** Whether `name` is one of the Model's attributes and loaded: not left out of `select(...)`. */
|
|
1515
|
+
hasAttribute(name) {
|
|
1516
|
+
return this.#model.attributeDefinitions.has(name) && Object.hasOwn(this.#values, name);
|
|
1517
|
+
}
|
|
1514
1518
|
/** An attribute's value; `MissingAttribute` if it wasn't loaded (left out of `select`). */
|
|
1515
1519
|
read(name) {
|
|
1516
1520
|
this.#requireAttribute(name);
|
|
@@ -1712,6 +1716,15 @@ var RecordState = class {
|
|
|
1712
1716
|
this.#snapshot.set(name, this.#storedForm(name));
|
|
1713
1717
|
}
|
|
1714
1718
|
}
|
|
1719
|
+
/**
|
|
1720
|
+
* After a touch (#50): as `commitColumns`, and `savedChanges` holds only the touched
|
|
1721
|
+
* attributes' changes, as Rails' `touch` applies them. The record's other changes stay unsaved.
|
|
1722
|
+
*/
|
|
1723
|
+
commitTouch(names) {
|
|
1724
|
+
const changes = this.changes();
|
|
1725
|
+
this.commitColumns(names);
|
|
1726
|
+
this.#savedChanges = Object.fromEntries(names.filter((name) => Object.hasOwn(changes, name)).map((name) => [name, changes[name]]));
|
|
1727
|
+
}
|
|
1715
1728
|
/** A save with nothing to write: nothing changes but `savedChanges`. */
|
|
1716
1729
|
commitClean() {
|
|
1717
1730
|
this.#savedChanges = {};
|
|
@@ -2042,4 +2055,4 @@ function specsFor(name, table, overrides) {
|
|
|
2042
2055
|
isIgnoringColumns: [...changes.values()].includes(false)
|
|
2043
2056
|
};
|
|
2044
2057
|
}
|
|
2045
|
-
export { modelNameOf as $,
|
|
2058
|
+
export { modelNameOf as $, filteredValues as A, specProblem as B, castInherited as C, Filtered as D, FILTERED as E, attributesForColumn as F, declare as G, defineEnumStatics as H, define as I, seal as J, declared as K, initialValues as L, shownKey as M, shownValue$1 as N, boundValue as O, attributeOf as P, isIgnoringColumns as Q, requireDefined as R, attributeFor as S, withArticle as T, enumNameProblem as U, defineEnumMethods as V, enumScopeNames as W, explainMissingTable as X, defineModelName as Y, inferTableNames as Z, inspectCustom as _, isGenerated as a, tableize as at, attributesNamedInMessages as b, methodsOffFixes as c, state as d, ownValueSetter as et, Errors as f, FilteredMark as g, fullMessageOf as h, isBase as i, tableOwnerModelName as it, isFiltered as j, defaultFilterAttributes as k, RecordState as l, clearErrors as m, defineGeneratedStatics as n, requireModelName as nt, schemaAdapter as o, ancestors as ot, addFailure as p, declaredByClass as q, hasSettledAttributes as r, requireTableName as rt, settleGenerated as s, staticBelow as st, defineAttributeAccessors as t, rejectAbstract as tt, linksOf as u, printed as v, noMatch as w, humanAttributeName as x, styled as y, defineType as z };
|
|
@@ -1,6 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { I as DatetimeAttributeKey, L as NumberAttributeKey, O as AnyDatabase, at as BelongsTo, ct as HasManyDependent, dt as HasOneDependent, f as Model, ft as HasOneThrough, g as DatabaseSchema, ht as ThroughOptions, it as AssociationOptions, lt as HasManyThrough, mt as ThroughDependent, ot as HasMany, p as ModelClass, pt as PolymorphicBelongsTo, ut as HasOne } from "./validations-DFLjJ203.mjs";
|
|
2
2
|
/** One of the attributes of `C`'s records, which a counter cache names. */
|
|
3
3
|
type CounterName<C extends ModelClass> = NumberAttributeKey<InstanceType<C>>;
|
|
4
|
+
/** One of the datetime attributes of `C`'s records, which a belongsTo's or hasOne's `touch` names. */
|
|
5
|
+
type TouchName<C extends ModelClass> = DatetimeAttributeKey<InstanceType<C>>;
|
|
6
|
+
/** What a belongsTo's or hasOne's `touch` sets: `updatedAt`, and the datetime attributes named. */
|
|
7
|
+
type TouchedAttributes<C extends ModelClass> = true | TouchName<C> | readonly TouchName<C>[];
|
|
8
|
+
/** What a hasOne takes to touch its record (#497). */
|
|
9
|
+
interface HasOneTouchOptions<C extends ModelClass> {
|
|
10
|
+
/**
|
|
11
|
+
* Touches the record when this one is updated, destroyed or touched (not created), in the
|
|
12
|
+
* same batch: `true` sets its `updatedAt`, and a datetime attribute's name, or a list, sets
|
|
13
|
+
* those too. The record is loaded first, so its `afterTouch` and commit callbacks run. A
|
|
14
|
+
* record this one's own save writes (built through it, or autosaved), or its `dependent`
|
|
15
|
+
* removes, is left to that write.
|
|
16
|
+
*/
|
|
17
|
+
touch?: TouchedAttributes<C>;
|
|
18
|
+
}
|
|
4
19
|
/** What only a belongsTo takes; `C` is its target, whose attribute a counter cache names. */
|
|
5
20
|
interface BelongsToOptions<C extends ModelClass = ModelClass> {
|
|
6
21
|
/** The record may point at nothing: saving doesn't require its record (#339). */
|
|
@@ -16,6 +31,12 @@ interface BelongsToOptions<C extends ModelClass = ModelClass> {
|
|
|
16
31
|
attribute?: CounterName<C>;
|
|
17
32
|
active?: false;
|
|
18
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* Touches the target when this record is created, updated, destroyed or touched (#353), in the
|
|
36
|
+
* same batch: `true` sets its `updatedAt`, and a datetime attribute's name, or a list, sets
|
|
37
|
+
* those too. The target is loaded first, so its `afterTouch` and commit callbacks run.
|
|
38
|
+
*/
|
|
39
|
+
touch?: TouchedAttributes<C>;
|
|
19
40
|
}
|
|
20
41
|
/**
|
|
21
42
|
* What a polymorphic belongsTo takes (#60): no `scope` (#436), and the attribute holding the
|
|
@@ -66,8 +87,8 @@ declare function hasMany<C extends ModelClass>(target: C, options?: AssociationO
|
|
|
66
87
|
* One `target` record points at this record through `foreignKey` (its own); or, with
|
|
67
88
|
* `through`, this record reaches it through another of its associations (#59).
|
|
68
89
|
*/
|
|
69
|
-
declare function hasOne<C extends ModelClass>(target: C, options: ThroughOptions<C>): HasOneThrough<C>;
|
|
70
|
-
declare function hasOne<C extends ModelClass>(target: C, options?: AssociationOptions<C> & ToPolymorphicOptions & {
|
|
90
|
+
declare function hasOne<C extends ModelClass>(target: C, options: ThroughOptions<C> & HasOneTouchOptions<C>): HasOneThrough<C>;
|
|
91
|
+
declare function hasOne<C extends ModelClass>(target: C, options?: AssociationOptions<C> & ToPolymorphicOptions & HasOneTouchOptions<C> & {
|
|
71
92
|
dependent?: HasOneDependent;
|
|
72
93
|
}): HasOne<C>;
|
|
73
94
|
/** Base class for every error the library throws on purpose. */
|
|
@@ -180,13 +201,14 @@ declare class RecordNotSaved extends ActiveRecordError {
|
|
|
180
201
|
}
|
|
181
202
|
/**
|
|
182
203
|
* `abort()` was thrown from an after-write callback (`afterSave`, `afterCreate`, `afterUpdate`,
|
|
183
|
-
* `afterDestroy`)
|
|
204
|
+
* `afterDestroy`, `afterTouch`), or from an around callback once its `next()` resolved. That's a
|
|
205
|
+
* mistake: the write already succeeded and nothing rolls back.
|
|
184
206
|
*/
|
|
185
207
|
declare class AbortAfterPersistence extends ActiveRecordError {
|
|
186
208
|
name: string;
|
|
187
209
|
readonly callback: string;
|
|
188
210
|
readonly reason: string;
|
|
189
|
-
constructor(callback: string, lifecycle: "save" | "destroy", abortion: CallbackAbort);
|
|
211
|
+
constructor(callback: string, lifecycle: "save" | "destroy" | "touch", abortion: CallbackAbort);
|
|
190
212
|
}
|
|
191
213
|
/**
|
|
192
214
|
* A `destroyOrThrow()` was refused by a `beforeDestroy` callback's `abort(reason)` or a
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { _ as defineType, a as AttributeType, g as CustomType, i as AttributeSpecs, l as EpochStorage, r as AttributeSpec } from "./metadata-CzntpYzC.mjs";
|
|
2
|
-
import { $ as
|
|
3
|
-
import { A as PolymorphicBelongsToOptions, C as RecordNotUnique, D as UnknownAttribute, E as UnknownAssociation, M as hasMany, N as hasOne, O as UnknownModelName, S as RecordNotSaved, T as StrictValidationFailed, _ as ReadonlyAssociation, a as AssociationNotLoaded, b as RecordNotDestroyed, c as ConstraintViolation, d as InvalidForeignKey, f as InvalidModel, g as NotNullViolation, h as NoDatabase, i as ActiveRecordError, j as belongsTo, k as abort, l as DeleteRestriction, m as MissingAttribute, n as withDatabase, o as CallbackAbort, p as IrreversibleOrder, r as AbortAfterPersistence, s as CheckViolation, t as defineSchema, u as IncompatibleRelation, v as RecordDestroyed, w as SoleRecordExceeded, x as RecordNotFound, y as RecordInvalid } from "./index-
|
|
4
|
-
export { AbortAfterPersistence, ActiveRecordError, type AssociatedValidationOptions, AssociationNotLoaded, type AssociationOptions, type AttributeConversions, type AttributeErrorMessages, type AttributeSpec, type AttributeSpecs, type AttributeType, type Batch, type BatchEntry, type BatchResults, type BelongsTo, CallbackAbort, CheckViolation, type ColumnReference, type ColumnValue, type Comparable, type Comparison, type ComparisonBound, type ComparisonOptions, type Conditions, ConstraintViolation, type CountlessPage, type CustomType, type DatabaseSchema, DeleteRestriction, type EpochStorage, type ErrorMessage, type ErrorMessages, Errors, type FilterAttribute, type GroupedRelation, type HasMany, type HasManyCollection, type HasManyDependent, type HasManyThrough, type HasOne, type HasOneDependent, type HasOneThrough, type InOrderOfOptions, IncompatibleRelation, type Init, type InsertOptions, InvalidForeignKey, InvalidModel, IrreversibleOrder, type IterationOptions, type LengthOptions, MissingAttribute, Model, NoDatabase, NotNullViolation, type NumericalityOptions, type OrderSpec, type Page, type PageOptions, type PolymorphicBelongsTo, type PolymorphicBelongsToOptions, type QueryEvent, type QueryListener, type QueryPart, type QuerySql, ReadonlyAssociation, RecordDestroyed, RecordInvalid, RecordNotDestroyed, RecordNotFound, RecordNotSaved, RecordNotUnique, type RecordStatement, Relation, type RelationsFor, type RestrictMessages, type ReturnedRow, type Returning, type SafeSql, type SaveOptions, type Scope, type ScopeMethods, type ScopeStatic, type Scoped, SoleRecordExceeded, type Statement, StrictValidationFailed, type TableAttributes, type TableSchema, type TableSchemas, type ThroughDependent, type ThroughOptions, type UniquenessOptions, UnknownAssociation, UnknownAttribute, UnknownModelName, type UpsertOptions, type ValidationCallbackOptions, type ValidationContext, type ValidationContexts, type ValidationError, type ValidationOptions, type WriteResult, abort, batch, belongsTo, between, column, defineSchema, defineType, gt, gte, hasMany, hasOne, lt, lte, sql, withDatabase };
|
|
2
|
+
import { $ as ReturnedRow, At as QuerySql, B as ValidationContext, Bt as ComparisonBound, C as QueryEvent, Ct as gt, Dt as QueryPart, Et as lte, F as RecordStatement, Ft as ColumnValue, G as Scoped, H as Relation, It as SafeSql, J as Page, K as IterationOptions, Lt as column, M as BatchResults, N as batch, Ot as InOrderOfOptions, P as Batch, Pt as ColumnReference, Q as Init, R as SaveOptions, Rt as sql, St as between, Tt as lt, U as Scope, V as ValidationContexts, Vt as ComparisonOptions, W as ScopeMethods, X as TouchOptions, Y as PageOptions, Z as GroupedRelation, _ as TableSchema, _t as InsertOptions, a as ValidationOptions, at as BelongsTo, bt as UpsertOptions, c as AttributeErrorMessages, ct as HasManyDependent, d as RestrictMessages, dt as HasOneDependent, et as Statement, f as Model, ft as HasOneThrough, g as DatabaseSchema, gt as Conditions, h as TableAttributes, ht as ThroughOptions, i as UniquenessOptions, it as AssociationOptions, j as BatchEntry, k as RelationsFor, l as ErrorMessage, lt as HasManyThrough, m as ScopeStatic, mt as ThroughDependent, n as LengthOptions, o as Errors, ot as HasMany, pt as PolymorphicBelongsTo, q as CountlessPage, r as NumericalityOptions, s as ValidationError, st as HasManyCollection, t as AssociatedValidationOptions, tt as WriteResult, u as ErrorMessages, ut as HasOne, v as TableSchemas, vt as OrderSpec, w as QueryListener, wt as gte, x as AttributeConversions, xt as Comparison, y as FilterAttribute, yt as Returning, z as ValidationCallbackOptions, zt as Comparable } from "./validations-DFLjJ203.mjs";
|
|
3
|
+
import { A as PolymorphicBelongsToOptions, C as RecordNotUnique, D as UnknownAttribute, E as UnknownAssociation, M as hasMany, N as hasOne, O as UnknownModelName, S as RecordNotSaved, T as StrictValidationFailed, _ as ReadonlyAssociation, a as AssociationNotLoaded, b as RecordNotDestroyed, c as ConstraintViolation, d as InvalidForeignKey, f as InvalidModel, g as NotNullViolation, h as NoDatabase, i as ActiveRecordError, j as belongsTo, k as abort, l as DeleteRestriction, m as MissingAttribute, n as withDatabase, o as CallbackAbort, p as IrreversibleOrder, r as AbortAfterPersistence, s as CheckViolation, t as defineSchema, u as IncompatibleRelation, v as RecordDestroyed, w as SoleRecordExceeded, x as RecordNotFound, y as RecordInvalid } from "./index-BfX3Dgy_.mjs";
|
|
4
|
+
export { AbortAfterPersistence, ActiveRecordError, type AssociatedValidationOptions, AssociationNotLoaded, type AssociationOptions, type AttributeConversions, type AttributeErrorMessages, type AttributeSpec, type AttributeSpecs, type AttributeType, type Batch, type BatchEntry, type BatchResults, type BelongsTo, CallbackAbort, CheckViolation, type ColumnReference, type ColumnValue, type Comparable, type Comparison, type ComparisonBound, type ComparisonOptions, type Conditions, ConstraintViolation, type CountlessPage, type CustomType, type DatabaseSchema, DeleteRestriction, type EpochStorage, type ErrorMessage, type ErrorMessages, Errors, type FilterAttribute, type GroupedRelation, type HasMany, type HasManyCollection, type HasManyDependent, type HasManyThrough, type HasOne, type HasOneDependent, type HasOneThrough, type InOrderOfOptions, IncompatibleRelation, type Init, type InsertOptions, InvalidForeignKey, InvalidModel, IrreversibleOrder, type IterationOptions, type LengthOptions, MissingAttribute, Model, NoDatabase, NotNullViolation, type NumericalityOptions, type OrderSpec, type Page, type PageOptions, type PolymorphicBelongsTo, type PolymorphicBelongsToOptions, type QueryEvent, type QueryListener, type QueryPart, type QuerySql, ReadonlyAssociation, RecordDestroyed, RecordInvalid, RecordNotDestroyed, RecordNotFound, RecordNotSaved, RecordNotUnique, type RecordStatement, Relation, type RelationsFor, type RestrictMessages, type ReturnedRow, type Returning, type SafeSql, type SaveOptions, type Scope, type ScopeMethods, type ScopeStatic, type Scoped, SoleRecordExceeded, type Statement, StrictValidationFailed, type TableAttributes, type TableSchema, type TableSchemas, type ThroughDependent, type ThroughOptions, type TouchOptions, type UniquenessOptions, UnknownAssociation, UnknownAttribute, UnknownModelName, type UpsertOptions, type ValidationCallbackOptions, type ValidationContext, type ValidationContexts, type ValidationError, type ValidationOptions, type WriteResult, abort, batch, belongsTo, between, column, defineSchema, defineType, gt, gte, hasMany, hasOne, lt, lte, sql, withDatabase };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $ as abort, A as CallbackAbort, B as NotNullViolation, D as AbortAfterPersistence, F as InvalidForeignKey, G as RecordNotFound, H as RecordDestroyed, I as InvalidModel, J as SoleRecordExceeded, K as RecordNotSaved, L as IrreversibleOrder, M as ConstraintViolation, N as DeleteRestriction, O as ActiveRecordError, P as IncompatibleRelation, Q as UnknownModelName, R as MissingAttribute, U as RecordInvalid, V as ReadonlyAssociation, W as RecordNotDestroyed, X as UnknownAssociation, Y as StrictValidationFailed, Z as UnknownAttribute, j as CheckViolation, k as AssociationNotLoaded, q as RecordNotUnique, z as NoDatabase } from "./epoch-storage-
|
|
2
|
-
import { _ as lte, b as hasOne, c as Relation, d as sql, g as lt, h as gte, m as gt, n as Model, p as between, r as withDatabase, t as batch, u as column, v as belongsTo, y as hasMany } from "./batch-
|
|
3
|
-
import {
|
|
4
|
-
import { t as defineSchema } from "./src-
|
|
1
|
+
import { $ as abort, A as CallbackAbort, B as NotNullViolation, D as AbortAfterPersistence, F as InvalidForeignKey, G as RecordNotFound, H as RecordDestroyed, I as InvalidModel, J as SoleRecordExceeded, K as RecordNotSaved, L as IrreversibleOrder, M as ConstraintViolation, N as DeleteRestriction, O as ActiveRecordError, P as IncompatibleRelation, Q as UnknownModelName, R as MissingAttribute, U as RecordInvalid, V as ReadonlyAssociation, W as RecordNotDestroyed, X as UnknownAssociation, Y as StrictValidationFailed, Z as UnknownAttribute, j as CheckViolation, k as AssociationNotLoaded, q as RecordNotUnique, z as NoDatabase } from "./epoch-storage-C7186hd1.mjs";
|
|
2
|
+
import { _ as lte, b as hasOne, c as Relation, d as sql, g as lt, h as gte, m as gt, n as Model, p as between, r as withDatabase, t as batch, u as column, v as belongsTo, y as hasMany } from "./batch-D3nP3g83.mjs";
|
|
3
|
+
import { f as Errors, z as defineType } from "./generated-model-FB7oT7V1.mjs";
|
|
4
|
+
import { t as defineSchema } from "./src-DnuvSHF6.mjs";
|
|
5
5
|
export { AbortAfterPersistence, ActiveRecordError, AssociationNotLoaded, CallbackAbort, CheckViolation, ConstraintViolation, DeleteRestriction, Errors, IncompatibleRelation, InvalidForeignKey, InvalidModel, IrreversibleOrder, MissingAttribute, Model, NoDatabase, NotNullViolation, ReadonlyAssociation, RecordDestroyed, RecordInvalid, RecordNotDestroyed, RecordNotFound, RecordNotSaved, RecordNotUnique, Relation, SoleRecordExceeded, StrictValidationFailed, UnknownAssociation, UnknownAttribute, UnknownModelName, abort, batch, belongsTo, between, column, defineSchema, defineType, gt, gte, hasMany, hasOne, lt, lte, sql, withDatabase };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { i as attributeName, n as castDefault, s as listed, t as storageOverride, u as parseJsonc } from "./storage-override-
|
|
2
|
-
import { a as migrationSql, i as withDigits, n as namesInList, o as quotedName, r as withGeneratedEnum, s as indexName, t as generatedSchema } from "./for-adapters-
|
|
3
|
-
import { E as underscore } from "./epoch-storage-
|
|
1
|
+
import { i as attributeName, n as castDefault, s as listed, t as storageOverride, u as parseJsonc } from "./storage-override-BFC-GSR0.mjs";
|
|
2
|
+
import { a as migrationSql, 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 { E as underscore } from "./epoch-storage-C7186hd1.mjs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import { existsSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { i as attributeName, n as castDefault, p as byVersion, r as isCastDefaultType, u as parseJsonc } from "./storage-override-
|
|
2
|
-
import { a as migrationSql, i as withDigits, n as namesInList, o as quotedName, r as withGeneratedEnum, t as generatedSchema } from "./for-adapters-
|
|
3
|
-
import { E as underscore } from "./epoch-storage-
|
|
1
|
+
import { i as attributeName, n as castDefault, p as byVersion, r as isCastDefaultType, u as parseJsonc } from "./storage-override-BFC-GSR0.mjs";
|
|
2
|
+
import { a as migrationSql, i as withDigits, n as namesInList, o as quotedName, r as withGeneratedEnum, t as generatedSchema } from "./for-adapters-CgEQfuyD.mjs";
|
|
3
|
+
import { E as underscore } from "./epoch-storage-C7186hd1.mjs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
6
6
|
import { basename, dirname, join } from "node:path";
|
package/dist/postgresql.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as QueryEvent$1, D as SchemaAdapter, O as AnyDatabase, w as QueryListener$1 } from "./validations-
|
|
1
|
+
import { C as QueryEvent$1, D as SchemaAdapter, O as AnyDatabase, w as QueryListener$1 } from "./validations-DFLjJ203.mjs";
|
|
2
2
|
import pg from "pg";
|
|
3
3
|
/** The Postgres database a generated schema's Models query: `adapter: postgresql({ binding: "HYPERDRIVE" })`. */
|
|
4
4
|
export declare function postgresql({ binding }: {
|
package/dist/postgresql.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { a as databaseExecutor, i as AnyDatabase, l as DatabaseExecutor } from "./batch-
|
|
2
|
-
import { n as onlyRequested, t as workersEnv } from "./for-adapters-
|
|
3
|
-
import { z as NoDatabase } from "./epoch-storage-
|
|
4
|
-
import {
|
|
1
|
+
import { a as databaseExecutor, i as AnyDatabase, l as DatabaseExecutor } from "./batch-D3nP3g83.mjs";
|
|
2
|
+
import { n as onlyRequested, t as workersEnv } from "./for-adapters-l4rNitkK.mjs";
|
|
3
|
+
import { z as NoDatabase } from "./epoch-storage-C7186hd1.mjs";
|
|
4
|
+
import { O as boundValue } from "./generated-model-FB7oT7V1.mjs";
|
|
5
5
|
import pg from "pg";
|
|
6
6
|
// src/adapters/postgresql/connect-timeout.ts
|
|
7
7
|
/** The limit when the connection string sets none, in milliseconds. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as Model, o as readyModel, s as isReservedScopeName } from "./batch-
|
|
2
|
-
import { $ as modelNameOf, et as ownValueSetter, ot as ancestors, st as staticBelow } from "./generated-model-
|
|
1
|
+
import { n as Model, o as readyModel, s as isReservedScopeName } from "./batch-D3nP3g83.mjs";
|
|
2
|
+
import { $ as modelNameOf, et as ownValueSetter, ot as ancestors, st as staticBelow } from "./generated-model-FB7oT7V1.mjs";
|
|
3
3
|
// src/define-schema.ts
|
|
4
4
|
const listed = /* @__PURE__ */ new Set();
|
|
5
5
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as underscore, T as camelize, g as reservedWords, l as uncastable, o as castValue, t as epochStorages } from "./epoch-storage-
|
|
1
|
+
import { E as underscore, T as camelize, g as reservedWords, l as uncastable, o as castValue, t as epochStorages } from "./epoch-storage-C7186hd1.mjs";
|
|
2
2
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
3
3
|
import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
4
4
|
// cli/project/paths.ts
|