@ai0x0/utils 0.0.37 → 0.0.39
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 +12 -8
- package/README.md +42 -1
- package/SKILL.md +12 -8
- package/es/backend/route-operation/delete-operation.d.ts +3 -2
- package/es/backend/route-operation/delete-operation.js +35 -22
- package/es/backend/route-operation/get-list-operation.d.ts +6 -5
- package/es/backend/route-operation/get-list-operation.js +37 -22
- package/es/backend/route-operation/get-operation.d.ts +5 -4
- package/es/backend/route-operation/get-operation.js +34 -22
- package/es/backend/route-operation/post-operation.d.ts +5 -4
- package/es/backend/route-operation/post-operation.js +39 -34
- package/es/backend/route-operation/put-operation.d.ts +5 -4
- package/es/backend/route-operation/put-operation.js +44 -29
- package/es/backend/sqlite/actions/create-delete-action.d.ts +8 -0
- package/es/backend/sqlite/actions/create-delete-action.js +54 -0
- package/es/backend/sqlite/actions/create-get-action.d.ts +8 -0
- package/es/backend/sqlite/actions/create-get-action.js +64 -0
- package/es/backend/sqlite/actions/create-get-list-action.d.ts +11 -0
- package/es/backend/sqlite/actions/create-get-list-action.js +56 -0
- package/es/backend/sqlite/actions/create-post-action.d.ts +6 -0
- package/es/backend/sqlite/actions/create-post-action.js +31 -0
- package/es/backend/sqlite/actions/create-put-action.d.ts +8 -0
- package/es/backend/sqlite/actions/create-put-action.js +74 -0
- package/es/backend/sqlite/actions/get-list-data.d.ts +9 -0
- package/es/backend/sqlite/actions/get-list-data.js +75 -0
- package/es/backend/sqlite/actions/get-list-query.d.ts +19 -0
- package/es/backend/sqlite/actions/get-list-query.js +215 -0
- package/es/backend/sqlite/actions/index.d.ts +6 -0
- package/es/backend/sqlite/actions/index.js +6 -0
- package/es/backend/sqlite/actions/transform-body.d.ts +1 -0
- package/es/backend/sqlite/actions/transform-body.js +9 -0
- package/es/backend/sqlite/errors.d.ts +4 -0
- package/es/backend/sqlite/errors.js +31 -0
- package/es/backend/sqlite/index.d.ts +5 -0
- package/es/backend/sqlite/index.js +5 -0
- package/es/backend/sqlite/route-operation/delete-operation.d.ts +11 -0
- package/es/backend/sqlite/route-operation/delete-operation.js +122 -0
- package/es/backend/sqlite/route-operation/get-list-operation.d.ts +23 -0
- package/es/backend/sqlite/route-operation/get-list-operation.js +135 -0
- package/es/backend/sqlite/route-operation/get-operation.d.ts +17 -0
- package/es/backend/sqlite/route-operation/get-operation.js +132 -0
- package/es/backend/sqlite/route-operation/get-table-name.d.ts +3 -0
- package/es/backend/sqlite/route-operation/get-table-name.js +11 -0
- package/es/backend/sqlite/route-operation/index.d.ts +5 -0
- package/es/backend/sqlite/route-operation/index.js +5 -0
- package/es/backend/sqlite/route-operation/post-operation.d.ts +14 -0
- package/es/backend/sqlite/route-operation/post-operation.js +141 -0
- package/es/backend/sqlite/route-operation/put-operation.d.ts +15 -0
- package/es/backend/sqlite/route-operation/put-operation.js +156 -0
- package/es/backend/sqlite/schemas/index.d.ts +68 -0
- package/es/backend/sqlite/schemas/index.js +133 -0
- package/es/backend/sqlite/types.d.ts +16 -0
- package/es/backend/sqlite/types.js +1 -0
- package/lib/backend/route-operation/delete-operation.d.ts +3 -2
- package/lib/backend/route-operation/delete-operation.js +5 -3
- package/lib/backend/route-operation/get-list-operation.d.ts +6 -5
- package/lib/backend/route-operation/get-list-operation.js +8 -8
- package/lib/backend/route-operation/get-operation.d.ts +5 -4
- package/lib/backend/route-operation/get-operation.js +8 -8
- package/lib/backend/route-operation/post-operation.d.ts +5 -4
- package/lib/backend/route-operation/post-operation.js +4 -3
- package/lib/backend/route-operation/put-operation.d.ts +5 -4
- package/lib/backend/route-operation/put-operation.js +6 -4
- package/lib/backend/sqlite/actions/create-delete-action.d.ts +8 -0
- package/lib/backend/sqlite/actions/create-delete-action.js +53 -0
- package/lib/backend/sqlite/actions/create-get-action.d.ts +8 -0
- package/lib/backend/sqlite/actions/create-get-action.js +65 -0
- package/lib/backend/sqlite/actions/create-get-list-action.d.ts +11 -0
- package/lib/backend/sqlite/actions/create-get-list-action.js +63 -0
- package/lib/backend/sqlite/actions/create-post-action.d.ts +6 -0
- package/lib/backend/sqlite/actions/create-post-action.js +39 -0
- package/lib/backend/sqlite/actions/create-put-action.d.ts +8 -0
- package/lib/backend/sqlite/actions/create-put-action.js +60 -0
- package/lib/backend/sqlite/actions/get-list-data.d.ts +9 -0
- package/lib/backend/sqlite/actions/get-list-data.js +51 -0
- package/lib/backend/sqlite/actions/get-list-query.d.ts +19 -0
- package/lib/backend/sqlite/actions/get-list-query.js +165 -0
- package/lib/backend/sqlite/actions/index.d.ts +6 -0
- package/lib/backend/sqlite/actions/index.js +44 -0
- package/lib/backend/sqlite/actions/transform-body.d.ts +1 -0
- package/lib/backend/sqlite/actions/transform-body.js +49 -0
- package/lib/backend/sqlite/errors.d.ts +4 -0
- package/lib/backend/sqlite/errors.js +35 -0
- package/lib/backend/sqlite/index.d.ts +5 -0
- package/lib/backend/sqlite/index.js +31 -0
- package/lib/backend/sqlite/route-operation/delete-operation.d.ts +11 -0
- package/lib/backend/sqlite/route-operation/delete-operation.js +92 -0
- package/lib/backend/sqlite/route-operation/get-list-operation.d.ts +23 -0
- package/lib/backend/sqlite/route-operation/get-list-operation.js +108 -0
- package/lib/backend/sqlite/route-operation/get-operation.d.ts +17 -0
- package/lib/backend/sqlite/route-operation/get-operation.js +107 -0
- package/lib/backend/sqlite/route-operation/get-table-name.d.ts +3 -0
- package/lib/backend/sqlite/route-operation/get-table-name.js +35 -0
- package/lib/backend/sqlite/route-operation/index.d.ts +5 -0
- package/lib/backend/sqlite/route-operation/index.js +31 -0
- package/lib/backend/sqlite/route-operation/post-operation.d.ts +14 -0
- package/lib/backend/sqlite/route-operation/post-operation.js +95 -0
- package/lib/backend/sqlite/route-operation/put-operation.d.ts +15 -0
- package/lib/backend/sqlite/route-operation/put-operation.js +104 -0
- package/lib/backend/sqlite/schemas/index.d.ts +68 -0
- package/lib/backend/sqlite/schemas/index.js +113 -0
- package/lib/backend/sqlite/types.d.ts +16 -0
- package/lib/backend/sqlite/types.js +17 -0
- package/package.json +3 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseTable } from "../types.js";
|
|
2
|
+
export declare function createPutAction<TTable extends BaseTable>({ db, table, }: {
|
|
3
|
+
bodySchema: any;
|
|
4
|
+
db: any;
|
|
5
|
+
table: TTable;
|
|
6
|
+
}): (body: Record<string, unknown>, { byCreator, }?: {
|
|
7
|
+
byCreator?: boolean | undefined;
|
|
8
|
+
}) => Promise<any>;
|
|
@@ -0,0 +1,74 @@
|
|
|
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 _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
7
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
8
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
9
|
+
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); } }
|
|
10
|
+
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); }); }; }
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { transformBody } from "./transform-body.js";
|
|
13
|
+
import { eq } from "drizzle-orm";
|
|
14
|
+
import { createGetAction } from "./../index.js";
|
|
15
|
+
import { HttpError } from "../errors.js";
|
|
16
|
+
export function createPutAction(_ref) {
|
|
17
|
+
var db = _ref.db,
|
|
18
|
+
table = _ref.table;
|
|
19
|
+
return /*#__PURE__*/function () {
|
|
20
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(body) {
|
|
21
|
+
var _ref3,
|
|
22
|
+
_ref3$byCreator,
|
|
23
|
+
byCreator,
|
|
24
|
+
_data,
|
|
25
|
+
_yield$db$update$set$,
|
|
26
|
+
_yield$db$update$set$2,
|
|
27
|
+
data,
|
|
28
|
+
_args = arguments;
|
|
29
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
30
|
+
while (1) switch (_context.prev = _context.next) {
|
|
31
|
+
case 0:
|
|
32
|
+
_ref3 = _args.length > 1 && _args[1] !== undefined ? _args[1] : {}, _ref3$byCreator = _ref3.byCreator, byCreator = _ref3$byCreator === void 0 ? true : _ref3$byCreator;
|
|
33
|
+
if (!byCreator) {
|
|
34
|
+
_context.next = 7;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
_context.next = 4;
|
|
38
|
+
return createGetAction({
|
|
39
|
+
db: db,
|
|
40
|
+
table: table,
|
|
41
|
+
bodySchema: z.object({
|
|
42
|
+
creatorId: z.string(),
|
|
43
|
+
id: z.string()
|
|
44
|
+
})
|
|
45
|
+
})({
|
|
46
|
+
creatorId: body.editorId,
|
|
47
|
+
id: body.id
|
|
48
|
+
});
|
|
49
|
+
case 4:
|
|
50
|
+
_data = _context.sent;
|
|
51
|
+
if (_data) {
|
|
52
|
+
_context.next = 7;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
throw new HttpError(404, "未找到编辑对象,或没有权限");
|
|
56
|
+
case 7:
|
|
57
|
+
_context.next = 9;
|
|
58
|
+
return db.update(table).set(transformBody(body)).where(eq(table.id, body.id)).returning();
|
|
59
|
+
case 9:
|
|
60
|
+
_yield$db$update$set$ = _context.sent;
|
|
61
|
+
_yield$db$update$set$2 = _slicedToArray(_yield$db$update$set$, 1);
|
|
62
|
+
data = _yield$db$update$set$2[0];
|
|
63
|
+
return _context.abrupt("return", data);
|
|
64
|
+
case 13:
|
|
65
|
+
case "end":
|
|
66
|
+
return _context.stop();
|
|
67
|
+
}
|
|
68
|
+
}, _callee);
|
|
69
|
+
}));
|
|
70
|
+
return function (_x) {
|
|
71
|
+
return _ref2.apply(this, arguments);
|
|
72
|
+
};
|
|
73
|
+
}();
|
|
74
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getListQuery } from "./get-list-query.js";
|
|
2
|
+
export declare function getListData({ query, countQuery, pageSize, current, }: {
|
|
3
|
+
bodySchema?: any;
|
|
4
|
+
current?: number;
|
|
5
|
+
pageSize?: number;
|
|
6
|
+
} & ReturnType<typeof getListQuery>): () => Promise<{
|
|
7
|
+
data: unknown[];
|
|
8
|
+
total: number;
|
|
9
|
+
}>;
|
|
@@ -0,0 +1,75 @@
|
|
|
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 _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
7
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
8
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
9
|
+
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); } }
|
|
10
|
+
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); }); }; }
|
|
11
|
+
function runSelect(_x) {
|
|
12
|
+
return _runSelect.apply(this, arguments);
|
|
13
|
+
}
|
|
14
|
+
function _runSelect() {
|
|
15
|
+
_runSelect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(query) {
|
|
16
|
+
var executable;
|
|
17
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
18
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
19
|
+
case 0:
|
|
20
|
+
executable = query;
|
|
21
|
+
if (!executable.all) {
|
|
22
|
+
_context2.next = 3;
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
return _context2.abrupt("return", executable.all());
|
|
26
|
+
case 3:
|
|
27
|
+
if (!executable.execute) {
|
|
28
|
+
_context2.next = 5;
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
return _context2.abrupt("return", executable.execute());
|
|
32
|
+
case 5:
|
|
33
|
+
return _context2.abrupt("return", []);
|
|
34
|
+
case 6:
|
|
35
|
+
case "end":
|
|
36
|
+
return _context2.stop();
|
|
37
|
+
}
|
|
38
|
+
}, _callee2);
|
|
39
|
+
}));
|
|
40
|
+
return _runSelect.apply(this, arguments);
|
|
41
|
+
}
|
|
42
|
+
export function getListData(_ref) {
|
|
43
|
+
var query = _ref.query,
|
|
44
|
+
countQuery = _ref.countQuery,
|
|
45
|
+
_ref$pageSize = _ref.pageSize,
|
|
46
|
+
pageSize = _ref$pageSize === void 0 ? 10 : _ref$pageSize,
|
|
47
|
+
_ref$current = _ref.current,
|
|
48
|
+
current = _ref$current === void 0 ? 1 : _ref$current;
|
|
49
|
+
return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
50
|
+
var dataQuery, data, _yield$runSelect, _yield$runSelect2, count;
|
|
51
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
52
|
+
while (1) switch (_context.prev = _context.next) {
|
|
53
|
+
case 0:
|
|
54
|
+
dataQuery = query.limit(+pageSize).offset((+current - 1) * +pageSize);
|
|
55
|
+
_context.next = 3;
|
|
56
|
+
return runSelect(dataQuery);
|
|
57
|
+
case 3:
|
|
58
|
+
data = _context.sent;
|
|
59
|
+
_context.next = 6;
|
|
60
|
+
return runSelect(countQuery);
|
|
61
|
+
case 6:
|
|
62
|
+
_yield$runSelect = _context.sent;
|
|
63
|
+
_yield$runSelect2 = _slicedToArray(_yield$runSelect, 1);
|
|
64
|
+
count = _yield$runSelect2[0].count;
|
|
65
|
+
return _context.abrupt("return", {
|
|
66
|
+
data: data,
|
|
67
|
+
total: Number(count)
|
|
68
|
+
});
|
|
69
|
+
case 10:
|
|
70
|
+
case "end":
|
|
71
|
+
return _context.stop();
|
|
72
|
+
}
|
|
73
|
+
}, _callee);
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BaseTable, GetListRelations } from "../types.js";
|
|
2
|
+
import { SelectedFields } from "drizzle-orm/sqlite-core/query-builders/select.types";
|
|
3
|
+
export declare function getListQuery<TTable extends BaseTable, TSelection extends SelectedFields>({ db, fields, jsonArrayFields, params, relations, table, }: {
|
|
4
|
+
db: any;
|
|
5
|
+
fields: TSelection;
|
|
6
|
+
jsonArrayFields?: string[];
|
|
7
|
+
params: {
|
|
8
|
+
[field: string]: unknown;
|
|
9
|
+
orderBy?: keyof BaseTable;
|
|
10
|
+
orderDir?: "asc" | "desc";
|
|
11
|
+
page?: number;
|
|
12
|
+
pageSize?: number;
|
|
13
|
+
};
|
|
14
|
+
relations?: GetListRelations;
|
|
15
|
+
table: TTable;
|
|
16
|
+
}): {
|
|
17
|
+
countQuery: any;
|
|
18
|
+
query: any;
|
|
19
|
+
};
|
|
@@ -0,0 +1,215 @@
|
|
|
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
|
+
var _templateObject, _templateObject2, _templateObject3;
|
|
3
|
+
var _excluded = ["page", "pageSize", "orderBy", "orderDir"];
|
|
4
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
5
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
6
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
7
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
8
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
9
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
10
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
12
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
13
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
14
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
15
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
16
|
+
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; }
|
|
17
|
+
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; }
|
|
18
|
+
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; }
|
|
19
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
20
|
+
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); }
|
|
21
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
22
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
23
|
+
import { and, asc, desc, eq, gte, like, inArray, lte, or, sql } from "drizzle-orm";
|
|
24
|
+
export function getListQuery(_ref) {
|
|
25
|
+
var db = _ref.db,
|
|
26
|
+
fields = _ref.fields,
|
|
27
|
+
jsonArrayFields = _ref.jsonArrayFields,
|
|
28
|
+
params = _ref.params,
|
|
29
|
+
relations = _ref.relations,
|
|
30
|
+
table = _ref.table;
|
|
31
|
+
var _params$page = params.page,
|
|
32
|
+
page = _params$page === void 0 ? 1 : _params$page,
|
|
33
|
+
_params$pageSize = params.pageSize,
|
|
34
|
+
pageSize = _params$pageSize === void 0 ? 10 : _params$pageSize,
|
|
35
|
+
_params$orderBy = params.orderBy,
|
|
36
|
+
orderBy = _params$orderBy === void 0 ? "createdAt" : _params$orderBy,
|
|
37
|
+
_params$orderDir = params.orderDir,
|
|
38
|
+
orderDir = _params$orderDir === void 0 ? "desc" : _params$orderDir,
|
|
39
|
+
filters = _objectWithoutProperties(params, _excluded);
|
|
40
|
+
|
|
41
|
+
// 构建基础查询
|
|
42
|
+
function buildBaseQuery(table, fields, relations) {
|
|
43
|
+
var queryFields = _objectSpread({}, fields);
|
|
44
|
+
|
|
45
|
+
// 添加关联字段
|
|
46
|
+
if (relations !== null && relations !== void 0 && relations.length) {
|
|
47
|
+
var _iterator = _createForOfIteratorHelper(relations),
|
|
48
|
+
_step;
|
|
49
|
+
try {
|
|
50
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
51
|
+
var select = _step.value.select;
|
|
52
|
+
queryFields = _objectSpread(_objectSpread({}, queryFields), select);
|
|
53
|
+
}
|
|
54
|
+
} catch (err) {
|
|
55
|
+
_iterator.e(err);
|
|
56
|
+
} finally {
|
|
57
|
+
_iterator.f();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
var query = db.select(queryFields).from(table);
|
|
61
|
+
|
|
62
|
+
// 添加分组
|
|
63
|
+
if (relations !== null && relations !== void 0 && relations.length) {
|
|
64
|
+
query.groupBy.apply(query, [table.id].concat(_toConsumableArray(relations.filter(function (_ref2) {
|
|
65
|
+
var groupBy = _ref2.groupBy;
|
|
66
|
+
return groupBy;
|
|
67
|
+
}).filter(function (_ref3) {
|
|
68
|
+
var table = _ref3.table;
|
|
69
|
+
return table;
|
|
70
|
+
}).map(function (_ref4) {
|
|
71
|
+
var table = _ref4.table;
|
|
72
|
+
return table.id;
|
|
73
|
+
}))));
|
|
74
|
+
}
|
|
75
|
+
return query;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 查找目标列
|
|
79
|
+
function findTargetColumn(key, table, relations) {
|
|
80
|
+
var _concat$find;
|
|
81
|
+
return (_concat$find = [table].concat((relations === null || relations === void 0 ? void 0 : relations.filter(function (_ref5) {
|
|
82
|
+
var table = _ref5.table;
|
|
83
|
+
return table;
|
|
84
|
+
}).map(function (_ref6) {
|
|
85
|
+
var table = _ref6.table;
|
|
86
|
+
return table;
|
|
87
|
+
})) || []).find(function (table) {
|
|
88
|
+
return table[key];
|
|
89
|
+
})) === null || _concat$find === void 0 ? void 0 : _concat$find[key];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 添加条件
|
|
93
|
+
function addCondition(conditions, key, value, targetColumn) {
|
|
94
|
+
var isIdField = /id/i.test(key);
|
|
95
|
+
var isJsonArray = jsonArrayFields === null || jsonArrayFields === void 0 ? void 0 : jsonArrayFields.includes(key);
|
|
96
|
+
if (typeof value === "string") {
|
|
97
|
+
if (value.includes(",")) {
|
|
98
|
+
// 处理多值
|
|
99
|
+
var values = value.split(",").map(function (val) {
|
|
100
|
+
return val.trim();
|
|
101
|
+
}).filter(Boolean);
|
|
102
|
+
if (values.length > 0) {
|
|
103
|
+
if (isJsonArray) {
|
|
104
|
+
// 处理 JSON 数组字段
|
|
105
|
+
conditions.push(sql(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n EXISTS (\n SELECT 1 FROM json_each(", ") tag\n WHERE tag.value LIKE ", "\n )\n "])), targetColumn, "%".concat(values[0], "%")));
|
|
106
|
+
} else if (isIdField) {
|
|
107
|
+
conditions.push(inArray(targetColumn, values));
|
|
108
|
+
} else {
|
|
109
|
+
conditions.push(or.apply(void 0, _toConsumableArray(values.map(function (val) {
|
|
110
|
+
return like(targetColumn, "%".concat(val, "%"));
|
|
111
|
+
}))));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
// 处理单值
|
|
116
|
+
if (isJsonArray) {
|
|
117
|
+
// 处理 JSON 数组字段
|
|
118
|
+
conditions.push(sql(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n EXISTS (\n SELECT 1 FROM json_each(", ") tag\n WHERE tag.value LIKE ", "\n )\n "])), targetColumn, "%".concat(value, "%")));
|
|
119
|
+
} else if (isIdField) {
|
|
120
|
+
conditions.push(eq(targetColumn, value));
|
|
121
|
+
} else {
|
|
122
|
+
conditions.push(like(targetColumn, "%".concat(value, "%")));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
conditions.push(eq(targetColumn, value));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// 构建查询条件
|
|
131
|
+
function buildConditions(filters, table, relations) {
|
|
132
|
+
var conditions = [];
|
|
133
|
+
|
|
134
|
+
// 处理过滤条件
|
|
135
|
+
for (var _i = 0, _Object$entries = Object.entries(filters); _i < _Object$entries.length; _i++) {
|
|
136
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
137
|
+
key = _Object$entries$_i[0],
|
|
138
|
+
value = _Object$entries$_i[1];
|
|
139
|
+
if (!value) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// 处理日期范围字段
|
|
144
|
+
if (key.endsWith("AtFrom") || key.endsWith("AtTo")) {
|
|
145
|
+
var baseFieldName = key.replace(/(AtFrom|AtTo)$/, "");
|
|
146
|
+
var _targetColumn = findTargetColumn("".concat(baseFieldName, "At"), table, relations);
|
|
147
|
+
if (!_targetColumn) {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (key.endsWith("AtFrom")) {
|
|
151
|
+
conditions.push(gte(_targetColumn, new Date(value)));
|
|
152
|
+
} else if (key.endsWith("AtTo")) {
|
|
153
|
+
conditions.push(lte(_targetColumn, new Date(value)));
|
|
154
|
+
}
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// 处理其他普通过滤条件
|
|
159
|
+
var targetColumn = findTargetColumn(key, table, relations);
|
|
160
|
+
if (!targetColumn) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
addCondition(conditions, key, value, targetColumn);
|
|
164
|
+
}
|
|
165
|
+
return conditions;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// 构建排序
|
|
169
|
+
function buildOrderBy(table, orderBy, orderDir) {
|
|
170
|
+
var orderColumn = table[orderBy];
|
|
171
|
+
return orderDir === "asc" ? asc(orderColumn) : desc(orderColumn);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// 构建基础查询
|
|
175
|
+
var baseQuery = buildBaseQuery(table, fields, relations);
|
|
176
|
+
|
|
177
|
+
// 构建条件
|
|
178
|
+
var conditions = buildConditions(filters, table, relations);
|
|
179
|
+
|
|
180
|
+
// 构建主查询
|
|
181
|
+
var query = baseQuery.where(conditions.length > 0 ? and.apply(void 0, _toConsumableArray(conditions)) : undefined).orderBy(buildOrderBy(table, orderBy, orderDir)).limit(pageSize).offset((page - 1) * pageSize);
|
|
182
|
+
|
|
183
|
+
// 构建计数查询(优化后)
|
|
184
|
+
var countQuery = db.select({
|
|
185
|
+
count: sql(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["COUNT(DISTINCT ", ")"])), table.id)
|
|
186
|
+
}).from(table).where(conditions.length > 0 ? and.apply(void 0, _toConsumableArray(conditions)) : undefined);
|
|
187
|
+
|
|
188
|
+
// 添加关联
|
|
189
|
+
if (relations !== null && relations !== void 0 && relations.length) {
|
|
190
|
+
var _iterator2 = _createForOfIteratorHelper(relations),
|
|
191
|
+
_step2;
|
|
192
|
+
try {
|
|
193
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
194
|
+
var _step2$value = _step2.value,
|
|
195
|
+
relationTable = _step2$value.table,
|
|
196
|
+
joinSql = _step2$value.sql;
|
|
197
|
+
if (relationTable) {
|
|
198
|
+
query.leftJoin(relationTable, joinSql);
|
|
199
|
+
countQuery.leftJoin(relationTable, joinSql);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
} catch (err) {
|
|
203
|
+
_iterator2.e(err);
|
|
204
|
+
} finally {
|
|
205
|
+
_iterator2.f();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// console.log(query.prepare("a").getQuery());
|
|
210
|
+
|
|
211
|
+
return {
|
|
212
|
+
countQuery: countQuery,
|
|
213
|
+
query: query
|
|
214
|
+
};
|
|
215
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createDeleteAction } from "./create-delete-action.js";
|
|
2
|
+
export { createGetAction } from "./create-get-action.js";
|
|
3
|
+
export { createGetListAction } from "./create-get-list-action.js";
|
|
4
|
+
export { createPostAction } from "./create-post-action.js";
|
|
5
|
+
export { createPutAction } from "./create-put-action.js";
|
|
6
|
+
export { getListQuery } from "./get-list-query.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createDeleteAction } from "./create-delete-action.js";
|
|
2
|
+
export { createGetAction } from "./create-get-action.js";
|
|
3
|
+
export { createGetListAction } from "./create-get-list-action.js";
|
|
4
|
+
export { createPostAction } from "./create-post-action.js";
|
|
5
|
+
export { createPutAction } from "./create-put-action.js";
|
|
6
|
+
export { getListQuery } from "./get-list-query.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const transformBody: <T extends Record<string, unknown>>(body: T) => T;
|
|
@@ -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));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TypedNextResponse } from "next-rest-framework";
|
|
2
|
+
import { BaseTable } from "../types.js";
|
|
3
|
+
export interface DeleteOperationOptions<TTable extends BaseTable> {
|
|
4
|
+
table?: TTable;
|
|
5
|
+
summary?: string;
|
|
6
|
+
tags?: string[];
|
|
7
|
+
onSuccess?: () => Promise<void>;
|
|
8
|
+
onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
9
|
+
byCreator?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const createDeleteOperation: any;
|