@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.
Files changed (80) hide show
  1. package/CHANGELOG.md +552 -0
  2. package/README.md +407 -329
  3. package/dist/discovery/artifact.loader.d.ts +10 -6
  4. package/dist/discovery/artifact.loader.js +20 -20
  5. package/dist/discovery/capability-surface.interface.d.ts +1 -1
  6. package/dist/discovery/capability.deriver.d.ts +9 -6
  7. package/dist/discovery/capability.deriver.js +41 -6
  8. package/dist/discovery/client-shape.verifier.d.ts +1 -1
  9. package/dist/discovery/client-shape.verifier.js +2 -2
  10. package/dist/discovery/discovery-artifact.interface.d.ts +38 -47
  11. package/dist/discovery/discovery-artifact.interface.js +1 -1
  12. package/dist/discovery/enum.mapper.d.ts +2 -2
  13. package/dist/discovery/field.mapper.d.ts +13 -13
  14. package/dist/discovery/field.mapper.js +10 -10
  15. package/dist/discovery/identifier.mapper.d.ts +7 -7
  16. package/dist/discovery/installed-client.locator.d.ts +13 -0
  17. package/dist/discovery/installed-client.locator.js +43 -0
  18. package/dist/discovery/model.discoverer.d.ts +7 -4
  19. package/dist/discovery/model.discoverer.js +61 -19
  20. package/dist/discovery/operations.deriver.d.ts +6 -6
  21. package/dist/discovery/schema-facts.interface.d.ts +3 -3
  22. package/dist/discovery/schema.reader.d.ts +2 -2
  23. package/dist/discovery/schema.reader.js +5 -5
  24. package/dist/discovery/types.reader.d.ts +2 -2
  25. package/dist/discovery/types.reader.js +22 -22
  26. package/dist/discovery/vocabulary.dictionary.d.ts +14 -14
  27. package/dist/discovery/vocabulary.dictionary.js +1 -1
  28. package/dist/errors/back-reference.locator.d.ts +25 -0
  29. package/dist/errors/back-reference.locator.js +100 -0
  30. package/dist/errors/bigint-binding.locator.d.ts +7 -0
  31. package/dist/errors/bigint-binding.locator.js +27 -0
  32. package/dist/errors/error.normalizer.d.ts +44 -6
  33. package/dist/errors/error.normalizer.js +96 -7
  34. package/dist/errors/prisma-error.reader.d.ts +6 -0
  35. package/dist/errors/prisma-error.reader.js +3 -0
  36. package/dist/execution/first-variant.emulator.d.ts +4 -4
  37. package/dist/execution/first-variant.emulator.js +13 -9
  38. package/dist/execution/operation.executor.d.ts +15 -9
  39. package/dist/execution/operation.executor.js +34 -17
  40. package/dist/execution/result.shaper.d.ts +3 -3
  41. package/dist/execution/result.shaper.js +7 -7
  42. package/dist/execution/sql-statement.executor.d.ts +9 -0
  43. package/dist/execution/sql-statement.executor.js +58 -0
  44. package/dist/execution/transaction.executor.d.ts +12 -8
  45. package/dist/execution/transaction.executor.js +11 -5
  46. package/dist/generate/artifact.emitter.d.ts +11 -7
  47. package/dist/generate/artifact.emitter.js +60 -18
  48. package/dist/generate/computed-fields.reader.d.ts +19 -0
  49. package/dist/generate/computed-fields.reader.js +210 -0
  50. package/dist/generate/declared-support.reader.d.ts +1 -1
  51. package/dist/generate/discovery.cli.d.ts +4 -3
  52. package/dist/generate/discovery.cli.js +31 -15
  53. package/dist/generate/existence.gate.d.ts +4 -4
  54. package/dist/generate/existence.gate.js +4 -4
  55. package/dist/generate/index.d.ts +13 -5
  56. package/dist/generate/index.js +5 -2
  57. package/dist/generate/prisma.generate.d.ts +24 -8
  58. package/dist/generate/prisma.generate.js +52 -15
  59. package/dist/index.d.ts +4 -4
  60. package/dist/prisma-client.interface.d.ts +22 -8
  61. package/dist/prisma-client.interface.js +7 -0
  62. package/dist/prisma.adapter.d.ts +16 -16
  63. package/dist/prisma.adapter.js +48 -5
  64. package/dist/provider/provider-profile.d.ts +29 -13
  65. package/dist/provider/provider-profile.js +21 -0
  66. package/dist/translation/json-null.sentinel.d.ts +7 -0
  67. package/dist/translation/json-null.sentinel.js +17 -0
  68. package/dist/translation/mutation.translator.d.ts +8 -8
  69. package/dist/translation/mutation.translator.js +37 -30
  70. package/dist/translation/operation.translator.d.ts +7 -7
  71. package/dist/translation/operation.translator.js +12 -12
  72. package/dist/translation/order-pagination.translator.d.ts +5 -5
  73. package/dist/translation/order-pagination.translator.js +16 -16
  74. package/dist/translation/projection.translator.d.ts +4 -4
  75. package/dist/translation/projection.translator.js +11 -11
  76. package/dist/translation/scalar.conversion.d.ts +9 -9
  77. package/dist/translation/scalar.conversion.js +11 -11
  78. package/dist/translation/where.translator.d.ts +5 -5
  79. package/dist/translation/where.translator.js +114 -31
  80. package/package.json +6 -6
@@ -0,0 +1,13 @@
1
+ /** What the locator found: the version, or why it has none. */
2
+ export type InstalledPrismaClientVersion = {
3
+ readonly kind: "read";
4
+ readonly version: string;
5
+ } | {
6
+ readonly kind: "unread";
7
+ readonly reason: string;
8
+ };
9
+ /**
10
+ * Reads the installed `@prisma/client`'s version, resolved as described above.
11
+ * Never throws: a version it cannot read is answered `unread` with the reason.
12
+ */
13
+ export declare function locateInstalledPrismaClientVersion(): InstalledPrismaClientVersion;
@@ -0,0 +1,43 @@
1
+ const MANIFEST = "@prisma/client/package.json";
2
+ function resolutionBases(process) {
3
+ const bases = [];
4
+ try {
5
+ if (typeof import.meta.url === "string") {
6
+ bases.push(import.meta.url);
7
+ }
8
+ }
9
+ catch {
10
+ }
11
+ const cwd = process?.cwd?.();
12
+ if (typeof cwd === "string") {
13
+ bases.push(`${cwd.replace(/[\\/]+$/, "")}/package.json`);
14
+ }
15
+ return bases;
16
+ }
17
+ export function locateInstalledPrismaClientVersion() {
18
+ const process = globalThis.process;
19
+ const moduleApi = process?.getBuiltinModule?.("node:module");
20
+ if (typeof moduleApi?.createRequire !== "function") {
21
+ return {
22
+ kind: "unread",
23
+ reason: "this runtime has no Node module loader to resolve it with",
24
+ };
25
+ }
26
+ const tried = [];
27
+ for (const base of resolutionBases(process)) {
28
+ try {
29
+ const manifest = moduleApi.createRequire(base)(MANIFEST);
30
+ if (typeof manifest.version === "string") {
31
+ return { kind: "read", version: manifest.version };
32
+ }
33
+ tried.push(`${base} (its package.json states no version)`);
34
+ }
35
+ catch {
36
+ tried.push(base);
37
+ }
38
+ }
39
+ return {
40
+ kind: "unread",
41
+ reason: `\`${MANIFEST}\` does not resolve from ${tried.length === 0 ? "anywhere this runtime names" : tried.join(" or ")}`,
42
+ };
43
+ }
@@ -1,15 +1,18 @@
1
- import type { TransactionCapability } from "@aventara/core";
1
+ import type { AvTransactionCapability } from "@aventara/core";
2
2
  import type { PrismaComposedArtifact, PrismaModelComposer } from "../generate/prisma.generate.js";
3
+ import type { PrismaFilterModeFacts } from "../provider/provider-profile.js";
3
4
  import type { PrismaCapabilitySurface } from "./capability-surface.interface.js";
4
5
  import type { PrismaSchemaFacts } from "./schema-facts.interface.js";
5
6
  /** Thrown when the schema cannot be composed into a model; lists every problem. */
6
- export declare class PrismaModelCompositionError extends Error {
7
- readonly name = "PrismaModelCompositionError";
7
+ export declare class AvPrismaModelCompositionError extends Error {
8
+ readonly name = "AvPrismaModelCompositionError";
8
9
  readonly diagnostics: readonly string[];
9
10
  constructor(diagnostics: readonly string[]);
10
11
  }
11
12
  export type PrismaModelCompositionOptions = {
12
- readonly transactions: TransactionCapability;
13
+ readonly transactions: AvTransactionCapability;
14
+ /** The `mode`s the engine's comparisons honour (`provider-profile.ts`). */
15
+ readonly filterModes: PrismaFilterModeFacts;
13
16
  };
14
17
  export type PrismaModelDiscoveryInput = PrismaModelCompositionOptions & {
15
18
  /** PSL — what the schema says. */
@@ -4,12 +4,12 @@ import { mapPrismaEnum } from "./enum.mapper.js";
4
4
  import { crossCheckCreateOptional, projectPrismaField, } from "./field.mapper.js";
5
5
  import { mapPrismaIdentifiers } from "./identifier.mapper.js";
6
6
  import { deriveResourceOperations } from "./operations.deriver.js";
7
- export class PrismaModelCompositionError extends Error {
8
- name = "PrismaModelCompositionError";
7
+ export class AvPrismaModelCompositionError extends Error {
8
+ name = "AvPrismaModelCompositionError";
9
9
  diagnostics;
10
10
  constructor(diagnostics) {
11
11
  super([
12
- "discovery cannot compose an AdapterModel from this schema and client:",
12
+ "discovery cannot compose an AvAdapterModel from this schema and client:",
13
13
  ...diagnostics.map((diagnostic) => ` - ${diagnostic}`),
14
14
  ].join("\n"));
15
15
  this.diagnostics = diagnostics;
@@ -42,15 +42,24 @@ export function discoverPrismaModel(input) {
42
42
  modelNames,
43
43
  admitted,
44
44
  transactions: input.transactions,
45
+ filterModes: input.filterModes,
45
46
  diagnostics,
46
47
  usedScalars,
48
+ declared,
47
49
  });
48
50
  resources[name] = composed.resource;
49
51
  translation[name] = composed.translation;
50
52
  referentialActions[name] = composed.referentialActions;
51
53
  }
52
54
  if (diagnostics.length > 0) {
53
- throw new PrismaModelCompositionError(diagnostics);
55
+ throw new AvPrismaModelCompositionError(diagnostics);
56
+ }
57
+ const requirements = composeCreateRequirements(declared, input.surface, resources);
58
+ for (const [name, stated] of Object.entries(requirements)) {
59
+ const resource = resources[name];
60
+ if (resource !== undefined) {
61
+ resources[name] = { ...resource, createRequirements: stated };
62
+ }
54
63
  }
55
64
  return {
56
65
  model: {
@@ -62,12 +71,12 @@ export function discoverPrismaModel(input) {
62
71
  },
63
72
  translation,
64
73
  referentialActions,
65
- createRequirements: composeCreateRequirements(declared, input.surface, resources),
66
74
  };
67
75
  }
68
76
  const PRISMA_REFERENCE_WRITES = "uniform";
69
77
  function composeCreateRequirements(declared, surface, resources) {
70
- const table = {};
78
+ const groups = new Map();
79
+ const required = new Map();
71
80
  for (const [name, resource] of Object.entries(resources)) {
72
81
  const model = declared.get(name);
73
82
  const exposed = surface.resources[name];
@@ -83,8 +92,8 @@ function composeCreateRequirements(declared, surface, resources) {
83
92
  !scalar.createOptional);
84
93
  })
85
94
  .map(([field]) => field));
86
- const requirements = [];
87
95
  const references = new Set();
96
+ const resourceGroups = [];
88
97
  for (const field of model.fields) {
89
98
  const shape = resource.fields[field.name];
90
99
  if (shape?.kind !== "relation") {
@@ -97,21 +106,44 @@ function composeCreateRequirements(declared, surface, resources) {
97
106
  if (exposed.relationFields[field.name]?.createRequired !== true) {
98
107
  continue;
99
108
  }
100
- if (!owned.some((scalar) => requiredScalars.has(scalar))) {
109
+ const [first, ...rest] = owned.filter((scalar) => requiredScalars.has(scalar));
110
+ if (first === undefined) {
101
111
  continue;
102
112
  }
103
- const inverse = inverseOf(declared, name, field);
104
- requirements.push({
105
- kind: "relation",
106
- relation: field.name,
107
- ...(inverse === undefined ? {} : { inverse }),
113
+ resourceGroups.push({
114
+ group: [field.name, first, ...rest],
115
+ inverse: inverseOf(declared, name, field),
108
116
  });
109
117
  }
110
- const fields = model.fields
118
+ groups.set(name, resourceGroups);
119
+ required.set(name, model.fields
111
120
  .map((field) => field.name)
112
- .filter((field) => requiredScalars.has(field) && !references.has(field))
113
- .map((field) => ({ kind: "field", field }));
114
- table[name] = [...fields, ...requirements];
121
+ .filter((field) => requiredScalars.has(field) && !references.has(field)));
122
+ }
123
+ const table = {};
124
+ for (const [name, resourceGroups] of groups) {
125
+ const [firstRequired, ...restRequired] = required.get(name) ?? [];
126
+ const [firstGroup, ...restGroups] = resourceGroups.map((entry) => entry.group);
127
+ const parentSupplies = {};
128
+ for (const { group, inverse } of resourceGroups) {
129
+ if (inverse !== undefined && resources[inverse.resource] !== undefined) {
130
+ const byRelation = parentSupplies[inverse.resource] ?? {};
131
+ byRelation[inverse.relation] = group;
132
+ parentSupplies[inverse.resource] = byRelation;
133
+ }
134
+ }
135
+ if (firstRequired === undefined && firstGroup === undefined) {
136
+ continue;
137
+ }
138
+ table[name] = {
139
+ ...(firstRequired === undefined
140
+ ? {}
141
+ : { required: [firstRequired, ...restRequired] }),
142
+ ...(firstGroup === undefined
143
+ ? {}
144
+ : { oneOf: [firstGroup, ...restGroups] }),
145
+ ...(Object.keys(parentSupplies).length === 0 ? {} : { parentSupplies }),
146
+ };
115
147
  }
116
148
  return table;
117
149
  }
@@ -185,7 +217,10 @@ function composeResource(input) {
185
217
  }
186
218
  fields[projection.name] = {
187
219
  ...projection.field,
188
- capabilities: deriveScalarCapabilities({ surface: scalarSurface }),
220
+ capabilities: deriveScalarCapabilities({
221
+ surface: scalarSurface,
222
+ filterModes: input.filterModes,
223
+ }),
189
224
  };
190
225
  projectedScalars.push({
191
226
  name: projection.name,
@@ -205,8 +240,15 @@ function composeResource(input) {
205
240
  diagnostics.push(`\`${model.name}.${field.name}\` targets \`${projection.field.target}\`, which the existence gate did not admit, so the edge would point at a Resource the model does not carry.`);
206
241
  continue;
207
242
  }
243
+ const inverse = inverseOf(input.declared, model.name, field);
244
+ const [firstReference, ...moreReferences] = field.relation?.fields ?? [];
245
+ const referenceFields = firstReference === undefined
246
+ ? undefined
247
+ : [firstReference, ...moreReferences];
208
248
  fields[projection.name] = {
209
249
  ...projection.field,
250
+ ...(inverse === undefined ? {} : { inverse: inverse.relation }),
251
+ ...(referenceFields === undefined ? {} : { referenceFields }),
210
252
  capabilities: deriveRelationCapabilities({
211
253
  surface: relationSurface,
212
254
  }),
@@ -217,7 +259,7 @@ function composeResource(input) {
217
259
  field: projection.edge.field,
218
260
  target: projection.edge.target,
219
261
  cardinality: projection.edge.cardinality,
220
- references: [...(field.relation?.fields ?? [])],
262
+ references: [...(referenceFields ?? [])],
221
263
  onDelete: projection.edge.onDelete,
222
264
  onUpdate: projection.edge.onUpdate,
223
265
  });
@@ -1,12 +1,12 @@
1
- import type { ResourceOperations, TransactionCapability } from "@aventara/core";
2
- import type { AdapterResource } from "@aventara/core/internal";
3
- import type { PrismaAdapterModel } from "./discovery-artifact.interface.js";
4
- type DiscoveredIdentifiers = AdapterResource<PrismaAdapterModel>["identifiers"];
1
+ import type { AvResourceOperations, AvTransactionCapability } from "@aventara/core";
2
+ import type { AvAdapterResource } from "@aventara/core/internal";
3
+ import type { AvPrismaAdapterModel } from "./discovery-artifact.interface.js";
4
+ type DiscoveredIdentifiers = AvAdapterResource<AvPrismaAdapterModel>["identifiers"];
5
5
  export type ResourceOperationsInput = {
6
6
  readonly operations: readonly string[];
7
7
  /** The model's usable identifiers; empty means no unique addressing exists. */
8
8
  readonly identifiers: DiscoveredIdentifiers;
9
- readonly transactions: TransactionCapability;
9
+ readonly transactions: AvTransactionCapability;
10
10
  };
11
- export declare function deriveResourceOperations(input: ResourceOperationsInput): ResourceOperations;
11
+ export declare function deriveResourceOperations(input: ResourceOperationsInput): AvResourceOperations;
12
12
  export {};
@@ -1,4 +1,4 @@
1
- import type { PrismaReferentialAction } from "./discovery-artifact.interface.js";
1
+ import type { AvPrismaReferentialAction } from "./discovery-artifact.interface.js";
2
2
  /** Where a fact — or an unhandled construct — was found. One-based lines, as `prisma validate` reports them. */
3
3
  export type PrismaSchemaSite = {
4
4
  readonly file: string;
@@ -89,7 +89,7 @@ export type PrismaSchemaRelation = {
89
89
  * state, because an absent action and the explicitly-written default are one
90
90
  * fact about what a delete does.
91
91
  */
92
- readonly onDelete: PrismaReferentialAction | null;
92
+ readonly onDelete: AvPrismaReferentialAction | null;
93
93
  /** `@relation(onUpdate: …)`, resolved the same way. Read independently of `onDelete`. */
94
- readonly onUpdate: PrismaReferentialAction | null;
94
+ readonly onUpdate: AvPrismaReferentialAction | null;
95
95
  };
@@ -3,8 +3,8 @@ export type PrismaSchemaSource = {
3
3
  readonly file: string;
4
4
  readonly text: string;
5
5
  };
6
- export declare class PrismaSchemaReaderError extends Error {
7
- readonly name = "PrismaSchemaReaderError";
6
+ export declare class AvPrismaSchemaReaderError extends Error {
7
+ readonly name = "AvPrismaSchemaReaderError";
8
8
  }
9
9
  /**
10
10
  * Reads a schema file, or a schema **folder** (Prisma 7 accepts either).
@@ -1,7 +1,7 @@
1
1
  import { readdir, readFile, stat } from "node:fs/promises";
2
2
  import path from "node:path";
3
- export class PrismaSchemaReaderError extends Error {
4
- name = "PrismaSchemaReaderError";
3
+ export class AvPrismaSchemaReaderError extends Error {
4
+ name = "AvPrismaSchemaReaderError";
5
5
  }
6
6
  const FIELD_ATTRIBUTES = new Set([
7
7
  "@id",
@@ -42,7 +42,7 @@ const BLOCK_KEYWORDS = new Set([
42
42
  ]);
43
43
  export async function readPrismaSchema(location) {
44
44
  const stats = await stat(location).catch((cause) => {
45
- throw new PrismaSchemaReaderError(`the Prisma schema at ${location} could not be read`, { cause });
45
+ throw new AvPrismaSchemaReaderError(`the Prisma schema at ${location} could not be read`, { cause });
46
46
  });
47
47
  const files = stats.isDirectory()
48
48
  ? (await readdir(location))
@@ -51,7 +51,7 @@ export async function readPrismaSchema(location) {
51
51
  .map((entry) => path.join(location, entry))
52
52
  : [location];
53
53
  if (files.length === 0) {
54
- throw new PrismaSchemaReaderError(`the Prisma schema folder at ${location} contains no .prisma file`);
54
+ throw new AvPrismaSchemaReaderError(`the Prisma schema folder at ${location} contains no .prisma file`);
55
55
  }
56
56
  const sources = [];
57
57
  for (const file of files) {
@@ -146,7 +146,7 @@ function readOneSource(source, enums, models, unhandled) {
146
146
  }
147
147
  }
148
148
  if (open !== null) {
149
- throw new PrismaSchemaReaderError(`${source.file} ends inside the block "${open.name}"`);
149
+ throw new AvPrismaSchemaReaderError(`${source.file} ends inside the block "${open.name}"`);
150
150
  }
151
151
  }
152
152
  function openBlock(line, site, record) {
@@ -5,8 +5,8 @@ export type PrismaTypesReadResult = {
5
5
  /** Every file under the client directory the reader actually opened. */
6
6
  readonly filesRead: readonly string[];
7
7
  };
8
- export declare class PrismaTypesReaderError extends Error {
9
- readonly name = "PrismaTypesReaderError";
8
+ export declare class AvPrismaTypesReaderError extends Error {
9
+ readonly name = "AvPrismaTypesReaderError";
10
10
  }
11
11
  export declare function readWrittenTypeArguments(checker: ts.TypeChecker, reference: ts.TypeReferenceNode): readonly string[];
12
12
  export declare function readPrismaCapabilitySurface(clientDirectory: string): PrismaTypesReadResult;
@@ -11,8 +11,8 @@ const NON_PAGINATION_EDGE_ARGUMENTS = new Set([
11
11
  "where",
12
12
  ]);
13
13
  const MANY_WRITE_OPERATION = /^(?:create|update|delete)Many(?:AndReturn)?$/;
14
- export class PrismaTypesReaderError extends Error {
15
- name = "PrismaTypesReaderError";
14
+ export class AvPrismaTypesReaderError extends Error {
15
+ name = "AvPrismaTypesReaderError";
16
16
  }
17
17
  export function readWrittenTypeArguments(checker, reference) {
18
18
  return (reference.typeArguments ?? []).map((argument) => checker.typeToString(checker.getTypeFromTypeNode(argument)));
@@ -21,7 +21,7 @@ export function readPrismaCapabilitySurface(clientDirectory) {
21
21
  const root = path.resolve(clientDirectory);
22
22
  const publicFiles = listPublicFiles(root);
23
23
  if (publicFiles.length === 0) {
24
- throw new PrismaTypesReaderError(`no generated Prisma client file was found under ${root}`);
24
+ throw new AvPrismaTypesReaderError(`no generated Prisma client file was found under ${root}`);
25
25
  }
26
26
  const filesRead = new Set();
27
27
  const host = createPublicOnlyHost(root, filesRead);
@@ -63,11 +63,11 @@ function createPublicOnlyHost(root, filesRead) {
63
63
  return undefined;
64
64
  }
65
65
  if (isPrivatePath(root, resolved)) {
66
- throw new PrismaTypesReaderError(`the types reader asked for ${path.relative(root, resolved)}, which is an internal file of the generated client that must not be imported`);
66
+ throw new AvPrismaTypesReaderError(`the types reader asked for ${path.relative(root, resolved)}, which is an internal file of the generated client that must not be imported`);
67
67
  }
68
68
  const text = readFileSync(resolved, "utf8");
69
69
  if (text.includes(RED_BANNER) || !text.includes(GREEN_BANNER)) {
70
- throw new PrismaTypesReaderError(`${path.relative(root, resolved)} does not carry Prisma's "${GREEN_BANNER}" banner`);
70
+ throw new AvPrismaTypesReaderError(`${path.relative(root, resolved)} does not carry Prisma's "${GREEN_BANNER}" banner`);
71
71
  }
72
72
  filesRead.add(resolved);
73
73
  return text;
@@ -100,7 +100,7 @@ function indexDeclarations(program, publicFiles) {
100
100
  for (const file of publicFiles) {
101
101
  const source = program.getSourceFile(file);
102
102
  if (source === undefined) {
103
- throw new PrismaTypesReaderError(`${file} did not enter the program`);
103
+ throw new AvPrismaTypesReaderError(`${file} did not enter the program`);
104
104
  }
105
105
  for (const statement of source.statements) {
106
106
  if (ts.isTypeAliasDeclaration(statement) ||
@@ -128,7 +128,7 @@ function projectionMembers(index, name) {
128
128
  ? written.typeArguments?.[0]
129
129
  : written;
130
130
  if (literal === undefined || !ts.isTypeLiteralNode(literal)) {
131
- throw new PrismaTypesReaderError(`${name} is declared by the generated client's types and is not a written object type, so its projection members cannot be read`);
131
+ throw new AvPrismaTypesReaderError(`${name} is declared by the generated client's types and is not a written object type, so its projection members cannot be read`);
132
132
  }
133
133
  return new Set(memberNames(literal.members.filter(ts.isPropertySignature)));
134
134
  }
@@ -197,7 +197,7 @@ function keysOfReferenced(index, node, accept) {
197
197
  }
198
198
  const members = membersOf(index, referencedName(reference));
199
199
  if (members === null) {
200
- throw new PrismaTypesReaderError(`${referencedName(reference)} is referenced by the generated client's types but declared nowhere in them`);
200
+ throw new AvPrismaTypesReaderError(`${referencedName(reference)} is referenced by the generated client's types but declared nowhere in them`);
201
201
  }
202
202
  return memberNames(members);
203
203
  }
@@ -214,7 +214,7 @@ function deleteManyTakesScalarWhere(index, node) {
214
214
  function readEnums(program, root) {
215
215
  const source = program.getSourceFile(path.join(root, "enums.ts"));
216
216
  if (source === undefined) {
217
- throw new PrismaTypesReaderError(`enums.ts is absent from ${root}`);
217
+ throw new AvPrismaTypesReaderError(`enums.ts is absent from ${root}`);
218
218
  }
219
219
  const enums = {};
220
220
  for (const statement of source.statements) {
@@ -252,11 +252,11 @@ function readResources(checker, index) {
252
252
  function readResource(checker, index, model) {
253
253
  const payload = membersOf(index, `$${model}Payload`);
254
254
  if (payload === null) {
255
- throw new PrismaTypesReaderError(`$${model}Payload has no written members`);
255
+ throw new AvPrismaTypesReaderError(`$${model}Payload has no written members`);
256
256
  }
257
257
  const declaredName = payloadName(checker, payload);
258
258
  if (declaredName !== model) {
259
- throw new PrismaTypesReaderError(`$${model}Payload's own name literal is ${declaredName}`);
259
+ throw new AvPrismaTypesReaderError(`$${model}Payload's own name literal is ${declaredName}`);
260
260
  }
261
261
  const where = membersOf(index, `${model}WhereInput`) ?? [];
262
262
  const create = membersOf(index, `${model}CreateInput`) ?? [];
@@ -279,7 +279,7 @@ function readResource(checker, index, model) {
279
279
  function payloadName(checker, payload) {
280
280
  const member = payload.find((m) => memberName(m) === "name");
281
281
  if (member?.type === undefined) {
282
- throw new PrismaTypesReaderError("a payload carries no `name` member");
282
+ throw new AvPrismaTypesReaderError("a payload carries no `name` member");
283
283
  }
284
284
  return unquote(checker.typeToString(checker.getTypeFromTypeNode(member.type)));
285
285
  }
@@ -291,7 +291,7 @@ function readScalarFields(checker, index, model, payload, where, uncheckedCreate
291
291
  ? written.typeArguments?.[0]
292
292
  : undefined;
293
293
  if (literal === undefined || !ts.isTypeLiteralNode(literal)) {
294
- throw new PrismaTypesReaderError(`$${model}Payload.scalars is not a written object type`);
294
+ throw new AvPrismaTypesReaderError(`$${model}Payload.scalars is not a written object type`);
295
295
  }
296
296
  const names = [
297
297
  ...new Set([
@@ -303,7 +303,7 @@ function readScalarFields(checker, index, model, payload, where, uncheckedCreate
303
303
  for (const name of names) {
304
304
  const token = tokens.get(name);
305
305
  if (token === undefined) {
306
- throw new PrismaTypesReaderError(`${model}.${name} is a payload scalar with no ${model}FieldRefs entry`);
306
+ throw new AvPrismaTypesReaderError(`${model}.${name} is a payload scalar with no ${model}FieldRefs entry`);
307
307
  }
308
308
  const filter = findReference(where.get(name)?.type, (n) => n.endsWith("Filter"));
309
309
  const filterMembers = filter === null ? [] : (membersOf(index, referencedName(filter)) ?? []);
@@ -335,25 +335,25 @@ function readMutationOperations(index, model, stage, field, member) {
335
335
  }
336
336
  const members = membersOf(index, referencedName(reference));
337
337
  if (members === null) {
338
- throw new PrismaTypesReaderError(`${referencedName(reference)} is referenced by ${model}Unchecked${stage}Input.${field} and declared nowhere in the generated client's types`);
338
+ throw new AvPrismaTypesReaderError(`${referencedName(reference)} is referenced by ${model}Unchecked${stage}Input.${field} and declared nowhere in the generated client's types`);
339
339
  }
340
340
  return memberNames(members);
341
341
  }
342
342
  function readFieldRefTokens(checker, index, model) {
343
343
  const members = membersOf(index, `${model}FieldRefs`);
344
344
  if (members === null) {
345
- throw new PrismaTypesReaderError(`${model}FieldRefs is absent`);
345
+ throw new AvPrismaTypesReaderError(`${model}FieldRefs is absent`);
346
346
  }
347
347
  const tokens = new Map();
348
348
  for (const member of members) {
349
349
  const reference = findReference(member.type, (n) => n === "FieldRef");
350
350
  if (reference === null) {
351
- throw new PrismaTypesReaderError(`${model}FieldRefs.${memberName(member)} is not a FieldRef`);
351
+ throw new AvPrismaTypesReaderError(`${model}FieldRefs.${memberName(member)} is not a FieldRef`);
352
352
  }
353
353
  const written = readWrittenTypeArguments(checker, reference);
354
354
  const token = written[1];
355
355
  if (token === undefined) {
356
- throw new PrismaTypesReaderError(`${model}FieldRefs.${memberName(member)} carries no scalar token`);
356
+ throw new AvPrismaTypesReaderError(`${model}FieldRefs.${memberName(member)} carries no scalar token`);
357
357
  }
358
358
  tokens.set(memberName(member), unquote(token));
359
359
  }
@@ -377,11 +377,11 @@ function readRelationFields(checker, index, payload, where, create, update, incl
377
377
  part.literal.kind === ts.SyntaxKind.NullKeyword);
378
378
  const targetPayload = findReference(written, (n) => n.startsWith("$"));
379
379
  if (targetPayload === null) {
380
- throw new PrismaTypesReaderError(`a relation edge "${name}" references no payload`);
380
+ throw new AvPrismaTypesReaderError(`a relation edge "${name}" references no payload`);
381
381
  }
382
382
  const targetMembers = membersOf(index, referencedName(targetPayload));
383
383
  if (targetMembers === null) {
384
- throw new PrismaTypesReaderError(`${referencedName(targetPayload)} is declared nowhere in the generated client's types`);
384
+ throw new AvPrismaTypesReaderError(`${referencedName(targetPayload)} is declared nowhere in the generated client's types`);
385
385
  }
386
386
  const edge = findReference(include.get(name)?.type, (n) => n.endsWith("Args"));
387
387
  const edgeArguments = edge === null
@@ -427,7 +427,7 @@ function readUniqueKeys(checker, index, model) {
427
427
  function readOperations(index, model) {
428
428
  const declaration = index.get(`${model}Delegate`);
429
429
  if (declaration === undefined || !ts.isInterfaceDeclaration(declaration)) {
430
- throw new PrismaTypesReaderError(`${model}Delegate is absent`);
430
+ throw new AvPrismaTypesReaderError(`${model}Delegate is absent`);
431
431
  }
432
432
  return declaration.members
433
433
  .filter(ts.isMethodSignature)
@@ -442,7 +442,7 @@ function readManyWriteArguments(index, model, operations) {
442
442
  const capitalised = operation[0]?.toUpperCase() + operation.slice(1);
443
443
  const members = membersOf(index, `${model}${capitalised}Args`);
444
444
  if (members === null) {
445
- throw new PrismaTypesReaderError(`${model}${capitalised}Args is absent although ${model}Delegate declares ${operation}`);
445
+ throw new AvPrismaTypesReaderError(`${model}${capitalised}Args is absent although ${model}Delegate declares ${operation}`);
446
446
  }
447
447
  arguments_[operation] = memberNames(members);
448
448
  }
@@ -1,5 +1,5 @@
1
- import type { BuiltInScalar, PaginationCapability, RelationFilterCapability, RelationMutationDirective, ScalarFilterOperator, ScalarFormat, ScalarMutationDirective } from "@aventara/core";
2
- import type { AdapterLifecycleTrait } from "@aventara/core/internal";
1
+ import type { AvBuiltInScalar, AvPaginationCapability, AvRelationFilterCapability, AvRelationMutationDirective, AvScalarFilterOperator, AvScalarFormat, AvScalarMutationDirective } from "@aventara/core";
2
+ import type { AvAdapterLifecycleTrait } from "@aventara/core/internal";
3
3
  export type VocabularySource = "PSL" | "TYPE" | "RUN" | "DRIVER" | "CFG";
4
4
  export type VocabularyEntry = {
5
5
  readonly fact: string;
@@ -15,8 +15,8 @@ export type PrismaDiscoveryDiagnostic = {
15
15
  readonly message: string;
16
16
  };
17
17
  export type PrismaScalarMapping = {
18
- readonly scalar: BuiltInScalar;
19
- readonly format?: ScalarFormat;
18
+ readonly scalar: AvBuiltInScalar;
19
+ readonly format?: AvScalarFormat;
20
20
  };
21
21
  export type PrismaScalarTable = Readonly<Record<string, PrismaScalarMapping>>;
22
22
  /** Total and 1:1 over `BUILT_IN_SCALARS` **[CORE]**. */
@@ -25,7 +25,7 @@ export declare const PRISMA_SCALAR_TABLE: PrismaScalarTable;
25
25
  * The only `@db.*` spellings that **prove** a format, matched by exact written
26
26
  * spelling and never parsed.
27
27
  */
28
- export declare const PRISMA_NATIVE_FORMATS: Readonly<Record<string, ScalarFormat>>;
28
+ export declare const PRISMA_NATIVE_FORMATS: Readonly<Record<string, AvScalarFormat>>;
29
29
  export type PrismaEvidence = "RUN8" | "UNVERIFIED";
30
30
  export type PrismaDefaultRow = {
31
31
  /**
@@ -38,7 +38,7 @@ export type PrismaDefaultRow = {
38
38
  } | {
39
39
  readonly pattern: RegExp;
40
40
  };
41
- readonly traits: readonly AdapterLifecycleTrait[];
41
+ readonly traits: readonly AvAdapterLifecycleTrait[];
42
42
  readonly evidence: PrismaEvidence;
43
43
  };
44
44
  export declare const PRISMA_DEFAULT_TABLE: readonly PrismaDefaultRow[];
@@ -49,28 +49,28 @@ export declare const PRISMA_DEFAULT_TABLE: readonly PrismaDefaultRow[];
49
49
  * function is a build stop rather than a column Aventara quietly thinks the
50
50
  * client must supply.
51
51
  */
52
- export declare const PRISMA_UNMATCHED_DEFAULT_TRAITS: readonly AdapterLifecycleTrait[];
52
+ export declare const PRISMA_UNMATCHED_DEFAULT_TRAITS: readonly AvAdapterLifecycleTrait[];
53
53
  /**
54
54
  * The dictionary's other half: the point at which Prisma's spelling stops and
55
55
  * Aventara's begins.
56
56
  */
57
57
  /** `<Kind>Filter` / `<Kind>NullableFilter` / `Json[Nullable]Filter` keys. */
58
- export declare const PRISMA_FILTER_OPERATORS: Readonly<Record<string, ScalarFilterOperator>>;
58
+ export declare const PRISMA_FILTER_OPERATORS: Readonly<Record<string, AvScalarFilterOperator>>;
59
59
  /** `[Nullable]ScalarRelationFilter` and `ListRelationFilter` keys. */
60
- export declare const PRISMA_RELATION_FILTERS: Readonly<Record<string, RelationFilterCapability>>;
60
+ export declare const PRISMA_RELATION_FILTERS: Readonly<Record<string, AvRelationFilterCapability>>;
61
61
  /** `<Kind>FieldUpdateOperationsInput` and `<M><Stage><field>Input` keys. */
62
- export declare const PRISMA_SCALAR_DIRECTIVES: Readonly<Record<string, ScalarMutationDirective | null>>;
62
+ export declare const PRISMA_SCALAR_DIRECTIVES: Readonly<Record<string, AvScalarMutationDirective | null>>;
63
63
  /**
64
64
  * `<M>Update<edge>Without<M>NestedInput` / `<M>Create<edge>…NestedInput` keys.
65
65
  *
66
66
  * `createMany`, `updateMany` and `deleteMany` are `null`: they are nested BULK
67
- * writes, and `RelationMutationDirective` models per-row intent only **[CORE]**.
67
+ * writes, and `AvRelationMutationDirective` models per-row intent only **[CORE]**.
68
68
  * Aventara expresses the same effect by addressing the target Resource, so
69
69
  * advertising them would promise an argument no directive could carry.
70
70
  */
71
- export declare const PRISMA_RELATION_DIRECTIVES: Readonly<Record<string, RelationMutationDirective | null>>;
71
+ export declare const PRISMA_RELATION_DIRECTIVES: Readonly<Record<string, AvRelationMutationDirective | null>>;
72
72
  /**
73
- * `<M>$<edge>Args` keys, valued in `PaginationCapability`.
73
+ * `<M>$<edge>Args` keys, valued in `AvPaginationCapability`.
74
74
  *
75
75
  * `null` means the argument is read for something else, or for nothing:
76
76
  * `orderBy` answers `order`, `where` answers the `nested` filter capability,
@@ -78,7 +78,7 @@ export declare const PRISMA_RELATION_DIRECTIVES: Readonly<Record<string, Relatio
78
78
  * Aventara has no word for. The table is total over the keys both clients write,
79
79
  * so a new edge argument at 7.11 is an unrecognised key rather than a silent drop.
80
80
  */
81
- export declare const PRISMA_EDGE_ARGUMENTS: Readonly<Record<string, PaginationCapability | null>>;
81
+ export declare const PRISMA_EDGE_ARGUMENTS: Readonly<Record<string, AvPaginationCapability | null>>;
82
82
  /** `_count` on `<M>Include` / `<M>CountOutputType`. */
83
83
  export declare const PRISMA_REDUCERS: Readonly<Record<string, "$count">>;
84
84
  export type ObservedValueShape = {
@@ -67,7 +67,7 @@ export const VOCABULARY = [
67
67
  {
68
68
  fact: "COMPUTED_* / VIRTUAL",
69
69
  sources: ["CFG"],
70
- rule: "Outside `AdapterLifecycleTrait` by construction [CORE]; the adapter cannot emit them.",
70
+ rule: "Outside `AvAdapterLifecycleTrait` by construction [CORE]; the adapter cannot emit them.",
71
71
  },
72
72
  ];
73
73
  export const PRISMA_SCALAR_TABLE = {
@@ -0,0 +1,25 @@
1
+ import type { AvAdapterModel } from "@aventara/core";
2
+ /** A relation's other end, as seen from the record written through the relation. */
3
+ export type PrismaBackReference = {
4
+ /** The target's relation field that points back at the record it was written from. */
5
+ readonly relation: string;
6
+ /** The target's scalar fields holding that relation's reference, when the target owns it. */
7
+ readonly references: readonly string[];
8
+ };
9
+ /** By Resource, then by relation field: the back-reference a record written through it cannot write. */
10
+ export type PrismaBackReferenceTable = Readonly<Record<string, Readonly<Record<string, PrismaBackReference>>>>;
11
+ /** A path inside an operation's arguments. */
12
+ export type PrismaArgumentPath = readonly (string | number)[];
13
+ /**
14
+ * Pairs every relation field with its other end, once, at construction: the
15
+ * model's own `inverse` (the generate step pairs each relation from the schema,
16
+ * by relation name), and that end's `referenceFields`. A relation the model
17
+ * states no `inverse` for is left out, and its refusal stays `A3001`.
18
+ */
19
+ export declare function derivePrismaBackReferences(model: AvAdapterModel): PrismaBackReferenceTable;
20
+ /**
21
+ * Where the caller's write names a relation's other end (or its reference
22
+ * fields) inside a record written through that relation, as a path in the
23
+ * arguments; `undefined` when it does not. The first such place, in key order.
24
+ */
25
+ export declare function locateBackReferenceWrite(table: PrismaBackReferenceTable, model: AvAdapterModel, resource: string, args: unknown): PrismaArgumentPath | undefined;