antietcd 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.
- package/README.md +501 -0
- package/anticli.js +263 -0
- package/anticluster.js +526 -0
- package/antietcd-app.js +122 -0
- package/antietcd.d.ts +155 -0
- package/antietcd.js +552 -0
- package/antipersistence.js +138 -0
- package/common.js +38 -0
- package/etctree.js +875 -0
- package/package.json +55 -0
- package/stable-stringify.js +78 -0
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "antietcd",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Simplistic etcd replacement based on TinyRaft",
|
|
5
|
+
"main": "antietcd.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"lint": "eslint common.js anticli.js antipersistence.js anticluster.js antietcd.js etctree.js etctree.spec.js",
|
|
8
|
+
"test": "node etctree.spec.js"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://git.yourcmc.ru/vitalif/antietcd"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://git.yourcmc.ru/vitalif/antietcd",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://git.yourcmc.ru/vitalif/antietcd/issues"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"anticli.js",
|
|
20
|
+
"anticluster.js",
|
|
21
|
+
"antietcd-app.js",
|
|
22
|
+
"antietcd.js",
|
|
23
|
+
"antietcd.d.ts",
|
|
24
|
+
"antietcd.js",
|
|
25
|
+
"antipersistence.js",
|
|
26
|
+
"common.js",
|
|
27
|
+
"etctree.js",
|
|
28
|
+
"stable-stringify.js",
|
|
29
|
+
"README.md"
|
|
30
|
+
],
|
|
31
|
+
"keywords": [
|
|
32
|
+
"raft",
|
|
33
|
+
"etcd",
|
|
34
|
+
"quorum",
|
|
35
|
+
"leader",
|
|
36
|
+
"election"
|
|
37
|
+
],
|
|
38
|
+
"author": "Vitaliy Filippov",
|
|
39
|
+
"license": "MPL-2.0",
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=12.0.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"eslint": "^8.0.0",
|
|
45
|
+
"eslint-plugin-node": "^11.1.0"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"tinyraft": "^1.0.1",
|
|
49
|
+
"ws": "^8.17.0"
|
|
50
|
+
},
|
|
51
|
+
"bin": {
|
|
52
|
+
"antietcd": "./antietcd-app.js",
|
|
53
|
+
"anticli": "./anticli.js"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Copyright (c) Vitaliy Filippov, 2019+
|
|
2
|
+
// License: MIT
|
|
3
|
+
|
|
4
|
+
function stableStringify(obj, opts)
|
|
5
|
+
{
|
|
6
|
+
if (!opts)
|
|
7
|
+
opts = {};
|
|
8
|
+
if (typeof opts === 'function')
|
|
9
|
+
opts = { cmp: opts };
|
|
10
|
+
let space = opts.space || '';
|
|
11
|
+
if (typeof space === 'number')
|
|
12
|
+
space = Array(space+1).join(' ');
|
|
13
|
+
const cycles = (typeof opts.cycles === 'boolean') ? opts.cycles : false;
|
|
14
|
+
const cmp = opts.cmp && (function (f)
|
|
15
|
+
{
|
|
16
|
+
return function (node)
|
|
17
|
+
{
|
|
18
|
+
return function (a, b)
|
|
19
|
+
{
|
|
20
|
+
let aobj = { key: a, value: node[a] };
|
|
21
|
+
let bobj = { key: b, value: node[b] };
|
|
22
|
+
return f(aobj, bobj);
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
})(opts.cmp);
|
|
26
|
+
const seen = new Map();
|
|
27
|
+
return (function stringify (parent, key, node, level)
|
|
28
|
+
{
|
|
29
|
+
const indent = space ? ('\n' + new Array(level + 1).join(space)) : '';
|
|
30
|
+
const colonSeparator = space ? ': ' : ':';
|
|
31
|
+
if (node === undefined)
|
|
32
|
+
{
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (typeof node !== 'object' || node === null)
|
|
36
|
+
{
|
|
37
|
+
return JSON.stringify(node);
|
|
38
|
+
}
|
|
39
|
+
if (node instanceof Array)
|
|
40
|
+
{
|
|
41
|
+
const out = [];
|
|
42
|
+
for (let i = 0; i < node.length; i++)
|
|
43
|
+
{
|
|
44
|
+
const item = stringify(node, i, node[i], level+1) || JSON.stringify(null);
|
|
45
|
+
out.push(indent + space + item);
|
|
46
|
+
}
|
|
47
|
+
return '[' + out.join(',') + indent + ']';
|
|
48
|
+
}
|
|
49
|
+
else
|
|
50
|
+
{
|
|
51
|
+
if (seen.has(node))
|
|
52
|
+
{
|
|
53
|
+
if (cycles)
|
|
54
|
+
return JSON.stringify('__cycle__');
|
|
55
|
+
throw new TypeError('Converting circular structure to JSON');
|
|
56
|
+
}
|
|
57
|
+
else
|
|
58
|
+
seen.set(node, true);
|
|
59
|
+
const keys = Object.keys(node).sort(cmp && cmp(node));
|
|
60
|
+
const out = [];
|
|
61
|
+
for (let i = 0; i < keys.length; i++)
|
|
62
|
+
{
|
|
63
|
+
const key = keys[i];
|
|
64
|
+
const value = stringify(node, key, node[key], level+1);
|
|
65
|
+
if (!value)
|
|
66
|
+
continue;
|
|
67
|
+
const keyValue = JSON.stringify(key)
|
|
68
|
+
+ colonSeparator
|
|
69
|
+
+ value;
|
|
70
|
+
out.push(indent + space + keyValue);
|
|
71
|
+
}
|
|
72
|
+
seen.delete(node);
|
|
73
|
+
return '{' + out.join(',') + indent + '}';
|
|
74
|
+
}
|
|
75
|
+
})({ '': obj }, '', obj, 0);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
module.exports = stableStringify;
|