@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/dist/index.mjs CHANGED
@@ -12,7 +12,12 @@ import superagent from "superagent";
12
12
  *
13
13
  * @type {KebabCaseString}
14
14
  */
15
- const DEFAULT_KEBAB_CASE_STRING = { kebabValue: "" };
15
+ const DEFAULT_KEBAB_CASE_STRING = {
16
+ _type: "kebab",
17
+ value: "",
18
+ equals: () => false,
19
+ toString: () => ""
20
+ };
16
21
  /**
17
22
  * Validates whether a given string follows the kebab-case format.
18
23
  *
@@ -26,7 +31,7 @@ const DEFAULT_KEBAB_CASE_STRING = { kebabValue: "" };
26
31
  * @returns {string[]} - An empty array if the string is valid, otherwise an array containing an error message.
27
32
  */
28
33
  const isValidKebabCaseString = (value) => {
29
- if (!/^[a-z][a-z0-9]*(-[a-z][a-z0-9]*)*$/.test(value)) return ["Value must be in kebab-case"];
34
+ if (!/^[a-z][a-z0-9]*(-[a-z][a-z0-9]*)*$/.test(value)) return [` Value '${value}' must be in kebab-case`];
30
35
  return [];
31
36
  };
32
37
  /**
@@ -43,17 +48,21 @@ const getKebabCaseStringBuilder = () => {
43
48
  const internalState = { ...DEFAULT_KEBAB_CASE_STRING };
44
49
  const builder = {
45
50
  withValue: (value) => {
46
- internalState.kebabValue = value;
51
+ internalState.value = value;
47
52
  return builder;
48
53
  },
49
54
  reset: () => {
50
- internalState.kebabValue = DEFAULT_KEBAB_CASE_STRING.kebabValue;
55
+ internalState.value = DEFAULT_KEBAB_CASE_STRING.value;
51
56
  return builder;
52
57
  },
53
58
  build: () => {
54
- const validationErrors = isValidKebabCaseString(internalState.kebabValue);
59
+ const validationErrors = isValidKebabCaseString(internalState.value);
55
60
  if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
56
- return { ...internalState };
61
+ return {
62
+ ...internalState,
63
+ equals: (other) => internalState.value === other.value,
64
+ toString: () => internalState.value
65
+ };
57
66
  }
58
67
  };
59
68
  return builder;
@@ -65,8 +74,8 @@ let KebabCaseString$1;
65
74
 
66
75
  //#endregion
67
76
  //#region src/values/version.ts
68
- const equals$2 = (a, b) => a.major === b.major && a.minor === b.minor && a.patch === b.patch;
69
- const toString$1 = (version) => `v${version.major}.${version.minor}.${version.patch}`;
77
+ const equals$4 = (a, b) => a.major === b.major && a.minor === b.minor && a.patch === b.patch;
78
+ const toString$2 = (version) => `v${version.major}.${version.minor}.${version.patch}`;
70
79
  /**
71
80
  * Represents the default version for an application or library.
72
81
  *
@@ -77,7 +86,7 @@ const DEFAULT_VERSION = {
77
86
  major: 0,
78
87
  minor: 0,
79
88
  patch: 0,
80
- equals: (other) => equals$2(DEFAULT_VERSION, other)
89
+ equals: (other) => equals$4(DEFAULT_VERSION, other)
81
90
  };
82
91
  /**
83
92
  * Validates if the provided version object is properly initialized or equivalent to the default version.
@@ -87,7 +96,7 @@ const DEFAULT_VERSION = {
87
96
  * an array containing one error message. Otherwise, it returns an empty array.
88
97
  */
89
98
  const isValidVersion = (version) => {
90
- if (equals$2(version, DEFAULT_VERSION)) return ["Version must be initialized"];
99
+ if (equals$4(version, DEFAULT_VERSION)) return [" Version must be initialized"];
91
100
  return [];
92
101
  };
93
102
  /**
@@ -144,8 +153,8 @@ const getVersionBuilder = () => {
144
153
  if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
145
154
  const builtVersion = {
146
155
  ...internalState,
147
- equals: (other) => equals$2(builtVersion, other),
148
- toString: () => toString$1(builtVersion)
156
+ equals: (other) => equals$4(builtVersion, other),
157
+ toString: () => toString$2(builtVersion)
149
158
  };
150
159
  return builtVersion;
151
160
  }
@@ -179,7 +188,7 @@ let OwnerType$1 = /* @__PURE__ */ function(OwnerType) {
179
188
  //#endregion
180
189
  //#region src/values/guid.ts
181
190
  const isValidUuid = (value) => {
182
- 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`];
191
+ 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`];
183
192
  return [];
184
193
  };
185
194
 
@@ -191,7 +200,11 @@ const isValidUuid = (value) => {
191
200
  * This variable is declared as a constant to prevent modification
192
201
  * and is designed to not pass validation checks.
193
202
  */
194
- const DEFAULT_OWNER_ID = { ownerIdValue: "" };
203
+ const DEFAULT_OWNER_ID = {
204
+ _type: "ownerId",
205
+ value: "",
206
+ toString: () => ""
207
+ };
195
208
  /**
196
209
  * Validates whether the given string value is a valid UUID.
197
210
  *
@@ -203,8 +216,11 @@ const DEFAULT_OWNER_ID = { ownerIdValue: "" };
203
216
  * @returns {string[]} An array containing error messages if invalid, or an empty array if valid.
204
217
  */
205
218
  const isValidOwnerId = (value) => {
206
- if (!value || !value.ownerIdValue) return ["Value must be a non-empty string"];
207
- return isValidUuid(value.ownerIdValue);
219
+ if (!value || !value.value) return ["[Owner Id] Value must be a non-empty string"];
220
+ return addContextToErrors$8(value, isValidUuid(value.value));
221
+ };
222
+ const addContextToErrors$8 = (value, errors) => {
223
+ return errors.map((error) => `[Owner Id: ${value.toString()}]${error}`);
208
224
  };
209
225
  /**
210
226
  * Creates a builder for constructing a OwnerId object. The builder enforces uuid case formatting and ensures
@@ -220,17 +236,20 @@ const getOwnerIdBuilder = () => {
220
236
  const internalState = { ...DEFAULT_OWNER_ID };
221
237
  const builder = {
222
238
  withValue: (value) => {
223
- internalState.ownerIdValue = value;
239
+ internalState.value = value;
224
240
  return builder;
225
241
  },
226
242
  reset: () => {
227
- internalState.ownerIdValue = DEFAULT_OWNER_ID.ownerIdValue;
243
+ internalState.value = DEFAULT_OWNER_ID.value;
228
244
  return builder;
229
245
  },
230
246
  build: () => {
231
247
  const validationErrors = isValidOwnerId(internalState);
232
248
  if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
233
- return { ...internalState };
249
+ return {
250
+ ...internalState,
251
+ toString: () => internalState.value
252
+ };
234
253
  }
235
254
  };
236
255
  return builder;
@@ -242,17 +261,18 @@ let OwnerId$1;
242
261
 
243
262
  //#endregion
244
263
  //#region src/bounded_context/id.ts
245
- const equals$1 = (a, b) => a.ownerType === b.ownerType && a.ownerId.ownerIdValue === b.ownerId.ownerIdValue && a.name.kebabValue === b.name.kebabValue;
264
+ const equals$3 = (a, b) => a.ownerType === b.ownerType && a.ownerId.value === b.ownerId.value && a.name.value === b.name.value;
246
265
  /**
247
266
  * A default value for the bounded context identifier used in the system.
248
267
  * It contains values that will not pass validation checks.
249
268
  */
250
269
  const DEFAULT_BOUNDED_CONTEXT_ID = {
270
+ _type: "bounded_context",
251
271
  ownerType: OwnerType$1.Personal,
252
272
  ownerId: DEFAULT_OWNER_ID,
253
273
  name: DEFAULT_KEBAB_CASE_STRING,
254
- equals: (other) => equals$1(DEFAULT_BOUNDED_CONTEXT_ID, other),
255
- toString: () => boundedContextIdToString(DEFAULT_BOUNDED_CONTEXT_ID)
274
+ equals: () => false,
275
+ toString: () => ""
256
276
  };
257
277
  /**
258
278
  * Determines whether the given value is a valid Id.
@@ -267,11 +287,14 @@ const DEFAULT_BOUNDED_CONTEXT_ID = {
267
287
  * the `isValidKebabCaseString` function.
268
288
  */
269
289
  const isValidBoundedContextId = (value) => {
270
- const ownerIdErrors = isValidOwnerId(value.ownerId);
271
- const nameErrors = isValidKebabCaseString(value.name.kebabValue);
272
- return [...ownerIdErrors.map((x) => `[Bounded Context Id: ${boundedContextIdToString(value)}] Owner Id error: ${x}`), ...nameErrors.map((x) => `[Bounded Context Id: ${boundedContextIdToString(value)}] Name error: ${x}`)];
290
+ const ownerIdErrors = addContextToErrors$7(value, isValidOwnerId(value.ownerId));
291
+ const nameErrors = addContextToErrors$7(value, isValidKebabCaseString(value.name.value));
292
+ return [...ownerIdErrors, ...nameErrors];
273
293
  };
274
- const boundedContextIdToString = (id) => `${id.ownerType.toString()}/${id.ownerId.ownerIdValue}/${id.name.kebabValue}`;
294
+ const addContextToErrors$7 = (bcId, errors) => {
295
+ return errors.map((error) => `[Bounded Context Id: ${bcId.toString()}]${error}`);
296
+ };
297
+ const boundedContextIdToString = (id) => `${id.ownerType.toString()}/${id.ownerId.value}/${id.name.value}`;
275
298
  /**
276
299
  * Creates and returns a builder for constructing a `Id` object.
277
300
  *
@@ -309,7 +332,7 @@ const getBoundedContextIdBuilder = () => {
309
332
  if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
310
333
  const builtId = {
311
334
  ...internalState,
312
- equals: (other) => equals$1(builtId, other),
335
+ equals: (other) => equals$3(builtId, other),
313
336
  toString: () => boundedContextIdToString(builtId)
314
337
  };
315
338
  return builtId;
@@ -320,7 +343,8 @@ const getBoundedContextIdBuilder = () => {
320
343
 
321
344
  //#endregion
322
345
  //#region src/fractal/id.ts
323
- const toString = (id) => `${id.boundedContextId.toString()}/${id.name.kebabValue}:${id.version.toString()}`;
346
+ const equals$2 = (a, b) => a.boundedContextId.equals(b.boundedContextId) && a.name.equals(b.name) && a.version.equals(b.version);
347
+ const toString$1 = (id) => `${id.boundedContextId.toString()}/${id.name.toString()}:${id.version.toString()}`;
324
348
  /**
325
349
  * Validates a given Fractal ID and returns a list of error messages if any validation fails.
326
350
  * The validation process includes checking the bounded context ID, the name, and the version of the Fractal ID.
@@ -329,15 +353,18 @@ const toString = (id) => `${id.boundedContextId.toString()}/${id.name.kebabValue
329
353
  * @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.
330
354
  */
331
355
  const isValidFractalId = (id) => {
332
- const boundedContextIdErrors = isValidBoundedContextId(id.boundedContextId);
333
- const nameErrors = isValidKebabCaseString(id.name.kebabValue);
334
- const versionErrors = isValidVersion(id.version);
356
+ const boundedContextIdErrors = addContextToErrors$6(id, isValidBoundedContextId(id.boundedContextId));
357
+ const nameErrors = addContextToErrors$6(id, isValidKebabCaseString(id.name.value));
358
+ const versionErrors = addContextToErrors$6(id, isValidVersion(id.version));
335
359
  return [
336
- ...boundedContextIdErrors.map((x) => `[Fractal Id: ${id.toString()}] Bounded Context Id error: ${x}`),
337
- ...nameErrors.map((x) => `[Fractal Id: ${id.toString()}] Name errors: ${x}`),
338
- ...versionErrors.map((x) => `[Fractal Id: ${id.toString()}] Version error: ${x}`)
360
+ ...boundedContextIdErrors,
361
+ ...nameErrors,
362
+ ...versionErrors
339
363
  ];
340
364
  };
365
+ const addContextToErrors$6 = (value, errors) => {
366
+ return errors.map((error) => `[Fractal Id: ${toString$1(value)}]${error}`);
367
+ };
341
368
  /**
342
369
  * Represents the default identifier for a fractal instance.
343
370
  *
@@ -357,7 +384,9 @@ const isValidFractalId = (id) => {
357
384
  const DEFAULT_FRACTAL_ID = {
358
385
  boundedContextId: DEFAULT_BOUNDED_CONTEXT_ID,
359
386
  name: DEFAULT_KEBAB_CASE_STRING,
360
- version: DEFAULT_VERSION
387
+ version: DEFAULT_VERSION,
388
+ equals: () => false,
389
+ toString: () => ""
361
390
  };
362
391
  /**
363
392
  * Provides a builder for constructing a `FractalId` object.
@@ -400,7 +429,8 @@ const getFractalIdBuilder = () => {
400
429
  if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
401
430
  const builtId = {
402
431
  ...internalState,
403
- toString: () => toString(builtId)
432
+ equals: (other) => equals$2(builtId, other),
433
+ toString: () => toString$1(builtId)
404
434
  };
405
435
  return builtId;
406
436
  }
@@ -443,7 +473,7 @@ let ServiceDeliveryModel$1 = /* @__PURE__ */ function(ServiceDeliveryModel) {
443
473
  * if the string is valid.
444
474
  */
445
475
  const isValidPascalCaseString = (value) => {
446
- if (!/^[A-Z][a-zA-Z]*$/.test(value)) return [`Value '${value}' must be in PascalCase`];
476
+ if (!/^[A-Z][a-zA-Z]*$/.test(value)) return [` Value '${value}' must be in PascalCase`];
447
477
  return [];
448
478
  };
449
479
  /**
@@ -452,7 +482,12 @@ const isValidPascalCaseString = (value) => {
452
482
  * This variable is declared as a constant to prevent modification
453
483
  * and is designed to not pass validation checks.
454
484
  */
455
- const DEFAULT_PASCAL_CASE_STRING = { pascalValue: "" };
485
+ const DEFAULT_PASCAL_CASE_STRING = {
486
+ _type: "pascal",
487
+ value: "",
488
+ equals: () => false,
489
+ toString: () => ""
490
+ };
456
491
  /**
457
492
  * Creates a builder for constructing a PascalCaseString object. The builder enforces Pascal case formatting and ensures
458
493
  * a valid string is set before building. Once built, the PascalCaseString object becomes immutable.
@@ -467,17 +502,21 @@ const getPascalCaseStringBuilder = () => {
467
502
  const internalState = { ...DEFAULT_PASCAL_CASE_STRING };
468
503
  const builder = {
469
504
  withValue: (value) => {
470
- internalState.pascalValue = value;
505
+ internalState.value = value;
471
506
  return builder;
472
507
  },
473
508
  reset: () => {
474
- internalState.pascalValue = DEFAULT_PASCAL_CASE_STRING.pascalValue;
509
+ internalState.value = DEFAULT_PASCAL_CASE_STRING.value;
475
510
  return builder;
476
511
  },
477
512
  build: () => {
478
- const validationErrors = isValidPascalCaseString(internalState.pascalValue);
513
+ const validationErrors = isValidPascalCaseString(internalState.value);
479
514
  if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
480
- return { ...internalState };
515
+ return {
516
+ ...internalState,
517
+ equals: (other) => internalState.value === other.value,
518
+ toString: () => internalState.value
519
+ };
481
520
  }
482
521
  };
483
522
  return builder;
@@ -537,8 +576,8 @@ const DEFAULT_COMPONENT_TYPE = {
537
576
  * @returns {string[]} An array of error messages if validation fails; an empty array if the name is valid.
538
577
  */
539
578
  const isValidComponentType = (type) => {
540
- const nameError = isValidPascalCaseString(type.name.pascalValue);
541
- if (nameError.length > 0) return nameError.map((x) => `[Component Type: ${type.name.pascalValue}] Name error: ${x}`);
579
+ const nameError = isValidPascalCaseString(type.name.value);
580
+ if (nameError.length > 0) return nameError.map((x) => `[Component Type: ${type.name.value}][Name]${x}`);
542
581
  return [];
543
582
  };
544
583
  /**
@@ -651,7 +690,10 @@ const getBlueprintComponentTypeBuilder = () => {
651
690
  build: () => {
652
691
  const validationErrors = isValidBlueprintComponentType(internalState);
653
692
  if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
654
- return { ...internalState };
693
+ return {
694
+ ...internalState,
695
+ toString: () => `${internalState.domain}.${internalState.serviceDeliveryModel}.${internalState.name}`
696
+ };
655
697
  }
656
698
  };
657
699
  return builder;
@@ -693,16 +735,17 @@ const getParametersInstance = () => {
693
735
  * @returns {boolean} - Returns true if the identifier is in a valid kebab-case format, false otherwise.
694
736
  */
695
737
  const isValidId = (id) => {
696
- return isValidKebabCaseString(id.value.kebabValue).map((x) => `[Component Id: ${id.value.kebabValue}] Id error: ${x}`);
738
+ return isValidKebabCaseString(id.value.toString()).map((x) => `[Component Id: ${id.value.toString()}]${x}`);
697
739
  };
698
- const equals = (a, b) => a.value === b.value;
740
+ const equals$1 = (a, b) => a.value === b.value;
699
741
  /**
700
742
  * Represents the default identifier used in the application.
701
743
  * It is initialized with a value that will not pass validation.
702
744
  */
703
745
  const DEFAULT_COMPONENT_ID = {
704
746
  value: DEFAULT_KEBAB_CASE_STRING,
705
- equals: (other) => equals(DEFAULT_COMPONENT_ID, other)
747
+ equals: (other) => equals$1(DEFAULT_COMPONENT_ID, other),
748
+ toString: () => ""
706
749
  };
707
750
  /**
708
751
  * Creates and returns a builder for constructing a `ComponentId` object.
@@ -730,7 +773,8 @@ const getComponentIdBuilder = () => {
730
773
  if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
731
774
  const builtId = {
732
775
  ...internalState,
733
- equals: (other) => equals(builtId, other)
776
+ equals: (other) => equals$1(builtId, other),
777
+ toString: () => builtId.value.toString()
734
778
  };
735
779
  return builtId;
736
780
  }
@@ -856,18 +900,21 @@ const DEFAULT_COMPONENT = {
856
900
  * @returns {string[]} An array of error messages, each describing a specific validation failure. If no errors are found, the array will be empty.
857
901
  */
858
902
  const isValidComponent = (component) => {
859
- const idErrors = isValidId(component.id);
860
- const typeErrors = isValidComponentType(component.type);
861
- const versionErrors = isValidVersion(component.version);
862
- const displayNameErrors = isNonEmptyString(component.displayName) ? [] : ["Display name must be a non-empty string"];
903
+ const idErrors = addContextToErrors$5(component.id, isValidId(component.id));
904
+ const typeErrors = addContextToErrors$5(component.id, isValidComponentType(component.type));
905
+ const versionErrors = addContextToErrors$5(component.id, isValidVersion(component.version));
906
+ const displayNameErrors = addContextToErrors$5(component.id, isNonEmptyString(component.displayName) ? [] : ["Display name must be a non-empty string"]);
863
907
  return [
864
- ...idErrors.map((x) => `[Component: ${component.id.value}] Id error: ${x}`),
865
- ...typeErrors.map((x) => `[Component: ${component.id.value}] Type error: ${x}`),
866
- ...versionErrors.map((x) => `[Component: ${component.id.value}] Version error: ${x}`),
867
- ...typeErrors.map((x) => `[Component: ${component.id.value}] Type error: ${x}`),
868
- ...displayNameErrors.map((x) => `[Component: ${component.id.value}] Display Name error: ${x}`)
908
+ ...idErrors,
909
+ ...typeErrors,
910
+ ...versionErrors,
911
+ ...typeErrors,
912
+ ...displayNameErrors
869
913
  ];
870
914
  };
915
+ const addContextToErrors$5 = (componentId, errors) => {
916
+ return errors.map((error) => `[Component: ${componentId.toString()}]${error}`);
917
+ };
871
918
  /**
872
919
  * Creates and returns a builder for constructing `Component` objects.
873
920
  *
@@ -1005,7 +1052,7 @@ const isValidBlueprintComponent = (component) => {
1005
1052
  * - `withVersion(version: Version)`: Sets the version of the component.
1006
1053
  * - `withDisplayName(displayName: string)`: Sets the display name for the component.
1007
1054
  * - `withDescription(description: string)`: Sets a description for the component.
1008
- * - `withParameters(parameters: GenericParameters)`: Sets the parameters associated with the component.
1055
+ * - `withParameters(parameters: Component.Parameters)`: Sets the parameters associated with the component.
1009
1056
  * - `withLinks(links: ComponentLink[])`: Sets the links associated with the component.
1010
1057
  * - `withDependencies(dependencies: BlueprintComponentDependency[])`: Sets the dependencies of the component.
1011
1058
  * - `reset()`: Resets all properties of the component to their default values based on `DEFAULT_BLUEPRINT_COMPONENT`.
@@ -1093,22 +1140,23 @@ let BlueprintComponent;
1093
1140
 
1094
1141
  //#endregion
1095
1142
  //#region src/fractal/service.ts
1096
- const CLIENT_ID_HEADER = "X-ClientID";
1097
- const CLIENT_SECRET_HEADER = "X-ClientSecret";
1098
- const FRACTAL_API_URL = "https://api.fractal.cloud";
1143
+ const CLIENT_ID_HEADER$1 = "X-ClientID";
1144
+ const CLIENT_SECRET_HEADER$1 = "X-ClientSecret";
1145
+ const FRACTAL_API_URL$1 = "https://api.fractal.cloud";
1099
1146
  const deployFractal = async (credentials, fractal) => {
1100
- await superagent.post(`${FRACTAL_API_URL}/blueprints/${fractal.id.toString().replace(":", "/")}`).set(CLIENT_ID_HEADER, credentials.id.serviceAccountIdValue).set(CLIENT_SECRET_HEADER, credentials.secret).send({
1147
+ const fractalUrl = `${FRACTAL_API_URL$1}/blueprints/${fractal.id.toString().replace(":", "/")}`;
1148
+ ((await superagent.get(fractalUrl).set(CLIENT_ID_HEADER$1, credentials.id.serviceAccountIdValue).set(CLIENT_SECRET_HEADER$1, credentials.secret).send()).status === 200 ? superagent.put(fractalUrl) : superagent.post(fractalUrl)).set(CLIENT_ID_HEADER$1, credentials.id.serviceAccountIdValue).set(CLIENT_SECRET_HEADER$1, credentials.secret).send({
1101
1149
  description: fractal.description,
1102
1150
  isPrivate: fractal.isPrivate,
1103
1151
  components: fractal.components.map((c) => ({
1104
1152
  ...c,
1105
1153
  type: c.type.toString(),
1106
- id: c.id.value.kebabValue,
1154
+ id: c.id.value.toString(),
1107
1155
  version: c.version.toString(),
1108
1156
  parameters: c.parameters.toMap(),
1109
- dependencies: c.dependencies.map((d) => d.id.value.kebabValue),
1157
+ dependencies: c.dependencies.map((d) => d.id.value.toString()),
1110
1158
  links: c.links.map((l) => ({
1111
- componentId: l.id.value.kebabValue,
1159
+ componentId: l.id.value.toString(),
1112
1160
  settings: l.parameters.toMap()
1113
1161
  })),
1114
1162
  outputFields: Object.keys(c.outputFields.value)
@@ -1116,7 +1164,7 @@ const deployFractal = async (credentials, fractal) => {
1116
1164
  }).catch((e) => console.error(e.message, e.response.text));
1117
1165
  };
1118
1166
  const destroyFractal = async (credentials, id) => {
1119
- await superagent.delete(`${FRACTAL_API_URL}/blueprints/${id.toString().replace(":", "/")}`).set(CLIENT_ID_HEADER, credentials.id.serviceAccountIdValue).set(CLIENT_SECRET_HEADER, credentials.secret);
1167
+ await superagent.delete(`${FRACTAL_API_URL$1}/blueprints/${id.toString().replace(":", "/")}`).set(CLIENT_ID_HEADER$1, credentials.id.serviceAccountIdValue).set(CLIENT_SECRET_HEADER$1, credentials.secret);
1120
1168
  };
1121
1169
  let FractalService;
1122
1170
  (function(_FractalService) {
@@ -1163,13 +1211,36 @@ const DEFAULT_FRACTAL = {
1163
1211
  * @returns {string[]} An array of error messages describing any validation issues with the fractal.
1164
1212
  */
1165
1213
  const isValidFractal = (fractal) => {
1166
- const idErrors = isValidFractalId(fractal.id);
1167
- const componentsErrors = !fractal.components || fractal.components.length === 0 ? [`[Fractal: ${fractal.id.toString()}]: components must not be empty`] : fractal.components.reduce((acc, x) => {
1214
+ const idErrors = addContextToErrors$4(fractal.id, isValidFractalId(fractal.id));
1215
+ const componentsErrors = addContextToErrors$4(fractal.id, !fractal.components || fractal.components.length === 0 ? ["[Components] Components must not be empty"] : fractal.components.reduce((acc, x) => {
1168
1216
  acc.push(...isValidBlueprintComponent(x));
1169
1217
  return acc;
1170
- }, []);
1218
+ }, []));
1171
1219
  return [...idErrors, ...componentsErrors];
1172
1220
  };
1221
+ const addContextToErrors$4 = (value, errors) => {
1222
+ return errors.map((error) => `[Fractal: ${value.toString()}]${error}`);
1223
+ };
1224
+ /**
1225
+ * Creates and returns a builder object for constructing Fractal objects.
1226
+ *
1227
+ * This builder provides a fluent interface for setting various properties of a Fractal
1228
+ * and includes methods for validation, resetting to defaults, and final construction.
1229
+ *
1230
+ * @returns {FractalBuilder} A builder object for incrementally building a Fractal.
1231
+ *
1232
+ * The builder object supports the following methods:
1233
+ * - `withId(value: FractalId): FractalBuilder` - Sets the ID of the Fractal.
1234
+ * - `withIsPrivate(value: boolean): FractalBuilder` - Sets the privacy status of the Fractal.
1235
+ * - `withDescription(value: string): FractalBuilder` - Sets the description of the Fractal.
1236
+ * - `withComponents(value: BlueprintComponent[]): FractalBuilder` - Appends a list of components to the Fractal.
1237
+ * - `withComponent(value: BlueprintComponent): FractalBuilder` - Appends a single component to the Fractal.
1238
+ * - `reset(): FractalBuilder` - Resets the builder’s state to the default Fractal properties.
1239
+ * - `build(): Fractal` - Validates and constructs a Fractal object.
1240
+ *
1241
+ * Throws:
1242
+ * - `SyntaxError` - If the constructed Fractal object is invalid during the build process.
1243
+ */
1173
1244
  const getFractalBuilder = () => {
1174
1245
  const internalState = { ...DEFAULT_FRACTAL };
1175
1246
  const builder = {
@@ -1255,9 +1326,12 @@ const DEFAULT = {
1255
1326
  * @returns {boolean} Returns true if the bounded context is valid; otherwise, returns false.
1256
1327
  */
1257
1328
  const isValidBoundedContext = (value) => {
1258
- const idErrors = isValidBoundedContextId(value.id);
1259
- const displayNameErrors = isNonEmptyString(value.displayName) ? [] : ["Display name must be a non-empty string"];
1260
- return [...idErrors.map((x) => `[Bounded Context: ${value.id.toString()}] Id error: ${x}`), ...displayNameErrors.map((x) => `[Bounded Context: ${value.id.toString()}] Display Name error: ${x}`)];
1329
+ const idErrors = addContextToErrors$3(value.id, isValidBoundedContextId(value.id));
1330
+ const displayNameErrors = addContextToErrors$3(value.id, isNonEmptyString(value.displayName) ? [] : ["Display name must be a non-empty string"]);
1331
+ return [...idErrors, ...displayNameErrors];
1332
+ };
1333
+ const addContextToErrors$3 = (bcId, errors) => {
1334
+ return errors.map((error) => `[Bounded Context: ${bcId.toString()}]${error}`);
1261
1335
  };
1262
1336
  /**
1263
1337
  * Creates a builder for constructing a BoundedContext object with a fluid API.
@@ -1436,6 +1510,505 @@ let ServiceAccountCredentials$1;
1436
1510
  _ServiceAccountCredentials.getBuilder = getServiceAccountCredentialsBuilder;
1437
1511
  })(ServiceAccountCredentials$1 || (ServiceAccountCredentials$1 = {}));
1438
1512
 
1513
+ //#endregion
1514
+ //#region src/environment/id.ts
1515
+ const equals = (a, b) => a.ownerType === b.ownerType && a.ownerId.value === b.ownerId.value && a.name.value === b.name.value;
1516
+ /**
1517
+ * Represents the default environment identifier used within the system.
1518
+ * The variable holds a constant, immutable object reflecting the default
1519
+ * properties and metadata of an environment.
1520
+ *
1521
+ * Properties:
1522
+ * - `ownerType`: An enumeration value specifying the type of owner (e.g., personal).
1523
+ * - `ownerId`: A constant value representing the default owner identifier.
1524
+ * - `name`: A default kebab-case formatted string for the environment name.
1525
+ * - `equals`: A function that always returns `false`, used to compare equality with another environment.
1526
+ * - `toString`: A function returning an empty string representation of the environment.
1527
+ *
1528
+ * The object is defined as `const` to ensure its immutability and integrity throughout its usage.
1529
+ */
1530
+ const DEFAULT_ENVIRONMENT_ID = {
1531
+ _type: "environment",
1532
+ ownerType: OwnerType$1.Personal,
1533
+ ownerId: DEFAULT_OWNER_ID,
1534
+ name: DEFAULT_KEBAB_CASE_STRING,
1535
+ equals: () => false,
1536
+ toString: () => ""
1537
+ };
1538
+ /**
1539
+ * Validates whether the given environment ID is valid by checking its owner ID and name.
1540
+ *
1541
+ * @param {EnvironmentId} value - The environment ID to validate, which consists of an owner ID and a name.
1542
+ * @returns {string[]} An array of error messages, where each message describes a specific validation failure
1543
+ * for either the owner ID or the name. If no errors are present, the array is empty.
1544
+ */
1545
+ const isValidEnvironmentId = (value) => {
1546
+ const ownerIdErrors = addContextToErrors$2(value, isValidOwnerId(value.ownerId));
1547
+ const nameErrors = addContextToErrors$2(value, isValidKebabCaseString(value.name.toString()));
1548
+ return [...ownerIdErrors, ...nameErrors];
1549
+ };
1550
+ const addContextToErrors$2 = (value, errors) => {
1551
+ return errors.map((error) => `[Environment Id: ${environmentIdToString(value)}]${error}`);
1552
+ };
1553
+ const environmentIdToString = (id) => `${id.ownerType.toString()}/${id.ownerId.value}/${id.name.value}`;
1554
+ /**
1555
+ * Creates and returns a builder for constructing a `Id` object.
1556
+ *
1557
+ * The builder allows customization of the `Id` properties such as `ownerType`,
1558
+ * while also enforcing constraints during the construction process, ensuring the resulting object is valid.
1559
+ * The builder is stateful and provides a method to reset to default values if needed.
1560
+ *
1561
+ * @returns {EnvironmentIdBuilder} A builder object that provides methods for modifying and constructing a `Id`.
1562
+ *
1563
+ * @throws {SyntaxError} Throws an error if the resulting `Id` is invalid when the `build` method is invoked.
1564
+ */
1565
+ const getEnvironmentIdBuilder = () => {
1566
+ const internalState = { ...DEFAULT_ENVIRONMENT_ID };
1567
+ const builder = {
1568
+ withOwnerType: (ownerType) => {
1569
+ internalState.ownerType = ownerType;
1570
+ return builder;
1571
+ },
1572
+ withOwnerId: (ownerId) => {
1573
+ internalState.ownerId = ownerId;
1574
+ return builder;
1575
+ },
1576
+ withName: (name) => {
1577
+ internalState.name = name;
1578
+ return builder;
1579
+ },
1580
+ reset: () => {
1581
+ internalState.ownerType = DEFAULT_ENVIRONMENT_ID.ownerType;
1582
+ internalState.ownerId = DEFAULT_ENVIRONMENT_ID.ownerId;
1583
+ internalState.name = DEFAULT_ENVIRONMENT_ID.name;
1584
+ return builder;
1585
+ },
1586
+ build: () => {
1587
+ const validationErrors = isValidEnvironmentId(internalState);
1588
+ if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
1589
+ const builtId = {
1590
+ ...internalState,
1591
+ equals: (other) => equals(builtId, other),
1592
+ toString: () => environmentIdToString(builtId)
1593
+ };
1594
+ return builtId;
1595
+ }
1596
+ };
1597
+ return builder;
1598
+ };
1599
+
1600
+ //#endregion
1601
+ //#region src/environment/entity.ts
1602
+ const DEFAULT_ENVIRONMENT = {
1603
+ id: DEFAULT_ENVIRONMENT_ID,
1604
+ parameters: getParametersInstance()
1605
+ };
1606
+ const isValidEnvironment = (environment) => addContextToErrors$1(environment.id, isValidEnvironmentId(environment.id));
1607
+ const addContextToErrors$1 = (environmentId, errors) => {
1608
+ return errors.map((error) => `[Environment: ${environmentId.toString()}]${error}`);
1609
+ };
1610
+ const getEnvironmentBuilder = () => {
1611
+ const internalState = { ...DEFAULT_ENVIRONMENT };
1612
+ const builder = {
1613
+ withId: (id) => {
1614
+ internalState.id = id;
1615
+ return builder;
1616
+ },
1617
+ withParameters: (parameters) => {
1618
+ internalState.parameters = parameters;
1619
+ return builder;
1620
+ },
1621
+ reset: () => {
1622
+ internalState.id = DEFAULT_ENVIRONMENT.id;
1623
+ internalState.parameters = DEFAULT_ENVIRONMENT.parameters;
1624
+ return builder;
1625
+ },
1626
+ build: () => {
1627
+ const validationErrors = isValidEnvironment(internalState);
1628
+ if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
1629
+ return { ...internalState };
1630
+ }
1631
+ };
1632
+ return builder;
1633
+ };
1634
+
1635
+ //#endregion
1636
+ //#region src/environment/index.ts
1637
+ let Environment$1;
1638
+ (function(_Environment) {
1639
+ let Id;
1640
+ (function(_Id) {
1641
+ _Id.getBuilder = getEnvironmentIdBuilder;
1642
+ })(Id || (Id = _Environment.Id || (_Environment.Id = {})));
1643
+ _Environment.getBuilder = getEnvironmentBuilder;
1644
+ })(Environment$1 || (Environment$1 = {}));
1645
+
1646
+ //#endregion
1647
+ //#region src/live_system/id.ts
1648
+ const toString = (id) => `${id.boundedContextId.toString()}/${id.name.value}`;
1649
+ /**
1650
+ * Validates the specified LiveSystemId and returns a list of error messages.
1651
+ *
1652
+ * The validation process includes checking the validity of the bounded context ID
1653
+ * and the name associated with the LiveSystemId.
1654
+ *
1655
+ * @param {LiveSystemId} id - The LiveSystemId object to be validated. It contains
1656
+ * a bounded context ID and a name in kebab-case format.
1657
+ * @returns {string[]} An array of error messages generated during validation. Each error message
1658
+ * is prepended with the string representation of the provided LiveSystemId for context.
1659
+ */
1660
+ const isValidLiveSystemId = (id) => {
1661
+ const boundedContextIdErrors = isValidBoundedContextId(id.boundedContextId);
1662
+ const nameErrors = isValidKebabCaseString(id.name.value);
1663
+ 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}`)];
1664
+ };
1665
+ /**
1666
+ * Represents the default identifier for a live system within a bounded context.
1667
+ *
1668
+ * This constant is used to define the default configuration for a live system by associating a
1669
+ * predefined bounded context identifier with a default name in kebab-case format.
1670
+ *
1671
+ * Fields:
1672
+ * - `boundedContextId`: Identifies the default bounded context to which the live system belongs.
1673
+ * - `name`: Specifies the default name of the live system in a standardized kebab-case string format.
1674
+ */
1675
+ const DEFAULT_LIVE_SYSTEM_ID = {
1676
+ boundedContextId: DEFAULT_BOUNDED_CONTEXT_ID,
1677
+ name: DEFAULT_KEBAB_CASE_STRING
1678
+ };
1679
+ /**
1680
+ * Creates and returns a `LiveSystemIdBuilder` to construct and validate `LiveSystemId` objects.
1681
+ *
1682
+ * The builder provides a fluent API for setting properties and validating the resulting `LiveSystemId`.
1683
+ *
1684
+ * @returns {LiveSystemIdBuilder} A builder object with methods to configure, reset, and build a `LiveSystemId`.
1685
+ *
1686
+ * Methods available in the builder:
1687
+ * - `withBoundedContextId(value: BoundedContext.Id)`: Sets the bounded context ID for the `LiveSystemId`.
1688
+ * - `withName(value: KebabCaseString)`: Sets the name for the `LiveSystemId`.
1689
+ * - `reset()`: Resets all properties to their default values as defined in `DEFAULT_LIVE_SYSTEM_ID`.
1690
+ * - `build()`: Validates the current state of the builder and constructs a `LiveSystemId` object. Throws a `SyntaxError` if validation fails.
1691
+ */
1692
+ const getLiveSystemIdBuilder = () => {
1693
+ const internalState = { ...DEFAULT_LIVE_SYSTEM_ID };
1694
+ const builder = {
1695
+ withBoundedContextId: (value) => {
1696
+ internalState.boundedContextId = value;
1697
+ return builder;
1698
+ },
1699
+ withName: (value) => {
1700
+ internalState.name = value;
1701
+ return builder;
1702
+ },
1703
+ reset: () => {
1704
+ internalState.boundedContextId = DEFAULT_LIVE_SYSTEM_ID.boundedContextId;
1705
+ internalState.name = DEFAULT_LIVE_SYSTEM_ID.name;
1706
+ return builder;
1707
+ },
1708
+ build: () => {
1709
+ const validationErrors = isValidLiveSystemId(internalState);
1710
+ if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
1711
+ const builtId = {
1712
+ ...internalState,
1713
+ toString: () => toString(builtId)
1714
+ };
1715
+ return builtId;
1716
+ }
1717
+ };
1718
+ return builder;
1719
+ };
1720
+
1721
+ //#endregion
1722
+ //#region src/live_system/component/entity.ts
1723
+ const DEFAULT_LIVE_SYSTEM_COMPONENT = {
1724
+ ...DEFAULT_BLUEPRINT_COMPONENT,
1725
+ status: "Instantiating",
1726
+ lastUpdated: /* @__PURE__ */ new Date(0),
1727
+ lastOperationRetried: -1,
1728
+ provider: "Unknown",
1729
+ lastOperationStatusMessage: "",
1730
+ errorCode: ""
1731
+ };
1732
+ const isValidLiveSystemComponent = (component) => isValidBlueprintComponent(component);
1733
+ const getLiveSystemComponentBuilder = () => {
1734
+ const internalState = { ...DEFAULT_LIVE_SYSTEM_COMPONENT };
1735
+ const builder = {
1736
+ withType: (type) => {
1737
+ internalState.type = type;
1738
+ return builder;
1739
+ },
1740
+ withId: (id) => {
1741
+ internalState.id = id;
1742
+ return builder;
1743
+ },
1744
+ withVersion: (version) => {
1745
+ internalState.version = version;
1746
+ return builder;
1747
+ },
1748
+ withIsLocked: (value) => {
1749
+ internalState.isLocked = value;
1750
+ return builder;
1751
+ },
1752
+ withRecreateOnFailure: (value) => {
1753
+ internalState.recreateOnFailure = value;
1754
+ return builder;
1755
+ },
1756
+ withProvider: (value) => {
1757
+ internalState.provider = value;
1758
+ return builder;
1759
+ },
1760
+ withDisplayName: (displayName) => {
1761
+ internalState.displayName = displayName;
1762
+ return builder;
1763
+ },
1764
+ withDescription: (description) => {
1765
+ internalState.description = description;
1766
+ return builder;
1767
+ },
1768
+ withParameters: (parameters) => {
1769
+ internalState.parameters = parameters;
1770
+ return builder;
1771
+ },
1772
+ withLinks: (links) => {
1773
+ internalState.links = links;
1774
+ return builder;
1775
+ },
1776
+ withDependencies: (dependencies) => {
1777
+ internalState.dependencies = dependencies;
1778
+ return builder;
1779
+ },
1780
+ reset: () => {
1781
+ internalState.type = DEFAULT_LIVE_SYSTEM_COMPONENT.type;
1782
+ internalState.id = DEFAULT_LIVE_SYSTEM_COMPONENT.id;
1783
+ internalState.version = DEFAULT_LIVE_SYSTEM_COMPONENT.version;
1784
+ internalState.displayName = DEFAULT_LIVE_SYSTEM_COMPONENT.displayName;
1785
+ internalState.description = DEFAULT_LIVE_SYSTEM_COMPONENT.description;
1786
+ internalState.parameters = DEFAULT_LIVE_SYSTEM_COMPONENT.parameters;
1787
+ internalState.links = DEFAULT_LIVE_SYSTEM_COMPONENT.links;
1788
+ internalState.dependencies = DEFAULT_LIVE_SYSTEM_COMPONENT.dependencies;
1789
+ internalState.isLocked = DEFAULT_LIVE_SYSTEM_COMPONENT.isLocked;
1790
+ internalState.provider = DEFAULT_LIVE_SYSTEM_COMPONENT.provider;
1791
+ internalState.recreateOnFailure = DEFAULT_LIVE_SYSTEM_COMPONENT.recreateOnFailure;
1792
+ return builder;
1793
+ },
1794
+ build: () => {
1795
+ const validationErrors = isValidLiveSystemComponent(internalState);
1796
+ if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
1797
+ return { ...internalState };
1798
+ }
1799
+ };
1800
+ return builder;
1801
+ };
1802
+
1803
+ //#endregion
1804
+ //#region src/live_system/service.ts
1805
+ const CLIENT_ID_HEADER = "X-ClientID";
1806
+ const CLIENT_SECRET_HEADER = "X-ClientSecret";
1807
+ const FRACTAL_API_URL = "https://api.fractal.cloud";
1808
+ const deployLiveSystem = async (credentials, liveSystem) => {
1809
+ const body = {
1810
+ liveSystemId: liveSystem.id.toString(),
1811
+ fractalId: liveSystem.fractalId.toString(),
1812
+ description: liveSystem.description,
1813
+ provider: liveSystem.genericProvider,
1814
+ blueprintMap: liveSystem.components.reduce((acc, c) => {
1815
+ acc[c.id.value.toString()] = {
1816
+ ...c,
1817
+ type: c.type.toString(),
1818
+ id: c.id.value.toString(),
1819
+ version: c.version.toString(),
1820
+ parameters: c.parameters.toMap(),
1821
+ dependencies: c.dependencies.map((d) => d.id.value.toString()),
1822
+ links: c.links.map((l) => ({
1823
+ componentId: l.id.value.toString(),
1824
+ settings: l.parameters.toMap()
1825
+ })),
1826
+ outputFields: c.outputFields.value
1827
+ };
1828
+ return acc;
1829
+ }, {}),
1830
+ parameters: liveSystem.parameters.toMap(),
1831
+ environment: {
1832
+ id: {
1833
+ type: liveSystem.environment.id.ownerType,
1834
+ ownerId: liveSystem.environment.id.ownerId.toString(),
1835
+ shortName: liveSystem.environment.id.name.toString()
1836
+ },
1837
+ parameters: liveSystem.environment.parameters.toMap()
1838
+ }
1839
+ };
1840
+ const liveSystemUrl = `${FRACTAL_API_URL}/livesystems/${liveSystem.id.toString()}`;
1841
+ ((await superagent.get(liveSystemUrl).set(CLIENT_ID_HEADER, credentials.id.serviceAccountIdValue).set(CLIENT_SECRET_HEADER, credentials.secret).send()).status === 200 ? superagent.put(liveSystemUrl) : superagent.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));
1842
+ };
1843
+ const destroyLiveSystem = async (credentials, id) => {
1844
+ await superagent.delete(`${FRACTAL_API_URL}/livesystems/${id.toString()}`).set(CLIENT_ID_HEADER, credentials.id.serviceAccountIdValue).set(CLIENT_SECRET_HEADER, credentials.secret);
1845
+ };
1846
+ let LiveSystemService;
1847
+ (function(_LiveSystemService) {
1848
+ _LiveSystemService.deploy = deployLiveSystem;
1849
+ _LiveSystemService.destroy = destroyLiveSystem;
1850
+ })(LiveSystemService || (LiveSystemService = {}));
1851
+
1852
+ //#endregion
1853
+ //#region src/live_system/entity.ts
1854
+ const DEFAULT_LIVE_SYSTEM = {
1855
+ id: DEFAULT_LIVE_SYSTEM_ID,
1856
+ requesterId: "",
1857
+ fractalId: DEFAULT_FRACTAL_ID,
1858
+ description: "",
1859
+ status: "Unknown",
1860
+ statusMessage: "",
1861
+ components: [],
1862
+ genericProvider: "Unknown",
1863
+ parameters: getParametersInstance(),
1864
+ createdAt: /* @__PURE__ */ new Date(),
1865
+ updatedAt: /* @__PURE__ */ new Date(),
1866
+ environment: DEFAULT_ENVIRONMENT,
1867
+ deploy: () => Promise.reject(),
1868
+ destroy: () => Promise.reject()
1869
+ };
1870
+ /**
1871
+ * Validates a given live system and returns a list of error messages if any validation fails.
1872
+ *
1873
+ * This function verifies the following:
1874
+ * - The `id` of the live system is valid.
1875
+ * - The `fractalId` of the live system is valid.
1876
+ * - The `components` field is not empty and all its components pass validation.
1877
+ *
1878
+ * @param {LiveSystem} liveSystem - The live system object to be validated.
1879
+ * @returns {string[]} An array of error messages. If validation passes, this array will be empty.
1880
+ */
1881
+ const isValidLiveSystem = (liveSystem) => {
1882
+ const idErrors = addContextToErrors(liveSystem.id, isValidLiveSystemId(liveSystem.id));
1883
+ const fractalIdErrors = addContextToErrors(liveSystem.id, isValidFractalId(liveSystem.fractalId));
1884
+ const environmentErrors = addContextToErrors(liveSystem.id, isValidEnvironment(liveSystem.environment));
1885
+ const componentsErrors = addContextToErrors(liveSystem.id, !liveSystem.components || liveSystem.components.length === 0 ? ["[Components] Components must not be empty"] : liveSystem.components.reduce((acc, x) => {
1886
+ acc.push(...isValidLiveSystemComponent(x));
1887
+ return acc;
1888
+ }, []));
1889
+ return [
1890
+ ...idErrors,
1891
+ ...fractalIdErrors,
1892
+ ...componentsErrors,
1893
+ ...environmentErrors
1894
+ ];
1895
+ };
1896
+ const addContextToErrors = (liveSystemId, errors) => {
1897
+ return errors.map((error) => `[Live System: ${liveSystemId.toString()}]${error}`);
1898
+ };
1899
+ /**
1900
+ * Creates and returns a builder for constructing LiveSystem objects.
1901
+ * The builder allows the user to configure various properties of a LiveSystem
1902
+ * instance through a fluent API.
1903
+ *
1904
+ * @returns {LiveSystemBuilder} An object providing methods to configure and build a LiveSystem instance.
1905
+ *
1906
+ * @description
1907
+ * The `getLiveSystemBuilder` function initializes a builder object for constructing LiveSystem instances.
1908
+ * The builder maintains an internal state that gets updated through its methods. When the `build` method
1909
+ * is invoked, the internal state is validated and returned as a fully formed LiveSystem object.
1910
+ *
1911
+ * The builder provides the following configuration methods:
1912
+ * - `withId(value: LiveSystemId)`: Sets the `id` property of the LiveSystem.
1913
+ * - `withDescription(value: string)`: Sets the `description` property of the LiveSystem.
1914
+ * - `withFractalId(value: Fractal.Id)`: Sets the `fractalId` property of the LiveSystem.
1915
+ * - `withComponents(value: LiveSystemComponent[])`: Adds an array of components to the LiveSystem.
1916
+ * - `withComponent(value: LiveSystemComponent)`: Adds a single component to the LiveSystem.
1917
+ * - `withGenericProvider(value: LiveSystemComponent.Provider)`: Sets the `genericProvider` property of the LiveSystem.
1918
+ * - `withParameters(parameters: ComponentParameters): Assigns the provided `parameters` to the `LiveSystem`.
1919
+ *
1920
+ * Additional builder methods:
1921
+ * - `reset()`: Resets the internal state to the default LiveSystem configuration.
1922
+ * - `build()`: Validates the internal state and returns a LiveSystem instance. If validation fails, an error is thrown.
1923
+ *
1924
+ * Validation:
1925
+ * The `build` method performs validation on the internal state using the `isValidLiveSystem` function. If validation
1926
+ * errors are detected, a `SyntaxError` is thrown containing the list of errors.
1927
+ *
1928
+ * Lifecycle Operations:
1929
+ * The constructed LiveSystem object includes the `deploy` and `destroy` methods:
1930
+ * - `deploy(credentials)`: Deploys the LiveSystem using the given credentials.
1931
+ * - `destroy(credentials)`: Destroys the LiveSystem using the given credentials and its `id`.
1932
+ */
1933
+ const getLiveSystemBuilder = () => {
1934
+ const internalState = { ...DEFAULT_LIVE_SYSTEM };
1935
+ const builder = {
1936
+ withId: (value) => {
1937
+ internalState.id = value;
1938
+ return builder;
1939
+ },
1940
+ withFractalId: (value) => {
1941
+ internalState.fractalId = value;
1942
+ return builder;
1943
+ },
1944
+ withDescription: (value) => {
1945
+ internalState.description = value;
1946
+ return builder;
1947
+ },
1948
+ withComponents: (value) => {
1949
+ if (!internalState.components) internalState.components = [];
1950
+ internalState.components.push(...value);
1951
+ return builder;
1952
+ },
1953
+ withComponent: (value) => {
1954
+ if (!internalState.components) internalState.components = [];
1955
+ internalState.components.push(value);
1956
+ return builder;
1957
+ },
1958
+ withGenericProvider: (value) => {
1959
+ internalState.genericProvider = value;
1960
+ return builder;
1961
+ },
1962
+ withParameters: (parameters) => {
1963
+ internalState.parameters = parameters;
1964
+ return builder;
1965
+ },
1966
+ withEnvironment: (environment) => {
1967
+ internalState.environment = environment;
1968
+ return builder;
1969
+ },
1970
+ reset: () => {
1971
+ internalState.id = DEFAULT_LIVE_SYSTEM.id;
1972
+ internalState.requesterId = DEFAULT_LIVE_SYSTEM.requesterId;
1973
+ internalState.fractalId = DEFAULT_LIVE_SYSTEM.fractalId;
1974
+ internalState.description = DEFAULT_LIVE_SYSTEM.description;
1975
+ internalState.status = DEFAULT_LIVE_SYSTEM.status;
1976
+ internalState.statusMessage = DEFAULT_LIVE_SYSTEM.statusMessage;
1977
+ internalState.components = DEFAULT_LIVE_SYSTEM.components;
1978
+ internalState.genericProvider = DEFAULT_LIVE_SYSTEM.genericProvider;
1979
+ internalState.environment = DEFAULT_LIVE_SYSTEM.environment;
1980
+ internalState.createdAt = DEFAULT_LIVE_SYSTEM.createdAt;
1981
+ internalState.updatedAt = DEFAULT_LIVE_SYSTEM.updatedAt;
1982
+ return builder;
1983
+ },
1984
+ build: () => {
1985
+ const validationErrors = isValidLiveSystem(internalState);
1986
+ if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
1987
+ return {
1988
+ ...internalState,
1989
+ deploy: (credentials) => LiveSystemService.deploy(credentials, internalState),
1990
+ destroy: (credentials) => LiveSystemService.destroy(credentials, internalState.id)
1991
+ };
1992
+ }
1993
+ };
1994
+ return builder;
1995
+ };
1996
+
1997
+ //#endregion
1998
+ //#region src/live_system/index.ts
1999
+ let LiveSystem$1;
2000
+ (function(_LiveSystem) {
2001
+ let Id;
2002
+ (function(_Id) {
2003
+ _Id.getBuilder = getLiveSystemIdBuilder;
2004
+ })(Id || (Id = _LiveSystem.Id || (_LiveSystem.Id = {})));
2005
+ let Component;
2006
+ (function(_Component) {
2007
+ _Component.getBuilder = getLiveSystemComponentBuilder;
2008
+ })(Component || (Component = _LiveSystem.Component || (_LiveSystem.Component = {})));
2009
+ _LiveSystem.getBuilder = getLiveSystemBuilder;
2010
+ })(LiveSystem$1 || (LiveSystem$1 = {}));
2011
+
1439
2012
  //#endregion
1440
2013
  //#region src/index.ts
1441
2014
  const BoundedContext = BoundedContext$1;
@@ -1449,6 +2022,8 @@ const ServiceAccountCredentials = ServiceAccountCredentials$1;
1449
2022
  const ServiceAccountId = ServiceAccountId$1;
1450
2023
  const ServiceDeliveryModel = ServiceDeliveryModel$1;
1451
2024
  const Version = Version$1;
2025
+ const Environment = Environment$1;
2026
+ const LiveSystem = LiveSystem$1;
1452
2027
 
1453
2028
  //#endregion
1454
- export { BoundedContext, Fractal, InfrastructureDomain, KebabCaseString, OwnerId, OwnerType, PascalCaseString, ServiceAccountCredentials, ServiceAccountId, ServiceDeliveryModel, Version };
2029
+ export { BoundedContext, Environment, Fractal, InfrastructureDomain, KebabCaseString, LiveSystem, OwnerId, OwnerType, PascalCaseString, ServiceAccountCredentials, ServiceAccountId, ServiceDeliveryModel, Version };