@forestfuture/active-record 0.8.1 → 0.9.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.
@@ -1,75 +1,4 @@
1
- import { $ as PolymorphicBelongsTo, G as BelongsTo, I as NumberAttributeKey, J as HasManyDependent, K as HasMany, O as AnyDatabase, Q as HasOneThrough, W as AssociationOptions, X as HasOne, Y as HasManyThrough, Z as HasOneDependent, et as ThroughDependent, f as Model, g as DatabaseSchema, p as ModelClass, tt as ThroughOptions } from "./validations-BSZ5gVeI.mjs";
2
- /** One of the attributes of `C`'s records, which a counter cache names. */
3
- type CounterName<C extends ModelClass> = NumberAttributeKey<InstanceType<C>>;
4
- /** What only a belongsTo takes; `C` is its target, whose attribute a counter cache names. */
5
- interface BelongsToOptions<C extends ModelClass = ModelClass> {
6
- /** The record may point at nothing: saving doesn't require its record (#339). */
7
- optional?: boolean;
8
- /**
9
- * Keeps a count of these records on the target (#61), updated in the same batch as each
10
- * write: `true` counts them in the attribute named for them (`Reply` → `repliesCount`), or name
11
- * another of the target's attributes (one every Model a polymorphic belongsTo lists has).
12
- * `{ attribute, active: false }` keeps it on writes, but `size` doesn't read it yet, so it
13
- * can be filled in for the rows already there (Rails 7.2's `active: false`).
14
- */
15
- counterCache?: true | CounterName<C> | {
16
- attribute?: CounterName<C>;
17
- active?: false;
18
- };
19
- }
20
- /**
21
- * What a polymorphic belongsTo takes (#60): no `scope` (#436), and the attribute holding the
22
- * type, inferred as the association's name + `Type` (`commentable` → `commentableType`).
23
- */
24
- type PolymorphicBelongsToOptions<C extends ModelClass = ModelClass> = Omit<AssociationOptions, "dependent" | "scope"> & BelongsToOptions<C> & {
25
- foreignType?: string;
26
- };
27
- /**
28
- * This record points at one record of one of `targets` (#60), by the type and key it holds:
29
- * `commentable = belongsTo([Post, Photo])`.
30
- */
31
- declare function belongsTo<L extends readonly [ModelClass, ...ModelClass[]]>(targets: L, options?: PolymorphicBelongsToOptions<L[number]>): PolymorphicBelongsTo<L[number]>;
32
- /** This record points at one `target` record through `foreignKey` (its own attribute). */
33
- declare function belongsTo<C extends ModelClass>(target: C, options?: Omit<AssociationOptions<C>, "dependent"> & BelongsToOptions<C>): BelongsTo<C>;
34
- /**
35
- * What only a hasMany or hasOne takes: `as`, the name of the target's polymorphic belongsTo
36
- * (#60), so its records point at this one by its type and key.
37
- */
38
- interface ToPolymorphicOptions {
39
- /**
40
- * The target's polymorphic belongsTo this one is the other side of (#60): its records'
41
- * `${as}Type` holds this Model's name and `${as}Id` its key.
42
- */
43
- as?: string;
44
- /** The target's attribute holding the type, inferred from `as` (`commentableType`). */
45
- foreignType?: string;
46
- }
47
- /** What only a hasMany takes. */
48
- interface HasManyOptions {
49
- dependent?: HasManyDependent;
50
- /**
51
- * The owner's attribute holding a counter cache of these records (#61), which `size` reads:
52
- * by default the one named for this association (`replies` → `repliesCount`), as Rails'
53
- * has_many `counter_cache:`. The records' belongsTo keeps it.
54
- */
55
- counterCache?: string;
56
- }
57
- /**
58
- * Many `target` records point at this record through `foreignKey` (theirs); or, with `through`,
59
- * this record reaches them through another of its associations (#59).
60
- */
61
- declare function hasMany<C extends ModelClass>(target: C, options: ThroughOptions<C> & {
62
- dependent?: ThroughDependent;
63
- }): HasManyThrough<C>;
64
- declare function hasMany<C extends ModelClass>(target: C, options?: AssociationOptions<C> & ToPolymorphicOptions & HasManyOptions): HasMany<C>;
65
- /**
66
- * One `target` record points at this record through `foreignKey` (its own); or, with
67
- * `through`, this record reaches it through another of its associations (#59).
68
- */
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 & {
71
- dependent?: HasOneDependent;
72
- }): HasOne<C>;
1
+ import { I as DatetimeAttributeKey, L as NumberAttributeKey, O as AnyDatabase, _t as HasOneThrough, bt as ThroughOptions, dt as HasMany, f as Model, g as DatabaseSchema, gt as HasOneDependent, ht as HasOne, lt as AssociationOptions, mt as HasManyThrough, p as ModelClass, pt as HasManyDependent, ut as BelongsTo, vt as PolymorphicBelongsTo, yt as ThroughDependent } from "./validations-CKPJoSj4.mjs";
73
2
  /** Base class for every error the library throws on purpose. */
74
3
  declare class ActiveRecordError extends Error {
75
4
  name: string;
@@ -90,6 +19,13 @@ declare class NoDatabase extends ActiveRecordError {
90
19
  declare class RecordNotFound extends ActiveRecordError {
91
20
  name: string;
92
21
  }
22
+ /**
23
+ * A token a finder that must find a record was given isn't valid (#517): it was changed, signed
24
+ * with another secret, made for another purpose, or has expired.
25
+ */
26
+ declare class InvalidToken extends ActiveRecordError {
27
+ name: string;
28
+ }
93
29
  /** `sole()` or `findSoleBy()` matched more than one record. */
94
30
  declare class SoleRecordExceeded extends ActiveRecordError {
95
31
  name: string;
@@ -102,7 +38,7 @@ declare class MissingAttribute extends ActiveRecordError {
102
38
  declare class DeleteRestriction extends ActiveRecordError {
103
39
  name: string;
104
40
  }
105
- /** `last()` can't reverse an order given as an `sql` fragment (Rails' IrreversibleOrderError). */
41
+ /** `last()` can't reverse an order given as an `sql` fragment. */
106
42
  declare class IrreversibleOrder extends ActiveRecordError {
107
43
  name: string;
108
44
  }
@@ -178,10 +114,22 @@ declare function abort(reason?: string): CallbackAbort;
178
114
  declare class RecordNotSaved extends ActiveRecordError {
179
115
  name: string;
180
116
  }
117
+ /** What a stale record was refused: its save's update, its destroy, or its `touch()` (#357). */
118
+ type StaleAction = "update" | "destroy" | "touch";
119
+ /**
120
+ * A save, destroy or `touch()` of a record whose row another write changed since it was loaded
121
+ * (#357): its `lockVersion` is no longer the row's. Nothing in the write was kept.
122
+ */
123
+ declare class StaleRecord extends ActiveRecordError {
124
+ name: string;
125
+ readonly record: Model;
126
+ readonly action: StaleAction;
127
+ constructor(record: Model, action: StaleAction, options?: ErrorOptions);
128
+ }
181
129
  /**
182
130
  * `abort()` was thrown from an after-write callback (`afterSave`, `afterCreate`, `afterUpdate`,
183
- * `afterDestroy`, `afterTouch`). That's a mistake: the write already succeeded and nothing rolls
184
- * back.
131
+ * `afterDestroy`, `afterTouch`), or from an around callback once its `next()` resolved. That's a
132
+ * mistake: the write already succeeded and nothing rolls back.
185
133
  */
186
134
  declare class AbortAfterPersistence extends ActiveRecordError {
187
135
  name: string;
@@ -210,7 +158,7 @@ declare class ReadonlyAssociation extends ActiveRecordError {
210
158
  }
211
159
  /**
212
160
  * A polymorphic belongsTo's type that names none of the Models it lists (#60), read from the
213
- * database, as Rails raises when it can't find the class a type names.
161
+ * database.
214
162
  */
215
163
  declare class UnknownModelName extends ActiveRecordError {
216
164
  name: string;
@@ -219,6 +167,98 @@ declare class UnknownModelName extends ActiveRecordError {
219
167
  declare class AssociationNotLoaded extends ActiveRecordError {
220
168
  name: string;
221
169
  }
170
+ /** One of the attributes of `C`'s records, which a counter cache names. */
171
+ type CounterName<C extends ModelClass> = NumberAttributeKey<InstanceType<C>>;
172
+ /** One of the datetime attributes of `C`'s records, which a belongsTo's or hasOne's `touch` names. */
173
+ type TouchName<C extends ModelClass> = DatetimeAttributeKey<InstanceType<C>>;
174
+ /** What a belongsTo's or hasOne's `touch` sets: `updatedAt`, and the datetime attributes named. */
175
+ type TouchedAttributes<C extends ModelClass> = true | TouchName<C> | readonly TouchName<C>[];
176
+ /** What a hasOne takes to touch its record (#497). */
177
+ interface HasOneTouchOptions<C extends ModelClass> {
178
+ /**
179
+ * Touches the record when this one is updated, destroyed or touched (not created), in the
180
+ * same batch: `true` sets its `updatedAt`, and a datetime attribute's name, or a list, sets
181
+ * those too. The record is loaded first, so its `afterTouch` and commit callbacks run. A
182
+ * record this one's own save writes (built through it, or autosaved), or its `dependent`
183
+ * removes, is left to that write.
184
+ */
185
+ touch?: TouchedAttributes<C>;
186
+ }
187
+ /** What only a belongsTo takes; `C` is its target, whose attribute a counter cache names. */
188
+ interface BelongsToOptions<C extends ModelClass = ModelClass> {
189
+ /** The record may point at nothing: saving doesn't require its record (#339). */
190
+ optional?: boolean;
191
+ /**
192
+ * Keeps a count of these records on the target (#61), updated in the same batch as each
193
+ * write: `true` counts them in the attribute named for them (`Reply` → `repliesCount`), or name
194
+ * another of the target's attributes (one every Model a polymorphic belongsTo lists has).
195
+ * `{ attribute, active: false }` keeps it on writes, but `size` doesn't read it yet, so it
196
+ * can be filled in for the rows already there.
197
+ */
198
+ counterCache?: true | CounterName<C> | {
199
+ attribute?: CounterName<C>;
200
+ active?: false;
201
+ };
202
+ /**
203
+ * Touches the target when this record is created, updated, destroyed or touched (#353), in the
204
+ * same batch: `true` sets its `updatedAt`, and a datetime attribute's name, or a list, sets
205
+ * those too. The target is loaded first, so its `afterTouch` and commit callbacks run.
206
+ */
207
+ touch?: TouchedAttributes<C>;
208
+ }
209
+ /**
210
+ * What a polymorphic belongsTo takes (#60): no `scope` (#436), and the attribute holding the
211
+ * type, inferred as the association's name + `Type` (`commentable` → `commentableType`).
212
+ */
213
+ type PolymorphicBelongsToOptions<C extends ModelClass = ModelClass> = Omit<AssociationOptions, "dependent" | "scope"> & BelongsToOptions<C> & {
214
+ foreignType?: string;
215
+ };
216
+ /**
217
+ * This record points at one record of one of `targets` (#60), by the type and key it holds:
218
+ * `commentable = belongsTo([Post, Photo])`.
219
+ */
220
+ declare function belongsTo<L extends readonly [ModelClass, ...ModelClass[]]>(targets: L, options?: PolymorphicBelongsToOptions<L[number]>): PolymorphicBelongsTo<L[number]>;
221
+ /** This record points at one `target` record through `foreignKey` (its own attribute). */
222
+ declare function belongsTo<C extends ModelClass>(target: C, options?: Omit<AssociationOptions<C>, "dependent"> & BelongsToOptions<C>): BelongsTo<C>;
223
+ /**
224
+ * What only a hasMany or hasOne takes: `as`, the name of the target's polymorphic belongsTo
225
+ * (#60), so its records point at this one by its type and key.
226
+ */
227
+ interface ToPolymorphicOptions {
228
+ /**
229
+ * The target's polymorphic belongsTo this one is the other side of (#60): its records'
230
+ * `${as}Type` holds this Model's name and `${as}Id` its key.
231
+ */
232
+ as?: string;
233
+ /** The target's attribute holding the type, inferred from `as` (`commentableType`). */
234
+ foreignType?: string;
235
+ }
236
+ /** What only a hasMany takes. */
237
+ interface HasManyOptions {
238
+ dependent?: HasManyDependent;
239
+ /**
240
+ * The owner's attribute holding a counter cache of these records (#61), which `size` reads:
241
+ * by default the one named for this association (`replies` → `repliesCount`).
242
+ * The records' belongsTo keeps it.
243
+ */
244
+ counterCache?: string;
245
+ }
246
+ /**
247
+ * Many `target` records point at this record through `foreignKey` (theirs); or, with `through`,
248
+ * this record reaches them through another of its associations (#59).
249
+ */
250
+ declare function hasMany<C extends ModelClass>(target: C, options: ThroughOptions<C> & {
251
+ dependent?: ThroughDependent;
252
+ }): HasManyThrough<C>;
253
+ declare function hasMany<C extends ModelClass>(target: C, options?: AssociationOptions<C> & ToPolymorphicOptions & HasManyOptions): HasMany<C>;
254
+ /**
255
+ * One `target` record points at this record through `foreignKey` (its own); or, with
256
+ * `through`, this record reaches it through another of its associations (#59).
257
+ */
258
+ declare function hasOne<C extends ModelClass>(target: C, options: ThroughOptions<C> & HasOneTouchOptions<C>): HasOneThrough<C>;
259
+ declare function hasOne<C extends ModelClass>(target: C, options?: AssociationOptions<C> & ToPolymorphicOptions & HasOneTouchOptions<C> & {
260
+ dependent?: HasOneDependent;
261
+ }): HasOne<C>;
222
262
  /**
223
263
  * Runs `fn` with `databases` as the request's own: queries started from a Model inside it (and
224
264
  * everything it awaits) use the one on that Model's binding, with its Session and `onQuery`.
@@ -239,4 +279,4 @@ declare function withDatabase<R>(databases: AnyDatabase | readonly AnyDatabase[]
239
279
  * which defines the scope on it; on any other, it's `undefined`.
240
280
  */
241
281
  declare function defineSchema<const S extends DatabaseSchema>(schema: S): S;
242
- export { PolymorphicBelongsToOptions as A, RecordNotUnique as C, UnknownAttribute as D, UnknownAssociation as E, hasMany as M, hasOne as N, UnknownModelName as O, RecordNotSaved as S, StrictValidationFailed as T, ReadonlyAssociation as _, AssociationNotLoaded as a, RecordNotDestroyed as b, ConstraintViolation as c, InvalidForeignKey as d, InvalidModel as f, NotNullViolation as g, NoDatabase as h, ActiveRecordError as i, belongsTo as j, abort as k, DeleteRestriction as l, MissingAttribute as m, withDatabase as n, CallbackAbort as o, IrreversibleOrder as p, AbortAfterPersistence as r, CheckViolation as s, defineSchema as t, IncompatibleRelation as u, RecordDestroyed as v, SoleRecordExceeded as w, RecordNotFound as x, RecordInvalid as y };
282
+ export { StaleAction as A, RecordDestroyed as C, RecordNotSaved as D, RecordNotFound as E, UnknownModelName as F, abort as I, StrictValidationFailed as M, UnknownAssociation as N, RecordNotUnique as O, UnknownAttribute as P, ReadonlyAssociation as S, RecordNotDestroyed as T, InvalidToken as _, hasMany as a, NoDatabase as b, ActiveRecordError as c, CheckViolation as d, ConstraintViolation as f, InvalidModel as g, InvalidForeignKey as h, belongsTo as i, StaleRecord as j, SoleRecordExceeded as k, AssociationNotLoaded as l, IncompatibleRelation as m, withDatabase as n, hasOne as o, DeleteRestriction as p, PolymorphicBelongsToOptions as r, AbortAfterPersistence as s, defineSchema as t, CallbackAbort as u, IrreversibleOrder as v, RecordInvalid as w, NotNullViolation as x, MissingAttribute as y };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
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 PolymorphicBelongsTo, B as ValidationContexts, Bt as ComparisonOptions, C as QueryEvent, Ct as gte, Dt as InOrderOfOptions, Et as QueryPart, F as RecordStatement, Ft as SafeSql, G as BelongsTo, H as Page, It as column, J as HasManyDependent, K as HasMany, L as SaveOptions, Lt as sql, M as BatchResults, N as batch, Nt as ColumnReference, P as Batch, Pt as ColumnValue, Q as HasOneThrough, R as ValidationCallbackOptions, Rt as Comparable, St as gt, Tt as lte, U as PageOptions, V as CountlessPage, W as AssociationOptions, X as HasOne, Y as HasManyThrough, Z as HasOneDependent, _ as TableSchema, _t as OrderSpec, a as ValidationOptions, at as Scoped, bt as Comparison, c as AttributeErrorMessages, ct as GroupedRelation, d as RestrictMessages, dt as Statement, et as ThroughDependent, f as Model, ft as WriteResult, g as DatabaseSchema, gt as InsertOptions, h as TableAttributes, ht as Conditions, i as UniquenessOptions, it as ScopeMethods, j as BatchEntry, k as RelationsFor, kt as QuerySql, l as ErrorMessage, lt as Init, m as ScopeStatic, n as LengthOptions, nt as Relation, o as Errors, ot as IterationOptions, q as HasManyCollection, r as NumericalityOptions, rt as Scope, s as ValidationError, st as TouchOptions, t as AssociatedValidationOptions, tt as ThroughOptions, u as ErrorMessages, ut as ReturnedRow, v as TableSchemas, vt as Returning, w as QueryListener, wt as lt, x as AttributeConversions, xt as between, y as FilterAttribute, yt as UpsertOptions, z as ValidationContext, zt as ComparisonBound } from "./validations-BSZ5gVeI.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-D5getfHx.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 };
1
+ import { A as defineType, C as SecurePasswordOptions, D as Duration, E as PasswordAlgorithm, _ as SecureTokenOptions, a as AttributeType, i as AttributeSpecs, k as CustomType, r as AttributeSpec, u as EpochStorage, v as generateSecureToken } from "./metadata-BIUbGJlS.mjs";
2
+ import { $ as TouchOptions, At as lt, B as SaveOptions, Bt as ColumnValue, C as QueryEvent, Ct as OrderSpec, Dt as between, Et as Comparison, F as RecordStatement, Ft as QuerySql, G as Relation, Gt as ComparisonBound, H as ValidationContext, Ht as column, J as Scoped, K as Scope, Kt as ComparisonOptions, M as BatchResults, Mt as QueryPart, N as batch, Nt as InOrderOfOptions, Ot as gt, P as Batch, Q as PageOptions, R as SigningEnv, St as InsertOptions, Tt as UpsertOptions, U as ValidationContexts, Ut as sql, V as ValidationCallbackOptions, Vt as SafeSql, W as TokenForOptions, Wt as Comparable, X as CountlessPage, Y as IterationOptions, Z as Page, _ as TableSchema, _t as HasOneThrough, a as ValidationOptions, at as Statement, bt as ThroughOptions, c as AttributeErrorMessages, d as RestrictMessages, dt as HasMany, et as GroupedRelation, f as Model, ft as HasManyCollection, g as DatabaseSchema, gt as HasOneDependent, h as TableAttributes, ht as HasOne, i as UniquenessOptions, it as ReturnedRow, j as BatchEntry, jt as lte, k as RelationsFor, kt as gte, l as ErrorMessage, lt as AssociationOptions, m as ScopeStatic, mt as HasManyThrough, n as LengthOptions, nt as SignedIdOptions, o as Errors, ot as WriteResult, pt as HasManyDependent, q as ScopeMethods, r as NumericalityOptions, rt as Init, s as ValidationError, t as AssociatedValidationOptions, tt as FindSignedOptions, u as ErrorMessages, ut as BelongsTo, v as TableSchemas, vt as PolymorphicBelongsTo, w as QueryListener, wt as Returning, x as AttributeConversions, xt as Conditions, y as FilterAttribute, yt as ThroughDependent, z as SigningSecrets, zt as ColumnReference } from "./validations-CKPJoSj4.mjs";
3
+ import { A as StaleAction, C as RecordDestroyed, D as RecordNotSaved, E as RecordNotFound, F as UnknownModelName, I as abort, M as StrictValidationFailed, N as UnknownAssociation, O as RecordNotUnique, P as UnknownAttribute, S as ReadonlyAssociation, T as RecordNotDestroyed, _ as InvalidToken, a as hasMany, b as NoDatabase, c as ActiveRecordError, d as CheckViolation, f as ConstraintViolation, g as InvalidModel, h as InvalidForeignKey, i as belongsTo, j as StaleRecord, k as SoleRecordExceeded, l as AssociationNotLoaded, m as IncompatibleRelation, n as withDatabase, o as hasOne, p as DeleteRestriction, r as PolymorphicBelongsToOptions, s as AbortAfterPersistence, t as defineSchema, u as CallbackAbort, v as IrreversibleOrder, w as RecordInvalid, x as NotNullViolation, y as MissingAttribute } from "./index-Fq4gT3c8.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 Duration, type EpochStorage, type ErrorMessage, type ErrorMessages, Errors, type FilterAttribute, type FindSignedOptions, 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, InvalidToken, IrreversibleOrder, type IterationOptions, type LengthOptions, MissingAttribute, Model, NoDatabase, NotNullViolation, type NumericalityOptions, type OrderSpec, type Page, type PageOptions, type PasswordAlgorithm, 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, type SecurePasswordOptions, type SecureTokenOptions, type SignedIdOptions, type SigningEnv, type SigningSecrets, SoleRecordExceeded, type StaleAction, StaleRecord, type Statement, StrictValidationFailed, type TableAttributes, type TableSchema, type TableSchemas, type ThroughDependent, type ThroughOptions, type TokenForOptions, 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, generateSecureToken, 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 "./identifiers-Dh5DFACX.mjs";
2
- import { b as hasOne, c as Relation, d as between, f as gt, h as lte, i as withDatabase, l as column, m as lt, p as gte, r as Model, t as batch, u as sql, v as belongsTo, y as hasMany } from "./batch-Ms5p9lKq.mjs";
3
- import { g as Errors, z as defineType } from "./generated-model-DJA8vmNE.mjs";
4
- import { t as defineSchema } from "./src-BAVZKQ7J.mjs";
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
+ import { $ as UnknownAssociation, A as AssociationNotLoaded, B as MissingAttribute, F as IncompatibleRelation, G as RecordInvalid, H as NotNullViolation, I as InvalidForeignKey, J as RecordNotSaved, K as RecordNotDestroyed, L as InvalidModel, M as CheckViolation, N as ConstraintViolation, O as AbortAfterPersistence, P as DeleteRestriction, Q as StrictValidationFailed, R as InvalidToken, U as ReadonlyAssociation, V as NoDatabase, W as RecordDestroyed, X as SoleRecordExceeded, Y as RecordNotUnique, Z as StaleRecord, et as UnknownAttribute, j as CallbackAbort, k as ActiveRecordError, nt as abort, q as RecordNotFound, tt as UnknownModelName, z as IrreversibleOrder } from "./identifiers-CzqYL_nC.mjs";
2
+ import { _ as lt, b as hasMany, c as Relation, d as column, f as sql, g as gte, h as gt, m as between, n as Model, r as withDatabase, t as batch, v as lte, x as hasOne, y as belongsTo } from "./batch-Ca1JtVcK.mjs";
3
+ import { Y as Errors, dt as defineType, st as generateSecureToken } from "./generated-model-L4WAqgOZ.mjs";
4
+ import { t as defineSchema } from "./src-fYq-nVHE.mjs";
5
+ export { AbortAfterPersistence, ActiveRecordError, AssociationNotLoaded, CallbackAbort, CheckViolation, ConstraintViolation, DeleteRestriction, Errors, IncompatibleRelation, InvalidForeignKey, InvalidModel, InvalidToken, IrreversibleOrder, MissingAttribute, Model, NoDatabase, NotNullViolation, ReadonlyAssociation, RecordDestroyed, RecordInvalid, RecordNotDestroyed, RecordNotFound, RecordNotSaved, RecordNotUnique, Relation, SoleRecordExceeded, StaleRecord, StrictValidationFailed, UnknownAssociation, UnknownAttribute, UnknownModelName, abort, batch, belongsTo, between, column, defineSchema, defineType, generateSecureToken, gt, gte, hasMany, hasOne, lt, lte, sql, withDatabase };
@@ -0,0 +1,363 @@
1
+ /** An alias in `static attributes` or `define`: `title: { aliasOf: "name" }` reads as "title is an alias of name". */
2
+ interface AttributeAlias {
3
+ readonly aliasOf: string;
4
+ }
5
+ /** The aliases among a Model's declared attributes `O`, each typed as the attribute it names in `S`. */
6
+ type AliasSpecs<S, O> = { -readonly [K in keyof O as O[K] extends {
7
+ aliasOf: keyof S;
8
+ } ? K : never]: O[K] extends {
9
+ aliasOf: infer T extends keyof S;
10
+ } ? S[T] : never; };
11
+ /** `define`'s attributes `A`, with each alias typed as the attribute it names; `A` itself without one. */
12
+ type DefinedSpecs<A> = [AliasNames<A>] extends [never] ? A : WithoutAliases<A> & AliasSpecs<WithoutAliases<A>, A>;
13
+ /** The names of the aliases among `A`. */
14
+ type AliasNames<A> = { [K in keyof A]: A[K] extends {
15
+ aliasOf: string;
16
+ } ? K : never; }[keyof A];
17
+ /** The declared attributes `O` without their aliases. */
18
+ type WithoutAliases<O> = { [K in keyof O as O[K] extends {
19
+ aliasOf: string;
20
+ } ? never : K]: O[K]; };
21
+ /**
22
+ * A type an app defines: what its values are, and how each is kept as a value of the built-in
23
+ * type it's stored as. Made by `defineType`.
24
+ */
25
+ interface CustomType<T = unknown, S extends AttributeType = AttributeType> {
26
+ /** The built-in type its values are stored as: `"integer"` for money kept as cents. */
27
+ readonly storedAs: S;
28
+ /**
29
+ * An assigned value or a condition's as the type's value. It throws for one it can't hold:
30
+ * assigning that value throws `TypeError`, with this error as its `cause`, and a condition
31
+ * matches nothing. Never called with `null`.
32
+ */
33
+ cast(input: unknown): T;
34
+ /** A value as the stored type's value: `money.cents`. Never called with `null`. */
35
+ serialize(value: T): BuiltInValue<S>;
36
+ /** A stored type's value, read as the stored type reads a cell, as the type's value. */
37
+ deserialize(stored: BuiltInValue<S>): T;
38
+ }
39
+ /** Any custom type, whatever its values: what a spec takes. */
40
+ type AnyCustomType = CustomType<any, AttributeType>;
41
+ /**
42
+ * Defines an attribute type, used in a spec as a type name is: `price: money`, or
43
+ * `{ type: money, null: false }`. Its values are kept as `storedAs` keeps its own, so they're
44
+ * read strictly, compared and ordered as that type's are.
45
+ */
46
+ declare function defineType<T, S extends AttributeType>(type: CustomType<T, S>): CustomType<T, S>;
47
+ /** A length of time: `{ minutes: 15 }`, `{ days: 1, hours: 12 }`. */
48
+ interface Duration {
49
+ readonly seconds?: number;
50
+ readonly minutes?: number;
51
+ readonly hours?: number;
52
+ readonly days?: number;
53
+ }
54
+ /**
55
+ * What hashes a secure password and verifies it against a digest: the default, or an app's own
56
+ * (bcrypt, to read digests another app made).
57
+ */
58
+ interface PasswordAlgorithm {
59
+ /** A digest of `password`, salted, that `verify` can check it against. */
60
+ hash(password: string): Promise<string>;
61
+ /** Whether `password` is the one `digest` was made from. */
62
+ verify(password: string, digest: string): Promise<boolean>;
63
+ /** The most bytes a password may be, in UTF-8; without it, any length. */
64
+ readonly maxBytes?: number;
65
+ }
66
+ /** `securePassword`'s options: the algorithm that hashes the password, and its validations. */
67
+ interface SecurePasswordOptions {
68
+ /** What hashes the password and verifies it: PBKDF2-SHA256 unless given. */
69
+ readonly algorithm?: PasswordAlgorithm;
70
+ /** `false` leaves out the validations a secure password adds. */
71
+ readonly validations?: boolean;
72
+ /**
73
+ * Its reset token (`passwordResetToken()`), which lasts 15 minutes unless `expiresIn` says
74
+ * otherwise, and stops finding its record once the password changes; `false` leaves it out.
75
+ */
76
+ readonly resetToken?: boolean | {
77
+ readonly expiresIn?: Duration;
78
+ };
79
+ }
80
+ /** A secure password in `static attributes` or `define`: `password: { securePassword: true }`. */
81
+ interface SecurePasswordDeclaration {
82
+ readonly securePassword: true | SecurePasswordOptions;
83
+ }
84
+ /** The spec a secure password's own attribute gets: a virtual string that says it's one, with its options. */
85
+ type PasswordSpec<D> = {
86
+ type: "string";
87
+ virtual: true;
88
+ securePassword: D extends {
89
+ securePassword: infer P;
90
+ } ? P : true;
91
+ };
92
+ /** The spec of its confirmation and its challenge: virtual strings. */
93
+ type CompanionSpec = {
94
+ type: "string";
95
+ virtual: true;
96
+ };
97
+ /** The names among `O` that declare a secure password. */
98
+ type DeclaredNames<O> = { [K in keyof O]: O[K] extends SecurePasswordDeclaration ? K & string : never; }[keyof O];
99
+ /**
100
+ * The attributes the secure passwords among the declared attributes `O` add: each one, its
101
+ * confirmation and its challenge, virtual strings.
102
+ */
103
+ type SecurePasswordSpecs<O> = { -readonly [K in DeclaredNames<O>]: PasswordSpec<O[K]>; } & { -readonly [K in DeclaredNames<O> as `${K}Confirmation` | `${K}Challenge`]: CompanionSpec; };
104
+ /** The declared attributes `O`, each secure password in it replaced by the attributes it adds. */
105
+ type WithSecurePasswords<O> = [DeclaredNames<O>] extends [never] ? O : { [K in keyof O as K extends DeclaredNames<O> ? never : K]: O[K]; } & SecurePasswordSpecs<O>;
106
+ /** The names among the attribute specs `A` that are secure passwords. */
107
+ type PasswordNames<A> = { [K in keyof A]: A[K] extends {
108
+ securePassword: true | object;
109
+ } ? K & string : never; }[keyof A];
110
+ /**
111
+ * What `authenticateBy` takes for a Model whose attribute specs are `S` and attributes `A`: any of
112
+ * its attributes, or `never` for a Model without a secure password, so calling it is a compile
113
+ * error.
114
+ */
115
+ type AuthenticateByAttributes<S, A> = [PasswordNames<S>] extends [never] ? never : Partial<A>;
116
+ /** Checks a password against its digest: the record, or `false` when it isn't the one. */
117
+ type Authenticate = <R>(this: R, password: string) => Promise<R | false>;
118
+ /** The names among the attribute specs `A` that are secure passwords with a reset token. */
119
+ type ResettableNames<A> = { [K in keyof A]: A[K] extends {
120
+ securePassword: {
121
+ resetToken: false;
122
+ };
123
+ } ? never : A[K] extends {
124
+ securePassword: true | object;
125
+ } ? K & string : never; }[keyof A];
126
+ /**
127
+ * What the secure passwords among the specs `A` add to a record: `authenticatePassword` for
128
+ * `password`, `authenticateRecoveryPassword` for `recoveryPassword`, and `authenticate`, for
129
+ * `password` alone; and each reset token's, `passwordResetToken()` (#517).
130
+ */
131
+ type SecurePasswordMethods<A> = { [K in PasswordNames<A> as `authenticate${Capitalize<K>}`]: Authenticate; } & ("password" extends PasswordNames<A> ? {
132
+ authenticate: Authenticate;
133
+ } : {}) & { [K in ResettableNames<A> as `${K}ResetToken`]: () => Promise<string>; };
134
+ /**
135
+ * What `findByPasswordResetToken` takes for a Model whose attribute specs are `S`: a token, or
136
+ * `never` for a Model whose `password` has no reset token, so calling it is a compile error.
137
+ */
138
+ type PasswordResetTokenArgument<S> = "password" extends ResettableNames<S> ? unknown : never;
139
+ /** `secureToken`'s options: how long the token is, a prefix, and when it's generated. */
140
+ interface SecureTokenOptions {
141
+ /** Its characters, after any prefix: 24 unless given, and at least 24. */
142
+ readonly length?: number;
143
+ /** Text before the token: `true` for the column's name and `_` (`auth_token_…`), or its own. */
144
+ readonly prefix?: true | string;
145
+ /** When a new record without one gets it: as it's built (the default), or as it's created. */
146
+ readonly on?: "initialize" | "create";
147
+ }
148
+ /**
149
+ * A random base58 token of `length` characters (24 unless given), from `crypto.getRandomValues`,
150
+ * each character equally likely. Nothing checks it's unique: a unique index does that.
151
+ */
152
+ declare function generateSecureToken(length?: number): string;
153
+ /** The names among the attribute specs `A` that are secure tokens. */
154
+ type TokenNames<A> = { [K in keyof A]: A[K] extends {
155
+ secureToken: true | object;
156
+ } ? K & string : never; }[keyof A];
157
+ /**
158
+ * What the secure tokens among the specs `A` add to a record: `regenerateAuthToken()`, resolving
159
+ * to `false` when the record is invalid or a callback aborts, and its `OrThrow`.
160
+ */
161
+ type SecureTokenMethods<A> = { [K in TokenNames<A> as `regenerate${Capitalize<K>}`]: () => Promise<boolean>; } & { [K in TokenNames<A> as `regenerate${Capitalize<K>}OrThrow`]: () => Promise<true>; };
162
+ /**
163
+ * An enum's values: its names, each stored as itself (a `string` attribute's only), or each name
164
+ * with the value it's stored as (`{ draft: 0, published: 1 }`).
165
+ */
166
+ type EnumValues = readonly string[] | {
167
+ readonly [name: string]: string | number;
168
+ };
169
+ /** A `string` attribute's enum: names stored as themselves, or each with the text it's stored as. */
170
+ type TextEnum = readonly string[] | {
171
+ readonly [name: string]: string;
172
+ };
173
+ /** An `integer` attribute's enum: each name with the integer it's stored as. */
174
+ type IntegerEnum = {
175
+ readonly [name: string]: number;
176
+ };
177
+ /** The names an enum's values give its attribute: `"draft" | "published"`. */
178
+ type EnumNames<E> = E extends readonly (infer N extends string)[] ? N : keyof E & string;
179
+ /** An enum's names, each with the value it's stored as, as `enumValues` gives them. */
180
+ type EnumMapping<E> = E extends readonly string[] ? { readonly [N in E[number]]: N; } : Readonly<E>;
181
+ /** A datetime held in an `INTEGER` column as seconds or milliseconds since 1970. */
182
+ declare const epochStorages: readonly ["unixSeconds", "unixMilliseconds"];
183
+ type EpochStorage = (typeof epochStorages)[number];
184
+ type AttributeType = "string" | "integer" | "real" | "decimal" | "boolean" | "datetime" | "date" | "time" | "json" | "binary";
185
+ /** An attribute's spec written out: its type, and optionally nullability, column and default. */
186
+ interface SpecObject {
187
+ /** A built-in type's name, or a type `defineType` made (#20). */
188
+ type: AttributeType | AnyCustomType;
189
+ null?: boolean;
190
+ column?: string;
191
+ /** A `datetime` held as a Unix epoch integer, as Drizzle's timestamp modes write it (#73). */
192
+ storage?: EpochStorage;
193
+ /** A decimal's most digits in all, as `NUMERIC(10, 2)`'s 10; without a scale, its scale is 0 (#398). */
194
+ precision?: number;
195
+ /** A decimal's digits after the point, as `NUMERIC(10, 2)`'s 2: a cast value is rounded to them (#398). */
196
+ scale?: number;
197
+ /** Evaluated at `build()`, e.g. `() => new Date()`. */
198
+ default?: () => unknown;
199
+ /**
200
+ * Made by the Model's `generateId` when not given, where a default would run: an
201
+ * app-generated key (#99). Generated ids are strings, so only a string attribute has one.
202
+ */
203
+ generateId?: boolean;
204
+ /** Its only values, by name, and what each is stored as (#340). */
205
+ enum?: EnumValues;
206
+ /** A word before each enum name in its methods' names: the attribute's name for `true` (#340). */
207
+ prefix?: boolean | string;
208
+ /** A word after each enum name in its methods' names: the attribute's name for `true` (#340). */
209
+ suffix?: boolean | string;
210
+ /** `false` to give the Model no scope for each enum name (#340). */
211
+ scopes?: boolean;
212
+ /** `false` to give records no predicate or `saveAs…` setter for each enum name (#340). */
213
+ instanceMethods?: boolean;
214
+ /**
215
+ * Validates an enum's value instead of refusing an unknown one when it's assigned: a
216
+ * record holding another value, or null unless `allowNull`, is invalid.
217
+ */
218
+ validate?: EnumValidation;
219
+ /**
220
+ * An attribute that isn't a column (#356): cast and tracked like one, never read from a row or
221
+ * written to one, and refused in queries.
222
+ */
223
+ virtual?: boolean;
224
+ /**
225
+ * A virtual password kept as its digest, in the column of the attribute named for it with
226
+ * `Digest` (#355): `true`, or its options.
227
+ */
228
+ securePassword?: true | SecurePasswordOptions;
229
+ /**
230
+ * A random token, generated for a new record that has none, and regenerated by
231
+ * `regenerate…()` (#355): `true`, or its options. Only a string has one.
232
+ */
233
+ secureToken?: boolean | SecureTokenOptions;
234
+ }
235
+ /** How an enum's value is validated: `true`, or `{ allowNull: true }` to let it be null. */
236
+ type EnumValidation = boolean | {
237
+ readonly allowNull?: boolean;
238
+ };
239
+ /** Where a string attribute's value comes from when it isn't given: a default or `generateId`, never both. */
240
+ type ValueSource = {
241
+ default?: () => unknown;
242
+ generateId?: false;
243
+ } | {
244
+ default?: never;
245
+ generateId: true;
246
+ };
247
+ /** An attribute that isn't an enum: no type but a string or an integer has one (#340). */
248
+ type NoEnum = {
249
+ enum?: never;
250
+ prefix?: never;
251
+ suffix?: never;
252
+ scopes?: never;
253
+ instanceMethods?: never;
254
+ validate?: never;
255
+ };
256
+ /** An attribute that isn't a decimal: only a decimal has a precision and a scale (#398). */
257
+ type NoDigits = {
258
+ precision?: never;
259
+ scale?: never;
260
+ };
261
+ /** An attribute that isn't a string: only a string has a secure token (#355). */
262
+ type NoToken = {
263
+ secureToken?: never;
264
+ };
265
+ /** The spec's keys that only some types have, each written by the type's own branch below. */
266
+ type PerTypeKeys = "type" | "generateId" | "storage" | "enum" | "precision" | "scale" | "secureToken";
267
+ type AttributeSpec = AttributeType | AnyCustomType | (SpecObjectByType & Placement);
268
+ /** A column, or a virtual attribute, which has none (#356). */
269
+ type Placement = {
270
+ virtual?: false;
271
+ } | {
272
+ virtual: true;
273
+ column?: never;
274
+ };
275
+ /** A spec written out, by its type: the keys each type may have. */
276
+ type SpecObjectByType = (Omit<SpecObject, "default" | PerTypeKeys> & {
277
+ type: "string";
278
+ storage?: never;
279
+ enum?: TextEnum;
280
+ secureToken?: boolean | SecureTokenOptions;
281
+ } & ValueSource & NoDigits) | (Omit<SpecObject, PerTypeKeys> & NoDigits & NoToken & {
282
+ type: "integer";
283
+ generateId?: false;
284
+ storage?: never;
285
+ enum?: IntegerEnum;
286
+ }) | (Omit<SpecObject, PerTypeKeys> & NoEnum & NoDigits & NoToken & {
287
+ type: Exclude<AttributeType, "string" | "integer" | "datetime" | "decimal">;
288
+ generateId?: false;
289
+ storage?: never;
290
+ }) | (Omit<SpecObject, PerTypeKeys> & NoEnum & NoToken & {
291
+ type: "decimal";
292
+ generateId?: false;
293
+ storage?: never;
294
+ precision?: number;
295
+ scale?: number;
296
+ }) | (Omit<SpecObject, Exclude<PerTypeKeys, "storage">> & NoEnum & NoDigits & NoToken & {
297
+ type: "datetime";
298
+ generateId?: false;
299
+ }) | (Omit<SpecObject, PerTypeKeys> & NoEnum & NoDigits & NoToken & {
300
+ type: AnyCustomType;
301
+ generateId?: false;
302
+ storage?: never;
303
+ });
304
+ type AttributeSpecs = Record<string, AttributeSpec>;
305
+ /** What `define` takes: attribute specs, aliases of them (#509), and secure passwords (#355). */
306
+ type DeclaredAttributes = Record<string, AttributeSpec | AttributeAlias | SecurePasswordDeclaration>;
307
+ /**
308
+ * `A`, with any key a spec doesn't have typed `never`, so a misspelled one (`nul: false`) is a
309
+ * compile error: a generic parameter skips TypeScript's own check for unknown keys (#102).
310
+ */
311
+ type ExactSpecs<A> = { [K in keyof A]: A[K] extends AnyCustomType ? A[K] : A[K] extends {
312
+ aliasOf: string;
313
+ } ? A[K] & Record<Exclude<keyof A[K], "aliasOf">, never> : A[K] extends {
314
+ securePassword: unknown;
315
+ type?: never;
316
+ } ? A[K] & ExactSecurePassword<A[K]["securePassword"]> & Record<Exclude<keyof A[K], "securePassword">, never> : A[K] extends object ? A[K] & Record<Exclude<keyof A[K], keyof SpecObject>, never> : A[K]; };
317
+ /** A secure password's `securePassword`, with any option it doesn't have typed `never` (#355). */
318
+ type ExactSecurePassword<P> = {
319
+ securePassword: P extends true ? true : P & Record<Exclude<keyof P, keyof SecurePasswordOptions>, never>;
320
+ };
321
+ /** An attribute's resolved metadata. */
322
+ interface AttributeDefinition {
323
+ /** Its built-in type: for a custom type, the type it's stored as. */
324
+ type: AttributeType;
325
+ /** The type `defineType` made, whose values it holds, kept as `type`'s (#20). */
326
+ customType?: AnyCustomType;
327
+ column: string;
328
+ default?: () => unknown;
329
+ generateId?: true;
330
+ storage?: EpochStorage;
331
+ precision?: number;
332
+ scale?: number;
333
+ enum?: EnumValues;
334
+ prefix?: boolean | string;
335
+ suffix?: boolean | string;
336
+ scopes?: boolean;
337
+ instanceMethods?: boolean;
338
+ validate?: EnumValidation;
339
+ /** Not a column: never read or written, and refused in queries (#356). */
340
+ virtual?: true;
341
+ /** A secure password, kept as its digest (#355). */
342
+ securePassword?: true | SecurePasswordOptions;
343
+ /** A secure token, generated for a new record (#355). */
344
+ secureToken?: true | SecureTokenOptions;
345
+ }
346
+ /** The JavaScript value an attribute of a built-in type holds: a `Date` for a `datetime`. */
347
+ type BuiltInValue<T extends AttributeType> = T extends "string" ? string : T extends "integer" | "real" ? number : T extends "boolean" ? boolean : T extends "datetime" ? Date : T extends "binary" ? Uint8Array : T extends "decimal" | "date" | "time" ? string : unknown;
348
+ /** A type's JavaScript value: a built-in type's, or a custom type's own (#20). */
349
+ type ValueOf<T> = T extends AttributeType ? BuiltInValue<T> : T extends CustomType<infer V, AttributeType> ? V : never;
350
+ /** A spec's value, not null: an enum's names (#340), or its type's JavaScript value. */
351
+ type SpecValue<S> = S extends {
352
+ enum: infer E extends EnumValues;
353
+ } ? EnumNames<E> : S extends {
354
+ type: infer T;
355
+ } ? ValueOf<T> : never;
356
+ type AttributeValue<S> = S extends AttributeType | AnyCustomType ? ValueOf<S> | null : S extends {
357
+ type: unknown;
358
+ null: false;
359
+ } ? SpecValue<S> : S extends {
360
+ type: unknown;
361
+ } ? SpecValue<S> | null : never;
362
+ type AttributeProperties<A extends AttributeSpecs> = { -readonly [K in keyof A]: AttributeValue<A[K]>; };
363
+ export { defineType as A, SecurePasswordOptions as C, Duration as D, PasswordAlgorithm as E, AttributeAlias as M, DefinedSpecs as N, AnyCustomType as O, WithoutAliases as P, SecurePasswordMethods as S, WithSecurePasswords as T, SecureTokenOptions as _, AttributeType as a, PasswordResetTokenArgument as b, SpecObject as c, EnumMapping as d, EnumNames as f, SecureTokenMethods as g, TextEnum as h, AttributeSpecs as i, AliasSpecs as j, CustomType as k, ValueSource as l, IntegerEnum as m, AttributeProperties as n, DeclaredAttributes as o, EnumValues as p, AttributeSpec as r, ExactSpecs as s, AttributeDefinition as t, EpochStorage as u, generateSecureToken as v, SecurePasswordSpecs as w, SecurePasswordDeclaration as x, AuthenticateByAttributes as y };