@iyio/protogen-runtime 0.0.11 → 0.0.13
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/esm/src/lib/default-plugins.js +42 -0
- package/esm/src/lib/default-plugins.js.map +1 -1
- package/esm/src/lib/plugins/actionPlugin.d.ts +40 -0
- package/esm/src/lib/plugins/actionPlugin.js +97 -0
- package/esm/src/lib/plugins/actionPlugin.js.map +1 -0
- package/esm/src/lib/plugins/assignPlugin.d.ts +20 -0
- package/esm/src/lib/plugins/assignPlugin.js +52 -0
- package/esm/src/lib/plugins/assignPlugin.js.map +1 -0
- package/esm/src/lib/plugins/autoPackageIndexPlugin.js +10 -0
- package/esm/src/lib/plugins/autoPackageIndexPlugin.js.map +1 -1
- package/esm/src/lib/plugins/bucketCdkTemplate.js +4 -2
- package/esm/src/lib/plugins/bucketCdkTemplate.js.map +1 -1
- package/esm/src/lib/plugins/bucketPlugin.js +16 -4
- package/esm/src/lib/plugins/bucketPlugin.js.map +1 -1
- package/esm/src/lib/plugins/callablePlugin.d.ts +40 -0
- package/esm/src/lib/plugins/callablePlugin.js +86 -0
- package/esm/src/lib/plugins/callablePlugin.js.map +1 -0
- package/esm/src/lib/plugins/examplePlugin.js +1 -2
- package/esm/src/lib/plugins/examplePlugin.js.map +1 -1
- package/esm/src/lib/plugins/fileWriter.js +3 -2
- package/esm/src/lib/plugins/fileWriter.js.map +1 -1
- package/esm/src/lib/plugins/functionPlugin.js +37 -8
- package/esm/src/lib/plugins/functionPlugin.js.map +1 -1
- package/esm/src/lib/plugins/nextJsAppPlugin.js +14 -5
- package/esm/src/lib/plugins/nextJsAppPlugin.js.map +1 -1
- package/esm/src/lib/plugins/nextJsAppTemplate.js +18 -0
- package/esm/src/lib/plugins/nextJsAppTemplate.js.map +1 -1
- package/esm/src/lib/plugins/nextJsPagePlugin.d.ts +15 -0
- package/esm/src/lib/plugins/nextJsPagePlugin.js +65 -0
- package/esm/src/lib/plugins/nextJsPagePlugin.js.map +1 -0
- package/esm/src/lib/plugins/reactCompPlugin.js +1 -1
- package/esm/src/lib/plugins/reactCompPlugin.js.map +1 -1
- package/esm/src/lib/plugins/serverFnCdkTemplate.d.ts +2 -1
- package/esm/src/lib/plugins/serverFnCdkTemplate.js +10 -3
- package/esm/src/lib/plugins/serverFnCdkTemplate.js.map +1 -1
- package/esm/src/lib/plugins/serverFnPlugin.d.ts +6 -0
- package/esm/src/lib/plugins/serverFnPlugin.js +87 -23
- package/esm/src/lib/plugins/serverFnPlugin.js.map +1 -1
- package/esm/src/lib/plugins/sqlMigrationCdkTemplate.d.ts +5 -0
- package/esm/src/lib/plugins/sqlMigrationCdkTemplate.js +40 -0
- package/esm/src/lib/plugins/sqlMigrationCdkTemplate.js.map +1 -0
- package/esm/src/lib/plugins/sqlMigrationsPlugin.d.ts +39 -0
- package/esm/src/lib/plugins/sqlMigrationsPlugin.js +114 -0
- package/esm/src/lib/plugins/sqlMigrationsPlugin.js.map +1 -0
- package/esm/src/lib/plugins/sqlTablePlugin.d.ts +64 -0
- package/esm/src/lib/plugins/sqlTablePlugin.js +162 -0
- package/esm/src/lib/plugins/sqlTablePlugin.js.map +1 -0
- package/esm/src/lib/plugins/tablePlugin.js +16 -134
- package/esm/src/lib/plugins/tablePlugin.js.map +1 -1
- package/esm/src/lib/plugins/tsProtoNodePlugin.js +1 -1
- package/esm/src/lib/plugins/tsProtoNodePlugin.js.map +1 -1
- package/esm/src/lib/plugins/userPoolPlugin.js +16 -1
- package/esm/src/lib/plugins/userPoolPlugin.js.map +1 -1
- package/esm/src/lib/plugins/zodPlugin.d.ts +3 -0
- package/esm/src/lib/plugins/zodPlugin.js +151 -33
- package/esm/src/lib/plugins/zodPlugin.js.map +1 -1
- package/esm/src/lib/protogen-table-generator.d.ts +39 -0
- package/esm/src/lib/protogen-table-generator.js +181 -0
- package/esm/src/lib/protogen-table-generator.js.map +1 -0
- package/esm/src/lib/runProtogenCliAsync.js +5 -0
- package/esm/src/lib/runProtogenCliAsync.js.map +1 -1
- package/package.json +18 -10
- package/src/lib/default-plugins.js +42 -0
- package/src/lib/default-plugins.js.map +1 -1
- package/src/lib/plugins/actionPlugin.d.ts +40 -0
- package/src/lib/plugins/actionPlugin.js +100 -0
- package/src/lib/plugins/actionPlugin.js.map +1 -0
- package/src/lib/plugins/assignPlugin.d.ts +20 -0
- package/src/lib/plugins/assignPlugin.js +55 -0
- package/src/lib/plugins/assignPlugin.js.map +1 -0
- package/src/lib/plugins/autoPackageIndexPlugin.js +10 -0
- package/src/lib/plugins/autoPackageIndexPlugin.js.map +1 -1
- package/src/lib/plugins/bucketCdkTemplate.js +4 -2
- package/src/lib/plugins/bucketCdkTemplate.js.map +1 -1
- package/src/lib/plugins/bucketPlugin.js +15 -3
- package/src/lib/plugins/bucketPlugin.js.map +1 -1
- package/src/lib/plugins/callablePlugin.d.ts +40 -0
- package/src/lib/plugins/callablePlugin.js +89 -0
- package/src/lib/plugins/callablePlugin.js.map +1 -0
- package/src/lib/plugins/examplePlugin.js +1 -2
- package/src/lib/plugins/examplePlugin.js.map +1 -1
- package/src/lib/plugins/fileWriter.js +3 -2
- package/src/lib/plugins/fileWriter.js.map +1 -1
- package/src/lib/plugins/functionPlugin.js +36 -7
- package/src/lib/plugins/functionPlugin.js.map +1 -1
- package/src/lib/plugins/nextJsAppPlugin.js +13 -4
- package/src/lib/plugins/nextJsAppPlugin.js.map +1 -1
- package/src/lib/plugins/nextJsAppTemplate.js +18 -0
- package/src/lib/plugins/nextJsAppTemplate.js.map +1 -1
- package/src/lib/plugins/nextJsPagePlugin.d.ts +15 -0
- package/src/lib/plugins/nextJsPagePlugin.js +68 -0
- package/src/lib/plugins/nextJsPagePlugin.js.map +1 -0
- package/src/lib/plugins/reactCompPlugin.js +1 -1
- package/src/lib/plugins/reactCompPlugin.js.map +1 -1
- package/src/lib/plugins/serverFnCdkTemplate.d.ts +2 -1
- package/src/lib/plugins/serverFnCdkTemplate.js +10 -3
- package/src/lib/plugins/serverFnCdkTemplate.js.map +1 -1
- package/src/lib/plugins/serverFnPlugin.d.ts +6 -0
- package/src/lib/plugins/serverFnPlugin.js +85 -21
- package/src/lib/plugins/serverFnPlugin.js.map +1 -1
- package/src/lib/plugins/sqlMigrationCdkTemplate.d.ts +5 -0
- package/src/lib/plugins/sqlMigrationCdkTemplate.js +44 -0
- package/src/lib/plugins/sqlMigrationCdkTemplate.js.map +1 -0
- package/src/lib/plugins/sqlMigrationsPlugin.d.ts +39 -0
- package/src/lib/plugins/sqlMigrationsPlugin.js +117 -0
- package/src/lib/plugins/sqlMigrationsPlugin.js.map +1 -0
- package/src/lib/plugins/sqlTablePlugin.d.ts +64 -0
- package/src/lib/plugins/sqlTablePlugin.js +165 -0
- package/src/lib/plugins/sqlTablePlugin.js.map +1 -0
- package/src/lib/plugins/tablePlugin.js +15 -133
- package/src/lib/plugins/tablePlugin.js.map +1 -1
- package/src/lib/plugins/tsProtoNodePlugin.js +1 -1
- package/src/lib/plugins/tsProtoNodePlugin.js.map +1 -1
- package/src/lib/plugins/userPoolPlugin.js +16 -1
- package/src/lib/plugins/userPoolPlugin.js.map +1 -1
- package/src/lib/plugins/zodPlugin.d.ts +3 -0
- package/src/lib/plugins/zodPlugin.js +149 -31
- package/src/lib/plugins/zodPlugin.js.map +1 -1
- package/src/lib/protogen-table-generator.d.ts +39 -0
- package/src/lib/protogen-table-generator.js +185 -0
- package/src/lib/protogen-table-generator.js.map +1 -0
- package/src/lib/runProtogenCliAsync.js +5 -0
- package/src/lib/runProtogenCliAsync.js.map +1 -1
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { __awaiter, __rest } from "tslib";
|
|
2
|
-
import { joinPaths, notWordRegex } from "@iyio/common";
|
|
3
|
-
import { addTsImport, getProtoPluginPackAndPath, protoAddContextParam, protoFormatTsComment, protoGenerateTsIndex, protoGetChildren, protoGetChildrenByName, protoGetParamName, protoPrependTsImports } from "@iyio/protogen";
|
|
4
2
|
import { z } from "zod";
|
|
5
|
-
import {
|
|
3
|
+
import { generateProtoTable } from "../protogen-table-generator";
|
|
4
|
+
import { SharedTsPluginConfigScheme } from "../sharedTsConfig";
|
|
6
5
|
import { tableCdkTemplate } from "./tableCdkTemplate";
|
|
7
6
|
const TablePluginConfig = z.object({
|
|
8
|
-
/**
|
|
9
|
-
* @default .tablePackage
|
|
10
|
-
*/
|
|
11
7
|
tablePath: z.string().optional(),
|
|
12
8
|
/**
|
|
13
9
|
* @default "tables.ts"
|
|
@@ -45,136 +41,22 @@ const TablePluginConfig = z.object({
|
|
|
45
41
|
}).merge(SharedTsPluginConfigScheme);
|
|
46
42
|
export const tablePlugin = {
|
|
47
43
|
configScheme: TablePluginConfig,
|
|
48
|
-
generate: (
|
|
49
|
-
var
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
addImport('DataTableDescription', dataTableDescriptionPackage);
|
|
60
|
-
addImport('DataTableIndex', dataTableDescriptionPackage);
|
|
61
|
-
}
|
|
62
|
-
log(`${supported.length} supported node(s)`);
|
|
63
|
-
const out = [];
|
|
64
|
-
const tableNames = [];
|
|
65
|
-
const tableInfos = [];
|
|
66
|
-
for (const node of supported) {
|
|
67
|
-
const name = node.name;
|
|
68
|
-
const paramName = protoGetParamName(name + 'Table');
|
|
69
|
-
importMap[name + 'Table'] = packageName;
|
|
70
|
-
importMap[name + 'TableIndexMap'] = packageName;
|
|
71
|
-
tableNames.push(name + 'Table');
|
|
72
|
-
tableInfos.push({ name: name + 'Table', paramName });
|
|
73
|
-
log(`table - ${name}Table`);
|
|
74
|
-
const props = protoGetChildren(node, false);
|
|
75
|
-
out.push('');
|
|
76
|
-
if (node.comment) {
|
|
77
|
-
out.push(protoFormatTsComment(node.comment, ''));
|
|
78
|
-
}
|
|
79
|
-
addImport(name);
|
|
80
|
-
out.push(`export const ${name}Table:DataTableDescription<${name}>={`);
|
|
81
|
-
out.push(`${tab}name:${JSON.stringify(name)},`);
|
|
82
|
-
const primary = props.find(n => { var _a; return (_a = n.children) === null || _a === void 0 ? void 0 : _a['primaryKey']; });
|
|
83
|
-
out.push(`${tab}primaryKey:${primary ? JSON.stringify(primary.name) : '"id"'},`);
|
|
84
|
-
if (tableUseParamIds) {
|
|
85
|
-
protoAddContextParam(name + 'Table', paramPackage, paramMap, importMap);
|
|
86
|
-
addImport(paramName, paramPackage);
|
|
87
|
-
out.push(`${tab}tableIdParam:${paramName},`);
|
|
88
|
-
}
|
|
89
|
-
const config = (_d = (_c = (_b = node.children) === null || _b === void 0 ? void 0 : _b['$table']) === null || _c === void 0 ? void 0 : _c.children) !== null && _d !== void 0 ? _d : {};
|
|
90
|
-
let configValue;
|
|
91
|
-
configValue = (_f = (_e = config['scheme']) === null || _e === void 0 ? void 0 : _e.value) !== null && _f !== void 0 ? _f : getTsSchemeName(name, tsConfig);
|
|
92
|
-
if (importMap[configValue]) {
|
|
93
|
-
addImport(configValue);
|
|
94
|
-
out.push(`${tab}scheme:${configValue},`);
|
|
95
|
-
}
|
|
96
|
-
if (configValue = (_g = config['mountPath']) === null || _g === void 0 ? void 0 : _g.value) {
|
|
97
|
-
out.push(`${tab}mountPath:${JSON.stringify(configValue)},`);
|
|
98
|
-
}
|
|
99
|
-
if (configValue = (_h = config['isReadonly']) === null || _h === void 0 ? void 0 : _h.value) {
|
|
100
|
-
out.push(`${tab}isReadonly:${JSON.stringify(Boolean(configValue))},`);
|
|
101
|
-
}
|
|
102
|
-
if (configValue = (_k = (_j = config['watchable']) === null || _j === void 0 ? void 0 : _j.value) === null || _k === void 0 ? void 0 : _k.replace(notWordRegex, '')) {
|
|
103
|
-
out.push(`${tab}watchable:${JSON.stringify(Boolean(configValue))},`);
|
|
104
|
-
}
|
|
105
|
-
if (configValue = (_m = (_l = config['defaultOrderProp']) === null || _l === void 0 ? void 0 : _l.value) === null || _m === void 0 ? void 0 : _m.replace(notWordRegex, '')) {
|
|
106
|
-
out.push(`${tab}defaultOrderProp:${JSON.stringify(configValue)},`);
|
|
107
|
-
}
|
|
108
|
-
if (configValue = (_p = (_o = config['defaultOrderDesc']) === null || _o === void 0 ? void 0 : _o.value) === null || _p === void 0 ? void 0 : _p.replace(notWordRegex, '')) {
|
|
109
|
-
out.push(`${tab}defaultOrderDesc:${JSON.stringify(Boolean(configValue))},`);
|
|
110
|
-
}
|
|
111
|
-
if (configValue = (_s = (_r = (_q = config['ttlProp']) === null || _q === void 0 ? void 0 : _q.value) === null || _r === void 0 ? void 0 : _r.replace(notWordRegex, '')) !== null && _s !== void 0 ? _s : (_t = props.find(p => p.name === 'ttl')) === null || _t === void 0 ? void 0 : _t.name) {
|
|
112
|
-
out.push(`${tab}ttlProp:${JSON.stringify(configValue)},`);
|
|
113
|
-
}
|
|
114
|
-
if (configValue = (_v = (_u = config['updateVersionProp']) === null || _u === void 0 ? void 0 : _u.value) !== null && _v !== void 0 ? _v : (_w = props.find(p => p.name === 'uv')) === null || _w === void 0 ? void 0 : _w.name) {
|
|
115
|
-
out.push(`${tab}updateVersionProp:${JSON.stringify(configValue)},`);
|
|
116
|
-
}
|
|
117
|
-
const indexes = protoGetChildrenByName((_x = node.children) === null || _x === void 0 ? void 0 : _x['$table'], 'index', false);
|
|
118
|
-
const indexOut = [];
|
|
119
|
-
if (indexes.length) {
|
|
120
|
-
out.push(`${tab}indexes:[`);
|
|
121
|
-
for (let i = 0; i < indexes.length; i++) {
|
|
122
|
-
const index = indexes[i];
|
|
123
|
-
const indexName = index.value || 'index' + i;
|
|
124
|
-
indexOut.push(`${tab}${JSON.stringify(indexName)}:${name}Table.indexes?.[${i}] as DataTableIndex,`);
|
|
125
|
-
out.push(`${tab}${tab}{`);
|
|
126
|
-
out.push(`${tab}${tab}${tab}name:${JSON.stringify(indexName)},`);
|
|
127
|
-
const primaryProp = (_0 = (_z = (_y = index.children) === null || _y === void 0 ? void 0 : _y['primary']) === null || _z === void 0 ? void 0 : _z.value) === null || _0 === void 0 ? void 0 : _0.replace(notWordRegex, '');
|
|
128
|
-
out.push(`${tab}${tab}${tab}primary:${JSON.stringify(primaryProp !== null && primaryProp !== void 0 ? primaryProp : indexName)},`);
|
|
129
|
-
const sortProp = (_3 = (_2 = (_1 = index.children) === null || _1 === void 0 ? void 0 : _1['sort']) === null || _2 === void 0 ? void 0 : _2.value) === null || _3 === void 0 ? void 0 : _3.replace(notWordRegex, '');
|
|
130
|
-
if (sortProp) {
|
|
131
|
-
out.push(`${tab}${tab}${tab}sort:${JSON.stringify(sortProp)},`);
|
|
132
|
-
}
|
|
133
|
-
if ((_4 = index.children) === null || _4 === void 0 ? void 0 : _4['includeAll']) {
|
|
134
|
-
out.push(`${tab}${tab}${tab}includeAll:true,`);
|
|
135
|
-
}
|
|
136
|
-
const includeProps = protoGetChildren((_5 = index.children) === null || _5 === void 0 ? void 0 : _5['include'], false);
|
|
137
|
-
if (includeProps.length) {
|
|
138
|
-
out.push(`${tab}${tab}${tab}include:[`);
|
|
139
|
-
for (const incProp of includeProps) {
|
|
140
|
-
out.push(`${tab}${tab}${tab}${tab}${JSON.stringify(incProp.name)},`);
|
|
141
|
-
}
|
|
142
|
-
out.push(`${tab}${tab}${tab}],`);
|
|
143
|
-
}
|
|
144
|
-
out.push(`${tab}${tab}},`);
|
|
145
|
-
}
|
|
146
|
-
out.push(`${tab}],`);
|
|
147
|
-
}
|
|
148
|
-
out.push('}');
|
|
149
|
-
out.push(`export const ${name}TableIndexMap={`);
|
|
150
|
-
out.push(...indexOut);
|
|
151
|
-
out.push('}');
|
|
152
|
-
}
|
|
153
|
-
importMap[allTableArrayName] = packageName;
|
|
154
|
-
out.push(`export const ${allTableArrayName}=[${tableNames.join(',')}] as const`);
|
|
155
|
-
out.push(`Object.freeze(${allTableArrayName})`);
|
|
156
|
-
if (imports.length) {
|
|
157
|
-
protoPrependTsImports(imports, importMap, out, localImportMap);
|
|
44
|
+
generate: (context, _a) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
+
var { tablePath, tablePackage = 'tables', tableFilename = 'tables.ts', tableIndexFilename = 'tables-index.ts', tableUseParamIds, dataTableDescriptionPackage = '@iyio/common', allTableArrayName = 'allTables', tableCdkConstructClassName = 'Tbls', tableCdkConstructFile = context.libStyle === 'nx' ? `packages/cdk/src/${tableCdkConstructClassName}.ts` : undefined } = _a, tsConfig = __rest(_a, ["tablePath", "tablePackage", "tableFilename", "tableIndexFilename", "tableUseParamIds", "dataTableDescriptionPackage", "allTableArrayName", "tableCdkConstructClassName", "tableCdkConstructFile"]);
|
|
46
|
+
const result = yield generateProtoTable(context, Object.assign({ pluginName: 'tablePlugin', supportedTypes: ['table'], tablePath,
|
|
47
|
+
tablePackage,
|
|
48
|
+
tableFilename,
|
|
49
|
+
tableIndexFilename,
|
|
50
|
+
tableUseParamIds,
|
|
51
|
+
dataTableDescriptionPackage,
|
|
52
|
+
allTableArrayName }, tsConfig));
|
|
53
|
+
if (!result) {
|
|
54
|
+
return;
|
|
158
55
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
outputs.push({
|
|
162
|
-
path: joinPaths(path, tableFilename),
|
|
163
|
-
content: out.join('\n'),
|
|
164
|
-
});
|
|
165
|
-
outputs.push({
|
|
166
|
-
path: joinPaths(path, tableIndexFilename),
|
|
167
|
-
content: '',
|
|
168
|
-
isPackageIndex: true,
|
|
169
|
-
generator: {
|
|
170
|
-
root: path,
|
|
171
|
-
generator: protoGenerateTsIndex
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
if (tableCdkConstructFile) {
|
|
175
|
-
outputs.push({
|
|
56
|
+
if (tableCdkConstructFile && tableCdkConstructClassName) {
|
|
57
|
+
context.outputs.push({
|
|
176
58
|
path: tableCdkConstructFile,
|
|
177
|
-
content: tableCdkTemplate(tableCdkConstructClassName, tableInfos, importMap)
|
|
59
|
+
content: tableCdkTemplate(tableCdkConstructClassName, result.tableInfos, context.importMap)
|
|
178
60
|
});
|
|
179
61
|
}
|
|
180
62
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tablePlugin.js","sourceRoot":"","sources":["../../../../../../../packages/protogen-runtime/src/lib/plugins/tablePlugin.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"tablePlugin.js","sourceRoot":"","sources":["../../../../../../../packages/protogen-runtime/src/lib/plugins/tablePlugin.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,iBAAiB,GAAC,CAAC,CAAC,MAAM,CAChC;IACI,SAAS,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAE/B;;OAEG;IACH,aAAa,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAEnC;;OAEG;IACH,kBAAkB,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAGxC;;OAEG;IACH,YAAY,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAElC;;OAEG;IACH,gBAAgB,EAAC,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAEvC;;OAEG;IACH,2BAA2B,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAEjD;;OAEG;IACH,iBAAiB,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAEvC;;;OAGG;IACH,qBAAqB,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAE3C;;OAEG;IACH,0BAA0B,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAInD,CAAC,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;AAErC,MAAM,CAAC,MAAM,WAAW,GACxB;IACI,YAAY,EAAC,iBAAiB;IAE9B,QAAQ,EAAC,CAAO,OAAO,EAAC,EAWvB,EAAC,EAAE;YAXoB,EACpB,SAAS,EACT,YAAY,GAAC,QAAQ,EACrB,aAAa,GAAC,WAAW,EACzB,kBAAkB,GAAC,iBAAiB,EACpC,gBAAgB,EAChB,2BAA2B,GAAC,cAAc,EAC1C,iBAAiB,GAAC,WAAW,EAC7B,0BAA0B,GAAC,MAAM,EACjC,qBAAqB,GAAC,OAAO,CAAC,QAAQ,KAAG,IAAI,CAAA,CAAC,CAAA,oBAAoB,0BAA0B,KAAK,CAAA,CAAC,CAAA,SAAS,OAE9G,EADM,QAAQ,cAVS,mMAWvB,CADc;QAGX,MAAM,MAAM,GAAC,MAAM,kBAAkB,CAAC,OAAO,kBACzC,UAAU,EAAC,aAAa,EACxB,cAAc,EAAC,CAAC,OAAO,CAAC,EACxB,SAAS;YACT,YAAY;YACZ,aAAa;YACb,kBAAkB;YAClB,gBAAgB;YAChB,2BAA2B;YAC3B,iBAAiB,IACd,QAAQ,EACb,CAAA;QAEF,IAAG,CAAC,MAAM,EAAC;YACP,OAAO;SACV;QAED,IAAG,qBAAqB,IAAI,0BAA0B,EAAC;YACnD,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;gBACjB,IAAI,EAAC,qBAAqB;gBAC1B,OAAO,EAAC,gBAAgB,CAAC,0BAA0B,EAAC,MAAM,CAAC,UAAU,EAAC,OAAO,CAAC,SAAS,CAAC;aAC3F,CAAC,CAAA;SACL;IACL,CAAC,CAAA;CACJ,CAAA"}
|
|
@@ -38,7 +38,7 @@ export const tsProtoNodePlugin = {
|
|
|
38
38
|
path: joinPaths(path, tsProtoNodeFilename),
|
|
39
39
|
content: `import { ProtoAddressMap } from '@iyio/protogen';
|
|
40
40
|
|
|
41
|
-
export const ${tsProtoNodeExportName}=${JSON.stringify(protoCreateNodeAddressMap(protoRemoveDisplayChildren(deepClone(nodes))), null, tsProtoNodeMinify ? 0 : tab.length)} satisfies ProtoAddressMap;`,
|
|
41
|
+
export const ${tsProtoNodeExportName}=${JSON.stringify(protoCreateNodeAddressMap(protoRemoveDisplayChildren(deepClone(nodes, 1000))), null, tsProtoNodeMinify ? 0 : tab.length)} satisfies ProtoAddressMap;`,
|
|
42
42
|
});
|
|
43
43
|
outputs.push({
|
|
44
44
|
path: joinPaths(path, tsProtoNodeIndexFilename),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tsProtoNodePlugin.js","sourceRoot":"","sources":["../../../../../../../packages/protogen-runtime/src/lib/plugins/tsProtoNodePlugin.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,
|
|
1
|
+
{"version":3,"file":"tsProtoNodePlugin.js","sourceRoot":"","sources":["../../../../../../../packages/protogen-runtime/src/lib/plugins/tsProtoNodePlugin.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAmC,yBAAyB,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AACzK,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,uBAAuB,GAAC,CAAC,CAAC,MAAM,CACtC;IACI;;OAEG;IACH,eAAe,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAErC;;OAEG;IACH,kBAAkB,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAExC;;OAEG;IACH,mBAAmB,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAEzC;;OAEG;IACH,wBAAwB,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAE9C;;OAEG;IACH,qBAAqB,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAE3C;;OAEG;IACH,iBAAiB,EAAC,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CAC3C,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAC9B;IACI,YAAY,EAAC,uBAAuB;IACpC,QAAQ,EAAC,CAAO,EACZ,SAAS,EACT,OAAO,EACP,GAAG,EACH,GAAG,EACH,KAAK,EACL,SAAS,EACT,QAAQ,EACR,YAAY,EACf,EAAC,EACE,kBAAkB,GAAC,aAAa,EAChC,eAAe,GAAC,kBAAkB,EAClC,mBAAmB,GAAC,eAAe,EACnC,qBAAqB,GAAC,YAAY,EAClC,wBAAwB,GAAC,kBAAkB,EAC3C,iBAAiB,GAAC,KAAK,GAC1B,EAAC,EAAE;QAEA,MAAM,EAAC,IAAI,EAAC,WAAW,EAAC,GAAC,yBAAyB,CAC9C,SAAS,EACT,kBAAkB,EAClB,eAAe,EACf,QAAQ,EACR,EAAC,YAAY,EAAC,aAAa,EAAC,wBAAwB,EAAC,CACxD,CAAC;QAEF,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,UAAU,CAAC,CAAC;QAE/B,SAAS,CAAC,qBAAqB,CAAC,GAAC,WAAW,CAAC;QAE7C,OAAO,CAAC,IAAI,CAAC;YACT,IAAI,EAAC,SAAS,CAAC,IAAI,EAAC,mBAAmB,CAAC;YACxC,OAAO,EACnB;;eAEe,qBAAqB,IAAI,IAAI,CAAC,SAAS,CAClD,yBAAyB,CAAC,0BAA0B,CAAC,SAAS,CAAC,KAAK,EAAC,IAAI,CAAC,CAAC,CAAC,EAChF,IAAI,EAAC,iBAAiB,CAAA,CAAC,CAAA,CAAC,CAAA,CAAC,CAAA,GAAG,CAAC,MAAM,CAAC,6BAA6B;SACxD,CAAC,CAAA;QAEF,OAAO,CAAC,IAAI,CAAC;YACT,IAAI,EAAC,SAAS,CAAC,IAAI,EAAC,wBAAwB,CAAC;YAC7C,OAAO,EAAC,EAAE;YACV,cAAc,EAAC,IAAI;YACnB,SAAS,EAAC;gBACN,IAAI,EAAC,IAAI;gBACT,SAAS,EAAC,oBAAoB;aACjC;SACJ,CAAC,CAAA;IAEN,CAAC,CAAA;CACJ,CAAA"}
|
|
@@ -32,7 +32,7 @@ export const userPoolPlugin = {
|
|
|
32
32
|
//userPoolPath=userPoolPackage,
|
|
33
33
|
//userPoolIndexFilename='user-pool-index.ts',
|
|
34
34
|
userPoolCdkConstructClassName = 'UsrPool', userPoolCdkConstructFile = libStyle === 'nx' ? `packages/cdk/src/${userPoolCdkConstructClassName}.ts` : undefined, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
-
var _a, _b, _c, _d;
|
|
35
|
+
var _a, _b, _c, _d, _e, _f;
|
|
36
36
|
const supported = nodes.filter(n => supportedTypes.some(t => n.types.some(nt => nt.type === t)));
|
|
37
37
|
log(`${supported.length} supported node(s)`);
|
|
38
38
|
if (!supported.length) {
|
|
@@ -41,11 +41,26 @@ export const userPoolPlugin = {
|
|
|
41
41
|
if (userPoolCdkConstructFile) {
|
|
42
42
|
const access = (_b = (_a = supported[0]) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b['$access'];
|
|
43
43
|
const anon = (_d = (_c = supported[0]) === null || _c === void 0 ? void 0 : _c.children) === null || _d === void 0 ? void 0 : _d['$anon-access'];
|
|
44
|
+
const triggersNode = (_f = (_e = supported[0]) === null || _e === void 0 ? void 0 : _e.children) === null || _f === void 0 ? void 0 : _f['$userPoolTriggers'];
|
|
45
|
+
const triggers = triggersNode ? {} : undefined;
|
|
46
|
+
if ((triggersNode === null || triggersNode === void 0 ? void 0 : triggersNode.children) && triggers) {
|
|
47
|
+
for (const name in triggersNode.children) {
|
|
48
|
+
const tNode = triggersNode.children[name];
|
|
49
|
+
if (!tNode) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (!nodes.find(n => n.name === tNode.type)) {
|
|
53
|
+
throw new Error(`No type found for trigger. trigger:${name}, type:${tNode.type}`);
|
|
54
|
+
}
|
|
55
|
+
triggers[name] = tNode.type;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
44
58
|
outputs.push({
|
|
45
59
|
path: userPoolCdkConstructFile,
|
|
46
60
|
content: userPoolCdkTemplate(userPoolCdkConstructClassName, {
|
|
47
61
|
authorizedAccessRequests: access ? protoNodeChildrenToAccessRequests(access) : undefined,
|
|
48
62
|
unauthorizedAccessRequests: anon ? protoNodeChildrenToAccessRequests(anon) : undefined,
|
|
63
|
+
triggers
|
|
49
64
|
})
|
|
50
65
|
});
|
|
51
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userPoolPlugin.js","sourceRoot":"","sources":["../../../../../../../packages/protogen-runtime/src/lib/plugins/userPoolPlugin.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"userPoolPlugin.js","sourceRoot":"","sources":["../../../../../../../packages/protogen-runtime/src/lib/plugins/userPoolPlugin.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ProtoPipelineConfigurablePlugin } from "@iyio/protogen";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
declare const ZodPluginConfig: z.ZodObject<{
|
|
4
|
+
longStringProps: z.ZodOptional<z.ZodString>;
|
|
4
5
|
zodPath: z.ZodOptional<z.ZodString>;
|
|
5
6
|
zodFilename: z.ZodOptional<z.ZodString>;
|
|
6
7
|
zodIndexFilename: z.ZodOptional<z.ZodString>;
|
|
@@ -8,6 +9,7 @@ declare const ZodPluginConfig: z.ZodObject<{
|
|
|
8
9
|
tsSchemePrefix: z.ZodOptional<z.ZodString>;
|
|
9
10
|
tsSchemeSuffix: z.ZodOptional<z.ZodString>;
|
|
10
11
|
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
longStringProps?: string | undefined;
|
|
11
13
|
zodPath?: string | undefined;
|
|
12
14
|
zodFilename?: string | undefined;
|
|
13
15
|
zodIndexFilename?: string | undefined;
|
|
@@ -15,6 +17,7 @@ declare const ZodPluginConfig: z.ZodObject<{
|
|
|
15
17
|
tsSchemePrefix?: string | undefined;
|
|
16
18
|
tsSchemeSuffix?: string | undefined;
|
|
17
19
|
}, {
|
|
20
|
+
longStringProps?: string | undefined;
|
|
18
21
|
zodPath?: string | undefined;
|
|
19
22
|
zodFilename?: string | undefined;
|
|
20
23
|
zodIndexFilename?: string | undefined;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { __awaiter, __rest } from "tslib";
|
|
2
2
|
import { asArray, getObjKeyCount, joinPaths } from "@iyio/common";
|
|
3
|
-
import { getProtoPluginPackAndPath, protoChildrenToArray, protoFormatTsComment, protoGenerateTsIndex, protoTsBuiltTypes, protoTsNumTypes, protoTsTypeMap } from "@iyio/protogen";
|
|
3
|
+
import { getProtoPluginPackAndPath, protoChildrenToArray, protoFormatTsComment, protoGenerateTsIndex, protoGetChildrenByName, protoTsBuiltTypes, protoTsNumTypes, protoTsTypeMap } from "@iyio/protogen";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
-
import {
|
|
5
|
+
import { SharedTsPluginConfigScheme, getTsSchemeName } from "../sharedTsConfig";
|
|
6
6
|
const ZodPluginConfig = z.object({
|
|
7
7
|
/**
|
|
8
8
|
* @default .zodPackage
|
|
@@ -20,12 +20,18 @@ const ZodPluginConfig = z.object({
|
|
|
20
20
|
* @default "types"
|
|
21
21
|
*/
|
|
22
22
|
zodPackage: z.string().optional(),
|
|
23
|
+
/**
|
|
24
|
+
* A comma separated list of properties that should be converted as long strings.
|
|
25
|
+
*/
|
|
26
|
+
longStringProps: z.string().optional(),
|
|
23
27
|
}).merge(SharedTsPluginConfigScheme);
|
|
24
28
|
export const zodPlugin = {
|
|
25
29
|
configScheme: ZodPluginConfig,
|
|
26
30
|
generate: ({ log, nodes, outputs, importMap, tab, packagePaths, namespace, libStyle, }, _a) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
-
var
|
|
31
|
+
var _b, _c;
|
|
32
|
+
var { zodFilename = 'types.ts', zodPackage = 'types', zodIndexFilename = 'types-index.ts', zodPath, longStringProps } = _a, tsConfig = __rest(_a, ["zodFilename", "zodPackage", "zodIndexFilename", "zodPath", "longStringProps"]);
|
|
28
33
|
const { path, packageName } = getProtoPluginPackAndPath(namespace, zodPackage, zodPath, libStyle, { packagePaths, indexFilename: zodIndexFilename });
|
|
34
|
+
const autoLong = longStringProps ? longStringProps.split(',').map(s => s.trim()) : [];
|
|
29
35
|
log(`zodPlugin. node count = ${nodes.length}`);
|
|
30
36
|
const getFullName = (name) => getTsSchemeName(name, tsConfig);
|
|
31
37
|
const out = [];
|
|
@@ -34,30 +40,66 @@ export const zodPlugin = {
|
|
|
34
40
|
out.push(`// generator = zodPlugin`);
|
|
35
41
|
out.push(`import { z } from 'zod';`);
|
|
36
42
|
for (const node of nodes) {
|
|
37
|
-
let
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
let anyAdded = false;
|
|
44
|
+
for (const nodeType of node.types) {
|
|
45
|
+
let added = true;
|
|
46
|
+
let nodeName = node.name;
|
|
47
|
+
switch (nodeType.type) {
|
|
48
|
+
case 'union':
|
|
49
|
+
addUnion(node, out, tab, getFullName);
|
|
50
|
+
break;
|
|
51
|
+
case 'enum':
|
|
52
|
+
addEnum(node, out, tab, getFullName);
|
|
53
|
+
break;
|
|
54
|
+
case 'array':
|
|
55
|
+
nodeName = addArray(node, out, tab);
|
|
56
|
+
break;
|
|
57
|
+
case 'map':
|
|
58
|
+
nodeName = addMap(node, out, tab);
|
|
59
|
+
break;
|
|
60
|
+
case 'function':
|
|
61
|
+
nodeName = node.name + 'FunctionArgs';
|
|
62
|
+
addInterface(Object.assign(Object.assign({}, (_c = (_b = node.children) === null || _b === void 0 ? void 0 : _b['args']) !== null && _c !== void 0 ? _c : {
|
|
63
|
+
name: 'args',
|
|
64
|
+
type: '',
|
|
65
|
+
address: '',
|
|
66
|
+
types: []
|
|
67
|
+
}), { name: nodeName }), out, tab, autoLong, getFullName, useCustomTypes);
|
|
68
|
+
break;
|
|
69
|
+
case 'serverFn':
|
|
70
|
+
nodeName = 'invoke' + node.name + 'FunctionArgs';
|
|
71
|
+
addInterface(Object.assign(Object.assign({}, node), { name: nodeName }), out, tab, autoLong, getFullName, useCustomTypes, prop => prop.name === 'input');
|
|
72
|
+
break;
|
|
73
|
+
case 'entity':
|
|
74
|
+
case 'struct':
|
|
75
|
+
case 'interface':
|
|
76
|
+
case 'class':
|
|
77
|
+
case 'event':
|
|
78
|
+
case 'type':
|
|
79
|
+
addInterface(node, out, tab, autoLong, getFullName, useCustomTypes);
|
|
80
|
+
break;
|
|
81
|
+
default:
|
|
82
|
+
added = false;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
if (added) {
|
|
86
|
+
anyAdded = true;
|
|
87
|
+
if (importMap[nodeName] === packageName) {
|
|
88
|
+
throw new Error(`Export conflict. ${nodeName} already exported from ${packageName}`);
|
|
89
|
+
}
|
|
90
|
+
importMap[nodeName] = packageName;
|
|
91
|
+
const fullName = getFullName(nodeName);
|
|
92
|
+
if (fullName !== nodeName) {
|
|
93
|
+
importMap[fullName] = packageName;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
55
96
|
}
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
97
|
+
if (anyAdded) {
|
|
98
|
+
const names = addAlias(node, out, tab);
|
|
99
|
+
if (names) {
|
|
100
|
+
for (const name of names) {
|
|
101
|
+
importMap[name] = packageName;
|
|
102
|
+
}
|
|
61
103
|
}
|
|
62
104
|
}
|
|
63
105
|
}
|
|
@@ -111,7 +153,81 @@ const addUnion = (node, out, tab, getFullName) => {
|
|
|
111
153
|
out.push(`]);`);
|
|
112
154
|
out.push(`export type ${node.name}=z.infer<typeof ${fullName}>;`);
|
|
113
155
|
};
|
|
114
|
-
const
|
|
156
|
+
const addAlias = (node, out, tab) => {
|
|
157
|
+
var _a;
|
|
158
|
+
let hasAlias = false;
|
|
159
|
+
const toAlias = {};
|
|
160
|
+
const fromAlias = {};
|
|
161
|
+
const aliasList = [];
|
|
162
|
+
if (node.children) {
|
|
163
|
+
for (const name in node.children) {
|
|
164
|
+
const child = node.children[name];
|
|
165
|
+
if (child.isContent || child.special) {
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
const aliases = protoGetChildrenByName(child, 'alias', false);
|
|
169
|
+
if (aliases.length) {
|
|
170
|
+
hasAlias = true;
|
|
171
|
+
for (const a of aliases) {
|
|
172
|
+
const alias = (_a = a.value) !== null && _a !== void 0 ? _a : '';
|
|
173
|
+
if (aliasList.includes(alias)) {
|
|
174
|
+
throw new Error(`Alias (${alias}) already included for type (${node.name})`);
|
|
175
|
+
}
|
|
176
|
+
aliasList.push(alias);
|
|
177
|
+
let record = toAlias[child.name];
|
|
178
|
+
if (!record) {
|
|
179
|
+
record = { default: alias, all: [] };
|
|
180
|
+
toAlias[child.name] = record;
|
|
181
|
+
}
|
|
182
|
+
record.all.push(alias);
|
|
183
|
+
record = fromAlias[alias];
|
|
184
|
+
if (!record) {
|
|
185
|
+
record = { default: child.name, all: [] };
|
|
186
|
+
fromAlias[alias] = record;
|
|
187
|
+
}
|
|
188
|
+
record.all.push(child.name);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (hasAlias) {
|
|
194
|
+
out.push(`export const ${node.name}ToAlias=${JSON.stringify(toAlias, null, tab)}`);
|
|
195
|
+
out.push(`export const ${node.name}FromAlias=${JSON.stringify(fromAlias, null, tab)}`);
|
|
196
|
+
return [`${node.name}ToAlias`, `${node.name}FromAlias`];
|
|
197
|
+
}
|
|
198
|
+
return null;
|
|
199
|
+
};
|
|
200
|
+
const addArray = (node, out, tab) => {
|
|
201
|
+
out.push('');
|
|
202
|
+
out.push(`export const ${node.name}Ary=[`);
|
|
203
|
+
if (node.children) {
|
|
204
|
+
for (const name in node.children) {
|
|
205
|
+
const child = node.children[name];
|
|
206
|
+
if (child.isContent || child.special) {
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
out.push(`${tab}${JSON.stringify(child.name)},`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
out.push(`];`);
|
|
213
|
+
return node.name + 'Ary';
|
|
214
|
+
};
|
|
215
|
+
const addMap = (node, out, tab) => {
|
|
216
|
+
out.push('');
|
|
217
|
+
out.push(`export const ${node.name}Map={`);
|
|
218
|
+
if (node.children) {
|
|
219
|
+
for (const name in node.children) {
|
|
220
|
+
const child = node.children[name];
|
|
221
|
+
if (child.isContent || child.special) {
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
out.push(`${tab}${JSON.stringify(child.name)}:${JSON.stringify(child.value || child.name)},`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
out.push(`};`);
|
|
228
|
+
return node.name + 'Map';
|
|
229
|
+
};
|
|
230
|
+
const addInterface = (node, out, tab, autoLong, getFullName, useCustomTypes, propFilter) => {
|
|
115
231
|
var _a, _b, _c, _d, _e;
|
|
116
232
|
const fullName = getFullName(node.name);
|
|
117
233
|
const children = protoChildrenToArray(node.children);
|
|
@@ -127,21 +243,21 @@ const addInterface = (node, out, tab, getFullName, useCustomTypes) => {
|
|
|
127
243
|
const lazyProps = [];
|
|
128
244
|
if (node.children) {
|
|
129
245
|
for (const prop of children) {
|
|
130
|
-
if (prop.special || prop.isContent) {
|
|
246
|
+
if (prop.special || prop.isContent || (propFilter && !propFilter(prop))) {
|
|
131
247
|
continue;
|
|
132
248
|
}
|
|
133
249
|
const propType = (_b = (_a = protoTsTypeMap[prop.type]) !== null && _a !== void 0 ? _a : prop.type) !== null && _b !== void 0 ? _b : 'string';
|
|
134
250
|
const isBuiltIn = isBuiltInType(propType);
|
|
135
251
|
if (!isBuiltIn) {
|
|
136
252
|
interfaceProps.push(`${prop.comment ? protoFormatTsComment(prop.comment, tab) + '\n' : ''}${tab}${prop.name}${prop.optional ? '?' : ''}:${propType}${((_c = prop.types[0]) === null || _c === void 0 ? void 0 : _c.isArray) ? '[]' : ''};`);
|
|
137
|
-
lazyProps.push(`${tab}${prop.name}:z.lazy(()=>${getFullName(propType)})${((_d = prop.types[0]) === null || _d === void 0 ? void 0 : _d.isArray) ? '.array()' : ''}${getFormatCalls(prop, propType)}${prop.optional ? '.optional()' : ''},`);
|
|
253
|
+
lazyProps.push(`${tab}${prop.name}:z.lazy(()=>${getFullName(propType)})${((_d = prop.types[0]) === null || _d === void 0 ? void 0 : _d.isArray) ? '.array()' : ''}${getFormatCalls(prop, propType, autoLong)}${prop.optional ? '.optional()' : ''},`);
|
|
138
254
|
continue;
|
|
139
255
|
}
|
|
140
256
|
const customType = getRealCustomType(propType);
|
|
141
257
|
if (customType && !useCustomTypes.includes(propType)) {
|
|
142
258
|
useCustomTypes.push(propType);
|
|
143
259
|
}
|
|
144
|
-
out.push(`${prop.comment ? protoFormatTsComment(prop.comment, tab) + '\n' : ''}${tab}${prop.name}:${customType || `z.${propType}()${getFormatCalls(prop, propType)}`}${((_e = prop.types[0]) === null || _e === void 0 ? void 0 : _e.isArray) ? '.array()' : ''}${prop.optional ? '.optional()' : ''},`);
|
|
260
|
+
out.push(`${prop.comment ? protoFormatTsComment(prop.comment, tab) + '\n' : ''}${tab}${prop.name}:${customType || `z.${propType}()${getFormatCalls(prop, propType, autoLong)}`}${((_e = prop.types[0]) === null || _e === void 0 ? void 0 : _e.isArray) ? '.array()' : ''}${prop.optional ? '.optional()' : ''},`);
|
|
145
261
|
}
|
|
146
262
|
}
|
|
147
263
|
out.push('});');
|
|
@@ -167,9 +283,10 @@ const addInterface = (node, out, tab, getFullName, useCustomTypes) => {
|
|
|
167
283
|
out.push(`export type ${node.name}=z.infer<typeof ${hasCustoms ? '__base__' : ''}${fullName}>;`);
|
|
168
284
|
}
|
|
169
285
|
};
|
|
170
|
-
const customBuiltIns = ['stringMap', 'numberMap', 'booleanMap', 'dateMap', 'bigIntMap'];
|
|
286
|
+
const customBuiltIns = ['map', 'stringMap', 'numberMap', 'booleanMap', 'dateMap', 'bigIntMap'];
|
|
171
287
|
const getRealCustomType = (type) => {
|
|
172
288
|
switch (type) {
|
|
289
|
+
case 'map': return 'z.record(z.any())';
|
|
173
290
|
case 'stringMap': return 'z.record(z.string())';
|
|
174
291
|
case 'numberMap': return 'z.record(z.number())';
|
|
175
292
|
case 'booleanMap': return 'z.record(z.boolean())';
|
|
@@ -181,7 +298,7 @@ const getRealCustomType = (type) => {
|
|
|
181
298
|
const isBuiltInType = (type) => {
|
|
182
299
|
return protoTsBuiltTypes.includes(type) || customBuiltIns.includes(type);
|
|
183
300
|
};
|
|
184
|
-
const getFormatCalls = (prop, propType) => {
|
|
301
|
+
const getFormatCalls = (prop, propType, autoLong) => {
|
|
185
302
|
var _a, _b, _c;
|
|
186
303
|
let call = '';
|
|
187
304
|
const add = (type, name, att, getValue, { defaultValue, hasMessage = true, rawValue, option } = {}) => {
|
|
@@ -215,10 +332,11 @@ const getFormatCalls = (prop, propType) => {
|
|
|
215
332
|
if (!noAutoLength &&
|
|
216
333
|
propType === 'string' &&
|
|
217
334
|
!attChildren['max'] &&
|
|
335
|
+
!autoLong.includes(prop.name) &&
|
|
218
336
|
!parseBool((_c = attChildren['long']) === null || _c === void 0 ? void 0 : _c.value, false)) {
|
|
219
337
|
call += '.max(255)';
|
|
220
338
|
}
|
|
221
|
-
if (
|
|
339
|
+
if (prop.type === 'int' && !attChildren['int']) {
|
|
222
340
|
call += '.int()';
|
|
223
341
|
}
|
|
224
342
|
add(['string', ...protoTsNumTypes], 'min', attChildren['min'], att => parseNum(att.value));
|