@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.
Files changed (77) 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 -18
  5. package/es/backend/route-operation/delete-operation.js +10 -122
  6. package/es/backend/route-operation/get-list-operation.d.ts +5 -27
  7. package/es/backend/route-operation/get-list-operation.js +10 -135
  8. package/es/backend/route-operation/get-operation.d.ts +5 -21
  9. package/es/backend/route-operation/get-operation.js +10 -132
  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 -20
  28. package/es/backend/sqlite/route-operation/delete-operation.js +10 -122
  29. package/es/backend/sqlite/route-operation/get-list-operation.d.ts +6 -28
  30. package/es/backend/sqlite/route-operation/get-list-operation.js +10 -135
  31. package/es/backend/sqlite/route-operation/get-operation.d.ts +6 -22
  32. package/es/backend/sqlite/route-operation/get-operation.js +10 -132
  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/es/backend/sqlite/schemas/index.d.ts +69 -5
  40. package/es/backend/sqlite/schemas/index.js +0 -1
  41. package/lib/__shims__/next-rest-framework.d.ts +2 -0
  42. package/lib/backend/route-operation/delete-operation.d.ts +7 -18
  43. package/lib/backend/route-operation/delete-operation.js +7 -52
  44. package/lib/backend/route-operation/get-list-operation.d.ts +5 -27
  45. package/lib/backend/route-operation/get-list-operation.js +7 -68
  46. package/lib/backend/route-operation/get-operation.d.ts +5 -21
  47. package/lib/backend/route-operation/get-operation.js +7 -67
  48. package/lib/backend/route-operation/index.d.ts +1 -0
  49. package/lib/backend/route-operation/index.js +3 -1
  50. package/lib/backend/route-operation/open-api-operation.d.ts +6 -0
  51. package/lib/backend/route-operation/open-api-operation.js +37 -0
  52. package/lib/backend/route-operation/operation-common.d.ts +38 -0
  53. package/lib/backend/route-operation/operation-common.js +90 -0
  54. package/lib/backend/route-operation/operation-core.d.ts +3 -0
  55. package/lib/backend/route-operation/operation-core.js +27 -0
  56. package/lib/backend/route-operation/post-operation.d.ts +5 -25
  57. package/lib/backend/route-operation/post-operation.js +7 -71
  58. package/lib/backend/route-operation/put-operation.d.ts +4 -23
  59. package/lib/backend/route-operation/put-operation.js +7 -68
  60. package/lib/backend/route-operation/read-operation-core.d.ts +55 -0
  61. package/lib/backend/route-operation/read-operation-core.js +151 -0
  62. package/lib/backend/route-operation/write-operation-core.d.ts +94 -0
  63. package/lib/backend/route-operation/write-operation-core.js +181 -0
  64. package/lib/backend/sqlite/route-operation/delete-operation.d.ts +9 -20
  65. package/lib/backend/sqlite/route-operation/delete-operation.js +7 -52
  66. package/lib/backend/sqlite/route-operation/get-list-operation.d.ts +6 -28
  67. package/lib/backend/sqlite/route-operation/get-list-operation.js +7 -71
  68. package/lib/backend/sqlite/route-operation/get-operation.d.ts +6 -22
  69. package/lib/backend/sqlite/route-operation/get-operation.js +7 -67
  70. package/lib/backend/sqlite/route-operation/index.d.ts +1 -0
  71. package/lib/backend/sqlite/route-operation/index.js +3 -1
  72. package/lib/backend/sqlite/route-operation/post-operation.d.ts +6 -26
  73. package/lib/backend/sqlite/route-operation/post-operation.js +7 -71
  74. package/lib/backend/sqlite/route-operation/put-operation.d.ts +6 -25
  75. package/lib/backend/sqlite/route-operation/put-operation.js +7 -68
  76. package/lib/backend/sqlite/schemas/index.d.ts +69 -5
  77. package/package.json +1 -1
@@ -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,24 +1,13 @@
1
- import { TypedNextResponse } from "next-rest-framework";
2
- import { BaseTable } from "../types.js";
3
1
  import { NextRequest } from "next/server";
4
- export interface DeleteOperationOptions<TTable extends BaseTable> {
5
- table?: TTable;
6
- description?: string;
7
- summary?: string;
8
- tags?: string[];
9
- onSuccess?: (_payload: {
10
- params: {
11
- id: string;
12
- creatorId?: string;
13
- };
14
- data: unknown;
15
- }) => Promise<void>;
16
- onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
17
- byCreator?: boolean;
18
- }
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>;
19
6
  export declare const createDeleteOperation: ({ db, getSession, }: {
20
- db?: any;
21
- getSession: (_req: NextRequest) => Promise<{
7
+ db?: unknown;
8
+ getSession(req: NextRequest): Promise<{
22
9
  userId?: string;
23
10
  } | undefined>;
24
- }) => <TTable extends BaseTable>({ table, description, summary, tags, onSuccess, onError, byCreator, }: DeleteOperationOptions<TTable>) => import("next-rest-framework").RouteOperationDefinition<"DELETE">;
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,62 +32,17 @@ __export(delete_operation_exports, {
32
32
  createDeleteOperation: () => createDeleteOperation
33
33
  });
34
34
  module.exports = __toCommonJS(delete_operation_exports);
35
- var import_next_rest_framework = require("next-rest-framework");
36
- var import_zod = require("zod");
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 import_actions = require("../actions");
39
- var import_errors = require("../errors");
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,33 +1,11 @@
1
- import { z, ZodSchema } from "zod";
2
1
  import { NextRequest } from "next/server";
3
- import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
2
+ import { ZodSchema } from "zod";
4
3
  import { BaseTable, GetListRelations } from "../types.js";
5
- export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> {
6
- bodySchema: T;
7
- jsonArrayFields?: string[];
8
- querySchema: Q;
9
- relations?: GetListRelations;
10
- setParams?: (_req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string, unknown>>;
11
- byCreator?: boolean;
12
- description?: string;
13
- summary?: string;
14
- tags?: string[];
15
- table?: TTable;
16
- onSuccess?: <D extends T>(_payload: {
17
- params: Partial<z.infer<T>> & Record<string, unknown>;
18
- data: {
19
- data: z.infer<D>[];
20
- total: number;
21
- };
22
- }) => Promise<{
23
- data: z.infer<T>[];
24
- total: number;
25
- }>;
26
- onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
27
- }
4
+ import { type GetListOperationOptions as CoreGetListOperationOptions } from "../../route-operation/operation-core.js";
5
+ export type GetListOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> = CoreGetListOperationOptions<T, Q, TTable, GetListRelations>;
28
6
  export declare const createGetListOperation: ({ db, getSession, }: {
29
- db?: any;
30
- getSession: (_req: NextRequest) => Promise<{
7
+ db?: unknown;
8
+ getSession(req: NextRequest): Promise<{
31
9
  userId?: string;
32
10
  } | undefined>;
33
- }) => <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, jsonArrayFields, setParams, onSuccess, onError, byCreator, }: GetListOperationOptions<T, Q, TTable>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
11
+ }) => <T extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, Q extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, jsonArrayFields, setParams, handler, catch: catchHandler, }: CoreGetListOperationOptions<T, Q, BaseTable, GetListRelations>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
@@ -32,81 +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
+ var import_operation_core = require("../../route-operation/operation-core");
36
37
  var import_get_table_name = __toESM(require("./get-table-name"));
37
- var import_schemas = require("../schemas");
38
- var import_actions = require("../actions");
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({
92
- data: result,
93
- params: mergedParams
94
- });
95
- }
96
- return import_next_rest_framework.TypedNextResponse.json(
97
- 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
  createGetListOperation
@@ -1,27 +1,11 @@
1
- import { z, ZodSchema } from "zod";
2
1
  import { NextRequest } from "next/server";
3
- import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
2
+ import { ZodSchema } from "zod";
4
3
  import { BaseTable, GetListRelations } from "../types.js";
5
- export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> {
6
- bodySchema: T;
7
- jsonArrayFields?: string[];
8
- querySchema: Q;
9
- relations?: GetListRelations;
10
- setParams?: (_req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string, unknown>>;
11
- onSuccess?: (_payload: {
12
- params: Partial<z.infer<T>> & Record<string, unknown>;
13
- data: z.infer<T>;
14
- }) => Promise<z.infer<T>>;
15
- onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
16
- description?: string;
17
- summary?: string;
18
- tags?: string[];
19
- table?: TTable;
20
- byCreator?: boolean;
21
- }
4
+ import { type GetOperationOptions as CoreGetOperationOptions } from "../../route-operation/operation-core.js";
5
+ export type GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> = CoreGetOperationOptions<T, Q, TTable, GetListRelations>;
22
6
  export declare const createGetOperation: ({ getSession, db, }: {
23
- db?: any;
24
- getSession: (_req: NextRequest) => Promise<{
7
+ db?: unknown;
8
+ getSession(req: NextRequest): Promise<{
25
9
  userId?: string;
26
10
  } | undefined>;
27
- }) => <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">;
11
+ }) => <T extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, Q extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, table, openApiOperation, relations, setParams, jsonArrayFields, handler, catch: catchHandler, }: CoreGetOperationOptions<T, Q, BaseTable, GetListRelations>) => import("next-rest-framework").RouteOperationDefinition<"GET">;
@@ -32,77 +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
+ var import_operation_core = require("../../route-operation/operation-core");
36
37
  var import_get_table_name = __toESM(require("./get-table-name"));
37
- var import_actions = require("../actions");
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
@@ -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 "../../route-operation/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("../../route-operation/open-api-operation"), module.exports);
24
25
  // Annotate the CommonJS export names for ESM import in node:
25
26
  0 && (module.exports = {
26
27
  ...require("./get-operation"),
27
28
  ...require("./get-list-operation"),
28
29
  ...require("./delete-operation"),
29
30
  ...require("./post-operation"),
30
- ...require("./put-operation")
31
+ ...require("./put-operation"),
32
+ ...require("../../route-operation/open-api-operation")
31
33
  });
@@ -1,31 +1,11 @@
1
- import { z, ZodSchema } from "zod";
2
1
  import { SQLiteTable } from "drizzle-orm/sqlite-core";
3
2
  import { NextRequest } from "next/server";
4
- import { TypedNextResponse } from "next-rest-framework";
5
- type PostOperationParams<IB extends ZodSchema> = z.infer<IB> & Record<string, unknown> & {
6
- creatorId?: string;
7
- };
8
- export interface PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends SQLiteTable> {
9
- bodySchema: IB;
10
- contentType?: string;
11
- description?: string;
12
- outputBodySchema?: OB;
13
- parseBody?: (_req: NextRequest) => Promise<Record<string, unknown>>;
14
- setBody?: (_req: NextRequest) => Promise<Partial<z.infer<IB>>>;
15
- summary?: string;
16
- tags?: string[];
17
- onSuccess?: (_payload: {
18
- params: PostOperationParams<IB>;
19
- data: z.infer<OB>;
20
- req: NextRequest;
21
- }) => Promise<z.infer<OB>>;
22
- onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
23
- table?: TTable;
24
- }
3
+ import { ZodSchema } from "zod";
4
+ import { type PostOperationOptions as CorePostOperationOptions } from "../../route-operation/operation-core.js";
5
+ export type PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends SQLiteTable> = CorePostOperationOptions<IB, OB, TTable>;
25
6
  export declare const createPostOperation: ({ getSession, db, }: {
26
- db?: any;
27
- getSession: (_req: NextRequest) => Promise<{
7
+ db?: unknown;
8
+ getSession(req: NextRequest): Promise<{
28
9
  userId?: string;
29
10
  } | 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 SQLiteTable<import("drizzle-orm/sqlite-core").TableConfig>>({ bodySchema, contentType, description, outputBodySchema, parseBody, setBody, summary, tags, table, onSuccess, onError, }: PostOperationOptions<IB, OB, TTable>) => import("next-rest-framework").RouteOperationDefinition<"POST">;
31
- export {};
11
+ }) => <IB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, OB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, contentType, openApiOperation, parseBody, setBody, table, handler, catch: catchHandler, }: CorePostOperationOptions<IB, OB, SQLiteTable<import("drizzle-orm/sqlite-core").TableConfig>>) => import("next-rest-framework").RouteOperationDefinition<"POST">;