@ai0x0/utils 0.0.26 → 0.0.29
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.
- package/README.md +2 -2
- package/es/backend/route-operation/delete-operation.d.ts +1 -8
- package/es/backend/route-operation/get-list-operation.d.ts +1 -8
- package/es/backend/route-operation/get-operation.d.ts +1 -8
- package/es/backend/route-operation/post-operation.d.ts +1 -8
- package/es/backend/route-operation/post-operation.js +40 -41
- package/es/backend/route-operation/put-operation.d.ts +1 -9
- package/es/backend/route-operation/put-operation.js +40 -41
- package/eslint-rules/index.js +40 -0
- package/eslint-rules/no-antd-space.js +63 -0
- package/eslint-rules/no-consecutive-setstate.js +87 -0
- package/eslint-rules/no-hardcoded-style.js +437 -0
- package/eslint-rules/no-one-letter-vars.js +111 -0
- package/eslint-rules/no-then.js +40 -0
- package/eslint-rules/no-use-request-run.js +54 -0
- package/eslint-rules/require-form-convention.js +200 -0
- package/eslint-rules/require-pro-components.js +131 -0
- package/eslint-rules/require-section-divider.js +116 -0
- package/eslint-rules/require-use-form.js +77 -0
- package/lib/backend/route-operation/delete-operation.d.ts +1 -8
- package/lib/backend/route-operation/get-list-operation.d.ts +1 -8
- package/lib/backend/route-operation/get-operation.d.ts +1 -8
- package/lib/backend/route-operation/get-operation.js +3 -1
- package/lib/backend/route-operation/post-operation.d.ts +1 -8
- package/lib/backend/route-operation/post-operation.js +9 -8
- package/lib/backend/route-operation/put-operation.d.ts +1 -9
- package/lib/backend/route-operation/put-operation.js +9 -14
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -25,10 +25,10 @@ Custom ESLint 9 flat-config rules ported from production projects. All enabled v
|
|
|
25
25
|
|
|
26
26
|
```js
|
|
27
27
|
// eslint.config.js
|
|
28
|
-
import
|
|
28
|
+
import ai0x0Plugin from "./eslint-rules/index.js";
|
|
29
29
|
|
|
30
30
|
export default [
|
|
31
|
-
|
|
31
|
+
ai0x0Plugin.configs.recommended,
|
|
32
32
|
// ... other config
|
|
33
33
|
];
|
|
34
34
|
```
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { TypedNextResponse } from "next-rest-framework";
|
|
2
2
|
import { BaseTable } from "../types.js";
|
|
3
|
-
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
4
|
-
import { NextRequest } from "next/server";
|
|
5
3
|
export interface DeleteOperationOptions<TTable extends BaseTable> {
|
|
6
4
|
table: TTable;
|
|
7
5
|
summary?: string;
|
|
@@ -9,9 +7,4 @@ export interface DeleteOperationOptions<TTable extends BaseTable> {
|
|
|
9
7
|
onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
10
8
|
byCreator?: boolean;
|
|
11
9
|
}
|
|
12
|
-
export declare const createDeleteOperation:
|
|
13
|
-
db: NodePgDatabase<Record<string, unknown>>;
|
|
14
|
-
getSession: (req: NextRequest) => Promise<{
|
|
15
|
-
userId?: string;
|
|
16
|
-
} | undefined>;
|
|
17
|
-
}) => <TTable extends BaseTable>({ table, summary, onSuccess, onError, byCreator, }: DeleteOperationOptions<TTable>) => import("next-rest-framework").RouteOperationDefinition<"DELETE">;
|
|
10
|
+
export declare const createDeleteOperation: any;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { z, ZodSchema } from "zod";
|
|
2
|
-
import { NextRequest } from "next/server";
|
|
3
2
|
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
4
|
-
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
5
3
|
import { BaseTable, GetListRelations } from "../types.js";
|
|
6
4
|
export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> {
|
|
7
5
|
bodySchema: T;
|
|
@@ -21,9 +19,4 @@ export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchem
|
|
|
21
19
|
}>;
|
|
22
20
|
onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
23
21
|
}
|
|
24
|
-
export declare const createGetListOperation:
|
|
25
|
-
db: NodePgDatabase<Record<string, unknown>>;
|
|
26
|
-
getSession: (req: NextRequest) => Promise<{
|
|
27
|
-
userId?: string;
|
|
28
|
-
} | undefined>;
|
|
29
|
-
}) => <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, Q extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, TTable extends BaseTable>({ querySchema, bodySchema, table, summary, relations, jsonArrayFields, setParams, onSuccess, onError, byCreator, }: GetListOperationOptions<T, Q, TTable>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
22
|
+
export declare const createGetListOperation: any;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { z, ZodSchema } from "zod";
|
|
2
|
-
import { NextRequest } from "next/server";
|
|
3
2
|
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
4
|
-
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
5
3
|
import { BaseTable, GetListRelations } from "../types.js";
|
|
6
4
|
export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> {
|
|
7
5
|
bodySchema: T;
|
|
@@ -15,9 +13,4 @@ export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, T
|
|
|
15
13
|
table: TTable;
|
|
16
14
|
byCreator?: boolean;
|
|
17
15
|
}
|
|
18
|
-
export declare const createGetOperation:
|
|
19
|
-
db: NodePgDatabase<Record<string, unknown>>;
|
|
20
|
-
getSession: (req: NextRequest) => Promise<{
|
|
21
|
-
userId?: string;
|
|
22
|
-
} | undefined>;
|
|
23
|
-
}) => <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, Q extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, TTable extends BaseTable>({ querySchema, bodySchema, table, summary, relations, setParams, jsonArrayFields, onSuccess, onError, byCreator, }: GetOperationOptions<T, Q, TTable>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
16
|
+
export declare const createGetOperation: any;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { z, ZodSchema } from "zod";
|
|
2
2
|
import { PgTable } from "drizzle-orm/pg-core";
|
|
3
|
-
import { NextRequest } from "next/server";
|
|
4
3
|
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
5
|
-
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
6
4
|
export interface PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends PgTable> {
|
|
7
5
|
bodySchema: IB;
|
|
8
6
|
outputBodySchema?: IB;
|
|
@@ -12,9 +10,4 @@ export interface PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema
|
|
|
12
10
|
onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
13
11
|
table: TTable;
|
|
14
12
|
}
|
|
15
|
-
export declare const createPostOperation:
|
|
16
|
-
db: NodePgDatabase<Record<string, unknown>>;
|
|
17
|
-
getSession: (req: NextRequest) => Promise<{
|
|
18
|
-
userId?: string;
|
|
19
|
-
} | undefined>;
|
|
20
|
-
}) => <IB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, TTable extends PgTable<import("drizzle-orm/pg-core").TableConfig>>({ bodySchema, outputBodySchema, setBody, summary, table, onSuccess, onError, }: PostOperationOptions<IB, OB, TTable>) => import("next-rest-framework").RouteOperationDefinition<"POST">;
|
|
13
|
+
export declare const createPostOperation: any;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
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
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
3
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
9
4
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
5
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
11
6
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
12
7
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
13
8
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
9
|
+
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; }
|
|
10
|
+
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; }
|
|
11
|
+
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; }
|
|
12
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
13
|
+
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); }
|
|
14
14
|
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); } }
|
|
15
15
|
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); }); }; }
|
|
16
16
|
import { z } from "zod";
|
|
@@ -45,7 +45,7 @@ export var createPostOperation = function createPostOperation(_ref) {
|
|
|
45
45
|
status: 200
|
|
46
46
|
}]).handler( /*#__PURE__*/function () {
|
|
47
47
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
|
|
48
|
-
var _ref4, userId, body, _yield$createPostActi, _yield$createPostActi2, raw, _data, response;
|
|
48
|
+
var _ref4, userId, body, extraBody, mergedBody, _yield$createPostActi, _yield$createPostActi2, raw, _data, response;
|
|
49
49
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
50
50
|
while (1) switch (_context.prev = _context.next) {
|
|
51
51
|
case 0:
|
|
@@ -62,72 +62,71 @@ export var createPostOperation = function createPostOperation(_ref) {
|
|
|
62
62
|
case 6:
|
|
63
63
|
_ref4 = _context.t0;
|
|
64
64
|
userId = _ref4.userId;
|
|
65
|
-
_context.
|
|
66
|
-
_context.next = 11;
|
|
65
|
+
_context.next = 10;
|
|
67
66
|
return req.json();
|
|
68
|
-
case
|
|
69
|
-
|
|
70
|
-
_context.next =
|
|
67
|
+
case 10:
|
|
68
|
+
body = _context.sent;
|
|
69
|
+
_context.next = 13;
|
|
71
70
|
return setBody === null || setBody === void 0 ? void 0 : setBody(req);
|
|
72
|
-
case
|
|
73
|
-
_context.
|
|
74
|
-
if (_context.
|
|
75
|
-
_context.next =
|
|
71
|
+
case 13:
|
|
72
|
+
_context.t1 = _context.sent;
|
|
73
|
+
if (_context.t1) {
|
|
74
|
+
_context.next = 16;
|
|
76
75
|
break;
|
|
77
76
|
}
|
|
78
|
-
_context.
|
|
79
|
-
case
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
_context.next =
|
|
77
|
+
_context.t1 = {};
|
|
78
|
+
case 16:
|
|
79
|
+
extraBody = _context.t1;
|
|
80
|
+
mergedBody = _objectSpread(_objectSpread({}, body), extraBody);
|
|
81
|
+
_context.next = 20;
|
|
83
82
|
return createPostAction({
|
|
84
83
|
bodySchema: bodySchema,
|
|
85
84
|
db: db,
|
|
86
85
|
table: table
|
|
87
86
|
})(_objectSpread({
|
|
88
87
|
creatorId: userId
|
|
89
|
-
},
|
|
90
|
-
case
|
|
88
|
+
}, mergedBody));
|
|
89
|
+
case 20:
|
|
91
90
|
_yield$createPostActi = _context.sent;
|
|
92
91
|
_yield$createPostActi2 = _slicedToArray(_yield$createPostActi, 1);
|
|
93
92
|
raw = _yield$createPostActi2[0];
|
|
94
93
|
if (!onSuccess) {
|
|
95
|
-
_context.next =
|
|
94
|
+
_context.next = 29;
|
|
96
95
|
break;
|
|
97
96
|
}
|
|
98
|
-
_context.next =
|
|
97
|
+
_context.next = 26;
|
|
99
98
|
return onSuccess(raw);
|
|
100
|
-
case
|
|
101
|
-
_context.
|
|
102
|
-
_context.next =
|
|
99
|
+
case 26:
|
|
100
|
+
_context.t2 = _context.sent;
|
|
101
|
+
_context.next = 30;
|
|
103
102
|
break;
|
|
103
|
+
case 29:
|
|
104
|
+
_context.t2 = raw;
|
|
104
105
|
case 30:
|
|
105
|
-
|
|
106
|
-
case 31:
|
|
107
|
-
_data = _context.t5;
|
|
106
|
+
_data = _context.t2;
|
|
108
107
|
return _context.abrupt("return", TypedNextResponse.json(_data, {
|
|
109
108
|
status: 200
|
|
110
109
|
}));
|
|
111
|
-
case
|
|
112
|
-
_context.prev =
|
|
113
|
-
_context.
|
|
114
|
-
console.error(_context.
|
|
115
|
-
_context.next =
|
|
116
|
-
return onError === null || onError === void 0 ? void 0 : onError(_context.
|
|
117
|
-
case
|
|
110
|
+
case 34:
|
|
111
|
+
_context.prev = 34;
|
|
112
|
+
_context.t3 = _context["catch"](0);
|
|
113
|
+
console.error(_context.t3);
|
|
114
|
+
_context.next = 39;
|
|
115
|
+
return onError === null || onError === void 0 ? void 0 : onError(_context.t3);
|
|
116
|
+
case 39:
|
|
118
117
|
response = _context.sent;
|
|
119
118
|
if (!response) {
|
|
120
|
-
_context.next =
|
|
119
|
+
_context.next = 44;
|
|
121
120
|
break;
|
|
122
121
|
}
|
|
123
122
|
return _context.abrupt("return", response);
|
|
123
|
+
case 44:
|
|
124
|
+
throw _context.t3;
|
|
124
125
|
case 45:
|
|
125
|
-
throw _context.t6;
|
|
126
|
-
case 46:
|
|
127
126
|
case "end":
|
|
128
127
|
return _context.stop();
|
|
129
128
|
}
|
|
130
|
-
}, _callee, null, [[0,
|
|
129
|
+
}, _callee, null, [[0, 34]]);
|
|
131
130
|
}));
|
|
132
131
|
return function (_x) {
|
|
133
132
|
return _ref3.apply(this, arguments);
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { z, ZodSchema } from "zod";
|
|
2
2
|
import { PgTable } from "drizzle-orm/pg-core";
|
|
3
3
|
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
4
|
-
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
5
|
-
import { NextRequest } from "next/server";
|
|
6
|
-
import { BaseTable } from "../types.js";
|
|
7
4
|
export interface PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends PgTable> {
|
|
8
5
|
bodySchema: IB;
|
|
9
6
|
outputBodySchema?: OB;
|
|
@@ -14,9 +11,4 @@ export interface PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema,
|
|
|
14
11
|
onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
15
12
|
byCreator?: boolean;
|
|
16
13
|
}
|
|
17
|
-
export declare const createPutOperation:
|
|
18
|
-
getSession: (req: NextRequest) => Promise<{
|
|
19
|
-
userId?: string;
|
|
20
|
-
} | undefined>;
|
|
21
|
-
db: NodePgDatabase<Record<string, unknown>>;
|
|
22
|
-
}) => <IB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, TTable extends BaseTable>({ bodySchema, outputBodySchema, table, summary, setBody, onSuccess, byCreator, onError, }: PutOperationOptions<IB, OB, TTable>) => import("next-rest-framework").RouteOperationDefinition<"PUT">;
|
|
14
|
+
export declare const createPutOperation: any;
|
|
@@ -40,7 +40,7 @@ export var createPutOperation = function createPutOperation(_ref) {
|
|
|
40
40
|
contentType: "application/json"
|
|
41
41
|
}]).handler( /*#__PURE__*/function () {
|
|
42
42
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
|
|
43
|
-
var _ref4, userId, body, raw, _data, response;
|
|
43
|
+
var _ref4, userId, body, extraBody, mergedBody, raw, _data, response;
|
|
44
44
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
45
45
|
while (1) switch (_context.prev = _context.next) {
|
|
46
46
|
case 0:
|
|
@@ -57,82 +57,81 @@ export var createPutOperation = function createPutOperation(_ref) {
|
|
|
57
57
|
case 6:
|
|
58
58
|
_ref4 = _context.t0;
|
|
59
59
|
userId = _ref4.userId;
|
|
60
|
-
_context.
|
|
61
|
-
_context.next = 11;
|
|
60
|
+
_context.next = 10;
|
|
62
61
|
return req.json();
|
|
63
|
-
case
|
|
64
|
-
|
|
65
|
-
_context.next =
|
|
62
|
+
case 10:
|
|
63
|
+
body = _context.sent;
|
|
64
|
+
_context.next = 13;
|
|
66
65
|
return setBody === null || setBody === void 0 ? void 0 : setBody(req);
|
|
67
|
-
case
|
|
68
|
-
_context.
|
|
69
|
-
if (_context.
|
|
70
|
-
_context.next =
|
|
66
|
+
case 13:
|
|
67
|
+
_context.t1 = _context.sent;
|
|
68
|
+
if (_context.t1) {
|
|
69
|
+
_context.next = 16;
|
|
71
70
|
break;
|
|
72
71
|
}
|
|
73
|
-
_context.
|
|
74
|
-
case
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
_context.next =
|
|
72
|
+
_context.t1 = {};
|
|
73
|
+
case 16:
|
|
74
|
+
extraBody = _context.t1;
|
|
75
|
+
mergedBody = _objectSpread(_objectSpread({}, body), extraBody);
|
|
76
|
+
_context.next = 20;
|
|
78
77
|
return createPutAction({
|
|
79
78
|
bodySchema: bodySchema,
|
|
80
79
|
table: table,
|
|
81
80
|
db: db
|
|
82
81
|
})(_objectSpread({
|
|
83
82
|
editorId: userId
|
|
84
|
-
},
|
|
83
|
+
}, mergedBody), {
|
|
85
84
|
byCreator: byCreator
|
|
86
85
|
});
|
|
87
|
-
case
|
|
86
|
+
case 20:
|
|
88
87
|
raw = _context.sent;
|
|
89
88
|
if (!onSuccess) {
|
|
90
|
-
_context.next =
|
|
89
|
+
_context.next = 27;
|
|
91
90
|
break;
|
|
92
91
|
}
|
|
93
|
-
_context.next =
|
|
92
|
+
_context.next = 24;
|
|
94
93
|
return onSuccess(raw);
|
|
95
|
-
case
|
|
96
|
-
_context.
|
|
97
|
-
_context.next =
|
|
94
|
+
case 24:
|
|
95
|
+
_context.t2 = _context.sent;
|
|
96
|
+
_context.next = 28;
|
|
98
97
|
break;
|
|
98
|
+
case 27:
|
|
99
|
+
_context.t2 = raw;
|
|
99
100
|
case 28:
|
|
100
|
-
|
|
101
|
-
case 29:
|
|
102
|
-
_data = _context.t5;
|
|
101
|
+
_data = _context.t2;
|
|
103
102
|
return _context.abrupt("return", TypedNextResponse.json(_data, {
|
|
104
103
|
status: 200
|
|
105
104
|
}));
|
|
106
|
-
case
|
|
107
|
-
_context.prev =
|
|
108
|
-
_context.
|
|
109
|
-
if (!(_context.
|
|
110
|
-
_context.next =
|
|
111
|
-
return onError === null || onError === void 0 ? void 0 : onError(_context.
|
|
112
|
-
case
|
|
105
|
+
case 32:
|
|
106
|
+
_context.prev = 32;
|
|
107
|
+
_context.t3 = _context["catch"](0);
|
|
108
|
+
if (!(_context.t3 instanceof HttpError)) console.error(_context.t3);
|
|
109
|
+
_context.next = 37;
|
|
110
|
+
return onError === null || onError === void 0 ? void 0 : onError(_context.t3);
|
|
111
|
+
case 37:
|
|
113
112
|
response = _context.sent;
|
|
114
113
|
if (!response) {
|
|
115
|
-
_context.next =
|
|
114
|
+
_context.next = 40;
|
|
116
115
|
break;
|
|
117
116
|
}
|
|
118
117
|
return _context.abrupt("return", response);
|
|
119
|
-
case
|
|
120
|
-
if (!(_context.
|
|
121
|
-
_context.next =
|
|
118
|
+
case 40:
|
|
119
|
+
if (!(_context.t3 instanceof HttpError)) {
|
|
120
|
+
_context.next = 42;
|
|
122
121
|
break;
|
|
123
122
|
}
|
|
124
123
|
return _context.abrupt("return", TypedNextResponse.json({
|
|
125
|
-
message: _context.
|
|
124
|
+
message: _context.t3.message
|
|
126
125
|
}, {
|
|
127
|
-
status: _context.
|
|
126
|
+
status: _context.t3.status
|
|
128
127
|
}));
|
|
128
|
+
case 42:
|
|
129
|
+
throw _context.t3;
|
|
129
130
|
case 43:
|
|
130
|
-
throw _context.t6;
|
|
131
|
-
case 44:
|
|
132
131
|
case "end":
|
|
133
132
|
return _context.stop();
|
|
134
133
|
}
|
|
135
|
-
}, _callee, null, [[0,
|
|
134
|
+
}, _callee, null, [[0, 32]]);
|
|
136
135
|
}));
|
|
137
136
|
return function (_x) {
|
|
138
137
|
return _ref3.apply(this, arguments);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 本地 ESLint plugin:封装项目自定义规则。
|
|
3
|
+
*/
|
|
4
|
+
import requireSectionDivider from "./require-section-divider.js";
|
|
5
|
+
import noHardcodedStyle from "./no-hardcoded-style.js";
|
|
6
|
+
import requireUseForm from "./require-use-form.js";
|
|
7
|
+
import requireFormConvention from "./require-form-convention.js";
|
|
8
|
+
import requireProComponents from "./require-pro-components.js";
|
|
9
|
+
import noAntdSpace from "./no-antd-space.js";
|
|
10
|
+
import noUseRequestRun from "./no-use-request-run.js";
|
|
11
|
+
import noThen from "./no-then.js";
|
|
12
|
+
import noOneLetterVars from "./no-one-letter-vars.js";
|
|
13
|
+
import noConsecutiveSetState from "./no-consecutive-setstate.js";
|
|
14
|
+
|
|
15
|
+
const rules = {
|
|
16
|
+
"require-section-divider": requireSectionDivider,
|
|
17
|
+
"no-hardcoded-style": noHardcodedStyle,
|
|
18
|
+
"require-use-form": requireUseForm,
|
|
19
|
+
"require-form-convention": requireFormConvention,
|
|
20
|
+
"require-pro-components": requireProComponents,
|
|
21
|
+
"no-antd-space": noAntdSpace,
|
|
22
|
+
"no-use-request-run": noUseRequestRun,
|
|
23
|
+
"no-then": noThen,
|
|
24
|
+
"no-one-letter-vars": noOneLetterVars,
|
|
25
|
+
"no-consecutive-setstate": noConsecutiveSetState,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const plugin = {
|
|
29
|
+
rules,
|
|
30
|
+
configs: {
|
|
31
|
+
recommended: {
|
|
32
|
+
plugins: { ai0x0: { rules } },
|
|
33
|
+
rules: Object.fromEntries(
|
|
34
|
+
Object.keys(rules).map((name) => [`ai0x0/${name}`, "error"]),
|
|
35
|
+
),
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default plugin;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* no-antd-space
|
|
3
|
+
* -------------
|
|
4
|
+
* 禁止使用 antd <Space>,用 antd <Flex> 代替。
|
|
5
|
+
*
|
|
6
|
+
* 映射参考:
|
|
7
|
+
* - <Space direction="vertical"> → <Flex vertical>
|
|
8
|
+
* - <Space size={N}> → <Flex gap={N}>
|
|
9
|
+
* - <Space wrap> → <Flex wrap="wrap">
|
|
10
|
+
* - Space.Compact → 用 Flex 自行实现紧凑排列
|
|
11
|
+
*
|
|
12
|
+
* 本规则只负责检测,不负责自动修复。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** @type {import('eslint').Rule.RuleModule} */
|
|
16
|
+
const rule = {
|
|
17
|
+
meta: {
|
|
18
|
+
type: "suggestion",
|
|
19
|
+
docs: {
|
|
20
|
+
description: "禁止使用 antd <Space>,请使用 antd <Flex> 代替。",
|
|
21
|
+
},
|
|
22
|
+
schema: [],
|
|
23
|
+
messages: {
|
|
24
|
+
useFlexInstead:
|
|
25
|
+
"禁止使用 antd <Space>,请使用 antd <Flex> 代替。<Space> 的 props 到 <Flex> 的映射:direction={vertical} → vertical, wrap → wrap='wrap', size={N} → gap={N}。",
|
|
26
|
+
useFlexInsteadCompact:
|
|
27
|
+
"禁止使用 antd <Space.Compact>,请使用 <Flex> 自行实现紧凑排列。",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
create(context) {
|
|
31
|
+
const getTagName = (name) => {
|
|
32
|
+
if (name.type === "JSXIdentifier") return name.name;
|
|
33
|
+
if (
|
|
34
|
+
name.type === "JSXMemberExpression" &&
|
|
35
|
+
name.object.type === "JSXIdentifier" &&
|
|
36
|
+
name.property.type === "JSXIdentifier"
|
|
37
|
+
) {
|
|
38
|
+
return `${name.object.name}.${name.property.name}`;
|
|
39
|
+
}
|
|
40
|
+
return "";
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
JSXOpeningElement(node) {
|
|
45
|
+
const tagName = getTagName(node.name);
|
|
46
|
+
if (tagName === "Space") {
|
|
47
|
+
context.report({
|
|
48
|
+
node: node,
|
|
49
|
+
messageId: "useFlexInstead",
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (tagName === "Space.Compact") {
|
|
53
|
+
context.report({
|
|
54
|
+
node: node,
|
|
55
|
+
messageId: "useFlexInsteadCompact",
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export default rule;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* no-consecutive-setstate
|
|
3
|
+
* ------------------------
|
|
4
|
+
* 禁止在同一个块中连续调用多个 setState()。
|
|
5
|
+
* ahooks useSetState 的 setState 会合并状态,连续多次调用应该合并为一次。
|
|
6
|
+
*
|
|
7
|
+
* 误:
|
|
8
|
+
* setState({ a: 1 });
|
|
9
|
+
* setState({ b: 2 });
|
|
10
|
+
*
|
|
11
|
+
* 正:
|
|
12
|
+
* setState({ a: 1, b: 2 });
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** @type {import('eslint').Rule.RuleModule} */
|
|
16
|
+
const rule = {
|
|
17
|
+
meta: {
|
|
18
|
+
type: "suggestion",
|
|
19
|
+
docs: {
|
|
20
|
+
description: "禁止连续调用多个 setState(),应合并为一次。",
|
|
21
|
+
},
|
|
22
|
+
schema: [],
|
|
23
|
+
messages: {
|
|
24
|
+
merge:
|
|
25
|
+
"连续多个 setState() 应合并为一次:将 {{prevField}} 和 {{currField}} 合并到一个 setState 中",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
create(context) {
|
|
29
|
+
return {
|
|
30
|
+
BlockStatement(node) {
|
|
31
|
+
const body = node.body;
|
|
32
|
+
for (let i = 0; i + 1 < body.length; i++) {
|
|
33
|
+
const curr = body[i];
|
|
34
|
+
const next = body[i + 1];
|
|
35
|
+
|
|
36
|
+
if (
|
|
37
|
+
curr.type !== "ExpressionStatement" ||
|
|
38
|
+
next.type !== "ExpressionStatement"
|
|
39
|
+
)
|
|
40
|
+
continue;
|
|
41
|
+
|
|
42
|
+
const currExpr = curr.expression;
|
|
43
|
+
const nextExpr = next.expression;
|
|
44
|
+
|
|
45
|
+
const isCurrSetState =
|
|
46
|
+
currExpr.type === "CallExpression" &&
|
|
47
|
+
currExpr.callee.type === "Identifier" &&
|
|
48
|
+
currExpr.callee.name === "setState" &&
|
|
49
|
+
currExpr.arguments.length === 1 &&
|
|
50
|
+
currExpr.arguments[0].type === "ObjectExpression";
|
|
51
|
+
|
|
52
|
+
const isNextSetState =
|
|
53
|
+
nextExpr.type === "CallExpression" &&
|
|
54
|
+
nextExpr.callee.type === "Identifier" &&
|
|
55
|
+
nextExpr.callee.name === "setState" &&
|
|
56
|
+
nextExpr.arguments.length === 1 &&
|
|
57
|
+
nextExpr.arguments[0].type === "ObjectExpression";
|
|
58
|
+
|
|
59
|
+
if (!isCurrSetState || !isNextSetState) continue;
|
|
60
|
+
|
|
61
|
+
const prevField = currExpr.arguments[0];
|
|
62
|
+
const currField = nextExpr.arguments[0];
|
|
63
|
+
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
64
|
+
const prevFieldText = sourceCode
|
|
65
|
+
.getText(prevField)
|
|
66
|
+
.slice(1, -1)
|
|
67
|
+
.trim();
|
|
68
|
+
const currFieldText = sourceCode
|
|
69
|
+
.getText(currField)
|
|
70
|
+
.slice(1, -1)
|
|
71
|
+
.trim();
|
|
72
|
+
|
|
73
|
+
context.report({
|
|
74
|
+
node: next,
|
|
75
|
+
messageId: "merge",
|
|
76
|
+
data: {
|
|
77
|
+
prevField: prevFieldText,
|
|
78
|
+
currField: currFieldText,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export default rule;
|