@dofe/infra-prisma-crud-generator 0.1.60
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/dist/cli.d.ts +10 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +139 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +34 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +19 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +64 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -0
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../../packages/prisma-crud-generator/src/cli.ts"],"names":[],"mappings":";AACA;;;;;;GAMG"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* dofe-prisma-crud CLI entry point.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* dofe-prisma-crud generate --config <path>
|
|
8
|
+
* dofe-prisma-crud generate --schema <path> --out <dir>
|
|
9
|
+
*/
|
|
10
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
13
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
14
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}) : (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
o[k2] = m[k];
|
|
20
|
+
}));
|
|
21
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
22
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
23
|
+
}) : function(o, v) {
|
|
24
|
+
o["default"] = v;
|
|
25
|
+
});
|
|
26
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
27
|
+
var ownKeys = function(o) {
|
|
28
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
29
|
+
var ar = [];
|
|
30
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
31
|
+
return ar;
|
|
32
|
+
};
|
|
33
|
+
return ownKeys(o);
|
|
34
|
+
};
|
|
35
|
+
return function (mod) {
|
|
36
|
+
if (mod && mod.__esModule) return mod;
|
|
37
|
+
var result = {};
|
|
38
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
39
|
+
__setModuleDefault(result, mod);
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
42
|
+
})();
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
const fs = __importStar(require("fs"));
|
|
45
|
+
const path = __importStar(require("path"));
|
|
46
|
+
const args = process.argv.slice(2);
|
|
47
|
+
const command = args[0];
|
|
48
|
+
async function main() {
|
|
49
|
+
if (!command || command === 'help' || command === '--help') {
|
|
50
|
+
printHelp();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
switch (command) {
|
|
54
|
+
case 'generate':
|
|
55
|
+
await runGenerate(args.slice(1));
|
|
56
|
+
break;
|
|
57
|
+
default:
|
|
58
|
+
console.error(`Unknown command: ${command}`);
|
|
59
|
+
printHelp();
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async function runGenerate(generateArgs) {
|
|
64
|
+
const configPath = getArg(generateArgs, '--config', '-c');
|
|
65
|
+
const schemaPath = getArg(generateArgs, '--schema', '-s');
|
|
66
|
+
const outDir = getArg(generateArgs, '--out', '-o');
|
|
67
|
+
const dryRun = generateArgs.includes('--dry-run');
|
|
68
|
+
console.log('dofe-prisma-crud generate');
|
|
69
|
+
console.log('=========================');
|
|
70
|
+
if (configPath) {
|
|
71
|
+
console.log(`Config: ${configPath}`);
|
|
72
|
+
// Load and use config file
|
|
73
|
+
const resolvedPath = path.resolve(configPath);
|
|
74
|
+
if (!fs.existsSync(resolvedPath)) {
|
|
75
|
+
console.error(`Config file not found: ${resolvedPath}`);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
// TODO: Dynamic import of config and full generation
|
|
79
|
+
console.log('(Full config-driven generation coming in next version)');
|
|
80
|
+
}
|
|
81
|
+
if (schemaPath) {
|
|
82
|
+
const resolved = path.resolve(schemaPath);
|
|
83
|
+
console.log(`Schema: ${resolved}`);
|
|
84
|
+
if (!fs.existsSync(resolved)) {
|
|
85
|
+
console.error(`Schema file not found: ${resolved}`);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
const content = fs.readFileSync(resolved, 'utf-8');
|
|
89
|
+
const { parsePrismaSchema } = await import('./index.js');
|
|
90
|
+
const models = parsePrismaSchema(content);
|
|
91
|
+
console.log(`\nFound ${models.length} models:`);
|
|
92
|
+
for (const model of models) {
|
|
93
|
+
console.log(` - ${model.name} (${model.fields.length} fields)`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (outDir) {
|
|
97
|
+
console.log(`Output: ${path.resolve(outDir)}`);
|
|
98
|
+
}
|
|
99
|
+
if (dryRun) {
|
|
100
|
+
console.log('\n[Dry run - no files written]');
|
|
101
|
+
}
|
|
102
|
+
console.log('\nDone. Use --config <path> for full generation.');
|
|
103
|
+
}
|
|
104
|
+
function getArg(args, ...names) {
|
|
105
|
+
for (const name of names) {
|
|
106
|
+
const idx = args.indexOf(name);
|
|
107
|
+
if (idx !== -1 && idx + 1 < args.length) {
|
|
108
|
+
return args[idx + 1];
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
function printHelp() {
|
|
114
|
+
console.log(`
|
|
115
|
+
dofe-prisma-crud - Generate Prisma-based CRUD modules
|
|
116
|
+
|
|
117
|
+
Usage:
|
|
118
|
+
dofe-prisma-crud <command> [options]
|
|
119
|
+
|
|
120
|
+
Commands:
|
|
121
|
+
generate Generate CRUD modules from Prisma schema
|
|
122
|
+
help Show this help
|
|
123
|
+
|
|
124
|
+
Generate Options:
|
|
125
|
+
--config, -c <path> Path to config file (dofe-prisma-crud.config.ts)
|
|
126
|
+
--schema, -s <path> Path to Prisma schema file
|
|
127
|
+
--out, -o <dir> Output directory for generated modules
|
|
128
|
+
--dry-run Preview without writing files
|
|
129
|
+
|
|
130
|
+
Examples:
|
|
131
|
+
dofe-prisma-crud generate --config dofe-prisma-crud.config.ts
|
|
132
|
+
dofe-prisma-crud generate --schema apps/api/prisma/schema.prisma --dry-run
|
|
133
|
+
`);
|
|
134
|
+
}
|
|
135
|
+
main().catch((err) => {
|
|
136
|
+
console.error('Error:', err);
|
|
137
|
+
process.exit(1);
|
|
138
|
+
});
|
|
139
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../packages/prisma-crud-generator/src/cli.ts"],"names":[],"mappings":";;AACA;;;;;;GAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,uCAAyB;AACzB,2CAA6B;AAE7B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnC,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;AAExB,KAAK,UAAU,IAAI;IACjB,IAAI,CAAC,OAAO,IAAI,OAAO,KAAK,MAAM,IAAI,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC3D,SAAS,EAAE,CAA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AAI,GAAG,KAAK,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;YACxC,OAAO,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,SAAS;IAChB,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;;;;CAmBb,CAAC,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAC7B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration types for @dofe/infra-prisma-crud-generator.
|
|
3
|
+
*/
|
|
4
|
+
export interface DofePrismaCrudGeneratorConfig {
|
|
5
|
+
/** Path to the Prisma schema file. */
|
|
6
|
+
schemaPath: string;
|
|
7
|
+
/** Directory where generated CRUD modules will be written. */
|
|
8
|
+
modulesDir: string;
|
|
9
|
+
/** Path where the barrel index file will be written. */
|
|
10
|
+
indexPath: string;
|
|
11
|
+
/** Models to exclude from generation. */
|
|
12
|
+
excludeModels?: string[];
|
|
13
|
+
/** Field name for soft-delete support (e.g., 'deletedAt'). */
|
|
14
|
+
softDeleteField?: string;
|
|
15
|
+
/** Default ordering for list queries. */
|
|
16
|
+
defaultOrderBy?: Record<string, 'asc' | 'desc'>;
|
|
17
|
+
/** Import paths for dependencies (customizable per project). */
|
|
18
|
+
imports?: {
|
|
19
|
+
prismaService: string;
|
|
20
|
+
prismaModule: string;
|
|
21
|
+
transactionalServiceBase: string;
|
|
22
|
+
prismaError: string;
|
|
23
|
+
pagination: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export declare const DEFAULT_IMPORTS: {
|
|
27
|
+
prismaService: string;
|
|
28
|
+
prismaModule: string;
|
|
29
|
+
transactionalServiceBase: string;
|
|
30
|
+
prismaError: string;
|
|
31
|
+
pagination: string;
|
|
32
|
+
};
|
|
33
|
+
export declare const DEFAULT_CONFIG: Partial<DofePrismaCrudGeneratorConfig>;
|
|
34
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../packages/prisma-crud-generator/src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,6BAA6B;IAC5C,sCAAsC;IACtC,UAAU,EAAE,MAAM,CAAC;IAEnB,8DAA8D;IAC9D,UAAU,EAAE,MAAM,CAAC;IAEnB,wDAAwD;IACxD,SAAS,EAAE,MAAM,CAAC;IAElB,yCAAyC;IACzC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IAEzB,8DAA8D;IAC9D,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,yCAAyC;IACzC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,GAAG,MAAM,CAAC,CAAC;IAEhD,gEAAgE;IAChE,OAAO,CAAC,EAAE;QACR,aAAa,EAAE,MAAM,CAAC;QACtB,YAAY,EAAE,MAAM,CAAC;QACrB,wBAAwB,EAAE,MAAM,CAAC;QACjC,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH;AAED,eAAO,MAAM,eAAe;;;;;;CAM3B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,OAAO,CAAC,6BAA6B,CAIjE,CAAC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration types for @dofe/infra-prisma-crud-generator.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DEFAULT_CONFIG = exports.DEFAULT_IMPORTS = void 0;
|
|
7
|
+
exports.DEFAULT_IMPORTS = {
|
|
8
|
+
prismaService: '@dofe/infra-prisma',
|
|
9
|
+
prismaModule: '@dofe/infra-prisma',
|
|
10
|
+
transactionalServiceBase: '@dofe/infra-shared-db',
|
|
11
|
+
prismaError: '@dofe/infra-common/utils/prisma-error.util',
|
|
12
|
+
pagination: '@dofe/infra-contracts-base',
|
|
13
|
+
};
|
|
14
|
+
exports.DEFAULT_CONFIG = {
|
|
15
|
+
excludeModels: ['UserInfo'],
|
|
16
|
+
softDeleteField: 'deletedAt',
|
|
17
|
+
imports: exports.DEFAULT_IMPORTS,
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../packages/prisma-crud-generator/src/config.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AA+BU,QAAA,eAAe,GAAG;IAC7B,aAAa,EAAE,oBAAoB;IACnC,YAAY,EAAE,oBAAoB;IAClC,wBAAwB,EAAE,uBAAuB;IACjD,WAAW,EAAE,4CAA4C;IACzD,UAAU,EAAE,4BAA4B;CACzC,CAAC;AAEW,QAAA,cAAc,GAA2C;IACpE,aAAa,EAAE,CAAC,UAAU,CAAC;IAC3B,eAAe,EAAE,WAAW;IAC5B,OAAO,EAAE,uBAAe;CACzB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @dofe/infra-prisma-crud-generator
|
|
3
|
+
*
|
|
4
|
+
* CLI tool for generating Prisma-based CRUD modules from schema definitions.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* dofe-prisma-crud generate --config dofe-prisma-crud.config.ts
|
|
8
|
+
*
|
|
9
|
+
* @example Configuration file (dofe-prisma-crud.config.ts):
|
|
10
|
+
* ```ts
|
|
11
|
+
* import type { DofePrismaCrudGeneratorConfig } from '@dofe/infra-prisma-crud-generator/config';
|
|
12
|
+
*
|
|
13
|
+
* const config: DofePrismaCrudGeneratorConfig = {
|
|
14
|
+
* schemaPath: 'apps/api/prisma/schema.prisma',
|
|
15
|
+
* modulesDir: 'apps/api/generated/db/modules',
|
|
16
|
+
* indexPath: 'apps/api/generated/db/index.ts',
|
|
17
|
+
* excludeModels: ['UserInfo'],
|
|
18
|
+
* softDeleteField: 'deletedAt',
|
|
19
|
+
* };
|
|
20
|
+
*
|
|
21
|
+
* export default config;
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export { type DofePrismaCrudGeneratorConfig, DEFAULT_IMPORTS, DEFAULT_CONFIG } from './config';
|
|
25
|
+
/**
|
|
26
|
+
* Parse a Prisma schema file and extract model definitions.
|
|
27
|
+
*
|
|
28
|
+
* @param schemaContent - Raw Prisma schema content
|
|
29
|
+
* @returns Array of parsed model info objects
|
|
30
|
+
*/
|
|
31
|
+
export declare function parsePrismaSchema(schemaContent: string): Array<{
|
|
32
|
+
name: string;
|
|
33
|
+
fields: Array<{
|
|
34
|
+
name: string;
|
|
35
|
+
type: string;
|
|
36
|
+
isRequired: boolean;
|
|
37
|
+
isId: boolean;
|
|
38
|
+
}>;
|
|
39
|
+
}>;
|
|
40
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../packages/prisma-crud-generator/src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,KAAK,6BAA6B,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/F;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,KAAK,CAAC;IAC9D,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CACnF,CAAC,CAmCD"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @dofe/infra-prisma-crud-generator
|
|
4
|
+
*
|
|
5
|
+
* CLI tool for generating Prisma-based CRUD modules from schema definitions.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* dofe-prisma-crud generate --config dofe-prisma-crud.config.ts
|
|
9
|
+
*
|
|
10
|
+
* @example Configuration file (dofe-prisma-crud.config.ts):
|
|
11
|
+
* ```ts
|
|
12
|
+
* import type { DofePrismaCrudGeneratorConfig } from '@dofe/infra-prisma-crud-generator/config';
|
|
13
|
+
*
|
|
14
|
+
* const config: DofePrismaCrudGeneratorConfig = {
|
|
15
|
+
* schemaPath: 'apps/api/prisma/schema.prisma',
|
|
16
|
+
* modulesDir: 'apps/api/generated/db/modules',
|
|
17
|
+
* indexPath: 'apps/api/generated/db/index.ts',
|
|
18
|
+
* excludeModels: ['UserInfo'],
|
|
19
|
+
* softDeleteField: 'deletedAt',
|
|
20
|
+
* };
|
|
21
|
+
*
|
|
22
|
+
* export default config;
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.DEFAULT_CONFIG = exports.DEFAULT_IMPORTS = void 0;
|
|
27
|
+
exports.parsePrismaSchema = parsePrismaSchema;
|
|
28
|
+
var config_1 = require("./config");
|
|
29
|
+
Object.defineProperty(exports, "DEFAULT_IMPORTS", { enumerable: true, get: function () { return config_1.DEFAULT_IMPORTS; } });
|
|
30
|
+
Object.defineProperty(exports, "DEFAULT_CONFIG", { enumerable: true, get: function () { return config_1.DEFAULT_CONFIG; } });
|
|
31
|
+
/**
|
|
32
|
+
* Parse a Prisma schema file and extract model definitions.
|
|
33
|
+
*
|
|
34
|
+
* @param schemaContent - Raw Prisma schema content
|
|
35
|
+
* @returns Array of parsed model info objects
|
|
36
|
+
*/
|
|
37
|
+
function parsePrismaSchema(schemaContent) {
|
|
38
|
+
const models = [];
|
|
39
|
+
const modelRegex = /model\s+(\w+)\s*\{([^}]*)\}/gs;
|
|
40
|
+
let match;
|
|
41
|
+
while ((match = modelRegex.exec(schemaContent)) !== null) {
|
|
42
|
+
const modelName = match[1];
|
|
43
|
+
const body = match[2];
|
|
44
|
+
const fields = [];
|
|
45
|
+
const lines = body.split('\n');
|
|
46
|
+
for (const line of lines) {
|
|
47
|
+
const trimmed = line.trim();
|
|
48
|
+
if (!trimmed || trimmed.startsWith('//') || trimmed.startsWith('@@'))
|
|
49
|
+
continue;
|
|
50
|
+
const fieldMatch = trimmed.match(/^(\w+)\s+(\w+)(\[\])?\s*(@id)?/);
|
|
51
|
+
if (fieldMatch) {
|
|
52
|
+
fields.push({
|
|
53
|
+
name: fieldMatch[1],
|
|
54
|
+
type: fieldMatch[2],
|
|
55
|
+
isRequired: !trimmed.includes('?') && !trimmed.includes('[]'),
|
|
56
|
+
isId: trimmed.includes('@id'),
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
models.push({ name: modelName, fields });
|
|
61
|
+
}
|
|
62
|
+
return models;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/prisma-crud-generator/src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AAUH,8CAsCC;AA9CD,mCAA+F;AAAlD,yGAAA,eAAe,OAAA;AAAE,wGAAA,cAAc,OAAA;AAE5E;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,aAAqB;IAIrD,MAAM,MAAM,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
|
|
2
|
+
"name": "@dofe/infra-prisma-crud-generator",
|
|
3
|
+
"version": "0.1.60",
|
|
4
|
+
"description": "CLI tool for generating Prisma-based CRUD modules from schema definitions",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"dofe-prisma-crud": "./dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./cli": {
|
|
16
|
+
"types": "./dist/cli.d.ts",
|
|
17
|
+
"default": "./dist/cli.js"
|
|
18
|
+
},
|
|
19
|
+
"./config": {
|
|
20
|
+
"types": "./dist/config.d.ts",
|
|
21
|
+
"default": "./dist/config.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"type": "commonjs",
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"license": "UNLICENSED",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@dofe/infra-contracts-base": "0.1.60"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsc",
|
|
37
|
+
"typecheck": "tsc --noEmit",
|
|
38
|
+
"clean": "rimraf dist"
|
|
39
|
+
}
|
|
40
|
+
}
|