@funcd-dev/shim 0.16.0 → 0.18.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  // context.blob — function-facing blob over the worker-node local API (HTTP-over-UDS, ADR-0127). Dials the
2
2
  // same per-sandbox socket as context.kv/context.invoke (FUNCD_INVOKE_SOCKET); the platform routes /blob/…
3
3
  // to the binding-gated, PDP-authorized Facade with the sandbox's function identity (bind-as-grant on
4
- // spec.blob). Reached only through the built-in shim — no @aws-sdk, no keypair. The blob twin of context.kv;
4
+ // spec.bindings.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
6
  import { send as sendOn } from "./socket.js";
7
7
  const send = (method, path, body, member) => sendOn('context.blob', method, path, body, member);
@@ -0,0 +1,10 @@
1
+ export interface CatalogEndpoint {
2
+ url: string;
3
+ token: string;
4
+ }
5
+ /** A function's catalog bindings by alias (funcd ADR-0245). */
6
+ export interface CatalogClient {
7
+ /** Throws an Error naming the alias when it is not bound. */
8
+ get(alias: string): CatalogEndpoint;
9
+ }
10
+ export declare function makeCatalog(env?: NodeJS.ProcessEnv): CatalogClient;
@@ -0,0 +1,14 @@
1
+ // context.catalog — a catalog binding's proxy URL and this function's token (funcd ADR-0245, ADR-0091, ADR-0137), from
2
+ // FUNCD_CATALOG_<ALIAS>_URL and _TOKEN at call time.
3
+ export function makeCatalog(env = process.env) {
4
+ return {
5
+ get(alias) {
6
+ const prefix = `FUNCD_CATALOG_${alias.toUpperCase()}_`;
7
+ const url = env[`${prefix}URL`];
8
+ const token = env[`${prefix}TOKEN`];
9
+ if (!url || !token)
10
+ throw new Error(`context.catalog.get: catalog "${alias}" is not bound`);
11
+ return { url, token };
12
+ },
13
+ };
14
+ }
@@ -0,0 +1,8 @@
1
+ export declare function listedKeys(env: NodeJS.ProcessEnv, list: string): string[];
2
+ export declare function listedValue(env: NodeJS.ProcessEnv, list: string, key: string): string | undefined;
3
+ /** A function's bound config (funcd ADR-0245): a key a secret overrides, or any unbound variable, reads as undefined. */
4
+ export interface ConfigClient {
5
+ get(key: string): string | undefined;
6
+ list(): string[];
7
+ }
8
+ export declare function makeConfig(env?: NodeJS.ProcessEnv): ConfigClient;
package/dist/config.js ADDED
@@ -0,0 +1,16 @@
1
+ // context.config — the keys of a function's bound ConfigMaps (funcd ADR-0245), read from the environment at call time.
2
+ // funcd sets FUNCD_CONFIG_KEYS and FUNCD_SECRET_KEYS, comma-separated lists of the bound keys of each kind in the
3
+ // environment; an absent or empty list is no keys. context.secret reads its list with the same helpers.
4
+ export function listedKeys(env, list) {
5
+ const v = env[list];
6
+ return v ? v.split(',') : [];
7
+ }
8
+ export function listedValue(env, list, key) {
9
+ return listedKeys(env, list).includes(key) ? env[key] : undefined;
10
+ }
11
+ export function makeConfig(env = process.env) {
12
+ return {
13
+ get: (key) => listedValue(env, 'FUNCD_CONFIG_KEYS', key),
14
+ list: () => listedKeys(env, 'FUNCD_CONFIG_KEYS'),
15
+ };
16
+ }
@@ -0,0 +1,6 @@
1
+ /** A function's bound secrets (funcd ADR-0245): an unbound key reads as undefined. */
2
+ export interface SecretClient {
3
+ get(key: string): Promise<string | undefined>;
4
+ list(): Promise<string[]>;
5
+ }
6
+ export declare function makeSecret(env?: NodeJS.ProcessEnv): SecretClient;
package/dist/secret.js ADDED
@@ -0,0 +1,9 @@
1
+ // context.secret — the keys of a function's bound Secrets (funcd ADR-0245), read from the environment at call time.
2
+ // The methods return Promises, as every client that calls funcd does, so a later read from funcd keeps this API.
3
+ import { listedKeys, listedValue } from "./config.js";
4
+ export function makeSecret(env = process.env) {
5
+ return {
6
+ get: async (key) => listedValue(env, 'FUNCD_SECRET_KEYS', key),
7
+ list: async () => listedKeys(env, 'FUNCD_SECRET_KEYS'),
8
+ };
9
+ }
package/dist/sql.d.ts CHANGED
@@ -18,7 +18,7 @@ export interface SQLExecResult {
18
18
  columns?: string[];
19
19
  values?: unknown[][];
20
20
  }
21
- /** A function's view of the SQL databases it binds (spec.sql), by alias. */
21
+ /** A function's view of the SQL databases it binds (spec.bindings.sql), by alias. */
22
22
  export interface SQLClient {
23
23
  query(alias: string, sql: string, params?: SQLParams): Promise<SQLRow[]>;
24
24
  queryValues(alias: string, sql: string, params?: SQLParams): Promise<SQLValues>;
package/dist/types.d.ts CHANGED
@@ -1,9 +1,15 @@
1
1
  import type { KVClient } from './kv.ts';
2
2
  import type { BlobClient } from './blob.ts';
3
3
  import type { SQLClient } from './sql.ts';
4
+ import type { ConfigClient } from './config.ts';
5
+ import type { SecretClient } from './secret.ts';
6
+ import type { CatalogClient } from './catalog.ts';
4
7
  export type { KVClient } from './kv.ts';
5
8
  export type { BlobClient, SignOptions } from './blob.ts';
6
9
  export type { SQLClient, SQLExecResult, SQLParam, SQLParams, SQLRow, SQLStatement, SQLValues, } from './sql.ts';
10
+ export type { ConfigClient } from './config.ts';
11
+ export type { SecretClient } from './secret.ts';
12
+ export type { CatalogClient, CatalogEndpoint } from './catalog.ts';
7
13
  /** A CloudEvent — the normalized trigger envelope (ADR-0023). */
8
14
  export interface CloudEvent<T = unknown> {
9
15
  id: string;
@@ -21,7 +27,7 @@ export interface CloudEvent<T = unknown> {
21
27
  export interface FunctionContext {
22
28
  /** Structured log line → stdout (collected by the platform, ADR-0010). */
23
29
  log(...args: unknown[]): void;
24
- /** Synchronously invoke a linked function by its spec.links alias (ADR-0064). The input is
30
+ /** Synchronously invoke a linked function by its spec.bindings.links alias (ADR-0064). The input is
25
31
  * validated against the target's contract by the target's shim; its result is returned. Fails
26
32
  * closed (rejects) if the caller declares no such link.
27
33
  *
@@ -30,7 +36,7 @@ export interface FunctionContext {
30
36
  * `data`, and the other keys are dropped. To send an object that has its own `data` key, wrap it in an
31
37
  * envelope: `{ specversion: '1.0', data: { data: [1], page: 2 } }`. */
32
38
  invoke<I = unknown, O = unknown>(alias: string, input: I): Promise<O>;
33
- /** Send an HTTP request to a linked Function that serves HTTP (spec.protocol: http) by its spec.links alias
39
+ /** Send an HTTP request to a linked Function that serves HTTP (spec.protocol: http) by its spec.bindings.links alias
34
40
  * (funcd ADR-0243). `path` starts with "/" and may carry a query. The reply comes back whole, at most 1 MiB, with
35
41
  * its status and headers; funcd answers an error status, and calls nothing, for an undeclared link or a target
36
42
  * that does not serve HTTP (call it with invoke). */
@@ -43,6 +49,12 @@ export interface FunctionContext {
43
49
  /** The SQL databases a function binds (funcd ADR-0233): query reads, queryValues keeps every column of a join,
44
50
  * execute writes in one transaction. A write needs the database's owner or a writer role. */
45
51
  sql: SQLClient;
52
+ /** The keys of the ConfigMaps a function binds (funcd ADR-0245); a key a bound Secret overrides is a secret. */
53
+ config: ConfigClient;
54
+ /** The keys of the Secrets a function binds (funcd ADR-0245). */
55
+ secret: SecretClient;
56
+ /** A bound catalog's proxy URL and this function's token, by spec.bindings.catalog alias (funcd ADR-0245). */
57
+ catalog: CatalogClient;
46
58
  /** Milliseconds left before the call's deadline (X-Funcd-Timeout-Ms), floored at 0; null without one (ADR-0226). */
47
59
  remainingMs(): number | null;
48
60
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funcd-dev/shim",
3
- "version": "0.16.0",
3
+ "version": "0.18.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",