@prisma-next/sql-contract-psl 0.0.1 → 0.3.0-dev.113
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/LICENSE +201 -0
- package/README.md +34 -8
- package/dist/default-function-registry-DUMRIhJH.d.mts +71 -0
- package/dist/default-function-registry-DUMRIhJH.d.mts.map +1 -0
- package/dist/index.d.mts +11 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/interpreter-D7gLmaHz.mjs +1412 -0
- package/dist/interpreter-D7gLmaHz.mjs.map +1 -0
- package/dist/provider.d.mts +10 -11
- package/dist/provider.d.mts.map +1 -1
- package/dist/provider.mjs +18 -12
- package/dist/provider.mjs.map +1 -1
- package/package.json +23 -23
- package/src/default-function-registry.ts +262 -0
- package/src/exports/index.ts +8 -0
- package/src/interpreter.ts +1055 -102
- package/src/provider.ts +34 -21
- package/dist/interpreter-_6-Xk1_m.mjs +0 -661
- package/dist/interpreter-_6-Xk1_m.mjs.map +0 -1
package/src/provider.ts
CHANGED
|
@@ -1,33 +1,32 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
|
-
import type { ContractConfig } from '@prisma-next/config/config-types';
|
|
2
|
+
import type { ContractConfig, ContractSourceContext } from '@prisma-next/config/config-types';
|
|
3
3
|
import type { TargetPackRef } from '@prisma-next/contract/framework-components';
|
|
4
4
|
import { parsePslDocument } from '@prisma-next/psl-parser';
|
|
5
5
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
6
|
-
import { notOk } from '@prisma-next/utils/result';
|
|
6
|
+
import { notOk, ok } from '@prisma-next/utils/result';
|
|
7
7
|
import { resolve } from 'pathe';
|
|
8
|
+
import type { ControlMutationDefaults } from './default-function-registry';
|
|
8
9
|
import { interpretPslDocumentToSqlContractIR } from './interpreter';
|
|
9
10
|
|
|
10
11
|
export interface PrismaContractOptions {
|
|
11
12
|
readonly output?: string;
|
|
12
|
-
readonly target
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
readonly target: TargetPackRef<'sql', 'postgres'>;
|
|
14
|
+
readonly scalarTypeDescriptors: ReadonlyMap<
|
|
15
|
+
string,
|
|
16
|
+
{
|
|
17
|
+
readonly codecId: string;
|
|
18
|
+
readonly nativeType: string;
|
|
19
|
+
readonly typeRef?: string;
|
|
20
|
+
readonly typeParams?: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
>;
|
|
23
|
+
readonly controlMutationDefaults?: ControlMutationDefaults;
|
|
22
24
|
readonly composedExtensionPacks?: readonly string[];
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
export function prismaContract(
|
|
26
|
-
schemaPath: string,
|
|
27
|
-
options?: PrismaContractOptions,
|
|
28
|
-
): ContractConfig {
|
|
27
|
+
export function prismaContract(schemaPath: string, options: PrismaContractOptions): ContractConfig {
|
|
29
28
|
return {
|
|
30
|
-
source: async () => {
|
|
29
|
+
source: async (context: ContractSourceContext) => {
|
|
31
30
|
const absoluteSchemaPath = resolve(schemaPath);
|
|
32
31
|
let schema: string;
|
|
33
32
|
try {
|
|
@@ -51,13 +50,27 @@ export function prismaContract(
|
|
|
51
50
|
schema,
|
|
52
51
|
sourceId: schemaPath,
|
|
53
52
|
});
|
|
53
|
+
const composedExtensionPacks = [
|
|
54
|
+
...(context.composedExtensionPacks ?? []),
|
|
55
|
+
...(options.composedExtensionPacks ?? []),
|
|
56
|
+
];
|
|
54
57
|
|
|
55
|
-
|
|
58
|
+
const interpreted = interpretPslDocumentToSqlContractIR({
|
|
56
59
|
document,
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
target: options.target,
|
|
61
|
+
scalarTypeDescriptors: options.scalarTypeDescriptors,
|
|
62
|
+
...ifDefined(
|
|
63
|
+
'composedExtensionPacks',
|
|
64
|
+
composedExtensionPacks.length > 0 ? composedExtensionPacks : undefined,
|
|
65
|
+
),
|
|
66
|
+
...ifDefined('controlMutationDefaults', options.controlMutationDefaults),
|
|
59
67
|
});
|
|
68
|
+
if (!interpreted.ok) {
|
|
69
|
+
return interpreted;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return ok(interpreted.value);
|
|
60
73
|
},
|
|
61
|
-
...ifDefined('output', options
|
|
74
|
+
...ifDefined('output', options.output),
|
|
62
75
|
};
|
|
63
76
|
}
|