@evolu/common 8.0.0-next.4 → 8.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 (237) hide show
  1. package/dist/src/Array.d.ts +279 -173
  2. package/dist/src/Array.d.ts.map +1 -1
  3. package/dist/src/Array.js +105 -101
  4. package/dist/src/Assert.d.ts +44 -44
  5. package/dist/src/Assert.d.ts.map +1 -1
  6. package/dist/src/Assert.js +44 -32
  7. package/dist/src/BigInt.d.ts +6 -3
  8. package/dist/src/BigInt.d.ts.map +1 -1
  9. package/dist/src/BigInt.js +5 -2
  10. package/dist/src/Brand.d.ts +27 -40
  11. package/dist/src/Brand.d.ts.map +1 -1
  12. package/dist/src/Buffer.d.ts +27 -11
  13. package/dist/src/Buffer.d.ts.map +1 -1
  14. package/dist/src/Cache.d.ts +9 -4
  15. package/dist/src/Cache.d.ts.map +1 -1
  16. package/dist/src/Cache.js +8 -3
  17. package/dist/src/Callbacks.d.ts +30 -19
  18. package/dist/src/Callbacks.d.ts.map +1 -1
  19. package/dist/src/Console.d.ts +145 -66
  20. package/dist/src/Console.d.ts.map +1 -1
  21. package/dist/src/Console.js +91 -43
  22. package/dist/src/Crypto.d.ts +85 -42
  23. package/dist/src/Crypto.d.ts.map +1 -1
  24. package/dist/src/Crypto.js +44 -20
  25. package/dist/src/Eq.d.ts +87 -21
  26. package/dist/src/Eq.d.ts.map +1 -1
  27. package/dist/src/Eq.js +67 -19
  28. package/dist/src/Error.d.ts +5 -3
  29. package/dist/src/Error.d.ts.map +1 -1
  30. package/dist/src/Error.js +16 -0
  31. package/dist/src/Function.d.ts +119 -58
  32. package/dist/src/Function.d.ts.map +1 -1
  33. package/dist/src/Function.js +86 -43
  34. package/dist/src/Http.d.ts +394 -0
  35. package/dist/src/Http.d.ts.map +1 -0
  36. package/dist/src/Http.js +102 -0
  37. package/dist/src/Identicon.d.ts +16 -7
  38. package/dist/src/Identicon.d.ts.map +1 -1
  39. package/dist/src/Identicon.js +14 -5
  40. package/dist/src/LeakDetector.d.ts +88 -0
  41. package/dist/src/LeakDetector.d.ts.map +1 -0
  42. package/dist/src/LeakDetector.js +86 -0
  43. package/dist/src/LockManager.d.ts +18 -9
  44. package/dist/src/LockManager.d.ts.map +1 -1
  45. package/dist/src/LockManager.js +7 -8
  46. package/dist/src/Lookup.d.ts +43 -13
  47. package/dist/src/Lookup.d.ts.map +1 -1
  48. package/dist/src/Lookup.js +28 -8
  49. package/dist/src/Microtask.d.ts +1 -1
  50. package/dist/src/Microtask.d.ts.map +1 -1
  51. package/dist/src/Microtask.js +3 -7
  52. package/dist/src/Number.d.ts +49 -13
  53. package/dist/src/Number.d.ts.map +1 -1
  54. package/dist/src/Number.js +34 -5
  55. package/dist/src/Object.d.ts +160 -40
  56. package/dist/src/Object.d.ts.map +1 -1
  57. package/dist/src/Object.js +92 -46
  58. package/dist/src/Option.d.ts +10 -7
  59. package/dist/src/Option.d.ts.map +1 -1
  60. package/dist/src/Option.js +9 -6
  61. package/dist/src/Order.d.ts +21 -21
  62. package/dist/src/Order.d.ts.map +1 -1
  63. package/dist/src/Order.js +18 -21
  64. package/dist/src/Platform.d.ts +31 -0
  65. package/dist/src/Platform.d.ts.map +1 -1
  66. package/dist/src/Platform.js +98 -0
  67. package/dist/src/Random.d.ts +32 -17
  68. package/dist/src/Random.d.ts.map +1 -1
  69. package/dist/src/Random.js +12 -8
  70. package/dist/src/Redacted.d.ts +43 -29
  71. package/dist/src/Redacted.d.ts.map +1 -1
  72. package/dist/src/Redacted.js +14 -3
  73. package/dist/src/Ref.d.ts +11 -3
  74. package/dist/src/Ref.d.ts.map +1 -1
  75. package/dist/src/Ref.js +2 -2
  76. package/dist/src/RefCount.d.ts +2 -6
  77. package/dist/src/RefCount.d.ts.map +1 -1
  78. package/dist/src/RefCount.js +33 -90
  79. package/dist/src/Relation.d.ts +70 -5
  80. package/dist/src/Relation.d.ts.map +1 -1
  81. package/dist/src/Relation.js +77 -2
  82. package/dist/src/Resource.d.ts +590 -155
  83. package/dist/src/Resource.d.ts.map +1 -1
  84. package/dist/src/Resource.js +592 -343
  85. package/dist/src/Result.d.ts +838 -191
  86. package/dist/src/Result.d.ts.map +1 -1
  87. package/dist/src/Result.js +163 -102
  88. package/dist/src/Schedule.d.ts +684 -231
  89. package/dist/src/Schedule.d.ts.map +1 -1
  90. package/dist/src/Schedule.js +766 -295
  91. package/dist/src/Set.d.ts +89 -40
  92. package/dist/src/Set.d.ts.map +1 -1
  93. package/dist/src/Set.js +50 -29
  94. package/dist/src/Sqlite.d.ts +29 -72
  95. package/dist/src/Sqlite.d.ts.map +1 -1
  96. package/dist/src/Sqlite.js +41 -46
  97. package/dist/src/StackTrace.d.ts +40 -0
  98. package/dist/src/StackTrace.d.ts.map +1 -0
  99. package/dist/src/StackTrace.js +140 -0
  100. package/dist/src/Store.d.ts +5 -4
  101. package/dist/src/Store.d.ts.map +1 -1
  102. package/dist/src/Store.js +5 -4
  103. package/dist/src/String.d.ts +7 -1
  104. package/dist/src/String.d.ts.map +1 -1
  105. package/dist/src/String.js +20 -7
  106. package/dist/src/Task.d.ts +3572 -1770
  107. package/dist/src/Task.d.ts.map +1 -1
  108. package/dist/src/Task.js +1879 -1274
  109. package/dist/src/Test.d.ts +17 -125
  110. package/dist/src/Test.d.ts.map +1 -1
  111. package/dist/src/Test.js +17 -68
  112. package/dist/src/Time.d.ts +108 -49
  113. package/dist/src/Time.d.ts.map +1 -1
  114. package/dist/src/Time.js +172 -73
  115. package/dist/src/Type.d.ts +3542 -1926
  116. package/dist/src/Type.d.ts.map +1 -1
  117. package/dist/src/Type.js +3070 -1784
  118. package/dist/src/Types.d.ts +200 -108
  119. package/dist/src/Types.d.ts.map +1 -1
  120. package/dist/src/Types.js +39 -8
  121. package/dist/src/WebSocket.d.ts +48 -23
  122. package/dist/src/WebSocket.d.ts.map +1 -1
  123. package/dist/src/WebSocket.js +15 -6
  124. package/dist/src/Worker.d.ts +94 -36
  125. package/dist/src/Worker.d.ts.map +1 -1
  126. package/dist/src/Worker.js +58 -24
  127. package/dist/src/index.d.ts +55 -52
  128. package/dist/src/index.d.ts.map +1 -1
  129. package/dist/src/index.js +3 -1
  130. package/dist/src/intl/cs.d.ts +94 -0
  131. package/dist/src/intl/cs.d.ts.map +1 -0
  132. package/dist/src/intl/cs.js +220 -0
  133. package/dist/src/intl/index.d.ts +7 -0
  134. package/dist/src/intl/index.d.ts.map +1 -0
  135. package/dist/src/intl/index.js +6 -0
  136. package/dist/src/local-first/Db.d.ts +12 -8
  137. package/dist/src/local-first/Db.d.ts.map +1 -1
  138. package/dist/src/local-first/Db.js +109 -132
  139. package/dist/src/local-first/Error.d.ts +4 -4
  140. package/dist/src/local-first/Evolu.d.ts +338 -92
  141. package/dist/src/local-first/Evolu.d.ts.map +1 -1
  142. package/dist/src/local-first/Evolu.js +47 -55
  143. package/dist/src/local-first/LocalAuth.d.ts +4 -4
  144. package/dist/src/local-first/LocalAuth.d.ts.map +1 -1
  145. package/dist/src/local-first/Owner.d.ts +61 -24
  146. package/dist/src/local-first/Owner.d.ts.map +1 -1
  147. package/dist/src/local-first/Owner.js +45 -8
  148. package/dist/src/local-first/Protocol.d.ts +44 -31
  149. package/dist/src/local-first/Protocol.d.ts.map +1 -1
  150. package/dist/src/local-first/Protocol.js +36 -13
  151. package/dist/src/local-first/Query.d.ts +147 -62
  152. package/dist/src/local-first/Query.d.ts.map +1 -1
  153. package/dist/src/local-first/Query.js +112 -58
  154. package/dist/src/local-first/Relay.d.ts +44 -14
  155. package/dist/src/local-first/Relay.d.ts.map +1 -1
  156. package/dist/src/local-first/Schema.d.ts +92 -41
  157. package/dist/src/local-first/Schema.d.ts.map +1 -1
  158. package/dist/src/local-first/Schema.js +25 -8
  159. package/dist/src/local-first/Shared.d.ts +23 -21
  160. package/dist/src/local-first/Shared.d.ts.map +1 -1
  161. package/dist/src/local-first/Shared.js +100 -57
  162. package/dist/src/local-first/Storage.d.ts +53 -32
  163. package/dist/src/local-first/Storage.d.ts.map +1 -1
  164. package/dist/src/local-first/Storage.js +194 -234
  165. package/dist/src/local-first/Timestamp.d.ts +21 -21
  166. package/dist/src/local-first/Timestamp.d.ts.map +1 -1
  167. package/dist/src/local-first/Timestamp.js +2 -2
  168. package/dist/src/local-first/index.d.ts +11 -11
  169. package/package.json +14 -13
  170. package/src/Array.ts +306 -205
  171. package/src/Assert.ts +54 -69
  172. package/src/BigInt.ts +6 -3
  173. package/src/Brand.ts +27 -40
  174. package/src/Buffer.ts +28 -12
  175. package/src/Cache.ts +9 -4
  176. package/src/Callbacks.ts +30 -19
  177. package/src/Console.ts +156 -84
  178. package/src/Crypto.ts +83 -41
  179. package/src/Eq.ts +95 -22
  180. package/src/Error.ts +8 -4
  181. package/src/Function.ts +167 -59
  182. package/src/Http.ts +549 -0
  183. package/src/Identicon.ts +16 -7
  184. package/src/LeakDetector.ts +182 -0
  185. package/src/LockManager.ts +43 -39
  186. package/src/Lookup.ts +62 -28
  187. package/src/Microtask.ts +19 -23
  188. package/src/Number.ts +64 -12
  189. package/src/Object.ts +173 -49
  190. package/src/Option.ts +10 -7
  191. package/src/Order.ts +23 -21
  192. package/src/Platform.ts +136 -0
  193. package/src/Polyfills.ts +6 -12
  194. package/src/Random.ts +32 -19
  195. package/src/Redacted.ts +44 -30
  196. package/src/Ref.ts +14 -6
  197. package/src/RefCount.ts +38 -80
  198. package/src/Relation.ts +202 -10
  199. package/src/Resource.ts +1199 -591
  200. package/src/Result.ts +930 -271
  201. package/src/Schedule.ts +859 -343
  202. package/src/Set.ts +89 -40
  203. package/src/Sqlite.ts +144 -138
  204. package/src/StackTrace.ts +230 -0
  205. package/src/Store.ts +8 -7
  206. package/src/String.ts +22 -5
  207. package/src/Task.ts +5101 -2832
  208. package/src/Test.ts +20 -168
  209. package/src/Time.ts +293 -90
  210. package/src/Type.ts +10034 -4117
  211. package/src/Types.ts +227 -110
  212. package/src/WebSocket.ts +64 -36
  213. package/src/Worker.ts +180 -72
  214. package/src/index.ts +55 -52
  215. package/src/intl/cs.ts +388 -0
  216. package/src/intl/index.ts +7 -0
  217. package/src/local-first/Db.ts +152 -179
  218. package/src/local-first/Error.ts +4 -4
  219. package/src/local-first/Evolu.ts +495 -250
  220. package/src/local-first/LocalAuth.ts +6 -12
  221. package/src/local-first/Owner.ts +58 -21
  222. package/src/local-first/Protocol.ts +49 -31
  223. package/src/local-first/Query.ts +146 -61
  224. package/src/local-first/Relay.ts +51 -21
  225. package/src/local-first/Schema.ts +109 -51
  226. package/src/local-first/Shared.ts +266 -226
  227. package/src/local-first/Storage.ts +266 -264
  228. package/src/local-first/Timestamp.ts +25 -18
  229. package/src/local-first/index.ts +11 -11
  230. package/dist/src/Skiplist.d.ts +0 -28
  231. package/dist/src/Skiplist.d.ts.map +0 -1
  232. package/dist/src/Skiplist.js +0 -64
  233. package/dist/src/Tracer.d.ts +0 -48
  234. package/dist/src/Tracer.d.ts.map +0 -1
  235. package/dist/src/Tracer.js +0 -6
  236. package/src/Skiplist.ts +0 -108
  237. package/src/Tracer.ts +0 -54
@@ -4,27 +4,30 @@
4
4
  * @module
5
5
  */
6
6
 
7
- import { bytesToHex } from "../Buffer.js";
8
- import type { RandomBytesDep } from "../Crypto.js";
9
- import { createEqObject, eqNumber, eqString } from "../Eq.js";
10
- import { increment } from "../Number.js";
11
- import type { Order } from "../Order.js";
12
- import { orderUint8Array } from "../Order.js";
13
- import type { Result } from "../Result.js";
14
- import { err, ok } from "../Result.js";
15
- import type { TimeDep } from "../Time.js";
16
- import { Millis, minMillis } from "../Time.js";
17
- import type { DateIso, InferType, Typed } from "../Type.js";
7
+ import { bytesToHex } from "../Buffer.ts";
8
+ import type { RandomBytesDep } from "../Crypto.ts";
9
+ import { createEqObject, eqNumber, eqString } from "../Eq.ts";
10
+ import { increment } from "../Number.ts";
11
+ import type { Order } from "../Order.ts";
12
+ import { orderUint8Array } from "../Order.ts";
13
+ import type { Result } from "../Result.ts";
14
+ import { err, ok } from "../Result.ts";
15
+ import type { TimeDep } from "../Time.ts";
16
+ import { Millis, minMillis } from "../Time.ts";
18
17
  import {
19
18
  brand,
19
+ type DateIso,
20
+ type InferType,
20
21
  length,
21
22
  lessThanOrEqualTo,
22
23
  NonNegativeInt,
23
24
  object,
25
+ type ObjectType,
24
26
  regex,
25
27
  String,
28
+ type Typed,
26
29
  Uint8Array,
27
- } from "../Type.js";
30
+ } from "../Type.ts";
28
31
 
29
32
  export interface TimestampConfig {
30
33
  /**
@@ -60,7 +63,7 @@ export const Counter = /*#__PURE__*/ brand(
60
63
  "Counter",
61
64
  /*#__PURE__*/ lessThanOrEqualTo(65535)(NonNegativeInt),
62
65
  );
63
- export type Counter = typeof Counter.Type;
66
+ export type Counter = typeof Counter.Output;
64
67
 
65
68
  export const minCounter = 0 as Counter;
66
69
  export const maxCounter = 65535 as Counter;
@@ -91,7 +94,7 @@ export const maxCounter = 65535 as Counter;
91
94
  * resolved by resetting one device to generate a new NodeId.
92
95
  */
93
96
  export const NodeId = /*#__PURE__*/ regex("NodeId", /^[a-f0-9]{16}$/)(String);
94
- export type NodeId = typeof NodeId.Type;
97
+ export type NodeId = typeof NodeId.Output;
95
98
 
96
99
  export const minNodeId = "0000000000000000" as NodeId;
97
100
  export const maxNodeId = "ffffffffffffffff" as NodeId;
@@ -156,7 +159,11 @@ export const maxNodeId = "ffffffffffffffff" as NodeId;
156
159
  * real usage patterns. This preserves real-time collaboration but increases
157
160
  * storage and bandwidth usage.
158
161
  */
159
- export const Timestamp = /*#__PURE__*/ object({
162
+ export const Timestamp: ObjectType<{
163
+ readonly millis: typeof Millis;
164
+ readonly counter: typeof Counter;
165
+ readonly nodeId: typeof NodeId;
166
+ }> = /*#__PURE__*/ object({
160
167
  millis: Millis,
161
168
  counter: Counter,
162
169
  nodeId: NodeId,
@@ -186,7 +193,7 @@ const getNextMillis =
186
193
  (
187
194
  millis: ReadonlyArray<Millis>,
188
195
  ): Result<Millis, TimestampTimeOutOfRangeError | TimestampDriftError> => {
189
- const now = Millis.from(deps.time.now());
196
+ const now = Millis.fromUnknown(deps.time.now());
190
197
  if (!now.ok) {
191
198
  return err({ type: "TimestampTimeOutOfRangeError" });
192
199
  }
@@ -203,7 +210,7 @@ const getNextMillis =
203
210
  const incrementCounter = (
204
211
  counter: Counter,
205
212
  ): Result<Counter, TimestampCounterOverflowError> => {
206
- const next = Counter.from(increment(counter));
213
+ const next = Counter.fromUnknown(increment(counter));
207
214
  if (!next.ok) return err({ type: "TimestampCounterOverflowError" });
208
215
  return ok(next.value);
209
216
  };
@@ -271,7 +278,7 @@ export const TimestampBytes = /*#__PURE__*/ brand(
271
278
  "TimestampBytes",
272
279
  /*#__PURE__*/ length(16)(Uint8Array),
273
280
  );
274
- export type TimestampBytes = typeof TimestampBytes.Type;
281
+ export type TimestampBytes = typeof TimestampBytes.Output;
275
282
 
276
283
  export const timestampBytesLength = /*#__PURE__*/ NonNegativeInt.orThrow(16);
277
284
 
@@ -1,11 +1,11 @@
1
- export * from "./Db.js";
2
- export * from "./Error.js";
3
- export * from "./Evolu.js";
4
- export * from "./Owner.js";
5
- export * from "./Protocol.js";
6
- export * from "./Query.js";
7
- export * from "./Relay.js";
8
- export * from "./Schema.js";
9
- export * from "./Shared.js";
10
- export * from "./Storage.js";
11
- export * from "./Timestamp.js";
1
+ export * from "./Db.ts";
2
+ export * from "./Error.ts";
3
+ export * from "./Evolu.ts";
4
+ export * from "./Owner.ts";
5
+ export * from "./Protocol.ts";
6
+ export * from "./Query.ts";
7
+ export * from "./Relay.ts";
8
+ export * from "./Schema.ts";
9
+ export * from "./Shared.ts";
10
+ export * from "./Storage.ts";
11
+ export * from "./Timestamp.ts";
@@ -1,28 +0,0 @@
1
- /**
2
- * Skiplist data structure with probabilistic level generation.
3
- *
4
- * @module
5
- */
6
- import type { RandomDep } from "./Random.js";
7
- import { PositiveInt } from "./Type.js";
8
- export interface SkiplistLevel {
9
- readonly create: () => PositiveInt;
10
- }
11
- export interface SkiplistLevelDep {
12
- readonly skiplistLevel: SkiplistLevel;
13
- }
14
- export interface SkiplistLevelConfig {
15
- readonly probability?: number;
16
- readonly maxLevel?: number;
17
- }
18
- export declare const createSkiplistLevel: (deps: RandomDep) => (config?: SkiplistLevelConfig) => SkiplistLevel;
19
- export interface Skiplist {
20
- readonly insert: (key: number) => void;
21
- readonly find: (key: number) => SkiplistNode | null;
22
- }
23
- export interface SkiplistNode {
24
- readonly key: number;
25
- readonly pointers: Array<SkiplistNode>;
26
- }
27
- export declare const createSkiplist: (deps: SkiplistLevelDep) => Skiplist;
28
- //# sourceMappingURL=Skiplist.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Skiplist.d.ts","sourceRoot":"","sources":["../../src/Skiplist.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,WAAW,CAAC;CACpC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;CACvC;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAGD,eAAO,MAAM,mBAAmB,GAC7B,MAAM,SAAS,MACf,SAAQ,mBAAwB,KAAG,aAWnC,CAAC;AAEJ,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,YAAY,GAAG,IAAI,CAAC;CACrD;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;CACxC;AAED,eAAO,MAAM,cAAc,GAAI,MAAM,gBAAgB,KAAG,QA2DvD,CAAC"}
@@ -1,64 +0,0 @@
1
- /**
2
- * Skiplist data structure with probabilistic level generation.
3
- *
4
- * @module
5
- */
6
- import { PositiveInt } from "./Type.js";
7
- // TODO: Use in Storage.
8
- export const createSkiplistLevel = (deps) => (config = {}) => {
9
- const { probability = 0.5, maxLevel = 32 } = config;
10
- return {
11
- create: () => {
12
- let level = 1;
13
- while (deps.random.next() <= probability && level < maxLevel) {
14
- level += 1;
15
- }
16
- return PositiveInt.orThrow(level);
17
- },
18
- };
19
- };
20
- export const createSkiplist = (deps) => {
21
- const tail = {
22
- key: Number.MAX_VALUE,
23
- pointers: [],
24
- };
25
- const head = {
26
- key: Number.MIN_VALUE,
27
- pointers: [tail],
28
- };
29
- // Cached to reuse the array.
30
- const path = [];
31
- return {
32
- insert: (key) => {
33
- let cur = head;
34
- for (let i = head.pointers.length - 1; i >= 0; i--) {
35
- while (cur.pointers[i].key < key) {
36
- cur = cur.pointers[i];
37
- }
38
- path[i] = cur;
39
- }
40
- const level = deps.skiplistLevel.create();
41
- if (level > head.pointers.length) {
42
- const tails = Array(level - head.pointers.length).fill(tail);
43
- const heads = Array(level - head.pointers.length).fill(head);
44
- head.pointers.push(...tails);
45
- path.push(...heads);
46
- }
47
- const newNode = { key, pointers: [] };
48
- for (let i = 0; i < level; i++) {
49
- newNode.pointers[i] = path[i].pointers[i];
50
- path[i].pointers[i] = newNode;
51
- }
52
- },
53
- find: (key) => {
54
- let cur = head;
55
- for (let i = head.pointers.length - 1; i >= 0; i--) {
56
- while (cur.pointers[i] && cur.pointers[i].key < key) {
57
- cur = cur.pointers[i];
58
- }
59
- }
60
- const candidate = cur.pointers[0];
61
- return candidate.key === key ? candidate : null;
62
- },
63
- };
64
- };
@@ -1,48 +0,0 @@
1
- /**
2
- * Minimal tracer interface for observability.
3
- *
4
- * @module
5
- */
6
- import type { Ref } from "./Ref.js";
7
- /**
8
- * Minimal tracer interface for observability.
9
- *
10
- * Tracer provides unified observability for both sync and async code. Use it
11
- * directly for sync operations, or let {@link Run} use it automatically for
12
- * async tasks.
13
- *
14
- * ### Example
15
- *
16
- * ```ts
17
- * // Sync code — use tracer directly
18
- * const result = deps.tracer?.span("parseData", () => parseData(input));
19
- *
20
- * // Async code — Run traces automatically
21
- * await using run = createRun(deps);
22
- * const result = await run(fetchUser(id)); // Traced if tracer provided
23
- * ```
24
- *
25
- * TODO: Complete implementation with OpenTelemetry adapter.
26
- */
27
- export interface Tracer {
28
- /**
29
- * Wraps a sync function in a traced span.
30
- *
31
- * Records start time, end time, and success/failure status.
32
- */
33
- readonly span: <T>(name: string, fn: () => T) => T;
34
- /** Records an event/fact (e.g., "user.purchased", "sync.completed"). */
35
- readonly event: (name: string, data?: unknown) => void;
36
- }
37
- export interface TracerDep {
38
- readonly tracer: Tracer;
39
- }
40
- /** Configuration for tracing. */
41
- export interface TracerConfig {
42
- /** When `true`, enables trace data collection. Can be toggled at runtime. */
43
- readonly tracing?: Ref<boolean>;
44
- }
45
- export interface TracerConfigDep {
46
- readonly tracerConfig: TracerConfig;
47
- }
48
- //# sourceMappingURL=Tracer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Tracer.d.ts","sourceRoot":"","sources":["../../src/Tracer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAGpC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,MAAM;IACrB;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IAEnD,wEAAwE;IACxE,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CACxD;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,iCAAiC;AACjC,MAAM,WAAW,YAAY;IAC3B,6EAA6E;IAC7E,QAAQ,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;CACrC"}
@@ -1,6 +0,0 @@
1
- /**
2
- * Minimal tracer interface for observability.
3
- *
4
- * @module
5
- */
6
- export {};
package/src/Skiplist.ts DELETED
@@ -1,108 +0,0 @@
1
- /**
2
- * Skiplist data structure with probabilistic level generation.
3
- *
4
- * @module
5
- */
6
-
7
- import type { RandomDep } from "./Random.js";
8
- import { PositiveInt } from "./Type.js";
9
-
10
- export interface SkiplistLevel {
11
- readonly create: () => PositiveInt;
12
- }
13
-
14
- export interface SkiplistLevelDep {
15
- readonly skiplistLevel: SkiplistLevel;
16
- }
17
-
18
- export interface SkiplistLevelConfig {
19
- readonly probability?: number;
20
- readonly maxLevel?: number;
21
- }
22
-
23
- // TODO: Use in Storage.
24
- export const createSkiplistLevel =
25
- (deps: RandomDep) =>
26
- (config: SkiplistLevelConfig = {}): SkiplistLevel => {
27
- const { probability = 0.5, maxLevel = 32 } = config;
28
- return {
29
- create: () => {
30
- let level = 1;
31
- while (deps.random.next() <= probability && level < maxLevel) {
32
- level += 1;
33
- }
34
- return PositiveInt.orThrow(level);
35
- },
36
- };
37
- };
38
-
39
- export interface Skiplist {
40
- readonly insert: (key: number) => void;
41
- readonly find: (key: number) => SkiplistNode | null;
42
- }
43
-
44
- export interface SkiplistNode {
45
- readonly key: number;
46
- readonly pointers: Array<SkiplistNode>;
47
- }
48
-
49
- export const createSkiplist = (deps: SkiplistLevelDep): Skiplist => {
50
- const tail: SkiplistNode = {
51
- key: Number.MAX_VALUE,
52
- pointers: [],
53
- };
54
-
55
- const head: SkiplistNode = {
56
- key: Number.MIN_VALUE,
57
- pointers: [tail],
58
- };
59
-
60
- // Cached to reuse the array.
61
- const path: Array<SkiplistNode> = [];
62
-
63
- return {
64
- insert: (key) => {
65
- let cur = head;
66
-
67
- for (let i = head.pointers.length - 1; i >= 0; i--) {
68
- while (cur.pointers[i].key < key) {
69
- cur = cur.pointers[i];
70
- }
71
- path[i] = cur;
72
- }
73
-
74
- const level = deps.skiplistLevel.create();
75
-
76
- if (level > head.pointers.length) {
77
- const tails = Array<SkiplistNode>(level - head.pointers.length).fill(
78
- tail,
79
- );
80
- const heads = Array<SkiplistNode>(level - head.pointers.length).fill(
81
- head,
82
- );
83
- head.pointers.push(...tails);
84
- path.push(...heads);
85
- }
86
-
87
- const newNode: SkiplistNode = { key, pointers: [] };
88
-
89
- for (let i = 0; i < level; i++) {
90
- newNode.pointers[i] = path[i].pointers[i];
91
- path[i].pointers[i] = newNode;
92
- }
93
- },
94
-
95
- find: (key) => {
96
- let cur = head;
97
-
98
- for (let i = head.pointers.length - 1; i >= 0; i--) {
99
- while (cur.pointers[i] && cur.pointers[i].key < key) {
100
- cur = cur.pointers[i];
101
- }
102
- }
103
-
104
- const candidate = cur.pointers[0];
105
- return candidate.key === key ? candidate : null;
106
- },
107
- };
108
- };
package/src/Tracer.ts DELETED
@@ -1,54 +0,0 @@
1
- /**
2
- * Minimal tracer interface for observability.
3
- *
4
- * @module
5
- */
6
-
7
- import type { Ref } from "./Ref.js";
8
- import type { Run } from "./Task.js";
9
-
10
- /**
11
- * Minimal tracer interface for observability.
12
- *
13
- * Tracer provides unified observability for both sync and async code. Use it
14
- * directly for sync operations, or let {@link Run} use it automatically for
15
- * async tasks.
16
- *
17
- * ### Example
18
- *
19
- * ```ts
20
- * // Sync code — use tracer directly
21
- * const result = deps.tracer?.span("parseData", () => parseData(input));
22
- *
23
- * // Async code — Run traces automatically
24
- * await using run = createRun(deps);
25
- * const result = await run(fetchUser(id)); // Traced if tracer provided
26
- * ```
27
- *
28
- * TODO: Complete implementation with OpenTelemetry adapter.
29
- */
30
- export interface Tracer {
31
- /**
32
- * Wraps a sync function in a traced span.
33
- *
34
- * Records start time, end time, and success/failure status.
35
- */
36
- readonly span: <T>(name: string, fn: () => T) => T;
37
-
38
- /** Records an event/fact (e.g., "user.purchased", "sync.completed"). */
39
- readonly event: (name: string, data?: unknown) => void;
40
- }
41
-
42
- export interface TracerDep {
43
- readonly tracer: Tracer;
44
- }
45
-
46
- /** Configuration for tracing. */
47
- export interface TracerConfig {
48
- /** When `true`, enables trace data collection. Can be toggled at runtime. */
49
- readonly tracing?: Ref<boolean>;
50
- }
51
-
52
- export interface TracerConfigDep {
53
- readonly tracerConfig: TracerConfig;
54
- }