@cyberismo/backend 0.0.12 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/domain/resources/index.js +8 -1
- package/dist/domain/resources/index.js.map +1 -1
- package/dist/domain/resources/schema.js +29 -0
- package/dist/domain/resources/schema.js.map +1 -1
- package/dist/domain/resources/service.js +9 -0
- package/dist/domain/resources/service.js.map +1 -1
- package/dist/public/THIRD-PARTY.txt +4 -4
- package/dist/public/assets/{index-BngW8o1w.css → index-DA46eVkH.css} +1 -1
- package/dist/public/assets/{index-D46PNX0J.js → index-OjHhVGiV.js} +40966 -40819
- package/dist/public/index.html +2 -2
- package/package.json +6 -4
- package/src/domain/resources/index.ts +22 -1
- package/src/domain/resources/schema.ts +32 -0
- package/src/domain/resources/service.ts +19 -1
package/dist/public/index.html
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
name="msapplication-TileImage"
|
|
12
12
|
content="/cropped-favicon-270x270.png"
|
|
13
13
|
/>
|
|
14
|
-
<script type="module" crossorigin src="/assets/index-
|
|
15
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
14
|
+
<script type="module" crossorigin src="/assets/index-OjHhVGiV.js"></script>
|
|
15
|
+
<link rel="stylesheet" crossorigin href="/assets/index-DA46eVkH.css">
|
|
16
16
|
</head>
|
|
17
17
|
<body>
|
|
18
18
|
<div id="root"></div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cyberismo/backend",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"description": "Express backend for Cyberismo",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"keywords": [],
|
|
@@ -8,12 +8,14 @@
|
|
|
8
8
|
"license": "AGPL-3.0",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@asciidoctor/core": "^3.0.4",
|
|
11
|
-
"@hono/node-server": "^1.19.
|
|
11
|
+
"@hono/node-server": "^1.19.2",
|
|
12
12
|
"@hono/zod-validator": "^0.7.2",
|
|
13
|
+
"@types/mime-types": "^3.0.1",
|
|
13
14
|
"dotenv": "^17.2.2",
|
|
14
15
|
"hono": "^4.9.7",
|
|
15
|
-
"
|
|
16
|
-
"
|
|
16
|
+
"mime-types": "^3.0.1",
|
|
17
|
+
"zod": "^4.1.8",
|
|
18
|
+
"@cyberismo/data-handler": "0.0.14"
|
|
17
19
|
},
|
|
18
20
|
"devDependencies": {
|
|
19
21
|
"@cyberismo/app": "0.0.2"
|
|
@@ -19,7 +19,10 @@ import type {
|
|
|
19
19
|
} from '../../types.js';
|
|
20
20
|
import { resourceParamsSchema } from '../../common/validationSchemas.js';
|
|
21
21
|
import { zValidator } from '../../middleware/zvalidator.js';
|
|
22
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
validateResourceParamsSchema,
|
|
24
|
+
updateOperationBodySchema,
|
|
25
|
+
} from './schema.js';
|
|
23
26
|
|
|
24
27
|
const router = new Hono();
|
|
25
28
|
|
|
@@ -163,4 +166,22 @@ router.delete(
|
|
|
163
166
|
},
|
|
164
167
|
);
|
|
165
168
|
|
|
169
|
+
router.post(
|
|
170
|
+
'/:prefix/:type/:identifier/operation',
|
|
171
|
+
zValidator('param', resourceParamsSchema),
|
|
172
|
+
zValidator('json', updateOperationBodySchema),
|
|
173
|
+
async (c) => {
|
|
174
|
+
const commands = c.get('commands');
|
|
175
|
+
const resourceParams = c.req.valid('param');
|
|
176
|
+
const { key, operation } = c.req.valid('json');
|
|
177
|
+
|
|
178
|
+
await resourceService.updateResourceWithOperation(
|
|
179
|
+
commands,
|
|
180
|
+
resourceParams,
|
|
181
|
+
{ key, operation },
|
|
182
|
+
);
|
|
183
|
+
return c.json({ message: 'Updated' });
|
|
184
|
+
},
|
|
185
|
+
);
|
|
186
|
+
|
|
166
187
|
export default router;
|
|
@@ -17,3 +17,35 @@ export const validateResourceParamsSchema = resourceParamsSchema.extend({
|
|
|
17
17
|
export type ValidateResourceParams = z.infer<
|
|
18
18
|
typeof validateResourceParamsSchema
|
|
19
19
|
>;
|
|
20
|
+
|
|
21
|
+
// Body schema for update operation-based resource update
|
|
22
|
+
export const updateOperationBodySchema = z.object({
|
|
23
|
+
key: z.string(),
|
|
24
|
+
operation: z.discriminatedUnion('name', [
|
|
25
|
+
z.object({
|
|
26
|
+
name: z.literal('add'),
|
|
27
|
+
target: z.unknown(),
|
|
28
|
+
}),
|
|
29
|
+
z.object({
|
|
30
|
+
name: z.literal('change'),
|
|
31
|
+
target: z.unknown(),
|
|
32
|
+
to: z.unknown(),
|
|
33
|
+
mappingTable: z
|
|
34
|
+
.object({
|
|
35
|
+
stateMapping: z.record(z.string(), z.string()),
|
|
36
|
+
})
|
|
37
|
+
.optional(),
|
|
38
|
+
}),
|
|
39
|
+
z.object({
|
|
40
|
+
name: z.literal('remove'),
|
|
41
|
+
target: z.unknown(),
|
|
42
|
+
}),
|
|
43
|
+
z.object({
|
|
44
|
+
name: z.literal('rank'),
|
|
45
|
+
target: z.unknown(),
|
|
46
|
+
newIndex: z.number(),
|
|
47
|
+
}),
|
|
48
|
+
]),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
export type UpdateOperationBody = z.infer<typeof updateOperationBodySchema>;
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
resourceNameToString,
|
|
26
26
|
} from '@cyberismo/data-handler';
|
|
27
27
|
import type { ResourceParams } from '../../common/validationSchemas.js';
|
|
28
|
-
import type { ValidateResourceParams } from './schema.js';
|
|
28
|
+
import type { ValidateResourceParams, UpdateOperationBody } from './schema.js';
|
|
29
29
|
|
|
30
30
|
const resourceTypes: ResourceFolderType[] = [
|
|
31
31
|
'calculations',
|
|
@@ -384,6 +384,7 @@ export async function getFileContent(
|
|
|
384
384
|
resource: string,
|
|
385
385
|
fileName: string,
|
|
386
386
|
) {
|
|
387
|
+
// TODO: Use resource APIs to fetch resource content; showFile will be removed
|
|
387
388
|
return commands.showCmd.showFile(
|
|
388
389
|
resourceName(`${module}/${type}/${resource}`),
|
|
389
390
|
fileName,
|
|
@@ -434,3 +435,20 @@ export async function validateResource(
|
|
|
434
435
|
errors: errors.split('\n\n').filter((error) => error !== ''),
|
|
435
436
|
};
|
|
436
437
|
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Perform an updateOperation on a resource key.
|
|
441
|
+
* This delegates to data-handler Update.applyResourceOperation.
|
|
442
|
+
*/
|
|
443
|
+
export async function updateResourceWithOperation(
|
|
444
|
+
commands: CommandManager,
|
|
445
|
+
resource: ResourceParams,
|
|
446
|
+
body: UpdateOperationBody,
|
|
447
|
+
) {
|
|
448
|
+
const { key, operation } = body;
|
|
449
|
+
await commands.updateCmd.applyResourceOperation(
|
|
450
|
+
resourceNameToString(resource),
|
|
451
|
+
key,
|
|
452
|
+
operation,
|
|
453
|
+
);
|
|
454
|
+
}
|