@prisma-next/sql-contract-psl 0.4.0-dev.9 → 0.4.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/dist/provider.d.mts.map +1 -1
- package/dist/provider.mjs +39 -36
- package/dist/provider.mjs.map +1 -1
- package/package.json +10 -10
- package/src/provider.ts +59 -50
package/dist/provider.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.mts","names":[],"sources":["../src/provider.ts"],"sourcesContent":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"provider.d.mts","names":[],"sources":["../src/provider.ts"],"sourcesContent":[],"mappings":";;;;UAUiB,qBAAA;;EAAA,SAAA,MAAA,EAEE,aAFmB,CAAA,KAEnB,EAAA,UAAA,CAAA;EAmBH,SAAA,yBAA4C,CAAA,EAAA,SAlBZ,gBAkBoC,CAAA,KAAc,EAAA,UAAA,CAAA,EAAA;;iBAAlF,cAAA,8BAA4C,wBAAwB"}
|
package/dist/provider.mjs
CHANGED
|
@@ -3,7 +3,6 @@ import { ifDefined } from "@prisma-next/utils/defined";
|
|
|
3
3
|
import { notOk, ok } from "@prisma-next/utils/result";
|
|
4
4
|
import { parsePslDocument } from "@prisma-next/psl-parser";
|
|
5
5
|
import { readFile } from "node:fs/promises";
|
|
6
|
-
import { resolve } from "pathe";
|
|
7
6
|
|
|
8
7
|
//#region src/provider.ts
|
|
9
8
|
function buildColumnDescriptorMap(scalarTypeDescriptors, codecLookup) {
|
|
@@ -22,43 +21,47 @@ function buildColumnDescriptorMap(scalarTypeDescriptors, codecLookup) {
|
|
|
22
21
|
}
|
|
23
22
|
function prismaContract(schemaPath, options) {
|
|
24
23
|
return {
|
|
25
|
-
source:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
24
|
+
source: {
|
|
25
|
+
inputs: [schemaPath],
|
|
26
|
+
load: async (context) => {
|
|
27
|
+
const [absoluteSchemaPath] = context.resolvedInputs;
|
|
28
|
+
if (absoluteSchemaPath === void 0) throw new Error("prismaContract: context.resolvedInputs is empty. The CLI config loader should populate it positional-matched with source.inputs.");
|
|
29
|
+
let schema;
|
|
30
|
+
try {
|
|
31
|
+
schema = await readFile(absoluteSchemaPath, "utf-8");
|
|
32
|
+
} catch (error) {
|
|
33
|
+
const message = String(error);
|
|
34
|
+
return notOk({
|
|
35
|
+
summary: `Failed to read Prisma schema at "${schemaPath}"`,
|
|
36
|
+
diagnostics: [{
|
|
37
|
+
code: "PSL_SCHEMA_READ_FAILED",
|
|
38
|
+
message,
|
|
39
|
+
sourceId: schemaPath
|
|
40
|
+
}],
|
|
41
|
+
meta: {
|
|
42
|
+
schemaPath,
|
|
43
|
+
absoluteSchemaPath,
|
|
44
|
+
cause: message
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
const document = parsePslDocument({
|
|
49
|
+
schema,
|
|
50
|
+
sourceId: schemaPath
|
|
44
51
|
});
|
|
52
|
+
const scalarTypeDescriptors = buildColumnDescriptorMap(context.scalarTypeDescriptors, context.codecLookup);
|
|
53
|
+
const interpreted = interpretPslDocumentToSqlContract({
|
|
54
|
+
document,
|
|
55
|
+
target: options.target,
|
|
56
|
+
authoringContributions: context.authoringContributions,
|
|
57
|
+
scalarTypeDescriptors,
|
|
58
|
+
...ifDefined("composedExtensionPacks", context.composedExtensionPacks.length > 0 ? [...context.composedExtensionPacks] : void 0),
|
|
59
|
+
...ifDefined("composedExtensionPackRefs", options.composedExtensionPackRefs?.length ? options.composedExtensionPackRefs : void 0),
|
|
60
|
+
controlMutationDefaults: context.controlMutationDefaults
|
|
61
|
+
});
|
|
62
|
+
if (!interpreted.ok) return interpreted;
|
|
63
|
+
return ok(interpreted.value);
|
|
45
64
|
}
|
|
46
|
-
const document = parsePslDocument({
|
|
47
|
-
schema,
|
|
48
|
-
sourceId: schemaPath
|
|
49
|
-
});
|
|
50
|
-
const scalarTypeDescriptors = buildColumnDescriptorMap(context.scalarTypeDescriptors, context.codecLookup);
|
|
51
|
-
const interpreted = interpretPslDocumentToSqlContract({
|
|
52
|
-
document,
|
|
53
|
-
target: options.target,
|
|
54
|
-
authoringContributions: context.authoringContributions,
|
|
55
|
-
scalarTypeDescriptors,
|
|
56
|
-
...ifDefined("composedExtensionPacks", context.composedExtensionPacks.length > 0 ? [...context.composedExtensionPacks] : void 0),
|
|
57
|
-
...ifDefined("composedExtensionPackRefs", options.composedExtensionPackRefs?.length ? options.composedExtensionPackRefs : void 0),
|
|
58
|
-
controlMutationDefaults: context.controlMutationDefaults
|
|
59
|
-
});
|
|
60
|
-
if (!interpreted.ok) return interpreted;
|
|
61
|
-
return ok(interpreted.value);
|
|
62
65
|
},
|
|
63
66
|
...ifDefined("output", options.output)
|
|
64
67
|
};
|
package/dist/provider.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.mjs","names":["schema: string"],"sources":["../src/provider.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport type { ContractConfig
|
|
1
|
+
{"version":3,"file":"provider.mjs","names":["schema: string"],"sources":["../src/provider.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport type { ContractConfig } from '@prisma-next/config/config-types';\nimport type { CodecLookup } from '@prisma-next/framework-components/codec';\nimport type { ExtensionPackRef, TargetPackRef } from '@prisma-next/framework-components/components';\nimport { parsePslDocument } from '@prisma-next/psl-parser';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { notOk, ok } from '@prisma-next/utils/result';\nimport { interpretPslDocumentToSqlContract } from './interpreter';\nimport type { ColumnDescriptor } from './psl-column-resolution';\n\nexport interface PrismaContractOptions {\n readonly output?: string;\n readonly target: TargetPackRef<'sql', 'postgres'>;\n readonly composedExtensionPackRefs?: readonly ExtensionPackRef<'sql', 'postgres'>[];\n}\n\nfunction buildColumnDescriptorMap(\n scalarTypeDescriptors: ReadonlyMap<string, string>,\n codecLookup: CodecLookup,\n): ReadonlyMap<string, ColumnDescriptor> {\n const result = new Map<string, ColumnDescriptor>();\n for (const [typeName, codecId] of scalarTypeDescriptors) {\n const codec = codecLookup.get(codecId);\n if (!codec) continue;\n const nativeType = codec.targetTypes[0];\n if (nativeType === undefined) continue;\n result.set(typeName, { codecId, nativeType });\n }\n return result;\n}\n\nexport function prismaContract(schemaPath: string, options: PrismaContractOptions): ContractConfig {\n return {\n source: {\n inputs: [schemaPath],\n load: async (context) => {\n const [absoluteSchemaPath] = context.resolvedInputs;\n if (absoluteSchemaPath === undefined) {\n throw new Error(\n 'prismaContract: context.resolvedInputs is empty. The CLI config loader should populate it positional-matched with source.inputs.',\n );\n }\n let schema: string;\n try {\n schema = await readFile(absoluteSchemaPath, 'utf-8');\n } catch (error) {\n const message = String(error);\n return notOk({\n summary: `Failed to read Prisma schema at \"${schemaPath}\"`,\n diagnostics: [\n {\n code: 'PSL_SCHEMA_READ_FAILED',\n message,\n sourceId: schemaPath,\n },\n ],\n meta: { schemaPath, absoluteSchemaPath, cause: message },\n });\n }\n\n const document = parsePslDocument({\n schema,\n sourceId: schemaPath,\n });\n\n const scalarTypeDescriptors = buildColumnDescriptorMap(\n context.scalarTypeDescriptors,\n context.codecLookup,\n );\n\n const interpreted = interpretPslDocumentToSqlContract({\n document,\n target: options.target,\n authoringContributions: context.authoringContributions,\n scalarTypeDescriptors,\n ...ifDefined(\n 'composedExtensionPacks',\n context.composedExtensionPacks.length > 0\n ? [...context.composedExtensionPacks]\n : undefined,\n ),\n ...ifDefined(\n 'composedExtensionPackRefs',\n options.composedExtensionPackRefs?.length\n ? options.composedExtensionPackRefs\n : undefined,\n ),\n controlMutationDefaults: context.controlMutationDefaults,\n });\n if (!interpreted.ok) {\n return interpreted;\n }\n\n return ok(interpreted.value);\n },\n },\n ...ifDefined('output', options.output),\n };\n}\n"],"mappings":";;;;;;;AAgBA,SAAS,yBACP,uBACA,aACuC;CACvC,MAAM,yBAAS,IAAI,KAA+B;AAClD,MAAK,MAAM,CAAC,UAAU,YAAY,uBAAuB;EACvD,MAAM,QAAQ,YAAY,IAAI,QAAQ;AACtC,MAAI,CAAC,MAAO;EACZ,MAAM,aAAa,MAAM,YAAY;AACrC,MAAI,eAAe,OAAW;AAC9B,SAAO,IAAI,UAAU;GAAE;GAAS;GAAY,CAAC;;AAE/C,QAAO;;AAGT,SAAgB,eAAe,YAAoB,SAAgD;AACjG,QAAO;EACL,QAAQ;GACN,QAAQ,CAAC,WAAW;GACpB,MAAM,OAAO,YAAY;IACvB,MAAM,CAAC,sBAAsB,QAAQ;AACrC,QAAI,uBAAuB,OACzB,OAAM,IAAI,MACR,mIACD;IAEH,IAAIA;AACJ,QAAI;AACF,cAAS,MAAM,SAAS,oBAAoB,QAAQ;aAC7C,OAAO;KACd,MAAM,UAAU,OAAO,MAAM;AAC7B,YAAO,MAAM;MACX,SAAS,oCAAoC,WAAW;MACxD,aAAa,CACX;OACE,MAAM;OACN;OACA,UAAU;OACX,CACF;MACD,MAAM;OAAE;OAAY;OAAoB,OAAO;OAAS;MACzD,CAAC;;IAGJ,MAAM,WAAW,iBAAiB;KAChC;KACA,UAAU;KACX,CAAC;IAEF,MAAM,wBAAwB,yBAC5B,QAAQ,uBACR,QAAQ,YACT;IAED,MAAM,cAAc,kCAAkC;KACpD;KACA,QAAQ,QAAQ;KAChB,wBAAwB,QAAQ;KAChC;KACA,GAAG,UACD,0BACA,QAAQ,uBAAuB,SAAS,IACpC,CAAC,GAAG,QAAQ,uBAAuB,GACnC,OACL;KACD,GAAG,UACD,6BACA,QAAQ,2BAA2B,SAC/B,QAAQ,4BACR,OACL;KACD,yBAAyB,QAAQ;KAClC,CAAC;AACF,QAAI,CAAC,YAAY,GACf,QAAO;AAGT,WAAO,GAAG,YAAY,MAAM;;GAE/B;EACD,GAAG,UAAU,UAAU,QAAQ,OAAO;EACvC"}
|
package/package.json
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/sql-contract-psl",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "PSL-to-SQL ContractIR interpreter for Prisma Next",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"pathe": "^2.0.3",
|
|
9
|
-
"@prisma-next/config": "0.4.
|
|
10
|
-
"@prisma-next/contract": "0.4.
|
|
11
|
-
"@prisma-next/framework-components": "0.4.
|
|
12
|
-
"@prisma-next/
|
|
13
|
-
"@prisma-next/sql-contract
|
|
14
|
-
"@prisma-next/
|
|
15
|
-
"@prisma-next/
|
|
9
|
+
"@prisma-next/config": "0.4.2",
|
|
10
|
+
"@prisma-next/contract": "0.4.2",
|
|
11
|
+
"@prisma-next/framework-components": "0.4.2",
|
|
12
|
+
"@prisma-next/psl-parser": "0.4.2",
|
|
13
|
+
"@prisma-next/sql-contract": "0.4.2",
|
|
14
|
+
"@prisma-next/sql-contract-ts": "0.4.2",
|
|
15
|
+
"@prisma-next/utils": "0.4.2"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"tsdown": "0.18.4",
|
|
19
19
|
"typescript": "5.9.3",
|
|
20
20
|
"vitest": "4.0.17",
|
|
21
21
|
"@prisma-next/test-utils": "0.0.1",
|
|
22
|
+
"@prisma-next/tsdown": "0.0.0",
|
|
22
23
|
"@prisma-next/tsconfig": "0.0.0",
|
|
23
|
-
"@prisma-next/contract-authoring": "0.4.
|
|
24
|
-
"@prisma-next/tsdown": "0.0.0"
|
|
24
|
+
"@prisma-next/contract-authoring": "0.4.2"
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
27
|
"dist",
|
package/src/provider.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
|
-
import type { ContractConfig
|
|
2
|
+
import type { ContractConfig } from '@prisma-next/config/config-types';
|
|
3
3
|
import type { CodecLookup } from '@prisma-next/framework-components/codec';
|
|
4
4
|
import type { ExtensionPackRef, TargetPackRef } from '@prisma-next/framework-components/components';
|
|
5
5
|
import { parsePslDocument } from '@prisma-next/psl-parser';
|
|
6
6
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
7
7
|
import { notOk, ok } from '@prisma-next/utils/result';
|
|
8
|
-
import { resolve } from 'pathe';
|
|
9
8
|
import { interpretPslDocumentToSqlContract } from './interpreter';
|
|
10
9
|
import type { ColumnDescriptor } from './psl-column-resolution';
|
|
11
10
|
|
|
@@ -32,58 +31,68 @@ function buildColumnDescriptorMap(
|
|
|
32
31
|
|
|
33
32
|
export function prismaContract(schemaPath: string, options: PrismaContractOptions): ContractConfig {
|
|
34
33
|
return {
|
|
35
|
-
source:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
34
|
+
source: {
|
|
35
|
+
inputs: [schemaPath],
|
|
36
|
+
load: async (context) => {
|
|
37
|
+
const [absoluteSchemaPath] = context.resolvedInputs;
|
|
38
|
+
if (absoluteSchemaPath === undefined) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
'prismaContract: context.resolvedInputs is empty. The CLI config loader should populate it positional-matched with source.inputs.',
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
let schema: string;
|
|
44
|
+
try {
|
|
45
|
+
schema = await readFile(absoluteSchemaPath, 'utf-8');
|
|
46
|
+
} catch (error) {
|
|
47
|
+
const message = String(error);
|
|
48
|
+
return notOk({
|
|
49
|
+
summary: `Failed to read Prisma schema at "${schemaPath}"`,
|
|
50
|
+
diagnostics: [
|
|
51
|
+
{
|
|
52
|
+
code: 'PSL_SCHEMA_READ_FAILED',
|
|
53
|
+
message,
|
|
54
|
+
sourceId: schemaPath,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
meta: { schemaPath, absoluteSchemaPath, cause: message },
|
|
58
|
+
});
|
|
59
|
+
}
|
|
54
60
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
const document = parsePslDocument({
|
|
62
|
+
schema,
|
|
63
|
+
sourceId: schemaPath,
|
|
64
|
+
});
|
|
59
65
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
const scalarTypeDescriptors = buildColumnDescriptorMap(
|
|
67
|
+
context.scalarTypeDescriptors,
|
|
68
|
+
context.codecLookup,
|
|
69
|
+
);
|
|
64
70
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
71
|
+
const interpreted = interpretPslDocumentToSqlContract({
|
|
72
|
+
document,
|
|
73
|
+
target: options.target,
|
|
74
|
+
authoringContributions: context.authoringContributions,
|
|
75
|
+
scalarTypeDescriptors,
|
|
76
|
+
...ifDefined(
|
|
77
|
+
'composedExtensionPacks',
|
|
78
|
+
context.composedExtensionPacks.length > 0
|
|
79
|
+
? [...context.composedExtensionPacks]
|
|
80
|
+
: undefined,
|
|
81
|
+
),
|
|
82
|
+
...ifDefined(
|
|
83
|
+
'composedExtensionPackRefs',
|
|
84
|
+
options.composedExtensionPackRefs?.length
|
|
85
|
+
? options.composedExtensionPackRefs
|
|
86
|
+
: undefined,
|
|
87
|
+
),
|
|
88
|
+
controlMutationDefaults: context.controlMutationDefaults,
|
|
89
|
+
});
|
|
90
|
+
if (!interpreted.ok) {
|
|
91
|
+
return interpreted;
|
|
92
|
+
}
|
|
85
93
|
|
|
86
|
-
|
|
94
|
+
return ok(interpreted.value);
|
|
95
|
+
},
|
|
87
96
|
},
|
|
88
97
|
...ifDefined('output', options.output),
|
|
89
98
|
};
|