@ai0x0/utils 0.1.3 → 0.3.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/backend/route-operation/delete-operation.d.ts +5 -9
- package/es/backend/route-operation/get-list-operation.d.ts +5 -9
- package/es/backend/route-operation/get-operation.d.ts +5 -9
- package/es/backend/route-operation/index.d.ts +2 -0
- package/es/backend/route-operation/index.js +4 -1
- package/es/backend/route-operation/operation-common.d.ts +12 -0
- package/es/backend/route-operation/operation-common.js +2 -1
- package/es/backend/route-operation/post-operation.d.ts +5 -9
- package/es/backend/route-operation/put-operation.d.ts +5 -9
- package/es/backend/route-operation/write-operation-core.js +32 -27
- package/es/backend/schemas/index.js +80 -14
- package/es/backend/sqlite/schemas/index.js +80 -14
- package/lib/backend/route-operation/delete-operation.d.ts +5 -9
- package/lib/backend/route-operation/get-list-operation.d.ts +5 -9
- package/lib/backend/route-operation/get-operation.d.ts +5 -9
- package/lib/backend/route-operation/index.d.ts +2 -0
- package/lib/backend/route-operation/operation-common.d.ts +12 -0
- package/lib/backend/route-operation/operation-common.js +1 -1
- package/lib/backend/route-operation/post-operation.d.ts +5 -9
- package/lib/backend/route-operation/put-operation.d.ts +5 -9
- package/lib/backend/route-operation/write-operation-core.js +11 -4
- package/lib/backend/schemas/index.js +50 -14
- package/lib/backend/sqlite/schemas/index.js +50 -14
- package/package.json +1 -1
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
2
|
-
import { NextRequest } from "next/server";
|
|
3
2
|
import { ZodSchema } from "zod";
|
|
4
3
|
import { BaseTable } from "../types.js";
|
|
5
4
|
import { type DeleteOperationOptions as CoreDeleteOperationOptions } from "./operation-core.js";
|
|
6
|
-
|
|
7
|
-
export
|
|
5
|
+
import type { DefaultSession, SessionGetter } from "./operation-common.js";
|
|
6
|
+
export type DeleteOperationOptions<TTable extends BaseTable, B extends ZodSchema, TSession = DefaultSession> = CoreDeleteOperationOptions<TTable, B, TSession>;
|
|
7
|
+
export declare const createDeleteOperation: <TSession = DefaultSession>({ db, getSession, }: {
|
|
8
8
|
db?: NodePgDatabase<Record<string, unknown>> | undefined;
|
|
9
|
-
getSession
|
|
10
|
-
userId?: string;
|
|
11
|
-
} | undefined>;
|
|
9
|
+
getSession: SessionGetter<TSession>;
|
|
12
10
|
}) => <B extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>> = import("zod").ZodObject<{
|
|
13
11
|
id: import("zod").ZodString;
|
|
14
|
-
}, import("zod/v4/core").$strip>>({ table, schemas, access, openApiOperation, handler, catch: catchHandler, }: CoreDeleteOperationOptions<BaseTable, B,
|
|
15
|
-
userId?: string | undefined;
|
|
16
|
-
}>) => import("next-rest-framework").RouteOperationDefinition<"DELETE">;
|
|
12
|
+
}, import("zod/v4/core").$strip>>({ table, schemas, access, openApiOperation, handler, catch: catchHandler, }: CoreDeleteOperationOptions<BaseTable, B, TSession>) => import("next-rest-framework").RouteOperationDefinition<"DELETE">;
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
2
|
-
import { NextRequest } from "next/server";
|
|
3
2
|
import { ZodSchema } from "zod";
|
|
4
3
|
import { BaseTable, GetListRelations } from "../types.js";
|
|
5
4
|
import { type GetListOperationOptions as CoreGetListOperationOptions } from "./operation-core.js";
|
|
6
|
-
|
|
7
|
-
export
|
|
5
|
+
import type { DefaultSession, SessionGetter } from "./operation-common.js";
|
|
6
|
+
export type GetListOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable, TSession = DefaultSession> = CoreGetListOperationOptions<T, Q, TTable, GetListRelations, TSession>;
|
|
7
|
+
export declare const createGetListOperation: <TSession = DefaultSession>({ db, getSession, }: {
|
|
8
8
|
db?: NodePgDatabase<Record<string, unknown>> | undefined;
|
|
9
|
-
getSession
|
|
10
|
-
|
|
11
|
-
} | undefined>;
|
|
12
|
-
}) => <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, {
|
|
13
|
-
userId?: string | undefined;
|
|
14
|
-
}>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
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">;
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
2
|
-
import { NextRequest } from "next/server";
|
|
3
2
|
import { ZodSchema } from "zod";
|
|
4
3
|
import { BaseTable, GetListRelations } from "../types.js";
|
|
5
4
|
import { type GetOperationOptions as CoreGetOperationOptions } from "./operation-core.js";
|
|
6
|
-
|
|
7
|
-
export
|
|
5
|
+
import type { DefaultSession, SessionGetter } from "./operation-common.js";
|
|
6
|
+
export type GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable, TSession = DefaultSession> = CoreGetOperationOptions<T, Q, TTable, GetListRelations, TSession>;
|
|
7
|
+
export declare const createGetOperation: <TSession = DefaultSession>({ getSession, db, }: {
|
|
8
8
|
db?: NodePgDatabase<Record<string, unknown>> | undefined;
|
|
9
|
-
getSession
|
|
10
|
-
|
|
11
|
-
} | undefined>;
|
|
12
|
-
}) => <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, {
|
|
13
|
-
userId?: string | undefined;
|
|
14
|
-
}>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
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">;
|
|
@@ -4,3 +4,5 @@ export * from "./delete-operation.js";
|
|
|
4
4
|
export * from "./post-operation.js";
|
|
5
5
|
export * from "./put-operation.js";
|
|
6
6
|
export * from "./open-api-operation.js";
|
|
7
|
+
export type { AccessDenial, AccessOptions, DefaultSession, HttpMethod, SessionGetter, } from "./operation-common.js";
|
|
8
|
+
export type { ScopeCondition, ScopeValue } from "../scope.js";
|
|
@@ -3,4 +3,7 @@ export * from "./get-list-operation.js";
|
|
|
3
3
|
export * from "./delete-operation.js";
|
|
4
4
|
export * from "./post-operation.js";
|
|
5
5
|
export * from "./put-operation.js";
|
|
6
|
-
export * from "./open-api-operation.js";
|
|
6
|
+
export * from "./open-api-operation.js";
|
|
7
|
+
// 调用方要自己拼 access 预设(把 scope / can / stamp 收在一处复用)就得有这几个类型 ——
|
|
8
|
+
// 不导出的话只能在业务里重写一遍 HttpMethod 之类,两边一旦漂移就是静默的错配。
|
|
9
|
+
export {};
|
|
@@ -44,6 +44,18 @@ export interface AccessOptions<TSession = DefaultSession> {
|
|
|
44
44
|
session: TSession;
|
|
45
45
|
method: HttpMethod;
|
|
46
46
|
}) => boolean | AccessDenial | Promise<boolean | AccessDenial>;
|
|
47
|
+
/**
|
|
48
|
+
* 新建(POST)时额外要盖在行上的列。归属列由 `scope` 盖,这里管别的服务端字段 ——
|
|
49
|
+
* 最典型的就是「谁建的」:归属列一旦不是 `creatorId`(比如换成 `ownerId`),作者就没人写了,
|
|
50
|
+
* 而 `setBody` 只能返回请求体 schema 里有的字段,`creatorId` 不在里面。
|
|
51
|
+
*
|
|
52
|
+
* 与归属戳同一条不变量:**最后展开,客户端覆盖不了**。所以这里能安全地盖任何服务端字段,
|
|
53
|
+
* 不必担心请求体里塞一个同名键把它顶掉。
|
|
54
|
+
*
|
|
55
|
+
* 库不替业务猜要盖什么(哪张表有 creatorId、要不要记作者,都是业务的事),所以给的是钩子
|
|
56
|
+
* 而不是默认行为。
|
|
57
|
+
*/
|
|
58
|
+
stamp?: (session: TSession) => Record<string, unknown>;
|
|
47
59
|
}
|
|
48
60
|
/**
|
|
49
61
|
* 把会话读取包成「本次请求最多取一次」的取值器。
|
|
@@ -69,7 +69,8 @@ function _resolveAccess() {
|
|
|
69
69
|
case 0:
|
|
70
70
|
access = _ref.access, loadSession = _ref.loadSession, method = _ref.method;
|
|
71
71
|
wantsScope = Boolean(access === null || access === void 0 ? void 0 : access.scope) || ((_access$byCreator = access === null || access === void 0 ? void 0 : access.byCreator) !== null && _access$byCreator !== void 0 ? _access$byCreator : true); // 不需要就不取:关掉隔离的路由(多半是公开端点)不该为此白付一次会话读取。
|
|
72
|
-
|
|
72
|
+
// stamp 也要会话 —— 它是拿会话算「盖哪些列」的。
|
|
73
|
+
if (!(wantsScope || access !== null && access !== void 0 && access.can || access !== null && access !== void 0 && access.stamp)) {
|
|
73
74
|
_context.next = 8;
|
|
74
75
|
break;
|
|
75
76
|
}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { PgTable } from "drizzle-orm/pg-core";
|
|
2
2
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
3
|
-
import { NextRequest } from "next/server";
|
|
4
3
|
import { ZodSchema } from "zod";
|
|
5
4
|
import { type PostOperationOptions as CorePostOperationOptions } from "./operation-core.js";
|
|
6
|
-
|
|
7
|
-
export
|
|
5
|
+
import type { DefaultSession, SessionGetter } from "./operation-common.js";
|
|
6
|
+
export type PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends PgTable, TSession = DefaultSession> = CorePostOperationOptions<IB, OB, TTable, TSession>;
|
|
7
|
+
export declare const createPostOperation: <TSession = DefaultSession>({ getSession, db, }: {
|
|
8
8
|
db?: NodePgDatabase<Record<string, unknown>> | undefined;
|
|
9
|
-
getSession
|
|
10
|
-
|
|
11
|
-
} | undefined>;
|
|
12
|
-
}) => <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>, {
|
|
13
|
-
userId?: string | undefined;
|
|
14
|
-
}>) => import("next-rest-framework").RouteOperationDefinition<"POST">;
|
|
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">;
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { PgTable } from "drizzle-orm/pg-core";
|
|
2
2
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
3
|
-
import { NextRequest } from "next/server";
|
|
4
3
|
import { ZodSchema } from "zod";
|
|
5
4
|
import { type PutOperationOptions as CorePutOperationOptions } from "./operation-core.js";
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} | undefined>;
|
|
5
|
+
import type { DefaultSession, SessionGetter } from "./operation-common.js";
|
|
6
|
+
export type PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends PgTable, TSession = DefaultSession> = CorePutOperationOptions<IB, OB, TTable, TSession>;
|
|
7
|
+
export declare const createPutOperation: <TSession = DefaultSession>({ getSession, db, }: {
|
|
8
|
+
getSession: SessionGetter<TSession>;
|
|
11
9
|
db?: NodePgDatabase<Record<string, unknown>> | undefined;
|
|
12
|
-
}) => <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>,
|
|
13
|
-
userId?: string | undefined;
|
|
14
|
-
}>) => 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("next-rest-framework").RouteOperationDefinition<"PUT">;
|
|
@@ -48,13 +48,13 @@ export function createPostOperationFactory(_ref) {
|
|
|
48
48
|
contentType: contentType
|
|
49
49
|
}).outputs([{
|
|
50
50
|
body: schemas.response || z.object({
|
|
51
|
-
id: z.string()
|
|
51
|
+
id: z.string().describe("Id of the row created.")
|
|
52
52
|
}),
|
|
53
53
|
contentType: "application/json",
|
|
54
54
|
status: 200
|
|
55
55
|
}]).handler( /*#__PURE__*/function () {
|
|
56
56
|
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
|
|
57
|
-
var _yield$resolveAccess, scope, body, extraBody, params, raw, data;
|
|
57
|
+
var _access$stamp, _access$stamp2, _yield$resolveAccess, scope, session, body, extraBody, stamped, params, raw, data;
|
|
58
58
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
59
59
|
while (1) switch (_context.prev = _context.next) {
|
|
60
60
|
case 0:
|
|
@@ -68,27 +68,31 @@ export function createPostOperationFactory(_ref) {
|
|
|
68
68
|
case 3:
|
|
69
69
|
_yield$resolveAccess = _context.sent;
|
|
70
70
|
scope = _yield$resolveAccess.scope;
|
|
71
|
-
|
|
71
|
+
session = _yield$resolveAccess.session;
|
|
72
|
+
_context.next = 8;
|
|
72
73
|
return readPostBody(req, {
|
|
73
74
|
contentType: contentType,
|
|
74
75
|
parseBody: parseBody
|
|
75
76
|
});
|
|
76
|
-
case
|
|
77
|
+
case 8:
|
|
77
78
|
body = _context.sent;
|
|
78
|
-
_context.next =
|
|
79
|
+
_context.next = 11;
|
|
79
80
|
return setBody === null || setBody === void 0 ? void 0 : setBody(req);
|
|
80
|
-
case
|
|
81
|
+
case 11:
|
|
81
82
|
_context.t0 = _context.sent;
|
|
82
83
|
if (_context.t0) {
|
|
83
|
-
_context.next =
|
|
84
|
+
_context.next = 14;
|
|
84
85
|
break;
|
|
85
86
|
}
|
|
86
87
|
_context.t0 = {};
|
|
87
|
-
case
|
|
88
|
+
case 14:
|
|
88
89
|
extraBody = _context.t0;
|
|
89
90
|
// 新建的行归属这次请求的作用域。默认情形下作用域就是 creatorId = 当前用户,
|
|
90
91
|
// 换了归属列(比如 ownerId)时它自动跟着换。
|
|
91
|
-
//
|
|
92
|
+
//
|
|
93
|
+
// 别的服务端字段(最典型的是「谁建的」)由 access.stamp 盖:归属列一旦不是
|
|
94
|
+
// creatorId,作者就没人写了,而 setBody 只能返回请求体 schema 里有的字段。
|
|
95
|
+
// 归属戳排在它后面 —— 两者撞同一个键时以归属为准,那是更强的那条不变量。
|
|
92
96
|
//
|
|
93
97
|
// **归属戳必须最后展开**,这是一条安全不变量,别为了「让调用方能覆盖」而调顺序:
|
|
94
98
|
// `.input({ body })` 只校验、**不替换**请求体(next-rest-framework 交给 handler 的
|
|
@@ -96,55 +100,56 @@ export function createPostOperationFactory(_ref) {
|
|
|
96
100
|
// schema 过滤。所以只要 body 排在戳后面,客户端在 JSON 里塞一个 `ownerId` /
|
|
97
101
|
// `creatorId` 就能把行写到别人名下 —— 调用方把该列从 schema 里 omit 掉也拦不住。
|
|
98
102
|
// 见 __tests__/route-operation-scope-stamp。
|
|
99
|
-
|
|
103
|
+
stamped = session === undefined ? {} : (_access$stamp = access === null || access === void 0 || (_access$stamp2 = access.stamp) === null || _access$stamp2 === void 0 ? void 0 : _access$stamp2.call(access, session)) !== null && _access$stamp !== void 0 ? _access$stamp : {};
|
|
104
|
+
params = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, body), extraBody), stamped), scopeStamp(scope));
|
|
100
105
|
if (!(table && db)) {
|
|
101
|
-
_context.next =
|
|
106
|
+
_context.next = 23;
|
|
102
107
|
break;
|
|
103
108
|
}
|
|
104
|
-
_context.next =
|
|
109
|
+
_context.next = 20;
|
|
105
110
|
return createAction({
|
|
106
111
|
bodySchema: schemas.body,
|
|
107
112
|
db: db,
|
|
108
113
|
table: table
|
|
109
114
|
})(params);
|
|
110
|
-
case
|
|
115
|
+
case 20:
|
|
111
116
|
_context.t1 = _context.sent[0];
|
|
112
|
-
_context.next =
|
|
117
|
+
_context.next = 24;
|
|
113
118
|
break;
|
|
114
|
-
case
|
|
119
|
+
case 23:
|
|
115
120
|
_context.t1 = params;
|
|
116
|
-
case
|
|
121
|
+
case 24:
|
|
117
122
|
raw = _context.t1;
|
|
118
123
|
if (!handler) {
|
|
119
|
-
_context.next =
|
|
124
|
+
_context.next = 31;
|
|
120
125
|
break;
|
|
121
126
|
}
|
|
122
|
-
_context.next =
|
|
127
|
+
_context.next = 28;
|
|
123
128
|
return handler({
|
|
124
129
|
data: raw,
|
|
125
130
|
params: params,
|
|
126
131
|
req: req
|
|
127
132
|
});
|
|
128
|
-
case
|
|
133
|
+
case 28:
|
|
129
134
|
_context.t2 = _context.sent;
|
|
130
|
-
_context.next =
|
|
135
|
+
_context.next = 32;
|
|
131
136
|
break;
|
|
132
|
-
case
|
|
137
|
+
case 31:
|
|
133
138
|
_context.t2 = raw;
|
|
134
|
-
case
|
|
139
|
+
case 32:
|
|
135
140
|
data = _context.t2;
|
|
136
141
|
return _context.abrupt("return", TypedNextResponse.json(data, {
|
|
137
142
|
status: 200
|
|
138
143
|
}));
|
|
139
|
-
case
|
|
140
|
-
_context.prev =
|
|
144
|
+
case 36:
|
|
145
|
+
_context.prev = 36;
|
|
141
146
|
_context.t3 = _context["catch"](0);
|
|
142
147
|
return _context.abrupt("return", handleOperationError(_context.t3, catchHandler));
|
|
143
|
-
case
|
|
148
|
+
case 39:
|
|
144
149
|
case "end":
|
|
145
150
|
return _context.stop();
|
|
146
151
|
}
|
|
147
|
-
}, _callee, null, [[0,
|
|
152
|
+
}, _callee, null, [[0, 36]]);
|
|
148
153
|
}));
|
|
149
154
|
return function (_x) {
|
|
150
155
|
return _ref4.apply(this, arguments);
|
|
@@ -311,7 +316,7 @@ export function createPutOperationFactory(_ref5) {
|
|
|
311
316
|
// ==============================================================================
|
|
312
317
|
|
|
313
318
|
var defaultDeleteBodySchema = z.object({
|
|
314
|
-
id: z.string()
|
|
319
|
+
id: z.string().describe("Id of the row to delete.")
|
|
315
320
|
});
|
|
316
321
|
export function createDeleteOperationFactory(_ref9) {
|
|
317
322
|
var createAction = _ref9.createAction,
|
|
@@ -4,6 +4,12 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
4
4
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
6
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
+
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."); }
|
|
9
|
+
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); }
|
|
10
|
+
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; }
|
|
11
|
+
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; } }
|
|
12
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
13
|
import { z } from "zod";
|
|
8
14
|
import { pgTable, timestamp, uuid } from "drizzle-orm/pg-core";
|
|
9
15
|
import { createInsertSchema, createSelectSchema, createUpdateSchema } from "drizzle-zod";
|
|
@@ -72,19 +78,21 @@ export var BASIC_UPDATE_OMIT = {
|
|
|
72
78
|
// =============================================================================
|
|
73
79
|
// 列表查询字段
|
|
74
80
|
// =============================================================================
|
|
81
|
+
// 说明写成 `.describe()` 而不是行末注释:注释只有读源码的人看得到,而这七个字段会出现在每一个
|
|
82
|
+
// list 端点的 OpenAPI spec 里,再从那里流进生成的 client 与 CLI 文档。写成注释的代价是下游只能
|
|
83
|
+
// 自己再手写一份 —— 那份必然会漂,而且漂了没有任何东西会报错。
|
|
84
|
+
//
|
|
85
|
+
// 类型是 string 而不是 number:query 参数在线上只有字符串,服务端收下之后才转数字。默认值也
|
|
86
|
+
// 因此是 "1" / "10"。
|
|
75
87
|
export var queryListSchema = function queryListSchema(schema) {
|
|
76
88
|
return z.object({
|
|
77
|
-
current: z.string().optional().default("1"),
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
// 筛选结束日期
|
|
85
|
-
orderBy: z.string().optional(),
|
|
86
|
-
creatorId: z.string().optional(),
|
|
87
|
-
orderDir: z.enum(["asc", "desc"]).optional()
|
|
89
|
+
current: z.string().optional().default("1").describe("Page number, starting at 1."),
|
|
90
|
+
pageSize: z.string().optional().default("10").describe("Rows per page. Omitting it yields only 10 — pass a larger value to get the whole set."),
|
|
91
|
+
createdAtFrom: z.string().optional().describe("Keep only rows created at or after this instant (ISO 8601, e.g. 2026-08-01T00:00:00Z)."),
|
|
92
|
+
createdAtTo: z.string().optional().describe("Keep only rows created at or before this instant."),
|
|
93
|
+
orderBy: z.string().optional().describe("Column to sort by — a column name of this resource (createdAt / updatedAt and the like)."),
|
|
94
|
+
creatorId: z.string().optional().describe("Keep only rows created by this user. Useful in shared spaces to filter down to one member."),
|
|
95
|
+
orderDir: z.enum(["asc", "desc"]).optional().describe("Sort ascending or descending.")
|
|
88
96
|
}).merge(schema);
|
|
89
97
|
};
|
|
90
98
|
|
|
@@ -98,6 +106,64 @@ export var listBodySchema = function listBodySchema(schema) {
|
|
|
98
106
|
});
|
|
99
107
|
};
|
|
100
108
|
|
|
109
|
+
// =============================================================================
|
|
110
|
+
// 给基础字段挂说明
|
|
111
|
+
// =============================================================================
|
|
112
|
+
// basicFields 是 drizzle 列,而 drizzle 列没有「描述」这个概念 —— 所以说明只能挂在
|
|
113
|
+
// drizzle-zod 出来的 schema 上。值得做是因为这六个字段出现在**每一张表**的 select schema 里:
|
|
114
|
+
// 一处写完,所有 list / get 端点的返回字段表都有了(在 do-tv 上是 173 行)。
|
|
115
|
+
//
|
|
116
|
+
// 一律只挂元数据,**不换类型**:`.describe()` / `.meta()` 返回的是带元数据的克隆,校验行为一模
|
|
117
|
+
// 一样。selectSchema 是有人拿去 safeParse 的(本包自己的测试就在用 Date 校验它),换类型等于改
|
|
118
|
+
// 这个包的契约。
|
|
119
|
+
//
|
|
120
|
+
// 时间戳那三列额外用 `.meta()` 补上 JSON Schema 表示,因为不补就是错的:drizzle-zod 给的是
|
|
121
|
+
// `z.date()`,而 `Date` 在 JSON Schema 里表达不出来,于是这三个字段在 spec 里是**空对象** ——
|
|
122
|
+
// 没有 `type`,照 spec 生成的 client / CLI 只能得到 `unknown`。而线上根本不可能是 Date:响应一经
|
|
123
|
+
// JSON 序列化就是 ISO 8601 字符串。
|
|
124
|
+
//
|
|
125
|
+
// `.meta({ type, format })` 恰好只改「怎么描述」不改「怎么校验」:spec 里成为
|
|
126
|
+
// `{"type":"string","format":"date-time"}`,而 `safeParse(new Date())` 照样通过。
|
|
127
|
+
// 不用 `z.iso.datetime()` 换掉它,是因为那既改了校验(不再收 Date),又会往 JSON Schema 里塞一条
|
|
128
|
+
// 380 字节的正则 —— 乘上每张表几十 KB,而 `format` 已经把「按日期时间解析」说清楚了。
|
|
129
|
+
var BASIC_FIELD_NOTES = {
|
|
130
|
+
creatorId: "User id of the creator. Stamped by the server; clients cannot send it.",
|
|
131
|
+
editorId: "User id of whoever changed this row last. Stamped by the server; clients cannot send it.",
|
|
132
|
+
id: "Primary key of this row (uuid)."
|
|
133
|
+
};
|
|
134
|
+
var BASIC_TIMESTAMP_NOTES = {
|
|
135
|
+
accessedAt: "When this row was last accessed.",
|
|
136
|
+
createdAt: "When this row was created.",
|
|
137
|
+
updatedAt: "When this row was last modified."
|
|
138
|
+
};
|
|
139
|
+
var describeBasicFields = function describeBasicFields(schema) {
|
|
140
|
+
var overlay = {};
|
|
141
|
+
for (var _i = 0, _Object$entries = Object.entries(BASIC_FIELD_NOTES); _i < _Object$entries.length; _i++) {
|
|
142
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
143
|
+
field = _Object$entries$_i[0],
|
|
144
|
+
note = _Object$entries$_i[1];
|
|
145
|
+
var existing = schema.shape[field];
|
|
146
|
+
// 表里没这一列就跳过 —— 不给不存在的字段凭空造一个。
|
|
147
|
+
if (existing) {
|
|
148
|
+
overlay[field] = existing.describe(note);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries(BASIC_TIMESTAMP_NOTES); _i2 < _Object$entries2.length; _i2++) {
|
|
152
|
+
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
|
|
153
|
+
_field = _Object$entries2$_i[0],
|
|
154
|
+
_note = _Object$entries2$_i[1];
|
|
155
|
+
var _existing = schema.shape[_field];
|
|
156
|
+
if (_existing) {
|
|
157
|
+
overlay[_field] = _existing.meta({
|
|
158
|
+
description: _note,
|
|
159
|
+
format: "date-time",
|
|
160
|
+
type: "string"
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return schema.extend(overlay);
|
|
165
|
+
};
|
|
166
|
+
|
|
101
167
|
// =============================================================================
|
|
102
168
|
// 建表 —— 表 + 5 份 zod schema
|
|
103
169
|
// =============================================================================
|
|
@@ -112,16 +178,16 @@ export var createTableSchema = function createTableSchema(_ref) {
|
|
|
112
178
|
extraConfig = _ref.extraConfig;
|
|
113
179
|
var mergedColumns = _objectSpread(_objectSpread(_objectSpread({}, basicFields), serverColumns), columns);
|
|
114
180
|
var table = pgTable(name, mergedColumns, extraConfig);
|
|
115
|
-
var selectSchema = createSelectSchema(table);
|
|
181
|
+
var selectSchema = describeBasicFields(createSelectSchema(table));
|
|
116
182
|
// 只从 columns 推 —— basicFields 与 serverColumns 都由服务端写,不该出现在请求体里。
|
|
117
183
|
var insertSchema = createInsertSchema(pgTable(name, columns));
|
|
118
184
|
var updateSchema = createUpdateSchema(pgTable(name, _objectSpread({
|
|
119
185
|
id: uuid("id")
|
|
120
186
|
}, columns))).extend({
|
|
121
|
-
id: z.string()
|
|
187
|
+
id: z.string().describe("Id of the row to update.")
|
|
122
188
|
});
|
|
123
189
|
var querySchema = z.object({
|
|
124
|
-
id: z.string()
|
|
190
|
+
id: z.string().describe("Id of the row to fetch.")
|
|
125
191
|
});
|
|
126
192
|
var queryListWithSchema = queryListSchema(z.object({}).catchall(z.unknown()));
|
|
127
193
|
return {
|
|
@@ -4,6 +4,12 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
4
4
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
6
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
+
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."); }
|
|
9
|
+
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); }
|
|
10
|
+
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; }
|
|
11
|
+
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; } }
|
|
12
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
13
|
import { z } from "zod";
|
|
8
14
|
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
9
15
|
import { createInsertSchema, createSelectSchema, createUpdateSchema } from "drizzle-zod";
|
|
@@ -78,19 +84,21 @@ export var BASIC_UPDATE_OMIT = {
|
|
|
78
84
|
// =============================================================================
|
|
79
85
|
// 列表查询字段
|
|
80
86
|
// =============================================================================
|
|
87
|
+
// 说明写成 `.describe()` 而不是行末注释:注释只有读源码的人看得到,而这七个字段会出现在每一个
|
|
88
|
+
// list 端点的 OpenAPI spec 里,再从那里流进生成的 client 与 CLI 文档。写成注释的代价是下游只能
|
|
89
|
+
// 自己再手写一份 —— 那份必然会漂,而且漂了没有任何东西会报错。
|
|
90
|
+
//
|
|
91
|
+
// 类型是 string 而不是 number:query 参数在线上只有字符串,服务端收下之后才转数字。默认值也
|
|
92
|
+
// 因此是 "1" / "10"。
|
|
81
93
|
export var queryListSchema = function queryListSchema(schema) {
|
|
82
94
|
return z.object({
|
|
83
|
-
current: z.string().optional().default("1"),
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
// 筛选结束日期
|
|
91
|
-
orderBy: z.string().optional(),
|
|
92
|
-
creatorId: z.string().optional(),
|
|
93
|
-
orderDir: z.enum(["asc", "desc"]).optional()
|
|
95
|
+
current: z.string().optional().default("1").describe("Page number, starting at 1."),
|
|
96
|
+
pageSize: z.string().optional().default("10").describe("Rows per page. Omitting it yields only 10 — pass a larger value to get the whole set."),
|
|
97
|
+
createdAtFrom: z.string().optional().describe("Keep only rows created at or after this instant (ISO 8601, e.g. 2026-08-01T00:00:00Z)."),
|
|
98
|
+
createdAtTo: z.string().optional().describe("Keep only rows created at or before this instant."),
|
|
99
|
+
orderBy: z.string().optional().describe("Column to sort by — a column name of this resource (createdAt / updatedAt and the like)."),
|
|
100
|
+
creatorId: z.string().optional().describe("Keep only rows created by this user. Useful in shared spaces to filter down to one member."),
|
|
101
|
+
orderDir: z.enum(["asc", "desc"]).optional().describe("Sort ascending or descending.")
|
|
94
102
|
}).merge(schema);
|
|
95
103
|
};
|
|
96
104
|
|
|
@@ -104,6 +112,64 @@ export var listBodySchema = function listBodySchema(schema) {
|
|
|
104
112
|
});
|
|
105
113
|
};
|
|
106
114
|
|
|
115
|
+
// =============================================================================
|
|
116
|
+
// 给基础字段挂说明
|
|
117
|
+
// =============================================================================
|
|
118
|
+
// basicFields 是 drizzle 列,而 drizzle 列没有「描述」这个概念 —— 所以说明只能挂在
|
|
119
|
+
// drizzle-zod 出来的 schema 上。值得做是因为这六个字段出现在**每一张表**的 select schema 里:
|
|
120
|
+
// 一处写完,所有 list / get 端点的返回字段都有说明了。
|
|
121
|
+
//
|
|
122
|
+
// 一律只挂元数据,**不换类型**:`.describe()` / `.meta()` 返回的是带元数据的克隆,校验行为一模
|
|
123
|
+
// 一样。selectSchema 是有人拿去 safeParse 的(本包自己的测试就在用 Date 校验它),换类型等于改
|
|
124
|
+
// 这个包的契约。
|
|
125
|
+
//
|
|
126
|
+
// 时间戳那三列额外用 `.meta()` 补上 JSON Schema 表示,因为不补就是错的:drizzle-zod 给的是
|
|
127
|
+
// `z.date()`,而 `Date` 在 JSON Schema 里表达不出来,于是这三个字段在 spec 里是**空对象** ——
|
|
128
|
+
// 没有 `type`,照 spec 生成的 client / CLI 只能得到 `unknown`。而线上根本不可能是 Date:响应一经
|
|
129
|
+
// JSON 序列化就是 ISO 8601 字符串。
|
|
130
|
+
//
|
|
131
|
+
// `.meta({ type, format })` 恰好只改「怎么描述」不改「怎么校验」:spec 里成为
|
|
132
|
+
// `{"type":"string","format":"date-time"}`,而 `safeParse(new Date())` 照样通过。
|
|
133
|
+
// 不用 `z.iso.datetime()` 换掉它,是因为那既改了校验(不再收 Date),又会往 JSON Schema 里塞一条
|
|
134
|
+
// 380 字节的正则 —— 乘上每张表几十 KB,而 `format` 已经把「按日期时间解析」说清楚了。
|
|
135
|
+
var BASIC_FIELD_NOTES = {
|
|
136
|
+
creatorId: "User id of the creator. Stamped by the server; clients cannot send it.",
|
|
137
|
+
editorId: "User id of whoever changed this row last. Stamped by the server; clients cannot send it.",
|
|
138
|
+
id: "Primary key of this row (uuid)."
|
|
139
|
+
};
|
|
140
|
+
var BASIC_TIMESTAMP_NOTES = {
|
|
141
|
+
accessedAt: "When this row was last accessed.",
|
|
142
|
+
createdAt: "When this row was created.",
|
|
143
|
+
updatedAt: "When this row was last modified."
|
|
144
|
+
};
|
|
145
|
+
var describeBasicFields = function describeBasicFields(schema) {
|
|
146
|
+
var overlay = {};
|
|
147
|
+
for (var _i = 0, _Object$entries = Object.entries(BASIC_FIELD_NOTES); _i < _Object$entries.length; _i++) {
|
|
148
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
149
|
+
field = _Object$entries$_i[0],
|
|
150
|
+
note = _Object$entries$_i[1];
|
|
151
|
+
var existing = schema.shape[field];
|
|
152
|
+
// 表里没这一列就跳过 —— 不给不存在的字段凭空造一个。
|
|
153
|
+
if (existing) {
|
|
154
|
+
overlay[field] = existing.describe(note);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries(BASIC_TIMESTAMP_NOTES); _i2 < _Object$entries2.length; _i2++) {
|
|
158
|
+
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
|
|
159
|
+
_field = _Object$entries2$_i[0],
|
|
160
|
+
_note = _Object$entries2$_i[1];
|
|
161
|
+
var _existing = schema.shape[_field];
|
|
162
|
+
if (_existing) {
|
|
163
|
+
overlay[_field] = _existing.meta({
|
|
164
|
+
description: _note,
|
|
165
|
+
format: "date-time",
|
|
166
|
+
type: "string"
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return schema.extend(overlay);
|
|
171
|
+
};
|
|
172
|
+
|
|
107
173
|
// =============================================================================
|
|
108
174
|
// 建表 —— 表 + 5 份 zod schema
|
|
109
175
|
// =============================================================================
|
|
@@ -118,16 +184,16 @@ export var createTableSchema = function createTableSchema(_ref) {
|
|
|
118
184
|
extraConfig = _ref.extraConfig;
|
|
119
185
|
var mergedColumns = _objectSpread(_objectSpread(_objectSpread({}, basicFields), serverColumns), columns);
|
|
120
186
|
var table = sqliteTable(name, mergedColumns, extraConfig);
|
|
121
|
-
var selectSchema = createSelectSchema(table);
|
|
187
|
+
var selectSchema = describeBasicFields(createSelectSchema(table));
|
|
122
188
|
// 只从 columns 推 —— basicFields 与 serverColumns 都由服务端写,不该出现在请求体里。
|
|
123
189
|
var insertSchema = createInsertSchema(sqliteTable(name, columns));
|
|
124
190
|
var updateSchema = createUpdateSchema(sqliteTable(name, _objectSpread({
|
|
125
191
|
id: text("id")
|
|
126
192
|
}, columns))).extend({
|
|
127
|
-
id: z.string()
|
|
193
|
+
id: z.string().describe("Id of the row to update.")
|
|
128
194
|
});
|
|
129
195
|
var querySchema = z.object({
|
|
130
|
-
id: z.string()
|
|
196
|
+
id: z.string().describe("Id of the row to fetch.")
|
|
131
197
|
});
|
|
132
198
|
var queryListWithSchema = queryListSchema(z.object({}).catchall(z.unknown()));
|
|
133
199
|
return {
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
2
|
-
import { NextRequest } from "next/server";
|
|
3
2
|
import { ZodSchema } from "zod";
|
|
4
3
|
import { BaseTable } from "../types.js";
|
|
5
4
|
import { type DeleteOperationOptions as CoreDeleteOperationOptions } from "./operation-core.js";
|
|
6
|
-
|
|
7
|
-
export
|
|
5
|
+
import type { DefaultSession, SessionGetter } from "./operation-common.js";
|
|
6
|
+
export type DeleteOperationOptions<TTable extends BaseTable, B extends ZodSchema, TSession = DefaultSession> = CoreDeleteOperationOptions<TTable, B, TSession>;
|
|
7
|
+
export declare const createDeleteOperation: <TSession = DefaultSession>({ db, getSession, }: {
|
|
8
8
|
db?: NodePgDatabase<Record<string, unknown>> | undefined;
|
|
9
|
-
getSession
|
|
10
|
-
userId?: string;
|
|
11
|
-
} | undefined>;
|
|
9
|
+
getSession: SessionGetter<TSession>;
|
|
12
10
|
}) => <B extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>> = import("zod").ZodObject<{
|
|
13
11
|
id: import("zod").ZodString;
|
|
14
|
-
}, import("zod/v4/core").$strip>>({ table, schemas, access, openApiOperation, handler, catch: catchHandler, }: CoreDeleteOperationOptions<BaseTable, B,
|
|
15
|
-
userId?: string | undefined;
|
|
16
|
-
}>) => import("next-rest-framework").RouteOperationDefinition<"DELETE">;
|
|
12
|
+
}, import("zod/v4/core").$strip>>({ table, schemas, access, openApiOperation, handler, catch: catchHandler, }: CoreDeleteOperationOptions<BaseTable, B, TSession>) => import("next-rest-framework").RouteOperationDefinition<"DELETE">;
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
2
|
-
import { NextRequest } from "next/server";
|
|
3
2
|
import { ZodSchema } from "zod";
|
|
4
3
|
import { BaseTable, GetListRelations } from "../types.js";
|
|
5
4
|
import { type GetListOperationOptions as CoreGetListOperationOptions } from "./operation-core.js";
|
|
6
|
-
|
|
7
|
-
export
|
|
5
|
+
import type { DefaultSession, SessionGetter } from "./operation-common.js";
|
|
6
|
+
export type GetListOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable, TSession = DefaultSession> = CoreGetListOperationOptions<T, Q, TTable, GetListRelations, TSession>;
|
|
7
|
+
export declare const createGetListOperation: <TSession = DefaultSession>({ db, getSession, }: {
|
|
8
8
|
db?: NodePgDatabase<Record<string, unknown>> | undefined;
|
|
9
|
-
getSession
|
|
10
|
-
|
|
11
|
-
} | undefined>;
|
|
12
|
-
}) => <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, {
|
|
13
|
-
userId?: string | undefined;
|
|
14
|
-
}>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
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">;
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
2
|
-
import { NextRequest } from "next/server";
|
|
3
2
|
import { ZodSchema } from "zod";
|
|
4
3
|
import { BaseTable, GetListRelations } from "../types.js";
|
|
5
4
|
import { type GetOperationOptions as CoreGetOperationOptions } from "./operation-core.js";
|
|
6
|
-
|
|
7
|
-
export
|
|
5
|
+
import type { DefaultSession, SessionGetter } from "./operation-common.js";
|
|
6
|
+
export type GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable, TSession = DefaultSession> = CoreGetOperationOptions<T, Q, TTable, GetListRelations, TSession>;
|
|
7
|
+
export declare const createGetOperation: <TSession = DefaultSession>({ getSession, db, }: {
|
|
8
8
|
db?: NodePgDatabase<Record<string, unknown>> | undefined;
|
|
9
|
-
getSession
|
|
10
|
-
|
|
11
|
-
} | undefined>;
|
|
12
|
-
}) => <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, {
|
|
13
|
-
userId?: string | undefined;
|
|
14
|
-
}>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
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">;
|
|
@@ -4,3 +4,5 @@ export * from "./delete-operation.js";
|
|
|
4
4
|
export * from "./post-operation.js";
|
|
5
5
|
export * from "./put-operation.js";
|
|
6
6
|
export * from "./open-api-operation.js";
|
|
7
|
+
export type { AccessDenial, AccessOptions, DefaultSession, HttpMethod, SessionGetter, } from "./operation-common.js";
|
|
8
|
+
export type { ScopeCondition, ScopeValue } from "../scope.js";
|
|
@@ -44,6 +44,18 @@ export interface AccessOptions<TSession = DefaultSession> {
|
|
|
44
44
|
session: TSession;
|
|
45
45
|
method: HttpMethod;
|
|
46
46
|
}) => boolean | AccessDenial | Promise<boolean | AccessDenial>;
|
|
47
|
+
/**
|
|
48
|
+
* 新建(POST)时额外要盖在行上的列。归属列由 `scope` 盖,这里管别的服务端字段 ——
|
|
49
|
+
* 最典型的就是「谁建的」:归属列一旦不是 `creatorId`(比如换成 `ownerId`),作者就没人写了,
|
|
50
|
+
* 而 `setBody` 只能返回请求体 schema 里有的字段,`creatorId` 不在里面。
|
|
51
|
+
*
|
|
52
|
+
* 与归属戳同一条不变量:**最后展开,客户端覆盖不了**。所以这里能安全地盖任何服务端字段,
|
|
53
|
+
* 不必担心请求体里塞一个同名键把它顶掉。
|
|
54
|
+
*
|
|
55
|
+
* 库不替业务猜要盖什么(哪张表有 creatorId、要不要记作者,都是业务的事),所以给的是钩子
|
|
56
|
+
* 而不是默认行为。
|
|
57
|
+
*/
|
|
58
|
+
stamp?: (session: TSession) => Record<string, unknown>;
|
|
47
59
|
}
|
|
48
60
|
/**
|
|
49
61
|
* 把会话读取包成「本次请求最多取一次」的取值器。
|
|
@@ -42,7 +42,7 @@ async function resolveAccess({
|
|
|
42
42
|
}) {
|
|
43
43
|
var _a;
|
|
44
44
|
const wantsScope = Boolean(access == null ? void 0 : access.scope) || ((access == null ? void 0 : access.byCreator) ?? true);
|
|
45
|
-
const session = wantsScope || (access == null ? void 0 : access.can) ? await loadSession() : void 0;
|
|
45
|
+
const session = wantsScope || (access == null ? void 0 : access.can) || (access == null ? void 0 : access.stamp) ? await loadSession() : void 0;
|
|
46
46
|
if (access == null ? void 0 : access.can) {
|
|
47
47
|
if (!session) {
|
|
48
48
|
throw new import_errors.HttpError(401, "未登录");
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { PgTable } from "drizzle-orm/pg-core";
|
|
2
2
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
3
|
-
import { NextRequest } from "next/server";
|
|
4
3
|
import { ZodSchema } from "zod";
|
|
5
4
|
import { type PostOperationOptions as CorePostOperationOptions } from "./operation-core.js";
|
|
6
|
-
|
|
7
|
-
export
|
|
5
|
+
import type { DefaultSession, SessionGetter } from "./operation-common.js";
|
|
6
|
+
export type PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends PgTable, TSession = DefaultSession> = CorePostOperationOptions<IB, OB, TTable, TSession>;
|
|
7
|
+
export declare const createPostOperation: <TSession = DefaultSession>({ getSession, db, }: {
|
|
8
8
|
db?: NodePgDatabase<Record<string, unknown>> | undefined;
|
|
9
|
-
getSession
|
|
10
|
-
|
|
11
|
-
} | undefined>;
|
|
12
|
-
}) => <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>, {
|
|
13
|
-
userId?: string | undefined;
|
|
14
|
-
}>) => import("next-rest-framework").RouteOperationDefinition<"POST">;
|
|
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">;
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { PgTable } from "drizzle-orm/pg-core";
|
|
2
2
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
3
|
-
import { NextRequest } from "next/server";
|
|
4
3
|
import { ZodSchema } from "zod";
|
|
5
4
|
import { type PutOperationOptions as CorePutOperationOptions } from "./operation-core.js";
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} | undefined>;
|
|
5
|
+
import type { DefaultSession, SessionGetter } from "./operation-common.js";
|
|
6
|
+
export type PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends PgTable, TSession = DefaultSession> = CorePutOperationOptions<IB, OB, TTable, TSession>;
|
|
7
|
+
export declare const createPutOperation: <TSession = DefaultSession>({ getSession, db, }: {
|
|
8
|
+
getSession: SessionGetter<TSession>;
|
|
11
9
|
db?: NodePgDatabase<Record<string, unknown>> | undefined;
|
|
12
|
-
}) => <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>,
|
|
13
|
-
userId?: string | undefined;
|
|
14
|
-
}>) => 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("next-rest-framework").RouteOperationDefinition<"PUT">;
|
|
@@ -57,20 +57,27 @@ function createPostOperationFactory({
|
|
|
57
57
|
contentType
|
|
58
58
|
}).outputs([
|
|
59
59
|
{
|
|
60
|
-
body: schemas.response || import_zod.z.object({ id: import_zod.z.string() }),
|
|
60
|
+
body: schemas.response || import_zod.z.object({ id: import_zod.z.string().describe("Id of the row created.") }),
|
|
61
61
|
contentType: "application/json",
|
|
62
62
|
status: 200
|
|
63
63
|
}
|
|
64
64
|
]).handler(async (req) => {
|
|
65
|
+
var _a;
|
|
65
66
|
try {
|
|
66
|
-
const { scope } = await (0, import_operation_common.resolveAccess)({
|
|
67
|
+
const { scope, session } = await (0, import_operation_common.resolveAccess)({
|
|
67
68
|
access,
|
|
68
69
|
loadSession: (0, import_operation_common.sessionLoader)(getSession, req),
|
|
69
70
|
method: "POST"
|
|
70
71
|
});
|
|
71
72
|
const body = await (0, import_operation_common.readPostBody)(req, { contentType, parseBody });
|
|
72
73
|
const extraBody = await (setBody == null ? void 0 : setBody(req)) || {};
|
|
73
|
-
const
|
|
74
|
+
const stamped = session === void 0 ? {} : ((_a = access == null ? void 0 : access.stamp) == null ? void 0 : _a.call(access, session)) ?? {};
|
|
75
|
+
const params = {
|
|
76
|
+
...body,
|
|
77
|
+
...extraBody,
|
|
78
|
+
...stamped,
|
|
79
|
+
...scopeStamp(scope)
|
|
80
|
+
};
|
|
74
81
|
const raw = table && db ? (await createAction({
|
|
75
82
|
bodySchema: schemas.body,
|
|
76
83
|
db,
|
|
@@ -149,7 +156,7 @@ function createPutOperationFactory({
|
|
|
149
156
|
});
|
|
150
157
|
}
|
|
151
158
|
var defaultDeleteBodySchema = import_zod.z.object({
|
|
152
|
-
id: import_zod.z.string()
|
|
159
|
+
id: import_zod.z.string().describe("Id of the row to delete.")
|
|
153
160
|
});
|
|
154
161
|
function createDeleteOperationFactory({
|
|
155
162
|
createAction,
|
|
@@ -58,22 +58,56 @@ var BASIC_UPDATE_OMIT = {
|
|
|
58
58
|
updatedAt: true
|
|
59
59
|
};
|
|
60
60
|
var queryListSchema = (schema) => import_zod.z.object({
|
|
61
|
-
current: import_zod.z.string().optional().default("1"),
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
createdAtFrom: import_zod.z.string().optional()
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
orderBy: import_zod.z.string().optional()
|
|
70
|
-
|
|
71
|
-
|
|
61
|
+
current: import_zod.z.string().optional().default("1").describe("Page number, starting at 1."),
|
|
62
|
+
pageSize: import_zod.z.string().optional().default("10").describe(
|
|
63
|
+
"Rows per page. Omitting it yields only 10 — pass a larger value to get the whole set."
|
|
64
|
+
),
|
|
65
|
+
createdAtFrom: import_zod.z.string().optional().describe(
|
|
66
|
+
"Keep only rows created at or after this instant (ISO 8601, e.g. 2026-08-01T00:00:00Z)."
|
|
67
|
+
),
|
|
68
|
+
createdAtTo: import_zod.z.string().optional().describe("Keep only rows created at or before this instant."),
|
|
69
|
+
orderBy: import_zod.z.string().optional().describe(
|
|
70
|
+
"Column to sort by — a column name of this resource (createdAt / updatedAt and the like)."
|
|
71
|
+
),
|
|
72
|
+
creatorId: import_zod.z.string().optional().describe(
|
|
73
|
+
"Keep only rows created by this user. Useful in shared spaces to filter down to one member."
|
|
74
|
+
),
|
|
75
|
+
orderDir: import_zod.z.enum(["asc", "desc"]).optional().describe("Sort ascending or descending.")
|
|
72
76
|
}).merge(schema);
|
|
73
77
|
var listBodySchema = (schema) => import_zod.z.object({
|
|
74
78
|
total: import_zod.z.number(),
|
|
75
79
|
data: import_zod.z.array(schema)
|
|
76
80
|
});
|
|
81
|
+
var BASIC_FIELD_NOTES = {
|
|
82
|
+
creatorId: "User id of the creator. Stamped by the server; clients cannot send it.",
|
|
83
|
+
editorId: "User id of whoever changed this row last. Stamped by the server; clients cannot send it.",
|
|
84
|
+
id: "Primary key of this row (uuid)."
|
|
85
|
+
};
|
|
86
|
+
var BASIC_TIMESTAMP_NOTES = {
|
|
87
|
+
accessedAt: "When this row was last accessed.",
|
|
88
|
+
createdAt: "When this row was created.",
|
|
89
|
+
updatedAt: "When this row was last modified."
|
|
90
|
+
};
|
|
91
|
+
var describeBasicFields = (schema) => {
|
|
92
|
+
const overlay = {};
|
|
93
|
+
for (const [field, note] of Object.entries(BASIC_FIELD_NOTES)) {
|
|
94
|
+
const existing = schema.shape[field];
|
|
95
|
+
if (existing) {
|
|
96
|
+
overlay[field] = existing.describe(note);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
for (const [field, note] of Object.entries(BASIC_TIMESTAMP_NOTES)) {
|
|
100
|
+
const existing = schema.shape[field];
|
|
101
|
+
if (existing) {
|
|
102
|
+
overlay[field] = existing.meta({
|
|
103
|
+
description: note,
|
|
104
|
+
format: "date-time",
|
|
105
|
+
type: "string"
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return schema.extend(overlay);
|
|
110
|
+
};
|
|
77
111
|
var createTableSchema = ({
|
|
78
112
|
name,
|
|
79
113
|
columns,
|
|
@@ -86,12 +120,14 @@ var createTableSchema = ({
|
|
|
86
120
|
...columns
|
|
87
121
|
};
|
|
88
122
|
const table = (0, import_pg_core.pgTable)(name, mergedColumns, extraConfig);
|
|
89
|
-
const selectSchema = (0, import_drizzle_zod.createSelectSchema)(table);
|
|
123
|
+
const selectSchema = describeBasicFields((0, import_drizzle_zod.createSelectSchema)(table));
|
|
90
124
|
const insertSchema = (0, import_drizzle_zod.createInsertSchema)((0, import_pg_core.pgTable)(name, columns));
|
|
91
125
|
const updateSchema = (0, import_drizzle_zod.createUpdateSchema)(
|
|
92
126
|
(0, import_pg_core.pgTable)(name, { id: (0, import_pg_core.uuid)("id"), ...columns })
|
|
93
|
-
).extend({ id: import_zod.z.string() });
|
|
94
|
-
const querySchema = import_zod.z.object({
|
|
127
|
+
).extend({ id: import_zod.z.string().describe("Id of the row to update.") });
|
|
128
|
+
const querySchema = import_zod.z.object({
|
|
129
|
+
id: import_zod.z.string().describe("Id of the row to fetch.")
|
|
130
|
+
});
|
|
95
131
|
const queryListWithSchema = queryListSchema(
|
|
96
132
|
import_zod.z.object({}).catchall(import_zod.z.unknown())
|
|
97
133
|
);
|
|
@@ -60,22 +60,56 @@ var BASIC_UPDATE_OMIT = {
|
|
|
60
60
|
updatedAt: true
|
|
61
61
|
};
|
|
62
62
|
var queryListSchema = (schema) => import_zod.z.object({
|
|
63
|
-
current: import_zod.z.string().optional().default("1"),
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
createdAtFrom: import_zod.z.string().optional()
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
orderBy: import_zod.z.string().optional()
|
|
72
|
-
|
|
73
|
-
|
|
63
|
+
current: import_zod.z.string().optional().default("1").describe("Page number, starting at 1."),
|
|
64
|
+
pageSize: import_zod.z.string().optional().default("10").describe(
|
|
65
|
+
"Rows per page. Omitting it yields only 10 — pass a larger value to get the whole set."
|
|
66
|
+
),
|
|
67
|
+
createdAtFrom: import_zod.z.string().optional().describe(
|
|
68
|
+
"Keep only rows created at or after this instant (ISO 8601, e.g. 2026-08-01T00:00:00Z)."
|
|
69
|
+
),
|
|
70
|
+
createdAtTo: import_zod.z.string().optional().describe("Keep only rows created at or before this instant."),
|
|
71
|
+
orderBy: import_zod.z.string().optional().describe(
|
|
72
|
+
"Column to sort by — a column name of this resource (createdAt / updatedAt and the like)."
|
|
73
|
+
),
|
|
74
|
+
creatorId: import_zod.z.string().optional().describe(
|
|
75
|
+
"Keep only rows created by this user. Useful in shared spaces to filter down to one member."
|
|
76
|
+
),
|
|
77
|
+
orderDir: import_zod.z.enum(["asc", "desc"]).optional().describe("Sort ascending or descending.")
|
|
74
78
|
}).merge(schema);
|
|
75
79
|
var listBodySchema = (schema) => import_zod.z.object({
|
|
76
80
|
total: import_zod.z.number(),
|
|
77
81
|
data: import_zod.z.array(schema)
|
|
78
82
|
});
|
|
83
|
+
var BASIC_FIELD_NOTES = {
|
|
84
|
+
creatorId: "User id of the creator. Stamped by the server; clients cannot send it.",
|
|
85
|
+
editorId: "User id of whoever changed this row last. Stamped by the server; clients cannot send it.",
|
|
86
|
+
id: "Primary key of this row (uuid)."
|
|
87
|
+
};
|
|
88
|
+
var BASIC_TIMESTAMP_NOTES = {
|
|
89
|
+
accessedAt: "When this row was last accessed.",
|
|
90
|
+
createdAt: "When this row was created.",
|
|
91
|
+
updatedAt: "When this row was last modified."
|
|
92
|
+
};
|
|
93
|
+
var describeBasicFields = (schema) => {
|
|
94
|
+
const overlay = {};
|
|
95
|
+
for (const [field, note] of Object.entries(BASIC_FIELD_NOTES)) {
|
|
96
|
+
const existing = schema.shape[field];
|
|
97
|
+
if (existing) {
|
|
98
|
+
overlay[field] = existing.describe(note);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
for (const [field, note] of Object.entries(BASIC_TIMESTAMP_NOTES)) {
|
|
102
|
+
const existing = schema.shape[field];
|
|
103
|
+
if (existing) {
|
|
104
|
+
overlay[field] = existing.meta({
|
|
105
|
+
description: note,
|
|
106
|
+
format: "date-time",
|
|
107
|
+
type: "string"
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return schema.extend(overlay);
|
|
112
|
+
};
|
|
79
113
|
var createTableSchema = ({ name, columns, serverColumns, extraConfig }) => {
|
|
80
114
|
const mergedColumns = {
|
|
81
115
|
...basicFields,
|
|
@@ -87,12 +121,14 @@ var createTableSchema = ({ name, columns, serverColumns, extraConfig }) => {
|
|
|
87
121
|
mergedColumns,
|
|
88
122
|
extraConfig
|
|
89
123
|
);
|
|
90
|
-
const selectSchema = (0, import_drizzle_zod.createSelectSchema)(table);
|
|
124
|
+
const selectSchema = describeBasicFields((0, import_drizzle_zod.createSelectSchema)(table));
|
|
91
125
|
const insertSchema = (0, import_drizzle_zod.createInsertSchema)((0, import_sqlite_core.sqliteTable)(name, columns));
|
|
92
126
|
const updateSchema = (0, import_drizzle_zod.createUpdateSchema)(
|
|
93
127
|
(0, import_sqlite_core.sqliteTable)(name, { id: (0, import_sqlite_core.text)("id"), ...columns })
|
|
94
|
-
).extend({ id: import_zod.z.string() });
|
|
95
|
-
const querySchema = import_zod.z.object({
|
|
128
|
+
).extend({ id: import_zod.z.string().describe("Id of the row to update.") });
|
|
129
|
+
const querySchema = import_zod.z.object({
|
|
130
|
+
id: import_zod.z.string().describe("Id of the row to fetch.")
|
|
131
|
+
});
|
|
96
132
|
const queryListWithSchema = queryListSchema(
|
|
97
133
|
import_zod.z.object({}).catchall(import_zod.z.unknown())
|
|
98
134
|
);
|