@ai0x0/utils 0.0.38 → 0.0.40

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 (43) hide show
  1. package/.agents/skills/ai0x0-utils/backend/SKILL.md +13 -9
  2. package/SKILL.md +13 -9
  3. package/es/backend/route-operation/delete-operation.d.ts +10 -3
  4. package/es/backend/route-operation/delete-operation.js +39 -23
  5. package/es/backend/route-operation/get-list-operation.d.ts +11 -7
  6. package/es/backend/route-operation/get-list-operation.js +41 -23
  7. package/es/backend/route-operation/get-operation.d.ts +8 -4
  8. package/es/backend/route-operation/get-operation.js +38 -23
  9. package/es/backend/route-operation/post-operation.d.ts +8 -4
  10. package/es/backend/route-operation/post-operation.js +45 -38
  11. package/es/backend/route-operation/put-operation.d.ts +8 -4
  12. package/es/backend/route-operation/put-operation.js +53 -36
  13. package/es/backend/sqlite/route-operation/delete-operation.d.ts +9 -2
  14. package/es/backend/sqlite/route-operation/delete-operation.js +39 -26
  15. package/es/backend/sqlite/route-operation/get-list-operation.d.ts +8 -4
  16. package/es/backend/sqlite/route-operation/get-list-operation.js +41 -25
  17. package/es/backend/sqlite/route-operation/get-operation.d.ts +6 -2
  18. package/es/backend/sqlite/route-operation/get-operation.js +38 -25
  19. package/es/backend/sqlite/route-operation/post-operation.d.ts +6 -2
  20. package/es/backend/sqlite/route-operation/post-operation.js +44 -38
  21. package/es/backend/sqlite/route-operation/put-operation.d.ts +6 -2
  22. package/es/backend/sqlite/route-operation/put-operation.js +51 -37
  23. package/lib/backend/route-operation/delete-operation.d.ts +10 -3
  24. package/lib/backend/route-operation/delete-operation.js +6 -4
  25. package/lib/backend/route-operation/get-list-operation.d.ts +11 -7
  26. package/lib/backend/route-operation/get-list-operation.js +9 -9
  27. package/lib/backend/route-operation/get-operation.d.ts +8 -4
  28. package/lib/backend/route-operation/get-operation.js +9 -9
  29. package/lib/backend/route-operation/post-operation.d.ts +8 -4
  30. package/lib/backend/route-operation/post-operation.js +8 -6
  31. package/lib/backend/route-operation/put-operation.d.ts +8 -4
  32. package/lib/backend/route-operation/put-operation.js +11 -5
  33. package/lib/backend/sqlite/route-operation/delete-operation.d.ts +9 -2
  34. package/lib/backend/sqlite/route-operation/delete-operation.js +4 -3
  35. package/lib/backend/sqlite/route-operation/get-list-operation.d.ts +8 -4
  36. package/lib/backend/sqlite/route-operation/get-list-operation.js +12 -9
  37. package/lib/backend/sqlite/route-operation/get-operation.d.ts +6 -2
  38. package/lib/backend/sqlite/route-operation/get-operation.js +9 -9
  39. package/lib/backend/sqlite/route-operation/post-operation.d.ts +6 -2
  40. package/lib/backend/sqlite/route-operation/post-operation.js +8 -6
  41. package/lib/backend/sqlite/route-operation/put-operation.d.ts +6 -2
  42. package/lib/backend/sqlite/route-operation/put-operation.js +9 -4
  43. package/package.json +1 -1
@@ -6,11 +6,15 @@ 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?(payload: {
11
+ params: Partial<z.infer<T>> & Record<string, unknown>;
12
+ data: z.infer<T>;
13
+ }): Promise<z.infer<T>>;
14
+ onError?(error: Error): Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
12
15
  summary?: string;
13
- table: TTable;
16
+ tags?: string[];
17
+ table?: TTable;
14
18
  byCreator?: boolean;
15
19
  }
16
20
  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,21 +73,20 @@ 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
- result = await onSuccess(result);
89
+ result = await onSuccess({ data: result, params: mergedParams });
90
90
  }
91
91
  return import_next_rest_framework.TypedNextResponse.json(result, {
92
92
  status: 200
@@ -4,10 +4,14 @@ 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?(payload: {
11
+ params: Record<string, unknown>;
12
+ data: z.infer<OB>;
13
+ }): Promise<z.infer<OB>>;
14
+ onError?(error: Error): Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
15
+ table?: TTable;
12
16
  }
13
17
  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,11 +71,12 @@ 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
- creatorId: userId,
75
- ...mergedBody
76
- });
77
- const data = onSuccess ? await onSuccess(raw) : raw;
74
+ const params = { creatorId: userId, ...mergedBody };
75
+ const raw = table ? (await (0, import_actions.createPostAction)({ bodySchema, db, table })(params))[0] : params;
76
+ const data = onSuccess ? await onSuccess({
77
+ data: raw,
78
+ params
79
+ }) : raw;
78
80
  return import_next_rest_framework.TypedNextResponse.json(data, {
79
81
  status: 200
80
82
  });
@@ -4,11 +4,15 @@ 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?(payload: {
12
+ params: Record<string, unknown>;
13
+ data: z.infer<OB>;
14
+ }): Promise<z.infer<OB>>;
15
+ onError?(error: Error): Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
12
16
  byCreator?: boolean;
13
17
  }
14
18
  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,23 @@ var createPutOperation = ({
72
73
  req
73
74
  )) || {};
74
75
  const mergedBody = { ...body, ...extraBody };
75
- const raw = await (0, import_actions.createPutAction)({
76
+ const params = { editorId: userId, ...mergedBody };
77
+ const raw = table ? await (0, import_actions.createPutAction)({
76
78
  bodySchema,
77
79
  table,
78
80
  db
79
- })({ editorId: userId, ...mergedBody }, { byCreator });
80
- const data = onSuccess ? await onSuccess(raw) : raw;
81
+ })(params, { byCreator }) : params;
82
+ const data = onSuccess ? await onSuccess({
83
+ data: raw,
84
+ params
85
+ }) : raw;
81
86
  return import_next_rest_framework.TypedNextResponse.json(data, {
82
87
  status: 200
83
88
  });
84
89
  } catch (e) {
85
- if (!(e instanceof import_errors.HttpError))
90
+ if (!(e instanceof import_errors.HttpError)) {
86
91
  console.error(e);
92
+ }
87
93
  const response = await (onError == null ? void 0 : onError(e));
88
94
  if (response) {
89
95
  return response;
@@ -1,9 +1,16 @@
1
1
  import { TypedNextResponse } from "next-rest-framework";
2
2
  import { BaseTable } from "../types.js";
3
3
  export interface DeleteOperationOptions<TTable extends BaseTable> {
4
- table: TTable;
4
+ table?: TTable;
5
5
  summary?: string;
6
- onSuccess?: () => Promise<void>;
6
+ tags?: string[];
7
+ onSuccess?: (_payload: {
8
+ params: {
9
+ id: string;
10
+ creatorId?: string;
11
+ };
12
+ data: unknown;
13
+ }) => Promise<void>;
7
14
  onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
8
15
  byCreator?: boolean;
9
16
  }
@@ -43,6 +43,7 @@ var createDeleteOperation = ({
43
43
  }) => ({
44
44
  table,
45
45
  summary,
46
+ tags,
46
47
  onSuccess,
47
48
  onError,
48
49
  byCreator = true
@@ -50,7 +51,7 @@ var createDeleteOperation = ({
50
51
  method: "DELETE",
51
52
  openApiOperation: {
52
53
  summary,
53
- tags: [(0, import_get_table_name.default)(table)]
54
+ tags: tags ?? (table ? [(0, import_get_table_name.default)(table)] : [])
54
55
  }
55
56
  }).input({
56
57
  body: import_zod.z.object({
@@ -64,8 +65,8 @@ var createDeleteOperation = ({
64
65
  const { userId } = await getSession(req) || {};
65
66
  body.creatorId = userId;
66
67
  }
67
- const data = await (0, import_actions.createDeleteAction)({ table, db })(body);
68
- await (onSuccess == null ? void 0 : onSuccess());
68
+ const data = table ? await (0, import_actions.createDeleteAction)({ table, db })(body) : body;
69
+ await (onSuccess == null ? void 0 : onSuccess({ data, params: body }));
69
70
  return import_next_rest_framework.TypedNextResponse.json(data, {
70
71
  status: 200
71
72
  });
@@ -9,10 +9,14 @@ export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchem
9
9
  setParams?: (_req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string, unknown>>;
10
10
  byCreator?: boolean;
11
11
  summary?: string;
12
- table: TTable;
13
- onSuccess?: <D extends T>(_data: {
14
- data: z.infer<D>[];
15
- total: number;
12
+ tags?: string[];
13
+ table?: TTable;
14
+ onSuccess?: <D extends T>(_payload: {
15
+ params: Partial<z.infer<T>> & Record<string, unknown>;
16
+ data: {
17
+ data: z.infer<D>[];
18
+ total: number;
19
+ };
16
20
  }) => Promise<{
17
21
  data: z.infer<T>[];
18
22
  total: number;
@@ -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,20 +74,22 @@ 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
- result = await onSuccess(result);
89
+ result = await onSuccess({
90
+ data: result,
91
+ params: mergedParams
92
+ });
90
93
  }
91
94
  return import_next_rest_framework.TypedNextResponse.json(
92
95
  result,
@@ -7,10 +7,14 @@ export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, T
7
7
  querySchema: Q;
8
8
  relations?: GetListRelations;
9
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>>;
10
+ onSuccess?: (_payload: {
11
+ params: Partial<z.infer<T>> & Record<string, unknown>;
12
+ data: z.infer<T>;
13
+ }) => Promise<z.infer<T>>;
11
14
  onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
12
15
  summary?: string;
13
- table: TTable;
16
+ tags?: string[];
17
+ table?: TTable;
14
18
  byCreator?: boolean;
15
19
  }
16
20
  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,21 +73,20 @@ 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
- result = await onSuccess(result);
89
+ result = await onSuccess({ data: result, params: mergedParams });
90
90
  }
91
91
  return import_next_rest_framework.TypedNextResponse.json(result, {
92
92
  status: 200
@@ -6,8 +6,12 @@ export interface PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema
6
6
  outputBodySchema?: IB;
7
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>>;
9
+ tags?: string[];
10
+ onSuccess?: (_payload: {
11
+ params: Record<string, unknown>;
12
+ data: z.infer<OB>;
13
+ }) => Promise<z.infer<OB>>;
10
14
  onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
11
- table: TTable;
15
+ table?: TTable;
12
16
  }
13
17
  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,11 +71,12 @@ 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
- creatorId: userId,
75
- ...mergedBody
76
- });
77
- const data = onSuccess ? await onSuccess(raw) : raw;
74
+ const params = { creatorId: userId, ...mergedBody };
75
+ const raw = table ? (await (0, import_actions.createPostAction)({ bodySchema, db, table })(params))[0] : params;
76
+ const data = onSuccess ? await onSuccess({
77
+ data: raw,
78
+ params
79
+ }) : raw;
78
80
  return import_next_rest_framework.TypedNextResponse.json(data, {
79
81
  status: 200
80
82
  });
@@ -4,10 +4,14 @@ import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
4
4
  export interface PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends SQLiteTable> {
5
5
  bodySchema: IB;
6
6
  outputBodySchema?: OB;
7
- table: TTable;
7
+ table?: TTable;
8
8
  summary?: string;
9
+ tags?: string[];
9
10
  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
+ onSuccess?: (_payload: {
12
+ params: Record<string, unknown>;
13
+ data: z.infer<OB>;
14
+ }) => Promise<z.infer<OB>>;
11
15
  onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
12
16
  byCreator?: boolean;
13
17
  }
@@ -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,12 +73,16 @@ var createPutOperation = ({
72
73
  req
73
74
  )) || {};
74
75
  const mergedBody = { ...body, ...extraBody };
75
- const raw = await (0, import_actions.createPutAction)({
76
+ const params = { editorId: userId, ...mergedBody };
77
+ const raw = table ? await (0, import_actions.createPutAction)({
76
78
  bodySchema,
77
79
  table,
78
80
  db
79
- })({ editorId: userId, ...mergedBody }, { byCreator });
80
- const data = onSuccess ? await onSuccess(raw) : raw;
81
+ })(params, { byCreator }) : params;
82
+ const data = onSuccess ? await onSuccess({
83
+ data: raw,
84
+ params
85
+ }) : raw;
81
86
  return import_next_rest_framework.TypedNextResponse.json(data, {
82
87
  status: 200
83
88
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai0x0/utils",
3
- "version": "0.0.38",
3
+ "version": "0.0.40",
4
4
  "description": "AI0x0 utils",
5
5
  "keywords": [
6
6
  "ai0x0"