@evolu/common 8.0.0-next.5 → 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 (236) 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 +39 -44
  5. package/dist/src/Assert.d.ts.map +1 -1
  6. package/dist/src/Assert.js +38 -31
  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 +3 -3
  29. package/dist/src/Error.d.ts.map +1 -1
  30. package/dist/src/Function.d.ts +119 -58
  31. package/dist/src/Function.d.ts.map +1 -1
  32. package/dist/src/Function.js +86 -43
  33. package/dist/src/Http.d.ts +394 -0
  34. package/dist/src/Http.d.ts.map +1 -0
  35. package/dist/src/Http.js +102 -0
  36. package/dist/src/Identicon.d.ts +16 -7
  37. package/dist/src/Identicon.d.ts.map +1 -1
  38. package/dist/src/Identicon.js +14 -5
  39. package/dist/src/LeakDetector.d.ts +88 -0
  40. package/dist/src/LeakDetector.d.ts.map +1 -0
  41. package/dist/src/LeakDetector.js +86 -0
  42. package/dist/src/LockManager.d.ts +18 -9
  43. package/dist/src/LockManager.d.ts.map +1 -1
  44. package/dist/src/LockManager.js +7 -8
  45. package/dist/src/Lookup.d.ts +43 -13
  46. package/dist/src/Lookup.d.ts.map +1 -1
  47. package/dist/src/Lookup.js +28 -8
  48. package/dist/src/Microtask.d.ts +1 -1
  49. package/dist/src/Microtask.d.ts.map +1 -1
  50. package/dist/src/Microtask.js +3 -7
  51. package/dist/src/Number.d.ts +49 -13
  52. package/dist/src/Number.d.ts.map +1 -1
  53. package/dist/src/Number.js +34 -5
  54. package/dist/src/Object.d.ts +160 -40
  55. package/dist/src/Object.d.ts.map +1 -1
  56. package/dist/src/Object.js +92 -46
  57. package/dist/src/Option.d.ts +10 -7
  58. package/dist/src/Option.d.ts.map +1 -1
  59. package/dist/src/Option.js +9 -6
  60. package/dist/src/Order.d.ts +21 -21
  61. package/dist/src/Order.d.ts.map +1 -1
  62. package/dist/src/Order.js +18 -21
  63. package/dist/src/Platform.d.ts +31 -0
  64. package/dist/src/Platform.d.ts.map +1 -1
  65. package/dist/src/Platform.js +98 -0
  66. package/dist/src/Random.d.ts +32 -17
  67. package/dist/src/Random.d.ts.map +1 -1
  68. package/dist/src/Random.js +12 -8
  69. package/dist/src/Redacted.d.ts +43 -29
  70. package/dist/src/Redacted.d.ts.map +1 -1
  71. package/dist/src/Redacted.js +14 -3
  72. package/dist/src/Ref.d.ts +11 -3
  73. package/dist/src/Ref.d.ts.map +1 -1
  74. package/dist/src/Ref.js +2 -2
  75. package/dist/src/RefCount.d.ts +2 -6
  76. package/dist/src/RefCount.d.ts.map +1 -1
  77. package/dist/src/RefCount.js +33 -90
  78. package/dist/src/Relation.d.ts +70 -5
  79. package/dist/src/Relation.d.ts.map +1 -1
  80. package/dist/src/Relation.js +77 -2
  81. package/dist/src/Resource.d.ts +590 -155
  82. package/dist/src/Resource.d.ts.map +1 -1
  83. package/dist/src/Resource.js +592 -343
  84. package/dist/src/Result.d.ts +838 -191
  85. package/dist/src/Result.d.ts.map +1 -1
  86. package/dist/src/Result.js +163 -102
  87. package/dist/src/Schedule.d.ts +684 -231
  88. package/dist/src/Schedule.d.ts.map +1 -1
  89. package/dist/src/Schedule.js +766 -295
  90. package/dist/src/Set.d.ts +89 -40
  91. package/dist/src/Set.d.ts.map +1 -1
  92. package/dist/src/Set.js +50 -29
  93. package/dist/src/Sqlite.d.ts +29 -72
  94. package/dist/src/Sqlite.d.ts.map +1 -1
  95. package/dist/src/Sqlite.js +39 -45
  96. package/dist/src/StackTrace.d.ts +40 -0
  97. package/dist/src/StackTrace.d.ts.map +1 -0
  98. package/dist/src/StackTrace.js +140 -0
  99. package/dist/src/Store.d.ts +5 -4
  100. package/dist/src/Store.d.ts.map +1 -1
  101. package/dist/src/Store.js +5 -4
  102. package/dist/src/String.d.ts +7 -1
  103. package/dist/src/String.d.ts.map +1 -1
  104. package/dist/src/String.js +20 -7
  105. package/dist/src/Task.d.ts +3428 -1629
  106. package/dist/src/Task.d.ts.map +1 -1
  107. package/dist/src/Task.js +1876 -1279
  108. package/dist/src/Test.d.ts +17 -124
  109. package/dist/src/Test.d.ts.map +1 -1
  110. package/dist/src/Test.js +17 -68
  111. package/dist/src/Time.d.ts +108 -49
  112. package/dist/src/Time.d.ts.map +1 -1
  113. package/dist/src/Time.js +172 -73
  114. package/dist/src/Type.d.ts +3542 -1926
  115. package/dist/src/Type.d.ts.map +1 -1
  116. package/dist/src/Type.js +3070 -1784
  117. package/dist/src/Types.d.ts +200 -100
  118. package/dist/src/Types.d.ts.map +1 -1
  119. package/dist/src/Types.js +39 -8
  120. package/dist/src/WebSocket.d.ts +48 -23
  121. package/dist/src/WebSocket.d.ts.map +1 -1
  122. package/dist/src/WebSocket.js +15 -6
  123. package/dist/src/Worker.d.ts +94 -36
  124. package/dist/src/Worker.d.ts.map +1 -1
  125. package/dist/src/Worker.js +58 -24
  126. package/dist/src/index.d.ts +55 -52
  127. package/dist/src/index.d.ts.map +1 -1
  128. package/dist/src/index.js +3 -1
  129. package/dist/src/intl/cs.d.ts +94 -0
  130. package/dist/src/intl/cs.d.ts.map +1 -0
  131. package/dist/src/intl/cs.js +220 -0
  132. package/dist/src/intl/index.d.ts +7 -0
  133. package/dist/src/intl/index.d.ts.map +1 -0
  134. package/dist/src/intl/index.js +6 -0
  135. package/dist/src/local-first/Db.d.ts +12 -8
  136. package/dist/src/local-first/Db.d.ts.map +1 -1
  137. package/dist/src/local-first/Db.js +107 -130
  138. package/dist/src/local-first/Error.d.ts +4 -4
  139. package/dist/src/local-first/Evolu.d.ts +338 -92
  140. package/dist/src/local-first/Evolu.d.ts.map +1 -1
  141. package/dist/src/local-first/Evolu.js +47 -55
  142. package/dist/src/local-first/LocalAuth.d.ts +4 -4
  143. package/dist/src/local-first/LocalAuth.d.ts.map +1 -1
  144. package/dist/src/local-first/Owner.d.ts +61 -24
  145. package/dist/src/local-first/Owner.d.ts.map +1 -1
  146. package/dist/src/local-first/Owner.js +45 -8
  147. package/dist/src/local-first/Protocol.d.ts +44 -31
  148. package/dist/src/local-first/Protocol.d.ts.map +1 -1
  149. package/dist/src/local-first/Protocol.js +36 -13
  150. package/dist/src/local-first/Query.d.ts +147 -62
  151. package/dist/src/local-first/Query.d.ts.map +1 -1
  152. package/dist/src/local-first/Query.js +112 -58
  153. package/dist/src/local-first/Relay.d.ts +44 -14
  154. package/dist/src/local-first/Relay.d.ts.map +1 -1
  155. package/dist/src/local-first/Schema.d.ts +92 -41
  156. package/dist/src/local-first/Schema.d.ts.map +1 -1
  157. package/dist/src/local-first/Schema.js +25 -8
  158. package/dist/src/local-first/Shared.d.ts +23 -21
  159. package/dist/src/local-first/Shared.d.ts.map +1 -1
  160. package/dist/src/local-first/Shared.js +85 -42
  161. package/dist/src/local-first/Storage.d.ts +53 -32
  162. package/dist/src/local-first/Storage.d.ts.map +1 -1
  163. package/dist/src/local-first/Storage.js +194 -234
  164. package/dist/src/local-first/Timestamp.d.ts +21 -21
  165. package/dist/src/local-first/Timestamp.d.ts.map +1 -1
  166. package/dist/src/local-first/Timestamp.js +2 -2
  167. package/dist/src/local-first/index.d.ts +11 -11
  168. package/package.json +14 -13
  169. package/src/Array.ts +306 -205
  170. package/src/Assert.ts +48 -68
  171. package/src/BigInt.ts +6 -3
  172. package/src/Brand.ts +27 -40
  173. package/src/Buffer.ts +28 -12
  174. package/src/Cache.ts +9 -4
  175. package/src/Callbacks.ts +30 -19
  176. package/src/Console.ts +156 -84
  177. package/src/Crypto.ts +83 -41
  178. package/src/Eq.ts +95 -22
  179. package/src/Error.ts +5 -2
  180. package/src/Function.ts +167 -59
  181. package/src/Http.ts +549 -0
  182. package/src/Identicon.ts +16 -7
  183. package/src/LeakDetector.ts +182 -0
  184. package/src/LockManager.ts +43 -39
  185. package/src/Lookup.ts +62 -28
  186. package/src/Microtask.ts +19 -23
  187. package/src/Number.ts +64 -12
  188. package/src/Object.ts +173 -49
  189. package/src/Option.ts +10 -7
  190. package/src/Order.ts +23 -21
  191. package/src/Platform.ts +136 -0
  192. package/src/Polyfills.ts +6 -12
  193. package/src/Random.ts +32 -19
  194. package/src/Redacted.ts +44 -30
  195. package/src/Ref.ts +14 -6
  196. package/src/RefCount.ts +38 -80
  197. package/src/Relation.ts +202 -10
  198. package/src/Resource.ts +1199 -591
  199. package/src/Result.ts +930 -271
  200. package/src/Schedule.ts +859 -343
  201. package/src/Set.ts +89 -40
  202. package/src/Sqlite.ts +142 -137
  203. package/src/StackTrace.ts +230 -0
  204. package/src/Store.ts +8 -7
  205. package/src/String.ts +22 -5
  206. package/src/Task.ts +5109 -2845
  207. package/src/Test.ts +20 -167
  208. package/src/Time.ts +293 -90
  209. package/src/Type.ts +10034 -4117
  210. package/src/Types.ts +227 -101
  211. package/src/WebSocket.ts +64 -36
  212. package/src/Worker.ts +180 -72
  213. package/src/index.ts +55 -52
  214. package/src/intl/cs.ts +388 -0
  215. package/src/intl/index.ts +7 -0
  216. package/src/local-first/Db.ts +161 -190
  217. package/src/local-first/Error.ts +4 -4
  218. package/src/local-first/Evolu.ts +495 -250
  219. package/src/local-first/LocalAuth.ts +6 -12
  220. package/src/local-first/Owner.ts +58 -21
  221. package/src/local-first/Protocol.ts +49 -31
  222. package/src/local-first/Query.ts +146 -61
  223. package/src/local-first/Relay.ts +51 -21
  224. package/src/local-first/Schema.ts +109 -51
  225. package/src/local-first/Shared.ts +253 -214
  226. package/src/local-first/Storage.ts +266 -264
  227. package/src/local-first/Timestamp.ts +25 -18
  228. package/src/local-first/index.ts +11 -11
  229. package/dist/src/Skiplist.d.ts +0 -28
  230. package/dist/src/Skiplist.d.ts.map +0 -1
  231. package/dist/src/Skiplist.js +0 -64
  232. package/dist/src/Tracer.d.ts +0 -48
  233. package/dist/src/Tracer.d.ts.map +0 -1
  234. package/dist/src/Tracer.js +0 -6
  235. package/src/Skiplist.ts +0 -108
  236. 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
- }