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