@midwayjs/tablestore 4.0.0-beta.11 → 4.0.0-beta.12

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/dist/manager.d.ts CHANGED
@@ -1,9 +1,14 @@
1
- import { ServiceFactory } from '@midwayjs/core';
1
+ import { ServiceFactory, MidwayTraceService } from '@midwayjs/core';
2
2
  import { TableStoreClient } from './interface';
3
3
  export declare class TableStoreServiceFactory extends ServiceFactory<TableStoreClient> {
4
4
  tableStoreConfig: any;
5
+ protected traceService: MidwayTraceService;
6
+ protected traceMetaResolver: any;
7
+ protected traceEnabled: any;
8
+ protected traceInjector: any;
5
9
  init(): Promise<void>;
6
10
  createClient(config: any): Promise<TableStoreClient>;
11
+ protected bindTraceContext(client: any): void;
7
12
  getName(): string;
8
13
  }
9
14
  export declare class TableStoreService implements TableStoreClient {
package/dist/manager.js CHANGED
@@ -14,13 +14,61 @@ const core_1 = require("@midwayjs/core");
14
14
  const TableStore = require("tablestore");
15
15
  let TableStoreServiceFactory = class TableStoreServiceFactory extends core_1.ServiceFactory {
16
16
  tableStoreConfig;
17
+ traceService;
18
+ traceMetaResolver;
19
+ traceEnabled;
20
+ traceInjector;
17
21
  async init() {
18
22
  await this.initClients(this.tableStoreConfig, {
19
23
  concurrent: true,
20
24
  });
21
25
  }
22
26
  async createClient(config) {
23
- return new TableStore.Client(config);
27
+ const client = new TableStore.Client(config);
28
+ this.bindTraceContext(client);
29
+ return client;
30
+ }
31
+ bindTraceContext(client) {
32
+ if (!client || !this.traceService) {
33
+ return;
34
+ }
35
+ const rawMakeRequest = client.makeRequest?.bind(client);
36
+ if (!rawMakeRequest) {
37
+ return;
38
+ }
39
+ client.makeRequest = (...args) => {
40
+ if (typeof args[1] === 'function' || typeof args[2] === 'function') {
41
+ return rawMakeRequest(...args);
42
+ }
43
+ const operation = args?.[0] || 'request';
44
+ const rawCarrier = typeof this.traceInjector === 'function'
45
+ ? this.traceInjector({
46
+ request: args,
47
+ custom: {
48
+ operation: String(operation),
49
+ },
50
+ })
51
+ : {};
52
+ const carrier = rawCarrier && typeof rawCarrier === 'object' ? rawCarrier : {};
53
+ return this.traceService.runWithExitSpan(`tablestore.${String(operation).toLowerCase()}`, {
54
+ enable: this.traceEnabled !== false,
55
+ carrier,
56
+ attributes: {
57
+ 'midway.protocol': 'tablestore',
58
+ 'midway.tablestore.operation': String(operation),
59
+ },
60
+ meta: this.traceMetaResolver,
61
+ metaArgs: {
62
+ carrier,
63
+ request: args,
64
+ custom: {
65
+ operation: String(operation),
66
+ },
67
+ },
68
+ }, async () => {
69
+ return rawMakeRequest(...args);
70
+ });
71
+ };
24
72
  }
25
73
  getName() {
26
74
  return 'tableStore';
@@ -31,6 +79,22 @@ __decorate([
31
79
  (0, core_1.Config)('tableStore'),
32
80
  __metadata("design:type", Object)
33
81
  ], TableStoreServiceFactory.prototype, "tableStoreConfig", void 0);
82
+ __decorate([
83
+ (0, core_1.Inject)(),
84
+ __metadata("design:type", core_1.MidwayTraceService)
85
+ ], TableStoreServiceFactory.prototype, "traceService", void 0);
86
+ __decorate([
87
+ (0, core_1.Config)('tableStore.tracing.meta'),
88
+ __metadata("design:type", Object)
89
+ ], TableStoreServiceFactory.prototype, "traceMetaResolver", void 0);
90
+ __decorate([
91
+ (0, core_1.Config)('tableStore.tracing.enable'),
92
+ __metadata("design:type", Object)
93
+ ], TableStoreServiceFactory.prototype, "traceEnabled", void 0);
94
+ __decorate([
95
+ (0, core_1.Config)('tableStore.tracing.injector'),
96
+ __metadata("design:type", Object)
97
+ ], TableStoreServiceFactory.prototype, "traceInjector", void 0);
34
98
  __decorate([
35
99
  (0, core_1.Init)(),
36
100
  __metadata("design:type", Function),
package/dist/util.js CHANGED
@@ -10,18 +10,20 @@ const formatToString = value => {
10
10
  const formatRow = (row, filterColumn) => {
11
11
  filterColumn = filterColumn || {};
12
12
  const rowData = {};
13
- row.primaryKey &&
13
+ if (row.primaryKey) {
14
14
  row.primaryKey.map(pk => {
15
15
  if (filterColumn[pk.name])
16
16
  return;
17
17
  rowData[pk.name] = formatToString(pk.value);
18
18
  });
19
- row.attributes &&
19
+ }
20
+ if (row.attributes) {
20
21
  row.attributes.map(item => {
21
22
  if (filterColumn[item.columnName])
22
23
  return;
23
24
  rowData[item.columnName] = formatToString(item.columnValue);
24
25
  });
26
+ }
25
27
  return rowData;
26
28
  };
27
29
  exports.formatRow = formatRow;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@midwayjs/tablestore",
3
3
  "description": "midway tablestore component",
4
- "version": "4.0.0-beta.11",
4
+ "version": "4.0.0-beta.12",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
7
7
  "files": [
@@ -10,8 +10,8 @@
10
10
  "index.d.ts"
11
11
  ],
12
12
  "devDependencies": {
13
- "@midwayjs/core": "^4.0.0-beta.11",
14
- "@midwayjs/mock": "^4.0.0-beta.11"
13
+ "@midwayjs/core": "^4.0.0-beta.12",
14
+ "@midwayjs/mock": "^4.0.0-beta.12"
15
15
  },
16
16
  "dependencies": {
17
17
  "int64-buffer": "1.0.1",
@@ -37,5 +37,5 @@
37
37
  "type": "git",
38
38
  "url": "https://github.com/midwayjs/midway.git"
39
39
  },
40
- "gitHead": "6ef05719ca6e900f1ec34aff7a5c5a9614358c50"
40
+ "gitHead": "1c48179b7c827ba8ec9351e9b6c36ec1726d3e11"
41
41
  }