@postxl/generator 0.0.1
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 +3 -0
- package/dist/jest.config.d.ts +3 -0
- package/dist/src/generator.d.ts +12 -0
- package/dist/src/generator.js +164 -0
- package/dist/src/generators/enums/react.generator.d.ts +10 -0
- package/dist/src/generators/enums/react.generator.js +81 -0
- package/dist/src/generators/enums/types.generator.d.ts +10 -0
- package/dist/src/generators/enums/types.generator.js +18 -0
- package/dist/src/generators/indices/datamockmodule.generator.d.ts +9 -0
- package/dist/src/generators/indices/datamockmodule.generator.js +104 -0
- package/dist/src/generators/indices/datamodule.generator.d.ts +9 -0
- package/dist/src/generators/indices/datamodule.generator.js +128 -0
- package/dist/src/generators/indices/dataservice.generator.d.ts +9 -0
- package/dist/src/generators/indices/dataservice.generator.js +47 -0
- package/dist/src/generators/indices/repositories.generator.d.ts +9 -0
- package/dist/src/generators/indices/repositories.generator.js +17 -0
- package/dist/src/generators/indices/seed.generator.d.ts +9 -0
- package/dist/src/generators/indices/seed.generator.js +17 -0
- package/dist/src/generators/indices/stubs.generator.d.ts +9 -0
- package/dist/src/generators/indices/stubs.generator.js +17 -0
- package/dist/src/generators/indices/testdataservice.generator.d.ts +7 -0
- package/dist/src/generators/indices/testdataservice.generator.js +61 -0
- package/dist/src/generators/indices/types.generator.d.ts +10 -0
- package/dist/src/generators/indices/types.generator.js +21 -0
- package/dist/src/generators/models/react.generator/context.generator.d.ts +9 -0
- package/dist/src/generators/models/react.generator/context.generator.js +66 -0
- package/dist/src/generators/models/react.generator/index.d.ts +10 -0
- package/dist/src/generators/models/react.generator/index.js +32 -0
- package/dist/src/generators/models/react.generator/library.generator.d.ts +9 -0
- package/dist/src/generators/models/react.generator/library.generator.js +113 -0
- package/dist/src/generators/models/react.generator/lookup.generator.d.ts +9 -0
- package/dist/src/generators/models/react.generator/lookup.generator.js +97 -0
- package/dist/src/generators/models/react.generator/modals.generator.d.ts +23 -0
- package/dist/src/generators/models/react.generator/modals.generator.js +521 -0
- package/dist/src/generators/models/repository.generator.d.ts +9 -0
- package/dist/src/generators/models/repository.generator.js +282 -0
- package/dist/src/generators/models/route.generator.d.ts +16 -0
- package/dist/src/generators/models/route.generator.js +112 -0
- package/dist/src/generators/models/seed.generator.d.ts +20 -0
- package/dist/src/generators/models/seed.generator.js +185 -0
- package/dist/src/generators/models/stub.generator.d.ts +9 -0
- package/dist/src/generators/models/stub.generator.js +74 -0
- package/dist/src/generators/models/types.generator.d.ts +9 -0
- package/dist/src/generators/models/types.generator.js +116 -0
- package/dist/src/lib/attributes.d.ts +43 -0
- package/dist/src/lib/attributes.js +2 -0
- package/dist/src/lib/exports.d.ts +26 -0
- package/dist/src/lib/exports.js +38 -0
- package/dist/src/lib/imports.d.ts +35 -0
- package/dist/src/lib/imports.js +55 -0
- package/dist/src/lib/meta.d.ts +359 -0
- package/dist/src/lib/meta.js +195 -0
- package/dist/src/lib/schema/fields.d.ts +35 -0
- package/dist/src/lib/schema/fields.js +49 -0
- package/dist/src/lib/schema/schema.d.ts +275 -0
- package/dist/src/lib/schema/schema.js +2 -0
- package/dist/src/lib/schema/types.d.ts +72 -0
- package/dist/src/lib/schema/types.js +41 -0
- package/dist/src/lib/schema/zod.d.ts +8 -0
- package/dist/src/lib/schema/zod.js +44 -0
- package/dist/src/lib/serializer.d.ts +15 -0
- package/dist/src/lib/serializer.js +24 -0
- package/dist/src/lib/utils/error.d.ts +5 -0
- package/dist/src/lib/utils/error.js +13 -0
- package/dist/src/lib/utils/file.d.ts +10 -0
- package/dist/src/lib/utils/file.js +54 -0
- package/dist/src/lib/utils/logger.d.ts +11 -0
- package/dist/src/lib/utils/logger.js +2 -0
- package/dist/src/lib/utils/string.d.ts +29 -0
- package/dist/src/lib/utils/string.js +75 -0
- package/dist/src/lib/utils/types.d.ts +12 -0
- package/dist/src/lib/utils/types.js +2 -0
- package/dist/src/lib/vfs.d.ts +137 -0
- package/dist/src/lib/vfs.js +419 -0
- package/dist/src/prisma/attributes.d.ts +17 -0
- package/dist/src/prisma/attributes.js +80 -0
- package/dist/src/prisma/client-path.d.ts +7 -0
- package/dist/src/prisma/client-path.js +29 -0
- package/dist/src/prisma/parse.d.ts +12 -0
- package/dist/src/prisma/parse.js +276 -0
- package/dist/tests/attributes.test.d.ts +1 -0
- package/dist/tests/attributes.test.js +76 -0
- package/dist/tests/file.test.d.ts +1 -0
- package/dist/tests/file.test.js +26 -0
- package/dist/tests/utils/random.d.ts +3 -0
- package/dist/tests/utils/random.js +15 -0
- package/dist/tests/vfs.test.d.ts +1 -0
- package/dist/tests/vfs.test.js +74 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/jest.config.ts +18 -0
- package/package.json +42 -0
- package/tests/attributes.test.ts +91 -0
- package/tests/file.test.ts +32 -0
- package/tests/utils/random.ts +11 -0
- package/tests/vfs.test.ts +92 -0
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import * as Schema from './schema/schema';
|
|
2
|
+
import * as Types from './schema/types';
|
|
3
|
+
/**
|
|
4
|
+
* Collection of "global", schema-related values that might be referenced by different generators.
|
|
5
|
+
*/
|
|
6
|
+
export type SchemaMetaData = {
|
|
7
|
+
data: {
|
|
8
|
+
/**
|
|
9
|
+
* Path to the file containing the data module class definition.
|
|
10
|
+
*/
|
|
11
|
+
dataModuleFilePath: Types.Path;
|
|
12
|
+
/**
|
|
13
|
+
* Path to the file containing the mock data for the database.
|
|
14
|
+
*/
|
|
15
|
+
dataMockModuleFilePath: Types.Path;
|
|
16
|
+
/**
|
|
17
|
+
* Path to the file containing data service class definitions.
|
|
18
|
+
*/
|
|
19
|
+
dataServiceFilePath: Types.Path;
|
|
20
|
+
/**
|
|
21
|
+
* Path to the file containing test data service definition.
|
|
22
|
+
*/
|
|
23
|
+
testDataServiceFilePath: Types.Path;
|
|
24
|
+
/**
|
|
25
|
+
* Path to the file containing the index file for the repositories.
|
|
26
|
+
*/
|
|
27
|
+
repositoriesIndexFilePath: Types.Path;
|
|
28
|
+
/**
|
|
29
|
+
* Path to the file containing the index file for the subs.
|
|
30
|
+
*/
|
|
31
|
+
stubIndexFilePath: Types.Path;
|
|
32
|
+
};
|
|
33
|
+
seed: {
|
|
34
|
+
/**
|
|
35
|
+
* Path to the index file for the seed package.
|
|
36
|
+
*/
|
|
37
|
+
indexFilePath: Types.Path;
|
|
38
|
+
/**
|
|
39
|
+
* Path that may be used in the import statement.
|
|
40
|
+
*/
|
|
41
|
+
importPath: Types.Path;
|
|
42
|
+
/**
|
|
43
|
+
* Random seed value to use for seeding faker.
|
|
44
|
+
*/
|
|
45
|
+
randomSeed: number;
|
|
46
|
+
};
|
|
47
|
+
trpc: {
|
|
48
|
+
/**
|
|
49
|
+
* Path to the file that contains the trpc routes object.
|
|
50
|
+
*/
|
|
51
|
+
routesFilePath: Types.Path;
|
|
52
|
+
/**
|
|
53
|
+
* Path that may be used to import the trpc routes object.
|
|
54
|
+
*/
|
|
55
|
+
importPath: Types.Path;
|
|
56
|
+
};
|
|
57
|
+
types: {
|
|
58
|
+
/**
|
|
59
|
+
* Path to the index file for the types package.
|
|
60
|
+
*/
|
|
61
|
+
indexFilePath: Types.Path;
|
|
62
|
+
/**
|
|
63
|
+
* Path that may be used to import the type definitions package.
|
|
64
|
+
*/
|
|
65
|
+
importPath: Types.Path;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Returns a collection of metadata relevant in the global schema context.
|
|
70
|
+
*/
|
|
71
|
+
export declare function getSchemaMetadata({ config }: {
|
|
72
|
+
config: Schema.SchemaConfig;
|
|
73
|
+
}): SchemaMetaData;
|
|
74
|
+
/**
|
|
75
|
+
* Collection of values that might be referenced by different generators.
|
|
76
|
+
*/
|
|
77
|
+
export type ModelMetaData = {
|
|
78
|
+
/**
|
|
79
|
+
* A user friendly name
|
|
80
|
+
*
|
|
81
|
+
* NOTE: User friendly name is very generic and meant to be used in log messages, errors -
|
|
82
|
+
* and any other places where the user shall read about it!
|
|
83
|
+
* It is not meant to be used for variables, class names, etc. In code, you should
|
|
84
|
+
* use a more specific name for your purposes (e.g. `reactCreateModalComponentName`).
|
|
85
|
+
*/
|
|
86
|
+
userFriendlyName: string;
|
|
87
|
+
data: {
|
|
88
|
+
/**
|
|
89
|
+
* Path that may be used to import definitions of this model.
|
|
90
|
+
*/
|
|
91
|
+
importPath: Types.Path;
|
|
92
|
+
/**
|
|
93
|
+
* The name of the MockData's property that contains the mock data for this model. (e.g. aggregations)
|
|
94
|
+
*/
|
|
95
|
+
mockDataPropertyName: Types.VariableName;
|
|
96
|
+
/**
|
|
97
|
+
* The path to the file containing stub definitions of this model.
|
|
98
|
+
*/
|
|
99
|
+
stubFilePath: Types.Path;
|
|
100
|
+
/**
|
|
101
|
+
* The name of the TypeScript constant that contains default values for all fields.
|
|
102
|
+
*/
|
|
103
|
+
defaultStubConstantName: Types.VariableName;
|
|
104
|
+
/**
|
|
105
|
+
* The name of the function that adds missing values to the partially populated model value.
|
|
106
|
+
*/
|
|
107
|
+
stubGenerationFnName: Types.Function;
|
|
108
|
+
/**
|
|
109
|
+
* Name of the file containing the repository definition for this model.
|
|
110
|
+
*/
|
|
111
|
+
repoFileName: Types.FileName;
|
|
112
|
+
/**
|
|
113
|
+
* Path to the file containing the repository definition.
|
|
114
|
+
*/
|
|
115
|
+
repoFilePath: Types.Path;
|
|
116
|
+
/**
|
|
117
|
+
* The name of the class for the repository definition of this model (e.g. AggregationRepository).
|
|
118
|
+
*/
|
|
119
|
+
repositoryClassName: Types.ClassName;
|
|
120
|
+
/**
|
|
121
|
+
* The name by which the repository is exposed in the dataService/context. (e.g. aggregations)
|
|
122
|
+
*/
|
|
123
|
+
dataServiceName: Types.VariableName;
|
|
124
|
+
/**
|
|
125
|
+
* The name of the export Excel table (e.g. `Aggregations`).
|
|
126
|
+
*/
|
|
127
|
+
excelExportTableName: string;
|
|
128
|
+
repository: {
|
|
129
|
+
/**
|
|
130
|
+
* The name of the function that decodes a source (database) object to a fully typed object, e.g. `toAggregation`.
|
|
131
|
+
*/
|
|
132
|
+
decoderFnName: Types.Function;
|
|
133
|
+
/**
|
|
134
|
+
* The name of the method that should be used to get objects from the database, e.g. `aggregations`.
|
|
135
|
+
*/
|
|
136
|
+
getMethodFnName: Types.Function;
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
seed: {
|
|
140
|
+
/**
|
|
141
|
+
* The name of the constant containing seed data of this model (e.g. `aggregations`).
|
|
142
|
+
*/
|
|
143
|
+
constantName: Types.VariableName;
|
|
144
|
+
/**
|
|
145
|
+
* Path to the file containing the seed data for this model (e.g. `aggregations.ts`).
|
|
146
|
+
*/
|
|
147
|
+
filePath: Types.Path;
|
|
148
|
+
/**
|
|
149
|
+
* The file or package name that contains the seed data for this model (e.g. `@d2i/aggregations`).
|
|
150
|
+
*/
|
|
151
|
+
importPath: Types.Path;
|
|
152
|
+
};
|
|
153
|
+
react: {
|
|
154
|
+
/**
|
|
155
|
+
* Name of the folder that contains React components for this model.
|
|
156
|
+
*/
|
|
157
|
+
folderName: Types.FolderName;
|
|
158
|
+
/**
|
|
159
|
+
* The path to the folder that contains React components for this model.
|
|
160
|
+
*/
|
|
161
|
+
folderPath: Types.Path;
|
|
162
|
+
context: {
|
|
163
|
+
/**
|
|
164
|
+
* Name of the function that should be used as React hook (e.g. `useAggregation`).
|
|
165
|
+
*/
|
|
166
|
+
hookFnName: Types.Function;
|
|
167
|
+
/**
|
|
168
|
+
* Name of the context wrapper.
|
|
169
|
+
*/
|
|
170
|
+
testContextProviderName: Types.VariableName;
|
|
171
|
+
/**
|
|
172
|
+
* Name of the context wrapper for this model.
|
|
173
|
+
*/
|
|
174
|
+
contextProviderName: Types.VariableName;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Names of React components that should be generated for this model.
|
|
178
|
+
*
|
|
179
|
+
* NOTE: You can assume that these components exist.
|
|
180
|
+
*/
|
|
181
|
+
components: {
|
|
182
|
+
modals: {
|
|
183
|
+
createComponentName: Types.VariableName;
|
|
184
|
+
editComponentName: Types.VariableName;
|
|
185
|
+
deleteComponentName: Types.VariableName;
|
|
186
|
+
};
|
|
187
|
+
forms: {
|
|
188
|
+
selectInputName: Types.VariableName;
|
|
189
|
+
selectFieldName: Types.VariableName;
|
|
190
|
+
menuSelectInputName: Types.VariableName;
|
|
191
|
+
menuSelectFieldName: Types.VariableName;
|
|
192
|
+
searchInputName: Types.VariableName;
|
|
193
|
+
searchFieldName: Types.VariableName;
|
|
194
|
+
tableSelectInputName: Types.VariableName;
|
|
195
|
+
tableSelectFieldName: Types.VariableName;
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* React component that may be used to list all model instances.
|
|
199
|
+
*/
|
|
200
|
+
libraryComponentName: Types.VariableName;
|
|
201
|
+
/**
|
|
202
|
+
* Name of the generic component containing basic information about a single model instance.
|
|
203
|
+
*/
|
|
204
|
+
cardComponentName: Types.VariableName;
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
trpc: {
|
|
208
|
+
/**
|
|
209
|
+
* The path to the file that contains the router definition for this model.
|
|
210
|
+
*/
|
|
211
|
+
importPath: Types.Path;
|
|
212
|
+
/**
|
|
213
|
+
* The absolute path of the file that contains the router definition for this model.
|
|
214
|
+
*/
|
|
215
|
+
routerFilePath: Types.Path;
|
|
216
|
+
/**
|
|
217
|
+
* The name of the router that should be used for this model (e.g. `aggregation`).
|
|
218
|
+
*/
|
|
219
|
+
routerName: Types.VariableName;
|
|
220
|
+
getMap: {
|
|
221
|
+
/**
|
|
222
|
+
* The name of the TRPC create method (e.g. `create` or `createAggregation`).
|
|
223
|
+
*/
|
|
224
|
+
methodName: Types.VariableName;
|
|
225
|
+
/**
|
|
226
|
+
* The full method name of the React Query method (e.g. `aggregation.create`).
|
|
227
|
+
*/
|
|
228
|
+
reactQueryMethod: Types.Function;
|
|
229
|
+
};
|
|
230
|
+
create: {
|
|
231
|
+
/**
|
|
232
|
+
* The name of the TRPC create method (e.g. `create` or `createAggregation`).
|
|
233
|
+
*/
|
|
234
|
+
methodName: Types.VariableName;
|
|
235
|
+
/**
|
|
236
|
+
* The full method name of the React Query method (e.g. `aggregation.create`).
|
|
237
|
+
*/
|
|
238
|
+
reactQueryMethod: Types.Function;
|
|
239
|
+
};
|
|
240
|
+
update: {
|
|
241
|
+
/**
|
|
242
|
+
* The name of the TRPC create method (e.g. `create` or `createAggregation`).
|
|
243
|
+
*/
|
|
244
|
+
methodName: Types.VariableName;
|
|
245
|
+
/**
|
|
246
|
+
* The full method name of the React Query method (e.g. `aggregation.create`).
|
|
247
|
+
*/
|
|
248
|
+
reactQueryMethod: Types.Function;
|
|
249
|
+
};
|
|
250
|
+
delete: {
|
|
251
|
+
/**
|
|
252
|
+
* The name of the TRPC create method (e.g. `create` or `createAggregation`).
|
|
253
|
+
*/
|
|
254
|
+
methodName: Types.VariableName;
|
|
255
|
+
/**
|
|
256
|
+
* The full method name of the React Query method (e.g. `aggregation.create`).
|
|
257
|
+
*/
|
|
258
|
+
reactQueryMethod: Types.Function;
|
|
259
|
+
};
|
|
260
|
+
};
|
|
261
|
+
types: {
|
|
262
|
+
/**
|
|
263
|
+
* The absolute path of the file that contains the type definition for this model.
|
|
264
|
+
*/
|
|
265
|
+
filePath: Types.Path;
|
|
266
|
+
/**
|
|
267
|
+
* Path that may be used to import the types of this model.
|
|
268
|
+
*/
|
|
269
|
+
importPath: Types.Path;
|
|
270
|
+
/**
|
|
271
|
+
* The name of the type that represents a branded ID, e.g. `AggregationId`.
|
|
272
|
+
*/
|
|
273
|
+
brandedIdType: Types.TypeName;
|
|
274
|
+
/**
|
|
275
|
+
* Function that may be used to convert a scalar value to a branded ID type,
|
|
276
|
+
* e.g. `toAggregationId`.
|
|
277
|
+
*/
|
|
278
|
+
toBrandedIdTypeFnName: Types.Function;
|
|
279
|
+
/**
|
|
280
|
+
* The name of the function that decodes a source (database) object to a fully typed object, e.g. `aggregationDecoder`.
|
|
281
|
+
*/
|
|
282
|
+
zodDecoderFnName: Types.Function;
|
|
283
|
+
/**
|
|
284
|
+
* The name of the file containing type definitions (e.g. `aggregation.type`).
|
|
285
|
+
*/
|
|
286
|
+
typeDefFileName: Types.FileName;
|
|
287
|
+
/**
|
|
288
|
+
* The name of the type that represents a source (i.e. database) object, e.g. `Aggregation`.
|
|
289
|
+
*/
|
|
290
|
+
sourceType: Types.TypeName;
|
|
291
|
+
};
|
|
292
|
+
};
|
|
293
|
+
/**
|
|
294
|
+
* Returns metadata related to the given model.
|
|
295
|
+
*/
|
|
296
|
+
export declare function getModelMetadata({ model }: {
|
|
297
|
+
model: Schema.ModelCore;
|
|
298
|
+
}): ModelMetaData;
|
|
299
|
+
type FieldMetaData = {
|
|
300
|
+
/**
|
|
301
|
+
* Name of the field as it should appear in the "exposed" properties of the generated type.
|
|
302
|
+
*/
|
|
303
|
+
tsFieldName: Types.VariableName;
|
|
304
|
+
};
|
|
305
|
+
/**
|
|
306
|
+
* A collection of hardcoded values shared across multiple generators related to the given field in the model.
|
|
307
|
+
*/
|
|
308
|
+
export declare function getFieldMetadata({ field }: {
|
|
309
|
+
field: Schema.Field;
|
|
310
|
+
}): FieldMetaData;
|
|
311
|
+
export type EnumMetaData = {
|
|
312
|
+
react: {
|
|
313
|
+
/**
|
|
314
|
+
* Name of the folder that contains React components for this model.
|
|
315
|
+
*/
|
|
316
|
+
folderName: Types.FolderName;
|
|
317
|
+
/**
|
|
318
|
+
* The path to the folder that contains React components for this model.
|
|
319
|
+
*/
|
|
320
|
+
folderPath: Types.Path;
|
|
321
|
+
/**
|
|
322
|
+
* Relative path to the file or a package that contains the React components for this model.
|
|
323
|
+
*/
|
|
324
|
+
importPath: Types.Path;
|
|
325
|
+
selectInputName: Types.VariableName;
|
|
326
|
+
selectFieldName: Types.VariableName;
|
|
327
|
+
switcherInputName: Types.VariableName;
|
|
328
|
+
switcherFieldName: Types.VariableName;
|
|
329
|
+
};
|
|
330
|
+
types: {
|
|
331
|
+
/**
|
|
332
|
+
* Variable that holds a list of all enum members (e.g. `aggregationGroupMembers`).
|
|
333
|
+
*/
|
|
334
|
+
membersList: Types.VariableName;
|
|
335
|
+
/**
|
|
336
|
+
* Variable that holds a map of all enum members (e.g. `aggregationGroup`).
|
|
337
|
+
*/
|
|
338
|
+
membersMap: Types.VariableName;
|
|
339
|
+
/**
|
|
340
|
+
* Relative path to the file that contains the enum's types, e.g. `./aggregation.type`.
|
|
341
|
+
*/
|
|
342
|
+
filePath: Types.Path;
|
|
343
|
+
/**
|
|
344
|
+
* Path that should be used to import enum type definitions.
|
|
345
|
+
*/
|
|
346
|
+
importPath: Types.Path;
|
|
347
|
+
/**
|
|
348
|
+
* Name of the enum as it appears in the source file (e.g. in Prisma schema).
|
|
349
|
+
*/
|
|
350
|
+
sourceName: string;
|
|
351
|
+
};
|
|
352
|
+
};
|
|
353
|
+
/**
|
|
354
|
+
* Returns string values that may be used across multiple generators related to the given enum.
|
|
355
|
+
*/
|
|
356
|
+
export declare function getEnumMetadata({ enumerator: { name, schemaConfig: config }, }: {
|
|
357
|
+
enumerator: Schema.Enum;
|
|
358
|
+
}): EnumMetaData;
|
|
359
|
+
export {};
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.getEnumMetadata = exports.getFieldMetadata = exports.getModelMetadata = exports.getSchemaMetadata = void 0;
|
|
27
|
+
const Types = __importStar(require("./schema/types"));
|
|
28
|
+
const string_1 = require("./utils/string");
|
|
29
|
+
/**
|
|
30
|
+
* Returns a collection of metadata relevant in the global schema context.
|
|
31
|
+
*/
|
|
32
|
+
function getSchemaMetadata({ config }) {
|
|
33
|
+
return {
|
|
34
|
+
data: {
|
|
35
|
+
dataModuleFilePath: Types.toPath(`${config.paths.dataLibPath}services/data.module`),
|
|
36
|
+
dataMockModuleFilePath: Types.toPath(`${config.paths.dataLibPath}services/data.mock.module`),
|
|
37
|
+
testDataServiceFilePath: Types.toPath(`${config.paths.dataLibPath}services/test-data.service`),
|
|
38
|
+
dataServiceFilePath: Types.toPath(`${config.paths.dataLibPath}services/data.service`),
|
|
39
|
+
repositoriesIndexFilePath: Types.toPath(`${config.paths.dataLibPath}repositories/index`),
|
|
40
|
+
stubIndexFilePath: Types.toPath(`${config.paths.dataLibPath}stubs/index`),
|
|
41
|
+
},
|
|
42
|
+
trpc: {
|
|
43
|
+
routesFilePath: Types.toPath(`${config.paths.trpcRoutesFolderPath}index`),
|
|
44
|
+
importPath: Types.toPath(`@${config.project}/trpc`),
|
|
45
|
+
},
|
|
46
|
+
seed: {
|
|
47
|
+
indexFilePath: Types.toPath(`${config.paths.seedPath}index`),
|
|
48
|
+
importPath: Types.toPath(`@${config.project}/seed`),
|
|
49
|
+
randomSeed: config.randomSeed,
|
|
50
|
+
},
|
|
51
|
+
types: {
|
|
52
|
+
indexFilePath: Types.toPath(`${config.paths.modelTypeDefinitionsPath}index`),
|
|
53
|
+
importPath: Types.toPath(`@${config.project}/types`),
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
exports.getSchemaMetadata = getSchemaMetadata;
|
|
58
|
+
/**
|
|
59
|
+
* Returns metadata related to the given model.
|
|
60
|
+
*/
|
|
61
|
+
function getModelMetadata({ model }) {
|
|
62
|
+
const { name, schemaConfig: config } = model;
|
|
63
|
+
const { PascalCase, camelCase, pluralized, uncapitalizedPlural } = (0, string_1.conjugateNames)(name);
|
|
64
|
+
return {
|
|
65
|
+
userFriendlyName: PascalCase,
|
|
66
|
+
data: {
|
|
67
|
+
mockDataPropertyName: Types.toVariableName(`${uncapitalizedPlural}`),
|
|
68
|
+
defaultStubConstantName: Types.toVariableName(`${camelCase}DefaultStub`),
|
|
69
|
+
repoFileName: Types.toFileName(`${camelCase}.repository`),
|
|
70
|
+
repoFilePath: Types.toPath(`${config.paths.dataLibPath}repositories/${camelCase}.repository`),
|
|
71
|
+
stubFilePath: Types.toPath(`${config.paths.dataLibPath}stubs/${camelCase}.stub`),
|
|
72
|
+
importPath: Types.toPath(`@${config.project}/data`),
|
|
73
|
+
stubGenerationFnName: Types.toFunction(`stub${PascalCase}`),
|
|
74
|
+
repositoryClassName: Types.toClassName(`${PascalCase}Repository`),
|
|
75
|
+
dataServiceName: Types.toVariableName(`${uncapitalizedPlural}`),
|
|
76
|
+
excelExportTableName: `${pluralized}`,
|
|
77
|
+
repository: {
|
|
78
|
+
decoderFnName: Types.toFunction(`to${PascalCase}`),
|
|
79
|
+
getMethodFnName: Types.toFunction(`${camelCase}`),
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
seed: {
|
|
83
|
+
filePath: Types.toPath(`${config.paths.seedPath}${uncapitalizedPlural}`),
|
|
84
|
+
constantName: Types.toVariableName(`${uncapitalizedPlural}`),
|
|
85
|
+
importPath: Types.toPath(`@${config.project}/seed`),
|
|
86
|
+
},
|
|
87
|
+
react: {
|
|
88
|
+
folderName: Types.toFolderName(`${PascalCase}`),
|
|
89
|
+
folderPath: Types.toPath(`${config.paths.reactFolderPath}models/${PascalCase}/`),
|
|
90
|
+
context: {
|
|
91
|
+
hookFnName: Types.toFunction(`use${PascalCase}`),
|
|
92
|
+
testContextProviderName: Types.toVariableName(`${PascalCase}TestContextProvider`),
|
|
93
|
+
contextProviderName: Types.toVariableName(`${PascalCase}Provider`),
|
|
94
|
+
},
|
|
95
|
+
components: {
|
|
96
|
+
modals: {
|
|
97
|
+
createComponentName: Types.toVariableName(`Create${PascalCase}Modal`),
|
|
98
|
+
editComponentName: Types.toVariableName(`Edit${PascalCase}Modal`),
|
|
99
|
+
deleteComponentName: Types.toVariableName(`Delete${PascalCase}Modal`),
|
|
100
|
+
},
|
|
101
|
+
forms: {
|
|
102
|
+
selectInputName: Types.toVariableName(`${PascalCase}SelectInput`),
|
|
103
|
+
selectFieldName: Types.toVariableName(`${PascalCase}SelectField`),
|
|
104
|
+
menuSelectInputName: Types.toVariableName(`${PascalCase}MenuSelectInput`),
|
|
105
|
+
menuSelectFieldName: Types.toVariableName(`${PascalCase}MenuSelectField`),
|
|
106
|
+
searchInputName: Types.toVariableName(`${PascalCase}SearchInput`),
|
|
107
|
+
searchFieldName: Types.toVariableName(`${PascalCase}SearchField`),
|
|
108
|
+
tableSelectInputName: Types.toVariableName(`${PascalCase}TableSelectInput`),
|
|
109
|
+
tableSelectFieldName: Types.toVariableName(`${PascalCase}TableSelectField`),
|
|
110
|
+
},
|
|
111
|
+
libraryComponentName: Types.toVariableName(`${PascalCase}Library`),
|
|
112
|
+
cardComponentName: Types.toVariableName(`${PascalCase}Card`),
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
trpc: {
|
|
116
|
+
routerFilePath: Types.toPath(`${config.paths.trpcRoutesFolderPath}${camelCase}.router`),
|
|
117
|
+
routerName: Types.toVariableName(camelCase),
|
|
118
|
+
importPath: Types.toPath(`@${config.project}${camelCase}.router`),
|
|
119
|
+
getMap: {
|
|
120
|
+
methodName: Types.toVariableName('getMap'),
|
|
121
|
+
reactQueryMethod: Types.toFunction(`${camelCase}.getMap`),
|
|
122
|
+
},
|
|
123
|
+
create: {
|
|
124
|
+
methodName: Types.toVariableName('create'),
|
|
125
|
+
reactQueryMethod: Types.toFunction(`${camelCase}.create`),
|
|
126
|
+
},
|
|
127
|
+
update: {
|
|
128
|
+
methodName: Types.toVariableName('update'),
|
|
129
|
+
reactQueryMethod: Types.toFunction(`${camelCase}.update`),
|
|
130
|
+
},
|
|
131
|
+
delete: {
|
|
132
|
+
methodName: Types.toVariableName('delete'),
|
|
133
|
+
reactQueryMethod: Types.toFunction(`${camelCase}.delete`),
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
types: {
|
|
137
|
+
importPath: Types.toPath(`@${config.project}/types`),
|
|
138
|
+
filePath: Types.toPath(`${config.paths.modelTypeDefinitionsPath}${camelCase}.type`),
|
|
139
|
+
brandedIdType: Types.toTypeName(`${PascalCase}Id`),
|
|
140
|
+
toBrandedIdTypeFnName: Types.toFunction(`to${PascalCase}Id`),
|
|
141
|
+
zodDecoderFnName: Types.toFunction(`${camelCase}Decoder`),
|
|
142
|
+
typeDefFileName: Types.toFileName(`${camelCase}.type`),
|
|
143
|
+
sourceType: Types.toTypeName(`${PascalCase}`),
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
exports.getModelMetadata = getModelMetadata;
|
|
148
|
+
/**
|
|
149
|
+
* A collection of hardcoded values shared across multiple generators related to the given field in the model.
|
|
150
|
+
*/
|
|
151
|
+
function getFieldMetadata({ field }) {
|
|
152
|
+
switch (field.kind) {
|
|
153
|
+
case 'id':
|
|
154
|
+
return {
|
|
155
|
+
tsFieldName: Types.toVariableName((0, string_1.toCamelCase)(field.name)),
|
|
156
|
+
};
|
|
157
|
+
case 'enum':
|
|
158
|
+
return {
|
|
159
|
+
tsFieldName: Types.toVariableName((0, string_1.toCamelCase)(field.name)),
|
|
160
|
+
};
|
|
161
|
+
case 'relation':
|
|
162
|
+
return {
|
|
163
|
+
tsFieldName: Types.toVariableName((0, string_1.toCamelCase)(field.name)),
|
|
164
|
+
};
|
|
165
|
+
case 'scalar':
|
|
166
|
+
return {
|
|
167
|
+
tsFieldName: Types.toVariableName((0, string_1.toCamelCase)(field.name)),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.getFieldMetadata = getFieldMetadata;
|
|
172
|
+
/**
|
|
173
|
+
* Returns string values that may be used across multiple generators related to the given enum.
|
|
174
|
+
*/
|
|
175
|
+
function getEnumMetadata({ enumerator: { name, schemaConfig: config }, }) {
|
|
176
|
+
return {
|
|
177
|
+
react: {
|
|
178
|
+
folderName: Types.toFolderName((0, string_1.toPascalCase)(name)),
|
|
179
|
+
folderPath: Types.toPath(`${config.paths.reactFolderPath}/enums/${(0, string_1.toPascalCase)(name)}`),
|
|
180
|
+
importPath: Types.toPath(`@${config.project}/react/enums/${(0, string_1.toPascalCase)(name)}`),
|
|
181
|
+
selectInputName: Types.toVariableName(`${(0, string_1.toPascalCase)(name)}SelectInput`),
|
|
182
|
+
selectFieldName: Types.toVariableName(`${(0, string_1.toPascalCase)(name)}SelectField`),
|
|
183
|
+
switcherInputName: Types.toVariableName(`${(0, string_1.toPascalCase)(name)}SwitcherInput`),
|
|
184
|
+
switcherFieldName: Types.toVariableName(`${(0, string_1.toPascalCase)(name)}SwitcherField`),
|
|
185
|
+
},
|
|
186
|
+
types: {
|
|
187
|
+
membersList: Types.toVariableName(`${(0, string_1.toCamelCase)(name)}Members`),
|
|
188
|
+
membersMap: Types.toVariableName(`${(0, string_1.toCamelCase)(name)}`),
|
|
189
|
+
filePath: Types.toPath(`${config.paths.modelTypeDefinitionsPath}${(0, string_1.toCamelCase)(name)}.enum`),
|
|
190
|
+
importPath: Types.toPath(`@${config.project}/types`),
|
|
191
|
+
sourceName: name,
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
exports.getEnumMetadata = getEnumMetadata;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Field, FieldEnum, FieldRelation, FieldScalar } from './schema';
|
|
2
|
+
/**
|
|
3
|
+
* The default field of the model.
|
|
4
|
+
* Note: A model can only have one or no default field!
|
|
5
|
+
* This is enforced by the schema validation.
|
|
6
|
+
*/
|
|
7
|
+
export declare const getDefaultField: ({ fields }: {
|
|
8
|
+
fields: Field[];
|
|
9
|
+
}) => FieldScalar | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* List of all scalar fields of the model (excluding foreing keys and the id)
|
|
12
|
+
*/
|
|
13
|
+
export declare const getScalarFields: ({ fields }: {
|
|
14
|
+
fields: Field[];
|
|
15
|
+
}) => FieldScalar[];
|
|
16
|
+
/**
|
|
17
|
+
* List of all relation fields of the model.
|
|
18
|
+
*/
|
|
19
|
+
export declare const getRelationFields: ({ fields }: {
|
|
20
|
+
fields: Field[];
|
|
21
|
+
}) => FieldRelation[];
|
|
22
|
+
/**
|
|
23
|
+
* List of all enum fields of the model.
|
|
24
|
+
*/
|
|
25
|
+
export declare const getEnumFields: ({ fields }: {
|
|
26
|
+
fields: Field[];
|
|
27
|
+
}) => FieldEnum[];
|
|
28
|
+
/**
|
|
29
|
+
* Returns a default value for a TypeScript type.
|
|
30
|
+
*/
|
|
31
|
+
export declare const getDefaultValueForType: (type: string) => string;
|
|
32
|
+
/**
|
|
33
|
+
* Returns true if the given field is unique and a string field.
|
|
34
|
+
*/
|
|
35
|
+
export declare const isUniqueStringField: (f: Field) => boolean;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isUniqueStringField = exports.getDefaultValueForType = exports.getEnumFields = exports.getRelationFields = exports.getScalarFields = exports.getDefaultField = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The default field of the model.
|
|
6
|
+
* Note: A model can only have one or no default field!
|
|
7
|
+
* This is enforced by the schema validation.
|
|
8
|
+
*/
|
|
9
|
+
const getDefaultField = ({ fields }) => fields.find((f) => f.attributes.isDefaultField);
|
|
10
|
+
exports.getDefaultField = getDefaultField;
|
|
11
|
+
/**
|
|
12
|
+
* List of all scalar fields of the model (excluding foreing keys and the id)
|
|
13
|
+
*/
|
|
14
|
+
const getScalarFields = ({ fields }) => fields.filter((f) => f.kind === 'scalar');
|
|
15
|
+
exports.getScalarFields = getScalarFields;
|
|
16
|
+
/**
|
|
17
|
+
* List of all relation fields of the model.
|
|
18
|
+
*/
|
|
19
|
+
const getRelationFields = ({ fields }) => fields.filter((f) => f.kind === 'relation');
|
|
20
|
+
exports.getRelationFields = getRelationFields;
|
|
21
|
+
/**
|
|
22
|
+
* List of all enum fields of the model.
|
|
23
|
+
*/
|
|
24
|
+
const getEnumFields = ({ fields }) => fields.filter((f) => f.kind === 'enum');
|
|
25
|
+
exports.getEnumFields = getEnumFields;
|
|
26
|
+
/**
|
|
27
|
+
* Returns a default value for a TypeScript type.
|
|
28
|
+
*/
|
|
29
|
+
const getDefaultValueForType = (type) => {
|
|
30
|
+
switch (type) {
|
|
31
|
+
case 'number':
|
|
32
|
+
return '0';
|
|
33
|
+
case 'string':
|
|
34
|
+
return "''";
|
|
35
|
+
case 'boolean':
|
|
36
|
+
return 'true';
|
|
37
|
+
case 'Date':
|
|
38
|
+
return 'new Date()';
|
|
39
|
+
default:
|
|
40
|
+
return '{} as any';
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
exports.getDefaultValueForType = getDefaultValueForType;
|
|
44
|
+
/**
|
|
45
|
+
* Returns true if the given field is unique and a string field.
|
|
46
|
+
*/
|
|
47
|
+
const isUniqueStringField = (f) => (f.kind === 'id' && f.isUnique && f.unbrandedTypeName === 'string') ||
|
|
48
|
+
(f.kind === 'scalar' && f.isUnique && f.typeName === 'string');
|
|
49
|
+
exports.isUniqueStringField = isUniqueStringField;
|