@vielzeug/familiar 26.11.4 → 26.11.6

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/worker.js CHANGED
@@ -1,20 +1,20 @@
1
- import { unrefTimer as e } from "./_timers.js";
2
- import { FamiliarInvalidOptionsError as t, FamiliarRuntimeError as n, FamiliarTaskError as r, FamiliarTerminatedError as i, FamiliarTimeoutError as a } from "./errors.js";
3
- import { validateTimeout as o } from "./_pool-core.js";
4
- import { createPool as s } from "./_pool.js";
5
- import { createStreamPool as c } from "./_stream-pool.js";
1
+ import { createPool as e } from "./_pool.js";
2
+ import { validateTimeout as t } from "./_pool-core.js";
3
+ import { createStreamPool as n } from "./_stream-pool.js";
4
+ import { unrefTimer as r } from "./_timers.js";
5
+ import { FamiliarInvalidOptionsError as i, FamiliarRuntimeError as a, FamiliarTaskError as o, FamiliarTerminatedError as s, FamiliarTimeoutError as c } from "./errors.js";
6
6
  import "./protocol.js";
7
- //#region src/worker.ts
7
+ // src/worker.ts
8
8
  function resolveOptions(e = {}) {
9
- let { concurrency: n = 1, maxQueue: r, onFull: i = "reject", timeout: a } = e, s = n === "auto" ? Math.min(512, Math.max(1, globalThis.navigator?.hardwareConcurrency ?? 1)) : n;
10
- if (!Number.isInteger(s) || s < 1 || s > 512) throw new t("`concurrency` must be a positive integer ≤ 512 or \"auto\"");
11
- if (r !== void 0 && (!Number.isInteger(r) || r < 1)) throw new t("`maxQueue` must be a positive integer");
12
- if (i !== "reject" && i !== "wait") throw new t("`onFull` must be \"reject\" or \"wait\"");
13
- return o(a), {
9
+ let { concurrency: n = 1, maxQueue: r, onFull: a = "reject", timeout: o } = e, s = n === "auto" ? Math.min(512, Math.max(1, globalThis.navigator?.hardwareConcurrency ?? 1)) : n;
10
+ if (!Number.isInteger(s) || s < 1 || s > 512) throw new i("`concurrency` must be a positive integer ≤ 512 or \"auto\"");
11
+ if (r !== void 0 && (!Number.isInteger(r) || r < 1)) throw new i("`maxQueue` must be a positive integer");
12
+ if (a !== "reject" && a !== "wait") throw new i("`onFull` must be \"reject\" or \"wait\"");
13
+ return t(o), {
14
14
  concurrency: s,
15
15
  maxQueue: r,
16
- onFull: i,
17
- timeout: a
16
+ onFull: a,
17
+ timeout: o
18
18
  };
19
19
  }
20
20
  function isWorkerResponse(e) {
@@ -24,7 +24,7 @@ function isWorkerResponse(e) {
24
24
  }
25
25
  function responseError(e) {
26
26
  let t = Error(e.message);
27
- return t.name = e.name, t.stack = e.stack, e.category === "protocol" ? new n(e.message, { cause: t }) : new r(e.message, { cause: t });
27
+ return t.name = e.name, t.stack = e.stack, e.category === "protocol" ? new a(e.message, { cause: t }) : new o(e.message, { cause: t });
28
28
  }
29
29
  var Slot = class {
30
30
  #e;
@@ -43,14 +43,14 @@ var Slot = class {
43
43
  return this.#a(e, t, n, "run");
44
44
  }
45
45
  stream(e, t) {
46
- let stop = () => this.cancel(new i("Stream consumer stopped")), n = [], r = [], a = !1, o, emit = (e) => {
46
+ let stop = () => this.cancel(new s("Stream consumer stopped")), n = [], r = [], i = !1, a, emit = (e) => {
47
47
  let t = r.shift();
48
48
  t ? t({
49
49
  done: !1,
50
50
  value: e
51
51
  }) : n.push(e);
52
52
  }, finish = (e) => {
53
- for (a = !0, o = e; r.length > 0;) r.shift()(e === void 0 ? {
53
+ for (i = !0, a = e; r.length > 0;) r.shift()(e === void 0 ? {
54
54
  done: !0,
55
55
  value: void 0
56
56
  } : Promise.reject(e));
@@ -63,8 +63,8 @@ var Slot = class {
63
63
  done: !1,
64
64
  value: n.shift()
65
65
  };
66
- if (o !== void 0) throw o;
67
- return a ? {
66
+ if (a !== void 0) throw a;
67
+ return i ? {
68
68
  done: !0,
69
69
  value: void 0
70
70
  } : new Promise((e, t) => {
@@ -83,31 +83,31 @@ var Slot = class {
83
83
  };
84
84
  }
85
85
  terminate() {
86
- this.#t = !0, this.#s(), this.#u("reject", new i());
86
+ this.#t = !0, this.#s(), this.#u("reject", new s());
87
87
  }
88
- #a(t, r, o, s, c) {
89
- if (this.#t) return Promise.reject(new i());
90
- if (this.#n) return Promise.reject(new n("Worker slot is already busy"));
88
+ #a(e, t, n, i, o) {
89
+ if (this.#t) return Promise.reject(new s());
90
+ if (this.#n) return Promise.reject(new a("Worker slot is already busy"));
91
91
  try {
92
- let i = this.#o(), l = this.#r;
92
+ let s = this.#o(), l = this.#r;
93
93
  return this.#r = l === 2 ** 53 - 1 ? 0 : l + 1, new Promise((u, d) => {
94
94
  let f = {
95
- emit: c,
95
+ emit: o,
96
96
  id: l,
97
- kind: s,
97
+ kind: i,
98
98
  reject: d,
99
99
  resolve: u
100
100
  };
101
- this.#n = f, o !== void 0 && (f.timer = setTimeout(() => this.cancel(new a(o)), o), e(f.timer));
101
+ this.#n = f, n !== void 0 && (f.timer = setTimeout(() => this.cancel(new c(n)), n), r(f.timer));
102
102
  try {
103
- i.postMessage({
103
+ s.postMessage({
104
104
  id: l,
105
- input: t,
106
- kind: s,
105
+ input: e,
106
+ kind: i,
107
107
  version: 1
108
- }, r);
108
+ }, t);
109
109
  } catch (e) {
110
- this.cancel(new n("Failed to post message to worker", { cause: e }));
110
+ this.cancel(new a("Failed to post message to worker", { cause: e }));
111
111
  }
112
112
  });
113
113
  } catch (e) {
@@ -116,14 +116,14 @@ var Slot = class {
116
116
  }
117
117
  #o() {
118
118
  if (this.#i) return this.#i;
119
- if (typeof Worker > "u") throw new n("Worker API is unavailable in this runtime");
119
+ if (typeof Worker > "u") throw new a("Worker API is unavailable in this runtime");
120
120
  try {
121
121
  let e = new Worker(this.#e, { type: "module" });
122
122
  return e.onmessage = (t) => {
123
123
  this.#i === e && this.#l(t.data);
124
- }, e.onerror = (t) => this.#c(e, new n(t.message || "Worker failed")), e.onmessageerror = () => this.#c(e, new n("Worker response could not be deserialized")), this.#i = e, e;
124
+ }, e.onerror = (t) => this.#c(e, new a(t.message || "Worker failed")), e.onmessageerror = () => this.#c(e, new a("Worker response could not be deserialized")), this.#i = e, e;
125
125
  } catch (e) {
126
- throw new n("Failed to create Worker", { cause: e });
126
+ throw new a("Failed to create Worker", { cause: e });
127
127
  }
128
128
  }
129
129
  #s() {
@@ -134,7 +134,7 @@ var Slot = class {
134
134
  this.#i === e && (this.#s(), this.#u("reject", t), this.notify?.(t));
135
135
  }
136
136
  #l(e) {
137
- this.#n && (!isWorkerResponse(e) || e.id !== this.#n.id || this.#n.kind === "run" && e.kind === "chunk" ? this.cancel(new n("Worker returned an incompatible protocol response")) : e.kind === "chunk" ? this.#n.emit?.(e.value) : e.kind === "error" ? this.#u("reject", responseError(e.error)) : this.#u("resolve", e.value));
137
+ this.#n && (!isWorkerResponse(e) || e.id !== this.#n.id || this.#n.kind === "run" && e.kind === "chunk" ? this.cancel(new a("Worker returned an incompatible protocol response")) : e.kind === "chunk" ? this.#n.emit?.(e.value) : e.kind === "error" ? this.#u("reject", responseError(e.error)) : this.#u("resolve", e.value));
138
138
  }
139
139
  #u(e, t) {
140
140
  let n = this.#n;
@@ -145,23 +145,22 @@ function slots(e, t) {
145
145
  let n = typeof e == "string" ? e : e.href;
146
146
  return Array.from({ length: t.concurrency }, () => new Slot(n));
147
147
  }
148
- function createWorker(e, t = {}) {
149
- let n = resolveOptions(t);
150
- return s(slots(e, n), {
151
- defaultTimeout: n.timeout,
152
- maxQueue: n.maxQueue,
153
- onFull: n.onFull
148
+ function createWorker(t, n = {}) {
149
+ let r = resolveOptions(n);
150
+ return e(slots(t, r), {
151
+ defaultTimeout: r.timeout,
152
+ maxQueue: r.maxQueue,
153
+ onFull: r.onFull
154
154
  });
155
155
  }
156
156
  function createStreamWorker(e, t = {}) {
157
- let n = resolveOptions(t);
158
- return c(slots(e, n), {
159
- defaultTimeout: n.timeout,
160
- maxQueue: n.maxQueue,
161
- onFull: n.onFull
157
+ let r = resolveOptions(t);
158
+ return n(slots(e, r), {
159
+ defaultTimeout: r.timeout,
160
+ maxQueue: r.maxQueue,
161
+ onFull: r.onFull
162
162
  });
163
163
  }
164
- //#endregion
165
164
  export { createStreamWorker, createWorker };
166
165
 
167
166
  //# sourceMappingURL=worker.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vielzeug/familiar",
3
- "version": "26.11.4",
3
+ "version": "26.11.6",
4
4
  "description": "Web Worker pool with tasks, timeouts, cancellation",
5
5
  "repository": {
6
6
  "type": "git",
@@ -51,24 +51,24 @@
51
51
  "registry": "https://registry.npmjs.org/"
52
52
  },
53
53
  "scripts": {
54
- "build": "vite build && pnpm --silent run build:bundle && pnpm --silent run build:types && pnpm --silent run test:types && pnpm --silent run verify:exports",
54
+ "build": "vite build && bun run --silent build:bundle && bun run --silent build:types && bun run --silent test:types && bun run --silent verify:exports",
55
55
  "build:bundle": "vite build --config vite.bundle.config.ts",
56
56
  "build:types": "tsc -p tsconfig.declarations.json",
57
57
  "fix": "biome check --write src",
58
58
  "lint": "biome ci src",
59
- "prepublishOnly": "pnpm --silent run build",
59
+ "prepublishOnly": "bun run --silent build",
60
60
  "preview": "vite preview",
61
61
  "test": "vitest",
62
62
  "test:types": "tsc -p tsconfig.type-tests.json",
63
- "verify:exports": "node verify-exports.mjs"
63
+ "verify:exports": "bun verify-exports.mjs"
64
64
  },
65
65
  "dependencies": {
66
- "@vielzeug/arsenal": "26.11.4"
66
+ "@vielzeug/arsenal": "26.11.6"
67
67
  },
68
68
  "devDependencies": {
69
- "@types/node": "^26.6.5",
69
+ "@types/node": "^26.6.6",
70
70
  "typescript": "^6.0.3",
71
- "vite": "^8.3.4",
72
- "vitest": "^5.0.5"
71
+ "vite": "^8.3.6",
72
+ "vitest": "^5.1.0"
73
73
  }
74
74
  }