@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.
Files changed (74) hide show
  1. package/.agents/skills/ai0x0-utils/backend/SKILL.md +40 -38
  2. package/SKILL.md +39 -37
  3. package/es/__shims__/next-rest-framework.d.ts +2 -0
  4. package/es/backend/route-operation/delete-operation.d.ts +7 -24
  5. package/es/backend/route-operation/delete-operation.js +9 -127
  6. package/es/backend/route-operation/get-list-operation.d.ts +5 -31
  7. package/es/backend/route-operation/get-list-operation.js +10 -142
  8. package/es/backend/route-operation/get-operation.d.ts +5 -25
  9. package/es/backend/route-operation/get-operation.js +10 -139
  10. package/es/backend/route-operation/get-table-name.js +0 -2
  11. package/es/backend/route-operation/index.d.ts +1 -0
  12. package/es/backend/route-operation/index.js +2 -1
  13. package/es/backend/route-operation/open-api-operation.d.ts +6 -0
  14. package/es/backend/route-operation/open-api-operation.js +13 -0
  15. package/es/backend/route-operation/operation-common.d.ts +38 -0
  16. package/es/backend/route-operation/operation-common.js +148 -0
  17. package/es/backend/route-operation/operation-core.d.ts +3 -0
  18. package/es/backend/route-operation/operation-core.js +3 -0
  19. package/es/backend/route-operation/post-operation.d.ts +5 -25
  20. package/es/backend/route-operation/post-operation.js +13 -189
  21. package/es/backend/route-operation/put-operation.d.ts +4 -23
  22. package/es/backend/route-operation/put-operation.js +10 -155
  23. package/es/backend/route-operation/read-operation-core.d.ts +55 -0
  24. package/es/backend/route-operation/read-operation-core.js +224 -0
  25. package/es/backend/route-operation/write-operation-core.d.ts +94 -0
  26. package/es/backend/route-operation/write-operation-core.js +390 -0
  27. package/es/backend/sqlite/route-operation/delete-operation.d.ts +9 -26
  28. package/es/backend/sqlite/route-operation/delete-operation.js +9 -127
  29. package/es/backend/sqlite/route-operation/get-list-operation.d.ts +6 -32
  30. package/es/backend/sqlite/route-operation/get-list-operation.js +10 -142
  31. package/es/backend/sqlite/route-operation/get-operation.d.ts +6 -26
  32. package/es/backend/sqlite/route-operation/get-operation.js +10 -139
  33. package/es/backend/sqlite/route-operation/index.d.ts +1 -0
  34. package/es/backend/sqlite/route-operation/index.js +2 -1
  35. package/es/backend/sqlite/route-operation/post-operation.d.ts +6 -26
  36. package/es/backend/sqlite/route-operation/post-operation.js +13 -189
  37. package/es/backend/sqlite/route-operation/put-operation.d.ts +6 -25
  38. package/es/backend/sqlite/route-operation/put-operation.js +10 -155
  39. package/lib/__shims__/next-rest-framework.d.ts +2 -0
  40. package/lib/backend/route-operation/delete-operation.d.ts +7 -24
  41. package/lib/backend/route-operation/delete-operation.js +6 -56
  42. package/lib/backend/route-operation/get-list-operation.d.ts +5 -31
  43. package/lib/backend/route-operation/get-list-operation.js +7 -72
  44. package/lib/backend/route-operation/get-operation.d.ts +5 -25
  45. package/lib/backend/route-operation/get-operation.js +7 -71
  46. package/lib/backend/route-operation/index.d.ts +1 -0
  47. package/lib/backend/route-operation/index.js +3 -1
  48. package/lib/backend/route-operation/open-api-operation.d.ts +6 -0
  49. package/lib/backend/route-operation/open-api-operation.js +37 -0
  50. package/lib/backend/route-operation/operation-common.d.ts +38 -0
  51. package/lib/backend/route-operation/operation-common.js +90 -0
  52. package/lib/backend/route-operation/operation-core.d.ts +3 -0
  53. package/lib/backend/route-operation/operation-core.js +27 -0
  54. package/lib/backend/route-operation/post-operation.d.ts +5 -25
  55. package/lib/backend/route-operation/post-operation.js +7 -71
  56. package/lib/backend/route-operation/put-operation.d.ts +4 -23
  57. package/lib/backend/route-operation/put-operation.js +7 -68
  58. package/lib/backend/route-operation/read-operation-core.d.ts +55 -0
  59. package/lib/backend/route-operation/read-operation-core.js +151 -0
  60. package/lib/backend/route-operation/write-operation-core.d.ts +94 -0
  61. package/lib/backend/route-operation/write-operation-core.js +181 -0
  62. package/lib/backend/sqlite/route-operation/delete-operation.d.ts +9 -26
  63. package/lib/backend/sqlite/route-operation/delete-operation.js +6 -56
  64. package/lib/backend/sqlite/route-operation/get-list-operation.d.ts +6 -32
  65. package/lib/backend/sqlite/route-operation/get-list-operation.js +7 -75
  66. package/lib/backend/sqlite/route-operation/get-operation.d.ts +6 -26
  67. package/lib/backend/sqlite/route-operation/get-operation.js +7 -71
  68. package/lib/backend/sqlite/route-operation/index.d.ts +1 -0
  69. package/lib/backend/sqlite/route-operation/index.js +3 -1
  70. package/lib/backend/sqlite/route-operation/post-operation.d.ts +6 -26
  71. package/lib/backend/sqlite/route-operation/post-operation.js +7 -71
  72. package/lib/backend/sqlite/route-operation/put-operation.d.ts +6 -25
  73. package/lib/backend/sqlite/route-operation/put-operation.js +7 -68
  74. package/package.json +1 -1
@@ -32,82 +32,17 @@ __export(get_list_operation_exports, {
32
32
  createGetListOperation: () => createGetListOperation
33
33
  });
34
34
  module.exports = __toCommonJS(get_list_operation_exports);
35
- var import_next_rest_framework = require("next-rest-framework");
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 import_schemas = require("../schemas");
38
- var import_actions = require("../actions");
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 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({ data: result, params: mergedParams });
96
- }
97
- return import_next_rest_framework.TypedNextResponse.json(
98
- result,
99
- { status: 200 }
100
- );
101
- } catch (e) {
102
- console.error(e);
103
- const response = await (onError == null ? void 0 : onError(e));
104
- if (response) {
105
- return response;
106
- } else {
107
- throw e;
108
- }
109
- }
110
- });
45
+ }) => createOperation({ db, getSession });
111
46
  // Annotate the CommonJS export names for ESM import in node:
112
47
  0 && (module.exports = {
113
48
  createGetListOperation
@@ -1,32 +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
- type GetOperationParams<Q extends ZodSchema> = z.infer<Q> & Record<string, unknown> & {
7
- creatorId?: string;
8
- };
9
- export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> {
10
- bodySchema: T;
11
- jsonArrayFields?: string[];
12
- querySchema: Q;
13
- relations?: GetListRelations;
14
- setParams?(req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>): Promise<Record<string, unknown>>;
15
- onSuccess?(payload: {
16
- params: GetOperationParams<Q>;
17
- data: z.infer<T>;
18
- }): Promise<z.infer<T>>;
19
- onError?(error: Error): Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
20
- description?: string;
21
- summary?: string;
22
- tags?: string[];
23
- table?: TTable;
24
- byCreator?: boolean;
25
- }
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>;
26
7
  export declare const createGetOperation: ({ getSession, db, }: {
27
8
  db?: NodePgDatabase<Record<string, unknown>> | undefined;
28
9
  getSession(req: NextRequest): Promise<{
29
10
  userId?: string;
30
11
  } | undefined>;
31
- }) => <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, Q extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, TTable extends BaseTable>({ querySchema, bodySchema, table, description, summary, tags, relations, setParams, jsonArrayFields, onSuccess, onError, byCreator, }: GetOperationOptions<T, Q, TTable>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
32
- export {};
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,81 +32,17 @@ __export(get_operation_exports, {
32
32
  createGetOperation: () => createGetOperation
33
33
  });
34
34
  module.exports = __toCommonJS(get_operation_exports);
35
- var import_next_rest_framework = require("next-rest-framework");
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 import_actions = require("../actions");
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 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
@@ -3,3 +3,4 @@ export * from "./get-list-operation.js";
3
3
  export * from "./delete-operation.js";
4
4
  export * from "./post-operation.js";
5
5
  export * from "./put-operation.js";
6
+ export * from "./open-api-operation.js";
@@ -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,3 @@
1
+ export * from "./operation-common.js";
2
+ export * from "./read-operation-core.js";
3
+ export * from "./write-operation-core.js";
@@ -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
- 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 extends PgTable> {
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 z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, TTable extends PgTable<import("drizzle-orm/pg-core").TableConfig>>({ bodySchema, contentType, description, outputBodySchema, parseBody, setBody, summary, tags, table, onSuccess, onError, }: PostOperationOptions<IB, OB, TTable>) => import("next-rest-framework").RouteOperationDefinition<"POST">;
32
- export {};
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">;
@@ -32,81 +32,17 @@ __export(post_operation_exports, {
32
32
  createPostOperation: () => createPostOperation
33
33
  });
34
34
  module.exports = __toCommonJS(post_operation_exports);
35
- var import_zod = require("zod");
36
- var import_next_rest_framework = require("next-rest-framework");
35
+ var import_create_post_action = require("../actions/create-post-action");
37
36
  var import_get_table_name = __toESM(require("./get-table-name"));
38
- var import_actions = require("../actions");
39
- async function readPostBody(req, {
40
- contentType,
41
- parseBody
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
- }
37
+ var import_operation_core = require("./operation-core");
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,31 +1,12 @@
1
- import { z, ZodSchema } from "zod";
2
1
  import { PgTable } from "drizzle-orm/pg-core";
3
- import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
4
2
  import { NodePgDatabase } from "drizzle-orm/node-postgres";
5
3
  import { NextRequest } from "next/server";
6
- import { BaseTable } from "../types.js";
7
- type PutOperationParams<IB extends ZodSchema> = z.infer<IB> & Record<string, unknown> & {
8
- editorId?: string;
9
- };
10
- export interface PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends PgTable> {
11
- bodySchema: IB;
12
- description?: string;
13
- outputBodySchema?: OB;
14
- table?: TTable;
15
- summary?: string;
16
- tags?: string[];
17
- setBody?(req: TypedNextRequest<"PUT", "application/json", z.infer<IB>>): Promise<Partial<z.infer<IB>>>;
18
- onSuccess?(payload: {
19
- params: PutOperationParams<IB>;
20
- data: z.infer<OB>;
21
- }): Promise<z.infer<OB>>;
22
- onError?(error: Error): Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
23
- byCreator?: boolean;
24
- }
4
+ import { ZodSchema } from "zod";
5
+ import { type PutOperationOptions as CorePutOperationOptions } from "./operation-core.js";
6
+ export type PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends PgTable> = CorePutOperationOptions<IB, OB, TTable>;
25
7
  export declare const createPutOperation: ({ getSession, db, }: {
26
8
  getSession(req: NextRequest): Promise<{
27
9
  userId?: string;
28
10
  } | undefined>;
29
11
  db?: NodePgDatabase<Record<string, unknown>> | undefined;
30
- }) => <IB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, TTable extends BaseTable>({ bodySchema, description, outputBodySchema, table, summary, tags, setBody, onSuccess, byCreator, onError, }: PutOperationOptions<IB, OB, TTable>) => import("next-rest-framework").RouteOperationDefinition<"PUT">;
31
- export {};
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, access, openApiOperation, table, setBody, handler, catch: catchHandler, }: CorePutOperationOptions<IB, OB, PgTable<import("drizzle-orm/pg-core").TableConfig>>) => import("next-rest-framework").RouteOperationDefinition<"PUT">;