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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { OrielError, ModelNotFoundError as ModelNotFoundError$1, DriverName, DatabaseConnection, Row, QueryBuilder, Operator, DatabaseManager, Token, ModelInstance, Application, ConsoleKernel, RouteModelResolver, Class } from '@orieljs/contracts';
1
+ import { OrielError, ModelNotFoundError as ModelNotFoundError$1, DriverName, DatabaseConnection, Row, QueryBuilder, Operator, DatabaseManager, Token, ModelInstance, DatabaseNotification as DatabaseNotification$1, Application, ConsoleKernel, RouteModelResolver, Class } from '@orieljs/contracts';
2
2
  import { SqliteDatabase, SqliteStatement, Dialect, RawBuilder, Kysely, CompiledQuery, QueryResult } from 'kysely';
3
3
  import { Collection, LazyCollection } from '@orieljs/collections';
4
4
  import * as _orieljs_support from '@orieljs/support';
@@ -676,7 +676,10 @@ declare class LengthAwarePaginator<T> extends AbstractPaginator<T> {
676
676
  hasMorePages(): boolean;
677
677
  onLastPage(): boolean;
678
678
  nextPageUrl(): string | null;
679
- /** The page links Laravel renders: previous, the page window with '...' gaps, next. */
679
+ /**
680
+ * The page links Laravel renders: previous, the page window with '...' gaps, next. The labels are plain text
681
+ * ("« Previous", "Next »"), not Laravel's `&laquo;` entities, so a page can print them as text.
682
+ */
680
683
  linkCollection(): PaginationLink[];
681
684
  /** Laravel's UrlWindow: the first pages, the slider around the current page and the last pages, with '...' between. */
682
685
  protected elements(): Array<UrlRange | '...'>;
@@ -723,6 +726,13 @@ declare class Grammar {
723
726
  compileOrders(query: Builder$1<unknown>): Sql | undefined;
724
727
  compileWheres(wheres: readonly Where[], keyword?: 'where' | 'on'): Sql | undefined;
725
728
  compileWhere(where: Where): Sql;
729
+ /**
730
+ * whereLike() per driver, as Laravel 12's grammars: Postgres compares the column as text with ilike (like when
731
+ * case-sensitive); MySQL uses like (like binary); SQLite uses like, or glob with the pattern translated.
732
+ */
733
+ compileWhereLike(where: Extract<Where, {
734
+ type: 'like';
735
+ }>): Sql;
726
736
  compileJoin(joinClause: JoinClause): Sql;
727
737
  compileHavings(havings: readonly Having[]): Sql | undefined;
728
738
  compileLimitOffset(limit: number | undefined, offset: number | undefined): Sql | undefined;
@@ -770,6 +780,13 @@ type Where = {
770
780
  values: readonly [unknown, unknown];
771
781
  not: boolean;
772
782
  boolean: WhereBoolean;
783
+ } | {
784
+ type: 'like';
785
+ column: ColumnRef;
786
+ value: string;
787
+ caseSensitive: boolean;
788
+ not: boolean;
789
+ boolean: WhereBoolean;
773
790
  } | {
774
791
  type: 'column';
775
792
  first: ColumnRef;
@@ -812,6 +829,8 @@ type SelectColumn = ColumnRef | {
812
829
  as: string;
813
830
  };
814
831
  type NestedCallback<Q> = (query: Q) => unknown;
832
+ /** The value when()'s callback receives: the condition's type without its falsy members. */
833
+ type Truthy<V> = Exclude<V, false | 0 | 0n | '' | null | undefined>;
815
834
  /** The key a selected column comes back under: 'users.name' → 'name', 'name as n' → 'n'. */
816
835
  declare function columnKey(column: string): string;
817
836
  /**
@@ -862,6 +881,16 @@ declare class Builder$1<T = Row> implements QueryBuilder<T> {
862
881
  whereBetween(column: ColumnRef, values: readonly [unknown, unknown]): this;
863
882
  orWhereBetween(column: ColumnRef, values: readonly [unknown, unknown]): this;
864
883
  whereNotBetween(column: ColumnRef, values: readonly [unknown, unknown]): this;
884
+ /**
885
+ * Laravel's whereLike(): the value is the pattern, `%` and `_` included (`whereLike('title', `%${term}%`)`).
886
+ * Case-insensitive unless caseSensitive: ilike on Postgres, like on MySQL and SQLite (their like already ignores
887
+ * case: MySQL through the column's collation, SQLite for ASCII letters). Case-sensitive is like on Postgres,
888
+ * like binary on MySQL and glob on SQLite.
889
+ */
890
+ whereLike(column: ColumnRef, value: string, caseSensitive?: boolean, boolean?: WhereBoolean, not?: boolean): this;
891
+ orWhereLike(column: ColumnRef, value: string, caseSensitive?: boolean): this;
892
+ whereNotLike(column: ColumnRef, value: string, caseSensitive?: boolean, boolean?: WhereBoolean): this;
893
+ orWhereNotLike(column: ColumnRef, value: string, caseSensitive?: boolean): this;
865
894
  /** Compares two columns: whereColumn('updated_at', '>', 'created_at'). */
866
895
  whereColumn(first: ColumnRef, operatorOrSecond: string, second?: ColumnRef, boolean?: WhereBoolean): this;
867
896
  orWhereColumn(first: ColumnRef, operatorOrSecond: string, second?: ColumnRef): this;
@@ -896,8 +925,20 @@ declare class Builder$1<T = Row> implements QueryBuilder<T> {
896
925
  forPage(page: number, perPage?: number): this;
897
926
  lockForUpdate(): this;
898
927
  sharedLock(): this;
899
- /** Calls callback(this, value) when value is truthy (or the default callback otherwise). */
900
- when<V>(value: V, callback: (query: this, value: V) => unknown, otherwise?: (query: this, value: V) => unknown): this;
928
+ /**
929
+ * Laravel's when(): callback(query, value) runs when the value is truthy, otherwise(query, value) when it is falsy.
930
+ * A function value is called with the query first and its result is the value. Truthiness is JavaScript's, so `'0'`
931
+ * and `[]` are truthy: a `?active=0` filter applies, where Laravel would skip it. Returns the query; what the
932
+ * callbacks return is ignored.
933
+ *
934
+ * @example
935
+ * Post.query().when(request.query('q'), (query, q) => query.whereLike('title', `%${q}%`))
936
+ */
937
+ when<V>(value: (query: this) => V, callback: (query: this, value: Truthy<V>) => unknown, otherwise?: (query: this, value: V) => unknown): this;
938
+ when<V>(value: V, callback: (query: this, value: Truthy<V>) => unknown, otherwise?: (query: this, value: V) => unknown): this;
939
+ /** Laravel's unless(): when() with the condition reversed. callback(query, value) runs when the value is falsy. */
940
+ unless<V>(value: (query: this) => V, callback: (query: this, value: V) => unknown, otherwise?: (query: this, value: Truthy<V>) => unknown): this;
941
+ unless<V>(value: V, callback: (query: this, value: V) => unknown, otherwise?: (query: this, value: Truthy<V>) => unknown): this;
901
942
  tap(callback: (query: this) => unknown): this;
902
943
  get(): Promise<Collection<T>>;
903
944
  /** The raw rows, without a Collection around them. */
@@ -1218,6 +1259,10 @@ declare class Builder<M extends Model = Model> extends Builder$1<M> {
1218
1259
  whereNull(columns: Column<M> | Expression | Array<Column<M> | Expression>): this;
1219
1260
  whereNotNull(columns: Column<M> | Expression | Array<Column<M> | Expression>): this;
1220
1261
  whereBetween(column: Column<M> | Expression, values: readonly [unknown, unknown]): this;
1262
+ whereLike(column: Column<M> | Expression, value: string, caseSensitive?: boolean, boolean?: WhereBoolean, not?: boolean): this;
1263
+ orWhereLike(column: Column<M> | Expression, value: string, caseSensitive?: boolean): this;
1264
+ whereNotLike(column: Column<M> | Expression, value: string, caseSensitive?: boolean, boolean?: WhereBoolean): this;
1265
+ orWhereNotLike(column: Column<M> | Expression, value: string, caseSensitive?: boolean): this;
1221
1266
  orderBy(column: Column<M> | Expression, direction?: Direction | Uppercase<Direction>): this;
1222
1267
  /** Newest first by the model's created_at column (or the given one). */
1223
1268
  latest(column?: Column<M> | Expression): this;
@@ -1803,12 +1848,21 @@ declare class Model implements ModelInstance {
1803
1848
  /** A new query of this model, with its global scopes. */
1804
1849
  static query<C extends typeof Model>(this: C): ModelBuilder<C>;
1805
1850
  static where<C extends typeof Model>(this: C, ...args: WhereArgs<Instance<C>, ModelBuilder<C>>): ModelBuilder<C>;
1851
+ /** Post.when(request.query('q'), (query, q) => query.whereLike('title', `%${q}%`)): a new query, then when(). */
1852
+ static when<C extends typeof Model, V>(this: C, value: (query: ModelBuilder<C>) => V, callback: (query: ModelBuilder<C>, value: Truthy<V>) => unknown, otherwise?: (query: ModelBuilder<C>, value: V) => unknown): ModelBuilder<C>;
1853
+ static when<C extends typeof Model, V>(this: C, value: V, callback: (query: ModelBuilder<C>, value: Truthy<V>) => unknown, otherwise?: (query: ModelBuilder<C>, value: V) => unknown): ModelBuilder<C>;
1854
+ /** A new query, then unless(): the callback runs when the value is falsy. */
1855
+ static unless<C extends typeof Model, V>(this: C, value: (query: ModelBuilder<C>) => V, callback: (query: ModelBuilder<C>, value: V) => unknown, otherwise?: (query: ModelBuilder<C>, value: Truthy<V>) => unknown): ModelBuilder<C>;
1856
+ static unless<C extends typeof Model, V>(this: C, value: V, callback: (query: ModelBuilder<C>, value: V) => unknown, otherwise?: (query: ModelBuilder<C>, value: Truthy<V>) => unknown): ModelBuilder<C>;
1806
1857
  static whereKey<C extends typeof Model>(this: C, id: unknown): ModelBuilder<C>;
1807
1858
  static whereIn<C extends typeof Model>(this: C, column: Column<Instance<C>> | Expression, values: readonly unknown[]): ModelBuilder<C>;
1808
1859
  static whereNotIn<C extends typeof Model>(this: C, column: Column<Instance<C>> | Expression, values: readonly unknown[]): ModelBuilder<C>;
1809
1860
  static whereNull<C extends typeof Model>(this: C, column: Column<Instance<C>> | Expression): ModelBuilder<C>;
1810
1861
  static whereNotNull<C extends typeof Model>(this: C, column: Column<Instance<C>> | Expression): ModelBuilder<C>;
1811
1862
  static whereBetween<C extends typeof Model>(this: C, column: Column<Instance<C>> | Expression, values: readonly [unknown, unknown]): ModelBuilder<C>;
1863
+ /** Post.whereLike('title', `%${term}%`): case-insensitive unless caseSensitive (see the query builder's whereLike()). */
1864
+ static whereLike<C extends typeof Model>(this: C, column: Column<Instance<C>> | Expression, value: string, caseSensitive?: boolean): ModelBuilder<C>;
1865
+ static whereNotLike<C extends typeof Model>(this: C, column: Column<Instance<C>> | Expression, value: string, caseSensitive?: boolean): ModelBuilder<C>;
1812
1866
  static whereColumn<C extends typeof Model>(this: C, first: Column<Instance<C>>, operatorOrSecond: string, second?: Column<Instance<C>>): ModelBuilder<C>;
1813
1867
  static whereRaw<C extends typeof Model>(this: C, sql: string, bindings?: readonly unknown[]): ModelBuilder<C>;
1814
1868
  static select<C extends typeof Model>(this: C, ...columns: Array<Column<Instance<C>> | Expression>): ModelBuilder<C>;
@@ -2121,6 +2175,82 @@ declare class Pivot extends Model {
2121
2175
  timestamps: boolean;
2122
2176
  }
2123
2177
 
2178
+ /**
2179
+ * 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.
2181
+ */
2182
+ declare class DatabaseNotification extends Model implements DatabaseNotification$1 {
2183
+ protected table: string | undefined;
2184
+ protected keyType: 'int' | 'string';
2185
+ incrementing: boolean;
2186
+ protected guarded: string[];
2187
+ protected casts: Readonly<Record<string, CastDefinition>>;
2188
+ $attributes?: {
2189
+ id: string;
2190
+ type: string;
2191
+ notifiable_type: string;
2192
+ notifiable_id: number | string;
2193
+ data: Record<string, unknown>;
2194
+ read_at: Date | null;
2195
+ created_at: Date | null;
2196
+ updated_at: Date | null;
2197
+ };
2198
+ readonly id: string;
2199
+ readonly type: string;
2200
+ readonly notifiable_type: string;
2201
+ readonly notifiable_id: number | string;
2202
+ readonly data: Record<string, unknown>;
2203
+ read_at: Date | null;
2204
+ readonly created_at: Date | null;
2205
+ readonly updated_at: Date | null;
2206
+ /** The model the notification was sent to. */
2207
+ notifiable<R extends Model = Model>(): MorphTo<R, this>;
2208
+ /** Sets read_at to now and saves, unless it is already read. */
2209
+ markAsRead(): Promise<void>;
2210
+ /** Clears read_at and saves, unless it is already unread. */
2211
+ markAsUnread(): Promise<void>;
2212
+ read(): boolean;
2213
+ unread(): boolean;
2214
+ /** `query.read()`: only read notifications. */
2215
+ static scopeRead(query: Builder<DatabaseNotification>): Builder<DatabaseNotification>;
2216
+ /** `query.unread()`: only unread notifications. */
2217
+ static scopeUnread(query: Builder<DatabaseNotification>): Builder<DatabaseNotification>;
2218
+ }
2219
+ /** Laravel's DatabaseNotificationCollection: what `await user.notifications().get()` returns. */
2220
+ declare class DatabaseNotificationCollection extends Collection<DatabaseNotification> {
2221
+ /** Marks every notification as read (one save each, as in Laravel). */
2222
+ markAsRead(): Promise<void>;
2223
+ /** Marks every notification as unread. */
2224
+ markAsUnread(): Promise<void>;
2225
+ }
2226
+ /**
2227
+ * The relation `notifications()`, `readNotifications()` and `unreadNotifications()` return: a morphMany over
2228
+ * DatabaseNotification whose results (get(), the loaded relation, eager loads) are DatabaseNotificationCollections.
2229
+ * Every builder method works on it: paginate(), count(), update({ read_at }), where(), …
2230
+ */
2231
+ declare class DatabaseNotificationsRelation<P extends Model = Model> extends MorphMany<DatabaseNotification, P> {
2232
+ get(): Promise<DatabaseNotificationCollection>;
2233
+ getResults(): Promise<DatabaseNotificationCollection>;
2234
+ initRelation(models: P[], relation: string): P[];
2235
+ match(models: P[], results: DatabaseNotification[], relation: string): P[];
2236
+ }
2237
+
2238
+ type ModelConstructor = new (...args: any[]) => Model;
2239
+ /** What HasDatabaseNotifications adds to a model. */
2240
+ interface HasDatabaseNotificationsModel extends Model {
2241
+ /** The model's notifications, newest first: morphMany(DatabaseNotification, 'notifiable').latest(). */
2242
+ notifications(): DatabaseNotificationsRelation<this>;
2243
+ /** The read ones (read_at set). */
2244
+ readNotifications(): DatabaseNotificationsRelation<this>;
2245
+ /** The unread ones (read_at null). */
2246
+ unreadNotifications(): DatabaseNotificationsRelation<this>;
2247
+ }
2248
+ /**
2249
+ * Laravel's HasDatabaseNotifications: the notifications the database channel stored for this model, as queries.
2250
+ * `class User extends HasDatabaseNotifications(Model) {}`; apps get it through `Notifiable`.
2251
+ */
2252
+ declare function HasDatabaseNotifications<TBase extends ModelConstructor>(Base: TBase): TBase & (new (...args: any[]) => HasDatabaseNotificationsModel);
2253
+
2124
2254
  /**
2125
2255
  * The morph map: the value stored in `*_type` columns for each model class (Laravel's Relation::morphMap()).
2126
2256
  * Without an entry the class name is stored ('Post'). Returns the current map.
@@ -2438,7 +2568,11 @@ declare class RouteModelResolverImpl implements RouteModelResolver {
2438
2568
 
2439
2569
  /** Laravel 11's config/database.php defaults (the app's config/database.ts wins, key by key). */
2440
2570
  declare function databaseConfigDefaults(app: Pick<Application, 'databasePath'>): DatabaseConfig & Record<string, unknown>;
2441
- /** Points the paginators at the current request: ?page=, ?cursor=, the URL and the query string (Laravel's resolvers). */
2571
+ /**
2572
+ * Points the paginators at the current request: ?page=, ?cursor=, the URL and the query string (Laravel's resolvers).
2573
+ * A bound PaginationState is asked first for the page and the path (Livewire's WithPagination replaces Laravel's
2574
+ * resolvers the same way); what it leaves undefined comes from the request.
2575
+ */
2442
2576
  declare function usePaginationResolvers(): void;
2443
2577
  /**
2444
2578
  * Binds the database layer: the DatabaseManager (a root singleton owning the pools) behind the DB facade, the
@@ -2453,4 +2587,4 @@ declare class DatabaseServiceProvider extends ServiceProvider {
2453
2587
  private manager;
2454
2588
  }
2455
2589
 
2456
- 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, DatabaseServiceProvider, type Direction, type EagerLoadSpec, type EnumLike, Expression, Factory, type FactoryResult, Faker, FakerOverflowError, ForeignIdColumnDefinition, ForeignKeyDefinition, type GlobalScope, Grammar, 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 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 };
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 };
package/dist/index.js CHANGED
@@ -539,14 +539,17 @@ var LengthAwarePaginator = class extends AbstractPaginator {
539
539
  nextPageUrl() {
540
540
  return this.hasMorePages() ? this.url(this.currentPageValue + 1) : null;
541
541
  }
542
- /** The page links Laravel renders: previous, the page window with '...' gaps, next. */
542
+ /**
543
+ * The page links Laravel renders: previous, the page window with '...' gaps, next. The labels are plain text
544
+ * ("« Previous", "Next »"), not Laravel's `&laquo;` entities, so a page can print them as text.
545
+ */
543
546
  linkCollection() {
544
- const links = [{ url: this.previousPageUrl(), label: "&laquo; Previous", active: false }];
547
+ const links = [{ url: this.previousPageUrl(), label: "\xAB Previous", active: false }];
545
548
  for (const element of this.elements()) {
546
549
  if (element === "...") links.push({ url: null, label: "...", active: false });
547
550
  else for (const [page, url] of element) links.push({ url, label: String(page), active: page === this.currentPageValue });
548
551
  }
549
- links.push({ url: this.nextPageUrl(), label: "Next &raquo;", active: false });
552
+ links.push({ url: this.nextPageUrl(), label: "Next \xBB", active: false });
550
553
  return links;
551
554
  }
552
555
  /** Laravel's UrlWindow: the first pages, the slider around the current page and the last pages, with '...' between. */
@@ -677,6 +680,9 @@ var EMPTY = sql2.raw("");
677
680
  var isSqlFragment = (value) => typeof value === "object" && value !== null && typeof value.toOperationNode === "function";
678
681
  var join = (parts, separator = ", ") => sql2.join(parts, sql2.raw(separator));
679
682
  var clauses = (parts) => join(parts.filter((part) => part !== void 0), " ");
683
+ function likeToGlob(pattern) {
684
+ return pattern.replaceAll("*", "[*]").replaceAll("?", "[?]").replaceAll("%", "*").replaceAll("_", "?");
685
+ }
680
686
  var Grammar = class {
681
687
  constructor(driver) {
682
688
  this.driver = driver;
@@ -757,6 +763,8 @@ var Grammar = class {
757
763
  }
758
764
  case "null":
759
765
  return sql2`${this.wrap(where.column)} ${sql2.raw(where.not ? "is not null" : "is null")}`;
766
+ case "like":
767
+ return this.compileWhereLike(where);
760
768
  case "between":
761
769
  return sql2`${this.wrap(where.column)} ${sql2.raw(where.not ? "not between" : "between")} ${this.parameter(where.values[0])} and ${this.parameter(where.values[1])}`;
762
770
  case "column":
@@ -769,6 +777,18 @@ var Grammar = class {
769
777
  return rawWithBindings(where.sql, where.bindings.map((value) => this.prepare(value)));
770
778
  }
771
779
  }
780
+ /**
781
+ * whereLike() per driver, as Laravel 12's grammars: Postgres compares the column as text with ilike (like when
782
+ * case-sensitive); MySQL uses like (like binary); SQLite uses like, or glob with the pattern translated.
783
+ */
784
+ compileWhereLike(where) {
785
+ const not = where.not ? "not " : "";
786
+ const column = this.wrap(where.column);
787
+ if (this.driver === "pgsql") return sql2`${column}::text ${sql2.raw(`${not}${where.caseSensitive ? "like" : "ilike"}`)} ${this.parameter(where.value)}`;
788
+ if (this.driver === "mysql") return sql2`${column} ${sql2.raw(`${not}${where.caseSensitive ? "like binary" : "like"}`)} ${this.parameter(where.value)}`;
789
+ if (where.caseSensitive) return sql2`${column} ${sql2.raw(`${not}glob`)} ${this.parameter(likeToGlob(where.value))}`;
790
+ return sql2`${column} ${sql2.raw(`${not}like`)} ${this.parameter(where.value)}`;
791
+ }
772
792
  compileJoin(joinClause) {
773
793
  if (joinClause.joinType === "cross") return sql2`cross join ${this.wrapTable(joinClause.table)}`;
774
794
  return sql2`${sql2.raw(joinClause.joinType)} join ${this.wrapTable(joinClause.table)} ${this.compileWheres(joinClause.wheres, "on") ?? EMPTY}`;
@@ -1023,6 +1043,25 @@ var Builder = class _Builder {
1023
1043
  this.wheres.push({ type: "between", column, values, not: true, boolean: "and" });
1024
1044
  return this;
1025
1045
  }
1046
+ /**
1047
+ * Laravel's whereLike(): the value is the pattern, `%` and `_` included (`whereLike('title', `%${term}%`)`).
1048
+ * Case-insensitive unless caseSensitive: ilike on Postgres, like on MySQL and SQLite (their like already ignores
1049
+ * case: MySQL through the column's collation, SQLite for ASCII letters). Case-sensitive is like on Postgres,
1050
+ * like binary on MySQL and glob on SQLite.
1051
+ */
1052
+ whereLike(column, value, caseSensitive = false, boolean = "and", not = false) {
1053
+ this.wheres.push({ type: "like", column, value, caseSensitive, not, boolean });
1054
+ return this;
1055
+ }
1056
+ orWhereLike(column, value, caseSensitive = false) {
1057
+ return this.whereLike(column, value, caseSensitive, "or");
1058
+ }
1059
+ whereNotLike(column, value, caseSensitive = false, boolean = "and") {
1060
+ return this.whereLike(column, value, caseSensitive, boolean, true);
1061
+ }
1062
+ orWhereNotLike(column, value, caseSensitive = false) {
1063
+ return this.whereNotLike(column, value, caseSensitive, "or");
1064
+ }
1026
1065
  /** Compares two columns: whereColumn('updated_at', '>', 'created_at'). */
1027
1066
  whereColumn(first, operatorOrSecond, second, boolean = "and") {
1028
1067
  const [operator, other] = second === void 0 ? ["=", operatorOrSecond] : [operatorOrSecond, second];
@@ -1146,10 +1185,16 @@ var Builder = class _Builder {
1146
1185
  this.lockMode = "share";
1147
1186
  return this;
1148
1187
  }
1149
- /** Calls callback(this, value) when value is truthy (or the default callback otherwise). */
1150
1188
  when(value, callback, otherwise) {
1151
- if (value) callback(this, value);
1152
- else otherwise?.(this, value);
1189
+ const resolved = typeof value === "function" ? value(this) : value;
1190
+ if (resolved) callback(this, resolved);
1191
+ else otherwise?.(this, resolved);
1192
+ return this;
1193
+ }
1194
+ unless(value, callback, otherwise) {
1195
+ const resolved = typeof value === "function" ? value(this) : value;
1196
+ if (!resolved) callback(this, resolved);
1197
+ else otherwise?.(this, resolved);
1153
1198
  return this;
1154
1199
  }
1155
1200
  tap(callback) {
@@ -2880,6 +2925,18 @@ var Builder2 = class extends Builder {
2880
2925
  whereBetween(column, values) {
2881
2926
  return super.whereBetween(column, values);
2882
2927
  }
2928
+ whereLike(column, value, caseSensitive = false, boolean = "and", not = false) {
2929
+ return super.whereLike(column, value, caseSensitive, boolean, not);
2930
+ }
2931
+ orWhereLike(column, value, caseSensitive = false) {
2932
+ return super.orWhereLike(column, value, caseSensitive);
2933
+ }
2934
+ whereNotLike(column, value, caseSensitive = false, boolean = "and") {
2935
+ return super.whereNotLike(column, value, caseSensitive, boolean);
2936
+ }
2937
+ orWhereNotLike(column, value, caseSensitive = false) {
2938
+ return super.orWhereNotLike(column, value, caseSensitive);
2939
+ }
2883
2940
  orderBy(column, direction = "asc") {
2884
2941
  return super.orderBy(column, direction);
2885
2942
  }
@@ -4494,6 +4551,14 @@ var Model = class _Model {
4494
4551
  const query = this.query();
4495
4552
  return Reflect.apply(query.where, query, args);
4496
4553
  }
4554
+ static when(...args) {
4555
+ const query = this.query();
4556
+ return Reflect.apply(query.when, query, args);
4557
+ }
4558
+ static unless(...args) {
4559
+ const query = this.query();
4560
+ return Reflect.apply(query.unless, query, args);
4561
+ }
4497
4562
  static whereKey(id) {
4498
4563
  return this.query().whereKey(id);
4499
4564
  }
@@ -4512,6 +4577,13 @@ var Model = class _Model {
4512
4577
  static whereBetween(column, values) {
4513
4578
  return this.query().whereBetween(column, values);
4514
4579
  }
4580
+ /** Post.whereLike('title', `%${term}%`): case-insensitive unless caseSensitive (see the query builder's whereLike()). */
4581
+ static whereLike(column, value, caseSensitive = false) {
4582
+ return this.query().whereLike(column, value, caseSensitive);
4583
+ }
4584
+ static whereNotLike(column, value, caseSensitive = false) {
4585
+ return this.query().whereNotLike(column, value, caseSensitive);
4586
+ }
4515
4587
  static whereColumn(first, operatorOrSecond, second) {
4516
4588
  return this.query().whereColumn(first, operatorOrSecond, second);
4517
4589
  }
@@ -5471,6 +5543,95 @@ var Pivot = class extends Model {
5471
5543
  timestamps = false;
5472
5544
  };
5473
5545
 
5546
+ // Eloquent/DatabaseNotification.ts
5547
+ import { Collection as Collection12 } from "@orieljs/collections";
5548
+ var DatabaseNotification = class extends Model {
5549
+ table = "notifications";
5550
+ keyType = "string";
5551
+ incrementing = false;
5552
+ guarded = [];
5553
+ casts = { data: "array", read_at: "datetime" };
5554
+ /** The model the notification was sent to. */
5555
+ notifiable() {
5556
+ return this.morphTo("notifiable");
5557
+ }
5558
+ /** Sets read_at to now and saves, unless it is already read. */
5559
+ async markAsRead() {
5560
+ if (this.unread()) await this.forceFill({ read_at: this.freshTimestamp() }).save();
5561
+ }
5562
+ /** Clears read_at and saves, unless it is already unread. */
5563
+ async markAsUnread() {
5564
+ if (this.read()) await this.forceFill({ read_at: null }).save();
5565
+ }
5566
+ read() {
5567
+ return this.read_at !== null && this.read_at !== void 0;
5568
+ }
5569
+ unread() {
5570
+ return !this.read();
5571
+ }
5572
+ /** `query.read()`: only read notifications. */
5573
+ static scopeRead(query) {
5574
+ return query.whereNotNull("read_at");
5575
+ }
5576
+ /** `query.unread()`: only unread notifications. */
5577
+ static scopeUnread(query) {
5578
+ return query.whereNull("read_at");
5579
+ }
5580
+ };
5581
+ var DatabaseNotificationCollection = class extends Collection12 {
5582
+ /** Marks every notification as read (one save each, as in Laravel). */
5583
+ async markAsRead() {
5584
+ for (const notification of this.all()) await notification.markAsRead();
5585
+ }
5586
+ /** Marks every notification as unread. */
5587
+ async markAsUnread() {
5588
+ for (const notification of this.all()) await notification.markAsUnread();
5589
+ }
5590
+ };
5591
+ var DatabaseNotificationsRelation = class extends MorphMany {
5592
+ async get() {
5593
+ return new DatabaseNotificationCollection(await this.runSelect());
5594
+ }
5595
+ async getResults() {
5596
+ const key = this.getParentKey();
5597
+ return key === null || key === void 0 ? new DatabaseNotificationCollection() : this.get();
5598
+ }
5599
+ initRelation(models, relation) {
5600
+ for (const model of models) model.setRelation(relation, new DatabaseNotificationCollection());
5601
+ return models;
5602
+ }
5603
+ match(models, results, relation) {
5604
+ const dictionary = this.buildDictionary(results);
5605
+ for (const model of models) {
5606
+ model.setRelation(relation, new DatabaseNotificationCollection(dictionary.get(String(model.getAttribute(this.localKey))) ?? []));
5607
+ }
5608
+ return models;
5609
+ }
5610
+ };
5611
+
5612
+ // Eloquent/HasDatabaseNotifications.ts
5613
+ function HasDatabaseNotifications(Base) {
5614
+ class WithDatabaseNotifications extends Base {
5615
+ notifications() {
5616
+ const related = this.newRelatedInstance(DatabaseNotification);
5617
+ return new DatabaseNotificationsRelation(
5618
+ related,
5619
+ this,
5620
+ related.qualifyColumn("notifiable_type"),
5621
+ related.qualifyColumn("notifiable_id"),
5622
+ this.getKeyName()
5623
+ ).latest();
5624
+ }
5625
+ readNotifications() {
5626
+ return this.notifications().whereNotNull("read_at");
5627
+ }
5628
+ unreadNotifications() {
5629
+ return this.notifications().whereNull("read_at");
5630
+ }
5631
+ }
5632
+ return WithDatabaseNotifications;
5633
+ }
5634
+
5474
5635
  // Migrations/Migration.ts
5475
5636
  var Migration = class {
5476
5637
  /** The connection to run on (default: the default connection). */
@@ -6476,9 +6637,10 @@ import {
6476
6637
  ConsoleKernel,
6477
6638
  DatabaseManager as DatabaseManager3,
6478
6639
  HttpRequest,
6640
+ PaginationState,
6479
6641
  RouteModelResolver
6480
6642
  } from "@orieljs/contracts";
6481
- import { currentContainer as currentContainer4 } from "@orieljs/container";
6643
+ import { BindingResolutionError, currentContainer as currentContainer4 } from "@orieljs/container";
6482
6644
  import { ServiceProvider } from "@orieljs/support";
6483
6645
  var env = (key, fallback) => {
6484
6646
  const value = process.env[key];
@@ -6535,9 +6697,21 @@ function currentRequest() {
6535
6697
  return void 0;
6536
6698
  }
6537
6699
  }
6700
+ function paginationState() {
6701
+ const container = currentContainer4();
6702
+ if (!container?.bound(PaginationState)) return void 0;
6703
+ try {
6704
+ return container.make(PaginationState);
6705
+ } catch (error) {
6706
+ if (error instanceof BindingResolutionError) return void 0;
6707
+ throw error;
6708
+ }
6709
+ }
6538
6710
  function usePaginationResolvers() {
6539
- AbstractPaginator.currentPathResolver = () => currentRequest()?.url() ?? "/";
6711
+ AbstractPaginator.currentPathResolver = () => paginationState()?.currentPath() ?? currentRequest()?.url() ?? "/";
6540
6712
  AbstractPaginator.currentPageResolver = (pageName) => {
6713
+ const state = paginationState()?.currentPage(pageName);
6714
+ if (state !== void 0) return state;
6541
6715
  const page = Number(currentRequest()?.input(pageName));
6542
6716
  return Number.isInteger(page) && page >= 1 ? page : 1;
6543
6717
  };
@@ -6587,6 +6761,9 @@ export {
6587
6761
  DatabaseConfigError,
6588
6762
  DatabaseError,
6589
6763
  DatabaseManagerImpl,
6764
+ DatabaseNotification,
6765
+ DatabaseNotificationCollection,
6766
+ DatabaseNotificationsRelation,
6590
6767
  DatabaseServiceProvider,
6591
6768
  Expression,
6592
6769
  Factory,
@@ -6595,6 +6772,7 @@ export {
6595
6772
  ForeignIdColumnDefinition,
6596
6773
  ForeignKeyDefinition,
6597
6774
  Grammar,
6775
+ HasDatabaseNotifications,
6598
6776
  HasMany,
6599
6777
  HasManyThrough,
6600
6778
  HasOne,