@pc-nexus/async 0.8.0-next.2
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/index.d.ts +3 -0
- package/index.d.ts.map +1 -0
- package/index.js +1 -0
- package/lib/consumer.d.ts +29 -0
- package/lib/consumer.d.ts.map +1 -0
- package/lib/consumer.js +1 -0
- package/lib/queue.d.ts +16 -0
- package/lib/queue.d.ts.map +1 -0
- package/lib/queue.js +19 -0
- package/package.json +35 -0
package/index.d.ts
ADDED
package/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC7D,YAAY,EAAE,eAAe,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC"}
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { queue } from "./lib/queue.js";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { NexusAppContext } from "@pc-nexus/internal";
|
|
2
|
+
/** 处理该任务的消费者信息 */
|
|
3
|
+
export interface QueueConsumer {
|
|
4
|
+
/** 消费者 key(manifest `async.consumers[].key`) */
|
|
5
|
+
key: string;
|
|
6
|
+
/** 该消费者的并发度:manifest 声明值,未声明时为平台默认值 */
|
|
7
|
+
concurrency: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 队列消费者收到的任务。
|
|
11
|
+
*
|
|
12
|
+
* 投递语义是 at-least-once,handler 必须幂等——去重要用 `task_id`(单条任务)而不是 `job_id`(一次 push 内共享)。
|
|
13
|
+
*/
|
|
14
|
+
export interface QueueTask<T = unknown> {
|
|
15
|
+
/** 推送时传入的载荷,原样带回 */
|
|
16
|
+
payload: T;
|
|
17
|
+
/** 单条任务的标识,幂等去重以它为准 */
|
|
18
|
+
task_id: string;
|
|
19
|
+
/** 一次 push 调用的标识,批量推送的多条任务共享 */
|
|
20
|
+
job_id: string;
|
|
21
|
+
/** 处理该任务的消费者信息。同一队列有多个消费者时,用它区分当前是哪一个 */
|
|
22
|
+
consumer: QueueConsumer;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 队列消费者处理函数。第二个参数直接是任务本身——消费者不是事件,
|
|
26
|
+
* 不套 `event.payload` 那层包装。
|
|
27
|
+
*/
|
|
28
|
+
export type ConsumerHandler<T = unknown> = (context: NexusAppContext, task: QueueTask<T>) => Promise<void>;
|
|
29
|
+
//# sourceMappingURL=consumer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consumer.d.ts","sourceRoot":"","sources":["../../src/lib/consumer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D,kBAAkB;AAClB,MAAM,WAAW,aAAa;IAC1B,gDAAgD;IAChD,GAAG,EAAE,MAAM,CAAC;IACZ,uCAAuC;IACvC,WAAW,EAAE,MAAM,CAAC;CACvB;AAED;;;;GAIG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,GAAG,OAAO;IAClC,oBAAoB;IACpB,OAAO,EAAE,CAAC,CAAC;IACX,uBAAuB;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,gCAAgC;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,yCAAyC;IACzC,QAAQ,EAAE,aAAa,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
package/lib/consumer.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/queue.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface QueuePushResult {
|
|
2
|
+
/** 服务端生成,一次 push 一个;批量推送时所有任务共享 */
|
|
3
|
+
jobId: string;
|
|
4
|
+
}
|
|
5
|
+
declare class Queue {
|
|
6
|
+
/**
|
|
7
|
+
* 把一条或多条任务推入队列。调用只保证入队,不等待消费者执行。
|
|
8
|
+
*
|
|
9
|
+
* @param key 队列名,必须等于 manifest 中某个 `async.queues` 条目的 `key`
|
|
10
|
+
* @param payload 单条载荷或载荷数组
|
|
11
|
+
*/
|
|
12
|
+
push<T = unknown>(key: string, payload: T | T[]): Promise<QueuePushResult>;
|
|
13
|
+
}
|
|
14
|
+
export declare const queue: Queue;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../src/lib/queue.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,eAAe;IAC5B,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAC;CACjB;AACD,cAAM,KAAK;IACP;;;;;OAKG;IACU,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,OAAO,CAAC,eAAe,CAAC;CAS1F;AAED,eAAO,MAAM,KAAK,OAAc,CAAC"}
|
package/lib/queue.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { invoke } from "@pc-nexus/internal";
|
|
2
|
+
class Queue {
|
|
3
|
+
/**
|
|
4
|
+
* 把一条或多条任务推入队列。调用只保证入队,不等待消费者执行。
|
|
5
|
+
*
|
|
6
|
+
* @param key 队列名,必须等于 manifest 中某个 `async.queues` 条目的 `key`
|
|
7
|
+
* @param payload 单条载荷或载荷数组
|
|
8
|
+
*/
|
|
9
|
+
async push(key, payload) {
|
|
10
|
+
const payloads = Array.isArray(payload) ? payload : [payload];
|
|
11
|
+
const response = await invoke("async", "queue/push", {
|
|
12
|
+
queue_key: key,
|
|
13
|
+
payloads,
|
|
14
|
+
});
|
|
15
|
+
const result = (await response.json());
|
|
16
|
+
return result.value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export const queue = new Queue();
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pc-nexus/async",
|
|
3
|
+
"version": "0.8.0-next.2",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc",
|
|
8
|
+
"pub:alpha": "cd dist && npm publish --access public --tag alpha",
|
|
9
|
+
"pub": "cd dist && npm publish --access public --tag latest",
|
|
10
|
+
"pub-next": "cd dist && npm publish --access public --tag next"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/atinc/pc-nexus.git"
|
|
15
|
+
},
|
|
16
|
+
"author": "",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"directories": {
|
|
19
|
+
"test": "test",
|
|
20
|
+
"lib": "dist"
|
|
21
|
+
},
|
|
22
|
+
"types": "index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"default": "./index.js",
|
|
26
|
+
"types": "./index.d.ts"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"type": "module",
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@pc-nexus/internal": "0.8.0-next.2"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {},
|
|
34
|
+
"peerDependencies": {}
|
|
35
|
+
}
|