@ai0x0/utils 0.0.0

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 (122) hide show
  1. package/LICENSE +21 -0
  2. package/es/backend/actions/delete-action-fn.d.ts +7 -0
  3. package/es/backend/actions/delete-action-fn.d.ts.map +1 -0
  4. package/es/backend/actions/delete-action-fn.js +30 -0
  5. package/es/backend/actions/get-List-query.d.ts +30 -0
  6. package/es/backend/actions/get-List-query.d.ts.map +1 -0
  7. package/es/backend/actions/get-List-query.js +212 -0
  8. package/es/backend/actions/get-action-fn.d.ts +12 -0
  9. package/es/backend/actions/get-action-fn.d.ts.map +1 -0
  10. package/es/backend/actions/get-action-fn.js +75 -0
  11. package/es/backend/actions/get-list-action-fn.d.ts +12 -0
  12. package/es/backend/actions/get-list-action-fn.d.ts.map +1 -0
  13. package/es/backend/actions/get-list-action-fn.js +68 -0
  14. package/es/backend/actions/get-list-data.d.ts +8 -0
  15. package/es/backend/actions/get-list-data.d.ts.map +1 -0
  16. package/es/backend/actions/get-list-data.js +49 -0
  17. package/es/backend/actions/index.d.ts +6 -0
  18. package/es/backend/actions/index.d.ts.map +1 -0
  19. package/es/backend/actions/index.js +5 -0
  20. package/es/backend/actions/post-action-fn.d.ts +13 -0
  21. package/es/backend/actions/post-action-fn.d.ts.map +1 -0
  22. package/es/backend/actions/post-action-fn.js +35 -0
  23. package/es/backend/actions/put-action-fn.d.ts +9 -0
  24. package/es/backend/actions/put-action-fn.d.ts.map +1 -0
  25. package/es/backend/actions/put-action-fn.js +34 -0
  26. package/es/backend/actions/transform-body.d.ts +2 -0
  27. package/es/backend/actions/transform-body.d.ts.map +1 -0
  28. package/es/backend/actions/transform-body.js +11 -0
  29. package/es/backend/index.d.ts +3 -0
  30. package/es/backend/index.d.ts.map +1 -0
  31. package/es/backend/index.js +2 -0
  32. package/es/backend/route-operation/delete-operation.d.ts +10 -0
  33. package/es/backend/route-operation/delete-operation.d.ts.map +1 -0
  34. package/es/backend/route-operation/delete-operation.js +59 -0
  35. package/es/backend/route-operation/get-list-operation.d.ts +24 -0
  36. package/es/backend/route-operation/get-list-operation.d.ts.map +1 -0
  37. package/es/backend/route-operation/get-list-operation.js +83 -0
  38. package/es/backend/route-operation/get-operation.d.ts +17 -0
  39. package/es/backend/route-operation/get-operation.d.ts.map +1 -0
  40. package/es/backend/route-operation/get-operation.js +65 -0
  41. package/es/backend/route-operation/get-table-name.d.ts +4 -0
  42. package/es/backend/route-operation/get-table-name.d.ts.map +1 -0
  43. package/es/backend/route-operation/get-table-name.js +13 -0
  44. package/es/backend/route-operation/index.d.ts +6 -0
  45. package/es/backend/route-operation/index.d.ts.map +1 -0
  46. package/es/backend/route-operation/index.js +5 -0
  47. package/es/backend/route-operation/post-operation.d.ts +14 -0
  48. package/es/backend/route-operation/post-operation.d.ts.map +1 -0
  49. package/es/backend/route-operation/post-operation.js +84 -0
  50. package/es/backend/route-operation/put-operation.d.ts +14 -0
  51. package/es/backend/route-operation/put-operation.d.ts.map +1 -0
  52. package/es/backend/route-operation/put-operation.js +71 -0
  53. package/es/backend/schemas/index.d.ts +4674 -0
  54. package/es/backend/schemas/index.d.ts.map +1 -0
  55. package/es/backend/schemas/index.js +87 -0
  56. package/es/backend/types.d.ts +13 -0
  57. package/es/backend/types.d.ts.map +1 -0
  58. package/es/backend/types.js +1 -0
  59. package/es/index.d.ts +1 -0
  60. package/es/index.d.ts.map +1 -0
  61. package/es/index.js +0 -0
  62. package/lib/backend/actions/delete-action-fn.d.ts +7 -0
  63. package/lib/backend/actions/delete-action-fn.d.ts.map +1 -0
  64. package/lib/backend/actions/delete-action-fn.js +42 -0
  65. package/lib/backend/actions/get-List-query.d.ts +30 -0
  66. package/lib/backend/actions/get-List-query.d.ts.map +1 -0
  67. package/lib/backend/actions/get-List-query.js +162 -0
  68. package/lib/backend/actions/get-action-fn.d.ts +12 -0
  69. package/lib/backend/actions/get-action-fn.d.ts.map +1 -0
  70. package/lib/backend/actions/get-action-fn.js +75 -0
  71. package/lib/backend/actions/get-list-action-fn.d.ts +12 -0
  72. package/lib/backend/actions/get-list-action-fn.d.ts.map +1 -0
  73. package/lib/backend/actions/get-list-action-fn.js +74 -0
  74. package/lib/backend/actions/get-list-data.d.ts +8 -0
  75. package/lib/backend/actions/get-list-data.d.ts.map +1 -0
  76. package/lib/backend/actions/get-list-data.js +48 -0
  77. package/lib/backend/actions/index.d.ts +6 -0
  78. package/lib/backend/actions/index.d.ts.map +1 -0
  79. package/lib/backend/actions/index.js +41 -0
  80. package/lib/backend/actions/post-action-fn.d.ts +13 -0
  81. package/lib/backend/actions/post-action-fn.d.ts.map +1 -0
  82. package/lib/backend/actions/post-action-fn.js +49 -0
  83. package/lib/backend/actions/put-action-fn.d.ts +9 -0
  84. package/lib/backend/actions/put-action-fn.d.ts.map +1 -0
  85. package/lib/backend/actions/put-action-fn.js +43 -0
  86. package/lib/backend/actions/transform-body.d.ts +2 -0
  87. package/lib/backend/actions/transform-body.d.ts.map +1 -0
  88. package/lib/backend/actions/transform-body.js +47 -0
  89. package/lib/backend/index.d.ts +3 -0
  90. package/lib/backend/index.d.ts.map +1 -0
  91. package/lib/backend/index.js +25 -0
  92. package/lib/backend/route-operation/delete-operation.d.ts +10 -0
  93. package/lib/backend/route-operation/delete-operation.d.ts.map +1 -0
  94. package/lib/backend/route-operation/delete-operation.js +59 -0
  95. package/lib/backend/route-operation/get-list-operation.d.ts +24 -0
  96. package/lib/backend/route-operation/get-list-operation.d.ts.map +1 -0
  97. package/lib/backend/route-operation/get-list-operation.js +87 -0
  98. package/lib/backend/route-operation/get-operation.d.ts +17 -0
  99. package/lib/backend/route-operation/get-operation.d.ts.map +1 -0
  100. package/lib/backend/route-operation/get-operation.js +82 -0
  101. package/lib/backend/route-operation/get-table-name.d.ts +4 -0
  102. package/lib/backend/route-operation/get-table-name.d.ts.map +1 -0
  103. package/lib/backend/route-operation/get-table-name.js +35 -0
  104. package/lib/backend/route-operation/index.d.ts +6 -0
  105. package/lib/backend/route-operation/index.d.ts.map +1 -0
  106. package/lib/backend/route-operation/index.js +31 -0
  107. package/lib/backend/route-operation/post-operation.d.ts +14 -0
  108. package/lib/backend/route-operation/post-operation.d.ts.map +1 -0
  109. package/lib/backend/route-operation/post-operation.js +67 -0
  110. package/lib/backend/route-operation/put-operation.d.ts +14 -0
  111. package/lib/backend/route-operation/put-operation.d.ts.map +1 -0
  112. package/lib/backend/route-operation/put-operation.js +66 -0
  113. package/lib/backend/schemas/index.d.ts +4674 -0
  114. package/lib/backend/schemas/index.d.ts.map +1 -0
  115. package/lib/backend/schemas/index.js +98 -0
  116. package/lib/backend/types.d.ts +13 -0
  117. package/lib/backend/types.d.ts.map +1 -0
  118. package/lib/backend/types.js +17 -0
  119. package/lib/index.d.ts +1 -0
  120. package/lib/index.d.ts.map +1 -0
  121. package/lib/index.js +0 -0
  122. package/package.json +86 -0
@@ -0,0 +1,4 @@
1
+ import { PgTable } from "drizzle-orm/pg-core";
2
+ declare function getTableName(table: PgTable): string;
3
+ export default getTableName;
4
+ //# sourceMappingURL=get-table-name.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-table-name.d.ts","sourceRoot":"","sources":["get-table-name.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,iBAAS,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAa5C;AAED,eAAe,YAAY,CAAC"}
@@ -0,0 +1,13 @@
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
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
8
+ // @ts-ignore
9
+ return table[nameSymbol];
10
+ }
11
+ return "";
12
+ }
13
+ export default getTableName;
@@ -0,0 +1,6 @@
1
+ export * from "./get-operation";
2
+ export * from "./get-list-operation";
3
+ export * from "./delete-operation";
4
+ export * from "./post-operation";
5
+ export * from "./put-operation";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from "./get-operation";
2
+ export * from "./get-list-operation";
3
+ export * from "./delete-operation";
4
+ export * from "./post-operation";
5
+ export * from "./put-operation";
@@ -0,0 +1,14 @@
1
+ import { z, ZodSchema } from "zod";
2
+ import { PgTable } from "drizzle-orm/pg-core";
3
+ import { NextRequest } from "next/server";
4
+ import { NodePgDatabase } from "drizzle-orm/node-postgres";
5
+ export interface PostOperationOptions<T extends ZodSchema, TTable extends PgTable> {
6
+ bodySchema: T;
7
+ setBody?: (req: NextRequest) => Promise<Partial<z.infer<T>>>;
8
+ summary?: string;
9
+ table: TTable;
10
+ }
11
+ export declare const createPostOperation: <T extends z.ZodType<any, z.ZodTypeDef, any>, TTable extends PgTable<import("drizzle-orm/pg-core").TableConfig>>({ db, }: {
12
+ db: NodePgDatabase<any>;
13
+ }) => ({ bodySchema, setBody, summary, table }: PostOperationOptions<T, TTable>) => any;
14
+ //# sourceMappingURL=post-operation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"post-operation.d.ts","sourceRoot":"","sources":["post-operation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI1C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,MAAM,WAAW,oBAAoB,CACnC,CAAC,SAAS,SAAS,EACnB,MAAM,SAAS,OAAO;IAEtB,UAAU,EAAE,CAAC,CAAC;IACd,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,mBAAmB;QAIxB,eAAe,GAAG,CAAC;uFA4BZ,CAAC"}
@@ -0,0 +1,84 @@
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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
5
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
7
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
8
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
9
+ 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); } }
10
+ 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); }); }; }
11
+ import { z } from "zod";
12
+ import { routeOperation, TypedNextResponse } from "next-rest-framework";
13
+ import getTableName from "./get-table-name";
14
+ import { postActionFn } from "../actions";
15
+ export var createPostOperation = function createPostOperation(_ref) {
16
+ var db = _ref.db;
17
+ return function (_ref2) {
18
+ var bodySchema = _ref2.bodySchema,
19
+ setBody = _ref2.setBody,
20
+ summary = _ref2.summary,
21
+ table = _ref2.table;
22
+ return routeOperation({
23
+ method: "POST",
24
+ openApiOperation: {
25
+ summary: summary,
26
+ tags: [getTableName(table)]
27
+ }
28
+ }).input({
29
+ body: bodySchema,
30
+ contentType: "application/json"
31
+ }).outputs([{
32
+ body: z.object({
33
+ id: z.string()
34
+ }),
35
+ contentType: "application/json",
36
+ status: 200
37
+ }]).handler( /*#__PURE__*/function () {
38
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
39
+ var body, _yield$postActionFn, _yield$postActionFn2, data;
40
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
41
+ while (1) switch (_context.prev = _context.next) {
42
+ case 0:
43
+ _context.t0 = Object;
44
+ _context.next = 3;
45
+ return setBody === null || setBody === void 0 ? void 0 : setBody(req);
46
+ case 3:
47
+ _context.t1 = _context.sent;
48
+ if (_context.t1) {
49
+ _context.next = 6;
50
+ break;
51
+ }
52
+ _context.t1 = {};
53
+ case 6:
54
+ _context.t2 = _context.t1;
55
+ _context.next = 9;
56
+ return req.json();
57
+ case 9:
58
+ _context.t3 = _context.sent;
59
+ body = _context.t0.assign.call(_context.t0, _context.t2, _context.t3);
60
+ _context.next = 13;
61
+ return postActionFn({
62
+ bodySchema: bodySchema,
63
+ db: db,
64
+ table: table
65
+ })(body);
66
+ case 13:
67
+ _yield$postActionFn = _context.sent;
68
+ _yield$postActionFn2 = _slicedToArray(_yield$postActionFn, 1);
69
+ data = _yield$postActionFn2[0];
70
+ return _context.abrupt("return", TypedNextResponse.json(data, {
71
+ status: 200
72
+ }));
73
+ case 17:
74
+ case "end":
75
+ return _context.stop();
76
+ }
77
+ }, _callee);
78
+ }));
79
+ return function (_x) {
80
+ return _ref3.apply(this, arguments);
81
+ };
82
+ }());
83
+ };
84
+ };
@@ -0,0 +1,14 @@
1
+ import { z, ZodSchema } from "zod";
2
+ import { PgTable } from "drizzle-orm/pg-core";
3
+ import { NodePgDatabase } from "drizzle-orm/node-postgres";
4
+ import { NextRequest } from "next/server";
5
+ export interface PutOperationOptions<T extends ZodSchema, TTable extends PgTable> {
6
+ bodySchema: T;
7
+ table: TTable;
8
+ summary?: string;
9
+ setBody?: (req: NextRequest) => Promise<Partial<z.infer<T>>>;
10
+ }
11
+ export declare const createPutOperation: <T extends z.ZodType<any, z.ZodTypeDef, any>, TTable extends PgTable<import("drizzle-orm/pg-core").TableConfig>>({ db, }: {
12
+ db: NodePgDatabase<any>;
13
+ }) => ({ bodySchema, table, summary, setBody }: PutOperationOptions<T, TTable>) => any;
14
+ //# sourceMappingURL=put-operation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"put-operation.d.ts","sourceRoot":"","sources":["put-operation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAI9C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,WAAW,mBAAmB,CAClC,CAAC,SAAS,SAAS,EACnB,MAAM,SAAS,OAAO;IAEtB,UAAU,EAAE,CAAC,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC9D;AAED,eAAO,MAAM,kBAAkB;QAIvB,eAAe,GAAG,CAAC;sFA2BZ,CAAC"}
@@ -0,0 +1,71 @@
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";
7
+ import { putActionFn } from "../actions";
8
+ export var createPutOperation = function createPutOperation(_ref) {
9
+ var db = _ref.db;
10
+ return function (_ref2) {
11
+ var bodySchema = _ref2.bodySchema,
12
+ table = _ref2.table,
13
+ summary = _ref2.summary,
14
+ setBody = _ref2.setBody;
15
+ return routeOperation({
16
+ method: "PUT",
17
+ openApiOperation: {
18
+ summary: summary,
19
+ tags: [getTableName(table)]
20
+ }
21
+ }).input({
22
+ body: bodySchema,
23
+ contentType: "application/json"
24
+ }).handler( /*#__PURE__*/function () {
25
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
26
+ var body;
27
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
28
+ while (1) switch (_context.prev = _context.next) {
29
+ case 0:
30
+ _context.t0 = Object;
31
+ _context.next = 3;
32
+ return setBody === null || setBody === void 0 ? void 0 : setBody(req);
33
+ case 3:
34
+ _context.t1 = _context.sent;
35
+ if (_context.t1) {
36
+ _context.next = 6;
37
+ break;
38
+ }
39
+ _context.t1 = {};
40
+ case 6:
41
+ _context.t2 = _context.t1;
42
+ _context.next = 9;
43
+ return req.json();
44
+ case 9:
45
+ _context.t3 = _context.sent;
46
+ body = _context.t0.assign.call(_context.t0, _context.t2, _context.t3);
47
+ _context.t4 = TypedNextResponse;
48
+ _context.next = 14;
49
+ return putActionFn({
50
+ bodySchema: bodySchema,
51
+ table: table,
52
+ db: db
53
+ })(body);
54
+ case 14:
55
+ _context.t5 = _context.sent;
56
+ _context.t6 = {
57
+ status: 200
58
+ };
59
+ return _context.abrupt("return", _context.t4.json.call(_context.t4, _context.t5, _context.t6));
60
+ case 17:
61
+ case "end":
62
+ return _context.stop();
63
+ }
64
+ }, _callee);
65
+ }));
66
+ return function (_x) {
67
+ return _ref3.apply(this, arguments);
68
+ };
69
+ }());
70
+ };
71
+ };