@fractal_cloud/sdk 0.1.1 → 0.1.2

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.cjs ADDED
@@ -0,0 +1,1493 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) {
14
+ __defProp(to, key, {
15
+ get: ((k) => from[k]).bind(null, key),
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ }
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
26
+ }) : target, mod));
27
+
28
+ //#endregion
29
+ let superagent = require("superagent");
30
+ superagent = __toESM(superagent);
31
+
32
+ //#region src/values/kebab_case_string.ts
33
+ /**
34
+ * A constant variable representing a default kebab-case string.
35
+ *
36
+ * The `DEFAULT_KEBAB_CASE_STRING` is initialized with a `value` key,
37
+ * containing an empty string as its default value.
38
+ *
39
+ * This variable is declared as a constant to prevent modification
40
+ * and is designed to not pass validation checks.
41
+ *
42
+ * @type {KebabCaseString}
43
+ */
44
+ const DEFAULT_KEBAB_CASE_STRING = { kebabValue: "" };
45
+ /**
46
+ * Validates whether a given string follows the kebab-case format.
47
+ *
48
+ * A string is considered as valid kebab-case if it:
49
+ * - Starts with a lowercase letter.
50
+ * - Contains only lowercase letters, numbers, and hyphens.
51
+ * - Does not have consecutive hyphens.
52
+ * - Does not end or begin with a hyphen.
53
+ *
54
+ * @param {string} value - The string to validate.
55
+ * @returns {string[]} - An empty array if the string is valid, otherwise an array containing an error message.
56
+ */
57
+ const isValidKebabCaseString = (value) => {
58
+ if (!/^[a-z][a-z0-9]*(-[a-z][a-z0-9]*)*$/.test(value)) return ["Value must be in kebab-case"];
59
+ return [];
60
+ };
61
+ /**
62
+ * Creates a builder for constructing a KebabCaseString object. The builder enforces Kebab case formatting and ensures
63
+ * a valid string is set before building. Once built, the KebabCaseString object becomes immutable.
64
+ *
65
+ * @function getKebabCaseStringBuilder
66
+ * @returns {Object} A builder object with the following methods:
67
+ * - `withValue(value: string): Object` – Sets the value of the KebabCaseString. Throws a `RangeError` if the input is not in Kebab case format (e.g., "example-string").
68
+ * - `reset(): void` – Resets the builder to its default state, clearing the current value.
69
+ * - `build(): KebabCaseString` – Constructs and returns a KebabCaseString object based on the current state. Throws a `SyntaxError` if no value has been set before building.
70
+ */
71
+ const getKebabCaseStringBuilder = () => {
72
+ const internalState = { ...DEFAULT_KEBAB_CASE_STRING };
73
+ const builder = {
74
+ withValue: (value) => {
75
+ internalState.kebabValue = value;
76
+ return builder;
77
+ },
78
+ reset: () => {
79
+ internalState.kebabValue = DEFAULT_KEBAB_CASE_STRING.kebabValue;
80
+ return builder;
81
+ },
82
+ build: () => {
83
+ const validationErrors = isValidKebabCaseString(internalState.kebabValue);
84
+ if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
85
+ return { ...internalState };
86
+ }
87
+ };
88
+ return builder;
89
+ };
90
+ let KebabCaseString$1;
91
+ (function(_KebabCaseString) {
92
+ _KebabCaseString.getBuilder = getKebabCaseStringBuilder;
93
+ })(KebabCaseString$1 || (KebabCaseString$1 = {}));
94
+
95
+ //#endregion
96
+ //#region src/values/version.ts
97
+ const equals$2 = (a, b) => a.major === b.major && a.minor === b.minor && a.patch === b.patch;
98
+ const toString$1 = (version) => `v${version.major}.${version.minor}.${version.patch}`;
99
+ /**
100
+ * Represents the default version for an application or library.
101
+ *
102
+ * This variable is declared as a constant to prevent modification
103
+ * and is designed to not pass validation checks.
104
+ */
105
+ const DEFAULT_VERSION = {
106
+ major: 0,
107
+ minor: 0,
108
+ patch: 0,
109
+ equals: (other) => equals$2(DEFAULT_VERSION, other)
110
+ };
111
+ /**
112
+ * Validates if the provided version object is properly initialized or equivalent to the default version.
113
+ *
114
+ * @param {Version} version - The version object to be validated.
115
+ * @returns {string[]} An array of error messages. If the version is equivalent to the default version, it returns
116
+ * an array containing one error message. Otherwise, it returns an empty array.
117
+ */
118
+ const isValidVersion = (version) => {
119
+ if (equals$2(version, DEFAULT_VERSION)) return ["Version must be initialized"];
120
+ return [];
121
+ };
122
+ /**
123
+ * Creates a builder object for constructing and managing version objects.
124
+ * The builder allows for setting major, minor, and patch versions, resetting to defaults,
125
+ * and building the final version object. The default version is considered uninitialized and
126
+ * an error is thrown if build is called without initializing the version.
127
+ *
128
+ * @function getVersionBuilder
129
+ * @returns {VersionBuilder} Returns a builder object with methods to define and construct a version.
130
+ *
131
+ * - `withMajor(major: number): builder`
132
+ * Sets the major version number and returns the builder.
133
+ *
134
+ * - `withMinor(minor: number): builder`
135
+ * Sets the minor version number and returns the builder.
136
+ *
137
+ * - `withPatch(patch: number): builder`
138
+ * Sets the patch version number and returns the builder.
139
+ *
140
+ * - `reset(): builder`
141
+ * Resets the version to the default values (major: 0, minor: 0, patch: 0) and returns the builder.
142
+ *
143
+ * - `build(): Version`
144
+ * Constructs and returns the final version object. Throws a `SyntaxError` if the version
145
+ * is not initialized (when it matches the default version).
146
+ */
147
+ const getVersionBuilder = () => {
148
+ const internalState = { ...DEFAULT_VERSION };
149
+ const builder = {
150
+ withMajor: (major) => {
151
+ internalState.major = major;
152
+ if (major < 0) throw new RangeError("Major version must be non-negative");
153
+ return builder;
154
+ },
155
+ withMinor: (minor) => {
156
+ if (minor < 0) throw new RangeError("Minor version must be non-negative");
157
+ internalState.minor = minor;
158
+ return builder;
159
+ },
160
+ withPatch: (patch) => {
161
+ if (patch < 0) throw new RangeError("Patch version must be non-negative");
162
+ internalState.patch = patch;
163
+ return builder;
164
+ },
165
+ reset: () => {
166
+ internalState.major = DEFAULT_VERSION.major;
167
+ internalState.minor = DEFAULT_VERSION.minor;
168
+ internalState.patch = DEFAULT_VERSION.patch;
169
+ return builder;
170
+ },
171
+ build: () => {
172
+ const validationErrors = isValidVersion(internalState);
173
+ if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
174
+ const builtVersion = {
175
+ ...internalState,
176
+ equals: (other) => equals$2(builtVersion, other),
177
+ toString: () => toString$1(builtVersion)
178
+ };
179
+ return builtVersion;
180
+ }
181
+ };
182
+ return builder;
183
+ };
184
+ let Version$1;
185
+ (function(_Version) {
186
+ _Version.getBuilder = getVersionBuilder;
187
+ })(Version$1 || (Version$1 = {}));
188
+
189
+ //#endregion
190
+ //#region src/values/owner_type.ts
191
+ /**
192
+ * Enum representing the type of ownership for an entity.
193
+ *
194
+ * This enumeration can be used to differentiate between entities owned by individuals
195
+ * and those owned by organizations.
196
+ *
197
+ * @enum {string}
198
+ * @readonly
199
+ * @property {string} Personal - Represents ownership by an individual person.
200
+ * @property {string} Organizational - Represents ownership by an organization or group.
201
+ */
202
+ let OwnerType$1 = /* @__PURE__ */ function(OwnerType) {
203
+ OwnerType["Personal"] = "Personal";
204
+ OwnerType["Organizational"] = "Organizational";
205
+ return OwnerType;
206
+ }({});
207
+
208
+ //#endregion
209
+ //#region src/values/guid.ts
210
+ 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`];
212
+ return [];
213
+ };
214
+
215
+ //#endregion
216
+ //#region src/values/owner_id.ts
217
+ /**
218
+ * A constant variable representing the default owner ID.
219
+ *
220
+ * This variable is declared as a constant to prevent modification
221
+ * and is designed to not pass validation checks.
222
+ */
223
+ const DEFAULT_OWNER_ID = { ownerIdValue: "" };
224
+ /**
225
+ * Validates whether the given string value is a valid UUID.
226
+ *
227
+ * This function checks if the provided `value` conforms to the UUID format.
228
+ * If the validation fails, an array containing an error message will be returned.
229
+ * If the validation passes, an empty array is returned.
230
+ *
231
+ * @param {string} value - The string value to be validated.
232
+ * @returns {string[]} An array containing error messages if invalid, or an empty array if valid.
233
+ */
234
+ const isValidOwnerId = (value) => {
235
+ if (!value || !value.ownerIdValue) return ["Value must be a non-empty string"];
236
+ return isValidUuid(value.ownerIdValue);
237
+ };
238
+ /**
239
+ * Creates a builder for constructing a OwnerId object. The builder enforces uuid case formatting and ensures
240
+ * a valid string is set before building. Once built, the OwnerId object becomes immutable.
241
+ *
242
+ * @function getOwnerIdBuilder
243
+ * @returns {Object} A builder object with the following methods:
244
+ * - `withValue(value: string): Object` – Sets the value of the OwnerId. Throws a `RangeError` if the input is not in uuid format (e.g., "550e8400-e29b-41d4-a716-446655440000").
245
+ * - `reset(): void` – Resets the builder to its default state, clearing the current value.
246
+ * - `build(): OwnerId` – Constructs and returns a OwnerId object based on the current state. Throws a `SyntaxError` if no value has been set before building.
247
+ */
248
+ const getOwnerIdBuilder = () => {
249
+ const internalState = { ...DEFAULT_OWNER_ID };
250
+ const builder = {
251
+ withValue: (value) => {
252
+ internalState.ownerIdValue = value;
253
+ return builder;
254
+ },
255
+ reset: () => {
256
+ internalState.ownerIdValue = DEFAULT_OWNER_ID.ownerIdValue;
257
+ return builder;
258
+ },
259
+ build: () => {
260
+ const validationErrors = isValidOwnerId(internalState);
261
+ if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
262
+ return { ...internalState };
263
+ }
264
+ };
265
+ return builder;
266
+ };
267
+ let OwnerId$1;
268
+ (function(_OwnerId) {
269
+ _OwnerId.getBuilder = getOwnerIdBuilder;
270
+ })(OwnerId$1 || (OwnerId$1 = {}));
271
+
272
+ //#endregion
273
+ //#region src/bounded_context/id.ts
274
+ const equals$1 = (a, b) => a.ownerType === b.ownerType && a.ownerId.ownerIdValue === b.ownerId.ownerIdValue && a.name.kebabValue === b.name.kebabValue;
275
+ /**
276
+ * A default value for the bounded context identifier used in the system.
277
+ * It contains values that will not pass validation checks.
278
+ */
279
+ const DEFAULT_BOUNDED_CONTEXT_ID = {
280
+ ownerType: OwnerType$1.Personal,
281
+ ownerId: DEFAULT_OWNER_ID,
282
+ name: DEFAULT_KEBAB_CASE_STRING,
283
+ equals: (other) => equals$1(DEFAULT_BOUNDED_CONTEXT_ID, other),
284
+ toString: () => boundedContextIdToString(DEFAULT_BOUNDED_CONTEXT_ID)
285
+ };
286
+ /**
287
+ * Determines whether the given value is a valid Id.
288
+ *
289
+ * @param {BoundedContextId} value - The Id to validate.
290
+ * @returns {boolean} True if the Id is valid; otherwise, false.
291
+ *
292
+ * A Id is considered valid if:
293
+ * - The `ownerId` component of the value is a valid owner identifier, as verified
294
+ * by the `isValidOwnerId` function.
295
+ * - The `name` component of the value is in kebab-case format, as verified by
296
+ * the `isValidKebabCaseString` function.
297
+ */
298
+ const isValidBoundedContextId = (value) => {
299
+ const ownerIdErrors = isValidOwnerId(value.ownerId);
300
+ const nameErrors = isValidKebabCaseString(value.name.kebabValue);
301
+ return [...ownerIdErrors.map((x) => `[Bounded Context Id: ${boundedContextIdToString(value)}] Owner Id error: ${x}`), ...nameErrors.map((x) => `[Bounded Context Id: ${boundedContextIdToString(value)}] Name error: ${x}`)];
302
+ };
303
+ const boundedContextIdToString = (id) => `${id.ownerType.toString()}/${id.ownerId.ownerIdValue}/${id.name.kebabValue}`;
304
+ /**
305
+ * Creates and returns a builder for constructing a `Id` object.
306
+ *
307
+ * The builder allows customization of the `Id` properties such as `ownerType`,
308
+ * while also enforcing constraints during the construction process, ensuring the resulting object is valid.
309
+ * The builder is stateful and provides a method to reset to default values if needed.
310
+ *
311
+ * @returns {BoundedContextIdBuilder} A builder object that provides methods for modifying and constructing a `Id`.
312
+ *
313
+ * @throws {SyntaxError} Throws an error if the resulting `Id` is invalid when the `build` method is invoked.
314
+ */
315
+ const getBoundedContextIdBuilder = () => {
316
+ const internalState = { ...DEFAULT_BOUNDED_CONTEXT_ID };
317
+ const builder = {
318
+ withOwnerType: (ownerType) => {
319
+ internalState.ownerType = ownerType;
320
+ return builder;
321
+ },
322
+ withOwnerId: (ownerId) => {
323
+ internalState.ownerId = ownerId;
324
+ return builder;
325
+ },
326
+ withName: (name) => {
327
+ internalState.name = name;
328
+ return builder;
329
+ },
330
+ reset: () => {
331
+ internalState.ownerType = DEFAULT_BOUNDED_CONTEXT_ID.ownerType;
332
+ internalState.ownerId = DEFAULT_BOUNDED_CONTEXT_ID.ownerId;
333
+ internalState.name = DEFAULT_BOUNDED_CONTEXT_ID.name;
334
+ return builder;
335
+ },
336
+ build: () => {
337
+ const validationErrors = isValidBoundedContextId(internalState);
338
+ if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
339
+ const builtId = {
340
+ ...internalState,
341
+ equals: (other) => equals$1(builtId, other),
342
+ toString: () => boundedContextIdToString(builtId)
343
+ };
344
+ return builtId;
345
+ }
346
+ };
347
+ return builder;
348
+ };
349
+
350
+ //#endregion
351
+ //#region src/fractal/id.ts
352
+ const toString = (id) => `${id.boundedContextId.toString()}/${id.name.kebabValue}:${id.version.toString()}`;
353
+ /**
354
+ * Validates a given Fractal ID and returns a list of error messages if any validation fails.
355
+ * The validation process includes checking the bounded context ID, the name, and the version of the Fractal ID.
356
+ *
357
+ * @param {FractalId} id - The Fractal ID to validate.
358
+ * @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
+ */
360
+ const isValidFractalId = (id) => {
361
+ const boundedContextIdErrors = isValidBoundedContextId(id.boundedContextId);
362
+ const nameErrors = isValidKebabCaseString(id.name.kebabValue);
363
+ const versionErrors = isValidVersion(id.version);
364
+ return [
365
+ ...boundedContextIdErrors.map((x) => `[Fractal Id: ${id.toString()}] Bounded Context Id error: ${x}`),
366
+ ...nameErrors.map((x) => `[Fractal Id: ${id.toString()}] Name errors: ${x}`),
367
+ ...versionErrors.map((x) => `[Fractal Id: ${id.toString()}] Version error: ${x}`)
368
+ ];
369
+ };
370
+ /**
371
+ * Represents the default identifier for a fractal instance.
372
+ *
373
+ * This constant holds a predefined FractalId object used as a default configuration
374
+ * in systems where fractal identification is required. The FractalId includes
375
+ * properties such as the bounded context ID, name, and version.
376
+ *
377
+ * The `boundedContextId` corresponds to the default bounded context identifier.
378
+ * The `name` is represented as a default kebab-case string format.
379
+ * The `version` reflects the defined default version of the fractal.
380
+ *
381
+ * DEFAULT_FRACTAL_ID can be used as a fallback or initial value in scenarios
382
+ * where no specific fractal identifier is provided.
383
+ *
384
+ * @constant {FractalId} DEFAULT_FRACTAL_ID
385
+ */
386
+ const DEFAULT_FRACTAL_ID = {
387
+ boundedContextId: DEFAULT_BOUNDED_CONTEXT_ID,
388
+ name: DEFAULT_KEBAB_CASE_STRING,
389
+ version: DEFAULT_VERSION
390
+ };
391
+ /**
392
+ * Provides a builder for constructing a `FractalId` object.
393
+ * This builder allows incremental creation of the ID through a fluent API
394
+ * with methods for specifying bounded context ID, name, and version, as well as
395
+ * resetting and building the final object.
396
+ *
397
+ * @returns {FractalIdBuilder} A builder object with methods for constructing a `FractalId`.
398
+ *
399
+ * Methods available on the builder:
400
+ * - `withBoundedContextId(value: BoundedContext.Id)`: Sets the bounded context ID for the `FractalId`.
401
+ * - `withName(value: KebabCaseString)`: Sets the name for the `FractalId`.
402
+ * - `withVersion(value: Version)`: Sets the version for the `FractalId`.
403
+ * - `reset()`: Resets the builder's internal state to default values.
404
+ * - `build()`: Validates and constructs the final `FractalId` object. Throws a `SyntaxError` if validation fails.
405
+ */
406
+ const getFractalIdBuilder = () => {
407
+ const internalState = { ...DEFAULT_FRACTAL_ID };
408
+ const builder = {
409
+ withBoundedContextId: (value) => {
410
+ internalState.boundedContextId = value;
411
+ return builder;
412
+ },
413
+ withName: (value) => {
414
+ internalState.name = value;
415
+ return builder;
416
+ },
417
+ withVersion: (value) => {
418
+ internalState.version = value;
419
+ return builder;
420
+ },
421
+ reset: () => {
422
+ internalState.boundedContextId = DEFAULT_FRACTAL_ID.boundedContextId;
423
+ internalState.name = DEFAULT_FRACTAL_ID.name;
424
+ internalState.version = DEFAULT_FRACTAL_ID.version;
425
+ return builder;
426
+ },
427
+ build: () => {
428
+ const validationErrors = isValidFractalId(internalState);
429
+ if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
430
+ const builtId = {
431
+ ...internalState,
432
+ toString: () => toString(builtId)
433
+ };
434
+ return builtId;
435
+ }
436
+ };
437
+ return builder;
438
+ };
439
+
440
+ //#endregion
441
+ //#region src/values/service_delivery_model.ts
442
+ /**
443
+ * Enum representing the different types of service delivery models in cloud computing.
444
+ *
445
+ * @enum {string}
446
+ * @readonly
447
+ * @property {string} IaaS Infrastructure as a Service - A model that provides virtualized computing infrastructure over the internet.
448
+ * @property {string} CaaS Container as a Service - A model focused on deploying and managing containers as a service.
449
+ * @property {string} PaaS Platform as a Service - A cloud model that provides a platform allowing users to develop, run, and manage applications without dealing with the underlying infrastructure.
450
+ * @property {string} FaaS Function as a Service - A serverless model where cloud functions are executed in response to events.
451
+ * @property {string} SaaS Software as a Service - A model in which software applications are delivered over the internet on a subscription basis.
452
+ */
453
+ let ServiceDeliveryModel$1 = /* @__PURE__ */ function(ServiceDeliveryModel) {
454
+ ServiceDeliveryModel["IaaS"] = "IaaS";
455
+ ServiceDeliveryModel["CaaS"] = "CaaS";
456
+ ServiceDeliveryModel["PaaS"] = "PaaS";
457
+ ServiceDeliveryModel["FaaS"] = "FaaS";
458
+ ServiceDeliveryModel["SaaS"] = "SaaS";
459
+ return ServiceDeliveryModel;
460
+ }({});
461
+
462
+ //#endregion
463
+ //#region src/values/pascal_case_string.ts
464
+ /**
465
+ * Validates whether a given string is in PascalCase format.
466
+ * A PascalCase string must start with an uppercase letter and contain
467
+ * only alphabetic characters.
468
+ *
469
+ * @param {string} value - The string to validate.
470
+ * @returns {string[]} An array containing an error message if the string
471
+ * does not conform to PascalCase, or an empty array
472
+ * if the string is valid.
473
+ */
474
+ const isValidPascalCaseString = (value) => {
475
+ if (!/^[A-Z][a-zA-Z]*$/.test(value)) return [`Value '${value}' must be in PascalCase`];
476
+ return [];
477
+ };
478
+ /**
479
+ * A constant object representing a default PascalCase formatted string.
480
+ *
481
+ * This variable is declared as a constant to prevent modification
482
+ * and is designed to not pass validation checks.
483
+ */
484
+ const DEFAULT_PASCAL_CASE_STRING = { pascalValue: "" };
485
+ /**
486
+ * Creates a builder for constructing a PascalCaseString object. The builder enforces Pascal case formatting and ensures
487
+ * a valid string is set before building. Once built, the PascalCaseString object becomes immutable.
488
+ *
489
+ * @function getPascalCaseStringBuilder
490
+ * @returns {Object} A builder object with the following methods:
491
+ * - `withValue(value: string): Object` – Sets the value of the PascalCaseString. Throws a `RangeError` if the input is not in Pascal case format (e.g., "ExampleString").
492
+ * - `reset(): void` – Resets the builder to its default state, clearing the current value.
493
+ * - `build(): PascalCaseString` – Constructs and returns a PascalCaseString object based on the current state. Throws a `SyntaxError` if no value has been set before building.
494
+ */
495
+ const getPascalCaseStringBuilder = () => {
496
+ const internalState = { ...DEFAULT_PASCAL_CASE_STRING };
497
+ const builder = {
498
+ withValue: (value) => {
499
+ internalState.pascalValue = value;
500
+ return builder;
501
+ },
502
+ reset: () => {
503
+ internalState.pascalValue = DEFAULT_PASCAL_CASE_STRING.pascalValue;
504
+ return builder;
505
+ },
506
+ build: () => {
507
+ const validationErrors = isValidPascalCaseString(internalState.pascalValue);
508
+ if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
509
+ return { ...internalState };
510
+ }
511
+ };
512
+ return builder;
513
+ };
514
+ let PascalCaseString$1;
515
+ (function(_PascalCaseString) {
516
+ _PascalCaseString.getBuilder = getPascalCaseStringBuilder;
517
+ })(PascalCaseString$1 || (PascalCaseString$1 = {}));
518
+
519
+ //#endregion
520
+ //#region src/values/infrastructure_domain.ts
521
+ /**
522
+ * Enumeration representing various infrastructure domains.
523
+ * These domains categorize components or services
524
+ * within an infrastructure system.
525
+ *
526
+ * @enum {string}
527
+ * @property {string} ApiManagement - Represents API management-related components.
528
+ * @property {string} NetworkAndCompute - Represents network and compute components.
529
+ * @property {string} CustomWorkloads - Represents custom workload components.
530
+ * @property {string} Messaging - Represents messaging and communication components.
531
+ * @property {string} Storage - Represents data storage components.
532
+ * @property {string} Observability - Represents observability tools and monitoring components.
533
+ * @property {string} Security - Represents security-focused components.
534
+ */
535
+ let InfrastructureDomain$1 = /* @__PURE__ */ function(InfrastructureDomain) {
536
+ InfrastructureDomain["ApiManagement"] = "APIManagement";
537
+ InfrastructureDomain["NetworkAndCompute"] = "NetworkAndCompute";
538
+ InfrastructureDomain["CustomWorkloads"] = "CustomWorkloads";
539
+ InfrastructureDomain["Messaging"] = "Messaging";
540
+ InfrastructureDomain["Storage"] = "Storage";
541
+ InfrastructureDomain["Observability"] = "Observability";
542
+ InfrastructureDomain["Security"] = "Security";
543
+ return InfrastructureDomain;
544
+ }({});
545
+
546
+ //#endregion
547
+ //#region src/component/type.ts
548
+ /**
549
+ * Represents the default type configuration for a component.
550
+ *
551
+ * This variable is declared as a constant to prevent modification
552
+ * and is designed to not pass validation checks.
553
+ */
554
+ const DEFAULT_COMPONENT_TYPE = {
555
+ domain: InfrastructureDomain$1.ApiManagement,
556
+ name: DEFAULT_PASCAL_CASE_STRING
557
+ };
558
+ /**
559
+ * Validates the provided component type and checks for errors in the type's name.
560
+ *
561
+ * The validation ensures that the name of the component type follows the PascalCase string format.
562
+ * If any violations are detected, it returns an array of error messages. Each error message is
563
+ * formatted to include the component type's name and a descriptive error message.
564
+ *
565
+ * @param {ComponentType} type - The component type object to be validated.
566
+ * @returns {string[]} An array of error messages if validation fails; an empty array if the name is valid.
567
+ */
568
+ const isValidComponentType = (type) => {
569
+ const nameError = isValidPascalCaseString(type.name.pascalValue);
570
+ if (nameError.length > 0) return nameError.map((x) => `[Component Type: ${type.name.pascalValue}] Name error: ${x}`);
571
+ return [];
572
+ };
573
+ /**
574
+ * Creates and returns a builder for constructing a `TypeBuilder` instance.
575
+ *
576
+ * This builder provides methods to configure and customize the properties
577
+ * of a `ComponentType` object before it is finalized and built.
578
+ *
579
+ * @returns {ComponentTypeBuilder} A builder instance for constructing a `ComponentType`.
580
+ *
581
+ * @property {Function} withInfrastructureDomain - Sets the `domain` property
582
+ * of the internal state with the provided `InfrastructureDomain` value.
583
+ *
584
+ * @property {Function} withName - Sets the `name` property of the internal
585
+ * state with the provided `PascalCaseString` value.
586
+ *
587
+ * @property {Function} reset - Resets the internal state of the builder to
588
+ * the default `ComponentType` values.
589
+ *
590
+ * @property {Function} build - Validates the internal state of the builder
591
+ * and returns a finalized `ComponentType` object. Throws a `SyntaxError` if
592
+ * validation fails.
593
+ */
594
+ const getComponentTypeBuilder = () => {
595
+ const internalState = { ...DEFAULT_COMPONENT_TYPE };
596
+ const builder = {
597
+ withInfrastructureDomain: (domain) => {
598
+ internalState.domain = domain;
599
+ return builder;
600
+ },
601
+ withName: (name) => {
602
+ internalState.name = name;
603
+ return builder;
604
+ },
605
+ reset: () => {
606
+ internalState.domain = DEFAULT_COMPONENT_TYPE.domain;
607
+ internalState.name = DEFAULT_COMPONENT_TYPE.name;
608
+ return builder;
609
+ },
610
+ build: () => {
611
+ const validationErrors = isValidComponentType(internalState);
612
+ if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
613
+ return { ...internalState };
614
+ }
615
+ };
616
+ return builder;
617
+ };
618
+
619
+ //#endregion
620
+ //#region src/fractal/component/type.ts
621
+ /**
622
+ */
623
+ const DEFAULT_BLUEPRINT_COMPONENT_TYPE = {
624
+ ...DEFAULT_COMPONENT_TYPE,
625
+ serviceDeliveryModel: ServiceDeliveryModel$1.SaaS
626
+ };
627
+ /**
628
+ * Validates the provided component type and checks for errors in the type's name.
629
+ *
630
+ * The validation ensures that the name of the component type follows the PascalCase string format.
631
+ * If any violations are detected, it returns an array of error messages. Each error message is
632
+ * formatted to include the component type's name and a descriptive error message.
633
+ *
634
+ * @param {BlueprintComponentType} type - The component type object to be validated.
635
+ * @returns {string[]} An array of error messages if validation fails; an empty array if the name is valid.
636
+ */
637
+ const isValidBlueprintComponentType = (type) => isValidComponentType(type);
638
+ /**
639
+ * Creates and returns a builder for constructing a `TypeBuilder` instance.
640
+ *
641
+ * This builder provides methods to configure and customize the properties
642
+ * of a `ComponentType` object before it is finalized and built.
643
+ *
644
+ * @returns {BlueprintComponentTypeBuilder} A builder instance for constructing a `ComponentType`.
645
+ *
646
+ * @property {Function} withInfrastructureDomain - Sets the `domain` property
647
+ * of the internal state with the provided `InfrastructureDomain` value.
648
+ *
649
+ * @property {Function} withName - Sets the `name` property of the internal
650
+ * state with the provided `PascalCaseString` value.
651
+ *
652
+ * @property {Function} reset - Resets the internal state of the builder to
653
+ * the default `ComponentType` values.
654
+ *
655
+ * @property {Function} build - Validates the internal state of the builder
656
+ * and returns a finalized `ComponentType` object. Throws a `SyntaxError` if
657
+ * validation fails.
658
+ */
659
+ const getBlueprintComponentTypeBuilder = () => {
660
+ const internalState = { ...DEFAULT_BLUEPRINT_COMPONENT_TYPE };
661
+ const builder = {
662
+ withInfrastructureDomain: (domain) => {
663
+ internalState.domain = domain;
664
+ return builder;
665
+ },
666
+ withServiceDeliveryModel: (serviceDeliveryModel) => {
667
+ internalState.serviceDeliveryModel = serviceDeliveryModel;
668
+ return builder;
669
+ },
670
+ withName: (name) => {
671
+ internalState.name = name;
672
+ return builder;
673
+ },
674
+ reset: () => {
675
+ internalState.domain = DEFAULT_BLUEPRINT_COMPONENT_TYPE.domain;
676
+ internalState.serviceDeliveryModel = DEFAULT_BLUEPRINT_COMPONENT_TYPE.serviceDeliveryModel;
677
+ internalState.name = DEFAULT_BLUEPRINT_COMPONENT_TYPE.name;
678
+ return builder;
679
+ },
680
+ build: () => {
681
+ const validationErrors = isValidBlueprintComponentType(internalState);
682
+ if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
683
+ return { ...internalState };
684
+ }
685
+ };
686
+ return builder;
687
+ };
688
+
689
+ //#endregion
690
+ //#region src/values/generic_parameters.ts
691
+ /**
692
+ * Provides a mechanism to manage and retrieve named fields from an internal container.
693
+ *
694
+ * This function returns an object with methods to access required and optional fields by name.
695
+ * It utilizes an internal container to store field data, enabling controlled retrieval of fields.
696
+ *
697
+ * @returns {GenericParameters} An object containing methods for field retrieval:
698
+ * - `getRequiredFieldByName`: Retrieves a specified field by name. Throws an error if the field is not defined.
699
+ * - `getOptionalFieldByName`: Retrieves a specified field by name. Returns null if the field is not defined.
700
+ */
701
+ const getParametersInstance = () => {
702
+ const container = {};
703
+ return {
704
+ getRequiredFieldByName: (name) => {
705
+ if (typeof container[name] === "undefined" || container[name] === null) throw new Error(`Required field ${name} is not defined`);
706
+ return container[name];
707
+ },
708
+ getOptionalFieldByName: (name) => container[name] ?? null,
709
+ getAllFieldNames: () => Object.keys(container),
710
+ push: (key, value) => container[key] = value,
711
+ remove: (key) => delete container[key],
712
+ toMap: () => ({ ...container })
713
+ };
714
+ };
715
+
716
+ //#endregion
717
+ //#region src/component/id.ts
718
+ /**
719
+ * Validates whether the given identifier is in a valid kebab-case format.
720
+ *
721
+ * @param {ComponentId} id - The identifier object to validate, containing the value to check.
722
+ * @returns {boolean} - Returns true if the identifier is in a valid kebab-case format, false otherwise.
723
+ */
724
+ const isValidId = (id) => {
725
+ return isValidKebabCaseString(id.value.kebabValue).map((x) => `[Component Id: ${id.value.kebabValue}] Id error: ${x}`);
726
+ };
727
+ const equals = (a, b) => a.value === b.value;
728
+ /**
729
+ * Represents the default identifier used in the application.
730
+ * It is initialized with a value that will not pass validation.
731
+ */
732
+ const DEFAULT_COMPONENT_ID = {
733
+ value: DEFAULT_KEBAB_CASE_STRING,
734
+ equals: (other) => equals(DEFAULT_COMPONENT_ID, other)
735
+ };
736
+ /**
737
+ * Creates and returns a builder for constructing a `ComponentId` object.
738
+ *
739
+ * The builder provides methods to set properties of the `ComponentId`, reset them to default
740
+ * values, and validate and build the final object. The `build` method performs validation before
741
+ * creating the `ComponentId`, and throws an error if any validation rules are violated.
742
+ *
743
+ * @returns {ComponentIdBuilder} A builder with methods to configure and build a `ComponentId`.
744
+ */
745
+ const getComponentIdBuilder = () => {
746
+ const internalState = { ...DEFAULT_COMPONENT_ID };
747
+ const builder = {
748
+ withValue: (value) => {
749
+ internalState.value = value;
750
+ return builder;
751
+ },
752
+ reset: () => {
753
+ internalState.value = DEFAULT_COMPONENT_ID.value;
754
+ internalState.equals = DEFAULT_COMPONENT_ID.equals;
755
+ return builder;
756
+ },
757
+ build: () => {
758
+ const validationErrors = isValidId(internalState);
759
+ if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
760
+ const builtId = {
761
+ ...internalState,
762
+ equals: (other) => equals(builtId, other)
763
+ };
764
+ return builtId;
765
+ }
766
+ };
767
+ return builder;
768
+ };
769
+
770
+ //#endregion
771
+ //#region src/component/link.ts
772
+ /**
773
+ * A function to determine if a given ComponentLink is valid.
774
+ *
775
+ * This function checks the validity of a ComponentLink object by verifying
776
+ * the validity of its `id` and `type` properties.
777
+ *
778
+ * @param {ComponentLink} link - The ComponentLink object to validate.
779
+ * @returns {boolean} - Returns true if the link's `id` is valid and its `type` is valid; otherwise, returns false.
780
+ */
781
+ const isValidLink = (link) => {
782
+ const idErrors = isValidId(link.id);
783
+ const typeErrors = isValidComponentType(link.type);
784
+ return [...idErrors.map((x) => `[Link: ${link.id.value}] Id error: ${x}`), ...typeErrors.map((x) => `[Link: ${link.id.value}] Type error: ${x}`)];
785
+ };
786
+ const DEFAULT_LINK = {
787
+ id: DEFAULT_COMPONENT_ID,
788
+ type: DEFAULT_COMPONENT_TYPE,
789
+ parameters: getParametersInstance()
790
+ };
791
+ /**
792
+ * Creates and returns a builder for constructing `ComponentLink` objects.
793
+ *
794
+ * The `getLinkBuilder` function provides a fluent interface for configuring a `ComponentLink` instance.
795
+ * It allows setting properties such as `id`, `type`, and `parameters`. The builder maintains an internal
796
+ * state to incrementally configure the `ComponentLink` object.
797
+ *
798
+ * Functions exposed by the builder:
799
+ *
800
+ * - `withId(id: ComponentId): LinkBuilder`: Assigns the provided `id` to the `ComponentLink`.
801
+ * - `withType(type: ComponentType): LinkBuilder`: Assigns the provided `type` to the `ComponentLink`.
802
+ * - `withParameters(parameters: LinkParameters): LinkBuilder`: Assigns the provided `parameters` to the `ComponentLink`.
803
+ * - `reset(): LinkBuilder`: Resets the builder state to its default values.
804
+ * - `build(): ComponentLink`: Validates the internal state and constructs an immutable `ComponentLink` instance.
805
+ *
806
+ * Throws:
807
+ * - `SyntaxError` if the internal state is invalid when invoking `build()`.
808
+ *
809
+ * @returns {LinkBuilder} The builder object to configure and construct `ComponentLink` instances.
810
+ */
811
+ const getLinkBuilder = () => {
812
+ const internalState = { ...DEFAULT_LINK };
813
+ const builder = {
814
+ withId: (id) => {
815
+ internalState.id = id;
816
+ return builder;
817
+ },
818
+ withType: (type) => {
819
+ internalState.type = type;
820
+ return builder;
821
+ },
822
+ withParameters: (parameters) => {
823
+ internalState.parameters = parameters;
824
+ return builder;
825
+ },
826
+ reset: () => {
827
+ internalState.id = DEFAULT_LINK.id;
828
+ internalState.type = DEFAULT_LINK.type;
829
+ internalState.parameters = DEFAULT_LINK.parameters;
830
+ return builder;
831
+ },
832
+ build: () => {
833
+ const validationErrors = isValidLink(internalState);
834
+ if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
835
+ return { ...internalState };
836
+ }
837
+ };
838
+ return builder;
839
+ };
840
+
841
+ //#endregion
842
+ //#region src/values/helpers.ts
843
+ const isNonEmptyString = (value) => typeof value === "string" && value.trim() !== "";
844
+
845
+ //#endregion
846
+ //#region src/component/entity.ts
847
+ /**
848
+ * Represents the default configuration for a component within the system.
849
+ * This constant can be used as a template or fallback value when no specific component configuration is available.
850
+ *
851
+ * Properties of this constant include:
852
+ * - `type`: The default component type identifier.
853
+ * - `id`: The unique identifier for the default component.
854
+ * - `version`: The version of the default component.
855
+ * - `displayName`: An empty string representing a placeholder for the display name.
856
+ * - `description`: An empty string serving as a placeholder for the component description.
857
+ * - `parameters`: Default parameters for the component, retrieved from a predefined instance.
858
+ * - `outputFields`: The default output fields structure with a nested empty object under `value`.
859
+ * - `links`: An empty array indicating no predefined links for the default configuration.
860
+ * - `dependencies`: An empty array representing no external dependencies.
861
+ */
862
+ const DEFAULT_COMPONENT = {
863
+ type: DEFAULT_COMPONENT_TYPE,
864
+ id: DEFAULT_COMPONENT_ID,
865
+ version: DEFAULT_VERSION,
866
+ displayName: "",
867
+ description: "",
868
+ parameters: getParametersInstance(),
869
+ outputFields: { value: {} },
870
+ links: [],
871
+ dependencies: []
872
+ };
873
+ /**
874
+ * Validates a given component object and returns a list of error messages if any validations fail.
875
+ *
876
+ * The function checks the following properties of the `component`:
877
+ * - `id`: Assessed using the `isValidId` function.
878
+ * - `type`: Assessed using the `isValidComponentType` function.
879
+ * - `version`: Assessed using the `isValidVersion` function.
880
+ * - `displayName`: Validated to ensure it is a non-empty string.
881
+ *
882
+ * Validation errors are returned as strings formatted with the component's ID for easy identification.
883
+ *
884
+ * @param {Component} component - The component object to validate. Must include the fields `id`, `type`, `version`, and `displayName`.
885
+ * @returns {string[]} An array of error messages, each describing a specific validation failure. If no errors are found, the array will be empty.
886
+ */
887
+ 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"];
892
+ return [
893
+ ...idErrors.map((x) => `[Component: ${component.id.value}] Id error: ${x}`),
894
+ ...typeErrors.map((x) => `[Component: ${component.id.value}] Type error: ${x}`),
895
+ ...versionErrors.map((x) => `[Component: ${component.id.value}] Version error: ${x}`),
896
+ ...typeErrors.map((x) => `[Component: ${component.id.value}] Type error: ${x}`),
897
+ ...displayNameErrors.map((x) => `[Component: ${component.id.value}] Display Name error: ${x}`)
898
+ ];
899
+ };
900
+ /**
901
+ * Creates and returns a builder for constructing `Component` objects.
902
+ *
903
+ * The `getComponentBuilder` function provides a fluent interface for configuring a `Component` instance.
904
+ * It allows setting properties such as `type`, `id`, `version`, `displayName`, `description`, `parameters`,
905
+ * `links`, and `dependencies`. The builder maintains an internal state to incrementally configure the `Component` object.
906
+ *
907
+ * Functions exposed by the builder:
908
+ *
909
+ * - `withType(type: ComponentType): ComponentBuilder`: Assigns the provided `type` to the `Component`.
910
+ * - `withId(id: ComponentId): ComponentBuilder`: Assigns the provided `id` to the `Component`.
911
+ * - `withVersion(version: Version): ComponentBuilder`: Assigns the provided `version` to the `Component`.
912
+ * - `withDisplayName(displayName: string): ComponentBuilder`: Assigns the provided `displayName` to the `Component`.
913
+ * - `withDescription(description: string): ComponentBuilder`: Assigns the provided `description` to the `Component`.
914
+ * - `withParameters(parameters: ComponentParameters): ComponentBuilder`: Assigns the provided `parameters` to the `Component`.
915
+ * - `withLinks(links: ComponentLink[]): ComponentBuilder`: Assigns the provided `links` to the `Component`.
916
+ * - `withDependencies(dependencies: Dependency[]): ComponentBuilder`: Assigns the provided `dependencies` to the `Component`.
917
+ * - `reset(): ComponentBuilder`: Resets the builder state to its default values.
918
+ * - `build(): Component`: Validates the internal state and constructs an immutable `Component` instance.
919
+ *
920
+ * Throws:
921
+ * - `SyntaxError` if the internal state is invalid when invoking `build()`.
922
+ *
923
+ * @returns {ComponentBuilder} The builder object to configure and construct `Component` instances.
924
+ */
925
+ const getComponentBuilder = () => {
926
+ const internalState = { ...DEFAULT_COMPONENT };
927
+ const builder = {
928
+ withType: (type) => {
929
+ internalState.type = type;
930
+ return builder;
931
+ },
932
+ withId: (id) => {
933
+ internalState.id = id;
934
+ return builder;
935
+ },
936
+ withVersion: (version) => {
937
+ internalState.version = version;
938
+ return builder;
939
+ },
940
+ withDisplayName: (displayName) => {
941
+ internalState.displayName = displayName;
942
+ return builder;
943
+ },
944
+ withDescription: (description) => {
945
+ internalState.description = description;
946
+ return builder;
947
+ },
948
+ withParameters: (parameters) => {
949
+ internalState.parameters = parameters;
950
+ return builder;
951
+ },
952
+ withLinks: (links) => {
953
+ internalState.links = links;
954
+ return builder;
955
+ },
956
+ withDependencies: (dependencies) => {
957
+ internalState.dependencies = dependencies;
958
+ return builder;
959
+ },
960
+ reset: () => {
961
+ internalState.type = DEFAULT_COMPONENT.type;
962
+ internalState.id = DEFAULT_COMPONENT.id;
963
+ internalState.version = DEFAULT_COMPONENT.version;
964
+ internalState.displayName = DEFAULT_COMPONENT.displayName;
965
+ internalState.description = DEFAULT_COMPONENT.description;
966
+ internalState.parameters = DEFAULT_COMPONENT.parameters;
967
+ internalState.links = DEFAULT_COMPONENT.links;
968
+ internalState.dependencies = DEFAULT_COMPONENT.dependencies;
969
+ return builder;
970
+ },
971
+ build: () => {
972
+ const validationErrors = isValidComponent(internalState);
973
+ if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
974
+ return { ...internalState };
975
+ }
976
+ };
977
+ return builder;
978
+ };
979
+
980
+ //#endregion
981
+ //#region src/component/index.ts
982
+ let Component;
983
+ (function(_Component) {
984
+ let Type;
985
+ (function(_Type) {
986
+ _Type.getBuilder = getComponentTypeBuilder;
987
+ })(Type || (Type = _Component.Type || (_Component.Type = {})));
988
+ let Parameters;
989
+ (function(_Parameters) {
990
+ _Parameters.getInstance = getParametersInstance;
991
+ })(Parameters || (Parameters = _Component.Parameters || (_Component.Parameters = {})));
992
+ let Link;
993
+ (function(_Link) {
994
+ let Parameters;
995
+ (function(_Parameters2) {
996
+ _Parameters2.getInstance = getParametersInstance;
997
+ })(Parameters || (Parameters = _Link.Parameters || (_Link.Parameters = {})));
998
+ _Link.getBuilder = getLinkBuilder;
999
+ })(Link || (Link = _Component.Link || (_Component.Link = {})));
1000
+ let Id;
1001
+ (function(_Id) {
1002
+ _Id.getBuilder = getComponentIdBuilder;
1003
+ })(Id || (Id = _Component.Id || (_Component.Id = {})));
1004
+ _Component.getBuilder = getComponentBuilder;
1005
+ })(Component || (Component = {}));
1006
+
1007
+ //#endregion
1008
+ //#region src/fractal/component/entity.ts
1009
+ const DEFAULT_BLUEPRINT_COMPONENT = {
1010
+ ...DEFAULT_COMPONENT,
1011
+ type: DEFAULT_BLUEPRINT_COMPONENT_TYPE,
1012
+ dependencies: [],
1013
+ isLocked: false,
1014
+ recreateOnFailure: false
1015
+ };
1016
+ const isValidBlueprintComponent = (component) => {
1017
+ return isValidComponent({
1018
+ ...component,
1019
+ dependencies: []
1020
+ });
1021
+ };
1022
+ /**
1023
+ * Creates and returns a builder for constructing `BlueprintComponent` instances.
1024
+ *
1025
+ * The builder provides a fluent API for setting various properties of a `BlueprintComponent`
1026
+ * and performs validation upon calling the `build` method to ensure the resulting object
1027
+ * is valid. If validation fails, an error is thrown.
1028
+ *
1029
+ * @returns {BlueprintComponentBuilder} An object with methods to configure and build a `BlueprintComponent`.
1030
+ *
1031
+ * Methods available on the builder:
1032
+ * - `withType(type: BlueprintComponentType)`: Sets the type of the component.
1033
+ * - `withId(id: ComponentId)`: Sets the unique identifier for the component.
1034
+ * - `withVersion(version: Version)`: Sets the version of the component.
1035
+ * - `withDisplayName(displayName: string)`: Sets the display name for the component.
1036
+ * - `withDescription(description: string)`: Sets a description for the component.
1037
+ * - `withParameters(parameters: GenericParameters)`: Sets the parameters associated with the component.
1038
+ * - `withLinks(links: ComponentLink[])`: Sets the links associated with the component.
1039
+ * - `withDependencies(dependencies: BlueprintComponentDependency[])`: Sets the dependencies of the component.
1040
+ * - `reset()`: Resets all properties of the component to their default values based on `DEFAULT_BLUEPRINT_COMPONENT`.
1041
+ * - `build()`: Validates and constructs the `BlueprintComponent` object. Throws an error if validation fails.
1042
+ */
1043
+ const getBlueprintComponentBuilder = () => {
1044
+ const internalState = { ...DEFAULT_BLUEPRINT_COMPONENT };
1045
+ const builder = {
1046
+ withType: (type) => {
1047
+ internalState.type = type;
1048
+ return builder;
1049
+ },
1050
+ withId: (id) => {
1051
+ internalState.id = id;
1052
+ return builder;
1053
+ },
1054
+ withVersion: (version) => {
1055
+ internalState.version = version;
1056
+ return builder;
1057
+ },
1058
+ withIsLocked: (value) => {
1059
+ internalState.isLocked = value;
1060
+ return builder;
1061
+ },
1062
+ withRecreateOnFailure: (value) => {
1063
+ internalState.recreateOnFailure = value;
1064
+ return builder;
1065
+ },
1066
+ withDisplayName: (displayName) => {
1067
+ internalState.displayName = displayName;
1068
+ return builder;
1069
+ },
1070
+ withDescription: (description) => {
1071
+ internalState.description = description;
1072
+ return builder;
1073
+ },
1074
+ withParameters: (parameters) => {
1075
+ internalState.parameters = parameters;
1076
+ return builder;
1077
+ },
1078
+ withLinks: (links) => {
1079
+ internalState.links = links;
1080
+ return builder;
1081
+ },
1082
+ withDependencies: (dependencies) => {
1083
+ internalState.dependencies = dependencies;
1084
+ return builder;
1085
+ },
1086
+ reset: () => {
1087
+ internalState.type = DEFAULT_BLUEPRINT_COMPONENT.type;
1088
+ internalState.id = DEFAULT_BLUEPRINT_COMPONENT.id;
1089
+ internalState.version = DEFAULT_BLUEPRINT_COMPONENT.version;
1090
+ internalState.displayName = DEFAULT_BLUEPRINT_COMPONENT.displayName;
1091
+ internalState.description = DEFAULT_BLUEPRINT_COMPONENT.description;
1092
+ internalState.parameters = DEFAULT_BLUEPRINT_COMPONENT.parameters;
1093
+ internalState.links = DEFAULT_BLUEPRINT_COMPONENT.links;
1094
+ internalState.dependencies = DEFAULT_BLUEPRINT_COMPONENT.dependencies;
1095
+ internalState.isLocked = DEFAULT_BLUEPRINT_COMPONENT.isLocked;
1096
+ internalState.recreateOnFailure = DEFAULT_BLUEPRINT_COMPONENT.recreateOnFailure;
1097
+ return builder;
1098
+ },
1099
+ build: () => {
1100
+ const validationErrors = isValidBlueprintComponent(internalState);
1101
+ if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
1102
+ return { ...internalState };
1103
+ }
1104
+ };
1105
+ return builder;
1106
+ };
1107
+
1108
+ //#endregion
1109
+ //#region src/fractal/component/index.ts
1110
+ let BlueprintComponent;
1111
+ (function(_BlueprintComponent) {
1112
+ let Type;
1113
+ (function(_Type) {
1114
+ _Type.getBuilder = getBlueprintComponentTypeBuilder;
1115
+ })(Type || (Type = _BlueprintComponent.Type || (_BlueprintComponent.Type = {})));
1116
+ let Id;
1117
+ (function(_Id) {
1118
+ _Id.getBuilder = Component.Id.getBuilder;
1119
+ })(Id || (Id = _BlueprintComponent.Id || (_BlueprintComponent.Id = {})));
1120
+ _BlueprintComponent.getBuilder = getBlueprintComponentBuilder;
1121
+ })(BlueprintComponent || (BlueprintComponent = {}));
1122
+
1123
+ //#endregion
1124
+ //#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";
1128
+ const deployFractal = async (credentials, fractal) => {
1129
+ await superagent.default.post(`${FRACTAL_API_URL}/blueprints/${fractal.id.toString().replace(":", "/")}`).set(CLIENT_ID_HEADER, credentials.id.serviceAccountIdValue).set(CLIENT_SECRET_HEADER, credentials.secret).send({
1130
+ description: fractal.description,
1131
+ isPrivate: fractal.isPrivate,
1132
+ components: fractal.components.map((c) => ({
1133
+ ...c,
1134
+ type: c.type.toString(),
1135
+ id: c.id.value.kebabValue,
1136
+ version: c.version.toString(),
1137
+ parameters: c.parameters.toMap(),
1138
+ dependencies: c.dependencies.map((d) => d.id.value.kebabValue),
1139
+ links: c.links.map((l) => ({
1140
+ componentId: l.id.value.kebabValue,
1141
+ settings: l.parameters.toMap()
1142
+ })),
1143
+ outputFields: Object.keys(c.outputFields.value)
1144
+ }))
1145
+ }).catch((e) => console.error(e.message, e.response.text));
1146
+ };
1147
+ 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);
1149
+ };
1150
+ let FractalService;
1151
+ (function(_FractalService) {
1152
+ _FractalService.deploy = deployFractal;
1153
+ _FractalService.destroy = destroyFractal;
1154
+ })(FractalService || (FractalService = {}));
1155
+
1156
+ //#endregion
1157
+ //#region src/fractal/entity.ts
1158
+ /**
1159
+ * Represents the default configuration for a fractal object.
1160
+ * This variable initializes a fractal with predefined values and
1161
+ * provides default methods for deployment and destruction.
1162
+ *
1163
+ * @constant {Fractal} DEFAULT_FRACTAL
1164
+ * @property {string} id - The unique identifier of the fractal.
1165
+ * @property {boolean} isPrivate - Determines if the fractal is private.
1166
+ * @property {string} description - A brief description of the fractal.
1167
+ * @property {Array} components - A collection of components associated with the fractal.
1168
+ * @property {function} deploy - A method to deploy the fractal.
1169
+ * @property {function} destroy - A method to clean up or destroy the fractal.
1170
+ */
1171
+ const DEFAULT_FRACTAL = {
1172
+ id: DEFAULT_FRACTAL_ID,
1173
+ isPrivate: false,
1174
+ description: "",
1175
+ components: [],
1176
+ deploy: () => Promise.reject(),
1177
+ destroy: () => Promise.reject()
1178
+ };
1179
+ /**
1180
+ * Validates a given fractal object and returns a list of error messages if any issues are found.
1181
+ *
1182
+ * This function checks the following:
1183
+ * 1. Validity of the fractal's ID through the `isValidFractalId` function.
1184
+ * 2. Presence and validity of the fractal's components through the `isValidBlueprintComponent` function.
1185
+ *
1186
+ * If the fractal has:
1187
+ * - An invalid ID: Any errors related to the ID are added to the error list.
1188
+ * - No components or an empty components array: Adds an error indicating components must not be empty.
1189
+ * - Invalid components: Errors from validating each component are appended to the error list.
1190
+ *
1191
+ * @param {Fractal} fractal - The fractal object to validate. Must include an ID and an array of components.
1192
+ * @returns {string[]} An array of error messages describing any validation issues with the fractal.
1193
+ */
1194
+ const isValidFractal = (fractal) => {
1195
+ const idErrors = isValidFractalId(fractal.id);
1196
+ const componentsErrors = !fractal.components || fractal.components.length === 0 ? [`[Fractal: ${fractal.id.toString()}]: components must not be empty`] : fractal.components.reduce((acc, x) => {
1197
+ acc.push(...isValidBlueprintComponent(x));
1198
+ return acc;
1199
+ }, []);
1200
+ return [...idErrors, ...componentsErrors];
1201
+ };
1202
+ const getFractalBuilder = () => {
1203
+ const internalState = { ...DEFAULT_FRACTAL };
1204
+ const builder = {
1205
+ withId: (value) => {
1206
+ internalState.id = value;
1207
+ return builder;
1208
+ },
1209
+ withIsPrivate: (value) => {
1210
+ internalState.isPrivate = value;
1211
+ return builder;
1212
+ },
1213
+ withDescription: (value) => {
1214
+ internalState.description = value;
1215
+ return builder;
1216
+ },
1217
+ withComponents: (value) => {
1218
+ if (!internalState.components) internalState.components = [];
1219
+ internalState.components.push(...value);
1220
+ return builder;
1221
+ },
1222
+ withComponent: (value) => {
1223
+ if (!internalState.components) internalState.components = [];
1224
+ internalState.components.push(value);
1225
+ return builder;
1226
+ },
1227
+ reset: () => {
1228
+ internalState.id = DEFAULT_FRACTAL.id;
1229
+ internalState.isPrivate = DEFAULT_FRACTAL.isPrivate;
1230
+ internalState.description = DEFAULT_FRACTAL.description;
1231
+ internalState.components = DEFAULT_FRACTAL.components;
1232
+ return builder;
1233
+ },
1234
+ build: () => {
1235
+ const validationErrors = isValidFractal(internalState);
1236
+ if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
1237
+ return {
1238
+ ...internalState,
1239
+ deploy: (credentials) => FractalService.deploy(credentials, internalState),
1240
+ destroy: (credentials) => FractalService.destroy(credentials, internalState.id)
1241
+ };
1242
+ }
1243
+ };
1244
+ return builder;
1245
+ };
1246
+
1247
+ //#endregion
1248
+ //#region src/fractal/index.ts
1249
+ let Fractal$1;
1250
+ (function(_Fractal) {
1251
+ let Id;
1252
+ (function(_Id) {
1253
+ _Id.getBuilder = getFractalIdBuilder;
1254
+ })(Id || (Id = _Fractal.Id || (_Fractal.Id = {})));
1255
+ let Component;
1256
+ (function(_Component) {
1257
+ _Component.getBuilder = getBlueprintComponentBuilder;
1258
+ let Type;
1259
+ (function(_Type) {
1260
+ _Type.getBuilder = getBlueprintComponentTypeBuilder;
1261
+ })(Type || (Type = _Component.Type || (_Component.Type = {})));
1262
+ let Id;
1263
+ (function(_Id2) {
1264
+ _Id2.getBuilder = BlueprintComponent.Id.getBuilder;
1265
+ })(Id || (Id = _Component.Id || (_Component.Id = {})));
1266
+ })(Component || (Component = _Fractal.Component || (_Fractal.Component = {})));
1267
+ _Fractal.getBuilder = getFractalBuilder;
1268
+ })(Fractal$1 || (Fractal$1 = {}));
1269
+
1270
+ //#endregion
1271
+ //#region src/bounded_context/entity.ts
1272
+ const DEFAULT = {
1273
+ id: DEFAULT_BOUNDED_CONTEXT_ID,
1274
+ displayName: ""
1275
+ };
1276
+ /**
1277
+ * Determines whether the given bounded context object is valid.
1278
+ *
1279
+ * The validation checks if the bounded context contains:
1280
+ * - A valid bounded context ID, verified through the `isValidBoundedContextId` function.
1281
+ * - A non-empty string as the display name, verified through the `isNonEmptyString` function.
1282
+ *
1283
+ * @param {BoundedContext} value - The bounded context object to be validated.
1284
+ * @returns {boolean} Returns true if the bounded context is valid; otherwise, returns false.
1285
+ */
1286
+ 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.map((x) => `[Bounded Context: ${value.id.toString()}] Id error: ${x}`), ...displayNameErrors.map((x) => `[Bounded Context: ${value.id.toString()}] Display Name error: ${x}`)];
1290
+ };
1291
+ /**
1292
+ * Creates a builder for constructing a BoundedContext object with a fluid API.
1293
+ *
1294
+ * The `getBoundedContextBuilder` function returns an object with methods that allow incremental construction
1295
+ * of a `BoundedContext` instance. It ensures validation at the `build()` step and supports resets
1296
+ * to default values.
1297
+ *
1298
+ * @function
1299
+ * @returns {BoundedContextBuilder} A builder object for creating a `BoundedContext` instance.
1300
+ *
1301
+ * @throws {SyntaxError} Thrown when attempting to build a `BoundedContext` instance
1302
+ * that is invalid, such as when required fields are not initialized.
1303
+ */
1304
+ const getBoundedContextBuilder = () => {
1305
+ const internalState = { ...DEFAULT };
1306
+ const builder = {
1307
+ withId: (id) => {
1308
+ internalState.id = id;
1309
+ return builder;
1310
+ },
1311
+ withDisplayName: (displayName) => {
1312
+ internalState.displayName = displayName;
1313
+ return builder;
1314
+ },
1315
+ withDescription: (description) => {
1316
+ internalState.description = description;
1317
+ return builder;
1318
+ },
1319
+ reset: () => {
1320
+ internalState.id = DEFAULT.id;
1321
+ internalState.displayName = DEFAULT.displayName;
1322
+ internalState.description = DEFAULT.description;
1323
+ return builder;
1324
+ },
1325
+ build: () => {
1326
+ const validationErrors = isValidBoundedContext(internalState);
1327
+ if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
1328
+ return { ...internalState };
1329
+ }
1330
+ };
1331
+ return builder;
1332
+ };
1333
+
1334
+ //#endregion
1335
+ //#region src/bounded_context/index.ts
1336
+ let BoundedContext$1;
1337
+ (function(_BoundedContext) {
1338
+ let Id;
1339
+ (function(_Id) {
1340
+ _Id.getBuilder = getBoundedContextIdBuilder;
1341
+ })(Id || (Id = _BoundedContext.Id || (_BoundedContext.Id = {})));
1342
+ _BoundedContext.getBuilder = getBoundedContextBuilder;
1343
+ })(BoundedContext$1 || (BoundedContext$1 = {}));
1344
+
1345
+ //#endregion
1346
+ //#region src/values/service_account_id.ts
1347
+ /**
1348
+ * Represents the default service account identifier used in the application.
1349
+ * This value is typically utilized to associate operations or resources with the
1350
+ * default service account when no specific account is provided.
1351
+ *
1352
+ * @constant {ServiceAccountId}
1353
+ */
1354
+ const DEFAULT_SERVICE_ACCOUNT_ID = { serviceAccountIdValue: "" };
1355
+ /**
1356
+ * Validates whether the provided value is a valid service account ID.
1357
+ *
1358
+ * The function determines validity by checking if the given value is a valid UUID.
1359
+ * It returns an array of validation error messages if the value is invalid;
1360
+ * otherwise, it returns an empty array.
1361
+ *
1362
+ * @param {string} value - The value to be validated as a service account ID.
1363
+ * @returns {string[]} An array of validation errors, or an empty array if valid.
1364
+ */
1365
+ const isValidServiceAccountId = (value) => {
1366
+ if (!value || !value.serviceAccountIdValue) return ["Value must be a non-empty string"];
1367
+ return isValidUuid(value.serviceAccountIdValue);
1368
+ };
1369
+ /**
1370
+ * Creates and returns a builder object for constructing a ServiceAccountId.
1371
+ *
1372
+ * The builder provides methods to configure and build a ServiceAccountId, ensuring
1373
+ * that the resulting object adheres to the required validation rules.
1374
+ *
1375
+ * @returns {ServiceAccountIdBuilder} A builder instance used to configure and construct
1376
+ * a ServiceAccountId object.
1377
+ *
1378
+ * The builder provides the following functionalities:
1379
+ * - `withValue(value: string)`: Sets the `value` for the ServiceAccountId. The provided
1380
+ * value must be a valid UUID; otherwise, a `RangeError` is thrown.
1381
+ * - `reset()`: Resets the `value` to the default value specified by `DEFAULT_SERVICE_ACCOUNT_ID`.
1382
+ * - `build()`: Constructs the ServiceAccountId object. If the current state contains
1383
+ * validation errors, a `SyntaxError` is thrown with the list of validation messages.
1384
+ *
1385
+ * The builder maintains an internal mutable state that is used to apply configurations
1386
+ * incrementally until `build()` is called to produce the final ServiceAccountId object.
1387
+ */
1388
+ const getServiceAccountIdBuilder = () => {
1389
+ const internalState = { ...DEFAULT_SERVICE_ACCOUNT_ID };
1390
+ const builder = {
1391
+ withValue: (value) => {
1392
+ internalState.serviceAccountIdValue = value;
1393
+ return builder;
1394
+ },
1395
+ reset: () => {
1396
+ internalState.serviceAccountIdValue = DEFAULT_SERVICE_ACCOUNT_ID.serviceAccountIdValue;
1397
+ return builder;
1398
+ },
1399
+ build: () => {
1400
+ const validationErrors = isValidServiceAccountId(internalState);
1401
+ if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
1402
+ return { ...internalState };
1403
+ }
1404
+ };
1405
+ return builder;
1406
+ };
1407
+ let ServiceAccountId$1;
1408
+ (function(_ServiceAccountId) {
1409
+ _ServiceAccountId.getBuilder = getServiceAccountIdBuilder;
1410
+ })(ServiceAccountId$1 || (ServiceAccountId$1 = {}));
1411
+
1412
+ //#endregion
1413
+ //#region src/values/service_account_credentials.ts
1414
+ const DEFAULT_SERVICE_ACCOUNT_CREDENTIALS = {
1415
+ id: DEFAULT_SERVICE_ACCOUNT_ID,
1416
+ secret: ""
1417
+ };
1418
+ /**
1419
+ * Validates the provided service account credentials and returns a list of validation errors.
1420
+ *
1421
+ * @param {ServiceAccountCredentials} value - The service account credentials to validate.
1422
+ * @returns {string[]} - An array of error messages, where each message describes a validation issue.
1423
+ * If the credentials are valid, the array is empty.
1424
+ */
1425
+ const isValidServiceAccountCredentials = (value) => {
1426
+ const idErrors = isValidServiceAccountId(value.id);
1427
+ const secretErrors = value.secret ? [] : ["Secret must be a non-empty string"];
1428
+ return [...idErrors, ...secretErrors];
1429
+ };
1430
+ /**
1431
+ * Creates and returns a builder for constructing service account credentials.
1432
+ *
1433
+ * The builder provides methods to configure and validate a `ServiceAccountCredentials` object.
1434
+ * It includes support for setting the `id` and `secret`, resetting to default values,
1435
+ * and finalizing the construction by ensuring the credentials are valid.
1436
+ *
1437
+ * @returns {ServiceAccountCredentialsBuilder} A builder object to construct `ServiceAccountCredentials`.
1438
+ */
1439
+ const getServiceAccountCredentialsBuilder = () => {
1440
+ const internalState = { ...DEFAULT_SERVICE_ACCOUNT_CREDENTIALS };
1441
+ const builder = {
1442
+ withId: (value) => {
1443
+ internalState.id = value;
1444
+ return builder;
1445
+ },
1446
+ withSecret: (value) => {
1447
+ internalState.secret = value;
1448
+ return builder;
1449
+ },
1450
+ reset: () => {
1451
+ internalState.id = DEFAULT_SERVICE_ACCOUNT_CREDENTIALS.id;
1452
+ internalState.secret = DEFAULT_SERVICE_ACCOUNT_CREDENTIALS.secret;
1453
+ return builder;
1454
+ },
1455
+ build: () => {
1456
+ const validationErrors = isValidServiceAccountCredentials(internalState);
1457
+ if (validationErrors.length > 0) throw new SyntaxError(validationErrors.join("\n"));
1458
+ return { ...internalState };
1459
+ }
1460
+ };
1461
+ return builder;
1462
+ };
1463
+ let ServiceAccountCredentials$1;
1464
+ (function(_ServiceAccountCredentials) {
1465
+ _ServiceAccountCredentials.getBuilder = getServiceAccountCredentialsBuilder;
1466
+ })(ServiceAccountCredentials$1 || (ServiceAccountCredentials$1 = {}));
1467
+
1468
+ //#endregion
1469
+ //#region src/index.ts
1470
+ const BoundedContext = BoundedContext$1;
1471
+ const Fractal = Fractal$1;
1472
+ const InfrastructureDomain = InfrastructureDomain$1;
1473
+ const KebabCaseString = KebabCaseString$1;
1474
+ const OwnerId = OwnerId$1;
1475
+ const OwnerType = OwnerType$1;
1476
+ const PascalCaseString = PascalCaseString$1;
1477
+ const ServiceAccountCredentials = ServiceAccountCredentials$1;
1478
+ const ServiceAccountId = ServiceAccountId$1;
1479
+ const ServiceDeliveryModel = ServiceDeliveryModel$1;
1480
+ const Version = Version$1;
1481
+
1482
+ //#endregion
1483
+ exports.BoundedContext = BoundedContext;
1484
+ exports.Fractal = Fractal;
1485
+ exports.InfrastructureDomain = InfrastructureDomain;
1486
+ exports.KebabCaseString = KebabCaseString;
1487
+ exports.OwnerId = OwnerId;
1488
+ exports.OwnerType = OwnerType;
1489
+ exports.PascalCaseString = PascalCaseString;
1490
+ exports.ServiceAccountCredentials = ServiceAccountCredentials;
1491
+ exports.ServiceAccountId = ServiceAccountId;
1492
+ exports.ServiceDeliveryModel = ServiceDeliveryModel;
1493
+ exports.Version = Version;