@vnodes/prisma-plugin 0.0.23
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 -0
- package/bin/nestjs.mjs +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/nestjs/generator.d.ts +3 -0
- package/dist/lib/nestjs/generator.d.ts.map +1 -0
- package/dist/lib/nestjs/generator.js +10 -0
- package/dist/lib/nestjs/generator.js.map +1 -0
- package/dist/lib/nestjs/imp/common/print-common-code.d.ts +3 -0
- package/dist/lib/nestjs/imp/common/print-common-code.d.ts.map +1 -0
- package/dist/lib/nestjs/imp/common/print-common-code.js +8 -0
- package/dist/lib/nestjs/imp/common/print-common-code.js.map +1 -0
- package/dist/lib/nestjs/imp/index.d.ts +7 -0
- package/dist/lib/nestjs/imp/index.d.ts.map +1 -0
- package/dist/lib/nestjs/imp/index.js +9 -0
- package/dist/lib/nestjs/imp/index.js.map +1 -0
- package/dist/lib/nestjs/imp/printers/dto-decorator-printer.d.ts +12 -0
- package/dist/lib/nestjs/imp/printers/dto-decorator-printer.d.ts.map +1 -0
- package/dist/lib/nestjs/imp/printers/dto-decorator-printer.js +21 -0
- package/dist/lib/nestjs/imp/printers/dto-decorator-printer.js.map +1 -0
- package/dist/lib/nestjs/imp/printers/dto-property-printer.d.ts +15 -0
- package/dist/lib/nestjs/imp/printers/dto-property-printer.d.ts.map +1 -0
- package/dist/lib/nestjs/imp/printers/dto-property-printer.js +28 -0
- package/dist/lib/nestjs/imp/printers/dto-property-printer.js.map +1 -0
- package/dist/lib/nestjs/imp/printers/nestjs-printer.d.ts +31 -0
- package/dist/lib/nestjs/imp/printers/nestjs-printer.d.ts.map +1 -0
- package/dist/lib/nestjs/imp/printers/nestjs-printer.js +149 -0
- package/dist/lib/nestjs/imp/printers/nestjs-printer.js.map +1 -0
- package/dist/lib/nestjs/imp/specific/print-nestjs-printers.d.ts +2 -0
- package/dist/lib/nestjs/imp/specific/print-nestjs-printers.d.ts.map +1 -0
- package/dist/lib/nestjs/imp/specific/print-nestjs-printers.js +74 -0
- package/dist/lib/nestjs/imp/specific/print-nestjs-printers.js.map +1 -0
- package/dist/lib/nestjs/imp/types/dto-generator-options.d.ts +6 -0
- package/dist/lib/nestjs/imp/types/dto-generator-options.d.ts.map +1 -0
- package/dist/lib/nestjs/imp/types/dto-generator-options.js +3 -0
- package/dist/lib/nestjs/imp/types/dto-generator-options.js.map +1 -0
- package/dist/lib/nestjs/on-generate.d.ts +3 -0
- package/dist/lib/nestjs/on-generate.d.ts.map +1 -0
- package/dist/lib/nestjs/on-generate.js +39 -0
- package/dist/lib/nestjs/on-generate.js.map +1 -0
- package/dist/lib/nestjs/on-manifest.d.ts +3 -0
- package/dist/lib/nestjs/on-manifest.d.ts.map +1 -0
- package/dist/lib/nestjs/on-manifest.js +12 -0
- package/dist/lib/nestjs/on-manifest.js.map +1 -0
- package/package.json +69 -0
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# prisma-plugin
|
|
2
|
+
|
|
3
|
+
This library was generated with [Nx](https://nx.dev).
|
|
4
|
+
|
|
5
|
+
## Building
|
|
6
|
+
|
|
7
|
+
Run `nx build prisma-plugin` to build the library.
|
|
8
|
+
|
|
9
|
+
## Running unit tests
|
|
10
|
+
|
|
11
|
+
Run `nx test prisma-plugin` to execute the unit tests via [Vitest](https://vitest.dev/).
|
package/bin/nestjs.mjs
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './lib/nestjs/imp/index.js';\n"],"names":[],"mappings":"AAAA,cAAc,4BAA4B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/lib/nestjs/generator.ts"],"names":[],"mappings":";AAMA,wBAGG"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import pkg from '@prisma/generator-helper';
|
|
2
|
+
import onGenerate from './on-generate.js';
|
|
3
|
+
import onManifest from './on-manifest.js';
|
|
4
|
+
const { generatorHandler } = pkg;
|
|
5
|
+
export default generatorHandler({
|
|
6
|
+
onManifest: onManifest,
|
|
7
|
+
onGenerate: onGenerate
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/nestjs/generator.ts"],"sourcesContent":["import pkg from '@prisma/generator-helper';\nimport onGenerate from './on-generate.js';\nimport onManifest from './on-manifest.js';\n\nconst { generatorHandler } = pkg;\n\nexport default generatorHandler({\n onManifest: onManifest,\n onGenerate: onGenerate,\n});\n"],"names":["pkg","onGenerate","onManifest","generatorHandler"],"mappings":"AAAA,OAAOA,SAAS,2BAA2B;AAC3C,OAAOC,gBAAgB,mBAAmB;AAC1C,OAAOC,gBAAgB,mBAAmB;AAE1C,MAAM,EAAEC,gBAAgB,EAAE,GAAGH;AAE7B,eAAeG,iBAAiB;IAC5BD,YAAYA;IACZD,YAAYA;AAChB,GAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"print-common-code.d.ts","sourceRoot":"","sources":["../../../../../src/lib/nestjs/imp/common/print-common-code.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAE7E,wBAAgB,eAAe,CAAC,gBAAgB,EAAE,mBAAmB,UAqBpE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { joinLines } from '@vnodes/utils';
|
|
2
|
+
export function printCommonCode(generatorOptions) {
|
|
3
|
+
const { prismaClientPath } = generatorOptions;
|
|
4
|
+
const propertyDecorator = 'Prop';
|
|
5
|
+
return joinLines(`import type { ValidationError } from '@vnodes/nestjs/class-validator';`, `import { NotFoundException, UnprocessableEntityException } from '@vnodes/nestjs/common';`, `import { PartialType } from '@vnodes/nestjs/swagger';`, `import { Prop } from '@vnodes/prop';`, `import type { Names } from '@vnodes/types';`, `import { keys, pick } from '@vnodes/utils';`, `import { Prisma } from '${prismaClientPath}';`, ``, ``, `export class PaginationDto {`, `@${propertyDecorator}({ minimum: 1 }) take?: number`, `@${propertyDecorator}({ minimum: 0 }) skip?: number`, `} `);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=print-common-code.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/nestjs/imp/common/print-common-code.ts"],"sourcesContent":["import { joinLines } from '@vnodes/utils';\nimport type { DtoGeneratorOptions } from '../types/dto-generator-options.js';\n\nexport function printCommonCode(generatorOptions: DtoGeneratorOptions) {\n const { prismaClientPath } = generatorOptions;\n\n const propertyDecorator = 'Prop';\n\n return joinLines(\n `import type { ValidationError } from '@vnodes/nestjs/class-validator';`,\n `import { NotFoundException, UnprocessableEntityException } from '@vnodes/nestjs/common';`,\n `import { PartialType } from '@vnodes/nestjs/swagger';`,\n `import { Prop } from '@vnodes/prop';`,\n `import type { Names } from '@vnodes/types';`,\n `import { keys, pick } from '@vnodes/utils';`,\n `import { Prisma } from '${prismaClientPath}';`,\n\n ``,\n ``,\n `export class PaginationDto {`,\n `@${propertyDecorator}({ minimum: 1 }) take?: number`,\n `@${propertyDecorator}({ minimum: 0 }) skip?: number`,\n `} `,\n );\n}\n"],"names":["joinLines","printCommonCode","generatorOptions","prismaClientPath","propertyDecorator"],"mappings":"AAAA,SAASA,SAAS,QAAQ,gBAAgB;AAG1C,OAAO,SAASC,gBAAgBC,gBAAqC;IACjE,MAAM,EAAEC,gBAAgB,EAAE,GAAGD;IAE7B,MAAME,oBAAoB;IAE1B,OAAOJ,UACH,CAAC,sEAAsE,CAAC,EACxE,CAAC,wFAAwF,CAAC,EAC1F,CAAC,qDAAqD,CAAC,EACvD,CAAC,oCAAoC,CAAC,EACtC,CAAC,2CAA2C,CAAC,EAC7C,CAAC,2CAA2C,CAAC,EAC7C,CAAC,wBAAwB,EAAEG,iBAAiB,EAAE,CAAC,EAE/C,EAAE,EACF,EAAE,EACF,CAAC,4BAA4B,CAAC,EAC9B,CAAC,CAAC,EAAEC,kBAAkB,8BAA8B,CAAC,EACrD,CAAC,CAAC,EAAEA,kBAAkB,8BAA8B,CAAC,EACrD,CAAC,EAAE,CAAC;AAEZ"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './common/print-common-code.js';
|
|
2
|
+
export * from './printers/dto-decorator-printer.js';
|
|
3
|
+
export * from './printers/dto-property-printer.js';
|
|
4
|
+
export * from './printers/nestjs-printer.js';
|
|
5
|
+
export * from './specific/print-nestjs-printers.js';
|
|
6
|
+
export * from './types/dto-generator-options.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/nestjs/imp/index.ts"],"names":[],"mappings":"AACA,cAAc,+BAA+B,CAAA;AAC7C,cAAc,qCAAqC,CAAA;AACnD,cAAc,oCAAoC,CAAA;AAClD,cAAc,8BAA8B,CAAA;AAC5C,cAAc,qCAAqC,CAAA;AACnD,cAAc,kCAAkC,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// @index(['./**/*.ts', '!./**/*.{spec,test}.ts'], f => `export * from '${f.path}.js'`)
|
|
2
|
+
export * from './common/print-common-code.js';
|
|
3
|
+
export * from './printers/dto-decorator-printer.js';
|
|
4
|
+
export * from './printers/dto-property-printer.js';
|
|
5
|
+
export * from './printers/nestjs-printer.js';
|
|
6
|
+
export * from './specific/print-nestjs-printers.js';
|
|
7
|
+
export * from './types/dto-generator-options.js';
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/nestjs/imp/index.ts"],"sourcesContent":["// @index(['./**/*.ts', '!./**/*.{spec,test}.ts'], f => `export * from '${f.path}.js'`)\nexport * from './common/print-common-code.js'\nexport * from './printers/dto-decorator-printer.js'\nexport * from './printers/dto-property-printer.js'\nexport * from './printers/nestjs-printer.js'\nexport * from './specific/print-nestjs-printers.js'\nexport * from './types/dto-generator-options.js'\n"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,cAAc,gCAA+B;AAC7C,cAAc,sCAAqC;AACnD,cAAc,qCAAoC;AAClD,cAAc,+BAA8B;AAC5C,cAAc,sCAAqC;AACnD,cAAc,mCAAkC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DMMF } from '@prisma/generator-helper';
|
|
2
|
+
import type { DtoGeneratorOptions } from '../types/dto-generator-options.js';
|
|
3
|
+
export declare class DtoDecoratorPrinter {
|
|
4
|
+
protected readonly datamodel: DMMF.Datamodel;
|
|
5
|
+
protected readonly model: DMMF.Model;
|
|
6
|
+
protected readonly field: DMMF.Field;
|
|
7
|
+
protected readonly generatorOptions: DtoGeneratorOptions;
|
|
8
|
+
constructor(datamodel: DMMF.Datamodel, model: DMMF.Model, field: DMMF.Field, generatorOptions: DtoGeneratorOptions);
|
|
9
|
+
protected printOptions(): string;
|
|
10
|
+
print(): string;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=dto-decorator-printer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dto-decorator-printer.d.ts","sourceRoot":"","sources":["../../../../../src/lib/nestjs/imp/printers/dto-decorator-printer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAErD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAE7E,qBAAa,mBAAmB;IAExB,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS;IAC5C,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK;IACpC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK;IACpC,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE,mBAAmB;gBAHrC,SAAS,EAAE,IAAI,CAAC,SAAS,EACzB,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,gBAAgB,EAAE,mBAAmB;IAG5D,SAAS,CAAC,YAAY,IAAI,MAAM;IAUhC,KAAK,IAAI,MAAM;CAGlB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { extractPropOptions, parsePropOptions } from '@vnodes/prisma-plugin-helpers';
|
|
2
|
+
export class DtoDecoratorPrinter {
|
|
3
|
+
printOptions() {
|
|
4
|
+
if (this.field.documentation) {
|
|
5
|
+
const options = this.field.documentation ? parsePropOptions(extractPropOptions(this.field.documentation)) : '';
|
|
6
|
+
return JSON.stringify(options);
|
|
7
|
+
}
|
|
8
|
+
return '';
|
|
9
|
+
}
|
|
10
|
+
print() {
|
|
11
|
+
return `@Prop(${this.printOptions()})`;
|
|
12
|
+
}
|
|
13
|
+
constructor(datamodel, model, field, generatorOptions){
|
|
14
|
+
this.datamodel = datamodel;
|
|
15
|
+
this.model = model;
|
|
16
|
+
this.field = field;
|
|
17
|
+
this.generatorOptions = generatorOptions;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=dto-decorator-printer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/nestjs/imp/printers/dto-decorator-printer.ts"],"sourcesContent":["import type { DMMF } from '@prisma/generator-helper';\nimport { extractPropOptions, parsePropOptions } from '@vnodes/prisma-plugin-helpers';\nimport type { DtoGeneratorOptions } from '../types/dto-generator-options.js';\n\nexport class DtoDecoratorPrinter {\n constructor(\n protected readonly datamodel: DMMF.Datamodel,\n protected readonly model: DMMF.Model,\n protected readonly field: DMMF.Field,\n protected readonly generatorOptions: DtoGeneratorOptions,\n ) {}\n\n protected printOptions(): string {\n if (this.field.documentation) {\n const options = this.field.documentation\n ? parsePropOptions(extractPropOptions(this.field.documentation))\n : '';\n return JSON.stringify(options);\n }\n return '';\n }\n\n print(): string {\n return `@Prop(${this.printOptions()})`;\n }\n}\n"],"names":["extractPropOptions","parsePropOptions","DtoDecoratorPrinter","printOptions","field","documentation","options","JSON","stringify","print","datamodel","model","generatorOptions"],"mappings":"AACA,SAASA,kBAAkB,EAAEC,gBAAgB,QAAQ,gCAAgC;AAGrF,OAAO,MAAMC;IAQCC,eAAuB;QAC7B,IAAI,IAAI,CAACC,KAAK,CAACC,aAAa,EAAE;YAC1B,MAAMC,UAAU,IAAI,CAACF,KAAK,CAACC,aAAa,GAClCJ,iBAAiBD,mBAAmB,IAAI,CAACI,KAAK,CAACC,aAAa,KAC5D;YACN,OAAOE,KAAKC,SAAS,CAACF;QAC1B;QACA,OAAO;IACX;IAEAG,QAAgB;QACZ,OAAO,CAAC,MAAM,EAAE,IAAI,CAACN,YAAY,GAAG,CAAC,CAAC;IAC1C;IAnBA,YACI,AAAmBO,SAAyB,EAC5C,AAAmBC,KAAiB,EACpC,AAAmBP,KAAiB,EACpC,AAAmBQ,gBAAqC,CAC1D;aAJqBF,YAAAA;aACAC,QAAAA;aACAP,QAAAA;aACAQ,mBAAAA;IACpB;AAeP"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DMMF } from '@prisma/generator-helper';
|
|
2
|
+
import { type ParsedPropOptions } from '@vnodes/prisma-plugin-helpers';
|
|
3
|
+
import type { DtoGeneratorOptions } from '../types/dto-generator-options.js';
|
|
4
|
+
export declare class DtoPropertyPrinter {
|
|
5
|
+
protected readonly datamodel: DMMF.Datamodel;
|
|
6
|
+
protected readonly model: DMMF.Model;
|
|
7
|
+
protected readonly field: DMMF.Field;
|
|
8
|
+
protected readonly generatorOptions: DtoGeneratorOptions;
|
|
9
|
+
constructor(datamodel: DMMF.Datamodel, model: DMMF.Model, field: DMMF.Field, generatorOptions: DtoGeneratorOptions);
|
|
10
|
+
protected annotations(): ParsedPropOptions;
|
|
11
|
+
protected isRequired(): "" | "?";
|
|
12
|
+
protected printPropetyDefinition(): string;
|
|
13
|
+
print(): string;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=dto-property-printer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dto-property-printer.d.ts","sourceRoot":"","sources":["../../../../../src/lib/nestjs/imp/printers/dto-property-printer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAGH,KAAK,iBAAiB,EAGzB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAG7E,qBAAa,kBAAkB;IAEvB,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS;IAC5C,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK;IACpC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK;IACpC,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE,mBAAmB;gBAHrC,SAAS,EAAE,IAAI,CAAC,SAAS,EACzB,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,gBAAgB,EAAE,mBAAmB;IAG5D,SAAS,CAAC,WAAW,IAAI,iBAAiB;IAO1C,SAAS,CAAC,UAAU;IAIpB,SAAS,CAAC,sBAAsB;IAIhC,KAAK,IAAI,MAAM;CAMlB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { extractPropOptions, isRequiredProp, parsePropOptions, propType } from '@vnodes/prisma-plugin-helpers';
|
|
2
|
+
import { joinBySpace } from '@vnodes/utils';
|
|
3
|
+
import { DtoDecoratorPrinter } from './dto-decorator-printer.js';
|
|
4
|
+
export class DtoPropertyPrinter {
|
|
5
|
+
annotations() {
|
|
6
|
+
if (this.field.documentation) {
|
|
7
|
+
return parsePropOptions(extractPropOptions(this.field.documentation));
|
|
8
|
+
}
|
|
9
|
+
return {};
|
|
10
|
+
}
|
|
11
|
+
isRequired() {
|
|
12
|
+
return isRequiredProp(this.field, this.annotations()) ? '' : '?';
|
|
13
|
+
}
|
|
14
|
+
printPropetyDefinition() {
|
|
15
|
+
return `${this.field.name}${this.isRequired()}:${propType(this.field)};`;
|
|
16
|
+
}
|
|
17
|
+
print() {
|
|
18
|
+
return joinBySpace(new DtoDecoratorPrinter(this.datamodel, this.model, this.field, this.generatorOptions).print(), this.printPropetyDefinition());
|
|
19
|
+
}
|
|
20
|
+
constructor(datamodel, model, field, generatorOptions){
|
|
21
|
+
this.datamodel = datamodel;
|
|
22
|
+
this.model = model;
|
|
23
|
+
this.field = field;
|
|
24
|
+
this.generatorOptions = generatorOptions;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=dto-property-printer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/nestjs/imp/printers/dto-property-printer.ts"],"sourcesContent":["import type { DMMF } from '@prisma/generator-helper';\nimport {\n extractPropOptions,\n isRequiredProp,\n type ParsedPropOptions,\n parsePropOptions,\n propType,\n} from '@vnodes/prisma-plugin-helpers';\nimport { joinBySpace } from '@vnodes/utils';\nimport type { DtoGeneratorOptions } from '../types/dto-generator-options.js';\nimport { DtoDecoratorPrinter } from './dto-decorator-printer.js';\n\nexport class DtoPropertyPrinter {\n constructor(\n protected readonly datamodel: DMMF.Datamodel,\n protected readonly model: DMMF.Model,\n protected readonly field: DMMF.Field,\n protected readonly generatorOptions: DtoGeneratorOptions,\n ) {}\n\n protected annotations(): ParsedPropOptions {\n if (this.field.documentation) {\n return parsePropOptions(extractPropOptions(this.field.documentation));\n }\n return {};\n }\n\n protected isRequired() {\n return isRequiredProp(this.field, this.annotations()) ? '' : '?';\n }\n\n protected printPropetyDefinition() {\n return `${this.field.name}${this.isRequired()}:${propType(this.field)};`;\n }\n\n print(): string {\n return joinBySpace(\n new DtoDecoratorPrinter(this.datamodel, this.model, this.field, this.generatorOptions).print(),\n this.printPropetyDefinition(),\n );\n }\n}\n"],"names":["extractPropOptions","isRequiredProp","parsePropOptions","propType","joinBySpace","DtoDecoratorPrinter","DtoPropertyPrinter","annotations","field","documentation","isRequired","printPropetyDefinition","name","print","datamodel","model","generatorOptions"],"mappings":"AACA,SACIA,kBAAkB,EAClBC,cAAc,EAEdC,gBAAgB,EAChBC,QAAQ,QACL,gCAAgC;AACvC,SAASC,WAAW,QAAQ,gBAAgB;AAE5C,SAASC,mBAAmB,QAAQ,6BAA6B;AAEjE,OAAO,MAAMC;IAQCC,cAAiC;QACvC,IAAI,IAAI,CAACC,KAAK,CAACC,aAAa,EAAE;YAC1B,OAAOP,iBAAiBF,mBAAmB,IAAI,CAACQ,KAAK,CAACC,aAAa;QACvE;QACA,OAAO,CAAC;IACZ;IAEUC,aAAa;QACnB,OAAOT,eAAe,IAAI,CAACO,KAAK,EAAE,IAAI,CAACD,WAAW,MAAM,KAAK;IACjE;IAEUI,yBAAyB;QAC/B,OAAO,GAAG,IAAI,CAACH,KAAK,CAACI,IAAI,GAAG,IAAI,CAACF,UAAU,GAAG,CAAC,EAAEP,SAAS,IAAI,CAACK,KAAK,EAAE,CAAC,CAAC;IAC5E;IAEAK,QAAgB;QACZ,OAAOT,YACH,IAAIC,oBAAoB,IAAI,CAACS,SAAS,EAAE,IAAI,CAACC,KAAK,EAAE,IAAI,CAACP,KAAK,EAAE,IAAI,CAACQ,gBAAgB,EAAEH,KAAK,IAC5F,IAAI,CAACF,sBAAsB;IAEnC;IA3BA,YACI,AAAmBG,SAAyB,EAC5C,AAAmBC,KAAiB,EACpC,AAAmBP,KAAiB,EACpC,AAAmBQ,gBAAqC,CAC1D;aAJqBF,YAAAA;aACAC,QAAAA;aACAP,QAAAA;aACAQ,mBAAAA;IACpB;AAuBP"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { DMMF } from '@prisma/generator-helper';
|
|
2
|
+
import type { DtoGeneratorOptions } from '../types/dto-generator-options.js';
|
|
3
|
+
export declare class NestjsPrinter {
|
|
4
|
+
protected readonly datamodel: DMMF.Datamodel;
|
|
5
|
+
protected readonly model: DMMF.Model;
|
|
6
|
+
protected readonly generatorOptions: DtoGeneratorOptions;
|
|
7
|
+
protected readonly readDtoName: string;
|
|
8
|
+
protected readonly createDtoName: string;
|
|
9
|
+
protected readonly updateDtoName: string;
|
|
10
|
+
protected readonly queryDtoName: string;
|
|
11
|
+
protected readonly serviceName: string;
|
|
12
|
+
constructor(datamodel: DMMF.Datamodel, model: DMMF.Model, generatorOptions: DtoGeneratorOptions);
|
|
13
|
+
protected printReadDtoProperties(): string;
|
|
14
|
+
protected printCreateDtoProperties(): string;
|
|
15
|
+
protected printReadDto(): string;
|
|
16
|
+
protected printCreateDto(): string;
|
|
17
|
+
protected printUpdateDto(): string;
|
|
18
|
+
protected printQueryDto(): string;
|
|
19
|
+
protected printQueryParserFn(): string;
|
|
20
|
+
protected __printHardDeleteMethod(field: DMMF.Field): string;
|
|
21
|
+
protected __printSoftDeleteMethod(field: DMMF.Field, softDeleteField: DMMF.Field): string;
|
|
22
|
+
protected printDeleteMethods(): string;
|
|
23
|
+
protected printCountMethods(): string;
|
|
24
|
+
protected printUpdateMethods(): string;
|
|
25
|
+
protected printFindByMethods(): string;
|
|
26
|
+
protected printFindRelationMethods(): string;
|
|
27
|
+
protected printIsUnqieuMethod(): string;
|
|
28
|
+
protected printService(): string;
|
|
29
|
+
print(): string;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=nestjs-printer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nestjs-printer.d.ts","sourceRoot":"","sources":["../../../../../src/lib/nestjs/imp/printers/nestjs-printer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAcrD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAG7E,qBAAa,aAAa;IAQlB,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS;IAC5C,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK;IACpC,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE,mBAAmB;IAT5D,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IACvC,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IACzC,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IACzC,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IACxC,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;gBAGhB,SAAS,EAAE,IAAI,CAAC,SAAS,EACzB,KAAK,EAAE,IAAI,CAAC,KAAK,EACjB,gBAAgB,EAAE,mBAAmB;IAU5D,SAAS,CAAC,sBAAsB;IAYhC,SAAS,CAAC,wBAAwB;IAelC,SAAS,CAAC,YAAY;IAQtB,SAAS,CAAC,cAAc;IAIxB,SAAS,CAAC,cAAc;IAIxB,SAAS,CAAC,aAAa;IAWvB,SAAS,CAAC,kBAAkB;IA0B5B,SAAS,CAAC,uBAAuB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK;IAWnD,SAAS,CAAC,uBAAuB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,eAAe,EAAE,IAAI,CAAC,KAAK;IAWhF,SAAS,CAAC,kBAAkB;IA0B5B,SAAS,CAAC,iBAAiB;IAgB3B,SAAS,CAAC,kBAAkB;IAiB5B,SAAS,CAAC,kBAAkB;IAyB5B,SAAS,CAAC,wBAAwB;IAiBlC,SAAS,CAAC,mBAAmB;IA2B7B,SAAS,CAAC,YAAY;IA8BtB,KAAK;CAUR"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { names } from '@vnodes/names';
|
|
2
|
+
import { extractPropOptions, isCountProp, isFindByProp, isInputProp, isRelationProp, isSearchProp, isSoftDeleteProp, parsePropOptions, propType } from '@vnodes/prisma-plugin-helpers';
|
|
3
|
+
import { joinLines } from '@vnodes/utils';
|
|
4
|
+
import { DtoPropertyPrinter } from './dto-property-printer.js';
|
|
5
|
+
export class NestjsPrinter {
|
|
6
|
+
printReadDtoProperties() {
|
|
7
|
+
return joinLines(...this.model.fields.filter((field)=>{
|
|
8
|
+
return !isRelationProp(field);
|
|
9
|
+
}).map((field)=>{
|
|
10
|
+
return new DtoPropertyPrinter(this.datamodel, this.model, field, this.generatorOptions).print();
|
|
11
|
+
}));
|
|
12
|
+
}
|
|
13
|
+
printCreateDtoProperties() {
|
|
14
|
+
return joinLines(...this.model.fields.filter((field)=>{
|
|
15
|
+
const options = field.documentation ? parsePropOptions(extractPropOptions(field.documentation)) : {};
|
|
16
|
+
return isInputProp(field, options);
|
|
17
|
+
}).map((field)=>{
|
|
18
|
+
return new DtoPropertyPrinter(this.datamodel, this.model, field, this.generatorOptions).print();
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
printReadDto() {
|
|
22
|
+
return joinLines(`export class ${this.readDtoName} {
|
|
23
|
+
${this.printReadDtoProperties()}
|
|
24
|
+
}`);
|
|
25
|
+
}
|
|
26
|
+
printCreateDto() {
|
|
27
|
+
return joinLines(`export class ${this.createDtoName}{`, this.printCreateDtoProperties(), `}`);
|
|
28
|
+
}
|
|
29
|
+
printUpdateDto() {
|
|
30
|
+
return joinLines(`export class ${this.updateDtoName} extends PartialType(${this.createDtoName}) {}`);
|
|
31
|
+
}
|
|
32
|
+
printQueryDto() {
|
|
33
|
+
return joinLines(`export class ${this.queryDtoName} extends PaginationDto {`, ` @Prop({ enum: Prisma.${this.model.name}ScalarFieldEnum }) orderBy?: Prisma.${this.model.name}ScalarFieldEnum;`, ` @Prop({ enum: Prisma.SortOrder }) orderDir?: Prisma.SortOrder;`, ` @Prop() search?: string;`, ` @Prop() withDeleted?: boolean;`, `}`);
|
|
34
|
+
}
|
|
35
|
+
printQueryParserFn() {
|
|
36
|
+
const searchQuery = this.model.fields.filter(isSearchProp).map((e)=>{
|
|
37
|
+
return `{ ${e.name}: { contains: search, mode: 'insensitive' } }`;
|
|
38
|
+
}).join(',');
|
|
39
|
+
return joinLines(`export function normalize${this.queryDtoName}(query: ${this.queryDtoName}):Prisma.${this.model.name}FindManyArgs {`, ` const { take, skip, search } = query;`, ``, ` const orderBy: Prisma.${this.model.name}OrderByWithRelationInput | undefined = query.orderBy`, ` ? { [query.orderBy]: query.orderDir ?? 'asc' }`, ` : undefined;`, ``, ` const where: Prisma.${this.model.name}WhereInput | undefined = search`, ` ? {`, ` OR: [${searchQuery}]`, ` }`, ` : undefined;`, ``, ` return { take, skip, where, orderBy };`, `}`);
|
|
40
|
+
}
|
|
41
|
+
__printHardDeleteMethod(field) {
|
|
42
|
+
const { pascal, camel } = names(field.name);
|
|
43
|
+
const fieldType = propType(field);
|
|
44
|
+
return joinLines(`async deleteOneBy${pascal}Hard(${camel}: ${fieldType}){ `, ` await this.findOneBy${pascal}OrThrow(${camel})`, ` return await this.repo.delete({ where: { ${camel} } })`, `}`);
|
|
45
|
+
}
|
|
46
|
+
__printSoftDeleteMethod(field, softDeleteField) {
|
|
47
|
+
const { pascal, camel } = names(field.name);
|
|
48
|
+
const fieldType = propType(field);
|
|
49
|
+
const softDeleteFieldName = softDeleteField.name;
|
|
50
|
+
return joinLines(`async deleteOneBy${pascal}(${camel}: ${fieldType}){ `, ` await this.findOneBy${pascal}OrThrow(${camel})`, ` return await this.repo.update({ where: { ${camel}, ${softDeleteFieldName}: null }, data:{ ${softDeleteFieldName}: new Date() } })`, `}`);
|
|
51
|
+
}
|
|
52
|
+
printDeleteMethods() {
|
|
53
|
+
const deleteMethods = [];
|
|
54
|
+
const deleteByFields = this.model.fields.filter((field)=>{
|
|
55
|
+
return field.isUnique || field.isId;
|
|
56
|
+
});
|
|
57
|
+
const softDeleteField = this.model.fields.find(isSoftDeleteProp);
|
|
58
|
+
// Soft delete methods
|
|
59
|
+
if (softDeleteField) {
|
|
60
|
+
const softDeleteMethods = deleteByFields.map((field)=>{
|
|
61
|
+
return this.__printSoftDeleteMethod(field, softDeleteField);
|
|
62
|
+
});
|
|
63
|
+
deleteMethods.push(...softDeleteMethods);
|
|
64
|
+
}
|
|
65
|
+
// Hard delete methods
|
|
66
|
+
{
|
|
67
|
+
const methods = deleteByFields.map((field)=>{
|
|
68
|
+
return this.__printHardDeleteMethod(field);
|
|
69
|
+
});
|
|
70
|
+
deleteMethods.push(...methods);
|
|
71
|
+
}
|
|
72
|
+
return joinLines(...deleteMethods);
|
|
73
|
+
}
|
|
74
|
+
printCountMethods() {
|
|
75
|
+
const countFields = this.model.fields.filter(isCountProp);
|
|
76
|
+
const countMethods = countFields.map((field)=>{
|
|
77
|
+
const { pascal, camel } = names(field.name);
|
|
78
|
+
const fieldType = propType(field);
|
|
79
|
+
return joinLines(`async countBy${pascal}(${camel}: ${fieldType} ){ `, ` return await this.repo.count({ where:{ ${camel} } })`, `}`);
|
|
80
|
+
});
|
|
81
|
+
return joinLines(...countMethods);
|
|
82
|
+
}
|
|
83
|
+
printUpdateMethods() {
|
|
84
|
+
const updateByFields = this.model.fields.filter((field)=>{
|
|
85
|
+
return field.isUnique || field.isId;
|
|
86
|
+
});
|
|
87
|
+
const updateMethods = updateByFields.map((field)=>{
|
|
88
|
+
const { pascal, camel } = names(field.name);
|
|
89
|
+
return joinLines(` async updateOneBy${pascal}(${camel}:${propType(field)}, data: ${this.updateDtoName}) {`, ` await this.findOneBy${pascal}OrThrow(${camel})`, ` await this.isUnique(data)`, ` return await this.repo.update({ where: { ${camel} }, data });`, ` }`);
|
|
90
|
+
});
|
|
91
|
+
return joinLines(...updateMethods);
|
|
92
|
+
}
|
|
93
|
+
printFindByMethods() {
|
|
94
|
+
const findByFields = this.model.fields.filter(isFindByProp);
|
|
95
|
+
const findBymethods = findByFields.map((field)=>{
|
|
96
|
+
const { pascal, camel } = names(field.name);
|
|
97
|
+
return joinLines(` async findOneBy${pascal}(${camel}: ${propType(field)}){`, ` return await this.repo.findFirst({ where: { ${camel} } })`, ` }`, ` async findOneBy${pascal}OrThrow(${camel}: ${propType(field)}){`, ` const found = await this.findOneBy${pascal}(${camel})`, ` if(!found) throw new NotFoundException('Not found by ${camel}')`, ` return found;`, ` }`, ` async findManyBy${pascal}(${camel}: ${propType(field)}){`, ` return await this.repo.findMany({ where: { ${camel} } })`, ` }`);
|
|
98
|
+
});
|
|
99
|
+
return joinLines(...findBymethods);
|
|
100
|
+
}
|
|
101
|
+
printFindRelationMethods() {
|
|
102
|
+
return this.model.fields.filter((field)=>field.kind === 'object').map((field)=>{
|
|
103
|
+
return joinLines(` async find${field.type}Of(id: number){ `, ` const result = await this.repo.findUnique({`, ` where: { id },`, ` select: { ${field.name}: true }`, ` })`, ` return result?.${field.name}`, ` }`);
|
|
104
|
+
}).join('\n');
|
|
105
|
+
}
|
|
106
|
+
printIsUnqieuMethod() {
|
|
107
|
+
const uniqueFields = this.model.fields.filter((field)=>field.isUnique).map((field)=>`'${field.name}'`).join(',');
|
|
108
|
+
return `
|
|
109
|
+
async isUnique(data: Partial<Prisma.SampleModel>) {
|
|
110
|
+
const uniqueData = pick(data, [${uniqueFields}]);
|
|
111
|
+
const uniqueKeys = keys(uniqueData);
|
|
112
|
+
const errors: ValidationError[] = [];
|
|
113
|
+
|
|
114
|
+
for (const key of uniqueKeys) {
|
|
115
|
+
const found = await this.repo.findUnique({ where: { [key]: uniqueData[key] } });
|
|
116
|
+
if (found) {
|
|
117
|
+
errors.push({ property: key, constraints: { unique: \`\${key} must be unique\` } });
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (errors.length > 0) {
|
|
122
|
+
throw new UnprocessableEntityException({ errors });
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
`;
|
|
128
|
+
}
|
|
129
|
+
printService() {
|
|
130
|
+
return joinLines(`export class ${this.serviceName} {`, ` constructor(protected readonly repo: Prisma.${this.model.name}Delegate) {}`, ``, this.printIsUnqieuMethod(), `
|
|
131
|
+
`, ` async findMany(query: ${this.queryDtoName}) {`, ` return await this.repo.findMany(normalize${this.queryDtoName}(query));`, ` }`, ``, ``, ` async createOne(data: ${this.createDtoName}) {`, ` await this.isUnique(data)`, ` return await this.repo.create({ data });`, ` }`, this.printFindByMethods(), this.printUpdateMethods(), this.printDeleteMethods(), this.printFindRelationMethods(), this.printCountMethods(), `}`);
|
|
132
|
+
}
|
|
133
|
+
print() {
|
|
134
|
+
return joinLines(this.printReadDto(), this.printCreateDto(), this.printUpdateDto(), this.printQueryDto(), this.printQueryParserFn(), this.printService());
|
|
135
|
+
}
|
|
136
|
+
constructor(datamodel, model, generatorOptions){
|
|
137
|
+
this.datamodel = datamodel;
|
|
138
|
+
this.model = model;
|
|
139
|
+
this.generatorOptions = generatorOptions;
|
|
140
|
+
const { pascal } = names(model.name);
|
|
141
|
+
this.readDtoName = `${pascal}Dto`;
|
|
142
|
+
this.createDtoName = `${pascal}CreateDto`;
|
|
143
|
+
this.updateDtoName = `${pascal}UpdateDto`;
|
|
144
|
+
this.queryDtoName = `${pascal}QueryDto`;
|
|
145
|
+
this.serviceName = `Base${pascal}Service`;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
//# sourceMappingURL=nestjs-printer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/nestjs/imp/printers/nestjs-printer.ts"],"sourcesContent":["import type { DMMF } from '@prisma/generator-helper';\nimport { names } from '@vnodes/names';\nimport {\n extractPropOptions,\n isCountProp,\n isFindByProp,\n isInputProp,\n isRelationProp,\n isSearchProp,\n isSoftDeleteProp,\n parsePropOptions,\n propType,\n} from '@vnodes/prisma-plugin-helpers';\nimport { joinLines } from '@vnodes/utils';\nimport type { DtoGeneratorOptions } from '../types/dto-generator-options.js';\nimport { DtoPropertyPrinter } from './dto-property-printer.js';\n\nexport class NestjsPrinter {\n protected readonly readDtoName: string;\n protected readonly createDtoName: string;\n protected readonly updateDtoName: string;\n protected readonly queryDtoName: string;\n protected readonly serviceName: string;\n\n constructor(\n protected readonly datamodel: DMMF.Datamodel,\n protected readonly model: DMMF.Model,\n protected readonly generatorOptions: DtoGeneratorOptions,\n ) {\n const { pascal } = names(model.name);\n this.readDtoName = `${pascal}Dto`;\n this.createDtoName = `${pascal}CreateDto`;\n this.updateDtoName = `${pascal}UpdateDto`;\n this.queryDtoName = `${pascal}QueryDto`;\n this.serviceName = `Base${pascal}Service`;\n }\n\n protected printReadDtoProperties() {\n return joinLines(\n ...this.model.fields\n .filter((field) => {\n return !isRelationProp(field);\n })\n .map((field) => {\n return new DtoPropertyPrinter(this.datamodel, this.model, field, this.generatorOptions).print();\n }),\n );\n }\n\n protected printCreateDtoProperties() {\n return joinLines(\n ...this.model.fields\n .filter((field) => {\n const options = field.documentation\n ? parsePropOptions(extractPropOptions(field.documentation))\n : {};\n return isInputProp(field, options);\n })\n .map((field) => {\n return new DtoPropertyPrinter(this.datamodel, this.model, field, this.generatorOptions).print();\n }),\n );\n }\n\n protected printReadDto() {\n return joinLines(\n `export class ${this.readDtoName} { \n ${this.printReadDtoProperties()}\n }`,\n );\n }\n\n protected printCreateDto() {\n return joinLines(`export class ${this.createDtoName}{`, this.printCreateDtoProperties(), `}`);\n }\n\n protected printUpdateDto() {\n return joinLines(`export class ${this.updateDtoName} extends PartialType(${this.createDtoName}) {}`);\n }\n\n protected printQueryDto() {\n return joinLines(\n `export class ${this.queryDtoName} extends PaginationDto {`,\n ` @Prop({ enum: Prisma.${this.model.name}ScalarFieldEnum }) orderBy?: Prisma.${this.model.name}ScalarFieldEnum;`,\n ` @Prop({ enum: Prisma.SortOrder }) orderDir?: Prisma.SortOrder;`,\n ` @Prop() search?: string;`,\n ` @Prop() withDeleted?: boolean;`,\n `}`,\n );\n }\n\n protected printQueryParserFn() {\n const searchQuery = this.model.fields\n .filter(isSearchProp)\n .map((e) => {\n return `{ ${e.name}: { contains: search, mode: 'insensitive' } }`;\n })\n .join(',');\n return joinLines(\n `export function normalize${this.queryDtoName}(query: ${this.queryDtoName}):Prisma.${this.model.name}FindManyArgs {`,\n ` const { take, skip, search } = query;`,\n ``,\n ` const orderBy: Prisma.${this.model.name}OrderByWithRelationInput | undefined = query.orderBy`,\n ` ? { [query.orderBy]: query.orderDir ?? 'asc' }`,\n ` : undefined;`,\n ``,\n ` const where: Prisma.${this.model.name}WhereInput | undefined = search`,\n ` ? {`,\n ` OR: [${searchQuery}]`,\n ` }`,\n ` : undefined;`,\n ``,\n ` return { take, skip, where, orderBy };`,\n `}`,\n );\n }\n\n protected __printHardDeleteMethod(field: DMMF.Field) {\n const { pascal, camel } = names(field.name);\n const fieldType = propType(field);\n return joinLines(\n `async deleteOneBy${pascal}Hard(${camel}: ${fieldType}){ `,\n ` await this.findOneBy${pascal}OrThrow(${camel})`,\n ` return await this.repo.delete({ where: { ${camel} } })`,\n `}`,\n );\n }\n\n protected __printSoftDeleteMethod(field: DMMF.Field, softDeleteField: DMMF.Field) {\n const { pascal, camel } = names(field.name);\n const fieldType = propType(field);\n const softDeleteFieldName = softDeleteField.name;\n return joinLines(\n `async deleteOneBy${pascal}(${camel}: ${fieldType}){ `,\n ` await this.findOneBy${pascal}OrThrow(${camel})`,\n ` return await this.repo.update({ where: { ${camel}, ${softDeleteFieldName}: null }, data:{ ${softDeleteFieldName}: new Date() } })`,\n `}`,\n );\n }\n protected printDeleteMethods() {\n const deleteMethods: string[] = [];\n const deleteByFields = this.model.fields.filter((field) => {\n return field.isUnique || field.isId;\n });\n const softDeleteField = this.model.fields.find(isSoftDeleteProp);\n\n // Soft delete methods\n if (softDeleteField) {\n const softDeleteMethods = deleteByFields.map((field) => {\n return this.__printSoftDeleteMethod(field, softDeleteField);\n });\n\n deleteMethods.push(...softDeleteMethods);\n }\n\n // Hard delete methods\n {\n const methods = deleteByFields.map((field) => {\n return this.__printHardDeleteMethod(field);\n });\n deleteMethods.push(...methods);\n }\n return joinLines(...deleteMethods);\n }\n\n protected printCountMethods() {\n const countFields = this.model.fields.filter(isCountProp);\n\n const countMethods = countFields.map((field) => {\n const { pascal, camel } = names(field.name);\n const fieldType = propType(field);\n return joinLines(\n `async countBy${pascal}(${camel}: ${fieldType} ){ `,\n ` return await this.repo.count({ where:{ ${camel} } })`,\n `}`,\n );\n });\n\n return joinLines(...countMethods);\n }\n\n protected printUpdateMethods() {\n const updateByFields = this.model.fields.filter((field) => {\n return field.isUnique || field.isId;\n });\n const updateMethods = updateByFields.map((field) => {\n const { pascal, camel } = names(field.name);\n\n return joinLines(\n ` async updateOneBy${pascal}(${camel}:${propType(field)}, data: ${this.updateDtoName}) {`,\n ` await this.findOneBy${pascal}OrThrow(${camel})`,\n ` await this.isUnique(data)`,\n ` return await this.repo.update({ where: { ${camel} }, data });`,\n ` }`,\n );\n });\n return joinLines(...updateMethods);\n }\n protected printFindByMethods() {\n const findByFields = this.model.fields.filter(isFindByProp);\n const findBymethods = findByFields.map((field) => {\n const { pascal, camel } = names(field.name);\n\n return joinLines(\n ` async findOneBy${pascal}(${camel}: ${propType(field)}){`,\n ` return await this.repo.findFirst({ where: { ${camel} } })`,\n ` }`,\n\n ` async findOneBy${pascal}OrThrow(${camel}: ${propType(field)}){`,\n ` const found = await this.findOneBy${pascal}(${camel})`,\n ` if(!found) throw new NotFoundException('Not found by ${camel}')`,\n ` return found;`,\n ` }`,\n\n ` async findManyBy${pascal}(${camel}: ${propType(field)}){`,\n ` return await this.repo.findMany({ where: { ${camel} } })`,\n ` }`,\n );\n });\n\n return joinLines(...findBymethods);\n }\n\n protected printFindRelationMethods() {\n return this.model.fields\n .filter((field) => field.kind === 'object')\n .map((field) => {\n return joinLines(\n ` async find${field.type}Of(id: number){ `,\n ` const result = await this.repo.findUnique({`,\n ` where: { id },`,\n ` select: { ${field.name}: true }`,\n ` })`,\n ` return result?.${field.name}`,\n ` }`,\n );\n })\n .join('\\n');\n }\n\n protected printIsUnqieuMethod() {\n const uniqueFields = this.model.fields\n .filter((field) => field.isUnique)\n .map((field) => `'${field.name}'`)\n .join(',');\n return `\n async isUnique(data: Partial<Prisma.SampleModel>) {\n const uniqueData = pick(data, [${uniqueFields}]);\n const uniqueKeys = keys(uniqueData);\n const errors: ValidationError[] = [];\n\n for (const key of uniqueKeys) {\n const found = await this.repo.findUnique({ where: { [key]: uniqueData[key] } });\n if (found) {\n errors.push({ property: key, constraints: { unique: \\`\\${key} must be unique\\` } });\n }\n }\n\n if (errors.length > 0) {\n throw new UnprocessableEntityException({ errors });\n }\n\n return;\n }\n `;\n }\n\n protected printService() {\n return joinLines(\n `export class ${this.serviceName} {`,\n ` constructor(protected readonly repo: Prisma.${this.model.name}Delegate) {}`,\n ``,\n\n this.printIsUnqieuMethod(),\n `\n `,\n ` async findMany(query: ${this.queryDtoName}) {`,\n ` return await this.repo.findMany(normalize${this.queryDtoName}(query));`,\n ` }`,\n ``,\n ``,\n ` async createOne(data: ${this.createDtoName}) {`,\n ` await this.isUnique(data)`,\n ` return await this.repo.create({ data });`,\n ` }`,\n\n this.printFindByMethods(),\n this.printUpdateMethods(),\n this.printDeleteMethods(),\n\n this.printFindRelationMethods(),\n this.printCountMethods(),\n\n `}`,\n );\n }\n\n print() {\n return joinLines(\n this.printReadDto(),\n this.printCreateDto(),\n this.printUpdateDto(),\n this.printQueryDto(),\n this.printQueryParserFn(),\n this.printService(),\n );\n }\n}\n"],"names":["names","extractPropOptions","isCountProp","isFindByProp","isInputProp","isRelationProp","isSearchProp","isSoftDeleteProp","parsePropOptions","propType","joinLines","DtoPropertyPrinter","NestjsPrinter","printReadDtoProperties","model","fields","filter","field","map","datamodel","generatorOptions","print","printCreateDtoProperties","options","documentation","printReadDto","readDtoName","printCreateDto","createDtoName","printUpdateDto","updateDtoName","printQueryDto","queryDtoName","name","printQueryParserFn","searchQuery","e","join","__printHardDeleteMethod","pascal","camel","fieldType","__printSoftDeleteMethod","softDeleteField","softDeleteFieldName","printDeleteMethods","deleteMethods","deleteByFields","isUnique","isId","find","softDeleteMethods","push","methods","printCountMethods","countFields","countMethods","printUpdateMethods","updateByFields","updateMethods","printFindByMethods","findByFields","findBymethods","printFindRelationMethods","kind","type","printIsUnqieuMethod","uniqueFields","printService","serviceName"],"mappings":"AACA,SAASA,KAAK,QAAQ,gBAAgB;AACtC,SACIC,kBAAkB,EAClBC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,cAAc,EACdC,YAAY,EACZC,gBAAgB,EAChBC,gBAAgB,EAChBC,QAAQ,QACL,gCAAgC;AACvC,SAASC,SAAS,QAAQ,gBAAgB;AAE1C,SAASC,kBAAkB,QAAQ,4BAA4B;AAE/D,OAAO,MAAMC;IAoBCC,yBAAyB;QAC/B,OAAOH,aACA,IAAI,CAACI,KAAK,CAACC,MAAM,CACfC,MAAM,CAAC,CAACC;YACL,OAAO,CAACZ,eAAeY;QAC3B,GACCC,GAAG,CAAC,CAACD;YACF,OAAO,IAAIN,mBAAmB,IAAI,CAACQ,SAAS,EAAE,IAAI,CAACL,KAAK,EAAEG,OAAO,IAAI,CAACG,gBAAgB,EAAEC,KAAK;QACjG;IAEZ;IAEUC,2BAA2B;QACjC,OAAOZ,aACA,IAAI,CAACI,KAAK,CAACC,MAAM,CACfC,MAAM,CAAC,CAACC;YACL,MAAMM,UAAUN,MAAMO,aAAa,GA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3,"file":"print-nestjs-printers.d.ts","sourceRoot":"","sources":["../../../../../src/lib/nestjs/imp/specific/print-nestjs-printers.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,cAuE7B,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export const printNestjsPrinters = ()=>`
|
|
2
|
+
|
|
3
|
+
export const printNestjsService = ({ pascal, camel }: Names) => \`
|
|
4
|
+
import { Injectable } from '@vnodes/nestjs/common';
|
|
5
|
+
import { InjectDelegate } from '@vnodes/prisma';
|
|
6
|
+
import type { Prisma } from '@vnodes/sample-db/client';
|
|
7
|
+
import { Base\${pascal}Service } from '@vnodes/sample-db/nestjs';
|
|
8
|
+
|
|
9
|
+
@Injectable()
|
|
10
|
+
export class \${pascal}Service extends Base\${pascal}Service {
|
|
11
|
+
constructor(@InjectDelegate('\${camel}') repo: Prisma.\${pascal}Delegate) {
|
|
12
|
+
super(repo);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
\`;
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
export const printNestjsModule = ({ camel, pascal }: Names) => \`
|
|
20
|
+
import { Module } from '@vnodes/nestjs/common';
|
|
21
|
+
import { PrismaModule } from '@vnodes/prisma';
|
|
22
|
+
import { \${pascal}Controller } from './\${camel}.controller.js';
|
|
23
|
+
import { \${pascal}Service } from './\${camel}.service.js';
|
|
24
|
+
|
|
25
|
+
@Module({
|
|
26
|
+
imports: [PrismaModule.forFeature({ models: ['\${camel}'] })],
|
|
27
|
+
providers: [\${pascal}Service],
|
|
28
|
+
controllers: [\${pascal}Controller],
|
|
29
|
+
})
|
|
30
|
+
export class \${pascal}Module {}
|
|
31
|
+
\`;
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
export const printNestjsController = ({ pascal, camel }: Names) => \`
|
|
35
|
+
/** biome-ignore-all lint/style/useImportType: NeedMetadata */
|
|
36
|
+
|
|
37
|
+
import { Autowire, ParamID, type ResourceController } from '@vnodes/autowire';
|
|
38
|
+
import { Body, Query } from '@vnodes/nestjs/common';
|
|
39
|
+
import {
|
|
40
|
+
\${pascal}CreateDto as CreateDto,
|
|
41
|
+
\${pascal}QueryDto as QueryDto,
|
|
42
|
+
\${pascal}Dto as ReadDto,
|
|
43
|
+
\${pascal}UpdateDto as UpdateDto,
|
|
44
|
+
} from '@vnodes/sample-db/nestjs';
|
|
45
|
+
import { \${pascal}Service } from './\${camel}.service.js';
|
|
46
|
+
|
|
47
|
+
@Autowire({ readDto: ReadDto })
|
|
48
|
+
export class \${pascal}Controller implements ResourceController {
|
|
49
|
+
constructor(protected readonly service: \${pascal}Service) {}
|
|
50
|
+
|
|
51
|
+
findMany(@Query() query: QueryDto) {
|
|
52
|
+
return this.service.findMany(query);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
findOneById(@ParamID() id: number) {
|
|
56
|
+
return this.service.findOneByIdOrThrow(id);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
createOne(@Body() data: CreateDto) {
|
|
60
|
+
return this.service.createOne(data);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
updateOneById(@ParamID() id: number, @Body() data: UpdateDto) {
|
|
64
|
+
return this.service.updateOneById(id, data);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
deleteOneById(@ParamID() id: number) {
|
|
68
|
+
return this.service.deleteOneById(id);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
\``;
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=print-nestjs-printers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/nestjs/imp/specific/print-nestjs-printers.ts"],"sourcesContent":["export const printNestjsPrinters = () => `\n\nexport const printNestjsService = ({ pascal, camel }: Names) => \\`\nimport { Injectable } from '@vnodes/nestjs/common';\nimport { InjectDelegate } from '@vnodes/prisma';\nimport type { Prisma } from '@vnodes/sample-db/client';\nimport { Base\\${pascal}Service } from '@vnodes/sample-db/nestjs';\n\n@Injectable()\nexport class \\${pascal}Service extends Base\\${pascal}Service {\n constructor(@InjectDelegate('\\${camel}') repo: Prisma.\\${pascal}Delegate) {\n super(repo);\n }\n}\n\\`;\n\n\n\nexport const printNestjsModule = ({ camel, pascal }: Names) => \\`\nimport { Module } from '@vnodes/nestjs/common';\nimport { PrismaModule } from '@vnodes/prisma';\nimport { \\${pascal}Controller } from './\\${camel}.controller.js';\nimport { \\${pascal}Service } from './\\${camel}.service.js';\n\n@Module({\n imports: [PrismaModule.forFeature({ models: ['\\${camel}'] })],\n providers: [\\${pascal}Service],\n controllers: [\\${pascal}Controller],\n})\nexport class \\${pascal}Module {}\n\\`;\n\n\nexport const printNestjsController = ({ pascal, camel }: Names) => \\`\n/** biome-ignore-all lint/style/useImportType: NeedMetadata */\n\nimport { Autowire, ParamID, type ResourceController } from '@vnodes/autowire';\nimport { Body, Query } from '@vnodes/nestjs/common';\nimport {\n \\${pascal}CreateDto as CreateDto,\n \\${pascal}QueryDto as QueryDto,\n \\${pascal}Dto as ReadDto,\n \\${pascal}UpdateDto as UpdateDto,\n} from '@vnodes/sample-db/nestjs';\nimport { \\${pascal}Service } from './\\${camel}.service.js';\n\n@Autowire({ readDto: ReadDto })\nexport class \\${pascal}Controller implements ResourceController {\n constructor(protected readonly service: \\${pascal}Service) {}\n\n findMany(@Query() query: QueryDto) {\n return this.service.findMany(query);\n }\n\n findOneById(@ParamID() id: number) {\n return this.service.findOneByIdOrThrow(id);\n }\n\n createOne(@Body() data: CreateDto) {\n return this.service.createOne(data);\n }\n\n updateOneById(@ParamID() id: number, @Body() data: UpdateDto) {\n return this.service.updateOneById(id, data);\n }\n\n deleteOneById(@ParamID() id: number) {\n return this.service.deleteOneById(id);\n }\n}\n\n\\``;\n"],"names":["printNestjsPrinters"],"mappings":"AAAA,OAAO,MAAMA,sBAAsB,IAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuExC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dto-generator-options.d.ts","sourceRoot":"","sources":["../../../../../src/lib/nestjs/imp/types/dto-generator-options.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/nestjs/imp/types/dto-generator-options.ts"],"sourcesContent":["export type DtoGeneratorOptions = {\n output: string;\n prismaClientPath: string;\n fileName?: string;\n};\n"],"names":[],"mappings":"AAAA,WAIE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"on-generate.d.ts","sourceRoot":"","sources":["../../../src/lib/nestjs/on-generate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AASjE,wBAA8B,UAAU,CAAC,OAAO,EAAE,gBAAgB,iBAsCjE"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { InvalidDateError, RequiredError } from '@vnodes/errors';
|
|
3
|
+
import { writeTextFile } from '@vnodes/fs';
|
|
4
|
+
import { joinLines } from '@vnodes/utils';
|
|
5
|
+
import { printCommonCode } from './imp/common/print-common-code.js';
|
|
6
|
+
import { printNestjsPrinters } from './imp/index.js';
|
|
7
|
+
import { NestjsPrinter } from './imp/printers/nestjs-printer.js';
|
|
8
|
+
export default async function onGenerate(options) {
|
|
9
|
+
var _options_generator_config_propertyDecorator, _options_generator_config_propertyDecoratorPackage, _options_generator_config_prismaClientPath, _options_generator_config_fileName;
|
|
10
|
+
var _options_generator_output;
|
|
11
|
+
const output = (_options_generator_output = options.generator.output) == null ? void 0 : _options_generator_output.value;
|
|
12
|
+
const datamodel = options.dmmf.datamodel;
|
|
13
|
+
const propertyDecorator = (_options_generator_config_propertyDecorator = options.generator.config.propertyDecorator) != null ? _options_generator_config_propertyDecorator : 'Prop';
|
|
14
|
+
const propertyDecoratorPackage = (_options_generator_config_propertyDecoratorPackage = options.generator.config.propertyDecoratorPackage) != null ? _options_generator_config_propertyDecoratorPackage : '@vnodes/prop';
|
|
15
|
+
const prismaClientPath = (_options_generator_config_prismaClientPath = options.generator.config.prismaClientPath) != null ? _options_generator_config_prismaClientPath : '../prisma/client.js';
|
|
16
|
+
const fileName = (_options_generator_config_fileName = options.generator.config.fileName) != null ? _options_generator_config_fileName : 'nestjs.ts';
|
|
17
|
+
if (typeof propertyDecorator !== 'string') {
|
|
18
|
+
throw new InvalidDateError(`propertyDecorator configuration should be string`);
|
|
19
|
+
}
|
|
20
|
+
if (typeof propertyDecoratorPackage !== 'string') {
|
|
21
|
+
throw new InvalidDateError(`propertyDecorator configuration should be string`);
|
|
22
|
+
}
|
|
23
|
+
if (!output) throw new RequiredError();
|
|
24
|
+
const dtoGeneratorOptions = {
|
|
25
|
+
output,
|
|
26
|
+
prismaClientPath,
|
|
27
|
+
fileName
|
|
28
|
+
};
|
|
29
|
+
const models = options.dmmf.datamodel.models;
|
|
30
|
+
const contents = [];
|
|
31
|
+
contents.push(printCommonCode(dtoGeneratorOptions));
|
|
32
|
+
for (const model of models){
|
|
33
|
+
contents.push(new NestjsPrinter(datamodel, model, dtoGeneratorOptions).print());
|
|
34
|
+
}
|
|
35
|
+
contents.push(printNestjsPrinters());
|
|
36
|
+
await writeTextFile(join(output, fileName), joinLines(...contents));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=on-generate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/nestjs/on-generate.ts"],"sourcesContent":["import { join } from 'node:path';\nimport type { GeneratorOptions } from '@prisma/generator-helper';\nimport { InvalidDateError, RequiredError } from '@vnodes/errors';\nimport { writeTextFile } from '@vnodes/fs';\nimport { joinLines } from '@vnodes/utils';\nimport { printCommonCode } from './imp/common/print-common-code.js';\nimport { printNestjsPrinters } from './imp/index.js';\nimport { NestjsPrinter } from './imp/printers/nestjs-printer.js';\nimport type { DtoGeneratorOptions } from './imp/types/dto-generator-options.js';\n\nexport default async function onGenerate(options: GeneratorOptions) {\n const output = options.generator.output?.value;\n const datamodel = options.dmmf.datamodel;\n const propertyDecorator: string = (options.generator.config.propertyDecorator as string) ?? 'Prop';\n const propertyDecoratorPackage: string =\n (options.generator.config.propertyDecoratorPackage as string) ?? '@vnodes/prop';\n const prismaClientPath: string = (options.generator.config.prismaClientPath as string) ?? '../prisma/client.js';\n const fileName: string = (options.generator.config.fileName as string) ?? 'nestjs.ts';\n\n if (typeof propertyDecorator !== 'string') {\n throw new InvalidDateError(`propertyDecorator configuration should be string`);\n }\n\n if (typeof propertyDecoratorPackage !== 'string') {\n throw new InvalidDateError(`propertyDecorator configuration should be string`);\n }\n\n if (!output) throw new RequiredError();\n\n const dtoGeneratorOptions: DtoGeneratorOptions = {\n output,\n prismaClientPath,\n fileName,\n };\n\n const models = options.dmmf.datamodel.models;\n\n const contents: string[] = [];\n\n contents.push(printCommonCode(dtoGeneratorOptions));\n\n for (const model of models) {\n contents.push(new NestjsPrinter(datamodel, model, dtoGeneratorOptions).print());\n }\n\n contents.push(printNestjsPrinters());\n\n await writeTextFile(join(output, fileName), joinLines(...contents));\n}\n"],"names":["join","InvalidDateError","RequiredError","writeTextFile","joinLines","printCommonCode","printNestjsPrinters","NestjsPrinter","onGenerate","options","output","generator","value","datamodel","dmmf","propertyDecorator","config","propertyDecoratorPackage","prismaClientPath","fileName","dtoGeneratorOptions","models","contents","push","model","print"],"mappings":"AAAA,SAASA,IAAI,QAAQ,YAAY;AAEjC,SAASC,gBAAgB,EAAEC,aAAa,QAAQ,iBAAiB;AACjE,SAASC,aAAa,QAAQ,aA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AAMH,cAAcH,KAAKU,QAAQS,WAAWf,aAAakB;AAC7D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"on-manifest.d.ts","sourceRoot":"","sources":["../../../src/lib/nestjs/on-manifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,MAAM,CAAC,OAAO,UAAU,UAAU,IAAI,iBAAiB,CAOtD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export default function onManifest() {
|
|
2
|
+
return {
|
|
3
|
+
prettyName: 'Nestjs Service and Dto Generator',
|
|
4
|
+
defaultOutput: '../src/generated/nestjs',
|
|
5
|
+
requiresGenerators: [
|
|
6
|
+
'prisma-client'
|
|
7
|
+
],
|
|
8
|
+
version: '0.0.1'
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=on-manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/nestjs/on-manifest.ts"],"sourcesContent":["import type { GeneratorManifest } from '@prisma/generator-helper';\n\nexport default function onManifest(): GeneratorManifest {\n return {\n prettyName: 'Nestjs Service and Dto Generator',\n defaultOutput: '../src/generated/nestjs',\n requiresGenerators: ['prisma-client'],\n version: '0.0.1',\n };\n}\n"],"names":["onManifest","prettyName","defaultOutput","requiresGenerators","version"],"mappings":"AAEA,eAAe,SAASA;IACpB,OAAO;QACHC,YAAY;QACZC,eAAe;QACfC,oBAAoB;YAAC;SAAgB;QACrCC,SAAS;IACb;AACJ"}
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vnodes/prisma-plugin",
|
|
3
|
+
"version": "0.0.23",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
"./package.json": "./package.json",
|
|
10
|
+
".": {
|
|
11
|
+
"@vnodes/source": "./src/index.ts",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"bin",
|
|
19
|
+
"dist",
|
|
20
|
+
"!**/*.tsbuildinfo"
|
|
21
|
+
],
|
|
22
|
+
"bin": {
|
|
23
|
+
"nestjs": "./bin/nestjs.mjs"
|
|
24
|
+
},
|
|
25
|
+
"nx": {
|
|
26
|
+
"sourceRoot": "plugins/prisma-plugin/src",
|
|
27
|
+
"targets": {
|
|
28
|
+
"build": {
|
|
29
|
+
"executor": "@nx/js:swc",
|
|
30
|
+
"outputs": [
|
|
31
|
+
"{options.outputPath}"
|
|
32
|
+
],
|
|
33
|
+
"options": {
|
|
34
|
+
"outputPath": "plugins/prisma-plugin/dist",
|
|
35
|
+
"main": "plugins/prisma-plugin/src/index.ts",
|
|
36
|
+
"tsConfig": "plugins/prisma-plugin/tsconfig.lib.json",
|
|
37
|
+
"skipTypeCheck": true,
|
|
38
|
+
"stripLeadingPaths": true
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"tags": [
|
|
43
|
+
"lib"
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@prisma/generator-helper": "^7.6.0",
|
|
48
|
+
"@swc/helpers": "~0.5.18",
|
|
49
|
+
"@vnodes/fs": "0.0.23"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@vnodes/errors": "0.0.23",
|
|
53
|
+
"@vnodes/prisma-plugin-helpers": "0.0.23",
|
|
54
|
+
"@vnodes/types": "0.0.23",
|
|
55
|
+
"@vnodes/names": "0.0.23",
|
|
56
|
+
"@vnodes/utils": "0.0.23"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@vnodes/errors": "0.0.23",
|
|
60
|
+
"@vnodes/names": "0.0.23",
|
|
61
|
+
"@vnodes/prisma-plugin-helpers": "0.0.23",
|
|
62
|
+
"@vnodes/types": "0.0.23",
|
|
63
|
+
"@vnodes/utils": "0.0.23"
|
|
64
|
+
},
|
|
65
|
+
"publishConfig": {
|
|
66
|
+
"access": "public",
|
|
67
|
+
"tag": "latest"
|
|
68
|
+
}
|
|
69
|
+
}
|