@k0lyan/nestjs-prisma-graphql-generator 0.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/LICENSE +21 -0
- package/README.md +210 -0
- package/dist/cli/generator.d.ts +3 -0
- package/dist/cli/generator.d.ts.map +1 -0
- package/dist/cli/generator.js +24 -0
- package/dist/cli/generator.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +18 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/options-parser.d.ts +48 -0
- package/dist/cli/options-parser.d.ts.map +1 -0
- package/dist/cli/options-parser.js +61 -0
- package/dist/cli/options-parser.js.map +1 -0
- package/dist/cli/prisma-generator.d.ts +4 -0
- package/dist/cli/prisma-generator.d.ts.map +1 -0
- package/dist/cli/prisma-generator.js +27 -0
- package/dist/cli/prisma-generator.js.map +1 -0
- package/dist/generator/common.d.ts +7 -0
- package/dist/generator/common.d.ts.map +1 -0
- package/dist/generator/common.js +87 -0
- package/dist/generator/common.js.map +1 -0
- package/dist/generator/dmmf/document.d.ts +96 -0
- package/dist/generator/dmmf/document.d.ts.map +1 -0
- package/dist/generator/dmmf/document.js +223 -0
- package/dist/generator/dmmf/document.js.map +1 -0
- package/dist/generator/dmmf/index.d.ts +4 -0
- package/dist/generator/dmmf/index.d.ts.map +1 -0
- package/dist/generator/dmmf/index.js +20 -0
- package/dist/generator/dmmf/index.js.map +1 -0
- package/dist/generator/dmmf/transformer.d.ts +59 -0
- package/dist/generator/dmmf/transformer.d.ts.map +1 -0
- package/dist/generator/dmmf/transformer.js +247 -0
- package/dist/generator/dmmf/transformer.js.map +1 -0
- package/dist/generator/dmmf/types.d.ts +169 -0
- package/dist/generator/dmmf/types.d.ts.map +1 -0
- package/dist/generator/dmmf/types.js +32 -0
- package/dist/generator/dmmf/types.js.map +1 -0
- package/dist/generator/generate.d.ts +10 -0
- package/dist/generator/generate.d.ts.map +1 -0
- package/dist/generator/generate.js +131 -0
- package/dist/generator/generate.js.map +1 -0
- package/dist/generator/helpers-generator.d.ts +7 -0
- package/dist/generator/helpers-generator.d.ts.map +1 -0
- package/dist/generator/helpers-generator.js +216 -0
- package/dist/generator/helpers-generator.js.map +1 -0
- package/dist/generator/index.d.ts +7 -0
- package/dist/generator/index.d.ts.map +1 -0
- package/dist/generator/index.js +23 -0
- package/dist/generator/index.js.map +1 -0
- package/dist/generator/templates/args.d.ts +8 -0
- package/dist/generator/templates/args.d.ts.map +1 -0
- package/dist/generator/templates/args.js +650 -0
- package/dist/generator/templates/args.js.map +1 -0
- package/dist/generator/templates/enum.d.ts +8 -0
- package/dist/generator/templates/enum.d.ts.map +1 -0
- package/dist/generator/templates/enum.js +66 -0
- package/dist/generator/templates/enum.js.map +1 -0
- package/dist/generator/templates/index.d.ts +6 -0
- package/dist/generator/templates/index.d.ts.map +1 -0
- package/dist/generator/templates/index.js +22 -0
- package/dist/generator/templates/index.js.map +1 -0
- package/dist/generator/templates/input.d.ts +8 -0
- package/dist/generator/templates/input.d.ts.map +1 -0
- package/dist/generator/templates/input.js +248 -0
- package/dist/generator/templates/input.js.map +1 -0
- package/dist/generator/templates/model.d.ts +8 -0
- package/dist/generator/templates/model.d.ts.map +1 -0
- package/dist/generator/templates/model.js +184 -0
- package/dist/generator/templates/model.js.map +1 -0
- package/dist/generator/templates/resolver.d.ts +8 -0
- package/dist/generator/templates/resolver.d.ts.map +1 -0
- package/dist/generator/templates/resolver.js +456 -0
- package/dist/generator/templates/resolver.js.map +1 -0
- package/dist/generator/writers/file-writer.d.ts +10 -0
- package/dist/generator/writers/file-writer.d.ts.map +1 -0
- package/dist/generator/writers/file-writer.js +40 -0
- package/dist/generator/writers/file-writer.js.map +1 -0
- package/dist/generator/writers/index.d.ts +2 -0
- package/dist/generator/writers/index.d.ts.map +1 -0
- package/dist/generator/writers/index.js +18 -0
- package/dist/generator/writers/index.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime/helpers.d.ts +102 -0
- package/dist/runtime/helpers.d.ts.map +1 -0
- package/dist/runtime/helpers.js +210 -0
- package/dist/runtime/helpers.js.map +1 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +18 -0
- package/dist/runtime/index.js.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import type { DMMF } from '@prisma/generator-helper';
|
|
2
|
+
/**
|
|
3
|
+
* Scalar type mapping from Prisma to TypeScript/GraphQL
|
|
4
|
+
*/
|
|
5
|
+
export type ScalarType = 'String' | 'Int' | 'Float' | 'Boolean' | 'DateTime' | 'Json' | 'Bytes' | 'BigInt' | 'Decimal';
|
|
6
|
+
/**
|
|
7
|
+
* Mapping of Prisma scalar types to GraphQL scalar types
|
|
8
|
+
*/
|
|
9
|
+
export declare const PRISMA_TO_GRAPHQL_SCALAR: Record<string, string>;
|
|
10
|
+
/**
|
|
11
|
+
* Mapping of Prisma scalar types to TypeScript types
|
|
12
|
+
*/
|
|
13
|
+
export declare const PRISMA_TO_TS_TYPE: Record<string, string>;
|
|
14
|
+
/**
|
|
15
|
+
* Internal representation of a model field
|
|
16
|
+
*/
|
|
17
|
+
export interface ModelField {
|
|
18
|
+
name: string;
|
|
19
|
+
type: string;
|
|
20
|
+
kind: DMMF.FieldKind;
|
|
21
|
+
isList: boolean;
|
|
22
|
+
isRequired: boolean;
|
|
23
|
+
isUnique: boolean;
|
|
24
|
+
isId: boolean;
|
|
25
|
+
isReadOnly: boolean;
|
|
26
|
+
isGenerated: boolean;
|
|
27
|
+
isUpdatedAt: boolean;
|
|
28
|
+
hasDefaultValue: boolean;
|
|
29
|
+
default?: DMMF.FieldDefault | DMMF.FieldDefaultScalar | DMMF.FieldDefaultScalar[];
|
|
30
|
+
relationName?: string;
|
|
31
|
+
relationFromFields?: string[];
|
|
32
|
+
relationToFields?: string[];
|
|
33
|
+
documentation?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Internal representation of a model
|
|
37
|
+
*/
|
|
38
|
+
export interface Model {
|
|
39
|
+
name: string;
|
|
40
|
+
dbName: string | null;
|
|
41
|
+
fields: ModelField[];
|
|
42
|
+
primaryKey: PrimaryKey | null;
|
|
43
|
+
uniqueFields: string[][];
|
|
44
|
+
uniqueIndexes: UniqueIndex[];
|
|
45
|
+
documentation?: string;
|
|
46
|
+
isGenerated: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Primary key definition
|
|
50
|
+
*/
|
|
51
|
+
export interface PrimaryKey {
|
|
52
|
+
name: string | null;
|
|
53
|
+
fields: string[];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Unique index definition
|
|
57
|
+
*/
|
|
58
|
+
export interface UniqueIndex {
|
|
59
|
+
name: string | null;
|
|
60
|
+
fields: string[];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Internal representation of an enum
|
|
64
|
+
*/
|
|
65
|
+
export interface Enum {
|
|
66
|
+
name: string;
|
|
67
|
+
values: EnumValue[];
|
|
68
|
+
documentation?: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Enum value definition
|
|
72
|
+
*/
|
|
73
|
+
export interface EnumValue {
|
|
74
|
+
name: string;
|
|
75
|
+
dbName?: string | null;
|
|
76
|
+
documentation?: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Relation information between models
|
|
80
|
+
*/
|
|
81
|
+
export interface Relation {
|
|
82
|
+
name: string;
|
|
83
|
+
fromModel: string;
|
|
84
|
+
fromField: string;
|
|
85
|
+
toModel: string;
|
|
86
|
+
toField: string;
|
|
87
|
+
type: 'one-to-one' | 'one-to-many' | 'many-to-many';
|
|
88
|
+
isList: boolean;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* CRUD operation types
|
|
92
|
+
*/
|
|
93
|
+
export type CrudOperation = 'findUnique' | 'findFirst' | 'findMany' | 'create' | 'createMany' | 'update' | 'updateMany' | 'upsert' | 'delete' | 'deleteMany' | 'aggregate' | 'groupBy' | 'count';
|
|
94
|
+
/**
|
|
95
|
+
* Model mapping for CRUD operations
|
|
96
|
+
*/
|
|
97
|
+
export interface ModelMapping {
|
|
98
|
+
model: string;
|
|
99
|
+
plural: string;
|
|
100
|
+
findUnique?: string;
|
|
101
|
+
findFirst?: string;
|
|
102
|
+
findMany?: string;
|
|
103
|
+
create?: string;
|
|
104
|
+
createMany?: string;
|
|
105
|
+
update?: string;
|
|
106
|
+
updateMany?: string;
|
|
107
|
+
upsert?: string;
|
|
108
|
+
delete?: string;
|
|
109
|
+
deleteMany?: string;
|
|
110
|
+
aggregate?: string;
|
|
111
|
+
groupBy?: string;
|
|
112
|
+
count?: string;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Generated file representation
|
|
116
|
+
*/
|
|
117
|
+
export interface GeneratedFile {
|
|
118
|
+
path: string;
|
|
119
|
+
content: string;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Input type field
|
|
123
|
+
*/
|
|
124
|
+
export interface InputField {
|
|
125
|
+
name: string;
|
|
126
|
+
type: string;
|
|
127
|
+
isList: boolean;
|
|
128
|
+
isRequired: boolean;
|
|
129
|
+
isNullable: boolean;
|
|
130
|
+
inputTypes: InputTypeRef[];
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Reference to an input type
|
|
134
|
+
*/
|
|
135
|
+
export interface InputTypeRef {
|
|
136
|
+
type: string;
|
|
137
|
+
isList: boolean;
|
|
138
|
+
location: 'scalar' | 'enumTypes' | 'inputObjectTypes' | 'outputObjectTypes';
|
|
139
|
+
namespace?: 'prisma' | 'model';
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Input type definition
|
|
143
|
+
*/
|
|
144
|
+
export interface InputType {
|
|
145
|
+
name: string;
|
|
146
|
+
fields: InputField[];
|
|
147
|
+
constraints: {
|
|
148
|
+
maxNumFields?: number | null;
|
|
149
|
+
minNumFields?: number | null;
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Output type field
|
|
154
|
+
*/
|
|
155
|
+
export interface OutputField {
|
|
156
|
+
name: string;
|
|
157
|
+
type: string;
|
|
158
|
+
isList: boolean;
|
|
159
|
+
isNullable: boolean;
|
|
160
|
+
args: InputField[];
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Output type definition
|
|
164
|
+
*/
|
|
165
|
+
export interface OutputType {
|
|
166
|
+
name: string;
|
|
167
|
+
fields: OutputField[];
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/generator/dmmf/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,UAAU,GAClB,QAAQ,GACR,KAAK,GACL,OAAO,GACP,SAAS,GACT,UAAU,GACV,MAAM,GACN,OAAO,GACP,QAAQ,GACR,SAAS,CAAC;AAEd;;GAEG;AACH,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAU3D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAUpD,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;IACrB,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,E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zB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,YAAY,EAAE,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,QAAQ,GAAG,WAAW,GAAG,kBAAkB,GAAG,mBAAmB,CAAC;IAC5E,SAAS,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,WAAW,EAAE;QACX,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC7B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KAC9B,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;IACpB,IAAI,EAAE,UAAU,EAAE,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PRISMA_TO_TS_TYPE = exports.PRISMA_TO_GRAPHQL_SCALAR = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Mapping of Prisma scalar types to GraphQL scalar types
|
|
6
|
+
*/
|
|
7
|
+
exports.PRISMA_TO_GRAPHQL_SCALAR = {
|
|
8
|
+
String: 'String',
|
|
9
|
+
Int: 'Int',
|
|
10
|
+
Float: 'Float',
|
|
11
|
+
Boolean: 'Boolean',
|
|
12
|
+
DateTime: 'Date',
|
|
13
|
+
Json: 'GraphQLJSON',
|
|
14
|
+
Bytes: 'String', // Base64 encoded
|
|
15
|
+
BigInt: 'BigInt',
|
|
16
|
+
Decimal: 'Float',
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Mapping of Prisma scalar types to TypeScript types
|
|
20
|
+
*/
|
|
21
|
+
exports.PRISMA_TO_TS_TYPE = {
|
|
22
|
+
String: 'string',
|
|
23
|
+
Int: 'number',
|
|
24
|
+
Float: 'number',
|
|
25
|
+
Boolean: 'boolean',
|
|
26
|
+
DateTime: 'Date',
|
|
27
|
+
Json: 'any',
|
|
28
|
+
Bytes: 'Buffer',
|
|
29
|
+
BigInt: 'bigint',
|
|
30
|
+
Decimal: 'number',
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/generator/dmmf/types.ts"],"names":[],"mappings":";;;AAgBA;;GAEG;AACU,QAAA,wBAAwB,GAA2B;IAC9D,MAAM,EAAE,QAAQ;IAChB,GAAG,EAAE,KAAK;IACV,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,SAAS;IAClB,QAAQ,EAAE,MAAM;IAChB,IAAI,EAAE,aAAa;IACnB,KAAK,EAAE,QAAQ,EAAE,iBAAiB;IAClC,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,OAAO;CACjB,CAAC;AAEF;;GAEG;AACU,QAAA,iBAAiB,GAA2B;IACvD,MAAM,EAAE,QAAQ;IAChB,GAAG,EAAE,QAAQ;IACb,KAAK,EAAE,QAAQ;IACf,OAAO,EAAE,SAAS;IAClB,QAAQ,EAAE,MAAM;IAChB,IAAI,EAAE,KAAK;IACX,KAAK,EAAE,QAAQ;IACf,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,QAAQ;CAClB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DMMFDocument } from './dmmf/document';
|
|
2
|
+
import type { GeneratedFile } from './dmmf/types';
|
|
3
|
+
import type { GeneratorConfig } from '../cli/options-parser';
|
|
4
|
+
/**
|
|
5
|
+
* Main code generation orchestrator
|
|
6
|
+
*
|
|
7
|
+
* Coordinates generation of all code files from the DMMF document
|
|
8
|
+
*/
|
|
9
|
+
export declare function generateCode(dmmf: DMMFDocument, config: GeneratorConfig): Promise<GeneratedFile[]>;
|
|
10
|
+
//# sourceMappingURL=generate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/generator/generate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAS7D;;;;GAIG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,YAAY,EAClB,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,aAAa,EAAE,CAAC,CAsF1B"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateCode = generateCode;
|
|
4
|
+
const ts_morph_1 = require("ts-morph");
|
|
5
|
+
const args_1 = require("./templates/args");
|
|
6
|
+
const common_1 = require("./common");
|
|
7
|
+
const enum_1 = require("./templates/enum");
|
|
8
|
+
const helpers_generator_1 = require("./helpers-generator");
|
|
9
|
+
const input_1 = require("./templates/input");
|
|
10
|
+
const model_1 = require("./templates/model");
|
|
11
|
+
const resolver_1 = require("./templates/resolver");
|
|
12
|
+
/**
|
|
13
|
+
* Main code generation orchestrator
|
|
14
|
+
*
|
|
15
|
+
* Coordinates generation of all code files from the DMMF document
|
|
16
|
+
*/
|
|
17
|
+
async function generateCode(dmmf, config) {
|
|
18
|
+
const project = new ts_morph_1.Project({
|
|
19
|
+
useInMemoryFileSystem: true,
|
|
20
|
+
compilerOptions: {
|
|
21
|
+
declaration: true,
|
|
22
|
+
strict: true,
|
|
23
|
+
experimentalDecorators: true,
|
|
24
|
+
emitDecoratorMetadata: true,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
const allFiles = new Map();
|
|
28
|
+
// Check which blocks to emit
|
|
29
|
+
const emitAll = !config.emitOnly || config.emitOnly.length === 0;
|
|
30
|
+
const shouldEmit = (block) => emitAll || config.emitOnly?.includes(block);
|
|
31
|
+
// Generate enums
|
|
32
|
+
if (shouldEmit('enums')) {
|
|
33
|
+
const enumFiles = (0, enum_1.generateEnums)(project, dmmf, config);
|
|
34
|
+
for (const [path, file] of enumFiles) {
|
|
35
|
+
allFiles.set(path, file);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// Generate model types
|
|
39
|
+
if (shouldEmit('models')) {
|
|
40
|
+
const modelFiles = (0, model_1.generateModels)(project, dmmf, config);
|
|
41
|
+
for (const [path, file] of modelFiles) {
|
|
42
|
+
allFiles.set(path, file);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Generate input types
|
|
46
|
+
if (shouldEmit('inputs')) {
|
|
47
|
+
const inputFiles = (0, input_1.generateInputs)(project, dmmf, config);
|
|
48
|
+
for (const [path, file] of inputFiles) {
|
|
49
|
+
allFiles.set(path, file);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// Generate args types
|
|
53
|
+
if (shouldEmit('args')) {
|
|
54
|
+
const argsFiles = (0, args_1.generateArgs)(project, dmmf, config);
|
|
55
|
+
for (const [path, file] of argsFiles) {
|
|
56
|
+
allFiles.set(path, file);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Generate resolvers
|
|
60
|
+
if (shouldEmit('resolvers') && config.generateResolvers) {
|
|
61
|
+
const resolverFiles = (0, resolver_1.generateResolvers)(project, dmmf, config);
|
|
62
|
+
for (const [path, file] of resolverFiles) {
|
|
63
|
+
allFiles.set(path, file);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// Generate common types (AffectedRows, etc.)
|
|
67
|
+
const commonFiles = (0, common_1.generateCommonTypes)(project, config);
|
|
68
|
+
for (const [path, file] of commonFiles) {
|
|
69
|
+
allFiles.set(path, file);
|
|
70
|
+
}
|
|
71
|
+
// Generate helpers
|
|
72
|
+
if (shouldEmit('helpers')) {
|
|
73
|
+
const helperFiles = (0, helpers_generator_1.generateHelpers)(project, config);
|
|
74
|
+
for (const [path, file] of helperFiles) {
|
|
75
|
+
allFiles.set(path, file);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Generate root index file
|
|
79
|
+
const indexFile = project.createSourceFile('index.ts', '', { overwrite: true });
|
|
80
|
+
generateRootIndex(indexFile, config, dmmf);
|
|
81
|
+
allFiles.set('index.ts', indexFile);
|
|
82
|
+
// Convert to GeneratedFile array
|
|
83
|
+
const result = [];
|
|
84
|
+
for (const [path, sourceFile] of allFiles) {
|
|
85
|
+
result.push({
|
|
86
|
+
path,
|
|
87
|
+
content: sourceFile.getFullText(),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Generate root index.ts that exports everything
|
|
94
|
+
*/
|
|
95
|
+
function generateRootIndex(sourceFile, config, dmmf) {
|
|
96
|
+
const emitAll = !config.emitOnly || config.emitOnly.length === 0;
|
|
97
|
+
const shouldEmit = (block) => emitAll || config.emitOnly?.includes(block);
|
|
98
|
+
if (shouldEmit('enums') && dmmf.enums.length > 0) {
|
|
99
|
+
sourceFile.addExportDeclaration({
|
|
100
|
+
moduleSpecifier: `./${config.outputDirs?.enums ?? 'enums'}`,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
if (shouldEmit('models') && dmmf.models.length > 0) {
|
|
104
|
+
sourceFile.addExportDeclaration({
|
|
105
|
+
moduleSpecifier: `./${config.outputDirs?.models ?? 'models'}`,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
if (shouldEmit('inputs')) {
|
|
109
|
+
sourceFile.addExportDeclaration({
|
|
110
|
+
moduleSpecifier: `./${config.outputDirs?.inputs ?? 'inputs'}`,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
if (shouldEmit('args')) {
|
|
114
|
+
sourceFile.addExportDeclaration({
|
|
115
|
+
moduleSpecifier: `./${config.outputDirs?.args ?? 'args'}`,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
if (shouldEmit('resolvers') && config.generateResolvers) {
|
|
119
|
+
sourceFile.addExportDeclaration({
|
|
120
|
+
moduleSpecifier: `./${config.outputDirs?.resolvers ?? 'resolvers'}`,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
// Always export common types and helpers
|
|
124
|
+
sourceFile.addExportDeclaration({
|
|
125
|
+
moduleSpecifier: './common',
|
|
126
|
+
});
|
|
127
|
+
sourceFile.addExportDeclaration({
|
|
128
|
+
moduleSpecifier: './helpers',
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=generate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/generator/generate.ts"],"names":[],"mappings":";;AAkBA,oCAyFC;AA3GD,uCAA+C;AAK/C,2CAAgD;AAChD,qCAA+C;AAC/C,2CAAiD;AACjD,2DAAsD;AACtD,6CAAmD;AACnD,6CAAmD;AACnD,mDAAyD;AAEzD;;;;GAIG;AACI,KAAK,UAAU,YAAY,CAChC,IAAkB,EAClB,MAAuB;IAEvB,MAAM,OAAO,GAAG,IAAI,kBAAO,CAAC;QAC1B,qBAAqB,EAAE,IAAI;QAC3B,eAAe,EAAE;YACf,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B,eAAe,EAAE,KAAK,MAAM,CAAC,UAAU,EAAE,MAAM,IAAI,QAAQ,EAAE;SAC9D,CAAC,CAAC;IACL,CAAC;IAED,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QACzB,UAAU,CAAC,oBAAoB,CAAC;YAC9B,eAAe,EAAE,KAAK,MAAM,CAAC,UAAU,EAAE,MAAM,IAAI,QAAQ,EAAE;SAC9D,CAAC,CAAC;IACL,CAAC;IAED,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QACvB,UAAU,CAAC,oBAAoB,CAAC;YAC9B,eAAe,EAAE,KAAK,MAAM,CAAC,UAAU,EAAE,IAAI,IAAI,MAAM,EAAE;SAC1D,CAAC,CAAC;IACL,CAAC;IAED,IAAI,UAAU,CAAC,WAAW,CAAC,IAAI,MAAM,CAAC,iBAAiB,EAAE,CAAC;QACxD,UAAU,CAAC,oBAAoB,CAAC;YAC9B,eAAe,EAAE,KAAK,MAAM,CAAC,UAAU,EAAE,SAAS,IAAI,WAAW,EAAE;SACpE,CAAC,CAAC;IACL,CAAC;IAED,yCAAyC;IACzC,UAAU,CAAC,oBAAoB,CAAC;QAC9B,eAAe,EAAE,UAAU;KAC5B,CAAC,CAAC;IAEH,UAAU,CAAC,oBAAoB,CAAC;QAC9B,eAAe,EAAE,WAAW;KAC7B,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Project, SourceFile } from 'ts-morph';
|
|
2
|
+
import type { GeneratorConfig } from '../cli/options-parser';
|
|
3
|
+
/**
|
|
4
|
+
* Generate runtime helper files that will be included in the output
|
|
5
|
+
*/
|
|
6
|
+
export declare function generateHelpers(project: Project, config: GeneratorConfig): Map<string, SourceFile>;
|
|
7
|
+
//# sourceMappingURL=helpers-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers-generator.d.ts","sourceRoot":"","sources":["../../src/generator/helpers-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D;;GAEG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,eAAe,GACtB,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAUzB"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateHelpers = generateHelpers;
|
|
4
|
+
/**
|
|
5
|
+
* Generate runtime helper files that will be included in the output
|
|
6
|
+
*/
|
|
7
|
+
function generateHelpers(project, config) {
|
|
8
|
+
const files = new Map();
|
|
9
|
+
// Generate main helpers file
|
|
10
|
+
const helpersPath = 'helpers.ts';
|
|
11
|
+
const helpersFile = project.createSourceFile(helpersPath, '', { overwrite: true });
|
|
12
|
+
generateHelpersFile(helpersFile, config);
|
|
13
|
+
files.set(helpersPath, helpersFile);
|
|
14
|
+
return files;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Generate the helpers.ts file with runtime utilities
|
|
18
|
+
*/
|
|
19
|
+
function generateHelpersFile(sourceFile, _config) {
|
|
20
|
+
sourceFile.addStatements(`
|
|
21
|
+
/**
|
|
22
|
+
* Runtime helpers for NestJS Prisma GraphQL Generator
|
|
23
|
+
*
|
|
24
|
+
* These helpers are used at runtime to transform GraphQL queries
|
|
25
|
+
* into optimized Prisma select/include objects.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import type { GraphQLResolveInfo } from 'graphql';
|
|
29
|
+
import {
|
|
30
|
+
parseResolveInfo,
|
|
31
|
+
simplifyParsedResolveInfoFragmentWithType,
|
|
32
|
+
ResolveTree,
|
|
33
|
+
} from 'graphql-parse-resolve-info';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Prisma select/include object type
|
|
37
|
+
*/
|
|
38
|
+
export interface PrismaSelect {
|
|
39
|
+
select?: Record<string, boolean | PrismaSelect>;
|
|
40
|
+
include?: Record<string, boolean | PrismaSelect>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Context type that should contain the Prisma client
|
|
45
|
+
*/
|
|
46
|
+
export interface GraphQLContext {
|
|
47
|
+
prisma: any;
|
|
48
|
+
[key: string]: any;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Fields that should be excluded from selection
|
|
53
|
+
*/
|
|
54
|
+
const EXCLUDED_FIELDS = new Set([
|
|
55
|
+
'__typename',
|
|
56
|
+
'_count',
|
|
57
|
+
'_avg',
|
|
58
|
+
'_sum',
|
|
59
|
+
'_min',
|
|
60
|
+
'_max',
|
|
61
|
+
]);
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Transform GraphQL resolve info into Prisma select/include arguments
|
|
65
|
+
*
|
|
66
|
+
* This is the core optimization function that analyzes the GraphQL query
|
|
67
|
+
* and builds an optimal Prisma query with only the requested fields.
|
|
68
|
+
*
|
|
69
|
+
* @param info - GraphQL resolve info from the resolver
|
|
70
|
+
* @returns Prisma select object
|
|
71
|
+
*/
|
|
72
|
+
export function transformInfoIntoPrismaArgs(info: GraphQLResolveInfo): PrismaSelect {
|
|
73
|
+
const parsedInfo = parseResolveInfo(info);
|
|
74
|
+
|
|
75
|
+
if (!parsedInfo) {
|
|
76
|
+
return {};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const simplifiedInfo = simplifyParsedResolveInfoFragmentWithType(
|
|
80
|
+
parsedInfo as ResolveTree,
|
|
81
|
+
info.returnType,
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
return buildPrismaSelect(simplifiedInfo.fields);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Build Prisma select object from parsed GraphQL fields
|
|
89
|
+
*/
|
|
90
|
+
function buildPrismaSelect(fields: Record<string, ResolveTree>): PrismaSelect {
|
|
91
|
+
const select: Record<string, boolean | PrismaSelect> = {};
|
|
92
|
+
|
|
93
|
+
for (const [fieldName, fieldInfo] of Object.entries(fields)) {
|
|
94
|
+
if (EXCLUDED_FIELDS.has(fieldName)) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const nestedFields = fieldInfo.fieldsByTypeName;
|
|
99
|
+
const nestedTypes = Object.keys(nestedFields);
|
|
100
|
+
|
|
101
|
+
if (nestedTypes.length > 0) {
|
|
102
|
+
// Relation field
|
|
103
|
+
const allNestedFields: Record<string, ResolveTree> = {};
|
|
104
|
+
for (const typeName of nestedTypes) {
|
|
105
|
+
Object.assign(allNestedFields, nestedFields[typeName]);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const nestedSelect = buildPrismaSelect(allNestedFields);
|
|
109
|
+
|
|
110
|
+
if (Object.keys(nestedSelect).length > 0) {
|
|
111
|
+
select[fieldName] = nestedSelect;
|
|
112
|
+
} else {
|
|
113
|
+
select[fieldName] = true;
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
select[fieldName] = true;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (Object.keys(select).length === 0) {
|
|
121
|
+
return {};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return { select };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Get Prisma client from GraphQL context
|
|
129
|
+
*/
|
|
130
|
+
export function getPrismaFromContext(info: GraphQLResolveInfo): any {
|
|
131
|
+
const ctx = (info as any).variableValues?.context ||
|
|
132
|
+
(info as any).rootValue?.context ||
|
|
133
|
+
(info as any).context;
|
|
134
|
+
|
|
135
|
+
if (ctx?.prisma) {
|
|
136
|
+
return ctx.prisma;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const rootValue = info.rootValue as GraphQLContext | undefined;
|
|
140
|
+
if (rootValue?.prisma) {
|
|
141
|
+
return rootValue.prisma;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
throw new Error(
|
|
145
|
+
'Prisma client not found in GraphQL context. ' +
|
|
146
|
+
'Make sure to pass the Prisma client in the context: { prisma }'
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Transform count fields into Prisma _count select
|
|
152
|
+
*/
|
|
153
|
+
export function transformCountFieldIntoSelectRelationsCount(
|
|
154
|
+
fields: Record<string, ResolveTree>,
|
|
155
|
+
): { _count?: { select: Record<string, boolean> } } {
|
|
156
|
+
const countField = fields['_count'];
|
|
157
|
+
|
|
158
|
+
if (!countField) {
|
|
159
|
+
return {};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const countNestedFields = countField.fieldsByTypeName;
|
|
163
|
+
const countTypes = Object.keys(countNestedFields);
|
|
164
|
+
|
|
165
|
+
if (countTypes.length === 0) {
|
|
166
|
+
return {};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const countSelect: Record<string, boolean> = {};
|
|
170
|
+
|
|
171
|
+
for (const typeName of countTypes) {
|
|
172
|
+
const typeFields = countNestedFields[typeName];
|
|
173
|
+
if (typeFields) {
|
|
174
|
+
for (const fieldName of Object.keys(typeFields)) {
|
|
175
|
+
countSelect[fieldName] = true;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (Object.keys(countSelect).length === 0) {
|
|
181
|
+
return {};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
_count: {
|
|
186
|
+
select: countSelect,
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Merge multiple Prisma select objects
|
|
193
|
+
*/
|
|
194
|
+
export function mergePrismaSelects(...selects: PrismaSelect[]): PrismaSelect {
|
|
195
|
+
const result: PrismaSelect = {};
|
|
196
|
+
|
|
197
|
+
for (const select of selects) {
|
|
198
|
+
if (select.select) {
|
|
199
|
+
result.select = {
|
|
200
|
+
...result.select,
|
|
201
|
+
...select.select,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
if (select.include) {
|
|
205
|
+
result.include = {
|
|
206
|
+
...result.include,
|
|
207
|
+
...select.include,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
214
|
+
`);
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=helpers-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers-generator.js","sourceRoot":"","sources":["../../src/generator/helpers-generator.ts"],"names":[],"mappings":";;AAOA,0CAaC;AAhBD;;GAEG;AACH,SAAgB,eAAe,CAC7B,OAAgB,EAChB,MAAuB;IAEvB,MAAM,KAAK,GAAG,IAAI,GAAG,EAAsB,CAAC;IAE5C,6BAA6B;IAC7B,MAAM,WAAW,GAAG,YAAY,CAAC;IACjC,MAAM,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC,WAAW,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACnF,mBAAmB,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IACzC,KAAK,CAAC,GAAG,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;IAEpC,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,SAAS,mBAAmB,CAAC,UAAsB,EAAE,OAAwB;IAC3E,UAAU,CAAC,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkM1B,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./dmmf"), exports);
|
|
18
|
+
__exportStar(require("./templates"), exports);
|
|
19
|
+
__exportStar(require("./generate"), exports);
|
|
20
|
+
__exportStar(require("./common"), exports);
|
|
21
|
+
__exportStar(require("./helpers-generator"), exports);
|
|
22
|
+
__exportStar(require("./writers"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,8CAA4B;AAC5B,6CAA2B;AAC3B,2CAAyB;AACzB,sDAAoC;AACpC,4CAA0B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Project, SourceFile } from 'ts-morph';
|
|
2
|
+
import type { DMMFDocument } from '../dmmf/document';
|
|
3
|
+
import type { GeneratorConfig } from '../../cli/options-parser';
|
|
4
|
+
/**
|
|
5
|
+
* Generate Args type files for CRUD operations
|
|
6
|
+
*/
|
|
7
|
+
export declare function generateArgs(project: Project, dmmf: DMMFDocument, config: GeneratorConfig): Map<string, SourceFile>;
|
|
8
|
+
//# sourceMappingURL=args.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../../src/generator/templates/args.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAGhE;;GAEG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,YAAY,EAClB,MAAM,EAAE,eAAe,GACtB,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAoBzB"}
|