prisma-nestjs-graphql 19.0.1 → 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 +45 -9
- package/generate.d.ts +10 -27
- package/package.json +1 -1
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
|
@@ -1159,6 +1159,8 @@ function modelOutputType(outputType, args) {
|
|
|
1159
1159
|
importDeclarations.add("Field", nestjsGraphql$1);
|
|
1160
1160
|
importDeclarations.add("ObjectType", nestjsGraphql$1);
|
|
1161
1161
|
for (const field of outputType.fields) {
|
|
1162
|
+
if (config.omitModelsCount && field.name === "_count")
|
|
1163
|
+
continue;
|
|
1162
1164
|
let fileType = "model";
|
|
1163
1165
|
const { location, isList, type, namespace } = field.outputType;
|
|
1164
1166
|
let outputTypeName = String(type);
|
|
@@ -1353,6 +1355,8 @@ function outputType(outputType2, args) {
|
|
|
1353
1355
|
const model = models.get(modelName);
|
|
1354
1356
|
const isAggregateOutput = model && /(?:Count|Avg|Sum|Min|Max)AggregateOutputType$/.test(outputType2.name) && String(outputType2.name).startsWith(model.name);
|
|
1355
1357
|
const isCountOutput = (model == null ? void 0 : model.name) && outputType2.name === `${model.name}CountOutputType`;
|
|
1358
|
+
if (!config.emitBlocks.outputs && !isCountOutput)
|
|
1359
|
+
return;
|
|
1356
1360
|
outputType2.name = getOutputTypeName(outputType2.name);
|
|
1357
1361
|
if (isAggregateOutput) {
|
|
1358
1362
|
eventEmitter.emitSync("AggregateOutput", { ...args, outputType: outputType2 });
|
|
@@ -1596,7 +1600,9 @@ function getNamespaceExportDeclaration(directory, sourceDirectory) {
|
|
|
1596
1600
|
}
|
|
1597
1601
|
|
|
1598
1602
|
function registerEnum(enumType, args) {
|
|
1599
|
-
const { getSourceFile, enums } = args;
|
|
1603
|
+
const { getSourceFile, enums, config } = args;
|
|
1604
|
+
if (!config.emitBlocks.prismaEnums && !enums[enumType.name])
|
|
1605
|
+
return;
|
|
1600
1606
|
const dataModelEnum = enums[enumType.name];
|
|
1601
1607
|
const sourceFile = getSourceFile({
|
|
1602
1608
|
name: enumType.name,
|
|
@@ -1649,6 +1655,30 @@ function warning(message) {
|
|
|
1649
1655
|
}
|
|
1650
1656
|
}
|
|
1651
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
|
+
|
|
1652
1682
|
function createConfig(data) {
|
|
1653
1683
|
var _a;
|
|
1654
1684
|
const config = lodash.merge({}, flat.unflatten(data, { delimiter: "_" }));
|
|
@@ -1717,6 +1747,8 @@ function createConfig(data) {
|
|
|
1717
1747
|
reExport: ReExport[String(config.reExport)] || ReExport.None,
|
|
1718
1748
|
emitSingle: toBoolean(config.emitSingle),
|
|
1719
1749
|
emitCompiled: toBoolean(config.emitCompiled),
|
|
1750
|
+
emitBlocks: createEmitBlocks(config.emitBlocks),
|
|
1751
|
+
omitModelsCount: toBoolean(config.omitModelsCount),
|
|
1720
1752
|
$warnings,
|
|
1721
1753
|
fields,
|
|
1722
1754
|
purgeOutput: toBoolean(config.purgeOutput),
|
|
@@ -1929,17 +1961,21 @@ async function generate(args) {
|
|
|
1929
1961
|
const { connectCallback, generator, skipAddOutputSourceFiles, dmmf } = args;
|
|
1930
1962
|
const generatorOutputValue = (_a = generator.output) == null ? void 0 : _a.value;
|
|
1931
1963
|
assert.ok(generatorOutputValue, "Missing generator configuration: output");
|
|
1964
|
+
const config = createConfig(generator.config);
|
|
1932
1965
|
const eventEmitter = new AwaitEventEmitter__default["default"]();
|
|
1933
1966
|
eventEmitter.on("Warning", warning);
|
|
1934
|
-
eventEmitter.on("Model", modelData);
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
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);
|
|
1941
1978
|
eventEmitter.on("GenerateFiles", generateFiles);
|
|
1942
|
-
const config = createConfig(generator.config);
|
|
1943
1979
|
for (const message of config.$warnings) {
|
|
1944
1980
|
eventEmitter.emitSync("Warning", message);
|
|
1945
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