@cyberismo/data-handler 0.0.14 → 0.0.16
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 +8 -4
- package/dist/card-metadata-updater.js.map +1 -1
- package/dist/command-handler.d.ts +4 -0
- package/dist/command-handler.js +29 -19
- package/dist/command-handler.js.map +1 -1
- package/dist/command-manager.d.ts +25 -2
- package/dist/command-manager.js +30 -5
- package/dist/command-manager.js.map +1 -1
- package/dist/commands/create.d.ts +1 -1
- package/dist/commands/create.js +45 -93
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/edit.d.ts +1 -15
- package/dist/commands/edit.js +15 -89
- package/dist/commands/edit.js.map +1 -1
- package/dist/commands/export.d.ts +11 -2
- package/dist/commands/export.js +58 -58
- package/dist/commands/export.js.map +1 -1
- package/dist/commands/import.d.ts +9 -1
- package/dist/commands/import.js +17 -11
- package/dist/commands/import.js.map +1 -1
- package/dist/commands/move.d.ts +1 -2
- package/dist/commands/move.js +107 -146
- package/dist/commands/move.js.map +1 -1
- package/dist/commands/remove.d.ts +8 -1
- package/dist/commands/remove.js +17 -48
- package/dist/commands/remove.js.map +1 -1
- package/dist/commands/rename.d.ts +4 -9
- package/dist/commands/rename.js +34 -108
- package/dist/commands/rename.js.map +1 -1
- package/dist/commands/show.d.ts +22 -34
- package/dist/commands/show.js +103 -151
- package/dist/commands/show.js.map +1 -1
- package/dist/commands/transition.d.ts +9 -2
- package/dist/commands/transition.js +49 -44
- package/dist/commands/transition.js.map +1 -1
- package/dist/commands/update.d.ts +18 -12
- package/dist/commands/update.js +34 -18
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/validate.d.ts +18 -10
- package/dist/commands/validate.js +101 -47
- 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 +13 -4
- package/dist/containers/project/calculation-engine.js +79 -77
- 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/project-paths.d.ts +5 -4
- package/dist/containers/project/project-paths.js +16 -12
- package/dist/containers/project/project-paths.js.map +1 -1
- package/dist/containers/project/resource-cache.d.ts +169 -0
- package/dist/containers/project/resource-cache.js +507 -0
- package/dist/containers/project/resource-cache.js.map +1 -0
- package/dist/containers/project/resource-handler.d.ts +129 -0
- package/dist/containers/project/resource-handler.js +206 -0
- package/dist/containers/project/resource-handler.js.map +1 -0
- package/dist/containers/project.d.ts +114 -195
- package/dist/containers/project.js +425 -535
- package/dist/containers/project.js.map +1 -1
- package/dist/containers/template.d.ts +22 -32
- package/dist/containers/template.js +113 -115
- 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 +7 -4
- package/dist/interfaces/folder-content-interfaces.js +3 -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 +7 -5
- package/dist/interfaces/project-interfaces.js.map +1 -1
- package/dist/interfaces/resource-interfaces.d.ts +25 -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 +14 -28
- 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/index.d.ts +1 -1
- package/dist/macros/index.js +2 -2
- package/dist/macros/index.js.map +1 -1
- 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 +3 -6
- 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.d.ts +16 -3
- package/dist/module-manager.js +55 -23
- package/dist/module-manager.js.map +1 -1
- package/dist/project-settings.d.ts +16 -3
- package/dist/project-settings.js +79 -14
- package/dist/project-settings.js.map +1 -1
- package/dist/resources/calculation-resource.d.ts +6 -33
- package/dist/resources/calculation-resource.js +11 -60
- package/dist/resources/calculation-resource.js.map +1 -1
- package/dist/resources/card-type-resource.d.ts +10 -22
- package/dist/resources/card-type-resource.js +46 -66
- package/dist/resources/card-type-resource.js.map +1 -1
- package/dist/resources/create-defaults.d.ts +3 -2
- package/dist/resources/create-defaults.js +3 -2
- package/dist/resources/create-defaults.js.map +1 -1
- package/dist/resources/field-type-resource.d.ts +8 -22
- package/dist/resources/field-type-resource.js +35 -60
- package/dist/resources/field-type-resource.js.map +1 -1
- package/dist/resources/file-resource.d.ts +14 -35
- package/dist/resources/file-resource.js +22 -301
- package/dist/resources/file-resource.js.map +1 -1
- package/dist/resources/folder-resource.d.ts +44 -66
- package/dist/resources/folder-resource.js +102 -149
- package/dist/resources/folder-resource.js.map +1 -1
- package/dist/resources/graph-model-resource.d.ts +9 -34
- package/dist/resources/graph-model-resource.js +18 -64
- package/dist/resources/graph-model-resource.js.map +1 -1
- package/dist/resources/graph-view-resource.d.ts +9 -29
- package/dist/resources/graph-view-resource.js +13 -48
- package/dist/resources/graph-view-resource.js.map +1 -1
- package/dist/resources/link-type-resource.d.ts +9 -23
- package/dist/resources/link-type-resource.js +11 -33
- package/dist/resources/link-type-resource.js.map +1 -1
- package/dist/resources/report-resource.d.ts +10 -23
- package/dist/resources/report-resource.js +20 -67
- package/dist/resources/report-resource.js.map +1 -1
- package/dist/resources/resource-object.d.ts +143 -23
- package/dist/resources/resource-object.js +369 -48
- package/dist/resources/resource-object.js.map +1 -1
- package/dist/resources/template-resource.d.ts +10 -17
- package/dist/resources/template-resource.js +19 -27
- package/dist/resources/template-resource.js.map +1 -1
- package/dist/resources/workflow-resource.d.ts +9 -25
- package/dist/resources/workflow-resource.js +25 -55
- 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-fact-builder.d.ts +25 -14
- package/dist/utils/clingo-fact-builder.js +27 -5
- package/dist/utils/clingo-fact-builder.js.map +1 -1
- package/dist/utils/clingo-facts.js +14 -7
- 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 +4 -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/resource-utils.d.ts +1 -0
- package/dist/utils/resource-utils.js +2 -1
- package/dist/utils/resource-utils.js.map +1 -1
- package/package.json +11 -11
- package/src/card-metadata-updater.ts +9 -7
- package/src/command-handler.ts +35 -23
- package/src/command-manager.ts +32 -19
- package/src/commands/create.ts +59 -160
- package/src/commands/edit.ts +16 -132
- package/src/commands/export.ts +71 -81
- package/src/commands/import.ts +26 -18
- package/src/commands/move.ts +143 -179
- package/src/commands/remove.ts +20 -59
- package/src/commands/rename.ts +45 -156
- package/src/commands/show.ts +153 -211
- package/src/commands/transition.ts +53 -58
- package/src/commands/update.ts +44 -23
- package/src/commands/validate.ts +108 -82
- package/src/containers/card-container.ts +200 -360
- package/src/containers/project/calculation-engine.ts +81 -105
- package/src/containers/project/card-cache.ts +497 -0
- package/src/containers/project/project-paths.ts +21 -13
- package/src/containers/project/resource-cache.ts +648 -0
- package/src/containers/project/resource-handler.ts +265 -0
- package/src/containers/project.ts +551 -693
- package/src/containers/template.ts +129 -142
- package/src/index.ts +1 -0
- package/src/interfaces/folder-content-interfaces.ts +14 -7
- package/src/interfaces/macros.ts +2 -0
- package/src/interfaces/project-interfaces.ts +14 -7
- package/src/interfaces/resource-interfaces.ts +30 -27
- package/src/macros/createCards/index.ts +1 -12
- package/src/macros/createCards/types.ts +46 -0
- package/src/macros/graph/index.ts +27 -52
- 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/index.ts +2 -2
- package/src/macros/percentage/index.ts +1 -7
- package/src/macros/percentage/types.ts +32 -0
- package/src/macros/report/index.ts +4 -13
- 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 +79 -22
- package/src/project-settings.ts +84 -15
- package/src/resources/calculation-resource.ts +21 -91
- package/src/resources/card-type-resource.ts +74 -109
- package/src/resources/create-defaults.ts +3 -2
- package/src/resources/field-type-resource.ts +61 -104
- package/src/resources/file-resource.ts +33 -441
- package/src/resources/folder-resource.ts +130 -207
- package/src/resources/graph-model-resource.ts +36 -95
- package/src/resources/graph-view-resource.ts +28 -70
- package/src/resources/link-type-resource.ts +23 -53
- package/src/resources/report-resource.ts +34 -96
- package/src/resources/resource-object.ts +511 -66
- package/src/resources/template-resource.ts +32 -44
- package/src/resources/workflow-resource.ts +42 -85
- package/src/utils/card-utils.ts +217 -31
- package/src/utils/clingo-fact-builder.ts +28 -16
- package/src/utils/clingo-facts.ts +16 -7
- package/src/utils/clingo-parser.ts +1 -1
- package/src/utils/constants.ts +6 -0
- package/src/utils/csv.ts +1 -1
- package/src/utils/resource-utils.ts +2 -1
- package/dist/containers/project/resource-collector.d.ts +0 -87
- package/dist/containers/project/resource-collector.js +0 -337
- package/dist/containers/project/resource-collector.js.map +0 -1
- package/src/containers/project/resource-collector.ts +0 -396
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transition.js","sourceRoot":"","sources":["../../src/commands/transition.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;EAWE;AAEF,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"transition.js","sourceRoot":"","sources":["../../src/commands/transition.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;EAWE;AAEF,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAIlE;;GAEG;AACH,MAAM,OAAO,UAAU;IAKD;IAJpB;;;OAGG;IACH,YAAoB,OAAgB;QAAhB,YAAO,GAAP,OAAO,CAAS;IAAG,CAAC;IAExC,qCAAqC;IAC7B,KAAK,CAAC,sBAAsB,CAAC,OAAe,EAAE,UAAkB;QACtE,IAAI,CAAC,OAAO,IAAI,CAAC,UAAU;YAAE,OAAO,SAAS,CAAC;QAC9C,OAAO,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,QAAQ,CAAC,cAAc,EAAE,UAAU,EAAE;YACzE,OAAO;YACP,UAAU;SACX,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,cAAc,CAAC,OAAe,EAAE,UAAyB;QACpE,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAE5C,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,8BA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EAAE,YAAY,KAAK,SAAS,EAC7C,CAAC;oBACD,OAAO;gBACT,CAAC;gBACD,MAAM,cAAc,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC,CAAE,CAAC,YAAY,CAAC;gBACvD,OAAO,mBAAmB,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;YACjE,CAAC,CAAC;iBACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;CACF"}
|
|
@@ -10,18 +10,34 @@
|
|
|
10
10
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
11
11
|
*/
|
|
12
12
|
import type { OperationFor, UpdateOperations } from '../resources/resource-object.js';
|
|
13
|
-
import { Project } from '../containers/project.js';
|
|
13
|
+
import type { Project } from '../containers/project.js';
|
|
14
|
+
import type { UpdateKey } from '../interfaces/resource-interfaces.js';
|
|
14
15
|
/**
|
|
15
16
|
* Class that handles 'update' commands.
|
|
16
17
|
*/
|
|
17
18
|
export declare class Update {
|
|
18
19
|
private project;
|
|
20
|
+
/**
|
|
21
|
+
* Creates an instance of Update command.
|
|
22
|
+
* @param project Project to use.
|
|
23
|
+
*/
|
|
19
24
|
constructor(project: Project);
|
|
25
|
+
/**
|
|
26
|
+
* Update single resource property
|
|
27
|
+
* This is similar to updateValue, but allows the operation to be fully specified
|
|
28
|
+
* @param name Name of the resource to operate on.
|
|
29
|
+
* @param updateKey Property to change in resource or in resource content.
|
|
30
|
+
* @param operation The full operation object
|
|
31
|
+
* @template Type Type of the target of the operation
|
|
32
|
+
* @template T Type of operation ('add', 'remove', 'change', 'rank')
|
|
33
|
+
* @template K Type of the key to change
|
|
34
|
+
*/
|
|
35
|
+
applyResourceOperation<Type, T extends UpdateOperations, K extends string>(name: string, updateKey: UpdateKey<K>, operation: OperationFor<Type, T>): Promise<void>;
|
|
20
36
|
/**
|
|
21
37
|
* Updates single resource property.
|
|
22
38
|
* @param name Name of the resource to operate on.
|
|
23
39
|
* @param operation Operation to perform ('add', 'remove', 'change', 'rank')
|
|
24
|
-
* @param key Property to change in resource JSON
|
|
40
|
+
* @param key Property to change in resource JSON. If content, content/<property>
|
|
25
41
|
* @param value Value for 'key'
|
|
26
42
|
* @param optionalDetail Additional detail needed for some operations. For example, 'update' needs a new value.
|
|
27
43
|
* @param mappingTable Optional mapping table for workflow state transitions (only used for workflow changes)
|
|
@@ -30,14 +46,4 @@ export declare class Update {
|
|
|
30
46
|
mappingTable?: {
|
|
31
47
|
stateMapping: Record<string, string>;
|
|
32
48
|
}): Promise<void>;
|
|
33
|
-
/**
|
|
34
|
-
* Update single resource property
|
|
35
|
-
* This is similar to updateValue, but allows the operation to be fully specified
|
|
36
|
-
* @param name Name of the resource to operate on.
|
|
37
|
-
* @param key Property to change in resource JSON
|
|
38
|
-
* @param operation The full operation object
|
|
39
|
-
* @template Type Type of the target of the operation
|
|
40
|
-
* @template T Type of operation ('add', 'remove', 'change', 'rank')
|
|
41
|
-
*/
|
|
42
|
-
applyResourceOperation<Type, T extends UpdateOperations>(name: string, key: string, operation: OperationFor<Type, T>): Promise<void>;
|
|
43
49
|
}
|
package/dist/commands/update.js
CHANGED
|
@@ -9,21 +9,38 @@
|
|
|
9
9
|
You should have received a copy of the GNU Affero General Public
|
|
10
10
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
11
11
|
*/
|
|
12
|
-
import { Project } from '../containers/project.js';
|
|
13
|
-
import { resourceName } from '../utils/resource-utils.js';
|
|
14
12
|
/**
|
|
15
13
|
* Class that handles 'update' commands.
|
|
16
14
|
*/
|
|
17
15
|
export class Update {
|
|
18
16
|
project;
|
|
17
|
+
/**
|
|
18
|
+
* Creates an instance of Update command.
|
|
19
|
+
* @param project Project to use.
|
|
20
|
+
*/
|
|
19
21
|
constructor(project) {
|
|
20
22
|
this.project = project;
|
|
21
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Update single resource property
|
|
26
|
+
* This is similar to updateValue, but allows the operation to be fully specified
|
|
27
|
+
* @param name Name of the resource to operate on.
|
|
28
|
+
* @param updateKey Property to change in resource or in resource content.
|
|
29
|
+
* @param operation The full operation object
|
|
30
|
+
* @template Type Type of the target of the operation
|
|
31
|
+
* @template T Type of operation ('add', 'remove', 'change', 'rank')
|
|
32
|
+
* @template K Type of the key to change
|
|
33
|
+
*/
|
|
34
|
+
async applyResourceOperation(name, updateKey, operation) {
|
|
35
|
+
const type = this.project.resources.extractType(name);
|
|
36
|
+
const resource = this.project.resources.byType(name, type);
|
|
37
|
+
await resource?.update(updateKey, operation);
|
|
38
|
+
}
|
|
22
39
|
/**
|
|
23
40
|
* Updates single resource property.
|
|
24
41
|
* @param name Name of the resource to operate on.
|
|
25
42
|
* @param operation Operation to perform ('add', 'remove', 'change', 'rank')
|
|
26
|
-
* @param key Property to change in resource JSON
|
|
43
|
+
* @param key Property to change in resource JSON. If content, content/<property>
|
|
27
44
|
* @param value Value for 'key'
|
|
28
45
|
* @param optionalDetail Additional detail needed for some operations. For example, 'update' needs a new value.
|
|
29
46
|
* @param mappingTable Optional mapping table for workflow state transitions (only used for workflow changes)
|
|
@@ -62,21 +79,20 @@ export class Update {
|
|
|
62
79
|
? optionalDetail
|
|
63
80
|
: undefined;
|
|
64
81
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
this.project.collectLocalResources();
|
|
82
|
+
const splitKey = key.split('/');
|
|
83
|
+
if (splitKey.length !== 1 && splitKey.length !== 2) {
|
|
84
|
+
throw new Error(`Invalid key format: ${key}. Use 'property' or 'content/<property>'.`);
|
|
85
|
+
}
|
|
86
|
+
if (splitKey.length === 2 && splitKey[0] !== 'content') {
|
|
87
|
+
throw new Error(`Invalid key format: ${key}. When using 'content', always use as 'content/<property>'.`);
|
|
88
|
+
}
|
|
89
|
+
const [parsedKey, subKey] = splitKey;
|
|
90
|
+
if (parsedKey === 'content') {
|
|
91
|
+
await this.applyResourceOperation(name, { key: parsedKey, subKey }, op);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
await this.applyResourceOperation(name, { key: parsedKey }, op);
|
|
95
|
+
}
|
|
80
96
|
}
|
|
81
97
|
}
|
|
82
98
|
//# sourceMappingURL=update.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../src/commands/update.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;
|
|
1
|
+
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../src/commands/update.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAcF;;GAEG;AACH,MAAM,OAAO,MAAM;IAKG;IAJpB;;;OAGG;IACH,YAAoB,OAAgB;QAAhB,YAAO,GAAP,OAAO,CAAS;IAAG,CAAC;IAExC;;;;;;;;;OASG;IACI,KAAK,CAAC,sBAAsB,CAIjC,IAAY,EAAE,SAAuB,EAAE,SAAgC;QACvE,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACtD,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC3D,MAAM,QAAQ,EAAE,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;;;;OAQG;IACI,KAAK,CAAC,WAAW,CACtB,IAAY,EACZ,SAA2B,EAC3B,GAAW,EACX,KAAW,EACX,cAAqB,EAAE,kEAAkE;IACzF,YAAuD;QAEvD,MAAM,EAAE,GAAoB;YAC1B,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,EAAU;YAClB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G,6DAA6D,CACxF,CAAC;QACJ,CAAC;QACD,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC;QACrC,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,MAAM,IAAI,CAAC,sBAAsB,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;QAC1E,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,CAAC,sBAAsB,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;CACF"}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
import { Validator as JSONValidator } from 'jsonschema';
|
|
14
14
|
import { Validator as DirectoryValidator } from 'directory-schema-validator';
|
|
15
15
|
import type { Card, ResourceTypes } from '../interfaces/project-interfaces.js';
|
|
16
|
-
import { Project } from '../containers/project.js';
|
|
16
|
+
import type { Project } from '../containers/project.js';
|
|
17
17
|
import { type ResourceName } from '../utils/resource-utils.js';
|
|
18
18
|
export interface LengthProvider {
|
|
19
19
|
length: number;
|
|
@@ -37,12 +37,14 @@ export declare class Validate {
|
|
|
37
37
|
static cardMetadataFile: string;
|
|
38
38
|
static dotSchemaSchemaId: string;
|
|
39
39
|
static parameterSchemaFile: string;
|
|
40
|
+
/**
|
|
41
|
+
* Creates an instance of Validate command.
|
|
42
|
+
*/
|
|
40
43
|
constructor();
|
|
41
44
|
private length;
|
|
42
45
|
private addChildSchemas;
|
|
43
46
|
private checkResourceName;
|
|
44
47
|
private fullPath;
|
|
45
|
-
private getAndCacheResource;
|
|
46
48
|
private parseValidatorMessage;
|
|
47
49
|
private readAndValidateContentFiles;
|
|
48
50
|
private removeDuplicateEntries;
|
|
@@ -53,7 +55,7 @@ export declare class Validate {
|
|
|
53
55
|
private validType;
|
|
54
56
|
/**
|
|
55
57
|
* Validates that new identifier of a resource is according to naming convention.
|
|
56
|
-
* @param identifier
|
|
58
|
+
* @param identifier Resource identifier
|
|
57
59
|
* returns true if identifier is valid, and false otherwise.
|
|
58
60
|
*/
|
|
59
61
|
static isValidIdentifierName(identifier: string): boolean;
|
|
@@ -100,9 +102,12 @@ export declare class Validate {
|
|
|
100
102
|
* @param resourceType Type of resource
|
|
101
103
|
* @param name Name of resource
|
|
102
104
|
* @param prefixes currently used project prefixes
|
|
105
|
+
* @throws when resource is not from given prefixes,
|
|
106
|
+
* or when actual resource does not match the type,
|
|
107
|
+
* or when identifier name is not valid
|
|
103
108
|
* @returns resource name as valid resource name; throws in error cases.
|
|
104
109
|
*/
|
|
105
|
-
validResourceName(resourceType: ResourceTypes, name: string, prefixes: string[]):
|
|
110
|
+
validResourceName(resourceType: ResourceTypes, name: string, prefixes: string[]): string;
|
|
106
111
|
/**
|
|
107
112
|
* Validates that 'prefix' is valid project prefix.
|
|
108
113
|
* @param prefix project prefix
|
|
@@ -113,26 +118,29 @@ export declare class Validate {
|
|
|
113
118
|
* Validates that card's custom fields are according to schema and have correct data in them.
|
|
114
119
|
* @param project currently used Project
|
|
115
120
|
* @param card specific card
|
|
116
|
-
* @
|
|
121
|
+
* @throws when card does not have metadata
|
|
122
|
+
* @returns validation errors, if any.
|
|
117
123
|
*/
|
|
118
|
-
validateCustomFields(project: Project, card: Card): Promise<string>;
|
|
124
|
+
validateCustomFields(project: Project, card: Card, prefixes: string[]): Promise<string>;
|
|
119
125
|
/**
|
|
120
126
|
* Validates the labels of a card
|
|
121
127
|
* @param card card to validate. Card must have metadata.
|
|
128
|
+
* @returns validation errors, if any.
|
|
122
129
|
*/
|
|
123
|
-
validateCardLabels(card: Card):
|
|
130
|
+
validateCardLabels(card: Card): string;
|
|
124
131
|
/**
|
|
125
132
|
* Checks if card's current workflow state matches workflow that card's card type is using.
|
|
126
133
|
* Template cards are expected to have empty workflow state.
|
|
127
134
|
* @param project Project object.
|
|
128
135
|
* @param card Card object to validate
|
|
129
|
-
* @returns
|
|
136
|
+
* @returns validation errors, if any.
|
|
130
137
|
*/
|
|
131
138
|
validateWorkflowState(project: Project, card: Card): Promise<string>;
|
|
132
139
|
/**
|
|
133
140
|
* Validates a single resource.
|
|
134
|
-
* @param
|
|
135
|
-
* @
|
|
141
|
+
* @param resourceName Resource to validate
|
|
142
|
+
* @param project Project instance to use.
|
|
143
|
+
* @returns validation errors, if any.
|
|
136
144
|
*/
|
|
137
145
|
validateResource(resourceName: ResourceName, project: Project): Promise<string>;
|
|
138
146
|
/**
|
|
@@ -18,15 +18,15 @@ import { Validator as DirectoryValidator } from 'directory-schema-validator';
|
|
|
18
18
|
import { parentSchema, schemas } from '@cyberismo/assets';
|
|
19
19
|
import { errorFunction } from '../utils/error-utils.js';
|
|
20
20
|
import { isTemplateCard } from '../utils/card-utils.js';
|
|
21
|
+
import { isPredefinedField } from '../utils/constants.js';
|
|
21
22
|
import { pathExists } from '../utils/file-utils.js';
|
|
22
|
-
import { Project } from '../containers/project.js';
|
|
23
23
|
import { readJsonFile } from '../utils/json.js';
|
|
24
24
|
import { resourceName } from '../utils/resource-utils.js';
|
|
25
25
|
const invalidNames = new RegExp('[<>:"/\\|?*\x00-\x1F]|^(?:aux|con|clock$|nul|prn|com[1-9]|lpt[1-9])$');
|
|
26
26
|
const SHORT_TEXT_MAX_LENGTH = 80;
|
|
27
27
|
import * as EmailValidator from 'email-validator';
|
|
28
28
|
import { evaluateMacros } from '../macros/index.js';
|
|
29
|
-
const baseDir = import.meta.dirname;
|
|
29
|
+
const baseDir = import.meta.dirname ?? new URL('.', import.meta.url).pathname;
|
|
30
30
|
const subFoldersToValidate = ['.cards', 'cardRoot'];
|
|
31
31
|
/**
|
|
32
32
|
* Validates content.
|
|
@@ -47,6 +47,9 @@ export class Validate {
|
|
|
47
47
|
static cardMetadataFile = 'index.json';
|
|
48
48
|
static dotSchemaSchemaId = '/dotSchema';
|
|
49
49
|
static parameterSchemaFile = 'parameterSchema.json';
|
|
50
|
+
/**
|
|
51
|
+
* Creates an instance of Validate command.
|
|
52
|
+
*/
|
|
50
53
|
constructor() {
|
|
51
54
|
Validate.baseFolder = pathExists(join(process.cwd(), '../../schema', 'cardTreeDirectorySchema.json'))
|
|
52
55
|
? join(process.cwd(), '../../schema')
|
|
@@ -102,18 +105,7 @@ export class Validate {
|
|
|
102
105
|
fullPath(file) {
|
|
103
106
|
return join(file.parentPath, file.name);
|
|
104
107
|
}
|
|
105
|
-
//
|
|
106
|
-
// If value is already cached, returns from cache.
|
|
107
|
-
async getAndCacheResource(project, cachedValues, valueName) {
|
|
108
|
-
return (cachedValues.get(valueName) ||
|
|
109
|
-
project.resource(valueName).then((resource) => {
|
|
110
|
-
if (!resource) {
|
|
111
|
-
return undefined;
|
|
112
|
-
}
|
|
113
|
-
cachedValues.set(valueName, resource);
|
|
114
|
-
return resource;
|
|
115
|
-
}));
|
|
116
|
-
}
|
|
108
|
+
// Parses validator messages
|
|
117
109
|
parseValidatorMessage(errorObject) {
|
|
118
110
|
let parsedErrorMessage = '';
|
|
119
111
|
// todo: get schema name here?
|
|
@@ -155,7 +147,7 @@ export class Validate {
|
|
|
155
147
|
async readAndValidateContentFiles(project, path) {
|
|
156
148
|
const message = [];
|
|
157
149
|
try {
|
|
158
|
-
const prefixes =
|
|
150
|
+
const prefixes = project.projectPrefixes();
|
|
159
151
|
const files = await readdir(path, {
|
|
160
152
|
withFileTypes: true,
|
|
161
153
|
});
|
|
@@ -266,7 +258,13 @@ export class Validate {
|
|
|
266
258
|
const errors = [];
|
|
267
259
|
if (cardType && fieldArray) {
|
|
268
260
|
const validationPromises = fieldArray.map(async (field) => {
|
|
269
|
-
|
|
261
|
+
let fieldType;
|
|
262
|
+
try {
|
|
263
|
+
fieldType = project.resources.byType(field, 'fieldTypes').show();
|
|
264
|
+
}
|
|
265
|
+
catch {
|
|
266
|
+
fieldType = undefined;
|
|
267
|
+
}
|
|
270
268
|
if (!fieldType) {
|
|
271
269
|
return `Card type '${cardType.name}' has invalid reference to unknown ${nameOfArray} '${field}'`;
|
|
272
270
|
}
|
|
@@ -329,7 +327,7 @@ export class Validate {
|
|
|
329
327
|
}
|
|
330
328
|
/**
|
|
331
329
|
* Validates that new identifier of a resource is according to naming convention.
|
|
332
|
-
* @param identifier
|
|
330
|
+
* @param identifier Resource identifier
|
|
333
331
|
* returns true if identifier is valid, and false otherwise.
|
|
334
332
|
*/
|
|
335
333
|
static isValidIdentifierName(identifier) {
|
|
@@ -391,15 +389,17 @@ export class Validate {
|
|
|
391
389
|
else {
|
|
392
390
|
const errorMsg = [];
|
|
393
391
|
const project = projectFn();
|
|
392
|
+
await project.populateCaches();
|
|
394
393
|
// Then, validate that each 'contentSchema' children as well.
|
|
395
394
|
const result = await this.readAndValidateContentFiles(project, projectPath);
|
|
396
395
|
if (result.length > 0) {
|
|
397
396
|
errorMsg.push(...result);
|
|
398
397
|
}
|
|
399
398
|
// Finally, validate that each card is correct
|
|
400
|
-
const cards =
|
|
401
|
-
cards.push(...
|
|
399
|
+
const cards = project.cards();
|
|
400
|
+
cards.push(...project.allTemplateCards());
|
|
402
401
|
const cardIds = new Map();
|
|
402
|
+
const allPrefixes = await project.projectPrefixes();
|
|
403
403
|
for (const card of cards) {
|
|
404
404
|
if (cardIds.has(card.key)) {
|
|
405
405
|
cardIds.set(card.key, (cardIds.get(card.key) || 0) + 1);
|
|
@@ -408,7 +408,6 @@ export class Validate {
|
|
|
408
408
|
cardIds.set(card.key, 1);
|
|
409
409
|
}
|
|
410
410
|
if (card.metadata) {
|
|
411
|
-
// validate card's workflow
|
|
412
411
|
if (!isTemplateCard(card)) {
|
|
413
412
|
const validWorkflow = await this.validateWorkflowState(project, card);
|
|
414
413
|
if (validWorkflow.length !== 0) {
|
|
@@ -416,7 +415,7 @@ export class Validate {
|
|
|
416
415
|
}
|
|
417
416
|
}
|
|
418
417
|
}
|
|
419
|
-
const validCustomFields = await this.validateCustomFields(project, card);
|
|
418
|
+
const validCustomFields = await this.validateCustomFields(project, card, allPrefixes);
|
|
420
419
|
if (validCustomFields.length !== 0) {
|
|
421
420
|
errorMsg.push(validCustomFields);
|
|
422
421
|
}
|
|
@@ -429,7 +428,7 @@ export class Validate {
|
|
|
429
428
|
await evaluateMacros(card.content, {
|
|
430
429
|
context: 'localApp',
|
|
431
430
|
mode: 'validate',
|
|
432
|
-
project,
|
|
431
|
+
project: project,
|
|
433
432
|
cardKey: card.key,
|
|
434
433
|
});
|
|
435
434
|
}
|
|
@@ -492,17 +491,16 @@ export class Validate {
|
|
|
492
491
|
* @param resourceType Type of resource
|
|
493
492
|
* @param name Name of resource
|
|
494
493
|
* @param prefixes currently used project prefixes
|
|
494
|
+
* @throws when resource is not from given prefixes,
|
|
495
|
+
* or when actual resource does not match the type,
|
|
496
|
+
* or when identifier name is not valid
|
|
495
497
|
* @returns resource name as valid resource name; throws in error cases.
|
|
496
498
|
*/
|
|
497
|
-
|
|
499
|
+
validResourceName(resourceType, name, prefixes) {
|
|
498
500
|
const resource = resourceName(name);
|
|
499
501
|
resource.type = resource.type ? resource.type : resourceType;
|
|
500
|
-
// a bit shaky way to ensure that prefix is set; first of the project prefixes should be the actual project prefix.
|
|
501
502
|
if (resource.prefix === '') {
|
|
502
|
-
|
|
503
|
-
if (resource.prefix === '') {
|
|
504
|
-
throw new Error(`Project prefix cannot be empty string`);
|
|
505
|
-
}
|
|
503
|
+
throw new Error(`Project prefix cannot be empty string`);
|
|
506
504
|
}
|
|
507
505
|
if (!prefixes.includes(resource.prefix)) {
|
|
508
506
|
throw new Error(`Resource name can only refer to project that it is part of. Prefix '${resource.prefix}' is not included in '[${prefixes.join(',')}]'`);
|
|
@@ -530,14 +528,23 @@ export class Validate {
|
|
|
530
528
|
* Validates that card's custom fields are according to schema and have correct data in them.
|
|
531
529
|
* @param project currently used Project
|
|
532
530
|
* @param card specific card
|
|
533
|
-
* @
|
|
531
|
+
* @throws when card does not have metadata
|
|
532
|
+
* @returns validation errors, if any.
|
|
534
533
|
*/
|
|
535
|
-
async validateCustomFields(project, card) {
|
|
534
|
+
async validateCustomFields(project, card, prefixes) {
|
|
536
535
|
const validationErrors = [];
|
|
537
536
|
if (!card.metadata) {
|
|
538
537
|
throw new Error(`Card '${card.key}' has no metadata. Card object needs to be instantiated with '{metadata: true}'`);
|
|
539
538
|
}
|
|
540
|
-
|
|
539
|
+
let cardType;
|
|
540
|
+
try {
|
|
541
|
+
cardType = project.resources
|
|
542
|
+
.byType(card.metadata?.cardType, 'cardTypes')
|
|
543
|
+
.show();
|
|
544
|
+
}
|
|
545
|
+
catch {
|
|
546
|
+
cardType = undefined;
|
|
547
|
+
}
|
|
541
548
|
if (!cardType) {
|
|
542
549
|
validationErrors.push(`Card '${card.key}' has invalid card type '${card.metadata?.cardType}'`);
|
|
543
550
|
return validationErrors.join('\n');
|
|
@@ -548,9 +555,18 @@ export class Validate {
|
|
|
548
555
|
fieldErrors = await this.validateArrayOfFields(project, cardType, cardType.alwaysVisibleFields, 'always visible fields');
|
|
549
556
|
validationErrors.push(...fieldErrors);
|
|
550
557
|
for (const field of cardType.customFields) {
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
558
|
+
let fieldType;
|
|
559
|
+
try {
|
|
560
|
+
fieldType = await project.resources
|
|
561
|
+
.byType(field.name, 'fieldTypes')
|
|
562
|
+
.show();
|
|
563
|
+
}
|
|
564
|
+
catch {
|
|
565
|
+
fieldType = undefined;
|
|
566
|
+
}
|
|
567
|
+
if (!fieldType) {
|
|
568
|
+
validationErrors.push(`In card '${card.key}' field '${field.name}' is missing from project\n`);
|
|
569
|
+
continue;
|
|
554
570
|
}
|
|
555
571
|
if (field.isCalculated) {
|
|
556
572
|
if (card.metadata[field.name] !== undefined) {
|
|
@@ -564,11 +580,6 @@ export class Validate {
|
|
|
564
580
|
continue;
|
|
565
581
|
}
|
|
566
582
|
}
|
|
567
|
-
const fieldType = await this.getAndCacheResource(project, this.validatedFieldTypes, field.name);
|
|
568
|
-
if (!fieldType) {
|
|
569
|
-
validationErrors.push(`In card '${card.key}' field '${field.name}' is missing from project\n`);
|
|
570
|
-
continue;
|
|
571
|
-
}
|
|
572
583
|
if (!this.validType(card.metadata[field.name], fieldType)) {
|
|
573
584
|
const typeOfValue = typeof card.metadata[field.name];
|
|
574
585
|
let fieldValue = card.metadata[field.name];
|
|
@@ -589,13 +600,40 @@ export class Validate {
|
|
|
589
600
|
validationErrors.push(`In card '${card.key}' field '${field.name}' is defined as '${fieldType.dataType}', but it is '${typeOfValue}' with value of ${fieldValue}\n`);
|
|
590
601
|
}
|
|
591
602
|
}
|
|
603
|
+
// Validate that all metadata keys are either predefined fields or valid field type names
|
|
604
|
+
for (const key of Object.keys(card.metadata)) {
|
|
605
|
+
if (isPredefinedField(key) ||
|
|
606
|
+
key === 'labels' ||
|
|
607
|
+
key === 'links') {
|
|
608
|
+
continue;
|
|
609
|
+
}
|
|
610
|
+
try {
|
|
611
|
+
this.validResourceName('fieldTypes', key, prefixes);
|
|
612
|
+
}
|
|
613
|
+
catch {
|
|
614
|
+
validationErrors.push(`Card '${card.key}' has invalid metadata key '${key}'`);
|
|
615
|
+
continue;
|
|
616
|
+
}
|
|
617
|
+
// Check that the card's fieldType exists in the project
|
|
618
|
+
let fieldType;
|
|
619
|
+
try {
|
|
620
|
+
fieldType = await project.resources.byType(key, 'fieldTypes').show();
|
|
621
|
+
}
|
|
622
|
+
catch {
|
|
623
|
+
fieldType = undefined;
|
|
624
|
+
}
|
|
625
|
+
if (!fieldType) {
|
|
626
|
+
validationErrors.push(`Card '${card.key}' has field '${key}' that does not exist in the project`);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
592
629
|
return validationErrors.join('\n');
|
|
593
630
|
}
|
|
594
631
|
/**
|
|
595
632
|
* Validates the labels of a card
|
|
596
633
|
* @param card card to validate. Card must have metadata.
|
|
634
|
+
* @returns validation errors, if any.
|
|
597
635
|
*/
|
|
598
|
-
|
|
636
|
+
validateCardLabels(card) {
|
|
599
637
|
const validationErrors = [];
|
|
600
638
|
if (!card.metadata) {
|
|
601
639
|
validationErrors.push(`Card '${card.key}' has no metadata. Card object needs to be instantiated with '{metadata: true}'`);
|
|
@@ -621,15 +659,22 @@ export class Validate {
|
|
|
621
659
|
* Template cards are expected to have empty workflow state.
|
|
622
660
|
* @param project Project object.
|
|
623
661
|
* @param card Card object to validate
|
|
624
|
-
* @returns
|
|
662
|
+
* @returns validation errors, if any.
|
|
625
663
|
*/
|
|
626
664
|
async validateWorkflowState(project, card) {
|
|
627
665
|
const validationErrors = [];
|
|
628
666
|
if (!card.metadata) {
|
|
629
667
|
validationErrors.push(`Card '${card.key}' has no metadata. Card object needs to be instantiated with '{metadata: true}'`);
|
|
630
668
|
}
|
|
631
|
-
|
|
632
|
-
|
|
669
|
+
let cardType;
|
|
670
|
+
try {
|
|
671
|
+
cardType = card.metadata?.cardType
|
|
672
|
+
? project.resources.byType(card.metadata?.cardType, 'cardTypes').show()
|
|
673
|
+
: undefined;
|
|
674
|
+
}
|
|
675
|
+
catch {
|
|
676
|
+
cardType = undefined;
|
|
677
|
+
}
|
|
633
678
|
if (!cardType) {
|
|
634
679
|
validationErrors.push(`Card '${card.key}' has invalid card type '${card.metadata?.cardType}'`);
|
|
635
680
|
return validationErrors.join('\n');
|
|
@@ -638,7 +683,15 @@ export class Validate {
|
|
|
638
683
|
validationErrors.push(`Card type '${card.metadata?.cardType}' does not have 'workflow'`);
|
|
639
684
|
return validationErrors.join('\n');
|
|
640
685
|
}
|
|
641
|
-
|
|
686
|
+
let workflow;
|
|
687
|
+
try {
|
|
688
|
+
workflow = project.resources
|
|
689
|
+
.byType(cardType.workflow, 'workflows')
|
|
690
|
+
.show();
|
|
691
|
+
}
|
|
692
|
+
catch {
|
|
693
|
+
workflow = undefined;
|
|
694
|
+
}
|
|
642
695
|
if (!workflow) {
|
|
643
696
|
validationErrors.push(`Workflow of '${cardType.workflow}' card type '${card.metadata?.cardType}' does not exist in the project`);
|
|
644
697
|
return validationErrors.join('\n');
|
|
@@ -659,12 +712,13 @@ export class Validate {
|
|
|
659
712
|
}
|
|
660
713
|
/**
|
|
661
714
|
* Validates a single resource.
|
|
662
|
-
* @param
|
|
663
|
-
* @
|
|
715
|
+
* @param resourceName Resource to validate
|
|
716
|
+
* @param project Project instance to use.
|
|
717
|
+
* @returns validation errors, if any.
|
|
664
718
|
*/
|
|
665
719
|
async validateResource(resourceName, project) {
|
|
666
720
|
try {
|
|
667
|
-
const resource =
|
|
721
|
+
const resource = project.resources.byType(resourceName);
|
|
668
722
|
await resource.validate();
|
|
669
723
|
return '';
|
|
670
724
|
}
|