@ai0x0/utils 0.0.45 → 0.0.47
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/.agents/skills/ai0x0-utils/backend/SKILL.md +3 -1
- package/SKILL.md +3 -1
- package/es/backend/route-operation/delete-operation.d.ts +12 -6
- package/es/backend/route-operation/delete-operation.js +52 -46
- package/es/backend/route-operation/get-list-operation.d.ts +5 -1
- package/es/backend/route-operation/get-list-operation.js +30 -23
- package/es/backend/route-operation/get-operation.d.ts +5 -1
- package/es/backend/route-operation/get-operation.js +30 -23
- package/es/backend/route-operation/post-operation.d.ts +5 -1
- package/es/backend/route-operation/put-operation.d.ts +5 -1
- package/es/backend/sqlite/route-operation/delete-operation.d.ts +12 -6
- package/es/backend/sqlite/route-operation/delete-operation.js +52 -46
- package/es/backend/sqlite/route-operation/get-list-operation.d.ts +5 -1
- package/es/backend/sqlite/route-operation/get-list-operation.js +30 -23
- package/es/backend/sqlite/route-operation/get-operation.d.ts +5 -1
- package/es/backend/sqlite/route-operation/get-operation.js +30 -23
- package/es/backend/sqlite/route-operation/post-operation.d.ts +5 -1
- package/es/backend/sqlite/route-operation/put-operation.d.ts +5 -1
- package/es/backend/sqlite/schemas/index.d.ts +69 -5
- package/es/backend/sqlite/schemas/index.js +0 -1
- package/lib/backend/route-operation/delete-operation.d.ts +12 -6
- package/lib/backend/route-operation/delete-operation.js +10 -5
- package/lib/backend/route-operation/get-list-operation.d.ts +5 -1
- package/lib/backend/route-operation/get-list-operation.js +10 -6
- package/lib/backend/route-operation/get-operation.d.ts +5 -1
- package/lib/backend/route-operation/get-operation.js +10 -6
- package/lib/backend/route-operation/post-operation.d.ts +5 -1
- package/lib/backend/route-operation/put-operation.d.ts +5 -1
- package/lib/backend/sqlite/route-operation/delete-operation.d.ts +12 -6
- package/lib/backend/sqlite/route-operation/delete-operation.js +10 -5
- package/lib/backend/sqlite/route-operation/get-list-operation.d.ts +5 -1
- package/lib/backend/sqlite/route-operation/get-list-operation.js +10 -6
- package/lib/backend/sqlite/route-operation/get-operation.d.ts +5 -1
- package/lib/backend/sqlite/route-operation/get-operation.js +10 -6
- package/lib/backend/sqlite/route-operation/post-operation.d.ts +5 -1
- package/lib/backend/sqlite/route-operation/put-operation.d.ts +5 -1
- package/lib/backend/sqlite/schemas/index.d.ts +69 -5
- package/package.json +1 -1
|
@@ -42,12 +42,76 @@ export declare const BASIC_UPDATE_OMIT: {
|
|
|
42
42
|
readonly createdAt: true;
|
|
43
43
|
readonly updatedAt: true;
|
|
44
44
|
};
|
|
45
|
-
export declare const queryListSchema: (schema:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
export declare const queryListSchema: <Incoming extends z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>(schema: Incoming) => z.ZodObject<(("creatorId" | "orderBy" | "orderDir" | "pageSize" | "current" | "createdAtFrom" | "createdAtTo") & keyof Incoming["shape"] extends never ? {
|
|
46
|
+
current: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
47
|
+
pageSize: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
48
|
+
createdAtFrom: z.ZodOptional<z.ZodString>;
|
|
49
|
+
createdAtTo: z.ZodOptional<z.ZodString>;
|
|
50
|
+
orderBy: z.ZodOptional<z.ZodString>;
|
|
51
|
+
creatorId: z.ZodOptional<z.ZodString>;
|
|
52
|
+
orderDir: z.ZodOptional<z.ZodEnum<{
|
|
53
|
+
asc: "asc";
|
|
54
|
+
desc: "desc";
|
|
55
|
+
}>>;
|
|
56
|
+
} & Incoming["shape"] : ({
|
|
57
|
+
current: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
58
|
+
pageSize: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
59
|
+
createdAtFrom: z.ZodOptional<z.ZodString>;
|
|
60
|
+
createdAtTo: z.ZodOptional<z.ZodString>;
|
|
61
|
+
orderBy: z.ZodOptional<z.ZodString>;
|
|
62
|
+
creatorId: z.ZodOptional<z.ZodString>;
|
|
63
|
+
orderDir: z.ZodOptional<z.ZodEnum<{
|
|
64
|
+
asc: "asc";
|
|
65
|
+
desc: "desc";
|
|
66
|
+
}>>;
|
|
67
|
+
} extends infer T_1 extends z.core.util.SomeObject ? { [K in keyof T_1 as K extends keyof Incoming["shape"] ? never : K]: {
|
|
68
|
+
current: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
69
|
+
pageSize: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
70
|
+
createdAtFrom: z.ZodOptional<z.ZodString>;
|
|
71
|
+
createdAtTo: z.ZodOptional<z.ZodString>;
|
|
72
|
+
orderBy: z.ZodOptional<z.ZodString>;
|
|
73
|
+
creatorId: z.ZodOptional<z.ZodString>;
|
|
74
|
+
orderDir: z.ZodOptional<z.ZodEnum<{
|
|
75
|
+
asc: "asc";
|
|
76
|
+
desc: "desc";
|
|
77
|
+
}>>;
|
|
78
|
+
}[K]; } : never) & (Incoming["shape"] extends infer T_2 extends z.core.util.SomeObject ? { [K_1 in keyof T_2]: Incoming["shape"][K_1]; } : never)) extends infer T ? { [k in keyof T]: (("creatorId" | "orderBy" | "orderDir" | "pageSize" | "current" | "createdAtFrom" | "createdAtTo") & keyof Incoming["shape"] extends never ? {
|
|
79
|
+
current: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
80
|
+
pageSize: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
81
|
+
createdAtFrom: z.ZodOptional<z.ZodString>;
|
|
82
|
+
createdAtTo: z.ZodOptional<z.ZodString>;
|
|
83
|
+
orderBy: z.ZodOptional<z.ZodString>;
|
|
84
|
+
creatorId: z.ZodOptional<z.ZodString>;
|
|
85
|
+
orderDir: z.ZodOptional<z.ZodEnum<{
|
|
86
|
+
asc: "asc";
|
|
87
|
+
desc: "desc";
|
|
88
|
+
}>>;
|
|
89
|
+
} & Incoming["shape"] : ({
|
|
90
|
+
current: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
91
|
+
pageSize: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
92
|
+
createdAtFrom: z.ZodOptional<z.ZodString>;
|
|
93
|
+
createdAtTo: z.ZodOptional<z.ZodString>;
|
|
94
|
+
orderBy: z.ZodOptional<z.ZodString>;
|
|
95
|
+
creatorId: z.ZodOptional<z.ZodString>;
|
|
96
|
+
orderDir: z.ZodOptional<z.ZodEnum<{
|
|
97
|
+
asc: "asc";
|
|
98
|
+
desc: "desc";
|
|
99
|
+
}>>;
|
|
100
|
+
} extends infer T_1 extends z.core.util.SomeObject ? { [K in keyof T_1 as K extends keyof Incoming["shape"] ? never : K]: {
|
|
101
|
+
current: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
102
|
+
pageSize: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
103
|
+
createdAtFrom: z.ZodOptional<z.ZodString>;
|
|
104
|
+
createdAtTo: z.ZodOptional<z.ZodString>;
|
|
105
|
+
orderBy: z.ZodOptional<z.ZodString>;
|
|
106
|
+
creatorId: z.ZodOptional<z.ZodString>;
|
|
107
|
+
orderDir: z.ZodOptional<z.ZodEnum<{
|
|
108
|
+
asc: "asc";
|
|
109
|
+
desc: "desc";
|
|
110
|
+
}>>;
|
|
111
|
+
}[K]; } : never) & (Incoming["shape"] extends infer T_2 extends z.core.util.SomeObject ? { [K_1 in keyof T_2]: Incoming["shape"][K_1]; } : never))[k]; } : never, Incoming["_zod"]["config"]>;
|
|
112
|
+
export declare const listBodySchema: <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>(schema: T) => z.ZodObject<{
|
|
49
113
|
total: z.ZodNumber;
|
|
50
|
-
data: z.ZodArray<
|
|
114
|
+
data: z.ZodArray<T>;
|
|
51
115
|
}, z.core.$strip>;
|
|
52
116
|
/**
|
|
53
117
|
* 基于 drizzle + drizzle-zod 快速生成带基础字段(id / 创建时间等)的
|
|
@@ -4,7 +4,6 @@ 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
|
-
/* eslint-disable no-unused-vars */
|
|
8
7
|
import { z } from "zod";
|
|
9
8
|
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
10
9
|
import { createInsertSchema, createSelectSchema, createUpdateSchema } from "drizzle-zod";
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { TypedNextResponse } from "next-rest-framework";
|
|
2
|
+
import { z } from "zod";
|
|
2
3
|
import { BaseTable } from "../types.js";
|
|
3
4
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
4
5
|
import { NextRequest } from "next/server";
|
|
5
|
-
|
|
6
|
+
type DeleteOperationParams<B extends z.ZodSchema> = z.infer<B> & Record<string, unknown> & {
|
|
7
|
+
creatorId?: string;
|
|
8
|
+
id: string;
|
|
9
|
+
};
|
|
10
|
+
export interface DeleteOperationOptions<TTable extends BaseTable, B extends z.ZodSchema> {
|
|
6
11
|
table?: TTable;
|
|
12
|
+
bodySchema?: B;
|
|
7
13
|
description?: string;
|
|
8
14
|
summary?: string;
|
|
9
15
|
tags?: string[];
|
|
10
16
|
onSuccess?: (payload: {
|
|
11
|
-
params:
|
|
12
|
-
id: string;
|
|
13
|
-
creatorId?: string;
|
|
14
|
-
};
|
|
17
|
+
params: DeleteOperationParams<B>;
|
|
15
18
|
data: unknown;
|
|
16
19
|
}) => Promise<void>;
|
|
17
20
|
onError?(error: Error): Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
@@ -22,4 +25,7 @@ export declare const createDeleteOperation: ({ db, getSession, }: {
|
|
|
22
25
|
getSession(req: NextRequest): Promise<{
|
|
23
26
|
userId?: string;
|
|
24
27
|
} | undefined>;
|
|
25
|
-
}) => <TTable extends BaseTable
|
|
28
|
+
}) => <TTable extends BaseTable, B extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>> = z.ZodObject<{
|
|
29
|
+
id: z.ZodString;
|
|
30
|
+
}, z.core.$strip>>({ table, bodySchema, description, summary, tags, onSuccess, onError, byCreator, }: DeleteOperationOptions<TTable, B>) => import("next-rest-framework").RouteOperationDefinition<"DELETE">;
|
|
31
|
+
export {};
|
|
@@ -37,11 +37,15 @@ var import_zod = require("zod");
|
|
|
37
37
|
var import_get_table_name = __toESM(require("./get-table-name"));
|
|
38
38
|
var import_actions = require("../actions");
|
|
39
39
|
var import_errors = require("../errors");
|
|
40
|
+
var defaultDeleteBodySchema = import_zod.z.object({
|
|
41
|
+
id: import_zod.z.string()
|
|
42
|
+
});
|
|
40
43
|
var createDeleteOperation = ({
|
|
41
44
|
db,
|
|
42
45
|
getSession
|
|
43
46
|
}) => ({
|
|
44
47
|
table,
|
|
48
|
+
bodySchema = defaultDeleteBodySchema,
|
|
45
49
|
description,
|
|
46
50
|
summary,
|
|
47
51
|
tags,
|
|
@@ -56,18 +60,19 @@ var createDeleteOperation = ({
|
|
|
56
60
|
tags: tags ?? (table ? [(0, import_get_table_name.default)(table)] : [])
|
|
57
61
|
}
|
|
58
62
|
}).input({
|
|
59
|
-
body:
|
|
60
|
-
id: import_zod.z.string()
|
|
61
|
-
}),
|
|
63
|
+
body: bodySchema,
|
|
62
64
|
contentType: "application/json"
|
|
63
65
|
}).handler(async (req) => {
|
|
64
66
|
try {
|
|
65
|
-
const body =
|
|
67
|
+
const body = bodySchema.parse(
|
|
68
|
+
await req.json()
|
|
69
|
+
);
|
|
66
70
|
if (byCreator) {
|
|
67
71
|
const { userId } = await getSession(req) || {};
|
|
68
72
|
body.creatorId = userId;
|
|
69
73
|
}
|
|
70
|
-
const
|
|
74
|
+
const tableParams = body;
|
|
75
|
+
const data = table && db ? await (0, import_actions.createDeleteAction)({ table, db })(tableParams) : body;
|
|
71
76
|
await (onSuccess == null ? void 0 : onSuccess({ data, params: body }));
|
|
72
77
|
return import_next_rest_framework.TypedNextResponse.json(data, {
|
|
73
78
|
status: 200
|
|
@@ -3,6 +3,9 @@ import { NextRequest } from "next/server";
|
|
|
3
3
|
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
4
4
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
5
5
|
import { BaseTable, GetListRelations } from "../types.js";
|
|
6
|
+
type GetListOperationParams<Q extends ZodSchema> = z.infer<Q> & Record<string, unknown> & {
|
|
7
|
+
creatorId?: string;
|
|
8
|
+
};
|
|
6
9
|
export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> {
|
|
7
10
|
bodySchema: T;
|
|
8
11
|
jsonArrayFields?: string[];
|
|
@@ -15,7 +18,7 @@ export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchem
|
|
|
15
18
|
tags?: string[];
|
|
16
19
|
table?: TTable;
|
|
17
20
|
onSuccess?<D extends T>(payload: {
|
|
18
|
-
params:
|
|
21
|
+
params: GetListOperationParams<Q>;
|
|
19
22
|
data: {
|
|
20
23
|
data: z.infer<D>[];
|
|
21
24
|
total: number;
|
|
@@ -32,3 +35,4 @@ export declare const createGetListOperation: ({ db, getSession, }: {
|
|
|
32
35
|
userId?: string;
|
|
33
36
|
} | undefined>;
|
|
34
37
|
}) => <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, Q extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, TTable extends BaseTable>({ querySchema, bodySchema, table, description, summary, tags, relations, jsonArrayFields, setParams, onSuccess, onError, byCreator, }: GetListOperationOptions<T, Q, TTable>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
38
|
+
export {};
|
|
@@ -69,24 +69,28 @@ var createGetListOperation = ({
|
|
|
69
69
|
}
|
|
70
70
|
]).handler(async (req) => {
|
|
71
71
|
try {
|
|
72
|
-
const
|
|
72
|
+
const extraParams = await (setParams == null ? void 0 : setParams(
|
|
73
73
|
req
|
|
74
74
|
)) || {};
|
|
75
75
|
if (byCreator) {
|
|
76
76
|
const { userId } = await getSession(req) || {};
|
|
77
|
-
|
|
77
|
+
extraParams.creatorId = userId;
|
|
78
78
|
}
|
|
79
|
-
const
|
|
80
|
-
Object.fromEntries(new URL(req.url).searchParams)
|
|
81
|
-
params
|
|
79
|
+
const queryParams = querySchema.parse(
|
|
80
|
+
Object.fromEntries(new URL(req.url).searchParams)
|
|
82
81
|
);
|
|
82
|
+
const mergedParams = {
|
|
83
|
+
...queryParams,
|
|
84
|
+
...extraParams
|
|
85
|
+
};
|
|
86
|
+
const tableParams = mergedParams;
|
|
83
87
|
let result = table && db ? await (0, import_actions.createGetListAction)({
|
|
84
88
|
bodySchema,
|
|
85
89
|
db,
|
|
86
90
|
jsonArrayFields,
|
|
87
91
|
relations,
|
|
88
92
|
table
|
|
89
|
-
})(
|
|
93
|
+
})(tableParams) : { data: [], total: 0 };
|
|
90
94
|
if (onSuccess) {
|
|
91
95
|
result = await onSuccess({ data: result, params: mergedParams });
|
|
92
96
|
}
|
|
@@ -3,6 +3,9 @@ import { NextRequest } from "next/server";
|
|
|
3
3
|
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
4
4
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
5
5
|
import { BaseTable, GetListRelations } from "../types.js";
|
|
6
|
+
type GetOperationParams<Q extends ZodSchema> = z.infer<Q> & Record<string, unknown> & {
|
|
7
|
+
creatorId?: string;
|
|
8
|
+
};
|
|
6
9
|
export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> {
|
|
7
10
|
bodySchema: T;
|
|
8
11
|
jsonArrayFields?: string[];
|
|
@@ -10,7 +13,7 @@ export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, T
|
|
|
10
13
|
relations?: GetListRelations;
|
|
11
14
|
setParams?(req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>): Promise<Record<string, unknown>>;
|
|
12
15
|
onSuccess?(payload: {
|
|
13
|
-
params:
|
|
16
|
+
params: GetOperationParams<Q>;
|
|
14
17
|
data: z.infer<T>;
|
|
15
18
|
}): Promise<z.infer<T>>;
|
|
16
19
|
onError?(error: Error): Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
@@ -26,3 +29,4 @@ export declare const createGetOperation: ({ getSession, db, }: {
|
|
|
26
29
|
userId?: string;
|
|
27
30
|
} | undefined>;
|
|
28
31
|
}) => <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, Q extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, TTable extends BaseTable>({ querySchema, bodySchema, table, description, summary, tags, relations, setParams, jsonArrayFields, onSuccess, onError, byCreator, }: GetOperationOptions<T, Q, TTable>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
32
|
+
export {};
|
|
@@ -68,24 +68,28 @@ var createGetOperation = ({
|
|
|
68
68
|
}
|
|
69
69
|
]).handler(async (req) => {
|
|
70
70
|
try {
|
|
71
|
-
const
|
|
71
|
+
const extraParams = await (setParams == null ? void 0 : setParams(
|
|
72
72
|
req
|
|
73
73
|
)) || {};
|
|
74
74
|
if (byCreator) {
|
|
75
75
|
const { userId } = await getSession(req) || {};
|
|
76
|
-
|
|
76
|
+
extraParams.creatorId = userId;
|
|
77
77
|
}
|
|
78
|
-
const
|
|
79
|
-
Object.fromEntries(new URL(req.url).searchParams)
|
|
80
|
-
params
|
|
78
|
+
const queryParams = querySchema.parse(
|
|
79
|
+
Object.fromEntries(new URL(req.url).searchParams)
|
|
81
80
|
);
|
|
81
|
+
const mergedParams = {
|
|
82
|
+
...queryParams,
|
|
83
|
+
...extraParams
|
|
84
|
+
};
|
|
85
|
+
const tableParams = mergedParams;
|
|
82
86
|
const rawResult = table && db ? await (0, import_actions.createGetAction)({
|
|
83
87
|
bodySchema,
|
|
84
88
|
db,
|
|
85
89
|
jsonArrayFields,
|
|
86
90
|
relations,
|
|
87
91
|
table
|
|
88
|
-
})(
|
|
92
|
+
})(tableParams) : mergedParams;
|
|
89
93
|
let result = rawResult ?? {};
|
|
90
94
|
if (onSuccess) {
|
|
91
95
|
result = await onSuccess({ data: result, params: mergedParams });
|
|
@@ -3,6 +3,9 @@ import { PgTable } from "drizzle-orm/pg-core";
|
|
|
3
3
|
import { NextRequest } from "next/server";
|
|
4
4
|
import { TypedNextResponse } from "next-rest-framework";
|
|
5
5
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
6
|
+
type PostOperationParams<IB extends ZodSchema> = z.infer<IB> & Record<string, unknown> & {
|
|
7
|
+
creatorId?: string;
|
|
8
|
+
};
|
|
6
9
|
export interface PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends PgTable> {
|
|
7
10
|
bodySchema: IB;
|
|
8
11
|
contentType?: string;
|
|
@@ -13,7 +16,7 @@ export interface PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema
|
|
|
13
16
|
summary?: string;
|
|
14
17
|
tags?: string[];
|
|
15
18
|
onSuccess?(payload: {
|
|
16
|
-
params:
|
|
19
|
+
params: PostOperationParams<IB>;
|
|
17
20
|
data: z.infer<OB>;
|
|
18
21
|
req: NextRequest;
|
|
19
22
|
}): Promise<z.infer<OB>>;
|
|
@@ -26,3 +29,4 @@ export declare const createPostOperation: ({ getSession, db, }: {
|
|
|
26
29
|
userId?: string;
|
|
27
30
|
} | undefined>;
|
|
28
31
|
}) => <IB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, TTable extends PgTable<import("drizzle-orm/pg-core").TableConfig>>({ bodySchema, contentType, description, outputBodySchema, parseBody, setBody, summary, tags, table, onSuccess, onError, }: PostOperationOptions<IB, OB, TTable>) => import("next-rest-framework").RouteOperationDefinition<"POST">;
|
|
32
|
+
export {};
|
|
@@ -4,6 +4,9 @@ import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
|
4
4
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
5
5
|
import { NextRequest } from "next/server";
|
|
6
6
|
import { BaseTable } from "../types.js";
|
|
7
|
+
type PutOperationParams<IB extends ZodSchema> = z.infer<IB> & Record<string, unknown> & {
|
|
8
|
+
editorId?: string;
|
|
9
|
+
};
|
|
7
10
|
export interface PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends PgTable> {
|
|
8
11
|
bodySchema: IB;
|
|
9
12
|
description?: string;
|
|
@@ -13,7 +16,7 @@ export interface PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema,
|
|
|
13
16
|
tags?: string[];
|
|
14
17
|
setBody?(req: TypedNextRequest<"PUT", "application/json", z.infer<IB>>): Promise<Partial<z.infer<IB>>>;
|
|
15
18
|
onSuccess?(payload: {
|
|
16
|
-
params:
|
|
19
|
+
params: PutOperationParams<IB>;
|
|
17
20
|
data: z.infer<OB>;
|
|
18
21
|
}): Promise<z.infer<OB>>;
|
|
19
22
|
onError?(error: Error): Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
@@ -25,3 +28,4 @@ export declare const createPutOperation: ({ getSession, db, }: {
|
|
|
25
28
|
} | undefined>;
|
|
26
29
|
db?: NodePgDatabase<Record<string, unknown>> | undefined;
|
|
27
30
|
}) => <IB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, TTable extends BaseTable>({ bodySchema, description, outputBodySchema, table, summary, tags, setBody, onSuccess, byCreator, onError, }: PutOperationOptions<IB, OB, TTable>) => import("next-rest-framework").RouteOperationDefinition<"PUT">;
|
|
31
|
+
export {};
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { TypedNextResponse } from "next-rest-framework";
|
|
2
|
+
import { z } from "zod";
|
|
2
3
|
import { BaseTable } from "../types.js";
|
|
3
4
|
import { NextRequest } from "next/server";
|
|
4
|
-
|
|
5
|
+
type DeleteOperationParams<B extends z.ZodSchema> = z.infer<B> & Record<string, unknown> & {
|
|
6
|
+
creatorId?: string;
|
|
7
|
+
id: string;
|
|
8
|
+
};
|
|
9
|
+
export interface DeleteOperationOptions<TTable extends BaseTable, B extends z.ZodSchema> {
|
|
5
10
|
table?: TTable;
|
|
11
|
+
bodySchema?: B;
|
|
6
12
|
description?: string;
|
|
7
13
|
summary?: string;
|
|
8
14
|
tags?: string[];
|
|
9
15
|
onSuccess?: (_payload: {
|
|
10
|
-
params:
|
|
11
|
-
id: string;
|
|
12
|
-
creatorId?: string;
|
|
13
|
-
};
|
|
16
|
+
params: DeleteOperationParams<B>;
|
|
14
17
|
data: unknown;
|
|
15
18
|
}) => Promise<void>;
|
|
16
19
|
onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
@@ -21,4 +24,7 @@ export declare const createDeleteOperation: ({ db, getSession, }: {
|
|
|
21
24
|
getSession: (_req: NextRequest) => Promise<{
|
|
22
25
|
userId?: string;
|
|
23
26
|
} | undefined>;
|
|
24
|
-
}) => <TTable extends BaseTable
|
|
27
|
+
}) => <TTable extends BaseTable, B extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>> = z.ZodObject<{
|
|
28
|
+
id: z.ZodString;
|
|
29
|
+
}, z.core.$strip>>({ table, bodySchema, description, summary, tags, onSuccess, onError, byCreator, }: DeleteOperationOptions<TTable, B>) => import("next-rest-framework").RouteOperationDefinition<"DELETE">;
|
|
30
|
+
export {};
|
|
@@ -37,11 +37,15 @@ var import_zod = require("zod");
|
|
|
37
37
|
var import_get_table_name = __toESM(require("./get-table-name"));
|
|
38
38
|
var import_actions = require("../actions");
|
|
39
39
|
var import_errors = require("../errors");
|
|
40
|
+
var defaultDeleteBodySchema = import_zod.z.object({
|
|
41
|
+
id: import_zod.z.string()
|
|
42
|
+
});
|
|
40
43
|
var createDeleteOperation = ({
|
|
41
44
|
db,
|
|
42
45
|
getSession
|
|
43
46
|
}) => ({
|
|
44
47
|
table,
|
|
48
|
+
bodySchema = defaultDeleteBodySchema,
|
|
45
49
|
description,
|
|
46
50
|
summary,
|
|
47
51
|
tags,
|
|
@@ -56,18 +60,19 @@ var createDeleteOperation = ({
|
|
|
56
60
|
tags: tags ?? (table ? [(0, import_get_table_name.default)(table)] : [])
|
|
57
61
|
}
|
|
58
62
|
}).input({
|
|
59
|
-
body:
|
|
60
|
-
id: import_zod.z.string()
|
|
61
|
-
}),
|
|
63
|
+
body: bodySchema,
|
|
62
64
|
contentType: "application/json"
|
|
63
65
|
}).handler(async (req) => {
|
|
64
66
|
try {
|
|
65
|
-
const body =
|
|
67
|
+
const body = bodySchema.parse(
|
|
68
|
+
await req.json()
|
|
69
|
+
);
|
|
66
70
|
if (byCreator) {
|
|
67
71
|
const { userId } = await getSession(req) || {};
|
|
68
72
|
body.creatorId = userId;
|
|
69
73
|
}
|
|
70
|
-
const
|
|
74
|
+
const tableParams = body;
|
|
75
|
+
const data = table && db ? await (0, import_actions.createDeleteAction)({ table, db })(tableParams) : body;
|
|
71
76
|
await (onSuccess == null ? void 0 : onSuccess({ data, params: body }));
|
|
72
77
|
return import_next_rest_framework.TypedNextResponse.json(data, {
|
|
73
78
|
status: 200
|
|
@@ -2,6 +2,9 @@ import { z, ZodSchema } from "zod";
|
|
|
2
2
|
import { NextRequest } from "next/server";
|
|
3
3
|
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
4
4
|
import { BaseTable, GetListRelations } from "../types.js";
|
|
5
|
+
type GetListOperationParams<Q extends ZodSchema> = z.infer<Q> & Record<string, unknown> & {
|
|
6
|
+
creatorId?: string;
|
|
7
|
+
};
|
|
5
8
|
export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> {
|
|
6
9
|
bodySchema: T;
|
|
7
10
|
jsonArrayFields?: string[];
|
|
@@ -14,7 +17,7 @@ export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchem
|
|
|
14
17
|
tags?: string[];
|
|
15
18
|
table?: TTable;
|
|
16
19
|
onSuccess?: <D extends T>(_payload: {
|
|
17
|
-
params:
|
|
20
|
+
params: GetListOperationParams<Q>;
|
|
18
21
|
data: {
|
|
19
22
|
data: z.infer<D>[];
|
|
20
23
|
total: number;
|
|
@@ -31,3 +34,4 @@ export declare const createGetListOperation: ({ db, getSession, }: {
|
|
|
31
34
|
userId?: string;
|
|
32
35
|
} | undefined>;
|
|
33
36
|
}) => <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, Q extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, TTable extends BaseTable>({ querySchema, bodySchema, table, description, summary, tags, relations, jsonArrayFields, setParams, onSuccess, onError, byCreator, }: GetListOperationOptions<T, Q, TTable>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
37
|
+
export {};
|
|
@@ -69,24 +69,28 @@ var createGetListOperation = ({
|
|
|
69
69
|
}
|
|
70
70
|
]).handler(async (req) => {
|
|
71
71
|
try {
|
|
72
|
-
const
|
|
72
|
+
const extraParams = await (setParams == null ? void 0 : setParams(
|
|
73
73
|
req
|
|
74
74
|
)) || {};
|
|
75
75
|
if (byCreator) {
|
|
76
76
|
const { userId } = await getSession(req) || {};
|
|
77
|
-
|
|
77
|
+
extraParams.creatorId = userId;
|
|
78
78
|
}
|
|
79
|
-
const
|
|
80
|
-
Object.fromEntries(new URL(req.url).searchParams)
|
|
81
|
-
params
|
|
79
|
+
const queryParams = querySchema.parse(
|
|
80
|
+
Object.fromEntries(new URL(req.url).searchParams)
|
|
82
81
|
);
|
|
82
|
+
const mergedParams = {
|
|
83
|
+
...queryParams,
|
|
84
|
+
...extraParams
|
|
85
|
+
};
|
|
86
|
+
const tableParams = mergedParams;
|
|
83
87
|
let result = table && db ? await (0, import_actions.createGetListAction)({
|
|
84
88
|
bodySchema,
|
|
85
89
|
db,
|
|
86
90
|
jsonArrayFields,
|
|
87
91
|
relations,
|
|
88
92
|
table
|
|
89
|
-
})(
|
|
93
|
+
})(tableParams) : { data: [], total: 0 };
|
|
90
94
|
if (onSuccess) {
|
|
91
95
|
result = await onSuccess({
|
|
92
96
|
data: result,
|
|
@@ -2,6 +2,9 @@ import { z, ZodSchema } from "zod";
|
|
|
2
2
|
import { NextRequest } from "next/server";
|
|
3
3
|
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
4
4
|
import { BaseTable, GetListRelations } from "../types.js";
|
|
5
|
+
type GetOperationParams<Q extends ZodSchema> = z.infer<Q> & Record<string, unknown> & {
|
|
6
|
+
creatorId?: string;
|
|
7
|
+
};
|
|
5
8
|
export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> {
|
|
6
9
|
bodySchema: T;
|
|
7
10
|
jsonArrayFields?: string[];
|
|
@@ -9,7 +12,7 @@ export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, T
|
|
|
9
12
|
relations?: GetListRelations;
|
|
10
13
|
setParams?: (_req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string, unknown>>;
|
|
11
14
|
onSuccess?: (_payload: {
|
|
12
|
-
params:
|
|
15
|
+
params: GetOperationParams<Q>;
|
|
13
16
|
data: z.infer<T>;
|
|
14
17
|
}) => Promise<z.infer<T>>;
|
|
15
18
|
onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
@@ -25,3 +28,4 @@ export declare const createGetOperation: ({ getSession, db, }: {
|
|
|
25
28
|
userId?: string;
|
|
26
29
|
} | undefined>;
|
|
27
30
|
}) => <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, Q extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, TTable extends BaseTable>({ querySchema, bodySchema, table, description, summary, tags, relations, setParams, jsonArrayFields, onSuccess, onError, byCreator, }: GetOperationOptions<T, Q, TTable>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
31
|
+
export {};
|
|
@@ -68,24 +68,28 @@ var createGetOperation = ({
|
|
|
68
68
|
}
|
|
69
69
|
]).handler(async (req) => {
|
|
70
70
|
try {
|
|
71
|
-
const
|
|
71
|
+
const extraParams = await (setParams == null ? void 0 : setParams(
|
|
72
72
|
req
|
|
73
73
|
)) || {};
|
|
74
74
|
if (byCreator) {
|
|
75
75
|
const { userId } = await getSession(req) || {};
|
|
76
|
-
|
|
76
|
+
extraParams.creatorId = userId;
|
|
77
77
|
}
|
|
78
|
-
const
|
|
79
|
-
Object.fromEntries(new URL(req.url).searchParams)
|
|
80
|
-
params
|
|
78
|
+
const queryParams = querySchema.parse(
|
|
79
|
+
Object.fromEntries(new URL(req.url).searchParams)
|
|
81
80
|
);
|
|
81
|
+
const mergedParams = {
|
|
82
|
+
...queryParams,
|
|
83
|
+
...extraParams
|
|
84
|
+
};
|
|
85
|
+
const tableParams = mergedParams;
|
|
82
86
|
const rawResult = table && db ? await (0, import_actions.createGetAction)({
|
|
83
87
|
bodySchema,
|
|
84
88
|
db,
|
|
85
89
|
jsonArrayFields,
|
|
86
90
|
relations,
|
|
87
91
|
table
|
|
88
|
-
})(
|
|
92
|
+
})(tableParams) : mergedParams;
|
|
89
93
|
let result = rawResult ?? {};
|
|
90
94
|
if (onSuccess) {
|
|
91
95
|
result = await onSuccess({ data: result, params: mergedParams });
|
|
@@ -2,6 +2,9 @@ import { z, ZodSchema } from "zod";
|
|
|
2
2
|
import { SQLiteTable } from "drizzle-orm/sqlite-core";
|
|
3
3
|
import { NextRequest } from "next/server";
|
|
4
4
|
import { TypedNextResponse } from "next-rest-framework";
|
|
5
|
+
type PostOperationParams<IB extends ZodSchema> = z.infer<IB> & Record<string, unknown> & {
|
|
6
|
+
creatorId?: string;
|
|
7
|
+
};
|
|
5
8
|
export interface PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends SQLiteTable> {
|
|
6
9
|
bodySchema: IB;
|
|
7
10
|
contentType?: string;
|
|
@@ -12,7 +15,7 @@ export interface PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema
|
|
|
12
15
|
summary?: string;
|
|
13
16
|
tags?: string[];
|
|
14
17
|
onSuccess?: (_payload: {
|
|
15
|
-
params:
|
|
18
|
+
params: PostOperationParams<IB>;
|
|
16
19
|
data: z.infer<OB>;
|
|
17
20
|
req: NextRequest;
|
|
18
21
|
}) => Promise<z.infer<OB>>;
|
|
@@ -25,3 +28,4 @@ export declare const createPostOperation: ({ getSession, db, }: {
|
|
|
25
28
|
userId?: string;
|
|
26
29
|
} | undefined>;
|
|
27
30
|
}) => <IB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, TTable extends SQLiteTable<import("drizzle-orm/sqlite-core").TableConfig>>({ bodySchema, contentType, description, outputBodySchema, parseBody, setBody, summary, tags, table, onSuccess, onError, }: PostOperationOptions<IB, OB, TTable>) => import("next-rest-framework").RouteOperationDefinition<"POST">;
|
|
31
|
+
export {};
|
|
@@ -3,6 +3,9 @@ import { SQLiteTable } from "drizzle-orm/sqlite-core";
|
|
|
3
3
|
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
4
4
|
import { NextRequest } from "next/server";
|
|
5
5
|
import { BaseTable } from "../types.js";
|
|
6
|
+
type PutOperationParams<IB extends ZodSchema> = z.infer<IB> & Record<string, unknown> & {
|
|
7
|
+
editorId?: string;
|
|
8
|
+
};
|
|
6
9
|
export interface PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends SQLiteTable> {
|
|
7
10
|
bodySchema: IB;
|
|
8
11
|
description?: string;
|
|
@@ -12,7 +15,7 @@ export interface PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema,
|
|
|
12
15
|
tags?: string[];
|
|
13
16
|
setBody?: (_req: TypedNextRequest<"PUT", "application/json", z.infer<IB>>) => Promise<Partial<z.infer<IB>>>;
|
|
14
17
|
onSuccess?: (_payload: {
|
|
15
|
-
params:
|
|
18
|
+
params: PutOperationParams<IB>;
|
|
16
19
|
data: z.infer<OB>;
|
|
17
20
|
}) => Promise<z.infer<OB>>;
|
|
18
21
|
onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
@@ -24,3 +27,4 @@ export declare const createPutOperation: ({ getSession, db, }: {
|
|
|
24
27
|
} | undefined>;
|
|
25
28
|
db?: any;
|
|
26
29
|
}) => <IB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, TTable extends BaseTable>({ bodySchema, description, outputBodySchema, table, summary, tags, setBody, onSuccess, byCreator, onError, }: PutOperationOptions<IB, OB, TTable>) => import("next-rest-framework").RouteOperationDefinition<"PUT">;
|
|
30
|
+
export {};
|