turbodata 0.1.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 (104) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +27 -0
  3. package/README.md +215 -0
  4. package/dist/compression.d.ts +8 -0
  5. package/dist/compression.d.ts.map +1 -0
  6. package/dist/compression.js +19 -0
  7. package/dist/compression.js.map +1 -0
  8. package/dist/index.d.ts +16 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +23 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/io.d.ts +37 -0
  13. package/dist/io.d.ts.map +1 -0
  14. package/dist/io.js +174 -0
  15. package/dist/io.js.map +1 -0
  16. package/dist/iterators/message_heap.d.ts +17 -0
  17. package/dist/iterators/message_heap.d.ts.map +1 -0
  18. package/dist/iterators/message_heap.js +83 -0
  19. package/dist/iterators/message_heap.js.map +1 -0
  20. package/dist/iterators/preloaded_topics_group_iterator.d.ts +38 -0
  21. package/dist/iterators/preloaded_topics_group_iterator.d.ts.map +1 -0
  22. package/dist/iterators/preloaded_topics_group_iterator.js +109 -0
  23. package/dist/iterators/preloaded_topics_group_iterator.js.map +1 -0
  24. package/dist/iterators/topics_group_iterator.d.ts +45 -0
  25. package/dist/iterators/topics_group_iterator.d.ts.map +1 -0
  26. package/dist/iterators/topics_group_iterator.js +132 -0
  27. package/dist/iterators/topics_group_iterator.js.map +1 -0
  28. package/dist/loaded_bytes.d.ts +12 -0
  29. package/dist/loaded_bytes.d.ts.map +1 -0
  30. package/dist/loaded_bytes.js +43 -0
  31. package/dist/loaded_bytes.js.map +1 -0
  32. package/dist/msgpack.d.ts +10 -0
  33. package/dist/msgpack.d.ts.map +1 -0
  34. package/dist/msgpack.js +44 -0
  35. package/dist/msgpack.js.map +1 -0
  36. package/dist/multi_reader.d.ts +56 -0
  37. package/dist/multi_reader.d.ts.map +1 -0
  38. package/dist/multi_reader.js +281 -0
  39. package/dist/multi_reader.js.map +1 -0
  40. package/dist/read_fetcher.d.ts +9 -0
  41. package/dist/read_fetcher.d.ts.map +1 -0
  42. package/dist/read_fetcher.js +59 -0
  43. package/dist/read_fetcher.js.map +1 -0
  44. package/dist/read_options.d.ts +40 -0
  45. package/dist/read_options.d.ts.map +1 -0
  46. package/dist/read_options.js +16 -0
  47. package/dist/read_options.js.map +1 -0
  48. package/dist/read_planner.d.ts +37 -0
  49. package/dist/read_planner.d.ts.map +1 -0
  50. package/dist/read_planner.js +110 -0
  51. package/dist/read_planner.js.map +1 -0
  52. package/dist/read_source.d.ts +19 -0
  53. package/dist/read_source.d.ts.map +1 -0
  54. package/dist/read_source.js +15 -0
  55. package/dist/read_source.js.map +1 -0
  56. package/dist/read_strategy.d.ts +52 -0
  57. package/dist/read_strategy.d.ts.map +1 -0
  58. package/dist/read_strategy.js +70 -0
  59. package/dist/read_strategy.js.map +1 -0
  60. package/dist/reader.d.ts +209 -0
  61. package/dist/reader.d.ts.map +1 -0
  62. package/dist/reader.js +649 -0
  63. package/dist/reader.js.map +1 -0
  64. package/dist/sample.d.ts +41 -0
  65. package/dist/sample.d.ts.map +1 -0
  66. package/dist/sample.js +528 -0
  67. package/dist/sample.js.map +1 -0
  68. package/dist/sort_and_filter.d.ts +25 -0
  69. package/dist/sort_and_filter.d.ts.map +1 -0
  70. package/dist/sort_and_filter.js +126 -0
  71. package/dist/sort_and_filter.js.map +1 -0
  72. package/dist/sources/blob.d.ts +8 -0
  73. package/dist/sources/blob.d.ts.map +1 -0
  74. package/dist/sources/blob.js +38 -0
  75. package/dist/sources/blob.js.map +1 -0
  76. package/dist/sources/http.d.ts +17 -0
  77. package/dist/sources/http.d.ts.map +1 -0
  78. package/dist/sources/http.js +90 -0
  79. package/dist/sources/http.js.map +1 -0
  80. package/dist/types.d.ts +75 -0
  81. package/dist/types.d.ts.map +1 -0
  82. package/dist/types.js +29 -0
  83. package/dist/types.js.map +1 -0
  84. package/package.json +61 -0
  85. package/src/compression.ts +28 -0
  86. package/src/index.ts +70 -0
  87. package/src/io.ts +214 -0
  88. package/src/iterators/message_heap.ts +104 -0
  89. package/src/iterators/preloaded_topics_group_iterator.ts +143 -0
  90. package/src/iterators/topics_group_iterator.ts +180 -0
  91. package/src/loaded_bytes.ts +61 -0
  92. package/src/msgpack.ts +46 -0
  93. package/src/multi_reader.ts +337 -0
  94. package/src/read_fetcher.ts +74 -0
  95. package/src/read_options.ts +58 -0
  96. package/src/read_planner.ts +153 -0
  97. package/src/read_source.ts +33 -0
  98. package/src/read_strategy.ts +111 -0
  99. package/src/reader.ts +910 -0
  100. package/src/sample.ts +715 -0
  101. package/src/sort_and_filter.ts +167 -0
  102. package/src/sources/blob.ts +52 -0
  103. package/src/sources/http.ts +121 -0
  104. package/src/types.ts +110 -0
@@ -0,0 +1,111 @@
1
+ // Copyright 2026 Wanjia He
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ // ReadStrategy: knobs for the cost-aware reader path. Mirrors
16
+ // go/read_strategy.go.
17
+
18
+ export interface ReadStrategy {
19
+ /**
20
+ * int64. Byte gap below which two adjacent needed ranges are merged into
21
+ * a single read. 0n disables coalescing.
22
+ */
23
+ coalesceGap: bigint;
24
+
25
+ /**
26
+ * int64. Size above which a merged read is sliced into parallel sub-reads
27
+ * at internal range boundaries. A single range larger than splitThreshold
28
+ * stays as one oversized op (atomic units are never split). 0n or
29
+ * int64-max disables splitting.
30
+ */
31
+ splitThreshold: bigint;
32
+
33
+ /** Max number of in-flight reads. <= 0 is clamped to 1 (serial). */
34
+ maxConcurrency: number;
35
+ }
36
+
37
+ const MAX_INT64 = 0x7fffffffffffffffn;
38
+
39
+ /**
40
+ * Strategy that minimizes wall-clock by amortizing per-request RTT and
41
+ * splitting reads at the bandwidth-latency product so each parallel sub-read
42
+ * keeps a stream saturated for ~one RTT.
43
+ */
44
+ export function StrategyForLatency(opts: {
45
+ rttSeconds: number;
46
+ perStreamBytesPerSec: number;
47
+ concurrency: number;
48
+ }): ReadStrategy {
49
+ let bdp = BigInt(Math.trunc(opts.rttSeconds * opts.perStreamBytesPerSec));
50
+ if (bdp <= 0n) {
51
+ bdp = 1n;
52
+ }
53
+ return {
54
+ coalesceGap: bdp,
55
+ splitThreshold: bdp,
56
+ maxConcurrency: opts.concurrency,
57
+ };
58
+ }
59
+
60
+ /**
61
+ * Strategy that minimizes total spend by aggressively coalescing (to save
62
+ * requests) and never splitting (extra splits = extra paid requests).
63
+ *
64
+ * Set bytePrice to 0 for free in-region egress; then coalescing happens
65
+ * regardless of gap.
66
+ */
67
+ export function StrategyForMoney(opts: {
68
+ reqPrice: number;
69
+ bytePrice: number;
70
+ concurrency: number;
71
+ }): ReadStrategy {
72
+ let gap = MAX_INT64;
73
+ if (opts.bytePrice > 0) {
74
+ gap = BigInt(Math.trunc(opts.reqPrice / opts.bytePrice));
75
+ }
76
+ return {
77
+ coalesceGap: gap,
78
+ splitThreshold: MAX_INT64,
79
+ maxConcurrency: opts.concurrency,
80
+ };
81
+ }
82
+
83
+ /**
84
+ * Strategy that minimizes spend (via the same money-driven coalesceGap as
85
+ * StrategyForMoney) but caps how long any single read may take by splitting
86
+ * reads larger than maxReadTimeSeconds * perStreamBytesPerSec into parallel
87
+ * sub-reads.
88
+ */
89
+ export function StrategyForBlended(opts: {
90
+ reqPrice: number;
91
+ bytePrice: number;
92
+ maxReadTimeSeconds: number;
93
+ perStreamBytesPerSec: number;
94
+ concurrency: number;
95
+ }): ReadStrategy {
96
+ let gap = MAX_INT64;
97
+ if (opts.bytePrice > 0) {
98
+ gap = BigInt(Math.trunc(opts.reqPrice / opts.bytePrice));
99
+ }
100
+ let split = BigInt(
101
+ Math.trunc(opts.maxReadTimeSeconds * opts.perStreamBytesPerSec),
102
+ );
103
+ if (split <= 0n) {
104
+ split = MAX_INT64;
105
+ }
106
+ return {
107
+ coalesceGap: gap,
108
+ splitThreshold: split,
109
+ maxConcurrency: opts.concurrency,
110
+ };
111
+ }