@ai0x0/utils 0.0.37 → 0.0.38
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/README.md +42 -1
- package/es/backend/sqlite/actions/create-delete-action.d.ts +8 -0
- package/es/backend/sqlite/actions/create-delete-action.js +54 -0
- package/es/backend/sqlite/actions/create-get-action.d.ts +8 -0
- package/es/backend/sqlite/actions/create-get-action.js +64 -0
- package/es/backend/sqlite/actions/create-get-list-action.d.ts +11 -0
- package/es/backend/sqlite/actions/create-get-list-action.js +56 -0
- package/es/backend/sqlite/actions/create-post-action.d.ts +6 -0
- package/es/backend/sqlite/actions/create-post-action.js +31 -0
- package/es/backend/sqlite/actions/create-put-action.d.ts +8 -0
- package/es/backend/sqlite/actions/create-put-action.js +74 -0
- package/es/backend/sqlite/actions/get-list-data.d.ts +9 -0
- package/es/backend/sqlite/actions/get-list-data.js +75 -0
- package/es/backend/sqlite/actions/get-list-query.d.ts +19 -0
- package/es/backend/sqlite/actions/get-list-query.js +215 -0
- package/es/backend/sqlite/actions/index.d.ts +6 -0
- package/es/backend/sqlite/actions/index.js +6 -0
- package/es/backend/sqlite/actions/transform-body.d.ts +1 -0
- package/es/backend/sqlite/actions/transform-body.js +9 -0
- package/es/backend/sqlite/errors.d.ts +4 -0
- package/es/backend/sqlite/errors.js +31 -0
- package/es/backend/sqlite/index.d.ts +5 -0
- package/es/backend/sqlite/index.js +5 -0
- package/es/backend/sqlite/route-operation/delete-operation.d.ts +10 -0
- package/es/backend/sqlite/route-operation/delete-operation.js +112 -0
- package/es/backend/sqlite/route-operation/get-list-operation.d.ts +22 -0
- package/es/backend/sqlite/route-operation/get-list-operation.js +122 -0
- package/es/backend/sqlite/route-operation/get-operation.d.ts +16 -0
- package/es/backend/sqlite/route-operation/get-operation.js +122 -0
- package/es/backend/sqlite/route-operation/get-table-name.d.ts +3 -0
- package/es/backend/sqlite/route-operation/get-table-name.js +11 -0
- package/es/backend/sqlite/route-operation/index.d.ts +5 -0
- package/es/backend/sqlite/route-operation/index.js +5 -0
- package/es/backend/sqlite/route-operation/post-operation.d.ts +13 -0
- package/es/backend/sqlite/route-operation/post-operation.js +137 -0
- package/es/backend/sqlite/route-operation/put-operation.d.ts +14 -0
- package/es/backend/sqlite/route-operation/put-operation.js +144 -0
- package/es/backend/sqlite/schemas/index.d.ts +68 -0
- package/es/backend/sqlite/schemas/index.js +133 -0
- package/es/backend/sqlite/types.d.ts +16 -0
- package/es/backend/sqlite/types.js +1 -0
- package/lib/backend/sqlite/actions/create-delete-action.d.ts +8 -0
- package/lib/backend/sqlite/actions/create-delete-action.js +53 -0
- package/lib/backend/sqlite/actions/create-get-action.d.ts +8 -0
- package/lib/backend/sqlite/actions/create-get-action.js +65 -0
- package/lib/backend/sqlite/actions/create-get-list-action.d.ts +11 -0
- package/lib/backend/sqlite/actions/create-get-list-action.js +63 -0
- package/lib/backend/sqlite/actions/create-post-action.d.ts +6 -0
- package/lib/backend/sqlite/actions/create-post-action.js +39 -0
- package/lib/backend/sqlite/actions/create-put-action.d.ts +8 -0
- package/lib/backend/sqlite/actions/create-put-action.js +60 -0
- package/lib/backend/sqlite/actions/get-list-data.d.ts +9 -0
- package/lib/backend/sqlite/actions/get-list-data.js +51 -0
- package/lib/backend/sqlite/actions/get-list-query.d.ts +19 -0
- package/lib/backend/sqlite/actions/get-list-query.js +165 -0
- package/lib/backend/sqlite/actions/index.d.ts +6 -0
- package/lib/backend/sqlite/actions/index.js +44 -0
- package/lib/backend/sqlite/actions/transform-body.d.ts +1 -0
- package/lib/backend/sqlite/actions/transform-body.js +49 -0
- package/lib/backend/sqlite/errors.d.ts +4 -0
- package/lib/backend/sqlite/errors.js +35 -0
- package/lib/backend/sqlite/index.d.ts +5 -0
- package/lib/backend/sqlite/index.js +31 -0
- package/lib/backend/sqlite/route-operation/delete-operation.d.ts +10 -0
- package/lib/backend/sqlite/route-operation/delete-operation.js +91 -0
- package/lib/backend/sqlite/route-operation/get-list-operation.d.ts +22 -0
- package/lib/backend/sqlite/route-operation/get-list-operation.js +108 -0
- package/lib/backend/sqlite/route-operation/get-operation.d.ts +16 -0
- package/lib/backend/sqlite/route-operation/get-operation.js +107 -0
- package/lib/backend/sqlite/route-operation/get-table-name.d.ts +3 -0
- package/lib/backend/sqlite/route-operation/get-table-name.js +35 -0
- package/lib/backend/sqlite/route-operation/index.d.ts +5 -0
- package/lib/backend/sqlite/route-operation/index.js +31 -0
- package/lib/backend/sqlite/route-operation/post-operation.d.ts +13 -0
- package/lib/backend/sqlite/route-operation/post-operation.js +94 -0
- package/lib/backend/sqlite/route-operation/put-operation.d.ts +14 -0
- package/lib/backend/sqlite/route-operation/put-operation.js +103 -0
- package/lib/backend/sqlite/schemas/index.d.ts +68 -0
- package/lib/backend/sqlite/schemas/index.js +113 -0
- package/lib/backend/sqlite/types.d.ts +16 -0
- package/lib/backend/sqlite/types.js +17 -0
- package/package.json +3 -1
|
@@ -0,0 +1,133 @@
|
|
|
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
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
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); }
|
|
7
|
+
/* eslint-disable no-unused-vars */
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
10
|
+
import { createInsertSchema, createSelectSchema, createUpdateSchema } from "drizzle-zod";
|
|
11
|
+
|
|
12
|
+
//============================基本字段============================//
|
|
13
|
+
var timestamp = function timestamp(name) {
|
|
14
|
+
return integer(name, {
|
|
15
|
+
mode: "timestamp_ms"
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
var now = function now() {
|
|
19
|
+
return new Date();
|
|
20
|
+
};
|
|
21
|
+
var id = function id() {
|
|
22
|
+
return crypto.randomUUID();
|
|
23
|
+
};
|
|
24
|
+
var createdAt = function createdAt() {
|
|
25
|
+
return timestamp("created_at").notNull().$defaultFn(now);
|
|
26
|
+
};
|
|
27
|
+
var updatedAt = function updatedAt() {
|
|
28
|
+
return timestamp("updated_at").notNull().$defaultFn(now);
|
|
29
|
+
};
|
|
30
|
+
var accessedAt = function accessedAt() {
|
|
31
|
+
return timestamp("accessed_at").notNull().$defaultFn(now);
|
|
32
|
+
};
|
|
33
|
+
export var basicFields = {
|
|
34
|
+
id: text("id").primaryKey().$defaultFn(id),
|
|
35
|
+
creatorId: text("creator_id"),
|
|
36
|
+
editorId: text("editor_id"),
|
|
37
|
+
accessedAt: accessedAt(),
|
|
38
|
+
createdAt: createdAt(),
|
|
39
|
+
updatedAt: updatedAt()
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 业务侧 insert schema 需要从 drizzle-zod 生成的 schema 中排除的基础字段。
|
|
44
|
+
* 这些字段由后端在 createPostAction 中自动写入。
|
|
45
|
+
*
|
|
46
|
+
* 使用方式(在业务 schema 中):
|
|
47
|
+
* const insertFooSchema = createInsertSchema(foos)
|
|
48
|
+
* .omit(BASIC_INSERT_OMIT)
|
|
49
|
+
* .extend({ ... });
|
|
50
|
+
*
|
|
51
|
+
* 说明:上游导出为 const 而不是 helper function,是为了避免经过泛型
|
|
52
|
+
* wrapper 后 TS 把 drizzle-zod 推导出的深层条件 Shape 归约成 Omit,
|
|
53
|
+
* 从而在下游 `.extend(...)` 时丢失原有字段类型。
|
|
54
|
+
*/
|
|
55
|
+
export var BASIC_INSERT_OMIT = {
|
|
56
|
+
id: true,
|
|
57
|
+
creatorId: true,
|
|
58
|
+
editorId: true,
|
|
59
|
+
accessedAt: true,
|
|
60
|
+
createdAt: true,
|
|
61
|
+
updatedAt: true
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 业务侧 update schema 需要从 drizzle-zod 生成的 schema 中排除的基础字段。
|
|
66
|
+
* update 保留 id(随后用 `.required({ id: true })` 变成必填),其余由
|
|
67
|
+
* 后端 createPutAction 自动维护。
|
|
68
|
+
*/
|
|
69
|
+
export var BASIC_UPDATE_OMIT = {
|
|
70
|
+
creatorId: true,
|
|
71
|
+
editorId: true,
|
|
72
|
+
accessedAt: true,
|
|
73
|
+
createdAt: true,
|
|
74
|
+
updatedAt: true
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
//============================列表查询字段============================//
|
|
78
|
+
export var queryListSchema = function queryListSchema(schema) {
|
|
79
|
+
return z.object({
|
|
80
|
+
current: z.string().optional().default("1"),
|
|
81
|
+
// 默认页码为 1
|
|
82
|
+
pageSize: z.string().optional().default("10"),
|
|
83
|
+
// 默认每页条数为 10
|
|
84
|
+
createdAtFrom: z.string().optional(),
|
|
85
|
+
// 筛选开始日期
|
|
86
|
+
createdAtTo: z.string().optional(),
|
|
87
|
+
// 筛选结束日期
|
|
88
|
+
orderBy: z.string().optional(),
|
|
89
|
+
creatorId: z.string().optional(),
|
|
90
|
+
orderDir: z.enum(["asc", "desc"]).optional()
|
|
91
|
+
}).merge(schema);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
//============================列表返回字段============================//
|
|
95
|
+
export var listBodySchema = function listBodySchema(schema) {
|
|
96
|
+
return z.object({
|
|
97
|
+
total: z.number(),
|
|
98
|
+
data: z.array(schema)
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
//============================创建一个sqlite表============================//
|
|
103
|
+
/**
|
|
104
|
+
* 基于 drizzle + drizzle-zod 快速生成带基础字段(id / 创建时间等)的
|
|
105
|
+
* 表定义以及 select / insert / update / query / list zod schema。
|
|
106
|
+
*/
|
|
107
|
+
export var createTableSchema = function createTableSchema(_ref) {
|
|
108
|
+
var name = _ref.name,
|
|
109
|
+
columns = _ref.columns,
|
|
110
|
+
extraConfig = _ref.extraConfig;
|
|
111
|
+
var mergedColumns = _objectSpread(_objectSpread({}, basicFields), columns);
|
|
112
|
+
var table = sqliteTable(name, mergedColumns, extraConfig);
|
|
113
|
+
var selectSchema = createSelectSchema(table);
|
|
114
|
+
var insertSchema = createInsertSchema(sqliteTable(name, columns));
|
|
115
|
+
var updateSchema = createUpdateSchema(sqliteTable(name, _objectSpread({
|
|
116
|
+
id: text("id")
|
|
117
|
+
}, columns))).extend({
|
|
118
|
+
id: z.string()
|
|
119
|
+
});
|
|
120
|
+
var querySchema = z.object({
|
|
121
|
+
id: z.string()
|
|
122
|
+
});
|
|
123
|
+
var queryListWithSchema = queryListSchema(z.object({}).catchall(z.unknown()));
|
|
124
|
+
return {
|
|
125
|
+
table: table,
|
|
126
|
+
selectSchema: selectSchema,
|
|
127
|
+
insertSchema: insertSchema,
|
|
128
|
+
updateSchema: updateSchema,
|
|
129
|
+
querySchema: querySchema,
|
|
130
|
+
queryListSchema: queryListWithSchema,
|
|
131
|
+
queryListSelectSchema: selectSchema
|
|
132
|
+
};
|
|
133
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AnySQLiteColumn, SQLiteTable } from "drizzle-orm/sqlite-core";
|
|
2
|
+
import { SQL } from "drizzle-orm";
|
|
3
|
+
export interface BaseTable extends SQLiteTable {
|
|
4
|
+
id: AnySQLiteColumn;
|
|
5
|
+
creatorId: AnySQLiteColumn;
|
|
6
|
+
editorId: AnySQLiteColumn;
|
|
7
|
+
accessedAt: AnySQLiteColumn;
|
|
8
|
+
createdAt: AnySQLiteColumn;
|
|
9
|
+
updatedAt: AnySQLiteColumn;
|
|
10
|
+
}
|
|
11
|
+
export type GetListRelations = {
|
|
12
|
+
groupBy?: boolean;
|
|
13
|
+
select?: Record<string, unknown>;
|
|
14
|
+
sql?: SQL;
|
|
15
|
+
table?: BaseTable;
|
|
16
|
+
}[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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,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
|
+
};
|