@floegence/floe-webapp-protocol 0.43.0 → 0.44.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/client.d.ts CHANGED
@@ -1,10 +1,11 @@
1
- import type { ArtifactSource, ConnectionSnapshot, ConnectionState, Session } from '@floegence/flowersec-core';
1
+ import type { ArtifactSource, ConnectionDiagnostic, ConnectionSnapshot, ConnectionState, Session } from '@floegence/flowersec-core';
2
2
  import type { ConnectionControllerOptions } from '@floegence/flowersec-core/browser';
3
3
  import { type JSX } from 'solid-js';
4
4
  import type { ProtocolContract } from './contract';
5
5
  interface ProtocolContextValue {
6
6
  status: () => ConnectionState;
7
7
  snapshot: () => ConnectionSnapshot;
8
+ diagnostic: () => ConnectionDiagnostic;
8
9
  error: () => Error | null;
9
10
  session: () => Session | null;
10
11
  rpcTransport: () => Session['rpc'] | null;
package/dist/index2.js CHANGED
@@ -1,33 +1,37 @@
1
- import { createContext as S, onCleanup as x, createComponent as E, useContext as z } from "solid-js";
2
- import { createStore as O } from "solid-js/store";
3
- const R = () => import("@floegence/flowersec-core/browser");
4
- class j extends Error {
1
+ import { connectionDiagnostic as C, ConnectionControllerError as z } from "@floegence/flowersec-core";
2
+ import { createContext as D, onCleanup as O, createComponent as g, useContext as N } from "solid-js";
3
+ import { createStore as R } from "solid-js/store";
4
+ const j = () => import("@floegence/flowersec-core/browser");
5
+ class F extends Error {
5
6
  constructor() {
6
7
  super("Connection source or options changed; call replaceConnection() explicitly"), this.name = "ConnectionReplacementRequiredError";
7
8
  }
8
9
  }
9
- const m = S(), w = Object.freeze({
10
+ const v = D(), y = Object.freeze({
10
11
  state: "idle",
11
12
  attempt: 0
12
- });
13
- function A(n) {
14
- const [t, p] = O({
15
- snapshot: w,
13
+ }), b = C(y);
14
+ function H(t) {
15
+ const [o, d] = R({
16
+ snapshot: y,
17
+ diagnostic: b,
16
18
  error: null
17
- }), h = n.contract;
18
- let r = null, u = null, a = null, l = null, s = 0;
19
- const d = (e, o, c) => r === e && a === o && s === c, b = (e, o, c, i) => {
20
- if (d(o, c, i))
19
+ }), S = t.contract;
20
+ let r = null, f = null, a = null, l = null, i = 0;
21
+ const p = (e, n, c) => r === e && a === n && i === c, E = (e, n, c, s) => {
22
+ if (p(n, c, s))
21
23
  try {
22
- if (c.lifecycle?.synchronize(e), !d(o, c, i)) return;
23
- p({
24
+ if (c.lifecycle?.synchronize(e), !p(n, c, s)) return;
25
+ const u = C(e);
26
+ d({
24
27
  snapshot: e,
25
- error: N(e)
28
+ diagnostic: u,
29
+ error: _(e, u)
26
30
  });
27
- } catch (f) {
28
- const P = f instanceof Error ? f : new Error("Floe connection binding failed");
29
- c.lifecycle?.dispose(), d(o, c, i) && p({
30
- snapshot: Object.freeze({
31
+ } catch (u) {
32
+ const x = u instanceof Error ? u : new Error("Floe connection binding failed");
33
+ if (c.lifecycle?.dispose(), p(n, c, s)) {
34
+ const h = Object.freeze({
31
35
  state: "failed",
32
36
  attempt: e.attempt,
33
37
  failure: Object.freeze({
@@ -37,38 +41,49 @@ function A(n) {
37
41
  retryDisposition: Object.freeze({
38
42
  kind: "terminal"
39
43
  })
40
- }),
41
- error: P
42
- }), o.close();
44
+ });
45
+ d({
46
+ snapshot: h,
47
+ diagnostic: C(h),
48
+ error: x
49
+ });
50
+ }
51
+ n.close();
43
52
  }
44
- }, y = async () => {
45
- const e = s;
46
- u?.(), u = null;
47
- const o = r, c = a;
48
- r = null, a = null, c?.lifecycle?.dispose(), o !== null && await o.close(), e === s && r === null && a === null && p({
49
- snapshot: w,
53
+ }, w = async () => {
54
+ const e = i;
55
+ f?.(), f = null;
56
+ const n = r, c = a;
57
+ r = null, a = null, c?.lifecycle?.dispose(), n !== null && await n.close(), e === i && r === null && a === null && d({
58
+ snapshot: y,
59
+ diagnostic: b,
50
60
  error: null
51
61
  });
52
- }, C = async (e) => {
53
- const o = s, {
62
+ }, m = async (e) => {
63
+ const n = i, {
54
64
  createConnectionController: c
55
- } = await R();
56
- if (o !== s) return;
57
- const i = c(e.source, e.controller);
58
- a = e, r = i, u = i.subscribe((f) => b(f, i, e, o)), i.start(), await i.waitForSession();
59
- }, v = {
60
- status: () => t.snapshot.state,
61
- snapshot: () => t.snapshot,
62
- error: () => t.error,
63
- session: () => t.snapshot.currentSession ?? null,
64
- rpcTransport: () => t.snapshot.currentSession?.rpc ?? null,
65
- contract: () => h,
65
+ } = await j();
66
+ if (n !== i) return;
67
+ const s = await c(e.source, e.controller);
68
+ if (n !== i) {
69
+ await s.close();
70
+ return;
71
+ }
72
+ a = e, r = s, f = s.subscribe((u) => E(u, s, e, n)), s.start(), await s.waitForSession();
73
+ }, P = {
74
+ status: () => o.snapshot.state,
75
+ snapshot: () => o.snapshot,
76
+ diagnostic: () => o.diagnostic,
77
+ error: () => o.error,
78
+ session: () => o.snapshot.currentSession ?? null,
79
+ rpcTransport: () => o.snapshot.currentSession?.rpc ?? null,
80
+ contract: () => S,
66
81
  connect: async (e) => {
67
- if (r !== null && a !== null && !F(a, e))
68
- throw new j();
82
+ if (r !== null && a !== null && !I(a, e))
83
+ throw new F();
69
84
  return l !== null || (l = (async () => {
70
85
  if (r === null) {
71
- await C(e);
86
+ await m(e);
72
87
  return;
73
88
  }
74
89
  r.start(), await r.waitForSession();
@@ -78,38 +93,38 @@ function A(n) {
78
93
  },
79
94
  replaceConnection: async (e) => (l !== null && await l.catch(() => {
80
95
  }), l = (async () => {
81
- s += 1, await y(), s += 1, await C(e);
96
+ i += 1, await w(), i += 1, await m(e);
82
97
  })().finally(() => {
83
98
  l = null;
84
99
  }), l),
85
100
  retryNow: () => r?.retryNow() ?? !1,
86
101
  disconnect: () => {
87
- s += 1, y();
102
+ i += 1, w();
88
103
  }
89
104
  };
90
- return x(() => {
91
- s += 1, u?.(), a?.lifecycle?.dispose(), r?.close();
92
- }), E(m.Provider, {
93
- value: v,
105
+ return O(() => {
106
+ i += 1, f?.(), a?.lifecycle?.dispose(), r?.close();
107
+ }), g(v.Provider, {
108
+ value: P,
94
109
  get children() {
95
- return n.children;
110
+ return t.children;
96
111
  }
97
112
  });
98
113
  }
99
- function B() {
100
- const n = z(m);
101
- if (!n) throw new Error("useProtocol must be used within a ProtocolProvider");
102
- return n;
114
+ function J() {
115
+ const t = N(v);
116
+ if (!t) throw new Error("useProtocol must be used within a ProtocolProvider");
117
+ return t;
103
118
  }
104
- function F(n, t) {
105
- return n.source === t.source && n.controller === t.controller && n.lifecycle === t.lifecycle;
119
+ function I(t, o) {
120
+ return t.source === o.source && t.controller === o.controller && t.lifecycle === o.lifecycle;
106
121
  }
107
- function N(n) {
108
- const t = n.failure;
109
- return t === void 0 ? null : new Error(`${t.phase}:${t.code}`);
122
+ function _(t, o) {
123
+ const d = t.failure;
124
+ return d === void 0 || t.state !== "failed" && t.state !== "closed" ? null : new z(t.state === "closed" ? "closed" : "failed", d, t.retryDisposition, o);
110
125
  }
111
126
  export {
112
- j as ConnectionReplacementRequiredError,
113
- A as ProtocolProvider,
114
- B as useProtocol
127
+ F as ConnectionReplacementRequiredError,
128
+ H as ProtocolProvider,
129
+ J as useProtocol
115
130
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floegence/floe-webapp-protocol",
3
- "version": "0.43.0",
3
+ "version": "0.44.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -34,7 +34,7 @@
34
34
  "solid-js": "^1.8.0"
35
35
  },
36
36
  "dependencies": {
37
- "@floegence/flowersec-core": "2.5.2"
37
+ "@floegence/flowersec-core": "3.1.1"
38
38
  },
39
39
  "devDependencies": {
40
40
  "solid-js": "^1.9.11",