@selvajs/compute 4.0.0-beta.3 → 4.0.0-beta.5

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.
@@ -1,231 +0,0 @@
1
- declare const ErrorCodes: {
2
- readonly NETWORK_ERROR: "NETWORK_ERROR";
3
- readonly AUTH_ERROR: "AUTH_ERROR";
4
- readonly VALIDATION_ERROR: "VALIDATION_ERROR";
5
- readonly COMPUTATION_ERROR: "COMPUTATION_ERROR";
6
- readonly TIMEOUT_ERROR: "TIMEOUT_ERROR";
7
- readonly CORS_ERROR: "CORS_ERROR";
8
- /** HTTP 404 — the endpoint path does not exist on the server (usually a typo'd route or wrong server). Never retried. */
9
- readonly NOT_FOUND: "NOT_FOUND";
10
- /** HTTP 429 — the server is rate-limiting requests. Retried by default (honors `Retry-After`); see `RetryPolicy.retryOn429`. */
11
- readonly RATE_LIMIT: "RATE_LIMIT";
12
- /**
13
- * The server answered 2xx but the body is deterministically not JSON (the
14
- * response declared a non-JSON `Content-Type`, e.g. an HTML captive-portal or
15
- * proxy login page, or a misconfigured endpoint). Never retried — refetching
16
- * returns the same page.
17
- */
18
- readonly INVALID_RESPONSE: "INVALID_RESPONSE";
19
- readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
20
- readonly INVALID_STATE: "INVALID_STATE";
21
- readonly INVALID_INPUT: "INVALID_INPUT";
22
- readonly INVALID_CONFIG: "INVALID_CONFIG";
23
- readonly BROWSER_ONLY: "BROWSER_ONLY";
24
- readonly ENVIRONMENT_ERROR: "ENVIRONMENT_ERROR";
25
- readonly ENCODING_ERROR: "ENCODING_ERROR";
26
- /** An input's `default` had a shape the normalizer didn't recognize (no innerTree key). */
27
- readonly MALFORMED_DEFAULT: "MALFORMED_DEFAULT";
28
- /** Scheduler latest-wins: this call was replaced by a newer one. */
29
- readonly SUPERSEDED: "SUPERSEDED";
30
- /** Scheduler / caller-supplied AbortSignal: this call was aborted. */
31
- readonly ABORTED: "ABORTED";
32
- /**
33
- * Scheduler backpressure: the queue was already at `maxQueueDepth` when this
34
- * call arrived, so it was rejected immediately rather than queued. Retryable — the
35
- * caller (or an HTTP layer, as 503 + Retry-After) should back off and retry.
36
- * The error `context` carries `{ queueDepth, maxQueueDepth }`.
37
- */
38
- readonly QUEUE_FULL: "QUEUE_FULL";
39
- /**
40
- * Scheduler backpressure: this call sat queued longer than `queueWaitMs`
41
- * without starting, so it was rejected before wasting compute on a stale request.
42
- * Retryable. The error `context` carries `{ waitedMs, queueWaitMs }`.
43
- */
44
- readonly QUEUE_TIMEOUT: "QUEUE_TIMEOUT";
45
- /**
46
- * A solve referenced a definition by `pointer` (server-side cache key), but the
47
- * server no longer holds that definition (evicted / GC'd / a different child in
48
- * the pool / server restarted). The caller should retry with the full
49
- * definition. Surfaced when the server tags its error body with
50
- * `code: "definition_not_cached"`, so it survives production message-scrubbing.
51
- */
52
- readonly DEFINITION_NOT_CACHED: "DEFINITION_NOT_CACHED";
53
- };
54
- type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
55
- /**
56
- * Simplified error for Rhino Compute operations
57
- *
58
- * @public Use this for error handling with error codes and context.
59
- */
60
- declare class ComputeError extends Error {
61
- readonly code: ErrorCode;
62
- readonly statusCode?: number;
63
- readonly context?: Record<string, unknown>;
64
- readonly originalError?: Error;
65
- constructor(message: string, code?: ErrorCode, options?: {
66
- statusCode?: number;
67
- context?: Record<string, unknown>;
68
- originalError?: Error;
69
- });
70
- /**
71
- * Create an error for missing/empty values
72
- */
73
- static missingValues(inputName: string, expectedType?: string, context?: Record<string, unknown>): ComputeError;
74
- /**
75
- * Create an error for unknown parameter type
76
- */
77
- static unknownParamType(paramType: string, paramName?: string, context?: Record<string, unknown>): ComputeError;
78
- }
79
-
80
- /**
81
- * Backend wire code (the JSON error body's `code` field) → one of our
82
- * {@link ErrorCodes}. An unlisted code falls back to the status-based mapping.
83
- */
84
- type ServerErrorCodeMap = Record<string, ErrorCode>;
85
- interface RetryPolicy {
86
- /** Maximum number of retry attempts after the initial request (default: 0). */
87
- attempts?: number;
88
- /** Base delay in milliseconds for exponential backoff (default: 500). */
89
- baseDelayMs?: number;
90
- /** Upper bound for backoff delay (default: 30_000). */
91
- maxDelayMs?: number;
92
- /** Whether to retry on 429 responses (default: true — honors Retry-After). */
93
- retryOn429?: boolean;
94
- }
95
- interface ComputeConfig {
96
- serverUrl: string;
97
- /** Optional API key for authenticating with the server. Sent as {@link apiKeyHeader}. */
98
- apiKey?: string;
99
- /**
100
- * Header name carrying `apiKey`. Defaults to `'RhinoComputeKey'` — the name
101
- * rhino.compute expects. A different backend sets its own.
102
- */
103
- apiKeyHeader?: string;
104
- /** Optional Bearer token for authentication (e.g., when behind a proxy or API gateway) */
105
- authToken?: string;
106
- headers?: Record<string, string>;
107
- /** Enable debug logging to the console */
108
- debug?: boolean;
109
- /** Suppress browser security warnings in the console */
110
- suppressBrowserWarning?: boolean;
111
- timeoutMs?: number;
112
- /**
113
- * Retry policy for transient errors. Default: no retries.
114
- */
115
- retry?: RetryPolicy;
116
- /**
117
- * Optional caller-supplied AbortSignal. Composes with the internal timeout —
118
- * whichever fires first wins. Lets callers cancel in-flight requests
119
- * (e.g. on component unmount or when superseding a stale solve).
120
- */
121
- signal?: AbortSignal;
122
- /**
123
- * Machine-readable error codes this backend tags onto its error bodies, mapped
124
- * to our {@link ErrorCodes}. A code here outranks the status-based mapping.
125
- * Core knows no backend's codes — the client supplies its own table.
126
- */
127
- serverErrorCodes?: ServerErrorCodeMap;
128
- onServerTiming?: (timing: ServerTiming, requestId: string) => void;
129
- }
130
- interface ServerTiming {
131
- decode?: number;
132
- solve?: number;
133
- encode?: number;
134
- raw: string;
135
- }
136
-
137
- /**
138
- * By-reference definition form for solves.
139
- *
140
- * Lets a caller that already knows a definition's identity (e.g. a stored
141
- * version's UUID) schedule solves without materializing the multi-MB bytes:
142
- * cache keys and the server-pointer map are derived from `key` alone, and
143
- * `load()` is only called when an upload is genuinely unavoidable (first solve
144
- * of a definition, or a server-side pointer miss).
145
- */
146
- /**
147
- * A definition identified by a stable key, with bytes materialized on demand.
148
- *
149
- * **Immutability contract — read this before constructing one.** `key` must
150
- * identify IMMUTABLE bytes: every `load()` for a given `key` must return the
151
- * same content, forever. All caching (the scheduler's result cache, the
152
- * server-pointer map, and any durable cache built on these keys) trusts the
153
- * key as the definition's identity WITHOUT looking at the bytes. If two
154
- * different byte contents ever share a key, cached solves from one are served
155
- * for the other — silent cache poisoning with no diagnostic. Use an identity
156
- * that can never be reused for different content (e.g. a version UUID), never
157
- * a mutable name or path.
158
- */
159
- interface DefinitionRef {
160
- /**
161
- * Identity of immutable bytes (e.g. a version UUID). Two different byte
162
- * contents must never share a key — cache poisoning otherwise.
163
- */
164
- key: string;
165
- /**
166
- * Materialize the bytes. Called ONLY when an upload is unavoidable — inside
167
- * the solve execution, so it counts toward the solve's abort semantics.
168
- */
169
- load: () => Promise<Uint8Array>;
170
- }
171
- /**
172
- * Every definition form accepted by the solve entry points:
173
- * - a URL, base64 string, or plain string (content-hashed for caching)
174
- * - raw `.gh` bytes (content-hashed)
175
- * - a {@link DefinitionRef} (identity-keyed; bytes loaded lazily)
176
- */
177
- type SolveDefinition = string | Uint8Array | DefinitionRef;
178
- /** Narrow a {@link SolveDefinition} to the by-reference form. */
179
- declare function isDefinitionRef(definition: SolveDefinition): definition is DefinitionRef;
180
-
181
- /**
182
- * Raw file data from Grasshopper/Rhino Compute response, with metadata for processing.
183
- * Files are typically combined with additional files and packaged into a ZIP archive.
184
- * @see {@link extractFilesFromComputeResponse} for extraction from compute responses
185
- */
186
- type FileData = {
187
- /** Base filename without extension (e.g., "model") */
188
- fileName: string;
189
- /** File content, base64-encoded or plain string depending on isBase64Encoded flag */
190
- data: string;
191
- /** File extension including the dot (e.g., ".3dm", ".json"). Appended to fileName to create the full filename */
192
- fileType: string;
193
- /** Whether data is base64-encoded. If true, must be decoded to binary before use */
194
- isBase64Encoded: boolean;
195
- /** Directory path for archive organization (e.g., "subfolder/nested"). Empty string for root-level files */
196
- subFolder: string;
197
- /** Arbitrary metadata attached in Grasshopper. Not interpreted by compute; passed through for downstream consumers. May be absent on older payloads */
198
- metadata?: Record<string, string>;
199
- };
200
- /**
201
- * Normalized file ready for consumption or archival.
202
- * Unified intermediate format from FileData or FileBaseInfo, ready to be packaged into archives or returned to callers.
203
- */
204
- type ProcessedFile = {
205
- /** Full filename including extension (e.g., "model.3dm") */
206
- fileName: string;
207
- /** File content as binary data (Uint8Array for decoded base64 or fetched binary) or text */
208
- content: Uint8Array | string;
209
- /** File path for archive organization (e.g., "subfolder/model.3dm") */
210
- path: string;
211
- };
212
- /**
213
- * Reference to an external file to be fetched and included in file operations.
214
- * Specifies additional files (beyond compute response files) to fetch and process as ProcessedFile.
215
- * @see {@link fetchRemoteFiles} for how FileBaseInfo is fetched and converted
216
- */
217
- type FileBaseInfo = {
218
- /** Destination filename for the file in the archive or result set (e.g., "additional-data.json") */
219
- fileName: string;
220
- /** URL to fetch the file from. Must be accessible from the runtime environment */
221
- filePath: string;
222
- /** Optional directory path for archive organization (e.g., "extras/docs"). When omitted, file lands at archive root */
223
- subFolder?: string;
224
- };
225
-
226
- /** Extracts and processes files from compute response data without downloading them. */
227
- declare const extractFilesFromComputeResponse: (downloadableFiles: FileData[], additionalFiles?: FileBaseInfo[] | FileBaseInfo | null) => Promise<ProcessedFile[]>;
228
- /** Downloads files from a compute response as a ZIP archive. */
229
- declare const downloadFileData: (downloadableFiles: FileData[], fileFoldername: string, additionalFiles?: FileBaseInfo[] | FileBaseInfo | null) => Promise<void>;
230
-
231
- export { type ComputeConfig as C, type DefinitionRef as D, type ErrorCode as E, type FileBaseInfo as F, type ProcessedFile as P, type RetryPolicy as R, type ServerErrorCodeMap as S, ComputeError as a, ErrorCodes as b, type FileData as c, type ServerTiming as d, type SolveDefinition as e, downloadFileData as f, extractFilesFromComputeResponse as g, isDefinitionRef as i };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/home/runner/work/selva/selva/packages/compute/dist/index.cjs"],"names":[],"mappings":"AAAA","file":"/home/runner/work/selva/selva/packages/compute/dist/index.cjs"}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}