@orieljs/framework 0.1.0-alpha.14 → 0.1.0-alpha.15

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
@@ -130,7 +130,7 @@ declare class ApplicationBuilder {
130
130
  type LifecycleCallback = (app: Application$2) => void | Promise<void>;
131
131
  declare class Application$1 extends Container implements Application$2 {
132
132
  private readonly base;
133
- readonly version = "0.1.0-alpha.14";
133
+ readonly version = "0.1.0-alpha.15";
134
134
  private readonly providers;
135
135
  private readonly bootingCallbacks;
136
136
  private readonly bootedCallbacks;
@@ -1605,6 +1605,7 @@ interface BunRuntime {
1605
1605
  serve(options: {
1606
1606
  port: number;
1607
1607
  hostname: string;
1608
+ idleTimeout?: number;
1608
1609
  fetch(request: Request, server: BunServer): Promise<Response>;
1609
1610
  error(error: Error): Response;
1610
1611
  }): BunServer;
@@ -1789,6 +1790,8 @@ declare class ScheduledEventImpl implements ScheduledEvent {
1789
1790
  /** The minute slot this server won with onOneServer(): its repetitions in that minute keep it. */
1790
1791
  private wonServerSlot;
1791
1792
  private overlapExpiryMinutes;
1793
+ /** The overlap lock a run in progress holds, so schedule:work can release it when it is stopped. */
1794
+ private heldOverlapLock;
1792
1795
  private oneServer;
1793
1796
  private background;
1794
1797
  private eventName;
@@ -1905,6 +1908,11 @@ declare class ScheduledEventImpl implements ScheduledEvent {
1905
1908
  * repetition's own moment), from which the next repetition counts.
1906
1909
  */
1907
1910
  run(startedAt?: Date, checkedAt?: Date): Promise<void>;
1911
+ /**
1912
+ * @internal schedule:work, stopped by a signal while this event runs: releases the overlap lock the run holds, so the
1913
+ * next start isn't blocked until the lock expires (24 hours by default).
1914
+ */
1915
+ releaseOverlapLock(): Promise<void>;
1908
1916
  /**
1909
1917
  * Runs the event and says whether it failed. A command fails when it exits non-zero, and a closure when it throws or
1910
1918
  * returns false, as Laravel's CallbackEvent does. A job whose handler returns false failing is Oriel's own choice:
@@ -2375,6 +2383,8 @@ declare const SCHEDULE_INTERRUPT_KEY = "oriel:schedule:interrupt";
2375
2383
  interface ScheduleClock {
2376
2384
  now: () => number;
2377
2385
  sleep: (ms: number) => Promise<void>;
2386
+ /** schedule:work, once a signal stopped it: no further task starts. */
2387
+ stopped?: () => boolean;
2378
2388
  }
2379
2389
 
2380
2390
  declare class ScheduleListCommand extends Command {
@@ -2392,6 +2402,8 @@ declare class ScheduleRunCommand extends Command {
2392
2402
  handle(): Promise<number>;
2393
2403
  }
2394
2404
 
2405
+ /** Where SIGINT and SIGTERM come from: the process, or a test's emitter. */
2406
+ type Signals = Pick<NodeJS.EventEmitter, 'once' | 'off'>;
2395
2407
  interface ScheduleWorkOptions {
2396
2408
  /** Overridable so tests don't wait on a real timer. */
2397
2409
  sleep?: (ms: number) => Promise<void>;
@@ -2399,13 +2411,20 @@ interface ScheduleWorkOptions {
2399
2411
  signal?: AbortSignal;
2400
2412
  /** Overridable so tests control the clock (milliseconds since the epoch). */
2401
2413
  now?: () => number;
2414
+ /** Overridable so tests can send SIGINT and SIGTERM. */
2415
+ signals?: Signals;
2402
2416
  }
2403
2417
  declare class ScheduleWorkCommand extends Command {
2404
2418
  private readonly workOptions;
2405
2419
  readonly signature = "schedule:work";
2406
2420
  description: string;
2407
2421
  constructor(workOptions?: ScheduleWorkOptions);
2422
+ /**
2423
+ * Ctrl-C (SIGINT) or a deploy's SIGTERM stops it: no task starts after the signal, the overlap locks of the tasks still
2424
+ * running are released, and the command ends with 0. A task still running isn't waited for.
2425
+ */
2408
2426
  handle(): Promise<number>;
2427
+ private work;
2409
2428
  }
2410
2429
 
2411
2430
  interface SpawnResult {
@@ -3069,6 +3088,7 @@ declare class Connection implements DatabaseConnection {
3069
3088
  protected readonly db: Kysely<any>;
3070
3089
  private readonly context;
3071
3090
  private readonly pinned;
3091
+ private savepoints;
3072
3092
  private loggingQueries;
3073
3093
  private queryLog;
3074
3094
  constructor(name: string, config: ConnectionConfig$1);
@@ -3301,7 +3321,12 @@ declare class Grammar {
3301
3321
  parameter(value: unknown): Sql;
3302
3322
  operator(operator: string): string;
3303
3323
  columnize(columns: ReadonlyArray<string | Expression>): Sql;
3304
- compileSelect(query: Builder$1<unknown>): Sql;
3324
+ compileSelect(query: Builder$1<unknown>, extraColumn?: Sql): Sql;
3325
+ /**
3326
+ * Laravel 11's compileGroupLimit(): the query numbers its rows per `column` in its own order, and an outer query keeps
3327
+ * those inside the limit and offset, in row-number order. SQLite 3.25+, MySQL 8 and PostgreSQL have window functions.
3328
+ */
3329
+ compileGroupLimit(query: Builder$1<unknown>): Sql;
3305
3330
  /** Everything after the select list: from, joins, where, group by, having, order by, limit/offset, lock. */
3306
3331
  compileComponents(query: Builder$1<unknown>): Sql;
3307
3332
  compileOrders(query: Builder$1<unknown>): Sql | undefined;
@@ -3325,7 +3350,10 @@ declare class Grammar {
3325
3350
  compileHavings(havings: readonly Having[]): Sql | undefined;
3326
3351
  compileLimitOffset(limit: number | undefined, offset: number | undefined): Sql | undefined;
3327
3352
  compileLock(mode: 'update' | 'share' | undefined): Sql | undefined;
3328
- /** `select count(*) as aggregate …`. Orders, limit and offset are dropped; grouped or distinct queries are wrapped. */
3353
+ /**
3354
+ * `select count(*) as aggregate …`. Orders, limit and offset are dropped. Grouped or distinct queries, and those with a
3355
+ * `having` (which may name a selected alias, withCount()'s `comments_count`), are wrapped, keeping their columns.
3356
+ */
3329
3357
  compileAggregate(query: Builder$1<unknown>, fn: string, column: string | Expression): Sql;
3330
3358
  compileExists(query: Builder$1<unknown>): Sql;
3331
3359
  compileInsert(query: Builder$1<unknown>, rows: readonly Row[]): Sql;
@@ -3453,6 +3481,12 @@ declare class Builder$1<T = Row> implements QueryBuilder<T> {
3453
3481
  orders: Order[];
3454
3482
  limitValue: number | undefined;
3455
3483
  offsetValue: number | undefined;
3484
+ /** A limit and offset per value of `column` (each parent of an eager load), compiled as a window (limitPerGroup()). */
3485
+ groupLimit: {
3486
+ column: string;
3487
+ limit: number | undefined;
3488
+ offset: number | undefined;
3489
+ } | undefined;
3456
3490
  lockMode: 'update' | 'share' | undefined;
3457
3491
  constructor(connection: Connection, table?: string | Expression);
3458
3492
  from(table: string | Expression): this;
@@ -3563,6 +3597,11 @@ declare class Builder$1<T = Row> implements QueryBuilder<T> {
3563
3597
  protected newCollection(items: T[]): Collection<T>;
3564
3598
  /** The raw rows, without a Collection around them. */
3565
3599
  runSelect(): Promise<T[]>;
3600
+ /**
3601
+ * @internal Eager loading (Laravel 11's groupLimit()): the limit and offset set so far apply to each value of `column`,
3602
+ * the parent's key, instead of to the whole query. Compiled as row_number() over (partition by …).
3603
+ */
3604
+ limitPerGroup(column: string): this;
3566
3605
  first(): Promise<T | undefined>;
3567
3606
  find(id: unknown, keyName?: string): Promise<T | undefined>;
3568
3607
  value<V = unknown>(column: string): Promise<V | undefined>;
@@ -3684,6 +3723,8 @@ declare class DatabaseManagerImpl implements DatabaseManager {
3684
3723
  private readonly config;
3685
3724
  private readonly connections;
3686
3725
  private defaultName;
3726
+ /** usingConnection()'s name, for its own async context only: requests running beside it keep theirs. */
3727
+ private readonly using;
3687
3728
  /** Pass the config, or a function that reads it (the provider reads config('database') lazily). */
3688
3729
  constructor(config: DatabaseConfig | (() => DatabaseConfig));
3689
3730
  private settings;
@@ -3693,8 +3734,8 @@ declare class DatabaseManagerImpl implements DatabaseManager {
3693
3734
  /** Overrides config('database.default'); undefined clears the override. */
3694
3735
  setDefaultConnection(name: string | undefined): void;
3695
3736
  /**
3696
- * Runs `callback` with `name` as the default connection (Laravel's usingConnection()), then restores the previous
3697
- * override, or none, so the default follows config('database.default') again. Without a name, just runs it.
3737
+ * Runs `callback` with `name` as the default connection (Laravel's usingConnection()), for the callback's own async
3738
+ * context only: other requests running meanwhile keep their default. Without a name, just runs it.
3698
3739
  */
3699
3740
  usingConnection<T>(name: string | undefined, callback: () => Promise<T>): Promise<T>;
3700
3741
  /** The connections opened so far. */
@@ -3850,12 +3891,6 @@ declare class EloquentCollection<M extends Model = Model> extends Collection<M>
3850
3891
  toQuery(): Builder<M>;
3851
3892
  }
3852
3893
 
3853
- /**
3854
- * A relation is the related model's query builder, constrained to the parent: post.comments() is a
3855
- * Builder<Comment> with `where comments.post_id = ?`, so every builder method (where, orderBy, paginate, a local
3856
- * scope, …) works on it. Subclasses add eager loading (addEagerConstraints/initRelation/match) and the existence
3857
- * queries behind has()/whereHas()/withCount().
3858
- */
3859
3894
  declare abstract class Relation<R extends Model = Model, P extends Model = Model, Result = unknown> extends Builder<R> {
3860
3895
  readonly parent: P;
3861
3896
  /** The name the relation is loaded under (set when resolved by name, for eager loading and associate()). */
@@ -3866,6 +3901,20 @@ declare abstract class Relation<R extends Model = Model, P extends Model = Model
3866
3901
  protected constructor(related: R, parent: P);
3867
3902
  getParent(): P;
3868
3903
  getRelated(): R;
3904
+ /**
3905
+ * When the related table is the parent's own (a category's children, a user's followers), the existence query reads it
3906
+ * under an alias, `oriel_reserved_<n>`, so its columns aren't the outer row's. The related model takes the alias as its
3907
+ * table, so its qualified columns (keys, soft deletes, a constraint's qualifyColumn()) follow. Returns the alias, or
3908
+ * undefined when the tables differ.
3909
+ */
3910
+ protected aliasSelfTable(query: Builder<R>): string | undefined;
3911
+ /**
3912
+ * @internal After an eager load's constraint: a limit() or offset() set there applies to each parent, as in Laravel 11,
3913
+ * on the relations that know the column holding the parent's key.
3914
+ */
3915
+ limitEagerPerParent(): void;
3916
+ /** The column of the eager query holding each row's parent key; undefined where a per-parent limit makes no sense. */
3917
+ protected eagerPartitionColumn(): string | undefined;
3869
3918
  /** Subclasses call this last in their constructor: adds the per-parent constraints unless eager loading. */
3870
3919
  protected init(): void;
3871
3920
  /** The constraints for one parent: where comments.post_id = post.id. */
@@ -4076,7 +4125,11 @@ declare class Builder<M extends Model = Model> extends Builder$1<M> {
4076
4125
  pluck<V = unknown>(column: Column<M>): Promise<Collection<V>>;
4077
4126
  /** Whether `id` can't be one of the model's unique ids (not a UUID for HasUuids): it matches no row. */
4078
4127
  protected isMalformedKey(id: unknown): boolean;
4079
- /** A malformed unique id (HasUuids, HasUlids) finds nothing without a query, as route model binding does. */
4128
+ /**
4129
+ * A model by its key, or undefined; with an array of keys, the models found, as a collection (Laravel's find()). A
4130
+ * malformed unique id (HasUuids, HasUlids) finds nothing without a query, as route model binding does.
4131
+ */
4132
+ find(ids: readonly unknown[]): Promise<EloquentCollection<M>>;
4080
4133
  find(id: unknown): Promise<M | undefined>;
4081
4134
  findMany(ids: readonly unknown[]): Promise<EloquentCollection<M>>;
4082
4135
  /** find(), or ModelNotFoundError (a 404). With an array, every id must exist. */
@@ -4170,8 +4223,9 @@ interface HasRelationship {
4170
4223
  interface ForRelationship {
4171
4224
  parent: RelatedFactory | Model;
4172
4225
  relationship: string;
4173
- resolved?: Model;
4174
4226
  }
4227
+ /** The for() parents one make()/create()/raw() call has resolved: shared by that call's models, made again by the next. */
4228
+ type ResolvedParents = Map<ForRelationship, Model>;
4175
4229
  /** The builder state newInstance() copies and changes. */
4176
4230
  interface FactoryState<M extends Model> {
4177
4231
  countValue: number | undefined;
@@ -4215,7 +4269,11 @@ declare abstract class Factory<M extends Model = Model> {
4215
4269
  trashed(): this;
4216
4270
  /** Creates related models for each created model: has(Post.factory().count(3)) (relationship default: 'posts'). */
4217
4271
  has(factory: RelatedFactory, relationship?: string, pivot?: Row): this;
4218
- /** Sets a belongsTo parent: for(User.factory()) or for(user) (relationship default: 'user'). Created once. */
4272
+ /**
4273
+ * Sets a belongsTo parent: for(User.factory()) or for(user) (relationship default: 'user'). A factory parent is made
4274
+ * once per make()/create() call, for all of its models, and again by the next call, so a factory kept in a variable
4275
+ * never points at a parent an earlier test rolled back.
4276
+ */
4219
4277
  for(parent: RelatedFactory | Model, relationship?: string): this;
4220
4278
  afterMaking(callback: (model: M) => unknown): this;
4221
4279
  afterCreating(callback: (model: M) => unknown): this;
@@ -4232,7 +4290,7 @@ declare abstract class Factory<M extends Model = Model> {
4232
4290
  protected newInstance(changes: Partial<FactoryState<M>>): this;
4233
4291
  protected makeModels(attributes: Row): Promise<M[]>;
4234
4292
  /** definition() + states + overrides + for() parents, with factory and function values expanded. */
4235
- protected attributesFor(overrides: Row, index: number): Promise<Row>;
4293
+ protected attributesFor(overrides: Row, index: number, parents?: ResolvedParents): Promise<Row>;
4236
4294
  private parentAttributes;
4237
4295
  private createChildren;
4238
4296
  private relationOn;
@@ -4315,6 +4373,7 @@ declare class BelongsToMany<R extends Model, P extends Model = Model> extends Re
4315
4373
  getResults(): Promise<EloquentCollection<R>>;
4316
4374
  initRelation(models: P[], relation: string): P[];
4317
4375
  match(models: P[], results: R[], relation: string): P[];
4376
+ protected eagerPartitionColumn(): string;
4318
4377
  getRelationExistenceQuery(query: Builder<R>, _parentQuery: Builder<P>, columns?: ColumnRef[]): Builder<R>;
4319
4378
  /** Inserts pivot rows for ids (or models, or { id: attributes }), with shared extra attributes. */
4320
4379
  attach(ids: PivotIds, attributes?: Row): Promise<void>;
@@ -4409,6 +4468,7 @@ declare abstract class HasOneOrMany<R extends Model, P extends Model, Result> ex
4409
4468
  protected setForeignAttributes(model: R): R;
4410
4469
  saveMany(models: Iterable<R>): Promise<R[]>;
4411
4470
  createMany(records: Row[]): Promise<R[]>;
4471
+ protected eagerPartitionColumn(): string;
4412
4472
  getRelationExistenceQuery(query: Builder<R>, _parentQuery: Builder<P>, columns?: ColumnRef[]): Builder<R>;
4413
4473
  }
4414
4474
 
@@ -4678,6 +4738,7 @@ declare class Model implements ModelInstance {
4678
4738
  static onlyTrashed<C extends typeof Model>(this: C): ModelBuilder<C>;
4679
4739
  static withoutTrashed<C extends typeof Model>(this: C): ModelBuilder<C>;
4680
4740
  static all<C extends typeof Model>(this: C): Promise<EloquentCollection<Instance<C>>>;
4741
+ static find<C extends typeof Model>(this: C, ids: readonly unknown[]): Promise<EloquentCollection<Instance<C>>>;
4681
4742
  static find<C extends typeof Model>(this: C, id: unknown): Promise<Instance<C> | undefined>;
4682
4743
  static findOrFail<C extends typeof Model>(this: C, ids: readonly unknown[]): Promise<EloquentCollection<Instance<C>>>;
4683
4744
  static findOrFail<C extends typeof Model>(this: C, id: unknown): Promise<Instance<C>>;
@@ -6709,6 +6770,16 @@ declare class SessionGuard implements StatefulGuard {
6709
6770
  * and `before` (the password the request began with) tells when this device's remember cookie needs the new one too.
6710
6771
  */
6711
6772
  keepPasswordHash(before?: string): void;
6773
+ /**
6774
+ * @internal After the password checked out: rehash it when the hasher's settings changed (hashing.rehash_on_login).
6775
+ * attempt() and the two-factor sign-in both call it.
6776
+ */
6777
+ rehashIfRequired(user: Authenticatable, credentials: Credentials): Promise<void>;
6778
+ /**
6779
+ * @internal A saved model that is this guard's user (same class and key) with a different password becomes the user,
6780
+ * so a password saved on a freshly loaded instance, not on request().user(), is the one this session keeps.
6781
+ */
6782
+ takeSavedUser(model: unknown): void;
6712
6783
  hasUser(): boolean;
6713
6784
  setUser(user: Authenticatable): void;
6714
6785
  /** Whether the user was authenticated by the remember-me cookie. */
@@ -6742,6 +6813,12 @@ declare class AuthManager implements AuthFactory {
6742
6813
  provider(driver: string, factory: UserProviderFactory): void;
6743
6814
  /** The user provider named in config('auth.providers') (default: auth.defaults.provider ?? 'users'). */
6744
6815
  createUserProvider(name?: string): UserProvider;
6816
+ /**
6817
+ * @internal A model saved in the current scope (a request, a job): each session guard already resolved there takes it
6818
+ * when it is its signed-in user with a new password, so `auth.session` keeps the hash the request saved. Resolves no
6819
+ * guard of its own.
6820
+ */
6821
+ userSaved(model: unknown): void;
6745
6822
  /** Forget the resolved guards of the current scope (tests). */
6746
6823
  forgetGuards(): void;
6747
6824
  user<T extends Authenticatable = Authenticatable>(): Promise<T | undefined>;
@@ -7764,6 +7841,10 @@ declare class DatabaseStore implements Store {
7764
7841
  increment(key: string, by: number, attempt?: number): Promise<number>;
7765
7842
  decrement(key: string, by: number): Promise<number>;
7766
7843
  forget(key: string): Promise<boolean>;
7844
+ /**
7845
+ * Deletes this store's keys: those starting with its prefix (every row without one). The prefix's `%` and `_` are
7846
+ * escaped, so another app's keys in the same table, `appXcache_…` beside `app_cache_…`, stay.
7847
+ */
7767
7848
  flush(): Promise<boolean>;
7768
7849
  }
7769
7850
 
@@ -8390,8 +8471,14 @@ declare class CallQueuedHandler {
8390
8471
  call(job: BaseJob): Promise<void>;
8391
8472
  /** Called by BaseJob.fail() after the job was deleted. */
8392
8473
  failed(job: BaseJob, error: unknown): Promise<void>;
8393
- /** Dispatches a callback job (chain catch, batch then/catch/finally) through the Bus, or runs it inline. */
8394
- dispatchCallback(callback: Job): Promise<void>;
8474
+ /**
8475
+ * Dispatches a callback job (chain catch, batch then/catch/finally) through the Bus, or runs it inline. It goes to
8476
+ * `target`'s connection and queue (the chain's or the batch's) unless it names its own.
8477
+ */
8478
+ dispatchCallback(callback: Job, target?: {
8479
+ connection?: string;
8480
+ queue?: string;
8481
+ }): Promise<void>;
8395
8482
  private handleModelNotFound;
8396
8483
  private dispatchThroughMiddleware;
8397
8484
  private dispatchNextJobInChain;
@@ -9905,10 +9992,17 @@ type SerializedObject<T> = Simplify<{
9905
9992
  } & {
9906
9993
  [K in OptionalKeys<T> as K extends string ? K : never]?: Serialized<Exclude<Unwrap<T[K]>, undefined>>;
9907
9994
  }>;
9908
- /** A model's generated column types (types/models.d.ts declares `$attributes`), or never for anything else. */
9995
+ /**
9996
+ * A model's generated column types (types/models.d.ts declares `$attributes`) without its hidden ones (`$hidden`, which
9997
+ * toJSON() leaves out), or never for anything else.
9998
+ */
9909
9999
  type ModelAttributes<T> = T extends {
9910
10000
  $attributes?: infer A;
9911
- } ? (unknown extends A ? never : NonNullable<A>) : never;
10001
+ } ? (unknown extends A ? never : Omit<NonNullable<A>, ModelHidden<T>>) : never;
10002
+ /** The names of a model's hidden columns, from types/models.d.ts. */
10003
+ type ModelHidden<T> = T extends {
10004
+ $hidden?: infer H;
10005
+ } ? (unknown extends H ? never : Extract<NonNullable<H>, string>) : never;
9912
10006
  /** What a prop value looks like on the page. */
9913
10007
  type Serialized<T> = T extends string | number | boolean | null ? T : T extends undefined | symbol | bigint ? never : T extends Date ? string : T extends {
9914
10008
  readonly kind: string;