@prisma-next/mongo-contract-psl 0.4.0-dev.11 → 0.4.0-dev.13
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/exports/provider.d.mts.map +1 -1
- package/dist/exports/provider.mjs +32 -29
- package/dist/exports/provider.mjs.map +1 -1
- package/package.json +9 -9
- package/src/provider.ts +41 -34
|
@@ -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":";;;UAOiB,oBAAA;;AAAjB;AAIgB,iBAAA,aAAA,CAA4C,UAAA,EAAA,MAAuB,EAAA,OAAc,CAAd,EAAvB,oBAAqC,CAAA,EAAd,cAAc"}
|
|
@@ -3,42 +3,45 @@ import { notOk, ok } from "@prisma-next/utils/result";
|
|
|
3
3
|
import { parsePslDocument } from "@prisma-next/psl-parser";
|
|
4
4
|
import { readFile } from "node:fs/promises";
|
|
5
5
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
6
|
-
import { resolve } from "pathe";
|
|
7
6
|
|
|
8
7
|
//#region src/provider.ts
|
|
9
8
|
function mongoContract(schemaPath, options) {
|
|
10
9
|
return {
|
|
11
|
-
source:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
source: {
|
|
11
|
+
inputs: [schemaPath],
|
|
12
|
+
load: async (context) => {
|
|
13
|
+
const [absoluteSchemaPath] = context.resolvedInputs;
|
|
14
|
+
if (absoluteSchemaPath === void 0) throw new Error("mongoContract: context.resolvedInputs is empty. The CLI config loader should populate it positional-matched with source.inputs.");
|
|
15
|
+
let schema;
|
|
16
|
+
try {
|
|
17
|
+
schema = await readFile(absoluteSchemaPath, "utf-8");
|
|
18
|
+
} catch (error) {
|
|
19
|
+
const message = String(error);
|
|
20
|
+
return notOk({
|
|
21
|
+
summary: `Failed to read Prisma schema at "${schemaPath}"`,
|
|
22
|
+
diagnostics: [{
|
|
23
|
+
code: "PSL_SCHEMA_READ_FAILED",
|
|
24
|
+
message,
|
|
25
|
+
sourceId: schemaPath
|
|
26
|
+
}],
|
|
27
|
+
meta: {
|
|
28
|
+
schemaPath,
|
|
29
|
+
absoluteSchemaPath,
|
|
30
|
+
cause: message
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
const interpreted = interpretPslDocumentToMongoContract({
|
|
35
|
+
document: parsePslDocument({
|
|
36
|
+
schema,
|
|
23
37
|
sourceId: schemaPath
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
absoluteSchemaPath,
|
|
28
|
-
cause: message
|
|
29
|
-
}
|
|
38
|
+
}),
|
|
39
|
+
scalarTypeDescriptors: context.scalarTypeDescriptors,
|
|
40
|
+
codecLookup: context.codecLookup
|
|
30
41
|
});
|
|
42
|
+
if (!interpreted.ok) return interpreted;
|
|
43
|
+
return ok(interpreted.value);
|
|
31
44
|
}
|
|
32
|
-
const interpreted = interpretPslDocumentToMongoContract({
|
|
33
|
-
document: parsePslDocument({
|
|
34
|
-
schema,
|
|
35
|
-
sourceId: schemaPath
|
|
36
|
-
}),
|
|
37
|
-
scalarTypeDescriptors: context.scalarTypeDescriptors,
|
|
38
|
-
codecLookup: context.codecLookup
|
|
39
|
-
});
|
|
40
|
-
if (!interpreted.ok) return interpreted;
|
|
41
|
-
return ok(interpreted.value);
|
|
42
45
|
},
|
|
43
46
|
...ifDefined("output", options?.output)
|
|
44
47
|
};
|
|
@@ -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 { parsePslDocument } from '@prisma-next/psl-parser';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { notOk, ok } from '@prisma-next/utils/result';\nimport { interpretPslDocumentToMongoContract } from './interpreter';\n\nexport interface MongoContractOptions {\n readonly output?: string;\n}\n\nexport function mongoContract(schemaPath: string, options?: MongoContractOptions): 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 'mongoContract: 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 interpreted = interpretPslDocumentToMongoContract({\n document,\n scalarTypeDescriptors: context.scalarTypeDescriptors,\n codecLookup: context.codecLookup,\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":";;;;;;;AAWA,SAAgB,cAAc,YAAoB,SAAgD;AAChG,QAAO;EACL,QAAQ;GACN,QAAQ,CAAC,WAAW;GACpB,MAAM,OAAO,YAAY;IACvB,MAAM,CAAC,sBAAsB,QAAQ;AACrC,QAAI,uBAAuB,OACzB,OAAM,IAAI,MACR,kIACD;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;;IAQJ,MAAM,cAAc,oCAAoC;KACtD,UANe,iBAAiB;MAChC;MACA,UAAU;MACX,CAAC;KAIA,uBAAuB,QAAQ;KAC/B,aAAa,QAAQ;KACtB,CAAC;AACF,QAAI,CAAC,YAAY,GACf,QAAO;AAGT,WAAO,GAAG,YAAY,MAAM;;GAE/B;EACD,GAAG,UAAU,UAAU,SAAS,OAAO;EACxC"}
|
package/package.json
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/mongo-contract-psl",
|
|
3
|
-
"version": "0.4.0-dev.
|
|
3
|
+
"version": "0.4.0-dev.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "PSL-to-Mongo ContractIR interpreter for Prisma Next",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"pathe": "^2.0.3",
|
|
9
|
-
"@prisma-next/
|
|
10
|
-
"@prisma-next/
|
|
11
|
-
"@prisma-next/mongo-contract": "0.4.0-dev.
|
|
12
|
-
"@prisma-next/
|
|
13
|
-
"@prisma-next/
|
|
14
|
-
"@prisma-next/
|
|
9
|
+
"@prisma-next/config": "0.4.0-dev.13",
|
|
10
|
+
"@prisma-next/psl-parser": "0.4.0-dev.13",
|
|
11
|
+
"@prisma-next/mongo-contract": "0.4.0-dev.13",
|
|
12
|
+
"@prisma-next/utils": "0.4.0-dev.13",
|
|
13
|
+
"@prisma-next/contract": "0.4.0-dev.13",
|
|
14
|
+
"@prisma-next/framework-components": "0.4.0-dev.13"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"tsdown": "0.18.4",
|
|
18
18
|
"typescript": "5.9.3",
|
|
19
19
|
"vitest": "4.0.17",
|
|
20
|
-
"@prisma-next/
|
|
21
|
-
"@prisma-next/
|
|
20
|
+
"@prisma-next/tsdown": "0.0.0",
|
|
21
|
+
"@prisma-next/tsconfig": "0.0.0"
|
|
22
22
|
},
|
|
23
23
|
"files": [
|
|
24
24
|
"dist",
|
package/src/provider.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
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 { parsePslDocument } from '@prisma-next/psl-parser';
|
|
4
4
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
5
5
|
import { notOk, ok } from '@prisma-next/utils/result';
|
|
6
|
-
import { resolve } from 'pathe';
|
|
7
6
|
import { interpretPslDocumentToMongoContract } from './interpreter';
|
|
8
7
|
|
|
9
8
|
export interface MongoContractOptions {
|
|
@@ -12,41 +11,49 @@ export interface MongoContractOptions {
|
|
|
12
11
|
|
|
13
12
|
export function mongoContract(schemaPath: string, options?: MongoContractOptions): ContractConfig {
|
|
14
13
|
return {
|
|
15
|
-
source:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
14
|
+
source: {
|
|
15
|
+
inputs: [schemaPath],
|
|
16
|
+
load: async (context) => {
|
|
17
|
+
const [absoluteSchemaPath] = context.resolvedInputs;
|
|
18
|
+
if (absoluteSchemaPath === undefined) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
'mongoContract: context.resolvedInputs is empty. The CLI config loader should populate it positional-matched with source.inputs.',
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
let schema: string;
|
|
24
|
+
try {
|
|
25
|
+
schema = await readFile(absoluteSchemaPath, 'utf-8');
|
|
26
|
+
} catch (error) {
|
|
27
|
+
const message = String(error);
|
|
28
|
+
return notOk({
|
|
29
|
+
summary: `Failed to read Prisma schema at "${schemaPath}"`,
|
|
30
|
+
diagnostics: [
|
|
31
|
+
{
|
|
32
|
+
code: 'PSL_SCHEMA_READ_FAILED',
|
|
33
|
+
message,
|
|
34
|
+
sourceId: schemaPath,
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
meta: { schemaPath, absoluteSchemaPath, cause: message },
|
|
38
|
+
});
|
|
39
|
+
}
|
|
34
40
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
const document = parsePslDocument({
|
|
42
|
+
schema,
|
|
43
|
+
sourceId: schemaPath,
|
|
44
|
+
});
|
|
39
45
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
const interpreted = interpretPslDocumentToMongoContract({
|
|
47
|
+
document,
|
|
48
|
+
scalarTypeDescriptors: context.scalarTypeDescriptors,
|
|
49
|
+
codecLookup: context.codecLookup,
|
|
50
|
+
});
|
|
51
|
+
if (!interpreted.ok) {
|
|
52
|
+
return interpreted;
|
|
53
|
+
}
|
|
48
54
|
|
|
49
|
-
|
|
55
|
+
return ok(interpreted.value);
|
|
56
|
+
},
|
|
50
57
|
},
|
|
51
58
|
...ifDefined('output', options?.output),
|
|
52
59
|
};
|