@iii-dev/helpers 0.19.4-alpha.2
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/LICENSE.spdx +25 -0
- package/README.md +5 -0
- package/dist/http/index.cjs +46 -0
- package/dist/http/index.cjs.map +1 -0
- package/dist/http/index.d.cts +130 -0
- package/dist/http/index.d.mts +130 -0
- package/dist/http/index.mjs +44 -0
- package/dist/http/index.mjs.map +1 -0
- package/dist/queue/index.cjs +0 -0
- package/dist/queue/index.d.cts +10 -0
- package/dist/queue/index.d.mts +10 -0
- package/dist/queue/index.mjs +1 -0
- package/dist/stream/index.cjs +0 -0
- package/dist/stream/index.d.cts +249 -0
- package/dist/stream/index.d.mts +249 -0
- package/dist/stream/index.mjs +1 -0
- package/dist/worker-connection-manager/index.cjs +0 -0
- package/dist/worker-connection-manager/index.d.cts +95 -0
- package/dist/worker-connection-manager/index.d.mts +95 -0
- package/dist/worker-connection-manager/index.mjs +1 -0
- package/package.json +74 -0
package/LICENSE.spdx
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
SPDXVersion: SPDX-2.3
|
|
2
|
+
DataLicense: CC0-1.0
|
|
3
|
+
SPDXID: SPDXRef-DOCUMENT
|
|
4
|
+
DocumentName: iii
|
|
5
|
+
DocumentNamespace: https://iii.dev/spdx/iii
|
|
6
|
+
PackageName: iii
|
|
7
|
+
SPDXID: SPDXRef-Package
|
|
8
|
+
PackageSupplier: Organization: Motia LLC
|
|
9
|
+
PackageHomePage: https://iii.dev
|
|
10
|
+
PackageLicenseDeclared: Apache-2.0 AND Elastic-2.0
|
|
11
|
+
PackageLicenseConcluded: Apache-2.0 AND Elastic-2.0
|
|
12
|
+
PackageCopyrightText: 2024-present, Motia LLC
|
|
13
|
+
PackageSummary: <text>iii turns distributed backend complexity into a
|
|
14
|
+
simple set of real-time, interoperable primitives called Workers,
|
|
15
|
+
Triggers, and Functions. The result is coordinated execution
|
|
16
|
+
that behaves as if it were a single runtime.
|
|
17
|
+
</text>
|
|
18
|
+
PackageComment: <text>Inbound contributions from external
|
|
19
|
+
contributors are accepted under Apache-2.0 only; see CONTRIBUTING.md.
|
|
20
|
+
</text>
|
|
21
|
+
Created: 2024-01-01T00:00:00Z
|
|
22
|
+
PackageDownloadLocation: git://github.com/iii-hq/iii
|
|
23
|
+
PackageDownloadLocation: git+https://github.com/iii-hq/iii.git
|
|
24
|
+
PackageDownloadLocation: git+ssh://github.com/iii-hq/iii.git
|
|
25
|
+
Creator: Organization: Motia LLC
|
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
//#region src/http/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* Helper that wraps an HTTP-style handler (with separate `req`/`res` arguments)
|
|
6
|
+
* into the function handler format expected by the SDK.
|
|
7
|
+
*
|
|
8
|
+
* @param callback - Async handler receiving a streaming request and response.
|
|
9
|
+
* @returns A function handler compatible with `IIIClient.registerFunction`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { http } from '@iii-dev/helpers/http'
|
|
14
|
+
*
|
|
15
|
+
* iii.registerFunction(
|
|
16
|
+
* 'my-api',
|
|
17
|
+
* http(async (req, res) => {
|
|
18
|
+
* res.status(200)
|
|
19
|
+
* res.headers({ 'content-type': 'application/json' })
|
|
20
|
+
* res.stream.end(JSON.stringify({ hello: 'world' }))
|
|
21
|
+
* res.close()
|
|
22
|
+
* }),
|
|
23
|
+
* )
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
const http = (callback) => {
|
|
27
|
+
return async (req) => {
|
|
28
|
+
const { response, ...request } = req;
|
|
29
|
+
return callback(request, {
|
|
30
|
+
status: (status_code) => response.sendMessage(JSON.stringify({
|
|
31
|
+
type: "set_status",
|
|
32
|
+
status_code
|
|
33
|
+
})),
|
|
34
|
+
headers: (headers) => response.sendMessage(JSON.stringify({
|
|
35
|
+
type: "set_headers",
|
|
36
|
+
headers
|
|
37
|
+
})),
|
|
38
|
+
stream: response.stream,
|
|
39
|
+
close: () => response.close()
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
exports.http = http;
|
|
46
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/http/index.ts"],"sourcesContent":["/**\n * HTTP method accepted by {@link HttpInvocationConfig}. Distinct from the core\n * `builtin_triggers` HTTP method enum, which also covers HEAD/OPTIONS.\n */\nexport type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'\n\n/**\n * Authentication configuration for HTTP-invoked functions.\n *\n * - `hmac` -- HMAC signature verification using a shared secret.\n * - `bearer` -- Bearer token authentication.\n * - `api_key` -- API key sent via a custom header.\n */\nexport type HttpAuthConfig =\n | { type: 'hmac'; secret_key: string }\n | { type: 'bearer'; token_key: string }\n | { type: 'api_key'; header: string; value_key: string }\n\n/**\n * Configuration for registering an HTTP-invoked function (Lambda, Cloudflare\n * Workers, etc.) instead of a local handler.\n */\nexport type HttpInvocationConfig = {\n /** URL to invoke. */\n url: string\n /** HTTP method. Defaults to `POST`. */\n method?: HttpMethod\n /** Timeout in milliseconds. */\n timeout_ms?: number\n /** Custom headers to send with the request. */\n headers?: Record<string, string>\n /** Authentication configuration. */\n auth?: HttpAuthConfig\n}\n\n/**\n * Incoming buffered HTTP request received by a function handler.\n *\n * @typeParam TBody - Type of the parsed request body.\n */\nexport type HttpRequest<TBody = unknown> = {\n path_params: Record<string, string>\n query_params: Record<string, string | string[]>\n body: TBody\n headers: Record<string, string | string[]>\n method: string\n request_body: HttpStreamReader\n}\n\n/**\n * Structured buffered HTTP response returned from function handlers.\n *\n * @typeParam TStatus - HTTP status code literal type.\n * @typeParam TBody - Type of the response body.\n *\n * @example\n * ```typescript\n * const response: HttpResponse = {\n * status_code: 200,\n * headers: { 'content-type': 'application/json' },\n * body: { message: 'ok' },\n * }\n * ```\n */\nexport type HttpResponse<\n TStatus extends number = number,\n TBody = string | Buffer | Record<string, unknown>,\n> = {\n /** HTTP status code. */\n status_code: TStatus\n /** Response headers. */\n headers?: Record<string, string>\n /** Response body. */\n body?: TBody\n}\n\n/**\n * Structural shape of the reader end of a stream channel. Declared locally so\n * the helpers package does not runtime-depend on the core SDK.\n */\ntype HttpStreamReader = {\n stream: NodeJS.ReadableStream\n readAll: () => Promise<Buffer>\n onMessage: (callback: (msg: string) => void) => void\n close: () => void\n}\n\n/** Structural shape of the writer end of a stream channel. */\ntype HttpStreamWriter = {\n sendMessage: (message: string) => unknown\n stream: NodeJS.WritableStream\n close: () => unknown\n}\n\n/** Structural shape of a streaming request passed to the {@link http} handler. */\ntype HttpStreamingRequest = {\n path_params: Record<string, string>\n query_params: Record<string, string | string[]>\n body: unknown\n headers: Record<string, string | string[]>\n method: string\n request_body: HttpStreamReader\n}\n\n/** Structural shape of the streaming response passed to the {@link http} handler. */\ntype HttpStreamingResponse = {\n status: (statusCode: number) => void\n headers: (headers: Record<string, string>) => void\n stream: NodeJS.WritableStream\n close: () => void\n}\n\n/** Structural shape of the internal request delivered by the runtime. */\ntype HttpInternalRequest = HttpStreamingRequest & { response: HttpStreamWriter }\n\n/**\n * Helper that wraps an HTTP-style handler (with separate `req`/`res` arguments)\n * into the function handler format expected by the SDK.\n *\n * @param callback - Async handler receiving a streaming request and response.\n * @returns A function handler compatible with `IIIClient.registerFunction`.\n *\n * @example\n * ```typescript\n * import { http } from '@iii-dev/helpers/http'\n *\n * iii.registerFunction(\n * 'my-api',\n * http(async (req, res) => {\n * res.status(200)\n * res.headers({ 'content-type': 'application/json' })\n * res.stream.end(JSON.stringify({ hello: 'world' }))\n * res.close()\n * }),\n * )\n * ```\n */\nexport const http = (\n // biome-ignore lint/suspicious/noConfusingVoidType: void is necessary here\n callback: (req: HttpStreamingRequest, res: HttpStreamingResponse) => Promise<void | HttpResponse>,\n) => {\n return async (req: HttpInternalRequest) => {\n const { response, ...request } = req\n\n const httpResponse: HttpStreamingResponse = {\n status: (status_code: number) =>\n response.sendMessage(JSON.stringify({ type: 'set_status', status_code })),\n headers: (headers: Record<string, string>) =>\n response.sendMessage(JSON.stringify({ type: 'set_headers', headers })),\n stream: response.stream,\n close: () => response.close(),\n }\n\n return callback(request, httpResponse)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyIA,MAAa,QAEX,aACG;AACH,QAAO,OAAO,QAA6B;EACzC,MAAM,EAAE,UAAU,GAAG,YAAY;AAWjC,SAAO,SAAS,SAT4B;GAC1C,SAAS,gBACP,SAAS,YAAY,KAAK,UAAU;IAAE,MAAM;IAAc;IAAa,CAAC,CAAC;GAC3E,UAAU,YACR,SAAS,YAAY,KAAK,UAAU;IAAE,MAAM;IAAe;IAAS,CAAC,CAAC;GACxE,QAAQ,SAAS;GACjB,aAAa,SAAS,OAAO;GAC9B,CAEqC"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
//#region src/http/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* HTTP method accepted by {@link HttpInvocationConfig}. Distinct from the core
|
|
4
|
+
* `builtin_triggers` HTTP method enum, which also covers HEAD/OPTIONS.
|
|
5
|
+
*/
|
|
6
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
7
|
+
/**
|
|
8
|
+
* Authentication configuration for HTTP-invoked functions.
|
|
9
|
+
*
|
|
10
|
+
* - `hmac` -- HMAC signature verification using a shared secret.
|
|
11
|
+
* - `bearer` -- Bearer token authentication.
|
|
12
|
+
* - `api_key` -- API key sent via a custom header.
|
|
13
|
+
*/
|
|
14
|
+
type HttpAuthConfig = {
|
|
15
|
+
type: 'hmac';
|
|
16
|
+
secret_key: string;
|
|
17
|
+
} | {
|
|
18
|
+
type: 'bearer';
|
|
19
|
+
token_key: string;
|
|
20
|
+
} | {
|
|
21
|
+
type: 'api_key';
|
|
22
|
+
header: string;
|
|
23
|
+
value_key: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Configuration for registering an HTTP-invoked function (Lambda, Cloudflare
|
|
27
|
+
* Workers, etc.) instead of a local handler.
|
|
28
|
+
*/
|
|
29
|
+
type HttpInvocationConfig = {
|
|
30
|
+
/** URL to invoke. */url: string; /** HTTP method. Defaults to `POST`. */
|
|
31
|
+
method?: HttpMethod; /** Timeout in milliseconds. */
|
|
32
|
+
timeout_ms?: number; /** Custom headers to send with the request. */
|
|
33
|
+
headers?: Record<string, string>; /** Authentication configuration. */
|
|
34
|
+
auth?: HttpAuthConfig;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Incoming buffered HTTP request received by a function handler.
|
|
38
|
+
*
|
|
39
|
+
* @typeParam TBody - Type of the parsed request body.
|
|
40
|
+
*/
|
|
41
|
+
type HttpRequest<TBody = unknown> = {
|
|
42
|
+
path_params: Record<string, string>;
|
|
43
|
+
query_params: Record<string, string | string[]>;
|
|
44
|
+
body: TBody;
|
|
45
|
+
headers: Record<string, string | string[]>;
|
|
46
|
+
method: string;
|
|
47
|
+
request_body: HttpStreamReader;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Structured buffered HTTP response returned from function handlers.
|
|
51
|
+
*
|
|
52
|
+
* @typeParam TStatus - HTTP status code literal type.
|
|
53
|
+
* @typeParam TBody - Type of the response body.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const response: HttpResponse = {
|
|
58
|
+
* status_code: 200,
|
|
59
|
+
* headers: { 'content-type': 'application/json' },
|
|
60
|
+
* body: { message: 'ok' },
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
type HttpResponse<TStatus extends number = number, TBody = string | Buffer | Record<string, unknown>> = {
|
|
65
|
+
/** HTTP status code. */status_code: TStatus; /** Response headers. */
|
|
66
|
+
headers?: Record<string, string>; /** Response body. */
|
|
67
|
+
body?: TBody;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Structural shape of the reader end of a stream channel. Declared locally so
|
|
71
|
+
* the helpers package does not runtime-depend on the core SDK.
|
|
72
|
+
*/
|
|
73
|
+
type HttpStreamReader = {
|
|
74
|
+
stream: NodeJS.ReadableStream;
|
|
75
|
+
readAll: () => Promise<Buffer>;
|
|
76
|
+
onMessage: (callback: (msg: string) => void) => void;
|
|
77
|
+
close: () => void;
|
|
78
|
+
};
|
|
79
|
+
/** Structural shape of the writer end of a stream channel. */
|
|
80
|
+
type HttpStreamWriter = {
|
|
81
|
+
sendMessage: (message: string) => unknown;
|
|
82
|
+
stream: NodeJS.WritableStream;
|
|
83
|
+
close: () => unknown;
|
|
84
|
+
};
|
|
85
|
+
/** Structural shape of a streaming request passed to the {@link http} handler. */
|
|
86
|
+
type HttpStreamingRequest = {
|
|
87
|
+
path_params: Record<string, string>;
|
|
88
|
+
query_params: Record<string, string | string[]>;
|
|
89
|
+
body: unknown;
|
|
90
|
+
headers: Record<string, string | string[]>;
|
|
91
|
+
method: string;
|
|
92
|
+
request_body: HttpStreamReader;
|
|
93
|
+
};
|
|
94
|
+
/** Structural shape of the streaming response passed to the {@link http} handler. */
|
|
95
|
+
type HttpStreamingResponse = {
|
|
96
|
+
status: (statusCode: number) => void;
|
|
97
|
+
headers: (headers: Record<string, string>) => void;
|
|
98
|
+
stream: NodeJS.WritableStream;
|
|
99
|
+
close: () => void;
|
|
100
|
+
};
|
|
101
|
+
/** Structural shape of the internal request delivered by the runtime. */
|
|
102
|
+
type HttpInternalRequest = HttpStreamingRequest & {
|
|
103
|
+
response: HttpStreamWriter;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Helper that wraps an HTTP-style handler (with separate `req`/`res` arguments)
|
|
107
|
+
* into the function handler format expected by the SDK.
|
|
108
|
+
*
|
|
109
|
+
* @param callback - Async handler receiving a streaming request and response.
|
|
110
|
+
* @returns A function handler compatible with `IIIClient.registerFunction`.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* import { http } from '@iii-dev/helpers/http'
|
|
115
|
+
*
|
|
116
|
+
* iii.registerFunction(
|
|
117
|
+
* 'my-api',
|
|
118
|
+
* http(async (req, res) => {
|
|
119
|
+
* res.status(200)
|
|
120
|
+
* res.headers({ 'content-type': 'application/json' })
|
|
121
|
+
* res.stream.end(JSON.stringify({ hello: 'world' }))
|
|
122
|
+
* res.close()
|
|
123
|
+
* }),
|
|
124
|
+
* )
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
declare const http: (callback: (req: HttpStreamingRequest, res: HttpStreamingResponse) => Promise<void | HttpResponse>) => (req: HttpInternalRequest) => Promise<void | HttpResponse<number, string | Buffer<ArrayBufferLike> | Record<string, unknown>>>;
|
|
128
|
+
//#endregion
|
|
129
|
+
export { HttpAuthConfig, HttpInvocationConfig, HttpMethod, HttpRequest, HttpResponse, http };
|
|
130
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
//#region src/http/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* HTTP method accepted by {@link HttpInvocationConfig}. Distinct from the core
|
|
4
|
+
* `builtin_triggers` HTTP method enum, which also covers HEAD/OPTIONS.
|
|
5
|
+
*/
|
|
6
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
7
|
+
/**
|
|
8
|
+
* Authentication configuration for HTTP-invoked functions.
|
|
9
|
+
*
|
|
10
|
+
* - `hmac` -- HMAC signature verification using a shared secret.
|
|
11
|
+
* - `bearer` -- Bearer token authentication.
|
|
12
|
+
* - `api_key` -- API key sent via a custom header.
|
|
13
|
+
*/
|
|
14
|
+
type HttpAuthConfig = {
|
|
15
|
+
type: 'hmac';
|
|
16
|
+
secret_key: string;
|
|
17
|
+
} | {
|
|
18
|
+
type: 'bearer';
|
|
19
|
+
token_key: string;
|
|
20
|
+
} | {
|
|
21
|
+
type: 'api_key';
|
|
22
|
+
header: string;
|
|
23
|
+
value_key: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Configuration for registering an HTTP-invoked function (Lambda, Cloudflare
|
|
27
|
+
* Workers, etc.) instead of a local handler.
|
|
28
|
+
*/
|
|
29
|
+
type HttpInvocationConfig = {
|
|
30
|
+
/** URL to invoke. */url: string; /** HTTP method. Defaults to `POST`. */
|
|
31
|
+
method?: HttpMethod; /** Timeout in milliseconds. */
|
|
32
|
+
timeout_ms?: number; /** Custom headers to send with the request. */
|
|
33
|
+
headers?: Record<string, string>; /** Authentication configuration. */
|
|
34
|
+
auth?: HttpAuthConfig;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Incoming buffered HTTP request received by a function handler.
|
|
38
|
+
*
|
|
39
|
+
* @typeParam TBody - Type of the parsed request body.
|
|
40
|
+
*/
|
|
41
|
+
type HttpRequest<TBody = unknown> = {
|
|
42
|
+
path_params: Record<string, string>;
|
|
43
|
+
query_params: Record<string, string | string[]>;
|
|
44
|
+
body: TBody;
|
|
45
|
+
headers: Record<string, string | string[]>;
|
|
46
|
+
method: string;
|
|
47
|
+
request_body: HttpStreamReader;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Structured buffered HTTP response returned from function handlers.
|
|
51
|
+
*
|
|
52
|
+
* @typeParam TStatus - HTTP status code literal type.
|
|
53
|
+
* @typeParam TBody - Type of the response body.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const response: HttpResponse = {
|
|
58
|
+
* status_code: 200,
|
|
59
|
+
* headers: { 'content-type': 'application/json' },
|
|
60
|
+
* body: { message: 'ok' },
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
type HttpResponse<TStatus extends number = number, TBody = string | Buffer | Record<string, unknown>> = {
|
|
65
|
+
/** HTTP status code. */status_code: TStatus; /** Response headers. */
|
|
66
|
+
headers?: Record<string, string>; /** Response body. */
|
|
67
|
+
body?: TBody;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Structural shape of the reader end of a stream channel. Declared locally so
|
|
71
|
+
* the helpers package does not runtime-depend on the core SDK.
|
|
72
|
+
*/
|
|
73
|
+
type HttpStreamReader = {
|
|
74
|
+
stream: NodeJS.ReadableStream;
|
|
75
|
+
readAll: () => Promise<Buffer>;
|
|
76
|
+
onMessage: (callback: (msg: string) => void) => void;
|
|
77
|
+
close: () => void;
|
|
78
|
+
};
|
|
79
|
+
/** Structural shape of the writer end of a stream channel. */
|
|
80
|
+
type HttpStreamWriter = {
|
|
81
|
+
sendMessage: (message: string) => unknown;
|
|
82
|
+
stream: NodeJS.WritableStream;
|
|
83
|
+
close: () => unknown;
|
|
84
|
+
};
|
|
85
|
+
/** Structural shape of a streaming request passed to the {@link http} handler. */
|
|
86
|
+
type HttpStreamingRequest = {
|
|
87
|
+
path_params: Record<string, string>;
|
|
88
|
+
query_params: Record<string, string | string[]>;
|
|
89
|
+
body: unknown;
|
|
90
|
+
headers: Record<string, string | string[]>;
|
|
91
|
+
method: string;
|
|
92
|
+
request_body: HttpStreamReader;
|
|
93
|
+
};
|
|
94
|
+
/** Structural shape of the streaming response passed to the {@link http} handler. */
|
|
95
|
+
type HttpStreamingResponse = {
|
|
96
|
+
status: (statusCode: number) => void;
|
|
97
|
+
headers: (headers: Record<string, string>) => void;
|
|
98
|
+
stream: NodeJS.WritableStream;
|
|
99
|
+
close: () => void;
|
|
100
|
+
};
|
|
101
|
+
/** Structural shape of the internal request delivered by the runtime. */
|
|
102
|
+
type HttpInternalRequest = HttpStreamingRequest & {
|
|
103
|
+
response: HttpStreamWriter;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Helper that wraps an HTTP-style handler (with separate `req`/`res` arguments)
|
|
107
|
+
* into the function handler format expected by the SDK.
|
|
108
|
+
*
|
|
109
|
+
* @param callback - Async handler receiving a streaming request and response.
|
|
110
|
+
* @returns A function handler compatible with `IIIClient.registerFunction`.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* import { http } from '@iii-dev/helpers/http'
|
|
115
|
+
*
|
|
116
|
+
* iii.registerFunction(
|
|
117
|
+
* 'my-api',
|
|
118
|
+
* http(async (req, res) => {
|
|
119
|
+
* res.status(200)
|
|
120
|
+
* res.headers({ 'content-type': 'application/json' })
|
|
121
|
+
* res.stream.end(JSON.stringify({ hello: 'world' }))
|
|
122
|
+
* res.close()
|
|
123
|
+
* }),
|
|
124
|
+
* )
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
declare const http: (callback: (req: HttpStreamingRequest, res: HttpStreamingResponse) => Promise<void | HttpResponse>) => (req: HttpInternalRequest) => Promise<void | HttpResponse<number, string | Buffer<ArrayBufferLike> | Record<string, unknown>>>;
|
|
128
|
+
//#endregion
|
|
129
|
+
export { HttpAuthConfig, HttpInvocationConfig, HttpMethod, HttpRequest, HttpResponse, http };
|
|
130
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//#region src/http/index.ts
|
|
2
|
+
/**
|
|
3
|
+
* Helper that wraps an HTTP-style handler (with separate `req`/`res` arguments)
|
|
4
|
+
* into the function handler format expected by the SDK.
|
|
5
|
+
*
|
|
6
|
+
* @param callback - Async handler receiving a streaming request and response.
|
|
7
|
+
* @returns A function handler compatible with `IIIClient.registerFunction`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { http } from '@iii-dev/helpers/http'
|
|
12
|
+
*
|
|
13
|
+
* iii.registerFunction(
|
|
14
|
+
* 'my-api',
|
|
15
|
+
* http(async (req, res) => {
|
|
16
|
+
* res.status(200)
|
|
17
|
+
* res.headers({ 'content-type': 'application/json' })
|
|
18
|
+
* res.stream.end(JSON.stringify({ hello: 'world' }))
|
|
19
|
+
* res.close()
|
|
20
|
+
* }),
|
|
21
|
+
* )
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
const http = (callback) => {
|
|
25
|
+
return async (req) => {
|
|
26
|
+
const { response, ...request } = req;
|
|
27
|
+
return callback(request, {
|
|
28
|
+
status: (status_code) => response.sendMessage(JSON.stringify({
|
|
29
|
+
type: "set_status",
|
|
30
|
+
status_code
|
|
31
|
+
})),
|
|
32
|
+
headers: (headers) => response.sendMessage(JSON.stringify({
|
|
33
|
+
type: "set_headers",
|
|
34
|
+
headers
|
|
35
|
+
})),
|
|
36
|
+
stream: response.stream,
|
|
37
|
+
close: () => response.close()
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
export { http };
|
|
44
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/http/index.ts"],"sourcesContent":["/**\n * HTTP method accepted by {@link HttpInvocationConfig}. Distinct from the core\n * `builtin_triggers` HTTP method enum, which also covers HEAD/OPTIONS.\n */\nexport type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'\n\n/**\n * Authentication configuration for HTTP-invoked functions.\n *\n * - `hmac` -- HMAC signature verification using a shared secret.\n * - `bearer` -- Bearer token authentication.\n * - `api_key` -- API key sent via a custom header.\n */\nexport type HttpAuthConfig =\n | { type: 'hmac'; secret_key: string }\n | { type: 'bearer'; token_key: string }\n | { type: 'api_key'; header: string; value_key: string }\n\n/**\n * Configuration for registering an HTTP-invoked function (Lambda, Cloudflare\n * Workers, etc.) instead of a local handler.\n */\nexport type HttpInvocationConfig = {\n /** URL to invoke. */\n url: string\n /** HTTP method. Defaults to `POST`. */\n method?: HttpMethod\n /** Timeout in milliseconds. */\n timeout_ms?: number\n /** Custom headers to send with the request. */\n headers?: Record<string, string>\n /** Authentication configuration. */\n auth?: HttpAuthConfig\n}\n\n/**\n * Incoming buffered HTTP request received by a function handler.\n *\n * @typeParam TBody - Type of the parsed request body.\n */\nexport type HttpRequest<TBody = unknown> = {\n path_params: Record<string, string>\n query_params: Record<string, string | string[]>\n body: TBody\n headers: Record<string, string | string[]>\n method: string\n request_body: HttpStreamReader\n}\n\n/**\n * Structured buffered HTTP response returned from function handlers.\n *\n * @typeParam TStatus - HTTP status code literal type.\n * @typeParam TBody - Type of the response body.\n *\n * @example\n * ```typescript\n * const response: HttpResponse = {\n * status_code: 200,\n * headers: { 'content-type': 'application/json' },\n * body: { message: 'ok' },\n * }\n * ```\n */\nexport type HttpResponse<\n TStatus extends number = number,\n TBody = string | Buffer | Record<string, unknown>,\n> = {\n /** HTTP status code. */\n status_code: TStatus\n /** Response headers. */\n headers?: Record<string, string>\n /** Response body. */\n body?: TBody\n}\n\n/**\n * Structural shape of the reader end of a stream channel. Declared locally so\n * the helpers package does not runtime-depend on the core SDK.\n */\ntype HttpStreamReader = {\n stream: NodeJS.ReadableStream\n readAll: () => Promise<Buffer>\n onMessage: (callback: (msg: string) => void) => void\n close: () => void\n}\n\n/** Structural shape of the writer end of a stream channel. */\ntype HttpStreamWriter = {\n sendMessage: (message: string) => unknown\n stream: NodeJS.WritableStream\n close: () => unknown\n}\n\n/** Structural shape of a streaming request passed to the {@link http} handler. */\ntype HttpStreamingRequest = {\n path_params: Record<string, string>\n query_params: Record<string, string | string[]>\n body: unknown\n headers: Record<string, string | string[]>\n method: string\n request_body: HttpStreamReader\n}\n\n/** Structural shape of the streaming response passed to the {@link http} handler. */\ntype HttpStreamingResponse = {\n status: (statusCode: number) => void\n headers: (headers: Record<string, string>) => void\n stream: NodeJS.WritableStream\n close: () => void\n}\n\n/** Structural shape of the internal request delivered by the runtime. */\ntype HttpInternalRequest = HttpStreamingRequest & { response: HttpStreamWriter }\n\n/**\n * Helper that wraps an HTTP-style handler (with separate `req`/`res` arguments)\n * into the function handler format expected by the SDK.\n *\n * @param callback - Async handler receiving a streaming request and response.\n * @returns A function handler compatible with `IIIClient.registerFunction`.\n *\n * @example\n * ```typescript\n * import { http } from '@iii-dev/helpers/http'\n *\n * iii.registerFunction(\n * 'my-api',\n * http(async (req, res) => {\n * res.status(200)\n * res.headers({ 'content-type': 'application/json' })\n * res.stream.end(JSON.stringify({ hello: 'world' }))\n * res.close()\n * }),\n * )\n * ```\n */\nexport const http = (\n // biome-ignore lint/suspicious/noConfusingVoidType: void is necessary here\n callback: (req: HttpStreamingRequest, res: HttpStreamingResponse) => Promise<void | HttpResponse>,\n) => {\n return async (req: HttpInternalRequest) => {\n const { response, ...request } = req\n\n const httpResponse: HttpStreamingResponse = {\n status: (status_code: number) =>\n response.sendMessage(JSON.stringify({ type: 'set_status', status_code })),\n headers: (headers: Record<string, string>) =>\n response.sendMessage(JSON.stringify({ type: 'set_headers', headers })),\n stream: response.stream,\n close: () => response.close(),\n }\n\n return callback(request, httpResponse)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAyIA,MAAa,QAEX,aACG;AACH,QAAO,OAAO,QAA6B;EACzC,MAAM,EAAE,UAAU,GAAG,YAAY;AAWjC,SAAO,SAAS,SAT4B;GAC1C,SAAS,gBACP,SAAS,YAAY,KAAK,UAAU;IAAE,MAAM;IAAc;IAAa,CAAC,CAAC;GAC3E,UAAU,YACR,SAAS,YAAY,KAAK,UAAU;IAAE,MAAM;IAAe;IAAS,CAAC,CAAC;GACxE,QAAQ,SAAS;GACjB,aAAa,SAAS,OAAO;GAC9B,CAEqC"}
|
|
File without changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/queue/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Result returned when a function is invoked with `TriggerAction.Enqueue`.
|
|
4
|
+
*/
|
|
5
|
+
type EnqueueResult = {
|
|
6
|
+
/** Unique receipt ID for the enqueued message. */messageReceiptId: string;
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { EnqueueResult };
|
|
10
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/queue/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Result returned when a function is invoked with `TriggerAction.Enqueue`.
|
|
4
|
+
*/
|
|
5
|
+
type EnqueueResult = {
|
|
6
|
+
/** Unique receipt ID for the enqueued message. */messageReceiptId: string;
|
|
7
|
+
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { EnqueueResult };
|
|
10
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
File without changes
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
//#region src/stream/index.d.ts
|
|
2
|
+
/** Input for stream authentication. */
|
|
3
|
+
interface StreamAuthInput {
|
|
4
|
+
/** Request headers. */
|
|
5
|
+
headers: Record<string, string>;
|
|
6
|
+
/** Request path. */
|
|
7
|
+
path: string;
|
|
8
|
+
/** Query parameters. */
|
|
9
|
+
query_params: Record<string, string[]>;
|
|
10
|
+
/** Client address. */
|
|
11
|
+
addr: string;
|
|
12
|
+
}
|
|
13
|
+
/** Result of stream authentication. */
|
|
14
|
+
interface StreamAuthResult {
|
|
15
|
+
/** Arbitrary context passed to stream handlers after authentication. */
|
|
16
|
+
context?: any;
|
|
17
|
+
}
|
|
18
|
+
/** Context type extracted from {@link StreamAuthResult}. */
|
|
19
|
+
type StreamContext = StreamAuthResult['context'];
|
|
20
|
+
/** Event payload for stream join/leave events. */
|
|
21
|
+
interface StreamJoinLeaveEvent {
|
|
22
|
+
/** Unique subscription identifier. */
|
|
23
|
+
subscription_id: string;
|
|
24
|
+
/** Name of the stream. */
|
|
25
|
+
stream_name: string;
|
|
26
|
+
/** Group identifier. */
|
|
27
|
+
group_id: string;
|
|
28
|
+
/** Item identifier (if applicable). */
|
|
29
|
+
id?: string;
|
|
30
|
+
/** Auth context from {@link StreamAuthResult}. */
|
|
31
|
+
context?: StreamContext;
|
|
32
|
+
}
|
|
33
|
+
/** Result of a stream join request. */
|
|
34
|
+
interface StreamJoinResult {
|
|
35
|
+
/** Whether the join was unauthorized. */
|
|
36
|
+
unauthorized: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** Input for retrieving a single stream item. */
|
|
39
|
+
type StreamGetInput = {
|
|
40
|
+
/** Name of the stream. */stream_name: string; /** Group identifier. */
|
|
41
|
+
group_id: string; /** Item identifier. */
|
|
42
|
+
item_id: string;
|
|
43
|
+
};
|
|
44
|
+
/** Input for setting a stream item. */
|
|
45
|
+
type StreamSetInput = {
|
|
46
|
+
/** Name of the stream. */stream_name: string; /** Group identifier. */
|
|
47
|
+
group_id: string; /** Item identifier. */
|
|
48
|
+
item_id: string; /** Data to store. */
|
|
49
|
+
data: any;
|
|
50
|
+
};
|
|
51
|
+
/** Input for deleting a stream item. */
|
|
52
|
+
type StreamDeleteInput = {
|
|
53
|
+
/** Name of the stream. */stream_name: string; /** Group identifier. */
|
|
54
|
+
group_id: string; /** Item identifier. */
|
|
55
|
+
item_id: string;
|
|
56
|
+
};
|
|
57
|
+
/** Input for listing all items in a stream group. */
|
|
58
|
+
type StreamListInput = {
|
|
59
|
+
/** Name of the stream. */stream_name: string; /** Group identifier. */
|
|
60
|
+
group_id: string;
|
|
61
|
+
};
|
|
62
|
+
/** Input for listing all groups in a stream. */
|
|
63
|
+
type StreamListGroupsInput = {
|
|
64
|
+
/** Name of the stream. */stream_name: string;
|
|
65
|
+
};
|
|
66
|
+
/** Result of a stream set operation. */
|
|
67
|
+
type StreamSetResult<TData> = {
|
|
68
|
+
/** Previous value (if it existed). */old_value?: TData; /** New value that was stored. */
|
|
69
|
+
new_value: TData;
|
|
70
|
+
};
|
|
71
|
+
/** Result of a stream update operation. */
|
|
72
|
+
type StreamUpdateResult<TData> = {
|
|
73
|
+
/** Previous value (if it existed). */old_value?: TData; /** New value after the update. */
|
|
74
|
+
new_value: TData;
|
|
75
|
+
/**
|
|
76
|
+
* Per-op errors. Emitted by `merge` and `append` for validation
|
|
77
|
+
* rejections (path depth/size, value depth, or a
|
|
78
|
+
* `__proto__`/`constructor`/`prototype` segment or top-level key)
|
|
79
|
+
* and by `append` for the case-2 `append.type_mismatch` and
|
|
80
|
+
* `append.target_not_object` surfaces. Successfully applied ops are
|
|
81
|
+
* still reflected in `new_value`. The field is omitted from the
|
|
82
|
+
* JSON wire when empty.
|
|
83
|
+
*/
|
|
84
|
+
errors?: UpdateOpError[];
|
|
85
|
+
};
|
|
86
|
+
/** Set a field at the given path to a value. */
|
|
87
|
+
type UpdateSet = {
|
|
88
|
+
type: 'set'; /** First-level field path. Use an empty string to target the root value. */
|
|
89
|
+
path: string; /** Value to set. */
|
|
90
|
+
value: any;
|
|
91
|
+
};
|
|
92
|
+
/** Increment a numeric field by a given amount. */
|
|
93
|
+
type UpdateIncrement = {
|
|
94
|
+
type: 'increment'; /** First-level field path. */
|
|
95
|
+
path: string; /** Amount to increment by. */
|
|
96
|
+
by: number;
|
|
97
|
+
};
|
|
98
|
+
/** Decrement a numeric field by a given amount. */
|
|
99
|
+
type UpdateDecrement = {
|
|
100
|
+
type: 'decrement'; /** First-level field path. */
|
|
101
|
+
path: string; /** Amount to decrement by. */
|
|
102
|
+
by: number;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Append an element to an array, concatenate a string, or push a new
|
|
106
|
+
* value at a nested path. The target is the root (when `path` is
|
|
107
|
+
* omitted, empty, or `[]`), a single first-level key (when `path` is
|
|
108
|
+
* a non-empty string), or an arbitrary nested location (when `path`
|
|
109
|
+
* is an array of literal segments).
|
|
110
|
+
*
|
|
111
|
+
* Engine semantics:
|
|
112
|
+
* - Missing or non-object intermediates along a nested path are
|
|
113
|
+
* auto-replaced with `{}` so a stray `null` or scalar never blocks
|
|
114
|
+
* future appends.
|
|
115
|
+
* - At the leaf:
|
|
116
|
+
* - missing/null + nested path → `[value]` (always an array)
|
|
117
|
+
* - missing/null + single-string path → string-as-string for the
|
|
118
|
+
* string-concat tier, otherwise `[value]`
|
|
119
|
+
* - existing array → push
|
|
120
|
+
* - existing string + string value → concatenate
|
|
121
|
+
* - existing object/scalar at the leaf → `append.type_mismatch`
|
|
122
|
+
* - Each path segment is a literal key. `["a.b"]` targets a single
|
|
123
|
+
* key named `"a.b"`, not `a → b`.
|
|
124
|
+
*
|
|
125
|
+
* Validation: invalid paths (depth > 32 segments, segment > 256
|
|
126
|
+
* bytes, or any `__proto__`/`constructor`/`prototype` segment) are
|
|
127
|
+
* rejected with a structured error in the `errors` field of the
|
|
128
|
+
* `state::update` / `stream::update` response. The append does not
|
|
129
|
+
* apply when an error is returned for that op.
|
|
130
|
+
*/
|
|
131
|
+
type UpdateAppend = {
|
|
132
|
+
type: 'append';
|
|
133
|
+
/**
|
|
134
|
+
* Optional path to the append target. Accepts a single first-level
|
|
135
|
+
* key (legacy `string`) or an array of literal segments for nested
|
|
136
|
+
* append. See {@link MergePath} (the same shape is reused).
|
|
137
|
+
*/
|
|
138
|
+
path?: MergePath; /** Value to append. String targets only accept string values. */
|
|
139
|
+
value: any;
|
|
140
|
+
};
|
|
141
|
+
/** Remove a field at the given path. */
|
|
142
|
+
type UpdateRemove = {
|
|
143
|
+
type: 'remove'; /** First-level field path. */
|
|
144
|
+
path: string;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Path target for a {@link UpdateMerge} op. Accepts:
|
|
148
|
+
* - a single string (legacy / first-level field)
|
|
149
|
+
* - an array of literal segments (nested path; each element is one
|
|
150
|
+
* literal key, dots are NOT interpreted as separators)
|
|
151
|
+
*
|
|
152
|
+
* Omit `path`, pass `""`, or pass `[]` to target the root value.
|
|
153
|
+
*
|
|
154
|
+
* @example single first-level field
|
|
155
|
+
* { type: 'merge', path: 'session-abc', value: { author: 'alice' } }
|
|
156
|
+
* @example nested path (closes issue #1546's structured-state use case)
|
|
157
|
+
* { type: 'merge', path: ['sessions', 'abc'], value: { ts: chunk } }
|
|
158
|
+
*/
|
|
159
|
+
type MergePath = string | string[];
|
|
160
|
+
/**
|
|
161
|
+
* Shallow-merge an object into the target. The target is the root
|
|
162
|
+
* (when `path` is omitted/empty) or an arbitrary nested location
|
|
163
|
+
* specified by an array of literal segments.
|
|
164
|
+
*
|
|
165
|
+
* Engine semantics:
|
|
166
|
+
* - Missing or non-object intermediates along the path are
|
|
167
|
+
* auto-replaced with `{}` so a stray `null` or scalar never
|
|
168
|
+
* blocks future merges.
|
|
169
|
+
* - The merge is shallow at the target — top-level keys of `value`
|
|
170
|
+
* replace same-named keys; siblings are preserved.
|
|
171
|
+
* - Each path segment is a literal key. `["a.b"]` writes a single
|
|
172
|
+
* key named `"a.b"`, not `a → b`.
|
|
173
|
+
*
|
|
174
|
+
* Validation: invalid paths/values (depth > 32 segments, segment >
|
|
175
|
+
* 256 bytes, value depth > 16, > 1024 top-level keys, or any
|
|
176
|
+
* `__proto__`/`constructor`/`prototype` segment or top-level key)
|
|
177
|
+
* are rejected with a structured error in the `errors` field of the
|
|
178
|
+
* `state::update` / `stream::update` response. The merge does not
|
|
179
|
+
* apply when an error is returned for that op.
|
|
180
|
+
*/
|
|
181
|
+
type UpdateMerge = {
|
|
182
|
+
type: 'merge'; /** Optional path to the merge target. See {@link MergePath}. */
|
|
183
|
+
path?: MergePath; /** Object to merge. Must be a JSON object. */
|
|
184
|
+
value: any;
|
|
185
|
+
};
|
|
186
|
+
/** Per-op error returned by `state::update` / `stream::update`. */
|
|
187
|
+
type UpdateOpError = {
|
|
188
|
+
/** Index of the offending op within the original `ops` array. */op_index: number; /** Stable error code, e.g. `"merge.path.too_deep"`. */
|
|
189
|
+
code: string; /** Human-readable description with concrete numbers when applicable. */
|
|
190
|
+
message: string; /** Optional documentation URL. */
|
|
191
|
+
doc_url?: string;
|
|
192
|
+
};
|
|
193
|
+
/** Result of a stream delete operation. */
|
|
194
|
+
type StreamDeleteResult = {
|
|
195
|
+
/** Previous value (if it existed). */old_value?: any;
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* Union of all atomic update operations supported by streams.
|
|
199
|
+
*
|
|
200
|
+
* @see {@link UpdateSet}, {@link UpdateIncrement}, {@link UpdateDecrement},
|
|
201
|
+
* {@link UpdateAppend}, {@link UpdateRemove}, {@link UpdateMerge}
|
|
202
|
+
*/
|
|
203
|
+
type UpdateOp = UpdateSet | UpdateIncrement | UpdateDecrement | UpdateAppend | UpdateRemove | UpdateMerge;
|
|
204
|
+
/** Input for atomically updating a stream item. */
|
|
205
|
+
type StreamUpdateInput = {
|
|
206
|
+
/** Name of the stream. */stream_name: string; /** Group identifier. */
|
|
207
|
+
group_id: string; /** Item identifier. */
|
|
208
|
+
item_id: string; /** Ordered list of update operations to apply atomically. */
|
|
209
|
+
ops: UpdateOp[];
|
|
210
|
+
};
|
|
211
|
+
/** Trigger config for `stream` triggers. Filters which item changes fire the handler. */
|
|
212
|
+
interface StreamTriggerConfig {
|
|
213
|
+
/** Stream name to watch. Only changes on this stream fire the handler. */
|
|
214
|
+
stream_name: string;
|
|
215
|
+
/** If set, only changes within this group fire the handler. */
|
|
216
|
+
group_id?: string;
|
|
217
|
+
/** If set, only changes to this specific item fire the handler. */
|
|
218
|
+
item_id?: string;
|
|
219
|
+
/** Function ID for conditional execution. If it returns `false`, the handler is skipped. */
|
|
220
|
+
condition_function_id?: string;
|
|
221
|
+
}
|
|
222
|
+
/** Trigger config for `stream:join` and `stream:leave` triggers. */
|
|
223
|
+
interface StreamJoinLeaveTriggerConfig {
|
|
224
|
+
/** Function ID for conditional execution. If it returns `false`, the handler is skipped. */
|
|
225
|
+
condition_function_id?: string;
|
|
226
|
+
}
|
|
227
|
+
/** Detail of a stream change event containing the mutation type and data. */
|
|
228
|
+
type StreamChangeEventDetail = {
|
|
229
|
+
/** The kind of mutation (create, update, or delete). */type: 'create' | 'update' | 'delete'; /** The data associated with the event. */
|
|
230
|
+
data: any;
|
|
231
|
+
};
|
|
232
|
+
/** Handler input for `stream` triggers, fired when an item changes via `stream::set`, `stream::update`, or `stream::delete`. */
|
|
233
|
+
interface StreamChangeEvent {
|
|
234
|
+
/** The event type. */
|
|
235
|
+
type: 'stream';
|
|
236
|
+
/** Unix timestamp of the event. */
|
|
237
|
+
timestamp: number;
|
|
238
|
+
/** The stream where the change occurred. */
|
|
239
|
+
streamName: string;
|
|
240
|
+
/** The group where the change occurred. */
|
|
241
|
+
groupId: string;
|
|
242
|
+
/** The item ID that changed. */
|
|
243
|
+
id?: string;
|
|
244
|
+
/** The event detail containing mutation type and data. */
|
|
245
|
+
event: StreamChangeEventDetail;
|
|
246
|
+
}
|
|
247
|
+
//#endregion
|
|
248
|
+
export { MergePath, StreamAuthInput, StreamAuthResult, StreamChangeEvent, StreamChangeEventDetail, StreamContext, StreamDeleteInput, StreamDeleteResult, StreamGetInput, StreamJoinLeaveEvent, StreamJoinLeaveTriggerConfig, StreamJoinResult, StreamListGroupsInput, StreamListInput, StreamSetInput, StreamSetResult, StreamTriggerConfig, StreamUpdateInput, StreamUpdateResult, UpdateAppend, UpdateDecrement, UpdateIncrement, UpdateMerge, UpdateOp, UpdateOpError, UpdateRemove, UpdateSet };
|
|
249
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
//#region src/stream/index.d.ts
|
|
2
|
+
/** Input for stream authentication. */
|
|
3
|
+
interface StreamAuthInput {
|
|
4
|
+
/** Request headers. */
|
|
5
|
+
headers: Record<string, string>;
|
|
6
|
+
/** Request path. */
|
|
7
|
+
path: string;
|
|
8
|
+
/** Query parameters. */
|
|
9
|
+
query_params: Record<string, string[]>;
|
|
10
|
+
/** Client address. */
|
|
11
|
+
addr: string;
|
|
12
|
+
}
|
|
13
|
+
/** Result of stream authentication. */
|
|
14
|
+
interface StreamAuthResult {
|
|
15
|
+
/** Arbitrary context passed to stream handlers after authentication. */
|
|
16
|
+
context?: any;
|
|
17
|
+
}
|
|
18
|
+
/** Context type extracted from {@link StreamAuthResult}. */
|
|
19
|
+
type StreamContext = StreamAuthResult['context'];
|
|
20
|
+
/** Event payload for stream join/leave events. */
|
|
21
|
+
interface StreamJoinLeaveEvent {
|
|
22
|
+
/** Unique subscription identifier. */
|
|
23
|
+
subscription_id: string;
|
|
24
|
+
/** Name of the stream. */
|
|
25
|
+
stream_name: string;
|
|
26
|
+
/** Group identifier. */
|
|
27
|
+
group_id: string;
|
|
28
|
+
/** Item identifier (if applicable). */
|
|
29
|
+
id?: string;
|
|
30
|
+
/** Auth context from {@link StreamAuthResult}. */
|
|
31
|
+
context?: StreamContext;
|
|
32
|
+
}
|
|
33
|
+
/** Result of a stream join request. */
|
|
34
|
+
interface StreamJoinResult {
|
|
35
|
+
/** Whether the join was unauthorized. */
|
|
36
|
+
unauthorized: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** Input for retrieving a single stream item. */
|
|
39
|
+
type StreamGetInput = {
|
|
40
|
+
/** Name of the stream. */stream_name: string; /** Group identifier. */
|
|
41
|
+
group_id: string; /** Item identifier. */
|
|
42
|
+
item_id: string;
|
|
43
|
+
};
|
|
44
|
+
/** Input for setting a stream item. */
|
|
45
|
+
type StreamSetInput = {
|
|
46
|
+
/** Name of the stream. */stream_name: string; /** Group identifier. */
|
|
47
|
+
group_id: string; /** Item identifier. */
|
|
48
|
+
item_id: string; /** Data to store. */
|
|
49
|
+
data: any;
|
|
50
|
+
};
|
|
51
|
+
/** Input for deleting a stream item. */
|
|
52
|
+
type StreamDeleteInput = {
|
|
53
|
+
/** Name of the stream. */stream_name: string; /** Group identifier. */
|
|
54
|
+
group_id: string; /** Item identifier. */
|
|
55
|
+
item_id: string;
|
|
56
|
+
};
|
|
57
|
+
/** Input for listing all items in a stream group. */
|
|
58
|
+
type StreamListInput = {
|
|
59
|
+
/** Name of the stream. */stream_name: string; /** Group identifier. */
|
|
60
|
+
group_id: string;
|
|
61
|
+
};
|
|
62
|
+
/** Input for listing all groups in a stream. */
|
|
63
|
+
type StreamListGroupsInput = {
|
|
64
|
+
/** Name of the stream. */stream_name: string;
|
|
65
|
+
};
|
|
66
|
+
/** Result of a stream set operation. */
|
|
67
|
+
type StreamSetResult<TData> = {
|
|
68
|
+
/** Previous value (if it existed). */old_value?: TData; /** New value that was stored. */
|
|
69
|
+
new_value: TData;
|
|
70
|
+
};
|
|
71
|
+
/** Result of a stream update operation. */
|
|
72
|
+
type StreamUpdateResult<TData> = {
|
|
73
|
+
/** Previous value (if it existed). */old_value?: TData; /** New value after the update. */
|
|
74
|
+
new_value: TData;
|
|
75
|
+
/**
|
|
76
|
+
* Per-op errors. Emitted by `merge` and `append` for validation
|
|
77
|
+
* rejections (path depth/size, value depth, or a
|
|
78
|
+
* `__proto__`/`constructor`/`prototype` segment or top-level key)
|
|
79
|
+
* and by `append` for the case-2 `append.type_mismatch` and
|
|
80
|
+
* `append.target_not_object` surfaces. Successfully applied ops are
|
|
81
|
+
* still reflected in `new_value`. The field is omitted from the
|
|
82
|
+
* JSON wire when empty.
|
|
83
|
+
*/
|
|
84
|
+
errors?: UpdateOpError[];
|
|
85
|
+
};
|
|
86
|
+
/** Set a field at the given path to a value. */
|
|
87
|
+
type UpdateSet = {
|
|
88
|
+
type: 'set'; /** First-level field path. Use an empty string to target the root value. */
|
|
89
|
+
path: string; /** Value to set. */
|
|
90
|
+
value: any;
|
|
91
|
+
};
|
|
92
|
+
/** Increment a numeric field by a given amount. */
|
|
93
|
+
type UpdateIncrement = {
|
|
94
|
+
type: 'increment'; /** First-level field path. */
|
|
95
|
+
path: string; /** Amount to increment by. */
|
|
96
|
+
by: number;
|
|
97
|
+
};
|
|
98
|
+
/** Decrement a numeric field by a given amount. */
|
|
99
|
+
type UpdateDecrement = {
|
|
100
|
+
type: 'decrement'; /** First-level field path. */
|
|
101
|
+
path: string; /** Amount to decrement by. */
|
|
102
|
+
by: number;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Append an element to an array, concatenate a string, or push a new
|
|
106
|
+
* value at a nested path. The target is the root (when `path` is
|
|
107
|
+
* omitted, empty, or `[]`), a single first-level key (when `path` is
|
|
108
|
+
* a non-empty string), or an arbitrary nested location (when `path`
|
|
109
|
+
* is an array of literal segments).
|
|
110
|
+
*
|
|
111
|
+
* Engine semantics:
|
|
112
|
+
* - Missing or non-object intermediates along a nested path are
|
|
113
|
+
* auto-replaced with `{}` so a stray `null` or scalar never blocks
|
|
114
|
+
* future appends.
|
|
115
|
+
* - At the leaf:
|
|
116
|
+
* - missing/null + nested path → `[value]` (always an array)
|
|
117
|
+
* - missing/null + single-string path → string-as-string for the
|
|
118
|
+
* string-concat tier, otherwise `[value]`
|
|
119
|
+
* - existing array → push
|
|
120
|
+
* - existing string + string value → concatenate
|
|
121
|
+
* - existing object/scalar at the leaf → `append.type_mismatch`
|
|
122
|
+
* - Each path segment is a literal key. `["a.b"]` targets a single
|
|
123
|
+
* key named `"a.b"`, not `a → b`.
|
|
124
|
+
*
|
|
125
|
+
* Validation: invalid paths (depth > 32 segments, segment > 256
|
|
126
|
+
* bytes, or any `__proto__`/`constructor`/`prototype` segment) are
|
|
127
|
+
* rejected with a structured error in the `errors` field of the
|
|
128
|
+
* `state::update` / `stream::update` response. The append does not
|
|
129
|
+
* apply when an error is returned for that op.
|
|
130
|
+
*/
|
|
131
|
+
type UpdateAppend = {
|
|
132
|
+
type: 'append';
|
|
133
|
+
/**
|
|
134
|
+
* Optional path to the append target. Accepts a single first-level
|
|
135
|
+
* key (legacy `string`) or an array of literal segments for nested
|
|
136
|
+
* append. See {@link MergePath} (the same shape is reused).
|
|
137
|
+
*/
|
|
138
|
+
path?: MergePath; /** Value to append. String targets only accept string values. */
|
|
139
|
+
value: any;
|
|
140
|
+
};
|
|
141
|
+
/** Remove a field at the given path. */
|
|
142
|
+
type UpdateRemove = {
|
|
143
|
+
type: 'remove'; /** First-level field path. */
|
|
144
|
+
path: string;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Path target for a {@link UpdateMerge} op. Accepts:
|
|
148
|
+
* - a single string (legacy / first-level field)
|
|
149
|
+
* - an array of literal segments (nested path; each element is one
|
|
150
|
+
* literal key, dots are NOT interpreted as separators)
|
|
151
|
+
*
|
|
152
|
+
* Omit `path`, pass `""`, or pass `[]` to target the root value.
|
|
153
|
+
*
|
|
154
|
+
* @example single first-level field
|
|
155
|
+
* { type: 'merge', path: 'session-abc', value: { author: 'alice' } }
|
|
156
|
+
* @example nested path (closes issue #1546's structured-state use case)
|
|
157
|
+
* { type: 'merge', path: ['sessions', 'abc'], value: { ts: chunk } }
|
|
158
|
+
*/
|
|
159
|
+
type MergePath = string | string[];
|
|
160
|
+
/**
|
|
161
|
+
* Shallow-merge an object into the target. The target is the root
|
|
162
|
+
* (when `path` is omitted/empty) or an arbitrary nested location
|
|
163
|
+
* specified by an array of literal segments.
|
|
164
|
+
*
|
|
165
|
+
* Engine semantics:
|
|
166
|
+
* - Missing or non-object intermediates along the path are
|
|
167
|
+
* auto-replaced with `{}` so a stray `null` or scalar never
|
|
168
|
+
* blocks future merges.
|
|
169
|
+
* - The merge is shallow at the target — top-level keys of `value`
|
|
170
|
+
* replace same-named keys; siblings are preserved.
|
|
171
|
+
* - Each path segment is a literal key. `["a.b"]` writes a single
|
|
172
|
+
* key named `"a.b"`, not `a → b`.
|
|
173
|
+
*
|
|
174
|
+
* Validation: invalid paths/values (depth > 32 segments, segment >
|
|
175
|
+
* 256 bytes, value depth > 16, > 1024 top-level keys, or any
|
|
176
|
+
* `__proto__`/`constructor`/`prototype` segment or top-level key)
|
|
177
|
+
* are rejected with a structured error in the `errors` field of the
|
|
178
|
+
* `state::update` / `stream::update` response. The merge does not
|
|
179
|
+
* apply when an error is returned for that op.
|
|
180
|
+
*/
|
|
181
|
+
type UpdateMerge = {
|
|
182
|
+
type: 'merge'; /** Optional path to the merge target. See {@link MergePath}. */
|
|
183
|
+
path?: MergePath; /** Object to merge. Must be a JSON object. */
|
|
184
|
+
value: any;
|
|
185
|
+
};
|
|
186
|
+
/** Per-op error returned by `state::update` / `stream::update`. */
|
|
187
|
+
type UpdateOpError = {
|
|
188
|
+
/** Index of the offending op within the original `ops` array. */op_index: number; /** Stable error code, e.g. `"merge.path.too_deep"`. */
|
|
189
|
+
code: string; /** Human-readable description with concrete numbers when applicable. */
|
|
190
|
+
message: string; /** Optional documentation URL. */
|
|
191
|
+
doc_url?: string;
|
|
192
|
+
};
|
|
193
|
+
/** Result of a stream delete operation. */
|
|
194
|
+
type StreamDeleteResult = {
|
|
195
|
+
/** Previous value (if it existed). */old_value?: any;
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* Union of all atomic update operations supported by streams.
|
|
199
|
+
*
|
|
200
|
+
* @see {@link UpdateSet}, {@link UpdateIncrement}, {@link UpdateDecrement},
|
|
201
|
+
* {@link UpdateAppend}, {@link UpdateRemove}, {@link UpdateMerge}
|
|
202
|
+
*/
|
|
203
|
+
type UpdateOp = UpdateSet | UpdateIncrement | UpdateDecrement | UpdateAppend | UpdateRemove | UpdateMerge;
|
|
204
|
+
/** Input for atomically updating a stream item. */
|
|
205
|
+
type StreamUpdateInput = {
|
|
206
|
+
/** Name of the stream. */stream_name: string; /** Group identifier. */
|
|
207
|
+
group_id: string; /** Item identifier. */
|
|
208
|
+
item_id: string; /** Ordered list of update operations to apply atomically. */
|
|
209
|
+
ops: UpdateOp[];
|
|
210
|
+
};
|
|
211
|
+
/** Trigger config for `stream` triggers. Filters which item changes fire the handler. */
|
|
212
|
+
interface StreamTriggerConfig {
|
|
213
|
+
/** Stream name to watch. Only changes on this stream fire the handler. */
|
|
214
|
+
stream_name: string;
|
|
215
|
+
/** If set, only changes within this group fire the handler. */
|
|
216
|
+
group_id?: string;
|
|
217
|
+
/** If set, only changes to this specific item fire the handler. */
|
|
218
|
+
item_id?: string;
|
|
219
|
+
/** Function ID for conditional execution. If it returns `false`, the handler is skipped. */
|
|
220
|
+
condition_function_id?: string;
|
|
221
|
+
}
|
|
222
|
+
/** Trigger config for `stream:join` and `stream:leave` triggers. */
|
|
223
|
+
interface StreamJoinLeaveTriggerConfig {
|
|
224
|
+
/** Function ID for conditional execution. If it returns `false`, the handler is skipped. */
|
|
225
|
+
condition_function_id?: string;
|
|
226
|
+
}
|
|
227
|
+
/** Detail of a stream change event containing the mutation type and data. */
|
|
228
|
+
type StreamChangeEventDetail = {
|
|
229
|
+
/** The kind of mutation (create, update, or delete). */type: 'create' | 'update' | 'delete'; /** The data associated with the event. */
|
|
230
|
+
data: any;
|
|
231
|
+
};
|
|
232
|
+
/** Handler input for `stream` triggers, fired when an item changes via `stream::set`, `stream::update`, or `stream::delete`. */
|
|
233
|
+
interface StreamChangeEvent {
|
|
234
|
+
/** The event type. */
|
|
235
|
+
type: 'stream';
|
|
236
|
+
/** Unix timestamp of the event. */
|
|
237
|
+
timestamp: number;
|
|
238
|
+
/** The stream where the change occurred. */
|
|
239
|
+
streamName: string;
|
|
240
|
+
/** The group where the change occurred. */
|
|
241
|
+
groupId: string;
|
|
242
|
+
/** The item ID that changed. */
|
|
243
|
+
id?: string;
|
|
244
|
+
/** The event detail containing mutation type and data. */
|
|
245
|
+
event: StreamChangeEventDetail;
|
|
246
|
+
}
|
|
247
|
+
//#endregion
|
|
248
|
+
export { MergePath, StreamAuthInput, StreamAuthResult, StreamChangeEvent, StreamChangeEventDetail, StreamContext, StreamDeleteInput, StreamDeleteResult, StreamGetInput, StreamJoinLeaveEvent, StreamJoinLeaveTriggerConfig, StreamJoinResult, StreamListGroupsInput, StreamListInput, StreamSetInput, StreamSetResult, StreamTriggerConfig, StreamUpdateInput, StreamUpdateResult, UpdateAppend, UpdateDecrement, UpdateIncrement, UpdateMerge, UpdateOp, UpdateOpError, UpdateRemove, UpdateSet };
|
|
249
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
File without changes
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
//#region src/worker-connection-manager/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Input passed to the RBAC auth function during WebSocket upgrade.
|
|
4
|
+
* Contains the HTTP headers, query parameters, and client IP from the
|
|
5
|
+
* connecting worker's upgrade request.
|
|
6
|
+
*/
|
|
7
|
+
type AuthInput = {
|
|
8
|
+
/** HTTP headers from the WebSocket upgrade request. */headers: Record<string, string>; /** Query parameters from the upgrade URL. Each key maps to an array of values to support repeated keys. */
|
|
9
|
+
query_params: Record<string, string[]>; /** IP address of the connecting client. */
|
|
10
|
+
ip_address: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Return value from the RBAC auth function. Controls which functions the
|
|
14
|
+
* authenticated worker can invoke and what context is forwarded to the
|
|
15
|
+
* middleware.
|
|
16
|
+
*/
|
|
17
|
+
type AuthResult = {
|
|
18
|
+
/** Additional function IDs to allow beyond the `expose_functions` config. */allowed_functions: string[]; /** Function IDs to deny even if they match `expose_functions`. Takes precedence over allowed. */
|
|
19
|
+
forbidden_functions: string[]; /** Trigger type IDs the worker may register triggers for. When omitted, all types are allowed. */
|
|
20
|
+
allowed_trigger_types?: string[]; /** Whether the worker may register new trigger types. */
|
|
21
|
+
allow_trigger_type_registration: boolean; /** Whether the worker may register new functions. Defaults to `true` if omitted. */
|
|
22
|
+
allow_function_registration?: boolean; /** Arbitrary context forwarded to the middleware function on every invocation. */
|
|
23
|
+
context: Record<string, unknown>; /** Optional prefix applied to all function IDs registered by this worker. */
|
|
24
|
+
function_registration_prefix?: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Input passed to the `on_trigger_type_registration_function_id` hook
|
|
28
|
+
* when a worker attempts to register a new trigger type through the RBAC port.
|
|
29
|
+
* Return an {@link OnTriggerTypeRegistrationResult} with the (possibly mapped)
|
|
30
|
+
* fields, or throw to deny the registration.
|
|
31
|
+
*/
|
|
32
|
+
type OnTriggerTypeRegistrationInput = {
|
|
33
|
+
/** ID of the trigger type being registered. */trigger_type_id: string; /** Human-readable description of the trigger type. */
|
|
34
|
+
description: string; /** Auth context from `AuthResult.context` for this session. */
|
|
35
|
+
context: Record<string, unknown>;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Result returned from the `on_trigger_type_registration_function_id` hook.
|
|
39
|
+
* All fields are optional -- omitted fields keep the original value from the
|
|
40
|
+
* registration request.
|
|
41
|
+
*/
|
|
42
|
+
type OnTriggerTypeRegistrationResult = {
|
|
43
|
+
/** Mapped trigger type ID. */trigger_type_id?: string; /** Mapped description. */
|
|
44
|
+
description?: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Input passed to the `on_trigger_registration_function_id` hook
|
|
48
|
+
* when a worker attempts to register a trigger through the RBAC port.
|
|
49
|
+
* Return an {@link OnTriggerRegistrationResult} with the (possibly mapped)
|
|
50
|
+
* fields, or throw to deny the registration.
|
|
51
|
+
*/
|
|
52
|
+
type OnTriggerRegistrationInput = {
|
|
53
|
+
/** ID of the trigger being registered. */trigger_id: string; /** Trigger type identifier. */
|
|
54
|
+
trigger_type: string; /** ID of the function this trigger is bound to. */
|
|
55
|
+
function_id: string; /** Trigger-specific configuration. */
|
|
56
|
+
config: unknown; /** Arbitrary metadata attached to the trigger. */
|
|
57
|
+
metadata?: Record<string, unknown>; /** Auth context from `AuthResult.context` for this session. */
|
|
58
|
+
context: Record<string, unknown>;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Result returned from the `on_trigger_registration_function_id` hook.
|
|
62
|
+
* All fields are optional -- omitted fields keep the original value from the
|
|
63
|
+
* registration request.
|
|
64
|
+
*/
|
|
65
|
+
type OnTriggerRegistrationResult = {
|
|
66
|
+
/** Mapped trigger ID. */trigger_id?: string; /** Mapped trigger type. */
|
|
67
|
+
trigger_type?: string; /** Mapped function ID. */
|
|
68
|
+
function_id?: string; /** Mapped trigger configuration. */
|
|
69
|
+
config?: unknown;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Input passed to the `on_function_registration_function_id` hook
|
|
73
|
+
* when a worker attempts to register a function through the RBAC port.
|
|
74
|
+
* Return an {@link OnFunctionRegistrationResult} with the (possibly mapped)
|
|
75
|
+
* fields, or throw to deny the registration.
|
|
76
|
+
*/
|
|
77
|
+
type OnFunctionRegistrationInput = {
|
|
78
|
+
/** ID of the function being registered. */function_id: string; /** Human-readable description of the function. */
|
|
79
|
+
description?: string; /** Arbitrary metadata attached to the function. */
|
|
80
|
+
metadata?: Record<string, unknown>; /** Auth context from `AuthResult.context` for this session. */
|
|
81
|
+
context: Record<string, unknown>;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Result returned from the `on_function_registration_function_id` hook.
|
|
85
|
+
* All fields are optional -- omitted fields keep the original value from the
|
|
86
|
+
* registration request.
|
|
87
|
+
*/
|
|
88
|
+
type OnFunctionRegistrationResult = {
|
|
89
|
+
/** Mapped function ID. */function_id?: string; /** Mapped description. */
|
|
90
|
+
description?: string; /** Mapped metadata. */
|
|
91
|
+
metadata?: Record<string, unknown>;
|
|
92
|
+
};
|
|
93
|
+
//#endregion
|
|
94
|
+
export { AuthInput, AuthResult, OnFunctionRegistrationInput, OnFunctionRegistrationResult, OnTriggerRegistrationInput, OnTriggerRegistrationResult, OnTriggerTypeRegistrationInput, OnTriggerTypeRegistrationResult };
|
|
95
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
//#region src/worker-connection-manager/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Input passed to the RBAC auth function during WebSocket upgrade.
|
|
4
|
+
* Contains the HTTP headers, query parameters, and client IP from the
|
|
5
|
+
* connecting worker's upgrade request.
|
|
6
|
+
*/
|
|
7
|
+
type AuthInput = {
|
|
8
|
+
/** HTTP headers from the WebSocket upgrade request. */headers: Record<string, string>; /** Query parameters from the upgrade URL. Each key maps to an array of values to support repeated keys. */
|
|
9
|
+
query_params: Record<string, string[]>; /** IP address of the connecting client. */
|
|
10
|
+
ip_address: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Return value from the RBAC auth function. Controls which functions the
|
|
14
|
+
* authenticated worker can invoke and what context is forwarded to the
|
|
15
|
+
* middleware.
|
|
16
|
+
*/
|
|
17
|
+
type AuthResult = {
|
|
18
|
+
/** Additional function IDs to allow beyond the `expose_functions` config. */allowed_functions: string[]; /** Function IDs to deny even if they match `expose_functions`. Takes precedence over allowed. */
|
|
19
|
+
forbidden_functions: string[]; /** Trigger type IDs the worker may register triggers for. When omitted, all types are allowed. */
|
|
20
|
+
allowed_trigger_types?: string[]; /** Whether the worker may register new trigger types. */
|
|
21
|
+
allow_trigger_type_registration: boolean; /** Whether the worker may register new functions. Defaults to `true` if omitted. */
|
|
22
|
+
allow_function_registration?: boolean; /** Arbitrary context forwarded to the middleware function on every invocation. */
|
|
23
|
+
context: Record<string, unknown>; /** Optional prefix applied to all function IDs registered by this worker. */
|
|
24
|
+
function_registration_prefix?: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Input passed to the `on_trigger_type_registration_function_id` hook
|
|
28
|
+
* when a worker attempts to register a new trigger type through the RBAC port.
|
|
29
|
+
* Return an {@link OnTriggerTypeRegistrationResult} with the (possibly mapped)
|
|
30
|
+
* fields, or throw to deny the registration.
|
|
31
|
+
*/
|
|
32
|
+
type OnTriggerTypeRegistrationInput = {
|
|
33
|
+
/** ID of the trigger type being registered. */trigger_type_id: string; /** Human-readable description of the trigger type. */
|
|
34
|
+
description: string; /** Auth context from `AuthResult.context` for this session. */
|
|
35
|
+
context: Record<string, unknown>;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Result returned from the `on_trigger_type_registration_function_id` hook.
|
|
39
|
+
* All fields are optional -- omitted fields keep the original value from the
|
|
40
|
+
* registration request.
|
|
41
|
+
*/
|
|
42
|
+
type OnTriggerTypeRegistrationResult = {
|
|
43
|
+
/** Mapped trigger type ID. */trigger_type_id?: string; /** Mapped description. */
|
|
44
|
+
description?: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Input passed to the `on_trigger_registration_function_id` hook
|
|
48
|
+
* when a worker attempts to register a trigger through the RBAC port.
|
|
49
|
+
* Return an {@link OnTriggerRegistrationResult} with the (possibly mapped)
|
|
50
|
+
* fields, or throw to deny the registration.
|
|
51
|
+
*/
|
|
52
|
+
type OnTriggerRegistrationInput = {
|
|
53
|
+
/** ID of the trigger being registered. */trigger_id: string; /** Trigger type identifier. */
|
|
54
|
+
trigger_type: string; /** ID of the function this trigger is bound to. */
|
|
55
|
+
function_id: string; /** Trigger-specific configuration. */
|
|
56
|
+
config: unknown; /** Arbitrary metadata attached to the trigger. */
|
|
57
|
+
metadata?: Record<string, unknown>; /** Auth context from `AuthResult.context` for this session. */
|
|
58
|
+
context: Record<string, unknown>;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Result returned from the `on_trigger_registration_function_id` hook.
|
|
62
|
+
* All fields are optional -- omitted fields keep the original value from the
|
|
63
|
+
* registration request.
|
|
64
|
+
*/
|
|
65
|
+
type OnTriggerRegistrationResult = {
|
|
66
|
+
/** Mapped trigger ID. */trigger_id?: string; /** Mapped trigger type. */
|
|
67
|
+
trigger_type?: string; /** Mapped function ID. */
|
|
68
|
+
function_id?: string; /** Mapped trigger configuration. */
|
|
69
|
+
config?: unknown;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Input passed to the `on_function_registration_function_id` hook
|
|
73
|
+
* when a worker attempts to register a function through the RBAC port.
|
|
74
|
+
* Return an {@link OnFunctionRegistrationResult} with the (possibly mapped)
|
|
75
|
+
* fields, or throw to deny the registration.
|
|
76
|
+
*/
|
|
77
|
+
type OnFunctionRegistrationInput = {
|
|
78
|
+
/** ID of the function being registered. */function_id: string; /** Human-readable description of the function. */
|
|
79
|
+
description?: string; /** Arbitrary metadata attached to the function. */
|
|
80
|
+
metadata?: Record<string, unknown>; /** Auth context from `AuthResult.context` for this session. */
|
|
81
|
+
context: Record<string, unknown>;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Result returned from the `on_function_registration_function_id` hook.
|
|
85
|
+
* All fields are optional -- omitted fields keep the original value from the
|
|
86
|
+
* registration request.
|
|
87
|
+
*/
|
|
88
|
+
type OnFunctionRegistrationResult = {
|
|
89
|
+
/** Mapped function ID. */function_id?: string; /** Mapped description. */
|
|
90
|
+
description?: string; /** Mapped metadata. */
|
|
91
|
+
metadata?: Record<string, unknown>;
|
|
92
|
+
};
|
|
93
|
+
//#endregion
|
|
94
|
+
export { AuthInput, AuthResult, OnFunctionRegistrationInput, OnFunctionRegistrationResult, OnTriggerRegistrationInput, OnTriggerRegistrationResult, OnTriggerTypeRegistrationInput, OnTriggerTypeRegistrationResult };
|
|
95
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@iii-dev/helpers",
|
|
3
|
+
"version": "0.19.4-alpha.2",
|
|
4
|
+
"private": false,
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"author": "III",
|
|
10
|
+
"license": "Apache-2.0",
|
|
11
|
+
"description": "Shared helper primitives across iii SDKs.",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"iii",
|
|
14
|
+
"helpers"
|
|
15
|
+
],
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"exports": {
|
|
21
|
+
"./http": {
|
|
22
|
+
"import": {
|
|
23
|
+
"types": "./dist/http/index.d.mts",
|
|
24
|
+
"default": "./dist/http/index.mjs"
|
|
25
|
+
},
|
|
26
|
+
"require": {
|
|
27
|
+
"types": "./dist/http/index.d.cts",
|
|
28
|
+
"default": "./dist/http/index.cjs"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"./queue": {
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./dist/queue/index.d.mts",
|
|
34
|
+
"default": "./dist/queue/index.mjs"
|
|
35
|
+
},
|
|
36
|
+
"require": {
|
|
37
|
+
"types": "./dist/queue/index.d.cts",
|
|
38
|
+
"default": "./dist/queue/index.cjs"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"./stream": {
|
|
42
|
+
"import": {
|
|
43
|
+
"types": "./dist/stream/index.d.mts",
|
|
44
|
+
"default": "./dist/stream/index.mjs"
|
|
45
|
+
},
|
|
46
|
+
"require": {
|
|
47
|
+
"types": "./dist/stream/index.d.cts",
|
|
48
|
+
"default": "./dist/stream/index.cjs"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"./worker-connection-manager": {
|
|
52
|
+
"import": {
|
|
53
|
+
"types": "./dist/worker-connection-manager/index.d.mts",
|
|
54
|
+
"default": "./dist/worker-connection-manager/index.mjs"
|
|
55
|
+
},
|
|
56
|
+
"require": {
|
|
57
|
+
"types": "./dist/worker-connection-manager/index.d.cts",
|
|
58
|
+
"default": "./dist/worker-connection-manager/index.cjs"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@types/node": "^24.10.1",
|
|
64
|
+
"@vitest/coverage-v8": "^2.1.0",
|
|
65
|
+
"tsdown": "^0.21.4",
|
|
66
|
+
"typescript": "^5.9.3",
|
|
67
|
+
"vitest": "^2.1.0"
|
|
68
|
+
},
|
|
69
|
+
"scripts": {
|
|
70
|
+
"build": "tsdown",
|
|
71
|
+
"test": "vitest run",
|
|
72
|
+
"type-check": "tsc --noEmit"
|
|
73
|
+
}
|
|
74
|
+
}
|