@funcd-dev/shim 0.28.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 CHANGED
@@ -1,18 +1,30 @@
1
- /** Options for a presigned URL: the HTTP method it grants (default GET) and its lifetime, a duration string
2
- * such as "10m" or "1h30m" (funcd ADR-0198: units h, m, s, ms in that order, whole seconds from 1s to 168h). The
3
- * server checks it and answers 400 for a bad value, "" included; only an absent expiry gets the driver's default.
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
- /** A function's binding-scoped blob storage (ADR-0127): get/put/delete a bound prefix's objects, list
10
- * keys, or mint a presigned URL — the blob twin of KVClient. */
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 (funcd ADR-0245): a key a secret overrides, or any unbound variable, reads as undefined. */
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 lake bindings by alias (funcd ADR-0245). */
5
+ /** A function's Lake bindings, each by its alias in spec.bindings.lake. */
6
6
  export interface LakeClient {
7
- /** Throws an Error naming the alias when it is not bound. */
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,11 +1,23 @@
1
- /** A function's bound secrets (funcd ADR-0249): an unbound key reads as undefined. */
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`, as put may write it; a key the Secret lacks is no error. */
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/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
- /** Structured log line → stdout (collected by the platform, ADR-0010). */
28
+ /** Writes the arguments as one log line at level INFO, as console.log does. */
29
29
  log(...args: unknown[]): void;
30
- /** Synchronously invoke a linked function by its spec.bindings.links alias (ADR-0064). funcd checks the
31
- * input against the target's contract (funcd ADR-0303); its result is returned. Fails closed (rejects) if
32
- * the caller declares no such link.
33
- *
34
- * The target receives `input` as its `event.data`, except that an object with a top-level `data` or
35
- * `specversion` key is taken as a full CloudEvent envelope (ADR-0134): the target receives only its
36
- * `data`, and the other keys are dropped. To send an object that has its own `data` key, wrap it in an
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
- /** Send an HTTP request to a linked Function that serves HTTP (spec.protocol: http) by its spec.bindings.links alias
40
- * (funcd ADR-0243). `path` starts with "/" and may carry a query. The reply comes back whole, at most 1 MiB, with
41
- * its status and headers; funcd answers an error status, and calls nothing, for an undeclared link or a target
42
- * that does not serve HTTP (call it with invoke). */
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
- /** Binding-scoped blob storage (ADR-0127): get/put/del/list a bound prefix's objects, or mint a
47
- * presigned URL — the blob twin of kv. */
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 a function binds (funcd ADR-0233): query reads, queryValues keeps every column of a join,
50
- * execute writes in one transaction. A write needs the database's owner or a writer role. */
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 a function binds (funcd ADR-0245); a key a bound Secret overrides is a secret. */
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 keys and values of the Secrets a function binds, read from funcd on every call (funcd ADR-0249). */
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
- /** A bound lake's proxy URL and this function's token, by spec.bindings.lake alias (funcd ADR-0245). */
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
- /** Milliseconds left before the call's deadline (X-Funcd-Timeout-Ms), floored at 0; null without one (ADR-0226). */
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). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funcd-dev/shim",
3
- "version": "0.28.0",
3
+ "version": "0.29.0",
4
4
  "type": "module",
5
5
  "description": "Types and the contract build for writing funcd functions in TypeScript",
6
6
  "license": "Apache-2.0",