@ai0x0/utils 0.0.17 → 0.0.18

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 (34) hide show
  1. package/es/backend/actions/create-delete-action.d.ts +4 -3
  2. package/es/backend/actions/create-get-action.d.ts +3 -2
  3. package/es/backend/actions/create-get-list-action.d.ts +3 -2
  4. package/es/backend/actions/create-post-action.d.ts +4 -4
  5. package/es/backend/actions/create-put-action.d.ts +3 -2
  6. package/es/backend/actions/get-list-query.d.ts +12 -4
  7. package/es/backend/actions/get-list-query.js +8 -11
  8. package/es/backend/route-operation/delete-operation.d.ts +3 -2
  9. package/es/backend/route-operation/get-list-operation.d.ts +3 -2
  10. package/es/backend/route-operation/get-operation.d.ts +3 -2
  11. package/es/backend/route-operation/get-table-name.d.ts +2 -2
  12. package/es/backend/route-operation/post-operation.d.ts +5 -5
  13. package/es/backend/route-operation/put-operation.d.ts +5 -4
  14. package/es/backend/schemas/index.d.ts +597 -598
  15. package/es/backend/schemas/index.js +31 -19
  16. package/es/backend/types.d.ts +8 -14
  17. package/lib/backend/actions/create-delete-action.d.ts +4 -3
  18. package/lib/backend/actions/create-get-action.d.ts +3 -2
  19. package/lib/backend/actions/create-get-list-action.d.ts +3 -2
  20. package/lib/backend/actions/create-post-action.d.ts +4 -4
  21. package/lib/backend/actions/create-post-action.js +4 -1
  22. package/lib/backend/actions/create-put-action.d.ts +3 -2
  23. package/lib/backend/actions/get-list-query.d.ts +12 -4
  24. package/lib/backend/actions/get-list-query.js +6 -7
  25. package/lib/backend/route-operation/delete-operation.d.ts +3 -2
  26. package/lib/backend/route-operation/get-list-operation.d.ts +3 -2
  27. package/lib/backend/route-operation/get-operation.d.ts +3 -2
  28. package/lib/backend/route-operation/get-table-name.d.ts +2 -2
  29. package/lib/backend/route-operation/post-operation.d.ts +5 -5
  30. package/lib/backend/route-operation/put-operation.d.ts +5 -4
  31. package/lib/backend/schemas/index.d.ts +597 -598
  32. package/lib/backend/schemas/index.js +21 -21
  33. package/lib/backend/types.d.ts +8 -14
  34. package/package.json +1 -1
@@ -1,8 +1,9 @@
1
- import { BaseTable, AnyDatabase } from "../types";
1
+ import { NodePgDatabase } from "drizzle-orm/node-postgres";
2
+ import { BaseTable } from "../types";
2
3
  export declare function createDeleteAction<TTable extends BaseTable>({ table, db, }: {
3
- db: AnyDatabase;
4
+ db: NodePgDatabase<Record<string, unknown>>;
4
5
  table: TTable;
5
6
  }): ({ id, creatorId }: {
6
7
  id: string;
7
8
  creatorId?: string | undefined;
8
- }) => Promise<any>;
9
+ }) => Promise<TTable["$inferSelect"] extends infer T ? T extends TTable["$inferSelect"] ? T extends undefined ? QueryResult<import("drizzle-orm").Assume<this["row"], QueryResultRow>> : T[] : never : never>;
@@ -1,8 +1,9 @@
1
1
  import { z, ZodSchema } from "zod";
2
- import { BaseTable, GetListRelations, AnyDatabase } from "../types";
2
+ import { NodePgDatabase } from "drizzle-orm/node-postgres";
3
+ import { BaseTable, GetListRelations } from "../types";
3
4
  export declare function createGetAction<T extends ZodSchema, TTable extends BaseTable>({ bodySchema, db, jsonArrayFields, relations, table, }: {
4
5
  bodySchema: T;
5
- db: AnyDatabase;
6
+ db: NodePgDatabase<Record<string, unknown>>;
6
7
  jsonArrayFields?: string[];
7
8
  relations?: GetListRelations;
8
9
  table: TTable;
@@ -1,8 +1,9 @@
1
1
  import { z, ZodSchema } from "zod";
2
- import { BaseTable, GetListRelations, AnyDatabase } from "../types";
2
+ import { BaseTable, GetListRelations } from "../types";
3
+ import { NodePgDatabase } from "drizzle-orm/node-postgres";
3
4
  export declare function createGetListAction<T extends ZodSchema, TTable extends BaseTable>({ bodySchema, db, jsonArrayFields, relations, table, }: {
4
5
  bodySchema: T;
5
- db: AnyDatabase;
6
+ db: NodePgDatabase<Record<string, unknown>>;
6
7
  jsonArrayFields?: string[];
7
8
  relations?: GetListRelations;
8
9
  table: TTable;
@@ -1,8 +1,8 @@
1
1
  import { z, ZodSchema } from "zod";
2
- import { AnyDatabase } from "../types";
3
- import { SQLiteTable } from "drizzle-orm/sqlite-core";
4
- export declare function createPostAction<T extends ZodSchema, TTable extends SQLiteTable>({ table, db }: {
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
5
  bodySchema: T;
6
- db: AnyDatabase;
6
+ db: NodePgDatabase<Record<string, unknown>>;
7
7
  table: TTable;
8
8
  }): (body: z.infer<T>) => Promise<z.infer<T>[]>;
@@ -1,8 +1,9 @@
1
1
  import { z, ZodSchema } from "zod";
2
- import { BaseTable, AnyDatabase } from "../types";
2
+ import { NodePgDatabase } from "drizzle-orm/node-postgres";
3
+ import { BaseTable } from "../types";
3
4
  export declare function createPutAction<T extends ZodSchema, TTable extends BaseTable>({ db, table, }: {
4
5
  bodySchema: T;
5
- db: AnyDatabase;
6
+ db: NodePgDatabase<Record<string, unknown>>;
6
7
  table: TTable;
7
8
  }): (body: Partial<z.infer<T>> & Record<string, unknown>, { byCreator, }?: {
8
9
  byCreator?: boolean | undefined;
@@ -1,7 +1,9 @@
1
- import { BaseTable, GetListRelations, AnyDatabase } from "../types";
2
- import { SelectedFields } from "drizzle-orm/sqlite-core/query-builders/select.types";
1
+ import { BaseTable, GetListRelations } from "../types";
2
+ import { SelectedFields } from "drizzle-orm/pg-core/query-builders/select.types";
3
+ import { SQL } from "drizzle-orm";
4
+ import { NodePgDatabase } from "drizzle-orm/node-postgres";
3
5
  export declare function getListQuery<TTable extends BaseTable, TSelection extends SelectedFields>({ db, fields, jsonArrayFields, params, relations, table, }: {
4
- db: AnyDatabase;
6
+ db: NodePgDatabase<Record<string, unknown>>;
5
7
  fields: TSelection;
6
8
  jsonArrayFields?: string[];
7
9
  params: {
@@ -14,6 +16,12 @@ export declare function getListQuery<TTable extends BaseTable, TSelection extend
14
16
  relations?: GetListRelations;
15
17
  table: TTable;
16
18
  }): {
17
- countQuery: any;
19
+ countQuery: Omit<import("drizzle-orm/pg-core").PgSelectBase<string, {
20
+ count: SQL<unknown>;
21
+ }, "partial", Record<string, "not-null">, false, "where", {
22
+ count: unknown;
23
+ }[], {
24
+ count: import("drizzle-orm").DrizzleTypeError<"You cannot reference this field without assigning it an alias first - use `.as(<alias>)`">;
25
+ }>, "where">;
18
26
  query: any;
19
27
  };
@@ -1,10 +1,11 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _templateObject, _templateObject2, _templateObject3;
2
3
  var _excluded = ["page", "pageSize", "orderBy", "orderDir"];
3
- var _templateObject, _templateObject2, _templateObject3, _templateObject4;
4
4
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
5
5
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
6
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
7
7
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
8
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
8
9
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
9
10
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
11
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
@@ -19,11 +20,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
19
20
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
20
21
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
21
22
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
22
- function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
23
- import { and, asc, desc, eq, gte, inArray, lte, or, sql } from "drizzle-orm";
24
- var ciLike = function ciLike(col, value) {
25
- return sql(_templateObject || (_templateObject = _taggedTemplateLiteral(["LOWER(", ") LIKE ", ""])), col, value.toLowerCase());
26
- };
23
+ import { and, asc, desc, eq, gte, ilike, inArray, lte, or, sql } from "drizzle-orm";
27
24
  export function getListQuery(_ref) {
28
25
  var db = _ref.db,
29
26
  fields = _ref.fields,
@@ -105,12 +102,12 @@ export function getListQuery(_ref) {
105
102
  if (values.length > 0) {
106
103
  if (isJsonArray) {
107
104
  // 处理JSONB数组字段
108
- conditions.push(sql(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n EXISTS (\n SELECT 1 FROM json_each(", ")\n WHERE LOWER(json_each.value) LIKE ", "\n )\n "])), targetColumn, "%".concat(values[0], "%")));
105
+ conditions.push(sql(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n EXISTS (\n SELECT 1 FROM jsonb_array_elements_text(", ") tag\n WHERE tag LIKE ", "\n )\n "])), targetColumn, "%".concat(values[0], "%")));
109
106
  } else if (isIdField) {
110
107
  conditions.push(inArray(targetColumn, values));
111
108
  } else {
112
109
  conditions.push(or.apply(void 0, _toConsumableArray(values.map(function (v) {
113
- return ciLike(targetColumn, "%".concat(v, "%"));
110
+ return ilike(targetColumn, "%".concat(v, "%"));
114
111
  }))));
115
112
  }
116
113
  }
@@ -118,11 +115,11 @@ export function getListQuery(_ref) {
118
115
  // 处理单值
119
116
  if (isJsonArray) {
120
117
  // 处理JSONB数组字段
121
- conditions.push(sql(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n EXISTS (\n SELECT 1 FROM json_each(", ")\n WHERE LOWER(json_each.value) LIKE ", "\n )\n "])), targetColumn, "%".concat(value, "%")));
118
+ conditions.push(sql(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n EXISTS (\n SELECT 1 FROM jsonb_array_elements_text(", ") tag\n WHERE tag LIKE ", "\n )\n "])), targetColumn, "%".concat(value, "%")));
122
119
  } else if (isIdField) {
123
120
  conditions.push(eq(targetColumn, value));
124
121
  } else {
125
- conditions.push(ciLike(targetColumn, "%".concat(value, "%")));
122
+ conditions.push(ilike(targetColumn, "%".concat(value, "%")));
126
123
  }
127
124
  }
128
125
  } else {
@@ -182,7 +179,7 @@ export function getListQuery(_ref) {
182
179
 
183
180
  // 构建计数查询(优化后)
184
181
  var countQuery = db.select({
185
- count: sql(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["COUNT(DISTINCT ", ")"])), table.id)
182
+ count: sql(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["COUNT(DISTINCT ", ")"])), table.id)
186
183
  }).from(table).where(conditions.length > 0 ? and.apply(void 0, _toConsumableArray(conditions)) : undefined);
187
184
 
188
185
  // 添加关联
@@ -1,5 +1,6 @@
1
1
  import { TypedNextResponse } from "next-rest-framework";
2
- import { BaseTable, AnyDatabase } from "../types";
2
+ import { BaseTable } from "../types";
3
+ import { NodePgDatabase } from "drizzle-orm/node-postgres";
3
4
  import { NextRequest } from "next/server";
4
5
  export interface DeleteOperationOptions<TTable extends BaseTable> {
5
6
  table: TTable;
@@ -9,7 +10,7 @@ export interface DeleteOperationOptions<TTable extends BaseTable> {
9
10
  byCreator?: boolean;
10
11
  }
11
12
  export declare const createDeleteOperation: ({ db, getSession, }: {
12
- db: AnyDatabase;
13
+ db: NodePgDatabase<Record<string, unknown>>;
13
14
  getSession: (req: NextRequest) => Promise<{
14
15
  userId?: string;
15
16
  } | undefined>;
@@ -1,7 +1,8 @@
1
1
  import { z, ZodSchema } from "zod";
2
2
  import { NextRequest } from "next/server";
3
3
  import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
4
- import { BaseTable, GetListRelations, AnyDatabase } from "../types";
4
+ import { NodePgDatabase } from "drizzle-orm/node-postgres";
5
+ import { BaseTable, GetListRelations } from "../types";
5
6
  export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> {
6
7
  bodySchema: T;
7
8
  jsonArrayFields?: string[];
@@ -21,7 +22,7 @@ export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchem
21
22
  onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
22
23
  }
23
24
  export declare const createGetListOperation: ({ db, getSession, }: {
24
- db: AnyDatabase;
25
+ db: NodePgDatabase<Record<string, unknown>>;
25
26
  getSession: (req: NextRequest) => Promise<{
26
27
  userId?: string;
27
28
  } | undefined>;
@@ -1,7 +1,8 @@
1
1
  import { z, ZodSchema } from "zod";
2
2
  import { NextRequest } from "next/server";
3
3
  import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
4
- import { BaseTable, GetListRelations, AnyDatabase } from "../types";
4
+ import { NodePgDatabase } from "drizzle-orm/node-postgres";
5
+ import { BaseTable, GetListRelations } from "../types";
5
6
  export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> {
6
7
  bodySchema: T;
7
8
  jsonArrayFields?: string[];
@@ -15,7 +16,7 @@ export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, T
15
16
  byCreator?: boolean;
16
17
  }
17
18
  export declare const createGetOperation: ({ getSession, db, }: {
18
- db: AnyDatabase;
19
+ db: NodePgDatabase<Record<string, unknown>>;
19
20
  getSession: (req: NextRequest) => Promise<{
20
21
  userId?: string;
21
22
  } | undefined>;
@@ -1,3 +1,3 @@
1
- import { SQLiteTable } from "drizzle-orm/sqlite-core";
2
- declare function getTableName(table: SQLiteTable): string;
1
+ import { PgTable } from "drizzle-orm/pg-core";
2
+ declare function getTableName(table: PgTable): string;
3
3
  export default getTableName;
@@ -1,9 +1,9 @@
1
1
  import { z, ZodSchema } from "zod";
2
- import { AnyDatabase } from "../types";
3
- import { SQLiteTable } from "drizzle-orm/sqlite-core";
2
+ import { PgTable } from "drizzle-orm/pg-core";
4
3
  import { NextRequest } from "next/server";
5
4
  import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
6
- export interface PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends SQLiteTable> {
5
+ import { NodePgDatabase } from "drizzle-orm/node-postgres";
6
+ export interface PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends PgTable> {
7
7
  bodySchema: IB;
8
8
  outputBodySchema?: IB;
9
9
  setBody?: (req: TypedNextRequest<"POST", "application/json", z.infer<IB>>) => Promise<Partial<z.infer<IB>>>;
@@ -13,8 +13,8 @@ export interface PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema
13
13
  table: TTable;
14
14
  }
15
15
  export declare const createPostOperation: ({ getSession, db, }: {
16
- db: AnyDatabase;
16
+ db: NodePgDatabase<Record<string, unknown>>;
17
17
  getSession: (req: NextRequest) => Promise<{
18
18
  userId?: string;
19
19
  } | undefined>;
20
- }) => <IB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, TTable extends SQLiteTable<import("drizzle-orm/sqlite-core").TableConfig>>({ bodySchema, outputBodySchema, setBody, summary, table, onSuccess, onError, }: PostOperationOptions<IB, OB, TTable>) => import("next-rest-framework").RouteOperationDefinition<"POST">;
20
+ }) => <IB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, OB extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, TTable extends PgTable<import("drizzle-orm/pg-core").TableConfig>>({ bodySchema, outputBodySchema, setBody, summary, table, onSuccess, onError, }: PostOperationOptions<IB, OB, TTable>) => import("next-rest-framework").RouteOperationDefinition<"POST">;
@@ -1,9 +1,10 @@
1
1
  import { z, ZodSchema } from "zod";
2
- import { SQLiteTable } from "drizzle-orm/sqlite-core";
2
+ import { PgTable } from "drizzle-orm/pg-core";
3
3
  import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
4
+ import { NodePgDatabase } from "drizzle-orm/node-postgres";
4
5
  import { NextRequest } from "next/server";
5
- import { BaseTable, AnyDatabase } from "../types";
6
- export interface PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends SQLiteTable> {
6
+ import { BaseTable } from "../types";
7
+ export interface PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends PgTable> {
7
8
  bodySchema: IB;
8
9
  outputBodySchema?: OB;
9
10
  table: TTable;
@@ -17,5 +18,5 @@ export declare const createPutOperation: ({ getSession, db, }: {
17
18
  getSession: (req: NextRequest) => Promise<{
18
19
  userId?: string;
19
20
  } | undefined>;
20
- db: AnyDatabase;
21
+ db: NodePgDatabase<Record<string, unknown>>;
21
22
  }) => <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, outputBodySchema, table, summary, setBody, onSuccess, byCreator, onError, }: PutOperationOptions<IB, OB, TTable>) => import("next-rest-framework").RouteOperationDefinition<"PUT">;