@hypen-space/core 0.4.980 → 0.5.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.
- package/README.md +5 -8
- package/dist/app.js +13 -1168
- package/dist/app.js.map +3 -9
- package/dist/chunk-00zt3w6e.js +58 -0
- package/dist/chunk-00zt3w6e.js.map +10 -0
- package/dist/chunk-3zvyth50.js +87 -0
- package/dist/chunk-3zvyth50.js.map +10 -0
- package/dist/chunk-5gtx3pza.js +11 -0
- package/dist/chunk-5gtx3pza.js.map +9 -0
- package/dist/chunk-7222131a.js +191 -0
- package/dist/chunk-7222131a.js.map +10 -0
- package/dist/chunk-avchpwhf.js +200 -0
- package/dist/chunk-avchpwhf.js.map +10 -0
- package/dist/chunk-ec0tgy9a.js +154 -0
- package/dist/chunk-ec0tgy9a.js.map +10 -0
- package/dist/chunk-fnss4dm2.js +479 -0
- package/dist/chunk-fnss4dm2.js.map +10 -0
- package/dist/chunk-g2gz9pgg.js +133 -0
- package/dist/chunk-g2gz9pgg.js.map +10 -0
- package/dist/chunk-g72v6mmf.js +341 -0
- package/dist/chunk-g72v6mmf.js.map +10 -0
- package/dist/chunk-g7g3jxty.js +351 -0
- package/dist/chunk-g7g3jxty.js.map +10 -0
- package/dist/chunk-g830re2c.js +50 -0
- package/dist/chunk-g830re2c.js.map +10 -0
- package/dist/chunk-gtwh1sg7.js +127 -0
- package/dist/chunk-gtwh1sg7.js.map +10 -0
- package/dist/chunk-k12cwfst.js +72 -0
- package/dist/chunk-k12cwfst.js.map +10 -0
- package/dist/chunk-mbqqsz6r.js +128 -0
- package/dist/chunk-mbqqsz6r.js.map +10 -0
- package/dist/chunk-ne632swm.js +209 -0
- package/dist/chunk-ne632swm.js.map +10 -0
- package/dist/chunk-p3pj1bax.js +206 -0
- package/dist/chunk-p3pj1bax.js.map +10 -0
- package/dist/chunk-vshdk2pw.js +56 -0
- package/dist/chunk-vshdk2pw.js.map +10 -0
- package/dist/chunk-wp2ebn2m.js +51 -0
- package/dist/chunk-wp2ebn2m.js.map +10 -0
- package/dist/chunk-x4qv4jm9.js +88 -0
- package/dist/chunk-x4qv4jm9.js.map +10 -0
- package/dist/chunk-ycxp4drd.js +211 -0
- package/dist/chunk-ycxp4drd.js.map +10 -0
- package/dist/components/builtin.js +14 -1246
- package/dist/components/builtin.js.map +3 -10
- package/dist/context.js +7 -362
- package/dist/context.js.map +3 -6
- package/dist/datasource.js +5 -76
- package/dist/datasource.js.map +3 -4
- package/dist/disposable.js +20 -367
- package/dist/disposable.js.map +3 -5
- package/dist/engine-base.d.ts +38 -2
- package/dist/engine-base.js +45 -412
- package/dist/engine-base.js.map +4 -6
- package/dist/events.js +7 -285
- package/dist/events.js.map +3 -5
- package/dist/hypen.js +8 -71
- package/dist/hypen.js.map +3 -4
- package/dist/index.browser.js +58 -2152
- package/dist/index.browser.js.map +3 -16
- package/dist/index.d.ts +2 -0
- package/dist/index.js +132 -3058
- package/dist/index.js.map +4 -22
- package/dist/logger.js +16 -220
- package/dist/logger.js.map +3 -4
- package/dist/managed-router.js +12 -1367
- package/dist/managed-router.js.map +3 -10
- package/dist/portable.js +6 -70
- package/dist/portable.js.map +3 -4
- package/dist/remote/client.js +9 -1010
- package/dist/remote/client.js.map +3 -8
- package/dist/remote/index.d.ts +2 -0
- package/dist/remote/index.js +511 -1066
- package/dist/remote/index.js.map +4 -9
- package/dist/remote/remote-session.d.ts +245 -0
- package/dist/remote/session.js +5 -147
- package/dist/remote/session.js.map +3 -4
- package/dist/renderer.js +7 -271
- package/dist/renderer.js.map +3 -5
- package/dist/resolver.js +5 -484
- package/dist/resolver.js.map +3 -5
- package/dist/result.js +25 -211
- package/dist/result.js.map +3 -4
- package/dist/retry.js +10 -336
- package/dist/retry.js.map +3 -5
- package/dist/router.js +9 -807
- package/dist/router.js.map +3 -8
- package/dist/state.js +10 -274
- package/dist/state.js.map +3 -5
- package/dist/validate.d.ts +19 -0
- package/package.json +13 -1
- package/src/engine-base.ts +87 -4
- package/src/index.ts +5 -0
- package/src/remote/index.ts +16 -0
- package/src/remote/remote-session.ts +998 -0
- package/src/validate.ts +37 -0
package/dist/retry.js.map
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": [
|
|
3
|
+
"sources": [],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * Result Type for Error Handling\n *\n * A lightweight Result type for explicit error handling without exceptions.\n * Provides type-safe error propagation and composition.\n */\n\n/**\n * Represents either a successful value or an error\n */\nexport type Result<T, E = Error> =\n | { readonly ok: true; readonly value: T }\n | { readonly ok: false; readonly error: E };\n\n/**\n * Create a successful Result\n */\nexport function Ok<T>(value: T): Result<T, never> {\n return { ok: true, value };\n}\n\n/**\n * Create a failed Result\n */\nexport function Err<E>(error: E): Result<never, E> {\n return { ok: false, error };\n}\n\n/**\n * Check if a Result is Ok\n */\nexport function isOk<T, E>(result: Result<T, E>): result is { ok: true; value: T } {\n return result.ok;\n}\n\n/**\n * Check if a Result is Err\n */\nexport function isErr<T, E>(result: Result<T, E>): result is { ok: false; error: E } {\n return !result.ok;\n}\n\n/**\n * Wrap a Promise in a Result, catching any thrown errors\n */\nexport async function fromPromise<T, E = Error>(\n promise: Promise<T>,\n mapError?: (e: unknown) => E\n): Promise<Result<T, E>> {\n try {\n const value = await promise;\n return Ok(value);\n } catch (e) {\n if (mapError) {\n return Err(mapError(e));\n }\n return Err(e as E);\n }\n}\n\n/**\n * Wrap a synchronous function in a Result, catching any thrown errors\n */\nexport function fromTry<T, E = Error>(\n fn: () => T,\n mapError?: (e: unknown) => E\n): Result<T, E> {\n try {\n return Ok(fn());\n } catch (e) {\n if (mapError) {\n return Err(mapError(e));\n }\n return Err(e as E);\n }\n}\n\n/**\n * Map over a successful Result value\n */\nexport function map<T, U, E>(\n result: Result<T, E>,\n fn: (value: T) => U\n): Result<U, E> {\n if (result.ok) {\n return Ok(fn(result.value));\n }\n return result;\n}\n\n/**\n * Map over a failed Result error\n */\nexport function mapErr<T, E, F>(\n result: Result<T, E>,\n fn: (error: E) => F\n): Result<T, F> {\n if (!result.ok) {\n return Err(fn(result.error));\n }\n return result;\n}\n\n/**\n * Chain Results together (flatMap)\n */\nexport function flatMap<T, U, E>(\n result: Result<T, E>,\n fn: (value: T) => Result<U, E>\n): Result<U, E> {\n if (result.ok) {\n return fn(result.value);\n }\n return result;\n}\n\n/**\n * Unwrap a Result, throwing if it's an error\n */\nexport function unwrap<T, E>(result: Result<T, E>): T {\n if (result.ok) {\n return result.value;\n }\n throw result.error;\n}\n\n/**\n * Unwrap a Result with a default value\n */\nexport function unwrapOr<T, E>(result: Result<T, E>, defaultValue: T): T {\n if (result.ok) {\n return result.value;\n }\n return defaultValue;\n}\n\n/**\n * Unwrap a Result with a lazy default value\n */\nexport function unwrapOrElse<T, E>(result: Result<T, E>, fn: (error: E) => T): T {\n if (result.ok) {\n return result.value;\n }\n return fn(result.error);\n}\n\n/**\n * Match on a Result, providing handlers for both cases\n */\nexport function match<T, E, U>(\n result: Result<T, E>,\n handlers: {\n ok: (value: T) => U;\n err: (error: E) => U;\n }\n): U {\n if (result.ok) {\n return handlers.ok(result.value);\n }\n return handlers.err(result.error);\n}\n\n/**\n * Combine multiple Results into a single Result containing an array\n * Returns the first error encountered, or Ok with all values\n */\nexport function all<T, E>(results: Result<T, E>[]): Result<T[], E> {\n const values: T[] = [];\n for (const result of results) {\n if (!result.ok) {\n return result;\n }\n values.push(result.value);\n }\n return Ok(values);\n}\n\n/**\n * Base class for typed errors with context\n */\nexport class HypenError extends Error {\n readonly code: string;\n readonly context?: Record<string, unknown>;\n override readonly cause?: Error;\n\n constructor(\n code: string,\n message: string,\n options?: { context?: Record<string, unknown>; cause?: Error }\n ) {\n super(message);\n this.name = 'HypenError';\n this.code = code;\n this.context = options?.context;\n this.cause = options?.cause;\n\n // Maintain proper prototype chain\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * Error thrown when an action handler fails\n */\nexport class ActionError extends HypenError {\n readonly actionName: string;\n\n constructor(actionName: string, cause?: unknown) {\n super(\n 'ACTION_ERROR',\n `Action handler \"${actionName}\" failed: ${cause instanceof Error ? cause.message : String(cause)}`,\n {\n context: { actionName },\n cause: cause instanceof Error ? cause : undefined,\n }\n );\n this.name = 'ActionError';\n this.actionName = actionName;\n }\n}\n\n/**\n * Error thrown when a connection fails\n */\nexport class ConnectionError extends HypenError {\n readonly url: string;\n readonly attempt?: number;\n\n constructor(url: string, cause?: unknown, attempt?: number) {\n super(\n 'CONNECTION_ERROR',\n `Connection to \"${url}\" failed${attempt ? ` (attempt ${attempt})` : ''}: ${\n cause instanceof Error ? cause.message : String(cause)\n }`,\n {\n context: { url, attempt },\n cause: cause instanceof Error ? cause : undefined,\n }\n );\n this.name = 'ConnectionError';\n this.url = url;\n this.attempt = attempt;\n }\n}\n\n/**\n * Error thrown when state operations fail\n */\nexport class StateError extends HypenError {\n readonly path?: string;\n\n constructor(message: string, path?: string, cause?: unknown) {\n super('STATE_ERROR', message, {\n context: { path },\n cause: cause instanceof Error ? cause : undefined,\n });\n this.name = 'StateError';\n this.path = path;\n }\n}\n\n/**\n * Error thrown when parsing Hypen DSL source fails\n */\nexport class ParseError extends HypenError {\n readonly source?: string;\n\n constructor(message: string, source?: string, cause?: unknown) {\n super('PARSE_ERROR', message, {\n context: { source },\n cause: cause instanceof Error ? cause : undefined,\n });\n this.name = 'ParseError';\n this.source = source;\n }\n}\n\n/**\n * Error thrown when rendering fails\n */\nexport class RenderError extends HypenError {\n constructor(message: string, cause?: unknown) {\n super('RENDER_ERROR', message, {\n cause: cause instanceof Error ? cause : undefined,\n });\n this.name = 'RenderError';\n }\n}\n\n/**\n * Classify a WASM engine error string into the appropriate HypenError subclass.\n * The engine returns JsValue error strings with known prefixes.\n */\nexport function classifyEngineError(err: unknown): HypenError {\n // Handle structured WASM errors: { type: string, message: string }\n if (err && typeof err === 'object' && 'message' in err && 'type' in err) {\n const structured = err as { type: string; message: string };\n switch (structured.type) {\n case 'parseError': return new ParseError(structured.message);\n case 'stateError': return new StateError(structured.message);\n case 'renderError': return new RenderError(structured.message);\n case 'actionError': return new HypenError('ACTION_ERROR', structured.message);\n default: return new HypenError('UNKNOWN_ERROR', structured.message);\n }\n }\n const message = err instanceof Error ? err.message : String(err);\n\n if (message.startsWith('Parse error:')) {\n return new ParseError(message);\n }\n if (message.startsWith('Invalid state:') || message.startsWith('Invalid state patch:')) {\n return new StateError(message);\n }\n if (message.startsWith('Parent node not found:')) {\n return new RenderError(message);\n }\n\n return new RenderError(message);\n}\n",
|
|
6
|
-
"/**\n * Retry Utility for Network Operations\n *\n * Provides configurable retry logic with exponential/linear backoff\n * for handling transient failures in network operations.\n */\n\nimport { type Result, Ok, Err } from \"./result.js\";\n\n/**\n * Options for retry behavior\n */\nexport interface RetryOptions {\n /** Maximum number of attempts (default: 3) */\n maxAttempts?: number;\n /** Initial delay in milliseconds (default: 1000) */\n delayMs?: number;\n /** Backoff strategy (default: 'exponential') */\n backoff?: \"linear\" | \"exponential\" | \"none\";\n /** Maximum delay cap in milliseconds (default: 30000) */\n maxDelayMs?: number;\n /** Jitter factor 0-1 to randomize delays (default: 0.1) */\n jitter?: number;\n /** Callback on each retry attempt */\n onRetry?: (attempt: number, error: Error, nextDelayMs: number) => void;\n /** Optional predicate to determine if error is retryable */\n shouldRetry?: (error: Error) => boolean;\n /** AbortSignal for cancellation */\n signal?: AbortSignal;\n}\n\n/**\n * Default retry options\n */\nconst DEFAULT_OPTIONS: Required<Omit<RetryOptions, \"onRetry\" | \"shouldRetry\" | \"signal\">> = {\n maxAttempts: 3,\n delayMs: 1000,\n backoff: \"exponential\",\n maxDelayMs: 30000,\n jitter: 0.1,\n};\n\n/**\n * Calculate delay for a given attempt\n */\nfunction calculateDelay(\n attempt: number,\n options: Required<Omit<RetryOptions, \"onRetry\" | \"shouldRetry\" | \"signal\">>\n): number {\n let delay: number;\n\n switch (options.backoff) {\n case \"exponential\":\n // 2^(attempt-1) * delayMs: 1x, 2x, 4x, 8x...\n delay = options.delayMs * Math.pow(2, attempt - 1);\n break;\n case \"linear\":\n // attempt * delayMs: 1x, 2x, 3x, 4x...\n delay = options.delayMs * attempt;\n break;\n case \"none\":\n delay = options.delayMs;\n break;\n }\n\n // Apply jitter (randomize ±jitter%)\n if (options.jitter > 0) {\n const jitterRange = delay * options.jitter;\n delay += (Math.random() * 2 - 1) * jitterRange;\n }\n\n // Cap at maxDelayMs\n return Math.min(delay, options.maxDelayMs);\n}\n\n/**\n * Sleep for a given duration, respecting abort signal\n */\nfunction sleep(ms: number, signal?: AbortSignal): Promise<void> {\n return new Promise((resolve, reject) => {\n if (signal?.aborted) {\n reject(new Error(\"Retry aborted\"));\n return;\n }\n\n const timeoutId = setTimeout(resolve, ms);\n\n signal?.addEventListener(\"abort\", () => {\n clearTimeout(timeoutId);\n reject(new Error(\"Retry aborted\"));\n });\n });\n}\n\n/**\n * Retry a function with configurable backoff\n *\n * @example\n * ```typescript\n * // Basic usage\n * const result = await retry(() => fetch('/api/data'));\n *\n * // With options\n * const result = await retry(\n * () => fetch('/api/data'),\n * {\n * maxAttempts: 5,\n * delayMs: 2000,\n * backoff: 'exponential',\n * onRetry: (n, err) => console.log(`Attempt ${n} failed: ${err.message}`)\n * }\n * );\n * ```\n */\nexport async function retry<T>(\n fn: () => T | Promise<T>,\n options: RetryOptions = {}\n): Promise<T> {\n const opts = { ...DEFAULT_OPTIONS, ...options };\n let lastError: Error = new Error(\"No attempts made\");\n\n for (let attempt = 1; attempt <= opts.maxAttempts; attempt++) {\n try {\n // Check for abort before each attempt\n if (opts.signal?.aborted) {\n throw new Error(\"Retry aborted\");\n }\n\n return await fn();\n } catch (e) {\n lastError = e instanceof Error ? e : new Error(String(e));\n\n // Check if we should retry this error\n if (opts.shouldRetry && !opts.shouldRetry(lastError)) {\n throw lastError;\n }\n\n // If this was the last attempt, don't wait\n if (attempt === opts.maxAttempts) {\n break;\n }\n\n // Calculate delay and notify\n const delayMs = calculateDelay(attempt, opts);\n opts.onRetry?.(attempt, lastError, delayMs);\n\n // Wait before next attempt\n await sleep(delayMs, opts.signal);\n }\n }\n\n throw lastError;\n}\n\n/**\n * Retry a function, returning a Result instead of throwing\n *\n * @example\n * ```typescript\n * const result = await retryResult(() => fetch('/api/data'));\n * if (result.ok) {\n * console.log('Success:', result.value);\n * } else {\n * console.error('All retries failed:', result.error);\n * }\n * ```\n */\nexport async function retryResult<T>(\n fn: () => T | Promise<T>,\n options: RetryOptions = {}\n): Promise<Result<T, Error>> {\n try {\n const value = await retry(fn, options);\n return Ok(value);\n } catch (e) {\n return Err(e instanceof Error ? e : new Error(String(e)));\n }\n}\n\n/**\n * Create a retryable version of a function\n *\n * @example\n * ```typescript\n * const fetchWithRetry = withRetry(\n * (url: string) => fetch(url),\n * { maxAttempts: 3 }\n * );\n *\n * const response = await fetchWithRetry('/api/data');\n * ```\n */\nexport function withRetry<TArgs extends unknown[], TReturn>(\n fn: (...args: TArgs) => TReturn | Promise<TReturn>,\n options: RetryOptions = {}\n): (...args: TArgs) => Promise<TReturn> {\n return (...args: TArgs) => retry(() => fn(...args), options);\n}\n\n/**\n * Predefined retry conditions\n */\nexport const RetryConditions = {\n /**\n * Retry on network errors (fetch failures, timeouts)\n */\n networkErrors: (error: Error): boolean => {\n const message = error.message.toLowerCase();\n return (\n message.includes(\"network\") ||\n message.includes(\"fetch\") ||\n message.includes(\"timeout\") ||\n message.includes(\"econnrefused\") ||\n message.includes(\"econnreset\") ||\n message.includes(\"socket\")\n );\n },\n\n /**\n * Retry on specific HTTP status codes (from fetch Response)\n */\n httpRetryable: (error: Error & { status?: number }): boolean => {\n const status = error.status;\n if (!status) return false;\n // Retry on 408, 429, 500, 502, 503, 504\n return [408, 429, 500, 502, 503, 504].includes(status);\n },\n\n /**\n * Retry on transient WebSocket errors\n */\n websocketErrors: (error: Error): boolean => {\n const message = error.message.toLowerCase();\n return (\n message.includes(\"websocket\") ||\n message.includes(\"connection\") ||\n message.includes(\"close\")\n );\n },\n\n /**\n * Combine multiple conditions (retry if any match)\n */\n any:\n (...conditions: Array<(error: Error) => boolean>) =>\n (error: Error): boolean =>\n conditions.some((c) => c(error)),\n\n /**\n * Combine multiple conditions (retry if all match)\n */\n all:\n (...conditions: Array<(error: Error) => boolean>) =>\n (error: Error): boolean =>\n conditions.every((c) => c(error)),\n};\n\n/**\n * Preset configurations for common use cases\n */\nexport const RetryPresets = {\n /**\n * Aggressive retry for critical operations\n */\n aggressive: {\n maxAttempts: 10,\n delayMs: 500,\n backoff: \"exponential\" as const,\n maxDelayMs: 60000,\n jitter: 0.2,\n },\n\n /**\n * Conservative retry for non-critical operations\n */\n conservative: {\n maxAttempts: 3,\n delayMs: 2000,\n backoff: \"linear\" as const,\n maxDelayMs: 10000,\n jitter: 0.1,\n },\n\n /**\n * Fast retry for local operations (short delays)\n */\n fast: {\n maxAttempts: 5,\n delayMs: 100,\n backoff: \"exponential\" as const,\n maxDelayMs: 2000,\n jitter: 0,\n },\n\n /**\n * WebSocket reconnection preset\n */\n websocket: {\n maxAttempts: 10,\n delayMs: 1000,\n backoff: \"exponential\" as const,\n maxDelayMs: 30000,\n jitter: 0.1,\n shouldRetry: RetryConditions.websocketErrors,\n },\n};\n"
|
|
7
5
|
],
|
|
8
|
-
"mappings": "
|
|
9
|
-
"debugId": "
|
|
6
|
+
"mappings": "",
|
|
7
|
+
"debugId": "271C330395943DFE64756E2164756E21",
|
|
10
8
|
"names": []
|
|
11
9
|
}
|