@cyberismo/data-handler 0.0.15 → 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 +7 -1
- package/dist/card-metadata-updater.js.map +1 -1
- package/dist/command-handler.d.ts +4 -0
- package/dist/command-handler.js +19 -3
- package/dist/command-handler.js.map +1 -1
- package/dist/command-manager.d.ts +24 -1
- package/dist/command-manager.js +27 -3
- package/dist/command-manager.js.map +1 -1
- package/dist/commands/create.d.ts +1 -1
- package/dist/commands/create.js +34 -36
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/export.d.ts +11 -2
- package/dist/commands/export.js +54 -41
- package/dist/commands/export.js.map +1 -1
- package/dist/commands/import.d.ts +9 -1
- package/dist/commands/import.js +15 -7
- package/dist/commands/import.js.map +1 -1
- package/dist/commands/move.js +0 -1
- package/dist/commands/move.js.map +1 -1
- package/dist/commands/remove.d.ts +8 -1
- package/dist/commands/remove.js +8 -4
- package/dist/commands/remove.js.map +1 -1
- package/dist/commands/rename.d.ts +4 -9
- package/dist/commands/rename.js +32 -101
- package/dist/commands/rename.js.map +1 -1
- package/dist/commands/show.d.ts +16 -10
- package/dist/commands/show.js +71 -55
- package/dist/commands/show.js.map +1 -1
- package/dist/commands/transition.d.ts +9 -2
- package/dist/commands/transition.js +25 -17
- package/dist/commands/transition.js.map +1 -1
- package/dist/commands/update.d.ts +16 -12
- package/dist/commands/update.js +19 -17
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/validate.d.ts +17 -9
- package/dist/commands/validate.js +96 -35
- package/dist/commands/validate.js.map +1 -1
- package/dist/containers/project/calculation-engine.d.ts +7 -4
- package/dist/containers/project/calculation-engine.js +61 -66
- package/dist/containers/project/calculation-engine.js.map +1 -1
- 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 +38 -153
- package/dist/containers/project.js +129 -405
- package/dist/containers/project.js.map +1 -1
- package/dist/containers/template.d.ts +8 -2
- package/dist/containers/template.js +20 -15
- package/dist/containers/template.js.map +1 -1
- package/dist/interfaces/folder-content-interfaces.d.ts +5 -3
- package/dist/interfaces/folder-content-interfaces.js +3 -3
- package/dist/interfaces/folder-content-interfaces.js.map +1 -1
- package/dist/interfaces/project-interfaces.d.ts +2 -4
- package/dist/interfaces/project-interfaces.js.map +1 -1
- package/dist/interfaces/resource-interfaces.d.ts +14 -1
- package/dist/interfaces/resource-interfaces.js.map +1 -1
- package/dist/macros/graph/index.js +12 -26
- package/dist/macros/graph/index.js.map +1 -1
- 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/report/index.js +3 -6
- package/dist/macros/report/index.js.map +1 -1
- package/dist/module-manager.d.ts +16 -3
- package/dist/module-manager.js +51 -19
- 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 +4 -3
- package/dist/resources/calculation-resource.js +11 -5
- package/dist/resources/calculation-resource.js.map +1 -1
- package/dist/resources/card-type-resource.d.ts +6 -1
- package/dist/resources/card-type-resource.js +34 -23
- 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 +4 -1
- package/dist/resources/field-type-resource.js +22 -23
- package/dist/resources/field-type-resource.js.map +1 -1
- package/dist/resources/file-resource.d.ts +5 -9
- package/dist/resources/file-resource.js +6 -11
- package/dist/resources/file-resource.js.map +1 -1
- package/dist/resources/folder-resource.d.ts +29 -32
- package/dist/resources/folder-resource.js +59 -78
- package/dist/resources/folder-resource.js.map +1 -1
- package/dist/resources/graph-model-resource.d.ts +4 -1
- package/dist/resources/graph-model-resource.js +11 -4
- package/dist/resources/graph-model-resource.js.map +1 -1
- package/dist/resources/graph-view-resource.d.ts +5 -2
- package/dist/resources/graph-view-resource.js +7 -3
- package/dist/resources/graph-view-resource.js.map +1 -1
- package/dist/resources/link-type-resource.d.ts +5 -2
- package/dist/resources/link-type-resource.js +5 -2
- package/dist/resources/link-type-resource.js.map +1 -1
- package/dist/resources/report-resource.d.ts +6 -7
- package/dist/resources/report-resource.js +14 -23
- package/dist/resources/report-resource.js.map +1 -1
- package/dist/resources/resource-object.d.ts +93 -8
- package/dist/resources/resource-object.js +162 -110
- package/dist/resources/resource-object.js.map +1 -1
- package/dist/resources/template-resource.d.ts +7 -3
- package/dist/resources/template-resource.js +10 -3
- package/dist/resources/template-resource.js.map +1 -1
- package/dist/resources/workflow-resource.d.ts +5 -2
- package/dist/resources/workflow-resource.js +18 -22
- package/dist/resources/workflow-resource.js.map +1 -1
- package/dist/utils/card-utils.d.ts +2 -2
- package/dist/utils/card-utils.js +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 +3 -4
- package/dist/utils/clingo-facts.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 +8 -8
- package/src/card-metadata-updater.ts +6 -2
- package/src/command-handler.ts +24 -5
- package/src/command-manager.ts +29 -17
- package/src/commands/create.ts +43 -78
- package/src/commands/export.ts +63 -52
- package/src/commands/import.ts +24 -14
- package/src/commands/move.ts +0 -1
- package/src/commands/remove.ts +11 -7
- package/src/commands/rename.ts +43 -149
- package/src/commands/show.ts +113 -78
- package/src/commands/transition.ts +26 -28
- package/src/commands/update.ts +25 -22
- package/src/commands/validate.ts +108 -67
- package/src/containers/project/calculation-engine.ts +61 -93
- 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 +178 -522
- package/src/containers/template.ts +24 -19
- package/src/interfaces/folder-content-interfaces.ts +7 -6
- package/src/interfaces/project-interfaces.ts +7 -6
- package/src/interfaces/resource-interfaces.ts +18 -3
- package/src/macros/graph/index.ts +26 -47
- package/src/macros/index.ts +2 -2
- package/src/macros/report/index.ts +3 -9
- package/src/module-manager.ts +74 -17
- package/src/project-settings.ts +83 -14
- package/src/resources/calculation-resource.ts +18 -18
- package/src/resources/card-type-resource.ts +50 -50
- package/src/resources/create-defaults.ts +3 -2
- package/src/resources/field-type-resource.ts +41 -55
- package/src/resources/file-resource.ts +10 -36
- package/src/resources/folder-resource.ts +69 -120
- package/src/resources/graph-model-resource.ts +20 -22
- package/src/resources/graph-view-resource.ts +15 -17
- package/src/resources/link-type-resource.ts +10 -13
- package/src/resources/report-resource.ts +21 -43
- package/src/resources/resource-object.ts +194 -152
- package/src/resources/template-resource.ts +17 -16
- package/src/resources/workflow-resource.ts +25 -44
- package/src/utils/card-utils.ts +2 -2
- package/src/utils/clingo-fact-builder.ts +28 -16
- package/src/utils/clingo-facts.ts +3 -4
- package/src/utils/resource-utils.ts +2 -1
- package/dist/containers/project/resource-collector.d.ts +0 -110
- package/dist/containers/project/resource-collector.js +0 -344
- package/dist/containers/project/resource-collector.js.map +0 -1
- package/src/containers/project/resource-collector.ts +0 -404
|
@@ -11,40 +11,30 @@
|
|
|
11
11
|
You should have received a copy of the GNU Affero General Public
|
|
12
12
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
13
13
|
*/
|
|
14
|
-
import { readdir } from 'node:fs/promises';
|
|
15
|
-
import { readFileSync } from 'node:fs';
|
|
16
14
|
import { extname, join } from 'node:path';
|
|
15
|
+
import { readdir } from 'node:fs/promises';
|
|
17
16
|
import { copyDir } from '../utils/file-utils.js';
|
|
18
|
-
import { DefaultContent
|
|
17
|
+
import { DefaultContent } from './create-defaults.js';
|
|
18
|
+
import { FolderResource } from './folder-resource.js';
|
|
19
19
|
import { getStaticDirectoryPath } from '@cyberismo/assets';
|
|
20
|
+
import { resourceNameToString } from '../utils/resource-utils.js';
|
|
21
|
+
import { sortCards } from '../utils/card-utils.js';
|
|
20
22
|
import { Validate } from '../commands/validate.js';
|
|
21
|
-
const REPORT_SCHEMA_FILE = 'parameterSchema.json';
|
|
22
23
|
const PARAMETER_SCHEMA_ID = 'jsonSchema';
|
|
23
|
-
const staticDirectoryPath = await getStaticDirectoryPath();
|
|
24
24
|
/**
|
|
25
25
|
* Report resource class.
|
|
26
26
|
*/
|
|
27
27
|
export class ReportResource extends FolderResource {
|
|
28
|
-
reportSchema;
|
|
29
28
|
constructor(project, name) {
|
|
30
29
|
super(project, name, 'reports');
|
|
31
30
|
this.contentSchemaId = 'reportSchema';
|
|
32
31
|
this.contentSchema = super.contentSchemaContent(this.contentSchemaId);
|
|
33
|
-
const schemaPath = join(this.internalFolder, REPORT_SCHEMA_FILE);
|
|
34
|
-
this.reportSchema = this.readSchemaFile(schemaPath);
|
|
35
32
|
}
|
|
36
33
|
// Path to content folder.
|
|
37
34
|
// @todo: create the files' content dynamically.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
const schema = readFileSync(path);
|
|
43
|
-
return JSON.parse(schema.toString());
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
return undefined;
|
|
47
|
-
}
|
|
35
|
+
async getDefaultReportLocation() {
|
|
36
|
+
const staticDirectoryPath = await getStaticDirectoryPath();
|
|
37
|
+
return join(staticDirectoryPath, 'defaultReport');
|
|
48
38
|
}
|
|
49
39
|
/**
|
|
50
40
|
* Handle name changes for reports
|
|
@@ -60,14 +50,14 @@ export class ReportResource extends FolderResource {
|
|
|
60
50
|
}
|
|
61
51
|
/**
|
|
62
52
|
* Sets new metadata into the report object.
|
|
63
|
-
* @param newContent metadata content for the report.
|
|
64
|
-
* @throws if 'newContent' is not valid.
|
|
65
53
|
*/
|
|
66
54
|
async createReport() {
|
|
67
55
|
const defaultContent = DefaultContent.report(resourceNameToString(this.resourceName));
|
|
68
56
|
await super.create(defaultContent);
|
|
69
57
|
// Copy report default structure to destination.
|
|
70
|
-
|
|
58
|
+
const defaultReportLocation = await this.getDefaultReportLocation();
|
|
59
|
+
await copyDir(defaultReportLocation, this.internalFolder);
|
|
60
|
+
await this.loadContentFiles();
|
|
71
61
|
}
|
|
72
62
|
/**
|
|
73
63
|
* Returns list of handlebar filenames that this report has.
|
|
@@ -126,8 +116,9 @@ export class ReportResource extends FolderResource {
|
|
|
126
116
|
* @note If content is not provided, base class validation will use resource's current content.
|
|
127
117
|
*/
|
|
128
118
|
async validate(content) {
|
|
129
|
-
|
|
130
|
-
|
|
119
|
+
const resourceContent = this.contentData();
|
|
120
|
+
if (resourceContent.schema) {
|
|
121
|
+
const errors = Validate.getInstance().validateJson(resourceContent.schema, PARAMETER_SCHEMA_ID);
|
|
131
122
|
if (errors.length > 0) {
|
|
132
123
|
throw new Error(`Invalid parameter schema: ${errors}`);
|
|
133
124
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"report-resource.js","sourceRoot":"","sources":["../../src/resources/report-resource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;EAYE;AAEF,OAAO,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"report-resource.js","sourceRoot":"","sources":["../../src/resources/report-resource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;EAYE;AAEF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM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see <https://www.gnu.org/licenses/>.
|
|
11
11
|
*/
|
|
12
|
+
import { type ResourceName } from '../utils/resource-utils.js';
|
|
12
13
|
import type { Card, ResourceFolderType } from '../interfaces/project-interfaces.js';
|
|
13
14
|
import type { Logger } from 'pino';
|
|
14
15
|
import type { Project } from '../containers/project.js';
|
|
15
16
|
import type { ResourceBaseMetadata, UpdateKey } from '../interfaces/resource-interfaces.js';
|
|
16
|
-
import { type ResourceName } from '../utils/resource-utils.js';
|
|
17
17
|
export type UpdateOperations = 'add' | 'change' | 'rank' | 'remove';
|
|
18
18
|
type BaseOperation<T> = {
|
|
19
19
|
name: 'add' | 'change' | 'rank' | 'remove';
|
|
@@ -57,7 +57,7 @@ export declare abstract class AbstractResource<T extends ResourceBaseMetadata, U
|
|
|
57
57
|
protected abstract delete(): Promise<void>;
|
|
58
58
|
protected abstract read(): Promise<void>;
|
|
59
59
|
protected abstract rename(newName: ResourceName): Promise<void>;
|
|
60
|
-
protected abstract show():
|
|
60
|
+
protected abstract show(): ShowReturnType<T, U>;
|
|
61
61
|
protected abstract update<Type, K extends string>(updateKey: UpdateKey<K>, operation: Operation<Type>): Promise<void>;
|
|
62
62
|
protected abstract usage(cards?: Card[]): Promise<string[]>;
|
|
63
63
|
protected abstract validate(content?: object): Promise<void>;
|
|
@@ -68,7 +68,6 @@ export declare abstract class AbstractResource<T extends ResourceBaseMetadata, U
|
|
|
68
68
|
export declare abstract class ResourceObject<T extends ResourceBaseMetadata, U> extends AbstractResource<T, U> {
|
|
69
69
|
protected project: Project;
|
|
70
70
|
protected resourceName: ResourceName;
|
|
71
|
-
private cache;
|
|
72
71
|
private static validateInstancePromise?;
|
|
73
72
|
protected content: T;
|
|
74
73
|
protected moduleResource: boolean;
|
|
@@ -81,18 +80,35 @@ export declare abstract class ResourceObject<T extends ResourceBaseMetadata, U>
|
|
|
81
80
|
* Path to the resource metadata file (the .json file).
|
|
82
81
|
*/
|
|
83
82
|
fileName: string;
|
|
83
|
+
/**
|
|
84
|
+
* Constructs a ResourceObject instance
|
|
85
|
+
* @param project Project where this resource is
|
|
86
|
+
* @param resourceName Name for the resource
|
|
87
|
+
* @param type Type of resource
|
|
88
|
+
*/
|
|
84
89
|
constructor(project: Project, resourceName: ResourceName, type: ResourceFolderType);
|
|
90
|
+
private exists;
|
|
85
91
|
private static getValidate;
|
|
86
|
-
private
|
|
92
|
+
private reportHandlerBarFiles;
|
|
87
93
|
private resourceType;
|
|
88
|
-
private toCache;
|
|
89
94
|
/**
|
|
90
|
-
* Checks if resource exists
|
|
95
|
+
* Checks if resource exists.
|
|
96
|
+
* This should only throw, if someone creates resources directly; ie. not through the cache
|
|
91
97
|
* @throws if resource does not exist
|
|
92
98
|
*/
|
|
93
99
|
protected assertResourceExists(): void;
|
|
100
|
+
/**
|
|
101
|
+
* Calculate; empty implementation.
|
|
102
|
+
*/
|
|
94
103
|
protected calculate(): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Calculations that use this resource.
|
|
106
|
+
* @throws if accessing calculations files failed
|
|
107
|
+
*/
|
|
95
108
|
protected calculations(): Promise<string[]>;
|
|
109
|
+
/**
|
|
110
|
+
* Cards from project.
|
|
111
|
+
*/
|
|
96
112
|
protected cards(): Card[];
|
|
97
113
|
/**
|
|
98
114
|
* Returns .schema content file.
|
|
@@ -100,8 +116,21 @@ export declare abstract class ResourceObject<T extends ResourceBaseMetadata, U>
|
|
|
100
116
|
* @returns .schema content.
|
|
101
117
|
*/
|
|
102
118
|
protected contentSchemaContent(schemaId: string): JSON;
|
|
119
|
+
/**
|
|
120
|
+
* Creates resource.
|
|
121
|
+
* @param newContent Content for resource.
|
|
122
|
+
* @throws when resource already exists in the project.
|
|
123
|
+
*/
|
|
103
124
|
protected create(newContent?: T): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Gets a logger instance.
|
|
127
|
+
* @param loggerName
|
|
128
|
+
* @returns logger instance
|
|
129
|
+
*/
|
|
104
130
|
protected getLogger(loggerName: string): Logger;
|
|
131
|
+
/**
|
|
132
|
+
* Returns type of this resource.
|
|
133
|
+
*/
|
|
105
134
|
protected get getType(): string;
|
|
106
135
|
/**
|
|
107
136
|
* Handles operation to an array.
|
|
@@ -109,23 +138,60 @@ export declare abstract class ResourceObject<T extends ResourceBaseMetadata, U>
|
|
|
109
138
|
* @param arrayName Name of the array, for error messages.
|
|
110
139
|
* @param array Array to be updated.
|
|
111
140
|
* @returns Changed array after the operation.
|
|
141
|
+
* @throws when operation cannot be done.
|
|
112
142
|
*/
|
|
113
143
|
protected handleArray<Type>(operation: Operation<Type>, arrayName: string, array: Type[]): Type[];
|
|
114
144
|
/**
|
|
115
145
|
* Updates scalar value. The only accepted operation is 'change'
|
|
116
146
|
* @param operation Operation to perform on scalar.
|
|
117
147
|
* @returns What the scalar should be changed to.
|
|
148
|
+
* @throws when operation cannot be done
|
|
118
149
|
*/
|
|
119
150
|
protected handleScalar<Type>(operation: Operation<Type>): Type;
|
|
151
|
+
/**
|
|
152
|
+
* Initialize the resource.
|
|
153
|
+
*/
|
|
120
154
|
protected initialize(): void;
|
|
155
|
+
/**
|
|
156
|
+
* Called after inherited class has finished 'update' operation.
|
|
157
|
+
* @param content New content for resource
|
|
158
|
+
* @param updateKey Which property to change
|
|
159
|
+
* @param op What kind of operation is performed to updateKey
|
|
160
|
+
* @throws if validation fails after the update
|
|
161
|
+
*/
|
|
121
162
|
protected postUpdate<Type, K extends string>(content: T, updateKey: UpdateKey<K>, op: Operation<Type>): Promise<void>;
|
|
122
|
-
|
|
163
|
+
/**
|
|
164
|
+
* Reads content from file to memory.
|
|
165
|
+
*/
|
|
123
166
|
protected read(): Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Renames resource.
|
|
169
|
+
* @param newName New name for the resource.
|
|
170
|
+
* @throws if trying to rename module resource, or
|
|
171
|
+
* if resource does not exist,
|
|
172
|
+
* if trying to rename so that type changes
|
|
173
|
+
*/
|
|
124
174
|
protected rename(newName: ResourceName): Promise<void>;
|
|
175
|
+
/**
|
|
176
|
+
* Update resource; the base class makes some checks only.
|
|
177
|
+
* @template type Resource type
|
|
178
|
+
* @template K Resource key
|
|
179
|
+
* @throws if resource does not exist, or
|
|
180
|
+
* if trying to update module content, or
|
|
181
|
+
* if key is empty
|
|
182
|
+
*/
|
|
183
|
+
protected update<Type, K extends string>(key: UpdateKey<K>, _op: Operation<Type>): Promise<void>;
|
|
184
|
+
/**
|
|
185
|
+
* Validates resource identifier to prevent filesystem operations with invalid names
|
|
186
|
+
* todo: To Validate?
|
|
187
|
+
*/
|
|
188
|
+
protected validateResourceIdentifier(): void;
|
|
125
189
|
/**
|
|
126
190
|
* Update calculation files.
|
|
127
191
|
* @param from Resource name to update
|
|
128
192
|
* @param to New name for resource
|
|
193
|
+
* @throws if 'from' or 'to' is empty string, or
|
|
194
|
+
* if there was error accessing calculation files.
|
|
129
195
|
*/
|
|
130
196
|
protected updateCalculations(from: string, to: string): Promise<void>;
|
|
131
197
|
/**
|
|
@@ -133,10 +199,26 @@ export declare abstract class ResourceObject<T extends ResourceBaseMetadata, U>
|
|
|
133
199
|
* @param from Resource name to update
|
|
134
200
|
* @param to New name for resource
|
|
135
201
|
* @param handleBarFiles Optional. List of handlebar files. If omitted, affects all handlebar files in the project.
|
|
202
|
+
* @throws if 'from' or 'to' is empty string
|
|
136
203
|
*/
|
|
137
204
|
protected updateHandleBars(from: string, to: string, handleBarFiles?: string[]): Promise<void>;
|
|
205
|
+
/**
|
|
206
|
+
* Check if there are references to the resource in the card content.
|
|
207
|
+
* @note that this needs to be async, since inherited classes need to async operations
|
|
208
|
+
* @param cards cards to check
|
|
209
|
+
* @throws if resource does not exist
|
|
210
|
+
*/
|
|
138
211
|
protected usage(cards?: Card[]): Promise<string[]>;
|
|
212
|
+
/**
|
|
213
|
+
* Checks if resource name is valid.
|
|
214
|
+
* @param newName New name for resource.
|
|
215
|
+
* @returns valid name
|
|
216
|
+
*/
|
|
139
217
|
protected validName(newName: ResourceName): Promise<string>;
|
|
218
|
+
/**
|
|
219
|
+
* Write the content from memory to disk.
|
|
220
|
+
* @throws if trying to write a module resource.
|
|
221
|
+
*/
|
|
140
222
|
protected write(): Promise<void>;
|
|
141
223
|
/**
|
|
142
224
|
* Returns memory resident data as JSON.
|
|
@@ -146,12 +228,15 @@ export declare abstract class ResourceObject<T extends ResourceBaseMetadata, U>
|
|
|
146
228
|
get data(): T | undefined;
|
|
147
229
|
/**
|
|
148
230
|
* Deletes the file and removes the resource from project.
|
|
149
|
-
* @throws if resource is a module resource or
|
|
231
|
+
* @throws if resource is a module resource, or
|
|
232
|
+
* if resource does not exist, or
|
|
233
|
+
* if resource is used by other resources.
|
|
150
234
|
*/
|
|
151
235
|
delete(): Promise<void>;
|
|
152
236
|
/**
|
|
153
237
|
* Validates the content of the resource.
|
|
154
238
|
* @param content Content to be validated.
|
|
239
|
+
* @throws if content is invalid.
|
|
155
240
|
*/
|
|
156
241
|
validate(content?: object): Promise<void>;
|
|
157
242
|
}
|