@ai0x0/utils 0.0.37 → 0.0.39

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 (104) hide show
  1. package/.agents/skills/ai0x0-utils/backend/SKILL.md +12 -8
  2. package/README.md +42 -1
  3. package/SKILL.md +12 -8
  4. package/es/backend/route-operation/delete-operation.d.ts +3 -2
  5. package/es/backend/route-operation/delete-operation.js +35 -22
  6. package/es/backend/route-operation/get-list-operation.d.ts +6 -5
  7. package/es/backend/route-operation/get-list-operation.js +37 -22
  8. package/es/backend/route-operation/get-operation.d.ts +5 -4
  9. package/es/backend/route-operation/get-operation.js +34 -22
  10. package/es/backend/route-operation/post-operation.d.ts +5 -4
  11. package/es/backend/route-operation/post-operation.js +39 -34
  12. package/es/backend/route-operation/put-operation.d.ts +5 -4
  13. package/es/backend/route-operation/put-operation.js +44 -29
  14. package/es/backend/sqlite/actions/create-delete-action.d.ts +8 -0
  15. package/es/backend/sqlite/actions/create-delete-action.js +54 -0
  16. package/es/backend/sqlite/actions/create-get-action.d.ts +8 -0
  17. package/es/backend/sqlite/actions/create-get-action.js +64 -0
  18. package/es/backend/sqlite/actions/create-get-list-action.d.ts +11 -0
  19. package/es/backend/sqlite/actions/create-get-list-action.js +56 -0
  20. package/es/backend/sqlite/actions/create-post-action.d.ts +6 -0
  21. package/es/backend/sqlite/actions/create-post-action.js +31 -0
  22. package/es/backend/sqlite/actions/create-put-action.d.ts +8 -0
  23. package/es/backend/sqlite/actions/create-put-action.js +74 -0
  24. package/es/backend/sqlite/actions/get-list-data.d.ts +9 -0
  25. package/es/backend/sqlite/actions/get-list-data.js +75 -0
  26. package/es/backend/sqlite/actions/get-list-query.d.ts +19 -0
  27. package/es/backend/sqlite/actions/get-list-query.js +215 -0
  28. package/es/backend/sqlite/actions/index.d.ts +6 -0
  29. package/es/backend/sqlite/actions/index.js +6 -0
  30. package/es/backend/sqlite/actions/transform-body.d.ts +1 -0
  31. package/es/backend/sqlite/actions/transform-body.js +9 -0
  32. package/es/backend/sqlite/errors.d.ts +4 -0
  33. package/es/backend/sqlite/errors.js +31 -0
  34. package/es/backend/sqlite/index.d.ts +5 -0
  35. package/es/backend/sqlite/index.js +5 -0
  36. package/es/backend/sqlite/route-operation/delete-operation.d.ts +11 -0
  37. package/es/backend/sqlite/route-operation/delete-operation.js +122 -0
  38. package/es/backend/sqlite/route-operation/get-list-operation.d.ts +23 -0
  39. package/es/backend/sqlite/route-operation/get-list-operation.js +135 -0
  40. package/es/backend/sqlite/route-operation/get-operation.d.ts +17 -0
  41. package/es/backend/sqlite/route-operation/get-operation.js +132 -0
  42. package/es/backend/sqlite/route-operation/get-table-name.d.ts +3 -0
  43. package/es/backend/sqlite/route-operation/get-table-name.js +11 -0
  44. package/es/backend/sqlite/route-operation/index.d.ts +5 -0
  45. package/es/backend/sqlite/route-operation/index.js +5 -0
  46. package/es/backend/sqlite/route-operation/post-operation.d.ts +14 -0
  47. package/es/backend/sqlite/route-operation/post-operation.js +141 -0
  48. package/es/backend/sqlite/route-operation/put-operation.d.ts +15 -0
  49. package/es/backend/sqlite/route-operation/put-operation.js +156 -0
  50. package/es/backend/sqlite/schemas/index.d.ts +68 -0
  51. package/es/backend/sqlite/schemas/index.js +133 -0
  52. package/es/backend/sqlite/types.d.ts +16 -0
  53. package/es/backend/sqlite/types.js +1 -0
  54. package/lib/backend/route-operation/delete-operation.d.ts +3 -2
  55. package/lib/backend/route-operation/delete-operation.js +5 -3
  56. package/lib/backend/route-operation/get-list-operation.d.ts +6 -5
  57. package/lib/backend/route-operation/get-list-operation.js +8 -8
  58. package/lib/backend/route-operation/get-operation.d.ts +5 -4
  59. package/lib/backend/route-operation/get-operation.js +8 -8
  60. package/lib/backend/route-operation/post-operation.d.ts +5 -4
  61. package/lib/backend/route-operation/post-operation.js +4 -3
  62. package/lib/backend/route-operation/put-operation.d.ts +5 -4
  63. package/lib/backend/route-operation/put-operation.js +6 -4
  64. package/lib/backend/sqlite/actions/create-delete-action.d.ts +8 -0
  65. package/lib/backend/sqlite/actions/create-delete-action.js +53 -0
  66. package/lib/backend/sqlite/actions/create-get-action.d.ts +8 -0
  67. package/lib/backend/sqlite/actions/create-get-action.js +65 -0
  68. package/lib/backend/sqlite/actions/create-get-list-action.d.ts +11 -0
  69. package/lib/backend/sqlite/actions/create-get-list-action.js +63 -0
  70. package/lib/backend/sqlite/actions/create-post-action.d.ts +6 -0
  71. package/lib/backend/sqlite/actions/create-post-action.js +39 -0
  72. package/lib/backend/sqlite/actions/create-put-action.d.ts +8 -0
  73. package/lib/backend/sqlite/actions/create-put-action.js +60 -0
  74. package/lib/backend/sqlite/actions/get-list-data.d.ts +9 -0
  75. package/lib/backend/sqlite/actions/get-list-data.js +51 -0
  76. package/lib/backend/sqlite/actions/get-list-query.d.ts +19 -0
  77. package/lib/backend/sqlite/actions/get-list-query.js +165 -0
  78. package/lib/backend/sqlite/actions/index.d.ts +6 -0
  79. package/lib/backend/sqlite/actions/index.js +44 -0
  80. package/lib/backend/sqlite/actions/transform-body.d.ts +1 -0
  81. package/lib/backend/sqlite/actions/transform-body.js +49 -0
  82. package/lib/backend/sqlite/errors.d.ts +4 -0
  83. package/lib/backend/sqlite/errors.js +35 -0
  84. package/lib/backend/sqlite/index.d.ts +5 -0
  85. package/lib/backend/sqlite/index.js +31 -0
  86. package/lib/backend/sqlite/route-operation/delete-operation.d.ts +11 -0
  87. package/lib/backend/sqlite/route-operation/delete-operation.js +92 -0
  88. package/lib/backend/sqlite/route-operation/get-list-operation.d.ts +23 -0
  89. package/lib/backend/sqlite/route-operation/get-list-operation.js +108 -0
  90. package/lib/backend/sqlite/route-operation/get-operation.d.ts +17 -0
  91. package/lib/backend/sqlite/route-operation/get-operation.js +107 -0
  92. package/lib/backend/sqlite/route-operation/get-table-name.d.ts +3 -0
  93. package/lib/backend/sqlite/route-operation/get-table-name.js +35 -0
  94. package/lib/backend/sqlite/route-operation/index.d.ts +5 -0
  95. package/lib/backend/sqlite/route-operation/index.js +31 -0
  96. package/lib/backend/sqlite/route-operation/post-operation.d.ts +14 -0
  97. package/lib/backend/sqlite/route-operation/post-operation.js +95 -0
  98. package/lib/backend/sqlite/route-operation/put-operation.d.ts +15 -0
  99. package/lib/backend/sqlite/route-operation/put-operation.js +104 -0
  100. package/lib/backend/sqlite/schemas/index.d.ts +68 -0
  101. package/lib/backend/sqlite/schemas/index.js +113 -0
  102. package/lib/backend/sqlite/types.d.ts +16 -0
  103. package/lib/backend/sqlite/types.js +17 -0
  104. package/package.json +3 -1
@@ -85,14 +85,18 @@ export const getListOperation = createGetListOperation({ db, getSession });
85
85
 
86
86
  ## Factory Catalog
87
87
 
88
- | Export | Purpose | Required options | Notable optional options |
89
- | ------------------- | -------------------------- | ------------------------------------ | ------------------------------------------------------------------------------------------- |
90
- | `createTableSchema` | pg `Table` + 5 zod schemas | `name`, `columns` | `refineSchema`, `extraConfig` |
91
- | `getOperation` | GET one by filters | `table`, `bodySchema`, `querySchema` | `setParams`, `relations`, `jsonArrayFields`, `byCreator`, `onSuccess`, `onError`, `summary` |
92
- | `getListOperation` | GET paginated list | `table`, `bodySchema`, `querySchema` | `setParams`, `relations`, `jsonArrayFields`, `onSuccess`, `onError`, `summary` |
93
- | `postOperation` | POST create | `table`, `bodySchema` | `outputBodySchema`, `setBody`, `onSuccess`, `onError`, `summary` |
94
- | `putOperation` | PUT update | `table`, `bodySchema` | `outputBodySchema`, `setBody`, `byCreator`, `onSuccess`, `onError`, `summary` |
95
- | `deleteOperation` | DELETE | `table` | `byCreator`, `onSuccess`, `onError`, `summary` |
88
+ | Export | Purpose | Required options | Notable optional options |
89
+ | ------------------- | -------------------------- | --------------------------- | ------------------------------------------------------------------------------------------------------------ |
90
+ | `createTableSchema` | pg `Table` + 5 zod schemas | `name`, `columns` | `refineSchema`, `extraConfig` |
91
+ | `getOperation` | GET one by filters | `bodySchema`, `querySchema` | `table`, `setParams`, `relations`, `jsonArrayFields`, `byCreator`, `onSuccess`, `onError`, `summary`, `tags` |
92
+ | `getListOperation` | GET paginated list | `bodySchema`, `querySchema` | `table`, `setParams`, `relations`, `jsonArrayFields`, `onSuccess`, `onError`, `summary`, `tags` |
93
+ | `postOperation` | POST create | `bodySchema` | `table`, `outputBodySchema`, `setBody`, `onSuccess`, `onError`, `summary`, `tags` |
94
+ | `putOperation` | PUT update | `bodySchema` | `table`, `outputBodySchema`, `setBody`, `byCreator`, `onSuccess`, `onError`, `summary`, `tags` |
95
+ | `deleteOperation` | DELETE | — | `table`, `byCreator`, `onSuccess`, `onError`, `summary`, `tags` |
96
+
97
+ `tags` can be passed manually to override the default OpenAPI tag inferred from `table`.
98
+
99
+ `table` is optional for route operations. When omitted, the operation still parses input, applies `setParams` / `setBody`, session-derived fields, and `onSuccess`, but skips the built-in table action (`select` / `insert` / `update` / `delete`). Use this for custom endpoints that want the same OpenAPI and response wiring without a direct table operation.
96
100
 
97
101
  ## Canonical Examples
98
102
 
package/README.md CHANGED
@@ -17,6 +17,47 @@ Declarative CRUD factories on top of `next-rest-framework`, `drizzle-orm/pg-core
17
17
 
18
18
  See [SKILL.md](./SKILL.md) for detailed workflow, setup, and escape hatches.
19
19
 
20
+ ## SQLite Backend (`src/backend/sqlite/`)
21
+
22
+ Projects that use a local SQLite database can import the same CRUD factory surface from `@ai0x0/utils/es/backend/sqlite`.
23
+
24
+ ```ts
25
+ import {
26
+ createTableSchema,
27
+ queryListSchema,
28
+ } from "@ai0x0/utils/es/backend/sqlite/schemas/index.js";
29
+ import {
30
+ createGetOperation,
31
+ createPostOperation,
32
+ } from "@ai0x0/utils/es/backend/sqlite/index.js";
33
+ ```
34
+
35
+ The SQLite helpers mirror the PostgreSQL helpers, but use `drizzle-orm/sqlite-core`, SQLite `LIKE`, and `json_each(...)` for JSON-array filtering.
36
+
37
+ Focused SQLite coverage should verify:
38
+
39
+ 1. `createTableSchema` generates SQLite tables with the base fields: `id`, `creatorId`, `editorId`, `accessedAt`, `createdAt`, and `updatedAt`.
40
+ 2. `queryListSchema` preserves pagination defaults.
41
+ 3. `createGetListAction` works with SQLite query builders that expose `.all()`.
42
+ 4. `getListData` executes plain queries directly and does not depend on `next-rest-framework` RPC wrappers.
43
+ 5. `createPostAction` and `createPutAction` normalize `*At` fields through `transformBody`.
44
+ 6. String filters use SQLite `LIKE`, comma-separated id filters use `inArray`, JSON-array filters use `json_each(...)`, and date range filters map `createdAtFrom` / `createdAtTo` to the matching timestamp column.
45
+
46
+ Run the focused SQLite tests:
47
+
48
+ ```bash
49
+ pnpm test -- src/__tests__/sqlite-actions.test.ts src/__tests__/sqlite-schemas.test.ts
50
+ ```
51
+
52
+ Run the full package checks before publishing:
53
+
54
+ ```bash
55
+ pnpm test
56
+ pnpm exec tsc --noEmit
57
+ pnpm build
58
+ npm pack --dry-run --json
59
+ ```
60
+
20
61
  ## Agent Skills
21
62
 
22
63
  This package also ships reusable project skills under `.agents/skills`:
@@ -114,7 +155,7 @@ Restrictions cover: `TryStatement`, `as` (non-const), `useState`, `useEffect`, `
114
155
  pnpm add @ai0x0/utils
115
156
  ```
116
157
 
117
- Peer dependencies: `drizzle-orm ^0.45.x`, `drizzle-zod ^0.8.x`, `zod ^4.x`.
158
+ Peer dependencies: `drizzle-orm ^0.45.x`, `drizzle-zod ^0.8.x`, `next ^16.x`, `next-rest-framework`, `zod ^4.x`.
118
159
 
119
160
  ## Docs
120
161
 
package/SKILL.md CHANGED
@@ -64,14 +64,18 @@ export const getListOperation = createGetListOperation({ db, getSession });
64
64
 
65
65
  ## Factory Catalog
66
66
 
67
- | Export | Purpose | Required options | Notable optional options |
68
- | ------------------- | -------------------------- | ------------------------------------ | ------------------------------------------------------------------------------------------- |
69
- | `createTableSchema` | pg `Table` + 5 zod schemas | `name`, `columns` | `refineSchema`, `extraConfig` |
70
- | `getOperation` | GET one by filters | `table`, `bodySchema`, `querySchema` | `setParams`, `relations`, `jsonArrayFields`, `byCreator`, `onSuccess`, `onError`, `summary` |
71
- | `getListOperation` | GET paginated list | `table`, `bodySchema`, `querySchema` | `setParams`, `relations`, `jsonArrayFields`, `onSuccess`, `onError`, `summary` |
72
- | `postOperation` | POST create | `table`, `bodySchema` | `outputBodySchema`, `setBody`, `onSuccess`, `onError`, `summary` |
73
- | `putOperation` | PUT update | `table`, `bodySchema` | `outputBodySchema`, `setBody`, `byCreator`, `onSuccess`, `onError`, `summary` |
74
- | `deleteOperation` | DELETE | `table` | `byCreator`, `onSuccess`, `onError`, `summary` |
67
+ | Export | Purpose | Required options | Notable optional options |
68
+ | ------------------- | -------------------------- | --------------------------- | ------------------------------------------------------------------------------------------------------------ |
69
+ | `createTableSchema` | pg `Table` + 5 zod schemas | `name`, `columns` | `refineSchema`, `extraConfig` |
70
+ | `getOperation` | GET one by filters | `bodySchema`, `querySchema` | `table`, `setParams`, `relations`, `jsonArrayFields`, `byCreator`, `onSuccess`, `onError`, `summary`, `tags` |
71
+ | `getListOperation` | GET paginated list | `bodySchema`, `querySchema` | `table`, `setParams`, `relations`, `jsonArrayFields`, `onSuccess`, `onError`, `summary`, `tags` |
72
+ | `postOperation` | POST create | `bodySchema` | `table`, `outputBodySchema`, `setBody`, `onSuccess`, `onError`, `summary`, `tags` |
73
+ | `putOperation` | PUT update | `bodySchema` | `table`, `outputBodySchema`, `setBody`, `byCreator`, `onSuccess`, `onError`, `summary`, `tags` |
74
+ | `deleteOperation` | DELETE | — | `table`, `byCreator`, `onSuccess`, `onError`, `summary`, `tags` |
75
+
76
+ `tags` can be passed manually to override the default OpenAPI tag inferred from `table`.
77
+
78
+ `table` is optional for route operations. When omitted, the operation still parses input, applies `setParams` / `setBody`, session-derived fields, and `onSuccess`, but skips the built-in table action (`select` / `insert` / `update` / `delete`). Use this for custom endpoints that want the same OpenAPI and response wiring without a direct table operation.
75
79
 
76
80
  ## Canonical Examples
77
81
 
@@ -1,10 +1,11 @@
1
1
  import { TypedNextResponse } from "next-rest-framework";
2
2
  import { BaseTable } from "../types.js";
3
3
  export interface DeleteOperationOptions<TTable extends BaseTable> {
4
- table: TTable;
4
+ table?: TTable;
5
5
  summary?: string;
6
+ tags?: string[];
6
7
  onSuccess?: () => Promise<void>;
7
- onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
8
+ onError?(error: Error): Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
8
9
  byCreator?: boolean;
9
10
  }
10
11
  export declare const createDeleteOperation: any;
@@ -13,6 +13,7 @@ export var createDeleteOperation = function createDeleteOperation(_ref) {
13
13
  return function (_ref2) {
14
14
  var table = _ref2.table,
15
15
  summary = _ref2.summary,
16
+ tags = _ref2.tags,
16
17
  onSuccess = _ref2.onSuccess,
17
18
  onError = _ref2.onError,
18
19
  _ref2$byCreator = _ref2.byCreator,
@@ -21,7 +22,7 @@ export var createDeleteOperation = function createDeleteOperation(_ref) {
21
22
  method: "DELETE",
22
23
  openApiOperation: {
23
24
  summary: summary,
24
- tags: [getTableName(table)]
25
+ tags: tags !== null && tags !== void 0 ? tags : table ? [getTableName(table)] : []
25
26
  }
26
27
  }).input({
27
28
  body: z.object({
@@ -57,49 +58,61 @@ export var createDeleteOperation = function createDeleteOperation(_ref) {
57
58
  userId = _ref4.userId;
58
59
  body.creatorId = userId;
59
60
  case 13:
60
- _context.next = 15;
61
+ if (!table) {
62
+ _context.next = 19;
63
+ break;
64
+ }
65
+ _context.next = 16;
61
66
  return createDeleteAction({
62
67
  table: table,
63
68
  db: db
64
69
  })(body);
65
- case 15:
66
- data = _context.sent;
67
- _context.next = 18;
70
+ case 16:
71
+ _context.t1 = _context.sent;
72
+ _context.next = 20;
73
+ break;
74
+ case 19:
75
+ _context.t1 = body;
76
+ case 20:
77
+ data = _context.t1;
78
+ _context.next = 23;
68
79
  return onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess();
69
- case 18:
80
+ case 23:
70
81
  return _context.abrupt("return", TypedNextResponse.json(data, {
71
82
  status: 200
72
83
  }));
73
- case 21:
74
- _context.prev = 21;
75
- _context.t1 = _context["catch"](0);
76
- if (!(_context.t1 instanceof HttpError)) console.error(_context.t1);
77
- _context.next = 26;
78
- return onError === null || onError === void 0 ? void 0 : onError(_context.t1);
79
84
  case 26:
85
+ _context.prev = 26;
86
+ _context.t2 = _context["catch"](0);
87
+ if (!(_context.t2 instanceof HttpError)) {
88
+ console.error(_context.t2);
89
+ }
90
+ _context.next = 31;
91
+ return onError === null || onError === void 0 ? void 0 : onError(_context.t2);
92
+ case 31:
80
93
  response = _context.sent;
81
94
  if (!response) {
82
- _context.next = 29;
95
+ _context.next = 34;
83
96
  break;
84
97
  }
85
98
  return _context.abrupt("return", response);
86
- case 29:
87
- if (!(_context.t1 instanceof HttpError)) {
88
- _context.next = 31;
99
+ case 34:
100
+ if (!(_context.t2 instanceof HttpError)) {
101
+ _context.next = 36;
89
102
  break;
90
103
  }
91
104
  return _context.abrupt("return", TypedNextResponse.json({
92
- message: _context.t1.message
105
+ message: _context.t2.message
93
106
  }, {
94
- status: _context.t1.status
107
+ status: _context.t2.status
95
108
  }));
96
- case 31:
97
- throw _context.t1;
98
- case 32:
109
+ case 36:
110
+ throw _context.t2;
111
+ case 37:
99
112
  case "end":
100
113
  return _context.stop();
101
114
  }
102
- }, _callee, null, [[0, 21]]);
115
+ }, _callee, null, [[0, 26]]);
103
116
  }));
104
117
  return function (_x) {
105
118
  return _ref3.apply(this, arguments);
@@ -6,17 +6,18 @@ export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchem
6
6
  jsonArrayFields?: string[];
7
7
  querySchema: Q;
8
8
  relations?: GetListRelations;
9
- setParams?: (req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string, unknown>>;
9
+ setParams?(req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>): Promise<Record<string, unknown>>;
10
10
  byCreator?: boolean;
11
11
  summary?: string;
12
- table: TTable;
13
- onSuccess?: <D extends T>(data: {
12
+ tags?: string[];
13
+ table?: TTable;
14
+ onSuccess?<D extends T>(data: {
14
15
  data: z.infer<D>[];
15
16
  total: number;
16
- }) => Promise<{
17
+ }): Promise<{
17
18
  data: z.infer<T>[];
18
19
  total: number;
19
20
  }>;
20
- onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
21
+ onError?(error: Error): Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
21
22
  }
22
23
  export declare const createGetListOperation: any;
@@ -14,6 +14,7 @@ export var createGetListOperation = function createGetListOperation(_ref) {
14
14
  bodySchema = _ref2.bodySchema,
15
15
  table = _ref2.table,
16
16
  summary = _ref2.summary,
17
+ tags = _ref2.tags,
17
18
  relations = _ref2.relations,
18
19
  jsonArrayFields = _ref2.jsonArrayFields,
19
20
  setParams = _ref2.setParams,
@@ -25,7 +26,7 @@ export var createGetListOperation = function createGetListOperation(_ref) {
25
26
  method: "GET",
26
27
  openApiOperation: {
27
28
  summary: summary,
28
- tags: [getTableName(table)]
29
+ tags: tags !== null && tags !== void 0 ? tags : table ? [getTableName(table)] : []
29
30
  }
30
31
  }).input({
31
32
  query: querySchema
@@ -35,7 +36,7 @@ export var createGetListOperation = function createGetListOperation(_ref) {
35
36
  status: 200
36
37
  }]).handler( /*#__PURE__*/function () {
37
38
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
38
- var params, _ref4, userId, result, response;
39
+ var params, _ref4, userId, mergedParams, result, response;
39
40
  return _regeneratorRuntime().wrap(function _callee$(_context) {
40
41
  while (1) switch (_context.prev = _context.next) {
41
42
  case 0:
@@ -69,48 +70,62 @@ export var createGetListOperation = function createGetListOperation(_ref) {
69
70
  userId = _ref4.userId;
70
71
  params.creatorId = userId;
71
72
  case 16:
72
- _context.next = 18;
73
+ mergedParams = Object.assign(Object.fromEntries(new URL(req.url).searchParams), params);
74
+ if (!table) {
75
+ _context.next = 23;
76
+ break;
77
+ }
78
+ _context.next = 20;
73
79
  return createGetListAction({
74
80
  bodySchema: bodySchema,
75
81
  db: db,
76
82
  jsonArrayFields: jsonArrayFields,
77
83
  relations: relations,
78
84
  table: table
79
- })(Object.assign(Object.fromEntries(new URL(req.url).searchParams), params));
80
- case 18:
81
- result = _context.sent;
85
+ })(mergedParams);
86
+ case 20:
87
+ _context.t2 = _context.sent;
88
+ _context.next = 24;
89
+ break;
90
+ case 23:
91
+ _context.t2 = {
92
+ data: [],
93
+ total: 0
94
+ };
95
+ case 24:
96
+ result = _context.t2;
82
97
  if (!onSuccess) {
83
- _context.next = 23;
98
+ _context.next = 29;
84
99
  break;
85
100
  }
86
- _context.next = 22;
101
+ _context.next = 28;
87
102
  return onSuccess(result);
88
- case 22:
103
+ case 28:
89
104
  result = _context.sent;
90
- case 23:
105
+ case 29:
91
106
  return _context.abrupt("return", TypedNextResponse.json(result, {
92
107
  status: 200
93
108
  }));
94
- case 26:
95
- _context.prev = 26;
96
- _context.t2 = _context["catch"](0);
97
- console.error(_context.t2);
98
- _context.next = 31;
99
- return onError === null || onError === void 0 ? void 0 : onError(_context.t2);
100
- case 31:
109
+ case 32:
110
+ _context.prev = 32;
111
+ _context.t3 = _context["catch"](0);
112
+ console.error(_context.t3);
113
+ _context.next = 37;
114
+ return onError === null || onError === void 0 ? void 0 : onError(_context.t3);
115
+ case 37:
101
116
  response = _context.sent;
102
117
  if (!response) {
103
- _context.next = 36;
118
+ _context.next = 42;
104
119
  break;
105
120
  }
106
121
  return _context.abrupt("return", response);
107
- case 36:
108
- throw _context.t2;
109
- case 37:
122
+ case 42:
123
+ throw _context.t3;
124
+ case 43:
110
125
  case "end":
111
126
  return _context.stop();
112
127
  }
113
- }, _callee, null, [[0, 26]]);
128
+ }, _callee, null, [[0, 32]]);
114
129
  }));
115
130
  return function (_x) {
116
131
  return _ref3.apply(this, arguments);
@@ -6,11 +6,12 @@ export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, T
6
6
  jsonArrayFields?: string[];
7
7
  querySchema: Q;
8
8
  relations?: GetListRelations;
9
- setParams?: (req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string, unknown>>;
10
- onSuccess?: (data: z.infer<T>) => Promise<z.infer<T>>;
11
- onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
9
+ setParams?(req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>): Promise<Record<string, unknown>>;
10
+ onSuccess?(data: z.infer<T>): Promise<z.infer<T>>;
11
+ onError?(error: Error): Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
12
12
  summary?: string;
13
- table: TTable;
13
+ tags?: string[];
14
+ table?: TTable;
14
15
  byCreator?: boolean;
15
16
  }
16
17
  export declare const createGetOperation: any;
@@ -13,6 +13,7 @@ export var createGetOperation = function createGetOperation(_ref) {
13
13
  bodySchema = _ref2.bodySchema,
14
14
  table = _ref2.table,
15
15
  summary = _ref2.summary,
16
+ tags = _ref2.tags,
16
17
  relations = _ref2.relations,
17
18
  setParams = _ref2.setParams,
18
19
  jsonArrayFields = _ref2.jsonArrayFields,
@@ -24,7 +25,7 @@ export var createGetOperation = function createGetOperation(_ref) {
24
25
  method: "GET",
25
26
  openApiOperation: {
26
27
  summary: summary,
27
- tags: [getTableName(table)]
28
+ tags: tags !== null && tags !== void 0 ? tags : table ? [getTableName(table)] : []
28
29
  }
29
30
  }).input({
30
31
  query: querySchema
@@ -34,7 +35,7 @@ export var createGetOperation = function createGetOperation(_ref) {
34
35
  status: 200
35
36
  }]).handler( /*#__PURE__*/function () {
36
37
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
37
- var params, _ref4, userId, rawResult, result, response;
38
+ var params, _ref4, userId, mergedParams, rawResult, result, response;
38
39
  return _regeneratorRuntime().wrap(function _callee$(_context) {
39
40
  while (1) switch (_context.prev = _context.next) {
40
41
  case 0:
@@ -68,49 +69,60 @@ export var createGetOperation = function createGetOperation(_ref) {
68
69
  userId = _ref4.userId;
69
70
  params.creatorId = userId;
70
71
  case 16:
71
- _context.next = 18;
72
+ mergedParams = Object.assign(Object.fromEntries(new URL(req.url).searchParams), params);
73
+ if (!table) {
74
+ _context.next = 23;
75
+ break;
76
+ }
77
+ _context.next = 20;
72
78
  return createGetAction({
73
79
  bodySchema: bodySchema,
74
80
  db: db,
75
81
  jsonArrayFields: jsonArrayFields,
76
82
  relations: relations,
77
83
  table: table
78
- })(Object.assign(Object.fromEntries(new URL(req.url).searchParams), params));
79
- case 18:
80
- rawResult = _context.sent;
84
+ })(mergedParams);
85
+ case 20:
86
+ _context.t2 = _context.sent;
87
+ _context.next = 24;
88
+ break;
89
+ case 23:
90
+ _context.t2 = mergedParams;
91
+ case 24:
92
+ rawResult = _context.t2;
81
93
  result = rawResult !== null && rawResult !== void 0 ? rawResult : {};
82
94
  if (!onSuccess) {
83
- _context.next = 24;
95
+ _context.next = 30;
84
96
  break;
85
97
  }
86
- _context.next = 23;
98
+ _context.next = 29;
87
99
  return onSuccess(result);
88
- case 23:
100
+ case 29:
89
101
  result = _context.sent;
90
- case 24:
102
+ case 30:
91
103
  return _context.abrupt("return", TypedNextResponse.json(result, {
92
104
  status: 200
93
105
  }));
94
- case 27:
95
- _context.prev = 27;
96
- _context.t2 = _context["catch"](0);
97
- console.error(_context.t2);
98
- _context.next = 32;
99
- return onError === null || onError === void 0 ? void 0 : onError(_context.t2);
100
- case 32:
106
+ case 33:
107
+ _context.prev = 33;
108
+ _context.t3 = _context["catch"](0);
109
+ console.error(_context.t3);
110
+ _context.next = 38;
111
+ return onError === null || onError === void 0 ? void 0 : onError(_context.t3);
112
+ case 38:
101
113
  response = _context.sent;
102
114
  if (!response) {
103
- _context.next = 37;
115
+ _context.next = 43;
104
116
  break;
105
117
  }
106
118
  return _context.abrupt("return", response);
107
- case 37:
108
- throw _context.t2;
109
- case 38:
119
+ case 43:
120
+ throw _context.t3;
121
+ case 44:
110
122
  case "end":
111
123
  return _context.stop();
112
124
  }
113
- }, _callee, null, [[0, 27]]);
125
+ }, _callee, null, [[0, 33]]);
114
126
  }));
115
127
  return function (_x) {
116
128
  return _ref3.apply(this, arguments);
@@ -4,10 +4,11 @@ import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
4
4
  export interface PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends PgTable> {
5
5
  bodySchema: IB;
6
6
  outputBodySchema?: IB;
7
- setBody?: (req: TypedNextRequest<"POST", "application/json", z.infer<IB>>) => Promise<Partial<z.infer<IB>>>;
7
+ setBody?(req: TypedNextRequest<"POST", "application/json", z.infer<IB>>): Promise<Partial<z.infer<IB>>>;
8
8
  summary?: string;
9
- onSuccess?: (data: z.infer<OB>) => Promise<z.infer<OB>>;
10
- onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
11
- table: TTable;
9
+ tags?: string[];
10
+ onSuccess?(data: z.infer<OB>): Promise<z.infer<OB>>;
11
+ onError?(error: Error): Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
12
+ table?: TTable;
12
13
  }
13
14
  export declare const createPostOperation: any;