@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.
Files changed (112) hide show
  1. package/README.md +7 -0
  2. package/esm/package.json +3 -0
  3. package/esm/src/index.d.ts +12 -0
  4. package/esm/src/index.js +13 -0
  5. package/esm/src/index.js.map +1 -0
  6. package/esm/src/lib/default-plugins.d.ts +2 -0
  7. package/esm/src/lib/default-plugins.js +74 -0
  8. package/esm/src/lib/default-plugins.js.map +1 -0
  9. package/esm/src/lib/plugins/examplePlugin.d.ts +26 -0
  10. package/esm/src/lib/plugins/examplePlugin.js +65 -0
  11. package/esm/src/lib/plugins/examplePlugin.js.map +1 -0
  12. package/esm/src/lib/plugins/fileReader.d.ts +2 -0
  13. package/esm/src/lib/plugins/fileReader.js +22 -0
  14. package/esm/src/lib/plugins/fileReader.js.map +1 -0
  15. package/esm/src/lib/plugins/fileWriter.d.ts +2 -0
  16. package/esm/src/lib/plugins/fileWriter.js +57 -0
  17. package/esm/src/lib/plugins/fileWriter.js.map +1 -0
  18. package/esm/src/lib/plugins/functionPlugin.d.ts +26 -0
  19. package/esm/src/lib/plugins/functionPlugin.js +79 -0
  20. package/esm/src/lib/plugins/functionPlugin.js.map +1 -0
  21. package/esm/src/lib/plugins/markdownParser.d.ts +2 -0
  22. package/esm/src/lib/plugins/markdownParser.js +15 -0
  23. package/esm/src/lib/plugins/markdownParser.js.map +1 -0
  24. package/esm/src/lib/plugins/reactCompPlugin.d.ts +32 -0
  25. package/esm/src/lib/plugins/reactCompPlugin.js +167 -0
  26. package/esm/src/lib/plugins/reactCompPlugin.js.map +1 -0
  27. package/esm/src/lib/plugins/serverFnPlugin.d.ts +68 -0
  28. package/esm/src/lib/plugins/serverFnPlugin.js +158 -0
  29. package/esm/src/lib/plugins/serverFnPlugin.js.map +1 -0
  30. package/esm/src/lib/plugins/tablePlugin.d.ts +38 -0
  31. package/esm/src/lib/plugins/tablePlugin.js +176 -0
  32. package/esm/src/lib/plugins/tablePlugin.js.map +1 -0
  33. package/esm/src/lib/plugins/tsConfigPathsPlugin.d.ts +14 -0
  34. package/esm/src/lib/plugins/tsConfigPathsPlugin.js +49 -0
  35. package/esm/src/lib/plugins/tsConfigPathsPlugin.js.map +1 -0
  36. package/esm/src/lib/plugins/tsExternalExecutor.d.ts +2 -0
  37. package/esm/src/lib/plugins/tsExternalExecutor.js +55 -0
  38. package/esm/src/lib/plugins/tsExternalExecutor.js.map +1 -0
  39. package/esm/src/lib/plugins/zodPlugin.d.ts +26 -0
  40. package/esm/src/lib/plugins/zodPlugin.js +330 -0
  41. package/esm/src/lib/plugins/zodPlugin.js.map +1 -0
  42. package/esm/src/lib/protogen-cli-entry.d.ts +1 -0
  43. package/esm/src/lib/protogen-cli-entry.js +6 -0
  44. package/esm/src/lib/protogen-cli-entry.js.map +1 -0
  45. package/esm/src/lib/protogen-runtime.d.ts +5 -0
  46. package/esm/src/lib/protogen-runtime.js +63 -0
  47. package/esm/src/lib/protogen-runtime.js.map +1 -0
  48. package/esm/src/lib/runProtogenCliAsync.d.ts +12 -0
  49. package/esm/src/lib/runProtogenCliAsync.js +99 -0
  50. package/esm/src/lib/runProtogenCliAsync.js.map +1 -0
  51. package/esm/src/lib/sharedTsConfig.d.ts +18 -0
  52. package/esm/src/lib/sharedTsConfig.js +12 -0
  53. package/esm/src/lib/sharedTsConfig.js.map +1 -0
  54. package/esm/src/lib/test-plugins/echo-generator.d.ts +1 -0
  55. package/esm/src/lib/test-plugins/echo-generator.js +12 -0
  56. package/esm/src/lib/test-plugins/echo-generator.js.map +1 -0
  57. package/package.json +20 -0
  58. package/src/index.d.ts +12 -0
  59. package/src/index.js +16 -0
  60. package/src/index.js.map +1 -0
  61. package/src/lib/default-plugins.d.ts +2 -0
  62. package/src/lib/default-plugins.js +78 -0
  63. package/src/lib/default-plugins.js.map +1 -0
  64. package/src/lib/plugins/examplePlugin.d.ts +26 -0
  65. package/src/lib/plugins/examplePlugin.js +68 -0
  66. package/src/lib/plugins/examplePlugin.js.map +1 -0
  67. package/src/lib/plugins/fileReader.d.ts +2 -0
  68. package/src/lib/plugins/fileReader.js +26 -0
  69. package/src/lib/plugins/fileReader.js.map +1 -0
  70. package/src/lib/plugins/fileWriter.d.ts +2 -0
  71. package/src/lib/plugins/fileWriter.js +61 -0
  72. package/src/lib/plugins/fileWriter.js.map +1 -0
  73. package/src/lib/plugins/functionPlugin.d.ts +26 -0
  74. package/src/lib/plugins/functionPlugin.js +82 -0
  75. package/src/lib/plugins/functionPlugin.js.map +1 -0
  76. package/src/lib/plugins/markdownParser.d.ts +2 -0
  77. package/src/lib/plugins/markdownParser.js +19 -0
  78. package/src/lib/plugins/markdownParser.js.map +1 -0
  79. package/src/lib/plugins/reactCompPlugin.d.ts +32 -0
  80. package/src/lib/plugins/reactCompPlugin.js +170 -0
  81. package/src/lib/plugins/reactCompPlugin.js.map +1 -0
  82. package/src/lib/plugins/serverFnPlugin.d.ts +68 -0
  83. package/src/lib/plugins/serverFnPlugin.js +161 -0
  84. package/src/lib/plugins/serverFnPlugin.js.map +1 -0
  85. package/src/lib/plugins/tablePlugin.d.ts +38 -0
  86. package/src/lib/plugins/tablePlugin.js +179 -0
  87. package/src/lib/plugins/tablePlugin.js.map +1 -0
  88. package/src/lib/plugins/tsConfigPathsPlugin.d.ts +14 -0
  89. package/src/lib/plugins/tsConfigPathsPlugin.js +52 -0
  90. package/src/lib/plugins/tsConfigPathsPlugin.js.map +1 -0
  91. package/src/lib/plugins/tsExternalExecutor.d.ts +2 -0
  92. package/src/lib/plugins/tsExternalExecutor.js +58 -0
  93. package/src/lib/plugins/tsExternalExecutor.js.map +1 -0
  94. package/src/lib/plugins/zodPlugin.d.ts +26 -0
  95. package/src/lib/plugins/zodPlugin.js +333 -0
  96. package/src/lib/plugins/zodPlugin.js.map +1 -0
  97. package/src/lib/protogen-cli-entry.d.ts +1 -0
  98. package/src/lib/protogen-cli-entry.js +8 -0
  99. package/src/lib/protogen-cli-entry.js.map +1 -0
  100. package/src/lib/protogen-runtime.d.ts +5 -0
  101. package/src/lib/protogen-runtime.js +69 -0
  102. package/src/lib/protogen-runtime.js.map +1 -0
  103. package/src/lib/runProtogenCliAsync.d.ts +12 -0
  104. package/src/lib/runProtogenCliAsync.js +103 -0
  105. package/src/lib/runProtogenCliAsync.js.map +1 -0
  106. package/src/lib/sharedTsConfig.d.ts +18 -0
  107. package/src/lib/sharedTsConfig.js +16 -0
  108. package/src/lib/sharedTsConfig.js.map +1 -0
  109. package/src/lib/test-plugins/echo-generator.d.ts +1 -0
  110. package/src/lib/test-plugins/echo-generator.js +14 -0
  111. package/src/lib/test-plugins/echo-generator.js.map +1 -0
  112. package/src/package.json +4 -0
@@ -0,0 +1,99 @@
1
+ import { __awaiter } from "tslib";
2
+ import { uuid } from "@iyio/common";
3
+ import { executeTGenPipelineAsync, protoGetStageFromName } from "@iyio/protogen";
4
+ import { getDefaultProtoPipelinePlugins } from "./default-plugins";
5
+ export const runProtogenCliAsync = ({ config, args, loadModule, logOutput, verbose: _verbose, onOutputReady, onPipelineReady, }) => __awaiter(void 0, void 0, void 0, function* () {
6
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
7
+ let startDir = null;
8
+ if (config.workingDirectory && ((_a = globalThis.process) === null || _a === void 0 ? void 0 : _a.chdir) !== undefined && ((_b = globalThis.process) === null || _b === void 0 ? void 0 : _b.cwd) !== undefined) {
9
+ startDir = globalThis.process.cwd();
10
+ globalThis.process.chdir(config.workingDirectory);
11
+ }
12
+ try {
13
+ const verbose = (_c = _verbose !== null && _verbose !== void 0 ? _verbose : config.verbose) !== null && _c !== void 0 ? _c : false;
14
+ const log = logOutput !== null && logOutput !== void 0 ? logOutput : (verbose ? console.log : () => { });
15
+ onOutputReady === null || onOutputReady === void 0 ? void 0 : onOutputReady(verbose, log);
16
+ if (verbose) {
17
+ log('Verbose mode enabled');
18
+ }
19
+ const pipeline = {
20
+ config,
21
+ context: {
22
+ executionId: uuid(),
23
+ metadata: {},
24
+ packagePaths: {},
25
+ args,
26
+ inputs: (_d = config.inputs) !== null && _d !== void 0 ? _d : [],
27
+ sources: [],
28
+ nodes: [],
29
+ outputs: [],
30
+ verbose,
31
+ namespace: (_e = config.namespace) !== null && _e !== void 0 ? _e : 'common',
32
+ tab: ' ',
33
+ stage: 'init',
34
+ importMap: {},
35
+ dryRun: (_f = config.dryRun) !== null && _f !== void 0 ? _f : false,
36
+ log,
37
+ },
38
+ plugins: [],
39
+ };
40
+ const plugins = (_g = config.plugins) !== null && _g !== void 0 ? _g : [];
41
+ for (const p of plugins) {
42
+ const [source, _name, ...paths] = p.split(':');
43
+ const name = _name || 'default';
44
+ log(`Load plugin ${name} from ${source}`);
45
+ const plugin = (_h = loadModule === null || loadModule === void 0 ? void 0 : loadModule(p)) === null || _h === void 0 ? void 0 : _h[name];
46
+ if (!plugin) {
47
+ throw new Error(`No plugin found for plugin path ${p}`);
48
+ }
49
+ if (typeof plugin === 'function') {
50
+ const stage = (_j = protoGetStageFromName(name)) !== null && _j !== void 0 ? _j : protoGetStageFromName(source);
51
+ if (!stage) {
52
+ throw new Error('Unable to determine plugin stage by name');
53
+ }
54
+ pipeline.plugins.push({
55
+ name,
56
+ source,
57
+ paths,
58
+ plugin: { [stage]: plugin }
59
+ });
60
+ }
61
+ else if (typeof plugin === 'object') {
62
+ pipeline.plugins.push({
63
+ name,
64
+ source,
65
+ paths,
66
+ plugin
67
+ });
68
+ }
69
+ else {
70
+ throw new Error(`Invalid plugin returned from ${p}. ` +
71
+ `A ProtoPipelinePlugin, ProtoPipelineConfigurablePlugin or ` +
72
+ `function should be returned.`);
73
+ }
74
+ }
75
+ if (config.loadDefaultPlugins) {
76
+ pipeline.plugins.push(...getDefaultProtoPipelinePlugins());
77
+ }
78
+ if (config.disablePlugins) {
79
+ for (let i = 0; i < pipeline.plugins.length; i++) {
80
+ const p = pipeline.plugins[i];
81
+ if (config.disablePlugins.includes(p.name)) {
82
+ log(`disabling plugin ${p.name}`);
83
+ pipeline.plugins.splice(i, 1);
84
+ i--;
85
+ }
86
+ }
87
+ }
88
+ onPipelineReady === null || onPipelineReady === void 0 ? void 0 : onPipelineReady(pipeline);
89
+ yield executeTGenPipelineAsync(pipeline);
90
+ //log('context',inspect(pipeline.context,{showHidden:false,depth:20,colors:true}));
91
+ return pipeline;
92
+ }
93
+ finally {
94
+ if (startDir) {
95
+ globalThis.process.chdir(startDir);
96
+ }
97
+ }
98
+ });
99
+ //# sourceMappingURL=runProtogenCliAsync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runProtogenCliAsync.js","sourceRoot":"","sources":["../../../../../../packages/protogen-runtime/src/lib/runProtogenCliAsync.ts"],"names":[],"mappings":";AAAA,OAAO,EAAW,IAAI,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAsC,MAAM,gBAAgB,CAAC;AACrH,OAAO,EAAE,8BAA8B,EAAE,MAAM,mBAAmB,CAAC;AAanE,MAAM,CAAC,MAAM,mBAAmB,GAAC,CAAO,EACpC,MAAM,EACN,IAAI,EACJ,UAAU,EACV,SAAS,EACT,OAAO,EAAE,QAAQ,EACjB,aAAa,EACb,eAAe,GACS,EAAwB,EAAE;;IAElD,IAAI,QAAQ,GAAa,IAAI,CAAC;IAC9B,IAAG,MAAM,CAAC,gBAAgB,IAAI,CAAA,MAAA,UAAU,CAAC,OAAO,0CAAE,KAAK,MAAG,SAAS,IAAI,CAAA,MAAA,UAAU,CAAC,OAAO,0CAAE,GAAG,MAAG,SAAS,EAAC;QACvG,QAAQ,GAAC,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;QAClC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;KACrD;IAED,IAAG;QAEC,MAAM,OAAO,GAAC,MAAA,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAE,MAAM,CAAC,OAAO,mCAAE,KAAK,CAA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;oBACtC,GAAG,CAAC,oBAAoB,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;oBAClC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC;oBAC7B,CAAC,EAAE,CAAC;iBACP;aACJ;SACJ;QAED,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAG,QAAQ,CAAC,CAAC;QAE5B,MAAM,wBAAwB,CAAC,QAAQ,CAAC,CAAC;QAEzC,mFAAmF;QAEnF,OAAO,QAAQ,CAAC;KACnB;YAAO;QACJ,IAAG,QAAQ,EAAC;YACR,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;SACtC;KACJ;AACL,CAAC,CAAA,CAAA"}
@@ -0,0 +1,18 @@
1
+ import { z } from "zod";
2
+ export declare const SharedTsPluginConfigScheme: z.ZodObject<{
3
+ tsSchemePrefix: z.ZodOptional<z.ZodString>;
4
+ /**
5
+ * @default Scheme
6
+ */
7
+ tsSchemeSuffix: z.ZodOptional<z.ZodString>;
8
+ }, "strip", z.ZodTypeAny, {
9
+ tsSchemePrefix?: string | undefined;
10
+ tsSchemeSuffix?: string | undefined;
11
+ }, {
12
+ tsSchemePrefix?: string | undefined;
13
+ tsSchemeSuffix?: string | undefined;
14
+ }>;
15
+ export type SharedTsPluginConfig = z.infer<typeof SharedTsPluginConfigScheme>;
16
+ export declare const defaultTsSchemePrefix = "";
17
+ export declare const defaultTsSchemeSuffix = "Scheme";
18
+ export declare const getTsSchemeName: (name: string, { tsSchemePrefix, tsSchemeSuffix }: SharedTsPluginConfig) => string;
@@ -0,0 +1,12 @@
1
+ import { z } from "zod";
2
+ export const SharedTsPluginConfigScheme = z.object({
3
+ tsSchemePrefix: z.string().optional(),
4
+ /**
5
+ * @default Scheme
6
+ */
7
+ tsSchemeSuffix: z.string().optional(),
8
+ });
9
+ export const defaultTsSchemePrefix = '';
10
+ export const defaultTsSchemeSuffix = 'Scheme';
11
+ export const getTsSchemeName = (name, { tsSchemePrefix = defaultTsSchemePrefix, tsSchemeSuffix = defaultTsSchemeSuffix }) => (`${tsSchemePrefix}${name}${tsSchemeSuffix}`);
12
+ //# sourceMappingURL=sharedTsConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sharedTsConfig.js","sourceRoot":"","sources":["../../../../../../packages/protogen-runtime/src/lib/sharedTsConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,0BAA0B,GAAC,CAAC,CAAC,MAAM,CAChD;IACI,cAAc,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAEpC;;OAEG;IACH,cAAc,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACvC,CAAC,CAAA;AAIF,MAAM,CAAC,MAAM,qBAAqB,GAAC,EAAE,CAAC;AACtC,MAAM,CAAC,MAAM,qBAAqB,GAAC,QAAQ,CAAC;AAE5C,MAAM,CAAC,MAAM,eAAe,GAAC,CAAC,IAAW,EAAC,EACtC,cAAc,GAAC,qBAAqB,EACpC,cAAc,GAAC,qBAAqB,EAClB,EAAC,EAAE,CAAA,CACrB,GAAG,cAAc,GAAG,IAAI,GAAG,cAAc,EAAE,CAC9C,CAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import { __awaiter } from "tslib";
2
+ import { chmod, writeFile } from "fs/promises";
3
+ import { executeProtoPluginAsync } from "../protogen-runtime";
4
+ executeProtoPluginAsync({
5
+ generate: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
6
+ const cmd = ctx.nodes.map(n => `echo ${n.name}`).join('\n') + '\n';
7
+ yield writeFile('./echo-nodes.sh', cmd);
8
+ yield chmod('./echo-nodes.sh', 511);
9
+ console.log('./echo-nodes.sh created');
10
+ })
11
+ });
12
+ //# sourceMappingURL=echo-generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"echo-generator.js","sourceRoot":"","sources":["../../../../../../../packages/protogen-runtime/src/lib/test-plugins/echo-generator.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,uBAAuB,CAAC;IACpB,QAAQ,EAAC,CAAM,GAAG,EAAA,EAAE;QAChB,MAAM,GAAG,GAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA,EAAE,CAAA,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAC,IAAI,CAAC;QAC7D,MAAM,SAAS,CAAC,iBAAiB,EAAC,GAAG,CAAC,CAAC;QACvC,MAAM,KAAK,CAAC,iBAAiB,EAAC,GAAG,CAAC,CAAC;QACnC,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAA;IAC1C,CAAC,CAAA;CACJ,CAAC,CAAA"}
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@iyio/protogen-runtime",
3
+ "version": "0.0.1",
4
+ "dependencies": {
5
+ "date-fns": ">=2.29.3",
6
+ "node-fetch": ">=2.6.9",
7
+ "rxjs": ">=7.8.0",
8
+ "uuid": ">=9.0.0",
9
+ "zod": ">=3.21.4"
10
+ },
11
+ "peerDependencies": {
12
+ "@iyio/common": "^0.2.20",
13
+ "@iyio/node-common": "^0.2.2",
14
+ "@iyio/protogen": "^0.0.1"
15
+ },
16
+ "main": "./src/index.js",
17
+ "types": "./src/index.d.ts",
18
+ "sideEffects": false,
19
+ "module": "./esm/src/index.js"
20
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ export * from './lib/default-plugins';
2
+ export * from "./lib/plugins/fileReader";
3
+ export * from "./lib/plugins/fileWriter";
4
+ export * from "./lib/plugins/functionPlugin";
5
+ export * from "./lib/plugins/markdownParser";
6
+ export * from "./lib/plugins/reactCompPlugin";
7
+ export * from "./lib/plugins/tablePlugin";
8
+ export * from "./lib/plugins/tsConfigPathsPlugin";
9
+ export * from "./lib/plugins/zodPlugin";
10
+ export * from './lib/protogen-runtime';
11
+ export * from './lib/runProtogenCliAsync';
12
+ export * from './lib/sharedTsConfig';
package/src/index.js ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./lib/default-plugins"), exports);
5
+ tslib_1.__exportStar(require("./lib/plugins/fileReader"), exports);
6
+ tslib_1.__exportStar(require("./lib/plugins/fileWriter"), exports);
7
+ tslib_1.__exportStar(require("./lib/plugins/functionPlugin"), exports);
8
+ tslib_1.__exportStar(require("./lib/plugins/markdownParser"), exports);
9
+ tslib_1.__exportStar(require("./lib/plugins/reactCompPlugin"), exports);
10
+ tslib_1.__exportStar(require("./lib/plugins/tablePlugin"), exports);
11
+ tslib_1.__exportStar(require("./lib/plugins/tsConfigPathsPlugin"), exports);
12
+ tslib_1.__exportStar(require("./lib/plugins/zodPlugin"), exports);
13
+ tslib_1.__exportStar(require("./lib/protogen-runtime"), exports);
14
+ tslib_1.__exportStar(require("./lib/runProtogenCliAsync"), exports);
15
+ tslib_1.__exportStar(require("./lib/sharedTsConfig"), exports);
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/protogen-runtime/src/index.ts"],"names":[],"mappings":";;;AAAA,gEAAsC;AACtC,mEAAyC;AACzC,mEAAyC;AACzC,uEAA6C;AAC7C,uEAA6C;AAC7C,wEAA8C;AAC9C,oEAA0C;AAC1C,4EAAkD;AAClD,kEAAwC;AACxC,iEAAuC;AACvC,oEAA0C;AAC1C,+DAAqC"}
@@ -0,0 +1,2 @@
1
+ import { ProtoPipelinePluginInfo } from "@iyio/protogen";
2
+ export declare const getDefaultProtoPipelinePlugins: () => ProtoPipelinePluginInfo[];
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDefaultProtoPipelinePlugins = void 0;
4
+ const fileReader_1 = require("./plugins/fileReader");
5
+ const fileWriter_1 = require("./plugins/fileWriter");
6
+ const functionPlugin_1 = require("./plugins/functionPlugin");
7
+ const markdownParser_1 = require("./plugins/markdownParser");
8
+ const reactCompPlugin_1 = require("./plugins/reactCompPlugin");
9
+ const serverFnPlugin_1 = require("./plugins/serverFnPlugin");
10
+ const tablePlugin_1 = require("./plugins/tablePlugin");
11
+ const tsConfigPathsPlugin_1 = require("./plugins/tsConfigPathsPlugin");
12
+ const zodPlugin_1 = require("./plugins/zodPlugin");
13
+ const getDefaultProtoPipelinePlugins = () => {
14
+ return [
15
+ {
16
+ name: 'fileReader',
17
+ source: '@',
18
+ paths: [],
19
+ plugin: {
20
+ input: fileReader_1.fileReader
21
+ }
22
+ },
23
+ {
24
+ name: 'markdownParser',
25
+ source: '@',
26
+ paths: [],
27
+ plugin: {
28
+ parse: markdownParser_1.markdownParser
29
+ }
30
+ },
31
+ {
32
+ name: 'zodPlugin',
33
+ source: '@',
34
+ paths: [],
35
+ plugin: zodPlugin_1.zodPlugin
36
+ },
37
+ {
38
+ name: 'functionPlugin',
39
+ source: '@',
40
+ paths: [],
41
+ plugin: functionPlugin_1.functionPlugin
42
+ },
43
+ {
44
+ name: 'tablePlugin',
45
+ source: '@',
46
+ paths: [],
47
+ plugin: tablePlugin_1.tablePlugin
48
+ },
49
+ {
50
+ name: 'reactPlugin',
51
+ source: '@',
52
+ paths: [],
53
+ plugin: reactCompPlugin_1.reactCompPlugin
54
+ },
55
+ {
56
+ name: 'serverFnPlugin',
57
+ source: '@',
58
+ paths: [],
59
+ plugin: serverFnPlugin_1.serverFnPlugin
60
+ },
61
+ {
62
+ name: 'fileWriter',
63
+ source: '@',
64
+ paths: [],
65
+ plugin: {
66
+ output: fileWriter_1.fileWriter
67
+ }
68
+ },
69
+ {
70
+ name: 'tsConfigPlugin',
71
+ source: '@',
72
+ paths: [],
73
+ plugin: tsConfigPathsPlugin_1.tsConfigPlugin
74
+ },
75
+ ];
76
+ };
77
+ exports.getDefaultProtoPipelinePlugins = getDefaultProtoPipelinePlugins;
78
+ //# sourceMappingURL=default-plugins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-plugins.js","sourceRoot":"","sources":["../../../../../packages/protogen-runtime/src/lib/default-plugins.ts"],"names":[],"mappings":";;;AACA,qDAAkD;AAClD,qDAAkD;AAClD,6DAA0D;AAC1D,6DAA0D;AAC1D,+DAA4D;AAC5D,6DAA0D;AAC1D,uDAAoD;AACpD,uEAA+D;AAC/D,mDAAgD;AAEzC,MAAM,8BAA8B,GAAC,GAA4B,EAAE;IACtE,OAAO;QACH;YACI,IAAI,EAAC,YAAY;YACjB,MAAM,EAAC,GAAG;YACV,KAAK,EAAC,EAAE;YACR,MAAM,EAAC;gBACH,KAAK,EAAC,uBAAU;aACnB;SACJ;QACD;YACI,IAAI,EAAC,gBAAgB;YACrB,MAAM,EAAC,GAAG;YACV,KAAK,EAAC,EAAE;YACR,MAAM,EAAC;gBACH,KAAK,EAAC,+BAAc;aACvB;SACJ;QACD;YACI,IAAI,EAAC,WAAW;YAChB,MAAM,EAAC,GAAG;YACV,KAAK,EAAC,EAAE;YACR,MAAM,EAAC,qBAAS;SACnB;QACD;YACI,IAAI,EAAC,gBAAgB;YACrB,MAAM,EAAC,GAAG;YACV,KAAK,EAAC,EAAE;YACR,MAAM,EAAC,+BAAc;SACxB;QACD;YACI,IAAI,EAAC,aAAa;YAClB,MAAM,EAAC,GAAG;YACV,KAAK,EAAC,EAAE;YACR,MAAM,EAAC,yBAAW;SACrB;QACD;YACI,IAAI,EAAC,aAAa;YAClB,MAAM,EAAC,GAAG;YACV,KAAK,EAAC,EAAE;YACR,MAAM,EAAC,iCAAe;SACzB;QACD;YACI,IAAI,EAAC,gBAAgB;YACrB,MAAM,EAAC,GAAG;YACV,KAAK,EAAC,EAAE;YACR,MAAM,EAAC,+BAAc;SACxB;QACD;YACI,IAAI,EAAC,YAAY;YACjB,MAAM,EAAC,GAAG;YACV,KAAK,EAAC,EAAE;YACR,MAAM,EAAC;gBACH,MAAM,EAAC,uBAAU;aACpB;SACJ;QACD;YACI,IAAI,EAAC,gBAAgB;YACrB,MAAM,EAAC,GAAG;YACV,KAAK,EAAC,EAAE;YACR,MAAM,EAAC,oCAAc;SACxB;KACJ,CAAC;AACN,CAAC,CAAA;AA/DY,QAAA,8BAA8B,kCA+D1C"}
@@ -0,0 +1,26 @@
1
+ import { ProtoPipelineConfigurablePlugin } from "@iyio/protogen";
2
+ import { z } from "zod";
3
+ declare const ExamplePluginConfig: z.ZodObject<{
4
+ /**
5
+ * @default .examplePackage
6
+ */
7
+ examplePath: z.ZodOptional<z.ZodString>;
8
+ /**
9
+ * @default "examples"
10
+ */
11
+ examplePackage: z.ZodOptional<z.ZodString>;
12
+ /**
13
+ * @default "examples-index.ts"
14
+ */
15
+ exampleIndexFilename: z.ZodOptional<z.ZodString>;
16
+ }, "strip", z.ZodTypeAny, {
17
+ examplePath?: string | undefined;
18
+ examplePackage?: string | undefined;
19
+ exampleIndexFilename?: string | undefined;
20
+ }, {
21
+ examplePath?: string | undefined;
22
+ examplePackage?: string | undefined;
23
+ exampleIndexFilename?: string | undefined;
24
+ }>;
25
+ export declare const examplePlugin: ProtoPipelineConfigurablePlugin<typeof ExamplePluginConfig>;
26
+ export {};
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.examplePlugin = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@iyio/common");
6
+ const protogen_1 = require("@iyio/protogen");
7
+ const zod_1 = require("zod");
8
+ const supportedTypes = ['example'];
9
+ const ExamplePluginConfig = zod_1.z.object({
10
+ /**
11
+ * @default .examplePackage
12
+ */
13
+ examplePath: zod_1.z.string().optional(),
14
+ /**
15
+ * @default "examples"
16
+ */
17
+ examplePackage: zod_1.z.string().optional(),
18
+ /**
19
+ * @default "examples-index.ts"
20
+ */
21
+ exampleIndexFilename: zod_1.z.string().optional(),
22
+ });
23
+ exports.examplePlugin = {
24
+ configScheme: ExamplePluginConfig,
25
+ generate: ({ importMap, outputs, tab, log, nodes, namespace, packagePaths, }, { examplePackage = 'examples', examplePath = examplePackage, exampleIndexFilename = 'examples-index.ts', }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
26
+ var _a, _b, _c;
27
+ const { path, packageName } = (0, protogen_1.getProtoPluginPackAndPath)(namespace, examplePackage, examplePath, { packagePaths, indexFilename: exampleIndexFilename });
28
+ const supported = nodes.filter(n => supportedTypes.includes(n.type));
29
+ log(`${supported.length} supported node(s)`);
30
+ if (!supported.length) {
31
+ return;
32
+ }
33
+ for (const node of supported) {
34
+ const out = [];
35
+ const imports = [];
36
+ const name = node.name;
37
+ // export name under packageName
38
+ importMap[name] = packageName;
39
+ out.push('');
40
+ if (node.comment) {
41
+ out.push(...(0, protogen_1.protoFormatTsComment)(node.comment, '').split('\n'));
42
+ }
43
+ const idType = (_c = (_b = (_a = node.children) === null || _a === void 0 ? void 0 : _a['id']) === null || _b === void 0 ? void 0 : _b.type) !== null && _c !== void 0 ? _c : 'string';
44
+ if (!(0, protogen_1.protoIsTsBuiltType)(idType)) {
45
+ imports.push(idType);
46
+ }
47
+ out.push(`export class ${name}`);
48
+ out.push('{');
49
+ out.push(`${tab}id?:${idType};`);
50
+ out.push('}');
51
+ (0, protogen_1.protoPrependTsImports)(imports, importMap, out);
52
+ outputs.push({
53
+ path: (0, common_1.joinPaths)(path, name + '.ts'),
54
+ content: out.join('\n')
55
+ });
56
+ }
57
+ // add index file
58
+ outputs.push({
59
+ path: (0, common_1.joinPaths)(path, exampleIndexFilename),
60
+ content: '',
61
+ generator: {
62
+ root: path,
63
+ generator: protogen_1.protoGenerateTsIndex
64
+ }
65
+ });
66
+ })
67
+ };
68
+ //# sourceMappingURL=examplePlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"examplePlugin.js","sourceRoot":"","sources":["../../../../../../packages/protogen-runtime/src/lib/plugins/examplePlugin.ts"],"names":[],"mappings":";;;;AAAA,yCAAyC;AACzC,6CAAmL;AACnL,6BAAwB;AAExB,MAAM,cAAc,GAAC,CAAC,SAAS,CAAC,CAAC;AAEjC,MAAM,mBAAmB,GAAC,OAAC,CAAC,MAAM,CAClC;IACI;;OAEG;IACH,WAAW,EAAC,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAEjC;;OAEG;IACH,cAAc,EAAC,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAEpC;;OAEG;IACH,oBAAoB,EAAC,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC7C,CAAC,CAAA;AAEW,QAAA,aAAa,GAC1B;IACI,YAAY,EAAC,mBAAmB;IAChC,QAAQ,EAAC,CAAO,EACZ,SAAS,EACT,OAAO,EACP,GAAG,EACH,GAAG,EACH,KAAK,EACL,SAAS,EACT,YAAY,GACf,EAAC,EACE,cAAc,GAAC,UAAU,EACzB,WAAW,GAAC,cAAc,EAC1B,oBAAoB,GAAC,mBAAmB,GAC3C,EAAC,EAAE;;QAEA,MAAM,EAAC,IAAI,EAAC,WAAW,EAAC,GAAC,IAAA,oCAAyB,EAC9C,SAAS,EACT,cAAc,EACd,WAAW,EACX,EAAC,YAAY,EAAC,aAAa,EAAC,oBAAoB,EAAC,CACpD,CAAC;QAEF,MAAM,SAAS,GAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA,EAAE,CAAA,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QAEjE,GAAG,CAAC,GAAG,SAAS,CAAC,MAAM,oBAAoB,CAAC,CAAC;QAC7C,IAAG,CAAC,SAAS,CAAC,MAAM,EAAC;YACjB,OAAO;SACV;QAGD,KAAI,MAAM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AC,oBAAoB,CAAC;YACzC,OAAO,EAAC,EAAE;YACV,SAAS,EAAC;gBACN,IAAI,EAAC,IAAI;gBACT,SAAS,EAAC,+BAAoB;aACjC;SACJ,CAAC,CAAA;IACN,CAAC,CAAA;CACJ,CAAA"}
@@ -0,0 +1,2 @@
1
+ import { ProtoContext } from "@iyio/protogen";
2
+ export declare const fileReader: ({ log, inputs, sources }: ProtoContext) => Promise<void>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fileReader = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@iyio/common");
6
+ const promises_1 = require("fs/promises");
7
+ const fileReader = ({ log, inputs, sources }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
8
+ var _a;
9
+ for (const _input of inputs) {
10
+ const proto = common_1.protocolReg.exec(_input);
11
+ if (proto && ((_a = proto[1]) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== 'file') {
12
+ continue;
13
+ }
14
+ const input = proto ? _input.substring("file://".length) : _input;
15
+ log(`read - ${input}`);
16
+ const content = (yield (0, promises_1.readFile)(input)).toString();
17
+ log(`${input} - ${content.length / 1000}kb`);
18
+ sources.push({
19
+ input,
20
+ ext: (0, common_1.getFileExt)(input, false, true),
21
+ content,
22
+ });
23
+ }
24
+ });
25
+ exports.fileReader = fileReader;
26
+ //# sourceMappingURL=fileReader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fileReader.js","sourceRoot":"","sources":["../../../../../../packages/protogen-runtime/src/lib/plugins/fileReader.ts"],"names":[],"mappings":";;;;AAAA,yCAAuD;AAEvD,0CAAuC;AAGhC,MAAM,UAAU,GAAC,CAAO,EAC3B,GAAG,EACH,MAAM,EACN,OAAO,EACG,EAAC,EAAE;;IACb,KAAI,MAAM,MAAM,IAAI,MAAM,EAAC;QACvB,MAAM,KAAK,GAAC,oBAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACrC,IAAG,KAAK,IAAI,CAAA,MAAA,KAAK,CAAC,CAAC,CAAC,0CAAE,WAAW,EAAE,MAAG,MAAM,EAAC;YACzC,SAAS;SACZ;QACD,MAAM,KAAK,GAAC,KAAK,CAAA,CAAC,CAAA,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA,CAAC,CAAA,MAAM,CAAC;QAC5D,GAAG,CAAC,UAAU,KAAK,EAAE,CAAC,CAAC;QAEvB,MAAM,OAAO,GAAC,CAAC,MAAM,IAAA,mBAAQ,EAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;QAEjD,GAAG,CAAC,GAAG,KAAK,MAAM,OAAO,CAAC,MAAM,GAAC,IAAI,IAAI,CAAC,CAAC;QAE3C,OAAO,CAAC,IAAI,CAAC;YACT,KAAK;YACL,GAAG,EAAC,IAAA,mBAAU,EAAC,KAAK,EAAC,KAAK,EAAC,IAAI,CAAC;YAChC,OAAO;SACV,CAAC,CAAA;KAEL;AACL,CAAC,CAAA,CAAA;AAxBY,QAAA,UAAU,cAwBtB"}
@@ -0,0 +1,2 @@
1
+ import { ProtoContext } from "@iyio/protogen";
2
+ export declare const fileWriter: (ctx: ProtoContext) => Promise<void>;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fileWriter = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@iyio/common");
6
+ const node_common_1 = require("@iyio/node-common");
7
+ const protogen_1 = require("@iyio/protogen");
8
+ const promises_1 = require("fs/promises");
9
+ const path_1 = require("path");
10
+ const fileWriter = (ctx) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
11
+ const { log, outputs, dryRun, } = ctx;
12
+ if (dryRun) {
13
+ log('### DRY RUN');
14
+ }
15
+ for (const output of outputs) {
16
+ const name = (0, common_1.unrootPath)(output.path);
17
+ if (!name) {
18
+ continue;
19
+ }
20
+ if (name.includes('/') || name.includes('\\')) {
21
+ const dirName = (0, path_1.dirname)(name);
22
+ if (!(yield (0, node_common_1.pathExistsAsync)(dirName))) {
23
+ if (!dryRun) {
24
+ yield (0, promises_1.mkdir)(dirName, { recursive: true });
25
+ }
26
+ }
27
+ }
28
+ if (output.generator) {
29
+ output.content = yield output.generator.generator(ctx, output.generator, output);
30
+ }
31
+ const mergers = output.mergeHandler ? (0, common_1.asArray)(output.mergeHandler) : null;
32
+ if ((output.autoMerge || mergers) && (yield (0, node_common_1.pathExistsAsync)(name))) {
33
+ const existing = (yield (0, promises_1.readFile)(name)).toString();
34
+ const contentLines = output.content.split('\n');
35
+ (0, protogen_1.protoMergeTsImports)({ existing, overwriting: contentLines });
36
+ let mergedLines = (output.autoMerge ?
37
+ (0, protogen_1.protoMergeSourceCode)({ existing, overwriting: contentLines }) :
38
+ existing.split('\n'));
39
+ if (mergers) {
40
+ for (const merger of mergers) {
41
+ if (merger) {
42
+ mergedLines = merger({ existing: mergedLines, overwriting: contentLines });
43
+ }
44
+ }
45
+ }
46
+ const content = mergedLines.join('\n');
47
+ log(`write merged - ${name} - ${content.length / 1000}kb`);
48
+ if (!dryRun) {
49
+ yield (0, promises_1.writeFile)(name, content);
50
+ }
51
+ }
52
+ else {
53
+ log(`write - ${name} - ${output.content.length / 1000}kb`);
54
+ if (!dryRun) {
55
+ yield (0, promises_1.writeFile)(name, output.content);
56
+ }
57
+ }
58
+ }
59
+ });
60
+ exports.fileWriter = fileWriter;
61
+ //# sourceMappingURL=fileWriter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fileWriter.js","sourceRoot":"","sources":["../../../../../../packages/protogen-runtime/src/lib/plugins/fileWriter.ts"],"names":[],"mappings":";;;;AAAA,yCAAmD;AACnD,mDAAoD;AACpD,6CAAyF;AACzF,0CAAyD;AACzD,+BAA+B;AAExB,MAAM,UAAU,GAAC,CAAO,GAAgB,EAAC,EAAE;IAE9C,MAAM,EACF,GAAG,EACH,OAAO,EACP,MAAM,GACT,GAAC,GAAG,CAA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AAC,WAAW,EAAC,YAAY,EAAC,CAAC,CAAA;YAExD,IAAI,WAAW,GAAC,CAAC,MAAM,CAAC,SAAS,CAAA,CAAC;gBAC9B,IAAA,+BAAoB,EAAC,EAAC,QAAQ,EAAC,WAAW,EAAC,YAAY,EAAC,CAAC,CAAA,CAAC;gBAC1D,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CACvB,CAAA;YAED,IAAG,OAAO,EAAC;gBACP,KAAI,MAAM,MAAM,IAAI,OAAO,EAAC;oBACxB,IAAG,MAAM,EAAC;wBACN,WAAW,GAAC,MAAM,CAAC,EAAC,QAAQ,EAAC,WAAW,EAAC,WAAW,EAAC,YAAY,EAAC,CAAC,CAAC;qBACvE;iBACJ;aACJ;YAGD,MAAM,OAAO,GAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACrC,GAAG,CAAC,kBAAkB,IAAI,MAAM,OAAO,CAAC,MAAM,GAAC,IAAI,IAAI,CAAC,CAAC;YACzD,IAAG,CAAC,MAAM,EAAC;gBACP,MAAM,IAAA,oBAAS,EAAC,IAAI,EAAC,OAAO,CAAC,CAAC;aACjC;SAEJ;aAAI;YACD,GAAG,CAAC,WAAW,IAAI,MAAM,MAAM,CAAC,OAAO,CAAC,MAAM,GAAC,IAAI,IAAI,CAAC,CAAC;YACzD,IAAG,CAAC,MAAM,EAAC;gBACP,MAAM,IAAA,oBAAS,EAAC,IAAI,EAAC,MAAM,CAAC,OAAO,CAAC,CAAC;aACxC;SACJ;KACJ;AAEL,CAAC,CAAA,CAAA;AApEY,QAAA,UAAU,cAoEtB"}
@@ -0,0 +1,26 @@
1
+ import { ProtoPipelineConfigurablePlugin } from "@iyio/protogen";
2
+ import { z } from "zod";
3
+ declare const FunctionPluginConfig: z.ZodObject<{
4
+ /**
5
+ * @default .functionPackage
6
+ */
7
+ functionPath: z.ZodOptional<z.ZodString>;
8
+ /**
9
+ * @default "functions"
10
+ */
11
+ functionPackage: z.ZodOptional<z.ZodString>;
12
+ /**
13
+ * @default "functions-index.ts"
14
+ */
15
+ functionIndexFilename: z.ZodOptional<z.ZodString>;
16
+ }, "strip", z.ZodTypeAny, {
17
+ functionPath?: string | undefined;
18
+ functionPackage?: string | undefined;
19
+ functionIndexFilename?: string | undefined;
20
+ }, {
21
+ functionPath?: string | undefined;
22
+ functionPackage?: string | undefined;
23
+ functionIndexFilename?: string | undefined;
24
+ }>;
25
+ export declare const functionPlugin: ProtoPipelineConfigurablePlugin<typeof FunctionPluginConfig>;
26
+ export {};
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.functionPlugin = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@iyio/common");
6
+ const protogen_1 = require("@iyio/protogen");
7
+ const zod_1 = require("zod");
8
+ const supportedTypes = ['function'];
9
+ const FunctionPluginConfig = zod_1.z.object({
10
+ /**
11
+ * @default .functionPackage
12
+ */
13
+ functionPath: zod_1.z.string().optional(),
14
+ /**
15
+ * @default "functions"
16
+ */
17
+ functionPackage: zod_1.z.string().optional(),
18
+ /**
19
+ * @default "functions-index.ts"
20
+ */
21
+ functionIndexFilename: zod_1.z.string().optional(),
22
+ });
23
+ exports.functionPlugin = {
24
+ configScheme: FunctionPluginConfig,
25
+ generate: ({ importMap, outputs, tab, log, nodes, namespace, packagePaths, }, { functionPackage = 'functions', functionPath = functionPackage, functionIndexFilename = 'functions-index.ts', }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
26
+ var _a, _b, _c, _d;
27
+ const { path, packageName } = (0, protogen_1.getProtoPluginPackAndPath)(namespace, functionPackage, functionPath, { packagePaths, indexFilename: functionIndexFilename });
28
+ const supported = nodes.filter(n => supportedTypes.includes(n.type));
29
+ log(`${supported.length} supported node(s)`);
30
+ for (const node of supported) {
31
+ const out = [];
32
+ const imports = [];
33
+ out.push('');
34
+ if (node.comment) {
35
+ out.push(...(0, protogen_1.protoFormatTsComment)(node.comment, '').split('\n'));
36
+ }
37
+ const name = node.name;
38
+ // export name using packageName
39
+ importMap[name] = packageName;
40
+ const isAsync = name.toLowerCase().endsWith('async') || ((_a = node.children) === null || _a === void 0 ? void 0 : _a['async']) !== undefined;
41
+ const args = (0, protogen_1.protoGetChildren)((_b = node.children) === null || _b === void 0 ? void 0 : _b['args'], false);
42
+ const returnTypeBase = ((_d = (_c = node.children) === null || _c === void 0 ? void 0 : _c['return']) === null || _d === void 0 ? void 0 : _d.type) || 'void';
43
+ const returnType = isAsync ? `Promise<${returnTypeBase}>` : returnTypeBase;
44
+ if (!(0, protogen_1.protoIsTsBuiltType)(returnTypeBase)) {
45
+ imports.push(returnTypeBase);
46
+ }
47
+ const startI = out.length;
48
+ const oneLiner = `export const ${name}=${isAsync ? 'async ' : ''}(${args.map(a => `${a.name}:${a.type}`).join(', ')}):${returnType}=>`;
49
+ if (oneLiner.length <= 90 || args.length === 0) {
50
+ out.push(oneLiner);
51
+ out.push('{');
52
+ }
53
+ else {
54
+ out.push(`export const ${name}=${isAsync ? 'async ' : ''}(`);
55
+ for (let a = 0; a < args.length; a++) {
56
+ const arg = args[a];
57
+ out.push(`${tab}${arg.name}:${arg.type}${a === args.length - 1 ? '' : ','}`);
58
+ }
59
+ out.push(`):${returnType}=>{`);
60
+ }
61
+ (0, protogen_1.protoLabelOutputLines)(out, 'function', startI);
62
+ out.push(`${tab}// ${name}`);
63
+ out.push('}');
64
+ if (imports.length) {
65
+ (0, protogen_1.protoPrependTsImports)(imports, importMap, out);
66
+ }
67
+ outputs.push({
68
+ path: (0, common_1.joinPaths)(path, name + '.ts'),
69
+ content: out.join('\n')
70
+ });
71
+ }
72
+ outputs.push({
73
+ path: (0, common_1.joinPaths)(path, functionIndexFilename),
74
+ content: '',
75
+ generator: {
76
+ root: path,
77
+ generator: protogen_1.protoGenerateTsIndex
78
+ }
79
+ });
80
+ })
81
+ };
82
+ //# sourceMappingURL=functionPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functionP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