@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.
Files changed (173) hide show
  1. package/dist/card-metadata-updater.js +7 -1
  2. package/dist/card-metadata-updater.js.map +1 -1
  3. package/dist/command-handler.d.ts +4 -0
  4. package/dist/command-handler.js +19 -3
  5. package/dist/command-handler.js.map +1 -1
  6. package/dist/command-manager.d.ts +24 -1
  7. package/dist/command-manager.js +27 -3
  8. package/dist/command-manager.js.map +1 -1
  9. package/dist/commands/create.d.ts +1 -1
  10. package/dist/commands/create.js +34 -36
  11. package/dist/commands/create.js.map +1 -1
  12. package/dist/commands/export.d.ts +11 -2
  13. package/dist/commands/export.js +54 -41
  14. package/dist/commands/export.js.map +1 -1
  15. package/dist/commands/import.d.ts +9 -1
  16. package/dist/commands/import.js +15 -7
  17. package/dist/commands/import.js.map +1 -1
  18. package/dist/commands/move.js +0 -1
  19. package/dist/commands/move.js.map +1 -1
  20. package/dist/commands/remove.d.ts +8 -1
  21. package/dist/commands/remove.js +8 -4
  22. package/dist/commands/remove.js.map +1 -1
  23. package/dist/commands/rename.d.ts +4 -9
  24. package/dist/commands/rename.js +32 -101
  25. package/dist/commands/rename.js.map +1 -1
  26. package/dist/commands/show.d.ts +16 -10
  27. package/dist/commands/show.js +71 -55
  28. package/dist/commands/show.js.map +1 -1
  29. package/dist/commands/transition.d.ts +9 -2
  30. package/dist/commands/transition.js +25 -17
  31. package/dist/commands/transition.js.map +1 -1
  32. package/dist/commands/update.d.ts +16 -12
  33. package/dist/commands/update.js +19 -17
  34. package/dist/commands/update.js.map +1 -1
  35. package/dist/commands/validate.d.ts +17 -9
  36. package/dist/commands/validate.js +96 -35
  37. package/dist/commands/validate.js.map +1 -1
  38. package/dist/containers/project/calculation-engine.d.ts +7 -4
  39. package/dist/containers/project/calculation-engine.js +61 -66
  40. package/dist/containers/project/calculation-engine.js.map +1 -1
  41. package/dist/containers/project/project-paths.d.ts +5 -4
  42. package/dist/containers/project/project-paths.js +16 -12
  43. package/dist/containers/project/project-paths.js.map +1 -1
  44. package/dist/containers/project/resource-cache.d.ts +169 -0
  45. package/dist/containers/project/resource-cache.js +507 -0
  46. package/dist/containers/project/resource-cache.js.map +1 -0
  47. package/dist/containers/project/resource-handler.d.ts +129 -0
  48. package/dist/containers/project/resource-handler.js +206 -0
  49. package/dist/containers/project/resource-handler.js.map +1 -0
  50. package/dist/containers/project.d.ts +38 -153
  51. package/dist/containers/project.js +129 -405
  52. package/dist/containers/project.js.map +1 -1
  53. package/dist/containers/template.d.ts +8 -2
  54. package/dist/containers/template.js +20 -15
  55. package/dist/containers/template.js.map +1 -1
  56. package/dist/interfaces/folder-content-interfaces.d.ts +5 -3
  57. package/dist/interfaces/folder-content-interfaces.js +3 -3
  58. package/dist/interfaces/folder-content-interfaces.js.map +1 -1
  59. package/dist/interfaces/project-interfaces.d.ts +2 -4
  60. package/dist/interfaces/project-interfaces.js.map +1 -1
  61. package/dist/interfaces/resource-interfaces.d.ts +14 -1
  62. package/dist/interfaces/resource-interfaces.js.map +1 -1
  63. package/dist/macros/graph/index.js +12 -26
  64. package/dist/macros/graph/index.js.map +1 -1
  65. package/dist/macros/index.d.ts +1 -1
  66. package/dist/macros/index.js +2 -2
  67. package/dist/macros/index.js.map +1 -1
  68. package/dist/macros/report/index.js +3 -6
  69. package/dist/macros/report/index.js.map +1 -1
  70. package/dist/module-manager.d.ts +16 -3
  71. package/dist/module-manager.js +51 -19
  72. package/dist/module-manager.js.map +1 -1
  73. package/dist/project-settings.d.ts +16 -3
  74. package/dist/project-settings.js +79 -14
  75. package/dist/project-settings.js.map +1 -1
  76. package/dist/resources/calculation-resource.d.ts +4 -3
  77. package/dist/resources/calculation-resource.js +11 -5
  78. package/dist/resources/calculation-resource.js.map +1 -1
  79. package/dist/resources/card-type-resource.d.ts +6 -1
  80. package/dist/resources/card-type-resource.js +34 -23
  81. package/dist/resources/card-type-resource.js.map +1 -1
  82. package/dist/resources/create-defaults.d.ts +3 -2
  83. package/dist/resources/create-defaults.js +3 -2
  84. package/dist/resources/create-defaults.js.map +1 -1
  85. package/dist/resources/field-type-resource.d.ts +4 -1
  86. package/dist/resources/field-type-resource.js +22 -23
  87. package/dist/resources/field-type-resource.js.map +1 -1
  88. package/dist/resources/file-resource.d.ts +5 -9
  89. package/dist/resources/file-resource.js +6 -11
  90. package/dist/resources/file-resource.js.map +1 -1
  91. package/dist/resources/folder-resource.d.ts +29 -32
  92. package/dist/resources/folder-resource.js +59 -78
  93. package/dist/resources/folder-resource.js.map +1 -1
  94. package/dist/resources/graph-model-resource.d.ts +4 -1
  95. package/dist/resources/graph-model-resource.js +11 -4
  96. package/dist/resources/graph-model-resource.js.map +1 -1
  97. package/dist/resources/graph-view-resource.d.ts +5 -2
  98. package/dist/resources/graph-view-resource.js +7 -3
  99. package/dist/resources/graph-view-resource.js.map +1 -1
  100. package/dist/resources/link-type-resource.d.ts +5 -2
  101. package/dist/resources/link-type-resource.js +5 -2
  102. package/dist/resources/link-type-resource.js.map +1 -1
  103. package/dist/resources/report-resource.d.ts +6 -7
  104. package/dist/resources/report-resource.js +14 -23
  105. package/dist/resources/report-resource.js.map +1 -1
  106. package/dist/resources/resource-object.d.ts +93 -8
  107. package/dist/resources/resource-object.js +162 -110
  108. package/dist/resources/resource-object.js.map +1 -1
  109. package/dist/resources/template-resource.d.ts +7 -3
  110. package/dist/resources/template-resource.js +10 -3
  111. package/dist/resources/template-resource.js.map +1 -1
  112. package/dist/resources/workflow-resource.d.ts +5 -2
  113. package/dist/resources/workflow-resource.js +18 -22
  114. package/dist/resources/workflow-resource.js.map +1 -1
  115. package/dist/utils/card-utils.d.ts +2 -2
  116. package/dist/utils/card-utils.js +1 -1
  117. package/dist/utils/clingo-fact-builder.d.ts +25 -14
  118. package/dist/utils/clingo-fact-builder.js +27 -5
  119. package/dist/utils/clingo-fact-builder.js.map +1 -1
  120. package/dist/utils/clingo-facts.js +3 -4
  121. package/dist/utils/clingo-facts.js.map +1 -1
  122. package/dist/utils/resource-utils.d.ts +1 -0
  123. package/dist/utils/resource-utils.js +2 -1
  124. package/dist/utils/resource-utils.js.map +1 -1
  125. package/package.json +8 -8
  126. package/src/card-metadata-updater.ts +6 -2
  127. package/src/command-handler.ts +24 -5
  128. package/src/command-manager.ts +29 -17
  129. package/src/commands/create.ts +43 -78
  130. package/src/commands/export.ts +63 -52
  131. package/src/commands/import.ts +24 -14
  132. package/src/commands/move.ts +0 -1
  133. package/src/commands/remove.ts +11 -7
  134. package/src/commands/rename.ts +43 -149
  135. package/src/commands/show.ts +113 -78
  136. package/src/commands/transition.ts +26 -28
  137. package/src/commands/update.ts +25 -22
  138. package/src/commands/validate.ts +108 -67
  139. package/src/containers/project/calculation-engine.ts +61 -93
  140. package/src/containers/project/project-paths.ts +21 -13
  141. package/src/containers/project/resource-cache.ts +648 -0
  142. package/src/containers/project/resource-handler.ts +265 -0
  143. package/src/containers/project.ts +178 -522
  144. package/src/containers/template.ts +24 -19
  145. package/src/interfaces/folder-content-interfaces.ts +7 -6
  146. package/src/interfaces/project-interfaces.ts +7 -6
  147. package/src/interfaces/resource-interfaces.ts +18 -3
  148. package/src/macros/graph/index.ts +26 -47
  149. package/src/macros/index.ts +2 -2
  150. package/src/macros/report/index.ts +3 -9
  151. package/src/module-manager.ts +74 -17
  152. package/src/project-settings.ts +83 -14
  153. package/src/resources/calculation-resource.ts +18 -18
  154. package/src/resources/card-type-resource.ts +50 -50
  155. package/src/resources/create-defaults.ts +3 -2
  156. package/src/resources/field-type-resource.ts +41 -55
  157. package/src/resources/file-resource.ts +10 -36
  158. package/src/resources/folder-resource.ts +69 -120
  159. package/src/resources/graph-model-resource.ts +20 -22
  160. package/src/resources/graph-view-resource.ts +15 -17
  161. package/src/resources/link-type-resource.ts +10 -13
  162. package/src/resources/report-resource.ts +21 -43
  163. package/src/resources/resource-object.ts +194 -152
  164. package/src/resources/template-resource.ts +17 -16
  165. package/src/resources/workflow-resource.ts +25 -44
  166. package/src/utils/card-utils.ts +2 -2
  167. package/src/utils/clingo-fact-builder.ts +28 -16
  168. package/src/utils/clingo-facts.ts +3 -4
  169. package/src/utils/resource-utils.ts +2 -1
  170. package/dist/containers/project/resource-collector.d.ts +0 -110
  171. package/dist/containers/project/resource-collector.js +0 -344
  172. package/dist/containers/project/resource-collector.js.map +0 -1
  173. package/src/containers/project/resource-collector.ts +0 -404
@@ -13,44 +13,42 @@
13
13
  */
14
14
  import { CardContainer } from './card-container.js';
15
15
  import { CalculationEngine } from './project/calculation-engine.js';
16
- import { type Card, type CardAttachment, CardLocation, type CardListContainer, type CardMetadata, type FetchCardDetails, type MetadataContent, type ModuleContent, type ModuleSetting, type ProjectFetchCardDetails, type ProjectMetadata, type Resource, type ResourceFolderType } from '../interfaces/project-interfaces.js';
16
+ import { type Card, type CardAttachment, CardLocation, type CardListContainer, type CardMetadata, type FetchCardDetails, type MetadataContent, type ModuleContent, type ModuleSetting, type ProjectFetchCardDetails, type ProjectMetadata } from '../interfaces/project-interfaces.js';
17
17
  import { ProjectConfiguration } from '../project-settings.js';
18
18
  import { ProjectPaths } from './project/project-paths.js';
19
- import { type ResourceName } from '../utils/resource-utils.js';
20
- import { ResourcesFrom } from './project/resource-collector.js';
19
+ import { ResourcesFrom } from './project/resource-cache.js';
20
+ import { ResourceHandler } from './project/resource-handler.js';
21
21
  import type { Template } from './template.js';
22
- import { CalculationResource } from '../resources/calculation-resource.js';
23
- import { CardTypeResource } from '../resources/card-type-resource.js';
24
- import { FieldTypeResource } from '../resources/field-type-resource.js';
25
- import { GraphModelResource } from '../resources/graph-model-resource.js';
26
- import { GraphViewResource } from '../resources/graph-view-resource.js';
27
- import { LinkTypeResource } from '../resources/link-type-resource.js';
28
- import { ReportResource } from '../resources/report-resource.js';
29
- import { TemplateResource } from '../resources/template-resource.js';
30
- import { WorkflowResource } from '../resources/workflow-resource.js';
31
22
  export { ResourcesFrom };
23
+ /**
24
+ * Options for Project initialization.
25
+ * autoSave - If project configuration changes are saved automatically. Default true.
26
+ * watchResourceChanges - If project refresh automatically to filesystem changes. Default false.
27
+ */
28
+ export interface ProjectOptions {
29
+ autoSave?: boolean;
30
+ watchResourceChanges?: boolean;
31
+ }
32
32
  /**
33
33
  * Represents project folder.
34
34
  */
35
35
  export declare class Project extends CardContainer {
36
- private watchResourceChanges?;
36
+ private options;
37
37
  calculationEngine: CalculationEngine;
38
- private createdResources;
39
38
  private logger;
40
39
  private projectPaths;
41
- private resources;
40
+ private resourceHandler;
42
41
  private resourceWatcher;
43
42
  private settings;
44
43
  private validator;
45
- constructor(path: string, watchResourceChanges?: boolean | undefined);
44
+ constructor(path: string, options?: ProjectOptions);
46
45
  private changeParent;
47
46
  private findModule;
48
47
  private handleAttachmentChange;
49
48
  private parentFromPath;
50
49
  private removeCachedChildren;
51
- private replaceCacheValue;
52
- private resourcesOfType;
53
50
  private updateCachedChildren;
51
+ private validateCard;
54
52
  /**
55
53
  * Populate template cards into the card cache.
56
54
  */
@@ -59,12 +57,6 @@ export declare class Project extends CardContainer {
59
57
  * Populate both the project cards, and all template cards into card cache.
60
58
  */
61
59
  protected populateCardsCache(): Promise<void>;
62
- /**
63
- * Add a given 'resource' to the local resource arrays.
64
- * @param resource Resource to add.
65
- * @param data JSON data for the resource.
66
- */
67
- addResource(resource: Resource, data: JSON): void;
68
60
  /**
69
61
  * Returns all template cards from the project. This includes all module templates' cards.
70
62
  * @returns all the template cards from the project
@@ -82,17 +74,6 @@ export declare class Project extends CardContainer {
82
74
  * @returns Array of attachments from cards at the specified path
83
75
  */
84
76
  attachmentsByPath(path: string): CardAttachment[];
85
- /**
86
- * Returns all the attachments in the template cards.
87
- * @returns all the attachments in the template cards.
88
- */
89
- attachmentsFromTemplates(): Promise<CardAttachment[]>;
90
- /**
91
- * Returns an array of all the calculation files (*.lp) in the project.
92
- * @param from Defines where resources are collected from.
93
- * @returns array of all calculation files in the project.
94
- */
95
- calculations(from?: ResourcesFrom): Promise<Resource[]>;
96
77
  /**
97
78
  * Returns path to a card's attachment folder.
98
79
  * @param cardKey card key
@@ -107,13 +88,6 @@ export declare class Project extends CardContainer {
107
88
  * @throws If trying to add attachment to module card, or if attachment is not found
108
89
  */
109
90
  createCardAttachment(cardKey: string, attachmentName: string, attachmentData: string | Buffer): Promise<void>;
110
- /**
111
- * Removes an attachment from a card.
112
- * @param cardKey The card to remove attachment from
113
- * @param fileName The name of the attachment file to remove
114
- * @throws if trying to remove module card attachment, or the attachment was not found.
115
- */
116
- removeCardAttachment(cardKey: string, fileName: string): Promise<void>;
117
91
  /**
118
92
  * Returns path to a card's folder.
119
93
  * @param cardKey card key
@@ -126,12 +100,6 @@ export declare class Project extends CardContainer {
126
100
  * @returns Card data to the given card keys
127
101
  */
128
102
  cardKeysToCards(cardIds: string[]): Card[];
129
- /**
130
- * Accessor for cards cache.
131
- * Used by template container (it needs to access project's cache, not their own instance).
132
- * @note Should not be used directly (other than Template).
133
- */
134
- get cardsCache(): import("./project/card-cache.js").CardCache;
135
103
  /**
136
104
  * Returns an array of all the cards in the project.
137
105
  * @note These are project cards only, by default (unless path dictates otherwise).
@@ -141,25 +109,17 @@ export declare class Project extends CardContainer {
141
109
  */
142
110
  cards(path?: string, details?: FetchCardDetails): Card[];
143
111
  /**
144
- * Returns an array of all the card types in the project.
145
- * @param from Defines where resources are collected from.
146
- * @returns array of all card types in the project.
112
+ * Accessor for cards cache.
113
+ * Used by template container (it needs to access project's cache, not their own instance).
114
+ * @note Should not be used directly (other than Template).
147
115
  */
148
- cardTypes(from?: ResourcesFrom): Promise<Resource[]>;
116
+ get cardsCache(): import("./project/card-cache.js").CardCache;
149
117
  /**
150
118
  * Returns children of a given card; as Card array
151
119
  * @param card Parent card to fetch children from
152
120
  * @returns children of a given card; as Card array
153
121
  */
154
122
  childrenCards(card: Card): Card[];
155
- /**
156
- * Updates all local resources.
157
- */
158
- collectLocalResources(): void;
159
- /**
160
- * Updates all imported module resources.
161
- */
162
- collectModuleResources(): void;
163
123
  /**
164
124
  * Returns project configuration.
165
125
  * @returns project configuration.
@@ -175,18 +135,6 @@ export declare class Project extends CardContainer {
175
135
  * Cleanups project when it is being closed.
176
136
  */
177
137
  dispose(): void;
178
- /**
179
- * Returns an array of all the field types in the project.
180
- * @param from Defines where resources are collected from.
181
- * @returns array of all field types in the project.
182
- */
183
- fieldTypes(from?: ResourcesFrom): Promise<Resource[]>;
184
- /**
185
- * Finds root of a project
186
- * @param path Path where to start looking for the project root.
187
- * @returns path to a project root, or empty string.
188
- */
189
- static findProjectRoot(path: string): Promise<string>;
190
138
  /**
191
139
  * Returns specific card.
192
140
  * @param cardToFind Card key to find
@@ -195,17 +143,11 @@ export declare class Project extends CardContainer {
195
143
  */
196
144
  findCard(cardToFind: string, details?: ProjectFetchCardDetails): Card;
197
145
  /**
198
- * Returns an array of all the graph models in the project.
199
- * @param from Defines where resources are collected from.
200
- * @returns array of all the graph models in the project.
201
- */
202
- graphModels(from?: ResourcesFrom): Promise<Resource[]>;
203
- /**
204
- * Returns an array of all the graph views in the project.
205
- * @param from Defines where resources are collected from.
206
- * @returns array of all the graph views in the project.
146
+ * Finds root of a project
147
+ * @param path Path where to start looking for the project root.
148
+ * @returns path to a project root, or empty string.
207
149
  */
208
- graphViews(from?: ResourcesFrom): Promise<Resource[]>;
150
+ static findProjectRoot(path: string): Promise<string>;
209
151
  /**
210
152
  * When card changes.
211
153
  * @param changedCard Card that was changed.
@@ -239,12 +181,6 @@ export declare class Project extends CardContainer {
239
181
  * @returns true, if in the given path there is a project; false otherwise
240
182
  */
241
183
  static isCreated(path: string): boolean;
242
- /**
243
- * Returns an array of all the link types in the project.
244
- * @param from Defines where resources are collected from.
245
- * @returns array of all link types in the project.
246
- */
247
- linkTypes(from?: ResourcesFrom): Promise<Resource[]>;
248
184
  /**
249
185
  * Returns an array of cards in the project, in the templates or both.
250
186
  * Cards don't have content and nor metadata.
@@ -265,11 +201,6 @@ export declare class Project extends CardContainer {
265
201
  * @returns module details, or undefined if module cannot be found.
266
202
  */
267
203
  module(moduleName: string): Promise<ModuleContent | undefined>;
268
- /**
269
- * Returns list of modules in the project.
270
- * @returns list of modules in the project.
271
- */
272
- modules(): Promise<Resource[]>;
273
204
  /**
274
205
  * Returns a new unique card key with project prefix (e.g. test_x649it4x).
275
206
  * Random part of string will be always 8 characters in base-36 (0-9a-z)
@@ -304,61 +235,28 @@ export declare class Project extends CardContainer {
304
235
  */
305
236
  get projectPrefix(): string;
306
237
  /**
307
- * Collects all prefixes used in the project (project's own plus all from modules).
238
+ * Returns all prefixes used in the project (project's own plus all from imported modules).
308
239
  * @returns all prefixes used in the project.
309
- * @todo - move the module prefix fetch to resource-collector.
310
- * Make it use cached value that is only changed when module is removed/imported.
311
- */
312
- projectPrefixes(): Promise<string[]>;
313
- /**
314
- * Removes a module from the project
315
- * @param module Module (name) to remove.
316
- */
317
- removeModule(moduleName: string): Promise<void>;
318
- /**
319
- * Removes a resource from Project.
320
- * @param resource Resource to remove.
321
240
  */
322
- removeResource(resource: Resource): void;
241
+ projectPrefixes(): string[];
323
242
  /**
324
- * Array of reports in the project.
325
- * @param from Defines where resources are collected from.
326
- * @returns array of all reports in the project.
327
- */
328
- reports(from?: ResourcesFrom): Promise<Resource[]>;
329
- /**
330
- * Returns handlebar files from reports.
331
- * @param from Defines where report handlebar files are collected from.
332
- * @returns handlebar files from reports.
333
- */
334
- reportHandlerBarFiles(from?: ResourcesFrom): Promise<string[]>;
335
- /**
336
- * Returns metadata from a given resource
337
- * @param name Name of a resource
338
- * @returns Metadata from the resource.
339
- */
340
- resource<Type>(name: string): Type | undefined;
341
- /**
342
- * Returns resource cache.
243
+ * Removes an attachment from a card.
244
+ * @param cardKey The card to remove attachment from
245
+ * @param fileName The name of the attachment file to remove
246
+ * @throws if trying to remove module card attachment, or the attachment was not found.
343
247
  */
344
- get resourceCache(): Map<string, JSON>;
248
+ removeCardAttachment(cardKey: string, fileName: string): Promise<void>;
345
249
  /**
346
- * Checks if a given resource exists in the project already.
347
- * @param resourceType Type of resource as a string.
348
- * @param name Valid name of resource.
349
- * @returns boolean, true if resource exists; false otherwise.
250
+ * Removes a module from the project cache and configuration.
251
+ * @note that ModuleManager removes the actual files.
252
+ * @param moduleName Module name to remove.
350
253
  */
351
- resourceExists(resourceType: ResourceFolderType, name: string): Promise<boolean>;
254
+ removeModule(moduleName: string): Promise<void>;
352
255
  /**
353
- * Instantiates resource object from project with a resource name.
354
- * @note that this is memory based object only.
355
- * To manipulate the resource (create files, delete files etc), use the resource object's API.
356
- * @param project Project from which resources are created from.
357
- * @param name Resource name
358
- * @throws if called with unsupported resource type.
359
- * @returns Created resource.
256
+ * Accessor for resource handler.
257
+ * @returns Resource handler instance.
360
258
  */
361
- static resourceObject(project: Project, name: ResourceName): CalculationResource | CardTypeResource | FieldTypeResource | GraphModelResource | GraphViewResource | LinkTypeResource | ReportResource | TemplateResource | WorkflowResource;
259
+ get resources(): ResourceHandler;
362
260
  /**
363
261
  * Shows details of a project.
364
262
  * @returns details of a project.
@@ -375,12 +273,6 @@ export declare class Project extends CardContainer {
375
273
  * @returns List of cards from template.
376
274
  */
377
275
  templateCards(templateName: string): Card[];
378
- /**
379
- * Array of templates in the project.
380
- * @param from Defines where resources are collected from.
381
- * @returns array of all templates in the project.
382
- */
383
- templates(from?: ResourcesFrom): Promise<Resource[]>;
384
276
  /**
385
277
  * Update a card's content.
386
278
  * @param cardKey card key to update.
@@ -406,11 +298,4 @@ export declare class Project extends CardContainer {
406
298
  * @param changedMetadata changed content for the card
407
299
  */
408
300
  updateCardMetadata(card: Card, changedMetadata: CardMetadata): Promise<void>;
409
- private validateCard;
410
- /**
411
- * Array of workflows in the project.
412
- * @param from Defines where resources are collected from.
413
- * @returns array of all workflows in the project.
414
- */
415
- workflows(from?: ResourcesFrom): Promise<Resource[]>;
416
301
  }