@ai0x0/utils 0.0.46 → 0.0.48
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/.agents/skills/ai0x0-utils/backend/SKILL.md +40 -38
- package/SKILL.md +39 -37
- package/es/__shims__/next-rest-framework.d.ts +2 -0
- package/es/backend/route-operation/delete-operation.d.ts +7 -18
- package/es/backend/route-operation/delete-operation.js +10 -122
- package/es/backend/route-operation/get-list-operation.d.ts +5 -27
- package/es/backend/route-operation/get-list-operation.js +10 -135
- package/es/backend/route-operation/get-operation.d.ts +5 -21
- package/es/backend/route-operation/get-operation.js +10 -132
- package/es/backend/route-operation/get-table-name.js +0 -2
- package/es/backend/route-operation/index.d.ts +1 -0
- package/es/backend/route-operation/index.js +2 -1
- package/es/backend/route-operation/open-api-operation.d.ts +6 -0
- package/es/backend/route-operation/open-api-operation.js +13 -0
- package/es/backend/route-operation/operation-common.d.ts +38 -0
- package/es/backend/route-operation/operation-common.js +148 -0
- package/es/backend/route-operation/operation-core.d.ts +3 -0
- package/es/backend/route-operation/operation-core.js +3 -0
- package/es/backend/route-operation/post-operation.d.ts +5 -25
- package/es/backend/route-operation/post-operation.js +13 -189
- package/es/backend/route-operation/put-operation.d.ts +4 -23
- package/es/backend/route-operation/put-operation.js +10 -155
- package/es/backend/route-operation/read-operation-core.d.ts +55 -0
- package/es/backend/route-operation/read-operation-core.js +224 -0
- package/es/backend/route-operation/write-operation-core.d.ts +94 -0
- package/es/backend/route-operation/write-operation-core.js +390 -0
- package/es/backend/sqlite/route-operation/delete-operation.d.ts +9 -20
- package/es/backend/sqlite/route-operation/delete-operation.js +10 -122
- package/es/backend/sqlite/route-operation/get-list-operation.d.ts +6 -28
- package/es/backend/sqlite/route-operation/get-list-operation.js +10 -135
- package/es/backend/sqlite/route-operation/get-operation.d.ts +6 -22
- package/es/backend/sqlite/route-operation/get-operation.js +10 -132
- package/es/backend/sqlite/route-operation/index.d.ts +1 -0
- package/es/backend/sqlite/route-operation/index.js +2 -1
- package/es/backend/sqlite/route-operation/post-operation.d.ts +6 -26
- package/es/backend/sqlite/route-operation/post-operation.js +13 -189
- package/es/backend/sqlite/route-operation/put-operation.d.ts +6 -25
- package/es/backend/sqlite/route-operation/put-operation.js +10 -155
- package/es/backend/sqlite/schemas/index.d.ts +69 -5
- package/es/backend/sqlite/schemas/index.js +0 -1
- package/lib/__shims__/next-rest-framework.d.ts +2 -0
- package/lib/backend/route-operation/delete-operation.d.ts +7 -18
- package/lib/backend/route-operation/delete-operation.js +7 -52
- package/lib/backend/route-operation/get-list-operation.d.ts +5 -27
- package/lib/backend/route-operation/get-list-operation.js +7 -68
- package/lib/backend/route-operation/get-operation.d.ts +5 -21
- package/lib/backend/route-operation/get-operation.js +7 -67
- package/lib/backend/route-operation/index.d.ts +1 -0
- package/lib/backend/route-operation/index.js +3 -1
- package/lib/backend/route-operation/open-api-operation.d.ts +6 -0
- package/lib/backend/route-operation/open-api-operation.js +37 -0
- package/lib/backend/route-operation/operation-common.d.ts +38 -0
- package/lib/backend/route-operation/operation-common.js +90 -0
- package/lib/backend/route-operation/operation-core.d.ts +3 -0
- package/lib/backend/route-operation/operation-core.js +27 -0
- package/lib/backend/route-operation/post-operation.d.ts +5 -25
- package/lib/backend/route-operation/post-operation.js +7 -71
- package/lib/backend/route-operation/put-operation.d.ts +4 -23
- package/lib/backend/route-operation/put-operation.js +7 -68
- package/lib/backend/route-operation/read-operation-core.d.ts +55 -0
- package/lib/backend/route-operation/read-operation-core.js +151 -0
- package/lib/backend/route-operation/write-operation-core.d.ts +94 -0
- package/lib/backend/route-operation/write-operation-core.js +181 -0
- package/lib/backend/sqlite/route-operation/delete-operation.d.ts +9 -20
- package/lib/backend/sqlite/route-operation/delete-operation.js +7 -52
- package/lib/backend/sqlite/route-operation/get-list-operation.d.ts +6 -28
- package/lib/backend/sqlite/route-operation/get-list-operation.js +7 -71
- package/lib/backend/sqlite/route-operation/get-operation.d.ts +6 -22
- package/lib/backend/sqlite/route-operation/get-operation.js +7 -67
- package/lib/backend/sqlite/route-operation/index.d.ts +1 -0
- package/lib/backend/sqlite/route-operation/index.js +3 -1
- package/lib/backend/sqlite/route-operation/post-operation.d.ts +6 -26
- package/lib/backend/sqlite/route-operation/post-operation.js +7 -71
- package/lib/backend/sqlite/route-operation/put-operation.d.ts +6 -25
- package/lib/backend/sqlite/route-operation/put-operation.js +7 -68
- package/lib/backend/sqlite/schemas/index.d.ts +69 -5
- package/package.json +1 -1
|
@@ -1,191 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
9
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
10
|
-
import { z } from "zod";
|
|
11
|
-
import { routeOperation, TypedNextResponse } from "next-rest-framework";
|
|
1
|
+
import { createPostAction } from "../actions/create-post-action.js";
|
|
2
|
+
import { createPostOperationFactory } from "../../route-operation/operation-core.js";
|
|
12
3
|
import getTableName from "./get-table-name.js";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (!parseBody) {
|
|
25
|
-
_context2.next = 3;
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
return _context2.abrupt("return", parseBody(req));
|
|
29
|
-
case 3:
|
|
30
|
-
if (!(contentType === "multipart/form-data")) {
|
|
31
|
-
_context2.next = 9;
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
_context2.t0 = Object;
|
|
35
|
-
_context2.next = 7;
|
|
36
|
-
return req.formData();
|
|
37
|
-
case 7:
|
|
38
|
-
_context2.t1 = _context2.sent;
|
|
39
|
-
return _context2.abrupt("return", _context2.t0.fromEntries.call(_context2.t0, _context2.t1));
|
|
40
|
-
case 9:
|
|
41
|
-
_context2.next = 11;
|
|
42
|
-
return req.json();
|
|
43
|
-
case 11:
|
|
44
|
-
return _context2.abrupt("return", _context2.sent);
|
|
45
|
-
case 12:
|
|
46
|
-
case "end":
|
|
47
|
-
return _context2.stop();
|
|
48
|
-
}
|
|
49
|
-
}, _callee2);
|
|
50
|
-
}));
|
|
51
|
-
return _readPostBody.apply(this, arguments);
|
|
52
|
-
}
|
|
53
|
-
export var createPostOperation = function createPostOperation(_ref2) {
|
|
54
|
-
var getSession = _ref2.getSession,
|
|
55
|
-
db = _ref2.db;
|
|
56
|
-
return function (_ref3) {
|
|
57
|
-
var bodySchema = _ref3.bodySchema,
|
|
58
|
-
_ref3$contentType = _ref3.contentType,
|
|
59
|
-
contentType = _ref3$contentType === void 0 ? "application/json" : _ref3$contentType,
|
|
60
|
-
description = _ref3.description,
|
|
61
|
-
outputBodySchema = _ref3.outputBodySchema,
|
|
62
|
-
parseBody = _ref3.parseBody,
|
|
63
|
-
setBody = _ref3.setBody,
|
|
64
|
-
summary = _ref3.summary,
|
|
65
|
-
tags = _ref3.tags,
|
|
66
|
-
table = _ref3.table,
|
|
67
|
-
onSuccess = _ref3.onSuccess,
|
|
68
|
-
onError = _ref3.onError;
|
|
69
|
-
return routeOperation({
|
|
70
|
-
method: "POST",
|
|
71
|
-
openApiOperation: {
|
|
72
|
-
description: description,
|
|
73
|
-
summary: summary,
|
|
74
|
-
tags: tags !== null && tags !== void 0 ? tags : table ? [getTableName(table)] : []
|
|
75
|
-
}
|
|
76
|
-
}).input({
|
|
77
|
-
body: bodySchema,
|
|
78
|
-
contentType: contentType
|
|
79
|
-
}).outputs([{
|
|
80
|
-
body: outputBodySchema || z.object({
|
|
81
|
-
id: z.string()
|
|
82
|
-
}),
|
|
83
|
-
contentType: "application/json",
|
|
84
|
-
status: 200
|
|
85
|
-
}]).handler( /*#__PURE__*/function () {
|
|
86
|
-
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
|
|
87
|
-
var _ref5, userId, body, extraBody, mergedBody, params, raw, data, response;
|
|
88
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
89
|
-
while (1) switch (_context.prev = _context.next) {
|
|
90
|
-
case 0:
|
|
91
|
-
_context.prev = 0;
|
|
92
|
-
_context.next = 3;
|
|
93
|
-
return getSession(req);
|
|
94
|
-
case 3:
|
|
95
|
-
_context.t0 = _context.sent;
|
|
96
|
-
if (_context.t0) {
|
|
97
|
-
_context.next = 6;
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
_context.t0 = {};
|
|
101
|
-
case 6:
|
|
102
|
-
_ref5 = _context.t0;
|
|
103
|
-
userId = _ref5.userId;
|
|
104
|
-
_context.next = 10;
|
|
105
|
-
return readPostBody(req, {
|
|
106
|
-
contentType: contentType,
|
|
107
|
-
parseBody: parseBody
|
|
108
|
-
});
|
|
109
|
-
case 10:
|
|
110
|
-
body = _context.sent;
|
|
111
|
-
_context.next = 13;
|
|
112
|
-
return setBody === null || setBody === void 0 ? void 0 : setBody(req);
|
|
113
|
-
case 13:
|
|
114
|
-
_context.t1 = _context.sent;
|
|
115
|
-
if (_context.t1) {
|
|
116
|
-
_context.next = 16;
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
_context.t1 = {};
|
|
120
|
-
case 16:
|
|
121
|
-
extraBody = _context.t1;
|
|
122
|
-
mergedBody = _objectSpread(_objectSpread({}, body), extraBody);
|
|
123
|
-
params = _objectSpread({
|
|
124
|
-
creatorId: userId
|
|
125
|
-
}, mergedBody);
|
|
126
|
-
if (!(table && db)) {
|
|
127
|
-
_context.next = 25;
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
_context.next = 22;
|
|
131
|
-
return createPostAction({
|
|
132
|
-
bodySchema: bodySchema,
|
|
133
|
-
db: db,
|
|
134
|
-
table: table
|
|
135
|
-
})(params);
|
|
136
|
-
case 22:
|
|
137
|
-
_context.t2 = _context.sent[0];
|
|
138
|
-
_context.next = 26;
|
|
139
|
-
break;
|
|
140
|
-
case 25:
|
|
141
|
-
_context.t2 = params;
|
|
142
|
-
case 26:
|
|
143
|
-
raw = _context.t2;
|
|
144
|
-
if (!onSuccess) {
|
|
145
|
-
_context.next = 33;
|
|
146
|
-
break;
|
|
147
|
-
}
|
|
148
|
-
_context.next = 30;
|
|
149
|
-
return onSuccess({
|
|
150
|
-
data: raw,
|
|
151
|
-
params: params,
|
|
152
|
-
req: req
|
|
153
|
-
});
|
|
154
|
-
case 30:
|
|
155
|
-
_context.t3 = _context.sent;
|
|
156
|
-
_context.next = 34;
|
|
157
|
-
break;
|
|
158
|
-
case 33:
|
|
159
|
-
_context.t3 = raw;
|
|
160
|
-
case 34:
|
|
161
|
-
data = _context.t3;
|
|
162
|
-
return _context.abrupt("return", TypedNextResponse.json(data, {
|
|
163
|
-
status: 200
|
|
164
|
-
}));
|
|
165
|
-
case 38:
|
|
166
|
-
_context.prev = 38;
|
|
167
|
-
_context.t4 = _context["catch"](0);
|
|
168
|
-
console.error(_context.t4);
|
|
169
|
-
_context.next = 43;
|
|
170
|
-
return onError === null || onError === void 0 ? void 0 : onError(_context.t4);
|
|
171
|
-
case 43:
|
|
172
|
-
response = _context.sent;
|
|
173
|
-
if (!response) {
|
|
174
|
-
_context.next = 48;
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
return _context.abrupt("return", response);
|
|
178
|
-
case 48:
|
|
179
|
-
throw _context.t4;
|
|
180
|
-
case 49:
|
|
181
|
-
case "end":
|
|
182
|
-
return _context.stop();
|
|
183
|
-
}
|
|
184
|
-
}, _callee, null, [[0, 38]]);
|
|
185
|
-
}));
|
|
186
|
-
return function (_x3) {
|
|
187
|
-
return _ref4.apply(this, arguments);
|
|
188
|
-
};
|
|
189
|
-
}());
|
|
190
|
-
};
|
|
4
|
+
var createOperation = createPostOperationFactory({
|
|
5
|
+
createAction: createPostAction,
|
|
6
|
+
getTableName: getTableName
|
|
7
|
+
});
|
|
8
|
+
export var createPostOperation = function createPostOperation(_ref) {
|
|
9
|
+
var getSession = _ref.getSession,
|
|
10
|
+
db = _ref.db;
|
|
11
|
+
return createOperation({
|
|
12
|
+
db: db,
|
|
13
|
+
getSession: getSession
|
|
14
|
+
});
|
|
191
15
|
};
|
|
@@ -1,30 +1,11 @@
|
|
|
1
|
-
import { z, ZodSchema } from "zod";
|
|
2
1
|
import { SQLiteTable } from "drizzle-orm/sqlite-core";
|
|
3
|
-
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
4
2
|
import { NextRequest } from "next/server";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
export interface PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends SQLiteTable> {
|
|
10
|
-
bodySchema: IB;
|
|
11
|
-
description?: string;
|
|
12
|
-
outputBodySchema?: OB;
|
|
13
|
-
table?: TTable;
|
|
14
|
-
summary?: string;
|
|
15
|
-
tags?: string[];
|
|
16
|
-
setBody?: (_req: TypedNextRequest<"PUT", "application/json", z.infer<IB>>) => Promise<Partial<z.infer<IB>>>;
|
|
17
|
-
onSuccess?: (_payload: {
|
|
18
|
-
params: PutOperationParams<IB>;
|
|
19
|
-
data: z.infer<OB>;
|
|
20
|
-
}) => Promise<z.infer<OB>>;
|
|
21
|
-
onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
22
|
-
byCreator?: boolean;
|
|
23
|
-
}
|
|
3
|
+
import { ZodSchema } from "zod";
|
|
4
|
+
import { type PutOperationOptions as CorePutOperationOptions } from "../../route-operation/operation-core.js";
|
|
5
|
+
export type PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends SQLiteTable> = CorePutOperationOptions<IB, OB, TTable>;
|
|
24
6
|
export declare const createPutOperation: ({ getSession, db, }: {
|
|
25
|
-
getSession
|
|
7
|
+
getSession(req: NextRequest): Promise<{
|
|
26
8
|
userId?: string;
|
|
27
9
|
} | undefined>;
|
|
28
|
-
db?:
|
|
29
|
-
}) => <IB extends
|
|
30
|
-
export {};
|
|
10
|
+
db?: unknown;
|
|
11
|
+
}) => <IB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, OB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, openApiOperation, table, setBody, handler, catch: catchHandler, }: CorePutOperationOptions<IB, OB, SQLiteTable<import("drizzle-orm/sqlite-core").TableConfig>>) => import("next-rest-framework").RouteOperationDefinition<"PUT">;
|
|
@@ -1,160 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
9
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
10
|
-
import { z } from "zod";
|
|
11
|
-
import { routeOperation, TypedNextResponse } from "next-rest-framework";
|
|
1
|
+
import { createPutAction } from "../actions/create-put-action.js";
|
|
2
|
+
import { createPutOperationFactory } from "../../route-operation/operation-core.js";
|
|
12
3
|
import getTableName from "./get-table-name.js";
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
var createOperation = createPutOperationFactory({
|
|
5
|
+
createAction: createPutAction,
|
|
6
|
+
getTableName: getTableName
|
|
7
|
+
});
|
|
15
8
|
export var createPutOperation = function createPutOperation(_ref) {
|
|
16
9
|
var getSession = _ref.getSession,
|
|
17
10
|
db = _ref.db;
|
|
18
|
-
return
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
table = _ref2.table,
|
|
23
|
-
summary = _ref2.summary,
|
|
24
|
-
tags = _ref2.tags,
|
|
25
|
-
setBody = _ref2.setBody,
|
|
26
|
-
onSuccess = _ref2.onSuccess,
|
|
27
|
-
_ref2$byCreator = _ref2.byCreator,
|
|
28
|
-
byCreator = _ref2$byCreator === void 0 ? true : _ref2$byCreator,
|
|
29
|
-
onError = _ref2.onError;
|
|
30
|
-
return routeOperation({
|
|
31
|
-
method: "PUT",
|
|
32
|
-
openApiOperation: {
|
|
33
|
-
description: description,
|
|
34
|
-
summary: summary,
|
|
35
|
-
tags: tags !== null && tags !== void 0 ? tags : table ? [getTableName(table)] : []
|
|
36
|
-
}
|
|
37
|
-
}).input({
|
|
38
|
-
body: bodySchema,
|
|
39
|
-
contentType: "application/json"
|
|
40
|
-
}).outputs([{
|
|
41
|
-
body: outputBodySchema || z.void(),
|
|
42
|
-
status: 200,
|
|
43
|
-
contentType: "application/json"
|
|
44
|
-
}]).handler( /*#__PURE__*/function () {
|
|
45
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
|
|
46
|
-
var _ref4, userId, body, extraBody, mergedBody, params, raw, data, response;
|
|
47
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
48
|
-
while (1) switch (_context.prev = _context.next) {
|
|
49
|
-
case 0:
|
|
50
|
-
_context.prev = 0;
|
|
51
|
-
_context.next = 3;
|
|
52
|
-
return getSession(req);
|
|
53
|
-
case 3:
|
|
54
|
-
_context.t0 = _context.sent;
|
|
55
|
-
if (_context.t0) {
|
|
56
|
-
_context.next = 6;
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
_context.t0 = {};
|
|
60
|
-
case 6:
|
|
61
|
-
_ref4 = _context.t0;
|
|
62
|
-
userId = _ref4.userId;
|
|
63
|
-
_context.next = 10;
|
|
64
|
-
return req.json();
|
|
65
|
-
case 10:
|
|
66
|
-
body = _context.sent;
|
|
67
|
-
_context.next = 13;
|
|
68
|
-
return setBody === null || setBody === void 0 ? void 0 : setBody(req);
|
|
69
|
-
case 13:
|
|
70
|
-
_context.t1 = _context.sent;
|
|
71
|
-
if (_context.t1) {
|
|
72
|
-
_context.next = 16;
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
_context.t1 = {};
|
|
76
|
-
case 16:
|
|
77
|
-
extraBody = _context.t1;
|
|
78
|
-
mergedBody = _objectSpread(_objectSpread({}, body), extraBody);
|
|
79
|
-
params = _objectSpread({
|
|
80
|
-
editorId: userId
|
|
81
|
-
}, mergedBody);
|
|
82
|
-
if (!(table && db)) {
|
|
83
|
-
_context.next = 25;
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
_context.next = 22;
|
|
87
|
-
return createPutAction({
|
|
88
|
-
bodySchema: bodySchema,
|
|
89
|
-
table: table,
|
|
90
|
-
db: db
|
|
91
|
-
})(params, {
|
|
92
|
-
byCreator: byCreator
|
|
93
|
-
});
|
|
94
|
-
case 22:
|
|
95
|
-
_context.t2 = _context.sent;
|
|
96
|
-
_context.next = 26;
|
|
97
|
-
break;
|
|
98
|
-
case 25:
|
|
99
|
-
_context.t2 = params;
|
|
100
|
-
case 26:
|
|
101
|
-
raw = _context.t2;
|
|
102
|
-
if (!onSuccess) {
|
|
103
|
-
_context.next = 33;
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
_context.next = 30;
|
|
107
|
-
return onSuccess({
|
|
108
|
-
data: raw,
|
|
109
|
-
params: params
|
|
110
|
-
});
|
|
111
|
-
case 30:
|
|
112
|
-
_context.t3 = _context.sent;
|
|
113
|
-
_context.next = 34;
|
|
114
|
-
break;
|
|
115
|
-
case 33:
|
|
116
|
-
_context.t3 = raw;
|
|
117
|
-
case 34:
|
|
118
|
-
data = _context.t3;
|
|
119
|
-
return _context.abrupt("return", TypedNextResponse.json(data, {
|
|
120
|
-
status: 200
|
|
121
|
-
}));
|
|
122
|
-
case 38:
|
|
123
|
-
_context.prev = 38;
|
|
124
|
-
_context.t4 = _context["catch"](0);
|
|
125
|
-
if (!(_context.t4 instanceof HttpError)) {
|
|
126
|
-
console.error(_context.t4);
|
|
127
|
-
}
|
|
128
|
-
_context.next = 43;
|
|
129
|
-
return onError === null || onError === void 0 ? void 0 : onError(_context.t4);
|
|
130
|
-
case 43:
|
|
131
|
-
response = _context.sent;
|
|
132
|
-
if (!response) {
|
|
133
|
-
_context.next = 46;
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
return _context.abrupt("return", response);
|
|
137
|
-
case 46:
|
|
138
|
-
if (!(_context.t4 instanceof HttpError)) {
|
|
139
|
-
_context.next = 48;
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
return _context.abrupt("return", TypedNextResponse.json({
|
|
143
|
-
message: _context.t4.message
|
|
144
|
-
}, {
|
|
145
|
-
status: _context.t4.status
|
|
146
|
-
}));
|
|
147
|
-
case 48:
|
|
148
|
-
throw _context.t4;
|
|
149
|
-
case 49:
|
|
150
|
-
case "end":
|
|
151
|
-
return _context.stop();
|
|
152
|
-
}
|
|
153
|
-
}, _callee, null, [[0, 38]]);
|
|
154
|
-
}));
|
|
155
|
-
return function (_x) {
|
|
156
|
-
return _ref3.apply(this, arguments);
|
|
157
|
-
};
|
|
158
|
-
}());
|
|
159
|
-
};
|
|
11
|
+
return createOperation({
|
|
12
|
+
db: db,
|
|
13
|
+
getSession: getSession
|
|
14
|
+
});
|
|
160
15
|
};
|
|
@@ -42,12 +42,76 @@ export declare const BASIC_UPDATE_OMIT: {
|
|
|
42
42
|
readonly createdAt: true;
|
|
43
43
|
readonly updatedAt: true;
|
|
44
44
|
};
|
|
45
|
-
export declare const queryListSchema: (schema:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
export declare const queryListSchema: <Incoming extends z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>(schema: Incoming) => z.ZodObject<(("creatorId" | "orderBy" | "orderDir" | "pageSize" | "current" | "createdAtFrom" | "createdAtTo") & keyof Incoming["shape"] extends never ? {
|
|
46
|
+
current: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
47
|
+
pageSize: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
48
|
+
createdAtFrom: z.ZodOptional<z.ZodString>;
|
|
49
|
+
createdAtTo: z.ZodOptional<z.ZodString>;
|
|
50
|
+
orderBy: z.ZodOptional<z.ZodString>;
|
|
51
|
+
creatorId: z.ZodOptional<z.ZodString>;
|
|
52
|
+
orderDir: z.ZodOptional<z.ZodEnum<{
|
|
53
|
+
asc: "asc";
|
|
54
|
+
desc: "desc";
|
|
55
|
+
}>>;
|
|
56
|
+
} & Incoming["shape"] : ({
|
|
57
|
+
current: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
58
|
+
pageSize: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
59
|
+
createdAtFrom: z.ZodOptional<z.ZodString>;
|
|
60
|
+
createdAtTo: z.ZodOptional<z.ZodString>;
|
|
61
|
+
orderBy: z.ZodOptional<z.ZodString>;
|
|
62
|
+
creatorId: z.ZodOptional<z.ZodString>;
|
|
63
|
+
orderDir: z.ZodOptional<z.ZodEnum<{
|
|
64
|
+
asc: "asc";
|
|
65
|
+
desc: "desc";
|
|
66
|
+
}>>;
|
|
67
|
+
} extends infer T_1 extends z.core.util.SomeObject ? { [K in keyof T_1 as K extends keyof Incoming["shape"] ? never : K]: {
|
|
68
|
+
current: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
69
|
+
pageSize: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
70
|
+
createdAtFrom: z.ZodOptional<z.ZodString>;
|
|
71
|
+
createdAtTo: z.ZodOptional<z.ZodString>;
|
|
72
|
+
orderBy: z.ZodOptional<z.ZodString>;
|
|
73
|
+
creatorId: z.ZodOptional<z.ZodString>;
|
|
74
|
+
orderDir: z.ZodOptional<z.ZodEnum<{
|
|
75
|
+
asc: "asc";
|
|
76
|
+
desc: "desc";
|
|
77
|
+
}>>;
|
|
78
|
+
}[K]; } : never) & (Incoming["shape"] extends infer T_2 extends z.core.util.SomeObject ? { [K_1 in keyof T_2]: Incoming["shape"][K_1]; } : never)) extends infer T ? { [k in keyof T]: (("creatorId" | "orderBy" | "orderDir" | "pageSize" | "current" | "createdAtFrom" | "createdAtTo") & keyof Incoming["shape"] extends never ? {
|
|
79
|
+
current: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
80
|
+
pageSize: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
81
|
+
createdAtFrom: z.ZodOptional<z.ZodString>;
|
|
82
|
+
createdAtTo: z.ZodOptional<z.ZodString>;
|
|
83
|
+
orderBy: z.ZodOptional<z.ZodString>;
|
|
84
|
+
creatorId: z.ZodOptional<z.ZodString>;
|
|
85
|
+
orderDir: z.ZodOptional<z.ZodEnum<{
|
|
86
|
+
asc: "asc";
|
|
87
|
+
desc: "desc";
|
|
88
|
+
}>>;
|
|
89
|
+
} & Incoming["shape"] : ({
|
|
90
|
+
current: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
91
|
+
pageSize: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
92
|
+
createdAtFrom: z.ZodOptional<z.ZodString>;
|
|
93
|
+
createdAtTo: z.ZodOptional<z.ZodString>;
|
|
94
|
+
orderBy: z.ZodOptional<z.ZodString>;
|
|
95
|
+
creatorId: z.ZodOptional<z.ZodString>;
|
|
96
|
+
orderDir: z.ZodOptional<z.ZodEnum<{
|
|
97
|
+
asc: "asc";
|
|
98
|
+
desc: "desc";
|
|
99
|
+
}>>;
|
|
100
|
+
} extends infer T_1 extends z.core.util.SomeObject ? { [K in keyof T_1 as K extends keyof Incoming["shape"] ? never : K]: {
|
|
101
|
+
current: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
102
|
+
pageSize: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
103
|
+
createdAtFrom: z.ZodOptional<z.ZodString>;
|
|
104
|
+
createdAtTo: z.ZodOptional<z.ZodString>;
|
|
105
|
+
orderBy: z.ZodOptional<z.ZodString>;
|
|
106
|
+
creatorId: z.ZodOptional<z.ZodString>;
|
|
107
|
+
orderDir: z.ZodOptional<z.ZodEnum<{
|
|
108
|
+
asc: "asc";
|
|
109
|
+
desc: "desc";
|
|
110
|
+
}>>;
|
|
111
|
+
}[K]; } : never) & (Incoming["shape"] extends infer T_2 extends z.core.util.SomeObject ? { [K_1 in keyof T_2]: Incoming["shape"][K_1]; } : never))[k]; } : never, Incoming["_zod"]["config"]>;
|
|
112
|
+
export declare const listBodySchema: <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>(schema: T) => z.ZodObject<{
|
|
49
113
|
total: z.ZodNumber;
|
|
50
|
-
data: z.ZodArray<
|
|
114
|
+
data: z.ZodArray<T>;
|
|
51
115
|
}, z.core.$strip>;
|
|
52
116
|
/**
|
|
53
117
|
* 基于 drizzle + drizzle-zod 快速生成带基础字段(id / 创建时间等)的
|
|
@@ -4,7 +4,6 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
4
4
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
6
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
-
/* eslint-disable no-unused-vars */
|
|
8
7
|
import { z } from "zod";
|
|
9
8
|
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
10
9
|
import { createInsertSchema, createSelectSchema, createUpdateSchema } from "drizzle-zod";
|
|
@@ -23,7 +23,9 @@ declare module "next-rest-framework" {
|
|
|
23
23
|
export const routeOperation: <M extends string>(opts: {
|
|
24
24
|
method: M;
|
|
25
25
|
openApiOperation?: {
|
|
26
|
+
deprecated?: boolean;
|
|
26
27
|
description?: string;
|
|
28
|
+
security?: unknown[];
|
|
27
29
|
summary?: string;
|
|
28
30
|
tags?: string[];
|
|
29
31
|
};
|
|
@@ -1,25 +1,14 @@
|
|
|
1
|
-
import { TypedNextResponse } from "next-rest-framework";
|
|
2
|
-
import { BaseTable } from "../types.js";
|
|
3
1
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
4
2
|
import { NextRequest } from "next/server";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
tags?: string[];
|
|
10
|
-
onSuccess?: (payload: {
|
|
11
|
-
params: {
|
|
12
|
-
id: string;
|
|
13
|
-
creatorId?: string;
|
|
14
|
-
};
|
|
15
|
-
data: unknown;
|
|
16
|
-
}) => Promise<void>;
|
|
17
|
-
onError?(error: Error): Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
18
|
-
byCreator?: boolean;
|
|
19
|
-
}
|
|
3
|
+
import { ZodSchema } from "zod";
|
|
4
|
+
import { BaseTable } from "../types.js";
|
|
5
|
+
import { type DeleteOperationOptions as CoreDeleteOperationOptions } from "./operation-core.js";
|
|
6
|
+
export type DeleteOperationOptions<TTable extends BaseTable, B extends ZodSchema> = CoreDeleteOperationOptions<TTable, B>;
|
|
20
7
|
export declare const createDeleteOperation: ({ db, getSession, }: {
|
|
21
8
|
db?: NodePgDatabase<Record<string, unknown>> | undefined;
|
|
22
9
|
getSession(req: NextRequest): Promise<{
|
|
23
10
|
userId?: string;
|
|
24
11
|
} | undefined>;
|
|
25
|
-
}) => <
|
|
12
|
+
}) => <B extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>> = import("zod").ZodObject<{
|
|
13
|
+
id: import("zod").ZodString;
|
|
14
|
+
}, import("zod/v4/core").$strip>>({ table, schemas, access, openApiOperation, handler, catch: catchHandler, }: CoreDeleteOperationOptions<BaseTable, B>) => import("next-rest-framework").RouteOperationDefinition<"DELETE">;
|