@cyberismo/data-handler 0.0.20 → 0.0.22

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 (177) hide show
  1. package/dist/command-handler.js +13 -24
  2. package/dist/command-handler.js.map +1 -1
  3. package/dist/command-manager.d.ts +21 -6
  4. package/dist/command-manager.js +34 -32
  5. package/dist/command-manager.js.map +1 -1
  6. package/dist/commands/calculate.js +101 -46
  7. package/dist/commands/calculate.js.map +1 -1
  8. package/dist/commands/create.js +420 -320
  9. package/dist/commands/create.js.map +1 -1
  10. package/dist/commands/edit.js +117 -68
  11. package/dist/commands/edit.js.map +1 -1
  12. package/dist/commands/export.js +301 -252
  13. package/dist/commands/export.js.map +1 -1
  14. package/dist/commands/fetch.js +205 -156
  15. package/dist/commands/fetch.js.map +1 -1
  16. package/dist/commands/import.js +189 -134
  17. package/dist/commands/import.js.map +1 -1
  18. package/dist/commands/migrate.js +91 -45
  19. package/dist/commands/migrate.js.map +1 -1
  20. package/dist/commands/move.js +347 -267
  21. package/dist/commands/move.js.map +1 -1
  22. package/dist/commands/remove.d.ts +1 -0
  23. package/dist/commands/remove.js +202 -135
  24. package/dist/commands/remove.js.map +1 -1
  25. package/dist/commands/rename.js +233 -187
  26. package/dist/commands/rename.js.map +1 -1
  27. package/dist/commands/show.d.ts +8 -8
  28. package/dist/commands/show.js +477 -372
  29. package/dist/commands/show.js.map +1 -1
  30. package/dist/commands/transition.js +119 -73
  31. package/dist/commands/transition.js.map +1 -1
  32. package/dist/commands/update.js +8 -3
  33. package/dist/commands/update.js.map +1 -1
  34. package/dist/commands/validate.js +1 -1
  35. package/dist/commands/validate.js.map +1 -1
  36. package/dist/containers/project/calculation-engine.js +0 -1
  37. package/dist/containers/project/calculation-engine.js.map +1 -1
  38. package/dist/containers/project/card-cache.js +1 -1
  39. package/dist/containers/project/card-cache.js.map +1 -1
  40. package/dist/containers/project.d.ts +16 -0
  41. package/dist/containers/project.js +59 -1
  42. package/dist/containers/project.js.map +1 -1
  43. package/dist/containers/template.js +1 -1
  44. package/dist/containers/template.js.map +1 -1
  45. package/dist/interfaces/command-options.d.ts +1 -0
  46. package/dist/interfaces/resource-interfaces.d.ts +5 -12
  47. package/dist/interfaces/resource-interfaces.js.map +1 -1
  48. package/dist/macros/base-macro.js +1 -1
  49. package/dist/macros/base-macro.js.map +1 -1
  50. package/dist/macros/graph/index.js +3 -1
  51. package/dist/macros/graph/index.js.map +1 -1
  52. package/dist/macros/include/index.js +16 -1
  53. package/dist/macros/include/index.js.map +1 -1
  54. package/dist/macros/include/types.d.ts +15 -12
  55. package/dist/macros/index.js +4 -1
  56. package/dist/macros/index.js.map +1 -1
  57. package/dist/macros/report/index.js +1 -1
  58. package/dist/macros/report/index.js.map +1 -1
  59. package/dist/module-manager.js +5 -3
  60. package/dist/module-manager.js.map +1 -1
  61. package/dist/project-settings.js +2 -2
  62. package/dist/project-settings.js.map +1 -1
  63. package/dist/resources/card-type-resource.js +1 -1
  64. package/dist/resources/card-type-resource.js.map +1 -1
  65. package/dist/resources/create-defaults.js +0 -1
  66. package/dist/resources/create-defaults.js.map +1 -1
  67. package/dist/resources/field-type-resource.js +2 -5
  68. package/dist/resources/field-type-resource.js.map +1 -1
  69. package/dist/resources/file-resource.js +4 -1
  70. package/dist/resources/file-resource.js.map +1 -1
  71. package/dist/resources/folder-resource.d.ts +1 -1
  72. package/dist/resources/folder-resource.js +4 -1
  73. package/dist/resources/folder-resource.js.map +1 -1
  74. package/dist/resources/graph-model-resource.d.ts +1 -8
  75. package/dist/resources/graph-model-resource.js +0 -14
  76. package/dist/resources/graph-model-resource.js.map +1 -1
  77. package/dist/resources/graph-view-resource.d.ts +1 -8
  78. package/dist/resources/graph-view-resource.js +0 -14
  79. package/dist/resources/graph-view-resource.js.map +1 -1
  80. package/dist/resources/link-type-resource.js +1 -1
  81. package/dist/resources/link-type-resource.js.map +1 -1
  82. package/dist/resources/report-resource.d.ts +1 -8
  83. package/dist/resources/report-resource.js +0 -14
  84. package/dist/resources/report-resource.js.map +1 -1
  85. package/dist/resources/resource-object.d.ts +11 -1
  86. package/dist/resources/resource-object.js +19 -2
  87. package/dist/resources/resource-object.js.map +1 -1
  88. package/dist/resources/template-resource.d.ts +1 -9
  89. package/dist/resources/template-resource.js +0 -15
  90. package/dist/resources/template-resource.js.map +1 -1
  91. package/dist/resources/workflow-resource.d.ts +6 -0
  92. package/dist/resources/workflow-resource.js +29 -13
  93. package/dist/resources/workflow-resource.js.map +1 -1
  94. package/dist/utils/card-utils.js +1 -1
  95. package/dist/utils/card-utils.js.map +1 -1
  96. package/dist/utils/commit-context.d.ts +23 -0
  97. package/dist/utils/commit-context.js +30 -0
  98. package/dist/utils/commit-context.js.map +1 -0
  99. package/dist/utils/csv.d.ts +8 -0
  100. package/dist/utils/csv.js +11 -0
  101. package/dist/utils/csv.js.map +1 -1
  102. package/dist/utils/file-utils.js +3 -1
  103. package/dist/utils/file-utils.js.map +1 -1
  104. package/dist/utils/git-manager.d.ts +29 -0
  105. package/dist/utils/git-manager.js +76 -0
  106. package/dist/utils/git-manager.js.map +1 -0
  107. package/dist/utils/handlebars-helpers.d.ts +22 -0
  108. package/dist/utils/handlebars-helpers.js +78 -0
  109. package/dist/utils/handlebars-helpers.js.map +1 -0
  110. package/dist/utils/json.d.ts +17 -10
  111. package/dist/utils/json.js +27 -14
  112. package/dist/utils/json.js.map +1 -1
  113. package/dist/utils/log-utils.d.ts +7 -2
  114. package/dist/utils/log-utils.js +28 -3
  115. package/dist/utils/log-utils.js.map +1 -1
  116. package/dist/utils/report.d.ts +0 -19
  117. package/dist/utils/report.js +4 -63
  118. package/dist/utils/report.js.map +1 -1
  119. package/dist/utils/rw-lock.d.ts +71 -0
  120. package/dist/utils/rw-lock.js +220 -0
  121. package/dist/utils/rw-lock.js.map +1 -0
  122. package/dist/utils/user-preferences.js +3 -3
  123. package/dist/utils/user-preferences.js.map +1 -1
  124. package/package.json +10 -10
  125. package/src/command-handler.ts +14 -22
  126. package/src/command-manager.ts +43 -37
  127. package/src/commands/calculate.ts +8 -1
  128. package/src/commands/create.ts +39 -6
  129. package/src/commands/edit.ts +3 -0
  130. package/src/commands/export.ts +8 -2
  131. package/src/commands/fetch.ts +3 -0
  132. package/src/commands/import.ts +5 -0
  133. package/src/commands/migrate.ts +2 -0
  134. package/src/commands/move.ts +34 -0
  135. package/src/commands/remove.ts +24 -2
  136. package/src/commands/rename.ts +2 -0
  137. package/src/commands/show.ts +63 -34
  138. package/src/commands/transition.ts +2 -0
  139. package/src/commands/update.ts +9 -3
  140. package/src/commands/validate.ts +1 -1
  141. package/src/containers/project/calculation-engine.ts +0 -1
  142. package/src/containers/project/card-cache.ts +1 -0
  143. package/src/containers/project.ts +75 -1
  144. package/src/containers/template.ts +1 -1
  145. package/src/interfaces/command-options.ts +1 -0
  146. package/src/interfaces/resource-interfaces.ts +5 -12
  147. package/src/macros/base-macro.ts +1 -1
  148. package/src/macros/graph/index.ts +3 -0
  149. package/src/macros/include/index.ts +19 -1
  150. package/src/macros/include/types.ts +15 -12
  151. package/src/macros/index.ts +4 -1
  152. package/src/macros/report/index.ts +1 -0
  153. package/src/module-manager.ts +5 -2
  154. package/src/project-settings.ts +2 -1
  155. package/src/resources/card-type-resource.ts +1 -1
  156. package/src/resources/create-defaults.ts +0 -1
  157. package/src/resources/field-type-resource.ts +2 -4
  158. package/src/resources/file-resource.ts +3 -1
  159. package/src/resources/folder-resource.ts +7 -2
  160. package/src/resources/graph-model-resource.ts +1 -25
  161. package/src/resources/graph-view-resource.ts +1 -25
  162. package/src/resources/link-type-resource.ts +1 -1
  163. package/src/resources/report-resource.ts +1 -25
  164. package/src/resources/resource-object.ts +22 -1
  165. package/src/resources/template-resource.ts +0 -23
  166. package/src/resources/workflow-resource.ts +45 -16
  167. package/src/utils/card-utils.ts +1 -1
  168. package/src/utils/commit-context.ts +45 -0
  169. package/src/utils/csv.ts +12 -0
  170. package/src/utils/file-utils.ts +3 -1
  171. package/src/utils/git-manager.ts +87 -0
  172. package/src/utils/handlebars-helpers.ts +95 -0
  173. package/src/utils/json.ts +29 -15
  174. package/src/utils/log-utils.ts +33 -4
  175. package/src/utils/report.ts +8 -74
  176. package/src/utils/rw-lock.ts +279 -0
  177. package/src/utils/user-preferences.ts +3 -0
@@ -10,6 +10,40 @@
10
10
  details. You should have received a copy of the GNU Affero General Public
11
11
  License along with this program. If not, see <https://www.gnu.org/licenses/>.
12
12
  */
13
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
14
+ var useValue = arguments.length > 2;
15
+ for (var i = 0; i < initializers.length; i++) {
16
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
17
+ }
18
+ return useValue ? value : void 0;
19
+ };
20
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
21
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
22
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
23
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
24
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
25
+ var _, done = false;
26
+ for (var i = decorators.length - 1; i >= 0; i--) {
27
+ var context = {};
28
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
29
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
30
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
31
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
32
+ if (kind === "accessor") {
33
+ if (result === void 0) continue;
34
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
35
+ if (_ = accept(result.get)) descriptor.get = _;
36
+ if (_ = accept(result.set)) descriptor.set = _;
37
+ if (_ = accept(result.init)) initializers.unshift(_);
38
+ }
39
+ else if (_ = accept(result)) {
40
+ if (kind === "field") initializers.unshift(_);
41
+ else descriptor[key] = _;
42
+ }
43
+ }
44
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
45
+ done = true;
46
+ };
13
47
  // node
14
48
  import { join, resolve } from 'node:path';
15
49
  import { mkdir, writeFile } from 'node:fs/promises';
@@ -18,352 +52,418 @@ import { errorFunction } from '../utils/error-utils.js';
18
52
  import { Project } from '../containers/project.js';
19
53
  import { Validate } from './validate.js';
20
54
  import { EMPTY_RANK, sortItems } from '../utils/lexorank.js';
55
+ import { ROOT } from '../utils/constants.js';
21
56
  import { isModulePath } from '../utils/card-utils.js';
22
57
  import { resourceName, resourceNameToString } from '../utils/resource-utils.js';
58
+ import { write } from '../utils/rw-lock.js';
23
59
  import { writeJsonFile } from '../utils/json.js';
24
60
  // todo: Is there a easy to way to make JSON schema into a TypeScript interface/type?
25
61
  // Check this out: https://www.npmjs.com/package/json-schema-to-ts
26
62
  /**
27
63
  * Handles all create commands.
28
64
  */
29
- export class Create {
30
- project;
31
- constructor(project) {
32
- this.project = project;
33
- }
34
- static JSONFileContent = [
35
- {
36
- path: '.cards/local',
37
- content: [{ id: 'cardsConfigSchema', version: 1 }],
38
- name: Project.schemaContentFile,
39
- },
40
- {
41
- path: '.cards/local',
42
- content: {
43
- schemaVersion: SCHEMA_VERSION,
44
- cardKeyPrefix: '$PROJECT-PREFIX',
45
- name: '$PROJECT-NAME',
46
- description: '',
47
- modules: [],
48
- hubs: [],
49
- },
50
- name: Project.projectConfigFileName,
51
- },
52
- ];
53
- static gitIgnoreContent = [
54
- '.calc',
55
- '.asciidoctor',
56
- '.vscode',
57
- '*.html',
58
- '*.pdf',
59
- '*.puml',
60
- '**/.DS_Store',
61
- '*-debug.log',
62
- '*-error.log',
63
- '.temp',
64
- '.logs',
65
- '.cache',
66
- ];
67
- /**
68
- * Adds new cards to a template.
69
- * @param cardTypeName Card type for new cards.
70
- * @param templateName Template name to add cards into.
71
- * @param card Optional, if defined adds a new child-card under the card.
72
- * @param count How many cards to add. By default one.
73
- * @returns non-empty string array with ids of added cards
74
- */
75
- async addCards(cardTypeName, templateName, card, count = 1) {
76
- if (!templateName ||
77
- !Validate.validateFolder(join(this.project.basePath, templateName))) {
78
- throw new Error(`Input validation error: template name is invalid '${templateName}'`);
79
- }
80
- if (cardTypeName === undefined) {
81
- throw new Error(`Input validation error: card type cannot be empty`);
65
+ let Create = (() => {
66
+ let _instanceExtraInitializers = [];
67
+ let _addCards_decorators;
68
+ let _addHubLocation_decorators;
69
+ let _createAttachment_decorators;
70
+ let _createCalculation_decorators;
71
+ let _createCard_decorators;
72
+ let _createCardType_decorators;
73
+ let _createFieldType_decorators;
74
+ let _createGraphModel_decorators;
75
+ let _createGraphView_decorators;
76
+ let _createLabel_decorators;
77
+ let _createLinkType_decorators;
78
+ let _createLink_decorators;
79
+ let _createReport_decorators;
80
+ let _createTemplate_decorators;
81
+ let _createWorkflow_decorators;
82
+ return class Create {
83
+ static {
84
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
85
+ _addCards_decorators = [write((cardTypeName, templateName) => `Add cards of type ${cardTypeName} to template ${templateName}`)];
86
+ _addHubLocation_decorators = [write((hubUrl) => `Add hub ${hubUrl}`)];
87
+ _createAttachment_decorators = [write((cardKey, attachment) => `Add attachment ${attachment} to ${cardKey}`)];
88
+ _createCalculation_decorators = [write((calculationName) => `Create calculation ${calculationName}`)];
89
+ _createCard_decorators = [write((templateName) => `Create card from template ${templateName}`)];
90
+ _createCardType_decorators = [write((cardTypeName) => `Create card type ${cardTypeName}`)];
91
+ _createFieldType_decorators = [write((fieldTypeName) => `Create field type ${fieldTypeName}`)];
92
+ _createGraphModel_decorators = [write((graphModelName) => `Create graph model ${graphModelName}`)];
93
+ _createGraphView_decorators = [write((graphViewName) => `Create graph view ${graphViewName}`)];
94
+ _createLabel_decorators = [write((cardKey, label) => `Add label ${label} to ${cardKey}`)];
95
+ _createLinkType_decorators = [write((linkTypeName) => `Create link type ${linkTypeName}`)];
96
+ _createLink_decorators = [write((cardKey, destinationCardKey, linkType) => `Create ${linkType} link from ${cardKey} to ${destinationCardKey}`)];
97
+ _createReport_decorators = [write((name) => `Create report ${name}`)];
98
+ _createTemplate_decorators = [write((templateName) => `Create template ${templateName}`)];
99
+ _createWorkflow_decorators = [write((workflowName) => `Create workflow ${workflowName}`)];
100
+ __esDecorate(this, null, _addCards_decorators, { kind: "method", name: "addCards", static: false, private: false, access: { has: obj => "addCards" in obj, get: obj => obj.addCards }, metadata: _metadata }, null, _instanceExtraInitializers);
101
+ __esDecorate(this, null, _addHubLocation_decorators, { kind: "method", name: "addHubLocation", static: false, private: false, access: { has: obj => "addHubLocation" in obj, get: obj => obj.addHubLocation }, metadata: _metadata }, null, _instanceExtraInitializers);
102
+ __esDecorate(this, null, _createAttachment_decorators, { kind: "method", name: "createAttachment", static: false, private: false, access: { has: obj => "createAttachment" in obj, get: obj => obj.createAttachment }, metadata: _metadata }, null, _instanceExtraInitializers);
103
+ __esDecorate(this, null, _createCalculation_decorators, { kind: "method", name: "createCalculation", static: false, private: false, access: { has: obj => "createCalculation" in obj, get: obj => obj.createCalculation }, metadata: _metadata }, null, _instanceExtraInitializers);
104
+ __esDecorate(this, null, _createCard_decorators, { kind: "method", name: "createCard", static: false, private: false, access: { has: obj => "createCard" in obj, get: obj => obj.createCard }, metadata: _metadata }, null, _instanceExtraInitializers);
105
+ __esDecorate(this, null, _createCardType_decorators, { kind: "method", name: "createCardType", static: false, private: false, access: { has: obj => "createCardType" in obj, get: obj => obj.createCardType }, metadata: _metadata }, null, _instanceExtraInitializers);
106
+ __esDecorate(this, null, _createFieldType_decorators, { kind: "method", name: "createFieldType", static: false, private: false, access: { has: obj => "createFieldType" in obj, get: obj => obj.createFieldType }, metadata: _metadata }, null, _instanceExtraInitializers);
107
+ __esDecorate(this, null, _createGraphModel_decorators, { kind: "method", name: "createGraphModel", static: false, private: false, access: { has: obj => "createGraphModel" in obj, get: obj => obj.createGraphModel }, metadata: _metadata }, null, _instanceExtraInitializers);
108
+ __esDecorate(this, null, _createGraphView_decorators, { kind: "method", name: "createGraphView", static: false, private: false, access: { has: obj => "createGraphView" in obj, get: obj => obj.createGraphView }, metadata: _metadata }, null, _instanceExtraInitializers);
109
+ __esDecorate(this, null, _createLabel_decorators, { kind: "method", name: "createLabel", static: false, private: false, access: { has: obj => "createLabel" in obj, get: obj => obj.createLabel }, metadata: _metadata }, null, _instanceExtraInitializers);
110
+ __esDecorate(this, null, _createLinkType_decorators, { kind: "method", name: "createLinkType", static: false, private: false, access: { has: obj => "createLinkType" in obj, get: obj => obj.createLinkType }, metadata: _metadata }, null, _instanceExtraInitializers);
111
+ __esDecorate(this, null, _createLink_decorators, { kind: "method", name: "createLink", static: false, private: false, access: { has: obj => "createLink" in obj, get: obj => obj.createLink }, metadata: _metadata }, null, _instanceExtraInitializers);
112
+ __esDecorate(this, null, _createReport_decorators, { kind: "method", name: "createReport", static: false, private: false, access: { has: obj => "createReport" in obj, get: obj => obj.createReport }, metadata: _metadata }, null, _instanceExtraInitializers);
113
+ __esDecorate(this, null, _createTemplate_decorators, { kind: "method", name: "createTemplate", static: false, private: false, access: { has: obj => "createTemplate" in obj, get: obj => obj.createTemplate }, metadata: _metadata }, null, _instanceExtraInitializers);
114
+ __esDecorate(this, null, _createWorkflow_decorators, { kind: "method", name: "createWorkflow", static: false, private: false, access: { has: obj => "createWorkflow" in obj, get: obj => obj.createWorkflow }, metadata: _metadata }, null, _instanceExtraInitializers);
115
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
82
116
  }
83
- const templateResource = this.project.resources.byType(templateName, 'templates');
84
- const templateObject = templateResource.templateObject();
85
- const specificCard = card ? templateObject.findCard(card) : undefined;
86
- if (isModulePath(templateObject.templateFolder())) {
87
- throw new Error(`Cannot add cards to imported module templates`);
117
+ project = __runInitializers(this, _instanceExtraInitializers);
118
+ constructor(project) {
119
+ this.project = project;
88
120
  }
89
- // Collect all add-card promises and settle them in parallel.
90
- const promiseContainer = [];
91
- const cardsContainer = [];
92
- for (let cardCount = 0; cardCount < count; ++cardCount) {
93
- promiseContainer.push(templateObject.addCard(cardTypeName, specificCard));
94
- }
95
- const promisesResult = await Promise.allSettled(promiseContainer).then((results) => {
96
- for (const result of results) {
97
- if (result.status !== 'fulfilled') {
98
- throw new Error(result.reason);
99
- }
100
- cardsContainer.push(result.value);
121
+ static JSONFileContent = [
122
+ {
123
+ path: '.cards/local',
124
+ content: [{ id: 'cardsConfigSchema', version: 1 }],
125
+ name: Project.schemaContentFile,
126
+ },
127
+ {
128
+ path: '.cards/local',
129
+ content: {
130
+ schemaVersion: SCHEMA_VERSION,
131
+ cardKeyPrefix: '$PROJECT-PREFIX',
132
+ name: '$PROJECT-NAME',
133
+ description: '',
134
+ modules: [],
135
+ hubs: [],
136
+ },
137
+ name: Project.projectConfigFileName,
138
+ },
139
+ ];
140
+ static gitIgnoreContent = [
141
+ '.calc',
142
+ '.asciidoctor',
143
+ '.vscode',
144
+ '*.html',
145
+ '*.pdf',
146
+ '*.puml',
147
+ '**/.DS_Store',
148
+ '*-debug.log',
149
+ '*-error.log',
150
+ '.temp',
151
+ '.logs',
152
+ '.cache',
153
+ ];
154
+ /**
155
+ * Adds new cards to a template.
156
+ * @param cardTypeName Card type for new cards.
157
+ * @param templateName Template name to add cards into.
158
+ * @param card Optional, if defined adds a new child-card under the card.
159
+ * @param count How many cards to add. By default one.
160
+ * @returns non-empty string array with ids of added cards
161
+ */
162
+ async addCards(cardTypeName, templateName, card, count = 1) {
163
+ if (!templateName ||
164
+ !Validate.validateFolder(join(this.project.basePath, templateName))) {
165
+ throw new Error(`Input validation error: template name is invalid '${templateName}'`);
101
166
  }
102
- });
103
- if (cardsContainer.length === 0) {
104
- throw new Error(`Invalid value for 'repeat:' "${count}"`);
105
- }
106
- if (promisesResult === undefined) {
107
- return cardsContainer;
108
- }
109
- else {
110
- throw new Error('Unknown error');
111
- }
112
- }
113
- /**
114
- * Adds a new hub location.
115
- * @param hubUrl URL of the hub
116
- */
117
- async addHubLocation(hubUrl) {
118
- return this.project.configuration.addHub(hubUrl);
119
- }
120
- /**
121
- * Adds an attachment to a card.
122
- * @param cardKey card ID
123
- * @param attachment path to an attachment file or attachment name if buffer is defined
124
- * @param buffer (Optional) attachment buffer
125
- */
126
- async createAttachment(cardKey, attachment, buffer) {
127
- try {
128
- await this.project.createCardAttachment(cardKey, attachment, buffer || attachment);
129
- }
130
- catch (error) {
131
- throw new Error(errorFunction(error));
132
- }
133
- }
134
- /**
135
- * Creates a calculation resource.
136
- * @param calculationName name for the calculation resource
137
- */
138
- async createCalculation(calculationName) {
139
- return this.project.resources
140
- .byType(calculationName, 'calculations')
141
- .create();
142
- }
143
- /**
144
- * Creates card(s) to a project. All cards from template are instantiated to the project.
145
- * @param templateName name of a template to use
146
- * @param parentCardKey (Optional) card-key of a parent card. If missing, cards are added to the card root.
147
- * @returns array of card keys that were created. Cards are sorted by their parent key and rank. Template root cards are first but the order between other card groups is not guaranteed. However, the order of cards within a group is guaranteed to be ordered by rank.
148
- */
149
- async createCard(templateName, parentCardKey) {
150
- const templateResource = this.project.resources.byType(templateName, 'templates');
151
- Validate.getInstance().validResourceName('templates', resourceNameToString(resourceName(templateName)), this.project.allModulePrefixes());
152
- await templateResource.validate();
153
- const specificCard = parentCardKey
154
- ? this.project.findCard(parentCardKey)
155
- : undefined;
156
- const templateObject = templateResource.templateObject();
157
- if (!templateObject || !templateObject.isCreated()) {
158
- throw new Error(`Template '${templateName}' not found from project`);
159
- }
160
- const createdCards = await templateObject.createCards(specificCard);
161
- if (createdCards.length > 0) {
162
- // Note: This assumes that parent keys will be ahead of 'a' in the sort order.
163
- const sorted = sortItems(createdCards, (item) => {
164
- return `${item.parent === 'root' ? 'a' : item.parent}${item.metadata?.rank || EMPTY_RANK}`;
167
+ if (cardTypeName === undefined) {
168
+ throw new Error(`Input validation error: card type cannot be empty`);
169
+ }
170
+ const templateResource = this.project.resources.byType(templateName, 'templates');
171
+ const templateObject = templateResource.templateObject();
172
+ const specificCard = card ? templateObject.findCard(card) : undefined;
173
+ if (isModulePath(templateObject.templateFolder())) {
174
+ throw new Error(`Cannot add cards to imported module templates`);
175
+ }
176
+ // Collect all add-card promises and settle them in parallel.
177
+ const promiseContainer = [];
178
+ const cardsContainer = [];
179
+ for (let cardCount = 0; cardCount < count; ++cardCount) {
180
+ promiseContainer.push(templateObject.addCard(cardTypeName, specificCard));
181
+ }
182
+ const promisesResult = await Promise.allSettled(promiseContainer).then((results) => {
183
+ for (const result of results) {
184
+ if (result.status !== 'fulfilled') {
185
+ throw new Error(result.reason);
186
+ }
187
+ cardsContainer.push(result.value);
188
+ }
165
189
  });
166
- return sorted;
167
- }
168
- return [];
169
- }
170
- /**
171
- * Creates a card type.
172
- * @param cardTypeName name for the card type.
173
- * @param workflowName workflow name to use in the card type.
174
- */
175
- async createCardType(cardTypeName, workflowName) {
176
- return this.project.resources
177
- .byType(cardTypeName, 'cardTypes')
178
- .createCardType(workflowName);
179
- }
180
- /**
181
- * Creates a new field type.
182
- * @param fieldTypeName name for the field type.
183
- * @param dataType data type for the field type
184
- */
185
- async createFieldType(fieldTypeName, dataType) {
186
- return this.project.resources
187
- .byType(fieldTypeName, 'fieldTypes')
188
- .createFieldType(dataType);
189
- }
190
- /**
191
- * Creates a new graph model.
192
- * @param graphModelName name for the graph model.
193
- */
194
- async createGraphModel(graphModelName) {
195
- return this.project.resources
196
- .byType(graphModelName, 'graphModels')
197
- .create();
198
- }
199
- /**
200
- * Creates a new graph view.
201
- * @param graphViewName name for the graph view.
202
- */
203
- async createGraphView(graphViewName) {
204
- return this.project.resources.byType(graphViewName, 'graphViews').create();
205
- }
206
- /**
207
- * Creates a label in the given card
208
- * @param cardKey The card to which the label is added to
209
- * @param label The label being added
210
- */
211
- async createLabel(cardKey, label) {
212
- if (!Validate.isValidLabelName(label)) {
213
- throw new Error(`Not a valid label name'`);
214
- }
215
- const card = this.project.findCard(cardKey);
216
- const labels = structuredClone(card.metadata?.labels) ?? [];
217
- if (labels.includes(label)) {
218
- throw new Error('Label already exists');
219
- }
220
- labels.push(label);
221
- return this.project.updateCardMetadataKey(cardKey, 'labels', labels);
222
- }
223
- /**
224
- * Creates a new link type.
225
- * @param linkTypeName name for the link type.
226
- */
227
- async createLinkType(linkTypeName) {
228
- return this.project.resources.byType(linkTypeName, 'linkTypes').create();
229
- }
230
- /**
231
- * Creates a link between two cards.
232
- * @param cardKey The card to update
233
- * @param destinationCardKey The card to link to
234
- * @param linkType The type of link to add
235
- * @param linkDescription Optional description of the link
236
- */
237
- async createLink(cardKey, destinationCardKey, linkType, linkDescription) {
238
- if (cardKey === destinationCardKey) {
239
- throw new Error('Cannot link card to itself');
190
+ if (cardsContainer.length === 0) {
191
+ throw new Error(`Invalid value for 'repeat:' "${count}"`);
192
+ }
193
+ if (promisesResult === undefined) {
194
+ return cardsContainer;
195
+ }
196
+ else {
197
+ throw new Error('Unknown error');
198
+ }
240
199
  }
241
- // Determine the card path
242
- const card = this.project.findCard(cardKey);
243
- const destinationCard = this.project.findCard(destinationCardKey);
244
- // make sure the link type exists
245
- const linkTypeObject = this.project.resources
246
- .byType(linkType, 'linkTypes')
247
- .show();
248
- // make sure that if linkDescription is not enabled, linkDescription is not provided
249
- if (!linkTypeObject.enableLinkDescription &&
250
- linkDescription !== undefined) {
251
- throw new Error(`Link type '${linkType}' does not allow link description`);
200
+ /**
201
+ * Adds a new hub location.
202
+ * @param hubUrl URL of the hub
203
+ */
204
+ async addHubLocation(hubUrl) {
205
+ return this.project.configuration.addHub(hubUrl);
252
206
  }
253
- // make sure source card key exists in the link type sourceCardTypes
254
- // if sourceCardTypes is empty, any card can be linked
255
- if (linkTypeObject.sourceCardTypes.length > 0 &&
256
- !linkTypeObject.sourceCardTypes.includes(card.metadata.cardType)) {
257
- throw new Error(`Card type '${card.metadata?.cardType}' cannot be linked with link type '${linkType}'`);
207
+ /**
208
+ * Adds an attachment to a card.
209
+ * @param cardKey card ID
210
+ * @param attachment path to an attachment file or attachment name if buffer is defined
211
+ * @param buffer (Optional) attachment buffer
212
+ */
213
+ async createAttachment(cardKey, attachment, buffer) {
214
+ try {
215
+ await this.project.createCardAttachment(cardKey, attachment, buffer || attachment);
216
+ }
217
+ catch (error) {
218
+ throw new Error(errorFunction(error), { cause: error });
219
+ }
258
220
  }
259
- // make sure destination card key exists in the link type destinationCardTypes
260
- // if destinationCardTypes is empty, any card can be linked
261
- if (linkTypeObject.destinationCardTypes.length > 0 &&
262
- !linkTypeObject.destinationCardTypes.includes(destinationCard.metadata.cardType)) {
263
- throw new Error(`Card type '${destinationCard.metadata.cardType}' cannot be linked with link type '${linkType}'`);
221
+ /**
222
+ * Creates a calculation resource.
223
+ * @param calculationName name for the calculation resource
224
+ */
225
+ async createCalculation(calculationName) {
226
+ return this.project.resources
227
+ .byType(calculationName, 'calculations')
228
+ .create();
264
229
  }
265
- // if contains the same link, do not add it again
266
- const existingLink = card.metadata?.links.find((l) => l.linkType === linkType &&
267
- l.cardKey === destinationCardKey &&
268
- l.linkDescription === linkDescription);
269
- if (existingLink) {
270
- throw new Error(`Link from card '${cardKey}' to card '${destinationCardKey}' already exists`);
230
+ /**
231
+ * Creates card(s) to a project. All cards from template are instantiated to the project.
232
+ * @param templateName name of a template to use
233
+ * @param parentCardKey (Optional) card-key of a parent card. If missing, cards are added to the card root.
234
+ * @returns array of card keys that were created. Cards are sorted by their parent key and rank. Template root cards are first but the order between other card groups is not guaranteed. However, the order of cards within a group is guaranteed to be ordered by rank.
235
+ */
236
+ async createCard(templateName, parentCardKey) {
237
+ const templateResource = this.project.resources.byType(templateName, 'templates');
238
+ Validate.getInstance().validResourceName('templates', resourceNameToString(resourceName(templateName)), this.project.allModulePrefixes());
239
+ await templateResource.validate();
240
+ const specificCard = parentCardKey
241
+ ? this.project.findCard(parentCardKey)
242
+ : undefined;
243
+ const templateObject = templateResource.templateObject();
244
+ if (!templateObject || !templateObject.isCreated()) {
245
+ throw new Error(`Template '${templateName}' not found from project`);
246
+ }
247
+ const createdCards = await templateObject.createCards(specificCard);
248
+ if (createdCards.length > 0) {
249
+ const rootParent = specificCard?.key ?? ROOT;
250
+ const rootCards = [];
251
+ const childCards = [];
252
+ for (const card of createdCards) {
253
+ if (card.parent === rootParent) {
254
+ rootCards.push(card);
255
+ }
256
+ else {
257
+ childCards.push(card);
258
+ }
259
+ }
260
+ return [
261
+ ...sortItems(rootCards, (item) => item.metadata?.rank || EMPTY_RANK),
262
+ ...childCards,
263
+ ];
264
+ }
265
+ return [];
271
266
  }
272
- const links = card.metadata?.links || [];
273
- links.push({
274
- linkType,
275
- cardKey: destinationCardKey,
276
- linkDescription,
277
- });
278
- await this.project.updateCardMetadataKey(cardKey, 'links', links);
279
- }
280
- /**
281
- * Creates a new project.
282
- * @param projectPath where to create the project.
283
- * @param projectPrefix prefix for the project.
284
- * @param projectName name for the project.
285
- * @param projectCategory category for the project (empty string if not provided).
286
- * @param projectDescription description for the project (empty string if not provided).
287
- */
288
- static async createProject(projectPath, projectPrefix, projectName, projectCategory, projectDescription) {
289
- projectPath = resolve(projectPath);
290
- if (!projectPath) {
291
- throw new Error('Cannot create project without a path');
267
+ /**
268
+ * Creates a card type.
269
+ * @param cardTypeName name for the card type.
270
+ * @param workflowName workflow name to use in the card type.
271
+ */
272
+ async createCardType(cardTypeName, workflowName) {
273
+ return this.project.resources
274
+ .byType(cardTypeName, 'cardTypes')
275
+ .createCardType(workflowName);
292
276
  }
293
- const projectFolders = ['.cards/local', 'cardRoot'];
294
- if (!Validate.validateFolder(projectPath)) {
295
- throw new Error(`Input validation error: folder name '${projectPath}' is invalid`);
277
+ /**
278
+ * Creates a new field type.
279
+ * @param fieldTypeName name for the field type.
280
+ * @param dataType data type for the field type
281
+ */
282
+ async createFieldType(fieldTypeName, dataType) {
283
+ return this.project.resources
284
+ .byType(fieldTypeName, 'fieldTypes')
285
+ .createFieldType(dataType);
296
286
  }
297
- if (projectPrefix === undefined ||
298
- projectPrefix.length < 3 ||
299
- projectPrefix.length > 10) {
300
- throw new Error(`Input validation error: prefix must be from 3 to 10 characters long. '${projectPrefix}' does not fulfill the condition.`);
287
+ /**
288
+ * Creates a new graph model.
289
+ * @param graphModelName name for the graph model.
290
+ */
291
+ async createGraphModel(graphModelName) {
292
+ return this.project.resources
293
+ .byType(graphModelName, 'graphModels')
294
+ .create();
301
295
  }
302
- if (!Validate.isValidProjectName(projectName)) {
303
- throw new Error(`Input validation error: invalid project name '${projectName}'`);
296
+ /**
297
+ * Creates a new graph view.
298
+ * @param graphViewName name for the graph view.
299
+ */
300
+ async createGraphView(graphViewName) {
301
+ return this.project.resources.byType(graphViewName, 'graphViews').create();
304
302
  }
305
- if (!Validate.validatePrefix(projectPrefix)) {
306
- throw new Error(`Input validation error: invalid prefix '${projectPrefix}'`);
303
+ /**
304
+ * Creates a label in the given card
305
+ * @param cardKey The card to which the label is added to
306
+ * @param label The label being added
307
+ */
308
+ async createLabel(cardKey, label) {
309
+ if (!Validate.isValidLabelName(label)) {
310
+ throw new Error(`Not a valid label name'`);
311
+ }
312
+ const card = this.project.findCard(cardKey);
313
+ const labels = structuredClone(card.metadata?.labels) ?? [];
314
+ if (labels.includes(label)) {
315
+ throw new Error('Label already exists');
316
+ }
317
+ labels.push(label);
318
+ return this.project.updateCardMetadataKey(cardKey, 'labels', labels);
307
319
  }
308
- if (Project.isCreated(projectPath)) {
309
- throw new Error('Project already exists');
320
+ /**
321
+ * Creates a new link type.
322
+ * @param linkTypeName name for the link type.
323
+ */
324
+ async createLinkType(linkTypeName) {
325
+ return this.project.resources.byType(linkTypeName, 'linkTypes').create();
310
326
  }
311
- if (!Validate.isValidProjectName(projectName)) {
312
- throw new Error(`Input validation error: invalid project name '${projectName}'`);
327
+ /**
328
+ * Creates a link between two cards.
329
+ * @param cardKey The card to update
330
+ * @param destinationCardKey The card to link to
331
+ * @param linkType The type of link to add
332
+ * @param linkDescription Optional description of the link
333
+ */
334
+ async createLink(cardKey, destinationCardKey, linkType, linkDescription) {
335
+ if (cardKey === destinationCardKey) {
336
+ throw new Error('Cannot link card to itself');
337
+ }
338
+ // Determine the card path
339
+ const card = this.project.findCard(cardKey);
340
+ const destinationCard = this.project.findCard(destinationCardKey);
341
+ // make sure the link type exists
342
+ const linkTypeObject = this.project.resources
343
+ .byType(linkType, 'linkTypes')
344
+ .show();
345
+ // make sure that if linkDescription is not enabled, linkDescription is not provided
346
+ if (!linkTypeObject.enableLinkDescription &&
347
+ linkDescription !== undefined) {
348
+ throw new Error(`Link type '${linkType}' does not allow link description`);
349
+ }
350
+ // make sure source card key exists in the link type sourceCardTypes
351
+ // if sourceCardTypes is empty, any card can be linked
352
+ if (linkTypeObject.sourceCardTypes.length > 0 &&
353
+ !linkTypeObject.sourceCardTypes.includes(card.metadata.cardType)) {
354
+ throw new Error(`Card type '${card.metadata?.cardType}' cannot be linked with link type '${linkType}'`);
355
+ }
356
+ // make sure destination card key exists in the link type destinationCardTypes
357
+ // if destinationCardTypes is empty, any card can be linked
358
+ if (linkTypeObject.destinationCardTypes.length > 0 &&
359
+ !linkTypeObject.destinationCardTypes.includes(destinationCard.metadata.cardType)) {
360
+ throw new Error(`Card type '${destinationCard.metadata.cardType}' cannot be linked with link type '${linkType}'`);
361
+ }
362
+ // if contains the same link, do not add it again
363
+ const existingLink = card.metadata?.links.find((l) => l.linkType === linkType &&
364
+ l.cardKey === destinationCardKey &&
365
+ l.linkDescription === linkDescription);
366
+ if (existingLink) {
367
+ throw new Error(`Link from card '${cardKey}' to card '${destinationCardKey}' already exists`);
368
+ }
369
+ const links = card.metadata?.links || [];
370
+ links.push({
371
+ linkType,
372
+ cardKey: destinationCardKey,
373
+ linkDescription,
374
+ });
375
+ await this.project.updateCardMetadataKey(cardKey, 'links', links);
313
376
  }
314
- await mkdir(projectPath, { recursive: true }).then(async () => {
315
- return await Promise.all(projectFolders.map((folder) => mkdir(`${projectPath}/${folder}`, { recursive: true })));
316
- });
317
- await Promise.all(Create.JSONFileContent.map(async (entry) => {
318
- if ('cardKeyPrefix' in entry.content) {
319
- if (entry.content.cardKeyPrefix.includes('$PROJECT-PREFIX')) {
320
- entry.content.cardKeyPrefix = projectPrefix.toLowerCase();
321
- }
322
- if (entry.content.name.includes('$PROJECT-NAME')) {
323
- entry.content.name = projectName;
324
- }
325
- if (projectCategory) {
326
- entry.content.category = projectCategory;
327
- }
328
- if (projectDescription) {
329
- entry.content.description = projectDescription;
377
+ /**
378
+ * Creates a new project.
379
+ * @param projectPath where to create the project.
380
+ * @param projectPrefix prefix for the project.
381
+ * @param projectName name for the project.
382
+ * @param projectCategory category for the project (empty string if not provided).
383
+ * @param projectDescription description for the project (empty string if not provided).
384
+ */
385
+ static async createProject(projectPath, projectPrefix, projectName, projectCategory, projectDescription) {
386
+ // No lock required, since we are creating a new project
387
+ projectPath = resolve(projectPath);
388
+ if (!projectPath) {
389
+ throw new Error('Cannot create project without a path');
390
+ }
391
+ const projectFolders = ['.cards/local', 'cardRoot'];
392
+ if (!Validate.validateFolder(projectPath)) {
393
+ throw new Error(`Input validation error: folder name '${projectPath}' is invalid`);
394
+ }
395
+ if (projectPrefix === undefined ||
396
+ projectPrefix.length < 3 ||
397
+ projectPrefix.length > 10) {
398
+ throw new Error(`Input validation error: prefix must be from 3 to 10 characters long. '${projectPrefix}' does not fulfill the condition.`);
399
+ }
400
+ if (!Validate.isValidProjectName(projectName)) {
401
+ throw new Error(`Input validation error: invalid project name '${projectName}'`);
402
+ }
403
+ if (!Validate.validatePrefix(projectPrefix)) {
404
+ throw new Error(`Input validation error: invalid prefix '${projectPrefix}'`);
405
+ }
406
+ if (Project.isCreated(projectPath)) {
407
+ throw new Error('Project already exists');
408
+ }
409
+ if (!Validate.isValidProjectName(projectName)) {
410
+ throw new Error(`Input validation error: invalid project name '${projectName}'`);
411
+ }
412
+ await mkdir(projectPath, { recursive: true }).then(async () => {
413
+ return await Promise.all(projectFolders.map((folder) => mkdir(`${projectPath}/${folder}`, { recursive: true })));
414
+ });
415
+ await Promise.all(Create.JSONFileContent.map(async (entry) => {
416
+ if ('cardKeyPrefix' in entry.content) {
417
+ if (entry.content.cardKeyPrefix.includes('$PROJECT-PREFIX')) {
418
+ entry.content.cardKeyPrefix = projectPrefix.toLowerCase();
419
+ }
420
+ if (entry.content.name.includes('$PROJECT-NAME')) {
421
+ entry.content.name = projectName;
422
+ }
423
+ if (projectCategory) {
424
+ entry.content.category = projectCategory;
425
+ }
426
+ if (projectDescription) {
427
+ entry.content.description = projectDescription;
428
+ }
330
429
  }
430
+ await writeJsonFile(join(projectPath, entry.path, entry.name), entry.content);
431
+ }));
432
+ try {
433
+ await writeFile(join(projectPath, '.gitignore'), this.gitIgnoreContent.join('\n') + '\n');
434
+ }
435
+ catch {
436
+ console.error('Failed to create project');
331
437
  }
332
- await writeJsonFile(join(projectPath, entry.path, entry.name), entry.content);
333
- }));
334
- try {
335
- await writeFile(join(projectPath, '.gitignore'), this.gitIgnoreContent.join('\n') + '\n');
336
438
  }
337
- catch {
338
- console.error('Failed to create project');
439
+ /**
440
+ * Creates a report
441
+ * @param name name of the report
442
+ */
443
+ async createReport(name) {
444
+ return this.project.resources.byType(name, 'reports').createReport();
339
445
  }
340
- }
341
- /**
342
- * Creates a report
343
- * @param name name of the report
344
- */
345
- async createReport(name) {
346
- return this.project.resources.byType(name, 'reports').createReport();
347
- }
348
- /**
349
- * Creates a new template to a project.
350
- * @param templateName Name of the template.
351
- * @param templateContent JSON content for the template file.
352
- */
353
- async createTemplate(templateName, templateContent) {
354
- return this.project.resources
355
- .byType(templateName, 'templates')
356
- .create(templateContent ? JSON.parse(templateContent) : undefined);
357
- }
358
- /**
359
- * Creates a workflow.
360
- * @param workflowName workflow name
361
- * @param workflowContent workflow content JSON
362
- */
363
- async createWorkflow(workflowName, workflowContent) {
364
- return this.project.resources
365
- .byType(workflowName, 'workflows')
366
- .create(workflowContent ? JSON.parse(workflowContent) : undefined);
367
- }
368
- }
446
+ /**
447
+ * Creates a new template to a project.
448
+ * @param templateName Name of the template.
449
+ * @param templateContent JSON content for the template file.
450
+ */
451
+ async createTemplate(templateName, templateContent) {
452
+ return this.project.resources
453
+ .byType(templateName, 'templates')
454
+ .create(templateContent ? JSON.parse(templateContent) : undefined);
455
+ }
456
+ /**
457
+ * Creates a workflow.
458
+ * @param workflowName workflow name
459
+ * @param workflowContent workflow content JSON
460
+ */
461
+ async createWorkflow(workflowName, workflowContent) {
462
+ return this.project.resources
463
+ .byType(workflowName, 'workflows')
464
+ .create(workflowContent ? JSON.parse(workflowContent) : undefined);
465
+ }
466
+ };
467
+ })();
468
+ export { Create };
369
469
  //# sourceMappingURL=create.js.map