@wzyjs/utils 0.0.30 → 0.1.0
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/utils/src → cjs}/browser/element.d.ts +9 -9
- package/dist/cjs/browser/element.js +59 -0
- package/dist/{node/cjs/utils/src → cjs}/browser/index.d.ts +18 -18
- package/dist/cjs/browser/index.js +64 -0
- package/dist/{browser/cjs/utils/src → cjs}/browser/other.d.ts +1 -1
- package/dist/cjs/browser/other.js +35 -0
- package/dist/{browser/esm/utils/src → cjs}/browser/style.d.ts +10 -10
- package/dist/cjs/browser/style.js +81 -0
- package/dist/{browser/cjs/utils/src → cjs}/browser.d.ts +2 -2
- package/dist/cjs/browser.js +25 -0
- package/dist/{browser/esm/utils/src → cjs}/common/classs.d.ts +5 -5
- package/dist/cjs/common/classs.js +36 -0
- package/dist/{browser/cjs/utils/src → cjs}/common/dayjs.d.ts +4 -4
- package/dist/cjs/common/dayjs.js +57 -0
- package/dist/{node/cjs/utils/src → cjs}/common/index.d.ts +11 -11
- package/dist/cjs/common/index.js +99 -0
- package/dist/{browser/cjs/utils/src → cjs}/common/number.d.ts +3 -3
- package/dist/cjs/common/number.js +55 -0
- package/dist/{browser/esm/utils/src → cjs}/common/object.d.ts +10 -10
- package/dist/cjs/common/object.js +65 -0
- package/dist/{node/esm/utils/src → cjs}/common/other.d.ts +26 -26
- package/dist/cjs/common/other.js +129 -0
- package/dist/{browser/cjs/utils/src → cjs}/common/string.d.ts +16 -16
- package/dist/cjs/common/string.js +157 -0
- package/dist/{node/cjs/utils/src → cjs}/node/database/Collection.d.ts +22 -22
- package/dist/cjs/node/database/Collection.js +219 -0
- package/dist/{node/cjs/utils/src → cjs}/node/database/Database.d.ts +10 -10
- package/dist/cjs/node/database/Database.js +47 -0
- package/dist/{browser/esm/utils/src → cjs}/node/database/index.d.ts +2 -2
- package/dist/cjs/node/database/index.js +38 -0
- package/dist/{node/esm/utils/src → cjs}/node/database/types.d.ts +151 -151
- package/dist/cjs/node/database/types.js +51 -0
- package/dist/{browser/cjs/utils/src → cjs}/node/database/utils.d.ts +3 -3
- package/dist/cjs/node/database/utils.js +53 -0
- package/dist/{browser/cjs/utils/src → cjs}/node/index.d.ts +3 -3
- package/dist/cjs/node/index.js +27 -0
- package/dist/{node/cjs/utils/src → cjs}/node/jsonFile/index.d.ts +6 -6
- package/dist/cjs/node/jsonFile/index.js +51 -0
- package/dist/{browser/cjs/utils/src → cjs}/node/mail/index.d.ts +1 -1
- package/dist/cjs/node/mail/index.js +67 -0
- package/dist/{node/cjs/utils/src → cjs}/node.d.ts +2 -2
- package/dist/cjs/node.js +25 -0
- package/dist/{node/cjs/utils/src → esm}/browser/element.d.ts +9 -9
- package/dist/esm/browser/element.js +43 -0
- package/dist/{node/esm/utils/src → esm}/browser/index.d.ts +18 -18
- package/dist/esm/browser/index.js +15 -0
- package/dist/{node/cjs/utils/src → esm}/browser/other.d.ts +1 -1
- package/dist/esm/browser/other.js +28 -0
- package/dist/{browser/cjs/utils/src → esm}/browser/style.d.ts +10 -10
- package/dist/esm/browser/style.js +55 -0
- package/dist/{node/cjs/utils/src → esm}/browser.d.ts +2 -2
- package/dist/esm/browser.js +2 -0
- package/dist/{browser/cjs/utils/src → esm}/common/classs.d.ts +5 -5
- package/dist/esm/common/classs.js +33 -0
- package/dist/{browser/esm/utils/src → esm}/common/dayjs.d.ts +4 -4
- package/dist/{browser/esm → esm}/common/dayjs.js +10 -10
- package/dist/{node/esm/utils/src → esm}/common/index.d.ts +11 -11
- package/dist/{browser/cjs/utils/src/common/index.d.ts → esm/common/index.js} +12 -11
- package/dist/{browser/esm/utils/src → esm}/common/number.d.ts +3 -3
- package/dist/esm/common/number.js +31 -0
- package/dist/{node/cjs/utils/src → esm}/common/object.d.ts +10 -10
- package/dist/esm/common/object.js +84 -0
- package/dist/{browser/esm/utils/src → esm}/common/other.d.ts +26 -26
- package/dist/esm/common/other.js +173 -0
- package/dist/{browser/esm/utils/src → esm}/common/string.d.ts +16 -16
- package/dist/esm/common/string.js +140 -0
- package/dist/{browser/cjs/utils/src → esm}/node/database/Collection.d.ts +22 -22
- package/dist/esm/node/database/Collection.js +356 -0
- package/dist/{browser/cjs/utils/src → esm}/node/database/Database.d.ts +10 -10
- package/dist/esm/node/database/Database.js +36 -0
- package/dist/{node/cjs/utils/src → esm}/node/database/index.d.ts +2 -2
- package/dist/{browser/cjs/utils/src/node/database/index.d.ts → esm/node/database/index.js} +2 -2
- package/dist/{node/cjs/utils/src → esm}/node/database/types.d.ts +151 -151
- package/dist/esm/node/database/types.js +55 -0
- package/dist/{browser/esm/utils/src → esm}/node/database/utils.d.ts +3 -3
- package/dist/esm/node/database/utils.js +29 -0
- package/dist/{browser/esm/utils/src → esm}/node/index.d.ts +3 -3
- package/dist/esm/node/index.js +3 -0
- package/dist/{browser/cjs/utils/src → esm}/node/jsonFile/index.d.ts +6 -6
- package/dist/esm/node/jsonFile/index.js +43 -0
- package/dist/{browser/esm/utils/src → esm}/node/mail/index.d.ts +1 -1
- package/dist/esm/node/mail/index.js +48 -0
- package/dist/{browser/cjs/utils/src → esm}/node.d.ts +2 -2
- package/dist/esm/node.js +2 -0
- package/package.json +10 -23
- package/dist/browser/cjs/browser/element.js +0 -40
- package/dist/browser/cjs/browser/index.js +0 -20
- package/dist/browser/cjs/browser/other.js +0 -12
- package/dist/browser/cjs/browser/style.js +0 -49
- package/dist/browser/cjs/browser.js +0 -171
- package/dist/browser/cjs/common/classs.js +0 -14
- package/dist/browser/cjs/common/dayjs.js +0 -27
- package/dist/browser/cjs/common/number.js +0 -34
- package/dist/browser/cjs/common/object.js +0 -43
- package/dist/browser/cjs/common/other.js +0 -112
- package/dist/browser/cjs/common/string.js +0 -137
- package/dist/browser/cjs/types/index.d.ts +0 -27
- package/dist/browser/cjs/utils/src/browser/index.d.ts +0 -18
- package/dist/browser/cjs/utils/src/common/object.d.ts +0 -10
- package/dist/browser/cjs/utils/src/common/other.d.ts +0 -26
- package/dist/browser/cjs/utils/src/node/database/types.d.ts +0 -151
- package/dist/browser/esm/browser/element.js +0 -36
- package/dist/browser/esm/browser/index.js +0 -14
- package/dist/browser/esm/browser/other.js +0 -10
- package/dist/browser/esm/browser/style.js +0 -45
- package/dist/browser/esm/browser.js +0 -19
- package/dist/browser/esm/common/classs.js +0 -12
- package/dist/browser/esm/common/number.js +0 -30
- package/dist/browser/esm/common/object.js +0 -39
- package/dist/browser/esm/common/other.js +0 -106
- package/dist/browser/esm/common/string.js +0 -120
- package/dist/browser/esm/types/index.d.ts +0 -27
- package/dist/browser/esm/utils/src/browser/element.d.ts +0 -9
- package/dist/browser/esm/utils/src/browser/index.d.ts +0 -18
- package/dist/browser/esm/utils/src/browser/other.d.ts +0 -1
- package/dist/browser/esm/utils/src/browser.d.ts +0 -2
- package/dist/browser/esm/utils/src/common/index.d.ts +0 -11
- package/dist/browser/esm/utils/src/node/database/Collection.d.ts +0 -22
- package/dist/browser/esm/utils/src/node/database/Database.d.ts +0 -10
- package/dist/browser/esm/utils/src/node/database/types.d.ts +0 -151
- package/dist/browser/esm/utils/src/node/jsonFile/index.d.ts +0 -6
- package/dist/browser/esm/utils/src/node.d.ts +0 -2
- package/dist/node/cjs/common/classs.js +0 -14
- package/dist/node/cjs/common/dayjs.js +0 -27
- package/dist/node/cjs/common/number.js +0 -34
- package/dist/node/cjs/common/object.js +0 -43
- package/dist/node/cjs/common/other.js +0 -112
- package/dist/node/cjs/common/string.js +0 -137
- package/dist/node/cjs/node/database/Collection.js +0 -202
- package/dist/node/cjs/node/database/Database.js +0 -25
- package/dist/node/cjs/node/database/types.js +0 -25
- package/dist/node/cjs/node/database/utils.js +0 -30
- package/dist/node/cjs/node/jsonFile/index.js +0 -29
- package/dist/node/cjs/node/mail/index.js +0 -31
- package/dist/node/cjs/node.js +0 -157
- package/dist/node/cjs/types/index.d.ts +0 -27
- package/dist/node/cjs/utils/src/browser/style.d.ts +0 -10
- package/dist/node/cjs/utils/src/common/classs.d.ts +0 -5
- package/dist/node/cjs/utils/src/common/dayjs.d.ts +0 -4
- package/dist/node/cjs/utils/src/common/number.d.ts +0 -3
- package/dist/node/cjs/utils/src/common/other.d.ts +0 -26
- package/dist/node/cjs/utils/src/common/string.d.ts +0 -16
- package/dist/node/cjs/utils/src/node/database/utils.d.ts +0 -3
- package/dist/node/cjs/utils/src/node/index.d.ts +0 -3
- package/dist/node/cjs/utils/src/node/mail/index.d.ts +0 -1
- package/dist/node/esm/common/classs.js +0 -12
- package/dist/node/esm/common/dayjs.js +0 -18
- package/dist/node/esm/common/number.js +0 -30
- package/dist/node/esm/common/object.js +0 -39
- package/dist/node/esm/common/other.js +0 -106
- package/dist/node/esm/common/string.js +0 -120
- package/dist/node/esm/node/database/Collection.js +0 -200
- package/dist/node/esm/node/database/Database.js +0 -23
- package/dist/node/esm/node/database/types.js +0 -25
- package/dist/node/esm/node/database/utils.js +0 -27
- package/dist/node/esm/node/jsonFile/index.js +0 -27
- package/dist/node/esm/node/mail/index.js +0 -29
- package/dist/node/esm/node.js +0 -14
- package/dist/node/esm/types/index.d.ts +0 -27
- package/dist/node/esm/utils/src/browser/element.d.ts +0 -9
- package/dist/node/esm/utils/src/browser/other.d.ts +0 -1
- package/dist/node/esm/utils/src/browser/style.d.ts +0 -10
- package/dist/node/esm/utils/src/browser.d.ts +0 -2
- package/dist/node/esm/utils/src/common/classs.d.ts +0 -5
- package/dist/node/esm/utils/src/common/dayjs.d.ts +0 -4
- package/dist/node/esm/utils/src/common/number.d.ts +0 -3
- package/dist/node/esm/utils/src/common/object.d.ts +0 -10
- package/dist/node/esm/utils/src/common/string.d.ts +0 -16
- package/dist/node/esm/utils/src/node/database/Collection.d.ts +0 -22
- package/dist/node/esm/utils/src/node/database/Database.d.ts +0 -10
- package/dist/node/esm/utils/src/node/database/index.d.ts +0 -2
- package/dist/node/esm/utils/src/node/database/utils.d.ts +0 -3
- package/dist/node/esm/utils/src/node/index.d.ts +0 -3
- package/dist/node/esm/utils/src/node/jsonFile/index.d.ts +0 -6
- package/dist/node/esm/utils/src/node/mail/index.d.ts +0 -1
- package/dist/node/esm/utils/src/node.d.ts +0 -2
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var lodash = require('lodash');
|
|
4
|
-
var utils = require('./utils.js');
|
|
5
|
-
var types = require('./types.js');
|
|
6
|
-
|
|
7
|
-
class Collection {
|
|
8
|
-
db;
|
|
9
|
-
collection;
|
|
10
|
-
constructor(db, name) {
|
|
11
|
-
this.db = db;
|
|
12
|
-
this.collection = db.collection(name);
|
|
13
|
-
}
|
|
14
|
-
joinConditions(conditions) {
|
|
15
|
-
let record = this.collection;
|
|
16
|
-
if (!conditions) {
|
|
17
|
-
return record;
|
|
18
|
-
}
|
|
19
|
-
// 如果是根据 _id 查询
|
|
20
|
-
if ('_id' in conditions) {
|
|
21
|
-
record = record.doc(conditions._id);
|
|
22
|
-
// 如果是根据 条件 查询
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
const { page, order, where, options } = conditions;
|
|
26
|
-
if (options) {
|
|
27
|
-
record = record.options(options);
|
|
28
|
-
}
|
|
29
|
-
if (where) {
|
|
30
|
-
record = record.where(where);
|
|
31
|
-
}
|
|
32
|
-
if (order) {
|
|
33
|
-
record = record.orderBy(order.field, order.type || 'desc');
|
|
34
|
-
}
|
|
35
|
-
if (page?.current && page?.size) {
|
|
36
|
-
record = record.skip((page.current - 1) * page.size);
|
|
37
|
-
}
|
|
38
|
-
if (page?.size) {
|
|
39
|
-
record = record.limit(page.size);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
if (Array.isArray(conditions.field)) {
|
|
43
|
-
record = record.field(conditions.field.reduce((o, i) => ({ ...o, [i]: true }), {}));
|
|
44
|
-
}
|
|
45
|
-
else if (conditions.field) {
|
|
46
|
-
record = record.field(conditions.field);
|
|
47
|
-
}
|
|
48
|
-
return record;
|
|
49
|
-
}
|
|
50
|
-
request(params) {
|
|
51
|
-
switch (params.method) {
|
|
52
|
-
case types.Method.Add:
|
|
53
|
-
return this.joinConditions().add(params.data);
|
|
54
|
-
case types.Method.Find:
|
|
55
|
-
case types.Method.FindList:
|
|
56
|
-
return this.joinConditions(params.conditions).get();
|
|
57
|
-
case types.Method.Delete:
|
|
58
|
-
return this.joinConditions(params.conditions).remove();
|
|
59
|
-
case types.Method.Update:
|
|
60
|
-
if (params.isSet && '_id' in params.conditions) {
|
|
61
|
-
return this.joinConditions(params.conditions).set(params.data);
|
|
62
|
-
}
|
|
63
|
-
return this.joinConditions(params.conditions).update(params.data);
|
|
64
|
-
case types.Method.Count:
|
|
65
|
-
return this.joinConditions(params.conditions).count();
|
|
66
|
-
default:
|
|
67
|
-
throw new Error('method is not exist');
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
// 处理出参
|
|
71
|
-
async handleRes(params, res) {
|
|
72
|
-
if (res) {
|
|
73
|
-
delete res.requestId;
|
|
74
|
-
}
|
|
75
|
-
let data = res;
|
|
76
|
-
switch (params.method) {
|
|
77
|
-
case types.Method.Add:
|
|
78
|
-
const addRes = res;
|
|
79
|
-
if (addRes.id && params.isReturn) {
|
|
80
|
-
data = await this.find({ _id: addRes.id, field: params.conditions?.field });
|
|
81
|
-
}
|
|
82
|
-
break;
|
|
83
|
-
case types.Method.Update:
|
|
84
|
-
const updateRes = res;
|
|
85
|
-
if (updateRes.updated && params.isReturn && '_id' in params.conditions) {
|
|
86
|
-
data = await this.find({ _id: params.conditions._id, field: params.conditions?.field });
|
|
87
|
-
}
|
|
88
|
-
break;
|
|
89
|
-
case types.Method.Find:
|
|
90
|
-
const getRes = res;
|
|
91
|
-
data = getRes?.data[0] || null;
|
|
92
|
-
break;
|
|
93
|
-
case types.Method.FindList:
|
|
94
|
-
const getListRes = res;
|
|
95
|
-
const countRes = await this.request({
|
|
96
|
-
method: types.Method.Count,
|
|
97
|
-
conditions: params.conditions,
|
|
98
|
-
});
|
|
99
|
-
data = {
|
|
100
|
-
list: getListRes.data,
|
|
101
|
-
total: countRes.total,
|
|
102
|
-
};
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
return data;
|
|
106
|
-
}
|
|
107
|
-
// 处理数据
|
|
108
|
-
async handleData(params) {
|
|
109
|
-
switch (params.method) {
|
|
110
|
-
case types.Method.Add:
|
|
111
|
-
params.data = utils.appendTime(params.data, 'create');
|
|
112
|
-
params.data = utils.appendTime(params.data, 'update');
|
|
113
|
-
break;
|
|
114
|
-
case types.Method.Update:
|
|
115
|
-
if ('_id' in params.data) {
|
|
116
|
-
delete params.data._id;
|
|
117
|
-
}
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
return params;
|
|
121
|
-
}
|
|
122
|
-
// 处理条件
|
|
123
|
-
handleConditions(params) {
|
|
124
|
-
if (params.method !== types.Method.Add) {
|
|
125
|
-
params.conditions = lodash.merge(lodash.cloneDeep(utils.defaultConditions), params.conditions);
|
|
126
|
-
}
|
|
127
|
-
// 处理 where 条件
|
|
128
|
-
if (params.conditions && 'where' in params.conditions) {
|
|
129
|
-
const { command: _ } = this.db;
|
|
130
|
-
for (const key in params.conditions.where) {
|
|
131
|
-
const whereValue = params.conditions.where[key];
|
|
132
|
-
if (lodash.isObject(whereValue)) {
|
|
133
|
-
const { type, value } = whereValue;
|
|
134
|
-
switch (type) {
|
|
135
|
-
case types.Command.In:
|
|
136
|
-
params.conditions.where[key] = _.in(value);
|
|
137
|
-
break;
|
|
138
|
-
case types.Command.Nin:
|
|
139
|
-
params.conditions.where[key] = _.nin(value);
|
|
140
|
-
break;
|
|
141
|
-
case types.Command.Gt:
|
|
142
|
-
params.conditions.where[key] = _.gt(value);
|
|
143
|
-
break;
|
|
144
|
-
case types.Command.Gte:
|
|
145
|
-
params.conditions.where[key] = _.gte(value);
|
|
146
|
-
break;
|
|
147
|
-
case types.Command.Lt:
|
|
148
|
-
params.conditions.where[key] = _.lt(value);
|
|
149
|
-
break;
|
|
150
|
-
case types.Command.Lte:
|
|
151
|
-
params.conditions.where[key] = _.lte(value);
|
|
152
|
-
break;
|
|
153
|
-
case types.Command.Eq:
|
|
154
|
-
params.conditions.where[key] = _.eq(value);
|
|
155
|
-
break;
|
|
156
|
-
case types.Command.Neq:
|
|
157
|
-
params.conditions.where[key] = _.neq(value);
|
|
158
|
-
break;
|
|
159
|
-
case types.Command.Gtlt:
|
|
160
|
-
params.conditions.where[key] = _.and(_.gt(value[0]), _.lt(value[1]));
|
|
161
|
-
break;
|
|
162
|
-
default:
|
|
163
|
-
const check = type;
|
|
164
|
-
console.error(666, '处理 where 条件 出现未定义的情况', check);
|
|
165
|
-
break;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return params;
|
|
171
|
-
}
|
|
172
|
-
async exec(params) {
|
|
173
|
-
params = await this.handleData(params);
|
|
174
|
-
params = await this.handleConditions(params);
|
|
175
|
-
const res = await this.request(params);
|
|
176
|
-
return this.handleRes(params, res);
|
|
177
|
-
}
|
|
178
|
-
add(data, isReturn, conditions) {
|
|
179
|
-
return this.exec({ method: types.Method.Add, conditions, data, isReturn });
|
|
180
|
-
}
|
|
181
|
-
// 删
|
|
182
|
-
delete(conditions) {
|
|
183
|
-
return this.exec({ method: types.Method.Delete, conditions });
|
|
184
|
-
}
|
|
185
|
-
update(conditions, data, isReturn, isSet) {
|
|
186
|
-
return this.exec({ method: types.Method.Update, conditions, data, isReturn, isSet });
|
|
187
|
-
}
|
|
188
|
-
// 查
|
|
189
|
-
find(conditions) {
|
|
190
|
-
return this.exec({ method: types.Method.Find, conditions });
|
|
191
|
-
}
|
|
192
|
-
// 查列表
|
|
193
|
-
findList(conditions) {
|
|
194
|
-
return this.exec({ method: types.Method.FindList, conditions });
|
|
195
|
-
}
|
|
196
|
-
// 查
|
|
197
|
-
count(conditions) {
|
|
198
|
-
return this.exec({ method: types.Method.Count, conditions });
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
exports.Collection = Collection;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var nodeSdk = require('@cloudbase/node-sdk');
|
|
4
|
-
var Collection = require('./Collection.js');
|
|
5
|
-
|
|
6
|
-
class Database {
|
|
7
|
-
db;
|
|
8
|
-
instance = {};
|
|
9
|
-
constructor(config) {
|
|
10
|
-
this.db = nodeSdk.init(config).database();
|
|
11
|
-
}
|
|
12
|
-
// 封装了较多功能的 collection
|
|
13
|
-
collection(name) {
|
|
14
|
-
if (!this.instance[name]) {
|
|
15
|
-
this.instance[name] = new Collection.Collection(this.db, name);
|
|
16
|
-
}
|
|
17
|
-
return this.instance[name];
|
|
18
|
-
}
|
|
19
|
-
// 创建 collection
|
|
20
|
-
createCollection(name) {
|
|
21
|
-
return this.db.createCollection(name);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
exports.Database = Database;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// 查询数据库的条件 - 比较的特殊条件
|
|
4
|
-
exports.Command = void 0;
|
|
5
|
-
(function (Command) {
|
|
6
|
-
Command["Eq"] = "eq";
|
|
7
|
-
Command["Neq"] = "neq";
|
|
8
|
-
Command["Lt"] = "lt";
|
|
9
|
-
Command["Lte"] = "lte";
|
|
10
|
-
Command["Gt"] = "gt";
|
|
11
|
-
Command["Gte"] = "gte";
|
|
12
|
-
Command["In"] = "in";
|
|
13
|
-
Command["Nin"] = "nin";
|
|
14
|
-
Command["Gtlt"] = "gtlt";
|
|
15
|
-
})(exports.Command || (exports.Command = {}));
|
|
16
|
-
// 查询的方法
|
|
17
|
-
exports.Method = void 0;
|
|
18
|
-
(function (Method) {
|
|
19
|
-
Method["Add"] = "add";
|
|
20
|
-
Method["Find"] = "find";
|
|
21
|
-
Method["FindList"] = "findList";
|
|
22
|
-
Method["Delete"] = "delete";
|
|
23
|
-
Method["Update"] = "update";
|
|
24
|
-
Method["Count"] = "count";
|
|
25
|
-
})(exports.Method || (exports.Method = {}));
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// 给记录添加时间
|
|
4
|
-
const appendTime = (data, type) => {
|
|
5
|
-
if (!data) {
|
|
6
|
-
return {};
|
|
7
|
-
}
|
|
8
|
-
return {
|
|
9
|
-
...data,
|
|
10
|
-
[type + 'At']: Date.now(),
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
// 默认条件
|
|
14
|
-
const defaultConditions = {
|
|
15
|
-
order: {
|
|
16
|
-
field: 'createAt',
|
|
17
|
-
type: 'desc',
|
|
18
|
-
},
|
|
19
|
-
options: {
|
|
20
|
-
timeout: 10000,
|
|
21
|
-
multiple: true,
|
|
22
|
-
},
|
|
23
|
-
page: {
|
|
24
|
-
current: 1,
|
|
25
|
-
size: 10,
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
exports.appendTime = appendTime;
|
|
30
|
-
exports.defaultConditions = defaultConditions;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
// 实现一个文件系统读写数据库
|
|
6
|
-
class JsonFile {
|
|
7
|
-
filePath;
|
|
8
|
-
constructor(filePath) {
|
|
9
|
-
this.filePath = path.resolve(__dirname, filePath);
|
|
10
|
-
}
|
|
11
|
-
get(key) {
|
|
12
|
-
return new Promise((resolve) => {
|
|
13
|
-
fs.readFile(this.filePath, (err, data) => {
|
|
14
|
-
const json = data ? JSON.parse(data) : {};
|
|
15
|
-
resolve(json[key]);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
set(key, value) {
|
|
20
|
-
fs.readFile(this.filePath, { encoding: 'utf-8' }, (err, data) => {
|
|
21
|
-
const json = data ? JSON.parse(data || '{}') : {};
|
|
22
|
-
json[key] = value;
|
|
23
|
-
fs.writeFile(this.filePath, JSON.stringify(json), () => {
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
exports.JsonFile = JsonFile;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var nodemailer = require('nodemailer');
|
|
4
|
-
|
|
5
|
-
const fromEmail = '15835196981@163.com';
|
|
6
|
-
const fromPass = 'KPTVCFBMRXJVTCGW';
|
|
7
|
-
const transporter = nodemailer.createTransport({
|
|
8
|
-
host: 'smtp.163.com',
|
|
9
|
-
port: 465,
|
|
10
|
-
secure: true,
|
|
11
|
-
auth: {
|
|
12
|
-
user: fromEmail,
|
|
13
|
-
pass: fromPass
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
const sendMail = async (toEmail, title, content) => {
|
|
17
|
-
try {
|
|
18
|
-
await transporter.sendMail({
|
|
19
|
-
from: fromEmail,
|
|
20
|
-
to: toEmail,
|
|
21
|
-
subject: title,
|
|
22
|
-
text: content // 邮件正文
|
|
23
|
-
});
|
|
24
|
-
return title + ' 邮件通知成功';
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
return title + '邮件通知失败' + JSON.stringify(error);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
exports.sendMail = sendMail;
|
package/dist/node/cjs/node.js
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var lodash = require('lodash');
|
|
4
|
-
var consola = require('consola');
|
|
5
|
-
require('./common/dayjs.js');
|
|
6
|
-
var zod = require('zod');
|
|
7
|
-
var string = require('./common/string.js');
|
|
8
|
-
var object = require('./common/object.js');
|
|
9
|
-
var other = require('./common/other.js');
|
|
10
|
-
var number = require('./common/number.js');
|
|
11
|
-
var classs = require('./common/classs.js');
|
|
12
|
-
var Database = require('./node/database/Database.js');
|
|
13
|
-
var index = require('./node/jsonFile/index.js');
|
|
14
|
-
var index$1 = require('./node/mail/index.js');
|
|
15
|
-
var dayjs = require('dayjs');
|
|
16
|
-
|
|
17
|
-
function _interopNamespaceDefault(e) {
|
|
18
|
-
var n = Object.create(null);
|
|
19
|
-
if (e) {
|
|
20
|
-
Object.keys(e).forEach(function (k) {
|
|
21
|
-
if (k !== 'default') {
|
|
22
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
23
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
24
|
-
enumerable: true,
|
|
25
|
-
get: function () { return e[k]; }
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
n.default = e;
|
|
31
|
-
return Object.freeze(n);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
var consola__namespace = /*#__PURE__*/_interopNamespaceDefault(consola);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
exports._ = lodash;
|
|
39
|
-
Object.defineProperty(exports, 'cloneDeep', {
|
|
40
|
-
enumerable: true,
|
|
41
|
-
get: function () { return lodash.cloneDeep; }
|
|
42
|
-
});
|
|
43
|
-
Object.defineProperty(exports, 'debounce', {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
get: function () { return lodash.debounce; }
|
|
46
|
-
});
|
|
47
|
-
Object.defineProperty(exports, 'find', {
|
|
48
|
-
enumerable: true,
|
|
49
|
-
get: function () { return lodash.find; }
|
|
50
|
-
});
|
|
51
|
-
Object.defineProperty(exports, 'groupBy', {
|
|
52
|
-
enumerable: true,
|
|
53
|
-
get: function () { return lodash.groupBy; }
|
|
54
|
-
});
|
|
55
|
-
Object.defineProperty(exports, 'isBoolean', {
|
|
56
|
-
enumerable: true,
|
|
57
|
-
get: function () { return lodash.isBoolean; }
|
|
58
|
-
});
|
|
59
|
-
Object.defineProperty(exports, 'isEmpty', {
|
|
60
|
-
enumerable: true,
|
|
61
|
-
get: function () { return lodash.isEmpty; }
|
|
62
|
-
});
|
|
63
|
-
Object.defineProperty(exports, 'isEqual', {
|
|
64
|
-
enumerable: true,
|
|
65
|
-
get: function () { return lodash.isEqual; }
|
|
66
|
-
});
|
|
67
|
-
Object.defineProperty(exports, 'isError', {
|
|
68
|
-
enumerable: true,
|
|
69
|
-
get: function () { return lodash.isError; }
|
|
70
|
-
});
|
|
71
|
-
Object.defineProperty(exports, 'isFunction', {
|
|
72
|
-
enumerable: true,
|
|
73
|
-
get: function () { return lodash.isFunction; }
|
|
74
|
-
});
|
|
75
|
-
Object.defineProperty(exports, 'isNumber', {
|
|
76
|
-
enumerable: true,
|
|
77
|
-
get: function () { return lodash.isNumber; }
|
|
78
|
-
});
|
|
79
|
-
Object.defineProperty(exports, 'isObject', {
|
|
80
|
-
enumerable: true,
|
|
81
|
-
get: function () { return lodash.isObject; }
|
|
82
|
-
});
|
|
83
|
-
Object.defineProperty(exports, 'isString', {
|
|
84
|
-
enumerable: true,
|
|
85
|
-
get: function () { return lodash.isString; }
|
|
86
|
-
});
|
|
87
|
-
Object.defineProperty(exports, 'merge', {
|
|
88
|
-
enumerable: true,
|
|
89
|
-
get: function () { return lodash.merge; }
|
|
90
|
-
});
|
|
91
|
-
Object.defineProperty(exports, 'noop', {
|
|
92
|
-
enumerable: true,
|
|
93
|
-
get: function () { return lodash.noop; }
|
|
94
|
-
});
|
|
95
|
-
Object.defineProperty(exports, 'omit', {
|
|
96
|
-
enumerable: true,
|
|
97
|
-
get: function () { return lodash.omit; }
|
|
98
|
-
});
|
|
99
|
-
Object.defineProperty(exports, 'pick', {
|
|
100
|
-
enumerable: true,
|
|
101
|
-
get: function () { return lodash.pick; }
|
|
102
|
-
});
|
|
103
|
-
Object.defineProperty(exports, 'uniq', {
|
|
104
|
-
enumerable: true,
|
|
105
|
-
get: function () { return lodash.uniq; }
|
|
106
|
-
});
|
|
107
|
-
Object.defineProperty(exports, 'uniqBy', {
|
|
108
|
-
enumerable: true,
|
|
109
|
-
get: function () { return lodash.uniqBy; }
|
|
110
|
-
});
|
|
111
|
-
Object.defineProperty(exports, 'uniqWith', {
|
|
112
|
-
enumerable: true,
|
|
113
|
-
get: function () { return lodash.uniqWith; }
|
|
114
|
-
});
|
|
115
|
-
exports.consola = consola__namespace;
|
|
116
|
-
exports.amount = string.amount;
|
|
117
|
-
exports.getChinese = string.getChinese;
|
|
118
|
-
exports.getChineseByStr = string.getChineseByStr;
|
|
119
|
-
exports.getCookie = string.getCookie;
|
|
120
|
-
exports.getLength = string.getLength;
|
|
121
|
-
exports.getProxyUrl = string.getProxyUrl;
|
|
122
|
-
exports.getRandomColor = string.getRandomColor;
|
|
123
|
-
exports.getRandomString = string.getRandomString;
|
|
124
|
-
exports.getSliceStr = string.getSliceStr;
|
|
125
|
-
exports.getStrLength = string.getStrLength;
|
|
126
|
-
exports.getType = string.getType;
|
|
127
|
-
exports.isJson = string.isJson;
|
|
128
|
-
exports.jsonParse = string.jsonParse;
|
|
129
|
-
exports.replaceAll = string.replaceAll;
|
|
130
|
-
exports.replaceByRules = string.replaceByRules;
|
|
131
|
-
exports.toString = string.toString;
|
|
132
|
-
exports.filterParams = object.filterParams;
|
|
133
|
-
exports.findItem = object.findItem;
|
|
134
|
-
exports.watch = object.watch;
|
|
135
|
-
exports.delay = other.delay;
|
|
136
|
-
exports.executePromise = other.executePromise;
|
|
137
|
-
exports.handleParams = other.handleParams;
|
|
138
|
-
exports.handleRes2List = other.handleRes2List;
|
|
139
|
-
exports.locationFn = other.locationFn;
|
|
140
|
-
exports.getFileSize = number.getFileSize;
|
|
141
|
-
exports.getRandomNum = number.getRandomNum;
|
|
142
|
-
exports.limitDecimals = number.limitDecimals;
|
|
143
|
-
exports.CustomError = classs.CustomError;
|
|
144
|
-
exports.Database = Database.Database;
|
|
145
|
-
exports.JsonFile = index.JsonFile;
|
|
146
|
-
exports.sendMail = index$1.sendMail;
|
|
147
|
-
Object.defineProperty(exports, 'Dayjs', {
|
|
148
|
-
enumerable: true,
|
|
149
|
-
get: function () { return dayjs.Dayjs; }
|
|
150
|
-
});
|
|
151
|
-
exports.dayjs = dayjs;
|
|
152
|
-
Object.keys(zod).forEach(function (k) {
|
|
153
|
-
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
154
|
-
enumerable: true,
|
|
155
|
-
get: function () { return zod[k]; }
|
|
156
|
-
});
|
|
157
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
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>;
|
|
@@ -1,10 +0,0 @@
|
|
|
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;
|
|
@@ -1,26 +0,0 @@
|
|
|
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>;
|
|
@@ -1,16 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const sendMail: (toEmail: string, title: string, content?: string) => Promise<string>;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import dayjs from 'dayjs';
|
|
2
|
-
export { Dayjs, default } from 'dayjs';
|
|
3
|
-
import isBetween from 'dayjs/plugin/isBetween';
|
|
4
|
-
import weekday from 'dayjs/plugin/weekday';
|
|
5
|
-
import localeData from 'dayjs/plugin/localeData';
|
|
6
|
-
import isoWeek from 'dayjs/plugin/isoWeek';
|
|
7
|
-
import updateLocale from 'dayjs/plugin/updateLocale';
|
|
8
|
-
import 'dayjs/locale/zh-cn';
|
|
9
|
-
|
|
10
|
-
dayjs.extend(isBetween);
|
|
11
|
-
dayjs.extend(weekday);
|
|
12
|
-
dayjs.extend(localeData);
|
|
13
|
-
dayjs.extend(isoWeek);
|
|
14
|
-
dayjs.extend(updateLocale);
|
|
15
|
-
dayjs.locale('zh-cn');
|
|
16
|
-
dayjs.updateLocale('zh-cn', {
|
|
17
|
-
weekStart: 1,
|
|
18
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// 取指定范围内的随机数
|
|
2
|
-
const getRandomNum = (min, max) => {
|
|
3
|
-
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
4
|
-
};
|
|
5
|
-
// 指定小数点的位数
|
|
6
|
-
const limitDecimals = (v, num = 2, isForce) => {
|
|
7
|
-
let value = parseFloat(v);
|
|
8
|
-
if (isNaN(value)) {
|
|
9
|
-
if (isForce) {
|
|
10
|
-
value = 0;
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
return '';
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return value.toFixed(num).toString();
|
|
17
|
-
};
|
|
18
|
-
// 转换成更易读的尺寸单位
|
|
19
|
-
const getFileSize = (size) => {
|
|
20
|
-
let d = 'G';
|
|
21
|
-
let s = size / 1024 / 1024 / 1024;
|
|
22
|
-
if (s < 1) {
|
|
23
|
-
d = 'M';
|
|
24
|
-
s *= 1024;
|
|
25
|
-
}
|
|
26
|
-
// @ts-ignore
|
|
27
|
-
return `${(s.toFixed(1) / 1).toString()}${d}`;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export { getFileSize, getRandomNum, limitDecimals };
|