@direct.dev/sdk 1.0.0 → 1.0.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 +16 -14
- package/lib/index.cjs +1 -1
- package/lib/index.d.ts +134 -3
- package/lib/index.mjs +1 -1
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Branded subtype of number for returned timestamps, used to guarantee
|
|
3
|
+
* correctness of date processing integrations and argument forwarding.
|
|
4
|
+
*/
|
|
5
|
+
type Timestamp = number & {
|
|
6
|
+
readonly __tsBrand: unique symbol;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Factory for creating WebSocket connections used by Direct Wire transports.
|
|
11
|
+
*
|
|
12
|
+
* This allows callers to simulate or instrument websocket behavior without
|
|
13
|
+
* globally monkeypatching `WebSocket`.
|
|
14
|
+
*/
|
|
15
|
+
type DirectCreateWebSocket = (url: string) => WebSocket;
|
|
16
|
+
/**
|
|
17
|
+
* Public log levels exposed by the Direct.dev client surface.
|
|
18
|
+
*
|
|
19
|
+
* These are intentionally smaller than the internal Pulse log levels to keep
|
|
20
|
+
* the user-facing API simple and predictable.
|
|
21
|
+
*/
|
|
22
|
+
type ClientLogLevel = "silent" | "info" | "debug" | "warn" | "error";
|
|
23
|
+
/**
|
|
24
|
+
* Per-request logging mode for request tracing and cache-resolution insight.
|
|
25
|
+
*
|
|
26
|
+
* - `off`: no request logs
|
|
27
|
+
* - `summary`: one concise resolution line per handled request
|
|
28
|
+
* - `debug`: detailed request/response logging plus pipeline stage diagnostics
|
|
29
|
+
*/
|
|
30
|
+
type RequestLogging = "off" | "summary" | "debug";
|
|
31
|
+
/**
|
|
32
|
+
* Event emitted by Direct client logging hooks.
|
|
33
|
+
*
|
|
34
|
+
* Stable public events:
|
|
35
|
+
* - `request_resolution`
|
|
36
|
+
* - `preload.phase`
|
|
37
|
+
* - `preload.clock_sync`
|
|
38
|
+
* - `sync.rebuild`
|
|
39
|
+
* - `client.phase`
|
|
40
|
+
*
|
|
41
|
+
* Debug-oriented events:
|
|
42
|
+
* - `request_pipeline_resolution`
|
|
43
|
+
* - `request_handled`
|
|
44
|
+
* - `block.state_probe`
|
|
45
|
+
*
|
|
46
|
+
* Consumers should prefer the stable set unless they explicitly need deeper
|
|
47
|
+
* diagnostics from debug logging.
|
|
48
|
+
*/
|
|
49
|
+
type DirectLogEvent = {
|
|
50
|
+
level: Exclude<ClientLogLevel, "silent">;
|
|
51
|
+
name: string;
|
|
52
|
+
value: Record<string, unknown>;
|
|
53
|
+
timestamp: Timestamp;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Callback invoked for every emitted Direct client log event.
|
|
57
|
+
*/
|
|
58
|
+
type DirectLogEventListener = (event: DirectLogEvent) => void;
|
|
59
|
+
/**
|
|
60
|
+
* Unified logging configuration for Direct client surfaces.
|
|
61
|
+
*/
|
|
62
|
+
type DirectLoggingConfig = {
|
|
63
|
+
/**
|
|
64
|
+
* Controls operational/client log verbosity.
|
|
65
|
+
*
|
|
66
|
+
* This governs operational and lifecycle events such as:
|
|
67
|
+
* - `preload.phase`
|
|
68
|
+
* - `preload.clock_sync`
|
|
69
|
+
* - `sync.rebuild`
|
|
70
|
+
* - `client.phase`
|
|
71
|
+
*
|
|
72
|
+
* @default "warn"
|
|
73
|
+
*/
|
|
74
|
+
client?: ClientLogLevel;
|
|
75
|
+
/**
|
|
76
|
+
* Controls request-level tracing emitted by the client.
|
|
77
|
+
*
|
|
78
|
+
* This governs:
|
|
79
|
+
* - stable request completion: `request_resolution`
|
|
80
|
+
* - deeper diagnostics: `request_pipeline_resolution`, `request_handled`,
|
|
81
|
+
* and `block.state_probe`
|
|
82
|
+
*
|
|
83
|
+
* @default "off"
|
|
84
|
+
*/
|
|
85
|
+
requests?: RequestLogging;
|
|
86
|
+
/**
|
|
87
|
+
* Optional sink for intercepting emitted log events.
|
|
88
|
+
*/
|
|
89
|
+
onEvent?: DirectLogEventListener;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Shared types for the Direct.dev SDK.
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Options for the fetch wrapper.
|
|
98
|
+
*/
|
|
99
|
+
type CreateFetchOptions = {
|
|
100
|
+
/** Optional fetch implementation to wrap (defaults to global fetch). */
|
|
101
|
+
fetch?: typeof globalThis.fetch;
|
|
102
|
+
/** Optional WebSocket factory used by the underlying Direct client. */
|
|
103
|
+
createWebSocket?: DirectCreateWebSocket;
|
|
104
|
+
/** Unified logging configuration for operational logs and request tracing. */
|
|
105
|
+
logging?: DirectLoggingConfig;
|
|
106
|
+
/** URLs to preload on init (fire-and-forget). */
|
|
107
|
+
preload?: string[];
|
|
108
|
+
};
|
|
109
|
+
type LoggingOptions = DirectLoggingConfig;
|
|
110
|
+
type LogEvent = DirectLogEvent;
|
|
111
|
+
|
|
1
112
|
/**
|
|
2
113
|
* @direct.dev/sdk
|
|
3
114
|
*
|
|
4
|
-
*
|
|
115
|
+
* Direct.dev SDK that intercepts direct.dev RPC calls and routes them through
|
|
5
116
|
* DirectRPCClient while preserving fetch semantics.
|
|
6
117
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Create a fetch wrapper that intercepts direct.dev JSON-RPC calls.
|
|
121
|
+
* Each createFetch instance maintains its own isolated client pool.
|
|
122
|
+
*
|
|
123
|
+
* After install(), callers must provide an explicit base fetch to avoid
|
|
124
|
+
* wrapping the installed fetch instance.
|
|
125
|
+
*/
|
|
126
|
+
declare const createFetch: (rawOptions?: CreateFetchOptions) => typeof fetch;
|
|
127
|
+
/**
|
|
128
|
+
* Uninstall function returned by install().
|
|
129
|
+
*/
|
|
130
|
+
type UninstallFn = () => void;
|
|
131
|
+
/**
|
|
132
|
+
* Install the fetch wrapper globally on `globalThis.fetch`.
|
|
133
|
+
* Returns an uninstall function that restores the original fetch.
|
|
134
|
+
* Repeated installs are idempotent and return the active uninstall function.
|
|
135
|
+
*/
|
|
136
|
+
declare const install: (options?: CreateFetchOptions) => UninstallFn;
|
|
137
|
+
|
|
138
|
+
export { createFetch, install };
|
|
139
|
+
export type { CreateFetchOptions, LogEvent, LoggingOptions, UninstallFn };
|