@funcd-dev/shim 0.10.0 → 0.12.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/dist/blob.js +2 -28
- package/dist/invcontext.d.ts +11 -0
- package/dist/invcontext.js +27 -1
- package/dist/kv.js +2 -28
- package/dist/socket.d.ts +6 -0
- package/dist/socket.js +33 -0
- package/dist/sql.d.ts +29 -0
- package/dist/sql.js +52 -0
- package/dist/tracespan.d.ts +6 -4
- package/dist/tracespan.js +8 -5
- package/dist/types.d.ts +7 -0
- package/package.json +1 -1
package/dist/blob.js
CHANGED
|
@@ -3,34 +3,8 @@
|
|
|
3
3
|
// to the binding-gated, PDP-authorized Facade with the sandbox's function identity (bind-as-grant on
|
|
4
4
|
// spec.blob). Reached only through the built-in shim — no @aws-sdk, no keypair. The blob twin of context.kv;
|
|
5
5
|
// v1 is bytes-in-memory (streaming is a v2 follow-up).
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
function send(method, path, body, member) {
|
|
9
|
-
return new Promise((resolve, reject) => {
|
|
10
|
-
const socketPath = process.env.FUNCD_INVOKE_SOCKET;
|
|
11
|
-
if (!socketPath) {
|
|
12
|
-
reject(new Error('context.blob: worker-node local API socket unavailable (FUNCD_INVOKE_SOCKET unset)'));
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
const headers = {};
|
|
16
|
-
if (body)
|
|
17
|
-
headers['content-length'] = body.byteLength;
|
|
18
|
-
if (member)
|
|
19
|
-
headers[MEMBER_HEADER] = member;
|
|
20
|
-
const req = http.request({ socketPath, path, method, headers }, (res) => {
|
|
21
|
-
const chunks = [];
|
|
22
|
-
// A connection that drops mid-body errors the response, not the request, and never ends it.
|
|
23
|
-
res.on('error', (err) => reject(new Error(`context.blob ${method} ${path} failed: connection closed before the reply ended`, { cause: err })));
|
|
24
|
-
res.on('data', (c) => chunks.push(c));
|
|
25
|
-
res.on('end', () => resolve({ status: res.statusCode ?? 0, body: Buffer.concat(chunks) }));
|
|
26
|
-
});
|
|
27
|
-
req.on('error', (err) => reject(new Error(`context.blob ${method} ${path} failed: ${err.message}`, { cause: err })));
|
|
28
|
-
if (body)
|
|
29
|
-
req.end(body);
|
|
30
|
-
else
|
|
31
|
-
req.end();
|
|
32
|
-
});
|
|
33
|
-
}
|
|
6
|
+
import { send as sendOn } from "./socket.js";
|
|
7
|
+
const send = (method, path, body, member) => sendOn('context.blob', method, path, body, member);
|
|
34
8
|
const enc = encodeURIComponent;
|
|
35
9
|
// key may be hierarchical ("a/b"); keep the "/" separators (the server's {key...} captures them), encode segments.
|
|
36
10
|
const keyPath = (binding, key) => `/blob/${enc(binding)}/${key.split('/').map(enc).join('/')}`;
|
package/dist/invcontext.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export interface InvContext {
|
|
|
5
5
|
traceId: string;
|
|
6
6
|
spanId: string;
|
|
7
7
|
parentId: string;
|
|
8
|
+
deadline?: number;
|
|
8
9
|
}
|
|
9
10
|
/** invStore holds the active InvContext for the duration of a handler call (and its async
|
|
10
11
|
* continuations). Per-thread: each worker/process imports its own instance, which is correct —
|
|
@@ -13,3 +14,13 @@ export declare const invStore: AsyncLocalStorage<InvContext>;
|
|
|
13
14
|
/** currentInv returns the active invocation context, or undefined outside an invocation (e.g. a
|
|
14
15
|
* pre-invocation log line) — in which case log records emit empty inv/trace/span (back-compat). */
|
|
15
16
|
export declare function currentInv(): InvContext | undefined;
|
|
17
|
+
/** parseTimeoutMs reads a timeout in milliseconds: a decimal integer in 1..2_147_482_647, else undefined. */
|
|
18
|
+
export declare function parseTimeoutMs(value: string | undefined): number | undefined;
|
|
19
|
+
/** nowMs reads the deadline clock in milliseconds. process.hrtime is one monotonic clock for every thread of the
|
|
20
|
+
* process, so a deadline the pool host sets holds in the member's worker (ADR-0226). */
|
|
21
|
+
export declare function nowMs(): number;
|
|
22
|
+
/** deadlineFrom turns a valid X-Funcd-Timeout-Ms (funcd ADR-0151) into the call's deadline; undefined without one. */
|
|
23
|
+
export declare function deadlineFrom(header: string | undefined): number | undefined;
|
|
24
|
+
/** remainingMs is FunctionContext.remainingMs: the whole milliseconds left before the active call's deadline, floored
|
|
25
|
+
* at 0; null without a deadline. */
|
|
26
|
+
export declare function remainingMs(): number | null;
|
package/dist/invcontext.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// each handler call so BOTH the trace span (tracespan.ts) and the log capture (funclog.ts read it in
|
|
3
3
|
// buildRecord) tag their records with the SAME inv/trace/span ids — the logs↔trace correlation that
|
|
4
4
|
// closes ADR-0081's provenance open question. ADR-0081 specified this carrier but never shipped it
|
|
5
|
-
// (inv/trace_id/span_id were hardcoded empty); this is where it is introduced.
|
|
5
|
+
// (inv/trace_id/span_id were hardcoded empty); this is where it is introduced. It also carries the
|
|
6
|
+
// call's deadline, which ctx.remainingMs() reads (ADR-0226).
|
|
6
7
|
//
|
|
7
8
|
// Built-ins only (node:async_hooks) so it bundles into shim.mjs/pool.mjs.
|
|
8
9
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
@@ -15,3 +16,28 @@ export const invStore = new AsyncLocalStorage();
|
|
|
15
16
|
export function currentInv() {
|
|
16
17
|
return invStore.getStore();
|
|
17
18
|
}
|
|
19
|
+
// setTimeout's largest delay (2^31 - 1 ms) less the pool's 1 s margin.
|
|
20
|
+
const maxTimeoutMs = 2_147_482_647;
|
|
21
|
+
/** parseTimeoutMs reads a timeout in milliseconds: a decimal integer in 1..2_147_482_647, else undefined. */
|
|
22
|
+
export function parseTimeoutMs(value) {
|
|
23
|
+
if (value === undefined || !/^[0-9]+$/.test(value))
|
|
24
|
+
return undefined;
|
|
25
|
+
const ms = Number(value);
|
|
26
|
+
return ms >= 1 && ms <= maxTimeoutMs ? ms : undefined;
|
|
27
|
+
}
|
|
28
|
+
/** nowMs reads the deadline clock in milliseconds. process.hrtime is one monotonic clock for every thread of the
|
|
29
|
+
* process, so a deadline the pool host sets holds in the member's worker (ADR-0226). */
|
|
30
|
+
export function nowMs() {
|
|
31
|
+
return Number(process.hrtime.bigint()) / 1e6;
|
|
32
|
+
}
|
|
33
|
+
/** deadlineFrom turns a valid X-Funcd-Timeout-Ms (funcd ADR-0151) into the call's deadline; undefined without one. */
|
|
34
|
+
export function deadlineFrom(header) {
|
|
35
|
+
const ms = parseTimeoutMs(header);
|
|
36
|
+
return ms === undefined ? undefined : nowMs() + ms;
|
|
37
|
+
}
|
|
38
|
+
/** remainingMs is FunctionContext.remainingMs: the whole milliseconds left before the active call's deadline, floored
|
|
39
|
+
* at 0; null without a deadline. */
|
|
40
|
+
export function remainingMs() {
|
|
41
|
+
const deadline = currentInv()?.deadline;
|
|
42
|
+
return deadline === undefined ? null : Math.max(0, Math.floor(deadline - nowMs()));
|
|
43
|
+
}
|
package/dist/kv.js
CHANGED
|
@@ -1,34 +1,8 @@
|
|
|
1
1
|
// context.kv — function-facing KV over the worker-node local API (HTTP-over-UDS, ADR-0069). Dials the
|
|
2
2
|
// same per-sandbox socket as context.invoke (FUNCD_INVOKE_SOCKET); the platform routes /kv/… to the
|
|
3
3
|
// PDP-authorized Facade with the sandbox's namespace identity. Reached only through the built-in shim.
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
function send(method, path, body, member) {
|
|
7
|
-
return new Promise((resolve, reject) => {
|
|
8
|
-
const socketPath = process.env.FUNCD_INVOKE_SOCKET;
|
|
9
|
-
if (!socketPath) {
|
|
10
|
-
reject(new Error('context.kv: worker-node local API socket unavailable (FUNCD_INVOKE_SOCKET unset)'));
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
const headers = {};
|
|
14
|
-
if (body)
|
|
15
|
-
headers['content-length'] = body.byteLength;
|
|
16
|
-
if (member)
|
|
17
|
-
headers[MEMBER_HEADER] = member;
|
|
18
|
-
const req = http.request({ socketPath, path, method, headers }, (res) => {
|
|
19
|
-
const chunks = [];
|
|
20
|
-
// A connection that drops mid-body errors the response, not the request, and never ends it.
|
|
21
|
-
res.on('error', (err) => reject(new Error(`context.kv ${method} ${path} failed: connection closed before the reply ended`, { cause: err })));
|
|
22
|
-
res.on('data', (c) => chunks.push(c));
|
|
23
|
-
res.on('end', () => resolve({ status: res.statusCode ?? 0, body: Buffer.concat(chunks) }));
|
|
24
|
-
});
|
|
25
|
-
req.on('error', (err) => reject(new Error(`context.kv ${method} ${path} failed: ${err.message}`, { cause: err })));
|
|
26
|
-
if (body)
|
|
27
|
-
req.end(body);
|
|
28
|
-
else
|
|
29
|
-
req.end();
|
|
30
|
-
});
|
|
31
|
-
}
|
|
4
|
+
import { send as sendOn } from "./socket.js";
|
|
5
|
+
const send = (method, path, body, member) => sendOn('context.kv', method, path, body, member);
|
|
32
6
|
const enc = encodeURIComponent;
|
|
33
7
|
// key may be hierarchical ("a/b"); keep the "/" separators (the server's {key...} captures them), encode segments.
|
|
34
8
|
const keyPath = (binding, key) => `/kv/${enc(binding)}/${key.split('/').map(enc).join('/')}`;
|
package/dist/socket.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface Resp {
|
|
2
|
+
status: number;
|
|
3
|
+
body: Buffer;
|
|
4
|
+
}
|
|
5
|
+
/** send makes one request; `client` names the context client in its errors ("context.kv"). */
|
|
6
|
+
export declare function send(client: string, method: string, path: string, body: Buffer | undefined, member: string | undefined, contentType?: string): Promise<Resp>;
|
package/dist/socket.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// The worker-node local API client shared by context.kv, context.blob and context.sql: one HTTP request over the
|
|
2
|
+
// per-sandbox socket (FUNCD_INVOKE_SOCKET), as the calling pool member when one is given.
|
|
3
|
+
import http from 'node:http';
|
|
4
|
+
import { MEMBER_HEADER } from "./invoke.js";
|
|
5
|
+
/** send makes one request; `client` names the context client in its errors ("context.kv"). */
|
|
6
|
+
export function send(client, method, path, body, member, contentType) {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
const socketPath = process.env.FUNCD_INVOKE_SOCKET;
|
|
9
|
+
if (!socketPath) {
|
|
10
|
+
reject(new Error(`${client}: worker-node local API socket unavailable (FUNCD_INVOKE_SOCKET unset)`));
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const headers = {};
|
|
14
|
+
if (body)
|
|
15
|
+
headers['content-length'] = body.byteLength;
|
|
16
|
+
if (contentType)
|
|
17
|
+
headers['content-type'] = contentType;
|
|
18
|
+
if (member)
|
|
19
|
+
headers[MEMBER_HEADER] = member;
|
|
20
|
+
const req = http.request({ socketPath, path, method, headers }, (res) => {
|
|
21
|
+
const chunks = [];
|
|
22
|
+
// A connection that drops mid-body errors the response, not the request, and never ends it.
|
|
23
|
+
res.on('error', (err) => reject(new Error(`${client} ${method} ${path} failed: connection closed before the reply ended`, { cause: err })));
|
|
24
|
+
res.on('data', (c) => chunks.push(c));
|
|
25
|
+
res.on('end', () => resolve({ status: res.statusCode ?? 0, body: Buffer.concat(chunks) }));
|
|
26
|
+
});
|
|
27
|
+
req.on('error', (err) => reject(new Error(`${client} ${method} ${path} failed: ${err.message}`, { cause: err })));
|
|
28
|
+
if (body)
|
|
29
|
+
req.end(body);
|
|
30
|
+
else
|
|
31
|
+
req.end();
|
|
32
|
+
});
|
|
33
|
+
}
|
package/dist/sql.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** A SQL parameter: rqlite takes JSON scalars. Integers past 2^53 lose precision. */
|
|
2
|
+
export type SQLParam = string | number | boolean | null;
|
|
3
|
+
/** Positional parameters for `?`, or one map for `:name`. */
|
|
4
|
+
export type SQLParams = SQLParam[] | Record<string, SQLParam>;
|
|
5
|
+
/** One statement of a batch: its SQL text, with its parameters. */
|
|
6
|
+
export type SQLStatement = string | [sql: string, params?: SQLParams];
|
|
7
|
+
/** A row as an object; with a duplicate column name the last one wins (use queryValues to keep every column). */
|
|
8
|
+
export type SQLRow = Record<string, unknown>;
|
|
9
|
+
/** Rows as columns and arrays of values, as rqlite returns them: every column of a join is kept. */
|
|
10
|
+
export interface SQLValues {
|
|
11
|
+
columns: string[];
|
|
12
|
+
values: unknown[][];
|
|
13
|
+
}
|
|
14
|
+
/** The outcome of one executed statement; a RETURNING statement also carries its rows. */
|
|
15
|
+
export interface SQLExecResult {
|
|
16
|
+
rowsAffected: number;
|
|
17
|
+
lastInsertId: number;
|
|
18
|
+
columns?: string[];
|
|
19
|
+
values?: unknown[][];
|
|
20
|
+
}
|
|
21
|
+
/** A function's view of the SQL databases it binds (spec.sql), by alias. */
|
|
22
|
+
export interface SQLClient {
|
|
23
|
+
query(alias: string, sql: string, params?: SQLParams): Promise<SQLRow[]>;
|
|
24
|
+
queryValues(alias: string, sql: string, params?: SQLParams): Promise<SQLValues>;
|
|
25
|
+
execute(alias: string, sql: string, params?: SQLParams): Promise<SQLExecResult>;
|
|
26
|
+
execute(alias: string, statements: SQLStatement[]): Promise<SQLExecResult[]>;
|
|
27
|
+
}
|
|
28
|
+
/** Build the context.sql client. In a pool, `member` names the calling function on every request. */
|
|
29
|
+
export declare function makeSQL(member?: string): SQLClient;
|
package/dist/sql.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// context.sql — function-facing SQL over the worker-node local API (funcd ADR-0233). Dials the per-sandbox socket
|
|
2
|
+
// (FUNCD_INVOKE_SOCKET); the platform routes /sql/… to the PDP-authorized facade with the sandbox's identity, and
|
|
3
|
+
// the database's engine and credential never reach the sandbox. query runs read-only; execute runs its statements
|
|
4
|
+
// in one transaction, all or nothing.
|
|
5
|
+
import { send } from "./socket.js";
|
|
6
|
+
/** wire is a statement in the local API's form: ["SQL", p1, p2, …] or ["SQL", {name: value}]. */
|
|
7
|
+
function wire(sql, params) {
|
|
8
|
+
if (params === undefined)
|
|
9
|
+
return [sql];
|
|
10
|
+
return Array.isArray(params) ? [sql, ...params] : [sql, params];
|
|
11
|
+
}
|
|
12
|
+
function toWire(s) {
|
|
13
|
+
return typeof s === 'string' ? [s] : wire(s[0], s[1]);
|
|
14
|
+
}
|
|
15
|
+
/** Build the context.sql client. In a pool, `member` names the calling function on every request. */
|
|
16
|
+
export function makeSQL(member) {
|
|
17
|
+
async function call(verb, alias, statements) {
|
|
18
|
+
const path = `/sql/${encodeURIComponent(alias)}/${verb}`;
|
|
19
|
+
const body = Buffer.from(JSON.stringify({ statements }), 'utf8');
|
|
20
|
+
const r = await send('context.sql', 'POST', path, body, member, 'application/json');
|
|
21
|
+
const text = r.body.toString('utf8');
|
|
22
|
+
if (r.status < 200 || r.status >= 300)
|
|
23
|
+
throw new Error(`context.sql.${verb} failed: ${r.status} ${text}`);
|
|
24
|
+
try {
|
|
25
|
+
return JSON.parse(text).results;
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
throw new Error(`context.sql.${verb} failed: ${r.status} reply is not JSON: ${err.message}`, {
|
|
29
|
+
cause: err,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function queryValues(alias, sql, params) {
|
|
34
|
+
const [res] = await call('query', alias, [wire(sql, params)]);
|
|
35
|
+
return res;
|
|
36
|
+
}
|
|
37
|
+
async function execute(alias, sqlOrStatements, params) {
|
|
38
|
+
if (typeof sqlOrStatements === 'string') {
|
|
39
|
+
const [res] = await call('execute', alias, [wire(sqlOrStatements, params)]);
|
|
40
|
+
return res;
|
|
41
|
+
}
|
|
42
|
+
return call('execute', alias, sqlOrStatements.map(toWire));
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
async query(alias, sql, params) {
|
|
46
|
+
const { columns, values } = await queryValues(alias, sql, params);
|
|
47
|
+
return values.map((row) => Object.fromEntries(columns.map((c, i) => [c, row[i]])));
|
|
48
|
+
},
|
|
49
|
+
queryValues,
|
|
50
|
+
execute,
|
|
51
|
+
};
|
|
52
|
+
}
|
package/dist/tracespan.d.ts
CHANGED
|
@@ -8,8 +8,9 @@ export declare function parseTraceparent(tp: string | undefined): {
|
|
|
8
8
|
} | null;
|
|
9
9
|
/** newInvContext establishes the invocation identity: adopt the traceparent's trace-id + parent
|
|
10
10
|
* span-id when present, else mint a root (fresh 16-byte trace). The span-id is the engine-provided
|
|
11
|
-
* one (ADR-0105, X-Funcd-Span-Id) when a valid hex16 is given, else freshly minted (direct invoke).
|
|
12
|
-
|
|
11
|
+
* one (ADR-0105, X-Funcd-Span-Id) when a valid hex16 is given, else freshly minted (direct invoke).
|
|
12
|
+
* `deadline` is the call's deadline (ADR-0226), absent without a valid X-Funcd-Timeout-Ms. */
|
|
13
|
+
export declare function newInvContext(tp: string | undefined, providedSpanId?: string, deadline?: number): InvContext;
|
|
13
14
|
/** A live invocation span: run the handler inside its context (so logs correlate), then end() it
|
|
14
15
|
* with the outcome (which emits the span record on the channel). end() is idempotent. */
|
|
15
16
|
export interface Span {
|
|
@@ -22,8 +23,9 @@ export interface Span {
|
|
|
22
23
|
* the incoming `traceparent`; `spanId` is the engine-provided span-id to USE (ADR-0105,
|
|
23
24
|
* X-Funcd-Span-Id — else mint); `links` are fan-in edges (X-Funcd-Span-Links) attached to the span;
|
|
24
25
|
* `member` is the pool member, stamped as `funcd.member` (none in the solo shim); `bound` caps the span
|
|
25
|
-
* record line (FUNCD_FUNCLOG_MAX_RECORD_BYTES).
|
|
26
|
-
|
|
26
|
+
* record line (FUNCD_FUNCLOG_MAX_RECORD_BYTES); `deadline` is the call's deadline, which ctx.remainingMs()
|
|
27
|
+
* reads (ADR-0226). */
|
|
28
|
+
export declare function startSpan(sink: Sink | null, name: string, tp: string | undefined, spanId?: string, links?: string[], member?: string, bound?: number, deadline?: number): Span;
|
|
27
29
|
/** The CLIENT span of one context.invoke call (ADR-0165). */
|
|
28
30
|
export interface ClientSpan {
|
|
29
31
|
/** 00-<caller trace>-<this span>-01, stamped on POST /invoke/{alias}. */
|
package/dist/tracespan.js
CHANGED
|
@@ -29,8 +29,9 @@ export function parseTraceparent(tp) {
|
|
|
29
29
|
}
|
|
30
30
|
/** newInvContext establishes the invocation identity: adopt the traceparent's trace-id + parent
|
|
31
31
|
* span-id when present, else mint a root (fresh 16-byte trace). The span-id is the engine-provided
|
|
32
|
-
* one (ADR-0105, X-Funcd-Span-Id) when a valid hex16 is given, else freshly minted (direct invoke).
|
|
33
|
-
|
|
32
|
+
* one (ADR-0105, X-Funcd-Span-Id) when a valid hex16 is given, else freshly minted (direct invoke).
|
|
33
|
+
* `deadline` is the call's deadline (ADR-0226), absent without a valid X-Funcd-Timeout-Ms. */
|
|
34
|
+
export function newInvContext(tp, providedSpanId, deadline) {
|
|
34
35
|
const adopted = parseTraceparent(tp);
|
|
35
36
|
const spanId = providedSpanId && /^[0-9a-f]{16}$/.test(providedSpanId) ? providedSpanId : randomBytes(8).toString('hex');
|
|
36
37
|
return {
|
|
@@ -38,6 +39,7 @@ export function newInvContext(tp, providedSpanId) {
|
|
|
38
39
|
traceId: adopted ? adopted.traceId : randomBytes(16).toString('hex'),
|
|
39
40
|
spanId,
|
|
40
41
|
parentId: adopted ? adopted.parentId : '',
|
|
42
|
+
deadline,
|
|
41
43
|
};
|
|
42
44
|
}
|
|
43
45
|
/** emitSpan writes one span record. `ids` names the span (trace, span, parent, inv): the invocation's
|
|
@@ -88,9 +90,10 @@ function boundSpan(rec, bound) {
|
|
|
88
90
|
* the incoming `traceparent`; `spanId` is the engine-provided span-id to USE (ADR-0105,
|
|
89
91
|
* X-Funcd-Span-Id — else mint); `links` are fan-in edges (X-Funcd-Span-Links) attached to the span;
|
|
90
92
|
* `member` is the pool member, stamped as `funcd.member` (none in the solo shim); `bound` caps the span
|
|
91
|
-
* record line (FUNCD_FUNCLOG_MAX_RECORD_BYTES).
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
* record line (FUNCD_FUNCLOG_MAX_RECORD_BYTES); `deadline` is the call's deadline, which ctx.remainingMs()
|
|
94
|
+
* reads (ADR-0226). */
|
|
95
|
+
export function startSpan(sink, name, tp, spanId, links = [], member, bound = DEFAULT_MAX_RECORD_BYTES, deadline) {
|
|
96
|
+
const inv = newInvContext(tp, spanId, deadline);
|
|
94
97
|
const startNs = Date.now() * 1e6;
|
|
95
98
|
const t0 = process.hrtime.bigint();
|
|
96
99
|
const validLinks = links.filter((l) => /^[0-9a-f]{16}$/.test(l));
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { KVClient } from './kv.ts';
|
|
2
2
|
import type { BlobClient } from './blob.ts';
|
|
3
|
+
import type { SQLClient } from './sql.ts';
|
|
3
4
|
export type { KVClient } from './kv.ts';
|
|
4
5
|
export type { BlobClient, SignOptions } from './blob.ts';
|
|
6
|
+
export type { SQLClient, SQLExecResult, SQLParam, SQLParams, SQLRow, SQLStatement, SQLValues, } from './sql.ts';
|
|
5
7
|
/** A CloudEvent — the normalized trigger envelope (ADR-0023). */
|
|
6
8
|
export interface CloudEvent<T = unknown> {
|
|
7
9
|
id: string;
|
|
@@ -33,6 +35,11 @@ export interface FunctionContext {
|
|
|
33
35
|
/** Binding-scoped blob storage (ADR-0127): get/put/del/list a bound prefix's objects, or mint a
|
|
34
36
|
* presigned URL — the blob twin of kv. */
|
|
35
37
|
blob: BlobClient;
|
|
38
|
+
/** The SQL databases a function binds (funcd ADR-0233): query reads, queryValues keeps every column of a join,
|
|
39
|
+
* execute writes in one transaction. A write needs the database's owner or a writer role. */
|
|
40
|
+
sql: SQLClient;
|
|
41
|
+
/** Milliseconds left before the call's deadline (X-Funcd-Timeout-Ms), floored at 0; null without one (ADR-0226). */
|
|
42
|
+
remainingMs(): number | null;
|
|
36
43
|
}
|
|
37
44
|
/** A function handler: receives the context + CloudEvent, returns a response (or nothing). */
|
|
38
45
|
export type Handler<In = unknown, Out = unknown> = (context: FunctionContext, event: CloudEvent<In>) => Out | Promise<Out>;
|