@adminforth/list-in-place-edit 1.0.27 → 1.1.0
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/index.js +14 -3
- package/index.ts +16 -5
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -7,7 +7,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { AdminForthPlugin, interpretResource, ActionCheckSource, AllowedActionsEnum } from "adminforth";
|
|
10
|
+
import { AdminForthPlugin, parseBody, interpretResource, ActionCheckSource, AllowedActionsEnum } from "adminforth";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
const updateFieldBodySchema = z.object({
|
|
13
|
+
resourceId: z.string(),
|
|
14
|
+
recordId: z.union([z.string(), z.number()]),
|
|
15
|
+
field: z.string(),
|
|
16
|
+
value: z.unknown(),
|
|
17
|
+
}).strict();
|
|
11
18
|
export default class ListInPlaceEditPlugin extends AdminForthPlugin {
|
|
12
19
|
constructor(options) {
|
|
13
20
|
super(options, import.meta.url);
|
|
@@ -54,8 +61,12 @@ export default class ListInPlaceEditPlugin extends AdminForthPlugin {
|
|
|
54
61
|
server.endpoint({
|
|
55
62
|
method: 'POST',
|
|
56
63
|
path: `/plugin/${this.pluginInstanceId}/update-field`,
|
|
57
|
-
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser }) {
|
|
58
|
-
const
|
|
64
|
+
handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, adminUser, response }) {
|
|
65
|
+
const parsed = parseBody(updateFieldBodySchema, body, response);
|
|
66
|
+
if ('error' in parsed)
|
|
67
|
+
return parsed.error;
|
|
68
|
+
const data = parsed.data;
|
|
69
|
+
const { resourceId, recordId, field, value } = data;
|
|
59
70
|
if (this.resourceConfig.resourceId !== resourceId) {
|
|
60
71
|
return { error: 'Resource ID mismatch' };
|
|
61
72
|
}
|
package/index.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import { AdminForthPlugin, interpretResource, ActionCheckSource, AllowedActionsEnum } from "adminforth";
|
|
1
|
+
import { AdminForthPlugin, parseBody, interpretResource, ActionCheckSource, AllowedActionsEnum } from "adminforth";
|
|
2
2
|
import type { IAdminForth, IHttpServer, AdminForthResourcePages, AdminForthResourceColumn, AdminForthDataTypes, AdminForthResource } from "adminforth";
|
|
3
3
|
import type { PluginOptions } from './types.js';
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
|
|
6
|
+
const updateFieldBodySchema = z.object({
|
|
7
|
+
resourceId: z.string(),
|
|
8
|
+
recordId: z.union([z.string(), z.number()]),
|
|
9
|
+
field: z.string(),
|
|
10
|
+
value: z.unknown(),
|
|
11
|
+
}).strict();
|
|
4
12
|
|
|
5
13
|
export default class ListInPlaceEditPlugin extends AdminForthPlugin {
|
|
6
14
|
options: PluginOptions;
|
|
@@ -53,8 +61,11 @@ export default class ListInPlaceEditPlugin extends AdminForthPlugin {
|
|
|
53
61
|
server.endpoint({
|
|
54
62
|
method: 'POST',
|
|
55
63
|
path: `/plugin/${this.pluginInstanceId}/update-field`,
|
|
56
|
-
handler: async ({ body, adminUser }) => {
|
|
57
|
-
const
|
|
64
|
+
handler: async ({ body, adminUser, response }) => {
|
|
65
|
+
const parsed = parseBody(updateFieldBodySchema, body, response);
|
|
66
|
+
if ('error' in parsed) return parsed.error;
|
|
67
|
+
const data = parsed.data;
|
|
68
|
+
const { resourceId, recordId, field, value } = data;
|
|
58
69
|
if (this.resourceConfig.resourceId !== resourceId) {
|
|
59
70
|
return { error: 'Resource ID mismatch' };
|
|
60
71
|
}
|
|
@@ -83,7 +94,7 @@ export default class ListInPlaceEditPlugin extends AdminForthPlugin {
|
|
|
83
94
|
|
|
84
95
|
// Use AdminForth's built-in update method
|
|
85
96
|
const connector = this.adminforth.connectors[resource.dataSource];
|
|
86
|
-
const oldRecord = await connector.getRecordByPrimaryKey(resource, recordId)
|
|
97
|
+
const oldRecord = await connector.getRecordByPrimaryKey(resource, recordId as string)
|
|
87
98
|
if (!oldRecord) {
|
|
88
99
|
return { error: 'Record not found' };
|
|
89
100
|
}
|
|
@@ -114,7 +125,7 @@ export default class ListInPlaceEditPlugin extends AdminForthPlugin {
|
|
|
114
125
|
return { error: result.error };
|
|
115
126
|
}
|
|
116
127
|
|
|
117
|
-
const updatedRecord = await connector.getRecordByPrimaryKey(resource, recordId);
|
|
128
|
+
const updatedRecord = await connector.getRecordByPrimaryKey(resource, recordId as string);
|
|
118
129
|
return { record: updatedRecord };
|
|
119
130
|
}
|
|
120
131
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adminforth/list-in-place-edit",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"description": "AdminForth List In Place Edit Plugin",
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/node": "^22.10.7",
|
|
22
|
-
"adminforth": "^3.
|
|
22
|
+
"adminforth": "^3.7.1",
|
|
23
23
|
"semantic-release": "^24.2.1",
|
|
24
24
|
"semantic-release-slack-bot": "^4.0.2",
|
|
25
25
|
"typescript": "^5.7.3"
|
|
@@ -29,10 +29,11 @@
|
|
|
29
29
|
"url": "https://github.com/devforth/adminforth-list-in-place-edit"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"vue-i18n": "^11.1.3"
|
|
32
|
+
"vue-i18n": "^11.1.3",
|
|
33
|
+
"zod": "^4.3.6"
|
|
33
34
|
},
|
|
34
35
|
"peerDependencies": {
|
|
35
|
-
"adminforth": "^3.
|
|
36
|
+
"adminforth": "^3.7.1"
|
|
36
37
|
},
|
|
37
38
|
"release": {
|
|
38
39
|
"plugins": [
|