cnpmcore 1.9.1 → 1.10.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/History.md CHANGED
@@ -1,4 +1,10 @@
1
1
 
2
+ 1.10.0 / 2022-08-04
3
+ ==================
4
+
5
+ **features**
6
+ * [[`c2b7d5a`](http://github.com/cnpm/cnpmcore/commit/c2b7d5aa98b5ba8649ec246c616574a22e9a74b8)] - feat: use sort set to impl queue (#277) (killa <<killa123@126.com>>)
7
+
2
8
  1.9.1 / 2022-07-29
3
9
  ==================
4
10
 
@@ -26,3 +26,8 @@ export interface NFSClient {
26
26
  createDownloadStream(key: string): Promise<Readable | undefined>;
27
27
  url?(key: string): string;
28
28
  }
29
+ export interface QueueAdapter {
30
+ push<T>(key: string, item: T): Promise<boolean>;
31
+ pop<T>(key: string): Promise<T | null>;
32
+ length(key: string): Promise<number>;
33
+ }
@@ -0,0 +1,16 @@
1
+ import { QueueAdapter } from '../common/typing';
2
+ /**
3
+ * Use sort set to keep queue in order and keep same value only insert once
4
+ */
5
+ export declare class RedisQueueAdapter implements QueueAdapter {
6
+ private readonly redis;
7
+ private getQueueName;
8
+ private getQueueScoreName;
9
+ /**
10
+ * If queue has the same item, return false
11
+ * If queue not has the same item, return true
12
+ */
13
+ push<T>(key: string, item: T): Promise<boolean>;
14
+ pop<T>(key: string): Promise<T | null>;
15
+ length(key: string): Promise<number>;
16
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.RedisQueueAdapter = void 0;
10
+ const tegg_1 = require("@eggjs/tegg");
11
+ /**
12
+ * Use sort set to keep queue in order and keep same value only insert once
13
+ */
14
+ let RedisQueueAdapter = class RedisQueueAdapter {
15
+ getQueueName(key) {
16
+ return `CNPMCORE_Q_V2_${key}`;
17
+ }
18
+ getQueueScoreName(key) {
19
+ return `CNPMCORE_Q_S_V2_${key}`;
20
+ }
21
+ /**
22
+ * If queue has the same item, return false
23
+ * If queue not has the same item, return true
24
+ */
25
+ async push(key, item) {
26
+ const score = await this.redis.incr(this.getQueueScoreName(key));
27
+ const res = await this.redis.zadd(this.getQueueName(key), score, JSON.stringify(item));
28
+ return res !== 0;
29
+ }
30
+ async pop(key) {
31
+ const [json] = await this.redis.zpopmin(this.getQueueName(key));
32
+ if (!json)
33
+ return null;
34
+ return JSON.parse(json);
35
+ }
36
+ async length(key) {
37
+ return await this.redis.zcount(this.getQueueName(key), '-inf', '+inf');
38
+ }
39
+ };
40
+ __decorate([
41
+ (0, tegg_1.Inject)()
42
+ ], RedisQueueAdapter.prototype, "redis", void 0);
43
+ RedisQueueAdapter = __decorate([
44
+ (0, tegg_1.ContextProto)({
45
+ accessLevel: tegg_1.AccessLevel.PUBLIC,
46
+ name: 'queueAdapter',
47
+ })
48
+ ], RedisQueueAdapter);
49
+ exports.RedisQueueAdapter = RedisQueueAdapter;
50
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUXVldWVBZGFwdGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vYXBwL2luZnJhL1F1ZXVlQWRhcHRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7QUFBQSxzQ0FJcUI7QUFJckI7O0dBRUc7QUFLSCxJQUFhLGlCQUFpQixHQUE5QixNQUFhLGlCQUFpQjt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BQUMsWUFBWSxDQUFDLEdBQUcsQ0FBQyxFQUFFLE1BQU0sRUFBRSxNQUFNLENBQUMsQ0FBQztJQUN6RSxDQUFDO0NBQ0YsQ0FBQTtBQTdCQztJQURDLElBQUEsYUFBTSxHQUFFO2dEQUNxQjtBQUZuQixpQkFBaUI7SUFKN0IsSUFBQSxtQkFBWSxFQUFDO1FBQ1osV0FBVyxFQUFFLGtCQUFXLENBQUMsTUFBTTtRQUMvQixJQUFJLEVBQUUsY0FBYztLQUNyQixDQUFDO0dBQ1csaUJBQWlCLENBK0I3QjtBQS9CWSw4Q0FBaUIifQ==
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cnpmcore",
3
- "version": "1.9.1",
3
+ "version": "1.10.0",
4
4
  "description": "npm core",
5
5
  "files": [
6
6
  "dist/**/*"
@@ -1,7 +0,0 @@
1
- export declare class QueueAdapter {
2
- private readonly redis;
3
- private getQueueName;
4
- push<T>(key: string, item: T): Promise<number>;
5
- pop<T>(key: string): Promise<T | null>;
6
- length(key: string): Promise<number>;
7
- }
@@ -1,37 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.QueueAdapter = void 0;
10
- const tegg_1 = require("@eggjs/tegg");
11
- let QueueAdapter = class QueueAdapter {
12
- getQueueName(key) {
13
- return `CNPMCORE_Q_${key}`;
14
- }
15
- async push(key, item) {
16
- return await this.redis.lpush(this.getQueueName(key), JSON.stringify(item));
17
- }
18
- async pop(key) {
19
- const json = await this.redis.rpop(this.getQueueName(key));
20
- if (!json)
21
- return null;
22
- return JSON.parse(json);
23
- }
24
- async length(key) {
25
- return await this.redis.llen(this.getQueueName(key));
26
- }
27
- };
28
- __decorate([
29
- (0, tegg_1.Inject)()
30
- ], QueueAdapter.prototype, "redis", void 0);
31
- QueueAdapter = __decorate([
32
- (0, tegg_1.ContextProto)({
33
- accessLevel: tegg_1.AccessLevel.PUBLIC,
34
- })
35
- ], QueueAdapter);
36
- exports.QueueAdapter = QueueAdapter;
37
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUXVldWVBZGFwdGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vYXBwL2NvbW1vbi9hZGFwdGVyL1F1ZXVlQWRhcHRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7QUFBQSxzQ0FJcUI7QUFNckIsSUFBYSxZQUFZLEdBQXpCLE1BQWEsWUFBWTtJQUlmLFlBQVksQ0FBQyxHQUFXO1FBQzlCLE9BQU8sY0FBYyxHQUFHLEVBQUUsQ0FBQztJQUM3QixDQUFDO0lBRUQsS0FBSyxDQUFDLElBQUksQ0FBSSxHQUFXLEVBQUUsSUFBTztRQUNoQyxPQUFPLE1BQU0sSUFBSSxDQUFDLEtBQUssQ0FBQyxLQUFLLENBQUMsSUFBSSxDQUFDLFlBQVksQ0FBQyxHQUFHLENBQUMsRUFBRSxJQUFJLENBQUMsU0FBUyxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUM7SUFDOUUsQ0FBQztJQUVELEtBQUssQ0FBQyxHQUFHLENBQUksR0FBVztRQUN0QixNQUFNLElBQUksR0FBRyxNQUFNLElBQUksQ0FBQyxLQUFLLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxZQUFZLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQztRQUMz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