quai-types 0.1.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 +45 -0
- package/dist/index.d.ts +77 -0
- package/dist/index.js +20 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# quai-types
|
|
2
|
+
|
|
3
|
+
Types for [Quai](https://github.com/atinseau/quai) projects.
|
|
4
|
+
|
|
5
|
+
npm install --save-dev quai-types
|
|
6
|
+
|
|
7
|
+
## Functions
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { defineHandler } from "quai-types";
|
|
11
|
+
|
|
12
|
+
export default defineHandler((request, response) => {
|
|
13
|
+
response.end(JSON.stringify({ path: request.url }));
|
|
14
|
+
});
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
On Bun, use `defineBunHandler` and the platform's fetch-style handler:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { defineBunHandler } from "quai-types";
|
|
21
|
+
|
|
22
|
+
export default defineBunHandler((request) =>
|
|
23
|
+
Response.json({ path: new URL(request.url).pathname }),
|
|
24
|
+
);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Manifest
|
|
28
|
+
|
|
29
|
+
`quai.toml` stays the source of truth, but `defineConfig` gives you completion
|
|
30
|
+
and checking while you work out what to put in it:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { defineConfig } from "quai-types";
|
|
34
|
+
|
|
35
|
+
export default defineConfig({
|
|
36
|
+
type: "service",
|
|
37
|
+
runtime: "node",
|
|
38
|
+
service: { internalPort: 8080, start: "node server.js" },
|
|
39
|
+
limits: { memory: "512Mi", cpu: "1" },
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Every helper returns its argument untouched. They exist for the type checker,
|
|
44
|
+
so the code that runs on the server is exactly the code you wrote.
|
|
45
|
+
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for Quai projects.
|
|
3
|
+
*
|
|
4
|
+
* Everything here exists for the type checker and the editor. The helpers
|
|
5
|
+
* return their argument untouched: a wrapper would make the code that runs on
|
|
6
|
+
* the server differ from the code that was written, which is exactly what a
|
|
7
|
+
* typing package should not do.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* The Node request and response, described structurally rather than imported.
|
|
11
|
+
*
|
|
12
|
+
* Importing node:http would force @types/node on everyone, including projects
|
|
13
|
+
* that only deploy a static site or a Bun function. The shape below is what a
|
|
14
|
+
* handler actually uses; a real IncomingMessage satisfies it.
|
|
15
|
+
*/
|
|
16
|
+
export type QuaiRequest = {
|
|
17
|
+
url?: string;
|
|
18
|
+
method?: string;
|
|
19
|
+
headers: Record<string, string | string[] | undefined>;
|
|
20
|
+
on(event: string, listener: (...args: never[]) => void): unknown;
|
|
21
|
+
};
|
|
22
|
+
export type QuaiResponse = {
|
|
23
|
+
statusCode: number;
|
|
24
|
+
setHeader(name: string, value: string | number | readonly string[]): unknown;
|
|
25
|
+
end(body?: string | Uint8Array): unknown;
|
|
26
|
+
write(chunk: string | Uint8Array): unknown;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* A Node function.
|
|
30
|
+
*
|
|
31
|
+
* Quai supplies the server; the handler decides what a request produces. It
|
|
32
|
+
* may be exported as `default` or as `handler`.
|
|
33
|
+
*/
|
|
34
|
+
export type QuaiHandler = (request: QuaiRequest, response: QuaiResponse) => void | Promise<void>;
|
|
35
|
+
/** A Bun function, written against the platform's fetch-style handler. */
|
|
36
|
+
export type QuaiBunHandler = (request: Request) => Response | Promise<Response>;
|
|
37
|
+
/** Identity at runtime; it is the type annotation that does the work. */
|
|
38
|
+
export declare function defineHandler(handler: QuaiHandler): QuaiHandler;
|
|
39
|
+
/** Identity at runtime, as above. */
|
|
40
|
+
export declare function defineBunHandler(handler: QuaiBunHandler): QuaiBunHandler;
|
|
41
|
+
export type ProjectType = "static" | "service" | "function";
|
|
42
|
+
export type Runtime = "node" | "bun" | "python";
|
|
43
|
+
export type QuaiConfig = {
|
|
44
|
+
/** Defaults to the directory name, which is what makes redeploys idempotent. */
|
|
45
|
+
name?: string;
|
|
46
|
+
type: ProjectType;
|
|
47
|
+
runtime?: Runtime;
|
|
48
|
+
/** Runs on your machine. Only the output is uploaded. */
|
|
49
|
+
build?: {
|
|
50
|
+
command?: string;
|
|
51
|
+
/** Directory to ship instead of the whole project. */
|
|
52
|
+
output?: string;
|
|
53
|
+
};
|
|
54
|
+
service?: {
|
|
55
|
+
/** Declared, never guessed: the process listens where it says it does. */
|
|
56
|
+
internalPort?: number;
|
|
57
|
+
start?: string;
|
|
58
|
+
};
|
|
59
|
+
limits?: {
|
|
60
|
+
/** e.g. "256Mi", "1Gi". Absent means Quai's default. */
|
|
61
|
+
memory?: string;
|
|
62
|
+
/** Fraction of a core, e.g. "0.5". */
|
|
63
|
+
cpu?: string;
|
|
64
|
+
/** Maximum processes; this is what stops a fork bomb. */
|
|
65
|
+
pids?: number;
|
|
66
|
+
disk?: string;
|
|
67
|
+
/** Functions only, e.g. "30s". */
|
|
68
|
+
timeout?: string;
|
|
69
|
+
};
|
|
70
|
+
domains?: {
|
|
71
|
+
/** Served alongside the automatic subdomain, never instead of it. */
|
|
72
|
+
custom?: string[];
|
|
73
|
+
};
|
|
74
|
+
env?: Record<string, string>;
|
|
75
|
+
};
|
|
76
|
+
/** Identity at runtime; use it to get completion and checking on a manifest. */
|
|
77
|
+
export declare function defineConfig(config: QuaiConfig): QuaiConfig;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for Quai projects.
|
|
3
|
+
*
|
|
4
|
+
* Everything here exists for the type checker and the editor. The helpers
|
|
5
|
+
* return their argument untouched: a wrapper would make the code that runs on
|
|
6
|
+
* the server differ from the code that was written, which is exactly what a
|
|
7
|
+
* typing package should not do.
|
|
8
|
+
*/
|
|
9
|
+
/** Identity at runtime; it is the type annotation that does the work. */
|
|
10
|
+
export function defineHandler(handler) {
|
|
11
|
+
return handler;
|
|
12
|
+
}
|
|
13
|
+
/** Identity at runtime, as above. */
|
|
14
|
+
export function defineBunHandler(handler) {
|
|
15
|
+
return handler;
|
|
16
|
+
}
|
|
17
|
+
/** Identity at runtime; use it to get completion and checking on a manifest. */
|
|
18
|
+
export function defineConfig(config) {
|
|
19
|
+
return config;
|
|
20
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "quai-types",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Types for Quai projects: handlers and quai.toml",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/atinseau/quai.git",
|
|
9
|
+
"directory": "packages/quai"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"quai",
|
|
13
|
+
"paas",
|
|
14
|
+
"self-hosted",
|
|
15
|
+
"coolify",
|
|
16
|
+
"types"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"main": "./dist/index.js",
|
|
20
|
+
"module": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"README.md"
|
|
31
|
+
],
|
|
32
|
+
"sideEffects": false,
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc -p tsconfig.build.json",
|
|
35
|
+
"prepublishOnly": "npm run build"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"typescript": "^5"
|
|
39
|
+
}
|
|
40
|
+
}
|