@nil-/xit 0.1.22 → 0.1.23

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/assets/index.js CHANGED
@@ -2,58 +2,58 @@ var P = (i) => {
2
2
  throw TypeError(i);
3
3
  };
4
4
  var C = (i, e, n) => e.has(i) || P("Cannot " + n);
5
- var w = (i, e, n) => (C(i, e, "read from private field"), n ? n.call(i) : e.get(i)), F = (i, e, n) => e.has(i) ? P("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(i) : e.set(i, n), S = (i, e, n, f) => (C(i, e, "write to private field"), f ? f.call(i, n) : e.set(i, n), n), W = (i, e, n) => (C(i, e, "access private method"), n);
5
+ var w = (i, e, n) => (C(i, e, "read from private field"), n ? n.call(i) : e.get(i)), F = (i, e, n) => e.has(i) ? P("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(i) : e.set(i, n), $ = (i, e, n, f) => (C(i, e, "write to private field"), f ? f.call(i, n) : e.set(i, n), n), W = (i, e, n) => (C(i, e, "access private method"), n);
6
6
  import { w as writable, g as get } from "./svelte/store.js";
7
- var j, I, x, M, D, L, N, $, U;
7
+ var j, I, k, M, D, L, N, S, U;
8
8
  let Service$1 = (U = class {
9
9
  constructor({ host: e, port: n }) {
10
10
  F(this, j);
11
- F(this, x);
11
+ F(this, k);
12
12
  // 0 idle, 1 has connected, 2 keep reconnecting, 3 stopped
13
13
  F(this, M);
14
14
  F(this, D);
15
15
  F(this, L);
16
16
  F(this, N);
17
- F(this, $);
18
- S(this, N, `${e ?? "localhost"}${n != null ? `:${n}` : ""}`), S(this, x, 0), S(this, M, null), S(this, D, null), S(this, L, null), S(this, $, null);
17
+ F(this, S);
18
+ $(this, N, `${e ?? "localhost"}${n != null ? `:${n}` : ""}`), $(this, k, 0), $(this, M, null), $(this, D, null), $(this, L, null), $(this, S, null);
19
19
  }
20
20
  on_message(e) {
21
- S(this, L, e);
21
+ $(this, L, e);
22
22
  }
23
23
  on_connect(e) {
24
- S(this, M, e);
24
+ $(this, M, e);
25
25
  }
26
26
  on_disconnect(e) {
27
- S(this, D, e);
27
+ $(this, D, e);
28
28
  }
29
29
  // non-blocking (run is blocking in c++)
30
30
  // calling it again should not do anything
31
31
  start() {
32
- w(this, $) == null && w(this, x) !== 1 && w(this, x) !== 3 && (S(this, $, new WebSocket(`ws://${w(this, N)}`)), w(this, $).binaryType = "arraybuffer", w(this, $).onopen = () => {
33
- S(this, x, 1), w(this, M) && w(this, M).call(this, w(this, N));
34
- }, w(this, $).onclose = () => {
35
- w(this, x) === 1 && (w(this, D) && w(this, D).call(this, w(this, N)), S(this, x, 2), W(this, j, I).call(this));
36
- }, w(this, $).onerror = () => {
37
- w(this, x) !== 1 && w(this, x) !== 3 && (S(this, x, 2), W(this, j, I).call(this));
38
- }, w(this, $).onmessage = (e) => {
32
+ w(this, S) == null && w(this, k) !== 1 && w(this, k) !== 3 && ($(this, S, new WebSocket(`ws://${w(this, N)}`)), w(this, S).binaryType = "arraybuffer", w(this, S).onopen = () => {
33
+ w(this, k) == 3 ? this.stop() : ($(this, k, 1), w(this, M) && w(this, M).call(this, w(this, N)));
34
+ }, w(this, S).onclose = () => {
35
+ w(this, k) === 1 && (w(this, D) && w(this, D).call(this, w(this, N)), $(this, k, 2), W(this, j, I).call(this));
36
+ }, w(this, S).onerror = () => {
37
+ w(this, k) !== 1 && w(this, k) !== 3 ? ($(this, k, 2), W(this, j, I).call(this)) : w(this, k) === 3 && this.stop();
38
+ }, w(this, S).onmessage = (e) => {
39
39
  w(this, L) && w(this, L).call(this, w(this, N), new Uint8Array(e.data));
40
40
  });
41
41
  }
42
42
  stop() {
43
- S(this, x, 3), w(this, $) != null && (w(this, $).close(), S(this, $, null));
43
+ $(this, k, 3), w(this, S) != null && w(this, S).readyState !== WebSocket.CONNECTING && (w(this, S).close(), $(this, S, null));
44
44
  }
45
45
  restart() {
46
- S(this, x, 0);
46
+ $(this, k, 0);
47
47
  }
48
48
  publish(e) {
49
- w(this, $) != null && w(this, x) == 1 && w(this, $).send(e);
49
+ w(this, S) != null && w(this, k) == 1 && w(this, S).send(e);
50
50
  }
51
51
  send(e, n) {
52
52
  e === w(this, N) && this.publish(n);
53
53
  }
54
54
  }, j = new WeakSet(), I = function() {
55
- w(this, $) != null && (w(this, $).close(), S(this, $, null)), setTimeout(() => this.start(), 1e3);
56
- }, x = new WeakMap(), M = new WeakMap(), D = new WeakMap(), L = new WeakMap(), N = new WeakMap(), $ = new WeakMap(), U);
55
+ w(this, S) != null && (w(this, S).close(), $(this, S, null)), setTimeout(() => this.start(), 1e3);
56
+ }, k = new WeakMap(), M = new WeakMap(), D = new WeakMap(), L = new WeakMap(), N = new WeakMap(), S = new WeakMap(), U);
57
57
  const header = (i) => {
58
58
  const e = new Uint8Array(4);
59
59
  return new DataView(e.buffer).setUint32(0, i, !1), e;
@@ -68,7 +68,7 @@ const header = (i) => {
68
68
  f.stop(), n("connection failed... stopping");
69
69
  }, 2500);
70
70
  f.on_connect(() => {
71
- console.log("connection tested... proceeding"), clearTimeout(u), f.stop(), e();
71
+ clearTimeout(u), f.stop(), e();
72
72
  }), f.start();
73
73
  }), service_fetch = async (i, e, n) => new Promise((f, u) => {
74
74
  const a = new Service$1(i), t = setTimeout(() => {
@@ -2253,42 +2253,42 @@ function requireRoot() {
2253
2253
  if (!y)
2254
2254
  return u.asPromise(h, _, c, p);
2255
2255
  var v = y === r;
2256
- function m(q, k) {
2256
+ function m(q, A) {
2257
2257
  if (y) {
2258
2258
  if (v)
2259
2259
  throw q;
2260
- var A = y;
2261
- y = null, A(q, k);
2260
+ var x = y;
2261
+ y = null, x(q, A);
2262
2262
  }
2263
2263
  }
2264
2264
  function g(q) {
2265
- var k = q.lastIndexOf("google/protobuf/");
2266
- if (k > -1) {
2267
- var A = q.substring(k);
2268
- if (A in s) return A;
2265
+ var A = q.lastIndexOf("google/protobuf/");
2266
+ if (A > -1) {
2267
+ var x = q.substring(A);
2268
+ if (x in s) return x;
2269
2269
  }
2270
2270
  return null;
2271
2271
  }
2272
- function b(q, k) {
2272
+ function b(q, A) {
2273
2273
  try {
2274
- if (u.isString(k) && k.charAt(0) === "{" && (k = JSON.parse(k)), !u.isString(k))
2275
- _.setOptions(k.options).addJSON(k.nested);
2274
+ if (u.isString(A) && A.charAt(0) === "{" && (A = JSON.parse(A)), !u.isString(A))
2275
+ _.setOptions(A.options).addJSON(A.nested);
2276
2276
  else {
2277
2277
  t.filename = q;
2278
- var A = t(k, _, p), B, E = 0;
2279
- if (A.imports)
2280
- for (; E < A.imports.length; ++E)
2281
- (B = g(A.imports[E]) || _.resolvePath(q, A.imports[E])) && R(B);
2282
- if (A.weakImports)
2283
- for (E = 0; E < A.weakImports.length; ++E)
2284
- (B = g(A.weakImports[E]) || _.resolvePath(q, A.weakImports[E])) && R(B, !0);
2278
+ var x = t(A, _, p), B, E = 0;
2279
+ if (x.imports)
2280
+ for (; E < x.imports.length; ++E)
2281
+ (B = g(x.imports[E]) || _.resolvePath(q, x.imports[E])) && R(B);
2282
+ if (x.weakImports)
2283
+ for (E = 0; E < x.weakImports.length; ++E)
2284
+ (B = g(x.weakImports[E]) || _.resolvePath(q, x.weakImports[E])) && R(B, !0);
2285
2285
  }
2286
2286
  } catch (V) {
2287
2287
  m(V);
2288
2288
  }
2289
2289
  !v && !O && m(null, _);
2290
2290
  }
2291
- function R(q, k) {
2291
+ function R(q, A) {
2292
2292
  if (q = g(q) || q, !(_.files.indexOf(q) > -1)) {
2293
2293
  if (_.files.push(q), q in s) {
2294
2294
  v ? b(q, s[q]) : (++O, setTimeout(function() {
@@ -2297,19 +2297,19 @@ function requireRoot() {
2297
2297
  return;
2298
2298
  }
2299
2299
  if (v) {
2300
- var A;
2300
+ var x;
2301
2301
  try {
2302
- A = u.fs.readFileSync(q).toString("utf8");
2302
+ x = u.fs.readFileSync(q).toString("utf8");
2303
2303
  } catch (B) {
2304
- k || m(B);
2304
+ A || m(B);
2305
2305
  return;
2306
2306
  }
2307
- b(q, A);
2307
+ b(q, x);
2308
2308
  } else
2309
2309
  ++O, _.fetch(q, function(B, E) {
2310
2310
  if (--O, !!y) {
2311
2311
  if (B) {
2312
- k ? O || m(null, _) : m(B);
2312
+ A ? O || m(null, _) : m(B);
2313
2313
  return;
2314
2314
  }
2315
2315
  b(q, E);
@@ -2882,9 +2882,11 @@ const protobufjs = /* @__PURE__ */ getDefaultExportFromCjs(light), proto_data =
2882
2882
  resub: () => s.start(),
2883
2883
  unsub: () => s.stop()
2884
2884
  });
2885
- const v = c(y, _);
2886
- return () => {
2887
- s.stop(), v();
2885
+ const { destroy: v } = c(y, _);
2886
+ return {
2887
+ destroy: () => {
2888
+ s.stop(), v();
2889
+ }
2888
2890
  };
2889
2891
  };
2890
2892
  }, create_frame = async ({
package/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- export type Action<T> = (target: T) => () => void;
1
+ export type Action<T> = (target: T) => {
2
+ destroy: () => void;
3
+ };
2
4
  export type Writable<T> = {
3
5
  set: (v: T) => void;
4
6
  subscribe: (cb: (v: T) => void) => () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nil-/xit",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./package.json": "./package.json",