@cyberismo/backend 0.0.14 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/dist/app.d.ts +21 -0
  2. package/dist/app.js +9 -3
  3. package/dist/app.js.map +1 -1
  4. package/dist/common/validationSchemas.d.ts +48 -0
  5. package/dist/domain/calculations/index.d.ts +15 -0
  6. package/dist/domain/calculations/index.js +1 -53
  7. package/dist/domain/calculations/index.js.map +1 -1
  8. package/dist/domain/calculations/schema.d.ts +16 -0
  9. package/dist/domain/calculations/schema.js +0 -7
  10. package/dist/domain/calculations/schema.js.map +1 -1
  11. package/dist/domain/calculations/service.d.ts +14 -0
  12. package/dist/domain/calculations/service.js +0 -5
  13. package/dist/domain/calculations/service.js.map +1 -1
  14. package/dist/domain/cardTypes/index.d.ts +15 -0
  15. package/dist/domain/cardTypes/schema.d.ts +17 -0
  16. package/dist/domain/cardTypes/service.d.ts +15 -0
  17. package/dist/domain/cards/index.d.ts +15 -0
  18. package/dist/domain/cards/index.js +24 -8
  19. package/dist/domain/cards/index.js.map +1 -1
  20. package/dist/domain/cards/lib.d.ts +29 -0
  21. package/dist/domain/cards/lib.js +74 -13
  22. package/dist/domain/cards/lib.js.map +1 -1
  23. package/dist/domain/cards/service.d.ts +61 -0
  24. package/dist/domain/cards/service.js +22 -18
  25. package/dist/domain/cards/service.js.map +1 -1
  26. package/dist/domain/fieldTypes/index.d.ts +15 -0
  27. package/dist/domain/fieldTypes/schema.d.ts +28 -0
  28. package/dist/domain/fieldTypes/service.d.ts +16 -0
  29. package/dist/domain/graphModels/index.d.ts +15 -0
  30. package/dist/domain/graphModels/schema.d.ts +16 -0
  31. package/dist/domain/graphModels/service.d.ts +14 -0
  32. package/dist/domain/graphViews/index.d.ts +15 -0
  33. package/dist/domain/graphViews/schema.d.ts +4 -0
  34. package/dist/domain/graphViews/service.d.ts +14 -0
  35. package/dist/domain/labels/index.d.ts +15 -0
  36. package/dist/domain/labels/index.js +33 -0
  37. package/dist/domain/labels/index.js.map +1 -0
  38. package/dist/domain/labels/service.d.ts +19 -0
  39. package/dist/domain/labels/service.js +21 -0
  40. package/dist/domain/labels/service.js.map +1 -0
  41. package/dist/domain/linkTypes/index.d.ts +15 -0
  42. package/dist/domain/linkTypes/schema.d.ts +16 -0
  43. package/dist/domain/linkTypes/service.d.ts +15 -0
  44. package/dist/domain/logicPrograms/index.d.ts +15 -0
  45. package/dist/domain/logicPrograms/service.d.ts +15 -0
  46. package/dist/domain/reports/index.d.ts +15 -0
  47. package/dist/domain/reports/schema.d.ts +16 -0
  48. package/dist/domain/reports/service.d.ts +14 -0
  49. package/dist/domain/resources/index.d.ts +15 -0
  50. package/dist/domain/resources/index.js +2 -20
  51. package/dist/domain/resources/index.js.map +1 -1
  52. package/dist/domain/resources/schema.d.ts +60 -0
  53. package/dist/domain/resources/schema.js +12 -1
  54. package/dist/domain/resources/schema.js.map +1 -1
  55. package/dist/domain/resources/service.d.ts +36 -0
  56. package/dist/domain/resources/service.js +14 -34
  57. package/dist/domain/resources/service.js.map +1 -1
  58. package/dist/domain/templates/index.d.ts +15 -0
  59. package/dist/domain/templates/index.js +1 -1
  60. package/dist/domain/templates/index.js.map +1 -1
  61. package/dist/domain/templates/schema.d.ts +22 -0
  62. package/dist/domain/templates/service.d.ts +16 -0
  63. package/dist/domain/tree/index.d.ts +15 -0
  64. package/dist/domain/tree/index.js +3 -2
  65. package/dist/domain/tree/index.js.map +1 -1
  66. package/dist/domain/tree/service.d.ts +22 -0
  67. package/dist/domain/tree/service.js +10 -2
  68. package/dist/domain/tree/service.js.map +1 -1
  69. package/dist/domain/workflows/index.d.ts +15 -0
  70. package/dist/domain/workflows/schema.d.ts +16 -0
  71. package/dist/domain/workflows/service.d.ts +14 -0
  72. package/dist/export.d.ts +42 -0
  73. package/dist/export.js +48 -152
  74. package/dist/export.js.map +1 -1
  75. package/dist/index.d.ts +13 -0
  76. package/dist/index.js +3 -4
  77. package/dist/index.js.map +1 -1
  78. package/dist/main.d.ts +1 -0
  79. package/dist/middleware/commandManager.d.ts +20 -0
  80. package/dist/middleware/tree.d.ts +9 -0
  81. package/dist/middleware/tree.js +13 -0
  82. package/dist/middleware/tree.js.map +1 -0
  83. package/dist/middleware/zvalidator.d.ts +9 -0
  84. package/dist/public/THIRD-PARTY.txt +164 -164
  85. package/dist/public/assets/{index-OjHhVGiV.js → index-D410yunq.js} +89249 -81256
  86. package/dist/public/assets/index-DnK7MBer.css +1 -0
  87. package/dist/public/index.html +2 -2
  88. package/dist/types.d.ts +29 -0
  89. package/dist/utils.d.ts +11 -0
  90. package/dist/utils.js +0 -32
  91. package/dist/utils.js.map +1 -1
  92. package/package.json +8 -8
  93. package/src/app.ts +11 -4
  94. package/src/domain/calculations/index.ts +1 -68
  95. package/src/domain/calculations/schema.ts +0 -9
  96. package/src/domain/calculations/service.ts +0 -11
  97. package/src/domain/cards/index.ts +33 -8
  98. package/src/domain/cards/lib.ts +95 -22
  99. package/src/domain/cards/service.ts +38 -37
  100. package/src/domain/labels/index.ts +36 -0
  101. package/src/domain/labels/service.ts +23 -0
  102. package/src/domain/resources/index.ts +3 -41
  103. package/src/domain/resources/schema.ts +13 -1
  104. package/src/domain/resources/service.ts +28 -67
  105. package/src/domain/templates/index.ts +1 -1
  106. package/src/domain/tree/index.ts +10 -3
  107. package/src/domain/tree/service.ts +15 -1
  108. package/src/export.ts +59 -192
  109. package/src/index.ts +7 -4
  110. package/src/middleware/tree.ts +17 -0
  111. package/src/types.ts +13 -0
  112. package/src/utils.ts +0 -39
  113. package/dist/public/assets/index-DA46eVkH.css +0 -1
@@ -12,12 +12,10 @@
12
12
  */
13
13
 
14
14
  import Processor from '@asciidoctor/core';
15
- import {
16
- CardLocation,
17
- type MetadataContent,
18
- } from '@cyberismo/data-handler/interfaces/project-interfaces';
15
+ import { type MetadataContent } from '@cyberismo/data-handler/interfaces/project-interfaces';
19
16
  import { type CommandManager, evaluateMacros } from '@cyberismo/data-handler';
20
- import { getCardDetails } from './lib.js';
17
+ import { allCards } from './lib.js';
18
+ import type { TreeOptions } from '../../types.js';
21
19
 
22
20
  export async function getProjectInfo(commands: CommandManager) {
23
21
  const projectResponse = await commands.showCmd.showProject();
@@ -94,8 +92,6 @@ export async function updateCard(
94
92
  if (errors.length > 0) {
95
93
  throw new Error(errors.join('\n'));
96
94
  }
97
-
98
- return await getCardDetails(commands, key);
99
95
  }
100
96
 
101
97
  export async function deleteCard(commands: CommandManager, key: string) {
@@ -213,42 +209,47 @@ export async function removeLink(
213
209
  return { message: 'Link removed successfully' };
214
210
  }
215
211
 
216
- export async function getAttachment(
212
+ export function getAttachment(
217
213
  commands: CommandManager,
218
214
  key: string,
219
215
  filename: string,
220
216
  ) {
221
- const attachmentResponse = await commands.showCmd.showAttachment(
222
- key,
223
- filename,
224
- );
225
-
226
- if (!attachmentResponse) {
227
- throw new Error(
228
- `No attachment found from card ${key} and filename ${filename}`,
229
- );
230
- }
231
-
232
- return attachmentResponse;
217
+ return commands.showCmd.showAttachment(key, filename);
233
218
  }
234
219
 
235
- export async function getAllCards(commands: CommandManager) {
236
- const fetchedCards = await commands.showCmd.showCards(
237
- CardLocation.projectOnly,
238
- );
239
- const projectCards = fetchedCards.find(
240
- (cardContainer) => cardContainer.type === 'project',
241
- );
242
- if (!projectCards) {
243
- throw new Error('Data handler did not return project cards');
244
- }
245
- return projectCards.cards;
220
+ /**
221
+ * Used for exporting cards, thus static mode is assumed
222
+ * @param commandsthe command manager used for the query
223
+ * @param options optional tree query options
224
+ * @returns all cards in a flattened array
225
+ */
226
+ export async function findAllCards(
227
+ commands: CommandManager,
228
+ options?: TreeOptions,
229
+ ): ReturnType<typeof allCards> {
230
+ return allCards(commands, options);
246
231
  }
247
-
248
- export async function getAllAttachments(commands: CommandManager) {
232
+ /**
233
+ * Gets all attachments that are required for rendering the wanted cards
234
+ * @param commands the command manager used for the query
235
+ * @param options optional tree query options
236
+ * @returns all attachments for cards returned by the tree query
237
+ */
238
+ export async function findRelevantAttachments(
239
+ commands: CommandManager,
240
+ options?: TreeOptions,
241
+ ) {
242
+ const cards = new Set<string>(
243
+ (await allCards(commands, options)).map((c) => c.key),
244
+ );
249
245
  const attachments = await commands.showCmd.showAttachments();
250
- return attachments.map((attachment) => ({
251
- key: attachment.card,
252
- attachment: attachment.fileName,
253
- }));
246
+ return attachments
247
+ .filter(
248
+ (attachment) =>
249
+ cards.has(attachment.card) && attachment.mimeType?.startsWith('image/'),
250
+ )
251
+ .map((attachment) => ({
252
+ key: attachment.card,
253
+ attachment: attachment.fileName,
254
+ }));
254
255
  }
@@ -0,0 +1,36 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2025
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU Affero General Public License version 3 as published by
6
+ the Free Software Foundation.
7
+ This program is distributed in the hope that it will be useful, but WITHOUT
8
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9
+ FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
10
+ details. You should have received a copy of the GNU Affero General Public
11
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
12
+ */
13
+
14
+ import { Hono } from 'hono';
15
+ import * as labelsService from './service.js';
16
+
17
+ const router = new Hono();
18
+
19
+ /**
20
+ * @swagger
21
+ * /api/labels:
22
+ * get:
23
+ * summary: Returns all unique labels defined in the project.
24
+ * responses:
25
+ * 200:
26
+ * description: List of label strings.
27
+ * 500:
28
+ * description: Internal server error
29
+ */
30
+ router.get('/', (c) => {
31
+ const commands = c.get('commands');
32
+ const labels = labelsService.getLabels(commands);
33
+ return c.json(labels);
34
+ });
35
+
36
+ export default router;
@@ -0,0 +1,23 @@
1
+ /**
2
+ Cyberismo
3
+ Copyright © Cyberismo Ltd and contributors 2025
4
+ This program is free software: you can redistribute it and/or modify it under
5
+ the terms of the GNU Affero General Public License version 3 as published by
6
+ the Free Software Foundation.
7
+ This program is distributed in the hope that it will be useful, but WITHOUT
8
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9
+ FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
10
+ details. You should have received a copy of the GNU Affero General Public
11
+ License along with this program. If not, see <https://www.gnu.org/licenses/>.
12
+ */
13
+
14
+ import type { CommandManager } from '@cyberismo/data-handler';
15
+
16
+ /**
17
+ * Returns all unique labels available in the project.
18
+ * @param commands command manager used for the query
19
+ * @returns a list of labels
20
+ */
21
+ export function getLabels(commands: CommandManager): string[] {
22
+ return commands.showCmd.showLabels().sort();
23
+ }
@@ -13,10 +13,7 @@
13
13
 
14
14
  import { Hono } from 'hono';
15
15
  import * as resourceService from './service.js';
16
- import type {
17
- ResourceFileContentResponse,
18
- ResourceValidationResponse,
19
- } from '../../types.js';
16
+ import type { ResourceValidationResponse } from '../../types.js';
20
17
  import { resourceParamsSchema } from '../../common/validationSchemas.js';
21
18
  import { zValidator } from '../../middleware/zvalidator.js';
22
19
  import {
@@ -118,41 +115,6 @@ router.get(
118
115
  },
119
116
  );
120
117
 
121
- router.get('/:module/:type/:resource/:file', async (c) => {
122
- const commands = c.get('commands');
123
- const { module, type, resource, file } = c.req.param();
124
- const content = await resourceService.getFileContent(
125
- commands,
126
- module,
127
- type,
128
- resource,
129
- file,
130
- );
131
- const response: ResourceFileContentResponse = { content };
132
- return c.json(response);
133
- });
134
-
135
- router.put('/:module/:type/:resource/:file', async (c) => {
136
- const commands = c.get('commands');
137
- const { module, type, resource, file } = c.req.param();
138
- const changedContent = await c.req.json();
139
- if (
140
- changedContent.content === undefined ||
141
- typeof changedContent.content !== 'string'
142
- ) {
143
- return c.json({ error: 'Content is required' }, 400);
144
- }
145
- await resourceService.updateFile(
146
- commands,
147
- module,
148
- type,
149
- resource,
150
- file,
151
- changedContent.content,
152
- );
153
- return c.json({ content: changedContent.content });
154
- });
155
-
156
118
  router.delete(
157
119
  '/:prefix/:type/:identifier',
158
120
  zValidator('param', resourceParamsSchema),
@@ -173,12 +135,12 @@ router.post(
173
135
  async (c) => {
174
136
  const commands = c.get('commands');
175
137
  const resourceParams = c.req.valid('param');
176
- const { key, operation } = c.req.valid('json');
138
+ const { updateKey, operation } = c.req.valid('json');
177
139
 
178
140
  await resourceService.updateResourceWithOperation(
179
141
  commands,
180
142
  resourceParams,
181
- { key, operation },
143
+ { updateKey, operation },
182
144
  );
183
145
  return c.json({ message: 'Updated' });
184
146
  },
@@ -18,9 +18,21 @@ export type ValidateResourceParams = z.infer<
18
18
  typeof validateResourceParamsSchema
19
19
  >;
20
20
 
21
+ const updateKey = z.union([
22
+ z.object({
23
+ key: z.literal('content'),
24
+ subKey: z.string(),
25
+ }),
26
+ z.object({
27
+ key: z.string().refine((k) => k !== 'content', {
28
+ message: 'key cannot be "content" here',
29
+ }),
30
+ }),
31
+ ]);
32
+
21
33
  // Body schema for update operation-based resource update
22
34
  export const updateOperationBodySchema = z.object({
23
- key: z.string(),
35
+ updateKey,
24
36
  operation: z.discriminatedUnion('name', [
25
37
  z.object({
26
38
  name: z.literal('add'),
@@ -11,9 +11,10 @@
11
11
  License along with this program. If not, see <https://www.gnu.org/licenses/>.
12
12
  */
13
13
 
14
- import type { ResourceContent } from '@cyberismo/data-handler/interfaces/resource-interfaces';
14
+ import type { AnyResourceContent } from '@cyberismo/data-handler/interfaces/resource-interfaces';
15
15
  import type {
16
16
  Card,
17
+ CardWithChildrenCards,
17
18
  ResourceFolderType,
18
19
  RemovableResourceTypes,
19
20
  } from '@cyberismo/data-handler/interfaces/project-interfaces';
@@ -137,7 +138,7 @@ async function createResourceNode(
137
138
  id: string;
138
139
  type: ResourceFolderType;
139
140
  name: string;
140
- data: ResourceContent | undefined;
141
+ data: AnyResourceContent | undefined;
141
142
  children?: unknown[];
142
143
  readOnly?: boolean;
143
144
  }> {
@@ -146,7 +147,7 @@ async function createResourceNode(
146
147
  id: string;
147
148
  type: ResourceFolderType;
148
149
  name: string;
149
- data: ResourceContent | undefined;
150
+ data: AnyResourceContent | undefined;
150
151
  children?: unknown[];
151
152
  readOnly?: boolean;
152
153
  } = {
@@ -158,18 +159,26 @@ async function createResourceNode(
158
159
  };
159
160
 
160
161
  // Add file children for folder resources
161
- if (isResourceFolderType(resourceType) && resourceType !== 'templates') {
162
+ if (
163
+ isResourceFolderType(resourceType) &&
164
+ resourceType !== 'templates' &&
165
+ 'content' in resourceData!
166
+ ) {
162
167
  try {
163
- const fileNames = await commands.showCmd.showFileNames(
164
- resourceName(name),
168
+ const fileNodes = Object.entries(resourceData.content).map(
169
+ ([fileName, content]) => ({
170
+ id: `${resourceType}-${name}-${fileName}`,
171
+ type: 'file',
172
+ name: `${name}/${fileName}`,
173
+ resourceName: name,
174
+ fileName,
175
+ displayName: fileName,
176
+ data: {
177
+ content,
178
+ },
179
+ readOnly: resourceName(name).prefix !== projectPrefix,
180
+ }),
165
181
  );
166
- const fileNodes = fileNames.map((fileName: string) => ({
167
- id: `${resourceType}-${name}-${fileName}`,
168
- type: 'file',
169
- name: `${name}/${fileName}`,
170
- displayName: fileName,
171
- readOnly: resourceName(name).prefix !== projectPrefix,
172
- }));
173
182
 
174
183
  node.children = children ? [...children, ...fileNodes] : fileNodes;
175
184
  } catch (error) {
@@ -184,12 +193,12 @@ async function createResourceNode(
184
193
 
185
194
  // Helper function to recursively create card nodes with children
186
195
  function createCardNode(
187
- card: Card,
196
+ card: CardWithChildrenCards,
188
197
  module: string,
189
198
  projectPrefix: string,
190
199
  ): unknown {
191
200
  // Destructure to separate children from other card data
192
- const { children, ...cardData } = card;
201
+ const { childrenCards, ...cardData } = card;
193
202
 
194
203
  const cardNode: {
195
204
  id: string;
@@ -208,8 +217,8 @@ function createCardNode(
208
217
  };
209
218
 
210
219
  // Recursively process children if they exist
211
- if (children && children.length > 0) {
212
- cardNode.children = children.map((child) =>
220
+ if (childrenCards && childrenCards.length > 0) {
221
+ cardNode.children = childrenCards.map((child) =>
213
222
  createCardNode(child, module, projectPrefix),
214
223
  );
215
224
  }
@@ -368,54 +377,6 @@ export async function deleteResource(
368
377
  );
369
378
  }
370
379
 
371
- /**
372
- * Get the content of a file in a resource.
373
- * @param commands Command manager.
374
- * @param module Name of the module.
375
- * @param type Name of the type.
376
- * @param resource Name of the resource.
377
- * @param fileName Name of the file.
378
- * @returns The content of the file.
379
- */
380
- export async function getFileContent(
381
- commands: CommandManager,
382
- module: string,
383
- type: string,
384
- resource: string,
385
- fileName: string,
386
- ) {
387
- // TODO: Use resource APIs to fetch resource content; showFile will be removed
388
- return commands.showCmd.showFile(
389
- resourceName(`${module}/${type}/${resource}`),
390
- fileName,
391
- );
392
- }
393
-
394
- /**
395
- * Update a file of a folder resource. Cannot be used to create a new file.
396
- * @param commands Command manager.
397
- * @param module Name of the module.
398
- * @param type Name of the type.
399
- * @param resource Name of the resource.
400
- * @param fileName Name of the file.
401
- * @param changedContent The new content for the file.
402
- * @returns The updated file content.
403
- */
404
- export async function updateFile(
405
- commands: CommandManager,
406
- module: string,
407
- type: string,
408
- resource: string,
409
- fileName: string,
410
- changedContent: string,
411
- ) {
412
- return commands.editCmd.editResourceContent(
413
- resourceName(`${module}/${type}/${resource}`),
414
- fileName,
415
- changedContent,
416
- );
417
- }
418
-
419
380
  /**
420
381
  * Validate a single resource.
421
382
  * @param commands Command manager.
@@ -445,10 +406,10 @@ export async function updateResourceWithOperation(
445
406
  resource: ResourceParams,
446
407
  body: UpdateOperationBody,
447
408
  ) {
448
- const { key, operation } = body;
409
+ const { updateKey, operation } = body;
449
410
  await commands.updateCmd.applyResourceOperation(
450
411
  resourceNameToString(resource),
451
- key,
412
+ updateKey,
452
413
  operation,
453
414
  );
454
415
  }
@@ -12,10 +12,10 @@
12
12
  */
13
13
 
14
14
  import { Hono } from 'hono';
15
- import { isSSGContext } from '../../export.js';
16
15
  import * as templateService from './service.js';
17
16
  import { createTemplateSchema, addTemplateCardSchema } from './schema.js';
18
17
  import { zValidator } from '../../middleware/zvalidator.js';
18
+ import { isSSGContext } from 'hono/ssg';
19
19
 
20
20
  const router = new Hono();
21
21
 
@@ -13,7 +13,8 @@
13
13
 
14
14
  import { Hono } from 'hono';
15
15
  import * as treeService from './service.js';
16
- import { isSSGContext } from '../../export.js';
16
+ import { isSSGContext } from 'hono/ssg';
17
+ import type { AppContext } from '../../types.js';
17
18
 
18
19
  const router = new Hono();
19
20
 
@@ -31,11 +32,17 @@ const router = new Hono();
31
32
  * 500:
32
33
  * description: project_path not set or other internal error
33
34
  */
34
- router.get('/', async (c) => {
35
+ router.get('/', async (c: AppContext) => {
35
36
  const commands = c.get('commands');
37
+ const tree = c.get('tree');
36
38
 
37
39
  try {
38
- const response = await treeService.getCardTree(commands, isSSGContext(c));
40
+ const response = await treeService.getCardTree(
41
+ commands,
42
+ isSSGContext(c),
43
+ tree?.cardKey,
44
+ tree?.recursive,
45
+ );
39
46
  return c.json(response);
40
47
  } catch (error) {
41
48
  return c.json(
@@ -13,10 +13,24 @@
13
13
 
14
14
  import type { CommandManager } from '@cyberismo/data-handler';
15
15
 
16
- export async function getCardTree(commands: CommandManager, isSsg: boolean) {
16
+ /**
17
+ * Returns the card tree of the project
18
+ * @param commands command manager used for the query
19
+ * @param isSsg whether the context is static site generation
20
+ * @param cardKey optional card key to start the tree from
21
+ * @param recursive if false, includes only the given card. Otherwise, includes all child cards recursively.
22
+ * @returns
23
+ */
24
+ export async function getCardTree(
25
+ commands: CommandManager,
26
+ isSsg: boolean,
27
+ cardKey?: string,
28
+ recursive?: boolean,
29
+ ): ReturnType<typeof commands.calculateCmd.runQuery> {
17
30
  await commands.calculateCmd.generate();
18
31
  return commands.calculateCmd.runQuery(
19
32
  'tree',
20
33
  isSsg ? 'exportedSite' : 'localApp',
34
+ { cardKey, recursive },
21
35
  );
22
36
  }