@postxl/generator 0.67.0 → 0.69.0
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 +0 -10
- package/dist/generators/indices/dataservice.generator.js +1 -1
- package/dist/generators/indices/dispatcher-service.generator.js +1 -1
- package/dist/generators/indices/importexport-convert-import-functions.generator.js +1 -23
- package/dist/generators/indices/importexport-exporter-class.generator.js +1 -1
- package/dist/generators/indices/importexport-import-service.generator.js +1 -1
- package/dist/generators/models/businesslogic-update.generator.js +12 -25
- package/dist/generators/models/businesslogic-view.generator.js +30 -2
- package/dist/generators/models/importexport-decoder.generator.js +10 -15
- package/dist/generators/models/react.generator/context.generator.js +1 -1
- package/dist/generators/models/repository.generator.d.ts +0 -7
- package/dist/generators/models/repository.generator.js +274 -656
- package/dist/generators/models/route.generator.js +11 -8
- package/dist/lib/attributes.d.ts +0 -5
- package/dist/lib/meta.d.ts +21 -69
- package/dist/lib/meta.js +6 -27
- package/dist/lib/schema/types.d.ts +8 -1
- package/dist/lib/schema/types.js +3 -1
- package/dist/prisma/attributes.js +0 -2
- package/package.json +1 -1
- package/dist/generators/indices/datamock-module.generator.d.ts +0 -9
- package/dist/generators/indices/datamock-module.generator.js +0 -64
- package/dist/generators/indices/datamocker.generator.d.ts +0 -9
- package/dist/generators/indices/datamocker.generator.js +0 -88
- package/dist/generators/indices/emptydatabasemigration.generator.d.ts +0 -11
- package/dist/generators/indices/emptydatabasemigration.generator.js +0 -34
- package/dist/generators/indices/testdata-service.generator.d.ts +0 -9
- package/dist/generators/indices/testdata-service.generator.js +0 -84
|
@@ -12,20 +12,23 @@ function generateRoute({ model, meta }) {
|
|
|
12
12
|
const defaultValueMethod = `
|
|
13
13
|
getDefault: procedure.query(({ ctx }) => ctx.view.${meta.data.dataServiceName}.${dataRepositoryVariableName}.defaultValue),
|
|
14
14
|
`;
|
|
15
|
-
const decoders = meta.update.decoders;
|
|
16
15
|
const imports = imports_1.ImportsGenerator.from(meta.trpc.routerFilePath).addImports({
|
|
17
16
|
[meta.types.importPath]: [
|
|
18
17
|
(0, types_1.toAnnotatedTypeName)(model.typeName),
|
|
19
18
|
meta.types.toBrandedIdTypeFnName,
|
|
20
19
|
meta.types.zodDecoderFnNames.id,
|
|
21
20
|
],
|
|
22
|
-
[meta.update.serviceClassLocation.import]: [
|
|
21
|
+
[meta.update.serviceClassLocation.import]: [
|
|
22
|
+
meta.update.createInputDecoder,
|
|
23
|
+
meta.update.updateInputDecoder,
|
|
24
|
+
meta.update.upsertInputDecoder,
|
|
25
|
+
],
|
|
26
|
+
[meta.view.serviceLocation.import]: [meta.view.filterOperatorDecoder, meta.view.cursorDecoder],
|
|
23
27
|
});
|
|
24
28
|
return /* ts */ `
|
|
25
29
|
import { z } from 'zod'
|
|
26
30
|
import { procedure, router } from '../trpc'
|
|
27
31
|
|
|
28
|
-
import { CURSOR_DECODER, FILTER_OPERATOR_DECODER } from '@backend/common'
|
|
29
32
|
${imports.generate()}
|
|
30
33
|
|
|
31
34
|
export const ${meta.trpc.routerName} = router({
|
|
@@ -37,7 +40,7 @@ export const ${meta.trpc.routerName} = router({
|
|
|
37
40
|
getMap: procedure.query(({ ctx }) => ctx.view.${meta.data.dataServiceName}.getAll()),
|
|
38
41
|
getList: procedure
|
|
39
42
|
.input(z.object({
|
|
40
|
-
cursor:
|
|
43
|
+
cursor: ${meta.view.cursorDecoder}.optional(),
|
|
41
44
|
sort: z.object({
|
|
42
45
|
field: z.enum([
|
|
43
46
|
${model.fields.map((f) => `'${f.name}'`).join(',\n')}
|
|
@@ -51,7 +54,7 @@ export const ${meta.trpc.routerName} = router({
|
|
|
51
54
|
${model.fields.map((f) => `'${f.name}'`).join(',\n')}
|
|
52
55
|
])
|
|
53
56
|
.transform((v): keyof ${model.typeName} => v),
|
|
54
|
-
operator:
|
|
57
|
+
operator: ${meta.view.filterOperatorDecoder},
|
|
55
58
|
value: z.union([z.string(), z.number()]),
|
|
56
59
|
})
|
|
57
60
|
.optional(),
|
|
@@ -61,15 +64,15 @@ export const ${meta.trpc.routerName} = router({
|
|
|
61
64
|
}),
|
|
62
65
|
|
|
63
66
|
create: procedure
|
|
64
|
-
.input(${
|
|
67
|
+
.input(${meta.update.createInputDecoder})
|
|
65
68
|
.mutation(({ input, ctx }) => ctx.dispatch({scope: "${scopeName}", type: "create", payload: input})),
|
|
66
69
|
|
|
67
70
|
update: procedure
|
|
68
|
-
.input(${
|
|
71
|
+
.input(${meta.update.updateInputDecoder})
|
|
69
72
|
.mutation(({ input, ctx }) => ctx.dispatch({scope: "${scopeName}", type: "update", payload: input})),
|
|
70
73
|
|
|
71
74
|
upsert: procedure
|
|
72
|
-
.input(${
|
|
75
|
+
.input(${meta.update.upsertInputDecoder})
|
|
73
76
|
.mutation(({ input, ctx }) => ctx.dispatch({scope: "${scopeName}", type: "upsert", payload: input})),
|
|
74
77
|
|
|
75
78
|
delete: procedure
|
package/dist/lib/attributes.d.ts
CHANGED
|
@@ -16,11 +16,6 @@ export type ModelAttributes = {
|
|
|
16
16
|
* Note: Prisma has it's own schema attribute - but does not expose it in the DMMF.
|
|
17
17
|
*/
|
|
18
18
|
databaseSchema: string;
|
|
19
|
-
/**
|
|
20
|
-
* Schema tag: ´@@InMemoryOnly()`
|
|
21
|
-
* Whether the model should be stored in the database or only in memory.
|
|
22
|
-
*/
|
|
23
|
-
inMemoryOnly: boolean;
|
|
24
19
|
/**
|
|
25
20
|
* Schema tag: ´@@Index()`
|
|
26
21
|
* Creates an index on the given fields.
|
package/dist/lib/meta.d.ts
CHANGED
|
@@ -17,11 +17,7 @@ export type SchemaMetaData = {
|
|
|
17
17
|
* Names of the functions that are provided by the common backend module.
|
|
18
18
|
*/
|
|
19
19
|
functions: {
|
|
20
|
-
|
|
21
|
-
pluralize: Types.FunctionName;
|
|
22
|
-
uncapitalizeKeys: Types.FunctionName;
|
|
23
|
-
capitalizeKeys: Types.FunctionName;
|
|
24
|
-
nullOrBlankDecoder: Types.FunctionName;
|
|
20
|
+
excelNullOrBlankDecoder: Types.FunctionName;
|
|
25
21
|
excelStringNullableDecoder: Types.FunctionName;
|
|
26
22
|
excelStringDecoder: Types.FunctionName;
|
|
27
23
|
excelNumberNullableDecoder: Types.FunctionName;
|
|
@@ -186,10 +182,6 @@ export type SchemaMetaData = {
|
|
|
186
182
|
* Location of the module class
|
|
187
183
|
*/
|
|
188
184
|
moduleLocation: Types.ModuleLocation;
|
|
189
|
-
/**
|
|
190
|
-
* Path to the file containing the data module class definition.
|
|
191
|
-
*/
|
|
192
|
-
emptyDbCommandFilePath: Types.FilePath;
|
|
193
185
|
repository: {
|
|
194
186
|
/**
|
|
195
187
|
* Path to the file containing the repository type definition.
|
|
@@ -222,20 +214,6 @@ export type SchemaMetaData = {
|
|
|
222
214
|
*/
|
|
223
215
|
bulkMutationForModel: Types.TypeName;
|
|
224
216
|
};
|
|
225
|
-
mockModule: {
|
|
226
|
-
/**
|
|
227
|
-
* Path to the file containing the mock data for the database.
|
|
228
|
-
*/
|
|
229
|
-
location: Types.ModuleLocation;
|
|
230
|
-
/**
|
|
231
|
-
* Name of the mock data module class.
|
|
232
|
-
*/
|
|
233
|
-
name: Types.ClassName;
|
|
234
|
-
};
|
|
235
|
-
/**
|
|
236
|
-
* Name of the data mock type/interface.
|
|
237
|
-
*/
|
|
238
|
-
dataMockDataType: Types.TypeName;
|
|
239
217
|
dataService: {
|
|
240
218
|
/**
|
|
241
219
|
* Path to the file containing data service class definitions.
|
|
@@ -354,10 +332,6 @@ export type SchemaMetaData = {
|
|
|
354
332
|
* Name of the function that converts a delta to BulkMutations.
|
|
355
333
|
*/
|
|
356
334
|
deltaToBulkMutations: Types.FunctionName;
|
|
357
|
-
/**
|
|
358
|
-
* Name of the function that converts mock data to BulkMutations.
|
|
359
|
-
*/
|
|
360
|
-
mockDataToBulkMutations: Types.FunctionName;
|
|
361
335
|
};
|
|
362
336
|
/**
|
|
363
337
|
* Meta data for the import export types file.
|
|
@@ -634,10 +608,6 @@ export type SchemaMetaData = {
|
|
|
634
608
|
* Meta data for the e2e generators.
|
|
635
609
|
*/
|
|
636
610
|
e2e: {
|
|
637
|
-
/**
|
|
638
|
-
* Path to the file containing data mocker class definitions.
|
|
639
|
-
*/
|
|
640
|
-
dataMockerLocation: Types.ModuleLocation;
|
|
641
611
|
/**
|
|
642
612
|
* Path to the file containing component test ids for e2e tests.
|
|
643
613
|
*/
|
|
@@ -769,26 +739,6 @@ export type ModelMetaData = {
|
|
|
769
739
|
*/
|
|
770
740
|
getMethodFnName: Types.FunctionName;
|
|
771
741
|
};
|
|
772
|
-
mockRepository: {
|
|
773
|
-
/**
|
|
774
|
-
* Path to the file containing the mock repository definition.
|
|
775
|
-
*/
|
|
776
|
-
location: Types.ModuleLocation;
|
|
777
|
-
/**
|
|
778
|
-
* The name of the class for the in-memory mock repository definition of this model (e.g. MockAggregationRepository).
|
|
779
|
-
*/
|
|
780
|
-
className: Types.ClassName;
|
|
781
|
-
};
|
|
782
|
-
};
|
|
783
|
-
e2e: {
|
|
784
|
-
/**
|
|
785
|
-
* The path to the file containing stub definitions of this model.
|
|
786
|
-
*/
|
|
787
|
-
stubLocation: Types.ModuleLocation;
|
|
788
|
-
/**
|
|
789
|
-
* The name of the function that adds missing values to the partially populated model value.
|
|
790
|
-
*/
|
|
791
|
-
stubGenerationFnName: Types.FunctionName;
|
|
792
742
|
};
|
|
793
743
|
/**
|
|
794
744
|
* Properties provided by the `importExport` generators
|
|
@@ -878,6 +828,14 @@ export type ModelMetaData = {
|
|
|
878
828
|
* The name of the variable that holds the repository instance for the current model
|
|
879
829
|
*/
|
|
880
830
|
dataRepositoryVariableName: Types.VariableName;
|
|
831
|
+
/**
|
|
832
|
+
* The name of the variable that defines the filter operator decoder for the current model.
|
|
833
|
+
*/
|
|
834
|
+
filterOperatorDecoder: Types.VariableName;
|
|
835
|
+
/**
|
|
836
|
+
* The name of the variable that defines the cursor decoder for the current model.
|
|
837
|
+
*/
|
|
838
|
+
cursorDecoder: Types.VariableName;
|
|
881
839
|
};
|
|
882
840
|
/**
|
|
883
841
|
* The definitions for the update service of a model
|
|
@@ -913,24 +871,18 @@ export type ModelMetaData = {
|
|
|
913
871
|
* The name of the model used as a discriminant for the action execution. (e.g. `aggregation`)
|
|
914
872
|
*/
|
|
915
873
|
actionModelDiscriminantName: Types.VariableName;
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
update: Types.FunctionName;
|
|
929
|
-
/**
|
|
930
|
-
* The name of the function that decodes an Upsert object to a fully typed object (e.g. `aggregationUpsertDecoder`.)
|
|
931
|
-
*/
|
|
932
|
-
upsert: Types.FunctionName;
|
|
933
|
-
};
|
|
874
|
+
/**
|
|
875
|
+
* The name of the function that decodes a Create object to a fully typed object (e.g. `aggregationCreateDecoder`.)
|
|
876
|
+
*/
|
|
877
|
+
createInputDecoder: Types.VariableName;
|
|
878
|
+
/**
|
|
879
|
+
* The name of the function that decodes an Update object to a fully typed object (e.g. `aggregationUpdateDecoder`.)
|
|
880
|
+
*/
|
|
881
|
+
updateInputDecoder: Types.VariableName;
|
|
882
|
+
/**
|
|
883
|
+
* The name of the function that decodes an Upsert object to a fully typed object (e.g. `aggregationUpsertDecoder`.)
|
|
884
|
+
*/
|
|
885
|
+
upsertInputDecoder: Types.VariableName;
|
|
934
886
|
/**
|
|
935
887
|
* Name by which the business logic service exposes the data service.
|
|
936
888
|
*/
|
package/dist/lib/meta.js
CHANGED
|
@@ -35,11 +35,7 @@ function getSchemaMetadata({ config }) {
|
|
|
35
35
|
common: {
|
|
36
36
|
importPath: Types.toBackendModulePath(`@backend/common`),
|
|
37
37
|
functions: {
|
|
38
|
-
|
|
39
|
-
pluralize: Types.toFunctionName(`pluralize`),
|
|
40
|
-
uncapitalizeKeys: Types.toFunctionName(`uncapitalizeKeys`),
|
|
41
|
-
capitalizeKeys: Types.toFunctionName(`capitalizeKeys`),
|
|
42
|
-
nullOrBlankDecoder: Types.toFunctionName(`nullOrBlankDecoder`),
|
|
38
|
+
excelNullOrBlankDecoder: Types.toFunctionName(`excelNullOrBlankDecoder`),
|
|
43
39
|
excelStringNullableDecoder: Types.toFunctionName(`excelStringNullableDecoder`),
|
|
44
40
|
excelStringDecoder: Types.toFunctionName(`excelStringDecoder`),
|
|
45
41
|
excelNumberNullableDecoder: Types.toFunctionName(`excelNumberNullableDecoder`),
|
|
@@ -122,7 +118,6 @@ function getSchemaMetadata({ config }) {
|
|
|
122
118
|
data: {
|
|
123
119
|
moduleName: Types.toClassName(`DataModule`),
|
|
124
120
|
moduleLocation: Types.toModuleLocation(`data`, `${config.paths.dataLibPath}data.module`),
|
|
125
|
-
emptyDbCommandFilePath: Types.toPath(`${config.paths.dbLibPath}wipe-database.sql`),
|
|
126
121
|
repository: {
|
|
127
122
|
typeFilePath: Types.toPath(`${config.paths.dataLibPath}repository.type`),
|
|
128
123
|
typeName: Types.toTypeName(`Repository`),
|
|
@@ -142,14 +137,8 @@ function getSchemaMetadata({ config }) {
|
|
|
142
137
|
},
|
|
143
138
|
stubIndexFilePath: Types.toPath(`${config.paths.dataLibPath}stubs/index`),
|
|
144
139
|
testDataServiceFilePath: Types.toPath(`${config.paths.e2eLibPath}test-data.service`),
|
|
145
|
-
mockModule: {
|
|
146
|
-
location: Types.toModuleLocation(`data`, `${config.paths.dataLibPath}data.mock.module`),
|
|
147
|
-
name: Types.toClassName(`DataMockModule`),
|
|
148
|
-
},
|
|
149
|
-
dataMockDataType: Types.toTypeName(`MockData`),
|
|
150
140
|
},
|
|
151
141
|
e2e: {
|
|
152
|
-
dataMockerLocation: Types.toModuleLocation(`e2e`, `${config.paths.playwrightPath}support/data-mocker.class`),
|
|
153
142
|
testIdsFilePath: Types.toPath(`${config.paths.playwrightPath}support/model-test-ids`),
|
|
154
143
|
},
|
|
155
144
|
importExport: {
|
|
@@ -178,7 +167,6 @@ function getSchemaMetadata({ config }) {
|
|
|
178
167
|
location: Types.toModuleLocation(`import-export`, `${config.paths.importExportPath}convert-import.functions`),
|
|
179
168
|
importedDataToBulkMutations: Types.toFunctionName(`importToBulkMutations`),
|
|
180
169
|
deltaToBulkMutations: Types.toFunctionName(`deltaToBulkMutations`),
|
|
181
|
-
mockDataToBulkMutations: Types.toFunctionName(`mockDataToBulkMutations`),
|
|
182
170
|
},
|
|
183
171
|
types: {
|
|
184
172
|
location: Types.toModuleLocation(`import-export`, `${config.paths.importExportPath}types`),
|
|
@@ -288,20 +276,12 @@ function getModelMetadata({ model }) {
|
|
|
288
276
|
decoderFnName: Types.toFunctionName(`to${PascalCase}`),
|
|
289
277
|
getMethodFnName: Types.toFunctionName(`${camelCase}`),
|
|
290
278
|
},
|
|
291
|
-
mockRepository: {
|
|
292
|
-
location: Types.toModuleLocation(`data`, `${config.paths.dataLibPath}repositories/mock/${camelCase}.mock.repository`),
|
|
293
|
-
className: Types.toClassName(`Mock${PascalCase}Repository`),
|
|
294
|
-
},
|
|
295
279
|
stubLocation: Types.toModuleLocation(`data`, `${config.paths.dataLibPath}stubs/${camelCase}.stub`),
|
|
296
280
|
stubGenerationFnName: Types.toFunctionName(`stub${PascalCase}`),
|
|
297
281
|
defaultStubConstantName: Types.toVariableName(`${camelCase}DefaultStub`),
|
|
298
282
|
dataServiceName: Types.toVariableName(`${uncapitalizedPlural}`),
|
|
299
283
|
dataServiceIdName: Types.toVariableName(`${uncapitalized}`),
|
|
300
284
|
},
|
|
301
|
-
e2e: {
|
|
302
|
-
stubGenerationFnName: Types.toFunctionName(`stub${PascalCase}`),
|
|
303
|
-
stubLocation: Types.toModuleLocation(`e2e`, `${config.paths.playwrightPath}support/stubs/${camelCase}.stub`),
|
|
304
|
-
},
|
|
305
285
|
importExport: {
|
|
306
286
|
exportDataPropertyName: Types.toVariableName(`${capitalizedPlural}`),
|
|
307
287
|
exportDataFullPropertyName: Types.toVariableName(`${uncapitalizedPlural}`),
|
|
@@ -325,6 +305,8 @@ function getModelMetadata({ model }) {
|
|
|
325
305
|
serviceVariableName: Types.toVariableName(`${uncapitalizedPlural}`),
|
|
326
306
|
serviceLocation: Types.toModuleLocation(`view`, `${config.paths.businessViewLogicPath}${camelCase}.view.service`),
|
|
327
307
|
dataRepositoryVariableName: Types.toVariableName(`data`),
|
|
308
|
+
cursorDecoder: Types.toVariableName(`CURSOR_DECODER`),
|
|
309
|
+
filterOperatorDecoder: Types.toVariableName(`FILTER_OPERATOR_DECODER`),
|
|
328
310
|
},
|
|
329
311
|
update: {
|
|
330
312
|
scopeName: Types.toVariableName(`${camelCase}`),
|
|
@@ -334,12 +316,9 @@ function getModelMetadata({ model }) {
|
|
|
334
316
|
serviceInterfaceName: Types.toTypeName(`I${PascalCase}UpdateService`),
|
|
335
317
|
serviceVariableName: Types.toVariableName(`${uncapitalizedPlural}`),
|
|
336
318
|
actionModelDiscriminantName: Types.toVariableName(`${camelCase}`),
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
update: Types.toFunctionName(`${camelCase}UpdateDecoder`),
|
|
341
|
-
upsert: Types.toFunctionName(`${camelCase}UpsertDecoder`),
|
|
342
|
-
},
|
|
319
|
+
createInputDecoder: Types.toVariableName(`${camelCase}CreateInputDecoder`),
|
|
320
|
+
updateInputDecoder: Types.toVariableName(`${camelCase}UpdateInputDecoder`),
|
|
321
|
+
upsertInputDecoder: Types.toVariableName(`${camelCase}UpsertInputDecoder`),
|
|
343
322
|
dataRepositoryVariableName: Types.toVariableName(`data`),
|
|
344
323
|
},
|
|
345
324
|
seed: {
|
|
@@ -174,6 +174,13 @@ export type BackendModulePath = `@backend/${string}` & {
|
|
|
174
174
|
* Converts a string to a branded PAth.
|
|
175
175
|
*/
|
|
176
176
|
export declare const toPath: (t: string) => FilePath;
|
|
177
|
+
/**
|
|
178
|
+
* The name of an NPM package (e.g. "@postxl/runtime").
|
|
179
|
+
*/
|
|
180
|
+
export type PackageName = string & {
|
|
181
|
+
readonly ___type: 'PackageName';
|
|
182
|
+
};
|
|
183
|
+
export declare const toPackageName: (t: string) => PackageName;
|
|
177
184
|
/**
|
|
178
185
|
* Branded string values that can be used as import statement values in the generators
|
|
179
186
|
*/
|
|
@@ -181,4 +188,4 @@ export type ImportableTypes = FunctionName | ClassName | TypeName | AnnotatedTyp
|
|
|
181
188
|
/**
|
|
182
189
|
* Branded string values that can be used as paths in import statements
|
|
183
190
|
*/
|
|
184
|
-
export type ImportPaths = BackendModulePath | FilePath;
|
|
191
|
+
export type ImportPaths = BackendModulePath | FilePath | PackageName;
|
package/dist/lib/schema/types.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// MARK: - Generated content related types
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.toPath = exports.toBackendModulePath = exports.toModuleLocation = exports.toFolderName = exports.toFileName = exports.toVariableName = exports.toFunctionName = exports.toEnumName = exports.toFieldName = exports.isAnnotatedTypeName = exports.toAnnotatedTypeName = exports.toTypeName = exports.toModelName = exports.toDiscriminantName = exports.toClassName = void 0;
|
|
4
|
+
exports.toPackageName = exports.toPath = exports.toBackendModulePath = exports.toModuleLocation = exports.toFolderName = exports.toFileName = exports.toVariableName = exports.toFunctionName = exports.toEnumName = exports.toFieldName = exports.isAnnotatedTypeName = exports.toAnnotatedTypeName = exports.toTypeName = exports.toModelName = exports.toDiscriminantName = exports.toClassName = void 0;
|
|
5
5
|
/**
|
|
6
6
|
* Converts a raw string to a branded ClassName.
|
|
7
7
|
*/
|
|
@@ -104,3 +104,5 @@ exports.toBackendModulePath = toBackendModulePath;
|
|
|
104
104
|
*/
|
|
105
105
|
const toPath = (t) => t;
|
|
106
106
|
exports.toPath = toPath;
|
|
107
|
+
const toPackageName = (t) => t;
|
|
108
|
+
exports.toPackageName = toPackageName;
|
|
@@ -71,7 +71,6 @@ function getModelAttributes(model) {
|
|
|
71
71
|
const decoder = zod_1.default
|
|
72
72
|
.object({
|
|
73
73
|
ignore: blankStringBooleanDecoder,
|
|
74
|
-
inMemoryOnly: blankStringBooleanDecoder,
|
|
75
74
|
description: zod_1.default.string().optional(),
|
|
76
75
|
schema: zod_1.default.string({
|
|
77
76
|
required_error: `The PostXL attribute ${(0, logger_1.highlight)('`///@@Schema`')} attribute must be provided (in addition to Prisma's @@schema attribute)!`,
|
|
@@ -85,7 +84,6 @@ function getModelAttributes(model) {
|
|
|
85
84
|
})
|
|
86
85
|
.transform((obj) => ({
|
|
87
86
|
ignore: obj.ignore,
|
|
88
|
-
inMemoryOnly: obj.inMemoryOnly,
|
|
89
87
|
description: obj.description,
|
|
90
88
|
databaseSchema: obj.schema,
|
|
91
89
|
index: obj.index,
|
package/package.json
CHANGED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { SchemaMetaData } from '../../lib/meta';
|
|
2
|
-
import { Model } from '../../lib/schema/schema';
|
|
3
|
-
/**
|
|
4
|
-
* Generates a mocking class
|
|
5
|
-
*/
|
|
6
|
-
export declare function generateDataMockModule({ models, meta }: {
|
|
7
|
-
models: Model[];
|
|
8
|
-
meta: SchemaMetaData;
|
|
9
|
-
}): string;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateDataMockModule = void 0;
|
|
4
|
-
const imports_1 = require("../../lib/imports");
|
|
5
|
-
const meta_1 = require("../../lib/meta");
|
|
6
|
-
/**
|
|
7
|
-
* Generates a mocking class
|
|
8
|
-
*/
|
|
9
|
-
function generateDataMockModule({ models, meta }) {
|
|
10
|
-
const mm = models.map((model) => ({ model, meta: (0, meta_1.getModelMetadata)({ model }) }));
|
|
11
|
-
const imports = imports_1.ImportsGenerator.from(meta.data.mockModule.location.path).addImports({
|
|
12
|
-
[meta.data.moduleLocation.path]: [meta.data.moduleName],
|
|
13
|
-
[meta.data.dataService.location.path]: [meta.data.dataService.class],
|
|
14
|
-
[meta.backendModules.db.moduleLocation.import]: [meta.backendModules.db.moduleName],
|
|
15
|
-
// we need to import the file directly instead via the normal index file as this would cause a circular dependency else
|
|
16
|
-
[meta.actions.execution.mockLocation.import]: [meta.actions.execution.mock],
|
|
17
|
-
});
|
|
18
|
-
for (const { model, meta } of mm) {
|
|
19
|
-
imports.addTypeImport({ items: [model.typeName], from: meta.types.importPath });
|
|
20
|
-
imports.addImport({ items: [meta.data.repository.className], from: meta.data.repository.location.path });
|
|
21
|
-
imports.addImport({ items: [meta.data.mockRepository.className], from: meta.data.mockRepository.location.path });
|
|
22
|
-
}
|
|
23
|
-
const providers = mm
|
|
24
|
-
.map(({ meta }) => `{
|
|
25
|
-
provide: ${meta.data.repository.className},
|
|
26
|
-
useFactory: async () => {
|
|
27
|
-
const repository = new ${meta.data.mockRepository.className}()
|
|
28
|
-
if (!!seed && !!seed.${meta.seed.constantName}) {
|
|
29
|
-
await repository.reInit({items: seed.${meta.seed.constantName}, execution })
|
|
30
|
-
}
|
|
31
|
-
return repository
|
|
32
|
-
}
|
|
33
|
-
}`)
|
|
34
|
-
.join(', ');
|
|
35
|
-
return /* ts */ `
|
|
36
|
-
import { DynamicModule } from '@nestjs/common'
|
|
37
|
-
|
|
38
|
-
${imports.generate()}
|
|
39
|
-
|
|
40
|
-
export class ${meta.data.mockModule.name} {
|
|
41
|
-
static mock(seed?: MockData): DynamicModule {
|
|
42
|
-
const execution = new MockActionExecution()
|
|
43
|
-
|
|
44
|
-
const providers = [
|
|
45
|
-
DataService,
|
|
46
|
-
${providers}
|
|
47
|
-
]
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
module: ${meta.data.moduleName},
|
|
51
|
-
imports: [DatabaseModule.provideMock()],
|
|
52
|
-
providers,
|
|
53
|
-
exports: providers,
|
|
54
|
-
global: true,
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export interface ${meta.data.dataMockDataType} {
|
|
60
|
-
${mm.map(({ model, meta }) => `${meta.data.mockDataPropertyName}?: ${model.typeName}[]`).join('\n')}
|
|
61
|
-
}
|
|
62
|
-
`;
|
|
63
|
-
}
|
|
64
|
-
exports.generateDataMockModule = generateDataMockModule;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { SchemaMetaData } from '../../lib/meta';
|
|
2
|
-
import { Model } from '../../lib/schema/schema';
|
|
3
|
-
/**
|
|
4
|
-
* Generates a generic data mocker class.
|
|
5
|
-
*/
|
|
6
|
-
export declare function generateDataMocker({ models, meta: schemaMeta }: {
|
|
7
|
-
models: Model[];
|
|
8
|
-
meta: SchemaMetaData;
|
|
9
|
-
}): string;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateDataMocker = void 0;
|
|
4
|
-
const imports_1 = require("../../lib/imports");
|
|
5
|
-
const meta_1 = require("../../lib/meta");
|
|
6
|
-
const schema_1 = require("../../lib/schema/schema");
|
|
7
|
-
const types_1 = require("../../lib/schema/types");
|
|
8
|
-
/**
|
|
9
|
-
* Generates a generic data mocker class.
|
|
10
|
-
*/
|
|
11
|
-
function generateDataMocker({ models, meta: schemaMeta }) {
|
|
12
|
-
const modelMetas = models.map((model) => ({ model, meta: (0, meta_1.getModelMetadata)({ model }) }));
|
|
13
|
-
const imports = imports_1.ImportsGenerator.from(schemaMeta.e2e.dataMockerLocation.path);
|
|
14
|
-
for (const { model, meta } of modelMetas) {
|
|
15
|
-
imports.addImports({
|
|
16
|
-
[meta.types.importPath]: [(0, types_1.toAnnotatedTypeName)(model.typeName)],
|
|
17
|
-
[meta.e2e.stubLocation.path]: [meta.e2e.stubGenerationFnName],
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
const publicVariables = modelMetas
|
|
21
|
-
.map(({ model, meta }) => `public ${meta.data.dataServiceName}: ${model.typeName}[] = []`)
|
|
22
|
-
.join('\n');
|
|
23
|
-
const privateIds = modelMetas
|
|
24
|
-
.map(({ model, meta }) => `private ${meta.data.dataServiceIdName}Ids = new IdTracker<${model.typeName}>()`)
|
|
25
|
-
.join('\n');
|
|
26
|
-
const addDataFunctions = modelMetas.map(({ model, meta }) => generateAddDataFunction(model, meta)).join('\n');
|
|
27
|
-
return `
|
|
28
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
29
|
-
import type { MockData } from '@backend/data/data.mock.module'
|
|
30
|
-
|
|
31
|
-
${imports.generate()}
|
|
32
|
-
|
|
33
|
-
import { IdTracker } from './id-tracker.class'
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
export class DataMocker implements MockData {
|
|
37
|
-
${publicVariables}
|
|
38
|
-
|
|
39
|
-
${privateIds}
|
|
40
|
-
|
|
41
|
-
${addDataFunctions}
|
|
42
|
-
}
|
|
43
|
-
`;
|
|
44
|
-
}
|
|
45
|
-
exports.generateDataMocker = generateDataMocker;
|
|
46
|
-
function generateAddDataFunction(model, meta) {
|
|
47
|
-
const { fields, idField } = model;
|
|
48
|
-
const relations = fields
|
|
49
|
-
.filter(schema_1.isFieldRelation)
|
|
50
|
-
.map((field) => (Object.assign(Object.assign({}, field), { meta: (0, meta_1.getModelMetadata)({ model: field.relationToModel }), fieldMeta: (0, meta_1.getFieldMetadata)({ field }), model: field.relationToModel })))
|
|
51
|
-
.map((r) => {
|
|
52
|
-
if (r.isRequired) {
|
|
53
|
-
return `
|
|
54
|
-
if (_item.${r.name}) {
|
|
55
|
-
if (this.${r.meta.data.dataServiceName}.findIndex((x) => x.id === _item.${r.name}) === -1) {
|
|
56
|
-
this.add${r.model.typeName}({ id: _item.${r.name} })
|
|
57
|
-
}
|
|
58
|
-
} else {
|
|
59
|
-
if (this.${r.meta.data.dataServiceName}.length === 0) {
|
|
60
|
-
this.add${r.model.typeName}()
|
|
61
|
-
}
|
|
62
|
-
_item.${r.name} = this.${r.meta.data.dataServiceName}[0].id
|
|
63
|
-
}
|
|
64
|
-
`;
|
|
65
|
-
}
|
|
66
|
-
return `
|
|
67
|
-
if (_item.${r.name}) {
|
|
68
|
-
if (this.${r.meta.data.dataServiceName}.findIndex((x) => x.id === _item.${r.name}) === -1) {
|
|
69
|
-
this.add${r.model.typeName}({ id: _item.${r.name} })
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
`;
|
|
73
|
-
});
|
|
74
|
-
// TODO: Move the publicly accessible function's name to the metadata definition!
|
|
75
|
-
return /* ts */ `
|
|
76
|
-
public add${model.typeName}(
|
|
77
|
-
item?: Partial<Omit<${model.typeName}, '${idField.name}'> & { ${idField.name}: ${idField.unbrandedTypeName} }>
|
|
78
|
-
): DataMocker {
|
|
79
|
-
const _stub = stub${model.typeName}(item ?? {})
|
|
80
|
-
const _item = this.${meta.data.dataServiceIdName}Ids.ensureId(_stub)
|
|
81
|
-
|
|
82
|
-
this.${meta.data.dataServiceName}.push(_item)
|
|
83
|
-
|
|
84
|
-
${relations.join('\n')}
|
|
85
|
-
|
|
86
|
-
return this
|
|
87
|
-
}`;
|
|
88
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { SchemaMetaData } from '../../lib/meta';
|
|
2
|
-
import { Model } from '../../lib/schema/schema';
|
|
3
|
-
/**
|
|
4
|
-
* Generates a const that contains the SQL to delete all data from the E2E database.
|
|
5
|
-
*
|
|
6
|
-
* This is used in e2e tests to empty the database before each test.
|
|
7
|
-
*/
|
|
8
|
-
export declare function generateEmptyDatabaseCommand({ models }: {
|
|
9
|
-
models: Model[];
|
|
10
|
-
meta: SchemaMetaData;
|
|
11
|
-
}): string;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateEmptyDatabaseCommand = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Generates a const that contains the SQL to delete all data from the E2E database.
|
|
6
|
-
*
|
|
7
|
-
* This is used in e2e tests to empty the database before each test.
|
|
8
|
-
*/
|
|
9
|
-
function generateEmptyDatabaseCommand({ models }) {
|
|
10
|
-
const modelTables = models.map((model) => `${model.sourceSchemaName !== undefined ? `"${model.sourceSchemaName}".` : ''}"${model.sourceName}"`);
|
|
11
|
-
// We determine the schema used for all system tables by looking at the User model's schema.
|
|
12
|
-
const userModel = models.find((model) => model.name === 'User');
|
|
13
|
-
if (!userModel) {
|
|
14
|
-
throw new Error('Model definition for "User" could not be found - hence schema for system table cannot be derived!');
|
|
15
|
-
}
|
|
16
|
-
const configSchema = userModel.sourceSchemaName !== undefined ? `"${userModel.sourceSchemaName}".` : '';
|
|
17
|
-
const systemTables = ['Action', 'Mutation'].map((table) => `${configSchema}"${table}"`);
|
|
18
|
-
const configTableName = `${configSchema}"Config"`;
|
|
19
|
-
return /** ts */ `
|
|
20
|
-
/**
|
|
21
|
-
* SQL instruction to delete all data from the E2E database. Should only be used internally by the DbService!
|
|
22
|
-
*/
|
|
23
|
-
export const wipeDatabaseCommand = \`
|
|
24
|
-
DO $$
|
|
25
|
-
BEGIN
|
|
26
|
-
IF EXISTS (SELECT 1 FROM ${configTableName} WHERE "isTest" = TRUE) THEN
|
|
27
|
-
TRUNCATE TABLE
|
|
28
|
-
${[...systemTables, ...modelTables].join(',\n ')};
|
|
29
|
-
END IF;
|
|
30
|
-
END
|
|
31
|
-
$$;\`
|
|
32
|
-
`;
|
|
33
|
-
}
|
|
34
|
-
exports.generateEmptyDatabaseCommand = generateEmptyDatabaseCommand;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { SchemaMetaData } from '../../lib/meta';
|
|
2
|
-
import { Model } from '../../lib/schema/schema';
|
|
3
|
-
/**
|
|
4
|
-
* Generates the TestDataService class.
|
|
5
|
-
*/
|
|
6
|
-
export declare function generateTestDataService({ models, meta: schemaMeta, }: {
|
|
7
|
-
models: Model[];
|
|
8
|
-
meta: SchemaMetaData;
|
|
9
|
-
}): string;
|