@webpieces/cloudtasks-client 0.3.334 → 0.3.335
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
CHANGED
|
@@ -11,15 +11,15 @@ where it runs through the full server filter chain.
|
|
|
11
11
|
abstract class EmailApi { @Endpoint('/send') sendEmail(r: SendEmailRequest): Promise<void> {…} }
|
|
12
12
|
|
|
13
13
|
// build the client once (sync); 'email-svc' is the callee's Cloud Run service name
|
|
14
|
-
const emailTasks = factory.
|
|
14
|
+
const emailTasks = factory.createPubSubClient(EmailApi, new TaskClientConfig('email-svc'));
|
|
15
15
|
// ...or pin a URL lookup cannot describe (other region/project); svcName stays the log name
|
|
16
|
-
const other = factory.
|
|
16
|
+
const other = factory.createPubSubClient(EmailApi, new TaskClientConfig('email-svc', 'https://email.eu.example'));
|
|
17
17
|
|
|
18
18
|
// producer (inside a request → RequestContext active)
|
|
19
19
|
await scheduler.addToQueue(() => emailTasks.sendEmail(req), { dedupName: req.id });
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
- `ClientCloudTasksFactory.
|
|
22
|
+
- `ClientCloudTasksFactory.createPubSubClient(Api, TaskClientConfig)` — builds the enqueue proxy. It
|
|
23
23
|
injects a `Provider<TaskProxyClient>` and calls `get()` per contract; `TaskProxyClient` is bound
|
|
24
24
|
TRANSIENT, so each client gets its own. The delivery URL is resolved at enqueue time from
|
|
25
25
|
`svcName` (same project + region as this container, so you maintain no URL table) unless you pass
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/cloudtasks-client",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.335",
|
|
4
4
|
"description": "Cloud Tasks enqueue client generated from a shared @PubSub API contract (twin of http-client)",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@webpieces/core-context": "0.3.
|
|
27
|
-
"@webpieces/core-util": "0.3.
|
|
28
|
-
"@webpieces/gcp-identity": "0.3.
|
|
26
|
+
"@webpieces/core-context": "0.3.335",
|
|
27
|
+
"@webpieces/core-util": "0.3.335",
|
|
28
|
+
"@webpieces/gcp-identity": "0.3.335",
|
|
29
29
|
"@google-cloud/tasks": "5.5.2",
|
|
30
30
|
"inversify": "7.10.4",
|
|
31
31
|
"reflect-metadata": "0.2.2"
|
|
@@ -10,12 +10,12 @@ import { ApiPrototype, TaskClientConfig } from './TaskClientConfig';
|
|
|
10
10
|
*
|
|
11
11
|
* ```typescript
|
|
12
12
|
* // same project + region as this container; the URL is derived, you maintain nothing
|
|
13
|
-
* const emailTasks = factory.
|
|
13
|
+
* const emailTasks = factory.createPubSubClient(EmailApi, new TaskClientConfig('email-svc'));
|
|
14
14
|
* await scheduler.addToQueue(() => emailTasks.sendEmail(req), { dedupName });
|
|
15
15
|
* ```
|
|
16
16
|
*
|
|
17
17
|
* Every client it builds gets its OWN {@link TaskProxyClient} from the injected
|
|
18
|
-
* `Provider<TaskProxyClient>` (bound transient), which `
|
|
18
|
+
* `Provider<TaskProxyClient>` (bound transient), which `createPubSubClient` then `init`s for one
|
|
19
19
|
* contract. Their collaborators (TaskInvoker, RequestContextHeaders) come from the container.
|
|
20
20
|
*
|
|
21
21
|
* Node-only, so the factory IS the inversify entry point. An enqueue outside
|
|
@@ -25,5 +25,5 @@ export declare class ClientCloudTasksFactory {
|
|
|
25
25
|
private readonly taskProxyClientProvider;
|
|
26
26
|
constructor(taskProxyClientProvider: Provider<TaskProxyClient>);
|
|
27
27
|
/** Typed enqueue client for a @PubSub contract, delivered to `config.svcName`. */
|
|
28
|
-
|
|
28
|
+
createPubSubClient<T extends object>(apiClass: ApiPrototype<T>, config: TaskClientConfig): T;
|
|
29
29
|
}
|
|
@@ -26,12 +26,12 @@ const FRAMEWORK_INSPECTION_PROPERTIES = new Set([
|
|
|
26
26
|
*
|
|
27
27
|
* ```typescript
|
|
28
28
|
* // same project + region as this container; the URL is derived, you maintain nothing
|
|
29
|
-
* const emailTasks = factory.
|
|
29
|
+
* const emailTasks = factory.createPubSubClient(EmailApi, new TaskClientConfig('email-svc'));
|
|
30
30
|
* await scheduler.addToQueue(() => emailTasks.sendEmail(req), { dedupName });
|
|
31
31
|
* ```
|
|
32
32
|
*
|
|
33
33
|
* Every client it builds gets its OWN {@link TaskProxyClient} from the injected
|
|
34
|
-
* `Provider<TaskProxyClient>` (bound transient), which `
|
|
34
|
+
* `Provider<TaskProxyClient>` (bound transient), which `createPubSubClient` then `init`s for one
|
|
35
35
|
* contract. Their collaborators (TaskInvoker, RequestContextHeaders) come from the container.
|
|
36
36
|
*
|
|
37
37
|
* Node-only, so the factory IS the inversify entry point. An enqueue outside
|
|
@@ -43,7 +43,7 @@ let ClientCloudTasksFactory = class ClientCloudTasksFactory {
|
|
|
43
43
|
this.taskProxyClientProvider = taskProxyClientProvider;
|
|
44
44
|
}
|
|
45
45
|
/** Typed enqueue client for a @PubSub contract, delivered to `config.svcName`. */
|
|
46
|
-
|
|
46
|
+
createPubSubClient(apiClass, config) {
|
|
47
47
|
// Fresh instance per contract — TaskProxyClient is transient.
|
|
48
48
|
const proxyClient = this.taskProxyClientProvider.get();
|
|
49
49
|
proxyClient.init(apiClass, config);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientCloudTasksFactory.js","sourceRoot":"","sources":["../../../../../packages/cloud/cloudtasks-client/src/ClientCloudTasksFactory.ts"],"names":[],"mappings":";;;;AAAA,yCAA+C;AAC/C,oDAAsD;AACtD,0DAAqG;AACrG,uDAAgF;AAGhF,iGAAiG;AACjG,6EAA6E;AAC7E,IAAA,oCAAqB,EAAC,4CAA0B,EAAE,iCAAe,CAAC,CAAC;AAEnE;;;GAGG;AACH,MAAM,+BAA+B,GAAG,IAAI,GAAG,CAAS;IACpD,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS;IAC3E,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU;CACrE,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AAII,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAEyB;IADzD,YACyD,uBAAkD;QAAlD,4BAAuB,GAAvB,uBAAuB,CAA2B;IACxG,CAAC;IAEJ,kFAAkF;IAClF,
|
|
1
|
+
{"version":3,"file":"ClientCloudTasksFactory.js","sourceRoot":"","sources":["../../../../../packages/cloud/cloudtasks-client/src/ClientCloudTasksFactory.ts"],"names":[],"mappings":";;;;AAAA,yCAA+C;AAC/C,oDAAsD;AACtD,0DAAqG;AACrG,uDAAgF;AAGhF,iGAAiG;AACjG,6EAA6E;AAC7E,IAAA,oCAAqB,EAAC,4CAA0B,EAAE,iCAAe,CAAC,CAAC;AAEnE;;;GAGG;AACH,MAAM,+BAA+B,GAAG,IAAI,GAAG,CAAS;IACpD,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS;IAC3E,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU;CACrE,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AAII,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAEyB;IADzD,YACyD,uBAAkD;QAAlD,4BAAuB,GAAvB,uBAAuB,CAA2B;IACxG,CAAC;IAEJ,kFAAkF;IAClF,kBAAkB,CAAmB,QAAyB,EAAE,MAAwB;QACpF,8DAA8D;QAC9D,MAAM,WAAW,GAAG,IAAI,CAAC,uBAAuB,CAAC,GAAG,EAAE,CAAC;QACvD,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAEnC,OAAO,IAAI,KAAK,CAAC,EAAO,EAAE;YACtB,oGAAoG;YACpG,GAAG,CAAC,MAAS,EAAE,IAAqB;gBAChC,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,+BAA+B,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;oBACxE,OAAO,SAAS,CAAC;gBACrB,CAAC;gBACD,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;oBACjC,MAAM,IAAI,KAAK,CACX,wBAAwB,IAAI,QAAQ,QAAQ,CAAC,IAAI,IAAI,SAAS,IAAI;wBAClE,qDAAqD,CACxD,CAAC;gBACN,CAAC;gBACD,oFAAoF;gBACpF,OAAO,CAAC,UAAmB,EAAiB,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;YACzF,CAAC;SACJ,CAAC,CAAC;IACP,CAAC;CACJ,CAAA;AA5BY,0DAAuB;kCAAvB,uBAAuB;IAHnC,IAAA,0BAAc,GAAE;IAChB,IAAA,wCAAyB,GAAE;IAC3B,IAAA,sBAAU,GAAE;IAGJ,mBAAA,IAAA,kBAAM,EAAC,4CAA0B,CAAC,CAAA;6CAA2C,uBAAQ;GAFjF,uBAAuB,CA4BnC","sourcesContent":["import { inject, injectable } from 'inversify';\nimport { DocumentDesign } from '@webpieces/core-util';\nimport { Provider, bindFrameworkProvider, provideFrameworkSingleton } from '@webpieces/core-context';\nimport { TASK_PROXY_CLIENT_PROVIDER, TaskProxyClient } from './TaskProxyClient';\nimport { ApiPrototype, TaskClientConfig } from './TaskClientConfig';\n\n// Teach the container how to hand out fresh TaskProxyClients. TaskProxyClient is bound TRANSIENT\n// (@provideFrameworkTransient), so each provider.get() constructs a new one.\nbindFrameworkProvider(TASK_PROXY_CLIENT_PROVIDER, TaskProxyClient);\n\n/**\n * Properties DI frameworks / Promise checks / serializers probe on the proxy; return\n * undefined instead of treating them as endpoints. Mirrors http-client-core's buildClientProxy.\n */\nconst FRAMEWORK_INSPECTION_PROPERTIES = new Set<string>([\n 'constructor', 'prototype', '__proto__', 'name', 'then', 'catch', 'finally',\n 'toJSON', 'valueOf', 'toString', 'nodeType', 'tagName', '$$typeof',\n]);\n\n/**\n * ClientCloudTasksFactory - builds Cloud Tasks enqueue clients from a shared @PubSub API\n * contract. The fire-and-forget twin of http-client-node's ClientHttpFactory.\n *\n * Calling a method on the returned client ENQUEUES a task (it does not call remotely); the task\n * is later delivered to the same endpoint's controller through the full server filter chain.\n *\n * ```typescript\n * // same project + region as this container; the URL is derived, you maintain nothing\n * const emailTasks = factory.createPubSubClient(EmailApi, new TaskClientConfig('email-svc'));\n * await scheduler.addToQueue(() => emailTasks.sendEmail(req), { dedupName });\n * ```\n *\n * Every client it builds gets its OWN {@link TaskProxyClient} from the injected\n * `Provider<TaskProxyClient>` (bound transient), which `createPubSubClient` then `init`s for one\n * contract. Their collaborators (TaskInvoker, RequestContextHeaders) come from the container.\n *\n * Node-only, so the factory IS the inversify entry point. An enqueue outside\n * `RequestContext.run(...)` throws rather than silently dropping the caller's trace.\n */\n@DocumentDesign()\n@provideFrameworkSingleton()\n@injectable()\nexport class ClientCloudTasksFactory {\n constructor(\n @inject(TASK_PROXY_CLIENT_PROVIDER) private readonly taskProxyClientProvider: Provider<TaskProxyClient>,\n ) {}\n\n /** Typed enqueue client for a @PubSub contract, delivered to `config.svcName`. */\n createPubSubClient<T extends object>(apiClass: ApiPrototype<T>, config: TaskClientConfig): T {\n // Fresh instance per contract — TaskProxyClient is transient.\n const proxyClient = this.taskProxyClientProvider.get();\n proxyClient.init(apiClass, config);\n\n return new Proxy({} as T, {\n // webpieces-disable no-any-unknown -- proxy get trap returns either an endpoint method or undefined\n get(target: T, prop: string | symbol): unknown {\n if (typeof prop !== 'string' || FRAMEWORK_INSPECTION_PROPERTIES.has(prop)) {\n return undefined;\n }\n if (!proxyClient.hasEndpoint(prop)) {\n throw new Error(\n `No @PubSub endpoint '${prop}' on ${apiClass.name || 'Unknown'}. ` +\n `Check for typos or a missing @Endpoint() decorator.`,\n );\n }\n // webpieces-disable no-any-unknown -- request DTO type is erased at the proxy layer\n return (requestDto: unknown): Promise<void> => proxyClient.enqueue(prop, requestDto);\n },\n });\n }\n}\n"]}
|