orchid-orm 1.31.2 → 1.31.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +27 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Query, SelectableFromShape, CreateMethodsNames, CreateData, AddQueryDefaults, RelationConfigBase, UpdateData, WhereArg, JoinQueryMethod, DeleteMethodsNames, Db, IsolationLevel, TransactionOptions, Adapter, FromArg, FromResult, AdapterOptions, DbSharedOptions, RelationJoinQuery, RelationQuery, RelationsBase, ShapeColumnPrimaryKeys, ShapeUniqueColumns, TableDataItemsUniqueColumns, TableDataItemsUniqueColumnTuples, UniqueConstraints, TableDataItemsUniqueConstraints, ComputedColumnsFromOptions, MapTableScopesOption, TableDataItem, ComputedOptionsFactory, QueryData, QueryBase, TableDataFn, DbTableOptionScopes, SqlMethod, DefaultSchemaConfig, DefaultColumnTypes, QueryBeforeHook, QueryAfterHook, AfterHook, WhereResult, MergeQuery } from 'pqb';
|
|
2
2
|
export * from 'pqb';
|
|
3
|
-
import { ColumnsShapeBase, EmptyObject, MaybeArray,
|
|
3
|
+
import { ColumnsShapeBase, EmptyObject, MaybeArray, RecordUnknown, Simplify, ColumnShapeOutput, ColumnShapeInput, ColumnShapeInputPartial, CoreQueryScopes, ColumnSchemaConfig, QueryColumns, QueryReturnType } from 'orchid-core';
|
|
4
4
|
export * from 'orchid-core';
|
|
5
5
|
|
|
6
6
|
interface RelationCommonOptions<Related extends TableClass = TableClass, Scope extends Query = Query> {
|
|
@@ -189,7 +189,7 @@ interface FromQuery extends Query {
|
|
|
189
189
|
returnType: 'all';
|
|
190
190
|
}
|
|
191
191
|
type OrchidORM<T extends TableClasses = TableClasses> = {
|
|
192
|
-
[K in keyof T]:
|
|
192
|
+
[K in keyof T]: ORMTableInputToQueryBuilder<InstanceType<T[K]>>;
|
|
193
193
|
} & {
|
|
194
194
|
$transaction: typeof transaction;
|
|
195
195
|
$adapter: Adapter;
|
|
@@ -370,7 +370,7 @@ type RelationThunk = BelongsTo | HasOne | HasMany | HasAndBelongsToMany;
|
|
|
370
370
|
interface RelationThunks {
|
|
371
371
|
[K: string]: RelationThunk;
|
|
372
372
|
}
|
|
373
|
-
type RelationScopeOrTable<Relation extends RelationThunkBase> = Relation['options']['scope'] extends (q: Query) => Query ? ReturnType<Relation['options']['scope']> :
|
|
373
|
+
type RelationScopeOrTable<Relation extends RelationThunkBase> = Relation['options']['scope'] extends (q: Query) => Query ? ReturnType<Relation['options']['scope']> : ORMTableInputToQueryBuilder<InstanceType<ReturnType<Relation['fn']>>>;
|
|
374
374
|
interface RelationConfigSelf {
|
|
375
375
|
columns: {
|
|
376
376
|
shape: ColumnsShapeBase;
|
|
@@ -383,23 +383,27 @@ type MapRelations<T> = T extends RelationConfigSelf ? {
|
|
|
383
383
|
[K in keyof T['relations'] & string]: MapRelation<T, K, RelationScopeOrTable<T['relations'][K]>>;
|
|
384
384
|
} : EmptyObject;
|
|
385
385
|
|
|
386
|
-
interface TableClass<T extends
|
|
386
|
+
interface TableClass<T extends ORMTableInput = ORMTableInput> {
|
|
387
387
|
new (): T;
|
|
388
388
|
instance(): T;
|
|
389
389
|
}
|
|
390
390
|
interface TableClasses {
|
|
391
391
|
[K: string]: TableClass;
|
|
392
392
|
}
|
|
393
|
-
interface
|
|
394
|
-
relations: Relations;
|
|
393
|
+
interface TableInfo {
|
|
395
394
|
definedAs: string;
|
|
396
395
|
db: OrchidORM;
|
|
397
396
|
getFilePath(): string;
|
|
398
397
|
name: string;
|
|
399
398
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
interface
|
|
399
|
+
interface Table extends Query, TableInfo {
|
|
400
|
+
}
|
|
401
|
+
interface TableToDb<T extends ORMTableInput, Relations extends RelationsBase> extends TableInfo, Db<T['table'], T['columns']['shape'], keyof ShapeColumnPrimaryKeys<T['columns']['shape']> extends never ? never : ShapeColumnPrimaryKeys<T['columns']['shape']>, ShapeUniqueColumns<T['columns']['shape']> | TableDataItemsUniqueColumns<T['columns']['shape'], T['columns']['data']>, TableDataItemsUniqueColumnTuples<T['columns']['shape'], T['columns']['data']>, UniqueConstraints<T['columns']['shape']> | TableDataItemsUniqueConstraints<T['columns']['data']>, T['types'], T['columns']['shape'] & ComputedColumnsFromOptions<T['computed']>, MapTableScopesOption<T>> {
|
|
402
|
+
relations: Relations;
|
|
403
|
+
}
|
|
404
|
+
type ORMTableInputToQueryBuilder<T extends ORMTableInput> = T extends RelationConfigSelf ? TableToDb<T, MapRelations<T>> & MapRelations<T> : TableToDb<T, RelationsBase>;
|
|
405
|
+
type ScopeFn<Related extends TableClass, Scope extends Query> = (q: ORMTableInputToQueryBuilder<InstanceType<Related>>) => Scope;
|
|
406
|
+
interface ORMTableInput {
|
|
403
407
|
table: string;
|
|
404
408
|
columns: {
|
|
405
409
|
shape: ColumnsShapeBase;
|
|
@@ -414,19 +418,23 @@ interface Table {
|
|
|
414
418
|
* collect computed columns returned by {@link BaseTable.setColumns}
|
|
415
419
|
*/
|
|
416
420
|
computed?: ComputedOptionsFactory<never, never>;
|
|
417
|
-
scopes?:
|
|
421
|
+
scopes?: RecordUnknown;
|
|
418
422
|
readonly softDelete?: true | string;
|
|
419
423
|
comment?: string;
|
|
420
424
|
}
|
|
421
|
-
type Queryable<T extends
|
|
425
|
+
type Queryable<T extends ORMTableInput> = Simplify<{
|
|
422
426
|
[K in keyof T['columns']['shape']]?: T['columns']['shape'][K]['queryType'];
|
|
423
|
-
}
|
|
424
|
-
type Selectable<T extends
|
|
425
|
-
type Insertable<T extends
|
|
426
|
-
type Updatable<T extends
|
|
427
|
-
type BeforeHookMethod =
|
|
428
|
-
type AfterHookMethod =
|
|
429
|
-
type AfterSelectableHookMethod = <
|
|
427
|
+
}>;
|
|
428
|
+
type Selectable<T extends ORMTableInput> = Simplify<ColumnShapeOutput<T['columns']['shape']>>;
|
|
429
|
+
type Insertable<T extends ORMTableInput> = Simplify<ColumnShapeInput<T['columns']['shape']>>;
|
|
430
|
+
type Updatable<T extends ORMTableInput> = Simplify<ColumnShapeInputPartial<T['columns']['shape']>>;
|
|
431
|
+
type BeforeHookMethod = (cb: QueryBeforeHook) => void;
|
|
432
|
+
type AfterHookMethod = (cb: QueryAfterHook) => void;
|
|
433
|
+
type AfterSelectableHookMethod = <Shape extends QueryColumns, S extends (keyof Shape)[]>(this: {
|
|
434
|
+
columns: {
|
|
435
|
+
shape: Shape;
|
|
436
|
+
};
|
|
437
|
+
}, select: S, cb: AfterHook<S, Shape>) => void;
|
|
430
438
|
interface SetColumnsResult<Shape extends ColumnsShapeBase, Data extends MaybeArray<MaybeArray<TableDataItem>>> {
|
|
431
439
|
shape: Shape;
|
|
432
440
|
data: Data extends unknown[] ? Data : [Data];
|
|
@@ -645,4 +653,4 @@ type Repo<T extends Query, Methods extends MethodsBase<T>> = (<Q extends {
|
|
|
645
653
|
}>(q: Q) => Query & Q & MapMethods<T, Methods>) & T & MapMethods<T, Methods>;
|
|
646
654
|
declare const createRepo: <T extends Query, Methods extends MethodsBase<T>>(table: T, methods: Methods) => Repo<T, Methods>;
|
|
647
655
|
|
|
648
|
-
export { BaseTableClass, BaseTableInstance,
|
|
656
|
+
export { BaseTableClass, BaseTableInstance, Insertable, MapMethods, MapQueryMethods, MethodsBase, ORMTableInput, ORMTableInputToQueryBuilder, OrchidORM, Queryable, Repo, ScopeFn, Selectable, SetColumnsResult, Table, TableClass, TableClasses, TableInfo, TableToDb, Updatable, createBaseTable, createRepo, orchidORM };
|