baja-lite 1.0.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.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/cjs/constant.d.ts +13 -0
  4. package/cjs/constant.js +19 -0
  5. package/cjs/error.d.ts +5 -0
  6. package/cjs/error.js +16 -0
  7. package/cjs/fn.d.ts +128 -0
  8. package/cjs/fn.js +169 -0
  9. package/cjs/index.d.ts +8 -0
  10. package/cjs/index.js +24 -0
  11. package/cjs/math.d.ts +69 -0
  12. package/cjs/math.js +435 -0
  13. package/cjs/now.d.ts +7 -0
  14. package/cjs/now.js +26 -0
  15. package/cjs/object.d.ts +77 -0
  16. package/cjs/object.js +212 -0
  17. package/cjs/set-ex.d.ts +171 -0
  18. package/cjs/set-ex.js +336 -0
  19. package/cjs/sql.d.ts +1216 -0
  20. package/cjs/sql.js +3380 -0
  21. package/cjs/string.d.ts +18 -0
  22. package/cjs/string.js +124 -0
  23. package/cjs/test-mysql.d.ts +1 -0
  24. package/cjs/test-mysql.js +108 -0
  25. package/cjs/test-sqlite.d.ts +1 -0
  26. package/cjs/test-sqlite.js +89 -0
  27. package/cjs/test.d.ts +1 -0
  28. package/cjs/test.js +4 -0
  29. package/es/constant.d.ts +13 -0
  30. package/es/constant.js +16 -0
  31. package/es/error.d.ts +5 -0
  32. package/es/error.js +13 -0
  33. package/es/fn.d.ts +128 -0
  34. package/es/fn.js +162 -0
  35. package/es/index.d.ts +8 -0
  36. package/es/index.js +8 -0
  37. package/es/math.d.ts +69 -0
  38. package/es/math.js +414 -0
  39. package/es/now.d.ts +7 -0
  40. package/es/now.js +16 -0
  41. package/es/object.d.ts +77 -0
  42. package/es/object.js +196 -0
  43. package/es/set-ex.d.ts +171 -0
  44. package/es/set-ex.js +332 -0
  45. package/es/sql.d.ts +1216 -0
  46. package/es/sql.js +3338 -0
  47. package/es/string.d.ts +18 -0
  48. package/es/string.js +109 -0
  49. package/es/test-mysql.d.ts +1 -0
  50. package/es/test-mysql.js +106 -0
  51. package/es/test-sqlite.d.ts +1 -0
  52. package/es/test-sqlite.js +87 -0
  53. package/es/test.d.ts +1 -0
  54. package/es/test.js +2 -0
  55. package/package.json +66 -0
package/es/string.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * 通过uri获取key
3
+ * @param uri
4
+ */
5
+ export declare const getPicKey: (uri: string) => string;
6
+ export declare const emptyString: (source: any, skipEmptyString?: boolean) => boolean;
7
+ export declare const eqString: (a: any, b: any) => boolean;
8
+ export declare const notEmptyString: (source: any, skipEmptyString?: boolean) => boolean;
9
+ export declare const safeString: (source?: string) => string;
10
+ export declare const trimObject: <T>(data: any) => T;
11
+ export declare const randomNumber: (len: number) => string;
12
+ export declare const randomString: (len: number) => string;
13
+ export declare const randomString2: (len: number) => string;
14
+ export declare const randomString3: (len: number) => string;
15
+ export declare const buildWxStr: (data: {
16
+ [key: string]: string;
17
+ }, maxLabelLength: number, ...titles: string[]) => string;
18
+ export declare const replaceChineseCode: (str: string) => string;
package/es/string.js ADDED
@@ -0,0 +1,109 @@
1
+ import { lowerCase } from 'lodash';
2
+ /**
3
+ * 通过uri获取key
4
+ * @param uri
5
+ */
6
+ export const getPicKey = (uri) => {
7
+ const arr = /key=([0-9a-zA-Z.]+)/.exec(uri);
8
+ if (arr && arr.length === 2) {
9
+ return arr[1];
10
+ }
11
+ return uri;
12
+ };
13
+ export const emptyString = (source, skipEmptyString = true) => {
14
+ return (source === null ||
15
+ source === undefined ||
16
+ (skipEmptyString === true && (source === '' || `${source}`.replace(/\s/g, '') === '')));
17
+ };
18
+ export const eqString = (a, b) => {
19
+ return lowerCase(`${a}`) === lowerCase(`${b}`);
20
+ };
21
+ export const notEmptyString = (source, skipEmptyString = true) => {
22
+ return emptyString(source, skipEmptyString) === false;
23
+ };
24
+ export const safeString = (source) => {
25
+ if (source) {
26
+ return `${source}`.replace(/'/g, '');
27
+ }
28
+ return '';
29
+ };
30
+ export const trimObject = (data) => {
31
+ if (data) {
32
+ for (const k in data) {
33
+ if (typeof data[k] === 'string') {
34
+ data[k] = data[k].trim();
35
+ }
36
+ }
37
+ }
38
+ return data;
39
+ };
40
+ export const randomNumber = (len) => {
41
+ return `${parseInt(`${(Math.random() * 9 + 1) * Math.pow(10, (len - 1))}`, 10)}`;
42
+ };
43
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
44
+ const charLen = chars.length;
45
+ export const randomString = (len) => {
46
+ return Array.from(new Array(len)).map(() => chars.charAt(Math.floor(Math.random() * charLen))).join('');
47
+ };
48
+ const chars2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
49
+ const charLen2 = chars2.length;
50
+ export const randomString2 = (len) => {
51
+ return Array.from(new Array(len)).map(() => chars2.charAt(Math.floor(Math.random() * charLen2))).join('');
52
+ };
53
+ const chars3 = 'abcdefghijklmnopqrstuvwxyz0123456789';
54
+ const charLen3 = chars3.length;
55
+ export const randomString3 = (len) => {
56
+ return Array.from(new Array(len)).map(() => chars3.charAt(Math.floor(Math.random() * charLen3))).join('');
57
+ };
58
+ export const buildWxStr = (data, maxLabelLength, ...titles) => {
59
+ let str = titles.join('\r\n');
60
+ str += '\r\n\r\n';
61
+ const items = new Array();
62
+ // const maxLength = maxLabelLength * 2;
63
+ for (const [key, value] of Object.entries(data)) {
64
+ if (notEmptyString(value)) {
65
+ const len = maxLabelLength - key.length;
66
+ items.push(`${key}:${''.padEnd(len * 3 + (len > 0 ? 1 : 0), ' ')}${value}`);
67
+ }
68
+ }
69
+ str += items.join('\r\n');
70
+ return str;
71
+ };
72
+ const chinese = /[\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/g;
73
+ const table = {
74
+ '!': '!',
75
+ '¥': '$',
76
+ '…': '.',
77
+ '(': '(',
78
+ ')': ')',
79
+ '《': '<',
80
+ '》': '>',
81
+ '?': '?',
82
+ ':': ':',
83
+ '“': `'`,
84
+ '”': `'`,
85
+ '’': `'`,
86
+ '‘': `'`,
87
+ ',': ',',
88
+ '。': '.',
89
+ '、': '/',
90
+ ';': ';',
91
+ '〈': '<',
92
+ '〉': '>',
93
+ '【': '[',
94
+ '】': ']',
95
+ '『': '[',
96
+ '』': ']',
97
+ '「': '[',
98
+ '」': ']',
99
+ '﹃': '[',
100
+ '﹄': ']',
101
+ '〔': '(',
102
+ '〕': ')',
103
+ '—': '-',
104
+ '~': '~',
105
+ '﹏': '~'
106
+ };
107
+ export const replaceChineseCode = (str) => {
108
+ return str.replace(chinese, (a) => table[a] || '');
109
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,106 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { SqlService, LetsGo, Field, DB, DBType, SqlDelMode, SqlType, SqlInsertMode, SqlTemplateMode, SqlQueryMode } from './sql';
11
+ class AmaFuck2 {
12
+ }
13
+ __decorate([
14
+ Field({ type: SqlType.varchar, length1: 200 }),
15
+ __metadata("design:type", String)
16
+ ], AmaFuck2.prototype, "site", void 0);
17
+ __decorate([
18
+ Field({ type: SqlType.varchar, length1: 200 }),
19
+ __metadata("design:type", String)
20
+ ], AmaFuck2.prototype, "SellerSKU2", void 0);
21
+ __decorate([
22
+ Field({ type: SqlType.varchar, id: true, length1: 200 }),
23
+ __metadata("design:type", String)
24
+ ], AmaFuck2.prototype, "SellerSKU", void 0);
25
+ let AmaService2 = class AmaService2 extends SqlService {
26
+ };
27
+ AmaService2 = __decorate([
28
+ DB({
29
+ tableName: 'ama_fuck2', clz: AmaFuck2, dbType: DBType.Mysql
30
+ })
31
+ ], AmaService2);
32
+ async function go2() {
33
+ await LetsGo({
34
+ Mysql: {
35
+ host: '39.98.58.252',
36
+ port: 3308,
37
+ user: 'root',
38
+ password: 'Eme!2#456$&*',
39
+ // 数据库名
40
+ database: 'dmce',
41
+ debug: false
42
+ },
43
+ log: 'info'
44
+ });
45
+ const service = new AmaService2();
46
+ const ret = await service.transaction({
47
+ fn: async (conn) => {
48
+ const list = new Array({
49
+ SellerSKU: 'SellerSKU1',
50
+ site: 'site1'
51
+ }, {
52
+ SellerSKU: 'SellerSKU2',
53
+ SellerSKU2: 'SellerSKU22',
54
+ }, {
55
+ SellerSKU2: 'SellerSKU23',
56
+ SellerSKU: 'SellerSKU3',
57
+ site: 'site3'
58
+ }, {
59
+ SellerSKU2: 'SellerSKU24',
60
+ SellerSKU: 'SellerSKU4',
61
+ site: 'site4'
62
+ }, {
63
+ SellerSKU2: '',
64
+ SellerSKU: 'SellerSKU5',
65
+ site: undefined
66
+ });
67
+ const rt = await service.insert({
68
+ data: list,
69
+ conn, skipEmptyString: false,
70
+ mode: SqlInsertMode.InsertWithTempTable
71
+ });
72
+ console.log(11, rt);
73
+ const rt2 = await service.update({
74
+ data: {
75
+ SellerSKU: 'SellerSKU1',
76
+ SellerSKU2: 'SellerSKU21',
77
+ site: 'site1'
78
+ },
79
+ conn, skipEmptyString: false
80
+ });
81
+ console.log(22, rt2);
82
+ const rt3 = await service.delete({
83
+ where: [
84
+ { SellerSKU2: 'SellerSKU23', SellerSKU: 'SellerSKU3' }
85
+ ],
86
+ mode: SqlDelMode.TempTable,
87
+ conn
88
+ });
89
+ console.log(33, rt3);
90
+ const rt4 = await service.template({
91
+ where: { SellerSKU2: 'SellerSKU22', SellerSKU: 'SellerSKU2' },
92
+ resultMode: SqlTemplateMode.Count
93
+ });
94
+ console.log(44, rt4);
95
+ const rt5 = await service.select({
96
+ sql: `SELECT SellerSKU FROM ama_fuck2 WHERE SellerSKU LIKE CONCAT(:sku, '%');SELECT SellerSKU FROM ama_fuck2 WHERE SellerSKU LIKE CONCAT(:sku, '%');SELECT SellerSKU FROM ama_fuck2 WHERE SellerSKU LIKE CONCAT(:sku, '%')`,
97
+ params: { sku: 'SellerSKU4' },
98
+ resultMode: SqlQueryMode.Many_Row_One_Column
99
+ });
100
+ console.log(55, rt5);
101
+ return 1;
102
+ }
103
+ });
104
+ return ret;
105
+ }
106
+ go2();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,87 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { SqlService, LetsGo, Field, SqlType, DB, DBType, SqlSyncMode, SqlDelMode, SqlInsertMode } from './sql';
11
+ class AmaFuck {
12
+ }
13
+ __decorate([
14
+ Field({ type: SqlType.varchar }),
15
+ __metadata("design:type", String)
16
+ ], AmaFuck.prototype, "site", void 0);
17
+ __decorate([
18
+ Field({ type: SqlType.varchar }),
19
+ __metadata("design:type", String)
20
+ ], AmaFuck.prototype, "SellerSKU2", void 0);
21
+ __decorate([
22
+ Field({ type: SqlType.varchar, id: true }),
23
+ __metadata("design:type", String)
24
+ ], AmaFuck.prototype, "SellerSKU", void 0);
25
+ let AmaService = class AmaService extends SqlService {
26
+ };
27
+ AmaService = __decorate([
28
+ DB({
29
+ tableName: 'ama_fuck2', clz: AmaFuck, dbType: DBType.Sqlite, sqliteVersion: '0.0.3'
30
+ })
31
+ ], AmaService);
32
+ async function go() {
33
+ await LetsGo({
34
+ Sqlite: 'd:1.db',
35
+ log: 'info'
36
+ });
37
+ const service = new AmaService();
38
+ const ret = service.transaction({
39
+ sync: SqlSyncMode.Sync,
40
+ fn: conn => {
41
+ const list = new Array({
42
+ SellerSKU: '1',
43
+ site: '111'
44
+ }, {
45
+ SellerSKU: '2',
46
+ SellerSKU2: '22',
47
+ }, {
48
+ SellerSKU2: '33',
49
+ SellerSKU: '3',
50
+ site: '333'
51
+ }, {
52
+ SellerSKU2: '44',
53
+ SellerSKU: '4',
54
+ site: '444'
55
+ }, {
56
+ SellerSKU2: '',
57
+ SellerSKU: '66',
58
+ site: undefined
59
+ });
60
+ const rt = service.insert({
61
+ sync: SqlSyncMode.Sync,
62
+ data: list,
63
+ conn, skipEmptyString: false, mode: SqlInsertMode.InsertWithTempTable
64
+ });
65
+ console.log(rt);
66
+ const rt2 = service.update({
67
+ sync: SqlSyncMode.Sync,
68
+ data: list,
69
+ conn, skipEmptyString: false
70
+ });
71
+ console.log(rt2);
72
+ const rt3 = service.delete({
73
+ sync: SqlSyncMode.Sync,
74
+ where: [
75
+ { SellerSKU2: '11', SellerSKU: '1' },
76
+ { SellerSKU2: '22', SellerSKU: '2' },
77
+ { SellerSKU2: '33', SellerSKU: '3' }
78
+ ],
79
+ mode: SqlDelMode.TempTable
80
+ });
81
+ console.log(rt3);
82
+ return 1;
83
+ }
84
+ });
85
+ return ret;
86
+ }
87
+ go();
package/es/test.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/es/test.js ADDED
@@ -0,0 +1,2 @@
1
+ import { format } from 'mysql2';
2
+ console.log(format('select 1 from a where ?', [['1', '2', '3']]));
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "baja-lite",
3
+ "version": "1.0.0",
4
+ "description": "some util for self",
5
+ "homepage": "https://github.com/void-soul/util-man",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/void-soul/util-man.git"
9
+ },
10
+ "license": "MIT",
11
+ "author": "void-soul",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./es/index.d.ts",
15
+ "import": "./es/index.js",
16
+ "require": "./cjs/index.js"
17
+ },
18
+ "./*": "./*"
19
+ },
20
+ "main": "./cjs/index.js",
21
+ "types": "./es/index.d.ts",
22
+ "scripts": {
23
+ "dist": "node ci.js",
24
+ "mysql": "bun --inspect ./src/test-mysql.ts",
25
+ "sqlite": "node inspect ./dist/cjs/test-sqlite.js",
26
+ "mysql2": "node inspect ./dist/cjs/test-mysql.js"
27
+ },
28
+ "dependencies": {
29
+ "dayjs": "1.11.11",
30
+ "decimal.js": "10.4.3",
31
+ "iterare": "1.2.1",
32
+ "lodash": "4.17.21",
33
+ "pino": "9.1.0",
34
+ "pino-pretty": "11.1.0",
35
+ "reflect-metadata": "0.2.2",
36
+ "rxjs": "7.8.1",
37
+ "sqlstring": "2.3.3",
38
+ "tslib": "2.6.2",
39
+ "md5": "2.3.0"
40
+ },
41
+ "devDependencies": {
42
+ "@types/better-sqlite3": "7.6.10",
43
+ "@types/lodash": "4.17.4",
44
+ "@types/node": "20.14.0",
45
+ "@types/md5": "2.3.5",
46
+ "@types/sqlstring": "2.3.2",
47
+ "@typescript-eslint/eslint-plugin": "7.11.0",
48
+ "@typescript-eslint/parser": "7.11.0",
49
+ "better-sqlite3": "11.0.0",
50
+ "mongodb": "6.7.0",
51
+ "mysql2": "3.10.0",
52
+ "shelljs": "0.8.5",
53
+ "typescript": "5.4.5",
54
+ "ioredis": "5.4.1",
55
+ "redlock": "5.0.0-beta.2"
56
+ },
57
+ "publishConfig": {
58
+ "access": "public"
59
+ },
60
+ "models": "./es/index.js",
61
+ "engines": {
62
+ "node": "20",
63
+ "npm": ">= 6.13.4",
64
+ "yarn": ">= 1.22.19"
65
+ }
66
+ }