@prisma-next/sql-contract-psl 0.11.0-dev.5 → 0.11.0-dev.51
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/index.d.mts +2 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{interpreter-fVwMptxi.mjs → interpreter-BjGIhjdI.mjs} +7 -5
- package/dist/interpreter-BjGIhjdI.mjs.map +1 -0
- package/dist/provider.d.mts.map +1 -1
- package/dist/provider.mjs +1 -1
- package/dist/provider.mjs.map +1 -1
- package/package.json +12 -12
- package/src/interpreter.ts +11 -2
- package/dist/interpreter-fVwMptxi.mjs.map +0 -1
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 { 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,
|
|
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(schemaP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0BACA,QAAQ,uBAAuB,SAAS,IACpC,CAAC,GAAG,QAAQ,sBAAsB,IAClC,KAAA,CACN;KACA,GAAG,UACD,6BACA,QAAQ,2BAA2B,SAC/B,QAAQ,4BACR,KAAA,CACN;KACA,yBAAyB,QAAQ;IACnC,CAAC;IACD,IAAI,CAAC,YAAY,IACf,OAAO;IAGT,OAAO,GAAG,YAAY,KAAK;GAC7B;EACF;EACA,QAAQ,QAAQ,UAAU,4BAA4B,UAAU;CAClE;AACF"}
|
package/package.json
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/sql-contract-psl",
|
|
3
|
-
"version": "0.11.0-dev.
|
|
3
|
+
"version": "0.11.0-dev.51",
|
|
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
|
-
"@prisma-next/config": "0.11.0-dev.
|
|
10
|
-
"@prisma-next/contract": "0.11.0-dev.
|
|
11
|
-
"@prisma-next/framework-components": "0.11.0-dev.
|
|
12
|
-
"@prisma-next/psl-parser": "0.11.0-dev.
|
|
13
|
-
"@prisma-next/sql-contract": "0.11.0-dev.
|
|
14
|
-
"@prisma-next/sql-contract-ts": "0.11.0-dev.
|
|
15
|
-
"@prisma-next/utils": "0.11.0-dev.
|
|
9
|
+
"@prisma-next/config": "0.11.0-dev.51",
|
|
10
|
+
"@prisma-next/contract": "0.11.0-dev.51",
|
|
11
|
+
"@prisma-next/framework-components": "0.11.0-dev.51",
|
|
12
|
+
"@prisma-next/psl-parser": "0.11.0-dev.51",
|
|
13
|
+
"@prisma-next/sql-contract": "0.11.0-dev.51",
|
|
14
|
+
"@prisma-next/sql-contract-ts": "0.11.0-dev.51",
|
|
15
|
+
"@prisma-next/utils": "0.11.0-dev.51",
|
|
16
16
|
"pathe": "^2.0.3"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@prisma-next/contract-authoring": "0.11.0-dev.
|
|
20
|
-
"@prisma-next/test-utils": "0.11.0-dev.
|
|
21
|
-
"@prisma-next/tsconfig": "0.11.0-dev.
|
|
22
|
-
"@prisma-next/tsdown": "0.11.0-dev.
|
|
19
|
+
"@prisma-next/contract-authoring": "0.11.0-dev.51",
|
|
20
|
+
"@prisma-next/test-utils": "0.11.0-dev.51",
|
|
21
|
+
"@prisma-next/tsconfig": "0.11.0-dev.51",
|
|
22
|
+
"@prisma-next/tsdown": "0.11.0-dev.51",
|
|
23
23
|
"arktype": "^2.2.0",
|
|
24
24
|
"tsdown": "0.22.0",
|
|
25
25
|
"typescript": "5.9.3",
|
package/src/interpreter.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
ContractModel,
|
|
10
10
|
ContractValueObject,
|
|
11
11
|
} from '@prisma-next/contract/types';
|
|
12
|
+
import { crossRef } from '@prisma-next/contract/types';
|
|
12
13
|
import type {
|
|
13
14
|
AuthoringContributions,
|
|
14
15
|
AuthoringEntityContext,
|
|
@@ -22,6 +23,7 @@ import type {
|
|
|
22
23
|
MutationDefaultGeneratorDescriptor,
|
|
23
24
|
} from '@prisma-next/framework-components/control';
|
|
24
25
|
import type { Namespace } from '@prisma-next/framework-components/ir';
|
|
26
|
+
import { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';
|
|
25
27
|
import type {
|
|
26
28
|
ParsePslDocumentResult,
|
|
27
29
|
PslAttribute,
|
|
@@ -1303,6 +1305,7 @@ function resolvePolymorphism(
|
|
|
1303
1305
|
baseDeclarations: Map<string, BaseDeclaration>,
|
|
1304
1306
|
modelNames: Set<string>,
|
|
1305
1307
|
modelMappings: ReadonlyMap<string, ModelNameMapping>,
|
|
1308
|
+
modelNamespaceIds: ReadonlyMap<string, string>,
|
|
1306
1309
|
sourceId: string,
|
|
1307
1310
|
diagnostics: ContractSourceDiagnostic[],
|
|
1308
1311
|
): Record<string, ContractModel> {
|
|
@@ -1406,7 +1409,10 @@ function resolvePolymorphism(
|
|
|
1406
1409
|
...patched,
|
|
1407
1410
|
[variantName]: {
|
|
1408
1411
|
...variantModel,
|
|
1409
|
-
base:
|
|
1412
|
+
base: crossRef(
|
|
1413
|
+
baseDecl.baseName,
|
|
1414
|
+
modelNamespaceIds.get(baseDecl.baseName) ?? UNBOUND_NAMESPACE_ID,
|
|
1415
|
+
),
|
|
1410
1416
|
...(resolvedTable ? { storage: { ...variantModel.storage, table: resolvedTable } } : {}),
|
|
1411
1417
|
},
|
|
1412
1418
|
};
|
|
@@ -1680,6 +1686,7 @@ export function interpretPslDocumentToSqlContract(
|
|
|
1680
1686
|
baseDeclarations,
|
|
1681
1687
|
modelNames,
|
|
1682
1688
|
modelMappings,
|
|
1689
|
+
modelNamespaceIds,
|
|
1683
1690
|
sourceId,
|
|
1684
1691
|
polyDiagnostics,
|
|
1685
1692
|
);
|
|
@@ -1693,7 +1700,9 @@ export function interpretPslDocumentToSqlContract(
|
|
|
1693
1700
|
|
|
1694
1701
|
const variantModelNames = new Set(baseDeclarations.keys());
|
|
1695
1702
|
const filteredRoots = Object.fromEntries(
|
|
1696
|
-
Object.entries(contract.roots).filter(
|
|
1703
|
+
Object.entries(contract.roots).filter(
|
|
1704
|
+
([, crossReference]) => !variantModelNames.has(crossReference.model),
|
|
1705
|
+
),
|
|
1697
1706
|
);
|
|
1698
1707
|
|
|
1699
1708
|
const patchedContract: Contract = {
|