@prisma-next/framework-components 0.5.0-dev.6 → 0.5.0-dev.60
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 +61 -0
- package/dist/authoring.d.mts +2 -2
- package/dist/authoring.mjs +2 -121
- package/dist/codec-types-MWvfFmu1.d.mts +207 -0
- package/dist/codec-types-MWvfFmu1.d.mts.map +1 -0
- package/dist/codec.d.mts +2 -2
- package/dist/codec.mjs +38 -2
- 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 +109 -70
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +20 -35
- 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-C8ZhSwXe.mjs → framework-components-BsWST1Rn.mjs} +2 -2
- package/dist/framework-components-BsWST1Rn.mjs.map +1 -0
- package/dist/{framework-components-EJXe-pum.d.mts → framework-components-BvzjH6Pt.d.mts} +24 -8
- package/dist/framework-components-BvzjH6Pt.d.mts.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 +9 -6
- 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} +27 -83
- 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 +14 -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-types.ts +261 -0
- package/src/{framework-authoring.ts → shared/framework-authoring.ts} +202 -23
- 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/{framework-components.ts → shared/framework-components.ts} +0 -0
- /package/src/{types-import-spec.ts → shared/types-import-spec.ts} +0 -0
package/src/exports/codec.ts
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
export type {
|
|
2
|
-
|
|
1
|
+
export type {
|
|
2
|
+
Codec,
|
|
3
|
+
CodecCallContext,
|
|
4
|
+
CodecDescriptor,
|
|
5
|
+
CodecInstanceContext,
|
|
6
|
+
CodecLookup,
|
|
7
|
+
CodecMeta,
|
|
8
|
+
CodecTrait,
|
|
9
|
+
} from '../shared/codec-types';
|
|
10
|
+
export {
|
|
11
|
+
emptyCodecLookup,
|
|
12
|
+
synthesizeNonParameterizedDescriptor,
|
|
13
|
+
voidParamsSchema,
|
|
14
|
+
} from '../shared/codec-types';
|
|
@@ -20,5 +20,5 @@ export type {
|
|
|
20
20
|
TargetDescriptor,
|
|
21
21
|
TargetInstance,
|
|
22
22
|
TargetPackRef,
|
|
23
|
-
} from '../framework-components';
|
|
24
|
-
export { checkContractComponentRequirements } from '../framework-components';
|
|
23
|
+
} from '../shared/framework-components';
|
|
24
|
+
export { checkContractComponentRequirements } from '../shared/framework-components';
|
package/src/exports/control.ts
CHANGED
|
@@ -1,21 +1,30 @@
|
|
|
1
|
-
export type {
|
|
2
|
-
|
|
1
|
+
export type {
|
|
2
|
+
MigratableTargetDescriptor,
|
|
3
|
+
OperationPreviewCapable,
|
|
4
|
+
PslContractInferCapable,
|
|
5
|
+
SchemaViewCapable,
|
|
6
|
+
} from '../control/control-capabilities';
|
|
7
|
+
export {
|
|
8
|
+
hasMigrations,
|
|
9
|
+
hasOperationPreview,
|
|
10
|
+
hasPslContractInfer,
|
|
11
|
+
hasSchemaView,
|
|
12
|
+
} from '../control/control-capabilities';
|
|
3
13
|
export type {
|
|
4
14
|
ControlAdapterDescriptor,
|
|
5
15
|
ControlDriverDescriptor,
|
|
6
16
|
ControlExtensionDescriptor,
|
|
7
17
|
ControlFamilyDescriptor,
|
|
8
18
|
ControlTargetDescriptor,
|
|
9
|
-
} from '../control-descriptors';
|
|
19
|
+
} from '../control/control-descriptors';
|
|
10
20
|
export type {
|
|
11
21
|
ControlAdapterInstance,
|
|
12
22
|
ControlDriverInstance,
|
|
13
23
|
ControlExtensionInstance,
|
|
14
24
|
ControlFamilyInstance,
|
|
15
25
|
ControlTargetInstance,
|
|
16
|
-
} from '../control-instances';
|
|
26
|
+
} from '../control/control-instances';
|
|
17
27
|
export type {
|
|
18
|
-
DataTransformOperation,
|
|
19
28
|
MigrationOperationClass,
|
|
20
29
|
MigrationOperationPolicy,
|
|
21
30
|
MigrationPlan,
|
|
@@ -35,7 +44,11 @@ export type {
|
|
|
35
44
|
OpFactoryCall,
|
|
36
45
|
SerializedQueryPlan,
|
|
37
46
|
TargetMigrationsCapability,
|
|
38
|
-
} from '../control-migration-types';
|
|
47
|
+
} from '../control/control-migration-types';
|
|
48
|
+
export type {
|
|
49
|
+
OperationPreview,
|
|
50
|
+
OperationPreviewStatement,
|
|
51
|
+
} from '../control/control-operation-preview';
|
|
39
52
|
export type {
|
|
40
53
|
BaseSchemaIssue,
|
|
41
54
|
EmitContractResult,
|
|
@@ -47,25 +60,25 @@ export type {
|
|
|
47
60
|
SignDatabaseResult,
|
|
48
61
|
VerifyDatabaseResult,
|
|
49
62
|
VerifyDatabaseSchemaResult,
|
|
50
|
-
} from '../control-result-types';
|
|
63
|
+
} from '../control/control-result-types';
|
|
51
64
|
export {
|
|
52
65
|
VERIFY_CODE_HASH_MISMATCH,
|
|
53
66
|
VERIFY_CODE_MARKER_MISSING,
|
|
54
67
|
VERIFY_CODE_SCHEMA_FAILURE,
|
|
55
68
|
VERIFY_CODE_TARGET_MISMATCH,
|
|
56
|
-
} from '../control-result-types';
|
|
69
|
+
} from '../control/control-result-types';
|
|
57
70
|
export type {
|
|
58
71
|
CoreSchemaView,
|
|
59
72
|
SchemaNodeKind,
|
|
60
73
|
SchemaTreeNodeOptions,
|
|
61
74
|
SchemaTreeVisitor,
|
|
62
|
-
} from '../control-schema-view';
|
|
63
|
-
export { SchemaTreeNode } from '../control-schema-view';
|
|
75
|
+
} from '../control/control-schema-view';
|
|
76
|
+
export { SchemaTreeNode } from '../control/control-schema-view';
|
|
64
77
|
export type {
|
|
65
78
|
AssembledAuthoringContributions,
|
|
66
79
|
ControlStack,
|
|
67
80
|
CreateControlStackInput,
|
|
68
|
-
} from '../control-stack';
|
|
81
|
+
} from '../control/control-stack';
|
|
69
82
|
export {
|
|
70
83
|
assembleAuthoringContributions,
|
|
71
84
|
assembleControlMutationDefaults,
|
|
@@ -77,7 +90,7 @@ export {
|
|
|
77
90
|
extractComponentIds,
|
|
78
91
|
extractOperationTypeImports,
|
|
79
92
|
extractQueryOperationTypeImports,
|
|
80
|
-
} from '../control-stack';
|
|
93
|
+
} from '../control/control-stack';
|
|
81
94
|
export type {
|
|
82
95
|
ControlMutationDefaultEntry,
|
|
83
96
|
ControlMutationDefaultRegistry,
|
|
@@ -92,4 +105,4 @@ export type {
|
|
|
92
105
|
ParsedDefaultFunctionCall,
|
|
93
106
|
SourceDiagnostic,
|
|
94
107
|
SourceSpan,
|
|
95
|
-
} from '../mutation-default-types';
|
|
108
|
+
} from '../shared/mutation-default-types';
|
package/src/exports/emission.ts
CHANGED
|
@@ -2,5 +2,5 @@ export type {
|
|
|
2
2
|
EmissionSpi,
|
|
3
3
|
GenerateContractTypesOptions,
|
|
4
4
|
ValidationContext,
|
|
5
|
-
} from '../emission-types';
|
|
6
|
-
export type { TypesImportSpec } from '../types-import-spec';
|
|
5
|
+
} from '../control/emission-types';
|
|
6
|
+
export type { TypesImportSpec } from '../shared/types-import-spec';
|
package/src/exports/execution.ts
CHANGED
|
@@ -4,14 +4,14 @@ export type {
|
|
|
4
4
|
RuntimeExtensionDescriptor,
|
|
5
5
|
RuntimeFamilyDescriptor,
|
|
6
6
|
RuntimeTargetDescriptor,
|
|
7
|
-
} from '../execution-descriptors';
|
|
7
|
+
} from '../execution/execution-descriptors';
|
|
8
8
|
export type {
|
|
9
9
|
RuntimeAdapterInstance,
|
|
10
10
|
RuntimeDriverInstance,
|
|
11
11
|
RuntimeExtensionInstance,
|
|
12
12
|
RuntimeFamilyInstance,
|
|
13
13
|
RuntimeTargetInstance,
|
|
14
|
-
} from '../execution-instances';
|
|
15
|
-
export { assertRuntimeContractRequirementsSatisfied } from '../execution-requirements';
|
|
16
|
-
export type { ExecutionStack, ExecutionStackInstance } from '../execution-stack';
|
|
17
|
-
export { createExecutionStack, instantiateExecutionStack } from '../execution-stack';
|
|
14
|
+
} from '../execution/execution-instances';
|
|
15
|
+
export { assertRuntimeContractRequirementsSatisfied } from '../execution/execution-requirements';
|
|
16
|
+
export type { ExecutionStack, ExecutionStackInstance } from '../execution/execution-stack';
|
|
17
|
+
export { createExecutionStack, instantiateExecutionStack } from '../execution/execution-stack';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../control/psl-ast';
|
package/src/exports/runtime.ts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
export { AsyncIterableResult } from '../async-iterable-result';
|
|
2
|
-
export type {
|
|
3
|
-
export {
|
|
1
|
+
export { AsyncIterableResult } from '../execution/async-iterable-result';
|
|
2
|
+
export type { ExecutionPlan, QueryPlan, ResultType } from '../execution/query-plan';
|
|
3
|
+
export { checkAborted, raceAgainstAbort } from '../execution/race-against-abort';
|
|
4
|
+
export { runWithMiddleware } from '../execution/run-with-middleware';
|
|
5
|
+
export type { RuntimeCoreOptions } from '../execution/runtime-core';
|
|
6
|
+
export { RuntimeCore } from '../execution/runtime-core';
|
|
7
|
+
export type { RuntimeAbortedPhase, RuntimeErrorEnvelope } from '../execution/runtime-error';
|
|
8
|
+
export {
|
|
9
|
+
isRuntimeError,
|
|
10
|
+
RUNTIME_ABORTED,
|
|
11
|
+
runtimeAborted,
|
|
12
|
+
runtimeError,
|
|
13
|
+
} from '../execution/runtime-error';
|
|
4
14
|
export type {
|
|
5
15
|
AfterExecuteResult,
|
|
16
|
+
InterceptResult,
|
|
17
|
+
RuntimeExecuteOptions,
|
|
6
18
|
RuntimeExecutor,
|
|
7
19
|
RuntimeLog,
|
|
8
20
|
RuntimeMiddleware,
|
|
9
21
|
RuntimeMiddlewareContext,
|
|
10
|
-
} from '../runtime-middleware';
|
|
11
|
-
export { checkMiddlewareCompatibility } from '../runtime-middleware';
|
|
22
|
+
} from '../execution/runtime-middleware';
|
|
23
|
+
export { checkMiddlewareCompatibility } from '../execution/runtime-middleware';
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import type { JsonValue } from '@prisma-next/contract/types';
|
|
2
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
3
|
+
|
|
4
|
+
export type CodecTrait =
|
|
5
|
+
| 'equality'
|
|
6
|
+
| 'order'
|
|
7
|
+
| 'boolean'
|
|
8
|
+
| 'numeric'
|
|
9
|
+
| 'textual'
|
|
10
|
+
/**
|
|
11
|
+
* The codec carries a per-instance `validate(value: unknown) =>
|
|
12
|
+
* JsonSchemaValidationResult` function on the resolved codec object that
|
|
13
|
+
* the framework's `JsonSchemaValidatorRegistry` consults at runtime. The
|
|
14
|
+
* trait gates the `extractValidator` cast from structurally-typed
|
|
15
|
+
* `unknown` to a typed validator view.
|
|
16
|
+
*
|
|
17
|
+
* Retirement target. The unified `CodecDescriptor` model moves
|
|
18
|
+
* validation into the resolved codec's `decode` body; the parallel
|
|
19
|
+
* `JsonSchemaValidatorRegistry` (and this trait alongside it) retires
|
|
20
|
+
* under TML-2357 (T3.5.12). Per-library JSON extensions like
|
|
21
|
+
* `@prisma-next/extension-arktype-json` already follow the new pattern.
|
|
22
|
+
*/
|
|
23
|
+
| 'json-validator';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Per-call context the runtime threads to every `codec.encode` /
|
|
27
|
+
* `codec.decode` invocation for a single `runtime.execute()` call.
|
|
28
|
+
*
|
|
29
|
+
* The framework-level shape is family-agnostic and carries one field:
|
|
30
|
+
*
|
|
31
|
+
* - `signal?: AbortSignal` — per-query cancellation. The runtime returns
|
|
32
|
+
* a `RUNTIME.ABORTED` envelope when the signal aborts; codec authors
|
|
33
|
+
* who forward `signal` to their underlying SDK get true cancellation
|
|
34
|
+
* of in-flight network calls.
|
|
35
|
+
*
|
|
36
|
+
* Family layers extend this base with their own shape-of-call metadata:
|
|
37
|
+
* the SQL family adds `column?: SqlColumnRef` via `SqlCodecCallContext`
|
|
38
|
+
* (see `@prisma-next/sql-relational-core`). Mongo currently uses this
|
|
39
|
+
* framework type unchanged. Column metadata is intentionally **not** on
|
|
40
|
+
* the framework type — it is a SQL-family concept rooted in SQL's
|
|
41
|
+
* `(table, column)` addressing model and would not generalise to other
|
|
42
|
+
* families.
|
|
43
|
+
*
|
|
44
|
+
* The interface is named explicitly (not inlined) so future framework
|
|
45
|
+
* fields and family extensions can land additively without breaking
|
|
46
|
+
* codec author signatures.
|
|
47
|
+
*/
|
|
48
|
+
export interface CodecCallContext {
|
|
49
|
+
readonly signal?: AbortSignal;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* A codec is the contract between an application value and its on-wire and
|
|
54
|
+
* on-contract-disk representations.
|
|
55
|
+
*
|
|
56
|
+
* The author's mental model is two JS-side types — `TInput` (the
|
|
57
|
+
* application JS type) and `TWire` (the database driver wire format) —
|
|
58
|
+
* plus `JsonValue` for build-time contract artifacts. The codec translates
|
|
59
|
+
* `TInput` to `TWire` on writes and back on reads, and to/from `JsonValue`
|
|
60
|
+
* during contract emission and loading.
|
|
61
|
+
*
|
|
62
|
+
* Three representations participate:
|
|
63
|
+
* - **Input** (`TInput`): the JS type at the application boundary.
|
|
64
|
+
* - **Wire** (`TWire`): the format exchanged with the database driver.
|
|
65
|
+
* - **JSON** (`JsonValue`): a JSON-safe form used in contract artifacts.
|
|
66
|
+
*
|
|
67
|
+
* Codec methods split into two groups:
|
|
68
|
+
*
|
|
69
|
+
* - **Query-time** methods (`encode`, `decode`) run per row/parameter at the
|
|
70
|
+
* IO boundary; they are required and Promise-returning. The per-family
|
|
71
|
+
* codec factory accepts sync or async author functions and lifts sync
|
|
72
|
+
* ones to Promise-shaped methods automatically.
|
|
73
|
+
* - **Build-time** methods (`encodeJson`, `decodeJson`, `renderOutputType`)
|
|
74
|
+
* run when the contract is serialized, loaded, or when client types are
|
|
75
|
+
* emitted. They stay synchronous so contract validation and client
|
|
76
|
+
* construction are synchronous.
|
|
77
|
+
*
|
|
78
|
+
* Target-family codec interfaces extend this base with target-shaped
|
|
79
|
+
* metadata.
|
|
80
|
+
*/
|
|
81
|
+
export interface Codec<
|
|
82
|
+
Id extends string = string,
|
|
83
|
+
TTraits extends readonly CodecTrait[] = readonly CodecTrait[],
|
|
84
|
+
TWire = unknown,
|
|
85
|
+
TInput = unknown,
|
|
86
|
+
> {
|
|
87
|
+
/** Unique codec identifier in `namespace/name@version` format (e.g. `pg/timestamptz@1`). */
|
|
88
|
+
readonly id: Id;
|
|
89
|
+
/** Database-native type names this codec handles (e.g. `['timestamptz']`). */
|
|
90
|
+
readonly targetTypes: readonly string[];
|
|
91
|
+
/** Semantic traits for operator gating (e.g. equality, order, numeric). */
|
|
92
|
+
readonly traits?: TTraits;
|
|
93
|
+
/** Converts a JS value to the wire format expected by the database driver. Always Promise-returning at the boundary. The {@link CodecCallContext} is supplied by the runtime on every call (allocated once per `runtime.execute()`); family layers may narrow the ctx to extend it (e.g. SQL adds `column`). Author-side single-arg `(value) => …` functions remain legal via TypeScript's bivariance for trailing parameters. */
|
|
94
|
+
encode(value: TInput, ctx: CodecCallContext): Promise<TWire>;
|
|
95
|
+
/** Converts a wire value from the database driver into the JS application type. Always Promise-returning at the boundary. The {@link CodecCallContext} is supplied by the runtime on every call (allocated once per `runtime.execute()`); family layers may narrow the ctx to extend it (e.g. SQL adds `column`). Author-side single-arg `(wire) => …` functions remain legal via TypeScript's bivariance for trailing parameters. */
|
|
96
|
+
decode(wire: TWire, ctx: CodecCallContext): Promise<TInput>;
|
|
97
|
+
/** Converts a JS value to a JSON-safe representation for contract serialization. Synchronous; called during contract emission. */
|
|
98
|
+
encodeJson(value: TInput): JsonValue;
|
|
99
|
+
/** Converts a JSON representation back to the JS input type. Synchronous; called during contract loading via `validateContract`. */
|
|
100
|
+
decodeJson(json: JsonValue): TInput;
|
|
101
|
+
/** Produces the TypeScript output type expression for a field given its `typeParams`. Synchronous; used during contract.d.ts emission. */
|
|
102
|
+
renderOutputType?(typeParams: Record<string, unknown>): string | undefined;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface CodecLookup {
|
|
106
|
+
get(id: string): Codec | undefined;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export const emptyCodecLookup: CodecLookup = {
|
|
110
|
+
get: () => undefined,
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Family-agnostic per-instance context supplied by the framework when
|
|
115
|
+
* applying a higher-order codec factory. Allows stateful codecs (e.g.
|
|
116
|
+
* column-scoped encryption) to derive per-instance state from the
|
|
117
|
+
* materialization site.
|
|
118
|
+
*
|
|
119
|
+
* - `name` — the family-agnostic instance identity. For SQL, the runtime
|
|
120
|
+
* populates this as the `storage.types` instance name (e.g.
|
|
121
|
+
* `Embedding1536`) for typeRef-shaped columns, the synthesized
|
|
122
|
+
* anonymous instance name (`<anon:Document.embedding>`) for inline-
|
|
123
|
+
* `typeParams` columns, or a shared sentinel (`<shared:pg/text@1>`)
|
|
124
|
+
* for non-parameterized codec ids. Other families pick the analogous
|
|
125
|
+
* identity for their materialization sites.
|
|
126
|
+
*
|
|
127
|
+
* Family-specific extensions (e.g. {@link import('@prisma-next/sql-relational-core/ast').SqlCodecInstanceContext}
|
|
128
|
+
* in the SQL layer) augment this base with domain-shaped column-set
|
|
129
|
+
* metadata. Codec authors target the base when they don't read family-
|
|
130
|
+
* specific metadata; they target the family extension when they do.
|
|
131
|
+
*/
|
|
132
|
+
export interface CodecInstanceContext {
|
|
133
|
+
readonly name: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Family-agnostic codec metadata. Family-specific extensions augment the
|
|
138
|
+
* base `db.<family>.<target>` block with native-type information; the base
|
|
139
|
+
* shape is an empty object so non-relational codecs can carry no metadata.
|
|
140
|
+
*/
|
|
141
|
+
export interface CodecMeta {
|
|
142
|
+
readonly db?: Record<string, unknown>;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Unified codec descriptor. Every codec in the framework registers through
|
|
147
|
+
* this shape — non-parameterized codecs use `P = void` and a constant
|
|
148
|
+
* factory that returns the same shared codec instance for every column;
|
|
149
|
+
* parameterized codecs use a non-empty `P` and a curried higher-order
|
|
150
|
+
* factory that returns a per-instance codec.
|
|
151
|
+
*
|
|
152
|
+
* The descriptor is the codec-id-keyed source of truth for static metadata
|
|
153
|
+
* (`traits`, `targetTypes`, `meta`) and registration concerns
|
|
154
|
+
* (`paramsSchema` for JSON-boundary validation; optional `renderOutputType`
|
|
155
|
+
* for the `contract.d.ts` emit path). The runtime `Codec` instance returned
|
|
156
|
+
* by `factory(params)(ctx)` carries only the conversion behavior.
|
|
157
|
+
*
|
|
158
|
+
* Whether a codec id "is parameterized" stops being a registration-time
|
|
159
|
+
* distinction — it's a property of `P` on the descriptor. The descriptor
|
|
160
|
+
* map indexes every descriptor by `codecId`; both `descriptorFor(codecId)`
|
|
161
|
+
* and `forColumn(table, column)` resolve through the same map without
|
|
162
|
+
* branching on parameterization.
|
|
163
|
+
*
|
|
164
|
+
* @template P - The shape of the params accepted by the factory (`void` for
|
|
165
|
+
* non-parameterized codecs; a record like `{ length: number }` for
|
|
166
|
+
* parameterized codecs).
|
|
167
|
+
*
|
|
168
|
+
* Codec-registry-unification project § Decision.
|
|
169
|
+
*/
|
|
170
|
+
export interface CodecDescriptor<P = void> {
|
|
171
|
+
/** The codec ID this descriptor applies to (e.g. `pg/vector@1`, `pg/text@1`). */
|
|
172
|
+
readonly codecId: string;
|
|
173
|
+
/** Semantic traits for operator gating (e.g. equality, order, numeric). */
|
|
174
|
+
readonly traits: readonly CodecTrait[];
|
|
175
|
+
/** Database-native type names this codec handles (e.g. `['timestamptz']`). */
|
|
176
|
+
readonly targetTypes: readonly string[];
|
|
177
|
+
/** Optional family-specific metadata (e.g. SQL-side `db.sql.postgres.nativeType`). */
|
|
178
|
+
readonly meta?: CodecMeta;
|
|
179
|
+
/**
|
|
180
|
+
* Standard Schema validator for the factory's params. Validates JSON-
|
|
181
|
+
* sourced params at the contract boundary (PSL → IR; `contract.json` →
|
|
182
|
+
* runtime). For non-parameterized codecs (`P = void`), the schema
|
|
183
|
+
* validates `void`/`undefined` — the framework supplies no params at the
|
|
184
|
+
* call boundary.
|
|
185
|
+
*/
|
|
186
|
+
readonly paramsSchema: StandardSchemaV1<P>;
|
|
187
|
+
/**
|
|
188
|
+
* Emit-path string renderer for `contract.d.ts`. Returns the TypeScript
|
|
189
|
+
* output type expression for given params (e.g. `Vector<1536>`).
|
|
190
|
+
* Optional; absent renderers cause the emitter to fall back to the
|
|
191
|
+
* codec's base output type. Non-parameterized codecs typically omit it.
|
|
192
|
+
*/
|
|
193
|
+
readonly renderOutputType?: (params: P) => string | undefined;
|
|
194
|
+
/**
|
|
195
|
+
* The curried higher-order codec. For non-parameterized codecs, the
|
|
196
|
+
* factory is constant — every call returns the same shared codec
|
|
197
|
+
* instance. For parameterized codecs, the factory is called once per
|
|
198
|
+
* `storage.types` instance (or once per inline-`typeParams` column),
|
|
199
|
+
* with `ctx` carrying the column set the resulting codec serves.
|
|
200
|
+
*/
|
|
201
|
+
readonly factory: (params: P) => (ctx: CodecInstanceContext) => Codec;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Standard Schema validator for `void` params. Accepts only `undefined`
|
|
206
|
+
* (or absent input); rejects any other value so a contract that tries to
|
|
207
|
+
* thread `typeParams` through a non-parameterized codec id fails fast at
|
|
208
|
+
* the JSON boundary instead of silently coercing the value away. Used by
|
|
209
|
+
* the framework-supplied non-parameterized descriptor synthesizer.
|
|
210
|
+
*/
|
|
211
|
+
export const voidParamsSchema: StandardSchemaV1<void> = {
|
|
212
|
+
'~standard': {
|
|
213
|
+
version: 1,
|
|
214
|
+
vendor: 'prisma-next',
|
|
215
|
+
validate: (input) =>
|
|
216
|
+
input === undefined
|
|
217
|
+
? { value: undefined }
|
|
218
|
+
: {
|
|
219
|
+
issues: [
|
|
220
|
+
{
|
|
221
|
+
message: 'unexpected typeParams for non-parameterized codec (void params expected)',
|
|
222
|
+
},
|
|
223
|
+
],
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Synthesize a `CodecDescriptor<void>` for a non-parameterized codec
|
|
230
|
+
* runtime instance. The factory is constant — every call returns the same
|
|
231
|
+
* shared codec instance — so columns sharing this codec id share one
|
|
232
|
+
* resolved codec.
|
|
233
|
+
*
|
|
234
|
+
* Codec-registry-unification spec § Decision (Case T — non-parameterized
|
|
235
|
+
* text codec). This is the bridge while non-parameterized codec
|
|
236
|
+
* contributors still register through the legacy `codecs:` slot; once they
|
|
237
|
+
* migrate to ship descriptors directly (TML-2357 T3.5.3), this synthesis
|
|
238
|
+
* steps aside.
|
|
239
|
+
*/
|
|
240
|
+
export function synthesizeNonParameterizedDescriptor(codec: Codec): CodecDescriptor<void> {
|
|
241
|
+
// The descriptor's `factory: (params: void) => (ctx: CodecInstanceContext)
|
|
242
|
+
// => Codec` is a constant for non-parameterized codecs — `params` is
|
|
243
|
+
// never read and the returned ctx-applier always yields the same shared
|
|
244
|
+
// codec. We rely on the descriptor's typed `factory` slot to infer the
|
|
245
|
+
// signatures rather than naming `void` locally (biome's
|
|
246
|
+
// `noConfusingVoidType` flags `void` outside return positions).
|
|
247
|
+
const sharedFactory = () => () => codec;
|
|
248
|
+
// Family-extended codecs (SQL `Codec`) carry an optional `meta` field
|
|
249
|
+
// that the base interface doesn't declare. Read it through a structural
|
|
250
|
+
// narrow so the synthesizer forwards it to the descriptor without losing
|
|
251
|
+
// type safety on the base shape.
|
|
252
|
+
const codecMeta = (codec as { readonly meta?: CodecMeta }).meta;
|
|
253
|
+
return {
|
|
254
|
+
codecId: codec.id,
|
|
255
|
+
traits: codec.traits ?? [],
|
|
256
|
+
targetTypes: codec.targetTypes,
|
|
257
|
+
paramsSchema: voidParamsSchema,
|
|
258
|
+
factory: sharedFactory,
|
|
259
|
+
...(codecMeta !== undefined ? { meta: codecMeta } : {}),
|
|
260
|
+
};
|
|
261
|
+
}
|