@postxl/generator 0.44.3 → 0.44.5
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/generator.js +8 -9
- package/dist/generators/enums/react.generator.js +1 -1
- package/dist/generators/indices/businesslogic-update-module.generator.js +1 -1
- package/dist/generators/indices/businesslogic-view-module.generator.js +1 -1
- package/dist/generators/indices/data-types.generator.js +4 -3
- package/dist/generators/indices/datamock-module.generator.js +3 -3
- package/dist/generators/indices/datamocker.generator.js +5 -4
- package/dist/generators/indices/datamodule.generator.js +3 -3
- package/dist/generators/indices/dataservice.generator.js +5 -4
- package/dist/generators/indices/dispatcher-service.generator.js +4 -3
- package/dist/generators/indices/importexport-convert-import-functions.generator.js +29 -24
- package/dist/generators/indices/importexport-exporter-class.generator.js +4 -3
- package/dist/generators/indices/importexport-import-service.generator.js +27 -12
- package/dist/generators/indices/importexport-types.generator.js +9 -4
- package/dist/generators/indices/stubs.generator.js +2 -2
- package/dist/generators/indices/testdata-service.generator.js +5 -2
- package/dist/generators/models/businesslogic-update.generator.js +11 -10
- package/dist/generators/models/businesslogic-view.generator.js +4 -3
- package/dist/generators/models/importexport-decoder.generator.d.ts +2 -1
- package/dist/generators/models/importexport-decoder.generator.js +20 -19
- package/dist/generators/models/react.generator/context.generator.js +1 -1
- package/dist/generators/models/react.generator/index.js +2 -8
- package/dist/generators/models/react.generator/library.generator.d.ts +0 -2
- package/dist/generators/models/react.generator/library.generator.js +3 -5
- package/dist/generators/models/react.generator/lookup.generator.js +3 -6
- package/dist/generators/models/react.generator/modals.generator.js +4 -4
- package/dist/generators/models/repository.generator.js +26 -17
- package/dist/generators/models/route.generator.js +3 -2
- package/dist/generators/models/seed.generator.js +5 -4
- package/dist/generators/models/stub.generator.js +7 -2
- package/dist/generators/models/types.generator.js +7 -3
- package/dist/lib/exports.d.ts +2 -2
- package/dist/lib/imports.d.ts +12 -3
- package/dist/lib/imports.js +47 -15
- package/dist/lib/meta.d.ts +163 -88
- package/dist/lib/meta.js +68 -23
- package/dist/lib/schema/schema.d.ts +15 -18
- package/dist/lib/schema/types.d.ts +35 -5
- package/dist/lib/schema/types.js +20 -2
- package/dist/lib/types.d.ts +1 -1
- package/dist/lib/types.js +1 -1
- package/dist/prisma/parse.js +7 -9
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateModelBusinessLogicUpdate = void 0;
|
|
4
4
|
const imports_1 = require("../../lib/imports");
|
|
5
5
|
const meta_1 = require("../../lib/meta");
|
|
6
|
+
const types_1 = require("../../lib/schema/types");
|
|
6
7
|
const jsdoc_1 = require("../../lib/utils/jsdoc");
|
|
7
8
|
const repository_generator_1 = require("./repository.generator");
|
|
8
9
|
/**
|
|
@@ -15,7 +16,7 @@ function generateModelBusinessLogicUpdate({ model, meta }) {
|
|
|
15
16
|
imports.addImports({
|
|
16
17
|
[meta.data.importPath]: meta.data.repository.className,
|
|
17
18
|
[schemaMeta.actions.importPath]: schemaMeta.actions.actionExecution.interface,
|
|
18
|
-
[meta.types.importPath]: [model.brandedIdType, meta.types.typeName],
|
|
19
|
+
[meta.types.importPath]: [(0, types_1.toAnnotatedTypeName)(model.brandedIdType), (0, types_1.toAnnotatedTypeName)(meta.types.typeName)],
|
|
19
20
|
[schemaMeta.businessLogic.update.serviceFilePath]: schemaMeta.businessLogic.update.serviceClassName,
|
|
20
21
|
[schemaMeta.businessLogic.view.serviceFilePath]: schemaMeta.businessLogic.view.serviceClassName,
|
|
21
22
|
[meta.data.importPath]: [meta.data.repository.className],
|
|
@@ -43,7 +44,7 @@ function generateModelBusinessLogicUpdate({ model, meta }) {
|
|
|
43
44
|
const methodTypeSignatures = (0, repository_generator_1.getRepositoryMethodsTypeSignatures)({ model, meta });
|
|
44
45
|
return /* ts */ `
|
|
45
46
|
import { Inject, Injectable, forwardRef } from '@nestjs/common'
|
|
46
|
-
import { ExhaustiveSwitchCheck } from '@
|
|
47
|
+
import { ExhaustiveSwitchCheck } from '@backend/common'
|
|
47
48
|
|
|
48
49
|
${imports.generate()}
|
|
49
50
|
|
|
@@ -163,7 +164,7 @@ function prepareActionDefinitions({ model, meta, }) {
|
|
|
163
164
|
createFunctionName: meta.businessLogic.update.createActionFunctionNameCreate,
|
|
164
165
|
payload: meta.types.dto.create,
|
|
165
166
|
resultType: meta.types.typeName,
|
|
166
|
-
imports: [meta.types.dto.create],
|
|
167
|
+
imports: [(0, types_1.toAnnotatedTypeName)(meta.types.dto.create)],
|
|
167
168
|
dispatcherParameterName: 'item',
|
|
168
169
|
},
|
|
169
170
|
createMany: {
|
|
@@ -171,7 +172,7 @@ function prepareActionDefinitions({ model, meta, }) {
|
|
|
171
172
|
createFunctionName: meta.businessLogic.update.createActionFunctionNameCreateMany,
|
|
172
173
|
payload: `${meta.types.dto.create}[]`,
|
|
173
174
|
resultType: `${meta.types.typeName}[]`,
|
|
174
|
-
imports: [meta.types.dto.create],
|
|
175
|
+
imports: [(0, types_1.toAnnotatedTypeName)(meta.types.dto.create)],
|
|
175
176
|
dispatcherParameterName: 'items',
|
|
176
177
|
},
|
|
177
178
|
update: {
|
|
@@ -179,7 +180,7 @@ function prepareActionDefinitions({ model, meta, }) {
|
|
|
179
180
|
createFunctionName: meta.businessLogic.update.createActionFunctionNameUpdate,
|
|
180
181
|
payload: meta.types.dto.update,
|
|
181
182
|
resultType: meta.types.typeName,
|
|
182
|
-
imports: [meta.types.dto.update],
|
|
183
|
+
imports: [(0, types_1.toAnnotatedTypeName)(meta.types.dto.update)],
|
|
183
184
|
dispatcherParameterName: 'item',
|
|
184
185
|
},
|
|
185
186
|
updateMany: {
|
|
@@ -187,7 +188,7 @@ function prepareActionDefinitions({ model, meta, }) {
|
|
|
187
188
|
createFunctionName: meta.businessLogic.update.createActionFunctionNameUpdateMany,
|
|
188
189
|
payload: `${meta.types.dto.update}[]`,
|
|
189
190
|
resultType: `${meta.types.typeName}[]`,
|
|
190
|
-
imports: [meta.types.dto.update],
|
|
191
|
+
imports: [(0, types_1.toAnnotatedTypeName)(meta.types.dto.update)],
|
|
191
192
|
dispatcherParameterName: 'items',
|
|
192
193
|
},
|
|
193
194
|
upsert: {
|
|
@@ -195,7 +196,7 @@ function prepareActionDefinitions({ model, meta, }) {
|
|
|
195
196
|
createFunctionName: meta.businessLogic.update.createActionFunctionNameUpsert,
|
|
196
197
|
payload: meta.types.dto.upsert,
|
|
197
198
|
resultType: meta.types.typeName,
|
|
198
|
-
imports: [meta.types.dto.upsert],
|
|
199
|
+
imports: [(0, types_1.toAnnotatedTypeName)(meta.types.dto.upsert)],
|
|
199
200
|
dispatcherParameterName: 'item',
|
|
200
201
|
},
|
|
201
202
|
upsertMany: {
|
|
@@ -203,7 +204,7 @@ function prepareActionDefinitions({ model, meta, }) {
|
|
|
203
204
|
createFunctionName: meta.businessLogic.update.createActionFunctionNameUpsertMany,
|
|
204
205
|
payload: `${meta.types.dto.upsert}[]`,
|
|
205
206
|
resultType: `${meta.types.typeName}[]`,
|
|
206
|
-
imports: [meta.types.dto.upsert],
|
|
207
|
+
imports: [(0, types_1.toAnnotatedTypeName)(meta.types.dto.upsert)],
|
|
207
208
|
dispatcherParameterName: 'items',
|
|
208
209
|
},
|
|
209
210
|
delete: {
|
|
@@ -211,7 +212,7 @@ function prepareActionDefinitions({ model, meta, }) {
|
|
|
211
212
|
createFunctionName: meta.businessLogic.update.createActionFunctionNameDelete,
|
|
212
213
|
payload: model.brandedIdType,
|
|
213
214
|
resultType: model.brandedIdType,
|
|
214
|
-
imports: [model.brandedIdType],
|
|
215
|
+
imports: [(0, types_1.toAnnotatedTypeName)(model.brandedIdType)],
|
|
215
216
|
dispatcherParameterName: 'id',
|
|
216
217
|
},
|
|
217
218
|
deleteMany: {
|
|
@@ -219,7 +220,7 @@ function prepareActionDefinitions({ model, meta, }) {
|
|
|
219
220
|
createFunctionName: meta.businessLogic.update.createActionFunctionNameDeleteMany,
|
|
220
221
|
payload: `${model.brandedIdType}[]`,
|
|
221
222
|
resultType: `${model.brandedIdType}[]`,
|
|
222
|
-
imports: [model.brandedIdType],
|
|
223
|
+
imports: [(0, types_1.toAnnotatedTypeName)(model.brandedIdType)],
|
|
223
224
|
dispatcherParameterName: 'ids',
|
|
224
225
|
},
|
|
225
226
|
};
|
|
@@ -4,6 +4,7 @@ exports.generateModelBusinessLogicView = void 0;
|
|
|
4
4
|
const imports_1 = require("../../lib/imports");
|
|
5
5
|
const meta_1 = require("../../lib/meta");
|
|
6
6
|
const fields_1 = require("../../lib/schema/fields");
|
|
7
|
+
const types_1 = require("../../lib/schema/types");
|
|
7
8
|
const ast_1 = require("../../lib/utils/ast");
|
|
8
9
|
/**
|
|
9
10
|
* Generates view business logic for a given model.
|
|
@@ -14,7 +15,7 @@ function generateModelBusinessLogicView({ model, meta }) {
|
|
|
14
15
|
const imports = imports_1.ImportsGenerator.from(meta.businessLogic.view.serviceFilePath);
|
|
15
16
|
imports.addImports({
|
|
16
17
|
[meta.data.importPath]: meta.data.repository.className,
|
|
17
|
-
[meta.types.importPath]: [model.brandedIdType, meta.types.typeName],
|
|
18
|
+
[meta.types.importPath]: [(0, types_1.toAnnotatedTypeName)(model.brandedIdType), (0, types_1.toAnnotatedTypeName)(meta.types.typeName)],
|
|
18
19
|
[schemaMeta.businessLogic.view.serviceFilePath]: schemaMeta.businessLogic.view.serviceClassName,
|
|
19
20
|
[meta.data.importPath]: [meta.data.repository.className],
|
|
20
21
|
});
|
|
@@ -59,7 +60,7 @@ function generateModelBusinessLogicView({ model, meta }) {
|
|
|
59
60
|
}
|
|
60
61
|
const hasLinkedItems = variables.size > 0;
|
|
61
62
|
if (hasLinkedItems) {
|
|
62
|
-
imports.
|
|
63
|
+
imports.addTypeImport({ from: meta.types.importPath, items: [meta.types.linkedTypeName] });
|
|
63
64
|
}
|
|
64
65
|
const linkedItemsGetterFn = `
|
|
65
66
|
/**
|
|
@@ -95,7 +96,7 @@ function generateModelBusinessLogicView({ model, meta }) {
|
|
|
95
96
|
return /* ts */ `
|
|
96
97
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
97
98
|
import { Inject, Injectable, forwardRef } from '@nestjs/common'
|
|
98
|
-
import { FilterOperator } from '@
|
|
99
|
+
import { FilterOperator } from '@backend/common'
|
|
99
100
|
|
|
100
101
|
${imports.generate()}
|
|
101
102
|
|
|
@@ -3,9 +3,10 @@ import { Model } from '../../lib/schema/schema';
|
|
|
3
3
|
/**
|
|
4
4
|
* Creates a decoder for the Seed Excel template.
|
|
5
5
|
*/
|
|
6
|
-
export declare function generateModelImportExportDecoder({ model, meta }: {
|
|
6
|
+
export declare function generateModelImportExportDecoder({ model, meta, schemaMeta, }: {
|
|
7
7
|
model: Model;
|
|
8
8
|
meta: ModelMetaData;
|
|
9
|
+
schemaMeta: SchemaMetaData;
|
|
9
10
|
}): string;
|
|
10
11
|
/**
|
|
11
12
|
* Generates the data decoder, aggregating all the models.
|
|
@@ -6,24 +6,22 @@ const imports_1 = require("../../lib/imports");
|
|
|
6
6
|
const meta_1 = require("../../lib/meta");
|
|
7
7
|
const types_1 = require("../../lib/schema/types");
|
|
8
8
|
const types_2 = require("../../lib/types");
|
|
9
|
-
// TODO: Remove hardcoded path that seems to be reused in multiple places!
|
|
10
|
-
const PXL_COMMON = (0, types_1.toPath)('@pxl/common');
|
|
11
9
|
/**
|
|
12
10
|
* Creates a decoder for the Seed Excel template.
|
|
13
11
|
*/
|
|
14
|
-
function generateModelImportExportDecoder({ model, meta }) {
|
|
12
|
+
function generateModelImportExportDecoder({ model, meta, schemaMeta, }) {
|
|
15
13
|
const { filePath: decoderFilePath, itemEncoderFunctionName: rowExportFunctionName, encodedExcelType: excelType, arrayEncoderFunctionName: tableExportFunctionName, tableDecoder: tableImportDecoder, } = meta.importExport.decoder;
|
|
16
14
|
const imports = imports_1.ImportsGenerator.from(decoderFilePath);
|
|
17
15
|
imports.addImports({
|
|
18
|
-
[
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
[schemaMeta.backendModules.common.importPath]: [
|
|
17
|
+
schemaMeta.backendModules.common.functions.uncapitalizeKeys,
|
|
18
|
+
schemaMeta.backendModules.common.functions.capitalizeKeys,
|
|
19
|
+
schemaMeta.backendModules.common.functions.nullOrBlankDecoder,
|
|
22
20
|
],
|
|
23
|
-
[meta.types.importPath]: [meta.types.typeName],
|
|
21
|
+
[meta.types.importPath]: [(0, types_1.toAnnotatedTypeName)(meta.types.typeName)],
|
|
24
22
|
});
|
|
25
23
|
const { userFriendlyName: userFriendly, userFriendlyNamePlural: userFriendlyPlural, internalSingularName: singular, internalSingularNameCapitalized: singularCapitalized, } = meta;
|
|
26
|
-
const { fieldDecoders, blankFieldDecoders } = generateFieldDecoders({ model, meta, imports });
|
|
24
|
+
const { fieldDecoders, blankFieldDecoders } = generateFieldDecoders({ model, meta, schemaMeta, imports });
|
|
27
25
|
return `
|
|
28
26
|
import * as z from 'zod'
|
|
29
27
|
${imports.generate()}
|
|
@@ -71,7 +69,7 @@ export const ${tableExportFunctionName} = (items: ${model.typeName}[]): ${excelT
|
|
|
71
69
|
`;
|
|
72
70
|
}
|
|
73
71
|
exports.generateModelImportExportDecoder = generateModelImportExportDecoder;
|
|
74
|
-
function generateFieldDecoders({ model, meta, imports, }) {
|
|
72
|
+
function generateFieldDecoders({ model, meta, schemaMeta, imports, }) {
|
|
75
73
|
const fieldDecoders = [];
|
|
76
74
|
const blankFieldDecoders = [];
|
|
77
75
|
for (const field of model.fields) {
|
|
@@ -85,6 +83,7 @@ function generateFieldDecoders({ model, meta, imports, }) {
|
|
|
85
83
|
dbTypeName: field.schemaType,
|
|
86
84
|
nullable: false,
|
|
87
85
|
imports,
|
|
86
|
+
schemaMeta,
|
|
88
87
|
})}.transform((id: ${field.unbrandedTypeName}) => ${meta.types.toBrandedIdTypeFnName}(id))`);
|
|
89
88
|
break;
|
|
90
89
|
}
|
|
@@ -94,6 +93,7 @@ function generateFieldDecoders({ model, meta, imports, }) {
|
|
|
94
93
|
dbTypeName: field.schemaType,
|
|
95
94
|
nullable: !field.isRequired,
|
|
96
95
|
imports,
|
|
96
|
+
schemaMeta,
|
|
97
97
|
})}`);
|
|
98
98
|
break;
|
|
99
99
|
}
|
|
@@ -106,6 +106,7 @@ function generateFieldDecoders({ model, meta, imports, }) {
|
|
|
106
106
|
dbTypeName: field.schemaType,
|
|
107
107
|
nullable: !field.isRequired,
|
|
108
108
|
imports,
|
|
109
|
+
schemaMeta,
|
|
109
110
|
})}
|
|
110
111
|
.transform(
|
|
111
112
|
(id: ${field.unbrandedTypeName}${field.isRequired ? '' : '| null'}) =>
|
|
@@ -126,20 +127,20 @@ function generateFieldDecoders({ model, meta, imports, }) {
|
|
|
126
127
|
}
|
|
127
128
|
return { fieldDecoders, blankFieldDecoders };
|
|
128
129
|
}
|
|
129
|
-
function toExcelDecoder({ tsTypeName, dbTypeName: typeName, nullable, imports, }) {
|
|
130
|
+
function toExcelDecoder({ tsTypeName, dbTypeName: typeName, nullable, imports, schemaMeta, }) {
|
|
130
131
|
switch (tsTypeName) {
|
|
131
132
|
case 'string': {
|
|
132
|
-
const decoder =
|
|
133
|
+
const decoder = schemaMeta.backendModules.common.functions[nullable ? 'excelStringNullableDecoder' : 'excelStringDecoder'];
|
|
133
134
|
imports.addImport({
|
|
134
135
|
items: [decoder],
|
|
135
|
-
from:
|
|
136
|
+
from: schemaMeta.backendModules.common.importPath,
|
|
136
137
|
});
|
|
137
138
|
return decoder;
|
|
138
139
|
}
|
|
139
140
|
case 'boolean':
|
|
140
141
|
imports.addImport({
|
|
141
|
-
items: [
|
|
142
|
-
from:
|
|
142
|
+
items: [schemaMeta.backendModules.common.functions.excelBooleanDecoder],
|
|
143
|
+
from: schemaMeta.backendModules.common.importPath,
|
|
143
144
|
});
|
|
144
145
|
return 'excelBooleanDecoder';
|
|
145
146
|
case 'number':
|
|
@@ -151,10 +152,10 @@ function toExcelDecoder({ tsTypeName, dbTypeName: typeName, nullable, imports, }
|
|
|
151
152
|
return `z.number()${nullable ? '.nullable()' : ''}`;
|
|
152
153
|
}
|
|
153
154
|
case 'Date': {
|
|
154
|
-
const decoder =
|
|
155
|
+
const decoder = schemaMeta.backendModules.common.functions[nullable ? 'excelDateNullableDecoder' : 'excelDateDecoder'];
|
|
155
156
|
imports.addImport({
|
|
156
157
|
items: [decoder],
|
|
157
|
-
from:
|
|
158
|
+
from: schemaMeta.backendModules.common.importPath,
|
|
158
159
|
});
|
|
159
160
|
return decoder;
|
|
160
161
|
}
|
|
@@ -169,7 +170,7 @@ function generateImportExportDecoder({ models, meta }) {
|
|
|
169
170
|
const { decodedPXLModelDataTypeName, encodedExcelDataTypeName, fullDecoderName, fullEncoderFunctionName } = meta.importExport.decoder;
|
|
170
171
|
const imports = imports_1.ImportsGenerator.from(meta.importExport.decoder.fullDecoderFilePath);
|
|
171
172
|
imports.addImports({
|
|
172
|
-
[
|
|
173
|
+
[meta.backendModules.common.importPath]: (0, types_1.toFunctionName)('uncapitalizeKeys'),
|
|
173
174
|
});
|
|
174
175
|
const importTypes = [];
|
|
175
176
|
const decoderEntries = [];
|
|
@@ -181,7 +182,7 @@ function generateImportExportDecoder({ models, meta }) {
|
|
|
181
182
|
items: [
|
|
182
183
|
modelMeta.importExport.decoder.tableDecoder,
|
|
183
184
|
modelMeta.importExport.decoder.arrayEncoderFunctionName,
|
|
184
|
-
modelMeta.importExport.decoder.encodedExcelType,
|
|
185
|
+
(0, types_1.toAnnotatedTypeName)(modelMeta.importExport.decoder.encodedExcelType),
|
|
185
186
|
],
|
|
186
187
|
});
|
|
187
188
|
importTypes.push(`${modelMeta.importExport.tableName}?: ${modelMeta.importExport.decoder.encodedExcelType}[]`);
|
|
@@ -8,7 +8,7 @@ const string_1 = require("../../../lib/utils/string");
|
|
|
8
8
|
*/
|
|
9
9
|
function generateModelContext({ model, meta }) {
|
|
10
10
|
const queryName = (0, string_1.toCamelCase)(model.name);
|
|
11
|
-
const imports = imports_1.ImportsGenerator.from(meta.react.folderPath).
|
|
11
|
+
const imports = imports_1.ImportsGenerator.from(meta.react.folderPath).addTypeImport({
|
|
12
12
|
items: [model.typeName, model.brandedIdType],
|
|
13
13
|
from: meta.types.importPath,
|
|
14
14
|
});
|
|
@@ -23,14 +23,8 @@ function generateReactComponentsForModel({ model, meta }) {
|
|
|
23
23
|
vfs.write(`/EditModal.tsx`, (0, modals_generator_1.generateEditModalModelComponent)({ model, meta }));
|
|
24
24
|
vfs.write(`/DeleteModal.tsx`, (0, modals_generator_1.generateDeleteModalModelComponent)({ model, meta }));
|
|
25
25
|
vfs.write(`/Form.tsx`, (0, lookup_generator_1.generateModelLookupComponents)({ model, meta }));
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
// component without checking that a model has a name field.
|
|
29
|
-
const hasNameField = model.nameField != null;
|
|
30
|
-
if (hasNameField) {
|
|
31
|
-
vfs.write(`/Library.tsx`, (0, library_generator_1.generateModelLibraryComponents)({ model, meta }));
|
|
32
|
-
exports.exportEverythingFromFile('./Library');
|
|
33
|
-
}
|
|
26
|
+
vfs.write(`/Library.tsx`, (0, library_generator_1.generateModelLibraryComponents)({ model, meta }));
|
|
27
|
+
exports.exportEverythingFromFile('./Library');
|
|
34
28
|
vfs.write(`/index.ts`, exports.generate());
|
|
35
29
|
return vfs;
|
|
36
30
|
}
|
|
@@ -3,8 +3,6 @@ import { Model } from '../../../lib/schema/schema';
|
|
|
3
3
|
/**
|
|
4
4
|
* Generates components that may be used to list all entries of a given data type.
|
|
5
5
|
*
|
|
6
|
-
* NOTE: Library expects that the model has a `name` field. Make sure that you don't make a dependency on
|
|
7
|
-
* this component without checking that a model has a name field.
|
|
8
6
|
*/
|
|
9
7
|
export declare function generateModelLibraryComponents({ model, meta }: {
|
|
10
8
|
model: Model;
|
|
@@ -6,14 +6,12 @@ const imports_1 = require("../../../lib/imports");
|
|
|
6
6
|
/**
|
|
7
7
|
* Generates components that may be used to list all entries of a given data type.
|
|
8
8
|
*
|
|
9
|
-
* NOTE: Library expects that the model has a `name` field. Make sure that you don't make a dependency on
|
|
10
|
-
* this component without checking that a model has a name field.
|
|
11
9
|
*/
|
|
12
10
|
function generateModelLibraryComponents({ model, meta }) {
|
|
13
11
|
const { react: { context, components }, } = meta;
|
|
14
12
|
const selectorCollector = id_collector_1.SelectorCollector.from(meta.seed.constantName + '-card');
|
|
15
13
|
const imports = imports_1.ImportsGenerator.from(meta.react.folderPath)
|
|
16
|
-
.
|
|
14
|
+
.addTypeImport({
|
|
17
15
|
items: [model.typeName],
|
|
18
16
|
from: meta.types.importPath,
|
|
19
17
|
})
|
|
@@ -21,7 +19,7 @@ function generateModelLibraryComponents({ model, meta }) {
|
|
|
21
19
|
items: [context.hookFnName, components.modals.editComponentName, components.modals.deleteComponentName],
|
|
22
20
|
from: meta.react.folderPath,
|
|
23
21
|
});
|
|
24
|
-
return `
|
|
22
|
+
return /* ts */ `
|
|
25
23
|
import React, { useState } from 'react'
|
|
26
24
|
|
|
27
25
|
import { Card } from '@components/atoms/Card'
|
|
@@ -54,7 +52,7 @@ function generateModelLibraryComponents({ model, meta }) {
|
|
|
54
52
|
<>
|
|
55
53
|
<Card
|
|
56
54
|
ref={forwardedRef}
|
|
57
|
-
title={item.name}
|
|
55
|
+
title={item.${model.nameField.name}}
|
|
58
56
|
actions={[
|
|
59
57
|
{
|
|
60
58
|
label: 'Edit',
|
|
@@ -12,16 +12,13 @@ function generateModelLookupComponents({ model, meta }) {
|
|
|
12
12
|
items: [context.hookFnName],
|
|
13
13
|
from: meta.react.folderPath,
|
|
14
14
|
})
|
|
15
|
-
.
|
|
15
|
+
.addTypeImport({
|
|
16
16
|
items: [model.typeName],
|
|
17
17
|
from: meta.types.importPath,
|
|
18
18
|
});
|
|
19
19
|
const typeName = model.typeName;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const hasNameField = model.nameField != null;
|
|
23
|
-
const tsOmittedFields = hasNameField ? `'label' | 'options' | 'loading'` : `'options' | 'loading'`;
|
|
24
|
-
const reactLabelField = hasNameField ? `label={(l) => l.name}` : '';
|
|
20
|
+
const tsOmittedFields = `'label' | 'options' | 'loading'`;
|
|
21
|
+
const reactLabelField = `label={(l) => l.${model.nameField.name}}`;
|
|
25
22
|
let description = '';
|
|
26
23
|
if (model.description) {
|
|
27
24
|
description = `
|
|
@@ -305,7 +305,7 @@ exports.generateEditModalModelComponent = generateEditModalModelComponent;
|
|
|
305
305
|
*/
|
|
306
306
|
function generateDeleteModalModelComponent({ model, meta }) {
|
|
307
307
|
const { react: { components }, trpc, } = meta;
|
|
308
|
-
const imports = imports_1.ImportsGenerator.from(meta.react.folderPath).
|
|
308
|
+
const imports = imports_1.ImportsGenerator.from(meta.react.folderPath).addTypeImport({
|
|
309
309
|
items: [model.brandedIdType],
|
|
310
310
|
from: meta.types.importPath,
|
|
311
311
|
});
|
|
@@ -373,7 +373,7 @@ exports.generateDeleteModalModelComponent = generateDeleteModalModelComponent;
|
|
|
373
373
|
* Returns the import statements to the models that are used in this modal.
|
|
374
374
|
*/
|
|
375
375
|
function getFormImports({ model, meta }) {
|
|
376
|
-
const imports = imports_1.ImportsGenerator.from(meta.react.folderPath).
|
|
376
|
+
const imports = imports_1.ImportsGenerator.from(meta.react.folderPath).addTypeImport({
|
|
377
377
|
items: [model.brandedIdType, model.typeName],
|
|
378
378
|
from: meta.types.importPath,
|
|
379
379
|
});
|
|
@@ -384,14 +384,14 @@ function getFormImports({ model, meta }) {
|
|
|
384
384
|
items: [refMeta.react.components.forms.searchFieldName],
|
|
385
385
|
from: refMeta.react.folderPath,
|
|
386
386
|
});
|
|
387
|
-
imports.
|
|
387
|
+
imports.addTypeImport({
|
|
388
388
|
items: [refModel.brandedIdType],
|
|
389
389
|
from: refMeta.types.importPath,
|
|
390
390
|
});
|
|
391
391
|
}
|
|
392
392
|
for (const f of (0, fields_1.getEnumFields)(model)) {
|
|
393
393
|
const enumMeta = (0, meta_1.getEnumMetadata)(f);
|
|
394
|
-
imports.
|
|
394
|
+
imports.addTypeImport({
|
|
395
395
|
items: [f.enumerator.tsTypeName],
|
|
396
396
|
from: enumMeta.types.importPath,
|
|
397
397
|
});
|
|
@@ -15,14 +15,14 @@ function generateRepository({ model, meta }) {
|
|
|
15
15
|
const { idField } = model;
|
|
16
16
|
const schemaMeta = (0, meta_1.getSchemaMetadata)({ config: model.schemaConfig });
|
|
17
17
|
const imports = imports_1.ImportsGenerator.from(meta.data.repository.filePath).addImports({
|
|
18
|
-
[schemaMeta.data.repository.typeFilePath]: schemaMeta.data.repository.typeName,
|
|
18
|
+
[schemaMeta.data.repository.typeFilePath]: (0, types_1.toAnnotatedTypeName)(schemaMeta.data.repository.typeName),
|
|
19
19
|
[meta.types.importPath]: [
|
|
20
|
-
model.typeName,
|
|
21
|
-
model.brandedIdType,
|
|
20
|
+
(0, types_1.toAnnotatedTypeName)(model.typeName),
|
|
21
|
+
(0, types_1.toAnnotatedTypeName)(model.brandedIdType),
|
|
22
22
|
meta.types.toBrandedIdTypeFnName,
|
|
23
|
-
meta.types.dto.create,
|
|
24
|
-
meta.types.dto.update,
|
|
25
|
-
meta.types.dto.upsert,
|
|
23
|
+
(0, types_1.toAnnotatedTypeName)(meta.types.dto.create),
|
|
24
|
+
(0, types_1.toAnnotatedTypeName)(meta.types.dto.update),
|
|
25
|
+
(0, types_1.toAnnotatedTypeName)(meta.types.dto.upsert),
|
|
26
26
|
],
|
|
27
27
|
[schemaMeta.actions.importPath]: [schemaMeta.actions.actionExecution.interface],
|
|
28
28
|
});
|
|
@@ -48,7 +48,7 @@ function generateRepository({ model, meta }) {
|
|
|
48
48
|
const uniqueStringFieldsBlocks = generateUniqueFieldsBlocks({ model, meta });
|
|
49
49
|
const maxLengthBlocks = generateMaxLengthBlocks({ model, meta });
|
|
50
50
|
const validationBlocks = generateValidationBlocks({ model, meta });
|
|
51
|
-
const indexBlocks = generateIndexBlocks({ model, meta, imports });
|
|
51
|
+
const indexBlocks = generateIndexBlocks({ model, schemaMeta, meta, imports });
|
|
52
52
|
const relationsBlocks = generateRelationsBlocks({ model, meta, imports });
|
|
53
53
|
let mainBlocks;
|
|
54
54
|
if (model.attributes.inMemoryOnly) {
|
|
@@ -217,10 +217,13 @@ exports.generateMockRepository = generateMockRepository;
|
|
|
217
217
|
/**
|
|
218
218
|
* Generates the main building blocks of the repository for in-memory model.
|
|
219
219
|
*/
|
|
220
|
-
function _generateMainBuildingBlocks_InMemoryOnly({ model, meta, imports, blocks, }) {
|
|
220
|
+
function _generateMainBuildingBlocks_InMemoryOnly({ model, meta, schemaMeta, imports, blocks, }) {
|
|
221
221
|
const methodTypeSignatures = getRepositoryMethodsTypeSignatures({ model, meta });
|
|
222
222
|
const userRepositorySpecificBlocks = generateUserRepositorySpecificBlocks_InMemoryOnly({ model, meta, imports });
|
|
223
|
-
imports.addImport({
|
|
223
|
+
imports.addImport({
|
|
224
|
+
from: schemaMeta.backendModules.common.importPath,
|
|
225
|
+
items: ['removeUndefinedProperties'].map(types_1.toFunctionName),
|
|
226
|
+
});
|
|
224
227
|
return {
|
|
225
228
|
constructorCode: '',
|
|
226
229
|
userRepositorySpecificBlocks,
|
|
@@ -452,13 +455,19 @@ function _generateMainBuildingBlocks_InMemoryOnly({ model, meta, imports, blocks
|
|
|
452
455
|
/**
|
|
453
456
|
* Generates the methods of the repository for a model that is stored in the database.
|
|
454
457
|
*/
|
|
455
|
-
function generateMainBuildingBlocks_InDatabase({ model, meta, imports, blocks, }) {
|
|
458
|
+
function generateMainBuildingBlocks_InDatabase({ model, meta, schemaMeta, imports, blocks, }) {
|
|
456
459
|
const decoderFunctionName = meta.data.repository.decoderFnName;
|
|
457
460
|
const { idField } = model;
|
|
458
461
|
imports.addImports({
|
|
459
462
|
[meta.types.importPath]: [meta.types.zodDecoderFnNames.fromDatabase],
|
|
460
|
-
[
|
|
461
|
-
|
|
463
|
+
[schemaMeta.backendModules.db.importPath]: [
|
|
464
|
+
schemaMeta.backendModules.db.dbService.name,
|
|
465
|
+
(0, types_1.toAnnotatedTypeName)((0, types_1.toTypeName)(`${model.sourceName} as DbType`)),
|
|
466
|
+
],
|
|
467
|
+
[schemaMeta.backendModules.common.importPath]: [
|
|
468
|
+
schemaMeta.backendModules.common.functions.format,
|
|
469
|
+
schemaMeta.backendModules.common.functions.pluralize,
|
|
470
|
+
],
|
|
462
471
|
});
|
|
463
472
|
const dbTableName = [model.sourceSchemaName, model.sourceName]
|
|
464
473
|
.filter((s) => s != null)
|
|
@@ -777,7 +786,7 @@ function generateUserRepositorySpecificBlocks_InDatabase({ model, meta, imports,
|
|
|
777
786
|
}
|
|
778
787
|
imports.addImport({
|
|
779
788
|
from: meta.types.importPath,
|
|
780
|
-
items: [(0, types_1.
|
|
789
|
+
items: [(0, types_1.toVariableName)('UserRole')],
|
|
781
790
|
});
|
|
782
791
|
return {
|
|
783
792
|
rootUserNameConst: `public static ROOT_USER_ID = ${meta.types.toBrandedIdTypeFnName}('root')`,
|
|
@@ -825,7 +834,7 @@ function generateUserRepositorySpecificBlocks_InMemoryOnly({ model, meta, import
|
|
|
825
834
|
}
|
|
826
835
|
imports.addImport({
|
|
827
836
|
from: meta.types.importPath,
|
|
828
|
-
items: [(0, types_1.
|
|
837
|
+
items: [(0, types_1.toVariableName)('UserRole')],
|
|
829
838
|
});
|
|
830
839
|
return {
|
|
831
840
|
rootUserNameConst: `public static ROOT_USER_ID = ${meta.types.toBrandedIdTypeFnName}('root')`,
|
|
@@ -1164,10 +1173,10 @@ function generateValidationBlocks({ model }) {
|
|
|
1164
1173
|
}
|
|
1165
1174
|
return result;
|
|
1166
1175
|
}
|
|
1167
|
-
function generateIndexBlocks({ model, imports, }) {
|
|
1176
|
+
function generateIndexBlocks({ model, imports, schemaMeta, }) {
|
|
1168
1177
|
const indexes = model.attributes.index ? [getIndexDefinition({ fieldNames: model.attributes.index, model })] : [];
|
|
1169
1178
|
if (indexes.length > 0) {
|
|
1170
|
-
imports.
|
|
1179
|
+
imports.addTypeImport({ items: [(0, types_1.toTypeName)('NestedMap')], from: schemaMeta.backendModules.common.importPath });
|
|
1171
1180
|
}
|
|
1172
1181
|
const result = {
|
|
1173
1182
|
nestedMapDeclarations: [],
|
|
@@ -1228,7 +1237,7 @@ function generateRelationsBlocks({ model, imports, }) {
|
|
|
1228
1237
|
for (const r of relations) {
|
|
1229
1238
|
const fieldMeta = (0, meta_1.getFieldMetadata)({ field: r });
|
|
1230
1239
|
const relationModelMeta = (0, meta_1.getModelMetadata)({ model: r.relationToModel });
|
|
1231
|
-
imports.
|
|
1240
|
+
imports.addTypeImport({
|
|
1232
1241
|
items: [relationModelMeta.types.brandedIdType],
|
|
1233
1242
|
from: relationModelMeta.types.importPath,
|
|
1234
1243
|
});
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateRoutesIndex = exports.generateRoute = void 0;
|
|
4
4
|
const imports_1 = require("../../lib/imports");
|
|
5
5
|
const meta_1 = require("../../lib/meta");
|
|
6
|
+
const types_1 = require("../../lib/schema/types");
|
|
6
7
|
/**
|
|
7
8
|
* Generates TRPC route for a given model.
|
|
8
9
|
*/
|
|
@@ -13,7 +14,7 @@ function generateRoute({ model, meta }) {
|
|
|
13
14
|
`;
|
|
14
15
|
const imports = imports_1.ImportsGenerator.from(meta.trpc.routerFilePath).addImports({
|
|
15
16
|
[meta.types.importPath]: [
|
|
16
|
-
model.typeName,
|
|
17
|
+
(0, types_1.toAnnotatedTypeName)(model.typeName),
|
|
17
18
|
meta.types.toBrandedIdTypeFnName,
|
|
18
19
|
meta.types.zodDecoderFnNames.createObject,
|
|
19
20
|
meta.types.zodDecoderFnNames.updateObject,
|
|
@@ -35,7 +36,7 @@ function generateRoute({ model, meta }) {
|
|
|
35
36
|
import { z } from 'zod'
|
|
36
37
|
import { procedure, router } from '../trpc'
|
|
37
38
|
|
|
38
|
-
import { CURSOR_DECODER, FILTER_OPERATOR_DECODER } from '@
|
|
39
|
+
import { CURSOR_DECODER, FILTER_OPERATOR_DECODER } from '@backend/common'
|
|
39
40
|
${imports.generate()}
|
|
40
41
|
|
|
41
42
|
export const ${meta.trpc.routerName} = router({
|
|
@@ -5,8 +5,9 @@ const faker_1 = require("@faker-js/faker");
|
|
|
5
5
|
const imports_1 = require("../../lib/imports");
|
|
6
6
|
const meta_1 = require("../../lib/meta");
|
|
7
7
|
const fields_1 = require("../../lib/schema/fields");
|
|
8
|
+
const types_1 = require("../../lib/schema/types");
|
|
8
9
|
const serializer_1 = require("../../lib/serializer");
|
|
9
|
-
const
|
|
10
|
+
const types_2 = require("../../lib/types");
|
|
10
11
|
const string_1 = require("../../lib/utils/string");
|
|
11
12
|
/**
|
|
12
13
|
* Creates a seed file for a given model.
|
|
@@ -17,7 +18,7 @@ function generateSeedModel({ model, itemCount, meta, }) {
|
|
|
17
18
|
// This way changes to another model or to the ordering of models in the schema doesn't impact the generated values.
|
|
18
19
|
faker_1.faker.seed((_a = model.attributes.randomSeed) !== null && _a !== void 0 ? _a : 0);
|
|
19
20
|
const imports = imports_1.ImportsGenerator.from(meta.seed.filePath).addImport({
|
|
20
|
-
items: [model.typeName, meta.types.toBrandedIdTypeFnName],
|
|
21
|
+
items: [(0, types_1.toAnnotatedTypeName)(model.typeName), meta.types.toBrandedIdTypeFnName],
|
|
21
22
|
from: meta.types.importPath,
|
|
22
23
|
});
|
|
23
24
|
for (const relation of (0, fields_1.getRelationFields)(model)) {
|
|
@@ -92,7 +93,7 @@ function generateFieldData({ field, model, index, mode, }) {
|
|
|
92
93
|
case 'enum':
|
|
93
94
|
return generateEnumFieldExample({ field, mode, index });
|
|
94
95
|
default:
|
|
95
|
-
throw new
|
|
96
|
+
throw new types_2.ExhaustiveSwitchCheck(field);
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
function generateIdFieldExample({ field, model, index, mode, }) {
|
|
@@ -186,7 +187,7 @@ function generateFieldExample({ field, index, mode, }) {
|
|
|
186
187
|
return { hasExample: true, example };
|
|
187
188
|
}
|
|
188
189
|
default: {
|
|
189
|
-
throw new
|
|
190
|
+
throw new types_2.ExhaustiveSwitchCheck(mode);
|
|
190
191
|
}
|
|
191
192
|
}
|
|
192
193
|
}
|
|
@@ -10,8 +10,13 @@ const types_1 = require("../../lib/types");
|
|
|
10
10
|
*/
|
|
11
11
|
function generateStub({ model, meta }) {
|
|
12
12
|
const { fields, idField } = model;
|
|
13
|
-
const imports = imports_1.ImportsGenerator.from(meta.data.stubFilePath)
|
|
14
|
-
|
|
13
|
+
const imports = imports_1.ImportsGenerator.from(meta.data.stubFilePath)
|
|
14
|
+
.addImport({
|
|
15
|
+
items: [meta.types.toBrandedIdTypeFnName],
|
|
16
|
+
from: meta.types.importPath,
|
|
17
|
+
})
|
|
18
|
+
.addTypeImport({
|
|
19
|
+
items: [model.typeName],
|
|
15
20
|
from: meta.types.importPath,
|
|
16
21
|
});
|
|
17
22
|
const assignments = getAssignmentStatementModel({
|
|
@@ -22,20 +22,24 @@ function generateModelTypes({ model, meta }) {
|
|
|
22
22
|
const refModel = relation.relationToModel;
|
|
23
23
|
const refMeta = (0, meta_1.getModelMetadata)({ model: refModel });
|
|
24
24
|
imports.addImport({
|
|
25
|
-
items: [refMeta.types.toBrandedIdTypeFnName
|
|
25
|
+
items: [refMeta.types.toBrandedIdTypeFnName],
|
|
26
|
+
from: refMeta.types.filePath,
|
|
27
|
+
});
|
|
28
|
+
imports.addTypeImport({
|
|
29
|
+
items: [refModel.brandedIdType, refMeta.types.typeName],
|
|
26
30
|
from: refMeta.types.filePath,
|
|
27
31
|
});
|
|
28
32
|
hasLinkedItems = true;
|
|
29
33
|
}
|
|
30
34
|
for (const f of (0, fields_1.getEnumFields)(model)) {
|
|
31
35
|
const refEnumMeta = (0, meta_1.getEnumMetadata)({ enumerator: f.enumerator });
|
|
32
|
-
imports.
|
|
36
|
+
imports.addTypeImport({
|
|
33
37
|
items: [f.enumerator.tsTypeName],
|
|
34
38
|
from: refEnumMeta.types.filePath,
|
|
35
39
|
});
|
|
36
40
|
}
|
|
37
41
|
const schemaMeta = (0, meta_1.getSchemaMetadata)({ config: model.schemaConfig });
|
|
38
|
-
imports.
|
|
42
|
+
imports.addTypeImport({
|
|
39
43
|
items: [schemaMeta.types.dto.create, schemaMeta.types.dto.update, schemaMeta.types.dto.upsert],
|
|
40
44
|
from: schemaMeta.types.dto.path,
|
|
41
45
|
});
|
package/dist/lib/exports.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare class ExportsGenerator {
|
|
|
19
19
|
/**
|
|
20
20
|
* Creates a new instance of the exports generator.
|
|
21
21
|
*/
|
|
22
|
-
static from(path: Types.
|
|
22
|
+
static from(path: Types.FilePath): ExportsGenerator;
|
|
23
23
|
/**
|
|
24
24
|
* Creates a new instance of the exports generator from this folder (i.e. every path is relative to this folder).
|
|
25
25
|
*/
|
|
@@ -27,7 +27,7 @@ export declare class ExportsGenerator {
|
|
|
27
27
|
/**
|
|
28
28
|
* Adds a given file to the collection of files we're exporting everything from.
|
|
29
29
|
*/
|
|
30
|
-
exportEverythingFromPath(from: Types.
|
|
30
|
+
exportEverythingFromPath(from: Types.FilePath): ExportsGenerator;
|
|
31
31
|
/**
|
|
32
32
|
* Adds a given file to the collection of files we're exporting everything from.
|
|
33
33
|
*
|