@ai0x0/utils 0.0.11 → 0.0.12
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/es/backend/route-operation/delete-operation.d.ts +3 -1
- package/es/backend/route-operation/delete-operation.js +31 -15
- package/es/backend/route-operation/get-list-operation.d.ts +4 -2
- package/es/backend/route-operation/get-list-operation.js +35 -19
- package/es/backend/route-operation/get-operation.d.ts +4 -2
- package/es/backend/route-operation/get-operation.js +37 -21
- package/es/backend/route-operation/post-operation.d.ts +2 -2
- package/es/backend/route-operation/put-operation.d.ts +4 -2
- package/es/backend/route-operation/put-operation.js +39 -23
- package/lib/backend/route-operation/delete-operation.d.ts +3 -1
- package/lib/backend/route-operation/delete-operation.js +19 -9
- package/lib/backend/route-operation/get-list-operation.d.ts +4 -2
- package/lib/backend/route-operation/get-list-operation.js +30 -20
- package/lib/backend/route-operation/get-operation.d.ts +4 -2
- package/lib/backend/route-operation/get-operation.js +30 -20
- package/lib/backend/route-operation/post-operation.d.ts +2 -2
- package/lib/backend/route-operation/put-operation.d.ts +4 -2
- package/lib/backend/route-operation/put-operation.js +30 -20
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TypedNextResponse } from "next-rest-framework";
|
|
1
2
|
import { BaseTable } from "../types";
|
|
2
3
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
3
4
|
import { NextRequest } from "next/server";
|
|
@@ -5,6 +6,7 @@ export interface DeleteOperationOptions<TTable extends BaseTable> {
|
|
|
5
6
|
table: TTable;
|
|
6
7
|
summary?: string;
|
|
7
8
|
onSuccess?: () => Promise<void>;
|
|
9
|
+
onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
8
10
|
byCreator?: boolean;
|
|
9
11
|
}
|
|
10
12
|
export declare const createDeleteOperation: ({ db, getSession, }: {
|
|
@@ -12,4 +14,4 @@ export declare const createDeleteOperation: ({ db, getSession, }: {
|
|
|
12
14
|
getSession: (req: NextRequest) => Promise<{
|
|
13
15
|
userId?: string;
|
|
14
16
|
} | undefined>;
|
|
15
|
-
}) => <TTable extends BaseTable>({ table, summary, onSuccess, byCreator, }: DeleteOperationOptions<TTable>) => any;
|
|
17
|
+
}) => <TTable extends BaseTable>({ table, summary, onSuccess, onError, byCreator, }: DeleteOperationOptions<TTable>) => any;
|
|
@@ -13,6 +13,7 @@ export var createDeleteOperation = function createDeleteOperation(_ref) {
|
|
|
13
13
|
var table = _ref2.table,
|
|
14
14
|
summary = _ref2.summary,
|
|
15
15
|
onSuccess = _ref2.onSuccess,
|
|
16
|
+
onError = _ref2.onError,
|
|
16
17
|
_ref2$byCreator = _ref2.byCreator,
|
|
17
18
|
byCreator = _ref2$byCreator === void 0 ? true : _ref2$byCreator;
|
|
18
19
|
return routeOperation({
|
|
@@ -28,50 +29,65 @@ export var createDeleteOperation = function createDeleteOperation(_ref) {
|
|
|
28
29
|
contentType: "application/json"
|
|
29
30
|
}).handler( /*#__PURE__*/function () {
|
|
30
31
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
|
|
31
|
-
var body, _ref4, userId, data;
|
|
32
|
+
var body, _ref4, userId, data, response;
|
|
32
33
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
33
34
|
while (1) switch (_context.prev = _context.next) {
|
|
34
35
|
case 0:
|
|
35
|
-
_context.
|
|
36
|
+
_context.prev = 0;
|
|
37
|
+
_context.next = 3;
|
|
36
38
|
return req.json();
|
|
37
|
-
case
|
|
39
|
+
case 3:
|
|
38
40
|
body = _context.sent;
|
|
39
41
|
if (!byCreator) {
|
|
40
|
-
_context.next =
|
|
42
|
+
_context.next = 13;
|
|
41
43
|
break;
|
|
42
44
|
}
|
|
43
|
-
_context.next =
|
|
45
|
+
_context.next = 7;
|
|
44
46
|
return getSession(req);
|
|
45
|
-
case
|
|
47
|
+
case 7:
|
|
46
48
|
_context.t0 = _context.sent;
|
|
47
49
|
if (_context.t0) {
|
|
48
|
-
_context.next =
|
|
50
|
+
_context.next = 10;
|
|
49
51
|
break;
|
|
50
52
|
}
|
|
51
53
|
_context.t0 = {};
|
|
52
|
-
case
|
|
54
|
+
case 10:
|
|
53
55
|
_ref4 = _context.t0;
|
|
54
56
|
userId = _ref4.userId;
|
|
55
57
|
body.creatorId = userId;
|
|
56
|
-
case
|
|
57
|
-
_context.next =
|
|
58
|
+
case 13:
|
|
59
|
+
_context.next = 15;
|
|
58
60
|
return createDeleteAction({
|
|
59
61
|
table: table,
|
|
60
62
|
db: db
|
|
61
63
|
})(body);
|
|
62
|
-
case
|
|
64
|
+
case 15:
|
|
63
65
|
data = _context.sent;
|
|
64
|
-
_context.next =
|
|
66
|
+
_context.next = 18;
|
|
65
67
|
return onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess();
|
|
66
|
-
case
|
|
68
|
+
case 18:
|
|
67
69
|
return _context.abrupt("return", TypedNextResponse.json(data, {
|
|
68
70
|
status: 200
|
|
69
71
|
}));
|
|
70
|
-
case
|
|
72
|
+
case 21:
|
|
73
|
+
_context.prev = 21;
|
|
74
|
+
_context.t1 = _context["catch"](0);
|
|
75
|
+
_context.next = 25;
|
|
76
|
+
return onError === null || onError === void 0 ? void 0 : onError(_context.t1);
|
|
77
|
+
case 25:
|
|
78
|
+
response = _context.sent;
|
|
79
|
+
if (!response) {
|
|
80
|
+
_context.next = 30;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
return _context.abrupt("return", response);
|
|
84
|
+
case 30:
|
|
85
|
+
throw _context.t1;
|
|
86
|
+
case 31:
|
|
71
87
|
case "end":
|
|
72
88
|
return _context.stop();
|
|
73
89
|
}
|
|
74
|
-
}, _callee);
|
|
90
|
+
}, _callee, null, [[0, 21]]);
|
|
75
91
|
}));
|
|
76
92
|
return function (_x) {
|
|
77
93
|
return _ref3.apply(this, arguments);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z, ZodSchema } from "zod";
|
|
2
2
|
import { NextRequest } from "next/server";
|
|
3
|
+
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
3
4
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
4
5
|
import { BaseTable, GetListRelations } from "../types";
|
|
5
6
|
export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> {
|
|
@@ -7,7 +8,7 @@ export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchem
|
|
|
7
8
|
jsonArrayFields?: string[];
|
|
8
9
|
querySchema: Q;
|
|
9
10
|
relations?: GetListRelations;
|
|
10
|
-
setParams?: (req:
|
|
11
|
+
setParams?: (req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string, unknown>>;
|
|
11
12
|
byCreator?: boolean;
|
|
12
13
|
summary?: string;
|
|
13
14
|
table: TTable;
|
|
@@ -18,10 +19,11 @@ export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchem
|
|
|
18
19
|
data: z.infer<T>[];
|
|
19
20
|
total: number;
|
|
20
21
|
}>;
|
|
22
|
+
onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
21
23
|
}
|
|
22
24
|
export declare const createGetListOperation: ({ db, getSession, }: {
|
|
23
25
|
db: NodePgDatabase<any>;
|
|
24
26
|
getSession: (req: NextRequest) => Promise<{
|
|
25
27
|
userId?: string;
|
|
26
28
|
} | undefined>;
|
|
27
|
-
}) => <T extends z.ZodType<any, z.ZodTypeDef, any>, Q extends z.ZodType<any, z.ZodTypeDef, any>, TTable extends BaseTable>({ querySchema, bodySchema, table, summary, relations, jsonArrayFields, setParams, onSuccess, byCreator, }: GetListOperationOptions<T, Q, TTable>) => any;
|
|
29
|
+
}) => <T extends z.ZodType<any, z.ZodTypeDef, any>, Q extends z.ZodType<any, z.ZodTypeDef, any>, TTable extends BaseTable>({ querySchema, bodySchema, table, summary, relations, jsonArrayFields, setParams, onSuccess, onError, byCreator, }: GetListOperationOptions<T, Q, TTable>) => any;
|
|
@@ -18,6 +18,7 @@ export var createGetListOperation = function createGetListOperation(_ref) {
|
|
|
18
18
|
jsonArrayFields = _ref2.jsonArrayFields,
|
|
19
19
|
setParams = _ref2.setParams,
|
|
20
20
|
onSuccess = _ref2.onSuccess,
|
|
21
|
+
onError = _ref2.onError,
|
|
21
22
|
_ref2$byCreator = _ref2.byCreator,
|
|
22
23
|
byCreator = _ref2$byCreator === void 0 ? true : _ref2$byCreator;
|
|
23
24
|
return routeOperation({
|
|
@@ -34,40 +35,41 @@ export var createGetListOperation = function createGetListOperation(_ref) {
|
|
|
34
35
|
status: 200
|
|
35
36
|
}]).handler( /*#__PURE__*/function () {
|
|
36
37
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
|
|
37
|
-
var params, _ref4, userId, result;
|
|
38
|
+
var params, _ref4, userId, result, response;
|
|
38
39
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
39
40
|
while (1) switch (_context.prev = _context.next) {
|
|
40
41
|
case 0:
|
|
41
|
-
_context.
|
|
42
|
+
_context.prev = 0;
|
|
43
|
+
_context.next = 3;
|
|
42
44
|
return setParams === null || setParams === void 0 ? void 0 : setParams(req);
|
|
43
|
-
case
|
|
45
|
+
case 3:
|
|
44
46
|
_context.t0 = _context.sent;
|
|
45
47
|
if (_context.t0) {
|
|
46
|
-
_context.next =
|
|
48
|
+
_context.next = 6;
|
|
47
49
|
break;
|
|
48
50
|
}
|
|
49
51
|
_context.t0 = {};
|
|
50
|
-
case
|
|
52
|
+
case 6:
|
|
51
53
|
params = _context.t0;
|
|
52
54
|
if (!byCreator) {
|
|
53
|
-
_context.next =
|
|
55
|
+
_context.next = 16;
|
|
54
56
|
break;
|
|
55
57
|
}
|
|
56
|
-
_context.next =
|
|
58
|
+
_context.next = 10;
|
|
57
59
|
return getSession(req);
|
|
58
|
-
case
|
|
60
|
+
case 10:
|
|
59
61
|
_context.t1 = _context.sent;
|
|
60
62
|
if (_context.t1) {
|
|
61
|
-
_context.next =
|
|
63
|
+
_context.next = 13;
|
|
62
64
|
break;
|
|
63
65
|
}
|
|
64
66
|
_context.t1 = {};
|
|
65
|
-
case
|
|
67
|
+
case 13:
|
|
66
68
|
_ref4 = _context.t1;
|
|
67
69
|
userId = _ref4.userId;
|
|
68
70
|
params.creatorId = userId;
|
|
69
|
-
case
|
|
70
|
-
_context.next =
|
|
71
|
+
case 16:
|
|
72
|
+
_context.next = 18;
|
|
71
73
|
return createGetListAction({
|
|
72
74
|
bodySchema: bodySchema,
|
|
73
75
|
db: db,
|
|
@@ -75,25 +77,39 @@ export var createGetListOperation = function createGetListOperation(_ref) {
|
|
|
75
77
|
relations: relations,
|
|
76
78
|
table: table
|
|
77
79
|
})(Object.assign(Object.fromEntries(new URL(req.url).searchParams), params));
|
|
78
|
-
case
|
|
80
|
+
case 18:
|
|
79
81
|
result = _context.sent;
|
|
80
82
|
if (!onSuccess) {
|
|
81
|
-
_context.next =
|
|
83
|
+
_context.next = 23;
|
|
82
84
|
break;
|
|
83
85
|
}
|
|
84
|
-
_context.next =
|
|
86
|
+
_context.next = 22;
|
|
85
87
|
return onSuccess(result);
|
|
86
|
-
case 21:
|
|
87
|
-
result = _context.sent;
|
|
88
88
|
case 22:
|
|
89
|
+
result = _context.sent;
|
|
90
|
+
case 23:
|
|
89
91
|
return _context.abrupt("return", TypedNextResponse.json(result, {
|
|
90
92
|
status: 200
|
|
91
93
|
}));
|
|
92
|
-
case
|
|
94
|
+
case 26:
|
|
95
|
+
_context.prev = 26;
|
|
96
|
+
_context.t2 = _context["catch"](0);
|
|
97
|
+
_context.next = 30;
|
|
98
|
+
return onError === null || onError === void 0 ? void 0 : onError(_context.t2);
|
|
99
|
+
case 30:
|
|
100
|
+
response = _context.sent;
|
|
101
|
+
if (!response) {
|
|
102
|
+
_context.next = 35;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
return _context.abrupt("return", response);
|
|
106
|
+
case 35:
|
|
107
|
+
throw _context.t2;
|
|
108
|
+
case 36:
|
|
93
109
|
case "end":
|
|
94
110
|
return _context.stop();
|
|
95
111
|
}
|
|
96
|
-
}, _callee);
|
|
112
|
+
}, _callee, null, [[0, 26]]);
|
|
97
113
|
}));
|
|
98
114
|
return function (_x) {
|
|
99
115
|
return _ref3.apply(this, arguments);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z, ZodSchema } from "zod";
|
|
2
2
|
import { NextRequest } from "next/server";
|
|
3
|
+
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
3
4
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
4
5
|
import { BaseTable, GetListRelations } from "../types";
|
|
5
6
|
export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> {
|
|
@@ -7,8 +8,9 @@ export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, T
|
|
|
7
8
|
jsonArrayFields?: string[];
|
|
8
9
|
querySchema: Q;
|
|
9
10
|
relations?: GetListRelations;
|
|
10
|
-
setParams?: (req:
|
|
11
|
+
setParams?: (req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string, any>>;
|
|
11
12
|
onSuccess?: (data: z.infer<T>) => Promise<z.infer<T>>;
|
|
13
|
+
onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
12
14
|
summary?: string;
|
|
13
15
|
table: TTable;
|
|
14
16
|
byCreator?: boolean;
|
|
@@ -18,4 +20,4 @@ export declare const createGetOperation: ({ getSession, db, }: {
|
|
|
18
20
|
getSession: (req: NextRequest) => Promise<{
|
|
19
21
|
userId?: string;
|
|
20
22
|
} | undefined>;
|
|
21
|
-
}) => <T extends z.ZodType<any, z.ZodTypeDef, any>, Q extends z.ZodType<any, z.ZodTypeDef, any>, TTable extends BaseTable>({ querySchema, bodySchema, table, summary, relations, setParams, jsonArrayFields, onSuccess, byCreator, }: GetOperationOptions<T, Q, TTable>) => any;
|
|
23
|
+
}) => <T extends z.ZodType<any, z.ZodTypeDef, any>, Q extends z.ZodType<any, z.ZodTypeDef, any>, TTable extends BaseTable>({ querySchema, bodySchema, table, summary, relations, setParams, jsonArrayFields, onSuccess, onError, byCreator, }: GetOperationOptions<T, Q, TTable>) => any;
|
|
@@ -17,6 +17,7 @@ export var createGetOperation = function createGetOperation(_ref) {
|
|
|
17
17
|
setParams = _ref2.setParams,
|
|
18
18
|
jsonArrayFields = _ref2.jsonArrayFields,
|
|
19
19
|
onSuccess = _ref2.onSuccess,
|
|
20
|
+
onError = _ref2.onError,
|
|
20
21
|
_ref2$byCreator = _ref2.byCreator,
|
|
21
22
|
byCreator = _ref2$byCreator === void 0 ? true : _ref2$byCreator;
|
|
22
23
|
return routeOperation({
|
|
@@ -33,40 +34,41 @@ export var createGetOperation = function createGetOperation(_ref) {
|
|
|
33
34
|
status: 200
|
|
34
35
|
}]).handler( /*#__PURE__*/function () {
|
|
35
36
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
|
|
36
|
-
var params, _ref4, userId, result;
|
|
37
|
+
var params, _ref4, userId, result, response;
|
|
37
38
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
38
39
|
while (1) switch (_context.prev = _context.next) {
|
|
39
40
|
case 0:
|
|
40
|
-
_context.
|
|
41
|
+
_context.prev = 0;
|
|
42
|
+
_context.next = 3;
|
|
41
43
|
return setParams === null || setParams === void 0 ? void 0 : setParams(req);
|
|
42
|
-
case
|
|
44
|
+
case 3:
|
|
43
45
|
_context.t0 = _context.sent;
|
|
44
46
|
if (_context.t0) {
|
|
45
|
-
_context.next =
|
|
47
|
+
_context.next = 6;
|
|
46
48
|
break;
|
|
47
49
|
}
|
|
48
50
|
_context.t0 = {};
|
|
49
|
-
case
|
|
51
|
+
case 6:
|
|
50
52
|
params = _context.t0;
|
|
51
53
|
if (!byCreator) {
|
|
52
|
-
_context.next =
|
|
54
|
+
_context.next = 16;
|
|
53
55
|
break;
|
|
54
56
|
}
|
|
55
|
-
_context.next =
|
|
57
|
+
_context.next = 10;
|
|
56
58
|
return getSession(req);
|
|
57
|
-
case
|
|
59
|
+
case 10:
|
|
58
60
|
_context.t1 = _context.sent;
|
|
59
61
|
if (_context.t1) {
|
|
60
|
-
_context.next =
|
|
62
|
+
_context.next = 13;
|
|
61
63
|
break;
|
|
62
64
|
}
|
|
63
65
|
_context.t1 = {};
|
|
64
|
-
case
|
|
66
|
+
case 13:
|
|
65
67
|
_ref4 = _context.t1;
|
|
66
68
|
userId = _ref4.userId;
|
|
67
69
|
params.creatorId = userId;
|
|
68
|
-
case
|
|
69
|
-
_context.next =
|
|
70
|
+
case 16:
|
|
71
|
+
_context.next = 18;
|
|
70
72
|
return createGetAction({
|
|
71
73
|
bodySchema: bodySchema,
|
|
72
74
|
db: db,
|
|
@@ -74,32 +76,46 @@ export var createGetOperation = function createGetOperation(_ref) {
|
|
|
74
76
|
relations: relations,
|
|
75
77
|
table: table
|
|
76
78
|
})(Object.assign(Object.fromEntries(new URL(req.url).searchParams), params));
|
|
77
|
-
case
|
|
79
|
+
case 18:
|
|
78
80
|
_context.t2 = _context.sent;
|
|
79
81
|
if (_context.t2) {
|
|
80
|
-
_context.next =
|
|
82
|
+
_context.next = 21;
|
|
81
83
|
break;
|
|
82
84
|
}
|
|
83
85
|
_context.t2 = {};
|
|
84
|
-
case
|
|
86
|
+
case 21:
|
|
85
87
|
result = _context.t2;
|
|
86
88
|
if (!onSuccess) {
|
|
87
|
-
_context.next =
|
|
89
|
+
_context.next = 26;
|
|
88
90
|
break;
|
|
89
91
|
}
|
|
90
|
-
_context.next =
|
|
92
|
+
_context.next = 25;
|
|
91
93
|
return onSuccess(result);
|
|
92
|
-
case 24:
|
|
93
|
-
result = _context.sent;
|
|
94
94
|
case 25:
|
|
95
|
+
result = _context.sent;
|
|
96
|
+
case 26:
|
|
95
97
|
return _context.abrupt("return", TypedNextResponse.json(result, {
|
|
96
98
|
status: 200
|
|
97
99
|
}));
|
|
98
|
-
case
|
|
100
|
+
case 29:
|
|
101
|
+
_context.prev = 29;
|
|
102
|
+
_context.t3 = _context["catch"](0);
|
|
103
|
+
_context.next = 33;
|
|
104
|
+
return onError === null || onError === void 0 ? void 0 : onError(_context.t3);
|
|
105
|
+
case 33:
|
|
106
|
+
response = _context.sent;
|
|
107
|
+
if (!response) {
|
|
108
|
+
_context.next = 38;
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
return _context.abrupt("return", response);
|
|
112
|
+
case 38:
|
|
113
|
+
throw _context.t3;
|
|
114
|
+
case 39:
|
|
99
115
|
case "end":
|
|
100
116
|
return _context.stop();
|
|
101
117
|
}
|
|
102
|
-
}, _callee);
|
|
118
|
+
}, _callee, null, [[0, 29]]);
|
|
103
119
|
}));
|
|
104
120
|
return function (_x) {
|
|
105
121
|
return _ref3.apply(this, arguments);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { z, ZodSchema } from "zod";
|
|
2
2
|
import { PgTable } from "drizzle-orm/pg-core";
|
|
3
3
|
import { NextRequest } from "next/server";
|
|
4
|
-
import { TypedNextResponse } from "next-rest-framework";
|
|
4
|
+
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
5
5
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
6
6
|
export interface PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends PgTable> {
|
|
7
7
|
bodySchema: IB;
|
|
8
8
|
outputBodySchema?: IB;
|
|
9
|
-
setBody?: (req:
|
|
9
|
+
setBody?: (req: TypedNextRequest<"POST", "application/json", z.infer<IB>>) => Promise<Partial<z.infer<IB>>>;
|
|
10
10
|
summary?: string;
|
|
11
11
|
onSuccess?: (data: z.infer<OB>) => Promise<z.infer<OB>>;
|
|
12
12
|
onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z, ZodSchema } from "zod";
|
|
2
2
|
import { PgTable } from "drizzle-orm/pg-core";
|
|
3
|
+
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
3
4
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
4
5
|
import { NextRequest } from "next/server";
|
|
5
6
|
import { BaseTable } from "../types";
|
|
@@ -8,8 +9,9 @@ export interface PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema,
|
|
|
8
9
|
outputBodySchema?: OB;
|
|
9
10
|
table: TTable;
|
|
10
11
|
summary?: string;
|
|
11
|
-
setBody?: (req:
|
|
12
|
+
setBody?: (req: TypedNextRequest<"PUT", "application/json", z.infer<IB>>) => Promise<Partial<z.infer<IB>>>;
|
|
12
13
|
onSuccess?: (data: z.infer<OB>) => Promise<z.infer<OB>>;
|
|
14
|
+
onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
13
15
|
byCreator?: boolean;
|
|
14
16
|
}
|
|
15
17
|
export declare const createPutOperation: ({ getSession, db, }: {
|
|
@@ -17,4 +19,4 @@ export declare const createPutOperation: ({ getSession, db, }: {
|
|
|
17
19
|
userId?: string;
|
|
18
20
|
} | undefined>;
|
|
19
21
|
db: NodePgDatabase<any>;
|
|
20
|
-
}) => <IB extends z.ZodType<any, z.ZodTypeDef, any>, OB extends z.ZodType<any, z.ZodTypeDef, any>, TTable extends BaseTable>({ bodySchema, outputBodySchema, table, summary, setBody, onSuccess, byCreator, }: PutOperationOptions<IB, OB, TTable>) => any;
|
|
22
|
+
}) => <IB extends z.ZodType<any, z.ZodTypeDef, any>, OB extends z.ZodType<any, z.ZodTypeDef, any>, TTable extends BaseTable>({ bodySchema, outputBodySchema, table, summary, setBody, onSuccess, byCreator, onError, }: PutOperationOptions<IB, OB, TTable>) => any;
|
|
@@ -22,7 +22,8 @@ export var createPutOperation = function createPutOperation(_ref) {
|
|
|
22
22
|
setBody = _ref2.setBody,
|
|
23
23
|
onSuccess = _ref2.onSuccess,
|
|
24
24
|
_ref2$byCreator = _ref2.byCreator,
|
|
25
|
-
byCreator = _ref2$byCreator === void 0 ? true : _ref2$byCreator
|
|
25
|
+
byCreator = _ref2$byCreator === void 0 ? true : _ref2$byCreator,
|
|
26
|
+
onError = _ref2.onError;
|
|
26
27
|
return routeOperation({
|
|
27
28
|
method: "PUT",
|
|
28
29
|
openApiOperation: {
|
|
@@ -38,40 +39,41 @@ export var createPutOperation = function createPutOperation(_ref) {
|
|
|
38
39
|
contentType: "application/json"
|
|
39
40
|
}]).handler( /*#__PURE__*/function () {
|
|
40
41
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
|
|
41
|
-
var _ref4, userId, body,
|
|
42
|
+
var _ref4, userId, body, _data, response;
|
|
42
43
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
43
44
|
while (1) switch (_context.prev = _context.next) {
|
|
44
45
|
case 0:
|
|
45
|
-
_context.
|
|
46
|
+
_context.prev = 0;
|
|
47
|
+
_context.next = 3;
|
|
46
48
|
return getSession(req);
|
|
47
|
-
case
|
|
49
|
+
case 3:
|
|
48
50
|
_context.t0 = _context.sent;
|
|
49
51
|
if (_context.t0) {
|
|
50
|
-
_context.next =
|
|
52
|
+
_context.next = 6;
|
|
51
53
|
break;
|
|
52
54
|
}
|
|
53
55
|
_context.t0 = {};
|
|
54
|
-
case
|
|
56
|
+
case 6:
|
|
55
57
|
_ref4 = _context.t0;
|
|
56
58
|
userId = _ref4.userId;
|
|
57
59
|
_context.t1 = Object;
|
|
58
|
-
_context.next =
|
|
60
|
+
_context.next = 11;
|
|
59
61
|
return req.json();
|
|
60
|
-
case
|
|
62
|
+
case 11:
|
|
61
63
|
_context.t2 = _context.sent;
|
|
62
|
-
_context.next =
|
|
64
|
+
_context.next = 14;
|
|
63
65
|
return setBody === null || setBody === void 0 ? void 0 : setBody(req);
|
|
64
|
-
case
|
|
66
|
+
case 14:
|
|
65
67
|
_context.t3 = _context.sent;
|
|
66
68
|
if (_context.t3) {
|
|
67
|
-
_context.next =
|
|
69
|
+
_context.next = 17;
|
|
68
70
|
break;
|
|
69
71
|
}
|
|
70
72
|
_context.t3 = {};
|
|
71
|
-
case
|
|
73
|
+
case 17:
|
|
72
74
|
_context.t4 = _context.t3;
|
|
73
75
|
body = _context.t1.assign.call(_context.t1, _context.t2, _context.t4);
|
|
74
|
-
_context.next =
|
|
76
|
+
_context.next = 21;
|
|
75
77
|
return createPutAction({
|
|
76
78
|
bodySchema: bodySchema,
|
|
77
79
|
table: table,
|
|
@@ -81,25 +83,39 @@ export var createPutOperation = function createPutOperation(_ref) {
|
|
|
81
83
|
}, body), {
|
|
82
84
|
byCreator: byCreator
|
|
83
85
|
});
|
|
84
|
-
case
|
|
85
|
-
|
|
86
|
+
case 21:
|
|
87
|
+
_data = _context.sent;
|
|
86
88
|
if (!onSuccess) {
|
|
87
|
-
_context.next =
|
|
89
|
+
_context.next = 26;
|
|
88
90
|
break;
|
|
89
91
|
}
|
|
90
|
-
_context.next =
|
|
91
|
-
return onSuccess(
|
|
92
|
-
case 24:
|
|
93
|
-
data = _context.sent;
|
|
92
|
+
_context.next = 25;
|
|
93
|
+
return onSuccess(_data);
|
|
94
94
|
case 25:
|
|
95
|
-
|
|
95
|
+
_data = _context.sent;
|
|
96
|
+
case 26:
|
|
97
|
+
return _context.abrupt("return", TypedNextResponse.json(_data, {
|
|
96
98
|
status: 200
|
|
97
99
|
}));
|
|
98
|
-
case
|
|
100
|
+
case 29:
|
|
101
|
+
_context.prev = 29;
|
|
102
|
+
_context.t5 = _context["catch"](0);
|
|
103
|
+
_context.next = 33;
|
|
104
|
+
return onError === null || onError === void 0 ? void 0 : onError(_context.t5);
|
|
105
|
+
case 33:
|
|
106
|
+
response = _context.sent;
|
|
107
|
+
if (!response) {
|
|
108
|
+
_context.next = 38;
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
return _context.abrupt("return", response);
|
|
112
|
+
case 38:
|
|
113
|
+
throw _context.t5;
|
|
114
|
+
case 39:
|
|
99
115
|
case "end":
|
|
100
116
|
return _context.stop();
|
|
101
117
|
}
|
|
102
|
-
}, _callee);
|
|
118
|
+
}, _callee, null, [[0, 29]]);
|
|
103
119
|
}));
|
|
104
120
|
return function (_x) {
|
|
105
121
|
return _ref3.apply(this, arguments);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TypedNextResponse } from "next-rest-framework";
|
|
1
2
|
import { BaseTable } from "../types";
|
|
2
3
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
3
4
|
import { NextRequest } from "next/server";
|
|
@@ -5,6 +6,7 @@ export interface DeleteOperationOptions<TTable extends BaseTable> {
|
|
|
5
6
|
table: TTable;
|
|
6
7
|
summary?: string;
|
|
7
8
|
onSuccess?: () => Promise<void>;
|
|
9
|
+
onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
8
10
|
byCreator?: boolean;
|
|
9
11
|
}
|
|
10
12
|
export declare const createDeleteOperation: ({ db, getSession, }: {
|
|
@@ -12,4 +14,4 @@ export declare const createDeleteOperation: ({ db, getSession, }: {
|
|
|
12
14
|
getSession: (req: NextRequest) => Promise<{
|
|
13
15
|
userId?: string;
|
|
14
16
|
} | undefined>;
|
|
15
|
-
}) => <TTable extends BaseTable>({ table, summary, onSuccess, byCreator, }: DeleteOperationOptions<TTable>) => any;
|
|
17
|
+
}) => <TTable extends BaseTable>({ table, summary, onSuccess, onError, byCreator, }: DeleteOperationOptions<TTable>) => any;
|
|
@@ -43,6 +43,7 @@ var createDeleteOperation = ({
|
|
|
43
43
|
table,
|
|
44
44
|
summary,
|
|
45
45
|
onSuccess,
|
|
46
|
+
onError,
|
|
46
47
|
byCreator = true
|
|
47
48
|
}) => (0, import_next_rest_framework.routeOperation)({
|
|
48
49
|
method: "DELETE",
|
|
@@ -56,16 +57,25 @@ var createDeleteOperation = ({
|
|
|
56
57
|
}),
|
|
57
58
|
contentType: "application/json"
|
|
58
59
|
}).handler(async (req) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
try {
|
|
61
|
+
const body = await req.json();
|
|
62
|
+
if (byCreator) {
|
|
63
|
+
const { userId } = await getSession(req) || {};
|
|
64
|
+
body.creatorId = userId;
|
|
65
|
+
}
|
|
66
|
+
const data = await (0, import_actions.createDeleteAction)({ table, db })(body);
|
|
67
|
+
await (onSuccess == null ? void 0 : onSuccess());
|
|
68
|
+
return import_next_rest_framework.TypedNextResponse.json(data, {
|
|
69
|
+
status: 200
|
|
70
|
+
});
|
|
71
|
+
} catch (e) {
|
|
72
|
+
const response = await (onError == null ? void 0 : onError(e));
|
|
73
|
+
if (response) {
|
|
74
|
+
return response;
|
|
75
|
+
} else {
|
|
76
|
+
throw e;
|
|
77
|
+
}
|
|
63
78
|
}
|
|
64
|
-
const data = await (0, import_actions.createDeleteAction)({ table, db })(body);
|
|
65
|
-
await (onSuccess == null ? void 0 : onSuccess());
|
|
66
|
-
return import_next_rest_framework.TypedNextResponse.json(data, {
|
|
67
|
-
status: 200
|
|
68
|
-
});
|
|
69
79
|
});
|
|
70
80
|
// Annotate the CommonJS export names for ESM import in node:
|
|
71
81
|
0 && (module.exports = {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z, ZodSchema } from "zod";
|
|
2
2
|
import { NextRequest } from "next/server";
|
|
3
|
+
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
3
4
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
4
5
|
import { BaseTable, GetListRelations } from "../types";
|
|
5
6
|
export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> {
|
|
@@ -7,7 +8,7 @@ export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchem
|
|
|
7
8
|
jsonArrayFields?: string[];
|
|
8
9
|
querySchema: Q;
|
|
9
10
|
relations?: GetListRelations;
|
|
10
|
-
setParams?: (req:
|
|
11
|
+
setParams?: (req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string, unknown>>;
|
|
11
12
|
byCreator?: boolean;
|
|
12
13
|
summary?: string;
|
|
13
14
|
table: TTable;
|
|
@@ -18,10 +19,11 @@ export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchem
|
|
|
18
19
|
data: z.infer<T>[];
|
|
19
20
|
total: number;
|
|
20
21
|
}>;
|
|
22
|
+
onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
21
23
|
}
|
|
22
24
|
export declare const createGetListOperation: ({ db, getSession, }: {
|
|
23
25
|
db: NodePgDatabase<any>;
|
|
24
26
|
getSession: (req: NextRequest) => Promise<{
|
|
25
27
|
userId?: string;
|
|
26
28
|
} | undefined>;
|
|
27
|
-
}) => <T extends z.ZodType<any, z.ZodTypeDef, any>, Q extends z.ZodType<any, z.ZodTypeDef, any>, TTable extends BaseTable>({ querySchema, bodySchema, table, summary, relations, jsonArrayFields, setParams, onSuccess, byCreator, }: GetListOperationOptions<T, Q, TTable>) => any;
|
|
29
|
+
}) => <T extends z.ZodType<any, z.ZodTypeDef, any>, Q extends z.ZodType<any, z.ZodTypeDef, any>, TTable extends BaseTable>({ querySchema, bodySchema, table, summary, relations, jsonArrayFields, setParams, onSuccess, onError, byCreator, }: GetListOperationOptions<T, Q, TTable>) => any;
|
|
@@ -48,6 +48,7 @@ var createGetListOperation = ({
|
|
|
48
48
|
jsonArrayFields,
|
|
49
49
|
setParams,
|
|
50
50
|
onSuccess,
|
|
51
|
+
onError,
|
|
51
52
|
byCreator = true
|
|
52
53
|
}) => (0, import_next_rest_framework.routeOperation)({
|
|
53
54
|
method: "GET",
|
|
@@ -64,27 +65,36 @@ var createGetListOperation = ({
|
|
|
64
65
|
status: 200
|
|
65
66
|
}
|
|
66
67
|
]).handler(async (req) => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
try {
|
|
69
|
+
const params = await (setParams == null ? void 0 : setParams(req)) || {};
|
|
70
|
+
if (byCreator) {
|
|
71
|
+
const { userId } = await getSession(req) || {};
|
|
72
|
+
params.creatorId = userId;
|
|
73
|
+
}
|
|
74
|
+
let result = await (0, import_actions.createGetListAction)({
|
|
75
|
+
bodySchema,
|
|
76
|
+
db,
|
|
77
|
+
jsonArrayFields,
|
|
78
|
+
relations,
|
|
79
|
+
table
|
|
80
|
+
})(
|
|
81
|
+
Object.assign(
|
|
82
|
+
Object.fromEntries(new URL(req.url).searchParams),
|
|
83
|
+
params
|
|
84
|
+
)
|
|
85
|
+
);
|
|
86
|
+
if (onSuccess) {
|
|
87
|
+
result = await onSuccess(result);
|
|
88
|
+
}
|
|
89
|
+
return import_next_rest_framework.TypedNextResponse.json(result, { status: 200 });
|
|
90
|
+
} catch (e) {
|
|
91
|
+
const response = await (onError == null ? void 0 : onError(e));
|
|
92
|
+
if (response) {
|
|
93
|
+
return response;
|
|
94
|
+
} else {
|
|
95
|
+
throw e;
|
|
96
|
+
}
|
|
71
97
|
}
|
|
72
|
-
let result = await (0, import_actions.createGetListAction)({
|
|
73
|
-
bodySchema,
|
|
74
|
-
db,
|
|
75
|
-
jsonArrayFields,
|
|
76
|
-
relations,
|
|
77
|
-
table
|
|
78
|
-
})(
|
|
79
|
-
Object.assign(
|
|
80
|
-
Object.fromEntries(new URL(req.url).searchParams),
|
|
81
|
-
params
|
|
82
|
-
)
|
|
83
|
-
);
|
|
84
|
-
if (onSuccess) {
|
|
85
|
-
result = await onSuccess(result);
|
|
86
|
-
}
|
|
87
|
-
return import_next_rest_framework.TypedNextResponse.json(result, { status: 200 });
|
|
88
98
|
});
|
|
89
99
|
// Annotate the CommonJS export names for ESM import in node:
|
|
90
100
|
0 && (module.exports = {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z, ZodSchema } from "zod";
|
|
2
2
|
import { NextRequest } from "next/server";
|
|
3
|
+
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
3
4
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
4
5
|
import { BaseTable, GetListRelations } from "../types";
|
|
5
6
|
export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> {
|
|
@@ -7,8 +8,9 @@ export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, T
|
|
|
7
8
|
jsonArrayFields?: string[];
|
|
8
9
|
querySchema: Q;
|
|
9
10
|
relations?: GetListRelations;
|
|
10
|
-
setParams?: (req:
|
|
11
|
+
setParams?: (req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string, any>>;
|
|
11
12
|
onSuccess?: (data: z.infer<T>) => Promise<z.infer<T>>;
|
|
13
|
+
onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
12
14
|
summary?: string;
|
|
13
15
|
table: TTable;
|
|
14
16
|
byCreator?: boolean;
|
|
@@ -18,4 +20,4 @@ export declare const createGetOperation: ({ getSession, db, }: {
|
|
|
18
20
|
getSession: (req: NextRequest) => Promise<{
|
|
19
21
|
userId?: string;
|
|
20
22
|
} | undefined>;
|
|
21
|
-
}) => <T extends z.ZodType<any, z.ZodTypeDef, any>, Q extends z.ZodType<any, z.ZodTypeDef, any>, TTable extends BaseTable>({ querySchema, bodySchema, table, summary, relations, setParams, jsonArrayFields, onSuccess, byCreator, }: GetOperationOptions<T, Q, TTable>) => any;
|
|
23
|
+
}) => <T extends z.ZodType<any, z.ZodTypeDef, any>, Q extends z.ZodType<any, z.ZodTypeDef, any>, TTable extends BaseTable>({ querySchema, bodySchema, table, summary, relations, setParams, jsonArrayFields, onSuccess, onError, byCreator, }: GetOperationOptions<T, Q, TTable>) => any;
|
|
@@ -47,6 +47,7 @@ var createGetOperation = ({
|
|
|
47
47
|
setParams,
|
|
48
48
|
jsonArrayFields,
|
|
49
49
|
onSuccess,
|
|
50
|
+
onError,
|
|
50
51
|
byCreator = true
|
|
51
52
|
}) => (0, import_next_rest_framework.routeOperation)({
|
|
52
53
|
method: "GET",
|
|
@@ -63,27 +64,36 @@ var createGetOperation = ({
|
|
|
63
64
|
status: 200
|
|
64
65
|
}
|
|
65
66
|
]).handler(async (req) => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
try {
|
|
68
|
+
const params = await (setParams == null ? void 0 : setParams(req)) || {};
|
|
69
|
+
if (byCreator) {
|
|
70
|
+
const { userId } = await getSession(req) || {};
|
|
71
|
+
params.creatorId = userId;
|
|
72
|
+
}
|
|
73
|
+
let result = await (0, import_actions.createGetAction)({
|
|
74
|
+
bodySchema,
|
|
75
|
+
db,
|
|
76
|
+
jsonArrayFields,
|
|
77
|
+
relations,
|
|
78
|
+
table
|
|
79
|
+
})(
|
|
80
|
+
Object.assign(
|
|
81
|
+
Object.fromEntries(new URL(req.url).searchParams),
|
|
82
|
+
params
|
|
83
|
+
)
|
|
84
|
+
) || {};
|
|
85
|
+
if (onSuccess) {
|
|
86
|
+
result = await onSuccess(result);
|
|
87
|
+
}
|
|
88
|
+
return import_next_rest_framework.TypedNextResponse.json(result, { status: 200 });
|
|
89
|
+
} catch (e) {
|
|
90
|
+
const response = await (onError == null ? void 0 : onError(e));
|
|
91
|
+
if (response) {
|
|
92
|
+
return response;
|
|
93
|
+
} else {
|
|
94
|
+
throw e;
|
|
95
|
+
}
|
|
70
96
|
}
|
|
71
|
-
let result = await (0, import_actions.createGetAction)({
|
|
72
|
-
bodySchema,
|
|
73
|
-
db,
|
|
74
|
-
jsonArrayFields,
|
|
75
|
-
relations,
|
|
76
|
-
table
|
|
77
|
-
})(
|
|
78
|
-
Object.assign(
|
|
79
|
-
Object.fromEntries(new URL(req.url).searchParams),
|
|
80
|
-
params
|
|
81
|
-
)
|
|
82
|
-
) || {};
|
|
83
|
-
if (onSuccess) {
|
|
84
|
-
result = await onSuccess(result);
|
|
85
|
-
}
|
|
86
|
-
return import_next_rest_framework.TypedNextResponse.json(result, { status: 200 });
|
|
87
97
|
});
|
|
88
98
|
// Annotate the CommonJS export names for ESM import in node:
|
|
89
99
|
0 && (module.exports = {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { z, ZodSchema } from "zod";
|
|
2
2
|
import { PgTable } from "drizzle-orm/pg-core";
|
|
3
3
|
import { NextRequest } from "next/server";
|
|
4
|
-
import { TypedNextResponse } from "next-rest-framework";
|
|
4
|
+
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
5
5
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
6
6
|
export interface PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends PgTable> {
|
|
7
7
|
bodySchema: IB;
|
|
8
8
|
outputBodySchema?: IB;
|
|
9
|
-
setBody?: (req:
|
|
9
|
+
setBody?: (req: TypedNextRequest<"POST", "application/json", z.infer<IB>>) => Promise<Partial<z.infer<IB>>>;
|
|
10
10
|
summary?: string;
|
|
11
11
|
onSuccess?: (data: z.infer<OB>) => Promise<z.infer<OB>>;
|
|
12
12
|
onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z, ZodSchema } from "zod";
|
|
2
2
|
import { PgTable } from "drizzle-orm/pg-core";
|
|
3
|
+
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
3
4
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
4
5
|
import { NextRequest } from "next/server";
|
|
5
6
|
import { BaseTable } from "../types";
|
|
@@ -8,8 +9,9 @@ export interface PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema,
|
|
|
8
9
|
outputBodySchema?: OB;
|
|
9
10
|
table: TTable;
|
|
10
11
|
summary?: string;
|
|
11
|
-
setBody?: (req:
|
|
12
|
+
setBody?: (req: TypedNextRequest<"PUT", "application/json", z.infer<IB>>) => Promise<Partial<z.infer<IB>>>;
|
|
12
13
|
onSuccess?: (data: z.infer<OB>) => Promise<z.infer<OB>>;
|
|
14
|
+
onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
13
15
|
byCreator?: boolean;
|
|
14
16
|
}
|
|
15
17
|
export declare const createPutOperation: ({ getSession, db, }: {
|
|
@@ -17,4 +19,4 @@ export declare const createPutOperation: ({ getSession, db, }: {
|
|
|
17
19
|
userId?: string;
|
|
18
20
|
} | undefined>;
|
|
19
21
|
db: NodePgDatabase<any>;
|
|
20
|
-
}) => <IB extends z.ZodType<any, z.ZodTypeDef, any>, OB extends z.ZodType<any, z.ZodTypeDef, any>, TTable extends BaseTable>({ bodySchema, outputBodySchema, table, summary, setBody, onSuccess, byCreator, }: PutOperationOptions<IB, OB, TTable>) => any;
|
|
22
|
+
}) => <IB extends z.ZodType<any, z.ZodTypeDef, any>, OB extends z.ZodType<any, z.ZodTypeDef, any>, TTable extends BaseTable>({ bodySchema, outputBodySchema, table, summary, setBody, onSuccess, byCreator, onError, }: PutOperationOptions<IB, OB, TTable>) => any;
|
|
@@ -46,7 +46,8 @@ var createPutOperation = ({
|
|
|
46
46
|
summary,
|
|
47
47
|
setBody,
|
|
48
48
|
onSuccess,
|
|
49
|
-
byCreator = true
|
|
49
|
+
byCreator = true,
|
|
50
|
+
onError
|
|
50
51
|
}) => (0, import_next_rest_framework.routeOperation)({
|
|
51
52
|
method: "PUT",
|
|
52
53
|
openApiOperation: {
|
|
@@ -63,26 +64,35 @@ var createPutOperation = ({
|
|
|
63
64
|
contentType: "application/json"
|
|
64
65
|
}
|
|
65
66
|
]).handler(async (req) => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
67
|
+
try {
|
|
68
|
+
const { userId } = await getSession(req) || {};
|
|
69
|
+
const body = Object.assign(
|
|
70
|
+
await req.json(),
|
|
71
|
+
await (setBody == null ? void 0 : setBody(req)) || {}
|
|
72
|
+
);
|
|
73
|
+
let data = await (0, import_actions.createPutAction)({
|
|
74
|
+
bodySchema,
|
|
75
|
+
table,
|
|
76
|
+
db
|
|
77
|
+
})(
|
|
78
|
+
{
|
|
79
|
+
editorId: userId,
|
|
80
|
+
...body
|
|
81
|
+
},
|
|
82
|
+
{ byCreator }
|
|
83
|
+
);
|
|
84
|
+
if (onSuccess) {
|
|
85
|
+
data = await onSuccess(data);
|
|
86
|
+
}
|
|
87
|
+
return import_next_rest_framework.TypedNextResponse.json(data, { status: 200 });
|
|
88
|
+
} catch (e) {
|
|
89
|
+
const response = await (onError == null ? void 0 : onError(e));
|
|
90
|
+
if (response) {
|
|
91
|
+
return response;
|
|
92
|
+
} else {
|
|
93
|
+
throw e;
|
|
94
|
+
}
|
|
84
95
|
}
|
|
85
|
-
return import_next_rest_framework.TypedNextResponse.json(data, { status: 200 });
|
|
86
96
|
});
|
|
87
97
|
// Annotate the CommonJS export names for ESM import in node:
|
|
88
98
|
0 && (module.exports = {
|