prisma-effect-kysely 1.1.0
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/CHANGELOG.md +46 -0
- package/LICENSE +21 -0
- package/README.md +219 -0
- package/dist/effect/enum.d.ts +10 -0
- package/dist/effect/enum.d.ts.map +1 -0
- package/dist/effect/enum.js +33 -0
- package/dist/effect/enum.js.map +1 -0
- package/dist/effect/generator.d.ts +33 -0
- package/dist/effect/generator.d.ts.map +1 -0
- package/dist/effect/generator.js +81 -0
- package/dist/effect/generator.js.map +1 -0
- package/dist/effect/type.d.ts +11 -0
- package/dist/effect/type.d.ts.map +1 -0
- package/dist/effect/type.js +64 -0
- package/dist/effect/type.js.map +1 -0
- package/dist/generator/index.d.ts +4 -0
- package/dist/generator/index.d.ts.map +1 -0
- package/dist/generator/index.js +34 -0
- package/dist/generator/index.js.map +1 -0
- package/dist/generator/orchestrator.d.ts +42 -0
- package/dist/generator/orchestrator.d.ts.map +1 -0
- package/dist/generator/orchestrator.js +111 -0
- package/dist/generator/orchestrator.js.map +1 -0
- package/dist/kysely/generator.d.ts +26 -0
- package/dist/kysely/generator.d.ts.map +1 -0
- package/dist/kysely/generator.js +44 -0
- package/dist/kysely/generator.js.map +1 -0
- package/dist/kysely/helpers.d.ts +50 -0
- package/dist/kysely/helpers.d.ts.map +1 -0
- package/dist/kysely/helpers.js +144 -0
- package/dist/kysely/helpers.js.map +1 -0
- package/dist/kysely/type.d.ts +33 -0
- package/dist/kysely/type.d.ts.map +1 -0
- package/dist/kysely/type.js +78 -0
- package/dist/kysely/type.js.map +1 -0
- package/dist/prisma/enum.d.ts +15 -0
- package/dist/prisma/enum.d.ts.map +1 -0
- package/dist/prisma/enum.js +25 -0
- package/dist/prisma/enum.js.map +1 -0
- package/dist/prisma/generator.d.ts +22 -0
- package/dist/prisma/generator.d.ts.map +1 -0
- package/dist/prisma/generator.js +69 -0
- package/dist/prisma/generator.js.map +1 -0
- package/dist/prisma/type.d.ts +47 -0
- package/dist/prisma/type.d.ts.map +1 -0
- package/dist/prisma/type.js +96 -0
- package/dist/prisma/type.js.map +1 -0
- package/dist/utils/annotations.d.ts +33 -0
- package/dist/utils/annotations.d.ts.map +1 -0
- package/dist/utils/annotations.js +86 -0
- package/dist/utils/annotations.js.map +1 -0
- package/dist/utils/file-manager.d.ts +20 -0
- package/dist/utils/file-manager.d.ts.map +1 -0
- package/dist/utils/file-manager.js +36 -0
- package/dist/utils/file-manager.js.map +1 -0
- package/dist/utils/templates.d.ts +2 -0
- package/dist/utils/templates.d.ts.map +1 -0
- package/dist/utils/templates.js +55 -0
- package/dist/utils/templates.js.map +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GeneratorOrchestrator = void 0;
|
|
4
|
+
const file_manager_1 = require("../utils/file-manager");
|
|
5
|
+
const generator_1 = require("../prisma/generator");
|
|
6
|
+
const generator_2 = require("../effect/generator");
|
|
7
|
+
const generator_3 = require("../kysely/generator");
|
|
8
|
+
/**
|
|
9
|
+
* Orchestrates the generation of Effect Schema types from Prisma schema
|
|
10
|
+
* Uses domain-driven generators: Prisma → Effect → Kysely
|
|
11
|
+
*/
|
|
12
|
+
class GeneratorOrchestrator {
|
|
13
|
+
constructor(options) {
|
|
14
|
+
const outputPath = this.validateOutputPath(options);
|
|
15
|
+
this.fileManager = new file_manager_1.FileManager(outputPath);
|
|
16
|
+
this.prismaGen = new generator_1.PrismaGenerator(options.dmmf);
|
|
17
|
+
this.effectGen = new generator_2.EffectGenerator(options.dmmf);
|
|
18
|
+
this.kyselyGen = new generator_3.KyselyGenerator(options.dmmf);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Validate and extract output path from generator options
|
|
22
|
+
*/
|
|
23
|
+
validateOutputPath(options) {
|
|
24
|
+
const outputPath = options.generator.output?.value;
|
|
25
|
+
if (!outputPath) {
|
|
26
|
+
throw new Error('Prisma Effect Generator: output path not configured.\n' +
|
|
27
|
+
'Add "output" to your generator block in schema.prisma');
|
|
28
|
+
}
|
|
29
|
+
return outputPath;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Main generation entry point
|
|
33
|
+
* Orchestrates all generation steps
|
|
34
|
+
*/
|
|
35
|
+
async generate(options) {
|
|
36
|
+
this.logStart(options);
|
|
37
|
+
// Ensure output directory exists
|
|
38
|
+
await this.fileManager.ensureDirectory();
|
|
39
|
+
// Generate all files in parallel for better performance
|
|
40
|
+
await Promise.all([
|
|
41
|
+
this.generateEnums(),
|
|
42
|
+
this.generateTypes(),
|
|
43
|
+
this.generateIndex(),
|
|
44
|
+
]);
|
|
45
|
+
this.logComplete();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Generate enums.ts file
|
|
49
|
+
*/
|
|
50
|
+
async generateEnums() {
|
|
51
|
+
const enums = this.prismaGen.getEnums();
|
|
52
|
+
const content = this.effectGen.generateEnums(enums);
|
|
53
|
+
await this.fileManager.writeFile('enums.ts', content);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Generate types.ts file
|
|
57
|
+
*/
|
|
58
|
+
async generateTypes() {
|
|
59
|
+
const models = this.prismaGen.getModels();
|
|
60
|
+
const hasEnums = this.prismaGen.getEnums().length > 0;
|
|
61
|
+
// Generate header with imports
|
|
62
|
+
const header = this.effectGen.generateTypesHeader(hasEnums);
|
|
63
|
+
// Generate all model schemas
|
|
64
|
+
const modelSchemas = models
|
|
65
|
+
.map((model) => {
|
|
66
|
+
const fields = this.prismaGen.getModelFields(model);
|
|
67
|
+
const baseSchemaName = `_${model.name}`;
|
|
68
|
+
// Generate base schema with Kysely fields
|
|
69
|
+
const kyselyFields = this.kyselyGen.generateModelFields(fields);
|
|
70
|
+
const baseSchema = `// ${model.name} Base Schema
|
|
71
|
+
export const ${baseSchemaName} = Schema.Struct({
|
|
72
|
+
${kyselyFields}
|
|
73
|
+
});`;
|
|
74
|
+
// Generate operational schemas and type exports
|
|
75
|
+
const operationalSchema = this.effectGen.generateOperationalSchemas(model);
|
|
76
|
+
const typeExports = this.effectGen.generateTypeExports(model);
|
|
77
|
+
return `${baseSchema}\n\n${operationalSchema}\n\n${typeExports}`;
|
|
78
|
+
})
|
|
79
|
+
.join('\n\n');
|
|
80
|
+
// Generate DB interface
|
|
81
|
+
const dbInterface = this.kyselyGen.generateDBInterface(models);
|
|
82
|
+
const content = `${header}\n\n${modelSchemas}\n\n${dbInterface}`;
|
|
83
|
+
await this.fileManager.writeFile('types.ts', content);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Generate index.ts file
|
|
87
|
+
*/
|
|
88
|
+
async generateIndex() {
|
|
89
|
+
const content = this.kyselyGen.generateIndexFile();
|
|
90
|
+
await this.fileManager.writeFile('index.ts', content);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Log generation start with stats
|
|
94
|
+
*/
|
|
95
|
+
logStart(options) {
|
|
96
|
+
const modelCount = options.dmmf.datamodel.models.filter((m) => !m.name.startsWith('_')).length;
|
|
97
|
+
const enumCount = options.dmmf.datamodel.enums.length;
|
|
98
|
+
console.log('[Prisma Effect Kysely Generator] Starting generation...');
|
|
99
|
+
console.log(`[Effect Generator] Processing ${modelCount} models, ${enumCount} enums`);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Log generation completion
|
|
103
|
+
*/
|
|
104
|
+
logComplete() {
|
|
105
|
+
const outputPath = this.fileManager.getOutputPath();
|
|
106
|
+
console.log(`[Effect Generator] ✓ Generated to ${outputPath}`);
|
|
107
|
+
console.log(`[Effect Generator] Files: enums.ts, types.ts, index.ts`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.GeneratorOrchestrator = GeneratorOrchestrator;
|
|
111
|
+
//# sourceMappingURL=orchestrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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
|
3
|
+
* Kysely domain generator - orchestrates Kysely integration
|
|
4
|
+
* Applies Kysely helpers to Effect schemas
|
|
5
|
+
*/
|
|
6
|
+
export declare class KyselyGenerator {
|
|
7
|
+
private readonly dmmf;
|
|
8
|
+
constructor(dmmf: DMMF.Document);
|
|
9
|
+
/**
|
|
10
|
+
* Generate field definition with Kysely helpers applied
|
|
11
|
+
*/
|
|
12
|
+
generateFieldWithKysely(field: DMMF.Field): string;
|
|
13
|
+
/**
|
|
14
|
+
* Generate all fields for a model with Kysely integration
|
|
15
|
+
*/
|
|
16
|
+
generateModelFields(fields: readonly DMMF.Field[]): string;
|
|
17
|
+
/**
|
|
18
|
+
* Generate DB interface for all models
|
|
19
|
+
*/
|
|
20
|
+
generateDBInterface(models: readonly DMMF.Model[]): string;
|
|
21
|
+
/**
|
|
22
|
+
* Generate index.ts re-export file
|
|
23
|
+
*/
|
|
24
|
+
generateIndexFile(): string;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/kysely/generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAKrD;;;GAGG;AACH,qBAAa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,IAAI,CAAC,QAAQ;IAEhD;;OAEG;IACH,uBAAuB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK;IAUzC;;OAEG;IACH,mBAAmB,CAAC,MAAM,EAAE,SAAS,IAAI,CAAC,KAAK,EAAE;IAIjD;;OAEG;IACH,mBAAmB,CAAC,MAAM,EAAE,SAAS,IAAI,CAAC,KAAK,EAAE;IAIjD;;OAEG;IACH,iBAAiB;CAGlB"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KyselyGenerator = void 0;
|
|
4
|
+
const type_1 = require("./type");
|
|
5
|
+
const type_2 = require("../effect/type");
|
|
6
|
+
/**
|
|
7
|
+
* Kysely domain generator - orchestrates Kysely integration
|
|
8
|
+
* Applies Kysely helpers to Effect schemas
|
|
9
|
+
*/
|
|
10
|
+
class KyselyGenerator {
|
|
11
|
+
constructor(dmmf) {
|
|
12
|
+
this.dmmf = dmmf;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Generate field definition with Kysely helpers applied
|
|
16
|
+
*/
|
|
17
|
+
generateFieldWithKysely(field) {
|
|
18
|
+
// Get base Effect type
|
|
19
|
+
const baseFieldType = (0, type_2.buildFieldType)(field, this.dmmf);
|
|
20
|
+
// Apply Kysely helpers and @map
|
|
21
|
+
const kyselyFieldType = (0, type_1.buildKyselyFieldType)(baseFieldType, field);
|
|
22
|
+
return ` ${field.name}: ${kyselyFieldType}`;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Generate all fields for a model with Kysely integration
|
|
26
|
+
*/
|
|
27
|
+
generateModelFields(fields) {
|
|
28
|
+
return Array.from(fields).map((field) => this.generateFieldWithKysely(field)).join(',\n');
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Generate DB interface for all models
|
|
32
|
+
*/
|
|
33
|
+
generateDBInterface(models) {
|
|
34
|
+
return (0, type_1.generateDBInterface)(models);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Generate index.ts re-export file
|
|
38
|
+
*/
|
|
39
|
+
generateIndexFile() {
|
|
40
|
+
return `export * from "./enums";\nexport * from "./types";`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.KyselyGenerator = KyselyGenerator;
|
|
44
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../src/kysely/generator.ts"],"names":[],"mappings":";;;AACA,iCAAmE;AACnE,yCAAgD;AAGhD;;;GAGG;AACH,MAAa,eAAe;IAC1B,YAA6B,IAAmB;QAAnB,SAAI,GAAJ,IAAI,CAAe;IAAG,CAAC;IAEpD;;OAEG;IACH,uBAAuB,CAAC,KAAiB;QACvC,uBAAuB;QACvB,MAAM,aAAa,GAAG,IAAA,qBAAc,EAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAEvD,gCAAgC;QAChC,MAAM,eAAe,GAAG,IAAA,2BAAoB,EAAC,aAAa,EAAE,KAAK,CAAC,CAAC;QAEnE,OAAO,KAAK,KAAK,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;IAC/C,CAAC;IAED;;OAEG;IACH,mBAAmB,CAAC,MAA6B;QAC/C,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5F,CAAC;IAED;;OAEG;IACH,mBAAmB,CAAC,MAA6B;QAC/C,OAAO,IAAA,0BAAmB,EAAC,MAAM,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,iBAAiB;QACf,OAAO,oDAAoD,CAAC;IAC9D,CAAC;CACF;AApCD,0CAoCC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as S from 'effect/Schema';
|
|
2
|
+
import { ColumnType, Insertable, Selectable, Updateable } from 'kysely';
|
|
3
|
+
/**
|
|
4
|
+
* Runtime helpers for Kysely schema integration
|
|
5
|
+
* These are imported by generated code
|
|
6
|
+
*/
|
|
7
|
+
export declare const ColumnTypeId: unique symbol;
|
|
8
|
+
export declare const GeneratedId: unique symbol;
|
|
9
|
+
/**
|
|
10
|
+
* Mark a field as having different types for select/insert/update
|
|
11
|
+
* Used for ID fields with @default (read-only)
|
|
12
|
+
*/
|
|
13
|
+
export declare const columnType: <SType, SEncoded, IType, IEncoded, UType, UEncoded>(selectSchema: S.Schema<SType, SEncoded>, insertSchema: S.Schema<IType, IEncoded>, updateSchema: S.Schema<UType, UEncoded>) => S.Schema<ColumnType<SType, IType, UType>, ColumnType<SEncoded, IEncoded, UEncoded>>;
|
|
14
|
+
/**
|
|
15
|
+
* Mark a field as database-generated (optional on insert)
|
|
16
|
+
* Used for fields with @default
|
|
17
|
+
*/
|
|
18
|
+
export declare const generated: <SType, SEncoded>(schema: S.Schema<SType, SEncoded>) => S.SchemaClass<unknown, unknown, never>;
|
|
19
|
+
/**
|
|
20
|
+
* Create selectable schema from base schema
|
|
21
|
+
*/
|
|
22
|
+
export declare const selectable: <Type, Encoded>(schema: S.Schema<Type, Encoded>) => S.Schema<Selectable<Type>, Selectable<Encoded>>;
|
|
23
|
+
/**
|
|
24
|
+
* Create insertable schema from base schema
|
|
25
|
+
*/
|
|
26
|
+
export declare const insertable: <Type, Encoded>(schema: S.Schema<Type, Encoded>) => S.Schema<Insertable<Type>, Insertable<Encoded>>;
|
|
27
|
+
/**
|
|
28
|
+
* Create updateable schema from base schema
|
|
29
|
+
*/
|
|
30
|
+
export declare const updateable: <Type, Encoded>(schema: S.Schema<Type, Encoded>) => S.SchemaClass<unknown, unknown, never>;
|
|
31
|
+
export interface Schemas<Type, Encoded> {
|
|
32
|
+
Selectable: S.Schema<Selectable<Type>, Selectable<Encoded>>;
|
|
33
|
+
Insertable: S.Schema<Insertable<Type>, Insertable<Encoded>>;
|
|
34
|
+
Updateable: S.Schema<Updateable<Type>, Updateable<Encoded>>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Generate all operational schemas (Selectable/Insertable/Updateable) from base schema
|
|
38
|
+
* Used in generated code
|
|
39
|
+
*/
|
|
40
|
+
export declare const getSchemas: <Type, Encoded>(baseSchema: S.Schema<Type, Encoded>) => {
|
|
41
|
+
Selectable: S.Schema<import("kysely/dist/cjs/util/type-utils").DrainOuterGeneric<{ [K_1 in { [K in keyof Type]: import("kysely").SelectType<Type[K]> extends infer T ? T extends import("kysely").SelectType<Type[K]> ? T extends never ? never : K : never : never; }[keyof Type]]: import("kysely").SelectType<Type[K_1]>; }>, import("kysely/dist/cjs/util/type-utils").DrainOuterGeneric<{ [K_3 in { [K_2 in keyof Encoded]: import("kysely").SelectType<Encoded[K_2]> extends infer T ? T extends import("kysely").SelectType<Encoded[K_2]> ? T extends never ? never : K_2 : never : never; }[keyof Encoded]]: import("kysely").SelectType<Encoded[K_3]>; }>, never>;
|
|
42
|
+
Insertable: S.Schema<import("kysely/dist/cjs/util/type-utils").DrainOuterGeneric<{ [K_4 in import("kysely").NonNullableInsertKeys<Type>]: import("kysely").InsertType<Type[K_4]>; } & { [K_5 in import("kysely").NullableInsertKeys<Type>]?: import("kysely").InsertType<Type[K_5]> | undefined; }>, import("kysely/dist/cjs/util/type-utils").DrainOuterGeneric<{ [K_6 in import("kysely").NonNullableInsertKeys<Encoded>]: import("kysely").InsertType<Encoded[K_6]>; } & { [K_7 in import("kysely").NullableInsertKeys<Encoded>]?: import("kysely").InsertType<Encoded[K_7]> | undefined; }>, never>;
|
|
43
|
+
Updateable: S.SchemaClass<unknown, unknown, never>;
|
|
44
|
+
};
|
|
45
|
+
export interface GetTypes<T extends Schemas<unknown, unknown>> {
|
|
46
|
+
Selectable: S.Schema.Type<T['Selectable']>;
|
|
47
|
+
Insertable: S.Schema.Type<T['Insertable']>;
|
|
48
|
+
Updateable: S.Schema.Type<T['Updateable']>;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/kysely/helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,eAAe,CAAC;AACnC,OAAO,EACL,UAAU,EAEV,UAAU,EACV,UAAU,EACV,UAAU,EACX,MAAM,QAAQ,CAAC;AAEhB;;;GAGG;AAEH,eAA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F,MAAM,WAAW,OAAO,CAAC,IAAI,EAAE,OAAO;IACpC,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;IAC5D,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;IAC5D,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;CAC7D;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,IAAI,EAAE,OAAO,EACtC,YAAY,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC;;;;CAKnC,CAAC;AAEH,MAAM,WAAW,QAAQ,CAAC,CAAC,SAAS,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC;IAC3D,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;IAC3C,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;IAC3C,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;CAC5C"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getSchemas = exports.updateable = exports.insertable = exports.selectable = exports.generated = exports.columnType = exports.GeneratedId = exports.ColumnTypeId = void 0;
|
|
37
|
+
const AST = __importStar(require("effect/SchemaAST"));
|
|
38
|
+
const S = __importStar(require("effect/Schema"));
|
|
39
|
+
/**
|
|
40
|
+
* Runtime helpers for Kysely schema integration
|
|
41
|
+
* These are imported by generated code
|
|
42
|
+
*/
|
|
43
|
+
exports.ColumnTypeId = Symbol.for('/ColumnTypeId');
|
|
44
|
+
exports.GeneratedId = Symbol.for('/GeneratedId');
|
|
45
|
+
/**
|
|
46
|
+
* Mark a field as having different types for select/insert/update
|
|
47
|
+
* Used for ID fields with @default (read-only)
|
|
48
|
+
*/
|
|
49
|
+
const columnType = (selectSchema, insertSchema, updateSchema) => {
|
|
50
|
+
const schemas = {
|
|
51
|
+
selectSchema,
|
|
52
|
+
insertSchema,
|
|
53
|
+
updateSchema,
|
|
54
|
+
};
|
|
55
|
+
return S.make(AST.annotations(S.Never.ast, { [exports.ColumnTypeId]: schemas }));
|
|
56
|
+
};
|
|
57
|
+
exports.columnType = columnType;
|
|
58
|
+
/**
|
|
59
|
+
* Mark a field as database-generated (optional on insert)
|
|
60
|
+
* Used for fields with @default
|
|
61
|
+
*/
|
|
62
|
+
const generated = (schema) => {
|
|
63
|
+
const schemas = {
|
|
64
|
+
selectSchema: schema,
|
|
65
|
+
insertSchema: S.Union(schema, S.Undefined),
|
|
66
|
+
updateSchema: schema,
|
|
67
|
+
};
|
|
68
|
+
return S.make(AST.annotations(S.Never.ast, { [exports.GeneratedId]: schemas }));
|
|
69
|
+
};
|
|
70
|
+
exports.generated = generated;
|
|
71
|
+
/**
|
|
72
|
+
* Create selectable schema from base schema
|
|
73
|
+
*/
|
|
74
|
+
const selectable = (schema) => {
|
|
75
|
+
const { ast } = schema;
|
|
76
|
+
if (!AST.isTypeLiteral(ast)) {
|
|
77
|
+
return S.make(ast);
|
|
78
|
+
}
|
|
79
|
+
return S.make(new AST.TypeLiteral(extractParametersFromTypeLiteral(ast, 'selectSchema'), ast.indexSignatures, ast.annotations));
|
|
80
|
+
};
|
|
81
|
+
exports.selectable = selectable;
|
|
82
|
+
/**
|
|
83
|
+
* Create insertable schema from base schema
|
|
84
|
+
*/
|
|
85
|
+
const insertable = (schema) => {
|
|
86
|
+
const { ast } = schema;
|
|
87
|
+
if (!AST.isTypeLiteral(ast)) {
|
|
88
|
+
return S.make(ast);
|
|
89
|
+
}
|
|
90
|
+
const extracted = extractParametersFromTypeLiteral(ast, 'insertSchema');
|
|
91
|
+
const res = new AST.TypeLiteral(extracted.map((prop) => new AST.PropertySignature(prop.name, prop.type, isOptionalType(prop.type), prop.isReadonly, prop.annotations)), ast.indexSignatures, ast.annotations);
|
|
92
|
+
return S.make(res);
|
|
93
|
+
};
|
|
94
|
+
exports.insertable = insertable;
|
|
95
|
+
/**
|
|
96
|
+
* Create updateable schema from base schema
|
|
97
|
+
*/
|
|
98
|
+
const updateable = (schema) => {
|
|
99
|
+
const { ast } = schema;
|
|
100
|
+
if (!AST.isTypeLiteral(ast)) {
|
|
101
|
+
return S.make(ast);
|
|
102
|
+
}
|
|
103
|
+
const extracted = extractParametersFromTypeLiteral(ast, 'updateSchema');
|
|
104
|
+
const res = new AST.TypeLiteral(extracted.map((prop) => new AST.PropertySignature(prop.name, AST.Union.make([prop.type, new AST.UndefinedKeyword()]), true, prop.isReadonly, prop.annotations)), ast.indexSignatures, ast.annotations);
|
|
105
|
+
return S.make(res);
|
|
106
|
+
};
|
|
107
|
+
exports.updateable = updateable;
|
|
108
|
+
/**
|
|
109
|
+
* Generate all operational schemas (Selectable/Insertable/Updateable) from base schema
|
|
110
|
+
* Used in generated code
|
|
111
|
+
*/
|
|
112
|
+
const getSchemas = (baseSchema) => ({
|
|
113
|
+
Selectable: (0, exports.selectable)(baseSchema),
|
|
114
|
+
Insertable: (0, exports.insertable)(baseSchema),
|
|
115
|
+
Updateable: (0, exports.updateable)(baseSchema),
|
|
116
|
+
});
|
|
117
|
+
exports.getSchemas = getSchemas;
|
|
118
|
+
const extractParametersFromTypeLiteral = (ast, schemaType) => {
|
|
119
|
+
return ast.propertySignatures
|
|
120
|
+
.map((prop) => {
|
|
121
|
+
if (isColumnType(prop.type)) {
|
|
122
|
+
const schemas = prop.type.annotations[exports.ColumnTypeId];
|
|
123
|
+
return new AST.PropertySignature(prop.name, schemas[schemaType].ast, prop.isOptional, prop.isReadonly, prop.annotations);
|
|
124
|
+
}
|
|
125
|
+
if (isGeneratedType(prop.type)) {
|
|
126
|
+
const schemas = prop.type.annotations[exports.GeneratedId];
|
|
127
|
+
return new AST.PropertySignature(prop.name, schemas[schemaType].ast, prop.isOptional, prop.isReadonly, prop.annotations);
|
|
128
|
+
}
|
|
129
|
+
return prop;
|
|
130
|
+
})
|
|
131
|
+
.filter((prop) => prop.type._tag !== 'NeverKeyword');
|
|
132
|
+
};
|
|
133
|
+
const isColumnType = (ast) => exports.ColumnTypeId in ast.annotations;
|
|
134
|
+
const isGeneratedType = (ast) => exports.GeneratedId in ast.annotations;
|
|
135
|
+
const isOptionalType = (ast) => {
|
|
136
|
+
if (!AST.isUnion(ast)) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
return (ast.types.some((t) => AST.isUndefinedKeyword(t)) ||
|
|
140
|
+
ast.types.some((t) => isNullType(t)));
|
|
141
|
+
};
|
|
142
|
+
const isNullType = (ast) => AST.isLiteral(ast) &&
|
|
143
|
+
Object.entries(ast.annotations).find(([sym, value]) => sym === AST.IdentifierAnnotationId.toString() && value === 'null');
|
|
144
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/kysely/helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAwC;AACxC,iDAAmC;AASnC;;;GAGG;AAEU,QAAA,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AAC3C,QAAA,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;AActD;;;GAGG;AACI,MAAM,UAAU,GAAG,CACxB,YAAuC,EACvC,YAAuC,EACvC,YAAuC,EAIvC,EAAE;IACF,MAAM,OAAO,GAOT;QACF,YAAY;QACZ,YAAY;QACZ,YAAY;KACb,CAAC;IACF,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,CAAC,oBAAY,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;AAC3E,CAAC,CAAC;AArBW,Q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AC,CAAC;AAcF,MAAM,YAAY,GAAG,CAAC,GAAY,EAAE,EAAE,CAAC,oBAAY,IAAI,GAAG,CAAC,WAAW,CAAC;AAEvE,MAAM,eAAe,GAAG,CAAC,GAAY,EAAE,EAAE,CAAC,mBAAW,IAAI,GAAG,CAAC,WAAW,CAAC;AAEzE,MAAM,cAAc,GAAG,CAAC,GAAY,EAAE,EAAE;IACtC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACtB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,CACL,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAU,EAAE,EAAE,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;QACzD,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAU,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAC9C,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,GAAY,EAAE,EAAE,CAClC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC;IAClB,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,CAClC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CACf,GAAG,KAAK,GAAG,CAAC,sBAAsB,CAAC,QAAQ,EAAE,IAAI,KAAK,KAAK,MAAM,CACpE,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { DMMF } from '@prisma/generator-helper';
|
|
2
|
+
/**
|
|
3
|
+
* Determine if field needs Kysely columnType wrapper
|
|
4
|
+
* ID fields with @default are read-only (can't insert/update)
|
|
5
|
+
*/
|
|
6
|
+
export declare function needsColumnType(field: DMMF.Field): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Determine if field needs Kysely generated wrapper
|
|
9
|
+
* Regular fields with @default are optional on insert
|
|
10
|
+
*/
|
|
11
|
+
export declare function needsGenerated(field: DMMF.Field): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Apply Kysely helper wrappers to a field type
|
|
14
|
+
*/
|
|
15
|
+
export declare function applyKyselyHelpers(fieldType: string, field: DMMF.Field): string;
|
|
16
|
+
/**
|
|
17
|
+
* Apply @map directive wrapper if field has different DB name
|
|
18
|
+
*/
|
|
19
|
+
export declare function applyMapDirective(fieldType: string, field: DMMF.Field): string;
|
|
20
|
+
/**
|
|
21
|
+
* Build complete field type with Kysely helpers and @map
|
|
22
|
+
* Order: base type � Kysely helpers � @map wrapper
|
|
23
|
+
*/
|
|
24
|
+
export declare function buildKyselyFieldType(baseFieldType: string, field: DMMF.Field): string;
|
|
25
|
+
/**
|
|
26
|
+
* Generate DB interface entry for a model
|
|
27
|
+
*/
|
|
28
|
+
export declare function generateDBInterfaceEntry(model: DMMF.Model): string;
|
|
29
|
+
/**
|
|
30
|
+
* Generate complete DB interface
|
|
31
|
+
*/
|
|
32
|
+
export declare function generateDBInterface(models: readonly DMMF.Model[]): string;
|
|
33
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../src/kysely/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAGrD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,WAEhD;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,WAE/C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,UAOtE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,UAMrE;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,IAAI,CAAC,KAAK,UASlB;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,UAIzD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,IAAI,CAAC,KAAK,EAAE,UAShE"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.needsColumnType = needsColumnType;
|
|
4
|
+
exports.needsGenerated = needsGenerated;
|
|
5
|
+
exports.applyKyselyHelpers = applyKyselyHelpers;
|
|
6
|
+
exports.applyMapDirective = applyMapDirective;
|
|
7
|
+
exports.buildKyselyFieldType = buildKyselyFieldType;
|
|
8
|
+
exports.generateDBInterfaceEntry = generateDBInterfaceEntry;
|
|
9
|
+
exports.generateDBInterface = generateDBInterface;
|
|
10
|
+
const type_1 = require("../prisma/type");
|
|
11
|
+
/**
|
|
12
|
+
* Determine if field needs Kysely columnType wrapper
|
|
13
|
+
* ID fields with @default are read-only (can't insert/update)
|
|
14
|
+
*/
|
|
15
|
+
function needsColumnType(field) {
|
|
16
|
+
return (0, type_1.hasDefaultValue)(field) && (0, type_1.isIdField)(field);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Determine if field needs Kysely generated wrapper
|
|
20
|
+
* Regular fields with @default are optional on insert
|
|
21
|
+
*/
|
|
22
|
+
function needsGenerated(field) {
|
|
23
|
+
return (0, type_1.hasDefaultValue)(field) && !(0, type_1.isIdField)(field);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Apply Kysely helper wrappers to a field type
|
|
27
|
+
*/
|
|
28
|
+
function applyKyselyHelpers(fieldType, field) {
|
|
29
|
+
if (needsColumnType(field)) {
|
|
30
|
+
return `columnType(${fieldType}, Schema.Never, Schema.Never)`;
|
|
31
|
+
}
|
|
32
|
+
else if (needsGenerated(field)) {
|
|
33
|
+
return `generated(${fieldType})`;
|
|
34
|
+
}
|
|
35
|
+
return fieldType;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Apply @map directive wrapper if field has different DB name
|
|
39
|
+
*/
|
|
40
|
+
function applyMapDirective(fieldType, field) {
|
|
41
|
+
const dbName = (0, type_1.getFieldDbName)(field);
|
|
42
|
+
if (field.dbName && field.dbName !== field.name) {
|
|
43
|
+
return `Schema.propertySignature(${fieldType}).pipe(Schema.fromKey("${dbName}"))`;
|
|
44
|
+
}
|
|
45
|
+
return fieldType;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Build complete field type with Kysely helpers and @map
|
|
49
|
+
* Order: base type � Kysely helpers � @map wrapper
|
|
50
|
+
*/
|
|
51
|
+
function buildKyselyFieldType(baseFieldType, field) {
|
|
52
|
+
// Step 1: Apply Kysely helpers (domain transformation)
|
|
53
|
+
let fieldType = applyKyselyHelpers(baseFieldType, field);
|
|
54
|
+
// Step 2: Apply @map wrapper (structural transformation)
|
|
55
|
+
fieldType = applyMapDirective(fieldType, field);
|
|
56
|
+
return fieldType;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Generate DB interface entry for a model
|
|
60
|
+
*/
|
|
61
|
+
function generateDBInterfaceEntry(model) {
|
|
62
|
+
const tableName = model.dbName || model.name;
|
|
63
|
+
const baseSchemaName = `_${model.name}`;
|
|
64
|
+
return ` ${tableName}: Schema.Schema.Encoded<typeof ${baseSchemaName}>;`;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Generate complete DB interface
|
|
68
|
+
*/
|
|
69
|
+
function generateDBInterface(models) {
|
|
70
|
+
const tableEntries = Array.from(models)
|
|
71
|
+
.map(generateDBInterfaceEntry)
|
|
72
|
+
.join('\n');
|
|
73
|
+
return `// Kysely Database Interface
|
|
74
|
+
export interface DB {
|
|
75
|
+
${tableEntries}
|
|
76
|
+
}`;
|
|
77
|
+
}
|
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G,kBAAkB,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;IAEzD,yDAAyD;IACzD,SAAS,GAAG,iBAAiB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAEhD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;GAEG;AACH,SAAgB,wBAAwB,CAAC,KAAiB;IACxD,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC;IAC7C,MAAM,cAAc,GAAG,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;IACxC,OAAO,KAAK,SAAS,kCAAkC,cAAc,IAAI,CAAC;AAC5E,CAAC;AAED;;GAEG;AACH,SAAgB,mBAAmB,CAAC,MAA6B;IAC/D,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;SACpC,GAAG,CAAC,wBAAwB,CAAC;SAC7B,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,OAAO;;EAEP,YAAY;EACZ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DMMF } from '@prisma/generator-helper';
|
|
2
|
+
/**
|
|
3
|
+
* Extract enum definitions from Prisma DMMF
|
|
4
|
+
* Handles @map directive for database-level enum values
|
|
5
|
+
*/
|
|
6
|
+
export declare function extractEnums(dmmf: DMMF.Document): readonly DMMF.DatamodelEnum[];
|
|
7
|
+
/**
|
|
8
|
+
* Get the database value for an enum value (respects @map directive)
|
|
9
|
+
*/
|
|
10
|
+
export declare function getEnumValueDbName(enumValue: DMMF.EnumValue): string;
|
|
11
|
+
/**
|
|
12
|
+
* Get all database values for an enum
|
|
13
|
+
*/
|
|
14
|
+
export declare function getEnumDbValues(enumDef: DMMF.DatamodelEnum): string[];
|
|
15
|
+
//# sourceMappingURL=enum.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../src/prisma/enum.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAErD;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,IAAI,CAAC,QAAQ,GAClB,SAAS,IAAI,CAAC,aAAa,EAAE,CAE/B;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,UAE3D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa,YAE1D"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractEnums = extractEnums;
|
|
4
|
+
exports.getEnumValueDbName = getEnumValueDbName;
|
|
5
|
+
exports.getEnumDbValues = getEnumDbValues;
|
|
6
|
+
/**
|
|
7
|
+
* Extract enum definitions from Prisma DMMF
|
|
8
|
+
* Handles @map directive for database-level enum values
|
|
9
|
+
*/
|
|
10
|
+
function extractEnums(dmmf) {
|
|
11
|
+
return dmmf.datamodel.enums;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get the database value for an enum value (respects @map directive)
|
|
15
|
+
*/
|
|
16
|
+
function getEnumValueDbName(enumValue) {
|
|
17
|
+
return enumValue.dbName ?? enumValue.name;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Get all database values for an enum
|
|
21
|
+
*/
|
|
22
|
+
function getEnumDbValues(enumDef) {
|
|
23
|
+
return enumDef.values.map(getEnumValueDbName);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum.js","sourceRoot":"","sources":["../../src/prisma/enum.ts"],"names":[],"mappings":";;AAMA,oCAIC;AAKD,gDAEC;AAKD,0CAEC;AAtBD;;;GAGG;AACH,SAAgB,YAAY,CAC1B,IAAmB;IAEnB,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;AAC9B,CAAC;AAED;;GAEG;AACH,SAAgB,kBAAkB,CAAC,SAAyB;IAC1D,OAAO,SAAS,CAAC,MAAM,IAAI,SAAS,CAAC,IAAI,CAAC;AAC5C,CAAC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,OAA2B;IACzD,OAAO,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { DMMF } from '@prisma/generator-helper';
|
|
2
|
+
/**
|
|
3
|
+
* Prisma domain generator - orchestrates DMMF parsing and extraction
|
|
4
|
+
* No schema generation here, just native Prisma data extraction
|
|
5
|
+
*/
|
|
6
|
+
export declare class PrismaGenerator {
|
|
7
|
+
private readonly dmmf;
|
|
8
|
+
constructor(dmmf: DMMF.Document);
|
|
9
|
+
/**
|
|
10
|
+
* Get all enums from DMMF
|
|
11
|
+
*/
|
|
12
|
+
getEnums(): readonly DMMF.DatamodelEnum[];
|
|
13
|
+
/**
|
|
14
|
+
* Get all models from DMMF (filtered and sorted)
|
|
15
|
+
*/
|
|
16
|
+
getModels(): readonly DMMF.Model[];
|
|
17
|
+
/**
|
|
18
|
+
* Get schema fields for a model (filtered and sorted)
|
|
19
|
+
*/
|
|
20
|
+
getModelFields(model: DMMF.Model): readonly DMMF.Field[];
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/prisma/generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAIrD;;;GAGG;AACH,qBAAa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,IAAI,CAAC,QAAQ;IAEhD;;OAEG;IACH,QAAQ,IAAI,SAAS,IAAI,CAAC,aAAa,EAAE;IAIzC;;OAEG;IACH,SAAS,IAAI,SAAS,IAAI,CAAC,KAAK,EAAE;IAOlC;;OAEG;IACH,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,GAAG,SAAS,IAAI,CAAC,KAAK,EAAE;CAIzD"}
|