@getstrata/core 0.4.0 → 0.5.1
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/bootstrap/httpKernel.d.ts +2 -0
- package/dist/config/queue.d.ts +8 -0
- package/dist/config/rateLimit.d.ts +2 -1
- package/dist/core/database/baseRepository.d.ts +16 -4
- package/dist/core/database/index.d.ts +10 -4
- package/dist/core/database/migrations/advisoryLock.d.ts +6 -0
- package/dist/core/database/migrations/runner.d.ts +8 -2
- package/dist/core/database/migrations/types.d.ts +1 -0
- package/dist/core/database/model.d.ts +46 -17
- package/dist/core/database/query.d.ts +25 -14
- package/dist/core/database/relationships.d.ts +32 -2
- package/dist/core/database/repositoryQuery.d.ts +16 -1
- package/dist/core/database/schema/blueprint.d.ts +47 -0
- package/dist/core/database/schema/columnDefinition.d.ts +36 -0
- package/dist/core/database/schema/driver.d.ts +8 -0
- package/dist/core/database/schema/errors.d.ts +4 -0
- package/dist/core/database/schema/grammars/compileStatements.d.ts +8 -0
- package/dist/core/database/schema/grammars/createGrammar.d.ts +4 -0
- package/dist/core/database/schema/grammars/grammar.d.ts +10 -0
- package/dist/core/database/schema/grammars/index.d.ts +7 -0
- package/dist/core/database/schema/grammars/mysqlGrammar.d.ts +2 -0
- package/dist/core/database/schema/grammars/postgresGrammar.d.ts +2 -0
- package/dist/core/database/schema/grammars/sqliteGrammar.d.ts +2 -0
- package/dist/core/database/schema/index.d.ts +12 -0
- package/dist/core/database/schema/schema.d.ts +21 -0
- package/dist/core/database/seeders/runner.d.ts +6 -0
- package/dist/core/database/seeders/types.d.ts +8 -0
- package/dist/core/database/types.d.ts +39 -2
- package/dist/core/database/whereBuilder.d.ts +17 -0
- package/dist/core/http/index.d.ts +1 -1
- package/dist/core/http/securedRouteModelBinding.d.ts +2 -1
- package/dist/core/lifecycle/gracefulShutdown.d.ts +6 -0
- package/dist/core/pagination/index.d.ts +11 -1
- package/dist/core/queue/failedJobRepository.d.ts +6 -0
- package/dist/core/queue/failedJobService.d.ts +15 -0
- package/dist/core/queue/failedJobTable.d.ts +3 -0
- package/dist/core/queue/jobRegistry.d.ts +14 -0
- package/dist/core/queue/jobRunner.d.ts +9 -0
- package/dist/core/queue/publicQueue.d.ts +15 -0
- package/dist/core/queue/redisQueue.d.ts +29 -0
- package/dist/core/queue/resilientQueue.d.ts +9 -0
- package/dist/core/queue/types.d.ts +8 -0
- package/dist/core/scheduler/schedule.d.ts +15 -0
- package/dist/entries/auth/accessControl.js +113 -0
- package/dist/entries/auth/authContext.js +15 -0
- package/dist/entries/auth/guard.js +2871 -0
- package/dist/entries/auth/membershipContext.js +276 -0
- package/dist/entries/auth/membershipScope.js +390 -0
- package/dist/entries/auth/membershipService.js +477 -0
- package/dist/entries/auth/oauth/oidcProvider.js +49 -0
- package/dist/entries/auth/oauth/providers.js +71 -0
- package/dist/entries/auth/oauth/samlProvider.js +26 -0
- package/dist/entries/auth/oauth/types.js +1 -0
- package/dist/entries/auth/password.js +15 -0
- package/dist/entries/auth/policy.js +134 -0
- package/dist/entries/auth/sessionCookie.js +75 -0
- package/dist/entries/auth/tokenHash.js +17 -0
- package/dist/entries/cache/tags.js +13 -0
- package/dist/entries/crypto/fieldEncryption.js +93 -0
- package/dist/entries/crypto/mfaSecret.js +105 -0
- package/dist/entries/database/factory.js +17 -0
- package/dist/entries/database/seeders.js +30 -0
- package/dist/entries/database/types.js +1 -0
- package/dist/entries/database.js +2219 -0
- package/dist/entries/errors/http.js +78 -0
- package/dist/entries/http/contentNegotiation.js +26 -0
- package/dist/entries/http/csrfToken.js +147 -0
- package/dist/entries/http/etag.js +170 -0
- package/dist/entries/http/flashSession.js +106 -0
- package/dist/entries/http/middleware.js +68 -0
- package/dist/entries/http/parseFormBody.js +88 -0
- package/dist/entries/http/requestMetaContext.js +18 -0
- package/dist/entries/http/resources.js +19 -0
- package/dist/entries/http/webErrorResponse.js +3144 -0
- package/dist/entries/http/webFormRequest.js +293 -0
- package/dist/entries/http.js +3925 -0
- package/dist/entries/jobs/dispatchWebhookJob.js +342 -0
- package/dist/entries/lifecycle/gracefulShutdown.js +50 -0
- package/dist/entries/metrics/prometheus.js +70 -0
- package/dist/entries/pagination.js +14 -0
- package/dist/entries/queue/createAppQueue.js +2849 -0
- package/dist/entries/queue/failedJobService.js +38 -0
- package/dist/entries/queue/jobRegistry.js +32 -0
- package/dist/entries/queue/jobRunner.js +75 -0
- package/dist/entries/queue/publicQueue.js +2477 -0
- package/dist/entries/queue/queueMetrics.js +2899 -0
- package/dist/entries/queue/types.js +1 -0
- package/dist/entries/security/oauthState.js +75 -0
- package/dist/entries/security/publicReads.js +33 -0
- package/dist/entries/security/safeUrl.js +143 -0
- package/dist/entries/security/securityEvents.js +41 -0
- package/dist/entries/security/stripeWebhook.js +115 -0
- package/dist/entries/security/tokenExpiry.js +16 -0
- package/dist/entries/security/totp.js +51 -0
- package/dist/entries/storage/storage.js +123 -0
- package/dist/entries/tenant/tenantContext.js +30 -0
- package/dist/entries/tenant/tenantMiddleware.js +312 -0
- package/dist/entries/tracing/traceContext.js +15 -0
- package/dist/entries/validation/rules.js +232 -0
- package/dist/entries/view.js +3073 -0
- package/dist/framework/public-api.d.ts +65 -38
- package/dist/index.js +3199 -308
- package/dist/modules/user/apiTokenRepository.d.ts +1 -1
- package/dist/modules/user/apiTokenTable.d.ts +1 -1
- package/dist/modules/user/authService.d.ts +1 -1
- package/dist/modules/user/notificationRepository.d.ts +1 -1
- package/dist/modules/user/notificationService.d.ts +1 -1
- package/dist/modules/user/notificationTable.d.ts +1 -1
- package/dist/modules/user/oauthIdentityRepository.d.ts +2 -2
- package/dist/modules/user/provider.d.ts +1 -1
- package/dist/modules/user/repository.d.ts +1 -1
- package/dist/modules/user/table.d.ts +1 -1
- package/dist/modules/user/tokenService.d.ts +1 -1
- 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 };
|
|
@@ -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?:
|
|
18
|
+
findAll(options?: ExtendedQueryOptions<TEntity>): Promise<TEntity[]>;
|
|
15
19
|
paginate(options: {
|
|
16
20
|
page: number;
|
|
17
21
|
perPage: number;
|
|
18
|
-
} & Omit<
|
|
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[]>;
|
|
@@ -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 {
|
|
6
|
-
export
|
|
7
|
-
export {
|
|
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 {
|
|
24
|
+
export { withMigrationLock } from "./advisoryLock.ts";
|
|
25
|
+
export { ensureMigrationsTable, freshDatabase, getAppliedMigrations, getMigrationStatus, loadMigrationsFromDirectory, migrateDatabase, rollbackDatabase, runPendingMigrations, };
|
|
@@ -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
|
-
|
|
6
|
-
|
|
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
|
|
18
|
+
protected attributes: TEntity;
|
|
10
19
|
protected readonly repository: BaseRepository<TEntity, PrimaryKey>;
|
|
11
|
-
|
|
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
|
|
17
|
-
static
|
|
18
|
-
static
|
|
19
|
-
static
|
|
20
|
-
static
|
|
21
|
-
static
|
|
31
|
+
protected static primaryKeyField(this: object): string;
|
|
32
|
+
protected static hydrateAttributes<TEntity extends object>(this: object, attributes: TEntity): TEntity;
|
|
33
|
+
protected static dehydrateAttributes(this: object, attributes: LoadedAttributes): LoadedAttributes;
|
|
34
|
+
protected static fromRecord<TEntity extends object, PrimaryKey extends keyof TEntity & string>(this: object, 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<
|
|
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,52 +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
|
|
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
|
|
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
38
|
declare function assertSafeProjectionExpression(expression: string): void;
|
|
28
|
-
declare function buildGroupedCountQuery<TEntity, K extends keyof TEntity & string>(table: TableDefinition<TEntity>, column: K, where?: QueryWhere<TEntity>, options?: Pick<QueryOptions<TEntity>, "withTrashed" | "onlyTrashed">): {
|
|
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">): {
|
|
29
40
|
text: string;
|
|
30
41
|
params: unknown[];
|
|
31
42
|
};
|
|
32
|
-
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>): {
|
|
33
44
|
text: string;
|
|
34
45
|
params: unknown[];
|
|
35
46
|
};
|
|
36
|
-
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>): {
|
|
37
48
|
text: string;
|
|
38
49
|
params: unknown[];
|
|
39
50
|
};
|
|
40
|
-
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): {
|
|
41
52
|
text: string;
|
|
42
53
|
params: unknown[];
|
|
43
54
|
};
|
|
44
|
-
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]): {
|
|
45
56
|
text: string;
|
|
46
57
|
params: unknown[];
|
|
47
58
|
};
|
|
48
|
-
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]): {
|
|
49
60
|
text: string;
|
|
50
61
|
params: unknown[];
|
|
51
62
|
};
|
|
52
|
-
export { assertSafeProjectionExpression, 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
|
-
|
|
26
|
-
export {
|
|
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, };
|
|
@@ -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(
|
|
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,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,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,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 };
|