@ai0x0/utils 0.7.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/__shims__/{next-rest-framework.d.ts → ai0x0-next-rest-framework.d.ts} +1 -1
- package/es/backend/actions/get-list-data.js +1 -1
- package/es/backend/index.d.ts +1 -0
- package/es/backend/index.js +1 -0
- package/es/backend/response-headers.d.ts +16 -0
- package/es/backend/response-headers.js +79 -0
- package/es/backend/route-operation/delete-operation.d.ts +1 -1
- package/es/backend/route-operation/get-list-operation.d.ts +1 -1
- package/es/backend/route-operation/get-operation.d.ts +1 -1
- package/es/backend/route-operation/open-api-operation.d.ts +1 -1
- package/es/backend/route-operation/operation-common.d.ts +1 -1
- package/es/backend/route-operation/operation-common.js +1 -1
- package/es/backend/route-operation/post-operation.d.ts +1 -1
- package/es/backend/route-operation/put-operation.d.ts +1 -1
- package/es/backend/route-operation/read-operation-core.d.ts +3 -3
- package/es/backend/route-operation/read-operation-core.js +6 -5
- package/es/backend/route-operation/write-operation-core.d.ts +4 -4
- package/es/backend/route-operation/write-operation-core.js +33 -50
- package/es/backend/sqlite/route-operation/delete-operation.d.ts +1 -1
- package/es/backend/sqlite/route-operation/get-list-operation.d.ts +1 -1
- package/es/backend/sqlite/route-operation/get-operation.d.ts +1 -1
- package/es/backend/sqlite/route-operation/post-operation.d.ts +1 -1
- package/es/backend/sqlite/route-operation/put-operation.d.ts +1 -1
- package/lib/__shims__/{next-rest-framework.d.ts → ai0x0-next-rest-framework.d.ts} +1 -1
- package/lib/backend/actions/get-list-data.js +1 -1
- package/lib/backend/index.d.ts +1 -0
- package/lib/backend/index.js +2 -0
- package/lib/backend/response-headers.d.ts +16 -0
- package/lib/backend/response-headers.js +57 -0
- package/lib/backend/route-operation/delete-operation.d.ts +1 -1
- package/lib/backend/route-operation/get-list-operation.d.ts +1 -1
- package/lib/backend/route-operation/get-operation.d.ts +1 -1
- package/lib/backend/route-operation/open-api-operation.d.ts +1 -1
- package/lib/backend/route-operation/operation-common.d.ts +1 -1
- package/lib/backend/route-operation/operation-common.js +1 -1
- package/lib/backend/route-operation/post-operation.d.ts +1 -1
- package/lib/backend/route-operation/put-operation.d.ts +1 -1
- package/lib/backend/route-operation/read-operation-core.d.ts +3 -3
- package/lib/backend/route-operation/read-operation-core.js +10 -5
- package/lib/backend/route-operation/write-operation-core.d.ts +4 -4
- package/lib/backend/route-operation/write-operation-core.js +12 -5
- package/lib/backend/sqlite/route-operation/delete-operation.d.ts +1 -1
- package/lib/backend/sqlite/route-operation/get-list-operation.d.ts +1 -1
- package/lib/backend/sqlite/route-operation/get-operation.d.ts +1 -1
- package/lib/backend/sqlite/route-operation/post-operation.d.ts +1 -1
- package/lib/backend/sqlite/route-operation/put-operation.d.ts +1 -1
- package/package.json +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { NextRequest } from "next/server";
|
|
2
2
|
import type { ZodType } from "zod";
|
|
3
3
|
|
|
4
|
-
declare module "next-rest-framework" {
|
|
4
|
+
declare module "@ai0x0/next-rest-framework" {
|
|
5
5
|
export interface RouteOperationDefinition<M extends string = string> {
|
|
6
6
|
_method: M;
|
|
7
7
|
}
|
|
@@ -8,7 +8,7 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
|
|
|
8
8
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
9
9
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
10
10
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
11
|
-
import { rpcOperation } from "next-rest-framework";
|
|
11
|
+
import { rpcOperation } from "@ai0x0/next-rest-framework";
|
|
12
12
|
import { listBodySchema } from "../schemas/index.js";
|
|
13
13
|
import { normalizePaging } from "./paging.js";
|
|
14
14
|
export function getListData(_ref) {
|
package/es/backend/index.d.ts
CHANGED
package/es/backend/index.js
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 记一个响应头,等这次请求出结果时一起发出去。
|
|
3
|
+
*
|
|
4
|
+
* @param owner 这次请求的会话对象 —— 处理器收到的那个 session(本库把 getSession 的返回值
|
|
5
|
+
* 原样传给处理器,所以业务那边手上的就是它)。传 undefined 等于不记。
|
|
6
|
+
*/
|
|
7
|
+
export declare function setResponseHeader(owner: unknown, name: string, value: string): void;
|
|
8
|
+
/**
|
|
9
|
+
* 把这次请求攒下的头写进已经建好的那条响应。**工厂出口用**。
|
|
10
|
+
*
|
|
11
|
+
* 为什么是「建好之后再写」而不是建的时候一起传:TypedNextResponse.json 的第二个参数只收
|
|
12
|
+
* status(见 next-rest-framework 的类型),而响应对象本身的 headers 是可写的。
|
|
13
|
+
*/
|
|
14
|
+
export declare function withResponseHeaders<T extends {
|
|
15
|
+
headers: Headers;
|
|
16
|
+
}>(response: T, owner: unknown): T;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
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."); }
|
|
3
|
+
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); }
|
|
4
|
+
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; }
|
|
5
|
+
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; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
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); }
|
|
8
|
+
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; }
|
|
9
|
+
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; }
|
|
10
|
+
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; }
|
|
11
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
12
|
+
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); }
|
|
13
|
+
// =============================================================================
|
|
14
|
+
// 给这次请求的响应挂一个额外的头
|
|
15
|
+
// =============================================================================
|
|
16
|
+
// 处理器深处发生了「顺带得告诉客户端」的事,而那一层够不着响应 —— 典型是扣费:扣完之后
|
|
17
|
+
// 新余额只有那一层知道,界面上却要立刻更新;不给条路的话,客户端只能在每次请求之后再问一遍
|
|
18
|
+
// 余额,或者干脆一直显示旧数。
|
|
19
|
+
//
|
|
20
|
+
// 通道是一张 WeakMap,键是**这次请求解析出来的会话对象**(getSession 每个请求回一个新的,
|
|
21
|
+
// 见 sessionLoader)。两个「为什么不是」:
|
|
22
|
+
// · 不是 AsyncLocalStorage —— 那要求运行时开 node 兼容,而这套要能在边缘运行时里跑;
|
|
23
|
+
// · 不是 req —— 业务那一层常常只拿得到会话(扣费函数收的就是它),够不着请求对象。
|
|
24
|
+
//
|
|
25
|
+
// **取一次就没了**(takeResponseHeaders 会清掉):一个请求攒的头不该漏进下一个 —— 键虽然
|
|
26
|
+
// 每请求一个,但调用方完全可能把会话对象缓存起来复用。
|
|
27
|
+
//
|
|
28
|
+
// 键认不出、这次没人挂过头,一律当作没有。这是个可选的补丁,任何一步不对劲都不该影响那条
|
|
29
|
+
// 响应本身。
|
|
30
|
+
|
|
31
|
+
var pending = new WeakMap();
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 记一个响应头,等这次请求出结果时一起发出去。
|
|
35
|
+
*
|
|
36
|
+
* @param owner 这次请求的会话对象 —— 处理器收到的那个 session(本库把 getSession 的返回值
|
|
37
|
+
* 原样传给处理器,所以业务那边手上的就是它)。传 undefined 等于不记。
|
|
38
|
+
*/
|
|
39
|
+
export function setResponseHeader(owner, name, value) {
|
|
40
|
+
if (!isKey(owner)) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
pending.set(owner, _objectSpread(_objectSpread({}, pending.get(owner)), {}, _defineProperty({}, name, value)));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 会话对象长什么样由调用方定(TSession 是个不带约束的泛型),所以这两个口子收 unknown,
|
|
47
|
+
// 在这儿把「能不能当 WeakMap 的键」判掉 —— 让每个调用点各写一遍类型断言是把脏活外包出去。
|
|
48
|
+
function isKey(owner) {
|
|
49
|
+
return _typeof(owner) === "object" && owner !== null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** 取出并清空这次请求攒下的头。**工厂出口用**,业务不该调它。 */
|
|
53
|
+
function takeResponseHeaders(owner) {
|
|
54
|
+
if (!isKey(owner)) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
var headers = pending.get(owner);
|
|
58
|
+
if (headers) {
|
|
59
|
+
pending.delete(owner);
|
|
60
|
+
}
|
|
61
|
+
return headers;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 把这次请求攒下的头写进已经建好的那条响应。**工厂出口用**。
|
|
66
|
+
*
|
|
67
|
+
* 为什么是「建好之后再写」而不是建的时候一起传:TypedNextResponse.json 的第二个参数只收
|
|
68
|
+
* status(见 next-rest-framework 的类型),而响应对象本身的 headers 是可写的。
|
|
69
|
+
*/
|
|
70
|
+
export function withResponseHeaders(response, owner) {
|
|
71
|
+
var extra = takeResponseHeaders(owner);
|
|
72
|
+
for (var _i = 0, _Object$entries = Object.entries(extra !== null && extra !== void 0 ? extra : {}); _i < _Object$entries.length; _i++) {
|
|
73
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
74
|
+
name = _Object$entries$_i[0],
|
|
75
|
+
value = _Object$entries$_i[1];
|
|
76
|
+
response.headers.set(name, value);
|
|
77
|
+
}
|
|
78
|
+
return response;
|
|
79
|
+
}
|
|
@@ -9,4 +9,4 @@ export declare const createDeleteOperation: <TSession = DefaultSession>({ db, ge
|
|
|
9
9
|
getSession: SessionGetter<TSession>;
|
|
10
10
|
}) => <B extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>> = import("zod").ZodObject<{
|
|
11
11
|
id: import("zod").ZodString;
|
|
12
|
-
}, import("zod/v4/core").$strip>>({ table, schemas, access, openApiOperation, handler, catch: catchHandler, }: CoreDeleteOperationOptions<BaseTable, B, TSession>) => import("next-rest-framework").RouteOperationDefinition<"DELETE">;
|
|
12
|
+
}, import("zod/v4/core").$strip>>({ table, schemas, access, openApiOperation, handler, catch: catchHandler, }: CoreDeleteOperationOptions<BaseTable, B, TSession>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"DELETE">;
|
|
@@ -7,4 +7,4 @@ export type GetListOperationOptions<T extends ZodSchema, Q extends ZodSchema, TT
|
|
|
7
7
|
export declare const createGetListOperation: <TSession = DefaultSession>({ db, getSession, }: {
|
|
8
8
|
db?: NodePgDatabase<Record<string, unknown>> | undefined;
|
|
9
9
|
getSession: SessionGetter<TSession>;
|
|
10
|
-
}) => <T extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, Q extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, jsonArrayFields, setParams, handler, catch: catchHandler, }: CoreGetListOperationOptions<T, Q, BaseTable, GetListRelations, TSession>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
10
|
+
}) => <T extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, Q extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, jsonArrayFields, setParams, handler, catch: catchHandler, }: CoreGetListOperationOptions<T, Q, BaseTable, GetListRelations, TSession>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"GET">;
|
|
@@ -7,4 +7,4 @@ export type GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable
|
|
|
7
7
|
export declare const createGetOperation: <TSession = DefaultSession>({ getSession, db, }: {
|
|
8
8
|
db?: NodePgDatabase<Record<string, unknown>> | undefined;
|
|
9
9
|
getSession: SessionGetter<TSession>;
|
|
10
|
-
}) => <T extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, Q extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, setParams, jsonArrayFields, handler, catch: catchHandler, }: CoreGetOperationOptions<T, Q, BaseTable, GetListRelations, TSession>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
10
|
+
}) => <T extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, Q extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, setParams, jsonArrayFields, handler, catch: catchHandler, }: CoreGetOperationOptions<T, Q, BaseTable, GetListRelations, TSession>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"GET">;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { routeOperation } from "next-rest-framework";
|
|
1
|
+
import type { routeOperation } from "@ai0x0/next-rest-framework";
|
|
2
2
|
export type RouteOpenApiOperation = NonNullable<Parameters<typeof routeOperation>[0]["openApiOperation"]>;
|
|
3
3
|
export declare function createOpenApiOperation({ defaultTags, openApiOperation, }: {
|
|
4
4
|
defaultTags: string[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NextRequest } from "next/server";
|
|
2
|
-
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
2
|
+
import { TypedNextRequest, TypedNextResponse } from "@ai0x0/next-rest-framework";
|
|
3
3
|
import { z, ZodSchema } from "zod";
|
|
4
4
|
import { ScopeArg, ScopeValue } from "../scope.js";
|
|
5
5
|
export type JsonResponse = ReturnType<(typeof TypedNextResponse)["json"]>;
|
|
@@ -7,7 +7,7 @@ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyri
|
|
|
7
7
|
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); }
|
|
8
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
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 { TypedNextResponse } from "next-rest-framework";
|
|
10
|
+
import { TypedNextResponse } from "@ai0x0/next-rest-framework";
|
|
11
11
|
import { HttpError } from "../errors.js";
|
|
12
12
|
import { isEmptyScopeValue, NO_SCOPE } from "../scope.js";
|
|
13
13
|
|
|
@@ -7,4 +7,4 @@ export type PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTa
|
|
|
7
7
|
export declare const createPostOperation: <TSession = DefaultSession>({ getSession, db, }: {
|
|
8
8
|
db?: NodePgDatabase<Record<string, unknown>> | undefined;
|
|
9
9
|
getSession: SessionGetter<TSession>;
|
|
10
|
-
}) => <IB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, OB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, contentType, openApiOperation, parseBody, setBody, table, handler, catch: catchHandler, }: CorePostOperationOptions<IB, OB, PgTable<import("drizzle-orm/pg-core").TableConfig>, TSession>) => import("next-rest-framework").RouteOperationDefinition<"POST">;
|
|
10
|
+
}) => <IB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, OB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, contentType, openApiOperation, parseBody, setBody, table, handler, catch: catchHandler, }: CorePostOperationOptions<IB, OB, PgTable<import("drizzle-orm/pg-core").TableConfig>, TSession>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"POST">;
|
|
@@ -7,4 +7,4 @@ export type PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTab
|
|
|
7
7
|
export declare const createPutOperation: <TSession = DefaultSession>({ getSession, db, }: {
|
|
8
8
|
getSession: SessionGetter<TSession>;
|
|
9
9
|
db?: NodePgDatabase<Record<string, unknown>> | undefined;
|
|
10
|
-
}) => <IB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, OB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, openApiOperation, table, setBody, handler, catch: catchHandler, }: CorePutOperationOptions<IB, OB, PgTable<import("drizzle-orm/pg-core").TableConfig>, TSession>) => import("next-rest-framework").RouteOperationDefinition<"PUT">;
|
|
10
|
+
}) => <IB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, OB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, openApiOperation, table, setBody, handler, catch: catchHandler, }: CorePutOperationOptions<IB, OB, PgTable<import("drizzle-orm/pg-core").TableConfig>, TSession>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"PUT">;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NextRequest } from "next/server";
|
|
2
|
-
import { TypedNextRequest } from "next-rest-framework";
|
|
2
|
+
import { TypedNextRequest } from "@ai0x0/next-rest-framework";
|
|
3
3
|
import { z, ZodSchema } from "zod";
|
|
4
4
|
import { type RouteOpenApiOperation } from "./open-api-operation.js";
|
|
5
5
|
import { AccessOptions, ActionFactory, DefaultSession, GetOperationParams, RouteCatch, SessionGetter } from "./operation-common.js";
|
|
@@ -30,7 +30,7 @@ export declare function createGetOperationFactory<TTable, TRelations>({ createAc
|
|
|
30
30
|
}): <TSession = DefaultSession>({ db, getSession, }: {
|
|
31
31
|
db?: unknown;
|
|
32
32
|
getSession: SessionGetter<TSession>;
|
|
33
|
-
}) => <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, Q extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, setParams, jsonArrayFields, handler, catch: catchHandler, }: GetOperationOptions<T, Q, TTable, TRelations, TSession>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
33
|
+
}) => <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, Q extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, setParams, jsonArrayFields, handler, catch: catchHandler, }: GetOperationOptions<T, Q, TTable, TRelations, TSession>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"GET">;
|
|
34
34
|
export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable, TRelations, TSession = DefaultSession> extends Omit<GetOperationOptions<T, Q, TTable, TRelations, TSession>, "handler"> {
|
|
35
35
|
handler?: <D extends T>(_payload: {
|
|
36
36
|
params: GetOperationParams<Q>;
|
|
@@ -55,4 +55,4 @@ export declare function createGetListOperationFactory<TTable, TRelations>({ crea
|
|
|
55
55
|
}): <TSession = DefaultSession>({ db, getSession, }: {
|
|
56
56
|
db?: unknown;
|
|
57
57
|
getSession: SessionGetter<TSession>;
|
|
58
|
-
}) => <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, Q extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, jsonArrayFields, setParams, handler, catch: catchHandler, }: GetListOperationOptions<T, Q, TTable, TRelations, TSession>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
58
|
+
}) => <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, Q extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, jsonArrayFields, setParams, handler, catch: catchHandler, }: GetListOperationOptions<T, Q, TTable, TRelations, TSession>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"GET">;
|
|
@@ -7,10 +7,11 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
7
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
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
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 { routeOperation, TypedNextResponse } from "next-rest-framework";
|
|
10
|
+
import { routeOperation, TypedNextResponse } from "@ai0x0/next-rest-framework";
|
|
11
11
|
import { listBodySchema } from "../schemas/index.js";
|
|
12
12
|
import { createOpenApiOperation } from "./open-api-operation.js";
|
|
13
13
|
import { callerIdOf, getDefaultTags, getReadParams, handleOperationError } from "./operation-common.js";
|
|
14
|
+
import { withResponseHeaders } from "../response-headers.js";
|
|
14
15
|
|
|
15
16
|
// ==============================================================================
|
|
16
17
|
// GET single operation
|
|
@@ -106,9 +107,9 @@ export function createGetOperationFactory(_ref) {
|
|
|
106
107
|
case 19:
|
|
107
108
|
result = _context.sent;
|
|
108
109
|
case 20:
|
|
109
|
-
return _context.abrupt("return", TypedNextResponse.json(result, {
|
|
110
|
+
return _context.abrupt("return", withResponseHeaders(TypedNextResponse.json(result, {
|
|
110
111
|
status: 200
|
|
111
|
-
}));
|
|
112
|
+
}), session));
|
|
112
113
|
case 23:
|
|
113
114
|
_context.prev = 23;
|
|
114
115
|
_context.t1 = _context["catch"](0);
|
|
@@ -223,9 +224,9 @@ export function createGetListOperationFactory(_ref5) {
|
|
|
223
224
|
case 18:
|
|
224
225
|
result = _context2.sent;
|
|
225
226
|
case 19:
|
|
226
|
-
return _context2.abrupt("return", TypedNextResponse.json(result, {
|
|
227
|
+
return _context2.abrupt("return", withResponseHeaders(TypedNextResponse.json(result, {
|
|
227
228
|
status: 200
|
|
228
|
-
}));
|
|
229
|
+
}), session));
|
|
229
230
|
case 22:
|
|
230
231
|
_context2.prev = 22;
|
|
231
232
|
_context2.t1 = _context2["catch"](0);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NextRequest } from "next/server";
|
|
2
|
-
import { TypedNextRequest } from "next-rest-framework";
|
|
2
|
+
import { TypedNextRequest } from "@ai0x0/next-rest-framework";
|
|
3
3
|
import { z, ZodSchema } from "zod";
|
|
4
4
|
import { type RouteOpenApiOperation } from "./open-api-operation.js";
|
|
5
5
|
import { AccessOptions, ActionFactory, DefaultSession, RouteCatch, SessionGetter } from "./operation-common.js";
|
|
@@ -36,7 +36,7 @@ export declare function createPostOperationFactory<TTable>({ createAction, getTa
|
|
|
36
36
|
}): <TSession = DefaultSession>({ db, getSession, }: {
|
|
37
37
|
db?: unknown;
|
|
38
38
|
getSession: SessionGetter<TSession>;
|
|
39
|
-
}) => <IB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>({ schemas, access, contentType, openApiOperation, parseBody, setBody, table, handler, catch: catchHandler, }: PostOperationOptions<IB, OB, TTable, TSession>) => import("next-rest-framework").RouteOperationDefinition<"POST">;
|
|
39
|
+
}) => <IB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>({ schemas, access, contentType, openApiOperation, parseBody, setBody, table, handler, catch: catchHandler, }: PostOperationOptions<IB, OB, TTable, TSession>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"POST">;
|
|
40
40
|
export type PutOperationParams<IB extends ZodSchema> = z.infer<IB> & Record<string, unknown> & {
|
|
41
41
|
callerId?: string;
|
|
42
42
|
editorId?: string;
|
|
@@ -65,7 +65,7 @@ export declare function createPutOperationFactory<TTable>({ createAction, getTab
|
|
|
65
65
|
}): <TSession = DefaultSession>({ db, getSession, }: {
|
|
66
66
|
db?: unknown;
|
|
67
67
|
getSession: SessionGetter<TSession>;
|
|
68
|
-
}) => <IB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>({ schemas, access, openApiOperation, table, setBody, handler, catch: catchHandler, }: PutOperationOptions<IB, OB, TTable, TSession>) => import("next-rest-framework").RouteOperationDefinition<"PUT">;
|
|
68
|
+
}) => <IB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>({ schemas, access, openApiOperation, table, setBody, handler, catch: catchHandler, }: PutOperationOptions<IB, OB, TTable, TSession>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"PUT">;
|
|
69
69
|
export type DeleteOperationParams<B extends ZodSchema> = z.infer<B> & Record<string, unknown> & {
|
|
70
70
|
callerId?: string;
|
|
71
71
|
id: string;
|
|
@@ -96,4 +96,4 @@ export declare function createDeleteOperationFactory<TTable>({ createAction, get
|
|
|
96
96
|
getSession: SessionGetter<TSession>;
|
|
97
97
|
}) => <B extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>> = z.ZodObject<{
|
|
98
98
|
id: z.ZodString;
|
|
99
|
-
}, z.core.$strip>>({ table, schemas, access, openApiOperation, handler, catch: catchHandler, }: DeleteOperationOptions<TTable, B, TSession>) => import("next-rest-framework").RouteOperationDefinition<"DELETE">;
|
|
99
|
+
}, z.core.$strip>>({ table, schemas, access, openApiOperation, handler, catch: catchHandler, }: DeleteOperationOptions<TTable, B, TSession>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"DELETE">;
|
|
@@ -7,11 +7,12 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
7
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
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
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 { routeOperation, TypedNextResponse } from "next-rest-framework";
|
|
10
|
+
import { routeOperation, TypedNextResponse } from "@ai0x0/next-rest-framework";
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
import { createOpenApiOperation } from "./open-api-operation.js";
|
|
13
13
|
import { callerIdOf, getDefaultTags, handleOperationError, readPostBody, resolveAccess, sessionLoader } from "./operation-common.js";
|
|
14
14
|
import { NO_SCOPE } from "../scope.js";
|
|
15
|
+
import { withResponseHeaders } from "../response-headers.js";
|
|
15
16
|
|
|
16
17
|
// ==============================================================================
|
|
17
18
|
// POST create operation
|
|
@@ -153,9 +154,9 @@ export function createPostOperationFactory(_ref) {
|
|
|
153
154
|
_context.t2 = raw;
|
|
154
155
|
case 32:
|
|
155
156
|
data = _context.t2;
|
|
156
|
-
return _context.abrupt("return", TypedNextResponse.json(data, {
|
|
157
|
+
return _context.abrupt("return", withResponseHeaders(TypedNextResponse.json(data, {
|
|
157
158
|
status: 200
|
|
158
|
-
}));
|
|
159
|
+
}), session));
|
|
159
160
|
case 36:
|
|
160
161
|
_context.prev = 36;
|
|
161
162
|
_context.t3 = _context["catch"](0);
|
|
@@ -213,7 +214,7 @@ export function createPutOperationFactory(_ref5) {
|
|
|
213
214
|
status: 200
|
|
214
215
|
}]).handler( /*#__PURE__*/function () {
|
|
215
216
|
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(req) {
|
|
216
|
-
var
|
|
217
|
+
var loadSession, _yield$resolveAccess2, scope, body, extraBody, session, editorId, params, raw, data;
|
|
217
218
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
218
219
|
while (1) switch (_context2.prev = _context2.next) {
|
|
219
220
|
case 0:
|
|
@@ -246,35 +247,17 @@ export function createPutOperationFactory(_ref5) {
|
|
|
246
247
|
_context2.next = 17;
|
|
247
248
|
return loadSession();
|
|
248
249
|
case 17:
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
if (_context2.t1) {
|
|
252
|
-
_context2.next = 21;
|
|
253
|
-
break;
|
|
254
|
-
}
|
|
255
|
-
_context2.t1 = _yield$loadSession === void 0;
|
|
256
|
-
case 21:
|
|
257
|
-
if (!_context2.t1) {
|
|
258
|
-
_context2.next = 25;
|
|
259
|
-
break;
|
|
260
|
-
}
|
|
261
|
-
_context2.t3 = void 0;
|
|
262
|
-
_context2.next = 26;
|
|
263
|
-
break;
|
|
264
|
-
case 25:
|
|
265
|
-
_context2.t3 = _yield$loadSession.userId;
|
|
266
|
-
case 26:
|
|
267
|
-
editorId = _context2.t3;
|
|
268
|
-
// editorId 同样**最后**展开:它是审计字段,让请求体覆盖等于让人随便写「是谁改的」。
|
|
250
|
+
session = _context2.sent;
|
|
251
|
+
editorId = session === null || session === void 0 ? void 0 : session.userId; // editorId 同样**最后**展开:它是审计字段,让请求体覆盖等于让人随便写「是谁改的」。
|
|
269
252
|
// 理由与 POST 那边的归属戳一样,见那里的说明。
|
|
270
253
|
params = _objectSpread(_objectSpread(_objectSpread({}, body), extraBody), {}, {
|
|
271
254
|
editorId: editorId
|
|
272
255
|
});
|
|
273
256
|
if (!(table && db)) {
|
|
274
|
-
_context2.next =
|
|
257
|
+
_context2.next = 26;
|
|
275
258
|
break;
|
|
276
259
|
}
|
|
277
|
-
_context2.next =
|
|
260
|
+
_context2.next = 23;
|
|
278
261
|
return createAction({
|
|
279
262
|
bodySchema: schemas.body,
|
|
280
263
|
db: db,
|
|
@@ -282,19 +265,19 @@ export function createPutOperationFactory(_ref5) {
|
|
|
282
265
|
})(params, {
|
|
283
266
|
scope: scope
|
|
284
267
|
});
|
|
285
|
-
case
|
|
286
|
-
_context2.
|
|
287
|
-
_context2.next =
|
|
268
|
+
case 23:
|
|
269
|
+
_context2.t1 = _context2.sent;
|
|
270
|
+
_context2.next = 27;
|
|
288
271
|
break;
|
|
289
|
-
case
|
|
290
|
-
_context2.
|
|
291
|
-
case
|
|
292
|
-
raw = _context2.
|
|
272
|
+
case 26:
|
|
273
|
+
_context2.t1 = params;
|
|
274
|
+
case 27:
|
|
275
|
+
raw = _context2.t1;
|
|
293
276
|
if (!handler) {
|
|
294
|
-
_context2.next =
|
|
277
|
+
_context2.next = 34;
|
|
295
278
|
break;
|
|
296
279
|
}
|
|
297
|
-
_context2.next =
|
|
280
|
+
_context2.next = 31;
|
|
298
281
|
return handler({
|
|
299
282
|
data: raw,
|
|
300
283
|
// 同 POST:callerId 不进 createAction 那一份(它会被 .set() 原样写进 UPDATE,
|
|
@@ -304,26 +287,26 @@ export function createPutOperationFactory(_ref5) {
|
|
|
304
287
|
}),
|
|
305
288
|
req: req
|
|
306
289
|
});
|
|
307
|
-
case
|
|
308
|
-
_context2.
|
|
309
|
-
_context2.next =
|
|
290
|
+
case 31:
|
|
291
|
+
_context2.t2 = _context2.sent;
|
|
292
|
+
_context2.next = 35;
|
|
310
293
|
break;
|
|
311
|
-
case
|
|
312
|
-
_context2.
|
|
313
|
-
case
|
|
314
|
-
data = _context2.
|
|
315
|
-
return _context2.abrupt("return", TypedNextResponse.json(data, {
|
|
294
|
+
case 34:
|
|
295
|
+
_context2.t2 = raw;
|
|
296
|
+
case 35:
|
|
297
|
+
data = _context2.t2;
|
|
298
|
+
return _context2.abrupt("return", withResponseHeaders(TypedNextResponse.json(data, {
|
|
316
299
|
status: 200
|
|
317
|
-
}));
|
|
318
|
-
case
|
|
319
|
-
_context2.prev =
|
|
320
|
-
_context2.
|
|
321
|
-
return _context2.abrupt("return", handleOperationError(_context2.
|
|
322
|
-
case
|
|
300
|
+
}), session));
|
|
301
|
+
case 39:
|
|
302
|
+
_context2.prev = 39;
|
|
303
|
+
_context2.t3 = _context2["catch"](0);
|
|
304
|
+
return _context2.abrupt("return", handleOperationError(_context2.t3, catchHandler));
|
|
305
|
+
case 42:
|
|
323
306
|
case "end":
|
|
324
307
|
return _context2.stop();
|
|
325
308
|
}
|
|
326
|
-
}, _callee2, null, [[0,
|
|
309
|
+
}, _callee2, null, [[0, 39]]);
|
|
327
310
|
}));
|
|
328
311
|
return function (_x2) {
|
|
329
312
|
return _ref8.apply(this, arguments);
|
|
@@ -12,4 +12,4 @@ export declare const createDeleteOperation: ({ db, getSession, }: {
|
|
|
12
12
|
id: import("zod").ZodString;
|
|
13
13
|
}, import("zod/v4/core").$strip>>({ table, schemas, access, openApiOperation, handler, catch: catchHandler, }: CoreDeleteOperationOptions<BaseTable, B, {
|
|
14
14
|
userId?: string | undefined;
|
|
15
|
-
}>) => import("next-rest-framework").RouteOperationDefinition<"DELETE">;
|
|
15
|
+
}>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"DELETE">;
|
|
@@ -10,4 +10,4 @@ export declare const createGetListOperation: ({ db, getSession, }: {
|
|
|
10
10
|
} | undefined>;
|
|
11
11
|
}) => <T extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, Q extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, jsonArrayFields, setParams, handler, catch: catchHandler, }: CoreGetListOperationOptions<T, Q, BaseTable, GetListRelations, {
|
|
12
12
|
userId?: string | undefined;
|
|
13
|
-
}>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
13
|
+
}>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"GET">;
|
|
@@ -10,4 +10,4 @@ export declare const createGetOperation: ({ getSession, db, }: {
|
|
|
10
10
|
} | undefined>;
|
|
11
11
|
}) => <T extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, Q extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, setParams, jsonArrayFields, handler, catch: catchHandler, }: CoreGetOperationOptions<T, Q, BaseTable, GetListRelations, {
|
|
12
12
|
userId?: string | undefined;
|
|
13
|
-
}>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
13
|
+
}>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"GET">;
|
|
@@ -10,4 +10,4 @@ export declare const createPostOperation: ({ getSession, db, }: {
|
|
|
10
10
|
} | undefined>;
|
|
11
11
|
}) => <IB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, OB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, contentType, openApiOperation, parseBody, setBody, table, handler, catch: catchHandler, }: CorePostOperationOptions<IB, OB, SQLiteTable<import("drizzle-orm/sqlite-core").TableConfig>, {
|
|
12
12
|
userId?: string | undefined;
|
|
13
|
-
}>) => import("next-rest-framework").RouteOperationDefinition<"POST">;
|
|
13
|
+
}>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"POST">;
|
|
@@ -10,4 +10,4 @@ export declare const createPutOperation: ({ getSession, db, }: {
|
|
|
10
10
|
db?: unknown;
|
|
11
11
|
}) => <IB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, OB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, openApiOperation, table, setBody, handler, catch: catchHandler, }: CorePutOperationOptions<IB, OB, SQLiteTable<import("drizzle-orm/sqlite-core").TableConfig>, {
|
|
12
12
|
userId?: string | undefined;
|
|
13
|
-
}>) => import("next-rest-framework").RouteOperationDefinition<"PUT">;
|
|
13
|
+
}>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"PUT">;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { NextRequest } from "next/server";
|
|
2
2
|
import type { ZodType } from "zod";
|
|
3
3
|
|
|
4
|
-
declare module "next-rest-framework" {
|
|
4
|
+
declare module "@ai0x0/next-rest-framework" {
|
|
5
5
|
export interface RouteOperationDefinition<M extends string = string> {
|
|
6
6
|
_method: M;
|
|
7
7
|
}
|
|
@@ -22,7 +22,7 @@ __export(get_list_data_exports, {
|
|
|
22
22
|
getListData: () => getListData
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(get_list_data_exports);
|
|
25
|
-
var import_next_rest_framework = require("next-rest-framework");
|
|
25
|
+
var import_next_rest_framework = require("@ai0x0/next-rest-framework");
|
|
26
26
|
var import_schemas = require("../schemas");
|
|
27
27
|
var import_paging = require("./paging");
|
|
28
28
|
function getListData({
|
package/lib/backend/index.d.ts
CHANGED
package/lib/backend/index.js
CHANGED
|
@@ -20,6 +20,7 @@ __reExport(backend_exports, require("./actions"), module.exports);
|
|
|
20
20
|
__reExport(backend_exports, require("./route-operation"), module.exports);
|
|
21
21
|
__reExport(backend_exports, require("./schemas"), module.exports);
|
|
22
22
|
__reExport(backend_exports, require("./errors"), module.exports);
|
|
23
|
+
__reExport(backend_exports, require("./response-headers"), module.exports);
|
|
23
24
|
__reExport(backend_exports, require("./scope"), module.exports);
|
|
24
25
|
// Annotate the CommonJS export names for ESM import in node:
|
|
25
26
|
0 && (module.exports = {
|
|
@@ -27,5 +28,6 @@ __reExport(backend_exports, require("./scope"), module.exports);
|
|
|
27
28
|
...require("./route-operation"),
|
|
28
29
|
...require("./schemas"),
|
|
29
30
|
...require("./errors"),
|
|
31
|
+
...require("./response-headers"),
|
|
30
32
|
...require("./scope")
|
|
31
33
|
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 记一个响应头,等这次请求出结果时一起发出去。
|
|
3
|
+
*
|
|
4
|
+
* @param owner 这次请求的会话对象 —— 处理器收到的那个 session(本库把 getSession 的返回值
|
|
5
|
+
* 原样传给处理器,所以业务那边手上的就是它)。传 undefined 等于不记。
|
|
6
|
+
*/
|
|
7
|
+
export declare function setResponseHeader(owner: unknown, name: string, value: string): void;
|
|
8
|
+
/**
|
|
9
|
+
* 把这次请求攒下的头写进已经建好的那条响应。**工厂出口用**。
|
|
10
|
+
*
|
|
11
|
+
* 为什么是「建好之后再写」而不是建的时候一起传:TypedNextResponse.json 的第二个参数只收
|
|
12
|
+
* status(见 next-rest-framework 的类型),而响应对象本身的 headers 是可写的。
|
|
13
|
+
*/
|
|
14
|
+
export declare function withResponseHeaders<T extends {
|
|
15
|
+
headers: Headers;
|
|
16
|
+
}>(response: T, owner: unknown): T;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/backend/response-headers.ts
|
|
20
|
+
var response_headers_exports = {};
|
|
21
|
+
__export(response_headers_exports, {
|
|
22
|
+
setResponseHeader: () => setResponseHeader,
|
|
23
|
+
withResponseHeaders: () => withResponseHeaders
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(response_headers_exports);
|
|
26
|
+
var pending = /* @__PURE__ */ new WeakMap();
|
|
27
|
+
function setResponseHeader(owner, name, value) {
|
|
28
|
+
if (!isKey(owner)) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
pending.set(owner, { ...pending.get(owner), [name]: value });
|
|
32
|
+
}
|
|
33
|
+
function isKey(owner) {
|
|
34
|
+
return typeof owner === "object" && owner !== null;
|
|
35
|
+
}
|
|
36
|
+
function takeResponseHeaders(owner) {
|
|
37
|
+
if (!isKey(owner)) {
|
|
38
|
+
return void 0;
|
|
39
|
+
}
|
|
40
|
+
const headers = pending.get(owner);
|
|
41
|
+
if (headers) {
|
|
42
|
+
pending.delete(owner);
|
|
43
|
+
}
|
|
44
|
+
return headers;
|
|
45
|
+
}
|
|
46
|
+
function withResponseHeaders(response, owner) {
|
|
47
|
+
const extra = takeResponseHeaders(owner);
|
|
48
|
+
for (const [name, value] of Object.entries(extra ?? {})) {
|
|
49
|
+
response.headers.set(name, value);
|
|
50
|
+
}
|
|
51
|
+
return response;
|
|
52
|
+
}
|
|
53
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
+
0 && (module.exports = {
|
|
55
|
+
setResponseHeader,
|
|
56
|
+
withResponseHeaders
|
|
57
|
+
});
|
|
@@ -9,4 +9,4 @@ export declare const createDeleteOperation: <TSession = DefaultSession>({ db, ge
|
|
|
9
9
|
getSession: SessionGetter<TSession>;
|
|
10
10
|
}) => <B extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>> = import("zod").ZodObject<{
|
|
11
11
|
id: import("zod").ZodString;
|
|
12
|
-
}, import("zod/v4/core").$strip>>({ table, schemas, access, openApiOperation, handler, catch: catchHandler, }: CoreDeleteOperationOptions<BaseTable, B, TSession>) => import("next-rest-framework").RouteOperationDefinition<"DELETE">;
|
|
12
|
+
}, import("zod/v4/core").$strip>>({ table, schemas, access, openApiOperation, handler, catch: catchHandler, }: CoreDeleteOperationOptions<BaseTable, B, TSession>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"DELETE">;
|
|
@@ -7,4 +7,4 @@ export type GetListOperationOptions<T extends ZodSchema, Q extends ZodSchema, TT
|
|
|
7
7
|
export declare const createGetListOperation: <TSession = DefaultSession>({ db, getSession, }: {
|
|
8
8
|
db?: NodePgDatabase<Record<string, unknown>> | undefined;
|
|
9
9
|
getSession: SessionGetter<TSession>;
|
|
10
|
-
}) => <T extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, Q extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, jsonArrayFields, setParams, handler, catch: catchHandler, }: CoreGetListOperationOptions<T, Q, BaseTable, GetListRelations, TSession>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
10
|
+
}) => <T extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, Q extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, jsonArrayFields, setParams, handler, catch: catchHandler, }: CoreGetListOperationOptions<T, Q, BaseTable, GetListRelations, TSession>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"GET">;
|
|
@@ -7,4 +7,4 @@ export type GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable
|
|
|
7
7
|
export declare const createGetOperation: <TSession = DefaultSession>({ getSession, db, }: {
|
|
8
8
|
db?: NodePgDatabase<Record<string, unknown>> | undefined;
|
|
9
9
|
getSession: SessionGetter<TSession>;
|
|
10
|
-
}) => <T extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, Q extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, setParams, jsonArrayFields, handler, catch: catchHandler, }: CoreGetOperationOptions<T, Q, BaseTable, GetListRelations, TSession>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
10
|
+
}) => <T extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, Q extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, setParams, jsonArrayFields, handler, catch: catchHandler, }: CoreGetOperationOptions<T, Q, BaseTable, GetListRelations, TSession>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"GET">;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { routeOperation } from "next-rest-framework";
|
|
1
|
+
import type { routeOperation } from "@ai0x0/next-rest-framework";
|
|
2
2
|
export type RouteOpenApiOperation = NonNullable<Parameters<typeof routeOperation>[0]["openApiOperation"]>;
|
|
3
3
|
export declare function createOpenApiOperation({ defaultTags, openApiOperation, }: {
|
|
4
4
|
defaultTags: string[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NextRequest } from "next/server";
|
|
2
|
-
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
2
|
+
import { TypedNextRequest, TypedNextResponse } from "@ai0x0/next-rest-framework";
|
|
3
3
|
import { z, ZodSchema } from "zod";
|
|
4
4
|
import { ScopeArg, ScopeValue } from "../scope.js";
|
|
5
5
|
export type JsonResponse = ReturnType<(typeof TypedNextResponse)["json"]>;
|
|
@@ -28,7 +28,7 @@ __export(operation_common_exports, {
|
|
|
28
28
|
sessionLoader: () => sessionLoader
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(operation_common_exports);
|
|
31
|
-
var import_next_rest_framework = require("next-rest-framework");
|
|
31
|
+
var import_next_rest_framework = require("@ai0x0/next-rest-framework");
|
|
32
32
|
var import_errors = require("../errors");
|
|
33
33
|
var import_scope = require("../scope");
|
|
34
34
|
function callerIdOf(session) {
|
|
@@ -7,4 +7,4 @@ export type PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTa
|
|
|
7
7
|
export declare const createPostOperation: <TSession = DefaultSession>({ getSession, db, }: {
|
|
8
8
|
db?: NodePgDatabase<Record<string, unknown>> | undefined;
|
|
9
9
|
getSession: SessionGetter<TSession>;
|
|
10
|
-
}) => <IB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, OB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, contentType, openApiOperation, parseBody, setBody, table, handler, catch: catchHandler, }: CorePostOperationOptions<IB, OB, PgTable<import("drizzle-orm/pg-core").TableConfig>, TSession>) => import("next-rest-framework").RouteOperationDefinition<"POST">;
|
|
10
|
+
}) => <IB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, OB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, contentType, openApiOperation, parseBody, setBody, table, handler, catch: catchHandler, }: CorePostOperationOptions<IB, OB, PgTable<import("drizzle-orm/pg-core").TableConfig>, TSession>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"POST">;
|
|
@@ -7,4 +7,4 @@ export type PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTab
|
|
|
7
7
|
export declare const createPutOperation: <TSession = DefaultSession>({ getSession, db, }: {
|
|
8
8
|
getSession: SessionGetter<TSession>;
|
|
9
9
|
db?: NodePgDatabase<Record<string, unknown>> | undefined;
|
|
10
|
-
}) => <IB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, OB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, openApiOperation, table, setBody, handler, catch: catchHandler, }: CorePutOperationOptions<IB, OB, PgTable<import("drizzle-orm/pg-core").TableConfig>, TSession>) => import("next-rest-framework").RouteOperationDefinition<"PUT">;
|
|
10
|
+
}) => <IB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, OB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, openApiOperation, table, setBody, handler, catch: catchHandler, }: CorePutOperationOptions<IB, OB, PgTable<import("drizzle-orm/pg-core").TableConfig>, TSession>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"PUT">;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NextRequest } from "next/server";
|
|
2
|
-
import { TypedNextRequest } from "next-rest-framework";
|
|
2
|
+
import { TypedNextRequest } from "@ai0x0/next-rest-framework";
|
|
3
3
|
import { z, ZodSchema } from "zod";
|
|
4
4
|
import { type RouteOpenApiOperation } from "./open-api-operation.js";
|
|
5
5
|
import { AccessOptions, ActionFactory, DefaultSession, GetOperationParams, RouteCatch, SessionGetter } from "./operation-common.js";
|
|
@@ -30,7 +30,7 @@ export declare function createGetOperationFactory<TTable, TRelations>({ createAc
|
|
|
30
30
|
}): <TSession = DefaultSession>({ db, getSession, }: {
|
|
31
31
|
db?: unknown;
|
|
32
32
|
getSession: SessionGetter<TSession>;
|
|
33
|
-
}) => <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, Q extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, setParams, jsonArrayFields, handler, catch: catchHandler, }: GetOperationOptions<T, Q, TTable, TRelations, TSession>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
33
|
+
}) => <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, Q extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, setParams, jsonArrayFields, handler, catch: catchHandler, }: GetOperationOptions<T, Q, TTable, TRelations, TSession>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"GET">;
|
|
34
34
|
export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable, TRelations, TSession = DefaultSession> extends Omit<GetOperationOptions<T, Q, TTable, TRelations, TSession>, "handler"> {
|
|
35
35
|
handler?: <D extends T>(_payload: {
|
|
36
36
|
params: GetOperationParams<Q>;
|
|
@@ -55,4 +55,4 @@ export declare function createGetListOperationFactory<TTable, TRelations>({ crea
|
|
|
55
55
|
}): <TSession = DefaultSession>({ db, getSession, }: {
|
|
56
56
|
db?: unknown;
|
|
57
57
|
getSession: SessionGetter<TSession>;
|
|
58
|
-
}) => <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, Q extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, jsonArrayFields, setParams, handler, catch: catchHandler, }: GetListOperationOptions<T, Q, TTable, TRelations, TSession>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
58
|
+
}) => <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, Q extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, jsonArrayFields, setParams, handler, catch: catchHandler, }: GetListOperationOptions<T, Q, TTable, TRelations, TSession>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"GET">;
|
|
@@ -23,10 +23,11 @@ __export(read_operation_core_exports, {
|
|
|
23
23
|
createGetOperationFactory: () => createGetOperationFactory
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(read_operation_core_exports);
|
|
26
|
-
var import_next_rest_framework = require("next-rest-framework");
|
|
26
|
+
var import_next_rest_framework = require("@ai0x0/next-rest-framework");
|
|
27
27
|
var import_schemas = require("../schemas");
|
|
28
28
|
var import_open_api_operation = require("./open-api-operation");
|
|
29
29
|
var import_operation_common = require("./operation-common");
|
|
30
|
+
var import_response_headers = require("../response-headers");
|
|
30
31
|
function createGetOperationFactory({
|
|
31
32
|
createAction,
|
|
32
33
|
getTableName
|
|
@@ -87,7 +88,10 @@ function createGetOperationFactory({
|
|
|
87
88
|
req
|
|
88
89
|
});
|
|
89
90
|
}
|
|
90
|
-
return
|
|
91
|
+
return (0, import_response_headers.withResponseHeaders)(
|
|
92
|
+
import_next_rest_framework.TypedNextResponse.json(result, { status: 200 }),
|
|
93
|
+
session
|
|
94
|
+
);
|
|
91
95
|
} catch (error) {
|
|
92
96
|
return (0, import_operation_common.handleOperationError)(error, catchHandler);
|
|
93
97
|
}
|
|
@@ -152,9 +156,10 @@ function createGetListOperationFactory({
|
|
|
152
156
|
req
|
|
153
157
|
});
|
|
154
158
|
}
|
|
155
|
-
return
|
|
156
|
-
status: 200
|
|
157
|
-
|
|
159
|
+
return (0, import_response_headers.withResponseHeaders)(
|
|
160
|
+
import_next_rest_framework.TypedNextResponse.json(result, { status: 200 }),
|
|
161
|
+
session
|
|
162
|
+
);
|
|
158
163
|
} catch (error) {
|
|
159
164
|
return (0, import_operation_common.handleOperationError)(error, catchHandler);
|
|
160
165
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NextRequest } from "next/server";
|
|
2
|
-
import { TypedNextRequest } from "next-rest-framework";
|
|
2
|
+
import { TypedNextRequest } from "@ai0x0/next-rest-framework";
|
|
3
3
|
import { z, ZodSchema } from "zod";
|
|
4
4
|
import { type RouteOpenApiOperation } from "./open-api-operation.js";
|
|
5
5
|
import { AccessOptions, ActionFactory, DefaultSession, RouteCatch, SessionGetter } from "./operation-common.js";
|
|
@@ -36,7 +36,7 @@ export declare function createPostOperationFactory<TTable>({ createAction, getTa
|
|
|
36
36
|
}): <TSession = DefaultSession>({ db, getSession, }: {
|
|
37
37
|
db?: unknown;
|
|
38
38
|
getSession: SessionGetter<TSession>;
|
|
39
|
-
}) => <IB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>({ schemas, access, contentType, openApiOperation, parseBody, setBody, table, handler, catch: catchHandler, }: PostOperationOptions<IB, OB, TTable, TSession>) => import("next-rest-framework").RouteOperationDefinition<"POST">;
|
|
39
|
+
}) => <IB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>({ schemas, access, contentType, openApiOperation, parseBody, setBody, table, handler, catch: catchHandler, }: PostOperationOptions<IB, OB, TTable, TSession>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"POST">;
|
|
40
40
|
export type PutOperationParams<IB extends ZodSchema> = z.infer<IB> & Record<string, unknown> & {
|
|
41
41
|
callerId?: string;
|
|
42
42
|
editorId?: string;
|
|
@@ -65,7 +65,7 @@ export declare function createPutOperationFactory<TTable>({ createAction, getTab
|
|
|
65
65
|
}): <TSession = DefaultSession>({ db, getSession, }: {
|
|
66
66
|
db?: unknown;
|
|
67
67
|
getSession: SessionGetter<TSession>;
|
|
68
|
-
}) => <IB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>({ schemas, access, openApiOperation, table, setBody, handler, catch: catchHandler, }: PutOperationOptions<IB, OB, TTable, TSession>) => import("next-rest-framework").RouteOperationDefinition<"PUT">;
|
|
68
|
+
}) => <IB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>({ schemas, access, openApiOperation, table, setBody, handler, catch: catchHandler, }: PutOperationOptions<IB, OB, TTable, TSession>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"PUT">;
|
|
69
69
|
export type DeleteOperationParams<B extends ZodSchema> = z.infer<B> & Record<string, unknown> & {
|
|
70
70
|
callerId?: string;
|
|
71
71
|
id: string;
|
|
@@ -96,4 +96,4 @@ export declare function createDeleteOperationFactory<TTable>({ createAction, get
|
|
|
96
96
|
getSession: SessionGetter<TSession>;
|
|
97
97
|
}) => <B extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>> = z.ZodObject<{
|
|
98
98
|
id: z.ZodString;
|
|
99
|
-
}, z.core.$strip>>({ table, schemas, access, openApiOperation, handler, catch: catchHandler, }: DeleteOperationOptions<TTable, B, TSession>) => import("next-rest-framework").RouteOperationDefinition<"DELETE">;
|
|
99
|
+
}, z.core.$strip>>({ table, schemas, access, openApiOperation, handler, catch: catchHandler, }: DeleteOperationOptions<TTable, B, TSession>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"DELETE">;
|
|
@@ -24,11 +24,12 @@ __export(write_operation_core_exports, {
|
|
|
24
24
|
createPutOperationFactory: () => createPutOperationFactory
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(write_operation_core_exports);
|
|
27
|
-
var import_next_rest_framework = require("next-rest-framework");
|
|
27
|
+
var import_next_rest_framework = require("@ai0x0/next-rest-framework");
|
|
28
28
|
var import_zod = require("zod");
|
|
29
29
|
var import_open_api_operation = require("./open-api-operation");
|
|
30
30
|
var import_operation_common = require("./operation-common");
|
|
31
31
|
var import_scope = require("../scope");
|
|
32
|
+
var import_response_headers = require("../response-headers");
|
|
32
33
|
function createPostOperationFactory({
|
|
33
34
|
createAction,
|
|
34
35
|
getTableName
|
|
@@ -93,7 +94,10 @@ function createPostOperationFactory({
|
|
|
93
94
|
},
|
|
94
95
|
req
|
|
95
96
|
}) : raw;
|
|
96
|
-
return
|
|
97
|
+
return (0, import_response_headers.withResponseHeaders)(
|
|
98
|
+
import_next_rest_framework.TypedNextResponse.json(data, { status: 200 }),
|
|
99
|
+
session
|
|
100
|
+
);
|
|
97
101
|
} catch (error) {
|
|
98
102
|
return (0, import_operation_common.handleOperationError)(error, catchHandler);
|
|
99
103
|
}
|
|
@@ -130,7 +134,6 @@ function createPutOperationFactory({
|
|
|
130
134
|
status: 200
|
|
131
135
|
}
|
|
132
136
|
]).handler(async (req) => {
|
|
133
|
-
var _a;
|
|
134
137
|
try {
|
|
135
138
|
const loadSession = (0, import_operation_common.sessionLoader)(getSession, req);
|
|
136
139
|
const { scope } = await (0, import_operation_common.resolveAccess)({
|
|
@@ -142,7 +145,8 @@ function createPutOperationFactory({
|
|
|
142
145
|
const extraBody = await (setBody == null ? void 0 : setBody(
|
|
143
146
|
req
|
|
144
147
|
)) || {};
|
|
145
|
-
const
|
|
148
|
+
const session = await loadSession();
|
|
149
|
+
const editorId = session == null ? void 0 : session.userId;
|
|
146
150
|
const params = { ...body, ...extraBody, editorId };
|
|
147
151
|
const raw = table && db ? await createAction({
|
|
148
152
|
bodySchema: schemas.body,
|
|
@@ -159,7 +163,10 @@ function createPutOperationFactory({
|
|
|
159
163
|
},
|
|
160
164
|
req
|
|
161
165
|
}) : raw;
|
|
162
|
-
return
|
|
166
|
+
return (0, import_response_headers.withResponseHeaders)(
|
|
167
|
+
import_next_rest_framework.TypedNextResponse.json(data, { status: 200 }),
|
|
168
|
+
session
|
|
169
|
+
);
|
|
163
170
|
} catch (error) {
|
|
164
171
|
return (0, import_operation_common.handleOperationError)(error, catchHandler);
|
|
165
172
|
}
|
|
@@ -12,4 +12,4 @@ export declare const createDeleteOperation: ({ db, getSession, }: {
|
|
|
12
12
|
id: import("zod").ZodString;
|
|
13
13
|
}, import("zod/v4/core").$strip>>({ table, schemas, access, openApiOperation, handler, catch: catchHandler, }: CoreDeleteOperationOptions<BaseTable, B, {
|
|
14
14
|
userId?: string | undefined;
|
|
15
|
-
}>) => import("next-rest-framework").RouteOperationDefinition<"DELETE">;
|
|
15
|
+
}>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"DELETE">;
|
|
@@ -10,4 +10,4 @@ export declare const createGetListOperation: ({ db, getSession, }: {
|
|
|
10
10
|
} | undefined>;
|
|
11
11
|
}) => <T extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, Q extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, jsonArrayFields, setParams, handler, catch: catchHandler, }: CoreGetListOperationOptions<T, Q, BaseTable, GetListRelations, {
|
|
12
12
|
userId?: string | undefined;
|
|
13
|
-
}>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
13
|
+
}>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"GET">;
|
|
@@ -10,4 +10,4 @@ export declare const createGetOperation: ({ getSession, db, }: {
|
|
|
10
10
|
} | undefined>;
|
|
11
11
|
}) => <T extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, Q extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, setParams, jsonArrayFields, handler, catch: catchHandler, }: CoreGetOperationOptions<T, Q, BaseTable, GetListRelations, {
|
|
12
12
|
userId?: string | undefined;
|
|
13
|
-
}>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
13
|
+
}>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"GET">;
|
|
@@ -10,4 +10,4 @@ export declare const createPostOperation: ({ getSession, db, }: {
|
|
|
10
10
|
} | undefined>;
|
|
11
11
|
}) => <IB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, OB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, contentType, openApiOperation, parseBody, setBody, table, handler, catch: catchHandler, }: CorePostOperationOptions<IB, OB, SQLiteTable<import("drizzle-orm/sqlite-core").TableConfig>, {
|
|
12
12
|
userId?: string | undefined;
|
|
13
|
-
}>) => import("next-rest-framework").RouteOperationDefinition<"POST">;
|
|
13
|
+
}>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"POST">;
|
|
@@ -10,4 +10,4 @@ export declare const createPutOperation: ({ getSession, db, }: {
|
|
|
10
10
|
db?: unknown;
|
|
11
11
|
}) => <IB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, OB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, openApiOperation, table, setBody, handler, catch: catchHandler, }: CorePutOperationOptions<IB, OB, SQLiteTable<import("drizzle-orm/sqlite-core").TableConfig>, {
|
|
12
12
|
userId?: string | undefined;
|
|
13
|
-
}>) => import("next-rest-framework").RouteOperationDefinition<"PUT">;
|
|
13
|
+
}>) => import("@ai0x0/next-rest-framework").RouteOperationDefinition<"PUT">;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai0x0/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "AI0x0 utils",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai0x0"
|
|
@@ -85,6 +85,7 @@
|
|
|
85
85
|
]
|
|
86
86
|
},
|
|
87
87
|
"devDependencies": {
|
|
88
|
+
"@ai0x0/next-rest-framework": "^6.2.0",
|
|
88
89
|
"@commitlint/cli": "^20.5.0",
|
|
89
90
|
"@eslint/eslintrc": "^3.3.5",
|
|
90
91
|
"@eslint/js": "^10.0.1",
|
|
@@ -104,7 +105,6 @@
|
|
|
104
105
|
"husky": "^9.1.7",
|
|
105
106
|
"lint-staged": "^16.4.0",
|
|
106
107
|
"next": "^16.2.6",
|
|
107
|
-
"next-rest-framework": "github:mushan0x0/next-rest-framework#pkg",
|
|
108
108
|
"prettier": "^3.8.3",
|
|
109
109
|
"pretty-quick": "^4.2.2",
|
|
110
110
|
"remark-cli": "^12.0.1",
|
|
@@ -121,10 +121,10 @@
|
|
|
121
121
|
"packageManager": "pnpm@10.32.1",
|
|
122
122
|
"type": "module",
|
|
123
123
|
"peerDependencies": {
|
|
124
|
+
"@ai0x0/next-rest-framework": "*",
|
|
124
125
|
"drizzle-orm": "^0.45.2",
|
|
125
126
|
"drizzle-zod": "^0.8.3",
|
|
126
127
|
"next": "^16.0.0",
|
|
127
|
-
"next-rest-framework": "*",
|
|
128
128
|
"zod": "^4.3.6"
|
|
129
129
|
}
|
|
130
130
|
}
|