@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.
- package/dist/src/Array.d.ts +279 -173
- package/dist/src/Array.d.ts.map +1 -1
- package/dist/src/Array.js +105 -101
- package/dist/src/Assert.d.ts +44 -44
- package/dist/src/Assert.d.ts.map +1 -1
- package/dist/src/Assert.js +44 -32
- package/dist/src/BigInt.d.ts +6 -3
- package/dist/src/BigInt.d.ts.map +1 -1
- package/dist/src/BigInt.js +5 -2
- package/dist/src/Brand.d.ts +27 -40
- package/dist/src/Brand.d.ts.map +1 -1
- package/dist/src/Buffer.d.ts +27 -11
- package/dist/src/Buffer.d.ts.map +1 -1
- package/dist/src/Cache.d.ts +9 -4
- package/dist/src/Cache.d.ts.map +1 -1
- package/dist/src/Cache.js +8 -3
- package/dist/src/Callbacks.d.ts +30 -19
- package/dist/src/Callbacks.d.ts.map +1 -1
- package/dist/src/Console.d.ts +145 -66
- package/dist/src/Console.d.ts.map +1 -1
- package/dist/src/Console.js +91 -43
- package/dist/src/Crypto.d.ts +85 -42
- package/dist/src/Crypto.d.ts.map +1 -1
- package/dist/src/Crypto.js +44 -20
- package/dist/src/Eq.d.ts +87 -21
- package/dist/src/Eq.d.ts.map +1 -1
- package/dist/src/Eq.js +67 -19
- package/dist/src/Error.d.ts +5 -3
- package/dist/src/Error.d.ts.map +1 -1
- package/dist/src/Error.js +16 -0
- package/dist/src/Function.d.ts +119 -58
- package/dist/src/Function.d.ts.map +1 -1
- package/dist/src/Function.js +86 -43
- package/dist/src/Http.d.ts +394 -0
- package/dist/src/Http.d.ts.map +1 -0
- package/dist/src/Http.js +102 -0
- package/dist/src/Identicon.d.ts +16 -7
- package/dist/src/Identicon.d.ts.map +1 -1
- package/dist/src/Identicon.js +14 -5
- package/dist/src/LeakDetector.d.ts +88 -0
- package/dist/src/LeakDetector.d.ts.map +1 -0
- package/dist/src/LeakDetector.js +86 -0
- package/dist/src/LockManager.d.ts +18 -9
- package/dist/src/LockManager.d.ts.map +1 -1
- package/dist/src/LockManager.js +7 -8
- package/dist/src/Lookup.d.ts +43 -13
- package/dist/src/Lookup.d.ts.map +1 -1
- package/dist/src/Lookup.js +28 -8
- package/dist/src/Microtask.d.ts +1 -1
- package/dist/src/Microtask.d.ts.map +1 -1
- package/dist/src/Microtask.js +3 -7
- package/dist/src/Number.d.ts +49 -13
- package/dist/src/Number.d.ts.map +1 -1
- package/dist/src/Number.js +34 -5
- package/dist/src/Object.d.ts +160 -40
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/Object.js +92 -46
- package/dist/src/Option.d.ts +10 -7
- package/dist/src/Option.d.ts.map +1 -1
- package/dist/src/Option.js +9 -6
- package/dist/src/Order.d.ts +21 -21
- package/dist/src/Order.d.ts.map +1 -1
- package/dist/src/Order.js +18 -21
- package/dist/src/Platform.d.ts +31 -0
- package/dist/src/Platform.d.ts.map +1 -1
- package/dist/src/Platform.js +98 -0
- package/dist/src/Random.d.ts +32 -17
- package/dist/src/Random.d.ts.map +1 -1
- package/dist/src/Random.js +12 -8
- package/dist/src/Redacted.d.ts +43 -29
- package/dist/src/Redacted.d.ts.map +1 -1
- package/dist/src/Redacted.js +14 -3
- package/dist/src/Ref.d.ts +11 -3
- package/dist/src/Ref.d.ts.map +1 -1
- package/dist/src/Ref.js +2 -2
- package/dist/src/RefCount.d.ts +2 -6
- package/dist/src/RefCount.d.ts.map +1 -1
- package/dist/src/RefCount.js +33 -90
- package/dist/src/Relation.d.ts +70 -5
- package/dist/src/Relation.d.ts.map +1 -1
- package/dist/src/Relation.js +77 -2
- package/dist/src/Resource.d.ts +590 -155
- package/dist/src/Resource.d.ts.map +1 -1
- package/dist/src/Resource.js +592 -343
- package/dist/src/Result.d.ts +838 -191
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Result.js +163 -102
- package/dist/src/Schedule.d.ts +684 -231
- package/dist/src/Schedule.d.ts.map +1 -1
- package/dist/src/Schedule.js +766 -295
- package/dist/src/Set.d.ts +89 -40
- package/dist/src/Set.d.ts.map +1 -1
- package/dist/src/Set.js +50 -29
- package/dist/src/Sqlite.d.ts +29 -72
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +41 -46
- package/dist/src/StackTrace.d.ts +40 -0
- package/dist/src/StackTrace.d.ts.map +1 -0
- package/dist/src/StackTrace.js +140 -0
- package/dist/src/Store.d.ts +5 -4
- package/dist/src/Store.d.ts.map +1 -1
- package/dist/src/Store.js +5 -4
- package/dist/src/String.d.ts +7 -1
- package/dist/src/String.d.ts.map +1 -1
- package/dist/src/String.js +20 -7
- package/dist/src/Task.d.ts +3572 -1770
- package/dist/src/Task.d.ts.map +1 -1
- package/dist/src/Task.js +1879 -1274
- package/dist/src/Test.d.ts +17 -125
- package/dist/src/Test.d.ts.map +1 -1
- package/dist/src/Test.js +17 -68
- package/dist/src/Time.d.ts +108 -49
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +172 -73
- package/dist/src/Type.d.ts +3542 -1926
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +3070 -1784
- package/dist/src/Types.d.ts +200 -108
- package/dist/src/Types.d.ts.map +1 -1
- package/dist/src/Types.js +39 -8
- package/dist/src/WebSocket.d.ts +48 -23
- package/dist/src/WebSocket.d.ts.map +1 -1
- package/dist/src/WebSocket.js +15 -6
- package/dist/src/Worker.d.ts +94 -36
- package/dist/src/Worker.d.ts.map +1 -1
- package/dist/src/Worker.js +58 -24
- package/dist/src/index.d.ts +55 -52
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -1
- package/dist/src/intl/cs.d.ts +94 -0
- package/dist/src/intl/cs.d.ts.map +1 -0
- package/dist/src/intl/cs.js +220 -0
- package/dist/src/intl/index.d.ts +7 -0
- package/dist/src/intl/index.d.ts.map +1 -0
- package/dist/src/intl/index.js +6 -0
- package/dist/src/local-first/Db.d.ts +12 -8
- package/dist/src/local-first/Db.d.ts.map +1 -1
- package/dist/src/local-first/Db.js +109 -132
- package/dist/src/local-first/Error.d.ts +4 -4
- package/dist/src/local-first/Evolu.d.ts +338 -92
- package/dist/src/local-first/Evolu.d.ts.map +1 -1
- package/dist/src/local-first/Evolu.js +47 -55
- package/dist/src/local-first/LocalAuth.d.ts +4 -4
- package/dist/src/local-first/LocalAuth.d.ts.map +1 -1
- package/dist/src/local-first/Owner.d.ts +61 -24
- package/dist/src/local-first/Owner.d.ts.map +1 -1
- package/dist/src/local-first/Owner.js +45 -8
- package/dist/src/local-first/Protocol.d.ts +44 -31
- package/dist/src/local-first/Protocol.d.ts.map +1 -1
- package/dist/src/local-first/Protocol.js +36 -13
- package/dist/src/local-first/Query.d.ts +147 -62
- package/dist/src/local-first/Query.d.ts.map +1 -1
- package/dist/src/local-first/Query.js +112 -58
- package/dist/src/local-first/Relay.d.ts +44 -14
- package/dist/src/local-first/Relay.d.ts.map +1 -1
- package/dist/src/local-first/Schema.d.ts +92 -41
- package/dist/src/local-first/Schema.d.ts.map +1 -1
- package/dist/src/local-first/Schema.js +25 -8
- package/dist/src/local-first/Shared.d.ts +23 -21
- package/dist/src/local-first/Shared.d.ts.map +1 -1
- package/dist/src/local-first/Shared.js +100 -57
- package/dist/src/local-first/Storage.d.ts +53 -32
- package/dist/src/local-first/Storage.d.ts.map +1 -1
- package/dist/src/local-first/Storage.js +194 -234
- package/dist/src/local-first/Timestamp.d.ts +21 -21
- package/dist/src/local-first/Timestamp.d.ts.map +1 -1
- package/dist/src/local-first/Timestamp.js +2 -2
- package/dist/src/local-first/index.d.ts +11 -11
- package/package.json +14 -13
- package/src/Array.ts +306 -205
- package/src/Assert.ts +54 -69
- package/src/BigInt.ts +6 -3
- package/src/Brand.ts +27 -40
- package/src/Buffer.ts +28 -12
- package/src/Cache.ts +9 -4
- package/src/Callbacks.ts +30 -19
- package/src/Console.ts +156 -84
- package/src/Crypto.ts +83 -41
- package/src/Eq.ts +95 -22
- package/src/Error.ts +8 -4
- package/src/Function.ts +167 -59
- package/src/Http.ts +549 -0
- package/src/Identicon.ts +16 -7
- package/src/LeakDetector.ts +182 -0
- package/src/LockManager.ts +43 -39
- package/src/Lookup.ts +62 -28
- package/src/Microtask.ts +19 -23
- package/src/Number.ts +64 -12
- package/src/Object.ts +173 -49
- package/src/Option.ts +10 -7
- package/src/Order.ts +23 -21
- package/src/Platform.ts +136 -0
- package/src/Polyfills.ts +6 -12
- package/src/Random.ts +32 -19
- package/src/Redacted.ts +44 -30
- package/src/Ref.ts +14 -6
- package/src/RefCount.ts +38 -80
- package/src/Relation.ts +202 -10
- package/src/Resource.ts +1199 -591
- package/src/Result.ts +930 -271
- package/src/Schedule.ts +859 -343
- package/src/Set.ts +89 -40
- package/src/Sqlite.ts +144 -138
- package/src/StackTrace.ts +230 -0
- package/src/Store.ts +8 -7
- package/src/String.ts +22 -5
- package/src/Task.ts +5101 -2832
- package/src/Test.ts +20 -168
- package/src/Time.ts +293 -90
- package/src/Type.ts +10034 -4117
- package/src/Types.ts +227 -110
- package/src/WebSocket.ts +64 -36
- package/src/Worker.ts +180 -72
- package/src/index.ts +55 -52
- package/src/intl/cs.ts +388 -0
- package/src/intl/index.ts +7 -0
- package/src/local-first/Db.ts +152 -179
- package/src/local-first/Error.ts +4 -4
- package/src/local-first/Evolu.ts +495 -250
- package/src/local-first/LocalAuth.ts +6 -12
- package/src/local-first/Owner.ts +58 -21
- package/src/local-first/Protocol.ts +49 -31
- package/src/local-first/Query.ts +146 -61
- package/src/local-first/Relay.ts +51 -21
- package/src/local-first/Schema.ts +109 -51
- package/src/local-first/Shared.ts +266 -226
- package/src/local-first/Storage.ts +266 -264
- package/src/local-first/Timestamp.ts +25 -18
- package/src/local-first/index.ts +11 -11
- package/dist/src/Skiplist.d.ts +0 -28
- package/dist/src/Skiplist.d.ts.map +0 -1
- package/dist/src/Skiplist.js +0 -64
- package/dist/src/Tracer.d.ts +0 -48
- package/dist/src/Tracer.d.ts.map +0 -1
- package/dist/src/Tracer.js +0 -6
- package/src/Skiplist.ts +0 -108
- package/src/Tracer.ts +0 -54
|
@@ -4,27 +4,30 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { bytesToHex } from "../Buffer.
|
|
8
|
-
import type { RandomBytesDep } from "../Crypto.
|
|
9
|
-
import { createEqObject, eqNumber, eqString } from "../Eq.
|
|
10
|
-
import { increment } from "../Number.
|
|
11
|
-
import type { Order } from "../Order.
|
|
12
|
-
import { orderUint8Array } from "../Order.
|
|
13
|
-
import type { Result } from "../Result.
|
|
14
|
-
import { err, ok } from "../Result.
|
|
15
|
-
import type { TimeDep } from "../Time.
|
|
16
|
-
import { Millis, minMillis } from "../Time.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
281
|
+
export type TimestampBytes = typeof TimestampBytes.Output;
|
|
275
282
|
|
|
276
283
|
export const timestampBytesLength = /*#__PURE__*/ NonNegativeInt.orThrow(16);
|
|
277
284
|
|
package/src/local-first/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export * from "./Db.
|
|
2
|
-
export * from "./Error.
|
|
3
|
-
export * from "./Evolu.
|
|
4
|
-
export * from "./Owner.
|
|
5
|
-
export * from "./Protocol.
|
|
6
|
-
export * from "./Query.
|
|
7
|
-
export * from "./Relay.
|
|
8
|
-
export * from "./Schema.
|
|
9
|
-
export * from "./Shared.
|
|
10
|
-
export * from "./Storage.
|
|
11
|
-
export * from "./Timestamp.
|
|
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";
|
package/dist/src/Skiplist.d.ts
DELETED
|
@@ -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"}
|
package/dist/src/Skiplist.js
DELETED
|
@@ -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
|
-
};
|
package/dist/src/Tracer.d.ts
DELETED
|
@@ -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
|
package/dist/src/Tracer.d.ts.map
DELETED
|
@@ -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"}
|
package/dist/src/Tracer.js
DELETED
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
|
-
}
|