@funcd-dev/shim 0.15.0 → 0.17.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/catalog.d.ts +10 -0
- package/dist/catalog.js +14 -0
- package/dist/config.d.ts +8 -0
- package/dist/config.js +16 -0
- package/dist/secret.d.ts +6 -0
- package/dist/secret.js +9 -0
- package/dist/types.d.ts +12 -0
- package/package.json +1 -1
|
@@ -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;
|
package/dist/catalog.js
ADDED
|
@@ -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
|
+
}
|
package/dist/config.d.ts
ADDED
|
@@ -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
|
+
}
|
package/dist/secret.d.ts
ADDED
|
@@ -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/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;
|
|
@@ -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.catalogs 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
|
}
|