@cyberismo/data-handler 0.0.21 → 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 (166) 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 +417 -328
  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/index.js +3 -1
  53. package/dist/macros/index.js.map +1 -1
  54. package/dist/macros/report/index.js +1 -1
  55. package/dist/macros/report/index.js.map +1 -1
  56. package/dist/module-manager.js +5 -3
  57. package/dist/module-manager.js.map +1 -1
  58. package/dist/project-settings.js +2 -2
  59. package/dist/project-settings.js.map +1 -1
  60. package/dist/resources/card-type-resource.js +1 -1
  61. package/dist/resources/card-type-resource.js.map +1 -1
  62. package/dist/resources/create-defaults.js +0 -1
  63. package/dist/resources/create-defaults.js.map +1 -1
  64. package/dist/resources/field-type-resource.js +2 -5
  65. package/dist/resources/field-type-resource.js.map +1 -1
  66. package/dist/resources/file-resource.js +4 -1
  67. package/dist/resources/file-resource.js.map +1 -1
  68. package/dist/resources/folder-resource.d.ts +1 -1
  69. package/dist/resources/folder-resource.js +4 -1
  70. package/dist/resources/folder-resource.js.map +1 -1
  71. package/dist/resources/graph-model-resource.d.ts +1 -8
  72. package/dist/resources/graph-model-resource.js +0 -14
  73. package/dist/resources/graph-model-resource.js.map +1 -1
  74. package/dist/resources/graph-view-resource.d.ts +1 -8
  75. package/dist/resources/graph-view-resource.js +0 -14
  76. package/dist/resources/graph-view-resource.js.map +1 -1
  77. package/dist/resources/link-type-resource.js +1 -1
  78. package/dist/resources/link-type-resource.js.map +1 -1
  79. package/dist/resources/report-resource.d.ts +1 -8
  80. package/dist/resources/report-resource.js +0 -14
  81. package/dist/resources/report-resource.js.map +1 -1
  82. package/dist/resources/resource-object.d.ts +11 -1
  83. package/dist/resources/resource-object.js +19 -2
  84. package/dist/resources/resource-object.js.map +1 -1
  85. package/dist/resources/template-resource.d.ts +1 -9
  86. package/dist/resources/template-resource.js +0 -15
  87. package/dist/resources/template-resource.js.map +1 -1
  88. package/dist/resources/workflow-resource.js +1 -1
  89. package/dist/resources/workflow-resource.js.map +1 -1
  90. package/dist/utils/card-utils.js +1 -1
  91. package/dist/utils/card-utils.js.map +1 -1
  92. package/dist/utils/commit-context.d.ts +23 -0
  93. package/dist/utils/commit-context.js +30 -0
  94. package/dist/utils/commit-context.js.map +1 -0
  95. package/dist/utils/file-utils.js +3 -1
  96. package/dist/utils/file-utils.js.map +1 -1
  97. package/dist/utils/git-manager.d.ts +29 -0
  98. package/dist/utils/git-manager.js +76 -0
  99. package/dist/utils/git-manager.js.map +1 -0
  100. package/dist/utils/handlebars-helpers.d.ts +22 -0
  101. package/dist/utils/handlebars-helpers.js +78 -0
  102. package/dist/utils/handlebars-helpers.js.map +1 -0
  103. package/dist/utils/json.js +6 -2
  104. package/dist/utils/json.js.map +1 -1
  105. package/dist/utils/log-utils.d.ts +7 -2
  106. package/dist/utils/log-utils.js +28 -3
  107. package/dist/utils/log-utils.js.map +1 -1
  108. package/dist/utils/report.d.ts +0 -19
  109. package/dist/utils/report.js +4 -67
  110. package/dist/utils/report.js.map +1 -1
  111. package/dist/utils/rw-lock.d.ts +71 -0
  112. package/dist/utils/rw-lock.js +220 -0
  113. package/dist/utils/rw-lock.js.map +1 -0
  114. package/dist/utils/user-preferences.js +3 -3
  115. package/dist/utils/user-preferences.js.map +1 -1
  116. package/package.json +5 -5
  117. package/src/command-handler.ts +14 -22
  118. package/src/command-manager.ts +43 -37
  119. package/src/commands/calculate.ts +8 -1
  120. package/src/commands/create.ts +24 -1
  121. package/src/commands/edit.ts +3 -0
  122. package/src/commands/export.ts +8 -2
  123. package/src/commands/fetch.ts +3 -0
  124. package/src/commands/import.ts +5 -0
  125. package/src/commands/migrate.ts +2 -0
  126. package/src/commands/move.ts +34 -0
  127. package/src/commands/remove.ts +24 -2
  128. package/src/commands/rename.ts +2 -0
  129. package/src/commands/show.ts +63 -34
  130. package/src/commands/transition.ts +2 -0
  131. package/src/commands/update.ts +9 -3
  132. package/src/commands/validate.ts +1 -1
  133. package/src/containers/project/calculation-engine.ts +0 -1
  134. package/src/containers/project/card-cache.ts +1 -0
  135. package/src/containers/project.ts +75 -1
  136. package/src/containers/template.ts +1 -1
  137. package/src/interfaces/command-options.ts +1 -0
  138. package/src/interfaces/resource-interfaces.ts +5 -12
  139. package/src/macros/base-macro.ts +1 -1
  140. package/src/macros/graph/index.ts +3 -0
  141. package/src/macros/index.ts +3 -1
  142. package/src/macros/report/index.ts +1 -0
  143. package/src/module-manager.ts +5 -2
  144. package/src/project-settings.ts +2 -1
  145. package/src/resources/card-type-resource.ts +1 -1
  146. package/src/resources/create-defaults.ts +0 -1
  147. package/src/resources/field-type-resource.ts +2 -4
  148. package/src/resources/file-resource.ts +3 -1
  149. package/src/resources/folder-resource.ts +7 -2
  150. package/src/resources/graph-model-resource.ts +1 -25
  151. package/src/resources/graph-view-resource.ts +1 -25
  152. package/src/resources/link-type-resource.ts +1 -1
  153. package/src/resources/report-resource.ts +1 -25
  154. package/src/resources/resource-object.ts +22 -1
  155. package/src/resources/template-resource.ts +0 -23
  156. package/src/resources/workflow-resource.ts +1 -1
  157. package/src/utils/card-utils.ts +1 -1
  158. package/src/utils/commit-context.ts +45 -0
  159. package/src/utils/file-utils.ts +3 -1
  160. package/src/utils/git-manager.ts +87 -0
  161. package/src/utils/handlebars-helpers.ts +95 -0
  162. package/src/utils/json.ts +6 -2
  163. package/src/utils/log-utils.ts +33 -4
  164. package/src/utils/report.ts +8 -78
  165. package/src/utils/rw-lock.ts +279 -0
  166. 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';
@@ -21,360 +55,415 @@ import { EMPTY_RANK, sortItems } from '../utils/lexorank.js';
21
55
  import { ROOT } from '../utils/constants.js';
22
56
  import { isModulePath } from '../utils/card-utils.js';
23
57
  import { resourceName, resourceNameToString } from '../utils/resource-utils.js';
58
+ import { write } from '../utils/rw-lock.js';
24
59
  import { writeJsonFile } from '../utils/json.js';
25
60
  // todo: Is there a easy to way to make JSON schema into a TypeScript interface/type?
26
61
  // Check this out: https://www.npmjs.com/package/json-schema-to-ts
27
62
  /**
28
63
  * Handles all create commands.
29
64
  */
30
- export class Create {
31
- project;
32
- constructor(project) {
33
- this.project = project;
34
- }
35
- static JSONFileContent = [
36
- {
37
- path: '.cards/local',
38
- content: [{ id: 'cardsConfigSchema', version: 1 }],
39
- name: Project.schemaContentFile,
40
- },
41
- {
42
- path: '.cards/local',
43
- content: {
44
- schemaVersion: SCHEMA_VERSION,
45
- cardKeyPrefix: '$PROJECT-PREFIX',
46
- name: '$PROJECT-NAME',
47
- description: '',
48
- modules: [],
49
- hubs: [],
50
- },
51
- name: Project.projectConfigFileName,
52
- },
53
- ];
54
- static gitIgnoreContent = [
55
- '.calc',
56
- '.asciidoctor',
57
- '.vscode',
58
- '*.html',
59
- '*.pdf',
60
- '*.puml',
61
- '**/.DS_Store',
62
- '*-debug.log',
63
- '*-error.log',
64
- '.temp',
65
- '.logs',
66
- '.cache',
67
- ];
68
- /**
69
- * Adds new cards to a template.
70
- * @param cardTypeName Card type for new cards.
71
- * @param templateName Template name to add cards into.
72
- * @param card Optional, if defined adds a new child-card under the card.
73
- * @param count How many cards to add. By default one.
74
- * @returns non-empty string array with ids of added cards
75
- */
76
- async addCards(cardTypeName, templateName, card, count = 1) {
77
- if (!templateName ||
78
- !Validate.validateFolder(join(this.project.basePath, templateName))) {
79
- throw new Error(`Input validation error: template name is invalid '${templateName}'`);
80
- }
81
- if (cardTypeName === undefined) {
82
- 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 });
83
116
  }
84
- const templateResource = this.project.resources.byType(templateName, 'templates');
85
- const templateObject = templateResource.templateObject();
86
- const specificCard = card ? templateObject.findCard(card) : undefined;
87
- if (isModulePath(templateObject.templateFolder())) {
88
- throw new Error(`Cannot add cards to imported module templates`);
117
+ project = __runInitializers(this, _instanceExtraInitializers);
118
+ constructor(project) {
119
+ this.project = project;
89
120
  }
90
- // Collect all add-card promises and settle them in parallel.
91
- const promiseContainer = [];
92
- const cardsContainer = [];
93
- for (let cardCount = 0; cardCount < count; ++cardCount) {
94
- promiseContainer.push(templateObject.addCard(cardTypeName, specificCard));
95
- }
96
- const promisesResult = await Promise.allSettled(promiseContainer).then((results) => {
97
- for (const result of results) {
98
- if (result.status !== 'fulfilled') {
99
- throw new Error(result.reason);
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}'`);
166
+ }
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);
100
188
  }
101
- cardsContainer.push(result.value);
189
+ });
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');
102
198
  }
103
- });
104
- if (cardsContainer.length === 0) {
105
- throw new Error(`Invalid value for 'repeat:' "${count}"`);
106
- }
107
- if (promisesResult === undefined) {
108
- return cardsContainer;
109
- }
110
- else {
111
- throw new Error('Unknown error');
112
199
  }
113
- }
114
- /**
115
- * Adds a new hub location.
116
- * @param hubUrl URL of the hub
117
- */
118
- async addHubLocation(hubUrl) {
119
- return this.project.configuration.addHub(hubUrl);
120
- }
121
- /**
122
- * Adds an attachment to a card.
123
- * @param cardKey card ID
124
- * @param attachment path to an attachment file or attachment name if buffer is defined
125
- * @param buffer (Optional) attachment buffer
126
- */
127
- async createAttachment(cardKey, attachment, buffer) {
128
- try {
129
- await this.project.createCardAttachment(cardKey, attachment, buffer || attachment);
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);
130
206
  }
131
- catch (error) {
132
- throw new Error(errorFunction(error));
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
+ }
133
220
  }
134
- }
135
- /**
136
- * Creates a calculation resource.
137
- * @param calculationName name for the calculation resource
138
- */
139
- async createCalculation(calculationName) {
140
- return this.project.resources
141
- .byType(calculationName, 'calculations')
142
- .create();
143
- }
144
- /**
145
- * Creates card(s) to a project. All cards from template are instantiated to the project.
146
- * @param templateName name of a template to use
147
- * @param parentCardKey (Optional) card-key of a parent card. If missing, cards are added to the card root.
148
- * @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.
149
- */
150
- async createCard(templateName, parentCardKey) {
151
- const templateResource = this.project.resources.byType(templateName, 'templates');
152
- Validate.getInstance().validResourceName('templates', resourceNameToString(resourceName(templateName)), this.project.allModulePrefixes());
153
- await templateResource.validate();
154
- const specificCard = parentCardKey
155
- ? this.project.findCard(parentCardKey)
156
- : undefined;
157
- const templateObject = templateResource.templateObject();
158
- if (!templateObject || !templateObject.isCreated()) {
159
- throw new Error(`Template '${templateName}' not found from project`);
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();
160
229
  }
161
- const createdCards = await templateObject.createCards(specificCard);
162
- if (createdCards.length > 0) {
163
- const rootParent = specificCard?.key ?? ROOT;
164
- const rootCards = [];
165
- const childCards = [];
166
- for (const card of createdCards) {
167
- if (card.parent === rootParent) {
168
- rootCards.push(card);
169
- }
170
- else {
171
- childCards.push(card);
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
+ }
172
259
  }
260
+ return [
261
+ ...sortItems(rootCards, (item) => item.metadata?.rank || EMPTY_RANK),
262
+ ...childCards,
263
+ ];
173
264
  }
174
- return [
175
- ...sortItems(rootCards, (item) => item.metadata?.rank || EMPTY_RANK),
176
- ...childCards,
177
- ];
265
+ return [];
178
266
  }
179
- return [];
180
- }
181
- /**
182
- * Creates a card type.
183
- * @param cardTypeName name for the card type.
184
- * @param workflowName workflow name to use in the card type.
185
- */
186
- async createCardType(cardTypeName, workflowName) {
187
- return this.project.resources
188
- .byType(cardTypeName, 'cardTypes')
189
- .createCardType(workflowName);
190
- }
191
- /**
192
- * Creates a new field type.
193
- * @param fieldTypeName name for the field type.
194
- * @param dataType data type for the field type
195
- */
196
- async createFieldType(fieldTypeName, dataType) {
197
- return this.project.resources
198
- .byType(fieldTypeName, 'fieldTypes')
199
- .createFieldType(dataType);
200
- }
201
- /**
202
- * Creates a new graph model.
203
- * @param graphModelName name for the graph model.
204
- */
205
- async createGraphModel(graphModelName) {
206
- return this.project.resources
207
- .byType(graphModelName, 'graphModels')
208
- .create();
209
- }
210
- /**
211
- * Creates a new graph view.
212
- * @param graphViewName name for the graph view.
213
- */
214
- async createGraphView(graphViewName) {
215
- return this.project.resources.byType(graphViewName, 'graphViews').create();
216
- }
217
- /**
218
- * Creates a label in the given card
219
- * @param cardKey The card to which the label is added to
220
- * @param label The label being added
221
- */
222
- async createLabel(cardKey, label) {
223
- if (!Validate.isValidLabelName(label)) {
224
- throw new Error(`Not a valid label name'`);
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);
225
276
  }
226
- const card = this.project.findCard(cardKey);
227
- const labels = structuredClone(card.metadata?.labels) ?? [];
228
- if (labels.includes(label)) {
229
- throw new Error('Label already exists');
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);
230
286
  }
231
- labels.push(label);
232
- return this.project.updateCardMetadataKey(cardKey, 'labels', labels);
233
- }
234
- /**
235
- * Creates a new link type.
236
- * @param linkTypeName name for the link type.
237
- */
238
- async createLinkType(linkTypeName) {
239
- return this.project.resources.byType(linkTypeName, 'linkTypes').create();
240
- }
241
- /**
242
- * Creates a link between two cards.
243
- * @param cardKey The card to update
244
- * @param destinationCardKey The card to link to
245
- * @param linkType The type of link to add
246
- * @param linkDescription Optional description of the link
247
- */
248
- async createLink(cardKey, destinationCardKey, linkType, linkDescription) {
249
- if (cardKey === destinationCardKey) {
250
- throw new Error('Cannot link card to itself');
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();
251
295
  }
252
- // Determine the card path
253
- const card = this.project.findCard(cardKey);
254
- const destinationCard = this.project.findCard(destinationCardKey);
255
- // make sure the link type exists
256
- const linkTypeObject = this.project.resources
257
- .byType(linkType, 'linkTypes')
258
- .show();
259
- // make sure that if linkDescription is not enabled, linkDescription is not provided
260
- if (!linkTypeObject.enableLinkDescription &&
261
- linkDescription !== undefined) {
262
- throw new Error(`Link type '${linkType}' does not allow link description`);
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();
263
302
  }
264
- // make sure source card key exists in the link type sourceCardTypes
265
- // if sourceCardTypes is empty, any card can be linked
266
- if (linkTypeObject.sourceCardTypes.length > 0 &&
267
- !linkTypeObject.sourceCardTypes.includes(card.metadata.cardType)) {
268
- throw new Error(`Card type '${card.metadata?.cardType}' cannot be linked with link type '${linkType}'`);
269
- }
270
- // make sure destination card key exists in the link type destinationCardTypes
271
- // if destinationCardTypes is empty, any card can be linked
272
- if (linkTypeObject.destinationCardTypes.length > 0 &&
273
- !linkTypeObject.destinationCardTypes.includes(destinationCard.metadata.cardType)) {
274
- throw new Error(`Card type '${destinationCard.metadata.cardType}' cannot be linked with link type '${linkType}'`);
275
- }
276
- // if contains the same link, do not add it again
277
- const existingLink = card.metadata?.links.find((l) => l.linkType === linkType &&
278
- l.cardKey === destinationCardKey &&
279
- l.linkDescription === linkDescription);
280
- if (existingLink) {
281
- throw new Error(`Link from card '${cardKey}' to card '${destinationCardKey}' already exists`);
282
- }
283
- const links = card.metadata?.links || [];
284
- links.push({
285
- linkType,
286
- cardKey: destinationCardKey,
287
- linkDescription,
288
- });
289
- await this.project.updateCardMetadataKey(cardKey, 'links', links);
290
- }
291
- /**
292
- * Creates a new project.
293
- * @param projectPath where to create the project.
294
- * @param projectPrefix prefix for the project.
295
- * @param projectName name for the project.
296
- * @param projectCategory category for the project (empty string if not provided).
297
- * @param projectDescription description for the project (empty string if not provided).
298
- */
299
- static async createProject(projectPath, projectPrefix, projectName, projectCategory, projectDescription) {
300
- projectPath = resolve(projectPath);
301
- if (!projectPath) {
302
- throw new Error('Cannot create project without a path');
303
- }
304
- const projectFolders = ['.cards/local', 'cardRoot'];
305
- if (!Validate.validateFolder(projectPath)) {
306
- throw new Error(`Input validation error: folder name '${projectPath}' is invalid`);
307
- }
308
- if (projectPrefix === undefined ||
309
- projectPrefix.length < 3 ||
310
- projectPrefix.length > 10) {
311
- throw new Error(`Input validation error: prefix must be from 3 to 10 characters long. '${projectPrefix}' does not fulfill the condition.`);
312
- }
313
- if (!Validate.isValidProjectName(projectName)) {
314
- throw new Error(`Input validation error: invalid project name '${projectName}'`);
315
- }
316
- if (!Validate.validatePrefix(projectPrefix)) {
317
- 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);
318
319
  }
319
- if (Project.isCreated(projectPath)) {
320
- 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();
321
326
  }
322
- if (!Validate.isValidProjectName(projectName)) {
323
- 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);
324
376
  }
325
- await mkdir(projectPath, { recursive: true }).then(async () => {
326
- return await Promise.all(projectFolders.map((folder) => mkdir(`${projectPath}/${folder}`, { recursive: true })));
327
- });
328
- await Promise.all(Create.JSONFileContent.map(async (entry) => {
329
- if ('cardKeyPrefix' in entry.content) {
330
- if (entry.content.cardKeyPrefix.includes('$PROJECT-PREFIX')) {
331
- entry.content.cardKeyPrefix = projectPrefix.toLowerCase();
332
- }
333
- if (entry.content.name.includes('$PROJECT-NAME')) {
334
- entry.content.name = projectName;
335
- }
336
- if (projectCategory) {
337
- entry.content.category = projectCategory;
338
- }
339
- if (projectDescription) {
340
- 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
+ }
341
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');
342
437
  }
343
- await writeJsonFile(join(projectPath, entry.path, entry.name), entry.content);
344
- }));
345
- try {
346
- await writeFile(join(projectPath, '.gitignore'), this.gitIgnoreContent.join('\n') + '\n');
347
438
  }
348
- catch {
349
- 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();
350
445
  }
351
- }
352
- /**
353
- * Creates a report
354
- * @param name name of the report
355
- */
356
- async createReport(name) {
357
- return this.project.resources.byType(name, 'reports').createReport();
358
- }
359
- /**
360
- * Creates a new template to a project.
361
- * @param templateName Name of the template.
362
- * @param templateContent JSON content for the template file.
363
- */
364
- async createTemplate(templateName, templateContent) {
365
- return this.project.resources
366
- .byType(templateName, 'templates')
367
- .create(templateContent ? JSON.parse(templateContent) : undefined);
368
- }
369
- /**
370
- * Creates a workflow.
371
- * @param workflowName workflow name
372
- * @param workflowContent workflow content JSON
373
- */
374
- async createWorkflow(workflowName, workflowContent) {
375
- return this.project.resources
376
- .byType(workflowName, 'workflows')
377
- .create(workflowContent ? JSON.parse(workflowContent) : undefined);
378
- }
379
- }
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 };
380
469
  //# sourceMappingURL=create.js.map