@prisma-next/framework-components 0.5.0-dev.6 → 0.5.0-dev.61
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 +63 -3
- package/dist/authoring.d.mts +2 -2
- package/dist/authoring.mjs +2 -121
- package/dist/codec-BUBJeOk4.d.mts +168 -0
- package/dist/codec-BUBJeOk4.d.mts.map +1 -0
- package/dist/codec.d.mts +49 -2
- package/dist/codec.d.mts.map +1 -0
- package/dist/codec.mjs +68 -3
- package/dist/codec.mjs.map +1 -1
- package/dist/components.d.mts +3 -1
- package/dist/components.mjs +1 -1
- package/dist/control.d.mts +110 -71
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +47 -45
- package/dist/control.mjs.map +1 -1
- package/dist/emission-types-DzNgwiFC.d.mts +39 -0
- package/dist/emission-types-DzNgwiFC.d.mts.map +1 -0
- package/dist/emission.d.mts +2 -2
- package/dist/execution.d.mts +7 -5
- package/dist/execution.d.mts.map +1 -1
- package/dist/execution.mjs +3 -3
- package/dist/execution.mjs.map +1 -1
- package/dist/{framework-authoring-D1-JZ37B.d.mts → framework-authoring-DJbiXhmf.d.mts} +41 -12
- package/dist/framework-authoring-DJbiXhmf.d.mts.map +1 -0
- package/dist/framework-authoring-gi_BJlNO.mjs +206 -0
- package/dist/framework-authoring-gi_BJlNO.mjs.map +1 -0
- package/dist/{framework-components-EJXe-pum.d.mts → framework-components-BVqm1I48.d.mts} +45 -55
- package/dist/framework-components-BVqm1I48.d.mts.map +1 -0
- package/dist/{framework-components-C8ZhSwXe.mjs → framework-components-BsWST1Rn.mjs} +2 -2
- package/dist/framework-components-BsWST1Rn.mjs.map +1 -0
- package/dist/psl-ast-BlDveJZ4.d.mts +159 -0
- package/dist/psl-ast-BlDveJZ4.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 +346 -19
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +256 -4
- package/dist/runtime.mjs.map +1 -1
- package/dist/{types-import-spec-C4sc7wbb.d.mts → types-import-spec-CPhrNJIV.d.mts} +2 -2
- package/dist/types-import-spec-CPhrNJIV.d.mts.map +1 -0
- package/package.json +7 -4
- package/src/control/control-capabilities.ts +71 -0
- package/src/{control-descriptors.ts → control/control-descriptors.ts} +7 -7
- package/src/{control-instances.ts → control/control-instances.ts} +6 -6
- package/src/{control-migration-types.ts → control/control-migration-types.ts} +57 -60
- package/src/control/control-operation-preview.ts +23 -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 +85 -0
- package/src/execution/run-with-middleware.ts +132 -0
- package/src/execution/runtime-core.ts +133 -0
- package/src/execution/runtime-error.ts +83 -0
- package/src/execution/runtime-middleware.ts +182 -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 +26 -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 +17 -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} +202 -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-B58nCJiu.d.mts +0 -40
- package/dist/codec-types-B58nCJiu.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-EJXe-pum.d.mts.map +0 -1
- package/dist/types-import-spec-C4sc7wbb.d.mts.map +0 -1
- package/src/codec-types.ts +0 -46
- package/src/control-capabilities.ts +0 -34
- package/src/emission-types.ts +0 -28
- package/src/runtime-error.ts +0 -39
- 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
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `column()` packager + `ColumnSpec<R, P>` shape + `ColumnHelperFor<D>` variants for tying per-codec column helpers to their descriptor.
|
|
3
|
+
*
|
|
4
|
+
* `ColumnSpec<R, P>` extends {@link ColumnTypeDescriptor} so it remains a drop-in for contract authoring sites that consume `ColumnTypeDescriptor` shapes — both types live at the framework-components layer so the `extends` clause is real (no structural mirror).
|
|
5
|
+
*
|
|
6
|
+
* `column()` is a trivial, non-polymorphic packager. Generic over `R` (the codec instance type returned by the descriptor's curried factory) and `P` (the typeParams record). The framework does NOT try to infer `R` and `P` from a descriptor — that path is the variance trap. Per-codec helpers absorb the descriptor relationship instead and tie themselves to their descriptor via `satisfies ColumnHelperFor<D>` or `satisfies ColumnHelperForStrict<D>`.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { CodecDescriptor } from './codec-descriptor';
|
|
10
|
+
import type { CodecInstanceContext } from './codec-types';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Authored column-type descriptor — the data shape an authoring site (PSL or TypeScript builders) attaches to a column to identify its codec and its native database type.
|
|
14
|
+
*
|
|
15
|
+
* Lives at the framework-components layer alongside the codec types so codec-author packages (e.g. column-spec / `column()` packagers) can extend it directly without crossing layer boundaries.
|
|
16
|
+
*
|
|
17
|
+
* @template TCodecId Narrowed codec id literal for sites that thread a specific codec id through the type system.
|
|
18
|
+
*/
|
|
19
|
+
export type ColumnTypeDescriptor<TCodecId extends string = string> = {
|
|
20
|
+
readonly codecId: TCodecId;
|
|
21
|
+
readonly nativeType: string;
|
|
22
|
+
readonly typeParams?: Record<string, unknown> | undefined;
|
|
23
|
+
readonly typeRef?: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Column spec carrying the codec factory closure alongside the {@link ColumnTypeDescriptor} fields. Codec authors return a `ColumnSpec` from per-codec column helpers; the runtime materializes the codec instance by calling `codecFactory(ctx)` once it knows the column's `CodecInstanceContext`.
|
|
28
|
+
*
|
|
29
|
+
* Extends {@link ColumnTypeDescriptor} so `ColumnSpec` instances flow directly into contract-authoring sites that consume the descriptor shape — no structural mirroring required.
|
|
30
|
+
*/
|
|
31
|
+
export interface ColumnSpec<R, P extends Record<string, unknown> | undefined>
|
|
32
|
+
extends ColumnTypeDescriptor {
|
|
33
|
+
readonly codecFactory: (ctx: CodecInstanceContext) => R;
|
|
34
|
+
readonly typeParams: P;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Trivial column packager. Per-codec helpers call this directly with the result of `descriptor.factory(params)` — direct method invocation binds the descriptor's method-level generic at the call site and the literal flows through `R`.
|
|
39
|
+
*
|
|
40
|
+
* `nativeType` is the column's database-native type spelling — the value the postgres adapter's migration planner, the SQL renderer's cast policy, and the contract's `meta.db.<family>.<target>.nativeType` slot read. Per-codec helpers pass the literal native-type string for their codec (e.g. `'text'`, `'int4'`, `'character varying'`); for codecs whose native-type spelling depends on parameters (none today; reserved for future shapes), the helper computes the rendered string before calling `column`. The framework does not derive the value from `codecId` — that mapping is target-specific and lives at the helper.
|
|
41
|
+
*/
|
|
42
|
+
export function column<R, P extends Record<string, unknown> | undefined>(
|
|
43
|
+
codecFactory: (ctx: CodecInstanceContext) => R,
|
|
44
|
+
codecId: string,
|
|
45
|
+
typeParams: P,
|
|
46
|
+
nativeType: string,
|
|
47
|
+
): ColumnSpec<R, P> {
|
|
48
|
+
return {
|
|
49
|
+
codecFactory,
|
|
50
|
+
codecId,
|
|
51
|
+
typeParams,
|
|
52
|
+
nativeType,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Coarse `satisfies` shape — checks the helper's typeParams record matches the descriptor's factory params. Catches "wrong typeParams shape" wiring mistakes; does NOT catch "wrong descriptor's factory" mistakes (the codec slot is left as `unknown`).
|
|
58
|
+
*
|
|
59
|
+
* Use when the codec's `ReturnType<factory>` is unstable (e.g. heavily overloaded factories where extraction widens too much).
|
|
60
|
+
*/
|
|
61
|
+
// biome-ignore lint/suspicious/noExplicitAny: variance erasure — `CodecDescriptor<P>` is invariant in P, so concrete subclasses do not extend `CodecDescriptor<unknown>`; matches the existing `AnyCodecDescriptor` pattern
|
|
62
|
+
export type ColumnHelperFor<D extends CodecDescriptor<any>> = (
|
|
63
|
+
// biome-ignore lint/suspicious/noExplicitAny: helper signature is the verification subject; satisfies clauses can't narrow this without circular inference
|
|
64
|
+
...args: any[]
|
|
65
|
+
) => ColumnSpec<unknown, ColumnHelperParams<D>>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Strict `satisfies` shape — also checks the helper's codec is at least the *base* codec instance type the descriptor's factory returns. `ReturnType<ReturnType<D['factory']>>` widens method generics to their constraint, so this only sanity-checks the wiring at the base type level. Literal preservation comes from the direct `descriptor.factory(...)` call inside the helper, not from `satisfies`.
|
|
69
|
+
*/
|
|
70
|
+
// biome-ignore lint/suspicious/noExplicitAny: variance erasure — `CodecDescriptor<P>` is invariant in P, so concrete subclasses do not extend `CodecDescriptor<unknown>`; matches the existing `AnyCodecDescriptor` pattern
|
|
71
|
+
export type ColumnHelperForStrict<D extends CodecDescriptor<any>> = (
|
|
72
|
+
// biome-ignore lint/suspicious/noExplicitAny: helper signature is the verification subject; satisfies clauses can't narrow this without circular inference
|
|
73
|
+
...args: any[]
|
|
74
|
+
) => ColumnSpec<ReturnType<ReturnType<D['factory']>>, ColumnHelperParams<D>>;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Coerce a descriptor's `factory` first parameter into the typeParams shape `ColumnSpec` accepts. Non-parameterized descriptors (factory with no params, or `params: void`) collapse to `undefined`; parameterized descriptors keep the params record shape.
|
|
78
|
+
*/
|
|
79
|
+
// biome-ignore lint/suspicious/noExplicitAny: variance erasure — see above
|
|
80
|
+
type ColumnHelperParams<D extends CodecDescriptor<any>> =
|
|
81
|
+
Parameters<D['factory']>[0] extends Record<string, unknown>
|
|
82
|
+
? Parameters<D['factory']>[0]
|
|
83
|
+
: undefined;
|
|
@@ -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 = {
|
|
@@ -63,10 +72,15 @@ export type AuthoringColumnDefaultTemplate =
|
|
|
63
72
|
| AuthoringColumnDefaultTemplateLiteral
|
|
64
73
|
| AuthoringColumnDefaultTemplateFunction;
|
|
65
74
|
|
|
75
|
+
export interface AuthoringExecutionDefaultsTemplate {
|
|
76
|
+
readonly onCreate?: AuthoringTemplateValue;
|
|
77
|
+
readonly onUpdate?: AuthoringTemplateValue;
|
|
78
|
+
}
|
|
79
|
+
|
|
66
80
|
export interface AuthoringFieldPresetOutput extends AuthoringStorageTypeTemplate {
|
|
67
81
|
readonly nullable?: boolean;
|
|
68
82
|
readonly default?: AuthoringColumnDefaultTemplate;
|
|
69
|
-
readonly
|
|
83
|
+
readonly executionDefaults?: AuthoringExecutionDefaultsTemplate;
|
|
70
84
|
readonly id?: boolean;
|
|
71
85
|
readonly unique?: boolean;
|
|
72
86
|
}
|
|
@@ -132,6 +146,148 @@ export function isAuthoringFieldPresetDescriptor(
|
|
|
132
146
|
);
|
|
133
147
|
}
|
|
134
148
|
|
|
149
|
+
/**
|
|
150
|
+
* Returns true when `namespace` is a non-leaf key in `contributions.field`.
|
|
151
|
+
*
|
|
152
|
+
* `AuthoringFieldNamespace` permits a leaf descriptor at any depth — including
|
|
153
|
+
* the root — so a top-level `field: { Foo: { kind: 'fieldPreset', ... } }`
|
|
154
|
+
* registration must NOT be treated as a "namespace" with sub-paths. Callers
|
|
155
|
+
* use this predicate to gate dot-namespaced lookups (e.g. PSL `@Foo.bar`).
|
|
156
|
+
*/
|
|
157
|
+
export function hasRegisteredFieldNamespace(
|
|
158
|
+
contributions: AuthoringContributions | undefined,
|
|
159
|
+
namespace: string,
|
|
160
|
+
): boolean {
|
|
161
|
+
if (contributions?.field === undefined || !Object.hasOwn(contributions.field, namespace)) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
return !isAuthoringFieldPresetDescriptor(contributions.field[namespace]);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function isPlainNamespaceObject(value: unknown): value is Record<string, unknown> {
|
|
168
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Merges `source` into `target` recursively at the descriptor-namespace
|
|
173
|
+
* level. `leafGuard` decides which values are descriptors (terminal
|
|
174
|
+
* merge points; same-path registrations across components are reported
|
|
175
|
+
* as duplicates) versus sub-namespaces (recursion targets).
|
|
176
|
+
*
|
|
177
|
+
* Path segments are validated against prototype-pollution names
|
|
178
|
+
* (`__proto__`, `constructor`, `prototype`). A value that is neither a
|
|
179
|
+
* recognized leaf nor a plain object — e.g. a malformed descriptor
|
|
180
|
+
* where the canonical leaf guard rejected it for missing `output` —
|
|
181
|
+
* is reported as an invalid contribution rather than recursed into,
|
|
182
|
+
* which would either silently mangle state or infinite-loop on
|
|
183
|
+
* primitive properties.
|
|
184
|
+
*
|
|
185
|
+
* Within-registry duplicate detection is this walker's job;
|
|
186
|
+
* cross-registry detection runs separately via
|
|
187
|
+
* `assertNoCrossRegistryCollisions` after merging completes.
|
|
188
|
+
*/
|
|
189
|
+
export function mergeAuthoringNamespaces(
|
|
190
|
+
target: Record<string, unknown>,
|
|
191
|
+
source: Record<string, unknown>,
|
|
192
|
+
path: readonly string[],
|
|
193
|
+
leafGuard: (value: unknown) => boolean,
|
|
194
|
+
label: string,
|
|
195
|
+
): void {
|
|
196
|
+
const assertSafePath = (currentPath: readonly string[]) => {
|
|
197
|
+
const blockedSegment = currentPath.find(
|
|
198
|
+
(segment) => segment === '__proto__' || segment === 'constructor' || segment === 'prototype',
|
|
199
|
+
);
|
|
200
|
+
if (blockedSegment) {
|
|
201
|
+
throw new Error(
|
|
202
|
+
`Invalid authoring ${label} helper "${currentPath.join('.')}". Helper path segments must not use "${blockedSegment}".`,
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
for (const [key, sourceValue] of Object.entries(source)) {
|
|
208
|
+
const currentPath = [...path, key];
|
|
209
|
+
assertSafePath(currentPath);
|
|
210
|
+
const hasExistingValue = Object.hasOwn(target, key);
|
|
211
|
+
const existingValue = hasExistingValue ? target[key] : undefined;
|
|
212
|
+
|
|
213
|
+
if (!hasExistingValue) {
|
|
214
|
+
target[key] = sourceValue;
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const existingIsLeaf = leafGuard(existingValue);
|
|
219
|
+
const sourceIsLeaf = leafGuard(sourceValue);
|
|
220
|
+
|
|
221
|
+
if (existingIsLeaf || sourceIsLeaf) {
|
|
222
|
+
throw new Error(
|
|
223
|
+
`Duplicate authoring ${label} helper "${currentPath.join('.')}". Helper names must be unique across composed packs.`,
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (!isPlainNamespaceObject(existingValue) || !isPlainNamespaceObject(sourceValue)) {
|
|
228
|
+
throw new Error(
|
|
229
|
+
`Invalid authoring ${label} helper "${currentPath.join('.')}". Expected a sub-namespace object or a recognized descriptor; received a malformed value.`,
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
mergeAuthoringNamespaces(existingValue, sourceValue, currentPath, leafGuard, label);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function collectAuthoringLeafPaths(
|
|
238
|
+
namespace: Readonly<Record<string, unknown>>,
|
|
239
|
+
isLeaf: (value: unknown) => boolean,
|
|
240
|
+
path: readonly string[] = [],
|
|
241
|
+
): string[] {
|
|
242
|
+
const paths: string[] = [];
|
|
243
|
+
for (const [key, value] of Object.entries(namespace)) {
|
|
244
|
+
const currentPath = [...path, key];
|
|
245
|
+
if (isLeaf(value)) {
|
|
246
|
+
paths.push(currentPath.join('.'));
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
250
|
+
paths.push(
|
|
251
|
+
...collectAuthoringLeafPaths(
|
|
252
|
+
value as Readonly<Record<string, unknown>>,
|
|
253
|
+
isLeaf,
|
|
254
|
+
currentPath,
|
|
255
|
+
),
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return paths;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export function assertNoCrossRegistryCollisions(
|
|
263
|
+
typeNamespace: AuthoringTypeNamespace,
|
|
264
|
+
fieldNamespace: AuthoringFieldNamespace,
|
|
265
|
+
): void {
|
|
266
|
+
const typePaths = new Set(
|
|
267
|
+
collectAuthoringLeafPaths(typeNamespace, isAuthoringTypeConstructorDescriptor),
|
|
268
|
+
);
|
|
269
|
+
// Within-registry duplicate detection is handled upstream by the merge
|
|
270
|
+
// walker (`mergeAuthoringNamespaces` in control-stack.ts and
|
|
271
|
+
// `mergeHelperNamespaces` in composed-authoring-helpers.ts), which throws
|
|
272
|
+
// on same-path registrations within either registry before this check
|
|
273
|
+
// runs. This function only handles the cross-registry case — and an
|
|
274
|
+
// empty type namespace makes a cross-registry collision structurally
|
|
275
|
+
// impossible, so the early-out is sound.
|
|
276
|
+
if (typePaths.size === 0) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
for (const fieldPath of collectAuthoringLeafPaths(
|
|
280
|
+
fieldNamespace,
|
|
281
|
+
isAuthoringFieldPresetDescriptor,
|
|
282
|
+
)) {
|
|
283
|
+
if (typePaths.has(fieldPath)) {
|
|
284
|
+
throw new Error(
|
|
285
|
+
`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.`,
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
135
291
|
export function resolveAuthoringTemplateValue(
|
|
136
292
|
template: AuthoringTemplateValue,
|
|
137
293
|
args: readonly unknown[],
|
|
@@ -295,20 +451,17 @@ function resolveAuthoringStorageTypeTemplate(
|
|
|
295
451
|
function resolveAuthoringColumnDefaultTemplate(
|
|
296
452
|
template: AuthoringColumnDefaultTemplate,
|
|
297
453
|
args: readonly unknown[],
|
|
298
|
-
):
|
|
299
|
-
| {
|
|
300
|
-
readonly kind: 'literal';
|
|
301
|
-
readonly value: unknown;
|
|
302
|
-
}
|
|
303
|
-
| {
|
|
304
|
-
readonly kind: 'function';
|
|
305
|
-
readonly expression: string;
|
|
306
|
-
} {
|
|
454
|
+
): ColumnDefault {
|
|
307
455
|
if (template.kind === 'literal') {
|
|
308
456
|
const value = resolveAuthoringTemplateValue(template.value, args);
|
|
309
457
|
if (value === undefined) {
|
|
310
458
|
throw new Error('Resolved authoring literal default must not be undefined');
|
|
311
459
|
}
|
|
460
|
+
if (!isColumnDefaultLiteralInputValue(value)) {
|
|
461
|
+
throw new Error(
|
|
462
|
+
`Resolved authoring literal default must be a JSON-serializable value or Date, received ${String(value)}`,
|
|
463
|
+
);
|
|
464
|
+
}
|
|
312
465
|
return {
|
|
313
466
|
kind: 'literal',
|
|
314
467
|
value,
|
|
@@ -327,6 +480,40 @@ function resolveAuthoringColumnDefaultTemplate(
|
|
|
327
480
|
};
|
|
328
481
|
}
|
|
329
482
|
|
|
483
|
+
function resolveExecutionMutationDefaultPhase(
|
|
484
|
+
phase: 'onCreate' | 'onUpdate',
|
|
485
|
+
template: AuthoringTemplateValue,
|
|
486
|
+
args: readonly unknown[],
|
|
487
|
+
): ExecutionMutationDefaultValue {
|
|
488
|
+
const value = resolveAuthoringTemplateValue(template, args);
|
|
489
|
+
if (!isExecutionMutationDefaultValue(value)) {
|
|
490
|
+
throw new Error(
|
|
491
|
+
`Authoring preset executionDefaults.${phase} did not resolve to a valid generator descriptor (kind: 'generator', id: string).`,
|
|
492
|
+
);
|
|
493
|
+
}
|
|
494
|
+
return value;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
function resolveAuthoringExecutionDefaultsTemplate(
|
|
498
|
+
template: AuthoringExecutionDefaultsTemplate,
|
|
499
|
+
args: readonly unknown[],
|
|
500
|
+
): ExecutionMutationDefaultPhases {
|
|
501
|
+
return {
|
|
502
|
+
...ifDefined(
|
|
503
|
+
'onCreate',
|
|
504
|
+
template.onCreate !== undefined
|
|
505
|
+
? resolveExecutionMutationDefaultPhase('onCreate', template.onCreate, args)
|
|
506
|
+
: undefined,
|
|
507
|
+
),
|
|
508
|
+
...ifDefined(
|
|
509
|
+
'onUpdate',
|
|
510
|
+
template.onUpdate !== undefined
|
|
511
|
+
? resolveExecutionMutationDefaultPhase('onUpdate', template.onUpdate, args)
|
|
512
|
+
: undefined,
|
|
513
|
+
),
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
|
|
330
517
|
export function instantiateAuthoringTypeConstructor(
|
|
331
518
|
descriptor: AuthoringTypeConstructorDescriptor,
|
|
332
519
|
args: readonly unknown[],
|
|
@@ -348,16 +535,8 @@ export function instantiateAuthoringFieldPreset(
|
|
|
348
535
|
readonly typeParams?: Record<string, unknown>;
|
|
349
536
|
};
|
|
350
537
|
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;
|
|
538
|
+
readonly default?: ColumnDefault;
|
|
539
|
+
readonly executionDefaults?: ExecutionMutationDefaultPhases;
|
|
361
540
|
readonly id: boolean;
|
|
362
541
|
readonly unique: boolean;
|
|
363
542
|
} {
|
|
@@ -371,9 +550,9 @@ export function instantiateAuthoringFieldPreset(
|
|
|
371
550
|
: undefined,
|
|
372
551
|
),
|
|
373
552
|
...ifDefined(
|
|
374
|
-
'
|
|
375
|
-
descriptor.output.
|
|
376
|
-
?
|
|
553
|
+
'executionDefaults',
|
|
554
|
+
descriptor.output.executionDefaults !== undefined
|
|
555
|
+
? resolveAuthoringExecutionDefaultsTemplate(descriptor.output.executionDefaults, args)
|
|
377
556
|
: undefined,
|
|
378
557
|
),
|
|
379
558
|
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,29 +21,25 @@ 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
44
|
readonly operationTypes?: { readonly import: TypesImportSpec };
|
|
52
45
|
readonly queryOperationTypes?: { readonly import: TypesImportSpec };
|
|
@@ -61,21 +54,17 @@ export interface ComponentMetadata {
|
|
|
61
54
|
/**
|
|
62
55
|
* Optional pure-data authoring contributions exposed by this component.
|
|
63
56
|
*
|
|
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.
|
|
57
|
+
* 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
58
|
*/
|
|
68
59
|
readonly authoring?: AuthoringContributions;
|
|
69
60
|
|
|
70
61
|
/**
|
|
71
|
-
* Scalar type name to codec ID mapping contributed by this component.
|
|
72
|
-
* Assembled by `createControlStack` with duplicate detection.
|
|
62
|
+
* Scalar type name to codec ID mapping contributed by this component. Assembled by `createControlStack` with duplicate detection.
|
|
73
63
|
*/
|
|
74
64
|
readonly scalarTypeDescriptors?: ReadonlyMap<string, string>;
|
|
75
65
|
|
|
76
66
|
/**
|
|
77
|
-
* Mutation default function handlers and generator descriptors contributed
|
|
78
|
-
* by this component. Assembled by `createControlStack` with duplicate detection.
|
|
67
|
+
* Mutation default function handlers and generator descriptors contributed by this component. Assembled by `createControlStack` with duplicate detection.
|
|
79
68
|
*/
|
|
80
69
|
readonly controlMutationDefaults?: ControlMutationDefaults;
|
|
81
70
|
}
|
|
@@ -83,13 +72,9 @@ export interface ComponentMetadata {
|
|
|
83
72
|
/**
|
|
84
73
|
* Base descriptor for any framework component.
|
|
85
74
|
*
|
|
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.).
|
|
75
|
+
* 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
76
|
*
|
|
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.
|
|
77
|
+
* @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
78
|
*
|
|
94
79
|
* @example
|
|
95
80
|
* ```ts
|
|
@@ -163,14 +148,12 @@ export function checkContractComponentRequirements(
|
|
|
163
148
|
/**
|
|
164
149
|
* Descriptor for a family component.
|
|
165
150
|
*
|
|
166
|
-
* A "family" represents a category of data sources with shared semantics
|
|
167
|
-
* (e.g., SQL databases, document stores). Families define:
|
|
151
|
+
* A "family" represents a category of data sources with shared semantics (e.g., SQL databases, document stores). Families define:
|
|
168
152
|
* - Query semantics and operations (SELECT, INSERT, find, aggregate, etc.)
|
|
169
153
|
* - Contract structure (tables vs collections, columns vs fields)
|
|
170
154
|
* - Type system and codecs
|
|
171
155
|
*
|
|
172
|
-
* Families are the top-level grouping. Each family contains multiple targets
|
|
173
|
-
* (e.g., SQL family contains Postgres, MySQL, SQLite targets).
|
|
156
|
+
* Families are the top-level grouping. Each family contains multiple targets (e.g., SQL family contains Postgres, MySQL, SQLite targets).
|
|
174
157
|
*
|
|
175
158
|
* Extended by plane-specific descriptors:
|
|
176
159
|
* - `ControlFamilyDescriptor` - adds `emission` for CLI/tooling operations
|
|
@@ -195,13 +178,11 @@ export interface FamilyDescriptor<TFamilyId extends string> extends ComponentDes
|
|
|
195
178
|
/**
|
|
196
179
|
* Descriptor for a target component.
|
|
197
180
|
*
|
|
198
|
-
* A "target" represents a specific database or data store within a family
|
|
199
|
-
* (e.g., Postgres, MySQL, MongoDB). Targets define:
|
|
181
|
+
* A "target" represents a specific database or data store within a family (e.g., Postgres, MySQL, MongoDB). Targets define:
|
|
200
182
|
* - Native type mappings (e.g., Postgres int4 → TypeScript number)
|
|
201
183
|
* - Target-specific capabilities (e.g., RETURNING, LATERAL joins)
|
|
202
184
|
*
|
|
203
|
-
* Targets are bound to a family and provide the target-specific implementation
|
|
204
|
-
* details that adapters and drivers use.
|
|
185
|
+
* Targets are bound to a family and provide the target-specific implementation details that adapters and drivers use.
|
|
205
186
|
*
|
|
206
187
|
* Extended by plane-specific descriptors:
|
|
207
188
|
* - `ControlTargetDescriptor` - adds optional `migrations` capability
|
|
@@ -229,8 +210,7 @@ export interface TargetDescriptor<TFamilyId extends string, TTargetId extends st
|
|
|
229
210
|
}
|
|
230
211
|
|
|
231
212
|
/**
|
|
232
|
-
* Base shape for any pack reference.
|
|
233
|
-
* Pack refs are pure JSON-friendly objects safe to import in authoring flows.
|
|
213
|
+
* Base shape for any pack reference. Pack refs are pure JSON-friendly objects safe to import in authoring flows.
|
|
234
214
|
*/
|
|
235
215
|
export interface PackRefBase<Kind extends string, TFamilyId extends string>
|
|
236
216
|
extends ComponentMetadata {
|
|
@@ -274,14 +254,12 @@ export type DriverPackRef<
|
|
|
274
254
|
/**
|
|
275
255
|
* Descriptor for an adapter component.
|
|
276
256
|
*
|
|
277
|
-
* An "adapter" provides the protocol and dialect implementation for a target.
|
|
278
|
-
* Adapters handle:
|
|
257
|
+
* An "adapter" provides the protocol and dialect implementation for a target. Adapters handle:
|
|
279
258
|
* - SQL/query generation (lowering AST to target-specific syntax)
|
|
280
259
|
* - Codec registration (encoding/decoding between JS and wire types)
|
|
281
260
|
* - Type mappings and coercions
|
|
282
261
|
*
|
|
283
|
-
* Adapters are bound to a specific family+target combination and work with
|
|
284
|
-
* any compatible driver for that target.
|
|
262
|
+
* Adapters are bound to a specific family+target combination and work with any compatible driver for that target.
|
|
285
263
|
*
|
|
286
264
|
* Extended by plane-specific descriptors:
|
|
287
265
|
* - `ControlAdapterDescriptor` - control-plane factory
|
|
@@ -311,16 +289,13 @@ export interface AdapterDescriptor<TFamilyId extends string, TTargetId extends s
|
|
|
311
289
|
/**
|
|
312
290
|
* Descriptor for a driver component.
|
|
313
291
|
*
|
|
314
|
-
* A "driver" provides the connection and execution layer for a target.
|
|
315
|
-
* Drivers handle:
|
|
292
|
+
* A "driver" provides the connection and execution layer for a target. Drivers handle:
|
|
316
293
|
* - Connection management (pooling, timeouts, retries)
|
|
317
294
|
* - Query execution (sending SQL/commands, receiving results)
|
|
318
295
|
* - Transaction management
|
|
319
296
|
* - Wire protocol communication
|
|
320
297
|
*
|
|
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).
|
|
298
|
+
* 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
299
|
*
|
|
325
300
|
* Extended by plane-specific descriptors:
|
|
326
301
|
* - `ControlDriverDescriptor` - creates driver from connection URL
|
|
@@ -355,8 +330,7 @@ export interface DriverDescriptor<TFamilyId extends string, TTargetId extends st
|
|
|
355
330
|
* - Custom types and codecs (e.g., vector type)
|
|
356
331
|
* - Extended query capabilities
|
|
357
332
|
*
|
|
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.
|
|
333
|
+
* 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
334
|
*
|
|
361
335
|
* Extended by plane-specific descriptors:
|
|
362
336
|
* - `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":"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"}
|
|
@@ -1,40 +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
|
-
* Base codec interface for all target families.
|
|
7
|
-
*
|
|
8
|
-
* A codec maps between three representations of a value:
|
|
9
|
-
* - **JS** (`TJs`): the JavaScript type used in application code
|
|
10
|
-
* - **Wire** (`TWire`): the format sent to/from the database driver
|
|
11
|
-
* - **JSON** (`JsonValue`): the JSON-safe form stored in contract artifacts
|
|
12
|
-
*
|
|
13
|
-
* Family-specific codec interfaces (SQL `Codec`, Mongo `MongoCodec`) extend
|
|
14
|
-
* this base to add family-specific metadata.
|
|
15
|
-
*/
|
|
16
|
-
interface Codec<Id extends string = string, TTraits extends readonly CodecTrait[] = readonly CodecTrait[], TWire = unknown, TJs = unknown> {
|
|
17
|
-
/** Unique codec identifier in `namespace/name@version` format (e.g. `pg/timestamptz@1`). */
|
|
18
|
-
readonly id: Id;
|
|
19
|
-
/** Database-native type names this codec handles (e.g. `['timestamptz']`). */
|
|
20
|
-
readonly targetTypes: readonly string[];
|
|
21
|
-
/** Semantic traits for operator gating (e.g. equality, order, numeric). */
|
|
22
|
-
readonly traits?: TTraits;
|
|
23
|
-
/** Converts a JS value to the wire format expected by the database driver. Optional when the driver accepts the JS type directly. */
|
|
24
|
-
encode?(value: TJs): TWire;
|
|
25
|
-
/** Converts a wire value from the database driver into the JS type. */
|
|
26
|
-
decode(wire: TWire): TJs;
|
|
27
|
-
/** Converts a JS value to a JSON-safe representation for contract serialization. Called during contract emission. */
|
|
28
|
-
encodeJson(value: TJs): JsonValue;
|
|
29
|
-
/** Converts a JSON representation back to the JS type. Called during contract loading via `validateContract`. */
|
|
30
|
-
decodeJson(json: JsonValue): TJs;
|
|
31
|
-
/** Produces the TypeScript output type expression for a field given its `typeParams`. Used during contract.d.ts emission. */
|
|
32
|
-
renderOutputType?(typeParams: Record<string, unknown>): string | undefined;
|
|
33
|
-
}
|
|
34
|
-
interface CodecLookup {
|
|
35
|
-
get(id: string): Codec | undefined;
|
|
36
|
-
}
|
|
37
|
-
declare const emptyCodecLookup: CodecLookup;
|
|
38
|
-
//#endregion
|
|
39
|
-
export { emptyCodecLookup as i, CodecLookup as n, CodecTrait as r, Codec as t };
|
|
40
|
-
//# sourceMappingURL=codec-types-B58nCJiu.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codec-types-B58nCJiu.d.mts","names":[],"sources":["../src/codec-types.ts"],"sourcesContent":[],"mappings":";;;KAEY,UAAA;;AAAZ;AAaA;;;;;;;;;AAiBoB,UAjBH,KAiBG,CAAA,WAAA,MAAA,GAAA,MAAA,EAAA,gBAAA,SAfO,UAeP,EAAA,GAAA,SAf+B,UAe/B,EAAA,EAAA,QAAA,OAAA,EAAA,MAAA,OAAA,CAAA,CAAA;EAAM;EAEP,SAAA,EAAA,EAZJ,EAYI;EAAY;EAEC,SAAA,WAAA,EAAA,SAAA,MAAA,EAAA;EAAM;EAGrB,SAAA,MAAW,CAAA,EAbR,OAcD;EAGN;iBAfI,MAAM;;eAER,QAAQ;;oBAEH,MAAM;;mBAEP,YAAY;;gCAEC;;UAGf,WAAA;mBACE;;cAGN,kBAAkB"}
|