@funcd-dev/shim 0.26.0 → 0.28.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/kv.d.ts +15 -11
- package/dist/secret.d.ts +5 -0
- package/dist/secret.js +15 -1
- package/dist/types.d.ts +1 -1
- package/package.json +3 -2
package/dist/kv.d.ts
CHANGED
|
@@ -9,27 +9,31 @@ export interface PutOptions {
|
|
|
9
9
|
* lease from before the call never counts past the key's expiry. Renew it with a compareAndSet and a new ttl. */
|
|
10
10
|
ttl?: number;
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
/** The key-value tables that a function binds, each by its alias in spec.bindings.kv. putIfAbsent, compareAndSet and
|
|
13
|
+
* delIf write only while their condition holds and say who won: of racing writers, exactly one gets the new version,
|
|
14
|
+
* and the others get null (false for delIf). */
|
|
15
15
|
export interface KVClient {
|
|
16
|
+
/** The key's value as bytes, or null when the key does not exist. */
|
|
16
17
|
get(binding: string, key: string): Promise<Uint8Array | null>;
|
|
17
|
-
/**
|
|
18
|
+
/** The key's value with its version, or null when the key does not exist. */
|
|
18
19
|
getEntry(binding: string, key: string): Promise<KVEntry | null>;
|
|
19
|
-
/**
|
|
20
|
-
* TextDecoder dance; put() already accepts a string. */
|
|
20
|
+
/** The key's value decoded as UTF-8 text, or null when the key does not exist. */
|
|
21
21
|
getText(binding: string, key: string): Promise<string | null>;
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
22
|
+
/** The key's value parsed as JSON, or null when the key does not exist. Write it with
|
|
23
|
+
* put(binding, key, JSON.stringify(value)). */
|
|
24
24
|
getJSON<T = unknown>(binding: string, key: string): Promise<T | null>;
|
|
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. */
|
|
25
27
|
put(binding: string, key: string, value: Uint8Array | string, opts?: PutOptions): Promise<void>;
|
|
26
|
-
/**
|
|
28
|
+
/** Creates the key: its new version, or null when it exists (an expired key does not). */
|
|
27
29
|
putIfAbsent(binding: string, key: string, value: Uint8Array | string, opts?: PutOptions): Promise<string | null>;
|
|
28
|
-
/**
|
|
30
|
+
/** Replaces the key while it is at version: its new version, or null when it is not. */
|
|
29
31
|
compareAndSet(binding: string, key: string, value: Uint8Array | string, version: string, opts?: PutOptions): Promise<string | null>;
|
|
32
|
+
/** Deletes the key. */
|
|
30
33
|
del(binding: string, key: string): Promise<void>;
|
|
31
|
-
/**
|
|
34
|
+
/** Deletes the key while it is at version, as a lease holder releases what it holds: true when it did. */
|
|
32
35
|
delIf(binding: string, key: string, version: string): Promise<boolean>;
|
|
36
|
+
/** The keys that start with prefix; without a prefix, every key of the table. */
|
|
33
37
|
list(binding: string, prefix?: string): Promise<string[]>;
|
|
34
38
|
}
|
|
35
39
|
/** Build the context.kv client. In a pool, `member` names the calling function on every request
|
package/dist/secret.d.ts
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
export interface SecretClient {
|
|
3
3
|
get(key: string): Promise<string | undefined>;
|
|
4
4
|
list(): Promise<string[]>;
|
|
5
|
+
/** 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. */
|
|
7
|
+
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. */
|
|
9
|
+
del(binding: string, key: string): Promise<void>;
|
|
5
10
|
}
|
|
6
11
|
/** Build the context.secret client. In a pool, `member` names the calling function on every request (funcd checks it
|
|
7
12
|
* 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/types.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export interface FunctionContext {
|
|
|
41
41
|
* its status and headers; funcd answers an error status, and calls nothing, for an undeclared link or a target
|
|
42
42
|
* that does not serve HTTP (call it with invoke). */
|
|
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
46
|
/** Binding-scoped blob storage (ADR-0127): get/put/del/list a bound prefix's objects, or mint a
|
|
47
47
|
* presigned URL — the blob twin of kv. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@funcd-dev/shim",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.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",
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
"scripts": {
|
|
33
33
|
"typecheck": "tsc --noEmit",
|
|
34
34
|
"test": "node --test --experimental-strip-types test/*.test.ts",
|
|
35
|
-
"build": "yarn build:shim && yarn build:pool && yarn build:lib",
|
|
35
|
+
"build": "yarn build:shim && yarn build:pool && yarn build:lib && yarn build:api",
|
|
36
|
+
"build:api": "node --experimental-strip-types scripts/api.ts",
|
|
36
37
|
"build:shim": "esbuild src/shim.ts --bundle --platform=node --format=esm --target=node22 --outfile=shim.mjs --banner:js=\"// GENERATED from shim/src/shim.ts by 'yarn build' (esbuild). Do not edit by hand.\"",
|
|
37
38
|
"build:pool": "esbuild src/pool.ts --bundle --platform=node --format=esm --target=node22 --outfile=pool.mjs --banner:js=\"// GENERATED from shim/src/pool.ts by 'yarn build' (esbuild). Do not edit by hand.\"",
|
|
38
39
|
"build:lib": "tsc -p tsconfig.lib.json"
|