@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,224 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
|
+
import { routeOperation, TypedNextResponse } from "next-rest-framework";
|
|
6
|
+
import { listBodySchema } from "../schemas/index.js";
|
|
7
|
+
import { createOpenApiOperation } from "./open-api-operation.js";
|
|
8
|
+
import { getDefaultTags, getReadParams, handleOperationError } from "./operation-common.js";
|
|
9
|
+
|
|
10
|
+
// ==============================================================================
|
|
11
|
+
// GET single operation
|
|
12
|
+
// ==============================================================================
|
|
13
|
+
|
|
14
|
+
export function createGetOperationFactory(_ref) {
|
|
15
|
+
var createAction = _ref.createAction,
|
|
16
|
+
getTableName = _ref.getTableName;
|
|
17
|
+
return function (_ref2) {
|
|
18
|
+
var db = _ref2.db,
|
|
19
|
+
getSession = _ref2.getSession;
|
|
20
|
+
return function (_ref3) {
|
|
21
|
+
var schemas = _ref3.schemas,
|
|
22
|
+
access = _ref3.access,
|
|
23
|
+
table = _ref3.table,
|
|
24
|
+
openApiOperation = _ref3.openApiOperation,
|
|
25
|
+
relations = _ref3.relations,
|
|
26
|
+
setParams = _ref3.setParams,
|
|
27
|
+
jsonArrayFields = _ref3.jsonArrayFields,
|
|
28
|
+
handler = _ref3.handler,
|
|
29
|
+
catchHandler = _ref3.catch;
|
|
30
|
+
return routeOperation({
|
|
31
|
+
method: "GET",
|
|
32
|
+
openApiOperation: createOpenApiOperation({
|
|
33
|
+
defaultTags: getDefaultTags({
|
|
34
|
+
getTableName: getTableName,
|
|
35
|
+
table: table
|
|
36
|
+
}),
|
|
37
|
+
openApiOperation: openApiOperation
|
|
38
|
+
})
|
|
39
|
+
}).input({
|
|
40
|
+
query: schemas.query
|
|
41
|
+
}).outputs([{
|
|
42
|
+
body: schemas.response,
|
|
43
|
+
contentType: "application/json",
|
|
44
|
+
status: 200
|
|
45
|
+
}]).handler( /*#__PURE__*/function () {
|
|
46
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
|
|
47
|
+
var mergedParams, rawResult, result;
|
|
48
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
49
|
+
while (1) switch (_context.prev = _context.next) {
|
|
50
|
+
case 0:
|
|
51
|
+
_context.prev = 0;
|
|
52
|
+
_context.next = 3;
|
|
53
|
+
return getReadParams({
|
|
54
|
+
access: access,
|
|
55
|
+
getSession: getSession,
|
|
56
|
+
req: req,
|
|
57
|
+
schemas: schemas,
|
|
58
|
+
setParams: setParams
|
|
59
|
+
});
|
|
60
|
+
case 3:
|
|
61
|
+
mergedParams = _context.sent;
|
|
62
|
+
if (!(table && db)) {
|
|
63
|
+
_context.next = 10;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
_context.next = 7;
|
|
67
|
+
return createAction({
|
|
68
|
+
bodySchema: schemas.response,
|
|
69
|
+
db: db,
|
|
70
|
+
jsonArrayFields: jsonArrayFields,
|
|
71
|
+
relations: relations,
|
|
72
|
+
table: table
|
|
73
|
+
})(mergedParams);
|
|
74
|
+
case 7:
|
|
75
|
+
_context.t0 = _context.sent;
|
|
76
|
+
_context.next = 11;
|
|
77
|
+
break;
|
|
78
|
+
case 10:
|
|
79
|
+
_context.t0 = mergedParams;
|
|
80
|
+
case 11:
|
|
81
|
+
rawResult = _context.t0;
|
|
82
|
+
result = rawResult !== null && rawResult !== void 0 ? rawResult : {};
|
|
83
|
+
if (!handler) {
|
|
84
|
+
_context.next = 17;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
_context.next = 16;
|
|
88
|
+
return handler({
|
|
89
|
+
data: result,
|
|
90
|
+
params: mergedParams,
|
|
91
|
+
req: req
|
|
92
|
+
});
|
|
93
|
+
case 16:
|
|
94
|
+
result = _context.sent;
|
|
95
|
+
case 17:
|
|
96
|
+
return _context.abrupt("return", TypedNextResponse.json(result, {
|
|
97
|
+
status: 200
|
|
98
|
+
}));
|
|
99
|
+
case 20:
|
|
100
|
+
_context.prev = 20;
|
|
101
|
+
_context.t1 = _context["catch"](0);
|
|
102
|
+
return _context.abrupt("return", handleOperationError(_context.t1, catchHandler));
|
|
103
|
+
case 23:
|
|
104
|
+
case "end":
|
|
105
|
+
return _context.stop();
|
|
106
|
+
}
|
|
107
|
+
}, _callee, null, [[0, 20]]);
|
|
108
|
+
}));
|
|
109
|
+
return function (_x) {
|
|
110
|
+
return _ref4.apply(this, arguments);
|
|
111
|
+
};
|
|
112
|
+
}());
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// ==============================================================================
|
|
118
|
+
// GET list operation
|
|
119
|
+
// ==============================================================================
|
|
120
|
+
|
|
121
|
+
export function createGetListOperationFactory(_ref5) {
|
|
122
|
+
var createAction = _ref5.createAction,
|
|
123
|
+
getTableName = _ref5.getTableName;
|
|
124
|
+
return function (_ref6) {
|
|
125
|
+
var db = _ref6.db,
|
|
126
|
+
getSession = _ref6.getSession;
|
|
127
|
+
return function (_ref7) {
|
|
128
|
+
var schemas = _ref7.schemas,
|
|
129
|
+
access = _ref7.access,
|
|
130
|
+
table = _ref7.table,
|
|
131
|
+
openApiOperation = _ref7.openApiOperation,
|
|
132
|
+
relations = _ref7.relations,
|
|
133
|
+
jsonArrayFields = _ref7.jsonArrayFields,
|
|
134
|
+
setParams = _ref7.setParams,
|
|
135
|
+
handler = _ref7.handler,
|
|
136
|
+
catchHandler = _ref7.catch;
|
|
137
|
+
return routeOperation({
|
|
138
|
+
method: "GET",
|
|
139
|
+
openApiOperation: createOpenApiOperation({
|
|
140
|
+
defaultTags: getDefaultTags({
|
|
141
|
+
getTableName: getTableName,
|
|
142
|
+
table: table
|
|
143
|
+
}),
|
|
144
|
+
openApiOperation: openApiOperation
|
|
145
|
+
})
|
|
146
|
+
}).input({
|
|
147
|
+
query: schemas.query
|
|
148
|
+
}).outputs([{
|
|
149
|
+
body: listBodySchema(schemas.response),
|
|
150
|
+
contentType: "application/json",
|
|
151
|
+
status: 200
|
|
152
|
+
}]).handler( /*#__PURE__*/function () {
|
|
153
|
+
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(req) {
|
|
154
|
+
var mergedParams, result;
|
|
155
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
156
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
157
|
+
case 0:
|
|
158
|
+
_context2.prev = 0;
|
|
159
|
+
_context2.next = 3;
|
|
160
|
+
return getReadParams({
|
|
161
|
+
access: access,
|
|
162
|
+
getSession: getSession,
|
|
163
|
+
req: req,
|
|
164
|
+
schemas: schemas,
|
|
165
|
+
setParams: setParams
|
|
166
|
+
});
|
|
167
|
+
case 3:
|
|
168
|
+
mergedParams = _context2.sent;
|
|
169
|
+
if (!(table && db)) {
|
|
170
|
+
_context2.next = 10;
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
_context2.next = 7;
|
|
174
|
+
return createAction({
|
|
175
|
+
bodySchema: schemas.response,
|
|
176
|
+
db: db,
|
|
177
|
+
jsonArrayFields: jsonArrayFields,
|
|
178
|
+
relations: relations,
|
|
179
|
+
table: table
|
|
180
|
+
})(mergedParams);
|
|
181
|
+
case 7:
|
|
182
|
+
_context2.t0 = _context2.sent;
|
|
183
|
+
_context2.next = 11;
|
|
184
|
+
break;
|
|
185
|
+
case 10:
|
|
186
|
+
_context2.t0 = {
|
|
187
|
+
data: [],
|
|
188
|
+
total: 0
|
|
189
|
+
};
|
|
190
|
+
case 11:
|
|
191
|
+
result = _context2.t0;
|
|
192
|
+
if (!handler) {
|
|
193
|
+
_context2.next = 16;
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
_context2.next = 15;
|
|
197
|
+
return handler({
|
|
198
|
+
data: result,
|
|
199
|
+
params: mergedParams,
|
|
200
|
+
req: req
|
|
201
|
+
});
|
|
202
|
+
case 15:
|
|
203
|
+
result = _context2.sent;
|
|
204
|
+
case 16:
|
|
205
|
+
return _context2.abrupt("return", TypedNextResponse.json(result, {
|
|
206
|
+
status: 200
|
|
207
|
+
}));
|
|
208
|
+
case 19:
|
|
209
|
+
_context2.prev = 19;
|
|
210
|
+
_context2.t1 = _context2["catch"](0);
|
|
211
|
+
return _context2.abrupt("return", handleOperationError(_context2.t1, catchHandler));
|
|
212
|
+
case 22:
|
|
213
|
+
case "end":
|
|
214
|
+
return _context2.stop();
|
|
215
|
+
}
|
|
216
|
+
}, _callee2, null, [[0, 19]]);
|
|
217
|
+
}));
|
|
218
|
+
return function (_x2) {
|
|
219
|
+
return _ref8.apply(this, arguments);
|
|
220
|
+
};
|
|
221
|
+
}());
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { NextRequest } from "next/server";
|
|
2
|
+
import { TypedNextRequest } from "next-rest-framework";
|
|
3
|
+
import { z, ZodSchema } from "zod";
|
|
4
|
+
import { type RouteOpenApiOperation } from "./open-api-operation.js";
|
|
5
|
+
import { ActionFactory, RouteCatch, SessionGetter } from "./operation-common.js";
|
|
6
|
+
export type PostOperationParams<IB extends ZodSchema> = z.infer<IB> & Record<string, unknown> & {
|
|
7
|
+
creatorId?: string;
|
|
8
|
+
};
|
|
9
|
+
export interface PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable> {
|
|
10
|
+
schemas: {
|
|
11
|
+
body: IB;
|
|
12
|
+
response?: OB;
|
|
13
|
+
};
|
|
14
|
+
contentType?: string;
|
|
15
|
+
openApiOperation?: RouteOpenApiOperation;
|
|
16
|
+
parseBody?: (_req: NextRequest) => Promise<Record<string, unknown>>;
|
|
17
|
+
setBody?: (_req: NextRequest) => Promise<Partial<z.infer<IB>>>;
|
|
18
|
+
handler?: (_payload: {
|
|
19
|
+
params: PostOperationParams<IB>;
|
|
20
|
+
data: z.infer<OB>;
|
|
21
|
+
req: NextRequest;
|
|
22
|
+
}) => Promise<z.infer<OB>>;
|
|
23
|
+
catch?: RouteCatch;
|
|
24
|
+
table?: TTable;
|
|
25
|
+
}
|
|
26
|
+
export declare function createPostOperationFactory<TTable>({ createAction, getTableName, }: {
|
|
27
|
+
createAction: ActionFactory<TTable, (_body: Record<string, unknown>) => Promise<unknown[]>>;
|
|
28
|
+
getTableName(table: TTable): string;
|
|
29
|
+
}): ({ db, getSession }: {
|
|
30
|
+
db?: unknown;
|
|
31
|
+
getSession: SessionGetter;
|
|
32
|
+
}) => <IB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>({ schemas, contentType, openApiOperation, parseBody, setBody, table, handler, catch: catchHandler, }: PostOperationOptions<IB, OB, TTable>) => import("next-rest-framework").RouteOperationDefinition<"POST">;
|
|
33
|
+
export type PutOperationParams<IB extends ZodSchema> = z.infer<IB> & Record<string, unknown> & {
|
|
34
|
+
editorId?: string;
|
|
35
|
+
};
|
|
36
|
+
export interface PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable> {
|
|
37
|
+
schemas: {
|
|
38
|
+
body: IB;
|
|
39
|
+
response?: OB;
|
|
40
|
+
};
|
|
41
|
+
access?: {
|
|
42
|
+
byCreator?: boolean;
|
|
43
|
+
};
|
|
44
|
+
openApiOperation?: RouteOpenApiOperation;
|
|
45
|
+
table?: TTable;
|
|
46
|
+
setBody?: (_req: TypedNextRequest<"PUT", "application/json", z.infer<IB>>) => Promise<Partial<z.infer<IB>>>;
|
|
47
|
+
handler?: (_payload: {
|
|
48
|
+
params: PutOperationParams<IB>;
|
|
49
|
+
data: z.infer<OB>;
|
|
50
|
+
req: NextRequest;
|
|
51
|
+
}) => Promise<z.infer<OB>>;
|
|
52
|
+
catch?: RouteCatch;
|
|
53
|
+
}
|
|
54
|
+
export declare function createPutOperationFactory<TTable>({ createAction, getTableName, }: {
|
|
55
|
+
createAction: ActionFactory<TTable, (_body: Record<string, unknown>, _options?: {
|
|
56
|
+
byCreator?: boolean;
|
|
57
|
+
}) => Promise<unknown>>;
|
|
58
|
+
getTableName(table: TTable): string;
|
|
59
|
+
}): ({ db, getSession }: {
|
|
60
|
+
db?: unknown;
|
|
61
|
+
getSession: SessionGetter;
|
|
62
|
+
}) => <IB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>({ schemas, access, openApiOperation, table, setBody, handler, catch: catchHandler, }: PutOperationOptions<IB, OB, TTable>) => import("next-rest-framework").RouteOperationDefinition<"PUT">;
|
|
63
|
+
export type DeleteOperationParams<B extends ZodSchema> = z.infer<B> & Record<string, unknown> & {
|
|
64
|
+
creatorId?: string;
|
|
65
|
+
id: string;
|
|
66
|
+
};
|
|
67
|
+
export interface DeleteOperationOptions<TTable, B extends ZodSchema> {
|
|
68
|
+
table?: TTable;
|
|
69
|
+
schemas?: {
|
|
70
|
+
body?: B;
|
|
71
|
+
};
|
|
72
|
+
access?: {
|
|
73
|
+
byCreator?: boolean;
|
|
74
|
+
};
|
|
75
|
+
openApiOperation?: RouteOpenApiOperation;
|
|
76
|
+
handler?: (_payload: {
|
|
77
|
+
params: DeleteOperationParams<B>;
|
|
78
|
+
data: unknown;
|
|
79
|
+
req: NextRequest;
|
|
80
|
+
}) => Promise<void>;
|
|
81
|
+
catch?: RouteCatch;
|
|
82
|
+
}
|
|
83
|
+
export declare function createDeleteOperationFactory<TTable>({ createAction, getTableName, }: {
|
|
84
|
+
createAction: ActionFactory<TTable, (_params: {
|
|
85
|
+
id: string;
|
|
86
|
+
creatorId?: string;
|
|
87
|
+
}) => Promise<unknown>>;
|
|
88
|
+
getTableName(table: TTable): string;
|
|
89
|
+
}): ({ db, getSession }: {
|
|
90
|
+
db?: unknown;
|
|
91
|
+
getSession: SessionGetter;
|
|
92
|
+
}) => <B extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>> = z.ZodObject<{
|
|
93
|
+
id: z.ZodString;
|
|
94
|
+
}, z.core.$strip>>({ table, schemas, access, openApiOperation, handler, catch: catchHandler, }: DeleteOperationOptions<TTable, B>) => import("next-rest-framework").RouteOperationDefinition<"DELETE">;
|