@ai0x0/utils 0.0.27 → 0.0.30
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 +38 -7
- 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-config/index.js +67 -0
- package/eslint-rules/index.js +2 -2
- 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 +5 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @ai0x0/utils
|
|
2
2
|
|
|
3
|
-
AI0x0 shared utilities — backend CRUD factories for Next.js App Router + drizzle-orm,
|
|
3
|
+
AI0x0 shared utilities — backend CRUD factories for Next.js App Router + drizzle-orm, custom ESLint rules and presets.
|
|
4
4
|
|
|
5
5
|
## Backend (`src/backend/`)
|
|
6
6
|
|
|
@@ -15,20 +15,20 @@ Declarative CRUD factories on top of `next-rest-framework`, `drizzle-orm/pg-core
|
|
|
15
15
|
| `createDeleteOperation` | DELETE | Delete a record |
|
|
16
16
|
| `createTableSchema` | — | Generate pg table + 5 Zod schemas |
|
|
17
17
|
|
|
18
|
-
**Built-in conventions:** base fields (`id`, `creatorId`, `editorId`, `createdAt`, `updatedAt`, `accessedAt`), ownership checks via `byCreator`, automatic date coercion, pagination (`current`/`pageSize`/`orderBy`/`orderDir`), list filtering with `ILIKE`, `IN`, `jsonb` array matching, and relation joins.
|
|
19
|
-
|
|
20
18
|
See [SKILL.md](./SKILL.md) for detailed workflow, setup, and escape hatches.
|
|
21
19
|
|
|
22
|
-
## ESLint Rules
|
|
20
|
+
## ESLint Rules & Config
|
|
21
|
+
|
|
22
|
+
### Plugin (`eslint-rules/`)
|
|
23
23
|
|
|
24
|
-
Custom ESLint 9 flat-config rules
|
|
24
|
+
Custom ESLint 9 flat-config rules. All enabled via `configs.recommended`:
|
|
25
25
|
|
|
26
26
|
```js
|
|
27
27
|
// eslint.config.js
|
|
28
|
-
import
|
|
28
|
+
import { ai0x0 } from "@ai0x0/utils/eslint-config/index.js";
|
|
29
29
|
|
|
30
30
|
export default [
|
|
31
|
-
|
|
31
|
+
ai0x0.configs.recommended,
|
|
32
32
|
// ... other config
|
|
33
33
|
];
|
|
34
34
|
```
|
|
@@ -46,6 +46,37 @@ export default [
|
|
|
46
46
|
| `require-use-form` | Use `useForm()` for form state |
|
|
47
47
|
| `require-form-convention` | Form naming conventions |
|
|
48
48
|
|
|
49
|
+
### Shared restrictions (`eslint-config/`)
|
|
50
|
+
|
|
51
|
+
Pre-defined `no-restricted-syntax` selectors for antd + ahooks convention enforcement:
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
import {
|
|
55
|
+
ai0x0,
|
|
56
|
+
allRestrictions,
|
|
57
|
+
allRestrictionsWithNetworking,
|
|
58
|
+
} from "@ai0x0/utils/eslint-config/index.js";
|
|
59
|
+
|
|
60
|
+
export default [
|
|
61
|
+
ai0x0.configs.recommended,
|
|
62
|
+
// ... Prettier + TypeScript configs ...
|
|
63
|
+
// Backend code
|
|
64
|
+
{
|
|
65
|
+
files: ["app/(backend)/**/*.ts"],
|
|
66
|
+
rules: { "no-restricted-syntax": ["error", ...allRestrictions] },
|
|
67
|
+
},
|
|
68
|
+
// Frontend code (also restricts fetch / WebSocket)
|
|
69
|
+
{
|
|
70
|
+
files: ["app/(frontend)/**/*.ts"],
|
|
71
|
+
rules: {
|
|
72
|
+
"no-restricted-syntax": ["error", ...allRestrictionsWithNetworking],
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Restrictions cover: `TryStatement`, `as` (non-const), `useState`, `useEffect`, `useMemo`, `useCallback`, native `div/span/p/h` tags, hardcoded colors, `fetch` and `new WebSocket()`.
|
|
79
|
+
|
|
49
80
|
## Installation
|
|
50
81
|
|
|
51
82
|
```bash
|
|
@@ -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,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ai0x0/utils eslint-config — shared ESLint 9 flat config presets.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
*
|
|
6
|
+
* import { ai0x0, allRestrictions, allRestrictionsWithNetworking }
|
|
7
|
+
* from "@ai0x0/utils/eslint-config/index.js";
|
|
8
|
+
*/
|
|
9
|
+
import localPlugin from "../eslint-rules/index.js";
|
|
10
|
+
|
|
11
|
+
export { localPlugin as ai0x0 };
|
|
12
|
+
|
|
13
|
+
export const allRestrictions = [
|
|
14
|
+
{
|
|
15
|
+
selector: "TryStatement",
|
|
16
|
+
message:
|
|
17
|
+
"禁止 try/catch。后端交给 route-operation 工厂 + defaultOnError 兜底;前端交给 axios 拦截器 + useRequest onError。仅允许 JSON.parse/atob 等入口层解析容错,且必须单行 // eslint-disable-next-line no-restricted-syntax 并注明原因。",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
selector:
|
|
21
|
+
"TSAsExpression:not([typeAnnotation.type='TSTypeReference'][typeAnnotation.typeName.name='const'])",
|
|
22
|
+
message:
|
|
23
|
+
"禁止 `as` 类型断言(`as const` 除外)。优先 satisfies / 类型守卫 / openapi-generator 枚举。必须用 as 时加 // eslint-disable-next-line no-restricted-syntax 注明原因。",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
selector: "CallExpression[callee.name='useState']",
|
|
27
|
+
message:
|
|
28
|
+
"禁止 useState。业务组件请用 ahooks:useRequest / useBoolean / useSetState / useUrlState 等。",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
selector: "CallExpression[callee.name='useEffect']",
|
|
32
|
+
message:
|
|
33
|
+
"禁止 useEffect。副作用请用 ahooks:useMount / useUpdateEffect / useAsyncEffect / useInterval 等。",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
selector: "CallExpression[callee.name='useMemo']",
|
|
37
|
+
message: "禁止 useMemo。React Compiler 会自动记忆化,无需手动优化。",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
selector: "CallExpression[callee.name='useCallback']",
|
|
41
|
+
message: "禁止 useCallback。React Compiler 会自动记忆化,无需手动优化。",
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
selector: "JSXOpeningElement[name.name=/^(div|span|p|h[1-6])$/]",
|
|
45
|
+
message:
|
|
46
|
+
"禁用原生 div/span/p/h 标签。布局请用 antd Flex,文本请用 Typography.Text/Paragraph/Title。",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
selector: "Literal[value=/^(#[0-9a-fA-F]{3,8}|rgba?\\(|hsla?\\()/]",
|
|
50
|
+
message:
|
|
51
|
+
"禁止硬编码颜色字面量。请用 antd token(theme.useToken() 或 createStyles({token}) 里的 colorXxx / colorBgXxx)。",
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
export const allRestrictionsWithNetworking = [
|
|
56
|
+
...allRestrictions,
|
|
57
|
+
{
|
|
58
|
+
selector: "CallExpression[callee.name='fetch']",
|
|
59
|
+
message:
|
|
60
|
+
"禁止在前端业务代码中直接使用 fetch。请使用 axios 封装或 ahooks useRequest。",
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
selector: "NewExpression[callee.name='WebSocket']",
|
|
64
|
+
message:
|
|
65
|
+
"禁止在前端业务代码中直接使用 new WebSocket()。请使用项目封装的实时通信层。",
|
|
66
|
+
},
|
|
67
|
+
];
|
package/eslint-rules/index.js
CHANGED
|
@@ -29,9 +29,9 @@ const plugin = {
|
|
|
29
29
|
rules,
|
|
30
30
|
configs: {
|
|
31
31
|
recommended: {
|
|
32
|
-
plugins: {
|
|
32
|
+
plugins: { ai0x0: { rules } },
|
|
33
33
|
rules: Object.fromEntries(
|
|
34
|
-
Object.keys(rules).map((name) => [`
|
|
34
|
+
Object.keys(rules).map((name) => [`ai0x0/${name}`, "error"]),
|
|
35
35
|
),
|
|
36
36
|
},
|
|
37
37
|
},
|
|
@@ -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;
|
|
@@ -88,7 +88,9 @@ var createGetOperation = ({
|
|
|
88
88
|
if (onSuccess) {
|
|
89
89
|
result = await onSuccess(result);
|
|
90
90
|
}
|
|
91
|
-
return import_next_rest_framework.TypedNextResponse.json(result, {
|
|
91
|
+
return import_next_rest_framework.TypedNextResponse.json(result, {
|
|
92
|
+
status: 200
|
|
93
|
+
});
|
|
92
94
|
} catch (e) {
|
|
93
95
|
console.error(e);
|
|
94
96
|
const response = await (onError == null ? void 0 : onError(e));
|
|
@@ -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;
|
|
@@ -65,18 +65,19 @@ var createPostOperation = ({
|
|
|
65
65
|
]).handler(async (req) => {
|
|
66
66
|
try {
|
|
67
67
|
const { userId } = await getSession(req) || {};
|
|
68
|
-
const body =
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
);
|
|
68
|
+
const body = await req.json();
|
|
69
|
+
const extraBody = await (setBody == null ? void 0 : setBody(
|
|
70
|
+
req
|
|
71
|
+
)) || {};
|
|
72
|
+
const mergedBody = { ...body, ...extraBody };
|
|
74
73
|
const [raw] = await (0, import_actions.createPostAction)({ bodySchema, db, table })({
|
|
75
74
|
creatorId: userId,
|
|
76
|
-
...
|
|
75
|
+
...mergedBody
|
|
77
76
|
});
|
|
78
77
|
const data = onSuccess ? await onSuccess(raw) : raw;
|
|
79
|
-
return import_next_rest_framework.TypedNextResponse.json(data, {
|
|
78
|
+
return import_next_rest_framework.TypedNextResponse.json(data, {
|
|
79
|
+
status: 200
|
|
80
|
+
});
|
|
80
81
|
} catch (e) {
|
|
81
82
|
console.error(e);
|
|
82
83
|
const response = await (onError == null ? void 0 : onError(e));
|
|
@@ -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;
|
|
@@ -67,25 +67,20 @@ var createPutOperation = ({
|
|
|
67
67
|
]).handler(async (req) => {
|
|
68
68
|
try {
|
|
69
69
|
const { userId } = await getSession(req) || {};
|
|
70
|
-
const body =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
);
|
|
70
|
+
const body = await req.json();
|
|
71
|
+
const extraBody = await (setBody == null ? void 0 : setBody(
|
|
72
|
+
req
|
|
73
|
+
)) || {};
|
|
74
|
+
const mergedBody = { ...body, ...extraBody };
|
|
76
75
|
const raw = await (0, import_actions.createPutAction)({
|
|
77
76
|
bodySchema,
|
|
78
77
|
table,
|
|
79
78
|
db
|
|
80
|
-
})(
|
|
81
|
-
{
|
|
82
|
-
editorId: userId,
|
|
83
|
-
...body
|
|
84
|
-
},
|
|
85
|
-
{ byCreator }
|
|
86
|
-
);
|
|
79
|
+
})({ editorId: userId, ...mergedBody }, { byCreator });
|
|
87
80
|
const data = onSuccess ? await onSuccess(raw) : raw;
|
|
88
|
-
return import_next_rest_framework.TypedNextResponse.json(data, {
|
|
81
|
+
return import_next_rest_framework.TypedNextResponse.json(data, {
|
|
82
|
+
status: 200
|
|
83
|
+
});
|
|
89
84
|
} catch (e) {
|
|
90
85
|
if (!(e instanceof import_errors.HttpError))
|
|
91
86
|
console.error(e);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai0x0/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.30",
|
|
4
4
|
"description": "AI0x0 utils",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai0x0"
|
|
@@ -20,10 +20,11 @@
|
|
|
20
20
|
"module": "./es/index.js",
|
|
21
21
|
"types": "./lib/index.d.ts",
|
|
22
22
|
"files": [
|
|
23
|
-
"
|
|
24
|
-
"lib",
|
|
23
|
+
"SKILL.md",
|
|
25
24
|
"es",
|
|
26
|
-
"
|
|
25
|
+
"eslint-config",
|
|
26
|
+
"eslint-rules",
|
|
27
|
+
"lib"
|
|
27
28
|
],
|
|
28
29
|
"scripts": {
|
|
29
30
|
"build": "node scripts/build.mjs",
|