@funcd-dev/shim 0.28.0 → 0.30.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.d.ts +18 -6
- package/dist/config.d.ts +6 -1
- package/dist/invcontext.d.ts +2 -0
- package/dist/invcontext.js +2 -1
- package/dist/kv.d.ts +1 -1
- package/dist/lake.d.ts +3 -2
- package/dist/principal.d.ts +10 -0
- package/dist/principal.js +37 -0
- package/dist/secret.d.ts +15 -3
- package/dist/sql.d.ts +9 -0
- package/dist/tracespan.d.ts +6 -4
- package/dist/tracespan.js +7 -5
- package/dist/types.d.ts +39 -21
- package/package.json +1 -1
package/dist/blob.d.ts
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
|
-
/** Options for a presigned URL: the HTTP method it
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* A PUT/DELETE URL requires s3::write. */
|
|
1
|
+
/** Options for a presigned URL: the HTTP method it allows, GET by default, and its lifetime, a duration such as "10m"
|
|
2
|
+
* or "1h30m" in whole seconds from 1s to 168h. funcd refuses another value, "" included, with the HTTP status 400;
|
|
3
|
+
* without an expiry, the URL lasts 15 minutes. A PUT or DELETE URL needs permission to write the prefix. */
|
|
5
4
|
export interface SignOptions {
|
|
6
5
|
method?: 'GET' | 'PUT' | 'DELETE';
|
|
7
6
|
expiry?: string;
|
|
8
7
|
}
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
8
|
+
/** The Bucket prefixes that a function binds, each by its alias in spec.bindings.blob: read, write, delete and list
|
|
9
|
+
* their objects, whose keys are relative to the binding's prefix. */
|
|
11
10
|
export interface BlobClient {
|
|
11
|
+
/** The object's content as bytes, or null when the object does not exist. */
|
|
12
12
|
get(binding: string, key: string): Promise<Uint8Array | null>;
|
|
13
|
+
/** Writes the object, replacing any object with that key. The value is at most 64 MiB, and at most the Bucket's
|
|
14
|
+
* spec.quota.maxObjectBytes when that is set: a larger one fails with the HTTP status 413. Only the prefix's owner
|
|
15
|
+
* and the writers that a RolesAssignment names can write. */
|
|
13
16
|
put(binding: string, key: string, value: Uint8Array): Promise<void>;
|
|
17
|
+
/** Deletes the object, and fails with the HTTP status 404 when it does not exist. Only the prefix's owner and the
|
|
18
|
+
* writers that a RolesAssignment names can delete. */
|
|
14
19
|
del(binding: string, key: string): Promise<void>;
|
|
20
|
+
/** The keys that start with prefix; without a prefix, every key under the binding's prefix. */
|
|
15
21
|
list(binding: string, prefix?: string): Promise<string[]>;
|
|
22
|
+
/** A presigned URL that lets its holder send an opts.method request, GET by default, for the object until
|
|
23
|
+
* opts.expiry passes: a duration such as "10m" or "1h30m", in whole seconds from 1s to 168h, or 15 minutes when
|
|
24
|
+
* unset. Any other expiry, "" included, fails with the HTTP status 400. A PUT or DELETE URL needs permission to
|
|
25
|
+
* write the prefix, and a PUT URL fails with the HTTP status 403 when the Bucket sets maxObjectBytes or a size
|
|
26
|
+
* quota applies to the Bucket or the prefix, since funcd could not enforce it on the upload. No blob store that
|
|
27
|
+
* funcd opens signs URLs, so a call that passes these checks fails with the HTTP status 503. */
|
|
16
28
|
signedUrl(binding: string, key: string, opts?: SignOptions): Promise<string>;
|
|
17
29
|
}
|
|
18
30
|
/** Build the context.blob client. In a pool, `member` names the calling function on every request
|
package/dist/config.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
/** A function's bound config
|
|
1
|
+
/** A function's bound config: the keys of the ConfigMaps in spec.bindings.config, with the values that the worker got
|
|
2
|
+
* when it started. A key that starts with FUNCD_, a key that a bound Secret also holds, and any other variable read
|
|
3
|
+
* as undefined. While funcd's S3 gateway runs, the AWS key pair that funcd issues replaces a ConfigMap's values for
|
|
4
|
+
* AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. */
|
|
2
5
|
export interface ConfigClient {
|
|
6
|
+
/** The key's value, or undefined when list() does not include the key. */
|
|
3
7
|
get(key: string): string | undefined;
|
|
8
|
+
/** The keys of the bound ConfigMaps, sorted, without the keys left out. */
|
|
4
9
|
list(): string[];
|
|
5
10
|
}
|
|
6
11
|
export declare function makeConfig(env?: NodeJS.ProcessEnv): ConfigClient;
|
package/dist/invcontext.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import type { Principal } from './principal.ts';
|
|
2
3
|
/** The identity of the currently-executing invocation. */
|
|
3
4
|
export interface InvContext {
|
|
4
5
|
inv: string;
|
|
@@ -6,6 +7,7 @@ export interface InvContext {
|
|
|
6
7
|
spanId: string;
|
|
7
8
|
parentId: string;
|
|
8
9
|
deadline?: number;
|
|
10
|
+
principal?: Principal;
|
|
9
11
|
}
|
|
10
12
|
/** invStore holds the active InvContext for the duration of a handler call (and its async
|
|
11
13
|
* continuations). Per-thread: each worker/process imports its own instance, which is correct —
|
package/dist/invcontext.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
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
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
|
+
// call's deadline, which ctx.remainingMs() reads (ADR-0226), and its principal, which ctx.principal reads
|
|
7
|
+
// (funcd ADR-0335): the handler's context is one object for every call.
|
|
7
8
|
//
|
|
8
9
|
// Built-ins only (node:async_hooks) so it bundles into shim.mjs/pool.mjs.
|
|
9
10
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
package/dist/kv.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export interface KVClient {
|
|
|
23
23
|
* put(binding, key, JSON.stringify(value)). */
|
|
24
24
|
getJSON<T = unknown>(binding: string, key: string): Promise<T | null>;
|
|
25
25
|
/** Writes the value. opts.ttl, in whole seconds, sets the key's expiry; a put without it leaves the key with none.
|
|
26
|
-
* Only the table's owner can write. */
|
|
26
|
+
* Only the table's owner and the writers that a RolesAssignment names can write. */
|
|
27
27
|
put(binding: string, key: string, value: Uint8Array | string, opts?: PutOptions): Promise<void>;
|
|
28
28
|
/** Creates the key: its new version, or null when it exists (an expired key does not). */
|
|
29
29
|
putIfAbsent(binding: string, key: string, value: Uint8Array | string, opts?: PutOptions): Promise<string | null>;
|
package/dist/lake.d.ts
CHANGED
|
@@ -2,9 +2,10 @@ export interface LakeEndpoint {
|
|
|
2
2
|
url: string;
|
|
3
3
|
token: string;
|
|
4
4
|
}
|
|
5
|
-
/** A function's
|
|
5
|
+
/** A function's Lake bindings, each by its alias in spec.bindings.lake. */
|
|
6
6
|
export interface LakeClient {
|
|
7
|
-
/**
|
|
7
|
+
/** The gateway of the Lake bound as alias: url, its address as host:port, and token, the token that it accepts from
|
|
8
|
+
* the function. Throws an Error naming the alias when the function binds no Lake with that alias. */
|
|
8
9
|
get(alias: string): LakeEndpoint;
|
|
9
10
|
}
|
|
10
11
|
export declare function makeLake(env?: NodeJS.ProcessEnv): LakeClient;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { FunctionContext } from './types.ts';
|
|
2
|
+
/** The principal of a signed-in call, as ctx.principal holds it. */
|
|
3
|
+
export type Principal = NonNullable<FunctionContext['principal']>;
|
|
4
|
+
/** The headers funcd's edge sets for a signed-in call. An http app receives them as sent. */
|
|
5
|
+
export declare const PRINCIPAL_HEADERS: ReadonlySet<string>;
|
|
6
|
+
/** principalFrom builds a call's principal from its headers: provider and claims from X-Funcd-Principal, the standard
|
|
7
|
+
* Base64 of the JSON {provider, claims}, id from X-Funcd-Principal-Id and name from X-Funcd-Principal-Name. It is
|
|
8
|
+
* undefined when X-Funcd-Principal or X-Funcd-Principal-Id is absent or empty, or when X-Funcd-Principal is not that
|
|
9
|
+
* encoding of an object with a provider name and an object of claims. */
|
|
10
|
+
export declare function principalFrom(headers: Headers): Principal | undefined;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** The headers funcd's edge sets for a signed-in call. An http app receives them as sent. */
|
|
2
|
+
export const PRINCIPAL_HEADERS = new Set([
|
|
3
|
+
'x-funcd-principal',
|
|
4
|
+
'x-funcd-principal-id',
|
|
5
|
+
'x-funcd-principal-name',
|
|
6
|
+
'x-funcd-id-token',
|
|
7
|
+
]);
|
|
8
|
+
// Standard Base64 with its padding, the form the edge writes.
|
|
9
|
+
const BASE64 = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
10
|
+
const isObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
11
|
+
// Node reads each byte of a header value as one Latin-1 character; the edge writes the values as UTF-8.
|
|
12
|
+
const utf8 = (value) => Buffer.from(value, 'latin1').toString('utf8');
|
|
13
|
+
/** principalFrom builds a call's principal from its headers: provider and claims from X-Funcd-Principal, the standard
|
|
14
|
+
* Base64 of the JSON {provider, claims}, id from X-Funcd-Principal-Id and name from X-Funcd-Principal-Name. It is
|
|
15
|
+
* undefined when X-Funcd-Principal or X-Funcd-Principal-Id is absent or empty, or when X-Funcd-Principal is not that
|
|
16
|
+
* encoding of an object with a provider name and an object of claims. */
|
|
17
|
+
export function principalFrom(headers) {
|
|
18
|
+
const encoded = headers.get('x-funcd-principal');
|
|
19
|
+
const id = headers.get('x-funcd-principal-id');
|
|
20
|
+
if (!encoded || !id || !BASE64.test(encoded))
|
|
21
|
+
return undefined;
|
|
22
|
+
let value;
|
|
23
|
+
try {
|
|
24
|
+
value = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(Buffer.from(encoded, 'base64')));
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
if (!isObject(value) || typeof value.provider !== 'string' || value.provider === '' || !isObject(value.claims)) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
const principal = { provider: value.provider, id: utf8(id), claims: value.claims };
|
|
33
|
+
const name = headers.get('x-funcd-principal-name');
|
|
34
|
+
if (name)
|
|
35
|
+
principal.name = utf8(name);
|
|
36
|
+
return principal;
|
|
37
|
+
}
|
package/dist/secret.d.ts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
/** A function's bound
|
|
1
|
+
/** A function's bound Secrets: get and list read them at each call, and put and del change one key of a bound Secret
|
|
2
|
+
* that the function may write. A key that no bound Secret holds, or that starts with FUNCD_, reads as undefined. */
|
|
2
3
|
export interface SecretClient {
|
|
4
|
+
/** The key's value, or undefined when no bound Secret holds the key, the key starts with FUNCD_, or a bound Secret
|
|
5
|
+
* does not exist. When two Secrets hold the key, the later one in spec.bindings.secret wins. Fails with the HTTP
|
|
6
|
+
* status 403 when a Policy forbids the function to read a bound Secret. */
|
|
3
7
|
get(key: string): Promise<string | undefined>;
|
|
8
|
+
/** The keys that the bound Secrets hold, sorted, except a key that starts with FUNCD_. Fails with the HTTP status
|
|
9
|
+
* 403 when a Policy forbids the function to read a bound Secret, and 404 when a bound Secret does not exist. */
|
|
4
10
|
list(): Promise<string[]>;
|
|
5
11
|
/** Writes key in Secret `binding`, which the function binds and may write: its owner, or a principal a writer role
|
|
6
|
-
* names. Every function that binds it reads the value at its next read.
|
|
12
|
+
* names. Every function that binds it reads the value at its next read. Fails with the HTTP status 403 when the
|
|
13
|
+
* function does not bind the Secret or may not write it, 404 when the Secret does not exist, 400 when the key or
|
|
14
|
+
* the value breaks a Secret's rules, 413 when the request passes 1 MiB, and 409 when the Secret changed under
|
|
15
|
+
* each of 5 attempts to write it. */
|
|
7
16
|
put(binding: string, key: string, value: string): Promise<void>;
|
|
8
|
-
/** Removes key from Secret `binding`,
|
|
17
|
+
/** Removes key from Secret `binding`, which the function binds and may write, as for put; a key that the Secret
|
|
18
|
+
* lacks is no error. Fails with the HTTP status 403 when the function does not bind the Secret
|
|
19
|
+
* or may not write it, 404 when the Secret does not exist, and 409 when the Secret changed under each of 5
|
|
20
|
+
* attempts to write it. */
|
|
9
21
|
del(binding: string, key: string): Promise<void>;
|
|
10
22
|
}
|
|
11
23
|
/** Build the context.secret client. In a pool, `member` names the calling function on every request (funcd checks it
|
package/dist/sql.d.ts
CHANGED
|
@@ -20,8 +20,17 @@ export interface SQLExecResult {
|
|
|
20
20
|
}
|
|
21
21
|
/** A function's view of the SQL databases it binds (spec.bindings.sql), by alias. */
|
|
22
22
|
export interface SQLClient {
|
|
23
|
+
/** Runs one statement that reads, and returns its rows as objects keyed by column name; with a duplicate column name,
|
|
24
|
+
* the last one wins. params fill the statement's ? placeholders in order, or its :name placeholders from one object.
|
|
25
|
+
* A statement that writes, or that the database refuses, fails with the HTTP status 400. */
|
|
23
26
|
query(alias: string, sql: string, params?: SQLParams): Promise<SQLRow[]>;
|
|
27
|
+
/** Runs one statement that reads, and returns its column names and its rows as arrays of values in column order, so
|
|
28
|
+
* every column of a join is kept. params and failures are as for query. */
|
|
24
29
|
queryValues(alias: string, sql: string, params?: SQLParams): Promise<SQLValues>;
|
|
30
|
+
/** Runs one statement, or a list of up to 500 statements, in one transaction that applies all or none of them.
|
|
31
|
+
* Returns the statement's result, or one result for each statement of a list: rowsAffected and lastInsertId, with
|
|
32
|
+
* columns and values for a RETURNING statement. A statement that the database refuses fails the call with the HTTP
|
|
33
|
+
* status 400. Only the database's owner and the writers that a RolesAssignment names can execute. */
|
|
25
34
|
execute(alias: string, sql: string, params?: SQLParams): Promise<SQLExecResult>;
|
|
26
35
|
execute(alias: string, statements: SQLStatement[]): Promise<SQLExecResult[]>;
|
|
27
36
|
}
|
package/dist/tracespan.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type InvContext } from './invcontext.ts';
|
|
2
2
|
import { type Sink } from './funclog.ts';
|
|
3
|
+
import type { Principal } from './principal.ts';
|
|
3
4
|
/** parseTraceparent parses a W3C `traceparent` (`00-<trace32>-<span16>-<flags>`), returning the
|
|
4
5
|
* trace-id + parent span-id, or null when absent/malformed/all-zero (⇒ the caller mints a root). */
|
|
5
6
|
export declare function parseTraceparent(tp: string | undefined): {
|
|
@@ -9,8 +10,9 @@ export declare function parseTraceparent(tp: string | undefined): {
|
|
|
9
10
|
/** newInvContext establishes the invocation identity: adopt the traceparent's trace-id + parent
|
|
10
11
|
* span-id when present, else mint a root (fresh 16-byte trace). The span-id is the engine-provided
|
|
11
12
|
* 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
|
-
|
|
13
|
+
* `deadline` is the call's deadline (ADR-0226), absent without a valid X-Funcd-Timeout-Ms; `principal` is who signed
|
|
14
|
+
* in to the call (funcd ADR-0335), absent when nobody did. */
|
|
15
|
+
export declare function newInvContext(tp: string | undefined, providedSpanId?: string, deadline?: number, principal?: Principal): InvContext;
|
|
14
16
|
/** A live invocation span: run the handler inside its context (so logs correlate), then end() it
|
|
15
17
|
* with the outcome (which emits the span record on the channel). end() is idempotent. */
|
|
16
18
|
export interface Span {
|
|
@@ -24,8 +26,8 @@ export interface Span {
|
|
|
24
26
|
* X-Funcd-Span-Id — else mint); `links` are fan-in edges (X-Funcd-Span-Links) attached to the span;
|
|
25
27
|
* `member` is the pool member, stamped as `funcd.member` (none in the solo shim); `bound` caps the span
|
|
26
28
|
* 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;
|
|
29
|
+
* reads (ADR-0226); `principal` is who signed in to the call, which ctx.principal reads (funcd ADR-0335). */
|
|
30
|
+
export declare function startSpan(sink: Sink | null, name: string, tp: string | undefined, spanId?: string, links?: string[], member?: string, bound?: number, deadline?: number, principal?: Principal): Span;
|
|
29
31
|
/** The CLIENT span of one context.invoke call (ADR-0165). */
|
|
30
32
|
export interface ClientSpan {
|
|
31
33
|
/** 00-<caller trace>-<this span>-01, stamped on POST /invoke/{alias}. */
|
package/dist/tracespan.js
CHANGED
|
@@ -30,8 +30,9 @@ export function parseTraceparent(tp) {
|
|
|
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
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
|
-
|
|
33
|
+
* `deadline` is the call's deadline (ADR-0226), absent without a valid X-Funcd-Timeout-Ms; `principal` is who signed
|
|
34
|
+
* in to the call (funcd ADR-0335), absent when nobody did. */
|
|
35
|
+
export function newInvContext(tp, providedSpanId, deadline, principal) {
|
|
35
36
|
const adopted = parseTraceparent(tp);
|
|
36
37
|
const spanId = providedSpanId && /^[0-9a-f]{16}$/.test(providedSpanId) ? providedSpanId : randomBytes(8).toString('hex');
|
|
37
38
|
return {
|
|
@@ -40,6 +41,7 @@ export function newInvContext(tp, providedSpanId, deadline) {
|
|
|
40
41
|
spanId,
|
|
41
42
|
parentId: adopted ? adopted.parentId : '',
|
|
42
43
|
deadline,
|
|
44
|
+
principal,
|
|
43
45
|
};
|
|
44
46
|
}
|
|
45
47
|
/** emitSpan writes one span record. `ids` names the span (trace, span, parent, inv): the invocation's
|
|
@@ -91,9 +93,9 @@ function boundSpan(rec, bound) {
|
|
|
91
93
|
* X-Funcd-Span-Id — else mint); `links` are fan-in edges (X-Funcd-Span-Links) attached to the span;
|
|
92
94
|
* `member` is the pool member, stamped as `funcd.member` (none in the solo shim); `bound` caps the span
|
|
93
95
|
* 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);
|
|
96
|
+
* reads (ADR-0226); `principal` is who signed in to the call, which ctx.principal reads (funcd ADR-0335). */
|
|
97
|
+
export function startSpan(sink, name, tp, spanId, links = [], member, bound = DEFAULT_MAX_RECORD_BYTES, deadline, principal) {
|
|
98
|
+
const inv = newInvContext(tp, spanId, deadline, principal);
|
|
97
99
|
const startNs = Date.now() * 1e6;
|
|
98
100
|
const t0 = process.hrtime.bigint();
|
|
99
101
|
const validLinks = links.filter((l) => /^[0-9a-f]{16}$/.test(l));
|
package/dist/types.d.ts
CHANGED
|
@@ -25,38 +25,56 @@ export interface CloudEvent<T = unknown> {
|
|
|
25
25
|
}
|
|
26
26
|
/** The per-invocation context the shim passes to the handler. */
|
|
27
27
|
export interface FunctionContext {
|
|
28
|
-
/**
|
|
28
|
+
/** Writes the arguments as one log line at level INFO, as console.log does. */
|
|
29
29
|
log(...args: unknown[]): void;
|
|
30
|
-
/**
|
|
31
|
-
*
|
|
32
|
-
* the
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* envelope: `{ specversion: '1.0', data: { data: [1], page: 2 } }`. */
|
|
30
|
+
/** Calls the function that the link named alias targets, and returns its result parsed from JSON, or null when it
|
|
31
|
+
* returns nothing. The target's event.data is input, except that an object with a top-level `data` or
|
|
32
|
+
* `specversion` key is taken as the whole CloudEvent, so event.data is only its `data`: send such an object inside
|
|
33
|
+
* an envelope, as `{ specversion: '1.0', data: { data: [1], page: 2 } }`. The link's timeout, 30 seconds by
|
|
34
|
+
* default, bounds the call. Fails with the HTTP status 403 when the function declares no link named alias, 409 when
|
|
35
|
+
* the target serves HTTP, 422 when input does not match the target's contract, and the target's status when its
|
|
36
|
+
* handler fails, such as 500. */
|
|
38
37
|
invoke<I = unknown, O = unknown>(alias: string, input: I): Promise<O>;
|
|
39
|
-
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
38
|
+
/** Sends an HTTP request to the function that the link named alias targets, which serves HTTP, and returns its reply
|
|
39
|
+
* as a Response, whatever its status. path starts with "/" and may carry a query; init sets the method, the headers
|
|
40
|
+
* and the body, as for the global fetch. The request body and the reply are each at most 1 MiB, and the link's
|
|
41
|
+
* timeout, 30 seconds by default, bounds the call. Fails with the HTTP status 403 when the function declares no
|
|
42
|
+
* link named alias, and 409 when the target does not serve HTTP. */
|
|
43
43
|
fetch(alias: string, path: string, init?: RequestInit): Promise<Response>;
|
|
44
44
|
/** The key-value tables that the function binds, by alias: read, write and list their keys. */
|
|
45
45
|
kv: KVClient;
|
|
46
|
-
/**
|
|
47
|
-
*
|
|
46
|
+
/** The Bucket prefixes that the function binds, by alias: read, write, delete and list their objects, whose keys are
|
|
47
|
+
* relative to the binding's prefix. */
|
|
48
48
|
blob: BlobClient;
|
|
49
|
-
/** The SQL databases
|
|
50
|
-
* execute writes in one transaction. A
|
|
49
|
+
/** The SQL databases that the function binds, by alias: query reads rows, queryValues keeps every column of a join,
|
|
50
|
+
* and execute writes in one transaction. A call fails with the HTTP status 503 while the database's engine is not
|
|
51
|
+
* Ready, or when a statement runs past funcd's SQL call timeout, 30 seconds by default. */
|
|
51
52
|
sql: SQLClient;
|
|
52
|
-
/** The keys of the ConfigMaps
|
|
53
|
+
/** The keys of the ConfigMaps that the function binds, with the values that the worker got when it started. A key
|
|
54
|
+
* that starts with FUNCD_ is left out, since funcd reserves that prefix. A key that a bound Secret also holds is
|
|
55
|
+
* left out too, and ctx.secret reads the Secret's value. While funcd's S3 gateway runs, a function that binds a
|
|
56
|
+
* Bucket reads the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY that funcd issues it, in place of a ConfigMap's. */
|
|
53
57
|
config: ConfigClient;
|
|
54
|
-
/** The
|
|
58
|
+
/** The Secrets that the function binds. get and list read their keys and values at each call, with no cache, so a
|
|
59
|
+
* changed Secret shows at the next read; a key that starts with FUNCD_ is never read: get returns undefined for
|
|
60
|
+
* it, and list leaves it out. put and del change one key of a bound Secret that the function may write, as the
|
|
61
|
+
* Secret's owner or through a writer role such as Secret Data Writer. */
|
|
55
62
|
secret: SecretClient;
|
|
56
|
-
/**
|
|
63
|
+
/** The Lakes that the function binds, by alias: the address of each Lake's gateway, and the token that the gateway
|
|
64
|
+
* accepts from the function. */
|
|
57
65
|
lake: LakeClient;
|
|
58
|
-
/**
|
|
66
|
+
/** The whole milliseconds left before the call's deadline, 0 once it has passed, or null when the call has none. */
|
|
59
67
|
remainingMs(): number | null;
|
|
68
|
+
/** Who signed in to the call, when funcd's edge signed a user in with an OpenID Connect provider: provider is the
|
|
69
|
+
* name of the OIDCProvider, id the user's subject (the sub claim), name the first of the claims name,
|
|
70
|
+
* preferred_username and email that is not empty, and claims the payload of the token that signed the user in, the
|
|
71
|
+
* ID token of a browser session or the Bearer token of an API call. Undefined when nobody signed in. */
|
|
72
|
+
principal?: {
|
|
73
|
+
provider: string;
|
|
74
|
+
id: string;
|
|
75
|
+
name?: string;
|
|
76
|
+
claims: Record<string, unknown>;
|
|
77
|
+
};
|
|
60
78
|
}
|
|
61
79
|
/** A function handler: receives the context + CloudEvent, returns a response (or nothing). */
|
|
62
80
|
export type Handler<In = unknown, Out = unknown> = (context: FunctionContext, event: CloudEvent<In>) => Out | Promise<Out>;
|