@wzyjs/types 0.2.0 → 0.2.2
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/cjs/api.d.ts +33 -0
- package/dist/cjs/api.js +40 -0
- package/{base.ts → dist/cjs/base.d.ts} +2 -5
- package/dist/cjs/base.js +17 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +27 -0
- package/dist/cjs/other.d.ts +6 -0
- package/dist/cjs/other.js +17 -0
- package/dist/esm/api.d.ts +33 -0
- package/dist/esm/api.js +23 -0
- package/dist/esm/base.d.ts +2 -0
- package/dist/esm/base.js +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/other.d.ts +6 -0
- package/dist/esm/other.js +1 -0
- package/package.json +17 -3
- package/api.ts +0 -43
- package/dist/cjs/common/index.d.ts +0 -6
- package/dist/cjs/common/tools/index.d.ts +0 -4
- package/dist/cjs/common/tools/number.d.ts +0 -3
- package/dist/cjs/common/tools/number.js +0 -34
- package/dist/cjs/common/tools/object.d.ts +0 -10
- package/dist/cjs/common/tools/object.js +0 -43
- package/dist/cjs/common/tools/other.d.ts +0 -26
- package/dist/cjs/common/tools/other.js +0 -112
- package/dist/cjs/common/tools/string.d.ts +0 -16
- package/dist/cjs/common/tools/string.js +0 -137
- package/dist/cjs/common/types/index.d.ts +0 -20
- package/dist/cjs/fe/dayjs.d.ts +0 -4
- package/dist/cjs/fe/element.d.ts +0 -9
- package/dist/cjs/fe/index.d.ts +0 -20
- package/dist/cjs/fe/middlewares/error.d.ts +0 -3
- package/dist/cjs/fe/middlewares/index.d.ts +0 -1
- package/dist/cjs/fe/other.d.ts +0 -1
- package/dist/cjs/fe/style.d.ts +0 -10
- 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/cjs/index_rd.js +0 -141
- package/dist/cjs/rd/database/Collection.d.ts +0 -22
- package/dist/cjs/rd/database/Collection.js +0 -202
- package/dist/cjs/rd/database/Database.d.ts +0 -10
- package/dist/cjs/rd/database/Database.js +0 -25
- package/dist/cjs/rd/database/index.d.ts +0 -2
- package/dist/cjs/rd/database/types.d.ts +0 -151
- package/dist/cjs/rd/database/types.js +0 -25
- package/dist/cjs/rd/database/utils.d.ts +0 -3
- package/dist/cjs/rd/database/utils.js +0 -30
- package/dist/cjs/rd/index.d.ts +0 -3
- package/dist/cjs/rd/jsonFile/index.d.ts +0 -6
- package/dist/cjs/rd/jsonFile/index.js +0 -29
- package/dist/cjs/rd/mail/index.d.ts +0 -1
- package/dist/cjs/rd/mail/index.js +0 -31
- package/dist/cjs/rd/middlewares/index.d.ts +0 -1
- package/dist/cjs/rd/middlewares/logger.d.ts +0 -1
- package/dist/esm/common/index.d.ts +0 -6
- package/dist/esm/common/tools/index.d.ts +0 -4
- package/dist/esm/common/tools/number.d.ts +0 -3
- package/dist/esm/common/tools/number.js +0 -30
- package/dist/esm/common/tools/object.d.ts +0 -10
- package/dist/esm/common/tools/object.js +0 -39
- package/dist/esm/common/tools/other.d.ts +0 -26
- package/dist/esm/common/tools/other.js +0 -106
- package/dist/esm/common/tools/string.d.ts +0 -16
- package/dist/esm/common/tools/string.js +0 -120
- package/dist/esm/common/types/index.d.ts +0 -20
- package/dist/esm/fe/dayjs.d.ts +0 -4
- package/dist/esm/fe/dayjs.js +0 -18
- package/dist/esm/fe/element.d.ts +0 -9
- package/dist/esm/fe/element.js +0 -36
- package/dist/esm/fe/index.d.ts +0 -20
- package/dist/esm/fe/index.js +0 -16
- package/dist/esm/fe/middlewares/error.d.ts +0 -3
- package/dist/esm/fe/middlewares/error.js +0 -22
- package/dist/esm/fe/middlewares/index.d.ts +0 -1
- package/dist/esm/fe/other.d.ts +0 -1
- package/dist/esm/fe/other.js +0 -10
- package/dist/esm/fe/style.d.ts +0 -10
- package/dist/esm/fe/style.js +0 -45
- 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 -19
- package/dist/esm/index_rd.d.ts +0 -2
- package/dist/esm/rd/database/Collection.d.ts +0 -22
- package/dist/esm/rd/database/Database.d.ts +0 -10
- package/dist/esm/rd/database/index.d.ts +0 -2
- package/dist/esm/rd/database/types.d.ts +0 -151
- package/dist/esm/rd/database/utils.d.ts +0 -3
- package/dist/esm/rd/index.d.ts +0 -3
- package/dist/esm/rd/jsonFile/index.d.ts +0 -6
- package/dist/esm/rd/mail/index.d.ts +0 -1
- package/index.ts +0 -3
- package/other.ts +0 -9
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// 获取字符串中的中文字符串
|
|
4
|
-
const getChineseByStr = (str) => {
|
|
5
|
-
if (!str) {
|
|
6
|
-
return '';
|
|
7
|
-
}
|
|
8
|
-
const match = str.match(/[\u4e00-\u9fa5]/g);
|
|
9
|
-
if (!match) {
|
|
10
|
-
return '';
|
|
11
|
-
}
|
|
12
|
-
return match.join('');
|
|
13
|
-
};
|
|
14
|
-
// 获取字符串中的长度,中文算 2 个字符
|
|
15
|
-
const getStrLength = (value) => {
|
|
16
|
-
if (!value) {
|
|
17
|
-
return 0;
|
|
18
|
-
}
|
|
19
|
-
const chineseLength = getChineseByStr(value).length;
|
|
20
|
-
return (value.length - chineseLength) + chineseLength * 2;
|
|
21
|
-
};
|
|
22
|
-
// 替换全部指定字符串
|
|
23
|
-
const replaceAll = (str, searchValue, replaceValue) => {
|
|
24
|
-
if (!str || !searchValue || !replaceValue) {
|
|
25
|
-
return str || '';
|
|
26
|
-
}
|
|
27
|
-
str = str.replace(searchValue, replaceValue);
|
|
28
|
-
if (!str.includes(searchValue)) {
|
|
29
|
-
return str;
|
|
30
|
-
}
|
|
31
|
-
return replaceAll(str, searchValue, replaceValue);
|
|
32
|
-
};
|
|
33
|
-
// 根据规则替换字符串
|
|
34
|
-
const replaceByRules = (str, rules) => {
|
|
35
|
-
rules.forEach(([searchValue, replaceValue]) => {
|
|
36
|
-
str = str.replaceAll(searchValue, replaceValue);
|
|
37
|
-
});
|
|
38
|
-
return str;
|
|
39
|
-
};
|
|
40
|
-
// 获取变量的类型
|
|
41
|
-
const getType = (value) => {
|
|
42
|
-
return Object.prototype.toString.call(value).slice(8, -1);
|
|
43
|
-
};
|
|
44
|
-
// 金钱格式化,每三位加,
|
|
45
|
-
const amount = (str) => {
|
|
46
|
-
const reg = /(?=(?!\b)(\d{3})+$)/g;
|
|
47
|
-
return str.replace(reg, ',');
|
|
48
|
-
};
|
|
49
|
-
// 更安全的 JSON.parse
|
|
50
|
-
const jsonParse = (value) => {
|
|
51
|
-
if (typeof value === 'object') {
|
|
52
|
-
return value;
|
|
53
|
-
}
|
|
54
|
-
try {
|
|
55
|
-
return JSON.parse(value);
|
|
56
|
-
}
|
|
57
|
-
catch (err) {
|
|
58
|
-
return {};
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
// 是否为json字符串
|
|
62
|
-
const isJson = (str) => {
|
|
63
|
-
try {
|
|
64
|
-
if (getType(JSON.parse(str)) === 'Object') {
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
catch (e) {
|
|
69
|
-
}
|
|
70
|
-
return false;
|
|
71
|
-
};
|
|
72
|
-
// 将变量转为字符串
|
|
73
|
-
const toString = (value) => {
|
|
74
|
-
return Object.prototype.toString.call(value).slice(8, -1) === 'object' ? JSON.stringify(value) : String(value);
|
|
75
|
-
};
|
|
76
|
-
// 生成随机颜色
|
|
77
|
-
const getRandomColor = () => {
|
|
78
|
-
const color = Math.floor(Math.random() * 16777215).toString(16);
|
|
79
|
-
if (color.length === 6) {
|
|
80
|
-
return color;
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
return getRandomColor();
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
// 生成随机字符串
|
|
87
|
-
const getRandomString = (length = 4) => {
|
|
88
|
-
return Math.random().toString(36).substr(2, length);
|
|
89
|
-
};
|
|
90
|
-
// 获取字符串内的中文
|
|
91
|
-
const getChinese = (str) => {
|
|
92
|
-
if (str == null || str === '') {
|
|
93
|
-
return '';
|
|
94
|
-
}
|
|
95
|
-
const res = str.match(/[\u4e00-\u9fa5]/g);
|
|
96
|
-
if (!res) {
|
|
97
|
-
return '';
|
|
98
|
-
}
|
|
99
|
-
return res.join('');
|
|
100
|
-
};
|
|
101
|
-
// 截取指定两个文本之间的字符串 (不好用)
|
|
102
|
-
const getSliceStr = (str, before, after) => {
|
|
103
|
-
return str.slice(str.indexOf(before) + before.length, str.lastIndexOf(after));
|
|
104
|
-
};
|
|
105
|
-
// 获取代理后的url
|
|
106
|
-
const getProxyUrl = (url) => {
|
|
107
|
-
const beforeUrl = 'https://1141871752167714.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/a.LATEST/proxy/?url=';
|
|
108
|
-
return beforeUrl + url;
|
|
109
|
-
};
|
|
110
|
-
// 获取字符串的长度
|
|
111
|
-
const getLength = (value) => {
|
|
112
|
-
const chineseLength = getChinese(value).length;
|
|
113
|
-
return (value.length - chineseLength) + chineseLength * 2;
|
|
114
|
-
};
|
|
115
|
-
// 获取指定cookie
|
|
116
|
-
const getCookie = (name) => {
|
|
117
|
-
const reg = new RegExp(`(^| )${name}=([^;]*)(;|$)`);
|
|
118
|
-
const arr = document.cookie.match(reg);
|
|
119
|
-
return arr ? unescape(arr[2]) : null;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
exports.amount = amount;
|
|
123
|
-
exports.getChinese = getChinese;
|
|
124
|
-
exports.getChineseByStr = getChineseByStr;
|
|
125
|
-
exports.getCookie = getCookie;
|
|
126
|
-
exports.getLength = getLength;
|
|
127
|
-
exports.getProxyUrl = getProxyUrl;
|
|
128
|
-
exports.getRandomColor = getRandomColor;
|
|
129
|
-
exports.getRandomString = getRandomString;
|
|
130
|
-
exports.getSliceStr = getSliceStr;
|
|
131
|
-
exports.getStrLength = getStrLength;
|
|
132
|
-
exports.getType = getType;
|
|
133
|
-
exports.isJson = isJson;
|
|
134
|
-
exports.jsonParse = jsonParse;
|
|
135
|
-
exports.replaceAll = replaceAll;
|
|
136
|
-
exports.replaceByRules = replaceByRules;
|
|
137
|
-
exports.toString = toString;
|
|
@@ -1,20 +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
|
-
}
|
package/dist/cjs/fe/dayjs.d.ts
DELETED
package/dist/cjs/fe/element.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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;
|
package/dist/cjs/fe/index.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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 { default as dayjs, Dayjs } from './dayjs';
|
|
17
|
-
export * from './style';
|
|
18
|
-
export * from './element';
|
|
19
|
-
export * from './other';
|
|
20
|
-
export * from './middlewares';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './error';
|
package/dist/cjs/fe/other.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const readClipboard: () => Promise<string>;
|
package/dist/cjs/fe/style.d.ts
DELETED
|
@@ -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;
|
package/dist/cjs/index_all.d.ts
DELETED
package/dist/cjs/index_fe.d.ts
DELETED
package/dist/cjs/index_rd.d.ts
DELETED
package/dist/cjs/index_rd.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var lodash = require('lodash');
|
|
4
|
-
var consola = require('consola');
|
|
5
|
-
var string = require('./common/tools/string.js');
|
|
6
|
-
var object = require('./common/tools/object.js');
|
|
7
|
-
var other = require('./common/tools/other.js');
|
|
8
|
-
var number = require('./common/tools/number.js');
|
|
9
|
-
var Database = require('./rd/database/Database.js');
|
|
10
|
-
var index = require('./rd/jsonFile/index.js');
|
|
11
|
-
var index$1 = require('./rd/mail/index.js');
|
|
12
|
-
|
|
13
|
-
function _interopNamespaceDefault(e) {
|
|
14
|
-
var n = Object.create(null);
|
|
15
|
-
if (e) {
|
|
16
|
-
Object.keys(e).forEach(function (k) {
|
|
17
|
-
if (k !== 'default') {
|
|
18
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
19
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
get: function () { return e[k]; }
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
n.default = e;
|
|
27
|
-
return Object.freeze(n);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
var consola__namespace = /*#__PURE__*/_interopNamespaceDefault(consola);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
exports._ = lodash;
|
|
35
|
-
Object.defineProperty(exports, 'cloneDeep', {
|
|
36
|
-
enumerable: true,
|
|
37
|
-
get: function () { return lodash.cloneDeep; }
|
|
38
|
-
});
|
|
39
|
-
Object.defineProperty(exports, 'debounce', {
|
|
40
|
-
enumerable: true,
|
|
41
|
-
get: function () { return lodash.debounce; }
|
|
42
|
-
});
|
|
43
|
-
Object.defineProperty(exports, 'find', {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
get: function () { return lodash.find; }
|
|
46
|
-
});
|
|
47
|
-
Object.defineProperty(exports, 'groupBy', {
|
|
48
|
-
enumerable: true,
|
|
49
|
-
get: function () { return lodash.groupBy; }
|
|
50
|
-
});
|
|
51
|
-
Object.defineProperty(exports, 'isBoolean', {
|
|
52
|
-
enumerable: true,
|
|
53
|
-
get: function () { return lodash.isBoolean; }
|
|
54
|
-
});
|
|
55
|
-
Object.defineProperty(exports, 'isEmpty', {
|
|
56
|
-
enumerable: true,
|
|
57
|
-
get: function () { return lodash.isEmpty; }
|
|
58
|
-
});
|
|
59
|
-
Object.defineProperty(exports, 'isEqual', {
|
|
60
|
-
enumerable: true,
|
|
61
|
-
get: function () { return lodash.isEqual; }
|
|
62
|
-
});
|
|
63
|
-
Object.defineProperty(exports, 'isError', {
|
|
64
|
-
enumerable: true,
|
|
65
|
-
get: function () { return lodash.isError; }
|
|
66
|
-
});
|
|
67
|
-
Object.defineProperty(exports, 'isFunction', {
|
|
68
|
-
enumerable: true,
|
|
69
|
-
get: function () { return lodash.isFunction; }
|
|
70
|
-
});
|
|
71
|
-
Object.defineProperty(exports, 'isNumber', {
|
|
72
|
-
enumerable: true,
|
|
73
|
-
get: function () { return lodash.isNumber; }
|
|
74
|
-
});
|
|
75
|
-
Object.defineProperty(exports, 'isObject', {
|
|
76
|
-
enumerable: true,
|
|
77
|
-
get: function () { return lodash.isObject; }
|
|
78
|
-
});
|
|
79
|
-
Object.defineProperty(exports, 'isString', {
|
|
80
|
-
enumerable: true,
|
|
81
|
-
get: function () { return lodash.isString; }
|
|
82
|
-
});
|
|
83
|
-
Object.defineProperty(exports, 'merge', {
|
|
84
|
-
enumerable: true,
|
|
85
|
-
get: function () { return lodash.merge; }
|
|
86
|
-
});
|
|
87
|
-
Object.defineProperty(exports, 'noop', {
|
|
88
|
-
enumerable: true,
|
|
89
|
-
get: function () { return lodash.noop; }
|
|
90
|
-
});
|
|
91
|
-
Object.defineProperty(exports, 'omit', {
|
|
92
|
-
enumerable: true,
|
|
93
|
-
get: function () { return lodash.omit; }
|
|
94
|
-
});
|
|
95
|
-
Object.defineProperty(exports, 'pick', {
|
|
96
|
-
enumerable: true,
|
|
97
|
-
get: function () { return lodash.pick; }
|
|
98
|
-
});
|
|
99
|
-
Object.defineProperty(exports, 'uniq', {
|
|
100
|
-
enumerable: true,
|
|
101
|
-
get: function () { return lodash.uniq; }
|
|
102
|
-
});
|
|
103
|
-
Object.defineProperty(exports, 'uniqBy', {
|
|
104
|
-
enumerable: true,
|
|
105
|
-
get: function () { return lodash.uniqBy; }
|
|
106
|
-
});
|
|
107
|
-
Object.defineProperty(exports, 'uniqWith', {
|
|
108
|
-
enumerable: true,
|
|
109
|
-
get: function () { return lodash.uniqWith; }
|
|
110
|
-
});
|
|
111
|
-
exports.consola = consola__namespace;
|
|
112
|
-
exports.amount = string.amount;
|
|
113
|
-
exports.getChinese = string.getChinese;
|
|
114
|
-
exports.getChineseByStr = string.getChineseByStr;
|
|
115
|
-
exports.getCookie = string.getCookie;
|
|
116
|
-
exports.getLength = string.getLength;
|
|
117
|
-
exports.getProxyUrl = string.getProxyUrl;
|
|
118
|
-
exports.getRandomColor = string.getRandomColor;
|
|
119
|
-
exports.getRandomString = string.getRandomString;
|
|
120
|
-
exports.getSliceStr = string.getSliceStr;
|
|
121
|
-
exports.getStrLength = string.getStrLength;
|
|
122
|
-
exports.getType = string.getType;
|
|
123
|
-
exports.isJson = string.isJson;
|
|
124
|
-
exports.jsonParse = string.jsonParse;
|
|
125
|
-
exports.replaceAll = string.replaceAll;
|
|
126
|
-
exports.replaceByRules = string.replaceByRules;
|
|
127
|
-
exports.toString = string.toString;
|
|
128
|
-
exports.filterParams = object.filterParams;
|
|
129
|
-
exports.findItem = object.findItem;
|
|
130
|
-
exports.watch = object.watch;
|
|
131
|
-
exports.delay = other.delay;
|
|
132
|
-
exports.executePromise = other.executePromise;
|
|
133
|
-
exports.handleParams = other.handleParams;
|
|
134
|
-
exports.handleRes2List = other.handleRes2List;
|
|
135
|
-
exports.locationFn = other.locationFn;
|
|
136
|
-
exports.getFileSize = number.getFileSize;
|
|
137
|
-
exports.getRandomNum = number.getRandomNum;
|
|
138
|
-
exports.limitDecimals = number.limitDecimals;
|
|
139
|
-
exports.Database = Database.Database;
|
|
140
|
-
exports.JsonFile = index.JsonFile;
|
|
141
|
-
exports.sendMail = index$1.sendMail;
|
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -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,10 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -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;
|