@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.
Files changed (80) hide show
  1. package/README.md +9 -2
  2. package/fragments.d.ts +13 -14
  3. package/global.d.ts +6 -1096
  4. package/index.d.ts +7 -27
  5. package/kitten/src/AppDatabase.d.ts +10 -0
  6. package/kitten/src/AppRepository.d.ts +101 -0
  7. package/kitten/src/AutomaticUpdates.d.ts +21 -0
  8. package/kitten/src/Files.d.ts +61 -0
  9. package/kitten/src/GlobalInternalDatabase.d.ts +22 -0
  10. package/kitten/src/InternalDatabase.d.ts +7 -0
  11. package/kitten/src/REPL.d.ts +5 -0
  12. package/kitten/src/Routes.d.ts +41 -0
  13. package/kitten/src/Server.d.ts +76 -0
  14. package/kitten/src/ServerError.d.ts +6 -0
  15. package/kitten/src/Sessions.d.ts +32 -0
  16. package/kitten/src/Uploads.d.ts +20 -0
  17. package/kitten/src/Utils.d.ts +79 -0
  18. package/kitten/src/cli/commands/db.d.ts +48 -0
  19. package/kitten/src/cli/commands/deploy.d.ts +16 -0
  20. package/kitten/src/cli/commands/disable.d.ts +9 -0
  21. package/kitten/src/cli/commands/enable.d.ts +9 -0
  22. package/kitten/src/cli/commands/logs.d.ts +15 -0
  23. package/kitten/src/cli/commands/restart.d.ts +11 -0
  24. package/kitten/src/cli/commands/run.d.ts +15 -0
  25. package/kitten/src/cli/commands/serve.d.ts +13 -0
  26. package/kitten/src/cli/commands/shell.d.ts +1 -0
  27. package/kitten/src/cli/commands/start.d.ts +9 -0
  28. package/kitten/src/cli/commands/status.d.ts +15 -0
  29. package/kitten/src/cli/commands/stop.d.ts +9 -0
  30. package/kitten/src/cli/commands/uninstall.d.ts +9 -0
  31. package/kitten/src/cli/commands/update.d.ts +7 -0
  32. package/kitten/src/cli/index.d.ts +55 -0
  33. package/kitten/src/cli/lib/WarningBox.d.ts +8 -0
  34. package/kitten/src/cli/lib/header.d.ts +10 -0
  35. package/kitten/src/components/SvgSpinner.component.d.ts +9 -0
  36. package/kitten/src/lib/KittenComponent.d.ts +340 -0
  37. package/kitten/src/lib/KittenMoji.d.ts +35 -0
  38. package/kitten/src/lib/KittenPackage.d.ts +56 -0
  39. package/kitten/src/lib/KittenPage.d.ts +202 -0
  40. package/kitten/src/lib/Version.d.ts +49 -0
  41. package/kitten/src/lib/ansi-highlight-html.d.ts +5 -0
  42. package/kitten/src/lib/components/stateful/CopyButton.component.d.ts +14 -0
  43. package/kitten/src/lib/components/stateless/copyButton.component.d.ts +21 -0
  44. package/kitten/src/lib/crypto.d.ts +95 -0
  45. package/kitten/src/lib/deploy.d.ts +20 -0
  46. package/kitten/src/lib/ensure.d.ts +28 -0
  47. package/kitten/src/lib/fragments.d.ts +1 -0
  48. package/kitten/src/lib/globals.d.ts +10 -0
  49. package/kitten/src/lib/html.d.ts +61 -0
  50. package/kitten/src/lib/markdown.d.ts +16 -0
  51. package/kitten/src/lib/paths.d.ts +25 -0
  52. package/kitten/src/lib/service-status.d.ts +14 -0
  53. package/kitten/src/lib/system-exit-codes.d.ts +39 -0
  54. package/kitten/src/lib/terminal-link.d.ts +24 -0
  55. package/kitten/src/middleware/authentication.d.ts +8 -0
  56. package/kitten/src/middleware/index.d.ts +5 -0
  57. package/kitten/src/middleware/request-and-response-helpers.d.ts +6 -0
  58. package/kitten/src/middleware/request-log.d.ts +10 -0
  59. package/kitten/src/middleware/sessions.d.ts +3 -0
  60. package/kitten/src/middleware/stats.d.ts +8 -0
  61. package/kitten/src/middleware/trailing-slashes.d.ts +11 -0
  62. package/kitten/src/middleware/websocket.d.ts +14 -0
  63. package/kitten/src/routes/HttpRoute.d.ts +16 -0
  64. package/kitten/src/routes/LazilyLoadedRoute.d.ts +15 -0
  65. package/kitten/src/routes/PageRoute.d.ts +54 -0
  66. package/kitten/src/routes/PageSocketRoute.d.ts +42 -0
  67. package/kitten/src/routes/PostRoute.d.ts +64 -0
  68. package/kitten/src/routes/StaticRoute.d.ts +17 -0
  69. package/kitten/src/routes/WebSocketRoute.d.ts +21 -0
  70. package/kitten/src/routes/lib/validator.d.ts +18 -0
  71. package/kitten/src/types/fragments.d.ts +14 -0
  72. package/kitten/src/types/globals.d.ts +1239 -0
  73. package/kitten/src/types/index.d.ts +12 -0
  74. package/kitten/src/types/types.d.ts +476 -0
  75. package/kitten/third-party-libraries-with-missing-type-information/index.d.ts +37 -0
  76. package/package.json +16 -5
  77. package/types.d.ts +5 -712
  78. package/polka/index.d.ts +0 -111
  79. package/slugify/index.d.ts +0 -246
  80. /package/{ws → kitten/third-party-libraries-with-missing-type-information/ws}/index.d.ts +0 -0
package/global.d.ts CHANGED
@@ -2,1104 +2,14 @@
2
2
  Kitten Types (@small-web/kitten-types)
3
3
 
4
4
  Type declarations for global `kitten` namespace.
5
- */
6
-
7
- import type { EventEmitter } from 'node:events'
8
- import type { Server } from 'node:https'
9
- import type { AutoEncryptedServer } from '@small-tech/auto-encrypt'
10
- import type { AutoEncryptedLocalhostServer } from '@small-tech/auto-encrypt-localhost'
11
-
12
- import type {
13
- Session,
14
- Upload,
15
- KittenComponent,
16
- KittenPage,
17
- MarkdownIt,
18
- Polka,
19
- WebSocket as KittenWebSocket,
20
- slugify as Slugify,
21
- yaml as Yaml,
22
- Point,
23
- Signature
24
- } from './types.d.ts'
25
-
26
- import type { KittenIcons } from 'kitten-icons/types.d.ts'
27
-
28
- /**
29
- Tagged template function (e.g. `kitten.html`, `kitten.css`).
30
- */
31
- export type TaggedTemplate = (
32
- strings: TemplateStringsArray,
33
- ...properties: any[]
34
- ) => string | Array<string> | Promise<string | Array<string>>
35
-
36
- /**
37
- Sanitisation helper (e.g. `kitten.safelyAddHtml`, `kitten.sanitise`).
38
- */
39
- export type SanitisationFunction = (
40
- untrustedContent: string,
41
- allowedTags?: Array<string>,
42
- contact?: boolean
43
- ) => string
44
-
45
- /**
46
- Record that maps URL fragments to hit counts.
47
- */
48
- type StatsObject = Record<string, number>
49
-
50
- /**
51
- Internal Kitten database (`kitten._db`).
52
- */
53
- export interface KittenInternalDatabase {
54
- sessions: Record<string, Session>
55
- settings: {
56
- autoUpdate: {
57
- interval: number
58
- }
59
- domainToken: string
60
- domainRedirects: Record<string, string>
61
- evergreenWebUrl: string
62
- hideWelcomeMessage: boolean
63
- id: {
64
- ed25519: {
65
- asString: string
66
- }
67
- ssh: {
68
- asString: string
69
- fingerprint: string
70
- }
71
- }
72
- packageLockFileHashes: Record<string, string>
73
- path: string
74
- smallWebHostDomain: string
75
- stats: {
76
- hits: StatsObject
77
- pages: StatsObject
78
- missing: StatsObject
79
- referrers: StatsObject
80
- serverErrors: StatsObject
81
- }
82
- webhookSecret: string
83
- }
84
- uploads: UploadStore,
85
- scheduledRestart: {
86
- lastRestartDate: number
87
- restartHour: number
88
- }
89
- }
90
5
 
91
- /**
92
- The `kitten.uploads` store.
93
- */
94
- export type UploadStore = {
95
- get(id: string): Upload
96
- length(): number
97
- all(): Upload[]
98
- allIds(): string[]
99
- delete(id: string): Promise<void>
100
- } & Record<string, Upload>
101
-
102
- /**
103
- Configuration options for the Kitten server.
104
- */
105
- interface ServerOptions {
106
- domain?: string
107
- port?: number
108
- aliases?: string
109
- open?: boolean
110
- 'working-directory'?: string
111
- 'domain-token'?: string
112
- 'small-web-host-domain'?: string
113
- }
114
-
115
- type UpdateType = 'upgrade' | 'downgrade' | 'updating' | 'restarting'
6
+ Generated from Kitten’s TypeScript source code
7
+ (see kitten/ – regenerated via `npm run sync-types` in the Kitten repository).
116
8
 
117
- /**
118
- Global `kitten` namespace.
9
+ Side-effect: Brings `declare global { var kitten }` into scope.
119
10
  */
120
- export interface kitten {
121
- /**
122
- Kitten’s version number and releated utilities.
123
- */
124
- version: {
125
- date: Date
126
- versionStamp: number
127
- gitHash: string
128
- apiVersion: number
129
- nodeVersion: string
130
- exactVersion: string
131
- birthday: string
132
- starSign: string
133
- Component: () => Function
134
- html: () => string
135
- printToConsole: () => void
136
- }
137
-
138
- /**
139
- The Kitten app.
140
-
141
- Includes references to the Kitten router (Polka) and server as well as the Kitten package (in deployed servers).
142
- */
143
- app: {
144
- /** The parsed package.json file for the current Kitten app (if any). */
145
- package?: any
146
- router: Polka<any>
147
- server: Server | AutoEncryptedServer | AutoEncryptedLocalhostServer
148
- }
149
-
150
- /**
151
- This is your custom JSDB database.
152
-
153
- If you want type safety for it, create a database app module in your project and declare the types there.
154
-
155
- @see https://codeberg.org/kitten/app#database-app-module
156
- */
157
- db: any
158
-
159
- /**
160
- Kitten’s internal database.
161
-
162
- You should not need to access this directly.
163
- */
164
- _db: KittenInternalDatabase
165
-
166
- /**
167
- Represents an uploaded file.
168
-
169
- @see https://kitten.small-web.org/tutorials/multipart-forms-and-file-uploads/
170
- */
171
- Upload: typeof Upload
172
-
173
- /**
174
- Uploads sent to `POST` routes via `<input type='file'>` in your pages are automatically saved in your project’s uploads folder. Kitten also automatically assigns them unique IDs, maps to IDs to their locations on disk in its internal database (`kitten._db.uploads`), and serves them from the `/uploads/<unique-id>` route.
175
-
176
- You can access uploads by ID from this global reference (which, itself, is simply a reference to `kitten._db.uploads`).
177
-
178
- The Upload objects are also available to your `POST` routes in the `request.uploads` array.
179
-
180
- @see https://kitten.small-web.org/tutorials/multipart-forms-and-file-uploads/
181
- */
182
- uploads: UploadStore
183
-
184
- /**
185
- Kitten’s built-in icon set.
186
-
187
- A subset of the Phosphor icon set by Helena Zhang and Tobias Fried as Kitten components.
188
-
189
- @example
190
- export default () => kitten.html`
191
- <h1>I’m a cat! <${kitten.icons.Cat} /></h1>
192
- `
193
-
194
- @see
195
- https://kitten.small-web.org/reference/#icons
196
- */
197
- icons: KittenIcons
198
-
199
- /**
200
- The domain or Web Number (IP Address) Kitten is running at.
201
- */
202
- domain: string
203
-
204
- /**
205
- The port number Kitten is running at.
206
- */
207
- port: number
208
-
209
- /**
210
- The unique identifier for this Kitten site/app, calculated using the base path of the source code as well as the domain and port the server is running on.
211
- */
212
- projectIdentifier: string
213
-
214
- /**
215
- Represents the git repository of the app that Kitten is currently serving.
216
-
217
- Available in production mode only (when Kitten is run with PRODUCTION=true).
218
-
219
- @remarks For internal use only.
220
- */
221
- appRepository?: {
222
- latestCompatibleVersion?: string,
223
- latestVersion?: string,
224
- latestApiVersion?: number,
225
- manualUpdateAvailable?: boolean,
226
- originRemoteUrl?: string,
227
- currentVersion?: string,
228
- latestAvailableCommit?: string,
229
- upgradeAppToLatestCompatibleVersion(): Promise<void>
230
- upgradeAppToLatestAvailableCommit(): Promise<void>
231
- updateAppToVersion(versionTag: string): Promise<void>
232
- update(): Promise<void>
233
- hasCompatibleAppVersion: boolean
234
- canBeUpgraded: boolean
235
- hasNewerApiVersion: boolean
236
- upgradeOrDowngrade(versionTag: string, lowercase: boolean): 'upgrade' | 'Upgrade' | 'downgrade' | 'Downgrade' | false
237
- isEqualToVersion(versionTag: string): boolean
238
-
239
- /** Returns a configured update button component. */
240
- UpdateButtonComponent(): ({type, version, small}: { type?: UpdateType, version?: string, small?: boolean }) => ReturnType<TaggedTemplate>
241
-
242
- VersionComponent ({version, compatible, brief}: { version: string, compatible: boolean, brief: boolean}): ReturnType<TaggedTemplate>
243
-
244
- /** Returns a configured Current app version component. */
245
- CurrentAppVersionComponent(): () => ReturnType<TaggedTemplate>
246
-
247
- /** Returns a configured All available versions component or kitten.html (it probably shouoldn’t be doing that). */
248
- AllAvailableVersionsComponent(): (() => ReturnType<TaggedTemplate>) | ReturnType<TaggedTemplate>
249
- displayAppVersion(): void
250
- }
251
-
252
- /**
253
- Schedules and runs automatic updates of both Kitten itself and the app that Kitten is running.
254
-
255
- Available in production mode only (when Kitten is run with PRODUCTION=true).
256
-
257
- @remarks For internal use only.
258
- */
259
- automaticUpdates?: {
260
- interval: number
261
- intervalInHours: number
262
- timeToNextCheck(): number
263
- timeToNextCheckPretty(): string | number
264
- start(): void
265
- checkForUpdates(): Promise<void>
266
- stop(): void
267
- }
268
-
269
- /**
270
- Represents the currently-installed Kitten package.
271
-
272
- Provides information about and manages updates of the package by communicating with Kitten’s deployment site (https://kittens.small-web.org).
273
-
274
- _Note that this class does NOT manage automatic updates. For that, please see the {@link AutomaticUpdates} class._
275
-
276
- @remarks For internal use only.
277
- */
278
- package: {
279
- hasCompatibleVersion: boolean
280
- isLatestReleaseVersion: boolean
281
- isMoreRecentThanReleaseVersion: boolean
282
- canBeUpgraded: boolean
283
- upgrade(apiVersion?: number): void
284
- update(): Promise<void>,
285
- latestRecommendedVersion?: {
286
- versionStamp: number,
287
- gitHash: string,
288
- apiVersion: number,
289
- nodeVersion: string,
290
- exactVersion: string,
291
- buildDate: Date,
292
- releaseDate: Date,
293
- upload: Upload,
294
- _buildDate:string,
295
- _releaseDate:string
296
- }
297
- }
298
-
299
- /**
300
- A truncated log of the last 25 request URLs for debugging purposes.
301
- */
302
- requests: Array<string>
303
-
304
- /**
305
- Record of all active KittenPage instances, keyed by page ID (UUID).
306
- */
307
- pages: Record<string, KittenPage>
308
-
309
- /**
310
- Global Kitten event emitter.
311
- */
312
- events: EventEmitter
313
-
314
- /**
315
- KittenComponent class.
316
-
317
- Extend this class to create your own stateful Kitten components.
318
-
319
- @example
320
- export default class MyComponent extends kitten.Component {
321
- override html () {
322
- return kitten.html`
323
- What a lovely component I am! :)
324
- `
325
- }
326
- }
327
- */
328
- Component: typeof KittenComponent
329
-
330
- /**
331
- KittenPage class.
332
-
333
- Extend this class to create your custom stateful Kitten pages.
334
-
335
- @example
336
- export default class MyPage extends kitten.Page {
337
- override html () {
338
- return kitten.html`
339
- I am a KittenPage, short and sweet!
340
- `
341
- }
342
- }
343
- */
344
- Page: typeof KittenPage
345
-
346
- /**
347
- Kitten HTML tagged template string with support for Kitten components and JavaScript string interpolation.
348
-
349
- This is the primary means of authoring HTML in Kitten.
350
-
351
- @example
352
- // A simple Kitten page (e.g., index.page.js) that says “Happy <month name>!” and uses the built-in kitten.icons.Smiley Kitten component to display a smiley.
353
- export default function () {
354
- const currentMonth = new Intl.DateTimeFormat('en-IE', { month: 'long' }).format(new Date())
355
- return kitten.html`
356
- <h1>Happy ${currentMonth}! <${kitten.icons.Smiley} /></h1>
357
- `
358
- }
359
-
360
- @see https://kitten.small-web.org/reference/#html
361
- */
362
- html: TaggedTemplate
363
-
364
- /**
365
- CSS tagged template.
366
-
367
- Wraps passed string in `<style>…</style>` tags.
368
-
369
- Useful if you want to use JavaScript variables in your CSS.
370
-
371
- @example
372
- const randomColour = ['red', 'green', 'blue'][Math.floor(Math.random()*3)]
373
- const css = kitten.css`body { background-color: ${randomColour} }`
374
-
375
- @see To include external static CSS, use CSS fragments (_.fragment.css_ files) instead. https://kitten.small-web.org/tutorials/components-and-fragments/#html-css-and-markdown-fragments
376
- */
377
- css: TaggedTemplate
378
-
379
- /**
380
- JS tagged template. This is a basic function that simply attaches its input to the page
381
- without any escaping. It can be used to get language intelligence/syntax highlighting
382
- for Alpine.js snippets in your editor (if your editor and/or language server understands
383
- to display kitten.js`` tagged templates as JavaScript).
384
-
385
- Be careful if using this as you will have to escape backticks in your code and it
386
- can make your code harder to read and understand for other people.
387
-
388
- Use for simple things only.
389
-
390
- @param {string[]} strings - Static strings.
391
- @param {[]} interpolations - Interpolated values.
392
- */
393
- js: TaggedTemplate
394
-
395
- /**
396
- Markdown wrapper.
397
-
398
- Results in exactly the same thing as `` kitten.html`<markdown>…</markdown>` `` but without
399
- requiring you to add the markdown tags. In a lot of ways more limited than just
400
- using ``` kitten.html`` ``` with markdown tags inside it but might be nicer semantically in
401
- certain cases.
402
-
403
- @see https://kitten.small-web.org/reference/#markdown-support
404
- */
405
- markdown: TaggedTemplate
406
-
407
- /**
408
- Reference to the MarkdownIt instance used internally by Kitten.
409
-
410
- Use `kitten.md.render()` and `kitten.md.renderInline()` if you need more flexibility than what the other Markdown features in Kitten allow.
411
-
412
- @example
413
- <!-- Safely display comments on a blog that contain Markdown syntax. -->
414
- <ul>
415
- ${kitten.db.comments.map(comment => kitten.html`
416
- <li>
417
- <p>${kitten.safelyAddHtml(kitten.md.render(comment.message))}</p>
418
- <p class='nameAndDate'>${comment.name} (${new Date(comment.date).toLocaleString()})</p>
419
- </li>
420
- `)}
421
- </ul>
422
- */
423
- md: MarkdownIt
424
-
425
- /**
426
- Slugify a string.
427
-
428
- @example
429
- kitten.slugify('I ♥ Dogs') // i-love-dogs
430
-
431
- @see https://github.com/sindresorhus/slugify
432
- */
433
- slugify: typeof Slugify
434
-
435
- /**
436
- YAML parser and serialiser.
437
-
438
- Used internally by the Markdown loader for parsing YAML frontmatter but also exposed here for you to use in your own apps.
439
-
440
- @example
441
- kitten.yaml.parse(`
442
- YAML:
443
- - A human-readable data serialization language
444
- - https://en.wikipedia.org/wiki/YAML
445
- `)
446
-
447
- @see https://github.com/eemeli/yaml
448
- */
449
- yaml: typeof Yaml
450
-
451
- /**
452
- Kitten Crypto API
453
-
454
- Crypographic functions used by Kitten and available for you to use in your own apps.
455
-
456
- Remember that secrets that belong to people should only be handled on the client. The exact same API is available to use in the browser.
457
-
458
- @example
459
- // Client side use
460
- <script type='module' async>
461
- import { createKeys } from '/🐱/library/crypto-1.js'
462
-
463
- async function generateSecret(event, secretView, copySecretButtonPlaceholder) {
464
- const keys = await createKeys('${domain}')
465
- const secret = keys.private.ed25519.asString
466
- }
467
- </script>
468
- */
469
- crypto: {
470
- /**
471
- Converts Uint8Array to hex string.
472
-
473
- From @noble/hashes.
474
-
475
- @see https://github.com/paulmillr/noble-hashes#utils
476
- */
477
- bytesToHex: (uint8a: Uint8Array) => string
478
-
479
- /**
480
- Decrypts passed encoded ciphertext using shared key.
481
-
482
- From micro-aes-gcm.
483
-
484
- @see https://www.npmjs.com/package/micro-aes-gcm
485
- */
486
- decrypt: (sharedKey: Uint8Array, encoded: string | Uint8Array) => Uint8Array
487
-
488
- /**
489
- Convert emoji string to secret bytes.
490
-
491
- @see https://kitten.small-web.org/reference/#cryptographic-properties
492
- */
493
- emojiStringToSecret: (emojiString: string) => Uint8Array
494
-
495
- /**
496
- Encrypts passed plain text using the shared key.
497
-
498
- From micro-aes-gcm.
499
-
500
- @see https://www.npmjs.com/package/micro-aes-gcm
501
- */
502
- encrypt: (sharedKey: Uint8Array, plaintext: string | Uint8Array) => Uint8Array
503
-
504
- /**
505
- Encrypts a message for a domain.
506
-
507
- @param message Message to encrypt
508
- @param ourPrivateKey Our emoji-encoded private key
509
- @param domain The domain to encrypt the message for
510
- @returns Hex-encoded encrypted message.
511
-
512
- @remarks While this function can be used on the server, all encryption should be carried out on the client as the server should never have person’s secrets.
513
- */
514
- encryptMessageForDomain: (message: string, ourPrivateKey: string, domain: string) => Promise<string>
515
-
516
- /**
517
- Converts ed25519 private / public keys to Curve25519 and calculates Elliptic Curve Diffie Hellman (ECDH) with X25519. Conforms to RFC7748.
518
-
519
- From `@noble/ed25519` (v1).
520
-
521
- @see https://github.com/paulmillr/noble-ed25519/tree/v1#getsharedsecretprivatekey-publickey
522
- */
523
- getSharedSecret: (
524
- privateKey: Uint8Array | string | bigint | number,
525
- publicKey: Uint8Array | string
526
- ) => Promise<Uint8Array>
527
-
528
- /**
529
- Converts hex string to Uint8Array .
530
-
531
- From `@noble/hashes`.
532
-
533
- @see https://github.com/paulmillr/noble-hashes#usage
534
- */
535
- hexToBytes: (hex: string) => Uint8Array
536
-
537
- /**
538
- Produces cryptographically secure random Uint8Array of length bytes.
539
-
540
- From `@noble/hashes`.
541
-
542
- @see https://github.com/paulmillr/noble-hashes#utils
543
- */
544
- randomBytes: (bytesLength?: number) => Uint8Array
545
-
546
- /**
547
- Generates cryptographically random 32-byte token and coverts it to hexadecimal representation.
548
-
549
- Use anywhere you need a secret token (domain token, webhook secret, etc.)
550
- */
551
- random32ByteTokenInHex: () => string
552
-
553
- /**
554
- Convert secret bytes to emoji string.
555
-
556
- @see https://kitten.small-web.org/reference/#cryptographic-properties
557
- */
558
- secretToEmojiString: (secret: Uint8Array) => string
559
-
560
- /**
561
- Calculates the shared secret for a domain using the domain’s public key and our private key.
562
-
563
- Part of the Meow Protocol.
564
- */
565
- sharedSecretForDomain: (domain: string, ourPrivateKey: string) => Promise<Uint8Array>
566
-
567
- /**
568
- Signs message with privatek key and returns EdDSA signature.
569
-
570
- From `@noble/ed25519` (v1).
571
-
572
- @param message Message (not message hash) which would be signed
573
- @param privateKey Private key which will sign the hash
574
- @returns EdDSA signature. You can consume it with the `Signature.fromHex()` method: `Signature.fromHex(ed25519.sign(hash, privateKey))`
575
-
576
- @see https://github.com/paulmillr/noble-ed25519/tree/v1#signmessage-privatekey
577
- */
578
- sign: (message: Uint8Array | string, privateKey: Uint8Array | string) => Promise<Uint8Array>
579
-
580
- /**
581
- Verifies signature.
582
-
583
- From `@noble/ed25519` (v1).
584
-
585
- Compatible with [ZIP215](https://zips.z.cash/zip-0215), accepts:
586
-
587
- ```
588
- 0 <= sig.R/publicKey < 2**256 (can be >= curve.P aka non-canonical encoding)
589
- 0 <= sig.s < l
590
- ```
591
-
592
- @param sig Signature returned by {@link sign} function
593
- @param message Message to be verified
594
- @param publicKey Public key (e.g., as generated from privateKey using it’s getPublicKey method)
595
-
596
- @see https://github.com/paulmillr/noble-ed25519/tree/v1#verifysignature-message-publickey
597
-
598
- @remarks Not compatible with RFC8032 because rfc encorces canonical encoding of R/publicKey. There is no security risk in ZIP behavior, and there is no effect on honestly generated signatures. For additional info about verification strictness, check out It’s [255:19AM](https://hdevalence.ca/blog/2020-10-04-its-25519am/).
599
- */
600
- verify: (
601
- sig: Uint8Array | string | Signature,
602
- message: Uint8Array | string,
603
- publicKey: Uint8Array | string | Point
604
- ) => Promise<boolean>
605
- }
606
-
607
- /**
608
- Kitten utility functions and properties.
609
- */
610
- utils: {
611
- /**
612
- Currently contains the same extensions as in {@link DYNAMIC_ROUTE_EXTENSIONS}.
613
- */
614
- ALL_ROUTE_EXTENSIONS: Array<string>
615
-
616
- /**
617
- Extensions that Kitten treats as backend routes.
618
-
619
- Currently: `socket.js` and `socket.ts`.
620
-
621
- @see https://kitten.small-web.org/tutorials/htmx-the-htmx-web-socket-extension-and-socket-routes/
622
- */
623
- BACKEND_EXTENSIONS: Array<string>
624
-
625
- /**
626
- Extensions that don’t map to routes but are elements that can be imported and used in routes.
627
-
628
- @example
629
- `component.js`, `component.ts`, `fragment.html`, `fragment.css`, `layout.js`, `layout.ts`
630
-
631
- @see https://kitten.small-web.org/tutorials/components-and-fragments/
632
- */
633
- DEPENDENCY_EXTENSIONS: Array<string>
634
-
635
- /**
636
- File extensions Kitten considers to be dynamic (not static) routes.
637
-
638
- Currently, this includes all extensions in {@link BACKEND_EXTENSIONS} and {@link FRONTEND_EXTENSIONS}.
639
- */
640
- DYNAMIC_ROUTE_EXTENSIONS: Array<string>
641
-
642
- /**
643
- Extensions for files that hold front-end functionality.
644
-
645
- Currently: `page.js`, `page.ts`, and `page.md`.
646
-
647
- @remarks For internal use only.
648
- */
649
- FRONTEND_EXTENSIONS: Array<string>
650
-
651
- /**
652
- Extensions Kitten maps to standard HTTP routes.
653
-
654
- @example
655
- `get.js`, `post.js`, `put.js`, `head.js`, etc.
656
-
657
- @see https://kitten.small-web.org/reference/#http-routes
658
-
659
- @remarks For internal use only.
660
- */
661
- HTTP_METHODS: Array<string>
662
-
663
- /**
664
- File extensions that that Kitten treats as static files.
665
-
666
- Currently: `html` and `htm`.
667
-
668
- @see https://kitten.small-web.org/tutorials/static-html/
669
-
670
- @remarks For internal use only.
671
- */
672
- STATIC_ROUTE_EXTENSIONS: Array<string>
673
-
674
- /**
675
- Given a file path, derives the unique class name for its route.
676
-
677
- @remarks For internal use only.
678
- */
679
- classNameFromFilePath: (filePath: string, basePath: string) => string
680
-
681
- /**
682
- Converts a route in the form of, e.g., `'/some_thing/with/underscores-and-hyphens'` to `'SomeThingWithUnderscoresAndHyphensPage'`.
683
-
684
- @remarks For internal use only.
685
- */
686
- classNameFromRoutePattern: (pattern: string) => string
687
-
688
- /**
689
- db namespace for JSDB database-related utility functions.
690
- */
691
- db: {
692
- /**
693
- Given a JSDB change string, returns the dot-separated keypath of the changed property.
694
- */
695
- keypathForChange(change: string): string
696
- }
697
-
698
- /**
699
- Inverse of encodeFilePath. Used when we want to avoid double escaping of file paths.
700
- */
701
- decodeFilePath: (filePath: string) => string
702
-
703
- /**
704
- Since Polka does not handle unicode in paths correctly (see https://github.com/lukeed/polka/issues/187), we have to split the file path and URI encode each component ourselves.
705
- */
706
- encodeFilePath: (filePath: string) => string
707
-
708
- /**
709
- Display error in console and exit process.
710
-
711
- @remarks For internal use only.
712
- */
713
- exitWithError: (message: string) => void
714
-
715
- /**
716
- Routes sorted by category based on their extensions (e.g., .page.js, post.js, etc.)
717
-
718
- Routes in the different categories are served differently by Kitten.
719
-
720
- @see https://kitten.small-web.org/reference/#valid-file-types
721
-
722
- @remarks For internal use only.
723
- */
724
- extensionCategories: {
725
- backendRoutes: Array<string>
726
- frontendRoutes: Array<string>
727
- dependencies: Array<string>
728
- dynamicRoutes: Array<string>
729
- staticRoutes: Array<string>
730
- allRoutes: Array<string>
731
- }
732
-
733
- /**
734
- Returns the complete extension (e.g., page.js not just .js) of the passed file path. Works with any number of extensions, returning the last two without a dot at the start.
735
- */
736
- extensionOfFilePath: (filePath: string) => string
737
-
738
- /**
739
- Determines which places the server should listen at.
740
- */
741
- getDomainsAndPort: (options: ServerOptions) => { domains: string[]; port: number }
742
-
743
- /**
744
- Returns unique project identifier based on the path of the project. This can be used as the name of a directory that is certain to be unique for this project.
745
- */
746
- getProjectIdentifierForDomain: (domain: string, port: number) => string
747
-
748
- /**
749
- Kitten app path, formatted in a way that works regardless of whether Kitten was invoked using the `kitten` command from the bundled distribution or via _bin/kitten_ from source.
750
- */
751
- kittenAppPath: string
752
-
753
- /**
754
- Run passed command (either `'ci'` or `'install'`) on the given module path.
755
- */
756
- npm: (command: 'ci' | 'install', modulePath: string) => boolean
757
-
758
- /**
759
- Derives the route pattern for the passed file path based on the base path.
760
- */
761
- routePatternFromFilePath: (filePath: string, basePath: string) => string
762
-
763
- /**
764
- Runs npm ci on the passed module path.
765
- */
766
- runNpmCiOnModulePath: (modulePath: string) => void
767
-
768
- /**
769
- Calculates the base path used by the Kitten server to find files in the served app.
770
- */
771
- setBasePath: (workingDirectory: string, pathToServe: string) => string
772
-
773
- /**
774
- A regular expression that matches all extensions supported by Kitten.
775
-
776
- Currently, this includes all extensions in {@link DYNAMIC_ROUTE_EXTENSIONS} and {@link STATIC_ROUTE_EXTENSIONS}.
777
-
778
- @remarks For internal use only.
779
- */
780
- supportedExtensionsRegExp: RegExp
781
- }
782
-
783
- /**
784
- Constants for well-known/supported client-side libraries meant to be referenced in page routes.
785
-
786
- Usually the file names held by these properties will refer to the minified version when `process.env.PRODUCTION` is `true` and non-minified versions otherwise (in development mode, so we can get more meaningful stack traces).
787
-
788
- @see https://kitten.small-web.org/reference/#kitten-client-side-libraries
789
- */
790
- libraries: {
791
- htmx: string
792
- htmxIdiomorph: string
793
- htmxWebSocket: string
794
- alpineJs: string
795
- water: string
796
- }
797
-
798
- /**
799
- Special page slot names (constants) that can be used as targets of `<content for='…'>` tags.
800
-
801
- @example
802
- export default () => kitten.html`
803
- <markdown>
804
- # Special page slots
805
-
806
- This is just regular page content.
807
- </markdown>
808
- <!-- Whereas this will be added to the <head>…</head> -->
809
- <content for='${kitten.page.head}'>
810
- <title>Special page slots</title>
811
- <link rel='icon' href='/favicon.ico'>
812
- </content>
813
- `
814
-
815
- @see https://kitten.small-web.org/tutorials/special-page-slots/
816
- */
817
- page: {
818
- html: 'HTML'
819
- head: 'HEAD'
820
- startOfBody: 'START_OF_BODY'
821
- beforeLibraries: 'BEFORE_LIBRARIES'
822
- afterLibraries: 'AFTER_LIBRARIES'
823
- endOfBody: 'END_OF_BODY'
824
- }
825
-
826
- /**
827
- Use this method to add untrusted markup to your page safely.
828
-
829
- You can customise the list of allowed tags by providing a list of ones to add to them (e.g., `['img']`) or by replacing it altogether with your own list by passing `false` as the last argument.
830
-
831
- @example
832
- <!-- Safely display comments on a blog that contain Markdown syntax. -->
833
- <ul>
834
- ${kitten.db.comments.map(comment => kitten.html`
835
- <li>
836
- <p>${kitten.safelyAddHtml(kitten.md.render(comment.message))}</p>
837
- <p class='nameAndDate'>${comment.name} (${new Date(comment.date).toLocaleString()})</p>
838
- </li>
839
- `)}
840
- </ul>
841
-
842
- @remarks
843
- Kitten escapes interpolated content by default so you’re safe from injection attacks by default. It also does not give you direct access to a `dangerouslySetInnerHTML()` style method on purpose. If you _really, really_ want to dangerously add HTML, you can do so by returning an array from your interpolation. e.g., `` `kitten.html`${[ thisContentWontBeSanitised ]}` ``. Needless to say, only ever do this with trusted content and then only if you absolutely must.
844
- */
845
- safelyAddHtml: SanitisationFunction
846
-
847
- /**
848
- This is a wrapper around sanitize-html that you can use to only allow whitelisted HTML in strings.
849
-
850
- @example
851
- // Kitten’s `kitten.safelyAddHtml()` function uses `sanitise()`.
852
- kitten.safelyAddHtml = (untrustedContent, allowedTags = [], concat = true) => kitten.html`${[ sanitise(untrustedContent, allowedTags, concat) ]}`
853
-
854
- @see https://github.com/apostrophecms/apostrophe/tree/main/packages/sanitize-html
855
- */
856
- sanitise: SanitisationFunction
857
-
858
- /**
859
- Reference to `WebSocket` class from ws.
860
-
861
- Use it to create your own server-to-server WebSocket connections.
862
-
863
- @see https://github.com/websockets/ws
864
-
865
- @example
866
- // Detail of _updates.socket.js_ route in Kitten’s Streamiverse example.
867
- stream = new kitten.WebSocket('wss://streamiverse.small-web.org/stream.socket')
868
-
869
- stream.addEventListener('message', event => {
870
- const message = JSON.parse(event.data)
871
- if (message.event === 'update') {
872
- const post = JSON.parse(message.payload)
873
-
874
- console.info(` 🐘 Got an update from ${post.account.username}!`)
875
- }
876
- })
877
- */
878
- WebSocket: typeof KittenWebSocket
879
-
880
- /**
881
- Kitten is run by default to silence Node’s deprecation warnings (you can turn them on by running `kitten` with `SHOW_DEPRECATION_WARNINGS=true`) as we use experimental features and we don’t what the console output to be noisy.
882
-
883
- Any deprecation warnings that are encountered are kept here even if they’re not shown in the console.
884
-
885
- @see https://codeberg.org/kitten/app/src/branch/main/suppress-experimental.cjs
886
- */
887
- deprecationWarnings: Array<string>
888
-
889
- /**
890
- File system paths of important Kitten resources.
891
- */
892
- paths: {
893
- /**
894
- Absolute local system path for binaries (~/.local/bin)
895
- */
896
- BINARY_HOME: string,
897
-
898
- /**
899
- Path to Kitten’s own “binary” (shell script that starts the Node runtime and loads the loader and main process bundles).
900
- */
901
- KITTEN_BINARY_PATH: string,
902
-
903
- /**
904
- The path where a person’s data files should be stored according to the XDG Base Directory Specification (if the `XDG_DATA_HOME` environment variable is set, otherwise, falls back to _~/.local/share_).
905
-
906
- @see https://specifications.freedesktop.org/basedir/latest/
907
- */
908
- DATA_HOME: string,
909
-
910
- /**
911
- The small-tech.org namespace within the person’s data home folder.
912
-
913
- All Small Technology Foundation tools, including Kitten, live under this namespace.
914
- */
915
- SMALL_TECH_DATA_HOME: string,
916
-
917
- /**
918
- The home directory of Kitten’s own data.
919
-
920
- Set to {@link SMALL_TECH_DATA_HOME}/kitten
921
- */
922
- KITTEN_DATA_HOME: string,
923
-
924
- /**
925
- The directory that hosts the Kitten app itself.
926
-
927
- Set to {@link KITTEN_DATA_HOME}/app
928
- */
929
- KITTEN_APP_DIRECTORY_PATH: string,
930
-
931
- /**
932
- The directory containing Kitten’s own web app (settings, initial secret creation, etc.)
933
-
934
- Set to {@link KITTEN_APP_DIRECTORY_PATH}/web
935
- */
936
- KITTEN_WEB_APP_DIRECTORY_PATH: string,
937
-
938
- /**
939
- The directory that houses all the TLS certificate information for Kitten servers (both local and globally-accessible ones).
940
-
941
- Stores certificate data managed by \@small-tech/auto-encrypt (Let’s Encrypt) and \@small-tech/auto-encrypt-localhost, as abstracted by \@small-tech/https.
942
-
943
- @see https://codeberg.org/small-tech/https
944
- */
945
- KITTEN_TLS_DIRECTORY: string,
946
-
947
- /**
948
- Contains certificate data for localhost domains.
949
-
950
- As managed by Auto Encrypt Localhost (\@small-tech/auto-encrypt-localhost).
951
-
952
- @see https://codeberg.org/small-tech/auto-encrypt-localhost
953
- */
954
- KITTEN_TLS_LOCAL_CERTIFICATE_DIRECTORY: string,
955
-
956
- /**
957
- Contains certificate data for production domains (and Web Numbers/IP Addresses).
958
-
959
- As managed by Auto Encrypt (\@small-tech/auto-encrypt).
960
-
961
- @see https://codeberg.org/small-tech/auto-encrypt
962
- */
963
- KITTEN_TLS_GLOBAL_CERTIFICATE_DIRECTORY: string,
964
-
965
- /**
966
- Location under /tmp that Kitten stores its temporary files.
967
-
968
- Currently /tmp/small-tech.org/kitten
969
- */
970
- KITTEN_TEMP_DIRECTORY: string,
971
-
972
- /**
973
- Location of runtime.tar.xz, the archived version of Kitten’s runtime.
974
-
975
- (Currently, Node.js).
976
- */
977
- KITTEN_TEMP_RUNTIME_ARCHIVE_PATH: string,
978
-
979
- /**
980
- The same-device temp directory is guaranteed to be on the same device as the rest of Kitten’s data so you can use, for example, `fs.rename` on it while you may not be able to do so with `KITTEN_TEMP_DIRECTORY`, which might be on a different partition.
981
- */
982
- KITTEN_SAME_DEVICE_TEMP_DIRECTORY: string,
983
-
984
- /**
985
- This directory holds Kitten’s runtime (currently, Node.js)
986
- */
987
- KITTEN_RUNTIME_DIRECTORY: string,
988
-
989
- /**
990
- The directory that holds the binary of Kitten’s runtime (currently, Node.js)
991
- */
992
- KITTEN_RUNTIME_BIN_DIRECTORY: string,
993
-
994
- /**
995
- The directory that holds the data for all projects (sites/apps) that have been served on this device.
996
-
997
- Subfolders within this directory are named based on {@link utils.getProjectIdentifierForDomain}.
998
- */
999
- KITTEN_DATA_DIRECTORY: string,
1000
-
1001
- /**
1002
- Kitten has two different types of internal databases: a global one for Kitten itself and separate internal databases for every project.
1003
-
1004
- This is path for the global one.
1005
-
1006
- @remarks For internal use only.
1007
- */
1008
- KITTEN_GLOBAL_INTERNAL_DATABASE_DIRECTORY: string,
1009
-
1010
- /**
1011
- The directory that kitten projects are deployed to when you use the `kitten deploy` command.
1012
- */
1013
- KITTEN_DEPLOYMENTS_DIRECTORY: string,
1014
-
1015
- /**
1016
- The directory that the repositories are cloned to when you use the `kitten run` command to clone and run a Kitten project based on the HTTPS git URL of the project’s repository.
1017
- */
1018
- KITTEN_CLONES_DIRECTORY: string,
1019
-
1020
- /**
1021
- The path where a person’s configuration files should be stored according to the XDG Base Directory Specification (if the `XDG_CONFIG_HOME` environment variable is set, otherwise, falls back to _~/.config_).
1022
-
1023
- @see https://specifications.freedesktop.org/basedir/latest/
1024
- */
1025
- CONFIG_HOME: string,
1026
-
1027
- /**
1028
- Path of the systemd “user” (we don’t use that term in Small Tech as it’s an othering) directory.
1029
-
1030
- Defaults to _~/.config/systemd/user_.
1031
- */
1032
- SYSTEMD_USER_DIRECTORY: string,
1033
-
1034
- /**
1035
- Path to Kitten’s systemd unit.
1036
-
1037
- Set to {@link SYSTEMD_USER_DIRECTORY}/kitten.service
1038
- */
1039
- KITTEN_SYSTEMD_UNIT_PATH: string
1040
-
1041
- // From Kitten’s src/lib/globals.ts
1042
-
1043
- /**
1044
- The app data directory for the current app (site/project).
1045
-
1046
- Use when opening your database in a Database App Module to get the path to it.
1047
-
1048
- @example
1049
- JSDB.open(
1050
- path.join(kitten.paths.APP_DATA_DIRECTORY, 'db'),
1051
- {
1052
- compactOnLoad,
1053
- classes: [
1054
- Database,
1055
- Kitten
1056
- ]
1057
- }
1058
- )
1059
-
1060
- @see https://kitten.small-web.org/tutorials/database-app-modules/
1061
- @see https://codeberg.org/kitten/app/src/branch/main/examples/database-app-module/app_modules/database/database.js#L46
1062
- */
1063
- APP_DATA_DIRECTORY: string
1064
-
1065
- /**
1066
- The location of file uploads for the current app.
1067
-
1068
- Set to {@link APP_DATA_DIRECTORY}/uploads
1069
- */
1070
- APP_UPLOADS_DIRECTORY: string
1071
-
1072
- /**
1073
- The location of REPL data (REPL history) for the current app.
1074
-
1075
- Set to {@link APP_DATA_DIRECTORY}/repl
1076
- */
1077
- APP_REPL_DIRECTORY: string
1078
- }
1079
-
1080
- /**
1081
- For internal use by Kitten’s web app.
1082
- */
1083
- deploy: Function
1084
- }
1085
-
1086
- declare global {
1087
- /**
1088
- Kitten’s global `kitten` object.
1089
-
1090
- The most common properties you’ll be using in daily authoring include:
1091
-
1092
- - {@link html} - Write HTML with component and string interpolation support.
1093
- - {@link db} - Reference your site/apps custom JSDB database.
1094
- - {@link Page} - Extend this class to create your own Kitten pages.
1095
- - {@link Component} - Extend this class to create your own stateful Kitten components.
1096
- - {@link safelyAddHtml} - Use when adding untrusted content to your pages.
1097
- - {@link crypto} - Kitten’s cryptographic library.
1098
- - {@link icons} - Kitten’s built-in icon library.
1099
11
 
1100
- @see https://kitten.small-web.org/tutorials/
1101
- */
1102
- var kitten: kitten
1103
- }
12
+ import './kitten/src/types/globals.d.ts'
1104
13
 
1105
- export {}
14
+ // Also export the global namespace shape, in case an author wants to reference it explicitly (e.g. `typeof kitten`).
15
+ export type { kitten } from './kitten/src/types/globals.d.ts'