@veloxts/cli 0.4.14 → 0.6.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 +2 -48
- package/dist/cli.d.ts +5 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +7 -1
- package/dist/cli.js.map +1 -1
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +71 -7
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/introspect.d.ts +16 -0
- package/dist/commands/introspect.d.ts.map +1 -0
- package/dist/commands/introspect.js +559 -0
- package/dist/commands/introspect.js.map +1 -0
- package/dist/commands/make.d.ts.map +1 -1
- package/dist/commands/make.js +18 -8
- package/dist/commands/make.js.map +1 -1
- package/dist/commands/procedures.d.ts.map +1 -1
- package/dist/commands/procedures.js +16 -0
- package/dist/commands/procedures.js.map +1 -1
- package/dist/dev/error-parser.d.ts.map +1 -1
- package/dist/dev/error-parser.js +24 -8
- package/dist/dev/error-parser.js.map +1 -1
- package/dist/dev/hmr-runner.d.ts.map +1 -1
- package/dist/dev/hmr-runner.js +6 -1
- package/dist/dev/hmr-runner.js.map +1 -1
- package/dist/dev/index.d.ts +3 -3
- package/dist/dev/index.d.ts.map +1 -1
- package/dist/dev/index.js +3 -3
- package/dist/dev/index.js.map +1 -1
- package/dist/dev/reload-reporter.d.ts +2 -2
- package/dist/dev/reload-reporter.d.ts.map +1 -1
- package/dist/dev/reload-reporter.js +2 -2
- package/dist/dev/reload-reporter.js.map +1 -1
- package/dist/errors/catalog.d.ts +48 -0
- package/dist/errors/catalog.d.ts.map +1 -0
- package/dist/errors/catalog.js +421 -0
- package/dist/errors/catalog.js.map +1 -0
- package/dist/errors/index.d.ts +26 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +28 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/velox-error.d.ts +122 -0
- package/dist/errors/velox-error.d.ts.map +1 -0
- package/dist/errors/velox-error.js +216 -0
- package/dist/errors/velox-error.js.map +1 -0
- package/dist/generators/base.d.ts.map +1 -1
- package/dist/generators/base.js +26 -0
- package/dist/generators/base.js.map +1 -1
- package/dist/generators/fields/__tests__/helpers.d.ts +66 -0
- package/dist/generators/fields/__tests__/helpers.d.ts.map +1 -0
- package/dist/generators/fields/__tests__/helpers.js +142 -0
- package/dist/generators/fields/__tests__/helpers.js.map +1 -0
- package/dist/generators/fields/actions.d.ts +58 -0
- package/dist/generators/fields/actions.d.ts.map +1 -0
- package/dist/generators/fields/actions.js +230 -0
- package/dist/generators/fields/actions.js.map +1 -0
- package/dist/generators/fields/display.d.ts +28 -0
- package/dist/generators/fields/display.d.ts.map +1 -0
- package/dist/generators/fields/display.js +214 -0
- package/dist/generators/fields/display.js.map +1 -0
- package/dist/generators/fields/index.d.ts +12 -0
- package/dist/generators/fields/index.d.ts.map +1 -0
- package/dist/generators/fields/index.js +12 -0
- package/dist/generators/fields/index.js.map +1 -0
- package/dist/generators/fields/prompts.d.ts +31 -0
- package/dist/generators/fields/prompts.d.ts.map +1 -0
- package/dist/generators/fields/prompts.js +366 -0
- package/dist/generators/fields/prompts.js.map +1 -0
- package/dist/generators/fields/templates.d.ts +49 -0
- package/dist/generators/fields/templates.d.ts.map +1 -0
- package/dist/generators/fields/templates.js +230 -0
- package/dist/generators/fields/templates.js.map +1 -0
- package/dist/generators/fields/types.d.ts +95 -0
- package/dist/generators/fields/types.d.ts.map +1 -0
- package/dist/generators/fields/types.js +150 -0
- package/dist/generators/fields/types.js.map +1 -0
- package/dist/generators/generators/action.d.ts +37 -0
- package/dist/generators/generators/action.d.ts.map +1 -0
- package/dist/generators/generators/action.js +109 -0
- package/dist/generators/generators/action.js.map +1 -0
- package/dist/generators/generators/exception.d.ts +38 -0
- package/dist/generators/generators/exception.d.ts.map +1 -0
- package/dist/generators/generators/exception.js +109 -0
- package/dist/generators/generators/exception.js.map +1 -0
- package/dist/generators/generators/guard.d.ts +38 -0
- package/dist/generators/generators/guard.d.ts.map +1 -0
- package/dist/generators/generators/guard.js +109 -0
- package/dist/generators/generators/guard.js.map +1 -0
- package/dist/generators/generators/index.d.ts +8 -0
- package/dist/generators/generators/index.d.ts.map +1 -1
- package/dist/generators/generators/index.js +27 -0
- package/dist/generators/generators/index.js.map +1 -1
- package/dist/generators/generators/layout.d.ts +36 -0
- package/dist/generators/generators/layout.d.ts.map +1 -0
- package/dist/generators/generators/layout.js +111 -0
- package/dist/generators/generators/layout.js.map +1 -0
- package/dist/generators/generators/middleware.d.ts +38 -0
- package/dist/generators/generators/middleware.d.ts.map +1 -0
- package/dist/generators/generators/middleware.js +109 -0
- package/dist/generators/generators/middleware.js.map +1 -0
- package/dist/generators/generators/model.d.ts +16 -4
- package/dist/generators/generators/model.d.ts.map +1 -1
- package/dist/generators/generators/model.js +88 -7
- package/dist/generators/generators/model.js.map +1 -1
- package/dist/generators/generators/page.d.ts +36 -0
- package/dist/generators/generators/page.d.ts.map +1 -0
- package/dist/generators/generators/page.js +112 -0
- package/dist/generators/generators/page.js.map +1 -0
- package/dist/generators/generators/policy.d.ts +37 -0
- package/dist/generators/generators/policy.d.ts.map +1 -0
- package/dist/generators/generators/policy.js +100 -0
- package/dist/generators/generators/policy.js.map +1 -0
- package/dist/generators/generators/resource.d.ts +42 -4
- package/dist/generators/generators/resource.d.ts.map +1 -1
- package/dist/generators/generators/resource.js +450 -9
- package/dist/generators/generators/resource.js.map +1 -1
- package/dist/generators/generators/service.d.ts +38 -0
- package/dist/generators/generators/service.d.ts.map +1 -0
- package/dist/generators/generators/service.js +109 -0
- package/dist/generators/generators/service.js.map +1 -0
- package/dist/generators/registry.d.ts.map +1 -1
- package/dist/generators/registry.js +10 -1
- package/dist/generators/registry.js.map +1 -1
- package/dist/generators/templates/action.d.ts +28 -0
- package/dist/generators/templates/action.d.ts.map +1 -0
- package/dist/generators/templates/action.js +359 -0
- package/dist/generators/templates/action.js.map +1 -0
- package/dist/generators/templates/exception.d.ts +26 -0
- package/dist/generators/templates/exception.d.ts.map +1 -0
- package/dist/generators/templates/exception.js +671 -0
- package/dist/generators/templates/exception.js.map +1 -0
- package/dist/generators/templates/guard.d.ts +26 -0
- package/dist/generators/templates/guard.d.ts.map +1 -0
- package/dist/generators/templates/guard.js +555 -0
- package/dist/generators/templates/guard.js.map +1 -0
- package/dist/generators/templates/layout.d.ts +28 -0
- package/dist/generators/templates/layout.d.ts.map +1 -0
- package/dist/generators/templates/layout.js +147 -0
- package/dist/generators/templates/layout.js.map +1 -0
- package/dist/generators/templates/middleware.d.ts +26 -0
- package/dist/generators/templates/middleware.d.ts.map +1 -0
- package/dist/generators/templates/middleware.js +411 -0
- package/dist/generators/templates/middleware.js.map +1 -0
- package/dist/generators/templates/model.d.ts +3 -0
- package/dist/generators/templates/model.d.ts.map +1 -1
- package/dist/generators/templates/model.js +183 -28
- package/dist/generators/templates/model.js.map +1 -1
- package/dist/generators/templates/page.d.ts +36 -0
- package/dist/generators/templates/page.d.ts.map +1 -0
- package/dist/generators/templates/page.js +147 -0
- package/dist/generators/templates/page.js.map +1 -0
- package/dist/generators/templates/policy.d.ts +24 -0
- package/dist/generators/templates/policy.d.ts.map +1 -0
- package/dist/generators/templates/policy.js +499 -0
- package/dist/generators/templates/policy.js.map +1 -0
- package/dist/generators/templates/resource.d.ts +65 -0
- package/dist/generators/templates/resource.d.ts.map +1 -1
- package/dist/generators/templates/resource.js +228 -43
- package/dist/generators/templates/resource.js.map +1 -1
- package/dist/generators/templates/service.d.ts +26 -0
- package/dist/generators/templates/service.d.ts.map +1 -0
- package/dist/generators/templates/service.js +511 -0
- package/dist/generators/templates/service.js.map +1 -0
- package/dist/generators/types.d.ts +26 -14
- package/dist/generators/types.d.ts.map +1 -1
- package/dist/generators/types.js +8 -25
- package/dist/generators/types.js.map +1 -1
- package/dist/generators/utils/ast-helpers.d.ts +147 -0
- package/dist/generators/utils/ast-helpers.d.ts.map +1 -0
- package/dist/generators/utils/ast-helpers.js +350 -0
- package/dist/generators/utils/ast-helpers.js.map +1 -0
- package/dist/generators/utils/prisma-migration.d.ts +59 -0
- package/dist/generators/utils/prisma-migration.d.ts.map +1 -0
- package/dist/generators/utils/prisma-migration.js +161 -0
- package/dist/generators/utils/prisma-migration.js.map +1 -0
- package/dist/generators/utils/prisma-schema.d.ts +97 -0
- package/dist/generators/utils/prisma-schema.d.ts.map +1 -0
- package/dist/generators/utils/prisma-schema.js +235 -0
- package/dist/generators/utils/prisma-schema.js.map +1 -0
- package/dist/generators/utils/router-integration.d.ts +70 -0
- package/dist/generators/utils/router-integration.d.ts.map +1 -0
- package/dist/generators/utils/router-integration.js +305 -0
- package/dist/generators/utils/router-integration.js.map +1 -0
- package/dist/generators/utils/snapshot.d.ts +93 -0
- package/dist/generators/utils/snapshot.d.ts.map +1 -0
- package/dist/generators/utils/snapshot.js +178 -0
- package/dist/generators/utils/snapshot.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/seeding/errors.d.ts +11 -24
- package/dist/seeding/errors.d.ts.map +1 -1
- package/dist/seeding/errors.js +11 -50
- package/dist/seeding/errors.js.map +1 -1
- package/dist/utils/paths.d.ts +19 -0
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +45 -0
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/schema-patterns.d.ts +26 -0
- package/dist/utils/schema-patterns.d.ts.map +1 -0
- package/dist/utils/schema-patterns.js +40 -0
- package/dist/utils/schema-patterns.js.map +1 -0
- package/package.json +12 -10
|
@@ -0,0 +1,671 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exception Template
|
|
3
|
+
*
|
|
4
|
+
* Generates custom error class files for VeloxTS applications.
|
|
5
|
+
*/
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// Path Helpers
|
|
8
|
+
// ============================================================================
|
|
9
|
+
/**
|
|
10
|
+
* Get the path for an exception file
|
|
11
|
+
*/
|
|
12
|
+
export function getExceptionPath(entityName, _project) {
|
|
13
|
+
return `src/exceptions/${entityName.toLowerCase()}.ts`;
|
|
14
|
+
}
|
|
15
|
+
// ============================================================================
|
|
16
|
+
// Templates
|
|
17
|
+
// ============================================================================
|
|
18
|
+
/**
|
|
19
|
+
* Generate HTTP exception
|
|
20
|
+
*/
|
|
21
|
+
function generateHttpException(ctx) {
|
|
22
|
+
const { entity } = ctx;
|
|
23
|
+
return `/**
|
|
24
|
+
* ${entity.pascal} HTTP Exception
|
|
25
|
+
*
|
|
26
|
+
* HTTP-aware exceptions for ${entity.humanReadable} errors.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
// ============================================================================
|
|
30
|
+
// Base HTTP Exception
|
|
31
|
+
// ============================================================================
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Base HTTP exception with status code and body
|
|
35
|
+
*/
|
|
36
|
+
export class HttpException extends Error {
|
|
37
|
+
constructor(
|
|
38
|
+
public readonly statusCode: number,
|
|
39
|
+
message: string,
|
|
40
|
+
public readonly code?: string,
|
|
41
|
+
public readonly details?: Record<string, unknown>
|
|
42
|
+
) {
|
|
43
|
+
super(message);
|
|
44
|
+
this.name = 'HttpException';
|
|
45
|
+
Error.captureStackTrace(this, this.constructor);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Convert to HTTP response body
|
|
50
|
+
*/
|
|
51
|
+
toJSON(): Record<string, unknown> {
|
|
52
|
+
return {
|
|
53
|
+
error: {
|
|
54
|
+
code: this.code ?? 'HTTP_ERROR',
|
|
55
|
+
message: this.message,
|
|
56
|
+
statusCode: this.statusCode,
|
|
57
|
+
...(this.details && { details: this.details }),
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ============================================================================
|
|
64
|
+
// ${entity.pascal} Exceptions
|
|
65
|
+
// ============================================================================
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* ${entity.pascal} not found (404)
|
|
69
|
+
*/
|
|
70
|
+
export class ${entity.pascal}NotFoundException extends HttpException {
|
|
71
|
+
constructor(id?: string) {
|
|
72
|
+
super(
|
|
73
|
+
404,
|
|
74
|
+
id ? \`${entity.pascal} not found: \${id}\` : '${entity.pascal} not found',
|
|
75
|
+
'${entity.screamingSnake}_NOT_FOUND'
|
|
76
|
+
);
|
|
77
|
+
this.name = '${entity.pascal}NotFoundException';
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* ${entity.pascal} already exists (409)
|
|
83
|
+
*/
|
|
84
|
+
export class ${entity.pascal}ConflictException extends HttpException {
|
|
85
|
+
constructor(field?: string, value?: string) {
|
|
86
|
+
super(
|
|
87
|
+
409,
|
|
88
|
+
field
|
|
89
|
+
? \`${entity.pascal} with \${field} "\${value}" already exists\`
|
|
90
|
+
: '${entity.pascal} already exists',
|
|
91
|
+
'${entity.screamingSnake}_CONFLICT',
|
|
92
|
+
field ? { field, value } : undefined
|
|
93
|
+
);
|
|
94
|
+
this.name = '${entity.pascal}ConflictException';
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* ${entity.pascal} forbidden (403)
|
|
100
|
+
*/
|
|
101
|
+
export class ${entity.pascal}ForbiddenException extends HttpException {
|
|
102
|
+
constructor(action?: string) {
|
|
103
|
+
super(
|
|
104
|
+
403,
|
|
105
|
+
action
|
|
106
|
+
? \`You are not allowed to \${action} this ${entity.humanReadable}\`
|
|
107
|
+
: 'Access to ${entity.humanReadable} forbidden',
|
|
108
|
+
'${entity.screamingSnake}_FORBIDDEN',
|
|
109
|
+
action ? { action } : undefined
|
|
110
|
+
);
|
|
111
|
+
this.name = '${entity.pascal}ForbiddenException';
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* ${entity.pascal} bad request (400)
|
|
117
|
+
*/
|
|
118
|
+
export class ${entity.pascal}BadRequestException extends HttpException {
|
|
119
|
+
constructor(message: string, details?: Record<string, unknown>) {
|
|
120
|
+
super(400, message, '${entity.screamingSnake}_BAD_REQUEST', details);
|
|
121
|
+
this.name = '${entity.pascal}BadRequestException';
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* ${entity.pascal} unprocessable (422)
|
|
127
|
+
*/
|
|
128
|
+
export class ${entity.pascal}UnprocessableException extends HttpException {
|
|
129
|
+
constructor(reason: string, details?: Record<string, unknown>) {
|
|
130
|
+
super(
|
|
131
|
+
422,
|
|
132
|
+
\`Cannot process ${entity.humanReadable}: \${reason}\`,
|
|
133
|
+
'${entity.screamingSnake}_UNPROCESSABLE',
|
|
134
|
+
details
|
|
135
|
+
);
|
|
136
|
+
this.name = '${entity.pascal}UnprocessableException';
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// ============================================================================
|
|
141
|
+
// Type Guards
|
|
142
|
+
// ============================================================================
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Check if error is an HTTP exception
|
|
146
|
+
*/
|
|
147
|
+
export function isHttpException(error: unknown): error is HttpException {
|
|
148
|
+
return error instanceof HttpException;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Check if error is a ${entity.pascal} exception
|
|
153
|
+
*/
|
|
154
|
+
export function is${entity.pascal}Exception(error: unknown): error is HttpException {
|
|
155
|
+
return (
|
|
156
|
+
error instanceof ${entity.pascal}NotFoundException ||
|
|
157
|
+
error instanceof ${entity.pascal}ConflictException ||
|
|
158
|
+
error instanceof ${entity.pascal}ForbiddenException ||
|
|
159
|
+
error instanceof ${entity.pascal}BadRequestException ||
|
|
160
|
+
error instanceof ${entity.pascal}UnprocessableException
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
`;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Generate validation exception
|
|
167
|
+
*/
|
|
168
|
+
function generateValidationException(ctx) {
|
|
169
|
+
const { entity } = ctx;
|
|
170
|
+
return `/**
|
|
171
|
+
* ${entity.pascal} Validation Exception
|
|
172
|
+
*
|
|
173
|
+
* Validation-focused exceptions for ${entity.humanReadable} operations.
|
|
174
|
+
*/
|
|
175
|
+
|
|
176
|
+
// ============================================================================
|
|
177
|
+
// Types
|
|
178
|
+
// ============================================================================
|
|
179
|
+
|
|
180
|
+
export interface FieldError {
|
|
181
|
+
field: string;
|
|
182
|
+
message: string;
|
|
183
|
+
code?: string;
|
|
184
|
+
value?: unknown;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface ValidationIssue {
|
|
188
|
+
path: string[];
|
|
189
|
+
message: string;
|
|
190
|
+
code: string;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// ============================================================================
|
|
194
|
+
// Validation Exception
|
|
195
|
+
// ============================================================================
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* ${entity.pascal} validation exception
|
|
199
|
+
*
|
|
200
|
+
* Collects multiple field errors for form validation feedback.
|
|
201
|
+
*/
|
|
202
|
+
export class ${entity.pascal}ValidationException extends Error {
|
|
203
|
+
public readonly errors: FieldError[];
|
|
204
|
+
|
|
205
|
+
constructor(errors: FieldError[] | string) {
|
|
206
|
+
const errorList = typeof errors === 'string' ? [{ field: '_root', message: errors }] : errors;
|
|
207
|
+
super(\`${entity.pascal} validation failed: \${errorList.map((e) => e.message).join(', ')}\`);
|
|
208
|
+
this.name = '${entity.pascal}ValidationException';
|
|
209
|
+
this.errors = errorList;
|
|
210
|
+
Error.captureStackTrace(this, this.constructor);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Create from Zod error
|
|
215
|
+
*/
|
|
216
|
+
static fromZodError(zodError: { issues: ValidationIssue[] }): ${entity.pascal}ValidationException {
|
|
217
|
+
const errors: FieldError[] = zodError.issues.map((issue) => ({
|
|
218
|
+
field: issue.path.join('.') || '_root',
|
|
219
|
+
message: issue.message,
|
|
220
|
+
code: issue.code,
|
|
221
|
+
}));
|
|
222
|
+
return new ${entity.pascal}ValidationException(errors);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Get errors for a specific field
|
|
227
|
+
*/
|
|
228
|
+
getFieldErrors(field: string): FieldError[] {
|
|
229
|
+
return this.errors.filter((e) => e.field === field);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Check if field has errors
|
|
234
|
+
*/
|
|
235
|
+
hasFieldError(field: string): boolean {
|
|
236
|
+
return this.errors.some((e) => e.field === field);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Convert to response format
|
|
241
|
+
*/
|
|
242
|
+
toJSON(): Record<string, unknown> {
|
|
243
|
+
return {
|
|
244
|
+
error: {
|
|
245
|
+
code: '${entity.screamingSnake}_VALIDATION_FAILED',
|
|
246
|
+
message: 'Validation failed',
|
|
247
|
+
errors: this.errors,
|
|
248
|
+
},
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Convert to field-keyed object for forms
|
|
254
|
+
*/
|
|
255
|
+
toFieldErrors(): Record<string, string[]> {
|
|
256
|
+
const result: Record<string, string[]> = {};
|
|
257
|
+
for (const error of this.errors) {
|
|
258
|
+
if (!result[error.field]) {
|
|
259
|
+
result[error.field] = [];
|
|
260
|
+
}
|
|
261
|
+
result[error.field].push(error.message);
|
|
262
|
+
}
|
|
263
|
+
return result;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// ============================================================================
|
|
268
|
+
// Factory Functions
|
|
269
|
+
// ============================================================================
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Create validation exception for required field
|
|
273
|
+
*/
|
|
274
|
+
export function ${entity.camel}Required(field: string): ${entity.pascal}ValidationException {
|
|
275
|
+
return new ${entity.pascal}ValidationException([
|
|
276
|
+
{ field, message: \`\${field} is required\`, code: 'required' },
|
|
277
|
+
]);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Create validation exception for invalid format
|
|
282
|
+
*/
|
|
283
|
+
export function ${entity.camel}InvalidFormat(
|
|
284
|
+
field: string,
|
|
285
|
+
expected: string
|
|
286
|
+
): ${entity.pascal}ValidationException {
|
|
287
|
+
return new ${entity.pascal}ValidationException([
|
|
288
|
+
{ field, message: \`\${field} must be a valid \${expected}\`, code: 'invalid_format' },
|
|
289
|
+
]);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Create validation exception for value out of range
|
|
294
|
+
*/
|
|
295
|
+
export function ${entity.camel}OutOfRange(
|
|
296
|
+
field: string,
|
|
297
|
+
min?: number,
|
|
298
|
+
max?: number
|
|
299
|
+
): ${entity.pascal}ValidationException {
|
|
300
|
+
let message = \`\${field} is out of range\`;
|
|
301
|
+
if (min !== undefined && max !== undefined) {
|
|
302
|
+
message = \`\${field} must be between \${min} and \${max}\`;
|
|
303
|
+
} else if (min !== undefined) {
|
|
304
|
+
message = \`\${field} must be at least \${min}\`;
|
|
305
|
+
} else if (max !== undefined) {
|
|
306
|
+
message = \`\${field} must be at most \${max}\`;
|
|
307
|
+
}
|
|
308
|
+
return new ${entity.pascal}ValidationException([{ field, message, code: 'out_of_range' }]);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// ============================================================================
|
|
312
|
+
// Type Guard
|
|
313
|
+
// ============================================================================
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Check if error is a validation exception
|
|
317
|
+
*/
|
|
318
|
+
export function is${entity.pascal}ValidationException(
|
|
319
|
+
error: unknown
|
|
320
|
+
): error is ${entity.pascal}ValidationException {
|
|
321
|
+
return error instanceof ${entity.pascal}ValidationException;
|
|
322
|
+
}
|
|
323
|
+
`;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Generate domain exception
|
|
327
|
+
*/
|
|
328
|
+
function generateDomainException(ctx) {
|
|
329
|
+
const { entity, options } = ctx;
|
|
330
|
+
const errorCodes = options.codes
|
|
331
|
+
? `
|
|
332
|
+
// ============================================================================
|
|
333
|
+
// Error Codes
|
|
334
|
+
// ============================================================================
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* ${entity.pascal} error codes
|
|
338
|
+
*/
|
|
339
|
+
export const ${entity.pascal}ErrorCode = {
|
|
340
|
+
NOT_FOUND: '${entity.screamingSnake}_NOT_FOUND',
|
|
341
|
+
ALREADY_EXISTS: '${entity.screamingSnake}_ALREADY_EXISTS',
|
|
342
|
+
INVALID_STATE: '${entity.screamingSnake}_INVALID_STATE',
|
|
343
|
+
LIMIT_EXCEEDED: '${entity.screamingSnake}_LIMIT_EXCEEDED',
|
|
344
|
+
EXPIRED: '${entity.screamingSnake}_EXPIRED',
|
|
345
|
+
LOCKED: '${entity.screamingSnake}_LOCKED',
|
|
346
|
+
DEPENDENCY_FAILED: '${entity.screamingSnake}_DEPENDENCY_FAILED',
|
|
347
|
+
} as const;
|
|
348
|
+
|
|
349
|
+
export type ${entity.pascal}ErrorCodeType = (typeof ${entity.pascal}ErrorCode)[keyof typeof ${entity.pascal}ErrorCode];
|
|
350
|
+
|
|
351
|
+
`
|
|
352
|
+
: '';
|
|
353
|
+
const codeParam = options.codes ? `${entity.pascal}ErrorCodeType` : 'string';
|
|
354
|
+
const codeDefault = options.codes
|
|
355
|
+
? `${entity.pascal}ErrorCode.NOT_FOUND`
|
|
356
|
+
: `'${entity.screamingSnake}_ERROR'`;
|
|
357
|
+
return `/**
|
|
358
|
+
* ${entity.pascal} Domain Exception
|
|
359
|
+
*
|
|
360
|
+
* Domain-specific exceptions for ${entity.humanReadable} business logic.
|
|
361
|
+
*/
|
|
362
|
+
${errorCodes}
|
|
363
|
+
// ============================================================================
|
|
364
|
+
// Base Domain Exception
|
|
365
|
+
// ============================================================================
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* ${entity.pascal} domain exception
|
|
369
|
+
*
|
|
370
|
+
* Base class for all ${entity.humanReadable}-related domain errors.
|
|
371
|
+
*/
|
|
372
|
+
export class ${entity.pascal}Exception extends Error {
|
|
373
|
+
constructor(
|
|
374
|
+
message: string,
|
|
375
|
+
public readonly code: ${codeParam} = ${codeDefault},
|
|
376
|
+
public readonly metadata?: Record<string, unknown>
|
|
377
|
+
) {
|
|
378
|
+
super(message);
|
|
379
|
+
this.name = '${entity.pascal}Exception';
|
|
380
|
+
Error.captureStackTrace(this, this.constructor);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Convert to serializable object
|
|
385
|
+
*/
|
|
386
|
+
toJSON(): Record<string, unknown> {
|
|
387
|
+
return {
|
|
388
|
+
name: this.name,
|
|
389
|
+
code: this.code,
|
|
390
|
+
message: this.message,
|
|
391
|
+
...(this.metadata && { metadata: this.metadata }),
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// ============================================================================
|
|
397
|
+
// Specific Exceptions
|
|
398
|
+
// ============================================================================
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* ${entity.pascal} not found
|
|
402
|
+
*/
|
|
403
|
+
export class ${entity.pascal}NotFoundException extends ${entity.pascal}Exception {
|
|
404
|
+
constructor(identifier?: string | Record<string, unknown>) {
|
|
405
|
+
const message =
|
|
406
|
+
typeof identifier === 'string'
|
|
407
|
+
? \`${entity.pascal} not found: \${identifier}\`
|
|
408
|
+
: '${entity.pascal} not found';
|
|
409
|
+
super(
|
|
410
|
+
message,
|
|
411
|
+
${options.codes ? `${entity.pascal}ErrorCode.NOT_FOUND` : `'${entity.screamingSnake}_NOT_FOUND'`},
|
|
412
|
+
typeof identifier === 'object' ? identifier : identifier ? { id: identifier } : undefined
|
|
413
|
+
);
|
|
414
|
+
this.name = '${entity.pascal}NotFoundException';
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* ${entity.pascal} already exists
|
|
420
|
+
*/
|
|
421
|
+
export class ${entity.pascal}AlreadyExistsException extends ${entity.pascal}Exception {
|
|
422
|
+
constructor(field: string, value: unknown) {
|
|
423
|
+
super(
|
|
424
|
+
\`${entity.pascal} with \${field} "\${value}" already exists\`,
|
|
425
|
+
${options.codes ? `${entity.pascal}ErrorCode.ALREADY_EXISTS` : `'${entity.screamingSnake}_ALREADY_EXISTS'`},
|
|
426
|
+
{ field, value }
|
|
427
|
+
);
|
|
428
|
+
this.name = '${entity.pascal}AlreadyExistsException';
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* ${entity.pascal} in invalid state
|
|
434
|
+
*/
|
|
435
|
+
export class ${entity.pascal}InvalidStateException extends ${entity.pascal}Exception {
|
|
436
|
+
constructor(currentState: string, requiredState: string | string[], action?: string) {
|
|
437
|
+
const required = Array.isArray(requiredState) ? requiredState.join(' or ') : requiredState;
|
|
438
|
+
const actionText = action ? \` to \${action}\` : '';
|
|
439
|
+
super(
|
|
440
|
+
\`${entity.pascal} must be in \${required} state\${actionText}, but is \${currentState}\`,
|
|
441
|
+
${options.codes ? `${entity.pascal}ErrorCode.INVALID_STATE` : `'${entity.screamingSnake}_INVALID_STATE'`},
|
|
442
|
+
{ currentState, requiredState, action }
|
|
443
|
+
);
|
|
444
|
+
this.name = '${entity.pascal}InvalidStateException';
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* ${entity.pascal} limit exceeded
|
|
450
|
+
*/
|
|
451
|
+
export class ${entity.pascal}LimitExceededException extends ${entity.pascal}Exception {
|
|
452
|
+
constructor(limit: number, current: number, resource?: string) {
|
|
453
|
+
const resourceText = resource ? \` for \${resource}\` : '';
|
|
454
|
+
super(
|
|
455
|
+
\`${entity.pascal} limit exceeded\${resourceText}: \${current}/\${limit}\`,
|
|
456
|
+
${options.codes ? `${entity.pascal}ErrorCode.LIMIT_EXCEEDED` : `'${entity.screamingSnake}_LIMIT_EXCEEDED'`},
|
|
457
|
+
{ limit, current, resource }
|
|
458
|
+
);
|
|
459
|
+
this.name = '${entity.pascal}LimitExceededException';
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* ${entity.pascal} expired
|
|
465
|
+
*/
|
|
466
|
+
export class ${entity.pascal}ExpiredException extends ${entity.pascal}Exception {
|
|
467
|
+
constructor(expiredAt?: Date) {
|
|
468
|
+
super(
|
|
469
|
+
expiredAt
|
|
470
|
+
? \`${entity.pascal} expired at \${expiredAt.toISOString()}\`
|
|
471
|
+
: '${entity.pascal} has expired',
|
|
472
|
+
${options.codes ? `${entity.pascal}ErrorCode.EXPIRED` : `'${entity.screamingSnake}_EXPIRED'`},
|
|
473
|
+
expiredAt ? { expiredAt: expiredAt.toISOString() } : undefined
|
|
474
|
+
);
|
|
475
|
+
this.name = '${entity.pascal}ExpiredException';
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// ============================================================================
|
|
480
|
+
// Type Guard
|
|
481
|
+
// ============================================================================
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Check if error is a ${entity.pascal} exception
|
|
485
|
+
*/
|
|
486
|
+
export function is${entity.pascal}Exception(error: unknown): error is ${entity.pascal}Exception {
|
|
487
|
+
return error instanceof ${entity.pascal}Exception;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Assert condition or throw ${entity.pascal} exception
|
|
492
|
+
*/
|
|
493
|
+
export function assert${entity.pascal}(
|
|
494
|
+
condition: boolean,
|
|
495
|
+
message: string,
|
|
496
|
+
code?: ${codeParam}
|
|
497
|
+
): asserts condition {
|
|
498
|
+
if (!condition) {
|
|
499
|
+
throw new ${entity.pascal}Exception(message, code);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
`;
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Generate simple exception template
|
|
506
|
+
*/
|
|
507
|
+
function generateSimpleException(ctx) {
|
|
508
|
+
const { entity } = ctx;
|
|
509
|
+
return `/**
|
|
510
|
+
* ${entity.pascal} Exception
|
|
511
|
+
*
|
|
512
|
+
* Custom exception for ${entity.humanReadable} errors.
|
|
513
|
+
*/
|
|
514
|
+
|
|
515
|
+
// ============================================================================
|
|
516
|
+
// Exception Class
|
|
517
|
+
// ============================================================================
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* ${entity.pascal} exception
|
|
521
|
+
*
|
|
522
|
+
* Thrown when ${entity.humanReadable} operations fail.
|
|
523
|
+
*
|
|
524
|
+
* @example
|
|
525
|
+
* throw new ${entity.pascal}Exception('Operation failed', 'OPERATION_FAILED');
|
|
526
|
+
*/
|
|
527
|
+
export class ${entity.pascal}Exception extends Error {
|
|
528
|
+
constructor(
|
|
529
|
+
message: string,
|
|
530
|
+
public readonly code: string = '${entity.screamingSnake}_ERROR',
|
|
531
|
+
public readonly details?: Record<string, unknown>
|
|
532
|
+
) {
|
|
533
|
+
super(message);
|
|
534
|
+
this.name = '${entity.pascal}Exception';
|
|
535
|
+
Error.captureStackTrace(this, this.constructor);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* Convert to JSON for API responses
|
|
540
|
+
*/
|
|
541
|
+
toJSON(): Record<string, unknown> {
|
|
542
|
+
return {
|
|
543
|
+
error: {
|
|
544
|
+
name: this.name,
|
|
545
|
+
code: this.code,
|
|
546
|
+
message: this.message,
|
|
547
|
+
...(this.details && { details: this.details }),
|
|
548
|
+
},
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Create a new exception with additional details
|
|
554
|
+
*/
|
|
555
|
+
withDetails(details: Record<string, unknown>): ${entity.pascal}Exception {
|
|
556
|
+
return new ${entity.pascal}Exception(this.message, this.code, {
|
|
557
|
+
...this.details,
|
|
558
|
+
...details,
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
// ============================================================================
|
|
564
|
+
// Factory Functions
|
|
565
|
+
// ============================================================================
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Create ${entity.humanReadable} not found exception
|
|
569
|
+
*/
|
|
570
|
+
export function ${entity.camel}NotFound(id?: string): ${entity.pascal}Exception {
|
|
571
|
+
return new ${entity.pascal}Exception(
|
|
572
|
+
id ? \`${entity.pascal} not found: \${id}\` : '${entity.pascal} not found',
|
|
573
|
+
'${entity.screamingSnake}_NOT_FOUND',
|
|
574
|
+
id ? { id } : undefined
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Create ${entity.humanReadable} invalid exception
|
|
580
|
+
*/
|
|
581
|
+
export function ${entity.camel}Invalid(reason: string): ${entity.pascal}Exception {
|
|
582
|
+
return new ${entity.pascal}Exception(
|
|
583
|
+
\`Invalid ${entity.humanReadable}: \${reason}\`,
|
|
584
|
+
'${entity.screamingSnake}_INVALID',
|
|
585
|
+
{ reason }
|
|
586
|
+
);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* Create ${entity.humanReadable} unauthorized exception
|
|
591
|
+
*/
|
|
592
|
+
export function ${entity.camel}Unauthorized(action?: string): ${entity.pascal}Exception {
|
|
593
|
+
return new ${entity.pascal}Exception(
|
|
594
|
+
action
|
|
595
|
+
? \`Not authorized to \${action} ${entity.humanReadable}\`
|
|
596
|
+
: 'Not authorized to access ${entity.humanReadable}',
|
|
597
|
+
'${entity.screamingSnake}_UNAUTHORIZED',
|
|
598
|
+
action ? { action } : undefined
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// ============================================================================
|
|
603
|
+
// Type Guard
|
|
604
|
+
// ============================================================================
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Check if error is a ${entity.pascal} exception
|
|
608
|
+
*/
|
|
609
|
+
export function is${entity.pascal}Exception(error: unknown): error is ${entity.pascal}Exception {
|
|
610
|
+
return error instanceof ${entity.pascal}Exception;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* Wrap any error as ${entity.pascal} exception
|
|
615
|
+
*/
|
|
616
|
+
export function wrap${entity.pascal}Exception(
|
|
617
|
+
error: unknown,
|
|
618
|
+
defaultMessage = '${entity.pascal} operation failed'
|
|
619
|
+
): ${entity.pascal}Exception {
|
|
620
|
+
if (is${entity.pascal}Exception(error)) {
|
|
621
|
+
return error;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
const message = error instanceof Error ? error.message : defaultMessage;
|
|
625
|
+
return new ${entity.pascal}Exception(message, '${entity.screamingSnake}_ERROR', {
|
|
626
|
+
originalError: error instanceof Error ? error.name : typeof error,
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
`;
|
|
630
|
+
}
|
|
631
|
+
// ============================================================================
|
|
632
|
+
// Main Template
|
|
633
|
+
// ============================================================================
|
|
634
|
+
/**
|
|
635
|
+
* Exception template function
|
|
636
|
+
*/
|
|
637
|
+
export const exceptionTemplate = (ctx) => {
|
|
638
|
+
if (ctx.options.http) {
|
|
639
|
+
return generateHttpException(ctx);
|
|
640
|
+
}
|
|
641
|
+
if (ctx.options.validation) {
|
|
642
|
+
return generateValidationException(ctx);
|
|
643
|
+
}
|
|
644
|
+
if (ctx.options.domain) {
|
|
645
|
+
return generateDomainException(ctx);
|
|
646
|
+
}
|
|
647
|
+
return generateSimpleException(ctx);
|
|
648
|
+
};
|
|
649
|
+
// ============================================================================
|
|
650
|
+
// Post-generation Instructions
|
|
651
|
+
// ============================================================================
|
|
652
|
+
export function getExceptionInstructions(entityName, options) {
|
|
653
|
+
const lines = [`Your ${entityName} exception has been created.`, '', 'Next steps:'];
|
|
654
|
+
lines.push(' 1. Import and throw in your services/procedures:');
|
|
655
|
+
lines.push(` import { ${entityName}Exception } from '@/exceptions/${entityName.toLowerCase()}';`);
|
|
656
|
+
lines.push(` throw new ${entityName}Exception('Something went wrong');`);
|
|
657
|
+
if (options.http) {
|
|
658
|
+
lines.push(' 2. Handle in your error middleware to set HTTP status');
|
|
659
|
+
}
|
|
660
|
+
else if (options.validation) {
|
|
661
|
+
lines.push(' 2. Use with Zod: throw ValidationException.fromZodError(error)');
|
|
662
|
+
}
|
|
663
|
+
else if (options.domain) {
|
|
664
|
+
lines.push(' 2. Add more domain-specific exception subclasses as needed');
|
|
665
|
+
}
|
|
666
|
+
if (options.codes) {
|
|
667
|
+
lines.push(' 3. Add more error codes to the ErrorCode enum');
|
|
668
|
+
}
|
|
669
|
+
return lines.join('\n');
|
|
670
|
+
}
|
|
671
|
+
//# sourceMappingURL=exception.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exception.js","sourceRoot":"","sources":["../../../src/generators/templates/exception.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAmBH,+EAA+E;AAC/E,eAAe;AACf,+EAA+E;AAE/E;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,UAAkB,EAAE,QAAwB;IAC3E,OAAO,kBAAkB,UAAU,CAAC,WAAW,EAAE,KAAK,CAAC;AACzD,CAAC;AAED,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E;;GAEG;AACH,SAAS,qBAAqB,CAAC,GAAsC;IACnE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAEvB,OAAO;KACJ,MAAM,CAAC,MAAM;;+BAEa,MAAM,CAAC,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAsC9C,MAAM,CAAC,MAAM;;;;KAIb,MAAM,CAAC,MAAM;;eAEH,MAAM,CAAC,MAAM;;;;eAIb,MAAM,CAAC,MAAM,2BAA2B,MAAM,CAAC,MAAM;SAC3D,MAAM,CAAC,cAAc;;mBAE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AAC,QAAQ,UAAU,8BAA8B,EAAE,EAAE,EAAE,aAAa,CAAC,CAAC;IAEpF,KAAK,CAAC,IAAI,CAAC,oDAAoD,CAAC,CAAC;IACjE,KAAK,CAAC,IAAI,CACR,iBAAiB,UAAU,kCAAkC,UAAU,CAAC,WAAW,EAAE,IAAI,CAC1F,CAAC;IACF,KAAK,CAAC,IAAI,CAAC,kBAAkB,UAAU,oCAAoC,CAAC,CAAC;IAE7E,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,KAAK,CAAC,IAAI,CAAC,yDAAyD,CAAC,CAAC;IACxE,CAAC;SAAM,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QAC9B,KAAK,CAAC,IAAI,CAAC,kEAAkE,CAAC,CAAC;IACjF,CAAC;SAAM,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QAC1B,KAAK,CAAC,IAAI,CAAC,8DAA8D,CAAC,CAAC;IAC7E,CAAC;IAED,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QAClB,KAAK,CAAC,IAAI,CAAC,iDAAiD,CAAC,CAAC;IAChE,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guard Template
|
|
3
|
+
*
|
|
4
|
+
* Generates auth guard files for VeloxTS applications.
|
|
5
|
+
*/
|
|
6
|
+
import type { ProjectContext, TemplateFunction } from '../types.js';
|
|
7
|
+
export interface GuardOptions {
|
|
8
|
+
/** Generate role-based guard */
|
|
9
|
+
role: boolean;
|
|
10
|
+
/** Generate permission-based guard */
|
|
11
|
+
permission: boolean;
|
|
12
|
+
/** Generate ownership guard */
|
|
13
|
+
ownership: boolean;
|
|
14
|
+
/** Generate composite guard */
|
|
15
|
+
composite: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get the path for a guard file
|
|
19
|
+
*/
|
|
20
|
+
export declare function getGuardPath(entityName: string, _project: ProjectContext): string;
|
|
21
|
+
/**
|
|
22
|
+
* Guard template function
|
|
23
|
+
*/
|
|
24
|
+
export declare const guardTemplate: TemplateFunction<GuardOptions>;
|
|
25
|
+
export declare function getGuardInstructions(entityName: string, options: GuardOptions): string;
|
|
26
|
+
//# sourceMappingURL=guard.d.ts.map
|