@iyio/protogen-runtime 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 +7 -0
- package/esm/package.json +3 -0
- package/esm/src/index.d.ts +12 -0
- package/esm/src/index.js +13 -0
- package/esm/src/index.js.map +1 -0
- package/esm/src/lib/default-plugins.d.ts +2 -0
- package/esm/src/lib/default-plugins.js +74 -0
- package/esm/src/lib/default-plugins.js.map +1 -0
- package/esm/src/lib/plugins/examplePlugin.d.ts +26 -0
- package/esm/src/lib/plugins/examplePlugin.js +65 -0
- package/esm/src/lib/plugins/examplePlugin.js.map +1 -0
- package/esm/src/lib/plugins/fileReader.d.ts +2 -0
- package/esm/src/lib/plugins/fileReader.js +22 -0
- package/esm/src/lib/plugins/fileReader.js.map +1 -0
- package/esm/src/lib/plugins/fileWriter.d.ts +2 -0
- package/esm/src/lib/plugins/fileWriter.js +57 -0
- package/esm/src/lib/plugins/fileWriter.js.map +1 -0
- package/esm/src/lib/plugins/functionPlugin.d.ts +26 -0
- package/esm/src/lib/plugins/functionPlugin.js +79 -0
- package/esm/src/lib/plugins/functionPlugin.js.map +1 -0
- package/esm/src/lib/plugins/markdownParser.d.ts +2 -0
- package/esm/src/lib/plugins/markdownParser.js +15 -0
- package/esm/src/lib/plugins/markdownParser.js.map +1 -0
- package/esm/src/lib/plugins/reactCompPlugin.d.ts +32 -0
- package/esm/src/lib/plugins/reactCompPlugin.js +167 -0
- package/esm/src/lib/plugins/reactCompPlugin.js.map +1 -0
- package/esm/src/lib/plugins/serverFnPlugin.d.ts +68 -0
- package/esm/src/lib/plugins/serverFnPlugin.js +158 -0
- package/esm/src/lib/plugins/serverFnPlugin.js.map +1 -0
- package/esm/src/lib/plugins/tablePlugin.d.ts +38 -0
- package/esm/src/lib/plugins/tablePlugin.js +176 -0
- package/esm/src/lib/plugins/tablePlugin.js.map +1 -0
- package/esm/src/lib/plugins/tsConfigPathsPlugin.d.ts +14 -0
- package/esm/src/lib/plugins/tsConfigPathsPlugin.js +49 -0
- package/esm/src/lib/plugins/tsConfigPathsPlugin.js.map +1 -0
- package/esm/src/lib/plugins/tsExternalExecutor.d.ts +2 -0
- package/esm/src/lib/plugins/tsExternalExecutor.js +55 -0
- package/esm/src/lib/plugins/tsExternalExecutor.js.map +1 -0
- package/esm/src/lib/plugins/zodPlugin.d.ts +26 -0
- package/esm/src/lib/plugins/zodPlugin.js +330 -0
- package/esm/src/lib/plugins/zodPlugin.js.map +1 -0
- package/esm/src/lib/protogen-cli-entry.d.ts +1 -0
- package/esm/src/lib/protogen-cli-entry.js +6 -0
- package/esm/src/lib/protogen-cli-entry.js.map +1 -0
- package/esm/src/lib/protogen-runtime.d.ts +5 -0
- package/esm/src/lib/protogen-runtime.js +63 -0
- package/esm/src/lib/protogen-runtime.js.map +1 -0
- package/esm/src/lib/runProtogenCliAsync.d.ts +12 -0
- package/esm/src/lib/runProtogenCliAsync.js +99 -0
- package/esm/src/lib/runProtogenCliAsync.js.map +1 -0
- package/esm/src/lib/sharedTsConfig.d.ts +18 -0
- package/esm/src/lib/sharedTsConfig.js +12 -0
- package/esm/src/lib/sharedTsConfig.js.map +1 -0
- package/esm/src/lib/test-plugins/echo-generator.d.ts +1 -0
- package/esm/src/lib/test-plugins/echo-generator.js +12 -0
- package/esm/src/lib/test-plugins/echo-generator.js.map +1 -0
- package/package.json +20 -0
- package/src/index.d.ts +12 -0
- package/src/index.js +16 -0
- package/src/index.js.map +1 -0
- package/src/lib/default-plugins.d.ts +2 -0
- package/src/lib/default-plugins.js +78 -0
- package/src/lib/default-plugins.js.map +1 -0
- package/src/lib/plugins/examplePlugin.d.ts +26 -0
- package/src/lib/plugins/examplePlugin.js +68 -0
- package/src/lib/plugins/examplePlugin.js.map +1 -0
- package/src/lib/plugins/fileReader.d.ts +2 -0
- package/src/lib/plugins/fileReader.js +26 -0
- package/src/lib/plugins/fileReader.js.map +1 -0
- package/src/lib/plugins/fileWriter.d.ts +2 -0
- package/src/lib/plugins/fileWriter.js +61 -0
- package/src/lib/plugins/fileWriter.js.map +1 -0
- package/src/lib/plugins/functionPlugin.d.ts +26 -0
- package/src/lib/plugins/functionPlugin.js +82 -0
- package/src/lib/plugins/functionPlugin.js.map +1 -0
- package/src/lib/plugins/markdownParser.d.ts +2 -0
- package/src/lib/plugins/markdownParser.js +19 -0
- package/src/lib/plugins/markdownParser.js.map +1 -0
- package/src/lib/plugins/reactCompPlugin.d.ts +32 -0
- package/src/lib/plugins/reactCompPlugin.js +170 -0
- package/src/lib/plugins/reactCompPlugin.js.map +1 -0
- package/src/lib/plugins/serverFnPlugin.d.ts +68 -0
- package/src/lib/plugins/serverFnPlugin.js +161 -0
- package/src/lib/plugins/serverFnPlugin.js.map +1 -0
- package/src/lib/plugins/tablePlugin.d.ts +38 -0
- package/src/lib/plugins/tablePlugin.js +179 -0
- package/src/lib/plugins/tablePlugin.js.map +1 -0
- package/src/lib/plugins/tsConfigPathsPlugin.d.ts +14 -0
- package/src/lib/plugins/tsConfigPathsPlugin.js +52 -0
- package/src/lib/plugins/tsConfigPathsPlugin.js.map +1 -0
- package/src/lib/plugins/tsExternalExecutor.d.ts +2 -0
- package/src/lib/plugins/tsExternalExecutor.js +58 -0
- package/src/lib/plugins/tsExternalExecutor.js.map +1 -0
- package/src/lib/plugins/zodPlugin.d.ts +26 -0
- package/src/lib/plugins/zodPlugin.js +333 -0
- package/src/lib/plugins/zodPlugin.js.map +1 -0
- package/src/lib/protogen-cli-entry.d.ts +1 -0
- package/src/lib/protogen-cli-entry.js +8 -0
- package/src/lib/protogen-cli-entry.js.map +1 -0
- package/src/lib/protogen-runtime.d.ts +5 -0
- package/src/lib/protogen-runtime.js +69 -0
- package/src/lib/protogen-runtime.js.map +1 -0
- package/src/lib/runProtogenCliAsync.d.ts +12 -0
- package/src/lib/runProtogenCliAsync.js +103 -0
- package/src/lib/runProtogenCliAsync.js.map +1 -0
- package/src/lib/sharedTsConfig.d.ts +18 -0
- package/src/lib/sharedTsConfig.js +16 -0
- package/src/lib/sharedTsConfig.js.map +1 -0
- package/src/lib/test-plugins/echo-generator.d.ts +1 -0
- package/src/lib/test-plugins/echo-generator.js +14 -0
- package/src/lib/test-plugins/echo-generator.js.map +1 -0
- package/src/package.json +4 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { joinPaths, requireUnrootPath } from "@iyio/common";
|
|
3
|
+
import { addTsImport, getProtoPluginPackAndPath, protoFormatTsComment, protoGenerateTsIndex, protoGetTsType, protoIsTsBuiltType, protoLabelOutputLines, protoMergeTsImports, protoPrependTsImports } from "@iyio/protogen";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
const supportedTypes = ['comp', 'view', 'screen'];
|
|
6
|
+
const ReactCompPluginConfig = z.object({
|
|
7
|
+
/**
|
|
8
|
+
* @default .reactPackage
|
|
9
|
+
*/
|
|
10
|
+
reactCompPath: z.string().optional(),
|
|
11
|
+
/**
|
|
12
|
+
* @default "react-comp-index.ts"
|
|
13
|
+
*/
|
|
14
|
+
reactCompIndexFilename: z.string().optional(),
|
|
15
|
+
/**
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
18
|
+
reactCompUseStyledJsx: z.boolean().optional(),
|
|
19
|
+
/**
|
|
20
|
+
* @default "components"
|
|
21
|
+
*/
|
|
22
|
+
reactCompPackage: z.string().optional(),
|
|
23
|
+
});
|
|
24
|
+
export const reactCompPlugin = {
|
|
25
|
+
configScheme: ReactCompPluginConfig,
|
|
26
|
+
generate: (ctx, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
const { log, nodes, outputs, packagePaths, namespace, } = ctx;
|
|
28
|
+
const { reactCompPackage = 'components', reactCompPath, reactCompIndexFilename = 'react-comp-index.ts' } = config;
|
|
29
|
+
const { path } = getProtoPluginPackAndPath(namespace, reactCompPackage, reactCompPath, { packagePaths, indexFilename: reactCompIndexFilename });
|
|
30
|
+
const supported = nodes.filter(n => supportedTypes.includes(n.type));
|
|
31
|
+
log(`reactPlugin. ${supported.length} supported node(s)`);
|
|
32
|
+
for (const node of supported) {
|
|
33
|
+
log(`component - ${node.name}`);
|
|
34
|
+
yield generateComponentAsync(node, ctx, config);
|
|
35
|
+
}
|
|
36
|
+
if (supported.length) {
|
|
37
|
+
outputs.push({
|
|
38
|
+
path: joinPaths(path, reactCompIndexFilename),
|
|
39
|
+
content: '',
|
|
40
|
+
generator: {
|
|
41
|
+
root: path,
|
|
42
|
+
recursive: true,
|
|
43
|
+
generator: protoGenerateTsIndex
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
};
|
|
49
|
+
const generateComponentAsync = (node, { tab, importMap, outputs, namespace, }, { reactCompPackage = 'components', reactCompPath, reactCompUseStyledJsx = false, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
51
|
+
const { path, packageName } = getProtoPluginPackAndPath(namespace, reactCompPackage, reactCompPath);
|
|
52
|
+
const imports = [];
|
|
53
|
+
const addImport = (im, pkg) => {
|
|
54
|
+
addTsImport(im, pkg, imports, importMap);
|
|
55
|
+
};
|
|
56
|
+
const name = node.name;
|
|
57
|
+
const filename = requireUnrootPath((_d = (_c = (_b = (_a = node.children) === null || _a === void 0 ? void 0 : _a['$filename']) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.trim()) !== null && _d !== void 0 ? _d : name + '.tsx');
|
|
58
|
+
importMap[name] = packageName;
|
|
59
|
+
importMap[name + 'Props'] = packageName;
|
|
60
|
+
const baseLayout = (_e = node.children) === null || _e === void 0 ? void 0 : _e['baseLayout'];
|
|
61
|
+
const baseLayoutType = baseLayout ? getBaseLayoutName(baseLayout.value || 'outer') : null;
|
|
62
|
+
if (baseLayoutType) {
|
|
63
|
+
addImport(baseLayoutType, '@iyio/common');
|
|
64
|
+
addImport('bcn', '@iyio/common');
|
|
65
|
+
}
|
|
66
|
+
let startI;
|
|
67
|
+
const out = [];
|
|
68
|
+
const propsNode = (_f = node.children) === null || _f === void 0 ? void 0 : _f['props'];
|
|
69
|
+
const props = propsNode === null || propsNode === void 0 ? void 0 : propsNode.children;
|
|
70
|
+
if (props) {
|
|
71
|
+
out.push('');
|
|
72
|
+
if (propsNode.comment) {
|
|
73
|
+
out.push(...protoFormatTsComment(propsNode.comment, '').split('\n'));
|
|
74
|
+
}
|
|
75
|
+
startI = out.length;
|
|
76
|
+
out.push(`export interface ${name}Props`);
|
|
77
|
+
out.push('{');
|
|
78
|
+
for (const name in props) {
|
|
79
|
+
const p = props[name];
|
|
80
|
+
if (p.special || p.isContent) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const type = protoGetTsType(p.type);
|
|
84
|
+
if (!protoIsTsBuiltType(type)) {
|
|
85
|
+
addImport(type);
|
|
86
|
+
}
|
|
87
|
+
if (p.comment) {
|
|
88
|
+
out.push(...protoFormatTsComment(p.comment, tab).split('\n'));
|
|
89
|
+
}
|
|
90
|
+
out.push(`${tab}${name}:${type};`);
|
|
91
|
+
}
|
|
92
|
+
protoLabelOutputLines(out, 'props', startI);
|
|
93
|
+
out.push('}');
|
|
94
|
+
out.push('');
|
|
95
|
+
}
|
|
96
|
+
if (node.comment) {
|
|
97
|
+
out.push(...protoFormatTsComment(node.comment, '').split('\n'));
|
|
98
|
+
}
|
|
99
|
+
startI = out.length;
|
|
100
|
+
out.push(`export function ${name}(${props ? '{' : ')'}`);
|
|
101
|
+
protoLabelOutputLines(out, 'comp', startI);
|
|
102
|
+
if (props) {
|
|
103
|
+
for (const name in props) {
|
|
104
|
+
const p = props[name];
|
|
105
|
+
if (p.special || p.isContent) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const defaultValue = (_h = (_g = p.children) === null || _g === void 0 ? void 0 : _g['default']) === null || _h === void 0 ? void 0 : _h.value;
|
|
109
|
+
out.push(`${tab}${name}${defaultValue ? '=' + defaultValue : ''},`);
|
|
110
|
+
}
|
|
111
|
+
if (baseLayoutType) {
|
|
112
|
+
out.push(`${tab}...props`);
|
|
113
|
+
out.push(`}:${name}Props & ${baseLayoutType}){`);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
out.push(`}:${name}Props){`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
out.push('{');
|
|
121
|
+
}
|
|
122
|
+
out.push('');
|
|
123
|
+
out.push(`${tab}return (`);
|
|
124
|
+
if (baseLayoutType) {
|
|
125
|
+
out.push(`${tab}${tab}<div className={bcn(props,'${name}')}>`);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
out.push(`${tab}${tab}<div className="${name}">`);
|
|
129
|
+
}
|
|
130
|
+
const bodyTab = `${tab}${tab}${tab}`;
|
|
131
|
+
out.push('');
|
|
132
|
+
out.push(`${bodyTab}${name}`);
|
|
133
|
+
out.push('');
|
|
134
|
+
if (reactCompUseStyledJsx || ((_j = node.children) === null || _j === void 0 ? void 0 : _j['styled-jsx'])) {
|
|
135
|
+
out.push(`${bodyTab}<style global jsx>{\``);
|
|
136
|
+
out.push(`${bodyTab}${tab}.${name}{`);
|
|
137
|
+
out.push(`${bodyTab}${tab}${tab}display:flex;`);
|
|
138
|
+
out.push(`${bodyTab}${tab}${tab}flex-direction:column;`);
|
|
139
|
+
out.push(`${bodyTab}${tab}}`);
|
|
140
|
+
out.push(`${bodyTab}\`}</style>`);
|
|
141
|
+
}
|
|
142
|
+
out.push(`${tab}${tab}</div>`);
|
|
143
|
+
out.push(`${tab})`);
|
|
144
|
+
out.push('}');
|
|
145
|
+
if (imports.length) {
|
|
146
|
+
protoPrependTsImports(imports, importMap, out);
|
|
147
|
+
}
|
|
148
|
+
outputs.push({
|
|
149
|
+
path: joinPaths(path, filename),
|
|
150
|
+
content: out.join('\n'),
|
|
151
|
+
autoMerge: true,
|
|
152
|
+
mergeHandler: protoMergeTsImports
|
|
153
|
+
});
|
|
154
|
+
return name;
|
|
155
|
+
});
|
|
156
|
+
const getBaseLayoutName = (type) => {
|
|
157
|
+
switch (type) {
|
|
158
|
+
case "inner": return 'BaseLayoutInnerProps';
|
|
159
|
+
case "outer-no-flex": return 'BaseLayoutOuterNoFlexProps';
|
|
160
|
+
case "base": return 'BaseLayoutProps';
|
|
161
|
+
case "all": return 'AllBaseLayoutProps';
|
|
162
|
+
case "outer":
|
|
163
|
+
default:
|
|
164
|
+
return 'BaseLayoutOuterProps';
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
//# sourceMappingURL=reactCompPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reactCompPlugin.js","sourceRoot":"","sources":["../../../../../../../packages/protogen-runtime/src/lib/plugins/reactCompPlugin.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,yBAAyB,EAAgB,oBAAoB,EAAE,oBAAoB,EAAE,cAAc,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,mBAAmB,EAA8C,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACrR,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,cAAc,GAAC,CAAC,MAAM,EAAC,MAAM,EAAC,QAAQ,CAAC,CAAC;AAE9C,MAAM,qBAAqB,GAAC,CAAC,CAAC,MAAM,CACpC;IACI;;OAEG;IACH,aAAa,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAEnC;;OAEG;IACH,sBAAsB,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAE5C;;OAEG;IACH,qBAAqB,EAAC,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAG5C;;OAEG;IACH,gBAAgB,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EA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AAC,CAAC;KAChD;IAED,OAAO,CAAC,IAAI,CAAC;QACT,IAAI,EAAC,SAAS,CAAC,IAAI,EAAC,QAAQ,CAAC;QAC7B,OAAO,EAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;QACtB,SAAS,EAAC,IAAI;QACd,YAAY,EAAC,mBAAmB;KACnC,CAAC,CAAA;IAEF,OAAO,IAAI,CAAC;AAEhB,CAAC,CAAA,CAAA;AAGD,MAAM,iBAAiB,GAAC,CAAC,IAAW,EAAC,EAAE;IAEnC,QAAO,IAAI,EAAC;QACR,KAAK,OAAO,CAAC,CAAC,OAAO,sBAAsB,CAAC;QAC5C,KAAK,eAAe,CAAC,CAAC,OAAO,4BAA4B,CAAC;QAC1D,KAAK,MAAM,CAAC,CAAC,OAAO,iBAAiB,CAAC;QACtC,KAAK,KAAK,CAAC,CAAC,OAAO,oBAAoB,CAAC;QACxC,KAAK,OAAO,CAAC;QACb;YACI,OAAO,sBAAsB,CAAC;KACrC;AACL,CAAC,CAAA"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ProtoPipelineConfigurablePlugin } from "@iyio/protogen";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
declare const ServerFnPluginConfig: z.ZodObject<{
|
|
4
|
+
/**
|
|
5
|
+
* @default .serverFnPackage
|
|
6
|
+
*/
|
|
7
|
+
serverFnPath: z.ZodOptional<z.ZodString>;
|
|
8
|
+
/**
|
|
9
|
+
* @default "serverFns"
|
|
10
|
+
*/
|
|
11
|
+
serverFnPackage: z.ZodOptional<z.ZodString>;
|
|
12
|
+
/**
|
|
13
|
+
* @default .serverFnClientPackage
|
|
14
|
+
*/
|
|
15
|
+
serverFnClientPath: z.ZodOptional<z.ZodString>;
|
|
16
|
+
/**
|
|
17
|
+
* @default "serverFnsClient"
|
|
18
|
+
*/
|
|
19
|
+
serverFnClientPackage: z.ZodOptional<z.ZodString>;
|
|
20
|
+
/**
|
|
21
|
+
* @default "serverFn-params.ts"
|
|
22
|
+
*/
|
|
23
|
+
serverFnParamsFilename: z.ZodOptional<z.ZodString>;
|
|
24
|
+
/**
|
|
25
|
+
* @default "serverFn-client-index.ts"
|
|
26
|
+
*/
|
|
27
|
+
serverFnClientIndexFilename: z.ZodOptional<z.ZodString>;
|
|
28
|
+
/**
|
|
29
|
+
* @default "serverFnClients.ts"
|
|
30
|
+
*/
|
|
31
|
+
serverFnClientFilename: z.ZodOptional<z.ZodString>;
|
|
32
|
+
/**
|
|
33
|
+
* @default "handler"
|
|
34
|
+
*/
|
|
35
|
+
serverFnHandlerName: z.ZodOptional<z.ZodString>;
|
|
36
|
+
/**
|
|
37
|
+
* @default "@iyio/common"
|
|
38
|
+
*/
|
|
39
|
+
serverFnLibPackage: z.ZodOptional<z.ZodString>;
|
|
40
|
+
/**
|
|
41
|
+
* @default "@iyio/aws-lambda"
|
|
42
|
+
*/
|
|
43
|
+
serverFnLambdaPackage: z.ZodOptional<z.ZodString>;
|
|
44
|
+
}, "strip", z.ZodTypeAny, {
|
|
45
|
+
serverFnPath?: string | undefined;
|
|
46
|
+
serverFnPackage?: string | undefined;
|
|
47
|
+
serverFnClientPath?: string | undefined;
|
|
48
|
+
serverFnClientPackage?: string | undefined;
|
|
49
|
+
serverFnParamsFilename?: string | undefined;
|
|
50
|
+
serverFnClientIndexFilename?: string | undefined;
|
|
51
|
+
serverFnClientFilename?: string | undefined;
|
|
52
|
+
serverFnHandlerName?: string | undefined;
|
|
53
|
+
serverFnLibPackage?: string | undefined;
|
|
54
|
+
serverFnLambdaPackage?: string | undefined;
|
|
55
|
+
}, {
|
|
56
|
+
serverFnPath?: string | undefined;
|
|
57
|
+
serverFnPackage?: string | undefined;
|
|
58
|
+
serverFnClientPath?: string | undefined;
|
|
59
|
+
serverFnClientPackage?: string | undefined;
|
|
60
|
+
serverFnParamsFilename?: string | undefined;
|
|
61
|
+
serverFnClientIndexFilename?: string | undefined;
|
|
62
|
+
serverFnClientFilename?: string | undefined;
|
|
63
|
+
serverFnHandlerName?: string | undefined;
|
|
64
|
+
serverFnLibPackage?: string | undefined;
|
|
65
|
+
serverFnLambdaPackage?: string | undefined;
|
|
66
|
+
}>;
|
|
67
|
+
export declare const serverFnPlugin: ProtoPipelineConfigurablePlugin<typeof ServerFnPluginConfig>;
|
|
68
|
+
export {};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { getFileNameNoExt, joinPaths, strFirstToLower } from "@iyio/common";
|
|
3
|
+
import { getProtoPluginPackAndPath, protoFormatTsComment, protoGenerateTsIndex, protoIsTsBuiltType, protoLabelOutputLines, protoMergeTsImports, protoPrependTsImports } from "@iyio/protogen";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
const supportedTypes = ['serverFn'];
|
|
6
|
+
const ServerFnPluginConfig = z.object({
|
|
7
|
+
/**
|
|
8
|
+
* @default .serverFnPackage
|
|
9
|
+
*/
|
|
10
|
+
serverFnPath: z.string().optional(),
|
|
11
|
+
/**
|
|
12
|
+
* @default "serverFns"
|
|
13
|
+
*/
|
|
14
|
+
serverFnPackage: z.string().optional(),
|
|
15
|
+
/**
|
|
16
|
+
* @default .serverFnClientPackage
|
|
17
|
+
*/
|
|
18
|
+
serverFnClientPath: z.string().optional(),
|
|
19
|
+
/**
|
|
20
|
+
* @default "serverFnsClient"
|
|
21
|
+
*/
|
|
22
|
+
serverFnClientPackage: z.string().optional(),
|
|
23
|
+
/**
|
|
24
|
+
* @default "serverFn-params.ts"
|
|
25
|
+
*/
|
|
26
|
+
serverFnParamsFilename: z.string().optional(),
|
|
27
|
+
/**
|
|
28
|
+
* @default "serverFn-client-index.ts"
|
|
29
|
+
*/
|
|
30
|
+
serverFnClientIndexFilename: z.string().optional(),
|
|
31
|
+
/**
|
|
32
|
+
* @default "serverFnClients.ts"
|
|
33
|
+
*/
|
|
34
|
+
serverFnClientFilename: z.string().optional(),
|
|
35
|
+
/**
|
|
36
|
+
* @default "handler"
|
|
37
|
+
*/
|
|
38
|
+
serverFnHandlerName: z.string().optional(),
|
|
39
|
+
/**
|
|
40
|
+
* @default "@iyio/common"
|
|
41
|
+
*/
|
|
42
|
+
serverFnLibPackage: z.string().optional(),
|
|
43
|
+
/**
|
|
44
|
+
* @default "@iyio/aws-lambda"
|
|
45
|
+
*/
|
|
46
|
+
serverFnLambdaPackage: z.string().optional(),
|
|
47
|
+
});
|
|
48
|
+
export const serverFnPlugin = {
|
|
49
|
+
configScheme: ServerFnPluginConfig,
|
|
50
|
+
generate: ({ importMap, outputs, tab, log, nodes, namespace, packagePaths, }, { serverFnPackage = 'serverFns', serverFnPath = serverFnPackage, serverFnClientPackage = 'serverFnsClient', serverFnClientPath = serverFnClientPackage, serverFnParamsFilename = 'serverFn-params.ts', serverFnHandlerName = 'handler', serverFnLibPackage = '@iyio/common', serverFnClientFilename = 'serverFnClients.ts', serverFnLambdaPackage = '@iyio/aws-lambda', serverFnClientIndexFilename = 'serverFn-client-index.ts', }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
52
|
+
const { path } = getProtoPluginPackAndPath(namespace, serverFnPackage, serverFnPath);
|
|
53
|
+
const { path: clientPath } = getProtoPluginPackAndPath(namespace, serverFnClientPackage, serverFnClientPath, { packagePaths, indexFilename: serverFnClientIndexFilename });
|
|
54
|
+
const supported = nodes.filter(n => supportedTypes.includes(n.type));
|
|
55
|
+
log(`${supported.length} supported node(s)`);
|
|
56
|
+
if (!supported.length) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const paramsOut = [];
|
|
60
|
+
paramsOut.push('import { defineStringParam } from "@iyio/common";');
|
|
61
|
+
paramsOut.push('');
|
|
62
|
+
const clientOut = [];
|
|
63
|
+
const clientInputs = [];
|
|
64
|
+
const clientParamImports = [];
|
|
65
|
+
clientOut.push(`import { lambdaClient } from '${serverFnLambdaPackage}';`);
|
|
66
|
+
clientOut.push('');
|
|
67
|
+
for (const node of supported) {
|
|
68
|
+
const out = [];
|
|
69
|
+
const imports = [];
|
|
70
|
+
const name = node.name;
|
|
71
|
+
const inputType = (_c = (_b = (_a = node.children) === null || _a === void 0 ? void 0 : _a['input']) === null || _b === void 0 ? void 0 : _b.type) !== null && _c !== void 0 ? _c : 'void';
|
|
72
|
+
const outputType = (_f = (_e = (_d = node.children) === null || _d === void 0 ? void 0 : _d['output']) === null || _e === void 0 ? void 0 : _e.type) !== null && _f !== void 0 ? _f : 'void';
|
|
73
|
+
const inputPackage = importMap[inputType + 'Scheme'];
|
|
74
|
+
const outputPackage = importMap[outputType + 'Scheme'];
|
|
75
|
+
const paramName = strFirstToLower(name) + 'ArnParam';
|
|
76
|
+
importMap[paramName] = serverFnClientPackage;
|
|
77
|
+
clientParamImports.push(paramName);
|
|
78
|
+
paramsOut.push(`export const ${paramName}=defineStringParam('${strFirstToLower(name)}Arn');`);
|
|
79
|
+
const clientName = name.endsWith('Fn') ? name.substring(0, name.length - 2) : name;
|
|
80
|
+
importMap[clientName] = serverFnClientPackage;
|
|
81
|
+
clientOut.push(`export const ${clientName}=(input:${inputType}):Promise<${outputType}>=>(`);
|
|
82
|
+
clientOut.push(`${tab}lambdaClient().invokeAsync<${inputType},${outputType}>({`);
|
|
83
|
+
clientOut.push(`${tab}${tab}fn:${paramName}(),`);
|
|
84
|
+
clientOut.push(`${tab}${tab}input,`);
|
|
85
|
+
if (inputPackage) {
|
|
86
|
+
clientInputs.push(inputType + 'Scheme');
|
|
87
|
+
clientOut.push(`${tab}${tab}inputScheme:${inputType}Scheme,`);
|
|
88
|
+
}
|
|
89
|
+
if (outputPackage) {
|
|
90
|
+
clientInputs.push(outputType + 'Scheme');
|
|
91
|
+
clientOut.push(`${tab}${tab}outputScheme:${outputType}Scheme,`);
|
|
92
|
+
}
|
|
93
|
+
clientOut.push(`${tab}})`);
|
|
94
|
+
clientOut.push(')');
|
|
95
|
+
clientOut.push('');
|
|
96
|
+
const handlerName = (_j = (_h = (_g = node.children) === null || _g === void 0 ? void 0 : _g['handlerName']) === null || _h === void 0 ? void 0 : _h.value) !== null && _j !== void 0 ? _j : serverFnHandlerName;
|
|
97
|
+
const isDefault = handlerName === 'default';
|
|
98
|
+
if (!protoIsTsBuiltType(inputType)) {
|
|
99
|
+
imports.push(inputType);
|
|
100
|
+
clientInputs.push(inputType);
|
|
101
|
+
}
|
|
102
|
+
if (!protoIsTsBuiltType(outputType)) {
|
|
103
|
+
imports.push(outputType);
|
|
104
|
+
clientInputs.push(outputType);
|
|
105
|
+
}
|
|
106
|
+
out.push(`import { createFnHandler, FnEvent } from '${serverFnLibPackage}';`);
|
|
107
|
+
out.push('');
|
|
108
|
+
if (node.comment) {
|
|
109
|
+
out.push(...protoFormatTsComment(node.comment, '').split('\n'));
|
|
110
|
+
}
|
|
111
|
+
const startI = out.length;
|
|
112
|
+
out.push(`const ${name}=async (`);
|
|
113
|
+
out.push(`${tab}fnEvt:FnEvent${inputType === 'void' ? '' : ','}`);
|
|
114
|
+
out.push(`${inputType === 'void' ? '' : `${tab}input:${inputType}`}`);
|
|
115
|
+
out.push(`):Promise<${outputType}>=>{`);
|
|
116
|
+
protoLabelOutputLines(out, 'head', startI);
|
|
117
|
+
out.push(`${tab}// do cool stuff`);
|
|
118
|
+
out.push('}');
|
|
119
|
+
out.push('');
|
|
120
|
+
out.push(isDefault ? `export default ${name};` : `export const ${handlerName}=createFnHandler(${name},{`);
|
|
121
|
+
if (inputPackage) {
|
|
122
|
+
imports.push(inputType + 'Scheme');
|
|
123
|
+
out.push(`${tab}inputScheme:${inputType}Scheme,`);
|
|
124
|
+
}
|
|
125
|
+
if (outputPackage) {
|
|
126
|
+
imports.push(outputType + 'Scheme');
|
|
127
|
+
out.push(`${tab}outputScheme:${outputType}Scheme,`);
|
|
128
|
+
}
|
|
129
|
+
out.push('});');
|
|
130
|
+
protoPrependTsImports(imports, importMap, out);
|
|
131
|
+
outputs.push({
|
|
132
|
+
path: joinPaths(path, name + '.ts'),
|
|
133
|
+
content: out.join('\n'),
|
|
134
|
+
autoMerge: true,
|
|
135
|
+
mergeHandler: protoMergeTsImports
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
clientOut.unshift(`import { ${clientParamImports.join(', ')} } from './${getFileNameNoExt(serverFnParamsFilename)}';`);
|
|
139
|
+
protoPrependTsImports(clientInputs, importMap, clientOut);
|
|
140
|
+
outputs.push({
|
|
141
|
+
path: joinPaths(clientPath, serverFnClientFilename),
|
|
142
|
+
content: clientOut.join('\n'),
|
|
143
|
+
});
|
|
144
|
+
outputs.push({
|
|
145
|
+
path: joinPaths(clientPath, serverFnParamsFilename),
|
|
146
|
+
content: paramsOut.join('\n'),
|
|
147
|
+
});
|
|
148
|
+
outputs.push({
|
|
149
|
+
path: joinPaths(clientPath, serverFnClientIndexFilename),
|
|
150
|
+
content: '',
|
|
151
|
+
generator: {
|
|
152
|
+
root: clientPath,
|
|
153
|
+
generator: protoGenerateTsIndex
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
})
|
|
157
|
+
};
|
|
158
|
+
//# sourceMappingURL=serverFnPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverFnPlugin.js","sourceRoot":"","sources":["../../../../../../../packages/protogen-runtime/src/lib/plugins/serverFnPlugin.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC5E,OAAO,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,mBAAmB,EAAmC,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC/N,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,cAAc,GAAC,CAAC,UAAU,CAAC,CAAC;AAElC,MAAM,oBAAoB,GAAC,CAAC,CAAC,MAAM,CACnC;IACI;;OAEG;IACH,YAAY,EAAC,CAAC,CAAC,MAAM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BAAmB;aACnC,CAAC,CAAA;SAEL;QAED,SAAS,CAAC,OAAO,CAAC,YAAY,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,gBAAgB,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAA;QACtH,qBAAqB,CAAC,YAAY,EAAC,SAAS,EAAC,SAAS,CAAC,CAAC;QACxD,OAAO,CAAC,IAAI,CAAC;YACT,IAAI,EAAC,SAAS,CAAC,UAAU,EAAC,sBAAsB,CAAC;YACjD,OAAO,EAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;SAC/B,CAAC,CAAA;QACF,OAAO,CAAC,IAAI,CAAC;YACT,IAAI,EAAC,SAAS,CAAC,UAAU,EAAC,sBAAsB,CAAC;YACjD,OAAO,EAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;SAC/B,CAAC,CAAA;QACF,OAAO,CAAC,IAAI,CAAC;YACT,IAAI,EAAC,SAAS,CAAC,UAAU,EAAC,2BAA2B,CAAC;YACtD,OAAO,EAAC,EAAE;YACV,SAAS,EAAC;gBACN,IAAI,EAAC,UAAU;gBACf,SAAS,EAAC,oBAAoB;aACjC;SACJ,CAAC,CAAA;IAEN,CAAC,CAAA;CACJ,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ProtoPipelineConfigurablePlugin } from "@iyio/protogen";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
declare const TablePluginConfig: z.ZodObject<{
|
|
4
|
+
tablePath: z.ZodOptional<z.ZodString>;
|
|
5
|
+
tableFilename: z.ZodOptional<z.ZodString>;
|
|
6
|
+
tableIndexFilename: z.ZodOptional<z.ZodString>;
|
|
7
|
+
tableParamsFilename: z.ZodOptional<z.ZodString>;
|
|
8
|
+
tablePackage: z.ZodOptional<z.ZodString>;
|
|
9
|
+
tableUseParamIds: z.ZodOptional<z.ZodBoolean>;
|
|
10
|
+
dataTableDescriptionPackage: z.ZodOptional<z.ZodString>;
|
|
11
|
+
allTableArrayName: z.ZodOptional<z.ZodString>;
|
|
12
|
+
tsSchemePrefix: z.ZodOptional<z.ZodString>;
|
|
13
|
+
tsSchemeSuffix: z.ZodOptional<z.ZodString>;
|
|
14
|
+
}, "strip", z.ZodTypeAny, {
|
|
15
|
+
tablePath?: string | undefined;
|
|
16
|
+
tableFilename?: string | undefined;
|
|
17
|
+
tableIndexFilename?: string | undefined;
|
|
18
|
+
tableParamsFilename?: string | undefined;
|
|
19
|
+
tablePackage?: string | undefined;
|
|
20
|
+
tableUseParamIds?: boolean | undefined;
|
|
21
|
+
dataTableDescriptionPackage?: string | undefined;
|
|
22
|
+
allTableArrayName?: string | undefined;
|
|
23
|
+
tsSchemePrefix?: string | undefined;
|
|
24
|
+
tsSchemeSuffix?: string | undefined;
|
|
25
|
+
}, {
|
|
26
|
+
tablePath?: string | undefined;
|
|
27
|
+
tableFilename?: string | undefined;
|
|
28
|
+
tableIndexFilename?: string | undefined;
|
|
29
|
+
tableParamsFilename?: string | undefined;
|
|
30
|
+
tablePackage?: string | undefined;
|
|
31
|
+
tableUseParamIds?: boolean | undefined;
|
|
32
|
+
dataTableDescriptionPackage?: string | undefined;
|
|
33
|
+
allTableArrayName?: string | undefined;
|
|
34
|
+
tsSchemePrefix?: string | undefined;
|
|
35
|
+
tsSchemeSuffix?: string | undefined;
|
|
36
|
+
}>;
|
|
37
|
+
export declare const tablePlugin: ProtoPipelineConfigurablePlugin<typeof TablePluginConfig>;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { __awaiter, __rest } from "tslib";
|
|
2
|
+
import { getFileNameNoExt, joinPaths, strFirstToLower } from "@iyio/common";
|
|
3
|
+
import { addTsImport, getProtoPluginPackAndPath, protoFormatTsComment, protoGenerateTsIndex, protoGetChildren, protoGetChildrenByName, protoPrependTsImports } from "@iyio/protogen";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { getTsSchemeName, SharedTsPluginConfigScheme } from "../sharedTsConfig";
|
|
6
|
+
const TablePluginConfig = z.object({
|
|
7
|
+
/**
|
|
8
|
+
* @default .tablePackage
|
|
9
|
+
*/
|
|
10
|
+
tablePath: z.string().optional(),
|
|
11
|
+
/**
|
|
12
|
+
* @default "tables.ts"
|
|
13
|
+
*/
|
|
14
|
+
tableFilename: z.string().optional(),
|
|
15
|
+
/**
|
|
16
|
+
* @default "tables-index.ts"
|
|
17
|
+
*/
|
|
18
|
+
tableIndexFilename: z.string().optional(),
|
|
19
|
+
/**
|
|
20
|
+
* @default "table-param.ts"
|
|
21
|
+
*/
|
|
22
|
+
tableParamsFilename: z.string().optional(),
|
|
23
|
+
/**
|
|
24
|
+
* @default "tables"
|
|
25
|
+
*/
|
|
26
|
+
tablePackage: z.string().optional(),
|
|
27
|
+
/**
|
|
28
|
+
* If true the tableIdParam of generated tables will be populated and a table-params file will be generated.
|
|
29
|
+
*/
|
|
30
|
+
tableUseParamIds: z.boolean().optional(),
|
|
31
|
+
/**
|
|
32
|
+
* @default '@iyio/common'
|
|
33
|
+
*/
|
|
34
|
+
dataTableDescriptionPackage: z.string().optional(),
|
|
35
|
+
/**
|
|
36
|
+
* @default 'allTables'
|
|
37
|
+
*/
|
|
38
|
+
allTableArrayName: z.string().optional(),
|
|
39
|
+
}).merge(SharedTsPluginConfigScheme);
|
|
40
|
+
export const tablePlugin = {
|
|
41
|
+
configScheme: TablePluginConfig,
|
|
42
|
+
generate: ({ log, nodes, outputs, importMap, tab, packagePaths, namespace, }, _a) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
|
|
44
|
+
var { tablePath, tablePackage = 'tables', tableFilename = 'tables.ts', tableParamsFilename = 'table-params.ts', tableIndexFilename = 'tables-index.ts', tableUseParamIds, dataTableDescriptionPackage = '@iyio/common', allTableArrayName = 'allTables' } = _a, tsConfig = __rest(_a, ["tablePath", "tablePackage", "tableFilename", "tableParamsFilename", "tableIndexFilename", "tableUseParamIds", "dataTableDescriptionPackage", "allTableArrayName"]);
|
|
45
|
+
const { path, packageName } = getProtoPluginPackAndPath(namespace, tablePackage, tablePath, { packagePaths, indexFilename: tableIndexFilename });
|
|
46
|
+
const imports = [];
|
|
47
|
+
const addImport = (im, packageName) => {
|
|
48
|
+
addTsImport(im, packageName, imports, importMap);
|
|
49
|
+
};
|
|
50
|
+
const supported = nodes.filter(node => node.types.some(t => t.type === 'table'));
|
|
51
|
+
if (supported.length) {
|
|
52
|
+
addImport('DataTableDescription', dataTableDescriptionPackage);
|
|
53
|
+
}
|
|
54
|
+
log(`${supported.length} supported node(s)`);
|
|
55
|
+
const out = [];
|
|
56
|
+
const paramsOut = [];
|
|
57
|
+
const paramImportName = './' + getFileNameNoExt(tableParamsFilename);
|
|
58
|
+
const tableNames = [];
|
|
59
|
+
for (const node of supported) {
|
|
60
|
+
const name = node.name;
|
|
61
|
+
const paramName = strFirstToLower(name) + 'TableParam';
|
|
62
|
+
importMap[name + 'Table'] = packageName;
|
|
63
|
+
tableNames.push(name + 'Table');
|
|
64
|
+
log(`table - ${name}Table`);
|
|
65
|
+
const props = protoGetChildren(node, false);
|
|
66
|
+
out.push('');
|
|
67
|
+
if (node.comment) {
|
|
68
|
+
out.push(protoFormatTsComment(node.comment, ''));
|
|
69
|
+
}
|
|
70
|
+
addImport(name);
|
|
71
|
+
out.push(`export const ${name}Table:DataTableDescription<${name}>={`);
|
|
72
|
+
out.push(`${tab}name:${JSON.stringify(name)},`);
|
|
73
|
+
const primary = props.find(n => { var _a; return (_a = n.children) === null || _a === void 0 ? void 0 : _a['primaryKey']; });
|
|
74
|
+
out.push(`${tab}primaryKey:${primary ? JSON.stringify(primary.name) : '"id"'},`);
|
|
75
|
+
if (tableUseParamIds) {
|
|
76
|
+
addImport(paramName, paramImportName);
|
|
77
|
+
paramsOut.push(`export const ${paramName}=defineStringParam('${name}Table');`);
|
|
78
|
+
out.push(`${tab}tableIdParam:${paramName},`);
|
|
79
|
+
}
|
|
80
|
+
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 : {};
|
|
81
|
+
let configValue;
|
|
82
|
+
configValue = (_f = (_e = config['scheme']) === null || _e === void 0 ? void 0 : _e.value) !== null && _f !== void 0 ? _f : getTsSchemeName(name, tsConfig);
|
|
83
|
+
if (importMap[configValue]) {
|
|
84
|
+
addImport(configValue);
|
|
85
|
+
out.push(`${tab}scheme:${configValue},`);
|
|
86
|
+
}
|
|
87
|
+
if (configValue = (_g = config['mousePath']) === null || _g === void 0 ? void 0 : _g.value) {
|
|
88
|
+
out.push(`${tab}mousePath:${JSON.stringify(configValue)},`);
|
|
89
|
+
}
|
|
90
|
+
if (configValue = (_h = config['mousePath']) === null || _h === void 0 ? void 0 : _h.value) {
|
|
91
|
+
out.push(`${tab}mousePath:${JSON.stringify(configValue)},`);
|
|
92
|
+
}
|
|
93
|
+
if (configValue = (_j = config['mousePath']) === null || _j === void 0 ? void 0 : _j.value) {
|
|
94
|
+
out.push(`${tab}mousePath:${JSON.stringify(configValue)},`);
|
|
95
|
+
}
|
|
96
|
+
if (configValue = (_k = config['isReadonly']) === null || _k === void 0 ? void 0 : _k.value) {
|
|
97
|
+
out.push(`${tab}isReadonly:${JSON.stringify(Boolean(configValue))},`);
|
|
98
|
+
}
|
|
99
|
+
if (configValue = (_l = config['watchable']) === null || _l === void 0 ? void 0 : _l.value) {
|
|
100
|
+
out.push(`${tab}watchable:${JSON.stringify(Boolean(configValue))},`);
|
|
101
|
+
}
|
|
102
|
+
if (configValue = (_m = config['defaultOrderProp']) === null || _m === void 0 ? void 0 : _m.value) {
|
|
103
|
+
out.push(`${tab}defaultOrderProp:${JSON.stringify(configValue)},`);
|
|
104
|
+
}
|
|
105
|
+
if (configValue = (_o = config['defaultOrderDesc']) === null || _o === void 0 ? void 0 : _o.value) {
|
|
106
|
+
out.push(`${tab}defaultOrderDesc:${JSON.stringify(Boolean(configValue))},`);
|
|
107
|
+
}
|
|
108
|
+
if (configValue = (_q = (_p = config['ttlProp']) === null || _p === void 0 ? void 0 : _p.value) !== null && _q !== void 0 ? _q : (_r = props.find(p => p.name === 'ttl')) === null || _r === void 0 ? void 0 : _r.name) {
|
|
109
|
+
out.push(`${tab}ttlProp:${JSON.stringify(configValue)},`);
|
|
110
|
+
}
|
|
111
|
+
if (configValue = (_t = (_s = config['updateVersionProp']) === null || _s === void 0 ? void 0 : _s.value) !== null && _t !== void 0 ? _t : (_u = props.find(p => p.name === 'uv')) === null || _u === void 0 ? void 0 : _u.name) {
|
|
112
|
+
out.push(`${tab}updateVersionProp:${JSON.stringify(configValue)},`);
|
|
113
|
+
}
|
|
114
|
+
const indexes = protoGetChildrenByName((_v = node.children) === null || _v === void 0 ? void 0 : _v['$table'], 'index', false);
|
|
115
|
+
if (indexes.length) {
|
|
116
|
+
out.push(`${tab}indexes:[`);
|
|
117
|
+
for (let i = 0; i < indexes.length; i++) {
|
|
118
|
+
const index = indexes[i];
|
|
119
|
+
out.push(`${tab}${tab}{`);
|
|
120
|
+
out.push(`${tab}${tab}${tab}name:${JSON.stringify(index.value || 'index' + i)},`);
|
|
121
|
+
out.push(`${tab}${tab}${tab}props:[`);
|
|
122
|
+
const indexProps = protoGetChildren((_w = index.children) === null || _w === void 0 ? void 0 : _w['props'], false);
|
|
123
|
+
for (const iProp of indexProps) {
|
|
124
|
+
out.push(`${tab}${tab}${tab}${tab}${JSON.stringify(iProp.name)},`);
|
|
125
|
+
}
|
|
126
|
+
out.push(`${tab}${tab}${tab}],`);
|
|
127
|
+
if ((_x = index.children) === null || _x === void 0 ? void 0 : _x['includeAll']) {
|
|
128
|
+
out.push(`${tab}${tab}${tab}includeAll:true,`);
|
|
129
|
+
}
|
|
130
|
+
const includeProps = protoGetChildren((_y = index.children) === null || _y === void 0 ? void 0 : _y['include'], false);
|
|
131
|
+
if (includeProps.length) {
|
|
132
|
+
out.push(`${tab}${tab}${tab}include:[`);
|
|
133
|
+
for (const incProp of includeProps) {
|
|
134
|
+
out.push(`${tab}${tab}${tab}${tab}${JSON.stringify(incProp.name)},`);
|
|
135
|
+
}
|
|
136
|
+
out.push(`${tab}${tab}${tab}],`);
|
|
137
|
+
}
|
|
138
|
+
out.push(`${tab}${tab}},`);
|
|
139
|
+
}
|
|
140
|
+
out.push(`${tab}],`);
|
|
141
|
+
}
|
|
142
|
+
out.push('}');
|
|
143
|
+
}
|
|
144
|
+
importMap[allTableArrayName] = packageName;
|
|
145
|
+
out.push(`export const ${allTableArrayName}=[${tableNames.join(',')}] as const`);
|
|
146
|
+
out.push(`Object.freeze(${allTableArrayName})`);
|
|
147
|
+
if (imports.length) {
|
|
148
|
+
protoPrependTsImports(imports, importMap, out);
|
|
149
|
+
}
|
|
150
|
+
out.splice(0, 0, `// this file was autogenerated by @iyio/protogen - https://github.com/iyioio/common/packages/protogen`);
|
|
151
|
+
out.splice(1, 0, `// generator = tablePlugin`);
|
|
152
|
+
outputs.push({
|
|
153
|
+
path: joinPaths(path, tableFilename),
|
|
154
|
+
content: out.join('\n'),
|
|
155
|
+
});
|
|
156
|
+
if (paramsOut.length) {
|
|
157
|
+
paramsOut.splice(0, 0, `// this file was autogenerated by @iyio/protogen - https://github.com/iyioio/common/packages/protogen`);
|
|
158
|
+
paramsOut.splice(1, 0, `// generator = tablePlugin`);
|
|
159
|
+
paramsOut.splice(2, 0, 'import { defineStringParam } from "@iyio/common";');
|
|
160
|
+
paramsOut.splice(3, 0, '');
|
|
161
|
+
outputs.push({
|
|
162
|
+
path: joinPaths(path, tableParamsFilename),
|
|
163
|
+
content: paramsOut.join('\n'),
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
outputs.push({
|
|
167
|
+
path: joinPaths(path, tableIndexFilename),
|
|
168
|
+
content: '',
|
|
169
|
+
generator: {
|
|
170
|
+
root: path,
|
|
171
|
+
generator: protoGenerateTsIndex
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
})
|
|
175
|
+
};
|
|
176
|
+
//# sourceMappingURL=tablePlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tablePlugin.js","sourceRoot":"","sources":["../../../../../../../packages/protogen-runtime/src/lib/plugins/tablePlugin.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,sBAAsB,EAAmC,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACtN,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAIhF,MAAM,iBAAiB,GAAC,CAAC,CAAC,MAAM,CAChC;IACI;;OAEG;IACH,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;IAExC;;OAEG;IACH,mBAAmB,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAGzC;;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;CAE1C,CAAC,CAAC,KAAK,CAAC,0BA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