@wzyjs/utils 0.0.26 → 0.0.28
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/dist/browser/cjs/browser/element.js +40 -0
- package/dist/browser/cjs/browser/index.js +20 -0
- package/dist/browser/cjs/browser/other.js +12 -0
- package/dist/browser/cjs/browser/style.js +49 -0
- package/dist/browser/cjs/browser.js +171 -0
- package/dist/browser/cjs/common/classs.js +14 -0
- package/dist/browser/cjs/common/dayjs.js +27 -0
- package/dist/browser/cjs/types/index.d.ts +27 -0
- package/dist/{esm/fe → browser/cjs/utils/src/browser}/index.d.ts +1 -1
- package/dist/browser/cjs/utils/src/browser/other.d.ts +1 -0
- package/dist/browser/cjs/utils/src/browser.d.ts +2 -0
- package/dist/browser/cjs/utils/src/common/classs.d.ts +5 -0
- package/dist/browser/cjs/utils/src/common/dayjs.d.ts +4 -0
- package/dist/browser/cjs/utils/src/common/index.d.ts +11 -0
- package/dist/{cjs/common/tools → browser/cjs/utils/src/common}/other.d.ts +1 -1
- package/dist/{cjs/rd → browser/cjs/utils/src/node}/jsonFile/index.d.ts +1 -1
- package/dist/browser/cjs/utils/src/node.d.ts +2 -0
- package/dist/{esm/fe → browser/esm/browser}/index.js +0 -1
- package/dist/browser/esm/browser/other.js +10 -0
- package/dist/browser/esm/browser.js +19 -0
- package/dist/browser/esm/common/classs.js +12 -0
- package/dist/browser/esm/common/dayjs.js +18 -0
- package/dist/browser/esm/types/index.d.ts +27 -0
- package/dist/{cjs/fe → browser/esm/utils/src/browser}/index.d.ts +1 -1
- package/dist/browser/esm/utils/src/browser/other.d.ts +1 -0
- package/dist/browser/esm/utils/src/browser.d.ts +2 -0
- package/dist/browser/esm/utils/src/common/classs.d.ts +5 -0
- package/dist/browser/esm/utils/src/common/dayjs.d.ts +4 -0
- package/dist/browser/esm/utils/src/common/index.d.ts +11 -0
- package/dist/{esm/common/tools → browser/esm/utils/src/common}/other.d.ts +1 -1
- package/dist/{esm/rd → browser/esm/utils/src/node}/jsonFile/index.d.ts +1 -1
- package/dist/browser/esm/utils/src/node.d.ts +2 -0
- package/dist/node/cjs/common/classs.js +14 -0
- package/dist/node/cjs/common/dayjs.js +27 -0
- package/dist/node/cjs/common/number.js +34 -0
- package/dist/node/cjs/common/object.js +43 -0
- package/dist/node/cjs/common/other.js +112 -0
- package/dist/node/cjs/common/string.js +137 -0
- package/dist/{cjs/index_rd.js → node/cjs/node.js} +28 -8
- package/dist/node/cjs/types/index.d.ts +27 -0
- package/dist/node/cjs/utils/src/browser/element.d.ts +9 -0
- package/dist/node/cjs/utils/src/browser/index.d.ts +18 -0
- package/dist/node/cjs/utils/src/browser/other.d.ts +1 -0
- package/dist/node/cjs/utils/src/browser/style.d.ts +10 -0
- package/dist/node/cjs/utils/src/browser.d.ts +2 -0
- package/dist/node/cjs/utils/src/common/classs.d.ts +5 -0
- package/dist/node/cjs/utils/src/common/dayjs.d.ts +4 -0
- package/dist/node/cjs/utils/src/common/index.d.ts +11 -0
- package/dist/node/cjs/utils/src/common/number.d.ts +3 -0
- package/dist/node/cjs/utils/src/common/object.d.ts +10 -0
- package/dist/node/cjs/utils/src/common/other.d.ts +26 -0
- package/dist/node/cjs/utils/src/common/string.d.ts +16 -0
- package/dist/node/cjs/utils/src/node/database/Collection.d.ts +22 -0
- package/dist/node/cjs/utils/src/node/database/Database.d.ts +10 -0
- package/dist/node/cjs/utils/src/node/database/index.d.ts +2 -0
- package/dist/node/cjs/utils/src/node/database/types.d.ts +151 -0
- package/dist/node/cjs/utils/src/node/database/utils.d.ts +3 -0
- package/dist/node/cjs/utils/src/node/index.d.ts +3 -0
- package/dist/node/cjs/utils/src/node/jsonFile/index.d.ts +6 -0
- package/dist/node/cjs/utils/src/node/mail/index.d.ts +1 -0
- package/dist/node/cjs/utils/src/node.d.ts +2 -0
- package/dist/node/esm/common/classs.js +12 -0
- package/dist/node/esm/common/dayjs.js +18 -0
- package/dist/node/esm/common/number.js +30 -0
- package/dist/node/esm/common/object.js +39 -0
- package/dist/node/esm/common/other.js +106 -0
- package/dist/node/esm/common/string.js +120 -0
- package/dist/node/esm/node/database/Collection.js +200 -0
- package/dist/node/esm/node/database/Database.js +23 -0
- package/dist/node/esm/node/database/types.js +25 -0
- package/dist/node/esm/node/database/utils.js +27 -0
- package/dist/node/esm/node/jsonFile/index.js +27 -0
- package/dist/node/esm/node/mail/index.js +29 -0
- package/dist/node/esm/node.js +14 -0
- package/dist/node/esm/types/index.d.ts +27 -0
- package/dist/node/esm/utils/src/browser/element.d.ts +9 -0
- package/dist/node/esm/utils/src/browser/index.d.ts +18 -0
- package/dist/node/esm/utils/src/browser/other.d.ts +1 -0
- package/dist/node/esm/utils/src/browser/style.d.ts +10 -0
- package/dist/node/esm/utils/src/browser.d.ts +2 -0
- package/dist/node/esm/utils/src/common/classs.d.ts +5 -0
- package/dist/node/esm/utils/src/common/dayjs.d.ts +4 -0
- package/dist/node/esm/utils/src/common/index.d.ts +11 -0
- package/dist/node/esm/utils/src/common/number.d.ts +3 -0
- package/dist/node/esm/utils/src/common/object.d.ts +10 -0
- package/dist/node/esm/utils/src/common/other.d.ts +26 -0
- package/dist/node/esm/utils/src/common/string.d.ts +16 -0
- package/dist/node/esm/utils/src/node/database/Collection.d.ts +22 -0
- package/dist/node/esm/utils/src/node/database/Database.d.ts +10 -0
- package/dist/node/esm/utils/src/node/database/index.d.ts +2 -0
- package/dist/node/esm/utils/src/node/database/types.d.ts +151 -0
- package/dist/node/esm/utils/src/node/database/utils.d.ts +3 -0
- package/dist/node/esm/utils/src/node/index.d.ts +3 -0
- package/dist/node/esm/utils/src/node/jsonFile/index.d.ts +6 -0
- package/dist/node/esm/utils/src/node/mail/index.d.ts +1 -0
- package/dist/node/esm/utils/src/node.d.ts +2 -0
- package/package.json +23 -11
- package/dist/cjs/common/index.d.ts +0 -6
- package/dist/cjs/common/tools/index.d.ts +0 -4
- package/dist/cjs/common/types/index.d.ts +0 -15
- package/dist/cjs/fe/dayjs.d.ts +0 -2
- package/dist/cjs/index_all.d.ts +0 -3
- package/dist/cjs/index_fe.d.ts +0 -2
- package/dist/cjs/index_rd.d.ts +0 -2
- package/dist/esm/common/index.d.ts +0 -6
- package/dist/esm/common/tools/index.d.ts +0 -4
- package/dist/esm/common/types/index.d.ts +0 -15
- package/dist/esm/fe/dayjs.d.ts +0 -2
- package/dist/esm/fe/dayjs.js +0 -9
- package/dist/esm/index_all.d.ts +0 -3
- package/dist/esm/index_fe.d.ts +0 -2
- package/dist/esm/index_fe.js +0 -16
- package/dist/esm/index_rd.d.ts +0 -2
- /package/dist/{cjs/common/tools → browser/cjs/common}/number.js +0 -0
- /package/dist/{cjs/common/tools → browser/cjs/common}/object.js +0 -0
- /package/dist/{cjs/common/tools → browser/cjs/common}/other.js +0 -0
- /package/dist/{cjs/common/tools → browser/cjs/common}/string.js +0 -0
- /package/dist/{cjs/fe → browser/cjs/utils/src/browser}/element.d.ts +0 -0
- /package/dist/{cjs/fe → browser/cjs/utils/src/browser}/style.d.ts +0 -0
- /package/dist/{cjs/common/tools → browser/cjs/utils/src/common}/number.d.ts +0 -0
- /package/dist/{cjs/common/tools → browser/cjs/utils/src/common}/object.d.ts +0 -0
- /package/dist/{cjs/common/tools → browser/cjs/utils/src/common}/string.d.ts +0 -0
- /package/dist/{cjs/rd → browser/cjs/utils/src/node}/database/Collection.d.ts +0 -0
- /package/dist/{cjs/rd → browser/cjs/utils/src/node}/database/Database.d.ts +0 -0
- /package/dist/{cjs/rd → browser/cjs/utils/src/node}/database/index.d.ts +0 -0
- /package/dist/{cjs/rd → browser/cjs/utils/src/node}/database/types.d.ts +0 -0
- /package/dist/{cjs/rd → browser/cjs/utils/src/node}/database/utils.d.ts +0 -0
- /package/dist/{cjs/rd → browser/cjs/utils/src/node}/index.d.ts +0 -0
- /package/dist/{cjs/rd → browser/cjs/utils/src/node}/mail/index.d.ts +0 -0
- /package/dist/{esm/fe → browser/esm/browser}/element.js +0 -0
- /package/dist/{esm/fe → browser/esm/browser}/style.js +0 -0
- /package/dist/{esm/common/tools → browser/esm/common}/number.js +0 -0
- /package/dist/{esm/common/tools → browser/esm/common}/object.js +0 -0
- /package/dist/{esm/common/tools → browser/esm/common}/other.js +0 -0
- /package/dist/{esm/common/tools → browser/esm/common}/string.js +0 -0
- /package/dist/{esm/fe → browser/esm/utils/src/browser}/element.d.ts +0 -0
- /package/dist/{esm/fe → browser/esm/utils/src/browser}/style.d.ts +0 -0
- /package/dist/{esm/common/tools → browser/esm/utils/src/common}/number.d.ts +0 -0
- /package/dist/{esm/common/tools → browser/esm/utils/src/common}/object.d.ts +0 -0
- /package/dist/{esm/common/tools → browser/esm/utils/src/common}/string.d.ts +0 -0
- /package/dist/{esm/rd → browser/esm/utils/src/node}/database/Collection.d.ts +0 -0
- /package/dist/{esm/rd → browser/esm/utils/src/node}/database/Database.d.ts +0 -0
- /package/dist/{esm/rd → browser/esm/utils/src/node}/database/index.d.ts +0 -0
- /package/dist/{esm/rd → browser/esm/utils/src/node}/database/types.d.ts +0 -0
- /package/dist/{esm/rd → browser/esm/utils/src/node}/database/utils.d.ts +0 -0
- /package/dist/{esm/rd → browser/esm/utils/src/node}/index.d.ts +0 -0
- /package/dist/{esm/rd → browser/esm/utils/src/node}/mail/index.d.ts +0 -0
- /package/dist/{cjs/rd → node/cjs/node}/database/Collection.js +0 -0
- /package/dist/{cjs/rd → node/cjs/node}/database/Database.js +0 -0
- /package/dist/{cjs/rd → node/cjs/node}/database/types.js +0 -0
- /package/dist/{cjs/rd → node/cjs/node}/database/utils.js +0 -0
- /package/dist/{cjs/rd → node/cjs/node}/jsonFile/index.js +0 -0
- /package/dist/{cjs/rd → node/cjs/node}/mail/index.js +0 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { merge, cloneDeep, isObject } from 'lodash';
|
|
2
|
+
import { appendTime, defaultConditions } from './utils.js';
|
|
3
|
+
import { Method, Command } from './types.js';
|
|
4
|
+
|
|
5
|
+
class Collection {
|
|
6
|
+
db;
|
|
7
|
+
collection;
|
|
8
|
+
constructor(db, name) {
|
|
9
|
+
this.db = db;
|
|
10
|
+
this.collection = db.collection(name);
|
|
11
|
+
}
|
|
12
|
+
joinConditions(conditions) {
|
|
13
|
+
let record = this.collection;
|
|
14
|
+
if (!conditions) {
|
|
15
|
+
return record;
|
|
16
|
+
}
|
|
17
|
+
// 如果是根据 _id 查询
|
|
18
|
+
if ('_id' in conditions) {
|
|
19
|
+
record = record.doc(conditions._id);
|
|
20
|
+
// 如果是根据 条件 查询
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
const { page, order, where, options } = conditions;
|
|
24
|
+
if (options) {
|
|
25
|
+
record = record.options(options);
|
|
26
|
+
}
|
|
27
|
+
if (where) {
|
|
28
|
+
record = record.where(where);
|
|
29
|
+
}
|
|
30
|
+
if (order) {
|
|
31
|
+
record = record.orderBy(order.field, order.type || 'desc');
|
|
32
|
+
}
|
|
33
|
+
if (page?.current && page?.size) {
|
|
34
|
+
record = record.skip((page.current - 1) * page.size);
|
|
35
|
+
}
|
|
36
|
+
if (page?.size) {
|
|
37
|
+
record = record.limit(page.size);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (Array.isArray(conditions.field)) {
|
|
41
|
+
record = record.field(conditions.field.reduce((o, i) => ({ ...o, [i]: true }), {}));
|
|
42
|
+
}
|
|
43
|
+
else if (conditions.field) {
|
|
44
|
+
record = record.field(conditions.field);
|
|
45
|
+
}
|
|
46
|
+
return record;
|
|
47
|
+
}
|
|
48
|
+
request(params) {
|
|
49
|
+
switch (params.method) {
|
|
50
|
+
case Method.Add:
|
|
51
|
+
return this.joinConditions().add(params.data);
|
|
52
|
+
case Method.Find:
|
|
53
|
+
case Method.FindList:
|
|
54
|
+
return this.joinConditions(params.conditions).get();
|
|
55
|
+
case Method.Delete:
|
|
56
|
+
return this.joinConditions(params.conditions).remove();
|
|
57
|
+
case Method.Update:
|
|
58
|
+
if (params.isSet && '_id' in params.conditions) {
|
|
59
|
+
return this.joinConditions(params.conditions).set(params.data);
|
|
60
|
+
}
|
|
61
|
+
return this.joinConditions(params.conditions).update(params.data);
|
|
62
|
+
case Method.Count:
|
|
63
|
+
return this.joinConditions(params.conditions).count();
|
|
64
|
+
default:
|
|
65
|
+
throw new Error('method is not exist');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// 处理出参
|
|
69
|
+
async handleRes(params, res) {
|
|
70
|
+
if (res) {
|
|
71
|
+
delete res.requestId;
|
|
72
|
+
}
|
|
73
|
+
let data = res;
|
|
74
|
+
switch (params.method) {
|
|
75
|
+
case Method.Add:
|
|
76
|
+
const addRes = res;
|
|
77
|
+
if (addRes.id && params.isReturn) {
|
|
78
|
+
data = await this.find({ _id: addRes.id, field: params.conditions?.field });
|
|
79
|
+
}
|
|
80
|
+
break;
|
|
81
|
+
case Method.Update:
|
|
82
|
+
const updateRes = res;
|
|
83
|
+
if (updateRes.updated && params.isReturn && '_id' in params.conditions) {
|
|
84
|
+
data = await this.find({ _id: params.conditions._id, field: params.conditions?.field });
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
case Method.Find:
|
|
88
|
+
const getRes = res;
|
|
89
|
+
data = getRes?.data[0] || null;
|
|
90
|
+
break;
|
|
91
|
+
case Method.FindList:
|
|
92
|
+
const getListRes = res;
|
|
93
|
+
const countRes = await this.request({
|
|
94
|
+
method: Method.Count,
|
|
95
|
+
conditions: params.conditions,
|
|
96
|
+
});
|
|
97
|
+
data = {
|
|
98
|
+
list: getListRes.data,
|
|
99
|
+
total: countRes.total,
|
|
100
|
+
};
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
return data;
|
|
104
|
+
}
|
|
105
|
+
// 处理数据
|
|
106
|
+
async handleData(params) {
|
|
107
|
+
switch (params.method) {
|
|
108
|
+
case Method.Add:
|
|
109
|
+
params.data = appendTime(params.data, 'create');
|
|
110
|
+
params.data = appendTime(params.data, 'update');
|
|
111
|
+
break;
|
|
112
|
+
case Method.Update:
|
|
113
|
+
if ('_id' in params.data) {
|
|
114
|
+
delete params.data._id;
|
|
115
|
+
}
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
return params;
|
|
119
|
+
}
|
|
120
|
+
// 处理条件
|
|
121
|
+
handleConditions(params) {
|
|
122
|
+
if (params.method !== Method.Add) {
|
|
123
|
+
params.conditions = merge(cloneDeep(defaultConditions), params.conditions);
|
|
124
|
+
}
|
|
125
|
+
// 处理 where 条件
|
|
126
|
+
if (params.conditions && 'where' in params.conditions) {
|
|
127
|
+
const { command: _ } = this.db;
|
|
128
|
+
for (const key in params.conditions.where) {
|
|
129
|
+
const whereValue = params.conditions.where[key];
|
|
130
|
+
if (isObject(whereValue)) {
|
|
131
|
+
const { type, value } = whereValue;
|
|
132
|
+
switch (type) {
|
|
133
|
+
case Command.In:
|
|
134
|
+
params.conditions.where[key] = _.in(value);
|
|
135
|
+
break;
|
|
136
|
+
case Command.Nin:
|
|
137
|
+
params.conditions.where[key] = _.nin(value);
|
|
138
|
+
break;
|
|
139
|
+
case Command.Gt:
|
|
140
|
+
params.conditions.where[key] = _.gt(value);
|
|
141
|
+
break;
|
|
142
|
+
case Command.Gte:
|
|
143
|
+
params.conditions.where[key] = _.gte(value);
|
|
144
|
+
break;
|
|
145
|
+
case Command.Lt:
|
|
146
|
+
params.conditions.where[key] = _.lt(value);
|
|
147
|
+
break;
|
|
148
|
+
case Command.Lte:
|
|
149
|
+
params.conditions.where[key] = _.lte(value);
|
|
150
|
+
break;
|
|
151
|
+
case Command.Eq:
|
|
152
|
+
params.conditions.where[key] = _.eq(value);
|
|
153
|
+
break;
|
|
154
|
+
case Command.Neq:
|
|
155
|
+
params.conditions.where[key] = _.neq(value);
|
|
156
|
+
break;
|
|
157
|
+
case Command.Gtlt:
|
|
158
|
+
params.conditions.where[key] = _.and(_.gt(value[0]), _.lt(value[1]));
|
|
159
|
+
break;
|
|
160
|
+
default:
|
|
161
|
+
const check = type;
|
|
162
|
+
console.error(666, '处理 where 条件 出现未定义的情况', check);
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return params;
|
|
169
|
+
}
|
|
170
|
+
async exec(params) {
|
|
171
|
+
params = await this.handleData(params);
|
|
172
|
+
params = await this.handleConditions(params);
|
|
173
|
+
const res = await this.request(params);
|
|
174
|
+
return this.handleRes(params, res);
|
|
175
|
+
}
|
|
176
|
+
add(data, isReturn, conditions) {
|
|
177
|
+
return this.exec({ method: Method.Add, conditions, data, isReturn });
|
|
178
|
+
}
|
|
179
|
+
// 删
|
|
180
|
+
delete(conditions) {
|
|
181
|
+
return this.exec({ method: Method.Delete, conditions });
|
|
182
|
+
}
|
|
183
|
+
update(conditions, data, isReturn, isSet) {
|
|
184
|
+
return this.exec({ method: Method.Update, conditions, data, isReturn, isSet });
|
|
185
|
+
}
|
|
186
|
+
// 查
|
|
187
|
+
find(conditions) {
|
|
188
|
+
return this.exec({ method: Method.Find, conditions });
|
|
189
|
+
}
|
|
190
|
+
// 查列表
|
|
191
|
+
findList(conditions) {
|
|
192
|
+
return this.exec({ method: Method.FindList, conditions });
|
|
193
|
+
}
|
|
194
|
+
// 查
|
|
195
|
+
count(conditions) {
|
|
196
|
+
return this.exec({ method: Method.Count, conditions });
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export { Collection };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { init } from '@cloudbase/node-sdk';
|
|
2
|
+
import { Collection } from './Collection.js';
|
|
3
|
+
|
|
4
|
+
class Database {
|
|
5
|
+
db;
|
|
6
|
+
instance = {};
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.db = init(config).database();
|
|
9
|
+
}
|
|
10
|
+
// 封装了较多功能的 collection
|
|
11
|
+
collection(name) {
|
|
12
|
+
if (!this.instance[name]) {
|
|
13
|
+
this.instance[name] = new Collection(this.db, name);
|
|
14
|
+
}
|
|
15
|
+
return this.instance[name];
|
|
16
|
+
}
|
|
17
|
+
// 创建 collection
|
|
18
|
+
createCollection(name) {
|
|
19
|
+
return this.db.createCollection(name);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { Database };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// 查询数据库的条件 - 比较的特殊条件
|
|
2
|
+
var Command;
|
|
3
|
+
(function (Command) {
|
|
4
|
+
Command["Eq"] = "eq";
|
|
5
|
+
Command["Neq"] = "neq";
|
|
6
|
+
Command["Lt"] = "lt";
|
|
7
|
+
Command["Lte"] = "lte";
|
|
8
|
+
Command["Gt"] = "gt";
|
|
9
|
+
Command["Gte"] = "gte";
|
|
10
|
+
Command["In"] = "in";
|
|
11
|
+
Command["Nin"] = "nin";
|
|
12
|
+
Command["Gtlt"] = "gtlt";
|
|
13
|
+
})(Command || (Command = {}));
|
|
14
|
+
// 查询的方法
|
|
15
|
+
var Method;
|
|
16
|
+
(function (Method) {
|
|
17
|
+
Method["Add"] = "add";
|
|
18
|
+
Method["Find"] = "find";
|
|
19
|
+
Method["FindList"] = "findList";
|
|
20
|
+
Method["Delete"] = "delete";
|
|
21
|
+
Method["Update"] = "update";
|
|
22
|
+
Method["Count"] = "count";
|
|
23
|
+
})(Method || (Method = {}));
|
|
24
|
+
|
|
25
|
+
export { Command, Method };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// 给记录添加时间
|
|
2
|
+
const appendTime = (data, type) => {
|
|
3
|
+
if (!data) {
|
|
4
|
+
return {};
|
|
5
|
+
}
|
|
6
|
+
return {
|
|
7
|
+
...data,
|
|
8
|
+
[type + 'At']: Date.now(),
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
// 默认条件
|
|
12
|
+
const defaultConditions = {
|
|
13
|
+
order: {
|
|
14
|
+
field: 'createAt',
|
|
15
|
+
type: 'desc',
|
|
16
|
+
},
|
|
17
|
+
options: {
|
|
18
|
+
timeout: 10000,
|
|
19
|
+
multiple: true,
|
|
20
|
+
},
|
|
21
|
+
page: {
|
|
22
|
+
current: 1,
|
|
23
|
+
size: 10,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { appendTime, defaultConditions };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
// 实现一个文件系统读写数据库
|
|
4
|
+
class JsonFile {
|
|
5
|
+
filePath;
|
|
6
|
+
constructor(filePath) {
|
|
7
|
+
this.filePath = path.resolve(__dirname, filePath);
|
|
8
|
+
}
|
|
9
|
+
get(key) {
|
|
10
|
+
return new Promise((resolve) => {
|
|
11
|
+
fs.readFile(this.filePath, (err, data) => {
|
|
12
|
+
const json = data ? JSON.parse(data) : {};
|
|
13
|
+
resolve(json[key]);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
set(key, value) {
|
|
18
|
+
fs.readFile(this.filePath, { encoding: 'utf-8' }, (err, data) => {
|
|
19
|
+
const json = data ? JSON.parse(data || '{}') : {};
|
|
20
|
+
json[key] = value;
|
|
21
|
+
fs.writeFile(this.filePath, JSON.stringify(json), () => {
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { JsonFile };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import nodemailer from 'nodemailer';
|
|
2
|
+
|
|
3
|
+
const fromEmail = '15835196981@163.com';
|
|
4
|
+
const fromPass = 'KPTVCFBMRXJVTCGW';
|
|
5
|
+
const transporter = nodemailer.createTransport({
|
|
6
|
+
host: 'smtp.163.com',
|
|
7
|
+
port: 465,
|
|
8
|
+
secure: true,
|
|
9
|
+
auth: {
|
|
10
|
+
user: fromEmail,
|
|
11
|
+
pass: fromPass
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
const sendMail = async (toEmail, title, content) => {
|
|
15
|
+
try {
|
|
16
|
+
await transporter.sendMail({
|
|
17
|
+
from: fromEmail,
|
|
18
|
+
to: toEmail,
|
|
19
|
+
subject: title,
|
|
20
|
+
text: content // 邮件正文
|
|
21
|
+
});
|
|
22
|
+
return title + ' 邮件通知成功';
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
return title + '邮件通知失败' + JSON.stringify(error);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { sendMail };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { default as _, cloneDeep, debounce, find, groupBy, isBoolean, isEmpty, isEqual, isError, isFunction, isNumber, isObject, isString, merge, noop, omit, pick, uniq, uniqBy, uniqWith } from 'lodash';
|
|
2
|
+
import * as consola from 'consola';
|
|
3
|
+
export { consola };
|
|
4
|
+
import './common/dayjs.js';
|
|
5
|
+
export * from 'zod';
|
|
6
|
+
export { amount, getChinese, getChineseByStr, getCookie, getLength, getProxyUrl, getRandomColor, getRandomString, getSliceStr, getStrLength, getType, isJson, jsonParse, replaceAll, replaceByRules, toString } from './common/string.js';
|
|
7
|
+
export { filterParams, findItem, watch } from './common/object.js';
|
|
8
|
+
export { delay, executePromise, handleParams, handleRes2List, locationFn } from './common/other.js';
|
|
9
|
+
export { getFileSize, getRandomNum, limitDecimals } from './common/number.js';
|
|
10
|
+
export { CustomError } from './common/classs.js';
|
|
11
|
+
export { Database } from './node/database/Database.js';
|
|
12
|
+
export { JsonFile } from './node/jsonFile/index.js';
|
|
13
|
+
export { sendMail } from './node/mail/index.js';
|
|
14
|
+
export { Dayjs, default as dayjs } from 'dayjs';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface RequestRes<D = any> {
|
|
2
|
+
success: boolean;
|
|
3
|
+
message: string;
|
|
4
|
+
data: D;
|
|
5
|
+
}
|
|
6
|
+
export type KeyValue<D extends object | string = string, V = any> = Partial<Record<D extends string ? string : keyof D, V>>;
|
|
7
|
+
export interface Pagination {
|
|
8
|
+
current?: number;
|
|
9
|
+
pageSize?: number;
|
|
10
|
+
}
|
|
11
|
+
export type SortParams<D extends object | string = string> = Record<D extends string ? string : keyof D, 'ascend' | 'descend'>;
|
|
12
|
+
export type OrderParams<D extends object | string = string> = {
|
|
13
|
+
field: D extends string ? string : keyof D;
|
|
14
|
+
type: 'asc' | 'desc';
|
|
15
|
+
};
|
|
16
|
+
export interface Option<V extends string | number = string> {
|
|
17
|
+
label: string;
|
|
18
|
+
value: V;
|
|
19
|
+
children?: Option<V>[];
|
|
20
|
+
}
|
|
21
|
+
export type OrderBy = {
|
|
22
|
+
[key: string]: 'asc' | 'desc';
|
|
23
|
+
} | {
|
|
24
|
+
[key: string]: 'asc' | 'desc';
|
|
25
|
+
}[];
|
|
26
|
+
export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
27
|
+
export type Set<T, OmitK extends keyof T = never, OptionalK extends Exclude<keyof T, OmitK> = never> = Optional<Omit<T, OmitK>, OptionalK>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const scrollIntoView: (el: Element, option?: ScrollIntoViewOptions) => void;
|
|
2
|
+
export declare const getElement: (el: string | Element) => {
|
|
3
|
+
element: null;
|
|
4
|
+
originalStyle: {};
|
|
5
|
+
} | {
|
|
6
|
+
element: Element;
|
|
7
|
+
originalStyle: CSSStyleDeclaration;
|
|
8
|
+
};
|
|
9
|
+
export declare const isElementInViewport: (el: string | Element) => boolean | undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import md5 from 'md5';
|
|
2
|
+
import classnames from 'classnames';
|
|
3
|
+
import copy from 'copy-to-clipboard';
|
|
4
|
+
import anime from 'animejs';
|
|
5
|
+
export { copy, classnames, md5, anime };
|
|
6
|
+
export declare const localforage: {
|
|
7
|
+
config: {
|
|
8
|
+
(options: LocalForageOptions): boolean;
|
|
9
|
+
(options: string): any;
|
|
10
|
+
(): LocalForageOptions;
|
|
11
|
+
};
|
|
12
|
+
setItem: <T>(key: string, value: T, callback?: ((err: any, value: T) => void) | undefined) => Promise<T>;
|
|
13
|
+
getItem: <T_1>(key: string, callback?: ((err: any, value: T_1 | null) => void) | undefined) => Promise<T_1 | null>;
|
|
14
|
+
removeItem: (key: string, callback?: ((err: any) => void) | undefined) => Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
export * from './style';
|
|
17
|
+
export * from './element';
|
|
18
|
+
export * from './other';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const readClipboard: () => Promise<string>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const hexToRgba: (hexColor: string, a?: number) => {
|
|
2
|
+
nums: {
|
|
3
|
+
red: number;
|
|
4
|
+
green: number;
|
|
5
|
+
blue: number;
|
|
6
|
+
};
|
|
7
|
+
text: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const flashBackground: (el: string | Element, color: string, a?: number) => void;
|
|
10
|
+
export declare const flashBorder: (el: string | Element, color: string, a?: number) => void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { cloneDeep, debounce, isBoolean, isEqual, isFunction, isNumber, isObject, isString, merge, omit, pick, uniq, uniqBy, uniqWith, isEmpty, isError, find, groupBy, noop } from 'lodash';
|
|
2
|
+
export { cloneDeep, debounce, isBoolean, isEqual, isFunction, isNumber, isObject, isString, merge, omit, pick, uniq, uniqBy, uniqWith, isEmpty, isError, find, groupBy, noop, };
|
|
3
|
+
export * as consola from 'consola';
|
|
4
|
+
export { default as dayjs, Dayjs } from './dayjs';
|
|
5
|
+
export * from 'zod';
|
|
6
|
+
export * from './string';
|
|
7
|
+
export * from './object';
|
|
8
|
+
export * from './other';
|
|
9
|
+
export * from './number';
|
|
10
|
+
export * from './classs';
|
|
11
|
+
export { default as _ } from 'lodash';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const findItem: <I>(list: I[], attr: keyof I, value?: I[keyof I] | undefined) => I | undefined;
|
|
2
|
+
export declare const filterParams: (params: {
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
}) => {};
|
|
5
|
+
export declare const watch: {
|
|
6
|
+
observe(obj: {
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}, key: string, watchFun: (value: any, val: any) => undefined): void;
|
|
9
|
+
setWatcher(data?: {}, watch?: {}): void;
|
|
10
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { KeyValue, OrderParams, Pagination, SortParams } from '@wzyjs/types';
|
|
2
|
+
export declare const handleParams: (params?: Pagination & KeyValue, sort?: SortParams) => {
|
|
3
|
+
page: {
|
|
4
|
+
size?: number | undefined;
|
|
5
|
+
current?: number | undefined;
|
|
6
|
+
};
|
|
7
|
+
where: KeyValue<string, string | number | boolean | RegExp>;
|
|
8
|
+
order?: OrderParams<string> | undefined;
|
|
9
|
+
};
|
|
10
|
+
export declare const handleRes2List: <D>(reqPromise: any) => Promise<{
|
|
11
|
+
label: string;
|
|
12
|
+
value: string;
|
|
13
|
+
}[]>;
|
|
14
|
+
export declare const executePromise: (promise: Promise<any>) => Promise<{
|
|
15
|
+
result: any;
|
|
16
|
+
time: number;
|
|
17
|
+
}>;
|
|
18
|
+
export declare const locationFn: {
|
|
19
|
+
url2Params: (url?: string) => {};
|
|
20
|
+
params2Url: (params: {
|
|
21
|
+
[key: string]: any;
|
|
22
|
+
}) => string;
|
|
23
|
+
setUrlParams: (key: string, value: any, keepName: string) => void;
|
|
24
|
+
urlGetPath: (url?: string) => string;
|
|
25
|
+
};
|
|
26
|
+
export declare const delay: (time?: number) => Promise<unknown>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const getChineseByStr: (str: string) => string;
|
|
2
|
+
export declare const getStrLength: (value: string) => number;
|
|
3
|
+
export declare const replaceAll: (str: string, searchValue: string, replaceValue: string) => string;
|
|
4
|
+
export declare const replaceByRules: (str: string, rules: [string, string][]) => string;
|
|
5
|
+
export declare const getType: (value: any) => string;
|
|
6
|
+
export declare const amount: (str: string) => string;
|
|
7
|
+
export declare const jsonParse: (value: string | object) => object;
|
|
8
|
+
export declare const isJson: (str: string) => boolean;
|
|
9
|
+
export declare const toString: (value: any) => string;
|
|
10
|
+
export declare const getRandomColor: () => string;
|
|
11
|
+
export declare const getRandomString: (length?: number) => string;
|
|
12
|
+
export declare const getChinese: (str: string) => string;
|
|
13
|
+
export declare const getSliceStr: (str: string, before: string, after: string) => string;
|
|
14
|
+
export declare const getProxyUrl: (url: string) => string;
|
|
15
|
+
export declare const getLength: (value: string) => number;
|
|
16
|
+
export declare const getCookie: (name: string) => string | null;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Database, IKeyValue } from '@cloudbase/node-sdk';
|
|
2
|
+
import { Add, Conditions, Count, Delete, Find, FindList, IdConditions, MethodParams, Update, WhereConditions } from './types';
|
|
3
|
+
export declare class Collection<D extends IKeyValue> {
|
|
4
|
+
private readonly db;
|
|
5
|
+
private readonly collection;
|
|
6
|
+
constructor(db: Database.Db, name: string);
|
|
7
|
+
private joinConditions;
|
|
8
|
+
private request;
|
|
9
|
+
private handleRes;
|
|
10
|
+
private handleData;
|
|
11
|
+
handleConditions(params: MethodParams<D>): MethodParams<D>;
|
|
12
|
+
private exec;
|
|
13
|
+
add(data: Add.Params<D>['data']): Promise<Add.Res>;
|
|
14
|
+
add(data: Add.Params<D>['data'], isReturn: true, conditions?: Pick<IdConditions, 'field'>): Promise<Find.Res<D>>;
|
|
15
|
+
delete(conditions: Conditions): Promise<Delete.Res>;
|
|
16
|
+
update(conditions: Conditions, data: Update.Params<D>['data'], isSet?: true): Promise<Update.Res<D>>;
|
|
17
|
+
update(conditions: IdConditions, data: Update.Params<D>['data'], isSet?: true): Promise<Update.Res<D>>;
|
|
18
|
+
update(conditions: IdConditions, data: Update.Params<D>['data'], isReturn: true, isSet?: true): Promise<Find.Res<D>>;
|
|
19
|
+
find(conditions?: Conditions): Promise<Find.Res<D>>;
|
|
20
|
+
findList(conditions?: WhereConditions): Promise<FindList.Res<D>>;
|
|
21
|
+
count(conditions: Conditions): Promise<Count.Res>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import tcb, { IKeyValue } from '@cloudbase/node-sdk';
|
|
2
|
+
import { Config } from './types';
|
|
3
|
+
import { Collection } from './Collection';
|
|
4
|
+
export declare class Database {
|
|
5
|
+
private readonly db;
|
|
6
|
+
private readonly instance;
|
|
7
|
+
constructor(config: Config);
|
|
8
|
+
collection<D extends IKeyValue>(name: string): Collection<D>;
|
|
9
|
+
createCollection(name: string): tcb.IBaseRes;
|
|
10
|
+
}
|