orchid-orm 1.18.3 → 1.20.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.
- package/dist/index.d.ts +12 -10
- package/dist/index.js +54 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -32
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Query, QueryWithTable, SetQueryTableAlias, RelationJoinQuery, WhereArg, UpdateData, CreateData, AddQueryDefaults, Db, IsolationLevel, TransactionOptions, Adapter, FromArgs, FromResult, AdapterOptions, QueryLogOptions, NoPrimaryKeyOption, RelationQuery, RelationConfigBase, RelationQueryBase, ComputedColumnsBase, QueryData, QueryBase, DbTableOptionScopes, DefaultColumnTypes, QueryBeforeHook, QueryAfterHook, AfterHook, WhereResult, MergeQuery, SetQueryReturns, QueryReturnType } from 'pqb';
|
|
1
|
+
import { Query, QueryWithTable, SetQueryTableAlias, RelationJoinQuery, WhereArg, UpdateData, CreateData, AddQueryDefaults, Db, IsolationLevel, TransactionOptions, Adapter, FromArgs, FromResult, AdapterOptions, QueryLogOptions, NoPrimaryKeyOption, RelationQuery, RelationConfigBase, RelationQueryBase, ComputedColumnsBase, MapTableScopesOption, QueryData, QueryBase, DbTableOptionScopes, DefaultSchemaConfig, DefaultColumnTypes, QueryBeforeHook, QueryAfterHook, AfterHook, WhereResult, MergeQuery, SetQueryReturns, QueryReturnType } from 'pqb';
|
|
2
2
|
export * from 'pqb';
|
|
3
|
-
import { ColumnsShapeBase, EmptyObject, MaybeArray, StringKey, CoreQueryScopes, ColumnShapeQueryType, ColumnShapeOutput, ColumnShapeInput } from 'orchid-core';
|
|
3
|
+
import { ColumnsShapeBase, EmptyObject, MaybeArray, StringKey, CoreQueryScopes, ColumnShapeQueryType, ColumnShapeOutput, ColumnShapeInput, ColumnSchemaConfig } from 'orchid-core';
|
|
4
4
|
|
|
5
5
|
type RelationCommonOptions<Related extends TableClass = TableClass, Scope extends Query = Query> = {
|
|
6
6
|
scope?: ScopeFn<Related, Scope>;
|
|
@@ -344,7 +344,7 @@ type TableClass<T extends Table = Table> = {
|
|
|
344
344
|
type TableClasses = Record<string, TableClass>;
|
|
345
345
|
type TableToDb<T extends Table, RelationQueries extends Record<string, RelationQueryBase>> = Db<T['table'], T['columns'], RelationQueries, T['types'], T['computed'] extends ComputedColumnsBase<never> ? T['columns'] & {
|
|
346
346
|
[K in keyof T['computed']]: ReturnType<T['computed'][K]>['_type'];
|
|
347
|
-
} : T['columns'], T['scopes']
|
|
347
|
+
} : T['columns'], MapTableScopesOption<T['scopes'], T['softDelete']>> & {
|
|
348
348
|
definedAs: string;
|
|
349
349
|
db: OrchidORM;
|
|
350
350
|
getFilePath(): string;
|
|
@@ -365,6 +365,7 @@ type Table = {
|
|
|
365
365
|
*/
|
|
366
366
|
computed?: ComputedColumnsBase<never>;
|
|
367
367
|
scopes?: CoreQueryScopes;
|
|
368
|
+
readonly softDelete?: true | string;
|
|
368
369
|
};
|
|
369
370
|
type Queryable<T extends Table> = Partial<ColumnShapeQueryType<T['columns']>>;
|
|
370
371
|
type Selectable<T extends Table> = ColumnShapeOutput<T['columns']>;
|
|
@@ -373,7 +374,6 @@ type Updateable<T extends Table> = Partial<Insertable<T>>;
|
|
|
373
374
|
type BeforeHookMethod = <T extends Table>(cb: QueryBeforeHook) => T;
|
|
374
375
|
type AfterHookMethod = <T extends Table>(cb: QueryAfterHook) => T;
|
|
375
376
|
type AfterSelectableHookMethod = <T extends Table, S extends (keyof T['columns'])[]>(this: T, select: S, cb: AfterHook<S, T['columns']>) => T;
|
|
376
|
-
type SchemaProviderBase = any;
|
|
377
377
|
interface BaseTableInstance<ColumnTypes> {
|
|
378
378
|
table: string;
|
|
379
379
|
columns: ColumnsShapeBase;
|
|
@@ -529,23 +529,25 @@ interface BaseTableInstance<ColumnTypes> {
|
|
|
529
529
|
afterDelete: AfterSelectableHookMethod;
|
|
530
530
|
afterDeleteCommit: AfterSelectableHookMethod;
|
|
531
531
|
}
|
|
532
|
-
interface BaseTableClass<
|
|
532
|
+
interface BaseTableClass<SchemaConfig extends ColumnSchemaConfig, ColumnTypes> {
|
|
533
533
|
nowSQL: string | undefined;
|
|
534
534
|
exportAs: string;
|
|
535
|
-
schema: SchemaProvider;
|
|
536
535
|
getFilePath(): string;
|
|
537
536
|
new (): BaseTableInstance<ColumnTypes>;
|
|
538
537
|
instance(): BaseTableInstance<ColumnTypes>;
|
|
538
|
+
inputSchema: SchemaConfig['inputSchema'];
|
|
539
|
+
outputSchema: SchemaConfig['outputSchema'];
|
|
540
|
+
querySchema: SchemaConfig['querySchema'];
|
|
539
541
|
}
|
|
540
|
-
declare function createBaseTable<
|
|
541
|
-
|
|
542
|
+
declare function createBaseTable<SchemaConfig extends ColumnSchemaConfig = DefaultSchemaConfig, ColumnTypes = DefaultColumnTypes<SchemaConfig>>({ schemaConfig, columnTypes: columnTypesArg, snakeCase, filePath: filePathArg, nowSQL, exportAs, language, }?: {
|
|
543
|
+
schemaConfig?: SchemaConfig;
|
|
544
|
+
columnTypes?: ColumnTypes | ((t: DefaultColumnTypes<SchemaConfig>) => ColumnTypes);
|
|
542
545
|
snakeCase?: boolean;
|
|
543
546
|
filePath?: string;
|
|
544
547
|
nowSQL?: string;
|
|
545
548
|
exportAs?: string;
|
|
546
549
|
language?: string;
|
|
547
|
-
|
|
548
|
-
}): BaseTableClass<ColumnTypes, SchemaProvider>;
|
|
550
|
+
}): BaseTableClass<SchemaConfig, ColumnTypes>;
|
|
549
551
|
|
|
550
552
|
type QueryMethods<T extends Query> = Record<string, (q: T, ...args: any[]) => any>;
|
|
551
553
|
type QueryOne<T extends Query> = SetQueryReturns<T, Exclude<QueryReturnType, 'all'>>;
|
package/dist/index.js
CHANGED
|
@@ -5,25 +5,18 @@ var orchidCore = require('orchid-core');
|
|
|
5
5
|
var node_async_hooks = require('node:async_hooks');
|
|
6
6
|
|
|
7
7
|
function createBaseTable({
|
|
8
|
+
schemaConfig = pqb.defaultSchemaConfig,
|
|
8
9
|
columnTypes: columnTypesArg,
|
|
9
10
|
snakeCase,
|
|
10
11
|
filePath: filePathArg,
|
|
11
12
|
nowSQL,
|
|
12
13
|
exportAs = "BaseTable",
|
|
13
|
-
language
|
|
14
|
-
schemaProvider: schemaProviderArg
|
|
14
|
+
language
|
|
15
15
|
} = {}) {
|
|
16
16
|
var _a;
|
|
17
|
-
const columnTypes = typeof columnTypesArg === "function" ? columnTypesArg(
|
|
18
|
-
pqb.columnTypes
|
|
19
|
-
) : columnTypesArg || pqb.columnTypes;
|
|
17
|
+
const columnTypes = typeof columnTypesArg === "function" ? columnTypesArg(pqb.makeColumnTypes(schemaConfig)) : columnTypesArg || pqb.makeColumnTypes(pqb.defaultSchemaConfig);
|
|
20
18
|
const filePathOrStack = filePathArg || orchidCore.getStackTrace();
|
|
21
19
|
let filePath;
|
|
22
|
-
function schemaProvider() {
|
|
23
|
-
const schema = schemaProviderArg.call(this);
|
|
24
|
-
this.schema = () => schema;
|
|
25
|
-
return schema;
|
|
26
|
-
}
|
|
27
20
|
const base = (_a = class {
|
|
28
21
|
constructor() {
|
|
29
22
|
this.snakeCase = snakeCase;
|
|
@@ -31,6 +24,21 @@ function createBaseTable({
|
|
|
31
24
|
this.q = {};
|
|
32
25
|
this.language = language;
|
|
33
26
|
}
|
|
27
|
+
static inputSchema() {
|
|
28
|
+
return this._inputSchema === void 0 ? this._inputSchema = schemaConfig.inputSchema.call(this) : this._inputSchema;
|
|
29
|
+
}
|
|
30
|
+
static outputSchema() {
|
|
31
|
+
return this._outputSchema === void 0 ? this._outputSchema = schemaConfig.outputSchema.call(this) : this._outputSchema;
|
|
32
|
+
}
|
|
33
|
+
static querySchema() {
|
|
34
|
+
return this._querySchema === void 0 ? this._querySchema = schemaConfig.querySchema.call(this) : this._querySchema;
|
|
35
|
+
}
|
|
36
|
+
static updateSchema() {
|
|
37
|
+
return this._updateSchema === void 0 ? this._updateSchema = schemaConfig.updateSchema.call(this) : this._updateSchema;
|
|
38
|
+
}
|
|
39
|
+
static pkeySchema() {
|
|
40
|
+
return this._pkeySchema === void 0 ? this._pkeySchema = schemaConfig.pkeySchema.call(this) : this._pkeySchema;
|
|
41
|
+
}
|
|
34
42
|
static getFilePath() {
|
|
35
43
|
if (filePath)
|
|
36
44
|
return filePath;
|
|
@@ -77,7 +85,7 @@ function createBaseTable({
|
|
|
77
85
|
}
|
|
78
86
|
}
|
|
79
87
|
}
|
|
80
|
-
return shape;
|
|
88
|
+
return this.constructor.prototype.columns = shape;
|
|
81
89
|
}
|
|
82
90
|
setComputed(computed) {
|
|
83
91
|
return computed;
|
|
@@ -113,7 +121,7 @@ function createBaseTable({
|
|
|
113
121
|
options
|
|
114
122
|
};
|
|
115
123
|
}
|
|
116
|
-
}, _a.nowSQL = nowSQL, _a.exportAs = exportAs, _a
|
|
124
|
+
}, _a.nowSQL = nowSQL, _a.exportAs = exportAs, _a);
|
|
117
125
|
orchidCore.applyMixins(base, [pqb.QueryHooks]);
|
|
118
126
|
base.prototype.types = columnTypes;
|
|
119
127
|
return base;
|
|
@@ -226,8 +234,8 @@ const joinQueryChainingHOF = (reverseJoin, joinQuery) => (joiningQuery, baseQuer
|
|
|
226
234
|
};
|
|
227
235
|
|
|
228
236
|
class BelongsToVirtualColumn extends pqb.VirtualColumn {
|
|
229
|
-
constructor(key, state) {
|
|
230
|
-
super();
|
|
237
|
+
constructor(schema, key, state) {
|
|
238
|
+
super(schema);
|
|
231
239
|
this.key = key;
|
|
232
240
|
this.state = state;
|
|
233
241
|
this.nestedInsert = nestedInsert$3(this.state);
|
|
@@ -304,7 +312,11 @@ const makeBelongsToMethod = (relation, relationName, query) => {
|
|
|
304
312
|
method(params) {
|
|
305
313
|
return query.where(makeWhere(params));
|
|
306
314
|
},
|
|
307
|
-
virtualColumn: new BelongsToVirtualColumn(
|
|
315
|
+
virtualColumn: new BelongsToVirtualColumn(
|
|
316
|
+
pqb.defaultSchemaConfig,
|
|
317
|
+
relationName,
|
|
318
|
+
state
|
|
319
|
+
),
|
|
308
320
|
joinQuery: joinQueryChainingHOF(
|
|
309
321
|
reverseJoin,
|
|
310
322
|
(joiningQuery, baseQuery) => join(baseQuery, joiningQuery, primaryKeys, foreignKeys)
|
|
@@ -505,8 +517,8 @@ var __spreadValues$5 = (a, b) => {
|
|
|
505
517
|
return a;
|
|
506
518
|
};
|
|
507
519
|
class HasOneVirtualColumn extends pqb.VirtualColumn {
|
|
508
|
-
constructor(key, state) {
|
|
509
|
-
super();
|
|
520
|
+
constructor(schema, key, state) {
|
|
521
|
+
super(schema);
|
|
510
522
|
this.key = key;
|
|
511
523
|
this.state = state;
|
|
512
524
|
this.nestedInsert = nestedInsert$2(state);
|
|
@@ -603,7 +615,11 @@ const makeHasOneMethod = (table, relation, relationName, query) => {
|
|
|
603
615
|
}
|
|
604
616
|
return query.where(values)._defaults(values);
|
|
605
617
|
},
|
|
606
|
-
virtualColumn: new HasOneVirtualColumn(
|
|
618
|
+
virtualColumn: new HasOneVirtualColumn(
|
|
619
|
+
pqb.defaultSchemaConfig,
|
|
620
|
+
relationName,
|
|
621
|
+
state
|
|
622
|
+
),
|
|
607
623
|
joinQuery: joinQueryChainingHOF(
|
|
608
624
|
reverseJoin,
|
|
609
625
|
(joiningQuery, baseQuery) => joinHasRelation(baseQuery, joiningQuery, primaryKeys, foreignKeys, len)
|
|
@@ -749,8 +765,8 @@ var __spreadValues$4 = (a, b) => {
|
|
|
749
765
|
return a;
|
|
750
766
|
};
|
|
751
767
|
class HasManyVirtualColumn extends pqb.VirtualColumn {
|
|
752
|
-
constructor(key, state) {
|
|
753
|
-
super();
|
|
768
|
+
constructor(schema, key, state) {
|
|
769
|
+
super(schema);
|
|
754
770
|
this.key = key;
|
|
755
771
|
this.state = state;
|
|
756
772
|
this.nestedInsert = nestedInsert$1(state);
|
|
@@ -851,7 +867,11 @@ const makeHasManyMethod = (table, relation, relationName, query) => {
|
|
|
851
867
|
}
|
|
852
868
|
return query.where(values)._defaults(values);
|
|
853
869
|
},
|
|
854
|
-
virtualColumn: new HasManyVirtualColumn(
|
|
870
|
+
virtualColumn: new HasManyVirtualColumn(
|
|
871
|
+
pqb.defaultSchemaConfig,
|
|
872
|
+
relationName,
|
|
873
|
+
state
|
|
874
|
+
),
|
|
855
875
|
joinQuery: joinQueryChainingHOF(
|
|
856
876
|
reverseJoin,
|
|
857
877
|
(joiningQuery, baseQuery) => joinHasRelation(baseQuery, joiningQuery, primaryKeys, foreignKeys, len)
|
|
@@ -1042,8 +1062,8 @@ var __spreadValues$3 = (a, b) => {
|
|
|
1042
1062
|
};
|
|
1043
1063
|
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
1044
1064
|
class HasAndBelongsToManyVirtualColumn extends pqb.VirtualColumn {
|
|
1045
|
-
constructor(key, state) {
|
|
1046
|
-
super();
|
|
1065
|
+
constructor(schema, key, state) {
|
|
1066
|
+
super(schema);
|
|
1047
1067
|
this.key = key;
|
|
1048
1068
|
this.state = state;
|
|
1049
1069
|
this.nestedInsert = nestedInsert(state);
|
|
@@ -1112,7 +1132,9 @@ const makeHasAndBelongsToManyMethod = (table, qb, relation, relationName, query)
|
|
|
1112
1132
|
baseQuery.table = joinTable;
|
|
1113
1133
|
const shape = {};
|
|
1114
1134
|
for (let i = 0; i < len; i++) {
|
|
1115
|
-
shape[foreignKeys[i]] = removeColumnName(
|
|
1135
|
+
shape[foreignKeys[i]] = removeColumnName(
|
|
1136
|
+
table.shape[primaryKeys[i]]
|
|
1137
|
+
);
|
|
1116
1138
|
}
|
|
1117
1139
|
for (let i = 0; i < throughLen; i++) {
|
|
1118
1140
|
shape[throughForeignKeys[i]] = removeColumnName(
|
|
@@ -1176,7 +1198,11 @@ const makeHasAndBelongsToManyMethod = (table, qb, relation, relationName, query)
|
|
|
1176
1198
|
return q._where(where);
|
|
1177
1199
|
});
|
|
1178
1200
|
},
|
|
1179
|
-
virtualColumn: new HasAndBelongsToManyVirtualColumn(
|
|
1201
|
+
virtualColumn: new HasAndBelongsToManyVirtualColumn(
|
|
1202
|
+
pqb.defaultSchemaConfig,
|
|
1203
|
+
relationName,
|
|
1204
|
+
state
|
|
1205
|
+
),
|
|
1180
1206
|
joinQuery: joinQueryChainingHOF(reverseJoin, (joiningQuery, baseQuery2) => {
|
|
1181
1207
|
const joined = joinQuery(
|
|
1182
1208
|
joiningQuery,
|
|
@@ -1735,7 +1761,7 @@ const orchidORM = (_a, tables) => {
|
|
|
1735
1761
|
void 0,
|
|
1736
1762
|
void 0,
|
|
1737
1763
|
pqb.anyShape,
|
|
1738
|
-
pqb.
|
|
1764
|
+
pqb.makeColumnTypes(pqb.defaultSchemaConfig),
|
|
1739
1765
|
transactionStorage,
|
|
1740
1766
|
commonOptions
|
|
1741
1767
|
);
|
|
@@ -1760,7 +1786,8 @@ const orchidORM = (_a, tables) => {
|
|
|
1760
1786
|
const options2 = __spreadProps(__spreadValues$1({}, commonOptions), {
|
|
1761
1787
|
schema: table.schema,
|
|
1762
1788
|
language: table.language,
|
|
1763
|
-
scopes: table.scopes
|
|
1789
|
+
scopes: table.scopes,
|
|
1790
|
+
softDelete: table.softDelete
|
|
1764
1791
|
});
|
|
1765
1792
|
if (table.noPrimaryKey)
|
|
1766
1793
|
options2.noPrimaryKey = "ignore";
|