@fractal_cloud/sdk 0.1.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -28
- package/dist/index.cjs +650 -73
- package/dist/index.d.cts +462 -13
- package/dist/index.d.mts +462 -13
- package/dist/index.mjs +649 -74
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -41,7 +41,12 @@ superagent = __toESM(superagent);
|
|
|
41
41
|
*
|
|
42
42
|
* @type {KebabCaseString}
|
|
43
43
|
*/
|
|
44
|
-
const DEFAULT_KEBAB_CASE_STRING = {
|
|
44
|
+
const DEFAULT_KEBAB_CASE_STRING = {
|
|
45
|
+
_type: "kebab",
|
|
46
|
+
value: "",
|
|
47
|
+
equals: () => false,
|
|
48
|
+
toString: () => ""
|
|
49
|
+
};
|
|
45
50
|
/**
|
|
46
51
|
* Validates whether a given string follows the kebab-case format.
|
|
47
52
|
*
|
|
@@ -55,7 +60,7 @@ const DEFAULT_KEBAB_CASE_STRING = { kebabValue: "" };
|
|
|
55
60
|
* @returns {string[]} - An empty array if the string is valid, otherwise an array containing an error message.
|
|
56
61
|
*/
|
|
57
62
|
const isValidKebabCaseString = (value) => {
|
|
58
|
-
if (!/^[a-z][a-z0-9]*(-[a-z][a-z0-9]*)*$/.test(value)) return [
|
|
63
|
+
if (!/^[a-z][a-z0-9]*(-[a-z][a-z0-9]*)*$/.test(value)) return [` Value '${value}' must be in kebab-case`];
|
|
59
64
|
return [];
|
|
60
65
|
};
|
|
61
66
|
/**
|
|
@@ -72,17 +77,21 @@ const getKebabCaseStringBuilder = () => {
|
|
|
72
77
|
const internalState = { ...DEFAULT_KEBAB_CASE_STRING };
|
|
73
78
|
const builder = {
|
|
74
79
|
withValue: (value) => {
|
|
75
|
-
internalState.
|
|
80
|
+
internalState.value = value;
|
|
76
81
|
return builder;
|
|
77
82
|
},
|
|
78
83
|
reset: () => {
|
|
79
|
-
internalState.
|
|
84
|
+
internalState.value = DEFAULT_KEBAB_CASE_STRING.value;
|
|
80
85
|
return builder;
|
|
81
86
|
},
|
|
82
87
|
build: () => {
|
|
83
|
-
const validationErrors = isValidKebabCaseString(internalState.
|
|
88
|
+
const validationErrors = isValidKebabCaseString(internalState.value);
|
|
84
89
|
if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
|
|
85
|
-
return {
|
|
90
|
+
return {
|
|
91
|
+
...internalState,
|
|
92
|
+
equals: (other) => internalState.value === other.value,
|
|
93
|
+
toString: () => internalState.value
|
|
94
|
+
};
|
|
86
95
|
}
|
|
87
96
|
};
|
|
88
97
|
return builder;
|
|
@@ -94,8 +103,8 @@ let KebabCaseString$1;
|
|
|
94
103
|
|
|
95
104
|
//#endregion
|
|
96
105
|
//#region src/values/version.ts
|
|
97
|
-
const equals$
|
|
98
|
-
const toString$
|
|
106
|
+
const equals$4 = (a, b) => a.major === b.major && a.minor === b.minor && a.patch === b.patch;
|
|
107
|
+
const toString$2 = (version) => `v${version.major}.${version.minor}.${version.patch}`;
|
|
99
108
|
/**
|
|
100
109
|
* Represents the default version for an application or library.
|
|
101
110
|
*
|
|
@@ -106,7 +115,7 @@ const DEFAULT_VERSION = {
|
|
|
106
115
|
major: 0,
|
|
107
116
|
minor: 0,
|
|
108
117
|
patch: 0,
|
|
109
|
-
equals: (other) => equals$
|
|
118
|
+
equals: (other) => equals$4(DEFAULT_VERSION, other)
|
|
110
119
|
};
|
|
111
120
|
/**
|
|
112
121
|
* Validates if the provided version object is properly initialized or equivalent to the default version.
|
|
@@ -116,7 +125,7 @@ const DEFAULT_VERSION = {
|
|
|
116
125
|
* an array containing one error message. Otherwise, it returns an empty array.
|
|
117
126
|
*/
|
|
118
127
|
const isValidVersion = (version) => {
|
|
119
|
-
if (equals$
|
|
128
|
+
if (equals$4(version, DEFAULT_VERSION)) return [" Version must be initialized"];
|
|
120
129
|
return [];
|
|
121
130
|
};
|
|
122
131
|
/**
|
|
@@ -173,8 +182,8 @@ const getVersionBuilder = () => {
|
|
|
173
182
|
if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
|
|
174
183
|
const builtVersion = {
|
|
175
184
|
...internalState,
|
|
176
|
-
equals: (other) => equals$
|
|
177
|
-
toString: () => toString$
|
|
185
|
+
equals: (other) => equals$4(builtVersion, other),
|
|
186
|
+
toString: () => toString$2(builtVersion)
|
|
178
187
|
};
|
|
179
188
|
return builtVersion;
|
|
180
189
|
}
|
|
@@ -208,7 +217,7 @@ let OwnerType$1 = /* @__PURE__ */ function(OwnerType) {
|
|
|
208
217
|
//#endregion
|
|
209
218
|
//#region src/values/guid.ts
|
|
210
219
|
const isValidUuid = (value) => {
|
|
211
|
-
if (!/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(value)) return [`Value '${value}' must be a valid uuid`];
|
|
220
|
+
if (!/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(value)) return [` Value '${value}' must be a valid uuid`];
|
|
212
221
|
return [];
|
|
213
222
|
};
|
|
214
223
|
|
|
@@ -220,7 +229,11 @@ const isValidUuid = (value) => {
|
|
|
220
229
|
* This variable is declared as a constant to prevent modification
|
|
221
230
|
* and is designed to not pass validation checks.
|
|
222
231
|
*/
|
|
223
|
-
const DEFAULT_OWNER_ID = {
|
|
232
|
+
const DEFAULT_OWNER_ID = {
|
|
233
|
+
_type: "ownerId",
|
|
234
|
+
value: "",
|
|
235
|
+
toString: () => ""
|
|
236
|
+
};
|
|
224
237
|
/**
|
|
225
238
|
* Validates whether the given string value is a valid UUID.
|
|
226
239
|
*
|
|
@@ -232,8 +245,11 @@ const DEFAULT_OWNER_ID = { ownerIdValue: "" };
|
|
|
232
245
|
* @returns {string[]} An array containing error messages if invalid, or an empty array if valid.
|
|
233
246
|
*/
|
|
234
247
|
const isValidOwnerId = (value) => {
|
|
235
|
-
if (!value || !value.
|
|
236
|
-
return isValidUuid(value.
|
|
248
|
+
if (!value || !value.value) return ["[Owner Id] Value must be a non-empty string"];
|
|
249
|
+
return addContextToErrors$8(value, isValidUuid(value.value));
|
|
250
|
+
};
|
|
251
|
+
const addContextToErrors$8 = (value, errors) => {
|
|
252
|
+
return errors.map((error) => `[Owner Id: ${value.toString()}]${error}`);
|
|
237
253
|
};
|
|
238
254
|
/**
|
|
239
255
|
* Creates a builder for constructing a OwnerId object. The builder enforces uuid case formatting and ensures
|
|
@@ -249,17 +265,20 @@ const getOwnerIdBuilder = () => {
|
|
|
249
265
|
const internalState = { ...DEFAULT_OWNER_ID };
|
|
250
266
|
const builder = {
|
|
251
267
|
withValue: (value) => {
|
|
252
|
-
internalState.
|
|
268
|
+
internalState.value = value;
|
|
253
269
|
return builder;
|
|
254
270
|
},
|
|
255
271
|
reset: () => {
|
|
256
|
-
internalState.
|
|
272
|
+
internalState.value = DEFAULT_OWNER_ID.value;
|
|
257
273
|
return builder;
|
|
258
274
|
},
|
|
259
275
|
build: () => {
|
|
260
276
|
const validationErrors = isValidOwnerId(internalState);
|
|
261
277
|
if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
|
|
262
|
-
return {
|
|
278
|
+
return {
|
|
279
|
+
...internalState,
|
|
280
|
+
toString: () => internalState.value
|
|
281
|
+
};
|
|
263
282
|
}
|
|
264
283
|
};
|
|
265
284
|
return builder;
|
|
@@ -271,17 +290,18 @@ let OwnerId$1;
|
|
|
271
290
|
|
|
272
291
|
//#endregion
|
|
273
292
|
//#region src/bounded_context/id.ts
|
|
274
|
-
const equals$
|
|
293
|
+
const equals$3 = (a, b) => a.ownerType === b.ownerType && a.ownerId.value === b.ownerId.value && a.name.value === b.name.value;
|
|
275
294
|
/**
|
|
276
295
|
* A default value for the bounded context identifier used in the system.
|
|
277
296
|
* It contains values that will not pass validation checks.
|
|
278
297
|
*/
|
|
279
298
|
const DEFAULT_BOUNDED_CONTEXT_ID = {
|
|
299
|
+
_type: "bounded_context",
|
|
280
300
|
ownerType: OwnerType$1.Personal,
|
|
281
301
|
ownerId: DEFAULT_OWNER_ID,
|
|
282
302
|
name: DEFAULT_KEBAB_CASE_STRING,
|
|
283
|
-
equals: (
|
|
284
|
-
toString: () =>
|
|
303
|
+
equals: () => false,
|
|
304
|
+
toString: () => ""
|
|
285
305
|
};
|
|
286
306
|
/**
|
|
287
307
|
* Determines whether the given value is a valid Id.
|
|
@@ -296,11 +316,14 @@ const DEFAULT_BOUNDED_CONTEXT_ID = {
|
|
|
296
316
|
* the `isValidKebabCaseString` function.
|
|
297
317
|
*/
|
|
298
318
|
const isValidBoundedContextId = (value) => {
|
|
299
|
-
const ownerIdErrors = isValidOwnerId(value.ownerId);
|
|
300
|
-
const nameErrors = isValidKebabCaseString(value.name.
|
|
301
|
-
return [...ownerIdErrors
|
|
319
|
+
const ownerIdErrors = addContextToErrors$7(value, isValidOwnerId(value.ownerId));
|
|
320
|
+
const nameErrors = addContextToErrors$7(value, isValidKebabCaseString(value.name.value));
|
|
321
|
+
return [...ownerIdErrors, ...nameErrors];
|
|
302
322
|
};
|
|
303
|
-
const
|
|
323
|
+
const addContextToErrors$7 = (bcId, errors) => {
|
|
324
|
+
return errors.map((error) => `[Bounded Context Id: ${bcId.toString()}]${error}`);
|
|
325
|
+
};
|
|
326
|
+
const boundedContextIdToString = (id) => `${id.ownerType.toString()}/${id.ownerId.value}/${id.name.value}`;
|
|
304
327
|
/**
|
|
305
328
|
* Creates and returns a builder for constructing a `Id` object.
|
|
306
329
|
*
|
|
@@ -338,7 +361,7 @@ const getBoundedContextIdBuilder = () => {
|
|
|
338
361
|
if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
|
|
339
362
|
const builtId = {
|
|
340
363
|
...internalState,
|
|
341
|
-
equals: (other) => equals$
|
|
364
|
+
equals: (other) => equals$3(builtId, other),
|
|
342
365
|
toString: () => boundedContextIdToString(builtId)
|
|
343
366
|
};
|
|
344
367
|
return builtId;
|
|
@@ -349,7 +372,8 @@ const getBoundedContextIdBuilder = () => {
|
|
|
349
372
|
|
|
350
373
|
//#endregion
|
|
351
374
|
//#region src/fractal/id.ts
|
|
352
|
-
const
|
|
375
|
+
const equals$2 = (a, b) => a.boundedContextId.equals(b.boundedContextId) && a.name.equals(b.name) && a.version.equals(b.version);
|
|
376
|
+
const toString$1 = (id) => `${id.boundedContextId.toString()}/${id.name.toString()}:${id.version.toString()}`;
|
|
353
377
|
/**
|
|
354
378
|
* Validates a given Fractal ID and returns a list of error messages if any validation fails.
|
|
355
379
|
* The validation process includes checking the bounded context ID, the name, and the version of the Fractal ID.
|
|
@@ -358,15 +382,18 @@ const toString = (id) => `${id.boundedContextId.toString()}/${id.name.kebabValue
|
|
|
358
382
|
* @returns {string[]} An array of error messages. Each error message indicates the specific issue with the bounded context ID, name, or version of the Fractal ID.
|
|
359
383
|
*/
|
|
360
384
|
const isValidFractalId = (id) => {
|
|
361
|
-
const boundedContextIdErrors = isValidBoundedContextId(id.boundedContextId);
|
|
362
|
-
const nameErrors = isValidKebabCaseString(id.name.
|
|
363
|
-
const versionErrors = isValidVersion(id.version);
|
|
385
|
+
const boundedContextIdErrors = addContextToErrors$6(id, isValidBoundedContextId(id.boundedContextId));
|
|
386
|
+
const nameErrors = addContextToErrors$6(id, isValidKebabCaseString(id.name.value));
|
|
387
|
+
const versionErrors = addContextToErrors$6(id, isValidVersion(id.version));
|
|
364
388
|
return [
|
|
365
|
-
...boundedContextIdErrors
|
|
366
|
-
...nameErrors
|
|
367
|
-
...versionErrors
|
|
389
|
+
...boundedContextIdErrors,
|
|
390
|
+
...nameErrors,
|
|
391
|
+
...versionErrors
|
|
368
392
|
];
|
|
369
393
|
};
|
|
394
|
+
const addContextToErrors$6 = (value, errors) => {
|
|
395
|
+
return errors.map((error) => `[Fractal Id: ${toString$1(value)}]${error}`);
|
|
396
|
+
};
|
|
370
397
|
/**
|
|
371
398
|
* Represents the default identifier for a fractal instance.
|
|
372
399
|
*
|
|
@@ -386,7 +413,9 @@ const isValidFractalId = (id) => {
|
|
|
386
413
|
const DEFAULT_FRACTAL_ID = {
|
|
387
414
|
boundedContextId: DEFAULT_BOUNDED_CONTEXT_ID,
|
|
388
415
|
name: DEFAULT_KEBAB_CASE_STRING,
|
|
389
|
-
version: DEFAULT_VERSION
|
|
416
|
+
version: DEFAULT_VERSION,
|
|
417
|
+
equals: () => false,
|
|
418
|
+
toString: () => ""
|
|
390
419
|
};
|
|
391
420
|
/**
|
|
392
421
|
* Provides a builder for constructing a `FractalId` object.
|
|
@@ -429,7 +458,8 @@ const getFractalIdBuilder = () => {
|
|
|
429
458
|
if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
|
|
430
459
|
const builtId = {
|
|
431
460
|
...internalState,
|
|
432
|
-
|
|
461
|
+
equals: (other) => equals$2(builtId, other),
|
|
462
|
+
toString: () => toString$1(builtId)
|
|
433
463
|
};
|
|
434
464
|
return builtId;
|
|
435
465
|
}
|
|
@@ -472,7 +502,7 @@ let ServiceDeliveryModel$1 = /* @__PURE__ */ function(ServiceDeliveryModel) {
|
|
|
472
502
|
* if the string is valid.
|
|
473
503
|
*/
|
|
474
504
|
const isValidPascalCaseString = (value) => {
|
|
475
|
-
if (!/^[A-Z][a-zA-Z]*$/.test(value)) return [`Value '${value}' must be in PascalCase`];
|
|
505
|
+
if (!/^[A-Z][a-zA-Z]*$/.test(value)) return [` Value '${value}' must be in PascalCase`];
|
|
476
506
|
return [];
|
|
477
507
|
};
|
|
478
508
|
/**
|
|
@@ -481,7 +511,12 @@ const isValidPascalCaseString = (value) => {
|
|
|
481
511
|
* This variable is declared as a constant to prevent modification
|
|
482
512
|
* and is designed to not pass validation checks.
|
|
483
513
|
*/
|
|
484
|
-
const DEFAULT_PASCAL_CASE_STRING = {
|
|
514
|
+
const DEFAULT_PASCAL_CASE_STRING = {
|
|
515
|
+
_type: "pascal",
|
|
516
|
+
value: "",
|
|
517
|
+
equals: () => false,
|
|
518
|
+
toString: () => ""
|
|
519
|
+
};
|
|
485
520
|
/**
|
|
486
521
|
* Creates a builder for constructing a PascalCaseString object. The builder enforces Pascal case formatting and ensures
|
|
487
522
|
* a valid string is set before building. Once built, the PascalCaseString object becomes immutable.
|
|
@@ -496,17 +531,21 @@ const getPascalCaseStringBuilder = () => {
|
|
|
496
531
|
const internalState = { ...DEFAULT_PASCAL_CASE_STRING };
|
|
497
532
|
const builder = {
|
|
498
533
|
withValue: (value) => {
|
|
499
|
-
internalState.
|
|
534
|
+
internalState.value = value;
|
|
500
535
|
return builder;
|
|
501
536
|
},
|
|
502
537
|
reset: () => {
|
|
503
|
-
internalState.
|
|
538
|
+
internalState.value = DEFAULT_PASCAL_CASE_STRING.value;
|
|
504
539
|
return builder;
|
|
505
540
|
},
|
|
506
541
|
build: () => {
|
|
507
|
-
const validationErrors = isValidPascalCaseString(internalState.
|
|
542
|
+
const validationErrors = isValidPascalCaseString(internalState.value);
|
|
508
543
|
if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
|
|
509
|
-
return {
|
|
544
|
+
return {
|
|
545
|
+
...internalState,
|
|
546
|
+
equals: (other) => internalState.value === other.value,
|
|
547
|
+
toString: () => internalState.value
|
|
548
|
+
};
|
|
510
549
|
}
|
|
511
550
|
};
|
|
512
551
|
return builder;
|
|
@@ -566,8 +605,8 @@ const DEFAULT_COMPONENT_TYPE = {
|
|
|
566
605
|
* @returns {string[]} An array of error messages if validation fails; an empty array if the name is valid.
|
|
567
606
|
*/
|
|
568
607
|
const isValidComponentType = (type) => {
|
|
569
|
-
const nameError = isValidPascalCaseString(type.name.
|
|
570
|
-
if (nameError.length > 0) return nameError.map((x) => `[Component Type: ${type.name.
|
|
608
|
+
const nameError = isValidPascalCaseString(type.name.value);
|
|
609
|
+
if (nameError.length > 0) return nameError.map((x) => `[Component Type: ${type.name.value}][Name]${x}`);
|
|
571
610
|
return [];
|
|
572
611
|
};
|
|
573
612
|
/**
|
|
@@ -680,7 +719,10 @@ const getBlueprintComponentTypeBuilder = () => {
|
|
|
680
719
|
build: () => {
|
|
681
720
|
const validationErrors = isValidBlueprintComponentType(internalState);
|
|
682
721
|
if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
|
|
683
|
-
return {
|
|
722
|
+
return {
|
|
723
|
+
...internalState,
|
|
724
|
+
toString: () => `${internalState.domain}.${internalState.serviceDeliveryModel}.${internalState.name}`
|
|
725
|
+
};
|
|
684
726
|
}
|
|
685
727
|
};
|
|
686
728
|
return builder;
|
|
@@ -722,16 +764,17 @@ const getParametersInstance = () => {
|
|
|
722
764
|
* @returns {boolean} - Returns true if the identifier is in a valid kebab-case format, false otherwise.
|
|
723
765
|
*/
|
|
724
766
|
const isValidId = (id) => {
|
|
725
|
-
return isValidKebabCaseString(id.value.
|
|
767
|
+
return isValidKebabCaseString(id.value.toString()).map((x) => `[Component Id: ${id.value.toString()}]${x}`);
|
|
726
768
|
};
|
|
727
|
-
const equals = (a, b) => a.value === b.value;
|
|
769
|
+
const equals$1 = (a, b) => a.value === b.value;
|
|
728
770
|
/**
|
|
729
771
|
* Represents the default identifier used in the application.
|
|
730
772
|
* It is initialized with a value that will not pass validation.
|
|
731
773
|
*/
|
|
732
774
|
const DEFAULT_COMPONENT_ID = {
|
|
733
775
|
value: DEFAULT_KEBAB_CASE_STRING,
|
|
734
|
-
equals: (other) => equals(DEFAULT_COMPONENT_ID, other)
|
|
776
|
+
equals: (other) => equals$1(DEFAULT_COMPONENT_ID, other),
|
|
777
|
+
toString: () => ""
|
|
735
778
|
};
|
|
736
779
|
/**
|
|
737
780
|
* Creates and returns a builder for constructing a `ComponentId` object.
|
|
@@ -759,7 +802,8 @@ const getComponentIdBuilder = () => {
|
|
|
759
802
|
if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
|
|
760
803
|
const builtId = {
|
|
761
804
|
...internalState,
|
|
762
|
-
equals: (other) => equals(builtId, other)
|
|
805
|
+
equals: (other) => equals$1(builtId, other),
|
|
806
|
+
toString: () => builtId.value.toString()
|
|
763
807
|
};
|
|
764
808
|
return builtId;
|
|
765
809
|
}
|
|
@@ -885,18 +929,21 @@ const DEFAULT_COMPONENT = {
|
|
|
885
929
|
* @returns {string[]} An array of error messages, each describing a specific validation failure. If no errors are found, the array will be empty.
|
|
886
930
|
*/
|
|
887
931
|
const isValidComponent = (component) => {
|
|
888
|
-
const idErrors = isValidId(component.id);
|
|
889
|
-
const typeErrors = isValidComponentType(component.type);
|
|
890
|
-
const versionErrors = isValidVersion(component.version);
|
|
891
|
-
const displayNameErrors = isNonEmptyString(component.displayName) ? [] : ["Display name must be a non-empty string"];
|
|
932
|
+
const idErrors = addContextToErrors$5(component.id, isValidId(component.id));
|
|
933
|
+
const typeErrors = addContextToErrors$5(component.id, isValidComponentType(component.type));
|
|
934
|
+
const versionErrors = addContextToErrors$5(component.id, isValidVersion(component.version));
|
|
935
|
+
const displayNameErrors = addContextToErrors$5(component.id, isNonEmptyString(component.displayName) ? [] : ["Display name must be a non-empty string"]);
|
|
892
936
|
return [
|
|
893
|
-
...idErrors
|
|
894
|
-
...typeErrors
|
|
895
|
-
...versionErrors
|
|
896
|
-
...typeErrors
|
|
897
|
-
...displayNameErrors
|
|
937
|
+
...idErrors,
|
|
938
|
+
...typeErrors,
|
|
939
|
+
...versionErrors,
|
|
940
|
+
...typeErrors,
|
|
941
|
+
...displayNameErrors
|
|
898
942
|
];
|
|
899
943
|
};
|
|
944
|
+
const addContextToErrors$5 = (componentId, errors) => {
|
|
945
|
+
return errors.map((error) => `[Component: ${componentId.toString()}]${error}`);
|
|
946
|
+
};
|
|
900
947
|
/**
|
|
901
948
|
* Creates and returns a builder for constructing `Component` objects.
|
|
902
949
|
*
|
|
@@ -1034,7 +1081,7 @@ const isValidBlueprintComponent = (component) => {
|
|
|
1034
1081
|
* - `withVersion(version: Version)`: Sets the version of the component.
|
|
1035
1082
|
* - `withDisplayName(displayName: string)`: Sets the display name for the component.
|
|
1036
1083
|
* - `withDescription(description: string)`: Sets a description for the component.
|
|
1037
|
-
* - `withParameters(parameters:
|
|
1084
|
+
* - `withParameters(parameters: Component.Parameters)`: Sets the parameters associated with the component.
|
|
1038
1085
|
* - `withLinks(links: ComponentLink[])`: Sets the links associated with the component.
|
|
1039
1086
|
* - `withDependencies(dependencies: BlueprintComponentDependency[])`: Sets the dependencies of the component.
|
|
1040
1087
|
* - `reset()`: Resets all properties of the component to their default values based on `DEFAULT_BLUEPRINT_COMPONENT`.
|
|
@@ -1122,22 +1169,23 @@ let BlueprintComponent;
|
|
|
1122
1169
|
|
|
1123
1170
|
//#endregion
|
|
1124
1171
|
//#region src/fractal/service.ts
|
|
1125
|
-
const CLIENT_ID_HEADER = "X-ClientID";
|
|
1126
|
-
const CLIENT_SECRET_HEADER = "X-ClientSecret";
|
|
1127
|
-
const FRACTAL_API_URL = "https://api.fractal.cloud";
|
|
1172
|
+
const CLIENT_ID_HEADER$1 = "X-ClientID";
|
|
1173
|
+
const CLIENT_SECRET_HEADER$1 = "X-ClientSecret";
|
|
1174
|
+
const FRACTAL_API_URL$1 = "https://api.fractal.cloud";
|
|
1128
1175
|
const deployFractal = async (credentials, fractal) => {
|
|
1129
|
-
|
|
1176
|
+
const fractalUrl = `${FRACTAL_API_URL$1}/blueprints/${fractal.id.toString().replace(":", "/")}`;
|
|
1177
|
+
((await superagent.default.get(fractalUrl).set(CLIENT_ID_HEADER$1, credentials.id.serviceAccountIdValue).set(CLIENT_SECRET_HEADER$1, credentials.secret).send()).status === 200 ? superagent.default.put(fractalUrl) : superagent.default.post(fractalUrl)).set(CLIENT_ID_HEADER$1, credentials.id.serviceAccountIdValue).set(CLIENT_SECRET_HEADER$1, credentials.secret).send({
|
|
1130
1178
|
description: fractal.description,
|
|
1131
1179
|
isPrivate: fractal.isPrivate,
|
|
1132
1180
|
components: fractal.components.map((c) => ({
|
|
1133
1181
|
...c,
|
|
1134
1182
|
type: c.type.toString(),
|
|
1135
|
-
id: c.id.value.
|
|
1183
|
+
id: c.id.value.toString(),
|
|
1136
1184
|
version: c.version.toString(),
|
|
1137
1185
|
parameters: c.parameters.toMap(),
|
|
1138
|
-
dependencies: c.dependencies.map((d) => d.id.value.
|
|
1186
|
+
dependencies: c.dependencies.map((d) => d.id.value.toString()),
|
|
1139
1187
|
links: c.links.map((l) => ({
|
|
1140
|
-
componentId: l.id.value.
|
|
1188
|
+
componentId: l.id.value.toString(),
|
|
1141
1189
|
settings: l.parameters.toMap()
|
|
1142
1190
|
})),
|
|
1143
1191
|
outputFields: Object.keys(c.outputFields.value)
|
|
@@ -1145,7 +1193,7 @@ const deployFractal = async (credentials, fractal) => {
|
|
|
1145
1193
|
}).catch((e) => console.error(e.message, e.response.text));
|
|
1146
1194
|
};
|
|
1147
1195
|
const destroyFractal = async (credentials, id) => {
|
|
1148
|
-
await superagent.default.delete(`${FRACTAL_API_URL}/blueprints/${id.toString().replace(":", "/")}`).set(CLIENT_ID_HEADER, credentials.id.serviceAccountIdValue).set(CLIENT_SECRET_HEADER, credentials.secret);
|
|
1196
|
+
await superagent.default.delete(`${FRACTAL_API_URL$1}/blueprints/${id.toString().replace(":", "/")}`).set(CLIENT_ID_HEADER$1, credentials.id.serviceAccountIdValue).set(CLIENT_SECRET_HEADER$1, credentials.secret);
|
|
1149
1197
|
};
|
|
1150
1198
|
let FractalService;
|
|
1151
1199
|
(function(_FractalService) {
|
|
@@ -1192,13 +1240,36 @@ const DEFAULT_FRACTAL = {
|
|
|
1192
1240
|
* @returns {string[]} An array of error messages describing any validation issues with the fractal.
|
|
1193
1241
|
*/
|
|
1194
1242
|
const isValidFractal = (fractal) => {
|
|
1195
|
-
const idErrors = isValidFractalId(fractal.id);
|
|
1196
|
-
const componentsErrors = !fractal.components || fractal.components.length === 0 ? [
|
|
1243
|
+
const idErrors = addContextToErrors$4(fractal.id, isValidFractalId(fractal.id));
|
|
1244
|
+
const componentsErrors = addContextToErrors$4(fractal.id, !fractal.components || fractal.components.length === 0 ? ["[Components] Components must not be empty"] : fractal.components.reduce((acc, x) => {
|
|
1197
1245
|
acc.push(...isValidBlueprintComponent(x));
|
|
1198
1246
|
return acc;
|
|
1199
|
-
}, []);
|
|
1247
|
+
}, []));
|
|
1200
1248
|
return [...idErrors, ...componentsErrors];
|
|
1201
1249
|
};
|
|
1250
|
+
const addContextToErrors$4 = (value, errors) => {
|
|
1251
|
+
return errors.map((error) => `[Fractal: ${value.toString()}]${error}`);
|
|
1252
|
+
};
|
|
1253
|
+
/**
|
|
1254
|
+
* Creates and returns a builder object for constructing Fractal objects.
|
|
1255
|
+
*
|
|
1256
|
+
* This builder provides a fluent interface for setting various properties of a Fractal
|
|
1257
|
+
* and includes methods for validation, resetting to defaults, and final construction.
|
|
1258
|
+
*
|
|
1259
|
+
* @returns {FractalBuilder} A builder object for incrementally building a Fractal.
|
|
1260
|
+
*
|
|
1261
|
+
* The builder object supports the following methods:
|
|
1262
|
+
* - `withId(value: FractalId): FractalBuilder` - Sets the ID of the Fractal.
|
|
1263
|
+
* - `withIsPrivate(value: boolean): FractalBuilder` - Sets the privacy status of the Fractal.
|
|
1264
|
+
* - `withDescription(value: string): FractalBuilder` - Sets the description of the Fractal.
|
|
1265
|
+
* - `withComponents(value: BlueprintComponent[]): FractalBuilder` - Appends a list of components to the Fractal.
|
|
1266
|
+
* - `withComponent(value: BlueprintComponent): FractalBuilder` - Appends a single component to the Fractal.
|
|
1267
|
+
* - `reset(): FractalBuilder` - Resets the builder’s state to the default Fractal properties.
|
|
1268
|
+
* - `build(): Fractal` - Validates and constructs a Fractal object.
|
|
1269
|
+
*
|
|
1270
|
+
* Throws:
|
|
1271
|
+
* - `SyntaxError` - If the constructed Fractal object is invalid during the build process.
|
|
1272
|
+
*/
|
|
1202
1273
|
const getFractalBuilder = () => {
|
|
1203
1274
|
const internalState = { ...DEFAULT_FRACTAL };
|
|
1204
1275
|
const builder = {
|
|
@@ -1284,9 +1355,12 @@ const DEFAULT = {
|
|
|
1284
1355
|
* @returns {boolean} Returns true if the bounded context is valid; otherwise, returns false.
|
|
1285
1356
|
*/
|
|
1286
1357
|
const isValidBoundedContext = (value) => {
|
|
1287
|
-
const idErrors = isValidBoundedContextId(value.id);
|
|
1288
|
-
const displayNameErrors = isNonEmptyString(value.displayName) ? [] : ["Display name must be a non-empty string"];
|
|
1289
|
-
return [...idErrors
|
|
1358
|
+
const idErrors = addContextToErrors$3(value.id, isValidBoundedContextId(value.id));
|
|
1359
|
+
const displayNameErrors = addContextToErrors$3(value.id, isNonEmptyString(value.displayName) ? [] : ["Display name must be a non-empty string"]);
|
|
1360
|
+
return [...idErrors, ...displayNameErrors];
|
|
1361
|
+
};
|
|
1362
|
+
const addContextToErrors$3 = (bcId, errors) => {
|
|
1363
|
+
return errors.map((error) => `[Bounded Context: ${bcId.toString()}]${error}`);
|
|
1290
1364
|
};
|
|
1291
1365
|
/**
|
|
1292
1366
|
* Creates a builder for constructing a BoundedContext object with a fluid API.
|
|
@@ -1465,6 +1539,505 @@ let ServiceAccountCredentials$1;
|
|
|
1465
1539
|
_ServiceAccountCredentials.getBuilder = getServiceAccountCredentialsBuilder;
|
|
1466
1540
|
})(ServiceAccountCredentials$1 || (ServiceAccountCredentials$1 = {}));
|
|
1467
1541
|
|
|
1542
|
+
//#endregion
|
|
1543
|
+
//#region src/environment/id.ts
|
|
1544
|
+
const equals = (a, b) => a.ownerType === b.ownerType && a.ownerId.value === b.ownerId.value && a.name.value === b.name.value;
|
|
1545
|
+
/**
|
|
1546
|
+
* Represents the default environment identifier used within the system.
|
|
1547
|
+
* The variable holds a constant, immutable object reflecting the default
|
|
1548
|
+
* properties and metadata of an environment.
|
|
1549
|
+
*
|
|
1550
|
+
* Properties:
|
|
1551
|
+
* - `ownerType`: An enumeration value specifying the type of owner (e.g., personal).
|
|
1552
|
+
* - `ownerId`: A constant value representing the default owner identifier.
|
|
1553
|
+
* - `name`: A default kebab-case formatted string for the environment name.
|
|
1554
|
+
* - `equals`: A function that always returns `false`, used to compare equality with another environment.
|
|
1555
|
+
* - `toString`: A function returning an empty string representation of the environment.
|
|
1556
|
+
*
|
|
1557
|
+
* The object is defined as `const` to ensure its immutability and integrity throughout its usage.
|
|
1558
|
+
*/
|
|
1559
|
+
const DEFAULT_ENVIRONMENT_ID = {
|
|
1560
|
+
_type: "environment",
|
|
1561
|
+
ownerType: OwnerType$1.Personal,
|
|
1562
|
+
ownerId: DEFAULT_OWNER_ID,
|
|
1563
|
+
name: DEFAULT_KEBAB_CASE_STRING,
|
|
1564
|
+
equals: () => false,
|
|
1565
|
+
toString: () => ""
|
|
1566
|
+
};
|
|
1567
|
+
/**
|
|
1568
|
+
* Validates whether the given environment ID is valid by checking its owner ID and name.
|
|
1569
|
+
*
|
|
1570
|
+
* @param {EnvironmentId} value - The environment ID to validate, which consists of an owner ID and a name.
|
|
1571
|
+
* @returns {string[]} An array of error messages, where each message describes a specific validation failure
|
|
1572
|
+
* for either the owner ID or the name. If no errors are present, the array is empty.
|
|
1573
|
+
*/
|
|
1574
|
+
const isValidEnvironmentId = (value) => {
|
|
1575
|
+
const ownerIdErrors = addContextToErrors$2(value, isValidOwnerId(value.ownerId));
|
|
1576
|
+
const nameErrors = addContextToErrors$2(value, isValidKebabCaseString(value.name.toString()));
|
|
1577
|
+
return [...ownerIdErrors, ...nameErrors];
|
|
1578
|
+
};
|
|
1579
|
+
const addContextToErrors$2 = (value, errors) => {
|
|
1580
|
+
return errors.map((error) => `[Environment Id: ${environmentIdToString(value)}]${error}`);
|
|
1581
|
+
};
|
|
1582
|
+
const environmentIdToString = (id) => `${id.ownerType.toString()}/${id.ownerId.value}/${id.name.value}`;
|
|
1583
|
+
/**
|
|
1584
|
+
* Creates and returns a builder for constructing a `Id` object.
|
|
1585
|
+
*
|
|
1586
|
+
* The builder allows customization of the `Id` properties such as `ownerType`,
|
|
1587
|
+
* while also enforcing constraints during the construction process, ensuring the resulting object is valid.
|
|
1588
|
+
* The builder is stateful and provides a method to reset to default values if needed.
|
|
1589
|
+
*
|
|
1590
|
+
* @returns {EnvironmentIdBuilder} A builder object that provides methods for modifying and constructing a `Id`.
|
|
1591
|
+
*
|
|
1592
|
+
* @throws {SyntaxError} Throws an error if the resulting `Id` is invalid when the `build` method is invoked.
|
|
1593
|
+
*/
|
|
1594
|
+
const getEnvironmentIdBuilder = () => {
|
|
1595
|
+
const internalState = { ...DEFAULT_ENVIRONMENT_ID };
|
|
1596
|
+
const builder = {
|
|
1597
|
+
withOwnerType: (ownerType) => {
|
|
1598
|
+
internalState.ownerType = ownerType;
|
|
1599
|
+
return builder;
|
|
1600
|
+
},
|
|
1601
|
+
withOwnerId: (ownerId) => {
|
|
1602
|
+
internalState.ownerId = ownerId;
|
|
1603
|
+
return builder;
|
|
1604
|
+
},
|
|
1605
|
+
withName: (name) => {
|
|
1606
|
+
internalState.name = name;
|
|
1607
|
+
return builder;
|
|
1608
|
+
},
|
|
1609
|
+
reset: () => {
|
|
1610
|
+
internalState.ownerType = DEFAULT_ENVIRONMENT_ID.ownerType;
|
|
1611
|
+
internalState.ownerId = DEFAULT_ENVIRONMENT_ID.ownerId;
|
|
1612
|
+
internalState.name = DEFAULT_ENVIRONMENT_ID.name;
|
|
1613
|
+
return builder;
|
|
1614
|
+
},
|
|
1615
|
+
build: () => {
|
|
1616
|
+
const validationErrors = isValidEnvironmentId(internalState);
|
|
1617
|
+
if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
|
|
1618
|
+
const builtId = {
|
|
1619
|
+
...internalState,
|
|
1620
|
+
equals: (other) => equals(builtId, other),
|
|
1621
|
+
toString: () => environmentIdToString(builtId)
|
|
1622
|
+
};
|
|
1623
|
+
return builtId;
|
|
1624
|
+
}
|
|
1625
|
+
};
|
|
1626
|
+
return builder;
|
|
1627
|
+
};
|
|
1628
|
+
|
|
1629
|
+
//#endregion
|
|
1630
|
+
//#region src/environment/entity.ts
|
|
1631
|
+
const DEFAULT_ENVIRONMENT = {
|
|
1632
|
+
id: DEFAULT_ENVIRONMENT_ID,
|
|
1633
|
+
parameters: getParametersInstance()
|
|
1634
|
+
};
|
|
1635
|
+
const isValidEnvironment = (environment) => addContextToErrors$1(environment.id, isValidEnvironmentId(environment.id));
|
|
1636
|
+
const addContextToErrors$1 = (environmentId, errors) => {
|
|
1637
|
+
return errors.map((error) => `[Environment: ${environmentId.toString()}]${error}`);
|
|
1638
|
+
};
|
|
1639
|
+
const getEnvironmentBuilder = () => {
|
|
1640
|
+
const internalState = { ...DEFAULT_ENVIRONMENT };
|
|
1641
|
+
const builder = {
|
|
1642
|
+
withId: (id) => {
|
|
1643
|
+
internalState.id = id;
|
|
1644
|
+
return builder;
|
|
1645
|
+
},
|
|
1646
|
+
withParameters: (parameters) => {
|
|
1647
|
+
internalState.parameters = parameters;
|
|
1648
|
+
return builder;
|
|
1649
|
+
},
|
|
1650
|
+
reset: () => {
|
|
1651
|
+
internalState.id = DEFAULT_ENVIRONMENT.id;
|
|
1652
|
+
internalState.parameters = DEFAULT_ENVIRONMENT.parameters;
|
|
1653
|
+
return builder;
|
|
1654
|
+
},
|
|
1655
|
+
build: () => {
|
|
1656
|
+
const validationErrors = isValidEnvironment(internalState);
|
|
1657
|
+
if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
|
|
1658
|
+
return { ...internalState };
|
|
1659
|
+
}
|
|
1660
|
+
};
|
|
1661
|
+
return builder;
|
|
1662
|
+
};
|
|
1663
|
+
|
|
1664
|
+
//#endregion
|
|
1665
|
+
//#region src/environment/index.ts
|
|
1666
|
+
let Environment$1;
|
|
1667
|
+
(function(_Environment) {
|
|
1668
|
+
let Id;
|
|
1669
|
+
(function(_Id) {
|
|
1670
|
+
_Id.getBuilder = getEnvironmentIdBuilder;
|
|
1671
|
+
})(Id || (Id = _Environment.Id || (_Environment.Id = {})));
|
|
1672
|
+
_Environment.getBuilder = getEnvironmentBuilder;
|
|
1673
|
+
})(Environment$1 || (Environment$1 = {}));
|
|
1674
|
+
|
|
1675
|
+
//#endregion
|
|
1676
|
+
//#region src/live_system/id.ts
|
|
1677
|
+
const toString = (id) => `${id.boundedContextId.toString()}/${id.name.value}`;
|
|
1678
|
+
/**
|
|
1679
|
+
* Validates the specified LiveSystemId and returns a list of error messages.
|
|
1680
|
+
*
|
|
1681
|
+
* The validation process includes checking the validity of the bounded context ID
|
|
1682
|
+
* and the name associated with the LiveSystemId.
|
|
1683
|
+
*
|
|
1684
|
+
* @param {LiveSystemId} id - The LiveSystemId object to be validated. It contains
|
|
1685
|
+
* a bounded context ID and a name in kebab-case format.
|
|
1686
|
+
* @returns {string[]} An array of error messages generated during validation. Each error message
|
|
1687
|
+
* is prepended with the string representation of the provided LiveSystemId for context.
|
|
1688
|
+
*/
|
|
1689
|
+
const isValidLiveSystemId = (id) => {
|
|
1690
|
+
const boundedContextIdErrors = isValidBoundedContextId(id.boundedContextId);
|
|
1691
|
+
const nameErrors = isValidKebabCaseString(id.name.value);
|
|
1692
|
+
return [...boundedContextIdErrors.map((x) => `[Live System Id: ${id.toString()}] Bounded Context Id error: ${x}`), ...nameErrors.map((x) => `[Live System Id: ${id.toString()}] Name errors: ${x}`)];
|
|
1693
|
+
};
|
|
1694
|
+
/**
|
|
1695
|
+
* Represents the default identifier for a live system within a bounded context.
|
|
1696
|
+
*
|
|
1697
|
+
* This constant is used to define the default configuration for a live system by associating a
|
|
1698
|
+
* predefined bounded context identifier with a default name in kebab-case format.
|
|
1699
|
+
*
|
|
1700
|
+
* Fields:
|
|
1701
|
+
* - `boundedContextId`: Identifies the default bounded context to which the live system belongs.
|
|
1702
|
+
* - `name`: Specifies the default name of the live system in a standardized kebab-case string format.
|
|
1703
|
+
*/
|
|
1704
|
+
const DEFAULT_LIVE_SYSTEM_ID = {
|
|
1705
|
+
boundedContextId: DEFAULT_BOUNDED_CONTEXT_ID,
|
|
1706
|
+
name: DEFAULT_KEBAB_CASE_STRING
|
|
1707
|
+
};
|
|
1708
|
+
/**
|
|
1709
|
+
* Creates and returns a `LiveSystemIdBuilder` to construct and validate `LiveSystemId` objects.
|
|
1710
|
+
*
|
|
1711
|
+
* The builder provides a fluent API for setting properties and validating the resulting `LiveSystemId`.
|
|
1712
|
+
*
|
|
1713
|
+
* @returns {LiveSystemIdBuilder} A builder object with methods to configure, reset, and build a `LiveSystemId`.
|
|
1714
|
+
*
|
|
1715
|
+
* Methods available in the builder:
|
|
1716
|
+
* - `withBoundedContextId(value: BoundedContext.Id)`: Sets the bounded context ID for the `LiveSystemId`.
|
|
1717
|
+
* - `withName(value: KebabCaseString)`: Sets the name for the `LiveSystemId`.
|
|
1718
|
+
* - `reset()`: Resets all properties to their default values as defined in `DEFAULT_LIVE_SYSTEM_ID`.
|
|
1719
|
+
* - `build()`: Validates the current state of the builder and constructs a `LiveSystemId` object. Throws a `SyntaxError` if validation fails.
|
|
1720
|
+
*/
|
|
1721
|
+
const getLiveSystemIdBuilder = () => {
|
|
1722
|
+
const internalState = { ...DEFAULT_LIVE_SYSTEM_ID };
|
|
1723
|
+
const builder = {
|
|
1724
|
+
withBoundedContextId: (value) => {
|
|
1725
|
+
internalState.boundedContextId = value;
|
|
1726
|
+
return builder;
|
|
1727
|
+
},
|
|
1728
|
+
withName: (value) => {
|
|
1729
|
+
internalState.name = value;
|
|
1730
|
+
return builder;
|
|
1731
|
+
},
|
|
1732
|
+
reset: () => {
|
|
1733
|
+
internalState.boundedContextId = DEFAULT_LIVE_SYSTEM_ID.boundedContextId;
|
|
1734
|
+
internalState.name = DEFAULT_LIVE_SYSTEM_ID.name;
|
|
1735
|
+
return builder;
|
|
1736
|
+
},
|
|
1737
|
+
build: () => {
|
|
1738
|
+
const validationErrors = isValidLiveSystemId(internalState);
|
|
1739
|
+
if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
|
|
1740
|
+
const builtId = {
|
|
1741
|
+
...internalState,
|
|
1742
|
+
toString: () => toString(builtId)
|
|
1743
|
+
};
|
|
1744
|
+
return builtId;
|
|
1745
|
+
}
|
|
1746
|
+
};
|
|
1747
|
+
return builder;
|
|
1748
|
+
};
|
|
1749
|
+
|
|
1750
|
+
//#endregion
|
|
1751
|
+
//#region src/live_system/component/entity.ts
|
|
1752
|
+
const DEFAULT_LIVE_SYSTEM_COMPONENT = {
|
|
1753
|
+
...DEFAULT_BLUEPRINT_COMPONENT,
|
|
1754
|
+
status: "Instantiating",
|
|
1755
|
+
lastUpdated: /* @__PURE__ */ new Date(0),
|
|
1756
|
+
lastOperationRetried: -1,
|
|
1757
|
+
provider: "Unknown",
|
|
1758
|
+
lastOperationStatusMessage: "",
|
|
1759
|
+
errorCode: ""
|
|
1760
|
+
};
|
|
1761
|
+
const isValidLiveSystemComponent = (component) => isValidBlueprintComponent(component);
|
|
1762
|
+
const getLiveSystemComponentBuilder = () => {
|
|
1763
|
+
const internalState = { ...DEFAULT_LIVE_SYSTEM_COMPONENT };
|
|
1764
|
+
const builder = {
|
|
1765
|
+
withType: (type) => {
|
|
1766
|
+
internalState.type = type;
|
|
1767
|
+
return builder;
|
|
1768
|
+
},
|
|
1769
|
+
withId: (id) => {
|
|
1770
|
+
internalState.id = id;
|
|
1771
|
+
return builder;
|
|
1772
|
+
},
|
|
1773
|
+
withVersion: (version) => {
|
|
1774
|
+
internalState.version = version;
|
|
1775
|
+
return builder;
|
|
1776
|
+
},
|
|
1777
|
+
withIsLocked: (value) => {
|
|
1778
|
+
internalState.isLocked = value;
|
|
1779
|
+
return builder;
|
|
1780
|
+
},
|
|
1781
|
+
withRecreateOnFailure: (value) => {
|
|
1782
|
+
internalState.recreateOnFailure = value;
|
|
1783
|
+
return builder;
|
|
1784
|
+
},
|
|
1785
|
+
withProvider: (value) => {
|
|
1786
|
+
internalState.provider = value;
|
|
1787
|
+
return builder;
|
|
1788
|
+
},
|
|
1789
|
+
withDisplayName: (displayName) => {
|
|
1790
|
+
internalState.displayName = displayName;
|
|
1791
|
+
return builder;
|
|
1792
|
+
},
|
|
1793
|
+
withDescription: (description) => {
|
|
1794
|
+
internalState.description = description;
|
|
1795
|
+
return builder;
|
|
1796
|
+
},
|
|
1797
|
+
withParameters: (parameters) => {
|
|
1798
|
+
internalState.parameters = parameters;
|
|
1799
|
+
return builder;
|
|
1800
|
+
},
|
|
1801
|
+
withLinks: (links) => {
|
|
1802
|
+
internalState.links = links;
|
|
1803
|
+
return builder;
|
|
1804
|
+
},
|
|
1805
|
+
withDependencies: (dependencies) => {
|
|
1806
|
+
internalState.dependencies = dependencies;
|
|
1807
|
+
return builder;
|
|
1808
|
+
},
|
|
1809
|
+
reset: () => {
|
|
1810
|
+
internalState.type = DEFAULT_LIVE_SYSTEM_COMPONENT.type;
|
|
1811
|
+
internalState.id = DEFAULT_LIVE_SYSTEM_COMPONENT.id;
|
|
1812
|
+
internalState.version = DEFAULT_LIVE_SYSTEM_COMPONENT.version;
|
|
1813
|
+
internalState.displayName = DEFAULT_LIVE_SYSTEM_COMPONENT.displayName;
|
|
1814
|
+
internalState.description = DEFAULT_LIVE_SYSTEM_COMPONENT.description;
|
|
1815
|
+
internalState.parameters = DEFAULT_LIVE_SYSTEM_COMPONENT.parameters;
|
|
1816
|
+
internalState.links = DEFAULT_LIVE_SYSTEM_COMPONENT.links;
|
|
1817
|
+
internalState.dependencies = DEFAULT_LIVE_SYSTEM_COMPONENT.dependencies;
|
|
1818
|
+
internalState.isLocked = DEFAULT_LIVE_SYSTEM_COMPONENT.isLocked;
|
|
1819
|
+
internalState.provider = DEFAULT_LIVE_SYSTEM_COMPONENT.provider;
|
|
1820
|
+
internalState.recreateOnFailure = DEFAULT_LIVE_SYSTEM_COMPONENT.recreateOnFailure;
|
|
1821
|
+
return builder;
|
|
1822
|
+
},
|
|
1823
|
+
build: () => {
|
|
1824
|
+
const validationErrors = isValidLiveSystemComponent(internalState);
|
|
1825
|
+
if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
|
|
1826
|
+
return { ...internalState };
|
|
1827
|
+
}
|
|
1828
|
+
};
|
|
1829
|
+
return builder;
|
|
1830
|
+
};
|
|
1831
|
+
|
|
1832
|
+
//#endregion
|
|
1833
|
+
//#region src/live_system/service.ts
|
|
1834
|
+
const CLIENT_ID_HEADER = "X-ClientID";
|
|
1835
|
+
const CLIENT_SECRET_HEADER = "X-ClientSecret";
|
|
1836
|
+
const FRACTAL_API_URL = "https://api.fractal.cloud";
|
|
1837
|
+
const deployLiveSystem = async (credentials, liveSystem) => {
|
|
1838
|
+
const body = {
|
|
1839
|
+
liveSystemId: liveSystem.id.toString(),
|
|
1840
|
+
fractalId: liveSystem.fractalId.toString(),
|
|
1841
|
+
description: liveSystem.description,
|
|
1842
|
+
provider: liveSystem.genericProvider,
|
|
1843
|
+
blueprintMap: liveSystem.components.reduce((acc, c) => {
|
|
1844
|
+
acc[c.id.value.toString()] = {
|
|
1845
|
+
...c,
|
|
1846
|
+
type: c.type.toString(),
|
|
1847
|
+
id: c.id.value.toString(),
|
|
1848
|
+
version: c.version.toString(),
|
|
1849
|
+
parameters: c.parameters.toMap(),
|
|
1850
|
+
dependencies: c.dependencies.map((d) => d.id.value.toString()),
|
|
1851
|
+
links: c.links.map((l) => ({
|
|
1852
|
+
componentId: l.id.value.toString(),
|
|
1853
|
+
settings: l.parameters.toMap()
|
|
1854
|
+
})),
|
|
1855
|
+
outputFields: c.outputFields.value
|
|
1856
|
+
};
|
|
1857
|
+
return acc;
|
|
1858
|
+
}, {}),
|
|
1859
|
+
parameters: liveSystem.parameters.toMap(),
|
|
1860
|
+
environment: {
|
|
1861
|
+
id: {
|
|
1862
|
+
type: liveSystem.environment.id.ownerType,
|
|
1863
|
+
ownerId: liveSystem.environment.id.ownerId.toString(),
|
|
1864
|
+
shortName: liveSystem.environment.id.name.toString()
|
|
1865
|
+
},
|
|
1866
|
+
parameters: liveSystem.environment.parameters.toMap()
|
|
1867
|
+
}
|
|
1868
|
+
};
|
|
1869
|
+
const liveSystemUrl = `${FRACTAL_API_URL}/livesystems/${liveSystem.id.toString()}`;
|
|
1870
|
+
((await superagent.default.get(liveSystemUrl).set(CLIENT_ID_HEADER, credentials.id.serviceAccountIdValue).set(CLIENT_SECRET_HEADER, credentials.secret).send()).status === 200 ? superagent.default.put(liveSystemUrl) : superagent.default.post(`${FRACTAL_API_URL}/livesystems`)).set(CLIENT_ID_HEADER, credentials.id.serviceAccountIdValue).set(CLIENT_SECRET_HEADER, credentials.secret).send(body).catch((e) => console.error(e.message, e.response.text));
|
|
1871
|
+
};
|
|
1872
|
+
const destroyLiveSystem = async (credentials, id) => {
|
|
1873
|
+
await superagent.default.delete(`${FRACTAL_API_URL}/livesystems/${id.toString()}`).set(CLIENT_ID_HEADER, credentials.id.serviceAccountIdValue).set(CLIENT_SECRET_HEADER, credentials.secret);
|
|
1874
|
+
};
|
|
1875
|
+
let LiveSystemService;
|
|
1876
|
+
(function(_LiveSystemService) {
|
|
1877
|
+
_LiveSystemService.deploy = deployLiveSystem;
|
|
1878
|
+
_LiveSystemService.destroy = destroyLiveSystem;
|
|
1879
|
+
})(LiveSystemService || (LiveSystemService = {}));
|
|
1880
|
+
|
|
1881
|
+
//#endregion
|
|
1882
|
+
//#region src/live_system/entity.ts
|
|
1883
|
+
const DEFAULT_LIVE_SYSTEM = {
|
|
1884
|
+
id: DEFAULT_LIVE_SYSTEM_ID,
|
|
1885
|
+
requesterId: "",
|
|
1886
|
+
fractalId: DEFAULT_FRACTAL_ID,
|
|
1887
|
+
description: "",
|
|
1888
|
+
status: "Unknown",
|
|
1889
|
+
statusMessage: "",
|
|
1890
|
+
components: [],
|
|
1891
|
+
genericProvider: "Unknown",
|
|
1892
|
+
parameters: getParametersInstance(),
|
|
1893
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
1894
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
1895
|
+
environment: DEFAULT_ENVIRONMENT,
|
|
1896
|
+
deploy: () => Promise.reject(),
|
|
1897
|
+
destroy: () => Promise.reject()
|
|
1898
|
+
};
|
|
1899
|
+
/**
|
|
1900
|
+
* Validates a given live system and returns a list of error messages if any validation fails.
|
|
1901
|
+
*
|
|
1902
|
+
* This function verifies the following:
|
|
1903
|
+
* - The `id` of the live system is valid.
|
|
1904
|
+
* - The `fractalId` of the live system is valid.
|
|
1905
|
+
* - The `components` field is not empty and all its components pass validation.
|
|
1906
|
+
*
|
|
1907
|
+
* @param {LiveSystem} liveSystem - The live system object to be validated.
|
|
1908
|
+
* @returns {string[]} An array of error messages. If validation passes, this array will be empty.
|
|
1909
|
+
*/
|
|
1910
|
+
const isValidLiveSystem = (liveSystem) => {
|
|
1911
|
+
const idErrors = addContextToErrors(liveSystem.id, isValidLiveSystemId(liveSystem.id));
|
|
1912
|
+
const fractalIdErrors = addContextToErrors(liveSystem.id, isValidFractalId(liveSystem.fractalId));
|
|
1913
|
+
const environmentErrors = addContextToErrors(liveSystem.id, isValidEnvironment(liveSystem.environment));
|
|
1914
|
+
const componentsErrors = addContextToErrors(liveSystem.id, !liveSystem.components || liveSystem.components.length === 0 ? ["[Components] Components must not be empty"] : liveSystem.components.reduce((acc, x) => {
|
|
1915
|
+
acc.push(...isValidLiveSystemComponent(x));
|
|
1916
|
+
return acc;
|
|
1917
|
+
}, []));
|
|
1918
|
+
return [
|
|
1919
|
+
...idErrors,
|
|
1920
|
+
...fractalIdErrors,
|
|
1921
|
+
...componentsErrors,
|
|
1922
|
+
...environmentErrors
|
|
1923
|
+
];
|
|
1924
|
+
};
|
|
1925
|
+
const addContextToErrors = (liveSystemId, errors) => {
|
|
1926
|
+
return errors.map((error) => `[Live System: ${liveSystemId.toString()}]${error}`);
|
|
1927
|
+
};
|
|
1928
|
+
/**
|
|
1929
|
+
* Creates and returns a builder for constructing LiveSystem objects.
|
|
1930
|
+
* The builder allows the user to configure various properties of a LiveSystem
|
|
1931
|
+
* instance through a fluent API.
|
|
1932
|
+
*
|
|
1933
|
+
* @returns {LiveSystemBuilder} An object providing methods to configure and build a LiveSystem instance.
|
|
1934
|
+
*
|
|
1935
|
+
* @description
|
|
1936
|
+
* The `getLiveSystemBuilder` function initializes a builder object for constructing LiveSystem instances.
|
|
1937
|
+
* The builder maintains an internal state that gets updated through its methods. When the `build` method
|
|
1938
|
+
* is invoked, the internal state is validated and returned as a fully formed LiveSystem object.
|
|
1939
|
+
*
|
|
1940
|
+
* The builder provides the following configuration methods:
|
|
1941
|
+
* - `withId(value: LiveSystemId)`: Sets the `id` property of the LiveSystem.
|
|
1942
|
+
* - `withDescription(value: string)`: Sets the `description` property of the LiveSystem.
|
|
1943
|
+
* - `withFractalId(value: Fractal.Id)`: Sets the `fractalId` property of the LiveSystem.
|
|
1944
|
+
* - `withComponents(value: LiveSystemComponent[])`: Adds an array of components to the LiveSystem.
|
|
1945
|
+
* - `withComponent(value: LiveSystemComponent)`: Adds a single component to the LiveSystem.
|
|
1946
|
+
* - `withGenericProvider(value: LiveSystemComponent.Provider)`: Sets the `genericProvider` property of the LiveSystem.
|
|
1947
|
+
* - `withParameters(parameters: ComponentParameters): Assigns the provided `parameters` to the `LiveSystem`.
|
|
1948
|
+
*
|
|
1949
|
+
* Additional builder methods:
|
|
1950
|
+
* - `reset()`: Resets the internal state to the default LiveSystem configuration.
|
|
1951
|
+
* - `build()`: Validates the internal state and returns a LiveSystem instance. If validation fails, an error is thrown.
|
|
1952
|
+
*
|
|
1953
|
+
* Validation:
|
|
1954
|
+
* The `build` method performs validation on the internal state using the `isValidLiveSystem` function. If validation
|
|
1955
|
+
* errors are detected, a `SyntaxError` is thrown containing the list of errors.
|
|
1956
|
+
*
|
|
1957
|
+
* Lifecycle Operations:
|
|
1958
|
+
* The constructed LiveSystem object includes the `deploy` and `destroy` methods:
|
|
1959
|
+
* - `deploy(credentials)`: Deploys the LiveSystem using the given credentials.
|
|
1960
|
+
* - `destroy(credentials)`: Destroys the LiveSystem using the given credentials and its `id`.
|
|
1961
|
+
*/
|
|
1962
|
+
const getLiveSystemBuilder = () => {
|
|
1963
|
+
const internalState = { ...DEFAULT_LIVE_SYSTEM };
|
|
1964
|
+
const builder = {
|
|
1965
|
+
withId: (value) => {
|
|
1966
|
+
internalState.id = value;
|
|
1967
|
+
return builder;
|
|
1968
|
+
},
|
|
1969
|
+
withFractalId: (value) => {
|
|
1970
|
+
internalState.fractalId = value;
|
|
1971
|
+
return builder;
|
|
1972
|
+
},
|
|
1973
|
+
withDescription: (value) => {
|
|
1974
|
+
internalState.description = value;
|
|
1975
|
+
return builder;
|
|
1976
|
+
},
|
|
1977
|
+
withComponents: (value) => {
|
|
1978
|
+
if (!internalState.components) internalState.components = [];
|
|
1979
|
+
internalState.components.push(...value);
|
|
1980
|
+
return builder;
|
|
1981
|
+
},
|
|
1982
|
+
withComponent: (value) => {
|
|
1983
|
+
if (!internalState.components) internalState.components = [];
|
|
1984
|
+
internalState.components.push(value);
|
|
1985
|
+
return builder;
|
|
1986
|
+
},
|
|
1987
|
+
withGenericProvider: (value) => {
|
|
1988
|
+
internalState.genericProvider = value;
|
|
1989
|
+
return builder;
|
|
1990
|
+
},
|
|
1991
|
+
withParameters: (parameters) => {
|
|
1992
|
+
internalState.parameters = parameters;
|
|
1993
|
+
return builder;
|
|
1994
|
+
},
|
|
1995
|
+
withEnvironment: (environment) => {
|
|
1996
|
+
internalState.environment = environment;
|
|
1997
|
+
return builder;
|
|
1998
|
+
},
|
|
1999
|
+
reset: () => {
|
|
2000
|
+
internalState.id = DEFAULT_LIVE_SYSTEM.id;
|
|
2001
|
+
internalState.requesterId = DEFAULT_LIVE_SYSTEM.requesterId;
|
|
2002
|
+
internalState.fractalId = DEFAULT_LIVE_SYSTEM.fractalId;
|
|
2003
|
+
internalState.description = DEFAULT_LIVE_SYSTEM.description;
|
|
2004
|
+
internalState.status = DEFAULT_LIVE_SYSTEM.status;
|
|
2005
|
+
internalState.statusMessage = DEFAULT_LIVE_SYSTEM.statusMessage;
|
|
2006
|
+
internalState.components = DEFAULT_LIVE_SYSTEM.components;
|
|
2007
|
+
internalState.genericProvider = DEFAULT_LIVE_SYSTEM.genericProvider;
|
|
2008
|
+
internalState.environment = DEFAULT_LIVE_SYSTEM.environment;
|
|
2009
|
+
internalState.createdAt = DEFAULT_LIVE_SYSTEM.createdAt;
|
|
2010
|
+
internalState.updatedAt = DEFAULT_LIVE_SYSTEM.updatedAt;
|
|
2011
|
+
return builder;
|
|
2012
|
+
},
|
|
2013
|
+
build: () => {
|
|
2014
|
+
const validationErrors = isValidLiveSystem(internalState);
|
|
2015
|
+
if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
|
|
2016
|
+
return {
|
|
2017
|
+
...internalState,
|
|
2018
|
+
deploy: (credentials) => LiveSystemService.deploy(credentials, internalState),
|
|
2019
|
+
destroy: (credentials) => LiveSystemService.destroy(credentials, internalState.id)
|
|
2020
|
+
};
|
|
2021
|
+
}
|
|
2022
|
+
};
|
|
2023
|
+
return builder;
|
|
2024
|
+
};
|
|
2025
|
+
|
|
2026
|
+
//#endregion
|
|
2027
|
+
//#region src/live_system/index.ts
|
|
2028
|
+
let LiveSystem$1;
|
|
2029
|
+
(function(_LiveSystem) {
|
|
2030
|
+
let Id;
|
|
2031
|
+
(function(_Id) {
|
|
2032
|
+
_Id.getBuilder = getLiveSystemIdBuilder;
|
|
2033
|
+
})(Id || (Id = _LiveSystem.Id || (_LiveSystem.Id = {})));
|
|
2034
|
+
let Component;
|
|
2035
|
+
(function(_Component) {
|
|
2036
|
+
_Component.getBuilder = getLiveSystemComponentBuilder;
|
|
2037
|
+
})(Component || (Component = _LiveSystem.Component || (_LiveSystem.Component = {})));
|
|
2038
|
+
_LiveSystem.getBuilder = getLiveSystemBuilder;
|
|
2039
|
+
})(LiveSystem$1 || (LiveSystem$1 = {}));
|
|
2040
|
+
|
|
1468
2041
|
//#endregion
|
|
1469
2042
|
//#region src/index.ts
|
|
1470
2043
|
const BoundedContext = BoundedContext$1;
|
|
@@ -1478,12 +2051,16 @@ const ServiceAccountCredentials = ServiceAccountCredentials$1;
|
|
|
1478
2051
|
const ServiceAccountId = ServiceAccountId$1;
|
|
1479
2052
|
const ServiceDeliveryModel = ServiceDeliveryModel$1;
|
|
1480
2053
|
const Version = Version$1;
|
|
2054
|
+
const Environment = Environment$1;
|
|
2055
|
+
const LiveSystem = LiveSystem$1;
|
|
1481
2056
|
|
|
1482
2057
|
//#endregion
|
|
1483
2058
|
exports.BoundedContext = BoundedContext;
|
|
2059
|
+
exports.Environment = Environment;
|
|
1484
2060
|
exports.Fractal = Fractal;
|
|
1485
2061
|
exports.InfrastructureDomain = InfrastructureDomain;
|
|
1486
2062
|
exports.KebabCaseString = KebabCaseString;
|
|
2063
|
+
exports.LiveSystem = LiveSystem;
|
|
1487
2064
|
exports.OwnerId = OwnerId;
|
|
1488
2065
|
exports.OwnerType = OwnerType;
|
|
1489
2066
|
exports.PascalCaseString = PascalCaseString;
|