@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
@@ -0,0 +1,202 @@
1
+ /**
2
+ Represents a currently active live page. Live pages are open in the client
3
+ and either in the process of being served for the first time, connecting via
4
+ WebSocket, or connected via WebSocket.
5
+
6
+ All live pages belong to a session.
7
+
8
+ Usage:
9
+
10
+ When authoring, you can export your page route as a subclass of KittenPage using the global reference to it at `kitten.Page`.
11
+
12
+ Helpers:
13
+
14
+ page.send(): Sends message to connected page (calls page.socket.send()).
15
+ page.everyoneElse.send(): Sends message to everyone connected to this page but the current person.
16
+ page.everyone.send(): Send message to everyone connected to this page, including the current person.
17
+
18
+ @example
19
+
20
+ See the KittenComponent class for an example of usage.
21
+ */
22
+ import type { JavaScriptFunction } from './KittenComponent.ts';
23
+ export type KittenPageEvent = {
24
+ page: KittenPage;
25
+ name: string;
26
+ handler: string;
27
+ id: string;
28
+ target: string;
29
+ data: {
30
+ [s: string]: any;
31
+ };
32
+ headers: any;
33
+ event: any;
34
+ };
35
+ type WebSocketWithIsAlive = import('ws').WebSocket & {
36
+ isAlive: boolean;
37
+ id?: string;
38
+ };
39
+ type KittenRequest = import('../types/index.ts').KittenRequest & {
40
+ ws?: Function;
41
+ };
42
+ type KittenResponse = import('../types/index.ts').KittenResponse;
43
+ type SwapTarget = {
44
+ before?: string;
45
+ } | {
46
+ after?: string;
47
+ } | {
48
+ asFirstChildOf?: string;
49
+ } | {
50
+ asLastChildOf?: string;
51
+ };
52
+ type BufferLike = string | Buffer | DataView | number | ArrayBufferView | Uint8Array | ArrayBuffer | SharedArrayBuffer | ReadonlyArray<any> | ReadonlyArray<number> | {
53
+ valueOf(): ArrayBuffer;
54
+ } | {
55
+ valueOf(): SharedArrayBuffer;
56
+ } | {
57
+ valueOf(): Uint8Array;
58
+ } | {
59
+ valueOf(): ReadonlyArray<number>;
60
+ } | {
61
+ valueOf(): string;
62
+ } | {
63
+ [Symbol.toPrimitive](hint: string): string;
64
+ };
65
+ import KittenComponent from './KittenComponent.ts';
66
+ import { type Session } from '../Sessions.ts';
67
+ /**
68
+ Transform event name into event handler name.
69
+ */
70
+ export declare function eventNameToEventHandlerName(eventName: string): string;
71
+ /**
72
+ Converts any key paths found in the keys of
73
+ passed data into an actual object structure.
74
+
75
+ This enables you to specify object structure in
76
+ the names of your connected elements and makes it
77
+ easier to persist them on the server.
78
+ */
79
+ export declare function convertKeypathsToObjects(data: {
80
+ [s: string]: any;
81
+ }): {
82
+ [s: string]: any;
83
+ };
84
+ /**
85
+ Add message envelope used when inserting elements into the
86
+ DOM relative to another element using htmx’s out-of-band swaps
87
+ (oob-swaps).
88
+
89
+ If a swap target is not provided, the message is returned unchanged.
90
+ */
91
+ export declare function addMessageEnvelopeIfNecessary(message: any, swapTarget: SwapTarget): any;
92
+ export default class KittenPage extends KittenComponent {
93
+ _isPage: boolean;
94
+ session: Session | undefined;
95
+ _request: KittenRequest | undefined;
96
+ _response: KittenResponse | undefined;
97
+ _isAuthoredPage: boolean;
98
+ _socket: WebSocketWithIsAlive | undefined;
99
+ _sockets: Array<WebSocketWithIsAlive> | undefined;
100
+ timeout: ReturnType<typeof setTimeout> | undefined;
101
+ socketMessageHandler: ((event: any) => void) | undefined;
102
+ everyone: MessageSender;
103
+ everyoneElse: MessageSender;
104
+ /**
105
+ Every page has a unique ID (inherited from KittenComponent) and can hold
106
+ ephemeral page-level data. e.g., the states of components when
107
+ using the Streaming HTML workfow. (Page storage is ephemeral is that
108
+ it only lasts for the lifetime of a page in the browser and is destroyed
109
+ when the page is closed or reloaded.)
110
+
111
+ If you need greater persistence, use session storage (request.session) or
112
+ the built-in JSDB database (kitten.db).
113
+
114
+ A page is an authored page if the author of the Kitten app/site wrote
115
+ and exported a KittenPage subclass in the route (as opposed to exporting a
116
+ simple function and function-based event handlers that then resulted
117
+ in a generic page being created by Kitten’s PageRoute class). Keeping
118
+ track of this is an optimisation that enabled the PageSocketRoute to
119
+ not have to import the source file again if the page was authored
120
+ as a page instance and thus already contains its event handlers (as
121
+ opposed to the event handlers being exported as separate functions that
122
+ have be read in and mixed into the generic KittenPage instance by the PageSocketRoute).
123
+ */
124
+ constructor();
125
+ get request(): KittenRequest | undefined;
126
+ set request(request: KittenRequest | undefined);
127
+ get response(): import("../types/types.js").KittenResponse | undefined;
128
+ set response(response: import("../types/types.js").KittenResponse | undefined);
129
+ /**
130
+ The page has connected to its WebSocket. The list of sockets and the
131
+ specific socket for this page are passed for storage on the page and the
132
+ list of event handlers imported from the page (when using function-based
133
+ page routes), if any, to be mixed into this instance as methods.
134
+
135
+ */
136
+ connect(socket: WebSocketWithIsAlive, sockets: WebSocketWithIsAlive[], eventHandlers?: {
137
+ [s: string]: JavaScriptFunction;
138
+ }): void;
139
+ /**
140
+ Remove the socket event listener on disconnect.
141
+ */
142
+ _onDisconnect(): void;
143
+ /**
144
+ Dynamically add specified event handler for specified event name.
145
+
146
+ TODO: Is this still required with the new component model?
147
+ If we find that it doesn’t fit any use cases, we should remove this.
148
+
149
+ @deprecated Instead of `on(eventName, handler)`, export `onEventName()` from your page (or add `onEventName()` method to your `kitten.Page` subclass if using class-based page routes.)
150
+ */
151
+ on(eventName: string, eventHandler: JavaScriptFunction): this;
152
+ /**
153
+ Send specified message to just this page’s socket,
154
+ awaiting promise if message is a promise (which can happen if
155
+ this.component is accessed in a kitten.html tagged template string).
156
+
157
+ You can specify an optional swap target that intelligently
158
+ wraps what you’re sending with the necessary envelope tag.
159
+ This is normally rather confusing with htmx’s oob swaps,
160
+ especially when inserting table rows. See:
161
+ https://htmx.org/attributes/hx-swap-oob/#using-alternate-swap-strategies
162
+ */
163
+ send(message: BufferLike | Promise<BufferLike>, swapTarget?: SwapTarget): void;
164
+ /**
165
+ Sends message. Expects it not to be a promise.
166
+ */
167
+ sendImmediately(message: BufferLike, swapTarget: SwapTarget): void;
168
+ /**
169
+ The convention for page sockets is to map the name of the DOM element
170
+ that triggered the HTMX request to the name of the event handler so
171
+ that <element connect name='eventName' /> maps to onEventName() on
172
+ the page.
173
+ */
174
+ _messageHandler(event: {
175
+ data: any;
176
+ }): Promise<void>;
177
+ }
178
+ /**
179
+ Provides a namespaced send() method for use in Page instances.
180
+ */
181
+ export declare class MessageSender {
182
+ socket: WebSocketWithIsAlive;
183
+ sockets: WebSocketWithIsAlive[];
184
+ includeSelf: boolean;
185
+ constructor({ socket, sockets, includeSelf }: {
186
+ socket: WebSocketWithIsAlive;
187
+ sockets: WebSocketWithIsAlive[];
188
+ includeSelf: boolean;
189
+ });
190
+ /**
191
+ Sends message either to all connections or to all connections
192
+ excluding the current one.
193
+
194
+ You can specify an optional swap target that intelligently
195
+ wraps what you’re sending with the necessary envelope tag.
196
+ This is normally rather confusing with htmx’s oob swaps,
197
+ especially when inserting table rows. See:
198
+ https://htmx.org/attributes/hx-swap-oob/#using-alternate-swap-strategies
199
+ */
200
+ send(message: BufferLike, swapTarget?: SwapTarget): number;
201
+ }
202
+ export {};
@@ -0,0 +1,49 @@
1
+ /**
2
+ Deserialises version information from the version.json
3
+ file created by the Kitten build process.
4
+
5
+ Singleton.
6
+ */
7
+ export default class Version {
8
+ static instance: Version;
9
+ versionStamp: number;
10
+ gitHash: string;
11
+ apiVersion: number;
12
+ nodeVersion: string;
13
+ exactVersion: string;
14
+ _date: Date | undefined;
15
+ year: number | undefined;
16
+ month: number | undefined;
17
+ day: number | undefined;
18
+ paddedMonth: string | undefined;
19
+ paddedDay: string | undefined;
20
+ hour: number | undefined;
21
+ minute: number | undefined;
22
+ second: number | undefined;
23
+ paddedHour: string | undefined;
24
+ paddedMinute: string | undefined;
25
+ paddedSecond: string | undefined;
26
+ formattedDate: string | undefined;
27
+ formattedTime: string | undefined;
28
+ static getInstance(): Version;
29
+ constructor();
30
+ set date(date: Date);
31
+ get date(): Date;
32
+ birthday(): string;
33
+ /**
34
+ Get star sign based on passed month and day.
35
+
36
+ Based on https://gist.github.com/vyach-vasiliev/175758c7633fda9587f9dabf850507c0
37
+ @returns {string} Star sign.
38
+ */
39
+ get starSign(): string;
40
+ get Component(): () => string | string[] | Promise<string | string[]>;
41
+ /**
42
+ HTML component to display version information.
43
+ */
44
+ html(): string | string[] | Promise<string | string[]>;
45
+ /**
46
+ Output version information to the console.
47
+ */
48
+ printToConsole(): void;
49
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ Highlight a string of HTML. Pair with an indenter (e.g. htmlfy)
3
+ upstream; this only colours, it doesn't reformat.
4
+ */
5
+ export declare function ansiHighlightHtml(html: string): string;
@@ -0,0 +1,14 @@
1
+ /**
2
+ CopyButton: stateful
3
+ */
4
+ import KittenComponent from '../../KittenComponent.ts';
5
+ import { type CopyButtonProps } from '../stateless/copyButton.component.ts';
6
+ export default class CopyButton extends KittenComponent {
7
+ html(props: CopyButtonProps): string | string[] | Promise<string | string[]>;
8
+ onCopy(data: {
9
+ value: unknown;
10
+ }): void;
11
+ onCopyFail(data: {
12
+ value: unknown;
13
+ }): void;
14
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ Copy button component: stateless.
3
+
4
+ The stateful component wraps this.
5
+ */
6
+ export type CopyButtonProps = {
7
+ value: unknown;
8
+ SLOT?: unknown;
9
+ success?: string;
10
+ failure?: string;
11
+ };
12
+ /**
13
+ Button that copies the passed data to the clipboard on the client when clicked.
14
+
15
+ @param value - The value to copy.
16
+ @param SLOT - The contents of the button.
17
+ @param success - Name of event to be raised on successful copy. (default='copy'; maps to `onCopy()` method on nearest KittenComponent or KittenPage).
18
+ @param failure - Name of event to be raised on failed copy. (default='copyFail'; maps to `onCopyFail()` method on nearest KittenComponent or KittenPage).
19
+
20
+ */
21
+ export default function copyButton({ value, SLOT, success, failure, ...props }: CopyButtonProps): string | string[] | Promise<string | string[]>;
@@ -0,0 +1,95 @@
1
+ /**
2
+ Kitten Crypto API
3
+
4
+ Runs in browsers (packaged via esbuild) and in Node.
5
+
6
+ Exposes high-level cryptographic functions to enable generation
7
+ of secret key material as well as Diffie-Hellman key exchange (shared secrets)
8
+ and signing and encryption for the Small Web Protocol.
9
+
10
+ When used in browsers, does so in the person’s own browser without ever
11
+ hitting the server and, from there, generates the ed25519, ssh, and pgp
12
+ public keys that are sent to the server for storage and discovery.
13
+
14
+ ⚠️ Node-native subgraph: this module is loaded natively by Node.js via
15
+ type stripping. Only use erasable TypeScript syntax here. Additionally,
16
+ this module is bundled for the browser (see ./build), so it must remain
17
+ platform-neutral: no Node-only imports or types in its surface.
18
+
19
+ Copyright © 2022-present, Aral Balkan
20
+ Small Technology Foundation.
21
+ Released under GNU AGPLv3.
22
+ */
23
+ import { secretToEmojiString, emojiStringToSecret } from './KittenMoji.ts';
24
+ import { getSharedSecret, sign, verify } from '@noble/ed25519';
25
+ import { encrypt, decrypt } from 'micro-aes-gcm';
26
+ import { randomBytes } from 'ed25519-keygen/utils';
27
+ import { bytesToHex, hexToBytes } from '@noble/hashes/utils';
28
+ export { secretToEmojiString, emojiStringToSecret, getSharedSecret, encrypt, decrypt, sign, verify, randomBytes, bytesToHex, hexToBytes };
29
+ /**
30
+ Generates cryptographically random 32-byte token and coverts it to hexadecimal representation.
31
+
32
+ Use anywhere you need a secret token (domain token, webhook secret, etc.)
33
+ */
34
+ export declare function random32ByteTokenInHex(): string;
35
+ /**
36
+ Calculates the shared secret for a domain using the
37
+ domain’s public key and our private key.
38
+
39
+ @param domain
40
+ @param ourPrivateKey The emoji-encoded private key.
41
+ */
42
+ export declare function sharedSecretForDomain(domain: string, ourPrivateKey: string): Promise<Uint8Array<ArrayBufferLike>>;
43
+ /**
44
+ Encrypts a message for a domain.
45
+
46
+ @param message
47
+ @param ourPrivateKey The emoji-encoded private key.
48
+ @param domain
49
+
50
+ @returns Hex-encoded encrypted message.
51
+ */
52
+ export declare function encryptMessageForDomain(message: string, ourPrivateKey: string, domain: string): Promise<string>;
53
+ /**
54
+ Decrypts message from domain.
55
+
56
+ @param encryptedMessage Hex-encoded encrypted message.
57
+ @param ourPrivateKey Emoji-encoded private key string.
58
+ @param domain
59
+
60
+ @returns Unencrypted message as UTF8 string.
61
+ */
62
+ export declare function decryptMessageFromDomain(encryptedMessage: string, ourPrivateKey: string, domain: string): Promise<string>;
63
+ /**
64
+ The public and private key material for a domain.
65
+ */
66
+ export type DomainKeys = {
67
+ private: {
68
+ ssh: {
69
+ asString: string;
70
+ };
71
+ ed25519?: {
72
+ asBytes: Uint8Array;
73
+ asString: string;
74
+ };
75
+ };
76
+ public: {
77
+ ed25519: {
78
+ asString: string;
79
+ asBytes: Uint8Array;
80
+ };
81
+ ssh: {
82
+ asString: string;
83
+ asBytes: Uint8Array;
84
+ fingerprint: string;
85
+ };
86
+ };
87
+ };
88
+ /**
89
+ Creates keys for domain.
90
+ */
91
+ export declare function createKeys(domain: string): Promise<DomainKeys>;
92
+ /**
93
+ Derive keys from secret key for domain.
94
+ */
95
+ export declare function deriveKeysFromSecretKeyForDomain(secretKey: Uint8Array, domain: string): Promise<DomainKeys>;
@@ -0,0 +1,20 @@
1
+ /**
2
+ Deploys an app from a Git repository as a
3
+ systemd --user service.
4
+
5
+ Copyright ⓒ 2021-present, Aral Balkan
6
+ Small Technology Foundation
7
+
8
+ License: AGPL version 3.0.
9
+ */
10
+ import type { DeploymentOptions } from '../cli/index.ts';
11
+ type DeployOptions = DeploymentOptions & {
12
+ progress?: (message: string) => void;
13
+ context?: 'cli' | 'web';
14
+ 'is-being-deployed-by-domain'?: boolean;
15
+ };
16
+ /**
17
+ @param gitHttpsCloneUrl git clone url (HTTPS)
18
+ */
19
+ export default function deploy(gitHttpsCloneUrl: string, options: DeployOptions): Promise<void>;
20
+ export {};
@@ -0,0 +1,28 @@
1
+ /**
2
+ Kitten critical assertions.
3
+
4
+ Copyright ⓒ 2022-present, Aral Balkan (https://ar.al)
5
+ Small Technology Foundation (https://small-tech.org).
6
+
7
+ License: AGPL version 3.0.
8
+ */
9
+ declare const functions: {
10
+ commandExists: typeof commandExists;
11
+ systemctl: typeof systemctl;
12
+ journalctl: typeof journalctl;
13
+ serviceNotActive: typeof serviceNotActive;
14
+ portsAreFree: typeof portsAreFree;
15
+ canEnableService: typeof canEnableService;
16
+ };
17
+ export default functions;
18
+ /**
19
+ Does the command with the passed name exist?
20
+
21
+ @param {string} command
22
+ */
23
+ export declare function commandExists(command: string): boolean;
24
+ export declare function systemctl(): void;
25
+ export declare function journalctl(): void;
26
+ export declare function portsAreFree(): Promise<void>;
27
+ export declare function canEnableService(): Promise<void>;
28
+ export declare function serviceNotActive(): void;
@@ -0,0 +1 @@
1
+ export declare const developmentTimeHotReloadScript = "\n <script>\n // Kitten development time hot reload script.\n let __kittenDevelopmentSocket\n let __kittenDevelopmentSocketReconnectionAttemptTimeoutId = null\n\n // The server sends a boot id (unique per server process start) on connect.\n // We remember the first one we see and reload only when a reconnect reports\n // a different id (i.e. after the server process restarts).\n let __kittenServerBootId = null\n\n function __kittenConnectToDevelopmentSocket () {\n console.info('Attempting to connect to Kitten development socket.')\n __kittenDevelopmentSocket = new WebSocket(`wss://${location.host}/\uD83D\uDC31/development-socket/`)\n\n const socketOpenHandler = () => {\n clearTimeout(__kittenDevelopmentSocketReconnectionAttemptTimeoutId)\n console.info('\uD83D\uDC31 Kitten: connected to development-time hot reload socket.')\n }\n\n const socketMessageHandler = (event) => {\n let message\n try {\n message = JSON.parse(event.data)\n } catch {\n return\n }\n if (message && message.type === 'kitten-development-boot-id') {\n if (__kittenServerBootId === null) {\n // First connection: remember the server\u2019s boot id.\n __kittenServerBootId = message.bootId\n } else if (message.bootId !== __kittenServerBootId) {\n // The server process has restarted (new boot id). Reload the page.\n window.location.reload()\n }\n }\n }\n\n const socketCloseHandler = () => {\n clearTimeout(__kittenDevelopmentSocketReconnectionAttemptTimeoutId)\n __kittenDevelopmentSocketReconnectionAttemptTimeoutId = setTimeout(__kittenConnectToDevelopmentSocket, 50)\n }\n\n __kittenDevelopmentSocket.addEventListener('open', socketOpenHandler)\n __kittenDevelopmentSocket.addEventListener('message', socketMessageHandler)\n __kittenDevelopmentSocket.addEventListener('close', socketCloseHandler)\n\n // This is mainly a fix for Firefox, which is the only browser that results in\n // the closing of the WebSocket connection at the start of an HTTP load request\n // (e.g., form POST) and subsequent reconnection, thereby firing of a premature\n // GET request to the server.\n // See: https://mastodon.ar.al/@aral/109104595295584049\n window.addEventListener('beforeunload', () => {\n clearTimeout(__kittenDevelopmentSocketReconnectionAttemptTimeoutId)\n __kittenDevelopmentSocket.removeEventListener('open', socketOpenHandler)\n __kittenDevelopmentSocket.removeEventListener('message', socketMessageHandler)\n __kittenDevelopmentSocket.removeEventListener('close', socketCloseHandler)\n __kittenDevelopmentSocket.close()\n }) \n }\n\n // In case the developer is using htmx to update the body of the page,\n // make sure the development script runs only once.\n if (!globalThis.kittenDevelopmentTimeHotReloadScriptAlreadyInitialised) {\n globalThis.kittenDevelopmentTimeHotReloadScriptAlreadyInitialised = true\n __kittenConnectToDevelopmentSocket()\n }\n </script>\n ";
@@ -0,0 +1,10 @@
1
+ /**
2
+ Creates and populates the Kitten global namespace (kitten).
3
+ */
4
+ export default class Globals {
5
+ static initialised: boolean;
6
+ /**
7
+ Initialise Kitten globals (unique for each domain/port/project directory combination).
8
+ */
9
+ static initialise(domain: string, port: number): void;
10
+ }
@@ -0,0 +1,61 @@
1
+ /**
2
+ Tagged template HTML rendering.
3
+
4
+ This is a combination of xhtm (https://github.com/dy/xhtm) by Dmitry Ivanov
5
+ and vhtml (https://github.com/developit/vhtml) by Jason Miller.
6
+
7
+ I (Aral) was initially mantaining separate forks of them but parsing
8
+ tagged templates into hyperscript and rendering them into HTML is fiddly
9
+ enough to get your head around without having two modules interacting with
10
+ each other in the way these two did.
11
+
12
+ Given how fundamental rendering templates to HTML is to Kitten, I’m
13
+ inlining them here with an eye towards removing redudancy and hopefully
14
+ simplifying the interaction between the two in the future (as I don’t need
15
+ the flexibility of having them work independently) and being able to
16
+ iterate faster on authoring features that are impacted by the renderer.
17
+
18
+ Original vhtml code is Copyright © 2015-present Jason Miller (MIT license).
19
+ Original xhtm code is Copyright © 2019-present Dmitry Ivanov (MIT license).
20
+
21
+ Any modifications are Copyright © 2023-present Aral Balkan
22
+ and released under AGPL version 3.0 as is the rest of Kitten.
23
+
24
+ ⚠️ Node-native subgraph: this module (and everything it imports) is loaded
25
+ natively by Node.js via type stripping (imported by the loader). Only use
26
+ erasable TypeScript syntax here.
27
+ */
28
+ export { h as hyperscriptToHtmlString };
29
+ /**
30
+ Render any Markdown areas there might be and
31
+ return an updated list of values (as their order
32
+ might have changed during rendering).
33
+
34
+ */
35
+ export declare function renderMarkdown(strings: TemplateStringsArray | string[], values: any[]): {
36
+ finalStrings: string[] | TemplateStringsArray;
37
+ finalValues: any[];
38
+ };
39
+ /**
40
+ Kitten HTML tagged template.
41
+
42
+ Supports both synchronous and asynchronous use.
43
+
44
+ */
45
+ export declare function html(strings: TemplateStringsArray, ...values: any[]): string | string[] | Promise<string | string[]>;
46
+ /**
47
+ HyperScript (HyperText with JavaScript)
48
+ reviver that constructs sanitised HTML string.
49
+ (Generator; so we can use it with both synchronous
50
+ and asynchronous components.)
51
+
52
+ The original approach dates back to the HyperScript
53
+ project by Dominic Tarr:
54
+
55
+ https://github.com/hyperhype/hyperscript
56
+
57
+ */
58
+ declare function h(name: any, attrs: any, ...children: any[]): Generator<any, any, any>;
59
+ declare namespace h {
60
+ var token: string;
61
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ Kitten’s Markdown support, based on MarkdownIt and its plugins.
3
+
4
+ This library is used by both the ES Module Loader and main process.
5
+
6
+ ⚠️ Node-native subgraph: this module is loaded natively by Node.js via
7
+ type stripping. Only use erasable TypeScript syntax here.
8
+
9
+ Copyright ⓒ 2024-present, Aral Balkan, Small Technology Foundation.
10
+ Released under the AGPL 3.0 license.
11
+ */
12
+ import MarkdownIt from 'markdown-it';
13
+ import slugify from '@sindresorhus/slugify';
14
+ declare const markdownIt: MarkdownIt;
15
+ export default markdownIt;
16
+ export { slugify };
@@ -0,0 +1,25 @@
1
+ declare const paths: {
2
+ BINARY_HOME: string;
3
+ KITTEN_BINARY_PATH: string;
4
+ DATA_HOME: string;
5
+ SMALL_TECH_DATA_HOME: string;
6
+ KITTEN_DATA_HOME: string;
7
+ KITTEN_APP_DIRECTORY_PATH: string;
8
+ KITTEN_WEB_APP_DIRECTORY_PATH: string;
9
+ KITTEN_TLS_DIRECTORY: string;
10
+ KITTEN_TLS_LOCAL_CERTIFICATE_DIRECTORY: string;
11
+ KITTEN_TLS_GLOBAL_CERTIFICATE_DIRECTORY: string;
12
+ KITTEN_TEMP_DIRECTORY: string;
13
+ KITTEN_TEMP_RUNTIME_ARCHIVE_PATH: string;
14
+ KITTEN_SAME_DEVICE_TEMP_DIRECTORY: string;
15
+ KITTEN_RUNTIME_DIRECTORY: string;
16
+ KITTEN_RUNTIME_BIN_DIRECTORY: string;
17
+ KITTEN_DATA_DIRECTORY: string;
18
+ KITTEN_GLOBAL_INTERNAL_DATABASE_DIRECTORY: string;
19
+ KITTEN_DEPLOYMENTS_DIRECTORY: string;
20
+ KITTEN_CLONES_DIRECTORY: string;
21
+ CONFIG_HOME: string;
22
+ SYSTEMD_USER_DIRECTORY: string;
23
+ KITTEN_SYSTEMD_UNIT_PATH: string;
24
+ };
25
+ export default paths;
@@ -0,0 +1,14 @@
1
+ /**
2
+ Function: serviceStatus (synchronous)
3
+
4
+ Returns the Kitten server daemon status.
5
+
6
+ Proxies: systemctl status --user kitten
7
+
8
+ TODO: This module has not been updated for Kitten yet (copied over from Site.js).
9
+ */
10
+ export default function serviceStatus(): {
11
+ isActive: boolean;
12
+ isEnabled: boolean;
13
+ daemonDetails: {} | null;
14
+ };
@@ -0,0 +1,39 @@
1
+ /**
2
+ Exit status codes for system programs that attempts to conform to the nearest
3
+ thing I could find to a standard which is used in C/C++, via sysexists.h.
4
+ (See: https:tldp.org/LDP/abs/html/exitcodes.html)
5
+
6
+ Any additions to this will be documented here:
7
+
8
+ - 99: Restart request.
9
+
10
+ Original sysexists.h, where some portions of the comments in this file are
11
+ from, is copyright © 1987, 1993 The Regents of the University of California.
12
+ All rights reserved. And released under the 3-Clause BSD License.
13
+
14
+ Copyright ⓒ 2022-present, Aral Balkan
15
+ Small Technology Foundation
16
+
17
+ License: AGPL version 3.0.
18
+ */
19
+ declare const _default: {
20
+ ok: number;
21
+ generalError: number;
22
+ cliSyntaxError: number;
23
+ dataError: number;
24
+ fileNotFound: number;
25
+ accountNotFound: number;
26
+ hostNotFound: number;
27
+ unavailable: number;
28
+ internalSoftwareError: number;
29
+ systemError: number;
30
+ criticalSystemFileMissing: number;
31
+ cannotCreateOutputFile: number;
32
+ inputOutputError: number;
33
+ temporaryFailure: number;
34
+ protocolError: number;
35
+ permissionDenied: number;
36
+ configurationError: number;
37
+ restartRequest: number;
38
+ };
39
+ export default _default;
@@ -0,0 +1,24 @@
1
+ /**
2
+ Uses OSC 8 (https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda)
3
+ to create clickable hyperlinks with custom text in terminal.
4
+
5
+ Additionally, styles them with a dotted underline manually as some terminals
6
+ don’t do this (yet, at least).
7
+
8
+ e.g., See https://github.com/wez/wezterm/issues/4077#issuecomment-2324401900
9
+
10
+ Terminal support for this feature appears to be good:
11
+ https://github.com/Alhadis/OSC8-Adoption
12
+
13
+ Based on:
14
+ https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda?permalink_comment_id=5098507#gistcomment-5098507
15
+
16
+ For sequence code documentation, please see
17
+ https://gist.github.com/ConnerWill/d4b6c776b509add763e17f9f113fd25b#sequences
18
+ */
19
+ /**
20
+ @param {string} text
21
+ @param {string} url
22
+ */
23
+ export declare const link: (text: string, url: string) => string;
24
+ export default link;
@@ -0,0 +1,8 @@
1
+ /**
2
+ Authentication middleware.
3
+
4
+ Any route can require authentication if it contains the lock emoji in its name.
5
+ */
6
+ import type { NextHandler } from 'polka';
7
+ import type { KittenRequest, KittenResponse, KittenPolka } from '../types/index.ts';
8
+ export default function (app: KittenPolka): (request: KittenRequest, response: KittenResponse, next: NextHandler) => Promise<void>;
@@ -0,0 +1,5 @@
1
+ import type { KittenPolka } from '../types/index.ts';
2
+ /**
3
+ Adds all Kitten middleware to the Kitten Server’s Polka app.
4
+ */
5
+ export default function addAllMiddlewareToApp(app: KittenPolka): void;
@@ -0,0 +1,6 @@
1
+ import type { NextHandler } from 'polka';
2
+ import type { KittenRequest, KittenResponse } from '../types/index.ts';
3
+ /**
4
+ Adds helpers to request and response objects.
5
+ */
6
+ export default function (): (request: KittenRequest, response: KittenResponse, next: NextHandler) => void;