Skip to content

Commit 974f4e2

Browse files
committed
Fefactored and implements a standard Snowflake UUID generator.
1 parent f53df24 commit 974f4e2

29 files changed

+1757
-427
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
/dist/
1+
/libs/
2+
/samples/
23
/node_modules/

.vscode/launch.json

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,67 @@
77
{
88
"type": "node",
99
"request": "launch",
10-
"name": "Test Snowflake-SI",
11-
"program": "${workspaceFolder}/src/tests/snowflake-si.ts",
10+
"name": "Check Snowflake-BI Performance",
11+
"program": "${workspaceFolder}/src/samples/SnowflakeBI-Performance.ts",
1212
"sourceMaps": true,
1313
"outFiles": [
14-
"${workspaceFolder}/dist/*.js",
15-
"${workspaceFolder}/dist/**/*.js"
14+
"${workspaceFolder}/libs/*.js",
15+
"${workspaceFolder}/samples/*.js"
1616
]
1717
},
1818
{
1919
"type": "node",
2020
"request": "launch",
21-
"name": "Test Snowflake-SI-vA",
22-
"program": "${workspaceFolder}/src/tests/snowflake-si-va.ts",
21+
"name": "Verify Snowflake-BI Output",
22+
"program": "${workspaceFolder}/src/samples/SnowflakeBI-Verification.ts",
2323
"sourceMaps": true,
2424
"outFiles": [
25-
"${workspaceFolder}/dist/*.js",
26-
"${workspaceFolder}/dist/**/*.js"
25+
"${workspaceFolder}/libs/*.js",
26+
"${workspaceFolder}/samples/*.js"
27+
]
28+
},
29+
{
30+
"type": "node",
31+
"request": "launch",
32+
"name": "Check Snowflake-SI Performance",
33+
"program": "${workspaceFolder}/src/samples/SnowflakeSI-Performance.ts",
34+
"sourceMaps": true,
35+
"outFiles": [
36+
"${workspaceFolder}/libs/*.js",
37+
"${workspaceFolder}/samples/*.js"
38+
]
39+
},
40+
{
41+
"type": "node",
42+
"request": "launch",
43+
"name": "Verify Snowflake-SI Output",
44+
"program": "${workspaceFolder}/src/samples/SnowflakeSI-Verification.ts",
45+
"sourceMaps": true,
46+
"outFiles": [
47+
"${workspaceFolder}/libs/*.js",
48+
"${workspaceFolder}/samples/*.js"
49+
]
50+
},
51+
{
52+
"type": "node",
53+
"request": "launch",
54+
"name": "Check Snowflake-SI-vA Performance",
55+
"program": "${workspaceFolder}/src/samples/SnowflakeSIvA-Performance.ts",
56+
"sourceMaps": true,
57+
"outFiles": [
58+
"${workspaceFolder}/libs/*.js",
59+
"${workspaceFolder}/samples/*.js"
60+
]
61+
},
62+
{
63+
"type": "node",
64+
"request": "launch",
65+
"name": "Verify Snowflake-SI-vA Output",
66+
"program": "${workspaceFolder}/src/samples/SnowflakeSIvA-Verification.ts",
67+
"sourceMaps": true,
68+
"outFiles": [
69+
"${workspaceFolder}/libs/*.js",
70+
"${workspaceFolder}/samples/*.js"
2771
]
2872
}
2973
]

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"typescript.tsdk": "node_modules\\typescript\\lib"
3+
}

.vscode/tasks.json

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,22 @@
44
"version": "2.0.0",
55
"tasks": [
66
{
7-
"label": "Build (Watching)",
8-
"command": "tsc",
9-
"type": "shell",
10-
"args": [
11-
"-w",
12-
"-p",
13-
"."
7+
"label": "[LiteRT/UUID.js] Build (Prefer Local Compiler)",
8+
"type": "npm",
9+
"script": "build",
10+
"problemMatcher": [
11+
"$tsc-watch"
1412
],
15-
"presentation": {
16-
"echo": true,
17-
"reveal": "never",
18-
"focus": false,
19-
"panel": "shared"
20-
},
21-
"isBackground": true,
22-
"group": {
23-
"kind": "build",
24-
"isDefault": true
25-
},
26-
"problemMatcher": "$tsc-watch"
13+
"isBackground": true
14+
},
15+
{
16+
"label": "[LiteRT/UUID.js] Build (Watching, Prefer Local Compiler)",
17+
"type": "npm",
18+
"script": "build-watch",
19+
"problemMatcher": [
20+
"$tsc-watch"
21+
],
22+
"isBackground": true
2723
}
2824
]
2925
}

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changes Logs
22

3+
## v1.0.0
4+
5+
- Refactored the project.
6+
- Added implements of standard Snowflake algorithm.
7+
38
## v0.1.2
49

510
- Remove useless dependencies.

LICENSE

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -165,27 +165,3 @@ incurred by, or claims asserted against, such Contributor by reason of your
165165
accepting any such warranty or additional liability.
166166

167167
END OF TERMS AND CONDITIONS
168-
169-
APPENDIX: How to apply the Apache License to your work
170-
171-
To apply the Apache License to your work, attach the following boilerplate
172-
notice, with the fields enclosed by brackets "{}" replaced with your own
173-
identifying information. (Don't include the brackets!) The text should be
174-
enclosed in the appropriate comment syntax for the file format. We also
175-
recommend that a file or class name and description of purpose be included on
176-
the same "printed page" as the copyright notice for easier identification within
177-
third-party archives.
178-
179-
Copyright 2018 Angus.Fenying
180-
181-
Licensed under the Apache License, Version 2.0 (the "License");
182-
you may not use this file except in compliance with the License.
183-
You may obtain a copy of the License at
184-
185-
http://www.apache.org/licenses/LICENSE-2.0
186-
187-
Unless required by applicable law or agreed to in writing, software
188-
distributed under the License is distributed on an "AS IS" BASIS,
189-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190-
See the License for the specific language governing permissions and
191-
limitations under the License.

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,21 @@ npm i @litert/uuid --save
2323

2424
## Algorithms
2525

26-
Now only [Snowflake-SI](./docs/en-US/Snowflake-SI.md) algorithm and one of its
27-
variety [Snowflake-SI-vA](./docs/en-US/Snowflake-SI-vA.md) are supported.
26+
Following algorithms are supported:
2827

29-
> The Snowflake-SI algorithm generates safe integer (52-bits integer) for
30-
> JavaScript, with capacity 128 uuids per milliseconds, and 64 machine parallel
31-
> working.
28+
### [Snowflake](https://blog.twitter.com/engineering/en_us/a/2010/announcing-snowflake.html)
29+
30+
A 64-bit integer UUID algorithm provided by Twitter.
31+
32+
### [Snowflake-SI](./docs/en-US/Snowflake-SI.md)
33+
34+
The Snowflake-SI algorithm generates safe integer (52-bits integer) for
35+
JavaScript, with capacity 128 uuids per milliseconds, and 64 machine parallel
36+
working.
37+
38+
### [Snowflake-SI-vA](./docs/en-US/Snowflake-SI-vA.md)
39+
40+
A variant of Snowflake-SI algorithm.
3241

3342
## Samples
3443

README_zh.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,20 @@ npm i @litert/uuid --save
2323

2424
## 生成算法
2525

26-
目前只支持 [Snowflake-SI](./docs/zh-CN/Snowflake-SI.md) 算法及其一种变种
27-
[Snowflake-SI-vA](./docs/zh-CN/Snowflake-SI-vA.md)
26+
目前支持以下生成算法。
2827

29-
> Snowflake-SI 是 Snowflake Safe Integer 的简写,即是 Snowflake 算法的简版,但是能
30-
> 保证生成的是 ECMAScript 规范中的安全整数(0 ~ 2 ^ 53 - 1)
28+
### [Snowflake](https://blog.twitter.com/engineering/en_us/a/2010/announcing-snowflake.html)
29+
30+
一种推特发明的 64 位整数 UUID 生成算法。
31+
32+
### [Snowflake-SI](./docs/zh-CN/Snowflake-SI.md)
33+
34+
Snowflake-SI 是 Snowflake Safe Integer 的简写,即是 Snowflake 算法的简版,但是能
35+
保证生成的是 ECMAScript 规范中的安全整数(0 ~ 2 ^ 53 - 1)
36+
37+
### [Snowflake-SI-vA](./docs/zh-CN/Snowflake-SI-vA.md)
38+
39+
Snowflake-SI-vA 是 Snowflake-SI 算法的一个变种。
3140

3241
## 示例
3342

package-lock.json

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"name": "@litert/uuid",
3-
"version": "0.1.2",
3+
"version": "1.0.0",
44
"description": "A uuid generator library for LiteRT framework.",
5-
"main": "dist/index.js",
5+
"main": "libs/index.js",
66
"scripts": {
77
"prepare": "npm run rebuild",
8-
"build": "tsc -p .",
8+
"build": "echo Using TypeScript && tsc -v && tsc -p .",
9+
"build-watch": "echo Using TypeScript && tsc -v && tsc -w -p .",
910
"rebuild": "npm run clean && npm run lint && npm run build",
10-
"test": "echo See directory sources/samples",
11-
"clean": "rm -rf dist",
11+
"test": "echo See directory src/samples",
12+
"clean": "rm -rf libs samples",
1213
"lint": "tslint -p . -c tslint.json"
1314
},
1415
"keywords": [
@@ -27,9 +28,16 @@
2728
"url": "https://github.com/litert/uuid.js/issues"
2829
},
2930
"homepage": "https://github.com/litert/uuid.js#readme",
30-
"types": "dist/index.d.ts",
31-
"typings": "dist/index.d.ts",
31+
"types": "libs/index.d.ts",
32+
"typings": "libs/index.d.ts",
3233
"engines": {
33-
"node": ">=8.0.0"
34+
"node": ">=10.0.0"
35+
},
36+
"devDependencies": {
37+
"@types/node": "^10.12.18",
38+
"typescript": "^3.2.2"
39+
},
40+
"dependencies": {
41+
"@litert/core": "^1.0.3"
3442
}
3543
}

0 commit comments

Comments
 (0)