@prisma-next/sql-orm-client 0.9.0 → 0.10.0-dev.2
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.mts +11 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +15 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +20 -20
- package/src/collection-contract.ts +11 -4
- package/src/model-accessor.ts +6 -2
- package/src/query-plan-meta.ts +5 -2
- package/src/query-plan-mutations.ts +10 -3
- package/src/types.ts +26 -27
- package/src/where-binding.ts +9 -2
package/package.json
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/sql-orm-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0-dev.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "ORM client for Prisma Next — fluent, type-safe model collections",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@prisma-next/contract": "0.
|
|
10
|
-
"@prisma-next/framework-components": "0.
|
|
11
|
-
"@prisma-next/operations": "0.
|
|
12
|
-
"@prisma-next/sql-contract": "0.
|
|
13
|
-
"@prisma-next/sql-operations": "0.
|
|
14
|
-
"@prisma-next/sql-relational-core": "0.
|
|
15
|
-
"@prisma-next/sql-runtime": "0.
|
|
16
|
-
"@prisma-next/utils": "0.
|
|
9
|
+
"@prisma-next/contract": "0.10.0-dev.2",
|
|
10
|
+
"@prisma-next/framework-components": "0.10.0-dev.2",
|
|
11
|
+
"@prisma-next/operations": "0.10.0-dev.2",
|
|
12
|
+
"@prisma-next/sql-contract": "0.10.0-dev.2",
|
|
13
|
+
"@prisma-next/sql-operations": "0.10.0-dev.2",
|
|
14
|
+
"@prisma-next/sql-relational-core": "0.10.0-dev.2",
|
|
15
|
+
"@prisma-next/sql-runtime": "0.10.0-dev.2",
|
|
16
|
+
"@prisma-next/utils": "0.10.0-dev.2"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@prisma-next/adapter-postgres": "0.
|
|
20
|
-
"@prisma-next/driver-postgres": "0.
|
|
21
|
-
"@prisma-next/cli": "0.
|
|
22
|
-
"@prisma-next/extension-pgvector": "0.
|
|
23
|
-
"@prisma-next/family-sql": "0.
|
|
24
|
-
"@prisma-next/ids": "0.
|
|
25
|
-
"@prisma-next/sql-contract-ts": "0.
|
|
26
|
-
"@prisma-next/target-postgres": "0.
|
|
27
|
-
"@prisma-next/test-utils": "0.
|
|
28
|
-
"@prisma-next/tsconfig": "0.
|
|
29
|
-
"@prisma-next/tsdown": "0.
|
|
19
|
+
"@prisma-next/adapter-postgres": "0.10.0-dev.2",
|
|
20
|
+
"@prisma-next/driver-postgres": "0.10.0-dev.2",
|
|
21
|
+
"@prisma-next/cli": "0.10.0-dev.2",
|
|
22
|
+
"@prisma-next/extension-pgvector": "0.10.0-dev.2",
|
|
23
|
+
"@prisma-next/family-sql": "0.10.0-dev.2",
|
|
24
|
+
"@prisma-next/ids": "0.10.0-dev.2",
|
|
25
|
+
"@prisma-next/sql-contract-ts": "0.10.0-dev.2",
|
|
26
|
+
"@prisma-next/target-postgres": "0.10.0-dev.2",
|
|
27
|
+
"@prisma-next/test-utils": "0.10.0-dev.2",
|
|
28
|
+
"@prisma-next/tsconfig": "0.10.0-dev.2",
|
|
29
|
+
"@prisma-next/tsdown": "0.10.0-dev.2",
|
|
30
30
|
"@types/pg": "8.20.0",
|
|
31
31
|
"pg": "8.20.0",
|
|
32
32
|
"tsdown": "0.22.0",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Contract, ContractFieldType } from '@prisma-next/contract/types';
|
|
2
|
-
import
|
|
2
|
+
import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
|
|
3
|
+
import type { SqlStorage, StorageTable } from '@prisma-next/sql-contract/types';
|
|
3
4
|
import type { RelationCardinalityTag } from './types';
|
|
4
5
|
|
|
5
6
|
type ModelStorageFields = Record<string, { column?: string }>;
|
|
@@ -29,6 +30,12 @@ export interface PolymorphismInfo {
|
|
|
29
30
|
readonly mtiVariants: readonly PolymorphismVariantInfo[];
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
function unboundTable(contract: Contract<SqlStorage>, tableName: string): StorageTable | undefined {
|
|
34
|
+
return contract.storage.namespaces[UNBOUND_NAMESPACE_ID]?.tables[tableName] as
|
|
35
|
+
| StorageTable
|
|
36
|
+
| undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
32
39
|
function modelsOf(contract: Contract<SqlStorage>): ModelsMap {
|
|
33
40
|
return contract.models as ModelsMap;
|
|
34
41
|
}
|
|
@@ -303,7 +310,7 @@ export function resolveUpsertConflictColumns(
|
|
|
303
310
|
}
|
|
304
311
|
|
|
305
312
|
const tableName = resolveModelTableName(contract, modelName);
|
|
306
|
-
const primaryKeyColumns = contract
|
|
313
|
+
const primaryKeyColumns = unboundTable(contract, tableName)?.primaryKey?.columns ?? [];
|
|
307
314
|
return [...primaryKeyColumns];
|
|
308
315
|
}
|
|
309
316
|
|
|
@@ -319,14 +326,14 @@ export function resolveModelTableName(contract: Contract<SqlStorage>, modelName:
|
|
|
319
326
|
}
|
|
320
327
|
|
|
321
328
|
export function resolvePrimaryKeyColumn(contract: Contract<SqlStorage>, tableName: string): string {
|
|
322
|
-
return contract
|
|
329
|
+
return unboundTable(contract, tableName)?.primaryKey?.columns[0] ?? 'id';
|
|
323
330
|
}
|
|
324
331
|
|
|
325
332
|
export function resolveRowIdentityColumns(
|
|
326
333
|
contract: Contract<SqlStorage>,
|
|
327
334
|
tableName: string,
|
|
328
335
|
): readonly string[] {
|
|
329
|
-
const table = contract
|
|
336
|
+
const table = unboundTable(contract, tableName);
|
|
330
337
|
if (!table) {
|
|
331
338
|
return [];
|
|
332
339
|
}
|
package/src/model-accessor.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Contract } from '@prisma-next/contract/types';
|
|
2
|
-
import
|
|
2
|
+
import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
|
|
3
|
+
import type { SqlStorage, StorageTable } from '@prisma-next/sql-contract/types';
|
|
3
4
|
import type { SqlOperationEntry } from '@prisma-next/sql-operations';
|
|
4
5
|
import {
|
|
5
6
|
AndExpr,
|
|
@@ -126,7 +127,10 @@ function resolveColumn(
|
|
|
126
127
|
tableName: string,
|
|
127
128
|
columnName: string,
|
|
128
129
|
): { readonly codecId: string; readonly nullable: boolean } | undefined {
|
|
129
|
-
const
|
|
130
|
+
const table = contract.storage.namespaces[UNBOUND_NAMESPACE_ID]?.tables[tableName] as
|
|
131
|
+
| StorageTable
|
|
132
|
+
| undefined;
|
|
133
|
+
const column = table?.columns?.[columnName];
|
|
130
134
|
if (!column) return undefined;
|
|
131
135
|
return { codecId: column.codecId, nullable: column.nullable };
|
|
132
136
|
}
|
package/src/query-plan-meta.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Contract, PlanMeta } from '@prisma-next/contract/types';
|
|
2
|
+
import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
|
|
2
3
|
import type { AnnotationValue, OperationKind } from '@prisma-next/framework-components/runtime';
|
|
3
|
-
import type { SqlStorage } from '@prisma-next/sql-contract/types';
|
|
4
|
+
import type { SqlStorage, StorageTable } from '@prisma-next/sql-contract/types';
|
|
4
5
|
import { type AnyQueryAst, collectOrderedParamRefs } from '@prisma-next/sql-relational-core/ast';
|
|
5
6
|
import type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';
|
|
6
7
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
@@ -14,7 +15,9 @@ export function deriveParamsFromAst(ast: AnyQueryAst): {
|
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export function resolveTableColumns(contract: Contract<SqlStorage>, tableName: string): string[] {
|
|
17
|
-
const table = contract.storage.tables[tableName]
|
|
18
|
+
const table = contract.storage.namespaces[UNBOUND_NAMESPACE_ID]?.tables[tableName] as
|
|
19
|
+
| StorageTable
|
|
20
|
+
| undefined;
|
|
18
21
|
if (!table) {
|
|
19
22
|
throw new Error(`Unknown table "${tableName}" in SQL ORM query planner`);
|
|
20
23
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Contract } from '@prisma-next/contract/types';
|
|
2
|
-
import
|
|
2
|
+
import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
|
|
3
|
+
import type { SqlStorage, StorageTable } from '@prisma-next/sql-contract/types';
|
|
3
4
|
import {
|
|
4
5
|
type AnyExpression,
|
|
5
6
|
ColumnRef,
|
|
@@ -18,6 +19,12 @@ import { ifDefined } from '@prisma-next/utils/defined';
|
|
|
18
19
|
import { buildOrmQueryPlan, deriveParamsFromAst, resolveTableColumns } from './query-plan-meta';
|
|
19
20
|
import { combineWhereExprs } from './where-utils';
|
|
20
21
|
|
|
22
|
+
function unboundTable(contract: Contract<SqlStorage>, tableName: string): StorageTable | undefined {
|
|
23
|
+
return contract.storage.namespaces[UNBOUND_NAMESPACE_ID]?.tables[tableName] as
|
|
24
|
+
| StorageTable
|
|
25
|
+
| undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
21
28
|
function buildReturningColumns(
|
|
22
29
|
contract: Contract<SqlStorage>,
|
|
23
30
|
tableName: string,
|
|
@@ -46,7 +53,7 @@ function toParamAssignments(
|
|
|
46
53
|
} {
|
|
47
54
|
const assignments: Record<string, ParamRef> = {};
|
|
48
55
|
|
|
49
|
-
const table = contract
|
|
56
|
+
const table = unboundTable(contract, tableName);
|
|
50
57
|
if (!table) {
|
|
51
58
|
throw new Error(`Unknown table "${tableName}"`);
|
|
52
59
|
}
|
|
@@ -89,7 +96,7 @@ function normalizeInsertRows(
|
|
|
89
96
|
}
|
|
90
97
|
}
|
|
91
98
|
|
|
92
|
-
const table = contract
|
|
99
|
+
const table = unboundTable(contract, tableName);
|
|
93
100
|
if (!table) {
|
|
94
101
|
throw new Error(`Unknown table "${tableName}"`);
|
|
95
102
|
}
|
package/src/types.ts
CHANGED
|
@@ -577,6 +577,16 @@ type FieldColumnName<
|
|
|
577
577
|
: FieldName) &
|
|
578
578
|
string;
|
|
579
579
|
|
|
580
|
+
type NamespaceTableDef<TContract extends Contract<SqlStorage>, TableName extends string> = {
|
|
581
|
+
[K in keyof TContract['storage']['namespaces']]: TContract['storage']['namespaces'][K] extends {
|
|
582
|
+
readonly tables: infer Tables;
|
|
583
|
+
}
|
|
584
|
+
? TableName extends keyof Tables
|
|
585
|
+
? Tables[TableName]
|
|
586
|
+
: never
|
|
587
|
+
: never;
|
|
588
|
+
}[keyof TContract['storage']['namespaces']];
|
|
589
|
+
|
|
580
590
|
type ResolvedStorageColumn<
|
|
581
591
|
TContract extends Contract<SqlStorage>,
|
|
582
592
|
ModelName extends string,
|
|
@@ -584,15 +594,10 @@ type ResolvedStorageColumn<
|
|
|
584
594
|
> =
|
|
585
595
|
ModelTableName<TContract, ModelName> extends infer TableName extends string
|
|
586
596
|
? FieldColumnName<TContract, ModelName, FieldName> extends infer ColName extends string
|
|
587
|
-
? TContract
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
? TableName extends keyof TContract['storage']['tables']
|
|
592
|
-
? ColName extends keyof TContract['storage']['tables'][TableName]['columns']
|
|
593
|
-
? TContract['storage']['tables'][TableName]['columns'][ColName] extends StorageColumn
|
|
594
|
-
? TContract['storage']['tables'][TableName]['columns'][ColName]
|
|
595
|
-
: never
|
|
597
|
+
? NamespaceTableDef<TContract, TableName> extends { readonly columns: infer Columns }
|
|
598
|
+
? ColName extends keyof Columns
|
|
599
|
+
? Columns[ColName] extends StorageColumn
|
|
600
|
+
? Columns[ColName]
|
|
596
601
|
: never
|
|
597
602
|
: never
|
|
598
603
|
: never
|
|
@@ -787,11 +792,7 @@ export type ResolvedCreateInput<
|
|
|
787
792
|
|
|
788
793
|
type ModelStorageTableDef<TContract extends Contract<SqlStorage>, ModelName extends string> =
|
|
789
794
|
ModelTableName<TContract, ModelName> extends infer TableName extends string
|
|
790
|
-
? TContract
|
|
791
|
-
? TableName extends keyof TContract['storage']['tables']
|
|
792
|
-
? TContract['storage']['tables'][TableName]
|
|
793
|
-
: never
|
|
794
|
-
: never
|
|
795
|
+
? NamespaceTableDef<TContract, TableName>
|
|
795
796
|
: never;
|
|
796
797
|
|
|
797
798
|
type PrimaryKeyConstraintColumns<TContract extends Contract<SqlStorage>, ModelName extends string> =
|
|
@@ -1112,7 +1113,7 @@ type HasForeignKeyForCols<
|
|
|
1112
1113
|
FKs extends readonly unknown[],
|
|
1113
1114
|
Cols extends readonly string[],
|
|
1114
1115
|
> = FKs extends readonly [infer Head, ...infer Tail extends unknown[]]
|
|
1115
|
-
? Head extends { readonly columns: Cols }
|
|
1116
|
+
? Head extends { readonly source: { readonly columns: Cols } }
|
|
1116
1117
|
? true
|
|
1117
1118
|
: HasForeignKeyForCols<Tail, Cols>
|
|
1118
1119
|
: false;
|
|
@@ -1130,18 +1131,16 @@ type IsToOneRelationNullable<
|
|
|
1130
1131
|
RelName extends string,
|
|
1131
1132
|
> =
|
|
1132
1133
|
ModelTableName<TContract, ModelName> extends infer TableName extends string
|
|
1133
|
-
? TableName extends
|
|
1134
|
-
? TContract
|
|
1135
|
-
?
|
|
1136
|
-
?
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
?
|
|
1143
|
-
? AnyColumnNullable<Table['columns'], Cols>
|
|
1144
|
-
: true
|
|
1134
|
+
? NamespaceTableDef<TContract, TableName> extends infer Table extends StorageTable
|
|
1135
|
+
? RelationsOf<TContract, ModelName> extends infer Rels extends Record<string, unknown>
|
|
1136
|
+
? RelName extends keyof Rels
|
|
1137
|
+
? RelationLocalFieldColumns<
|
|
1138
|
+
TContract,
|
|
1139
|
+
ModelName,
|
|
1140
|
+
Rels[RelName]
|
|
1141
|
+
> extends infer Cols extends readonly string[]
|
|
1142
|
+
? IsFkSideOfRelation<Table, Cols> extends true
|
|
1143
|
+
? AnyColumnNullable<Table['columns'], Cols>
|
|
1145
1144
|
: true
|
|
1146
1145
|
: true
|
|
1147
1146
|
: true
|
package/src/where-binding.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Contract } from '@prisma-next/contract/types';
|
|
2
|
-
import
|
|
2
|
+
import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
|
|
3
|
+
import type { SqlStorage, StorageTable } from '@prisma-next/sql-contract/types';
|
|
3
4
|
import {
|
|
4
5
|
AndExpr,
|
|
5
6
|
type AnyExpression,
|
|
@@ -122,7 +123,13 @@ function createParamRef(
|
|
|
122
123
|
columnRef: ColumnRef,
|
|
123
124
|
value: unknown,
|
|
124
125
|
): ParamRef {
|
|
125
|
-
if (
|
|
126
|
+
if (
|
|
127
|
+
!(
|
|
128
|
+
contract.storage.namespaces[UNBOUND_NAMESPACE_ID]?.tables[columnRef.table] as
|
|
129
|
+
| StorageTable
|
|
130
|
+
| undefined
|
|
131
|
+
)?.columns[columnRef.column]
|
|
132
|
+
) {
|
|
126
133
|
throw new Error(`Unknown column "${columnRef.column}" in table "${columnRef.table}"`);
|
|
127
134
|
}
|
|
128
135
|
const codec = codecRefForStorageColumn(contract.storage, columnRef.table, columnRef.column);
|