@ai0x0/utils 0.0.37 → 0.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/.agents/skills/ai0x0-utils/backend/SKILL.md +12 -8
  2. package/README.md +42 -1
  3. package/SKILL.md +12 -8
  4. package/es/backend/route-operation/delete-operation.d.ts +3 -2
  5. package/es/backend/route-operation/delete-operation.js +35 -22
  6. package/es/backend/route-operation/get-list-operation.d.ts +6 -5
  7. package/es/backend/route-operation/get-list-operation.js +37 -22
  8. package/es/backend/route-operation/get-operation.d.ts +5 -4
  9. package/es/backend/route-operation/get-operation.js +34 -22
  10. package/es/backend/route-operation/post-operation.d.ts +5 -4
  11. package/es/backend/route-operation/post-operation.js +39 -34
  12. package/es/backend/route-operation/put-operation.d.ts +5 -4
  13. package/es/backend/route-operation/put-operation.js +44 -29
  14. package/es/backend/sqlite/actions/create-delete-action.d.ts +8 -0
  15. package/es/backend/sqlite/actions/create-delete-action.js +54 -0
  16. package/es/backend/sqlite/actions/create-get-action.d.ts +8 -0
  17. package/es/backend/sqlite/actions/create-get-action.js +64 -0
  18. package/es/backend/sqlite/actions/create-get-list-action.d.ts +11 -0
  19. package/es/backend/sqlite/actions/create-get-list-action.js +56 -0
  20. package/es/backend/sqlite/actions/create-post-action.d.ts +6 -0
  21. package/es/backend/sqlite/actions/create-post-action.js +31 -0
  22. package/es/backend/sqlite/actions/create-put-action.d.ts +8 -0
  23. package/es/backend/sqlite/actions/create-put-action.js +74 -0
  24. package/es/backend/sqlite/actions/get-list-data.d.ts +9 -0
  25. package/es/backend/sqlite/actions/get-list-data.js +75 -0
  26. package/es/backend/sqlite/actions/get-list-query.d.ts +19 -0
  27. package/es/backend/sqlite/actions/get-list-query.js +215 -0
  28. package/es/backend/sqlite/actions/index.d.ts +6 -0
  29. package/es/backend/sqlite/actions/index.js +6 -0
  30. package/es/backend/sqlite/actions/transform-body.d.ts +1 -0
  31. package/es/backend/sqlite/actions/transform-body.js +9 -0
  32. package/es/backend/sqlite/errors.d.ts +4 -0
  33. package/es/backend/sqlite/errors.js +31 -0
  34. package/es/backend/sqlite/index.d.ts +5 -0
  35. package/es/backend/sqlite/index.js +5 -0
  36. package/es/backend/sqlite/route-operation/delete-operation.d.ts +11 -0
  37. package/es/backend/sqlite/route-operation/delete-operation.js +122 -0
  38. package/es/backend/sqlite/route-operation/get-list-operation.d.ts +23 -0
  39. package/es/backend/sqlite/route-operation/get-list-operation.js +135 -0
  40. package/es/backend/sqlite/route-operation/get-operation.d.ts +17 -0
  41. package/es/backend/sqlite/route-operation/get-operation.js +132 -0
  42. package/es/backend/sqlite/route-operation/get-table-name.d.ts +3 -0
  43. package/es/backend/sqlite/route-operation/get-table-name.js +11 -0
  44. package/es/backend/sqlite/route-operation/index.d.ts +5 -0
  45. package/es/backend/sqlite/route-operation/index.js +5 -0
  46. package/es/backend/sqlite/route-operation/post-operation.d.ts +14 -0
  47. package/es/backend/sqlite/route-operation/post-operation.js +141 -0
  48. package/es/backend/sqlite/route-operation/put-operation.d.ts +15 -0
  49. package/es/backend/sqlite/route-operation/put-operation.js +156 -0
  50. package/es/backend/sqlite/schemas/index.d.ts +68 -0
  51. package/es/backend/sqlite/schemas/index.js +133 -0
  52. package/es/backend/sqlite/types.d.ts +16 -0
  53. package/es/backend/sqlite/types.js +1 -0
  54. package/lib/backend/route-operation/delete-operation.d.ts +3 -2
  55. package/lib/backend/route-operation/delete-operation.js +5 -3
  56. package/lib/backend/route-operation/get-list-operation.d.ts +6 -5
  57. package/lib/backend/route-operation/get-list-operation.js +8 -8
  58. package/lib/backend/route-operation/get-operation.d.ts +5 -4
  59. package/lib/backend/route-operation/get-operation.js +8 -8
  60. package/lib/backend/route-operation/post-operation.d.ts +5 -4
  61. package/lib/backend/route-operation/post-operation.js +4 -3
  62. package/lib/backend/route-operation/put-operation.d.ts +5 -4
  63. package/lib/backend/route-operation/put-operation.js +6 -4
  64. package/lib/backend/sqlite/actions/create-delete-action.d.ts +8 -0
  65. package/lib/backend/sqlite/actions/create-delete-action.js +53 -0
  66. package/lib/backend/sqlite/actions/create-get-action.d.ts +8 -0
  67. package/lib/backend/sqlite/actions/create-get-action.js +65 -0
  68. package/lib/backend/sqlite/actions/create-get-list-action.d.ts +11 -0
  69. package/lib/backend/sqlite/actions/create-get-list-action.js +63 -0
  70. package/lib/backend/sqlite/actions/create-post-action.d.ts +6 -0
  71. package/lib/backend/sqlite/actions/create-post-action.js +39 -0
  72. package/lib/backend/sqlite/actions/create-put-action.d.ts +8 -0
  73. package/lib/backend/sqlite/actions/create-put-action.js +60 -0
  74. package/lib/backend/sqlite/actions/get-list-data.d.ts +9 -0
  75. package/lib/backend/sqlite/actions/get-list-data.js +51 -0
  76. package/lib/backend/sqlite/actions/get-list-query.d.ts +19 -0
  77. package/lib/backend/sqlite/actions/get-list-query.js +165 -0
  78. package/lib/backend/sqlite/actions/index.d.ts +6 -0
  79. package/lib/backend/sqlite/actions/index.js +44 -0
  80. package/lib/backend/sqlite/actions/transform-body.d.ts +1 -0
  81. package/lib/backend/sqlite/actions/transform-body.js +49 -0
  82. package/lib/backend/sqlite/errors.d.ts +4 -0
  83. package/lib/backend/sqlite/errors.js +35 -0
  84. package/lib/backend/sqlite/index.d.ts +5 -0
  85. package/lib/backend/sqlite/index.js +31 -0
  86. package/lib/backend/sqlite/route-operation/delete-operation.d.ts +11 -0
  87. package/lib/backend/sqlite/route-operation/delete-operation.js +92 -0
  88. package/lib/backend/sqlite/route-operation/get-list-operation.d.ts +23 -0
  89. package/lib/backend/sqlite/route-operation/get-list-operation.js +108 -0
  90. package/lib/backend/sqlite/route-operation/get-operation.d.ts +17 -0
  91. package/lib/backend/sqlite/route-operation/get-operation.js +107 -0
  92. package/lib/backend/sqlite/route-operation/get-table-name.d.ts +3 -0
  93. package/lib/backend/sqlite/route-operation/get-table-name.js +35 -0
  94. package/lib/backend/sqlite/route-operation/index.d.ts +5 -0
  95. package/lib/backend/sqlite/route-operation/index.js +31 -0
  96. package/lib/backend/sqlite/route-operation/post-operation.d.ts +14 -0
  97. package/lib/backend/sqlite/route-operation/post-operation.js +95 -0
  98. package/lib/backend/sqlite/route-operation/put-operation.d.ts +15 -0
  99. package/lib/backend/sqlite/route-operation/put-operation.js +104 -0
  100. package/lib/backend/sqlite/schemas/index.d.ts +68 -0
  101. package/lib/backend/sqlite/schemas/index.js +113 -0
  102. package/lib/backend/sqlite/types.d.ts +16 -0
  103. package/lib/backend/sqlite/types.js +17 -0
  104. package/package.json +3 -1
@@ -0,0 +1,122 @@
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 { z } from "zod";
7
+ import getTableName from "./get-table-name.js";
8
+ import { createDeleteAction } from "../actions/index.js";
9
+ import { HttpError } from "../errors.js";
10
+ export var createDeleteOperation = function createDeleteOperation(_ref) {
11
+ var db = _ref.db,
12
+ getSession = _ref.getSession;
13
+ return function (_ref2) {
14
+ var table = _ref2.table,
15
+ summary = _ref2.summary,
16
+ tags = _ref2.tags,
17
+ onSuccess = _ref2.onSuccess,
18
+ onError = _ref2.onError,
19
+ _ref2$byCreator = _ref2.byCreator,
20
+ byCreator = _ref2$byCreator === void 0 ? true : _ref2$byCreator;
21
+ return routeOperation({
22
+ method: "DELETE",
23
+ openApiOperation: {
24
+ summary: summary,
25
+ tags: tags !== null && tags !== void 0 ? tags : table ? [getTableName(table)] : []
26
+ }
27
+ }).input({
28
+ body: z.object({
29
+ id: z.string()
30
+ }),
31
+ contentType: "application/json"
32
+ }).handler( /*#__PURE__*/function () {
33
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
34
+ var body, _ref4, userId, data, response;
35
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
36
+ while (1) switch (_context.prev = _context.next) {
37
+ case 0:
38
+ _context.prev = 0;
39
+ _context.next = 3;
40
+ return req.json();
41
+ case 3:
42
+ body = _context.sent;
43
+ if (!byCreator) {
44
+ _context.next = 13;
45
+ break;
46
+ }
47
+ _context.next = 7;
48
+ return getSession(req);
49
+ case 7:
50
+ _context.t0 = _context.sent;
51
+ if (_context.t0) {
52
+ _context.next = 10;
53
+ break;
54
+ }
55
+ _context.t0 = {};
56
+ case 10:
57
+ _ref4 = _context.t0;
58
+ userId = _ref4.userId;
59
+ body.creatorId = userId;
60
+ case 13:
61
+ if (!table) {
62
+ _context.next = 19;
63
+ break;
64
+ }
65
+ _context.next = 16;
66
+ return createDeleteAction({
67
+ table: table,
68
+ db: db
69
+ })(body);
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
+ case 23:
81
+ return _context.abrupt("return", TypedNextResponse.json(data, {
82
+ status: 200
83
+ }));
84
+ case 26:
85
+ _context.prev = 26;
86
+ _context.t2 = _context["catch"](0);
87
+ if (!(_context.t2 instanceof HttpError)) {
88
+ console.error(_context.t2);
89
+ }
90
+ _context.next = 31;
91
+ return onError === null || onError === void 0 ? void 0 : onError(_context.t2);
92
+ case 31:
93
+ response = _context.sent;
94
+ if (!response) {
95
+ _context.next = 34;
96
+ break;
97
+ }
98
+ return _context.abrupt("return", response);
99
+ case 34:
100
+ if (!(_context.t2 instanceof HttpError)) {
101
+ _context.next = 36;
102
+ break;
103
+ }
104
+ return _context.abrupt("return", TypedNextResponse.json({
105
+ message: _context.t2.message
106
+ }, {
107
+ status: _context.t2.status
108
+ }));
109
+ case 36:
110
+ throw _context.t2;
111
+ case 37:
112
+ case "end":
113
+ return _context.stop();
114
+ }
115
+ }, _callee, null, [[0, 26]]);
116
+ }));
117
+ return function (_x) {
118
+ return _ref3.apply(this, arguments);
119
+ };
120
+ }());
121
+ };
122
+ };
@@ -0,0 +1,23 @@
1
+ import { z, ZodSchema } from "zod";
2
+ import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
3
+ import { BaseTable, GetListRelations } from "../types.js";
4
+ export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> {
5
+ bodySchema: T;
6
+ jsonArrayFields?: string[];
7
+ querySchema: Q;
8
+ relations?: GetListRelations;
9
+ setParams?: (_req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string, unknown>>;
10
+ byCreator?: boolean;
11
+ summary?: string;
12
+ tags?: string[];
13
+ table?: TTable;
14
+ onSuccess?: <D extends T>(_data: {
15
+ data: z.infer<D>[];
16
+ total: number;
17
+ }) => Promise<{
18
+ data: z.infer<T>[];
19
+ total: number;
20
+ }>;
21
+ onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
22
+ }
23
+ export declare const createGetListOperation: any;
@@ -0,0 +1,135 @@
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 getTableName from "./get-table-name.js";
7
+ import { listBodySchema } from "../schemas/index.js";
8
+ import { createGetListAction } from "../actions/index.js";
9
+ export var createGetListOperation = function createGetListOperation(_ref) {
10
+ var db = _ref.db,
11
+ getSession = _ref.getSession;
12
+ return function (_ref2) {
13
+ var querySchema = _ref2.querySchema,
14
+ bodySchema = _ref2.bodySchema,
15
+ table = _ref2.table,
16
+ summary = _ref2.summary,
17
+ tags = _ref2.tags,
18
+ relations = _ref2.relations,
19
+ jsonArrayFields = _ref2.jsonArrayFields,
20
+ setParams = _ref2.setParams,
21
+ onSuccess = _ref2.onSuccess,
22
+ onError = _ref2.onError,
23
+ _ref2$byCreator = _ref2.byCreator,
24
+ byCreator = _ref2$byCreator === void 0 ? true : _ref2$byCreator;
25
+ return routeOperation({
26
+ method: "GET",
27
+ openApiOperation: {
28
+ summary: summary,
29
+ tags: tags !== null && tags !== void 0 ? tags : table ? [getTableName(table)] : []
30
+ }
31
+ }).input({
32
+ query: querySchema
33
+ }).outputs([{
34
+ body: listBodySchema(bodySchema),
35
+ contentType: "application/json",
36
+ status: 200
37
+ }]).handler( /*#__PURE__*/function () {
38
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
39
+ var params, _ref4, userId, mergedParams, result, response;
40
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
41
+ while (1) switch (_context.prev = _context.next) {
42
+ case 0:
43
+ _context.prev = 0;
44
+ _context.next = 3;
45
+ return setParams === null || setParams === void 0 ? void 0 : setParams(req);
46
+ case 3:
47
+ _context.t0 = _context.sent;
48
+ if (_context.t0) {
49
+ _context.next = 6;
50
+ break;
51
+ }
52
+ _context.t0 = {};
53
+ case 6:
54
+ params = _context.t0;
55
+ if (!byCreator) {
56
+ _context.next = 16;
57
+ break;
58
+ }
59
+ _context.next = 10;
60
+ return getSession(req);
61
+ case 10:
62
+ _context.t1 = _context.sent;
63
+ if (_context.t1) {
64
+ _context.next = 13;
65
+ break;
66
+ }
67
+ _context.t1 = {};
68
+ case 13:
69
+ _ref4 = _context.t1;
70
+ userId = _ref4.userId;
71
+ params.creatorId = userId;
72
+ case 16:
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;
79
+ return createGetListAction({
80
+ bodySchema: bodySchema,
81
+ db: db,
82
+ jsonArrayFields: jsonArrayFields,
83
+ relations: relations,
84
+ table: table
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;
97
+ if (!onSuccess) {
98
+ _context.next = 29;
99
+ break;
100
+ }
101
+ _context.next = 28;
102
+ return onSuccess(result);
103
+ case 28:
104
+ result = _context.sent;
105
+ case 29:
106
+ return _context.abrupt("return", TypedNextResponse.json(result, {
107
+ status: 200
108
+ }));
109
+ case 32:
110
+ _context.prev = 32;
111
+ _context.t3 = _context["catch"](0);
112
+ console.error(_context.t3);
113
+ _context.next = 37;
114
+ return onError === null || onError === void 0 ? void 0 : onError(_context.t3);
115
+ case 37:
116
+ response = _context.sent;
117
+ if (!response) {
118
+ _context.next = 42;
119
+ break;
120
+ }
121
+ return _context.abrupt("return", response);
122
+ case 42:
123
+ throw _context.t3;
124
+ case 43:
125
+ case "end":
126
+ return _context.stop();
127
+ }
128
+ }, _callee, null, [[0, 32]]);
129
+ }));
130
+ return function (_x) {
131
+ return _ref3.apply(this, arguments);
132
+ };
133
+ }());
134
+ };
135
+ };
@@ -0,0 +1,17 @@
1
+ import { z, ZodSchema } from "zod";
2
+ import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
3
+ import { BaseTable, GetListRelations } from "../types.js";
4
+ export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> {
5
+ bodySchema: T;
6
+ jsonArrayFields?: string[];
7
+ querySchema: Q;
8
+ relations?: GetListRelations;
9
+ setParams?: (_req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string, unknown>>;
10
+ onSuccess?: (_data: z.infer<T>) => Promise<z.infer<T>>;
11
+ onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
12
+ summary?: string;
13
+ tags?: string[];
14
+ table?: TTable;
15
+ byCreator?: boolean;
16
+ }
17
+ export declare const createGetOperation: any;
@@ -0,0 +1,132 @@
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 getTableName from "./get-table-name.js";
7
+ import { createGetAction } from "../actions/index.js";
8
+ export var createGetOperation = function createGetOperation(_ref) {
9
+ var getSession = _ref.getSession,
10
+ db = _ref.db;
11
+ return function (_ref2) {
12
+ var querySchema = _ref2.querySchema,
13
+ bodySchema = _ref2.bodySchema,
14
+ table = _ref2.table,
15
+ summary = _ref2.summary,
16
+ tags = _ref2.tags,
17
+ relations = _ref2.relations,
18
+ setParams = _ref2.setParams,
19
+ jsonArrayFields = _ref2.jsonArrayFields,
20
+ onSuccess = _ref2.onSuccess,
21
+ onError = _ref2.onError,
22
+ _ref2$byCreator = _ref2.byCreator,
23
+ byCreator = _ref2$byCreator === void 0 ? true : _ref2$byCreator;
24
+ return routeOperation({
25
+ method: "GET",
26
+ openApiOperation: {
27
+ summary: summary,
28
+ tags: tags !== null && tags !== void 0 ? tags : table ? [getTableName(table)] : []
29
+ }
30
+ }).input({
31
+ query: querySchema
32
+ }).outputs([{
33
+ body: bodySchema,
34
+ contentType: "application/json",
35
+ status: 200
36
+ }]).handler( /*#__PURE__*/function () {
37
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
38
+ var params, _ref4, userId, mergedParams, rawResult, result, response;
39
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
40
+ while (1) switch (_context.prev = _context.next) {
41
+ case 0:
42
+ _context.prev = 0;
43
+ _context.next = 3;
44
+ return setParams === null || setParams === void 0 ? void 0 : setParams(req);
45
+ case 3:
46
+ _context.t0 = _context.sent;
47
+ if (_context.t0) {
48
+ _context.next = 6;
49
+ break;
50
+ }
51
+ _context.t0 = {};
52
+ case 6:
53
+ params = _context.t0;
54
+ if (!byCreator) {
55
+ _context.next = 16;
56
+ break;
57
+ }
58
+ _context.next = 10;
59
+ return getSession(req);
60
+ case 10:
61
+ _context.t1 = _context.sent;
62
+ if (_context.t1) {
63
+ _context.next = 13;
64
+ break;
65
+ }
66
+ _context.t1 = {};
67
+ case 13:
68
+ _ref4 = _context.t1;
69
+ userId = _ref4.userId;
70
+ params.creatorId = userId;
71
+ case 16:
72
+ mergedParams = Object.assign(Object.fromEntries(new URL(req.url).searchParams), params);
73
+ if (!table) {
74
+ _context.next = 23;
75
+ break;
76
+ }
77
+ _context.next = 20;
78
+ return createGetAction({
79
+ bodySchema: bodySchema,
80
+ db: db,
81
+ jsonArrayFields: jsonArrayFields,
82
+ relations: relations,
83
+ table: table
84
+ })(mergedParams);
85
+ case 20:
86
+ _context.t2 = _context.sent;
87
+ _context.next = 24;
88
+ break;
89
+ case 23:
90
+ _context.t2 = mergedParams;
91
+ case 24:
92
+ rawResult = _context.t2;
93
+ result = rawResult !== null && rawResult !== void 0 ? rawResult : {};
94
+ if (!onSuccess) {
95
+ _context.next = 30;
96
+ break;
97
+ }
98
+ _context.next = 29;
99
+ return onSuccess(result);
100
+ case 29:
101
+ result = _context.sent;
102
+ case 30:
103
+ return _context.abrupt("return", TypedNextResponse.json(result, {
104
+ status: 200
105
+ }));
106
+ case 33:
107
+ _context.prev = 33;
108
+ _context.t3 = _context["catch"](0);
109
+ console.error(_context.t3);
110
+ _context.next = 38;
111
+ return onError === null || onError === void 0 ? void 0 : onError(_context.t3);
112
+ case 38:
113
+ response = _context.sent;
114
+ if (!response) {
115
+ _context.next = 43;
116
+ break;
117
+ }
118
+ return _context.abrupt("return", response);
119
+ case 43:
120
+ throw _context.t3;
121
+ case 44:
122
+ case "end":
123
+ return _context.stop();
124
+ }
125
+ }, _callee, null, [[0, 33]]);
126
+ }));
127
+ return function (_x) {
128
+ return _ref3.apply(this, arguments);
129
+ };
130
+ }());
131
+ };
132
+ };
@@ -0,0 +1,3 @@
1
+ import { SQLiteTable } from "drizzle-orm/sqlite-core";
2
+ declare function getTableName(table: SQLiteTable): string;
3
+ export default getTableName;
@@ -0,0 +1,11 @@
1
+ function getTableName(table) {
2
+ var symbols = Object.getOwnPropertySymbols(table);
3
+ var nameSymbol = symbols.find(function (sym) {
4
+ return sym.toString() === "Symbol(drizzle:Name)";
5
+ });
6
+ if (nameSymbol) {
7
+ return table[nameSymbol];
8
+ }
9
+ return "";
10
+ }
11
+ export default getTableName;
@@ -0,0 +1,5 @@
1
+ export * from "./get-operation.js";
2
+ export * from "./get-list-operation.js";
3
+ export * from "./delete-operation.js";
4
+ export * from "./post-operation.js";
5
+ export * from "./put-operation.js";
@@ -0,0 +1,5 @@
1
+ export * from "./get-operation.js";
2
+ export * from "./get-list-operation.js";
3
+ export * from "./delete-operation.js";
4
+ export * from "./post-operation.js";
5
+ export * from "./put-operation.js";
@@ -0,0 +1,14 @@
1
+ import { z, ZodSchema } from "zod";
2
+ import { SQLiteTable } from "drizzle-orm/sqlite-core";
3
+ import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
4
+ export interface PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends SQLiteTable> {
5
+ bodySchema: IB;
6
+ outputBodySchema?: IB;
7
+ setBody?: (_req: TypedNextRequest<"POST", "application/json", z.infer<IB>>) => Promise<Partial<z.infer<IB>>>;
8
+ summary?: string;
9
+ tags?: string[];
10
+ onSuccess?: (_data: z.infer<OB>) => Promise<z.infer<OB>>;
11
+ onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
12
+ table?: TTable;
13
+ }
14
+ export declare const createPostOperation: any;