@midwayjs/etcd 3.0.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/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # midwayjs etcd module
2
+
3
+ [![Package Quality](http://npm.packagequality.com/shield/midway-core.svg)](http://packagequality.com/#?package=midway-core)
4
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/midwayjs/midway/pulls)
5
+
6
+ this is a sub package for midway.
7
+
8
+ Document: [https://midwayjs.org](https://midwayjs.org)
9
+
10
+ ## License
11
+
12
+ [MIT]((http://github.com/midwayjs/midway/blob/master/LICENSE))
@@ -0,0 +1,4 @@
1
+ export declare const etcd: {
2
+ default: {};
3
+ };
4
+ //# sourceMappingURL=config.default.d.ts.map
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.etcd = void 0;
4
+ exports.etcd = {
5
+ default: {},
6
+ };
7
+ //# sourceMappingURL=config.default.js.map
@@ -0,0 +1,4 @@
1
+ export declare class ETCDConfiguration {
2
+ onReady(container: any): Promise<void>;
3
+ }
4
+ //# sourceMappingURL=configuration.d.ts.map
@@ -0,0 +1,29 @@
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.ETCDConfiguration = void 0;
10
+ const core_1 = require("@midwayjs/core");
11
+ const manager_1 = require("./manager");
12
+ const defaultConfig = require("./config.default");
13
+ let ETCDConfiguration = class ETCDConfiguration {
14
+ async onReady(container) {
15
+ await container.getAsync(manager_1.ETCDServiceFactory);
16
+ }
17
+ };
18
+ ETCDConfiguration = __decorate([
19
+ (0, core_1.Configuration)({
20
+ namespace: 'etcd',
21
+ importConfigs: [
22
+ {
23
+ default: defaultConfig,
24
+ },
25
+ ],
26
+ })
27
+ ], ETCDConfiguration);
28
+ exports.ETCDConfiguration = ETCDConfiguration;
29
+ //# sourceMappingURL=configuration.js.map
@@ -0,0 +1,3 @@
1
+ export { ETCDConfiguration as Configuration } from './configuration';
2
+ export * from './manager';
3
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Configuration = void 0;
18
+ var configuration_1 = require("./configuration");
19
+ Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.ETCDConfiguration; } });
20
+ __exportStar(require("./manager"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,18 @@
1
+ import { ServiceFactory } from '@midwayjs/core';
2
+ import { Etcd3, IOptions } from 'etcd3';
3
+ export declare class ETCDServiceFactory extends ServiceFactory<Etcd3> {
4
+ etcdConfig: any;
5
+ init(): Promise<void>;
6
+ logger: any;
7
+ createClient(config: IOptions): Promise<Etcd3>;
8
+ getName(): string;
9
+ destroyClient(client: Etcd3): Promise<void>;
10
+ }
11
+ export declare class ETCDService implements Etcd3 {
12
+ private serviceFactory;
13
+ private instance;
14
+ init(): Promise<void>;
15
+ }
16
+ export interface ETCDService extends Etcd3 {
17
+ }
18
+ //# sourceMappingURL=manager.d.ts.map
@@ -0,0 +1,73 @@
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
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ETCDService = exports.ETCDServiceFactory = void 0;
13
+ const core_1 = require("@midwayjs/core");
14
+ const etcd3_1 = require("etcd3");
15
+ let ETCDServiceFactory = class ETCDServiceFactory extends core_1.ServiceFactory {
16
+ async init() {
17
+ await this.initClients(this.etcdConfig);
18
+ }
19
+ async createClient(config) {
20
+ this.logger.info('[midway:etcd] init %s', config.hosts);
21
+ return new etcd3_1.Etcd3(config);
22
+ }
23
+ getName() {
24
+ return 'etcd';
25
+ }
26
+ async destroyClient(client) {
27
+ await client.close();
28
+ }
29
+ };
30
+ __decorate([
31
+ (0, core_1.Config)('etcd'),
32
+ __metadata("design:type", Object)
33
+ ], ETCDServiceFactory.prototype, "etcdConfig", void 0);
34
+ __decorate([
35
+ (0, core_1.Init)(),
36
+ __metadata("design:type", Function),
37
+ __metadata("design:paramtypes", []),
38
+ __metadata("design:returntype", Promise)
39
+ ], ETCDServiceFactory.prototype, "init", null);
40
+ __decorate([
41
+ (0, core_1.Logger)('coreLogger'),
42
+ __metadata("design:type", Object)
43
+ ], ETCDServiceFactory.prototype, "logger", void 0);
44
+ ETCDServiceFactory = __decorate([
45
+ (0, core_1.Provide)(),
46
+ (0, core_1.Scope)(core_1.ScopeEnum.Singleton)
47
+ ], ETCDServiceFactory);
48
+ exports.ETCDServiceFactory = ETCDServiceFactory;
49
+ let ETCDService = class ETCDService {
50
+ async init() {
51
+ this.instance = this.serviceFactory.get('default');
52
+ if (!this.instance) {
53
+ throw new core_1.MidwayCommonError('etcd default instance not found.');
54
+ }
55
+ }
56
+ };
57
+ __decorate([
58
+ (0, core_1.Inject)(),
59
+ __metadata("design:type", ETCDServiceFactory)
60
+ ], ETCDService.prototype, "serviceFactory", void 0);
61
+ __decorate([
62
+ (0, core_1.Init)(),
63
+ __metadata("design:type", Function),
64
+ __metadata("design:paramtypes", []),
65
+ __metadata("design:returntype", Promise)
66
+ ], ETCDService.prototype, "init", null);
67
+ ETCDService = __decorate([
68
+ (0, core_1.Provide)(),
69
+ (0, core_1.Scope)(core_1.ScopeEnum.Singleton)
70
+ ], ETCDService);
71
+ exports.ETCDService = ETCDService;
72
+ (0, core_1.delegateTargetAllPrototypeMethod)(ETCDService, etcd3_1.Etcd3);
73
+ //# sourceMappingURL=manager.js.map
package/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { IOptions } from 'etcd3';
2
+ export * from './dist/index';
3
+
4
+ declare module '@midwayjs/core/dist/interface' {
5
+ interface MidwayConfig {
6
+ etcd?: ServiceFactoryConfigOption<IOptions>;
7
+ }
8
+ }
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@midwayjs/etcd",
3
+ "description": "midway etcd component",
4
+ "version": "3.0.0",
5
+ "main": "dist/index",
6
+ "typings": "index.d.ts",
7
+ "files": [
8
+ "dist/**/*.js",
9
+ "dist/**/*.d.ts",
10
+ "index.d.ts"
11
+ ],
12
+ "devDependencies": {
13
+ "@midwayjs/core": "^3.7.0",
14
+ "@midwayjs/mock": "^3.7.3"
15
+ },
16
+ "dependencies": {
17
+ "etcd3": "1.1.0"
18
+ },
19
+ "keywords": [
20
+ "etcd",
21
+ "midway"
22
+ ],
23
+ "author": "czy88840616 <czy88840616@gmail.com>",
24
+ "license": "MIT",
25
+ "scripts": {
26
+ "build": "tsc",
27
+ "test": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand",
28
+ "cov": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand --coverage --forceExit",
29
+ "ci": "npm run test",
30
+ "lint": "mwts check"
31
+ },
32
+ "engines": {
33
+ "node": ">=12"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/midwayjs/midway.git"
38
+ }
39
+ }