@prisma-next/sql-contract-psl 0.4.0-dev.2 → 0.4.0-dev.4

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.
@@ -1,5 +1,3 @@
1
- import { t as ControlMutationDefaults } from "./default-function-registry-DUMRIhJH.mjs";
2
- import { AuthoringContributions } from "@prisma-next/framework-components/authoring";
3
1
  import { ContractConfig } from "@prisma-next/config/config-types";
4
2
  import { ExtensionPackRef, TargetPackRef } from "@prisma-next/framework-components/components";
5
3
 
@@ -7,15 +5,6 @@ import { ExtensionPackRef, TargetPackRef } from "@prisma-next/framework-componen
7
5
  interface PrismaContractOptions {
8
6
  readonly output?: string;
9
7
  readonly target: TargetPackRef<'sql', 'postgres'>;
10
- readonly authoringContributions?: AuthoringContributions;
11
- readonly scalarTypeDescriptors: ReadonlyMap<string, {
12
- readonly codecId: string;
13
- readonly nativeType: string;
14
- readonly typeRef?: string;
15
- readonly typeParams?: Record<string, unknown>;
16
- }>;
17
- readonly controlMutationDefaults?: ControlMutationDefaults;
18
- readonly composedExtensionPacks?: readonly string[];
19
8
  readonly composedExtensionPackRefs?: readonly ExtensionPackRef<'sql', 'postgres'>[];
20
9
  }
21
10
  declare function prismaContract(schemaPath: string, options: PrismaContractOptions): ContractConfig;
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.mts","names":[],"sources":["../src/provider.ts"],"sourcesContent":[],"mappings":";;;;;;UAWiB,qBAAA;;EAAA,SAAA,MAAA,EAEE,aAFmB,CAAA,KAAA,EAAA,UAAA,CAAA;EAEnB,SAAA,sBAAA,CAAA,EACiB,sBADjB;EACiB,SAAA,qBAAA,EACF,WADE,CAAA,MAAA,EAAA;IAOR,SAAA,OAAA,EAAA,MAAA;IANM,SAAA,UAAA,EAAA,MAAA;IASG,SAAA,OAAA,CAAA,EAAA,MAAA;IAEW,SAAA,UAAA,CAAA,EALpB,MAKoB,CAAA,MAAA,EAAA,OAAA,CAAA;EAAgB,CAAA,CAAA;EAGhD,SAAA,uBAA4C,CAAA,EALvB,uBAK+C;;gDAHpC;;iBAGhC,cAAA,8BAA4C,wBAAwB"}
1
+ {"version":3,"file":"provider.d.mts","names":[],"sources":["../src/provider.ts"],"sourcesContent":[],"mappings":";;;;UAWiB,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
@@ -6,6 +6,20 @@ import { readFile } from "node:fs/promises";
6
6
  import { resolve } from "pathe";
7
7
 
8
8
  //#region src/provider.ts
9
+ function buildColumnDescriptorMap(scalarTypeDescriptors, codecLookup) {
10
+ const result = /* @__PURE__ */ new Map();
11
+ for (const [typeName, codecId] of scalarTypeDescriptors) {
12
+ const codec = codecLookup.get(codecId);
13
+ if (!codec) continue;
14
+ const nativeType = codec.targetTypes[0];
15
+ if (nativeType === void 0) continue;
16
+ result.set(typeName, {
17
+ codecId,
18
+ nativeType
19
+ });
20
+ }
21
+ return result;
22
+ }
9
23
  function prismaContract(schemaPath, options) {
10
24
  return {
11
25
  source: async (context) => {
@@ -33,15 +47,15 @@ function prismaContract(schemaPath, options) {
33
47
  schema,
34
48
  sourceId: schemaPath
35
49
  });
36
- const composedExtensionPacks = [...context.composedExtensionPacks ?? [], ...options.composedExtensionPacks ?? []];
50
+ const scalarTypeDescriptors = buildColumnDescriptorMap(context.scalarTypeDescriptors, context.codecLookup);
37
51
  const interpreted = interpretPslDocumentToSqlContract({
38
52
  document,
39
53
  target: options.target,
40
- ...ifDefined("authoringContributions", options.authoringContributions),
41
- scalarTypeDescriptors: options.scalarTypeDescriptors,
42
- ...ifDefined("composedExtensionPacks", composedExtensionPacks.length > 0 ? composedExtensionPacks : void 0),
54
+ authoringContributions: context.authoringContributions,
55
+ scalarTypeDescriptors,
56
+ ...ifDefined("composedExtensionPacks", context.composedExtensionPacks.length > 0 ? [...context.composedExtensionPacks] : void 0),
43
57
  ...ifDefined("composedExtensionPackRefs", options.composedExtensionPackRefs?.length ? options.composedExtensionPackRefs : void 0),
44
- ...ifDefined("controlMutationDefaults", options.controlMutationDefaults)
58
+ controlMutationDefaults: context.controlMutationDefaults
45
59
  });
46
60
  if (!interpreted.ok) return interpreted;
47
61
  return ok(interpreted.value);
@@ -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, ContractSourceContext } from '@prisma-next/config/config-types';\nimport type { AuthoringContributions } from '@prisma-next/framework-components/authoring';\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 { resolve } from 'pathe';\nimport type { ControlMutationDefaults } from './default-function-registry';\nimport { interpretPslDocumentToSqlContract } from './interpreter';\n\nexport interface PrismaContractOptions {\n readonly output?: string;\n readonly target: TargetPackRef<'sql', 'postgres'>;\n readonly authoringContributions?: AuthoringContributions;\n readonly scalarTypeDescriptors: ReadonlyMap<\n string,\n {\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeRef?: string;\n readonly typeParams?: Record<string, unknown>;\n }\n >;\n readonly controlMutationDefaults?: ControlMutationDefaults;\n readonly composedExtensionPacks?: readonly string[];\n readonly composedExtensionPackRefs?: readonly ExtensionPackRef<'sql', 'postgres'>[];\n}\n\nexport function prismaContract(schemaPath: string, options: PrismaContractOptions): ContractConfig {\n return {\n source: async (context: ContractSourceContext) => {\n const absoluteSchemaPath = resolve(schemaPath);\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 const composedExtensionPacks = [\n ...(context.composedExtensionPacks ?? []),\n ...(options.composedExtensionPacks ?? []),\n ];\n\n const interpreted = interpretPslDocumentToSqlContract({\n document,\n target: options.target,\n ...ifDefined('authoringContributions', options.authoringContributions),\n scalarTypeDescriptors: options.scalarTypeDescriptors,\n ...ifDefined(\n 'composedExtensionPacks',\n composedExtensionPacks.length > 0 ? composedExtensionPacks : undefined,\n ),\n ...ifDefined(\n 'composedExtensionPackRefs',\n options.composedExtensionPackRefs?.length ? options.composedExtensionPackRefs : undefined,\n ),\n ...ifDefined('controlMutationDefaults', options.controlMutationDefaults),\n });\n if (!interpreted.ok) {\n return interpreted;\n }\n\n return ok(interpreted.value);\n },\n ...ifDefined('output', options.output),\n };\n}\n"],"mappings":";;;;;;;;AA6BA,SAAgB,eAAe,YAAoB,SAAgD;AACjG,QAAO;EACL,QAAQ,OAAO,YAAmC;GAChD,MAAM,qBAAqB,QAAQ,WAAW;GAC9C,IAAIA;AACJ,OAAI;AACF,aAAS,MAAM,SAAS,oBAAoB,QAAQ;YAC7C,OAAO;IACd,MAAM,UAAU,OAAO,MAAM;AAC7B,WAAO,MAAM;KACX,SAAS,oCAAoC,WAAW;KACxD,aAAa,CACX;MACE,MAAM;MACN;MACA,UAAU;MACX,CACF;KACD,MAAM;MAAE;MAAY;MAAoB,OAAO;MAAS;KACzD,CAAC;;GAGJ,MAAM,WAAW,iBAAiB;IAChC;IACA,UAAU;IACX,CAAC;GACF,MAAM,yBAAyB,CAC7B,GAAI,QAAQ,0BAA0B,EAAE,EACxC,GAAI,QAAQ,0BAA0B,EAAE,CACzC;GAED,MAAM,cAAc,kCAAkC;IACpD;IACA,QAAQ,QAAQ;IAChB,GAAG,UAAU,0BAA0B,QAAQ,uBAAuB;IACtE,uBAAuB,QAAQ;IAC/B,GAAG,UACD,0BACA,uBAAuB,SAAS,IAAI,yBAAyB,OAC9D;IACD,GAAG,UACD,6BACA,QAAQ,2BAA2B,SAAS,QAAQ,4BAA4B,OACjF;IACD,GAAG,UAAU,2BAA2B,QAAQ,wBAAwB;IACzE,CAAC;AACF,OAAI,CAAC,YAAY,GACf,QAAO;AAGT,UAAO,GAAG,YAAY,MAAM;;EAE9B,GAAG,UAAU,UAAU,QAAQ,OAAO;EACvC"}
1
+ {"version":3,"file":"provider.mjs","names":["schema: string"],"sources":["../src/provider.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport type { ContractConfig, ContractSourceContext } 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 { resolve } 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', '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: async (context: ContractSourceContext) => {\n const absoluteSchemaPath = resolve(schemaPath);\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 ? options.composedExtensionPackRefs : undefined,\n ),\n controlMutationDefaults: context.controlMutationDefaults,\n });\n if (!interpreted.ok) {\n return interpreted;\n }\n\n return ok(interpreted.value);\n },\n ...ifDefined('output', options.output),\n };\n}\n"],"mappings":";;;;;;;;AAiBA,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,OAAO,YAAmC;GAChD,MAAM,qBAAqB,QAAQ,WAAW;GAC9C,IAAIA;AACJ,OAAI;AACF,aAAS,MAAM,SAAS,oBAAoB,QAAQ;YAC7C,OAAO;IACd,MAAM,UAAU,OAAO,MAAM;AAC7B,WAAO,MAAM;KACX,SAAS,oCAAoC,WAAW;KACxD,aAAa,CACX;MACE,MAAM;MACN;MACA,UAAU;MACX,CACF;KACD,MAAM;MAAE;MAAY;MAAoB,OAAO;MAAS;KACzD,CAAC;;GAGJ,MAAM,WAAW,iBAAiB;IAChC;IACA,UAAU;IACX,CAAC;GAEF,MAAM,wBAAwB,yBAC5B,QAAQ,uBACR,QAAQ,YACT;GAED,MAAM,cAAc,kCAAkC;IACpD;IACA,QAAQ,QAAQ;IAChB,wBAAwB,QAAQ;IAChC;IACA,GAAG,UACD,0BACA,QAAQ,uBAAuB,SAAS,IACpC,CAAC,GAAG,QAAQ,uBAAuB,GACnC,OACL;IACD,GAAG,UACD,6BACA,QAAQ,2BAA2B,SAAS,QAAQ,4BAA4B,OACjF;IACD,yBAAyB,QAAQ;IAClC,CAAC;AACF,OAAI,CAAC,YAAY,GACf,QAAO;AAGT,UAAO,GAAG,YAAY,MAAM;;EAE9B,GAAG,UAAU,UAAU,QAAQ,OAAO;EACvC"}
package/package.json CHANGED
@@ -1,24 +1,24 @@
1
1
  {
2
2
  "name": "@prisma-next/sql-contract-psl",
3
- "version": "0.4.0-dev.2",
3
+ "version": "0.4.0-dev.4",
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.0-dev.2",
10
- "@prisma-next/contract": "0.4.0-dev.2",
11
- "@prisma-next/framework-components": "0.4.0-dev.2",
12
- "@prisma-next/sql-contract": "0.4.0-dev.2",
13
- "@prisma-next/psl-parser": "0.4.0-dev.2",
14
- "@prisma-next/sql-contract-ts": "0.4.0-dev.2",
15
- "@prisma-next/utils": "0.4.0-dev.2"
9
+ "@prisma-next/framework-components": "0.4.0-dev.4",
10
+ "@prisma-next/psl-parser": "0.4.0-dev.4",
11
+ "@prisma-next/sql-contract": "0.4.0-dev.4",
12
+ "@prisma-next/sql-contract-ts": "0.4.0-dev.4",
13
+ "@prisma-next/utils": "0.4.0-dev.4",
14
+ "@prisma-next/config": "0.4.0-dev.4",
15
+ "@prisma-next/contract": "0.4.0-dev.4"
16
16
  },
17
17
  "devDependencies": {
18
18
  "tsdown": "0.18.4",
19
19
  "typescript": "5.9.3",
20
20
  "vitest": "4.0.17",
21
- "@prisma-next/contract-authoring": "0.4.0-dev.2",
21
+ "@prisma-next/contract-authoring": "0.4.0-dev.4",
22
22
  "@prisma-next/tsconfig": "0.0.0",
23
23
  "@prisma-next/tsdown": "0.0.0"
24
24
  },
@@ -1,5 +1,9 @@
1
- import type { ContractSourceDiagnostic } from '@prisma-next/config/config-types';
2
- import type { ColumnDefault, ExecutionMutationDefaultValue } from '@prisma-next/contract/types';
1
+ import type {
2
+ ControlMutationDefaultRegistry,
3
+ DefaultFunctionLoweringContext,
4
+ LoweredDefaultResult,
5
+ ParsedDefaultFunctionCall,
6
+ } from '@prisma-next/framework-components/control';
3
7
  import type { PslSpan } from '@prisma-next/psl-parser';
4
8
 
5
9
  interface DefaultFunctionArgument {
@@ -7,70 +11,6 @@ interface DefaultFunctionArgument {
7
11
  readonly span: PslSpan;
8
12
  }
9
13
 
10
- export interface ParsedDefaultFunctionCall {
11
- readonly name: string;
12
- readonly raw: string;
13
- readonly args: readonly DefaultFunctionArgument[];
14
- readonly span: PslSpan;
15
- }
16
-
17
- export interface DefaultFunctionLoweringContext {
18
- readonly sourceId: string;
19
- readonly modelName: string;
20
- readonly fieldName: string;
21
- readonly columnCodecId?: string;
22
- }
23
-
24
- export type LoweredDefaultValue =
25
- | { readonly kind: 'storage'; readonly defaultValue: ColumnDefault }
26
- | { readonly kind: 'execution'; readonly generated: ExecutionMutationDefaultValue };
27
-
28
- export type LoweredDefaultResult =
29
- | { readonly ok: true; readonly value: LoweredDefaultValue }
30
- | { readonly ok: false; readonly diagnostic: ContractSourceDiagnostic };
31
-
32
- export type DefaultFunctionLoweringHandler = (input: {
33
- readonly call: ParsedDefaultFunctionCall;
34
- readonly context: DefaultFunctionLoweringContext;
35
- }) => LoweredDefaultResult;
36
-
37
- export interface DefaultFunctionRegistryEntry {
38
- readonly lower: DefaultFunctionLoweringHandler;
39
- readonly usageSignatures?: readonly string[];
40
- }
41
-
42
- export type DefaultFunctionRegistry = ReadonlyMap<string, DefaultFunctionRegistryEntry>;
43
-
44
- export interface MutationDefaultGeneratorDescriptor {
45
- readonly id: string;
46
- readonly applicableCodecIds: readonly string[];
47
- readonly resolveGeneratedColumnDescriptor?: (input: {
48
- readonly generated: ExecutionMutationDefaultValue;
49
- }) =>
50
- | {
51
- readonly codecId: string;
52
- readonly nativeType: string;
53
- readonly typeRef?: string;
54
- readonly typeParams?: Record<string, unknown>;
55
- }
56
- | undefined;
57
- }
58
-
59
- export interface ControlMutationDefaultEntry {
60
- readonly lower: (input: {
61
- readonly call: ParsedDefaultFunctionCall;
62
- readonly context: DefaultFunctionLoweringContext;
63
- }) => LoweredDefaultResult;
64
- readonly usageSignatures?: readonly string[];
65
- }
66
-
67
- export type ControlMutationDefaultRegistry = ReadonlyMap<string, ControlMutationDefaultEntry>;
68
-
69
- export interface ControlMutationDefaults {
70
- readonly defaultFunctionRegistry: ControlMutationDefaultRegistry;
71
- readonly generatorDescriptors: readonly MutationDefaultGeneratorDescriptor[];
72
- }
73
-
74
14
  function resolveSpanPositionFromBase(
75
15
  base: PslSpan,
76
16
  text: string,
@@ -5,7 +5,7 @@ export type {
5
5
  DefaultFunctionRegistry,
6
6
  DefaultFunctionRegistryEntry,
7
7
  MutationDefaultGeneratorDescriptor,
8
- } from '../default-function-registry';
8
+ } from '@prisma-next/framework-components/control';
9
9
  export {
10
10
  type InterpretPslDocumentToSqlContractInput,
11
11
  interpretPslDocumentToSqlContract,
@@ -15,6 +15,11 @@ import type {
15
15
  } from '@prisma-next/framework-components/authoring';
16
16
  import { instantiateAuthoringTypeConstructor } from '@prisma-next/framework-components/authoring';
17
17
  import type { ExtensionPackRef, TargetPackRef } from '@prisma-next/framework-components/components';
18
+ import type {
19
+ ControlMutationDefaultRegistry,
20
+ ControlMutationDefaults,
21
+ MutationDefaultGeneratorDescriptor,
22
+ } from '@prisma-next/framework-components/control';
18
23
  import type {
19
24
  ParsePslDocumentResult,
20
25
  PslAttribute,
@@ -34,11 +39,6 @@ import {
34
39
  } from '@prisma-next/sql-contract-ts/contract-builder';
35
40
  import { ifDefined } from '@prisma-next/utils/defined';
36
41
  import { notOk, ok, type Result } from '@prisma-next/utils/result';
37
- import type {
38
- ControlMutationDefaultRegistry,
39
- ControlMutationDefaults,
40
- MutationDefaultGeneratorDescriptor,
41
- } from './default-function-registry';
42
42
  import {
43
43
  getAttribute,
44
44
  getPositionalArgument,
package/src/provider.ts CHANGED
@@ -1,32 +1,35 @@
1
1
  import { readFile } from 'node:fs/promises';
2
2
  import type { ContractConfig, ContractSourceContext } from '@prisma-next/config/config-types';
3
- import type { AuthoringContributions } from '@prisma-next/framework-components/authoring';
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
8
  import { resolve } from 'pathe';
9
- import type { ControlMutationDefaults } from './default-function-registry';
10
9
  import { interpretPslDocumentToSqlContract } from './interpreter';
10
+ import type { ColumnDescriptor } from './psl-column-resolution';
11
11
 
12
12
  export interface PrismaContractOptions {
13
13
  readonly output?: string;
14
14
  readonly target: TargetPackRef<'sql', 'postgres'>;
15
- readonly authoringContributions?: AuthoringContributions;
16
- readonly scalarTypeDescriptors: ReadonlyMap<
17
- string,
18
- {
19
- readonly codecId: string;
20
- readonly nativeType: string;
21
- readonly typeRef?: string;
22
- readonly typeParams?: Record<string, unknown>;
23
- }
24
- >;
25
- readonly controlMutationDefaults?: ControlMutationDefaults;
26
- readonly composedExtensionPacks?: readonly string[];
27
15
  readonly composedExtensionPackRefs?: readonly ExtensionPackRef<'sql', 'postgres'>[];
28
16
  }
29
17
 
18
+ function buildColumnDescriptorMap(
19
+ scalarTypeDescriptors: ReadonlyMap<string, string>,
20
+ codecLookup: CodecLookup,
21
+ ): ReadonlyMap<string, ColumnDescriptor> {
22
+ const result = new Map<string, ColumnDescriptor>();
23
+ for (const [typeName, codecId] of scalarTypeDescriptors) {
24
+ const codec = codecLookup.get(codecId);
25
+ if (!codec) continue;
26
+ const nativeType = codec.targetTypes[0];
27
+ if (nativeType === undefined) continue;
28
+ result.set(typeName, { codecId, nativeType });
29
+ }
30
+ return result;
31
+ }
32
+
30
33
  export function prismaContract(schemaPath: string, options: PrismaContractOptions): ContractConfig {
31
34
  return {
32
35
  source: async (context: ContractSourceContext) => {
@@ -53,25 +56,28 @@ export function prismaContract(schemaPath: string, options: PrismaContractOption
53
56
  schema,
54
57
  sourceId: schemaPath,
55
58
  });
56
- const composedExtensionPacks = [
57
- ...(context.composedExtensionPacks ?? []),
58
- ...(options.composedExtensionPacks ?? []),
59
- ];
59
+
60
+ const scalarTypeDescriptors = buildColumnDescriptorMap(
61
+ context.scalarTypeDescriptors,
62
+ context.codecLookup,
63
+ );
60
64
 
61
65
  const interpreted = interpretPslDocumentToSqlContract({
62
66
  document,
63
67
  target: options.target,
64
- ...ifDefined('authoringContributions', options.authoringContributions),
65
- scalarTypeDescriptors: options.scalarTypeDescriptors,
68
+ authoringContributions: context.authoringContributions,
69
+ scalarTypeDescriptors,
66
70
  ...ifDefined(
67
71
  'composedExtensionPacks',
68
- composedExtensionPacks.length > 0 ? composedExtensionPacks : undefined,
72
+ context.composedExtensionPacks.length > 0
73
+ ? [...context.composedExtensionPacks]
74
+ : undefined,
69
75
  ),
70
76
  ...ifDefined(
71
77
  'composedExtensionPackRefs',
72
78
  options.composedExtensionPackRefs?.length ? options.composedExtensionPackRefs : undefined,
73
79
  ),
74
- ...ifDefined('controlMutationDefaults', options.controlMutationDefaults),
80
+ controlMutationDefaults: context.controlMutationDefaults,
75
81
  });
76
82
  if (!interpreted.ok) {
77
83
  return interpreted;
@@ -9,16 +9,16 @@ import {
9
9
  isAuthoringTypeConstructorDescriptor,
10
10
  validateAuthoringHelperArguments,
11
11
  } from '@prisma-next/framework-components/authoring';
12
+ import type {
13
+ ControlMutationDefaultRegistry,
14
+ MutationDefaultGeneratorDescriptor,
15
+ } from '@prisma-next/framework-components/control';
12
16
  import type {
13
17
  PslAttribute,
14
18
  PslField,
15
19
  PslSpan,
16
20
  PslTypeConstructorCall,
17
21
  } from '@prisma-next/psl-parser';
18
- import type {
19
- ControlMutationDefaultRegistry,
20
- MutationDefaultGeneratorDescriptor,
21
- } from './default-function-registry';
22
22
  import {
23
23
  lowerDefaultFunctionWithRegistry,
24
24
  parseDefaultFunctionCall,
@@ -1,12 +1,12 @@
1
1
  import type { ContractSourceDiagnostic } from '@prisma-next/config/config-types';
2
2
  import type { ColumnDefault, ExecutionMutationDefaultValue } from '@prisma-next/contract/types';
3
3
  import type { AuthoringContributions } from '@prisma-next/framework-components/authoring';
4
- import type { PslAttribute, PslField, PslModel } from '@prisma-next/psl-parser';
5
- import { ifDefined } from '@prisma-next/utils/defined';
6
4
  import type {
7
5
  ControlMutationDefaultRegistry,
8
6
  MutationDefaultGeneratorDescriptor,
9
- } from './default-function-registry';
7
+ } from '@prisma-next/framework-components/control';
8
+ import type { PslAttribute, PslField, PslModel } from '@prisma-next/psl-parser';
9
+ import { ifDefined } from '@prisma-next/utils/defined';
10
10
  import {
11
11
  getAttribute,
12
12
  lowerFirst,
@@ -1,71 +0,0 @@
1
- import { PslSpan } from "@prisma-next/psl-parser";
2
- import { ContractSourceDiagnostic } from "@prisma-next/config/config-types";
3
- import { ColumnDefault, ExecutionMutationDefaultValue } from "@prisma-next/contract/types";
4
-
5
- //#region src/default-function-registry.d.ts
6
- interface DefaultFunctionArgument {
7
- readonly raw: string;
8
- readonly span: PslSpan;
9
- }
10
- interface ParsedDefaultFunctionCall {
11
- readonly name: string;
12
- readonly raw: string;
13
- readonly args: readonly DefaultFunctionArgument[];
14
- readonly span: PslSpan;
15
- }
16
- interface DefaultFunctionLoweringContext {
17
- readonly sourceId: string;
18
- readonly modelName: string;
19
- readonly fieldName: string;
20
- readonly columnCodecId?: string;
21
- }
22
- type LoweredDefaultValue = {
23
- readonly kind: 'storage';
24
- readonly defaultValue: ColumnDefault;
25
- } | {
26
- readonly kind: 'execution';
27
- readonly generated: ExecutionMutationDefaultValue;
28
- };
29
- type LoweredDefaultResult = {
30
- readonly ok: true;
31
- readonly value: LoweredDefaultValue;
32
- } | {
33
- readonly ok: false;
34
- readonly diagnostic: ContractSourceDiagnostic;
35
- };
36
- type DefaultFunctionLoweringHandler = (input: {
37
- readonly call: ParsedDefaultFunctionCall;
38
- readonly context: DefaultFunctionLoweringContext;
39
- }) => LoweredDefaultResult;
40
- interface DefaultFunctionRegistryEntry {
41
- readonly lower: DefaultFunctionLoweringHandler;
42
- readonly usageSignatures?: readonly string[];
43
- }
44
- type DefaultFunctionRegistry = ReadonlyMap<string, DefaultFunctionRegistryEntry>;
45
- interface MutationDefaultGeneratorDescriptor {
46
- readonly id: string;
47
- readonly applicableCodecIds: readonly string[];
48
- readonly resolveGeneratedColumnDescriptor?: (input: {
49
- readonly generated: ExecutionMutationDefaultValue;
50
- }) => {
51
- readonly codecId: string;
52
- readonly nativeType: string;
53
- readonly typeRef?: string;
54
- readonly typeParams?: Record<string, unknown>;
55
- } | undefined;
56
- }
57
- interface ControlMutationDefaultEntry {
58
- readonly lower: (input: {
59
- readonly call: ParsedDefaultFunctionCall;
60
- readonly context: DefaultFunctionLoweringContext;
61
- }) => LoweredDefaultResult;
62
- readonly usageSignatures?: readonly string[];
63
- }
64
- type ControlMutationDefaultRegistry = ReadonlyMap<string, ControlMutationDefaultEntry>;
65
- interface ControlMutationDefaults {
66
- readonly defaultFunctionRegistry: ControlMutationDefaultRegistry;
67
- readonly generatorDescriptors: readonly MutationDefaultGeneratorDescriptor[];
68
- }
69
- //#endregion
70
- export { DefaultFunctionRegistryEntry as a, DefaultFunctionRegistry as i, DefaultFunctionLoweringContext as n, MutationDefaultGeneratorDescriptor as o, DefaultFunctionLoweringHandler as r, ControlMutationDefaults as t };
71
- //# sourceMappingURL=default-function-registry-DUMRIhJH.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"default-function-registry-DUMRIhJH.d.mts","names":[],"sources":["../src/default-function-registry.ts"],"sourcesContent":[],"mappings":";;;;;UAIU,uBAAA;;EAAA,SAAA,IAAA,EAEO,OAFP;AAKV;AAOiB,UAPA,yBAAA,CAO8B;EAOnC,SAAA,IAAA,EAAA,MAAA;EAIA,SAAA,GAAA,EAAA,MAAA;EAIA,SAAA,IAAA,EAAA,SAnBc,uBAmBgB,EAAA;EACzB,SAAA,IAAA,EAnBA,OAmBA;;AAEX,UAlBW,8BAAA,CAkBX;EAAoB,SAAA,QAAA,EAAA,MAAA;EAET,SAAA,SAAA,EAAA,MAAA;EAKL,SAAA,SAAA,EAAA,MAAuB;EAElB,SAAA,aAAA,CAAA,EAAA,MAAA;AAejB;AAEmB,KArCP,mBAAA,GAqCO;EACG,SAAA,IAAA,EAAA,SAAA;EACd,SAAA,YAAA,EAtC+C,aAsC/C;CAAoB,GAAA;EAIhB,SAAA,IAAA,EAAA,WAAA;EAEK,SAAA,SAAA,EA3CqC,6BA4ClB;;KA1CxB,oBAAA;;kBAC6B;;;uBACM;;KAEnC,8BAAA;iBACK;oBACG;MACd;UAEW,4BAAA;kBACC;;;KAIN,uBAAA,GAA0B,oBAAoB;UAEzC,kCAAA;;;;wBAIO;;;;;0BAMM;;;UAKb,2BAAA;;mBAEE;sBACG;QACd;;;KAII,8BAAA,GAAiC,oBAAoB;UAEhD,uBAAA;oCACmB;0CACM"}