@funcd-dev/shim 0.27.0 → 0.29.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/kv.d.ts +1 -1
- package/dist/lake.d.ts +3 -2
- package/dist/secret.d.ts +18 -1
- package/dist/secret.js +15 -1
- package/dist/sql.d.ts +9 -0
- package/dist/types.d.ts +29 -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/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;
|
package/dist/secret.d.ts
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
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[]>;
|
|
11
|
+
/** Writes key in Secret `binding`, which the function binds and may write: its owner, or a principal a writer role
|
|
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. */
|
|
16
|
+
put(binding: string, key: string, value: string): Promise<void>;
|
|
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. */
|
|
21
|
+
del(binding: string, key: string): Promise<void>;
|
|
5
22
|
}
|
|
6
23
|
/** Build the context.secret client. In a pool, `member` names the calling function on every request (funcd checks it
|
|
7
24
|
* against the pool's members); the solo shim passes none. */
|
package/dist/secret.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// context.secret — the keys and values of a function's bound Secrets, read from funcd over the worker-node local API
|
|
2
2
|
// on every call (funcd ADR-0249): GET /secret and GET /secret/{key}, checked by funcd, with no cache. No secret sits in
|
|
3
|
-
// the worker's environment.
|
|
3
|
+
// the worker's environment. A function writes one key of a bound Secret it may write, its owner or a writer-role grant,
|
|
4
|
+
// with PUT and DELETE /secret/{binding}/{key} (funcd ADR-0327, ADR-0328).
|
|
4
5
|
import { send } from "./socket.js";
|
|
5
6
|
const fail = (verb, r) => new Error(`context.secret.${verb} failed: ${r.status} ${r.body.toString('utf8')}`);
|
|
6
7
|
const json = (verb, r) => {
|
|
@@ -13,6 +14,8 @@ const json = (verb, r) => {
|
|
|
13
14
|
});
|
|
14
15
|
}
|
|
15
16
|
};
|
|
17
|
+
const keyPath = (binding, key) => `/secret/${encodeURIComponent(binding)}/${encodeURIComponent(key)}`;
|
|
18
|
+
const written = (r) => r.status >= 200 && r.status < 300;
|
|
16
19
|
/** Build the context.secret client. In a pool, `member` names the calling function on every request (funcd checks it
|
|
17
20
|
* against the pool's members); the solo shim passes none. */
|
|
18
21
|
export function makeSecret(member) {
|
|
@@ -31,5 +34,16 @@ export function makeSecret(member) {
|
|
|
31
34
|
throw fail('list', r);
|
|
32
35
|
return json('list', r).keys;
|
|
33
36
|
},
|
|
37
|
+
async put(binding, key, value) {
|
|
38
|
+
const body = Buffer.from(JSON.stringify({ value }), 'utf8');
|
|
39
|
+
const r = await send('context.secret', 'PUT', keyPath(binding, key), body, member, 'application/json');
|
|
40
|
+
if (!written(r))
|
|
41
|
+
throw fail('put', r);
|
|
42
|
+
},
|
|
43
|
+
async del(binding, key) {
|
|
44
|
+
const r = await send('context.secret', 'DELETE', keyPath(binding, key), undefined, member);
|
|
45
|
+
if (!written(r))
|
|
46
|
+
throw fail('del', r);
|
|
47
|
+
},
|
|
34
48
|
};
|
|
35
49
|
}
|
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/types.d.ts
CHANGED
|
@@ -25,37 +25,45 @@ 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;
|
|
60
68
|
}
|
|
61
69
|
/** A function handler: receives the context + CloudEvent, returns a response (or nothing). */
|