@ai0x0/utils 0.0.14 → 0.0.16
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/SKILL.md +336 -0
- package/es/__shims__/next-rest-framework.d.ts +48 -0
- package/es/backend/actions/create-delete-action.d.ts +1 -1
- package/es/backend/actions/create-get-action.d.ts +2 -2
- package/es/backend/actions/create-get-action.js +1 -1
- package/es/backend/actions/create-get-list-action.d.ts +3 -3
- package/es/backend/actions/create-get-list-action.js +3 -3
- package/es/backend/actions/create-post-action.d.ts +2 -2
- package/es/backend/actions/create-post-action.js +8 -2
- package/es/backend/actions/create-put-action.d.ts +3 -3
- package/es/backend/actions/get-list-data.d.ts +3 -15
- package/es/backend/actions/get-list-query.d.ts +5 -7
- package/es/backend/actions/transform-body.d.ts +1 -1
- package/es/backend/actions/transform-body.js +0 -2
- package/es/backend/route-operation/delete-operation.d.ts +2 -2
- package/es/backend/route-operation/get-list-operation.d.ts +2 -2
- package/es/backend/route-operation/get-operation.d.ts +3 -3
- package/es/backend/route-operation/get-operation.js +18 -24
- package/es/backend/route-operation/post-operation.d.ts +2 -2
- package/es/backend/route-operation/post-operation.js +21 -16
- package/es/backend/route-operation/put-operation.d.ts +2 -2
- package/es/backend/route-operation/put-operation.js +21 -16
- package/es/backend/schemas/index.d.ts +76 -1249
- package/es/backend/schemas/index.js +1 -6
- package/lib/__shims__/next-rest-framework.d.ts +48 -0
- package/lib/backend/actions/create-delete-action.d.ts +1 -1
- package/lib/backend/actions/create-get-action.d.ts +2 -2
- package/lib/backend/actions/create-get-list-action.d.ts +3 -3
- package/lib/backend/actions/create-post-action.d.ts +2 -2
- package/lib/backend/actions/create-post-action.js +3 -1
- package/lib/backend/actions/create-put-action.d.ts +3 -3
- package/lib/backend/actions/create-put-action.js +4 -1
- package/lib/backend/actions/get-list-data.d.ts +3 -15
- package/lib/backend/actions/get-list-query.d.ts +5 -7
- package/lib/backend/actions/transform-body.d.ts +1 -1
- package/lib/backend/actions/transform-body.js +3 -1
- package/lib/backend/route-operation/delete-operation.d.ts +2 -2
- package/lib/backend/route-operation/get-list-operation.d.ts +2 -2
- package/lib/backend/route-operation/get-list-operation.js +7 -2
- package/lib/backend/route-operation/get-operation.d.ts +3 -3
- package/lib/backend/route-operation/get-operation.js +6 -3
- package/lib/backend/route-operation/post-operation.d.ts +2 -2
- package/lib/backend/route-operation/post-operation.js +5 -5
- package/lib/backend/route-operation/put-operation.d.ts +2 -2
- package/lib/backend/route-operation/put-operation.js +5 -5
- package/lib/backend/schemas/index.d.ts +76 -1249
- package/lib/backend/schemas/index.js +12 -14
- package/package.json +39 -35
|
@@ -7,6 +7,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
import { pgTable, timestamp, uuid } from "drizzle-orm/pg-core";
|
|
9
9
|
import { createInsertSchema, createSelectSchema, createUpdateSchema } from "drizzle-zod";
|
|
10
|
+
|
|
10
11
|
//============================基本字段============================//
|
|
11
12
|
var timestamptz = function timestamptz(name) {
|
|
12
13
|
return timestamp(name, {
|
|
@@ -74,17 +75,11 @@ export var createTableSchema = function createTableSchema(_ref) {
|
|
|
74
75
|
return {
|
|
75
76
|
table: table,
|
|
76
77
|
selectSchema: selectSchema,
|
|
77
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
78
|
-
// @ts-ignore
|
|
79
78
|
insertSchema: createInsertSchema(insertTable, refineSchema),
|
|
80
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
81
|
-
// @ts-ignore
|
|
82
79
|
updateSchema: createUpdateSchema(updateTable, _objectSpread({
|
|
83
80
|
id: z.string()
|
|
84
81
|
}, refineSchema)),
|
|
85
82
|
querySchema: selectSchema.pick({
|
|
86
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
87
|
-
// @ts-ignore
|
|
88
83
|
id: true
|
|
89
84
|
}),
|
|
90
85
|
queryListSchema: queryListSchema(selectSchema.partial()),
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { NextRequest } from "next/server";
|
|
2
|
+
import type { ZodType } from "zod";
|
|
3
|
+
|
|
4
|
+
declare module "next-rest-framework" {
|
|
5
|
+
export interface RouteOperationDefinition<M extends string = string> {
|
|
6
|
+
_method: M;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface RouteOperationBuilder<M extends string> {
|
|
10
|
+
input: (opts: {
|
|
11
|
+
body?: ZodType;
|
|
12
|
+
query?: ZodType;
|
|
13
|
+
contentType?: string;
|
|
14
|
+
}) => RouteOperationBuilder<M>;
|
|
15
|
+
outputs: (
|
|
16
|
+
opts: { body?: ZodType; status?: number; contentType?: string }[],
|
|
17
|
+
) => RouteOperationBuilder<M>;
|
|
18
|
+
handler: (
|
|
19
|
+
fn: (req: NextRequest) => Promise<Response>,
|
|
20
|
+
) => RouteOperationDefinition<M>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const routeOperation: <M extends string>(opts: {
|
|
24
|
+
method: M;
|
|
25
|
+
openApiOperation?: { summary?: string; tags?: string[] };
|
|
26
|
+
}) => RouteOperationBuilder<M>;
|
|
27
|
+
|
|
28
|
+
export const rpcOperation: () => {
|
|
29
|
+
outputs: (opts: { body?: ZodType; contentType?: string }[]) => {
|
|
30
|
+
handler: <T>(fn: () => Promise<T>) => () => Promise<T>;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const TypedNextResponse: {
|
|
35
|
+
json: <T>(body: T, init?: { status?: number }) => Response;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type TypedNextRequest<
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
40
|
+
M = string,
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
42
|
+
C = string,
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
44
|
+
B = unknown,
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
46
|
+
Q = Record<string, string>,
|
|
47
|
+
> = NextRequest;
|
|
48
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
2
2
|
import { BaseTable } from "../types";
|
|
3
3
|
export declare function createDeleteAction<TTable extends BaseTable>({ table, db, }: {
|
|
4
|
-
db: NodePgDatabase<
|
|
4
|
+
db: NodePgDatabase<Record<string, unknown>>;
|
|
5
5
|
table: TTable;
|
|
6
6
|
}): ({ id, creatorId }: {
|
|
7
7
|
id: string;
|
|
@@ -3,8 +3,8 @@ import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
|
3
3
|
import { BaseTable, GetListRelations } from "../types";
|
|
4
4
|
export declare function createGetAction<T extends ZodSchema, TTable extends BaseTable>({ bodySchema, db, jsonArrayFields, relations, table, }: {
|
|
5
5
|
bodySchema: T;
|
|
6
|
-
db: NodePgDatabase<
|
|
6
|
+
db: NodePgDatabase<Record<string, unknown>>;
|
|
7
7
|
jsonArrayFields?: string[];
|
|
8
8
|
relations?: GetListRelations;
|
|
9
9
|
table: TTable;
|
|
10
|
-
}): (params: Partial<z.infer<T>>) => Promise<T
|
|
10
|
+
}): (params: Partial<z.infer<T>> & Record<string, unknown>) => Promise<z.core.output<T> | undefined>;
|
|
@@ -3,11 +3,11 @@ import { BaseTable, GetListRelations } from "../types";
|
|
|
3
3
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
4
4
|
export declare function createGetListAction<T extends ZodSchema, TTable extends BaseTable>({ bodySchema, db, jsonArrayFields, relations, table, }: {
|
|
5
5
|
bodySchema: T;
|
|
6
|
-
db: NodePgDatabase<
|
|
6
|
+
db: NodePgDatabase<Record<string, unknown>>;
|
|
7
7
|
jsonArrayFields?: string[];
|
|
8
8
|
relations?: GetListRelations;
|
|
9
9
|
table: TTable;
|
|
10
|
-
}): (params: Partial<z.infer<T>>) => Promise<{
|
|
11
|
-
data:
|
|
10
|
+
}): (params: Partial<z.infer<T>> & Record<string, unknown>) => Promise<{
|
|
11
|
+
data: any;
|
|
12
12
|
total: number;
|
|
13
13
|
}>;
|
|
@@ -3,6 +3,6 @@ import { PgTable } from "drizzle-orm/pg-core";
|
|
|
3
3
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
4
4
|
export declare function createPostAction<T extends ZodSchema, TTable extends PgTable>({ table, db, }: {
|
|
5
5
|
bodySchema: T;
|
|
6
|
-
db: NodePgDatabase<
|
|
6
|
+
db: NodePgDatabase<Record<string, unknown>>;
|
|
7
7
|
table: TTable;
|
|
8
|
-
}): (body: z.infer<T>) => Promise<T[
|
|
8
|
+
}): (body: z.infer<T>) => Promise<z.infer<T>[]>;
|
|
@@ -28,7 +28,9 @@ function createPostAction({
|
|
|
28
28
|
db
|
|
29
29
|
}) {
|
|
30
30
|
return async (body) => {
|
|
31
|
-
|
|
31
|
+
const values = (0, import_transform_body.transformBody)(body);
|
|
32
|
+
const result = await db.insert(table).values(values).returning();
|
|
33
|
+
return result;
|
|
32
34
|
};
|
|
33
35
|
}
|
|
34
36
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -3,8 +3,8 @@ import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
|
3
3
|
import { BaseTable } from "../types";
|
|
4
4
|
export declare function createPutAction<T extends ZodSchema, TTable extends BaseTable>({ db, table, }: {
|
|
5
5
|
bodySchema: T;
|
|
6
|
-
db: NodePgDatabase<
|
|
6
|
+
db: NodePgDatabase<Record<string, unknown>>;
|
|
7
7
|
table: TTable;
|
|
8
|
-
}): (body: Partial<z.infer<T
|
|
8
|
+
}): (body: Partial<z.infer<T>> & Record<string, unknown>, { byCreator, }?: {
|
|
9
9
|
byCreator?: boolean | undefined;
|
|
10
|
-
}) => Promise<T
|
|
10
|
+
}) => Promise<z.infer<T>>;
|
|
@@ -41,7 +41,10 @@ function createPutAction({
|
|
|
41
41
|
creatorId: import_zod.z.string(),
|
|
42
42
|
id: import_zod.z.string()
|
|
43
43
|
})
|
|
44
|
-
})({
|
|
44
|
+
})({
|
|
45
|
+
creatorId: body.editorId,
|
|
46
|
+
id: body.id
|
|
47
|
+
});
|
|
45
48
|
if (!data2) {
|
|
46
49
|
throw Error("未找到编辑对象,或没有权限");
|
|
47
50
|
}
|
|
@@ -4,19 +4,7 @@ export declare function getListData<B extends ZodSchema>({ query, countQuery, pa
|
|
|
4
4
|
bodySchema: B;
|
|
5
5
|
current?: number;
|
|
6
6
|
pageSize?: number;
|
|
7
|
-
} & ReturnType<typeof getListQuery>):
|
|
8
|
-
|
|
9
|
-
total: import("zod").ZodNumber;
|
|
10
|
-
data: import("zod").ZodArray<B, "many">;
|
|
11
|
-
}, "strip", import("zod").ZodTypeAny, {
|
|
12
|
-
data: B["_output"][];
|
|
13
|
-
total: number;
|
|
14
|
-
}, {
|
|
15
|
-
data: B["_input"][];
|
|
16
|
-
total: number;
|
|
17
|
-
}>;
|
|
18
|
-
contentType: "application/json";
|
|
19
|
-
}[], false, Promise<{
|
|
20
|
-
data: B["_output"][];
|
|
7
|
+
} & ReturnType<typeof getListQuery>): () => Promise<{
|
|
8
|
+
data: any;
|
|
21
9
|
total: number;
|
|
22
|
-
}
|
|
10
|
+
}>;
|
|
@@ -3,11 +3,11 @@ import { SelectedFields } from "drizzle-orm/pg-core/query-builders/select.types"
|
|
|
3
3
|
import { SQL } from "drizzle-orm";
|
|
4
4
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
5
5
|
export declare function getListQuery<TTable extends BaseTable, TSelection extends SelectedFields>({ db, fields, jsonArrayFields, params, relations, table, }: {
|
|
6
|
-
db: NodePgDatabase<
|
|
6
|
+
db: NodePgDatabase<Record<string, unknown>>;
|
|
7
7
|
fields: TSelection;
|
|
8
8
|
jsonArrayFields?: string[];
|
|
9
9
|
params: {
|
|
10
|
-
[field: string]:
|
|
10
|
+
[field: string]: unknown;
|
|
11
11
|
orderBy?: keyof BaseTable;
|
|
12
12
|
orderDir?: "asc" | "desc";
|
|
13
13
|
page?: number;
|
|
@@ -16,13 +16,11 @@ export declare function getListQuery<TTable extends BaseTable, TSelection extend
|
|
|
16
16
|
relations?: GetListRelations;
|
|
17
17
|
table: TTable;
|
|
18
18
|
}): {
|
|
19
|
-
countQuery: Omit<import("drizzle-orm/pg-core").PgSelectBase<
|
|
19
|
+
countQuery: Omit<import("drizzle-orm/pg-core").PgSelectBase<string, {
|
|
20
20
|
count: SQL<unknown>;
|
|
21
|
-
}, "partial",
|
|
21
|
+
}, "partial", Record<string, "not-null">, false, "where", {
|
|
22
22
|
count: unknown;
|
|
23
|
-
}
|
|
24
|
-
count: unknown;
|
|
25
|
-
})[], {
|
|
23
|
+
}[], {
|
|
26
24
|
count: import("drizzle-orm").DrizzleTypeError<"You cannot reference this field without assigning it an alias first - use `.as(<alias>)`">;
|
|
27
25
|
}>, "where">;
|
|
28
26
|
query: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const transformBody:
|
|
1
|
+
export declare const transformBody: <T extends Record<string, unknown>>(body: T) => T;
|
|
@@ -36,7 +36,9 @@ var import_dayjs = __toESM(require("dayjs"));
|
|
|
36
36
|
var transformBody = (body) => {
|
|
37
37
|
for (const key in body) {
|
|
38
38
|
if (key.endsWith("At")) {
|
|
39
|
-
body[key] = (0, import_dayjs.default)(
|
|
39
|
+
body[key] = (0, import_dayjs.default)(
|
|
40
|
+
body[key]
|
|
41
|
+
).toDate();
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
44
|
return body;
|
|
@@ -10,8 +10,8 @@ export interface DeleteOperationOptions<TTable extends BaseTable> {
|
|
|
10
10
|
byCreator?: boolean;
|
|
11
11
|
}
|
|
12
12
|
export declare const createDeleteOperation: ({ db, getSession, }: {
|
|
13
|
-
db: NodePgDatabase<
|
|
13
|
+
db: NodePgDatabase<Record<string, unknown>>;
|
|
14
14
|
getSession: (req: NextRequest) => Promise<{
|
|
15
15
|
userId?: string;
|
|
16
16
|
} | undefined>;
|
|
17
|
-
}) => <TTable extends BaseTable>({ table, summary, onSuccess, onError, byCreator, }: DeleteOperationOptions<TTable>) =>
|
|
17
|
+
}) => <TTable extends BaseTable>({ table, summary, onSuccess, onError, byCreator, }: DeleteOperationOptions<TTable>) => import("next-rest-framework").RouteOperationDefinition<"DELETE">;
|
|
@@ -22,8 +22,8 @@ export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchem
|
|
|
22
22
|
onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
23
23
|
}
|
|
24
24
|
export declare const createGetListOperation: ({ db, getSession, }: {
|
|
25
|
-
db: NodePgDatabase<
|
|
25
|
+
db: NodePgDatabase<Record<string, unknown>>;
|
|
26
26
|
getSession: (req: NextRequest) => Promise<{
|
|
27
27
|
userId?: string;
|
|
28
28
|
} | undefined>;
|
|
29
|
-
}) => <T extends z.ZodType<
|
|
29
|
+
}) => <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, Q extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, TTable extends BaseTable>({ querySchema, bodySchema, table, summary, relations, jsonArrayFields, setParams, onSuccess, onError, byCreator, }: GetListOperationOptions<T, Q, TTable>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
@@ -66,7 +66,9 @@ var createGetListOperation = ({
|
|
|
66
66
|
}
|
|
67
67
|
]).handler(async (req) => {
|
|
68
68
|
try {
|
|
69
|
-
const params = await (setParams == null ? void 0 : setParams(
|
|
69
|
+
const params = await (setParams == null ? void 0 : setParams(
|
|
70
|
+
req
|
|
71
|
+
)) || {};
|
|
70
72
|
if (byCreator) {
|
|
71
73
|
const { userId } = await getSession(req) || {};
|
|
72
74
|
params.creatorId = userId;
|
|
@@ -86,7 +88,10 @@ var createGetListOperation = ({
|
|
|
86
88
|
if (onSuccess) {
|
|
87
89
|
result = await onSuccess(result);
|
|
88
90
|
}
|
|
89
|
-
return import_next_rest_framework.TypedNextResponse.json(
|
|
91
|
+
return import_next_rest_framework.TypedNextResponse.json(
|
|
92
|
+
result,
|
|
93
|
+
{ status: 200 }
|
|
94
|
+
);
|
|
90
95
|
} catch (e) {
|
|
91
96
|
const response = await (onError == null ? void 0 : onError(e));
|
|
92
97
|
if (response) {
|
|
@@ -8,7 +8,7 @@ export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, T
|
|
|
8
8
|
jsonArrayFields?: string[];
|
|
9
9
|
querySchema: Q;
|
|
10
10
|
relations?: GetListRelations;
|
|
11
|
-
setParams?: (req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string,
|
|
11
|
+
setParams?: (req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string, unknown>>;
|
|
12
12
|
onSuccess?: (data: z.infer<T>) => Promise<z.infer<T>>;
|
|
13
13
|
onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
14
14
|
summary?: string;
|
|
@@ -16,8 +16,8 @@ export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, T
|
|
|
16
16
|
byCreator?: boolean;
|
|
17
17
|
}
|
|
18
18
|
export declare const createGetOperation: ({ getSession, db, }: {
|
|
19
|
-
db: NodePgDatabase<
|
|
19
|
+
db: NodePgDatabase<Record<string, unknown>>;
|
|
20
20
|
getSession: (req: NextRequest) => Promise<{
|
|
21
21
|
userId?: string;
|
|
22
22
|
} | undefined>;
|
|
23
|
-
}) => <T extends z.ZodType<
|
|
23
|
+
}) => <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, Q extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, TTable extends BaseTable>({ querySchema, bodySchema, table, summary, relations, setParams, jsonArrayFields, onSuccess, onError, byCreator, }: GetOperationOptions<T, Q, TTable>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
@@ -65,12 +65,14 @@ var createGetOperation = ({
|
|
|
65
65
|
}
|
|
66
66
|
]).handler(async (req) => {
|
|
67
67
|
try {
|
|
68
|
-
const params = await (setParams == null ? void 0 : setParams(
|
|
68
|
+
const params = await (setParams == null ? void 0 : setParams(
|
|
69
|
+
req
|
|
70
|
+
)) || {};
|
|
69
71
|
if (byCreator) {
|
|
70
72
|
const { userId } = await getSession(req) || {};
|
|
71
73
|
params.creatorId = userId;
|
|
72
74
|
}
|
|
73
|
-
|
|
75
|
+
const rawResult = await (0, import_actions.createGetAction)({
|
|
74
76
|
bodySchema,
|
|
75
77
|
db,
|
|
76
78
|
jsonArrayFields,
|
|
@@ -81,7 +83,8 @@ var createGetOperation = ({
|
|
|
81
83
|
Object.fromEntries(new URL(req.url).searchParams),
|
|
82
84
|
params
|
|
83
85
|
)
|
|
84
|
-
)
|
|
86
|
+
);
|
|
87
|
+
let result = rawResult ?? {};
|
|
85
88
|
if (onSuccess) {
|
|
86
89
|
result = await onSuccess(result);
|
|
87
90
|
}
|
|
@@ -13,8 +13,8 @@ export interface PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema
|
|
|
13
13
|
table: TTable;
|
|
14
14
|
}
|
|
15
15
|
export declare const createPostOperation: ({ getSession, db, }: {
|
|
16
|
-
db: NodePgDatabase<
|
|
16
|
+
db: NodePgDatabase<Record<string, unknown>>;
|
|
17
17
|
getSession: (req: NextRequest) => Promise<{
|
|
18
18
|
userId?: string;
|
|
19
19
|
} | undefined>;
|
|
20
|
-
}) => <IB extends z.ZodType<
|
|
20
|
+
}) => <IB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, TTable extends PgTable<import("drizzle-orm/pg-core").TableConfig>>({ bodySchema, outputBodySchema, setBody, summary, table, onSuccess, onError, }: PostOperationOptions<IB, OB, TTable>) => import("next-rest-framework").RouteOperationDefinition<"POST">;
|
|
@@ -67,15 +67,15 @@ var createPostOperation = ({
|
|
|
67
67
|
const { userId } = await getSession(req) || {};
|
|
68
68
|
const body = Object.assign(
|
|
69
69
|
await req.json(),
|
|
70
|
-
await (setBody == null ? void 0 : setBody(
|
|
70
|
+
await (setBody == null ? void 0 : setBody(
|
|
71
|
+
req
|
|
72
|
+
)) || {}
|
|
71
73
|
);
|
|
72
|
-
|
|
74
|
+
const [raw] = await (0, import_actions.createPostAction)({ bodySchema, db, table })({
|
|
73
75
|
creatorId: userId,
|
|
74
76
|
...body
|
|
75
77
|
});
|
|
76
|
-
|
|
77
|
-
data = await onSuccess(data);
|
|
78
|
-
}
|
|
78
|
+
const data = onSuccess ? await onSuccess(raw) : raw;
|
|
79
79
|
return import_next_rest_framework.TypedNextResponse.json(data, { status: 200 });
|
|
80
80
|
} catch (e) {
|
|
81
81
|
const response = await (onError == null ? void 0 : onError(e));
|
|
@@ -18,5 +18,5 @@ export declare const createPutOperation: ({ getSession, db, }: {
|
|
|
18
18
|
getSession: (req: NextRequest) => Promise<{
|
|
19
19
|
userId?: string;
|
|
20
20
|
} | undefined>;
|
|
21
|
-
db: NodePgDatabase<
|
|
22
|
-
}) => <IB extends z.ZodType<
|
|
21
|
+
db: NodePgDatabase<Record<string, unknown>>;
|
|
22
|
+
}) => <IB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, TTable extends BaseTable>({ bodySchema, outputBodySchema, table, summary, setBody, onSuccess, byCreator, onError, }: PutOperationOptions<IB, OB, TTable>) => import("next-rest-framework").RouteOperationDefinition<"PUT">;
|
|
@@ -68,9 +68,11 @@ var createPutOperation = ({
|
|
|
68
68
|
const { userId } = await getSession(req) || {};
|
|
69
69
|
const body = Object.assign(
|
|
70
70
|
await req.json(),
|
|
71
|
-
await (setBody == null ? void 0 : setBody(
|
|
71
|
+
await (setBody == null ? void 0 : setBody(
|
|
72
|
+
req
|
|
73
|
+
)) || {}
|
|
72
74
|
);
|
|
73
|
-
|
|
75
|
+
const raw = await (0, import_actions.createPutAction)({
|
|
74
76
|
bodySchema,
|
|
75
77
|
table,
|
|
76
78
|
db
|
|
@@ -81,9 +83,7 @@ var createPutOperation = ({
|
|
|
81
83
|
},
|
|
82
84
|
{ byCreator }
|
|
83
85
|
);
|
|
84
|
-
|
|
85
|
-
data = await onSuccess(data);
|
|
86
|
-
}
|
|
86
|
+
const data = onSuccess ? await onSuccess(raw) : raw;
|
|
87
87
|
return import_next_rest_framework.TypedNextResponse.json(data, { status: 200 });
|
|
88
88
|
} catch (e) {
|
|
89
89
|
const response = await (onError == null ? void 0 : onError(e));
|