prisma-nestjs-graphql 19.0.0 → 19.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/README.md +11 -2
- package/generate.cjs +53 -11
- package/generate.d.ts +10 -27
- package/package.json +19 -19
package/README.md
CHANGED
|
@@ -116,9 +116,18 @@ with temporal dead zone when generating merged file.
|
|
|
116
116
|
Type: `boolean`
|
|
117
117
|
Default: `false`
|
|
118
118
|
|
|
119
|
-
#### `
|
|
119
|
+
#### `emitBlocks`
|
|
120
|
+
Emit only selected blocks. Be aware, that some blocks do depend on others, e.g. one can't emit `models` without emitting `enums`.
|
|
121
|
+
Type: `("args" | "inputs" | "outputs" | "models" | "enums")[]`
|
|
122
|
+
Default: `["args", "inputs", "outputs", "models", "enums"]`
|
|
120
123
|
|
|
121
|
-
|
|
124
|
+
#### `omitModelsCount`
|
|
125
|
+
Omit `_count` field from models.
|
|
126
|
+
Type: `boolean`
|
|
127
|
+
Default: `false`
|
|
128
|
+
|
|
129
|
+
#### `purgeOutput`
|
|
130
|
+
Delete all files in `output` folder.
|
|
122
131
|
Type: `boolean`
|
|
123
132
|
Default: `false`
|
|
124
133
|
|
package/generate.cjs
CHANGED
|
@@ -565,12 +565,18 @@ function getPropertyType(args) {
|
|
|
565
565
|
|
|
566
566
|
function getWhereUniqueAtLeastKeys(model) {
|
|
567
567
|
const names = model.fields.filter((field) => field.isUnique || field.isId).map((field) => field.name);
|
|
568
|
+
if (model.primaryKey) {
|
|
569
|
+
names.push(createFieldName(model.primaryKey));
|
|
570
|
+
}
|
|
568
571
|
for (const uniqueIndex of model.uniqueIndexes) {
|
|
569
|
-
|
|
570
|
-
names.push(name);
|
|
572
|
+
names.push(createFieldName(uniqueIndex));
|
|
571
573
|
}
|
|
572
574
|
return names.map((name) => `'${name}'`).join(" | ");
|
|
573
575
|
}
|
|
576
|
+
function createFieldName(args) {
|
|
577
|
+
const { name, fields } = args;
|
|
578
|
+
return name || fields.join("_");
|
|
579
|
+
}
|
|
574
580
|
|
|
575
581
|
function isWhereUniqueInputType(name) {
|
|
576
582
|
return name.endsWith("WhereUniqueInput");
|
|
@@ -1153,6 +1159,8 @@ function modelOutputType(outputType, args) {
|
|
|
1153
1159
|
importDeclarations.add("Field", nestjsGraphql$1);
|
|
1154
1160
|
importDeclarations.add("ObjectType", nestjsGraphql$1);
|
|
1155
1161
|
for (const field of outputType.fields) {
|
|
1162
|
+
if (config.omitModelsCount && field.name === "_count")
|
|
1163
|
+
continue;
|
|
1156
1164
|
let fileType = "model";
|
|
1157
1165
|
const { location, isList, type, namespace } = field.outputType;
|
|
1158
1166
|
let outputTypeName = String(type);
|
|
@@ -1347,6 +1355,8 @@ function outputType(outputType2, args) {
|
|
|
1347
1355
|
const model = models.get(modelName);
|
|
1348
1356
|
const isAggregateOutput = model && /(?:Count|Avg|Sum|Min|Max)AggregateOutputType$/.test(outputType2.name) && String(outputType2.name).startsWith(model.name);
|
|
1349
1357
|
const isCountOutput = (model == null ? void 0 : model.name) && outputType2.name === `${model.name}CountOutputType`;
|
|
1358
|
+
if (!config.emitBlocks.outputs && !isCountOutput)
|
|
1359
|
+
return;
|
|
1350
1360
|
outputType2.name = getOutputTypeName(outputType2.name);
|
|
1351
1361
|
if (isAggregateOutput) {
|
|
1352
1362
|
eventEmitter.emitSync("AggregateOutput", { ...args, outputType: outputType2 });
|
|
@@ -1590,7 +1600,9 @@ function getNamespaceExportDeclaration(directory, sourceDirectory) {
|
|
|
1590
1600
|
}
|
|
1591
1601
|
|
|
1592
1602
|
function registerEnum(enumType, args) {
|
|
1593
|
-
const { getSourceFile, enums } = args;
|
|
1603
|
+
const { getSourceFile, enums, config } = args;
|
|
1604
|
+
if (!config.emitBlocks.prismaEnums && !enums[enumType.name])
|
|
1605
|
+
return;
|
|
1594
1606
|
const dataModelEnum = enums[enumType.name];
|
|
1595
1607
|
const sourceFile = getSourceFile({
|
|
1596
1608
|
name: enumType.name,
|
|
@@ -1643,6 +1655,30 @@ function warning(message) {
|
|
|
1643
1655
|
}
|
|
1644
1656
|
}
|
|
1645
1657
|
|
|
1658
|
+
const allEmmittedBlocks = ["prismaEnums", "schemaEnums", "models", "inputs", "args", "outputs"];
|
|
1659
|
+
const blocksDependencyMap = {
|
|
1660
|
+
enums: ["schemaEnums", "prismaEnums"],
|
|
1661
|
+
models: ["models", "schemaEnums"],
|
|
1662
|
+
inputs: ["inputs", "prismaEnums"],
|
|
1663
|
+
outputs: ["outputs"],
|
|
1664
|
+
args: ["args", "inputs", "prismaEnums"]
|
|
1665
|
+
};
|
|
1666
|
+
function createEmitBlocks(data) {
|
|
1667
|
+
if (!data) {
|
|
1668
|
+
return Object.fromEntries(allEmmittedBlocks.map((block) => [block, true]));
|
|
1669
|
+
}
|
|
1670
|
+
let blocksToEmit = {};
|
|
1671
|
+
for (const block of data) {
|
|
1672
|
+
if (!Object.keys(blocksDependencyMap).includes(block))
|
|
1673
|
+
continue;
|
|
1674
|
+
blocksToEmit = {
|
|
1675
|
+
...blocksToEmit,
|
|
1676
|
+
...Object.fromEntries(blocksDependencyMap[block].map((block2) => [block2, true]))
|
|
1677
|
+
};
|
|
1678
|
+
}
|
|
1679
|
+
return blocksToEmit;
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1646
1682
|
function createConfig(data) {
|
|
1647
1683
|
var _a;
|
|
1648
1684
|
const config = lodash.merge({}, flat.unflatten(data, { delimiter: "_" }));
|
|
@@ -1711,6 +1747,8 @@ function createConfig(data) {
|
|
|
1711
1747
|
reExport: ReExport[String(config.reExport)] || ReExport.None,
|
|
1712
1748
|
emitSingle: toBoolean(config.emitSingle),
|
|
1713
1749
|
emitCompiled: toBoolean(config.emitCompiled),
|
|
1750
|
+
emitBlocks: createEmitBlocks(config.emitBlocks),
|
|
1751
|
+
omitModelsCount: toBoolean(config.omitModelsCount),
|
|
1714
1752
|
$warnings,
|
|
1715
1753
|
fields,
|
|
1716
1754
|
purgeOutput: toBoolean(config.purgeOutput),
|
|
@@ -1923,17 +1961,21 @@ async function generate(args) {
|
|
|
1923
1961
|
const { connectCallback, generator, skipAddOutputSourceFiles, dmmf } = args;
|
|
1924
1962
|
const generatorOutputValue = (_a = generator.output) == null ? void 0 : _a.value;
|
|
1925
1963
|
assert.ok(generatorOutputValue, "Missing generator configuration: output");
|
|
1964
|
+
const config = createConfig(generator.config);
|
|
1926
1965
|
const eventEmitter = new AwaitEventEmitter__default["default"]();
|
|
1927
1966
|
eventEmitter.on("Warning", warning);
|
|
1928
|
-
eventEmitter.on("Model", modelData);
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1967
|
+
config.emitBlocks.models && eventEmitter.on("Model", modelData);
|
|
1968
|
+
if (config.emitBlocks.prismaEnums || config.emitBlocks.schemaEnums) {
|
|
1969
|
+
eventEmitter.on("EnumType", registerEnum);
|
|
1970
|
+
}
|
|
1971
|
+
if (config.emitBlocks.outputs || config.emitBlocks.models && !config.omitModelsCount) {
|
|
1972
|
+
eventEmitter.on("OutputType", outputType);
|
|
1973
|
+
}
|
|
1974
|
+
config.emitBlocks.models && eventEmitter.on("ModelOutputType", modelOutputType);
|
|
1975
|
+
config.emitBlocks.outputs && eventEmitter.on("AggregateOutput", createAggregateInput);
|
|
1976
|
+
config.emitBlocks.inputs && eventEmitter.on("InputType", inputType);
|
|
1977
|
+
config.emitBlocks.args && eventEmitter.on("ArgsType", argsType);
|
|
1935
1978
|
eventEmitter.on("GenerateFiles", generateFiles);
|
|
1936
|
-
const config = createConfig(generator.config);
|
|
1937
1979
|
for (const message of config.$warnings) {
|
|
1938
1980
|
eventEmitter.emitSync("Warning", message);
|
|
1939
1981
|
}
|
package/generate.d.ts
CHANGED
|
@@ -82,7 +82,6 @@ declare namespace DMMF {
|
|
|
82
82
|
relationOnDelete?: string;
|
|
83
83
|
relationName?: string;
|
|
84
84
|
documentation?: string;
|
|
85
|
-
[key: string]: any;
|
|
86
85
|
}
|
|
87
86
|
export interface FieldDefault {
|
|
88
87
|
name: string;
|
|
@@ -118,25 +117,24 @@ declare namespace DMMF {
|
|
|
118
117
|
isRequired: boolean;
|
|
119
118
|
isList: boolean;
|
|
120
119
|
}
|
|
121
|
-
export type
|
|
122
|
-
export interface SchemaArgInputType {
|
|
120
|
+
export type TypeRef<AllowedLocations extends FieldLocation> = {
|
|
123
121
|
isList: boolean;
|
|
124
|
-
type:
|
|
125
|
-
location:
|
|
122
|
+
type: string;
|
|
123
|
+
location: AllowedLocations;
|
|
126
124
|
namespace?: FieldNamespace;
|
|
127
|
-
}
|
|
125
|
+
};
|
|
126
|
+
export type InputTypeRef = TypeRef<'scalar' | 'inputObjectTypes' | 'enumTypes' | 'fieldRefTypes'>;
|
|
128
127
|
export interface SchemaArg {
|
|
129
128
|
name: string;
|
|
130
129
|
comment?: string;
|
|
131
130
|
isNullable: boolean;
|
|
132
131
|
isRequired: boolean;
|
|
133
|
-
inputTypes:
|
|
132
|
+
inputTypes: InputTypeRef[];
|
|
134
133
|
deprecation?: Deprecation;
|
|
135
134
|
}
|
|
136
135
|
export interface OutputType {
|
|
137
136
|
name: string;
|
|
138
137
|
fields: SchemaField[];
|
|
139
|
-
fieldMap?: Record<string, SchemaField>;
|
|
140
138
|
}
|
|
141
139
|
export interface SchemaField {
|
|
142
140
|
name: string;
|
|
@@ -146,23 +144,7 @@ declare namespace DMMF {
|
|
|
146
144
|
deprecation?: Deprecation;
|
|
147
145
|
documentation?: string;
|
|
148
146
|
}
|
|
149
|
-
export type
|
|
150
|
-
isList: boolean;
|
|
151
|
-
namespace?: FieldNamespace;
|
|
152
|
-
};
|
|
153
|
-
export type TypeRefScalar = TypeRefCommon & {
|
|
154
|
-
location: 'scalar';
|
|
155
|
-
type: string;
|
|
156
|
-
};
|
|
157
|
-
export type TypeRefOutputObject = TypeRefCommon & {
|
|
158
|
-
location: 'outputObjectTypes';
|
|
159
|
-
type: OutputType | string;
|
|
160
|
-
};
|
|
161
|
-
export type TypeRefEnum = TypeRefCommon & {
|
|
162
|
-
location: 'enumTypes';
|
|
163
|
-
type: SchemaEnum | string;
|
|
164
|
-
};
|
|
165
|
-
export type OutputTypeRef = TypeRefScalar | TypeRefOutputObject | TypeRefEnum;
|
|
147
|
+
export type OutputTypeRef = TypeRef<'scalar' | 'outputObjectTypes' | 'enumTypes'>;
|
|
166
148
|
export interface Deprecation {
|
|
167
149
|
sinceVersion: string;
|
|
168
150
|
reason: string;
|
|
@@ -179,14 +161,13 @@ declare namespace DMMF {
|
|
|
179
161
|
source?: string;
|
|
180
162
|
};
|
|
181
163
|
fields: SchemaArg[];
|
|
182
|
-
fieldMap?: Record<string, SchemaArg>;
|
|
183
164
|
}
|
|
184
165
|
export interface FieldRefType {
|
|
185
166
|
name: string;
|
|
186
167
|
allowTypes: FieldRefAllowType[];
|
|
187
168
|
fields: SchemaArg[];
|
|
188
169
|
}
|
|
189
|
-
export type FieldRefAllowType =
|
|
170
|
+
export type FieldRefAllowType = TypeRef<'scalar' | 'enumTypes'>;
|
|
190
171
|
export interface ModelMapping {
|
|
191
172
|
model: string;
|
|
192
173
|
plural: string;
|
|
@@ -254,6 +235,8 @@ declare function createConfig(data: Record<string, unknown>): {
|
|
|
254
235
|
reExport: ReExport;
|
|
255
236
|
emitSingle: boolean;
|
|
256
237
|
emitCompiled: boolean;
|
|
238
|
+
emitBlocks: Record<"models" | "inputs" | "args" | "outputs" | "prismaEnums" | "schemaEnums", boolean>;
|
|
239
|
+
omitModelsCount: boolean;
|
|
257
240
|
$warnings: string[];
|
|
258
241
|
fields: Record<string, Partial<Omit<ObjectSetting, "name">> | undefined>;
|
|
259
242
|
purgeOutput: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prisma-nestjs-graphql",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Generate object types, inputs, args, etc. from prisma schema file for usage with @nestjs/graphql module",
|
|
6
6
|
"bin": "bin.js",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@prisma/generator-helper": "^5.
|
|
73
|
+
"@prisma/generator-helper": "^5.1.1",
|
|
74
74
|
"await-event-emitter": "^2.0.2",
|
|
75
75
|
"filenamify": "4.X",
|
|
76
76
|
"flat": "^5.0.2",
|
|
@@ -87,44 +87,44 @@
|
|
|
87
87
|
"@commitlint/cli": "^17.6.7",
|
|
88
88
|
"@commitlint/config-conventional": "^17.6.7",
|
|
89
89
|
"@nestjs/apollo": "^12.0.7",
|
|
90
|
-
"@nestjs/common": "^10.1.
|
|
91
|
-
"@nestjs/core": "^10.1.
|
|
90
|
+
"@nestjs/common": "^10.1.3",
|
|
91
|
+
"@nestjs/core": "^10.1.3",
|
|
92
92
|
"@nestjs/graphql": "^12.0.8",
|
|
93
|
-
"@nestjs/platform-express": "^10.1.
|
|
93
|
+
"@nestjs/platform-express": "^10.1.3",
|
|
94
94
|
"@paljs/plugins": "^5.3.3",
|
|
95
|
-
"@prisma/client": "^5.
|
|
95
|
+
"@prisma/client": "^5.1.1",
|
|
96
96
|
"@semantic-release/changelog": "^6.0.3",
|
|
97
97
|
"@semantic-release/git": "^10.0.1",
|
|
98
|
-
"@swc/core": "^1.3.
|
|
98
|
+
"@swc/core": "^1.3.74",
|
|
99
99
|
"@swc/helpers": "^0.5.1",
|
|
100
100
|
"@swc/register": "^0.1.10",
|
|
101
101
|
"@types/flat": "^5.0.2",
|
|
102
102
|
"@types/graceful-fs": "^4.1.6",
|
|
103
|
-
"@types/lodash": "^4.14.
|
|
103
|
+
"@types/lodash": "^4.14.196",
|
|
104
104
|
"@types/mocha": "^10.0.1",
|
|
105
|
-
"@types/node": "^20.4.
|
|
105
|
+
"@types/node": "^20.4.7",
|
|
106
106
|
"@types/pluralize": "^0.0.30",
|
|
107
|
-
"@typescript-eslint/eslint-plugin": "^6.2.
|
|
108
|
-
"@typescript-eslint/parser": "^6.2.
|
|
107
|
+
"@typescript-eslint/eslint-plugin": "^6.2.1",
|
|
108
|
+
"@typescript-eslint/parser": "^6.2.1",
|
|
109
109
|
"apollo-server-express": "^3.10.0",
|
|
110
|
-
"c8": "^8.0.
|
|
110
|
+
"c8": "^8.0.1",
|
|
111
111
|
"class-transformer": "^0.5.1",
|
|
112
112
|
"class-validator": "^0.14.0",
|
|
113
113
|
"commitizen": "^4.3.0",
|
|
114
114
|
"cz-customizable": "^7.0.0",
|
|
115
115
|
"decimal.js": "^10.4.3",
|
|
116
|
-
"eslint": "^8.
|
|
116
|
+
"eslint": "^8.46.0",
|
|
117
117
|
"eslint-import-resolver-node": "^0.3.7",
|
|
118
118
|
"eslint-plugin-etc": "^2.0.3",
|
|
119
|
-
"eslint-plugin-import": "^2.
|
|
119
|
+
"eslint-plugin-import": "^2.28.0",
|
|
120
120
|
"eslint-plugin-only-warn": "^1.1.0",
|
|
121
121
|
"eslint-plugin-prettier": "^5.0.0",
|
|
122
122
|
"eslint-plugin-regexp": "^1.15.0",
|
|
123
123
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
124
124
|
"eslint-plugin-sort-class-members": "^1.18.0",
|
|
125
|
-
"eslint-plugin-unicorn": "^48.0.
|
|
125
|
+
"eslint-plugin-unicorn": "^48.0.1",
|
|
126
126
|
"eslint-plugin-wix-editor": "^3.3.0",
|
|
127
|
-
"expect": "^29.6.
|
|
127
|
+
"expect": "^29.6.2",
|
|
128
128
|
"git-branch-is": "^4.0.0",
|
|
129
129
|
"graphql": "^16.7.1",
|
|
130
130
|
"graphql-scalars": "^1.22.2",
|
|
@@ -132,8 +132,8 @@
|
|
|
132
132
|
"mocha": "^10.2.0",
|
|
133
133
|
"ololog": "^1.1.175",
|
|
134
134
|
"precise-commits": "^1.0.2",
|
|
135
|
-
"prettier": "^3.0.
|
|
136
|
-
"prisma": "^5.
|
|
135
|
+
"prettier": "^3.0.1",
|
|
136
|
+
"prisma": "^5.1.1",
|
|
137
137
|
"prisma-graphql-type-decimal": "^3.0.0",
|
|
138
138
|
"reflect-metadata": "^0.1.13",
|
|
139
139
|
"request": "^2.88.2",
|
|
@@ -147,6 +147,6 @@
|
|
|
147
147
|
"watchexec-bin": "^1.0.0"
|
|
148
148
|
},
|
|
149
149
|
"overrides": {
|
|
150
|
-
"prisma": "^5.
|
|
150
|
+
"prisma": "^5.1.1"
|
|
151
151
|
}
|
|
152
152
|
}
|