@prisma-next/sql-lane 0.3.0-dev.4 → 0.3.0-dev.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/exports/sql.d.ts +5 -5
- package/dist/exports/sql.d.ts.map +1 -0
- package/dist/index.d.ts +5 -116
- package/dist/index.d.ts.map +1 -0
- package/dist/raw.d.ts +11 -0
- package/dist/raw.d.ts.map +1 -0
- package/dist/sql/builder.d.ts +11 -0
- package/dist/sql/builder.d.ts.map +1 -0
- package/dist/sql/context.d.ts +5 -0
- package/dist/sql/context.d.ts.map +1 -0
- package/dist/sql/include-builder.d.ts +35 -0
- package/dist/sql/include-builder.d.ts.map +1 -0
- package/dist/sql/join-builder.d.ts +4 -0
- package/dist/sql/join-builder.d.ts.map +1 -0
- package/dist/sql/mutation-builder.d.ts +64 -0
- package/dist/sql/mutation-builder.d.ts.map +1 -0
- package/dist/sql/plan.d.ts +4 -0
- package/dist/sql/plan.d.ts.map +1 -0
- package/dist/sql/predicate-builder.d.ts +11 -0
- package/dist/sql/predicate-builder.d.ts.map +1 -0
- package/dist/sql/projection.d.ts +18 -0
- package/dist/sql/projection.d.ts.map +1 -0
- package/dist/sql/select-builder.d.ts +35 -0
- package/dist/sql/select-builder.d.ts.map +1 -0
- package/dist/types/internal.d.ts +35 -0
- package/dist/types/internal.d.ts.map +1 -0
- package/dist/types/public.d.ts +18 -0
- package/dist/types/public.d.ts.map +1 -0
- package/dist/utils/assertions.d.ts +28 -0
- package/dist/utils/assertions.d.ts.map +1 -0
- package/dist/utils/capabilities.d.ts +4 -0
- package/dist/utils/capabilities.d.ts.map +1 -0
- package/dist/utils/errors.d.ts +30 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/state.d.ts +30 -0
- package/dist/utils/state.d.ts.map +1 -0
- package/package.json +10 -9
- package/src/exports/sql.ts +12 -0
- package/src/index.ts +13 -0
- package/src/raw.ts +230 -0
- package/src/sql/builder.ts +66 -0
- package/src/sql/context.ts +10 -0
- package/src/sql/include-builder.ts +248 -0
- package/src/sql/join-builder.ts +18 -0
- package/src/sql/mutation-builder.ts +494 -0
- package/src/sql/plan.ts +289 -0
- package/src/sql/predicate-builder.ts +130 -0
- package/src/sql/projection.ts +112 -0
- package/src/sql/select-builder.ts +449 -0
- package/src/types/internal.ts +41 -0
- package/src/types/public.ts +36 -0
- package/src/utils/assertions.ts +34 -0
- package/src/utils/capabilities.ts +39 -0
- package/src/utils/errors.ts +168 -0
- package/src/utils/state.ts +40 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { planInvalid } from '@prisma-next/plan';
|
|
2
|
+
|
|
3
|
+
export function errorAliasPathEmpty(): never {
|
|
4
|
+
throw planInvalid('Alias path cannot be empty');
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function errorAliasCollision(path: string[], alias: string, existingPath?: string[]): never {
|
|
8
|
+
throw planInvalid(
|
|
9
|
+
`Alias collision: path ${path.join('.')} would generate alias "${alias}" which conflicts with path ${existingPath?.join('.') ?? 'unknown'}`,
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function errorLimitMustBeNonNegativeInteger(): never {
|
|
14
|
+
throw planInvalid('Limit must be a non-negative integer');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function errorChildProjectionMustBeSpecified(): never {
|
|
18
|
+
throw planInvalid('Child projection must be specified');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function errorIncludeRequiresCapabilities(target?: string): never {
|
|
22
|
+
throw planInvalid(
|
|
23
|
+
'includeMany requires lateral and jsonAgg capabilities',
|
|
24
|
+
target ? { target } : undefined,
|
|
25
|
+
[
|
|
26
|
+
'Enable capabilities for your target in contract.capabilities[target]',
|
|
27
|
+
"For SQL includes, set both 'lateral' and 'jsonAgg' to true",
|
|
28
|
+
'If your database lacks lateral/json_agg, use explicit joins + group aggregates',
|
|
29
|
+
],
|
|
30
|
+
[
|
|
31
|
+
'docs/Architecture Overview.md',
|
|
32
|
+
'docs/reference/extensions-glossary.md',
|
|
33
|
+
'packages/3-targets/6-adapters/postgres/README.md',
|
|
34
|
+
],
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function errorIncludeCapabilitiesNotTrue(
|
|
39
|
+
target?: string,
|
|
40
|
+
values?: { lateral?: unknown; jsonAgg?: unknown },
|
|
41
|
+
): never {
|
|
42
|
+
throw planInvalid(
|
|
43
|
+
'includeMany requires lateral and jsonAgg capabilities to be true',
|
|
44
|
+
target ? { target, values } : undefined,
|
|
45
|
+
[
|
|
46
|
+
'Set contract.capabilities[target].lateral = true and .jsonAgg = true',
|
|
47
|
+
'If the target does not support these, avoid includeMany and compose a two-step plan',
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
'docs/Architecture Overview.md',
|
|
51
|
+
'docs/reference/extensions-glossary.md',
|
|
52
|
+
'packages/3-targets/6-adapters/postgres/README.md',
|
|
53
|
+
],
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function errorUnknownTable(tableName: string): never {
|
|
58
|
+
throw planInvalid(`Unknown table ${tableName}`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function errorSelfJoinNotSupported(): never {
|
|
62
|
+
throw planInvalid('Self-joins are not supported in MVP');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function errorChildProjectionEmpty(): never {
|
|
66
|
+
throw planInvalid('Child projection must not be empty');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function errorIncludeAliasCollision(alias: string, type: 'projection' | 'include'): never {
|
|
70
|
+
throw planInvalid(
|
|
71
|
+
`Alias collision: include alias "${alias}" conflicts with existing ${type} alias`,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function errorMissingColumnForAlias(alias: string, index: number): never {
|
|
76
|
+
throw planInvalid(`Missing column for alias ${alias ?? 'unknown'} at index ${index}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function errorMissingAlias(index: number): never {
|
|
80
|
+
throw planInvalid(`Missing alias at index ${index}`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function errorInvalidColumnForAlias(alias: string, index: number): never {
|
|
84
|
+
throw planInvalid(`Invalid column for alias ${alias} at index ${index}`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function errorFromMustBeCalled(): never {
|
|
88
|
+
throw planInvalid('from() must be called before building a query');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function errorSelectMustBeCalled(): never {
|
|
92
|
+
throw planInvalid('select() must be called before build()');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function errorMissingParameter(paramName: string): never {
|
|
96
|
+
throw planInvalid(`Missing value for parameter ${paramName}`);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function errorInvalidProjectionValue(path: string[]): never {
|
|
100
|
+
throw planInvalid(
|
|
101
|
+
`Invalid projection value at path ${path.join('.')}: expected ColumnBuilder or nested object`,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function errorIncludeAliasNotFound(alias: string): never {
|
|
106
|
+
throw planInvalid(
|
|
107
|
+
`Include alias "${alias}" not found. Did you call includeMany() with alias "${alias}"?`,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function errorInvalidProjectionKey(key: string): never {
|
|
112
|
+
throw planInvalid(
|
|
113
|
+
`Invalid projection value at key "${key}": expected ColumnBuilder, boolean true (for includes), or nested object`,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function errorProjectionEmpty(): never {
|
|
118
|
+
throw planInvalid('select() requires at least one column or include');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function errorReturningRequiresCapability(target?: string): never {
|
|
122
|
+
throw planInvalid(
|
|
123
|
+
'returning() requires returning capability',
|
|
124
|
+
target ? { target } : undefined,
|
|
125
|
+
[
|
|
126
|
+
"Enable 'returning' for your target in contract.capabilities[target]",
|
|
127
|
+
'PostgreSQL supports RETURNING; MySQL does not',
|
|
128
|
+
'If unsupported, remove returning() and fetch with a follow-up select()',
|
|
129
|
+
],
|
|
130
|
+
[
|
|
131
|
+
'docs/Architecture Overview.md',
|
|
132
|
+
'docs/reference/extensions-glossary.md',
|
|
133
|
+
'packages/3-targets/6-adapters/postgres/README.md',
|
|
134
|
+
],
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function errorReturningCapabilityNotTrue(target?: string, value?: unknown): never {
|
|
139
|
+
throw planInvalid(
|
|
140
|
+
'returning() requires returning capability to be true',
|
|
141
|
+
target ? { target, value } : undefined,
|
|
142
|
+
[
|
|
143
|
+
'Set contract.capabilities[target].returning = true',
|
|
144
|
+
'If your database/adapter cannot support RETURNING, remove returning() and select after',
|
|
145
|
+
],
|
|
146
|
+
[
|
|
147
|
+
'docs/Architecture Overview.md',
|
|
148
|
+
'docs/reference/extensions-glossary.md',
|
|
149
|
+
'packages/3-targets/6-adapters/postgres/README.md',
|
|
150
|
+
],
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function errorUnknownColumn(columnName: string, tableName: string): never {
|
|
155
|
+
throw planInvalid(`Unknown column ${columnName} in table ${tableName}`);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function errorWhereMustBeCalledForUpdate(): never {
|
|
159
|
+
throw planInvalid('where() must be called before building an UPDATE query');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function errorFailedToBuildWhereClause(): never {
|
|
163
|
+
throw planInvalid('Failed to build WHERE clause');
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function errorWhereMustBeCalledForDelete(): never {
|
|
167
|
+
throw planInvalid('where() must be called before building a DELETE query');
|
|
168
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { TableRef } from '@prisma-next/sql-relational-core/ast';
|
|
2
|
+
import type {
|
|
3
|
+
AnyBinaryBuilder,
|
|
4
|
+
AnyColumnBuilder,
|
|
5
|
+
AnyOrderBuilder,
|
|
6
|
+
JoinOnPredicate,
|
|
7
|
+
} from '@prisma-next/sql-relational-core/types';
|
|
8
|
+
|
|
9
|
+
export interface ProjectionState {
|
|
10
|
+
readonly aliases: string[];
|
|
11
|
+
// columns can be null for include placeholders (when alias matches an include)
|
|
12
|
+
// This maintains array alignment but avoids creating invalid ColumnBuilders
|
|
13
|
+
readonly columns: (AnyColumnBuilder | null)[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface JoinState {
|
|
17
|
+
readonly joinType: 'inner' | 'left' | 'right' | 'full';
|
|
18
|
+
readonly table: TableRef;
|
|
19
|
+
readonly on: JoinOnPredicate;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface IncludeState {
|
|
23
|
+
readonly alias: string;
|
|
24
|
+
readonly table: TableRef;
|
|
25
|
+
readonly on: JoinOnPredicate;
|
|
26
|
+
readonly childProjection: ProjectionState;
|
|
27
|
+
readonly childWhere?: AnyBinaryBuilder;
|
|
28
|
+
readonly childOrderBy?: AnyOrderBuilder;
|
|
29
|
+
readonly childLimit?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface BuilderState {
|
|
33
|
+
from?: TableRef;
|
|
34
|
+
joins?: ReadonlyArray<JoinState>;
|
|
35
|
+
includes?: ReadonlyArray<IncludeState>;
|
|
36
|
+
projection?: ProjectionState;
|
|
37
|
+
where?: AnyBinaryBuilder;
|
|
38
|
+
orderBy?: AnyOrderBuilder;
|
|
39
|
+
limit?: number;
|
|
40
|
+
}
|