@ai0x0/utils 0.7.1 → 0.7.2
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/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/read-operation-core.js +5 -4
- package/es/backend/route-operation/write-operation-core.js +32 -49
- 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/read-operation-core.js +9 -4
- package/lib/backend/route-operation/write-operation-core.js +11 -4
- package/package.json +1 -1
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
|
+
}
|
|
@@ -11,6 +11,7 @@ import { routeOperation, TypedNextResponse } from "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);
|
|
@@ -12,6 +12,7 @@ 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);
|
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
|
+
});
|
|
@@ -27,6 +27,7 @@ var import_next_rest_framework = require("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
|
}
|
|
@@ -29,6 +29,7 @@ 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
|
}
|