@ersbeth/picoflow 1.1.0 → 1.1.2

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/picoflow.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { createSignal, createMemo, createResource, onMount, onCleanup } from 'solid-js';
2
+
1
3
  function isDisposable(obj) {
2
4
  return obj !== null && obj !== void 0 && typeof obj.dispose === "function";
3
5
  }
@@ -1545,4 +1547,110 @@ function map(initial) {
1545
1547
  );
1546
1548
  }
1547
1549
 
1548
- export { FlowArray, FlowEffect, FlowGraph, FlowMap, FlowNode, FlowNodeAsync, FlowSignal, array, constant, constantAsync, derivation, derivationAsync, effect, isDisposable, map, signal, state, stateAsync };
1550
+ class SolidState {
1551
+ /**
1552
+ * Returns the current value.
1553
+ */
1554
+ get;
1555
+ /**
1556
+ * Sets the value or updates it using a getter function.
1557
+ */
1558
+ set;
1559
+ /**
1560
+ * Creates a new SolidState with the given initial value.
1561
+ * @param initialValue - The initial value.
1562
+ */
1563
+ constructor(initialValue) {
1564
+ const [get, set] = createSignal(initialValue);
1565
+ this.get = get;
1566
+ this.set = set;
1567
+ }
1568
+ }
1569
+ class SolidDerivation {
1570
+ /**
1571
+ * Returns the current derived value.
1572
+ */
1573
+ get;
1574
+ /**
1575
+ * Creates a new SolidDerivation from a getter function or value.
1576
+ * @param calculator - The getter function or value.
1577
+ */
1578
+ constructor(calculator) {
1579
+ const get = createMemo(calculator);
1580
+ this.get = get;
1581
+ }
1582
+ }
1583
+ class SolidResource {
1584
+ /**
1585
+ * Returns the current value (or undefined if not yet loaded).
1586
+ */
1587
+ get;
1588
+ /**
1589
+ * Returns the current resource state.
1590
+ */
1591
+ state;
1592
+ /**
1593
+ * Returns the latest successfully loaded value (or undefined).
1594
+ */
1595
+ latest;
1596
+ /**
1597
+ * Triggers a refetch of the resource.
1598
+ */
1599
+ refetch;
1600
+ set;
1601
+ /**
1602
+ * Creates a new SolidResource from a fetcher function.
1603
+ * @param fetcher - The async fetcher function.
1604
+ */
1605
+ constructor(fetcher) {
1606
+ const [get, set] = createResource(fetcher);
1607
+ this.get = get;
1608
+ this.state = () => get.state;
1609
+ this.latest = () => get.latest;
1610
+ this.refetch = () => set.refetch();
1611
+ this.set = (value) => set.mutate(value);
1612
+ }
1613
+ }
1614
+
1615
+ function fromNode(node) {
1616
+ let initialized = false;
1617
+ const solidResource = new SolidResource(async () => {
1618
+ let value;
1619
+ if (initialized) {
1620
+ value = await node.get(null);
1621
+ } else {
1622
+ value = await node.pick();
1623
+ initialized = true;
1624
+ }
1625
+ return value;
1626
+ });
1627
+ let fx;
1628
+ onMount(() => {
1629
+ fx = new FlowEffect(async (t) => {
1630
+ const watched = node.watch(t);
1631
+ if (watched instanceof Promise) {
1632
+ await watched;
1633
+ }
1634
+ solidResource.refetch();
1635
+ });
1636
+ });
1637
+ onCleanup(() => fx.dispose());
1638
+ return solidResource;
1639
+ }
1640
+ function fromGetter(getter) {
1641
+ const derivation = new FlowNodeAsync(async (t) => {
1642
+ return getter(t);
1643
+ });
1644
+ return fromNode(derivation);
1645
+ }
1646
+ function from(flow) {
1647
+ if (flow instanceof FlowNodeAsync || flow instanceof FlowNode) {
1648
+ return fromNode(flow);
1649
+ }
1650
+ if (typeof flow === "function") {
1651
+ return fromGetter(flow);
1652
+ }
1653
+ throw new Error("Invalid flow type");
1654
+ }
1655
+
1656
+ export { FlowArray, FlowEffect, FlowGraph, FlowMap, FlowNode, FlowNodeAsync, FlowSignal, SolidDerivation, SolidResource, SolidState, array, constant, constantAsync, derivation, derivationAsync, effect, from, isDisposable, map, signal, state, stateAsync };
@@ -60,4 +60,5 @@
60
60
  * @see {@link https://github.com/yourusername/picoflow | GitHub Repository}
61
61
  */
62
62
  export * from './flow';
63
+ export * from './solid';
63
64
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAEH,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAEH,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
@@ -1,13 +1,13 @@
1
1
  import { FlowReadonly, FlowReadonlyAsync } from '../flow';
2
2
  import { FlowTracker } from '../flow/base/flowTracker';
3
3
  import { SolidResource } from './primitives';
4
+ import { NotPromise } from '../flow/base';
4
5
  /**
5
6
  * Utility type that excludes Promise types from T.
6
7
  * Used to ensure type safety for synchronous derivations/resources.
7
8
  *
8
9
  * @public
9
10
  */
10
- export type NotPromise<T> = T extends Promise<unknown> ? never : T;
11
11
  /**
12
12
  * Converts a FlowNode, FlowNodeAsync, or getter function into a SolidResource.
13
13
  *
@@ -50,5 +50,8 @@ export type NotPromise<T> = T extends Promise<unknown> ? never : T;
50
50
  *
51
51
  * @public
52
52
  */
53
- export declare function from<T>(flow: FlowReadonlyAsync<T> | FlowReadonly<T> | ((t: FlowTracker) => T) | ((t: FlowTracker) => Promise<T>)): SolidResource<T>;
53
+ export declare function from<T>(flow: FlowReadonlyAsync<T>): SolidResource<T>;
54
+ export declare function from<T>(flow: FlowReadonly<T>): SolidResource<T>;
55
+ export declare function from<T>(flow: (t: FlowTracker) => Promise<T>): SolidResource<T>;
56
+ export declare function from<T>(flow: (t: FlowTracker) => NotPromise<T>): SolidResource<T>;
54
57
  //# sourceMappingURL=converters.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"converters.d.ts","sourceRoot":"","sources":["../../../src/solid/converters.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE9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AC,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;AAChF,wBAAgB,IAAI,CAAC,CAAC,EACrB,IAAI,EAAE,CAAC,CAAC,EAAE,WAAW,KAAK,UAAU,CAAC,CAAC,CAAC,GACrC,aAAa,CAAC,CAAC,CAAC,CAAC"}
@@ -1,3 +1,3 @@
1
- export { from, type NotPromise } from './converters';
2
- export { SolidDerivation, type SolidGetter, type SolidObservable, SolidResource, SolidState, } from './primitives';
1
+ export * from './converters';
2
+ export * from './primitives';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/solid/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EACN,eAAe,EACf,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,aAAa,EACb,UAAU,GACV,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/solid/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ersbeth/picoflow",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Minimal Dataflow librairy for TypeScript",
5
5
  "type": "module",
6
6
  "exports": {
package/src/index.ts CHANGED
@@ -61,3 +61,4 @@
61
61
  */
62
62
 
63
63
  export * from "./flow";
64
+ export * from "./solid";
@@ -4,7 +4,7 @@ import { FlowEffect } from "../flow/base";
4
4
  import type { FlowTracker } from "../flow/base/flowTracker";
5
5
  import { FlowNodeAsync } from "../flow/nodes/async/flowNodeAsync";
6
6
  import { SolidResource } from "./primitives";
7
-
7
+ import type { NotPromise } from "../flow/base";
8
8
  /**
9
9
  * Converts an asynchronous FlowNodeAsync (Promise-based) into a SolidJS resource.
10
10
  *
@@ -36,7 +36,10 @@ function fromNode<T>(node: FlowNodeAsync<T> | FlowNode<T>): SolidResource<T> {
36
36
 
37
37
  onMount(() => {
38
38
  fx = new FlowEffect(async (t) => {
39
- node.watch(t);
39
+ const watched = node.watch(t);
40
+ if (watched instanceof Promise) {
41
+ await watched;
42
+ }
40
43
  solidResource.refetch();
41
44
  });
42
45
  });
@@ -76,7 +79,7 @@ function fromGetter<T>(
76
79
  *
77
80
  * @public
78
81
  */
79
- export type NotPromise<T> = T extends Promise<unknown> ? never : T;
82
+ // export type NotPromise<T> = T extends Promise<unknown> ? never : T;
80
83
 
81
84
  /**
82
85
  * Converts a FlowNode, FlowNodeAsync, or getter function into a SolidResource.
@@ -120,11 +123,17 @@ export type NotPromise<T> = T extends Promise<unknown> ? never : T;
120
123
  *
121
124
  * @public
122
125
  */
126
+ export function from<T>(flow: FlowReadonlyAsync<T>): SolidResource<T>;
127
+ export function from<T>(flow: FlowReadonly<T>): SolidResource<T>;
128
+ export function from<T>(flow: (t: FlowTracker) => Promise<T>): SolidResource<T>;
129
+ export function from<T>(
130
+ flow: (t: FlowTracker) => NotPromise<T>,
131
+ ): SolidResource<T>;
123
132
  export function from<T>(
124
133
  flow:
125
134
  | FlowReadonlyAsync<T>
126
135
  | FlowReadonly<T>
127
- | ((t: FlowTracker) => T)
136
+ | ((t: FlowTracker) => NotPromise<T>)
128
137
  | ((t: FlowTracker) => Promise<T>),
129
138
  ): SolidResource<T> {
130
139
  if (flow instanceof FlowNodeAsync || flow instanceof FlowNode) {
@@ -1,8 +1,2 @@
1
- export { from, type NotPromise } from "./converters";
2
- export {
3
- SolidDerivation,
4
- type SolidGetter,
5
- type SolidObservable,
6
- SolidResource,
7
- SolidState,
8
- } from "./primitives";
1
+ export * from "./converters";
2
+ export * from "./primitives";