@aventara/prisma7-adapter 1.0.0-rc.0 → 1.0.0-rc.2
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/CHANGELOG.md +552 -0
- package/README.md +407 -329
- package/dist/discovery/artifact.loader.d.ts +10 -6
- package/dist/discovery/artifact.loader.js +20 -20
- package/dist/discovery/capability-surface.interface.d.ts +1 -1
- package/dist/discovery/capability.deriver.d.ts +9 -6
- package/dist/discovery/capability.deriver.js +41 -6
- package/dist/discovery/client-shape.verifier.d.ts +1 -1
- package/dist/discovery/client-shape.verifier.js +2 -2
- package/dist/discovery/discovery-artifact.interface.d.ts +38 -47
- package/dist/discovery/discovery-artifact.interface.js +1 -1
- package/dist/discovery/enum.mapper.d.ts +2 -2
- package/dist/discovery/field.mapper.d.ts +13 -13
- package/dist/discovery/field.mapper.js +10 -10
- package/dist/discovery/identifier.mapper.d.ts +7 -7
- package/dist/discovery/installed-client.locator.d.ts +13 -0
- package/dist/discovery/installed-client.locator.js +43 -0
- package/dist/discovery/model.discoverer.d.ts +7 -4
- package/dist/discovery/model.discoverer.js +61 -19
- package/dist/discovery/operations.deriver.d.ts +6 -6
- package/dist/discovery/schema-facts.interface.d.ts +3 -3
- package/dist/discovery/schema.reader.d.ts +2 -2
- package/dist/discovery/schema.reader.js +5 -5
- package/dist/discovery/types.reader.d.ts +2 -2
- package/dist/discovery/types.reader.js +22 -22
- package/dist/discovery/vocabulary.dictionary.d.ts +14 -14
- package/dist/discovery/vocabulary.dictionary.js +1 -1
- package/dist/errors/back-reference.locator.d.ts +25 -0
- package/dist/errors/back-reference.locator.js +100 -0
- package/dist/errors/bigint-binding.locator.d.ts +7 -0
- package/dist/errors/bigint-binding.locator.js +27 -0
- package/dist/errors/error.normalizer.d.ts +44 -6
- package/dist/errors/error.normalizer.js +96 -7
- package/dist/errors/prisma-error.reader.d.ts +6 -0
- package/dist/errors/prisma-error.reader.js +3 -0
- package/dist/execution/first-variant.emulator.d.ts +4 -4
- package/dist/execution/first-variant.emulator.js +13 -9
- package/dist/execution/operation.executor.d.ts +15 -9
- package/dist/execution/operation.executor.js +34 -17
- package/dist/execution/result.shaper.d.ts +3 -3
- package/dist/execution/result.shaper.js +7 -7
- package/dist/execution/sql-statement.executor.d.ts +9 -0
- package/dist/execution/sql-statement.executor.js +58 -0
- package/dist/execution/transaction.executor.d.ts +12 -8
- package/dist/execution/transaction.executor.js +11 -5
- package/dist/generate/artifact.emitter.d.ts +11 -7
- package/dist/generate/artifact.emitter.js +60 -18
- package/dist/generate/computed-fields.reader.d.ts +19 -0
- package/dist/generate/computed-fields.reader.js +210 -0
- package/dist/generate/declared-support.reader.d.ts +1 -1
- package/dist/generate/discovery.cli.d.ts +4 -3
- package/dist/generate/discovery.cli.js +31 -15
- package/dist/generate/existence.gate.d.ts +4 -4
- package/dist/generate/existence.gate.js +4 -4
- package/dist/generate/index.d.ts +13 -5
- package/dist/generate/index.js +5 -2
- package/dist/generate/prisma.generate.d.ts +24 -8
- package/dist/generate/prisma.generate.js +52 -15
- package/dist/index.d.ts +4 -4
- package/dist/prisma-client.interface.d.ts +22 -8
- package/dist/prisma-client.interface.js +7 -0
- package/dist/prisma.adapter.d.ts +16 -16
- package/dist/prisma.adapter.js +48 -5
- package/dist/provider/provider-profile.d.ts +29 -13
- package/dist/provider/provider-profile.js +21 -0
- package/dist/translation/json-null.sentinel.d.ts +7 -0
- package/dist/translation/json-null.sentinel.js +17 -0
- package/dist/translation/mutation.translator.d.ts +8 -8
- package/dist/translation/mutation.translator.js +37 -30
- package/dist/translation/operation.translator.d.ts +7 -7
- package/dist/translation/operation.translator.js +12 -12
- package/dist/translation/order-pagination.translator.d.ts +5 -5
- package/dist/translation/order-pagination.translator.js +16 -16
- package/dist/translation/projection.translator.d.ts +4 -4
- package/dist/translation/projection.translator.js +11 -11
- package/dist/translation/scalar.conversion.d.ts +9 -9
- package/dist/translation/scalar.conversion.js +11 -11
- package/dist/translation/where.translator.d.ts +5 -5
- package/dist/translation/where.translator.js +114 -31
- package/package.json +6 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type AvPrismaAdapterModel } from "./discovery-artifact.interface.js";
|
|
2
2
|
/** Every artifact failure is this class, and every one of them says how to fix it. */
|
|
3
|
-
export declare class
|
|
3
|
+
export declare class AvPrismaDiscoveryArtifactError extends Error {
|
|
4
4
|
/**
|
|
5
5
|
* `instruction` replaces the general regeneration sentence where the reason
|
|
6
6
|
* reads as the first half of one sentence with it.
|
|
@@ -9,8 +9,12 @@ export declare class PrismaDiscoveryArtifactError extends Error {
|
|
|
9
9
|
}
|
|
10
10
|
export type PrismaDiscoveryArtifactLoad = {
|
|
11
11
|
readonly artifact: unknown;
|
|
12
|
-
/**
|
|
13
|
-
|
|
12
|
+
/**
|
|
13
|
+
* The `version` of the `@prisma/client` actually installed beside the caller;
|
|
14
|
+
* `undefined` when it could not be read, and the majors are then not compared
|
|
15
|
+
* (the adapter says so at startup).
|
|
16
|
+
*/
|
|
17
|
+
readonly installedPrismaVersion: string | undefined;
|
|
14
18
|
};
|
|
15
19
|
/**
|
|
16
20
|
* The identity of a discovered model: one canonicalization, one digest — over
|
|
@@ -20,6 +24,6 @@ export type PrismaDiscoveryArtifactLoad = {
|
|
|
20
24
|
* entrypoint, and hashing it would put a foreign-key action into the Contract
|
|
21
25
|
* identity and into every generated client.
|
|
22
26
|
*/
|
|
23
|
-
export declare function computeModelHash(model:
|
|
27
|
+
export declare function computeModelHash(model: AvPrismaAdapterModel): Promise<string>;
|
|
24
28
|
/** Validates an artifact and hands back its model **unchanged**. */
|
|
25
|
-
export declare function loadDiscoveryArtifact(load: PrismaDiscoveryArtifactLoad): Promise<
|
|
29
|
+
export declare function loadDiscoveryArtifact(load: PrismaDiscoveryArtifactLoad): Promise<AvPrismaAdapterModel>;
|
|
@@ -5,10 +5,10 @@ const REGENERATION_INSTRUCTION = "Regenerate the discovery artifact — `npm run
|
|
|
5
5
|
"set up by `aventara`, or the adapter's generate step " +
|
|
6
6
|
"(`aventara-prisma7-generate`) — and redeploy it " +
|
|
7
7
|
"alongside the schema and client it was generated from.";
|
|
8
|
-
export class
|
|
8
|
+
export class AvPrismaDiscoveryArtifactError extends Error {
|
|
9
9
|
constructor(reason, instruction = REGENERATION_INSTRUCTION) {
|
|
10
10
|
super(`${reason} ${instruction}`);
|
|
11
|
-
this.name = "
|
|
11
|
+
this.name = "AvPrismaDiscoveryArtifactError";
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
function hex(digest) {
|
|
@@ -31,56 +31,56 @@ function majorOf(version) {
|
|
|
31
31
|
}
|
|
32
32
|
function assertArtifactShape(artifact) {
|
|
33
33
|
if (!isRecord(artifact)) {
|
|
34
|
-
throw new
|
|
34
|
+
throw new AvPrismaDiscoveryArtifactError("The discovery artifact is not a JSON object.");
|
|
35
35
|
}
|
|
36
36
|
if (artifact.regenerate_with_aventara_prepare !== DISCOVERY_ARTIFACT_FORMAT) {
|
|
37
|
-
throw new
|
|
37
|
+
throw new AvPrismaDiscoveryArtifactError("The discovery artifact was written by another version of @aventara/prisma7-adapter.");
|
|
38
38
|
}
|
|
39
39
|
for (const key of ["prismaVersion", "provider", "modelHash"]) {
|
|
40
40
|
if (typeof artifact[key] !== "string") {
|
|
41
|
-
throw new
|
|
41
|
+
throw new AvPrismaDiscoveryArtifactError(`The discovery artifact's \`${key}\` is not a string.`);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
if (!isRecord(artifact.model)) {
|
|
45
|
-
throw new
|
|
45
|
+
throw new AvPrismaDiscoveryArtifactError("The discovery artifact's `model` is not a JSON object.");
|
|
46
46
|
}
|
|
47
|
-
for (const key of [
|
|
48
|
-
"translation",
|
|
49
|
-
"referentialActions",
|
|
50
|
-
"client",
|
|
51
|
-
"createRequirements",
|
|
52
|
-
]) {
|
|
47
|
+
for (const key of ["translation", "referentialActions", "client"]) {
|
|
53
48
|
if (!isRecord(artifact[key])) {
|
|
54
|
-
throw new
|
|
49
|
+
throw new AvPrismaDiscoveryArtifactError(`The discovery artifact's \`${key}\` is not a JSON object.`);
|
|
55
50
|
}
|
|
56
51
|
}
|
|
52
|
+
if (artifact.computedFields !== null && !isRecord(artifact.computedFields)) {
|
|
53
|
+
throw new AvPrismaDiscoveryArtifactError("The discovery artifact's `computedFields` is neither a JSON object nor null.");
|
|
54
|
+
}
|
|
57
55
|
for (const key of ["scalars", "enums", "resources"]) {
|
|
58
56
|
if (!isRecord(artifact.model[key])) {
|
|
59
|
-
throw new
|
|
57
|
+
throw new AvPrismaDiscoveryArtifactError(`The discovery artifact's \`model.${key}\` is not a JSON object.`);
|
|
60
58
|
}
|
|
61
59
|
}
|
|
62
60
|
if (artifact.model.transactions !== "none" &&
|
|
63
61
|
artifact.model.transactions !== "interactive") {
|
|
64
|
-
throw new
|
|
62
|
+
throw new AvPrismaDiscoveryArtifactError("The discovery artifact's `model.transactions` is not a transaction capability.");
|
|
65
63
|
}
|
|
66
64
|
if (artifact.model.referenceWrites !== "uniform") {
|
|
67
|
-
throw new
|
|
65
|
+
throw new AvPrismaDiscoveryArtifactError("The discovery artifact's `model.referenceWrites` is not `uniform`, which every Prisma model is.");
|
|
68
66
|
}
|
|
69
67
|
}
|
|
70
68
|
export async function loadDiscoveryArtifact(load) {
|
|
71
69
|
const { artifact, installedPrismaVersion } = load;
|
|
72
70
|
assertArtifactShape(artifact);
|
|
73
71
|
const artifactMajor = majorOf(artifact.prismaVersion);
|
|
74
|
-
const installedMajor =
|
|
72
|
+
const installedMajor = installedPrismaVersion === undefined
|
|
73
|
+
? artifactMajor
|
|
74
|
+
: majorOf(installedPrismaVersion);
|
|
75
75
|
if (artifactMajor === undefined || installedMajor === undefined) {
|
|
76
|
-
throw new
|
|
76
|
+
throw new AvPrismaDiscoveryArtifactError(`A Prisma version is not a major.minor.patch version: the artifact declares \`${artifact.prismaVersion}\` and the installed client reports \`${installedPrismaVersion}\`.`);
|
|
77
77
|
}
|
|
78
78
|
if (artifactMajor !== installedMajor) {
|
|
79
|
-
throw new
|
|
79
|
+
throw new AvPrismaDiscoveryArtifactError(`The discovery artifact was generated against Prisma major ${artifactMajor}, and the installed client is major ${installedMajor}. The P-code surface and the generated-client grammar are version-bound.`);
|
|
80
80
|
}
|
|
81
81
|
const modelHash = await computeModelHash(artifact.model);
|
|
82
82
|
if (modelHash !== artifact.modelHash) {
|
|
83
|
-
throw new
|
|
83
|
+
throw new AvPrismaDiscoveryArtifactError("The discovery artifact's `modelHash` does not match its own `model`, so the artifact is corrupt or was edited by hand.");
|
|
84
84
|
}
|
|
85
85
|
return artifact.model;
|
|
86
86
|
}
|
|
@@ -101,7 +101,7 @@ export type PrismaRelationSurface = {
|
|
|
101
101
|
* presence question, asked of the reducer key rather than of the edge.
|
|
102
102
|
*
|
|
103
103
|
* A model-level fact carried on each edge because the capability it qualifies
|
|
104
|
-
* is the edge's: `
|
|
104
|
+
* is the edge's: `AvRelationFieldCapabilities.reducers` says which reducers *this
|
|
105
105
|
* relation* admits, and `_count` is the one projection key all of them are
|
|
106
106
|
* asked for through.
|
|
107
107
|
*/
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AvRelationFieldCapabilities, AvScalarFieldCapabilities, AvScalarFilterOperator } from "@aventara/core";
|
|
2
|
+
import type { PrismaFilterModeFacts } from "../provider/provider-profile.js";
|
|
2
3
|
import type { PrismaRelationSurface, PrismaScalarSurface } from "./capability-surface.interface.js";
|
|
3
4
|
/** A Prisma spelling that no dictionary table recognises: a build stop, never a drop. */
|
|
4
|
-
export declare class
|
|
5
|
-
readonly name = "
|
|
5
|
+
export declare class AvPrismaCapabilityDerivationError extends Error {
|
|
6
|
+
readonly name = "AvPrismaCapabilityDerivationError";
|
|
6
7
|
}
|
|
7
8
|
export type ScalarCapabilityInput = {
|
|
8
9
|
readonly surface: PrismaScalarSurface;
|
|
10
|
+
/** The `mode`s the engine honours (see this module's header). */
|
|
11
|
+
readonly filterModes: PrismaFilterModeFacts;
|
|
9
12
|
};
|
|
10
13
|
/** A relation's capabilities are answered for the field, not for an operation. */
|
|
11
14
|
export type RelationCapabilityInput = {
|
|
12
15
|
readonly surface: PrismaRelationSurface;
|
|
13
16
|
};
|
|
14
|
-
export declare function deriveScalarCapabilities(input: ScalarCapabilityInput):
|
|
17
|
+
export declare function deriveScalarCapabilities(input: ScalarCapabilityInput): AvScalarFieldCapabilities;
|
|
15
18
|
/** The Prisma operand for each ADVERTISED operator, keyed by the Aventara name. */
|
|
16
|
-
export declare function deriveScalarFilterOperands(input: ScalarCapabilityInput): Readonly<Partial<Record<
|
|
17
|
-
export declare function deriveRelationCapabilities(input: RelationCapabilityInput):
|
|
19
|
+
export declare function deriveScalarFilterOperands(input: Pick<ScalarCapabilityInput, "surface">): Readonly<Partial<Record<AvScalarFilterOperator, string>>>;
|
|
20
|
+
export declare function deriveRelationCapabilities(input: RelationCapabilityInput): AvRelationFieldCapabilities;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PRISMA_EDGE_ARGUMENTS, PRISMA_FILTER_OPERATORS, PRISMA_REDUCERS, PRISMA_RELATION_DIRECTIVES, PRISMA_RELATION_FILTERS, PRISMA_SCALAR_DIRECTIVES, } from "./vocabulary.dictionary.js";
|
|
2
|
-
export class
|
|
3
|
-
name = "
|
|
2
|
+
export class AvPrismaCapabilityDerivationError extends Error {
|
|
3
|
+
name = "AvPrismaCapabilityDerivationError";
|
|
4
4
|
}
|
|
5
5
|
const FILTER_OPERATOR_ORDER = [
|
|
6
6
|
"equals",
|
|
@@ -61,18 +61,50 @@ const PAGINATION_ORDER = [
|
|
|
61
61
|
export function deriveScalarCapabilities(input) {
|
|
62
62
|
const { surface } = input;
|
|
63
63
|
const operands = deriveScalarFilterOperands(input);
|
|
64
|
-
const
|
|
64
|
+
const derived = surface.filters
|
|
65
65
|
.map((key) => look(PRISMA_FILTER_OPERATORS, key, "a scalar filter operator"))
|
|
66
|
-
.filter((operator) => translatable(operator, operands))
|
|
66
|
+
.filter((operator) => translatable(operator, operands));
|
|
67
|
+
const modes = filterModes(derived, input.filterModes);
|
|
68
|
+
const filter = canonical(FILTER_OPERATOR_ORDER, [
|
|
69
|
+
...derived,
|
|
70
|
+
...(modes === undefined ? [] : ["mode"]),
|
|
71
|
+
]);
|
|
67
72
|
return {
|
|
68
73
|
select: true,
|
|
69
74
|
...(filter.length > 0 ? { filter } : {}),
|
|
75
|
+
...(modes ?? {}),
|
|
70
76
|
order: surface.orderable,
|
|
71
77
|
...(surface.nullsOrderable ? { orderNulls: true } : {}),
|
|
72
78
|
...directives("create", surface.createOperations),
|
|
73
79
|
...directives("update", surface.updateOperations),
|
|
74
80
|
};
|
|
75
81
|
}
|
|
82
|
+
const TEXT_OPERATORS = [
|
|
83
|
+
"contains",
|
|
84
|
+
"startsWith",
|
|
85
|
+
"endsWith",
|
|
86
|
+
];
|
|
87
|
+
const JSON_TEXT_OPERATORS = [
|
|
88
|
+
"stringContains",
|
|
89
|
+
"stringStartsWith",
|
|
90
|
+
"stringEndsWith",
|
|
91
|
+
];
|
|
92
|
+
function filterModes(operators, facts) {
|
|
93
|
+
const admitted = (modes) => modes.filter((mode) => mode !== "insensitive" || operators.includes("mode"));
|
|
94
|
+
if (operators.some((operator) => JSON_TEXT_OPERATORS.includes(operator))) {
|
|
95
|
+
return {
|
|
96
|
+
filterModes: admitted(facts.jsonDocument),
|
|
97
|
+
...(operators.includes("path")
|
|
98
|
+
? { pathFilterModes: admitted(facts.jsonPath) }
|
|
99
|
+
: {}),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
if (operators.includes("mode") ||
|
|
103
|
+
operators.some((operator) => TEXT_OPERATORS.includes(operator))) {
|
|
104
|
+
return { filterModes: admitted(facts.text) };
|
|
105
|
+
}
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
76
108
|
export function deriveScalarFilterOperands(input) {
|
|
77
109
|
const operands = {};
|
|
78
110
|
for (const operator of FILTER_OPERATOR_ORDER) {
|
|
@@ -126,7 +158,10 @@ function reducersIn(reducers, bulk) {
|
|
|
126
158
|
return bulk ? reducers : { reducers, scopes: ["record"] };
|
|
127
159
|
}
|
|
128
160
|
function writableIn(directives, bulk) {
|
|
129
|
-
return
|
|
161
|
+
return {
|
|
162
|
+
directives,
|
|
163
|
+
scopes: bulk ? ["nested", "bulkWrite"] : ["nested"],
|
|
164
|
+
};
|
|
130
165
|
}
|
|
131
166
|
export function deriveRelationCapabilities(input) {
|
|
132
167
|
const { surface } = input;
|
|
@@ -164,7 +199,7 @@ export function deriveRelationCapabilities(input) {
|
|
|
164
199
|
}
|
|
165
200
|
function look(table, key, what) {
|
|
166
201
|
if (!(key in table)) {
|
|
167
|
-
throw new
|
|
202
|
+
throw new AvPrismaCapabilityDerivationError(`the generated types offer "${key}" as ${what} and the dictionary has no row for it`);
|
|
168
203
|
}
|
|
169
204
|
return table[key];
|
|
170
205
|
}
|
|
@@ -8,6 +8,6 @@ export declare function describeClientDrift(recorded: PrismaClientShape, client:
|
|
|
8
8
|
* Throws when the client in hand is not the one the artifact was generated
|
|
9
9
|
* against — one sentence, naming what differs and `aventara:prepare`.
|
|
10
10
|
*
|
|
11
|
-
* @throws
|
|
11
|
+
* @throws AvPrismaDiscoveryArtifactError
|
|
12
12
|
*/
|
|
13
13
|
export declare function assertClientMatchesArtifact(recorded: PrismaClientShape, client: unknown): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { delegateKeyOf } from "../execution/operation.executor.js";
|
|
2
|
-
import {
|
|
2
|
+
import { AvPrismaDiscoveryArtifactError } from "./artifact.loader.js";
|
|
3
3
|
const SHOWN = 3;
|
|
4
4
|
function readMember(value, key) {
|
|
5
5
|
if ((typeof value !== "object" && typeof value !== "function") ||
|
|
@@ -89,5 +89,5 @@ export function assertClientMatchesArtifact(recorded, client) {
|
|
|
89
89
|
}
|
|
90
90
|
const shown = drift.slice(0, SHOWN).join("; ");
|
|
91
91
|
const more = drift.length > SHOWN ? `; and ${drift.length - SHOWN} more` : "";
|
|
92
|
-
throw new
|
|
92
|
+
throw new AvPrismaDiscoveryArtifactError(`The Prisma client has changed since the discovery artifact was generated (${shown}${more}):`, "run `npm run aventara:prepare` (the adapter's `aventara-prisma7-generate`) to regenerate it, then restart.");
|
|
93
93
|
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import type { AvAdapterModel, AvConfigComputedFields, AvEnumDefinition, AvScalarRegistry, AvTransactionCapability } from "@aventara/core";
|
|
2
|
+
import type { AvAdapterResource } from "@aventara/core/internal";
|
|
3
|
+
import type { AvPrismaProvider } from "../provider/provider-profile.js";
|
|
4
4
|
/** The adapter model a discovery artifact carries, in Aventara's vocabulary. */
|
|
5
|
-
export type
|
|
5
|
+
export type AvPrismaAdapterModel = {
|
|
6
6
|
/** The scalar types the schema uses. */
|
|
7
|
-
readonly scalars:
|
|
7
|
+
readonly scalars: AvScalarRegistry;
|
|
8
8
|
/** The schema's enums, by name. */
|
|
9
|
-
readonly enums: Readonly<Record<string,
|
|
9
|
+
readonly enums: Readonly<Record<string, AvEnumDefinition>>;
|
|
10
10
|
/** The schema's models, as Resources. */
|
|
11
|
-
readonly resources: Readonly<Record<string,
|
|
11
|
+
readonly resources: Readonly<Record<string, AvAdapterResource<AvPrismaAdapterModel>>>;
|
|
12
12
|
/** Whether the driver supports interactive transactions. */
|
|
13
|
-
readonly transactions:
|
|
13
|
+
readonly transactions: AvTransactionCapability;
|
|
14
14
|
/**
|
|
15
15
|
* Prisma takes one record's references one way at a time (its checked and
|
|
16
16
|
* unchecked write inputs), so every artifact states `"uniform"`.
|
|
17
17
|
*/
|
|
18
|
-
readonly referenceWrites: NonNullable<
|
|
18
|
+
readonly referenceWrites: NonNullable<AvAdapterModel["referenceWrites"]>;
|
|
19
19
|
};
|
|
20
20
|
/** One identifier, and the **Prisma addressing key** that reaches it. */
|
|
21
21
|
export type PrismaIdentifierAddress = {
|
|
22
|
-
readonly members:
|
|
22
|
+
readonly members: AvAdapterResource<AvPrismaAdapterModel>["identifiers"][number];
|
|
23
23
|
readonly key: string;
|
|
24
24
|
};
|
|
25
25
|
/** One Resource's Prisma addressing, in the order the identifiers were discovered. */
|
|
@@ -27,44 +27,44 @@ export type PrismaResourceTranslation = {
|
|
|
27
27
|
readonly identifierKeys: readonly PrismaIdentifierAddress[];
|
|
28
28
|
};
|
|
29
29
|
/** The **translation table**: Prisma addressing for every discovered Resource. */
|
|
30
|
-
export type PrismaTranslationTable<M extends
|
|
30
|
+
export type PrismaTranslationTable<M extends AvPrismaAdapterModel = AvPrismaAdapterModel> = {
|
|
31
31
|
readonly [R in keyof M["resources"]]: PrismaResourceTranslation;
|
|
32
32
|
};
|
|
33
33
|
/** A referential action, as `onDelete`/`onUpdate` name it in the schema. */
|
|
34
|
-
export type
|
|
35
|
-
/** One
|
|
36
|
-
export type
|
|
34
|
+
export type AvPrismaReferentialAction = "cascade" | "restrict" | "no-action" | "set-null" | "set-default";
|
|
35
|
+
/** One owning relation edge's resolved referential actions. */
|
|
36
|
+
export type AvPrismaReferentialEdge = {
|
|
37
37
|
/** The edge's field name on the enclosing (child) resource. */
|
|
38
38
|
readonly field: string;
|
|
39
|
-
/** The resource the edge points
|
|
39
|
+
/** The resource the edge points at: the parent, whose deletion fires `onDelete`. */
|
|
40
40
|
readonly target: string;
|
|
41
41
|
/** Whether the edge holds one related row or many. */
|
|
42
42
|
readonly cardinality: "one" | "many";
|
|
43
43
|
/**
|
|
44
|
-
* The scalar fields of the
|
|
44
|
+
* The scalar fields of the enclosing resource that hold the reference: the
|
|
45
45
|
* relation's `@relation(fields: […])`, in schema order.
|
|
46
46
|
*/
|
|
47
47
|
readonly references: readonly string[];
|
|
48
|
-
/** What deleting a `target` row does to rows of the
|
|
49
|
-
readonly onDelete:
|
|
48
|
+
/** What deleting a `target` row does to rows of the enclosing resource. */
|
|
49
|
+
readonly onDelete: AvPrismaReferentialAction;
|
|
50
50
|
/** The same for an update of the referenced key. Read independently of `onDelete`. */
|
|
51
|
-
readonly onUpdate:
|
|
51
|
+
readonly onUpdate: AvPrismaReferentialAction;
|
|
52
52
|
};
|
|
53
53
|
/**
|
|
54
54
|
* One Resource's owning edges, in schema field order: the relation fields that
|
|
55
55
|
* declare `@relation(fields: …)`. An empty list means deleting rows elsewhere
|
|
56
56
|
* leaves this Resource's rows alone.
|
|
57
57
|
*/
|
|
58
|
-
export type
|
|
58
|
+
export type AvPrismaResourceReferentialActions = {
|
|
59
59
|
/** The Resource's owning edges, in schema order. */
|
|
60
|
-
readonly owningEdges: readonly
|
|
60
|
+
readonly owningEdges: readonly AvPrismaReferentialEdge[];
|
|
61
61
|
};
|
|
62
62
|
/**
|
|
63
|
-
* The
|
|
63
|
+
* The referential-action table: every discovered Resource's owning edges,
|
|
64
64
|
* resolved.
|
|
65
65
|
*/
|
|
66
|
-
export type
|
|
67
|
-
readonly [R in keyof M["resources"]]:
|
|
66
|
+
export type AvPrismaReferentialActionTable<M extends AvPrismaAdapterModel = AvPrismaAdapterModel> = {
|
|
67
|
+
readonly [R in keyof M["resources"]]: AvPrismaResourceReferentialActions;
|
|
68
68
|
};
|
|
69
69
|
/**
|
|
70
70
|
* What the generated Prisma client exposed when the artifact was generated: each
|
|
@@ -72,29 +72,14 @@ export type PrismaReferentialActionTable<M extends PrismaAdapterModel = PrismaAd
|
|
|
72
72
|
* references (`prisma.<model>.fields`) in code-unit order.
|
|
73
73
|
*/
|
|
74
74
|
export type PrismaClientShape = Readonly<Record<string, readonly string[]>>;
|
|
75
|
-
/**
|
|
76
|
-
* What a create of each Resource cannot do without, already in core's words
|
|
77
|
-
* (`Adapter["createRequirements"]`): a column the client must write, or a
|
|
78
|
-
* required relation — which may instead be written through the scalar fields
|
|
79
|
-
* that hold its reference, read off the relation's referential edge
|
|
80
|
-
* (`references`), never restated here — and the relation's other end, through
|
|
81
|
-
* which a nested create supplies it.
|
|
82
|
-
*
|
|
83
|
-
* Read at generate time from the generated client's create inputs — the
|
|
84
|
-
* question marks on `<M>UncheckedCreateInput` and `<M>CreateInput` — and from the
|
|
85
|
-
* schema's `@relation(fields: …)` pairing. Beside the model and outside
|
|
86
|
-
* `modelHash`: a requirement is a fact about the store, not about the semantic
|
|
87
|
-
* model, and the Contract carries no foreign-key detail.
|
|
88
|
-
*/
|
|
89
|
-
export type PrismaCreateRequirementTable = NonNullable<Adapter["createRequirements"]>;
|
|
90
75
|
/** The current discovery artifact format. */
|
|
91
|
-
export declare const DISCOVERY_ARTIFACT_FORMAT =
|
|
76
|
+
export declare const DISCOVERY_ARTIFACT_FORMAT = 4;
|
|
92
77
|
/**
|
|
93
78
|
* The discovery artifact: the module `aventara-prisma7-generate` writes from
|
|
94
79
|
* your schema and generated client. Import its `discovery` export and pass it
|
|
95
80
|
* to `createPrismaAdapter({ discovery })`.
|
|
96
81
|
*/
|
|
97
|
-
export type
|
|
82
|
+
export type AvPrismaDiscoveryArtifact<M extends AvPrismaAdapterModel = AvPrismaAdapterModel> = {
|
|
98
83
|
/**
|
|
99
84
|
* The artifact's format. A TypeScript error naming this property means the
|
|
100
85
|
* artifact was written by another version of `@aventara/prisma7-adapter`:
|
|
@@ -104,8 +89,8 @@ export type PrismaDiscoveryArtifact<M extends PrismaAdapterModel = PrismaAdapter
|
|
|
104
89
|
/** The Prisma version the artifact was generated with, such as `"7.10.0"`. */
|
|
105
90
|
readonly prismaVersion: string;
|
|
106
91
|
/** The database provider: `"sqlite"` or `"postgresql"`. */
|
|
107
|
-
readonly provider:
|
|
108
|
-
/** `sha256:<hex>` of the canonicalized `model` below
|
|
92
|
+
readonly provider: AvPrismaProvider;
|
|
93
|
+
/** `sha256:<hex>` of the canonicalized `model` below, and of nothing else. */
|
|
109
94
|
readonly modelHash: string;
|
|
110
95
|
/** What the schema and the generated client agreed on. */
|
|
111
96
|
readonly model: M;
|
|
@@ -113,14 +98,20 @@ export type PrismaDiscoveryArtifact<M extends PrismaAdapterModel = PrismaAdapter
|
|
|
113
98
|
readonly translation: PrismaTranslationTable<M>;
|
|
114
99
|
/**
|
|
115
100
|
* The schema's referential actions; not part of `modelHash`. An entry under
|
|
116
|
-
* resource `R` says
|
|
101
|
+
* resource `R` says that deleting a `target` row does `onDelete` to rows of `R`.
|
|
117
102
|
*/
|
|
118
|
-
readonly referentialActions:
|
|
103
|
+
readonly referentialActions: AvPrismaReferentialActionTable<M>;
|
|
119
104
|
/**
|
|
120
105
|
* The models and field references of the client the artifact was generated
|
|
121
106
|
* against; not part of `modelHash`.
|
|
122
107
|
*/
|
|
123
108
|
readonly client: PrismaClientShape;
|
|
124
|
-
/**
|
|
125
|
-
|
|
109
|
+
/**
|
|
110
|
+
* Which fields the configuration's write compute fills, per layer, as the
|
|
111
|
+
* generate step read them off the configuration it was given (`--config`);
|
|
112
|
+
* `null` when it was given none. The model's type carries the same statement
|
|
113
|
+
* for the pipeline stages' types; this value is compared with the
|
|
114
|
+
* configuration when the framework starts. Not part of `modelHash`.
|
|
115
|
+
*/
|
|
116
|
+
readonly computedFields: AvConfigComputedFields | null;
|
|
126
117
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const DISCOVERY_ARTIFACT_FORMAT =
|
|
1
|
+
export const DISCOVERY_ARTIFACT_FORMAT = 4;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AvEnumDefinition } from "@aventara/core";
|
|
2
2
|
import type { PrismaSchemaEnum } from "./schema-facts.interface.js";
|
|
3
3
|
import type { PrismaDiscoveryDiagnostic } from "./vocabulary.dictionary.js";
|
|
4
4
|
export type EnumMappingInput = {
|
|
@@ -9,7 +9,7 @@ export type EnumMappingInput = {
|
|
|
9
9
|
export type EnumMappingOutcome = {
|
|
10
10
|
readonly outcome: "enum";
|
|
11
11
|
readonly name: string;
|
|
12
|
-
readonly definition:
|
|
12
|
+
readonly definition: AvEnumDefinition;
|
|
13
13
|
} | {
|
|
14
14
|
readonly outcome: "excluded";
|
|
15
15
|
readonly diagnostic: PrismaDiscoveryDiagnostic;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type AvAdapterLifecycleTrait, type AvAdapterRelationField, type AvAdapterScalarField } from "@aventara/core/internal";
|
|
2
2
|
import type { PrismaResourceSurface } from "./capability-surface.interface.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { AvPrismaAdapterModel, AvPrismaReferentialAction } from "./discovery-artifact.interface.js";
|
|
4
4
|
import type { PrismaSchemaField, PrismaSchemaUnknown } from "./schema-facts.interface.js";
|
|
5
5
|
import { type PrismaDiscoveryDiagnostic, type PrismaEvidence } from "./vocabulary.dictionary.js";
|
|
6
6
|
/** A reader-versus-reader disagreement: not a schema problem, and not recoverable. */
|
|
7
|
-
export declare class
|
|
8
|
-
readonly name = "
|
|
7
|
+
export declare class AvPrismaFieldProjectionError extends Error {
|
|
8
|
+
readonly name = "AvPrismaFieldProjectionError";
|
|
9
9
|
}
|
|
10
|
-
export type ProjectedScalarField = Omit<
|
|
11
|
-
export type ProjectedRelationField = Omit<
|
|
10
|
+
export type ProjectedScalarField = Omit<AvAdapterScalarField<AvPrismaAdapterModel>, "capabilities">;
|
|
11
|
+
export type ProjectedRelationField = Omit<AvAdapterRelationField<AvPrismaAdapterModel>, "capabilities">;
|
|
12
12
|
/**
|
|
13
13
|
* One relation edge as PSL states it — the pairing evidence and the referential
|
|
14
14
|
* actions, neither of which the projected field carries.
|
|
@@ -22,9 +22,9 @@ export type PrismaRelationEdge = {
|
|
|
22
22
|
readonly cardinality: "one" | "many";
|
|
23
23
|
/** `@relation("Name")`, or `null` where PSL wrote none. PSL-only. */
|
|
24
24
|
readonly relationName: string | null;
|
|
25
|
-
readonly onDelete:
|
|
25
|
+
readonly onDelete: AvPrismaReferentialAction | null;
|
|
26
26
|
/** The same for an update of the referenced key. `null` on a non-owning edge. */
|
|
27
|
-
readonly onUpdate:
|
|
27
|
+
readonly onUpdate: AvPrismaReferentialAction | null;
|
|
28
28
|
};
|
|
29
29
|
export type FieldProjectionInput = {
|
|
30
30
|
readonly resource: string;
|
|
@@ -61,22 +61,22 @@ export type PrismaDefaultOutcome =
|
|
|
61
61
|
/** A row of `PRISMA_DEFAULT_TABLE` matched, and its evidence travels with it. */
|
|
62
62
|
{
|
|
63
63
|
readonly form: "table";
|
|
64
|
-
readonly traits: readonly
|
|
64
|
+
readonly traits: readonly AvAdapterLifecycleTrait[];
|
|
65
65
|
readonly evidence: PrismaEvidence;
|
|
66
66
|
}
|
|
67
67
|
/** A static value — a literal, a number, a boolean, an enum member, a list. */
|
|
68
68
|
| {
|
|
69
69
|
readonly form: "static";
|
|
70
|
-
readonly traits: readonly
|
|
70
|
+
readonly traits: readonly AvAdapterLifecycleTrait[];
|
|
71
71
|
}
|
|
72
72
|
/** A generator form the table does not carry: `DEFAULTED`, plus a recorded unknown. */
|
|
73
73
|
| {
|
|
74
74
|
readonly form: "unrecognised-generator";
|
|
75
|
-
readonly traits: readonly
|
|
75
|
+
readonly traits: readonly AvAdapterLifecycleTrait[];
|
|
76
76
|
};
|
|
77
77
|
export declare function matchPrismaDefault(argument: string): PrismaDefaultOutcome;
|
|
78
78
|
/** Why a field is legitimately optional in `<M>UncheckedCreateInput`. */
|
|
79
|
-
export type CreateOptionalCause =
|
|
79
|
+
export type CreateOptionalCause = AvAdapterLifecycleTrait | "nullable"
|
|
80
80
|
/** A scalar list needs no value: the empty list is one. */
|
|
81
81
|
| "list";
|
|
82
82
|
export type CreateOptionalCrossCheckInput = {
|
|
@@ -90,7 +90,7 @@ export type CreateOptionalCrossCheckInput = {
|
|
|
90
90
|
readonly name: string;
|
|
91
91
|
readonly nullable: boolean;
|
|
92
92
|
readonly list: boolean;
|
|
93
|
-
readonly lifecycle: readonly
|
|
93
|
+
readonly lifecycle: readonly AvAdapterLifecycleTrait[];
|
|
94
94
|
}[];
|
|
95
95
|
/** TYPE — `<M>UncheckedCreateInput`'s optional members. */
|
|
96
96
|
readonly createOptional: readonly string[];
|
|
@@ -2,8 +2,8 @@ import { LIFECYCLE_TRAITS, } from "@aventara/core/internal";
|
|
|
2
2
|
import { projectEnumBackedColumn } from "./enum.mapper.js";
|
|
3
3
|
import { mapPrismaScalarField } from "./scalar.mapper.js";
|
|
4
4
|
import { PRISMA_DEFAULT_TABLE, PRISMA_UNMATCHED_DEFAULT_TRAITS, } from "./vocabulary.dictionary.js";
|
|
5
|
-
export class
|
|
6
|
-
name = "
|
|
5
|
+
export class AvPrismaFieldProjectionError extends Error {
|
|
6
|
+
name = "AvPrismaFieldProjectionError";
|
|
7
7
|
}
|
|
8
8
|
export function projectPrismaField(input) {
|
|
9
9
|
return input.models.has(input.field.type)
|
|
@@ -18,7 +18,7 @@ function projectScalarField(input) {
|
|
|
18
18
|
}
|
|
19
19
|
const exposed = surface.scalarFields[field.name];
|
|
20
20
|
if (exposed === undefined) {
|
|
21
|
-
throw new
|
|
21
|
+
throw new AvPrismaFieldProjectionError(`${resource}.${field.name} passed the existence gate and has no scalar surface`);
|
|
22
22
|
}
|
|
23
23
|
assertTokenAgrees(resource, field, exposed.token);
|
|
24
24
|
const lifecycle = projectLifecycle(resource, field);
|
|
@@ -44,10 +44,10 @@ function assertTokenAgrees(resource, field, token) {
|
|
|
44
44
|
const listed = token.endsWith("[]");
|
|
45
45
|
const base = listed ? token.slice(0, -2) : token;
|
|
46
46
|
if (base !== field.type) {
|
|
47
|
-
throw new
|
|
47
|
+
throw new AvPrismaFieldProjectionError(`${resource}.${field.name} is written \`${field.type}\` in schema.prisma and the generated client's types carry the FieldRef token \`${token}\`. The two readers describe one instant, so this is a stale generated client or a reader defect, not a schema the adapter can translate.`);
|
|
48
48
|
}
|
|
49
49
|
if (listed !== field.list) {
|
|
50
|
-
throw new
|
|
50
|
+
throw new AvPrismaFieldProjectionError(`${resource}.${field.name} is ${field.list ? "a list" : "not a list"} in schema.prisma and the generated client's types carry the FieldRef token \`${token}\`, which says the opposite.`);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
const ADAPTER_TRAIT_ORDER = LIFECYCLE_TRAITS.filter((trait) => trait === "DEFAULTED" ||
|
|
@@ -145,13 +145,13 @@ function projectRelationField(input) {
|
|
|
145
145
|
const cardinality = field.list ? "many" : "one";
|
|
146
146
|
const nullable = cardinality === "many" ? false : field.optional;
|
|
147
147
|
if (exposed.many !== field.list) {
|
|
148
|
-
throw new
|
|
148
|
+
throw new AvPrismaFieldProjectionError(`${column} is ${field.list ? "a list" : "a single edge"} in schema.prisma and the generated client's payload type says the opposite.`);
|
|
149
149
|
}
|
|
150
150
|
if (exposed.nullable !== nullable) {
|
|
151
|
-
throw new
|
|
151
|
+
throw new AvPrismaFieldProjectionError(`${column} is ${nullable ? "optional" : "required"} in schema.prisma and the generated client's payload type ${exposed.nullable ? "admits" : "refuses"} \`null\`.`);
|
|
152
152
|
}
|
|
153
153
|
if (exposed.target !== field.type) {
|
|
154
|
-
throw new
|
|
154
|
+
throw new AvPrismaFieldProjectionError(`${column} targets \`${field.type}\` in schema.prisma and \`${exposed.target}\` in the generated client's payload type.`);
|
|
155
155
|
}
|
|
156
156
|
assertForeignKeyAgrees(column, field, siblings, nullable);
|
|
157
157
|
return {
|
|
@@ -178,10 +178,10 @@ function assertForeignKeyAgrees(column, field, siblings, nullable) {
|
|
|
178
178
|
for (const name of field.relation?.fields ?? []) {
|
|
179
179
|
const scalar = siblings.find((sibling) => sibling.name === name);
|
|
180
180
|
if (scalar === undefined) {
|
|
181
|
-
throw new
|
|
181
|
+
throw new AvPrismaFieldProjectionError(`${column} names \`${name}\` in \`@relation(fields: …)\` and the model declares no such column.`);
|
|
182
182
|
}
|
|
183
183
|
if (scalar.optional && !nullable) {
|
|
184
|
-
throw new
|
|
184
|
+
throw new AvPrismaFieldProjectionError(`${column} is required and its foreign key \`${name}\` is optional. PSL forbids this combination, so the schema cannot have said it: one of the readers is wrong.`);
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
}
|
|
@@ -22,12 +22,12 @@ export type PrismaIdentifierOmission = PrismaUniquenessCriterion & ({
|
|
|
22
22
|
* from the model, a relation field, a list, or `@ignore`d out of the
|
|
23
23
|
* generated client. Valid PSL cannot produce the first three; `@ignore`
|
|
24
24
|
* can, and keeping it would emit an identifier over a key no
|
|
25
|
-
* `
|
|
25
|
+
* `AvAdapterFieldMap` carries.
|
|
26
26
|
*/
|
|
27
27
|
readonly reason: "unresolved-participant";
|
|
28
28
|
readonly unresolvedMembers: readonly string[];
|
|
29
29
|
} | {
|
|
30
|
-
/** An empty member list: `
|
|
30
|
+
/** An empty member list: `AvAdapterIdentifier` is non-empty by type. */
|
|
31
31
|
readonly reason: "no-participants";
|
|
32
32
|
});
|
|
33
33
|
/**
|
|
@@ -36,18 +36,18 @@ export type PrismaIdentifierOmission = PrismaUniquenessCriterion & ({
|
|
|
36
36
|
* rest are not usable.
|
|
37
37
|
*
|
|
38
38
|
* One list, two projections, which is the reason the pair is not split here:
|
|
39
|
-
* the composer takes `.members` for `
|
|
39
|
+
* the composer takes `.members` for `AvAdapterResource.identifiers` (model
|
|
40
40
|
* content, hashed, Contract-bound) and the whole address for the artifact's
|
|
41
41
|
* translation table (adapter-private, unhashed). Two parallel lists would have
|
|
42
42
|
* to be kept in step; these cannot drift because they are one.
|
|
43
43
|
*
|
|
44
|
-
* `PrismaIdentifierAddress.members` is derived from `
|
|
44
|
+
* `PrismaIdentifierAddress.members` is derived from `AvAdapterResource`, so a
|
|
45
45
|
* change in core's identifier type reaches this mapper as a compile error.
|
|
46
46
|
* Discovery is where the field map is being **built**, so the abstract form is
|
|
47
|
-
* what applies — `
|
|
48
|
-
* `
|
|
47
|
+
* what applies — `AvAdapterScalarFieldKey` widens to `string` through
|
|
48
|
+
* `AvAdapterFieldMap<M>`, making an identifier here a non-empty tuple of field
|
|
49
49
|
* names. The concrete keys are pinned later, in the emitted artifact
|
|
50
|
-
* (`
|
|
50
|
+
* (`AvPrismaDiscoveryArtifact<M>`).
|
|
51
51
|
*/
|
|
52
52
|
export type PrismaIdentifierMapping = {
|
|
53
53
|
readonly identifiers: readonly PrismaIdentifierAddress[];
|