@hamak/ui-store-impl 0.9.5 → 0.9.6
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.
|
@@ -29,36 +29,43 @@ export class DataUpdater {
|
|
|
29
29
|
*/
|
|
30
30
|
executeDelete(data, itinerary) {
|
|
31
31
|
if (itinerary === undefined) {
|
|
32
|
-
return;
|
|
32
|
+
return { deleted: false, reason: 'itinerary-not-provided' };
|
|
33
33
|
}
|
|
34
34
|
const { parent, value: step } = itinerary;
|
|
35
35
|
const parentNode = navigate(data, parent);
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
36
|
+
if (parentNode === undefined) {
|
|
37
|
+
return { deleted: false, reason: 'parent-not-found' };
|
|
38
|
+
}
|
|
39
|
+
if (isArray(parentNode)) {
|
|
40
|
+
let position;
|
|
41
|
+
if (step.type === 'position') {
|
|
42
|
+
position = step.position;
|
|
44
43
|
}
|
|
45
|
-
else if (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
// TODO log expected PropertyStep
|
|
53
|
-
}
|
|
44
|
+
else if (step.type === 'lookup') {
|
|
45
|
+
position = parentNode.findIndex(element => element !== undefined
|
|
46
|
+
&& element !== null
|
|
47
|
+
&& step.keys.every(({ propertyName, propertyValue }) => element[propertyName] === propertyValue));
|
|
54
48
|
}
|
|
55
49
|
else {
|
|
56
|
-
|
|
50
|
+
return { deleted: false, reason: 'array-step-not-supported' };
|
|
57
51
|
}
|
|
52
|
+
if (!Number.isInteger(position) || position < 0 || position >= parentNode.length) {
|
|
53
|
+
return { deleted: false, reason: 'target-not-found' };
|
|
54
|
+
}
|
|
55
|
+
parentNode.splice(position, 1);
|
|
56
|
+
return { deleted: true };
|
|
58
57
|
}
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
if (isObject(parentNode)) {
|
|
59
|
+
if (step.type !== 'property') {
|
|
60
|
+
return { deleted: false, reason: 'object-step-not-supported' };
|
|
61
|
+
}
|
|
62
|
+
if (!Object.prototype.hasOwnProperty.call(parentNode, step.propertyName)) {
|
|
63
|
+
return { deleted: false, reason: 'target-not-found' };
|
|
64
|
+
}
|
|
65
|
+
delete parentNode[step.propertyName];
|
|
66
|
+
return { deleted: true };
|
|
61
67
|
}
|
|
68
|
+
return { deleted: false, reason: 'parent-not-container' };
|
|
62
69
|
}
|
|
63
70
|
/**
|
|
64
71
|
* Set a value at the specified itinerary
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { Itinerary, StackElement } from '@hamak/shared-utils';
|
|
2
2
|
import { UnitaryStructureNodeCommand, BatchUpdateStructureNodeCommand } from '../commands/structure-commands.js';
|
|
3
|
+
export type DeleteFailureReason = 'itinerary-not-provided' | 'parent-not-found' | 'parent-not-container' | 'array-step-not-supported' | 'object-step-not-supported' | 'target-not-found';
|
|
4
|
+
export type DeleteResult = {
|
|
5
|
+
deleted: true;
|
|
6
|
+
} | {
|
|
7
|
+
deleted: false;
|
|
8
|
+
reason: DeleteFailureReason;
|
|
9
|
+
};
|
|
3
10
|
/**
|
|
4
11
|
* DataUpdater class handles operations on data structures using itineraries
|
|
5
12
|
*/
|
|
@@ -7,7 +14,7 @@ export declare class DataUpdater {
|
|
|
7
14
|
/**
|
|
8
15
|
* Delete a value at the specified itinerary
|
|
9
16
|
*/
|
|
10
|
-
executeDelete(data: any, itinerary: Itinerary | undefined):
|
|
17
|
+
executeDelete(data: any, itinerary: Itinerary | undefined): DeleteResult;
|
|
11
18
|
/**
|
|
12
19
|
* Set a value at the specified itinerary
|
|
13
20
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-updater.d.ts","sourceRoot":"","sources":["../../../src/fs/utils/data-updater.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,YAAY,EAKb,MA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B,EACxC,UAAU,EAAE,2BAA2B,GACtC,2BAA2B,GAAG,IAAI;IAqFrC;;;;OAIG;IACI,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,+BAA+B,GAAG,IAAI;CA4B/E"}
|
|
@@ -29,36 +29,43 @@ export class DataUpdater {
|
|
|
29
29
|
*/
|
|
30
30
|
executeDelete(data, itinerary) {
|
|
31
31
|
if (itinerary === undefined) {
|
|
32
|
-
return;
|
|
32
|
+
return { deleted: false, reason: 'itinerary-not-provided' };
|
|
33
33
|
}
|
|
34
34
|
const { parent, value: step } = itinerary;
|
|
35
35
|
const parentNode = navigate(data, parent);
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
36
|
+
if (parentNode === undefined) {
|
|
37
|
+
return { deleted: false, reason: 'parent-not-found' };
|
|
38
|
+
}
|
|
39
|
+
if (isArray(parentNode)) {
|
|
40
|
+
let position;
|
|
41
|
+
if (step.type === 'position') {
|
|
42
|
+
position = step.position;
|
|
44
43
|
}
|
|
45
|
-
else if (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
// TODO log expected PropertyStep
|
|
53
|
-
}
|
|
44
|
+
else if (step.type === 'lookup') {
|
|
45
|
+
position = parentNode.findIndex(element => element !== undefined
|
|
46
|
+
&& element !== null
|
|
47
|
+
&& step.keys.every(({ propertyName, propertyValue }) => element[propertyName] === propertyValue));
|
|
54
48
|
}
|
|
55
49
|
else {
|
|
56
|
-
|
|
50
|
+
return { deleted: false, reason: 'array-step-not-supported' };
|
|
57
51
|
}
|
|
52
|
+
if (!Number.isInteger(position) || position < 0 || position >= parentNode.length) {
|
|
53
|
+
return { deleted: false, reason: 'target-not-found' };
|
|
54
|
+
}
|
|
55
|
+
parentNode.splice(position, 1);
|
|
56
|
+
return { deleted: true };
|
|
58
57
|
}
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
if (isObject(parentNode)) {
|
|
59
|
+
if (step.type !== 'property') {
|
|
60
|
+
return { deleted: false, reason: 'object-step-not-supported' };
|
|
61
|
+
}
|
|
62
|
+
if (!Object.prototype.hasOwnProperty.call(parentNode, step.propertyName)) {
|
|
63
|
+
return { deleted: false, reason: 'target-not-found' };
|
|
64
|
+
}
|
|
65
|
+
delete parentNode[step.propertyName];
|
|
66
|
+
return { deleted: true };
|
|
61
67
|
}
|
|
68
|
+
return { deleted: false, reason: 'parent-not-container' };
|
|
62
69
|
}
|
|
63
70
|
/**
|
|
64
71
|
* Set a value at the specified itinerary
|