@small-web/kitten-types 1.1.5 → 2.0.0
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 +9 -2
- package/fragments.d.ts +13 -14
- package/global.d.ts +6 -1096
- package/index.d.ts +7 -27
- package/kitten/src/AppDatabase.d.ts +10 -0
- package/kitten/src/AppRepository.d.ts +101 -0
- package/kitten/src/AutomaticUpdates.d.ts +21 -0
- package/kitten/src/Files.d.ts +61 -0
- package/kitten/src/GlobalInternalDatabase.d.ts +22 -0
- package/kitten/src/InternalDatabase.d.ts +7 -0
- package/kitten/src/REPL.d.ts +5 -0
- package/kitten/src/Routes.d.ts +41 -0
- package/kitten/src/Server.d.ts +76 -0
- package/kitten/src/ServerError.d.ts +6 -0
- package/kitten/src/Sessions.d.ts +32 -0
- package/kitten/src/Uploads.d.ts +20 -0
- package/kitten/src/Utils.d.ts +79 -0
- package/kitten/src/cli/commands/db.d.ts +48 -0
- package/kitten/src/cli/commands/deploy.d.ts +16 -0
- package/kitten/src/cli/commands/disable.d.ts +9 -0
- package/kitten/src/cli/commands/enable.d.ts +9 -0
- package/kitten/src/cli/commands/logs.d.ts +15 -0
- package/kitten/src/cli/commands/restart.d.ts +11 -0
- package/kitten/src/cli/commands/run.d.ts +15 -0
- package/kitten/src/cli/commands/serve.d.ts +13 -0
- package/kitten/src/cli/commands/shell.d.ts +1 -0
- package/kitten/src/cli/commands/start.d.ts +9 -0
- package/kitten/src/cli/commands/status.d.ts +15 -0
- package/kitten/src/cli/commands/stop.d.ts +9 -0
- package/kitten/src/cli/commands/uninstall.d.ts +9 -0
- package/kitten/src/cli/commands/update.d.ts +7 -0
- package/kitten/src/cli/index.d.ts +55 -0
- package/kitten/src/cli/lib/WarningBox.d.ts +8 -0
- package/kitten/src/cli/lib/header.d.ts +10 -0
- package/kitten/src/components/SvgSpinner.component.d.ts +9 -0
- package/kitten/src/lib/KittenComponent.d.ts +340 -0
- package/kitten/src/lib/KittenMoji.d.ts +35 -0
- package/kitten/src/lib/KittenPackage.d.ts +56 -0
- package/kitten/src/lib/KittenPage.d.ts +202 -0
- package/kitten/src/lib/Version.d.ts +49 -0
- package/kitten/src/lib/ansi-highlight-html.d.ts +5 -0
- package/kitten/src/lib/components/stateful/CopyButton.component.d.ts +14 -0
- package/kitten/src/lib/components/stateless/copyButton.component.d.ts +21 -0
- package/kitten/src/lib/crypto.d.ts +95 -0
- package/kitten/src/lib/deploy.d.ts +20 -0
- package/kitten/src/lib/ensure.d.ts +28 -0
- package/kitten/src/lib/fragments.d.ts +1 -0
- package/kitten/src/lib/globals.d.ts +10 -0
- package/kitten/src/lib/html.d.ts +61 -0
- package/kitten/src/lib/markdown.d.ts +16 -0
- package/kitten/src/lib/paths.d.ts +25 -0
- package/kitten/src/lib/service-status.d.ts +14 -0
- package/kitten/src/lib/system-exit-codes.d.ts +39 -0
- package/kitten/src/lib/terminal-link.d.ts +24 -0
- package/kitten/src/middleware/authentication.d.ts +8 -0
- package/kitten/src/middleware/index.d.ts +5 -0
- package/kitten/src/middleware/request-and-response-helpers.d.ts +6 -0
- package/kitten/src/middleware/request-log.d.ts +10 -0
- package/kitten/src/middleware/sessions.d.ts +3 -0
- package/kitten/src/middleware/stats.d.ts +8 -0
- package/kitten/src/middleware/trailing-slashes.d.ts +11 -0
- package/kitten/src/middleware/websocket.d.ts +14 -0
- package/kitten/src/routes/HttpRoute.d.ts +16 -0
- package/kitten/src/routes/LazilyLoadedRoute.d.ts +15 -0
- package/kitten/src/routes/PageRoute.d.ts +54 -0
- package/kitten/src/routes/PageSocketRoute.d.ts +42 -0
- package/kitten/src/routes/PostRoute.d.ts +64 -0
- package/kitten/src/routes/StaticRoute.d.ts +17 -0
- package/kitten/src/routes/WebSocketRoute.d.ts +21 -0
- package/kitten/src/routes/lib/validator.d.ts +18 -0
- package/kitten/src/types/fragments.d.ts +14 -0
- package/kitten/src/types/globals.d.ts +1239 -0
- package/kitten/src/types/index.d.ts +12 -0
- package/kitten/src/types/types.d.ts +476 -0
- package/kitten/third-party-libraries-with-missing-type-information/index.d.ts +37 -0
- package/package.json +16 -5
- package/types.d.ts +5 -712
- package/polka/index.d.ts +0 -111
- package/slugify/index.d.ts +0 -246
- /package/{ws → kitten/third-party-libraries-with-missing-type-information/ws}/index.d.ts +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Kitten types.
|
|
3
|
+
|
|
4
|
+
This entry point re-exports Kitten types for use in explicit annotations.
|
|
5
|
+
|
|
6
|
+
Side-effect: Brings `declare global { var kitten }` into scope.
|
|
7
|
+
*/
|
|
8
|
+
import './globals.d.ts';
|
|
9
|
+
import './fragments.d.ts';
|
|
10
|
+
export type { Session, WebSocket, BufferLike, slugify, Polka, KittenPolka, KittenHandler, MarkdownIt, Upload, LazilyLoadedRoute, MessageSender, Listener, KittenComponent, KittenPage, ParsedURL, PolkaResponse, PolkaRequest, KittenRequest, KittenResponse, KittenPostRequest, Point, Signature } from './types.d.ts';
|
|
11
|
+
export type { yaml } from './types.d.ts';
|
|
12
|
+
export type { kitten } from './globals.d.ts';
|
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
import EventEmitter from 'node:events'
|
|
2
|
+
import type polka from 'polka'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
Represents a browser session.
|
|
6
|
+
|
|
7
|
+
Sessions are automatically persisted (and expired) in Kitten’s internal database.
|
|
8
|
+
|
|
9
|
+
Used by Kitten to provide automatic authentication for Small Web places.
|
|
10
|
+
|
|
11
|
+
You can also add/update arbitrary session data by adding/updating properties on this object in your routes (this object maps a session object in the `kitten._db.sessions` table in the internal database).
|
|
12
|
+
|
|
13
|
+
You can emit events on a session in order to communicate with other browser tabs and windows that share the same session.
|
|
14
|
+
|
|
15
|
+
@example
|
|
16
|
+
export default function ({ request }) {
|
|
17
|
+
request.session.kittens ??= { count: 1 }
|
|
18
|
+
|
|
19
|
+
return kitten.html`
|
|
20
|
+
<h1>Kitten count</h1>
|
|
21
|
+
<p>${'🐱️'.repeat(request.session.kittens.count++)}</p>
|
|
22
|
+
`
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@see https://kitten.small-web.org/tutorials/sessions/
|
|
26
|
+
|
|
27
|
+
@remarks
|
|
28
|
+
Do not save custom classes on request.session or JSDB will throw an error when it tries to open the internal `_db` database and cannot find your custom class to instantiate.
|
|
29
|
+
|
|
30
|
+
If you want persisted session-level custom objects, store them in your own database table in `kitten.db` keyed by `session.id`.
|
|
31
|
+
*/
|
|
32
|
+
import type { Session } from '../Sessions.ts'
|
|
33
|
+
export type { Session }
|
|
34
|
+
|
|
35
|
+
export type { default as WebSocket, BufferLike } from '../../third-party-libraries-with-missing-type-information/ws/index.d.ts'
|
|
36
|
+
export type { default as slugify } from '@sindresorhus/slugify'
|
|
37
|
+
export type Polka = ReturnType<typeof polka>
|
|
38
|
+
export { default as MarkdownIt } from 'markdown-it'
|
|
39
|
+
|
|
40
|
+
export namespace yaml {
|
|
41
|
+
export function parse(str:string, ...args:any[]): any
|
|
42
|
+
export function stringify(value:any, ...args:any[]): string
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
Represents an uploaded file.
|
|
47
|
+
|
|
48
|
+
@see https://kitten.small-web.org/tutorials/multipart-forms-and-file-uploads/
|
|
49
|
+
*/
|
|
50
|
+
export type { Upload } from '../routes/PostRoute.ts'
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
Abstract base class for lazily-loaded routes.
|
|
54
|
+
*/
|
|
55
|
+
export type { default as LazilyLoadedRoute } from '../routes/LazilyLoadedRoute.ts'
|
|
56
|
+
|
|
57
|
+
import type {default as WebSocket, BufferLike } from '../../third-party-libraries-with-missing-type-information/ws/index.d.ts'
|
|
58
|
+
|
|
59
|
+
type WebSocketWithIsAlive = WebSocket & {isAlive:boolean}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
MessageSender class.
|
|
63
|
+
|
|
64
|
+
Provides a namespaced send() method for use in PageSocket.
|
|
65
|
+
*/
|
|
66
|
+
export type { MessageSender } from '../lib/KittenPage.ts'
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
Kitten component class.
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
This type definition required due to following shenanigans:
|
|
74
|
+
https://github.com/Microsoft/TypeScript/issues/20007#issuecomment-2255964704
|
|
75
|
+
*/
|
|
76
|
+
type JavaScriptFunction = (...args: any[]) => any
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
A class constructor.
|
|
80
|
+
*/
|
|
81
|
+
type Constructor<T> = new (...args: any[]) => T
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
Represents the render function of a component that is bound to component (as its `this`).
|
|
85
|
+
*/
|
|
86
|
+
type BoundComponentRenderFunction<T extends KittenComponent> =
|
|
87
|
+
((...args: Parameters<T['html']>) => Promise<Awaited<ReturnType<T['html']>>>)
|
|
88
|
+
& { boundObject: T }
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
An EventEmitter listener with a `remove()` method for cleanup.
|
|
92
|
+
*/
|
|
93
|
+
export type { Listener } from '../lib/KittenComponent.ts'
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
Kitten Component.
|
|
97
|
+
|
|
98
|
+
A class that makes it easier to author hierarchies of connected components.
|
|
99
|
+
|
|
100
|
+
Handles wiring up and disposal of event listeners for you and gives you an ergonomic, class-based way of writing maintainable applications that take advantage of Kitten’s Streaming HTML workflow while working with well-encapsulated, self-contained components in a clear hierarchy.
|
|
101
|
+
|
|
102
|
+
Extend and instantiate this class to create your own components (components, fragments, layout components, and pages) and provide at least an override for the `html()` method, which is just a function that returns `kitten.html`.
|
|
103
|
+
|
|
104
|
+
The example, below, updates a persisted counter via the + and - buttons (index.page.ts).
|
|
105
|
+
|
|
106
|
+
@example
|
|
107
|
+
// Initialise the database with a persisted counter object.
|
|
108
|
+
kitten.db.counter ??= { count: 0 }
|
|
109
|
+
|
|
110
|
+
export default class CounterPage extends kitten.Page {
|
|
111
|
+
counter
|
|
112
|
+
|
|
113
|
+
constructor () {
|
|
114
|
+
super()
|
|
115
|
+
this.counter = this.addChild(new Counter())
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
override html () {
|
|
119
|
+
return kitten.html`
|
|
120
|
+
<page css>
|
|
121
|
+
<h1>Counter</h1>
|
|
122
|
+
<${this.counter} />
|
|
123
|
+
`
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
class Counter extends kitten.Component {
|
|
128
|
+
override html () {
|
|
129
|
+
return kitten.html`
|
|
130
|
+
<div>
|
|
131
|
+
<div
|
|
132
|
+
id='count'
|
|
133
|
+
aria-live='assertive'
|
|
134
|
+
>
|
|
135
|
+
${kitten.db.counter.count}
|
|
136
|
+
</div>
|
|
137
|
+
<button name='update' connect data='{value: -1}' aria-label='decrement'>-</button>
|
|
138
|
+
<button name='update' connect data='{value: 1}' aria-label='increment'>+</button>
|
|
139
|
+
</div>
|
|
140
|
+
`
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
onUpdate (data: { value: number } ) {
|
|
144
|
+
kitten.db.counter.count += data.value
|
|
145
|
+
this.update()
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
*/
|
|
149
|
+
import type { default as KittenComponent } from '../lib/KittenComponent.ts'
|
|
150
|
+
export type { default as KittenComponent } from '../lib/KittenComponent.ts'
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
KittenPage class.
|
|
154
|
+
|
|
155
|
+
A KittenPage is a specialised KittenComponent that represents a live page in memory (a live page is one that has an automatic WebSocket connection to the page rendered by the PageRoute).
|
|
156
|
+
|
|
157
|
+
A KittenPage constitutes the root of the server-side component hierarchy.
|
|
158
|
+
|
|
159
|
+
Instance data in a `KittenPage` instance sticks around for the lifetime of the page (e.g., until a reload or a navigation event away from it in the browser).
|
|
160
|
+
|
|
161
|
+
If you need greater persistence, use session storage (`request.session`) or the built-in JSDB database (`kitten.db`).
|
|
162
|
+
*/
|
|
163
|
+
import type { default as KittenPage } from '../lib/KittenPage.ts'
|
|
164
|
+
export type { default as KittenPage } from '../lib/KittenPage.ts'
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
Request and response types.
|
|
168
|
+
|
|
169
|
+
These vary per route type but are all built on the base of Polka’s request and response objects which are, themselves, based on the incoming message and server response types of Node’s own http module.
|
|
170
|
+
*/
|
|
171
|
+
|
|
172
|
+
import type { IncomingMessage, ServerResponse } from 'http'
|
|
173
|
+
|
|
174
|
+
export interface ParsedURL {
|
|
175
|
+
pathname: string
|
|
176
|
+
search: string
|
|
177
|
+
query: Record<string, string | string[]> | void
|
|
178
|
+
raw: string
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export type PolkaResponse = ServerResponse
|
|
182
|
+
|
|
183
|
+
export interface PolkaRequest extends IncomingMessage {
|
|
184
|
+
url: string
|
|
185
|
+
method: string
|
|
186
|
+
originalUrl: string
|
|
187
|
+
params: Record<string, string>
|
|
188
|
+
path: string
|
|
189
|
+
search: string
|
|
190
|
+
query: Record<string,string>
|
|
191
|
+
body?: any
|
|
192
|
+
_decoded?: true
|
|
193
|
+
_parsedUrl: ParsedURL
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
The request objects received by Kitten routes.
|
|
198
|
+
|
|
199
|
+
Based on Polka’s request object with extra Kitten-specific properties and methods.
|
|
200
|
+
*/
|
|
201
|
+
export interface KittenRequest extends PolkaRequest {
|
|
202
|
+
/**
|
|
203
|
+
The raw body of non-multipart requests. Used, for example, for validation webhook signatures.
|
|
204
|
+
*/
|
|
205
|
+
rawBody: Buffer
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
Check if the incoming request contains the `"Content-Type"` header field, and, if so, if it contains the specified mime `type`.
|
|
209
|
+
|
|
210
|
+
Examples:
|
|
211
|
+
|
|
212
|
+
// With Content-Type: text/html; charset=utf-8
|
|
213
|
+
req.is('html');
|
|
214
|
+
req.is('text/html');
|
|
215
|
+
req.is('text/*');
|
|
216
|
+
// => true
|
|
217
|
+
|
|
218
|
+
// When Content-Type is application/json
|
|
219
|
+
req.is('json');
|
|
220
|
+
req.is('application/json');
|
|
221
|
+
req.is('application/*');
|
|
222
|
+
// => true
|
|
223
|
+
req.is('html');
|
|
224
|
+
// => false
|
|
225
|
+
|
|
226
|
+
@link https://github.com/expressjs/express/blob/master/lib/request.js#L231
|
|
227
|
+
*/
|
|
228
|
+
is (types:Array<string>|string):string|false|null
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
Represents a browser session.
|
|
232
|
+
|
|
233
|
+
Sessions are automatically persisted (and expired) in Kitten’s internal database.
|
|
234
|
+
|
|
235
|
+
Used by Kitten to provide automatic authentication for Small Web places.
|
|
236
|
+
|
|
237
|
+
You can also add/update arbitrary session data by adding/updating properties on this object in your routes (this object maps a session object in the `kitten._db.sessions` table in the internal database).
|
|
238
|
+
|
|
239
|
+
You can emit events on a session in order to communicate with other browser tabs and windows that share the same session.
|
|
240
|
+
|
|
241
|
+
@example
|
|
242
|
+
export default function ({ request }) {
|
|
243
|
+
request.session.kittens ??= { count: 1 }
|
|
244
|
+
|
|
245
|
+
return kitten.html`
|
|
246
|
+
<h1>Kitten count</h1>
|
|
247
|
+
<p>${'🐱️'.repeat(request.session.kittens.count++)}</p>
|
|
248
|
+
`
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
@see https://kitten.small-web.org/tutorials/sessions/
|
|
252
|
+
|
|
253
|
+
@remarks
|
|
254
|
+
Do not save custom classes on request.session or JSDB will throw an error when it tries to open the internal `_db` database and cannot find your custom class to instantiate.
|
|
255
|
+
|
|
256
|
+
If you want persisted session-level custom objects, store them in your own database table in `kitten.db` keyed by `session.id`.
|
|
257
|
+
*/
|
|
258
|
+
session: Session & {
|
|
259
|
+
[key: string]: any
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
type TypedArray = Int8Array|Uint8Array|Uint8ClampedArray|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array|BigInt64Array|BigUint64Array
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
The response objects received by Kitten routes.
|
|
267
|
+
|
|
268
|
+
Based on Polka’s response object with extra Kitten-specific properties and methods.
|
|
269
|
+
*/
|
|
270
|
+
export interface KittenResponse extends PolkaResponse {
|
|
271
|
+
/**
|
|
272
|
+
JSON.stringifies passed data and ends response with inline JSON using proper headers.
|
|
273
|
+
*/
|
|
274
|
+
json (data:any):void
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
JSON.stringifies passed data and ends response with JSON attachment using proper headers and requested file name (or data.json as fallback if no file name is provided).
|
|
278
|
+
*/
|
|
279
|
+
jsonFile (data:any, fileName?:string):void
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
Ends response with a file. Optionally, uses passed file name (or `'download'` as fallback) and passed mime type (or `'application/octet-stream'` as fallback).
|
|
283
|
+
*/
|
|
284
|
+
file (data:string|Buffer|TypedArray|DataView, fileName?:string, mimeType?:string):void
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
Ends response with 200 OK response code, and the response body, if any (and `''` if not).
|
|
288
|
+
|
|
289
|
+
@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/200
|
|
290
|
+
*/
|
|
291
|
+
ok (body?:string):void
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
Ends response with 201 Created response code, and the response body, if any (and `''` if not).
|
|
295
|
+
|
|
296
|
+
@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/201
|
|
297
|
+
*/
|
|
298
|
+
created (body?:string):void
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
Ends response with redirect via a GET request (303 See Other) to given location.
|
|
302
|
+
|
|
303
|
+
Alias: seeOther
|
|
304
|
+
*/
|
|
305
|
+
get (location:string):void
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
Alias for {@link get}.
|
|
309
|
+
*/
|
|
310
|
+
seeOther (location:string):void
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
Redirect (temporary; 307) to requested location without changing the request method.
|
|
314
|
+
*/
|
|
315
|
+
redirect (location:string):void
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
Alias for {@link redirect}.
|
|
319
|
+
*/
|
|
320
|
+
temporaryRedirect (location:string):void
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
Redirect (permanentl 308) to requested location without changing the request method.
|
|
324
|
+
*/
|
|
325
|
+
permanentRedirect (location:string):void
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
400 Bad Request
|
|
329
|
+
|
|
330
|
+
Indicates that the server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
|
|
331
|
+
|
|
332
|
+
@link https://httpwg.org/specs/rfc9110.html#rfc.section.15.5.1
|
|
333
|
+
*/
|
|
334
|
+
badRequest (body?:string):void
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
“401 Unauthorized” (actually, unauthenticated) response.
|
|
338
|
+
|
|
339
|
+
Aliases: unauthorised, unauthorized.
|
|
340
|
+
*/
|
|
341
|
+
unauthenticated (body?:string):void
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
Alias for {@link unauthenticated}.
|
|
345
|
+
*/
|
|
346
|
+
unauthorised (body?:string):void
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
Alias for {@link unauthenticated}.
|
|
350
|
+
*/
|
|
351
|
+
unauthorized (body?:string):void
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
403 Forbidden response. This should be returned if the request is authenticated but lacks the authorisation (i.e., sufficient rights) to access the resource.
|
|
355
|
+
|
|
356
|
+
If the request requires authentication but has not been authenticated, you should return a “401 Unauthorized” (actually: unauthenticated) response.
|
|
357
|
+
|
|
358
|
+
@see unauthenticated
|
|
359
|
+
*/
|
|
360
|
+
forbidden (body?:string):void
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
404 Not Found response.
|
|
364
|
+
*/
|
|
365
|
+
notFound (body?:string):void
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
500 Internal Server Error response.
|
|
369
|
+
|
|
370
|
+
Alias: internalServerError.
|
|
371
|
+
*/
|
|
372
|
+
error (body?:string):void
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
Alias for {@link error}.
|
|
376
|
+
*/
|
|
377
|
+
internalServerError (body?:string):void
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
General shorthand helper for setting the status code and ending the response with an optional body.
|
|
381
|
+
*/
|
|
382
|
+
withCode (statusCode:number, body?:string):void
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
The signature of Kitten route handlers and middleware.
|
|
387
|
+
|
|
388
|
+
Like polka’s own `Middleware` type but with Kitten’s request and response
|
|
389
|
+
objects (Kitten’s middleware mixes the helper methods into every request
|
|
390
|
+
and response before any route handler runs).
|
|
391
|
+
*/
|
|
392
|
+
export type KittenHandler = (
|
|
393
|
+
request: KittenRequest,
|
|
394
|
+
response: KittenResponse,
|
|
395
|
+
next: polka.NextHandler
|
|
396
|
+
) => void | Promise<void>
|
|
397
|
+
|
|
398
|
+
type RoutePattern = RegExp | string
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
The Kitten server’s polka app.
|
|
402
|
+
|
|
403
|
+
A polka instance whose handlers receive Kitten’s request and response objects.
|
|
404
|
+
*/
|
|
405
|
+
export interface KittenPolka extends Omit<
|
|
406
|
+
Polka,
|
|
407
|
+
'find' | 'add' | 'use' | 'all' | 'get' | 'head' | 'patch' | 'options'
|
|
408
|
+
| 'connect' | 'delete' | 'trace' | 'post' | 'put'
|
|
409
|
+
| 'wares' | 'onError' | 'onNoMatch' | 'handler'
|
|
410
|
+
> {
|
|
411
|
+
handler: KittenHandler
|
|
412
|
+
find(method: string, url: string): {
|
|
413
|
+
params: Record<string, string>
|
|
414
|
+
handlers: KittenHandler[]
|
|
415
|
+
}
|
|
416
|
+
add(method: string, pattern: RoutePattern, ...handlers: KittenHandler[]): this
|
|
417
|
+
use(pattern: RoutePattern, ...handlers: (KittenPolka | KittenHandler)[]): this
|
|
418
|
+
use(...handlers: (KittenPolka | KittenHandler)[]): this
|
|
419
|
+
all(pattern: RoutePattern, ...handlers: KittenHandler[]): this
|
|
420
|
+
get(pattern: RoutePattern, ...handlers: KittenHandler[]): this
|
|
421
|
+
head(pattern: RoutePattern, ...handlers: KittenHandler[]): this
|
|
422
|
+
patch(pattern: RoutePattern, ...handlers: KittenHandler[]): this
|
|
423
|
+
options(pattern: RoutePattern, ...handlers: KittenHandler[]): this
|
|
424
|
+
connect(pattern: RoutePattern, ...handlers: KittenHandler[]): this
|
|
425
|
+
delete(pattern: RoutePattern, ...handlers: KittenHandler[]): this
|
|
426
|
+
trace(pattern: RoutePattern, ...handlers: KittenHandler[]): this
|
|
427
|
+
post(pattern: RoutePattern, ...handlers: KittenHandler[]): this
|
|
428
|
+
put(pattern: RoutePattern, ...handlers: KittenHandler[]): this
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
Kitten’s POST request object.
|
|
433
|
+
|
|
434
|
+
If the POST route had a multi-part form with file uploads, they will be handled automatically by Kitten and you can find them in the `uploads` property.
|
|
435
|
+
|
|
436
|
+
@see https://kitten.small-web.org/tutorials/multipart-forms-and-file-uploads/
|
|
437
|
+
*/
|
|
438
|
+
export interface KittenPostRequest extends KittenRequest {
|
|
439
|
+
uploads: Upload[]
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/* Crypto */
|
|
443
|
+
|
|
444
|
+
type Hex = Uint8Array | string;
|
|
445
|
+
type PrivKey = Hex | bigint | number;
|
|
446
|
+
|
|
447
|
+
export class Point {
|
|
448
|
+
readonly x: bigint;
|
|
449
|
+
readonly y: bigint;
|
|
450
|
+
static BASE: Point;
|
|
451
|
+
static ZERO: Point;
|
|
452
|
+
_WINDOW_SIZE?: number;
|
|
453
|
+
constructor(x: bigint, y: bigint);
|
|
454
|
+
_setWindowSize(windowSize: number): void;
|
|
455
|
+
static fromHex(hex: Hex, strict?: boolean): Point;
|
|
456
|
+
static fromPrivateKey(privateKey: PrivKey): Promise<Point>;
|
|
457
|
+
toRawBytes(): Uint8Array;
|
|
458
|
+
toHex(): string;
|
|
459
|
+
toX25519(): Uint8Array;
|
|
460
|
+
isTorsionFree(): boolean;
|
|
461
|
+
equals(other: Point): boolean;
|
|
462
|
+
negate(): Point;
|
|
463
|
+
add(other: Point): Point;
|
|
464
|
+
subtract(other: Point): Point;
|
|
465
|
+
multiply(scalar: number | bigint): Point;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
export class Signature {
|
|
469
|
+
readonly r: Point;
|
|
470
|
+
readonly s: bigint;
|
|
471
|
+
constructor(r: Point, s: bigint);
|
|
472
|
+
static fromHex(hex: Hex): Signature;
|
|
473
|
+
assertValidity(): this;
|
|
474
|
+
toRawBytes(): Uint8Array;
|
|
475
|
+
toHex(): string;
|
|
476
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
These are third-party libraries used in Kitten that do not have static type information in their module or in the centralised @types package.
|
|
3
|
+
|
|
4
|
+
To remove type warnings at author time, they are declared here and added to `typeRoots` in jsconfig.js.
|
|
5
|
+
|
|
6
|
+
(Longer term, it would be nice to contribute type information for these libraries with the eventual goal of removing this file from the project.)
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// JSDB
|
|
10
|
+
declare module '@small-tech/jsdb'
|
|
11
|
+
|
|
12
|
+
// Middleware and helpers without bundled or @types declarations.
|
|
13
|
+
declare module 'cors'
|
|
14
|
+
declare module 'hsts'
|
|
15
|
+
declare module 'type-is'
|
|
16
|
+
declare module 'cookie'
|
|
17
|
+
declare module 'uid-safe'
|
|
18
|
+
declare module 'tcp-port-used'
|
|
19
|
+
declare module 'serve-static'
|
|
20
|
+
declare module 'connect-static-file'
|
|
21
|
+
declare module 'tail-file'
|
|
22
|
+
declare module 'sanitize-html'
|
|
23
|
+
declare module 'simply-beautiful'
|
|
24
|
+
declare module 'prismjs'
|
|
25
|
+
declare module 'js-beautify'
|
|
26
|
+
declare module 'path-complete-extname'
|
|
27
|
+
declare module '@small-tech/attribute-parser'
|
|
28
|
+
|
|
29
|
+
// Markdown-it plugins (used in src/lib/html.js)
|
|
30
|
+
declare module 'markdown-it-footnote'
|
|
31
|
+
declare module 'markdown-it-image-figures'
|
|
32
|
+
declare module 'markdown-it-ins'
|
|
33
|
+
declare module 'markdown-it-bracketed-spans'
|
|
34
|
+
declare module 'markdown-it-mark'
|
|
35
|
+
declare module 'markdown-it-sub'
|
|
36
|
+
declare module 'markdown-it-sup'
|
|
37
|
+
declare module 'markdown-it-task-checkbox'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@small-web/kitten-types",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Types-only package for Kitten: declares global `kitten` namespace and exports Kitten types.",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -8,9 +8,7 @@
|
|
|
8
8
|
"global.d.ts",
|
|
9
9
|
"fragments.d.ts",
|
|
10
10
|
"types.d.ts",
|
|
11
|
-
"
|
|
12
|
-
"slugify/index.d.ts",
|
|
13
|
-
"ws/index.d.ts"
|
|
11
|
+
"kitten"
|
|
14
12
|
],
|
|
15
13
|
"exports": {
|
|
16
14
|
".": {
|
|
@@ -57,10 +55,23 @@
|
|
|
57
55
|
"@types/node": ">=24"
|
|
58
56
|
},
|
|
59
57
|
"dependencies": {
|
|
58
|
+
"@noble/ed25519": "^1.7.5",
|
|
59
|
+
"@noble/hashes": "^1.1.5",
|
|
60
|
+
"@sindresorhus/slugify": "^2.2.1",
|
|
60
61
|
"@small-tech/auto-encrypt": "^5.1.0",
|
|
61
62
|
"@small-tech/auto-encrypt-localhost": "^10.0.0",
|
|
62
63
|
"@types/markdown-it": "^14.1.2",
|
|
63
64
|
"@types/node": ">=24",
|
|
64
|
-
"
|
|
65
|
+
"@types/ws": "^8.18.1",
|
|
66
|
+
"ed25519-keygen": "^0.2.4",
|
|
67
|
+
"kitten-icons": "^4.1.0",
|
|
68
|
+
"micro-aes-gcm": "^0.3.3",
|
|
69
|
+
"polka": "^1.0.0-next.25",
|
|
70
|
+
"sade": "^1.8.1",
|
|
71
|
+
"simple-git": "^3.25.0",
|
|
72
|
+
"watcher": "^2.3.1"
|
|
73
|
+
},
|
|
74
|
+
"scripts": {
|
|
75
|
+
"typecheck": "tsc --noEmit"
|
|
65
76
|
}
|
|
66
77
|
}
|