@api-client/core 0.11.6 → 0.11.8

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.
Files changed (58) hide show
  1. package/build/src/amf/definitions/Shapes.d.ts +1 -1
  2. package/build/src/amf/definitions/Shapes.js.map +1 -1
  3. package/build/src/browser.d.ts +2 -0
  4. package/build/src/browser.d.ts.map +1 -1
  5. package/build/src/browser.js +2 -0
  6. package/build/src/browser.js.map +1 -1
  7. package/build/src/index.d.ts +2 -0
  8. package/build/src/index.d.ts.map +1 -1
  9. package/build/src/index.js +2 -0
  10. package/build/src/index.js.map +1 -1
  11. package/build/src/modeling/DataAssociation.d.ts +10 -2
  12. package/build/src/modeling/DataAssociation.d.ts.map +1 -1
  13. package/build/src/modeling/DataAssociation.js +32 -2
  14. package/build/src/modeling/DataAssociation.js.map +1 -1
  15. package/build/src/modeling/DataEntity.d.ts +26 -1
  16. package/build/src/modeling/DataEntity.d.ts.map +1 -1
  17. package/build/src/modeling/DataEntity.js +73 -8
  18. package/build/src/modeling/DataEntity.js.map +1 -1
  19. package/build/src/modeling/DataModel.d.ts +10 -1
  20. package/build/src/modeling/DataModel.d.ts.map +1 -1
  21. package/build/src/modeling/DataModel.js +22 -2
  22. package/build/src/modeling/DataModel.js.map +1 -1
  23. package/build/src/modeling/DataNamespace.d.ts +60 -55
  24. package/build/src/modeling/DataNamespace.d.ts.map +1 -1
  25. package/build/src/modeling/DataNamespace.js +133 -116
  26. package/build/src/modeling/DataNamespace.js.map +1 -1
  27. package/build/src/modeling/DataProperty.d.ts +16 -3
  28. package/build/src/modeling/DataProperty.d.ts.map +1 -1
  29. package/build/src/modeling/DataProperty.js +28 -2
  30. package/build/src/modeling/DataProperty.js.map +1 -1
  31. package/build/src/modeling/ImpactAnalysis.d.ts +290 -0
  32. package/build/src/modeling/ImpactAnalysis.d.ts.map +1 -0
  33. package/build/src/modeling/ImpactAnalysis.js +437 -0
  34. package/build/src/modeling/ImpactAnalysis.js.map +1 -0
  35. package/build/src/modeling/types.d.ts +14 -0
  36. package/build/src/modeling/types.d.ts.map +1 -0
  37. package/build/src/modeling/types.js +2 -0
  38. package/build/src/modeling/types.js.map +1 -0
  39. package/data/models/example-generator-api.json +9 -9
  40. package/package.json +9 -19
  41. package/src/amf/definitions/Shapes.ts +1 -1
  42. package/src/modeling/DataAssociation.ts +36 -2
  43. package/src/modeling/DataEntity.ts +88 -12
  44. package/src/modeling/DataModel.ts +24 -2
  45. package/src/modeling/DataNamespace.ts +150 -137
  46. package/src/modeling/DataProperty.ts +32 -3
  47. package/src/modeling/ImpactAnalysis.ts +519 -0
  48. package/src/modeling/types.ts +13 -0
  49. package/tests/servers/ExpressServer.ts +1 -0
  50. package/tests/servers/express-routes/BaseApi.ts +1 -1
  51. package/tests/servers/express-routes/TestsApi.ts +1 -1
  52. package/tests/unit/modeling/data_association.spec.ts +73 -0
  53. package/tests/unit/modeling/data_entity.spec.ts +111 -1
  54. package/tests/unit/modeling/data_model.spec.ts +54 -0
  55. package/tests/unit/modeling/data_namespace.spec.ts +46 -1
  56. package/tests/unit/modeling/data_property.spec.ts +73 -0
  57. package/tests/unit/modeling/impact_analysis.spec.ts +373 -0
  58. package/tsconfig.browser.json +2 -1
@@ -0,0 +1,290 @@
1
+ import { DataNamespaceKind, DataEntityKind, DataModelKind, DataPropertyKind, DataAssociationKind } from '../models/kinds.js';
2
+ import type { DataNamespace } from './DataNamespace.js';
3
+ export type ImpactKinds = typeof DataNamespaceKind | typeof DataEntityKind | typeof DataModelKind | typeof DataPropertyKind | typeof DataAssociationKind;
4
+ /**
5
+ * The impact analysis report
6
+ */
7
+ interface ImpactReport {
8
+ /**
9
+ * The key of the impacted data object.
10
+ * This is the key of the object that is being changed.
11
+ */
12
+ key: string;
13
+ /**
14
+ * The kind of the impacted data object.
15
+ * This is the kind of the object that is being changed.
16
+ */
17
+ kind: ImpactKinds;
18
+ /**
19
+ * The list of impacted data objects.
20
+ */
21
+ impact: ImpactItem[];
22
+ /**
23
+ * Whether it is possible to proceed with the change.
24
+ * If the change is not possible, the reason will be in the impact list.
25
+ */
26
+ canProceed: boolean;
27
+ }
28
+ interface ImpactItem {
29
+ /**
30
+ * The key of the impacted data object.
31
+ */
32
+ key: string;
33
+ /**
34
+ * The kind of the impacted data object.
35
+ */
36
+ kind: string;
37
+ /**
38
+ * The type of the impact.
39
+ *
40
+ * - `delete` - The data object would be deleted.
41
+ */
42
+ type: 'delete';
43
+ /**
44
+ * The impact description.
45
+ */
46
+ impact: string;
47
+ /**
48
+ * Whether the impact is blocking the operation.
49
+ * If true, the operation cannot proceed.
50
+ */
51
+ blocking: boolean;
52
+ /**
53
+ * The type of the relationship between two impacted objects.
54
+ */
55
+ relationship?: 'child';
56
+ /**
57
+ * The resolution of the conflict if the change will be forced.
58
+ */
59
+ resolution?: string;
60
+ }
61
+ /**
62
+ * # ImpactAnalysis
63
+ *
64
+ * The `ImpactAnalysis` class is a powerful tool for analyzing the consequences of deleting data domain objects
65
+ * within a `DataNamespace`.
66
+ * It helps developers understand the ripple effects of removing a namespace, data model, entity, property,
67
+ * or association, ensuring data integrity and preventing unintended side effects.
68
+ *
69
+ * ## Core Concepts
70
+ *
71
+ * - **Impact Report:** The central output of the `ImpactAnalysis` class is an `ImpactReport`. This report details the
72
+ * potential consequences of a deletion operation, including:
73
+ * - The object being deleted (`key`, `kind`).
74
+ * - A list of `ImpactItem` objects, each describing a specific consequence.
75
+ * - Whether the deletion can proceed safely (`canProceed`).
76
+ *
77
+ * - **ImpactItem:** Each `ImpactItem` describes a specific consequence of the deletion. Key properties include:
78
+ * - `key`: The key of the impacted object.
79
+ * - `kind`: The kind of the impacted object.
80
+ * - `type`: The type of impact (currently only `delete`).
81
+ * - `impact`: A human-readable description of the impact.
82
+ * - `blocking`: Whether this impact prevents the deletion from proceeding.
83
+ * - `relationship`: The type of relationship between the deleted object and the impacted object (e.g., `child`).
84
+ * - `resolution`: A description of how the impact will be resolved if the deletion is forced.
85
+ *
86
+ * - **Blocking Impacts:** Some impacts are considered "blocking," meaning they prevent the deletion from proceeding
87
+ * without manual intervention. For example, deleting an entity that is a parent to other entities is
88
+ * a blocking impact.
89
+ *
90
+ * - **Non-Blocking Impacts:** Some impacts are informational and do not prevent the deletion. For example, deleting a
91
+ * property is not a blocking impact.
92
+ *
93
+ * ## Usage
94
+ *
95
+ * 1. **Instantiation:** Create an instance of `ImpactAnalysis`, passing the root `DataNamespace` as an argument.
96
+ *
97
+ * ```typescript
98
+ * import { DataNamespace } from './DataNamespace'; // Assuming DataNamespace is in the same directory
99
+ * import { ImpactAnalysis } from './ImpactAnalysis'; // Assuming ImpactAnalysis is in the same directory
100
+ *
101
+ * const rootNamespace = new DataNamespace();
102
+ * // ... add some data to the namespace
103
+ * const analyzer = new ImpactAnalysis(rootNamespace);
104
+ * ```
105
+ *
106
+ * 2. **Performing Analysis:** Use the `deleteAnalysis()` method to generate an `ImpactReport` for a specific deletion.
107
+ * Provide the `key` and `kind` of the object to be deleted.
108
+ *
109
+ * ```typescript
110
+ * import { DataEntityKind } from '../models/kinds.js';
111
+ * // ...
112
+ * const entityKey = 'some-entity-key';
113
+ * const report = analyzer.deleteAnalysis(entityKey, DataEntityKind);
114
+ * ```
115
+ *
116
+ * 3. **Interpreting the Report:** Examine the `ImpactReport` to understand the consequences of the deletion.
117
+ * - Check `report.canProceed` to see if the deletion is safe.
118
+ * - Iterate through `report.impact` to understand each consequence.
119
+ * - Pay special attention to `impact.blocking` to identify impacts that require manual resolution.
120
+ *
121
+ * ```typescript
122
+ * if (report.canProceed) {
123
+ * // Proceed with deletion
124
+ * } else {
125
+ * console.warn('Deletion cannot proceed due to the following impacts:');
126
+ * report.impact.forEach((item) => {
127
+ * console.warn(`- ${item.impact}`);
128
+ * if (item.blocking) {
129
+ * console.warn(` - This impact is blocking.`);
130
+ * if (item.resolution) {
131
+ * console.warn(` - Resolution: ${item.resolution}`);
132
+ * }
133
+ * }
134
+ * });
135
+ * // Handle blocking impacts (e.g., prompt the user, modify the data, etc.)
136
+ * }
137
+ * ```
138
+ *
139
+ * ## Supported Deletion Scenarios
140
+ *
141
+ * The `ImpactAnalysis` class supports analyzing the deletion of the following data domain object types:
142
+ *
143
+ * - **Namespaces (`DataNamespaceKind`):** Deleting a namespace also impacts all its child namespaces,
144
+ * data models, entities, properties, and associations.
145
+ * - **Data Models (`DataModelKind`):** Deleting a data model impacts all its entities, properties, and associations.
146
+ * - **Entities (`DataEntityKind`):** Deleting an entity impacts its properties, associations, and any other
147
+ * entities that have it as a parent or target in an association.
148
+ * - **Properties (`DataPropertyKind`):** Deleting a property impacts the entity it belongs to.
149
+ * - **Associations (`DataAssociationKind`):** Deleting an association impacts the entity it belongs to.
150
+ *
151
+ * ## Example: Deleting an Entity
152
+ *
153
+ * Consider the following scenario:
154
+ *
155
+ * - Namespace: `MyNamespace`
156
+ * - Data Model: `ProductModel`
157
+ * - Entity: `Product`
158
+ * - Property: `name`
159
+ * - Association: `category` (targets `Category` entity)
160
+ * - Entity: `Category`
161
+ * - Property: `name`
162
+ * - Entity: `SpecialProduct` (parent: `Product`)
163
+ *
164
+ * If you attempt to delete the `Product` entity, the `ImpactAnalysis` will generate a report similar to this:
165
+ *
166
+ * ```json
167
+ * {
168
+ * "key": "Product",
169
+ * "kind": "DataEntityKind",
170
+ * "impact": [
171
+ * {
172
+ * "key": "Product",
173
+ * "kind": "DataEntityKind",
174
+ * "type": "delete",
175
+ * "impact": "The entity with key Product will be deleted.",
176
+ * "blocking": false
177
+ * },
178
+ * {
179
+ * "key": "SpecialProduct",
180
+ * "kind": "DataEntityKind",
181
+ * "type": "delete",
182
+ * "impact": "The SpecialProduct entity will become an orphan because it is a child of Product.",
183
+ * "resolution": "The Product will be removed as the parent parent of SpecialProduct.",
184
+ * "blocking": true,
185
+ * "relationship": "child"
186
+ * },
187
+ * {
188
+ * "key": "category",
189
+ * "kind": "DataAssociationKind",
190
+ * "type": "delete",
191
+ * "impact": "The association with key category will be broken because it has a target to Product.",
192
+ * "resolution": "The association with key category will be removed from Product.",
193
+ * "blocking": true
194
+ * },
195
+ * {
196
+ * "key": "name",
197
+ * "kind": "DataPropertyKind",
198
+ * "type": "delete",
199
+ * "impact": "The property with key name will be deleted.",
200
+ * "blocking": false
201
+ * }
202
+ * ],
203
+ * "canProceed": false
204
+ * }
205
+ * ```
206
+ *
207
+ * This report indicates that:
208
+ *
209
+ * - The `Product` entity will be deleted.
210
+ * - The `SpecialProduct` entity will become an orphan (blocking).
211
+ * - The `category` association will be broken (blocking).
212
+ * - The `name` property will be deleted.
213
+ * - The deletion cannot proceed without addressing the blocking impacts.
214
+ *
215
+ * ## Types
216
+ *
217
+ * ### `ImpactKinds`
218
+ *
219
+ * - **Description:** A type alias for the kinds of data domain objects that can be analyzed.
220
+ * - **Values:**
221
+ * - `DataNamespaceKind`
222
+ * - `DataEntityKind`
223
+ * - `DataModelKind`
224
+ * - `DataPropertyKind`
225
+ * - `DataAssociationKind`
226
+ *
227
+ * ### `ImpactReport`
228
+ *
229
+ * - **Description:** The structure of the impact analysis report.
230
+ * - **Properties:**
231
+ * - `key` (`string`): The key of the object being deleted.
232
+ * - `kind` (`ImpactKinds`): The kind of the object being deleted.
233
+ * - `impact` (`ImpactItem[]`): The list of impacts.
234
+ * - `canProceed` (`boolean`): Whether the deletion can proceed.
235
+ *
236
+ * ### `ImpactItem`
237
+ *
238
+ * - **Description:** The structure of an individual impact item.
239
+ * - **Properties:**
240
+ * - `key` (`string`): The key of the impacted object.
241
+ * - `kind` (`string`): The kind of the impacted object.
242
+ * - `type` (`'delete'`): The type of impact.
243
+ * - `impact` (`string`): The impact description.
244
+ * - `blocking` (`boolean`): Whether the impact is blocking.
245
+ * - `relationship` (`'child'`, optional): The relationship type.
246
+ * - `resolution` (`string`, optional): The resolution description.
247
+ *
248
+ * ## Error Handling
249
+ *
250
+ * The `ImpactAnalysis` class does not throw errors. Instead, it uses the `ImpactReport` to communicate
251
+ * the results of the analysis, including any blocking impacts.
252
+ *
253
+ * ## Best Practices
254
+ *
255
+ * - **Always Analyze Before Deleting:** Before deleting any data domain object, always use `ImpactAnalysis`
256
+ * to understand the consequences.
257
+ * - **Handle Blocking Impacts:** Pay close attention to `blocking` impacts and implement appropriate
258
+ * logic to handle them.
259
+ * - **Inform the User:** If a deletion cannot proceed, inform the user about the blocking impacts and provide
260
+ * guidance on how to resolve them.
261
+ * - **Consider Forced Deletion:** In some cases, you may want to allow users to force a deletion even if there are
262
+ * blocking impacts. In such cases, you should clearly communicate the risks to the user.
263
+ *
264
+ * ## Conclusion
265
+ *
266
+ * The `ImpactAnalysis` class is an essential tool for maintaining data integrity when working with complex
267
+ * data domain models. By providing detailed impact reports, it empowers developers to make informed decisions
268
+ * about data deletion and prevent unintended consequences.
269
+ */
270
+ export declare class ImpactAnalysis {
271
+ private report;
272
+ private root;
273
+ constructor(root: DataNamespace);
274
+ /**
275
+ * Generates a report of how the data domain will be impacted by the deletion of a data domain object.
276
+ * @param key The key of the impacted data domain object.
277
+ * @param kind The kind of the impacted data object.
278
+ * @returns The delete impact analysis report.
279
+ */
280
+ deleteAnalysis(key: string, kind: ImpactKinds): ImpactReport;
281
+ protected createDeleteImpact(key: string, kind: ImpactKinds, rootKey: string): ImpactItem[];
282
+ protected deleteNamespaceAnalysis(key: string, rootKey: string): ImpactItem[];
283
+ protected deleteDataModelAnalysis(key: string, rootKey: string): ImpactItem[];
284
+ protected deleteEntityAnalysis(key: string, rootKey: string): ImpactItem[];
285
+ protected deletePropertyAnalysis(key: string): ImpactItem[];
286
+ protected deleteAssociationAnalysis(key: string): ImpactItem[];
287
+ protected kindToLabel(kind: ImpactKinds): string;
288
+ }
289
+ export {};
290
+ //# sourceMappingURL=ImpactAnalysis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImpactAnalysis.d.ts","sourceRoot":"","sources":["../../../src/modeling/ImpactAnalysis.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,gBAAgB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