@prisma-next/sql-contract-psl 0.6.0-dev.3 → 0.6.0-dev.5
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 +16 -1
- package/dist/provider.mjs.map +1 -1
- package/package.json +11 -11
- package/src/provider.ts +23 -1
package/dist/provider.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.mts","names":[],"sources":["../src/provider.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"provider.d.mts","names":[],"sources":["../src/provider.ts"],"mappings":";;;;UAWiB,qBAAA;EAAA,SACN,MAAA;EAAA,SACA,MAAA,EAAQ,aAAA;EAAA,SACR,yBAAA,YAAqC,gBAAA;AAAA;AAAA,iBAqChC,cAAA,CAAe,UAAA,UAAoB,OAAA,EAAS,qBAAA,GAAwB,cAAA"}
|
package/dist/provider.mjs
CHANGED
|
@@ -3,7 +3,22 @@ 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 { basename, extname } from "pathe";
|
|
6
7
|
//#region src/provider.ts
|
|
8
|
+
/**
|
|
9
|
+
* Derives the emit output path from the schema input path so artefacts land
|
|
10
|
+
* colocated with the source (e.g. `src/contract/schema.prisma` →
|
|
11
|
+
* `src/contract/contract.json`). The provider owns this because it is the
|
|
12
|
+
* only layer that knows the input path; the upstream `normalizeContractConfig`
|
|
13
|
+
* default is a last-resort fallback for providers that don't carry one.
|
|
14
|
+
*/
|
|
15
|
+
function defaultOutputFromSchemaPath(schemaPath) {
|
|
16
|
+
const ext = extname(schemaPath);
|
|
17
|
+
if (ext.length === 0) return `${schemaPath}.json`;
|
|
18
|
+
const base = schemaPath.slice(0, -ext.length);
|
|
19
|
+
if (basename(base) === "schema") return `${base.slice(0, -6)}contract.json`;
|
|
20
|
+
return `${base}.json`;
|
|
21
|
+
}
|
|
7
22
|
function buildColumnDescriptorMap(scalarTypeDescriptors, codecLookup) {
|
|
8
23
|
const result = /* @__PURE__ */ new Map();
|
|
9
24
|
for (const [typeName, codecId] of scalarTypeDescriptors) {
|
|
@@ -60,7 +75,7 @@ function prismaContract(schemaPath, options) {
|
|
|
60
75
|
return ok(interpreted.value);
|
|
61
76
|
}
|
|
62
77
|
},
|
|
63
|
-
|
|
78
|
+
output: options.output ?? defaultOutputFromSchemaPath(schemaPath)
|
|
64
79
|
};
|
|
65
80
|
}
|
|
66
81
|
//#endregion
|
package/dist/provider.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.mjs","names":[],"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', string>;\n readonly composedExtensionPackRefs?: readonly ExtensionPackRef<'sql', string>[];\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 nativeType = codecLookup.targetTypesFor(codecId)?.[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
|
|
1
|
+
{"version":3,"file":"provider.mjs","names":[],"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 { basename, extname } from 'pathe';\nimport { interpretPslDocumentToSqlContract } from './interpreter';\nimport type { ColumnDescriptor } from './psl-column-resolution';\n\nexport interface PrismaContractOptions {\n readonly output?: string;\n readonly target: TargetPackRef<'sql', string>;\n readonly composedExtensionPackRefs?: readonly ExtensionPackRef<'sql', string>[];\n}\n\n/**\n * Derives the emit output path from the schema input path so artefacts land\n * colocated with the source (e.g. `src/contract/schema.prisma` →\n * `src/contract/contract.json`). The provider owns this because it is the\n * only layer that knows the input path; the upstream `normalizeContractConfig`\n * default is a last-resort fallback for providers that don't carry one.\n */\nfunction defaultOutputFromSchemaPath(schemaPath: string): string {\n const ext = extname(schemaPath);\n if (ext.length === 0) return `${schemaPath}.json`;\n const base = schemaPath.slice(0, -ext.length);\n // PSL schemas commonly use `schema.prisma`; the emitted JSON is called\n // `contract.json` to mirror the rest of the toolchain, not `schema.json`.\n // Match only the exact basename `schema` so files like `my-schema.prisma`\n // are not silently rewritten to `my-contract.json`.\n if (basename(base) === 'schema') {\n return `${base.slice(0, -'schema'.length)}contract.json`;\n }\n return `${base}.json`;\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 nativeType = codecLookup.targetTypesFor(codecId)?.[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 output: options.output ?? defaultOutputFromSchemaPath(schemaPath),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAwBA,SAAS,4BAA4B,YAA4B;CAC/D,MAAM,MAAM,QAAQ,WAAW;CAC/B,IAAI,IAAI,WAAW,GAAG,OAAO,GAAG,WAAW;CAC3C,MAAM,OAAO,WAAW,MAAM,GAAG,CAAC,IAAI,OAAO;CAK7C,IAAI,SAAS,KAAK,KAAK,UACrB,OAAO,GAAG,KAAK,MAAM,GAAG,GAAiB,CAAC;CAE5C,OAAO,GAAG,KAAK;;AAGjB,SAAS,yBACP,uBACA,aACuC;CACvC,MAAM,yBAAS,IAAI,KAA+B;CAClD,KAAK,MAAM,CAAC,UAAU,YAAY,uBAAuB;EACvD,MAAM,aAAa,YAAY,eAAe,QAAQ,GAAG;EACzD,IAAI,eAAe,KAAA,GAAW;EAC9B,OAAO,IAAI,UAAU;GAAE;GAAS;GAAY,CAAC;;CAE/C,OAAO;;AAGT,SAAgB,eAAe,YAAoB,SAAgD;CACjG,OAAO;EACL,QAAQ;GACN,QAAQ,CAAC,WAAW;GACpB,MAAM,OAAO,YAAY;IACvB,MAAM,CAAC,sBAAsB,QAAQ;IACrC,IAAI,uBAAuB,KAAA,GACzB,MAAM,IAAI,MACR,mIACD;IAEH,IAAI;IACJ,IAAI;KACF,SAAS,MAAM,SAAS,oBAAoB,QAAQ;aAC7C,OAAO;KACd,MAAM,UAAU,OAAO,MAAM;KAC7B,OAAO,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,KAAA,EACL;KACD,GAAG,UACD,6BACA,QAAQ,2BAA2B,SAC/B,QAAQ,4BACR,KAAA,EACL;KACD,yBAAyB,QAAQ;KAClC,CAAC;IACF,IAAI,CAAC,YAAY,IACf,OAAO;IAGT,OAAO,GAAG,YAAY,MAAM;;GAE/B;EACD,QAAQ,QAAQ,UAAU,4BAA4B,WAAW;EAClE"}
|
package/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/sql-contract-psl",
|
|
3
|
-
"version": "0.6.0-dev.
|
|
3
|
+
"version": "0.6.0-dev.5",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"description": "PSL-to-SQL ContractIR interpreter for Prisma Next",
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"pathe": "^2.0.3",
|
|
10
|
-
"@prisma-next/config": "0.6.0-dev.
|
|
11
|
-
"@prisma-next/
|
|
12
|
-
"@prisma-next/
|
|
13
|
-
"@prisma-next/
|
|
14
|
-
"@prisma-next/contract": "0.6.0-dev.
|
|
15
|
-
"@prisma-next/utils": "0.6.0-dev.
|
|
16
|
-
"@prisma-next/
|
|
10
|
+
"@prisma-next/config": "0.6.0-dev.5",
|
|
11
|
+
"@prisma-next/contract": "0.6.0-dev.5",
|
|
12
|
+
"@prisma-next/sql-contract": "0.6.0-dev.5",
|
|
13
|
+
"@prisma-next/framework-components": "0.6.0-dev.5",
|
|
14
|
+
"@prisma-next/sql-contract-ts": "0.6.0-dev.5",
|
|
15
|
+
"@prisma-next/utils": "0.6.0-dev.5",
|
|
16
|
+
"@prisma-next/psl-parser": "0.6.0-dev.5"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"arktype": "^2.1.25",
|
|
20
20
|
"tsdown": "0.22.0",
|
|
21
21
|
"typescript": "5.9.3",
|
|
22
22
|
"vitest": "4.1.5",
|
|
23
|
-
"@prisma-next/contract-authoring": "0.6.0-dev.
|
|
24
|
-
"@prisma-next/tsdown": "0.0.0",
|
|
23
|
+
"@prisma-next/contract-authoring": "0.6.0-dev.5",
|
|
25
24
|
"@prisma-next/tsconfig": "0.0.0",
|
|
26
|
-
"@prisma-next/test-utils": "0.0.1"
|
|
25
|
+
"@prisma-next/test-utils": "0.0.1",
|
|
26
|
+
"@prisma-next/tsdown": "0.0.0"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
"dist",
|
package/src/provider.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { ExtensionPackRef, TargetPackRef } from '@prisma-next/framework-com
|
|
|
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 { basename, extname } from 'pathe';
|
|
8
9
|
import { interpretPslDocumentToSqlContract } from './interpreter';
|
|
9
10
|
import type { ColumnDescriptor } from './psl-column-resolution';
|
|
10
11
|
|
|
@@ -14,6 +15,27 @@ export interface PrismaContractOptions {
|
|
|
14
15
|
readonly composedExtensionPackRefs?: readonly ExtensionPackRef<'sql', string>[];
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Derives the emit output path from the schema input path so artefacts land
|
|
20
|
+
* colocated with the source (e.g. `src/contract/schema.prisma` →
|
|
21
|
+
* `src/contract/contract.json`). The provider owns this because it is the
|
|
22
|
+
* only layer that knows the input path; the upstream `normalizeContractConfig`
|
|
23
|
+
* default is a last-resort fallback for providers that don't carry one.
|
|
24
|
+
*/
|
|
25
|
+
function defaultOutputFromSchemaPath(schemaPath: string): string {
|
|
26
|
+
const ext = extname(schemaPath);
|
|
27
|
+
if (ext.length === 0) return `${schemaPath}.json`;
|
|
28
|
+
const base = schemaPath.slice(0, -ext.length);
|
|
29
|
+
// PSL schemas commonly use `schema.prisma`; the emitted JSON is called
|
|
30
|
+
// `contract.json` to mirror the rest of the toolchain, not `schema.json`.
|
|
31
|
+
// Match only the exact basename `schema` so files like `my-schema.prisma`
|
|
32
|
+
// are not silently rewritten to `my-contract.json`.
|
|
33
|
+
if (basename(base) === 'schema') {
|
|
34
|
+
return `${base.slice(0, -'schema'.length)}contract.json`;
|
|
35
|
+
}
|
|
36
|
+
return `${base}.json`;
|
|
37
|
+
}
|
|
38
|
+
|
|
17
39
|
function buildColumnDescriptorMap(
|
|
18
40
|
scalarTypeDescriptors: ReadonlyMap<string, string>,
|
|
19
41
|
codecLookup: CodecLookup,
|
|
@@ -92,6 +114,6 @@ export function prismaContract(schemaPath: string, options: PrismaContractOption
|
|
|
92
114
|
return ok(interpreted.value);
|
|
93
115
|
},
|
|
94
116
|
},
|
|
95
|
-
|
|
117
|
+
output: options.output ?? defaultOutputFromSchemaPath(schemaPath),
|
|
96
118
|
};
|
|
97
119
|
}
|