@ai0x0/utils 0.0.46 → 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 -18
- package/es/backend/route-operation/delete-operation.js +10 -122
- package/es/backend/route-operation/get-list-operation.d.ts +5 -27
- package/es/backend/route-operation/get-list-operation.js +10 -135
- package/es/backend/route-operation/get-operation.d.ts +5 -21
- package/es/backend/route-operation/get-operation.js +10 -132
- 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 -20
- package/es/backend/sqlite/route-operation/delete-operation.js +10 -122
- package/es/backend/sqlite/route-operation/get-list-operation.d.ts +6 -28
- package/es/backend/sqlite/route-operation/get-list-operation.js +10 -135
- package/es/backend/sqlite/route-operation/get-operation.d.ts +6 -22
- package/es/backend/sqlite/route-operation/get-operation.js +10 -132
- 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/es/backend/sqlite/schemas/index.d.ts +69 -5
- package/es/backend/sqlite/schemas/index.js +0 -1
- package/lib/__shims__/next-rest-framework.d.ts +2 -0
- package/lib/backend/route-operation/delete-operation.d.ts +7 -18
- package/lib/backend/route-operation/delete-operation.js +7 -52
- package/lib/backend/route-operation/get-list-operation.d.ts +5 -27
- package/lib/backend/route-operation/get-list-operation.js +7 -68
- package/lib/backend/route-operation/get-operation.d.ts +5 -21
- package/lib/backend/route-operation/get-operation.js +7 -67
- 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 -20
- package/lib/backend/sqlite/route-operation/delete-operation.js +7 -52
- package/lib/backend/sqlite/route-operation/get-list-operation.d.ts +6 -28
- package/lib/backend/sqlite/route-operation/get-list-operation.js +7 -71
- package/lib/backend/sqlite/route-operation/get-operation.d.ts +6 -22
- package/lib/backend/sqlite/route-operation/get-operation.js +7 -67
- 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/lib/backend/sqlite/schemas/index.d.ts +69 -5
- package/package.json +1 -1
|
@@ -32,62 +32,17 @@ __export(delete_operation_exports, {
|
|
|
32
32
|
createDeleteOperation: () => createDeleteOperation
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(delete_operation_exports);
|
|
35
|
-
var
|
|
36
|
-
var import_zod = require("zod");
|
|
35
|
+
var import_create_delete_action = require("../actions/create-delete-action");
|
|
37
36
|
var import_get_table_name = __toESM(require("./get-table-name"));
|
|
38
|
-
var
|
|
39
|
-
var
|
|
37
|
+
var import_operation_core = require("./operation-core");
|
|
38
|
+
var createOperation = (0, import_operation_core.createDeleteOperationFactory)({
|
|
39
|
+
createAction: import_create_delete_action.createDeleteAction,
|
|
40
|
+
getTableName: import_get_table_name.default
|
|
41
|
+
});
|
|
40
42
|
var createDeleteOperation = ({
|
|
41
43
|
db,
|
|
42
44
|
getSession
|
|
43
|
-
}) => ({
|
|
44
|
-
table,
|
|
45
|
-
description,
|
|
46
|
-
summary,
|
|
47
|
-
tags,
|
|
48
|
-
onSuccess,
|
|
49
|
-
onError,
|
|
50
|
-
byCreator = true
|
|
51
|
-
}) => (0, import_next_rest_framework.routeOperation)({
|
|
52
|
-
method: "DELETE",
|
|
53
|
-
openApiOperation: {
|
|
54
|
-
description,
|
|
55
|
-
summary,
|
|
56
|
-
tags: tags ?? (table ? [(0, import_get_table_name.default)(table)] : [])
|
|
57
|
-
}
|
|
58
|
-
}).input({
|
|
59
|
-
body: import_zod.z.object({
|
|
60
|
-
id: import_zod.z.string()
|
|
61
|
-
}),
|
|
62
|
-
contentType: "application/json"
|
|
63
|
-
}).handler(async (req) => {
|
|
64
|
-
try {
|
|
65
|
-
const body = await req.json();
|
|
66
|
-
if (byCreator) {
|
|
67
|
-
const { userId } = await getSession(req) || {};
|
|
68
|
-
body.creatorId = userId;
|
|
69
|
-
}
|
|
70
|
-
const data = table && db ? await (0, import_actions.createDeleteAction)({ table, db })(body) : body;
|
|
71
|
-
await (onSuccess == null ? void 0 : onSuccess({ data, params: body }));
|
|
72
|
-
return import_next_rest_framework.TypedNextResponse.json(data, {
|
|
73
|
-
status: 200
|
|
74
|
-
});
|
|
75
|
-
} catch (e) {
|
|
76
|
-
if (!(e instanceof import_errors.HttpError)) {
|
|
77
|
-
console.error(e);
|
|
78
|
-
}
|
|
79
|
-
const response = await (onError == null ? void 0 : onError(e));
|
|
80
|
-
if (response) {
|
|
81
|
-
return response;
|
|
82
|
-
}
|
|
83
|
-
if (e instanceof import_errors.HttpError) {
|
|
84
|
-
return import_next_rest_framework.TypedNextResponse.json({ message: e.message }, {
|
|
85
|
-
status: e.status
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
throw e;
|
|
89
|
-
}
|
|
90
|
-
});
|
|
45
|
+
}) => createOperation({ db, getSession });
|
|
91
46
|
// Annotate the CommonJS export names for ESM import in node:
|
|
92
47
|
0 && (module.exports = {
|
|
93
48
|
createDeleteOperation
|
|
@@ -1,34 +1,12 @@
|
|
|
1
|
-
import { z, ZodSchema } from "zod";
|
|
2
|
-
import { NextRequest } from "next/server";
|
|
3
|
-
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
4
1
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
2
|
+
import { NextRequest } from "next/server";
|
|
3
|
+
import { ZodSchema } from "zod";
|
|
5
4
|
import { BaseTable, GetListRelations } from "../types.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
jsonArrayFields?: string[];
|
|
9
|
-
querySchema: Q;
|
|
10
|
-
relations?: GetListRelations;
|
|
11
|
-
setParams?(req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>): Promise<Record<string, unknown>>;
|
|
12
|
-
byCreator?: boolean;
|
|
13
|
-
description?: string;
|
|
14
|
-
summary?: string;
|
|
15
|
-
tags?: string[];
|
|
16
|
-
table?: TTable;
|
|
17
|
-
onSuccess?<D extends T>(payload: {
|
|
18
|
-
params: Partial<z.infer<T>> & Record<string, unknown>;
|
|
19
|
-
data: {
|
|
20
|
-
data: z.infer<D>[];
|
|
21
|
-
total: number;
|
|
22
|
-
};
|
|
23
|
-
}): Promise<{
|
|
24
|
-
data: z.infer<T>[];
|
|
25
|
-
total: number;
|
|
26
|
-
}>;
|
|
27
|
-
onError?(error: Error): Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
28
|
-
}
|
|
5
|
+
import { type GetListOperationOptions as CoreGetListOperationOptions } from "./operation-core.js";
|
|
6
|
+
export type GetListOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> = CoreGetListOperationOptions<T, Q, TTable, GetListRelations>;
|
|
29
7
|
export declare const createGetListOperation: ({ db, getSession, }: {
|
|
30
8
|
db?: NodePgDatabase<Record<string, unknown>> | undefined;
|
|
31
9
|
getSession(req: NextRequest): Promise<{
|
|
32
10
|
userId?: string;
|
|
33
11
|
} | undefined>;
|
|
34
|
-
}) => <T extends
|
|
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>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
@@ -32,78 +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
36
|
var import_get_table_name = __toESM(require("./get-table-name"));
|
|
37
|
-
var
|
|
38
|
-
var
|
|
37
|
+
var import_operation_core = require("./operation-core");
|
|
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 params = await (setParams == null ? void 0 : setParams(
|
|
73
|
-
req
|
|
74
|
-
)) || {};
|
|
75
|
-
if (byCreator) {
|
|
76
|
-
const { userId } = await getSession(req) || {};
|
|
77
|
-
params.creatorId = userId;
|
|
78
|
-
}
|
|
79
|
-
const mergedParams = Object.assign(
|
|
80
|
-
Object.fromEntries(new URL(req.url).searchParams),
|
|
81
|
-
params
|
|
82
|
-
);
|
|
83
|
-
let result = table && db ? await (0, import_actions.createGetListAction)({
|
|
84
|
-
bodySchema,
|
|
85
|
-
db,
|
|
86
|
-
jsonArrayFields,
|
|
87
|
-
relations,
|
|
88
|
-
table
|
|
89
|
-
})(mergedParams) : { data: [], total: 0 };
|
|
90
|
-
if (onSuccess) {
|
|
91
|
-
result = await onSuccess({ data: result, params: mergedParams });
|
|
92
|
-
}
|
|
93
|
-
return import_next_rest_framework.TypedNextResponse.json(
|
|
94
|
-
result,
|
|
95
|
-
{ status: 200 }
|
|
96
|
-
);
|
|
97
|
-
} catch (e) {
|
|
98
|
-
console.error(e);
|
|
99
|
-
const response = await (onError == null ? void 0 : onError(e));
|
|
100
|
-
if (response) {
|
|
101
|
-
return response;
|
|
102
|
-
} else {
|
|
103
|
-
throw e;
|
|
104
|
-
}
|
|
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
|
createGetListOperation
|
|
@@ -1,28 +1,12 @@
|
|
|
1
|
-
import { z, ZodSchema } from "zod";
|
|
2
|
-
import { NextRequest } from "next/server";
|
|
3
|
-
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
4
1
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
2
|
+
import { NextRequest } from "next/server";
|
|
3
|
+
import { ZodSchema } from "zod";
|
|
5
4
|
import { BaseTable, GetListRelations } from "../types.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
jsonArrayFields?: string[];
|
|
9
|
-
querySchema: Q;
|
|
10
|
-
relations?: GetListRelations;
|
|
11
|
-
setParams?(req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>): Promise<Record<string, unknown>>;
|
|
12
|
-
onSuccess?(payload: {
|
|
13
|
-
params: Partial<z.infer<T>> & Record<string, unknown>;
|
|
14
|
-
data: z.infer<T>;
|
|
15
|
-
}): Promise<z.infer<T>>;
|
|
16
|
-
onError?(error: Error): Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
17
|
-
description?: string;
|
|
18
|
-
summary?: string;
|
|
19
|
-
tags?: string[];
|
|
20
|
-
table?: TTable;
|
|
21
|
-
byCreator?: boolean;
|
|
22
|
-
}
|
|
5
|
+
import { type GetOperationOptions as CoreGetOperationOptions } from "./operation-core.js";
|
|
6
|
+
export type GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> = CoreGetOperationOptions<T, Q, TTable, GetListRelations>;
|
|
23
7
|
export declare const createGetOperation: ({ getSession, db, }: {
|
|
24
8
|
db?: NodePgDatabase<Record<string, unknown>> | undefined;
|
|
25
9
|
getSession(req: NextRequest): Promise<{
|
|
26
10
|
userId?: string;
|
|
27
11
|
} | undefined>;
|
|
28
|
-
}) => <T extends
|
|
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>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
@@ -32,77 +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
36
|
var import_get_table_name = __toESM(require("./get-table-name"));
|
|
37
|
-
var
|
|
37
|
+
var import_operation_core = require("./operation-core");
|
|
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 params = await (setParams == null ? void 0 : setParams(
|
|
72
|
-
req
|
|
73
|
-
)) || {};
|
|
74
|
-
if (byCreator) {
|
|
75
|
-
const { userId } = await getSession(req) || {};
|
|
76
|
-
params.creatorId = userId;
|
|
77
|
-
}
|
|
78
|
-
const mergedParams = Object.assign(
|
|
79
|
-
Object.fromEntries(new URL(req.url).searchParams),
|
|
80
|
-
params
|
|
81
|
-
);
|
|
82
|
-
const rawResult = table && db ? await (0, import_actions.createGetAction)({
|
|
83
|
-
bodySchema,
|
|
84
|
-
db,
|
|
85
|
-
jsonArrayFields,
|
|
86
|
-
relations,
|
|
87
|
-
table
|
|
88
|
-
})(mergedParams) : mergedParams;
|
|
89
|
-
let result = rawResult ?? {};
|
|
90
|
-
if (onSuccess) {
|
|
91
|
-
result = await onSuccess({ data: result, params: mergedParams });
|
|
92
|
-
}
|
|
93
|
-
return import_next_rest_framework.TypedNextResponse.json(result, {
|
|
94
|
-
status: 200
|
|
95
|
-
});
|
|
96
|
-
} catch (e) {
|
|
97
|
-
console.error(e);
|
|
98
|
-
const response = await (onError == null ? void 0 : onError(e));
|
|
99
|
-
if (response) {
|
|
100
|
-
return response;
|
|
101
|
-
} else {
|
|
102
|
-
throw e;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
});
|
|
45
|
+
}) => createOperation({ db, getSession });
|
|
106
46
|
// Annotate the CommonJS export names for ESM import in node:
|
|
107
47
|
0 && (module.exports = {
|
|
108
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("./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("./open-api-operation")
|
|
31
33
|
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { routeOperation } from "next-rest-framework";
|
|
2
|
+
export type RouteOpenApiOperation = NonNullable<Parameters<typeof routeOperation>[0]["openApiOperation"]>;
|
|
3
|
+
export declare function createOpenApiOperation({ defaultTags, openApiOperation, }: {
|
|
4
|
+
defaultTags: string[];
|
|
5
|
+
openApiOperation?: RouteOpenApiOperation;
|
|
6
|
+
}): RouteOpenApiOperation;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/backend/route-operation/open-api-operation.ts
|
|
20
|
+
var open_api_operation_exports = {};
|
|
21
|
+
__export(open_api_operation_exports, {
|
|
22
|
+
createOpenApiOperation: () => createOpenApiOperation
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(open_api_operation_exports);
|
|
25
|
+
function createOpenApiOperation({
|
|
26
|
+
defaultTags,
|
|
27
|
+
openApiOperation
|
|
28
|
+
}) {
|
|
29
|
+
return {
|
|
30
|
+
tags: defaultTags,
|
|
31
|
+
...openApiOperation
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
createOpenApiOperation
|
|
37
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { NextRequest } from "next/server";
|
|
2
|
+
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
3
|
+
import { z, ZodSchema } from "zod";
|
|
4
|
+
export type JsonResponse = ReturnType<(typeof TypedNextResponse)["json"]>;
|
|
5
|
+
export type RouteCatch = (error: Error) => Promise<JsonResponse | undefined>;
|
|
6
|
+
export type SessionGetter = (req: NextRequest) => Promise<{
|
|
7
|
+
userId?: string;
|
|
8
|
+
} | undefined>;
|
|
9
|
+
export type ActionFactory<TTable, TAction> = (_options: {
|
|
10
|
+
bodySchema?: ZodSchema;
|
|
11
|
+
db: unknown;
|
|
12
|
+
jsonArrayFields?: string[];
|
|
13
|
+
relations?: unknown;
|
|
14
|
+
table: TTable;
|
|
15
|
+
}) => TAction;
|
|
16
|
+
export declare function handleOperationError(error: unknown, catchHandler?: RouteCatch): Promise<Response>;
|
|
17
|
+
export declare function readPostBody(req: NextRequest, { contentType, parseBody, }: {
|
|
18
|
+
contentType: string;
|
|
19
|
+
parseBody?: (_req: NextRequest) => Promise<Record<string, unknown>>;
|
|
20
|
+
}): Promise<Record<string, unknown>>;
|
|
21
|
+
export declare function getDefaultTags<TTable>({ getTableName, table, }: {
|
|
22
|
+
getTableName(table: TTable): string;
|
|
23
|
+
table?: TTable;
|
|
24
|
+
}): string[];
|
|
25
|
+
export type GetOperationParams<Q extends ZodSchema> = z.infer<Q> & Record<string, unknown> & {
|
|
26
|
+
creatorId?: string;
|
|
27
|
+
};
|
|
28
|
+
export declare function getReadParams<Q extends ZodSchema>({ access, getSession, req, schemas, setParams, }: {
|
|
29
|
+
access?: {
|
|
30
|
+
byCreator?: boolean;
|
|
31
|
+
};
|
|
32
|
+
getSession: SessionGetter;
|
|
33
|
+
req: NextRequest;
|
|
34
|
+
schemas: {
|
|
35
|
+
query: Q;
|
|
36
|
+
};
|
|
37
|
+
setParams?: (_req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string, unknown>>;
|
|
38
|
+
}): Promise<GetOperationParams<Q>>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/backend/route-operation/operation-common.ts
|
|
20
|
+
var operation_common_exports = {};
|
|
21
|
+
__export(operation_common_exports, {
|
|
22
|
+
getDefaultTags: () => getDefaultTags,
|
|
23
|
+
getReadParams: () => getReadParams,
|
|
24
|
+
handleOperationError: () => handleOperationError,
|
|
25
|
+
readPostBody: () => readPostBody
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(operation_common_exports);
|
|
28
|
+
var import_next_rest_framework = require("next-rest-framework");
|
|
29
|
+
function isHttpLikeError(error) {
|
|
30
|
+
return error instanceof Error && error.name === "HttpError" && typeof error.status === "number";
|
|
31
|
+
}
|
|
32
|
+
async function handleOperationError(error, catchHandler) {
|
|
33
|
+
if (!isHttpLikeError(error)) {
|
|
34
|
+
console.error(error);
|
|
35
|
+
}
|
|
36
|
+
const response = await (catchHandler == null ? void 0 : catchHandler(error));
|
|
37
|
+
if (response) {
|
|
38
|
+
return response;
|
|
39
|
+
}
|
|
40
|
+
if (isHttpLikeError(error)) {
|
|
41
|
+
return import_next_rest_framework.TypedNextResponse.json({ message: error.message }, {
|
|
42
|
+
status: error.status
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
async function readPostBody(req, {
|
|
48
|
+
contentType,
|
|
49
|
+
parseBody
|
|
50
|
+
}) {
|
|
51
|
+
if (parseBody) {
|
|
52
|
+
return parseBody(req);
|
|
53
|
+
}
|
|
54
|
+
if (contentType === "multipart/form-data") {
|
|
55
|
+
return Object.fromEntries(await req.formData());
|
|
56
|
+
}
|
|
57
|
+
return await req.json();
|
|
58
|
+
}
|
|
59
|
+
function getDefaultTags({
|
|
60
|
+
getTableName,
|
|
61
|
+
table
|
|
62
|
+
}) {
|
|
63
|
+
return table ? [getTableName(table)] : [];
|
|
64
|
+
}
|
|
65
|
+
async function getReadParams({
|
|
66
|
+
access,
|
|
67
|
+
getSession,
|
|
68
|
+
req,
|
|
69
|
+
schemas,
|
|
70
|
+
setParams
|
|
71
|
+
}) {
|
|
72
|
+
const extraParams = await (setParams == null ? void 0 : setParams(
|
|
73
|
+
req
|
|
74
|
+
)) || {};
|
|
75
|
+
if ((access == null ? void 0 : access.byCreator) ?? true) {
|
|
76
|
+
const { userId } = await getSession(req) || {};
|
|
77
|
+
extraParams.creatorId = userId;
|
|
78
|
+
}
|
|
79
|
+
const queryParams = schemas.query.parse(
|
|
80
|
+
Object.fromEntries(new URL(req.url).searchParams)
|
|
81
|
+
);
|
|
82
|
+
return { ...queryParams, ...extraParams };
|
|
83
|
+
}
|
|
84
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
+
0 && (module.exports = {
|
|
86
|
+
getDefaultTags,
|
|
87
|
+
getReadParams,
|
|
88
|
+
handleOperationError,
|
|
89
|
+
readPostBody
|
|
90
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/backend/route-operation/operation-core.ts
|
|
17
|
+
var operation_core_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(operation_core_exports);
|
|
19
|
+
__reExport(operation_core_exports, require("./operation-common"), module.exports);
|
|
20
|
+
__reExport(operation_core_exports, require("./read-operation-core"), module.exports);
|
|
21
|
+
__reExport(operation_core_exports, require("./write-operation-core"), module.exports);
|
|
22
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
23
|
+
0 && (module.exports = {
|
|
24
|
+
...require("./operation-common"),
|
|
25
|
+
...require("./read-operation-core"),
|
|
26
|
+
...require("./write-operation-core")
|
|
27
|
+
});
|
|
@@ -1,32 +1,12 @@
|
|
|
1
|
-
import { z, ZodSchema } from "zod";
|
|
2
1
|
import { PgTable } from "drizzle-orm/pg-core";
|
|
3
|
-
import { NextRequest } from "next/server";
|
|
4
|
-
import { TypedNextResponse } from "next-rest-framework";
|
|
5
2
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
export
|
|
10
|
-
bodySchema: IB;
|
|
11
|
-
contentType?: string;
|
|
12
|
-
description?: string;
|
|
13
|
-
outputBodySchema?: OB;
|
|
14
|
-
parseBody?(req: NextRequest): Promise<Record<string, unknown>>;
|
|
15
|
-
setBody?(req: NextRequest): Promise<Partial<z.infer<IB>>>;
|
|
16
|
-
summary?: string;
|
|
17
|
-
tags?: string[];
|
|
18
|
-
onSuccess?(payload: {
|
|
19
|
-
params: PostOperationParams<IB>;
|
|
20
|
-
data: z.infer<OB>;
|
|
21
|
-
req: NextRequest;
|
|
22
|
-
}): Promise<z.infer<OB>>;
|
|
23
|
-
onError?(error: Error): Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
24
|
-
table?: TTable;
|
|
25
|
-
}
|
|
3
|
+
import { NextRequest } from "next/server";
|
|
4
|
+
import { ZodSchema } from "zod";
|
|
5
|
+
import { type PostOperationOptions as CorePostOperationOptions } from "./operation-core.js";
|
|
6
|
+
export type PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends PgTable> = CorePostOperationOptions<IB, OB, TTable>;
|
|
26
7
|
export declare const createPostOperation: ({ getSession, db, }: {
|
|
27
8
|
db?: NodePgDatabase<Record<string, unknown>> | undefined;
|
|
28
9
|
getSession(req: NextRequest): Promise<{
|
|
29
10
|
userId?: string;
|
|
30
11
|
} | undefined>;
|
|
31
|
-
}) => <IB extends
|
|
32
|
-
export {};
|
|
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, contentType, openApiOperation, parseBody, setBody, table, handler, catch: catchHandler, }: CorePostOperationOptions<IB, OB, PgTable<import("drizzle-orm/pg-core").TableConfig>>) => import("next-rest-framework").RouteOperationDefinition<"POST">;
|