@ai0x0/utils 0.0.46 → 0.0.48

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 (77) hide show
  1. package/.agents/skills/ai0x0-utils/backend/SKILL.md +40 -38
  2. package/SKILL.md +39 -37
  3. package/es/__shims__/next-rest-framework.d.ts +2 -0
  4. package/es/backend/route-operation/delete-operation.d.ts +7 -18
  5. package/es/backend/route-operation/delete-operation.js +10 -122
  6. package/es/backend/route-operation/get-list-operation.d.ts +5 -27
  7. package/es/backend/route-operation/get-list-operation.js +10 -135
  8. package/es/backend/route-operation/get-operation.d.ts +5 -21
  9. package/es/backend/route-operation/get-operation.js +10 -132
  10. package/es/backend/route-operation/get-table-name.js +0 -2
  11. package/es/backend/route-operation/index.d.ts +1 -0
  12. package/es/backend/route-operation/index.js +2 -1
  13. package/es/backend/route-operation/open-api-operation.d.ts +6 -0
  14. package/es/backend/route-operation/open-api-operation.js +13 -0
  15. package/es/backend/route-operation/operation-common.d.ts +38 -0
  16. package/es/backend/route-operation/operation-common.js +148 -0
  17. package/es/backend/route-operation/operation-core.d.ts +3 -0
  18. package/es/backend/route-operation/operation-core.js +3 -0
  19. package/es/backend/route-operation/post-operation.d.ts +5 -25
  20. package/es/backend/route-operation/post-operation.js +13 -189
  21. package/es/backend/route-operation/put-operation.d.ts +4 -23
  22. package/es/backend/route-operation/put-operation.js +10 -155
  23. package/es/backend/route-operation/read-operation-core.d.ts +55 -0
  24. package/es/backend/route-operation/read-operation-core.js +224 -0
  25. package/es/backend/route-operation/write-operation-core.d.ts +94 -0
  26. package/es/backend/route-operation/write-operation-core.js +390 -0
  27. package/es/backend/sqlite/route-operation/delete-operation.d.ts +9 -20
  28. package/es/backend/sqlite/route-operation/delete-operation.js +10 -122
  29. package/es/backend/sqlite/route-operation/get-list-operation.d.ts +6 -28
  30. package/es/backend/sqlite/route-operation/get-list-operation.js +10 -135
  31. package/es/backend/sqlite/route-operation/get-operation.d.ts +6 -22
  32. package/es/backend/sqlite/route-operation/get-operation.js +10 -132
  33. package/es/backend/sqlite/route-operation/index.d.ts +1 -0
  34. package/es/backend/sqlite/route-operation/index.js +2 -1
  35. package/es/backend/sqlite/route-operation/post-operation.d.ts +6 -26
  36. package/es/backend/sqlite/route-operation/post-operation.js +13 -189
  37. package/es/backend/sqlite/route-operation/put-operation.d.ts +6 -25
  38. package/es/backend/sqlite/route-operation/put-operation.js +10 -155
  39. package/es/backend/sqlite/schemas/index.d.ts +69 -5
  40. package/es/backend/sqlite/schemas/index.js +0 -1
  41. package/lib/__shims__/next-rest-framework.d.ts +2 -0
  42. package/lib/backend/route-operation/delete-operation.d.ts +7 -18
  43. package/lib/backend/route-operation/delete-operation.js +7 -52
  44. package/lib/backend/route-operation/get-list-operation.d.ts +5 -27
  45. package/lib/backend/route-operation/get-list-operation.js +7 -68
  46. package/lib/backend/route-operation/get-operation.d.ts +5 -21
  47. package/lib/backend/route-operation/get-operation.js +7 -67
  48. package/lib/backend/route-operation/index.d.ts +1 -0
  49. package/lib/backend/route-operation/index.js +3 -1
  50. package/lib/backend/route-operation/open-api-operation.d.ts +6 -0
  51. package/lib/backend/route-operation/open-api-operation.js +37 -0
  52. package/lib/backend/route-operation/operation-common.d.ts +38 -0
  53. package/lib/backend/route-operation/operation-common.js +90 -0
  54. package/lib/backend/route-operation/operation-core.d.ts +3 -0
  55. package/lib/backend/route-operation/operation-core.js +27 -0
  56. package/lib/backend/route-operation/post-operation.d.ts +5 -25
  57. package/lib/backend/route-operation/post-operation.js +7 -71
  58. package/lib/backend/route-operation/put-operation.d.ts +4 -23
  59. package/lib/backend/route-operation/put-operation.js +7 -68
  60. package/lib/backend/route-operation/read-operation-core.d.ts +55 -0
  61. package/lib/backend/route-operation/read-operation-core.js +151 -0
  62. package/lib/backend/route-operation/write-operation-core.d.ts +94 -0
  63. package/lib/backend/route-operation/write-operation-core.js +181 -0
  64. package/lib/backend/sqlite/route-operation/delete-operation.d.ts +9 -20
  65. package/lib/backend/sqlite/route-operation/delete-operation.js +7 -52
  66. package/lib/backend/sqlite/route-operation/get-list-operation.d.ts +6 -28
  67. package/lib/backend/sqlite/route-operation/get-list-operation.js +7 -71
  68. package/lib/backend/sqlite/route-operation/get-operation.d.ts +6 -22
  69. package/lib/backend/sqlite/route-operation/get-operation.js +7 -67
  70. package/lib/backend/sqlite/route-operation/index.d.ts +1 -0
  71. package/lib/backend/sqlite/route-operation/index.js +3 -1
  72. package/lib/backend/sqlite/route-operation/post-operation.d.ts +6 -26
  73. package/lib/backend/sqlite/route-operation/post-operation.js +7 -71
  74. package/lib/backend/sqlite/route-operation/put-operation.d.ts +6 -25
  75. package/lib/backend/sqlite/route-operation/put-operation.js +7 -68
  76. package/lib/backend/sqlite/schemas/index.d.ts +69 -5
  77. package/package.json +1 -1
@@ -32,81 +32,17 @@ __export(post_operation_exports, {
32
32
  createPostOperation: () => createPostOperation
33
33
  });
34
34
  module.exports = __toCommonJS(post_operation_exports);
35
- var import_zod = require("zod");
36
- var import_next_rest_framework = require("next-rest-framework");
35
+ var import_create_post_action = require("../actions/create-post-action");
36
+ var import_operation_core = require("../../route-operation/operation-core");
37
37
  var import_get_table_name = __toESM(require("./get-table-name"));
38
- var import_actions = require("../actions");
39
- async function readPostBody(req, {
40
- contentType,
41
- parseBody
42
- }) {
43
- if (parseBody) {
44
- return parseBody(req);
45
- }
46
- if (contentType === "multipart/form-data") {
47
- return Object.fromEntries(await req.formData());
48
- }
49
- return await req.json();
50
- }
38
+ var createOperation = (0, import_operation_core.createPostOperationFactory)({
39
+ createAction: import_create_post_action.createPostAction,
40
+ getTableName: import_get_table_name.default
41
+ });
51
42
  var createPostOperation = ({
52
43
  getSession,
53
44
  db
54
- }) => ({
55
- bodySchema,
56
- contentType = "application/json",
57
- description,
58
- outputBodySchema,
59
- parseBody,
60
- setBody,
61
- summary,
62
- tags,
63
- table,
64
- onSuccess,
65
- onError
66
- }) => (0, import_next_rest_framework.routeOperation)({
67
- method: "POST",
68
- openApiOperation: {
69
- description,
70
- summary,
71
- tags: tags ?? (table ? [(0, import_get_table_name.default)(table)] : [])
72
- }
73
- }).input({
74
- body: bodySchema,
75
- contentType
76
- }).outputs([
77
- {
78
- body: outputBodySchema || import_zod.z.object({ id: import_zod.z.string() }),
79
- contentType: "application/json",
80
- status: 200
81
- }
82
- ]).handler(async (req) => {
83
- try {
84
- const { userId } = await getSession(req) || {};
85
- const body = await readPostBody(req, { contentType, parseBody });
86
- const extraBody = await (setBody == null ? void 0 : setBody(req)) || {};
87
- const mergedBody = { ...body, ...extraBody };
88
- const params = { creatorId: userId, ...mergedBody };
89
- const raw = table && db ? (await (0, import_actions.createPostAction)({ bodySchema, db, table })(
90
- params
91
- ))[0] : params;
92
- const data = onSuccess ? await onSuccess({
93
- data: raw,
94
- params,
95
- req
96
- }) : raw;
97
- return import_next_rest_framework.TypedNextResponse.json(data, {
98
- status: 200
99
- });
100
- } catch (e) {
101
- console.error(e);
102
- const response = await (onError == null ? void 0 : onError(e));
103
- if (response) {
104
- return response;
105
- } else {
106
- throw e;
107
- }
108
- }
109
- });
45
+ }) => createOperation({ db, getSession });
110
46
  // Annotate the CommonJS export names for ESM import in node:
111
47
  0 && (module.exports = {
112
48
  createPostOperation
@@ -1,30 +1,11 @@
1
- import { z, ZodSchema } from "zod";
2
1
  import { SQLiteTable } from "drizzle-orm/sqlite-core";
3
- import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
4
2
  import { NextRequest } from "next/server";
5
- import { BaseTable } from "../types.js";
6
- type PutOperationParams<IB extends ZodSchema> = z.infer<IB> & Record<string, unknown> & {
7
- editorId?: string;
8
- };
9
- export interface PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends SQLiteTable> {
10
- bodySchema: IB;
11
- description?: string;
12
- outputBodySchema?: OB;
13
- table?: TTable;
14
- summary?: string;
15
- tags?: string[];
16
- setBody?: (_req: TypedNextRequest<"PUT", "application/json", z.infer<IB>>) => Promise<Partial<z.infer<IB>>>;
17
- onSuccess?: (_payload: {
18
- params: PutOperationParams<IB>;
19
- data: z.infer<OB>;
20
- }) => Promise<z.infer<OB>>;
21
- onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
22
- byCreator?: boolean;
23
- }
3
+ import { ZodSchema } from "zod";
4
+ import { type PutOperationOptions as CorePutOperationOptions } from "../../route-operation/operation-core.js";
5
+ export type PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends SQLiteTable> = CorePutOperationOptions<IB, OB, TTable>;
24
6
  export declare const createPutOperation: ({ getSession, db, }: {
25
- getSession: (_req: NextRequest) => Promise<{
7
+ getSession(req: NextRequest): Promise<{
26
8
  userId?: string;
27
9
  } | undefined>;
28
- db?: any;
29
- }) => <IB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, TTable extends BaseTable>({ bodySchema, description, outputBodySchema, table, summary, tags, setBody, onSuccess, byCreator, onError, }: PutOperationOptions<IB, OB, TTable>) => import("next-rest-framework").RouteOperationDefinition<"PUT">;
30
- export {};
10
+ db?: unknown;
11
+ }) => <IB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>, OB extends ZodSchema<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>({ schemas, access, openApiOperation, table, setBody, handler, catch: catchHandler, }: CorePutOperationOptions<IB, OB, SQLiteTable<import("drizzle-orm/sqlite-core").TableConfig>>) => import("next-rest-framework").RouteOperationDefinition<"PUT">;
@@ -32,78 +32,17 @@ __export(put_operation_exports, {
32
32
  createPutOperation: () => createPutOperation
33
33
  });
34
34
  module.exports = __toCommonJS(put_operation_exports);
35
- var import_zod = require("zod");
36
- var import_next_rest_framework = require("next-rest-framework");
35
+ var import_create_put_action = require("../actions/create-put-action");
36
+ var import_operation_core = require("../../route-operation/operation-core");
37
37
  var import_get_table_name = __toESM(require("./get-table-name"));
38
- var import_actions = require("../actions");
39
- var import_errors = require("../errors");
38
+ var createOperation = (0, import_operation_core.createPutOperationFactory)({
39
+ createAction: import_create_put_action.createPutAction,
40
+ getTableName: import_get_table_name.default
41
+ });
40
42
  var createPutOperation = ({
41
43
  getSession,
42
44
  db
43
- }) => ({
44
- bodySchema,
45
- description,
46
- outputBodySchema,
47
- table,
48
- summary,
49
- tags,
50
- setBody,
51
- onSuccess,
52
- byCreator = true,
53
- onError
54
- }) => (0, import_next_rest_framework.routeOperation)({
55
- method: "PUT",
56
- openApiOperation: {
57
- description,
58
- summary,
59
- tags: tags ?? (table ? [(0, import_get_table_name.default)(table)] : [])
60
- }
61
- }).input({
62
- body: bodySchema,
63
- contentType: "application/json"
64
- }).outputs([
65
- {
66
- body: outputBodySchema || import_zod.z.void(),
67
- status: 200,
68
- contentType: "application/json"
69
- }
70
- ]).handler(async (req) => {
71
- try {
72
- const { userId } = await getSession(req) || {};
73
- const body = await req.json();
74
- const extraBody = await (setBody == null ? void 0 : setBody(
75
- req
76
- )) || {};
77
- const mergedBody = { ...body, ...extraBody };
78
- const params = { editorId: userId, ...mergedBody };
79
- const raw = table && db ? await (0, import_actions.createPutAction)({
80
- bodySchema,
81
- table,
82
- db
83
- })(params, { byCreator }) : params;
84
- const data = onSuccess ? await onSuccess({
85
- data: raw,
86
- params
87
- }) : raw;
88
- return import_next_rest_framework.TypedNextResponse.json(data, {
89
- status: 200
90
- });
91
- } catch (e) {
92
- if (!(e instanceof import_errors.HttpError)) {
93
- console.error(e);
94
- }
95
- const response = await (onError == null ? void 0 : onError(e));
96
- if (response) {
97
- return response;
98
- }
99
- if (e instanceof import_errors.HttpError) {
100
- return import_next_rest_framework.TypedNextResponse.json({ message: e.message }, {
101
- status: e.status
102
- });
103
- }
104
- throw e;
105
- }
106
- });
45
+ }) => createOperation({ db, getSession });
107
46
  // Annotate the CommonJS export names for ESM import in node:
108
47
  0 && (module.exports = {
109
48
  createPutOperation
@@ -42,12 +42,76 @@ export declare const BASIC_UPDATE_OMIT: {
42
42
  readonly createdAt: true;
43
43
  readonly updatedAt: true;
44
44
  };
45
- export declare const queryListSchema: (schema: any) => z.ZodObject<{
46
- [x: string]: any;
47
- }, any>;
48
- export declare const listBodySchema: (schema: any) => z.ZodObject<{
45
+ export declare const queryListSchema: <Incoming extends z.ZodObject<z.core.$ZodLooseShape, z.core.$strip>>(schema: Incoming) => z.ZodObject<(("creatorId" | "orderBy" | "orderDir" | "pageSize" | "current" | "createdAtFrom" | "createdAtTo") & keyof Incoming["shape"] extends never ? {
46
+ current: z.ZodDefault<z.ZodOptional<z.ZodString>>;
47
+ pageSize: z.ZodDefault<z.ZodOptional<z.ZodString>>;
48
+ createdAtFrom: z.ZodOptional<z.ZodString>;
49
+ createdAtTo: z.ZodOptional<z.ZodString>;
50
+ orderBy: z.ZodOptional<z.ZodString>;
51
+ creatorId: z.ZodOptional<z.ZodString>;
52
+ orderDir: z.ZodOptional<z.ZodEnum<{
53
+ asc: "asc";
54
+ desc: "desc";
55
+ }>>;
56
+ } & Incoming["shape"] : ({
57
+ current: z.ZodDefault<z.ZodOptional<z.ZodString>>;
58
+ pageSize: z.ZodDefault<z.ZodOptional<z.ZodString>>;
59
+ createdAtFrom: z.ZodOptional<z.ZodString>;
60
+ createdAtTo: z.ZodOptional<z.ZodString>;
61
+ orderBy: z.ZodOptional<z.ZodString>;
62
+ creatorId: z.ZodOptional<z.ZodString>;
63
+ orderDir: z.ZodOptional<z.ZodEnum<{
64
+ asc: "asc";
65
+ desc: "desc";
66
+ }>>;
67
+ } extends infer T_1 extends z.core.util.SomeObject ? { [K in keyof T_1 as K extends keyof Incoming["shape"] ? never : K]: {
68
+ current: z.ZodDefault<z.ZodOptional<z.ZodString>>;
69
+ pageSize: z.ZodDefault<z.ZodOptional<z.ZodString>>;
70
+ createdAtFrom: z.ZodOptional<z.ZodString>;
71
+ createdAtTo: z.ZodOptional<z.ZodString>;
72
+ orderBy: z.ZodOptional<z.ZodString>;
73
+ creatorId: z.ZodOptional<z.ZodString>;
74
+ orderDir: z.ZodOptional<z.ZodEnum<{
75
+ asc: "asc";
76
+ desc: "desc";
77
+ }>>;
78
+ }[K]; } : never) & (Incoming["shape"] extends infer T_2 extends z.core.util.SomeObject ? { [K_1 in keyof T_2]: Incoming["shape"][K_1]; } : never)) extends infer T ? { [k in keyof T]: (("creatorId" | "orderBy" | "orderDir" | "pageSize" | "current" | "createdAtFrom" | "createdAtTo") & keyof Incoming["shape"] extends never ? {
79
+ current: z.ZodDefault<z.ZodOptional<z.ZodString>>;
80
+ pageSize: z.ZodDefault<z.ZodOptional<z.ZodString>>;
81
+ createdAtFrom: z.ZodOptional<z.ZodString>;
82
+ createdAtTo: z.ZodOptional<z.ZodString>;
83
+ orderBy: z.ZodOptional<z.ZodString>;
84
+ creatorId: z.ZodOptional<z.ZodString>;
85
+ orderDir: z.ZodOptional<z.ZodEnum<{
86
+ asc: "asc";
87
+ desc: "desc";
88
+ }>>;
89
+ } & Incoming["shape"] : ({
90
+ current: z.ZodDefault<z.ZodOptional<z.ZodString>>;
91
+ pageSize: z.ZodDefault<z.ZodOptional<z.ZodString>>;
92
+ createdAtFrom: z.ZodOptional<z.ZodString>;
93
+ createdAtTo: z.ZodOptional<z.ZodString>;
94
+ orderBy: z.ZodOptional<z.ZodString>;
95
+ creatorId: z.ZodOptional<z.ZodString>;
96
+ orderDir: z.ZodOptional<z.ZodEnum<{
97
+ asc: "asc";
98
+ desc: "desc";
99
+ }>>;
100
+ } extends infer T_1 extends z.core.util.SomeObject ? { [K in keyof T_1 as K extends keyof Incoming["shape"] ? never : K]: {
101
+ current: z.ZodDefault<z.ZodOptional<z.ZodString>>;
102
+ pageSize: z.ZodDefault<z.ZodOptional<z.ZodString>>;
103
+ createdAtFrom: z.ZodOptional<z.ZodString>;
104
+ createdAtTo: z.ZodOptional<z.ZodString>;
105
+ orderBy: z.ZodOptional<z.ZodString>;
106
+ creatorId: z.ZodOptional<z.ZodString>;
107
+ orderDir: z.ZodOptional<z.ZodEnum<{
108
+ asc: "asc";
109
+ desc: "desc";
110
+ }>>;
111
+ }[K]; } : never) & (Incoming["shape"] extends infer T_2 extends z.core.util.SomeObject ? { [K_1 in keyof T_2]: Incoming["shape"][K_1]; } : never))[k]; } : never, Incoming["_zod"]["config"]>;
112
+ export declare const listBodySchema: <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>(schema: T) => z.ZodObject<{
49
113
  total: z.ZodNumber;
50
- data: z.ZodArray<any>;
114
+ data: z.ZodArray<T>;
51
115
  }, z.core.$strip>;
52
116
  /**
53
117
  * 基于 drizzle + drizzle-zod 快速生成带基础字段(id / 创建时间等)的
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai0x0/utils",
3
- "version": "0.0.46",
3
+ "version": "0.0.48",
4
4
  "description": "AI0x0 utils",
5
5
  "keywords": [
6
6
  "ai0x0"