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