@ai0x0/utils 0.0.47 → 0.0.49
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
|
@@ -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 import_next_rest_framework = require("next-rest-framework");
|
|
35
|
+
var import_create_put_action = require("../actions/create-put-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.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
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { NextRequest } from "next/server";
|
|
2
|
+
import { TypedNextRequest } from "next-rest-framework";
|
|
3
|
+
import { z, ZodSchema } from "zod";
|
|
4
|
+
import { type RouteOpenApiOperation } from "./open-api-operation.js";
|
|
5
|
+
import { ActionFactory, GetOperationParams, RouteCatch, SessionGetter } from "./operation-common.js";
|
|
6
|
+
export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable, TRelations> {
|
|
7
|
+
schemas: {
|
|
8
|
+
query: Q;
|
|
9
|
+
response: T;
|
|
10
|
+
};
|
|
11
|
+
access?: {
|
|
12
|
+
byCreator?: boolean;
|
|
13
|
+
};
|
|
14
|
+
jsonArrayFields?: string[];
|
|
15
|
+
relations?: TRelations;
|
|
16
|
+
setParams?: (_req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string, unknown>>;
|
|
17
|
+
handler?: (_payload: {
|
|
18
|
+
params: GetOperationParams<Q>;
|
|
19
|
+
data: z.infer<T>;
|
|
20
|
+
req: NextRequest;
|
|
21
|
+
}) => Promise<z.infer<T>>;
|
|
22
|
+
catch?: RouteCatch;
|
|
23
|
+
openApiOperation?: RouteOpenApiOperation;
|
|
24
|
+
table?: TTable;
|
|
25
|
+
}
|
|
26
|
+
export declare function createGetOperationFactory<TTable, TRelations>({ createAction, getTableName, }: {
|
|
27
|
+
createAction: ActionFactory<TTable, (_params: Record<string, unknown>) => Promise<unknown | undefined>>;
|
|
28
|
+
getTableName(table: TTable): string;
|
|
29
|
+
}): ({ db, getSession }: {
|
|
30
|
+
db?: unknown;
|
|
31
|
+
getSession: SessionGetter;
|
|
32
|
+
}) => <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, Q extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, setParams, jsonArrayFields, handler, catch: catchHandler, }: GetOperationOptions<T, Q, TTable, TRelations>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
33
|
+
export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable, TRelations> extends Omit<GetOperationOptions<T, Q, TTable, TRelations>, "handler"> {
|
|
34
|
+
handler?: <D extends T>(_payload: {
|
|
35
|
+
params: GetOperationParams<Q>;
|
|
36
|
+
data: {
|
|
37
|
+
data: z.infer<D>[];
|
|
38
|
+
total: number;
|
|
39
|
+
};
|
|
40
|
+
req: NextRequest;
|
|
41
|
+
}) => Promise<{
|
|
42
|
+
data: z.infer<T>[];
|
|
43
|
+
total: number;
|
|
44
|
+
}>;
|
|
45
|
+
}
|
|
46
|
+
export declare function createGetListOperationFactory<TTable, TRelations>({ createAction, getTableName, }: {
|
|
47
|
+
createAction: ActionFactory<TTable, (_params: Record<string, unknown>) => Promise<{
|
|
48
|
+
data: unknown[];
|
|
49
|
+
total: number;
|
|
50
|
+
}>>;
|
|
51
|
+
getTableName(table: TTable): string;
|
|
52
|
+
}): ({ db, getSession }: {
|
|
53
|
+
db?: unknown;
|
|
54
|
+
getSession: SessionGetter;
|
|
55
|
+
}) => <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, Q extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, jsonArrayFields, setParams, handler, catch: catchHandler, }: GetListOperationOptions<T, Q, TTable, TRelations>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
|
|
@@ -0,0 +1,151 @@
|
|
|
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/read-operation-core.ts
|
|
20
|
+
var read_operation_core_exports = {};
|
|
21
|
+
__export(read_operation_core_exports, {
|
|
22
|
+
createGetListOperationFactory: () => createGetListOperationFactory,
|
|
23
|
+
createGetOperationFactory: () => createGetOperationFactory
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(read_operation_core_exports);
|
|
26
|
+
var import_next_rest_framework = require("next-rest-framework");
|
|
27
|
+
var import_schemas = require("../schemas");
|
|
28
|
+
var import_open_api_operation = require("./open-api-operation");
|
|
29
|
+
var import_operation_common = require("./operation-common");
|
|
30
|
+
function createGetOperationFactory({
|
|
31
|
+
createAction,
|
|
32
|
+
getTableName
|
|
33
|
+
}) {
|
|
34
|
+
return ({ db, getSession }) => ({
|
|
35
|
+
schemas,
|
|
36
|
+
access,
|
|
37
|
+
table,
|
|
38
|
+
openApiOperation,
|
|
39
|
+
relations,
|
|
40
|
+
setParams,
|
|
41
|
+
jsonArrayFields,
|
|
42
|
+
handler,
|
|
43
|
+
catch: catchHandler
|
|
44
|
+
}) => (0, import_next_rest_framework.routeOperation)({
|
|
45
|
+
method: "GET",
|
|
46
|
+
openApiOperation: (0, import_open_api_operation.createOpenApiOperation)({
|
|
47
|
+
defaultTags: (0, import_operation_common.getDefaultTags)({ getTableName, table }),
|
|
48
|
+
openApiOperation
|
|
49
|
+
})
|
|
50
|
+
}).input({
|
|
51
|
+
query: schemas.query
|
|
52
|
+
}).outputs([
|
|
53
|
+
{
|
|
54
|
+
body: schemas.response,
|
|
55
|
+
contentType: "application/json",
|
|
56
|
+
status: 200
|
|
57
|
+
}
|
|
58
|
+
]).handler(async (req) => {
|
|
59
|
+
try {
|
|
60
|
+
const mergedParams = await (0, import_operation_common.getReadParams)({
|
|
61
|
+
access,
|
|
62
|
+
getSession,
|
|
63
|
+
req,
|
|
64
|
+
schemas,
|
|
65
|
+
setParams
|
|
66
|
+
});
|
|
67
|
+
const rawResult = table && db ? await createAction({
|
|
68
|
+
bodySchema: schemas.response,
|
|
69
|
+
db,
|
|
70
|
+
jsonArrayFields,
|
|
71
|
+
relations,
|
|
72
|
+
table
|
|
73
|
+
})(mergedParams) : mergedParams;
|
|
74
|
+
let result = rawResult ?? {};
|
|
75
|
+
if (handler) {
|
|
76
|
+
result = await handler({
|
|
77
|
+
data: result,
|
|
78
|
+
params: mergedParams,
|
|
79
|
+
req
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return import_next_rest_framework.TypedNextResponse.json(result, { status: 200 });
|
|
83
|
+
} catch (error) {
|
|
84
|
+
return (0, import_operation_common.handleOperationError)(error, catchHandler);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function createGetListOperationFactory({
|
|
89
|
+
createAction,
|
|
90
|
+
getTableName
|
|
91
|
+
}) {
|
|
92
|
+
return ({ db, getSession }) => ({
|
|
93
|
+
schemas,
|
|
94
|
+
access,
|
|
95
|
+
table,
|
|
96
|
+
openApiOperation,
|
|
97
|
+
relations,
|
|
98
|
+
jsonArrayFields,
|
|
99
|
+
setParams,
|
|
100
|
+
handler,
|
|
101
|
+
catch: catchHandler
|
|
102
|
+
}) => (0, import_next_rest_framework.routeOperation)({
|
|
103
|
+
method: "GET",
|
|
104
|
+
openApiOperation: (0, import_open_api_operation.createOpenApiOperation)({
|
|
105
|
+
defaultTags: (0, import_operation_common.getDefaultTags)({ getTableName, table }),
|
|
106
|
+
openApiOperation
|
|
107
|
+
})
|
|
108
|
+
}).input({
|
|
109
|
+
query: schemas.query
|
|
110
|
+
}).outputs([
|
|
111
|
+
{
|
|
112
|
+
body: (0, import_schemas.listBodySchema)(schemas.response),
|
|
113
|
+
contentType: "application/json",
|
|
114
|
+
status: 200
|
|
115
|
+
}
|
|
116
|
+
]).handler(async (req) => {
|
|
117
|
+
try {
|
|
118
|
+
const mergedParams = await (0, import_operation_common.getReadParams)({
|
|
119
|
+
access,
|
|
120
|
+
getSession,
|
|
121
|
+
req,
|
|
122
|
+
schemas,
|
|
123
|
+
setParams
|
|
124
|
+
});
|
|
125
|
+
let result = table && db ? await createAction({
|
|
126
|
+
bodySchema: schemas.response,
|
|
127
|
+
db,
|
|
128
|
+
jsonArrayFields,
|
|
129
|
+
relations,
|
|
130
|
+
table
|
|
131
|
+
})(mergedParams) : { data: [], total: 0 };
|
|
132
|
+
if (handler) {
|
|
133
|
+
result = await handler({
|
|
134
|
+
data: result,
|
|
135
|
+
params: mergedParams,
|
|
136
|
+
req
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return import_next_rest_framework.TypedNextResponse.json(result, {
|
|
140
|
+
status: 200
|
|
141
|
+
});
|
|
142
|
+
} catch (error) {
|
|
143
|
+
return (0, import_operation_common.handleOperationError)(error, catchHandler);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
148
|
+
0 && (module.exports = {
|
|
149
|
+
createGetListOperationFactory,
|
|
150
|
+
createGetOperationFactory
|
|
151
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { NextRequest } from "next/server";
|
|
2
|
+
import { TypedNextRequest } from "next-rest-framework";
|
|
3
|
+
import { z, ZodSchema } from "zod";
|
|
4
|
+
import { type RouteOpenApiOperation } from "./open-api-operation.js";
|
|
5
|
+
import { ActionFactory, RouteCatch, SessionGetter } from "./operation-common.js";
|
|
6
|
+
export type PostOperationParams<IB extends ZodSchema> = z.infer<IB> & Record<string, unknown> & {
|
|
7
|
+
creatorId?: string;
|
|
8
|
+
};
|
|
9
|
+
export interface PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable> {
|
|
10
|
+
schemas: {
|
|
11
|
+
body: IB;
|
|
12
|
+
response?: OB;
|
|
13
|
+
};
|
|
14
|
+
contentType?: string;
|
|
15
|
+
openApiOperation?: RouteOpenApiOperation;
|
|
16
|
+
parseBody?: (_req: NextRequest) => Promise<Record<string, unknown>>;
|
|
17
|
+
setBody?: (_req: NextRequest) => Promise<Partial<z.infer<IB>>>;
|
|
18
|
+
handler?: (_payload: {
|
|
19
|
+
params: PostOperationParams<IB>;
|
|
20
|
+
data: z.infer<OB>;
|
|
21
|
+
req: NextRequest;
|
|
22
|
+
}) => Promise<z.infer<OB>>;
|
|
23
|
+
catch?: RouteCatch;
|
|
24
|
+
table?: TTable;
|
|
25
|
+
}
|
|
26
|
+
export declare function createPostOperationFactory<TTable>({ createAction, getTableName, }: {
|
|
27
|
+
createAction: ActionFactory<TTable, (_body: Record<string, unknown>) => Promise<unknown[]>>;
|
|
28
|
+
getTableName(table: TTable): string;
|
|
29
|
+
}): ({ db, getSession }: {
|
|
30
|
+
db?: unknown;
|
|
31
|
+
getSession: SessionGetter;
|
|
32
|
+
}) => <IB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>({ schemas, contentType, openApiOperation, parseBody, setBody, table, handler, catch: catchHandler, }: PostOperationOptions<IB, OB, TTable>) => import("next-rest-framework").RouteOperationDefinition<"POST">;
|
|
33
|
+
export type PutOperationParams<IB extends ZodSchema> = z.infer<IB> & Record<string, unknown> & {
|
|
34
|
+
editorId?: string;
|
|
35
|
+
};
|
|
36
|
+
export interface PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable> {
|
|
37
|
+
schemas: {
|
|
38
|
+
body: IB;
|
|
39
|
+
response?: OB;
|
|
40
|
+
};
|
|
41
|
+
access?: {
|
|
42
|
+
byCreator?: boolean;
|
|
43
|
+
};
|
|
44
|
+
openApiOperation?: RouteOpenApiOperation;
|
|
45
|
+
table?: TTable;
|
|
46
|
+
setBody?: (_req: TypedNextRequest<"PUT", "application/json", z.infer<IB>>) => Promise<Partial<z.infer<IB>>>;
|
|
47
|
+
handler?: (_payload: {
|
|
48
|
+
params: PutOperationParams<IB>;
|
|
49
|
+
data: z.infer<OB>;
|
|
50
|
+
req: NextRequest;
|
|
51
|
+
}) => Promise<z.infer<OB>>;
|
|
52
|
+
catch?: RouteCatch;
|
|
53
|
+
}
|
|
54
|
+
export declare function createPutOperationFactory<TTable>({ createAction, getTableName, }: {
|
|
55
|
+
createAction: ActionFactory<TTable, (_body: Record<string, unknown>, _options?: {
|
|
56
|
+
byCreator?: boolean;
|
|
57
|
+
}) => Promise<unknown>>;
|
|
58
|
+
getTableName(table: TTable): string;
|
|
59
|
+
}): ({ db, getSession }: {
|
|
60
|
+
db?: unknown;
|
|
61
|
+
getSession: SessionGetter;
|
|
62
|
+
}) => <IB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>({ schemas, access, openApiOperation, table, setBody, handler, catch: catchHandler, }: PutOperationOptions<IB, OB, TTable>) => import("next-rest-framework").RouteOperationDefinition<"PUT">;
|
|
63
|
+
export type DeleteOperationParams<B extends ZodSchema> = z.infer<B> & Record<string, unknown> & {
|
|
64
|
+
creatorId?: string;
|
|
65
|
+
id: string;
|
|
66
|
+
};
|
|
67
|
+
export interface DeleteOperationOptions<TTable, B extends ZodSchema> {
|
|
68
|
+
table?: TTable;
|
|
69
|
+
schemas?: {
|
|
70
|
+
body?: B;
|
|
71
|
+
};
|
|
72
|
+
access?: {
|
|
73
|
+
byCreator?: boolean;
|
|
74
|
+
};
|
|
75
|
+
openApiOperation?: RouteOpenApiOperation;
|
|
76
|
+
handler?: (_payload: {
|
|
77
|
+
params: DeleteOperationParams<B>;
|
|
78
|
+
data: unknown;
|
|
79
|
+
req: NextRequest;
|
|
80
|
+
}) => Promise<void>;
|
|
81
|
+
catch?: RouteCatch;
|
|
82
|
+
}
|
|
83
|
+
export declare function createDeleteOperationFactory<TTable>({ createAction, getTableName, }: {
|
|
84
|
+
createAction: ActionFactory<TTable, (_params: {
|
|
85
|
+
id: string;
|
|
86
|
+
creatorId?: string;
|
|
87
|
+
}) => Promise<unknown>>;
|
|
88
|
+
getTableName(table: TTable): string;
|
|
89
|
+
}): ({ db, getSession }: {
|
|
90
|
+
db?: unknown;
|
|
91
|
+
getSession: SessionGetter;
|
|
92
|
+
}) => <B extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>> = z.ZodObject<{
|
|
93
|
+
id: z.ZodString;
|
|
94
|
+
}, z.core.$strip>>({ table, schemas, access, openApiOperation, handler, catch: catchHandler, }: DeleteOperationOptions<TTable, B>) => import("next-rest-framework").RouteOperationDefinition<"DELETE">;
|
|
@@ -0,0 +1,181 @@
|
|
|
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/write-operation-core.ts
|
|
20
|
+
var write_operation_core_exports = {};
|
|
21
|
+
__export(write_operation_core_exports, {
|
|
22
|
+
createDeleteOperationFactory: () => createDeleteOperationFactory,
|
|
23
|
+
createPostOperationFactory: () => createPostOperationFactory,
|
|
24
|
+
createPutOperationFactory: () => createPutOperationFactory
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(write_operation_core_exports);
|
|
27
|
+
var import_next_rest_framework = require("next-rest-framework");
|
|
28
|
+
var import_zod = require("zod");
|
|
29
|
+
var import_open_api_operation = require("./open-api-operation");
|
|
30
|
+
var import_operation_common = require("./operation-common");
|
|
31
|
+
function createPostOperationFactory({
|
|
32
|
+
createAction,
|
|
33
|
+
getTableName
|
|
34
|
+
}) {
|
|
35
|
+
return ({ db, getSession }) => ({
|
|
36
|
+
schemas,
|
|
37
|
+
contentType = "application/json",
|
|
38
|
+
openApiOperation,
|
|
39
|
+
parseBody,
|
|
40
|
+
setBody,
|
|
41
|
+
table,
|
|
42
|
+
handler,
|
|
43
|
+
catch: catchHandler
|
|
44
|
+
}) => (0, import_next_rest_framework.routeOperation)({
|
|
45
|
+
method: "POST",
|
|
46
|
+
openApiOperation: (0, import_open_api_operation.createOpenApiOperation)({
|
|
47
|
+
defaultTags: (0, import_operation_common.getDefaultTags)({ getTableName, table }),
|
|
48
|
+
openApiOperation
|
|
49
|
+
})
|
|
50
|
+
}).input({
|
|
51
|
+
body: schemas.body,
|
|
52
|
+
contentType
|
|
53
|
+
}).outputs([
|
|
54
|
+
{
|
|
55
|
+
body: schemas.response || import_zod.z.object({ id: import_zod.z.string() }),
|
|
56
|
+
contentType: "application/json",
|
|
57
|
+
status: 200
|
|
58
|
+
}
|
|
59
|
+
]).handler(async (req) => {
|
|
60
|
+
try {
|
|
61
|
+
const { userId } = await getSession(req) || {};
|
|
62
|
+
const body = await (0, import_operation_common.readPostBody)(req, { contentType, parseBody });
|
|
63
|
+
const extraBody = await (setBody == null ? void 0 : setBody(req)) || {};
|
|
64
|
+
const params = { creatorId: userId, ...body, ...extraBody };
|
|
65
|
+
const raw = table && db ? (await createAction({
|
|
66
|
+
bodySchema: schemas.body,
|
|
67
|
+
db,
|
|
68
|
+
table
|
|
69
|
+
})(params))[0] : params;
|
|
70
|
+
const data = handler ? await handler({
|
|
71
|
+
data: raw,
|
|
72
|
+
params,
|
|
73
|
+
req
|
|
74
|
+
}) : raw;
|
|
75
|
+
return import_next_rest_framework.TypedNextResponse.json(data, { status: 200 });
|
|
76
|
+
} catch (error) {
|
|
77
|
+
return (0, import_operation_common.handleOperationError)(error, catchHandler);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function createPutOperationFactory({
|
|
82
|
+
createAction,
|
|
83
|
+
getTableName
|
|
84
|
+
}) {
|
|
85
|
+
return ({ db, getSession }) => ({
|
|
86
|
+
schemas,
|
|
87
|
+
access,
|
|
88
|
+
openApiOperation,
|
|
89
|
+
table,
|
|
90
|
+
setBody,
|
|
91
|
+
handler,
|
|
92
|
+
catch: catchHandler
|
|
93
|
+
}) => (0, import_next_rest_framework.routeOperation)({
|
|
94
|
+
method: "PUT",
|
|
95
|
+
openApiOperation: (0, import_open_api_operation.createOpenApiOperation)({
|
|
96
|
+
defaultTags: (0, import_operation_common.getDefaultTags)({ getTableName, table }),
|
|
97
|
+
openApiOperation
|
|
98
|
+
})
|
|
99
|
+
}).input({
|
|
100
|
+
body: schemas.body,
|
|
101
|
+
contentType: "application/json"
|
|
102
|
+
}).outputs([
|
|
103
|
+
{
|
|
104
|
+
body: schemas.response || import_zod.z.void(),
|
|
105
|
+
contentType: "application/json",
|
|
106
|
+
status: 200
|
|
107
|
+
}
|
|
108
|
+
]).handler(async (req) => {
|
|
109
|
+
try {
|
|
110
|
+
const { userId } = await getSession(req) || {};
|
|
111
|
+
const body = await req.json();
|
|
112
|
+
const extraBody = await (setBody == null ? void 0 : setBody(
|
|
113
|
+
req
|
|
114
|
+
)) || {};
|
|
115
|
+
const params = { editorId: userId, ...body, ...extraBody };
|
|
116
|
+
const raw = table && db ? await createAction({
|
|
117
|
+
bodySchema: schemas.body,
|
|
118
|
+
db,
|
|
119
|
+
table
|
|
120
|
+
})(params, { byCreator: (access == null ? void 0 : access.byCreator) ?? true }) : params;
|
|
121
|
+
const data = handler ? await handler({
|
|
122
|
+
data: raw,
|
|
123
|
+
params,
|
|
124
|
+
req
|
|
125
|
+
}) : raw;
|
|
126
|
+
return import_next_rest_framework.TypedNextResponse.json(data, { status: 200 });
|
|
127
|
+
} catch (error) {
|
|
128
|
+
return (0, import_operation_common.handleOperationError)(error, catchHandler);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
var defaultDeleteBodySchema = import_zod.z.object({
|
|
133
|
+
id: import_zod.z.string()
|
|
134
|
+
});
|
|
135
|
+
function createDeleteOperationFactory({
|
|
136
|
+
createAction,
|
|
137
|
+
getTableName
|
|
138
|
+
}) {
|
|
139
|
+
return ({ db, getSession }) => ({
|
|
140
|
+
table,
|
|
141
|
+
schemas,
|
|
142
|
+
access,
|
|
143
|
+
openApiOperation,
|
|
144
|
+
handler,
|
|
145
|
+
catch: catchHandler
|
|
146
|
+
}) => (0, import_next_rest_framework.routeOperation)({
|
|
147
|
+
method: "DELETE",
|
|
148
|
+
openApiOperation: (0, import_open_api_operation.createOpenApiOperation)({
|
|
149
|
+
defaultTags: (0, import_operation_common.getDefaultTags)({ getTableName, table }),
|
|
150
|
+
openApiOperation
|
|
151
|
+
})
|
|
152
|
+
}).input({
|
|
153
|
+
body: (schemas == null ? void 0 : schemas.body) || defaultDeleteBodySchema,
|
|
154
|
+
contentType: "application/json"
|
|
155
|
+
}).handler(async (req) => {
|
|
156
|
+
try {
|
|
157
|
+
const bodySchema = (schemas == null ? void 0 : schemas.body) || defaultDeleteBodySchema;
|
|
158
|
+
const body = bodySchema.parse(
|
|
159
|
+
await req.json()
|
|
160
|
+
);
|
|
161
|
+
if ((access == null ? void 0 : access.byCreator) ?? true) {
|
|
162
|
+
const { userId } = await getSession(req) || {};
|
|
163
|
+
body.creatorId = userId;
|
|
164
|
+
}
|
|
165
|
+
const data = table && db ? await createAction({ db, table })({
|
|
166
|
+
creatorId: body.creatorId,
|
|
167
|
+
id: body.id
|
|
168
|
+
}) : body;
|
|
169
|
+
await (handler == null ? void 0 : handler({ data, params: body, req }));
|
|
170
|
+
return import_next_rest_framework.TypedNextResponse.json(data, { status: 200 });
|
|
171
|
+
} catch (error) {
|
|
172
|
+
return (0, import_operation_common.handleOperationError)(error, catchHandler);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
177
|
+
0 && (module.exports = {
|
|
178
|
+
createDeleteOperationFactory,
|
|
179
|
+
createPostOperationFactory,
|
|
180
|
+
createPutOperationFactory
|
|
181
|
+
});
|
|
@@ -1,30 +1,13 @@
|
|
|
1
|
-
import { TypedNextResponse } from "next-rest-framework";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { BaseTable } from "../types.js";
|
|
4
1
|
import { NextRequest } from "next/server";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export interface DeleteOperationOptions<TTable extends BaseTable, B extends z.ZodSchema> {
|
|
10
|
-
table?: TTable;
|
|
11
|
-
bodySchema?: B;
|
|
12
|
-
description?: string;
|
|
13
|
-
summary?: string;
|
|
14
|
-
tags?: string[];
|
|
15
|
-
onSuccess?: (_payload: {
|
|
16
|
-
params: DeleteOperationParams<B>;
|
|
17
|
-
data: unknown;
|
|
18
|
-
}) => Promise<void>;
|
|
19
|
-
onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
20
|
-
byCreator?: boolean;
|
|
21
|
-
}
|
|
2
|
+
import { ZodSchema } from "zod";
|
|
3
|
+
import { BaseTable } from "../types.js";
|
|
4
|
+
import { type DeleteOperationOptions as CoreDeleteOperationOptions } from "../../route-operation/operation-core.js";
|
|
5
|
+
export type DeleteOperationOptions<TTable extends BaseTable, B extends ZodSchema> = CoreDeleteOperationOptions<TTable, B>;
|
|
22
6
|
export declare const createDeleteOperation: ({ db, getSession, }: {
|
|
23
|
-
db?:
|
|
24
|
-
getSession
|
|
7
|
+
db?: unknown;
|
|
8
|
+
getSession(req: NextRequest): Promise<{
|
|
25
9
|
userId?: string;
|
|
26
10
|
} | undefined>;
|
|
27
|
-
}) => <
|
|
28
|
-
id:
|
|
29
|
-
},
|
|
30
|
-
export {};
|
|
11
|
+
}) => <B extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>> = import("zod").ZodObject<{
|
|
12
|
+
id: import("zod").ZodString;
|
|
13
|
+
}, import("zod/v4/core").$strip>>({ table, schemas, access, openApiOperation, handler, catch: catchHandler, }: CoreDeleteOperationOptions<BaseTable, B>) => import("next-rest-framework").RouteOperationDefinition<"DELETE">;
|
|
@@ -32,67 +32,17 @@ __export(delete_operation_exports, {
|
|
|
32
32
|
createDeleteOperation: () => createDeleteOperation
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(delete_operation_exports);
|
|
35
|
-
var
|
|
36
|
-
var
|
|
35
|
+
var import_create_delete_action = require("../actions/create-delete-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
|
-
id: import_zod.z.string()
|
|
38
|
+
var createOperation = (0, import_operation_core.createDeleteOperationFactory)({
|
|
39
|
+
createAction: import_create_delete_action.createDeleteAction,
|
|
40
|
+
getTableName: import_get_table_name.default
|
|
42
41
|
});
|
|
43
42
|
var createDeleteOperation = ({
|
|
44
43
|
db,
|
|
45
44
|
getSession
|
|
46
|
-
}) => ({
|
|
47
|
-
table,
|
|
48
|
-
bodySchema = defaultDeleteBodySchema,
|
|
49
|
-
description,
|
|
50
|
-
summary,
|
|
51
|
-
tags,
|
|
52
|
-
onSuccess,
|
|
53
|
-
onError,
|
|
54
|
-
byCreator = true
|
|
55
|
-
}) => (0, import_next_rest_framework.routeOperation)({
|
|
56
|
-
method: "DELETE",
|
|
57
|
-
openApiOperation: {
|
|
58
|
-
description,
|
|
59
|
-
summary,
|
|
60
|
-
tags: tags ?? (table ? [(0, import_get_table_name.default)(table)] : [])
|
|
61
|
-
}
|
|
62
|
-
}).input({
|
|
63
|
-
body: bodySchema,
|
|
64
|
-
contentType: "application/json"
|
|
65
|
-
}).handler(async (req) => {
|
|
66
|
-
try {
|
|
67
|
-
const body = bodySchema.parse(
|
|
68
|
-
await req.json()
|
|
69
|
-
);
|
|
70
|
-
if (byCreator) {
|
|
71
|
-
const { userId } = await getSession(req) || {};
|
|
72
|
-
body.creatorId = userId;
|
|
73
|
-
}
|
|
74
|
-
const tableParams = body;
|
|
75
|
-
const data = table && db ? await (0, import_actions.createDeleteAction)({ table, db })(tableParams) : body;
|
|
76
|
-
await (onSuccess == null ? void 0 : onSuccess({ data, params: body }));
|
|
77
|
-
return import_next_rest_framework.TypedNextResponse.json(data, {
|
|
78
|
-
status: 200
|
|
79
|
-
});
|
|
80
|
-
} catch (e) {
|
|
81
|
-
if (!(e instanceof import_errors.HttpError)) {
|
|
82
|
-
console.error(e);
|
|
83
|
-
}
|
|
84
|
-
const response = await (onError == null ? void 0 : onError(e));
|
|
85
|
-
if (response) {
|
|
86
|
-
return response;
|
|
87
|
-
}
|
|
88
|
-
if (e instanceof import_errors.HttpError) {
|
|
89
|
-
return import_next_rest_framework.TypedNextResponse.json({ message: e.message }, {
|
|
90
|
-
status: e.status
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
throw e;
|
|
94
|
-
}
|
|
95
|
-
});
|
|
45
|
+
}) => createOperation({ db, getSession });
|
|
96
46
|
// Annotate the CommonJS export names for ESM import in node:
|
|
97
47
|
0 && (module.exports = {
|
|
98
48
|
createDeleteOperation
|