@ai0x0/utils 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/es/backend/actions/delete-action-fn.d.ts +7 -0
- package/es/backend/actions/delete-action-fn.d.ts.map +1 -0
- package/es/backend/actions/delete-action-fn.js +30 -0
- package/es/backend/actions/get-List-query.d.ts +30 -0
- package/es/backend/actions/get-List-query.d.ts.map +1 -0
- package/es/backend/actions/get-List-query.js +212 -0
- package/es/backend/actions/get-action-fn.d.ts +12 -0
- package/es/backend/actions/get-action-fn.d.ts.map +1 -0
- package/es/backend/actions/get-action-fn.js +75 -0
- package/es/backend/actions/get-list-action-fn.d.ts +12 -0
- package/es/backend/actions/get-list-action-fn.d.ts.map +1 -0
- package/es/backend/actions/get-list-action-fn.js +68 -0
- package/es/backend/actions/get-list-data.d.ts +8 -0
- package/es/backend/actions/get-list-data.d.ts.map +1 -0
- package/es/backend/actions/get-list-data.js +49 -0
- package/es/backend/actions/index.d.ts +6 -0
- package/es/backend/actions/index.d.ts.map +1 -0
- package/es/backend/actions/index.js +5 -0
- package/es/backend/actions/post-action-fn.d.ts +13 -0
- package/es/backend/actions/post-action-fn.d.ts.map +1 -0
- package/es/backend/actions/post-action-fn.js +35 -0
- package/es/backend/actions/put-action-fn.d.ts +9 -0
- package/es/backend/actions/put-action-fn.d.ts.map +1 -0
- package/es/backend/actions/put-action-fn.js +34 -0
- package/es/backend/actions/transform-body.d.ts +2 -0
- package/es/backend/actions/transform-body.d.ts.map +1 -0
- package/es/backend/actions/transform-body.js +11 -0
- package/es/backend/index.d.ts +3 -0
- package/es/backend/index.d.ts.map +1 -0
- package/es/backend/index.js +2 -0
- package/es/backend/route-operation/delete-operation.d.ts +10 -0
- package/es/backend/route-operation/delete-operation.d.ts.map +1 -0
- package/es/backend/route-operation/delete-operation.js +59 -0
- package/es/backend/route-operation/get-list-operation.d.ts +24 -0
- package/es/backend/route-operation/get-list-operation.d.ts.map +1 -0
- package/es/backend/route-operation/get-list-operation.js +83 -0
- package/es/backend/route-operation/get-operation.d.ts +17 -0
- package/es/backend/route-operation/get-operation.d.ts.map +1 -0
- package/es/backend/route-operation/get-operation.js +65 -0
- package/es/backend/route-operation/get-table-name.d.ts +4 -0
- package/es/backend/route-operation/get-table-name.d.ts.map +1 -0
- package/es/backend/route-operation/get-table-name.js +13 -0
- package/es/backend/route-operation/index.d.ts +6 -0
- package/es/backend/route-operation/index.d.ts.map +1 -0
- package/es/backend/route-operation/index.js +5 -0
- package/es/backend/route-operation/post-operation.d.ts +14 -0
- package/es/backend/route-operation/post-operation.d.ts.map +1 -0
- package/es/backend/route-operation/post-operation.js +84 -0
- package/es/backend/route-operation/put-operation.d.ts +14 -0
- package/es/backend/route-operation/put-operation.d.ts.map +1 -0
- package/es/backend/route-operation/put-operation.js +71 -0
- package/es/backend/schemas/index.d.ts +4674 -0
- package/es/backend/schemas/index.d.ts.map +1 -0
- package/es/backend/schemas/index.js +87 -0
- package/es/backend/types.d.ts +13 -0
- package/es/backend/types.d.ts.map +1 -0
- package/es/backend/types.js +1 -0
- package/es/index.d.ts +1 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +0 -0
- package/lib/backend/actions/delete-action-fn.d.ts +7 -0
- package/lib/backend/actions/delete-action-fn.d.ts.map +1 -0
- package/lib/backend/actions/delete-action-fn.js +42 -0
- package/lib/backend/actions/get-List-query.d.ts +30 -0
- package/lib/backend/actions/get-List-query.d.ts.map +1 -0
- package/lib/backend/actions/get-List-query.js +162 -0
- package/lib/backend/actions/get-action-fn.d.ts +12 -0
- package/lib/backend/actions/get-action-fn.d.ts.map +1 -0
- package/lib/backend/actions/get-action-fn.js +75 -0
- package/lib/backend/actions/get-list-action-fn.d.ts +12 -0
- package/lib/backend/actions/get-list-action-fn.d.ts.map +1 -0
- package/lib/backend/actions/get-list-action-fn.js +74 -0
- package/lib/backend/actions/get-list-data.d.ts +8 -0
- package/lib/backend/actions/get-list-data.d.ts.map +1 -0
- package/lib/backend/actions/get-list-data.js +48 -0
- package/lib/backend/actions/index.d.ts +6 -0
- package/lib/backend/actions/index.d.ts.map +1 -0
- package/lib/backend/actions/index.js +41 -0
- package/lib/backend/actions/post-action-fn.d.ts +13 -0
- package/lib/backend/actions/post-action-fn.d.ts.map +1 -0
- package/lib/backend/actions/post-action-fn.js +49 -0
- package/lib/backend/actions/put-action-fn.d.ts +9 -0
- package/lib/backend/actions/put-action-fn.d.ts.map +1 -0
- package/lib/backend/actions/put-action-fn.js +43 -0
- package/lib/backend/actions/transform-body.d.ts +2 -0
- package/lib/backend/actions/transform-body.d.ts.map +1 -0
- package/lib/backend/actions/transform-body.js +47 -0
- package/lib/backend/index.d.ts +3 -0
- package/lib/backend/index.d.ts.map +1 -0
- package/lib/backend/index.js +25 -0
- package/lib/backend/route-operation/delete-operation.d.ts +10 -0
- package/lib/backend/route-operation/delete-operation.d.ts.map +1 -0
- package/lib/backend/route-operation/delete-operation.js +59 -0
- package/lib/backend/route-operation/get-list-operation.d.ts +24 -0
- package/lib/backend/route-operation/get-list-operation.d.ts.map +1 -0
- package/lib/backend/route-operation/get-list-operation.js +87 -0
- package/lib/backend/route-operation/get-operation.d.ts +17 -0
- package/lib/backend/route-operation/get-operation.d.ts.map +1 -0
- package/lib/backend/route-operation/get-operation.js +82 -0
- package/lib/backend/route-operation/get-table-name.d.ts +4 -0
- package/lib/backend/route-operation/get-table-name.d.ts.map +1 -0
- package/lib/backend/route-operation/get-table-name.js +35 -0
- package/lib/backend/route-operation/index.d.ts +6 -0
- package/lib/backend/route-operation/index.d.ts.map +1 -0
- package/lib/backend/route-operation/index.js +31 -0
- package/lib/backend/route-operation/post-operation.d.ts +14 -0
- package/lib/backend/route-operation/post-operation.d.ts.map +1 -0
- package/lib/backend/route-operation/post-operation.js +67 -0
- package/lib/backend/route-operation/put-operation.d.ts +14 -0
- package/lib/backend/route-operation/put-operation.d.ts.map +1 -0
- package/lib/backend/route-operation/put-operation.js +66 -0
- package/lib/backend/schemas/index.d.ts +4674 -0
- package/lib/backend/schemas/index.d.ts.map +1 -0
- package/lib/backend/schemas/index.js +98 -0
- package/lib/backend/types.d.ts +13 -0
- package/lib/backend/types.d.ts.map +1 -0
- package/lib/backend/types.js +17 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +0 -0
- package/package.json +86 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 LobeHub
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
2
|
+
import { BaseTable } from "../types";
|
|
3
|
+
export declare function deleteActionFn<TTable extends BaseTable>({ table, db, }: {
|
|
4
|
+
db: NodePgDatabase<any>;
|
|
5
|
+
table: TTable;
|
|
6
|
+
}): any;
|
|
7
|
+
//# sourceMappingURL=delete-action-fn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-action-fn.d.ts","sourceRoot":"","sources":["delete-action-fn.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,OAAO,EAAE,SAAS,EAAE,iBAAwB;AAE5C,wBAAgB,cAAc,CAAC,MAAM,SAAS,SAAS,EAAE,EACvD,KAAK,EACL,EAAE,GACH,EAAE;IACD,EAAE,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;CACf,OASA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
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 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); } }
|
|
4
|
+
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); }); }; }
|
|
5
|
+
import { rpcOperation } from "next-rest-framework";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { eq } from "drizzle-orm";
|
|
8
|
+
export function deleteActionFn(_ref) {
|
|
9
|
+
var table = _ref.table,
|
|
10
|
+
db = _ref.db;
|
|
11
|
+
return rpcOperation().input({
|
|
12
|
+
body: z.string(),
|
|
13
|
+
contentType: "application/json"
|
|
14
|
+
}).handler( /*#__PURE__*/function () {
|
|
15
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(id) {
|
|
16
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
17
|
+
while (1) switch (_context.prev = _context.next) {
|
|
18
|
+
case 0:
|
|
19
|
+
return _context.abrupt("return", db.delete(table).where(eq(table.id, id)).returning());
|
|
20
|
+
case 1:
|
|
21
|
+
case "end":
|
|
22
|
+
return _context.stop();
|
|
23
|
+
}
|
|
24
|
+
}, _callee);
|
|
25
|
+
}));
|
|
26
|
+
return function (_x) {
|
|
27
|
+
return _ref2.apply(this, arguments);
|
|
28
|
+
};
|
|
29
|
+
}());
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BaseTable, GetListRelations } from "../types";
|
|
2
|
+
import { SelectedFields } from "drizzle-orm/pg-core/query-builders/select.types";
|
|
3
|
+
import { SQL } from "drizzle-orm";
|
|
4
|
+
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
5
|
+
export declare function getListQuery<TTable extends BaseTable, TSelection extends SelectedFields>({ db, fields, jsonArrayFields, params, relations, table, }: {
|
|
6
|
+
db: NodePgDatabase<any>;
|
|
7
|
+
fields: TSelection;
|
|
8
|
+
jsonArrayFields?: string[];
|
|
9
|
+
params: {
|
|
10
|
+
[field: string]: any;
|
|
11
|
+
orderBy?: keyof BaseTable;
|
|
12
|
+
orderDir?: "asc" | "desc";
|
|
13
|
+
page?: number;
|
|
14
|
+
pageSize?: number;
|
|
15
|
+
};
|
|
16
|
+
relations?: GetListRelations;
|
|
17
|
+
table: TTable;
|
|
18
|
+
}): {
|
|
19
|
+
countQuery: Omit<import("drizzle-orm/pg-core").PgSelectBase<any, {
|
|
20
|
+
count: SQL<unknown>;
|
|
21
|
+
}, "partial", {} | Record<any, "not-null">, false, "where", ({
|
|
22
|
+
count: unknown;
|
|
23
|
+
} | {
|
|
24
|
+
count: unknown;
|
|
25
|
+
})[], {
|
|
26
|
+
count: import("drizzle-orm").DrizzleTypeError<"You cannot reference this field without assigning it an alias first - use `.as(<alias>)`">;
|
|
27
|
+
}>, "where">;
|
|
28
|
+
query: any;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=get-List-query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-List-query.d.ts","sourceRoot":"","sources":["get-List-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,iBAAwB;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,iDAAiD,CAAC;AACjF,OAAO,EAYL,GAAG,EACJ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,wBAAgB,YAAY,CAC1B,MAAM,SAAS,SAAS,EACxB,UAAU,SAAS,cAAc,EACjC,EACA,EAAE,EACF,MAAM,EACN,eAAe,EACf,MAAM,EACN,SAAS,EACT,KAAK,GACN,EAAE;IACD,EAAE,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC;IACxB,MAAM,EAAE,UAAU,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,MAAM,EAAE;QAEN,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC;QAErB,OAAO,CAAC,EAAE,MAAM,SAAS,CAAC;QAE1B,QAAQ,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;QAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;QAEd,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;CACf;;;;;;;;;;;EA6MA"}
|
|
@@ -0,0 +1,212 @@
|
|
|
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, ilike, 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 (t) {
|
|
88
|
+
return t[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 (v) {
|
|
100
|
+
return v.trim();
|
|
101
|
+
}).filter(Boolean);
|
|
102
|
+
if (values.length > 0) {
|
|
103
|
+
if (isJsonArray) {
|
|
104
|
+
// 处理JSONB数组字段
|
|
105
|
+
conditions.push(sql(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n EXISTS (\n SELECT 1 FROM jsonb_array_elements_text(", ") tag\n WHERE tag 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 (v) {
|
|
110
|
+
return ilike(targetColumn, "%".concat(v, "%"));
|
|
111
|
+
}))));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
// 处理单值
|
|
116
|
+
if (isJsonArray) {
|
|
117
|
+
// 处理JSONB数组字段
|
|
118
|
+
conditions.push(sql(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n EXISTS (\n SELECT 1 FROM jsonb_array_elements_text(", ") tag\n WHERE tag LIKE ", "\n )\n "])), targetColumn, "%".concat(value, "%")));
|
|
119
|
+
} else if (isIdField) {
|
|
120
|
+
conditions.push(eq(targetColumn, value));
|
|
121
|
+
} else {
|
|
122
|
+
conditions.push(ilike(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) continue;
|
|
140
|
+
|
|
141
|
+
// 处理日期范围字段
|
|
142
|
+
if (key.endsWith("AtFrom") || key.endsWith("AtTo")) {
|
|
143
|
+
var baseFieldName = key.replace(/(AtFrom|AtTo)$/, "");
|
|
144
|
+
var _targetColumn = findTargetColumn("".concat(baseFieldName, "At"), table, relations);
|
|
145
|
+
if (!_targetColumn) continue;
|
|
146
|
+
if (key.endsWith("AtFrom")) {
|
|
147
|
+
conditions.push(gte(_targetColumn, new Date(value)));
|
|
148
|
+
} else if (key.endsWith("AtTo")) {
|
|
149
|
+
conditions.push(lte(_targetColumn, new Date(value)));
|
|
150
|
+
}
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// 处理其他普通过滤条件
|
|
155
|
+
var targetColumn = findTargetColumn(key, table, relations);
|
|
156
|
+
if (!targetColumn) continue;
|
|
157
|
+
addCondition(conditions, key, value, targetColumn);
|
|
158
|
+
}
|
|
159
|
+
return conditions;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// 构建排序
|
|
163
|
+
function buildOrderBy(table, orderBy, orderDir) {
|
|
164
|
+
var orderColumn = table[orderBy];
|
|
165
|
+
return orderDir === "asc" ? asc(orderColumn) : desc(orderColumn);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// 构建基础查询
|
|
169
|
+
var baseQuery = buildBaseQuery(table, fields, relations);
|
|
170
|
+
|
|
171
|
+
// 构建条件
|
|
172
|
+
var conditions = buildConditions(filters, table, relations);
|
|
173
|
+
|
|
174
|
+
// 构建主查询
|
|
175
|
+
var query = baseQuery.where(conditions.length > 0 ? and.apply(void 0, _toConsumableArray(conditions)) : undefined).orderBy(buildOrderBy(table, orderBy, orderDir))
|
|
176
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
177
|
+
// @ts-ignore
|
|
178
|
+
.limit(pageSize).offset((page - 1) * pageSize);
|
|
179
|
+
|
|
180
|
+
// 构建计数查询(优化后)
|
|
181
|
+
var countQuery = db.select({
|
|
182
|
+
count: sql(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["COUNT(DISTINCT ", ")"])), table.id)
|
|
183
|
+
}).from(table).where(conditions.length > 0 ? and.apply(void 0, _toConsumableArray(conditions)) : undefined);
|
|
184
|
+
|
|
185
|
+
// 添加关联
|
|
186
|
+
if (relations !== null && relations !== void 0 && relations.length) {
|
|
187
|
+
var _iterator2 = _createForOfIteratorHelper(relations),
|
|
188
|
+
_step2;
|
|
189
|
+
try {
|
|
190
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
191
|
+
var _step2$value = _step2.value,
|
|
192
|
+
relationTable = _step2$value.table,
|
|
193
|
+
joinSql = _step2$value.sql;
|
|
194
|
+
if (relationTable) {
|
|
195
|
+
query.leftJoin(relationTable, joinSql);
|
|
196
|
+
countQuery.leftJoin(relationTable, joinSql);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
} catch (err) {
|
|
200
|
+
_iterator2.e(err);
|
|
201
|
+
} finally {
|
|
202
|
+
_iterator2.f();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// console.log(query.prepare("a").getQuery());
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
countQuery: countQuery,
|
|
210
|
+
query: query
|
|
211
|
+
};
|
|
212
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ZodSchema } from "zod";
|
|
2
|
+
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
3
|
+
import { BaseTable, GetListRelations } from "../types";
|
|
4
|
+
export declare function getActionFn<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable>({ bodySchema, db, jsonArrayFields, querySchema, relations, table, }: {
|
|
5
|
+
bodySchema: T;
|
|
6
|
+
db: NodePgDatabase<any>;
|
|
7
|
+
jsonArrayFields?: string[];
|
|
8
|
+
querySchema: Q;
|
|
9
|
+
relations?: GetListRelations;
|
|
10
|
+
table: TTable;
|
|
11
|
+
}): any;
|
|
12
|
+
//# sourceMappingURL=get-action-fn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-action-fn.d.ts","sourceRoot":"","sources":["get-action-fn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAGhC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAG3D,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,iBAAwB;AAE9D,wBAAgB,WAAW,CACzB,CAAC,SAAS,SAAS,EACnB,CAAC,SAAS,SAAS,EACnB,MAAM,SAAS,SAAS,EACxB,EACA,UAAU,EACV,EAAE,EACF,eAAe,EACf,WAAW,EACX,SAAS,EACT,KAAK,GACN,EAAE;IACD,UAAU,EAAE,CAAC,CAAC;IACd,EAAE,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,WAAW,EAAE,CAAC,CAAC;IACf,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;CACf,OA8CA"}
|
|
@@ -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
|
+
import { rpcOperation } from "next-rest-framework";
|
|
12
|
+
import { getListQuery } from "./get-List-query";
|
|
13
|
+
import { getListData } from "./get-list-data";
|
|
14
|
+
export function getActionFn(_ref) {
|
|
15
|
+
var bodySchema = _ref.bodySchema,
|
|
16
|
+
db = _ref.db,
|
|
17
|
+
jsonArrayFields = _ref.jsonArrayFields,
|
|
18
|
+
querySchema = _ref.querySchema,
|
|
19
|
+
relations = _ref.relations,
|
|
20
|
+
table = _ref.table;
|
|
21
|
+
return rpcOperation().input({
|
|
22
|
+
body: querySchema,
|
|
23
|
+
contentType: "application/json"
|
|
24
|
+
}).outputs([{
|
|
25
|
+
body: bodySchema,
|
|
26
|
+
contentType: "application/json"
|
|
27
|
+
}]).handler( /*#__PURE__*/function () {
|
|
28
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
|
|
29
|
+
var fields, _i, _Object$keys, key, field, _getListQuery, query, countQuery, _yield$getListData, _yield$getListData$da, result;
|
|
30
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
31
|
+
while (1) switch (_context.prev = _context.next) {
|
|
32
|
+
case 0:
|
|
33
|
+
fields = {}; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
for (_i = 0, _Object$keys = Object.keys(bodySchema.shape); _i < _Object$keys.length; _i++) {
|
|
36
|
+
key = _Object$keys[_i];
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
field = table[key];
|
|
40
|
+
if (field) {
|
|
41
|
+
fields[key] = field;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
_getListQuery = getListQuery({
|
|
45
|
+
db: db,
|
|
46
|
+
fields: fields,
|
|
47
|
+
jsonArrayFields: jsonArrayFields,
|
|
48
|
+
params: params,
|
|
49
|
+
relations: relations,
|
|
50
|
+
table: table
|
|
51
|
+
}), query = _getListQuery.query, countQuery = _getListQuery.countQuery; // 执行查询
|
|
52
|
+
_context.next = 5;
|
|
53
|
+
return getListData({
|
|
54
|
+
bodySchema: bodySchema,
|
|
55
|
+
countQuery: countQuery,
|
|
56
|
+
current: 1,
|
|
57
|
+
pageSize: 1,
|
|
58
|
+
query: query
|
|
59
|
+
})();
|
|
60
|
+
case 5:
|
|
61
|
+
_yield$getListData = _context.sent;
|
|
62
|
+
_yield$getListData$da = _slicedToArray(_yield$getListData.data, 1);
|
|
63
|
+
result = _yield$getListData$da[0];
|
|
64
|
+
return _context.abrupt("return", result || {});
|
|
65
|
+
case 9:
|
|
66
|
+
case "end":
|
|
67
|
+
return _context.stop();
|
|
68
|
+
}
|
|
69
|
+
}, _callee);
|
|
70
|
+
}));
|
|
71
|
+
return function (_x) {
|
|
72
|
+
return _ref2.apply(this, arguments);
|
|
73
|
+
};
|
|
74
|
+
}());
|
|
75
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ZodSchema } from "zod";
|
|
2
|
+
import { BaseTable, GetListRelations } from "../types";
|
|
3
|
+
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
4
|
+
export declare function getListActionFn<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable>({ bodySchema, db, jsonArrayFields, querySchema, relations, table, }: {
|
|
5
|
+
bodySchema: T;
|
|
6
|
+
db: NodePgDatabase<any>;
|
|
7
|
+
jsonArrayFields?: string[];
|
|
8
|
+
querySchema: Q;
|
|
9
|
+
relations?: GetListRelations;
|
|
10
|
+
table: TTable;
|
|
11
|
+
}): any;
|
|
12
|
+
//# sourceMappingURL=get-list-action-fn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-list-action-fn.d.ts","sourceRoot":"","sources":["get-list-action-fn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,iBAAwB;AAM9D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,wBAAgB,eAAe,CAC7B,CAAC,SAAS,SAAS,EACnB,CAAC,SAAS,SAAS,EACnB,MAAM,SAAS,SAAS,EACxB,EACA,UAAU,EACV,EAAE,EACF,eAAe,EACf,WAAW,EACX,SAAS,EACT,KAAK,GACN,EAAE;IACD,UAAU,EAAE,CAAC,CAAC;IACd,EAAE,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,WAAW,EAAE,CAAC,CAAC;IACf,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;CACf,OA2CA"}
|
|
@@ -0,0 +1,68 @@
|
|
|
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 _excluded = ["current", "pageSize"];
|
|
3
|
+
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; }
|
|
4
|
+
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; }
|
|
5
|
+
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; }
|
|
6
|
+
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); } }
|
|
7
|
+
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); }); }; }
|
|
8
|
+
import { rpcOperation } from "next-rest-framework";
|
|
9
|
+
import { listBodySchema } from "../schemas";
|
|
10
|
+
import { getListQuery } from "./get-List-query";
|
|
11
|
+
import { getListData } from "./get-list-data";
|
|
12
|
+
export function getListActionFn(_ref) {
|
|
13
|
+
var bodySchema = _ref.bodySchema,
|
|
14
|
+
db = _ref.db,
|
|
15
|
+
jsonArrayFields = _ref.jsonArrayFields,
|
|
16
|
+
querySchema = _ref.querySchema,
|
|
17
|
+
relations = _ref.relations,
|
|
18
|
+
table = _ref.table;
|
|
19
|
+
return rpcOperation().input({
|
|
20
|
+
body: querySchema,
|
|
21
|
+
contentType: "application/json"
|
|
22
|
+
}).outputs([{
|
|
23
|
+
body: listBodySchema(bodySchema),
|
|
24
|
+
contentType: "application/json"
|
|
25
|
+
}]).handler( /*#__PURE__*/function () {
|
|
26
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
|
|
27
|
+
var current, pageSize, other, fields, _i, _Object$keys, key, field, _getListQuery, query, countQuery;
|
|
28
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
29
|
+
while (1) switch (_context.prev = _context.next) {
|
|
30
|
+
case 0:
|
|
31
|
+
current = params.current, pageSize = params.pageSize, other = _objectWithoutProperties(params, _excluded);
|
|
32
|
+
fields = {}; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
for (_i = 0, _Object$keys = Object.keys(bodySchema.shape); _i < _Object$keys.length; _i++) {
|
|
35
|
+
key = _Object$keys[_i];
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
field = table[key];
|
|
39
|
+
if (field) {
|
|
40
|
+
fields[key] = field;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
_getListQuery = getListQuery({
|
|
44
|
+
db: db,
|
|
45
|
+
fields: fields,
|
|
46
|
+
jsonArrayFields: jsonArrayFields,
|
|
47
|
+
params: other,
|
|
48
|
+
relations: relations,
|
|
49
|
+
table: table
|
|
50
|
+
}), query = _getListQuery.query, countQuery = _getListQuery.countQuery; // 执行查询
|
|
51
|
+
return _context.abrupt("return", getListData({
|
|
52
|
+
bodySchema: bodySchema,
|
|
53
|
+
countQuery: countQuery,
|
|
54
|
+
current: current,
|
|
55
|
+
pageSize: pageSize,
|
|
56
|
+
query: query
|
|
57
|
+
})());
|
|
58
|
+
case 5:
|
|
59
|
+
case "end":
|
|
60
|
+
return _context.stop();
|
|
61
|
+
}
|
|
62
|
+
}, _callee);
|
|
63
|
+
}));
|
|
64
|
+
return function (_x) {
|
|
65
|
+
return _ref2.apply(this, arguments);
|
|
66
|
+
};
|
|
67
|
+
}());
|
|
68
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ZodSchema } from "zod";
|
|
2
|
+
import { getListQuery } from "./get-List-query";
|
|
3
|
+
export declare function getListData<B extends ZodSchema>({ query, countQuery, pageSize, current, bodySchema, }: {
|
|
4
|
+
bodySchema: B;
|
|
5
|
+
current?: number;
|
|
6
|
+
pageSize?: number;
|
|
7
|
+
} & ReturnType<typeof getListQuery>): any;
|
|
8
|
+
//# sourceMappingURL=get-list-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-list-data.d.ts","sourceRoot":"","sources":["get-list-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIhD,wBAAgB,WAAW,CAAC,CAAC,SAAS,SAAS,EAAE,EAC/C,KAAK,EACL,UAAU,EACV,QAAa,EACb,OAAW,EACX,UAAU,GACX,EAAE;IACD,UAAU,EAAE,CAAC,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,OAoBlC"}
|