orchid-orm 1.50.4 → 1.50.5
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 +4 -16
- package/dist/index.js +9 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -8
- package/dist/index.mjs.map +1 -1
- package/dist/migrations.js +6 -4
- package/dist/migrations.js.map +1 -1
- package/dist/migrations.mjs +7 -5
- package/dist/migrations.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -417,18 +417,6 @@ interface RelationConfigSelf {
|
|
|
417
417
|
relations: RelationThunks;
|
|
418
418
|
}
|
|
419
419
|
type RelationConfigParams<T extends RelationConfigSelf, Relation extends RelationThunk> = Relation extends BelongsTo ? BelongsToParams<T, Relation> : Relation extends HasOne | HasMany ? HasOneParams<T, Relation> : Relation extends HasAndBelongsToMany ? HasAndBelongsToManyParams<T, Relation> : never;
|
|
420
|
-
type MapRelation<T extends RelationConfigSelf, K extends keyof T['relations'] & string> = T['relations'][K] extends BelongsTo ? {
|
|
421
|
-
relationConfig: BelongsToInfo<T, K, T['relations'][K], T['relations'][K]['options']['columns'][number] & string, T['relations'][K]['options']['required'], BelongsToQuery<RelationTableToQuery<T['relations'][K]>, K>>;
|
|
422
|
-
} : T['relations'][K] extends HasOne ? {
|
|
423
|
-
relationConfig: HasOneInfo<T, K, T['relations'][K], HasOneQuery<T, K, RelationTableToQuery<T['relations'][K]>>>;
|
|
424
|
-
} : T['relations'][K] extends HasMany ? {
|
|
425
|
-
relationConfig: HasManyInfo<T, K, T['relations'][K], HasOneQuery<T, K, RelationTableToQuery<T['relations'][K]>>>;
|
|
426
|
-
} : T['relations'][K] extends HasAndBelongsToMany ? {
|
|
427
|
-
relationConfig: HasAndBelongsToManyInfo<T, K, T['relations'][K], HasAndBelongsToManyQuery<K, RelationTableToQuery<T['relations'][K]>>>;
|
|
428
|
-
} : never;
|
|
429
|
-
type MapRelations<T> = T extends RelationConfigSelf ? {
|
|
430
|
-
[K in keyof T['relations'] & string]: MapRelation<T, K>;
|
|
431
|
-
} : EmptyObject;
|
|
432
420
|
|
|
433
421
|
interface TableClass<T extends ORMTableInput = ORMTableInput> {
|
|
434
422
|
new (): T;
|
|
@@ -446,11 +434,11 @@ interface TableInfo {
|
|
|
446
434
|
interface Table extends Query, TableInfo {
|
|
447
435
|
}
|
|
448
436
|
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>> {
|
|
449
|
-
relations:
|
|
450
|
-
[K in keyof Relations]: Relations[K]['relationConfig']['query'] & Relations[K];
|
|
451
|
-
};
|
|
437
|
+
relations: Relations;
|
|
452
438
|
}
|
|
453
|
-
type ORMTableInputToQueryBuilder<T extends ORMTableInput> = T extends RelationConfigSelf ? TableToDb<T,
|
|
439
|
+
type ORMTableInputToQueryBuilder<T extends ORMTableInput> = T extends RelationConfigSelf ? TableToDb<T, T extends RelationConfigSelf ? {
|
|
440
|
+
[K in keyof T['relations'] & string]: T['relations'][K] extends BelongsTo ? BelongsToInfo<T, K, T['relations'][K], T['relations'][K]['options']['columns'][number] & string, T['relations'][K]['options']['required'], BelongsToQuery<RelationTableToQuery<T['relations'][K]>, K>> : T['relations'][K] extends HasOne ? HasOneInfo<T, K, T['relations'][K], HasOneQuery<T, K, RelationTableToQuery<T['relations'][K]>>> : T['relations'][K] extends HasMany ? HasManyInfo<T, K, T['relations'][K], HasOneQuery<T, K, RelationTableToQuery<T['relations'][K]>>> : T['relations'][K] extends HasAndBelongsToMany ? HasAndBelongsToManyInfo<T, K, T['relations'][K], HasAndBelongsToManyQuery<K, RelationTableToQuery<T['relations'][K]>>> : never;
|
|
441
|
+
} : EmptyObject> : TableToDb<T, EmptyObject>;
|
|
454
442
|
interface ORMTableInput {
|
|
455
443
|
table: string;
|
|
456
444
|
columns: {
|
package/dist/index.js
CHANGED
|
@@ -89,7 +89,7 @@ function createBaseTable({
|
|
|
89
89
|
setColumns(fn, dataFn) {
|
|
90
90
|
columnTypes[orchidCore.snakeCaseKey] = this.snakeCase;
|
|
91
91
|
const shape = pqb.getColumnTypes(columnTypes, fn, nowSQL, this.language);
|
|
92
|
-
const tableData =
|
|
92
|
+
const tableData = pqb.parseTableData(dataFn);
|
|
93
93
|
if (this.snakeCase) {
|
|
94
94
|
for (const key in shape) {
|
|
95
95
|
const column = shape[key];
|
|
@@ -148,10 +148,10 @@ function createBaseTable({
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
const getThroughRelation = (table, through) => {
|
|
151
|
-
return table.relations[through]
|
|
151
|
+
return table.relations[through];
|
|
152
152
|
};
|
|
153
153
|
const getSourceRelation = (throughRelation, source) => {
|
|
154
|
-
return throughRelation.query.relations[source]
|
|
154
|
+
return throughRelation.query.relations[source];
|
|
155
155
|
};
|
|
156
156
|
const hasRelationHandleCreate = (q, ctx, item, rowIndex, key, primaryKeys, nestedInsert) => {
|
|
157
157
|
const value = item[key];
|
|
@@ -297,7 +297,8 @@ const joinQueryChainHOF = (relPKeys, reverseJoin, joinQuery) => (joiningQuery, b
|
|
|
297
297
|
return joinQuery(jq, baseQuery);
|
|
298
298
|
}
|
|
299
299
|
const last = chain[chain.length - 1];
|
|
300
|
-
const
|
|
300
|
+
const prev = chain[chain.length - 2];
|
|
301
|
+
const query = prev.rel.joinQuery(last.query, baseQuery);
|
|
301
302
|
let useWhereExist = true;
|
|
302
303
|
if (jq.q.returnType !== "value" && jq.q.returnType !== "valueOrThrow") {
|
|
303
304
|
let tablePrefix;
|
|
@@ -1958,7 +1959,7 @@ const applyRelations = (qb, tables, result) => {
|
|
|
1958
1959
|
let message = `Cannot define a \`${item.relationName}\` relation on \`${as}\``;
|
|
1959
1960
|
const table = result[as];
|
|
1960
1961
|
const { through, source } = relation.options;
|
|
1961
|
-
const throughRel = table.relations[through]
|
|
1962
|
+
const throughRel = table.relations[through];
|
|
1962
1963
|
if (through && !throughRel) {
|
|
1963
1964
|
message += `: cannot find \`${through}\` relation required by the \`through\` option`;
|
|
1964
1965
|
} else if (source && throughRel && !throughRel.table.relations[source]) {
|
|
@@ -2033,7 +2034,7 @@ const applyRelation = (table, qb, { relationName, relation, dbTable, otherDbTabl
|
|
|
2033
2034
|
return q;
|
|
2034
2035
|
}
|
|
2035
2036
|
};
|
|
2036
|
-
|
|
2037
|
+
dbTable.relations[relationName] = {
|
|
2037
2038
|
table: otherDbTable,
|
|
2038
2039
|
query,
|
|
2039
2040
|
queryRelated: data.queryRelated,
|
|
@@ -2041,7 +2042,7 @@ const applyRelation = (table, qb, { relationName, relation, dbTable, otherDbTabl
|
|
|
2041
2042
|
reverseJoin: data.reverseJoin,
|
|
2042
2043
|
modifyRelatedQuery: data.modifyRelatedQuery
|
|
2043
2044
|
};
|
|
2044
|
-
dbTable.
|
|
2045
|
+
(dbTable.relationQueries ?? (dbTable.relationQueries = {}))[relationName] = query;
|
|
2045
2046
|
const tableRelations = delayedRelations.get(dbTable);
|
|
2046
2047
|
if (!tableRelations) return;
|
|
2047
2048
|
tableRelations[relationName]?.forEach((data2) => {
|
|
@@ -2140,7 +2141,7 @@ const orchidORM = ({
|
|
|
2140
2141
|
table.types,
|
|
2141
2142
|
transactionStorage,
|
|
2142
2143
|
options2,
|
|
2143
|
-
table.constructor.prototype.
|
|
2144
|
+
table.constructor.prototype.columns?.data ?? {}
|
|
2144
2145
|
);
|
|
2145
2146
|
dbTable.definedAs = key;
|
|
2146
2147
|
dbTable.db = result;
|