@cyberismo/data-handler 0.0.10 → 0.0.12
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 -1
- package/dist/card-metadata-updater.js.map +1 -1
- package/dist/command-handler.d.ts +13 -8
- package/dist/command-handler.js +47 -7
- package/dist/command-handler.js.map +1 -1
- package/dist/command-manager.d.ts +2 -1
- package/dist/command-manager.js +4 -2
- package/dist/command-manager.js.map +1 -1
- package/dist/commands/calculate.d.ts +7 -0
- package/dist/commands/calculate.js +9 -0
- package/dist/commands/calculate.js.map +1 -1
- package/dist/commands/create.d.ts +5 -0
- package/dist/commands/create.js +15 -8
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/fetch.d.ts +24 -0
- package/dist/commands/fetch.js +118 -0
- package/dist/commands/fetch.js.map +1 -0
- package/dist/commands/index.d.ts +2 -1
- package/dist/commands/index.js +2 -1
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/remove.d.ts +1 -0
- package/dist/commands/remove.js +16 -12
- package/dist/commands/remove.js.map +1 -1
- package/dist/commands/rename.js +4 -6
- package/dist/commands/rename.js.map +1 -1
- package/dist/commands/show.d.ts +18 -1
- package/dist/commands/show.js +52 -0
- package/dist/commands/show.js.map +1 -1
- package/dist/commands/validate.js +7 -8
- package/dist/commands/validate.js.map +1 -1
- package/dist/containers/project/calculation-engine.d.ts +8 -0
- package/dist/containers/project/calculation-engine.js +20 -9
- package/dist/containers/project/calculation-engine.js.map +1 -1
- package/dist/containers/project.d.ts +19 -8
- package/dist/containers/project.js +52 -34
- package/dist/containers/project.js.map +1 -1
- package/dist/containers/template.js +1 -1
- package/dist/containers/template.js.map +1 -1
- package/dist/interfaces/project-interfaces.d.ts +13 -2
- package/dist/interfaces/project-interfaces.js.map +1 -1
- package/dist/macros/base-macro.d.ts +1 -1
- package/dist/macros/base-macro.js +1 -1
- package/dist/macros/base-macro.js.map +1 -1
- package/dist/macros/createCards/index.d.ts +1 -1
- package/dist/macros/createCards/index.js +1 -1
- package/dist/macros/createCards/index.js.map +1 -1
- package/dist/macros/graph/index.d.ts +1 -1
- package/dist/macros/graph/index.js +21 -29
- package/dist/macros/graph/index.js.map +1 -1
- package/dist/macros/image/index.d.ts +1 -1
- package/dist/macros/image/index.js +1 -7
- package/dist/macros/image/index.js.map +1 -1
- package/dist/macros/include/index.d.ts +1 -1
- package/dist/macros/include/index.js +1 -1
- package/dist/macros/include/index.js.map +1 -1
- package/dist/macros/index.d.ts +12 -5
- package/dist/macros/index.js +19 -7
- package/dist/macros/index.js.map +1 -1
- package/dist/macros/percentage/index.d.ts +1 -1
- package/dist/macros/percentage/index.js +1 -1
- package/dist/macros/percentage/index.js.map +1 -1
- package/dist/macros/report/index.d.ts +1 -1
- package/dist/macros/report/index.js +1 -1
- package/dist/macros/report/index.js.map +1 -1
- package/dist/macros/scoreCard/index.d.ts +1 -1
- package/dist/macros/scoreCard/index.js +1 -1
- package/dist/macros/scoreCard/index.js.map +1 -1
- package/dist/macros/vega/index.d.ts +1 -1
- package/dist/macros/vega/index.js +1 -1
- package/dist/macros/vega/index.js.map +1 -1
- package/dist/macros/vegalite/index.d.ts +1 -1
- package/dist/macros/vegalite/index.js +1 -1
- package/dist/macros/vegalite/index.js.map +1 -1
- package/dist/macros/xref/index.d.ts +1 -1
- package/dist/macros/xref/index.js +1 -1
- package/dist/macros/xref/index.js.map +1 -1
- package/dist/project-settings.d.ts +14 -1
- package/dist/project-settings.js +51 -1
- package/dist/project-settings.js.map +1 -1
- package/dist/resources/field-type-resource.d.ts +5 -0
- package/dist/resources/field-type-resource.js +8 -3
- package/dist/resources/field-type-resource.js.map +1 -1
- package/dist/resources/graph-view-resource.js +3 -5
- package/dist/resources/graph-view-resource.js.map +1 -1
- package/dist/resources/workflow-resource.js +6 -5
- package/dist/resources/workflow-resource.js.map +1 -1
- package/dist/utils/log-utils.js +1 -1
- package/dist/utils/log-utils.js.map +1 -1
- package/dist/utils/report.js +6 -0
- package/dist/utils/report.js.map +1 -1
- package/dist/utils/resource-utils.d.ts +8 -0
- package/dist/utils/resource-utils.js +11 -0
- package/dist/utils/resource-utils.js.map +1 -1
- package/package.json +7 -9
- package/src/card-metadata-updater.ts +1 -1
- package/src/command-handler.ts +70 -15
- package/src/command-manager.ts +4 -1
- package/src/commands/calculate.ts +18 -0
- package/src/commands/create.ts +31 -19
- package/src/commands/fetch.ts +152 -0
- package/src/commands/index.ts +2 -0
- package/src/commands/remove.ts +18 -12
- package/src/commands/rename.ts +11 -11
- package/src/commands/show.ts +68 -0
- package/src/commands/validate.ts +7 -8
- package/src/containers/project/calculation-engine.ts +26 -8
- package/src/containers/project.ts +71 -61
- package/src/containers/template.ts +1 -1
- package/src/interfaces/project-interfaces.ts +18 -0
- package/src/macros/base-macro.ts +5 -2
- package/src/macros/createCards/index.ts +1 -1
- package/src/macros/graph/index.ts +47 -51
- package/src/macros/image/index.ts +1 -7
- package/src/macros/include/index.ts +1 -1
- package/src/macros/index.ts +19 -7
- package/src/macros/percentage/index.ts +1 -1
- package/src/macros/report/index.ts +1 -1
- package/src/macros/scoreCard/index.ts +1 -1
- package/src/macros/vega/index.ts +1 -1
- package/src/macros/vegalite/index.ts +1 -1
- package/src/macros/xref/index.ts +1 -1
- package/src/project-settings.ts +62 -1
- package/src/resources/field-type-resource.ts +8 -3
- package/src/resources/graph-view-resource.ts +7 -5
- package/src/resources/workflow-resource.ts +7 -6
- package/src/utils/log-utils.ts +1 -1
- package/src/utils/report.ts +6 -0
- package/src/utils/resource-utils.ts +16 -0
package/src/macros/xref/index.ts
CHANGED
package/src/project-settings.ts
CHANGED
|
@@ -13,9 +13,11 @@
|
|
|
13
13
|
|
|
14
14
|
import { writeJsonFile as atomicWrite } from 'write-json-file';
|
|
15
15
|
|
|
16
|
-
import { resolve } from 'path';
|
|
16
|
+
import { resolve } from 'node:path';
|
|
17
|
+
import { URL } from 'node:url';
|
|
17
18
|
|
|
18
19
|
import type {
|
|
20
|
+
HubSetting,
|
|
19
21
|
ModuleSetting,
|
|
20
22
|
ProjectSettings,
|
|
21
23
|
} from './interfaces/project-interfaces.js';
|
|
@@ -31,6 +33,7 @@ export class ProjectConfiguration implements ProjectSettings {
|
|
|
31
33
|
name: string;
|
|
32
34
|
cardKeyPrefix: string;
|
|
33
35
|
modules: ModuleSetting[];
|
|
36
|
+
hubs: HubSetting[];
|
|
34
37
|
private settingPath: string;
|
|
35
38
|
|
|
36
39
|
constructor(path: string) {
|
|
@@ -38,6 +41,7 @@ export class ProjectConfiguration implements ProjectSettings {
|
|
|
38
41
|
this.settingPath = path;
|
|
39
42
|
this.cardKeyPrefix = '';
|
|
40
43
|
this.modules = [];
|
|
44
|
+
this.hubs = [];
|
|
41
45
|
this.readSettings();
|
|
42
46
|
}
|
|
43
47
|
|
|
@@ -70,6 +74,7 @@ export class ProjectConfiguration implements ProjectSettings {
|
|
|
70
74
|
this.cardKeyPrefix = settings.cardKeyPrefix;
|
|
71
75
|
this.name = settings.name;
|
|
72
76
|
this.modules = settings.modules || [];
|
|
77
|
+
this.hubs = settings.hubs || [];
|
|
73
78
|
} else {
|
|
74
79
|
throw new Error(`Invalid configuration file '${this.settingPath}'`);
|
|
75
80
|
}
|
|
@@ -81,9 +86,51 @@ export class ProjectConfiguration implements ProjectSettings {
|
|
|
81
86
|
cardKeyPrefix: this.cardKeyPrefix,
|
|
82
87
|
name: this.name,
|
|
83
88
|
modules: this.modules,
|
|
89
|
+
hubs: this.hubs,
|
|
84
90
|
};
|
|
85
91
|
}
|
|
86
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Adds a new hub.
|
|
95
|
+
* @param hubName URL of the hub to add
|
|
96
|
+
* @throws if hub is already in the project or URL is invalid
|
|
97
|
+
*/
|
|
98
|
+
public async addHub(hubName: string) {
|
|
99
|
+
const trimmedHub = hubName?.trim();
|
|
100
|
+
if (!trimmedHub) {
|
|
101
|
+
throw new Error(`Cannot add empty hub to the project`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const exists = this.hubs.find((item) => item.location === trimmedHub);
|
|
105
|
+
if (exists) {
|
|
106
|
+
throw new Error(
|
|
107
|
+
`Hub '${trimmedHub}' already exists as a hub for the project`,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
try {
|
|
112
|
+
const hubUrl = new URL(trimmedHub);
|
|
113
|
+
if (!['http:', 'https:'].includes(hubUrl.protocol)) {
|
|
114
|
+
throw new Error(
|
|
115
|
+
`Invalid URL protocol '${hubUrl.protocol}'. Only HTTP and HTTPS protocols are supported for hubs.`,
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
if (!hubUrl.hostname) {
|
|
119
|
+
throw new Error('Hub URL must have a valid hostname.');
|
|
120
|
+
}
|
|
121
|
+
} catch (error) {
|
|
122
|
+
if (error instanceof TypeError) {
|
|
123
|
+
throw new Error(
|
|
124
|
+
`Invalid hub URL '${trimmedHub}'. Please provide a valid HTTP or HTTPS URL.`,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
this.hubs.push({ location: trimmedHub });
|
|
131
|
+
return this.save();
|
|
132
|
+
}
|
|
133
|
+
|
|
87
134
|
/**
|
|
88
135
|
* Adds new module to imported modules property.
|
|
89
136
|
* @param module Module to add as dependency
|
|
@@ -105,6 +152,20 @@ export class ProjectConfiguration implements ProjectSettings {
|
|
|
105
152
|
return this.save();
|
|
106
153
|
}
|
|
107
154
|
|
|
155
|
+
/**
|
|
156
|
+
* Removes a hub.
|
|
157
|
+
* @param hubName Name of the hub to remove.
|
|
158
|
+
* @throws if hub is not part of the project
|
|
159
|
+
*/
|
|
160
|
+
public async removeHub(hubName: string) {
|
|
161
|
+
const exists = this.hubs.find((item) => item.location === hubName);
|
|
162
|
+
if (!exists) {
|
|
163
|
+
throw new Error(`Hub '${hubName}' not part of the project`);
|
|
164
|
+
}
|
|
165
|
+
this.hubs = this.hubs.filter((item) => item.location !== hubName);
|
|
166
|
+
return this.save();
|
|
167
|
+
}
|
|
168
|
+
|
|
108
169
|
/**
|
|
109
170
|
* Removes module from imported modules property.
|
|
110
171
|
* @param moduleName Name of the module to remove.
|
|
@@ -150,13 +150,13 @@ export class FieldTypeResource extends FileResource {
|
|
|
150
150
|
const allCards = [...projectCards, ...templateCards];
|
|
151
151
|
|
|
152
152
|
// Finally, convert values and update the cards.
|
|
153
|
-
|
|
153
|
+
for (const card of allCards) {
|
|
154
154
|
const metadata = card.metadata!;
|
|
155
155
|
const fieldName = resourceNameToString(this.resourceName);
|
|
156
156
|
try {
|
|
157
157
|
metadata[fieldName] = this.convertValue(metadata[fieldName]);
|
|
158
158
|
// Either value was already null, or couldn't convert.
|
|
159
|
-
if (metadata[fieldName] === null)
|
|
159
|
+
if (metadata[fieldName] === null) continue;
|
|
160
160
|
|
|
161
161
|
await this.project.updateCardMetadata(card, metadata);
|
|
162
162
|
} catch (error) {
|
|
@@ -164,7 +164,7 @@ export class FieldTypeResource extends FileResource {
|
|
|
164
164
|
`In card '${card.key}': ${error instanceof Error ? error.message : String(error)}`,
|
|
165
165
|
);
|
|
166
166
|
}
|
|
167
|
-
}
|
|
167
|
+
}
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
// Checks that enum with 'enumValue' exists.
|
|
@@ -305,6 +305,7 @@ export class FieldTypeResource extends FileResource {
|
|
|
305
305
|
/**
|
|
306
306
|
* Creates a new field type object. Base class writes the object to disk automatically.
|
|
307
307
|
* @param dataType Type for the new field type.
|
|
308
|
+
* @throws if called with unknown data type
|
|
308
309
|
*/
|
|
309
310
|
public async createFieldType(dataType: DataType) {
|
|
310
311
|
if (!FieldTypeResource.fieldDataTypes().includes(dataType)) {
|
|
@@ -418,6 +419,10 @@ export class FieldTypeResource extends FileResource {
|
|
|
418
419
|
* Updates field type resource.
|
|
419
420
|
* @param key Key to modify
|
|
420
421
|
* @param op Operation to perform on 'key'
|
|
422
|
+
* @throws
|
|
423
|
+
* - when called with unknown data type
|
|
424
|
+
* - when called with data type conversion that cannot be done
|
|
425
|
+
* - when called with unknown property to update
|
|
421
426
|
*/
|
|
422
427
|
public async update<Type>(key: string, op: Operation<Type>) {
|
|
423
428
|
const nameChange = key === 'name';
|
|
@@ -31,7 +31,9 @@ import type {
|
|
|
31
31
|
GraphView,
|
|
32
32
|
GraphViewMetadata,
|
|
33
33
|
} from '../interfaces/resource-interfaces.js';
|
|
34
|
-
|
|
34
|
+
|
|
35
|
+
import { getStaticDirectoryPath } from '@cyberismo/assets';
|
|
36
|
+
import { copyDir } from '../utils/file-utils.js';
|
|
35
37
|
|
|
36
38
|
/**
|
|
37
39
|
* Graph view resource class.
|
|
@@ -73,10 +75,10 @@ export class GraphViewResource extends FolderResource {
|
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
await super.create(newContent);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
await copyDir(
|
|
79
|
+
join(await getStaticDirectoryPath(), 'defaultGraphView'),
|
|
80
|
+
this.internalFolder,
|
|
81
|
+
);
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
/**
|
|
@@ -190,12 +190,13 @@ export class WorkflowResource extends FileResource {
|
|
|
190
190
|
// Update card states when state is changed
|
|
191
191
|
private async updateCardStates(oldState: string, newState: string) {
|
|
192
192
|
const cards = await this.collectCardsUsingWorkflow();
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
193
|
+
const promises = cards
|
|
194
|
+
.filter((card) => card.metadata?.workflowState === oldState)
|
|
195
|
+
.map(async (card) => {
|
|
196
|
+
card.metadata!.workflowState = newState;
|
|
197
|
+
await this.project.updateCardMetadata(card, card.metadata!);
|
|
198
|
+
});
|
|
199
|
+
await Promise.all(promises);
|
|
199
200
|
}
|
|
200
201
|
|
|
201
202
|
// Update dependant card types.
|
package/src/utils/log-utils.ts
CHANGED
|
@@ -13,7 +13,7 @@ import pino, { type ChildLoggerOptions, type Logger } from 'pino';
|
|
|
13
13
|
|
|
14
14
|
// This could be also a more generic interface, but since we use pino and this is an internal package, let's keep it simple
|
|
15
15
|
// silent logger as default
|
|
16
|
-
let _logger: Logger = pino
|
|
16
|
+
let _logger: Logger = pino({ level: 'silent' });
|
|
17
17
|
|
|
18
18
|
export function setLogger(logger: Logger) {
|
|
19
19
|
_logger = logger;
|
package/src/utils/report.ts
CHANGED
|
@@ -62,8 +62,14 @@ export function formatValue(value: unknown): string {
|
|
|
62
62
|
) {
|
|
63
63
|
return value.displayValue;
|
|
64
64
|
}
|
|
65
|
+
if (value != null && 'value' in value && typeof value.value === 'string') {
|
|
66
|
+
return formatValue(value.value);
|
|
67
|
+
}
|
|
65
68
|
return JSON.stringify(value, null, 2);
|
|
66
69
|
}
|
|
70
|
+
if (typeof value === 'boolean') {
|
|
71
|
+
return value ? 'Yes' : 'No';
|
|
72
|
+
}
|
|
67
73
|
return value?.toString() ?? '';
|
|
68
74
|
}
|
|
69
75
|
|
|
@@ -112,6 +112,22 @@ export function resourceNameToPath(
|
|
|
112
112
|
throw new Error('resourceName does not contain prefix');
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
/**
|
|
116
|
+
* Return path to a file in a folder resource
|
|
117
|
+
* @param project Project
|
|
118
|
+
* @param resourceName Resource name
|
|
119
|
+
* @param fileName File name
|
|
120
|
+
* @returns Path to file in folder resource
|
|
121
|
+
*/
|
|
122
|
+
export function resourceFilePath(
|
|
123
|
+
project: Project,
|
|
124
|
+
resourceName: ResourceName,
|
|
125
|
+
fileName: string,
|
|
126
|
+
): string {
|
|
127
|
+
const resourcePath = resourceNameToPath(project, resourceName, '');
|
|
128
|
+
return join(resourcePath, fileName);
|
|
129
|
+
}
|
|
130
|
+
|
|
115
131
|
/**
|
|
116
132
|
* Resource metadata file path to resource name (e.g. <prefix>/<type>/<name>)
|
|
117
133
|
* @param project Project where resource is in
|