@postxl/generator 0.66.0 → 0.68.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/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 -1
- 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 +26 -27
- 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.js +4 -10
- package/dist/generators/models/route.generator.js +11 -8
- package/dist/lib/meta.d.ts +21 -23
- package/dist/lib/meta.js +6 -11
- package/dist/lib/schema/types.d.ts +8 -1
- package/dist/lib/schema/types.js +3 -1
- package/package.json +1 -1
|
@@ -45,7 +45,7 @@ function generateDataService({ models, meta }) {
|
|
|
45
45
|
return /* ts */ `
|
|
46
46
|
import { Injectable, Logger } from '@nestjs/common'
|
|
47
47
|
|
|
48
|
-
import { format, mapValues, pluralize } from '@
|
|
48
|
+
import { format, mapValues, pluralize } from '@postxl/runtime'
|
|
49
49
|
|
|
50
50
|
${imports.generate()}
|
|
51
51
|
|
|
@@ -24,7 +24,7 @@ function generateActionsDispatcherService({ models, meta }) {
|
|
|
24
24
|
return /* ts */ `
|
|
25
25
|
import { Injectable } from '@nestjs/common'
|
|
26
26
|
|
|
27
|
-
import { ExhaustiveSwitchCheck } from '@
|
|
27
|
+
import { ExhaustiveSwitchCheck } from '@postxl/runtime'
|
|
28
28
|
|
|
29
29
|
${imports.generate()}
|
|
30
30
|
|
|
@@ -42,7 +42,7 @@ function generateImportExportConvertImportFunctions({ models, meta, }) {
|
|
|
42
42
|
// logState({ state, nextStep, lastStep: 'updateModelState' })
|
|
43
43
|
}
|
|
44
44
|
return /* ts */ `
|
|
45
|
-
import { ExhaustiveSwitchCheck } from '@
|
|
45
|
+
import { ExhaustiveSwitchCheck } from '@postxl/runtime'
|
|
46
46
|
${imports.generate()}
|
|
47
47
|
|
|
48
48
|
/**
|
|
@@ -46,7 +46,7 @@ function generateImportExportImportService({ models, meta }) {
|
|
|
46
46
|
}
|
|
47
47
|
return /* ts */ `
|
|
48
48
|
import { Injectable } from '@nestjs/common'
|
|
49
|
-
import { ExhaustiveSwitchCheck } from '@
|
|
49
|
+
import { ExhaustiveSwitchCheck } from '@postxl/runtime'
|
|
50
50
|
|
|
51
51
|
${imports.generate()}
|
|
52
52
|
|
|
@@ -42,12 +42,6 @@ function generateModelBusinessLogicUpdate({ model, meta }) {
|
|
|
42
42
|
iExecution: schemaMeta.actions.execution.interface,
|
|
43
43
|
typeName: meta.types.typeName,
|
|
44
44
|
brandedId: model.brandedIdType,
|
|
45
|
-
decoders: {
|
|
46
|
-
name: meta.update.decoders.name,
|
|
47
|
-
createType: `Create${meta.internalSingularNameCapitalized}`,
|
|
48
|
-
updateType: `Update${meta.internalSingularNameCapitalized}`,
|
|
49
|
-
upsertType: `Upsert${meta.internalSingularNameCapitalized}`,
|
|
50
|
-
},
|
|
51
45
|
};
|
|
52
46
|
const imports = imports_1.ImportsGenerator.from(meta.update.serviceClassLocation.path);
|
|
53
47
|
imports.addImports({
|
|
@@ -96,7 +90,6 @@ function generateModelBusinessLogicUpdate({ model, meta }) {
|
|
|
96
90
|
`@Inject(forwardRef(() => ${schemaMeta.update.serviceClassName})) private readonly updateService: ${schemaMeta.update.serviceClassName}`,
|
|
97
91
|
`@Inject(forwardRef(() => ${schemaMeta.view.serviceClassName})) private readonly viewService: ${schemaMeta.view.serviceClassName}`,
|
|
98
92
|
];
|
|
99
|
-
const decoders = meta.update.decoders;
|
|
100
93
|
const { view, update } = meta;
|
|
101
94
|
const deleteFn = generateDeleteFn({ model, meta, m });
|
|
102
95
|
const deleteManyFn = generateDeleteManyFn({ imports, model, meta, m });
|
|
@@ -113,19 +106,19 @@ function generateModelBusinessLogicUpdate({ model, meta }) {
|
|
|
113
106
|
export type Actions = {
|
|
114
107
|
${(0, jsdoc_1.toJsDocComment)([`Creates a new ${meta.userFriendlyName} and returns it.`])}
|
|
115
108
|
create: {
|
|
116
|
-
payload:
|
|
109
|
+
payload: CreatePayload
|
|
117
110
|
result: ${m.typeName}
|
|
118
111
|
}
|
|
119
112
|
|
|
120
113
|
${(0, jsdoc_1.toJsDocComment)([`Updates a ${meta.userFriendlyName} and returns it.`])}
|
|
121
114
|
update: {
|
|
122
|
-
payload:
|
|
115
|
+
payload: UpdatePayload
|
|
123
116
|
result: ${m.typeName}
|
|
124
117
|
}
|
|
125
118
|
|
|
126
119
|
${(0, jsdoc_1.toJsDocComment)([`Creates or updates a ${meta.userFriendlyName} and returns it.`])}
|
|
127
120
|
upsert: {
|
|
128
|
-
payload:
|
|
121
|
+
payload: UpsertPayload
|
|
129
122
|
result: ${m.typeName}
|
|
130
123
|
}
|
|
131
124
|
|
|
@@ -139,40 +132,34 @@ function generateModelBusinessLogicUpdate({ model, meta }) {
|
|
|
139
132
|
/**
|
|
140
133
|
* Zod decoder for validating the create input of a ${meta.userFriendlyName}.
|
|
141
134
|
*/
|
|
142
|
-
export const ${
|
|
135
|
+
export const ${meta.update.createInputDecoder} = z.object({
|
|
143
136
|
${model.fields
|
|
144
137
|
.filter((f) => !f.attributes.isReadonly)
|
|
145
138
|
.map((f) => `${f.name}: z.${(0, zod_1.getZodDecoderDefinition)({ field: f })}`)
|
|
146
139
|
.join(',')}
|
|
147
140
|
})
|
|
148
141
|
|
|
149
|
-
type
|
|
142
|
+
type CreatePayload = z.infer<typeof ${meta.update.createInputDecoder}>
|
|
150
143
|
|
|
151
144
|
/**
|
|
152
145
|
* Zod decoder for validating the update input of a ${meta.userFriendlyName} .
|
|
153
146
|
*/
|
|
154
|
-
export const ${
|
|
147
|
+
export const ${meta.update.updateInputDecoder} = z.object({
|
|
155
148
|
${model.fields
|
|
156
149
|
.filter((f) => !f.attributes.isReadonly || f.kind === 'id')
|
|
157
150
|
.map((f) => `${f.name}: z.${(0, zod_1.getZodDecoderDefinition)({ field: f, allowAnyOptionalField: f.kind !== 'id' })}`)
|
|
158
151
|
.join(',')}
|
|
159
152
|
})
|
|
160
153
|
|
|
161
|
-
type
|
|
154
|
+
type UpdatePayload = z.infer<typeof ${meta.update.updateInputDecoder}>
|
|
162
155
|
|
|
163
156
|
/**
|
|
164
157
|
* Zod decoder for validating the upsert input of a ${meta.userFriendlyName} .
|
|
165
158
|
*/
|
|
166
|
-
export const ${
|
|
159
|
+
export const ${meta.update.upsertInputDecoder} = z.union([${meta.update.updateInputDecoder}, ${meta.update.createInputDecoder}])
|
|
167
160
|
|
|
168
|
-
type
|
|
161
|
+
type UpsertPayload = z.infer<typeof ${meta.update.upsertInputDecoder}>
|
|
169
162
|
|
|
170
|
-
export const ${decoders.name} = {
|
|
171
|
-
create: ${decoders.create},
|
|
172
|
-
update: ${decoders.update},
|
|
173
|
-
upsert: ${decoders.upsert},
|
|
174
|
-
}
|
|
175
|
-
|
|
176
163
|
export type ${update.serviceInterfaceName} = ${schemaMeta.actions.dispatcher.definition}<Actions>
|
|
177
164
|
|
|
178
165
|
@Injectable()
|
|
@@ -188,17 +175,17 @@ function generateModelBusinessLogicUpdate({ model, meta }) {
|
|
|
188
175
|
}
|
|
189
176
|
|
|
190
177
|
${(0, jsdoc_1.toJsDocComment)([`Creates a new ${meta.userFriendlyName} and returns it.`])}
|
|
191
|
-
public async create({ data, execution }: { data:
|
|
178
|
+
public async create({ data, execution }: { data: CreatePayload; execution: ${m.iExecution} }): Promise<${m.typeName}> {
|
|
192
179
|
return this.data.create({ item: data, execution })
|
|
193
180
|
}
|
|
194
181
|
|
|
195
182
|
${(0, jsdoc_1.toJsDocComment)([`Updates a ${meta.userFriendlyName} and returns it.`])}
|
|
196
|
-
public async update({ data, execution }: { data:
|
|
183
|
+
public async update({ data, execution }: { data: UpdatePayload; execution: ${m.iExecution} }): Promise<${m.typeName}> {
|
|
197
184
|
return this.data.update({ item: data, execution })
|
|
198
185
|
}
|
|
199
186
|
|
|
200
187
|
${(0, jsdoc_1.toJsDocComment)([`Creates or updates a ${meta.userFriendlyName} and returns it.`])}
|
|
201
|
-
public async upsert({ data, execution }: { data:
|
|
188
|
+
public async upsert({ data, execution }: { data: UpsertPayload; execution: ${m.iExecution} }): Promise<${m.typeName}> {
|
|
202
189
|
return this.data.upsert({ item: data, execution })
|
|
203
190
|
}
|
|
204
191
|
|
|
@@ -302,10 +289,22 @@ function generateDeleteManyFn({ imports, model, meta, m, }) {
|
|
|
302
289
|
function generateCloneFn({ model, meta, m }) {
|
|
303
290
|
const inputFields = model.fields.map((f) => {
|
|
304
291
|
const type = (0, typescript_1.getFieldType)(f);
|
|
305
|
-
|
|
292
|
+
// NOTE: ID field is always required to resolve the source.
|
|
293
|
+
if (f.kind === 'id') {
|
|
306
294
|
return `${f.name}: ${type}`;
|
|
307
295
|
}
|
|
308
|
-
|
|
296
|
+
if (f.isUnique) {
|
|
297
|
+
// NOTE: `unique` fields require a new value.
|
|
298
|
+
if (f.isRequired) {
|
|
299
|
+
return `${f.name}: ${type}`;
|
|
300
|
+
}
|
|
301
|
+
return `${f.name}: ${type} | null`;
|
|
302
|
+
}
|
|
303
|
+
// NOTE: Non-unique fields can be copied from the source.
|
|
304
|
+
if (f.isRequired) {
|
|
305
|
+
return `${f.name}?: ${type}`;
|
|
306
|
+
}
|
|
307
|
+
return `${f.name}?: ${type} | null`;
|
|
309
308
|
});
|
|
310
309
|
return `
|
|
311
310
|
${(0, jsdoc_1.toJsDocComment)([`Creates a new ${meta.userFriendlyName} deep clone and returns it.`])}
|
|
@@ -113,13 +113,41 @@ function generateModelBusinessLogicView({ model, meta }) {
|
|
|
113
113
|
`;
|
|
114
114
|
return /* ts */ `
|
|
115
115
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
116
|
+
import z from 'zod'
|
|
117
|
+
|
|
116
118
|
import { Inject, Injectable, forwardRef } from '@nestjs/common'
|
|
117
|
-
import { FilterOperator } from '@backend/common'
|
|
118
119
|
|
|
119
120
|
${imports.generate()}
|
|
120
121
|
|
|
121
122
|
${hasLinkedItems ? linkedTypeDefinition : ''}
|
|
122
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Cursor decoder.
|
|
126
|
+
*/
|
|
127
|
+
export const ${meta.view.cursorDecoder} = z.object({ startRow: z.number(), endRow: z.number() })
|
|
128
|
+
|
|
129
|
+
type Cursor = z.infer<typeof ${meta.view.cursorDecoder}>
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Filter operator decoder.
|
|
133
|
+
*/
|
|
134
|
+
export const ${meta.view.filterOperatorDecoder} = z.enum([
|
|
135
|
+
'eq',
|
|
136
|
+
'neq',
|
|
137
|
+
'gt',
|
|
138
|
+
'gte',
|
|
139
|
+
'lt',
|
|
140
|
+
'lte',
|
|
141
|
+
'in',
|
|
142
|
+
'nin',
|
|
143
|
+
'contains',
|
|
144
|
+
'ncontains',
|
|
145
|
+
'starts',
|
|
146
|
+
'ends',
|
|
147
|
+
])
|
|
148
|
+
|
|
149
|
+
type FilterOperator = z.infer<typeof ${meta.view.filterOperatorDecoder}>
|
|
150
|
+
|
|
123
151
|
@Injectable()
|
|
124
152
|
export class ${meta.view.serviceClassName} {
|
|
125
153
|
constructor(${constructorParameters.join(',\n')}) {}
|
|
@@ -151,7 +179,7 @@ export class ${meta.view.serviceClassName} {
|
|
|
151
179
|
}: {
|
|
152
180
|
filter?: { field: keyof ${model.typeName}; operator: FilterOperator; value: string | number }
|
|
153
181
|
sort?: { field: keyof ${model.typeName}; ascending: boolean }
|
|
154
|
-
cursor?:
|
|
182
|
+
cursor?: Cursor
|
|
155
183
|
}) {
|
|
156
184
|
const items = await this.${modelRepositoryVariableName}.getAllAsArray()
|
|
157
185
|
const filtered = !filter
|
|
@@ -10,19 +10,17 @@ const types_2 = require("../../lib/types");
|
|
|
10
10
|
*/
|
|
11
11
|
function generateModelImportExportDecoder({ model, meta, schemaMeta, }) {
|
|
12
12
|
const { filePath: decoderFilePath, itemEncoderFunctionName: rowExportFunctionName, encodedExcelType: excelType, arrayEncoderFunctionName: tableExportFunctionName, tableDecoder: tableImportDecoder, } = meta.importExport.decoder;
|
|
13
|
-
const imports = imports_1.ImportsGenerator.from(decoderFilePath)
|
|
14
|
-
|
|
15
|
-
[schemaMeta.backendModules.common.importPath]: [
|
|
16
|
-
schemaMeta.backendModules.common.functions.uncapitalizeKeys,
|
|
17
|
-
schemaMeta.backendModules.common.functions.capitalizeKeys,
|
|
18
|
-
schemaMeta.backendModules.common.functions.nullOrBlankDecoder,
|
|
19
|
-
],
|
|
13
|
+
const imports = imports_1.ImportsGenerator.from(decoderFilePath).addImports({
|
|
14
|
+
[schemaMeta.backendModules.common.importPath]: [schemaMeta.backendModules.common.functions.excelNullOrBlankDecoder],
|
|
20
15
|
[meta.types.importPath]: [(0, types_1.toAnnotatedTypeName)(meta.types.typeName)],
|
|
21
16
|
});
|
|
22
17
|
const { userFriendlyName: userFriendly, userFriendlyNamePlural: userFriendlyPlural, internalSingularName: singular, internalSingularNameCapitalized: singularCapitalized, } = meta;
|
|
23
18
|
const { fieldDecoders, blankFieldDecoders } = generateFieldDecoders({ model, meta, schemaMeta, imports });
|
|
24
19
|
return `
|
|
25
20
|
import * as z from 'zod'
|
|
21
|
+
|
|
22
|
+
import { uncapitalizeKeys, capitalizeKeys } from '@postxl/runtime'
|
|
23
|
+
|
|
26
24
|
${imports.generate()}
|
|
27
25
|
|
|
28
26
|
/**
|
|
@@ -80,7 +78,7 @@ function generateFieldDecoders({ model, meta, schemaMeta, imports, }) {
|
|
|
80
78
|
for (const field of model.fields) {
|
|
81
79
|
const fieldMeta = (0, meta_1.getFieldMetadata)({ field });
|
|
82
80
|
const optionalModifier = field.attributes.isUpdatedAt || field.attributes.isCreatedAt ? '.optional()' : '';
|
|
83
|
-
blankFieldDecoders.push(`${fieldMeta.excelColumnName}:
|
|
81
|
+
blankFieldDecoders.push(`${fieldMeta.excelColumnName}: excelNullOrBlankDecoder${optionalModifier}`);
|
|
84
82
|
switch (field.kind) {
|
|
85
83
|
case 'id': {
|
|
86
84
|
imports.addImport({ items: [meta.types.toBrandedIdTypeFnName], from: meta.types.importPath });
|
|
@@ -140,10 +138,7 @@ dbTypeName, nullable, imports, schemaMeta, }) {
|
|
|
140
138
|
switch (tsTypeName) {
|
|
141
139
|
case 'string': {
|
|
142
140
|
const decoder = schemaMeta.backendModules.common.functions[nullable ? 'excelStringNullableDecoder' : 'excelStringDecoder'];
|
|
143
|
-
imports.addImport({
|
|
144
|
-
items: [decoder],
|
|
145
|
-
from: schemaMeta.backendModules.common.importPath,
|
|
146
|
-
});
|
|
141
|
+
imports.addImport({ items: [decoder], from: schemaMeta.backendModules.common.importPath });
|
|
147
142
|
return decoder;
|
|
148
143
|
}
|
|
149
144
|
case 'boolean':
|
|
@@ -192,9 +187,6 @@ dbTypeName, nullable, imports, schemaMeta, }) {
|
|
|
192
187
|
function generateImportExportDecoder({ models, meta }) {
|
|
193
188
|
const { decodedPXLModelDataTypeName, encodedExcelDataTypeName, fullDecoderName, fullEncoderFunctionName } = meta.importExport.decoder;
|
|
194
189
|
const imports = imports_1.ImportsGenerator.from(meta.importExport.decoder.location.path);
|
|
195
|
-
imports.addImports({
|
|
196
|
-
[meta.backendModules.common.importPath]: (0, types_1.toFunctionName)('uncapitalizeKeys'),
|
|
197
|
-
});
|
|
198
190
|
const importTypes = [];
|
|
199
191
|
const decoderEntries = [];
|
|
200
192
|
const exportFields = [];
|
|
@@ -217,6 +209,9 @@ function generateImportExportDecoder({ models, meta }) {
|
|
|
217
209
|
}
|
|
218
210
|
return `
|
|
219
211
|
import * as z from 'zod'
|
|
212
|
+
|
|
213
|
+
import { uncapitalizeKeys } from '@postxl/runtime'
|
|
214
|
+
|
|
220
215
|
${imports.generate()}
|
|
221
216
|
|
|
222
217
|
export type ${encodedExcelDataTypeName} = {
|
|
@@ -18,7 +18,7 @@ function generateModelContext({ model, meta }) {
|
|
|
18
18
|
import React, { useMemo } from 'react'
|
|
19
19
|
|
|
20
20
|
import { trpc } from '@lib/trpc'
|
|
21
|
-
import { filterMap, mapMap } from '@
|
|
21
|
+
import { filterMap, mapMap } from '@postxl/runtime'
|
|
22
22
|
|
|
23
23
|
${imports.generate()}
|
|
24
24
|
|
|
@@ -56,7 +56,6 @@ function generateRepository({ model, meta }) {
|
|
|
56
56
|
mainBlocks = _generateMainBuildingBlocks_InMemoryOnly({
|
|
57
57
|
model,
|
|
58
58
|
meta,
|
|
59
|
-
schemaMeta,
|
|
60
59
|
imports,
|
|
61
60
|
blocks: {
|
|
62
61
|
uniqueStringFieldsBlocks,
|
|
@@ -88,6 +87,7 @@ function generateRepository({ model, meta }) {
|
|
|
88
87
|
}
|
|
89
88
|
return `
|
|
90
89
|
import { Injectable, Logger } from '@nestjs/common'
|
|
90
|
+
|
|
91
91
|
${idBlocks.libraryImports}
|
|
92
92
|
${imports.generate()}
|
|
93
93
|
|
|
@@ -228,13 +228,10 @@ exports.generateMockRepository = generateMockRepository;
|
|
|
228
228
|
/**
|
|
229
229
|
* Generates the main building blocks of the repository for in-memory model.
|
|
230
230
|
*/
|
|
231
|
-
function _generateMainBuildingBlocks_InMemoryOnly({ model, meta,
|
|
231
|
+
function _generateMainBuildingBlocks_InMemoryOnly({ model, meta, imports, blocks, }) {
|
|
232
232
|
const methodTypeSignatures = getRepositoryMethodsTypeSignatures({ model, meta });
|
|
233
233
|
const userRepositorySpecificBlocks = generateUserRepositorySpecificBlocks_InMemoryOnly({ model, meta, imports });
|
|
234
|
-
imports.addImport({
|
|
235
|
-
from: schemaMeta.backendModules.common.importPath,
|
|
236
|
-
items: ['removeUndefinedProperties'].map(types_1.toFunctionName),
|
|
237
|
-
});
|
|
234
|
+
imports.addImport({ from: (0, types_1.toPackageName)('@postxl/runtime'), items: [(0, types_1.toFunctionName)('removeUndefinedProperties')] });
|
|
238
235
|
return {
|
|
239
236
|
constructorCode: '',
|
|
240
237
|
userRepositorySpecificBlocks,
|
|
@@ -472,10 +469,7 @@ function generateMainBuildingBlocks_InDatabase({ model, meta, schemaMeta, import
|
|
|
472
469
|
[meta.types.importPath]: [meta.types.zodDecoderFnNames.fromDatabase],
|
|
473
470
|
[schemaMeta.backendModules.db.databaseService.location.import]: [schemaMeta.backendModules.db.databaseService.name],
|
|
474
471
|
[schemaMeta.backendModules.db.typesImportPath]: [(0, types_1.toAnnotatedTypeName)((0, types_1.toTypeName)(`${model.sourceName} as DbType`))],
|
|
475
|
-
[
|
|
476
|
-
schemaMeta.backendModules.common.functions.format,
|
|
477
|
-
schemaMeta.backendModules.common.functions.pluralize,
|
|
478
|
-
],
|
|
472
|
+
[(0, types_1.toPackageName)('@postxl/runtime')]: [(0, types_1.toFunctionName)('format'), (0, types_1.toFunctionName)('pluralize')],
|
|
479
473
|
});
|
|
480
474
|
const dbTableName = [model.sourceSchemaName, model.sourceName]
|
|
481
475
|
.filter((s) => s != null)
|
|
@@ -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/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;
|
|
@@ -878,6 +874,14 @@ export type ModelMetaData = {
|
|
|
878
874
|
* The name of the variable that holds the repository instance for the current model
|
|
879
875
|
*/
|
|
880
876
|
dataRepositoryVariableName: Types.VariableName;
|
|
877
|
+
/**
|
|
878
|
+
* The name of the variable that defines the filter operator decoder for the current model.
|
|
879
|
+
*/
|
|
880
|
+
filterOperatorDecoder: Types.VariableName;
|
|
881
|
+
/**
|
|
882
|
+
* The name of the variable that defines the cursor decoder for the current model.
|
|
883
|
+
*/
|
|
884
|
+
cursorDecoder: Types.VariableName;
|
|
881
885
|
};
|
|
882
886
|
/**
|
|
883
887
|
* The definitions for the update service of a model
|
|
@@ -913,24 +917,18 @@ export type ModelMetaData = {
|
|
|
913
917
|
* The name of the model used as a discriminant for the action execution. (e.g. `aggregation`)
|
|
914
918
|
*/
|
|
915
919
|
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
|
-
};
|
|
920
|
+
/**
|
|
921
|
+
* The name of the function that decodes a Create object to a fully typed object (e.g. `aggregationCreateDecoder`.)
|
|
922
|
+
*/
|
|
923
|
+
createInputDecoder: Types.VariableName;
|
|
924
|
+
/**
|
|
925
|
+
* The name of the function that decodes an Update object to a fully typed object (e.g. `aggregationUpdateDecoder`.)
|
|
926
|
+
*/
|
|
927
|
+
updateInputDecoder: Types.VariableName;
|
|
928
|
+
/**
|
|
929
|
+
* The name of the function that decodes an Upsert object to a fully typed object (e.g. `aggregationUpsertDecoder`.)
|
|
930
|
+
*/
|
|
931
|
+
upsertInputDecoder: Types.VariableName;
|
|
934
932
|
/**
|
|
935
933
|
* Name by which the business logic service exposes the data service.
|
|
936
934
|
*/
|
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`),
|
|
@@ -325,6 +321,8 @@ function getModelMetadata({ model }) {
|
|
|
325
321
|
serviceVariableName: Types.toVariableName(`${uncapitalizedPlural}`),
|
|
326
322
|
serviceLocation: Types.toModuleLocation(`view`, `${config.paths.businessViewLogicPath}${camelCase}.view.service`),
|
|
327
323
|
dataRepositoryVariableName: Types.toVariableName(`data`),
|
|
324
|
+
cursorDecoder: Types.toVariableName(`CURSOR_DECODER`),
|
|
325
|
+
filterOperatorDecoder: Types.toVariableName(`FILTER_OPERATOR_DECODER`),
|
|
328
326
|
},
|
|
329
327
|
update: {
|
|
330
328
|
scopeName: Types.toVariableName(`${camelCase}`),
|
|
@@ -334,12 +332,9 @@ function getModelMetadata({ model }) {
|
|
|
334
332
|
serviceInterfaceName: Types.toTypeName(`I${PascalCase}UpdateService`),
|
|
335
333
|
serviceVariableName: Types.toVariableName(`${uncapitalizedPlural}`),
|
|
336
334
|
actionModelDiscriminantName: Types.toVariableName(`${camelCase}`),
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
update: Types.toFunctionName(`${camelCase}UpdateDecoder`),
|
|
341
|
-
upsert: Types.toFunctionName(`${camelCase}UpsertDecoder`),
|
|
342
|
-
},
|
|
335
|
+
createInputDecoder: Types.toVariableName(`${camelCase}CreateInputDecoder`),
|
|
336
|
+
updateInputDecoder: Types.toVariableName(`${camelCase}UpdateInputDecoder`),
|
|
337
|
+
upsertInputDecoder: Types.toVariableName(`${camelCase}UpsertInputDecoder`),
|
|
343
338
|
dataRepositoryVariableName: Types.toVariableName(`data`),
|
|
344
339
|
},
|
|
345
340
|
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;
|