@prisma-next/sql-contract-psl 0.0.1 → 0.3.0-dev.113

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/src/provider.ts CHANGED
@@ -1,33 +1,32 @@
1
1
  import { readFile } from 'node:fs/promises';
2
- import type { ContractConfig } from '@prisma-next/config/config-types';
2
+ import type { ContractConfig, ContractSourceContext } from '@prisma-next/config/config-types';
3
3
  import type { TargetPackRef } from '@prisma-next/contract/framework-components';
4
4
  import { parsePslDocument } from '@prisma-next/psl-parser';
5
5
  import { ifDefined } from '@prisma-next/utils/defined';
6
- import { notOk } from '@prisma-next/utils/result';
6
+ import { notOk, ok } from '@prisma-next/utils/result';
7
7
  import { resolve } from 'pathe';
8
+ import type { ControlMutationDefaults } from './default-function-registry';
8
9
  import { interpretPslDocumentToSqlContractIR } from './interpreter';
9
10
 
10
11
  export interface PrismaContractOptions {
11
12
  readonly output?: string;
12
- readonly target?: TargetPackRef<'sql', 'postgres'>;
13
- /**
14
- * Milestone-local namespace availability hook.
15
- *
16
- * This currently models composed extension packs by id only (for example `["pgvector"]`),
17
- * and is sufficient for namespace presence checks in the PSL interpreter.
18
- *
19
- * Future milestones can evolve this to richer composed pack metadata/manifests when
20
- * attribute-level schema/argument validation needs to move beyond namespace existence.
21
- */
13
+ readonly target: TargetPackRef<'sql', 'postgres'>;
14
+ readonly scalarTypeDescriptors: ReadonlyMap<
15
+ string,
16
+ {
17
+ readonly codecId: string;
18
+ readonly nativeType: string;
19
+ readonly typeRef?: string;
20
+ readonly typeParams?: Record<string, unknown>;
21
+ }
22
+ >;
23
+ readonly controlMutationDefaults?: ControlMutationDefaults;
22
24
  readonly composedExtensionPacks?: readonly string[];
23
25
  }
24
26
 
25
- export function prismaContract(
26
- schemaPath: string,
27
- options?: PrismaContractOptions,
28
- ): ContractConfig {
27
+ export function prismaContract(schemaPath: string, options: PrismaContractOptions): ContractConfig {
29
28
  return {
30
- source: async () => {
29
+ source: async (context: ContractSourceContext) => {
31
30
  const absoluteSchemaPath = resolve(schemaPath);
32
31
  let schema: string;
33
32
  try {
@@ -51,13 +50,27 @@ export function prismaContract(
51
50
  schema,
52
51
  sourceId: schemaPath,
53
52
  });
53
+ const composedExtensionPacks = [
54
+ ...(context.composedExtensionPacks ?? []),
55
+ ...(options.composedExtensionPacks ?? []),
56
+ ];
54
57
 
55
- return interpretPslDocumentToSqlContractIR({
58
+ const interpreted = interpretPslDocumentToSqlContractIR({
56
59
  document,
57
- ...ifDefined('target', options?.target),
58
- ...ifDefined('composedExtensionPacks', options?.composedExtensionPacks),
60
+ target: options.target,
61
+ scalarTypeDescriptors: options.scalarTypeDescriptors,
62
+ ...ifDefined(
63
+ 'composedExtensionPacks',
64
+ composedExtensionPacks.length > 0 ? composedExtensionPacks : undefined,
65
+ ),
66
+ ...ifDefined('controlMutationDefaults', options.controlMutationDefaults),
59
67
  });
68
+ if (!interpreted.ok) {
69
+ return interpreted;
70
+ }
71
+
72
+ return ok(interpreted.value);
60
73
  },
61
- ...ifDefined('output', options?.output),
74
+ ...ifDefined('output', options.output),
62
75
  };
63
76
  }