baja-lite 1.1.12 → 1.2.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/code.js CHANGED
@@ -96,6 +96,7 @@ console.log(`
96
96
  className, eventMainInfo
97
97
  ClassName, EventMainInfo
98
98
  vueName, event-main-info
99
+ splitVueName, event/main-info
99
100
  splitName, event/main/info
100
101
  SplitName, event/mainInfo
101
102
 
@@ -118,7 +119,7 @@ console.log(`
118
119
  idNames: [], 主键字段数组
119
120
  idNames_join: []
120
121
 
121
- modelName: 模块名称,可能为空字符串
122
+ modelName: 模块名称,可能为空字符串 event
122
123
  modelPath: 模块名称实际就影响访问路径,所以这里会直接拼好controller的模块访问路径,如果模块为空,则该属性就是空字符串,否则是 /模块名称/
123
124
 
124
125
  logicDelete: 逻辑删除的查询条件,可以附加在sql条件的末尾,可能是空的
@@ -239,6 +240,8 @@ try {
239
240
  const className = tableName.replace(/_(\w)/g, (a, b) => b.toUpperCase());
240
241
  const ClassName = className.replace(/\w/, (v) => v.toUpperCase());
241
242
  const vueName = tableName.replace(/_/g, '-');
243
+ const splitVueName = tableName.replace(/_/, '/').replace(/_/g, '-');
244
+ const modelName = tableName.substring(0, tableName.indexOf('_'));
242
245
  const splitName = tableName.replace(/_/g, '/');
243
246
  const SplitName = tableName.replace(/_/, '/').replace(/_(\w)/g, (a, b) => b.toUpperCase());
244
247
  const data = {
@@ -247,6 +250,7 @@ try {
247
250
  className,
248
251
  ClassName,
249
252
  vueName,
253
+ splitVueName,
250
254
  splitName,
251
255
  SplitName,
252
256
  columns,
package/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export * from './list.js';
6
6
  export * from './math.js';
7
7
  export * from './object.js';
8
8
  export * from './set-ex.js';
9
+ export * from './snowflake.js';
9
10
  export * from './sql.js';
10
11
  export * from './sqlite.js';
11
12
  export * from './string.js';
package/index.js CHANGED
@@ -6,6 +6,7 @@ export * from './list.js';
6
6
  export * from './math.js';
7
7
  export * from './object.js';
8
8
  export * from './set-ex.js';
9
+ export * from './snowflake.js';
9
10
  export * from './sql.js';
10
11
  export * from './sqlite.js';
11
12
  export * from './string.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baja-lite",
3
- "version": "1.1.12",
3
+ "version": "1.2.0",
4
4
  "description": "some util for self",
5
5
  "homepage": "https://github.com/void-soul/util-man",
6
6
  "repository": {
@@ -31,12 +31,14 @@
31
31
  "postgres": "bun --inspect ./src/test-postgresql.ts",
32
32
  "postgres2": "node inspect ./dist/cjs/test-postgresql.js",
33
33
  "sqlite": "node inspect ./dist/cjs/test-sqlite.js",
34
- "xml": "bun --inspect ./src/test-xml.ts"
34
+ "xml": "bun --inspect ./src/test-xml.ts",
35
+ "test": "bun --inspect ./src/test.ts",
36
+ "test2": "node inspect ./dist/cjs/tes.js"
35
37
  },
36
38
  "dependencies": {
37
- "@msgpack/msgpack": "3.0.0-beta3",
39
+ "@msgpack/msgpack": "3.1.0",
38
40
  "@types/request-promise": "4.1.51",
39
- "axios": "1.7.9",
41
+ "axios": "1.8.1",
40
42
  "decimal.js": "10.5.0",
41
43
  "html-parse-stringify": "3.0.1",
42
44
  "iterare": "1.2.1",
@@ -47,7 +49,7 @@
47
49
  "reflect-metadata": "0.2.2",
48
50
  "request": "2.88.2",
49
51
  "request-promise": "4.2.6",
50
- "sql-formatter": "15.4.10",
52
+ "sql-formatter": "15.4.11",
51
53
  "sqlstring": "2.3.3",
52
54
  "tslib": "2.8.1"
53
55
  },
@@ -59,14 +61,14 @@
59
61
  "@types/pg-pool": "2.0.6",
60
62
  "@types/shelljs": "0.8.15",
61
63
  "@types/sqlstring": "2.3.2",
62
- "@typescript-eslint/eslint-plugin": "8.22.0",
63
- "@typescript-eslint/parser": "8.22.0",
64
+ "@typescript-eslint/eslint-plugin": "8.26.0",
65
+ "@typescript-eslint/parser": "8.26.0",
64
66
  "better-sqlite3": "11.8.1",
65
- "ioredis": "5.4.2",
66
- "mongodb": "6.13.0",
67
- "mysql2": "3.12.0",
68
- "pg": "8.13.1",
69
- "pg-pool": "3.7.0",
67
+ "ioredis": "5.6.0",
68
+ "mongodb": "6.14.2",
69
+ "mysql2": "3.13.0",
70
+ "pg": "8.13.3",
71
+ "pg-pool": "3.7.1",
70
72
  "redlock": "5.0.0-beta.2",
71
73
  "shelljs": "0.8.5",
72
74
  "typescript": "5.7.3"
package/snowflake.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ export declare class Snowflake {
2
+ private seq;
3
+ private mid;
4
+ private offset;
5
+ private lastTime;
6
+ constructor(options?: {
7
+ mid?: number;
8
+ offset?: number;
9
+ });
10
+ generate(): string | null;
11
+ }
12
+ export declare const snowflake: Snowflake;
package/snowflake.js ADDED
@@ -0,0 +1,108 @@
1
+ function hexToDec(hexStr) {
2
+ if (hexStr.substring(0, 2) === "0x")
3
+ hexStr = hexStr.substring(2);
4
+ hexStr = hexStr.toLowerCase();
5
+ return convertBase(hexStr, 16, 10);
6
+ }
7
+ function add(x, y, base) {
8
+ let z = [];
9
+ let n = Math.max(x.length, y.length);
10
+ let carry = 0;
11
+ let i = 0;
12
+ while (i < n || carry) {
13
+ let xi = i < x.length ? x[i] : 0;
14
+ let yi = i < y.length ? y[i] : 0;
15
+ let zi = carry + xi + yi;
16
+ z.push(zi % base);
17
+ carry = Math.floor(zi / base);
18
+ i++;
19
+ }
20
+ return z;
21
+ }
22
+ function multiplyByNumber(num, x, base) {
23
+ if (num < 0)
24
+ return null;
25
+ if (num == 0)
26
+ return [];
27
+ let result = [];
28
+ let power = x;
29
+ while (true) {
30
+ if (num & 1) {
31
+ result = add(result, power, base);
32
+ }
33
+ num = num >> 1;
34
+ if (num === 0)
35
+ break;
36
+ power = add(power, power, base);
37
+ }
38
+ return result;
39
+ }
40
+ function parseToDigitsArray(str, base) {
41
+ let digits = str.split("");
42
+ let ary = [];
43
+ for (let i = digits.length - 1; i >= 0; i--) {
44
+ let n = parseInt(digits[i], base);
45
+ if (isNaN(n))
46
+ return null;
47
+ ary.push(n);
48
+ }
49
+ return ary;
50
+ }
51
+ function convertBase(str, fromBase, toBase) {
52
+ let digits = parseToDigitsArray(str, fromBase);
53
+ if (digits === null)
54
+ return null;
55
+ let outArray = [];
56
+ let power = [1];
57
+ for (let i = 0; i < digits.length; i++) {
58
+ if (digits[i]) {
59
+ outArray = add(outArray, multiplyByNumber(digits[i], power, toBase), toBase);
60
+ }
61
+ power = multiplyByNumber(fromBase, power, toBase);
62
+ }
63
+ let out = "";
64
+ for (let i = outArray.length - 1; i >= 0; i--) {
65
+ out += outArray[i].toString(toBase);
66
+ }
67
+ return out;
68
+ }
69
+ export class Snowflake {
70
+ constructor(options) {
71
+ options = options || {};
72
+ this.seq = 0;
73
+ this.mid = (options.mid || 1) % 1023;
74
+ this.offset = options.offset || 0;
75
+ this.lastTime = 0;
76
+ }
77
+ generate() {
78
+ let time = Date.now(), bTime = (time - this.offset).toString(2);
79
+ if (this.lastTime == time) {
80
+ this.seq++;
81
+ if (this.seq > 4095) {
82
+ this.seq = 0;
83
+ while (Date.now() <= time) { }
84
+ }
85
+ }
86
+ else {
87
+ this.seq = 0;
88
+ }
89
+ this.lastTime = time;
90
+ let bSeq = this.seq.toString(2), bMid = this.mid.toString(2);
91
+ while (bSeq.length < 12) {
92
+ bSeq = "0" + bSeq;
93
+ }
94
+ while (bMid.length < 10) {
95
+ bMid = "0" + bMid;
96
+ }
97
+ let bid = bTime + bMid + bSeq;
98
+ let id = "";
99
+ for (let i = bid.length; i > 0; i -= 4) {
100
+ id = parseInt(bid.substring(i - 4, i), 2).toString(16) + id;
101
+ }
102
+ return hexToDec(id);
103
+ }
104
+ }
105
+ export const snowflake = new Snowflake({
106
+ mid: 66,
107
+ offset: (2024 - 1970) * 31536000 * 1000,
108
+ });
package/test.js CHANGED
@@ -1,2 +1,2 @@
1
- import { format } from 'mysql2';
2
- console.log(format('select 1 from a where ?', [['1', '2', '3']]));
1
+ import { snowflake } from "snowflake";
2
+ console.log(snowflake.generate());