@orieljs/database 0.1.0-alpha.5 → 0.1.0-alpha.6

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/NOTICE CHANGED
@@ -7,3 +7,6 @@ This product includes software developed by the Oriel project
7
7
  Oriel is licensed under the Apache License, Version 2.0 (see LICENSE).
8
8
  The Oriel name and logo are not covered by that license; see TRADEMARKS.md
9
9
  (https://github.com/orieljs/framework/blob/main/TRADEMARKS.md).
10
+
11
+ @orieljs/support (and @orieljs/framework, which bundles it) includes transliteration data from
12
+ voku/portable-ascii (https://github.com/voku/portable-ascii), Copyright (C) 2019 Lars Moelleken, MIT License.
package/dist/index.d.ts CHANGED
@@ -595,8 +595,11 @@ declare abstract class AbstractPaginator<T> implements Iterable<T> {
595
595
  items(): T[];
596
596
  getCollection(): Collection<T>;
597
597
  setCollection(items: Collection<T>): this;
598
- /** Transforms each item in place, typically for serialization: paginator.through(post => ({ id: post.id })). */
599
- through(callback: (item: T, index: number) => unknown): this;
598
+ /**
599
+ * Transforms each item in place, typically for serialization, and returns this paginator typed with the new items:
600
+ * `posts.through((post) => ({ id: post.id }))`. Each paginator narrows the return type to its own class.
601
+ */
602
+ through<U>(callback: (item: T, index: number) => U): AbstractPaginator<U>;
600
603
  perPage(): number;
601
604
  count(): number;
602
605
  isEmpty(): boolean;
@@ -642,6 +645,7 @@ declare class CursorPaginator<T> extends AbstractPaginator<T> {
642
645
  static resolveCurrentCursor(cursorName?: string): Cursor | undefined;
643
646
  cursor(): Cursor | undefined;
644
647
  getCursorName(): string;
648
+ through<U>(callback: (item: T, index: number) => U): CursorPaginator<U>;
645
649
  hasMorePages(): boolean;
646
650
  onFirstPage(): boolean;
647
651
  nextCursor(): Cursor | undefined;
@@ -671,6 +675,7 @@ declare class LengthAwarePaginator<T> extends AbstractPaginator<T> {
671
675
  protected readonly lastPageValue: number;
672
676
  constructor(items: Iterable<T>, totalValue: number, perPage: number, currentPage?: number, options?: PaginatorOptions);
673
677
  total(): number;
678
+ through<U>(callback: (item: T, index: number) => U): LengthAwarePaginator<U>;
674
679
  lastPage(): number;
675
680
  hasPages(): boolean;
676
681
  hasMorePages(): boolean;
@@ -696,6 +701,7 @@ declare class Paginator<T> extends AbstractPaginator<T> {
696
701
  protected readonly hasMore: boolean;
697
702
  constructor(items: Iterable<T>, perPage: number, currentPage?: number, options?: PaginatorOptions);
698
703
  hasMorePages(): boolean;
704
+ through<U>(callback: (item: T, index: number) => U): Paginator<U>;
699
705
  hasPages(): boolean;
700
706
  onLastPage(): boolean;
701
707
  nextPageUrl(): string | null;
@@ -1315,6 +1321,9 @@ declare class Builder<M extends Model = Model> extends Builder$1<M> {
1315
1321
  exists(): Promise<boolean>;
1316
1322
  /** The column's values, through the model's casts and accessors. */
1317
1323
  pluck<V = unknown>(column: Column<M>): Promise<Collection<V>>;
1324
+ /** Whether `id` can't be one of the model's unique ids (not a UUID for HasUuids): it matches no row. */
1325
+ protected isMalformedKey(id: unknown): boolean;
1326
+ /** A malformed unique id (HasUuids, HasUlids) finds nothing without a query, as route model binding does. */
1318
1327
  find(id: unknown): Promise<M | undefined>;
1319
1328
  findMany(ids: readonly unknown[]): Promise<Collection<M>>;
1320
1329
  /** find(), or ModelNotFoundError (a 404). With an array, every id must exist. */
@@ -1614,6 +1623,8 @@ declare abstract class HasOneOrMany<R extends Model, P extends Model, Result> ex
1614
1623
  readonly foreignKey: string;
1615
1624
  readonly localKey: string;
1616
1625
  readonly morph?: MorphConstraint | undefined;
1626
+ /** The relation on each related model that chaperone() points back at the parent. */
1627
+ protected inverseRelationship: string | undefined;
1617
1628
  /**
1618
1629
  * @param foreignKey the qualified foreign key on the related table ('comments.post_id')
1619
1630
  * @param localKey the key on the parent it points at ('id')
@@ -1629,6 +1640,26 @@ declare abstract class HasOneOrMany<R extends Model, P extends Model, Result> ex
1629
1640
  getMorphType(): string | undefined;
1630
1641
  /** The parent's value in the type column, for a morph relation. */
1631
1642
  getMorphClass(): string | undefined;
1643
+ /**
1644
+ * Laravel's chaperone(): every related model this relation loads, eagerly or lazily, or makes, gets the parent as
1645
+ * its `relation` (guessed when not given: post_id → post, the parent's class, owner), so reading it needs no query:
1646
+ * `comments() { return this.hasMany(Comment).chaperone() }`.
1647
+ */
1648
+ chaperone(relation?: string): this;
1649
+ /** Laravel's inverse(): chaperone() under its other name. */
1650
+ inverse(relation?: string): this;
1651
+ withoutChaperone(): this;
1652
+ withoutInverse(): this;
1653
+ getInverseRelationship(): string | undefined;
1654
+ /** The first of the possible names that is a relation of the related model. */
1655
+ protected guessInverseRelation(): string | undefined;
1656
+ /** Laravel's candidates: the morph name, the foreign key without the parent's key, the parent's class, owner, parent. */
1657
+ protected getPossibleInverseRelations(): string[];
1658
+ /** Sets the parent on a related model, when chaperone() named the relation. */
1659
+ protected applyInverseRelationToModel<M extends R | null | undefined>(model: M, parent?: P): M;
1660
+ protected applyInverseRelationToMany(models: R[], parent?: P): R[];
1661
+ /** The relation query's rows (get(), first(), paginate(), …), pointing back at the parent with chaperone(). */
1662
+ runSelect(): Promise<R[]>;
1632
1663
  addConstraints(): void;
1633
1664
  addEagerConstraints(models: P[]): void;
1634
1665
  /** Related models grouped by their foreign key, as strings: bigint and integer keys compare equal. */
@@ -1979,6 +2010,16 @@ declare class Model implements ModelInstance {
1979
2010
  getKeyName(): string;
1980
2011
  getKeyType(): 'int' | 'string';
1981
2012
  getIncrementing(): boolean;
2013
+ /** Whether new rows get unique string ids before `creating` (HasUuids, HasUlids). */
2014
+ usesUniqueIds(): boolean;
2015
+ /** The columns that get a unique id (HasUuids and HasUlids: the primary key). */
2016
+ uniqueIds(): string[];
2017
+ /** A new unique id (HasUuids: a version 7 UUID; HasUlids: a lower-case ULID). */
2018
+ newUniqueId(): string | undefined;
2019
+ /** Whether a value has the shape of this model's unique ids (HasUuids: a UUID). Any value passes by default. */
2020
+ isValidUniqueId(_value: unknown): boolean;
2021
+ /** Fills each empty unique id column with newUniqueId() (Laravel's setUniqueIds()). */
2022
+ setUniqueIds(): void;
1982
2023
  getKey(): unknown;
1983
2024
  getTable(): string;
1984
2025
  getConnectionName(): string | undefined;
@@ -1992,7 +2033,8 @@ declare class Model implements ModelInstance {
1992
2033
  getRouteKey(): unknown;
1993
2034
  /**
1994
2035
  * The model a route parameter value points at: where <field or route key> = value (global scopes apply, so a
1995
- * soft-deleted row isn't found). A non-numeric value for an integer primary key finds nothing without a query.
2036
+ * soft-deleted row isn't found). A non-numeric value for an integer primary key, or a value that isn't a UUID
2037
+ * (ULID) for a unique id column, finds nothing without a query.
1996
2038
  */
1997
2039
  resolveRouteBinding(value: string, field?: string): Promise<this | undefined>;
1998
2040
  /** Override to customize the binding query (Laravel's resolveRouteBindingQuery()). */
@@ -2125,6 +2167,8 @@ declare class Model implements ModelInstance {
2125
2167
  get pivot(): Model | undefined;
2126
2168
  /** A related model instance on this model's connection when it has none of its own. */
2127
2169
  protected newRelatedInstance<C extends typeof Model>(related: C): InstanceType<C>;
2170
+ /** Whether the model has a relation method called `name` (Laravel's isRelation()). */
2171
+ isRelation(name: string): boolean;
2128
2172
  /** Calls the relation method `name` (post.comments()) and checks that it returns a relation. */
2129
2173
  getRelationInstance(name: string): Relation;
2130
2174
  /**
@@ -2156,7 +2200,10 @@ declare class Model implements ModelInstance {
2156
2200
  setAppends(appends: string[]): this;
2157
2201
  /** Adds accessor-only attributes to the serialized form of this instance. */
2158
2202
  append(...attributes: Array<string | string[]>): this;
2159
- /** Attributes (through accessors and casts, dates as ISO strings), appends and loaded relations, minus hidden ones. */
2203
+ /**
2204
+ * Attributes (through accessors and casts, dates as ISO strings), appends and loaded relations, minus hidden ones.
2205
+ * A model met again while its own toArray() runs (a child chaperone() pointed back at it) gives its attributes only.
2206
+ */
2160
2207
  toArray(): Row;
2161
2208
  toJSON(): Row;
2162
2209
  attributesToArray(): Row;
@@ -2175,11 +2222,13 @@ declare class Pivot extends Model {
2175
2222
  timestamps: boolean;
2176
2223
  }
2177
2224
 
2225
+ declare const DatabaseNotification_base: typeof Model;
2178
2226
  /**
2179
2227
  * Laravel's DatabaseNotification: one row of the `notifications` table, which the database channel writes. A UUID
2180
- * string key, `data` as an array cast and `read_at` as a datetime. `user.notifications()` returns these, newest first.
2228
+ * string key (HasUuids: a malformed id finds nothing without a query, so it is a 404), `data` as an array cast and
2229
+ * `read_at` as a datetime. `user.notifications()` returns these, newest first.
2181
2230
  */
2182
- declare class DatabaseNotification extends Model implements DatabaseNotification$1 {
2231
+ declare class DatabaseNotification extends DatabaseNotification_base implements DatabaseNotification$1 {
2183
2232
  protected table: string | undefined;
2184
2233
  protected keyType: 'int' | 'string';
2185
2234
  incrementing: boolean;
@@ -2251,6 +2300,11 @@ interface HasDatabaseNotificationsModel extends Model {
2251
2300
  */
2252
2301
  declare function HasDatabaseNotifications<TBase extends ModelConstructor>(Base: TBase): TBase & (new (...args: any[]) => HasDatabaseNotificationsModel);
2253
2302
 
2303
+ /** Laravel's HasUuids: `class Post extends HasUuids(Model) {}` keys new rows with a version 7 UUID. */
2304
+ declare function HasUuids<TBase extends ModelConstructor>(Base: TBase): TBase;
2305
+ /** Laravel's HasUlids: `class Post extends HasUlids(Model) {}` keys new rows with a lower-case ULID. */
2306
+ declare function HasUlids<TBase extends ModelConstructor>(Base: TBase): TBase;
2307
+
2254
2308
  /**
2255
2309
  * The morph map: the value stored in `*_type` columns for each model class (Laravel's Relation::morphMap()).
2256
2310
  * Without an entry the class name is stored ('Post'). Returns the current map.
@@ -2587,4 +2641,4 @@ declare class DatabaseServiceProvider extends ServiceProvider {
2587
2641
  private manager;
2588
2642
  }
2589
2643
 
2590
- export { AbstractPaginator, type Attributes, BelongsTo, BelongsToMany, Blueprint, type BlueprintCommand, Builder, type BuiltInCast, type BunDatabase, BunSqliteDatabase, type BunStatement, type CastDefinition, type CastsAttributes, type Column, type ColumnAttributes, ColumnDefinition, type ColumnInfo, type ColumnRef, type ColumnType, Connection, type ConnectionConfig, type CreateMigrationOptions, Cursor, CursorPaginator, type CursorPaginatorOptions, DB, type DatabaseCommandContext, type DatabaseConfig, DatabaseConfigError, DatabaseError, DatabaseManagerImpl, DatabaseNotification, DatabaseNotificationCollection, DatabaseNotificationsRelation, DatabaseServiceProvider, type Direction, type EagerLoadSpec, type EnumLike, Expression, Factory, type FactoryResult, Faker, FakerOverflowError, ForeignIdColumnDefinition, ForeignKeyDefinition, type GlobalScope, Grammar, HasDatabaseNotifications, type HasDatabaseNotificationsModel, type HasFactory, HasMany, HasManyThrough, HasOne, HasOneOrMany, type Having, type IndexType, InvalidCastError, JoinClause, type JoinType, LengthAwarePaginator, type LoggedQuery, LogicError, MIGRATION_CREATE_STUB, MIGRATION_STUB, MIGRATION_UPDATE_STUB, MODEL_EVENTS, type Many, MassAssignmentError, Migration, MigrationCreator, type MigrationRecord, MigrationRepository, type MigrationStatus, Migrator, type MigratorOptions, Model, type ModelBuilder, type ModelClass, type ModelConstructor, type ModelEvent, type ModelListener, ModelNotFoundError, ModelRegistry, type MorphConstraint, MorphMany, MorphOne, MorphTo, MySqlSchemaGrammar, OPERATORS, type Order, type PaginationLink, Paginator, type PaginatorOptions, Pivot, type PivotIds, PostgresSchemaGrammar, Builder$1 as QueryBuilder, QueryError, type RawResult, type ReferentialAction, type RegisteredModel, Relation, type RelationConstraint, type RelationNames, RelationNotFoundError, RelationNotLoadedError, type RelationValue, type RollbackOptions, RouteModelResolverImpl, Schema, SchemaBuilder, SchemaBuilderToken, SchemaGrammar, type Scope, type ScopeCallback, type ScopeStatic, type Scopes, Seeder, type SeederClass, type SelectColumn, SoftDeletingScope, SqliteSchemaGrammar, type State, type StateContext, type SyncChanges, TypeGenerator, type TypeGeneratorOptions, type Where, type WhereArgs, type WhereBoolean, buildQuery, castGet, castSet, columnKey, createDialect, databaseConfigDefaults, discoverFactories, enumValues, fake, formatDate, formatDateTime, generateModelTypes, getMorphAlias, getMorphedModel, guessTable, isBun, isDateCast, isEquivalent, isJsonCast, loadRelations, migrationDatePrefix, modelEventName, morphMap, mysqlPoolOptions, openSqlite, parseDateTime, prepareValue, raw, rawWithBindings, registerMigrationCommands, registerModelTypesCommand, resolveMorphClass, runSeeder, serializeDate, usePaginationResolvers };
2644
+ export { AbstractPaginator, type Attributes, BelongsTo, BelongsToMany, Blueprint, type BlueprintCommand, Builder, type BuiltInCast, type BunDatabase, BunSqliteDatabase, type BunStatement, type CastDefinition, type CastsAttributes, type Column, type ColumnAttributes, ColumnDefinition, type ColumnInfo, type ColumnRef, type ColumnType, Connection, type ConnectionConfig, type CreateMigrationOptions, Cursor, CursorPaginator, type CursorPaginatorOptions, DB, type DatabaseCommandContext, type DatabaseConfig, DatabaseConfigError, DatabaseError, DatabaseManagerImpl, DatabaseNotification, DatabaseNotificationCollection, DatabaseNotificationsRelation, DatabaseServiceProvider, type Direction, type EagerLoadSpec, type EnumLike, Expression, Factory, type FactoryResult, Faker, FakerOverflowError, ForeignIdColumnDefinition, ForeignKeyDefinition, type GlobalScope, Grammar, HasDatabaseNotifications, type HasDatabaseNotificationsModel, type HasFactory, HasMany, HasManyThrough, HasOne, HasOneOrMany, HasUlids, HasUuids, type Having, type IndexType, InvalidCastError, JoinClause, type JoinType, LengthAwarePaginator, type LoggedQuery, LogicError, MIGRATION_CREATE_STUB, MIGRATION_STUB, MIGRATION_UPDATE_STUB, MODEL_EVENTS, type Many, MassAssignmentError, Migration, MigrationCreator, type MigrationRecord, MigrationRepository, type MigrationStatus, Migrator, type MigratorOptions, Model, type ModelBuilder, type ModelClass, type ModelConstructor, type ModelEvent, type ModelListener, ModelNotFoundError, ModelRegistry, type MorphConstraint, MorphMany, MorphOne, MorphTo, MySqlSchemaGrammar, OPERATORS, type Order, type PaginationLink, Paginator, type PaginatorOptions, Pivot, type PivotIds, PostgresSchemaGrammar, Builder$1 as QueryBuilder, QueryError, type RawResult, type ReferentialAction, type RegisteredModel, Relation, type RelationConstraint, type RelationNames, RelationNotFoundError, RelationNotLoadedError, type RelationValue, type RollbackOptions, RouteModelResolverImpl, Schema, SchemaBuilder, SchemaBuilderToken, SchemaGrammar, type Scope, type ScopeCallback, type ScopeStatic, type Scopes, Seeder, type SeederClass, type SelectColumn, SoftDeletingScope, SqliteSchemaGrammar, type State, type StateContext, type SyncChanges, TypeGenerator, type TypeGeneratorOptions, type Where, type WhereArgs, type WhereBoolean, buildQuery, castGet, castSet, columnKey, createDialect, databaseConfigDefaults, discoverFactories, enumValues, fake, formatDate, formatDateTime, generateModelTypes, getMorphAlias, getMorphedModel, guessTable, isBun, isDateCast, isEquivalent, isJsonCast, loadRelations, migrationDatePrefix, modelEventName, morphMap, mysqlPoolOptions, openSqlite, parseDateTime, prepareValue, raw, rawWithBindings, registerMigrationCommands, registerModelTypesCommand, resolveMorphClass, runSeeder, serializeDate, usePaginationResolvers };