@prisma-next/mongo-contract-psl 0.14.0-dev.4 → 0.14.0-dev.40
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 +5 -0
- package/dist/exports/provider.d.mts.map +1 -1
- package/dist/exports/provider.mjs +26 -8
- package/dist/exports/provider.mjs.map +1 -1
- package/dist/index.d.mts +33 -5
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/{interpreter-Cj1vigKn.mjs → interpreter-D0vfRJ7f.mjs} +183 -85
- package/dist/interpreter-D0vfRJ7f.mjs.map +1 -0
- package/package.json +12 -10
- package/src/derive-json-schema.ts +31 -19
- package/src/exports/index.ts +5 -0
- package/src/interpreter.ts +256 -87
- package/src/provider.ts +39 -6
- package/src/psl-helpers.ts +18 -13
- package/dist/interpreter-Cj1vigKn.mjs.map +0 -1
|
@@ -3,6 +3,11 @@ import { ContractConfig } from "@prisma-next/config/config-types";
|
|
|
3
3
|
//#region src/provider.d.ts
|
|
4
4
|
interface MongoContractOptions {
|
|
5
5
|
readonly output?: string;
|
|
6
|
+
/** The target's default codec ids for an `enum` block that omits `@@type`. */
|
|
7
|
+
readonly enumInferenceCodecs?: {
|
|
8
|
+
readonly text: string;
|
|
9
|
+
readonly int: string;
|
|
10
|
+
};
|
|
6
11
|
}
|
|
7
12
|
declare function mongoContract(schemaPath: string, options?: MongoContractOptions): ContractConfig;
|
|
8
13
|
//#endregion
|
|
@@ -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":";;;UAUiB,oBAAA;EAAA,SACN,MAAA;EADM;EAAA,SAGN,mBAAA;IAAA,SAAiC,IAAA;IAAA,SAAuB,GAAA;EAAA;AAAA;AAAA,iBAgBnD,aAAA,CAAc,UAAA,UAAoB,OAAA,GAAU,oBAAA,GAAuB,cAAc"}
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
import { t as interpretPslDocumentToMongoContract } from "../interpreter-
|
|
1
|
+
import { t as interpretPslDocumentToMongoContract } from "../interpreter-D0vfRJ7f.mjs";
|
|
2
|
+
import { buildSymbolTable, rangeToPslSpan } from "@prisma-next/psl-parser";
|
|
3
|
+
import { ifDefined } from "@prisma-next/utils/defined";
|
|
2
4
|
import { notOk, ok } from "@prisma-next/utils/result";
|
|
3
|
-
import { parsePslDocument } from "@prisma-next/psl-parser";
|
|
4
5
|
import { readFile } from "node:fs/promises";
|
|
5
|
-
import {
|
|
6
|
+
import { parse } from "@prisma-next/psl-parser/syntax";
|
|
6
7
|
//#region src/provider.ts
|
|
8
|
+
function mapParseDiagnostics(diagnostics, sourceFile, sourceId) {
|
|
9
|
+
return diagnostics.map((diagnostic) => ({
|
|
10
|
+
code: diagnostic.code,
|
|
11
|
+
message: diagnostic.message,
|
|
12
|
+
sourceId,
|
|
13
|
+
span: rangeToPslSpan(diagnostic.range, sourceFile)
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
7
16
|
function mongoContract(schemaPath, options) {
|
|
8
17
|
return {
|
|
9
18
|
source: {
|
|
@@ -31,13 +40,22 @@ function mongoContract(schemaPath, options) {
|
|
|
31
40
|
}
|
|
32
41
|
});
|
|
33
42
|
}
|
|
43
|
+
const { document, sourceFile, diagnostics: parseDiagnostics } = parse(schema);
|
|
44
|
+
const { table: symbolTable, diagnostics: symbolTableDiagnostics } = buildSymbolTable({
|
|
45
|
+
document,
|
|
46
|
+
sourceFile,
|
|
47
|
+
scalarTypes: [...context.scalarTypeDescriptors.keys()],
|
|
48
|
+
pslBlockDescriptors: context.authoringContributions.pslBlockDescriptors
|
|
49
|
+
});
|
|
34
50
|
const interpreted = interpretPslDocumentToMongoContract({
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
51
|
+
symbolTable,
|
|
52
|
+
sourceFile,
|
|
53
|
+
sourceId: schemaPath,
|
|
54
|
+
seedDiagnostics: [...mapParseDiagnostics(parseDiagnostics, sourceFile, schemaPath), ...mapParseDiagnostics(symbolTableDiagnostics, sourceFile, schemaPath)],
|
|
39
55
|
scalarTypeDescriptors: context.scalarTypeDescriptors,
|
|
40
|
-
codecLookup: context.codecLookup
|
|
56
|
+
codecLookup: context.codecLookup,
|
|
57
|
+
authoringContributions: context.authoringContributions,
|
|
58
|
+
...ifDefined("enumInferenceCodecs", options?.enumInferenceCodecs)
|
|
41
59
|
});
|
|
42
60
|
if (!interpreted.ok) return interpreted;
|
|
43
61
|
return ok(interpreted.value);
|
|
@@ -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 {
|
|
1
|
+
{"version":3,"file":"provider.mjs","names":[],"sources":["../../src/provider.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport type { ContractConfig, ContractSourceDiagnostic } from '@prisma-next/config/config-types';\nimport { buildSymbolTable, rangeToPslSpan } from '@prisma-next/psl-parser';\nimport type { ParseDiagnostic, SourceFile } from '@prisma-next/psl-parser/syntax';\nimport { parse } from '@prisma-next/psl-parser/syntax';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { notOk, ok } from '@prisma-next/utils/result';\n\nimport { interpretPslDocumentToMongoContract } from './interpreter';\n\nexport interface MongoContractOptions {\n readonly output?: string;\n /** The target's default codec ids for an `enum` block that omits `@@type`. */\n readonly enumInferenceCodecs?: { readonly text: string; readonly int: string };\n}\n\nfunction mapParseDiagnostics(\n diagnostics: readonly ParseDiagnostic[],\n sourceFile: SourceFile,\n sourceId: string,\n): ContractSourceDiagnostic[] {\n return diagnostics.map((diagnostic) => ({\n code: diagnostic.code,\n message: diagnostic.message,\n sourceId,\n span: rangeToPslSpan(diagnostic.range, sourceFile),\n }));\n}\n\nexport function mongoContract(schemaPath: string, options?: MongoContractOptions): ContractConfig {\n return {\n source: {\n sourceFormat: 'psl',\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, sourceFile, diagnostics: parseDiagnostics } = parse(schema);\n const { table: symbolTable, diagnostics: symbolTableDiagnostics } = buildSymbolTable({\n document,\n sourceFile,\n scalarTypes: [...context.scalarTypeDescriptors.keys()],\n pslBlockDescriptors: context.authoringContributions.pslBlockDescriptors,\n });\n\n // Do not short-circuit on provider-level diagnostics; recovered CST can\n // still produce interpreter diagnostics in the same response.\n const seedDiagnostics = [\n ...mapParseDiagnostics(parseDiagnostics, sourceFile, schemaPath),\n ...mapParseDiagnostics(symbolTableDiagnostics, sourceFile, schemaPath),\n ];\n\n const interpreted = interpretPslDocumentToMongoContract({\n symbolTable,\n sourceFile,\n sourceId: schemaPath,\n seedDiagnostics,\n scalarTypeDescriptors: context.scalarTypeDescriptors,\n codecLookup: context.codecLookup,\n authoringContributions: context.authoringContributions,\n ...ifDefined('enumInferenceCodecs', options?.enumInferenceCodecs),\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,oBACP,aACA,YACA,UAC4B;CAC5B,OAAO,YAAY,KAAK,gBAAgB;EACtC,MAAM,WAAW;EACjB,SAAS,WAAW;EACpB;EACA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
|
2
|
+
import { Contract, ContractField, ContractValueObject, JsonValue } from "@prisma-next/contract/types";
|
|
3
|
+
import { AuthoringContributions } from "@prisma-next/framework-components/authoring";
|
|
4
|
+
import { SymbolTable } from "@prisma-next/psl-parser";
|
|
2
5
|
import { Result } from "@prisma-next/utils/result";
|
|
3
|
-
import {
|
|
4
|
-
import { ContractSourceDiagnostics } from "@prisma-next/config/config-types";
|
|
6
|
+
import { SourceFile } from "@prisma-next/psl-parser/syntax";
|
|
5
7
|
import { CodecLookup } from "@prisma-next/framework-components/codec";
|
|
8
|
+
import { ContractSourceDiagnostic, ContractSourceDiagnostics } from "@prisma-next/config/config-types";
|
|
6
9
|
|
|
10
|
+
//#region src/derive-json-schema.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* The permitted values a field's value set restricts it to, keyed by the value set's name — the
|
|
13
|
+
* storage `entries.valueSet` slot. The validator's `enum` keyword is sourced from these, not from
|
|
14
|
+
* `domain.enum`.
|
|
15
|
+
*/
|
|
16
|
+
type FieldValueSets = Record<string, {
|
|
17
|
+
readonly values: readonly JsonValue[];
|
|
18
|
+
}>;
|
|
19
|
+
declare function deriveJsonSchema(fields: Record<string, ContractField>, valueObjects?: Record<string, ContractValueObject>, codecLookup?: CodecLookup, valueSets?: FieldValueSets): MongoValidator;
|
|
20
|
+
interface PolymorphicVariant {
|
|
21
|
+
readonly discriminatorValue: string;
|
|
22
|
+
readonly fields: Record<string, ContractField>;
|
|
23
|
+
}
|
|
24
|
+
declare function derivePolymorphicJsonSchema(baseFields: Record<string, ContractField>, discriminatorField: string, variants: readonly PolymorphicVariant[], valueObjects?: Record<string, ContractValueObject>, codecLookup?: CodecLookup, valueSets?: FieldValueSets): MongoValidator;
|
|
25
|
+
//#endregion
|
|
7
26
|
//#region src/interpreter.d.ts
|
|
8
27
|
interface InterpretPslDocumentToMongoContractInput {
|
|
9
|
-
readonly
|
|
28
|
+
readonly symbolTable: SymbolTable;
|
|
29
|
+
readonly sourceFile: SourceFile;
|
|
30
|
+
readonly sourceId: string;
|
|
10
31
|
readonly scalarTypeDescriptors: ReadonlyMap<string, string>;
|
|
11
32
|
readonly codecLookup?: CodecLookup;
|
|
33
|
+
readonly seedDiagnostics?: readonly ContractSourceDiagnostic[];
|
|
34
|
+
readonly authoringContributions?: AuthoringContributions;
|
|
35
|
+
/** The target's default codec ids for an `enum` block that omits `@@type`. */
|
|
36
|
+
readonly enumInferenceCodecs?: {
|
|
37
|
+
readonly text: string;
|
|
38
|
+
readonly int: string;
|
|
39
|
+
};
|
|
12
40
|
}
|
|
13
41
|
declare function interpretPslDocumentToMongoContract(input: InterpretPslDocumentToMongoContractInput): Result<Contract, ContractSourceDiagnostics>;
|
|
14
42
|
//#endregion
|
|
15
|
-
export { type InterpretPslDocumentToMongoContractInput, interpretPslDocumentToMongoContract };
|
|
43
|
+
export { type FieldValueSets, type InterpretPslDocumentToMongoContractInput, deriveJsonSchema, derivePolymorphicJsonSchema, interpretPslDocumentToMongoContract };
|
|
16
44
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/interpreter.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/derive-json-schema.ts","../src/interpreter.ts"],"mappings":";;;;;;;;;;;;;;;KASY,cAAA,GAAiB,MAAM;EAAA,SAAoB,MAAA,WAAiB,SAAA;AAAA;AAAA,iBA2FxD,gBAAA,CACd,MAAA,EAAQ,MAAA,SAAe,aAAA,GACvB,YAAA,GAAe,MAAA,SAAe,mBAAA,GAC9B,WAAA,GAAc,WAAA,EACd,SAAA,GAAY,cAAA,GACX,cAAA;AAAA,UAQc,kBAAA;EAAA,SACN,kBAAA;EAAA,SACA,MAAA,EAAQ,MAAM,SAAS,aAAA;AAAA;AAAA,iBAGlB,2BAAA,CACd,UAAA,EAAY,MAAA,SAAe,aAAA,GAC3B,kBAAA,UACA,QAAA,WAAmB,kBAAA,IACnB,YAAA,GAAe,MAAA,SAAe,mBAAA,GAC9B,WAAA,GAAc,WAAA,EACd,SAAA,GAAY,cAAA,GACX,cAAA;;;UC3Cc,wCAAA;EAAA,SACN,WAAA,EAAa,WAAA;EAAA,SACb,UAAA,EAAY,UAAA;EAAA,SACZ,QAAA;EAAA,SACA,qBAAA,EAAuB,WAAA;EAAA,SACvB,WAAA,GAAc,WAAA;EAAA,SACd,eAAA,YAA2B,wBAAA;EAAA,SAC3B,sBAAA,GAAyB,sBAAA;EDhFmB;EAAA,SCkF5C,mBAAA;IAAA,SAAiC,IAAA;IAAA,SAAuB,GAAA;EAAA;AAAA;AAAA,iBA41BnD,mCAAA,CACd,KAAA,EAAO,wCAAA,GACN,MAAA,CAAO,QAAA,EAAU,yBAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as interpretPslDocumentToMongoContract } from "./interpreter-
|
|
2
|
-
export { interpretPslDocumentToMongoContract };
|
|
1
|
+
import { n as deriveJsonSchema, r as derivePolymorphicJsonSchema, t as interpretPslDocumentToMongoContract } from "./interpreter-D0vfRJ7f.mjs";
|
|
2
|
+
export { deriveJsonSchema, derivePolymorphicJsonSchema, interpretPslDocumentToMongoContract };
|