aragog-client 0.2.1 → 1.0.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/lib/amqp.d.ts CHANGED
@@ -11,11 +11,12 @@ export interface QueueParam {
11
11
  export interface Options {
12
12
  durable?: boolean;
13
13
  }
14
- export interface SendData extends QueueItem {
14
+ export interface SendData extends Omit<QueueItem, 'appName'> {
15
15
  id: string;
16
16
  priority?: number;
17
17
  }
18
- export interface ResultData extends QueueResult {
18
+ export interface ResultData<T = any> extends QueueResult {
19
+ data: T;
19
20
  id: string;
20
21
  }
21
22
  declare class Amqp extends EventEmitter {
package/lib/amqp.js CHANGED
@@ -38,7 +38,7 @@ class Amqp extends events_1.EventEmitter {
38
38
  else {
39
39
  callbackQueue = await this.channel.assertQueue('', { exclusive: true });
40
40
  }
41
- await this.channel.bindQueue(dataQueue.queue, this.param.exchange, `#.${this.param.queue}`);
41
+ await this.channel.bindQueue(dataQueue.queue, this.param.exchange, `${this.param.app}.${this.param.queue}`);
42
42
  this.callbackQueueName = callbackQueue.queue;
43
43
  this.initialized = true;
44
44
  }
@@ -49,8 +49,10 @@ class Amqp extends events_1.EventEmitter {
49
49
  if (priority < 0 || priority > 10) {
50
50
  throw new Error('priority between 0-10');
51
51
  }
52
- const { exchange, app, queue } = this.param;
53
- await this.channel.publish(exchange, `${app}.${queue}`, Buffer.from(JSON.stringify(data)), {
52
+ await this.channel.publish(this.param.exchange, `${this.param.app}.${this.param.queue}`, Buffer.from(JSON.stringify({
53
+ ...data,
54
+ appName: this.param.app,
55
+ })), {
54
56
  priority,
55
57
  persistent: true,
56
58
  correlationId: id,
package/lib/index.d.ts CHANGED
@@ -10,8 +10,8 @@ interface Options {
10
10
  durable?: boolean;
11
11
  exchangeName?: string;
12
12
  }
13
- interface TaskCompletedCallback {
14
- (error: Error | undefined, data: ResultData): void | Promise<void>;
13
+ interface TaskCompletedCallback<T> {
14
+ (error: Error | undefined, data: ResultData<T>): void | Promise<void>;
15
15
  }
16
16
  declare class Aragog {
17
17
  readonly connection: Connection;
@@ -22,7 +22,7 @@ declare class Aragog {
22
22
  isClosed: boolean;
23
23
  constructor(connection: Connection, managementApi: ReturnType<typeof createManagementApi>, headlessClient: Amqp, sourceClient: Amqp, options: Options);
24
24
  addTask(type: TaskType, data: SendData): Promise<void>;
25
- onTaskCompleted(callback: TaskCompletedCallback): void;
25
+ onTaskCompleted<T>(callback: TaskCompletedCallback<T>): void;
26
26
  getServerInfo(): Promise<ConsumerInfo[]>;
27
27
  getQueueInfo(type: TaskType): Promise<QueueInfo>;
28
28
  close(): Promise<void>;
@@ -30,4 +30,5 @@ declare class Aragog {
30
30
  declare const connect: (connParam: AmqpConn & {
31
31
  appName: string;
32
32
  }, userOpts?: Options) => Promise<Aragog>;
33
+ export declare type AragogClient = InstanceType<typeof Aragog>;
33
34
  export { connect, SendData as Task, ResultData as TaskResult, QueueInfo, ConsumerInfo };
package/lib/index.js CHANGED
@@ -31,7 +31,7 @@ class Aragog {
31
31
  if (this.isClosed) {
32
32
  connectionClosedError();
33
33
  }
34
- utils_1.checkTaskInput(data);
34
+ (0, utils_1.checkTaskInput)(data);
35
35
  if (type === TaskType.Headless) {
36
36
  await this.headlessClient.sendToQueue(data);
37
37
  }
@@ -66,7 +66,7 @@ class Aragog {
66
66
  }
67
67
  }
68
68
  const connect = async (connParam, userOpts = {}) => {
69
- utils_1.checkConnectParam(connParam);
69
+ (0, utils_1.checkConnectParam)(connParam);
70
70
  const options = {
71
71
  exchangeName: 'aragog_exchange',
72
72
  durable: false,
@@ -86,6 +86,6 @@ const connect = async (connParam, userOpts = {}) => {
86
86
  exchange: options.exchangeName,
87
87
  }, options);
88
88
  await sourceClient.init();
89
- return new Aragog(conn, management_1.createManagementApi(connParam, options), headlessClient, sourceClient, options);
89
+ return new Aragog(conn, (0, management_1.createManagementApi)(connParam, options), headlessClient, sourceClient, options);
90
90
  };
91
91
  exports.connect = connect;
package/lib/management.js CHANGED
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createManagementApi = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
8
  /* eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types */
9
- exports.createManagementApi = (conn, { ssl = false }) => {
9
+ const createManagementApi = (conn, { ssl = false }) => {
10
10
  const request = axios_1.default.create({
11
11
  baseURL: `${ssl ? 'https' : 'http'}://${conn.hostname}:${conn.port || 15672}/api/`,
12
12
  auth: {
@@ -20,3 +20,4 @@ exports.createManagementApi = (conn, { ssl = false }) => {
20
20
  getConsumers: () => request.get(`/consumers/${vhost}`).then(({ data }) => data),
21
21
  };
22
22
  };
23
+ exports.createManagementApi = createManagementApi;
package/lib/types.d.ts CHANGED
@@ -10,6 +10,7 @@ export interface Cookie {
10
10
  }
11
11
 
12
12
  export interface QueueItem {
13
+ appName: string
13
14
  url: string
14
15
  script: string
15
16
  disableImage?: boolean
package/lib/utils.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { AmqpConn, QueueItem } from './types';
2
- export declare const checkTaskInput: (data: QueueItem & {
1
+ import { AmqpConn } from './types';
2
+ import { SendData } from './amqp';
3
+ export declare const checkTaskInput: (data: SendData & {
3
4
  id: string;
4
5
  }) => void;
5
6
  export declare const checkConnectParam: (connParam: AmqpConn & {
package/lib/utils.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkConnectParam = exports.checkTaskInput = void 0;
4
- exports.checkTaskInput = (data) => {
4
+ const checkTaskInput = (data) => {
5
5
  const allKeys = [
6
6
  'id',
7
7
  'url',
@@ -85,7 +85,8 @@ exports.checkTaskInput = (data) => {
85
85
  }
86
86
  });
87
87
  };
88
- exports.checkConnectParam = (connParam) => {
88
+ exports.checkTaskInput = checkTaskInput;
89
+ const checkConnectParam = (connParam) => {
89
90
  const allKeys = ['hostname', 'username', 'password', 'appName'];
90
91
  allKeys.forEach((key) => {
91
92
  if (!connParam[key]) {
@@ -96,3 +97,4 @@ exports.checkConnectParam = (connParam) => {
96
97
  }
97
98
  });
98
99
  };
100
+ exports.checkConnectParam = checkConnectParam;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aragog-client",
3
- "version": "0.2.1",
3
+ "version": "1.0.2",
4
4
  "description": "Aragog web scraping framework client",
5
5
  "keywords": [
6
6
  "scraping",
@@ -28,10 +28,8 @@
28
28
  "prepublishOnly": "ls lib"
29
29
  },
30
30
  "dependencies": {
31
- "amqplib": "^0.5.6",
32
- "axios": "^0.19.2"
33
- },
34
- "devDependencies": {
35
- "@types/amqplib": "^0.5.13"
31
+ "@types/amqplib": "^0.8.2",
32
+ "amqplib": "^0.8.0",
33
+ "axios": "^0.24.0"
36
34
  }
37
35
  }
package/CHANGELOG.md DELETED
@@ -1,14 +0,0 @@
1
- # 更新日志
2
-
3
- ## 0.2.1 (2020-06-19)
4
-
5
- - 修复 typescript 类型定义丢失
6
-
7
- ## v0.2.0 (2020-06-18)
8
-
9
- - 修复库文件缺失
10
- - 新增 package.json homepage 字段
11
-
12
- ## v0.1.1 (2020-06-17)
13
-
14
- - 创建项目