@prisma-next/psl-printer 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.
- package/LICENSE +201 -0
- package/README.md +30 -0
- package/dist/index.d.mts +45 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +972 -0
- package/dist/index.mjs.map +1 -0
- package/dist/postgres.d.mts +32 -0
- package/dist/postgres.d.mts.map +1 -0
- package/dist/postgres.mjs +358 -0
- package/dist/postgres.mjs.map +1 -0
- package/dist/types-BmnVaMF1.d.mts +54 -0
- package/dist/types-BmnVaMF1.d.mts.map +1 -0
- package/package.json +52 -0
- package/src/default-mapping.ts +85 -0
- package/src/exports/index.ts +8 -0
- package/src/exports/postgres.ts +8 -0
- package/src/name-transforms.ts +234 -0
- package/src/postgres-default-mapping.ts +16 -0
- package/src/postgres-type-map.ts +204 -0
- package/src/print-psl.ts +881 -0
- package/src/raw-default-parser.ts +108 -0
- package/src/relation-inference.ts +239 -0
- package/src/schema-validation.ts +308 -0
- package/src/types.ts +119 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { ColumnDefault } from '@prisma-next/contract/types';
|
|
2
|
+
import type { DefaultMappingOptions } from './default-mapping';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Result of resolving a native database type to a PSL type.
|
|
6
|
+
*/
|
|
7
|
+
export type PslNativeTypeAttribute = {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly args?: readonly string[];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type PslTypeResolution =
|
|
13
|
+
| {
|
|
14
|
+
readonly pslType: string;
|
|
15
|
+
readonly nativeType: string;
|
|
16
|
+
readonly typeParams?: Record<string, unknown>;
|
|
17
|
+
readonly nativeTypeAttribute?: PslNativeTypeAttribute;
|
|
18
|
+
}
|
|
19
|
+
| {
|
|
20
|
+
readonly unsupported: true;
|
|
21
|
+
readonly nativeType: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Interface for mapping native database types to PSL scalar types.
|
|
26
|
+
* Implementations are target-specific (e.g., Postgres, MySQL).
|
|
27
|
+
*/
|
|
28
|
+
export interface PslTypeMap {
|
|
29
|
+
resolve(nativeType: string, annotations?: Record<string, unknown>): PslTypeResolution;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Pre-extracted enum information from target-specific annotations.
|
|
34
|
+
*/
|
|
35
|
+
export interface EnumInfo {
|
|
36
|
+
readonly typeNames: ReadonlySet<string>;
|
|
37
|
+
readonly definitions: ReadonlyMap<string, readonly string[]>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Options for the PSL printer.
|
|
42
|
+
*/
|
|
43
|
+
export interface PslPrinterOptions {
|
|
44
|
+
readonly typeMap: PslTypeMap;
|
|
45
|
+
readonly header?: string;
|
|
46
|
+
readonly defaultMapping?: DefaultMappingOptions;
|
|
47
|
+
/** Pre-extracted enum info. Required for schemas with enum types. */
|
|
48
|
+
readonly enumInfo?: EnumInfo;
|
|
49
|
+
/** Target-specific parser for raw default expressions (e.g., Postgres SQL dialect). */
|
|
50
|
+
readonly parseRawDefault?: (rawDefault: string, nativeType?: string) => ColumnDefault | undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Normalized column default, accepted by the printer.
|
|
55
|
+
* Re-exported for convenience.
|
|
56
|
+
*/
|
|
57
|
+
export type { ColumnDefault };
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A processed field ready for serialization.
|
|
61
|
+
*/
|
|
62
|
+
export type PrinterField = {
|
|
63
|
+
readonly name: string;
|
|
64
|
+
readonly typeName: string;
|
|
65
|
+
readonly optional: boolean;
|
|
66
|
+
readonly list: boolean;
|
|
67
|
+
readonly attributes: readonly string[];
|
|
68
|
+
readonly mapName?: string | undefined;
|
|
69
|
+
readonly isId: boolean;
|
|
70
|
+
readonly isRelation: boolean;
|
|
71
|
+
readonly isUnsupported: boolean;
|
|
72
|
+
readonly comment?: string | undefined;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A processed model ready for serialization.
|
|
77
|
+
*/
|
|
78
|
+
export type PrinterModel = {
|
|
79
|
+
readonly name: string;
|
|
80
|
+
readonly mapName?: string | undefined;
|
|
81
|
+
readonly fields: readonly PrinterField[];
|
|
82
|
+
readonly modelAttributes: readonly string[];
|
|
83
|
+
readonly comment?: string | undefined;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* A processed enum ready for serialization.
|
|
88
|
+
*/
|
|
89
|
+
export type PrinterEnum = {
|
|
90
|
+
readonly name: string;
|
|
91
|
+
readonly mapName?: string | undefined;
|
|
92
|
+
readonly values: readonly string[];
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* A named type entry for the types block.
|
|
97
|
+
*/
|
|
98
|
+
export type PrinterNamedType = {
|
|
99
|
+
readonly name: string;
|
|
100
|
+
readonly baseType: string;
|
|
101
|
+
readonly attributes: readonly string[];
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Relation field metadata used during inference.
|
|
106
|
+
*/
|
|
107
|
+
export type RelationField = {
|
|
108
|
+
readonly fieldName: string;
|
|
109
|
+
readonly typeName: string;
|
|
110
|
+
readonly referencedTableName?: string | undefined;
|
|
111
|
+
readonly optional: boolean;
|
|
112
|
+
readonly list: boolean;
|
|
113
|
+
readonly relationName?: string | undefined;
|
|
114
|
+
readonly fkName?: string | undefined;
|
|
115
|
+
readonly fields?: readonly string[] | undefined;
|
|
116
|
+
readonly references?: readonly string[] | undefined;
|
|
117
|
+
readonly onDelete?: string | undefined;
|
|
118
|
+
readonly onUpdate?: string | undefined;
|
|
119
|
+
};
|