@prisma-next/framework-components 0.5.0-dev.8 → 0.5.0-dev.81
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/README.md +53 -4
- package/dist/authoring.d.mts +2 -2
- package/dist/authoring.mjs +2 -122
- package/dist/codec-m_-FAyQn.d.mts +168 -0
- package/dist/codec-m_-FAyQn.d.mts.map +1 -0
- package/dist/codec.d.mts +48 -2
- package/dist/codec.d.mts.map +1 -0
- package/dist/codec.mjs +67 -4
- package/dist/codec.mjs.map +1 -1
- package/dist/components.d.mts +1 -1
- package/dist/components.mjs +2 -3
- package/dist/control.d.mts +420 -74
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +83 -49
- package/dist/control.mjs.map +1 -1
- package/dist/emission-types-BKa4bR9m.d.mts +39 -0
- package/dist/emission-types-BKa4bR9m.d.mts.map +1 -0
- package/dist/emission.d.mts +2 -2
- package/dist/emission.mjs +1 -1
- package/dist/execution.d.mts +5 -5
- package/dist/execution.d.mts.map +1 -1
- package/dist/execution.mjs +4 -6
- package/dist/execution.mjs.map +1 -1
- package/dist/{framework-authoring-D1-JZ37B.d.mts → framework-authoring-DGIQbNPt.d.mts} +43 -12
- package/dist/framework-authoring-DGIQbNPt.d.mts.map +1 -0
- package/dist/framework-authoring-DxXcjyJX.mjs +209 -0
- package/dist/framework-authoring-DxXcjyJX.mjs.map +1 -0
- package/dist/{framework-components-DFZMi2h7.d.mts → framework-components-BGo7HsbL.d.mts} +45 -55
- package/dist/framework-components-BGo7HsbL.d.mts.map +1 -0
- package/dist/{framework-components-C8ZhSwXe.mjs → framework-components-FdqmlGUj.mjs} +3 -3
- package/dist/framework-components-FdqmlGUj.mjs.map +1 -0
- package/dist/psl-ast-Ckn_G-jv.d.mts +159 -0
- package/dist/psl-ast-Ckn_G-jv.d.mts.map +1 -0
- package/dist/psl-ast.d.mts +2 -0
- package/dist/psl-ast.mjs +1 -0
- package/dist/runtime.d.mts +395 -19
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +256 -7
- package/dist/runtime.mjs.map +1 -1
- package/dist/{types-import-spec-C4sc7wbb.d.mts → types-import-spec-BxI5cSQy.d.mts} +2 -2
- package/dist/types-import-spec-BxI5cSQy.d.mts.map +1 -0
- package/package.json +10 -6
- package/src/control/control-capabilities.ts +96 -0
- package/src/{control-descriptors.ts → control/control-descriptors.ts} +7 -7
- package/src/{control-instances.ts → control/control-instances.ts} +52 -6
- package/src/{control-migration-types.ts → control/control-migration-types.ts} +251 -63
- package/src/control/control-operation-preview.ts +23 -0
- package/src/control/control-spaces.ts +82 -0
- package/src/{control-stack.ts → control/control-stack.ts} +77 -94
- package/src/control/emission-types.ts +49 -0
- package/src/control/psl-ast.ts +193 -0
- package/src/{execution-descriptors.ts → execution/execution-descriptors.ts} +7 -7
- package/src/{execution-instances.ts → execution/execution-instances.ts} +1 -1
- package/src/{execution-requirements.ts → execution/execution-requirements.ts} +1 -1
- package/src/execution/query-plan.ts +53 -0
- package/src/execution/race-against-abort.ts +89 -0
- package/src/execution/run-with-middleware.ts +153 -0
- package/src/execution/runtime-core.ts +133 -0
- package/src/execution/runtime-error.ts +94 -0
- package/src/execution/runtime-middleware.ts +235 -0
- package/src/exports/authoring.ts +5 -2
- package/src/exports/codec.ts +27 -2
- package/src/exports/components.ts +2 -2
- package/src/exports/control.ts +41 -13
- package/src/exports/emission.ts +2 -2
- package/src/exports/execution.ts +5 -5
- package/src/exports/psl-ast.ts +1 -0
- package/src/exports/runtime.ts +18 -5
- package/src/shared/codec-descriptor.ts +87 -0
- package/src/shared/codec-types.ts +79 -0
- package/src/shared/codec.ts +80 -0
- package/src/shared/column-spec.ts +83 -0
- package/src/{framework-authoring.ts → shared/framework-authoring.ts} +210 -23
- package/src/{framework-components.ts → shared/framework-components.ts} +22 -48
- package/src/{mutation-default-types.ts → shared/mutation-default-types.ts} +22 -2
- package/dist/authoring.mjs.map +0 -1
- package/dist/codec-types-DQ1Agjom.d.mts +0 -58
- package/dist/codec-types-DQ1Agjom.d.mts.map +0 -1
- package/dist/emission-types-BPAALJbF.d.mts +0 -24
- package/dist/emission-types-BPAALJbF.d.mts.map +0 -1
- package/dist/framework-authoring-D1-JZ37B.d.mts.map +0 -1
- package/dist/framework-components-C8ZhSwXe.mjs.map +0 -1
- package/dist/framework-components-DFZMi2h7.d.mts.map +0 -1
- package/dist/types-import-spec-C4sc7wbb.d.mts.map +0 -1
- package/src/codec-types.ts +0 -64
- package/src/control-capabilities.ts +0 -34
- package/src/emission-types.ts +0 -28
- package/src/runtime-error.ts +0 -55
- package/src/runtime-middleware.ts +0 -83
- /package/src/{control-result-types.ts → control/control-result-types.ts} +0 -0
- /package/src/{control-schema-view.ts → control/control-schema-view.ts} +0 -0
- /package/src/{async-iterable-result.ts → execution/async-iterable-result.ts} +0 -0
- /package/src/{execution-stack.ts → execution/execution-stack.ts} +0 -0
- /package/src/{types-import-spec.ts → shared/types-import-spec.ts} +0 -0
|
@@ -1,25 +1,30 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
ControlAdapterDescriptor,
|
|
4
|
-
ControlDriverDescriptor,
|
|
5
|
-
ControlExtensionDescriptor,
|
|
6
|
-
ControlFamilyDescriptor,
|
|
7
|
-
ControlTargetDescriptor,
|
|
8
|
-
} from './control-descriptors';
|
|
1
|
+
import type { Codec } from '../shared/codec';
|
|
2
|
+
import type { CodecLookup, CodecMeta } from '../shared/codec-types';
|
|
9
3
|
import type {
|
|
10
4
|
AuthoringContributions,
|
|
11
5
|
AuthoringFieldNamespace,
|
|
12
|
-
AuthoringFieldPresetDescriptor,
|
|
13
|
-
AuthoringTypeConstructorDescriptor,
|
|
14
6
|
AuthoringTypeNamespace,
|
|
15
|
-
} from '
|
|
16
|
-
import
|
|
7
|
+
} from '../shared/framework-authoring';
|
|
8
|
+
import {
|
|
9
|
+
assertNoCrossRegistryCollisions,
|
|
10
|
+
isAuthoringFieldPresetDescriptor,
|
|
11
|
+
isAuthoringTypeConstructorDescriptor,
|
|
12
|
+
mergeAuthoringNamespaces,
|
|
13
|
+
} from '../shared/framework-authoring';
|
|
14
|
+
import type { ComponentMetadata } from '../shared/framework-components';
|
|
17
15
|
import type {
|
|
18
16
|
ControlMutationDefaultEntry,
|
|
19
17
|
ControlMutationDefaults,
|
|
20
18
|
MutationDefaultGeneratorDescriptor,
|
|
21
|
-
} from '
|
|
22
|
-
import type { TypesImportSpec } from '
|
|
19
|
+
} from '../shared/mutation-default-types';
|
|
20
|
+
import type { TypesImportSpec } from '../shared/types-import-spec';
|
|
21
|
+
import type {
|
|
22
|
+
ControlAdapterDescriptor,
|
|
23
|
+
ControlDriverDescriptor,
|
|
24
|
+
ControlExtensionDescriptor,
|
|
25
|
+
ControlFamilyDescriptor,
|
|
26
|
+
ControlTargetDescriptor,
|
|
27
|
+
} from './control-descriptors';
|
|
23
28
|
|
|
24
29
|
export interface AssembledAuthoringContributions {
|
|
25
30
|
readonly field: AuthoringFieldNamespace;
|
|
@@ -153,70 +158,6 @@ export function extractComponentIds(
|
|
|
153
158
|
return ids;
|
|
154
159
|
}
|
|
155
160
|
|
|
156
|
-
function isTypeConstructorDescriptor(value: unknown): value is AuthoringTypeConstructorDescriptor {
|
|
157
|
-
return (
|
|
158
|
-
typeof value === 'object' &&
|
|
159
|
-
value !== null &&
|
|
160
|
-
(value as { kind?: unknown }).kind === 'typeConstructor'
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function isFieldPresetDescriptor(value: unknown): value is AuthoringFieldPresetDescriptor {
|
|
165
|
-
return (
|
|
166
|
-
typeof value === 'object' &&
|
|
167
|
-
value !== null &&
|
|
168
|
-
(value as { kind?: unknown }).kind === 'fieldPreset'
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function mergeAuthoringNamespaces(
|
|
173
|
-
target: Record<string, unknown>,
|
|
174
|
-
source: Record<string, unknown>,
|
|
175
|
-
path: readonly string[],
|
|
176
|
-
leafGuard: (value: unknown) => boolean,
|
|
177
|
-
label: string,
|
|
178
|
-
): void {
|
|
179
|
-
const assertSafePath = (currentPath: readonly string[]) => {
|
|
180
|
-
const blockedSegment = currentPath.find(
|
|
181
|
-
(segment) => segment === '__proto__' || segment === 'constructor' || segment === 'prototype',
|
|
182
|
-
);
|
|
183
|
-
if (blockedSegment) {
|
|
184
|
-
throw new Error(
|
|
185
|
-
`Invalid authoring ${label} helper "${currentPath.join('.')}". Helper path segments must not use "${blockedSegment}".`,
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
for (const [key, sourceValue] of Object.entries(source)) {
|
|
191
|
-
const currentPath = [...path, key];
|
|
192
|
-
assertSafePath(currentPath);
|
|
193
|
-
const hasExistingValue = Object.hasOwn(target, key);
|
|
194
|
-
const existingValue = hasExistingValue ? target[key] : undefined;
|
|
195
|
-
|
|
196
|
-
if (!hasExistingValue) {
|
|
197
|
-
target[key] = sourceValue;
|
|
198
|
-
continue;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const existingIsLeaf = leafGuard(existingValue);
|
|
202
|
-
const sourceIsLeaf = leafGuard(sourceValue);
|
|
203
|
-
|
|
204
|
-
if (existingIsLeaf || sourceIsLeaf) {
|
|
205
|
-
throw new Error(
|
|
206
|
-
`Duplicate authoring ${label} helper "${currentPath.join('.')}". Descriptor contributions must be unique across composed components.`,
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
mergeAuthoringNamespaces(
|
|
211
|
-
existingValue as Record<string, unknown>,
|
|
212
|
-
sourceValue as Record<string, unknown>,
|
|
213
|
-
currentPath,
|
|
214
|
-
leafGuard,
|
|
215
|
-
label,
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
161
|
export function assembleAuthoringContributions(
|
|
221
162
|
descriptors: ReadonlyArray<{ readonly authoring?: AuthoringContributions }>,
|
|
222
163
|
): AssembledAuthoringContributions {
|
|
@@ -229,7 +170,7 @@ export function assembleAuthoringContributions(
|
|
|
229
170
|
field,
|
|
230
171
|
descriptor.authoring.field,
|
|
231
172
|
[],
|
|
232
|
-
|
|
173
|
+
isAuthoringFieldPresetDescriptor,
|
|
233
174
|
'field',
|
|
234
175
|
);
|
|
235
176
|
}
|
|
@@ -240,14 +181,18 @@ export function assembleAuthoringContributions(
|
|
|
240
181
|
type,
|
|
241
182
|
descriptor.authoring.type,
|
|
242
183
|
[],
|
|
243
|
-
|
|
184
|
+
isAuthoringTypeConstructorDescriptor,
|
|
244
185
|
'type',
|
|
245
186
|
);
|
|
246
187
|
}
|
|
247
188
|
|
|
189
|
+
const fieldNamespace = field as AuthoringFieldNamespace;
|
|
190
|
+
const typeNamespace = type as AuthoringTypeNamespace;
|
|
191
|
+
assertNoCrossRegistryCollisions(typeNamespace, fieldNamespace);
|
|
192
|
+
|
|
248
193
|
return {
|
|
249
|
-
field:
|
|
250
|
-
type:
|
|
194
|
+
field: fieldNamespace,
|
|
195
|
+
type: typeNamespace,
|
|
251
196
|
};
|
|
252
197
|
}
|
|
253
198
|
|
|
@@ -326,27 +271,65 @@ export function assembleControlMutationDefaults(
|
|
|
326
271
|
}
|
|
327
272
|
|
|
328
273
|
export function extractCodecLookup(
|
|
329
|
-
descriptors: ReadonlyArray<Pick<ComponentMetadata & { id
|
|
274
|
+
descriptors: ReadonlyArray<Pick<ComponentMetadata & { id: string }, 'types' | 'id'>>,
|
|
330
275
|
): CodecLookup {
|
|
331
|
-
const byId = new Map<string,
|
|
276
|
+
const byId = new Map<string, Codec>();
|
|
277
|
+
const targetTypesById = new Map<string, readonly string[]>();
|
|
278
|
+
const metaById = new Map<string, CodecMeta>();
|
|
279
|
+
const renderersById = new Map<string, (params: Record<string, unknown>) => string | undefined>();
|
|
332
280
|
const owners = new Map<string, string>();
|
|
333
281
|
for (const descriptor of descriptors) {
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
for (const
|
|
282
|
+
const codecTypes = descriptor.types?.codecTypes;
|
|
283
|
+
const descriptorId = descriptor.id;
|
|
284
|
+
// Descriptor-side metadata is the single source of truth for `targetTypes` / `meta` / `renderOutputType`. Every contributor ships a `codecDescriptors` list on `types.codecTypes`.
|
|
285
|
+
for (const codecDescriptor of codecTypes?.codecDescriptors ?? []) {
|
|
338
286
|
assertUniqueCodecOwner({
|
|
339
|
-
codecId:
|
|
287
|
+
codecId: codecDescriptor.codecId,
|
|
340
288
|
owners,
|
|
341
289
|
descriptorId,
|
|
342
|
-
entityLabel: 'codec
|
|
343
|
-
entityOwnershipLabel: 'codec
|
|
290
|
+
entityLabel: 'codec descriptor',
|
|
291
|
+
entityOwnershipLabel: 'codec descriptor provider',
|
|
344
292
|
});
|
|
345
|
-
owners.set(
|
|
346
|
-
|
|
293
|
+
owners.set(codecDescriptor.codecId, descriptorId);
|
|
294
|
+
if (Array.isArray(codecDescriptor.targetTypes)) {
|
|
295
|
+
targetTypesById.set(codecDescriptor.codecId, codecDescriptor.targetTypes);
|
|
296
|
+
}
|
|
297
|
+
if (codecDescriptor.meta !== undefined) {
|
|
298
|
+
metaById.set(codecDescriptor.codecId, codecDescriptor.meta);
|
|
299
|
+
}
|
|
300
|
+
if (typeof codecDescriptor.renderOutputType === 'function') {
|
|
301
|
+
renderersById.set(codecDescriptor.codecId, codecDescriptor.renderOutputType);
|
|
302
|
+
}
|
|
303
|
+
// Materialize a representative `Codec` instance for `byId.get()` so consumers reading the lookup's instance side (e.g. SQL renderer's cast-policy lookup, or the contract emitter's literal-default `encodeJson` resolver) keep finding the codec.
|
|
304
|
+
//
|
|
305
|
+
// Two cohorts:
|
|
306
|
+
// - Non-parameterized descriptors: factory must succeed; any throw is a real bug and we let it propagate (no silent try/catch).
|
|
307
|
+
// - Parameterized descriptors: try with empty params. Many parameterized codecs treat params as advisory (e.g. `pg/timestamptz@1` whose precision is rendered into the `nativeType` only and never read by the runtime codec), so an empty-params construction yields a usable representative for id-keyed lookups (e.g. emit-time literal-default encoding). Codecs whose factory genuinely requires params (e.g. `pg/vector@1` threading `length` into the runtime codec) will throw; for those, per-column instances are materialized at runtime by `buildContractCodecRegistry` and the id-keyed lookup miss is correct (the column-aware path resolves them).
|
|
308
|
+
if (!byId.has(codecDescriptor.codecId)) {
|
|
309
|
+
if (codecDescriptor.isParameterized) {
|
|
310
|
+
try {
|
|
311
|
+
const representative = codecDescriptor.factory({} as never)({
|
|
312
|
+
name: `<lookup:${codecDescriptor.codecId}>`,
|
|
313
|
+
} as Parameters<ReturnType<typeof codecDescriptor.factory>>[0]);
|
|
314
|
+
byId.set(codecDescriptor.codecId, representative);
|
|
315
|
+
} catch {
|
|
316
|
+
// Factory requires concrete params; skip representative materialization. Per-column instances are built at runtime; id-keyed lookup miss is the correct outcome here.
|
|
317
|
+
}
|
|
318
|
+
} else {
|
|
319
|
+
const representative = codecDescriptor.factory(undefined as never)({
|
|
320
|
+
name: `<lookup:${codecDescriptor.codecId}>`,
|
|
321
|
+
} as Parameters<ReturnType<typeof codecDescriptor.factory>>[0]);
|
|
322
|
+
byId.set(codecDescriptor.codecId, representative);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
347
325
|
}
|
|
348
326
|
}
|
|
349
|
-
return {
|
|
327
|
+
return {
|
|
328
|
+
get: (id) => byId.get(id),
|
|
329
|
+
targetTypesFor: (id) => targetTypesById.get(id),
|
|
330
|
+
metaFor: (id) => metaById.get(id),
|
|
331
|
+
renderOutputTypeFor: (id, params) => renderersById.get(id)?.(params),
|
|
332
|
+
};
|
|
350
333
|
}
|
|
351
334
|
|
|
352
335
|
export function validateScalarTypeCodecIds(
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Contract, ContractModel } from '@prisma-next/contract/types';
|
|
2
|
+
import type { TypesImportSpec } from '../shared/types-import-spec';
|
|
3
|
+
|
|
4
|
+
export interface GenerateContractTypesOptions {
|
|
5
|
+
readonly queryOperationTypeImports?: ReadonlyArray<TypesImportSpec>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ValidationContext {
|
|
9
|
+
readonly codecTypeImports?: ReadonlyArray<TypesImportSpec>;
|
|
10
|
+
readonly operationTypeImports?: ReadonlyArray<TypesImportSpec>;
|
|
11
|
+
readonly extensionIds?: ReadonlyArray<string>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface EmissionSpi {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
|
|
17
|
+
generateStorageType(contract: Contract, storageHashTypeName: string): string;
|
|
18
|
+
|
|
19
|
+
generateModelStorageType(modelName: string, model: ContractModel): string;
|
|
20
|
+
|
|
21
|
+
getFamilyImports(): string[];
|
|
22
|
+
|
|
23
|
+
getFamilyTypeAliases(options?: GenerateContractTypesOptions): string;
|
|
24
|
+
|
|
25
|
+
getTypeMapsExpression(): string;
|
|
26
|
+
|
|
27
|
+
getContractWrapper(contractBaseName: string, typeMapsName: string): string;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Per-family resolver for typeParams that don't live inline on the
|
|
31
|
+
* framework-domain `ContractField`. Some families (notably SQL) let columns
|
|
32
|
+
* reference a named entry in `storage.types` via `typeRef`; the typeParams
|
|
33
|
+
* live on that named entry rather than on the domain field. The framework
|
|
34
|
+
* emit path consults this hook so the codec's `renderOutputType` can run
|
|
35
|
+
* for typeRef-shaped columns.
|
|
36
|
+
*
|
|
37
|
+
* Inline `field.type.typeParams` always takes precedence; the hook is only
|
|
38
|
+
* consulted when the domain field has no typeParams. Families without
|
|
39
|
+
* named storage types (e.g. mongo) don't implement this hook.
|
|
40
|
+
*
|
|
41
|
+
* Returns `undefined` when the field has no resolvable typeParams.
|
|
42
|
+
*/
|
|
43
|
+
resolveFieldTypeParams?(
|
|
44
|
+
modelName: string,
|
|
45
|
+
fieldName: string,
|
|
46
|
+
model: ContractModel,
|
|
47
|
+
contract: Contract,
|
|
48
|
+
): Record<string, unknown> | undefined;
|
|
49
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
export interface PslPosition {
|
|
2
|
+
readonly offset: number;
|
|
3
|
+
readonly line: number;
|
|
4
|
+
readonly column: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface PslSpan {
|
|
8
|
+
readonly start: PslPosition;
|
|
9
|
+
readonly end: PslPosition;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type PslDiagnosticCode =
|
|
13
|
+
| 'PSL_UNTERMINATED_BLOCK'
|
|
14
|
+
| 'PSL_UNSUPPORTED_TOP_LEVEL_BLOCK'
|
|
15
|
+
| 'PSL_INVALID_ATTRIBUTE_SYNTAX'
|
|
16
|
+
| 'PSL_INVALID_MODEL_MEMBER'
|
|
17
|
+
| 'PSL_UNSUPPORTED_MODEL_ATTRIBUTE'
|
|
18
|
+
| 'PSL_UNSUPPORTED_FIELD_ATTRIBUTE'
|
|
19
|
+
| 'PSL_INVALID_RELATION_ATTRIBUTE'
|
|
20
|
+
| 'PSL_INVALID_REFERENTIAL_ACTION'
|
|
21
|
+
| 'PSL_INVALID_DEFAULT_VALUE'
|
|
22
|
+
| 'PSL_INVALID_ENUM_MEMBER'
|
|
23
|
+
| 'PSL_INVALID_TYPES_MEMBER';
|
|
24
|
+
|
|
25
|
+
export interface PslDiagnostic {
|
|
26
|
+
readonly code: PslDiagnosticCode;
|
|
27
|
+
readonly message: string;
|
|
28
|
+
readonly sourceId: string;
|
|
29
|
+
readonly span: PslSpan;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface PslDefaultFunctionValue {
|
|
33
|
+
readonly kind: 'function';
|
|
34
|
+
readonly name: 'autoincrement' | 'now';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface PslDefaultLiteralValue {
|
|
38
|
+
readonly kind: 'literal';
|
|
39
|
+
readonly value: string | number | boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type PslDefaultValue = PslDefaultFunctionValue | PslDefaultLiteralValue;
|
|
43
|
+
|
|
44
|
+
export type PslAttributeTarget = 'field' | 'model' | 'enum' | 'namedType';
|
|
45
|
+
|
|
46
|
+
export interface PslAttributePositionalArgument {
|
|
47
|
+
readonly kind: 'positional';
|
|
48
|
+
readonly value: string;
|
|
49
|
+
readonly span: PslSpan;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface PslAttributeNamedArgument {
|
|
53
|
+
readonly kind: 'named';
|
|
54
|
+
readonly name: string;
|
|
55
|
+
readonly value: string;
|
|
56
|
+
readonly span: PslSpan;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type PslAttributeArgument = PslAttributePositionalArgument | PslAttributeNamedArgument;
|
|
60
|
+
|
|
61
|
+
export interface PslTypeConstructorCall {
|
|
62
|
+
readonly kind: 'typeConstructor';
|
|
63
|
+
readonly path: readonly string[];
|
|
64
|
+
readonly args: readonly PslAttributeArgument[];
|
|
65
|
+
readonly span: PslSpan;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface PslAttribute {
|
|
69
|
+
readonly kind: 'attribute';
|
|
70
|
+
readonly target: PslAttributeTarget;
|
|
71
|
+
readonly name: string;
|
|
72
|
+
readonly args: readonly PslAttributeArgument[];
|
|
73
|
+
readonly span: PslSpan;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type PslReferentialAction = string;
|
|
77
|
+
|
|
78
|
+
export type PslFieldAttribute = PslAttribute;
|
|
79
|
+
|
|
80
|
+
export interface PslField {
|
|
81
|
+
readonly kind: 'field';
|
|
82
|
+
readonly name: string;
|
|
83
|
+
readonly typeName: string;
|
|
84
|
+
readonly typeConstructor?: PslTypeConstructorCall;
|
|
85
|
+
readonly optional: boolean;
|
|
86
|
+
readonly list: boolean;
|
|
87
|
+
readonly typeRef?: string;
|
|
88
|
+
readonly attributes: readonly PslFieldAttribute[];
|
|
89
|
+
readonly span: PslSpan;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface PslUniqueConstraint {
|
|
93
|
+
readonly kind: 'unique';
|
|
94
|
+
readonly fields: readonly string[];
|
|
95
|
+
readonly span: PslSpan;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface PslIndexConstraint {
|
|
99
|
+
readonly kind: 'index';
|
|
100
|
+
readonly fields: readonly string[];
|
|
101
|
+
readonly span: PslSpan;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export type PslModelAttribute = PslAttribute;
|
|
105
|
+
|
|
106
|
+
export interface PslModel {
|
|
107
|
+
readonly kind: 'model';
|
|
108
|
+
readonly name: string;
|
|
109
|
+
readonly fields: readonly PslField[];
|
|
110
|
+
readonly attributes: readonly PslModelAttribute[];
|
|
111
|
+
readonly span: PslSpan;
|
|
112
|
+
/**
|
|
113
|
+
* Optional leading comment line emitted above the `model` keyword by the
|
|
114
|
+
* printer. Producers (e.g. `sqlSchemaIrToPslAst`) attach introspection
|
|
115
|
+
* advisories such as "// WARNING: This table has no primary key in the
|
|
116
|
+
* database" here. The parser leaves this field unset; round-tripping a
|
|
117
|
+
* parsed schema does not re-attach comments.
|
|
118
|
+
*/
|
|
119
|
+
readonly comment?: string;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface PslEnumValue {
|
|
123
|
+
readonly kind: 'enumValue';
|
|
124
|
+
readonly name: string;
|
|
125
|
+
/**
|
|
126
|
+
* Optional storage label for the enum member, captured from a trailing
|
|
127
|
+
* `@map("...")` attribute on the member line. The parser populates this
|
|
128
|
+
* when the source PSL carries an explicit `@map`. Producers (e.g.
|
|
129
|
+
* `sqlSchemaIrToPslAst`) leave it unset; the printer emits `@map(...)`
|
|
130
|
+
* automatically when normalisation would change the printed member name
|
|
131
|
+
* (so an enum value `'in-progress'` becomes `inProgress @map("in-progress")`
|
|
132
|
+
* in PSL, preserving the round-trip).
|
|
133
|
+
*/
|
|
134
|
+
readonly mapName?: string;
|
|
135
|
+
readonly span: PslSpan;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface PslEnum {
|
|
139
|
+
readonly kind: 'enum';
|
|
140
|
+
readonly name: string;
|
|
141
|
+
readonly values: readonly PslEnumValue[];
|
|
142
|
+
readonly attributes: readonly PslAttribute[];
|
|
143
|
+
readonly span: PslSpan;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface PslCompositeType {
|
|
147
|
+
readonly kind: 'compositeType';
|
|
148
|
+
readonly name: string;
|
|
149
|
+
readonly fields: readonly PslField[];
|
|
150
|
+
readonly attributes: readonly PslAttribute[];
|
|
151
|
+
readonly span: PslSpan;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export interface PslNamedTypeDeclaration {
|
|
155
|
+
readonly kind: 'namedType';
|
|
156
|
+
readonly name: string;
|
|
157
|
+
/**
|
|
158
|
+
* Parser invariant: exactly one of `baseType` and `typeConstructor` is set.
|
|
159
|
+
* Expressing this as a discriminated union trips TypeScript narrowing when
|
|
160
|
+
* the declaration flows through helpers that accept the full union.
|
|
161
|
+
*/
|
|
162
|
+
readonly baseType?: string;
|
|
163
|
+
readonly typeConstructor?: PslTypeConstructorCall;
|
|
164
|
+
readonly attributes: readonly PslAttribute[];
|
|
165
|
+
readonly span: PslSpan;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export interface PslTypesBlock {
|
|
169
|
+
readonly kind: 'types';
|
|
170
|
+
readonly declarations: readonly PslNamedTypeDeclaration[];
|
|
171
|
+
readonly span: PslSpan;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface PslDocumentAst {
|
|
175
|
+
readonly kind: 'document';
|
|
176
|
+
readonly sourceId: string;
|
|
177
|
+
readonly models: readonly PslModel[];
|
|
178
|
+
readonly enums: readonly PslEnum[];
|
|
179
|
+
readonly compositeTypes: readonly PslCompositeType[];
|
|
180
|
+
readonly types?: PslTypesBlock;
|
|
181
|
+
readonly span: PslSpan;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export interface ParsePslDocumentInput {
|
|
185
|
+
readonly schema: string;
|
|
186
|
+
readonly sourceId: string;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export interface ParsePslDocumentResult {
|
|
190
|
+
readonly ast: PslDocumentAst;
|
|
191
|
+
readonly diagnostics: readonly PslDiagnostic[];
|
|
192
|
+
readonly ok: boolean;
|
|
193
|
+
}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AdapterDescriptor,
|
|
3
|
+
DriverDescriptor,
|
|
4
|
+
ExtensionDescriptor,
|
|
5
|
+
FamilyDescriptor,
|
|
6
|
+
TargetDescriptor,
|
|
7
|
+
} from '../shared/framework-components';
|
|
1
8
|
import type {
|
|
2
9
|
RuntimeAdapterInstance,
|
|
3
10
|
RuntimeDriverInstance,
|
|
@@ -6,13 +13,6 @@ import type {
|
|
|
6
13
|
RuntimeTargetInstance,
|
|
7
14
|
} from './execution-instances';
|
|
8
15
|
import type { ExecutionStack } from './execution-stack';
|
|
9
|
-
import type {
|
|
10
|
-
AdapterDescriptor,
|
|
11
|
-
DriverDescriptor,
|
|
12
|
-
ExtensionDescriptor,
|
|
13
|
-
FamilyDescriptor,
|
|
14
|
-
TargetDescriptor,
|
|
15
|
-
} from './framework-components';
|
|
16
16
|
|
|
17
17
|
export interface RuntimeFamilyDescriptor<
|
|
18
18
|
TFamilyId extends string,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { checkContractComponentRequirements } from '../shared/framework-components';
|
|
1
2
|
import type {
|
|
2
3
|
RuntimeAdapterDescriptor,
|
|
3
4
|
RuntimeExtensionDescriptor,
|
|
4
5
|
RuntimeFamilyDescriptor,
|
|
5
6
|
RuntimeTargetDescriptor,
|
|
6
7
|
} from './execution-descriptors';
|
|
7
|
-
import { checkContractComponentRequirements } from './framework-components';
|
|
8
8
|
|
|
9
9
|
export function assertRuntimeContractRequirementsSatisfied<
|
|
10
10
|
TFamilyId extends string,
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { PlanMeta } from '@prisma-next/contract/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Family-agnostic plan marker.
|
|
5
|
+
*
|
|
6
|
+
* Carries only `meta` (the family-agnostic plan metadata) and the optional
|
|
7
|
+
* phantom `_row` parameter that lets type-level utilities recover the row
|
|
8
|
+
* type from a plan value. SQL and Mongo extend this marker with their own
|
|
9
|
+
* concrete shapes (`SqlQueryPlan`, `MongoQueryPlan`).
|
|
10
|
+
*
|
|
11
|
+
* `QueryPlan` is the *pre-lowering* marker — i.e. the surface a builder
|
|
12
|
+
* produces before family-specific lowering turns it into an executable
|
|
13
|
+
* plan (`ExecutionPlan`).
|
|
14
|
+
*/
|
|
15
|
+
export interface QueryPlan<Row = unknown> {
|
|
16
|
+
readonly meta: PlanMeta;
|
|
17
|
+
/**
|
|
18
|
+
* Phantom property to carry the Row generic for type-level utilities.
|
|
19
|
+
* Not set at runtime; used only for `ResultType` extraction.
|
|
20
|
+
*/
|
|
21
|
+
readonly _row?: Row;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Family-agnostic execution-plan marker.
|
|
26
|
+
*
|
|
27
|
+
* Extends `QueryPlan` with no additional structural fields — the marker
|
|
28
|
+
* exists to nominally distinguish executable plans from pre-lowering plans
|
|
29
|
+
* in the type system. Family-specific execution plans (`SqlExecutionPlan`,
|
|
30
|
+
* `MongoExecutionPlan`) extend this marker with their concrete shapes
|
|
31
|
+
* (e.g. `sql + params` for SQL, `wireCommand` for Mongo).
|
|
32
|
+
*/
|
|
33
|
+
export interface ExecutionPlan<Row = unknown> extends QueryPlan<Row> {}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Extracts the `Row` type from a plan via the phantom `_row` property.
|
|
37
|
+
*
|
|
38
|
+
* Works with any plan that extends `QueryPlan<Row>` — including
|
|
39
|
+
* `ExecutionPlan<Row>`, `SqlQueryPlan<Row>`, `SqlExecutionPlan<Row>`,
|
|
40
|
+
* `MongoQueryPlan<Row>`, and `MongoExecutionPlan<Row>`.
|
|
41
|
+
*
|
|
42
|
+
* The `_row` property must be present in the plan's static type for the
|
|
43
|
+
* conditional to bind `R`; objects whose type lacks `_row` resolve to
|
|
44
|
+
* `never`. Without the `keyof` guard, `extends { _row?: infer R }` would
|
|
45
|
+
* silently match any object and infer `unknown`.
|
|
46
|
+
*
|
|
47
|
+
* Example: `type Row = ResultType<typeof plan>`.
|
|
48
|
+
*/
|
|
49
|
+
export type ResultType<P> = '_row' extends keyof P
|
|
50
|
+
? P extends { readonly _row?: infer R }
|
|
51
|
+
? R
|
|
52
|
+
: never
|
|
53
|
+
: never;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { RuntimeAbortedPhase } from './runtime-error';
|
|
2
|
+
import { runtimeAborted } from './runtime-error';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Throw a phase-tagged `RUNTIME.ABORTED` envelope if the supplied
|
|
6
|
+
* context is already aborted at the precheck site. Centralises the
|
|
7
|
+
* `if (ctx.signal?.aborted) throw runtimeAborted(...)` pattern that
|
|
8
|
+
* every codec dispatch site (and the `beforeExecute` middleware phase)
|
|
9
|
+
* repeats. Accepts both the framework `CodecCallContext` and the
|
|
10
|
+
* `RuntimeMiddlewareContext`; both expose `signal?: AbortSignal`.
|
|
11
|
+
*/
|
|
12
|
+
export function checkAborted(
|
|
13
|
+
ctx: { readonly signal?: AbortSignal },
|
|
14
|
+
phase: RuntimeAbortedPhase,
|
|
15
|
+
): void {
|
|
16
|
+
if (ctx.signal?.aborted) {
|
|
17
|
+
throw runtimeAborted(phase, ctx.signal.reason);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Race a per-cell `Promise.all` (or any other in-flight work promise) against
|
|
23
|
+
* the supplied abort signal so the runtime returns `RUNTIME.ABORTED` promptly
|
|
24
|
+
* even when codec bodies ignore the signal. In-flight bodies that ignore the
|
|
25
|
+
* signal are abandoned and run to completion in the background — the
|
|
26
|
+
* cooperative-cancellation contract documented in ADR 204.
|
|
27
|
+
*
|
|
28
|
+
* Call sites still SHOULD pre-check `signal.aborted` and short-circuit with
|
|
29
|
+
* a phase-tagged `RUNTIME.ABORTED` envelope before invoking this helper —
|
|
30
|
+
* that path is the canonical "aborted at entry" surface and avoids
|
|
31
|
+
* scheduling the work promise. As a defensive belt-and-braces, this helper
|
|
32
|
+
* also handles the already-aborted case internally: `AbortSignal` does not
|
|
33
|
+
* replay past abort events to listeners registered after the abort, so we
|
|
34
|
+
* inspect `signal.aborted` synchronously and reject with the sentinel
|
|
35
|
+
* before installing the listener. The rejection is still attributed to the
|
|
36
|
+
* abort path via the sentinel-identity check.
|
|
37
|
+
*
|
|
38
|
+
* Distinguishing the rejection source is load-bearing for AC-ERR4
|
|
39
|
+
* (`RUNTIME.ENCODE_FAILED` / `RUNTIME.DECODE_FAILED` pass through unchanged).
|
|
40
|
+
* The semantically equivalent `abortable(signal)` helper in
|
|
41
|
+
* `@prisma-next/utils` rejects with `signal.reason ?? new DOMException(...)`,
|
|
42
|
+
* which is not stably distinguishable from a codec-thrown error by identity
|
|
43
|
+
* alone (a fresh fallback DOMException is allocated per call). We instead
|
|
44
|
+
* track abort attribution with a unique sentinel: only the `onAbort` listener
|
|
45
|
+
* installed here ever rejects with the sentinel, so an `error === sentinel`
|
|
46
|
+
* identity check after the race is unambiguous.
|
|
47
|
+
*
|
|
48
|
+
* Lives in `framework-components` (rather than the SQL family, where it
|
|
49
|
+
* originated in m2) so every family runtime that needs cooperative
|
|
50
|
+
* cancellation around a codec-dispatch `Promise.all` (SQL encode + decode
|
|
51
|
+
* today, Mongo encode in m3) shares the same attribution logic.
|
|
52
|
+
*/
|
|
53
|
+
export async function raceAgainstAbort<T>(
|
|
54
|
+
work: Promise<T>,
|
|
55
|
+
signal: AbortSignal | undefined,
|
|
56
|
+
phase: RuntimeAbortedPhase,
|
|
57
|
+
): Promise<T> {
|
|
58
|
+
if (signal === undefined) {
|
|
59
|
+
return await work;
|
|
60
|
+
}
|
|
61
|
+
const sentinel: { reason: unknown } = { reason: undefined };
|
|
62
|
+
let onAbort: (() => void) | undefined;
|
|
63
|
+
|
|
64
|
+
const abortPromise = new Promise<never>((_, reject) => {
|
|
65
|
+
if (signal.aborted) {
|
|
66
|
+
sentinel.reason = signal.reason;
|
|
67
|
+
reject(sentinel);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
onAbort = () => {
|
|
71
|
+
sentinel.reason = signal.reason;
|
|
72
|
+
reject(sentinel);
|
|
73
|
+
};
|
|
74
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
return await Promise.race([work, abortPromise]);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (error === sentinel) {
|
|
81
|
+
throw runtimeAborted(phase, sentinel.reason);
|
|
82
|
+
}
|
|
83
|
+
throw error;
|
|
84
|
+
} finally {
|
|
85
|
+
if (onAbort) {
|
|
86
|
+
signal.removeEventListener('abort', onAbort);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|