@cloudflare/containers 0.0.27 → 0.0.29
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/README.md +229 -102
- package/dist/lib/container.d.ts +60 -70
- package/dist/lib/container.js +155 -163
- package/dist/lib/container.js.map +1 -1
- package/dist/lib/utils.d.ts +2 -2
- package/dist/lib/utils.js +4 -4
- package/dist/lib/utils.js.map +1 -1
- package/dist/types/index.d.ts +26 -3
- package/package.json +4 -4
package/dist/lib/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Get a random container instances across N instances
|
|
2
|
+
* Get a random container instances across N instances. This is useful for load balancing.
|
|
3
3
|
* @param binding The Container's Durable Object binding
|
|
4
4
|
* @param instances Number of instances to load balance across
|
|
5
5
|
* @returns A promise resolving to a container stub ready to handle requests
|
|
@@ -23,15 +23,15 @@ export async function loadBalance(binding, instances = 3) {
|
|
|
23
23
|
console.warn('loadBalance is deprecated, please use getRandom instead. This will be removed in a future version.');
|
|
24
24
|
return getRandom(binding, instances);
|
|
25
25
|
}
|
|
26
|
+
export const singletonContainerId = 'cf-singleton-container';
|
|
26
27
|
/**
|
|
27
28
|
* Get a container stub
|
|
28
29
|
* @param binding The Container's Durable Object binding
|
|
29
30
|
* @param name The name of the instance to get, uses 'cf-singleton-container' by default
|
|
30
31
|
* @returns A container stub ready to handle requests
|
|
31
32
|
*/
|
|
32
|
-
export
|
|
33
|
-
|
|
34
|
-
const objectId = binding.idFromName(name ?? singletonContainerId);
|
|
33
|
+
export function getContainer(binding, name = singletonContainerId) {
|
|
34
|
+
const objectId = binding.idFromName(name);
|
|
35
35
|
return binding.get(objectId);
|
|
36
36
|
}
|
|
37
37
|
/**
|
package/dist/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;A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CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AACvC,CAAC;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,wBAAwB,CAAC;AAC7D;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC1B,OAAkC,EAClC,IAAI,GAAG,oBAAoB;IAE3B,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC1C,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC/B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,OAAgB,EAAE,IAAY;IACvD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7C,OAAO,CAAC,GAAG,CAAC,0BAA0B,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;IACzD,OAAO,IAAI,OAAO,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;AAC3C,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -45,11 +45,34 @@ export interface ContainerStartConfigOptions {
|
|
|
45
45
|
/** Whether to enable internet access for the container */
|
|
46
46
|
enableInternet?: boolean;
|
|
47
47
|
}
|
|
48
|
-
export interface
|
|
48
|
+
export interface StartAndWaitForPortsOptions {
|
|
49
|
+
startOptions?: ContainerStartConfigOptions;
|
|
50
|
+
ports?: number | number[];
|
|
51
|
+
cancellationOptions?: CancellationOptions;
|
|
52
|
+
}
|
|
53
|
+
/** cancellationOptions for startAndWaitForPorts() */
|
|
54
|
+
export interface CancellationOptions {
|
|
55
|
+
/** abort signal, use to abort startAndWaitForPorts manually. */
|
|
49
56
|
abort?: AbortSignal;
|
|
50
|
-
|
|
51
|
-
|
|
57
|
+
/** max time to get container instance and start it (application inside may not be ready), in milliseconds */
|
|
58
|
+
instanceGetTimeoutMS?: number;
|
|
59
|
+
/** max time to wait for application to be listening at all specified ports, in milliseconds. */
|
|
60
|
+
portReadyTimeoutMS?: number;
|
|
61
|
+
/** time to wait between polling, in milliseconds */
|
|
62
|
+
waitInterval?: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Options for waitForPort()
|
|
66
|
+
*/
|
|
67
|
+
export interface WaitOptions {
|
|
68
|
+
/** The port number to check for readiness */
|
|
52
69
|
portToCheck: number;
|
|
70
|
+
/** Optional AbortSignal, use this to abort waiting for ports */
|
|
71
|
+
signal?: AbortSignal;
|
|
72
|
+
/** Number of attempts to wait for port to be ready */
|
|
73
|
+
retries?: number;
|
|
74
|
+
/** Time to wait in between polling port for readiness, in milliseconds */
|
|
75
|
+
waitInterval?: number;
|
|
53
76
|
}
|
|
54
77
|
/**
|
|
55
78
|
* Represents a scheduled task within a Container
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/containers",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.29",
|
|
4
4
|
"description": "Helper class for container-enabled Durable Objects",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -11,8 +11,7 @@
|
|
|
11
11
|
"typecheck": "tsc --noEmit",
|
|
12
12
|
"lint": "eslint src --ext .ts,.tsx --config .eslintrc.js",
|
|
13
13
|
"format": "prettier --write \"src/**/*.ts\"",
|
|
14
|
-
"test": "
|
|
15
|
-
"test:watch": "jest --watch"
|
|
14
|
+
"test": "set -e; for fixture in examples/*/; do if [ -d \"$fixture/test\" ] && [ -f \"$fixture/package.json\" ]; then cd \"$fixture\"; npm install; npm run test; cd - > /dev/null; fi; done"
|
|
16
15
|
},
|
|
17
16
|
"exports": {
|
|
18
17
|
".": {
|
|
@@ -44,7 +43,8 @@
|
|
|
44
43
|
"prettier": "^3.5.3",
|
|
45
44
|
"ts-jest": "^29.3.2",
|
|
46
45
|
"tsup": "^8.0.2",
|
|
47
|
-
"typescript": "latest"
|
|
46
|
+
"typescript": "latest",
|
|
47
|
+
"vitest": "^1.0.0"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|