@ai0x0/utils 0.0.3 → 0.0.5

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 (61) hide show
  1. package/es/backend/actions/create-delete-action.d.ts +6 -0
  2. package/es/backend/actions/{delete-action-fn.js → create-delete-action.js} +3 -8
  3. package/es/backend/actions/{get-list-action-fn.d.ts → create-get-action.d.ts} +4 -5
  4. package/es/backend/actions/{get-action-fn.js → create-get-action.js} +4 -12
  5. package/es/backend/actions/create-get-list-action.d.ts +13 -0
  6. package/es/backend/actions/{get-list-action-fn.js → create-get-list-action.js} +3 -12
  7. package/es/backend/actions/create-post-action.d.ts +8 -0
  8. package/es/backend/actions/{post-action-fn.js → create-post-action.js} +4 -14
  9. package/es/backend/actions/create-put-action.d.ts +8 -0
  10. package/es/backend/actions/{put-action-fn.js → create-put-action.js} +4 -12
  11. package/es/backend/actions/get-list-data.d.ts +16 -1
  12. package/es/backend/actions/index.d.ts +5 -5
  13. package/es/backend/actions/index.js +5 -5
  14. package/es/backend/route-operation/delete-operation.d.ts +3 -2
  15. package/es/backend/route-operation/delete-operation.js +13 -11
  16. package/es/backend/route-operation/get-list-operation.d.ts +3 -3
  17. package/es/backend/route-operation/get-list-operation.js +5 -6
  18. package/es/backend/route-operation/get-operation.d.ts +4 -3
  19. package/es/backend/route-operation/get-operation.js +20 -4
  20. package/es/backend/route-operation/post-operation.d.ts +3 -2
  21. package/es/backend/route-operation/post-operation.js +18 -8
  22. package/es/backend/route-operation/put-operation.d.ts +4 -2
  23. package/es/backend/route-operation/put-operation.js +20 -12
  24. package/es/backend/schemas/index.d.ts +10 -2
  25. package/es/backend/schemas/index.js +1 -1
  26. package/es/backend/types.d.ts +5 -1
  27. package/lib/backend/actions/create-delete-action.d.ts +6 -0
  28. package/lib/backend/actions/{delete-action-fn.js → create-delete-action.js} +9 -14
  29. package/lib/backend/actions/{get-list-action-fn.d.ts → create-get-action.d.ts} +4 -5
  30. package/lib/backend/actions/{get-action-fn.js → create-get-action.js} +10 -20
  31. package/lib/backend/actions/create-get-list-action.d.ts +13 -0
  32. package/lib/backend/actions/{get-list-action-fn.js → create-get-list-action.js} +9 -20
  33. package/lib/backend/actions/create-post-action.d.ts +8 -0
  34. package/lib/backend/actions/{post-action-fn.js → create-post-action.js} +9 -21
  35. package/lib/backend/actions/create-put-action.d.ts +8 -0
  36. package/lib/backend/actions/{put-action-fn.js → create-put-action.js} +9 -14
  37. package/lib/backend/actions/get-list-data.d.ts +16 -1
  38. package/lib/backend/actions/index.d.ts +5 -5
  39. package/lib/backend/actions/index.js +17 -17
  40. package/lib/backend/route-operation/delete-operation.d.ts +3 -2
  41. package/lib/backend/route-operation/delete-operation.js +8 -2
  42. package/lib/backend/route-operation/get-list-operation.d.ts +3 -3
  43. package/lib/backend/route-operation/get-list-operation.js +4 -5
  44. package/lib/backend/route-operation/get-operation.d.ts +4 -3
  45. package/lib/backend/route-operation/get-operation.js +6 -3
  46. package/lib/backend/route-operation/post-operation.d.ts +3 -2
  47. package/lib/backend/route-operation/post-operation.js +11 -2
  48. package/lib/backend/route-operation/put-operation.d.ts +4 -2
  49. package/lib/backend/route-operation/put-operation.js +19 -12
  50. package/lib/backend/schemas/index.d.ts +10 -2
  51. package/lib/backend/schemas/index.js +2 -0
  52. package/lib/backend/types.d.ts +5 -1
  53. package/package.json +3 -3
  54. package/es/backend/actions/delete-action-fn.d.ts +0 -6
  55. package/es/backend/actions/get-action-fn.d.ts +0 -11
  56. package/es/backend/actions/post-action-fn.d.ts +0 -12
  57. package/es/backend/actions/put-action-fn.d.ts +0 -8
  58. package/lib/backend/actions/delete-action-fn.d.ts +0 -6
  59. package/lib/backend/actions/get-action-fn.d.ts +0 -11
  60. package/lib/backend/actions/post-action-fn.d.ts +0 -12
  61. package/lib/backend/actions/put-action-fn.d.ts +0 -8
@@ -0,0 +1,6 @@
1
+ import { NodePgDatabase } from "drizzle-orm/node-postgres";
2
+ import { BaseTable } from "../types";
3
+ export declare function createDeleteAction<TTable extends BaseTable>({ table, db, }: {
4
+ db: NodePgDatabase<any>;
5
+ table: TTable;
6
+ }): (id: string) => Promise<TTable["$inferSelect"] extends infer T ? T extends TTable["$inferSelect"] ? T extends undefined ? QueryResult<import("drizzle-orm").Assume<this["row"], QueryResultRow>> : T[] : never : never>;
@@ -2,16 +2,11 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
2
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
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
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 { rpcOperation } from "next-rest-framework";
6
- import { z } from "zod";
7
5
  import { eq } from "drizzle-orm";
8
- export function deleteActionFn(_ref) {
6
+ export function createDeleteAction(_ref) {
9
7
  var table = _ref.table,
10
8
  db = _ref.db;
11
- return rpcOperation().input({
12
- body: z.string(),
13
- contentType: "application/json"
14
- }).handler( /*#__PURE__*/function () {
9
+ return /*#__PURE__*/function () {
15
10
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(id) {
16
11
  return _regeneratorRuntime().wrap(function _callee$(_context) {
17
12
  while (1) switch (_context.prev = _context.next) {
@@ -26,5 +21,5 @@ export function deleteActionFn(_ref) {
26
21
  return function (_x) {
27
22
  return _ref2.apply(this, arguments);
28
23
  };
29
- }());
24
+ }();
30
25
  }
@@ -1,11 +1,10 @@
1
- import { ZodSchema } from "zod";
2
- import { BaseTable, GetListRelations } from "../types";
1
+ import { z, ZodSchema } from "zod";
3
2
  import { NodePgDatabase } from "drizzle-orm/node-postgres";
4
- export declare function getListActionFn<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable>({ bodySchema, db, jsonArrayFields, querySchema, relations, table, }: {
3
+ import { BaseTable, GetListRelations } from "../types";
4
+ export declare function createGetAction<T extends ZodSchema, TTable extends BaseTable>({ bodySchema, db, jsonArrayFields, relations, table, }: {
5
5
  bodySchema: T;
6
6
  db: NodePgDatabase<any>;
7
7
  jsonArrayFields?: string[];
8
- querySchema: Q;
9
8
  relations?: GetListRelations;
10
9
  table: TTable;
11
- }): any;
10
+ }): (params: Partial<z.infer<T>>) => Promise<T["_output"]>;
@@ -8,23 +8,15 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
8
8
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
9
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
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 { rpcOperation } from "next-rest-framework";
12
11
  import { getListQuery } from "./get-list-query";
13
12
  import { getListData } from "./get-list-data";
14
- export function getActionFn(_ref) {
13
+ export function createGetAction(_ref) {
15
14
  var bodySchema = _ref.bodySchema,
16
15
  db = _ref.db,
17
16
  jsonArrayFields = _ref.jsonArrayFields,
18
- querySchema = _ref.querySchema,
19
17
  relations = _ref.relations,
20
18
  table = _ref.table;
21
- return rpcOperation().input({
22
- body: querySchema,
23
- contentType: "application/json"
24
- }).outputs([{
25
- body: bodySchema,
26
- contentType: "application/json"
27
- }]).handler( /*#__PURE__*/function () {
19
+ return /*#__PURE__*/function () {
28
20
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
29
21
  var fields, _i, _Object$keys, key, field, _getListQuery, query, countQuery, _yield$getListData, _yield$getListData$da, result;
30
22
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -61,7 +53,7 @@ export function getActionFn(_ref) {
61
53
  _yield$getListData = _context.sent;
62
54
  _yield$getListData$da = _slicedToArray(_yield$getListData.data, 1);
63
55
  result = _yield$getListData$da[0];
64
- return _context.abrupt("return", result || {});
56
+ return _context.abrupt("return", result);
65
57
  case 9:
66
58
  case "end":
67
59
  return _context.stop();
@@ -71,5 +63,5 @@ export function getActionFn(_ref) {
71
63
  return function (_x) {
72
64
  return _ref2.apply(this, arguments);
73
65
  };
74
- }());
66
+ }();
75
67
  }
@@ -0,0 +1,13 @@
1
+ import { z, ZodSchema } from "zod";
2
+ import { BaseTable, GetListRelations } from "../types";
3
+ import { NodePgDatabase } from "drizzle-orm/node-postgres";
4
+ export declare function createGetListAction<T extends ZodSchema, TTable extends BaseTable>({ bodySchema, db, jsonArrayFields, relations, table, }: {
5
+ bodySchema: T;
6
+ db: NodePgDatabase<any>;
7
+ jsonArrayFields?: string[];
8
+ relations?: GetListRelations;
9
+ table: TTable;
10
+ }): (params: Partial<z.infer<T>>) => Promise<{
11
+ data: T["_output"][];
12
+ total: number;
13
+ }>;
@@ -5,24 +5,15 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
5
5
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
6
6
  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); } }
7
7
  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); }); }; }
8
- import { rpcOperation } from "next-rest-framework";
9
- import { listBodySchema } from "../schemas";
10
8
  import { getListQuery } from "./get-list-query";
11
9
  import { getListData } from "./get-list-data";
12
- export function getListActionFn(_ref) {
10
+ export function createGetListAction(_ref) {
13
11
  var bodySchema = _ref.bodySchema,
14
12
  db = _ref.db,
15
13
  jsonArrayFields = _ref.jsonArrayFields,
16
- querySchema = _ref.querySchema,
17
14
  relations = _ref.relations,
18
15
  table = _ref.table;
19
- return rpcOperation().input({
20
- body: querySchema,
21
- contentType: "application/json"
22
- }).outputs([{
23
- body: listBodySchema(bodySchema),
24
- contentType: "application/json"
25
- }]).handler( /*#__PURE__*/function () {
16
+ return /*#__PURE__*/function () {
26
17
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
27
18
  var current, pageSize, other, fields, _i, _Object$keys, key, field, _getListQuery, query, countQuery;
28
19
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -64,5 +55,5 @@ export function getListActionFn(_ref) {
64
55
  return function (_x) {
65
56
  return _ref2.apply(this, arguments);
66
57
  };
67
- }());
58
+ }();
68
59
  }
@@ -0,0 +1,8 @@
1
+ import { z, ZodSchema } from "zod";
2
+ import { PgTable } from "drizzle-orm/pg-core";
3
+ import { NodePgDatabase } from "drizzle-orm/node-postgres";
4
+ export declare function createPostAction<T extends ZodSchema, TTable extends PgTable>({ table, db, }: {
5
+ bodySchema: T;
6
+ db: NodePgDatabase<any>;
7
+ table: TTable;
8
+ }): (body: z.infer<T>) => Promise<T["_output"][]>;
@@ -2,21 +2,11 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
2
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
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
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 { z } from "zod";
6
- import { rpcOperation } from "next-rest-framework";
7
5
  import { transformBody } from "./transform-body";
8
- export function postActionFn(_ref) {
9
- var bodySchema = _ref.bodySchema,
10
- table = _ref.table,
6
+ export function createPostAction(_ref) {
7
+ var table = _ref.table,
11
8
  db = _ref.db;
12
- return rpcOperation().input({
13
- body: bodySchema,
14
- contentType: "application/json"
15
- }).outputs([{
16
- body: z.array(bodySchema),
17
- contentType: "application/json",
18
- status: 200
19
- }]).handler( /*#__PURE__*/function () {
9
+ return /*#__PURE__*/function () {
20
10
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(body) {
21
11
  return _regeneratorRuntime().wrap(function _callee$(_context) {
22
12
  while (1) switch (_context.prev = _context.next) {
@@ -31,5 +21,5 @@ export function postActionFn(_ref) {
31
21
  return function (_x) {
32
22
  return _ref2.apply(this, arguments);
33
23
  };
34
- }());
24
+ }();
35
25
  }
@@ -0,0 +1,8 @@
1
+ import { z, ZodSchema } from "zod";
2
+ import { NodePgDatabase } from "drizzle-orm/node-postgres";
3
+ import { BaseTable } from "../types";
4
+ export declare function createPutAction<T extends ZodSchema, TTable extends BaseTable>({ db, table, }: {
5
+ bodySchema: T;
6
+ db: NodePgDatabase<any>;
7
+ table: TTable;
8
+ }): (body: Partial<z.infer<T>>) => Promise<T["_output"]>;
@@ -2,25 +2,17 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
2
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
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
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 { rpcOperation } from "next-rest-framework";
6
5
  import { transformBody } from "./transform-body";
7
6
  import { eq } from "drizzle-orm";
8
- export function putActionFn(_ref) {
7
+ export function createPutAction(_ref) {
9
8
  var db = _ref.db,
10
- bodySchema = _ref.bodySchema,
11
9
  table = _ref.table;
12
- return rpcOperation().input({
13
- body: bodySchema,
14
- contentType: "application/json"
15
- }).handler( /*#__PURE__*/function () {
10
+ return /*#__PURE__*/function () {
16
11
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(body) {
17
12
  return _regeneratorRuntime().wrap(function _callee$(_context) {
18
13
  while (1) switch (_context.prev = _context.next) {
19
14
  case 0:
20
- return _context.abrupt("return", db.update(table).set(transformBody(body))
21
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
22
- // @ts-ignore
23
- .where(eq(table.id, body.id)).returning());
15
+ return _context.abrupt("return", db.update(table).set(transformBody(body)).where(eq(table.id, body.id)).returning());
24
16
  case 1:
25
17
  case "end":
26
18
  return _context.stop();
@@ -30,5 +22,5 @@ export function putActionFn(_ref) {
30
22
  return function (_x) {
31
23
  return _ref2.apply(this, arguments);
32
24
  };
33
- }());
25
+ }();
34
26
  }
@@ -4,4 +4,19 @@ export declare function getListData<B extends ZodSchema>({ query, countQuery, pa
4
4
  bodySchema: B;
5
5
  current?: number;
6
6
  pageSize?: number;
7
- } & ReturnType<typeof getListQuery>): any;
7
+ } & ReturnType<typeof getListQuery>): import("next-rest-framework/dist/index-Xbs7wi4f").R<"application/json" | "application/x-www-form-urlencoded" | "multipart/form-data", unknown, {
8
+ body: import("zod").ZodObject<{
9
+ total: import("zod").ZodNumber;
10
+ data: import("zod").ZodArray<B, "many">;
11
+ }, "strip", import("zod").ZodTypeAny, {
12
+ data: B["_output"][];
13
+ total: number;
14
+ }, {
15
+ data: B["_input"][];
16
+ total: number;
17
+ }>;
18
+ contentType: "application/json";
19
+ }[], false, Promise<{
20
+ data: B["_output"][];
21
+ total: number;
22
+ }>>;
@@ -1,6 +1,6 @@
1
- export { deleteActionFn } from "./delete-action-fn";
2
- export { getActionFn } from "./get-action-fn";
3
- export { getListActionFn } from "./get-list-action-fn";
4
- export { postActionFn } from "./post-action-fn";
5
- export { putActionFn } from "./put-action-fn";
1
+ export { createDeleteAction } from "./create-delete-action";
2
+ export { createGetAction } from "./create-get-action";
3
+ export { createGetListAction } from "./create-get-list-action";
4
+ export { createPostAction } from "./create-post-action";
5
+ export { createPutAction } from "./create-put-action";
6
6
  export { getListQuery } from "./get-list-query";
@@ -1,6 +1,6 @@
1
- export { deleteActionFn } from "./delete-action-fn";
2
- export { getActionFn } from "./get-action-fn";
3
- export { getListActionFn } from "./get-list-action-fn";
4
- export { postActionFn } from "./post-action-fn";
5
- export { putActionFn } from "./put-action-fn";
1
+ export { createDeleteAction } from "./create-delete-action";
2
+ export { createGetAction } from "./create-get-action";
3
+ export { createGetListAction } from "./create-get-list-action";
4
+ export { createPostAction } from "./create-post-action";
5
+ export { createPutAction } from "./create-put-action";
6
6
  export { getListQuery } from "./get-list-query";
@@ -3,7 +3,8 @@ import { NodePgDatabase } from "drizzle-orm/node-postgres";
3
3
  export interface DeleteOperationOptions<TTable extends BaseTable> {
4
4
  table: TTable;
5
5
  summary?: string;
6
+ onSuccess?: () => Promise<void>;
6
7
  }
7
- export declare const createDeleteOperation: <TTable extends BaseTable>({ db }: {
8
+ export declare const createDeleteOperation: ({ db }: {
8
9
  db: NodePgDatabase<any>;
9
- }) => ({ table, summary }: DeleteOperationOptions<TTable>) => any;
10
+ }) => <TTable extends BaseTable>({ table, summary, onSuccess, }: DeleteOperationOptions<TTable>) => any;
@@ -5,12 +5,13 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
5
5
  import { routeOperation, TypedNextResponse } from "next-rest-framework";
6
6
  import { z } from "zod";
7
7
  import getTableName from "./get-table-name";
8
- import { deleteActionFn } from "../actions";
8
+ import { createDeleteAction } from "../actions";
9
9
  export var createDeleteOperation = function createDeleteOperation(_ref) {
10
10
  var db = _ref.db;
11
11
  return function (_ref2) {
12
12
  var table = _ref2.table,
13
- summary = _ref2.summary;
13
+ summary = _ref2.summary,
14
+ onSuccess = _ref2.onSuccess;
14
15
  return routeOperation({
15
16
  method: "DELETE",
16
17
  openApiOperation: {
@@ -24,7 +25,7 @@ export var createDeleteOperation = function createDeleteOperation(_ref) {
24
25
  contentType: "application/json"
25
26
  }).handler( /*#__PURE__*/function () {
26
27
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
27
- var _yield$req$json, id;
28
+ var _yield$req$json, id, data;
28
29
  return _regeneratorRuntime().wrap(function _callee$(_context) {
29
30
  while (1) switch (_context.prev = _context.next) {
30
31
  case 0:
@@ -33,18 +34,19 @@ export var createDeleteOperation = function createDeleteOperation(_ref) {
33
34
  case 2:
34
35
  _yield$req$json = _context.sent;
35
36
  id = _yield$req$json.id;
36
- _context.t0 = TypedNextResponse;
37
- _context.next = 7;
38
- return deleteActionFn({
37
+ _context.next = 6;
38
+ return createDeleteAction({
39
39
  table: table,
40
40
  db: db
41
41
  })(id);
42
- case 7:
43
- _context.t1 = _context.sent;
44
- _context.t2 = {
42
+ case 6:
43
+ data = _context.sent;
44
+ _context.next = 9;
45
+ return onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess();
46
+ case 9:
47
+ return _context.abrupt("return", TypedNextResponse.json(data, {
45
48
  status: 200
46
- };
47
- return _context.abrupt("return", _context.t0.json.call(_context.t0, _context.t1, _context.t2));
49
+ }));
48
50
  case 10:
49
51
  case "end":
50
52
  return _context.stop();
@@ -11,7 +11,7 @@ export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchem
11
11
  byCreator?: boolean;
12
12
  summary?: string;
13
13
  table: TTable;
14
- transform?: <D extends T>(data: {
14
+ onSuccess?: <D extends T>(data: {
15
15
  data: z.infer<D>[];
16
16
  total: number;
17
17
  }) => Promise<{
@@ -19,9 +19,9 @@ export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchem
19
19
  total: number;
20
20
  }>;
21
21
  }
22
- export declare const createGetListOperation: <T extends z.ZodType<any, z.ZodTypeDef, any>, Q extends z.ZodType<any, z.ZodTypeDef, any>, TTable extends BaseTable>({ db, getSession, }: {
22
+ export declare const createGetListOperation: ({ db, getSession, }: {
23
23
  db: NodePgDatabase<any>;
24
24
  getSession: (req: NextRequest) => Promise<{
25
25
  userId?: string;
26
26
  } | undefined>;
27
- }) => ({ querySchema, bodySchema, table, summary, relations, jsonArrayFields, setParams, transform, byCreator, }: GetListOperationOptions<T, Q, TTable>) => any;
27
+ }) => <T extends z.ZodType<any, z.ZodTypeDef, any>, Q extends z.ZodType<any, z.ZodTypeDef, any>, TTable extends BaseTable>({ querySchema, bodySchema, table, summary, relations, jsonArrayFields, setParams, onSuccess, byCreator, }: GetListOperationOptions<T, Q, TTable>) => any;
@@ -5,7 +5,7 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
5
5
  import { routeOperation, TypedNextResponse } from "next-rest-framework";
6
6
  import getTableName from "./get-table-name";
7
7
  import { listBodySchema } from "../schemas";
8
- import { getListActionFn } from "../actions";
8
+ import { createGetListAction } from "../actions";
9
9
  export var createGetListOperation = function createGetListOperation(_ref) {
10
10
  var db = _ref.db,
11
11
  getSession = _ref.getSession;
@@ -17,7 +17,7 @@ export var createGetListOperation = function createGetListOperation(_ref) {
17
17
  relations = _ref2.relations,
18
18
  jsonArrayFields = _ref2.jsonArrayFields,
19
19
  setParams = _ref2.setParams,
20
- transform = _ref2.transform,
20
+ onSuccess = _ref2.onSuccess,
21
21
  _ref2$byCreator = _ref2.byCreator,
22
22
  byCreator = _ref2$byCreator === void 0 ? true : _ref2$byCreator;
23
23
  return routeOperation({
@@ -68,22 +68,21 @@ export var createGetListOperation = function createGetListOperation(_ref) {
68
68
  params.creatorId = userId;
69
69
  case 15:
70
70
  _context.next = 17;
71
- return getListActionFn({
71
+ return createGetListAction({
72
72
  bodySchema: bodySchema,
73
73
  db: db,
74
74
  jsonArrayFields: jsonArrayFields,
75
- querySchema: querySchema,
76
75
  relations: relations,
77
76
  table: table
78
77
  })(Object.assign(Object.fromEntries(new URL(req.url).searchParams), params));
79
78
  case 17:
80
79
  result = _context.sent;
81
- if (!transform) {
80
+ if (!onSuccess) {
82
81
  _context.next = 22;
83
82
  break;
84
83
  }
85
84
  _context.next = 21;
86
- return transform(result);
85
+ return onSuccess(result);
87
86
  case 21:
88
87
  result = _context.sent;
89
88
  case 22:
@@ -1,4 +1,4 @@
1
- import { ZodSchema } from "zod";
1
+ import { z, ZodSchema } from "zod";
2
2
  import { NextRequest } from "next/server";
3
3
  import { NodePgDatabase } from "drizzle-orm/node-postgres";
4
4
  import { BaseTable, GetListRelations } from "../types";
@@ -8,13 +8,14 @@ export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, T
8
8
  querySchema: Q;
9
9
  relations?: GetListRelations;
10
10
  setParams?: (req: NextRequest) => Promise<Record<string, any>>;
11
+ onSuccess?: (data: z.infer<T>) => Promise<z.infer<T>>;
11
12
  summary?: string;
12
13
  table: TTable;
13
14
  byCreator?: boolean;
14
15
  }
15
- export declare const createGetOperation: <T extends ZodSchema<any, import("zod").ZodTypeDef, any>, Q extends ZodSchema<any, import("zod").ZodTypeDef, any>, TTable extends BaseTable>({ getSession, db, }: {
16
+ export declare const createGetOperation: ({ getSession, db, }: {
16
17
  db: NodePgDatabase<any>;
17
18
  getSession: (req: NextRequest) => Promise<{
18
19
  userId?: string;
19
20
  } | undefined>;
20
- }) => ({ querySchema, bodySchema, table, summary, relations, setParams, jsonArrayFields, byCreator, }: GetOperationOptions<T, Q, TTable>) => any;
21
+ }) => <T extends z.ZodType<any, z.ZodTypeDef, any>, Q extends z.ZodType<any, z.ZodTypeDef, any>, TTable extends BaseTable>({ querySchema, bodySchema, table, summary, relations, setParams, jsonArrayFields, onSuccess, byCreator, }: GetOperationOptions<T, Q, TTable>) => any;
@@ -4,7 +4,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
4
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
5
  import { routeOperation, TypedNextResponse } from "next-rest-framework";
6
6
  import getTableName from "./get-table-name";
7
- import { getActionFn } from "../actions";
7
+ import { createGetAction } from "../actions";
8
8
  export var createGetOperation = function createGetOperation(_ref) {
9
9
  var getSession = _ref.getSession,
10
10
  db = _ref.db;
@@ -16,6 +16,7 @@ export var createGetOperation = function createGetOperation(_ref) {
16
16
  relations = _ref2.relations,
17
17
  setParams = _ref2.setParams,
18
18
  jsonArrayFields = _ref2.jsonArrayFields,
19
+ onSuccess = _ref2.onSuccess,
19
20
  _ref2$byCreator = _ref2.byCreator,
20
21
  byCreator = _ref2$byCreator === void 0 ? true : _ref2$byCreator;
21
22
  return routeOperation({
@@ -66,20 +67,35 @@ export var createGetOperation = function createGetOperation(_ref) {
66
67
  params.creatorId = userId;
67
68
  case 15:
68
69
  _context.next = 17;
69
- return getActionFn({
70
+ return createGetAction({
70
71
  bodySchema: bodySchema,
71
72
  db: db,
72
73
  jsonArrayFields: jsonArrayFields,
73
- querySchema: querySchema,
74
74
  relations: relations,
75
75
  table: table
76
76
  })(Object.assign(Object.fromEntries(new URL(req.url).searchParams), params));
77
77
  case 17:
78
+ _context.t2 = _context.sent;
79
+ if (_context.t2) {
80
+ _context.next = 20;
81
+ break;
82
+ }
83
+ _context.t2 = {};
84
+ case 20:
85
+ result = _context.t2;
86
+ if (!onSuccess) {
87
+ _context.next = 25;
88
+ break;
89
+ }
90
+ _context.next = 24;
91
+ return onSuccess(result);
92
+ case 24:
78
93
  result = _context.sent;
94
+ case 25:
79
95
  return _context.abrupt("return", TypedNextResponse.json(result, {
80
96
  status: 200
81
97
  }));
82
- case 19:
98
+ case 26:
83
99
  case "end":
84
100
  return _context.stop();
85
101
  }
@@ -6,11 +6,12 @@ export interface PostOperationOptions<T extends ZodSchema, TTable extends PgTabl
6
6
  bodySchema: T;
7
7
  setBody?: (req: NextRequest) => Promise<Partial<z.infer<T>>>;
8
8
  summary?: string;
9
+ onSuccess?: (data: z.infer<T>) => Promise<z.infer<T>>;
9
10
  table: TTable;
10
11
  }
11
- export declare const createPostOperation: <T extends z.ZodType<any, z.ZodTypeDef, any>, TTable extends PgTable<import("drizzle-orm/pg-core").TableConfig>>({ getSession, db, }: {
12
+ export declare const createPostOperation: ({ getSession, db, }: {
12
13
  db: NodePgDatabase<any>;
13
14
  getSession: (req: NextRequest) => Promise<{
14
15
  userId?: string;
15
16
  } | undefined>;
16
- }) => ({ bodySchema, setBody, summary, table }: PostOperationOptions<T, TTable>) => any;
17
+ }) => <T extends z.ZodType<any, z.ZodTypeDef, any>, TTable extends PgTable<import("drizzle-orm/pg-core").TableConfig>>({ bodySchema, setBody, summary, table, onSuccess, }: PostOperationOptions<T, TTable>) => any;