@getstrata/core 0.3.9 → 0.5.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.
Files changed (116) hide show
  1. package/dist/bootstrap/httpKernel.d.ts +2 -0
  2. package/dist/config/queue.d.ts +8 -0
  3. package/dist/config/rateLimit.d.ts +2 -1
  4. package/dist/core/database/baseRepository.d.ts +16 -4
  5. package/dist/core/database/boundConnection.d.ts +5 -0
  6. package/dist/core/database/index.d.ts +10 -4
  7. package/dist/core/database/migrations/advisoryLock.d.ts +6 -0
  8. package/dist/core/database/migrations/runner.d.ts +8 -2
  9. package/dist/core/database/migrations/types.d.ts +1 -0
  10. package/dist/core/database/model.d.ts +46 -17
  11. package/dist/core/database/query.d.ts +26 -14
  12. package/dist/core/database/relationships.d.ts +32 -2
  13. package/dist/core/database/repositoryConnection.d.ts +4 -0
  14. package/dist/core/database/repositoryQuery.d.ts +16 -1
  15. package/dist/core/database/schema/blueprint.d.ts +47 -0
  16. package/dist/core/database/schema/columnDefinition.d.ts +36 -0
  17. package/dist/core/database/schema/driver.d.ts +8 -0
  18. package/dist/core/database/schema/errors.d.ts +4 -0
  19. package/dist/core/database/schema/grammars/compileStatements.d.ts +8 -0
  20. package/dist/core/database/schema/grammars/createGrammar.d.ts +4 -0
  21. package/dist/core/database/schema/grammars/grammar.d.ts +10 -0
  22. package/dist/core/database/schema/grammars/index.d.ts +7 -0
  23. package/dist/core/database/schema/grammars/mysqlGrammar.d.ts +2 -0
  24. package/dist/core/database/schema/grammars/postgresGrammar.d.ts +2 -0
  25. package/dist/core/database/schema/grammars/sqliteGrammar.d.ts +2 -0
  26. package/dist/core/database/schema/index.d.ts +12 -0
  27. package/dist/core/database/schema/schema.d.ts +21 -0
  28. package/dist/core/database/seeders/runner.d.ts +6 -0
  29. package/dist/core/database/seeders/types.d.ts +8 -0
  30. package/dist/core/database/types.d.ts +39 -2
  31. package/dist/core/database/whereBuilder.d.ts +17 -0
  32. package/dist/core/http/index.d.ts +1 -1
  33. package/dist/core/http/securedRouteModelBinding.d.ts +2 -1
  34. package/dist/core/lifecycle/gracefulShutdown.d.ts +6 -0
  35. package/dist/core/pagination/index.d.ts +11 -1
  36. package/dist/core/queue/failedJobRepository.d.ts +6 -0
  37. package/dist/core/queue/failedJobService.d.ts +15 -0
  38. package/dist/core/queue/failedJobTable.d.ts +3 -0
  39. package/dist/core/queue/jobRegistry.d.ts +14 -0
  40. package/dist/core/queue/jobRunner.d.ts +9 -0
  41. package/dist/core/queue/publicQueue.d.ts +15 -0
  42. package/dist/core/queue/redisQueue.d.ts +29 -0
  43. package/dist/core/queue/resilientQueue.d.ts +9 -0
  44. package/dist/core/queue/types.d.ts +8 -0
  45. package/dist/core/scheduler/schedule.d.ts +15 -0
  46. package/dist/entries/auth/accessControl.js +113 -0
  47. package/dist/entries/auth/authContext.js +15 -0
  48. package/dist/entries/auth/guard.js +2870 -0
  49. package/dist/entries/auth/membershipContext.js +276 -0
  50. package/dist/entries/auth/membershipScope.js +390 -0
  51. package/dist/entries/auth/membershipService.js +477 -0
  52. package/dist/entries/auth/oauth/oidcProvider.js +49 -0
  53. package/dist/entries/auth/oauth/providers.js +71 -0
  54. package/dist/entries/auth/oauth/samlProvider.js +26 -0
  55. package/dist/entries/auth/oauth/types.js +1 -0
  56. package/dist/entries/auth/password.js +15 -0
  57. package/dist/entries/auth/policy.js +134 -0
  58. package/dist/entries/auth/sessionCookie.js +75 -0
  59. package/dist/entries/auth/tokenHash.js +17 -0
  60. package/dist/entries/cache/tags.js +13 -0
  61. package/dist/entries/crypto/fieldEncryption.js +93 -0
  62. package/dist/entries/crypto/mfaSecret.js +105 -0
  63. package/dist/entries/database/factory.js +17 -0
  64. package/dist/entries/database/seeders.js +30 -0
  65. package/dist/entries/database/types.js +1 -0
  66. package/dist/entries/database.js +2218 -0
  67. package/dist/entries/errors/http.js +78 -0
  68. package/dist/entries/http/contentNegotiation.js +26 -0
  69. package/dist/entries/http/csrfToken.js +147 -0
  70. package/dist/entries/http/etag.js +170 -0
  71. package/dist/entries/http/flashSession.js +106 -0
  72. package/dist/entries/http/middleware.js +68 -0
  73. package/dist/entries/http/parseFormBody.js +88 -0
  74. package/dist/entries/http/requestMetaContext.js +18 -0
  75. package/dist/entries/http/resources.js +19 -0
  76. package/dist/entries/http/webErrorResponse.js +3143 -0
  77. package/dist/entries/http/webFormRequest.js +293 -0
  78. package/dist/entries/http.js +3924 -0
  79. package/dist/entries/jobs/dispatchWebhookJob.js +342 -0
  80. package/dist/entries/lifecycle/gracefulShutdown.js +50 -0
  81. package/dist/entries/metrics/prometheus.js +70 -0
  82. package/dist/entries/pagination.js +14 -0
  83. package/dist/entries/queue/createAppQueue.js +2848 -0
  84. package/dist/entries/queue/failedJobService.js +38 -0
  85. package/dist/entries/queue/jobRegistry.js +32 -0
  86. package/dist/entries/queue/jobRunner.js +75 -0
  87. package/dist/entries/queue/publicQueue.js +2476 -0
  88. package/dist/entries/queue/queueMetrics.js +2898 -0
  89. package/dist/entries/queue/types.js +1 -0
  90. package/dist/entries/security/oauthState.js +75 -0
  91. package/dist/entries/security/publicReads.js +33 -0
  92. package/dist/entries/security/safeUrl.js +143 -0
  93. package/dist/entries/security/securityEvents.js +41 -0
  94. package/dist/entries/security/stripeWebhook.js +115 -0
  95. package/dist/entries/security/tokenExpiry.js +16 -0
  96. package/dist/entries/security/totp.js +51 -0
  97. package/dist/entries/storage/storage.js +123 -0
  98. package/dist/entries/tenant/tenantContext.js +30 -0
  99. package/dist/entries/tenant/tenantMiddleware.js +312 -0
  100. package/dist/entries/tracing/traceContext.js +15 -0
  101. package/dist/entries/validation/rules.js +232 -0
  102. package/dist/entries/view.js +3072 -0
  103. package/dist/framework/public-api.d.ts +65 -38
  104. package/dist/index.js +3213 -281
  105. package/dist/modules/user/apiTokenRepository.d.ts +1 -1
  106. package/dist/modules/user/apiTokenTable.d.ts +1 -1
  107. package/dist/modules/user/authService.d.ts +1 -1
  108. package/dist/modules/user/notificationRepository.d.ts +1 -1
  109. package/dist/modules/user/notificationService.d.ts +1 -1
  110. package/dist/modules/user/notificationTable.d.ts +1 -1
  111. package/dist/modules/user/oauthIdentityRepository.d.ts +2 -2
  112. package/dist/modules/user/provider.d.ts +1 -1
  113. package/dist/modules/user/repository.d.ts +1 -1
  114. package/dist/modules/user/table.d.ts +1 -1
  115. package/dist/modules/user/tokenService.d.ts +1 -1
  116. package/package.json +289 -3
@@ -20,6 +20,8 @@ declare class HttpKernel {
20
20
  wrapAbility(ability: string, handler: RouteHandler): RouteHandler;
21
21
  wrapPolicy(resource: string, action: keyof Policy, handler: RouteHandler): RouteHandler;
22
22
  wrapLogin(handler: RouteHandler): RouteHandler;
23
+ wrapRegister(handler: RouteHandler): RouteHandler;
24
+ private wrapThrottle;
23
25
  }
24
26
  declare function createHttpKernel(dependencies: AppDependencies): HttpKernel;
25
27
  export type { MiddlewareGroupName };
@@ -0,0 +1,8 @@
1
+ interface QueueConfig {
2
+ driver: "sync" | "async" | "redis";
3
+ maxAttempts: number;
4
+ backoffMs: number;
5
+ }
6
+ declare const queueConfig: QueueConfig;
7
+ export type { QueueConfig };
8
+ export { queueConfig };
@@ -5,5 +5,6 @@ interface LoginRateLimitConfig {
5
5
  declare const LOCAL_LOGIN_RATE_LIMIT: LoginRateLimitConfig;
6
6
  declare const PRODUCTION_LOGIN_RATE_LIMIT: LoginRateLimitConfig;
7
7
  declare function resolveLoginRateLimit(): LoginRateLimitConfig;
8
+ declare function resolveRegisterRateLimit(): LoginRateLimitConfig;
8
9
  export type { LoginRateLimitConfig };
9
- export { LOCAL_LOGIN_RATE_LIMIT, PRODUCTION_LOGIN_RATE_LIMIT, resolveLoginRateLimit };
10
+ export { LOCAL_LOGIN_RATE_LIMIT, PRODUCTION_LOGIN_RATE_LIMIT, resolveLoginRateLimit, resolveRegisterRateLimit, };
@@ -1,8 +1,12 @@
1
- import { type PaginatedResult } from "../pagination/index.ts";
1
+ import { type CursorPaginatedResult, type PaginatedResult } from "../pagination/index.ts";
2
2
  import { type BelongsToRelation, type HasManyRelation } from "./relationships.ts";
3
3
  import { RepositoryQuery } from "./repositoryQuery.ts";
4
4
  import type { TableDefinition } from "./table.ts";
5
5
  import type { MutationValues, QueryOptions, QueryWhere, UpdateValues } from "./types.ts";
6
+ import type { WhereNode } from "./whereBuilder.ts";
7
+ type ExtendedQueryOptions<TEntity extends object> = QueryOptions<TEntity> & {
8
+ whereNodes?: WhereNode<TEntity>[];
9
+ };
6
10
  interface DatabaseConnection {
7
11
  unsafe<T>(query: string, params?: readonly unknown[]): Promise<T[]>;
8
12
  }
@@ -11,11 +15,18 @@ declare class BaseRepository<TEntity extends object, PrimaryKey extends keyof TE
11
15
  protected readonly table: TableDefinition<TEntity, PrimaryKey>;
12
16
  protected readonly connection: DatabaseConnection;
13
17
  constructor(table: TableDefinition<TEntity, PrimaryKey>, connection?: DatabaseConnection);
14
- findAll(options?: QueryOptions<TEntity>): Promise<TEntity[]>;
18
+ findAll(options?: ExtendedQueryOptions<TEntity>): Promise<TEntity[]>;
15
19
  paginate(options: {
16
20
  page: number;
17
21
  perPage: number;
18
- } & Omit<QueryOptions<TEntity>, "limit" | "offset">): Promise<PaginatedResult<TEntity>>;
22
+ } & Omit<ExtendedQueryOptions<TEntity>, "limit" | "offset">): Promise<PaginatedResult<TEntity>>;
23
+ chunk(count: number, callback: (rows: TEntity[]) => Promise<boolean | void>, options?: Omit<ExtendedQueryOptions<TEntity>, "limit" | "offset">): Promise<void>;
24
+ cursorPaginate(options: {
25
+ perPage: number;
26
+ cursor?: TEntity[PrimaryKey];
27
+ cursorColumn?: PrimaryKey;
28
+ direction?: "asc" | "desc";
29
+ } & Omit<ExtendedQueryOptions<TEntity>, "limit" | "offset">): Promise<CursorPaginatedResult<TEntity, TEntity[PrimaryKey]>>;
19
30
  findById(id: TEntity[PrimaryKey]): Promise<TEntity | null>;
20
31
  findByIdOrThrow(id: TEntity[PrimaryKey], errorFactory?: ErrorFactory<TEntity[PrimaryKey]>): Promise<TEntity>;
21
32
  findByIds(ids: readonly TEntity[PrimaryKey][]): Promise<TEntity[]>;
@@ -29,9 +40,10 @@ declare class BaseRepository<TEntity extends object, PrimaryKey extends keyof TE
29
40
  restoreById(id: TEntity[PrimaryKey]): Promise<TEntity | null>;
30
41
  withConnection(connection: DatabaseConnection): this;
31
42
  getConnection(): DatabaseConnection;
43
+ getTable(): TableDefinition<TEntity, PrimaryKey>;
32
44
  query(where?: QueryWhere<TEntity>): RepositoryQuery<TEntity, PrimaryKey>;
33
45
  protected findWhere(where: QueryWhere<TEntity>, options?: Omit<QueryOptions<TEntity>, "where">): Promise<TEntity[]>;
34
- protected countWhere(where?: QueryWhere<TEntity>, options?: Pick<QueryOptions<TEntity>, "withTrashed" | "onlyTrashed">): Promise<number>;
46
+ protected countWhere(where?: QueryWhere<TEntity>, options?: Pick<QueryOptions<TEntity>, "withTrashed" | "onlyTrashed" | "joins" | "groupBy">, whereNodes?: readonly WhereNode<TEntity>[]): Promise<number>;
35
47
  protected averageColumn(column: keyof TEntity & string, where?: QueryWhere<TEntity>): Promise<number>;
36
48
  protected averageExpression(expression: string, alias: string, where?: QueryWhere<TEntity>): Promise<number>;
37
49
  protected pluckNumberValues(expression: string, alias: string, options?: QueryOptions<TEntity>): Promise<number[]>;
@@ -0,0 +1,5 @@
1
+ import type { DatabaseConnection } from "./baseRepository";
2
+ declare function bindDatabaseConnection(connection: DatabaseConnection): void;
3
+ declare function getBoundDatabaseConnection(): DatabaseConnection | null;
4
+ declare function resetBoundDatabaseConnection(): void;
5
+ export { bindDatabaseConnection, getBoundDatabaseConnection, resetBoundDatabaseConnection };
@@ -2,11 +2,17 @@ export type { DatabaseConnection } from "./baseRepository.ts";
2
2
  export { default as BaseRepository } from "./baseRepository.ts";
3
3
  export { createDatabaseConnection } from "./connection.ts";
4
4
  export { mapDatabaseError, withDatabaseErrorHandling } from "./errors.ts";
5
- export { buildCountQuery, buildDeleteByIdQuery, buildGroupedCountQuery, buildInsertQuery, buildOrderByClause, buildProjectionQuery, buildQueryWhereClause, buildRestoreByIdQuery, buildSelectQuery, buildSoftDeleteByIdQuery, buildUpdateQuery, buildWhereClause, qualifyColumn, quoteIdentifier, resolveSoftDeleteColumn, } from "./query.ts";
6
- export type { BelongsToRelation, HasManyRelation } from "./relationships.ts";
7
- export { belongsTo, hasMany, indexBelongsToRelation, indexHasManyRelation, } from "./relationships.ts";
5
+ export type { CastType, GlobalScopeFn, ModelConstructor } from "./model.ts";
6
+ export { applyCasts, dehydrateValue, filterMassAssignable, hydrateValue, Model, registerModelRepository, } from "./model.ts";
7
+ export { buildAdvancedWhereClause, buildCountQuery, buildDeleteByIdQuery, buildGroupedCountQuery, buildInsertQuery, buildJoinClause, buildOrderByClause, buildProjectionQuery, buildQueryWhereClause, buildRestoreByIdQuery, buildSelectQuery, buildSoftDeleteByIdQuery, buildUpdateQuery, buildWhereClause, parseQualifiedColumn, qualifyColumn, quoteIdentifier, resolveQualifiedColumn, resolveSoftDeleteColumn, } from "./query.ts";
8
+ export type { BelongsToManyRelation, BelongsToRelation, HasManyRelation, HasOneRelation, } from "./relationships.ts";
9
+ export { belongsTo, belongsToMany, hasMany, hasOne, indexBelongsToManyRelation, indexBelongsToRelation, indexHasManyRelation, indexHasOneRelation, } from "./relationships.ts";
8
10
  export { RepositoryQuery } from "./repositoryQuery.ts";
11
+ export type { BlueprintAction, BlueprintCallback, ColumnKind, DatabaseDriver, ForeignKeyOptions, Grammar, IndexDefinition, IndexKind, ResolveDatabaseDriverOptions, SchemaBuilder, } from "./schema/index.ts";
12
+ export { Blueprint, ColumnDefinition, compileBlueprint, createSchemaBuilder, ForeignIdColumnDefinition, grammarForDriver, inferReferencedTable, MySqlGrammar, PostgresGrammar, resolveDatabaseDriver, Schema, SqliteGrammar, UnsupportedSchemaFeatureError, } from "./schema/index.ts";
9
13
  export type { TableDefinition } from "./table.ts";
10
14
  export { defineTable } from "./table.ts";
11
15
  export { runInTransaction } from "./transaction.ts";
12
- export type { DatabaseComparable, DatabaseScalar, MutationValues, QueryFilterValue, QueryOperator, QueryOptions, QueryOrder, QueryWhere, UpdateValues, } from "./types.ts";
16
+ export type { DatabaseComparable, DatabaseScalar, MutationValues, QueryFilterValue, QueryJoin, QueryJoinOn, QueryOperator, QueryOptions, QueryOrder, QuerySelectItem, QueryWhere, UpdateValues, } from "./types.ts";
17
+ export type { WhereNode } from "./whereBuilder.ts";
18
+ export { WhereBuilder } from "./whereBuilder.ts";
@@ -0,0 +1,6 @@
1
+ declare const MIGRATION_LOCK_KEY = 42424242;
2
+ type LockableDatabase = {
3
+ unsafe<T>(query: string, params?: readonly unknown[]): Promise<T[]>;
4
+ };
5
+ declare function withMigrationLock<T>(db: LockableDatabase, callback: () => Promise<T>, lockKey?: number): Promise<T>;
6
+ export { MIGRATION_LOCK_KEY, withMigrationLock };
@@ -1,4 +1,4 @@
1
- import type { Migration, MigrationDatabase, MigrationStatus } from "./types";
1
+ import type { Migration, MigrationDatabase, MigrationStatus } from "./types.ts";
2
2
  type AppliedMigrationRow = {
3
3
  name: string;
4
4
  batch: number | string;
@@ -7,13 +7,19 @@ declare function ensureMigrationsTable(db: MigrationDatabase): Promise<void>;
7
7
  declare function getAppliedMigrations(db: MigrationDatabase): Promise<AppliedMigrationRow[]>;
8
8
  declare function loadMigrationsFromDirectory(directory: string): Promise<Migration[]>;
9
9
  declare function getMigrationStatus(db: MigrationDatabase, migrations: Migration[]): Promise<MigrationStatus[]>;
10
+ declare function runPendingMigrations(db: MigrationDatabase, migrations: Migration[], options?: {
11
+ onMigration?: (name: string) => void;
12
+ }): Promise<number>;
10
13
  declare function migrateDatabase(db: MigrationDatabase, migrations: Migration[], options?: {
14
+ advisoryLock?: boolean;
11
15
  onMigration?: (name: string) => void;
12
16
  }): Promise<number>;
13
17
  declare function rollbackDatabase(db: MigrationDatabase, migrations: Migration[], options?: {
14
18
  onMigration?: (name: string) => void;
15
19
  }): Promise<number>;
16
20
  declare function freshDatabase(db: MigrationDatabase, migrations: Migration[], options?: {
21
+ advisoryLock?: boolean;
17
22
  onMigration?: (name: string) => void;
18
23
  }): Promise<void>;
19
- export { ensureMigrationsTable, freshDatabase, getAppliedMigrations, getMigrationStatus, loadMigrationsFromDirectory, migrateDatabase, rollbackDatabase, };
24
+ export { withMigrationLock } from "./advisoryLock.ts";
25
+ export { ensureMigrationsTable, freshDatabase, getAppliedMigrations, getMigrationStatus, loadMigrationsFromDirectory, migrateDatabase, rollbackDatabase, runPendingMigrations, };
@@ -1,5 +1,6 @@
1
1
  interface MigrationDatabase {
2
2
  unsafe<T = unknown>(query: string, params?: readonly unknown[]): Promise<T[]>;
3
+ schema?: import("../schema/schema.ts").SchemaBuilder;
3
4
  }
4
5
  interface Migration {
5
6
  name: string;
@@ -1,28 +1,57 @@
1
- import type BaseRepository from "./baseRepository";
2
- import type { BelongsToRelation, HasManyRelation } from "./relationships";
3
- import type { RepositoryQuery } from "./repositoryQuery";
4
- import type { QueryOptions, QueryWhere } from "./types";
5
- interface ModelConstructor<TEntity extends object, PrimaryKey extends keyof TEntity & string, TModel extends Model<TEntity, PrimaryKey>> {
6
- new (attributes: TEntity, repository: BaseRepository<TEntity, PrimaryKey>): TModel;
1
+ import type BaseRepository from "./baseRepository.ts";
2
+ import type { BelongsToManyRelation, BelongsToRelation, HasManyRelation, HasOneRelation } from "./relationships.ts";
3
+ import type { RepositoryQuery } from "./repositoryQuery.ts";
4
+ import type { QueryOptions, QueryWhere } from "./types.ts";
5
+ type CastType = "date" | "datetime" | "json" | "bool" | "boolean";
6
+ type LoadedAttributes = Record<string, unknown>;
7
+ type ModelCasts = Partial<Record<string, CastType>>;
8
+ type GlobalScopeFn<TEntity extends object, PrimaryKey extends keyof TEntity & string> = (query: RepositoryQuery<TEntity, PrimaryKey>) => RepositoryQuery<TEntity, PrimaryKey>;
9
+ type ModelClassType<TEntity extends object, PrimaryKey extends keyof TEntity & string> = typeof Model & (new (attributes: TEntity, repository: BaseRepository<TEntity, PrimaryKey>, exists?: boolean) => Model<TEntity, PrimaryKey>);
10
+ interface ModelConstructor<TEntity extends object, PrimaryKey extends keyof TEntity & string, TModel extends Model<TEntity, PrimaryKey>> extends ModelClassType<TEntity, PrimaryKey> {
11
+ new (attributes: TEntity, repository: BaseRepository<TEntity, PrimaryKey>, exists?: boolean): TModel;
7
12
  }
13
+ declare function hydrateValue(value: unknown, cast: CastType): unknown;
14
+ declare function dehydrateValue(value: unknown, cast: CastType): unknown;
15
+ declare function filterMassAssignable(fillable: readonly string[] | undefined, guarded: readonly string[] | true | undefined, input: LoadedAttributes): LoadedAttributes;
16
+ declare function applyCasts(values: LoadedAttributes, casts: ModelCasts, direction: "hydrate" | "dehydrate"): LoadedAttributes;
8
17
  declare class Model<TEntity extends object, PrimaryKey extends keyof TEntity & string> {
9
- protected readonly attributes: TEntity;
18
+ protected attributes: TEntity;
10
19
  protected readonly repository: BaseRepository<TEntity, PrimaryKey>;
11
- constructor(attributes: TEntity, repository: BaseRepository<TEntity, PrimaryKey>);
20
+ static $fillable?: readonly string[];
21
+ static $guarded?: readonly string[] | true;
22
+ static $casts: ModelCasts;
23
+ static $timestamps: boolean;
24
+ private _exists;
25
+ constructor(attributes: TEntity, repository: BaseRepository<TEntity, PrimaryKey>, exists?: boolean);
26
+ get $exists(): boolean;
12
27
  get<K extends keyof TEntity>(key: K): TEntity[K];
13
28
  get id(): TEntity[PrimaryKey];
14
29
  toObject(): TEntity;
15
30
  protected primaryKey(): PrimaryKey;
16
- static repository<TEntity extends object, PrimaryKey extends keyof TEntity & string, TModel extends Model<TEntity, PrimaryKey>>(this: ModelConstructor<TEntity, PrimaryKey, TModel>): BaseRepository<TEntity, PrimaryKey>;
17
- static query<TEntity extends object, PrimaryKey extends keyof TEntity & string, TModel extends Model<TEntity, PrimaryKey>>(this: ModelConstructor<TEntity, PrimaryKey, TModel>): RepositoryQuery<TEntity, PrimaryKey>;
18
- static find<TEntity extends object, PrimaryKey extends keyof TEntity & string, TModel extends Model<TEntity, PrimaryKey>>(this: ModelConstructor<TEntity, PrimaryKey, TModel>, id: TEntity[PrimaryKey]): Promise<TModel | null>;
19
- static findOrFail<TEntity extends object, PrimaryKey extends keyof TEntity & string, TModel extends Model<TEntity, PrimaryKey>>(this: ModelConstructor<TEntity, PrimaryKey, TModel>, id: TEntity[PrimaryKey], errorFactory?: (id: TEntity[PrimaryKey]) => Error): Promise<TModel>;
20
- static all<TEntity extends object, PrimaryKey extends keyof TEntity & string, TModel extends Model<TEntity, PrimaryKey>>(this: ModelConstructor<TEntity, PrimaryKey, TModel>, options?: QueryOptions<TEntity>): Promise<TModel[]>;
21
- static firstWhere<TEntity extends object, PrimaryKey extends keyof TEntity & string, TModel extends Model<TEntity, PrimaryKey>>(this: ModelConstructor<TEntity, PrimaryKey, TModel>, where: QueryWhere<TEntity>, options?: Omit<QueryOptions<TEntity>, "where">): Promise<TModel | null>;
31
+ protected static primaryKeyField(this: typeof Model): string;
32
+ protected static hydrateAttributes<TEntity extends object>(this: typeof Model, attributes: TEntity): TEntity;
33
+ protected static dehydrateAttributes(this: typeof Model, attributes: LoadedAttributes): LoadedAttributes;
34
+ protected static fromRecord<TEntity extends object, PrimaryKey extends keyof TEntity & string>(this: typeof Model, record: TEntity, repository: BaseRepository<TEntity, PrimaryKey>, exists?: boolean): Model<TEntity, PrimaryKey>;
35
+ static boot(): void;
36
+ static addGlobalScope<TEntity extends object, PrimaryKey extends keyof TEntity & string>(this: object, _name: string, scope: GlobalScopeFn<TEntity, PrimaryKey>): void;
37
+ static repository<TEntity extends object, PrimaryKey extends keyof TEntity & string>(this: object): BaseRepository<TEntity, PrimaryKey>;
38
+ static query<TEntity extends object, PrimaryKey extends keyof TEntity & string>(this: object): RepositoryQuery<TEntity, PrimaryKey>;
39
+ static create(this: object, attributes: Record<string, unknown>): Promise<Model<Record<string, unknown>, "id">>;
40
+ static find(this: object, id: unknown): Promise<Model<Record<string, unknown>, "id"> | null>;
41
+ static findOrFail(this: object, id: unknown, errorFactory?: (id: unknown) => Error): Promise<Model<Record<string, unknown>, "id">>;
42
+ static all(this: object, options?: Omit<QueryOptions<object>, "where">): Promise<Array<Model<Record<string, unknown>, "id">>>;
43
+ static firstWhere(this: object, where: QueryWhere<object>, options?: Omit<QueryOptions<object>, "where">): Promise<Model<Record<string, unknown>, "id"> | null>;
44
+ save(): Promise<this>;
45
+ update(changes: Partial<TEntity>): Promise<this>;
46
+ delete(): Promise<boolean>;
47
+ forceDelete(): Promise<boolean>;
48
+ restore(): Promise<this | null>;
22
49
  loadHasMany<TChild extends object, LocalKey extends keyof TEntity & string, ForeignKey extends keyof TChild & string, Alias extends string>(as: Alias, relation: HasManyRelation<TEntity, TChild, LocalKey, ForeignKey>, childRepository: BaseRepository<TChild, keyof TChild & string>, options?: Omit<QueryOptions<TChild>, "where">): Promise<this & Record<Alias, TChild[]>>;
50
+ loadHasOne<TChild extends object, LocalKey extends keyof TEntity & string, ForeignKey extends keyof TChild & string, Alias extends string>(as: Alias, relation: HasOneRelation<TEntity, TChild, LocalKey, ForeignKey>, childRepository: BaseRepository<TChild, keyof TChild & string>, options?: Omit<QueryOptions<TChild>, "where">): Promise<this & Record<Alias, TChild | undefined>>;
23
51
  loadBelongsTo<TParent extends object, ForeignKey extends keyof TEntity & string, OwnerKey extends keyof TParent & string, Alias extends string>(as: Alias, relation: BelongsToRelation<TEntity, TParent, ForeignKey, OwnerKey>, parentRepository: BaseRepository<TParent, OwnerKey>, options?: Omit<QueryOptions<TParent>, "where">): Promise<this & Record<Alias, TParent | undefined>>;
52
+ loadBelongsToMany<TRelated extends object, Pivot extends object, ParentKey extends keyof TEntity & string, RelatedKey extends keyof TRelated & string, ForeignPivotKey extends keyof Pivot & string, RelatedPivotKey extends keyof Pivot & string, Alias extends string>(as: Alias, relation: BelongsToManyRelation<TEntity, TRelated, Pivot, ParentKey, RelatedKey, ForeignPivotKey, RelatedPivotKey>, relatedRepository: BaseRepository<TRelated, RelatedKey>, options?: Omit<QueryOptions<TRelated>, "where">): Promise<this & Record<Alias, TRelated[]>>;
24
53
  mergeAttributes(patch: Partial<TEntity>): this;
25
54
  }
26
- declare function registerModelRepository<TEntity extends object, PrimaryKey extends keyof TEntity & string, TModel extends Model<TEntity, PrimaryKey>>(model: ModelConstructor<TEntity, PrimaryKey, TModel>, repository: BaseRepository<TEntity, PrimaryKey>): ModelConstructor<TEntity, PrimaryKey, TModel> & typeof Model;
27
- export type { ModelConstructor };
28
- export { Model, registerModelRepository };
55
+ declare function registerModelRepository<TModelClass>(model: TModelClass, repository: object): TModelClass;
56
+ export type { CastType, GlobalScopeFn, ModelClassType, ModelConstructor };
57
+ export { applyCasts, dehydrateValue, filterMassAssignable, hydrateValue, Model, registerModelRepository, };
@@ -1,51 +1,63 @@
1
1
  import type { TableDefinition } from "./table.ts";
2
- import type { MutationValues, QueryOptions, QueryWhere, UpdateValues } from "./types.ts";
2
+ import type { MutationValues, QueryJoin, QueryOptions, QueryWhere, UpdateValues } from "./types.ts";
3
+ import type { WhereNode } from "./whereBuilder.ts";
3
4
  declare function quoteIdentifier(identifier: string): string;
4
5
  declare function qualifyColumn(tableName: string, column: string): string;
5
- declare function buildWhereClause<TEntity>(tableName: string, where?: QueryWhere<TEntity>): {
6
+ declare function resolveQualifiedColumn(defaultTable: string, columnName: string): string;
7
+ declare function parseQualifiedColumn(reference: string): {
8
+ table: string;
9
+ column: string;
10
+ };
11
+ declare function buildWhereClause<TEntity extends object>(tableName: string, where?: QueryWhere<TEntity>): {
12
+ clause: string;
13
+ params: unknown[];
14
+ };
15
+ declare function buildAdvancedWhereClause<TEntity extends object>(tableName: string, where?: QueryWhere<TEntity>, whereNodes?: readonly WhereNode<TEntity>[]): {
6
16
  clause: string;
7
17
  params: unknown[];
8
18
  };
9
19
  declare function resolveSoftDeleteColumn<TEntity>(table: TableDefinition<TEntity>): string | null;
10
- declare function buildQueryWhereClause<TEntity>(table: TableDefinition<TEntity>, options?: Pick<QueryOptions<TEntity>, "where" | "withTrashed" | "onlyTrashed">): {
20
+ declare function buildQueryWhereClause<TEntity extends object>(table: TableDefinition<TEntity>, options?: Pick<QueryOptions<TEntity>, "where" | "withTrashed" | "onlyTrashed">, whereNodes?: readonly WhereNode<TEntity>[]): {
11
21
  clause: string;
12
22
  params: unknown[];
13
23
  };
14
- declare function buildOrderByClause<TEntity>(tableName: string, orderBy?: QueryOptions<TEntity>["orderBy"]): string;
15
- declare function buildSelectQuery<TEntity>(table: TableDefinition<TEntity>, options?: QueryOptions<TEntity>): {
24
+ declare function buildOrderByClause<TEntity extends object>(tableName: string, orderBy?: QueryOptions<TEntity>["orderBy"]): string;
25
+ declare function buildJoinClause(joins?: readonly QueryJoin[]): string;
26
+ declare function buildSelectQuery<TEntity extends object>(table: TableDefinition<TEntity>, options?: QueryOptions<TEntity>, whereNodes?: readonly WhereNode<TEntity>[]): {
16
27
  text: string;
17
28
  params: unknown[];
18
29
  };
19
- declare function buildCountQuery<TEntity>(table: TableDefinition<TEntity>, where?: QueryWhere<TEntity>, options?: Pick<QueryOptions<TEntity>, "withTrashed" | "onlyTrashed">): {
30
+ declare function buildCountQuery<TEntity extends object>(table: TableDefinition<TEntity>, where?: QueryWhere<TEntity>, options?: Pick<QueryOptions<TEntity>, "withTrashed" | "onlyTrashed" | "joins" | "groupBy">, whereNodes?: readonly WhereNode<TEntity>[]): {
20
31
  text: string;
21
32
  params: unknown[];
22
33
  };
23
- declare function buildProjectionQuery<TEntity>(table: TableDefinition<TEntity>, expression: string, alias: string, options?: QueryOptions<TEntity>): {
34
+ declare function buildProjectionQuery<TEntity extends object>(table: TableDefinition<TEntity>, expression: string, alias: string, options?: QueryOptions<TEntity>, whereNodes?: readonly WhereNode<TEntity>[]): {
24
35
  text: string;
25
36
  params: unknown[];
26
37
  };
27
- declare function buildGroupedCountQuery<TEntity, K extends keyof TEntity & string>(table: TableDefinition<TEntity>, column: K, where?: QueryWhere<TEntity>, options?: Pick<QueryOptions<TEntity>, "withTrashed" | "onlyTrashed">): {
38
+ declare function assertSafeProjectionExpression(expression: string): void;
39
+ declare function buildGroupedCountQuery<TEntity extends object, K extends keyof TEntity & string>(table: TableDefinition<TEntity>, column: K, where?: QueryWhere<TEntity>, options?: Pick<QueryOptions<TEntity>, "withTrashed" | "onlyTrashed">): {
28
40
  text: string;
29
41
  params: unknown[];
30
42
  };
31
- declare function buildInsertQuery<TEntity, PrimaryKey extends keyof TEntity & string>(table: TableDefinition<TEntity, PrimaryKey>, values: MutationValues<TEntity>): {
43
+ declare function buildInsertQuery<TEntity extends object, PrimaryKey extends keyof TEntity & string>(table: TableDefinition<TEntity, PrimaryKey>, values: MutationValues<TEntity>): {
32
44
  text: string;
33
45
  params: unknown[];
34
46
  };
35
- declare function buildUpdateQuery<TEntity, PrimaryKey extends keyof TEntity & string>(table: TableDefinition<TEntity, PrimaryKey>, id: TEntity[PrimaryKey], changes: UpdateValues<TEntity, PrimaryKey>): {
47
+ declare function buildUpdateQuery<TEntity extends object, PrimaryKey extends keyof TEntity & string>(table: TableDefinition<TEntity, PrimaryKey>, id: TEntity[PrimaryKey], changes: UpdateValues<TEntity, PrimaryKey>): {
36
48
  text: string;
37
49
  params: unknown[];
38
50
  };
39
- declare function buildSoftDeleteByIdQuery<TEntity, PrimaryKey extends keyof TEntity & string>(table: TableDefinition<TEntity, PrimaryKey>, id: TEntity[PrimaryKey], deletedAt: Date): {
51
+ declare function buildSoftDeleteByIdQuery<TEntity extends object, PrimaryKey extends keyof TEntity & string>(table: TableDefinition<TEntity, PrimaryKey>, id: TEntity[PrimaryKey], deletedAt: Date): {
40
52
  text: string;
41
53
  params: unknown[];
42
54
  };
43
- declare function buildRestoreByIdQuery<TEntity, PrimaryKey extends keyof TEntity & string>(table: TableDefinition<TEntity, PrimaryKey>, id: TEntity[PrimaryKey]): {
55
+ declare function buildRestoreByIdQuery<TEntity extends object, PrimaryKey extends keyof TEntity & string>(table: TableDefinition<TEntity, PrimaryKey>, id: TEntity[PrimaryKey]): {
44
56
  text: string;
45
57
  params: unknown[];
46
58
  };
47
- declare function buildDeleteByIdQuery<TEntity, PrimaryKey extends keyof TEntity & string>(table: TableDefinition<TEntity, PrimaryKey>, id: TEntity[PrimaryKey]): {
59
+ declare function buildDeleteByIdQuery<TEntity extends object, PrimaryKey extends keyof TEntity & string>(table: TableDefinition<TEntity, PrimaryKey>, id: TEntity[PrimaryKey]): {
48
60
  text: string;
49
61
  params: unknown[];
50
62
  };
51
- export { buildCountQuery, buildDeleteByIdQuery, buildGroupedCountQuery, buildInsertQuery, buildOrderByClause, buildProjectionQuery, buildQueryWhereClause, buildRestoreByIdQuery, buildSelectQuery, buildSoftDeleteByIdQuery, buildUpdateQuery, buildWhereClause, qualifyColumn, quoteIdentifier, resolveSoftDeleteColumn, };
63
+ export { assertSafeProjectionExpression, buildAdvancedWhereClause, buildCountQuery, buildDeleteByIdQuery, buildGroupedCountQuery, buildInsertQuery, buildJoinClause, buildOrderByClause, buildProjectionQuery, buildQueryWhereClause, buildRestoreByIdQuery, buildSelectQuery, buildSoftDeleteByIdQuery, buildUpdateQuery, buildWhereClause, parseQualifiedColumn, qualifyColumn, quoteIdentifier, resolveQualifiedColumn, resolveSoftDeleteColumn, };
@@ -4,23 +4,53 @@ interface HasManyRelation<TParent, TChild, LocalKey extends keyof TParent & stri
4
4
  localKey: LocalKey;
5
5
  foreignKey: ForeignKey;
6
6
  }
7
+ interface HasOneRelation<TParent, TChild, LocalKey extends keyof TParent & string = keyof TParent & string, ForeignKey extends keyof TChild & string = keyof TChild & string> {
8
+ type: "hasOne";
9
+ name: string;
10
+ localKey: LocalKey;
11
+ foreignKey: ForeignKey;
12
+ }
7
13
  interface BelongsToRelation<TChild, TParent, ForeignKey extends keyof TChild & string = keyof TChild & string, OwnerKey extends keyof TParent & string = keyof TParent & string> {
8
14
  type: "belongsTo";
9
15
  name: string;
10
16
  foreignKey: ForeignKey;
11
17
  ownerKey: OwnerKey;
12
18
  }
19
+ interface BelongsToManyRelation<TParent, TRelated, Pivot extends object, ParentKey extends keyof TParent & string = keyof TParent & string, RelatedKey extends keyof TRelated & string = keyof TRelated & string, ForeignPivotKey extends keyof Pivot & string = keyof Pivot & string, RelatedPivotKey extends keyof Pivot & string = keyof Pivot & string> {
20
+ type: "belongsToMany";
21
+ name: string;
22
+ pivotTable: string;
23
+ parentKey: ParentKey;
24
+ relatedKey: RelatedKey;
25
+ foreignPivotKey: ForeignPivotKey;
26
+ relatedPivotKey: RelatedPivotKey;
27
+ }
13
28
  declare function hasMany<TParent, TChild, LocalKey extends keyof TParent & string = keyof TParent & string, ForeignKey extends keyof TChild & string = keyof TChild & string>(definition: {
14
29
  name: string;
15
30
  localKey: LocalKey;
16
31
  foreignKey: ForeignKey;
17
32
  }): HasManyRelation<TParent, TChild, LocalKey, ForeignKey>;
33
+ declare function hasOne<TParent, TChild, LocalKey extends keyof TParent & string = keyof TParent & string, ForeignKey extends keyof TChild & string = keyof TChild & string>(definition: {
34
+ name: string;
35
+ localKey: LocalKey;
36
+ foreignKey: ForeignKey;
37
+ }): HasOneRelation<TParent, TChild, LocalKey, ForeignKey>;
18
38
  declare function belongsTo<TChild, TParent, ForeignKey extends keyof TChild & string = keyof TChild & string, OwnerKey extends keyof TParent & string = keyof TParent & string>(definition: {
19
39
  name: string;
20
40
  foreignKey: ForeignKey;
21
41
  ownerKey: OwnerKey;
22
42
  }): BelongsToRelation<TChild, TParent, ForeignKey, OwnerKey>;
43
+ declare function belongsToMany<TParent, TRelated, Pivot extends object, ParentKey extends keyof TParent & string = keyof TParent & string, RelatedKey extends keyof TRelated & string = keyof TRelated & string, ForeignPivotKey extends keyof Pivot & string = keyof Pivot & string, RelatedPivotKey extends keyof Pivot & string = keyof Pivot & string>(definition: {
44
+ name: string;
45
+ pivotTable: string;
46
+ parentKey: ParentKey;
47
+ relatedKey: RelatedKey;
48
+ foreignPivotKey: ForeignPivotKey;
49
+ relatedPivotKey: RelatedPivotKey;
50
+ }): BelongsToManyRelation<TParent, TRelated, Pivot, ParentKey, RelatedKey, ForeignPivotKey, RelatedPivotKey>;
23
51
  declare function indexHasManyRelation<TParent, TChild, LocalKey extends keyof TParent & string, ForeignKey extends keyof TChild & string>(parents: readonly TParent[], children: readonly TChild[], relation: HasManyRelation<TParent, TChild, LocalKey, ForeignKey>): Map<TParent[LocalKey], TChild[]>;
52
+ declare function indexHasOneRelation<TParent, TChild, LocalKey extends keyof TParent & string, ForeignKey extends keyof TChild & string>(parents: readonly TParent[], children: readonly TChild[], relation: HasOneRelation<TParent, TChild, LocalKey, ForeignKey>): Map<TParent[LocalKey], TChild | undefined>;
24
53
  declare function indexBelongsToRelation<TChild, TParent, ForeignKey extends keyof TChild & string, OwnerKey extends keyof TParent & string>(children: readonly TChild[], parents: readonly TParent[], relation: BelongsToRelation<TChild, TParent, ForeignKey, OwnerKey>): Map<TChild[ForeignKey], TParent>;
25
- export type { BelongsToRelation, HasManyRelation };
26
- export { belongsTo, hasMany, indexBelongsToRelation, indexHasManyRelation };
54
+ declare function indexBelongsToManyRelation<TParent, TRelated, Pivot extends object, ParentKey extends keyof TParent & string, RelatedKey extends keyof TRelated & string, ForeignPivotKey extends keyof Pivot & string, RelatedPivotKey extends keyof Pivot & string>(parents: readonly TParent[], pivotRows: readonly Pivot[], relatedRows: readonly TRelated[], relation: BelongsToManyRelation<TParent, TRelated, Pivot, ParentKey, RelatedKey, ForeignPivotKey, RelatedPivotKey>): Map<TParent[ParentKey], TRelated[]>;
55
+ export type { BelongsToManyRelation, BelongsToRelation, HasManyRelation, HasOneRelation };
56
+ export { belongsTo, belongsToMany, hasMany, hasOne, indexBelongsToManyRelation, indexBelongsToRelation, indexHasManyRelation, indexHasOneRelation, };
@@ -0,0 +1,4 @@
1
+ import type { DatabaseConnection } from "./baseRepository";
2
+ declare function resolveRepositoryConnection(): DatabaseConnection;
3
+ declare const repositoryConnection: DatabaseConnection;
4
+ export { repositoryConnection, resolveRepositoryConnection };
@@ -1,20 +1,35 @@
1
+ import type { PaginatedResult } from "../pagination/index.ts";
1
2
  import type BaseRepository from "./baseRepository.ts";
2
3
  import type { BelongsToRelation, HasManyRelation } from "./relationships.ts";
3
4
  import type { QueryOptions, QueryWhere } from "./types.ts";
5
+ import { WhereBuilder } from "./whereBuilder.ts";
4
6
  type LoadedRow = Record<string, unknown>;
5
7
  declare class RepositoryQuery<TEntity extends object, PrimaryKey extends keyof TEntity & string> {
6
8
  private readonly repository;
7
9
  private whereClause;
8
10
  private queryOptions;
9
11
  private readonly eagerLoads;
12
+ private readonly whereNodes;
10
13
  constructor(repository: BaseRepository<TEntity, PrimaryKey>, whereClause?: QueryWhere<TEntity>, queryOptions?: Omit<QueryOptions<TEntity>, "where">);
11
- where(where: QueryWhere<TEntity>): this;
14
+ where(input: QueryWhere<TEntity> | ((builder: WhereBuilder<TEntity>) => void)): this;
15
+ orWhere(input: QueryWhere<TEntity> | ((builder: WhereBuilder<TEntity>) => void)): this;
12
16
  orderBy(orderBy: QueryOptions<TEntity>["orderBy"]): this;
13
17
  limit(limit: number): this;
18
+ offset(offset: number): this;
19
+ join(left: `${string}.${string}`, right: `${string}.${string}`): this;
20
+ leftJoin(left: `${string}.${string}`, right: `${string}.${string}`): this;
21
+ groupBy(groupBy: QueryOptions<TEntity>["groupBy"]): this;
22
+ having(having: QueryWhere<TEntity>): this;
14
23
  withHasMany<TChild extends object, LocalKey extends keyof TEntity & string, ForeignKey extends keyof TChild & string, Alias extends string>(as: Alias, relation: HasManyRelation<TEntity, TChild, LocalKey, ForeignKey>, childRepository: BaseRepository<TChild, keyof TChild & string>, options?: Omit<QueryOptions<TChild>, "where">): this;
15
24
  withBelongsTo<TParent extends object, ForeignKey extends keyof TEntity & string, OwnerKey extends keyof TParent & string, Alias extends string>(as: Alias, relation: BelongsToRelation<TEntity, TParent, ForeignKey, OwnerKey>, parentRepository: BaseRepository<TParent, OwnerKey>, options?: Omit<QueryOptions<TParent>, "where">): this;
16
25
  get(): Promise<Array<TEntity & LoadedRow>>;
17
26
  first(): Promise<(TEntity & LoadedRow) | null>;
27
+ paginate(options: {
28
+ page: number;
29
+ perPage: number;
30
+ }): Promise<PaginatedResult<TEntity>>;
31
+ private buildOptions;
32
+ private addJoin;
18
33
  private attach;
19
34
  }
20
35
  export { RepositoryQuery };
@@ -0,0 +1,47 @@
1
+ import { ColumnDefinition, ForeignIdColumnDefinition } from "./columnDefinition.ts";
2
+ type IndexKind = "index" | "unique" | "partial" | "uniquePartial" | "fullText" | "gin";
3
+ interface IndexDefinition {
4
+ name?: string;
5
+ columns: string[];
6
+ kind: IndexKind;
7
+ where?: string;
8
+ order?: "asc" | "desc";
9
+ }
10
+ type BlueprintAction = "create" | "alter" | "drop";
11
+ declare class Blueprint {
12
+ readonly table: string;
13
+ readonly action: BlueprintAction;
14
+ readonly columns: ColumnDefinition[];
15
+ readonly indexes: IndexDefinition[];
16
+ readonly droppedColumns: string[];
17
+ readonly droppedIndexes: string[];
18
+ constructor(table: string, action: BlueprintAction);
19
+ id(name?: string): ColumnDefinition;
20
+ string(name: string, length?: number): ColumnDefinition;
21
+ text(name: string): ColumnDefinition;
22
+ boolean(name: string): ColumnDefinition;
23
+ integer(name: string): ColumnDefinition;
24
+ bigInteger(name: string): ColumnDefinition;
25
+ timestamp(name: string): ColumnDefinition;
26
+ json(name: string): ColumnDefinition;
27
+ jsonb(name: string): ColumnDefinition;
28
+ foreignId(name: string): ForeignIdColumnDefinition;
29
+ timestamps(): void;
30
+ softDeletes(): void;
31
+ dropColumn(name: string): void;
32
+ dropSoftDeletes(): void;
33
+ dropIndex(name: string): void;
34
+ unique(columns: string | string[], name?: string): void;
35
+ index(columns: string | string[], options?: {
36
+ name?: string;
37
+ order?: "asc" | "desc";
38
+ }): void;
39
+ partialIndex(columns: string | string[], where: string, nameOrOptions?: string | {
40
+ name?: string;
41
+ unique?: boolean;
42
+ }): void;
43
+ fullText(columns: string | string[], name?: string): void;
44
+ ginIndex(column: string, name?: string): void;
45
+ }
46
+ export type { BlueprintAction, IndexDefinition, IndexKind };
47
+ export { Blueprint };
@@ -0,0 +1,36 @@
1
+ type ColumnKind = "id" | "string" | "text" | "boolean" | "integer" | "bigInteger" | "timestamp" | "json" | "jsonb" | "foreignId";
2
+ interface ForeignKeyOptions {
3
+ referencesTable: string;
4
+ referencesColumn: string;
5
+ onDelete?: "cascade" | "set null" | "restrict";
6
+ }
7
+ declare class ColumnDefinition {
8
+ readonly name: string;
9
+ kind: ColumnKind;
10
+ length?: number;
11
+ isNullable: boolean;
12
+ isPrimary: boolean;
13
+ isUnique: boolean;
14
+ autoIncrement: boolean;
15
+ defaultValue?: string;
16
+ checkExpression?: string;
17
+ foreignKey?: ForeignKeyOptions;
18
+ constructor(name: string, kind: ColumnKind);
19
+ nullable(): this;
20
+ notNullable(): this;
21
+ default(value: string | number | boolean): this;
22
+ defaultRaw(expression: string): this;
23
+ unique(): this;
24
+ primary(): this;
25
+ check(expression: string): this;
26
+ }
27
+ declare class ForeignIdColumnDefinition extends ColumnDefinition {
28
+ constructor(name: string);
29
+ references(table: string, column?: string): this;
30
+ constrained(table?: string): this;
31
+ cascadeOnDelete(): this;
32
+ nullOnDelete(): this;
33
+ }
34
+ declare function inferReferencedTable(columnName: string): string;
35
+ export type { ColumnKind, ForeignKeyOptions };
36
+ export { ColumnDefinition, ForeignIdColumnDefinition, inferReferencedTable };
@@ -0,0 +1,8 @@
1
+ type DatabaseDriver = "pgsql" | "mysql" | "sqlite";
2
+ interface ResolveDatabaseDriverOptions {
3
+ url?: string;
4
+ connection?: string;
5
+ }
6
+ declare function resolveDatabaseDriver(options?: ResolveDatabaseDriverOptions): DatabaseDriver;
7
+ export type { DatabaseDriver, ResolveDatabaseDriverOptions };
8
+ export { resolveDatabaseDriver };
@@ -0,0 +1,4 @@
1
+ declare class UnsupportedSchemaFeatureError extends Error {
2
+ constructor(feature: string, driver: string);
3
+ }
4
+ export { UnsupportedSchemaFeatureError };
@@ -0,0 +1,8 @@
1
+ import type { Blueprint, IndexDefinition } from "../blueprint.ts";
2
+ import type { ColumnDefinition } from "../columnDefinition.ts";
3
+ import type { DatabaseDriver } from "../driver.ts";
4
+ declare function compileDropTable(driver: DatabaseDriver, tableName: string): string[];
5
+ declare function compileColumn(driver: DatabaseDriver, column: ColumnDefinition, mode: "create" | "alter"): string;
6
+ declare function compileIndex(_driver: DatabaseDriver, tableName: string, index: IndexDefinition): string;
7
+ declare function compileBlueprint(driver: DatabaseDriver, blueprint: Blueprint): string[];
8
+ export { compileBlueprint, compileColumn, compileDropTable, compileIndex };
@@ -0,0 +1,4 @@
1
+ import type { DatabaseDriver } from "../driver.ts";
2
+ import type { Grammar } from "./grammar.ts";
3
+ declare function createGrammar(driver: DatabaseDriver): Grammar;
4
+ export { createGrammar };
@@ -0,0 +1,10 @@
1
+ import type { Blueprint } from "../blueprint.ts";
2
+ import type { ColumnDefinition } from "../columnDefinition.ts";
3
+ import type { DatabaseDriver } from "../driver.ts";
4
+ interface Grammar {
5
+ readonly driver: DatabaseDriver;
6
+ compile(blueprint: Blueprint): string[];
7
+ }
8
+ declare function compileColumnType(driver: DatabaseDriver, column: ColumnDefinition): string;
9
+ export type { Grammar };
10
+ export { compileColumnType };
@@ -0,0 +1,7 @@
1
+ import type { DatabaseDriver } from "../driver.ts";
2
+ import type { Grammar } from "./grammar.ts";
3
+ import { MySqlGrammar } from "./mysqlGrammar.ts";
4
+ import { PostgresGrammar } from "./postgresGrammar.ts";
5
+ import { SqliteGrammar } from "./sqliteGrammar.ts";
6
+ declare function grammarForDriver(driver: DatabaseDriver): Grammar;
7
+ export { grammarForDriver, MySqlGrammar, PostgresGrammar, SqliteGrammar };
@@ -0,0 +1,2 @@
1
+ declare const MySqlGrammar: import("./grammar.ts").Grammar;
2
+ export { MySqlGrammar };
@@ -0,0 +1,2 @@
1
+ declare const PostgresGrammar: import("./grammar.ts").Grammar;
2
+ export { PostgresGrammar };
@@ -0,0 +1,2 @@
1
+ declare const SqliteGrammar: import("./grammar.ts").Grammar;
2
+ export { SqliteGrammar };
@@ -0,0 +1,12 @@
1
+ export type { BlueprintAction, IndexDefinition, IndexKind } from "./blueprint.ts";
2
+ export { Blueprint } from "./blueprint.ts";
3
+ export type { ColumnKind, ForeignKeyOptions } from "./columnDefinition.ts";
4
+ export { ColumnDefinition, ForeignIdColumnDefinition, inferReferencedTable, } from "./columnDefinition.ts";
5
+ export type { DatabaseDriver, ResolveDatabaseDriverOptions } from "./driver.ts";
6
+ export { resolveDatabaseDriver } from "./driver.ts";
7
+ export { UnsupportedSchemaFeatureError } from "./errors.ts";
8
+ export { compileBlueprint } from "./grammars/compileStatements.ts";
9
+ export type { Grammar } from "./grammars/grammar.ts";
10
+ export { grammarForDriver, MySqlGrammar, PostgresGrammar, SqliteGrammar, } from "./grammars/index.ts";
11
+ export type { BlueprintCallback } from "./schema.ts";
12
+ export { createSchemaBuilder, Schema, SchemaBuilder } from "./schema.ts";
@@ -0,0 +1,21 @@
1
+ import type { MigrationDatabase } from "../migrations/types.ts";
2
+ import { Blueprint } from "./blueprint.ts";
3
+ import type { DatabaseDriver } from "./driver.ts";
4
+ import { resolveDatabaseDriver } from "./driver.ts";
5
+ type BlueprintCallback = (table: Blueprint) => void;
6
+ declare class SchemaBuilder {
7
+ #private;
8
+ constructor(driver: DatabaseDriver);
9
+ create(table: string, callback: BlueprintCallback): this;
10
+ table(table: string, callback: BlueprintCallback): this;
11
+ drop(table: string): this;
12
+ toSql(): string[];
13
+ execute(db: MigrationDatabase): Promise<void>;
14
+ }
15
+ declare class Schema {
16
+ static builder(driver?: DatabaseDriver): SchemaBuilder;
17
+ static run(db: MigrationDatabase, driver: DatabaseDriver, callback: (schema: SchemaBuilder) => void | Promise<void>): Promise<void>;
18
+ }
19
+ declare function createSchemaBuilder(db: MigrationDatabase, driver?: DatabaseDriver): SchemaBuilder;
20
+ export type { BlueprintCallback };
21
+ export { createSchemaBuilder, resolveDatabaseDriver, Schema, SchemaBuilder };
@@ -0,0 +1,6 @@
1
+ import type { Seeder, SeederDatabase } from "./types.ts";
2
+ declare function loadSeedersFromDirectory(directory: string): Promise<Seeder[]>;
3
+ declare function runSeedersFromDirectory(directory: string, db: SeederDatabase, options?: {
4
+ onSeeder?: (name: string) => void;
5
+ }): Promise<number>;
6
+ export { loadSeedersFromDirectory, runSeedersFromDirectory };