@codenotch/codenotch.cli 1.0.35 → 1.0.37

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 (149) hide show
  1. package/README.md +2 -2
  2. package/dist/commands/generate/app.d.ts +2 -0
  3. package/dist/commands/generate/app.js +45 -0
  4. package/dist/commands/generate/app.js.map +1 -0
  5. package/dist/commands/generate/appmanifest.d.ts +2 -0
  6. package/dist/commands/generate/appmanifest.js +34 -0
  7. package/dist/commands/generate/appmanifest.js.map +1 -0
  8. package/dist/commands/generate/dbcontext.d.ts +2 -0
  9. package/dist/commands/generate/dbcontext.js +32 -0
  10. package/dist/commands/generate/dbcontext.js.map +1 -0
  11. package/dist/commands/generate/i18n.d.ts +2 -0
  12. package/dist/commands/generate/i18n.js +29 -0
  13. package/dist/commands/generate/i18n.js.map +1 -0
  14. package/dist/commands/generate/index.d.ts +2 -0
  15. package/dist/commands/generate/index.js +23 -0
  16. package/dist/commands/generate/index.js.map +1 -0
  17. package/dist/commands/generate/manifest.d.ts +2 -0
  18. package/dist/commands/generate/manifest.js +29 -0
  19. package/dist/commands/generate/manifest.js.map +1 -0
  20. package/dist/commands/generate/openapi.d.ts +2 -0
  21. package/dist/commands/generate/openapi.js +32 -0
  22. package/dist/commands/generate/openapi.js.map +1 -0
  23. package/dist/commands/generate/pkg.d.ts +2 -0
  24. package/dist/commands/generate/pkg.js +34 -0
  25. package/dist/commands/generate/pkg.js.map +1 -0
  26. package/dist/commands/generate/shared.d.ts +17 -0
  27. package/dist/commands/generate/shared.js +70 -0
  28. package/dist/commands/generate/shared.js.map +1 -0
  29. package/dist/commands/index.js +2 -0
  30. package/dist/commands/index.js.map +1 -1
  31. package/dist/commands/project/new.js +107 -187
  32. package/dist/commands/project/new.js.map +1 -1
  33. package/dist/commands/react/build.js +11 -5
  34. package/dist/commands/react/build.js.map +1 -1
  35. package/dist/commands/react/clean.d.ts +2 -0
  36. package/dist/commands/react/clean.js +46 -0
  37. package/dist/commands/react/clean.js.map +1 -0
  38. package/dist/commands/react/dev.d.ts +2 -0
  39. package/dist/commands/react/dev.js +27 -0
  40. package/dist/commands/react/dev.js.map +1 -0
  41. package/dist/commands/react/index.js +5 -1
  42. package/dist/commands/react/index.js.map +1 -1
  43. package/dist/commands/react/serve.js +33 -4
  44. package/dist/commands/react/serve.js.map +1 -1
  45. package/dist/commands/react/shared.d.ts +21 -0
  46. package/dist/commands/react/shared.js +80 -0
  47. package/dist/commands/react/shared.js.map +1 -0
  48. package/dist/commands/system/info.js +0 -7
  49. package/dist/commands/system/info.js.map +1 -1
  50. package/dist/commands/validation/ValidationUtils.d.ts +3 -13
  51. package/dist/commands/validation/ValidationUtils.js +5 -58
  52. package/dist/commands/validation/ValidationUtils.js.map +1 -1
  53. package/dist/commands/validation/files/AppManifestValidator.js +5 -20
  54. package/dist/commands/validation/files/AppManifestValidator.js.map +1 -1
  55. package/dist/commands/validation/files/I18nValidator.d.ts +24 -0
  56. package/dist/commands/validation/files/I18nValidator.js +190 -5
  57. package/dist/commands/validation/files/I18nValidator.js.map +1 -1
  58. package/dist/commands/validation/files/{BpmnValidator.d.ts → ProjectManifestValidator.d.ts} +1 -1
  59. package/dist/commands/validation/files/ProjectManifestValidator.js +31 -0
  60. package/dist/commands/validation/files/ProjectManifestValidator.js.map +1 -0
  61. package/dist/commands/validation/files/ScriptValidator.d.ts +6 -2
  62. package/dist/commands/validation/files/ScriptValidator.js +1 -1
  63. package/dist/commands/validation/files/ScriptValidator.js.map +1 -1
  64. package/dist/commands/validation/validate.js +15 -46
  65. package/dist/commands/validation/validate.js.map +1 -1
  66. package/dist/models/Codenotch.d.ts +0 -205
  67. package/dist/models/Codenotch.js +0 -211
  68. package/dist/models/Codenotch.js.map +1 -1
  69. package/dist/utils/BuildUtils.d.ts +66 -28
  70. package/dist/utils/BuildUtils.js +292 -330
  71. package/dist/utils/BuildUtils.js.map +1 -1
  72. package/dist/utils/ConsoleUtils.d.ts +13 -0
  73. package/dist/utils/ConsoleUtils.js +50 -0
  74. package/dist/utils/ConsoleUtils.js.map +1 -1
  75. package/dist/utils/DbSchemaUtils.d.ts +49 -0
  76. package/dist/utils/DbSchemaUtils.js +246 -0
  77. package/dist/utils/DbSchemaUtils.js.map +1 -0
  78. package/dist/utils/FileUtils.d.ts +104 -15
  79. package/dist/utils/FileUtils.js +285 -100
  80. package/dist/utils/FileUtils.js.map +1 -1
  81. package/dist/utils/GitHubAuthUtils.js.map +1 -1
  82. package/dist/utils/I18nTsUtils.d.ts +66 -0
  83. package/dist/utils/I18nTsUtils.js +221 -0
  84. package/dist/utils/I18nTsUtils.js.map +1 -0
  85. package/dist/utils/ManifestUtils.d.ts +24 -0
  86. package/dist/utils/ManifestUtils.js +53 -0
  87. package/dist/utils/ManifestUtils.js.map +1 -0
  88. package/dist/utils/OpenApiUtils.d.ts +81 -0
  89. package/dist/utils/OpenApiUtils.js +123 -0
  90. package/dist/utils/OpenApiUtils.js.map +1 -0
  91. package/dist/utils/ProjectCompilationUtils.d.ts +3 -30
  92. package/dist/utils/ProjectCompilationUtils.js +26 -760
  93. package/dist/utils/ProjectCompilationUtils.js.map +1 -1
  94. package/dist/utils/ProjectGeneratorUtils.d.ts +35 -0
  95. package/dist/utils/ProjectGeneratorUtils.js +119 -0
  96. package/dist/utils/ProjectGeneratorUtils.js.map +1 -0
  97. package/dist/utils/ProjectTemplates.d.ts +102 -0
  98. package/dist/utils/ProjectTemplates.js +284 -0
  99. package/dist/utils/ProjectTemplates.js.map +1 -0
  100. package/dist/utils/ProjectUtils.d.ts +217 -4
  101. package/dist/utils/ProjectUtils.js +386 -50
  102. package/dist/utils/ProjectUtils.js.map +1 -1
  103. package/dist/utils/RuntimeUtils.js +14 -8
  104. package/dist/utils/RuntimeUtils.js.map +1 -1
  105. package/dist/utils/ScriptDeclarationUtils.d.ts +169 -0
  106. package/dist/utils/ScriptDeclarationUtils.js +398 -0
  107. package/dist/utils/ScriptDeclarationUtils.js.map +1 -0
  108. package/dist/utils/ServeUtils.d.ts +0 -1
  109. package/dist/utils/ServeUtils.js +11 -29
  110. package/dist/utils/ServeUtils.js.map +1 -1
  111. package/dist/utils/ShellUtils.d.ts +6 -0
  112. package/dist/utils/ShellUtils.js +13 -0
  113. package/dist/utils/ShellUtils.js.map +1 -1
  114. package/dist/utils/TemplateUtils.d.ts +62 -0
  115. package/dist/utils/TemplateUtils.js +218 -0
  116. package/dist/utils/TemplateUtils.js.map +1 -0
  117. package/dist/utils/TypeSchemaUtils.d.ts +42 -0
  118. package/dist/utils/TypeSchemaUtils.js +171 -0
  119. package/dist/utils/TypeSchemaUtils.js.map +1 -0
  120. package/package.json +3 -3
  121. package/dist/commands/validation/files/BpmnValidator.js +0 -32
  122. package/dist/commands/validation/files/BpmnValidator.js.map +0 -1
  123. package/dist/commands/validation/files/DbSchemaValidator.d.ts +0 -5
  124. package/dist/commands/validation/files/DbSchemaValidator.js +0 -16
  125. package/dist/commands/validation/files/DbSchemaValidator.js.map +0 -1
  126. package/dist/commands/validation/files/DocumentValidator.d.ts +0 -5
  127. package/dist/commands/validation/files/DocumentValidator.js +0 -12
  128. package/dist/commands/validation/files/DocumentValidator.js.map +0 -1
  129. package/dist/commands/validation/files/ManifestCacheValidator.d.ts +0 -5
  130. package/dist/commands/validation/files/ManifestCacheValidator.js +0 -121
  131. package/dist/commands/validation/files/ManifestCacheValidator.js.map +0 -1
  132. package/dist/commands/validation/files/ManifestValidator.d.ts +0 -5
  133. package/dist/commands/validation/files/ManifestValidator.js +0 -14
  134. package/dist/commands/validation/files/ManifestValidator.js.map +0 -1
  135. package/dist/commands/validation/files/TableValidator.d.ts +0 -5
  136. package/dist/commands/validation/files/TableValidator.js +0 -19
  137. package/dist/commands/validation/files/TableValidator.js.map +0 -1
  138. package/dist/models/DbModels.d.ts +0 -221
  139. package/dist/models/DbModels.js +0 -130
  140. package/dist/models/DbModels.js.map +0 -1
  141. package/dist/models/OpenApiModels.d.ts +0 -115
  142. package/dist/models/OpenApiModels.js +0 -103
  143. package/dist/models/OpenApiModels.js.map +0 -1
  144. package/dist/utils/I18nUtils.d.ts +0 -9
  145. package/dist/utils/I18nUtils.js +0 -54
  146. package/dist/utils/I18nUtils.js.map +0 -1
  147. package/dist/utils/OpenAPIUtils.d.ts +0 -33
  148. package/dist/utils/OpenAPIUtils.js +0 -279
  149. package/dist/utils/OpenAPIUtils.js.map +0 -1
@@ -0,0 +1,221 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs_1 = require("fs");
4
+ const path_1 = require("path");
5
+ /**
6
+ * Generate an importable TypeScript class from the entries of a *.i18n.csv file.
7
+ *
8
+ * The generated class exposes one static method per translation key, e.g. for:
9
+ * key,en,de
10
+ * ,,
11
+ * userWelcome,hello,hallo
12
+ * hiMr,hello mister {0},hallo herr {0}
13
+ * we get `hello.userWelcome()` and `hello.hiMr(arg1)`.
14
+ *
15
+ * The file is fully regenerated on each run, it must not be edited by hand.
16
+ */
17
+ class I18nTsUtils {
18
+ static RESERVED_MEMBERS = ['values', 'lang', 'setLanguage', 'getValue'];
19
+ static PLACEHOLDER_REGEX = /\{(\d+)\}/g;
20
+ static INDENT = ' ';
21
+ /**
22
+ * Converts a *.i18n.csv file name (or path) into a valid class name, e.g. 'src/hello.i18n.csv' => 'hello'
23
+ */
24
+ static getClassName(fileNameOrPath) {
25
+ const fileName = fileNameOrPath.replaceAll('\\', '/').split('/').pop() ?? '';
26
+ const name = fileName.replace(/\.i18n\.csv$/i, '').replace(/\.csv$/i, '');
27
+ return this.toIdentifier(name) || 'I18n';
28
+ }
29
+ /**
30
+ * Keeps only the real translation entries of a parsed csv: the rows without key are ignored
31
+ * (the csv may still contain a leading empty row, kept for readability).
32
+ */
33
+ static getEntries(lines) {
34
+ const entries = [];
35
+ for (const line of lines) {
36
+ const key = (line.key ?? '').trim();
37
+ if (key === '') {
38
+ continue;
39
+ }
40
+ entries.push({ ...line, key });
41
+ }
42
+ return entries;
43
+ }
44
+ /**
45
+ * Generates the TypeScript class.
46
+ * @param className name of the generated class
47
+ * @param sourceFileName name of the *.i18n.csv the class is generated from (mentioned in the file header)
48
+ * @param entries translation entries (see getEntries)
49
+ */
50
+ static generate(className, sourceFileName, entries) {
51
+ const warnings = [];
52
+ const languages = this.getLanguages(entries);
53
+ const valuesBlock = this.generateValuesBlock(entries, languages);
54
+ const methodsBlock = this.generateMethodsBlock(entries, languages, warnings);
55
+ return { content: this.generateTemplate(className, sourceFileName, languages[0] ?? 'en', valuesBlock, methodsBlock), warnings };
56
+ }
57
+ /**
58
+ * Languages in csv column order (every column except 'key', papaparse internals are ignored)
59
+ */
60
+ static getLanguages(entries) {
61
+ const languages = [];
62
+ for (const entry of entries) {
63
+ for (const column of Object.keys(entry)) {
64
+ if (column === 'key' || column.startsWith('__') || languages.includes(column)) {
65
+ continue;
66
+ }
67
+ languages.push(column);
68
+ }
69
+ }
70
+ return languages;
71
+ }
72
+ static generateValuesBlock(entries, languages) {
73
+ const i = this.INDENT;
74
+ const lines = [];
75
+ lines.push(`${i}static values: { [key: string]: { [lang: string]: string } } = {`);
76
+ for (const entry of entries) {
77
+ const values = languages
78
+ .filter(lang => (entry[lang] ?? '').trim() !== '')
79
+ .map(lang => `${i}${i}${i}${JSON.stringify(lang)}: ${JSON.stringify(entry[lang])}`);
80
+ lines.push(`${i}${i}${JSON.stringify(entry.key)}: {`);
81
+ if (values.length > 0) {
82
+ lines.push(values.join(',\n'));
83
+ }
84
+ lines.push(`${i}${i}},`);
85
+ }
86
+ lines.push(`${i}};`);
87
+ return lines.join('\n');
88
+ }
89
+ static generateMethodsBlock(entries, languages, warnings) {
90
+ const i = this.INDENT;
91
+ const lines = [];
92
+ const usedNames = new Set();
93
+ for (const entry of entries) {
94
+ let methodName = this.toIdentifier(entry.key);
95
+ if (methodName !== entry.key) {
96
+ warnings.push(`Key '${entry.key}' is not a valid identifier, method '${methodName}' generated instead.`);
97
+ }
98
+ if (this.RESERVED_MEMBERS.includes(methodName)) {
99
+ warnings.push(`Key '${entry.key}' conflicts with a reserved member, method '${methodName}_' generated instead.`);
100
+ methodName = `${methodName}_`;
101
+ }
102
+ if (usedNames.has(methodName)) {
103
+ warnings.push(`Key '${entry.key}' produces the duplicated method '${methodName}', skipped.`);
104
+ continue;
105
+ }
106
+ usedNames.add(methodName);
107
+ const argCount = this.getArgCount(languages.map(lang => entry[lang] ?? ''));
108
+ const argNames = Array.from({ length: argCount }, (_, index) => `arg${index + 1}`);
109
+ const signature = argNames.map(name => `${name}: string`).join(', ');
110
+ const callArgs = [JSON.stringify(entry.key), ...argNames].join(', ');
111
+ lines.push(`${i}/**`);
112
+ for (const lang of languages) {
113
+ const value = (entry[lang] ?? '').trim();
114
+ if (value !== '') {
115
+ lines.push(`${i} * ${lang.toUpperCase()}: ${this.toCommentText(value)}`);
116
+ }
117
+ }
118
+ lines.push(`${i} */`);
119
+ lines.push(`${i}static ${methodName}(${signature}) { return this.getValue(${callArgs}); }`);
120
+ }
121
+ return lines.join('\n');
122
+ }
123
+ /**
124
+ * Number of arguments needed by a translation: highest {n} placeholder + 1 over all languages
125
+ */
126
+ static getArgCount(values) {
127
+ let maxIndex = -1;
128
+ for (const value of values) {
129
+ for (const match of value.matchAll(this.PLACEHOLDER_REGEX)) {
130
+ maxIndex = Math.max(maxIndex, parseInt(match[1], 10));
131
+ }
132
+ }
133
+ return maxIndex + 1;
134
+ }
135
+ /**
136
+ * Makes a translation value safe inside a JSDoc comment: single line, no comment terminator
137
+ */
138
+ static toCommentText(value) {
139
+ return value.replace(/\r?\n/g, ' ').replaceAll('*/', '* /');
140
+ }
141
+ static toIdentifier(name) {
142
+ let identifier = name.trim().replace(/[^\w$]/g, '_');
143
+ if (/^\d/.test(identifier)) {
144
+ identifier = `_${identifier}`;
145
+ }
146
+ return identifier;
147
+ }
148
+ /**
149
+ * Header written at the top of the generated file
150
+ */
151
+ static generateHeader(className, sourceFileName) {
152
+ const version = this.getCliVersion();
153
+ const generator = version ? `codenotch-cli v${version}` : 'codenotch-cli';
154
+ const line = '-'.repeat(75);
155
+ return [
156
+ `/* ${line}`,
157
+ ` * ${className}.i18n.ts`,
158
+ ` *`,
159
+ ` * Generated by ${generator} from '${this.toCommentText(sourceFileName)}'.`,
160
+ ` *`,
161
+ ` * THIS FILE IS GENERATED, DO NOT EDIT IT MANUALLY: it is entirely overwritten`,
162
+ ` * each time it is regenerated, edit the csv instead and run:`,
163
+ ` *`,
164
+ ` * cn generate i18n -f ${this.toCommentText(sourceFileName)}`,
165
+ ` * ${line} */`
166
+ ].join('\n');
167
+ }
168
+ static getCliVersion() {
169
+ try {
170
+ // works from both src/utils (tsx) and dist/utils (build)
171
+ const packageJson = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../package.json'), 'utf8'));
172
+ return typeof packageJson.version === 'string' ? packageJson.version : undefined;
173
+ }
174
+ catch {
175
+ return undefined;
176
+ }
177
+ }
178
+ static generateTemplate(className, sourceFileName, defaultLang, valuesBlock, methodsBlock) {
179
+ const i = this.INDENT;
180
+ return [
181
+ this.generateHeader(className, sourceFileName),
182
+ ``,
183
+ `export default abstract class ${className} {`,
184
+ ``,
185
+ valuesBlock,
186
+ ``,
187
+ `${i}static lang: string = ${JSON.stringify(defaultLang)};`,
188
+ `${i}static setLanguage(lang: string) {`,
189
+ `${i}${i}this.lang = lang.toLowerCase();`,
190
+ `${i}}`,
191
+ ``,
192
+ `${i}private static getValue(key: string, ...args: any[]) {`,
193
+ `${i}${i}try {`,
194
+ `${i}${i}${i}const values = this.values[key];`,
195
+ `${i}${i}${i}if (values === undefined) {`,
196
+ `${i}${i}${i}${i}return \`KEY '\${key}' NOT EXISTS\`;`,
197
+ `${i}${i}${i}}`,
198
+ ``,
199
+ `${i}${i}${i}let langValue = values[this.lang] ?? values[Object.keys(values)[0]];`,
200
+ `${i}${i}${i}let argIndex = 0;`,
201
+ `${i}${i}${i}for (const arg of args) {`,
202
+ `${i}${i}${i}${i}langValue = langValue.replaceAll(\`{\${argIndex}}\`, \`\${(arg ?? '')}\`.trim());`,
203
+ `${i}${i}${i}${i}argIndex++;`,
204
+ `${i}${i}${i}}`,
205
+ ``,
206
+ `${i}${i}${i}return langValue;`,
207
+ `${i}${i}}`,
208
+ `${i}${i}catch (e) {`,
209
+ `${i}${i}${i}console.error('I18N', e);`,
210
+ `${i}${i}${i}return 'ERROR';`,
211
+ `${i}${i}}`,
212
+ `${i}}`,
213
+ ``,
214
+ methodsBlock,
215
+ `}`,
216
+ ``
217
+ ].join('\n');
218
+ }
219
+ }
220
+ exports.default = I18nTsUtils;
221
+ //# sourceMappingURL=I18nTsUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"I18nTsUtils.js","sourceRoot":"","sources":["../../src/utils/I18nTsUtils.ts"],"names":[],"mappings":";;AAAA,2BAAkC;AAClC,+BAA4B;AAiB5B;;;;;;;;;;;GAWG;AACH,MAA8B,WAAW;IAE7B,MAAM,CAAU,gBAAgB,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC;IACjF,MAAM,CAAU,iBAAiB,GAAG,YAAY,CAAC;IACjD,MAAM,CAAU,MAAM,GAAG,MAAM,CAAC;IAExC;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,cAAsB;QACtC,MAAM,QAAQ,GAAG,cAAc,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;QAC7E,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QAC1E,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC;IAC7C,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,KAA2B;QACzC,MAAM,OAAO,GAAyB,EAAE,CAAC;QAEzC,KAAK,MA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AAG,CAAC,GAAG,CAAC,GAAG,CAAC,mFAAmF;YACnG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,aAAa;YAC7B,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG;YACf,EAAE;YACF,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,mBAAmB;YAC/B,GAAG,CAAC,GAAG,CAAC,GAAG;YACX,GAAG,CAAC,GAAG,CAAC,aAAa;YACrB,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,2BAA2B;YACvC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,iBAAiB;YAC7B,GAAG,CAAC,GAAG,CAAC,GAAG;YACX,GAAG,CAAC,GAAG;YACP,EAAE;YACF,YAAY;YACZ,GAAG;YACH,EAAE;SACL,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjB,CAAC;;AAhOL,8BAiOC"}
@@ -0,0 +1,24 @@
1
+ import { ICodenotchProjectManifest } from '@codenotch/codenotch.core';
2
+ /** Allowed characters of a service name: it ends up in URLs, SioQL `xmlns` and BPMN `echino:project`. */
3
+ export declare const SERVICE_NAME_PATTERN: RegExp;
4
+ export declare const DEFAULT_LANGUAGES: string[];
5
+ export declare const DEFAULT_PROJECT_VERSION = "0.0.0";
6
+ export type IManifestOptions = {
7
+ /** Defaults to a service name derived from the project name, see `ManifestUtils.toServiceName`. */
8
+ serviceName?: string;
9
+ };
10
+ export default abstract class ManifestUtils {
11
+ /**
12
+ * Derives a valid service name (`[\w.]+`) from a human readable project name:
13
+ * accents are stripped, spaces and dashes become underscores, other special characters are removed.
14
+ * Returns an empty string when nothing usable remains.
15
+ */
16
+ static toServiceName(projectName: string): string;
17
+ static isValidServiceName(serviceName: string): boolean;
18
+ /**
19
+ * Builds the minimal (non compiled) manifest of a project.
20
+ * Only metadata is included: the runtime/IDE fill in processes, tables, apps... at compilation time.
21
+ */
22
+ static createManifest(projectName: string, options?: IManifestOptions): ICodenotchProjectManifest;
23
+ static serialize(manifest: ICodenotchProjectManifest): string;
24
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_PROJECT_VERSION = exports.DEFAULT_LANGUAGES = exports.SERVICE_NAME_PATTERN = void 0;
4
+ /** Allowed characters of a service name: it ends up in URLs, SioQL `xmlns` and BPMN `echino:project`. */
5
+ exports.SERVICE_NAME_PATTERN = /^[\w.]+$/;
6
+ exports.DEFAULT_LANGUAGES = ['en', 'de', 'fr'];
7
+ exports.DEFAULT_PROJECT_VERSION = '0.0.0';
8
+ class ManifestUtils {
9
+ /**
10
+ * Derives a valid service name (`[\w.]+`) from a human readable project name:
11
+ * accents are stripped, spaces and dashes become underscores, other special characters are removed.
12
+ * Returns an empty string when nothing usable remains.
13
+ */
14
+ static toServiceName(projectName) {
15
+ const serviceName = (projectName ?? '')
16
+ .trim()
17
+ // Strip accents ("é" -> "e", "ç" -> "c")
18
+ .normalize('NFD')
19
+ .replace(/[̀-ͯ]/g, '')
20
+ // Spaces, tabs and dashes become underscores
21
+ .replace(/[-\s]+/g, '_')
22
+ // Drop anything that is not [\w.]
23
+ .replace(/[^\w.]/g, '')
24
+ // Collapse repeated separators
25
+ .replace(/__+/g, '_')
26
+ .replace(/\.\.+/g, '.')
27
+ // Service names are part of the project URL: keep them lowercase
28
+ .toLowerCase();
29
+ return ManifestUtils.isValidServiceName(serviceName) ? serviceName : '';
30
+ }
31
+ static isValidServiceName(serviceName) {
32
+ return typeof serviceName === 'string' && exports.SERVICE_NAME_PATTERN.test(serviceName);
33
+ }
34
+ /**
35
+ * Builds the minimal (non compiled) manifest of a project.
36
+ * Only metadata is included: the runtime/IDE fill in processes, tables, apps... at compilation time.
37
+ */
38
+ static createManifest(projectName, options = {}) {
39
+ const serviceName = options.serviceName?.trim() || ManifestUtils.toServiceName(projectName);
40
+ return {
41
+ projectName: projectName,
42
+ serviceName: serviceName,
43
+ languages: [...exports.DEFAULT_LANGUAGES],
44
+ roles: [],
45
+ version: exports.DEFAULT_PROJECT_VERSION
46
+ };
47
+ }
48
+ static serialize(manifest) {
49
+ return JSON.stringify(manifest, null, 4);
50
+ }
51
+ }
52
+ exports.default = ManifestUtils;
53
+ //# sourceMappingURL=ManifestUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ManifestUtils.js","sourceRoot":"","sources":["../../src/utils/ManifestUtils.ts"],"names":[],"mappings":";;;AAEA,yGAAyG;AAC5F,QAAA,oBAAoB,GAAG,UAAU,CAAC;AAClC,QAAA,iBAAiB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AACvC,QAAA,uBAAuB,GAAG,OAAO,CAAC;AAO/C,MAA8B,aAAa;IAEvC;;;;OAIG;IACH,MAAM,CAAC,aAAa,CAAC,WAAmB;QACpC,MAAM,WAAW,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC;aAClC,IAAI,EAAE;YACP,yCAAyC;aACxC,SAAS,CAAC,KAAK,CAAC;aAChB,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;YACtB,6CAA6C;aAC5C,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;YACxB,kCAAkC;aACjC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;YACvB,+BAA+B;aAC9B,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;aACpB,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC;YACvB,iEAAiE;aAChE,WAAW,EAAE,CAAC;QAEnB,OAAO,aAAa,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5E,CAAC;IAED,MAAM,CAAC,kBAAkB,CAAC,WAAmB;QACzC,OAAO,OAAO,WAAW,KAAK,QAAQ,IAAI,4BAAoB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACrF,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,cAAc,CAAC,WAAmB,EAAE,UAA4B,EAAE;QACrE,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,EAAE,IAAI,EAAE,IAAI,aAAa,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;QAE5F,OAAO;YACH,WAAW,EAAE,WAAW;YACxB,WAAW,EAAE,WAAW;YACxB,SAAS,EAAE,CAAC,GAAG,yBAAiB,CAAC;YACjC,KAAK,EAAE,EAAE;YACT,OAAO,EAAE,+BAAuB;SACnC,CAAC;IACN,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,QAAmC;QAChD,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAC7C,CAAC;CACJ;AAjDD,gCAiDC"}
@@ -0,0 +1,81 @@
1
+ import { IDiscoveredProcess } from './ProjectUtils';
2
+ import { IJsonSchema } from './TypeSchemaUtils';
3
+ export interface IOpenApiOptions {
4
+ /** Title of the API, usually the project name */
5
+ title: string;
6
+ /** Version of the API, usually the project version */
7
+ version: string;
8
+ /** Description shown at the top of the document */
9
+ description?: string;
10
+ }
11
+ export interface IOpenApiGenerationResult {
12
+ document: IOpenApiDocument;
13
+ warnings: string[];
14
+ /** Number of endpoints written */
15
+ endpointCount: number;
16
+ }
17
+ export interface IOpenApiParameter {
18
+ name: string;
19
+ in: 'path' | 'query';
20
+ required: boolean;
21
+ schema: IJsonSchema;
22
+ description?: string;
23
+ }
24
+ export interface IOpenApiOperation {
25
+ operationId: string;
26
+ summary?: string;
27
+ description?: string;
28
+ tags?: string[];
29
+ parameters?: IOpenApiParameter[];
30
+ requestBody?: {
31
+ required: boolean;
32
+ content: {
33
+ 'application/json': {
34
+ schema: IJsonSchema;
35
+ };
36
+ };
37
+ };
38
+ responses: Record<string, {
39
+ description: string;
40
+ content?: {
41
+ 'application/json': {
42
+ schema: IJsonSchema;
43
+ };
44
+ };
45
+ }>;
46
+ /** Value of 'auth.scope' of the process, a Codenotch specific extension */
47
+ 'x-codenotch-scope'?: string;
48
+ /** Id of the process behind the endpoint */
49
+ 'x-codenotch-process': string;
50
+ }
51
+ export interface IOpenApiDocument {
52
+ openapi: '3.0.3';
53
+ info: {
54
+ title: string;
55
+ version: string;
56
+ description?: string;
57
+ };
58
+ paths: Record<string, Record<string, IOpenApiOperation>>;
59
+ }
60
+ /**
61
+ * Builds the OpenAPI document of a project out of its processes triggered by `api.*(...)`.
62
+ *
63
+ * The input type of `run` is split between the path (its properties named like a route segment),
64
+ * the query string (GET and DELETE) or the request body (other methods). The declared return
65
+ * type becomes the 200 response. What the sources do not state is left open rather than invented:
66
+ * an input without annotation gives no parameter, a return type that is a reference stays named.
67
+ */
68
+ export default abstract class OpenApiUtils {
69
+ static generate(processes: IDiscoveredProcess[], options: IOpenApiOptions): IOpenApiGenerationResult;
70
+ /** Express style ':bookId' becomes OpenAPI style '{bookId}' */
71
+ static toOpenApiPath(route: string): string;
72
+ /** Names of the '{param}' segments of a path, in order */
73
+ static getPathParameterNames(route: string): string[];
74
+ private static sortKey;
75
+ private static toOperation;
76
+ /**
77
+ * Dispatches the properties of the input between the path, the query string and the body.
78
+ * A path parameter is always documented, typed from the input when it says so.
79
+ */
80
+ private static splitInput;
81
+ }
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const FileUtils_1 = __importDefault(require("./FileUtils"));
7
+ /** Methods whose input travels in the query string rather than in a body */
8
+ const QUERY_METHODS = ['get', 'delete', 'head', 'options'];
9
+ /**
10
+ * Builds the OpenAPI document of a project out of its processes triggered by `api.*(...)`.
11
+ *
12
+ * The input type of `run` is split between the path (its properties named like a route segment),
13
+ * the query string (GET and DELETE) or the request body (other methods). The declared return
14
+ * type becomes the 200 response. What the sources do not state is left open rather than invented:
15
+ * an input without annotation gives no parameter, a return type that is a reference stays named.
16
+ */
17
+ class OpenApiUtils {
18
+ static generate(processes, options) {
19
+ const warnings = [];
20
+ const paths = {};
21
+ let endpointCount = 0;
22
+ const endpoints = processes
23
+ .filter(process => process.trigger?.kind === 'api')
24
+ // Sorted so that regenerating an unchanged project produces an unchanged file
25
+ .sort((left, right) => this.sortKey(left).localeCompare(this.sortKey(right)));
26
+ for (const process of endpoints) {
27
+ const trigger = process.trigger;
28
+ const where = `${FileUtils_1.default.getNameFromPath(process.filePath)}:${process.line}`;
29
+ if (process.id === undefined) {
30
+ warnings.push(`The endpoint ${trigger.method} ${trigger.route} (${where}) has a computed id, it cannot be given an operationId and is left out.`);
31
+ continue;
32
+ }
33
+ const route = this.toOpenApiPath(trigger.route);
34
+ const method = trigger.method.toLowerCase();
35
+ if (paths[route]?.[method] !== undefined) {
36
+ warnings.push(`${trigger.method} ${route} is declared twice, by '${paths[route][method].operationId}' and '${process.id}' (${where}); only the first one is kept.`);
37
+ continue;
38
+ }
39
+ // A process that takes no input has nothing to document, one that takes an untyped input does
40
+ if (process.takesInput && process.input === undefined) {
41
+ warnings.push(`'${process.id}' (${where}) declares no type for its input, its parameters are not documented.`);
42
+ }
43
+ paths[route] = paths[route] ?? {};
44
+ paths[route][method] = this.toOperation(process, method, route);
45
+ endpointCount++;
46
+ }
47
+ return {
48
+ document: {
49
+ openapi: '3.0.3',
50
+ info: { title: options.title, version: options.version, ...(options.description ? { description: options.description } : {}) },
51
+ paths
52
+ },
53
+ warnings,
54
+ endpointCount
55
+ };
56
+ }
57
+ /** Express style ':bookId' becomes OpenAPI style '{bookId}' */
58
+ static toOpenApiPath(route) {
59
+ return route.replace(/:([A-Za-z_$][\w$]*)/g, '{$1}');
60
+ }
61
+ /** Names of the '{param}' segments of a path, in order */
62
+ static getPathParameterNames(route) {
63
+ return [...route.matchAll(/\{([^}]+)\}/g)].map(match => match[1]);
64
+ }
65
+ static sortKey(process) {
66
+ const trigger = process.trigger;
67
+ return `${this.toOpenApiPath(trigger.route)} ${trigger.method}`;
68
+ }
69
+ static toOperation(process, method, route) {
70
+ const { parameters, body } = this.splitInput(process.input, route, method);
71
+ // Built in the order a reader expects: what it is, what it takes, what it gives back
72
+ return {
73
+ operationId: process.id,
74
+ ...(process.description === undefined ? {} : { summary: process.description }),
75
+ tags: [FileUtils_1.default.getNameFromPath(process.filePath, true)],
76
+ ...(parameters.length === 0 ? {} : { parameters }),
77
+ ...(body === undefined ? {} : {
78
+ requestBody: { required: (body.required ?? []).length > 0, content: { 'application/json': { schema: body } } }
79
+ }),
80
+ responses: {
81
+ '200': {
82
+ description: 'Successful response',
83
+ ...(process.output === undefined ? {} : { content: { 'application/json': { schema: process.output } } })
84
+ }
85
+ },
86
+ 'x-codenotch-process': process.id,
87
+ ...(process.scope === undefined ? {} : { 'x-codenotch-scope': process.scope })
88
+ };
89
+ }
90
+ /**
91
+ * Dispatches the properties of the input between the path, the query string and the body.
92
+ * A path parameter is always documented, typed from the input when it says so.
93
+ */
94
+ static splitInput(input, route, method) {
95
+ const pathNames = this.getPathParameterNames(route);
96
+ const properties = input?.properties ?? {};
97
+ const required = new Set(input?.required ?? []);
98
+ const parameters = pathNames.map(name => ({
99
+ name,
100
+ in: 'path',
101
+ required: true,
102
+ schema: properties[name] ?? { type: 'string' }
103
+ }));
104
+ const remaining = Object.entries(properties).filter(([name]) => !pathNames.includes(name));
105
+ if (remaining.length === 0) {
106
+ return { parameters };
107
+ }
108
+ if (QUERY_METHODS.includes(method)) {
109
+ for (const [name, schema] of remaining) {
110
+ parameters.push({ name, in: 'query', required: required.has(name), schema });
111
+ }
112
+ return { parameters };
113
+ }
114
+ const body = { type: 'object', properties: Object.fromEntries(remaining) };
115
+ const bodyRequired = remaining.map(([name]) => name).filter(name => required.has(name));
116
+ if (bodyRequired.length > 0) {
117
+ body.required = bodyRequired;
118
+ }
119
+ return { parameters, body };
120
+ }
121
+ }
122
+ exports.default = OpenApiUtils;
123
+ //# sourceMappingURL=OpenApiUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OpenApiUt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S,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,EAAE,UAAU,EAAE,CAAC;QAC1B,CAAC;QAED,IAAI,aAAa,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACjC,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,SAAS,EAAE,CAAC;gBACrC,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;YACjF,CAAC;YACD,OAAO,EAAE,UAAU,EAAE,CAAC;QAC1B,CAAC;QAED,MAAM,IAAI,GAAgB,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC;QACxF,MAAM,YAAY,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;QACxF,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1B,IAAI,CAAC,QAAQ,GAAG,YAAY,CAAC;QACjC,CAAC;QAED,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;IAChC,CAAC;CACJ;AAjID,+BAiIC"}
@@ -1,23 +1,9 @@
1
- import { ProjectManifest } from "../models/Codenotch";
2
- import AbstractRecordContainer, { TableDefinition } from "../models/DbModels";
3
- import { JSONSchema7, JSONSchema7TypeName } from "json-schema";
4
- import { IProcess } from "@codenotch/codenotch.core.workflow";
5
- import { IWorkflowDataProvider } from "@codenotch/codenotch.core.workflow/dist/core/IWorkflowDataProvider";
6
- import { IVariable, VariableType } from "@codenotch/codenotch.core";
1
+ import { ICodenotchProjectManifest } from "@codenotch/codenotch.core";
7
2
  export interface CompilationContext {
8
3
  errors: string[];
9
4
  warnings: string[];
10
5
  targetPath: string;
11
- processes: {
12
- [processId: string]: any;
13
- };
14
- documents: {
15
- [documentId: string]: AbstractRecordContainer;
16
- };
17
- tables: {
18
- [tableId: string]: TableDefinition;
19
- };
20
- manifest?: ProjectManifest;
6
+ manifest?: ICodenotchProjectManifest;
21
7
  files: string[];
22
8
  }
23
9
  export interface CompilationResult {
@@ -29,7 +15,6 @@ export default abstract class ProjectCompilationUtils {
29
15
  * Create a new folder that contains a compiled version of the project
30
16
  * We have to compile the project because some files need to be modified a bit in order to work when deployed
31
17
  * In-place compilation, the files in the source folder will be modified/deleted and the output will be generated in the same folder
32
- * For example auml files have to include their i18n data
33
18
  * /!\Warning/!\ This will modify/delete files in the source folder, make sure to know what you are doing !!!
34
19
  * @param project current project
35
20
  * @returns the path to the compiled project
@@ -43,21 +28,9 @@ export default abstract class ProjectCompilationUtils {
43
28
  */
44
29
  static compileTestProject(targetPath: string): Promise<CompilationResult>;
45
30
  static generateDbSchema(context: CompilationContext): Promise<string>;
46
- static GetXMLFromTableDefinition(definitions: TableDefinition[], version?: string): string;
47
- /**
48
- * Will lock the version of all packages that use the "latest"
49
- */
50
- static getManifestFileType(file: string): "" | "table" | "bpmn" | "auml" | "document" | "script" | "jsxtsx" | "i18n";
51
31
  /**
52
32
  * Generate the full project manifest
53
33
  * Uses the manifest cache if available, otherwise read the project files to generate the full manifest
54
34
  */
55
- static generateManifest(context: CompilationContext): Promise<ProjectManifest>;
56
- static parseBpmn(rawBpmn: string, provider: IWorkflowDataProvider): Promise<IProcess | null>;
57
- private static generateManifestBpmn;
58
- private static generateManifestProcess;
59
- static ProcessVariableToJsonSchema(variable: IVariable): JSONSchema7;
60
- static ProcessVariableTypeToJsonSchemaTypeName(type: VariableType): JSONSchema7TypeName;
61
- private static generateManifestReactApp;
62
- private static generateManifestAumlApp;
35
+ static generateManifest(context: CompilationContext): Promise<ICodenotchProjectManifest>;
63
36
  }