@forestfuture/active-record 0.7.0 → 0.8.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.
Files changed (33) hide show
  1. package/config-schema.json +6 -2
  2. package/dist/adapter.d.mts +3 -3
  3. package/dist/adapter.mjs +5 -4
  4. package/dist/batch-Ms5p9lKq.mjs +9777 -0
  5. package/dist/cli.d.mts +55 -33
  6. package/dist/cli.mjs +4 -4
  7. package/dist/command.mjs +530 -271
  8. package/dist/d1.d.mts +2 -10
  9. package/dist/d1.mjs +0 -0
  10. package/dist/{for-adapters-t3-LukJQ.d.mts → for-adapters-BT2GDjIA.d.mts} +8 -6
  11. package/dist/{for-adapters-Ch6CoHD4.mjs → for-adapters-BbIMUNcz.mjs} +46 -10
  12. package/dist/{for-adapters-D_Iu0gS_.mjs → for-adapters-C-MQxaIx.mjs} +3 -5
  13. package/dist/{generated-model-Cnt0Ot9q.mjs → generated-model-DJA8vmNE.mjs} +705 -508
  14. package/dist/identifiers-Dh5DFACX.mjs +989 -0
  15. package/dist/index-D5getfHx.d.mts +242 -0
  16. package/dist/index.d.mts +4 -3
  17. package/dist/index.mjs +5 -4
  18. package/dist/metadata-CzntpYzC.d.mts +182 -0
  19. package/dist/{plugin-Cyoej7qV.mjs → plugin-CZPDqguF.mjs} +211 -112
  20. package/dist/{plugin-XOHYndhP.mjs → plugin-Cf-5Z0_h.mjs} +148 -52
  21. package/dist/postgresql.d.mts +1 -9
  22. package/dist/postgresql.mjs +42 -26
  23. package/dist/src-BAVZKQ7J.mjs +46 -0
  24. package/dist/{storage-override-CpbkdIqE.mjs → storage-override-0ZgeP2sc.mjs} +61 -28
  25. package/dist/validations-BSZ5gVeI.d.mts +2024 -0
  26. package/llms-full.txt +2326 -229
  27. package/package.json +1 -1
  28. package/skills/active-record/SKILL.md +24 -15
  29. package/dist/adapter-AGKp6wfO.d.mts +0 -1326
  30. package/dist/batch-BS_WseLf.mjs +0 -4255
  31. package/dist/epoch-storage-o2aoOH7H.mjs +0 -112
  32. package/dist/index-CyCJuM96.d.mts +0 -149
  33. package/dist/src-la_KkjCS.mjs +0 -1
@@ -1,112 +0,0 @@
1
- //#region src/naming.ts
2
- /**
3
- * Converts a camelCase attribute name to its snake_case column name, treating
4
- * a run of capitals as one word (Rails' `underscore`): `htmlURL` → `html_url`,
5
- * `userID` → `user_id`, `sha256Hash` → `sha256_hash`.
6
- */
7
- function underscore(name) {
8
- return name.replace(/(?<=[a-z\d])(?=[A-Z])|(?<=[A-Z\d])(?=[A-Z][a-z])/g, "_").toLowerCase();
9
- }
10
- /** A snake_case name as a camelCase attribute: `api_key` → `apiKey`. */
11
- function camelize(name) {
12
- return name.replace(/_([a-z\d])/g, (_, letter) => letter.toUpperCase());
13
- }
14
- //#endregion
15
- //#region src/inflections.ts
16
- /** Words whose plural no rule makes: singular, then plural. */
17
- const IRREGULARS = [
18
- ["person", "people"],
19
- ["man", "men"],
20
- ["child", "children"],
21
- ["sex", "sexes"],
22
- ["move", "moves"],
23
- ["zombie", "zombies"]
24
- ];
25
- /** Plural rules in Rails' order of definition. The last one that matches wins, as in Rails. */
26
- const PLURALS = [
27
- [/$/, "s"],
28
- [/s$/i, "s"],
29
- [/^(ax|test)is$/i, "$1es"],
30
- [/(octop|vir)us$/i, "$1i"],
31
- [/(octop|vir)i$/i, "$1i"],
32
- [/(alias|status)$/i, "$1es"],
33
- [/(bu)s$/i, "$1ses"],
34
- [/(buffal|tomat)o$/i, "$1oes"],
35
- [/([ti])um$/i, "$1a"],
36
- [/([ti])a$/i, "$1a"],
37
- [/sis$/i, "ses"],
38
- [/(?:([^f])fe|([lr])f)$/i, "$1$2ves"],
39
- [/(hive)$/i, "$1s"],
40
- [/([^aeiouy]|qu)y$/i, "$1ies"],
41
- [/(x|ch|ss|sh)$/i, "$1es"],
42
- [/(matr|vert|ind)(?:ix|ex)$/i, "$1ices"],
43
- [/^(m|l)ouse$/i, "$1ice"],
44
- [/^(m|l)ice$/i, "$1ice"],
45
- [/^(ox)$/i, "$1en"],
46
- [/^(oxen)$/i, "$1"],
47
- [/(quiz)$/i, "$1zes"],
48
- ...IRREGULARS.flatMap(([singular, plural]) => irregular(singular, plural, plural))
49
- ];
50
- /** Singular rules, likewise in Rails' order. */
51
- const SINGULARS = [
52
- [/s$/i, ""],
53
- [/(ss)$/i, "$1"],
54
- [/(n)ews$/i, "$1ews"],
55
- [/([ti])a$/i, "$1um"],
56
- [/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i, "$1sis"],
57
- [/(^analy)(sis|ses)$/i, "$1sis"],
58
- [/([^f])ves$/i, "$1fe"],
59
- [/(hive)s$/i, "$1"],
60
- [/(tive)s$/i, "$1"],
61
- [/([lr])ves$/i, "$1f"],
62
- [/([^aeiouy]|qu)ies$/i, "$1y"],
63
- [/(s)eries$/i, "$1eries"],
64
- [/(m)ovies$/i, "$1ovie"],
65
- [/(x|ch|ss|sh)es$/i, "$1"],
66
- [/^(m|l)ice$/i, "$1ouse"],
67
- [/(bus)(es)?$/i, "$1"],
68
- [/(o)es$/i, "$1"],
69
- [/(shoe)s$/i, "$1"],
70
- [/(cris|test)(is|es)$/i, "$1is"],
71
- [/^(a)x[ie]s$/i, "$1xis"],
72
- [/(octop|vir)(us|i)$/i, "$1us"],
73
- [/(alias|status)(es)?$/i, "$1"],
74
- [/^(ox)en/i, "$1"],
75
- [/(vert|ind)ices$/i, "$1ex"],
76
- [/(matr)ices$/i, "$1ix"],
77
- [/(quiz)zes$/i, "$1"],
78
- [/(database)s$/i, "$1"],
79
- ...IRREGULARS.flatMap(([singular, plural]) => irregular(singular, plural, singular))
80
- ];
81
- /** Words with no plural, matched as the last word (Rails' `\b<word>\z`). */
82
- const UNCOUNTABLE = /\b(?:equipment|information|rice|money|species|series|fish|sheep|jeans|police)$/i;
83
- /**
84
- * Rails' `irregular`: rules turning either form into `into` (the plural for plural rules, the
85
- * singular for singular ones), keeping the first letter's case.
86
- */
87
- function irregular(singular, plural, into) {
88
- return [[new RegExp(`(${singular[0]})${singular.slice(1)}$`, "i"), `$1${into.slice(1)}`], [new RegExp(`(${plural[0]})${plural.slice(1)}$`, "i"), `$1${into.slice(1)}`]];
89
- }
90
- /** Applies the last rule that matches, as Rails does; uncountable words stay as they are. */
91
- function inflect(word, rules) {
92
- if (word === "" || UNCOUNTABLE.test(word)) return word;
93
- for (let index = rules.length - 1; index >= 0; index--) {
94
- const [pattern, replacement] = rules[index];
95
- if (pattern.test(word)) return word.replace(pattern, replacement);
96
- }
97
- return word;
98
- }
99
- /** Rails' `pluralize`: `category` → `categories`, `person` → `people`, `sheep` → `sheep`. */
100
- function pluralize(word) {
101
- return inflect(word, PLURALS);
102
- }
103
- /** Rails' `singularize`: `categories` → `category`, `people` → `person`, `line_items` → `line_item`. */
104
- function singularize(word) {
105
- return inflect(word, SINGULARS);
106
- }
107
- //#endregion
108
- //#region src/epoch-storage.ts
109
- /** A datetime held in an `INTEGER` column as seconds or milliseconds since 1970. */
110
- const epochStorages = ["unixSeconds", "unixMilliseconds"];
111
- //#endregion
112
- export { underscore as a, camelize as i, pluralize as n, singularize as r, epochStorages as t };
@@ -1,149 +0,0 @@
1
- import { C as HasOne, S as HasManyDependent, b as BelongsTo, d as Model, f as ModelClass, i as AnyDatabase, w as HasOneDependent, x as HasMany, y as AssociationOptions } from "./adapter-AGKp6wfO.mjs";
2
- //#region src/association-fields.d.ts
3
- /** This record points at one `target` record through `foreignKey` (its own attribute). */
4
- declare function belongsTo<C extends ModelClass>(target: C, options?: Omit<AssociationOptions<C>, "dependent">): BelongsTo<C>;
5
- /** Many `target` records point at this record through `foreignKey` (theirs). */
6
- declare function hasMany<C extends ModelClass>(target: C, options?: AssociationOptions<C> & {
7
- dependent?: HasManyDependent;
8
- }): HasMany<C>;
9
- /** One `target` record points at this record through `foreignKey` (its own). */
10
- declare function hasOne<C extends ModelClass>(target: C, options?: AssociationOptions<C> & {
11
- dependent?: HasOneDependent;
12
- }): HasOne<C>;
13
- //#endregion
14
- //#region src/errors.d.ts
15
- /** Base class for every error the library throws on purpose. */
16
- declare class ActiveRecordError extends Error {
17
- name: string;
18
- }
19
- /** A Model's declaration is invalid, e.g. an association's foreign key isn't an attribute. */
20
- declare class InvalidModel extends ActiveRecordError {
21
- name: string;
22
- }
23
- /** A key that isn't a declared attribute of the Model. */
24
- declare class UnknownAttribute extends ActiveRecordError {
25
- name: string;
26
- }
27
- /** A record constructed directly (`new User()`) was used for something that needs D1. */
28
- declare class NoDatabase extends ActiveRecordError {
29
- name: string;
30
- }
31
- /** No record matched a lookup that requires one (`find`, `findByOrThrow`). */
32
- declare class RecordNotFound extends ActiveRecordError {
33
- name: string;
34
- }
35
- /** Reading an attribute that wasn't loaded, e.g. one left out of `select(...)`. */
36
- declare class MissingAttribute extends ActiveRecordError {
37
- name: string;
38
- }
39
- /** Destroying a record whose `dependent: "restrictWithException"` association still has records. */
40
- declare class DeleteRestriction extends ActiveRecordError {
41
- name: string;
42
- }
43
- /** `last()` can't reverse an order given as an `sql` fragment (Rails' IrreversibleOrderError). */
44
- declare class IrreversibleOrder extends ActiveRecordError {
45
- name: string;
46
- }
47
- /**
48
- * Things that can't be combined: relations in `or`/`merge` (e.g. of different Models),
49
- * `includes` or a write statement with `distinct()`, or statements of two Databases in a batch.
50
- */
51
- declare class IncompatibleRelation extends ActiveRecordError {
52
- name: string;
53
- }
54
- /** Using a destroyed record as a live one: `save`, `update`, `destroy` or `reload` after `destroy()`. */
55
- declare class RecordDestroyed extends ActiveRecordError {
56
- name: string;
57
- }
58
- /**
59
- * D1 rejected a write because of a database constraint. `table`, `columns` and `attributes`
60
- * are filled in when D1's message names them. `table` is null only for a batch writing to
61
- * several tables, when D1 doesn't say which one failed. The original D1 error is the `cause`.
62
- */
63
- declare class ConstraintViolation extends ActiveRecordError {
64
- name: string;
65
- readonly table: string | null;
66
- readonly columns: readonly string[];
67
- readonly attributes: readonly string[];
68
- constructor(message: string, details: {
69
- table: string | null;
70
- columns: readonly string[];
71
- attributes: readonly string[];
72
- cause: unknown;
73
- });
74
- }
75
- /** A UNIQUE constraint failed, e.g. another request won the race after validation passed. */
76
- declare class RecordNotUnique extends ConstraintViolation {
77
- name: string;
78
- }
79
- /** A FOREIGN KEY constraint failed. SQLite's message doesn't name the column. */
80
- declare class InvalidForeignKey extends ConstraintViolation {
81
- name: string;
82
- }
83
- /** A NOT NULL constraint failed. */
84
- declare class NotNullViolation extends ConstraintViolation {
85
- name: string;
86
- }
87
- /** A CHECK constraint failed. */
88
- declare class CheckViolation extends ConstraintViolation {
89
- name: string;
90
- }
91
- /** A `…OrThrow` save was refused because the record is invalid; `record.errors` says why. */
92
- declare class RecordInvalid extends ActiveRecordError {
93
- name: string;
94
- readonly record: Model;
95
- constructor(record: Model);
96
- }
97
- /**
98
- * Thrown by a callback to refuse a save or destroy: `throw abort("Account is suspended")`.
99
- * Only this exact class halts a lifecycle; returning `false` never does.
100
- */
101
- declare class CallbackAbort extends ActiveRecordError {
102
- name: string;
103
- readonly reason: string;
104
- constructor(reason: string);
105
- }
106
- /** Makes the sentinel a pre-write callback throws to refuse: `throw abort("reason")`. */
107
- declare function abort(reason?: string): CallbackAbort;
108
- /** A `…OrThrow` save was refused by a callback's `abort(reason)`. */
109
- declare class RecordNotSaved extends ActiveRecordError {
110
- name: string;
111
- }
112
- /**
113
- * `abort()` was thrown from an after-write callback (`afterSave`, `afterCreate`, `afterUpdate`,
114
- * `afterDestroy`). That's a mistake: the save or destroy already succeeded and nothing rolls back.
115
- */
116
- declare class AbortAfterPersistence extends ActiveRecordError {
117
- name: string;
118
- readonly callback: string;
119
- readonly reason: string;
120
- constructor(callback: string, lifecycle: "save" | "destroy", abortion: CallbackAbort);
121
- }
122
- /** A `destroyOrThrow()` was refused by a `beforeDestroy` callback's `abort(reason)`. */
123
- declare class RecordNotDestroyed extends ActiveRecordError {
124
- name: string;
125
- }
126
- /** A name passed to `includes()` or `loaded()` that isn't one of the Model's associations. */
127
- declare class UnknownAssociation extends ActiveRecordError {
128
- name: string;
129
- }
130
- /** `record.loaded(name)` for an association that wasn't preloaded or read yet. */
131
- declare class AssociationNotLoaded extends ActiveRecordError {
132
- name: string;
133
- }
134
- //#endregion
135
- //#region src/current-database.d.ts
136
- /**
137
- * Runs `fn` with `databases` as the request's own: queries started from a Model inside it (and
138
- * everything it awaits) use the one on that Model's binding, with its Session and `onQuery`.
139
- * Usually called once per request, in middleware. Nested calls add to the outer ones.
140
- *
141
- * Each call is a scope of its own, even with a Database another request shares. An adapter may
142
- * hold a connection for the scope (the PostgreSQL adapter does, from a connection string). A nested call with
143
- * the same Database shares the outer call's scope while that call is running. When `fn` settles,
144
- * the scope ends, and the adapter lets its connection go once the queries still running on it
145
- * finish. Work that outlives the scope, such as a `waitUntil` save, gets a connection of its own.
146
- */
147
- declare function withDatabase<R>(databases: AnyDatabase | readonly AnyDatabase[], fn: () => R | Promise<R>): Promise<R>;
148
- //#endregion
149
- export { UnknownAttribute as C, hasOne as D, hasMany as E, UnknownAssociation as S, belongsTo as T, RecordInvalid as _, CallbackAbort as a, RecordNotSaved as b, DeleteRestriction as c, InvalidModel as d, IrreversibleOrder as f, RecordDestroyed as g, NotNullViolation as h, AssociationNotLoaded as i, IncompatibleRelation as l, NoDatabase as m, AbortAfterPersistence as n, CheckViolation as o, MissingAttribute as p, ActiveRecordError as r, ConstraintViolation as s, withDatabase as t, InvalidForeignKey as u, RecordNotDestroyed as v, abort as w, RecordNotUnique as x, RecordNotFound as y };
@@ -1 +0,0 @@
1
- export {};