@solidrt/flux-types 0.0.11 → 0.0.14

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/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "@solidrt/flux-types",
3
- "version": "0.0.11",
3
+ "version": "0.0.14",
4
4
  "license": "MIT",
5
5
  "author": "Antoine van Wel",
6
6
  "types": "index.d.ts",
7
7
  "files": [
8
8
  "index.d.ts",
9
+ "modules",
10
+ "gui",
11
+ "standards",
9
12
  "README.md",
10
13
  "LICENSE"
11
14
  ]
@@ -0,0 +1,10 @@
1
+ // The web-standard `console` global. flux provides exactly these four methods
2
+ // (no info/trace/table/group/...). A global script file: these declarations
3
+ // stand in for the ones lib.dom would otherwise supply.
4
+
5
+ declare let console: {
6
+ debug(...args: any[]): void
7
+ log(...args: any[]): void
8
+ warn(...args: any[]): void
9
+ error(...args: any[]): void
10
+ }
@@ -0,0 +1,104 @@
1
+ // The Fetch API cluster (Headers, Request, Response, fetch). A deliberate subset
2
+ // of the WHATWG Fetch standard: flux provides exactly these members and no more
3
+ // (no Blob, FormData, ReadableStream, arrayBuffer(), clone(), AbortSignal, ...).
4
+ // Grouped in one file because the four share BodyInit/HeadersInit and reference
5
+ // each other.
6
+
7
+ /** Header initializer: a plain name -> value object, or another Headers. */
8
+ type HeadersInit = Record<string, string> | Headers
9
+
10
+ /**
11
+ * A message body: a string, raw bytes, or an async-iterable of string/byte
12
+ * chunks (e.g. an `async function*`), which is sent as a stream.
13
+ */
14
+ type BodyInit = string | Uint8Array | AsyncIterable<string | Uint8Array>
15
+
16
+ /** A subset of the WHATWG Headers API. Names are case-insensitive. */
17
+ interface Headers {
18
+ /** The value for `name` (multiple values comma-joined), or null if absent. */
19
+ get(name: string): string | null
20
+ /** Set `name` to `value`, replacing any existing values. */
21
+ set(name: string, value: string): void
22
+ /** Whether any value for `name` exists. */
23
+ has(name: string): boolean
24
+ /** Remove `name`. */
25
+ delete(name: string): void
26
+ /** Add a value for `name` without replacing existing ones. */
27
+ append(name: string, value: string): void
28
+ }
29
+
30
+ declare let Headers: {
31
+ new (init?: HeadersInit): Headers
32
+ }
33
+
34
+ interface RequestInit {
35
+ /** HTTP method; uppercased. Defaults to "GET". */
36
+ method?: string
37
+ /** Request body. */
38
+ body?: BodyInit | null
39
+ /** Request headers. */
40
+ headers?: HeadersInit
41
+ }
42
+
43
+ /**
44
+ * A subset of the WHATWG Request. flux adds `params` (route params) for requests
45
+ * the `flux:http` server passes to handlers. The body is read-once.
46
+ */
47
+ interface Request {
48
+ readonly method: string
49
+ readonly url: string
50
+ readonly headers: Headers
51
+ /** Route params from the matched pattern; an empty object for a JS-constructed Request. */
52
+ readonly params: Record<string, string>
53
+ /** The body as an async-iterable of byte chunks (read once). */
54
+ readonly body: AsyncIterable<Uint8Array>
55
+ /** Read the whole body as UTF-8 text. */
56
+ text(): Promise<string>
57
+ /** Read the whole body as raw bytes. */
58
+ bytes(): Promise<Uint8Array>
59
+ /** Read and parse the whole body as JSON. */
60
+ json(): Promise<any>
61
+ }
62
+
63
+ declare let Request: {
64
+ new (url: string, init?: RequestInit): Request
65
+ }
66
+
67
+ interface ResponseInit {
68
+ /** Status code. Defaults to 200. */
69
+ status?: number
70
+ /** Status text. */
71
+ statusText?: string
72
+ /** Response headers. */
73
+ headers?: HeadersInit
74
+ }
75
+
76
+ /** A subset of the WHATWG Response. The body is read-once. */
77
+ interface Response {
78
+ readonly status: number
79
+ readonly statusText: string
80
+ /** True when `status` is in the range 200..299. */
81
+ readonly ok: boolean
82
+ readonly url: string
83
+ readonly headers: Headers
84
+ /** The body as an async-iterable of byte chunks (read once). */
85
+ readonly body: AsyncIterable<Uint8Array>
86
+ /** Read the whole body as UTF-8 text. */
87
+ text(): Promise<string>
88
+ /** Read the whole body as raw bytes. */
89
+ bytes(): Promise<Uint8Array>
90
+ /** Read and parse the whole body as JSON. */
91
+ json(): Promise<any>
92
+ }
93
+
94
+ declare let Response: {
95
+ new (body?: BodyInit | null, init?: ResponseInit): Response
96
+ /** Build a JSON response (sets Content-Type to application/json when unset). */
97
+ json(data: any, init?: ResponseInit): Response
98
+ }
99
+
100
+ /**
101
+ * Fetch a resource over HTTP(S). The body may be a string, Uint8Array, or an
102
+ * async-iterable (streamed). Resolves to a {@link Response}.
103
+ */
104
+ declare function fetch(url: string, options?: RequestInit): Promise<Response>
@@ -0,0 +1,47 @@
1
+ // TextEncoder / TextDecoder. UTF-8 only (the only encoding the runtime needs).
2
+
3
+ interface TextEncoder {
4
+ /** Always "utf-8". */
5
+ readonly encoding: string
6
+ /** Encode `input` (default "") to its UTF-8 bytes. */
7
+ encode(input?: string): Uint8Array
8
+ }
9
+
10
+ declare let TextEncoder: {
11
+ new (): TextEncoder
12
+ }
13
+
14
+ /** Options for the {@link TextDecoder} constructor. */
15
+ interface TextDecoderOptions {
16
+ /** Throw on invalid UTF-8 instead of substituting U+FFFD. */
17
+ fatal?: boolean
18
+ /** Keep a leading byte-order mark instead of stripping it. */
19
+ ignoreBOM?: boolean
20
+ }
21
+
22
+ /** Options for {@link TextDecoder.decode}. */
23
+ interface TextDecodeOptions {
24
+ /** Hold an incomplete trailing UTF-8 sequence for the next call. */
25
+ stream?: boolean
26
+ }
27
+
28
+ interface TextDecoder {
29
+ /** Always "utf-8". */
30
+ readonly encoding: string
31
+ readonly fatal: boolean
32
+ readonly ignoreBOM: boolean
33
+ /**
34
+ * Decode UTF-8 `input` (a Uint8Array or ArrayBuffer; default empty) to a
35
+ * string. With `{ stream: true }`, an incomplete trailing sequence is held for
36
+ * the next call.
37
+ */
38
+ decode(input?: Uint8Array | ArrayBuffer, options?: TextDecodeOptions): string
39
+ }
40
+
41
+ declare let TextDecoder: {
42
+ /**
43
+ * `label` must be a UTF-8 encoding label (the runtime is UTF-8 only); any other
44
+ * label throws a RangeError.
45
+ */
46
+ new (label?: string, options?: TextDecoderOptions): TextDecoder
47
+ }
@@ -0,0 +1,31 @@
1
+ // Timers, microtask scheduling, and the monotonic clock. flux's timers differ
2
+ // from the browser in two ways: the delay is required, and no extra callback
3
+ // arguments are forwarded.
4
+
5
+ /**
6
+ * Run `callback` after at least `ms` milliseconds. Returns a timer id for
7
+ * {@link clearTimeout}.
8
+ */
9
+ declare function setTimeout(callback: () => void, ms: number): number
10
+ /** Cancel a pending timeout. Throws on an unknown id. */
11
+ declare function clearTimeout(id: number): void
12
+ /**
13
+ * Run `callback` every `ms` milliseconds. Returns a timer id for
14
+ * {@link clearInterval}.
15
+ */
16
+ declare function setInterval(callback: () => void, ms: number): number
17
+ /** Cancel a running interval. Throws on an unknown id. */
18
+ declare function clearInterval(id: number): void
19
+ /**
20
+ * Queue `callback` to run as a microtask: after the current job finishes, before
21
+ * any timer fires.
22
+ */
23
+ declare function queueMicrotask(callback: () => void): void
24
+
25
+ declare let performance: {
26
+ /**
27
+ * Milliseconds since a monotonic origin (high-resolution, not wall-clock). Use
28
+ * for measuring durations, not for calendar time.
29
+ */
30
+ now(): number
31
+ }
@@ -0,0 +1,62 @@
1
+ // The web-standard WebSocket client. A deliberate subset: handler properties
2
+ // only (no addEventListener), plain-object events (not Event instances), ws://
3
+ // only (wss:// is not supported yet), and send accepts only string or Uint8Array.
4
+
5
+ /** The event passed to {@link WebSocket.onopen}. */
6
+ interface WebSocketOpenEvent {
7
+ type: "open"
8
+ }
9
+
10
+ /** The event passed to {@link WebSocket.onmessage}. */
11
+ interface WebSocketMessageEvent {
12
+ type: "message"
13
+ /** Text frames arrive as a string, binary frames as a Uint8Array. */
14
+ data: string | Uint8Array
15
+ }
16
+
17
+ /** The event passed to {@link WebSocket.onerror}. */
18
+ interface WebSocketErrorEvent {
19
+ type: "error"
20
+ message: string
21
+ }
22
+
23
+ /** The event passed to {@link WebSocket.onclose}. */
24
+ interface WebSocketCloseEvent {
25
+ type: "close"
26
+ code: number
27
+ reason: string
28
+ wasClean: boolean
29
+ }
30
+
31
+ interface WebSocket {
32
+ readonly url: string
33
+ /** Connection state: CONNECTING 0, OPEN 1, CLOSING 2, CLOSED 3. */
34
+ readonly readyState: number
35
+ onopen: ((event: WebSocketOpenEvent) => void) | null
36
+ onmessage: ((event: WebSocketMessageEvent) => void) | null
37
+ onerror: ((event: WebSocketErrorEvent) => void) | null
38
+ onclose: ((event: WebSocketCloseEvent) => void) | null
39
+ /**
40
+ * Queue a message: a string sends a text frame, a Uint8Array a binary frame.
41
+ * Throws while CONNECTING; dropped once the socket is closing or closed.
42
+ */
43
+ send(data: string | Uint8Array): void
44
+ /**
45
+ * Start the closing handshake. `code` must be 1000 or in 3000..4999; `reason`
46
+ * must be 123 bytes or fewer.
47
+ */
48
+ close(code?: number, reason?: string): void
49
+ readonly CONNECTING: 0
50
+ readonly OPEN: 1
51
+ readonly CLOSING: 2
52
+ readonly CLOSED: 3
53
+ }
54
+
55
+ declare let WebSocket: {
56
+ /** Open a connection. `url` must be ws:// (wss:// is not supported yet). */
57
+ new (url: string): WebSocket
58
+ readonly CONNECTING: 0
59
+ readonly OPEN: 1
60
+ readonly CLOSING: 2
61
+ readonly CLOSED: 3
62
+ }