Adding tests and fixing stuff
This commit is contained in:
parent
cf1347ca3a
commit
f3f3d250b4
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,2 @@
|
||||
node_modules/
|
||||
testrepo/
|
||||
testrepo_*
|
@ -4,14 +4,19 @@
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev": "nodemon -e ts --exec ts-node src/test.ts",
|
||||
"dev": "nodemon -e ts --exec npm run test",
|
||||
"test": "mocha --require ts-node/register src/test.ts",
|
||||
"build": "tsc"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.2.21",
|
||||
"@types/mocha": "^9.0.0",
|
||||
"@types/node": "^16.4.13",
|
||||
"chai": "^4.3.4",
|
||||
"mocha": "^9.0.3",
|
||||
"nodemon": "^2.0.12",
|
||||
"ts-node": "^10.2.0",
|
||||
"typescript": "^4.3.5"
|
||||
@ -19,4 +24,4 @@
|
||||
"dependencies": {
|
||||
"jssha": "^3.2.0"
|
||||
}
|
||||
}
|
||||
}
|
401
pnpm-lock.yaml
401
pnpm-lock.yaml
@ -1,8 +1,12 @@
|
||||
lockfileVersion: 5.3
|
||||
|
||||
specifiers:
|
||||
'@types/chai': ^4.2.21
|
||||
'@types/mocha': ^9.0.0
|
||||
'@types/node': ^16.4.13
|
||||
chai: ^4.3.4
|
||||
jssha: ^3.2.0
|
||||
mocha: ^9.0.3
|
||||
nodemon: ^2.0.12
|
||||
ts-node: ^10.2.0
|
||||
typescript: ^4.3.5
|
||||
@ -11,7 +15,11 @@ dependencies:
|
||||
jssha: 3.2.0
|
||||
|
||||
devDependencies:
|
||||
'@types/chai': 4.2.21
|
||||
'@types/mocha': 9.0.0
|
||||
'@types/node': 16.4.13
|
||||
chai: 4.3.4
|
||||
mocha: 9.0.3
|
||||
nodemon: 2.0.12
|
||||
ts-node: 10.2.0_dea0625f6d31b223e93dc3dc354b8b43
|
||||
typescript: 4.3.5
|
||||
@ -58,10 +66,22 @@ packages:
|
||||
resolution: {integrity: sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==}
|
||||
dev: true
|
||||
|
||||
/@types/chai/4.2.21:
|
||||
resolution: {integrity: sha512-yd+9qKmJxm496BOV9CMNaey8TWsikaZOwMRwPHQIjcOJM9oV+fi9ZMNw3JsVnbEEbo2gRTDnGEBv8pjyn67hNg==}
|
||||
dev: true
|
||||
|
||||
/@types/mocha/9.0.0:
|
||||
resolution: {integrity: sha512-scN0hAWyLVAvLR9AyW7HoFF5sJZglyBsbPuHO4fv7JRvfmPBMfp1ozWqOf/e4wwPNxezBZXRfWzMb6iFLgEVRA==}
|
||||
dev: true
|
||||
|
||||
/@types/node/16.4.13:
|
||||
resolution: {integrity: sha512-bLL69sKtd25w7p1nvg9pigE4gtKVpGTPojBFLMkGHXuUgap2sLqQt2qUnqmVCDfzGUL0DRNZP+1prIZJbMeAXg==}
|
||||
dev: true
|
||||
|
||||
/@ungap/promise-all-settled/1.1.2:
|
||||
resolution: {integrity: sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==}
|
||||
dev: true
|
||||
|
||||
/abbrev/1.1.1:
|
||||
resolution: {integrity: sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==}
|
||||
dev: true
|
||||
@ -83,6 +103,16 @@ packages:
|
||||
string-width: 3.1.0
|
||||
dev: true
|
||||
|
||||
/ansi-colors/4.1.1:
|
||||
resolution: {integrity: sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==}
|
||||
engines: {node: '>=6'}
|
||||
dev: true
|
||||
|
||||
/ansi-regex/3.0.0:
|
||||
resolution: {integrity: sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=}
|
||||
engines: {node: '>=4'}
|
||||
dev: true
|
||||
|
||||
/ansi-regex/4.1.0:
|
||||
resolution: {integrity: sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==}
|
||||
engines: {node: '>=6'}
|
||||
@ -112,6 +142,14 @@ packages:
|
||||
resolution: {integrity: sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==}
|
||||
dev: true
|
||||
|
||||
/argparse/2.0.1:
|
||||
resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==}
|
||||
dev: true
|
||||
|
||||
/assertion-error/1.1.0:
|
||||
resolution: {integrity: sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==}
|
||||
dev: true
|
||||
|
||||
/balanced-match/1.0.2:
|
||||
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
|
||||
dev: true
|
||||
@ -149,6 +187,10 @@ packages:
|
||||
fill-range: 7.0.1
|
||||
dev: true
|
||||
|
||||
/browser-stdout/1.3.1:
|
||||
resolution: {integrity: sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==}
|
||||
dev: true
|
||||
|
||||
/cacheable-request/6.1.0:
|
||||
resolution: {integrity: sha512-Oj3cAGPCqOZX7Rz64Uny2GYAZNliQSqfbePrgAQ1wKAihYmCUnraBtJtKcGR4xz7wF+LoJC+ssFZvv5BgF9Igg==}
|
||||
engines: {node: '>=8'}
|
||||
@ -167,6 +209,23 @@ packages:
|
||||
engines: {node: '>=6'}
|
||||
dev: true
|
||||
|
||||
/camelcase/6.2.0:
|
||||
resolution: {integrity: sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg==}
|
||||
engines: {node: '>=10'}
|
||||
dev: true
|
||||
|
||||
/chai/4.3.4:
|
||||
resolution: {integrity: sha512-yS5H68VYOCtN1cjfwumDSuzn/9c+yza4f3reKXlE5rUg7SFcCEy90gJvydNgOYtblyf4Zi6jIWRnXOgErta0KA==}
|
||||
engines: {node: '>=4'}
|
||||
dependencies:
|
||||
assertion-error: 1.1.0
|
||||
check-error: 1.0.2
|
||||
deep-eql: 3.0.1
|
||||
get-func-name: 2.0.0
|
||||
pathval: 1.1.1
|
||||
type-detect: 4.0.8
|
||||
dev: true
|
||||
|
||||
/chalk/3.0.0:
|
||||
resolution: {integrity: sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==}
|
||||
engines: {node: '>=8'}
|
||||
@ -175,6 +234,18 @@ packages:
|
||||
supports-color: 7.2.0
|
||||
dev: true
|
||||
|
||||
/chalk/4.1.2:
|
||||
resolution: {integrity: sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==}
|
||||
engines: {node: '>=10'}
|
||||
dependencies:
|
||||
ansi-styles: 4.3.0
|
||||
supports-color: 7.2.0
|
||||
dev: true
|
||||
|
||||
/check-error/1.0.2:
|
||||
resolution: {integrity: sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=}
|
||||
dev: true
|
||||
|
||||
/chokidar/3.5.2:
|
||||
resolution: {integrity: sha512-ekGhOnNVPgT77r4K/U3GDhu+FQ2S8TnK/s2KbIGXi0SZWuwkZ2QNyfWdZW+TVfn84DpEP7rLeCt2UI6bJ8GwbQ==}
|
||||
engines: {node: '>= 8.10.0'}
|
||||
@ -199,6 +270,14 @@ packages:
|
||||
engines: {node: '>=6'}
|
||||
dev: true
|
||||
|
||||
/cliui/7.0.4:
|
||||
resolution: {integrity: sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==}
|
||||
dependencies:
|
||||
string-width: 4.2.2
|
||||
strip-ansi: 6.0.0
|
||||
wrap-ansi: 7.0.0
|
||||
dev: true
|
||||
|
||||
/clone-response/1.0.2:
|
||||
resolution: {integrity: sha1-0dyXOSAxTfZ/vrlCI7TuNQI56Ws=}
|
||||
dependencies:
|
||||
@ -253,6 +332,24 @@ packages:
|
||||
ms: 2.1.3
|
||||
dev: true
|
||||
|
||||
/debug/4.3.1_supports-color@8.1.1:
|
||||
resolution: {integrity: sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==}
|
||||
engines: {node: '>=6.0'}
|
||||
peerDependencies:
|
||||
supports-color: '*'
|
||||
peerDependenciesMeta:
|
||||
supports-color:
|
||||
optional: true
|
||||
dependencies:
|
||||
ms: 2.1.2
|
||||
supports-color: 8.1.1
|
||||
dev: true
|
||||
|
||||
/decamelize/4.0.0:
|
||||
resolution: {integrity: sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==}
|
||||
engines: {node: '>=10'}
|
||||
dev: true
|
||||
|
||||
/decompress-response/3.3.0:
|
||||
resolution: {integrity: sha1-gKTdMjdIOEv6JICDYirt7Jgq3/M=}
|
||||
engines: {node: '>=4'}
|
||||
@ -260,6 +357,13 @@ packages:
|
||||
mimic-response: 1.0.1
|
||||
dev: true
|
||||
|
||||
/deep-eql/3.0.1:
|
||||
resolution: {integrity: sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==}
|
||||
engines: {node: '>=0.12'}
|
||||
dependencies:
|
||||
type-detect: 4.0.8
|
||||
dev: true
|
||||
|
||||
/deep-extend/0.6.0:
|
||||
resolution: {integrity: sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==}
|
||||
engines: {node: '>=4.0.0'}
|
||||
@ -274,6 +378,11 @@ packages:
|
||||
engines: {node: '>=0.3.1'}
|
||||
dev: true
|
||||
|
||||
/diff/5.0.0:
|
||||
resolution: {integrity: sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==}
|
||||
engines: {node: '>=0.3.1'}
|
||||
dev: true
|
||||
|
||||
/dot-prop/5.3.0:
|
||||
resolution: {integrity: sha512-QM8q3zDe58hqUqjraQOmzZ1LIH9SWQJTlEKCH4kJ2oQvLZk7RbQXvtDM2XEq3fwkV9CCvvH4LA0AV+ogFsBM2Q==}
|
||||
engines: {node: '>=8'}
|
||||
@ -299,11 +408,21 @@ packages:
|
||||
once: 1.4.0
|
||||
dev: true
|
||||
|
||||
/escalade/3.1.1:
|
||||
resolution: {integrity: sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==}
|
||||
engines: {node: '>=6'}
|
||||
dev: true
|
||||
|
||||
/escape-goat/2.1.1:
|
||||
resolution: {integrity: sha512-8/uIhbG12Csjy2JEW7D9pHbreaVaS/OpN3ycnyvElTdwM5n6GY6W6e2IPemfvGZeUMqZ9A/3GqIZMgKnBhAw/Q==}
|
||||
engines: {node: '>=8'}
|
||||
dev: true
|
||||
|
||||
/escape-string-regexp/4.0.0:
|
||||
resolution: {integrity: sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==}
|
||||
engines: {node: '>=10'}
|
||||
dev: true
|
||||
|
||||
/fill-range/7.0.1:
|
||||
resolution: {integrity: sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==}
|
||||
engines: {node: '>=8'}
|
||||
@ -311,6 +430,23 @@ packages:
|
||||
to-regex-range: 5.0.1
|
||||
dev: true
|
||||
|
||||
/find-up/5.0.0:
|
||||
resolution: {integrity: sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==}
|
||||
engines: {node: '>=10'}
|
||||
dependencies:
|
||||
locate-path: 6.0.0
|
||||
path-exists: 4.0.0
|
||||
dev: true
|
||||
|
||||
/flat/5.0.2:
|
||||
resolution: {integrity: sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==}
|
||||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/fs.realpath/1.0.0:
|
||||
resolution: {integrity: sha1-FQStJSMVjKpA20onh8sBQRmU6k8=}
|
||||
dev: true
|
||||
|
||||
/fsevents/2.3.2:
|
||||
resolution: {integrity: sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==}
|
||||
engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0}
|
||||
@ -318,6 +454,15 @@ packages:
|
||||
dev: true
|
||||
optional: true
|
||||
|
||||
/get-caller-file/2.0.5:
|
||||
resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==}
|
||||
engines: {node: 6.* || 8.* || >= 10.*}
|
||||
dev: true
|
||||
|
||||
/get-func-name/2.0.0:
|
||||
resolution: {integrity: sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=}
|
||||
dev: true
|
||||
|
||||
/get-stream/4.1.0:
|
||||
resolution: {integrity: sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==}
|
||||
engines: {node: '>=6'}
|
||||
@ -339,6 +484,17 @@ packages:
|
||||
is-glob: 4.0.1
|
||||
dev: true
|
||||
|
||||
/glob/7.1.7:
|
||||
resolution: {integrity: sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ==}
|
||||
dependencies:
|
||||
fs.realpath: 1.0.0
|
||||
inflight: 1.0.6
|
||||
inherits: 2.0.4
|
||||
minimatch: 3.0.4
|
||||
once: 1.4.0
|
||||
path-is-absolute: 1.0.1
|
||||
dev: true
|
||||
|
||||
/global-dirs/2.1.0:
|
||||
resolution: {integrity: sha512-MG6kdOUh/xBnyo9cJFeIKkLEc1AyFq42QTU4XiX51i2NEdxLxLWXIjEjmqKeSuKR7pAZjTqUVoT2b2huxVLgYQ==}
|
||||
engines: {node: '>=8'}
|
||||
@ -367,6 +523,11 @@ packages:
|
||||
resolution: {integrity: sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==}
|
||||
dev: true
|
||||
|
||||
/growl/1.10.5:
|
||||
resolution: {integrity: sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==}
|
||||
engines: {node: '>=4.x'}
|
||||
dev: true
|
||||
|
||||
/has-flag/3.0.0:
|
||||
resolution: {integrity: sha1-tdRU3CGZriJWmfNGfloH87lVuv0=}
|
||||
engines: {node: '>=4'}
|
||||
@ -382,6 +543,11 @@ packages:
|
||||
engines: {node: '>=8'}
|
||||
dev: true
|
||||
|
||||
/he/1.2.0:
|
||||
resolution: {integrity: sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==}
|
||||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/http-cache-semantics/4.1.0:
|
||||
resolution: {integrity: sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ==}
|
||||
dev: true
|
||||
@ -400,6 +566,17 @@ packages:
|
||||
engines: {node: '>=0.8.19'}
|
||||
dev: true
|
||||
|
||||
/inflight/1.0.6:
|
||||
resolution: {integrity: sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=}
|
||||
dependencies:
|
||||
once: 1.4.0
|
||||
wrappy: 1.0.2
|
||||
dev: true
|
||||
|
||||
/inherits/2.0.4:
|
||||
resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==}
|
||||
dev: true
|
||||
|
||||
/ini/1.3.7:
|
||||
resolution: {integrity: sha512-iKpRpXP+CrP2jyrxvg1kMUpXDyRUFDWurxbnVT1vQPx+Wz9uCYsMIqYuSBLV+PAaZG/d7kRLKRFc9oDMsH+mFQ==}
|
||||
dev: true
|
||||
@ -472,14 +649,35 @@ packages:
|
||||
engines: {node: '>=8'}
|
||||
dev: true
|
||||
|
||||
/is-plain-obj/2.1.0:
|
||||
resolution: {integrity: sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==}
|
||||
engines: {node: '>=8'}
|
||||
dev: true
|
||||
|
||||
/is-typedarray/1.0.0:
|
||||
resolution: {integrity: sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=}
|
||||
dev: true
|
||||
|
||||
/is-unicode-supported/0.1.0:
|
||||
resolution: {integrity: sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==}
|
||||
engines: {node: '>=10'}
|
||||
dev: true
|
||||
|
||||
/is-yarn-global/0.3.0:
|
||||
resolution: {integrity: sha512-VjSeb/lHmkoyd8ryPVIKvOCn4D1koMqY+vqyjjUfc3xyKtP4dYOxM44sZrnqQSzSds3xyOrUTLTC9LVCVgLngw==}
|
||||
dev: true
|
||||
|
||||
/isexe/2.0.0:
|
||||
resolution: {integrity: sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=}
|
||||
dev: true
|
||||
|
||||
/js-yaml/4.1.0:
|
||||
resolution: {integrity: sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==}
|
||||
hasBin: true
|
||||
dependencies:
|
||||
argparse: 2.0.1
|
||||
dev: true
|
||||
|
||||
/json-buffer/3.0.0:
|
||||
resolution: {integrity: sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg=}
|
||||
dev: true
|
||||
@ -501,6 +699,21 @@ packages:
|
||||
package-json: 6.5.0
|
||||
dev: true
|
||||
|
||||
/locate-path/6.0.0:
|
||||
resolution: {integrity: sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==}
|
||||
engines: {node: '>=10'}
|
||||
dependencies:
|
||||
p-locate: 5.0.0
|
||||
dev: true
|
||||
|
||||
/log-symbols/4.1.0:
|
||||
resolution: {integrity: sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==}
|
||||
engines: {node: '>=10'}
|
||||
dependencies:
|
||||
chalk: 4.1.2
|
||||
is-unicode-supported: 0.1.0
|
||||
dev: true
|
||||
|
||||
/lowercase-keys/1.0.1:
|
||||
resolution: {integrity: sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
@ -537,14 +750,56 @@ packages:
|
||||
resolution: {integrity: sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==}
|
||||
dev: true
|
||||
|
||||
/mocha/9.0.3:
|
||||
resolution: {integrity: sha512-hnYFrSefHxYS2XFGtN01x8un0EwNu2bzKvhpRFhgoybIvMaOkkL60IVPmkb5h6XDmUl4IMSB+rT5cIO4/4bJgg==}
|
||||
engines: {node: '>= 12.0.0'}
|
||||
hasBin: true
|
||||
dependencies:
|
||||
'@ungap/promise-all-settled': 1.1.2
|
||||
ansi-colors: 4.1.1
|
||||
browser-stdout: 1.3.1
|
||||
chokidar: 3.5.2
|
||||
debug: 4.3.1_supports-color@8.1.1
|
||||
diff: 5.0.0
|
||||
escape-string-regexp: 4.0.0
|
||||
find-up: 5.0.0
|
||||
glob: 7.1.7
|
||||
growl: 1.10.5
|
||||
he: 1.2.0
|
||||
js-yaml: 4.1.0
|
||||
log-symbols: 4.1.0
|
||||
minimatch: 3.0.4
|
||||
ms: 2.1.3
|
||||
nanoid: 3.1.23
|
||||
serialize-javascript: 6.0.0
|
||||
strip-json-comments: 3.1.1
|
||||
supports-color: 8.1.1
|
||||
which: 2.0.2
|
||||
wide-align: 1.1.3
|
||||
workerpool: 6.1.5
|
||||
yargs: 16.2.0
|
||||
yargs-parser: 20.2.4
|
||||
yargs-unparser: 2.0.0
|
||||
dev: true
|
||||
|
||||
/ms/2.0.0:
|
||||
resolution: {integrity: sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=}
|
||||
dev: true
|
||||
|
||||
/ms/2.1.2:
|
||||
resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==}
|
||||
dev: true
|
||||
|
||||
/ms/2.1.3:
|
||||
resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==}
|
||||
dev: true
|
||||
|
||||
/nanoid/3.1.23:
|
||||
resolution: {integrity: sha512-FiB0kzdP0FFVGDKlRLEQ1BgDzU87dy5NnzjeW9YZNt+/c3+q82EQDUwniSAUxp/F0gFNI1ZhKU1FqYsMuqZVnw==}
|
||||
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
|
||||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/nodemon/2.0.12:
|
||||
resolution: {integrity: sha512-egCTmNZdObdBxUBw6ZNwvZ/xzk24CKRs5K6d+5zbmrMr7rOpPmfPeF6OxM3DDpaRx331CQRFEktn+wrFFfBSOA==}
|
||||
engines: {node: '>=8.10.0'}
|
||||
@ -591,6 +846,20 @@ packages:
|
||||
engines: {node: '>=6'}
|
||||
dev: true
|
||||
|
||||
/p-limit/3.1.0:
|
||||
resolution: {integrity: sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==}
|
||||
engines: {node: '>=10'}
|
||||
dependencies:
|
||||
yocto-queue: 0.1.0
|
||||
dev: true
|
||||
|
||||
/p-locate/5.0.0:
|
||||
resolution: {integrity: sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==}
|
||||
engines: {node: '>=10'}
|
||||
dependencies:
|
||||
p-limit: 3.1.0
|
||||
dev: true
|
||||
|
||||
/package-json/6.5.0:
|
||||
resolution: {integrity: sha512-k3bdm2n25tkyxcjSKzB5x8kfVxlMdgsbPr0GkZcwHsLpba6cBjqCt1KlcChKEvxHIcTB1FVMuwoijZ26xex5MQ==}
|
||||
engines: {node: '>=8'}
|
||||
@ -601,6 +870,20 @@ packages:
|
||||
semver: 6.3.0
|
||||
dev: true
|
||||
|
||||
/path-exists/4.0.0:
|
||||
resolution: {integrity: sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==}
|
||||
engines: {node: '>=8'}
|
||||
dev: true
|
||||
|
||||
/path-is-absolute/1.0.1:
|
||||
resolution: {integrity: sha1-F0uSaHNVNP+8es5r9TpanhtcX18=}
|
||||
engines: {node: '>=0.10.0'}
|
||||
dev: true
|
||||
|
||||
/pathval/1.1.1:
|
||||
resolution: {integrity: sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==}
|
||||
dev: true
|
||||
|
||||
/picomatch/2.3.0:
|
||||
resolution: {integrity: sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==}
|
||||
engines: {node: '>=8.6'}
|
||||
@ -629,6 +912,12 @@ packages:
|
||||
escape-goat: 2.1.1
|
||||
dev: true
|
||||
|
||||
/randombytes/2.1.0:
|
||||
resolution: {integrity: sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==}
|
||||
dependencies:
|
||||
safe-buffer: 5.2.1
|
||||
dev: true
|
||||
|
||||
/rc/1.2.8:
|
||||
resolution: {integrity: sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==}
|
||||
hasBin: true
|
||||
@ -660,12 +949,21 @@ packages:
|
||||
rc: 1.2.8
|
||||
dev: true
|
||||
|
||||
/require-directory/2.1.1:
|
||||
resolution: {integrity: sha1-jGStX9MNqxyXbiNE/+f3kqam30I=}
|
||||
engines: {node: '>=0.10.0'}
|
||||
dev: true
|
||||
|
||||
/responselike/1.0.2:
|
||||
resolution: {integrity: sha1-kYcg7ztjHFZCvgaPFa3lpG9Loec=}
|
||||
dependencies:
|
||||
lowercase-keys: 1.0.1
|
||||
dev: true
|
||||
|
||||
/safe-buffer/5.2.1:
|
||||
resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==}
|
||||
dev: true
|
||||
|
||||
/semver-diff/3.1.1:
|
||||
resolution: {integrity: sha512-GX0Ix/CJcHyB8c4ykpHGIAvLyOwOobtM/8d+TQkAd81/bEjgPHrfba41Vpesr7jX/t8Uh+R3EX9eAS5be+jQYg==}
|
||||
engines: {node: '>=8'}
|
||||
@ -683,10 +981,24 @@ packages:
|
||||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/serialize-javascript/6.0.0:
|
||||
resolution: {integrity: sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==}
|
||||
dependencies:
|
||||
randombytes: 2.1.0
|
||||
dev: true
|
||||
|
||||
/signal-exit/3.0.3:
|
||||
resolution: {integrity: sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==}
|
||||
dev: true
|
||||
|
||||
/string-width/2.1.1:
|
||||
resolution: {integrity: sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==}
|
||||
engines: {node: '>=4'}
|
||||
dependencies:
|
||||
is-fullwidth-code-point: 2.0.0
|
||||
strip-ansi: 4.0.0
|
||||
dev: true
|
||||
|
||||
/string-width/3.1.0:
|
||||
resolution: {integrity: sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==}
|
||||
engines: {node: '>=6'}
|
||||
@ -705,6 +1017,13 @@ packages:
|
||||
strip-ansi: 6.0.0
|
||||
dev: true
|
||||
|
||||
/strip-ansi/4.0.0:
|
||||
resolution: {integrity: sha1-qEeQIusaw2iocTibY1JixQXuNo8=}
|
||||
engines: {node: '>=4'}
|
||||
dependencies:
|
||||
ansi-regex: 3.0.0
|
||||
dev: true
|
||||
|
||||
/strip-ansi/5.2.0:
|
||||
resolution: {integrity: sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==}
|
||||
engines: {node: '>=6'}
|
||||
@ -724,6 +1043,11 @@ packages:
|
||||
engines: {node: '>=0.10.0'}
|
||||
dev: true
|
||||
|
||||
/strip-json-comments/3.1.1:
|
||||
resolution: {integrity: sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==}
|
||||
engines: {node: '>=8'}
|
||||
dev: true
|
||||
|
||||
/supports-color/5.5.0:
|
||||
resolution: {integrity: sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==}
|
||||
engines: {node: '>=4'}
|
||||
@ -738,6 +1062,13 @@ packages:
|
||||
has-flag: 4.0.0
|
||||
dev: true
|
||||
|
||||
/supports-color/8.1.1:
|
||||
resolution: {integrity: sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==}
|
||||
engines: {node: '>=10'}
|
||||
dependencies:
|
||||
has-flag: 4.0.0
|
||||
dev: true
|
||||
|
||||
/term-size/2.2.1:
|
||||
resolution: {integrity: sha512-wK0Ri4fOGjv/XPy8SBHZChl8CM7uMc5VML7SqiQ0zG7+J5Vr+RMQDoHa2CNT6KHUnTGIXH34UDMkPzAUyapBZg==}
|
||||
engines: {node: '>=8'}
|
||||
@ -793,6 +1124,11 @@ packages:
|
||||
yn: 3.1.1
|
||||
dev: true
|
||||
|
||||
/type-detect/4.0.8:
|
||||
resolution: {integrity: sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==}
|
||||
engines: {node: '>=4'}
|
||||
dev: true
|
||||
|
||||
/type-fest/0.8.1:
|
||||
resolution: {integrity: sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==}
|
||||
engines: {node: '>=8'}
|
||||
@ -849,6 +1185,20 @@ packages:
|
||||
prepend-http: 2.0.0
|
||||
dev: true
|
||||
|
||||
/which/2.0.2:
|
||||
resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==}
|
||||
engines: {node: '>= 8'}
|
||||
hasBin: true
|
||||
dependencies:
|
||||
isexe: 2.0.0
|
||||
dev: true
|
||||
|
||||
/wide-align/1.1.3:
|
||||
resolution: {integrity: sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA==}
|
||||
dependencies:
|
||||
string-width: 2.1.1
|
||||
dev: true
|
||||
|
||||
/widest-line/3.1.0:
|
||||
resolution: {integrity: sha512-NsmoXalsWVDMGupxZ5R08ka9flZjjiLvHVAWYOKtiKM8ujtZWr9cRffak+uSE48+Ob8ObalXpwyeUiyDD6QFgg==}
|
||||
engines: {node: '>=8'}
|
||||
@ -856,6 +1206,19 @@ packages:
|
||||
string-width: 4.2.2
|
||||
dev: true
|
||||
|
||||
/workerpool/6.1.5:
|
||||
resolution: {integrity: sha512-XdKkCK0Zqc6w3iTxLckiuJ81tiD/o5rBE/m+nXpRCB+/Sq4DqkfXZ/x0jW02DG1tGsfUGXbTJyZDP+eu67haSw==}
|
||||
dev: true
|
||||
|
||||
/wrap-ansi/7.0.0:
|
||||
resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==}
|
||||
engines: {node: '>=10'}
|
||||
dependencies:
|
||||
ansi-styles: 4.3.0
|
||||
string-width: 4.2.2
|
||||
strip-ansi: 6.0.0
|
||||
dev: true
|
||||
|
||||
/wrappy/1.0.2:
|
||||
resolution: {integrity: sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=}
|
||||
dev: true
|
||||
@ -874,7 +1237,45 @@ packages:
|
||||
engines: {node: '>=8'}
|
||||
dev: true
|
||||
|
||||
/y18n/5.0.8:
|
||||
resolution: {integrity: sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==}
|
||||
engines: {node: '>=10'}
|
||||
dev: true
|
||||
|
||||
/yargs-parser/20.2.4:
|
||||
resolution: {integrity: sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==}
|
||||
engines: {node: '>=10'}
|
||||
dev: true
|
||||
|
||||
/yargs-unparser/2.0.0:
|
||||
resolution: {integrity: sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA==}
|
||||
engines: {node: '>=10'}
|
||||
dependencies:
|
||||
camelcase: 6.2.0
|
||||
decamelize: 4.0.0
|
||||
flat: 5.0.2
|
||||
is-plain-obj: 2.1.0
|
||||
dev: true
|
||||
|
||||
/yargs/16.2.0:
|
||||
resolution: {integrity: sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==}
|
||||
engines: {node: '>=10'}
|
||||
dependencies:
|
||||
cliui: 7.0.4
|
||||
escalade: 3.1.1
|
||||
get-caller-file: 2.0.5
|
||||
require-directory: 2.1.1
|
||||
string-width: 4.2.2
|
||||
y18n: 5.0.8
|
||||
yargs-parser: 20.2.4
|
||||
dev: true
|
||||
|
||||
/yn/3.1.1:
|
||||
resolution: {integrity: sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==}
|
||||
engines: {node: '>=6'}
|
||||
dev: true
|
||||
|
||||
/yocto-queue/0.1.0:
|
||||
resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==}
|
||||
engines: {node: '>=10'}
|
||||
dev: true
|
||||
|
@ -10,6 +10,8 @@ export default class FSDataStore implements IDataStore {
|
||||
}
|
||||
|
||||
async get(name: string) {
|
||||
if (!await this.has(name))
|
||||
return undefined;
|
||||
return Fs.promises.readFile(Path.join(this.#path, name));
|
||||
}
|
||||
|
||||
@ -34,11 +36,11 @@ export default class FSDataStore implements IDataStore {
|
||||
//TODO: This is not atomic yet! FIX
|
||||
while ((await this.has("lock")) || this.#l) {
|
||||
try {
|
||||
let con = (await this.get("lock")).toString("utf-8");
|
||||
let con = (await this.get("lock") as Buffer).toString("utf-8");
|
||||
|
||||
if (Number(con) < Date.now() - 10000) break;
|
||||
await new Promise((y) => setTimeout(y, 10));
|
||||
} catch (err) {}
|
||||
} catch (err) { }
|
||||
}
|
||||
this.#l = true;
|
||||
|
||||
|
291
src/repo.ts
291
src/repo.ts
@ -2,7 +2,7 @@ import SHA from "jssha";
|
||||
import Path from "./helper/path";
|
||||
|
||||
export interface IDataStore {
|
||||
get(key: string): Promise<Uint8Array>;
|
||||
get(key: string): Promise<Uint8Array | undefined>;
|
||||
set(key: string, data: Uint8Array): Promise<void>;
|
||||
has(key: string): Promise<boolean>;
|
||||
close?: () => Promise<void>;
|
||||
@ -22,6 +22,14 @@ export type Commit = {
|
||||
date: Date;
|
||||
};
|
||||
|
||||
export type NodeLog = {
|
||||
/**
|
||||
* ObjectID of the data. Can be undefined if element was deleted!
|
||||
*/
|
||||
id: string | undefined;
|
||||
commit: Commit
|
||||
}
|
||||
|
||||
// TODOs:
|
||||
// - HEAD locks
|
||||
// - HEAD/Tree Cache
|
||||
@ -29,12 +37,16 @@ export type Commit = {
|
||||
// - Add DataStore Locking for access from multiple sources
|
||||
|
||||
export default class Repository {
|
||||
//#region local variables
|
||||
#store: IDataStore;
|
||||
//#endregion
|
||||
|
||||
constructor(store: IDataStore) {
|
||||
this.#store = store;
|
||||
}
|
||||
|
||||
//#region private
|
||||
|
||||
private sha1(data: Uint8Array) {
|
||||
const s = new SHA("SHA-1", "UINT8ARRAY");
|
||||
s.update(data);
|
||||
@ -50,11 +62,9 @@ export default class Repository {
|
||||
private splitPath(path: string) {
|
||||
const resolved = Path.resolve(path).slice(1);
|
||||
if (resolved == "") return [];
|
||||
return resolved.split(Path.delimiter);
|
||||
return resolved.split(Path.sep);
|
||||
}
|
||||
|
||||
private getHeadLock() {}
|
||||
|
||||
private async writeObject(data: Uint8Array | string): Promise<string> {
|
||||
if (typeof data == "string") {
|
||||
data = new TextEncoder().encode(data);
|
||||
@ -68,9 +78,9 @@ export default class Repository {
|
||||
return this.#store.has("objects/" + id);
|
||||
}
|
||||
|
||||
private async readObject(id: string, string: true): Promise<string>;
|
||||
private async readObject(id: string, string?: false): Promise<Uint8Array>;
|
||||
private async readObject(id: string, string = false): Promise<Uint8Array | string> {
|
||||
private async readObject(id: string, string: true): Promise<string | undefined>;
|
||||
private async readObject(id: string, string?: false): Promise<Uint8Array | undefined>;
|
||||
private async readObject(id: string, string = false): Promise<Uint8Array | string | undefined> {
|
||||
let data = await this.#store.get("objects/" + id);
|
||||
if (string) {
|
||||
return new TextDecoder().decode(data);
|
||||
@ -79,94 +89,7 @@ export default class Repository {
|
||||
}
|
||||
}
|
||||
|
||||
async clean() {
|
||||
// TODO: Cleanup broken things
|
||||
}
|
||||
|
||||
async readdir(path: string): Promise<TreeEntry[] | undefined> {
|
||||
const parts = this.splitPath(path);
|
||||
console.log({ parts });
|
||||
const head = await this.readHead();
|
||||
if (!head) return undefined;
|
||||
|
||||
const treeID = await this.treeFindObjectID(head.root, parts, "tree");
|
||||
|
||||
if (!treeID) return undefined;
|
||||
|
||||
return this.readTree(treeID);
|
||||
}
|
||||
|
||||
async read(path: string): Promise<Uint8Array | undefined> {
|
||||
const parts = this.splitPath(path);
|
||||
const head = await this.readHead();
|
||||
if (!head) return undefined;
|
||||
|
||||
const objectID = await this.treeFindObjectID(head.root, parts, "blob");
|
||||
|
||||
if (!objectID) return undefined;
|
||||
|
||||
return this.readObject(objectID);
|
||||
}
|
||||
|
||||
async write(path: string, data: Uint8Array) {
|
||||
const parts = this.splitPath(path);
|
||||
|
||||
const objectID = await this.writeObject(data);
|
||||
|
||||
const lock = await this.#store.getLock();
|
||||
try {
|
||||
//TODO: Improve need of locking.
|
||||
const head = await this.readHead();
|
||||
|
||||
const makeTree = async (treeID: string | undefined, parts: string[]) => {
|
||||
let tree: TreeEntry[];
|
||||
if (treeID) {
|
||||
tree = await this.readTree(treeID);
|
||||
} else {
|
||||
tree = [];
|
||||
}
|
||||
|
||||
const current = parts[0];
|
||||
|
||||
let existing = tree.findIndex(([, , name]) => name == current);
|
||||
|
||||
let entry: TreeEntry;
|
||||
|
||||
if (parts.length == 1) {
|
||||
entry = ["blob", objectID, current];
|
||||
} else {
|
||||
entry = [
|
||||
"tree",
|
||||
await makeTree(existing >= 0 ? tree[existing][1] : undefined, parts.slice(1)),
|
||||
current,
|
||||
];
|
||||
}
|
||||
|
||||
if (existing >= 0) {
|
||||
let ex = tree[existing];
|
||||
if (parts.length == 1 && ex[0] == "tree")
|
||||
throw new Error("This change would overwrite a folder!");
|
||||
tree[existing] = entry;
|
||||
} else {
|
||||
tree.push(entry);
|
||||
}
|
||||
|
||||
let treeString = tree.map(([type, hash, name]) => `${type} ${hash} ${name}`).join("\n");
|
||||
|
||||
let newTreeID = await this.writeObject(treeString);
|
||||
|
||||
return newTreeID;
|
||||
};
|
||||
|
||||
let newTree = await makeTree(head?.root, parts);
|
||||
let commit = await this.makeCommit(newTree, head);
|
||||
await this.writeHead(commit);
|
||||
} finally {
|
||||
await lock();
|
||||
}
|
||||
}
|
||||
|
||||
async treeFindObjectID(
|
||||
private async treeFindObjectID(
|
||||
treeID: string,
|
||||
parts: string[],
|
||||
type: NodeType
|
||||
@ -192,9 +115,10 @@ export default class Repository {
|
||||
}
|
||||
}
|
||||
|
||||
async readTree(id: string): Promise<TreeEntry[]> {
|
||||
private async readTree(id: string): Promise<TreeEntry[]> {
|
||||
const tree = await this.readObject(id, true);
|
||||
return tree.split("\n").map((e) => {
|
||||
if (tree == undefined) throw new Error("Invalid treeID");
|
||||
return tree.split("\n").filter(e => e !== "").map((e) => {
|
||||
const entry = e.split(" ") as TreeEntry;
|
||||
const [type] = entry;
|
||||
|
||||
@ -210,7 +134,7 @@ export default class Repository {
|
||||
});
|
||||
}
|
||||
|
||||
async makeCommit(treeID: string, old?: Commit) {
|
||||
private async makeCommit(treeID: string, old?: Commit) {
|
||||
if (!old) {
|
||||
// Could be called once more than necessary, if no HEAD exists.
|
||||
old = await this.readHead();
|
||||
@ -221,10 +145,10 @@ export default class Repository {
|
||||
return await this.writeObject(commitStr);
|
||||
}
|
||||
|
||||
async readCommit(id: string): Promise<Commit> {
|
||||
if (!(await this.hasObject(id))) throw new Error(`Commit with id ${id} not found!`);
|
||||
|
||||
private async readCommit(id: string): Promise<Commit> {
|
||||
const commitStr = await this.readObject(id, true);
|
||||
if (!commitStr)
|
||||
throw new Error(`Commit with id ${id} not found!`);
|
||||
|
||||
let commit: Commit = { id } as any;
|
||||
for (const entry of commitStr.split("\n")) {
|
||||
@ -236,8 +160,10 @@ export default class Repository {
|
||||
break;
|
||||
case "before": // TODO: Simple validity checks
|
||||
commit.before = value;
|
||||
break;
|
||||
case "date":
|
||||
commit.date = new Date(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -248,18 +174,177 @@ export default class Repository {
|
||||
return commit;
|
||||
}
|
||||
|
||||
async readHead(): Promise<Commit | undefined> {
|
||||
private async readHead(): Promise<Commit | undefined> {
|
||||
if (!(await this.#store.has("HEAD"))) return undefined;
|
||||
const head = new TextDecoder().decode(await this.#store.get("HEAD"));
|
||||
|
||||
return this.readCommit(head);
|
||||
}
|
||||
|
||||
async writeHead(commitID: string): Promise<void> {
|
||||
private async writeHead(commitID: string): Promise<void> {
|
||||
await this.#store.set("HEAD", new TextEncoder().encode(commitID));
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
|
||||
//#region public
|
||||
async clean() {
|
||||
// TODO: Cleanup broken things
|
||||
}
|
||||
|
||||
async readdir(path: string): Promise<TreeEntry[]> {
|
||||
const parts = this.splitPath(path);
|
||||
const head = await this.readHead();
|
||||
if (!head) return [];
|
||||
|
||||
const treeID = await this.treeFindObjectID(head.root, parts, "tree");
|
||||
|
||||
if (!treeID) return [];
|
||||
|
||||
return this.readTree(treeID);
|
||||
}
|
||||
|
||||
async read(path: string): Promise<Uint8Array | undefined> {
|
||||
const parts = this.splitPath(path);
|
||||
const head = await this.readHead();
|
||||
if (!head) return undefined;
|
||||
|
||||
const objectID = await this.treeFindObjectID(head.root, parts, "blob");
|
||||
|
||||
if (!objectID) return undefined;
|
||||
|
||||
return this.readObject(objectID);
|
||||
}
|
||||
|
||||
async readByID(id: string) {
|
||||
return this.readObject(id);
|
||||
}
|
||||
|
||||
async log(path: string): Promise<any[]> {
|
||||
const parts = this.splitPath(path);
|
||||
const head = await this.readHead();
|
||||
if (!head) return [];
|
||||
|
||||
let currObjectID = await this.treeFindObjectID(head.root, parts, "blob");
|
||||
|
||||
let history: NodeLog[] = [];
|
||||
|
||||
if (currObjectID) {
|
||||
history.push({
|
||||
id: currObjectID,
|
||||
commit: head
|
||||
})
|
||||
}
|
||||
|
||||
let currCommit = head.before;
|
||||
|
||||
while (currCommit !== undefined) {
|
||||
try {
|
||||
let commit = await this.readCommit(currCommit);
|
||||
let res = await this.treeFindObjectID(commit.root, parts, "blob");
|
||||
if (res !== currObjectID) {
|
||||
history.push({
|
||||
id: res,
|
||||
commit,
|
||||
});
|
||||
}
|
||||
currObjectID = res;
|
||||
currCommit = commit.before;
|
||||
} catch (err) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return history;
|
||||
}
|
||||
|
||||
|
||||
async delete(path: string) {
|
||||
return this.write(path, undefined);
|
||||
}
|
||||
|
||||
async write(path: string, data: Uint8Array | undefined) {
|
||||
const parts = this.splitPath(path);
|
||||
|
||||
let objectID: string | undefined = undefined;
|
||||
if (data) {
|
||||
objectID = await this.writeObject(data);
|
||||
}
|
||||
|
||||
const lock = await this.#store.getLock();
|
||||
//TODO: Improve need of locking.
|
||||
try {
|
||||
const head = await this.readHead();
|
||||
|
||||
const makeTree = async (treeID: string | undefined, parts: string[]) => {
|
||||
let tree: TreeEntry[];
|
||||
if (treeID) {
|
||||
tree = await this.readTree(treeID);
|
||||
} else {
|
||||
tree = [];
|
||||
}
|
||||
|
||||
const current = parts[0];
|
||||
|
||||
let existing = tree.findIndex(([, , name]) => name == current);
|
||||
|
||||
let entry: TreeEntry | undefined = undefined;
|
||||
|
||||
if (parts.length == 1) {
|
||||
if (objectID) {
|
||||
entry = ["blob", objectID, current];
|
||||
}
|
||||
} else {
|
||||
let newTreeID = await makeTree(existing >= 0 ? tree[existing][1] : undefined, parts.slice(1));
|
||||
if (newTreeID) {
|
||||
entry = [
|
||||
"tree",
|
||||
newTreeID,
|
||||
current,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (existing >= 0) {
|
||||
let ex = tree[existing];
|
||||
if (parts.length == 1 && ex[0] == "tree")
|
||||
throw new Error("This change would overwrite a folder!");
|
||||
if (entry)
|
||||
tree[existing] = entry;
|
||||
else {
|
||||
tree = [...tree.slice(0, existing), ...tree.slice(existing + 1)];
|
||||
}
|
||||
} else {
|
||||
if (entry)
|
||||
tree.push(entry);
|
||||
}
|
||||
|
||||
if (tree.length > 0) {
|
||||
let treeString = tree.map(([type, hash, name]) => `${type} ${hash} ${name}`).join("\n");
|
||||
|
||||
let newTreeID = await this.writeObject(treeString);
|
||||
|
||||
return newTreeID;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
let newTree = await makeTree(head?.root, parts);
|
||||
if (!newTree) { //TODO: Is this what i want?
|
||||
newTree = await this.writeObject("");
|
||||
}
|
||||
let commit = await this.makeCommit(newTree, head);
|
||||
await this.writeHead(commit);
|
||||
} finally {
|
||||
await lock();
|
||||
}
|
||||
}
|
||||
|
||||
async close() {
|
||||
if (this.#store.close) return this.#store?.close();
|
||||
}
|
||||
|
||||
//#endregion
|
||||
}
|
||||
|
169
src/test.ts
169
src/test.ts
@ -1,27 +1,164 @@
|
||||
import Repository from "./repo";
|
||||
import Repository, { IDataStore } from "./repo";
|
||||
import FSDataStore from "./datasources/fs";
|
||||
import * as Fs from "fs";
|
||||
import { expect } from "chai";
|
||||
import * as Crypto from "crypto";
|
||||
|
||||
const t = (t: string) => new TextEncoder().encode(t);
|
||||
const td = (t: Uint8Array | undefined) => new TextDecoder().decode(t);
|
||||
const exists = (path: string) => Fs.promises.access(path).then(() => true).catch(() => false)
|
||||
|
||||
async function test() {
|
||||
await Fs.promises.rm("./testrepo", { recursive: true, force: true });
|
||||
const ds = new FSDataStore("./testrepo");
|
||||
const rep = new Repository(ds);
|
||||
let test = 0;
|
||||
let repoPath = "";
|
||||
|
||||
console.log(new TextDecoder().decode(await rep.read("hi.txt")));
|
||||
beforeEach(async () => {
|
||||
repoPath = "./testrepo_" + test;
|
||||
console.log(" \tRunning at repo:", repoPath);
|
||||
await Fs.promises.rm(repoPath, { recursive: true, force: true });
|
||||
})
|
||||
|
||||
await Promise.all([
|
||||
rep.write("hi.txt", t("Hallo Welt: " + new Date().toLocaleString())),
|
||||
rep.write("hi_hallo.txt", t("Hallo Welt: " + new Date().toLocaleString())),
|
||||
rep.write("hi_hallo3.txt", t("Hallo Welt: " + new Date().toLocaleString())),
|
||||
]);
|
||||
afterEach(async () => {
|
||||
test++;
|
||||
})
|
||||
|
||||
console.log(new TextDecoder().decode(await rep.read("hi.txt")));
|
||||
describe("NodeJS DataStore", () => {
|
||||
it("should throw error when creating new instance", () => {
|
||||
const ds = new FSDataStore(repoPath);
|
||||
expect(ds).to.not.be.undefined;
|
||||
})
|
||||
|
||||
console.log((await rep.readdir("/"))?.map((e) => e[2]));
|
||||
it("should return undefined on read on non-existant field", async () => {
|
||||
const ds = new FSDataStore(repoPath);
|
||||
let val = await ds.get("test");
|
||||
expect(val).to.be.undefined;
|
||||
})
|
||||
|
||||
await rep.close();
|
||||
}
|
||||
it("should not fail when writing a new key and create the necessary files", async () => {
|
||||
const ds = new FSDataStore(repoPath);
|
||||
const text = "Hallo Welt";
|
||||
await ds.set("test", t(text));
|
||||
|
||||
test();
|
||||
let ex = await exists(repoPath + "/test");
|
||||
expect(ex).to.be.true;
|
||||
|
||||
let file_cont = await Fs.promises.readFile(repoPath + "/test", "utf-8");
|
||||
expect(file_cont).to.equal(text);
|
||||
})
|
||||
|
||||
it("has should return false on non-existing field", async () => {
|
||||
const ds = new FSDataStore(repoPath);
|
||||
expect(await ds.has("test")).to.be.false;
|
||||
})
|
||||
|
||||
it("has should return true on existing field", async () => {
|
||||
const ds = new FSDataStore(repoPath);
|
||||
const cont = t("Hallo Welt");
|
||||
await ds.set("test", cont);
|
||||
|
||||
let ex = await exists(repoPath + "/test");
|
||||
expect(ex).to.be.true;
|
||||
})
|
||||
|
||||
it("get should return value of existing field", async () => {
|
||||
const ds = new FSDataStore(repoPath);
|
||||
const text = "Hallo Welt";
|
||||
await ds.set("test", t(text));
|
||||
|
||||
expect(td(await ds.get("test"))).to.equal(text);
|
||||
})
|
||||
})
|
||||
|
||||
describe("Basic Repo functions", () => {
|
||||
let ds: IDataStore = new FSDataStore(repoPath);
|
||||
beforeEach(() => {
|
||||
ds = new FSDataStore(repoPath);
|
||||
})
|
||||
|
||||
it("should not throw error when creating new instance", () => {
|
||||
const repo = new Repository(ds)
|
||||
expect(repo).to.not.be.undefined;
|
||||
})
|
||||
|
||||
it("should return an empty list on an empty repository", async () => {
|
||||
const repo = new Repository(ds)
|
||||
const list = await repo.readdir("/");
|
||||
expect(list).to.be.an("array");
|
||||
expect(list.length).to.equal(0)
|
||||
})
|
||||
|
||||
it("should return undefined on non-existant file", async () => {
|
||||
const repo = new Repository(ds)
|
||||
let res = await repo.read("test");
|
||||
expect(res).to.be.undefined;
|
||||
})
|
||||
|
||||
it("should be possible to write data", async () => {
|
||||
const testData = "Hallo Welt";
|
||||
const repo = new Repository(ds)
|
||||
await repo.write("test", t(testData));
|
||||
|
||||
let res = await Fs.promises.readdir(repoPath + "/objects");
|
||||
expect(res.length).to.be.equal(3);
|
||||
|
||||
expect(await exists(repoPath + "/HEAD")).to.be.true;
|
||||
})
|
||||
|
||||
it("should be possible to write nested data", async () => {
|
||||
const testData = "Hallo Welt";
|
||||
const repo = new Repository(ds)
|
||||
await repo.write("test/hallo-welt", t(testData));
|
||||
|
||||
let res = await Fs.promises.readdir(repoPath + "/objects");
|
||||
|
||||
expect(res.length).to.be.equal(4);
|
||||
expect(await exists(repoPath + "/HEAD")).to.be.true;
|
||||
})
|
||||
|
||||
it("readdir should return the given entries", async () => {
|
||||
const testData = "Hallo Welt";
|
||||
const repo = new Repository(ds)
|
||||
await repo.write("test/hallo-welt", t(testData));
|
||||
await repo.write("tests", t(testData));
|
||||
|
||||
const res = await repo.readdir("/")
|
||||
expect(res.length).to.be.equal(2);
|
||||
// expect(res).to.include.
|
||||
})
|
||||
|
||||
it("should be possible to read back written data", async () => {
|
||||
const testData = "Hallo Welt";
|
||||
const repo = new Repository(ds)
|
||||
await repo.write("test", t(testData));
|
||||
|
||||
const res = await repo.read("test");
|
||||
expect(td(res)).to.equal(testData);
|
||||
})
|
||||
|
||||
it("should be possible to delete entries", async () => {
|
||||
const testData = "Hallo Welt";
|
||||
const repo = new Repository(ds)
|
||||
await repo.write("test", t(testData));
|
||||
|
||||
const res = await repo.read("test");
|
||||
expect(td(res)).to.equal(testData);
|
||||
|
||||
await repo.delete("test");
|
||||
|
||||
const res2 = await repo.read("test");
|
||||
expect(res2).to.be.undefined;
|
||||
})
|
||||
|
||||
it("should be possible to get a list of all versions of a file", async () => {
|
||||
const testData = "Hallo Welt";
|
||||
const repo = new Repository(ds)
|
||||
await repo.write("test", t(testData));
|
||||
await repo.write("test", t(testData + 1));
|
||||
await repo.write("test", t(testData + 2));
|
||||
await repo.write("test", t(testData + 3));
|
||||
await repo.write("test", t(testData + 4));
|
||||
|
||||
const res = await repo.log("test");
|
||||
expect(res).to.not.be.undefined;
|
||||
expect(res.length).to.equal(5);
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user