@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.
Files changed (77) hide show
  1. package/.agents/skills/ai0x0-utils/backend/SKILL.md +40 -38
  2. package/SKILL.md +39 -37
  3. package/es/__shims__/next-rest-framework.d.ts +2 -0
  4. package/es/backend/route-operation/delete-operation.d.ts +7 -18
  5. package/es/backend/route-operation/delete-operation.js +10 -122
  6. package/es/backend/route-operation/get-list-operation.d.ts +5 -27
  7. package/es/backend/route-operation/get-list-operation.js +10 -135
  8. package/es/backend/route-operation/get-operation.d.ts +5 -21
  9. package/es/backend/route-operation/get-operation.js +10 -132
  10. package/es/backend/route-operation/get-table-name.js +0 -2
  11. package/es/backend/route-operation/index.d.ts +1 -0
  12. package/es/backend/route-operation/index.js +2 -1
  13. package/es/backend/route-operation/open-api-operation.d.ts +6 -0
  14. package/es/backend/route-operation/open-api-operation.js +13 -0
  15. package/es/backend/route-operation/operation-common.d.ts +38 -0
  16. package/es/backend/route-operation/operation-common.js +148 -0
  17. package/es/backend/route-operation/operation-core.d.ts +3 -0
  18. package/es/backend/route-operation/operation-core.js +3 -0
  19. package/es/backend/route-operation/post-operation.d.ts +5 -25
  20. package/es/backend/route-operation/post-operation.js +13 -189
  21. package/es/backend/route-operation/put-operation.d.ts +4 -23
  22. package/es/backend/route-operation/put-operation.js +10 -155
  23. package/es/backend/route-operation/read-operation-core.d.ts +55 -0
  24. package/es/backend/route-operation/read-operation-core.js +224 -0
  25. package/es/backend/route-operation/write-operation-core.d.ts +94 -0
  26. package/es/backend/route-operation/write-operation-core.js +390 -0
  27. package/es/backend/sqlite/route-operation/delete-operation.d.ts +9 -20
  28. package/es/backend/sqlite/route-operation/delete-operation.js +10 -122
  29. package/es/backend/sqlite/route-operation/get-list-operation.d.ts +6 -28
  30. package/es/backend/sqlite/route-operation/get-list-operation.js +10 -135
  31. package/es/backend/sqlite/route-operation/get-operation.d.ts +6 -22
  32. package/es/backend/sqlite/route-operation/get-operation.js +10 -132
  33. package/es/backend/sqlite/route-operation/index.d.ts +1 -0
  34. package/es/backend/sqlite/route-operation/index.js +2 -1
  35. package/es/backend/sqlite/route-operation/post-operation.d.ts +6 -26
  36. package/es/backend/sqlite/route-operation/post-operation.js +13 -189
  37. package/es/backend/sqlite/route-operation/put-operation.d.ts +6 -25
  38. package/es/backend/sqlite/route-operation/put-operation.js +10 -155
  39. package/es/backend/sqlite/schemas/index.d.ts +69 -5
  40. package/es/backend/sqlite/schemas/index.js +0 -1
  41. package/lib/__shims__/next-rest-framework.d.ts +2 -0
  42. package/lib/backend/route-operation/delete-operation.d.ts +7 -18
  43. package/lib/backend/route-operation/delete-operation.js +7 -52
  44. package/lib/backend/route-operation/get-list-operation.d.ts +5 -27
  45. package/lib/backend/route-operation/get-list-operation.js +7 -68
  46. package/lib/backend/route-operation/get-operation.d.ts +5 -21
  47. package/lib/backend/route-operation/get-operation.js +7 -67
  48. package/lib/backend/route-operation/index.d.ts +1 -0
  49. package/lib/backend/route-operation/index.js +3 -1
  50. package/lib/backend/route-operation/open-api-operation.d.ts +6 -0
  51. package/lib/backend/route-operation/open-api-operation.js +37 -0
  52. package/lib/backend/route-operation/operation-common.d.ts +38 -0
  53. package/lib/backend/route-operation/operation-common.js +90 -0
  54. package/lib/backend/route-operation/operation-core.d.ts +3 -0
  55. package/lib/backend/route-operation/operation-core.js +27 -0
  56. package/lib/backend/route-operation/post-operation.d.ts +5 -25
  57. package/lib/backend/route-operation/post-operation.js +7 -71
  58. package/lib/backend/route-operation/put-operation.d.ts +4 -23
  59. package/lib/backend/route-operation/put-operation.js +7 -68
  60. package/lib/backend/route-operation/read-operation-core.d.ts +55 -0
  61. package/lib/backend/route-operation/read-operation-core.js +151 -0
  62. package/lib/backend/route-operation/write-operation-core.d.ts +94 -0
  63. package/lib/backend/route-operation/write-operation-core.js +181 -0
  64. package/lib/backend/sqlite/route-operation/delete-operation.d.ts +9 -20
  65. package/lib/backend/sqlite/route-operation/delete-operation.js +7 -52
  66. package/lib/backend/sqlite/route-operation/get-list-operation.d.ts +6 -28
  67. package/lib/backend/sqlite/route-operation/get-list-operation.js +7 -71
  68. package/lib/backend/sqlite/route-operation/get-operation.d.ts +6 -22
  69. package/lib/backend/sqlite/route-operation/get-operation.js +7 -67
  70. package/lib/backend/sqlite/route-operation/index.d.ts +1 -0
  71. package/lib/backend/sqlite/route-operation/index.js +3 -1
  72. package/lib/backend/sqlite/route-operation/post-operation.d.ts +6 -26
  73. package/lib/backend/sqlite/route-operation/post-operation.js +7 -71
  74. package/lib/backend/sqlite/route-operation/put-operation.d.ts +6 -25
  75. package/lib/backend/sqlite/route-operation/put-operation.js +7 -68
  76. package/lib/backend/sqlite/schemas/index.d.ts +69 -5
  77. package/package.json +1 -1
@@ -1,140 +1,15 @@
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";
1
+ import { createGetListAction } from "../actions/create-get-list-action.js";
6
2
  import getTableName from "./get-table-name.js";
7
- import { listBodySchema } from "../schemas/index.js";
8
- import { createGetListAction } from "../actions/index.js";
3
+ import { createGetListOperationFactory } from "./operation-core.js";
4
+ var createOperation = createGetListOperationFactory({
5
+ createAction: createGetListAction,
6
+ getTableName: getTableName
7
+ });
9
8
  export var createGetListOperation = function createGetListOperation(_ref) {
10
9
  var db = _ref.db,
11
10
  getSession = _ref.getSession;
12
- return function (_ref2) {
13
- var querySchema = _ref2.querySchema,
14
- bodySchema = _ref2.bodySchema,
15
- table = _ref2.table,
16
- description = _ref2.description,
17
- summary = _ref2.summary,
18
- tags = _ref2.tags,
19
- relations = _ref2.relations,
20
- jsonArrayFields = _ref2.jsonArrayFields,
21
- setParams = _ref2.setParams,
22
- onSuccess = _ref2.onSuccess,
23
- onError = _ref2.onError,
24
- _ref2$byCreator = _ref2.byCreator,
25
- byCreator = _ref2$byCreator === void 0 ? true : _ref2$byCreator;
26
- return routeOperation({
27
- method: "GET",
28
- openApiOperation: {
29
- description: description,
30
- summary: summary,
31
- tags: tags !== null && tags !== void 0 ? tags : table ? [getTableName(table)] : []
32
- }
33
- }).input({
34
- query: querySchema
35
- }).outputs([{
36
- body: listBodySchema(bodySchema),
37
- contentType: "application/json",
38
- status: 200
39
- }]).handler( /*#__PURE__*/function () {
40
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
41
- var params, _ref4, userId, mergedParams, result, response;
42
- return _regeneratorRuntime().wrap(function _callee$(_context) {
43
- while (1) switch (_context.prev = _context.next) {
44
- case 0:
45
- _context.prev = 0;
46
- _context.next = 3;
47
- return setParams === null || setParams === void 0 ? void 0 : setParams(req);
48
- case 3:
49
- _context.t0 = _context.sent;
50
- if (_context.t0) {
51
- _context.next = 6;
52
- break;
53
- }
54
- _context.t0 = {};
55
- case 6:
56
- params = _context.t0;
57
- if (!byCreator) {
58
- _context.next = 16;
59
- break;
60
- }
61
- _context.next = 10;
62
- return getSession(req);
63
- case 10:
64
- _context.t1 = _context.sent;
65
- if (_context.t1) {
66
- _context.next = 13;
67
- break;
68
- }
69
- _context.t1 = {};
70
- case 13:
71
- _ref4 = _context.t1;
72
- userId = _ref4.userId;
73
- params.creatorId = userId;
74
- case 16:
75
- mergedParams = Object.assign(Object.fromEntries(new URL(req.url).searchParams), params);
76
- if (!(table && db)) {
77
- _context.next = 23;
78
- break;
79
- }
80
- _context.next = 20;
81
- return createGetListAction({
82
- bodySchema: bodySchema,
83
- db: db,
84
- jsonArrayFields: jsonArrayFields,
85
- relations: relations,
86
- table: table
87
- })(mergedParams);
88
- case 20:
89
- _context.t2 = _context.sent;
90
- _context.next = 24;
91
- break;
92
- case 23:
93
- _context.t2 = {
94
- data: [],
95
- total: 0
96
- };
97
- case 24:
98
- result = _context.t2;
99
- if (!onSuccess) {
100
- _context.next = 29;
101
- break;
102
- }
103
- _context.next = 28;
104
- return onSuccess({
105
- data: result,
106
- params: mergedParams
107
- });
108
- case 28:
109
- result = _context.sent;
110
- case 29:
111
- return _context.abrupt("return", TypedNextResponse.json(result, {
112
- status: 200
113
- }));
114
- case 32:
115
- _context.prev = 32;
116
- _context.t3 = _context["catch"](0);
117
- console.error(_context.t3);
118
- _context.next = 37;
119
- return onError === null || onError === void 0 ? void 0 : onError(_context.t3);
120
- case 37:
121
- response = _context.sent;
122
- if (!response) {
123
- _context.next = 42;
124
- break;
125
- }
126
- return _context.abrupt("return", response);
127
- case 42:
128
- throw _context.t3;
129
- case 43:
130
- case "end":
131
- return _context.stop();
132
- }
133
- }, _callee, null, [[0, 32]]);
134
- }));
135
- return function (_x) {
136
- return _ref3.apply(this, arguments);
137
- };
138
- }());
139
- };
11
+ return createOperation({
12
+ db: db,
13
+ getSession: getSession
14
+ });
140
15
  };
@@ -1,28 +1,12 @@
1
- import { z, ZodSchema } from "zod";
2
- import { NextRequest } from "next/server";
3
- import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
4
1
  import { NodePgDatabase } from "drizzle-orm/node-postgres";
2
+ import { NextRequest } from "next/server";
3
+ import { ZodSchema } from "zod";
5
4
  import { BaseTable, GetListRelations } from "../types.js";
6
- export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> {
7
- bodySchema: T;
8
- jsonArrayFields?: string[];
9
- querySchema: Q;
10
- relations?: GetListRelations;
11
- setParams?(req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>): Promise<Record<string, unknown>>;
12
- onSuccess?(payload: {
13
- params: Partial<z.infer<T>> & Record<string, unknown>;
14
- data: z.infer<T>;
15
- }): Promise<z.infer<T>>;
16
- onError?(error: Error): Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
17
- description?: string;
18
- summary?: string;
19
- tags?: string[];
20
- table?: TTable;
21
- byCreator?: boolean;
22
- }
5
+ import { type GetOperationOptions as CoreGetOperationOptions } from "./operation-core.js";
6
+ export type GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> = CoreGetOperationOptions<T, Q, TTable, GetListRelations>;
23
7
  export declare const createGetOperation: ({ getSession, db, }: {
24
8
  db?: NodePgDatabase<Record<string, unknown>> | undefined;
25
9
  getSession(req: NextRequest): Promise<{
26
10
  userId?: string;
27
11
  } | undefined>;
28
- }) => <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, Q extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, TTable extends BaseTable>({ querySchema, bodySchema, table, description, summary, tags, relations, setParams, jsonArrayFields, onSuccess, onError, byCreator, }: GetOperationOptions<T, Q, TTable>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
12
+ }) => <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, setParams, jsonArrayFields, handler, catch: catchHandler, }: CoreGetOperationOptions<T, Q, BaseTable, GetListRelations>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
@@ -1,137 +1,15 @@
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";
1
+ import { createGetAction } from "../actions/create-get-action.js";
6
2
  import getTableName from "./get-table-name.js";
7
- import { createGetAction } from "../actions/index.js";
3
+ import { createGetOperationFactory } from "./operation-core.js";
4
+ var createOperation = createGetOperationFactory({
5
+ createAction: createGetAction,
6
+ getTableName: getTableName
7
+ });
8
8
  export var createGetOperation = function createGetOperation(_ref) {
9
9
  var getSession = _ref.getSession,
10
10
  db = _ref.db;
11
- return function (_ref2) {
12
- var querySchema = _ref2.querySchema,
13
- bodySchema = _ref2.bodySchema,
14
- table = _ref2.table,
15
- description = _ref2.description,
16
- summary = _ref2.summary,
17
- tags = _ref2.tags,
18
- relations = _ref2.relations,
19
- setParams = _ref2.setParams,
20
- jsonArrayFields = _ref2.jsonArrayFields,
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
- description: description,
29
- summary: summary,
30
- tags: tags !== null && tags !== void 0 ? tags : table ? [getTableName(table)] : []
31
- }
32
- }).input({
33
- query: querySchema
34
- }).outputs([{
35
- body: bodySchema,
36
- contentType: "application/json",
37
- status: 200
38
- }]).handler( /*#__PURE__*/function () {
39
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
40
- var params, _ref4, userId, mergedParams, rawResult, result, response;
41
- return _regeneratorRuntime().wrap(function _callee$(_context) {
42
- while (1) switch (_context.prev = _context.next) {
43
- case 0:
44
- _context.prev = 0;
45
- _context.next = 3;
46
- return setParams === null || setParams === void 0 ? void 0 : setParams(req);
47
- case 3:
48
- _context.t0 = _context.sent;
49
- if (_context.t0) {
50
- _context.next = 6;
51
- break;
52
- }
53
- _context.t0 = {};
54
- case 6:
55
- params = _context.t0;
56
- if (!byCreator) {
57
- _context.next = 16;
58
- break;
59
- }
60
- _context.next = 10;
61
- return getSession(req);
62
- case 10:
63
- _context.t1 = _context.sent;
64
- if (_context.t1) {
65
- _context.next = 13;
66
- break;
67
- }
68
- _context.t1 = {};
69
- case 13:
70
- _ref4 = _context.t1;
71
- userId = _ref4.userId;
72
- params.creatorId = userId;
73
- case 16:
74
- mergedParams = Object.assign(Object.fromEntries(new URL(req.url).searchParams), params);
75
- if (!(table && db)) {
76
- _context.next = 23;
77
- break;
78
- }
79
- _context.next = 20;
80
- return createGetAction({
81
- bodySchema: bodySchema,
82
- db: db,
83
- jsonArrayFields: jsonArrayFields,
84
- relations: relations,
85
- table: table
86
- })(mergedParams);
87
- case 20:
88
- _context.t2 = _context.sent;
89
- _context.next = 24;
90
- break;
91
- case 23:
92
- _context.t2 = mergedParams;
93
- case 24:
94
- rawResult = _context.t2;
95
- result = rawResult !== null && rawResult !== void 0 ? rawResult : {};
96
- if (!onSuccess) {
97
- _context.next = 30;
98
- break;
99
- }
100
- _context.next = 29;
101
- return onSuccess({
102
- data: result,
103
- params: mergedParams
104
- });
105
- case 29:
106
- result = _context.sent;
107
- case 30:
108
- return _context.abrupt("return", TypedNextResponse.json(result, {
109
- status: 200
110
- }));
111
- case 33:
112
- _context.prev = 33;
113
- _context.t3 = _context["catch"](0);
114
- console.error(_context.t3);
115
- _context.next = 38;
116
- return onError === null || onError === void 0 ? void 0 : onError(_context.t3);
117
- case 38:
118
- response = _context.sent;
119
- if (!response) {
120
- _context.next = 43;
121
- break;
122
- }
123
- return _context.abrupt("return", response);
124
- case 43:
125
- throw _context.t3;
126
- case 44:
127
- case "end":
128
- return _context.stop();
129
- }
130
- }, _callee, null, [[0, 33]]);
131
- }));
132
- return function (_x) {
133
- return _ref3.apply(this, arguments);
134
- };
135
- }());
136
- };
11
+ return createOperation({
12
+ db: db,
13
+ getSession: getSession
14
+ });
137
15
  };
@@ -4,8 +4,6 @@ function getTableName(table) {
4
4
  return sym.toString() === "Symbol(drizzle:Name)";
5
5
  });
6
6
  if (nameSymbol) {
7
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
8
- // @ts-ignore
9
7
  return table[nameSymbol];
10
8
  }
11
9
  return "";
@@ -3,3 +3,4 @@ export * from "./get-list-operation.js";
3
3
  export * from "./delete-operation.js";
4
4
  export * from "./post-operation.js";
5
5
  export * from "./put-operation.js";
6
+ export * from "./open-api-operation.js";
@@ -2,4 +2,5 @@ export * from "./get-operation.js";
2
2
  export * from "./get-list-operation.js";
3
3
  export * from "./delete-operation.js";
4
4
  export * from "./post-operation.js";
5
- export * from "./put-operation.js";
5
+ export * from "./put-operation.js";
6
+ export * from "./open-api-operation.js";
@@ -0,0 +1,6 @@
1
+ import type { routeOperation } from "next-rest-framework";
2
+ export type RouteOpenApiOperation = NonNullable<Parameters<typeof routeOperation>[0]["openApiOperation"]>;
3
+ export declare function createOpenApiOperation({ defaultTags, openApiOperation, }: {
4
+ defaultTags: string[];
5
+ openApiOperation?: RouteOpenApiOperation;
6
+ }): RouteOpenApiOperation;
@@ -0,0 +1,13 @@
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 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; }
3
+ 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; }
4
+ 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; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ 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); }
7
+ export function createOpenApiOperation(_ref) {
8
+ var defaultTags = _ref.defaultTags,
9
+ openApiOperation = _ref.openApiOperation;
10
+ return _objectSpread({
11
+ tags: defaultTags
12
+ }, openApiOperation);
13
+ }
@@ -0,0 +1,38 @@
1
+ import { NextRequest } from "next/server";
2
+ import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
3
+ import { z, ZodSchema } from "zod";
4
+ export type JsonResponse = ReturnType<(typeof TypedNextResponse)["json"]>;
5
+ export type RouteCatch = (error: Error) => Promise<JsonResponse | undefined>;
6
+ export type SessionGetter = (req: NextRequest) => Promise<{
7
+ userId?: string;
8
+ } | undefined>;
9
+ export type ActionFactory<TTable, TAction> = (_options: {
10
+ bodySchema?: ZodSchema;
11
+ db: unknown;
12
+ jsonArrayFields?: string[];
13
+ relations?: unknown;
14
+ table: TTable;
15
+ }) => TAction;
16
+ export declare function handleOperationError(error: unknown, catchHandler?: RouteCatch): Promise<Response>;
17
+ export declare function readPostBody(req: NextRequest, { contentType, parseBody, }: {
18
+ contentType: string;
19
+ parseBody?: (_req: NextRequest) => Promise<Record<string, unknown>>;
20
+ }): Promise<Record<string, unknown>>;
21
+ export declare function getDefaultTags<TTable>({ getTableName, table, }: {
22
+ getTableName(table: TTable): string;
23
+ table?: TTable;
24
+ }): string[];
25
+ export type GetOperationParams<Q extends ZodSchema> = z.infer<Q> & Record<string, unknown> & {
26
+ creatorId?: string;
27
+ };
28
+ export declare function getReadParams<Q extends ZodSchema>({ access, getSession, req, schemas, setParams, }: {
29
+ access?: {
30
+ byCreator?: boolean;
31
+ };
32
+ getSession: SessionGetter;
33
+ req: NextRequest;
34
+ schemas: {
35
+ query: Q;
36
+ };
37
+ setParams?: (_req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string, unknown>>;
38
+ }): Promise<GetOperationParams<Q>>;
@@ -0,0 +1,148 @@
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 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; }
3
+ 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; }
4
+ 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; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ 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); }
7
+ 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; }
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 { TypedNextResponse } from "next-rest-framework";
11
+ function isHttpLikeError(error) {
12
+ return error instanceof Error && error.name === "HttpError" && typeof error.status === "number";
13
+ }
14
+ export function handleOperationError(_x, _x2) {
15
+ return _handleOperationError.apply(this, arguments);
16
+ }
17
+ function _handleOperationError() {
18
+ _handleOperationError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(error, catchHandler) {
19
+ var response;
20
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
21
+ while (1) switch (_context.prev = _context.next) {
22
+ case 0:
23
+ if (!isHttpLikeError(error)) {
24
+ console.error(error);
25
+ }
26
+ _context.next = 3;
27
+ return catchHandler === null || catchHandler === void 0 ? void 0 : catchHandler(error);
28
+ case 3:
29
+ response = _context.sent;
30
+ if (!response) {
31
+ _context.next = 6;
32
+ break;
33
+ }
34
+ return _context.abrupt("return", response);
35
+ case 6:
36
+ if (!isHttpLikeError(error)) {
37
+ _context.next = 8;
38
+ break;
39
+ }
40
+ return _context.abrupt("return", TypedNextResponse.json({
41
+ message: error.message
42
+ }, {
43
+ status: error.status
44
+ }));
45
+ case 8:
46
+ throw error;
47
+ case 9:
48
+ case "end":
49
+ return _context.stop();
50
+ }
51
+ }, _callee);
52
+ }));
53
+ return _handleOperationError.apply(this, arguments);
54
+ }
55
+ export function readPostBody(_x3, _x4) {
56
+ return _readPostBody.apply(this, arguments);
57
+ }
58
+ function _readPostBody() {
59
+ _readPostBody = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(req, _ref) {
60
+ var contentType, parseBody;
61
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
62
+ while (1) switch (_context2.prev = _context2.next) {
63
+ case 0:
64
+ contentType = _ref.contentType, parseBody = _ref.parseBody;
65
+ if (!parseBody) {
66
+ _context2.next = 3;
67
+ break;
68
+ }
69
+ return _context2.abrupt("return", parseBody(req));
70
+ case 3:
71
+ if (!(contentType === "multipart/form-data")) {
72
+ _context2.next = 9;
73
+ break;
74
+ }
75
+ _context2.t0 = Object;
76
+ _context2.next = 7;
77
+ return req.formData();
78
+ case 7:
79
+ _context2.t1 = _context2.sent;
80
+ return _context2.abrupt("return", _context2.t0.fromEntries.call(_context2.t0, _context2.t1));
81
+ case 9:
82
+ _context2.next = 11;
83
+ return req.json();
84
+ case 11:
85
+ return _context2.abrupt("return", _context2.sent);
86
+ case 12:
87
+ case "end":
88
+ return _context2.stop();
89
+ }
90
+ }, _callee2);
91
+ }));
92
+ return _readPostBody.apply(this, arguments);
93
+ }
94
+ export function getDefaultTags(_ref2) {
95
+ var getTableName = _ref2.getTableName,
96
+ table = _ref2.table;
97
+ return table ? [getTableName(table)] : [];
98
+ }
99
+ export function getReadParams(_x5) {
100
+ return _getReadParams.apply(this, arguments);
101
+ }
102
+ function _getReadParams() {
103
+ _getReadParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref3) {
104
+ var _access$byCreator;
105
+ var access, getSession, req, schemas, setParams, extraParams, _ref4, userId, queryParams;
106
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
107
+ while (1) switch (_context3.prev = _context3.next) {
108
+ case 0:
109
+ access = _ref3.access, getSession = _ref3.getSession, req = _ref3.req, schemas = _ref3.schemas, setParams = _ref3.setParams;
110
+ _context3.next = 3;
111
+ return setParams === null || setParams === void 0 ? void 0 : setParams(req);
112
+ case 3:
113
+ _context3.t0 = _context3.sent;
114
+ if (_context3.t0) {
115
+ _context3.next = 6;
116
+ break;
117
+ }
118
+ _context3.t0 = {};
119
+ case 6:
120
+ extraParams = _context3.t0;
121
+ if (!((_access$byCreator = access === null || access === void 0 ? void 0 : access.byCreator) !== null && _access$byCreator !== void 0 ? _access$byCreator : true)) {
122
+ _context3.next = 16;
123
+ break;
124
+ }
125
+ _context3.next = 10;
126
+ return getSession(req);
127
+ case 10:
128
+ _context3.t1 = _context3.sent;
129
+ if (_context3.t1) {
130
+ _context3.next = 13;
131
+ break;
132
+ }
133
+ _context3.t1 = {};
134
+ case 13:
135
+ _ref4 = _context3.t1;
136
+ userId = _ref4.userId;
137
+ extraParams.creatorId = userId;
138
+ case 16:
139
+ queryParams = schemas.query.parse(Object.fromEntries(new URL(req.url).searchParams));
140
+ return _context3.abrupt("return", _objectSpread(_objectSpread({}, queryParams), extraParams));
141
+ case 18:
142
+ case "end":
143
+ return _context3.stop();
144
+ }
145
+ }, _callee3);
146
+ }));
147
+ return _getReadParams.apply(this, arguments);
148
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./operation-common.js";
2
+ export * from "./read-operation-core.js";
3
+ export * from "./write-operation-core.js";
@@ -0,0 +1,3 @@
1
+ export * from "./operation-common.js";
2
+ export * from "./read-operation-core.js";
3
+ export * from "./write-operation-core.js";