@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/create.ts
CHANGED
|
@@ -12,29 +12,25 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
// node
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
mkdir,
|
|
20
|
-
writeFile,
|
|
21
|
-
} from 'node:fs/promises';
|
|
22
|
-
|
|
23
|
-
import { errorFunction } from '../utils/log-utils.js';
|
|
15
|
+
import { join, resolve } from 'node:path';
|
|
16
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
17
|
+
|
|
18
|
+
import { errorFunction } from '../utils/error-utils.js';
|
|
24
19
|
import { Project } from '../containers/project.js';
|
|
25
20
|
import { Validate } from './index.js';
|
|
26
21
|
|
|
27
22
|
import { EMPTY_RANK, sortItems } from '../utils/lexorank.js';
|
|
23
|
+
import { isModulePath } from '../utils/card-utils.js';
|
|
28
24
|
import type {
|
|
29
25
|
DataType,
|
|
30
26
|
Link,
|
|
31
27
|
LinkType,
|
|
32
28
|
} from '../interfaces/resource-interfaces.js';
|
|
33
|
-
import { pathExists } from '../utils/file-utils.js';
|
|
34
29
|
import type { Card, ProjectFile } from '../interfaces/project-interfaces.js';
|
|
35
30
|
import { resourceName, resourceNameToString } from '../utils/resource-utils.js';
|
|
36
31
|
import { writeJsonFile } from '../utils/json.js';
|
|
37
32
|
|
|
33
|
+
import { CalculationResource } from '../resources/calculation-resource.js';
|
|
38
34
|
import { CardTypeResource } from '../resources/card-type-resource.js';
|
|
39
35
|
import { FieldTypeResource } from '../resources/field-type-resource.js';
|
|
40
36
|
import { GraphModelResource } from '../resources/graph-model-resource.js';
|
|
@@ -44,8 +40,6 @@ import { ReportResource } from '../resources/report-resource.js';
|
|
|
44
40
|
import { TemplateResource } from '../resources/template-resource.js';
|
|
45
41
|
import { WorkflowResource } from '../resources/workflow-resource.js';
|
|
46
42
|
|
|
47
|
-
const MODULES_PATH = `${sep}modules${sep}`;
|
|
48
|
-
|
|
49
43
|
// todo: Is there a easy to way to make JSON schema into a TypeScript interface/type?
|
|
50
44
|
// Check this out: https://www.npmjs.com/package/json-schema-to-ts
|
|
51
45
|
|
|
@@ -113,24 +107,14 @@ export class Create {
|
|
|
113
107
|
if (cardTypeName === undefined) {
|
|
114
108
|
throw new Error(`Input validation error: card type cannot be empty`);
|
|
115
109
|
}
|
|
116
|
-
// Use slice to get a copy of a string.
|
|
117
|
-
const origTemplateName = templateName.slice(0);
|
|
118
110
|
const templateResource = new TemplateResource(
|
|
119
111
|
this.project,
|
|
120
112
|
resourceName(templateName),
|
|
121
113
|
);
|
|
122
114
|
const templateObject = templateResource.templateObject();
|
|
115
|
+
const specificCard = card ? templateObject.findCard(card) : undefined;
|
|
123
116
|
|
|
124
|
-
|
|
125
|
-
? await templateObject.findSpecificCard(card)
|
|
126
|
-
: undefined;
|
|
127
|
-
if (card && !specificCard) {
|
|
128
|
-
throw new Error(
|
|
129
|
-
`Card '${card}' was not found from template '${origTemplateName}'`,
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (templateObject.templateFolder().includes(`${sep}modules${sep}`)) {
|
|
117
|
+
if (isModulePath(templateObject.templateFolder())) {
|
|
134
118
|
throw new Error(`Cannot add cards to imported module templates`);
|
|
135
119
|
}
|
|
136
120
|
|
|
@@ -181,66 +165,27 @@ export class Create {
|
|
|
181
165
|
attachment: string,
|
|
182
166
|
buffer?: Buffer,
|
|
183
167
|
) {
|
|
184
|
-
if (!buffer && !pathExists(attachment)) {
|
|
185
|
-
throw new Error(
|
|
186
|
-
`Input validation error: cannot find attachment '${attachment}'`,
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
const attachmentFolder = await this.project.cardAttachmentFolder(cardKey);
|
|
190
|
-
|
|
191
|
-
// Imported templates cannot be modified.
|
|
192
|
-
// @todo: make MODULES_PATH project level constant
|
|
193
|
-
if (attachmentFolder.includes(MODULES_PATH)) {
|
|
194
|
-
throw new Error(`Cannot modify imported module`);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
168
|
try {
|
|
198
|
-
await
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
fsConstants.COPYFILE_EXCL,
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
return writeFile(join(attachmentFolder, basename(attachment)), buffer, {
|
|
207
|
-
flag: 'wx',
|
|
208
|
-
});
|
|
209
|
-
});
|
|
169
|
+
await this.project.createCardAttachment(
|
|
170
|
+
cardKey,
|
|
171
|
+
attachment,
|
|
172
|
+
buffer || attachment,
|
|
173
|
+
);
|
|
210
174
|
} catch (error) {
|
|
211
175
|
throw new Error(errorFunction(error));
|
|
212
176
|
}
|
|
213
177
|
}
|
|
214
178
|
|
|
215
179
|
/**
|
|
216
|
-
* Creates a calculation
|
|
217
|
-
* @param
|
|
180
|
+
* Creates a calculation resource.
|
|
181
|
+
* @param calculationName name for the calculation resource
|
|
218
182
|
*/
|
|
219
|
-
public async createCalculation(
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
? fileName
|
|
226
|
-
: `${fileName}.lp`;
|
|
227
|
-
const calculationFilePath = join(calculationFolder, calculationFileName);
|
|
228
|
-
|
|
229
|
-
const calculationContent = `% Calculation file: ${calculationFileName}
|
|
230
|
-
% Add your logic programming rules here
|
|
231
|
-
`;
|
|
232
|
-
|
|
233
|
-
await writeFile(calculationFilePath, calculationContent, { flag: 'wx' });
|
|
234
|
-
|
|
235
|
-
// add to cache manually
|
|
236
|
-
// TODO: remove once calculations are a proper resource
|
|
237
|
-
const resourceName = `${this.project.projectPrefix}/calculations/${fileName.replace('.lp', '')}`;
|
|
238
|
-
const resource = {
|
|
239
|
-
name: resourceName,
|
|
240
|
-
path: calculationFolder,
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
this.project.addResource(resource, {} as JSON);
|
|
183
|
+
public async createCalculation(calculationName: string) {
|
|
184
|
+
const calculation = new CalculationResource(
|
|
185
|
+
this.project,
|
|
186
|
+
resourceName(calculationName),
|
|
187
|
+
);
|
|
188
|
+
await calculation.create();
|
|
244
189
|
}
|
|
245
190
|
|
|
246
191
|
/**
|
|
@@ -258,7 +203,7 @@ export class Create {
|
|
|
258
203
|
resourceName(templateName),
|
|
259
204
|
);
|
|
260
205
|
|
|
261
|
-
|
|
206
|
+
Validate.getInstance().validResourceName(
|
|
262
207
|
'templates',
|
|
263
208
|
resourceNameToString(resourceName(templateName)),
|
|
264
209
|
await this.project.projectPrefixes(),
|
|
@@ -267,15 +212,8 @@ export class Create {
|
|
|
267
212
|
await templateResource.validate();
|
|
268
213
|
|
|
269
214
|
const specificCard = parentCardKey
|
|
270
|
-
?
|
|
271
|
-
metadata: true,
|
|
272
|
-
children: true,
|
|
273
|
-
})
|
|
215
|
+
? this.project.findCard(parentCardKey)
|
|
274
216
|
: undefined;
|
|
275
|
-
if (parentCardKey && !specificCard) {
|
|
276
|
-
throw new Error(`Card '${parentCardKey}' not found from project`);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
217
|
const templateObject = templateResource.templateObject();
|
|
280
218
|
if (!templateObject || !templateObject.isCreated()) {
|
|
281
219
|
throw new Error(`Template '${templateName}' not found from project`);
|
|
@@ -283,7 +221,6 @@ export class Create {
|
|
|
283
221
|
|
|
284
222
|
const createdCards = await templateObject.createCards(specificCard);
|
|
285
223
|
if (createdCards.length > 0) {
|
|
286
|
-
await this.project.handleNewCards(createdCards);
|
|
287
224
|
// Note: This assumes that parent keys will be ahead of 'a' in the sort order.
|
|
288
225
|
const sorted = sortItems(createdCards, (item) => {
|
|
289
226
|
return `${item.parent === 'root' ? 'a' : item.parent}${item.metadata?.rank || EMPTY_RANK}`;
|
|
@@ -354,13 +291,8 @@ export class Create {
|
|
|
354
291
|
throw new Error(`Not a valid label name'`);
|
|
355
292
|
}
|
|
356
293
|
|
|
357
|
-
const card =
|
|
358
|
-
|
|
359
|
-
});
|
|
360
|
-
if (!card) {
|
|
361
|
-
throw new Error(`Card '${cardKey}' does not exist in the project`);
|
|
362
|
-
}
|
|
363
|
-
const labels = card.metadata?.labels ?? [];
|
|
294
|
+
const card = this.project.findCard(cardKey);
|
|
295
|
+
const labels = structuredClone(card.metadata?.labels) ?? [];
|
|
364
296
|
|
|
365
297
|
if (labels.includes(label)) {
|
|
366
298
|
throw new Error('Label already exists');
|
|
@@ -400,26 +332,10 @@ export class Create {
|
|
|
400
332
|
}
|
|
401
333
|
|
|
402
334
|
// Determine the card path
|
|
403
|
-
const card =
|
|
404
|
-
|
|
405
|
-
});
|
|
406
|
-
if (!card) {
|
|
407
|
-
throw new Error(`Card '${cardKey}' does not exist in the project`);
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
const destinationCard = await this.project.findSpecificCard(
|
|
411
|
-
destinationCardKey,
|
|
412
|
-
{
|
|
413
|
-
metadata: true,
|
|
414
|
-
},
|
|
415
|
-
);
|
|
416
|
-
if (!destinationCard) {
|
|
417
|
-
throw new Error(
|
|
418
|
-
`Card '${destinationCardKey}' does not exist in the project`,
|
|
419
|
-
);
|
|
420
|
-
}
|
|
335
|
+
const card = this.project.findCard(cardKey);
|
|
336
|
+
const destinationCard = this.project.findCard(destinationCardKey);
|
|
421
337
|
// make sure the link type exists
|
|
422
|
-
const linkTypeObject =
|
|
338
|
+
const linkTypeObject = this.project.resource<LinkType>(linkType);
|
|
423
339
|
if (!linkTypeObject) {
|
|
424
340
|
throw new Error(`Link type '${linkType}' does not exist in the project`);
|
|
425
341
|
}
|
package/src/commands/edit.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
Cyberismo
|
|
3
|
+
Copyright © Cyberismo Ltd and contributors 2024
|
|
4
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
5
|
+
the terms of the GNU Affero General Public License version 3 as published by
|
|
6
|
+
the Free Software Foundation.
|
|
7
|
+
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
8
|
+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
9
|
+
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
10
|
+
details. You should have received a copy of the GNU Affero General Public
|
|
11
|
+
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
11
12
|
*/
|
|
12
13
|
|
|
13
14
|
// node
|
|
@@ -16,18 +17,10 @@ import { homedir } from 'node:os';
|
|
|
16
17
|
import { spawnSync } from 'node:child_process';
|
|
17
18
|
|
|
18
19
|
import { ActionGuard } from '../permissions/action-guard.js';
|
|
19
|
-
import type {
|
|
20
|
-
MetadataContent,
|
|
21
|
-
ResourceFolderType,
|
|
22
|
-
} from '../interfaces/project-interfaces.js';
|
|
23
20
|
import { Project } from '../containers/project.js';
|
|
24
21
|
import { UserPreferences } from '../utils/user-preferences.js';
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
resourceNameToString,
|
|
28
|
-
} from '../utils/resource-utils.js';
|
|
29
|
-
import { FolderResource } from '../resources/folder-resource.js';
|
|
30
|
-
import { writeFile } from 'node:fs/promises';
|
|
22
|
+
|
|
23
|
+
import type { MetadataContent } from '../interfaces/project-interfaces.js';
|
|
31
24
|
|
|
32
25
|
export class Edit {
|
|
33
26
|
private project: Project;
|
|
@@ -36,54 +29,12 @@ export class Edit {
|
|
|
36
29
|
this.project = project;
|
|
37
30
|
}
|
|
38
31
|
|
|
39
|
-
/**
|
|
40
|
-
* Updates a calculation file.
|
|
41
|
-
* @param resourceName The name of the resource to update.
|
|
42
|
-
* @param changedContent The new content for the calculation.
|
|
43
|
-
*/
|
|
44
|
-
public async editCalculation(
|
|
45
|
-
resourceName: ResourceName,
|
|
46
|
-
changedContent: string,
|
|
47
|
-
) {
|
|
48
|
-
if (resourceName.prefix !== this.project.projectPrefix) {
|
|
49
|
-
throw new Error(
|
|
50
|
-
`Resource '${resourceName.identifier}' is not a local resource`,
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
const resourceNameString = resourceNameToString(resourceName);
|
|
54
|
-
if (
|
|
55
|
-
!(await this.project.resourceExists(
|
|
56
|
-
resourceName.type as ResourceFolderType,
|
|
57
|
-
resourceNameString,
|
|
58
|
-
))
|
|
59
|
-
) {
|
|
60
|
-
throw new Error(
|
|
61
|
-
`Resource '${resourceNameString}' does not exist in the project`,
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
await writeFile(
|
|
65
|
-
join(
|
|
66
|
-
this.project.paths.calculationProjectFolder,
|
|
67
|
-
resourceName.identifier + '.lp',
|
|
68
|
-
),
|
|
69
|
-
changedContent,
|
|
70
|
-
{
|
|
71
|
-
encoding: 'utf-8',
|
|
72
|
-
flag: 'r+',
|
|
73
|
-
},
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
32
|
/**
|
|
78
33
|
* Opens the content and metadata files for a card in the code editor
|
|
79
34
|
* @param cardKey - The key of the card to open. Required.
|
|
80
35
|
*/
|
|
81
|
-
public
|
|
82
|
-
|
|
83
|
-
const cardPath = this.project.pathToCard(cardKey);
|
|
84
|
-
if (!cardPath) {
|
|
85
|
-
throw new Error(`Card '${cardKey}' does not exist in the project`);
|
|
86
|
-
}
|
|
36
|
+
public editCard(cardKey: string) {
|
|
37
|
+
const card = this.project.findCard(cardKey);
|
|
87
38
|
|
|
88
39
|
// Read the user preferences
|
|
89
40
|
const prefs = new UserPreferences(
|
|
@@ -91,9 +42,8 @@ export class Edit {
|
|
|
91
42
|
).getPreferences();
|
|
92
43
|
|
|
93
44
|
// Construct paths for the card components (json and adoc)
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
const cardJsonPath = join(cardDirPath, Project.cardMetadataFile);
|
|
45
|
+
const cardContentPath = join(card.path, Project.cardContentFile);
|
|
46
|
+
const cardJsonPath = join(card.path, Project.cardMetadataFile);
|
|
97
47
|
|
|
98
48
|
// Extract the editor settings from the preferences.
|
|
99
49
|
const editorPrefs = prefs.editCommand[process.platform];
|
|
@@ -104,7 +54,7 @@ export class Edit {
|
|
|
104
54
|
const editorArgs = editorArgPrefs.map((arg) => {
|
|
105
55
|
arg = arg.replace(/\{\{\s*cardContentPath\s*\}\}/, cardContentPath);
|
|
106
56
|
arg = arg.replace(/\{\{\s*cardJsonPath\s*\}\}/, cardJsonPath);
|
|
107
|
-
arg = arg.replace(/\{\{\s*cardDirPath\s*\}\}/,
|
|
57
|
+
arg = arg.replace(/\{\{\s*cardDirPath\s*\}\}/, card.path);
|
|
108
58
|
|
|
109
59
|
return arg;
|
|
110
60
|
});
|
|
@@ -127,19 +77,14 @@ export class Edit {
|
|
|
127
77
|
* @param changedContent New content for the card.
|
|
128
78
|
*/
|
|
129
79
|
public async editCardContent(cardKey: string, changedContent: string) {
|
|
130
|
-
|
|
131
|
-
if (isTemplateCard) {
|
|
80
|
+
if (this.project.hasTemplateCard(cardKey)) {
|
|
132
81
|
return this.project.updateCardContent(cardKey, changedContent);
|
|
133
82
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
83
|
+
if (this.project.findCard(cardKey)) {
|
|
84
|
+
const actionGuard = new ActionGuard(this.project.calculationEngine);
|
|
85
|
+
await actionGuard.checkPermission('editContent', cardKey);
|
|
86
|
+
await this.project.updateCardContent(cardKey, changedContent);
|
|
137
87
|
}
|
|
138
|
-
|
|
139
|
-
const actionGuard = new ActionGuard(this.project.calculationEngine);
|
|
140
|
-
await actionGuard.checkPermission('editContent', cardKey);
|
|
141
|
-
|
|
142
|
-
await this.project.updateCardContent(cardKey, changedContent);
|
|
143
88
|
}
|
|
144
89
|
|
|
145
90
|
/**
|
|
@@ -156,51 +101,15 @@ export class Edit {
|
|
|
156
101
|
if (!changedKey) {
|
|
157
102
|
throw new Error(`Changed key cannot be empty`);
|
|
158
103
|
}
|
|
159
|
-
|
|
160
|
-
if (isTemplateCard) {
|
|
104
|
+
if (this.project.hasTemplateCard(cardKey)) {
|
|
161
105
|
return this.project.updateCardMetadataKey(cardKey, changedKey, newValue);
|
|
162
106
|
}
|
|
163
107
|
|
|
164
|
-
// Determine the card path
|
|
165
|
-
const cardPath = this.project.pathToCard(cardKey);
|
|
166
|
-
if (!cardPath) {
|
|
167
|
-
throw new Error(`Card '${cardKey}' does not exist in the project`);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
108
|
// check for editing rights
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Update a file of a folder resource. Cannot be used to create a new file.
|
|
178
|
-
* @param resourceName The name of the resource to update.
|
|
179
|
-
* @param fileName The name of the file to update.
|
|
180
|
-
* @param changedContent The new content for the file.
|
|
181
|
-
*/
|
|
182
|
-
public async editResourceContent(
|
|
183
|
-
resourceName: ResourceName,
|
|
184
|
-
fileName: string,
|
|
185
|
-
changedContent: string,
|
|
186
|
-
) {
|
|
187
|
-
const resourceNameString = resourceNameToString(resourceName);
|
|
188
|
-
if (
|
|
189
|
-
!(await this.project.resourceExists(
|
|
190
|
-
resourceName.type as ResourceFolderType,
|
|
191
|
-
resourceNameString,
|
|
192
|
-
))
|
|
193
|
-
) {
|
|
194
|
-
throw new Error(
|
|
195
|
-
`Resource '${resourceNameString}' does not exist in the project`,
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
const resource = Project.resourceObject(this.project, resourceName);
|
|
199
|
-
if (!(resource instanceof FolderResource)) {
|
|
200
|
-
throw new Error(
|
|
201
|
-
`Resource '${resourceNameString}' is not a folder resource`,
|
|
202
|
-
);
|
|
109
|
+
if (this.project.findCard(cardKey)) {
|
|
110
|
+
const actionGuard = new ActionGuard(this.project.calculationEngine);
|
|
111
|
+
await actionGuard.checkPermission('editField', cardKey, changedKey);
|
|
112
|
+
await this.project.updateCardMetadataKey(cardKey, changedKey, newValue);
|
|
203
113
|
}
|
|
204
|
-
return resource.updateFile(fileName, changedContent);
|
|
205
114
|
}
|
|
206
115
|
}
|
package/src/commands/export.ts
CHANGED
|
@@ -23,10 +23,7 @@ import {
|
|
|
23
23
|
import { dirname, join } from 'node:path';
|
|
24
24
|
import { spawn } from 'node:child_process';
|
|
25
25
|
|
|
26
|
-
import type {
|
|
27
|
-
Card,
|
|
28
|
-
FetchCardDetails,
|
|
29
|
-
} from '../interfaces/project-interfaces.js';
|
|
26
|
+
import type { Card } from '../interfaces/project-interfaces.js';
|
|
30
27
|
import type { CardType } from '../interfaces/resource-interfaces.js';
|
|
31
28
|
import { evaluateMacros } from '../macros/index.js';
|
|
32
29
|
import type { ExportPdfOptions } from '../interfaces/project-interfaces.js';
|
|
@@ -144,7 +141,10 @@ export class Export {
|
|
|
144
141
|
}
|
|
145
142
|
|
|
146
143
|
if (card.children) {
|
|
147
|
-
await this.toAdocFileAsContent(
|
|
144
|
+
await this.toAdocFileAsContent(
|
|
145
|
+
path,
|
|
146
|
+
this.project.cardKeysToCards(card.children),
|
|
147
|
+
);
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
}
|
|
@@ -187,22 +187,7 @@ export class Export {
|
|
|
187
187
|
children: [],
|
|
188
188
|
attachments: [],
|
|
189
189
|
};
|
|
190
|
-
|
|
191
|
-
// Get content and attachments separately, not included in queries
|
|
192
|
-
const fetchCardDetails: FetchCardDetails = {
|
|
193
|
-
attachments: true,
|
|
194
|
-
children: false,
|
|
195
|
-
content: true,
|
|
196
|
-
contentType: 'adoc',
|
|
197
|
-
metadata: true,
|
|
198
|
-
parent: false,
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
const cardDetailsResponse = await this.showCmd.showCardDetails(
|
|
202
|
-
fetchCardDetails,
|
|
203
|
-
card.key,
|
|
204
|
-
);
|
|
205
|
-
|
|
190
|
+
const cardDetailsResponse = this.showCmd.showCardDetails(card.key, 'adoc');
|
|
206
191
|
let asciiDocContent = '';
|
|
207
192
|
const project = this.project;
|
|
208
193
|
try {
|
|
@@ -227,7 +212,7 @@ export class Export {
|
|
|
227
212
|
card.attachments = cardDetailsResponse.attachments;
|
|
228
213
|
|
|
229
214
|
for (const result of treeQueryResult.children ?? []) {
|
|
230
|
-
card.children!.push(await this.treeQueryResultToCard(result));
|
|
215
|
+
card.children!.push((await this.treeQueryResultToCard(result)).key);
|
|
231
216
|
}
|
|
232
217
|
|
|
233
218
|
return card;
|
|
@@ -332,13 +317,7 @@ export class Export {
|
|
|
332
317
|
let cards: Card[] = [];
|
|
333
318
|
|
|
334
319
|
// If doing a partial tree export, put the parent information as it would have already been gathered.
|
|
335
|
-
if (cardKey) {
|
|
336
|
-
const card = await this.project.findSpecificCard(cardKey);
|
|
337
|
-
if (!card) {
|
|
338
|
-
throw new Error(
|
|
339
|
-
`Input validation error: cannot find card '${cardKey}'`,
|
|
340
|
-
);
|
|
341
|
-
}
|
|
320
|
+
if (cardKey && this.project.findCard(cardKey)) {
|
|
342
321
|
cards.push({
|
|
343
322
|
key: cardKey,
|
|
344
323
|
path: sourcePath,
|
package/src/commands/fetch.ts
CHANGED
|
@@ -18,7 +18,8 @@ import type { Project } from '../containers/project.js';
|
|
|
18
18
|
import { writeJsonFile } from '../utils/json.js';
|
|
19
19
|
import { validateJson } from '../utils/validate.js';
|
|
20
20
|
import { type ModuleSetting } from '../interfaces/project-interfaces.js';
|
|
21
|
-
import { errorFunction
|
|
21
|
+
import { errorFunction } from '../utils/error-utils.js';
|
|
22
|
+
import { getChildLogger } from '../utils/log-utils.js';
|
|
22
23
|
|
|
23
24
|
const FETCH_TIMEOUT = 30000; // 30s timeout for fetching a hub file.
|
|
24
25
|
const MAX_RESPONSE_SIZE = 1024 * 1024; // 1MB limit for safety
|
package/src/commands/import.ts
CHANGED
|
@@ -62,7 +62,7 @@ export class Import {
|
|
|
62
62
|
throw new Error(`Template '${template}' not found`);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
const templateCards =
|
|
65
|
+
const templateCards = templateObject.cards();
|
|
66
66
|
if (templateCards.length !== 1) {
|
|
67
67
|
console.warn(
|
|
68
68
|
`Template '${template}' for card '${title}' does not have exactly one card. Skipping row.`,
|
|
@@ -77,11 +77,9 @@ export class Import {
|
|
|
77
77
|
throw new Error('Card not created');
|
|
78
78
|
}
|
|
79
79
|
const cardKey = cards[0].key;
|
|
80
|
-
const card =
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const cardType = await this.project.resource<CardType>(
|
|
84
|
-
card?.metadata?.cardType || '',
|
|
80
|
+
const card = this.project.findCard(cardKey);
|
|
81
|
+
const cardType = this.project.resource<CardType>(
|
|
82
|
+
card.metadata?.cardType || '',
|
|
85
83
|
);
|
|
86
84
|
|
|
87
85
|
if (!cardType) {
|