compostjs 0.0.8 → 0.0.12

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 (141) hide show
  1. package/README.md +4 -4
  2. package/dist/fable_modules/fable-library-js.4.28.0/Array.d.ts +123 -0
  3. package/dist/fable_modules/fable-library-js.4.28.0/Array.js +1242 -0
  4. package/dist/fable_modules/fable-library-js.4.28.0/Async.d.ts +26 -0
  5. package/dist/fable_modules/fable-library-js.4.28.0/Async.js +145 -0
  6. package/dist/fable_modules/fable-library-js.4.28.0/AsyncBuilder.d.ts +59 -0
  7. package/dist/fable_modules/fable-library-js.4.28.0/AsyncBuilder.js +183 -0
  8. package/dist/fable_modules/fable-library-js.4.28.0/BigInt.d.ts +115 -0
  9. package/dist/fable_modules/fable-library-js.4.28.0/BigInt.js +283 -0
  10. package/dist/fable_modules/fable-library-js.4.28.0/BitConverter.d.ts +27 -0
  11. package/dist/fable_modules/fable-library-js.4.28.0/BitConverter.js +138 -0
  12. package/dist/fable_modules/fable-library-js.4.28.0/Boolean.d.ts +3 -0
  13. package/dist/fable_modules/fable-library-js.4.28.0/Boolean.js +21 -0
  14. package/dist/fable_modules/fable-library-js.4.28.0/CHANGELOG.md +100 -0
  15. package/dist/fable_modules/fable-library-js.4.28.0/Char.d.ts +65 -0
  16. package/dist/fable_modules/fable-library-js.4.28.0/Char.js +169 -0
  17. package/dist/fable_modules/fable-library-js.4.28.0/Choice.d.ts +121 -0
  18. package/dist/fable_modules/fable-library-js.4.28.0/Choice.js +184 -0
  19. package/dist/fable_modules/fable-library-js.4.28.0/CollectionUtil.d.ts +7 -0
  20. package/dist/fable_modules/fable-library-js.4.28.0/CollectionUtil.js +182 -0
  21. package/dist/fable_modules/fable-library-js.4.28.0/ConditionalWeakTable.d.ts +9 -0
  22. package/dist/fable_modules/fable-library-js.4.28.0/ConditionalWeakTable.js +21 -0
  23. package/dist/fable_modules/fable-library-js.4.28.0/Date.d.ts +70 -0
  24. package/dist/fable_modules/fable-library-js.4.28.0/Date.js +748 -0
  25. package/dist/fable_modules/fable-library-js.4.28.0/DateOffset.d.ts +63 -0
  26. package/dist/fable_modules/fable-library-js.4.28.0/DateOffset.js +268 -0
  27. package/dist/fable_modules/fable-library-js.4.28.0/DateOnly.d.ts +18 -0
  28. package/dist/fable_modules/fable-library-js.4.28.0/DateOnly.js +124 -0
  29. package/dist/fable_modules/fable-library-js.4.28.0/Decimal.d.ts +45 -0
  30. package/dist/fable_modules/fable-library-js.4.28.0/Decimal.js +212 -0
  31. package/dist/fable_modules/fable-library-js.4.28.0/Double.d.ts +11 -0
  32. package/dist/fable_modules/fable-library-js.4.28.0/Double.js +46 -0
  33. package/dist/fable_modules/fable-library-js.4.28.0/Encoding.d.ts +12 -0
  34. package/dist/fable_modules/fable-library-js.4.28.0/Encoding.js +173 -0
  35. package/dist/fable_modules/fable-library-js.4.28.0/Event.d.ts +31 -0
  36. package/dist/fable_modules/fable-library-js.4.28.0/Event.js +93 -0
  37. package/dist/fable_modules/fable-library-js.4.28.0/FSharp.Collections.d.ts +7 -0
  38. package/dist/fable_modules/fable-library-js.4.28.0/FSharp.Collections.js +27 -0
  39. package/dist/fable_modules/fable-library-js.4.28.0/FSharp.Core.CompilerServices.d.ts +12 -0
  40. package/dist/fable_modules/fable-library-js.4.28.0/FSharp.Core.CompilerServices.js +27 -0
  41. package/dist/fable_modules/fable-library-js.4.28.0/FSharp.Core.d.ts +17 -0
  42. package/dist/fable_modules/fable-library-js.4.28.0/FSharp.Core.js +69 -0
  43. package/dist/fable_modules/fable-library-js.4.28.0/Global.d.ts +24 -0
  44. package/dist/fable_modules/fable-library-js.4.28.0/Global.js +8 -0
  45. package/dist/fable_modules/fable-library-js.4.28.0/Guid.d.ts +10 -0
  46. package/dist/fable_modules/fable-library-js.4.28.0/Guid.js +142 -0
  47. package/dist/fable_modules/fable-library-js.4.28.0/Int32.d.ts +28 -0
  48. package/dist/fable_modules/fable-library-js.4.28.0/Int32.js +135 -0
  49. package/dist/fable_modules/fable-library-js.4.28.0/List.d.ts +143 -0
  50. package/dist/fable_modules/fable-library-js.4.28.0/List.js +1273 -0
  51. package/dist/fable_modules/fable-library-js.4.28.0/Long.d.ts +3 -0
  52. package/dist/fable_modules/fable-library-js.4.28.0/Long.js +46 -0
  53. package/dist/fable_modules/fable-library-js.4.28.0/MailboxProcessor.d.ts +25 -0
  54. package/dist/fable_modules/fable-library-js.4.28.0/MailboxProcessor.js +93 -0
  55. package/dist/fable_modules/fable-library-js.4.28.0/Map.d.ts +178 -0
  56. package/dist/fable_modules/fable-library-js.4.28.0/Map.js +1396 -0
  57. package/dist/fable_modules/fable-library-js.4.28.0/MapUtil.d.ts +12 -0
  58. package/dist/fable_modules/fable-library-js.4.28.0/MapUtil.js +127 -0
  59. package/dist/fable_modules/fable-library-js.4.28.0/MutableMap.d.ts +52 -0
  60. package/dist/fable_modules/fable-library-js.4.28.0/MutableMap.js +327 -0
  61. package/dist/fable_modules/fable-library-js.4.28.0/MutableSet.d.ts +39 -0
  62. package/dist/fable_modules/fable-library-js.4.28.0/MutableSet.js +233 -0
  63. package/dist/fable_modules/fable-library-js.4.28.0/Native.d.ts +2 -0
  64. package/dist/fable_modules/fable-library-js.4.28.0/Native.js +8 -0
  65. package/dist/fable_modules/fable-library-js.4.28.0/Numeric.d.ts +19 -0
  66. package/dist/fable_modules/fable-library-js.4.28.0/Numeric.js +71 -0
  67. package/dist/fable_modules/fable-library-js.4.28.0/Observable.d.ts +32 -0
  68. package/dist/fable_modules/fable-library-js.4.28.0/Observable.js +113 -0
  69. package/dist/fable_modules/fable-library-js.4.28.0/Option.d.ts +28 -0
  70. package/dist/fable_modules/fable-library-js.4.28.0/Option.js +96 -0
  71. package/dist/fable_modules/fable-library-js.4.28.0/README.md +3 -0
  72. package/dist/fable_modules/fable-library-js.4.28.0/Random.d.ts +37 -0
  73. package/dist/fable_modules/fable-library-js.4.28.0/Random.js +170 -0
  74. package/dist/fable_modules/fable-library-js.4.28.0/Range.d.ts +12 -0
  75. package/dist/fable_modules/fable-library-js.4.28.0/Range.js +45 -0
  76. package/dist/fable_modules/fable-library-js.4.28.0/Reflection.d.ts +119 -0
  77. package/dist/fable_modules/fable-library-js.4.28.0/Reflection.js +461 -0
  78. package/dist/fable_modules/fable-library-js.4.28.0/RegExp.d.ts +10 -0
  79. package/dist/fable_modules/fable-library-js.4.28.0/RegExp.js +131 -0
  80. package/dist/fable_modules/fable-library-js.4.28.0/Result.d.ts +37 -0
  81. package/dist/fable_modules/fable-library-js.4.28.0/Result.js +165 -0
  82. package/dist/fable_modules/fable-library-js.4.28.0/Seq.d.ts +165 -0
  83. package/dist/fable_modules/fable-library-js.4.28.0/Seq.js +1378 -0
  84. package/dist/fable_modules/fable-library-js.4.28.0/Seq2.d.ts +18 -0
  85. package/dist/fable_modules/fable-library-js.4.28.0/Seq2.js +111 -0
  86. package/dist/fable_modules/fable-library-js.4.28.0/Set.d.ts +190 -0
  87. package/dist/fable_modules/fable-library-js.4.28.0/Set.js +1789 -0
  88. package/dist/fable_modules/fable-library-js.4.28.0/String.d.ts +58 -0
  89. package/dist/fable_modules/fable-library-js.4.28.0/String.js +554 -0
  90. package/dist/fable_modules/fable-library-js.4.28.0/System.Collections.Generic.d.ts +79 -0
  91. package/dist/fable_modules/fable-library-js.4.28.0/System.Collections.Generic.js +317 -0
  92. package/dist/fable_modules/fable-library-js.4.28.0/System.Text.d.ts +38 -0
  93. package/dist/fable_modules/fable-library-js.4.28.0/System.Text.js +162 -0
  94. package/dist/fable_modules/fable-library-js.4.28.0/SystemException.d.ts +5 -0
  95. package/dist/fable_modules/fable-library-js.4.28.0/SystemException.js +5 -0
  96. package/dist/fable_modules/fable-library-js.4.28.0/TimeOnly.d.ts +15 -0
  97. package/dist/fable_modules/fable-library-js.4.28.0/TimeOnly.js +122 -0
  98. package/dist/fable_modules/fable-library-js.4.28.0/TimeSpan.d.ts +34 -0
  99. package/dist/fable_modules/fable-library-js.4.28.0/TimeSpan.js +177 -0
  100. package/dist/fable_modules/fable-library-js.4.28.0/Timer.d.ts +19 -0
  101. package/dist/fable_modules/fable-library-js.4.28.0/Timer.js +67 -0
  102. package/dist/fable_modules/fable-library-js.4.28.0/Types.d.ts +58 -0
  103. package/dist/fable_modules/fable-library-js.4.28.0/Types.js +208 -0
  104. package/dist/fable_modules/fable-library-js.4.28.0/Unicode.13.0.0.d.ts +2 -0
  105. package/dist/fable_modules/fable-library-js.4.28.0/Unicode.13.0.0.js +4 -0
  106. package/dist/fable_modules/fable-library-js.4.28.0/Uri.d.ts +31 -0
  107. package/dist/fable_modules/fable-library-js.4.28.0/Uri.js +159 -0
  108. package/dist/fable_modules/fable-library-js.4.28.0/Util.d.ts +210 -0
  109. package/dist/fable_modules/fable-library-js.4.28.0/Util.js +769 -0
  110. package/dist/fable_modules/fable-library-js.4.28.0/big.d.ts +338 -0
  111. package/dist/fable_modules/fable-library-js.4.28.0/lib/big.d.ts +5 -0
  112. package/dist/fable_modules/fable-library-js.4.28.0/lib/big.js +825 -0
  113. package/dist/fable_modules/fable-library-js.4.28.0/package.json +24 -0
  114. package/dist/fable_modules/project_cracked.json +1 -0
  115. package/package.json +6 -5
  116. package/.claude/settings.local.json +0 -11
  117. package/dist/fable-library.2.10.1/Array.js +0 -1336
  118. package/dist/fable-library.2.10.1/Async.js +0 -121
  119. package/dist/fable-library.2.10.1/AsyncBuilder.js +0 -200
  120. package/dist/fable-library.2.10.1/Date.js +0 -501
  121. package/dist/fable-library.2.10.1/Decimal.js +0 -208
  122. package/dist/fable-library.2.10.1/Event.js +0 -193
  123. package/dist/fable-library.2.10.1/Int32.js +0 -157
  124. package/dist/fable-library.2.10.1/List.js +0 -1234
  125. package/dist/fable-library.2.10.1/Long.js +0 -155
  126. package/dist/fable-library.2.10.1/Map.js +0 -1292
  127. package/dist/fable-library.2.10.1/MutableMap.js +0 -360
  128. package/dist/fable-library.2.10.1/MutableSet.js +0 -279
  129. package/dist/fable-library.2.10.1/Observable.js +0 -131
  130. package/dist/fable-library.2.10.1/Option.js +0 -118
  131. package/dist/fable-library.2.10.1/Reflection.js +0 -345
  132. package/dist/fable-library.2.10.1/RegExp.js +0 -118
  133. package/dist/fable-library.2.10.1/Seq.js +0 -917
  134. package/dist/fable-library.2.10.1/Set.js +0 -1692
  135. package/dist/fable-library.2.10.1/String.js +0 -679
  136. package/dist/fable-library.2.10.1/Types.js +0 -308
  137. package/dist/fable-library.2.10.1/Util.js +0 -761
  138. package/dist/helpers.js +0 -31
  139. package/dist/lib/big.js +0 -905
  140. package/dist/lib/long.js +0 -1375
  141. package/index.html +0 -49
@@ -0,0 +1,26 @@
1
+ import { Continuation, Continuations } from "./AsyncBuilder.js";
2
+ import { Async, IAsyncContext, CancellationToken } from "./AsyncBuilder.js";
3
+ import { FSharpChoice$2_$union } from "./Choice.js";
4
+ export declare function makeAsync<T>(body: Async<T>): Async<T>;
5
+ export declare function invoke<T>(computation: Async<T>, ctx: IAsyncContext<T>): void;
6
+ export declare function callThenInvoke<T, U>(ctx: IAsyncContext<T>, result1: U, part2: (x: U) => Async<T>): void;
7
+ export declare function bind<T, U>(ctx: IAsyncContext<T>, part1: Async<U>, part2: (x: U) => Async<T>): void;
8
+ export declare function createCancellationToken(arg?: boolean | number): CancellationToken;
9
+ export declare function cancel(token: CancellationToken): void;
10
+ export declare function cancelAfter(token: CancellationToken, ms: number): void;
11
+ export declare function isCancellationRequested(token: CancellationToken): boolean;
12
+ export declare function throwIfCancellationRequested(token: CancellationToken): void;
13
+ export declare function startChild<T>(computation: Async<T>, ms?: number): Async<Async<T>>;
14
+ export declare function awaitPromise<T>(p: Promise<T>): (ctx: IAsyncContext<T>) => void;
15
+ export declare function cancellationToken(): (ctx: IAsyncContext<CancellationToken>) => void;
16
+ export declare const defaultCancellationToken: CancellationToken;
17
+ export declare function catchAsync<T>(work: Async<T>): (ctx: IAsyncContext<FSharpChoice$2_$union<T, Error>>) => void;
18
+ export declare function fromContinuations<T>(f: (conts: Continuations<T>) => void): (ctx: IAsyncContext<T>) => void;
19
+ export declare function ignore<T>(computation: Async<T>): (ctx: IAsyncContext<undefined>) => void;
20
+ export declare function parallel<T>(computations: Iterable<Async<T>>): (ctx: IAsyncContext<Awaited<T>[]>) => void;
21
+ export declare function sequential<T>(computations: Iterable<Async<T>>): (ctx: IAsyncContext<T[]>) => void;
22
+ export declare function sleep(millisecondsDueTime: number): (ctx: IAsyncContext<void>) => void;
23
+ export declare function start<T>(computation: Async<T>, cancellationToken?: CancellationToken): void;
24
+ export declare function startImmediate<T>(computation: Async<T>, cancellationToken?: CancellationToken): void;
25
+ export declare function startWithContinuations<T>(computation: Async<T>, continuation: Continuation<T>, exceptionContinuation: Continuation<any>, cancellationContinuation: Continuation<any>, cancelToken?: CancellationToken): void;
26
+ export declare function startAsPromise<T>(computation: Async<T>, cancellationToken?: CancellationToken): Promise<T>;
@@ -0,0 +1,145 @@
1
+ import { OperationCanceledError, Trampoline } from "./AsyncBuilder.js";
2
+ import { CancellationToken } from "./AsyncBuilder.js";
3
+ import { protectedCont, protectedBind, protectedReturn } from "./AsyncBuilder.js";
4
+ import { Choice_makeChoice1Of2, Choice_makeChoice2Of2 } from "./Choice.js";
5
+ import { TimeoutException } from "./SystemException.js";
6
+ function emptyContinuation(_x) {
7
+ // NOP
8
+ }
9
+ // see AsyncBuilder.Delay
10
+ function delay(generator) {
11
+ return protectedCont((ctx) => generator()(ctx));
12
+ }
13
+ // MakeAsync: body:(AsyncActivation<'T> -> AsyncReturn) -> Async<'T>
14
+ export function makeAsync(body) {
15
+ return body;
16
+ }
17
+ // Invoke: computation: Async<'T> -> ctxt:AsyncActivation<'T> -> AsyncReturn
18
+ export function invoke(computation, ctx) {
19
+ return computation(ctx);
20
+ }
21
+ // CallThenInvoke: ctxt:AsyncActivation<'T> -> result1:'U -> part2:('U -> Async<'T>) -> AsyncReturn
22
+ export function callThenInvoke(ctx, result1, part2) {
23
+ return part2(result1)(ctx);
24
+ }
25
+ // Bind: ctxt:AsyncActivation<'T> -> part1:Async<'U> -> part2:('U -> Async<'T>) -> AsyncReturn
26
+ export function bind(ctx, part1, part2) {
27
+ return protectedBind(part1, part2)(ctx);
28
+ }
29
+ export function createCancellationToken(arg) {
30
+ const token = new CancellationToken(typeof arg === "boolean" ? arg : false);
31
+ if (typeof arg === "number") {
32
+ setTimeout(() => { token.cancel(); }, arg);
33
+ }
34
+ return token;
35
+ }
36
+ export function cancel(token) {
37
+ token.cancel();
38
+ }
39
+ export function cancelAfter(token, ms) {
40
+ setTimeout(() => { token.cancel(); }, ms);
41
+ }
42
+ export function isCancellationRequested(token) {
43
+ return token != null && token.isCancelled;
44
+ }
45
+ export function throwIfCancellationRequested(token) {
46
+ if (token != null && token.isCancelled) {
47
+ throw new Error("Operation is cancelled");
48
+ }
49
+ }
50
+ function throwAfter(millisecondsDueTime) {
51
+ return protectedCont((ctx) => {
52
+ let tokenId;
53
+ const timeoutId = setTimeout(() => {
54
+ ctx.cancelToken.removeListener(tokenId);
55
+ ctx.onError(new TimeoutException());
56
+ }, millisecondsDueTime);
57
+ tokenId = ctx.cancelToken.addListener(() => {
58
+ clearTimeout(timeoutId);
59
+ ctx.onCancel(new OperationCanceledError());
60
+ });
61
+ });
62
+ }
63
+ export function startChild(computation, ms) {
64
+ if (ms) {
65
+ const computationWithTimeout = protectedBind(parallel2(computation, throwAfter(ms)), xs => protectedReturn(xs[0]));
66
+ return startChild(computationWithTimeout);
67
+ }
68
+ const promise = startAsPromise(computation);
69
+ // JS Promises are hot, computation has already started
70
+ // but we delay returning the result
71
+ return protectedCont((ctx) => protectedReturn(awaitPromise(promise))(ctx));
72
+ }
73
+ export function awaitPromise(p) {
74
+ return fromContinuations((conts) => p.then(conts[0]).catch((err) => (err instanceof OperationCanceledError
75
+ ? conts[2] : conts[1])(err)));
76
+ }
77
+ export function cancellationToken() {
78
+ return protectedCont((ctx) => ctx.onSuccess(ctx.cancelToken));
79
+ }
80
+ export const defaultCancellationToken = new CancellationToken();
81
+ export function catchAsync(work) {
82
+ return protectedCont((ctx) => {
83
+ work({
84
+ onSuccess: (x) => ctx.onSuccess(Choice_makeChoice1Of2(x)),
85
+ onError: (ex) => ctx.onSuccess(Choice_makeChoice2Of2(ex)),
86
+ onCancel: ctx.onCancel,
87
+ cancelToken: ctx.cancelToken,
88
+ trampoline: ctx.trampoline,
89
+ });
90
+ });
91
+ }
92
+ export function fromContinuations(f) {
93
+ return protectedCont((ctx) => f([ctx.onSuccess, ctx.onError, ctx.onCancel]));
94
+ }
95
+ export function ignore(computation) {
96
+ return protectedBind(computation, (_x) => protectedReturn(void 0));
97
+ }
98
+ export function parallel(computations) {
99
+ return delay(() => awaitPromise(Promise.all(Array.from(computations, (w) => startAsPromise(w)))));
100
+ }
101
+ function parallel2(a, b) {
102
+ return delay(() => awaitPromise(Promise.all([startAsPromise(a), startAsPromise(b)])));
103
+ }
104
+ export function sequential(computations) {
105
+ function _sequential(computations) {
106
+ let pr = Promise.resolve([]);
107
+ for (const c of computations) {
108
+ pr = pr.then(results => startAsPromise(c).then(r => results.concat([r])));
109
+ }
110
+ return pr;
111
+ }
112
+ return delay(() => awaitPromise(_sequential(computations)));
113
+ }
114
+ export function sleep(millisecondsDueTime) {
115
+ return protectedCont((ctx) => {
116
+ let tokenId;
117
+ const timeoutId = setTimeout(() => {
118
+ ctx.cancelToken.removeListener(tokenId);
119
+ ctx.onSuccess(void 0);
120
+ }, millisecondsDueTime);
121
+ tokenId = ctx.cancelToken.addListener(() => {
122
+ clearTimeout(timeoutId);
123
+ ctx.onCancel(new OperationCanceledError());
124
+ });
125
+ });
126
+ }
127
+ export function start(computation, cancellationToken) {
128
+ return startWithContinuations(computation, emptyContinuation, function (err) { throw err; }, emptyContinuation, cancellationToken);
129
+ }
130
+ export function startImmediate(computation, cancellationToken) {
131
+ return start(computation, cancellationToken);
132
+ }
133
+ export function startWithContinuations(computation, continuation, exceptionContinuation, cancellationContinuation, cancelToken) {
134
+ const trampoline = new Trampoline();
135
+ computation({
136
+ onSuccess: continuation ? continuation : emptyContinuation,
137
+ onError: exceptionContinuation,
138
+ onCancel: cancellationContinuation,
139
+ cancelToken: cancelToken ? cancelToken : defaultCancellationToken,
140
+ trampoline,
141
+ });
142
+ }
143
+ export function startAsPromise(computation, cancellationToken) {
144
+ return new Promise((resolve, reject) => startWithContinuations(computation, resolve, reject, reject, cancellationToken ? cancellationToken : defaultCancellationToken));
145
+ }
@@ -0,0 +1,59 @@
1
+ import { IDisposable } from "./Util.js";
2
+ export interface AsyncReplyChannel<Reply> {
3
+ reply(value: Reply): void;
4
+ }
5
+ export type Continuation<T> = (x: T) => void;
6
+ export type Continuations<T> = [
7
+ Continuation<T>,
8
+ Continuation<Error>,
9
+ Continuation<OperationCanceledError>
10
+ ];
11
+ export declare class CancellationToken implements IDisposable {
12
+ private _id;
13
+ private _cancelled;
14
+ private _listeners;
15
+ constructor(cancelled?: boolean);
16
+ get isCancelled(): boolean;
17
+ cancel(): void;
18
+ addListener(f: () => void): number;
19
+ removeListener(id: number): boolean;
20
+ register(f: (state?: any) => void, state?: any): {
21
+ Dispose(): void;
22
+ };
23
+ Dispose(): void;
24
+ }
25
+ export declare class OperationCanceledError extends Error {
26
+ constructor();
27
+ }
28
+ export declare class Trampoline {
29
+ static get maxTrampolineCallCount(): number;
30
+ private callCount;
31
+ constructor();
32
+ incrementAndCheck(): boolean;
33
+ hijack(f: () => void): void;
34
+ }
35
+ export interface IAsyncContext<T> {
36
+ onSuccess: Continuation<T>;
37
+ onError: Continuation<Error>;
38
+ onCancel: Continuation<OperationCanceledError>;
39
+ cancelToken: CancellationToken;
40
+ trampoline: Trampoline;
41
+ }
42
+ export type Async<T> = (x: IAsyncContext<T>) => void;
43
+ export declare function protectedCont<T>(f: Async<T>): (ctx: IAsyncContext<T>) => void;
44
+ export declare function protectedBind<T, U>(computation: Async<T>, binder: (x: T) => Async<U>): (ctx: IAsyncContext<U>) => void;
45
+ export declare function protectedReturn<T>(value: T): (ctx: IAsyncContext<T>) => void;
46
+ export declare class AsyncBuilder {
47
+ Bind<T, U>(computation: Async<T>, binder: (x: T) => Async<U>): (ctx: IAsyncContext<U>) => void;
48
+ Combine<T>(computation1: Async<void>, computation2: Async<T>): (ctx: IAsyncContext<T>) => void;
49
+ Delay<T>(generator: () => Async<T>): (ctx: IAsyncContext<T>) => void;
50
+ For<T>(sequence: Iterable<T>, body: (x: T) => Async<void>): Async<void>;
51
+ Return<T>(value: T): (ctx: IAsyncContext<T>) => void;
52
+ ReturnFrom<T>(computation: Async<T>): Async<T>;
53
+ TryFinally<T>(computation: Async<T>, compensation: () => void): (ctx: IAsyncContext<T>) => void;
54
+ TryWith<T>(computation: Async<T>, catchHandler: (e: any) => Async<T>): (ctx: IAsyncContext<T>) => void;
55
+ Using<T extends IDisposable, U>(resource: T, binder: (x: T) => Async<U>): (ctx: IAsyncContext<U>) => void;
56
+ While(guard: () => boolean, computation: Async<void>): Async<void>;
57
+ Zero(): (ctx: IAsyncContext<void>) => void;
58
+ }
59
+ export declare const singleton: AsyncBuilder;
@@ -0,0 +1,183 @@
1
+ import { ensureErrorOrException } from './Types.js';
2
+ export class CancellationToken {
3
+ constructor(cancelled = false) {
4
+ this._id = 0;
5
+ this._cancelled = cancelled;
6
+ this._listeners = new Map();
7
+ }
8
+ get isCancelled() {
9
+ return this._cancelled;
10
+ }
11
+ cancel() {
12
+ if (!this._cancelled) {
13
+ this._cancelled = true;
14
+ for (const [, listener] of this._listeners) {
15
+ listener();
16
+ }
17
+ }
18
+ }
19
+ addListener(f) {
20
+ const id = this._id;
21
+ this._listeners.set(this._id++, f);
22
+ return id;
23
+ }
24
+ removeListener(id) {
25
+ return this._listeners.delete(id);
26
+ }
27
+ register(f, state) {
28
+ const $ = this;
29
+ const id = this.addListener(state == null ? f : () => f(state));
30
+ return { Dispose() { $.removeListener(id); } };
31
+ }
32
+ Dispose() {
33
+ // Implement IDisposable for compatibility but do nothing
34
+ // According to docs, calling Dispose does not trigger cancellation
35
+ // https://docs.microsoft.com/en-us/dotnet/api/system.threading.cancellationtokensource.dispose?view=net-6.0
36
+ }
37
+ }
38
+ export class OperationCanceledError extends Error {
39
+ constructor() {
40
+ super("The operation was canceled");
41
+ Object.setPrototypeOf(this, OperationCanceledError.prototype);
42
+ }
43
+ }
44
+ export class Trampoline {
45
+ static get maxTrampolineCallCount() {
46
+ return 2000;
47
+ }
48
+ constructor() {
49
+ this.callCount = 0;
50
+ }
51
+ incrementAndCheck() {
52
+ return this.callCount++ > Trampoline.maxTrampolineCallCount;
53
+ }
54
+ hijack(f) {
55
+ this.callCount = 0;
56
+ setTimeout(f, 0);
57
+ }
58
+ }
59
+ export function protectedCont(f) {
60
+ return (ctx) => {
61
+ if (ctx.cancelToken.isCancelled) {
62
+ ctx.onCancel(new OperationCanceledError());
63
+ }
64
+ else if (ctx.trampoline.incrementAndCheck()) {
65
+ ctx.trampoline.hijack(() => {
66
+ try {
67
+ f(ctx);
68
+ }
69
+ catch (err) {
70
+ ctx.onError(ensureErrorOrException(err));
71
+ }
72
+ });
73
+ }
74
+ else {
75
+ try {
76
+ f(ctx);
77
+ }
78
+ catch (err) {
79
+ ctx.onError(ensureErrorOrException(err));
80
+ }
81
+ }
82
+ };
83
+ }
84
+ export function protectedBind(computation, binder) {
85
+ return protectedCont((ctx) => {
86
+ computation({
87
+ onSuccess: (x) => {
88
+ try {
89
+ binder(x)(ctx);
90
+ }
91
+ catch (err) {
92
+ ctx.onError(ensureErrorOrException(err));
93
+ }
94
+ },
95
+ onError: ctx.onError,
96
+ onCancel: ctx.onCancel,
97
+ cancelToken: ctx.cancelToken,
98
+ trampoline: ctx.trampoline,
99
+ });
100
+ });
101
+ }
102
+ export function protectedReturn(value) {
103
+ return protectedCont((ctx) => ctx.onSuccess(value));
104
+ }
105
+ export class AsyncBuilder {
106
+ Bind(computation, binder) {
107
+ return protectedBind(computation, binder);
108
+ }
109
+ Combine(computation1, computation2) {
110
+ return this.Bind(computation1, () => computation2);
111
+ }
112
+ Delay(generator) {
113
+ return protectedCont((ctx) => generator()(ctx));
114
+ }
115
+ For(sequence, body) {
116
+ const iter = sequence[Symbol.iterator]();
117
+ let cur = iter.next();
118
+ return this.While(() => !cur.done, this.Delay(() => {
119
+ const res = body(cur.value);
120
+ cur = iter.next();
121
+ return res;
122
+ }));
123
+ }
124
+ Return(value) {
125
+ return protectedReturn(value);
126
+ }
127
+ ReturnFrom(computation) {
128
+ return computation;
129
+ }
130
+ TryFinally(computation, compensation) {
131
+ return protectedCont((ctx) => {
132
+ computation({
133
+ onSuccess: (x) => {
134
+ compensation();
135
+ ctx.onSuccess(x);
136
+ },
137
+ onError: (x) => {
138
+ compensation();
139
+ ctx.onError(x);
140
+ },
141
+ onCancel: (x) => {
142
+ compensation();
143
+ ctx.onCancel(x);
144
+ },
145
+ cancelToken: ctx.cancelToken,
146
+ trampoline: ctx.trampoline,
147
+ });
148
+ });
149
+ }
150
+ TryWith(computation, catchHandler) {
151
+ return protectedCont((ctx) => {
152
+ computation({
153
+ onSuccess: ctx.onSuccess,
154
+ onCancel: ctx.onCancel,
155
+ cancelToken: ctx.cancelToken,
156
+ trampoline: ctx.trampoline,
157
+ onError: (ex) => {
158
+ try {
159
+ catchHandler(ex)(ctx);
160
+ }
161
+ catch (err) {
162
+ ctx.onError(ensureErrorOrException(err));
163
+ }
164
+ },
165
+ });
166
+ });
167
+ }
168
+ Using(resource, binder) {
169
+ return this.TryFinally(binder(resource), () => resource.Dispose());
170
+ }
171
+ While(guard, computation) {
172
+ if (guard()) {
173
+ return this.Bind(computation, () => this.While(guard, computation));
174
+ }
175
+ else {
176
+ return this.Return(void 0);
177
+ }
178
+ }
179
+ Zero() {
180
+ return protectedCont((ctx) => ctx.onSuccess(void 0));
181
+ }
182
+ }
183
+ export const singleton = new AsyncBuilder();
@@ -0,0 +1,115 @@
1
+ import { FSharpRef } from "./Types.js";
2
+ import { int8, uint8, int16, uint16, int32, uint32, float16, float32, float64 } from "./Int32.js";
3
+ import { decimal } from "./Decimal.js";
4
+ export type int64 = bigint;
5
+ export type uint64 = bigint;
6
+ export type int128 = bigint;
7
+ export type uint128 = bigint;
8
+ export type nativeint = bigint;
9
+ export type unativeint = bigint;
10
+ export declare function isBigInt(x: any): boolean;
11
+ export declare function hash(x: bigint): int32;
12
+ export declare function equals(x: bigint, y: bigint): boolean;
13
+ export declare function compare(x: bigint, y: bigint): int32;
14
+ export declare function abs(x: bigint): bigint;
15
+ export declare function sign(x: bigint): int32;
16
+ export declare function max(x: bigint, y: bigint): bigint;
17
+ export declare function min(x: bigint, y: bigint): bigint;
18
+ export declare function maxMagnitude(x: bigint, y: bigint): bigint;
19
+ export declare function minMagnitude(x: bigint, y: bigint): bigint;
20
+ export declare function clamp(x: bigint, min: bigint, max: bigint): bigint;
21
+ export declare function add(x: bigint, y: bigint): bigint;
22
+ export declare function subtract(x: bigint, y: bigint): bigint;
23
+ export declare function multiply(x: bigint, y: bigint): bigint;
24
+ export declare function divide(x: bigint, y: bigint): bigint;
25
+ export declare function remainder(x: bigint, y: bigint): bigint;
26
+ export declare function negate(x: bigint): bigint;
27
+ export declare function op_UnaryNegation(x: bigint): bigint;
28
+ export declare function op_LogicalNot(x: bigint): bigint;
29
+ export declare function op_UnaryPlus(x: bigint): bigint;
30
+ export declare function op_Addition(x: bigint, y: bigint): bigint;
31
+ export declare function op_Subtraction(x: bigint, y: bigint): bigint;
32
+ export declare function op_Multiply(x: bigint, y: bigint): bigint;
33
+ export declare function op_Division(x: bigint, y: bigint): bigint;
34
+ export declare function op_Modulus(x: bigint, y: bigint): bigint;
35
+ export declare function op_RightShift(x: bigint, n: int32): bigint;
36
+ export declare function op_LeftShift(x: bigint, n: int32): bigint;
37
+ export declare function op_BitwiseAnd(x: bigint, y: bigint): bigint;
38
+ export declare function op_BitwiseOr(x: bigint, y: bigint): bigint;
39
+ export declare function op_ExclusiveOr(x: bigint, y: bigint): bigint;
40
+ export declare function op_LessThan(x: bigint, y: bigint): boolean;
41
+ export declare function op_LessThanOrEqual(x: bigint, y: bigint): boolean;
42
+ export declare function op_GreaterThan(x: bigint, y: bigint): boolean;
43
+ export declare function op_GreaterThanOrEqual(x: bigint, y: bigint): boolean;
44
+ export declare function op_Equality(x: bigint, y: bigint): boolean;
45
+ export declare function op_Inequality(x: bigint, y: bigint): boolean;
46
+ export declare function get_Zero(): bigint;
47
+ export declare function get_One(): bigint;
48
+ export declare function get_MinusOne(): bigint;
49
+ export declare function get_IsZero(x: bigint): boolean;
50
+ export declare function get_IsOne(x: bigint): boolean;
51
+ export declare function get_IsEven(x: bigint): boolean;
52
+ export declare function get_IsPowerOfTwo(x: bigint): boolean;
53
+ export declare function get_Sign(x: bigint): int32;
54
+ export declare function isNegative(x: bigint): boolean;
55
+ export declare function isPositive(x: bigint): boolean;
56
+ export declare function isEvenInteger(x: bigint): boolean;
57
+ export declare function isOddInteger(x: bigint): boolean;
58
+ export declare function isPow2(x: bigint): boolean;
59
+ export declare function fromZero(): bigint;
60
+ export declare function fromOne(): bigint;
61
+ export declare function fromInt8(n: int8): bigint;
62
+ export declare function fromUInt8(n: uint8): bigint;
63
+ export declare function fromInt16(n: int16): bigint;
64
+ export declare function fromUInt16(n: uint16): bigint;
65
+ export declare function fromInt32(n: int32): bigint;
66
+ export declare function fromUInt32(n: uint32): bigint;
67
+ export declare function fromInt64(n: int64): bigint;
68
+ export declare function fromUInt64(n: uint64): bigint;
69
+ export declare function fromInt128(n: int128): bigint;
70
+ export declare function fromUInt128(n: uint128): bigint;
71
+ export declare function fromNativeInt(n: nativeint): bigint;
72
+ export declare function fromUNativeInt(n: unativeint): bigint;
73
+ export declare function fromFloat16(n: float16): bigint;
74
+ export declare function fromFloat32(n: float32): bigint;
75
+ export declare function fromFloat64(n: float64): bigint;
76
+ export declare function fromDecimal(d: decimal): bigint;
77
+ export declare function fromBigInt(x: bigint): bigint;
78
+ export declare function fromBoolean(b: boolean): bigint;
79
+ export declare function fromChar(c: string): bigint;
80
+ export declare function fromString(s: string): bigint;
81
+ export declare function fromByteArray(bytes: ArrayLike<uint8>): bigint;
82
+ export declare function toByteArray(value: bigint): number[];
83
+ export declare function toInt8(x: bigint): int8;
84
+ export declare function toUInt8(x: bigint): uint8;
85
+ export declare function toInt16(x: bigint): int16;
86
+ export declare function toUInt16(x: bigint): uint16;
87
+ export declare function toInt32(x: bigint): int32;
88
+ export declare function toUInt32(x: bigint): uint32;
89
+ export declare function toInt64(x: bigint): int64;
90
+ export declare function toUInt64(x: bigint): uint64;
91
+ export declare function toInt128(x: bigint): int128;
92
+ export declare function toUInt128(x: bigint): uint128;
93
+ export declare function toNativeInt(x: bigint): nativeint;
94
+ export declare function toUNativeInt(x: bigint): unativeint;
95
+ export declare function toFloat16(x: bigint): float32;
96
+ export declare function toFloat32(x: bigint): float32;
97
+ export declare function toFloat64(x: bigint): float64;
98
+ export declare function toDecimal(x: bigint): decimal;
99
+ export declare function toBigInt(x: bigint): bigint;
100
+ export declare function toBoolean(x: bigint): boolean;
101
+ export declare function toChar(x: bigint): string;
102
+ export declare function toString(x: bigint): string;
103
+ export declare function tryParse(s: string, res: FSharpRef<bigint>): boolean;
104
+ export declare function parse(s: string): bigint;
105
+ export declare function pow(x: bigint, n: int32): bigint;
106
+ export declare function modPow(x: bigint, e: bigint, m: bigint): bigint;
107
+ export declare function divRem(x: bigint, y: bigint): [bigint, bigint];
108
+ export declare function divRem(x: bigint, y: bigint, out: FSharpRef<bigint>): bigint;
109
+ export declare function greatestCommonDivisor(x: bigint, y: bigint): bigint;
110
+ export declare function getBitLength(x: bigint): int64;
111
+ export declare function log2(x: bigint): float64;
112
+ export declare function log10(x: bigint): float64;
113
+ export declare function ln(x: bigint): float64;
114
+ export declare function log(x: bigint, base: float64): float64;
115
+ export declare function ilog2(x: bigint): bigint;