@ai0x0/utils 0.0.18 → 0.0.21
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/SKILL.md +13 -4
- package/es/backend/actions/create-delete-action.js +2 -1
- package/es/backend/actions/create-put-action.js +2 -1
- package/es/backend/errors.d.ts +4 -0
- package/es/backend/errors.js +31 -0
- package/es/backend/index.d.ts +1 -0
- package/es/backend/index.js +2 -1
- package/es/backend/route-operation/delete-operation.js +12 -1
- package/es/backend/route-operation/put-operation.js +12 -1
- package/es/backend/schemas/index.d.ts +17127 -30
- package/es/backend/schemas/index.js +66 -19
- package/lib/backend/actions/create-delete-action.js +2 -1
- package/lib/backend/actions/create-put-action.js +2 -1
- package/lib/backend/errors.d.ts +4 -0
- package/lib/backend/errors.js +35 -0
- package/lib/backend/index.d.ts +1 -0
- package/lib/backend/index.js +3 -1
- package/lib/backend/route-operation/delete-operation.js +7 -2
- package/lib/backend/route-operation/put-operation.js +7 -2
- package/lib/backend/schemas/index.d.ts +17127 -30
- package/lib/backend/schemas/index.js +35 -26
- package/package.json +1 -1
package/SKILL.md
CHANGED
|
@@ -97,14 +97,18 @@ export const { table: agents } = createTableSchema({
|
|
|
97
97
|
|
|
98
98
|
```ts
|
|
99
99
|
// app/(backend)/db/schemas/agent/index.ts
|
|
100
|
-
import {
|
|
100
|
+
import { createSelectSchema } from "drizzle-zod";
|
|
101
101
|
import { z } from "zod";
|
|
102
|
-
import {
|
|
102
|
+
import {
|
|
103
|
+
createInsertBodySchema,
|
|
104
|
+
createUpdateBodySchema,
|
|
105
|
+
queryListSchema,
|
|
106
|
+
} from "@backend/db/schemas";
|
|
103
107
|
import { agents } from "./table";
|
|
104
108
|
|
|
105
109
|
export { agents, agentColumns } from "./table";
|
|
106
110
|
|
|
107
|
-
export const insertAgentSchema =
|
|
111
|
+
export const insertAgentSchema = createInsertBodySchema(agents).merge(
|
|
108
112
|
z.object({
|
|
109
113
|
mcpIds: z.array(z.string()).optional(),
|
|
110
114
|
tags: z.array(z.string()).optional(),
|
|
@@ -116,7 +120,12 @@ export const selectAgentSchema = createSelectSchema(agents).merge(
|
|
|
116
120
|
tags: z.array(z.string()).optional(),
|
|
117
121
|
}),
|
|
118
122
|
);
|
|
119
|
-
export const updateAgentSchema =
|
|
123
|
+
export const updateAgentSchema = createUpdateBodySchema(agents).merge(
|
|
124
|
+
z.object({
|
|
125
|
+
mcpIds: z.array(z.string()).optional(),
|
|
126
|
+
tags: z.array(z.string()).optional(),
|
|
127
|
+
}),
|
|
128
|
+
);
|
|
120
129
|
export const queryAgentSchema = insertAgentSchema.partial();
|
|
121
130
|
export const queryListAgentSchema = queryListSchema(
|
|
122
131
|
selectAgentSchema.partial().merge(
|
|
@@ -5,6 +5,7 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
|
|
|
5
5
|
import { eq } from "drizzle-orm";
|
|
6
6
|
import { createGetAction } from "./..";
|
|
7
7
|
import { z } from "zod";
|
|
8
|
+
import { HttpError } from "../errors";
|
|
8
9
|
export function createDeleteAction(_ref) {
|
|
9
10
|
var table = _ref.table,
|
|
10
11
|
db = _ref.db;
|
|
@@ -37,7 +38,7 @@ export function createDeleteAction(_ref) {
|
|
|
37
38
|
_context.next = 7;
|
|
38
39
|
break;
|
|
39
40
|
}
|
|
40
|
-
throw
|
|
41
|
+
throw new HttpError(404, "未找到删除对象,或没有权限");
|
|
41
42
|
case 7:
|
|
42
43
|
return _context.abrupt("return", db.delete(table).where(eq(table.id, id)).returning());
|
|
43
44
|
case 8:
|
|
@@ -12,6 +12,7 @@ import { z } from "zod";
|
|
|
12
12
|
import { transformBody } from "./transform-body";
|
|
13
13
|
import { eq } from "drizzle-orm";
|
|
14
14
|
import { createGetAction } from "./..";
|
|
15
|
+
import { HttpError } from "../errors";
|
|
15
16
|
export function createPutAction(_ref) {
|
|
16
17
|
var db = _ref.db,
|
|
17
18
|
table = _ref.table;
|
|
@@ -51,7 +52,7 @@ export function createPutAction(_ref) {
|
|
|
51
52
|
_context.next = 7;
|
|
52
53
|
break;
|
|
53
54
|
}
|
|
54
|
-
throw
|
|
55
|
+
throw new HttpError(404, "未找到编辑对象,或没有权限");
|
|
55
56
|
case 7:
|
|
56
57
|
_context.next = 9;
|
|
57
58
|
return db.update(table).set(transformBody(body)).where(eq(table.id, body.id)).returning();
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
3
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
4
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
6
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
7
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
8
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
9
|
+
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
|
|
10
|
+
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
11
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
12
|
+
function _isNativeFunction(fn) { try { return Function.toString.call(fn).indexOf("[native code]") !== -1; } catch (e) { return typeof fn === "function"; } }
|
|
13
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
14
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
15
|
+
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; }
|
|
16
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
17
|
+
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); }
|
|
18
|
+
export var HttpError = /*#__PURE__*/function (_Error) {
|
|
19
|
+
_inherits(HttpError, _Error);
|
|
20
|
+
var _super = _createSuper(HttpError);
|
|
21
|
+
function HttpError(status, message) {
|
|
22
|
+
var _this;
|
|
23
|
+
_classCallCheck(this, HttpError);
|
|
24
|
+
_this = _super.call(this, message);
|
|
25
|
+
_defineProperty(_assertThisInitialized(_this), "status", void 0);
|
|
26
|
+
_this.name = "HttpError";
|
|
27
|
+
_this.status = status;
|
|
28
|
+
return _this;
|
|
29
|
+
}
|
|
30
|
+
return _createClass(HttpError);
|
|
31
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
package/es/backend/index.d.ts
CHANGED
package/es/backend/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { routeOperation, TypedNextResponse } from "next-rest-framework";
|
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import getTableName from "./get-table-name";
|
|
8
8
|
import { createDeleteAction } from "../actions";
|
|
9
|
+
import { HttpError } from "../errors";
|
|
9
10
|
export var createDeleteOperation = function createDeleteOperation(_ref) {
|
|
10
11
|
var db = _ref.db,
|
|
11
12
|
getSession = _ref.getSession;
|
|
@@ -77,10 +78,20 @@ export var createDeleteOperation = function createDeleteOperation(_ref) {
|
|
|
77
78
|
case 25:
|
|
78
79
|
response = _context.sent;
|
|
79
80
|
if (!response) {
|
|
80
|
-
_context.next =
|
|
81
|
+
_context.next = 28;
|
|
81
82
|
break;
|
|
82
83
|
}
|
|
83
84
|
return _context.abrupt("return", response);
|
|
85
|
+
case 28:
|
|
86
|
+
if (!(_context.t1 instanceof HttpError)) {
|
|
87
|
+
_context.next = 30;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
return _context.abrupt("return", TypedNextResponse.json({
|
|
91
|
+
message: _context.t1.message
|
|
92
|
+
}, {
|
|
93
|
+
status: _context.t1.status
|
|
94
|
+
}));
|
|
84
95
|
case 30:
|
|
85
96
|
throw _context.t1;
|
|
86
97
|
case 31:
|
|
@@ -11,6 +11,7 @@ import { z } from "zod";
|
|
|
11
11
|
import { routeOperation, TypedNextResponse } from "next-rest-framework";
|
|
12
12
|
import getTableName from "./get-table-name";
|
|
13
13
|
import { createPutAction } from "../actions";
|
|
14
|
+
import { HttpError } from "../errors";
|
|
14
15
|
export var createPutOperation = function createPutOperation(_ref) {
|
|
15
16
|
var getSession = _ref.getSession,
|
|
16
17
|
db = _ref.db;
|
|
@@ -110,10 +111,20 @@ export var createPutOperation = function createPutOperation(_ref) {
|
|
|
110
111
|
case 37:
|
|
111
112
|
response = _context.sent;
|
|
112
113
|
if (!response) {
|
|
113
|
-
_context.next =
|
|
114
|
+
_context.next = 40;
|
|
114
115
|
break;
|
|
115
116
|
}
|
|
116
117
|
return _context.abrupt("return", response);
|
|
118
|
+
case 40:
|
|
119
|
+
if (!(_context.t6 instanceof HttpError)) {
|
|
120
|
+
_context.next = 42;
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
return _context.abrupt("return", TypedNextResponse.json({
|
|
124
|
+
message: _context.t6.message
|
|
125
|
+
}, {
|
|
126
|
+
status: _context.t6.status
|
|
127
|
+
}));
|
|
117
128
|
case 42:
|
|
118
129
|
throw _context.t6;
|
|
119
130
|
case 43:
|