@ai0x0/utils 0.0.37 → 0.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/.agents/skills/ai0x0-utils/backend/SKILL.md +12 -8
  2. package/README.md +42 -1
  3. package/SKILL.md +12 -8
  4. package/es/backend/route-operation/delete-operation.d.ts +3 -2
  5. package/es/backend/route-operation/delete-operation.js +35 -22
  6. package/es/backend/route-operation/get-list-operation.d.ts +6 -5
  7. package/es/backend/route-operation/get-list-operation.js +37 -22
  8. package/es/backend/route-operation/get-operation.d.ts +5 -4
  9. package/es/backend/route-operation/get-operation.js +34 -22
  10. package/es/backend/route-operation/post-operation.d.ts +5 -4
  11. package/es/backend/route-operation/post-operation.js +39 -34
  12. package/es/backend/route-operation/put-operation.d.ts +5 -4
  13. package/es/backend/route-operation/put-operation.js +44 -29
  14. package/es/backend/sqlite/actions/create-delete-action.d.ts +8 -0
  15. package/es/backend/sqlite/actions/create-delete-action.js +54 -0
  16. package/es/backend/sqlite/actions/create-get-action.d.ts +8 -0
  17. package/es/backend/sqlite/actions/create-get-action.js +64 -0
  18. package/es/backend/sqlite/actions/create-get-list-action.d.ts +11 -0
  19. package/es/backend/sqlite/actions/create-get-list-action.js +56 -0
  20. package/es/backend/sqlite/actions/create-post-action.d.ts +6 -0
  21. package/es/backend/sqlite/actions/create-post-action.js +31 -0
  22. package/es/backend/sqlite/actions/create-put-action.d.ts +8 -0
  23. package/es/backend/sqlite/actions/create-put-action.js +74 -0
  24. package/es/backend/sqlite/actions/get-list-data.d.ts +9 -0
  25. package/es/backend/sqlite/actions/get-list-data.js +75 -0
  26. package/es/backend/sqlite/actions/get-list-query.d.ts +19 -0
  27. package/es/backend/sqlite/actions/get-list-query.js +215 -0
  28. package/es/backend/sqlite/actions/index.d.ts +6 -0
  29. package/es/backend/sqlite/actions/index.js +6 -0
  30. package/es/backend/sqlite/actions/transform-body.d.ts +1 -0
  31. package/es/backend/sqlite/actions/transform-body.js +9 -0
  32. package/es/backend/sqlite/errors.d.ts +4 -0
  33. package/es/backend/sqlite/errors.js +31 -0
  34. package/es/backend/sqlite/index.d.ts +5 -0
  35. package/es/backend/sqlite/index.js +5 -0
  36. package/es/backend/sqlite/route-operation/delete-operation.d.ts +11 -0
  37. package/es/backend/sqlite/route-operation/delete-operation.js +122 -0
  38. package/es/backend/sqlite/route-operation/get-list-operation.d.ts +23 -0
  39. package/es/backend/sqlite/route-operation/get-list-operation.js +135 -0
  40. package/es/backend/sqlite/route-operation/get-operation.d.ts +17 -0
  41. package/es/backend/sqlite/route-operation/get-operation.js +132 -0
  42. package/es/backend/sqlite/route-operation/get-table-name.d.ts +3 -0
  43. package/es/backend/sqlite/route-operation/get-table-name.js +11 -0
  44. package/es/backend/sqlite/route-operation/index.d.ts +5 -0
  45. package/es/backend/sqlite/route-operation/index.js +5 -0
  46. package/es/backend/sqlite/route-operation/post-operation.d.ts +14 -0
  47. package/es/backend/sqlite/route-operation/post-operation.js +141 -0
  48. package/es/backend/sqlite/route-operation/put-operation.d.ts +15 -0
  49. package/es/backend/sqlite/route-operation/put-operation.js +156 -0
  50. package/es/backend/sqlite/schemas/index.d.ts +68 -0
  51. package/es/backend/sqlite/schemas/index.js +133 -0
  52. package/es/backend/sqlite/types.d.ts +16 -0
  53. package/es/backend/sqlite/types.js +1 -0
  54. package/lib/backend/route-operation/delete-operation.d.ts +3 -2
  55. package/lib/backend/route-operation/delete-operation.js +5 -3
  56. package/lib/backend/route-operation/get-list-operation.d.ts +6 -5
  57. package/lib/backend/route-operation/get-list-operation.js +8 -8
  58. package/lib/backend/route-operation/get-operation.d.ts +5 -4
  59. package/lib/backend/route-operation/get-operation.js +8 -8
  60. package/lib/backend/route-operation/post-operation.d.ts +5 -4
  61. package/lib/backend/route-operation/post-operation.js +4 -3
  62. package/lib/backend/route-operation/put-operation.d.ts +5 -4
  63. package/lib/backend/route-operation/put-operation.js +6 -4
  64. package/lib/backend/sqlite/actions/create-delete-action.d.ts +8 -0
  65. package/lib/backend/sqlite/actions/create-delete-action.js +53 -0
  66. package/lib/backend/sqlite/actions/create-get-action.d.ts +8 -0
  67. package/lib/backend/sqlite/actions/create-get-action.js +65 -0
  68. package/lib/backend/sqlite/actions/create-get-list-action.d.ts +11 -0
  69. package/lib/backend/sqlite/actions/create-get-list-action.js +63 -0
  70. package/lib/backend/sqlite/actions/create-post-action.d.ts +6 -0
  71. package/lib/backend/sqlite/actions/create-post-action.js +39 -0
  72. package/lib/backend/sqlite/actions/create-put-action.d.ts +8 -0
  73. package/lib/backend/sqlite/actions/create-put-action.js +60 -0
  74. package/lib/backend/sqlite/actions/get-list-data.d.ts +9 -0
  75. package/lib/backend/sqlite/actions/get-list-data.js +51 -0
  76. package/lib/backend/sqlite/actions/get-list-query.d.ts +19 -0
  77. package/lib/backend/sqlite/actions/get-list-query.js +165 -0
  78. package/lib/backend/sqlite/actions/index.d.ts +6 -0
  79. package/lib/backend/sqlite/actions/index.js +44 -0
  80. package/lib/backend/sqlite/actions/transform-body.d.ts +1 -0
  81. package/lib/backend/sqlite/actions/transform-body.js +49 -0
  82. package/lib/backend/sqlite/errors.d.ts +4 -0
  83. package/lib/backend/sqlite/errors.js +35 -0
  84. package/lib/backend/sqlite/index.d.ts +5 -0
  85. package/lib/backend/sqlite/index.js +31 -0
  86. package/lib/backend/sqlite/route-operation/delete-operation.d.ts +11 -0
  87. package/lib/backend/sqlite/route-operation/delete-operation.js +92 -0
  88. package/lib/backend/sqlite/route-operation/get-list-operation.d.ts +23 -0
  89. package/lib/backend/sqlite/route-operation/get-list-operation.js +108 -0
  90. package/lib/backend/sqlite/route-operation/get-operation.d.ts +17 -0
  91. package/lib/backend/sqlite/route-operation/get-operation.js +107 -0
  92. package/lib/backend/sqlite/route-operation/get-table-name.d.ts +3 -0
  93. package/lib/backend/sqlite/route-operation/get-table-name.js +35 -0
  94. package/lib/backend/sqlite/route-operation/index.d.ts +5 -0
  95. package/lib/backend/sqlite/route-operation/index.js +31 -0
  96. package/lib/backend/sqlite/route-operation/post-operation.d.ts +14 -0
  97. package/lib/backend/sqlite/route-operation/post-operation.js +95 -0
  98. package/lib/backend/sqlite/route-operation/put-operation.d.ts +15 -0
  99. package/lib/backend/sqlite/route-operation/put-operation.js +104 -0
  100. package/lib/backend/sqlite/schemas/index.d.ts +68 -0
  101. package/lib/backend/sqlite/schemas/index.js +113 -0
  102. package/lib/backend/sqlite/types.d.ts +16 -0
  103. package/lib/backend/sqlite/types.js +17 -0
  104. package/package.json +3 -1
@@ -44,6 +44,7 @@ var createGetListOperation = ({
44
44
  bodySchema,
45
45
  table,
46
46
  summary,
47
+ tags,
47
48
  relations,
48
49
  jsonArrayFields,
49
50
  setParams,
@@ -54,7 +55,7 @@ var createGetListOperation = ({
54
55
  method: "GET",
55
56
  openApiOperation: {
56
57
  summary,
57
- tags: [(0, import_get_table_name.default)(table)]
58
+ tags: tags ?? (table ? [(0, import_get_table_name.default)(table)] : [])
58
59
  }
59
60
  }).input({
60
61
  query: querySchema
@@ -73,18 +74,17 @@ var createGetListOperation = ({
73
74
  const { userId } = await getSession(req) || {};
74
75
  params.creatorId = userId;
75
76
  }
76
- let result = await (0, import_actions.createGetListAction)({
77
+ const mergedParams = Object.assign(
78
+ Object.fromEntries(new URL(req.url).searchParams),
79
+ params
80
+ );
81
+ let result = table ? await (0, import_actions.createGetListAction)({
77
82
  bodySchema,
78
83
  db,
79
84
  jsonArrayFields,
80
85
  relations,
81
86
  table
82
- })(
83
- Object.assign(
84
- Object.fromEntries(new URL(req.url).searchParams),
85
- params
86
- )
87
- );
87
+ })(mergedParams) : { data: [], total: 0 };
88
88
  if (onSuccess) {
89
89
  result = await onSuccess(result);
90
90
  }
@@ -6,11 +6,12 @@ export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, T
6
6
  jsonArrayFields?: string[];
7
7
  querySchema: Q;
8
8
  relations?: GetListRelations;
9
- setParams?: (req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string, unknown>>;
10
- onSuccess?: (data: z.infer<T>) => Promise<z.infer<T>>;
11
- onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
9
+ setParams?(req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>): Promise<Record<string, unknown>>;
10
+ onSuccess?(data: z.infer<T>): Promise<z.infer<T>>;
11
+ onError?(error: Error): Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
12
12
  summary?: string;
13
- table: TTable;
13
+ tags?: string[];
14
+ table?: TTable;
14
15
  byCreator?: boolean;
15
16
  }
16
17
  export declare const createGetOperation: any;
@@ -43,6 +43,7 @@ var createGetOperation = ({
43
43
  bodySchema,
44
44
  table,
45
45
  summary,
46
+ tags,
46
47
  relations,
47
48
  setParams,
48
49
  jsonArrayFields,
@@ -53,7 +54,7 @@ var createGetOperation = ({
53
54
  method: "GET",
54
55
  openApiOperation: {
55
56
  summary,
56
- tags: [(0, import_get_table_name.default)(table)]
57
+ tags: tags ?? (table ? [(0, import_get_table_name.default)(table)] : [])
57
58
  }
58
59
  }).input({
59
60
  query: querySchema
@@ -72,18 +73,17 @@ var createGetOperation = ({
72
73
  const { userId } = await getSession(req) || {};
73
74
  params.creatorId = userId;
74
75
  }
75
- const rawResult = await (0, import_actions.createGetAction)({
76
+ const mergedParams = Object.assign(
77
+ Object.fromEntries(new URL(req.url).searchParams),
78
+ params
79
+ );
80
+ const rawResult = table ? await (0, import_actions.createGetAction)({
76
81
  bodySchema,
77
82
  db,
78
83
  jsonArrayFields,
79
84
  relations,
80
85
  table
81
- })(
82
- Object.assign(
83
- Object.fromEntries(new URL(req.url).searchParams),
84
- params
85
- )
86
- );
86
+ })(mergedParams) : mergedParams;
87
87
  let result = rawResult ?? {};
88
88
  if (onSuccess) {
89
89
  result = await onSuccess(result);
@@ -4,10 +4,11 @@ import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
4
4
  export interface PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends PgTable> {
5
5
  bodySchema: IB;
6
6
  outputBodySchema?: IB;
7
- setBody?: (req: TypedNextRequest<"POST", "application/json", z.infer<IB>>) => Promise<Partial<z.infer<IB>>>;
7
+ setBody?(req: TypedNextRequest<"POST", "application/json", z.infer<IB>>): Promise<Partial<z.infer<IB>>>;
8
8
  summary?: string;
9
- onSuccess?: (data: z.infer<OB>) => Promise<z.infer<OB>>;
10
- onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
11
- table: TTable;
9
+ tags?: string[];
10
+ onSuccess?(data: z.infer<OB>): Promise<z.infer<OB>>;
11
+ onError?(error: Error): Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
12
+ table?: TTable;
12
13
  }
13
14
  export declare const createPostOperation: any;
@@ -44,6 +44,7 @@ var createPostOperation = ({
44
44
  outputBodySchema,
45
45
  setBody,
46
46
  summary,
47
+ tags,
47
48
  table,
48
49
  onSuccess,
49
50
  onError
@@ -51,7 +52,7 @@ var createPostOperation = ({
51
52
  method: "POST",
52
53
  openApiOperation: {
53
54
  summary,
54
- tags: [(0, import_get_table_name.default)(table)]
55
+ tags: tags ?? (table ? [(0, import_get_table_name.default)(table)] : [])
55
56
  }
56
57
  }).input({
57
58
  body: bodySchema,
@@ -70,10 +71,10 @@ var createPostOperation = ({
70
71
  req
71
72
  )) || {};
72
73
  const mergedBody = { ...body, ...extraBody };
73
- const [raw] = await (0, import_actions.createPostAction)({ bodySchema, db, table })({
74
+ const raw = table ? (await (0, import_actions.createPostAction)({ bodySchema, db, table })({
74
75
  creatorId: userId,
75
76
  ...mergedBody
76
- });
77
+ }))[0] : { creatorId: userId, ...mergedBody };
77
78
  const data = onSuccess ? await onSuccess(raw) : raw;
78
79
  return import_next_rest_framework.TypedNextResponse.json(data, {
79
80
  status: 200
@@ -4,11 +4,12 @@ import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
4
4
  export interface PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends PgTable> {
5
5
  bodySchema: IB;
6
6
  outputBodySchema?: OB;
7
- table: TTable;
7
+ table?: TTable;
8
8
  summary?: string;
9
- setBody?: (req: TypedNextRequest<"PUT", "application/json", z.infer<IB>>) => Promise<Partial<z.infer<IB>>>;
10
- onSuccess?: (data: z.infer<OB>) => Promise<z.infer<OB>>;
11
- onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
9
+ tags?: string[];
10
+ setBody?(req: TypedNextRequest<"PUT", "application/json", z.infer<IB>>): Promise<Partial<z.infer<IB>>>;
11
+ onSuccess?(data: z.infer<OB>): Promise<z.infer<OB>>;
12
+ onError?(error: Error): Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
12
13
  byCreator?: boolean;
13
14
  }
14
15
  export declare const createPutOperation: any;
@@ -45,6 +45,7 @@ var createPutOperation = ({
45
45
  outputBodySchema,
46
46
  table,
47
47
  summary,
48
+ tags,
48
49
  setBody,
49
50
  onSuccess,
50
51
  byCreator = true,
@@ -53,7 +54,7 @@ var createPutOperation = ({
53
54
  method: "PUT",
54
55
  openApiOperation: {
55
56
  summary,
56
- tags: [(0, import_get_table_name.default)(table)]
57
+ tags: tags ?? (table ? [(0, import_get_table_name.default)(table)] : [])
57
58
  }
58
59
  }).input({
59
60
  body: bodySchema,
@@ -72,18 +73,19 @@ var createPutOperation = ({
72
73
  req
73
74
  )) || {};
74
75
  const mergedBody = { ...body, ...extraBody };
75
- const raw = await (0, import_actions.createPutAction)({
76
+ const raw = table ? await (0, import_actions.createPutAction)({
76
77
  bodySchema,
77
78
  table,
78
79
  db
79
- })({ editorId: userId, ...mergedBody }, { byCreator });
80
+ })({ editorId: userId, ...mergedBody }, { byCreator }) : { editorId: userId, ...mergedBody };
80
81
  const data = onSuccess ? await onSuccess(raw) : raw;
81
82
  return import_next_rest_framework.TypedNextResponse.json(data, {
82
83
  status: 200
83
84
  });
84
85
  } catch (e) {
85
- if (!(e instanceof import_errors.HttpError))
86
+ if (!(e instanceof import_errors.HttpError)) {
86
87
  console.error(e);
88
+ }
87
89
  const response = await (onError == null ? void 0 : onError(e));
88
90
  if (response) {
89
91
  return response;
@@ -0,0 +1,8 @@
1
+ import { BaseTable } from "../types.js";
2
+ export declare function createDeleteAction<TTable extends BaseTable>({ table, db, }: {
3
+ db: any;
4
+ table: TTable;
5
+ }): ({ id, creatorId }: {
6
+ id: string;
7
+ creatorId?: string | undefined;
8
+ }) => Promise<any>;
@@ -0,0 +1,53 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/backend/sqlite/actions/create-delete-action.ts
20
+ var create_delete_action_exports = {};
21
+ __export(create_delete_action_exports, {
22
+ createDeleteAction: () => createDeleteAction
23
+ });
24
+ module.exports = __toCommonJS(create_delete_action_exports);
25
+ var import_drizzle_orm = require("drizzle-orm");
26
+ var import_sqlite = require("..");
27
+ var import_zod = require("zod");
28
+ var import_errors = require("../errors");
29
+ function createDeleteAction({
30
+ table,
31
+ db
32
+ }) {
33
+ return async ({ id, creatorId }) => {
34
+ if (creatorId) {
35
+ const data = await (0, import_sqlite.createGetAction)({
36
+ db,
37
+ table,
38
+ bodySchema: import_zod.z.object({
39
+ creatorId: import_zod.z.string(),
40
+ id: import_zod.z.string()
41
+ })
42
+ })({ creatorId, id });
43
+ if (!data) {
44
+ throw new import_errors.HttpError(404, "未找到删除对象,或没有权限");
45
+ }
46
+ }
47
+ return db.delete(table).where((0, import_drizzle_orm.eq)(table.id, id)).returning();
48
+ };
49
+ }
50
+ // Annotate the CommonJS export names for ESM import in node:
51
+ 0 && (module.exports = {
52
+ createDeleteAction
53
+ });
@@ -0,0 +1,8 @@
1
+ import { BaseTable, GetListRelations } from "../types.js";
2
+ export declare function createGetAction<TTable extends BaseTable>({ bodySchema, db, jsonArrayFields, relations, table, }: {
3
+ bodySchema: any;
4
+ db: any;
5
+ jsonArrayFields?: string[];
6
+ relations?: GetListRelations;
7
+ table: TTable;
8
+ }): (params: Record<string, unknown>) => Promise<unknown>;
@@ -0,0 +1,65 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/backend/sqlite/actions/create-get-action.ts
20
+ var create_get_action_exports = {};
21
+ __export(create_get_action_exports, {
22
+ createGetAction: () => createGetAction
23
+ });
24
+ module.exports = __toCommonJS(create_get_action_exports);
25
+ var import_get_list_query = require("./get-list-query");
26
+ var import_get_list_data = require("./get-list-data");
27
+ function createGetAction({
28
+ bodySchema,
29
+ db,
30
+ jsonArrayFields,
31
+ relations,
32
+ table
33
+ }) {
34
+ return async (params) => {
35
+ const fields = {};
36
+ for (const key of Object.keys(bodySchema.shape)) {
37
+ const field = table[key];
38
+ if (field) {
39
+ fields[key] = field;
40
+ }
41
+ }
42
+ const { query, countQuery } = (0, import_get_list_query.getListQuery)({
43
+ db,
44
+ fields,
45
+ jsonArrayFields,
46
+ params,
47
+ relations,
48
+ table
49
+ });
50
+ const {
51
+ data: [result]
52
+ } = await (0, import_get_list_data.getListData)({
53
+ bodySchema,
54
+ countQuery,
55
+ current: 1,
56
+ pageSize: 1,
57
+ query
58
+ })();
59
+ return result;
60
+ };
61
+ }
62
+ // Annotate the CommonJS export names for ESM import in node:
63
+ 0 && (module.exports = {
64
+ createGetAction
65
+ });
@@ -0,0 +1,11 @@
1
+ import { BaseTable, GetListRelations } from "../types.js";
2
+ export declare function createGetListAction<TTable extends BaseTable>({ bodySchema, db, jsonArrayFields, relations, table, }: {
3
+ bodySchema: any;
4
+ db: any;
5
+ jsonArrayFields?: string[];
6
+ relations?: GetListRelations;
7
+ table: TTable;
8
+ }): (params: Record<string, unknown>) => Promise<{
9
+ data: unknown[];
10
+ total: number;
11
+ }>;
@@ -0,0 +1,63 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/backend/sqlite/actions/create-get-list-action.ts
20
+ var create_get_list_action_exports = {};
21
+ __export(create_get_list_action_exports, {
22
+ createGetListAction: () => createGetListAction
23
+ });
24
+ module.exports = __toCommonJS(create_get_list_action_exports);
25
+ var import_get_list_query = require("./get-list-query");
26
+ var import_get_list_data = require("./get-list-data");
27
+ function createGetListAction({
28
+ bodySchema,
29
+ db,
30
+ jsonArrayFields,
31
+ relations,
32
+ table
33
+ }) {
34
+ return async (params) => {
35
+ const { current, pageSize, ...other } = params;
36
+ const fields = {};
37
+ for (const key of Object.keys(bodySchema.shape)) {
38
+ const field = table[key];
39
+ if (field) {
40
+ fields[key] = field;
41
+ }
42
+ }
43
+ const { query, countQuery } = (0, import_get_list_query.getListQuery)({
44
+ db,
45
+ fields,
46
+ jsonArrayFields,
47
+ params: other,
48
+ relations,
49
+ table
50
+ });
51
+ return (0, import_get_list_data.getListData)({
52
+ bodySchema,
53
+ countQuery,
54
+ current,
55
+ pageSize,
56
+ query
57
+ })();
58
+ };
59
+ }
60
+ // Annotate the CommonJS export names for ESM import in node:
61
+ 0 && (module.exports = {
62
+ createGetListAction
63
+ });
@@ -0,0 +1,6 @@
1
+ import { SQLiteTable } from "drizzle-orm/sqlite-core";
2
+ export declare function createPostAction<TTable extends SQLiteTable>({ table, db, }: {
3
+ bodySchema: any;
4
+ db: any;
5
+ table: TTable;
6
+ }): (body: Record<string, unknown>) => Promise<any[]>;
@@ -0,0 +1,39 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/backend/sqlite/actions/create-post-action.ts
20
+ var create_post_action_exports = {};
21
+ __export(create_post_action_exports, {
22
+ createPostAction: () => createPostAction
23
+ });
24
+ module.exports = __toCommonJS(create_post_action_exports);
25
+ var import_transform_body = require("./transform-body");
26
+ function createPostAction({
27
+ table,
28
+ db
29
+ }) {
30
+ return async (body) => {
31
+ const values = (0, import_transform_body.transformBody)(body);
32
+ const result = await db.insert(table).values(values).returning();
33
+ return result;
34
+ };
35
+ }
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ createPostAction
39
+ });
@@ -0,0 +1,8 @@
1
+ import { BaseTable } from "../types.js";
2
+ export declare function createPutAction<TTable extends BaseTable>({ db, table, }: {
3
+ bodySchema: any;
4
+ db: any;
5
+ table: TTable;
6
+ }): (body: Record<string, unknown>, { byCreator, }?: {
7
+ byCreator?: boolean | undefined;
8
+ }) => Promise<any>;
@@ -0,0 +1,60 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/backend/sqlite/actions/create-put-action.ts
20
+ var create_put_action_exports = {};
21
+ __export(create_put_action_exports, {
22
+ createPutAction: () => createPutAction
23
+ });
24
+ module.exports = __toCommonJS(create_put_action_exports);
25
+ var import_zod = require("zod");
26
+ var import_transform_body = require("./transform-body");
27
+ var import_drizzle_orm = require("drizzle-orm");
28
+ var import_sqlite = require("..");
29
+ var import_errors = require("../errors");
30
+ function createPutAction({
31
+ db,
32
+ table
33
+ }) {
34
+ return async (body, {
35
+ byCreator = true
36
+ } = {}) => {
37
+ if (byCreator) {
38
+ const data2 = await (0, import_sqlite.createGetAction)({
39
+ db,
40
+ table,
41
+ bodySchema: import_zod.z.object({
42
+ creatorId: import_zod.z.string(),
43
+ id: import_zod.z.string()
44
+ })
45
+ })({
46
+ creatorId: body.editorId,
47
+ id: body.id
48
+ });
49
+ if (!data2) {
50
+ throw new import_errors.HttpError(404, "未找到编辑对象,或没有权限");
51
+ }
52
+ }
53
+ const [data] = await db.update(table).set((0, import_transform_body.transformBody)(body)).where((0, import_drizzle_orm.eq)(table.id, body.id)).returning();
54
+ return data;
55
+ };
56
+ }
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ createPutAction
60
+ });
@@ -0,0 +1,9 @@
1
+ import { getListQuery } from "./get-list-query.js";
2
+ export declare function getListData({ query, countQuery, pageSize, current, }: {
3
+ bodySchema?: any;
4
+ current?: number;
5
+ pageSize?: number;
6
+ } & ReturnType<typeof getListQuery>): () => Promise<{
7
+ data: unknown[];
8
+ total: number;
9
+ }>;
@@ -0,0 +1,51 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/backend/sqlite/actions/get-list-data.ts
20
+ var get_list_data_exports = {};
21
+ __export(get_list_data_exports, {
22
+ getListData: () => getListData
23
+ });
24
+ module.exports = __toCommonJS(get_list_data_exports);
25
+ async function runSelect(query) {
26
+ const executable = query;
27
+ if (executable.all) {
28
+ return executable.all();
29
+ }
30
+ if (executable.execute) {
31
+ return executable.execute();
32
+ }
33
+ return [];
34
+ }
35
+ function getListData({
36
+ query,
37
+ countQuery,
38
+ pageSize = 10,
39
+ current = 1
40
+ }) {
41
+ return async () => {
42
+ const dataQuery = query.limit(+pageSize).offset((+current - 1) * +pageSize);
43
+ const data = await runSelect(dataQuery);
44
+ const [{ count }] = await runSelect(countQuery);
45
+ return { data, total: Number(count) };
46
+ };
47
+ }
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ getListData
51
+ });
@@ -0,0 +1,19 @@
1
+ import { BaseTable, GetListRelations } from "../types.js";
2
+ import { SelectedFields } from "drizzle-orm/sqlite-core/query-builders/select.types";
3
+ export declare function getListQuery<TTable extends BaseTable, TSelection extends SelectedFields>({ db, fields, jsonArrayFields, params, relations, table, }: {
4
+ db: any;
5
+ fields: TSelection;
6
+ jsonArrayFields?: string[];
7
+ params: {
8
+ [field: string]: unknown;
9
+ orderBy?: keyof BaseTable;
10
+ orderDir?: "asc" | "desc";
11
+ page?: number;
12
+ pageSize?: number;
13
+ };
14
+ relations?: GetListRelations;
15
+ table: TTable;
16
+ }): {
17
+ countQuery: any;
18
+ query: any;
19
+ };