@ai0x0/utils 0.0.2 → 0.0.4

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 (61) hide show
  1. package/es/backend/actions/create-delete-action.d.ts +6 -0
  2. package/es/backend/actions/{delete-action-fn.js → create-delete-action.js} +3 -8
  3. package/es/backend/actions/{get-list-action-fn.d.ts → create-get-action.d.ts} +4 -5
  4. package/es/backend/actions/{get-action-fn.js → create-get-action.js} +4 -12
  5. package/es/backend/actions/create-get-list-action.d.ts +13 -0
  6. package/es/backend/actions/{get-list-action-fn.js → create-get-list-action.js} +3 -12
  7. package/es/backend/actions/create-post-action.d.ts +8 -0
  8. package/es/backend/actions/{post-action-fn.js → create-post-action.js} +4 -14
  9. package/es/backend/actions/create-put-action.d.ts +8 -0
  10. package/es/backend/actions/{put-action-fn.js → create-put-action.js} +4 -12
  11. package/es/backend/actions/get-list-data.d.ts +16 -1
  12. package/es/backend/actions/index.d.ts +5 -5
  13. package/es/backend/actions/index.js +5 -5
  14. package/es/backend/route-operation/delete-operation.d.ts +3 -2
  15. package/es/backend/route-operation/delete-operation.js +13 -11
  16. package/es/backend/route-operation/get-list-operation.d.ts +3 -3
  17. package/es/backend/route-operation/get-list-operation.js +5 -6
  18. package/es/backend/route-operation/get-operation.d.ts +4 -3
  19. package/es/backend/route-operation/get-operation.js +13 -4
  20. package/es/backend/route-operation/post-operation.d.ts +3 -2
  21. package/es/backend/route-operation/post-operation.js +19 -9
  22. package/es/backend/route-operation/put-operation.d.ts +4 -2
  23. package/es/backend/route-operation/put-operation.js +20 -12
  24. package/es/backend/schemas/index.d.ts +10 -2
  25. package/es/backend/schemas/index.js +1 -1
  26. package/es/backend/types.d.ts +5 -1
  27. package/lib/backend/actions/create-delete-action.d.ts +6 -0
  28. package/lib/backend/actions/{delete-action-fn.js → create-delete-action.js} +9 -14
  29. package/lib/backend/actions/{get-list-action-fn.d.ts → create-get-action.d.ts} +4 -5
  30. package/lib/backend/actions/{get-action-fn.js → create-get-action.js} +10 -20
  31. package/lib/backend/actions/create-get-list-action.d.ts +13 -0
  32. package/lib/backend/actions/{get-list-action-fn.js → create-get-list-action.js} +9 -20
  33. package/lib/backend/actions/create-post-action.d.ts +8 -0
  34. package/lib/backend/actions/{post-action-fn.js → create-post-action.js} +9 -21
  35. package/lib/backend/actions/create-put-action.d.ts +8 -0
  36. package/lib/backend/actions/{put-action-fn.js → create-put-action.js} +9 -14
  37. package/lib/backend/actions/get-list-data.d.ts +16 -1
  38. package/lib/backend/actions/index.d.ts +5 -5
  39. package/lib/backend/actions/index.js +17 -17
  40. package/lib/backend/route-operation/delete-operation.d.ts +3 -2
  41. package/lib/backend/route-operation/delete-operation.js +8 -2
  42. package/lib/backend/route-operation/get-list-operation.d.ts +3 -3
  43. package/lib/backend/route-operation/get-list-operation.js +4 -5
  44. package/lib/backend/route-operation/get-operation.d.ts +4 -3
  45. package/lib/backend/route-operation/get-operation.js +5 -2
  46. package/lib/backend/route-operation/post-operation.d.ts +3 -2
  47. package/lib/backend/route-operation/post-operation.js +12 -3
  48. package/lib/backend/route-operation/put-operation.d.ts +4 -2
  49. package/lib/backend/route-operation/put-operation.js +19 -12
  50. package/lib/backend/schemas/index.d.ts +10 -2
  51. package/lib/backend/schemas/index.js +2 -0
  52. package/lib/backend/types.d.ts +5 -1
  53. package/package.json +3 -3
  54. package/es/backend/actions/delete-action-fn.d.ts +0 -6
  55. package/es/backend/actions/get-action-fn.d.ts +0 -11
  56. package/es/backend/actions/post-action-fn.d.ts +0 -12
  57. package/es/backend/actions/put-action-fn.d.ts +0 -8
  58. package/lib/backend/actions/delete-action-fn.d.ts +0 -6
  59. package/lib/backend/actions/get-action-fn.d.ts +0 -11
  60. package/lib/backend/actions/post-action-fn.d.ts +0 -12
  61. 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 { postActionFn } from "../actions";
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$postActionFn, _yield$postActionFn2, data;
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,21 +77,30 @@ 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 postActionFn({
80
+ return createPostAction({
80
81
  bodySchema: bodySchema,
81
82
  db: db,
82
83
  table: table
83
84
  })(_objectSpread(_objectSpread({}, body), {}, {
84
- editorId: userId
85
+ creatorId: userId
85
86
  }));
86
87
  case 20:
87
- _yield$postActionFn = _context.sent;
88
- _yield$postActionFn2 = _slicedToArray(_yield$postActionFn, 1);
89
- data = _yield$postActionFn2[0];
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 24:
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: <T extends z.ZodType<any, z.ZodTypeDef, any>, TTable extends PgTable<import("drizzle-orm/pg-core").TableConfig>>({ getSession, db, }: {
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 { putActionFn } from "../actions";
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.t5 = TypedNextResponse;
66
- _context.next = 21;
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 21:
75
- _context.t6 = _context.sent;
76
- _context.t7 = {
77
- status: 200
78
- };
79
- return _context.abrupt("return", _context.t5.json.call(_context.t5, _context.t6, _context.t7));
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[]] | unknown[] | null | undefined;
4676
+ [x: string]: unknown[] | [any, ...any[]] | null | undefined;
4669
4677
  }, {
4670
- [x: string]: [any, ...any[]] | unknown[] | null | undefined;
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"),
@@ -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-fn.ts
20
- var delete_action_fn_exports = {};
21
- __export(delete_action_fn_exports, {
22
- deleteActionFn: () => deleteActionFn
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(delete_action_fn_exports);
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 deleteActionFn({
26
+ function createDeleteAction({
29
27
  table,
30
28
  db
31
29
  }) {
32
- return (0, import_next_rest_framework.rpcOperation)().input({
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
- deleteActionFn
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
- export declare function getListActionFn<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable>({ bodySchema, db, jsonArrayFields, querySchema, relations, table, }: {
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
- }): any;
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-fn.ts
20
- var get_action_fn_exports = {};
21
- __export(get_action_fn_exports, {
22
- getActionFn: () => getActionFn
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(get_action_fn_exports);
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 getActionFn({
27
+ function createGetAction({
29
28
  bodySchema,
30
29
  db,
31
30
  jsonArrayFields,
32
- querySchema,
33
31
  relations,
34
32
  table
35
33
  }) {
36
- return (0, import_next_rest_framework.rpcOperation)().input({
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
- getActionFn
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-fn.ts
20
- var get_list_action_fn_exports = {};
21
- __export(get_list_action_fn_exports, {
22
- getListActionFn: () => getListActionFn
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(get_list_action_fn_exports);
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 getListActionFn({
27
+ function createGetListAction({
30
28
  bodySchema,
31
29
  db,
32
30
  jsonArrayFields,
33
- querySchema,
34
31
  relations,
35
32
  table
36
33
  }) {
37
- return (0, import_next_rest_framework.rpcOperation)().input({
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
- getListActionFn
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-fn.ts
20
- var post_action_fn_exports = {};
21
- __export(post_action_fn_exports, {
22
- postActionFn: () => postActionFn
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(post_action_fn_exports);
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 postActionFn({
29
- bodySchema,
26
+ function createPostAction({
30
27
  table,
31
28
  db
32
29
  }) {
33
- return (0, import_next_rest_framework.rpcOperation)().input({
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
- postActionFn
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-fn.ts
20
- var put_action_fn_exports = {};
21
- __export(put_action_fn_exports, {
22
- putActionFn: () => putActionFn
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(put_action_fn_exports);
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 putActionFn({
27
+ function createPutAction({
29
28
  db,
30
- bodySchema,
31
29
  table
32
30
  }) {
33
- return (0, import_next_rest_framework.rpcOperation)().input({
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
- putActionFn
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>): any;
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 { deleteActionFn } from "./delete-action-fn";
2
- export { getActionFn } from "./get-action-fn";
3
- export { getListActionFn } from "./get-list-action-fn";
4
- export { postActionFn } from "./post-action-fn";
5
- export { putActionFn } from "./put-action-fn";
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
- deleteActionFn: () => import_delete_action_fn.deleteActionFn,
23
- getActionFn: () => import_get_action_fn.getActionFn,
24
- getListActionFn: () => import_get_list_action_fn.getListActionFn,
25
- getListQuery: () => import_get_list_query.getListQuery,
26
- postActionFn: () => import_post_action_fn.postActionFn,
27
- putActionFn: () => import_put_action_fn.putActionFn
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 import_delete_action_fn = require("./delete-action-fn");
31
- var import_get_action_fn = require("./get-action-fn");
32
- var import_get_list_action_fn = require("./get-list-action-fn");
33
- var import_post_action_fn = require("./post-action-fn");
34
- var import_put_action_fn = require("./put-action-fn");
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
- deleteActionFn,
39
- getActionFn,
40
- getListActionFn,
41
- getListQuery,
42
- postActionFn,
43
- putActionFn
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: <TTable extends BaseTable>({ db }: {
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 }) => ({ table, summary }) => (0, import_next_rest_framework.routeOperation)({
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
- return import_next_rest_framework.TypedNextResponse.json(await (0, import_actions.deleteActionFn)({ table, db })(id), {
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
- transform?: <D extends T>(data: {
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: <T extends z.ZodType<any, z.ZodTypeDef, any>, Q extends z.ZodType<any, z.ZodTypeDef, any>, TTable extends BaseTable>({ db, getSession, }: {
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, transform, byCreator, }: GetListOperationOptions<T, Q, TTable>) => any;
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;