@effectionx/worker 0.1.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/README.md +149 -0
- package/esm/_dnt.shims.d.ts +2 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +57 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/almost_equals.d.ts +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/almost_equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/almost_equals.js +46 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/array_includes.d.ts +24 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/array_includes.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/array_includes.js +46 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/assert.d.ts +16 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/assert.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/assert.js +22 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/assertion_error.d.ts +26 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/assertion_error.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/assertion_error.js +30 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/equal.d.ts +17 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/equal.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/equal.js +183 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/equals.d.ts +35 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/equals.js +58 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/exists.d.ts +18 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/exists.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/exists.js +27 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/fail.d.ts +15 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/fail.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/fail.js +20 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/false.d.ts +18 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/false.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/false.js +22 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/greater.d.ts +20 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/greater.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/greater.js +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/greater_or_equal.d.ts +20 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/greater_or_equal.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/greater_or_equal.js +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/instance_of.d.ts +23 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/instance_of.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/instance_of.js +52 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/is_error.d.ts +25 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/is_error.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/is_error.js +53 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/less.d.ts +19 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/less.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/less.js +28 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/less_or_equal.d.ts +20 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/less_or_equal.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/less_or_equal.js +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/match.d.ts +18 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/match.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/match.js +26 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/mod.d.ts +44 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/mod.js +45 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/not_equals.d.ts +21 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/not_equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/not_equals.js +33 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/not_instance_of.d.ts +20 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/not_instance_of.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/not_instance_of.js +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/not_match.d.ts +18 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/not_match.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/not_match.js +26 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/not_strict_equals.d.ts +23 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/not_strict_equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/not_strict_equals.js +32 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/object_match.d.ts +29 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/object_match.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/object_match.js +167 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/rejects.d.ts +42 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/rejects.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/rejects.js +53 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/strict_equals.d.ts +24 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/strict_equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/strict_equals.js +57 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/string_includes.d.ts +18 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/string_includes.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/string_includes.js +26 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/throws.d.ts +45 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/throws.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/throws.js +44 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/unimplemented.d.ts +15 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/unimplemented.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/unimplemented.js +20 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/unreachable.d.ts +15 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/unreachable.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.12/unreachable.js +20 -0
- package/esm/deps/jsr.io/@std/internal/1.0.6/build_message.d.ts +82 -0
- package/esm/deps/jsr.io/@std/internal/1.0.6/build_message.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.6/build_message.js +110 -0
- package/esm/deps/jsr.io/@std/internal/1.0.6/diff.d.ts +140 -0
- package/esm/deps/jsr.io/@std/internal/1.0.6/diff.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.6/diff.js +276 -0
- package/esm/deps/jsr.io/@std/internal/1.0.6/diff_str.d.ts +99 -0
- package/esm/deps/jsr.io/@std/internal/1.0.6/diff_str.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.6/diff_str.js +182 -0
- package/esm/deps/jsr.io/@std/internal/1.0.6/format.d.ts +2 -0
- package/esm/deps/jsr.io/@std/internal/1.0.6/format.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.6/format.js +37 -0
- package/esm/deps/jsr.io/@std/internal/1.0.6/styles.d.ts +159 -0
- package/esm/deps/jsr.io/@std/internal/1.0.6/styles.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.6/styles.js +207 -0
- package/esm/deps/jsr.io/@std/internal/1.0.6/types.d.ts +16 -0
- package/esm/deps/jsr.io/@std/internal/1.0.6/types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.6/types.js +3 -0
- package/esm/mod.d.ts +2 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +1 -0
- package/esm/package.json +3 -0
- package/esm/worker.d.ts +135 -0
- package/esm/worker.d.ts.map +1 -0
- package/esm/worker.js +237 -0
- package/package.json +29 -0
- package/script/_dnt.shims.d.ts +2 -0
- package/script/_dnt.shims.d.ts.map +1 -0
- package/script/_dnt.shims.js +60 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/almost_equals.d.ts +29 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/almost_equals.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/almost_equals.js +49 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/array_includes.d.ts +24 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/array_includes.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/array_includes.js +49 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/assert.d.ts +16 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/assert.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/assert.js +25 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/assertion_error.d.ts +26 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/assertion_error.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/assertion_error.js +34 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/equal.d.ts +17 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/equal.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/equal.js +209 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/equals.d.ts +35 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/equals.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/equals.js +61 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/exists.d.ts +18 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/exists.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/exists.js +30 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/fail.d.ts +15 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/fail.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/fail.js +23 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/false.d.ts +18 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/false.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/false.js +25 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/greater.d.ts +20 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/greater.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/greater.js +32 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/greater_or_equal.d.ts +20 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/greater_or_equal.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/greater_or_equal.js +32 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/instance_of.d.ts +23 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/instance_of.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/instance_of.js +55 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/is_error.d.ts +25 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/is_error.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/is_error.js +56 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/less.d.ts +19 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/less.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/less.js +31 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/less_or_equal.d.ts +20 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/less_or_equal.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/less_or_equal.js +32 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/match.d.ts +18 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/match.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/match.js +29 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/mod.d.ts +44 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/mod.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/mod.js +61 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/not_equals.d.ts +21 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/not_equals.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/not_equals.js +36 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/not_instance_of.d.ts +20 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/not_instance_of.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/not_instance_of.js +32 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/not_match.d.ts +18 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/not_match.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/not_match.js +29 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/not_strict_equals.d.ts +23 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/not_strict_equals.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/not_strict_equals.js +35 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/object_match.d.ts +29 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/object_match.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/object_match.js +170 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/rejects.d.ts +42 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/rejects.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/rejects.js +56 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/strict_equals.d.ts +24 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/strict_equals.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/strict_equals.js +60 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/string_includes.d.ts +18 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/string_includes.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/string_includes.js +29 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/throws.d.ts +45 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/throws.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/throws.js +47 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/unimplemented.d.ts +15 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/unimplemented.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/unimplemented.js +23 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/unreachable.d.ts +15 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/unreachable.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.12/unreachable.js +23 -0
- package/script/deps/jsr.io/@std/internal/1.0.6/build_message.d.ts +82 -0
- package/script/deps/jsr.io/@std/internal/1.0.6/build_message.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.6/build_message.js +115 -0
- package/script/deps/jsr.io/@std/internal/1.0.6/diff.d.ts +140 -0
- package/script/deps/jsr.io/@std/internal/1.0.6/diff.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.6/diff.js +283 -0
- package/script/deps/jsr.io/@std/internal/1.0.6/diff_str.d.ts +99 -0
- package/script/deps/jsr.io/@std/internal/1.0.6/diff_str.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.6/diff_str.js +188 -0
- package/script/deps/jsr.io/@std/internal/1.0.6/format.d.ts +2 -0
- package/script/deps/jsr.io/@std/internal/1.0.6/format.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.6/format.js +63 -0
- package/script/deps/jsr.io/@std/internal/1.0.6/styles.d.ts +159 -0
- package/script/deps/jsr.io/@std/internal/1.0.6/styles.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.6/styles.js +242 -0
- package/script/deps/jsr.io/@std/internal/1.0.6/types.d.ts +16 -0
- package/script/deps/jsr.io/@std/internal/1.0.6/types.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.6/types.js +4 -0
- package/script/mod.d.ts +2 -0
- package/script/mod.d.ts.map +1 -0
- package/script/mod.js +17 -0
- package/script/package.json +3 -0
- package/script/worker.d.ts +135 -0
- package/script/worker.d.ts.map +1 -0
- package/script/worker.js +241 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
3
|
+
// This module is browser compatible.
|
|
4
|
+
// A module to print ANSI terminal colors. Inspired by chalk, kleur, and colors
|
|
5
|
+
// on npm.
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
|
+
if (mod && mod.__esModule) return mod;
|
|
24
|
+
var result = {};
|
|
25
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
26
|
+
__setModuleDefault(result, mod);
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.bold = bold;
|
|
31
|
+
exports.red = red;
|
|
32
|
+
exports.green = green;
|
|
33
|
+
exports.yellow = yellow;
|
|
34
|
+
exports.white = white;
|
|
35
|
+
exports.gray = gray;
|
|
36
|
+
exports.brightBlack = brightBlack;
|
|
37
|
+
exports.bgRed = bgRed;
|
|
38
|
+
exports.bgGreen = bgGreen;
|
|
39
|
+
exports.stripAnsiCode = stripAnsiCode;
|
|
40
|
+
// This code is vendored from `fmt/colors.ts`.
|
|
41
|
+
// deno-lint-ignore no-explicit-any
|
|
42
|
+
const dntShim = __importStar(require("../../../../../_dnt.shims.js"));
|
|
43
|
+
const { Deno } = dntShim.dntGlobalThis;
|
|
44
|
+
const noColor = typeof Deno?.noColor === "boolean"
|
|
45
|
+
? Deno.noColor
|
|
46
|
+
: false;
|
|
47
|
+
const enabled = !noColor;
|
|
48
|
+
function code(open, close) {
|
|
49
|
+
return {
|
|
50
|
+
open: `\x1b[${open.join(";")}m`,
|
|
51
|
+
close: `\x1b[${close}m`,
|
|
52
|
+
regexp: new RegExp(`\\x1b\\[${close}m`, "g"),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function run(str, code) {
|
|
56
|
+
return enabled
|
|
57
|
+
? `${code.open}${str.replace(code.regexp, code.open)}${code.close}`
|
|
58
|
+
: str;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Sets the style of text to be printed to bold.
|
|
62
|
+
*
|
|
63
|
+
* Disable by setting the `NO_COLOR` environmental variable.
|
|
64
|
+
*
|
|
65
|
+
* @param str Text to make bold
|
|
66
|
+
*
|
|
67
|
+
* @returns Bold text for printing
|
|
68
|
+
*
|
|
69
|
+
* @example Usage
|
|
70
|
+
* ```ts no-assert
|
|
71
|
+
* import { bold } from "@std/internal/styles";
|
|
72
|
+
*
|
|
73
|
+
* console.log(bold("Hello, world!")); // Prints "Hello, world!" in bold
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
function bold(str) {
|
|
77
|
+
return run(str, code([1], 22));
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Sets the color of text to be printed to red.
|
|
81
|
+
*
|
|
82
|
+
* Disable by setting the `NO_COLOR` environmental variable.
|
|
83
|
+
*
|
|
84
|
+
* @param str Text to make red
|
|
85
|
+
*
|
|
86
|
+
* @returns Red text for printing
|
|
87
|
+
*
|
|
88
|
+
* @example Usage
|
|
89
|
+
* ```ts no-assert
|
|
90
|
+
* import { red } from "@std/internal/styles";
|
|
91
|
+
*
|
|
92
|
+
* console.log(red("Hello, world!")); // Prints "Hello, world!" in red
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
function red(str) {
|
|
96
|
+
return run(str, code([31], 39));
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Sets the color of text to be printed to green.
|
|
100
|
+
*
|
|
101
|
+
* Disable by setting the `NO_COLOR` environmental variable.
|
|
102
|
+
*
|
|
103
|
+
* @param str Text to make green
|
|
104
|
+
*
|
|
105
|
+
* @returns Green text for print
|
|
106
|
+
*
|
|
107
|
+
* @example Usage
|
|
108
|
+
* ```ts no-assert
|
|
109
|
+
* import { green } from "@std/internal/styles";
|
|
110
|
+
*
|
|
111
|
+
* console.log(green("Hello, world!")); // Prints "Hello, world!" in green
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
function green(str) {
|
|
115
|
+
return run(str, code([32], 39));
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Sets the color of text to be printed to yellow.
|
|
119
|
+
*
|
|
120
|
+
* Disable by setting the `NO_COLOR` environmental variable.
|
|
121
|
+
*
|
|
122
|
+
* @param str Text to make yellow
|
|
123
|
+
*
|
|
124
|
+
* @returns Yellow text for print
|
|
125
|
+
*
|
|
126
|
+
* @example Usage
|
|
127
|
+
* ```ts no-assert
|
|
128
|
+
* import { yellow } from "@std/internal/styles";
|
|
129
|
+
*
|
|
130
|
+
* console.log(yellow("Hello, world!")); // Prints "Hello, world!" in yellow
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
function yellow(str) {
|
|
134
|
+
return run(str, code([33], 39));
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Sets the color of text to be printed to white.
|
|
138
|
+
*
|
|
139
|
+
* @param str Text to make white
|
|
140
|
+
*
|
|
141
|
+
* @returns White text for print
|
|
142
|
+
*
|
|
143
|
+
* @example Usage
|
|
144
|
+
* ```ts no-assert
|
|
145
|
+
* import { white } from "@std/internal/styles";
|
|
146
|
+
*
|
|
147
|
+
* console.log(white("Hello, world!")); // Prints "Hello, world!" in white
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
function white(str) {
|
|
151
|
+
return run(str, code([37], 39));
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Sets the color of text to be printed to gray.
|
|
155
|
+
*
|
|
156
|
+
* @param str Text to make gray
|
|
157
|
+
*
|
|
158
|
+
* @returns Gray text for print
|
|
159
|
+
*
|
|
160
|
+
* @example Usage
|
|
161
|
+
* ```ts no-assert
|
|
162
|
+
* import { gray } from "@std/internal/styles";
|
|
163
|
+
*
|
|
164
|
+
* console.log(gray("Hello, world!")); // Prints "Hello, world!" in gray
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
function gray(str) {
|
|
168
|
+
return brightBlack(str);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Sets the color of text to be printed to bright-black.
|
|
172
|
+
*
|
|
173
|
+
* @param str Text to make bright-black
|
|
174
|
+
*
|
|
175
|
+
* @returns Bright-black text for print
|
|
176
|
+
*
|
|
177
|
+
* @example Usage
|
|
178
|
+
* ```ts no-assert
|
|
179
|
+
* import { brightBlack } from "@std/internal/styles";
|
|
180
|
+
*
|
|
181
|
+
* console.log(brightBlack("Hello, world!")); // Prints "Hello, world!" in bright-black
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
function brightBlack(str) {
|
|
185
|
+
return run(str, code([90], 39));
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Sets the background color of text to be printed to red.
|
|
189
|
+
*
|
|
190
|
+
* @param str Text to make its background red
|
|
191
|
+
*
|
|
192
|
+
* @returns Red background text for print
|
|
193
|
+
*
|
|
194
|
+
* @example Usage
|
|
195
|
+
* ```ts no-assert
|
|
196
|
+
* import { bgRed } from "@std/internal/styles";
|
|
197
|
+
*
|
|
198
|
+
* console.log(bgRed("Hello, world!")); // Prints "Hello, world!" with red background
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
function bgRed(str) {
|
|
202
|
+
return run(str, code([41], 49));
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Sets the background color of text to be printed to green.
|
|
206
|
+
*
|
|
207
|
+
* @param str Text to make its background green
|
|
208
|
+
*
|
|
209
|
+
* @returns Green background text for print
|
|
210
|
+
*
|
|
211
|
+
* @example Usage
|
|
212
|
+
* ```ts no-assert
|
|
213
|
+
* import { bgGreen } from "@std/internal/styles";
|
|
214
|
+
*
|
|
215
|
+
* console.log(bgGreen("Hello, world!")); // Prints "Hello, world!" with green background
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
function bgGreen(str) {
|
|
219
|
+
return run(str, code([42], 49));
|
|
220
|
+
}
|
|
221
|
+
// https://github.com/chalk/ansi-regex/blob/02fa893d619d3da85411acc8fd4e2eea0e95a9d9/index.js
|
|
222
|
+
const ANSI_PATTERN = new RegExp([
|
|
223
|
+
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
|
|
224
|
+
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TXZcf-nq-uy=><~]))",
|
|
225
|
+
].join("|"), "g");
|
|
226
|
+
/**
|
|
227
|
+
* Remove ANSI escape codes from the string.
|
|
228
|
+
*
|
|
229
|
+
* @param string Text to remove ANSI escape codes from
|
|
230
|
+
*
|
|
231
|
+
* @returns Text without ANSI escape codes
|
|
232
|
+
*
|
|
233
|
+
* @example Usage
|
|
234
|
+
* ```ts no-assert
|
|
235
|
+
* import { red, stripAnsiCode } from "@std/internal/styles";
|
|
236
|
+
*
|
|
237
|
+
* console.log(stripAnsiCode(red("Hello, world!"))); // Prints "Hello, world!"
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
function stripAnsiCode(string) {
|
|
241
|
+
return string.replace(ANSI_PATTERN, "");
|
|
242
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Ways that lines in a diff can be different. */
|
|
2
|
+
export type DiffType = "removed" | "common" | "added";
|
|
3
|
+
/**
|
|
4
|
+
* Represents the result of a diff operation.
|
|
5
|
+
*
|
|
6
|
+
* @typeParam T The type of the value in the diff result.
|
|
7
|
+
*/
|
|
8
|
+
export interface DiffResult<T> {
|
|
9
|
+
/** The type of the diff. */
|
|
10
|
+
type: DiffType;
|
|
11
|
+
/** The value of the diff. */
|
|
12
|
+
value: T;
|
|
13
|
+
/** The details of the diff. */
|
|
14
|
+
details?: DiffResult<T>[];
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/internal/1.0.6/types.ts"],"names":[],"mappings":"AAGA,kDAAkD;AAClD,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEtD;;;;GAIG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,4BAA4B;IAC5B,IAAI,EAAE,QAAQ,CAAC;IACf,6BAA6B;IAC7B,KAAK,EAAE,CAAC,CAAC;IACT,+BAA+B;IAC/B,OAAO,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;CAC3B"}
|
package/script/mod.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
|
package/script/mod.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./worker.js"), exports);
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { type Operation } from "effection";
|
|
2
|
+
export interface WorkerResource<TSend, TRecv, TReturn> extends Operation<TReturn> {
|
|
3
|
+
send(data: TSend): Operation<TRecv>;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Object that represents messages the main thread
|
|
7
|
+
* sends to the worker. It provides function for
|
|
8
|
+
* handling messages.
|
|
9
|
+
*
|
|
10
|
+
* @template TSend - value main thread will send to the worker
|
|
11
|
+
* @template TRecv - value main thread will receive from the worker
|
|
12
|
+
*/
|
|
13
|
+
export interface WorkerMessages<TSend, TRecv> {
|
|
14
|
+
forEach(fn: (message: TSend) => Operation<TRecv>): Operation<void>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Argument received by workerMain function
|
|
18
|
+
*
|
|
19
|
+
* @template TSend - value main thread will send to the worker
|
|
20
|
+
* @template TRecv - value main thread will receive from the worker
|
|
21
|
+
* @template TData - data passed from the main thread to the worker during initialization
|
|
22
|
+
*/
|
|
23
|
+
export interface WorkerMainOptions<TSend, TRecv, TData> {
|
|
24
|
+
/**
|
|
25
|
+
* Namespace that provides APIs for working with incoming messages
|
|
26
|
+
*/
|
|
27
|
+
messages: WorkerMessages<TSend, TRecv>;
|
|
28
|
+
/**
|
|
29
|
+
* Initial data received by the worker from the main thread used for initialization.
|
|
30
|
+
*/
|
|
31
|
+
data: TData;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Entrypoint used in the worker that estaliblishes communication
|
|
35
|
+
* with the main thread. It can be used to return a value,
|
|
36
|
+
* respond to messages or both.
|
|
37
|
+
*
|
|
38
|
+
* @example Returning a value
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { workerMain } from "../worker.ts";
|
|
41
|
+
*
|
|
42
|
+
* await workerMain(function* ({ data }) {
|
|
43
|
+
* return data;
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @example Responding to messages
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { workerMain } from "../worker.ts";
|
|
50
|
+
*
|
|
51
|
+
* await workerMain(function* ({ messages }) {
|
|
52
|
+
* yield* messages.forEach(function* (message) {
|
|
53
|
+
* return message;
|
|
54
|
+
* });
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @example Responding to messages and return a value
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { workerMain } from "../worker.ts";
|
|
61
|
+
*
|
|
62
|
+
* await workerMain<number, number, number, number>(
|
|
63
|
+
* function* ({ messages, data: initial }) {
|
|
64
|
+
* let counter = initial;
|
|
65
|
+
*
|
|
66
|
+
* yield* messages.forEach(function* (message) {
|
|
67
|
+
* counter += message;
|
|
68
|
+
* return counter; // returns a value after each message
|
|
69
|
+
* });
|
|
70
|
+
*
|
|
71
|
+
* return counter; // returns the final value
|
|
72
|
+
* },
|
|
73
|
+
* );
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @template TSend - value main thread will send to the worker
|
|
77
|
+
* @template TRecv - value main thread will receive from the worker
|
|
78
|
+
* @template TReturn - worker operation return value
|
|
79
|
+
* @template TData - data passed from the main thread to the worker during initialization
|
|
80
|
+
* @param {(options: WorkerMainOptions<TSend, TRecv, TData>) => Operation<TReturn>} body
|
|
81
|
+
* @returns {Promise<void>}
|
|
82
|
+
*/
|
|
83
|
+
export declare function workerMain<TSend, TRecv, TReturn, TData>(body: (options: WorkerMainOptions<TSend, TRecv, TData>) => Operation<TReturn>): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Use on the main thread to create and exeecute a well behaved web worker.
|
|
86
|
+
*
|
|
87
|
+
* @example Compute a single value
|
|
88
|
+
* ```ts
|
|
89
|
+
* import { run } from "effection";
|
|
90
|
+
* import { useWorker } from "@effectionx/worker"
|
|
91
|
+
*
|
|
92
|
+
* await run(function*() {
|
|
93
|
+
* const worker = yield* useWorker("script.ts", { type: "module" });
|
|
94
|
+
*
|
|
95
|
+
* try {
|
|
96
|
+
* const result = yield* worker;
|
|
97
|
+
* } catch (e) {
|
|
98
|
+
* console.error(e);
|
|
99
|
+
* }
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @example Compute multipe values
|
|
104
|
+
* ```ts
|
|
105
|
+
* import { run } from "effection";
|
|
106
|
+
* import { useWorker } from "@effectionx/worker"
|
|
107
|
+
*
|
|
108
|
+
* await run(function*() {
|
|
109
|
+
* const worker = yield* useWorker("script.ts", { type: "module" });
|
|
110
|
+
*
|
|
111
|
+
* try {
|
|
112
|
+
* const result1 = yield* worker.send("Tom");
|
|
113
|
+
* const result2 = yield* worker.send("Dick");
|
|
114
|
+
* const result2 = yield* worker.send("Harry");
|
|
115
|
+
*
|
|
116
|
+
* // get the last result
|
|
117
|
+
* const finalResult = yield* worker;
|
|
118
|
+
* } catch (e) {
|
|
119
|
+
* console.error(e);
|
|
120
|
+
* }
|
|
121
|
+
* });
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @param url URL or string of script
|
|
125
|
+
* @param options WorkerOptions
|
|
126
|
+
* @template TSend - value main thread will send to the worker
|
|
127
|
+
* @template TRecv - value main thread will receive from the worker
|
|
128
|
+
* @template TReturn - worker operation return value
|
|
129
|
+
* @template TData - data passed from the main thread to the worker during initialization
|
|
130
|
+
* @returns {Operation<WorkerResource<TSend, TRecv>>}
|
|
131
|
+
*/
|
|
132
|
+
export declare function useWorker<TSend, TRecv, TReturn, TData>(url: string | URL, options?: WorkerOptions & {
|
|
133
|
+
data?: TData;
|
|
134
|
+
}): Operation<WorkerResource<TSend, TRecv, TReturn>>;
|
|
135
|
+
//# sourceMappingURL=worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AACA,OAAO,EAQL,KAAK,SAAS,EAMf,MAAM,WAAW,CAAC;AAEnB,MAAM,WAAW,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CACnD,SAAQ,SAAS,CAAC,OAAO,CAAC;IAC1B,IAAI,CAAC,IAAI,EAAE,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;CACrC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc,CAAC,KAAK,EAAE,KAAK;IAC1C,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;CACpE;AAED;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK;IACpD;;OAEG;IACH,QAAQ,EAAE,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACvC;;OAEG;IACH,IAAI,EAAE,KAAK,CAAC;CACb;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,wBAAsB,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAC3D,IAAI,EAAE,CAAC,OAAO,EAAE,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,SAAS,CAAC,OAAO,CAAC,GAC5E,OAAO,CAAC,IAAI,CAAC,CAsDf;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EACpD,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,OAAO,CAAC,EAAE,aAAa,GAAG;IAAE,IAAI,CAAC,EAAE,KAAK,CAAA;CAAE,GACzC,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAgElD"}
|
package/script/worker.js
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.workerMain = workerMain;
|
|
4
|
+
exports.useWorker = useWorker;
|
|
5
|
+
const mod_js_1 = require("./deps/jsr.io/@std/assert/1.0.12/mod.js");
|
|
6
|
+
const effection_1 = require("effection");
|
|
7
|
+
/**
|
|
8
|
+
* Entrypoint used in the worker that estaliblishes communication
|
|
9
|
+
* with the main thread. It can be used to return a value,
|
|
10
|
+
* respond to messages or both.
|
|
11
|
+
*
|
|
12
|
+
* @example Returning a value
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { workerMain } from "../worker.ts";
|
|
15
|
+
*
|
|
16
|
+
* await workerMain(function* ({ data }) {
|
|
17
|
+
* return data;
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @example Responding to messages
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { workerMain } from "../worker.ts";
|
|
24
|
+
*
|
|
25
|
+
* await workerMain(function* ({ messages }) {
|
|
26
|
+
* yield* messages.forEach(function* (message) {
|
|
27
|
+
* return message;
|
|
28
|
+
* });
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example Responding to messages and return a value
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { workerMain } from "../worker.ts";
|
|
35
|
+
*
|
|
36
|
+
* await workerMain<number, number, number, number>(
|
|
37
|
+
* function* ({ messages, data: initial }) {
|
|
38
|
+
* let counter = initial;
|
|
39
|
+
*
|
|
40
|
+
* yield* messages.forEach(function* (message) {
|
|
41
|
+
* counter += message;
|
|
42
|
+
* return counter; // returns a value after each message
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* return counter; // returns the final value
|
|
46
|
+
* },
|
|
47
|
+
* );
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @template TSend - value main thread will send to the worker
|
|
51
|
+
* @template TRecv - value main thread will receive from the worker
|
|
52
|
+
* @template TReturn - worker operation return value
|
|
53
|
+
* @template TData - data passed from the main thread to the worker during initialization
|
|
54
|
+
* @param {(options: WorkerMainOptions<TSend, TRecv, TData>) => Operation<TReturn>} body
|
|
55
|
+
* @returns {Promise<void>}
|
|
56
|
+
*/
|
|
57
|
+
async function workerMain(body) {
|
|
58
|
+
await (0, effection_1.main)(function* () {
|
|
59
|
+
let sent = (0, effection_1.createSignal)();
|
|
60
|
+
let controls = yield* (0, effection_1.on)(self, "message");
|
|
61
|
+
let outcome = (0, effection_1.withResolvers)();
|
|
62
|
+
self.postMessage({ type: "open" });
|
|
63
|
+
let result = yield* (0, effection_1.scoped)(function* () {
|
|
64
|
+
yield* (0, effection_1.spawn)(function* () {
|
|
65
|
+
let next = yield* controls.next();
|
|
66
|
+
while (true) {
|
|
67
|
+
let control = next.value.data;
|
|
68
|
+
if (control.type === "init") {
|
|
69
|
+
yield* (0, effection_1.spawn)(function* () {
|
|
70
|
+
try {
|
|
71
|
+
let value = yield* body({
|
|
72
|
+
data: control.data,
|
|
73
|
+
messages: {
|
|
74
|
+
*forEach(fn) {
|
|
75
|
+
for (let { value, response } of yield* (0, effection_1.each)(sent)) {
|
|
76
|
+
yield* (0, effection_1.spawn)(function* () {
|
|
77
|
+
try {
|
|
78
|
+
let result = yield* fn(value);
|
|
79
|
+
response.postMessage((0, effection_1.Ok)(result));
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
response.postMessage((0, effection_1.Err)(error));
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
yield* effection_1.each.next();
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
outcome.resolve((0, effection_1.Ok)(value));
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
outcome.resolve((0, effection_1.Err)(error));
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
else if (control.type === "send") {
|
|
98
|
+
let { value, response } = control;
|
|
99
|
+
sent.send({ value, response });
|
|
100
|
+
}
|
|
101
|
+
else if (control.type === "close") {
|
|
102
|
+
outcome.resolve((0, effection_1.Err)(new Error(`worker terminated`)));
|
|
103
|
+
}
|
|
104
|
+
next = yield* controls.next();
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
return yield* outcome.operation;
|
|
108
|
+
});
|
|
109
|
+
self.postMessage({ type: "close", result });
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Use on the main thread to create and exeecute a well behaved web worker.
|
|
114
|
+
*
|
|
115
|
+
* @example Compute a single value
|
|
116
|
+
* ```ts
|
|
117
|
+
* import { run } from "effection";
|
|
118
|
+
* import { useWorker } from "@effectionx/worker"
|
|
119
|
+
*
|
|
120
|
+
* await run(function*() {
|
|
121
|
+
* const worker = yield* useWorker("script.ts", { type: "module" });
|
|
122
|
+
*
|
|
123
|
+
* try {
|
|
124
|
+
* const result = yield* worker;
|
|
125
|
+
* } catch (e) {
|
|
126
|
+
* console.error(e);
|
|
127
|
+
* }
|
|
128
|
+
* });
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
131
|
+
* @example Compute multipe values
|
|
132
|
+
* ```ts
|
|
133
|
+
* import { run } from "effection";
|
|
134
|
+
* import { useWorker } from "@effectionx/worker"
|
|
135
|
+
*
|
|
136
|
+
* await run(function*() {
|
|
137
|
+
* const worker = yield* useWorker("script.ts", { type: "module" });
|
|
138
|
+
*
|
|
139
|
+
* try {
|
|
140
|
+
* const result1 = yield* worker.send("Tom");
|
|
141
|
+
* const result2 = yield* worker.send("Dick");
|
|
142
|
+
* const result2 = yield* worker.send("Harry");
|
|
143
|
+
*
|
|
144
|
+
* // get the last result
|
|
145
|
+
* const finalResult = yield* worker;
|
|
146
|
+
* } catch (e) {
|
|
147
|
+
* console.error(e);
|
|
148
|
+
* }
|
|
149
|
+
* });
|
|
150
|
+
* ```
|
|
151
|
+
*
|
|
152
|
+
* @param url URL or string of script
|
|
153
|
+
* @param options WorkerOptions
|
|
154
|
+
* @template TSend - value main thread will send to the worker
|
|
155
|
+
* @template TRecv - value main thread will receive from the worker
|
|
156
|
+
* @template TReturn - worker operation return value
|
|
157
|
+
* @template TData - data passed from the main thread to the worker during initialization
|
|
158
|
+
* @returns {Operation<WorkerResource<TSend, TRecv>>}
|
|
159
|
+
*/
|
|
160
|
+
function useWorker(url, options) {
|
|
161
|
+
return (0, effection_1.resource)(function* (provide) {
|
|
162
|
+
let outcome = (0, effection_1.withResolvers)();
|
|
163
|
+
let worker = new Worker(url, options);
|
|
164
|
+
let subscription = yield* (0, effection_1.on)(worker, "message");
|
|
165
|
+
let onclose = (event) => {
|
|
166
|
+
if (event.data.type === "close") {
|
|
167
|
+
let { result } = event.data;
|
|
168
|
+
if (result.ok) {
|
|
169
|
+
outcome.resolve(result.value);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
outcome.reject(result.error);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
worker.addEventListener("message", onclose);
|
|
177
|
+
let first = yield* subscription.next();
|
|
178
|
+
(0, mod_js_1.assert)(first.value.data.type === "open", `expected first message to arrive from worker to be of type "open", but was: ${first.value.data.type}`);
|
|
179
|
+
yield* (0, effection_1.spawn)(function* () {
|
|
180
|
+
let event = yield* (0, effection_1.once)(worker, "error");
|
|
181
|
+
event.preventDefault();
|
|
182
|
+
throw event.error;
|
|
183
|
+
});
|
|
184
|
+
try {
|
|
185
|
+
worker.postMessage({
|
|
186
|
+
type: "init",
|
|
187
|
+
data: options?.data,
|
|
188
|
+
});
|
|
189
|
+
yield* provide({
|
|
190
|
+
*send(value) {
|
|
191
|
+
let channel = yield* useMessageChannel();
|
|
192
|
+
worker.postMessage({
|
|
193
|
+
type: "send",
|
|
194
|
+
value,
|
|
195
|
+
response: channel.port2,
|
|
196
|
+
}, [channel.port2]);
|
|
197
|
+
channel.port1.start();
|
|
198
|
+
let event = yield* (0, effection_1.once)(channel.port1, "message");
|
|
199
|
+
let result = event.data;
|
|
200
|
+
if (result.ok) {
|
|
201
|
+
return result.value;
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
throw result.error;
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
[Symbol.iterator]: outcome.operation[Symbol.iterator],
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
finally {
|
|
211
|
+
worker.postMessage({ type: "close" });
|
|
212
|
+
yield* settled(outcome.operation);
|
|
213
|
+
worker.removeEventListener("message", onclose);
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
function useMessageChannel() {
|
|
218
|
+
return (0, effection_1.resource)(function* (provide) {
|
|
219
|
+
let channel = new MessageChannel();
|
|
220
|
+
try {
|
|
221
|
+
yield* provide(channel);
|
|
222
|
+
}
|
|
223
|
+
finally {
|
|
224
|
+
channel.port1.close();
|
|
225
|
+
channel.port2.close();
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
function settled(operation) {
|
|
230
|
+
return {
|
|
231
|
+
*[Symbol.iterator]() {
|
|
232
|
+
try {
|
|
233
|
+
yield* operation;
|
|
234
|
+
return (0, effection_1.Ok)();
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
return (0, effection_1.Err)(error);
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
}
|