@ai0x0/utils 0.0.47 → 0.0.48
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 +40 -38
- package/SKILL.md +39 -37
- package/es/__shims__/next-rest-framework.d.ts +2 -0
- package/es/backend/route-operation/delete-operation.d.ts +7 -24
- package/es/backend/route-operation/delete-operation.js +9 -127
- package/es/backend/route-operation/get-list-operation.d.ts +5 -31
- package/es/backend/route-operation/get-list-operation.js +10 -142
- package/es/backend/route-operation/get-operation.d.ts +5 -25
- package/es/backend/route-operation/get-operation.js +10 -139
- package/es/backend/route-operation/get-table-name.js +0 -2
- package/es/backend/route-operation/index.d.ts +1 -0
- package/es/backend/route-operation/index.js +2 -1
- package/es/backend/route-operation/open-api-operation.d.ts +6 -0
- package/es/backend/route-operation/open-api-operation.js +13 -0
- package/es/backend/route-operation/operation-common.d.ts +38 -0
- package/es/backend/route-operation/operation-common.js +148 -0
- package/es/backend/route-operation/operation-core.d.ts +3 -0
- package/es/backend/route-operation/operation-core.js +3 -0
- package/es/backend/route-operation/post-operation.d.ts +5 -25
- package/es/backend/route-operation/post-operation.js +13 -189
- package/es/backend/route-operation/put-operation.d.ts +4 -23
- package/es/backend/route-operation/put-operation.js +10 -155
- package/es/backend/route-operation/read-operation-core.d.ts +55 -0
- package/es/backend/route-operation/read-operation-core.js +224 -0
- package/es/backend/route-operation/write-operation-core.d.ts +94 -0
- package/es/backend/route-operation/write-operation-core.js +390 -0
- package/es/backend/sqlite/route-operation/delete-operation.d.ts +9 -26
- package/es/backend/sqlite/route-operation/delete-operation.js +9 -127
- package/es/backend/sqlite/route-operation/get-list-operation.d.ts +6 -32
- package/es/backend/sqlite/route-operation/get-list-operation.js +10 -142
- package/es/backend/sqlite/route-operation/get-operation.d.ts +6 -26
- package/es/backend/sqlite/route-operation/get-operation.js +10 -139
- package/es/backend/sqlite/route-operation/index.d.ts +1 -0
- package/es/backend/sqlite/route-operation/index.js +2 -1
- package/es/backend/sqlite/route-operation/post-operation.d.ts +6 -26
- package/es/backend/sqlite/route-operation/post-operation.js +13 -189
- package/es/backend/sqlite/route-operation/put-operation.d.ts +6 -25
- package/es/backend/sqlite/route-operation/put-operation.js +10 -155
- package/lib/__shims__/next-rest-framework.d.ts +2 -0
- package/lib/backend/route-operation/delete-operation.d.ts +7 -24
- package/lib/backend/route-operation/delete-operation.js +6 -56
- package/lib/backend/route-operation/get-list-operation.d.ts +5 -31
- package/lib/backend/route-operation/get-list-operation.js +7 -72
- package/lib/backend/route-operation/get-operation.d.ts +5 -25
- package/lib/backend/route-operation/get-operation.js +7 -71
- package/lib/backend/route-operation/index.d.ts +1 -0
- package/lib/backend/route-operation/index.js +3 -1
- package/lib/backend/route-operation/open-api-operation.d.ts +6 -0
- package/lib/backend/route-operation/open-api-operation.js +37 -0
- package/lib/backend/route-operation/operation-common.d.ts +38 -0
- package/lib/backend/route-operation/operation-common.js +90 -0
- package/lib/backend/route-operation/operation-core.d.ts +3 -0
- package/lib/backend/route-operation/operation-core.js +27 -0
- package/lib/backend/route-operation/post-operation.d.ts +5 -25
- package/lib/backend/route-operation/post-operation.js +7 -71
- package/lib/backend/route-operation/put-operation.d.ts +4 -23
- package/lib/backend/route-operation/put-operation.js +7 -68
- package/lib/backend/route-operation/read-operation-core.d.ts +55 -0
- package/lib/backend/route-operation/read-operation-core.js +151 -0
- package/lib/backend/route-operation/write-operation-core.d.ts +94 -0
- package/lib/backend/route-operation/write-operation-core.js +181 -0
- package/lib/backend/sqlite/route-operation/delete-operation.d.ts +9 -26
- package/lib/backend/sqlite/route-operation/delete-operation.js +6 -56
- package/lib/backend/sqlite/route-operation/get-list-operation.d.ts +6 -32
- package/lib/backend/sqlite/route-operation/get-list-operation.js +7 -75
- package/lib/backend/sqlite/route-operation/get-operation.d.ts +6 -26
- package/lib/backend/sqlite/route-operation/get-operation.js +7 -71
- package/lib/backend/sqlite/route-operation/index.d.ts +1 -0
- package/lib/backend/sqlite/route-operation/index.js +3 -1
- package/lib/backend/sqlite/route-operation/post-operation.d.ts +6 -26
- package/lib/backend/sqlite/route-operation/post-operation.js +7 -71
- package/lib/backend/sqlite/route-operation/put-operation.d.ts +6 -25
- package/lib/backend/sqlite/route-operation/put-operation.js +7 -68
- package/package.json +1 -1
|
@@ -1,37 +1,11 @@
|
|
|
1
|
-
import { z, ZodSchema } from "zod";
|
|
2
1
|
import { NextRequest } from "next/server";
|
|
3
|
-
import {
|
|
2
|
+
import { ZodSchema } from "zod";
|
|
4
3
|
import { BaseTable, GetListRelations } from "../types.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> {
|
|
9
|
-
bodySchema: T;
|
|
10
|
-
jsonArrayFields?: string[];
|
|
11
|
-
querySchema: Q;
|
|
12
|
-
relations?: GetListRelations;
|
|
13
|
-
setParams?: (_req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string, unknown>>;
|
|
14
|
-
byCreator?: boolean;
|
|
15
|
-
description?: string;
|
|
16
|
-
summary?: string;
|
|
17
|
-
tags?: string[];
|
|
18
|
-
table?: TTable;
|
|
19
|
-
onSuccess?: <D extends T>(_payload: {
|
|
20
|
-
params: GetListOperationParams<Q>;
|
|
21
|
-
data: {
|
|
22
|
-
data: z.infer<D>[];
|
|
23
|
-
total: number;
|
|
24
|
-
};
|
|
25
|
-
}) => Promise<{
|
|
26
|
-
data: z.infer<T>[];
|
|
27
|
-
total: number;
|
|
28
|
-
}>;
|
|
29
|
-
onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
30
|
-
}
|
|
4
|
+
import { type GetListOperationOptions as CoreGetListOperationOptions } from "../../route-operation/operation-core.js";
|
|
5
|
+
export type GetListOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> = CoreGetListOperationOptions<T, Q, TTable, GetListRelations>;
|
|
31
6
|
export declare const createGetListOperation: ({ db, getSession, }: {
|
|
32
|
-
db?:
|
|
33
|
-
getSession
|
|
7
|
+
db?: unknown;
|
|
8
|
+
getSession(req: NextRequest): Promise<{
|
|
34
9
|
userId?: string;
|
|
35
10
|
} | undefined>;
|
|
36
|
-
}) => <T extends
|
|
37
|
-
export {};
|
|
11
|
+
}) => <T extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, Q extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, jsonArrayFields, setParams, handler, catch: catchHandler, }: CoreGetListOperationOptions<T, Q, BaseTable, GetListRelations>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
@@ -32,85 +32,17 @@ __export(get_list_operation_exports, {
|
|
|
32
32
|
createGetListOperation: () => createGetListOperation
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(get_list_operation_exports);
|
|
35
|
-
var
|
|
35
|
+
var import_create_get_list_action = require("../actions/create-get-list-action");
|
|
36
|
+
var import_operation_core = require("../../route-operation/operation-core");
|
|
36
37
|
var import_get_table_name = __toESM(require("./get-table-name"));
|
|
37
|
-
var
|
|
38
|
-
|
|
38
|
+
var createOperation = (0, import_operation_core.createGetListOperationFactory)({
|
|
39
|
+
createAction: import_create_get_list_action.createGetListAction,
|
|
40
|
+
getTableName: import_get_table_name.default
|
|
41
|
+
});
|
|
39
42
|
var createGetListOperation = ({
|
|
40
43
|
db,
|
|
41
44
|
getSession
|
|
42
|
-
}) => ({
|
|
43
|
-
querySchema,
|
|
44
|
-
bodySchema,
|
|
45
|
-
table,
|
|
46
|
-
description,
|
|
47
|
-
summary,
|
|
48
|
-
tags,
|
|
49
|
-
relations,
|
|
50
|
-
jsonArrayFields,
|
|
51
|
-
setParams,
|
|
52
|
-
onSuccess,
|
|
53
|
-
onError,
|
|
54
|
-
byCreator = true
|
|
55
|
-
}) => (0, import_next_rest_framework.routeOperation)({
|
|
56
|
-
method: "GET",
|
|
57
|
-
openApiOperation: {
|
|
58
|
-
description,
|
|
59
|
-
summary,
|
|
60
|
-
tags: tags ?? (table ? [(0, import_get_table_name.default)(table)] : [])
|
|
61
|
-
}
|
|
62
|
-
}).input({
|
|
63
|
-
query: querySchema
|
|
64
|
-
}).outputs([
|
|
65
|
-
{
|
|
66
|
-
body: (0, import_schemas.listBodySchema)(bodySchema),
|
|
67
|
-
contentType: "application/json",
|
|
68
|
-
status: 200
|
|
69
|
-
}
|
|
70
|
-
]).handler(async (req) => {
|
|
71
|
-
try {
|
|
72
|
-
const extraParams = await (setParams == null ? void 0 : setParams(
|
|
73
|
-
req
|
|
74
|
-
)) || {};
|
|
75
|
-
if (byCreator) {
|
|
76
|
-
const { userId } = await getSession(req) || {};
|
|
77
|
-
extraParams.creatorId = userId;
|
|
78
|
-
}
|
|
79
|
-
const queryParams = querySchema.parse(
|
|
80
|
-
Object.fromEntries(new URL(req.url).searchParams)
|
|
81
|
-
);
|
|
82
|
-
const mergedParams = {
|
|
83
|
-
...queryParams,
|
|
84
|
-
...extraParams
|
|
85
|
-
};
|
|
86
|
-
const tableParams = mergedParams;
|
|
87
|
-
let result = table && db ? await (0, import_actions.createGetListAction)({
|
|
88
|
-
bodySchema,
|
|
89
|
-
db,
|
|
90
|
-
jsonArrayFields,
|
|
91
|
-
relations,
|
|
92
|
-
table
|
|
93
|
-
})(tableParams) : { data: [], total: 0 };
|
|
94
|
-
if (onSuccess) {
|
|
95
|
-
result = await onSuccess({
|
|
96
|
-
data: result,
|
|
97
|
-
params: mergedParams
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
return import_next_rest_framework.TypedNextResponse.json(
|
|
101
|
-
result,
|
|
102
|
-
{ status: 200 }
|
|
103
|
-
);
|
|
104
|
-
} catch (e) {
|
|
105
|
-
console.error(e);
|
|
106
|
-
const response = await (onError == null ? void 0 : onError(e));
|
|
107
|
-
if (response) {
|
|
108
|
-
return response;
|
|
109
|
-
} else {
|
|
110
|
-
throw e;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
});
|
|
45
|
+
}) => createOperation({ db, getSession });
|
|
114
46
|
// Annotate the CommonJS export names for ESM import in node:
|
|
115
47
|
0 && (module.exports = {
|
|
116
48
|
createGetListOperation
|
|
@@ -1,31 +1,11 @@
|
|
|
1
|
-
import { z, ZodSchema } from "zod";
|
|
2
1
|
import { NextRequest } from "next/server";
|
|
3
|
-
import {
|
|
2
|
+
import { ZodSchema } from "zod";
|
|
4
3
|
import { BaseTable, GetListRelations } from "../types.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> {
|
|
9
|
-
bodySchema: T;
|
|
10
|
-
jsonArrayFields?: string[];
|
|
11
|
-
querySchema: Q;
|
|
12
|
-
relations?: GetListRelations;
|
|
13
|
-
setParams?: (_req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string, unknown>>;
|
|
14
|
-
onSuccess?: (_payload: {
|
|
15
|
-
params: GetOperationParams<Q>;
|
|
16
|
-
data: z.infer<T>;
|
|
17
|
-
}) => Promise<z.infer<T>>;
|
|
18
|
-
onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
19
|
-
description?: string;
|
|
20
|
-
summary?: string;
|
|
21
|
-
tags?: string[];
|
|
22
|
-
table?: TTable;
|
|
23
|
-
byCreator?: boolean;
|
|
24
|
-
}
|
|
4
|
+
import { type GetOperationOptions as CoreGetOperationOptions } from "../../route-operation/operation-core.js";
|
|
5
|
+
export type GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> = CoreGetOperationOptions<T, Q, TTable, GetListRelations>;
|
|
25
6
|
export declare const createGetOperation: ({ getSession, db, }: {
|
|
26
|
-
db?:
|
|
27
|
-
getSession
|
|
7
|
+
db?: unknown;
|
|
8
|
+
getSession(req: NextRequest): Promise<{
|
|
28
9
|
userId?: string;
|
|
29
10
|
} | undefined>;
|
|
30
|
-
}) => <T extends
|
|
31
|
-
export {};
|
|
11
|
+
}) => <T extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, Q extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, setParams, jsonArrayFields, handler, catch: catchHandler, }: CoreGetOperationOptions<T, Q, BaseTable, GetListRelations>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
@@ -32,81 +32,17 @@ __export(get_operation_exports, {
|
|
|
32
32
|
createGetOperation: () => createGetOperation
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(get_operation_exports);
|
|
35
|
-
var
|
|
35
|
+
var import_create_get_action = require("../actions/create-get-action");
|
|
36
|
+
var import_operation_core = require("../../route-operation/operation-core");
|
|
36
37
|
var import_get_table_name = __toESM(require("./get-table-name"));
|
|
37
|
-
var
|
|
38
|
+
var createOperation = (0, import_operation_core.createGetOperationFactory)({
|
|
39
|
+
createAction: import_create_get_action.createGetAction,
|
|
40
|
+
getTableName: import_get_table_name.default
|
|
41
|
+
});
|
|
38
42
|
var createGetOperation = ({
|
|
39
43
|
getSession,
|
|
40
44
|
db
|
|
41
|
-
}) => ({
|
|
42
|
-
querySchema,
|
|
43
|
-
bodySchema,
|
|
44
|
-
table,
|
|
45
|
-
description,
|
|
46
|
-
summary,
|
|
47
|
-
tags,
|
|
48
|
-
relations,
|
|
49
|
-
setParams,
|
|
50
|
-
jsonArrayFields,
|
|
51
|
-
onSuccess,
|
|
52
|
-
onError,
|
|
53
|
-
byCreator = true
|
|
54
|
-
}) => (0, import_next_rest_framework.routeOperation)({
|
|
55
|
-
method: "GET",
|
|
56
|
-
openApiOperation: {
|
|
57
|
-
description,
|
|
58
|
-
summary,
|
|
59
|
-
tags: tags ?? (table ? [(0, import_get_table_name.default)(table)] : [])
|
|
60
|
-
}
|
|
61
|
-
}).input({
|
|
62
|
-
query: querySchema
|
|
63
|
-
}).outputs([
|
|
64
|
-
{
|
|
65
|
-
body: bodySchema,
|
|
66
|
-
contentType: "application/json",
|
|
67
|
-
status: 200
|
|
68
|
-
}
|
|
69
|
-
]).handler(async (req) => {
|
|
70
|
-
try {
|
|
71
|
-
const extraParams = await (setParams == null ? void 0 : setParams(
|
|
72
|
-
req
|
|
73
|
-
)) || {};
|
|
74
|
-
if (byCreator) {
|
|
75
|
-
const { userId } = await getSession(req) || {};
|
|
76
|
-
extraParams.creatorId = userId;
|
|
77
|
-
}
|
|
78
|
-
const queryParams = querySchema.parse(
|
|
79
|
-
Object.fromEntries(new URL(req.url).searchParams)
|
|
80
|
-
);
|
|
81
|
-
const mergedParams = {
|
|
82
|
-
...queryParams,
|
|
83
|
-
...extraParams
|
|
84
|
-
};
|
|
85
|
-
const tableParams = mergedParams;
|
|
86
|
-
const rawResult = table && db ? await (0, import_actions.createGetAction)({
|
|
87
|
-
bodySchema,
|
|
88
|
-
db,
|
|
89
|
-
jsonArrayFields,
|
|
90
|
-
relations,
|
|
91
|
-
table
|
|
92
|
-
})(tableParams) : mergedParams;
|
|
93
|
-
let result = rawResult ?? {};
|
|
94
|
-
if (onSuccess) {
|
|
95
|
-
result = await onSuccess({ data: result, params: mergedParams });
|
|
96
|
-
}
|
|
97
|
-
return import_next_rest_framework.TypedNextResponse.json(result, {
|
|
98
|
-
status: 200
|
|
99
|
-
});
|
|
100
|
-
} catch (e) {
|
|
101
|
-
console.error(e);
|
|
102
|
-
const response = await (onError == null ? void 0 : onError(e));
|
|
103
|
-
if (response) {
|
|
104
|
-
return response;
|
|
105
|
-
} else {
|
|
106
|
-
throw e;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
});
|
|
45
|
+
}) => createOperation({ db, getSession });
|
|
110
46
|
// Annotate the CommonJS export names for ESM import in node:
|
|
111
47
|
0 && (module.exports = {
|
|
112
48
|
createGetOperation
|
|
@@ -21,11 +21,13 @@ __reExport(route_operation_exports, require("./get-list-operation"), module.expo
|
|
|
21
21
|
__reExport(route_operation_exports, require("./delete-operation"), module.exports);
|
|
22
22
|
__reExport(route_operation_exports, require("./post-operation"), module.exports);
|
|
23
23
|
__reExport(route_operation_exports, require("./put-operation"), module.exports);
|
|
24
|
+
__reExport(route_operation_exports, require("../../route-operation/open-api-operation"), module.exports);
|
|
24
25
|
// Annotate the CommonJS export names for ESM import in node:
|
|
25
26
|
0 && (module.exports = {
|
|
26
27
|
...require("./get-operation"),
|
|
27
28
|
...require("./get-list-operation"),
|
|
28
29
|
...require("./delete-operation"),
|
|
29
30
|
...require("./post-operation"),
|
|
30
|
-
...require("./put-operation")
|
|
31
|
+
...require("./put-operation"),
|
|
32
|
+
...require("../../route-operation/open-api-operation")
|
|
31
33
|
});
|
|
@@ -1,31 +1,11 @@
|
|
|
1
|
-
import { z, ZodSchema } from "zod";
|
|
2
1
|
import { SQLiteTable } from "drizzle-orm/sqlite-core";
|
|
3
2
|
import { NextRequest } from "next/server";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
export interface PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends SQLiteTable> {
|
|
9
|
-
bodySchema: IB;
|
|
10
|
-
contentType?: string;
|
|
11
|
-
description?: string;
|
|
12
|
-
outputBodySchema?: OB;
|
|
13
|
-
parseBody?: (_req: NextRequest) => Promise<Record<string, unknown>>;
|
|
14
|
-
setBody?: (_req: NextRequest) => Promise<Partial<z.infer<IB>>>;
|
|
15
|
-
summary?: string;
|
|
16
|
-
tags?: string[];
|
|
17
|
-
onSuccess?: (_payload: {
|
|
18
|
-
params: PostOperationParams<IB>;
|
|
19
|
-
data: z.infer<OB>;
|
|
20
|
-
req: NextRequest;
|
|
21
|
-
}) => Promise<z.infer<OB>>;
|
|
22
|
-
onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
23
|
-
table?: TTable;
|
|
24
|
-
}
|
|
3
|
+
import { ZodSchema } from "zod";
|
|
4
|
+
import { type PostOperationOptions as CorePostOperationOptions } from "../../route-operation/operation-core.js";
|
|
5
|
+
export type PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends SQLiteTable> = CorePostOperationOptions<IB, OB, TTable>;
|
|
25
6
|
export declare const createPostOperation: ({ getSession, db, }: {
|
|
26
|
-
db?:
|
|
27
|
-
getSession
|
|
7
|
+
db?: unknown;
|
|
8
|
+
getSession(req: NextRequest): Promise<{
|
|
28
9
|
userId?: string;
|
|
29
10
|
} | undefined>;
|
|
30
|
-
}) => <IB extends
|
|
31
|
-
export {};
|
|
11
|
+
}) => <IB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, OB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, contentType, openApiOperation, parseBody, setBody, table, handler, catch: catchHandler, }: CorePostOperationOptions<IB, OB, SQLiteTable<import("drizzle-orm/sqlite-core").TableConfig>>) => import("next-rest-framework").RouteOperationDefinition<"POST">;
|
|
@@ -32,81 +32,17 @@ __export(post_operation_exports, {
|
|
|
32
32
|
createPostOperation: () => createPostOperation
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(post_operation_exports);
|
|
35
|
-
var
|
|
36
|
-
var
|
|
35
|
+
var import_create_post_action = require("../actions/create-post-action");
|
|
36
|
+
var import_operation_core = require("../../route-operation/operation-core");
|
|
37
37
|
var import_get_table_name = __toESM(require("./get-table-name"));
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}) {
|
|
43
|
-
if (parseBody) {
|
|
44
|
-
return parseBody(req);
|
|
45
|
-
}
|
|
46
|
-
if (contentType === "multipart/form-data") {
|
|
47
|
-
return Object.fromEntries(await req.formData());
|
|
48
|
-
}
|
|
49
|
-
return await req.json();
|
|
50
|
-
}
|
|
38
|
+
var createOperation = (0, import_operation_core.createPostOperationFactory)({
|
|
39
|
+
createAction: import_create_post_action.createPostAction,
|
|
40
|
+
getTableName: import_get_table_name.default
|
|
41
|
+
});
|
|
51
42
|
var createPostOperation = ({
|
|
52
43
|
getSession,
|
|
53
44
|
db
|
|
54
|
-
}) => ({
|
|
55
|
-
bodySchema,
|
|
56
|
-
contentType = "application/json",
|
|
57
|
-
description,
|
|
58
|
-
outputBodySchema,
|
|
59
|
-
parseBody,
|
|
60
|
-
setBody,
|
|
61
|
-
summary,
|
|
62
|
-
tags,
|
|
63
|
-
table,
|
|
64
|
-
onSuccess,
|
|
65
|
-
onError
|
|
66
|
-
}) => (0, import_next_rest_framework.routeOperation)({
|
|
67
|
-
method: "POST",
|
|
68
|
-
openApiOperation: {
|
|
69
|
-
description,
|
|
70
|
-
summary,
|
|
71
|
-
tags: tags ?? (table ? [(0, import_get_table_name.default)(table)] : [])
|
|
72
|
-
}
|
|
73
|
-
}).input({
|
|
74
|
-
body: bodySchema,
|
|
75
|
-
contentType
|
|
76
|
-
}).outputs([
|
|
77
|
-
{
|
|
78
|
-
body: outputBodySchema || import_zod.z.object({ id: import_zod.z.string() }),
|
|
79
|
-
contentType: "application/json",
|
|
80
|
-
status: 200
|
|
81
|
-
}
|
|
82
|
-
]).handler(async (req) => {
|
|
83
|
-
try {
|
|
84
|
-
const { userId } = await getSession(req) || {};
|
|
85
|
-
const body = await readPostBody(req, { contentType, parseBody });
|
|
86
|
-
const extraBody = await (setBody == null ? void 0 : setBody(req)) || {};
|
|
87
|
-
const mergedBody = { ...body, ...extraBody };
|
|
88
|
-
const params = { creatorId: userId, ...mergedBody };
|
|
89
|
-
const raw = table && db ? (await (0, import_actions.createPostAction)({ bodySchema, db, table })(
|
|
90
|
-
params
|
|
91
|
-
))[0] : params;
|
|
92
|
-
const data = onSuccess ? await onSuccess({
|
|
93
|
-
data: raw,
|
|
94
|
-
params,
|
|
95
|
-
req
|
|
96
|
-
}) : raw;
|
|
97
|
-
return import_next_rest_framework.TypedNextResponse.json(data, {
|
|
98
|
-
status: 200
|
|
99
|
-
});
|
|
100
|
-
} catch (e) {
|
|
101
|
-
console.error(e);
|
|
102
|
-
const response = await (onError == null ? void 0 : onError(e));
|
|
103
|
-
if (response) {
|
|
104
|
-
return response;
|
|
105
|
-
} else {
|
|
106
|
-
throw e;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
});
|
|
45
|
+
}) => createOperation({ db, getSession });
|
|
110
46
|
// Annotate the CommonJS export names for ESM import in node:
|
|
111
47
|
0 && (module.exports = {
|
|
112
48
|
createPostOperation
|
|
@@ -1,30 +1,11 @@
|
|
|
1
|
-
import { z, ZodSchema } from "zod";
|
|
2
1
|
import { SQLiteTable } from "drizzle-orm/sqlite-core";
|
|
3
|
-
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
4
2
|
import { NextRequest } from "next/server";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
export interface PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends SQLiteTable> {
|
|
10
|
-
bodySchema: IB;
|
|
11
|
-
description?: string;
|
|
12
|
-
outputBodySchema?: OB;
|
|
13
|
-
table?: TTable;
|
|
14
|
-
summary?: string;
|
|
15
|
-
tags?: string[];
|
|
16
|
-
setBody?: (_req: TypedNextRequest<"PUT", "application/json", z.infer<IB>>) => Promise<Partial<z.infer<IB>>>;
|
|
17
|
-
onSuccess?: (_payload: {
|
|
18
|
-
params: PutOperationParams<IB>;
|
|
19
|
-
data: z.infer<OB>;
|
|
20
|
-
}) => Promise<z.infer<OB>>;
|
|
21
|
-
onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
22
|
-
byCreator?: boolean;
|
|
23
|
-
}
|
|
3
|
+
import { ZodSchema } from "zod";
|
|
4
|
+
import { type PutOperationOptions as CorePutOperationOptions } from "../../route-operation/operation-core.js";
|
|
5
|
+
export type PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends SQLiteTable> = CorePutOperationOptions<IB, OB, TTable>;
|
|
24
6
|
export declare const createPutOperation: ({ getSession, db, }: {
|
|
25
|
-
getSession
|
|
7
|
+
getSession(req: NextRequest): Promise<{
|
|
26
8
|
userId?: string;
|
|
27
9
|
} | undefined>;
|
|
28
|
-
db?:
|
|
29
|
-
}) => <IB extends
|
|
30
|
-
export {};
|
|
10
|
+
db?: unknown;
|
|
11
|
+
}) => <IB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, OB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, openApiOperation, table, setBody, handler, catch: catchHandler, }: CorePutOperationOptions<IB, OB, SQLiteTable<import("drizzle-orm/sqlite-core").TableConfig>>) => import("next-rest-framework").RouteOperationDefinition<"PUT">;
|
|
@@ -32,78 +32,17 @@ __export(put_operation_exports, {
|
|
|
32
32
|
createPutOperation: () => createPutOperation
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(put_operation_exports);
|
|
35
|
-
var
|
|
36
|
-
var
|
|
35
|
+
var import_create_put_action = require("../actions/create-put-action");
|
|
36
|
+
var import_operation_core = require("../../route-operation/operation-core");
|
|
37
37
|
var import_get_table_name = __toESM(require("./get-table-name"));
|
|
38
|
-
var
|
|
39
|
-
|
|
38
|
+
var createOperation = (0, import_operation_core.createPutOperationFactory)({
|
|
39
|
+
createAction: import_create_put_action.createPutAction,
|
|
40
|
+
getTableName: import_get_table_name.default
|
|
41
|
+
});
|
|
40
42
|
var createPutOperation = ({
|
|
41
43
|
getSession,
|
|
42
44
|
db
|
|
43
|
-
}) => ({
|
|
44
|
-
bodySchema,
|
|
45
|
-
description,
|
|
46
|
-
outputBodySchema,
|
|
47
|
-
table,
|
|
48
|
-
summary,
|
|
49
|
-
tags,
|
|
50
|
-
setBody,
|
|
51
|
-
onSuccess,
|
|
52
|
-
byCreator = true,
|
|
53
|
-
onError
|
|
54
|
-
}) => (0, import_next_rest_framework.routeOperation)({
|
|
55
|
-
method: "PUT",
|
|
56
|
-
openApiOperation: {
|
|
57
|
-
description,
|
|
58
|
-
summary,
|
|
59
|
-
tags: tags ?? (table ? [(0, import_get_table_name.default)(table)] : [])
|
|
60
|
-
}
|
|
61
|
-
}).input({
|
|
62
|
-
body: bodySchema,
|
|
63
|
-
contentType: "application/json"
|
|
64
|
-
}).outputs([
|
|
65
|
-
{
|
|
66
|
-
body: outputBodySchema || import_zod.z.void(),
|
|
67
|
-
status: 200,
|
|
68
|
-
contentType: "application/json"
|
|
69
|
-
}
|
|
70
|
-
]).handler(async (req) => {
|
|
71
|
-
try {
|
|
72
|
-
const { userId } = await getSession(req) || {};
|
|
73
|
-
const body = await req.json();
|
|
74
|
-
const extraBody = await (setBody == null ? void 0 : setBody(
|
|
75
|
-
req
|
|
76
|
-
)) || {};
|
|
77
|
-
const mergedBody = { ...body, ...extraBody };
|
|
78
|
-
const params = { editorId: userId, ...mergedBody };
|
|
79
|
-
const raw = table && db ? await (0, import_actions.createPutAction)({
|
|
80
|
-
bodySchema,
|
|
81
|
-
table,
|
|
82
|
-
db
|
|
83
|
-
})(params, { byCreator }) : params;
|
|
84
|
-
const data = onSuccess ? await onSuccess({
|
|
85
|
-
data: raw,
|
|
86
|
-
params
|
|
87
|
-
}) : raw;
|
|
88
|
-
return import_next_rest_framework.TypedNextResponse.json(data, {
|
|
89
|
-
status: 200
|
|
90
|
-
});
|
|
91
|
-
} catch (e) {
|
|
92
|
-
if (!(e instanceof import_errors.HttpError)) {
|
|
93
|
-
console.error(e);
|
|
94
|
-
}
|
|
95
|
-
const response = await (onError == null ? void 0 : onError(e));
|
|
96
|
-
if (response) {
|
|
97
|
-
return response;
|
|
98
|
-
}
|
|
99
|
-
if (e instanceof import_errors.HttpError) {
|
|
100
|
-
return import_next_rest_framework.TypedNextResponse.json({ message: e.message }, {
|
|
101
|
-
status: e.status
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
throw e;
|
|
105
|
-
}
|
|
106
|
-
});
|
|
45
|
+
}) => createOperation({ db, getSession });
|
|
107
46
|
// Annotate the CommonJS export names for ESM import in node:
|
|
108
47
|
0 && (module.exports = {
|
|
109
48
|
createPutOperation
|