motely-wasm 5.6.7 → 5.7.2

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.
@@ -0,0 +1,185 @@
1
+ {
2
+ "runtimeTarget": {
3
+ "name": ".NETCoreApp,Version=v10.0/browser-wasm",
4
+ "signature": ""
5
+ },
6
+ "compilationOptions": {},
7
+ "targets": {
8
+ ".NETCoreApp,Version=v10.0": {},
9
+ ".NETCoreApp,Version=v10.0/browser-wasm": {
10
+ "Motely.BrowserWasm/5.7.0": {
11
+ "dependencies": {
12
+ "Bootsharp": "0.7.0",
13
+ "Bootsharp.Inject": "0.7.0",
14
+ "Microsoft.Extensions.DependencyInjection": "10.0.5",
15
+ "Motely": "5.7.0"
16
+ },
17
+ "runtime": {
18
+ "Motely.BrowserWasm.dll": {}
19
+ }
20
+ },
21
+ "Bootsharp/0.7.0": {
22
+ "dependencies": {
23
+ "Bootsharp.Common": "0.7.0"
24
+ },
25
+ "runtime": {
26
+ "lib/net10.0/Bootsharp.dll": {
27
+ "assemblyVersion": "0.7.0.0",
28
+ "fileVersion": "0.7.0.0"
29
+ }
30
+ }
31
+ },
32
+ "Bootsharp.Common/0.7.0": {
33
+ "runtime": {
34
+ "lib/net10.0/Bootsharp.Common.dll": {
35
+ "assemblyVersion": "0.7.0.0",
36
+ "fileVersion": "0.7.0.0"
37
+ }
38
+ }
39
+ },
40
+ "Bootsharp.Inject/0.7.0": {
41
+ "dependencies": {
42
+ "Bootsharp.Common": "0.7.0",
43
+ "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.5"
44
+ },
45
+ "runtime": {
46
+ "lib/net10.0/Bootsharp.Inject.dll": {
47
+ "assemblyVersion": "0.7.0.0",
48
+ "fileVersion": "0.7.0.0"
49
+ }
50
+ }
51
+ },
52
+ "JetBrains.Annotations/2025.2.4": {
53
+ "runtime": {
54
+ "lib/netstandard2.0/JetBrains.Annotations.dll": {
55
+ "assemblyVersion": "4242.42.42.42",
56
+ "fileVersion": "2025.2.4.0"
57
+ }
58
+ }
59
+ },
60
+ "Microsoft.Extensions.DependencyInjection/10.0.5": {
61
+ "dependencies": {
62
+ "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.5"
63
+ },
64
+ "runtime": {
65
+ "lib/net10.0/Microsoft.Extensions.DependencyInjection.dll": {
66
+ "assemblyVersion": "10.0.0.0",
67
+ "fileVersion": "10.0.526.15411"
68
+ }
69
+ }
70
+ },
71
+ "Microsoft.Extensions.DependencyInjection.Abstractions/10.0.5": {
72
+ "runtime": {
73
+ "lib/net10.0/Microsoft.Extensions.DependencyInjection.Abstractions.dll": {
74
+ "assemblyVersion": "10.0.0.0",
75
+ "fileVersion": "10.0.526.15411"
76
+ }
77
+ }
78
+ },
79
+ "SixLabors.ImageSharp/3.1.12": {
80
+ "runtime": {
81
+ "lib/net6.0/SixLabors.ImageSharp.dll": {
82
+ "assemblyVersion": "3.0.0.0",
83
+ "fileVersion": "3.1.12.0"
84
+ }
85
+ }
86
+ },
87
+ "YamlDotNet/16.3.0": {
88
+ "runtime": {
89
+ "lib/net8.0/YamlDotNet.dll": {
90
+ "assemblyVersion": "16.0.0.0",
91
+ "fileVersion": "16.3.0.0"
92
+ }
93
+ }
94
+ },
95
+ "Motely/5.7.0": {
96
+ "dependencies": {
97
+ "JetBrains.Annotations": "2025.2.4",
98
+ "SixLabors.ImageSharp": "3.1.12",
99
+ "YamlDotNet": "16.3.0"
100
+ },
101
+ "runtime": {
102
+ "Motely.dll": {
103
+ "assemblyVersion": "0.0.0.0",
104
+ "fileVersion": "0.0.0.0"
105
+ }
106
+ }
107
+ }
108
+ }
109
+ },
110
+ "libraries": {
111
+ "Motely.BrowserWasm/5.7.0": {
112
+ "type": "project",
113
+ "serviceable": false,
114
+ "sha512": ""
115
+ },
116
+ "Bootsharp/0.7.0": {
117
+ "type": "package",
118
+ "serviceable": true,
119
+ "sha512": "sha512-Z/B4VDVkBCveZIQmmYQLbqfcVDW+6LHLiD34LhqISu9/V72mhrFz7n8SZGe3x6H6cG1agKBvijBF1MB6ervszw==",
120
+ "path": "bootsharp/0.7.0",
121
+ "hashPath": "bootsharp.0.7.0.nupkg.sha512"
122
+ },
123
+ "Bootsharp.Common/0.7.0": {
124
+ "type": "package",
125
+ "serviceable": true,
126
+ "sha512": "sha512-TolVI+sqecFVD4fEtPrjc6OIbXErBHDUebiVHpFHvfwq/m4HLSSjqWs5HVbpzkDCiM6XrLH5eP4olVn5nJ8NOw==",
127
+ "path": "bootsharp.common/0.7.0",
128
+ "hashPath": "bootsharp.common.0.7.0.nupkg.sha512"
129
+ },
130
+ "Bootsharp.Inject/0.7.0": {
131
+ "type": "package",
132
+ "serviceable": true,
133
+ "sha512": "sha512-kU94FKW0eCXkss1B0MxX2HDvXRnMo7+fwrcw1Y70mTa7mb8OpozQoABEcFEnbOTXAmxa7uIHdkh5AkOJD+6ZMg==",
134
+ "path": "bootsharp.inject/0.7.0",
135
+ "hashPath": "bootsharp.inject.0.7.0.nupkg.sha512"
136
+ },
137
+ "JetBrains.Annotations/2025.2.4": {
138
+ "type": "package",
139
+ "serviceable": true,
140
+ "sha512": "sha512-TwbgxAkXxY+vNEhNVx/QXjJ4vqxmepOjsgRvvImQPbHkHMMb4W+ahL3laMsxXKtNT7iMy+E1B3xkqao2hf1n3A==",
141
+ "path": "jetbrains.annotations/2025.2.4",
142
+ "hashPath": "jetbrains.annotations.2025.2.4.nupkg.sha512"
143
+ },
144
+ "Microsoft.Extensions.DependencyInjection/10.0.5": {
145
+ "type": "package",
146
+ "serviceable": true,
147
+ "sha512": "sha512-v1SVsowG6YE1YnHVGmLWz57YTRCQRx9pH5ebIESXfm5isI9gA3QaMyg/oMTzPpXYZwSAVDzYItGJKfmV+pqXkQ==",
148
+ "path": "microsoft.extensions.dependencyinjection/10.0.5",
149
+ "hashPath": "microsoft.extensions.dependencyinjection.10.0.5.nupkg.sha512"
150
+ },
151
+ "Microsoft.Extensions.DependencyInjection.Abstractions/10.0.5": {
152
+ "type": "package",
153
+ "serviceable": true,
154
+ "sha512": "sha512-iVMtq9eRvzyhx8949EGT0OCYJfXi737SbRVzWXE5GrOgGj5AaZ9eUuxA/BSUfmOMALKn/g8KfFaNQw0eiB3lyA==",
155
+ "path": "microsoft.extensions.dependencyinjection.abstractions/10.0.5",
156
+ "hashPath": "microsoft.extensions.dependencyinjection.abstractions.10.0.5.nupkg.sha512"
157
+ },
158
+ "SixLabors.ImageSharp/3.1.12": {
159
+ "type": "package",
160
+ "serviceable": true,
161
+ "sha512": "sha512-iAg6zifihXEFS/t7fiHhZBGAdCp3FavsF4i2ZIDp0JfeYeDVzvmlbY1CNhhIKimaIzrzSi5M/NBFcWvZT2rB/A==",
162
+ "path": "sixlabors.imagesharp/3.1.12",
163
+ "hashPath": "sixlabors.imagesharp.3.1.12.nupkg.sha512"
164
+ },
165
+ "YamlDotNet/16.3.0": {
166
+ "type": "package",
167
+ "serviceable": true,
168
+ "sha512": "sha512-SgMOdxbz8X65z8hraIs6hOEdnkH6hESTAIUa7viEngHOYaH+6q5XJmwr1+yb9vJpNQ19hCQY69xbFsLtXpobQA==",
169
+ "path": "yamldotnet/16.3.0",
170
+ "hashPath": "yamldotnet.16.3.0.nupkg.sha512"
171
+ },
172
+ "Motely/5.7.0": {
173
+ "type": "project",
174
+ "serviceable": false,
175
+ "sha512": ""
176
+ }
177
+ },
178
+ "runtimes": {
179
+ "browser-wasm": [
180
+ "browser",
181
+ "any",
182
+ "base"
183
+ ]
184
+ }
185
+ }
@@ -0,0 +1,48 @@
1
+ {
2
+ "runtimeOptions": {
3
+ "tfm": "net10.0",
4
+ "includedFrameworks": [
5
+ {
6
+ "name": "Microsoft.NETCore.App",
7
+ "version": "10.0.5"
8
+ }
9
+ ],
10
+ "configProperties": {
11
+ "System.Linq.Expressions.CanEmitObjectArrayDelegate": false,
12
+ "Microsoft.Extensions.DependencyInjection.VerifyOpenGenericServiceTrimmability": true,
13
+ "System.AggressiveAttributeTrimming": true,
14
+ "System.ComponentModel.DefaultValueAttribute.IsSupported": false,
15
+ "System.ComponentModel.Design.IDesignerHost.IsSupported": false,
16
+ "System.ComponentModel.TypeConverter.EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization": false,
17
+ "System.ComponentModel.TypeDescriptor.IsComObjectDescriptorSupported": false,
18
+ "System.Data.DataSet.XmlSerializationIsSupported": false,
19
+ "System.Diagnostics.Debugger.IsSupported": false,
20
+ "System.Diagnostics.Metrics.Meter.IsSupported": false,
21
+ "System.Diagnostics.StackTrace.IsSupported": false,
22
+ "System.Diagnostics.Tracing.EventSource.IsSupported": false,
23
+ "System.Globalization.Invariant": true,
24
+ "System.TimeZoneInfo.Invariant": true,
25
+ "System.Globalization.PredefinedCulturesOnly": true,
26
+ "System.Linq.Enumerable.IsSizeOptimized": true,
27
+ "System.Net.Http.EnableActivityPropagation": false,
28
+ "System.Net.Http.UseNativeHttpHandler": true,
29
+ "System.Net.Http.WasmEnableStreamingResponse": true,
30
+ "System.Net.SocketsHttpHandler.Http3Support": false,
31
+ "System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
32
+ "System.Reflection.NullabilityInfoContext.IsSupported": false,
33
+ "System.Resources.ResourceManager.AllowCustomResourceTypes": false,
34
+ "System.Resources.UseSystemResourceKeys": true,
35
+ "System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported": false,
36
+ "System.Runtime.InteropServices.BuiltInComInterop.IsSupported": false,
37
+ "System.Runtime.InteropServices.EnableConsumingManagedCodeFromNativeHosting": false,
38
+ "System.Runtime.InteropServices.EnableCppCLIHostActivation": false,
39
+ "System.Runtime.InteropServices.Marshalling.EnableGeneratedComInterfaceComImportInterop": false,
40
+ "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
41
+ "System.StartupHookProvider.IsSupported": false,
42
+ "System.Text.Encoding.EnableUnsafeUTF7Encoding": false,
43
+ "System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault": false,
44
+ "System.Threading.Thread.EnableAutoreleasePool": false,
45
+ "System.Xml.XmlResolver.IsNetworkingEnabledByDefault": false
46
+ }
47
+ }
48
+ }
package/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Motely WASM - NativeAOT-LLVM via Bootsharp 0.7.0
2
+
3
+ Real Motely types exported directly for browser use. **No facades, no wrappers, no glue code.**
4
+
5
+ ## Built With
6
+
7
+ - **Bootsharp 0.7.0**: .NET ↔ JavaScript interop
8
+ - **NativeAOT-LLVM**: AOT compilation to optimized WebAssembly
9
+ - **Real Types**: Direct access to Motely interfaces and concrete classes
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import init, * as motely from 'motely-wasm';
15
+
16
+ await init();
17
+
18
+ // Use real Motely types
19
+ const provider = new motely.MotelyRandomSeedProvider(100);
20
+ const palindromeProvider = new motely.MotelyPalindromeSeedProvider();
21
+ const seedList = new motely.MotelySeedListProvider(['123', '456']);
22
+ ```
23
+
24
+ ## Available Types
25
+
26
+ - `IMotelySearch` - interface for search operations
27
+ - `IMotelySearchSettings` - interface for search configuration
28
+ - `IMotelySeedProvider` - interface for seed providers
29
+ - `MotelyRandomSeedProvider` - generates random seeds
30
+ - `MotelyPalindromeSeedProvider` - generates palindrome seeds
31
+ - `MotelySeedListProvider` - provides seeds from a list
32
+
33
+ ## Testing
34
+
35
+ Open `test.html` in a browser to interactively test the WASM module.
36
+
37
+ ## Architecture
38
+
39
+ ```
40
+ C# .NET Browser/JavaScript
41
+ ↓ ↓
42
+ Motely types → Bootsharp → TypeScript bindings
43
+ ↓ ↓
44
+ WASM ←──────────────→ JS
45
+ ```
46
+
47
+ Bootsharp handles all serialization automatically. No manual JSON conversions.
48
+
49
+ ## Build
50
+
51
+ ```bash
52
+ dotnet publish Motely.BrowserWasm/Motely.BrowserWasm.csproj -c Release
53
+ ```
54
+
55
+ Output: `motely-wasm/` directory with ES module and type definitions.
@@ -0,0 +1,16 @@
1
+ import type { Event } from "./event";
2
+
3
+
4
+ export namespace MotelyWasm.MotelyBrowserApi {
5
+ export function getVersion(): string;
6
+ }
7
+ export namespace Program {
8
+ export const onProgress: Event<[searched: bigint, found: bigint, elapsedMs: bigint]>;
9
+ export const onResult: Event<[seed: string, score: number]>;
10
+ export const onComplete: Event<[status: string, seedsFound: number, highestScore: number]>;
11
+ export function getVersion(): string;
12
+ export function validateJaml(jamlContent: string): string | null;
13
+ export function analyzeSeed(seed: string, deck: string, stake: string): string;
14
+ export function startSearch(jamlContent: string, threadCount: number): void;
15
+ export function stopSearch(): void;
16
+ }
package/bindings.g.js ADDED
@@ -0,0 +1,29 @@
1
+ import { exports } from "./exports";
2
+ import { Event } from "./event";
3
+ import { registerInstance, getInstance, disposeOnFinalize } from "./instances";
4
+
5
+ function getExports() { if (exports == null) throw Error("Boot the runtime before invoking C# APIs."); return exports; }
6
+ function serialize(obj) { return JSON.stringify(obj); }
7
+ function deserialize(json) { const result = JSON.parse(json); if (result === null) return undefined; return result; }
8
+
9
+ /* v8 ignore start */
10
+
11
+
12
+ export const MotelyWasm = {
13
+ MotelyBrowserApi: {
14
+ getVersion: () => getExports().Bootsharp_Generated_Exports_Motely_BrowserWasm_JSMotelyBrowserApi_GetVersion()
15
+ }
16
+ };
17
+ export const Program = {
18
+ onProgress: new Event(),
19
+ onProgressSerialized: (searched, found, elapsedMs) => Program.onProgress.broadcast(searched, found, elapsedMs),
20
+ onResult: new Event(),
21
+ onResultSerialized: (seed, score) => Program.onResult.broadcast(seed, score),
22
+ onComplete: new Event(),
23
+ onCompleteSerialized: (status, seedsFound, highestScore) => Program.onComplete.broadcast(status, seedsFound, highestScore),
24
+ getVersion: () => getExports().Program_GetVersion(),
25
+ validateJaml: (jamlContent) => getExports().Program_ValidateJaml(jamlContent),
26
+ analyzeSeed: (seed, deck, stake) => getExports().Program_AnalyzeSeed(seed, deck, stake),
27
+ startSearch: (jamlContent, threadCount) => getExports().Program_StartSearch(jamlContent, threadCount),
28
+ stopSearch: () => getExports().Program_StopSearch()
29
+ };
package/boot.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ import { RuntimeConfig, RuntimeAPI } from "./modules";
2
+ import { BootResources } from "./resources";
3
+ /** Lifecycle status of the runtime module. */
4
+ export declare enum BootStatus {
5
+ /** Ready to boot. */
6
+ Standby = 0,
7
+ /** Async boot process is in progress. */
8
+ Booting = 1,
9
+ /** Booted and ready for interop. */
10
+ Booted = 2
11
+ }
12
+ /** Boot process configuration. */
13
+ export type BootOptions = {
14
+ /** Absolute path to the directory where boot resources are hosted (eg, <code>/bin</code>). */
15
+ readonly root?: string;
16
+ /** Resources required to boot .NET runtime. */
17
+ readonly resources?: BootResources;
18
+ /** .NET runtime configuration. */
19
+ readonly config?: RuntimeConfig;
20
+ /** Creates .NET runtime instance. */
21
+ readonly create?: (config: RuntimeConfig) => Promise<RuntimeAPI>;
22
+ /** Binds imported C# APIs. */
23
+ readonly import?: (runtime: RuntimeAPI) => Promise<void>;
24
+ /** Starts .NET runtime. */
25
+ readonly run?: (runtime: RuntimeAPI) => Promise<void>;
26
+ /** Binds exported C# APIs. */
27
+ readonly export?: (runtime: RuntimeAPI) => Promise<void>;
28
+ };
29
+ /** Returns current runtime module lifecycle state. */
30
+ export declare function getStatus(): BootStatus;
31
+ /** Initializes .NET runtime and binds C# APIs.
32
+ * @param options Specify to configure the boot process.
33
+ * @return Promise that resolves into .NET runtime instance. */
34
+ export declare function boot(options?: BootOptions): Promise<RuntimeAPI>;
35
+ /** Terminates .NET runtime and removes WASM module from memory.
36
+ * @param code Exit code; will use 0 (normal exit) by default.
37
+ * @param reason Exit reason description (optional). */
38
+ export declare function exit(code?: number, reason?: string): Promise<void>;
package/boot.js ADDED
@@ -0,0 +1,66 @@
1
+ import { getMain } from "./modules";
2
+ import { resources } from "./resources";
3
+ import { buildConfig } from "./config";
4
+ import { bindImports } from "./imports";
5
+ import { bindExports } from "./exports";
6
+ /** Lifecycle status of the runtime module. */
7
+ export var BootStatus;
8
+ (function (BootStatus) {
9
+ /** Ready to boot. */
10
+ BootStatus[BootStatus["Standby"] = 0] = "Standby";
11
+ /** Async boot process is in progress. */
12
+ BootStatus[BootStatus["Booting"] = 1] = "Booting";
13
+ /** Booted and ready for interop. */
14
+ BootStatus[BootStatus["Booted"] = 2] = "Booted";
15
+ })(BootStatus || (BootStatus = {}));
16
+ let status = BootStatus.Standby;
17
+ let main;
18
+ /** Returns current runtime module lifecycle state. */
19
+ export function getStatus() {
20
+ return status;
21
+ }
22
+ /** Initializes .NET runtime and binds C# APIs.
23
+ * @param options Specify to configure the boot process.
24
+ * @return Promise that resolves into .NET runtime instance. */
25
+ export async function boot(options) {
26
+ if (status === BootStatus.Booted)
27
+ throw Error("Failed to boot .NET runtime: already booted.");
28
+ if (status === BootStatus.Booting)
29
+ throw Error("Failed to boot .NET runtime: already booting.");
30
+ status = BootStatus.Booting;
31
+ main = await getMain(options?.root);
32
+ const runtime = await createRuntime(main, options);
33
+ status = BootStatus.Booted;
34
+ return runtime;
35
+ }
36
+ /** Terminates .NET runtime and removes WASM module from memory.
37
+ * @param code Exit code; will use 0 (normal exit) by default.
38
+ * @param reason Exit reason description (optional). */
39
+ export async function exit(code, reason) {
40
+ if (status !== BootStatus.Booted)
41
+ throw Error("Failed to exit .NET runtime: not booted.");
42
+ try {
43
+ main?.exit(code ?? 0, reason);
44
+ }
45
+ catch { }
46
+ finally {
47
+ status = BootStatus.Standby;
48
+ }
49
+ }
50
+ async function createRuntime(main, opt) {
51
+ const cfg = opt?.config ?? await buildConfig(opt?.resources ?? resources, opt?.root);
52
+ const runtime = await opt?.create?.(cfg) || await main.dotnet.withConfig(cfg).create();
53
+ if (opt?.import)
54
+ await opt.import(runtime);
55
+ else
56
+ bindImports(runtime);
57
+ if (opt?.run)
58
+ await opt.run(runtime);
59
+ else
60
+ await runtime.runMain(cfg.mainAssemblyName, []);
61
+ if (opt?.export)
62
+ await opt.export(runtime);
63
+ else
64
+ await bindExports(runtime, cfg.mainAssemblyName);
65
+ return runtime;
66
+ }
package/config.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { RuntimeConfig } from "./modules";
2
+ import { BootResources } from "./resources";
3
+ /** Builds .NET runtime configuration.
4
+ * @param resources Resources required for runtime initialization.
5
+ * @param root When specified, assumes boot resources are side-loaded from the specified root. */
6
+ export declare function buildConfig(resources: BootResources, root?: string): Promise<RuntimeConfig>;
package/config.js ADDED
@@ -0,0 +1,60 @@
1
+ import { getRuntime, getNative, getMain } from "./modules";
2
+ import { decodeBase64 } from "./decoder";
3
+ /** Builds .NET runtime configuration.
4
+ * @param resources Resources required for runtime initialization.
5
+ * @param root When specified, assumes boot resources are side-loaded from the specified root. */
6
+ export async function buildConfig(resources, root) {
7
+ const embed = root == null;
8
+ const assets = await Promise.all([
9
+ resolveWasm(),
10
+ resolveModule("dotnet.js", "js-module-dotnet", embed ? getMain : undefined),
11
+ resolveModule("dotnet.native.js", "js-module-native", embed ? getNative : undefined),
12
+ resolveModule("dotnet.runtime.js", "js-module-runtime", embed ? getRuntime : undefined),
13
+ ...resources.assemblies.map(resolveAssembly)
14
+ ]);
15
+ const mt = !embed && (await import("./dotnet.g")).mt;
16
+ if (mt)
17
+ assets.push(await resolveModule("dotnet.native.worker.mjs", "js-module-threads"));
18
+ return { assets, mainAssemblyName: resources.entryAssemblyName };
19
+ async function resolveWasm() {
20
+ return {
21
+ name: resources.wasm.name,
22
+ buffer: await resolveBuffer(resources.wasm),
23
+ behavior: "dotnetwasm"
24
+ };
25
+ }
26
+ async function resolveModule(name, behavior, embed) {
27
+ return {
28
+ name,
29
+ moduleExports: embed ? await embed() : undefined,
30
+ behavior
31
+ };
32
+ }
33
+ async function resolveAssembly(res) {
34
+ return {
35
+ name: res.name,
36
+ buffer: await resolveBuffer(res),
37
+ behavior: "assembly"
38
+ };
39
+ }
40
+ async function resolveBuffer(res) {
41
+ if (typeof res.content === "string")
42
+ return decodeBase64(res.content);
43
+ if (res.content !== undefined)
44
+ return res.content.buffer;
45
+ if (!embed)
46
+ return fetchBuffer(res);
47
+ throw Error(`Failed to resolve '${res.name}' boot resource.`);
48
+ }
49
+ async function fetchBuffer(res) {
50
+ const path = `${root}/${res.name}`;
51
+ if (typeof window === "object")
52
+ return (await fetch(path)).arrayBuffer();
53
+ if (typeof process === "object") {
54
+ const { readFile } = await import("fs/promises");
55
+ const bin = await readFile(path);
56
+ return bin.buffer.slice(bin.byteOffset, bin.byteOffset + bin.byteLength);
57
+ }
58
+ throw Error(`Failed to fetch '${path}' boot resource: unsupported runtime.`);
59
+ }
60
+ }
package/decoder.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function decodeBase64(source: string): ArrayBuffer;
package/decoder.js ADDED
@@ -0,0 +1,51 @@
1
+ const lookup = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 62, 0, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 63, 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51]);
2
+ export function decodeBase64(source) {
3
+ if (typeof window === "object")
4
+ return decodeWithBrowser(source);
5
+ if (typeof process === "object")
6
+ return decodeWithNode(source);
7
+ return decodeNaive(source);
8
+ }
9
+ function decodeWithBrowser(source) {
10
+ const binaryString = window.atob(source);
11
+ const length = binaryString.length;
12
+ const buffer = new ArrayBuffer(length);
13
+ const uint8Array = new Uint8Array(buffer);
14
+ for (let i = 0; i < length; i++)
15
+ uint8Array[i] = binaryString.charCodeAt(i);
16
+ return buffer;
17
+ }
18
+ function decodeWithNode(source) {
19
+ const buffer = Buffer.from(source, "base64");
20
+ return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
21
+ }
22
+ function decodeNaive(source) {
23
+ const srcLen = source.length;
24
+ const padLen = (source[srcLen - 2] === "=" ? 2 : (source[srcLen - 1] === "=" ? 1 : 0));
25
+ const outLen = ((srcLen - padLen) * 3) >> 2;
26
+ const buffer = new Uint8Array(outLen);
27
+ let tmp;
28
+ let byteIndex = 0;
29
+ for (let i = 0, baseLen = srcLen - padLen; i < baseLen; i += 4) {
30
+ tmp = (lookup[source.charCodeAt(i)] << 18)
31
+ | (lookup[source.charCodeAt(i + 1)] << 12)
32
+ | (lookup[source.charCodeAt(i + 2)] << 6)
33
+ | (lookup[source.charCodeAt(i + 3)]);
34
+ buffer[byteIndex++] = (tmp >> 16) & 0xFF;
35
+ buffer[byteIndex++] = (tmp >> 8) & 0xFF;
36
+ buffer[byteIndex++] = tmp & 0xFF;
37
+ }
38
+ if (padLen === 1) {
39
+ tmp = (lookup[source.charCodeAt(srcLen - 4)] << 18)
40
+ | (lookup[source.charCodeAt(srcLen - 3)] << 12)
41
+ | (lookup[source.charCodeAt(srcLen - 2)] << 6);
42
+ buffer[byteIndex++] = (tmp >> 16) & 0xFF;
43
+ buffer[byteIndex++] = (tmp >> 8) & 0xFF;
44
+ }
45
+ else if (padLen === 2) {
46
+ tmp = (lookup[source.charCodeAt(srcLen - 4)] << 18)
47
+ | (lookup[source.charCodeAt(srcLen - 3)] << 12);
48
+ buffer[byteIndex++] = (tmp >> 16) & 0xFF;
49
+ }
50
+ return buffer.buffer;
51
+ }
@@ -0,0 +1,4 @@
1
+ //! Licensed to the .NET Foundation under one or more agreements.
2
+ //! The .NET Foundation licenses this file to you under the MIT license.
3
+ let e=!1,t=null,s=null,n=null,o=null;const r=[65,68,86,82,95,86,49,0],i=[68,79,84,78,69,84,95,73,80,67,95,86,49,0];function a(e){return Uint8Array.from([...g(2,1,p(8)),...m(e)])}function c(e){const t=function(e){let t=0;t+=4,t+=4,t+=1,t+=4;for(const s of e.providers)t+=8,t+=4,t+=h(s.provider_name),t+=h(s.arguments);return t}(e),s=[...g(2,3,p(t)),...d(e.circularBufferMB),...d(e.format),...l(e.requestRundown?1:0),...d(e.providers.length)];for(const t of e.providers)s.push(...m(t.keywords)),s.push(...d(t.logLevel)),s.push(...f(t.provider_name)),s.push(...f(t.arguments));return Uint8Array.from(s)}function l(e){return Uint8Array.from([e])}function u(e){return new Uint8Array(Uint16Array.from([e]).buffer)}function d(e){return new Uint8Array(Uint32Array.from([e]).buffer)}function m(e){return new Uint8Array(Uint32Array.from([e[1],e[0]]).buffer)}function f(e){const t=[];if(null==e||""===e)t.push(...d(1)),t.push(...u(0));else{const s=e.length,n="\0"===e[s-1];t.push(...d(s+(n?0:1)));for(let n=0;n<s;n++)t.push(...u(e.charCodeAt(n)));n||t.push(...u(0))}return t}function h(e){return null==e||""===e?6:4+2*e.length+2}function p(e){return 20+e}function g(e,t,s){return Uint8Array.from([...Uint8Array.from(i),...u(s),...l(e),...l(t),...u(0)])}const v="MONO_WASM: ";function w(e,...t){console.warn(v+e,...t)}let _,S;function y(){if(_=void 0,n.is_runtime_running())try{s.mono_background_exec(),s.mono_wasm_ds_exec(),C(100)}catch(e){n.mono_exit(1,e)}}function C(e=0){_&&0!==e||(_=o.safeSetTimeout(y,e))}class b{constructor(e){this.client_socket=e,this.messagesToSend=[],this.messagesReceived=[]}store(e){return this.messagesToSend.push(e),e.byteLength}poll(){return this.messagesReceived.length}recv(e,t){if(0===this.messagesReceived.length)return 0;const s=this.messagesReceived[0],n=Math.min(s.length,t);return o.HEAPU8.set(s.subarray(0,n),e),n===s.length?this.messagesReceived.shift():this.messagesReceived[0]=s.subarray(n),n}}function k(e){if(e||(e={}),!E)throw new Error("No active JS diagnostic session");if(!s.config.environmentVariables.DOTNET_WasmPerformanceInstrumentation)throw new Error("method instrumentation is not enabled, please enable it with WasmPerformanceInstrumentation MSBuild property");const t=n.createPromiseController();return P({onClosePromise:t.promise_control,skipDownload:e.skipDownload,commandOnAdvertise:()=>function(e){return c({circularBufferMB:e.circularBufferMB||256,format:1,requestRundown:!0,providers:[{keywords:[0,0],logLevel:4,provider_name:"Microsoft-DotNETCore-SampleProfiler",arguments:null},...e.extraProviders||[]]})}(e),onSessionStart:function(t){var s;o.safeSetTimeout(()=>{t.sendCommand(a(t.session_id))},1e3*(null!==(s=null==e?void 0:e.durationSeconds)&&void 0!==s?s:60))}}),t.promise}function A(e){if(e||(e={}),!E)throw new Error("No active JS diagnostic session");const t=n.createPromiseController();return P({onClosePromise:t.promise_control,skipDownload:e.skipDownload,commandOnAdvertise:()=>function(e){return c({circularBufferMB:e.circularBufferMB||256,format:1,requestRundown:!1,providers:[{keywords:[0,2],logLevel:4,provider_name:"System.Diagnostics.Metrics",arguments:`SessionId=SHARED;Metrics=System.Runtime;RefreshInterval=${e.intervalSeconds||1};MaxTimeSeries=1000;MaxHistograms=10;ClientId=${"10000000-1000-4000-8000-100000000000".replace(/[018]/g,e=>(+e^globalThis.crypto.getRandomValues(new Uint8Array(1))[0]&15>>+e/4).toString(16))};`},...e.extraProviders||[]]})}(e),onSessionStart:function(t){var s;o.safeSetTimeout(()=>{t.sendCommand(a(t.session_id))},1e3*(null!==(s=null==e?void 0:e.durationSeconds)&&void 0!==s?s:60))}}),t.promise}function D(e){if(e||(e={}),!E)throw new Error("No active JS diagnostic session");const t=n.createPromiseController();let s=0,r=!1;return P({onClosePromise:t.promise_control,skipDownload:e.skipDownload,commandOnAdvertise:()=>function(e){return c({circularBufferMB:e.circularBufferMB||256,format:1,requestRundown:!0,providers:[{keywords:[0,26738689],logLevel:5,provider_name:"Microsoft-Windows-DotNETRuntime",arguments:null},...e.extraProviders||[]]})}(e),onData:function(t,n){var i;t.store(n),r||(s&&clearTimeout(s),s=o.safeSetTimeout(()=>{r=!0,t.sendCommand(a(t.session_id))},1e3*(null!==(i=null==e?void 0:e.durationSeconds)&&void 0!==i?i:1)))}}),t.promise}let E,T,R=!1;class M extends b{constructor(e){super(e),this.client_socket=e,this.session_id=void 0,this.stopDelayedAfterLastMessage=void 0,this.resumedRuntime=!1}sendCommand(e){E?E.respond(e):w("no server yet")}async connectNewClient(){this.diagClient=await S.promise,U();const e=this.diagClient.commandOnAdvertise();this.respond(e)}is_advert_message(e){return r.every((t,s)=>t===e[s])}is_response_message(e){return i.every((t,s)=>t===e[s])&&255==e[16]}is_response_ok_with_session(e){return 28===e.byteLength&&0==e[17]}parse_session_id(e){const t=e.subarray(20,28),s=t[0]|t[1]<<8|t[2]<<16|t[3]<<24;return[t[4]|t[5]<<8|t[6]<<16|t[7]<<24,s]}send(e){var t,s,n;return C(),this.is_advert_message(e)?(E=this,this.connectNewClient()):this.is_response_message(e)?this.is_response_ok_with_session(e)?(this.session_id=this.parse_session_id(e),(null===(t=this.diagClient)||void 0===t?void 0:t.onSessionStart)&&this.diagClient.onSessionStart(this)):(null===(s=this.diagClient)||void 0===s?void 0:s.onError)?this.diagClient.onError(this,e):w("Diagnostic session "+this.session_id+" error : "+e.toString()):(null===(n=this.diagClient)||void 0===n?void 0:n.onData)?this.diagClient.onData(this,e):this.store(e),e.length}respond(e){this.messagesReceived.push(e),C()}close(){var e,t;return(null===(e=this.diagClient)||void 0===e?void 0:e.onClose)&&this.diagClient.onClose(this.messagesToSend),(null===(t=this.diagClient)||void 0===t?void 0:t.onClosePromise)&&this.diagClient.onClosePromise.resolve(this.messagesToSend),0===this.messagesToSend.length||(this.diagClient&&!this.diagClient.skipDownload&&function(e){const t=new Blob(e,{type:"application/octet-stream"}),s=URL.createObjectURL(t),n=document.createElement("a");n.download="trace."+(new Date).valueOf()+".nettrace",function(e,...t){console.info(v+e,...t)}(`Downloading trace ${n.download} - ${t.size} bytes`),n.href=s,document.body.appendChild(n),n.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0,view:window}))}(this.messagesToSend),this.messagesToSend=[]),0}}function U(){S=n.createPromiseController()}function P(e){if(S.promise_control.isDone)throw new Error("multiple clients in parallel are not allowed");S.promise_control.resolve(e)}function B(e,t){return new L(e,t)}class L extends b{constructor(e,t){super(e);const s=this.ws=new WebSocket(t),n=async e=>{const t=await e.data.arrayBuffer(),s=new Uint8Array(t);this.messagesReceived.push(s),y()};s.addEventListener("open",()=>{for(const e of this.messagesToSend)s.send(e);this.messagesToSend=[],y()},{once:!0}),s.addEventListener("message",n),s.addEventListener("error",()=>{w("Diagnostic server WebSocket connection was closed unexpectedly."),s.removeEventListener("message",n)},{once:!0})}send(e){return C(),this.ws.readyState==WebSocket.CLOSED?-1:this.ws.readyState==WebSocket.CONNECTING?super.store(e):(this.ws.send(e),e.length)}close(){return C(),this.ws.close(),0}}let N,W=1;function x(r){!function(r){if(e)throw new Error("Diag module already loaded");e=!0,t=r.diagnosticHelpers,s=r.runtimeHelpers,n=r.loaderHelpers,o=r.module}(r),t.ds_rt_websocket_create=e=>{T||(T=new Map);const t=null!=N?N:s.utf8ToString(e),n=W++,o=t.startsWith("ws://")||t.startsWith("wss://")?B(n,t):function(e,t){if(!R){R=!0,t.startsWith("js://gcdump")&&D({}),t.startsWith("js://counters")&&A({}),t.startsWith("js://cpu-samples")&&k({});const e=globalThis.dotnetDiagnosticClient;"function"==typeof e&&S.promise_control.resolve(e(t))}return new M(e)}(n,t);return T.set(n,o),n},t.ds_rt_websocket_send=(e,t,s)=>{const n=T.get(e);if(!n)return-1;const r=new Uint8Array(o.HEAPU8.buffer,t,s).slice();return n.send(r)},t.ds_rt_websocket_poll=e=>{const t=T.get(e);return t?t.poll():0},t.ds_rt_websocket_recv=(e,t,s)=>{const n=T.get(e);return n?n.recv(t,s):-1},t.ds_rt_websocket_close=e=>{const t=T.get(e);return t?(T.delete(e),t.close()):-1},r.api.collectCpuSamples=k,r.api.collectMetrics=A,r.api.collectGcDump=D,r.api.connectDSRouter=O,U()}function O(e){if(!E)throw new Error("No active session to reconnect");N=e;const t=B(E.client_socket,e);T.set(E.client_socket,t),t.send(function(){const e=new Uint8Array(16);globalThis.crypto.getRandomValues(e),e[7]=15&e[7]|64;const t=s.SystemJS_GetCurrentProcessId();return Uint8Array.from([...r,...e,...m([0,t]),0,0])}())}export{x as setRuntimeGlobals};
4
+ //# sourceMappingURL=dotnet.diagnostics.js.map