@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.
- package/.agents/skills/ai0x0-utils/backend/SKILL.md +12 -8
- package/README.md +42 -1
- package/SKILL.md +12 -8
- package/es/backend/route-operation/delete-operation.d.ts +3 -2
- package/es/backend/route-operation/delete-operation.js +35 -22
- package/es/backend/route-operation/get-list-operation.d.ts +6 -5
- package/es/backend/route-operation/get-list-operation.js +37 -22
- package/es/backend/route-operation/get-operation.d.ts +5 -4
- package/es/backend/route-operation/get-operation.js +34 -22
- package/es/backend/route-operation/post-operation.d.ts +5 -4
- package/es/backend/route-operation/post-operation.js +39 -34
- package/es/backend/route-operation/put-operation.d.ts +5 -4
- package/es/backend/route-operation/put-operation.js +44 -29
- package/es/backend/sqlite/actions/create-delete-action.d.ts +8 -0
- package/es/backend/sqlite/actions/create-delete-action.js +54 -0
- package/es/backend/sqlite/actions/create-get-action.d.ts +8 -0
- package/es/backend/sqlite/actions/create-get-action.js +64 -0
- package/es/backend/sqlite/actions/create-get-list-action.d.ts +11 -0
- package/es/backend/sqlite/actions/create-get-list-action.js +56 -0
- package/es/backend/sqlite/actions/create-post-action.d.ts +6 -0
- package/es/backend/sqlite/actions/create-post-action.js +31 -0
- package/es/backend/sqlite/actions/create-put-action.d.ts +8 -0
- package/es/backend/sqlite/actions/create-put-action.js +74 -0
- package/es/backend/sqlite/actions/get-list-data.d.ts +9 -0
- package/es/backend/sqlite/actions/get-list-data.js +75 -0
- package/es/backend/sqlite/actions/get-list-query.d.ts +19 -0
- package/es/backend/sqlite/actions/get-list-query.js +215 -0
- package/es/backend/sqlite/actions/index.d.ts +6 -0
- package/es/backend/sqlite/actions/index.js +6 -0
- package/es/backend/sqlite/actions/transform-body.d.ts +1 -0
- package/es/backend/sqlite/actions/transform-body.js +9 -0
- package/es/backend/sqlite/errors.d.ts +4 -0
- package/es/backend/sqlite/errors.js +31 -0
- package/es/backend/sqlite/index.d.ts +5 -0
- package/es/backend/sqlite/index.js +5 -0
- package/es/backend/sqlite/route-operation/delete-operation.d.ts +11 -0
- package/es/backend/sqlite/route-operation/delete-operation.js +122 -0
- package/es/backend/sqlite/route-operation/get-list-operation.d.ts +23 -0
- package/es/backend/sqlite/route-operation/get-list-operation.js +135 -0
- package/es/backend/sqlite/route-operation/get-operation.d.ts +17 -0
- package/es/backend/sqlite/route-operation/get-operation.js +132 -0
- package/es/backend/sqlite/route-operation/get-table-name.d.ts +3 -0
- package/es/backend/sqlite/route-operation/get-table-name.js +11 -0
- package/es/backend/sqlite/route-operation/index.d.ts +5 -0
- package/es/backend/sqlite/route-operation/index.js +5 -0
- package/es/backend/sqlite/route-operation/post-operation.d.ts +14 -0
- package/es/backend/sqlite/route-operation/post-operation.js +141 -0
- package/es/backend/sqlite/route-operation/put-operation.d.ts +15 -0
- package/es/backend/sqlite/route-operation/put-operation.js +156 -0
- package/es/backend/sqlite/schemas/index.d.ts +68 -0
- package/es/backend/sqlite/schemas/index.js +133 -0
- package/es/backend/sqlite/types.d.ts +16 -0
- package/es/backend/sqlite/types.js +1 -0
- package/lib/backend/route-operation/delete-operation.d.ts +3 -2
- package/lib/backend/route-operation/delete-operation.js +5 -3
- package/lib/backend/route-operation/get-list-operation.d.ts +6 -5
- package/lib/backend/route-operation/get-list-operation.js +8 -8
- package/lib/backend/route-operation/get-operation.d.ts +5 -4
- package/lib/backend/route-operation/get-operation.js +8 -8
- package/lib/backend/route-operation/post-operation.d.ts +5 -4
- package/lib/backend/route-operation/post-operation.js +4 -3
- package/lib/backend/route-operation/put-operation.d.ts +5 -4
- package/lib/backend/route-operation/put-operation.js +6 -4
- package/lib/backend/sqlite/actions/create-delete-action.d.ts +8 -0
- package/lib/backend/sqlite/actions/create-delete-action.js +53 -0
- package/lib/backend/sqlite/actions/create-get-action.d.ts +8 -0
- package/lib/backend/sqlite/actions/create-get-action.js +65 -0
- package/lib/backend/sqlite/actions/create-get-list-action.d.ts +11 -0
- package/lib/backend/sqlite/actions/create-get-list-action.js +63 -0
- package/lib/backend/sqlite/actions/create-post-action.d.ts +6 -0
- package/lib/backend/sqlite/actions/create-post-action.js +39 -0
- package/lib/backend/sqlite/actions/create-put-action.d.ts +8 -0
- package/lib/backend/sqlite/actions/create-put-action.js +60 -0
- package/lib/backend/sqlite/actions/get-list-data.d.ts +9 -0
- package/lib/backend/sqlite/actions/get-list-data.js +51 -0
- package/lib/backend/sqlite/actions/get-list-query.d.ts +19 -0
- package/lib/backend/sqlite/actions/get-list-query.js +165 -0
- package/lib/backend/sqlite/actions/index.d.ts +6 -0
- package/lib/backend/sqlite/actions/index.js +44 -0
- package/lib/backend/sqlite/actions/transform-body.d.ts +1 -0
- package/lib/backend/sqlite/actions/transform-body.js +49 -0
- package/lib/backend/sqlite/errors.d.ts +4 -0
- package/lib/backend/sqlite/errors.js +35 -0
- package/lib/backend/sqlite/index.d.ts +5 -0
- package/lib/backend/sqlite/index.js +31 -0
- package/lib/backend/sqlite/route-operation/delete-operation.d.ts +11 -0
- package/lib/backend/sqlite/route-operation/delete-operation.js +92 -0
- package/lib/backend/sqlite/route-operation/get-list-operation.d.ts +23 -0
- package/lib/backend/sqlite/route-operation/get-list-operation.js +108 -0
- package/lib/backend/sqlite/route-operation/get-operation.d.ts +17 -0
- package/lib/backend/sqlite/route-operation/get-operation.js +107 -0
- package/lib/backend/sqlite/route-operation/get-table-name.d.ts +3 -0
- package/lib/backend/sqlite/route-operation/get-table-name.js +35 -0
- package/lib/backend/sqlite/route-operation/index.d.ts +5 -0
- package/lib/backend/sqlite/route-operation/index.js +31 -0
- package/lib/backend/sqlite/route-operation/post-operation.d.ts +14 -0
- package/lib/backend/sqlite/route-operation/post-operation.js +95 -0
- package/lib/backend/sqlite/route-operation/put-operation.d.ts +15 -0
- package/lib/backend/sqlite/route-operation/put-operation.js +104 -0
- package/lib/backend/sqlite/schemas/index.d.ts +68 -0
- package/lib/backend/sqlite/schemas/index.js +113 -0
- package/lib/backend/sqlite/types.d.ts +16 -0
- package/lib/backend/sqlite/types.js +17 -0
- 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
|
|
89
|
-
| ------------------- | -------------------------- |
|
|
90
|
-
| `createTableSchema` | pg `Table` + 5 zod schemas | `name`, `columns`
|
|
91
|
-
| `getOperation` | GET one by filters | `
|
|
92
|
-
| `getListOperation` | GET paginated list | `
|
|
93
|
-
| `postOperation` | POST create | `
|
|
94
|
-
| `putOperation` | PUT update | `
|
|
95
|
-
| `deleteOperation` | DELETE | `table
|
|
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
|
|
68
|
-
| ------------------- | -------------------------- |
|
|
69
|
-
| `createTableSchema` | pg `Table` + 5 zod schemas | `name`, `columns`
|
|
70
|
-
| `getOperation` | GET one by filters | `
|
|
71
|
-
| `getListOperation` | GET paginated list | `
|
|
72
|
-
| `postOperation` | POST create | `
|
|
73
|
-
| `putOperation` | PUT update | `
|
|
74
|
-
| `deleteOperation` | DELETE | `table
|
|
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
|
|
4
|
+
table?: TTable;
|
|
5
5
|
summary?: string;
|
|
6
|
+
tags?: string[];
|
|
6
7
|
onSuccess?: () => Promise<void>;
|
|
7
|
-
onError
|
|
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
|
-
|
|
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
|
|
66
|
-
|
|
67
|
-
_context.next =
|
|
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
|
|
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 =
|
|
95
|
+
_context.next = 34;
|
|
83
96
|
break;
|
|
84
97
|
}
|
|
85
98
|
return _context.abrupt("return", response);
|
|
86
|
-
case
|
|
87
|
-
if (!(_context.
|
|
88
|
-
_context.next =
|
|
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.
|
|
105
|
+
message: _context.t2.message
|
|
93
106
|
}, {
|
|
94
|
-
status: _context.
|
|
107
|
+
status: _context.t2.status
|
|
95
108
|
}));
|
|
96
|
-
case
|
|
97
|
-
throw _context.
|
|
98
|
-
case
|
|
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,
|
|
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
|
|
9
|
+
setParams?(req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>): Promise<Record<string, unknown>>;
|
|
10
10
|
byCreator?: boolean;
|
|
11
11
|
summary?: string;
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
tags?: string[];
|
|
13
|
+
table?: TTable;
|
|
14
|
+
onSuccess?<D extends T>(data: {
|
|
14
15
|
data: z.infer<D>[];
|
|
15
16
|
total: number;
|
|
16
|
-
})
|
|
17
|
+
}): Promise<{
|
|
17
18
|
data: z.infer<T>[];
|
|
18
19
|
total: number;
|
|
19
20
|
}>;
|
|
20
|
-
onError
|
|
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
|
-
|
|
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
|
-
})(
|
|
80
|
-
case
|
|
81
|
-
|
|
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 =
|
|
98
|
+
_context.next = 29;
|
|
84
99
|
break;
|
|
85
100
|
}
|
|
86
|
-
_context.next =
|
|
101
|
+
_context.next = 28;
|
|
87
102
|
return onSuccess(result);
|
|
88
|
-
case
|
|
103
|
+
case 28:
|
|
89
104
|
result = _context.sent;
|
|
90
|
-
case
|
|
105
|
+
case 29:
|
|
91
106
|
return _context.abrupt("return", TypedNextResponse.json(result, {
|
|
92
107
|
status: 200
|
|
93
108
|
}));
|
|
94
|
-
case
|
|
95
|
-
_context.prev =
|
|
96
|
-
_context.
|
|
97
|
-
console.error(_context.
|
|
98
|
-
_context.next =
|
|
99
|
-
return onError === null || onError === void 0 ? void 0 : onError(_context.
|
|
100
|
-
case
|
|
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 =
|
|
118
|
+
_context.next = 42;
|
|
104
119
|
break;
|
|
105
120
|
}
|
|
106
121
|
return _context.abrupt("return", response);
|
|
107
|
-
case
|
|
108
|
-
throw _context.
|
|
109
|
-
case
|
|
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,
|
|
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
|
|
10
|
-
onSuccess
|
|
11
|
-
onError
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
})(
|
|
79
|
-
case
|
|
80
|
-
|
|
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 =
|
|
95
|
+
_context.next = 30;
|
|
84
96
|
break;
|
|
85
97
|
}
|
|
86
|
-
_context.next =
|
|
98
|
+
_context.next = 29;
|
|
87
99
|
return onSuccess(result);
|
|
88
|
-
case
|
|
100
|
+
case 29:
|
|
89
101
|
result = _context.sent;
|
|
90
|
-
case
|
|
102
|
+
case 30:
|
|
91
103
|
return _context.abrupt("return", TypedNextResponse.json(result, {
|
|
92
104
|
status: 200
|
|
93
105
|
}));
|
|
94
|
-
case
|
|
95
|
-
_context.prev =
|
|
96
|
-
_context.
|
|
97
|
-
console.error(_context.
|
|
98
|
-
_context.next =
|
|
99
|
-
return onError === null || onError === void 0 ? void 0 : onError(_context.
|
|
100
|
-
case
|
|
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 =
|
|
115
|
+
_context.next = 43;
|
|
104
116
|
break;
|
|
105
117
|
}
|
|
106
118
|
return _context.abrupt("return", response);
|
|
107
|
-
case
|
|
108
|
-
throw _context.
|
|
109
|
-
case
|
|
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,
|
|
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
|
|
7
|
+
setBody?(req: TypedNextRequest<"POST", "application/json", z.infer<IB>>): Promise<Partial<z.infer<IB>>>;
|
|
8
8
|
summary?: string;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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;
|