@selvajs/compute 4.0.0-beta.4 → 4.0.0-beta.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/core-CEa0SxYF.cjs +3 -0
- package/dist/core-CEa0SxYF.cjs.map +1 -0
- package/dist/core-DONB46aK.js +3 -0
- package/dist/core-DONB46aK.js.map +1 -0
- package/dist/core.cjs +1 -2
- package/dist/core.d.cts +2 -219
- package/dist/core.d.ts +2 -219
- package/dist/core.js +1 -2
- package/dist/grasshopper.cjs +1 -1
- package/dist/grasshopper.cjs.map +1 -1
- package/dist/grasshopper.d.cts +1214 -1220
- package/dist/grasshopper.d.ts +1214 -1220
- package/dist/grasshopper.js +1 -1
- package/dist/grasshopper.js.map +1 -1
- package/dist/index-BNsid0_9.d.cts +458 -0
- package/dist/index-BNsid0_9.d.ts +458 -0
- package/dist/index.cjs +0 -1
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -1
- package/package.json +13 -11
- package/dist/chunk-AYH5O3VG.js +0 -4
- package/dist/chunk-AYH5O3VG.js.map +0 -1
- package/dist/chunk-MLPWPV6F.cjs +0 -4
- package/dist/chunk-MLPWPV6F.cjs.map +0 -1
- package/dist/core.cjs.map +0 -1
- package/dist/core.js.map +0 -1
- package/dist/handle-files-DMK9bCOW.d.cts +0 -231
- package/dist/handle-files-DMK9bCOW.d.ts +0 -231
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/core.d.cts
CHANGED
|
@@ -1,219 +1,2 @@
|
|
|
1
|
-
import { C as ComputeConfig } from
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Generic Rhino Compute fetch function.
|
|
6
|
-
* Sends a POST request to any Compute endpoint with pre-prepared arguments.
|
|
7
|
-
*
|
|
8
|
-
* Use this for advanced, low-level control over compute requests. For most use cases, prefer higher-level APIs.
|
|
9
|
-
*
|
|
10
|
-
* The transport is response-type-agnostic: it does not know which response a
|
|
11
|
-
* given endpoint returns. Callers supply the response type via `R` (defaulting
|
|
12
|
-
* to `unknown`, which forces an explicit narrowing before use).
|
|
13
|
-
*
|
|
14
|
-
* Timeout semantics: `config.timeoutMs` is a PER-ATTEMPT timeout, re-armed for
|
|
15
|
-
* every retry. With `retry: { attempts: N }` the worst-case wall clock is
|
|
16
|
-
* `(N + 1) × timeoutMs` plus backoff sleeps (and a server `Retry-After` can
|
|
17
|
-
* stretch a single sleep up to 60s). For a hard overall deadline, pass
|
|
18
|
-
* `config.signal` (e.g. `AbortSignal.timeout(totalMs)`) — a caller abort wins
|
|
19
|
-
* immediately, including during backoff.
|
|
20
|
-
*
|
|
21
|
-
* Retry caveats: requests are POSTs, so a retry after a mid-flight connection
|
|
22
|
-
* loss may re-execute a request the server already ran (see {@link RetryPolicy}).
|
|
23
|
-
* A 2xx response that declares a non-JSON `Content-Type` (captive portal,
|
|
24
|
-
* proxy login page) fails immediately with `INVALID_RESPONSE` and is never
|
|
25
|
-
* retried; a body that fails to parse under a JSON content-type is treated as
|
|
26
|
-
* a truncated stream and is retried.
|
|
27
|
-
*
|
|
28
|
-
* @typeParam R - The expected response shape. The caller names it at the call site.
|
|
29
|
-
* @param endpoint - The Compute API endpoint (e.g., 'grasshopper', 'io', 'mesh').
|
|
30
|
-
* @param args - Pre-prepared arguments for the request body.
|
|
31
|
-
* @param config - Compute configuration (server URL, API key, timeout, debug, retry, signal).
|
|
32
|
-
* @returns The parsed JSON response from the server, typed as `R`.
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* // Basic usage for the Grasshopper endpoint:
|
|
36
|
-
* const response = await fetchCompute(
|
|
37
|
-
* 'grasshopper',
|
|
38
|
-
* { ... },
|
|
39
|
-
* {
|
|
40
|
-
* serverUrl: 'https://my-server.com',
|
|
41
|
-
* debug: true,
|
|
42
|
-
* timeoutMs: 30_000,
|
|
43
|
-
* retry: { attempts: 2 },
|
|
44
|
-
* signal: controller.signal,
|
|
45
|
-
* }
|
|
46
|
-
* );
|
|
47
|
-
*/
|
|
48
|
-
declare function fetchCompute<R = unknown>(endpoint: string, args: Record<string, any>, config: ComputeConfig): Promise<R>;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Side-channel carrying a response's wire size (its JSON text length) alongside
|
|
52
|
-
* the parsed object, so downstream caches can budget by bytes without
|
|
53
|
-
* re-serializing (audit C2/C3 — the response tree can be hundreds of MB, and
|
|
54
|
-
* every extra `JSON.stringify` pass over it is a real cost).
|
|
55
|
-
*
|
|
56
|
-
* A `WeakMap` rather than a property on the response: the response type is the
|
|
57
|
-
* server's schema, and an extra enumerable field would leak into every
|
|
58
|
-
* `JSON.stringify(response)` on the way back out to clients. Derived copies
|
|
59
|
-
* (e.g. the `algo`-stripped shallow copy in `runSolve`) must re-register — the
|
|
60
|
-
* hint follows object identity, not content.
|
|
61
|
-
*
|
|
62
|
-
* The size is `text.length` (UTF-16 code units), not strict UTF-8 bytes —
|
|
63
|
-
* compute responses are ASCII-dominated JSON (base64 + numerals), so the two
|
|
64
|
-
* are interchangeable for budgeting purposes and `.length` is free.
|
|
65
|
-
*/
|
|
66
|
-
/** Record `response`'s wire size. No-op for non-object/null values. */
|
|
67
|
-
declare function setResponseWireSize(response: unknown, size: number): void;
|
|
68
|
-
/** The wire size recorded for `response`, or undefined when never registered. */
|
|
69
|
-
declare function getResponseWireSize(response: unknown): number | undefined;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Logger interface for structured logging
|
|
73
|
-
*
|
|
74
|
-
* @public Implement this interface to provide custom logging behavior.
|
|
75
|
-
*/
|
|
76
|
-
interface Logger {
|
|
77
|
-
debug(message: string, ...args: unknown[]): void;
|
|
78
|
-
info(message: string, ...args: unknown[]): void;
|
|
79
|
-
warn(message: string, ...args: unknown[]): void;
|
|
80
|
-
error(message: string, ...args: unknown[]): void;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Get the current logger instance
|
|
84
|
-
*
|
|
85
|
-
* @returns The current logger instance
|
|
86
|
-
*/
|
|
87
|
-
declare function getLogger(): Logger;
|
|
88
|
-
/**
|
|
89
|
-
* Set a custom logger instance
|
|
90
|
-
*
|
|
91
|
-
* @public Use this to configure custom logging behavior.
|
|
92
|
-
*
|
|
93
|
-
* @param logger - Custom logger implementation or null to disable logging
|
|
94
|
-
* @throws {ComputeError} `INVALID_CONFIG` if the logger is missing any of
|
|
95
|
-
* the four required methods — failing here beats a confusing
|
|
96
|
-
* "getLogger().debug is not a function" at some later, unrelated call site.
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```typescript
|
|
100
|
-
* import { setLogger } from '@selvajs/compute/core';
|
|
101
|
-
*
|
|
102
|
-
* // Enable console logging
|
|
103
|
-
* setLogger(console);
|
|
104
|
-
*
|
|
105
|
-
* // Use a custom logger
|
|
106
|
-
* setLogger({
|
|
107
|
-
* debug: (msg, ...args) => myLogger.debug(msg, ...args),
|
|
108
|
-
* info: (msg, ...args) => myLogger.info(msg, ...args),
|
|
109
|
-
* warn: (msg, ...args) => myLogger.warn(msg, ...args),
|
|
110
|
-
* error: (msg, ...args) => myLogger.error(msg, ...args)
|
|
111
|
-
* });
|
|
112
|
-
*
|
|
113
|
-
* // Disable logging
|
|
114
|
-
* setLogger(null);
|
|
115
|
-
* ```
|
|
116
|
-
*/
|
|
117
|
-
declare function setLogger(logger: Logger | Console | null): void;
|
|
118
|
-
/**
|
|
119
|
-
* Enable debug logging to console
|
|
120
|
-
*
|
|
121
|
-
* @public Convenience method to enable console logging.
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* ```typescript
|
|
125
|
-
* import { enableDebugLogging } from '@selvajs/compute/core';
|
|
126
|
-
*
|
|
127
|
-
* enableDebugLogging();
|
|
128
|
-
* ```
|
|
129
|
-
*/
|
|
130
|
-
declare function enableDebugLogging(): void;
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Case-insensitive single-key reader for wire payloads.
|
|
134
|
-
*
|
|
135
|
-
* The Rhino Compute family serializes the same logical field with different
|
|
136
|
-
* casing depending on the server branch:
|
|
137
|
-
*
|
|
138
|
-
* - mcneel 8.x / 9.x: the IO schema is PascalCase (`ParamType`, `Default`,
|
|
139
|
-
* `InnerTree`, …) because those C# classes carry no `[JsonProperty]`.
|
|
140
|
-
* - VektorNode Compute8: the IO schema is camelCase (`paramType`, `default`,
|
|
141
|
-
* …) because the fork added `[JsonProperty("camelCase")]`, BUT the nested
|
|
142
|
-
* `default` DataTree wrapper stays PascalCase (`ParamName` / `InnerTree`)
|
|
143
|
-
* since `Resthopper.IO.DataTree` is an external type the fork can't attribute.
|
|
144
|
-
*
|
|
145
|
-
* So a single response can mix casings, and which casing a given field uses
|
|
146
|
-
* depends on the server branch. Rather than deep-camelCasing the whole payload
|
|
147
|
-
* (the old `camelcaseKeys` approach — which corrupted user-authored value-list
|
|
148
|
-
* label keys and item `data` JSON), read the specific fields we care about
|
|
149
|
-
* case-insensitively and leave everything else verbatim.
|
|
150
|
-
*
|
|
151
|
-
* Prefers an exact-case match when present, then falls back to the first
|
|
152
|
-
* case-insensitive match. Returns `undefined` when no key matches.
|
|
153
|
-
*
|
|
154
|
-
* @param obj - The source object (any non-object input yields `undefined`).
|
|
155
|
-
* @param name - The logical field name, in any casing.
|
|
156
|
-
*/
|
|
157
|
-
declare function readField<T = unknown>(obj: unknown, name: string): T | undefined;
|
|
158
|
-
/**
|
|
159
|
-
* True when `obj` has a key matching `name` (case-insensitively). Distinguishes
|
|
160
|
-
* "field present but value is null/undefined" from "field absent" — needed where
|
|
161
|
-
* presence itself carries meaning (e.g. an `innerTree` that exists but is empty).
|
|
162
|
-
*/
|
|
163
|
-
declare function hasField(obj: unknown, name: string): boolean;
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Decodes a base64 string to binary data (Uint8Array).
|
|
167
|
-
* Normalizes and validates input per WHATWG forgiving-base64 so both runtimes fail consistently.
|
|
168
|
-
*
|
|
169
|
-
* @param base64File - Base64 encoded string
|
|
170
|
-
* @returns Decoded binary data as Uint8Array
|
|
171
|
-
* @throws {ComputeError} `ENCODING_ERROR` if invalid, or `INVALID_STATE` if decoder unavailable
|
|
172
|
-
*/
|
|
173
|
-
declare function decodeBase64ToBinary(base64File: string): Uint8Array;
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* The public McNeel endpoint's host — the default blocked host; users must point at
|
|
177
|
-
* their own server. Compared against the parsed hostname lowercased and with any
|
|
178
|
-
* trailing dot stripped, so the FQDN form (`compute.rhino3d.com.`) can't bypass it.
|
|
179
|
-
* Known limitation: the endpoint's raw IP is not blocked — it sits behind a load
|
|
180
|
-
* balancer with no single stable, verifiable address to pin.
|
|
181
|
-
*/
|
|
182
|
-
declare const DEFAULT_BLOCKED_HOST = "compute.rhino3d.com";
|
|
183
|
-
interface ValidateServerUrlOptions {
|
|
184
|
-
/**
|
|
185
|
-
* Hostnames rejected as a `serverUrl` — a backend's shared public endpoint,
|
|
186
|
-
* which callers must not point at. Defaults to `[DEFAULT_BLOCKED_HOST]`; pass
|
|
187
|
-
* `[]` to block nothing. Compared lowercased with any trailing dot stripped.
|
|
188
|
-
*/
|
|
189
|
-
blockedHosts?: readonly string[];
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Validate and normalize a compute `serverUrl`.
|
|
193
|
-
*
|
|
194
|
-
* This is the single source of truth for "is this a usable server URL?" — both
|
|
195
|
-
* `GrasshopperClient` (via `normalizeComputeConfig`) and the standalone-exported
|
|
196
|
-
* `ComputeServerStats` constructor delegate here, so a given URL is accepted or
|
|
197
|
-
* rejected identically no matter which entry point a caller uses.
|
|
198
|
-
*
|
|
199
|
-
* Rules (all enforced, on the *trimmed* input — the trimmed form is what's
|
|
200
|
-
* returned, so no stray whitespace survives into later `fetch` calls):
|
|
201
|
-
* - non-empty (after trim)
|
|
202
|
-
* - `http://` or `https://` scheme (case-insensitive, per RFC 3986)
|
|
203
|
-
* - parseable by `new URL()`
|
|
204
|
-
* - no embedded credentials (`http://user:pass@host`) — `fetch`/`new Request`
|
|
205
|
-
* reject credentialed URLs at runtime, so they must fail here instead
|
|
206
|
-
* - no query string or fragment — endpoint paths are appended to this URL
|
|
207
|
-
* (`${serverUrl}/version`), which a `?…` or `#…` suffix would corrupt
|
|
208
|
-
* - not a blocked host (by default the public McNeel endpoint) — compared by
|
|
209
|
-
* parsed hostname (lowercased, trailing dot stripped), so scheme, casing, port,
|
|
210
|
-
* path, trailing-slash, or FQDN-dot variants can't slip past the block
|
|
211
|
-
*
|
|
212
|
-
* @param raw - The candidate server URL.
|
|
213
|
-
* @param options - Override the blocked-host list for a non-Rhino backend.
|
|
214
|
-
* @returns The trimmed, normalized URL with any trailing slashes removed.
|
|
215
|
-
* @throws {ComputeError} `INVALID_CONFIG` if any rule fails.
|
|
216
|
-
*/
|
|
217
|
-
declare function validateServerUrl(raw: string, options?: ValidateServerUrlOptions): string;
|
|
218
|
-
|
|
219
|
-
export { ComputeConfig, DEFAULT_BLOCKED_HOST, type Logger, type ValidateServerUrlOptions, decodeBase64ToBinary, enableDebugLogging, fetchCompute, getLogger, getResponseWireSize, hasField, readField, setLogger, setResponseWireSize, validateServerUrl };
|
|
1
|
+
import { C as RetryPolicy, D as ErrorCode, E as ComputeError, O as ErrorCodes, S as ComputeConfig, T as ServerTiming, _ as getLogger, a as ProcessedFile, b as setResponseWireSize, c as validateServerUrl, d as isDefinitionRef, f as decodeBase64ToBinary, g as enableDebugLogging, h as Logger, i as FileData, l as DefinitionRef, m as readField, n as extractFilesFromComputeResponse, o as DEFAULT_BLOCKED_HOST, p as hasField, r as FileBaseInfo, s as ValidateServerUrlOptions, t as downloadFileData, u as SolveDefinition, v as setLogger, w as ServerErrorCodeMap, x as fetchCompute, y as getResponseWireSize } from "./index-BNsid0_9.cjs";
|
|
2
|
+
export { type ComputeConfig, ComputeError, DEFAULT_BLOCKED_HOST, type DefinitionRef, type ErrorCode, ErrorCodes, type FileBaseInfo, type FileData, type Logger, type ProcessedFile, type RetryPolicy, type ServerErrorCodeMap, type ServerTiming, type SolveDefinition, type ValidateServerUrlOptions, decodeBase64ToBinary, downloadFileData, enableDebugLogging, extractFilesFromComputeResponse, fetchCompute, getLogger, getResponseWireSize, hasField, isDefinitionRef, readField, setLogger, setResponseWireSize, validateServerUrl };
|
package/dist/core.d.ts
CHANGED
|
@@ -1,219 +1,2 @@
|
|
|
1
|
-
import { C as ComputeConfig } from
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Generic Rhino Compute fetch function.
|
|
6
|
-
* Sends a POST request to any Compute endpoint with pre-prepared arguments.
|
|
7
|
-
*
|
|
8
|
-
* Use this for advanced, low-level control over compute requests. For most use cases, prefer higher-level APIs.
|
|
9
|
-
*
|
|
10
|
-
* The transport is response-type-agnostic: it does not know which response a
|
|
11
|
-
* given endpoint returns. Callers supply the response type via `R` (defaulting
|
|
12
|
-
* to `unknown`, which forces an explicit narrowing before use).
|
|
13
|
-
*
|
|
14
|
-
* Timeout semantics: `config.timeoutMs` is a PER-ATTEMPT timeout, re-armed for
|
|
15
|
-
* every retry. With `retry: { attempts: N }` the worst-case wall clock is
|
|
16
|
-
* `(N + 1) × timeoutMs` plus backoff sleeps (and a server `Retry-After` can
|
|
17
|
-
* stretch a single sleep up to 60s). For a hard overall deadline, pass
|
|
18
|
-
* `config.signal` (e.g. `AbortSignal.timeout(totalMs)`) — a caller abort wins
|
|
19
|
-
* immediately, including during backoff.
|
|
20
|
-
*
|
|
21
|
-
* Retry caveats: requests are POSTs, so a retry after a mid-flight connection
|
|
22
|
-
* loss may re-execute a request the server already ran (see {@link RetryPolicy}).
|
|
23
|
-
* A 2xx response that declares a non-JSON `Content-Type` (captive portal,
|
|
24
|
-
* proxy login page) fails immediately with `INVALID_RESPONSE` and is never
|
|
25
|
-
* retried; a body that fails to parse under a JSON content-type is treated as
|
|
26
|
-
* a truncated stream and is retried.
|
|
27
|
-
*
|
|
28
|
-
* @typeParam R - The expected response shape. The caller names it at the call site.
|
|
29
|
-
* @param endpoint - The Compute API endpoint (e.g., 'grasshopper', 'io', 'mesh').
|
|
30
|
-
* @param args - Pre-prepared arguments for the request body.
|
|
31
|
-
* @param config - Compute configuration (server URL, API key, timeout, debug, retry, signal).
|
|
32
|
-
* @returns The parsed JSON response from the server, typed as `R`.
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* // Basic usage for the Grasshopper endpoint:
|
|
36
|
-
* const response = await fetchCompute(
|
|
37
|
-
* 'grasshopper',
|
|
38
|
-
* { ... },
|
|
39
|
-
* {
|
|
40
|
-
* serverUrl: 'https://my-server.com',
|
|
41
|
-
* debug: true,
|
|
42
|
-
* timeoutMs: 30_000,
|
|
43
|
-
* retry: { attempts: 2 },
|
|
44
|
-
* signal: controller.signal,
|
|
45
|
-
* }
|
|
46
|
-
* );
|
|
47
|
-
*/
|
|
48
|
-
declare function fetchCompute<R = unknown>(endpoint: string, args: Record<string, any>, config: ComputeConfig): Promise<R>;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Side-channel carrying a response's wire size (its JSON text length) alongside
|
|
52
|
-
* the parsed object, so downstream caches can budget by bytes without
|
|
53
|
-
* re-serializing (audit C2/C3 — the response tree can be hundreds of MB, and
|
|
54
|
-
* every extra `JSON.stringify` pass over it is a real cost).
|
|
55
|
-
*
|
|
56
|
-
* A `WeakMap` rather than a property on the response: the response type is the
|
|
57
|
-
* server's schema, and an extra enumerable field would leak into every
|
|
58
|
-
* `JSON.stringify(response)` on the way back out to clients. Derived copies
|
|
59
|
-
* (e.g. the `algo`-stripped shallow copy in `runSolve`) must re-register — the
|
|
60
|
-
* hint follows object identity, not content.
|
|
61
|
-
*
|
|
62
|
-
* The size is `text.length` (UTF-16 code units), not strict UTF-8 bytes —
|
|
63
|
-
* compute responses are ASCII-dominated JSON (base64 + numerals), so the two
|
|
64
|
-
* are interchangeable for budgeting purposes and `.length` is free.
|
|
65
|
-
*/
|
|
66
|
-
/** Record `response`'s wire size. No-op for non-object/null values. */
|
|
67
|
-
declare function setResponseWireSize(response: unknown, size: number): void;
|
|
68
|
-
/** The wire size recorded for `response`, or undefined when never registered. */
|
|
69
|
-
declare function getResponseWireSize(response: unknown): number | undefined;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Logger interface for structured logging
|
|
73
|
-
*
|
|
74
|
-
* @public Implement this interface to provide custom logging behavior.
|
|
75
|
-
*/
|
|
76
|
-
interface Logger {
|
|
77
|
-
debug(message: string, ...args: unknown[]): void;
|
|
78
|
-
info(message: string, ...args: unknown[]): void;
|
|
79
|
-
warn(message: string, ...args: unknown[]): void;
|
|
80
|
-
error(message: string, ...args: unknown[]): void;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Get the current logger instance
|
|
84
|
-
*
|
|
85
|
-
* @returns The current logger instance
|
|
86
|
-
*/
|
|
87
|
-
declare function getLogger(): Logger;
|
|
88
|
-
/**
|
|
89
|
-
* Set a custom logger instance
|
|
90
|
-
*
|
|
91
|
-
* @public Use this to configure custom logging behavior.
|
|
92
|
-
*
|
|
93
|
-
* @param logger - Custom logger implementation or null to disable logging
|
|
94
|
-
* @throws {ComputeError} `INVALID_CONFIG` if the logger is missing any of
|
|
95
|
-
* the four required methods — failing here beats a confusing
|
|
96
|
-
* "getLogger().debug is not a function" at some later, unrelated call site.
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```typescript
|
|
100
|
-
* import { setLogger } from '@selvajs/compute/core';
|
|
101
|
-
*
|
|
102
|
-
* // Enable console logging
|
|
103
|
-
* setLogger(console);
|
|
104
|
-
*
|
|
105
|
-
* // Use a custom logger
|
|
106
|
-
* setLogger({
|
|
107
|
-
* debug: (msg, ...args) => myLogger.debug(msg, ...args),
|
|
108
|
-
* info: (msg, ...args) => myLogger.info(msg, ...args),
|
|
109
|
-
* warn: (msg, ...args) => myLogger.warn(msg, ...args),
|
|
110
|
-
* error: (msg, ...args) => myLogger.error(msg, ...args)
|
|
111
|
-
* });
|
|
112
|
-
*
|
|
113
|
-
* // Disable logging
|
|
114
|
-
* setLogger(null);
|
|
115
|
-
* ```
|
|
116
|
-
*/
|
|
117
|
-
declare function setLogger(logger: Logger | Console | null): void;
|
|
118
|
-
/**
|
|
119
|
-
* Enable debug logging to console
|
|
120
|
-
*
|
|
121
|
-
* @public Convenience method to enable console logging.
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* ```typescript
|
|
125
|
-
* import { enableDebugLogging } from '@selvajs/compute/core';
|
|
126
|
-
*
|
|
127
|
-
* enableDebugLogging();
|
|
128
|
-
* ```
|
|
129
|
-
*/
|
|
130
|
-
declare function enableDebugLogging(): void;
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Case-insensitive single-key reader for wire payloads.
|
|
134
|
-
*
|
|
135
|
-
* The Rhino Compute family serializes the same logical field with different
|
|
136
|
-
* casing depending on the server branch:
|
|
137
|
-
*
|
|
138
|
-
* - mcneel 8.x / 9.x: the IO schema is PascalCase (`ParamType`, `Default`,
|
|
139
|
-
* `InnerTree`, …) because those C# classes carry no `[JsonProperty]`.
|
|
140
|
-
* - VektorNode Compute8: the IO schema is camelCase (`paramType`, `default`,
|
|
141
|
-
* …) because the fork added `[JsonProperty("camelCase")]`, BUT the nested
|
|
142
|
-
* `default` DataTree wrapper stays PascalCase (`ParamName` / `InnerTree`)
|
|
143
|
-
* since `Resthopper.IO.DataTree` is an external type the fork can't attribute.
|
|
144
|
-
*
|
|
145
|
-
* So a single response can mix casings, and which casing a given field uses
|
|
146
|
-
* depends on the server branch. Rather than deep-camelCasing the whole payload
|
|
147
|
-
* (the old `camelcaseKeys` approach — which corrupted user-authored value-list
|
|
148
|
-
* label keys and item `data` JSON), read the specific fields we care about
|
|
149
|
-
* case-insensitively and leave everything else verbatim.
|
|
150
|
-
*
|
|
151
|
-
* Prefers an exact-case match when present, then falls back to the first
|
|
152
|
-
* case-insensitive match. Returns `undefined` when no key matches.
|
|
153
|
-
*
|
|
154
|
-
* @param obj - The source object (any non-object input yields `undefined`).
|
|
155
|
-
* @param name - The logical field name, in any casing.
|
|
156
|
-
*/
|
|
157
|
-
declare function readField<T = unknown>(obj: unknown, name: string): T | undefined;
|
|
158
|
-
/**
|
|
159
|
-
* True when `obj` has a key matching `name` (case-insensitively). Distinguishes
|
|
160
|
-
* "field present but value is null/undefined" from "field absent" — needed where
|
|
161
|
-
* presence itself carries meaning (e.g. an `innerTree` that exists but is empty).
|
|
162
|
-
*/
|
|
163
|
-
declare function hasField(obj: unknown, name: string): boolean;
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Decodes a base64 string to binary data (Uint8Array).
|
|
167
|
-
* Normalizes and validates input per WHATWG forgiving-base64 so both runtimes fail consistently.
|
|
168
|
-
*
|
|
169
|
-
* @param base64File - Base64 encoded string
|
|
170
|
-
* @returns Decoded binary data as Uint8Array
|
|
171
|
-
* @throws {ComputeError} `ENCODING_ERROR` if invalid, or `INVALID_STATE` if decoder unavailable
|
|
172
|
-
*/
|
|
173
|
-
declare function decodeBase64ToBinary(base64File: string): Uint8Array;
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* The public McNeel endpoint's host — the default blocked host; users must point at
|
|
177
|
-
* their own server. Compared against the parsed hostname lowercased and with any
|
|
178
|
-
* trailing dot stripped, so the FQDN form (`compute.rhino3d.com.`) can't bypass it.
|
|
179
|
-
* Known limitation: the endpoint's raw IP is not blocked — it sits behind a load
|
|
180
|
-
* balancer with no single stable, verifiable address to pin.
|
|
181
|
-
*/
|
|
182
|
-
declare const DEFAULT_BLOCKED_HOST = "compute.rhino3d.com";
|
|
183
|
-
interface ValidateServerUrlOptions {
|
|
184
|
-
/**
|
|
185
|
-
* Hostnames rejected as a `serverUrl` — a backend's shared public endpoint,
|
|
186
|
-
* which callers must not point at. Defaults to `[DEFAULT_BLOCKED_HOST]`; pass
|
|
187
|
-
* `[]` to block nothing. Compared lowercased with any trailing dot stripped.
|
|
188
|
-
*/
|
|
189
|
-
blockedHosts?: readonly string[];
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Validate and normalize a compute `serverUrl`.
|
|
193
|
-
*
|
|
194
|
-
* This is the single source of truth for "is this a usable server URL?" — both
|
|
195
|
-
* `GrasshopperClient` (via `normalizeComputeConfig`) and the standalone-exported
|
|
196
|
-
* `ComputeServerStats` constructor delegate here, so a given URL is accepted or
|
|
197
|
-
* rejected identically no matter which entry point a caller uses.
|
|
198
|
-
*
|
|
199
|
-
* Rules (all enforced, on the *trimmed* input — the trimmed form is what's
|
|
200
|
-
* returned, so no stray whitespace survives into later `fetch` calls):
|
|
201
|
-
* - non-empty (after trim)
|
|
202
|
-
* - `http://` or `https://` scheme (case-insensitive, per RFC 3986)
|
|
203
|
-
* - parseable by `new URL()`
|
|
204
|
-
* - no embedded credentials (`http://user:pass@host`) — `fetch`/`new Request`
|
|
205
|
-
* reject credentialed URLs at runtime, so they must fail here instead
|
|
206
|
-
* - no query string or fragment — endpoint paths are appended to this URL
|
|
207
|
-
* (`${serverUrl}/version`), which a `?…` or `#…` suffix would corrupt
|
|
208
|
-
* - not a blocked host (by default the public McNeel endpoint) — compared by
|
|
209
|
-
* parsed hostname (lowercased, trailing dot stripped), so scheme, casing, port,
|
|
210
|
-
* path, trailing-slash, or FQDN-dot variants can't slip past the block
|
|
211
|
-
*
|
|
212
|
-
* @param raw - The candidate server URL.
|
|
213
|
-
* @param options - Override the blocked-host list for a non-Rhino backend.
|
|
214
|
-
* @returns The trimmed, normalized URL with any trailing slashes removed.
|
|
215
|
-
* @throws {ComputeError} `INVALID_CONFIG` if any rule fails.
|
|
216
|
-
*/
|
|
217
|
-
declare function validateServerUrl(raw: string, options?: ValidateServerUrlOptions): string;
|
|
218
|
-
|
|
219
|
-
export { ComputeConfig, DEFAULT_BLOCKED_HOST, type Logger, type ValidateServerUrlOptions, decodeBase64ToBinary, enableDebugLogging, fetchCompute, getLogger, getResponseWireSize, hasField, readField, setLogger, setResponseWireSize, validateServerUrl };
|
|
1
|
+
import { C as RetryPolicy, D as ErrorCode, E as ComputeError, O as ErrorCodes, S as ComputeConfig, T as ServerTiming, _ as getLogger, a as ProcessedFile, b as setResponseWireSize, c as validateServerUrl, d as isDefinitionRef, f as decodeBase64ToBinary, g as enableDebugLogging, h as Logger, i as FileData, l as DefinitionRef, m as readField, n as extractFilesFromComputeResponse, o as DEFAULT_BLOCKED_HOST, p as hasField, r as FileBaseInfo, s as ValidateServerUrlOptions, t as downloadFileData, u as SolveDefinition, v as setLogger, w as ServerErrorCodeMap, x as fetchCompute, y as getResponseWireSize } from "./index-BNsid0_9.js";
|
|
2
|
+
export { type ComputeConfig, ComputeError, DEFAULT_BLOCKED_HOST, type DefinitionRef, type ErrorCode, ErrorCodes, type FileBaseInfo, type FileData, type Logger, type ProcessedFile, type RetryPolicy, type ServerErrorCodeMap, type ServerTiming, type SolveDefinition, type ValidateServerUrlOptions, decodeBase64ToBinary, downloadFileData, enableDebugLogging, extractFilesFromComputeResponse, fetchCompute, getLogger, getResponseWireSize, hasField, isDefinitionRef, readField, setLogger, setResponseWireSize, validateServerUrl };
|
package/dist/core.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import{
|
|
2
|
-
//# sourceMappingURL=core.js.map
|
|
1
|
+
import{_ as e,a as t,c as n,d as r,f as i,g as a,h as o,i as s,m as c,n as l,o as u,p as d,r as f,t as p,v as m,y as h}from"./core-DONB46aK.js";export{m as ComputeError,r as DEFAULT_BLOCKED_HOST,h as ErrorCodes,n as decodeBase64ToBinary,p as downloadFileData,o as enableDebugLogging,l as extractFilesFromComputeResponse,s as fetchCompute,a as getLogger,t as getResponseWireSize,d as hasField,f as isDefinitionRef,c as readField,e as setLogger,u as setResponseWireSize,i as validateServerUrl};
|