@vuu-ui/vuu-data-test 3.0.0 → 3.1.0-beta.1

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 (264) hide show
  1. package/package.json +15 -12
  2. package/src/ArrayProxy.mjs +38 -0
  3. package/src/RuntimeVisualLink.mjs +45 -0
  4. package/src/Table.mjs +96 -0
  5. package/src/TickingArrayDataSource.mjs +265 -0
  6. package/src/UpdateGenerator.mjs +72 -0
  7. package/src/basket/BasketModule.mjs +272 -0
  8. package/src/basket/basket-schemas.mjs +366 -0
  9. package/src/basket/index.mjs +2 -0
  10. package/src/basket/reference-data/constituents.mjs +76 -0
  11. package/src/basket/reference-data/ftse100.mjs +686 -0
  12. package/src/basket/reference-data/hsi.mjs +1047 -0
  13. package/src/basket/reference-data/nasdaq100.mjs +812 -0
  14. package/src/basket/reference-data/prices.mjs +43 -0
  15. package/src/basket/reference-data/sp500.mjs +315 -0
  16. package/src/core/module/ModuleContainer.mjs +21 -0
  17. package/src/core/module/VuuModule.mjs +635 -0
  18. package/src/core/table/TableContainer.mjs +102 -0
  19. package/src/data-utils.mjs +57 -0
  20. package/src/default-column-definitions.mjs +15 -0
  21. package/src/index.mjs +12 -0
  22. package/src/local-datasource-provider/LocalDatasourceProvider.mjs +44 -0
  23. package/src/makeSuggestions.mjs +20 -0
  24. package/src/rowUpdates.mjs +0 -0
  25. package/src/schemas.mjs +19 -0
  26. package/src/session-table-utils.mjs +31 -0
  27. package/src/simul/SimulModule.mjs +175 -0
  28. package/src/simul/index.mjs +2 -0
  29. package/src/simul/reference-data/accounts.mjs +23 -0
  30. package/src/simul/reference-data/algos.mjs +9 -0
  31. package/src/simul/reference-data/currencies.mjs +8 -0
  32. package/src/simul/reference-data/index.mjs +5 -0
  33. package/src/simul/reference-data/instrument-prices.mjs +48 -0
  34. package/src/simul/reference-data/instruments-extended.mjs +12 -0
  35. package/src/simul/reference-data/instruments.mjs +69 -0
  36. package/src/simul/reference-data/isin-generator/convert-string-to-base-ten-number.mjs +2 -0
  37. package/src/simul/reference-data/isin-generator/fixtures/alphabet.mjs +27 -0
  38. package/src/simul/reference-data/isin-generator/fixtures/alphanumeric-values.mjs +7 -0
  39. package/src/simul/reference-data/isin-generator/fixtures/base-ten-numbers.mjs +13 -0
  40. package/src/simul/reference-data/isin-generator/generate-cusip-check-code.mjs +17 -0
  41. package/src/simul/reference-data/isin-generator/generate-cusip-without-check-code.mjs +8 -0
  42. package/src/simul/reference-data/isin-generator/generate-cusip.mjs +8 -0
  43. package/src/simul/reference-data/isin-generator/generate-random-alphanumeric.mjs +3 -0
  44. package/src/simul/reference-data/isin-generator/generate-random-base-ten-number.mjs +2 -0
  45. package/src/simul/reference-data/isin-generator/generate-random-string-of-alphanumeric-chars.mjs +7 -0
  46. package/src/simul/reference-data/isin-generator/generate-random-string-of-base-ten-chars.mjs +7 -0
  47. package/src/simul/reference-data/isin-generator/index.mjs +280 -0
  48. package/src/simul/reference-data/isin-generator/is-odd.mjs +2 -0
  49. package/src/simul/reference-data/locations.mjs +45 -0
  50. package/src/simul/reference-data/lotsizes.mjs +24 -0
  51. package/src/simul/reference-data/orderStatus.mjs +6 -0
  52. package/src/simul/reference-data/orders.mjs +64 -0
  53. package/src/simul/reference-data/parent-child-orders.mjs +119 -0
  54. package/src/simul/reference-data/priceStrategies.mjs +8 -0
  55. package/src/simul/reference-data/prices.mjs +80 -0
  56. package/src/simul/reference-data/sides.mjs +5 -0
  57. package/src/simul/simul-schemas.mjs +430 -0
  58. package/src/test/TestModule.mjs +582 -0
  59. package/src/test/index.mjs +1 -0
  60. package/src/vuu-row-generator.mjs +71 -0
  61. package/cjs/ArrayProxy.js +0 -72
  62. package/cjs/ArrayProxy.js.map +0 -1
  63. package/cjs/RuntimeVisualLink.js +0 -73
  64. package/cjs/RuntimeVisualLink.js.map +0 -1
  65. package/cjs/Table.js +0 -128
  66. package/cjs/Table.js.map +0 -1
  67. package/cjs/TickingArrayDataSource.js +0 -343
  68. package/cjs/TickingArrayDataSource.js.map +0 -1
  69. package/cjs/UpdateGenerator.js +0 -94
  70. package/cjs/UpdateGenerator.js.map +0 -1
  71. package/cjs/basket/BasketModule.js +0 -282
  72. package/cjs/basket/BasketModule.js.map +0 -1
  73. package/cjs/basket/basket-schemas.js +0 -134
  74. package/cjs/basket/basket-schemas.js.map +0 -1
  75. package/cjs/basket/reference-data/constituents.js +0 -40
  76. package/cjs/basket/reference-data/constituents.js.map +0 -1
  77. package/cjs/basket/reference-data/ftse100.js +0 -105
  78. package/cjs/basket/reference-data/ftse100.js.map +0 -1
  79. package/cjs/basket/reference-data/hsi.js +0 -87
  80. package/cjs/basket/reference-data/hsi.js.map +0 -1
  81. package/cjs/basket/reference-data/nasdaq100.js +0 -108
  82. package/cjs/basket/reference-data/nasdaq100.js.map +0 -1
  83. package/cjs/basket/reference-data/sp500.js +0 -46
  84. package/cjs/basket/reference-data/sp500.js.map +0 -1
  85. package/cjs/core/module/ModuleContainer.js +0 -43
  86. package/cjs/core/module/ModuleContainer.js.map +0 -1
  87. package/cjs/core/module/VuuModule.js +0 -843
  88. package/cjs/core/module/VuuModule.js.map +0 -1
  89. package/cjs/core/table/TableContainer.js +0 -144
  90. package/cjs/core/table/TableContainer.js.map +0 -1
  91. package/cjs/data-utils.js +0 -55
  92. package/cjs/data-utils.js.map +0 -1
  93. package/cjs/default-column-definitions.js +0 -10
  94. package/cjs/default-column-definitions.js.map +0 -1
  95. package/cjs/index.js +0 -44
  96. package/cjs/index.js.map +0 -1
  97. package/cjs/local-datasource-provider/LocalDatasourceProvider.js +0 -70
  98. package/cjs/local-datasource-provider/LocalDatasourceProvider.js.map +0 -1
  99. package/cjs/makeSuggestions.js +0 -26
  100. package/cjs/makeSuggestions.js.map +0 -1
  101. package/cjs/schemas.js +0 -28
  102. package/cjs/schemas.js.map +0 -1
  103. package/cjs/session-table-utils.js +0 -29
  104. package/cjs/session-table-utils.js.map +0 -1
  105. package/cjs/simul/SimulModule.js +0 -187
  106. package/cjs/simul/SimulModule.js.map +0 -1
  107. package/cjs/simul/reference-data/accounts.js +0 -27
  108. package/cjs/simul/reference-data/accounts.js.map +0 -1
  109. package/cjs/simul/reference-data/algos.js +0 -6
  110. package/cjs/simul/reference-data/algos.js.map +0 -1
  111. package/cjs/simul/reference-data/currencies.js +0 -6
  112. package/cjs/simul/reference-data/currencies.js.map +0 -1
  113. package/cjs/simul/reference-data/instruments-extended.js +0 -19
  114. package/cjs/simul/reference-data/instruments-extended.js.map +0 -1
  115. package/cjs/simul/reference-data/instruments.js +0 -87
  116. package/cjs/simul/reference-data/instruments.js.map +0 -1
  117. package/cjs/simul/reference-data/isin-generator/convert-string-to-base-ten-number.js +0 -6
  118. package/cjs/simul/reference-data/isin-generator/convert-string-to-base-ten-number.js.map +0 -1
  119. package/cjs/simul/reference-data/isin-generator/fixtures/alphabet.js +0 -31
  120. package/cjs/simul/reference-data/isin-generator/fixtures/alphabet.js.map +0 -1
  121. package/cjs/simul/reference-data/isin-generator/fixtures/alphanumeric-values.js +0 -9
  122. package/cjs/simul/reference-data/isin-generator/fixtures/alphanumeric-values.js.map +0 -1
  123. package/cjs/simul/reference-data/isin-generator/fixtures/base-ten-numbers.js +0 -17
  124. package/cjs/simul/reference-data/isin-generator/fixtures/base-ten-numbers.js.map +0 -1
  125. package/cjs/simul/reference-data/isin-generator/generate-cusip-check-code.js +0 -24
  126. package/cjs/simul/reference-data/isin-generator/generate-cusip-check-code.js.map +0 -1
  127. package/cjs/simul/reference-data/isin-generator/generate-cusip-without-check-code.js +0 -13
  128. package/cjs/simul/reference-data/isin-generator/generate-cusip-without-check-code.js.map +0 -1
  129. package/cjs/simul/reference-data/isin-generator/generate-cusip.js +0 -13
  130. package/cjs/simul/reference-data/isin-generator/generate-cusip.js.map +0 -1
  131. package/cjs/simul/reference-data/isin-generator/generate-random-alphanumeric.js +0 -8
  132. package/cjs/simul/reference-data/isin-generator/generate-random-alphanumeric.js.map +0 -1
  133. package/cjs/simul/reference-data/isin-generator/generate-random-base-ten-number.js +0 -6
  134. package/cjs/simul/reference-data/isin-generator/generate-random-base-ten-number.js.map +0 -1
  135. package/cjs/simul/reference-data/isin-generator/generate-random-string-of-alphanumeric-chars.js +0 -14
  136. package/cjs/simul/reference-data/isin-generator/generate-random-string-of-alphanumeric-chars.js.map +0 -1
  137. package/cjs/simul/reference-data/isin-generator/generate-random-string-of-base-ten-chars.js +0 -14
  138. package/cjs/simul/reference-data/isin-generator/generate-random-string-of-base-ten-chars.js.map +0 -1
  139. package/cjs/simul/reference-data/isin-generator/index.js +0 -295
  140. package/cjs/simul/reference-data/isin-generator/index.js.map +0 -1
  141. package/cjs/simul/reference-data/isin-generator/is-odd.js +0 -6
  142. package/cjs/simul/reference-data/isin-generator/is-odd.js.map +0 -1
  143. package/cjs/simul/reference-data/locations.js +0 -17
  144. package/cjs/simul/reference-data/locations.js.map +0 -1
  145. package/cjs/simul/reference-data/lotsizes.js +0 -28
  146. package/cjs/simul/reference-data/lotsizes.js.map +0 -1
  147. package/cjs/simul/reference-data/orderStatus.js +0 -6
  148. package/cjs/simul/reference-data/orderStatus.js.map +0 -1
  149. package/cjs/simul/reference-data/orders.js +0 -55
  150. package/cjs/simul/reference-data/orders.js.map +0 -1
  151. package/cjs/simul/reference-data/parent-child-orders.js +0 -146
  152. package/cjs/simul/reference-data/parent-child-orders.js.map +0 -1
  153. package/cjs/simul/reference-data/prices.js +0 -91
  154. package/cjs/simul/reference-data/prices.js.map +0 -1
  155. package/cjs/simul/reference-data/sides.js +0 -6
  156. package/cjs/simul/reference-data/sides.js.map +0 -1
  157. package/cjs/simul/simul-schemas.js +0 -159
  158. package/cjs/simul/simul-schemas.js.map +0 -1
  159. package/cjs/test/TestModule.js +0 -255
  160. package/cjs/test/TestModule.js.map +0 -1
  161. package/cjs/vuu-row-generator.js +0 -74
  162. package/cjs/vuu-row-generator.js.map +0 -1
  163. package/esm/ArrayProxy.js +0 -70
  164. package/esm/ArrayProxy.js.map +0 -1
  165. package/esm/RuntimeVisualLink.js +0 -71
  166. package/esm/RuntimeVisualLink.js.map +0 -1
  167. package/esm/Table.js +0 -124
  168. package/esm/Table.js.map +0 -1
  169. package/esm/TickingArrayDataSource.js +0 -341
  170. package/esm/TickingArrayDataSource.js.map +0 -1
  171. package/esm/UpdateGenerator.js +0 -92
  172. package/esm/UpdateGenerator.js.map +0 -1
  173. package/esm/basket/BasketModule.js +0 -278
  174. package/esm/basket/BasketModule.js.map +0 -1
  175. package/esm/basket/basket-schemas.js +0 -131
  176. package/esm/basket/basket-schemas.js.map +0 -1
  177. package/esm/basket/reference-data/constituents.js +0 -38
  178. package/esm/basket/reference-data/constituents.js.map +0 -1
  179. package/esm/basket/reference-data/ftse100.js +0 -103
  180. package/esm/basket/reference-data/ftse100.js.map +0 -1
  181. package/esm/basket/reference-data/hsi.js +0 -85
  182. package/esm/basket/reference-data/hsi.js.map +0 -1
  183. package/esm/basket/reference-data/nasdaq100.js +0 -106
  184. package/esm/basket/reference-data/nasdaq100.js.map +0 -1
  185. package/esm/basket/reference-data/sp500.js +0 -44
  186. package/esm/basket/reference-data/sp500.js.map +0 -1
  187. package/esm/core/module/ModuleContainer.js +0 -41
  188. package/esm/core/module/ModuleContainer.js.map +0 -1
  189. package/esm/core/module/VuuModule.js +0 -841
  190. package/esm/core/module/VuuModule.js.map +0 -1
  191. package/esm/core/table/TableContainer.js +0 -142
  192. package/esm/core/table/TableContainer.js.map +0 -1
  193. package/esm/data-utils.js +0 -50
  194. package/esm/data-utils.js.map +0 -1
  195. package/esm/default-column-definitions.js +0 -8
  196. package/esm/default-column-definitions.js.map +0 -1
  197. package/esm/index.js +0 -15
  198. package/esm/index.js.map +0 -1
  199. package/esm/local-datasource-provider/LocalDatasourceProvider.js +0 -68
  200. package/esm/local-datasource-provider/LocalDatasourceProvider.js.map +0 -1
  201. package/esm/makeSuggestions.js +0 -24
  202. package/esm/makeSuggestions.js.map +0 -1
  203. package/esm/schemas.js +0 -24
  204. package/esm/schemas.js.map +0 -1
  205. package/esm/session-table-utils.js +0 -26
  206. package/esm/session-table-utils.js.map +0 -1
  207. package/esm/simul/SimulModule.js +0 -184
  208. package/esm/simul/SimulModule.js.map +0 -1
  209. package/esm/simul/reference-data/accounts.js +0 -25
  210. package/esm/simul/reference-data/accounts.js.map +0 -1
  211. package/esm/simul/reference-data/algos.js +0 -4
  212. package/esm/simul/reference-data/algos.js.map +0 -1
  213. package/esm/simul/reference-data/currencies.js +0 -4
  214. package/esm/simul/reference-data/currencies.js.map +0 -1
  215. package/esm/simul/reference-data/instruments-extended.js +0 -17
  216. package/esm/simul/reference-data/instruments-extended.js.map +0 -1
  217. package/esm/simul/reference-data/instruments.js +0 -82
  218. package/esm/simul/reference-data/instruments.js.map +0 -1
  219. package/esm/simul/reference-data/isin-generator/convert-string-to-base-ten-number.js +0 -4
  220. package/esm/simul/reference-data/isin-generator/convert-string-to-base-ten-number.js.map +0 -1
  221. package/esm/simul/reference-data/isin-generator/fixtures/alphabet.js +0 -29
  222. package/esm/simul/reference-data/isin-generator/fixtures/alphabet.js.map +0 -1
  223. package/esm/simul/reference-data/isin-generator/fixtures/alphanumeric-values.js +0 -7
  224. package/esm/simul/reference-data/isin-generator/fixtures/alphanumeric-values.js.map +0 -1
  225. package/esm/simul/reference-data/isin-generator/fixtures/base-ten-numbers.js +0 -15
  226. package/esm/simul/reference-data/isin-generator/fixtures/base-ten-numbers.js.map +0 -1
  227. package/esm/simul/reference-data/isin-generator/generate-cusip-check-code.js +0 -22
  228. package/esm/simul/reference-data/isin-generator/generate-cusip-check-code.js.map +0 -1
  229. package/esm/simul/reference-data/isin-generator/generate-cusip-without-check-code.js +0 -11
  230. package/esm/simul/reference-data/isin-generator/generate-cusip-without-check-code.js.map +0 -1
  231. package/esm/simul/reference-data/isin-generator/generate-cusip.js +0 -11
  232. package/esm/simul/reference-data/isin-generator/generate-cusip.js.map +0 -1
  233. package/esm/simul/reference-data/isin-generator/generate-random-alphanumeric.js +0 -6
  234. package/esm/simul/reference-data/isin-generator/generate-random-alphanumeric.js.map +0 -1
  235. package/esm/simul/reference-data/isin-generator/generate-random-base-ten-number.js +0 -4
  236. package/esm/simul/reference-data/isin-generator/generate-random-base-ten-number.js.map +0 -1
  237. package/esm/simul/reference-data/isin-generator/generate-random-string-of-alphanumeric-chars.js +0 -12
  238. package/esm/simul/reference-data/isin-generator/generate-random-string-of-alphanumeric-chars.js.map +0 -1
  239. package/esm/simul/reference-data/isin-generator/generate-random-string-of-base-ten-chars.js +0 -12
  240. package/esm/simul/reference-data/isin-generator/generate-random-string-of-base-ten-chars.js.map +0 -1
  241. package/esm/simul/reference-data/isin-generator/index.js +0 -293
  242. package/esm/simul/reference-data/isin-generator/index.js.map +0 -1
  243. package/esm/simul/reference-data/isin-generator/is-odd.js +0 -4
  244. package/esm/simul/reference-data/isin-generator/is-odd.js.map +0 -1
  245. package/esm/simul/reference-data/locations.js +0 -14
  246. package/esm/simul/reference-data/locations.js.map +0 -1
  247. package/esm/simul/reference-data/lotsizes.js +0 -26
  248. package/esm/simul/reference-data/lotsizes.js.map +0 -1
  249. package/esm/simul/reference-data/orderStatus.js +0 -4
  250. package/esm/simul/reference-data/orderStatus.js.map +0 -1
  251. package/esm/simul/reference-data/orders.js +0 -52
  252. package/esm/simul/reference-data/orders.js.map +0 -1
  253. package/esm/simul/reference-data/parent-child-orders.js +0 -141
  254. package/esm/simul/reference-data/parent-child-orders.js.map +0 -1
  255. package/esm/simul/reference-data/prices.js +0 -88
  256. package/esm/simul/reference-data/prices.js.map +0 -1
  257. package/esm/simul/reference-data/sides.js +0 -4
  258. package/esm/simul/reference-data/sides.js.map +0 -1
  259. package/esm/simul/simul-schemas.js +0 -156
  260. package/esm/simul/simul-schemas.js.map +0 -1
  261. package/esm/test/TestModule.js +0 -253
  262. package/esm/test/TestModule.js.map +0 -1
  263. package/esm/vuu-row-generator.js +0 -68
  264. package/esm/vuu-row-generator.js.map +0 -1
package/package.json CHANGED
@@ -1,32 +1,35 @@
1
1
  {
2
- "version": "3.0.0",
2
+ "version": "3.1.0-beta.1",
3
+ "main": "src/index.ts",
3
4
  "author": "heswell",
4
5
  "license": "Apache-2.0",
6
+ "scripts": {
7
+ "build:dev": "node ../../scripts/run-build.mjs",
8
+ "build": "node ../../scripts/run-build-rslib.ts",
9
+ "type-defs": "node ../../scripts/build-type-defs.mjs"
10
+ },
5
11
  "dependencies": {
6
- "@vuu-ui/vuu-data-local": "3.0.0",
7
- "@vuu-ui/vuu-utils": "3.0.0"
12
+ "@vuu-ui/vuu-data-local": "3.1.0-beta.1",
13
+ "@vuu-ui/vuu-utils": "3.1.0-beta.1"
8
14
  },
9
15
  "devDependencies": {
10
- "@vuu-ui/vuu-protocol-types": "3.0.0",
11
- "@vuu-ui/vuu-data-types": "3.0.0",
12
- "@vuu-ui/vuu-table-types": "3.0.0"
16
+ "@vuu-ui/vuu-protocol-types": "3.1.0-beta.1",
17
+ "@vuu-ui/vuu-data-types": "3.1.0-beta.1",
18
+ "@vuu-ui/vuu-table-types": "3.1.0-beta.1"
13
19
  },
14
20
  "sideEffects": false,
15
21
  "files": [
16
22
  "README.md",
17
- "esm",
18
- "cjs",
23
+ "src",
19
24
  "/types"
20
25
  ],
21
26
  "exports": {
22
27
  ".": {
23
- "require": "./cjs/index.js",
24
- "import": "./esm/index.js",
28
+ "import": "./src/index.js",
25
29
  "types": "./types/index.d.ts"
26
30
  }
27
31
  },
28
- "main": "cjs/index.js",
29
- "module": "esm/index.js",
32
+ "module": "index.js",
30
33
  "name": "@vuu-ui/vuu-data-test",
31
34
  "type": "module",
32
35
  "types": "types/index.d.ts"
@@ -0,0 +1,38 @@
1
+ class ArrayProxy {
2
+ #getItem;
3
+ length = 0;
4
+ constructor(size, getRow){
5
+ this.#getItem = getRow;
6
+ this.length = size;
7
+ const handler = {
8
+ get: (target, prop)=>{
9
+ if ("length" === prop) return target.length;
10
+ if ("slice" === prop) return target.slice;
11
+ if ("map" === prop) return target.map;
12
+ if ("toString" === prop) return "[ArrayProxy]";
13
+ if ("string" == typeof prop) {
14
+ const index = parseInt(prop, 10);
15
+ if (!isNaN(index)) if (index < this.length) return target.#getItem(index);
16
+ else return;
17
+ }
18
+ throw Error(`unsupported property ${String(prop)} on ArrayProxy`);
19
+ },
20
+ set: (target, prop, newVal)=>{
21
+ if ("length" === prop) {
22
+ target.length = newVal;
23
+ return true;
24
+ }
25
+ throw Error("ArrayProxy is immutable except for length");
26
+ }
27
+ };
28
+ return new Proxy(this, handler);
29
+ }
30
+ map = (func)=>new ArrayProxy(this.length, (i)=>func(this.#getItem(i), i));
31
+ slice = (from, to)=>{
32
+ const out = [];
33
+ const end = Math.min(this.length, to);
34
+ for(let i = from; i < end; i++)out.push(this.#getItem(i));
35
+ return out;
36
+ };
37
+ }
38
+ export { ArrayProxy };
@@ -0,0 +1,45 @@
1
+ import { buildColumnMap } from "@vuu-ui/vuu-utils";
2
+ class RuntimeVisualLink {
3
+ #childColumnName;
4
+ #childDataSource;
5
+ #parentColumnName;
6
+ #parentDataSource;
7
+ constructor(childDataSource, parentDataSource, childColumnName, parentColumnName){
8
+ this.#childColumnName = childColumnName;
9
+ this.#childDataSource = childDataSource;
10
+ this.#parentColumnName = parentColumnName;
11
+ this.#parentDataSource = parentDataSource;
12
+ parentDataSource.on("row-selection", this.handleParentSelectEvent);
13
+ }
14
+ destroy() {}
15
+ remove() {
16
+ this.#parentDataSource?.removeListener("row-selection", this.handleParentSelectEvent);
17
+ this.#childDataSource.baseFilter = {
18
+ filter: ""
19
+ };
20
+ }
21
+ handleParentSelectEvent = ()=>{
22
+ if (this.#childDataSource) {
23
+ const selectedValues = this.pickUniqueSelectedValues();
24
+ if (0 === selectedValues.length) this.#childDataSource.baseFilter = void 0;
25
+ else if (1 === selectedValues.length) this.#childDataSource.baseFilter = {
26
+ filter: `${this.#childColumnName} = "${selectedValues[0]}"`
27
+ };
28
+ else this.#childDataSource.baseFilter = {
29
+ filter: `${this.#childColumnName} in ["${selectedValues.join('","')}"]`
30
+ };
31
+ }
32
+ };
33
+ pickUniqueSelectedValues() {
34
+ const dataSource = this.#parentDataSource;
35
+ const map = buildColumnMap(dataSource.columns);
36
+ const colIndex = map[this.#parentColumnName];
37
+ const set = new Set();
38
+ for (const key of dataSource.getSelectedRowIds()){
39
+ const row = dataSource.getRowByKey(key);
40
+ if (row) set.add(row[colIndex]);
41
+ }
42
+ return Array.from(set);
43
+ }
44
+ }
45
+ export { RuntimeVisualLink };
package/src/Table.mjs ADDED
@@ -0,0 +1,96 @@
1
+ import { EventEmitter } from "@vuu-ui/vuu-utils";
2
+ class Table extends EventEmitter {
3
+ #data;
4
+ #dataMap;
5
+ #indexOfKey;
6
+ #index = new Map();
7
+ #schema;
8
+ constructor(schema, data, dataMap, updateGenerator){
9
+ super();
10
+ this.#data = data;
11
+ this.#dataMap = dataMap;
12
+ this.#schema = schema;
13
+ this.#indexOfKey = dataMap[schema.key];
14
+ this.buildIndex();
15
+ updateGenerator?.setTable(this);
16
+ updateGenerator?.setRange({
17
+ from: 0,
18
+ to: 100
19
+ });
20
+ }
21
+ buildIndex() {
22
+ for(let i = 0; i < this.#data.length; i++){
23
+ const key = this.#data[i][this.#indexOfKey];
24
+ this.#index.set(key, i);
25
+ }
26
+ }
27
+ get data() {
28
+ return this.#data;
29
+ }
30
+ get map() {
31
+ return this.#dataMap;
32
+ }
33
+ get schema() {
34
+ return this.#schema;
35
+ }
36
+ get name() {
37
+ return this.#schema.table.table;
38
+ }
39
+ delete(key, emitEvent = true) {
40
+ const index = this.#index.get(key) ?? -1;
41
+ if (-1 !== index) {
42
+ this.#index.delete(key);
43
+ this.#data.splice(index, 1);
44
+ for(let i = index; i < this.#data.length; i++)this.#index.set(this.#data[i][this.#indexOfKey], i);
45
+ if (emitEvent) this.emit("delete", key);
46
+ } else throw Error(`[Table] delete key ${key} not found`);
47
+ }
48
+ insert(row, emitEvent = true) {
49
+ const index = this.#data.length;
50
+ this.#data.push(row);
51
+ const key = row[this.#indexOfKey];
52
+ this.#index.set(key, index);
53
+ if (emitEvent) this.emit("insert", row);
54
+ }
55
+ findByKey(key) {
56
+ const index = this.#index.get(key) ?? -1;
57
+ return this.#data[index];
58
+ }
59
+ update(key, columnName, value) {
60
+ const rowIndex = this.#data.findIndex((row)=>row[this.#indexOfKey] === key);
61
+ const colIndex = this.#dataMap[columnName];
62
+ if (-1 !== rowIndex) {
63
+ const row = this.#data[rowIndex];
64
+ const newRow = row.slice();
65
+ newRow[colIndex] = value;
66
+ const tsIndex = this.#dataMap.vuuUpdatedTimestamp;
67
+ if ("number" == typeof tsIndex) {
68
+ const lastUpdated = Date.now();
69
+ newRow[tsIndex] = lastUpdated;
70
+ }
71
+ this.#data[rowIndex] = newRow;
72
+ this.emit("update", newRow, columnName);
73
+ }
74
+ }
75
+ updateRow(row) {
76
+ const key = row[this.#indexOfKey];
77
+ const rowIndex = this.#data.findIndex((row)=>row[this.#indexOfKey] === key);
78
+ if (-1 !== rowIndex) {
79
+ const tsIndex = this.#dataMap.vuuUpdatedTimestamp;
80
+ const lastUpdated = Date.now();
81
+ row[tsIndex] = lastUpdated;
82
+ this.#data[rowIndex] = row;
83
+ this.emit("update", row);
84
+ }
85
+ }
86
+ }
87
+ function buildDataColumnMapFromSchema(schema) {
88
+ return Object.values(schema.columns).reduce((map, col, index)=>({
89
+ ...map,
90
+ [col.name]: index
91
+ }), {});
92
+ }
93
+ function buildDataColumnMap(schemas, tableName) {
94
+ return buildDataColumnMapFromSchema(schemas[tableName]);
95
+ }
96
+ export { Table, buildDataColumnMap, buildDataColumnMapFromSchema };
@@ -0,0 +1,265 @@
1
+ import { ArrayDataSource } from "@vuu-ui/vuu-data-local";
2
+ import { StaleUpdateError, isRpcSuccess, isTypeaheadRequest } from "@vuu-ui/vuu-utils";
3
+ import { makeSuggestions } from "./makeSuggestions.mjs";
4
+ class TickingArrayDataSource extends ArrayDataSource {
5
+ #menuRpcServices;
6
+ #pendingVisualLink;
7
+ #rpcMenuServices;
8
+ #rpcServices;
9
+ #sourceTableDataSource;
10
+ #table;
11
+ #selectionLinkSubscribers;
12
+ #visualLinkService;
13
+ #getVisualLinks;
14
+ #vuuModule;
15
+ constructor({ data, getVisualLinks, rpcServices, rpcMenuServices, table, menu, visualLink, visualLinkService, vuuModule, ...arrayDataSourceProps }){
16
+ if (void 0 === data && void 0 === table) throw Error("TickingArrayDataSource must be constructed with data");
17
+ super({
18
+ ...arrayDataSourceProps,
19
+ data: data ?? table?.data ?? [],
20
+ dataMap: table?.map
21
+ });
22
+ this._menu = menu;
23
+ this.#rpcMenuServices = rpcMenuServices;
24
+ this.#pendingVisualLink = visualLink;
25
+ this.#rpcServices = rpcServices;
26
+ this.#table = table;
27
+ this.#visualLinkService = visualLinkService;
28
+ this.#getVisualLinks = getVisualLinks;
29
+ this.#vuuModule = vuuModule;
30
+ if (table) {
31
+ this.tableSchema = table.schema;
32
+ table.on("insert", this.insert);
33
+ table.on("update", this.updateRowWithSessionCheck);
34
+ table.on("delete", this.handleDeleteFromTable);
35
+ }
36
+ }
37
+ updateRowWithSessionCheck = (row, columnName, sessionId)=>{
38
+ if (sessionId && sessionId === this.viewport) this.updateRow(row, columnName);
39
+ else if (sessionId) console.warn("THIS IS NEVER EXPECTED TO HAPPEN");
40
+ else this.updateRow(row, columnName);
41
+ };
42
+ async subscribe(subscribeProps, callback) {
43
+ const subscription = super.subscribe(subscribeProps, callback);
44
+ if (this.#pendingVisualLink) {
45
+ this.visualLink = this.#pendingVisualLink;
46
+ this.#pendingVisualLink = void 0;
47
+ }
48
+ return subscription;
49
+ }
50
+ unsubscribe() {
51
+ super.unsubscribe();
52
+ this.#table = void 0;
53
+ }
54
+ set links(links) {
55
+ super.links = links;
56
+ }
57
+ get links() {
58
+ return this.#getVisualLinks?.(this.table.table);
59
+ }
60
+ getSelectedRowIds() {
61
+ return Array.from(this.selectedRows);
62
+ }
63
+ isSessionDataSourceOf(dataSource) {
64
+ return this.#sourceTableDataSource === dataSource;
65
+ }
66
+ async createSessionDataSource(copyOption) {
67
+ const rpcResponse = await this?.rpcRequest?.({
68
+ type: "RPC_REQUEST",
69
+ rpcName: "createSessionTable",
70
+ params: {
71
+ copyOption
72
+ }
73
+ });
74
+ if (isRpcSuccess(rpcResponse)) {
75
+ const { table: sessionTable } = rpcResponse.data;
76
+ const columns = this.config.columns.includes("vuu_action") ? this.config.columns : this.config.columns.concat("vuu_action");
77
+ const sessionDataSource = this.#vuuModule?.createDataSource(sessionTable.table, sessionTable.table, {
78
+ ...this.config,
79
+ columns
80
+ });
81
+ if (sessionDataSource instanceof TickingArrayDataSource) sessionDataSource.#sourceTableDataSource = this;
82
+ return sessionDataSource;
83
+ }
84
+ throw Error(`[TickingArrayDataSource] createSessionDataSource ${rpcResponse?.errorMessage}`);
85
+ }
86
+ async beginEditSession(editSessionMode = "all-rows") {
87
+ const rpcResponse = await this?.rpcRequest?.({
88
+ type: "RPC_REQUEST",
89
+ rpcName: "beginEditSession",
90
+ params: {
91
+ editSessionMode
92
+ }
93
+ });
94
+ if (isRpcSuccess(rpcResponse)) {
95
+ const { table: sessionTable } = rpcResponse.data;
96
+ const sessionDataSource = this.#vuuModule?.createDataSource(sessionTable.table, sessionTable.table, {
97
+ ...this.config
98
+ });
99
+ if (sessionDataSource instanceof TickingArrayDataSource) sessionDataSource.#sourceTableDataSource = this;
100
+ return sessionDataSource;
101
+ }
102
+ throw Error(`[TickingArrayDataSource] beginEditSession ${rpcResponse?.errorMessage}`);
103
+ }
104
+ async editCell(key, column, data) {
105
+ return this.rpcRequest({
106
+ type: "RPC_REQUEST",
107
+ rpcName: "editCell",
108
+ params: {
109
+ column,
110
+ data,
111
+ key
112
+ }
113
+ });
114
+ }
115
+ addRow = async (rowData = {})=>{
116
+ const response = await this.rpcRequest?.({
117
+ type: "RPC_REQUEST",
118
+ rpcName: "addRow",
119
+ params: {
120
+ key: rowData[this.tableSchema.key],
121
+ data: rowData
122
+ }
123
+ });
124
+ if (isRpcSuccess(response)) return true;
125
+ return response?.errorMessage ?? "addRow failed";
126
+ };
127
+ deleteRow = async (key, mode = "hard")=>{
128
+ const response = await this.rpcRequest({
129
+ type: "RPC_REQUEST",
130
+ rpcName: "deleteRow",
131
+ params: {
132
+ key,
133
+ mode
134
+ }
135
+ });
136
+ if (isRpcSuccess(response)) return true;
137
+ return response?.errorMessage ?? "deleteRow failed";
138
+ };
139
+ deleteSelectedRows = async (mode = "soft")=>{
140
+ const response = await this.rpcRequest({
141
+ type: "RPC_REQUEST",
142
+ rpcName: "deleteSelectedRows",
143
+ params: {
144
+ mode
145
+ }
146
+ });
147
+ return response ?? {
148
+ type: "ERROR_RESULT",
149
+ errorMessage: "deleteSelectedRows failed"
150
+ };
151
+ };
152
+ undoRowChange = async (key)=>{
153
+ const response = await this.rpcRequest({
154
+ type: "RPC_REQUEST",
155
+ rpcName: "undoRowChange",
156
+ params: {
157
+ key
158
+ }
159
+ });
160
+ return response ?? {
161
+ type: "ERROR_RESULT",
162
+ errorMessage: "undoRowChange failed"
163
+ };
164
+ };
165
+ set columns(columns) {
166
+ super.columns = columns;
167
+ }
168
+ get columns() {
169
+ return super.columns;
170
+ }
171
+ async endEditSession(saveChanges = false) {
172
+ const type = "RPC_REQUEST";
173
+ const rpcName = "endEditSession";
174
+ const rpcResponse = await this.rpcRequest(saveChanges ? {
175
+ type,
176
+ rpcName,
177
+ params: {
178
+ save: true
179
+ }
180
+ } : {
181
+ type,
182
+ rpcName,
183
+ params: {}
184
+ });
185
+ if (isRpcSuccess(rpcResponse)) {
186
+ const sourceTableDataSource = this.#sourceTableDataSource;
187
+ if (sourceTableDataSource) {
188
+ this.#sourceTableDataSource = void 0;
189
+ this.unsubscribe();
190
+ } else this.sendRowsToClient(true);
191
+ } else if (rpcResponse?.errorMessage === "stale update") throw new StaleUpdateError(rpcResponse.errorMessage);
192
+ else throw Error(rpcResponse?.errorMessage ?? "endEditSession failed");
193
+ }
194
+ async rpcRequest(rpcRequest) {
195
+ if (isTypeaheadRequest(rpcRequest)) {
196
+ const { params: { column, starts } } = rpcRequest;
197
+ const data = await this.getTypeaheadSuggestions(column, starts);
198
+ return {
199
+ type: "SUCCESS_RESULT",
200
+ data
201
+ };
202
+ }
203
+ {
204
+ const rpcService = this.#rpcServices?.find((service)=>service.rpcName === rpcRequest.rpcName);
205
+ if (rpcService) return rpcService.service({
206
+ ...rpcRequest,
207
+ context: {
208
+ type: "VIEWPORT_CONTEXT",
209
+ viewPortId: this.viewport
210
+ }
211
+ });
212
+ throw Error(`[TickingArrayDataSource] no service to handle RPC request ${rpcRequest.rpcName}`);
213
+ }
214
+ }
215
+ async menuRpcCall(rpcRequest) {
216
+ const rpcService = this.#rpcMenuServices?.find((service)=>service.rpcName === rpcRequest.rpcName);
217
+ if (rpcService) return rpcService.service({
218
+ ...rpcRequest,
219
+ vpId: this.viewport
220
+ });
221
+ throw Error(`[TickingArrayDataSource] menuRpcCall no service for ${rpcRequest.rpcName}`);
222
+ }
223
+ getTypeaheadSuggestions(column, pattern) {
224
+ if (this.#table) {
225
+ const columnIndex = this.columnMap[column];
226
+ if (void 0 !== columnIndex) return makeSuggestions(this.currentData, columnIndex, pattern);
227
+ console.warn(`[TickingArrayDataSource] getTypeaheadSuggestions. No column ${column}`);
228
+ return Promise.resolve([]);
229
+ }
230
+ throw Error("cannot call getTypeaheadSuggestions on TickingDataSource if table has not been provided");
231
+ }
232
+ get visualLink() {
233
+ return this._config.visualLink;
234
+ }
235
+ set visualLink(visualLink) {
236
+ this._config = {
237
+ ...this._config,
238
+ visualLink
239
+ };
240
+ if (visualLink) {
241
+ const { parentClientVpId, link: { fromColumn, toColumn } } = visualLink;
242
+ if (this.viewport) this.#visualLinkService?.({
243
+ childVpId: this.viewport,
244
+ childColumnName: fromColumn,
245
+ type: "CREATE_VISUAL_LINK",
246
+ parentVpId: parentClientVpId,
247
+ parentColumnName: toColumn
248
+ }).then((response)=>{
249
+ this.emit("visual-link-created", response);
250
+ });
251
+ } else this.#visualLinkService?.({
252
+ childVpId: this.viewport,
253
+ type: "REMOVE_VISUAL_LINK"
254
+ }).then(()=>{
255
+ this.emit("visual-link-removed");
256
+ });
257
+ }
258
+ freeze() {
259
+ super.freeze();
260
+ }
261
+ unfreeze() {
262
+ super.unfreeze();
263
+ }
264
+ }
265
+ export { TickingArrayDataSource };
@@ -0,0 +1,72 @@
1
+ import { generateNextBidAsk, nextRandomDouble, random } from "./data-utils.mjs";
2
+ const getNewValue = (value)=>{
3
+ const multiplier = random(0, 100) / 1000;
4
+ const direction = random(0, 10) >= 5 ? 1 : -1;
5
+ return value + value * multiplier * direction;
6
+ };
7
+ class BaseUpdateGenerator {
8
+ table;
9
+ range;
10
+ updating = false;
11
+ timer;
12
+ tickingColumns;
13
+ constructor(tickingColumns){
14
+ this.tickingColumns = tickingColumns;
15
+ }
16
+ setRange(range) {
17
+ this.range = range;
18
+ if (!this.updating && this.table) this.startUpdating();
19
+ }
20
+ setTable(table) {
21
+ this.table = table;
22
+ }
23
+ startUpdating() {
24
+ this.updating = true;
25
+ this.update();
26
+ }
27
+ stopUpdating() {
28
+ this.updating = false;
29
+ if (this.timer) {
30
+ window.clearTimeout(this.timer);
31
+ this.timer = void 0;
32
+ }
33
+ }
34
+ update = ()=>{
35
+ if (this.range && this.table) {
36
+ const data = this.table?.data;
37
+ const { bid, ask, last, ...rest } = this.tickingColumns;
38
+ if (data && data?.length > 0) {
39
+ const maxRange = Math.min(this.range.to, data.length);
40
+ for(let rowIndex = this.range.from; rowIndex < maxRange; rowIndex++){
41
+ let updateCount = 0;
42
+ const shallUpdateRow = random(0, 10) < 2;
43
+ if (shallUpdateRow) {
44
+ const rowUpdates = this.table.data[rowIndex];
45
+ const row = data[rowIndex];
46
+ if (void 0 !== bid && void 0 !== ask) {
47
+ const { [bid]: currentBid, [ask]: currentAsk } = row;
48
+ const [newBid, newAsk] = generateNextBidAsk(currentBid, currentAsk, 10, 5, nextRandomDouble);
49
+ rowUpdates[ask] = newAsk;
50
+ rowUpdates[bid] = newBid;
51
+ if (void 0 !== last) {
52
+ const newLast = Math.round((currentAsk + (newAsk - currentAsk) / 2) * 100) / 100.0;
53
+ rowUpdates[last] = newLast;
54
+ }
55
+ }
56
+ for (const colIdx of Object.values(rest)){
57
+ const shallUpdateColumn = random(0, 10) < 5;
58
+ if (shallUpdateColumn) {
59
+ updateCount += 1;
60
+ const newValue = getNewValue(row[colIdx]);
61
+ if (this.table) rowUpdates[colIdx] = newValue;
62
+ }
63
+ }
64
+ if (this.table && updateCount > 0) this.table.updateRow(rowUpdates);
65
+ }
66
+ }
67
+ }
68
+ }
69
+ if (this.updating) this.timer = window.setTimeout(this.update, 500);
70
+ };
71
+ }
72
+ export { BaseUpdateGenerator };