@forestfuture/active-record 0.0.0 → 0.7.0

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.
@@ -0,0 +1,149 @@
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 };
@@ -0,0 +1,3 @@
1
+ import { $ as ErrorMessages, A as Page, B as Comparison, C as HasOne, D as ScopeMethods, E as Scope, F as Conditions, G as lte, H as gt, I as InsertOptions, J as TableSchemas, K as DatabaseSchema, L as OrderSpec, M as ReturnedRow, N as Statement, O as Scoped, P as WriteResult, Q as ErrorMessage, R as Returning, S as HasManyDependent, T as Relation, U as gte, V as between, W as lt, X as ValidationError, Y as Errors, Z as AttributeErrorMessages, _ as UniquenessOptions, _t as ColumnReference, a as RelationsFor, at as AttributeSpecs, b as BelongsTo, bt as column, c as BatchResults, d as Model, et as RestrictMessages, g as NumericalityOptions, h as LengthOptions, it as AttributeSpec, j as PageOptions, k as CountlessPage, l as batch, lt as QueryEvent, m as TableAttributes, mt as QuerySql, ot as AttributeType, p as ScopeStatic, q as TableSchema, rt as AttributeConversions, s as BatchEntry, st as EpochStorage, tt as FilterAttribute, u as RecordStatement, ut as QueryListener, v as ValidationOptions, vt as ColumnValue, w as HasOneDependent, x as HasMany, xt as sql, y as AssociationOptions, yt as SafeSql, z as UpsertOptions } from "./adapter-AGKp6wfO.mjs";
2
+ import { C as UnknownAttribute, D as hasOne, E as hasMany, S as UnknownAssociation, T as belongsTo, _ as RecordInvalid, a as CallbackAbort, b as RecordNotSaved, c as DeleteRestriction, d as InvalidModel, f as IrreversibleOrder, g as RecordDestroyed, h as NotNullViolation, i as AssociationNotLoaded, l as IncompatibleRelation, m as NoDatabase, n as AbortAfterPersistence, o as CheckViolation, p as MissingAttribute, r as ActiveRecordError, s as ConstraintViolation, t as withDatabase, u as InvalidForeignKey, v as RecordNotDestroyed, w as abort, x as RecordNotUnique, y as RecordNotFound } from "./index-CyCJuM96.mjs";
3
+ export { AbortAfterPersistence, ActiveRecordError, AssociationNotLoaded, type AssociationOptions, type AttributeConversions, type AttributeErrorMessages, type AttributeSpec, type AttributeSpecs, type AttributeType, type BatchEntry, type BatchResults, type BelongsTo, CallbackAbort, CheckViolation, type ColumnReference, type ColumnValue, type Comparison, type Conditions, ConstraintViolation, type CountlessPage, type DatabaseSchema, DeleteRestriction, type EpochStorage, type ErrorMessage, type ErrorMessages, Errors, type FilterAttribute, type HasMany, type HasManyDependent, type HasOne, type HasOneDependent, IncompatibleRelation, type InsertOptions, InvalidForeignKey, InvalidModel, IrreversibleOrder, type LengthOptions, MissingAttribute, Model, NoDatabase, NotNullViolation, type NumericalityOptions, type OrderSpec, type Page, type PageOptions, type QueryEvent, type QueryListener, type QuerySql, RecordDestroyed, RecordInvalid, RecordNotDestroyed, RecordNotFound, RecordNotSaved, RecordNotUnique, type RecordStatement, Relation, type RelationsFor, type RestrictMessages, type ReturnedRow, type Returning, type SafeSql, type Scope, type ScopeMethods, type ScopeStatic, type Scoped, type Statement, type TableAttributes, type TableSchema, type TableSchemas, type UniquenessOptions, UnknownAssociation, UnknownAttribute, type UpsertOptions, type ValidationError, type ValidationOptions, type WriteResult, abort, batch, belongsTo, between, column, gt, gte, hasMany, hasOne, lt, lte, sql, withDatabase };
package/dist/index.mjs ADDED
@@ -0,0 +1,4 @@
1
+ import { $ as CallbackAbort, Q as AssociationNotLoaded, X as AbortAfterPersistence, Z as ActiveRecordError, _t as UnknownAttribute, at as InvalidModel, ct as NoDatabase, d as Errors, dt as RecordInvalid, et as CheckViolation, ft as RecordNotDestroyed, gt as UnknownAssociation, ht as RecordNotUnique, it as InvalidForeignKey, lt as NotNullViolation, mt as RecordNotSaved, nt as DeleteRestriction, ot as IrreversibleOrder, pt as RecordNotFound, rt as IncompatibleRelation, st as MissingAttribute, tt as ConstraintViolation, ut as RecordDestroyed, vt as abort } from "./generated-model-Cnt0Ot9q.mjs";
2
+ import { _ as hasMany, d as between, f as gt, g as belongsTo, h as lte, l as column, m as lt, n as Model, o as Relation, p as gte, r as withDatabase, t as batch, u as sql, v as hasOne } from "./batch-BS_WseLf.mjs";
3
+ import "./src-la_KkjCS.mjs";
4
+ export { AbortAfterPersistence, ActiveRecordError, AssociationNotLoaded, CallbackAbort, CheckViolation, ConstraintViolation, DeleteRestriction, Errors, IncompatibleRelation, InvalidForeignKey, InvalidModel, IrreversibleOrder, MissingAttribute, Model, NoDatabase, NotNullViolation, RecordDestroyed, RecordInvalid, RecordNotDestroyed, RecordNotFound, RecordNotSaved, RecordNotUnique, Relation, UnknownAssociation, UnknownAttribute, abort, batch, belongsTo, between, column, gt, gte, hasMany, hasOne, lt, lte, sql, withDatabase };