repos / starfx

supercharged async flow control library.
git clone https://github.com/neurosnap/starfx.git

commit
b0613a8
parent
8f0f0f0
author
Eric Bower
date
2023-11-30 20:19:23 +0000 UTC
chore: update effection@v3-beta.3
14 files changed,  +73, -40
M mod.ts
M npm.ts
M deno.lock
+35, -0
 1@@ -144,6 +144,41 @@
 2     "https://deno.land/x/effection@3.0.0-beta.2/lib/sleep.ts": "44e3a80248dad7a47066a99a7daec9b318e87d5d211adf27776145544d455689",
 3     "https://deno.land/x/effection@3.0.0-beta.2/lib/types.ts": "4595c09ccfaae87c5a1d12006c23e5f4083fcd5658c322350f27801a9a9cb348",
 4     "https://deno.land/x/effection@3.0.0-beta.2/mod.ts": "ffae461c16d4a1bf24c2179582ab8d5c81ad0df61e4ae2fba51ef5e5bdf90345",
 5+    "https://deno.land/x/effection@3.0.0-beta.3/lib/abort-signal.ts": "8be1b331b2bc417d70fe4c07e0b806e89972b8eab519ce58beed7ec632ae9048",
 6+    "https://deno.land/x/effection@3.0.0-beta.3/lib/all.ts": "acadab8258228e290192f587c8c532428f9093337a9b7688ae55cbc2cacd5caf",
 7+    "https://deno.land/x/effection@3.0.0-beta.3/lib/async.ts": "086b27b253be944c47c633d105f1657e243cd8c0d35b9a0dc5383528d7235dde",
 8+    "https://deno.land/x/effection@3.0.0-beta.3/lib/call.ts": "2fe2d0ac5f4bda345ef8627b9047d19336f2926c25cf661bc982b84754aa57fa",
 9+    "https://deno.land/x/effection@3.0.0-beta.3/lib/channel.ts": "f86b36666463f8f86fc1ac1726a94f0f08dc05559ba710b8eb93581b2b8588e6",
10+    "https://deno.land/x/effection@3.0.0-beta.3/lib/context.ts": "108989ac839d6756e30f6c0afc458bfa3975dd0f970d5173b6b8f8473ce4c335",
11+    "https://deno.land/x/effection@3.0.0-beta.3/lib/deps.ts": "91062b4b97089a8cf36550d4f9605d325a0fd19bebc72d15524481a3b56ea669",
12+    "https://deno.land/x/effection@3.0.0-beta.3/lib/each.ts": "9689346d1db3fedcd87d48c70be5515ad3e18fa4b894755fa53910fb8ad356f3",
13+    "https://deno.land/x/effection@3.0.0-beta.3/lib/ensure.ts": "c3640cc12c1bc747a8a4086af476840db026d04ea22f45a697d53617b2b1cc66",
14+    "https://deno.land/x/effection@3.0.0-beta.3/lib/events.ts": "d962e7403d62948642f5a3161f611f4375932aa8702050575f0d538aab7c3467",
15+    "https://deno.land/x/effection@3.0.0-beta.3/lib/filter.ts": "39f349ee921ba718cf3259e05003255eeeafbb5ca6e437d2d269b1805da2236e",
16+    "https://deno.land/x/effection@3.0.0-beta.3/lib/first.ts": "5bc321069d2e2b87b6623f626a929d5d5ba32bca32ee03b37bdc1a64722eebb9",
17+    "https://deno.land/x/effection@3.0.0-beta.3/lib/instructions.ts": "5fd8638e385068adc6c1a896bba02b736d7c2c26e5124d3d063fdbcaf140abec",
18+    "https://deno.land/x/effection@3.0.0-beta.3/lib/lazy.ts": "92ea526c5ad7d88290f2a87168e038d482f97421379508d85cf2e049ee60639b",
19+    "https://deno.land/x/effection@3.0.0-beta.3/lib/lift.ts": "0c622bf0359f92235547b57efa66139b265a7b259428e6883469de0b3af32f5d",
20+    "https://deno.land/x/effection@3.0.0-beta.3/lib/main.ts": "a0deaf1d1d958ef7a5821d8ac3dfbd190a47608d603798a5fc3b0c2309a724da",
21+    "https://deno.land/x/effection@3.0.0-beta.3/lib/map.ts": "1a0c369dad53affc4b798a04142de637a75f981385acafcafd26bdc569675bc2",
22+    "https://deno.land/x/effection@3.0.0-beta.3/lib/mod.ts": "f7189b02d008baba1166d33779379b12f7104e0b6d373194270ac126a73ba82d",
23+    "https://deno.land/x/effection@3.0.0-beta.3/lib/pause.ts": "a690b0d67cf970c34f528df8c61d69eb43deda9817362776f6359f506dc0da45",
24+    "https://deno.land/x/effection@3.0.0-beta.3/lib/pipe.ts": "4a28fa93a1ba53661bafb84265f3fcb5614920bbecc0db1c261e1093da3b2cdf",
25+    "https://deno.land/x/effection@3.0.0-beta.3/lib/queue.ts": "80c6234cb6eaba9fd1abdae077e73f51897b099ea54f852b9a744e8eba51302f",
26+    "https://deno.land/x/effection@3.0.0-beta.3/lib/race.ts": "0c43f24ce5006768f5cbac8d6f5dc07848bafa625cc0bc6c24fb6a2f2a8808f2",
27+    "https://deno.land/x/effection@3.0.0-beta.3/lib/result.ts": "44e4bdadad155beb9bbfe41948819bbcb9e27a772283e52e89981bd6636a8687",
28+    "https://deno.land/x/effection@3.0.0-beta.3/lib/run.ts": "b85043bc8b30c0eb0d04654cdd07004b21145f2e3f59f52e39df76558e324ca4",
29+    "https://deno.land/x/effection@3.0.0-beta.3/lib/run/create.ts": "be9139af2fbe15908256d2d159dec8dca079f94cf02d488074c94fa26fc651fa",
30+    "https://deno.land/x/effection@3.0.0-beta.3/lib/run/frame.ts": "132fdace9c00e6ad0e249d7faab1c33680336c5fa8e4a893f092ecec4e2df786",
31+    "https://deno.land/x/effection@3.0.0-beta.3/lib/run/scope.ts": "e1c195fd4f954e4b525db25fb1db79447e745b2c0bb7c74a8a31ca58b1f4e64e",
32+    "https://deno.land/x/effection@3.0.0-beta.3/lib/run/task.ts": "7084b9cabdc338c776dc522ec8b677fb3ac41aa0c94e454d467731494cb68737",
33+    "https://deno.land/x/effection@3.0.0-beta.3/lib/run/types.ts": "010bea700f68fef99dd87ca5ca3cbbc90e026ac467889d8429d39cba0ee55fda",
34+    "https://deno.land/x/effection@3.0.0-beta.3/lib/run/value.ts": "d57428b45dfeecc9df1e68dadf8697dbc33cd412e6ffcab9d0ba4368e8c1fbd6",
35+    "https://deno.land/x/effection@3.0.0-beta.3/lib/shift-sync.ts": "74ecefa9cb2e145a3c52f363319f8d6296b804600852044b7d14bd53bc10b512",
36+    "https://deno.land/x/effection@3.0.0-beta.3/lib/signal.ts": "da723b43b6bd61ea86dab991e9a6c6249a61d3b1c3c98ef473b160c9383e7d07",
37+    "https://deno.land/x/effection@3.0.0-beta.3/lib/sleep.ts": "44e3a80248dad7a47066a99a7daec9b318e87d5d211adf27776145544d455689",
38+    "https://deno.land/x/effection@3.0.0-beta.3/lib/types.ts": "9738143fe6bfd5709a6ff10b6dd065582cfaca1167bf57902cb7bcca89b53dc4",
39+    "https://deno.land/x/effection@3.0.0-beta.3/mod.ts": "ffae461c16d4a1bf24c2179582ab8d5c81ad0df61e4ae2fba51ef5e5bdf90345",
40     "https://deno.land/x/expect@v0.3.0/expect.ts": "5e6717eddc9df376f7b2c9be6403e016130bb2edbb1acd261a2d6ea9608ee196",
41     "https://deno.land/x/expect@v0.3.0/matchers.ts": "a37ef4577739247af77a852cdcd69484f999a41ad86ec16bb63a88a7a47a2372",
42     "https://deno.land/x/expect@v0.3.0/mock.ts": "562d4b1d735d15b0b8e935f342679096b64fe452f86e96714fe8616c0c884914",
M deps.ts
+3, -2
 1@@ -1,4 +1,5 @@
 2 export type {
 3+  Callable,
 4   Channel,
 5   Instruction,
 6   Operation,
 7@@ -12,7 +13,7 @@ export type {
 8   Stream,
 9   Subscription,
10   Task,
11-} from "https://deno.land/x/effection@3.0.0-beta.2/mod.ts";
12+} from "https://deno.land/x/effection@3.0.0-beta.3/mod.ts";
13 export {
14   action,
15   call,
16@@ -32,7 +33,7 @@ export {
17   spawn,
18   suspend,
19   useAbortSignal,
20-} from "https://deno.land/x/effection@3.0.0-beta.2/mod.ts";
21+} from "https://deno.land/x/effection@3.0.0-beta.3/mod.ts";
22 
23 import React from "https://esm.sh/react@18.2.0?pin=v122";
24 export { React };
M fx/call.ts
+3, -4
 1@@ -1,10 +1,9 @@
 2-import type { Operation, Result } from "../deps.ts";
 3+import type { Callable, Operation, Result } from "../deps.ts";
 4 import { call, Err, Ok } from "../deps.ts";
 5-import type { Operator } from "../types.ts";
 6 
 7-export function* safe<T>(operator: Operator<T>): Operation<Result<T>> {
 8+export function* safe<T>(operator: Callable<T>): Operation<Result<T>> {
 9   try {
10-    const value: T = yield* call(operator as any) as any;
11+    const value = yield* call<T>(operator as any);
12     return Ok(value);
13   } catch (error) {
14     return Err(error);
M fx/parallel.ts
+3, -3
 1@@ -1,5 +1,5 @@
 2-import type { Channel, Operation, Result } from "../deps.ts";
 3-import type { Computation, Operator } from "../types.ts";
 4+import type { Callable, Channel, Operation, Result } from "../deps.ts";
 5+import type { Computation } from "../types.ts";
 6 import { createChannel, resource, spawn } from "../deps.ts";
 7 
 8 import { safe } from "./call.ts";
 9@@ -9,7 +9,7 @@ export interface ParallelRet<T> extends Computation<Result<T>[]> {
10   immediate: Channel<Result<T>, void>;
11 }
12 
13-export function parallel<T>(operations: Operator<T>[]) {
14+export function parallel<T>(operations: Callable<T>[]) {
15   const sequence = createChannel<Result<T>>();
16   const immediate = createChannel<Result<T>>();
17   const results: Result<T>[] = [];
M fx/race.ts
+2, -3
 1@@ -1,9 +1,8 @@
 2-import type { Operation, Task } from "../deps.ts";
 3+import type { Callable, Operation, Task } from "../deps.ts";
 4 import { action, call, resource, spawn } from "../deps.ts";
 5-import type { Operator } from "../types.ts";
 6 
 7 interface OpMap<T = unknown> {
 8-  [key: string]: Operator<T>;
 9+  [key: string]: Callable<T>;
10 }
11 
12 export function race<T>(
M fx/supervisor.ts
+3, -4
 1@@ -1,5 +1,4 @@
 2-import { Operation, Result, sleep } from "../deps.ts";
 3-import type { Operator } from "../types.ts";
 4+import { Callable, Operation, Result, sleep } from "../deps.ts";
 5 import { safe } from "./call.ts";
 6 import { parallel } from "./parallel.ts";
 7 import { log } from "../log.ts";
 8@@ -18,7 +17,7 @@ export function superviseBackoff(attempt: number, max = 10): number {
 9  * wait longer until attempting to restart and eventually give up.
10  */
11 export function supervise<T>(
12-  op: Operator<T>,
13+  op: Callable<T>,
14   backoff: (attemp: number) => number = superviseBackoff,
15 ) {
16   return function* () {
17@@ -50,7 +49,7 @@ export function supervise<T>(
18 }
19 
20 export function* keepAlive(
21-  ops: Operator<unknown>[],
22+  ops: Callable<unknown>[],
23   backoff?: (attempt: number) => number,
24 ): Operation<Result<void>[]> {
25   const group = yield* parallel(
M mod.ts
+1, -0
1@@ -23,6 +23,7 @@ export {
2   useAbortSignal,
3 } from "./deps.ts";
4 export type {
5+  Callable,
6   Channel,
7   Instruction,
8   Operation,
M npm.ts
+2, -2
 1@@ -31,9 +31,9 @@ async function init() {
 2       },
 3     ],
 4     mappings: {
 5-      "https://deno.land/x/effection@3.0.0-beta.2/mod.ts": {
 6+      "https://deno.land/x/effection@3.0.0-beta.3/mod.ts": {
 7         name: "effection",
 8-        version: "3.0.0-beta.2",
 9+        version: "3.0.0-beta.3",
10       },
11       "https://esm.sh/react@18.2.0?pin=v122": {
12         name: "react",
M query/thunk.ts
+4, -6
 1@@ -1,10 +1,8 @@
 2 import { compose } from "../compose.ts";
 3-import type { Operator, Payload } from "../types.ts";
 4+import type { Payload } from "../types.ts";
 5 import { keepAlive } from "../mod.ts";
 6-
 7 // TODO: remove store deps
 8 import { takeEvery } from "../redux/mod.ts";
 9-
10 import { isFn, isObject } from "./util.ts";
11 import { createKey } from "./create-key.ts";
12 import type {
13@@ -19,12 +17,12 @@ import type {
14   ThunkCtx,
15 } from "./types.ts";
16 import { API_ACTION_PREFIX } from "../action.ts";
17-import { Ok } from "../deps.ts";
18+import { Callable, Ok } from "../deps.ts";
19 
20 export interface ThunksApi<Ctx extends ThunkCtx> {
21   use: (fn: Middleware<Ctx>) => void;
22   routes: () => Middleware<Ctx>;
23-  bootup: Operator<void>;
24+  bootup: Callable<void>;
25   reset: () => void;
26 
27   /**
28@@ -128,7 +126,7 @@ export function createThunks<Ctx extends ThunkCtx = ThunkCtx<any>>(
29   } = { supervisor: takeEvery },
30 ): ThunksApi<Ctx> {
31   const middleware: Middleware<Ctx>[] = [];
32-  const visors: { [key: string]: Operator<unknown> } = {};
33+  const visors: { [key: string]: Callable<unknown> } = {};
34   const middlewareMap: { [key: string]: Middleware<Ctx> } = {};
35   let dynamicMiddlewareMap: { [key: string]: Middleware<Ctx> } = {};
36   const actionMap: {
M store/store.test.ts
+0, -1
1@@ -1,7 +1,6 @@
2 import { createScope, Operation, Result } from "../deps.ts";
3 import { parallel } from "../fx/mod.ts";
4 import { asserts, describe, it } from "../test.ts";
5-
6 import { StoreContext, StoreUpdateContext } from "./context.ts";
7 import { put, take, updateStore } from "./fx.ts";
8 import { configureStore, createStore } from "./store.ts";
M store/store.ts
+3, -2
 1@@ -1,4 +1,5 @@
 2 import {
 3+  Callable,
 4   createScope,
 5   createSignal,
 6   enablePatches,
 7@@ -9,7 +10,7 @@ import {
 8   Task,
 9 } from "../deps.ts";
10 import { BaseMiddleware, compose } from "../compose.ts";
11-import type { AnyAction, AnyState, Operator } from "../types.ts";
12+import type { AnyAction, AnyState } from "../types.ts";
13 import { safe } from "../fx/mod.ts";
14 import { Next } from "../query/types.ts";
15 import type { FxStore, Listener, StoreUpdater, UpdaterCtx } from "./types.ts";
16@@ -139,7 +140,7 @@ export function createStore<S extends AnyState>({
17     });
18   }
19 
20-  function run<T>(op: Operator<T>): Task<Result<T>> {
21+  function run<T>(op: Callable<T>): Task<Result<T>> {
22     return scope.run(function* () {
23       return yield* safe(op);
24     });
M store/supervisor.ts
+3, -3
 1@@ -1,7 +1,7 @@
 2 import { race } from "../fx/mod.ts";
 3 import { take } from "./fx.ts";
 4-import { call, Operation, sleep, spawn, Task } from "../deps.ts";
 5-import type { ActionWPayload, AnyAction, Operator } from "../types.ts";
 6+import { call, Callable, Operation, sleep, spawn, Task } from "../deps.ts";
 7+import type { ActionWPayload, AnyAction } from "../types.ts";
 8 import type { CreateActionPayload } from "../query/mod.ts";
 9 
10 const MS = 1000;
11@@ -44,7 +44,7 @@ export function poll(parentTimer: number = 5 * 1000, cancelType?: string) {
12 export function timer(timer: number = 5 * MINUTES) {
13   return function* onTimer(
14     actionType: string,
15-    op: (action: AnyAction) => Operator<unknown>,
16+    op: (action: AnyAction) => Callable<unknown>,
17   ) {
18     const map: { [key: string]: Task<unknown> } = {};
19 
M store/types.ts
+10, -3
 1@@ -1,6 +1,13 @@
 2-import type { Operation, Patch, Result, Scope, Task } from "../deps.ts";
 3+import type {
 4+  Callable,
 5+  Operation,
 6+  Patch,
 7+  Result,
 8+  Scope,
 9+  Task,
10+} from "../deps.ts";
11 import { BaseCtx } from "../mod.ts";
12-import type { AnyAction, AnyState, Operator } from "../types.ts";
13+import type { AnyAction, AnyState } from "../types.ts";
14 
15 export type StoreUpdater<S extends AnyState> = (s: S) => S | void;
16 
17@@ -32,7 +39,7 @@ export interface FxStore<S extends AnyState> {
18   getState: () => S;
19   subscribe: (fn: Listener) => () => void;
20   update: (u: StoreUpdater<S> | StoreUpdater<S>[]) => Operation<UpdaterCtx<S>>;
21-  run: <T>(op: Operator<T>) => Task<Result<T>>;
22+  run: <T>(op: Callable<T>) => Task<Result<T>>;
23   // deno-lint-ignore no-explicit-any
24   dispatch: (a: AnyAction) => any;
25   replaceReducer: (r: (s: S, a: AnyAction) => S) => void;
M types.ts
+1, -7
 1@@ -1,16 +1,10 @@
 2-import type { Instruction, Operation } from "./deps.ts";
 3+import type { Instruction } from "./deps.ts";
 4 
 5 export interface Computation<T = unknown> {
 6   // deno-lint-ignore no-explicit-any
 7   [Symbol.iterator](): Iterator<Instruction, T, any>;
 8 }
 9 
10-export type Operator<T> =
11-  | Operation<T>
12-  | Promise<T>
13-  | (() => Operation<T>)
14-  | (() => Promise<T>);
15-
16 export interface QueryState {
17   "@@starfx/loaders": Record<string, LoaderItemState>;
18   "@@starfx/data": Record<string, unknown>;