@izara_project/izara-core-generate-service-code 1.0.25 → 1.0.27

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/jsconfig.json CHANGED
@@ -2,8 +2,12 @@
2
2
  "compilerOptions": {
3
3
  "baseUrl": "src",
4
4
  "paths": {
5
- "#libs/*": ["libs/*"]
5
+ "#libs/*": [
6
+ "libs/*"
7
+ ]
6
8
  }
7
9
  },
8
- "include": ["src"]
9
- }
10
+ "include": [
11
+ "src"
12
+ ]
13
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@izara_project/izara-core-generate-service-code",
3
- "version": "1.0.25",
3
+ "version": "1.0.27",
4
4
  "description": "Code for locally generating per service files",
5
5
  "author": "Sven Mason <thebarbariansven@gmail.com>",
6
6
  "license": "AGPL-3.0-or-later",
@@ -27,7 +27,7 @@
27
27
  "@izara_project/izara-core-library-core": "^1.0.31",
28
28
  "@izara_project/izara-core-library-logger": "^1.0.8",
29
29
  "@izara_project/izara-core-library-s3": "^1.0.5",
30
- "@izara_project/izara-core-library-service-schemas": "^1.0.126",
30
+ "@izara_project/izara-core-library-service-schemas": "^1.0.127",
31
31
  "@izara_project/izara-shared-core": "^1.0.9",
32
32
  "ejs": "^5.0.1",
33
33
  "js-beautify": "^1.15.4",
@@ -31,7 +31,7 @@ const { HANDLER, SOURCE_PATH, SAVE_FILE_NAME } = consts;
31
31
 
32
32
  const { shortNameHandler, defaultIamRolePerAction } = libs;
33
33
 
34
- const { firstLetterUpperCase: upperCase } = utils;
34
+ const { firstLetterUpperCase: upperCase, savePath } = utils;
35
35
 
36
36
  const templatePath = path.join(__dirname, 'template.ejs');
37
37
 
@@ -54,7 +54,14 @@ function createSourceParamsApi(_izContext, flowSchema, appPath) {
54
54
  return {
55
55
  templatePath: templatePath,
56
56
  templateData: {
57
- resourceYamlFlowSchemaFlowTag,
57
+ resourceLocation:
58
+ // path.join(
59
+ // SOURCE_PATH.resourceLocationFlowSchema,
60
+ // upperCase(flowSchema.flowTag),
61
+ // 'MainHandler/',
62
+ // 'source/'
63
+ // ),
64
+ savePath.flowSchemaFlowTag(flowSchema.flowTag),
58
65
  functionName,
59
66
  handlerType,
60
67
  additionalResourcePermission,
@@ -24,6 +24,9 @@ import {
24
24
  //(<optionalRequire>)
25
25
  //(</optionalRequire>)
26
26
 
27
+ //(<helperFunctions>)
28
+ //(</helperFunctions>)
29
+
27
30
  /**
28
31
  * description of function.
29
32
  * @param {Object} _izContext
@@ -81,6 +84,10 @@ export default async function <%- functionName %>Main (
81
84
  return '<%- functionName %> completed successfully';
82
85
  } catch (err) {
83
86
  _izContext.logger.error('error <%- functionName %>: ', err);
87
+
88
+ //(<errorHandling>)
89
+ //(</errorHandling>)
90
+
84
91
  throw (err);
85
92
  }
86
93
  }
@@ -21,6 +21,9 @@ import { handlePlugInHookTag } from '@izara_project/izara-core-library-plugin';
21
21
  //(<optionalRequire>)
22
22
  //(</optionalRequire>)
23
23
 
24
+ //(<helperFunctions>)
25
+ //(</helperFunctions>)
26
+
24
27
  /**
25
28
  * description of function.
26
29
  * @param {Object} _izContext
@@ -30,10 +33,8 @@ import { handlePlugInHookTag } from '@izara_project/izara-core-library-plugin';
30
33
  * @param {Object} requestParams.identifiers - identifiers for get data
31
34
  * @param {Object} requestParams.additionalRequest - additionalRequest
32
35
  *
33
- *
34
36
  * @returns {object} description of return value
35
37
  */
36
-
37
38
  export default async function <%- functionName %>Main (
38
39
  _izContext,
39
40
  requestParams,
@@ -85,6 +86,10 @@ export default async function <%- functionName %>Main (
85
86
  return '<%- functionName %> completed successfully';
86
87
  } catch (err) {
87
88
  _izContext.logger.error('error <%- functionName %>: ', err)
89
+
90
+ //(<errorHandling>)
91
+ //(</errorHandling>)
92
+
88
93
  throw (err)
89
94
  }
90
95
  }
@@ -19,6 +19,9 @@ along with this program. If not, see
19
19
  //(<optionalRequire>)
20
20
  //(</optionalRequire>)
21
21
 
22
+ //(<helperFunctions>)
23
+ //(</helperFunctions>)
24
+
22
25
  /**
23
26
  * description of function.
24
27
  * @param {Object} _izContext
@@ -28,10 +31,8 @@ along with this program. If not, see
28
31
  * @param {Object} requestParams.identifiers - identifiers for get data
29
32
  * @param {Object} requestParams.additionalRequest - additionalRequest
30
33
  *
31
- *
32
34
  * @returns {object} description of return value
33
35
  */
34
-
35
36
  export default async function <%- functionName %> (
36
37
  _izContext,
37
38
  requestParams,
@@ -49,6 +50,10 @@ export default async function <%- functionName %> (
49
50
 
50
51
  } catch (err) {
51
52
  _izContext.logger.error('error <%- functionName %>: ', err)
53
+
54
+ //(<errorHandling>)
55
+ //(</errorHandling>)
56
+
52
57
  throw (err)
53
58
  }
54
59
  }
@@ -22,7 +22,7 @@ import snsSharedLib from '@izara_project/izara-core-library-sns';
22
22
  const _izContext = { logger: Logger }
23
23
 
24
24
  export function generatedLambdaRole() {
25
- let externalLambdaRole = [ <%_ datas.forEach((data,dataIndex) => { %>
25
+ const externalLambdaRole = [ <%_ datas.forEach((data,dataIndex) => { %>
26
26
  {
27
27
  roleName: "<%- data.objectType %>",
28
28
  statement: [
@@ -0,0 +1,57 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ import { join } from 'path';
19
+
20
+
21
+ import libs from '#libs/Utils.js';
22
+
23
+ const { checkValidTableYaml } = libs;
24
+ import createSourceTranslations from './translations/data.js';
25
+
26
+ async function translationComponent(
27
+ _izContext,
28
+ appPath,
29
+ allObjSchemas,
30
+ allFlowSchemas
31
+ ) {
32
+ try {
33
+ const objSchemaPath = join(appPath, '/src/schemas');
34
+
35
+ const createSources = [];
36
+ const translationComponent = await createSourceTranslations(
37
+ _izContext,
38
+ allObjSchemas,
39
+ allFlowSchemas,
40
+ objSchemaPath
41
+ );
42
+
43
+ console.log("translationComponent", translationComponent)
44
+ createSources.push(translationComponent);
45
+
46
+ return createSources;
47
+
48
+ } catch (error) {
49
+ _izContext.logger.error(
50
+ 'Error generating code with template resourceYaml: ',
51
+ error
52
+ );
53
+ return [];
54
+ }
55
+ }
56
+
57
+ export default translationComponent;
@@ -0,0 +1,87 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ import path from 'path';
19
+ import { fileURLToPath } from 'url';
20
+ const __filename = fileURLToPath(import.meta.url);
21
+ const __dirname = path.dirname(__filename);
22
+
23
+ import consts from '#libs/Consts.js';
24
+ import utils from '#libs/Utils.js';
25
+
26
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, getLocalConfig } =
27
+ utils;
28
+ const {
29
+ SOURCE_PATH,
30
+ SAVE_FILE_NAME,
31
+ } = consts;
32
+
33
+ const templatePath = path.join(__dirname, 'template.ejs');
34
+
35
+ import { utils as coreUtils } from '@izara_project/izara-core-library-service-schemas'
36
+ /**
37
+ * receive objectSchema
38
+ * create data for hdrInv template
39
+ *
40
+ * @return {{ templatePath, templateData, setting } }
41
+ */
42
+ function createSourceTranslations(_izContext, allObjectSchema, allFlowSchemas, srcPath) {
43
+ const createSourceArray = [];
44
+ // console.log("params objSchema", JSON.stringify(allObjectSchema, null, 2));
45
+ for (const objectSchema of allObjectSchema.records) {
46
+ for (const fieldName of Object.keys(objectSchema.fieldNames)) {
47
+ const objType = {
48
+ objectType: objectSchema.objectType,
49
+ serviceTag: getLocalConfig('iz_serviceTag')
50
+ }
51
+ const translationTextObjSchemas = {
52
+ nameSpace: `${coreUtils.createObjTypeConcat(_izContext, objType)}_description`, // for each objectType
53
+ systemTextTag: `${fieldName}_${coreUtils.createObjTypeConcat(_izContext, objType)}` // for each fieldName
54
+ }
55
+ createSourceArray.push(translationTextObjSchemas)
56
+ }
57
+ };
58
+
59
+ for (const flowSchema of allFlowSchemas.records) {
60
+ const flowType = {
61
+ flowTag: flowSchema.flowTag,
62
+ serviceTag: getLocalConfig('iz_serviceTag')
63
+ }
64
+ const translationTextFlowSchemas = {
65
+ nameSpace: `${coreUtils.createFlowTypeConcat(_izContext, flowType)}`, // for each flowType
66
+ systemTextTag: `errors_${coreUtils.createFlowTypeConcat(_izContext, flowType)}`
67
+ }
68
+ createSourceArray.push(translationTextFlowSchemas)
69
+ }
70
+
71
+ // console.log("createSourceArray", createSourceArray)
72
+ return {
73
+ templatePath: templatePath,
74
+ templateData: { datas: createSourceArray },
75
+ setting: {
76
+ savePath: path.join(srcPath, SOURCE_PATH.translationSchema),
77
+ saveFileName: SAVE_FILE_NAME.translationSchema,
78
+ fileExtension: '.js',
79
+ isAppend: true,
80
+ generateHookFile: false
81
+ }
82
+ };
83
+ };
84
+
85
+
86
+
87
+ export default createSourceTranslations;
@@ -0,0 +1,5 @@
1
+ export default [
2
+ <% datas.forEach((data, index) => { -%>
3
+ <%- JSON.stringify(data,null,2) %><%= index < datas.length - 1 ? ',' : '' %>
4
+ <% }); -%>
5
+ ];
@@ -37,6 +37,7 @@ import generateTemplateDataInitialSetup from './generateCode/generateInitialSetu
37
37
  import generateTemplateDataOther from './generateCode/generateOther/generateCodeOther.js';
38
38
 
39
39
  import generateTemplateDataRole from './generateCode/generateRole/generateCodeRole.js';
40
+ import generateTemplateTranslations from './generateCode/generateTranslation/generateTranslation.js';
40
41
 
41
42
  const __filename = fileURLToPath(import.meta.url);
42
43
  const __dirname = dirname(__filename);
@@ -92,7 +93,7 @@ async function generateCodeWithTemplate(
92
93
  console.info('[INFO] [generateCode] STATUS=GENERATING| template data...');
93
94
  _izContext.logger.info('[generateCode] generating template data...');
94
95
  const genStartTime = Date.now();
95
- const [flowSchemaResult, schemaResult, initialSetupResult, otherResult] =
96
+ const [flowSchemaResult, schemaResult, initialSetupResult, otherResult, translationResult] =
96
97
  await Promise.all([
97
98
  generateTemplateDataFromFlowSchema(
98
99
  _izContext,
@@ -120,7 +121,8 @@ async function generateCodeWithTemplate(
120
121
  allLocalFlowSchemas.records,
121
122
  settings
122
123
  ),
123
- generateTemplateDataOther(_izContext, appPath)
124
+ generateTemplateDataOther(_izContext, appPath),
125
+ generateTemplateTranslations(_izContext, appPath, allObjSchemas, allLocalFlowSchemas),
124
126
  ]);
125
127
 
126
128
  const genDuration = Date.now() - genStartTime;
@@ -129,11 +131,14 @@ async function generateCodeWithTemplate(
129
131
  `[INFO] [generateCode] STATUS=GENERATED | ${genStr.padEnd(40)} | elapsedMs=${genDuration}`
130
132
  );
131
133
 
134
+ console.log(translationResult)
135
+
132
136
  const allCreateSource = [
133
137
  ...flowSchemaResult,
134
138
  ...schemaResult,
135
139
  ...initialSetupResult,
136
- ...otherResult
140
+ ...otherResult,
141
+ ...translationResult
137
142
  ];
138
143
 
139
144
  // ── 3. Generate role configs ─────────────────────────────────────────────
@@ -91,7 +91,10 @@ const SOURCE_PATH = {
91
91
  'src/generatedCode/ActionEndpoint/source/',
92
92
  createRecordComplete: '/src/generatedCode/CreateRecordComplete/',
93
93
  resourceLocationCreateRecordComplete:
94
- 'src/generatedCode/CreateRecordComplete/'
94
+ 'src/generatedCode/CreateRecordComplete/',
95
+
96
+ // translations
97
+ translationSchema: 'translations/'
95
98
  };
96
99
 
97
100
  const SQS_RESOURCE = {
@@ -151,7 +154,8 @@ const SAVE_FILE_NAME = {
151
154
  objectRelationship: 'ObjectRelationships',
152
155
  refObjectRelationship: 'RefObjectRelationships',
153
156
  objectSchema: 'ObjectFieldSchema',
154
- roleNameConfig: 'RoleNameConfig'
157
+ roleNameConfig: 'RoleNameConfig',
158
+ translationSchema: 'TranslationsSchema'
155
159
  };
156
160
 
157
161
  const FUNCTION_NAME = {