@aventara/prisma7-adapter 1.0.0-rc.3 → 1.0.0-rc.8
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 +145 -1
- package/README.md +43 -14
- package/dist/discovery/discovery-artifact.interface.d.ts +11 -7
- package/dist/discovery/model.discoverer.js +8 -1
- package/dist/execution/operation.executor.js +17 -3
- package/dist/execution/scoped-cursor.resolver.d.ts +11 -0
- package/dist/execution/scoped-cursor.resolver.js +47 -0
- package/dist/generate/artifact.emitter.d.ts +8 -4
- package/dist/generate/artifact.emitter.js +10 -10
- package/dist/generate/computed-fields.import.d.ts +5 -0
- package/dist/generate/computed-fields.import.js +52 -0
- package/dist/generate/discovery.cli.js +7 -11
- package/dist/generate/index.d.ts +3 -5
- package/dist/generate/index.js +0 -1
- package/dist/generate/prisma.generate.d.ts +5 -13
- package/dist/generate/prisma.generate.js +9 -18
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/prisma-adapter.description.d.ts +42 -0
- package/dist/prisma-adapter.description.js +36 -0
- package/dist/prisma.adapter.js +10 -30
- package/dist/translation/operation.translator.d.ts +11 -0
- package/dist/translation/operation.translator.js +54 -8
- package/dist/translation/order-pagination.translator.d.ts +19 -0
- package/dist/translation/order-pagination.translator.js +15 -0
- package/package.json +2 -2
- package/dist/generate/computed-fields.reader.d.ts +0 -19
- package/dist/generate/computed-fields.reader.js +0 -210
|
@@ -2,7 +2,6 @@ import type { PrismaCapabilitySurface } from "../discovery/capability-surface.in
|
|
|
2
2
|
import type { AvPrismaAdapterModel, AvPrismaReferentialActionTable, PrismaTranslationTable } from "../discovery/discovery-artifact.interface.js";
|
|
3
3
|
import type { PrismaSchemaFacts } from "../discovery/schema-facts.interface.js";
|
|
4
4
|
import type { AvPrismaProvider } from "../provider/provider-profile.js";
|
|
5
|
-
import { type ConfigComputedFieldsReading } from "./computed-fields.reader.js";
|
|
6
5
|
import type { PrismaEntityAbsence } from "./existence.gate.js";
|
|
7
6
|
import { type PrismaCli } from "./prisma-cli.resolver.js";
|
|
8
7
|
import type { PrismaReaderExemption } from "./reader-crosscheck.js";
|
|
@@ -38,11 +37,6 @@ export type PrismaGenerateToolchain = {
|
|
|
38
37
|
readonly readSchema: (location: string) => Promise<PrismaSchemaFacts>;
|
|
39
38
|
readonly readSurface: (clientDirectory: string) => PrismaCapabilitySurface;
|
|
40
39
|
readonly writeArtifact: (file: string, source: string) => Promise<void>;
|
|
41
|
-
/**
|
|
42
|
-
* Reads which fields a configuration computes off its type. Optional: the
|
|
43
|
-
* TypeScript reader is used when it is left out.
|
|
44
|
-
*/
|
|
45
|
-
readonly readComputedFields?: (configFile: string) => ConfigComputedFieldsReading;
|
|
46
40
|
};
|
|
47
41
|
/** What {@link runPrismaGenerateStep} needs. */
|
|
48
42
|
export type PrismaGenerateRequest = {
|
|
@@ -55,8 +49,11 @@ export type PrismaGenerateRequest = {
|
|
|
55
49
|
readonly composeModel: PrismaModelComposer;
|
|
56
50
|
/**
|
|
57
51
|
* The application's Aventara configuration module (`src/aventara.config.ts`
|
|
58
|
-
* in a scaffolded project)
|
|
59
|
-
*
|
|
52
|
+
* in a scaffolded project). The artifact imports the fields it computes
|
|
53
|
+
* from the file `aventara-build` writes beside the artifact
|
|
54
|
+
* (`computed-fields.generated.ts`, a sibling); the step never reads the
|
|
55
|
+
* configuration, and only checks it exists. Left out, the artifact states
|
|
56
|
+
* none (`computedFields: null`).
|
|
60
57
|
*/
|
|
61
58
|
readonly config?: string;
|
|
62
59
|
readonly toolchain?: PrismaGenerateToolchain;
|
|
@@ -71,11 +68,6 @@ export type PrismaGenerateResult = {
|
|
|
71
68
|
/** PSL-only entities the schema itself explained away. */
|
|
72
69
|
readonly excluded: readonly PrismaEntityAbsence[];
|
|
73
70
|
readonly exemptions: readonly PrismaReaderExemption[];
|
|
74
|
-
/**
|
|
75
|
-
* What the step made of the configuration's computed fields: read, or why
|
|
76
|
-
* not. Absent when it was given no configuration.
|
|
77
|
-
*/
|
|
78
|
-
readonly computedFields?: ConfigComputedFieldsReading;
|
|
79
71
|
};
|
|
80
72
|
export declare function resolveInstalledPrismaCli(): PrismaCli;
|
|
81
73
|
/**
|
|
@@ -4,11 +4,10 @@ import path from "node:path";
|
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
5
|
import ts from "typescript";
|
|
6
6
|
import { computeModelHash } from "../discovery/artifact.loader.js";
|
|
7
|
-
import { DISCOVERY_ARTIFACT_FORMAT } from "../discovery/discovery-artifact.interface.js";
|
|
8
7
|
import { AvPrismaSchemaReaderError, readPrismaSchema, } from "../discovery/schema.reader.js";
|
|
9
8
|
import { readPrismaCapabilitySurface } from "../discovery/types.reader.js";
|
|
10
9
|
import { emitDiscoveryArtifactModule } from "./artifact.emitter.js";
|
|
11
|
-
import {
|
|
10
|
+
import { computedFieldsSpecifier } from "./computed-fields.import.js";
|
|
12
11
|
import { readDeclaredSupport } from "./declared-support.reader.js";
|
|
13
12
|
import { applyExistenceGate } from "./existence.gate.js";
|
|
14
13
|
import { resolvePrismaCli } from "./prisma-cli.resolver.js";
|
|
@@ -109,11 +108,6 @@ function unwritableArtifact(file, error) {
|
|
|
109
108
|
: code;
|
|
110
109
|
return new AvPrismaGenerateStepError(`the artifact file ${path.resolve(file)} (--out) cannot be written: ${because}.`);
|
|
111
110
|
}
|
|
112
|
-
async function describesModel(file, modelHash) {
|
|
113
|
-
const current = await readFile(file, "utf8").catch(() => undefined);
|
|
114
|
-
return (current?.includes(`\tregenerate_with_aventara_prepare: ${DISCOVERY_ARTIFACT_FORMAT},\n`) === true &&
|
|
115
|
-
current.includes(`\tmodelHash: ${JSON.stringify(modelHash)},\n`));
|
|
116
|
-
}
|
|
117
111
|
function majorOf(version) {
|
|
118
112
|
const major = /^(\d+)\./.exec(version)?.[1];
|
|
119
113
|
return major === undefined ? undefined : Number(major);
|
|
@@ -225,19 +219,17 @@ export async function runPrismaGenerateStep(request) {
|
|
|
225
219
|
client: clientShapeOf(surface),
|
|
226
220
|
};
|
|
227
221
|
const modelHash = await computeModelHash(model);
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
await toolchain.writeArtifact(request.artifactFile, await emitDiscoveryArtifactModule({
|
|
232
|
-
...emission,
|
|
233
|
-
computedFields: null,
|
|
234
|
-
}));
|
|
235
|
-
}
|
|
236
|
-
computedFields = (toolchain.readComputedFields ?? readConfigComputedFields)(request.config);
|
|
222
|
+
if (request.config !== undefined &&
|
|
223
|
+
(await stat(request.config).catch(() => undefined))?.isFile() !== true) {
|
|
224
|
+
throw new AvPrismaGenerateStepError(`the configuration \`${request.config}\` does not exist (--config).`);
|
|
237
225
|
}
|
|
238
226
|
const source = await emitDiscoveryArtifactModule({
|
|
239
227
|
...emission,
|
|
240
|
-
computedFields:
|
|
228
|
+
computedFields: request.config === undefined
|
|
229
|
+
? null
|
|
230
|
+
: {
|
|
231
|
+
specifier: computedFieldsSpecifier(request.artifactFile),
|
|
232
|
+
},
|
|
241
233
|
});
|
|
242
234
|
await toolchain.writeArtifact(request.artifactFile, source);
|
|
243
235
|
return {
|
|
@@ -247,7 +239,6 @@ export async function runPrismaGenerateStep(request) {
|
|
|
247
239
|
admitted,
|
|
248
240
|
excluded,
|
|
249
241
|
exemptions,
|
|
250
|
-
...(computedFields === undefined ? {} : { computedFields }),
|
|
251
242
|
};
|
|
252
243
|
}
|
|
253
244
|
function clientShapeOf(surface) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export type { AvPrismaAdapterModel, AvPrismaDiscoveryArtifact, AvPrismaReferentialAction, AvPrismaReferentialActionTable, AvPrismaReferentialEdge, AvPrismaResourceReferentialActions, } from "./discovery/discovery-artifact.interface.js";
|
|
2
2
|
export type { AvPrismaAdapterOptions } from "./prisma.adapter.js";
|
|
3
3
|
export { createPrismaAdapter } from "./prisma.adapter.js";
|
|
4
|
+
export { describePrismaAdapter } from "./prisma-adapter.description.js";
|
|
4
5
|
export type { AvPrismaDelegate, AvPrismaDelegateHost, AvPrismaDelegateIndex, AvPrismaTransactionOptions, } from "./prisma-client.interface.js";
|
|
5
6
|
export type { AvPrismaDriver, AvPrismaIsolationLevel, AvPrismaProvider, AvPrismaProviderProfile, } from "./provider/provider-profile.js";
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { AvAdapter, AvTransactionCapability } from "@aventara/core";
|
|
2
|
+
import type { AvPrismaAdapterModel, AvPrismaDiscoveryArtifact } from "./discovery/discovery-artifact.interface.js";
|
|
3
|
+
import { type AvPrismaDriver, type AvPrismaProvider } from "./provider/provider-profile.js";
|
|
4
|
+
/** What {@link describePrismaAdapter} takes: the artifact and the declared provider and driver. */
|
|
5
|
+
type PrismaAdapterDescriptionInput<M extends AvPrismaAdapterModel> = {
|
|
6
|
+
/** The `discovery` export of the generated discovery artifact. */
|
|
7
|
+
readonly discovery: AvPrismaDiscoveryArtifact<M>;
|
|
8
|
+
/** The database provider the client was generated for. */
|
|
9
|
+
readonly provider: AvPrismaProvider;
|
|
10
|
+
/** The Prisma driver adapter the client is constructed with. */
|
|
11
|
+
readonly driver: AvPrismaDriver;
|
|
12
|
+
};
|
|
13
|
+
/** The adapter's passive facts, as {@link describePrismaAdapter} states them. */
|
|
14
|
+
type PrismaAdapterDescription<M extends AvPrismaAdapterModel> = PrismaAdapterDescriptionInput<M> & Required<Pick<AvAdapter<M>, "model" | "referentialActions">> & Pick<AvAdapter<M>, "computedFields"> & {
|
|
15
|
+
/**
|
|
16
|
+
* The driver's transaction capability: `"interactive"` when the
|
|
17
|
+
* constructed Adapter runs transactions, `"none"` when it carries no
|
|
18
|
+
* `transaction` (`@prisma/adapter-d1`).
|
|
19
|
+
*/
|
|
20
|
+
readonly transactions: AvTransactionCapability;
|
|
21
|
+
/** Every Prisma driver runs developer SQL statements. */
|
|
22
|
+
readonly sqlStatements: true;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* The Prisma 7 adapter's passive description: the model, the driver's
|
|
26
|
+
* transaction capability, the referential actions and the computed fields, read
|
|
27
|
+
* from the discovery artifact with no client. `aventara-build` compiles the
|
|
28
|
+
* Contracts from it; `createPrismaAdapter({ ...description, client })` builds
|
|
29
|
+
* the adapter from it.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* // src/aventara.adapter.ts
|
|
34
|
+
* export default describePrismaAdapter({
|
|
35
|
+
* discovery,
|
|
36
|
+
* provider: "postgresql",
|
|
37
|
+
* driver: "@prisma/adapter-pg",
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function describePrismaAdapter<M extends AvPrismaAdapterModel>(input: PrismaAdapterDescriptionInput<M>): PrismaAdapterDescription<M>;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { resolveProviderProfile, } from "./provider/provider-profile.js";
|
|
2
|
+
const DELETE_EFFECTS = {
|
|
3
|
+
cascade: "cascade",
|
|
4
|
+
restrict: "restrict",
|
|
5
|
+
"no-action": "noAction",
|
|
6
|
+
"set-null": "setNull",
|
|
7
|
+
"set-default": "setDefault",
|
|
8
|
+
};
|
|
9
|
+
function translateReferentialActions(table) {
|
|
10
|
+
return Object.fromEntries(Object.entries(table).map(([resource, { owningEdges }]) => [
|
|
11
|
+
resource,
|
|
12
|
+
owningEdges.map((edge) => ({
|
|
13
|
+
field: edge.field,
|
|
14
|
+
target: edge.target,
|
|
15
|
+
referenceFields: edge.referenceFields,
|
|
16
|
+
onDelete: DELETE_EFFECTS[edge.onDelete],
|
|
17
|
+
})),
|
|
18
|
+
]));
|
|
19
|
+
}
|
|
20
|
+
export function describePrismaAdapter(input) {
|
|
21
|
+
const profile = resolveProviderProfile({
|
|
22
|
+
provider: input.provider,
|
|
23
|
+
driver: input.driver,
|
|
24
|
+
});
|
|
25
|
+
const computedFields = input.discovery.computedFields;
|
|
26
|
+
return Object.freeze({
|
|
27
|
+
discovery: input.discovery,
|
|
28
|
+
provider: input.provider,
|
|
29
|
+
driver: input.driver,
|
|
30
|
+
model: input.discovery.model,
|
|
31
|
+
transactions: profile.transactions,
|
|
32
|
+
referentialActions: translateReferentialActions(input.discovery.referentialActions),
|
|
33
|
+
...(computedFields === null ? {} : { computedFields }),
|
|
34
|
+
sqlStatements: true,
|
|
35
|
+
});
|
|
36
|
+
}
|
package/dist/prisma.adapter.js
CHANGED
|
@@ -5,25 +5,8 @@ import { derivePrismaBackReferences } from "./errors/back-reference.locator.js";
|
|
|
5
5
|
import { createPrismaOperationExecutor } from "./execution/operation.executor.js";
|
|
6
6
|
import { createPrismaSqlStatementExecutor } from "./execution/sql-statement.executor.js";
|
|
7
7
|
import { createPrismaTransactionExecutor } from "./execution/transaction.executor.js";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
cascade: "cascade",
|
|
11
|
-
restrict: "restrict",
|
|
12
|
-
"no-action": "noAction",
|
|
13
|
-
"set-null": "setNull",
|
|
14
|
-
"set-default": "setDefault",
|
|
15
|
-
};
|
|
16
|
-
function translateReferentialActions(table) {
|
|
17
|
-
return Object.fromEntries(Object.entries(table).map(([resource, { owningEdges }]) => [
|
|
18
|
-
resource,
|
|
19
|
-
owningEdges.map((edge) => ({
|
|
20
|
-
field: edge.field,
|
|
21
|
-
target: edge.target,
|
|
22
|
-
references: edge.references,
|
|
23
|
-
onDelete: DELETE_EFFECTS[edge.onDelete],
|
|
24
|
-
})),
|
|
25
|
-
]));
|
|
26
|
-
}
|
|
8
|
+
import { describePrismaAdapter } from "./prisma-adapter.description.js";
|
|
9
|
+
import { resolveBigintBinding, } from "./provider/provider-profile.js";
|
|
27
10
|
const PRISMA_VERSION_UNCHECKED_WARNING = "AVENTARA_PRISMA_VERSION_UNCHECKED";
|
|
28
11
|
function installedClientVersion(discovery, override) {
|
|
29
12
|
if (override !== undefined) {
|
|
@@ -47,22 +30,19 @@ function installedClientVersion(discovery, override) {
|
|
|
47
30
|
return undefined;
|
|
48
31
|
}
|
|
49
32
|
export async function createPrismaAdapter(options) {
|
|
50
|
-
const
|
|
51
|
-
provider: options.provider,
|
|
52
|
-
driver: options.driver,
|
|
53
|
-
});
|
|
33
|
+
const description = describePrismaAdapter(options);
|
|
54
34
|
await loadDiscoveryArtifact({
|
|
55
35
|
artifact: options.discovery,
|
|
56
36
|
installedPrismaVersion: installedClientVersion(options.discovery, options.installedPrismaVersion),
|
|
57
37
|
});
|
|
58
38
|
assertClientMatchesArtifact(options.discovery.client, options.client);
|
|
59
|
-
const model =
|
|
60
|
-
const referentialActions =
|
|
39
|
+
const model = description.model;
|
|
40
|
+
const referentialActions = description.referentialActions;
|
|
61
41
|
const backReferences = derivePrismaBackReferences(options.discovery.model);
|
|
62
42
|
const bigintBinding = resolveBigintBinding(options.driver);
|
|
63
|
-
const computedFields =
|
|
43
|
+
const computedFields = description.computedFields === undefined
|
|
64
44
|
? {}
|
|
65
|
-
: { computedFields:
|
|
45
|
+
: { computedFields: description.computedFields };
|
|
66
46
|
const { execute } = createPrismaOperationExecutor({
|
|
67
47
|
client: options.client,
|
|
68
48
|
model: options.discovery.model,
|
|
@@ -75,13 +55,13 @@ export async function createPrismaAdapter(options) {
|
|
|
75
55
|
: { transactionOptions: options.transactionOptions }),
|
|
76
56
|
});
|
|
77
57
|
const executeSql = createPrismaSqlStatementExecutor(options.client);
|
|
78
|
-
if (
|
|
58
|
+
if (description.transactions === "none") {
|
|
79
59
|
return {
|
|
80
60
|
model,
|
|
81
61
|
referentialActions,
|
|
82
62
|
...computedFields,
|
|
83
63
|
execute,
|
|
84
|
-
sqlStatements:
|
|
64
|
+
sqlStatements: description.sqlStatements,
|
|
85
65
|
executeSql,
|
|
86
66
|
};
|
|
87
67
|
}
|
|
@@ -101,7 +81,7 @@ export async function createPrismaAdapter(options) {
|
|
|
101
81
|
...computedFields,
|
|
102
82
|
execute,
|
|
103
83
|
transaction,
|
|
104
|
-
sqlStatements:
|
|
84
|
+
sqlStatements: description.sqlStatements,
|
|
105
85
|
executeSql,
|
|
106
86
|
};
|
|
107
87
|
}
|
|
@@ -144,3 +144,14 @@ export type PrismaOperationTranslationInput = {
|
|
|
144
144
|
* addresses no row — never a silently narrowed or widened call.
|
|
145
145
|
*/
|
|
146
146
|
export declare function translateOperation(input: PrismaOperationTranslationInput): PrismaOperationTranslation;
|
|
147
|
+
/**
|
|
148
|
+
* The unique read that tells whether the row a core cursor names meets the
|
|
149
|
+
* `AND` conditions it carries: `findUnique` by the cursor's address with the
|
|
150
|
+
* conditions, translated against `resource`, in its selector.
|
|
151
|
+
*/
|
|
152
|
+
export declare function translateScopedCursorLookup(input: {
|
|
153
|
+
readonly model: AvAdapterModel;
|
|
154
|
+
readonly translation: Readonly<Record<string, PrismaResourceTranslation>>;
|
|
155
|
+
readonly resource: string;
|
|
156
|
+
readonly cursor: Readonly<Record<string, unknown>>;
|
|
157
|
+
}): PrismaCall;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { addressIdentifier } from "./identifier.addressing.js";
|
|
2
2
|
import { translateMutationData } from "./mutation.translator.js";
|
|
3
|
-
import { translateOrderBy, translatePagination, } from "./order-pagination.translator.js";
|
|
3
|
+
import { translateCursorLookup, translateOrderBy, translatePagination, } from "./order-pagination.translator.js";
|
|
4
4
|
import { translateProjection, } from "./projection.translator.js";
|
|
5
5
|
import { translateWhere } from "./where.translator.js";
|
|
6
6
|
const FIRST_VARIANT_WRITE_ROUTE = {
|
|
@@ -131,7 +131,7 @@ function isUniqueSelectorVariant(key) {
|
|
|
131
131
|
function singleCallArguments(context, key, predicate, projectionArgs) {
|
|
132
132
|
const unique = isUniqueSelectorVariant(key);
|
|
133
133
|
const where = unique
|
|
134
|
-
? { where: uniqueWhere(context) }
|
|
134
|
+
? { where: uniqueWhere(context, key) }
|
|
135
135
|
: predicate === undefined
|
|
136
136
|
? {}
|
|
137
137
|
: { where: predicate };
|
|
@@ -189,11 +189,18 @@ function singleCallArguments(context, key, predicate, projectionArgs) {
|
|
|
189
189
|
throw new AvPrismaOperationTranslationError(`"${key}" has a dispatch entry and no argument shape, which is a translator defect`);
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
192
|
+
const SCOPED_UNIQUE_VARIANTS = new Set([
|
|
193
|
+
"update.unique",
|
|
194
|
+
"delete.unique",
|
|
195
|
+
]);
|
|
196
|
+
function uniqueWhere(context, key) {
|
|
197
|
+
const where = context.args.where;
|
|
198
|
+
if (!isRecord(where)) {
|
|
195
199
|
throw new AvPrismaOperationTranslationError("where must be a unique identifier object for a unique variant");
|
|
196
200
|
}
|
|
201
|
+
const { AND: conditions, ...rest } = where;
|
|
202
|
+
const scoped = conditions !== undefined && SCOPED_UNIQUE_VARIANTS.has(key);
|
|
203
|
+
const selector = scoped ? rest : where;
|
|
197
204
|
const addressed = addressIdentifier({
|
|
198
205
|
addresses: identifiersOf(context, context.resource),
|
|
199
206
|
values: selector,
|
|
@@ -203,7 +210,17 @@ function uniqueWhere(context) {
|
|
|
203
210
|
if (addressed === undefined) {
|
|
204
211
|
throw new AvPrismaOperationTranslationError(`where: { ${Object.keys(selector).join(", ")} } is no identifier of Resource "${context.resource}", so it addresses no row`);
|
|
205
212
|
}
|
|
206
|
-
|
|
213
|
+
if (!scoped) {
|
|
214
|
+
return addressed.where;
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
...addressed.where,
|
|
218
|
+
...translateWhere({
|
|
219
|
+
model: context.model,
|
|
220
|
+
resource: context.resource,
|
|
221
|
+
where: { AND: conditions },
|
|
222
|
+
}),
|
|
223
|
+
};
|
|
207
224
|
}
|
|
208
225
|
function identifierSelect(context) {
|
|
209
226
|
const [address] = identifiersOf(context, context.resource);
|
|
@@ -239,10 +256,39 @@ function paginationArguments(context) {
|
|
|
239
256
|
...(typeof context.args.offset === "number"
|
|
240
257
|
? { offset: context.args.offset }
|
|
241
258
|
: {}),
|
|
242
|
-
...(
|
|
259
|
+
...cursorArguments(context.args.cursor),
|
|
243
260
|
identifiers: identifiersOf(context, context.resource),
|
|
244
261
|
});
|
|
245
262
|
}
|
|
263
|
+
function cursorArguments(cursor) {
|
|
264
|
+
if (!isRecord(cursor)) {
|
|
265
|
+
return {};
|
|
266
|
+
}
|
|
267
|
+
if (Object.hasOwn(cursor, "AND")) {
|
|
268
|
+
throw new AvPrismaOperationTranslationError("cursor: its `AND` conditions reach no Prisma `cursor`; the executor resolves them before translation");
|
|
269
|
+
}
|
|
270
|
+
return { cursor };
|
|
271
|
+
}
|
|
272
|
+
export function translateScopedCursorLookup(input) {
|
|
273
|
+
const { AND: conditions, ...address } = input.cursor;
|
|
274
|
+
const identifiers = input.translation[input.resource]?.identifierKeys;
|
|
275
|
+
if (identifiers === undefined) {
|
|
276
|
+
throw new AvPrismaOperationTranslationError(`Resource "${input.resource}" has no Prisma addressing in the translation table`);
|
|
277
|
+
}
|
|
278
|
+
return {
|
|
279
|
+
model: input.resource,
|
|
280
|
+
action: "findUnique",
|
|
281
|
+
args: translateCursorLookup({
|
|
282
|
+
cursor: address,
|
|
283
|
+
conditions: translateWhere({
|
|
284
|
+
model: input.model,
|
|
285
|
+
resource: input.resource,
|
|
286
|
+
where: { AND: conditions },
|
|
287
|
+
}),
|
|
288
|
+
identifiers,
|
|
289
|
+
}),
|
|
290
|
+
};
|
|
291
|
+
}
|
|
246
292
|
function mutationData(context, stage, argument) {
|
|
247
293
|
return translateMutationData({
|
|
248
294
|
model: context.model,
|
|
@@ -305,7 +351,7 @@ function relationArgumentTranslator(context) {
|
|
|
305
351
|
Object.assign(emitted, translatePagination({
|
|
306
352
|
...(typeof args.limit === "number" ? { limit: args.limit } : {}),
|
|
307
353
|
...(typeof args.offset === "number" ? { offset: args.offset } : {}),
|
|
308
|
-
...(
|
|
354
|
+
...cursorArguments(args.cursor),
|
|
309
355
|
identifiers: identifiersOf(context, target),
|
|
310
356
|
}));
|
|
311
357
|
return emitted;
|
|
@@ -30,4 +30,23 @@ export type OrderByTranslation = {
|
|
|
30
30
|
readonly orderBy: unknown;
|
|
31
31
|
};
|
|
32
32
|
export declare function translatePagination(input: PaginationTranslation): PrismaPaginationArguments;
|
|
33
|
+
/**
|
|
34
|
+
* The Aventara cursor carries the active ordered scalar fields; core guarantees
|
|
35
|
+
* that they include a complete identifier (`V1009` — *"orderBy must include a
|
|
36
|
+
* complete Resource identifier as an explicit tie-breaker"*). Prisma's `cursor`
|
|
37
|
+
* is an ADDRESS, so the identifier is what is emitted: the remaining ordered
|
|
38
|
+
* fields are the ordering, which `orderBy` already carries, and adding them as
|
|
39
|
+
* equality members of a where-unique would narrow the address rather than
|
|
40
|
+
* sharpen it.
|
|
41
|
+
*/
|
|
42
|
+
/**
|
|
43
|
+
* The unique read that tells whether the row a cursor names meets `conditions`
|
|
44
|
+
* (a translated `<M>WhereInput`): its address, the conditions in `AND`, and the
|
|
45
|
+
* address's members selected.
|
|
46
|
+
*/
|
|
47
|
+
export declare function translateCursorLookup(input: {
|
|
48
|
+
readonly cursor: Readonly<Record<string, unknown>>;
|
|
49
|
+
readonly conditions: Readonly<Record<string, unknown>>;
|
|
50
|
+
readonly identifiers: readonly PrismaIdentifierAddress[];
|
|
51
|
+
}): Readonly<Record<string, unknown>>;
|
|
33
52
|
export declare function translateOrderBy(input: OrderByTranslation): PrismaOrderByInput | readonly PrismaOrderByInput[];
|
|
@@ -24,6 +24,21 @@ export function translatePagination(input) {
|
|
|
24
24
|
}
|
|
25
25
|
return emitted;
|
|
26
26
|
}
|
|
27
|
+
export function translateCursorLookup(input) {
|
|
28
|
+
const addressed = addressIdentifier({
|
|
29
|
+
addresses: input.identifiers,
|
|
30
|
+
values: input.cursor,
|
|
31
|
+
match: "subset",
|
|
32
|
+
emit: (_member, value) => value,
|
|
33
|
+
});
|
|
34
|
+
if (addressed === undefined) {
|
|
35
|
+
throw new AvPrismaOrderTranslationError(`cursor: no identifier is complete in { ${Object.keys(input.cursor).join(", ")} }, so it addresses no row`);
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
where: { ...addressed.where, AND: [input.conditions] },
|
|
39
|
+
select: Object.fromEntries(addressed.address.members.map((member) => [member, true])),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
27
42
|
function addressCursor(cursor, identifiers) {
|
|
28
43
|
const addressed = addressIdentifier({
|
|
29
44
|
addresses: identifiers,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aventara/prisma7-adapter",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.8",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"description": "The Prisma 7 adapter for Aventara.",
|
|
6
6
|
"type": "module",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"CHANGELOG.md"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@aventara/core": "1.0.0-rc.
|
|
33
|
+
"@aventara/core": "1.0.0-rc.8"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"@prisma/adapter-better-sqlite3": "^7.10.0",
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { AvConfigComputedFields } from "@aventara/core";
|
|
2
|
-
/** What the reader made of a configuration: its computed fields, or why it could not tell. */
|
|
3
|
-
export type ConfigComputedFieldsReading = {
|
|
4
|
-
readonly kind: "read";
|
|
5
|
-
readonly computedFields: AvConfigComputedFields;
|
|
6
|
-
} | {
|
|
7
|
-
readonly kind: "unread";
|
|
8
|
-
readonly reason: string;
|
|
9
|
-
};
|
|
10
|
-
/** Thrown when the configuration the step was told to read cannot be found. */
|
|
11
|
-
export declare class AvPrismaConfigReaderError extends Error {
|
|
12
|
-
readonly name = "AvPrismaConfigReaderError";
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Reads which fields the configuration in `configFile` computes, from the type
|
|
16
|
-
* of its `aventaraConfig` export (a function's awaited return, or a value), or
|
|
17
|
-
* of its default export.
|
|
18
|
-
*/
|
|
19
|
-
export declare function readConfigComputedFields(configFile: string): ConfigComputedFieldsReading;
|