@cyberismo/data-handler 0.0.13 → 0.0.15
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/card-metadata-updater.js +1 -3
- package/dist/card-metadata-updater.js.map +1 -1
- package/dist/command-handler.js +13 -17
- package/dist/command-handler.js.map +1 -1
- package/dist/command-manager.d.ts +1 -1
- package/dist/command-manager.js +4 -3
- package/dist/command-manager.js.map +1 -1
- package/dist/commands/create.d.ts +3 -3
- package/dist/commands/create.js +20 -81
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/edit.d.ts +12 -25
- package/dist/commands/edit.js +25 -74
- package/dist/commands/edit.js.map +1 -1
- package/dist/commands/export.js +4 -17
- package/dist/commands/export.js.map +1 -1
- package/dist/commands/fetch.js +2 -1
- package/dist/commands/fetch.js.map +1 -1
- package/dist/commands/import.js +3 -5
- package/dist/commands/import.js.map +1 -1
- package/dist/commands/move.d.ts +1 -2
- package/dist/commands/move.js +108 -146
- package/dist/commands/move.js.map +1 -1
- package/dist/commands/remove.js +15 -49
- package/dist/commands/remove.js.map +1 -1
- package/dist/commands/rename.d.ts +1 -0
- package/dist/commands/rename.js +13 -7
- package/dist/commands/rename.js.map +1 -1
- package/dist/commands/show.d.ts +7 -25
- package/dist/commands/show.js +39 -113
- package/dist/commands/show.js.map +1 -1
- package/dist/commands/transition.js +27 -30
- package/dist/commands/transition.js.map +1 -1
- package/dist/commands/update.d.ts +5 -3
- package/dist/commands/update.js +19 -5
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/validate.d.ts +3 -3
- package/dist/commands/validate.js +20 -27
- package/dist/commands/validate.js.map +1 -1
- package/dist/containers/card-container.d.ts +87 -24
- package/dist/containers/card-container.js +183 -279
- package/dist/containers/card-container.js.map +1 -1
- package/dist/containers/project/calculation-engine.d.ts +6 -0
- package/dist/containers/project/calculation-engine.js +36 -29
- package/dist/containers/project/calculation-engine.js.map +1 -1
- package/dist/containers/project/card-cache.d.ts +146 -0
- package/dist/containers/project/card-cache.js +411 -0
- package/dist/containers/project/card-cache.js.map +1 -0
- package/dist/containers/project/resource-collector.d.ts +24 -1
- package/dist/containers/project/resource-collector.js +8 -1
- package/dist/containers/project/resource-collector.js.map +1 -1
- package/dist/containers/project.d.ts +119 -84
- package/dist/containers/project.js +423 -253
- package/dist/containers/project.js.map +1 -1
- package/dist/containers/template.d.ts +15 -31
- package/dist/containers/template.js +97 -104
- package/dist/containers/template.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/folder-content-interfaces.d.ts +12 -5
- package/dist/interfaces/folder-content-interfaces.js +5 -3
- package/dist/interfaces/folder-content-interfaces.js.map +1 -1
- package/dist/interfaces/macros.d.ts +1 -0
- package/dist/interfaces/macros.js +1 -1
- package/dist/interfaces/macros.js.map +1 -1
- package/dist/interfaces/project-interfaces.d.ts +16 -10
- package/dist/interfaces/project-interfaces.js +10 -8
- package/dist/interfaces/project-interfaces.js.map +1 -1
- package/dist/interfaces/resource-interfaces.d.ts +21 -22
- package/dist/interfaces/resource-interfaces.js +3 -0
- package/dist/interfaces/resource-interfaces.js.map +1 -1
- package/dist/macros/common.d.ts +10 -10
- package/dist/macros/createCards/index.d.ts +0 -13
- package/dist/macros/createCards/index.js.map +1 -1
- package/dist/macros/createCards/types.d.ts +44 -0
- package/dist/macros/createCards/types.js +15 -0
- package/dist/macros/createCards/types.js.map +1 -0
- package/dist/macros/graph/index.d.ts +2 -6
- package/dist/macros/graph/index.js +2 -2
- package/dist/macros/graph/index.js.map +1 -1
- package/dist/macros/graph/types.d.ts +23 -0
- package/dist/macros/graph/types.js +15 -0
- package/dist/macros/graph/types.js.map +1 -0
- package/dist/macros/image/index.d.ts +8 -16
- package/dist/macros/image/index.js +36 -33
- package/dist/macros/image/index.js.map +1 -1
- package/dist/macros/image/types.d.ts +38 -0
- package/dist/macros/image/types.js +15 -0
- package/dist/macros/image/types.js.map +1 -0
- package/dist/macros/include/index.d.ts +1 -6
- package/dist/macros/include/index.js +4 -7
- package/dist/macros/include/index.js.map +1 -1
- package/dist/macros/include/types.d.ts +31 -0
- package/dist/macros/include/types.js +15 -0
- package/dist/macros/include/types.js.map +1 -0
- package/dist/macros/percentage/index.d.ts +0 -6
- package/dist/macros/percentage/index.js.map +1 -1
- package/dist/macros/percentage/types.d.ts +31 -0
- package/dist/macros/percentage/types.js +15 -0
- package/dist/macros/percentage/types.js.map +1 -0
- package/dist/macros/report/index.d.ts +0 -3
- package/dist/macros/report/index.js.map +1 -1
- package/dist/macros/report/types.d.ts +19 -0
- package/dist/macros/report/types.js +15 -0
- package/dist/macros/report/types.js.map +1 -0
- package/dist/macros/scoreCard/index.d.ts +0 -6
- package/dist/macros/scoreCard/index.js.map +1 -1
- package/dist/macros/scoreCard/types.d.ts +31 -0
- package/dist/macros/scoreCard/types.js +15 -0
- package/dist/macros/scoreCard/types.js.map +1 -0
- package/dist/macros/types.d.ts +25 -0
- package/dist/macros/types.js +2 -0
- package/dist/macros/types.js.map +1 -0
- package/dist/macros/vega/index.d.ts +0 -4
- package/dist/macros/vega/index.js.map +1 -1
- package/dist/macros/vega/types.d.ts +20 -0
- package/dist/macros/vega/types.js +2 -0
- package/dist/macros/vega/types.js.map +1 -0
- package/dist/macros/vegalite/index.d.ts +0 -4
- package/dist/macros/vegalite/index.js.map +1 -1
- package/dist/macros/vegalite/types.d.ts +20 -0
- package/dist/macros/vegalite/types.js +15 -0
- package/dist/macros/vegalite/types.js.map +1 -0
- package/dist/macros/xref/index.d.ts +0 -3
- package/dist/macros/xref/index.js +5 -14
- package/dist/macros/xref/index.js.map +1 -1
- package/dist/macros/xref/types.d.ts +19 -0
- package/dist/macros/xref/types.js +15 -0
- package/dist/macros/xref/types.js.map +1 -0
- package/dist/module-manager.js +4 -4
- package/dist/module-manager.js.map +1 -1
- package/dist/project-settings.js.map +1 -1
- package/dist/resources/calculation-resource.d.ts +43 -0
- package/dist/resources/calculation-resource.js +75 -0
- package/dist/resources/calculation-resource.js.map +1 -0
- package/dist/resources/card-type-resource.d.ts +4 -21
- package/dist/resources/card-type-resource.js +13 -44
- package/dist/resources/card-type-resource.js.map +1 -1
- package/dist/resources/create-defaults.d.ts +13 -6
- package/dist/resources/create-defaults.js +19 -5
- package/dist/resources/create-defaults.js.map +1 -1
- package/dist/resources/field-type-resource.d.ts +4 -21
- package/dist/resources/field-type-resource.js +14 -38
- package/dist/resources/field-type-resource.js.map +1 -1
- package/dist/resources/file-resource.d.ts +12 -29
- package/dist/resources/file-resource.js +19 -287
- package/dist/resources/file-resource.js.map +1 -1
- package/dist/resources/folder-resource.d.ts +32 -51
- package/dist/resources/folder-resource.js +68 -96
- package/dist/resources/folder-resource.js.map +1 -1
- package/dist/resources/graph-model-resource.d.ts +5 -33
- package/dist/resources/graph-model-resource.js +8 -61
- package/dist/resources/graph-model-resource.js.map +1 -1
- package/dist/resources/graph-view-resource.d.ts +5 -28
- package/dist/resources/graph-view-resource.js +6 -45
- package/dist/resources/graph-view-resource.js.map +1 -1
- package/dist/resources/link-type-resource.d.ts +4 -21
- package/dist/resources/link-type-resource.js +6 -31
- package/dist/resources/link-type-resource.js.map +1 -1
- package/dist/resources/report-resource.d.ts +5 -17
- package/dist/resources/report-resource.js +6 -44
- package/dist/resources/report-resource.js.map +1 -1
- package/dist/resources/resource-object.d.ts +58 -23
- package/dist/resources/resource-object.js +307 -26
- package/dist/resources/resource-object.js.map +1 -1
- package/dist/resources/template-resource.d.ts +4 -15
- package/dist/resources/template-resource.js +10 -25
- package/dist/resources/template-resource.js.map +1 -1
- package/dist/resources/workflow-resource.d.ts +4 -23
- package/dist/resources/workflow-resource.js +12 -38
- package/dist/resources/workflow-resource.js.map +1 -1
- package/dist/utils/card-utils.d.ts +69 -19
- package/dist/utils/card-utils.js +179 -30
- package/dist/utils/card-utils.js.map +1 -1
- package/dist/utils/clingo-facts.js +11 -3
- package/dist/utils/clingo-facts.js.map +1 -1
- package/dist/utils/clingo-parser.js +1 -1
- package/dist/utils/clingo-parser.js.map +1 -1
- package/dist/utils/constants.d.ts +2 -0
- package/dist/utils/constants.js +5 -0
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/csv.js +1 -1
- package/dist/utils/csv.js.map +1 -1
- package/dist/utils/error-utils.d.ts +34 -0
- package/dist/utils/error-utils.js +56 -0
- package/dist/utils/error-utils.js.map +1 -0
- package/dist/utils/log-utils.d.ts +0 -27
- package/dist/utils/log-utils.js +0 -58
- package/dist/utils/log-utils.js.map +1 -1
- package/dist/utils/user-preferences.js +6 -3
- package/dist/utils/user-preferences.js.map +1 -1
- package/package.json +5 -5
- package/src/card-metadata-updater.ts +3 -5
- package/src/command-handler.ts +14 -19
- package/src/command-manager.ts +4 -3
- package/src/commands/create.ts +28 -112
- package/src/commands/edit.ts +27 -118
- package/src/commands/export.ts +8 -29
- package/src/commands/fetch.ts +2 -1
- package/src/commands/import.ts +4 -6
- package/src/commands/move.ts +144 -179
- package/src/commands/remove.ts +12 -54
- package/src/commands/rename.ts +22 -7
- package/src/commands/show.ts +51 -156
- package/src/commands/transition.ts +30 -33
- package/src/commands/update.ts +27 -9
- package/src/commands/validate.ts +22 -37
- package/src/containers/card-container.ts +200 -360
- package/src/containers/project/calculation-engine.ts +43 -33
- package/src/containers/project/card-cache.ts +497 -0
- package/src/containers/project/resource-collector.ts +9 -1
- package/src/containers/project.ts +533 -328
- package/src/containers/template.ts +109 -127
- package/src/index.ts +1 -0
- package/src/interfaces/folder-content-interfaces.ts +23 -5
- package/src/interfaces/macros.ts +2 -0
- package/src/interfaces/project-interfaces.ts +19 -10
- package/src/interfaces/resource-interfaces.ts +22 -24
- package/src/macros/createCards/index.ts +1 -12
- package/src/macros/createCards/types.ts +46 -0
- package/src/macros/graph/index.ts +3 -7
- package/src/macros/graph/types.ts +24 -0
- package/src/macros/image/index.ts +50 -61
- package/src/macros/image/types.ts +39 -0
- package/src/macros/include/index.ts +6 -15
- package/src/macros/include/types.ts +32 -0
- package/src/macros/percentage/index.ts +1 -7
- package/src/macros/percentage/types.ts +32 -0
- package/src/macros/report/index.ts +1 -4
- package/src/macros/report/types.ts +20 -0
- package/src/macros/scoreCard/index.ts +1 -7
- package/src/macros/scoreCard/types.ts +32 -0
- package/src/macros/types.ts +48 -0
- package/src/macros/vega/index.ts +1 -4
- package/src/macros/vega/types.ts +21 -0
- package/src/macros/vegalite/index.ts +1 -4
- package/src/macros/vegalite/types.ts +22 -0
- package/src/macros/xref/index.ts +6 -20
- package/src/macros/xref/types.ts +20 -0
- package/src/module-manager.ts +5 -5
- package/src/project-settings.ts +1 -1
- package/src/resources/calculation-resource.ts +101 -0
- package/src/resources/card-type-resource.ts +24 -59
- package/src/resources/create-defaults.ts +21 -5
- package/src/resources/field-type-resource.ts +22 -51
- package/src/resources/file-resource.ts +27 -403
- package/src/resources/folder-resource.ts +99 -125
- package/src/resources/graph-model-resource.ts +17 -74
- package/src/resources/graph-view-resource.ts +14 -54
- package/src/resources/link-type-resource.ts +13 -40
- package/src/resources/report-resource.ts +17 -57
- package/src/resources/resource-object.ts +454 -39
- package/src/resources/template-resource.ts +16 -29
- package/src/resources/workflow-resource.ts +26 -50
- package/src/utils/card-utils.ts +217 -31
- package/src/utils/clingo-facts.ts +13 -3
- package/src/utils/clingo-parser.ts +1 -1
- package/src/utils/constants.ts +7 -0
- package/src/utils/csv.ts +1 -1
- package/src/utils/error-utils.ts +62 -0
- package/src/utils/log-utils.ts +0 -68
- package/src/utils/user-preferences.ts +7 -3
package/src/commands/move.ts
CHANGED
|
@@ -12,15 +12,12 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
// node
|
|
15
|
-
import { join
|
|
15
|
+
import { join } from 'node:path';
|
|
16
16
|
|
|
17
17
|
import { ActionGuard } from '../permissions/action-guard.js';
|
|
18
18
|
import { copyDir, deleteDir } from '../utils/file-utils.js';
|
|
19
|
-
import type {
|
|
20
|
-
|
|
21
|
-
FetchCardDetails,
|
|
22
|
-
} from '../interfaces/project-interfaces.js';
|
|
23
|
-
import { type Project, ResourcesFrom } from '../containers/project.js';
|
|
19
|
+
import type { Card } from '../interfaces/project-interfaces.js';
|
|
20
|
+
import type { Project } from '../containers/project.js';
|
|
24
21
|
import {
|
|
25
22
|
EMPTY_RANK,
|
|
26
23
|
FIRST_RANK,
|
|
@@ -29,72 +26,47 @@ import {
|
|
|
29
26
|
rebalanceRanks,
|
|
30
27
|
sortItems,
|
|
31
28
|
} from '../utils/lexorank.js';
|
|
32
|
-
import {
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
import {
|
|
30
|
+
cardPathParts,
|
|
31
|
+
isModuleCard,
|
|
32
|
+
isTemplateCard,
|
|
33
|
+
} from '../utils/card-utils.js';
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
const ROOT: string = 'root';
|
|
35
|
+
import { ROOT } from '../utils/constants.js';
|
|
38
36
|
|
|
39
37
|
export class Move {
|
|
40
38
|
constructor(private project: Project) {}
|
|
41
39
|
|
|
42
|
-
// Fetches a card (either template or project card).
|
|
43
|
-
private async getCard(cardKey: string, options: FetchCardDetails) {
|
|
44
|
-
let card: Card | undefined;
|
|
45
|
-
const templateCard = await this.project.isTemplateCard(cardKey);
|
|
46
|
-
if (templateCard) {
|
|
47
|
-
card = (await this.project.allTemplateCards(options)).find(
|
|
48
|
-
(card) => card.key === cardKey,
|
|
49
|
-
);
|
|
50
|
-
} else {
|
|
51
|
-
card = await this.project.findSpecificCard(cardKey, options);
|
|
52
|
-
}
|
|
53
|
-
if (!card) {
|
|
54
|
-
throw new Error('Card was not found from the project');
|
|
55
|
-
}
|
|
56
|
-
return card;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
40
|
// Returns children of a parent card or root cards
|
|
60
|
-
private
|
|
41
|
+
private getSiblings(card: Card): Card[] {
|
|
61
42
|
const parentCardKey = card.parent || ROOT;
|
|
62
43
|
|
|
63
44
|
// since we don't know if 'root' is templateRoot or cardRoot, we need to check the card
|
|
64
45
|
if (parentCardKey === ROOT) {
|
|
65
46
|
if (isTemplateCard(card)) {
|
|
66
|
-
|
|
67
|
-
if (!template) {
|
|
68
|
-
throw new Error(
|
|
69
|
-
`Cannot find template for the template card '${card.key}'`,
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
if (card?.path.includes(`${sep}modules${sep}`)) {
|
|
47
|
+
if (isModuleCard(card)) {
|
|
73
48
|
throw new Error(`Cannot rank module cards`);
|
|
74
49
|
}
|
|
75
|
-
|
|
50
|
+
const { template } = cardPathParts(
|
|
51
|
+
this.project.projectPrefix,
|
|
52
|
+
card.path,
|
|
53
|
+
);
|
|
54
|
+
return this.project.templateCards(template);
|
|
76
55
|
}
|
|
77
56
|
}
|
|
78
57
|
|
|
79
58
|
let parentCard;
|
|
80
59
|
if (parentCardKey !== ROOT) {
|
|
81
|
-
parentCard =
|
|
82
|
-
|
|
83
|
-
metadata: true,
|
|
84
|
-
});
|
|
85
|
-
if (!parentCard) {
|
|
86
|
-
throw new Error(`Card ${parentCardKey} not found from project`);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (parentCard) {
|
|
91
|
-
return parentCard.children || [];
|
|
60
|
+
parentCard = this.project.findCard(parentCardKey);
|
|
61
|
+
return this.project.cardKeysToCards(parentCard.children);
|
|
92
62
|
}
|
|
93
63
|
|
|
94
|
-
return this.project
|
|
64
|
+
return this.project
|
|
65
|
+
.showProjectCards()
|
|
66
|
+
.filter((item) => item.parent === 'root' || item.parent === '');
|
|
95
67
|
}
|
|
96
68
|
|
|
97
|
-
//
|
|
69
|
+
// Rebalances cards
|
|
98
70
|
private async rebalanceCards(cards: Card[]) {
|
|
99
71
|
const ranks = rebalanceRanks(cards.length);
|
|
100
72
|
|
|
@@ -116,7 +88,9 @@ export class Move {
|
|
|
116
88
|
const card = cards[i];
|
|
117
89
|
await this.project.updateCardMetadataKey(card.key, 'rank', ranks[i]);
|
|
118
90
|
if (card.children && card.children.length > 0) {
|
|
119
|
-
await this.rebalanceProjectRecursively(
|
|
91
|
+
await this.rebalanceProjectRecursively(
|
|
92
|
+
this.project.cardKeysToCards(card.children),
|
|
93
|
+
);
|
|
120
94
|
}
|
|
121
95
|
}
|
|
122
96
|
}
|
|
@@ -133,55 +107,55 @@ export class Move {
|
|
|
133
107
|
if (source === destination) {
|
|
134
108
|
throw new Error(`Card cannot be moved to itself`);
|
|
135
109
|
}
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (!sourceCard) {
|
|
152
|
-
throw new Error(`Card ${source} not found from project`);
|
|
153
|
-
}
|
|
154
|
-
if (!destinationCard) {
|
|
155
|
-
throw new Error(`Card ${destination} not found from project`);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (destinationCard.path.includes(source)) {
|
|
159
|
-
throw new Error(`Card cannot be moved to inside itself`);
|
|
110
|
+
const movingToRoot = destination === ROOT;
|
|
111
|
+
const sourceCard = this.project.findCard(source);
|
|
112
|
+
const destinationCard = !movingToRoot
|
|
113
|
+
? this.project.findCard(destination)
|
|
114
|
+
: undefined;
|
|
115
|
+
|
|
116
|
+
// Prevent moving card to inside its descendants
|
|
117
|
+
if (destinationCard) {
|
|
118
|
+
const { parents } = cardPathParts(
|
|
119
|
+
this.project.projectPrefix,
|
|
120
|
+
destinationCard.path,
|
|
121
|
+
);
|
|
122
|
+
if (parents.includes(source)) {
|
|
123
|
+
throw new Error(`Card cannot be moved to inside itself`);
|
|
124
|
+
}
|
|
160
125
|
}
|
|
161
126
|
|
|
162
127
|
// Imported templates cannot be modified.
|
|
163
128
|
if (
|
|
164
|
-
destinationCard
|
|
165
|
-
sourceCard
|
|
129
|
+
(destinationCard && isModuleCard(destinationCard)) ||
|
|
130
|
+
isModuleCard(sourceCard)
|
|
166
131
|
) {
|
|
167
132
|
throw new Error(`Cannot modify imported module templates`);
|
|
168
133
|
}
|
|
169
134
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
135
|
+
// Special handling for moving to root
|
|
136
|
+
if (movingToRoot) {
|
|
137
|
+
if (isTemplateCard(sourceCard)) {
|
|
138
|
+
throw new Error(`Template cards cannot be moved to project root`);
|
|
139
|
+
}
|
|
140
|
+
} else {
|
|
141
|
+
const bothTemplateCards =
|
|
142
|
+
isTemplateCard(sourceCard) &&
|
|
143
|
+
destinationCard &&
|
|
144
|
+
isTemplateCard(destinationCard);
|
|
145
|
+
const bothProjectCards =
|
|
146
|
+
this.project.hasProjectCard(sourceCard.key) &&
|
|
147
|
+
destinationCard &&
|
|
148
|
+
this.project.hasProjectCard(destinationCard.key);
|
|
149
|
+
if (!(bothTemplateCards || bothProjectCards)) {
|
|
150
|
+
throw new Error(
|
|
151
|
+
`Cards cannot be moved from project to template or vice versa`,
|
|
152
|
+
);
|
|
153
|
+
}
|
|
179
154
|
}
|
|
180
155
|
|
|
181
|
-
const destinationPath =
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
: join(destinationCard.path, 'c', sourceCard.key);
|
|
156
|
+
const destinationPath = movingToRoot
|
|
157
|
+
? join(this.project.paths.cardRootFolder, sourceCard.key)
|
|
158
|
+
: join(destinationCard!.path, 'c', sourceCard.key);
|
|
185
159
|
|
|
186
160
|
// if the card is already in the destination, do nothing
|
|
187
161
|
if (sourceCard.path === destinationPath) {
|
|
@@ -192,20 +166,14 @@ export class Move {
|
|
|
192
166
|
const actionGuard = new ActionGuard(this.project.calculationEngine);
|
|
193
167
|
await actionGuard.checkPermission('move', source);
|
|
194
168
|
|
|
195
|
-
//
|
|
169
|
+
// re-rank the card in the new location
|
|
196
170
|
// it will be the last one in the new location
|
|
197
171
|
let children;
|
|
198
|
-
if (
|
|
199
|
-
const parent =
|
|
200
|
-
|
|
201
|
-
metadata: true,
|
|
202
|
-
});
|
|
203
|
-
if (!parent) {
|
|
204
|
-
throw new Error(`Parent card ${destination} not found from project`);
|
|
205
|
-
}
|
|
206
|
-
children = parent.children;
|
|
172
|
+
if (!movingToRoot) {
|
|
173
|
+
const parent = this.project.findCard(destination);
|
|
174
|
+
children = this.project.cardKeysToCards(parent.children);
|
|
207
175
|
} else {
|
|
208
|
-
children =
|
|
176
|
+
children = this.project.showProjectCards();
|
|
209
177
|
}
|
|
210
178
|
|
|
211
179
|
if (!children) {
|
|
@@ -219,9 +187,51 @@ export class Move {
|
|
|
219
187
|
lastChild && lastChild.metadata
|
|
220
188
|
? getRankAfter(lastChild.metadata.rank)
|
|
221
189
|
: FIRST_RANK;
|
|
222
|
-
|
|
190
|
+
|
|
191
|
+
// First do the file operations, then update metadata
|
|
223
192
|
await copyDir(sourceCard.path, destinationPath);
|
|
224
193
|
await deleteDir(sourceCard.path);
|
|
194
|
+
|
|
195
|
+
// Update card with new path, parent, and rank
|
|
196
|
+
sourceCard.path = destinationPath!;
|
|
197
|
+
sourceCard.parent = movingToRoot ? ROOT : destination;
|
|
198
|
+
if (sourceCard.metadata) {
|
|
199
|
+
sourceCard.metadata.rank = rank;
|
|
200
|
+
sourceCard.metadata.parent = movingToRoot ? ROOT : destination;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Handle cache update and persistence
|
|
204
|
+
await this.project.updateCard(sourceCard);
|
|
205
|
+
const updatedCard: Card = {
|
|
206
|
+
...sourceCard,
|
|
207
|
+
path: destinationPath,
|
|
208
|
+
parent: movingToRoot ? ROOT : destination,
|
|
209
|
+
metadata: sourceCard.metadata
|
|
210
|
+
? {
|
|
211
|
+
...sourceCard.metadata,
|
|
212
|
+
rank: rank,
|
|
213
|
+
}
|
|
214
|
+
: undefined,
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// Fetch old parent
|
|
218
|
+
const oldParent = sourceCard.parent;
|
|
219
|
+
let oldParentCard: Card | undefined;
|
|
220
|
+
if (oldParent && oldParent !== ROOT) {
|
|
221
|
+
oldParentCard = this.project.findCard(oldParent);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
let newParentCard: Card | undefined;
|
|
225
|
+
if (!movingToRoot) {
|
|
226
|
+
newParentCard = this.project.findCard(destination);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Finally, update the project
|
|
230
|
+
await this.project.handleCardMoved(
|
|
231
|
+
updatedCard,
|
|
232
|
+
newParentCard,
|
|
233
|
+
oldParentCard,
|
|
234
|
+
);
|
|
225
235
|
}
|
|
226
236
|
|
|
227
237
|
/**
|
|
@@ -238,17 +248,13 @@ export class Move {
|
|
|
238
248
|
return;
|
|
239
249
|
}
|
|
240
250
|
|
|
241
|
-
const card =
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
if (!card || !card.parent) {
|
|
247
|
-
throw new Error(`Card ${cardKey} not found from project`);
|
|
251
|
+
const card = this.project.findCard(cardKey);
|
|
252
|
+
if (!card.parent) {
|
|
253
|
+
throw new Error(`Parent card ${cardKey} not found from project`);
|
|
248
254
|
}
|
|
249
255
|
|
|
250
256
|
const children = sortItems(
|
|
251
|
-
|
|
257
|
+
this.getSiblings(card),
|
|
252
258
|
(item) => item.metadata?.rank || EMPTY_RANK,
|
|
253
259
|
);
|
|
254
260
|
|
|
@@ -268,29 +274,15 @@ export class Move {
|
|
|
268
274
|
* @param beforeCardKey Card key after which the card will be ranked
|
|
269
275
|
*/
|
|
270
276
|
public async rankCard(cardKey: string, beforeCardKey: string) {
|
|
271
|
-
const card =
|
|
272
|
-
|
|
273
|
-
parent: true,
|
|
274
|
-
});
|
|
275
|
-
if (!card) {
|
|
276
|
-
throw new Error(`Card ${cardKey} not found from project`);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
const beforeCard = await this.project.findSpecificCard(beforeCardKey, {
|
|
280
|
-
metadata: true,
|
|
281
|
-
parent: true,
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
if (!beforeCard) {
|
|
285
|
-
throw new Error(`Card ${beforeCardKey} not found from project`);
|
|
286
|
-
}
|
|
277
|
+
const card = this.project.findCard(cardKey);
|
|
278
|
+
const beforeCard = this.project.findCard(beforeCardKey);
|
|
287
279
|
|
|
288
280
|
if (beforeCard.parent !== card.parent) {
|
|
289
281
|
throw new Error(`Cards must be from the same parent`);
|
|
290
282
|
}
|
|
291
283
|
|
|
292
284
|
const children = sortItems(
|
|
293
|
-
|
|
285
|
+
this.getSiblings(beforeCard),
|
|
294
286
|
(item) => item.metadata?.rank || EMPTY_RANK,
|
|
295
287
|
);
|
|
296
288
|
|
|
@@ -308,11 +300,8 @@ export class Move {
|
|
|
308
300
|
);
|
|
309
301
|
}
|
|
310
302
|
|
|
311
|
-
if (
|
|
312
|
-
|
|
313
|
-
children[beforeCardIndex + 1]?.key === cardKey
|
|
314
|
-
) {
|
|
315
|
-
throw new Error(`Card ${cardKey} is already in the correct position`);
|
|
303
|
+
if (children[beforeCardIndex].key === cardKey) {
|
|
304
|
+
throw new Error(`Card cannot be ranked after itself`);
|
|
316
305
|
}
|
|
317
306
|
|
|
318
307
|
if (beforeCardIndex === children.length - 1) {
|
|
@@ -338,13 +327,9 @@ export class Move {
|
|
|
338
327
|
* @param cardKey card key
|
|
339
328
|
*/
|
|
340
329
|
public async rankFirst(cardKey: string) {
|
|
341
|
-
const card =
|
|
342
|
-
metadata: true,
|
|
343
|
-
parent: true,
|
|
344
|
-
});
|
|
345
|
-
|
|
330
|
+
const card = this.project.findCard(cardKey);
|
|
346
331
|
const children = sortItems(
|
|
347
|
-
|
|
332
|
+
this.getSiblings(card),
|
|
348
333
|
(item) => item.metadata?.rank || EMPTY_RANK,
|
|
349
334
|
);
|
|
350
335
|
|
|
@@ -387,14 +372,13 @@ export class Move {
|
|
|
387
372
|
* @param parentCardKey parent card key
|
|
388
373
|
*/
|
|
389
374
|
public async rebalanceChildren(parentCardKey: string) {
|
|
390
|
-
const parentCard =
|
|
391
|
-
children: true,
|
|
392
|
-
metadata: true,
|
|
393
|
-
});
|
|
375
|
+
const parentCard = this.project.findCard(parentCardKey);
|
|
394
376
|
if (!parentCard || !parentCard.children) {
|
|
395
377
|
throw new Error(`Card ${parentCardKey} not found from project`);
|
|
396
378
|
}
|
|
397
|
-
await this.rebalanceCards(
|
|
379
|
+
await this.rebalanceCards(
|
|
380
|
+
this.project.cardKeysToCards(parentCard.children),
|
|
381
|
+
);
|
|
398
382
|
}
|
|
399
383
|
|
|
400
384
|
/**
|
|
@@ -402,47 +386,28 @@ export class Move {
|
|
|
402
386
|
* Can be used even if the ranks do not exist
|
|
403
387
|
*/
|
|
404
388
|
public async rebalanceProject() {
|
|
405
|
-
const cards =
|
|
389
|
+
const cards = this.project.showProjectCards();
|
|
406
390
|
|
|
407
391
|
await this.rebalanceProjectRecursively(cards);
|
|
408
392
|
|
|
409
|
-
|
|
410
|
-
const
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
resourceName(template.name),
|
|
415
|
-
);
|
|
416
|
-
const templateObject = templateResource.templateObject();
|
|
417
|
-
|
|
418
|
-
if (!templateObject) {
|
|
419
|
-
throw new Error(`Template '${template.name}' not found`);
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
const templateCards = await templateObject.cards('', {
|
|
423
|
-
parent: true,
|
|
424
|
-
metadata: true,
|
|
425
|
-
});
|
|
426
|
-
|
|
427
|
-
const cardGroups = templateCards.reduce(
|
|
428
|
-
(result, card) => {
|
|
429
|
-
// template card root cards have a parent(the template itself) so this shouldn't happen
|
|
430
|
-
if (!card.parent) {
|
|
431
|
-
return result;
|
|
432
|
-
}
|
|
433
|
-
// if the parent does not exist yet in the result, we create it
|
|
434
|
-
if (!result[card.parent]) {
|
|
435
|
-
result[card.parent] = [];
|
|
436
|
-
}
|
|
437
|
-
result[card.parent].push(card);
|
|
393
|
+
const templateCards = this.project.allTemplateCards();
|
|
394
|
+
const cardGroups = templateCards.reduce(
|
|
395
|
+
(result, card) => {
|
|
396
|
+
// template card root cards always have a parent(, thus this shouldn't happen
|
|
397
|
+
if (!card.parent) {
|
|
438
398
|
return result;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
|
|
399
|
+
}
|
|
400
|
+
if (!result[card.parent]) {
|
|
401
|
+
result[card.parent] = [];
|
|
402
|
+
}
|
|
403
|
+
result[card.parent].push(card);
|
|
404
|
+
return result;
|
|
405
|
+
},
|
|
406
|
+
{} as Record<string, Card[]>,
|
|
407
|
+
);
|
|
442
408
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
}
|
|
409
|
+
for (const [, cards] of Object.entries(cardGroups)) {
|
|
410
|
+
await this.rebalanceCards(cards);
|
|
446
411
|
}
|
|
447
412
|
}
|
|
448
413
|
}
|
package/src/commands/remove.ts
CHANGED
|
@@ -11,18 +11,13 @@
|
|
|
11
11
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
// node
|
|
15
|
-
import { join, sep } from 'node:path';
|
|
16
|
-
|
|
17
14
|
import { ActionGuard } from '../permissions/action-guard.js';
|
|
18
|
-
import {
|
|
15
|
+
import { isModuleCard } from '../utils/card-utils.js';
|
|
19
16
|
import { ModuleManager } from '../module-manager.js';
|
|
20
17
|
import { Project } from '../containers/project.js';
|
|
21
18
|
import type { RemovableResourceTypes } from '../interfaces/project-interfaces.js';
|
|
22
19
|
import { resourceName } from '../utils/resource-utils.js';
|
|
23
20
|
|
|
24
|
-
const MODULES_PATH = `${sep}modules${sep}`;
|
|
25
|
-
|
|
26
21
|
/**
|
|
27
22
|
* Remove command.
|
|
28
23
|
*/
|
|
@@ -35,6 +30,7 @@ export class Remove {
|
|
|
35
30
|
// True, if resource is a project resource
|
|
36
31
|
private projectResource(type: RemovableResourceTypes): boolean {
|
|
37
32
|
return (
|
|
33
|
+
type === 'calculation' ||
|
|
38
34
|
type === 'cardType' ||
|
|
39
35
|
type === 'fieldType' ||
|
|
40
36
|
type === 'graphModel' ||
|
|
@@ -52,45 +48,26 @@ export class Remove {
|
|
|
52
48
|
throw new Error(`Attachment filename required`);
|
|
53
49
|
}
|
|
54
50
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// Imported templates cannot be modified.
|
|
58
|
-
if (attachmentFolder.includes(MODULES_PATH)) {
|
|
59
|
-
throw new Error(`Cannot modify imported module`);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Attachment's reside in 'a' folders.
|
|
63
|
-
const success = await deleteFile(join(attachmentFolder, attachment));
|
|
64
|
-
if (!success) {
|
|
65
|
-
throw new Error('No such file');
|
|
66
|
-
}
|
|
51
|
+
return this.project.removeCardAttachment(cardKey, attachment);
|
|
67
52
|
}
|
|
68
53
|
|
|
69
54
|
// Removes card from project or template
|
|
70
55
|
private async removeCard(cardKey: string) {
|
|
71
|
-
const
|
|
72
|
-
if (!cardFolder) {
|
|
73
|
-
throw new Error(`Card '${cardKey}' not found`);
|
|
74
|
-
}
|
|
56
|
+
const card = this.project.findCard(cardKey);
|
|
75
57
|
|
|
76
58
|
// Imported templates cannot be modified.
|
|
77
|
-
if (
|
|
59
|
+
if (isModuleCard(card)) {
|
|
78
60
|
throw new Error(`Cannot modify imported module`);
|
|
79
61
|
}
|
|
80
62
|
|
|
81
63
|
// Make sure card can be removed if it's a project card
|
|
82
|
-
if (
|
|
64
|
+
if (this.project.hasProjectCard(cardKey)) {
|
|
83
65
|
const actionGuard = new ActionGuard(this.project.calculationEngine);
|
|
84
66
|
await actionGuard.checkPermission('delete', cardKey);
|
|
85
67
|
}
|
|
86
68
|
|
|
87
69
|
// If card is destination of a link, remove the link.
|
|
88
|
-
const allCards =
|
|
89
|
-
this.project.paths.cardRootFolder,
|
|
90
|
-
{
|
|
91
|
-
metadata: true,
|
|
92
|
-
},
|
|
93
|
-
);
|
|
70
|
+
const allCards = this.project.cards(this.project.paths.cardRootFolder);
|
|
94
71
|
const promiseContainer: Promise<void>[] = [];
|
|
95
72
|
|
|
96
73
|
for (const item of allCards) {
|
|
@@ -104,27 +81,14 @@ export class Remove {
|
|
|
104
81
|
|
|
105
82
|
await Promise.all(promiseContainer);
|
|
106
83
|
|
|
107
|
-
// Calculations need to be updated before card is removed.
|
|
108
|
-
const card = await this.project.findSpecificCard(cardKey, {
|
|
109
|
-
metadata: true,
|
|
110
|
-
children: true,
|
|
111
|
-
content: false,
|
|
112
|
-
parent: false,
|
|
113
|
-
});
|
|
114
|
-
await deleteDir(cardFolder);
|
|
115
84
|
if (card) {
|
|
116
|
-
await this.project.
|
|
85
|
+
await this.project.handleCardDeleted(card);
|
|
117
86
|
}
|
|
118
87
|
}
|
|
119
88
|
|
|
120
89
|
// removes label from project
|
|
121
90
|
private async removeLabel(cardKey: string, label: string) {
|
|
122
|
-
const card =
|
|
123
|
-
metadata: true,
|
|
124
|
-
});
|
|
125
|
-
if (!card) {
|
|
126
|
-
throw new Error(`Card '${cardKey}' does not exist in the project`);
|
|
127
|
-
}
|
|
91
|
+
const card = this.project.findCard(cardKey);
|
|
128
92
|
let labels = card.metadata?.labels ?? [];
|
|
129
93
|
|
|
130
94
|
if (!label && labels.length !== 1) {
|
|
@@ -151,13 +115,7 @@ export class Remove {
|
|
|
151
115
|
linkType?: string,
|
|
152
116
|
linkDescription?: string,
|
|
153
117
|
) {
|
|
154
|
-
const sourceCard =
|
|
155
|
-
metadata: true,
|
|
156
|
-
});
|
|
157
|
-
if (!sourceCard) {
|
|
158
|
-
throw new Error(`Card '${sourceCardKey}' not found`);
|
|
159
|
-
}
|
|
160
|
-
|
|
118
|
+
const sourceCard = this.project.findCard(sourceCardKey);
|
|
161
119
|
const link = sourceCard.metadata?.links.find(
|
|
162
120
|
(l) =>
|
|
163
121
|
l.cardKey === destinationCardKey &&
|
|
@@ -229,12 +187,12 @@ export class Remove {
|
|
|
229
187
|
if (type === 'attachment')
|
|
230
188
|
return this.removeAttachment(targetName, rest[0]);
|
|
231
189
|
else if (type === 'card') return this.removeCard(targetName);
|
|
190
|
+
else if (type === 'hub') return this.removeHubLocation(targetName);
|
|
191
|
+
else if (type === 'label') return this.removeLabel(targetName, rest[0]);
|
|
232
192
|
else if (type === 'link')
|
|
233
193
|
return this.removeLink(targetName, rest[0], rest[1], rest.at(2));
|
|
234
194
|
else if (type === 'module')
|
|
235
195
|
return this.moduleManager.removeModule(targetName);
|
|
236
|
-
else if (type === 'label') return this.removeLabel(targetName, rest[0]);
|
|
237
|
-
else if (type === 'hub') return this.removeHubLocation(targetName);
|
|
238
196
|
}
|
|
239
197
|
throw new Error(`Unknown resource type '${type}'`);
|
|
240
198
|
}
|
package/src/commands/rename.ts
CHANGED
|
@@ -22,6 +22,7 @@ import { type Project, ResourcesFrom } from '../containers/project.js';
|
|
|
22
22
|
import { resourceName } from '../utils/resource-utils.js';
|
|
23
23
|
import { Template } from '../containers/template.js';
|
|
24
24
|
|
|
25
|
+
import { CalculationResource } from '../resources/calculation-resource.js';
|
|
25
26
|
import { CardTypeResource } from '../resources/card-type-resource.js';
|
|
26
27
|
import { FieldTypeResource } from '../resources/field-type-resource.js';
|
|
27
28
|
import { GraphModelResource } from '../resources/graph-model-resource.js';
|
|
@@ -192,6 +193,17 @@ export class Rename {
|
|
|
192
193
|
return cardType.rename(resourceName(this.updateResourceName(cardTypeName)));
|
|
193
194
|
}
|
|
194
195
|
|
|
196
|
+
// Rename calculations.
|
|
197
|
+
private async updateCalculation(calculationName: string) {
|
|
198
|
+
const calculation = new CalculationResource(
|
|
199
|
+
this.project,
|
|
200
|
+
resourceName(calculationName),
|
|
201
|
+
);
|
|
202
|
+
return calculation.rename(
|
|
203
|
+
resourceName(this.updateResourceName(calculationName)),
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
195
207
|
// Updates field type's metadata.
|
|
196
208
|
private async updateFieldTypeMetadata(fieldTypeName: string) {
|
|
197
209
|
const fieldType = new FieldTypeResource(
|
|
@@ -268,11 +280,6 @@ export class Rename {
|
|
|
268
280
|
if (!to) {
|
|
269
281
|
throw new Error(`Input validation error: empty 'to' is not allowed`);
|
|
270
282
|
}
|
|
271
|
-
const cardContent = {
|
|
272
|
-
metadata: true,
|
|
273
|
-
attachments: true,
|
|
274
|
-
content: true,
|
|
275
|
-
};
|
|
276
283
|
|
|
277
284
|
this.from = this.project.configuration.cardKeyPrefix;
|
|
278
285
|
this.to = to;
|
|
@@ -341,17 +348,25 @@ export class Rename {
|
|
|
341
348
|
}
|
|
342
349
|
console.info('Updated templates');
|
|
343
350
|
|
|
351
|
+
const calculations = await this.project.calculations(
|
|
352
|
+
ResourcesFrom.localOnly,
|
|
353
|
+
);
|
|
354
|
+
for (const calculation of calculations) {
|
|
355
|
+
await this.updateCalculation(calculation.name);
|
|
356
|
+
}
|
|
357
|
+
console.info('Updated calculations');
|
|
358
|
+
|
|
344
359
|
// Rename all local template cards.
|
|
345
360
|
templates = await this.project.templates(ResourcesFrom.localOnly);
|
|
346
361
|
for (const template of templates) {
|
|
347
362
|
const templateObject = new Template(this.project, template);
|
|
348
|
-
await this.renameCards(
|
|
363
|
+
await this.renameCards(templateObject.cards());
|
|
349
364
|
}
|
|
350
365
|
console.info('Renamed template cards and updated the content');
|
|
351
366
|
|
|
352
367
|
// Rename all project cards.
|
|
353
368
|
await this.renameCards(
|
|
354
|
-
|
|
369
|
+
this.project.cards(this.project.paths.cardRootFolder),
|
|
355
370
|
);
|
|
356
371
|
console.info('Renamed project cards and updated the content');
|
|
357
372
|
|