@gapi/daemon 1.8.122

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/.prettierrc ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "singleQuote": true,
3
+ "printWidth": 80
4
+ }
package/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ before_script:
2
+ - npm install
3
+ # script: npm test
4
+ env:
5
+ - DEPLOY_PLATFORM=heroku
6
+ language: node_js
7
+ node_js:
8
+ - "8"
package/README.md ADDED
@@ -0,0 +1,140 @@
1
+ ## Daemon
2
+ > Helps with productivity
3
+
4
+ > Automatically apply schema introspection changes from graphql API to specific folders
5
+
6
+ > The schema is introspected only when the API is successfully started
7
+
8
+ > When API changes his `schema` the client should know about it
9
+
10
+ > When You have multiple clients (mobile, desktop, web) you want to sync them according to your API Graphql Schema
11
+
12
+ To use daemon you need to activate it inside your `@gapi/core` => `CoreModule` configuration
13
+
14
+ ```typescript
15
+ const DEFAULT_CONFIG = {
16
+ server: {},
17
+ graphql: {},
18
+ daemon: { activated: true }
19
+ };
20
+ ```
21
+
22
+ ```typescript
23
+ import { BootstrapFramework } from '@rxdi/core';
24
+ import { AppModule } from './app/app.module';
25
+ import { CoreModule, Module } from '@gapi/core';
26
+
27
+ @Module({
28
+ imports: [
29
+ CoreModule.forRoot({
30
+ server: {},
31
+ pubsub: {},
32
+ graphql: {},
33
+ daemon: { activated: true }
34
+ }),
35
+
36
+ ]
37
+ })
38
+ export class FrameworkImports {}
39
+
40
+ BootstrapFramework(AppModule, [FrameworkImports]).subscribe()
41
+
42
+ ```
43
+
44
+ #### Starting daemon
45
+ ```bash
46
+ gapi daemon start
47
+ ```
48
+
49
+ #### Stopping daemon
50
+ ```bash
51
+ gapi daemon stop
52
+ ```
53
+
54
+ #### Cleaning daemon cache folder `~/.gapi/daemon`
55
+ ```bash
56
+ gapi daemon clean
57
+ ```
58
+
59
+
60
+ #### Link project
61
+ ```bash
62
+ gapi daemon link your-link-name
63
+ ```
64
+
65
+
66
+ #### Unlink project
67
+
68
+ ```bash
69
+ gapi daemon unlink
70
+ ```
71
+
72
+ #### Unlink all projects
73
+
74
+ ```bash
75
+ gapi daemon unlink --all
76
+ ```
77
+
78
+ # Flow
79
+
80
+
81
+ 1. Start the API
82
+ 2. Execute `gapi daemon link your-link-name`
83
+ 3. Go to client project folder
84
+ 4. Execute `gapi daemon link your-link-name`
85
+ 5. Made change to the graphql schema on the API
86
+ 6. You will see that client introspection changed also without writing single line of code
87
+
88
+ If you wish to link more than one project just execute command inside other folder
89
+
90
+ ```bash
91
+ gapi daemon link your-link-name
92
+ ```
93
+
94
+ # IMPORTANT
95
+
96
+ ### `gapi-cli.conf.yml` will be created if not present since daemon will trigger command using configuration from it.
97
+
98
+ ```bash
99
+ gapi schema introspect --collect-documents --collect-types
100
+ ```
101
+ Read [more](https://github.com/Stradivario/gapi-cli/wiki/schema) about `schema introspect`
102
+
103
+ ```yml
104
+ config:
105
+ schema:
106
+ introspectionEndpoint: http://localhost:9000/graphql
107
+ introspectionOutputFolder: ./src/server/api-introspection
108
+ ```
109
+
110
+ Replace with the desired configuration
111
+
112
+
113
+ # Custom plugins
114
+
115
+ Gapi daemon has capability to load external plugins via IPFS network or using regular @gapi module example module can be found [HERE](https://github.com/Stradivario/gapi-daemon-example-plugin)
116
+
117
+ A simple plugin looks like regular `@rxdi`/`@gapi` module basically every module inside this architecture can be used as a daemon plugin.
118
+
119
+ ```typescript
120
+ import { Module } from '@gapi/core';
121
+ import { MainService } from './services/main.service';
122
+ import { CustomControllerController } from './custom-controller/custom-controller.controller';
123
+
124
+ @Module({
125
+ providers: [MainService],
126
+ controllers: [CustomControllerController]
127
+ })
128
+ export class AppModule {}
129
+ ```
130
+
131
+ You can add also plugins via IPFS https://ipfs.io/ipfs/QmY74wyqeeHYVtEkChvbQypxeZd43rk77hY8yfaU16fZQ4 this is `@rxdi/deploy` plugin module can be found here https://ipfs.io/ipfs/QmYtvfC5cXutnH6y7nK8eGnPcAkU75DpngR3vGDk9A9KQt
132
+
133
+ ```
134
+ gapi plugin add QmY74wyqeeHYVtEkChvbQypxeZd43rk77hY8yfaU16fZQ4
135
+ ```
136
+
137
+ Remove
138
+ ```
139
+ gapi plugin remove QmY74wyqeeHYVtEkChvbQypxeZd43rk77hY8yfaU16fZQ4
140
+ ```
@@ -0,0 +1,7 @@
1
+ import { InjectionToken } from '@rxdi/core';
2
+ export declare const DaemonLink: InjectionToken<string>;
3
+ export declare type DaemonLink = string;
4
+ export interface DaemonConfig {
5
+ activated: boolean;
6
+ link?: DaemonLink;
7
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DaemonLink = void 0;
4
+ const core_1 = require("@rxdi/core");
5
+ exports.DaemonLink = new core_1.InjectionToken('gapi-daemon-graphql-server-link');
@@ -0,0 +1,6 @@
1
+ import { ModuleWithServices } from '@rxdi/core';
2
+ import { DaemonConfig } from './daemon.interface';
3
+ export declare class DaemonModule {
4
+ static forRoot(options?: DaemonConfig): ModuleWithServices;
5
+ }
6
+ export * from './daemon.interface';
package/dist/index.js ADDED
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
10
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
11
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
12
+ 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;
13
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
14
+ };
15
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
17
+ };
18
+ var DaemonModule_1;
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.DaemonModule = void 0;
21
+ /* eslint-disable @typescript-eslint/no-explicit-any */
22
+ const core_1 = require("@rxdi/core");
23
+ const daemon_interface_1 = require("./daemon.interface");
24
+ const after_start_service_1 = require("./services/after-start.service");
25
+ const daemon_service_1 = require("./services/daemon.service");
26
+ let DaemonModule = DaemonModule_1 = class DaemonModule {
27
+ static forRoot(options = {}) {
28
+ return {
29
+ module: DaemonModule_1,
30
+ providers: [
31
+ ...(options.activated
32
+ ? [
33
+ daemon_service_1.DaemonService,
34
+ after_start_service_1.AfterStart,
35
+ {
36
+ provide: daemon_interface_1.DaemonLink,
37
+ useValue: options.link || 'http://localhost:42000/graphql',
38
+ },
39
+ ]
40
+ : []),
41
+ ],
42
+ };
43
+ }
44
+ };
45
+ DaemonModule = DaemonModule_1 = __decorate([
46
+ core_1.Module()
47
+ ], DaemonModule);
48
+ exports.DaemonModule = DaemonModule;
49
+ __exportStar(require("./daemon.interface"), exports);
@@ -0,0 +1,7 @@
1
+ import { AfterStarterService } from '@rxdi/core';
2
+ import { DaemonService } from './daemon.service';
3
+ export declare class AfterStart {
4
+ private afterStarterService;
5
+ private daemonService;
6
+ constructor(afterStarterService: AfterStarterService, daemonService: DaemonService);
7
+ }
@@ -0,0 +1,27 @@
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.AfterStart = void 0;
13
+ const core_1 = require("@rxdi/core");
14
+ const daemon_service_1 = require("./daemon.service");
15
+ let AfterStart = class AfterStart {
16
+ constructor(afterStarterService, daemonService) {
17
+ this.afterStarterService = afterStarterService;
18
+ this.daemonService = daemonService;
19
+ this.afterStarterService.appStarted.subscribe(() => this.daemonService.notifyDaemon());
20
+ }
21
+ };
22
+ AfterStart = __decorate([
23
+ core_1.Injectable(),
24
+ __metadata("design:paramtypes", [core_1.AfterStarterService,
25
+ daemon_service_1.DaemonService])
26
+ ], AfterStart);
27
+ exports.AfterStart = AfterStart;
@@ -0,0 +1,12 @@
1
+ import { Server } from 'hapi';
2
+ import { DaemonLink } from '../daemon.interface';
3
+ export declare class DaemonService {
4
+ private defaultDaemonLink;
5
+ private server;
6
+ constructor(defaultDaemonLink: DaemonLink, server: Server);
7
+ notifyDaemon(): PromiseLike<import("@rxdi/graphql/dist/plugin-init").Response<{
8
+ notifyDaemon: {
9
+ repoPath: string;
10
+ };
11
+ }>>;
12
+ }
@@ -0,0 +1,53 @@
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
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.DaemonService = void 0;
16
+ const core_1 = require("@rxdi/core");
17
+ const graphql_1 = require("@rxdi/graphql");
18
+ const hapi_1 = require("@rxdi/hapi");
19
+ const hapi_2 = require("hapi");
20
+ const daemon_interface_1 = require("../daemon.interface");
21
+ let DaemonService = class DaemonService {
22
+ constructor(defaultDaemonLink, server) {
23
+ this.defaultDaemonLink = defaultDaemonLink;
24
+ this.server = server;
25
+ }
26
+ notifyDaemon() {
27
+ return graphql_1.sendRequest({
28
+ query: `
29
+ mutation notifyDaemon($repoPath: String!, $serverMetadata: ServerMetadataInputType) {
30
+ notifyDaemon(repoPath: $repoPath, serverMetadata: $serverMetadata) {
31
+ repoPath
32
+ serverMetadata {
33
+ port
34
+ }
35
+ }
36
+ }
37
+ `,
38
+ variables: {
39
+ repoPath: process.cwd(),
40
+ serverMetadata: {
41
+ port: this.server.info.port,
42
+ },
43
+ },
44
+ }, this.defaultDaemonLink);
45
+ }
46
+ };
47
+ DaemonService = __decorate([
48
+ core_1.Injectable(),
49
+ __param(0, core_1.Inject(daemon_interface_1.DaemonLink)),
50
+ __param(1, core_1.Inject(hapi_1.HAPI_SERVER)),
51
+ __metadata("design:paramtypes", [String, hapi_2.Server])
52
+ ], DaemonService);
53
+ exports.DaemonService = DaemonService;
@@ -0,0 +1,109 @@
1
+ config:
2
+ # Application configuration
3
+ app:
4
+ local:
5
+ API_PORT: 9000
6
+ API_CERT: ./cert.key
7
+ NODE_ENV: development
8
+ AMQP_HOST: 182.10.0.5
9
+ AMQP_PORT: 5672
10
+ GRAPHIQL: true
11
+ GRAPHIQL_TOKEN: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImtyaXN0aXFuLnRhY2hldkBnbWFpbC5jb20iLCJpZCI6MSwic2NvcGUiOlsiQURNSU4iXSwiaWF0IjoxNTIwMjkxMzkyfQ.9hpIDPkSiGvjTmUEyg_R_izW-ra2RzzLbe3Uh3IFsZg
12
+ ENDPOINT_TESTING: http://localhost:9000/graphql
13
+ TOKEN_TESTING: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImtyaXN0aXFuLnRhY2hldkBnbWFpbC5jb20iLCJzY29wZSI6WyJBRE1JTiJdLCJpZCI6MSwiaWF0IjoxNTE2OTk2MzYxfQ.7ANr5VHrViD3NkCaDr0nSWYwk46UAEbOwB52pqye4AM
14
+ prod:
15
+ API_PORT: 9000
16
+ API_CERT: ./cert.key
17
+ NODE_ENV: production
18
+ AMQP_HOST: 182.10.0.5
19
+ AMQP_PORT: 5672
20
+ GRAPHIQL: true
21
+ GRAPHIQL_TOKEN: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImtyaXN0aXFuLnRhY2hldkBnbWFpbC5jb20iLCJpZCI6MSwic2NvcGUiOlsiQURNSU4iXSwiaWF0IjoxNTIwMjkxMzkyfQ.9hpIDPkSiGvjTmUEyg_R_izW-ra2RzzLbe3Uh3IFsZg
22
+ ENDPOINT_TESTING: http://localhost:9000/graphql
23
+ TOKEN_TESTING: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImtyaXN0aXFuLnRhY2hldkBnbWFpbC5jb20iLCJzY29wZSI6WyJBRE1JTiJdLCJpZCI6MSwiaWF0IjoxNTE2OTk2MzYxfQ.7ANr5VHrViD3NkCaDr0nSWYwk46UAEbOwB52pqye4AM
24
+ # Testing configuration for local(dev) or worker(running tests as a separate worker with separate environment)
25
+ test:
26
+ local: extends app/prod
27
+ worker:
28
+ API_PORT: 9000
29
+ API_CERT: ./cert.key
30
+ NODE_ENV: production
31
+ AMQP_HOST: 182.10.0.5
32
+ AMQP_PORT: 5672
33
+ ENDPOINT_TESTING: http://182.10.0.101:9000/graphql
34
+ TOKEN_TESTING: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImtyaXN0aXFuLnRhY2hldkBnbWFpbC5jb20iLCJzY29wZSI6WyJBRE1JTiJdLCJpZCI6MSwiaWF0IjoxNTE2OTk2MzYxfQ.7ANr5VHrViD3NkCaDr0nSWYwk46UAEbOwB52pqye4AM
35
+
36
+ schema:
37
+ introspectionEndpoint: http://localhost:9000/graphql
38
+ introspectionOutputFolder: ./src/api-introspection
39
+
40
+ commands:
41
+
42
+ testing:
43
+ stop:
44
+ - docker rm -f gapi-api-prod-worker-tests-executor
45
+ - docker rm -f gapi-api-prod-worker-tests-provider
46
+ start:
47
+ - gapi testing start-provider
48
+ - sleep 10
49
+ - gapi testing start-executor
50
+ - echo Cleaning...
51
+ - gapi testing stop
52
+ start-provider: docker run -d --network=gapiapiprod_gapi --ip=182.10.0.101 --name gapi-api-prod-worker-tests-provider gapi/api/prod
53
+ start-executor:
54
+ - docker run -d --network=gapiapiprod_gapi --ip=182.10.0.100 --name gapi-api-prod-worker-tests-executor gapi/api/prod
55
+ - docker exec gapi-api-prod-worker-tests-provider npm -v
56
+ - gapi test --worker
57
+
58
+ workers:
59
+ start:
60
+ - gapi workers start-1
61
+ - gapi workers start-2
62
+ - gapi workers start-3
63
+ - gapi workers start-4
64
+ stop:
65
+ - docker rm -f gapi-api-prod-worker-1
66
+ - docker rm -f gapi-api-prod-worker-2
67
+ - docker rm -f gapi-api-prod-worker-3
68
+ - docker rm -f gapi-api-prod-worker-4
69
+ start-1: docker run -d --network=gapiapiprod_gapi --ip=182.10.0.21 --name gapi-api-prod-worker-1 gapi/api/prod
70
+ start-2: docker run -d --network=gapiapiprod_gapi --ip=182.10.0.22 --name gapi-api-prod-worker-2 gapi/api/prod
71
+ start-3: docker run -d --network=gapiapiprod_gapi --ip=182.10.0.23 --name gapi-api-prod-worker-3 gapi/api/prod
72
+ start-4: docker run -d --network=gapiapiprod_gapi --ip=182.10.0.24 --name gapi-api-prod-worker-4 gapi/api/prod
73
+ example-worker-with-port: docker run -d --network=gapiapiprod_gapi --ip=182.10.0.25 --name gapi-api-prod-worker-5 -p 9001:9000 gapi/api/prod
74
+
75
+ app:
76
+ start:
77
+ - docker-compose -p gapi-api-prod up --force-recreate -d
78
+ - gapi rabbitmq enable-dashboard
79
+ stop:
80
+ - gapi nginx stop
81
+ - gapi api stop
82
+ - gapi rabbitmq stop
83
+ build: docker build -t gapi/api/prod .
84
+
85
+ api:
86
+ stop: docker rm -f gapi-api-prod
87
+
88
+ nginx:
89
+ stop: docker rm -f gapi-api-nginx
90
+
91
+ rabbitmq:
92
+ stop: docker rm -f gapi-api-rabbitmq
93
+ restart: docker restart gapi-api-rabbitmq
94
+ enable-dashboard: docker exec gapi-api-rabbitmq rabbitmq-plugins enable rabbitmq_management
95
+ prepare:
96
+ core:
97
+ - tsc
98
+ - find . -not -path "./node_modules/*" -type f -iname \*.js -delete
99
+ - parcel build --target node src/index.ts
100
+ - cp -r dist/index.js index.js
101
+ - gapi prepare clean
102
+ clean:
103
+ - rm -rf dist
104
+ - rm -rf .cache
105
+ # You can define your custom commands for example
106
+ # commands:
107
+ # your-cli:
108
+ # my-command: 'npm -v'
109
+ # This command can be executed as "gapi your-cli my-command"
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@gapi/daemon",
3
+ "version": "1.8.122",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/Stradivario/gapi.git"
7
+ },
8
+ "author": "Kristian Tachev <kristiqn.tachev@gmail.com> (Stradivario)",
9
+ "scripts": {
10
+ "patch": "npm run build && npm version patch && npm publish --update-readme --access public && npm run delete-dist",
11
+ "delete-dist": "rm -rf dist",
12
+ "clean": "git clean -dxf",
13
+ "lint": "npx eslint . --ext .ts",
14
+ "lint-fix": "npx eslint . --fix --ext .ts",
15
+ "build": "rm -rf dist && tsc || true"
16
+ },
17
+ "keywords": [
18
+ "graphql",
19
+ "gapi",
20
+ "node"
21
+ ],
22
+ "license": "MIT",
23
+ "bugs": {
24
+ "url": "https://github.com/Stradivario/gapi-daemon/issues"
25
+ },
26
+ "main": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
28
+ "module": "./dist/index.js",
29
+ "typings": "./dist/index.d.ts",
30
+ "jest": {
31
+ "testEnvironment": "node",
32
+ "testPathIgnorePatterns": [
33
+ "/node_modules/"
34
+ ],
35
+ "coverageReporters": [
36
+ "lcov",
37
+ "html"
38
+ ],
39
+ "rootDir": "./",
40
+ "moduleFileExtensions": [
41
+ "ts",
42
+ "tsx",
43
+ "js",
44
+ "json",
45
+ "node"
46
+ ],
47
+ "transform": {
48
+ "\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
49
+ },
50
+ "testRegex": "/development/.*\\.spec.(ts|tsx|js)$",
51
+ "verbose": true,
52
+ "collectCoverage": true
53
+ },
54
+ "description": "![Build Status](http://gitlab.youvolio.com/gapi/gapi-starter/badges/master/build.svg)",
55
+ "devDependencies": {
56
+ "@types/hapi": "^18.0.2",
57
+ "typescript": "^3.8.3",
58
+ "@rxdi/core": "^0.7.114",
59
+ "@rxdi/graphql": "^0.7.114",
60
+ "@rxdi/hapi": "^0.7.114"
61
+ }
62
+ }
@@ -0,0 +1,10 @@
1
+ import { InjectionToken } from '@rxdi/core';
2
+
3
+ export const DaemonLink = new InjectionToken<string>(
4
+ 'gapi-daemon-graphql-server-link'
5
+ );
6
+ export type DaemonLink = string;
7
+ export interface DaemonConfig {
8
+ activated: boolean;
9
+ link?: DaemonLink;
10
+ }
package/src/index.ts ADDED
@@ -0,0 +1,29 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { Module, ModuleWithServices } from '@rxdi/core';
3
+
4
+ import { DaemonConfig, DaemonLink } from './daemon.interface';
5
+ import { AfterStart } from './services/after-start.service';
6
+ import { DaemonService } from './services/daemon.service';
7
+
8
+ @Module()
9
+ export class DaemonModule {
10
+ public static forRoot(options: DaemonConfig = {} as any): ModuleWithServices {
11
+ return {
12
+ module: DaemonModule,
13
+ providers: [
14
+ ...(options.activated
15
+ ? [
16
+ DaemonService,
17
+ AfterStart,
18
+ {
19
+ provide: DaemonLink,
20
+ useValue: options.link || 'http://localhost:42000/graphql',
21
+ },
22
+ ]
23
+ : []),
24
+ ],
25
+ };
26
+ }
27
+ }
28
+
29
+ export * from './daemon.interface';
@@ -0,0 +1,15 @@
1
+ import { AfterStarterService, Injectable } from '@rxdi/core';
2
+
3
+ import { DaemonService } from './daemon.service';
4
+
5
+ @Injectable()
6
+ export class AfterStart {
7
+ constructor(
8
+ private afterStarterService: AfterStarterService,
9
+ private daemonService: DaemonService
10
+ ) {
11
+ this.afterStarterService.appStarted.subscribe(() =>
12
+ this.daemonService.notifyDaemon()
13
+ );
14
+ }
15
+ }
@@ -0,0 +1,38 @@
1
+ import { Inject, Injectable } from '@rxdi/core';
2
+ import { sendRequest } from '@rxdi/graphql';
3
+ import { HAPI_SERVER } from '@rxdi/hapi';
4
+ import { Server } from 'hapi';
5
+
6
+ import { DaemonLink } from '../daemon.interface';
7
+
8
+ @Injectable()
9
+ export class DaemonService {
10
+ constructor(
11
+ @Inject(DaemonLink) private defaultDaemonLink: DaemonLink,
12
+ @Inject(HAPI_SERVER) private server: Server
13
+ ) {}
14
+
15
+ notifyDaemon() {
16
+ return sendRequest<{ notifyDaemon: { repoPath: string } }>(
17
+ {
18
+ query: `
19
+ mutation notifyDaemon($repoPath: String!, $serverMetadata: ServerMetadataInputType) {
20
+ notifyDaemon(repoPath: $repoPath, serverMetadata: $serverMetadata) {
21
+ repoPath
22
+ serverMetadata {
23
+ port
24
+ }
25
+ }
26
+ }
27
+ `,
28
+ variables: {
29
+ repoPath: process.cwd(),
30
+ serverMetadata: {
31
+ port: this.server.info.port,
32
+ },
33
+ },
34
+ },
35
+ this.defaultDaemonLink
36
+ );
37
+ }
38
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": true,
4
+ "module": "commonjs",
5
+ "target": "es6",
6
+ "baseUrl": ".",
7
+ "stripInternal": true,
8
+ "emitDecoratorMetadata": true,
9
+ "experimentalDecorators": true,
10
+ "moduleResolution": "node",
11
+ "outDir": "dist",
12
+ "lib": [
13
+ "es2017",
14
+ "es2016",
15
+ "es2015",
16
+ "es6",
17
+ "dom",
18
+ "esnext.asynciterable"
19
+ ],
20
+ "skipLibCheck": true,
21
+ "types": []
22
+ },
23
+ "files": [
24
+ "src/index.ts"
25
+ ]
26
+ }