@postxl/generator 0.0.19 → 0.0.21
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/CHANGELOG.md +7 -0
- package/README.md +2 -2
- package/changelog.md +6 -0
- package/dist/src/generator.js +13 -13
- package/dist/src/generators/enums/react.generator.js +55 -55
- package/dist/src/generators/enums/types.generator.js +8 -8
- package/dist/src/generators/indices/datamockmodule.generator.js +46 -46
- package/dist/src/generators/indices/datamodule.generator.js +76 -76
- package/dist/src/generators/indices/dataservice.generator.js +26 -26
- package/dist/src/generators/indices/repositories.generator.js +3 -3
- package/dist/src/generators/indices/testdataservice.generator.js +22 -22
- package/dist/src/generators/models/react.generator/context.generator.js +47 -47
- package/dist/src/generators/models/react.generator/index.js +8 -8
- package/dist/src/generators/models/react.generator/library.generator.js +66 -66
- package/dist/src/generators/models/react.generator/lookup.generator.js +75 -75
- package/dist/src/generators/models/react.generator/modals.generator.js +261 -261
- package/dist/src/generators/models/repository.generator.js +239 -239
- package/dist/src/generators/models/route.generator.js +45 -45
- package/dist/src/generators/models/seed.generator.js +14 -14
- package/dist/src/generators/models/stub.generator.js +19 -19
- package/dist/src/generators/models/types.generator.js +39 -39
- package/dist/src/lib/meta.d.ts +7 -7
- package/dist/src/lib/meta.js +4 -4
- package/dist/src/lib/vfs.js +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/jest.config.ts +18 -18
- package/package.json +1 -1
- package/tests/attributes.test.ts +91 -91
- package/tests/file.test.ts +32 -32
- package/tests/schemas/la/la.prisma +862 -862
- package/tests/schemas/mca/mca.prisma +528 -528
- package/tests/utils/random.ts +11 -11
- package/tests/vfs.test.ts +92 -92
|
@@ -31,12 +31,12 @@ function generateSeedModel({ model, itemCount, meta, }) {
|
|
|
31
31
|
for (let i = 1; i <= exampleMode.itemCount; i++) {
|
|
32
32
|
seed.push(generateSeedData({ model, index: i, exampleMode }));
|
|
33
33
|
}
|
|
34
|
-
return `
|
|
35
|
-
${imports.generate()}
|
|
36
|
-
|
|
37
|
-
export const ${meta.seed.constantName}: ${model.typeName}[] = [
|
|
38
|
-
${seed.join(',\n')}
|
|
39
|
-
]
|
|
34
|
+
return `
|
|
35
|
+
${imports.generate()}
|
|
36
|
+
|
|
37
|
+
export const ${meta.seed.constantName}: ${model.typeName}[] = [
|
|
38
|
+
${seed.join(',\n')}
|
|
39
|
+
]
|
|
40
40
|
`;
|
|
41
41
|
}
|
|
42
42
|
exports.generateSeedModel = generateSeedModel;
|
|
@@ -172,14 +172,14 @@ function generateSeeds({ models, config, }) {
|
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
174
|
const seeds = models.map(({ meta }) => `${meta.seed.constantName}`).join(',\n');
|
|
175
|
-
return `
|
|
176
|
-
import { MockData } from '${config.paths.seedPath}'
|
|
177
|
-
|
|
178
|
-
${imports.generate()}
|
|
179
|
-
|
|
180
|
-
export const seed: MockData = {
|
|
181
|
-
${seeds}
|
|
182
|
-
}
|
|
175
|
+
return `
|
|
176
|
+
import { MockData } from '${config.paths.seedPath}'
|
|
177
|
+
|
|
178
|
+
${imports.generate()}
|
|
179
|
+
|
|
180
|
+
export const seed: MockData = {
|
|
181
|
+
${seeds}
|
|
182
|
+
}
|
|
183
183
|
`;
|
|
184
184
|
}
|
|
185
185
|
exports.generateSeeds = generateSeeds;
|
|
@@ -24,25 +24,25 @@ function generateStub({ model, meta }) {
|
|
|
24
24
|
from: meta.types.importPath,
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
return `
|
|
28
|
-
${imports.generate()}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Utility object containing default values for all fields in a model.
|
|
32
|
-
*/
|
|
33
|
-
export const ${meta.data.defaultStubConstantName}: ${model.typeName} = {
|
|
34
|
-
${getAssigmentStatementModel({ fields })}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Utility function that creates a new ${meta.userFriendlyName} object from a partial object of values.
|
|
39
|
-
*/
|
|
40
|
-
export const ${meta.data.stubGenerationFnName} = (
|
|
41
|
-
item: Partial<${model.typeName}>
|
|
42
|
-
): ${model.typeName} => ({
|
|
43
|
-
...${meta.data.defaultStubConstantName},
|
|
44
|
-
...item,
|
|
45
|
-
})
|
|
27
|
+
return `
|
|
28
|
+
${imports.generate()}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Utility object containing default values for all fields in a model.
|
|
32
|
+
*/
|
|
33
|
+
export const ${meta.data.defaultStubConstantName}: ${model.typeName} = {
|
|
34
|
+
${getAssigmentStatementModel({ fields })}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Utility function that creates a new ${meta.userFriendlyName} object from a partial object of values.
|
|
39
|
+
*/
|
|
40
|
+
export const ${meta.data.stubGenerationFnName} = (
|
|
41
|
+
item: Partial<${model.typeName}>
|
|
42
|
+
): ${model.typeName} => ({
|
|
43
|
+
...${meta.data.defaultStubConstantName},
|
|
44
|
+
...item,
|
|
45
|
+
})
|
|
46
46
|
`;
|
|
47
47
|
}
|
|
48
48
|
exports.generateStub = generateStub;
|
|
@@ -33,47 +33,47 @@ function generateModelTypes({ model, meta }) {
|
|
|
33
33
|
from: refEnumMeta.types.filePath,
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
-
return `
|
|
37
|
-
import { z } from 'zod'
|
|
38
|
-
|
|
39
|
-
${imports.generate()}
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
return `
|
|
37
|
+
import { z } from 'zod'
|
|
38
|
+
|
|
39
|
+
${imports.generate()}
|
|
40
|
+
|
|
41
|
+
|
|
42
42
|
${model.description
|
|
43
|
-
? `
|
|
44
|
-
/**
|
|
45
|
-
* ${model.description.split('\n').join('\n * ')}
|
|
43
|
+
? `
|
|
44
|
+
/**
|
|
45
|
+
* ${model.description.split('\n').join('\n * ')}
|
|
46
46
|
*/`
|
|
47
|
-
: ''}
|
|
48
|
-
export type ${model.typeName} = {
|
|
47
|
+
: ''}
|
|
48
|
+
export type ${model.typeName} = {
|
|
49
49
|
${model.fields
|
|
50
|
-
.map((f) => `
|
|
51
|
-
${getFieldComment(f)}
|
|
50
|
+
.map((f) => `
|
|
51
|
+
${getFieldComment(f)}
|
|
52
52
|
${f.name}: ${getFieldType(f)}${f.isRequired ? '' : ' | null'}`)
|
|
53
|
-
.join('\n')}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Branded Id type that should be used to identify an instance of this model.
|
|
58
|
-
*/
|
|
59
|
-
export type ${model.brandedIdType} = ${idField.unbrandedTypeName} & {
|
|
60
|
-
readonly ___type: '${model.typeName}'
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Converts a given scalar to a branded id type.
|
|
65
|
-
*/
|
|
66
|
-
export function ${meta.types.toBrandedIdTypeFnName}(id: ${idField.unbrandedTypeName}): ${model.brandedIdType} {
|
|
67
|
-
return id as ${model.brandedIdType}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Zod decoder for validating a Participant object.
|
|
72
|
-
*/
|
|
73
|
-
export const ${meta.types.zodDecoderFnName} = z.object({
|
|
74
|
-
${model.fields.map((field) => `${field.name}: z.${(0, zod_1.getZodDecoderDefinition)({ field })}`).join(',')}
|
|
75
|
-
})
|
|
76
|
-
|
|
53
|
+
.join('\n')}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Branded Id type that should be used to identify an instance of this model.
|
|
58
|
+
*/
|
|
59
|
+
export type ${model.brandedIdType} = ${idField.unbrandedTypeName} & {
|
|
60
|
+
readonly ___type: '${model.typeName}'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Converts a given scalar to a branded id type.
|
|
65
|
+
*/
|
|
66
|
+
export function ${meta.types.toBrandedIdTypeFnName}(id: ${idField.unbrandedTypeName}): ${model.brandedIdType} {
|
|
67
|
+
return id as ${model.brandedIdType}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Zod decoder for validating a Participant object.
|
|
72
|
+
*/
|
|
73
|
+
export const ${meta.types.zodDecoderFnName} = z.object({
|
|
74
|
+
${model.fields.map((field) => `${field.name}: z.${(0, zod_1.getZodDecoderDefinition)({ field })}`).join(',')}
|
|
75
|
+
})
|
|
76
|
+
|
|
77
77
|
`;
|
|
78
78
|
}
|
|
79
79
|
exports.generateModelTypes = generateModelTypes;
|
|
@@ -88,8 +88,8 @@ function getFieldComment(f) {
|
|
|
88
88
|
}
|
|
89
89
|
if (comment === '')
|
|
90
90
|
return '';
|
|
91
|
-
return `
|
|
92
|
-
/**
|
|
91
|
+
return `
|
|
92
|
+
/**
|
|
93
93
|
${comment}*/`;
|
|
94
94
|
}
|
|
95
95
|
function getFieldExamples(f) {
|
package/dist/src/lib/meta.d.ts
CHANGED
|
@@ -227,11 +227,11 @@ export type ModelMetaData = {
|
|
|
227
227
|
routerName: Types.VariableName;
|
|
228
228
|
getMap: {
|
|
229
229
|
/**
|
|
230
|
-
* The name of the TRPC
|
|
230
|
+
* The name of the TRPC getMap method (e.g. `getMap` or `getMapAggregation`).
|
|
231
231
|
*/
|
|
232
232
|
methodName: Types.VariableName;
|
|
233
233
|
/**
|
|
234
|
-
* The full method name of the React Query method (e.g. `
|
|
234
|
+
* The full method name of the React Query method (e.g. `aggregations.getMap`).
|
|
235
235
|
*/
|
|
236
236
|
reactQueryMethod: Types.Function;
|
|
237
237
|
};
|
|
@@ -241,27 +241,27 @@ export type ModelMetaData = {
|
|
|
241
241
|
*/
|
|
242
242
|
methodName: Types.VariableName;
|
|
243
243
|
/**
|
|
244
|
-
* The full method name of the React Query method (e.g. `
|
|
244
|
+
* The full method name of the React Query method (e.g. `aggregations.create`).
|
|
245
245
|
*/
|
|
246
246
|
reactQueryMethod: Types.Function;
|
|
247
247
|
};
|
|
248
248
|
update: {
|
|
249
249
|
/**
|
|
250
|
-
* The name of the TRPC
|
|
250
|
+
* The name of the TRPC udpate method (e.g. `udpate` or `udpateAggregation`).
|
|
251
251
|
*/
|
|
252
252
|
methodName: Types.VariableName;
|
|
253
253
|
/**
|
|
254
|
-
* The full method name of the React Query method (e.g. `
|
|
254
|
+
* The full method name of the React Query method (e.g. `aggregations.update`).
|
|
255
255
|
*/
|
|
256
256
|
reactQueryMethod: Types.Function;
|
|
257
257
|
};
|
|
258
258
|
delete: {
|
|
259
259
|
/**
|
|
260
|
-
* The name of the TRPC
|
|
260
|
+
* The name of the TRPC delete method (e.g. `delete` or `deleteAggregation`).
|
|
261
261
|
*/
|
|
262
262
|
methodName: Types.VariableName;
|
|
263
263
|
/**
|
|
264
|
-
* The full method name of the React Query method (e.g. `
|
|
264
|
+
* The full method name of the React Query method (e.g. `aggregations.delete`).
|
|
265
265
|
*/
|
|
266
266
|
reactQueryMethod: Types.Function;
|
|
267
267
|
};
|
package/dist/src/lib/meta.js
CHANGED
|
@@ -120,19 +120,19 @@ function getModelMetadata({ model }) {
|
|
|
120
120
|
importPath: Types.toPath(`@${config.project}${camelCase}.router`),
|
|
121
121
|
getMap: {
|
|
122
122
|
methodName: Types.toVariableName('getMap'),
|
|
123
|
-
reactQueryMethod: Types.toFunction(`${
|
|
123
|
+
reactQueryMethod: Types.toFunction(`${uncapitalizedPlural}.getMap`),
|
|
124
124
|
},
|
|
125
125
|
create: {
|
|
126
126
|
methodName: Types.toVariableName('create'),
|
|
127
|
-
reactQueryMethod: Types.toFunction(`${
|
|
127
|
+
reactQueryMethod: Types.toFunction(`${uncapitalizedPlural}.create`),
|
|
128
128
|
},
|
|
129
129
|
update: {
|
|
130
130
|
methodName: Types.toVariableName('update'),
|
|
131
|
-
reactQueryMethod: Types.toFunction(`${
|
|
131
|
+
reactQueryMethod: Types.toFunction(`${uncapitalizedPlural}.update`),
|
|
132
132
|
},
|
|
133
133
|
delete: {
|
|
134
134
|
methodName: Types.toVariableName('delete'),
|
|
135
|
-
reactQueryMethod: Types.toFunction(`${
|
|
135
|
+
reactQueryMethod: Types.toFunction(`${uncapitalizedPlural}.delete`),
|
|
136
136
|
},
|
|
137
137
|
},
|
|
138
138
|
types: {
|
package/dist/src/lib/vfs.js
CHANGED
|
@@ -382,8 +382,8 @@ class VirtualFS {
|
|
|
382
382
|
return prettier.format(content, Object.assign(Object.assign({}, options), { parser }));
|
|
383
383
|
}
|
|
384
384
|
catch (err) {
|
|
385
|
-
(0, error_1.throwError)(`
|
|
386
|
-
${content}\n\n
|
|
385
|
+
(0, error_1.throwError)(`
|
|
386
|
+
${content}\n\n
|
|
387
387
|
Failed to format ${path}\n\n`);
|
|
388
388
|
}
|
|
389
389
|
});
|