@prisma-next/sql-contract-psl 0.0.1

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.
@@ -0,0 +1,63 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import type { ContractConfig } from '@prisma-next/config/config-types';
3
+ import type { TargetPackRef } from '@prisma-next/contract/framework-components';
4
+ import { parsePslDocument } from '@prisma-next/psl-parser';
5
+ import { ifDefined } from '@prisma-next/utils/defined';
6
+ import { notOk } from '@prisma-next/utils/result';
7
+ import { resolve } from 'pathe';
8
+ import { interpretPslDocumentToSqlContractIR } from './interpreter';
9
+
10
+ export interface PrismaContractOptions {
11
+ 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
+ */
22
+ readonly composedExtensionPacks?: readonly string[];
23
+ }
24
+
25
+ export function prismaContract(
26
+ schemaPath: string,
27
+ options?: PrismaContractOptions,
28
+ ): ContractConfig {
29
+ return {
30
+ source: async () => {
31
+ const absoluteSchemaPath = resolve(schemaPath);
32
+ let schema: string;
33
+ try {
34
+ schema = await readFile(absoluteSchemaPath, 'utf-8');
35
+ } catch (error) {
36
+ const message = String(error);
37
+ return notOk({
38
+ summary: `Failed to read Prisma schema at "${schemaPath}"`,
39
+ diagnostics: [
40
+ {
41
+ code: 'PSL_SCHEMA_READ_FAILED',
42
+ message,
43
+ sourceId: schemaPath,
44
+ },
45
+ ],
46
+ meta: { schemaPath, absoluteSchemaPath, cause: message },
47
+ });
48
+ }
49
+
50
+ const document = parsePslDocument({
51
+ schema,
52
+ sourceId: schemaPath,
53
+ });
54
+
55
+ return interpretPslDocumentToSqlContractIR({
56
+ document,
57
+ ...ifDefined('target', options?.target),
58
+ ...ifDefined('composedExtensionPacks', options?.composedExtensionPacks),
59
+ });
60
+ },
61
+ ...ifDefined('output', options?.output),
62
+ };
63
+ }