@floegence/floe-webapp-protocol 0.43.0 → 0.44.1

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