@ai0x0/utils 0.0.16 → 0.0.17
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.
- package/es/backend/actions/create-delete-action.d.ts +3 -4
- package/es/backend/actions/create-get-action.d.ts +2 -3
- package/es/backend/actions/create-get-list-action.d.ts +2 -3
- package/es/backend/actions/create-post-action.d.ts +4 -4
- package/es/backend/actions/create-put-action.d.ts +2 -3
- package/es/backend/actions/get-list-query.d.ts +4 -12
- package/es/backend/actions/get-list-query.js +11 -8
- package/es/backend/route-operation/delete-operation.d.ts +2 -3
- package/es/backend/route-operation/get-list-operation.d.ts +2 -3
- package/es/backend/route-operation/get-operation.d.ts +2 -3
- package/es/backend/route-operation/get-table-name.d.ts +2 -2
- package/es/backend/route-operation/post-operation.d.ts +5 -5
- package/es/backend/route-operation/put-operation.d.ts +4 -5
- package/es/backend/schemas/index.d.ts +598 -597
- package/es/backend/schemas/index.js +19 -31
- package/es/backend/types.d.ts +14 -8
- package/lib/backend/actions/create-delete-action.d.ts +3 -4
- package/lib/backend/actions/create-get-action.d.ts +2 -3
- package/lib/backend/actions/create-get-list-action.d.ts +2 -3
- package/lib/backend/actions/create-post-action.d.ts +4 -4
- package/lib/backend/actions/create-post-action.js +1 -4
- package/lib/backend/actions/create-put-action.d.ts +2 -3
- package/lib/backend/actions/get-list-query.d.ts +4 -12
- package/lib/backend/actions/get-list-query.js +7 -6
- package/lib/backend/route-operation/delete-operation.d.ts +2 -3
- package/lib/backend/route-operation/get-list-operation.d.ts +2 -3
- package/lib/backend/route-operation/get-operation.d.ts +2 -3
- package/lib/backend/route-operation/get-table-name.d.ts +2 -2
- package/lib/backend/route-operation/post-operation.d.ts +5 -5
- package/lib/backend/route-operation/put-operation.d.ts +4 -5
- package/lib/backend/schemas/index.d.ts +598 -597
- package/lib/backend/schemas/index.js +21 -21
- package/lib/backend/types.d.ts +14 -8
- package/package.json +1 -1
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BaseTable } from "../types";
|
|
1
|
+
import { BaseTable, AnyDatabase } from "../types";
|
|
3
2
|
export declare function createDeleteAction<TTable extends BaseTable>({ table, db, }: {
|
|
4
|
-
db:
|
|
3
|
+
db: AnyDatabase;
|
|
5
4
|
table: TTable;
|
|
6
5
|
}): ({ id, creatorId }: {
|
|
7
6
|
id: string;
|
|
8
7
|
creatorId?: string | undefined;
|
|
9
|
-
}) => Promise<
|
|
8
|
+
}) => Promise<any>;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { z, ZodSchema } from "zod";
|
|
2
|
-
import {
|
|
3
|
-
import { BaseTable, GetListRelations } from "../types";
|
|
2
|
+
import { BaseTable, GetListRelations, AnyDatabase } from "../types";
|
|
4
3
|
export declare function createGetAction<T extends ZodSchema, TTable extends BaseTable>({ bodySchema, db, jsonArrayFields, relations, table, }: {
|
|
5
4
|
bodySchema: T;
|
|
6
|
-
db:
|
|
5
|
+
db: AnyDatabase;
|
|
7
6
|
jsonArrayFields?: string[];
|
|
8
7
|
relations?: GetListRelations;
|
|
9
8
|
table: TTable;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { z, ZodSchema } from "zod";
|
|
2
|
-
import { BaseTable, GetListRelations } from "../types";
|
|
3
|
-
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
2
|
+
import { BaseTable, GetListRelations, AnyDatabase } from "../types";
|
|
4
3
|
export declare function createGetListAction<T extends ZodSchema, TTable extends BaseTable>({ bodySchema, db, jsonArrayFields, relations, table, }: {
|
|
5
4
|
bodySchema: T;
|
|
6
|
-
db:
|
|
5
|
+
db: AnyDatabase;
|
|
7
6
|
jsonArrayFields?: string[];
|
|
8
7
|
relations?: GetListRelations;
|
|
9
8
|
table: TTable;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { z, ZodSchema } from "zod";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export declare function createPostAction<T extends ZodSchema, TTable extends
|
|
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 }: {
|
|
5
5
|
bodySchema: T;
|
|
6
|
-
db:
|
|
6
|
+
db: AnyDatabase;
|
|
7
7
|
table: TTable;
|
|
8
8
|
}): (body: z.infer<T>) => Promise<z.infer<T>[]>;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { z, ZodSchema } from "zod";
|
|
2
|
-
import {
|
|
3
|
-
import { BaseTable } from "../types";
|
|
2
|
+
import { BaseTable, AnyDatabase } from "../types";
|
|
4
3
|
export declare function createPutAction<T extends ZodSchema, TTable extends BaseTable>({ db, table, }: {
|
|
5
4
|
bodySchema: T;
|
|
6
|
-
db:
|
|
5
|
+
db: AnyDatabase;
|
|
7
6
|
table: TTable;
|
|
8
7
|
}): (body: Partial<z.infer<T>> & Record<string, unknown>, { byCreator, }?: {
|
|
9
8
|
byCreator?: boolean | undefined;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { BaseTable, GetListRelations } from "../types";
|
|
2
|
-
import { SelectedFields } from "drizzle-orm/
|
|
3
|
-
import { SQL } from "drizzle-orm";
|
|
4
|
-
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
1
|
+
import { BaseTable, GetListRelations, AnyDatabase } from "../types";
|
|
2
|
+
import { SelectedFields } from "drizzle-orm/sqlite-core/query-builders/select.types";
|
|
5
3
|
export declare function getListQuery<TTable extends BaseTable, TSelection extends SelectedFields>({ db, fields, jsonArrayFields, params, relations, table, }: {
|
|
6
|
-
db:
|
|
4
|
+
db: AnyDatabase;
|
|
7
5
|
fields: TSelection;
|
|
8
6
|
jsonArrayFields?: string[];
|
|
9
7
|
params: {
|
|
@@ -16,12 +14,6 @@ export declare function getListQuery<TTable extends BaseTable, TSelection extend
|
|
|
16
14
|
relations?: GetListRelations;
|
|
17
15
|
table: TTable;
|
|
18
16
|
}): {
|
|
19
|
-
countQuery:
|
|
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">;
|
|
17
|
+
countQuery: any;
|
|
26
18
|
query: any;
|
|
27
19
|
};
|
|
@@ -1,11 +1,10 @@
|
|
|
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;
|
|
3
2
|
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) } })); }
|
|
9
8
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
10
9
|
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."); }
|
|
11
10
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
@@ -20,7 +19,11 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
20
19
|
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); }
|
|
21
20
|
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; }
|
|
22
21
|
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; }
|
|
23
|
-
|
|
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
|
+
};
|
|
24
27
|
export function getListQuery(_ref) {
|
|
25
28
|
var db = _ref.db,
|
|
26
29
|
fields = _ref.fields,
|
|
@@ -102,12 +105,12 @@ export function getListQuery(_ref) {
|
|
|
102
105
|
if (values.length > 0) {
|
|
103
106
|
if (isJsonArray) {
|
|
104
107
|
// 处理JSONB数组字段
|
|
105
|
-
conditions.push(sql(
|
|
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], "%")));
|
|
106
109
|
} else if (isIdField) {
|
|
107
110
|
conditions.push(inArray(targetColumn, values));
|
|
108
111
|
} else {
|
|
109
112
|
conditions.push(or.apply(void 0, _toConsumableArray(values.map(function (v) {
|
|
110
|
-
return
|
|
113
|
+
return ciLike(targetColumn, "%".concat(v, "%"));
|
|
111
114
|
}))));
|
|
112
115
|
}
|
|
113
116
|
}
|
|
@@ -115,11 +118,11 @@ export function getListQuery(_ref) {
|
|
|
115
118
|
// 处理单值
|
|
116
119
|
if (isJsonArray) {
|
|
117
120
|
// 处理JSONB数组字段
|
|
118
|
-
conditions.push(sql(
|
|
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, "%")));
|
|
119
122
|
} else if (isIdField) {
|
|
120
123
|
conditions.push(eq(targetColumn, value));
|
|
121
124
|
} else {
|
|
122
|
-
conditions.push(
|
|
125
|
+
conditions.push(ciLike(targetColumn, "%".concat(value, "%")));
|
|
123
126
|
}
|
|
124
127
|
}
|
|
125
128
|
} else {
|
|
@@ -179,7 +182,7 @@ export function getListQuery(_ref) {
|
|
|
179
182
|
|
|
180
183
|
// 构建计数查询(优化后)
|
|
181
184
|
var countQuery = db.select({
|
|
182
|
-
count: sql(
|
|
185
|
+
count: sql(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["COUNT(DISTINCT ", ")"])), table.id)
|
|
183
186
|
}).from(table).where(conditions.length > 0 ? and.apply(void 0, _toConsumableArray(conditions)) : undefined);
|
|
184
187
|
|
|
185
188
|
// 添加关联
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { TypedNextResponse } from "next-rest-framework";
|
|
2
|
-
import { BaseTable } from "../types";
|
|
3
|
-
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
2
|
+
import { BaseTable, AnyDatabase } from "../types";
|
|
4
3
|
import { NextRequest } from "next/server";
|
|
5
4
|
export interface DeleteOperationOptions<TTable extends BaseTable> {
|
|
6
5
|
table: TTable;
|
|
@@ -10,7 +9,7 @@ export interface DeleteOperationOptions<TTable extends BaseTable> {
|
|
|
10
9
|
byCreator?: boolean;
|
|
11
10
|
}
|
|
12
11
|
export declare const createDeleteOperation: ({ db, getSession, }: {
|
|
13
|
-
db:
|
|
12
|
+
db: AnyDatabase;
|
|
14
13
|
getSession: (req: NextRequest) => Promise<{
|
|
15
14
|
userId?: string;
|
|
16
15
|
} | undefined>;
|
|
@@ -1,8 +1,7 @@
|
|
|
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 {
|
|
5
|
-
import { BaseTable, GetListRelations } from "../types";
|
|
4
|
+
import { BaseTable, GetListRelations, AnyDatabase } from "../types";
|
|
6
5
|
export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> {
|
|
7
6
|
bodySchema: T;
|
|
8
7
|
jsonArrayFields?: string[];
|
|
@@ -22,7 +21,7 @@ export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchem
|
|
|
22
21
|
onError?: (error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
23
22
|
}
|
|
24
23
|
export declare const createGetListOperation: ({ db, getSession, }: {
|
|
25
|
-
db:
|
|
24
|
+
db: AnyDatabase;
|
|
26
25
|
getSession: (req: NextRequest) => Promise<{
|
|
27
26
|
userId?: string;
|
|
28
27
|
} | undefined>;
|
|
@@ -1,8 +1,7 @@
|
|
|
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 {
|
|
5
|
-
import { BaseTable, GetListRelations } from "../types";
|
|
4
|
+
import { BaseTable, GetListRelations, AnyDatabase } from "../types";
|
|
6
5
|
export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> {
|
|
7
6
|
bodySchema: T;
|
|
8
7
|
jsonArrayFields?: string[];
|
|
@@ -16,7 +15,7 @@ export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, T
|
|
|
16
15
|
byCreator?: boolean;
|
|
17
16
|
}
|
|
18
17
|
export declare const createGetOperation: ({ getSession, db, }: {
|
|
19
|
-
db:
|
|
18
|
+
db: AnyDatabase;
|
|
20
19
|
getSession: (req: NextRequest) => Promise<{
|
|
21
20
|
userId?: string;
|
|
22
21
|
} | undefined>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare function getTableName(table:
|
|
1
|
+
import { SQLiteTable } from "drizzle-orm/sqlite-core";
|
|
2
|
+
declare function getTableName(table: SQLiteTable): string;
|
|
3
3
|
export default getTableName;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { z, ZodSchema } from "zod";
|
|
2
|
-
import {
|
|
2
|
+
import { AnyDatabase } from "../types";
|
|
3
|
+
import { SQLiteTable } from "drizzle-orm/sqlite-core";
|
|
3
4
|
import { NextRequest } from "next/server";
|
|
4
5
|
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
5
|
-
|
|
6
|
-
export interface PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends PgTable> {
|
|
6
|
+
export interface PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends SQLiteTable> {
|
|
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:
|
|
16
|
+
db: AnyDatabase;
|
|
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
|
|
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">;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { z, ZodSchema } from "zod";
|
|
2
|
-
import {
|
|
2
|
+
import { SQLiteTable } from "drizzle-orm/sqlite-core";
|
|
3
3
|
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
4
|
-
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
5
4
|
import { NextRequest } from "next/server";
|
|
6
|
-
import { BaseTable } from "../types";
|
|
7
|
-
export interface PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends
|
|
5
|
+
import { BaseTable, AnyDatabase } from "../types";
|
|
6
|
+
export interface PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends SQLiteTable> {
|
|
8
7
|
bodySchema: IB;
|
|
9
8
|
outputBodySchema?: OB;
|
|
10
9
|
table: TTable;
|
|
@@ -18,5 +17,5 @@ export declare const createPutOperation: ({ getSession, db, }: {
|
|
|
18
17
|
getSession: (req: NextRequest) => Promise<{
|
|
19
18
|
userId?: string;
|
|
20
19
|
} | undefined>;
|
|
21
|
-
db:
|
|
20
|
+
db: AnyDatabase;
|
|
22
21
|
}) => <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">;
|