@ai0x0/utils 0.0.37 → 0.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/.agents/skills/ai0x0-utils/backend/SKILL.md +12 -8
  2. package/README.md +42 -1
  3. package/SKILL.md +12 -8
  4. package/es/backend/route-operation/delete-operation.d.ts +3 -2
  5. package/es/backend/route-operation/delete-operation.js +35 -22
  6. package/es/backend/route-operation/get-list-operation.d.ts +6 -5
  7. package/es/backend/route-operation/get-list-operation.js +37 -22
  8. package/es/backend/route-operation/get-operation.d.ts +5 -4
  9. package/es/backend/route-operation/get-operation.js +34 -22
  10. package/es/backend/route-operation/post-operation.d.ts +5 -4
  11. package/es/backend/route-operation/post-operation.js +39 -34
  12. package/es/backend/route-operation/put-operation.d.ts +5 -4
  13. package/es/backend/route-operation/put-operation.js +44 -29
  14. package/es/backend/sqlite/actions/create-delete-action.d.ts +8 -0
  15. package/es/backend/sqlite/actions/create-delete-action.js +54 -0
  16. package/es/backend/sqlite/actions/create-get-action.d.ts +8 -0
  17. package/es/backend/sqlite/actions/create-get-action.js +64 -0
  18. package/es/backend/sqlite/actions/create-get-list-action.d.ts +11 -0
  19. package/es/backend/sqlite/actions/create-get-list-action.js +56 -0
  20. package/es/backend/sqlite/actions/create-post-action.d.ts +6 -0
  21. package/es/backend/sqlite/actions/create-post-action.js +31 -0
  22. package/es/backend/sqlite/actions/create-put-action.d.ts +8 -0
  23. package/es/backend/sqlite/actions/create-put-action.js +74 -0
  24. package/es/backend/sqlite/actions/get-list-data.d.ts +9 -0
  25. package/es/backend/sqlite/actions/get-list-data.js +75 -0
  26. package/es/backend/sqlite/actions/get-list-query.d.ts +19 -0
  27. package/es/backend/sqlite/actions/get-list-query.js +215 -0
  28. package/es/backend/sqlite/actions/index.d.ts +6 -0
  29. package/es/backend/sqlite/actions/index.js +6 -0
  30. package/es/backend/sqlite/actions/transform-body.d.ts +1 -0
  31. package/es/backend/sqlite/actions/transform-body.js +9 -0
  32. package/es/backend/sqlite/errors.d.ts +4 -0
  33. package/es/backend/sqlite/errors.js +31 -0
  34. package/es/backend/sqlite/index.d.ts +5 -0
  35. package/es/backend/sqlite/index.js +5 -0
  36. package/es/backend/sqlite/route-operation/delete-operation.d.ts +11 -0
  37. package/es/backend/sqlite/route-operation/delete-operation.js +122 -0
  38. package/es/backend/sqlite/route-operation/get-list-operation.d.ts +23 -0
  39. package/es/backend/sqlite/route-operation/get-list-operation.js +135 -0
  40. package/es/backend/sqlite/route-operation/get-operation.d.ts +17 -0
  41. package/es/backend/sqlite/route-operation/get-operation.js +132 -0
  42. package/es/backend/sqlite/route-operation/get-table-name.d.ts +3 -0
  43. package/es/backend/sqlite/route-operation/get-table-name.js +11 -0
  44. package/es/backend/sqlite/route-operation/index.d.ts +5 -0
  45. package/es/backend/sqlite/route-operation/index.js +5 -0
  46. package/es/backend/sqlite/route-operation/post-operation.d.ts +14 -0
  47. package/es/backend/sqlite/route-operation/post-operation.js +141 -0
  48. package/es/backend/sqlite/route-operation/put-operation.d.ts +15 -0
  49. package/es/backend/sqlite/route-operation/put-operation.js +156 -0
  50. package/es/backend/sqlite/schemas/index.d.ts +68 -0
  51. package/es/backend/sqlite/schemas/index.js +133 -0
  52. package/es/backend/sqlite/types.d.ts +16 -0
  53. package/es/backend/sqlite/types.js +1 -0
  54. package/lib/backend/route-operation/delete-operation.d.ts +3 -2
  55. package/lib/backend/route-operation/delete-operation.js +5 -3
  56. package/lib/backend/route-operation/get-list-operation.d.ts +6 -5
  57. package/lib/backend/route-operation/get-list-operation.js +8 -8
  58. package/lib/backend/route-operation/get-operation.d.ts +5 -4
  59. package/lib/backend/route-operation/get-operation.js +8 -8
  60. package/lib/backend/route-operation/post-operation.d.ts +5 -4
  61. package/lib/backend/route-operation/post-operation.js +4 -3
  62. package/lib/backend/route-operation/put-operation.d.ts +5 -4
  63. package/lib/backend/route-operation/put-operation.js +6 -4
  64. package/lib/backend/sqlite/actions/create-delete-action.d.ts +8 -0
  65. package/lib/backend/sqlite/actions/create-delete-action.js +53 -0
  66. package/lib/backend/sqlite/actions/create-get-action.d.ts +8 -0
  67. package/lib/backend/sqlite/actions/create-get-action.js +65 -0
  68. package/lib/backend/sqlite/actions/create-get-list-action.d.ts +11 -0
  69. package/lib/backend/sqlite/actions/create-get-list-action.js +63 -0
  70. package/lib/backend/sqlite/actions/create-post-action.d.ts +6 -0
  71. package/lib/backend/sqlite/actions/create-post-action.js +39 -0
  72. package/lib/backend/sqlite/actions/create-put-action.d.ts +8 -0
  73. package/lib/backend/sqlite/actions/create-put-action.js +60 -0
  74. package/lib/backend/sqlite/actions/get-list-data.d.ts +9 -0
  75. package/lib/backend/sqlite/actions/get-list-data.js +51 -0
  76. package/lib/backend/sqlite/actions/get-list-query.d.ts +19 -0
  77. package/lib/backend/sqlite/actions/get-list-query.js +165 -0
  78. package/lib/backend/sqlite/actions/index.d.ts +6 -0
  79. package/lib/backend/sqlite/actions/index.js +44 -0
  80. package/lib/backend/sqlite/actions/transform-body.d.ts +1 -0
  81. package/lib/backend/sqlite/actions/transform-body.js +49 -0
  82. package/lib/backend/sqlite/errors.d.ts +4 -0
  83. package/lib/backend/sqlite/errors.js +35 -0
  84. package/lib/backend/sqlite/index.d.ts +5 -0
  85. package/lib/backend/sqlite/index.js +31 -0
  86. package/lib/backend/sqlite/route-operation/delete-operation.d.ts +11 -0
  87. package/lib/backend/sqlite/route-operation/delete-operation.js +92 -0
  88. package/lib/backend/sqlite/route-operation/get-list-operation.d.ts +23 -0
  89. package/lib/backend/sqlite/route-operation/get-list-operation.js +108 -0
  90. package/lib/backend/sqlite/route-operation/get-operation.d.ts +17 -0
  91. package/lib/backend/sqlite/route-operation/get-operation.js +107 -0
  92. package/lib/backend/sqlite/route-operation/get-table-name.d.ts +3 -0
  93. package/lib/backend/sqlite/route-operation/get-table-name.js +35 -0
  94. package/lib/backend/sqlite/route-operation/index.d.ts +5 -0
  95. package/lib/backend/sqlite/route-operation/index.js +31 -0
  96. package/lib/backend/sqlite/route-operation/post-operation.d.ts +14 -0
  97. package/lib/backend/sqlite/route-operation/post-operation.js +95 -0
  98. package/lib/backend/sqlite/route-operation/put-operation.d.ts +15 -0
  99. package/lib/backend/sqlite/route-operation/put-operation.js +104 -0
  100. package/lib/backend/sqlite/schemas/index.d.ts +68 -0
  101. package/lib/backend/sqlite/schemas/index.js +113 -0
  102. package/lib/backend/sqlite/types.d.ts +16 -0
  103. package/lib/backend/sqlite/types.js +17 -0
  104. package/package.json +3 -1
@@ -0,0 +1,141 @@
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
9
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
10
+ import { z } from "zod";
11
+ import { routeOperation, TypedNextResponse } from "next-rest-framework";
12
+ import getTableName from "./get-table-name.js";
13
+ import { createPostAction } from "../actions/index.js";
14
+ export var createPostOperation = function createPostOperation(_ref) {
15
+ var getSession = _ref.getSession,
16
+ db = _ref.db;
17
+ return function (_ref2) {
18
+ var bodySchema = _ref2.bodySchema,
19
+ outputBodySchema = _ref2.outputBodySchema,
20
+ setBody = _ref2.setBody,
21
+ summary = _ref2.summary,
22
+ tags = _ref2.tags,
23
+ table = _ref2.table,
24
+ onSuccess = _ref2.onSuccess,
25
+ onError = _ref2.onError;
26
+ return routeOperation({
27
+ method: "POST",
28
+ openApiOperation: {
29
+ summary: summary,
30
+ tags: tags !== null && tags !== void 0 ? tags : table ? [getTableName(table)] : []
31
+ }
32
+ }).input({
33
+ body: bodySchema,
34
+ contentType: "application/json"
35
+ }).outputs([{
36
+ body: outputBodySchema || z.object({
37
+ id: z.string()
38
+ }),
39
+ contentType: "application/json",
40
+ status: 200
41
+ }]).handler( /*#__PURE__*/function () {
42
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
43
+ var _ref4, userId, body, extraBody, mergedBody, raw, data, response;
44
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
45
+ while (1) switch (_context.prev = _context.next) {
46
+ case 0:
47
+ _context.prev = 0;
48
+ _context.next = 3;
49
+ return getSession(req);
50
+ case 3:
51
+ _context.t0 = _context.sent;
52
+ if (_context.t0) {
53
+ _context.next = 6;
54
+ break;
55
+ }
56
+ _context.t0 = {};
57
+ case 6:
58
+ _ref4 = _context.t0;
59
+ userId = _ref4.userId;
60
+ _context.next = 10;
61
+ return req.json();
62
+ case 10:
63
+ body = _context.sent;
64
+ _context.next = 13;
65
+ return setBody === null || setBody === void 0 ? void 0 : setBody(req);
66
+ case 13:
67
+ _context.t1 = _context.sent;
68
+ if (_context.t1) {
69
+ _context.next = 16;
70
+ break;
71
+ }
72
+ _context.t1 = {};
73
+ case 16:
74
+ extraBody = _context.t1;
75
+ mergedBody = _objectSpread(_objectSpread({}, body), extraBody);
76
+ if (!table) {
77
+ _context.next = 24;
78
+ break;
79
+ }
80
+ _context.next = 21;
81
+ return createPostAction({
82
+ bodySchema: bodySchema,
83
+ db: db,
84
+ table: table
85
+ })(_objectSpread({
86
+ creatorId: userId
87
+ }, mergedBody));
88
+ case 21:
89
+ _context.t2 = _context.sent[0];
90
+ _context.next = 25;
91
+ break;
92
+ case 24:
93
+ _context.t2 = _objectSpread({
94
+ creatorId: userId
95
+ }, mergedBody);
96
+ case 25:
97
+ raw = _context.t2;
98
+ if (!onSuccess) {
99
+ _context.next = 32;
100
+ break;
101
+ }
102
+ _context.next = 29;
103
+ return onSuccess(raw);
104
+ case 29:
105
+ _context.t3 = _context.sent;
106
+ _context.next = 33;
107
+ break;
108
+ case 32:
109
+ _context.t3 = raw;
110
+ case 33:
111
+ data = _context.t3;
112
+ return _context.abrupt("return", TypedNextResponse.json(data, {
113
+ status: 200
114
+ }));
115
+ case 37:
116
+ _context.prev = 37;
117
+ _context.t4 = _context["catch"](0);
118
+ console.error(_context.t4);
119
+ _context.next = 42;
120
+ return onError === null || onError === void 0 ? void 0 : onError(_context.t4);
121
+ case 42:
122
+ response = _context.sent;
123
+ if (!response) {
124
+ _context.next = 47;
125
+ break;
126
+ }
127
+ return _context.abrupt("return", response);
128
+ case 47:
129
+ throw _context.t4;
130
+ case 48:
131
+ case "end":
132
+ return _context.stop();
133
+ }
134
+ }, _callee, null, [[0, 37]]);
135
+ }));
136
+ return function (_x) {
137
+ return _ref3.apply(this, arguments);
138
+ };
139
+ }());
140
+ };
141
+ };
@@ -0,0 +1,15 @@
1
+ import { z, ZodSchema } from "zod";
2
+ import { SQLiteTable } from "drizzle-orm/sqlite-core";
3
+ import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
4
+ export interface PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends SQLiteTable> {
5
+ bodySchema: IB;
6
+ outputBodySchema?: OB;
7
+ table?: TTable;
8
+ summary?: string;
9
+ tags?: string[];
10
+ setBody?: (_req: TypedNextRequest<"PUT", "application/json", z.infer<IB>>) => Promise<Partial<z.infer<IB>>>;
11
+ onSuccess?: (_data: z.infer<OB>) => Promise<z.infer<OB>>;
12
+ onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
13
+ byCreator?: boolean;
14
+ }
15
+ export declare const createPutOperation: any;
@@ -0,0 +1,156 @@
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
9
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
10
+ import { z } from "zod";
11
+ import { routeOperation, TypedNextResponse } from "next-rest-framework";
12
+ import getTableName from "./get-table-name.js";
13
+ import { createPutAction } from "../actions/index.js";
14
+ import { HttpError } from "../errors.js";
15
+ export var createPutOperation = function createPutOperation(_ref) {
16
+ var getSession = _ref.getSession,
17
+ db = _ref.db;
18
+ return function (_ref2) {
19
+ var bodySchema = _ref2.bodySchema,
20
+ outputBodySchema = _ref2.outputBodySchema,
21
+ table = _ref2.table,
22
+ summary = _ref2.summary,
23
+ tags = _ref2.tags,
24
+ setBody = _ref2.setBody,
25
+ onSuccess = _ref2.onSuccess,
26
+ _ref2$byCreator = _ref2.byCreator,
27
+ byCreator = _ref2$byCreator === void 0 ? true : _ref2$byCreator,
28
+ onError = _ref2.onError;
29
+ return routeOperation({
30
+ method: "PUT",
31
+ openApiOperation: {
32
+ summary: summary,
33
+ tags: tags !== null && tags !== void 0 ? tags : table ? [getTableName(table)] : []
34
+ }
35
+ }).input({
36
+ body: bodySchema,
37
+ contentType: "application/json"
38
+ }).outputs([{
39
+ body: outputBodySchema || z.void(),
40
+ status: 200,
41
+ contentType: "application/json"
42
+ }]).handler( /*#__PURE__*/function () {
43
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
44
+ var _ref4, userId, body, extraBody, mergedBody, raw, data, response;
45
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
46
+ while (1) switch (_context.prev = _context.next) {
47
+ case 0:
48
+ _context.prev = 0;
49
+ _context.next = 3;
50
+ return getSession(req);
51
+ case 3:
52
+ _context.t0 = _context.sent;
53
+ if (_context.t0) {
54
+ _context.next = 6;
55
+ break;
56
+ }
57
+ _context.t0 = {};
58
+ case 6:
59
+ _ref4 = _context.t0;
60
+ userId = _ref4.userId;
61
+ _context.next = 10;
62
+ return req.json();
63
+ case 10:
64
+ body = _context.sent;
65
+ _context.next = 13;
66
+ return setBody === null || setBody === void 0 ? void 0 : setBody(req);
67
+ case 13:
68
+ _context.t1 = _context.sent;
69
+ if (_context.t1) {
70
+ _context.next = 16;
71
+ break;
72
+ }
73
+ _context.t1 = {};
74
+ case 16:
75
+ extraBody = _context.t1;
76
+ mergedBody = _objectSpread(_objectSpread({}, body), extraBody);
77
+ if (!table) {
78
+ _context.next = 24;
79
+ break;
80
+ }
81
+ _context.next = 21;
82
+ return createPutAction({
83
+ bodySchema: bodySchema,
84
+ table: table,
85
+ db: db
86
+ })(_objectSpread({
87
+ editorId: userId
88
+ }, mergedBody), {
89
+ byCreator: byCreator
90
+ });
91
+ case 21:
92
+ _context.t2 = _context.sent;
93
+ _context.next = 25;
94
+ break;
95
+ case 24:
96
+ _context.t2 = _objectSpread({
97
+ editorId: userId
98
+ }, mergedBody);
99
+ case 25:
100
+ raw = _context.t2;
101
+ if (!onSuccess) {
102
+ _context.next = 32;
103
+ break;
104
+ }
105
+ _context.next = 29;
106
+ return onSuccess(raw);
107
+ case 29:
108
+ _context.t3 = _context.sent;
109
+ _context.next = 33;
110
+ break;
111
+ case 32:
112
+ _context.t3 = raw;
113
+ case 33:
114
+ data = _context.t3;
115
+ return _context.abrupt("return", TypedNextResponse.json(data, {
116
+ status: 200
117
+ }));
118
+ case 37:
119
+ _context.prev = 37;
120
+ _context.t4 = _context["catch"](0);
121
+ if (!(_context.t4 instanceof HttpError)) {
122
+ console.error(_context.t4);
123
+ }
124
+ _context.next = 42;
125
+ return onError === null || onError === void 0 ? void 0 : onError(_context.t4);
126
+ case 42:
127
+ response = _context.sent;
128
+ if (!response) {
129
+ _context.next = 45;
130
+ break;
131
+ }
132
+ return _context.abrupt("return", response);
133
+ case 45:
134
+ if (!(_context.t4 instanceof HttpError)) {
135
+ _context.next = 47;
136
+ break;
137
+ }
138
+ return _context.abrupt("return", TypedNextResponse.json({
139
+ message: _context.t4.message
140
+ }, {
141
+ status: _context.t4.status
142
+ }));
143
+ case 47:
144
+ throw _context.t4;
145
+ case 48:
146
+ case "end":
147
+ return _context.stop();
148
+ }
149
+ }, _callee, null, [[0, 37]]);
150
+ }));
151
+ return function (_x) {
152
+ return _ref3.apply(this, arguments);
153
+ };
154
+ }());
155
+ };
156
+ };
@@ -0,0 +1,68 @@
1
+ import { z } from "zod";
2
+ import { type SQLiteColumnBuilderBase, type SQLiteTableExtraConfigValue } from "drizzle-orm/sqlite-core";
3
+ import type { BuildExtraConfigColumns } from "drizzle-orm";
4
+ export declare const basicFields: {
5
+ id: import("drizzle-orm").HasRuntimeDefault<import("drizzle-orm").HasDefault<import("drizzle-orm").IsPrimaryKey<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core").SQLiteTextBuilderInitial<"id", [string, ...string[]], number | undefined>>>>>;
6
+ creatorId: import("drizzle-orm/sqlite-core").SQLiteTextBuilderInitial<"creator_id", [string, ...string[]], number | undefined>;
7
+ editorId: import("drizzle-orm/sqlite-core").SQLiteTextBuilderInitial<"editor_id", [string, ...string[]], number | undefined>;
8
+ accessedAt: import("drizzle-orm").HasRuntimeDefault<import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core").SQLiteTimestampBuilderInitial<string>>>>;
9
+ createdAt: import("drizzle-orm").HasRuntimeDefault<import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core").SQLiteTimestampBuilderInitial<string>>>>;
10
+ updatedAt: import("drizzle-orm").HasRuntimeDefault<import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core").SQLiteTimestampBuilderInitial<string>>>>;
11
+ };
12
+ /**
13
+ * 业务侧 insert schema 需要从 drizzle-zod 生成的 schema 中排除的基础字段。
14
+ * 这些字段由后端在 createPostAction 中自动写入。
15
+ *
16
+ * 使用方式(在业务 schema 中):
17
+ * const insertFooSchema = createInsertSchema(foos)
18
+ * .omit(BASIC_INSERT_OMIT)
19
+ * .extend({ ... });
20
+ *
21
+ * 说明:上游导出为 const 而不是 helper function,是为了避免经过泛型
22
+ * wrapper 后 TS 把 drizzle-zod 推导出的深层条件 Shape 归约成 Omit,
23
+ * 从而在下游 `.extend(...)` 时丢失原有字段类型。
24
+ */
25
+ export declare const BASIC_INSERT_OMIT: {
26
+ readonly id: true;
27
+ readonly creatorId: true;
28
+ readonly editorId: true;
29
+ readonly accessedAt: true;
30
+ readonly createdAt: true;
31
+ readonly updatedAt: true;
32
+ };
33
+ /**
34
+ * 业务侧 update schema 需要从 drizzle-zod 生成的 schema 中排除的基础字段。
35
+ * update 保留 id(随后用 `.required({ id: true })` 变成必填),其余由
36
+ * 后端 createPutAction 自动维护。
37
+ */
38
+ export declare const BASIC_UPDATE_OMIT: {
39
+ readonly creatorId: true;
40
+ readonly editorId: true;
41
+ readonly accessedAt: true;
42
+ readonly createdAt: true;
43
+ readonly updatedAt: true;
44
+ };
45
+ export declare const queryListSchema: (schema: any) => z.ZodObject<{
46
+ [x: string]: any;
47
+ }, any>;
48
+ export declare const listBodySchema: (schema: any) => z.ZodObject<{
49
+ total: z.ZodNumber;
50
+ data: z.ZodArray<any>;
51
+ }, z.core.$strip>;
52
+ /**
53
+ * 基于 drizzle + drizzle-zod 快速生成带基础字段(id / 创建时间等)的
54
+ * 表定义以及 select / insert / update / query / list zod schema。
55
+ */
56
+ export declare const createTableSchema: <TTableName extends string, TColumnsMap extends Record<string, SQLiteColumnBuilderBase>>(_options: {
57
+ name: TTableName;
58
+ columns: TColumnsMap;
59
+ extraConfig?: (_self: BuildExtraConfigColumns<TTableName, typeof basicFields & TColumnsMap, "sqlite">) => SQLiteTableExtraConfigValue[];
60
+ }) => {
61
+ table: any;
62
+ selectSchema: any;
63
+ insertSchema: any;
64
+ updateSchema: any;
65
+ querySchema: any;
66
+ queryListSchema: any;
67
+ queryListSelectSchema: any;
68
+ };
@@ -0,0 +1,133 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ /* eslint-disable no-unused-vars */
8
+ import { z } from "zod";
9
+ import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
10
+ import { createInsertSchema, createSelectSchema, createUpdateSchema } from "drizzle-zod";
11
+
12
+ //============================基本字段============================//
13
+ var timestamp = function timestamp(name) {
14
+ return integer(name, {
15
+ mode: "timestamp_ms"
16
+ });
17
+ };
18
+ var now = function now() {
19
+ return new Date();
20
+ };
21
+ var id = function id() {
22
+ return crypto.randomUUID();
23
+ };
24
+ var createdAt = function createdAt() {
25
+ return timestamp("created_at").notNull().$defaultFn(now);
26
+ };
27
+ var updatedAt = function updatedAt() {
28
+ return timestamp("updated_at").notNull().$defaultFn(now);
29
+ };
30
+ var accessedAt = function accessedAt() {
31
+ return timestamp("accessed_at").notNull().$defaultFn(now);
32
+ };
33
+ export var basicFields = {
34
+ id: text("id").primaryKey().$defaultFn(id),
35
+ creatorId: text("creator_id"),
36
+ editorId: text("editor_id"),
37
+ accessedAt: accessedAt(),
38
+ createdAt: createdAt(),
39
+ updatedAt: updatedAt()
40
+ };
41
+
42
+ /**
43
+ * 业务侧 insert schema 需要从 drizzle-zod 生成的 schema 中排除的基础字段。
44
+ * 这些字段由后端在 createPostAction 中自动写入。
45
+ *
46
+ * 使用方式(在业务 schema 中):
47
+ * const insertFooSchema = createInsertSchema(foos)
48
+ * .omit(BASIC_INSERT_OMIT)
49
+ * .extend({ ... });
50
+ *
51
+ * 说明:上游导出为 const 而不是 helper function,是为了避免经过泛型
52
+ * wrapper 后 TS 把 drizzle-zod 推导出的深层条件 Shape 归约成 Omit,
53
+ * 从而在下游 `.extend(...)` 时丢失原有字段类型。
54
+ */
55
+ export var BASIC_INSERT_OMIT = {
56
+ id: true,
57
+ creatorId: true,
58
+ editorId: true,
59
+ accessedAt: true,
60
+ createdAt: true,
61
+ updatedAt: true
62
+ };
63
+
64
+ /**
65
+ * 业务侧 update schema 需要从 drizzle-zod 生成的 schema 中排除的基础字段。
66
+ * update 保留 id(随后用 `.required({ id: true })` 变成必填),其余由
67
+ * 后端 createPutAction 自动维护。
68
+ */
69
+ export var BASIC_UPDATE_OMIT = {
70
+ creatorId: true,
71
+ editorId: true,
72
+ accessedAt: true,
73
+ createdAt: true,
74
+ updatedAt: true
75
+ };
76
+
77
+ //============================列表查询字段============================//
78
+ export var queryListSchema = function queryListSchema(schema) {
79
+ return z.object({
80
+ current: z.string().optional().default("1"),
81
+ // 默认页码为 1
82
+ pageSize: z.string().optional().default("10"),
83
+ // 默认每页条数为 10
84
+ createdAtFrom: z.string().optional(),
85
+ // 筛选开始日期
86
+ createdAtTo: z.string().optional(),
87
+ // 筛选结束日期
88
+ orderBy: z.string().optional(),
89
+ creatorId: z.string().optional(),
90
+ orderDir: z.enum(["asc", "desc"]).optional()
91
+ }).merge(schema);
92
+ };
93
+
94
+ //============================列表返回字段============================//
95
+ export var listBodySchema = function listBodySchema(schema) {
96
+ return z.object({
97
+ total: z.number(),
98
+ data: z.array(schema)
99
+ });
100
+ };
101
+
102
+ //============================创建一个sqlite表============================//
103
+ /**
104
+ * 基于 drizzle + drizzle-zod 快速生成带基础字段(id / 创建时间等)的
105
+ * 表定义以及 select / insert / update / query / list zod schema。
106
+ */
107
+ export var createTableSchema = function createTableSchema(_ref) {
108
+ var name = _ref.name,
109
+ columns = _ref.columns,
110
+ extraConfig = _ref.extraConfig;
111
+ var mergedColumns = _objectSpread(_objectSpread({}, basicFields), columns);
112
+ var table = sqliteTable(name, mergedColumns, extraConfig);
113
+ var selectSchema = createSelectSchema(table);
114
+ var insertSchema = createInsertSchema(sqliteTable(name, columns));
115
+ var updateSchema = createUpdateSchema(sqliteTable(name, _objectSpread({
116
+ id: text("id")
117
+ }, columns))).extend({
118
+ id: z.string()
119
+ });
120
+ var querySchema = z.object({
121
+ id: z.string()
122
+ });
123
+ var queryListWithSchema = queryListSchema(z.object({}).catchall(z.unknown()));
124
+ return {
125
+ table: table,
126
+ selectSchema: selectSchema,
127
+ insertSchema: insertSchema,
128
+ updateSchema: updateSchema,
129
+ querySchema: querySchema,
130
+ queryListSchema: queryListWithSchema,
131
+ queryListSelectSchema: selectSchema
132
+ };
133
+ };
@@ -0,0 +1,16 @@
1
+ import { AnySQLiteColumn, SQLiteTable } from "drizzle-orm/sqlite-core";
2
+ import { SQL } from "drizzle-orm";
3
+ export interface BaseTable extends SQLiteTable {
4
+ id: AnySQLiteColumn;
5
+ creatorId: AnySQLiteColumn;
6
+ editorId: AnySQLiteColumn;
7
+ accessedAt: AnySQLiteColumn;
8
+ createdAt: AnySQLiteColumn;
9
+ updatedAt: AnySQLiteColumn;
10
+ }
11
+ export type GetListRelations = {
12
+ groupBy?: boolean;
13
+ select?: Record<string, unknown>;
14
+ sql?: SQL;
15
+ table?: BaseTable;
16
+ }[];
@@ -0,0 +1 @@
1
+ export {};
@@ -1,10 +1,11 @@
1
1
  import { TypedNextResponse } from "next-rest-framework";
2
2
  import { BaseTable } from "../types.js";
3
3
  export interface DeleteOperationOptions<TTable extends BaseTable> {
4
- table: TTable;
4
+ table?: TTable;
5
5
  summary?: string;
6
+ tags?: string[];
6
7
  onSuccess?: () => Promise<void>;
7
- onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
8
+ onError?(error: Error): Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
8
9
  byCreator?: boolean;
9
10
  }
10
11
  export declare const createDeleteOperation: any;
@@ -43,6 +43,7 @@ var createDeleteOperation = ({
43
43
  }) => ({
44
44
  table,
45
45
  summary,
46
+ tags,
46
47
  onSuccess,
47
48
  onError,
48
49
  byCreator = true
@@ -50,7 +51,7 @@ var createDeleteOperation = ({
50
51
  method: "DELETE",
51
52
  openApiOperation: {
52
53
  summary,
53
- tags: [(0, import_get_table_name.default)(table)]
54
+ tags: tags ?? (table ? [(0, import_get_table_name.default)(table)] : [])
54
55
  }
55
56
  }).input({
56
57
  body: import_zod.z.object({
@@ -64,14 +65,15 @@ var createDeleteOperation = ({
64
65
  const { userId } = await getSession(req) || {};
65
66
  body.creatorId = userId;
66
67
  }
67
- const data = await (0, import_actions.createDeleteAction)({ table, db })(body);
68
+ const data = table ? await (0, import_actions.createDeleteAction)({ table, db })(body) : body;
68
69
  await (onSuccess == null ? void 0 : onSuccess());
69
70
  return import_next_rest_framework.TypedNextResponse.json(data, {
70
71
  status: 200
71
72
  });
72
73
  } catch (e) {
73
- if (!(e instanceof import_errors.HttpError))
74
+ if (!(e instanceof import_errors.HttpError)) {
74
75
  console.error(e);
76
+ }
75
77
  const response = await (onError == null ? void 0 : onError(e));
76
78
  if (response) {
77
79
  return response;
@@ -6,17 +6,18 @@ export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchem
6
6
  jsonArrayFields?: string[];
7
7
  querySchema: Q;
8
8
  relations?: GetListRelations;
9
- setParams?: (req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string, unknown>>;
9
+ setParams?(req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>): Promise<Record<string, unknown>>;
10
10
  byCreator?: boolean;
11
11
  summary?: string;
12
- table: TTable;
13
- onSuccess?: <D extends T>(data: {
12
+ tags?: string[];
13
+ table?: TTable;
14
+ onSuccess?<D extends T>(data: {
14
15
  data: z.infer<D>[];
15
16
  total: number;
16
- }) => Promise<{
17
+ }): Promise<{
17
18
  data: z.infer<T>[];
18
19
  total: number;
19
20
  }>;
20
- onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
21
+ onError?(error: Error): Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
21
22
  }
22
23
  export declare const createGetListOperation: any;