@ai0x0/utils 0.0.38 → 0.0.40
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 +13 -9
- package/SKILL.md +13 -9
- package/es/backend/route-operation/delete-operation.d.ts +10 -3
- package/es/backend/route-operation/delete-operation.js +39 -23
- package/es/backend/route-operation/get-list-operation.d.ts +11 -7
- package/es/backend/route-operation/get-list-operation.js +41 -23
- package/es/backend/route-operation/get-operation.d.ts +8 -4
- package/es/backend/route-operation/get-operation.js +38 -23
- package/es/backend/route-operation/post-operation.d.ts +8 -4
- package/es/backend/route-operation/post-operation.js +45 -38
- package/es/backend/route-operation/put-operation.d.ts +8 -4
- package/es/backend/route-operation/put-operation.js +53 -36
- package/es/backend/sqlite/route-operation/delete-operation.d.ts +9 -2
- package/es/backend/sqlite/route-operation/delete-operation.js +39 -26
- package/es/backend/sqlite/route-operation/get-list-operation.d.ts +8 -4
- package/es/backend/sqlite/route-operation/get-list-operation.js +41 -25
- package/es/backend/sqlite/route-operation/get-operation.d.ts +6 -2
- package/es/backend/sqlite/route-operation/get-operation.js +38 -25
- package/es/backend/sqlite/route-operation/post-operation.d.ts +6 -2
- package/es/backend/sqlite/route-operation/post-operation.js +44 -38
- package/es/backend/sqlite/route-operation/put-operation.d.ts +6 -2
- package/es/backend/sqlite/route-operation/put-operation.js +51 -37
- package/lib/backend/route-operation/delete-operation.d.ts +10 -3
- package/lib/backend/route-operation/delete-operation.js +6 -4
- package/lib/backend/route-operation/get-list-operation.d.ts +11 -7
- package/lib/backend/route-operation/get-list-operation.js +9 -9
- package/lib/backend/route-operation/get-operation.d.ts +8 -4
- package/lib/backend/route-operation/get-operation.js +9 -9
- package/lib/backend/route-operation/post-operation.d.ts +8 -4
- package/lib/backend/route-operation/post-operation.js +8 -6
- package/lib/backend/route-operation/put-operation.d.ts +8 -4
- package/lib/backend/route-operation/put-operation.js +11 -5
- package/lib/backend/sqlite/route-operation/delete-operation.d.ts +9 -2
- package/lib/backend/sqlite/route-operation/delete-operation.js +4 -3
- package/lib/backend/sqlite/route-operation/get-list-operation.d.ts +8 -4
- package/lib/backend/sqlite/route-operation/get-list-operation.js +12 -9
- package/lib/backend/sqlite/route-operation/get-operation.d.ts +6 -2
- package/lib/backend/sqlite/route-operation/get-operation.js +9 -9
- package/lib/backend/sqlite/route-operation/post-operation.d.ts +6 -2
- package/lib/backend/sqlite/route-operation/post-operation.js +8 -6
- package/lib/backend/sqlite/route-operation/put-operation.d.ts +6 -2
- package/lib/backend/sqlite/route-operation/put-operation.js +9 -4
- package/package.json +1 -1
|
@@ -1,11 +1,5 @@
|
|
|
1
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
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
3
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
4
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
5
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -25,6 +19,7 @@ export var createPostOperation = function createPostOperation(_ref) {
|
|
|
25
19
|
outputBodySchema = _ref2.outputBodySchema,
|
|
26
20
|
setBody = _ref2.setBody,
|
|
27
21
|
summary = _ref2.summary,
|
|
22
|
+
tags = _ref2.tags,
|
|
28
23
|
table = _ref2.table,
|
|
29
24
|
onSuccess = _ref2.onSuccess,
|
|
30
25
|
onError = _ref2.onError;
|
|
@@ -32,7 +27,7 @@ export var createPostOperation = function createPostOperation(_ref) {
|
|
|
32
27
|
method: "POST",
|
|
33
28
|
openApiOperation: {
|
|
34
29
|
summary: summary,
|
|
35
|
-
tags: [getTableName(table)]
|
|
30
|
+
tags: tags !== null && tags !== void 0 ? tags : table ? [getTableName(table)] : []
|
|
36
31
|
}
|
|
37
32
|
}).input({
|
|
38
33
|
body: bodySchema,
|
|
@@ -45,7 +40,7 @@ export var createPostOperation = function createPostOperation(_ref) {
|
|
|
45
40
|
status: 200
|
|
46
41
|
}]).handler( /*#__PURE__*/function () {
|
|
47
42
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
|
|
48
|
-
var _ref4, userId, body, extraBody, mergedBody,
|
|
43
|
+
var _ref4, userId, body, extraBody, mergedBody, params, raw, data, response;
|
|
49
44
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
50
45
|
while (1) switch (_context.prev = _context.next) {
|
|
51
46
|
case 0:
|
|
@@ -78,55 +73,67 @@ export var createPostOperation = function createPostOperation(_ref) {
|
|
|
78
73
|
case 16:
|
|
79
74
|
extraBody = _context.t1;
|
|
80
75
|
mergedBody = _objectSpread(_objectSpread({}, body), extraBody);
|
|
81
|
-
|
|
76
|
+
params = _objectSpread({
|
|
77
|
+
creatorId: userId
|
|
78
|
+
}, mergedBody);
|
|
79
|
+
if (!table) {
|
|
80
|
+
_context.next = 25;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
_context.next = 22;
|
|
82
84
|
return createPostAction({
|
|
83
85
|
bodySchema: bodySchema,
|
|
84
86
|
db: db,
|
|
85
87
|
table: table
|
|
86
|
-
})(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
88
|
+
})(params);
|
|
89
|
+
case 22:
|
|
90
|
+
_context.t2 = _context.sent[0];
|
|
91
|
+
_context.next = 26;
|
|
92
|
+
break;
|
|
93
|
+
case 25:
|
|
94
|
+
_context.t2 = params;
|
|
95
|
+
case 26:
|
|
96
|
+
raw = _context.t2;
|
|
93
97
|
if (!onSuccess) {
|
|
94
|
-
_context.next =
|
|
98
|
+
_context.next = 33;
|
|
95
99
|
break;
|
|
96
100
|
}
|
|
97
|
-
_context.next = 26;
|
|
98
|
-
return onSuccess(raw);
|
|
99
|
-
case 26:
|
|
100
|
-
_context.t2 = _context.sent;
|
|
101
101
|
_context.next = 30;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
return onSuccess({
|
|
103
|
+
data: raw,
|
|
104
|
+
params: params
|
|
105
|
+
});
|
|
105
106
|
case 30:
|
|
106
|
-
|
|
107
|
-
|
|
107
|
+
_context.t3 = _context.sent;
|
|
108
|
+
_context.next = 34;
|
|
109
|
+
break;
|
|
110
|
+
case 33:
|
|
111
|
+
_context.t3 = raw;
|
|
112
|
+
case 34:
|
|
113
|
+
data = _context.t3;
|
|
114
|
+
return _context.abrupt("return", TypedNextResponse.json(data, {
|
|
108
115
|
status: 200
|
|
109
116
|
}));
|
|
110
|
-
case
|
|
111
|
-
_context.prev =
|
|
112
|
-
_context.
|
|
113
|
-
console.error(_context.
|
|
114
|
-
_context.next =
|
|
115
|
-
return onError === null || onError === void 0 ? void 0 : onError(_context.
|
|
116
|
-
case
|
|
117
|
+
case 38:
|
|
118
|
+
_context.prev = 38;
|
|
119
|
+
_context.t4 = _context["catch"](0);
|
|
120
|
+
console.error(_context.t4);
|
|
121
|
+
_context.next = 43;
|
|
122
|
+
return onError === null || onError === void 0 ? void 0 : onError(_context.t4);
|
|
123
|
+
case 43:
|
|
117
124
|
response = _context.sent;
|
|
118
125
|
if (!response) {
|
|
119
|
-
_context.next =
|
|
126
|
+
_context.next = 48;
|
|
120
127
|
break;
|
|
121
128
|
}
|
|
122
129
|
return _context.abrupt("return", response);
|
|
123
|
-
case
|
|
124
|
-
throw _context.
|
|
125
|
-
case
|
|
130
|
+
case 48:
|
|
131
|
+
throw _context.t4;
|
|
132
|
+
case 49:
|
|
126
133
|
case "end":
|
|
127
134
|
return _context.stop();
|
|
128
135
|
}
|
|
129
|
-
}, _callee, null, [[0,
|
|
136
|
+
}, _callee, null, [[0, 38]]);
|
|
130
137
|
}));
|
|
131
138
|
return function (_x) {
|
|
132
139
|
return _ref3.apply(this, arguments);
|
|
@@ -4,11 +4,15 @@ import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
|
4
4
|
export interface PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends PgTable> {
|
|
5
5
|
bodySchema: IB;
|
|
6
6
|
outputBodySchema?: OB;
|
|
7
|
-
table
|
|
7
|
+
table?: TTable;
|
|
8
8
|
summary?: string;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
tags?: string[];
|
|
10
|
+
setBody?(req: TypedNextRequest<"PUT", "application/json", z.infer<IB>>): Promise<Partial<z.infer<IB>>>;
|
|
11
|
+
onSuccess?(payload: {
|
|
12
|
+
params: Record<string, unknown>;
|
|
13
|
+
data: z.infer<OB>;
|
|
14
|
+
}): Promise<z.infer<OB>>;
|
|
15
|
+
onError?(error: Error): Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
12
16
|
byCreator?: boolean;
|
|
13
17
|
}
|
|
14
18
|
export declare const createPutOperation: any;
|
|
@@ -20,6 +20,7 @@ export var createPutOperation = function createPutOperation(_ref) {
|
|
|
20
20
|
outputBodySchema = _ref2.outputBodySchema,
|
|
21
21
|
table = _ref2.table,
|
|
22
22
|
summary = _ref2.summary,
|
|
23
|
+
tags = _ref2.tags,
|
|
23
24
|
setBody = _ref2.setBody,
|
|
24
25
|
onSuccess = _ref2.onSuccess,
|
|
25
26
|
_ref2$byCreator = _ref2.byCreator,
|
|
@@ -29,7 +30,7 @@ export var createPutOperation = function createPutOperation(_ref) {
|
|
|
29
30
|
method: "PUT",
|
|
30
31
|
openApiOperation: {
|
|
31
32
|
summary: summary,
|
|
32
|
-
tags: [getTableName(table)]
|
|
33
|
+
tags: tags !== null && tags !== void 0 ? tags : table ? [getTableName(table)] : []
|
|
33
34
|
}
|
|
34
35
|
}).input({
|
|
35
36
|
body: bodySchema,
|
|
@@ -40,7 +41,7 @@ export var createPutOperation = function createPutOperation(_ref) {
|
|
|
40
41
|
contentType: "application/json"
|
|
41
42
|
}]).handler( /*#__PURE__*/function () {
|
|
42
43
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
|
|
43
|
-
var _ref4, userId, body, extraBody, mergedBody, raw,
|
|
44
|
+
var _ref4, userId, body, extraBody, mergedBody, params, raw, data, response;
|
|
44
45
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
45
46
|
while (1) switch (_context.prev = _context.next) {
|
|
46
47
|
case 0:
|
|
@@ -73,65 +74,81 @@ export var createPutOperation = function createPutOperation(_ref) {
|
|
|
73
74
|
case 16:
|
|
74
75
|
extraBody = _context.t1;
|
|
75
76
|
mergedBody = _objectSpread(_objectSpread({}, body), extraBody);
|
|
76
|
-
|
|
77
|
+
params = _objectSpread({
|
|
78
|
+
editorId: userId
|
|
79
|
+
}, mergedBody);
|
|
80
|
+
if (!table) {
|
|
81
|
+
_context.next = 25;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
_context.next = 22;
|
|
77
85
|
return createPutAction({
|
|
78
86
|
bodySchema: bodySchema,
|
|
79
87
|
table: table,
|
|
80
88
|
db: db
|
|
81
|
-
})(
|
|
82
|
-
editorId: userId
|
|
83
|
-
}, mergedBody), {
|
|
89
|
+
})(params, {
|
|
84
90
|
byCreator: byCreator
|
|
85
91
|
});
|
|
86
|
-
case
|
|
87
|
-
|
|
92
|
+
case 22:
|
|
93
|
+
_context.t2 = _context.sent;
|
|
94
|
+
_context.next = 26;
|
|
95
|
+
break;
|
|
96
|
+
case 25:
|
|
97
|
+
_context.t2 = params;
|
|
98
|
+
case 26:
|
|
99
|
+
raw = _context.t2;
|
|
88
100
|
if (!onSuccess) {
|
|
89
|
-
_context.next =
|
|
101
|
+
_context.next = 33;
|
|
90
102
|
break;
|
|
91
103
|
}
|
|
92
|
-
_context.next =
|
|
93
|
-
return onSuccess(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
104
|
+
_context.next = 30;
|
|
105
|
+
return onSuccess({
|
|
106
|
+
data: raw,
|
|
107
|
+
params: params
|
|
108
|
+
});
|
|
109
|
+
case 30:
|
|
110
|
+
_context.t3 = _context.sent;
|
|
111
|
+
_context.next = 34;
|
|
97
112
|
break;
|
|
98
|
-
case
|
|
99
|
-
_context.
|
|
100
|
-
case
|
|
101
|
-
|
|
102
|
-
return _context.abrupt("return", TypedNextResponse.json(
|
|
113
|
+
case 33:
|
|
114
|
+
_context.t3 = raw;
|
|
115
|
+
case 34:
|
|
116
|
+
data = _context.t3;
|
|
117
|
+
return _context.abrupt("return", TypedNextResponse.json(data, {
|
|
103
118
|
status: 200
|
|
104
119
|
}));
|
|
105
|
-
case
|
|
106
|
-
_context.prev =
|
|
107
|
-
_context.
|
|
108
|
-
if (!(_context.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
120
|
+
case 38:
|
|
121
|
+
_context.prev = 38;
|
|
122
|
+
_context.t4 = _context["catch"](0);
|
|
123
|
+
if (!(_context.t4 instanceof HttpError)) {
|
|
124
|
+
console.error(_context.t4);
|
|
125
|
+
}
|
|
126
|
+
_context.next = 43;
|
|
127
|
+
return onError === null || onError === void 0 ? void 0 : onError(_context.t4);
|
|
128
|
+
case 43:
|
|
112
129
|
response = _context.sent;
|
|
113
130
|
if (!response) {
|
|
114
|
-
_context.next =
|
|
131
|
+
_context.next = 46;
|
|
115
132
|
break;
|
|
116
133
|
}
|
|
117
134
|
return _context.abrupt("return", response);
|
|
118
|
-
case
|
|
119
|
-
if (!(_context.
|
|
120
|
-
_context.next =
|
|
135
|
+
case 46:
|
|
136
|
+
if (!(_context.t4 instanceof HttpError)) {
|
|
137
|
+
_context.next = 48;
|
|
121
138
|
break;
|
|
122
139
|
}
|
|
123
140
|
return _context.abrupt("return", TypedNextResponse.json({
|
|
124
|
-
message: _context.
|
|
141
|
+
message: _context.t4.message
|
|
125
142
|
}, {
|
|
126
|
-
status: _context.
|
|
143
|
+
status: _context.t4.status
|
|
127
144
|
}));
|
|
128
|
-
case
|
|
129
|
-
throw _context.
|
|
130
|
-
case
|
|
145
|
+
case 48:
|
|
146
|
+
throw _context.t4;
|
|
147
|
+
case 49:
|
|
131
148
|
case "end":
|
|
132
149
|
return _context.stop();
|
|
133
150
|
}
|
|
134
|
-
}, _callee, null, [[0,
|
|
151
|
+
}, _callee, null, [[0, 38]]);
|
|
135
152
|
}));
|
|
136
153
|
return function (_x) {
|
|
137
154
|
return _ref3.apply(this, arguments);
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { TypedNextResponse } from "next-rest-framework";
|
|
2
2
|
import { BaseTable } from "../types.js";
|
|
3
3
|
export interface DeleteOperationOptions<TTable extends BaseTable> {
|
|
4
|
-
table
|
|
4
|
+
table?: TTable;
|
|
5
5
|
summary?: string;
|
|
6
|
-
|
|
6
|
+
tags?: string[];
|
|
7
|
+
onSuccess?: (_payload: {
|
|
8
|
+
params: {
|
|
9
|
+
id: string;
|
|
10
|
+
creatorId?: string;
|
|
11
|
+
};
|
|
12
|
+
data: unknown;
|
|
13
|
+
}) => Promise<void>;
|
|
7
14
|
onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
8
15
|
byCreator?: boolean;
|
|
9
16
|
}
|
|
@@ -2,7 +2,6 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
2
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
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
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
|
-
/* eslint-disable no-unused-vars */
|
|
6
5
|
import { routeOperation, TypedNextResponse } from "next-rest-framework";
|
|
7
6
|
import { z } from "zod";
|
|
8
7
|
import getTableName from "./get-table-name.js";
|
|
@@ -14,6 +13,7 @@ export var createDeleteOperation = function createDeleteOperation(_ref) {
|
|
|
14
13
|
return function (_ref2) {
|
|
15
14
|
var table = _ref2.table,
|
|
16
15
|
summary = _ref2.summary,
|
|
16
|
+
tags = _ref2.tags,
|
|
17
17
|
onSuccess = _ref2.onSuccess,
|
|
18
18
|
onError = _ref2.onError,
|
|
19
19
|
_ref2$byCreator = _ref2.byCreator,
|
|
@@ -22,7 +22,7 @@ export var createDeleteOperation = function createDeleteOperation(_ref) {
|
|
|
22
22
|
method: "DELETE",
|
|
23
23
|
openApiOperation: {
|
|
24
24
|
summary: summary,
|
|
25
|
-
tags: [getTableName(table)]
|
|
25
|
+
tags: tags !== null && tags !== void 0 ? tags : table ? [getTableName(table)] : []
|
|
26
26
|
}
|
|
27
27
|
}).input({
|
|
28
28
|
body: z.object({
|
|
@@ -58,51 +58,64 @@ export var createDeleteOperation = function createDeleteOperation(_ref) {
|
|
|
58
58
|
userId = _ref4.userId;
|
|
59
59
|
body.creatorId = userId;
|
|
60
60
|
case 13:
|
|
61
|
-
|
|
61
|
+
if (!table) {
|
|
62
|
+
_context.next = 19;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
_context.next = 16;
|
|
62
66
|
return createDeleteAction({
|
|
63
67
|
table: table,
|
|
64
68
|
db: db
|
|
65
69
|
})(body);
|
|
66
|
-
case
|
|
67
|
-
|
|
68
|
-
_context.next =
|
|
69
|
-
|
|
70
|
-
case
|
|
70
|
+
case 16:
|
|
71
|
+
_context.t1 = _context.sent;
|
|
72
|
+
_context.next = 20;
|
|
73
|
+
break;
|
|
74
|
+
case 19:
|
|
75
|
+
_context.t1 = body;
|
|
76
|
+
case 20:
|
|
77
|
+
data = _context.t1;
|
|
78
|
+
_context.next = 23;
|
|
79
|
+
return onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess({
|
|
80
|
+
data: data,
|
|
81
|
+
params: body
|
|
82
|
+
});
|
|
83
|
+
case 23:
|
|
71
84
|
return _context.abrupt("return", TypedNextResponse.json(data, {
|
|
72
85
|
status: 200
|
|
73
86
|
}));
|
|
74
|
-
case 21:
|
|
75
|
-
_context.prev = 21;
|
|
76
|
-
_context.t1 = _context["catch"](0);
|
|
77
|
-
if (!(_context.t1 instanceof HttpError)) {
|
|
78
|
-
console.error(_context.t1);
|
|
79
|
-
}
|
|
80
|
-
_context.next = 26;
|
|
81
|
-
return onError === null || onError === void 0 ? void 0 : onError(_context.t1);
|
|
82
87
|
case 26:
|
|
88
|
+
_context.prev = 26;
|
|
89
|
+
_context.t2 = _context["catch"](0);
|
|
90
|
+
if (!(_context.t2 instanceof HttpError)) {
|
|
91
|
+
console.error(_context.t2);
|
|
92
|
+
}
|
|
93
|
+
_context.next = 31;
|
|
94
|
+
return onError === null || onError === void 0 ? void 0 : onError(_context.t2);
|
|
95
|
+
case 31:
|
|
83
96
|
response = _context.sent;
|
|
84
97
|
if (!response) {
|
|
85
|
-
_context.next =
|
|
98
|
+
_context.next = 34;
|
|
86
99
|
break;
|
|
87
100
|
}
|
|
88
101
|
return _context.abrupt("return", response);
|
|
89
|
-
case
|
|
90
|
-
if (!(_context.
|
|
91
|
-
_context.next =
|
|
102
|
+
case 34:
|
|
103
|
+
if (!(_context.t2 instanceof HttpError)) {
|
|
104
|
+
_context.next = 36;
|
|
92
105
|
break;
|
|
93
106
|
}
|
|
94
107
|
return _context.abrupt("return", TypedNextResponse.json({
|
|
95
|
-
message: _context.
|
|
108
|
+
message: _context.t2.message
|
|
96
109
|
}, {
|
|
97
|
-
status: _context.
|
|
110
|
+
status: _context.t2.status
|
|
98
111
|
}));
|
|
99
|
-
case
|
|
100
|
-
throw _context.
|
|
101
|
-
case
|
|
112
|
+
case 36:
|
|
113
|
+
throw _context.t2;
|
|
114
|
+
case 37:
|
|
102
115
|
case "end":
|
|
103
116
|
return _context.stop();
|
|
104
117
|
}
|
|
105
|
-
}, _callee, null, [[0,
|
|
118
|
+
}, _callee, null, [[0, 26]]);
|
|
106
119
|
}));
|
|
107
120
|
return function (_x) {
|
|
108
121
|
return _ref3.apply(this, arguments);
|
|
@@ -9,10 +9,14 @@ export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchem
|
|
|
9
9
|
setParams?: (_req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string, unknown>>;
|
|
10
10
|
byCreator?: boolean;
|
|
11
11
|
summary?: string;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
tags?: string[];
|
|
13
|
+
table?: TTable;
|
|
14
|
+
onSuccess?: <D extends T>(_payload: {
|
|
15
|
+
params: Partial<z.infer<T>> & Record<string, unknown>;
|
|
16
|
+
data: {
|
|
17
|
+
data: z.infer<D>[];
|
|
18
|
+
total: number;
|
|
19
|
+
};
|
|
16
20
|
}) => Promise<{
|
|
17
21
|
data: z.infer<T>[];
|
|
18
22
|
total: number;
|
|
@@ -2,8 +2,6 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
2
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
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
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
|
-
/* eslint-disable no-unused-vars */
|
|
6
|
-
|
|
7
5
|
import { routeOperation, TypedNextResponse } from "next-rest-framework";
|
|
8
6
|
import getTableName from "./get-table-name.js";
|
|
9
7
|
import { listBodySchema } from "../schemas/index.js";
|
|
@@ -16,6 +14,7 @@ export var createGetListOperation = function createGetListOperation(_ref) {
|
|
|
16
14
|
bodySchema = _ref2.bodySchema,
|
|
17
15
|
table = _ref2.table,
|
|
18
16
|
summary = _ref2.summary,
|
|
17
|
+
tags = _ref2.tags,
|
|
19
18
|
relations = _ref2.relations,
|
|
20
19
|
jsonArrayFields = _ref2.jsonArrayFields,
|
|
21
20
|
setParams = _ref2.setParams,
|
|
@@ -27,7 +26,7 @@ export var createGetListOperation = function createGetListOperation(_ref) {
|
|
|
27
26
|
method: "GET",
|
|
28
27
|
openApiOperation: {
|
|
29
28
|
summary: summary,
|
|
30
|
-
tags: [getTableName(table)]
|
|
29
|
+
tags: tags !== null && tags !== void 0 ? tags : table ? [getTableName(table)] : []
|
|
31
30
|
}
|
|
32
31
|
}).input({
|
|
33
32
|
query: querySchema
|
|
@@ -37,7 +36,7 @@ export var createGetListOperation = function createGetListOperation(_ref) {
|
|
|
37
36
|
status: 200
|
|
38
37
|
}]).handler( /*#__PURE__*/function () {
|
|
39
38
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
|
|
40
|
-
var params, _ref4, userId, result, response;
|
|
39
|
+
var params, _ref4, userId, mergedParams, result, response;
|
|
41
40
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
42
41
|
while (1) switch (_context.prev = _context.next) {
|
|
43
42
|
case 0:
|
|
@@ -71,48 +70,65 @@ export var createGetListOperation = function createGetListOperation(_ref) {
|
|
|
71
70
|
userId = _ref4.userId;
|
|
72
71
|
params.creatorId = userId;
|
|
73
72
|
case 16:
|
|
74
|
-
|
|
73
|
+
mergedParams = Object.assign(Object.fromEntries(new URL(req.url).searchParams), params);
|
|
74
|
+
if (!table) {
|
|
75
|
+
_context.next = 23;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
_context.next = 20;
|
|
75
79
|
return createGetListAction({
|
|
76
80
|
bodySchema: bodySchema,
|
|
77
81
|
db: db,
|
|
78
82
|
jsonArrayFields: jsonArrayFields,
|
|
79
83
|
relations: relations,
|
|
80
84
|
table: table
|
|
81
|
-
})(
|
|
82
|
-
case
|
|
83
|
-
|
|
85
|
+
})(mergedParams);
|
|
86
|
+
case 20:
|
|
87
|
+
_context.t2 = _context.sent;
|
|
88
|
+
_context.next = 24;
|
|
89
|
+
break;
|
|
90
|
+
case 23:
|
|
91
|
+
_context.t2 = {
|
|
92
|
+
data: [],
|
|
93
|
+
total: 0
|
|
94
|
+
};
|
|
95
|
+
case 24:
|
|
96
|
+
result = _context.t2;
|
|
84
97
|
if (!onSuccess) {
|
|
85
|
-
_context.next =
|
|
98
|
+
_context.next = 29;
|
|
86
99
|
break;
|
|
87
100
|
}
|
|
88
|
-
_context.next =
|
|
89
|
-
return onSuccess(
|
|
90
|
-
|
|
101
|
+
_context.next = 28;
|
|
102
|
+
return onSuccess({
|
|
103
|
+
data: result,
|
|
104
|
+
params: mergedParams
|
|
105
|
+
});
|
|
106
|
+
case 28:
|
|
91
107
|
result = _context.sent;
|
|
92
|
-
case
|
|
108
|
+
case 29:
|
|
93
109
|
return _context.abrupt("return", TypedNextResponse.json(result, {
|
|
94
110
|
status: 200
|
|
95
111
|
}));
|
|
96
|
-
case
|
|
97
|
-
_context.prev =
|
|
98
|
-
_context.
|
|
99
|
-
console.error(_context.
|
|
100
|
-
_context.next =
|
|
101
|
-
return onError === null || onError === void 0 ? void 0 : onError(_context.
|
|
102
|
-
case
|
|
112
|
+
case 32:
|
|
113
|
+
_context.prev = 32;
|
|
114
|
+
_context.t3 = _context["catch"](0);
|
|
115
|
+
console.error(_context.t3);
|
|
116
|
+
_context.next = 37;
|
|
117
|
+
return onError === null || onError === void 0 ? void 0 : onError(_context.t3);
|
|
118
|
+
case 37:
|
|
103
119
|
response = _context.sent;
|
|
104
120
|
if (!response) {
|
|
105
|
-
_context.next =
|
|
121
|
+
_context.next = 42;
|
|
106
122
|
break;
|
|
107
123
|
}
|
|
108
124
|
return _context.abrupt("return", response);
|
|
109
|
-
case
|
|
110
|
-
throw _context.
|
|
111
|
-
case
|
|
125
|
+
case 42:
|
|
126
|
+
throw _context.t3;
|
|
127
|
+
case 43:
|
|
112
128
|
case "end":
|
|
113
129
|
return _context.stop();
|
|
114
130
|
}
|
|
115
|
-
}, _callee, null, [[0,
|
|
131
|
+
}, _callee, null, [[0, 32]]);
|
|
116
132
|
}));
|
|
117
133
|
return function (_x) {
|
|
118
134
|
return _ref3.apply(this, arguments);
|