@ai0x0/utils 0.0.46 → 0.0.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/skills/ai0x0-utils/backend/SKILL.md +40 -38
- package/SKILL.md +39 -37
- package/es/__shims__/next-rest-framework.d.ts +2 -0
- package/es/backend/route-operation/delete-operation.d.ts +7 -18
- package/es/backend/route-operation/delete-operation.js +10 -122
- package/es/backend/route-operation/get-list-operation.d.ts +5 -27
- package/es/backend/route-operation/get-list-operation.js +10 -135
- package/es/backend/route-operation/get-operation.d.ts +5 -21
- package/es/backend/route-operation/get-operation.js +10 -132
- package/es/backend/route-operation/get-table-name.js +0 -2
- package/es/backend/route-operation/index.d.ts +1 -0
- package/es/backend/route-operation/index.js +2 -1
- package/es/backend/route-operation/open-api-operation.d.ts +6 -0
- package/es/backend/route-operation/open-api-operation.js +13 -0
- package/es/backend/route-operation/operation-common.d.ts +38 -0
- package/es/backend/route-operation/operation-common.js +148 -0
- package/es/backend/route-operation/operation-core.d.ts +3 -0
- package/es/backend/route-operation/operation-core.js +3 -0
- package/es/backend/route-operation/post-operation.d.ts +5 -25
- package/es/backend/route-operation/post-operation.js +13 -189
- package/es/backend/route-operation/put-operation.d.ts +4 -23
- package/es/backend/route-operation/put-operation.js +10 -155
- package/es/backend/route-operation/read-operation-core.d.ts +55 -0
- package/es/backend/route-operation/read-operation-core.js +224 -0
- package/es/backend/route-operation/write-operation-core.d.ts +94 -0
- package/es/backend/route-operation/write-operation-core.js +390 -0
- package/es/backend/sqlite/route-operation/delete-operation.d.ts +9 -20
- package/es/backend/sqlite/route-operation/delete-operation.js +10 -122
- package/es/backend/sqlite/route-operation/get-list-operation.d.ts +6 -28
- package/es/backend/sqlite/route-operation/get-list-operation.js +10 -135
- package/es/backend/sqlite/route-operation/get-operation.d.ts +6 -22
- package/es/backend/sqlite/route-operation/get-operation.js +10 -132
- package/es/backend/sqlite/route-operation/index.d.ts +1 -0
- package/es/backend/sqlite/route-operation/index.js +2 -1
- package/es/backend/sqlite/route-operation/post-operation.d.ts +6 -26
- package/es/backend/sqlite/route-operation/post-operation.js +13 -189
- package/es/backend/sqlite/route-operation/put-operation.d.ts +6 -25
- package/es/backend/sqlite/route-operation/put-operation.js +10 -155
- package/es/backend/sqlite/schemas/index.d.ts +69 -5
- package/es/backend/sqlite/schemas/index.js +0 -1
- package/lib/__shims__/next-rest-framework.d.ts +2 -0
- package/lib/backend/route-operation/delete-operation.d.ts +7 -18
- package/lib/backend/route-operation/delete-operation.js +7 -52
- package/lib/backend/route-operation/get-list-operation.d.ts +5 -27
- package/lib/backend/route-operation/get-list-operation.js +7 -68
- package/lib/backend/route-operation/get-operation.d.ts +5 -21
- package/lib/backend/route-operation/get-operation.js +7 -67
- package/lib/backend/route-operation/index.d.ts +1 -0
- package/lib/backend/route-operation/index.js +3 -1
- package/lib/backend/route-operation/open-api-operation.d.ts +6 -0
- package/lib/backend/route-operation/open-api-operation.js +37 -0
- package/lib/backend/route-operation/operation-common.d.ts +38 -0
- package/lib/backend/route-operation/operation-common.js +90 -0
- package/lib/backend/route-operation/operation-core.d.ts +3 -0
- package/lib/backend/route-operation/operation-core.js +27 -0
- package/lib/backend/route-operation/post-operation.d.ts +5 -25
- package/lib/backend/route-operation/post-operation.js +7 -71
- package/lib/backend/route-operation/put-operation.d.ts +4 -23
- package/lib/backend/route-operation/put-operation.js +7 -68
- package/lib/backend/route-operation/read-operation-core.d.ts +55 -0
- package/lib/backend/route-operation/read-operation-core.js +151 -0
- package/lib/backend/route-operation/write-operation-core.d.ts +94 -0
- package/lib/backend/route-operation/write-operation-core.js +181 -0
- package/lib/backend/sqlite/route-operation/delete-operation.d.ts +9 -20
- package/lib/backend/sqlite/route-operation/delete-operation.js +7 -52
- package/lib/backend/sqlite/route-operation/get-list-operation.d.ts +6 -28
- package/lib/backend/sqlite/route-operation/get-list-operation.js +7 -71
- package/lib/backend/sqlite/route-operation/get-operation.d.ts +6 -22
- package/lib/backend/sqlite/route-operation/get-operation.js +7 -67
- package/lib/backend/sqlite/route-operation/index.d.ts +1 -0
- package/lib/backend/sqlite/route-operation/index.js +3 -1
- package/lib/backend/sqlite/route-operation/post-operation.d.ts +6 -26
- package/lib/backend/sqlite/route-operation/post-operation.js +7 -71
- package/lib/backend/sqlite/route-operation/put-operation.d.ts +6 -25
- package/lib/backend/sqlite/route-operation/put-operation.js +7 -68
- package/lib/backend/sqlite/schemas/index.d.ts +69 -5
- package/package.json +1 -1
|
@@ -0,0 +1,390 @@
|
|
|
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
9
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
10
|
+
import { routeOperation, TypedNextResponse } from "next-rest-framework";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { createOpenApiOperation } from "./open-api-operation.js";
|
|
13
|
+
import { getDefaultTags, handleOperationError, readPostBody } from "./operation-common.js";
|
|
14
|
+
|
|
15
|
+
// ==============================================================================
|
|
16
|
+
// POST create operation
|
|
17
|
+
// ==============================================================================
|
|
18
|
+
|
|
19
|
+
export function createPostOperationFactory(_ref) {
|
|
20
|
+
var createAction = _ref.createAction,
|
|
21
|
+
getTableName = _ref.getTableName;
|
|
22
|
+
return function (_ref2) {
|
|
23
|
+
var db = _ref2.db,
|
|
24
|
+
getSession = _ref2.getSession;
|
|
25
|
+
return function (_ref3) {
|
|
26
|
+
var schemas = _ref3.schemas,
|
|
27
|
+
_ref3$contentType = _ref3.contentType,
|
|
28
|
+
contentType = _ref3$contentType === void 0 ? "application/json" : _ref3$contentType,
|
|
29
|
+
openApiOperation = _ref3.openApiOperation,
|
|
30
|
+
parseBody = _ref3.parseBody,
|
|
31
|
+
setBody = _ref3.setBody,
|
|
32
|
+
table = _ref3.table,
|
|
33
|
+
handler = _ref3.handler,
|
|
34
|
+
catchHandler = _ref3.catch;
|
|
35
|
+
return routeOperation({
|
|
36
|
+
method: "POST",
|
|
37
|
+
openApiOperation: createOpenApiOperation({
|
|
38
|
+
defaultTags: getDefaultTags({
|
|
39
|
+
getTableName: getTableName,
|
|
40
|
+
table: table
|
|
41
|
+
}),
|
|
42
|
+
openApiOperation: openApiOperation
|
|
43
|
+
})
|
|
44
|
+
}).input({
|
|
45
|
+
body: schemas.body,
|
|
46
|
+
contentType: contentType
|
|
47
|
+
}).outputs([{
|
|
48
|
+
body: schemas.response || z.object({
|
|
49
|
+
id: z.string()
|
|
50
|
+
}),
|
|
51
|
+
contentType: "application/json",
|
|
52
|
+
status: 200
|
|
53
|
+
}]).handler( /*#__PURE__*/function () {
|
|
54
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
|
|
55
|
+
var _ref5, userId, body, extraBody, params, raw, data;
|
|
56
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
57
|
+
while (1) switch (_context.prev = _context.next) {
|
|
58
|
+
case 0:
|
|
59
|
+
_context.prev = 0;
|
|
60
|
+
_context.next = 3;
|
|
61
|
+
return getSession(req);
|
|
62
|
+
case 3:
|
|
63
|
+
_context.t0 = _context.sent;
|
|
64
|
+
if (_context.t0) {
|
|
65
|
+
_context.next = 6;
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
_context.t0 = {};
|
|
69
|
+
case 6:
|
|
70
|
+
_ref5 = _context.t0;
|
|
71
|
+
userId = _ref5.userId;
|
|
72
|
+
_context.next = 10;
|
|
73
|
+
return readPostBody(req, {
|
|
74
|
+
contentType: contentType,
|
|
75
|
+
parseBody: parseBody
|
|
76
|
+
});
|
|
77
|
+
case 10:
|
|
78
|
+
body = _context.sent;
|
|
79
|
+
_context.next = 13;
|
|
80
|
+
return setBody === null || setBody === void 0 ? void 0 : setBody(req);
|
|
81
|
+
case 13:
|
|
82
|
+
_context.t1 = _context.sent;
|
|
83
|
+
if (_context.t1) {
|
|
84
|
+
_context.next = 16;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
_context.t1 = {};
|
|
88
|
+
case 16:
|
|
89
|
+
extraBody = _context.t1;
|
|
90
|
+
params = _objectSpread(_objectSpread({
|
|
91
|
+
creatorId: userId
|
|
92
|
+
}, body), extraBody);
|
|
93
|
+
if (!(table && db)) {
|
|
94
|
+
_context.next = 24;
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
_context.next = 21;
|
|
98
|
+
return createAction({
|
|
99
|
+
bodySchema: schemas.body,
|
|
100
|
+
db: db,
|
|
101
|
+
table: table
|
|
102
|
+
})(params);
|
|
103
|
+
case 21:
|
|
104
|
+
_context.t2 = _context.sent[0];
|
|
105
|
+
_context.next = 25;
|
|
106
|
+
break;
|
|
107
|
+
case 24:
|
|
108
|
+
_context.t2 = params;
|
|
109
|
+
case 25:
|
|
110
|
+
raw = _context.t2;
|
|
111
|
+
if (!handler) {
|
|
112
|
+
_context.next = 32;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
_context.next = 29;
|
|
116
|
+
return handler({
|
|
117
|
+
data: raw,
|
|
118
|
+
params: params,
|
|
119
|
+
req: req
|
|
120
|
+
});
|
|
121
|
+
case 29:
|
|
122
|
+
_context.t3 = _context.sent;
|
|
123
|
+
_context.next = 33;
|
|
124
|
+
break;
|
|
125
|
+
case 32:
|
|
126
|
+
_context.t3 = raw;
|
|
127
|
+
case 33:
|
|
128
|
+
data = _context.t3;
|
|
129
|
+
return _context.abrupt("return", TypedNextResponse.json(data, {
|
|
130
|
+
status: 200
|
|
131
|
+
}));
|
|
132
|
+
case 37:
|
|
133
|
+
_context.prev = 37;
|
|
134
|
+
_context.t4 = _context["catch"](0);
|
|
135
|
+
return _context.abrupt("return", handleOperationError(_context.t4, catchHandler));
|
|
136
|
+
case 40:
|
|
137
|
+
case "end":
|
|
138
|
+
return _context.stop();
|
|
139
|
+
}
|
|
140
|
+
}, _callee, null, [[0, 37]]);
|
|
141
|
+
}));
|
|
142
|
+
return function (_x) {
|
|
143
|
+
return _ref4.apply(this, arguments);
|
|
144
|
+
};
|
|
145
|
+
}());
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// ==============================================================================
|
|
151
|
+
// PUT update operation
|
|
152
|
+
// ==============================================================================
|
|
153
|
+
|
|
154
|
+
export function createPutOperationFactory(_ref6) {
|
|
155
|
+
var createAction = _ref6.createAction,
|
|
156
|
+
getTableName = _ref6.getTableName;
|
|
157
|
+
return function (_ref7) {
|
|
158
|
+
var db = _ref7.db,
|
|
159
|
+
getSession = _ref7.getSession;
|
|
160
|
+
return function (_ref8) {
|
|
161
|
+
var schemas = _ref8.schemas,
|
|
162
|
+
access = _ref8.access,
|
|
163
|
+
openApiOperation = _ref8.openApiOperation,
|
|
164
|
+
table = _ref8.table,
|
|
165
|
+
setBody = _ref8.setBody,
|
|
166
|
+
handler = _ref8.handler,
|
|
167
|
+
catchHandler = _ref8.catch;
|
|
168
|
+
return routeOperation({
|
|
169
|
+
method: "PUT",
|
|
170
|
+
openApiOperation: createOpenApiOperation({
|
|
171
|
+
defaultTags: getDefaultTags({
|
|
172
|
+
getTableName: getTableName,
|
|
173
|
+
table: table
|
|
174
|
+
}),
|
|
175
|
+
openApiOperation: openApiOperation
|
|
176
|
+
})
|
|
177
|
+
}).input({
|
|
178
|
+
body: schemas.body,
|
|
179
|
+
contentType: "application/json"
|
|
180
|
+
}).outputs([{
|
|
181
|
+
body: schemas.response || z.void(),
|
|
182
|
+
contentType: "application/json",
|
|
183
|
+
status: 200
|
|
184
|
+
}]).handler( /*#__PURE__*/function () {
|
|
185
|
+
var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(req) {
|
|
186
|
+
var _access$byCreator, _ref10, userId, body, extraBody, params, raw, data;
|
|
187
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
188
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
189
|
+
case 0:
|
|
190
|
+
_context2.prev = 0;
|
|
191
|
+
_context2.next = 3;
|
|
192
|
+
return getSession(req);
|
|
193
|
+
case 3:
|
|
194
|
+
_context2.t0 = _context2.sent;
|
|
195
|
+
if (_context2.t0) {
|
|
196
|
+
_context2.next = 6;
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
_context2.t0 = {};
|
|
200
|
+
case 6:
|
|
201
|
+
_ref10 = _context2.t0;
|
|
202
|
+
userId = _ref10.userId;
|
|
203
|
+
_context2.next = 10;
|
|
204
|
+
return req.json();
|
|
205
|
+
case 10:
|
|
206
|
+
body = _context2.sent;
|
|
207
|
+
_context2.next = 13;
|
|
208
|
+
return setBody === null || setBody === void 0 ? void 0 : setBody(req);
|
|
209
|
+
case 13:
|
|
210
|
+
_context2.t1 = _context2.sent;
|
|
211
|
+
if (_context2.t1) {
|
|
212
|
+
_context2.next = 16;
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
_context2.t1 = {};
|
|
216
|
+
case 16:
|
|
217
|
+
extraBody = _context2.t1;
|
|
218
|
+
params = _objectSpread(_objectSpread({
|
|
219
|
+
editorId: userId
|
|
220
|
+
}, body), extraBody);
|
|
221
|
+
if (!(table && db)) {
|
|
222
|
+
_context2.next = 24;
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
_context2.next = 21;
|
|
226
|
+
return createAction({
|
|
227
|
+
bodySchema: schemas.body,
|
|
228
|
+
db: db,
|
|
229
|
+
table: table
|
|
230
|
+
})(params, {
|
|
231
|
+
byCreator: (_access$byCreator = access === null || access === void 0 ? void 0 : access.byCreator) !== null && _access$byCreator !== void 0 ? _access$byCreator : true
|
|
232
|
+
});
|
|
233
|
+
case 21:
|
|
234
|
+
_context2.t2 = _context2.sent;
|
|
235
|
+
_context2.next = 25;
|
|
236
|
+
break;
|
|
237
|
+
case 24:
|
|
238
|
+
_context2.t2 = params;
|
|
239
|
+
case 25:
|
|
240
|
+
raw = _context2.t2;
|
|
241
|
+
if (!handler) {
|
|
242
|
+
_context2.next = 32;
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
_context2.next = 29;
|
|
246
|
+
return handler({
|
|
247
|
+
data: raw,
|
|
248
|
+
params: params,
|
|
249
|
+
req: req
|
|
250
|
+
});
|
|
251
|
+
case 29:
|
|
252
|
+
_context2.t3 = _context2.sent;
|
|
253
|
+
_context2.next = 33;
|
|
254
|
+
break;
|
|
255
|
+
case 32:
|
|
256
|
+
_context2.t3 = raw;
|
|
257
|
+
case 33:
|
|
258
|
+
data = _context2.t3;
|
|
259
|
+
return _context2.abrupt("return", TypedNextResponse.json(data, {
|
|
260
|
+
status: 200
|
|
261
|
+
}));
|
|
262
|
+
case 37:
|
|
263
|
+
_context2.prev = 37;
|
|
264
|
+
_context2.t4 = _context2["catch"](0);
|
|
265
|
+
return _context2.abrupt("return", handleOperationError(_context2.t4, catchHandler));
|
|
266
|
+
case 40:
|
|
267
|
+
case "end":
|
|
268
|
+
return _context2.stop();
|
|
269
|
+
}
|
|
270
|
+
}, _callee2, null, [[0, 37]]);
|
|
271
|
+
}));
|
|
272
|
+
return function (_x2) {
|
|
273
|
+
return _ref9.apply(this, arguments);
|
|
274
|
+
};
|
|
275
|
+
}());
|
|
276
|
+
};
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// ==============================================================================
|
|
281
|
+
// DELETE operation
|
|
282
|
+
// ==============================================================================
|
|
283
|
+
|
|
284
|
+
var defaultDeleteBodySchema = z.object({
|
|
285
|
+
id: z.string()
|
|
286
|
+
});
|
|
287
|
+
export function createDeleteOperationFactory(_ref11) {
|
|
288
|
+
var createAction = _ref11.createAction,
|
|
289
|
+
getTableName = _ref11.getTableName;
|
|
290
|
+
return function (_ref12) {
|
|
291
|
+
var db = _ref12.db,
|
|
292
|
+
getSession = _ref12.getSession;
|
|
293
|
+
return function (_ref13) {
|
|
294
|
+
var table = _ref13.table,
|
|
295
|
+
schemas = _ref13.schemas,
|
|
296
|
+
access = _ref13.access,
|
|
297
|
+
openApiOperation = _ref13.openApiOperation,
|
|
298
|
+
handler = _ref13.handler,
|
|
299
|
+
catchHandler = _ref13.catch;
|
|
300
|
+
return routeOperation({
|
|
301
|
+
method: "DELETE",
|
|
302
|
+
openApiOperation: createOpenApiOperation({
|
|
303
|
+
defaultTags: getDefaultTags({
|
|
304
|
+
getTableName: getTableName,
|
|
305
|
+
table: table
|
|
306
|
+
}),
|
|
307
|
+
openApiOperation: openApiOperation
|
|
308
|
+
})
|
|
309
|
+
}).input({
|
|
310
|
+
body: (schemas === null || schemas === void 0 ? void 0 : schemas.body) || defaultDeleteBodySchema,
|
|
311
|
+
contentType: "application/json"
|
|
312
|
+
}).handler( /*#__PURE__*/function () {
|
|
313
|
+
var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(req) {
|
|
314
|
+
var _access$byCreator2, bodySchema, body, _ref15, userId, data;
|
|
315
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
316
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
317
|
+
case 0:
|
|
318
|
+
_context3.prev = 0;
|
|
319
|
+
bodySchema = (schemas === null || schemas === void 0 ? void 0 : schemas.body) || defaultDeleteBodySchema;
|
|
320
|
+
_context3.t0 = bodySchema;
|
|
321
|
+
_context3.next = 5;
|
|
322
|
+
return req.json();
|
|
323
|
+
case 5:
|
|
324
|
+
_context3.t1 = _context3.sent;
|
|
325
|
+
body = _context3.t0.parse.call(_context3.t0, _context3.t1);
|
|
326
|
+
if (!((_access$byCreator2 = access === null || access === void 0 ? void 0 : access.byCreator) !== null && _access$byCreator2 !== void 0 ? _access$byCreator2 : true)) {
|
|
327
|
+
_context3.next = 16;
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
_context3.next = 10;
|
|
331
|
+
return getSession(req);
|
|
332
|
+
case 10:
|
|
333
|
+
_context3.t2 = _context3.sent;
|
|
334
|
+
if (_context3.t2) {
|
|
335
|
+
_context3.next = 13;
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
_context3.t2 = {};
|
|
339
|
+
case 13:
|
|
340
|
+
_ref15 = _context3.t2;
|
|
341
|
+
userId = _ref15.userId;
|
|
342
|
+
body.creatorId = userId;
|
|
343
|
+
case 16:
|
|
344
|
+
if (!(table && db)) {
|
|
345
|
+
_context3.next = 22;
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
_context3.next = 19;
|
|
349
|
+
return createAction({
|
|
350
|
+
db: db,
|
|
351
|
+
table: table
|
|
352
|
+
})({
|
|
353
|
+
creatorId: body.creatorId,
|
|
354
|
+
id: body.id
|
|
355
|
+
});
|
|
356
|
+
case 19:
|
|
357
|
+
_context3.t3 = _context3.sent;
|
|
358
|
+
_context3.next = 23;
|
|
359
|
+
break;
|
|
360
|
+
case 22:
|
|
361
|
+
_context3.t3 = body;
|
|
362
|
+
case 23:
|
|
363
|
+
data = _context3.t3;
|
|
364
|
+
_context3.next = 26;
|
|
365
|
+
return handler === null || handler === void 0 ? void 0 : handler({
|
|
366
|
+
data: data,
|
|
367
|
+
params: body,
|
|
368
|
+
req: req
|
|
369
|
+
});
|
|
370
|
+
case 26:
|
|
371
|
+
return _context3.abrupt("return", TypedNextResponse.json(data, {
|
|
372
|
+
status: 200
|
|
373
|
+
}));
|
|
374
|
+
case 29:
|
|
375
|
+
_context3.prev = 29;
|
|
376
|
+
_context3.t4 = _context3["catch"](0);
|
|
377
|
+
return _context3.abrupt("return", handleOperationError(_context3.t4, catchHandler));
|
|
378
|
+
case 32:
|
|
379
|
+
case "end":
|
|
380
|
+
return _context3.stop();
|
|
381
|
+
}
|
|
382
|
+
}, _callee3, null, [[0, 29]]);
|
|
383
|
+
}));
|
|
384
|
+
return function (_x3) {
|
|
385
|
+
return _ref14.apply(this, arguments);
|
|
386
|
+
};
|
|
387
|
+
}());
|
|
388
|
+
};
|
|
389
|
+
};
|
|
390
|
+
}
|
|
@@ -1,24 +1,13 @@
|
|
|
1
|
-
import { TypedNextResponse } from "next-rest-framework";
|
|
2
|
-
import { BaseTable } from "../types.js";
|
|
3
1
|
import { NextRequest } from "next/server";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
tags?: string[];
|
|
9
|
-
onSuccess?: (_payload: {
|
|
10
|
-
params: {
|
|
11
|
-
id: string;
|
|
12
|
-
creatorId?: string;
|
|
13
|
-
};
|
|
14
|
-
data: unknown;
|
|
15
|
-
}) => Promise<void>;
|
|
16
|
-
onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
17
|
-
byCreator?: boolean;
|
|
18
|
-
}
|
|
2
|
+
import { ZodSchema } from "zod";
|
|
3
|
+
import { BaseTable } from "../types.js";
|
|
4
|
+
import { type DeleteOperationOptions as CoreDeleteOperationOptions } from "../../route-operation/operation-core.js";
|
|
5
|
+
export type DeleteOperationOptions<TTable extends BaseTable, B extends ZodSchema> = CoreDeleteOperationOptions<TTable, B>;
|
|
19
6
|
export declare const createDeleteOperation: ({ db, getSession, }: {
|
|
20
|
-
db?:
|
|
21
|
-
getSession
|
|
7
|
+
db?: unknown;
|
|
8
|
+
getSession(req: NextRequest): Promise<{
|
|
22
9
|
userId?: string;
|
|
23
10
|
} | undefined>;
|
|
24
|
-
}) => <
|
|
11
|
+
}) => <B extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>> = import("zod").ZodObject<{
|
|
12
|
+
id: import("zod").ZodString;
|
|
13
|
+
}, import("zod/v4/core").$strip>>({ table, schemas, access, openApiOperation, handler, catch: catchHandler, }: CoreDeleteOperationOptions<BaseTable, B>) => import("next-rest-framework").RouteOperationDefinition<"DELETE">;
|
|
@@ -1,127 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 { routeOperation, TypedNextResponse } from "next-rest-framework";
|
|
6
|
-
import { z } from "zod";
|
|
1
|
+
import { createDeleteAction } from "../actions/create-delete-action.js";
|
|
2
|
+
import { createDeleteOperationFactory } from "../../route-operation/operation-core.js";
|
|
7
3
|
import getTableName from "./get-table-name.js";
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
var createOperation = createDeleteOperationFactory({
|
|
5
|
+
createAction: createDeleteAction,
|
|
6
|
+
getTableName: getTableName
|
|
7
|
+
});
|
|
10
8
|
export var createDeleteOperation = function createDeleteOperation(_ref) {
|
|
11
9
|
var db = _ref.db,
|
|
12
10
|
getSession = _ref.getSession;
|
|
13
|
-
return
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
tags = _ref2.tags,
|
|
18
|
-
onSuccess = _ref2.onSuccess,
|
|
19
|
-
onError = _ref2.onError,
|
|
20
|
-
_ref2$byCreator = _ref2.byCreator,
|
|
21
|
-
byCreator = _ref2$byCreator === void 0 ? true : _ref2$byCreator;
|
|
22
|
-
return routeOperation({
|
|
23
|
-
method: "DELETE",
|
|
24
|
-
openApiOperation: {
|
|
25
|
-
description: description,
|
|
26
|
-
summary: summary,
|
|
27
|
-
tags: tags !== null && tags !== void 0 ? tags : table ? [getTableName(table)] : []
|
|
28
|
-
}
|
|
29
|
-
}).input({
|
|
30
|
-
body: z.object({
|
|
31
|
-
id: z.string()
|
|
32
|
-
}),
|
|
33
|
-
contentType: "application/json"
|
|
34
|
-
}).handler( /*#__PURE__*/function () {
|
|
35
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
|
|
36
|
-
var body, _ref4, userId, data, response;
|
|
37
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
38
|
-
while (1) switch (_context.prev = _context.next) {
|
|
39
|
-
case 0:
|
|
40
|
-
_context.prev = 0;
|
|
41
|
-
_context.next = 3;
|
|
42
|
-
return req.json();
|
|
43
|
-
case 3:
|
|
44
|
-
body = _context.sent;
|
|
45
|
-
if (!byCreator) {
|
|
46
|
-
_context.next = 13;
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
_context.next = 7;
|
|
50
|
-
return getSession(req);
|
|
51
|
-
case 7:
|
|
52
|
-
_context.t0 = _context.sent;
|
|
53
|
-
if (_context.t0) {
|
|
54
|
-
_context.next = 10;
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
_context.t0 = {};
|
|
58
|
-
case 10:
|
|
59
|
-
_ref4 = _context.t0;
|
|
60
|
-
userId = _ref4.userId;
|
|
61
|
-
body.creatorId = userId;
|
|
62
|
-
case 13:
|
|
63
|
-
if (!(table && db)) {
|
|
64
|
-
_context.next = 19;
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
_context.next = 16;
|
|
68
|
-
return createDeleteAction({
|
|
69
|
-
table: table,
|
|
70
|
-
db: db
|
|
71
|
-
})(body);
|
|
72
|
-
case 16:
|
|
73
|
-
_context.t1 = _context.sent;
|
|
74
|
-
_context.next = 20;
|
|
75
|
-
break;
|
|
76
|
-
case 19:
|
|
77
|
-
_context.t1 = body;
|
|
78
|
-
case 20:
|
|
79
|
-
data = _context.t1;
|
|
80
|
-
_context.next = 23;
|
|
81
|
-
return onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess({
|
|
82
|
-
data: data,
|
|
83
|
-
params: body
|
|
84
|
-
});
|
|
85
|
-
case 23:
|
|
86
|
-
return _context.abrupt("return", TypedNextResponse.json(data, {
|
|
87
|
-
status: 200
|
|
88
|
-
}));
|
|
89
|
-
case 26:
|
|
90
|
-
_context.prev = 26;
|
|
91
|
-
_context.t2 = _context["catch"](0);
|
|
92
|
-
if (!(_context.t2 instanceof HttpError)) {
|
|
93
|
-
console.error(_context.t2);
|
|
94
|
-
}
|
|
95
|
-
_context.next = 31;
|
|
96
|
-
return onError === null || onError === void 0 ? void 0 : onError(_context.t2);
|
|
97
|
-
case 31:
|
|
98
|
-
response = _context.sent;
|
|
99
|
-
if (!response) {
|
|
100
|
-
_context.next = 34;
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
return _context.abrupt("return", response);
|
|
104
|
-
case 34:
|
|
105
|
-
if (!(_context.t2 instanceof HttpError)) {
|
|
106
|
-
_context.next = 36;
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
return _context.abrupt("return", TypedNextResponse.json({
|
|
110
|
-
message: _context.t2.message
|
|
111
|
-
}, {
|
|
112
|
-
status: _context.t2.status
|
|
113
|
-
}));
|
|
114
|
-
case 36:
|
|
115
|
-
throw _context.t2;
|
|
116
|
-
case 37:
|
|
117
|
-
case "end":
|
|
118
|
-
return _context.stop();
|
|
119
|
-
}
|
|
120
|
-
}, _callee, null, [[0, 26]]);
|
|
121
|
-
}));
|
|
122
|
-
return function (_x) {
|
|
123
|
-
return _ref3.apply(this, arguments);
|
|
124
|
-
};
|
|
125
|
-
}());
|
|
126
|
-
};
|
|
11
|
+
return createOperation({
|
|
12
|
+
db: db,
|
|
13
|
+
getSession: getSession
|
|
14
|
+
});
|
|
127
15
|
};
|
|
@@ -1,33 +1,11 @@
|
|
|
1
|
-
import { z, ZodSchema } from "zod";
|
|
2
1
|
import { NextRequest } from "next/server";
|
|
3
|
-
import {
|
|
2
|
+
import { ZodSchema } from "zod";
|
|
4
3
|
import { BaseTable, GetListRelations } from "../types.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
jsonArrayFields?: string[];
|
|
8
|
-
querySchema: Q;
|
|
9
|
-
relations?: GetListRelations;
|
|
10
|
-
setParams?: (_req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string, unknown>>;
|
|
11
|
-
byCreator?: boolean;
|
|
12
|
-
description?: string;
|
|
13
|
-
summary?: string;
|
|
14
|
-
tags?: string[];
|
|
15
|
-
table?: TTable;
|
|
16
|
-
onSuccess?: <D extends T>(_payload: {
|
|
17
|
-
params: Partial<z.infer<T>> & Record<string, unknown>;
|
|
18
|
-
data: {
|
|
19
|
-
data: z.infer<D>[];
|
|
20
|
-
total: number;
|
|
21
|
-
};
|
|
22
|
-
}) => Promise<{
|
|
23
|
-
data: z.infer<T>[];
|
|
24
|
-
total: number;
|
|
25
|
-
}>;
|
|
26
|
-
onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
27
|
-
}
|
|
4
|
+
import { type GetListOperationOptions as CoreGetListOperationOptions } from "../../route-operation/operation-core.js";
|
|
5
|
+
export type GetListOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> = CoreGetListOperationOptions<T, Q, TTable, GetListRelations>;
|
|
28
6
|
export declare const createGetListOperation: ({ db, getSession, }: {
|
|
29
|
-
db?:
|
|
30
|
-
getSession
|
|
7
|
+
db?: unknown;
|
|
8
|
+
getSession(req: NextRequest): Promise<{
|
|
31
9
|
userId?: string;
|
|
32
10
|
} | undefined>;
|
|
33
|
-
}) => <T extends
|
|
11
|
+
}) => <T extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, Q extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, jsonArrayFields, setParams, handler, catch: catchHandler, }: CoreGetListOperationOptions<T, Q, BaseTable, GetListRelations>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|