@prisma-next/framework-components 0.5.0-dev.9 → 0.5.0
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 +51 -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 -76
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +83 -58
- package/dist/control.mjs.map +1 -1
- package/dist/emission-types-CMv_053d.d.mts +38 -0
- package/dist/emission-types-CMv_053d.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-CHuBHXQN.d.mts} +45 -58
- package/dist/framework-components-CHuBHXQN.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 +273 -37
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +172 -30
- 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 -111
- package/src/control/emission-types.ts +48 -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/race-against-abort.ts +89 -0
- package/src/execution/run-with-middleware.ts +153 -0
- package/src/{runtime-core.ts → execution/runtime-core.ts} +27 -3
- 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 -14
- 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 -9
- 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 -49
- 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/run-with-middleware.ts +0 -77
- package/src/runtime-error.ts +0 -55
- package/src/runtime-middleware.ts +0 -87
- /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/{query-plan.ts → execution/query-plan.ts} +0 -0
- /package/src/{types-import-spec.ts → shared/types-import-spec.ts} +0 -0
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ColumnDefault,
|
|
3
|
+
ExecutionMutationDefaultPhases,
|
|
4
|
+
ExecutionMutationDefaultValue,
|
|
5
|
+
} from '@prisma-next/contract/types';
|
|
6
|
+
import {
|
|
7
|
+
isColumnDefaultLiteralInputValue,
|
|
8
|
+
isExecutionMutationDefaultValue,
|
|
9
|
+
} from '@prisma-next/contract/types';
|
|
1
10
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
2
11
|
|
|
3
12
|
export type AuthoringArgRef = {
|
|
@@ -24,6 +33,7 @@ interface AuthoringArgumentDescriptorCommon {
|
|
|
24
33
|
export type AuthoringArgumentDescriptor = AuthoringArgumentDescriptorCommon &
|
|
25
34
|
(
|
|
26
35
|
| { readonly kind: 'string' }
|
|
36
|
+
| { readonly kind: 'boolean' }
|
|
27
37
|
| {
|
|
28
38
|
readonly kind: 'number';
|
|
29
39
|
readonly integer?: boolean;
|
|
@@ -63,10 +73,15 @@ export type AuthoringColumnDefaultTemplate =
|
|
|
63
73
|
| AuthoringColumnDefaultTemplateLiteral
|
|
64
74
|
| AuthoringColumnDefaultTemplateFunction;
|
|
65
75
|
|
|
76
|
+
export interface AuthoringExecutionDefaultsTemplate {
|
|
77
|
+
readonly onCreate?: AuthoringTemplateValue;
|
|
78
|
+
readonly onUpdate?: AuthoringTemplateValue;
|
|
79
|
+
}
|
|
80
|
+
|
|
66
81
|
export interface AuthoringFieldPresetOutput extends AuthoringStorageTypeTemplate {
|
|
67
82
|
readonly nullable?: boolean;
|
|
68
83
|
readonly default?: AuthoringColumnDefaultTemplate;
|
|
69
|
-
readonly
|
|
84
|
+
readonly executionDefaults?: AuthoringExecutionDefaultsTemplate;
|
|
70
85
|
readonly id?: boolean;
|
|
71
86
|
readonly unique?: boolean;
|
|
72
87
|
}
|
|
@@ -132,6 +147,148 @@ export function isAuthoringFieldPresetDescriptor(
|
|
|
132
147
|
);
|
|
133
148
|
}
|
|
134
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Returns true when `namespace` is a non-leaf key in `contributions.field`.
|
|
152
|
+
*
|
|
153
|
+
* `AuthoringFieldNamespace` permits a leaf descriptor at any depth — including
|
|
154
|
+
* the root — so a top-level `field: { Foo: { kind: 'fieldPreset', ... } }`
|
|
155
|
+
* registration must NOT be treated as a "namespace" with sub-paths. Callers
|
|
156
|
+
* use this predicate to gate dot-namespaced lookups (e.g. PSL `@Foo.bar`).
|
|
157
|
+
*/
|
|
158
|
+
export function hasRegisteredFieldNamespace(
|
|
159
|
+
contributions: AuthoringContributions | undefined,
|
|
160
|
+
namespace: string,
|
|
161
|
+
): boolean {
|
|
162
|
+
if (contributions?.field === undefined || !Object.hasOwn(contributions.field, namespace)) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
return !isAuthoringFieldPresetDescriptor(contributions.field[namespace]);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function isPlainNamespaceObject(value: unknown): value is Record<string, unknown> {
|
|
169
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Merges `source` into `target` recursively at the descriptor-namespace
|
|
174
|
+
* level. `leafGuard` decides which values are descriptors (terminal
|
|
175
|
+
* merge points; same-path registrations across components are reported
|
|
176
|
+
* as duplicates) versus sub-namespaces (recursion targets).
|
|
177
|
+
*
|
|
178
|
+
* Path segments are validated against prototype-pollution names
|
|
179
|
+
* (`__proto__`, `constructor`, `prototype`). A value that is neither a
|
|
180
|
+
* recognized leaf nor a plain object — e.g. a malformed descriptor
|
|
181
|
+
* where the canonical leaf guard rejected it for missing `output` —
|
|
182
|
+
* is reported as an invalid contribution rather than recursed into,
|
|
183
|
+
* which would either silently mangle state or infinite-loop on
|
|
184
|
+
* primitive properties.
|
|
185
|
+
*
|
|
186
|
+
* Within-registry duplicate detection is this walker's job;
|
|
187
|
+
* cross-registry detection runs separately via
|
|
188
|
+
* `assertNoCrossRegistryCollisions` after merging completes.
|
|
189
|
+
*/
|
|
190
|
+
export function mergeAuthoringNamespaces(
|
|
191
|
+
target: Record<string, unknown>,
|
|
192
|
+
source: Record<string, unknown>,
|
|
193
|
+
path: readonly string[],
|
|
194
|
+
leafGuard: (value: unknown) => boolean,
|
|
195
|
+
label: string,
|
|
196
|
+
): void {
|
|
197
|
+
const assertSafePath = (currentPath: readonly string[]) => {
|
|
198
|
+
const blockedSegment = currentPath.find(
|
|
199
|
+
(segment) => segment === '__proto__' || segment === 'constructor' || segment === 'prototype',
|
|
200
|
+
);
|
|
201
|
+
if (blockedSegment) {
|
|
202
|
+
throw new Error(
|
|
203
|
+
`Invalid authoring ${label} helper "${currentPath.join('.')}". Helper path segments must not use "${blockedSegment}".`,
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
for (const [key, sourceValue] of Object.entries(source)) {
|
|
209
|
+
const currentPath = [...path, key];
|
|
210
|
+
assertSafePath(currentPath);
|
|
211
|
+
const hasExistingValue = Object.hasOwn(target, key);
|
|
212
|
+
const existingValue = hasExistingValue ? target[key] : undefined;
|
|
213
|
+
|
|
214
|
+
if (!hasExistingValue) {
|
|
215
|
+
target[key] = sourceValue;
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const existingIsLeaf = leafGuard(existingValue);
|
|
220
|
+
const sourceIsLeaf = leafGuard(sourceValue);
|
|
221
|
+
|
|
222
|
+
if (existingIsLeaf || sourceIsLeaf) {
|
|
223
|
+
throw new Error(
|
|
224
|
+
`Duplicate authoring ${label} helper "${currentPath.join('.')}". Helper names must be unique across composed packs.`,
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (!isPlainNamespaceObject(existingValue) || !isPlainNamespaceObject(sourceValue)) {
|
|
229
|
+
throw new Error(
|
|
230
|
+
`Invalid authoring ${label} helper "${currentPath.join('.')}". Expected a sub-namespace object or a recognized descriptor; received a malformed value.`,
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
mergeAuthoringNamespaces(existingValue, sourceValue, currentPath, leafGuard, label);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function collectAuthoringLeafPaths(
|
|
239
|
+
namespace: Readonly<Record<string, unknown>>,
|
|
240
|
+
isLeaf: (value: unknown) => boolean,
|
|
241
|
+
path: readonly string[] = [],
|
|
242
|
+
): string[] {
|
|
243
|
+
const paths: string[] = [];
|
|
244
|
+
for (const [key, value] of Object.entries(namespace)) {
|
|
245
|
+
const currentPath = [...path, key];
|
|
246
|
+
if (isLeaf(value)) {
|
|
247
|
+
paths.push(currentPath.join('.'));
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
251
|
+
paths.push(
|
|
252
|
+
...collectAuthoringLeafPaths(
|
|
253
|
+
value as Readonly<Record<string, unknown>>,
|
|
254
|
+
isLeaf,
|
|
255
|
+
currentPath,
|
|
256
|
+
),
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return paths;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export function assertNoCrossRegistryCollisions(
|
|
264
|
+
typeNamespace: AuthoringTypeNamespace,
|
|
265
|
+
fieldNamespace: AuthoringFieldNamespace,
|
|
266
|
+
): void {
|
|
267
|
+
const typePaths = new Set(
|
|
268
|
+
collectAuthoringLeafPaths(typeNamespace, isAuthoringTypeConstructorDescriptor),
|
|
269
|
+
);
|
|
270
|
+
// Within-registry duplicate detection is handled upstream by the merge
|
|
271
|
+
// walker (`mergeAuthoringNamespaces` in control-stack.ts and
|
|
272
|
+
// `mergeHelperNamespaces` in composed-authoring-helpers.ts), which throws
|
|
273
|
+
// on same-path registrations within either registry before this check
|
|
274
|
+
// runs. This function only handles the cross-registry case — and an
|
|
275
|
+
// empty type namespace makes a cross-registry collision structurally
|
|
276
|
+
// impossible, so the early-out is sound.
|
|
277
|
+
if (typePaths.size === 0) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
for (const fieldPath of collectAuthoringLeafPaths(
|
|
281
|
+
fieldNamespace,
|
|
282
|
+
isAuthoringFieldPresetDescriptor,
|
|
283
|
+
)) {
|
|
284
|
+
if (typePaths.has(fieldPath)) {
|
|
285
|
+
throw new Error(
|
|
286
|
+
`Ambiguous authoring registry path "${fieldPath}". The same path is registered as both a type constructor and a field preset; PSL resolution would be ambiguous. Register each path in only one of authoringContributions.field / authoringContributions.type.`,
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
135
292
|
export function resolveAuthoringTemplateValue(
|
|
136
293
|
template: AuthoringTemplateValue,
|
|
137
294
|
args: readonly unknown[],
|
|
@@ -188,6 +345,13 @@ function validateAuthoringArgument(
|
|
|
188
345
|
return;
|
|
189
346
|
}
|
|
190
347
|
|
|
348
|
+
if (descriptor.kind === 'boolean') {
|
|
349
|
+
if (typeof value !== 'boolean') {
|
|
350
|
+
throw new Error(`Authoring helper argument at ${path} must be a boolean`);
|
|
351
|
+
}
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
|
|
191
355
|
if (descriptor.kind === 'stringArray') {
|
|
192
356
|
if (!Array.isArray(value)) {
|
|
193
357
|
throw new Error(`Authoring helper argument at ${path} must be an array of strings`);
|
|
@@ -295,20 +459,17 @@ function resolveAuthoringStorageTypeTemplate(
|
|
|
295
459
|
function resolveAuthoringColumnDefaultTemplate(
|
|
296
460
|
template: AuthoringColumnDefaultTemplate,
|
|
297
461
|
args: readonly unknown[],
|
|
298
|
-
):
|
|
299
|
-
| {
|
|
300
|
-
readonly kind: 'literal';
|
|
301
|
-
readonly value: unknown;
|
|
302
|
-
}
|
|
303
|
-
| {
|
|
304
|
-
readonly kind: 'function';
|
|
305
|
-
readonly expression: string;
|
|
306
|
-
} {
|
|
462
|
+
): ColumnDefault {
|
|
307
463
|
if (template.kind === 'literal') {
|
|
308
464
|
const value = resolveAuthoringTemplateValue(template.value, args);
|
|
309
465
|
if (value === undefined) {
|
|
310
466
|
throw new Error('Resolved authoring literal default must not be undefined');
|
|
311
467
|
}
|
|
468
|
+
if (!isColumnDefaultLiteralInputValue(value)) {
|
|
469
|
+
throw new Error(
|
|
470
|
+
`Resolved authoring literal default must be a JSON-serializable value or Date, received ${String(value)}`,
|
|
471
|
+
);
|
|
472
|
+
}
|
|
312
473
|
return {
|
|
313
474
|
kind: 'literal',
|
|
314
475
|
value,
|
|
@@ -327,6 +488,40 @@ function resolveAuthoringColumnDefaultTemplate(
|
|
|
327
488
|
};
|
|
328
489
|
}
|
|
329
490
|
|
|
491
|
+
function resolveExecutionMutationDefaultPhase(
|
|
492
|
+
phase: 'onCreate' | 'onUpdate',
|
|
493
|
+
template: AuthoringTemplateValue,
|
|
494
|
+
args: readonly unknown[],
|
|
495
|
+
): ExecutionMutationDefaultValue {
|
|
496
|
+
const value = resolveAuthoringTemplateValue(template, args);
|
|
497
|
+
if (!isExecutionMutationDefaultValue(value)) {
|
|
498
|
+
throw new Error(
|
|
499
|
+
`Authoring preset executionDefaults.${phase} did not resolve to a valid generator descriptor (kind: 'generator', id: string).`,
|
|
500
|
+
);
|
|
501
|
+
}
|
|
502
|
+
return value;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
function resolveAuthoringExecutionDefaultsTemplate(
|
|
506
|
+
template: AuthoringExecutionDefaultsTemplate,
|
|
507
|
+
args: readonly unknown[],
|
|
508
|
+
): ExecutionMutationDefaultPhases {
|
|
509
|
+
return {
|
|
510
|
+
...ifDefined(
|
|
511
|
+
'onCreate',
|
|
512
|
+
template.onCreate !== undefined
|
|
513
|
+
? resolveExecutionMutationDefaultPhase('onCreate', template.onCreate, args)
|
|
514
|
+
: undefined,
|
|
515
|
+
),
|
|
516
|
+
...ifDefined(
|
|
517
|
+
'onUpdate',
|
|
518
|
+
template.onUpdate !== undefined
|
|
519
|
+
? resolveExecutionMutationDefaultPhase('onUpdate', template.onUpdate, args)
|
|
520
|
+
: undefined,
|
|
521
|
+
),
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
|
|
330
525
|
export function instantiateAuthoringTypeConstructor(
|
|
331
526
|
descriptor: AuthoringTypeConstructorDescriptor,
|
|
332
527
|
args: readonly unknown[],
|
|
@@ -348,16 +543,8 @@ export function instantiateAuthoringFieldPreset(
|
|
|
348
543
|
readonly typeParams?: Record<string, unknown>;
|
|
349
544
|
};
|
|
350
545
|
readonly nullable: boolean;
|
|
351
|
-
readonly default?:
|
|
352
|
-
|
|
353
|
-
readonly kind: 'literal';
|
|
354
|
-
readonly value: unknown;
|
|
355
|
-
}
|
|
356
|
-
| {
|
|
357
|
-
readonly kind: 'function';
|
|
358
|
-
readonly expression: string;
|
|
359
|
-
};
|
|
360
|
-
readonly executionDefault?: unknown;
|
|
546
|
+
readonly default?: ColumnDefault;
|
|
547
|
+
readonly executionDefaults?: ExecutionMutationDefaultPhases;
|
|
361
548
|
readonly id: boolean;
|
|
362
549
|
readonly unique: boolean;
|
|
363
550
|
} {
|
|
@@ -371,9 +558,9 @@ export function instantiateAuthoringFieldPreset(
|
|
|
371
558
|
: undefined,
|
|
372
559
|
),
|
|
373
560
|
...ifDefined(
|
|
374
|
-
'
|
|
375
|
-
descriptor.output.
|
|
376
|
-
?
|
|
561
|
+
'executionDefaults',
|
|
562
|
+
descriptor.output.executionDefaults !== undefined
|
|
563
|
+
? resolveAuthoringExecutionDefaultsTemplate(descriptor.output.executionDefaults, args)
|
|
377
564
|
: undefined,
|
|
378
565
|
),
|
|
379
566
|
id: descriptor.output.id ?? false,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AnyCodecDescriptor } from './codec-descriptor';
|
|
2
2
|
import type { AuthoringContributions } from './framework-authoring';
|
|
3
3
|
import type { ControlMutationDefaults } from './mutation-default-types';
|
|
4
4
|
import type { TypesImportSpec } from './types-import-spec';
|
|
@@ -13,10 +13,7 @@ export interface ComponentMetadata {
|
|
|
13
13
|
/**
|
|
14
14
|
* Capabilities this component provides.
|
|
15
15
|
*
|
|
16
|
-
* For adapters, capabilities must be declared on the adapter descriptor (so they are emitted into
|
|
17
|
-
* the contract) and also exposed in runtime adapter code (e.g. `adapter.profile.capabilities`);
|
|
18
|
-
* keep these declarations in sync. Targets are identifiers/descriptors and typically do not
|
|
19
|
-
* declare capabilities.
|
|
16
|
+
* For adapters, capabilities must be declared on the adapter descriptor (so they are emitted into the contract) and also exposed in runtime adapter code (e.g. `adapter.profile.capabilities`); keep these declarations in sync. Targets are identifiers/descriptors and typically do not declare capabilities.
|
|
20
17
|
*/
|
|
21
18
|
readonly capabilities?: Record<string, unknown>;
|
|
22
19
|
|
|
@@ -24,31 +21,26 @@ export interface ComponentMetadata {
|
|
|
24
21
|
readonly types?: {
|
|
25
22
|
readonly codecTypes?: {
|
|
26
23
|
/**
|
|
27
|
-
* Base codec types import spec.
|
|
28
|
-
* Optional: adapters typically provide this, extensions usually don't.
|
|
24
|
+
* Base codec types import spec. Optional: adapters typically provide this, extensions usually don't.
|
|
29
25
|
*/
|
|
30
26
|
readonly import?: TypesImportSpec;
|
|
31
27
|
/**
|
|
32
28
|
* Additional type-only imports for parameterized codec branded types.
|
|
33
29
|
*
|
|
34
|
-
* These imports are included in generated `contract.d.ts` but are NOT treated as
|
|
35
|
-
* codec type maps (i.e., they should not be intersected into `export type CodecTypes = ...`).
|
|
30
|
+
* These imports are included in generated `contract.d.ts` but are NOT treated as codec type maps (i.e., they should not be intersected into `export type CodecTypes = ...`).
|
|
36
31
|
*
|
|
37
32
|
* Example: `Vector<N>` for pgvector codecs that emit `Vector<1536>`
|
|
38
33
|
*/
|
|
39
34
|
readonly typeImports?: ReadonlyArray<TypesImportSpec>;
|
|
40
35
|
/**
|
|
41
|
-
* Optional control-plane hooks keyed by codecId.
|
|
42
|
-
* Used by family-specific planners/verifiers to handle storage types.
|
|
36
|
+
* Optional control-plane hooks keyed by codecId. Used by family-specific planners/verifiers to handle storage types.
|
|
43
37
|
*/
|
|
44
38
|
readonly controlPlaneHooks?: Record<string, unknown>;
|
|
45
39
|
/**
|
|
46
|
-
* Codec
|
|
47
|
-
* Used to build a CodecLookup for codec-dispatched type rendering during emission.
|
|
40
|
+
* Codec descriptors contributed by this component. Source of truth for codec-id-keyed metadata (`traits`, `targetTypes`, `meta`, `renderOutputType`) consumed by `extractCodecLookup`, and used to materialize representative `Codec` instances for codec-dispatched type rendering during emission.
|
|
48
41
|
*/
|
|
49
|
-
readonly
|
|
42
|
+
readonly codecDescriptors?: ReadonlyArray<AnyCodecDescriptor>;
|
|
50
43
|
};
|
|
51
|
-
readonly operationTypes?: { readonly import: TypesImportSpec };
|
|
52
44
|
readonly queryOperationTypes?: { readonly import: TypesImportSpec };
|
|
53
45
|
readonly storage?: ReadonlyArray<{
|
|
54
46
|
readonly typeId: string;
|
|
@@ -61,21 +53,17 @@ export interface ComponentMetadata {
|
|
|
61
53
|
/**
|
|
62
54
|
* Optional pure-data authoring contributions exposed by this component.
|
|
63
55
|
*
|
|
64
|
-
* These contributions are safe to include on pack refs and descriptors because
|
|
65
|
-
* they contain only declarative metadata. Higher-level authoring packages may
|
|
66
|
-
* project them into concrete helper functions for TS-first workflows.
|
|
56
|
+
* These contributions are safe to include on pack refs and descriptors because they contain only declarative metadata. Higher-level authoring packages may project them into concrete helper functions for TS-first workflows.
|
|
67
57
|
*/
|
|
68
58
|
readonly authoring?: AuthoringContributions;
|
|
69
59
|
|
|
70
60
|
/**
|
|
71
|
-
* Scalar type name to codec ID mapping contributed by this component.
|
|
72
|
-
* Assembled by `createControlStack` with duplicate detection.
|
|
61
|
+
* Scalar type name to codec ID mapping contributed by this component. Assembled by `createControlStack` with duplicate detection.
|
|
73
62
|
*/
|
|
74
63
|
readonly scalarTypeDescriptors?: ReadonlyMap<string, string>;
|
|
75
64
|
|
|
76
65
|
/**
|
|
77
|
-
* Mutation default function handlers and generator descriptors contributed
|
|
78
|
-
* by this component. Assembled by `createControlStack` with duplicate detection.
|
|
66
|
+
* Mutation default function handlers and generator descriptors contributed by this component. Assembled by `createControlStack` with duplicate detection.
|
|
79
67
|
*/
|
|
80
68
|
readonly controlMutationDefaults?: ControlMutationDefaults;
|
|
81
69
|
}
|
|
@@ -83,13 +71,9 @@ export interface ComponentMetadata {
|
|
|
83
71
|
/**
|
|
84
72
|
* Base descriptor for any framework component.
|
|
85
73
|
*
|
|
86
|
-
* All component descriptors share these fundamental properties that identify
|
|
87
|
-
* the component and provide its metadata. This interface is extended by
|
|
88
|
-
* specific descriptor types (FamilyDescriptor, TargetDescriptor, etc.).
|
|
74
|
+
* All component descriptors share these fundamental properties that identify the component and provide its metadata. This interface is extended by specific descriptor types (FamilyDescriptor, TargetDescriptor, etc.).
|
|
89
75
|
*
|
|
90
|
-
* @template Kind - Discriminator literal identifying the component type.
|
|
91
|
-
* Built-in kinds are 'family', 'target', 'adapter', 'driver', 'extension',
|
|
92
|
-
* but the type accepts any string to allow ecosystem extensions.
|
|
76
|
+
* @template Kind - Discriminator literal identifying the component type. Built-in kinds are 'family', 'target', 'adapter', 'driver', 'extension', but the type accepts any string to allow ecosystem extensions.
|
|
93
77
|
*
|
|
94
78
|
* @example
|
|
95
79
|
* ```ts
|
|
@@ -163,14 +147,12 @@ export function checkContractComponentRequirements(
|
|
|
163
147
|
/**
|
|
164
148
|
* Descriptor for a family component.
|
|
165
149
|
*
|
|
166
|
-
* A "family" represents a category of data sources with shared semantics
|
|
167
|
-
* (e.g., SQL databases, document stores). Families define:
|
|
150
|
+
* A "family" represents a category of data sources with shared semantics (e.g., SQL databases, document stores). Families define:
|
|
168
151
|
* - Query semantics and operations (SELECT, INSERT, find, aggregate, etc.)
|
|
169
152
|
* - Contract structure (tables vs collections, columns vs fields)
|
|
170
153
|
* - Type system and codecs
|
|
171
154
|
*
|
|
172
|
-
* Families are the top-level grouping. Each family contains multiple targets
|
|
173
|
-
* (e.g., SQL family contains Postgres, MySQL, SQLite targets).
|
|
155
|
+
* Families are the top-level grouping. Each family contains multiple targets (e.g., SQL family contains Postgres, MySQL, SQLite targets).
|
|
174
156
|
*
|
|
175
157
|
* Extended by plane-specific descriptors:
|
|
176
158
|
* - `ControlFamilyDescriptor` - adds `emission` for CLI/tooling operations
|
|
@@ -195,13 +177,11 @@ export interface FamilyDescriptor<TFamilyId extends string> extends ComponentDes
|
|
|
195
177
|
/**
|
|
196
178
|
* Descriptor for a target component.
|
|
197
179
|
*
|
|
198
|
-
* A "target" represents a specific database or data store within a family
|
|
199
|
-
* (e.g., Postgres, MySQL, MongoDB). Targets define:
|
|
180
|
+
* A "target" represents a specific database or data store within a family (e.g., Postgres, MySQL, MongoDB). Targets define:
|
|
200
181
|
* - Native type mappings (e.g., Postgres int4 → TypeScript number)
|
|
201
182
|
* - Target-specific capabilities (e.g., RETURNING, LATERAL joins)
|
|
202
183
|
*
|
|
203
|
-
* Targets are bound to a family and provide the target-specific implementation
|
|
204
|
-
* details that adapters and drivers use.
|
|
184
|
+
* Targets are bound to a family and provide the target-specific implementation details that adapters and drivers use.
|
|
205
185
|
*
|
|
206
186
|
* Extended by plane-specific descriptors:
|
|
207
187
|
* - `ControlTargetDescriptor` - adds optional `migrations` capability
|
|
@@ -229,8 +209,7 @@ export interface TargetDescriptor<TFamilyId extends string, TTargetId extends st
|
|
|
229
209
|
}
|
|
230
210
|
|
|
231
211
|
/**
|
|
232
|
-
* Base shape for any pack reference.
|
|
233
|
-
* Pack refs are pure JSON-friendly objects safe to import in authoring flows.
|
|
212
|
+
* Base shape for any pack reference. Pack refs are pure JSON-friendly objects safe to import in authoring flows.
|
|
234
213
|
*/
|
|
235
214
|
export interface PackRefBase<Kind extends string, TFamilyId extends string>
|
|
236
215
|
extends ComponentMetadata {
|
|
@@ -274,14 +253,12 @@ export type DriverPackRef<
|
|
|
274
253
|
/**
|
|
275
254
|
* Descriptor for an adapter component.
|
|
276
255
|
*
|
|
277
|
-
* An "adapter" provides the protocol and dialect implementation for a target.
|
|
278
|
-
* Adapters handle:
|
|
256
|
+
* An "adapter" provides the protocol and dialect implementation for a target. Adapters handle:
|
|
279
257
|
* - SQL/query generation (lowering AST to target-specific syntax)
|
|
280
258
|
* - Codec registration (encoding/decoding between JS and wire types)
|
|
281
259
|
* - Type mappings and coercions
|
|
282
260
|
*
|
|
283
|
-
* Adapters are bound to a specific family+target combination and work with
|
|
284
|
-
* any compatible driver for that target.
|
|
261
|
+
* Adapters are bound to a specific family+target combination and work with any compatible driver for that target.
|
|
285
262
|
*
|
|
286
263
|
* Extended by plane-specific descriptors:
|
|
287
264
|
* - `ControlAdapterDescriptor` - control-plane factory
|
|
@@ -311,16 +288,13 @@ export interface AdapterDescriptor<TFamilyId extends string, TTargetId extends s
|
|
|
311
288
|
/**
|
|
312
289
|
* Descriptor for a driver component.
|
|
313
290
|
*
|
|
314
|
-
* A "driver" provides the connection and execution layer for a target.
|
|
315
|
-
* Drivers handle:
|
|
291
|
+
* A "driver" provides the connection and execution layer for a target. Drivers handle:
|
|
316
292
|
* - Connection management (pooling, timeouts, retries)
|
|
317
293
|
* - Query execution (sending SQL/commands, receiving results)
|
|
318
294
|
* - Transaction management
|
|
319
295
|
* - Wire protocol communication
|
|
320
296
|
*
|
|
321
|
-
* Drivers are bound to a specific family+target and work with any compatible
|
|
322
|
-
* adapter. Multiple drivers can exist for the same target (e.g., node-postgres
|
|
323
|
-
* vs postgres.js for Postgres).
|
|
297
|
+
* Drivers are bound to a specific family+target and work with any compatible adapter. Multiple drivers can exist for the same target (e.g., node-postgres vs postgres.js for Postgres).
|
|
324
298
|
*
|
|
325
299
|
* Extended by plane-specific descriptors:
|
|
326
300
|
* - `ControlDriverDescriptor` - creates driver from connection URL
|
|
@@ -355,8 +329,7 @@ export interface DriverDescriptor<TFamilyId extends string, TTargetId extends st
|
|
|
355
329
|
* - Custom types and codecs (e.g., vector type)
|
|
356
330
|
* - Extended query capabilities
|
|
357
331
|
*
|
|
358
|
-
* Extensions are bound to a specific family+target and are registered in the
|
|
359
|
-
* config alongside the core components. Multiple extensions can be used together.
|
|
332
|
+
* Extensions are bound to a specific family+target and are registered in the config alongside the core components. Multiple extensions can be used together.
|
|
360
333
|
*
|
|
361
334
|
* Extended by plane-specific descriptors:
|
|
362
335
|
* - `ControlExtensionDescriptor` - control-plane extension factory
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
ColumnDefault,
|
|
3
|
+
ExecutionMutationDefaultPhases,
|
|
4
|
+
ExecutionMutationDefaultValue,
|
|
5
|
+
} from '@prisma-next/contract/types';
|
|
2
6
|
|
|
3
7
|
interface SourcePosition {
|
|
4
8
|
readonly offset: number;
|
|
@@ -60,7 +64,16 @@ export type DefaultFunctionRegistry = ReadonlyMap<string, DefaultFunctionRegistr
|
|
|
60
64
|
|
|
61
65
|
export interface MutationDefaultGeneratorDescriptor {
|
|
62
66
|
readonly id: string;
|
|
63
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Codec ids the generator is compatible with when the codec choice
|
|
69
|
+
* and the generator choice are made independently by the contract
|
|
70
|
+
* author. Set when the registry-coherence check is meaningful
|
|
71
|
+
* (the codec and the generator can be paired arbitrarily by the
|
|
72
|
+
* caller); omitted when the generator is only reachable through a
|
|
73
|
+
* descriptor that co-registers a fixed codec, so coherence is
|
|
74
|
+
* structural and the list would be tautological.
|
|
75
|
+
*/
|
|
76
|
+
readonly applicableCodecIds?: readonly string[];
|
|
64
77
|
readonly resolveGeneratedColumnDescriptor?: (input: {
|
|
65
78
|
readonly generated: ExecutionMutationDefaultValue;
|
|
66
79
|
}) =>
|
|
@@ -71,6 +84,13 @@ export interface MutationDefaultGeneratorDescriptor {
|
|
|
71
84
|
readonly typeParams?: Record<string, unknown>;
|
|
72
85
|
}
|
|
73
86
|
| undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Construct the `onCreate`/`onUpdate` phases value owned by this
|
|
89
|
+
* generator. Authoring layers (PSL `temporal.updatedAt()`, TS field presets) call
|
|
90
|
+
* this instead of building the literal inline so PSL/TS-authored
|
|
91
|
+
* contracts stay byte-equivalent for any future params-bearing generator.
|
|
92
|
+
*/
|
|
93
|
+
readonly buildPhases?: (args?: Record<string, unknown>) => ExecutionMutationDefaultPhases;
|
|
74
94
|
}
|
|
75
95
|
|
|
76
96
|
export interface ControlMutationDefaultEntry {
|
package/dist/authoring.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authoring.mjs","names":["resolved: Record<string, unknown>"],"sources":["../src/framework-authoring.ts"],"sourcesContent":["import { ifDefined } from '@prisma-next/utils/defined';\n\nexport type AuthoringArgRef = {\n readonly kind: 'arg';\n readonly index: number;\n readonly path?: readonly string[];\n readonly default?: AuthoringTemplateValue;\n};\n\nexport type AuthoringTemplateValue =\n | string\n | number\n | boolean\n | null\n | AuthoringArgRef\n | readonly AuthoringTemplateValue[]\n | { readonly [key: string]: AuthoringTemplateValue };\n\ninterface AuthoringArgumentDescriptorCommon {\n readonly name?: string;\n readonly optional?: boolean;\n}\n\nexport type AuthoringArgumentDescriptor = AuthoringArgumentDescriptorCommon &\n (\n | { readonly kind: 'string' }\n | {\n readonly kind: 'number';\n readonly integer?: boolean;\n readonly minimum?: number;\n readonly maximum?: number;\n }\n | { readonly kind: 'stringArray' }\n | {\n readonly kind: 'object';\n readonly properties: Record<string, AuthoringArgumentDescriptor>;\n }\n );\n\nexport interface AuthoringStorageTypeTemplate {\n readonly codecId: string;\n readonly nativeType: AuthoringTemplateValue;\n readonly typeParams?: Record<string, AuthoringTemplateValue>;\n}\n\nexport interface AuthoringTypeConstructorDescriptor {\n readonly kind: 'typeConstructor';\n readonly args?: readonly AuthoringArgumentDescriptor[];\n readonly output: AuthoringStorageTypeTemplate;\n}\n\nexport interface AuthoringColumnDefaultTemplateLiteral {\n readonly kind: 'literal';\n readonly value: AuthoringTemplateValue;\n}\n\nexport interface AuthoringColumnDefaultTemplateFunction {\n readonly kind: 'function';\n readonly expression: AuthoringTemplateValue;\n}\n\nexport type AuthoringColumnDefaultTemplate =\n | AuthoringColumnDefaultTemplateLiteral\n | AuthoringColumnDefaultTemplateFunction;\n\nexport interface AuthoringFieldPresetOutput extends AuthoringStorageTypeTemplate {\n readonly nullable?: boolean;\n readonly default?: AuthoringColumnDefaultTemplate;\n readonly executionDefault?: AuthoringTemplateValue;\n readonly id?: boolean;\n readonly unique?: boolean;\n}\n\nexport interface AuthoringFieldPresetDescriptor {\n readonly kind: 'fieldPreset';\n readonly args?: readonly AuthoringArgumentDescriptor[];\n readonly output: AuthoringFieldPresetOutput;\n}\n\nexport type AuthoringTypeNamespace = {\n readonly [name: string]: AuthoringTypeConstructorDescriptor | AuthoringTypeNamespace;\n};\n\nexport type AuthoringFieldNamespace = {\n readonly [name: string]: AuthoringFieldPresetDescriptor | AuthoringFieldNamespace;\n};\n\nexport interface AuthoringContributions {\n readonly type?: AuthoringTypeNamespace;\n readonly field?: AuthoringFieldNamespace;\n}\n\nexport function isAuthoringArgRef(value: unknown): value is AuthoringArgRef {\n if (typeof value !== 'object' || value === null || (value as { kind?: unknown }).kind !== 'arg') {\n return false;\n }\n const { index, path } = value as { index?: unknown; path?: unknown };\n if (typeof index !== 'number' || !Number.isInteger(index) || index < 0) {\n return false;\n }\n if (path !== undefined && (!Array.isArray(path) || path.some((s) => typeof s !== 'string'))) {\n return false;\n }\n return true;\n}\n\nfunction isAuthoringTemplateRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nexport function isAuthoringTypeConstructorDescriptor(\n value: unknown,\n): value is AuthoringTypeConstructorDescriptor {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { kind?: unknown }).kind === 'typeConstructor' &&\n typeof (value as { output?: unknown }).output === 'object' &&\n (value as { output?: unknown }).output !== null\n );\n}\n\nexport function isAuthoringFieldPresetDescriptor(\n value: unknown,\n): value is AuthoringFieldPresetDescriptor {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { kind?: unknown }).kind === 'fieldPreset' &&\n typeof (value as { output?: unknown }).output === 'object' &&\n (value as { output?: unknown }).output !== null\n );\n}\n\nexport function resolveAuthoringTemplateValue(\n template: AuthoringTemplateValue,\n args: readonly unknown[],\n): unknown {\n if (isAuthoringArgRef(template)) {\n let value = args[template.index];\n\n for (const segment of template.path ?? []) {\n if (!isAuthoringTemplateRecord(value) || !Object.hasOwn(value, segment)) {\n value = undefined;\n break;\n }\n value = (value as Record<string, unknown>)[segment];\n }\n\n if (value === undefined && template.default !== undefined) {\n return resolveAuthoringTemplateValue(template.default, args);\n }\n\n return value;\n }\n if (Array.isArray(template)) {\n return template.map((value) => resolveAuthoringTemplateValue(value, args));\n }\n if (typeof template === 'object' && template !== null) {\n const resolved: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(template)) {\n const resolvedValue = resolveAuthoringTemplateValue(value, args);\n if (resolvedValue !== undefined) {\n resolved[key] = resolvedValue;\n }\n }\n return resolved;\n }\n return template;\n}\n\nfunction validateAuthoringArgument(\n descriptor: AuthoringArgumentDescriptor,\n value: unknown,\n path: string,\n): void {\n if (value === undefined) {\n if (descriptor.optional) {\n return;\n }\n throw new Error(`Missing required authoring helper argument at ${path}`);\n }\n\n if (descriptor.kind === 'string') {\n if (typeof value !== 'string') {\n throw new Error(`Authoring helper argument at ${path} must be a string`);\n }\n return;\n }\n\n if (descriptor.kind === 'stringArray') {\n if (!Array.isArray(value)) {\n throw new Error(`Authoring helper argument at ${path} must be an array of strings`);\n }\n for (const entry of value) {\n if (typeof entry !== 'string') {\n throw new Error(`Authoring helper argument at ${path} must be an array of strings`);\n }\n }\n return;\n }\n\n if (descriptor.kind === 'object') {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new Error(`Authoring helper argument at ${path} must be an object`);\n }\n\n const input = value as Record<string, unknown>;\n const expectedKeys = new Set(Object.keys(descriptor.properties));\n\n for (const key of Object.keys(input)) {\n if (!expectedKeys.has(key)) {\n throw new Error(`Authoring helper argument at ${path} contains unknown property \"${key}\"`);\n }\n }\n\n for (const [key, propertyDescriptor] of Object.entries(descriptor.properties)) {\n validateAuthoringArgument(propertyDescriptor, input[key], `${path}.${key}`);\n }\n\n return;\n }\n\n if (typeof value !== 'number' || Number.isNaN(value)) {\n throw new Error(`Authoring helper argument at ${path} must be a number`);\n }\n\n if (descriptor.integer && !Number.isInteger(value)) {\n throw new Error(`Authoring helper argument at ${path} must be an integer`);\n }\n if (descriptor.minimum !== undefined && value < descriptor.minimum) {\n throw new Error(\n `Authoring helper argument at ${path} must be >= ${descriptor.minimum}, received ${value}`,\n );\n }\n if (descriptor.maximum !== undefined && value > descriptor.maximum) {\n throw new Error(\n `Authoring helper argument at ${path} must be <= ${descriptor.maximum}, received ${value}`,\n );\n }\n}\n\nexport function validateAuthoringHelperArguments(\n helperPath: string,\n descriptors: readonly AuthoringArgumentDescriptor[] | undefined,\n args: readonly unknown[],\n): void {\n const expected = descriptors ?? [];\n const minimumArgs = expected.reduce(\n (count, descriptor, index) => (descriptor.optional ? count : index + 1),\n 0,\n );\n if (args.length < minimumArgs || args.length > expected.length) {\n throw new Error(\n `${helperPath} expects ${minimumArgs === expected.length ? expected.length : `${minimumArgs}-${expected.length}`} argument(s), received ${args.length}`,\n );\n }\n\n expected.forEach((descriptor, index) => {\n validateAuthoringArgument(descriptor, args[index], `${helperPath}[${index}]`);\n });\n}\n\nfunction resolveAuthoringStorageTypeTemplate(\n template: AuthoringStorageTypeTemplate,\n args: readonly unknown[],\n): {\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeParams?: Record<string, unknown>;\n} {\n const nativeType = resolveAuthoringTemplateValue(template.nativeType, args);\n if (typeof nativeType !== 'string') {\n throw new Error(\n `Resolved authoring nativeType must be a string for codec \"${template.codecId}\", received ${String(nativeType)}`,\n );\n }\n const typeParams =\n template.typeParams === undefined\n ? undefined\n : resolveAuthoringTemplateValue(template.typeParams, args);\n if (typeParams !== undefined && !isAuthoringTemplateRecord(typeParams)) {\n throw new Error(\n `Resolved authoring typeParams must be an object for codec \"${template.codecId}\", received ${String(typeParams)}`,\n );\n }\n\n return {\n codecId: template.codecId,\n nativeType,\n ...(typeParams === undefined ? {} : { typeParams }),\n };\n}\n\nfunction resolveAuthoringColumnDefaultTemplate(\n template: AuthoringColumnDefaultTemplate,\n args: readonly unknown[],\n):\n | {\n readonly kind: 'literal';\n readonly value: unknown;\n }\n | {\n readonly kind: 'function';\n readonly expression: string;\n } {\n if (template.kind === 'literal') {\n const value = resolveAuthoringTemplateValue(template.value, args);\n if (value === undefined) {\n throw new Error('Resolved authoring literal default must not be undefined');\n }\n return {\n kind: 'literal',\n value,\n };\n }\n\n const expression = resolveAuthoringTemplateValue(template.expression, args);\n if (expression === undefined || (typeof expression === 'object' && expression !== null)) {\n throw new Error(\n `Resolved authoring function default expression must resolve to a primitive, received ${String(expression)}`,\n );\n }\n return {\n kind: 'function',\n expression: String(expression),\n };\n}\n\nexport function instantiateAuthoringTypeConstructor(\n descriptor: AuthoringTypeConstructorDescriptor,\n args: readonly unknown[],\n): {\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeParams?: Record<string, unknown>;\n} {\n return resolveAuthoringStorageTypeTemplate(descriptor.output, args);\n}\n\nexport function instantiateAuthoringFieldPreset(\n descriptor: AuthoringFieldPresetDescriptor,\n args: readonly unknown[],\n): {\n readonly descriptor: {\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeParams?: Record<string, unknown>;\n };\n readonly nullable: boolean;\n readonly default?:\n | {\n readonly kind: 'literal';\n readonly value: unknown;\n }\n | {\n readonly kind: 'function';\n readonly expression: string;\n };\n readonly executionDefault?: unknown;\n readonly id: boolean;\n readonly unique: boolean;\n} {\n return {\n descriptor: resolveAuthoringStorageTypeTemplate(descriptor.output, args),\n nullable: descriptor.output.nullable ?? false,\n ...ifDefined(\n 'default',\n descriptor.output.default !== undefined\n ? resolveAuthoringColumnDefaultTemplate(descriptor.output.default, args)\n : undefined,\n ),\n ...ifDefined(\n 'executionDefault',\n descriptor.output.executionDefault !== undefined\n ? resolveAuthoringTemplateValue(descriptor.output.executionDefault, args)\n : undefined,\n ),\n id: descriptor.output.id ?? false,\n unique: descriptor.output.unique ?? false,\n };\n}\n"],"mappings":";;;AA4FA,SAAgB,kBAAkB,OAA0C;AAC1E,KAAI,OAAO,UAAU,YAAY,UAAU,QAAS,MAA6B,SAAS,MACxF,QAAO;CAET,MAAM,EAAE,OAAO,SAAS;AACxB,KAAI,OAAO,UAAU,YAAY,CAAC,OAAO,UAAU,MAAM,IAAI,QAAQ,EACnE,QAAO;AAET,KAAI,SAAS,WAAc,CAAC,MAAM,QAAQ,KAAK,IAAI,KAAK,MAAM,MAAM,OAAO,MAAM,SAAS,EACxF,QAAO;AAET,QAAO;;AAGT,SAAS,0BAA0B,OAAkD;AACnF,QAAO,OAAO,UAAU,YAAY,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L,YAAY,oCAAoC,WAAW,QAAQ,KAAK;EACxE,UAAU,WAAW,OAAO,YAAY;EACxC,GAAG,UACD,WACA,WAAW,OAAO,YAAY,SAC1B,sCAAsC,WAAW,OAAO,SAAS,KAAK,GACtE,OACL;EACD,GAAG,UACD,oBACA,WAAW,OAAO,qBAAqB,SACnC,8BAA8B,WAAW,OAAO,kBAAkB,KAAK,GACvE,OACL;EACD,IAAI,WAAW,OAAO,MAAM;EAC5B,QAAQ,WAAW,OAAO,UAAU;EACrC"}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { JsonValue } from "@prisma-next/contract/types";
|
|
2
|
-
|
|
3
|
-
//#region src/codec-types.d.ts
|
|
4
|
-
type CodecTrait = 'equality' | 'order' | 'boolean' | 'numeric' | 'textual';
|
|
5
|
-
/**
|
|
6
|
-
* A codec is the contract between an application value and its on-wire and
|
|
7
|
-
* on-contract-disk representations.
|
|
8
|
-
*
|
|
9
|
-
* The author's mental model is two JS-side types — `TInput` (the
|
|
10
|
-
* application JS type) and `TWire` (the database driver wire format) —
|
|
11
|
-
* plus `JsonValue` for build-time contract artifacts. The codec translates
|
|
12
|
-
* `TInput` to `TWire` on writes and back on reads, and to/from `JsonValue`
|
|
13
|
-
* during contract emission and loading.
|
|
14
|
-
*
|
|
15
|
-
* Three representations participate:
|
|
16
|
-
* - **Input** (`TInput`): the JS type at the application boundary.
|
|
17
|
-
* - **Wire** (`TWire`): the format exchanged with the database driver.
|
|
18
|
-
* - **JSON** (`JsonValue`): a JSON-safe form used in contract artifacts.
|
|
19
|
-
*
|
|
20
|
-
* Codec methods split into two groups:
|
|
21
|
-
*
|
|
22
|
-
* - **Query-time** methods (`encode`, `decode`) run per row/parameter at the
|
|
23
|
-
* IO boundary; they are required and Promise-returning. The per-family
|
|
24
|
-
* codec factory accepts sync or async author functions and lifts sync
|
|
25
|
-
* ones to Promise-shaped methods automatically.
|
|
26
|
-
* - **Build-time** methods (`encodeJson`, `decodeJson`, `renderOutputType`)
|
|
27
|
-
* run when the contract is serialized, loaded, or when client types are
|
|
28
|
-
* emitted. They stay synchronous so contract validation and client
|
|
29
|
-
* construction are synchronous.
|
|
30
|
-
*
|
|
31
|
-
* Target-family codec interfaces extend this base with target-shaped
|
|
32
|
-
* metadata.
|
|
33
|
-
*/
|
|
34
|
-
interface Codec<Id extends string = string, TTraits extends readonly CodecTrait[] = readonly CodecTrait[], TWire = unknown, TInput = unknown> {
|
|
35
|
-
/** Unique codec identifier in `namespace/name@version` format (e.g. `pg/timestamptz@1`). */
|
|
36
|
-
readonly id: Id;
|
|
37
|
-
/** Database-native type names this codec handles (e.g. `['timestamptz']`). */
|
|
38
|
-
readonly targetTypes: readonly string[];
|
|
39
|
-
/** Semantic traits for operator gating (e.g. equality, order, numeric). */
|
|
40
|
-
readonly traits?: TTraits;
|
|
41
|
-
/** Converts a JS value to the wire format expected by the database driver. Always Promise-returning at the boundary. */
|
|
42
|
-
encode(value: TInput): Promise<TWire>;
|
|
43
|
-
/** Converts a wire value from the database driver into the JS application type. Always Promise-returning at the boundary. */
|
|
44
|
-
decode(wire: TWire): Promise<TInput>;
|
|
45
|
-
/** Converts a JS value to a JSON-safe representation for contract serialization. Synchronous; called during contract emission. */
|
|
46
|
-
encodeJson(value: TInput): JsonValue;
|
|
47
|
-
/** Converts a JSON representation back to the JS input type. Synchronous; called during contract loading via `validateContract`. */
|
|
48
|
-
decodeJson(json: JsonValue): TInput;
|
|
49
|
-
/** Produces the TypeScript output type expression for a field given its `typeParams`. Synchronous; used during contract.d.ts emission. */
|
|
50
|
-
renderOutputType?(typeParams: Record<string, unknown>): string | undefined;
|
|
51
|
-
}
|
|
52
|
-
interface CodecLookup {
|
|
53
|
-
get(id: string): Codec | undefined;
|
|
54
|
-
}
|
|
55
|
-
declare const emptyCodecLookup: CodecLookup;
|
|
56
|
-
//#endregion
|
|
57
|
-
export { emptyCodecLookup as i, CodecLookup as n, CodecTrait as r, Codec as t };
|
|
58
|
-
//# sourceMappingURL=codec-types-DQ1Agjom.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codec-types-DQ1Agjom.d.mts","names":[],"sources":["../src/codec-types.ts"],"sourcesContent":[],"mappings":";;;KAEY,UAAA;;AAAZ;AA+BA;;;;;;;;;;;;;;;;;AAwBA;AAIA;;;;;;;;;UA5BiB,2DAEU,wBAAwB;;eAKpC;;;;oBAIK;;gBAEJ,SAAS,QAAQ;;eAElB,QAAQ,QAAQ;;oBAEX,SAAS;;mBAEV,YAAY;;gCAEC;;UAGf,WAAA;mBACE;;cAGN,kBAAkB"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { t as TypesImportSpec } from "./types-import-spec-C4sc7wbb.mjs";
|
|
2
|
-
import { Contract, ContractModel } from "@prisma-next/contract/types";
|
|
3
|
-
|
|
4
|
-
//#region src/emission-types.d.ts
|
|
5
|
-
interface GenerateContractTypesOptions {
|
|
6
|
-
readonly queryOperationTypeImports?: ReadonlyArray<TypesImportSpec>;
|
|
7
|
-
}
|
|
8
|
-
interface ValidationContext {
|
|
9
|
-
readonly codecTypeImports?: ReadonlyArray<TypesImportSpec>;
|
|
10
|
-
readonly operationTypeImports?: ReadonlyArray<TypesImportSpec>;
|
|
11
|
-
readonly extensionIds?: ReadonlyArray<string>;
|
|
12
|
-
}
|
|
13
|
-
interface EmissionSpi {
|
|
14
|
-
readonly id: string;
|
|
15
|
-
generateStorageType(contract: Contract, storageHashTypeName: string): string;
|
|
16
|
-
generateModelStorageType(modelName: string, model: ContractModel): string;
|
|
17
|
-
getFamilyImports(): string[];
|
|
18
|
-
getFamilyTypeAliases(options?: GenerateContractTypesOptions): string;
|
|
19
|
-
getTypeMapsExpression(): string;
|
|
20
|
-
getContractWrapper(contractBaseName: string, typeMapsName: string): string;
|
|
21
|
-
}
|
|
22
|
-
//#endregion
|
|
23
|
-
export { GenerateContractTypesOptions as n, ValidationContext as r, EmissionSpi as t };
|
|
24
|
-
//# sourceMappingURL=emission-types-BPAALJbF.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"emission-types-BPAALJbF.d.mts","names":[],"sources":["../src/emission-types.ts"],"sourcesContent":[],"mappings":";;;;UAGiB,4BAAA;uCACsB,cAAc;AADrD;AAIiB,UAAA,iBAAA,CAAiB;EACU,SAAA,gBAAA,CAAA,EAAd,aAAc,CAAA,eAAA,CAAA;EAAd,SAAA,oBAAA,CAAA,EACI,aADJ,CACkB,eADlB,CAAA;EACkB,SAAA,YAAA,CAAA,EACtB,aADsB,CAAA,MAAA,CAAA;;AACtB,UAGT,WAAA,CAHS;EAAa,SAAA,EAAA,EAAA,MAAA;EAGtB,mBAAW,CAAA,QAAA,EAGI,QAHJ,EAAA,mBAAA,EAAA,MAAA,CAAA,EAAA,MAAA;EAGI,wBAAA,CAAA,SAAA,EAAA,MAAA,EAAA,KAAA,EAEqB,aAFrB,CAAA,EAAA,MAAA;EAEqB,gBAAA,EAAA,EAAA,MAAA,EAAA;EAIpB,oBAAA,CAAA,OAAA,CAAA,EAAA,4BAAA,CAAA,EAAA,MAAA;EAA4B,qBAAA,EAAA,EAAA,MAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"framework-authoring-D1-JZ37B.d.mts","names":[],"sources":["../src/framework-authoring.ts"],"sourcesContent":[],"mappings":";KAEY,eAAA;EAAA,SAAA,IAAA,EAAA,KAAe;EAOf,SAAA,KAAA,EAAA,MAAA;EAKR,SAAA,IAAA,CAAA,EAAA,SAAA,MAAA,EAAA;EACS,SAAA,OAAA,CAAA,EATQ,sBASR;CACiB;AAAsB,KAPxC,sBAAA,GAOwC,MAAA,GAAA,MAAA,GAAA,OAAA,GAAA,IAAA,GAFhD,eAEgD,GAAA,SADvC,sBACuC,EAAA,GAAA;EAE1C,UAAA,GAAA,EAAA,MAAA,CAAA,EAFoB,sBAEa;AAK3C,CAAA;UALU,iCAAA,CAKgC;EAYE,SAAA,IAAA,CAAA,EAAA,MAA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