@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,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Keeps a truncated log of the last 25 request URLs for debugging purposes.
|
|
3
|
+
|
|
4
|
+
This could be merged with the stats plugin or expanded to log more than just URLs
|
|
5
|
+
or even removed altogether in the future. Just keeping it in here for the moment
|
|
6
|
+
to see if it’s useful for debugging certain types of issues.
|
|
7
|
+
*/
|
|
8
|
+
import type { NextHandler } from 'polka';
|
|
9
|
+
import type { KittenRequest, KittenResponse } from '../types/index.ts';
|
|
10
|
+
export default function (): (request: KittenRequest, response: KittenResponse, next: NextHandler) => void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Stats middleware.
|
|
3
|
+
|
|
4
|
+
Logs referrers.
|
|
5
|
+
*/
|
|
6
|
+
import type { NextHandler } from 'polka';
|
|
7
|
+
import type { KittenRequest, KittenResponse } from '../types/index.ts';
|
|
8
|
+
export default function (ownDomainWithHttps: string): (request: KittenRequest, response: KittenResponse, next: NextHandler) => void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Add trailing slash to all URL paths that need one.
|
|
3
|
+
So, /hello will become /hello/, for example. This avoids
|
|
4
|
+
issues with relative URLs breaking when the path is missing a trailing
|
|
5
|
+
slash (e.g., <script src='./index.ts'></script>).
|
|
6
|
+
|
|
7
|
+
See: https://stackoverflow.com/questions/31111257/relative-links-on-pages-without-trailing-slash
|
|
8
|
+
*/
|
|
9
|
+
import type { NextHandler } from 'polka';
|
|
10
|
+
import type { KittenRequest, KittenResponse } from '../types/index.ts';
|
|
11
|
+
export default function (): (request: KittenRequest, response: KittenResponse, next: NextHandler) => void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
WebSocket middleware: development mode only.
|
|
3
|
+
|
|
4
|
+
Handles WebSocket connections using the Kitten `ws` mixin to implment hot reload functionality along with the client-side Kitten development time script that’s injected into pages during development.
|
|
5
|
+
|
|
6
|
+
On connection, sends server’s boot ID so development-time clients can reliably detect server restarts (the boot ID changes across process starts).
|
|
7
|
+
|
|
8
|
+
@returns {import('polka').Middleware<any>}
|
|
9
|
+
*/
|
|
10
|
+
import type { NextHandler } from 'polka';
|
|
11
|
+
import type { KittenRequest, KittenResponse, WebSocket } from '../types/index.ts';
|
|
12
|
+
export default function (): (request: KittenRequest & {
|
|
13
|
+
ws?: () => Promise<WebSocket>;
|
|
14
|
+
}, _response: KittenResponse, next: NextHandler) => Promise<void>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import LazilyLoadedRoute from './LazilyLoadedRoute.ts';
|
|
2
|
+
import type { KittenRequest, KittenResponse } from '../types/index.ts';
|
|
3
|
+
type HttpRouteHandler = (parameterObject: {
|
|
4
|
+
request: KittenRequest;
|
|
5
|
+
response: KittenResponse;
|
|
6
|
+
}) => any;
|
|
7
|
+
export default class HttpRoute extends LazilyLoadedRoute {
|
|
8
|
+
_handler: HttpRouteHandler | undefined;
|
|
9
|
+
initialise(): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
Concrete overload that lazily loads the route handler if
|
|
12
|
+
necessary and handles requests.
|
|
13
|
+
*/
|
|
14
|
+
lazilyLoadedHandler(request: KittenRequest, response: KittenResponse): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { NextHandler } from 'polka';
|
|
2
|
+
import type { KittenRequest, KittenResponse } from '../types/index.ts';
|
|
3
|
+
export default class LazilyLoadedRoute {
|
|
4
|
+
filePath: string;
|
|
5
|
+
basePath: string;
|
|
6
|
+
extension: string;
|
|
7
|
+
pattern: string;
|
|
8
|
+
method: string;
|
|
9
|
+
/**
|
|
10
|
+
Abstract base class for lazily-loaded routes.
|
|
11
|
+
*/
|
|
12
|
+
constructor(filePath: string, basePath: string);
|
|
13
|
+
get handler(): (request: KittenRequest, response: KittenResponse, next?: NextHandler) => Promise<void>;
|
|
14
|
+
lazilyLoadedHandler(request: KittenRequest, response: KittenResponse, next?: NextHandler): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import LazilyLoadedRoute from './LazilyLoadedRoute.ts';
|
|
2
|
+
import type { KittenRequest as SharedKittenRequest, KittenResponse as SharedKittenResponse } from '../types/index.ts';
|
|
3
|
+
export interface KittenRequest extends SharedKittenRequest {
|
|
4
|
+
ws?: () => any;
|
|
5
|
+
}
|
|
6
|
+
export interface KittenResponse extends SharedKittenResponse {
|
|
7
|
+
}
|
|
8
|
+
export type SwapTarget = {
|
|
9
|
+
before?: string;
|
|
10
|
+
} | {
|
|
11
|
+
after?: string;
|
|
12
|
+
} | {
|
|
13
|
+
asFirstChildOf?: string;
|
|
14
|
+
} | {
|
|
15
|
+
asLastChildOf?: string;
|
|
16
|
+
};
|
|
17
|
+
export interface Slot {
|
|
18
|
+
default?: string[] | any[];
|
|
19
|
+
HEAD?: string[];
|
|
20
|
+
START_OF_BODY?: string[];
|
|
21
|
+
END_OF_BODY?: string[];
|
|
22
|
+
BEFORE_LIBRARIES?: string[];
|
|
23
|
+
AFTER_LIBRARIES?: string[];
|
|
24
|
+
HTML?: string;
|
|
25
|
+
[key: string]: any;
|
|
26
|
+
}
|
|
27
|
+
export default class PageRoute extends LazilyLoadedRoute {
|
|
28
|
+
isClassBasedRoute: boolean;
|
|
29
|
+
isLive: boolean;
|
|
30
|
+
source: any;
|
|
31
|
+
url?: string;
|
|
32
|
+
lang: string;
|
|
33
|
+
/**
|
|
34
|
+
One-time lazy initialisation. Imports the handler and,
|
|
35
|
+
if present, the page template.
|
|
36
|
+
*/
|
|
37
|
+
initialise(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
Concrete overload that lazily loads the page route handler
|
|
40
|
+
as necessary and handles requests.
|
|
41
|
+
*/
|
|
42
|
+
lazilyLoadedHandler(request: KittenRequest, response: KittenResponse): Promise<void>;
|
|
43
|
+
renderBaseLayoutComponent({ headSlotOverrides, page, request, SLOT }: {
|
|
44
|
+
headSlotOverrides: Array<string>;
|
|
45
|
+
page: any;
|
|
46
|
+
request: KittenRequest;
|
|
47
|
+
SLOT: Slot;
|
|
48
|
+
}): string;
|
|
49
|
+
/**
|
|
50
|
+
Renders the final HTML given the results of the
|
|
51
|
+
html tagged template function.
|
|
52
|
+
*/
|
|
53
|
+
renderHtml(contents: string | string[] | any, page: any, request: KittenRequest): string;
|
|
54
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import LazilyLoadedRoute from './LazilyLoadedRoute.ts';
|
|
2
|
+
import type { NextHandler } from 'polka';
|
|
3
|
+
import type { KittenRequest, KittenResponse, WebSocket } from '../types/index.ts';
|
|
4
|
+
type WebSocketWithIsAlive = WebSocket & {
|
|
5
|
+
isAlive: boolean;
|
|
6
|
+
id?: string;
|
|
7
|
+
};
|
|
8
|
+
type RequestWithWebSocket = KittenRequest & {
|
|
9
|
+
ws?: () => Promise<any>;
|
|
10
|
+
};
|
|
11
|
+
export default class PageSocketRoute extends LazilyLoadedRoute {
|
|
12
|
+
sockets: WebSocketWithIsAlive[];
|
|
13
|
+
eventHandlers: Record<string, (...args: any[]) => any>;
|
|
14
|
+
initialised: boolean;
|
|
15
|
+
/**
|
|
16
|
+
Create a lazily-loaded PageSocket route instance with the provided file path.
|
|
17
|
+
|
|
18
|
+
(A PageSocket route is a specialised WebSocket route that simplifies streaming
|
|
19
|
+
updates ot the page it is connected to.)
|
|
20
|
+
*/
|
|
21
|
+
constructor(filePath: string, basePath: string);
|
|
22
|
+
/**
|
|
23
|
+
Lazily load the handler.
|
|
24
|
+
|
|
25
|
+
Unlike in other route types, we’re not loading in the default
|
|
26
|
+
export here (our _handler() function is already defined, below) but
|
|
27
|
+
the exported `onConnect()` function from a page route.
|
|
28
|
+
*/
|
|
29
|
+
lazilyLoadedHandler(request: RequestWithWebSocket, response: KittenResponse, next?: NextHandler): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
This is a specialised WebSocket route handler specifically for
|
|
32
|
+
routing to an `onConnect()` handler exported from a page.
|
|
33
|
+
|
|
34
|
+
TODO: Remove redundancy with routes/WebSocketRoute.js
|
|
35
|
+
*/
|
|
36
|
+
_handler({ request, next }: {
|
|
37
|
+
request: RequestWithWebSocket;
|
|
38
|
+
next?: NextHandler;
|
|
39
|
+
[key: string]: any;
|
|
40
|
+
}): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import LazilyLoadedRoute from './LazilyLoadedRoute.ts';
|
|
2
|
+
import type { KittenRequest, KittenResponse } from '../types/index.ts';
|
|
3
|
+
/**
|
|
4
|
+
We convert the file upload metadata returned by Busboy
|
|
5
|
+
to a leaner format that’s more ergonomic when authoring so
|
|
6
|
+
we do a little bit of gymlastics with types so our intent
|
|
7
|
+
is clear and the type checker is happy.
|
|
8
|
+
*/
|
|
9
|
+
type BusboyFileUploadMetadata = {
|
|
10
|
+
uuid: string;
|
|
11
|
+
filename: string;
|
|
12
|
+
file: string;
|
|
13
|
+
mimetype: string;
|
|
14
|
+
field: string;
|
|
15
|
+
encoding: string;
|
|
16
|
+
truncated: boolean;
|
|
17
|
+
done: boolean;
|
|
18
|
+
};
|
|
19
|
+
type OriginalRequest = KittenRequest & {
|
|
20
|
+
files?: Record<string, BusboyFileUploadMetadata | BusboyFileUploadMetadata[]>;
|
|
21
|
+
};
|
|
22
|
+
export declare class Upload {
|
|
23
|
+
id: string;
|
|
24
|
+
fileName: string;
|
|
25
|
+
filePath: string;
|
|
26
|
+
mimetype: string;
|
|
27
|
+
field: string;
|
|
28
|
+
encoding: string;
|
|
29
|
+
truncated: boolean;
|
|
30
|
+
done: boolean;
|
|
31
|
+
constructor(parameters: {
|
|
32
|
+
id: string;
|
|
33
|
+
fileName: string;
|
|
34
|
+
filePath: string;
|
|
35
|
+
mimetype: string;
|
|
36
|
+
field: string;
|
|
37
|
+
encoding: string;
|
|
38
|
+
truncated: boolean;
|
|
39
|
+
done: boolean;
|
|
40
|
+
});
|
|
41
|
+
/**
|
|
42
|
+
Returns absolute resource path for accessing this upload via a GET request
|
|
43
|
+
(content-disposition: inline).
|
|
44
|
+
*/
|
|
45
|
+
get resourcePath(): string;
|
|
46
|
+
/**
|
|
47
|
+
Returns the absolute download path (content-disposition: attachment).
|
|
48
|
+
*/
|
|
49
|
+
get downloadPath(): string;
|
|
50
|
+
/**
|
|
51
|
+
Deletes this uploaded file from the file system and also from the internal database.
|
|
52
|
+
*/
|
|
53
|
+
delete(): Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
export default class PostRoute extends LazilyLoadedRoute {
|
|
56
|
+
_handler: Function | undefined;
|
|
57
|
+
initialise(): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
Concrete overload that lazily loads the POST route handler if
|
|
60
|
+
necessary and handles requests.
|
|
61
|
+
*/
|
|
62
|
+
lazilyLoadedHandler(request: OriginalRequest, response: KittenResponse): Promise<void>;
|
|
63
|
+
}
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { KittenRequest, KittenResponse } from '../types/index.ts';
|
|
2
|
+
export default class StaticRoute {
|
|
3
|
+
filePath: string;
|
|
4
|
+
basePath: string;
|
|
5
|
+
pattern: string;
|
|
6
|
+
method: string;
|
|
7
|
+
/**
|
|
8
|
+
Represents static routes.
|
|
9
|
+
*/
|
|
10
|
+
constructor(filePath: string, basePath: string);
|
|
11
|
+
/**
|
|
12
|
+
This is a simple static file; serve it as such.
|
|
13
|
+
*/
|
|
14
|
+
get handler(): ((request: KittenRequest, response: KittenResponse) => Promise<void>) & {
|
|
15
|
+
filePath?: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import LazilyLoadedRoute from './LazilyLoadedRoute.ts';
|
|
2
|
+
import type { NextHandler } from 'polka';
|
|
3
|
+
import type { KittenRequest, KittenResponse } from '../types/index.ts';
|
|
4
|
+
type RequestWithOptionalWebSocket = KittenRequest & {
|
|
5
|
+
ws?: () => Promise<any>;
|
|
6
|
+
};
|
|
7
|
+
export default class WebSocketRoute extends LazilyLoadedRoute {
|
|
8
|
+
connections: any[];
|
|
9
|
+
__handler: Function | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Create a lazily-loaded WebSocket route instance with the provided file path.
|
|
12
|
+
*/
|
|
13
|
+
constructor(filePath: string, basePath: string);
|
|
14
|
+
lazilyLoadedHandler(request: KittenRequest, response: KittenResponse, next?: NextHandler): Promise<void>;
|
|
15
|
+
_handler({ request, next }: {
|
|
16
|
+
request: RequestWithOptionalWebSocket;
|
|
17
|
+
next?: NextHandler;
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Use either passed singular or plural form based on value of amount.
|
|
3
|
+
*/
|
|
4
|
+
declare const pluralise: (amount: number, singular: string, plural: string) => string;
|
|
5
|
+
/**
|
|
6
|
+
|
|
7
|
+
Validates for HTML and accessibility correctness.
|
|
8
|
+
|
|
9
|
+
@param source - HTML source to validate
|
|
10
|
+
@param filePath - path of current file
|
|
11
|
+
|
|
12
|
+
**/
|
|
13
|
+
declare function validate(source: string, filePath: string): any[];
|
|
14
|
+
/**
|
|
15
|
+
Adds validation support to the passed HTML document.
|
|
16
|
+
*/
|
|
17
|
+
export { pluralise, validate };
|
|
18
|
+
export default function addValidationSupportInDevelopment(htmlDocument: string, filePath: string, url: string): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type Fragment = (props?: {SLOT?: any}) => string
|
|
2
|
+
|
|
3
|
+
declare module '*.fragment.html' {
|
|
4
|
+
const fragment: Fragment
|
|
5
|
+
export default fragment
|
|
6
|
+
}
|
|
7
|
+
declare module '*.fragment.css' {
|
|
8
|
+
const fragment: Fragment
|
|
9
|
+
export default fragment
|
|
10
|
+
}
|
|
11
|
+
declare module '*.fragment.md' {
|
|
12
|
+
const fragment: Fragment
|
|
13
|
+
export default fragment
|
|
14
|
+
}
|