@izara_project/izara-core-generate-service-code 1.0.94 → 1.0.96

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@izara_project/izara-core-generate-service-code",
3
- "version": "1.0.94",
3
+ "version": "1.0.96",
4
4
  "description": "Code for locally generating per service files",
5
5
  "homepage": "https://bitbucket.org/izara-core-support-services/izara-core-support-services-generate-service-code#readme",
6
6
  "repository": {
@@ -1,3 +1,6 @@
1
+ import { resolveTargetServicePath } from './resolveTargetServicePath.js';
2
+ import { emitAttributeTreeTargetSchemas } from './emitAttributeTreeTargetSchemas.js';
3
+
1
4
  /**
2
5
  * Emits dynamic ObjectSchemas and RelationshipSchemas for attributeTree add-ons
3
6
  */
@@ -68,12 +71,10 @@ export function attributeTreeObjectSchemaManagedPaths(objects = []) {
68
71
 
69
72
  for (const { attributeTreeTag } of trees) {
70
73
  const tag = attributeTreeTag;
71
- const tagCap = _capitalize(tag);
72
74
  paths.push(
73
75
  `app/src/schemas/ObjectSchemas/generatedAttributeTree/${tag}Link.js`,
74
- `app/src/schemas/ObjectSchemas/generatedAttributeTree/attribute${tagCap}Value.js`,
75
- `app/src/schemas/ObjectSchemas/generatedAttributeTree/${tag}Label.js`,
76
- `app/src/schemas/ObjectSchemas/generatedAttributeTree/${tag}ValueStandard.js`
76
+ `app/src/schemas/ObjectSchemas/generatedAttributeTree/${tag}Value.js`,
77
+ `app/src/schemas/ObjectSchemas/generatedAttributeTree/${tag}Label.js`
77
78
  );
78
79
  }
79
80
 
@@ -144,14 +145,14 @@ export function emitAttributeTreeObjectSchemas({ objects = [] } = {}) {
144
145
  content: _renderObjectSchema(linkSchema)
145
146
  });
146
147
 
147
- // 2. attribute{Tag}Value.js
148
+ // 2. {tag}Value.js
148
149
  const valueSchema = {
149
- objectType: `attribute${tagCap}Value`,
150
+ objectType: `${tag}Value`,
150
151
  canDelete: true,
151
152
  generatedBy: 'user',
152
153
  storageResources: graphStorageResources,
153
154
  fieldNames: {
154
- [`attribute${tagCap}ValueId`]: {
155
+ [`${tag}ValueId`]: {
155
156
  type: 'string',
156
157
  randomOnCreate: true,
157
158
  canUpdate: false,
@@ -167,12 +168,12 @@ export function emitAttributeTreeObjectSchemas({ objects = [] } = {}) {
167
168
  identifiers: [
168
169
  {
169
170
  type: 'identifier',
170
- fieldName: `attribute${tagCap}ValueId`
171
+ fieldName: `${tag}ValueId`
171
172
  }
172
173
  ]
173
174
  };
174
175
  artifacts.push({
175
- path: `app/src/schemas/ObjectSchemas/generatedAttributeTree/attribute${tagCap}Value.js`,
176
+ path: `app/src/schemas/ObjectSchemas/generatedAttributeTree/${tag}Value.js`,
176
177
  content: _renderObjectSchema(valueSchema)
177
178
  });
178
179
 
@@ -207,38 +208,6 @@ export function emitAttributeTreeObjectSchemas({ objects = [] } = {}) {
207
208
  path: `app/src/schemas/ObjectSchemas/generatedAttributeTree/${tag}Label.js`,
208
209
  content: _renderObjectSchema(labelSchema)
209
210
  });
210
-
211
- // 4. {tag}ValueStandard.js
212
- const standardValueSchema = {
213
- objectType: `${tag}ValueStandard`,
214
- canDelete: true,
215
- generatedBy: 'user',
216
- storageResources: graphStorageResources,
217
- fieldNames: {
218
- [`${tag}ValueStandardId`]: {
219
- type: 'string',
220
- randomOnCreate: true,
221
- canUpdate: false,
222
- storageResourceTags
223
- },
224
- value: {
225
- type: 'string',
226
- requiredOnCreate: true,
227
- canUpdate: true,
228
- storageResourceTags
229
- }
230
- },
231
- identifiers: [
232
- {
233
- type: 'identifier',
234
- fieldName: `${tag}ValueStandardId`
235
- }
236
- ]
237
- };
238
- artifacts.push({
239
- path: `app/src/schemas/ObjectSchemas/generatedAttributeTree/${tag}ValueStandard.js`,
240
- content: _renderObjectSchema(standardValueSchema)
241
- });
242
211
  }
243
212
 
244
213
  return artifacts;
@@ -268,6 +237,7 @@ export function emitAttributeTreeRelationshipSchemas({
268
237
  const hasLinkRel = {
269
238
  fieldNames: {},
270
239
  storageResources: graphStorageResources,
240
+ generatedBy: 'user',
271
241
  links: [
272
242
  {
273
243
  storageResourceTags,
@@ -283,7 +253,8 @@ export function emitAttributeTreeRelationshipSchemas({
283
253
  serviceTag: effectiveServiceTag,
284
254
  objectType: `${tag}Link`
285
255
  },
286
- linkType: 'many'
256
+ linkType: 'many',
257
+ requiredOnCreate: true
287
258
  }
288
259
  }
289
260
  ]
@@ -297,6 +268,7 @@ export function emitAttributeTreeRelationshipSchemas({
297
268
  const disabledLinkRel = {
298
269
  fieldNames: {},
299
270
  storageResources: graphStorageResources,
271
+ generatedBy: 'user',
300
272
  links: [
301
273
  {
302
274
  storageResourceTags,
@@ -329,6 +301,7 @@ export function emitAttributeTreeRelationshipSchemas({
329
301
  const isRel = {
330
302
  fieldNames: {},
331
303
  storageResources: graphStorageResources,
304
+ generatedBy: 'systemNoUser',
332
305
  links: [
333
306
  {
334
307
  storageResourceTags,
@@ -337,14 +310,15 @@ export function emitAttributeTreeRelationshipSchemas({
337
310
  serviceTag: effectiveServiceTag,
338
311
  objectType: `${tag}Link`
339
312
  },
340
- linkType: 'one'
313
+ linkType: 'many',
314
+ requiredOnCreate: true
341
315
  },
342
316
  to: {
343
317
  objType: {
344
318
  serviceTag: effectiveServiceTag,
345
- objectType: `attribute${tagCap}Value`
319
+ objectType: `${tag}Value`
346
320
  },
347
- linkType: 'many'
321
+ linkType: 'one'
348
322
  }
349
323
  }
350
324
  ]
@@ -358,22 +332,24 @@ export function emitAttributeTreeRelationshipSchemas({
358
332
  const isLabelRel = {
359
333
  fieldNames: {},
360
334
  storageResources: graphStorageResources,
335
+ generatedBy: 'systemNoUser',
361
336
  links: [
362
337
  {
363
338
  storageResourceTags,
364
339
  from: {
365
340
  objType: {
366
341
  serviceTag: effectiveServiceTag,
367
- objectType: `${tag}Link`
342
+ objectType: `${tag}Value`
368
343
  },
369
- linkType: 'one'
344
+ linkType: 'many',
345
+ requiredOnCreate: true
370
346
  },
371
347
  to: {
372
348
  objType: {
373
349
  serviceTag: effectiveServiceTag,
374
350
  objectType: `${tag}Label`
375
351
  },
376
- linkType: 'many'
352
+ linkType: 'one'
377
353
  }
378
354
  }
379
355
  ]
@@ -386,3 +362,8 @@ export function emitAttributeTreeRelationshipSchemas({
386
362
 
387
363
  return artifacts;
388
364
  }
365
+
366
+ export {
367
+ resolveTargetServicePath,
368
+ emitAttributeTreeTargetSchemas
369
+ };
@@ -0,0 +1,153 @@
1
+ import path from 'node:path';
2
+
3
+ function _renderObjectSchema(schema) {
4
+ return `export default [\n ${JSON.stringify(schema, null, 2).replace(/\n/g, '\n ')}\n];\n`;
5
+ }
6
+
7
+ /**
8
+ * Emits standard schemas into target service folder for attributeTree.
9
+ *
10
+ * @param {Object} params
11
+ * @param {string} params.attributeTag - e.g. 'sellOfferTerm'
12
+ * @param {string} params.targetServiceRoot - Target service root directory
13
+ * @param {Object} [params.graphStorageResources] - Graph storage resources
14
+ * @returns {Array<{ path: string, content: string }>} Emitted target artifacts
15
+ */
16
+ export function emitAttributeTreeTargetSchemas({
17
+ attributeTag,
18
+ targetServiceRoot,
19
+ graphStorageResources = {
20
+ myGraph: {
21
+ storageType: 'graph',
22
+ graphServerTag: 'GraphHandler'
23
+ }
24
+ }
25
+ } = {}) {
26
+ if (!attributeTag || !targetServiceRoot) {
27
+ return [];
28
+ }
29
+
30
+ const tag = attributeTag;
31
+ const storageResourceTags = Object.keys(graphStorageResources);
32
+
33
+ // 1. {tag}ValueStandardPropertyLabel.js
34
+ const labelSchema = {
35
+ objectType: `${tag}ValueStandardPropertyLabel`,
36
+ canDelete: true,
37
+ generatedBy: 'user',
38
+ storageResources: graphStorageResources,
39
+ fieldNames: {
40
+ [`${tag}ValueStandardPropertyLabelId`]: {
41
+ type: 'string',
42
+ randomOnCreate: true,
43
+ canUpdate: false,
44
+ storageResourceTags
45
+ },
46
+ label: {
47
+ type: 'string',
48
+ requiredOnCreate: true,
49
+ canUpdate: true,
50
+ storageResourceTags
51
+ }
52
+ },
53
+ identifiers: [
54
+ {
55
+ type: 'identifier',
56
+ fieldName: `${tag}ValueStandardPropertyLabelId`
57
+ }
58
+ ]
59
+ };
60
+
61
+ // 2. {tag}ValueStandardPropertyValue.js
62
+ const valueSchema = {
63
+ objectType: `${tag}ValueStandardPropertyValue`,
64
+ canDelete: true,
65
+ generatedBy: 'user',
66
+ storageResources: graphStorageResources,
67
+ fieldNames: {
68
+ [`${tag}ValueStandardPropertyValueId`]: {
69
+ type: 'string',
70
+ randomOnCreate: true,
71
+ canUpdate: false,
72
+ storageResourceTags
73
+ },
74
+ value: {
75
+ type: 'string',
76
+ requiredOnCreate: true,
77
+ canUpdate: true,
78
+ storageResourceTags
79
+ }
80
+ },
81
+ identifiers: [
82
+ {
83
+ type: 'identifier',
84
+ fieldName: `${tag}ValueStandardPropertyValueId`
85
+ }
86
+ ]
87
+ };
88
+
89
+ // 3. {tag}ValueStandard.js
90
+ const standardValueSchema = {
91
+ objectType: `${tag}ValueStandard`,
92
+ canDelete: true,
93
+ generatedBy: 'user',
94
+ storageResources: graphStorageResources,
95
+ fieldNames: {
96
+ [`${tag}ValueStandardId`]: {
97
+ type: 'string',
98
+ randomOnCreate: true,
99
+ canUpdate: false,
100
+ storageResourceTags
101
+ },
102
+ value: {
103
+ type: 'string',
104
+ requiredOnCreate: true,
105
+ canUpdate: true,
106
+ storageResourceTags
107
+ }
108
+ },
109
+ identifiers: [
110
+ {
111
+ type: 'identifier',
112
+ fieldName: `${tag}ValueStandardId`
113
+ }
114
+ ]
115
+ };
116
+
117
+ const relDir = path.join(
118
+ 'app',
119
+ 'src',
120
+ 'schemas',
121
+ 'ObjectSchemas',
122
+ 'generatedCode',
123
+ 'attributeTree',
124
+ 'propertyValue'
125
+ );
126
+
127
+ return [
128
+ {
129
+ path: path.join(
130
+ targetServiceRoot,
131
+ relDir,
132
+ `${tag}ValueStandardPropertyLabel.js`
133
+ ),
134
+ content: _renderObjectSchema(labelSchema)
135
+ },
136
+ {
137
+ path: path.join(
138
+ targetServiceRoot,
139
+ relDir,
140
+ `${tag}ValueStandardPropertyValue.js`
141
+ ),
142
+ content: _renderObjectSchema(valueSchema)
143
+ },
144
+ {
145
+ path: path.join(
146
+ targetServiceRoot,
147
+ relDir,
148
+ `${tag}ValueStandard.js`
149
+ ),
150
+ content: _renderObjectSchema(standardValueSchema)
151
+ }
152
+ ];
153
+ }
@@ -0,0 +1,111 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+
4
+ /**
5
+ * Resolves target service root path based on attributeTag and developer suffix.
6
+ *
7
+ * @param {Object} params
8
+ * @param {string} params.currentServiceRoot - Root path of the current service
9
+ * @param {string} params.attributeTag - The attribute tag, e.g. 'sellOfferTerm'
10
+ * @param {string} [params.customOverridePath] - Optional custom path override
11
+ * @returns {string|null} Resolved absolute path or null if not found
12
+ */
13
+ export function resolveTargetServicePath({
14
+ currentServiceRoot,
15
+ attributeTag,
16
+ customOverridePath
17
+ } = {}) {
18
+ if (!currentServiceRoot || !attributeTag) {
19
+ return null;
20
+ }
21
+
22
+ if (customOverridePath) {
23
+ const resolvedCustom = path.resolve(
24
+ currentServiceRoot,
25
+ customOverridePath
26
+ );
27
+ if (fs.existsSync(resolvedCustom)) {
28
+ return resolvedCustom;
29
+ }
30
+ }
31
+
32
+ const currentFolderName = path.basename(currentServiceRoot);
33
+ const parentDir = path.resolve(currentServiceRoot, '..');
34
+
35
+ if (!fs.existsSync(parentDir)) {
36
+ return null;
37
+ }
38
+
39
+ let entries = [];
40
+ try {
41
+ entries = fs.readdirSync(parentDir, { withFileTypes: true });
42
+ } catch (err) {
43
+ return null;
44
+ }
45
+
46
+ const suffixMatch = currentFolderName.match(/-([a-zA-Z0-9]+)$/);
47
+ let devSuffix = '';
48
+ if (suffixMatch && suffixMatch[1]) {
49
+ devSuffix = suffixMatch[1].toLowerCase();
50
+ }
51
+
52
+ const normalizedTag = attributeTag.toLowerCase();
53
+ const kebabTag = attributeTag
54
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
55
+ .toLowerCase();
56
+
57
+ const priority1Matches = [];
58
+ const priority2Matches = [];
59
+ const priority3Matches = [];
60
+
61
+ for (const entry of entries) {
62
+ if (!entry.isDirectory()) {
63
+ continue;
64
+ }
65
+
66
+ if (entry.name === currentFolderName) {
67
+ continue;
68
+ }
69
+
70
+ const folderNameLower = entry.name.toLowerCase();
71
+ const hasTagMatch =
72
+ folderNameLower.includes(normalizedTag) ||
73
+ folderNameLower.includes(kebabTag);
74
+
75
+ if (!hasTagMatch) {
76
+ continue;
77
+ }
78
+
79
+ const fullPath = path.join(parentDir, entry.name);
80
+ const hasStructure =
81
+ fs.existsSync(path.join(fullPath, 'app', 'src')) ||
82
+ fs.existsSync(path.join(fullPath, 'package.json'));
83
+
84
+ if (!hasStructure) {
85
+ continue;
86
+ }
87
+
88
+ if (devSuffix !== '' && folderNameLower.endsWith('-' + devSuffix)) {
89
+ priority1Matches.push(fullPath);
90
+ } else if (
91
+ folderNameLower.endsWith(normalizedTag) ||
92
+ folderNameLower.endsWith(kebabTag)
93
+ ) {
94
+ priority2Matches.push(fullPath);
95
+ } else {
96
+ priority3Matches.push(fullPath);
97
+ }
98
+ }
99
+
100
+ if (priority1Matches.length > 0) {
101
+ return priority1Matches[0];
102
+ }
103
+ if (priority2Matches.length > 0) {
104
+ return priority2Matches[0];
105
+ }
106
+ if (priority3Matches.length > 0) {
107
+ return priority3Matches[0];
108
+ }
109
+
110
+ return null;
111
+ }
@@ -1,7 +1,7 @@
1
1
  import ejsLib from 'ejs';
2
2
  import { readFile } from 'node:fs/promises';
3
3
 
4
- import { customFlowNextSteps, flowHasRbac, upperFirst } from '../custom/customFlows.js';
4
+ import { customFlowNextSteps } from '../custom/customFlows.js';
5
5
  import { createCrudActionPlans } from '../crud/crudActionPlan.js';
6
6
 
7
7
  const TEMPLATE_URL = new URL('./templates/', import.meta.url);
@@ -217,29 +217,6 @@ export async function emitCoreFunctionArtifacts({ project, objects = [], relatio
217
217
  (objects || []).filter(o => o.belongTo?.serviceTag && o.belongTo.serviceTag !== 'Rbac').map(o => o.belongTo.serviceTag)
218
218
  )).sort();
219
219
 
220
- const customRbacFlows = (flows || []).filter((f) => flowHasRbac(f, objects));
221
- const customRbacFlowTags = customRbacFlows.map((f) => f.flowTag);
222
- const customRbacFlowsWithTags = customRbacFlows.map((f) => {
223
- const roleName = upperFirst(f.flowTag);
224
- const matched = objects.find((o) => o.objectType === f.objType?.objectType);
225
- const targetServiceTags = [];
226
- const belongTo = matched?.belongTo;
227
- if (belongTo) {
228
- if (Array.isArray(belongTo)) {
229
- for (const b of belongTo) {
230
- if (b?.serviceTag) targetServiceTags.push(b.serviceTag);
231
- }
232
- } else if (belongTo.serviceTag) {
233
- targetServiceTags.push(belongTo.serviceTag);
234
- }
235
- }
236
- return {
237
- roleName,
238
- flowTag: f.flowTag,
239
- targetServiceTags: Array.from(new Set(targetServiceTags))
240
- };
241
- });
242
-
243
220
  const crudPlans = createCrudActionPlans(objects);
244
221
  const hasQuotaReservation = crudPlans?.Create?.hasQuotaReservation ?? false;
245
222
 
@@ -250,8 +227,6 @@ export async function emitCoreFunctionArtifacts({ project, objects = [], relatio
250
227
  relationships,
251
228
  flows,
252
229
  customFlowNextSteps: customFlowNextSteps(flows),
253
- customRbacFlowTags,
254
- customRbacFlowsWithTags,
255
230
  objectGraphServiceTags,
256
231
  relationshipGraphServiceTags,
257
232
  crud,
@@ -178,23 +178,6 @@ const tableConfigs = {
178
178
  }
179
179
  });
180
180
  });
181
-
182
- const currentServiceTag = (typeof serviceTag !== 'undefined' && serviceTag) ? serviceTag : ((typeof project !== 'undefined' && project?.serviceTag) ? project.serviceTag : '');
183
- const rbacSubs = [];
184
-
185
- if (typeof customRbacFlowTags !== 'undefined' && customRbacFlowTags && customRbacFlowTags.length > 0) {
186
- const allRbacTags = Array.from(new Set([
187
- 'Rbac',
188
- currentServiceTag,
189
- ...(typeof rbacValidatorServiceTags !== 'undefined' ? rbacValidatorServiceTags : [])
190
- ])).filter(Boolean);
191
- customRbacFlowTags.forEach(function(flowTag) {
192
- const tagUpper = flowTag[0].toUpperCase() + flowTag.slice(1);
193
- allRbacTags.forEach(function(tag) {
194
- rbacSubs.push({ serviceTag: tag, topicName: 'ValidatorRbac_Out', sqsEndpoint: `${tagUpper}RbacCallbackHdrSqs` });
195
- });
196
- });
197
- }
198
181
  -%>
199
182
  const snsTopicSubscriptions = [
200
183
  <% if (relSubs.length > 0) { -%>
@@ -247,19 +230,6 @@ const snsTopicSubscriptions = [
247
230
  sqsEndpoint: '<%= sub.sqsEndpoint %>'
248
231
  },
249
232
  <% }); -%>
250
- <% } -%>
251
- <% if (rbacSubs.length > 0) { -%>
252
-
253
- // ------------------------------------------------------------
254
- // RBAC Validator Subscriptions
255
- // ------------------------------------------------------------
256
- <% rbacSubs.forEach(function(sub, idx) { -%>
257
- {
258
- serviceTag: '<%= sub.serviceTag %>',
259
- topicName: '<%= sub.topicName %>',
260
- sqsEndpoint: '<%= sub.sqsEndpoint %>'
261
- },
262
- <% }); -%>
263
233
  <% } -%>
264
234
 
265
235
  //(<additionalSubscription>)
@@ -4,8 +4,7 @@ import {
4
4
  generatedDsqFlows,
5
5
  generatedOwnTopicFlows,
6
6
  supportedCustomFlows,
7
- upperFirst,
8
- flowHasRbac
7
+ upperFirst
9
8
  } from './customFlows.js';
10
9
 
11
10
  export const YAML_PATH = 'app/sls_yaml/generatedCode/source/flow-schema.yml';
@@ -35,12 +34,6 @@ export function ownTopicRootPaths(flow, objects = []) {
35
34
  `${source}/${tag}_WbsMain.js`,
36
35
  `${source}/${tag}_HdrWbs.js`
37
36
  ];
38
- if (flowHasRbac(flow, objects)) {
39
- paths.push(
40
- `${source}/${tag}RbacCallback_Main.js`,
41
- `${source}/${tag}RbacCallback_HdrSqs.js`
42
- );
43
- }
44
37
  return paths;
45
38
  }
46
39
 
@@ -52,12 +45,6 @@ export function flowPaths(flow, objects = []) {
52
45
  if (needsProcessMain(flow)) {
53
46
  paths.push(`${source}/${process}_Main.js`);
54
47
  }
55
- if (flowHasRbac(flow, objects)) {
56
- paths.push(
57
- `${source}/${tag}RbacCallback_Main.js`,
58
- `${source}/${tag}RbacCallback_HdrSqs.js`
59
- );
60
- }
61
48
  if (flow.event.includes('extTopic') && !flow.event.includes('ownTopic')) {
62
49
  paths.push(`${source}/${process}_HdrSqs.js`);
63
50
  }
@@ -116,7 +103,7 @@ export function customFlowApplicationManagedPaths(
116
103
  const extSteps = flowExtTopicSteps(flows);
117
104
  const dsqSteps = flowDsqSteps(flows);
118
105
 
119
- return [
106
+ return Array.from(new Set([
120
107
  ...customFlowList.flatMap((flow) => flowPaths(flow, objects)),
121
108
  ...generatedRoots.flatMap((flow) => ownTopicRootPaths(flow, objects)),
122
109
  ...extSteps.flatMap(({ flowTag, stepName }) => {
@@ -145,5 +132,5 @@ export function customFlowApplicationManagedPaths(
145
132
  dsqSteps.length > 0
146
133
  ? [YAML_PATH]
147
134
  : [])
148
- ];
135
+ ]));
149
136
  }