@ai0x0/utils 0.0.3 → 0.0.5
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/es/backend/actions/create-delete-action.d.ts +6 -0
- package/es/backend/actions/{delete-action-fn.js → create-delete-action.js} +3 -8
- package/es/backend/actions/{get-list-action-fn.d.ts → create-get-action.d.ts} +4 -5
- package/es/backend/actions/{get-action-fn.js → create-get-action.js} +4 -12
- package/es/backend/actions/create-get-list-action.d.ts +13 -0
- package/es/backend/actions/{get-list-action-fn.js → create-get-list-action.js} +3 -12
- package/es/backend/actions/create-post-action.d.ts +8 -0
- package/es/backend/actions/{post-action-fn.js → create-post-action.js} +4 -14
- package/es/backend/actions/create-put-action.d.ts +8 -0
- package/es/backend/actions/{put-action-fn.js → create-put-action.js} +4 -12
- package/es/backend/actions/get-list-data.d.ts +16 -1
- package/es/backend/actions/index.d.ts +5 -5
- package/es/backend/actions/index.js +5 -5
- package/es/backend/route-operation/delete-operation.d.ts +3 -2
- package/es/backend/route-operation/delete-operation.js +13 -11
- package/es/backend/route-operation/get-list-operation.d.ts +3 -3
- package/es/backend/route-operation/get-list-operation.js +5 -6
- package/es/backend/route-operation/get-operation.d.ts +4 -3
- package/es/backend/route-operation/get-operation.js +20 -4
- package/es/backend/route-operation/post-operation.d.ts +3 -2
- package/es/backend/route-operation/post-operation.js +18 -8
- package/es/backend/route-operation/put-operation.d.ts +4 -2
- package/es/backend/route-operation/put-operation.js +20 -12
- package/es/backend/schemas/index.d.ts +10 -2
- package/es/backend/schemas/index.js +1 -1
- package/es/backend/types.d.ts +5 -1
- package/lib/backend/actions/create-delete-action.d.ts +6 -0
- package/lib/backend/actions/{delete-action-fn.js → create-delete-action.js} +9 -14
- package/lib/backend/actions/{get-list-action-fn.d.ts → create-get-action.d.ts} +4 -5
- package/lib/backend/actions/{get-action-fn.js → create-get-action.js} +10 -20
- package/lib/backend/actions/create-get-list-action.d.ts +13 -0
- package/lib/backend/actions/{get-list-action-fn.js → create-get-list-action.js} +9 -20
- package/lib/backend/actions/create-post-action.d.ts +8 -0
- package/lib/backend/actions/{post-action-fn.js → create-post-action.js} +9 -21
- package/lib/backend/actions/create-put-action.d.ts +8 -0
- package/lib/backend/actions/{put-action-fn.js → create-put-action.js} +9 -14
- package/lib/backend/actions/get-list-data.d.ts +16 -1
- package/lib/backend/actions/index.d.ts +5 -5
- package/lib/backend/actions/index.js +17 -17
- package/lib/backend/route-operation/delete-operation.d.ts +3 -2
- package/lib/backend/route-operation/delete-operation.js +8 -2
- package/lib/backend/route-operation/get-list-operation.d.ts +3 -3
- package/lib/backend/route-operation/get-list-operation.js +4 -5
- package/lib/backend/route-operation/get-operation.d.ts +4 -3
- package/lib/backend/route-operation/get-operation.js +6 -3
- package/lib/backend/route-operation/post-operation.d.ts +3 -2
- package/lib/backend/route-operation/post-operation.js +11 -2
- package/lib/backend/route-operation/put-operation.d.ts +4 -2
- package/lib/backend/route-operation/put-operation.js +19 -12
- package/lib/backend/schemas/index.d.ts +10 -2
- package/lib/backend/schemas/index.js +2 -0
- package/lib/backend/types.d.ts +5 -1
- package/package.json +3 -3
- package/es/backend/actions/delete-action-fn.d.ts +0 -6
- package/es/backend/actions/get-action-fn.d.ts +0 -11
- package/es/backend/actions/post-action-fn.d.ts +0 -12
- package/es/backend/actions/put-action-fn.d.ts +0 -8
- package/lib/backend/actions/delete-action-fn.d.ts +0 -6
- package/lib/backend/actions/get-action-fn.d.ts +0 -11
- package/lib/backend/actions/post-action-fn.d.ts +0 -12
- package/lib/backend/actions/put-action-fn.d.ts +0 -8
|
@@ -16,7 +16,7 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
|
|
|
16
16
|
import { z } from "zod";
|
|
17
17
|
import { routeOperation, TypedNextResponse } from "next-rest-framework";
|
|
18
18
|
import getTableName from "./get-table-name";
|
|
19
|
-
import {
|
|
19
|
+
import { createPostAction } from "../actions";
|
|
20
20
|
export var createPostOperation = function createPostOperation(_ref) {
|
|
21
21
|
var getSession = _ref.getSession,
|
|
22
22
|
db = _ref.db;
|
|
@@ -24,7 +24,8 @@ export var createPostOperation = function createPostOperation(_ref) {
|
|
|
24
24
|
var bodySchema = _ref2.bodySchema,
|
|
25
25
|
setBody = _ref2.setBody,
|
|
26
26
|
summary = _ref2.summary,
|
|
27
|
-
table = _ref2.table
|
|
27
|
+
table = _ref2.table,
|
|
28
|
+
onSuccess = _ref2.onSuccess;
|
|
28
29
|
return routeOperation({
|
|
29
30
|
method: "POST",
|
|
30
31
|
openApiOperation: {
|
|
@@ -42,7 +43,7 @@ export var createPostOperation = function createPostOperation(_ref) {
|
|
|
42
43
|
status: 200
|
|
43
44
|
}]).handler( /*#__PURE__*/function () {
|
|
44
45
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
|
|
45
|
-
var _ref4, userId, body, _yield$
|
|
46
|
+
var _ref4, userId, body, _yield$createPostActi, _yield$createPostActi2, data;
|
|
46
47
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
47
48
|
while (1) switch (_context.prev = _context.next) {
|
|
48
49
|
case 0:
|
|
@@ -76,7 +77,7 @@ export var createPostOperation = function createPostOperation(_ref) {
|
|
|
76
77
|
_context.t4 = _context.sent;
|
|
77
78
|
body = _context.t1.assign.call(_context.t1, _context.t3, _context.t4);
|
|
78
79
|
_context.next = 20;
|
|
79
|
-
return
|
|
80
|
+
return createPostAction({
|
|
80
81
|
bodySchema: bodySchema,
|
|
81
82
|
db: db,
|
|
82
83
|
table: table
|
|
@@ -84,13 +85,22 @@ export var createPostOperation = function createPostOperation(_ref) {
|
|
|
84
85
|
creatorId: userId
|
|
85
86
|
}));
|
|
86
87
|
case 20:
|
|
87
|
-
_yield$
|
|
88
|
-
_yield$
|
|
89
|
-
data = _yield$
|
|
88
|
+
_yield$createPostActi = _context.sent;
|
|
89
|
+
_yield$createPostActi2 = _slicedToArray(_yield$createPostActi, 1);
|
|
90
|
+
data = _yield$createPostActi2[0];
|
|
91
|
+
if (!onSuccess) {
|
|
92
|
+
_context.next = 27;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
_context.next = 26;
|
|
96
|
+
return onSuccess(data);
|
|
97
|
+
case 26:
|
|
98
|
+
data = _context.sent;
|
|
99
|
+
case 27:
|
|
90
100
|
return _context.abrupt("return", TypedNextResponse.json(data, {
|
|
91
101
|
status: 200
|
|
92
102
|
}));
|
|
93
|
-
case
|
|
103
|
+
case 28:
|
|
94
104
|
case "end":
|
|
95
105
|
return _context.stop();
|
|
96
106
|
}
|
|
@@ -2,15 +2,17 @@ import { z, ZodSchema } from "zod";
|
|
|
2
2
|
import { PgTable } from "drizzle-orm/pg-core";
|
|
3
3
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
4
4
|
import { NextRequest } from "next/server";
|
|
5
|
+
import { BaseTable } from "../types";
|
|
5
6
|
export interface PutOperationOptions<T extends ZodSchema, TTable extends PgTable> {
|
|
6
7
|
bodySchema: T;
|
|
7
8
|
table: TTable;
|
|
8
9
|
summary?: string;
|
|
9
10
|
setBody?: (req: NextRequest) => Promise<Partial<z.infer<T>>>;
|
|
11
|
+
onSuccess?: (data: z.infer<T>) => Promise<z.infer<T>>;
|
|
10
12
|
}
|
|
11
|
-
export declare const createPutOperation:
|
|
13
|
+
export declare const createPutOperation: ({ getSession, db, }: {
|
|
12
14
|
getSession: (req: NextRequest) => Promise<{
|
|
13
15
|
userId?: string;
|
|
14
16
|
} | undefined>;
|
|
15
17
|
db: NodePgDatabase<any>;
|
|
16
|
-
}) => ({ bodySchema, table, summary, setBody }: PutOperationOptions<T, TTable>) => any;
|
|
18
|
+
}) => <T extends z.ZodType<any, z.ZodTypeDef, any>, TTable extends BaseTable>({ bodySchema, table, summary, setBody, onSuccess, }: PutOperationOptions<T, TTable>) => any;
|
|
@@ -9,7 +9,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
9
9
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
10
10
|
import { routeOperation, TypedNextResponse } from "next-rest-framework";
|
|
11
11
|
import getTableName from "./get-table-name";
|
|
12
|
-
import {
|
|
12
|
+
import { createPutAction } from "../actions";
|
|
13
13
|
export var createPutOperation = function createPutOperation(_ref) {
|
|
14
14
|
var getSession = _ref.getSession,
|
|
15
15
|
db = _ref.db;
|
|
@@ -17,7 +17,8 @@ export var createPutOperation = function createPutOperation(_ref) {
|
|
|
17
17
|
var bodySchema = _ref2.bodySchema,
|
|
18
18
|
table = _ref2.table,
|
|
19
19
|
summary = _ref2.summary,
|
|
20
|
-
setBody = _ref2.setBody
|
|
20
|
+
setBody = _ref2.setBody,
|
|
21
|
+
onSuccess = _ref2.onSuccess;
|
|
21
22
|
return routeOperation({
|
|
22
23
|
method: "PUT",
|
|
23
24
|
openApiOperation: {
|
|
@@ -29,7 +30,7 @@ export var createPutOperation = function createPutOperation(_ref) {
|
|
|
29
30
|
contentType: "application/json"
|
|
30
31
|
}).handler( /*#__PURE__*/function () {
|
|
31
32
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req) {
|
|
32
|
-
var _ref4, userId, body;
|
|
33
|
+
var _ref4, userId, body, data;
|
|
33
34
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
34
35
|
while (1) switch (_context.prev = _context.next) {
|
|
35
36
|
case 0:
|
|
@@ -62,22 +63,29 @@ export var createPutOperation = function createPutOperation(_ref) {
|
|
|
62
63
|
case 16:
|
|
63
64
|
_context.t4 = _context.sent;
|
|
64
65
|
body = _context.t1.assign.call(_context.t1, _context.t3, _context.t4);
|
|
65
|
-
_context.
|
|
66
|
-
|
|
67
|
-
return putActionFn({
|
|
66
|
+
_context.next = 20;
|
|
67
|
+
return createPutAction({
|
|
68
68
|
bodySchema: bodySchema,
|
|
69
69
|
table: table,
|
|
70
70
|
db: db
|
|
71
71
|
})(_objectSpread(_objectSpread({}, body), {}, {
|
|
72
72
|
editorId: userId
|
|
73
73
|
}));
|
|
74
|
-
case
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
case 20:
|
|
75
|
+
data = _context.sent;
|
|
76
|
+
if (!onSuccess) {
|
|
77
|
+
_context.next = 25;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
_context.next = 24;
|
|
81
|
+
return onSuccess(data);
|
|
80
82
|
case 24:
|
|
83
|
+
data = _context.sent;
|
|
84
|
+
case 25:
|
|
85
|
+
return _context.abrupt("return", TypedNextResponse.json(data, {
|
|
86
|
+
status: 200
|
|
87
|
+
}));
|
|
88
|
+
case 26:
|
|
81
89
|
case "end":
|
|
82
90
|
return _context.stop();
|
|
83
91
|
}
|
|
@@ -2,6 +2,14 @@ import { AnyZodObject, z } from "zod";
|
|
|
2
2
|
import { PgColumnBuilderBase, PgTableExtraConfigValue } from "drizzle-orm/pg-core";
|
|
3
3
|
import { BuildExtraConfigColumns } from "drizzle-orm";
|
|
4
4
|
import { BuildSchema } from "drizzle-zod/schema.types.internal";
|
|
5
|
+
export declare const basicFields: {
|
|
6
|
+
id: import("drizzle-orm").IsPrimaryKey<import("drizzle-orm").NotNull<import("drizzle-orm").HasDefault<import("drizzle-orm/pg-core").PgUUIDBuilderInitial<"id">>>>;
|
|
7
|
+
creatorId: import("drizzle-orm/pg-core").PgUUIDBuilderInitial<"creator_id">;
|
|
8
|
+
editorId: import("drizzle-orm/pg-core").PgUUIDBuilderInitial<"editor_id">;
|
|
9
|
+
accessedAt: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<string>>>;
|
|
10
|
+
createdAt: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<string>>>;
|
|
11
|
+
updatedAt: import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/pg-core").PgTimestampBuilderInitial<string>>>;
|
|
12
|
+
};
|
|
5
13
|
export declare const queryListSchema: <Incoming extends AnyZodObject>(schema: Incoming) => z.ZodObject<z.objectUtil.extendShape<{
|
|
6
14
|
current: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
7
15
|
pageSize: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
@@ -4665,9 +4673,9 @@ export declare const createTableSchema: <TTableName extends string, TColumnsMap
|
|
|
4665
4673
|
queryListSchema: z.ZodObject<{} & {
|
|
4666
4674
|
[x: string]: z.ZodOptional<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<any | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null> | z.ZodNullable<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<any | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many">> | z.ZodOptional<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<any | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many">> | z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<z.ZodArray<any | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many"> | z.ZodTuple<[any, ...any[]], null>, "many">>> | z.ZodNullable<z.ZodTuple<[any, ...any[]], null>> | z.ZodOptional<z.ZodTuple<[any, ...any[]], null>> | z.ZodOptional<z.ZodNullable<z.ZodTuple<[any, ...any[]], null>>>>;
|
|
4667
4675
|
}, "strip", z.ZodTypeAny, {
|
|
4668
|
-
[x: string]: [any, ...any[]] |
|
|
4676
|
+
[x: string]: unknown[] | [any, ...any[]] | null | undefined;
|
|
4669
4677
|
}, {
|
|
4670
|
-
[x: string]: [any, ...any[]] |
|
|
4678
|
+
[x: string]: unknown[] | [any, ...any[]] | null | undefined;
|
|
4671
4679
|
}>;
|
|
4672
4680
|
queryListSelectSchema: BuildSchema<any, any, any>;
|
|
4673
4681
|
};
|
|
@@ -22,7 +22,7 @@ var updatedAt = function updatedAt() {
|
|
|
22
22
|
var accessedAt = function accessedAt() {
|
|
23
23
|
return timestamptz("accessed_at").notNull().defaultNow();
|
|
24
24
|
};
|
|
25
|
-
var basicFields = {
|
|
25
|
+
export var basicFields = {
|
|
26
26
|
id: uuid("id").defaultRandom().primaryKey(),
|
|
27
27
|
creatorId: uuid("creator_id"),
|
|
28
28
|
editorId: uuid("editor_id"),
|
package/es/backend/types.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { PgColumn, PgTable } from "drizzle-orm/pg-core";
|
|
2
2
|
import { SQL } from "drizzle-orm";
|
|
3
3
|
export interface BaseTable extends PgTable {
|
|
4
|
-
createdAt: PgColumn;
|
|
5
4
|
id: PgColumn;
|
|
5
|
+
creatorId: PgColumn;
|
|
6
|
+
editorId: PgColumn;
|
|
7
|
+
accessedAt: PgColumn;
|
|
8
|
+
createdAt: PgColumn;
|
|
9
|
+
updatedAt: PgColumn;
|
|
6
10
|
}
|
|
7
11
|
export type GetListRelations = {
|
|
8
12
|
groupBy?: boolean;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
2
|
+
import { BaseTable } from "../types";
|
|
3
|
+
export declare function createDeleteAction<TTable extends BaseTable>({ table, db, }: {
|
|
4
|
+
db: NodePgDatabase<any>;
|
|
5
|
+
table: TTable;
|
|
6
|
+
}): (id: string) => Promise<TTable["$inferSelect"] extends infer T ? T extends TTable["$inferSelect"] ? T extends undefined ? QueryResult<import("drizzle-orm").Assume<this["row"], QueryResultRow>> : T[] : never : never>;
|
|
@@ -16,27 +16,22 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
18
|
|
|
19
|
-
// src/backend/actions/delete-action
|
|
20
|
-
var
|
|
21
|
-
__export(
|
|
22
|
-
|
|
19
|
+
// src/backend/actions/create-delete-action.ts
|
|
20
|
+
var create_delete_action_exports = {};
|
|
21
|
+
__export(create_delete_action_exports, {
|
|
22
|
+
createDeleteAction: () => createDeleteAction
|
|
23
23
|
});
|
|
24
|
-
module.exports = __toCommonJS(
|
|
25
|
-
var import_next_rest_framework = require("next-rest-framework");
|
|
26
|
-
var import_zod = require("zod");
|
|
24
|
+
module.exports = __toCommonJS(create_delete_action_exports);
|
|
27
25
|
var import_drizzle_orm = require("drizzle-orm");
|
|
28
|
-
function
|
|
26
|
+
function createDeleteAction({
|
|
29
27
|
table,
|
|
30
28
|
db
|
|
31
29
|
}) {
|
|
32
|
-
return
|
|
33
|
-
body: import_zod.z.string(),
|
|
34
|
-
contentType: "application/json"
|
|
35
|
-
}).handler(async (id) => {
|
|
30
|
+
return async (id) => {
|
|
36
31
|
return db.delete(table).where((0, import_drizzle_orm.eq)(table.id, id)).returning();
|
|
37
|
-
}
|
|
32
|
+
};
|
|
38
33
|
}
|
|
39
34
|
// Annotate the CommonJS export names for ESM import in node:
|
|
40
35
|
0 && (module.exports = {
|
|
41
|
-
|
|
36
|
+
createDeleteAction
|
|
42
37
|
});
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { ZodSchema } from "zod";
|
|
2
|
-
import { BaseTable, GetListRelations } from "../types";
|
|
1
|
+
import { z, ZodSchema } from "zod";
|
|
3
2
|
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
4
|
-
|
|
3
|
+
import { BaseTable, GetListRelations } from "../types";
|
|
4
|
+
export declare function createGetAction<T extends ZodSchema, TTable extends BaseTable>({ bodySchema, db, jsonArrayFields, relations, table, }: {
|
|
5
5
|
bodySchema: T;
|
|
6
6
|
db: NodePgDatabase<any>;
|
|
7
7
|
jsonArrayFields?: string[];
|
|
8
|
-
querySchema: Q;
|
|
9
8
|
relations?: GetListRelations;
|
|
10
9
|
table: TTable;
|
|
11
|
-
}):
|
|
10
|
+
}): (params: Partial<z.infer<T>>) => Promise<T["_output"]>;
|
|
@@ -16,32 +16,22 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
18
|
|
|
19
|
-
// src/backend/actions/get-action
|
|
20
|
-
var
|
|
21
|
-
__export(
|
|
22
|
-
|
|
19
|
+
// src/backend/actions/create-get-action.ts
|
|
20
|
+
var create_get_action_exports = {};
|
|
21
|
+
__export(create_get_action_exports, {
|
|
22
|
+
createGetAction: () => createGetAction
|
|
23
23
|
});
|
|
24
|
-
module.exports = __toCommonJS(
|
|
25
|
-
var import_next_rest_framework = require("next-rest-framework");
|
|
24
|
+
module.exports = __toCommonJS(create_get_action_exports);
|
|
26
25
|
var import_get_list_query = require("./get-list-query");
|
|
27
26
|
var import_get_list_data = require("./get-list-data");
|
|
28
|
-
function
|
|
27
|
+
function createGetAction({
|
|
29
28
|
bodySchema,
|
|
30
29
|
db,
|
|
31
30
|
jsonArrayFields,
|
|
32
|
-
querySchema,
|
|
33
31
|
relations,
|
|
34
32
|
table
|
|
35
33
|
}) {
|
|
36
|
-
return
|
|
37
|
-
body: querySchema,
|
|
38
|
-
contentType: "application/json"
|
|
39
|
-
}).outputs([
|
|
40
|
-
{
|
|
41
|
-
body: bodySchema,
|
|
42
|
-
contentType: "application/json"
|
|
43
|
-
}
|
|
44
|
-
]).handler(async (params) => {
|
|
34
|
+
return async (params) => {
|
|
45
35
|
const fields = {};
|
|
46
36
|
for (const key of Object.keys(bodySchema.shape)) {
|
|
47
37
|
const field = table[key];
|
|
@@ -66,10 +56,10 @@ function getActionFn({
|
|
|
66
56
|
pageSize: 1,
|
|
67
57
|
query
|
|
68
58
|
})();
|
|
69
|
-
return result
|
|
70
|
-
}
|
|
59
|
+
return result;
|
|
60
|
+
};
|
|
71
61
|
}
|
|
72
62
|
// Annotate the CommonJS export names for ESM import in node:
|
|
73
63
|
0 && (module.exports = {
|
|
74
|
-
|
|
64
|
+
createGetAction
|
|
75
65
|
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z, ZodSchema } from "zod";
|
|
2
|
+
import { BaseTable, GetListRelations } from "../types";
|
|
3
|
+
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
4
|
+
export declare function createGetListAction<T extends ZodSchema, TTable extends BaseTable>({ bodySchema, db, jsonArrayFields, relations, table, }: {
|
|
5
|
+
bodySchema: T;
|
|
6
|
+
db: NodePgDatabase<any>;
|
|
7
|
+
jsonArrayFields?: string[];
|
|
8
|
+
relations?: GetListRelations;
|
|
9
|
+
table: TTable;
|
|
10
|
+
}): (params: Partial<z.infer<T>>) => Promise<{
|
|
11
|
+
data: T["_output"][];
|
|
12
|
+
total: number;
|
|
13
|
+
}>;
|
|
@@ -16,33 +16,22 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
18
|
|
|
19
|
-
// src/backend/actions/get-list-action
|
|
20
|
-
var
|
|
21
|
-
__export(
|
|
22
|
-
|
|
19
|
+
// src/backend/actions/create-get-list-action.ts
|
|
20
|
+
var create_get_list_action_exports = {};
|
|
21
|
+
__export(create_get_list_action_exports, {
|
|
22
|
+
createGetListAction: () => createGetListAction
|
|
23
23
|
});
|
|
24
|
-
module.exports = __toCommonJS(
|
|
25
|
-
var import_next_rest_framework = require("next-rest-framework");
|
|
26
|
-
var import_schemas = require("../schemas");
|
|
24
|
+
module.exports = __toCommonJS(create_get_list_action_exports);
|
|
27
25
|
var import_get_list_query = require("./get-list-query");
|
|
28
26
|
var import_get_list_data = require("./get-list-data");
|
|
29
|
-
function
|
|
27
|
+
function createGetListAction({
|
|
30
28
|
bodySchema,
|
|
31
29
|
db,
|
|
32
30
|
jsonArrayFields,
|
|
33
|
-
querySchema,
|
|
34
31
|
relations,
|
|
35
32
|
table
|
|
36
33
|
}) {
|
|
37
|
-
return
|
|
38
|
-
body: querySchema,
|
|
39
|
-
contentType: "application/json"
|
|
40
|
-
}).outputs([
|
|
41
|
-
{
|
|
42
|
-
body: (0, import_schemas.listBodySchema)(bodySchema),
|
|
43
|
-
contentType: "application/json"
|
|
44
|
-
}
|
|
45
|
-
]).handler(async (params) => {
|
|
34
|
+
return async (params) => {
|
|
46
35
|
const { current, pageSize, ...other } = params;
|
|
47
36
|
const fields = {};
|
|
48
37
|
for (const key of Object.keys(bodySchema.shape)) {
|
|
@@ -66,9 +55,9 @@ function getListActionFn({
|
|
|
66
55
|
pageSize,
|
|
67
56
|
query
|
|
68
57
|
})();
|
|
69
|
-
}
|
|
58
|
+
};
|
|
70
59
|
}
|
|
71
60
|
// Annotate the CommonJS export names for ESM import in node:
|
|
72
61
|
0 && (module.exports = {
|
|
73
|
-
|
|
62
|
+
createGetListAction
|
|
74
63
|
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z, ZodSchema } from "zod";
|
|
2
|
+
import { PgTable } from "drizzle-orm/pg-core";
|
|
3
|
+
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
4
|
+
export declare function createPostAction<T extends ZodSchema, TTable extends PgTable>({ table, db, }: {
|
|
5
|
+
bodySchema: T;
|
|
6
|
+
db: NodePgDatabase<any>;
|
|
7
|
+
table: TTable;
|
|
8
|
+
}): (body: z.infer<T>) => Promise<T["_output"][]>;
|
|
@@ -16,34 +16,22 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
18
|
|
|
19
|
-
// src/backend/actions/post-action
|
|
20
|
-
var
|
|
21
|
-
__export(
|
|
22
|
-
|
|
19
|
+
// src/backend/actions/create-post-action.ts
|
|
20
|
+
var create_post_action_exports = {};
|
|
21
|
+
__export(create_post_action_exports, {
|
|
22
|
+
createPostAction: () => createPostAction
|
|
23
23
|
});
|
|
24
|
-
module.exports = __toCommonJS(
|
|
25
|
-
var import_zod = require("zod");
|
|
26
|
-
var import_next_rest_framework = require("next-rest-framework");
|
|
24
|
+
module.exports = __toCommonJS(create_post_action_exports);
|
|
27
25
|
var import_transform_body = require("./transform-body");
|
|
28
|
-
function
|
|
29
|
-
bodySchema,
|
|
26
|
+
function createPostAction({
|
|
30
27
|
table,
|
|
31
28
|
db
|
|
32
29
|
}) {
|
|
33
|
-
return
|
|
34
|
-
body: bodySchema,
|
|
35
|
-
contentType: "application/json"
|
|
36
|
-
}).outputs([
|
|
37
|
-
{
|
|
38
|
-
body: import_zod.z.array(bodySchema),
|
|
39
|
-
contentType: "application/json",
|
|
40
|
-
status: 200
|
|
41
|
-
}
|
|
42
|
-
]).handler(async (body) => {
|
|
30
|
+
return async (body) => {
|
|
43
31
|
return db.insert(table).values((0, import_transform_body.transformBody)(body)).returning();
|
|
44
|
-
}
|
|
32
|
+
};
|
|
45
33
|
}
|
|
46
34
|
// Annotate the CommonJS export names for ESM import in node:
|
|
47
35
|
0 && (module.exports = {
|
|
48
|
-
|
|
36
|
+
createPostAction
|
|
49
37
|
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z, ZodSchema } from "zod";
|
|
2
|
+
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
3
|
+
import { BaseTable } from "../types";
|
|
4
|
+
export declare function createPutAction<T extends ZodSchema, TTable extends BaseTable>({ db, table, }: {
|
|
5
|
+
bodySchema: T;
|
|
6
|
+
db: NodePgDatabase<any>;
|
|
7
|
+
table: TTable;
|
|
8
|
+
}): (body: Partial<z.infer<T>>) => Promise<T["_output"]>;
|
|
@@ -16,28 +16,23 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
18
|
|
|
19
|
-
// src/backend/actions/put-action
|
|
20
|
-
var
|
|
21
|
-
__export(
|
|
22
|
-
|
|
19
|
+
// src/backend/actions/create-put-action.ts
|
|
20
|
+
var create_put_action_exports = {};
|
|
21
|
+
__export(create_put_action_exports, {
|
|
22
|
+
createPutAction: () => createPutAction
|
|
23
23
|
});
|
|
24
|
-
module.exports = __toCommonJS(
|
|
25
|
-
var import_next_rest_framework = require("next-rest-framework");
|
|
24
|
+
module.exports = __toCommonJS(create_put_action_exports);
|
|
26
25
|
var import_transform_body = require("./transform-body");
|
|
27
26
|
var import_drizzle_orm = require("drizzle-orm");
|
|
28
|
-
function
|
|
27
|
+
function createPutAction({
|
|
29
28
|
db,
|
|
30
|
-
bodySchema,
|
|
31
29
|
table
|
|
32
30
|
}) {
|
|
33
|
-
return
|
|
34
|
-
body: bodySchema,
|
|
35
|
-
contentType: "application/json"
|
|
36
|
-
}).handler(async (body) => {
|
|
31
|
+
return async (body) => {
|
|
37
32
|
return db.update(table).set((0, import_transform_body.transformBody)(body)).where((0, import_drizzle_orm.eq)(table.id, body.id)).returning();
|
|
38
|
-
}
|
|
33
|
+
};
|
|
39
34
|
}
|
|
40
35
|
// Annotate the CommonJS export names for ESM import in node:
|
|
41
36
|
0 && (module.exports = {
|
|
42
|
-
|
|
37
|
+
createPutAction
|
|
43
38
|
});
|
|
@@ -4,4 +4,19 @@ export declare function getListData<B extends ZodSchema>({ query, countQuery, pa
|
|
|
4
4
|
bodySchema: B;
|
|
5
5
|
current?: number;
|
|
6
6
|
pageSize?: number;
|
|
7
|
-
} & ReturnType<typeof getListQuery>):
|
|
7
|
+
} & ReturnType<typeof getListQuery>): import("next-rest-framework/dist/index-Xbs7wi4f").R<"application/json" | "application/x-www-form-urlencoded" | "multipart/form-data", unknown, {
|
|
8
|
+
body: import("zod").ZodObject<{
|
|
9
|
+
total: import("zod").ZodNumber;
|
|
10
|
+
data: import("zod").ZodArray<B, "many">;
|
|
11
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
12
|
+
data: B["_output"][];
|
|
13
|
+
total: number;
|
|
14
|
+
}, {
|
|
15
|
+
data: B["_input"][];
|
|
16
|
+
total: number;
|
|
17
|
+
}>;
|
|
18
|
+
contentType: "application/json";
|
|
19
|
+
}[], false, Promise<{
|
|
20
|
+
data: B["_output"][];
|
|
21
|
+
total: number;
|
|
22
|
+
}>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
1
|
+
export { createDeleteAction } from "./create-delete-action";
|
|
2
|
+
export { createGetAction } from "./create-get-action";
|
|
3
|
+
export { createGetListAction } from "./create-get-list-action";
|
|
4
|
+
export { createPostAction } from "./create-post-action";
|
|
5
|
+
export { createPutAction } from "./create-put-action";
|
|
6
6
|
export { getListQuery } from "./get-list-query";
|
|
@@ -19,26 +19,26 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/backend/actions/index.ts
|
|
20
20
|
var actions_exports = {};
|
|
21
21
|
__export(actions_exports, {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
createDeleteAction: () => import_create_delete_action.createDeleteAction,
|
|
23
|
+
createGetAction: () => import_create_get_action.createGetAction,
|
|
24
|
+
createGetListAction: () => import_create_get_list_action.createGetListAction,
|
|
25
|
+
createPostAction: () => import_create_post_action.createPostAction,
|
|
26
|
+
createPutAction: () => import_create_put_action.createPutAction,
|
|
27
|
+
getListQuery: () => import_get_list_query.getListQuery
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(actions_exports);
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
var
|
|
33
|
-
var
|
|
34
|
-
var
|
|
30
|
+
var import_create_delete_action = require("./create-delete-action");
|
|
31
|
+
var import_create_get_action = require("./create-get-action");
|
|
32
|
+
var import_create_get_list_action = require("./create-get-list-action");
|
|
33
|
+
var import_create_post_action = require("./create-post-action");
|
|
34
|
+
var import_create_put_action = require("./create-put-action");
|
|
35
35
|
var import_get_list_query = require("./get-list-query");
|
|
36
36
|
// Annotate the CommonJS export names for ESM import in node:
|
|
37
37
|
0 && (module.exports = {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
createDeleteAction,
|
|
39
|
+
createGetAction,
|
|
40
|
+
createGetListAction,
|
|
41
|
+
createPostAction,
|
|
42
|
+
createPutAction,
|
|
43
|
+
getListQuery
|
|
44
44
|
});
|
|
@@ -3,7 +3,8 @@ import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
|
3
3
|
export interface DeleteOperationOptions<TTable extends BaseTable> {
|
|
4
4
|
table: TTable;
|
|
5
5
|
summary?: string;
|
|
6
|
+
onSuccess?: () => Promise<void>;
|
|
6
7
|
}
|
|
7
|
-
export declare const createDeleteOperation:
|
|
8
|
+
export declare const createDeleteOperation: ({ db }: {
|
|
8
9
|
db: NodePgDatabase<any>;
|
|
9
|
-
}) => ({ table, summary }: DeleteOperationOptions<TTable>) => any;
|
|
10
|
+
}) => <TTable extends BaseTable>({ table, summary, onSuccess, }: DeleteOperationOptions<TTable>) => any;
|
|
@@ -36,7 +36,11 @@ var import_next_rest_framework = require("next-rest-framework");
|
|
|
36
36
|
var import_zod = require("zod");
|
|
37
37
|
var import_get_table_name = __toESM(require("./get-table-name"));
|
|
38
38
|
var import_actions = require("../actions");
|
|
39
|
-
var createDeleteOperation = ({ db }) => ({
|
|
39
|
+
var createDeleteOperation = ({ db }) => ({
|
|
40
|
+
table,
|
|
41
|
+
summary,
|
|
42
|
+
onSuccess
|
|
43
|
+
}) => (0, import_next_rest_framework.routeOperation)({
|
|
40
44
|
method: "DELETE",
|
|
41
45
|
openApiOperation: {
|
|
42
46
|
summary,
|
|
@@ -49,7 +53,9 @@ var createDeleteOperation = ({ db }) => ({ table, summary }) => (0, import_next_
|
|
|
49
53
|
contentType: "application/json"
|
|
50
54
|
}).handler(async (req) => {
|
|
51
55
|
const { id } = await req.json();
|
|
52
|
-
|
|
56
|
+
const data = await (0, import_actions.createDeleteAction)({ table, db })(id);
|
|
57
|
+
await (onSuccess == null ? void 0 : onSuccess());
|
|
58
|
+
return import_next_rest_framework.TypedNextResponse.json(data, {
|
|
53
59
|
status: 200
|
|
54
60
|
});
|
|
55
61
|
});
|
|
@@ -11,7 +11,7 @@ export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchem
|
|
|
11
11
|
byCreator?: boolean;
|
|
12
12
|
summary?: string;
|
|
13
13
|
table: TTable;
|
|
14
|
-
|
|
14
|
+
onSuccess?: <D extends T>(data: {
|
|
15
15
|
data: z.infer<D>[];
|
|
16
16
|
total: number;
|
|
17
17
|
}) => Promise<{
|
|
@@ -19,9 +19,9 @@ export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchem
|
|
|
19
19
|
total: number;
|
|
20
20
|
}>;
|
|
21
21
|
}
|
|
22
|
-
export declare const createGetListOperation:
|
|
22
|
+
export declare const createGetListOperation: ({ db, getSession, }: {
|
|
23
23
|
db: NodePgDatabase<any>;
|
|
24
24
|
getSession: (req: NextRequest) => Promise<{
|
|
25
25
|
userId?: string;
|
|
26
26
|
} | undefined>;
|
|
27
|
-
}) => ({ querySchema, bodySchema, table, summary, relations, jsonArrayFields, setParams,
|
|
27
|
+
}) => <T extends z.ZodType<any, z.ZodTypeDef, any>, Q extends z.ZodType<any, z.ZodTypeDef, any>, TTable extends BaseTable>({ querySchema, bodySchema, table, summary, relations, jsonArrayFields, setParams, onSuccess, byCreator, }: GetListOperationOptions<T, Q, TTable>) => any;
|