hive-stream 2.0.5 → 3.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 (89) hide show
  1. package/.claude/settings.local.json +12 -0
  2. package/.env.example +2 -2
  3. package/.travis.yml +11 -11
  4. package/CHANGELOG.md +166 -0
  5. package/CLAUDE.md +75 -0
  6. package/LICENSE +21 -21
  7. package/README.md +338 -238
  8. package/dist/actions.d.ts +41 -10
  9. package/dist/actions.js +126 -23
  10. package/dist/actions.js.map +1 -1
  11. package/dist/adapters/base.adapter.d.ts +25 -25
  12. package/dist/adapters/base.adapter.js +63 -49
  13. package/dist/adapters/base.adapter.js.map +1 -1
  14. package/dist/adapters/mongodb.adapter.d.ts +50 -37
  15. package/dist/adapters/mongodb.adapter.js +363 -158
  16. package/dist/adapters/mongodb.adapter.js.map +1 -1
  17. package/dist/adapters/postgresql.adapter.d.ts +49 -0
  18. package/dist/adapters/postgresql.adapter.js +507 -0
  19. package/dist/adapters/postgresql.adapter.js.map +1 -0
  20. package/dist/adapters/sqlite.adapter.d.ts +40 -41
  21. package/dist/adapters/sqlite.adapter.js +470 -397
  22. package/dist/adapters/sqlite.adapter.js.map +1 -1
  23. package/dist/api.d.ts +6 -6
  24. package/dist/api.js +95 -55
  25. package/dist/api.js.map +1 -1
  26. package/dist/config.d.ts +16 -16
  27. package/dist/config.js +18 -18
  28. package/dist/config.js.map +1 -1
  29. package/dist/contracts/coinflip.contract.d.ts +27 -14
  30. package/dist/contracts/coinflip.contract.js +253 -94
  31. package/dist/contracts/coinflip.contract.js.map +1 -1
  32. package/dist/contracts/dice.contract.d.ts +37 -29
  33. package/dist/contracts/dice.contract.js +282 -155
  34. package/dist/contracts/dice.contract.js.map +1 -1
  35. package/dist/contracts/lotto.contract.d.ts +20 -20
  36. package/dist/contracts/lotto.contract.js +246 -246
  37. package/dist/contracts/nft.contract.d.ts +24 -0
  38. package/dist/contracts/nft.contract.js +533 -0
  39. package/dist/contracts/nft.contract.js.map +1 -0
  40. package/dist/contracts/token.contract.d.ts +18 -0
  41. package/dist/contracts/token.contract.js +263 -0
  42. package/dist/contracts/token.contract.js.map +1 -0
  43. package/dist/exchanges/bittrex.d.ts +6 -6
  44. package/dist/exchanges/bittrex.js +34 -34
  45. package/dist/exchanges/coingecko.d.ts +5 -0
  46. package/dist/exchanges/coingecko.js +40 -0
  47. package/dist/exchanges/coingecko.js.map +1 -0
  48. package/dist/exchanges/exchange.d.ts +9 -9
  49. package/dist/exchanges/exchange.js +26 -26
  50. package/dist/hive-rates.d.ts +9 -9
  51. package/dist/hive-rates.js +121 -75
  52. package/dist/hive-rates.js.map +1 -1
  53. package/dist/index.d.ts +12 -11
  54. package/dist/index.js +33 -32
  55. package/dist/index.js.map +1 -1
  56. package/dist/streamer.d.ts +140 -93
  57. package/dist/streamer.js +793 -545
  58. package/dist/streamer.js.map +1 -1
  59. package/dist/test.d.ts +1 -1
  60. package/dist/test.js +25 -25
  61. package/dist/test.js.map +1 -1
  62. package/dist/types/hive-stream.d.ts +35 -6
  63. package/dist/types/hive-stream.js +2 -2
  64. package/dist/utils.d.ts +27 -27
  65. package/dist/utils.js +271 -261
  66. package/dist/utils.js.map +1 -1
  67. package/ecosystem.config.js +17 -17
  68. package/jest.config.js +8 -8
  69. package/package.json +53 -48
  70. package/test-contract-block.md +18 -18
  71. package/tests/actions.spec.ts +252 -0
  72. package/tests/adapters/actions-persistence.spec.ts +144 -0
  73. package/tests/adapters/postgresql.adapter.spec.ts +127 -0
  74. package/tests/adapters/sqlite.adapter.spec.ts +180 -42
  75. package/tests/contracts/coinflip.contract.spec.ts +221 -131
  76. package/tests/contracts/dice.contract.spec.ts +202 -159
  77. package/tests/contracts/entrants.json +728 -728
  78. package/tests/contracts/lotto.contract.spec.ts +323 -323
  79. package/tests/contracts/nft.contract.spec.ts +948 -0
  80. package/tests/contracts/token.contract.spec.ts +334 -0
  81. package/tests/helpers/mock-adapter.ts +214 -0
  82. package/tests/setup.ts +29 -18
  83. package/tests/streamer-actions.spec.ts +263 -0
  84. package/tests/streamer.spec.ts +248 -151
  85. package/tests/utils.spec.ts +91 -94
  86. package/tsconfig.build.json +3 -22
  87. package/tslint.json +20 -20
  88. package/wallaby.js +26 -26
  89. package/.env +0 -3
@@ -1,95 +1,92 @@
1
- import { Utils } from './../src/utils';
2
-
3
- describe('Utils', () => {
4
-
5
- describe('Round Precision', () => {
6
- test('Properly rounds precision of number to 3 places', () => {
7
- const value = 99.299223;
8
-
9
- expect(Utils.roundPrecision(value, 3)).toStrictEqual(99.299);
10
- });
11
-
12
- test('Properly rounds precision of number up and to 3 places', () => {
13
- const value = 99.2966;
14
-
15
- expect(Utils.roundPrecision(value, 3)).toStrictEqual(99.297);
16
- });
17
-
18
- test('Invalid numeric values passed', () => {
19
- expect(Utils.roundPrecision('dasd', 3)).toBeNaN();
20
- });
21
- });
22
-
23
- test('Should generate two deterministic numbers', () => {
24
- // Should generate a deterministic random number
25
- expect(Utils.randomNumber('dasdasdas', '2312fsdfsdfsdf', 'kfjlksdjflksdjf999')).toStrictEqual(26);
26
-
27
- expect(Utils.randomNumber('fdfsdfsdfsdfsf', '2312fsdfsdfsdf', 'kfjlksdjflksdjf999')).toStrictEqual(43);
28
- });
29
-
30
- test('Should shuffle array in a non-deterministic way', () => {
31
- const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
32
- const arrayCloned = [...array];
33
-
34
- Utils.shuffle(array);
35
-
36
- expect(array).not.toMatchObject(arrayCloned);
37
- });
38
-
39
- describe('Generate String', () => {
40
- test('Generates a memo 6 characters in length', () => {
41
- expect(Utils.randomString(6)).toHaveLength(6);
42
- });
43
-
44
- test('Generates a memo using default 12 character length', () => {
45
- expect(Utils.randomString()).toHaveLength(12);
46
- });
47
- });
48
-
49
- describe('Random Range', () => {
50
- test('Should generate a random number between 0 and 10', () => {
51
- expect(Utils.randomRange(0, 10)).toBeLessThanOrEqual(10);
52
- });
53
-
54
- test('Should generate the number 10', () => {
55
- expect(Utils.randomRange(10, 10)).toStrictEqual(10);
56
- });
57
-
58
- test('Only pass min and not max', () => {
59
- expect(Utils.randomRange(0)).toBeLessThanOrEqual(2000);
60
- });
61
-
62
- test('Pass non numeric values to random range', () => {
63
- expect(Utils.randomRange('dd' as any, 'asjj' as any)).toBeNaN();
64
- });
65
- });
66
-
67
- describe('Convert Hive Amount', () => {
68
- test('Converts amount', async () => {
69
- const amount = 25;
70
- const fiatSymbol = 'USD';
71
- const hiveSymbol = 'HIVE';
72
-
73
- (fetch as any)
74
- .once(JSON.stringify({'success':true,'message':'','result':{'Bid':6905.98900000,'Ask':6925.65900000,'Last':6925.66500000}}))
75
- .once(JSON.stringify({'success':true,'message':'','result':{'Bid':0.00003083,'Ask':0.00003169,'Last':0.00003192}}))
76
- .once(JSON.stringify({'success':true,'message':'','result':{'Bid':0.00010800,'Ask':0.00010900,'Last':0.00010800}}))
77
- .once(JSON.stringify({'rates':{'CAD':1.4383752203,'HKD':7.7558193453,'ISK':140.4989335064,'PHP':51.4003524066,'DKK':6.9281276083,'HUF':326.7458035797,'CZK':25.6283038116,'GBP':0.862190485,'RON':4.4960586108,'SEK':10.2675507744,'IDR':16574.9976815358,'INR':76.1620142817,'BRL':5.0683483261,'RUB':79.8293610313,'HRK':7.053695632,'JPY':110.4609106928,'THB':32.8646944264,'CHF':0.982101456,'EUR':0.9273856997,'MYR':4.4449596587,'BGN':1.8137809515,'TRY':6.5859222851,'CNY':7.0838356673,'NOK':11.3667810442,'NZD':1.7563757767,'ZAR':17.6333116943,'USD':1.0,'MXN':24.6805156264,'SGD':1.4601687842,'AUD':1.7236390615,'ILS':3.6698506909,'KRW':1256.7003616804,'PLN':4.2711675786},'base':'USD','date':'2020-03-23'}));
78
-
79
- const value = await Utils.convertHiveAmount(amount, fiatSymbol, hiveSymbol);
80
-
81
- expect(fetch).toBeCalledWith(`https://api.bittrex.com/v3/markets/USD-BTC/ticker`);
82
- expect(fetch).toBeCalledWith(`https://api.bittrex.com/v3/markets/HIVE-BTC/ticker`);
83
- expect(fetch).toBeCalledWith(`https://api.bittrex.com/v3/markets/HBD-BTC/ticker`);
84
-
85
- expect(value).toStrictEqual(113.088);
86
- });
87
- });
88
-
89
- describe('Get transfer URL', () => {
90
- test('Gets a transfer URL string', () => {
91
- expect(Utils.getTransferUrl('beggars', 'TEST123', '10.000 HIVE', 'http://localhost:5001')).toStrictEqual(`https://hivesigner.com/sign/transfer?to=beggars&memo=TEST123&amount=10.000 HIVE&redirect_uri=http://localhost:5001`);
92
- });
93
- });
94
-
1
+ import { Utils } from './../src/utils';
2
+
3
+ describe('Utils', () => {
4
+
5
+ describe('Round Precision', () => {
6
+ test('Properly rounds precision of number to 3 places', () => {
7
+ const value = 99.299223;
8
+
9
+ expect(Utils.roundPrecision(value, 3)).toStrictEqual(99.299);
10
+ });
11
+
12
+ test('Properly rounds precision of number up and to 3 places', () => {
13
+ const value = 99.2966;
14
+
15
+ expect(Utils.roundPrecision(value, 3)).toStrictEqual(99.297);
16
+ });
17
+
18
+ test('Invalid numeric values passed', () => {
19
+ expect(Utils.roundPrecision('dasd', 3)).toBeNaN();
20
+ });
21
+ });
22
+
23
+ test('Should generate two deterministic numbers', () => {
24
+ // Should generate a deterministic random number
25
+ expect(Utils.randomNumber('dasdasdas', '2312fsdfsdfsdf', 'kfjlksdjflksdjf999')).toStrictEqual(26);
26
+
27
+ expect(Utils.randomNumber('fdfsdfsdfsdfsf', '2312fsdfsdfsdf', 'kfjlksdjflksdjf999')).toStrictEqual(43);
28
+ });
29
+
30
+ test('Should shuffle array in a non-deterministic way', () => {
31
+ const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
32
+ const arrayCloned = [...array];
33
+
34
+ Utils.shuffle(array);
35
+
36
+ expect(array).not.toMatchObject(arrayCloned);
37
+ });
38
+
39
+ describe('Generate String', () => {
40
+ test('Generates a memo 6 characters in length', () => {
41
+ expect(Utils.randomString(6)).toHaveLength(6);
42
+ });
43
+
44
+ test('Generates a memo using default 12 character length', () => {
45
+ expect(Utils.randomString()).toHaveLength(12);
46
+ });
47
+ });
48
+
49
+ describe('Random Range', () => {
50
+ test('Should generate a random number between 0 and 10', () => {
51
+ expect(Utils.randomRange(0, 10)).toBeLessThanOrEqual(10);
52
+ });
53
+
54
+ test('Should generate the number 10', () => {
55
+ expect(Utils.randomRange(10, 10)).toStrictEqual(10);
56
+ });
57
+
58
+ test('Only pass min and not max', () => {
59
+ expect(Utils.randomRange(0)).toBeLessThanOrEqual(2000);
60
+ });
61
+
62
+ test('Pass non numeric values to random range', () => {
63
+ expect(Utils.randomRange('dd' as any, 'asjj' as any)).toBeNaN();
64
+ });
65
+ });
66
+
67
+ describe('Convert Hive Amount', () => {
68
+ test('Converts amount', async () => {
69
+ const amount = 25;
70
+ const fiatSymbol = 'USD';
71
+ const hiveSymbol = 'HIVE';
72
+
73
+ (fetch as any)
74
+ .once(JSON.stringify({'hive':{'usd':0.229951},'hive_dollar':{'usd':0.99805}})) // CoinGecko HIVE/HBD prices
75
+ .once(JSON.stringify({'date':'2025-07-31','usd':{'cad':1.38249328,'hkd':7.84969296,'isk':124.40606356,'php':58.05502018,'dkk':6.52928985,'huf':350.43324994,'czk':21.5182452,'gbp':0.75416895,'ron':4.43971718,'sek':9.77798397,'idr':16437.63140133,'inr':87.62805331,'brl':5.57697598,'rub':81.01377784,'hrk':6.59133796,'jpy':148.8919467,'thb':32.6921739,'chf':0.81307502,'eur':0.87482089,'myr':4.2526877,'bgn':1.71100093,'try':40.59221009,'cny':7.19127973,'nok':10.30319488,'nzd':1.69157541,'zar':17.98114271,'usd':1.0,'mxn':18.84341987,'sgd':1.29367688,'aud':1.5491513,'ils':3.38255864,'krw':1389.43611488,'pln':3.73980141}})); // Currency API fiat rates
76
+
77
+ const value = await Utils.convertHiveAmount(amount, fiatSymbol, hiveSymbol);
78
+
79
+ expect(fetch).toBeCalledWith('https://api.coingecko.com/api/v3/simple/price?ids=hive,hive_dollar&vs_currencies=usd');
80
+ expect(fetch).toBeCalledWith('https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/usd.json');
81
+
82
+ expect(value).toStrictEqual(Number((amount / 0.229951).toFixed(3))); // amount / HIVE price from CoinGecko (fiat to HIVE conversion)
83
+ });
84
+ });
85
+
86
+ describe('Get transfer URL', () => {
87
+ test('Gets a transfer URL string', () => {
88
+ expect(Utils.getTransferUrl('beggars', 'TEST123', '10.000 HIVE', 'http://localhost:5001')).toStrictEqual(`https://hivesigner.com/sign/transfer?to=beggars&memo=TEST123&amount=10.000 HIVE&redirect_uri=http://localhost:5001`);
89
+ });
90
+ });
91
+
95
92
  });
@@ -1,23 +1,4 @@
1
- {
2
- "compilerOptions": {
3
- "module": "commonjs",
4
- "esModuleInterop": true,
5
- "target": "esnext",
6
- "allowSyntheticDefaultImports": true,
7
- "emitDecoratorMetadata": true,
8
- "experimentalDecorators": true,
9
- "resolveJsonModule": true,
10
- "moduleResolution": "node",
11
- "declaration": true,
12
- "sourceMap": true,
13
- "outDir": "dist",
14
- "baseUrl": ".",
15
- "paths": {
16
- "*": [
17
- "node_modules/*",
18
- "src/types/*"
19
- ]
20
- }
21
- },
22
- "exclude": ["node_modules", ".vscode", "dist", "tests"]
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "exclude": ["node_modules", ".vscode", "dist", "tests"]
23
4
  }
package/tslint.json CHANGED
@@ -1,21 +1,21 @@
1
- {
2
- "extends": [
3
- "tslint:recommended"
4
- ],
5
- "jsRules": {},
6
- "rules": {
7
- "quotemark": [true, "single"],
8
- "ordered-imports": false,
9
- "interface-name": false,
10
- "object-literal-sort-keys": false,
11
- "eofline": false,
12
- "no-console": false,
13
- "member-ordering": false,
14
- "max-line-length": false,
15
- "trailing-comma": false,
16
- "no-string-literal": false,
17
- "arrow-parens": false,
18
- "object-literal-key-quotes": false
19
- },
20
- "rulesDirectory": []
1
+ {
2
+ "extends": [
3
+ "tslint:recommended"
4
+ ],
5
+ "jsRules": {},
6
+ "rules": {
7
+ "quotemark": [true, "single"],
8
+ "ordered-imports": false,
9
+ "interface-name": false,
10
+ "object-literal-sort-keys": false,
11
+ "eofline": false,
12
+ "no-console": false,
13
+ "member-ordering": false,
14
+ "max-line-length": false,
15
+ "trailing-comma": false,
16
+ "no-string-literal": false,
17
+ "arrow-parens": false,
18
+ "object-literal-key-quotes": false
19
+ },
20
+ "rulesDirectory": []
21
21
  }
package/wallaby.js CHANGED
@@ -1,26 +1,26 @@
1
- module.exports = function (wallaby) {
2
- return {
3
- files: [
4
- "**/*.css",
5
- "**/*.json",
6
- "src/**/*.ts",
7
- "src/**/*.html",
8
- "tests/setup.ts",
9
- "tsconfig.json",
10
- ],
11
-
12
- tests: ["tests/**/*.spec.ts"],
13
-
14
- compilers: {
15
- "**/*.ts": wallaby.compilers.typeScript({
16
- module: "commonjs",
17
- typescript: require("typescript"),
18
- }),
19
- },
20
-
21
- env: {
22
- runner: "node",
23
- type: "node",
24
- },
25
- };
26
- };
1
+ module.exports = function (wallaby) {
2
+ return {
3
+ files: [
4
+ "**/*.css",
5
+ "**/*.json",
6
+ "src/**/*.ts",
7
+ "src/**/*.html",
8
+ "tests/setup.ts",
9
+ "tsconfig.json",
10
+ ],
11
+
12
+ tests: ["tests/**/*.spec.ts"],
13
+
14
+ compilers: {
15
+ "**/*.ts": wallaby.compilers.typeScript({
16
+ module: "commonjs",
17
+ typescript: require("typescript"),
18
+ }),
19
+ },
20
+
21
+ env: {
22
+ runner: "node",
23
+ type: "node",
24
+ },
25
+ };
26
+ };
package/.env DELETED
@@ -1,3 +0,0 @@
1
- ACTIVE_KEY=5JBKcb9nNUDcuCgXyLYNdR1uR38nk1id3cwGGFtDTo443BB1By9
2
- POSTING_KEY=5KFthvokvn22PYAiCBbPPwTeTsULHuX7DNDHjNkapzJsx7T5qiT
3
- EXCHANGE_RATE_API_KEY=7d20br5S3MM3K8dhsasNpVRCvkZJ465c