@prisma-next/sql-builder 0.0.1 → 0.3.0-dev.162
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/LICENSE +201 -0
- package/dist/db-C7A7Y4tB.d.mts +348 -0
- package/dist/db-C7A7Y4tB.d.mts.map +1 -0
- package/dist/exports/types.d.mts +2 -0
- package/dist/exports/types.mjs +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1 -0
- package/dist/runtime/index.d.mts +35 -0
- package/dist/runtime/index.d.mts.map +1 -0
- package/dist/runtime/index.mjs +765 -0
- package/dist/runtime/index.mjs.map +1 -0
- package/package.json +30 -36
- package/src/exports/types.ts +1 -1
- package/src/resolve.ts +17 -7
- package/src/runtime/builder-base.ts +2 -2
- package/src/runtime/functions.ts +5 -6
- package/src/runtime/index.ts +1 -0
- package/src/runtime/mutation-impl.ts +18 -6
- package/src/runtime/query-impl.ts +5 -2
- package/src/runtime/sql.ts +5 -4
- package/src/scope.ts +1 -0
- package/src/types/mutation-query.ts +3 -3
- package/src/types/shared.ts +1 -1
- package/src/types/table-proxy.ts +114 -11
package/src/types/table-proxy.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
ExtractCodecTypes,
|
|
3
|
+
ExtractFieldInputTypes,
|
|
4
|
+
ExtractFieldOutputTypes,
|
|
3
5
|
ExtractQueryOperationTypes,
|
|
6
|
+
StorageTable,
|
|
4
7
|
} from '@prisma-next/sql-contract/types';
|
|
5
8
|
import type {
|
|
6
9
|
DefaultScope,
|
|
@@ -12,19 +15,107 @@ import type {
|
|
|
12
15
|
StorageTableToScopeTable,
|
|
13
16
|
} from '../scope';
|
|
14
17
|
import type { TableProxyContract } from './db';
|
|
15
|
-
import type {
|
|
16
|
-
DeleteQuery,
|
|
17
|
-
InsertQuery,
|
|
18
|
-
InsertValues,
|
|
19
|
-
UpdateQuery,
|
|
20
|
-
UpdateValues,
|
|
21
|
-
} from './mutation-query';
|
|
18
|
+
import type { DeleteQuery, InsertQuery, InsertValues, UpdateQuery } from './mutation-query';
|
|
22
19
|
import type { WithJoin, WithSelect } from './shared';
|
|
23
20
|
|
|
24
|
-
type
|
|
21
|
+
type FindModelForTable<C, TableName extends string> = C extends {
|
|
22
|
+
readonly models: infer Models extends Record<
|
|
23
|
+
string,
|
|
24
|
+
{ readonly storage: { readonly table: string } }
|
|
25
|
+
>;
|
|
26
|
+
}
|
|
27
|
+
? {
|
|
28
|
+
[M in keyof Models & string]: Models[M]['storage']['table'] extends TableName ? M : never;
|
|
29
|
+
}[keyof Models & string]
|
|
30
|
+
: never;
|
|
31
|
+
|
|
32
|
+
type FindFieldForColumn<C, ModelName extends string, ColumnName extends string> = C extends {
|
|
33
|
+
readonly models: infer Models extends Record<
|
|
34
|
+
string,
|
|
35
|
+
{ readonly storage: { readonly fields: Record<string, { readonly column: string }> } }
|
|
36
|
+
>;
|
|
37
|
+
}
|
|
38
|
+
? ModelName extends keyof Models
|
|
39
|
+
? {
|
|
40
|
+
[F in keyof Models[ModelName]['storage']['fields'] &
|
|
41
|
+
string]: Models[ModelName]['storage']['fields'][F]['column'] extends ColumnName
|
|
42
|
+
? F
|
|
43
|
+
: never;
|
|
44
|
+
}[keyof Models[ModelName]['storage']['fields'] & string]
|
|
45
|
+
: never
|
|
46
|
+
: never;
|
|
47
|
+
|
|
48
|
+
type ResolvedColumnTypes<
|
|
49
|
+
C,
|
|
50
|
+
TableName extends string,
|
|
51
|
+
FieldTypes extends Record<string, Record<string, unknown>>,
|
|
52
|
+
> = string extends keyof FieldTypes
|
|
53
|
+
? Record<string, never>
|
|
54
|
+
: FindModelForTable<C, TableName> extends infer ModelName extends string
|
|
55
|
+
? ModelName extends keyof FieldTypes
|
|
56
|
+
? C extends {
|
|
57
|
+
readonly storage: { readonly tables: infer Tables extends Record<string, StorageTable> };
|
|
58
|
+
}
|
|
59
|
+
? TableName extends keyof Tables
|
|
60
|
+
? {
|
|
61
|
+
[ColName in keyof Tables[TableName]['columns'] & string]: FindFieldForColumn<
|
|
62
|
+
C,
|
|
63
|
+
ModelName,
|
|
64
|
+
ColName
|
|
65
|
+
> extends infer FieldName extends string
|
|
66
|
+
? FieldName extends keyof FieldTypes[ModelName]
|
|
67
|
+
? FieldTypes[ModelName][FieldName]
|
|
68
|
+
: unknown
|
|
69
|
+
: unknown;
|
|
70
|
+
}
|
|
71
|
+
: Record<string, never>
|
|
72
|
+
: Record<string, never>
|
|
73
|
+
: Record<string, never>
|
|
74
|
+
: Record<string, never>;
|
|
75
|
+
|
|
76
|
+
type ResolvedInsertValues<
|
|
77
|
+
C,
|
|
78
|
+
Table extends StorageTable,
|
|
79
|
+
TableName extends string,
|
|
80
|
+
CT extends Record<string, { readonly input: unknown }>,
|
|
81
|
+
FieldInputs extends Record<string, Record<string, unknown>>,
|
|
82
|
+
> = string extends keyof FieldInputs
|
|
83
|
+
? InsertValues<Table, CT>
|
|
84
|
+
: FindModelForTable<C, TableName> extends infer ModelName extends string
|
|
85
|
+
? ModelName extends keyof FieldInputs
|
|
86
|
+
? {
|
|
87
|
+
[K in keyof Table['columns']]?: FindFieldForColumn<
|
|
88
|
+
C,
|
|
89
|
+
ModelName,
|
|
90
|
+
K & string
|
|
91
|
+
> extends infer FieldName extends string
|
|
92
|
+
? FieldName extends keyof FieldInputs[ModelName]
|
|
93
|
+
? Table['columns'][K]['nullable'] extends true
|
|
94
|
+
? NonNullable<FieldInputs[ModelName][FieldName]> | null
|
|
95
|
+
: NonNullable<FieldInputs[ModelName][FieldName]>
|
|
96
|
+
: Table['columns'][K]['codecId'] extends keyof CT
|
|
97
|
+
? CT[Table['columns'][K]['codecId']]['input']
|
|
98
|
+
: unknown
|
|
99
|
+
: Table['columns'][K]['codecId'] extends keyof CT
|
|
100
|
+
? CT[Table['columns'][K]['codecId']]['input']
|
|
101
|
+
: unknown;
|
|
102
|
+
}
|
|
103
|
+
: InsertValues<Table, CT>
|
|
104
|
+
: InsertValues<Table, CT>;
|
|
105
|
+
|
|
106
|
+
type ResolvedUpdateValues<
|
|
107
|
+
C,
|
|
108
|
+
Table extends StorageTable,
|
|
109
|
+
TableName extends string,
|
|
110
|
+
CT extends Record<string, { readonly input: unknown }>,
|
|
111
|
+
FieldInputs extends Record<string, Record<string, unknown>>,
|
|
112
|
+
> = ResolvedInsertValues<C, Table, TableName, CT, FieldInputs>;
|
|
113
|
+
|
|
114
|
+
type ContractToQC<C extends TableProxyContract, Name extends string = string> = {
|
|
25
115
|
readonly codecTypes: ExtractCodecTypes<C>;
|
|
26
116
|
readonly capabilities: C['capabilities'];
|
|
27
117
|
readonly queryOperationTypes: ExtractQueryOperationTypes<C>;
|
|
118
|
+
readonly resolvedColumnOutputTypes: ResolvedColumnTypes<C, Name, ExtractFieldOutputTypes<C>>;
|
|
28
119
|
};
|
|
29
120
|
|
|
30
121
|
export interface TableProxy<
|
|
@@ -32,7 +123,7 @@ export interface TableProxy<
|
|
|
32
123
|
Name extends string & keyof C['storage']['tables'],
|
|
33
124
|
Alias extends string = Name,
|
|
34
125
|
AvailableScope extends Scope = DefaultScope<Name, C['storage']['tables'][Name]>,
|
|
35
|
-
QC extends QueryContext = ContractToQC<C>,
|
|
126
|
+
QC extends QueryContext = ContractToQC<C, Name>,
|
|
36
127
|
> extends JoinSource<StorageTableToScopeTable<C['storage']['tables'][Name]>, Alias>,
|
|
37
128
|
WithSelect<QC, AvailableScope, EmptyRow>,
|
|
38
129
|
WithJoin<QC, AvailableScope, C['capabilities']> {
|
|
@@ -41,11 +132,23 @@ export interface TableProxy<
|
|
|
41
132
|
): TableProxy<C, Name, NewAlias, RebindScope<AvailableScope, Alias, NewAlias>>;
|
|
42
133
|
|
|
43
134
|
insert(
|
|
44
|
-
values:
|
|
135
|
+
values: ResolvedInsertValues<
|
|
136
|
+
C,
|
|
137
|
+
C['storage']['tables'][Name],
|
|
138
|
+
Name,
|
|
139
|
+
QC['codecTypes'],
|
|
140
|
+
ExtractFieldInputTypes<C>
|
|
141
|
+
>,
|
|
45
142
|
): InsertQuery<QC, AvailableScope, EmptyRow>;
|
|
46
143
|
|
|
47
144
|
update(
|
|
48
|
-
set:
|
|
145
|
+
set: ResolvedUpdateValues<
|
|
146
|
+
C,
|
|
147
|
+
C['storage']['tables'][Name],
|
|
148
|
+
Name,
|
|
149
|
+
QC['codecTypes'],
|
|
150
|
+
ExtractFieldInputTypes<C>
|
|
151
|
+
>,
|
|
49
152
|
): UpdateQuery<QC, AvailableScope, EmptyRow>;
|
|
50
153
|
|
|
51
154
|
delete(): DeleteQuery<QC, AvailableScope, EmptyRow>;
|