@things-factory/shell 7.0.0-alpha.0 → 7.0.0-alpha.1
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-server/graphql-local-client.d.ts +19 -0
- package/dist-server/graphql-local-client.js +14 -0
- package/dist-server/graphql-local-client.js.map +1 -1
- package/dist-server/initializers/database.d.ts +26 -0
- package/dist-server/initializers/database.js +26 -0
- package/dist-server/initializers/database.js.map +1 -1
- package/dist-server/pubsub-log-transport.d.ts +27 -0
- package/dist-server/pubsub-log-transport.js +15 -0
- package/dist-server/pubsub-log-transport.js.map +1 -1
- package/dist-server/pubsub.d.ts +9 -1
- package/dist-server/pubsub.js +14 -2
- package/dist-server/pubsub.js.map +1 -1
- package/dist-server/schema.d.ts +4 -0
- package/dist-server/schema.js +7 -3
- package/dist-server/schema.js.map +1 -1
- package/dist-server/service/subscription-data/data-resolver.js +6 -12
- package/dist-server/service/subscription-data/data-resolver.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/dist-server/typeorm/encrypt-transform.d.ts +5 -0
- package/dist-server/typeorm/encrypt-transform.js +25 -0
- package/dist-server/typeorm/encrypt-transform.js.map +1 -1
- package/dist-server/utils/condition-builder.d.ts +11 -0
- package/dist-server/utils/condition-builder.js +11 -0
- package/dist-server/utils/condition-builder.js.map +1 -1
- package/dist-server/utils/get-domain.d.ts +46 -0
- package/dist-server/utils/get-domain.js +70 -0
- package/dist-server/utils/get-domain.js.map +1 -1
- package/dist-server/utils/get-query-builder-from-list-params.d.ts +12 -2
- package/dist-server/utils/get-query-builder-from-list-params.js +24 -8
- package/dist-server/utils/get-query-builder-from-list-params.js.map +1 -1
- package/dist-server/utils/get-times-for-period.d.ts +14 -0
- package/dist-server/utils/get-times-for-period.js +14 -0
- package/dist-server/utils/get-times-for-period.js.map +1 -1
- package/dist-server/utils/list-param-adjuster.d.ts +9 -0
- package/dist-server/utils/list-param-adjuster.js +9 -0
- package/dist-server/utils/list-param-adjuster.js.map +1 -1
- package/dist-server/utils/list-params-converter.d.ts +6 -0
- package/dist-server/utils/list-params-converter.js +27 -0
- package/dist-server/utils/list-params-converter.js.map +1 -1
- package/dist-server/utils/list-query-builder.d.ts +10 -1
- package/dist-server/utils/list-query-builder.js +10 -1
- package/dist-server/utils/list-query-builder.js.map +1 -1
- package/dist-server/utils/publish-progress.d.ts +9 -0
- package/dist-server/utils/publish-progress.js +9 -0
- package/dist-server/utils/publish-progress.js.map +1 -1
- package/package.json +6 -6
- package/server/graphql-local-client.ts +20 -0
- package/server/initializers/database.ts +26 -0
- package/server/pubsub-log-transport.ts +29 -0
- package/server/pubsub.ts +17 -3
- package/server/schema.ts +9 -12
- package/server/service/subscription-data/data-resolver.ts +9 -18
- package/server/typeorm/encrypt-transform.ts +26 -0
- package/server/utils/condition-builder.ts +12 -8
- package/server/utils/get-domain.ts +70 -0
- package/server/utils/get-query-builder-from-list-params.ts +26 -16
- package/server/utils/get-times-for-period.ts +15 -4
- package/server/utils/list-param-adjuster.ts +9 -0
- package/server/utils/list-params-converter.ts +28 -4
- package/server/utils/list-query-builder.ts +13 -17
- package/server/utils/publish-progress.ts +9 -0
- package/dist-server/webpack/koa-webpack/client.d.ts +0 -1
- package/dist-server/webpack/koa-webpack/client.js +0 -24
- package/dist-server/webpack/koa-webpack/client.js.map +0 -1
- package/dist-server/webpack/koa-webpack/index.d.ts +0 -2
- package/dist-server/webpack/koa-webpack/index.js +0 -58
- package/dist-server/webpack/koa-webpack/index.js.map +0 -1
- package/dist-server/webpack/koa-webpack/middleware.d.ts +0 -0
- package/dist-server/webpack/koa-webpack/middleware.js +0 -42
- package/dist-server/webpack/koa-webpack/middleware.js.map +0 -1
- package/dist-server/webpack/koa-webpack/validate.d.ts +0 -1
- package/dist-server/webpack/koa-webpack/validate.js +0 -26
- package/dist-server/webpack/koa-webpack/validate.js.map +0 -1
- package/server/webpack/koa-webpack/client.ts +0 -26
- package/server/webpack/koa-webpack/index.ts +0 -71
- package/server/webpack/koa-webpack/middleware.ts +0 -47
- package/server/webpack/koa-webpack/validate.ts +0 -27
@@ -1,5 +1,24 @@
|
|
1
|
+
/**
|
2
|
+
* Apollo Client configuration for a local GraphQL schema.
|
3
|
+
* This class provides a static method `init` to initialize the client with a schema and an app context.
|
4
|
+
*/
|
1
5
|
import { ApolloClient, NormalizedCacheObject } from '@apollo/client';
|
6
|
+
/**
|
7
|
+
* GraphqlLocalClient is a utility class for initializing an Apollo Client for a local GraphQL schema.
|
8
|
+
* It provides a static `init` method for setting up the client with a schema and an app context.
|
9
|
+
*/
|
2
10
|
export declare class GraphqlLocalClient {
|
11
|
+
/**
|
12
|
+
* Apollo Client instance for local GraphQL schema.
|
13
|
+
* @static
|
14
|
+
* @type {ApolloClient<NormalizedCacheObject>}
|
15
|
+
*/
|
3
16
|
static client: ApolloClient<NormalizedCacheObject>;
|
17
|
+
/**
|
18
|
+
* Initializes the Apollo Client for a local GraphQL schema.
|
19
|
+
* @static
|
20
|
+
* @param {object} schema - The GraphQL schema to use.
|
21
|
+
* @param {object} app - The application context to be passed in as part of the execution context.
|
22
|
+
*/
|
4
23
|
static init(schema: any, app: any): void;
|
5
24
|
}
|
@@ -1,6 +1,10 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.GraphqlLocalClient = void 0;
|
4
|
+
/**
|
5
|
+
* Apollo Client configuration for a local GraphQL schema.
|
6
|
+
* This class provides a static method `init` to initialize the client with a schema and an app context.
|
7
|
+
*/
|
4
8
|
const client_1 = require("@apollo/client");
|
5
9
|
const schema_1 = require("@apollo/client/link/schema");
|
6
10
|
const defaultOptions = {
|
@@ -19,7 +23,17 @@ const defaultOptions = {
|
|
19
23
|
const cache = new client_1.InMemoryCache({
|
20
24
|
addTypename: false
|
21
25
|
});
|
26
|
+
/**
|
27
|
+
* GraphqlLocalClient is a utility class for initializing an Apollo Client for a local GraphQL schema.
|
28
|
+
* It provides a static `init` method for setting up the client with a schema and an app context.
|
29
|
+
*/
|
22
30
|
class GraphqlLocalClient {
|
31
|
+
/**
|
32
|
+
* Initializes the Apollo Client for a local GraphQL schema.
|
33
|
+
* @static
|
34
|
+
* @param {object} schema - The GraphQL schema to use.
|
35
|
+
* @param {object} app - The application context to be passed in as part of the execution context.
|
36
|
+
*/
|
23
37
|
static init(schema, app) {
|
24
38
|
GraphqlLocalClient.client = new client_1.ApolloClient({
|
25
39
|
defaultOptions,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"graphql-local-client.js","sourceRoot":"","sources":["../server/graphql-local-client.ts"],"names":[],"mappings":";;;AAAA,2CAAmF;AACnF,uDAAuD;AAEvD,MAAM,cAAc,GAAQ;IAC1B,UAAU,EAAE;QACV,WAAW,EAAE,UAAU;QACvB,WAAW,EAAE,QAAQ;KACtB;IACD,KAAK,EAAE;QACL,WAAW,EAAE,UAAU;QACvB,WAAW,EAAE,KAAK;KACnB;IACD,MAAM,EAAE;QACN,WAAW,EAAE,KAAK;KACnB;CACF,CAAA;AAED,MAAM,KAAK,GAAG,IAAI,sBAAa,CAAC;IAC9B,WAAW,EAAE,KAAK;CACnB,CAAC,CAAA;
|
1
|
+
{"version":3,"file":"graphql-local-client.js","sourceRoot":"","sources":["../server/graphql-local-client.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,2CAAmF;AACnF,uDAAuD;AAEvD,MAAM,cAAc,GAAQ;IAC1B,UAAU,EAAE;QACV,WAAW,EAAE,UAAU;QACvB,WAAW,EAAE,QAAQ;KACtB;IACD,KAAK,EAAE;QACL,WAAW,EAAE,UAAU;QACvB,WAAW,EAAE,KAAK;KACnB;IACD,MAAM,EAAE;QACN,WAAW,EAAE,KAAK;KACnB;CACF,CAAA;AAED,MAAM,KAAK,GAAG,IAAI,sBAAa,CAAC;IAC9B,WAAW,EAAE,KAAK;CACnB,CAAC,CAAA;AAEF;;;GAGG;AACH,MAAa,kBAAkB;IAQ7B;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG;QACrB,kBAAkB,CAAC,MAAM,GAAG,IAAI,qBAAY,CAAC;YAC3C,cAAc;YACd,KAAK;YACL,IAAI,EAAE,IAAI,mBAAU,CAAC;gBACnB,MAAM;gBACN,OAAO,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;oBACpC,uCACK,GAAG,CAAC,UAAU,EAAE,KACnB,GAAG,IACJ;gBACH,CAAC;aACF,CAAC;SACH,CAAC,CAAA;IACJ,CAAC;CACF;AA7BD,gDA6BC","sourcesContent":["/**\n * Apollo Client configuration for a local GraphQL schema.\n * This class provides a static method `init` to initialize the client with a schema and an app context.\n */\nimport { ApolloClient, InMemoryCache, NormalizedCacheObject } from '@apollo/client'\nimport { SchemaLink } from '@apollo/client/link/schema'\n\nconst defaultOptions: any = {\n watchQuery: {\n fetchPolicy: 'no-cache',\n errorPolicy: 'ignore'\n },\n query: {\n fetchPolicy: 'no-cache',\n errorPolicy: 'all'\n },\n mutate: {\n errorPolicy: 'all'\n }\n}\n\nconst cache = new InMemoryCache({\n addTypename: false\n})\n\n/**\n * GraphqlLocalClient is a utility class for initializing an Apollo Client for a local GraphQL schema.\n * It provides a static `init` method for setting up the client with a schema and an app context.\n */\nexport class GraphqlLocalClient {\n /**\n * Apollo Client instance for local GraphQL schema.\n * @static\n * @type {ApolloClient<NormalizedCacheObject>}\n */\n static client: ApolloClient<NormalizedCacheObject>\n\n /**\n * Initializes the Apollo Client for a local GraphQL schema.\n * @static\n * @param {object} schema - The GraphQL schema to use.\n * @param {object} app - The application context to be passed in as part of the execution context.\n */\n static init(schema, app) {\n GraphqlLocalClient.client = new ApolloClient({\n defaultOptions,\n cache,\n link: new SchemaLink({\n schema,\n context: (obj, args, context, info) => {\n return {\n ...obj.getContext(),\n app\n }\n }\n })\n })\n }\n}\n"]}
|
@@ -1,7 +1,33 @@
|
|
1
1
|
import { DataSource, EntityTarget, Repository } from 'typeorm';
|
2
|
+
/**
|
3
|
+
* Returns the specified DataSource by name.
|
4
|
+
* @param {string} name - The name of the DataSource.
|
5
|
+
* @returns {DataSource} - The DataSource with the specified name.
|
6
|
+
*/
|
2
7
|
export declare function getDataSource(name?: string): DataSource;
|
8
|
+
/**
|
9
|
+
* Adds a new DataSource with the specified name.
|
10
|
+
* @param {string} name - The name of the DataSource to add.
|
11
|
+
* @param {DataSource} dataSource - The DataSource to add.
|
12
|
+
*/
|
3
13
|
export declare function addDataSource(name: string, dataSource: DataSource): void;
|
14
|
+
/**
|
15
|
+
* Removes a DataSource with the specified name.
|
16
|
+
* @param {string} name - The name of the DataSource to remove.
|
17
|
+
*/
|
4
18
|
export declare function removeDataSource(name: string): void;
|
19
|
+
/**
|
20
|
+
* Returns an array of all registered DataSource names.
|
21
|
+
* @returns {string[]} - An array of DataSource names.
|
22
|
+
*/
|
5
23
|
export declare function getDataSourceNames(): string[];
|
24
|
+
/**
|
25
|
+
* Returns a repository for the specified entity.
|
26
|
+
* @param {EntityTarget<X>} target - The target entity for which to get the repository.
|
27
|
+
* @returns {Repository<X>} - The repository for the specified entity.
|
28
|
+
*/
|
6
29
|
export declare function getRepository<X>(target: EntityTarget<X>): Repository<X>;
|
30
|
+
/**
|
31
|
+
* Initializes the database connections and data sources.
|
32
|
+
*/
|
7
33
|
export declare const databaseInitializer: () => Promise<void>;
|
@@ -12,26 +12,52 @@ catch (e) {
|
|
12
12
|
ormconfig = require('@things-factory/shell/ormconfig');
|
13
13
|
}
|
14
14
|
const dataSources = {};
|
15
|
+
/**
|
16
|
+
* Returns the specified DataSource by name.
|
17
|
+
* @param {string} name - The name of the DataSource.
|
18
|
+
* @returns {DataSource} - The DataSource with the specified name.
|
19
|
+
*/
|
15
20
|
function getDataSource(name) {
|
16
21
|
return dataSources[name || 'default'];
|
17
22
|
}
|
18
23
|
exports.getDataSource = getDataSource;
|
24
|
+
/**
|
25
|
+
* Adds a new DataSource with the specified name.
|
26
|
+
* @param {string} name - The name of the DataSource to add.
|
27
|
+
* @param {DataSource} dataSource - The DataSource to add.
|
28
|
+
*/
|
19
29
|
function addDataSource(name, dataSource) {
|
20
30
|
dataSources[name] = dataSource;
|
21
31
|
}
|
22
32
|
exports.addDataSource = addDataSource;
|
33
|
+
/**
|
34
|
+
* Removes a DataSource with the specified name.
|
35
|
+
* @param {string} name - The name of the DataSource to remove.
|
36
|
+
*/
|
23
37
|
function removeDataSource(name) {
|
24
38
|
delete dataSources[name];
|
25
39
|
}
|
26
40
|
exports.removeDataSource = removeDataSource;
|
41
|
+
/**
|
42
|
+
* Returns an array of all registered DataSource names.
|
43
|
+
* @returns {string[]} - An array of DataSource names.
|
44
|
+
*/
|
27
45
|
function getDataSourceNames() {
|
28
46
|
return Object.keys(dataSources);
|
29
47
|
}
|
30
48
|
exports.getDataSourceNames = getDataSourceNames;
|
49
|
+
/**
|
50
|
+
* Returns a repository for the specified entity.
|
51
|
+
* @param {EntityTarget<X>} target - The target entity for which to get the repository.
|
52
|
+
* @returns {Repository<X>} - The repository for the specified entity.
|
53
|
+
*/
|
31
54
|
function getRepository(target) {
|
32
55
|
return getDataSource('default').getRepository(target);
|
33
56
|
}
|
34
57
|
exports.getRepository = getRepository;
|
58
|
+
/**
|
59
|
+
* Initializes the database connections and data sources.
|
60
|
+
*/
|
35
61
|
const databaseInitializer = async () => {
|
36
62
|
try {
|
37
63
|
const readConnectionConfig = env_1.config.get('ormconfig');
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../server/initializers/database.ts"],"names":[],"mappings":";;;AAAA,qCAAgF;AAEhF,6CAAiE;AAEjE,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAE5B,IAAI,SAAS,CAAA;AACb,IAAI;IACF,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,iBAAW,EAAE,WAAW,CAAC,CAAC,CAAA;CAC5D;AAAC,OAAO,CAAC,EAAE;IACV,S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ChC,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,CAAA;YAElC,YAAM,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAA;SAClD;aAAM;YACL,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;SAChC;KACF;IAAC,OAAO,CAAC,EAAE;QACV,YAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;KAChB;AACH,CAAC,CAAA;AAlCY,QAAA,mBAAmB,uBAkC/B","sourcesContent":["import { createConnection, DataSource, EntityTarget, Repository } from 'typeorm'\n\nimport { appRootPath, config, logger } from '@things-factory/env'\n\nconst path = require('path')\n\nvar ormconfig\ntry {\n ormconfig = require(path.resolve(appRootPath, 'ormconfig'))\n} catch (e) {\n ormconfig = require('@things-factory/shell/ormconfig')\n}\n\nconst dataSources: { [name: string]: DataSource } = {}\n\n/**\n * Returns the specified DataSource by name.\n * @param {string} name - The name of the DataSource.\n * @returns {DataSource} - The DataSource with the specified name.\n */\nexport function getDataSource(name?: string): DataSource {\n return dataSources[name || 'default']\n}\n\n/**\n * Adds a new DataSource with the specified name.\n * @param {string} name - The name of the DataSource to add.\n * @param {DataSource} dataSource - The DataSource to add.\n */\nexport function addDataSource(name: string, dataSource: DataSource) {\n dataSources[name] = dataSource\n}\n\n/**\n * Removes a DataSource with the specified name.\n * @param {string} name - The name of the DataSource to remove.\n */\nexport function removeDataSource(name: string) {\n delete dataSources[name]\n}\n\n/**\n * Returns an array of all registered DataSource names.\n * @returns {string[]} - An array of DataSource names.\n */\nexport function getDataSourceNames() {\n return Object.keys(dataSources)\n}\n\n/**\n * Returns a repository for the specified entity.\n * @param {EntityTarget<X>} target - The target entity for which to get the repository.\n * @returns {Repository<X>} - The repository for the specified entity.\n */\nexport function getRepository<X>(target: EntityTarget<X>): Repository<X> {\n return getDataSource('default').getRepository<X>(target)\n}\n\n/**\n * Initializes the database connections and data sources.\n */\nexport const databaseInitializer = async () => {\n try {\n const readConnectionConfig = config.get('ormconfig')\n\n const dataSource = await createConnection({\n ...ormconfig,\n ...readConnectionConfig\n })\n\n addDataSource('default', dataSource)\n\n logger.info('Default DataSource established')\n\n if (readConnectionConfig.type == 'sqlite' && readConnectionConfig.synchronize == false) {\n await dataSource.query('PRAGMA foreign_keys=OFF')\n await dataSource.synchronize()\n await dataSource.query('PRAGMA foreign_keys=ON')\n }\n\n if (config.get('ormconfig4Tx')) {\n const dataSource4Tx = new DataSource({\n ...ormconfig,\n ...config.get('ormconfig4Tx')\n })\n await dataSource4Tx.initialize()\n addDataSource('tx', dataSource4Tx)\n\n logger.info('Transaction DataSource established')\n } else {\n addDataSource('tx', dataSource)\n }\n } catch (e) {\n logger.error(e)\n }\n}\n"]}
|
@@ -1,8 +1,35 @@
|
|
1
1
|
import Transport from 'winston-transport';
|
2
|
+
/**
|
3
|
+
* PubSubLogTransport is a custom Winston transport that publishes log messages to a GraphQL Pub/Sub topic.
|
4
|
+
*/
|
2
5
|
export declare class PubSubLogTransport extends Transport {
|
6
|
+
/**
|
7
|
+
* The source object providing the log messages.
|
8
|
+
* @type {object}
|
9
|
+
*/
|
3
10
|
source: object;
|
11
|
+
/**
|
12
|
+
* The Pub/Sub topic to which log messages will be published.
|
13
|
+
* @type {string}
|
14
|
+
*/
|
4
15
|
topic: string;
|
16
|
+
/**
|
17
|
+
* The name of the field resolver for log messages.
|
18
|
+
* @type {string}
|
19
|
+
*/
|
5
20
|
resolver: string;
|
21
|
+
/**
|
22
|
+
* Creates an instance of PubSubLogTransport.
|
23
|
+
* @param {object} opts - Options for configuring the transport.
|
24
|
+
* @param {string} opts.topic - The Pub/Sub topic to which log messages will be published.
|
25
|
+
* @param {object} opts.source - The source object providing the log messages.
|
26
|
+
* @param {string} opts.resolver - The name of the field resolver for log messages (default: derived from the topic).
|
27
|
+
*/
|
6
28
|
constructor(opts: any);
|
29
|
+
/**
|
30
|
+
* Publishes a log message to the configured Pub/Sub topic.
|
31
|
+
* @param {object} info - The log message information.
|
32
|
+
* @param {Function} callback - The callback function to be called after publishing the message.
|
33
|
+
*/
|
7
34
|
log(info: any, callback: any): void;
|
8
35
|
}
|
@@ -5,13 +5,28 @@ const tslib_1 = require("tslib");
|
|
5
5
|
const camelCase_1 = tslib_1.__importDefault(require("lodash/camelCase"));
|
6
6
|
const winston_transport_1 = tslib_1.__importDefault(require("winston-transport"));
|
7
7
|
const pubsub_1 = require("./pubsub");
|
8
|
+
/**
|
9
|
+
* PubSubLogTransport is a custom Winston transport that publishes log messages to a GraphQL Pub/Sub topic.
|
10
|
+
*/
|
8
11
|
class PubSubLogTransport extends winston_transport_1.default {
|
12
|
+
/**
|
13
|
+
* Creates an instance of PubSubLogTransport.
|
14
|
+
* @param {object} opts - Options for configuring the transport.
|
15
|
+
* @param {string} opts.topic - The Pub/Sub topic to which log messages will be published.
|
16
|
+
* @param {object} opts.source - The source object providing the log messages.
|
17
|
+
* @param {string} opts.resolver - The name of the field resolver for log messages (default: derived from the topic).
|
18
|
+
*/
|
9
19
|
constructor(opts) {
|
10
20
|
super(opts);
|
11
21
|
this.topic = opts.topic;
|
12
22
|
this.source = opts.source;
|
13
23
|
this.resolver = opts.resolver || (0, camelCase_1.default)(this.topic);
|
14
24
|
}
|
25
|
+
/**
|
26
|
+
* Publishes a log message to the configured Pub/Sub topic.
|
27
|
+
* @param {object} info - The log message information.
|
28
|
+
* @param {Function} callback - The callback function to be called after publishing the message.
|
29
|
+
*/
|
15
30
|
log(info, callback) {
|
16
31
|
setImmediate(() => {
|
17
32
|
pubsub_1.pubsub.publish(this.topic, {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"pubsub-log-transport.js","sourceRoot":"","sources":["../server/pubsub-log-transport.ts"],"names":[],"mappings":";;;;AAAA,yEAAwC;AACxC,kFAAyC;AACzC,qCAAiC;AAEjC,MAAa,kBAAmB,SAAQ,2BAAS;
|
1
|
+
{"version":3,"file":"pubsub-log-transport.js","sourceRoot":"","sources":["../server/pubsub-log-transport.ts"],"names":[],"mappings":";;;;AAAA,yEAAwC;AACxC,kFAAyC;AACzC,qCAAiC;AAEjC;;GAEG;AACH,MAAa,kBAAmB,SAAQ,2BAAS;IAmB/C;;;;;;OAMG;IACH,YAAY,IAAI;QACd,KAAK,CAAC,IAAI,CAAC,CAAA;QAEX,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAA;QACvB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;QACzB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAA,mBAAS,EAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACxD,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,IAAI,EAAE,QAAQ;QAChB,YAAY,CAAC,GAAG,EAAE;YAChB,eAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE;gBACzB,CAAC,IAAI,CAAC,QAAQ,CAAC,kBACb,MAAM,EAAE,IAAI,CAAC,MAAM,IAChB,IAAI,CACR;aACF,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QAEF,QAAQ,EAAE,CAAA;IACZ,CAAC;CACF;AAnDD,gDAmDC","sourcesContent":["import camelCase from 'lodash/camelCase'\nimport Transport from 'winston-transport'\nimport { pubsub } from './pubsub'\n\n/**\n * PubSubLogTransport is a custom Winston transport that publishes log messages to a GraphQL Pub/Sub topic.\n */\nexport class PubSubLogTransport extends Transport {\n /**\n * The source object providing the log messages.\n * @type {object}\n */\n source: object\n\n /**\n * The Pub/Sub topic to which log messages will be published.\n * @type {string}\n */\n topic: string\n\n /**\n * The name of the field resolver for log messages.\n * @type {string}\n */\n resolver: string /* field resolver name */\n\n /**\n * Creates an instance of PubSubLogTransport.\n * @param {object} opts - Options for configuring the transport.\n * @param {string} opts.topic - The Pub/Sub topic to which log messages will be published.\n * @param {object} opts.source - The source object providing the log messages.\n * @param {string} opts.resolver - The name of the field resolver for log messages (default: derived from the topic).\n */\n constructor(opts) {\n super(opts)\n\n this.topic = opts.topic\n this.source = opts.source\n this.resolver = opts.resolver || camelCase(this.topic)\n }\n\n /**\n * Publishes a log message to the configured Pub/Sub topic.\n * @param {object} info - The log message information.\n * @param {Function} callback - The callback function to be called after publishing the message.\n */\n log(info, callback) {\n setImmediate(() => {\n pubsub.publish(this.topic, {\n [this.resolver]: {\n source: this.source,\n ...info\n }\n })\n })\n\n callback()\n }\n}\n"]}
|
package/dist-server/pubsub.d.ts
CHANGED
@@ -1,2 +1,10 @@
|
|
1
|
-
|
1
|
+
/**
|
2
|
+
* @module pubsub
|
3
|
+
* @description
|
4
|
+
* This module provides a Pub/Sub (Publish/Subscribe) mechanism for handling messages and events.
|
5
|
+
* Developers can use various middleware options such as MQTT, Redis, Redis Cluster, or Kafka
|
6
|
+
* to implement Pub/Sub functionality.
|
7
|
+
*/
|
8
|
+
import { PubSub } from 'type-graphql';
|
9
|
+
declare let pubsub: PubSub;
|
2
10
|
export { pubsub };
|
package/dist-server/pubsub.js
CHANGED
@@ -1,10 +1,17 @@
|
|
1
1
|
"use strict";
|
2
|
+
/**
|
3
|
+
* @module pubsub
|
4
|
+
* @description
|
5
|
+
* This module provides a Pub/Sub (Publish/Subscribe) mechanism for handling messages and events.
|
6
|
+
* Developers can use various middleware options such as MQTT, Redis, Redis Cluster, or Kafka
|
7
|
+
* to implement Pub/Sub functionality.
|
8
|
+
*/
|
2
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
10
|
exports.pubsub = void 0;
|
4
11
|
const tslib_1 = require("tslib");
|
5
12
|
const graphql_mqtt_subscriptions_1 = require("graphql-mqtt-subscriptions");
|
6
13
|
const graphql_redis_subscriptions_1 = require("graphql-redis-subscriptions");
|
7
|
-
const
|
14
|
+
const graphql_yoga_1 = require("graphql-yoga");
|
8
15
|
const ioredis_1 = tslib_1.__importDefault(require("ioredis"));
|
9
16
|
const mqtt_1 = require("mqtt");
|
10
17
|
const env_1 = require("@things-factory/env");
|
@@ -13,6 +20,7 @@ let pubsub;
|
|
13
20
|
exports.pubsub = pubsub;
|
14
21
|
switch (middleware) {
|
15
22
|
case 'mqtt':
|
23
|
+
//@ts-ignore
|
16
24
|
exports.pubsub = pubsub = new graphql_mqtt_subscriptions_1.MQTTPubSub({
|
17
25
|
client: (0, mqtt_1.connect)('mqtt://' + host, Object.assign({ reconnectPeriod: 1000 }, options))
|
18
26
|
});
|
@@ -23,6 +31,7 @@ switch (middleware) {
|
|
23
31
|
// reconnect after
|
24
32
|
return Math.min(times * 50, 2000);
|
25
33
|
} }, options);
|
34
|
+
//@ts-ignore
|
26
35
|
exports.pubsub = pubsub = new graphql_redis_subscriptions_1.RedisPubSub({
|
27
36
|
publisher: new ioredis_1.default(redisOption),
|
28
37
|
subscriber: new ioredis_1.default(redisOption)
|
@@ -30,6 +39,7 @@ switch (middleware) {
|
|
30
39
|
break;
|
31
40
|
case 'redisCluster':
|
32
41
|
const cluster = new ioredis_1.default.Cluster(nodes, options);
|
42
|
+
//@ts-ignore
|
33
43
|
exports.pubsub = pubsub = new graphql_redis_subscriptions_1.RedisPubSub({
|
34
44
|
publisher: cluster,
|
35
45
|
subscriber: cluster
|
@@ -51,13 +61,15 @@ switch (middleware) {
|
|
51
61
|
}
|
52
62
|
break;
|
53
63
|
default:
|
54
|
-
exports.pubsub = pubsub =
|
64
|
+
exports.pubsub = pubsub = (0, graphql_yoga_1.createPubSub)();
|
55
65
|
break;
|
56
66
|
}
|
57
67
|
// kafka pubsub keeps connection and app port with 'ctrl+c' termination.
|
58
68
|
const exitHandler = async (evt) => {
|
69
|
+
//@ts-ignore
|
59
70
|
if (pubsub.close) {
|
60
71
|
try {
|
72
|
+
//@ts-ignore
|
61
73
|
await pubsub.close();
|
62
74
|
}
|
63
75
|
catch (err) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"pubsub.js","sourceRoot":"","sources":["../server/pubsub.ts"],"names":[],"mappings":";;;;
|
1
|
+
{"version":3,"file":"pubsub.js","sourceRoot":"","sources":["../server/pubsub.ts"],"names":[],"mappings":";AAAA;;;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AAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA","sourcesContent":["/**\n * @module pubsub\n * @description\n * This module provides a Pub/Sub (Publish/Subscribe) mechanism for handling messages and events.\n * Developers can use various middleware options such as MQTT, Redis, Redis Cluster, or Kafka\n * to implement Pub/Sub functionality.\n */\n\nimport { MQTTPubSub } from 'graphql-mqtt-subscriptions'\nimport { RedisPubSub } from 'graphql-redis-subscriptions'\nimport { createPubSub } from 'graphql-yoga'\nimport Redis from 'ioredis'\nimport { connect } from 'mqtt'\n\nimport { config, logger } from '@things-factory/env'\nimport { PubSub } from 'type-graphql'\n\nconst { middleware, host, port, nodes, topic, options } = config.get('pubsub', {})\n\nlet pubsub: PubSub\n\nswitch (middleware) {\n case 'mqtt':\n //@ts-ignore\n pubsub = new MQTTPubSub({\n client: connect('mqtt://' + host, {\n reconnectPeriod: 1000,\n ...options\n }) as any\n })\n break\n case 'redis':\n const redisOption = {\n host,\n port,\n retryStrategy: times => {\n // reconnect after\n return Math.min(times * 50, 2000)\n },\n ...options\n }\n //@ts-ignore\n pubsub = new RedisPubSub({\n publisher: new Redis(redisOption),\n subscriber: new Redis(redisOption)\n })\n break\n case 'redisCluster':\n const cluster = new Redis.Cluster(nodes, options)\n //@ts-ignore\n pubsub = new RedisPubSub({\n publisher: cluster,\n subscriber: cluster\n })\n break\n case 'kafka':\n try {\n /*\n * https://github.com/hatiolab/things-factory/issues/1239\n */\n const { KafkaPubSub } = require('graphql-kafka-subscriptions')\n pubsub = new KafkaPubSub({\n topic,\n host,\n port,\n ...options\n })\n } catch (e) {\n logger.error('graphql-kafka-subscriptions module is not installed, so application can not go further.')\n throw e\n }\n break\n default:\n pubsub = createPubSub()\n break\n}\n\n// kafka pubsub keeps connection and app port with 'ctrl+c' termination.\nconst exitHandler = async evt => {\n //@ts-ignore\n if (pubsub.close) {\n try {\n //@ts-ignore\n await pubsub.close()\n } catch (err) {\n logger.error(err)\n }\n }\n}\n\n/*\n * exit events hint from https://stackoverflow.com/a/14032965/14539284\n */\n\n//do something when app is closing\nprocess.on('exit', exitHandler.bind(null, { name: 'exit', exit: true }))\n\n//catches ctrl+c event\nprocess.on('SIGINT', exitHandler.bind(null, { name: 'SIGINT', exit: true }))\n\n// catches \"kill pid\" (for example: nodemon restart)\nprocess.on('SIGUSR1', exitHandler.bind(null, { name: 'SIGUSR1', exit: true }))\nprocess.on('SIGUSR2', exitHandler.bind(null, { name: 'SIGUSR2', exit: true }))\n\n//catches uncaught exceptions\n// process.on('uncaughtException', exitHandler.bind(null, { name: 'uncaughtException', exit: true }))\n\nexport { pubsub }\n"]}
|
package/dist-server/schema.d.ts
CHANGED
package/dist-server/schema.js
CHANGED
@@ -7,7 +7,12 @@ const graphql_scalars_1 = require("graphql-scalars");
|
|
7
7
|
const schema_1 = require("@graphql-tools/schema");
|
8
8
|
const env_1 = require("@things-factory/env");
|
9
9
|
const utils_1 = require("@things-factory/utils");
|
10
|
+
const pubsub_1 = require("./pubsub");
|
10
11
|
const path = require('path');
|
12
|
+
/**
|
13
|
+
* Generates and returns a GraphQL schema by merging schemas and resolvers from various modules.
|
14
|
+
* @returns {GraphQLSchema} The merged GraphQL schema.
|
15
|
+
*/
|
11
16
|
async function schema() {
|
12
17
|
const schemas = env_1.orderedModuleNames
|
13
18
|
.map(dep => (0, env_1.loader)(dep).schema)
|
@@ -46,9 +51,7 @@ async function schema() {
|
|
46
51
|
const defs = {
|
47
52
|
query: queries.length > 0 ? ['type Query {', ...queries, '}'].join('\n') : 'type Query { _ : Boolean }',
|
48
53
|
mutation: mutations.length > 0 ? ['type Mutation {', ...mutations, '}'].join('\n') : 'type Mutation { _ : Boolean }',
|
49
|
-
subscription: subscriptions.length > 0
|
50
|
-
? ['type Subscription {', ...subscriptions, '}'].join('\n')
|
51
|
-
: 'type Subscription { _ : Boolean }'
|
54
|
+
subscription: subscriptions.length > 0 ? ['type Subscription {', ...subscriptions, '}'].join('\n') : 'type Subscription { _ : Boolean }'
|
52
55
|
};
|
53
56
|
typeDefs = [
|
54
57
|
...graphql_scalars_1.typeDefs,
|
@@ -96,6 +99,7 @@ async function schema() {
|
|
96
99
|
var merged = (0, schema_1.mergeSchemas)({
|
97
100
|
schemas: [
|
98
101
|
await (0, type_graphql_1.buildSchema)({
|
102
|
+
pubSub: pubsub_1.pubsub,
|
99
103
|
resolvers: schemas.resolverClasses,
|
100
104
|
// automatically create `schema.gql` file with schema definition
|
101
105
|
// in project's working directory
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../server/schema.ts"],"names":[],"mappings":";;;AACA,sEAA+D;AAC/D,+CAA0C;AAC1C,qDAA0F;AAE1F,kDAAoD;AACpD,6CAAgE;AAChE,iDAAiD;
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../server/schema.ts"],"names":[],"mappings":";;;AACA,sEAA+D;AAC/D,+CAA0C;AAC1C,qDAA0F;AAE1F,kDAAoD;AACpD,6CAAgE;AAChE,iDAAiD;AACjD,qCAAiC;AAEjC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAE5B;;;GAGG;AACI,KAAK,UAAU,MAAM;IAC1B,MAAM,OAAO,GAAG,wBAAkB;SAC/B,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,IAAA,YAAM,EAAC,GAAG,CAAC,CAAC,MAAM,CAAC;SAC9B,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC;SACxB,MAAM,CACL,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;QACd,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,GAAG,GAAG,CAAA;QAChE,IAAI,EAAE,QAAQ,EAAE,SAAS,GAAG,EAAE,EAAE,SAAS,EAAE,UAAU,GAAG,EAAE,EAAE,eAAe,EAAE,gBAAgB,GAAG,EAAE,EAAE,UAAU,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,MAAM,CAAA;QAE3I,OAAO;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;IAE1B,SAAS,iCACP,MAAM,EAAE,gCAAoB,EAC5B,KAAK,EAAE,IAAA,iBAAS,EAAC,KAAK,EAAE,cAAc,CAAC,EACvC,QAAQ,EAAE,IAAA,iBAAS,EAAC,QAAQ,EAAE,iBAAiB,CAAC,EAChD,YAAY,EAAE,IAAA,iBAAS,EAAC,YAAY,EAAE,qBAAqB,CAAC,IACzD,2BAAe,GACf,SAAS,CACb,CAAA;IAED,IAAI,MAAM,GAAG,IAAA,qBAAY,EAAC;QACxB,OAAO,EAAE;YACP,MAAM,IAAA,0BAAW,EAAC;gBAChB,MAAM,EAAE,eAAM;gBACd,SAAS,EAAE,OAAO,CAAC,eAAe;gBAClC,gEAAgE;gBAChE,iCAAiC;gBACjC,kDAAkD;gBAClD,cAAc,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa;gBACrD,4EAA4E;aAC7E,CAAC;SACH;QACD,QAAQ;QACR,SAAS;KACV,CAAC,CAAA;IAEF,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,SAAwC,EAAE,EAAE;QACjF,MAAM,GAAG,SAAS,CAAC,MAAM,CAAQ,CAAA;IACnC,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC;AAlJD,wBAkJC","sourcesContent":["import { GraphQLSchema } from 'graphql'\nimport { GraphQLUpload } from 'graphql-upload/GraphQLUpload.js'\nimport { buildSchema } from 'type-graphql'\nimport { typeDefs as scalarTypeDefs, resolvers as scalarResolvers } from 'graphql-scalars'\n\nimport { mergeSchemas } from '@graphql-tools/schema'\nimport { loader, orderedModuleNames } from '@things-factory/env'\nimport { deepMerge } from '@things-factory/utils'\nimport { pubsub } from './pubsub'\n\nconst path = require('path')\n\n/**\n * Generates and returns a GraphQL schema by merging schemas and resolvers from various modules.\n * @returns {GraphQLSchema} The merged GraphQL schema.\n */\nexport async function schema() {\n const schemas = orderedModuleNames\n .map(dep => loader(dep).schema)\n .filter(schema => schema)\n .reduce(\n (sum, schema) => {\n const { typeDefs, resolvers, resolverClasses, directives } = sum\n let { typeDefs: sTypeDefs = {}, resolvers: sResolvers = {}, resolverClasses: sResolverClasses = [], directives: sDirectives = {} } = schema\n\n return {\n typeDefs: deepMerge(typeDefs, sTypeDefs),\n resolvers: deepMerge(resolvers, sResolvers),\n resolverClasses: [...resolverClasses, ...(sResolverClasses || [])],\n directives: deepMerge(directives, sDirectives)\n }\n },\n {\n typeDefs: {},\n resolvers: {},\n resolverClasses: [],\n directives: {}\n }\n )\n\n /* for typeDefs */\n var typeDefs = schemas.typeDefs\n var { queries = [], mutations = [], subscriptions = [], directives = [], types = [] } = typeDefs\n\n queries = [...queries, ...(typeDefs.Query || [])]\n mutations = [...mutations, ...(typeDefs.Mutation || [])]\n subscriptions = [...subscriptions, ...(typeDefs.Subscription || [])]\n directives = [...directives, ...(typeDefs.Directive || [])]\n\n delete typeDefs.Query\n delete typeDefs.Mutation\n delete typeDefs.Subscription\n delete typeDefs.Directive\n\n delete typeDefs.queries\n delete typeDefs.mutations\n delete typeDefs.subscriptions\n delete typeDefs.directives\n delete typeDefs.types\n\n const defs = {\n query: queries.length > 0 ? ['type Query {', ...queries, '}'].join('\\n') : 'type Query { _ : Boolean }',\n mutation: mutations.length > 0 ? ['type Mutation {', ...mutations, '}'].join('\\n') : 'type Mutation { _ : Boolean }',\n subscription: subscriptions.length > 0 ? ['type Subscription {', ...subscriptions, '}'].join('\\n') : 'type Subscription { _ : Boolean }'\n }\n\n typeDefs = [\n ...scalarTypeDefs,\n `\n scalar Upload\n `,\n defs.query,\n defs.mutation,\n defs.subscription,\n ...directives,\n ...types,\n ...Object.values(typeDefs)\n ].filter(type => !!type)\n\n /* for resolvers */\n var { resolvers } = schemas\n var { queries = [], mutations = [], subscriptions = [], directives = [] } = resolvers\n\n var queryResolvers =\n queries.length > 0 &&\n queries.reduce((sum, query) => {\n return {\n ...sum,\n ...query\n }\n }, {})\n\n var mutationResolvers =\n mutations.length > 0 &&\n mutations.reduce((sum, mutation) => {\n return {\n ...sum,\n ...mutation\n }\n }, {})\n\n var subscriptionResolvers =\n subscriptions.length > 0 &&\n subscriptions.reduce((sum, subscription) => {\n return {\n ...sum,\n ...subscription\n }\n }, {})\n\n var directiveResolvers = directives.reduce((sum, directive) => {\n return {\n ...sum,\n ...directive\n }\n }, {})\n\n delete resolvers.queries\n delete resolvers.mutations\n delete resolvers.subscriptions\n delete resolvers.directives\n\n var Query = resolvers.Query || {}\n var Mutation = resolvers.Mutation || {}\n var Subscription = resolvers.Subscription || {}\n var Directive = resolvers.Directive || {}\n\n delete resolvers.Query\n delete resolvers.Mutation\n delete resolvers.Subscription\n delete resolvers.Directive\n\n resolvers = {\n Upload: GraphQLUpload as any,\n Query: deepMerge(Query, queryResolvers),\n Mutation: deepMerge(Mutation, mutationResolvers),\n Subscription: deepMerge(Subscription, subscriptionResolvers),\n ...scalarResolvers,\n ...resolvers\n }\n\n var merged = mergeSchemas({\n schemas: [\n await buildSchema({\n pubSub: pubsub,\n resolvers: schemas.resolverClasses,\n // automatically create `schema.gql` file with schema definition\n // in project's working directory\n // or create the file with schema in selected path\n emitSchemaFile: process.env.NODE_ENV == 'development'\n // emitSchemaFile: path.resolve(__dirname, 'snapshots/schema', 'schema.gql')\n })\n ],\n typeDefs,\n resolvers\n })\n\n Object.values(schemas.directives).map((directive: (schema: GraphQLSchema) => {}) => {\n merged = directive(merged) as any\n })\n\n return merged\n}\n"]}
|
@@ -2,7 +2,7 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.DataResolver = void 0;
|
4
4
|
const tslib_1 = require("tslib");
|
5
|
-
const
|
5
|
+
const graphql_yoga_1 = require("graphql-yoga");
|
6
6
|
const type_graphql_1 = require("type-graphql");
|
7
7
|
const pubsub_1 = require("../../pubsub");
|
8
8
|
const data_types_1 = require("./data-types");
|
@@ -13,7 +13,7 @@ let DataResolver = class DataResolver {
|
|
13
13
|
};
|
14
14
|
tslib_1.__decorate([
|
15
15
|
(0, type_graphql_1.Subscription)({
|
16
|
-
subscribe: (
|
16
|
+
subscribe: ({ args, context, info }) => {
|
17
17
|
var _a;
|
18
18
|
const { domain, user } = context.state;
|
19
19
|
const { tag } = args;
|
@@ -25,16 +25,10 @@ tslib_1.__decorate([
|
|
25
25
|
if (!((_a = user.domains) === null || _a === void 0 ? void 0 : _a.find(d => d.subdomain === subdomain)) && !process.superUserGranted(domain, user)) {
|
26
26
|
throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`);
|
27
27
|
}
|
28
|
-
return (0,
|
29
|
-
const { domain: pdomain, tag } = payload.data;
|
30
|
-
|
31
|
-
|
32
|
-
}
|
33
|
-
if (subdomain !== (pdomain === null || pdomain === void 0 ? void 0 : pdomain.subdomain)) {
|
34
|
-
return false;
|
35
|
-
}
|
36
|
-
return true;
|
37
|
-
})(_, args, context, info);
|
28
|
+
return (0, graphql_yoga_1.pipe)(pubsub_1.pubsub.subscribe('data'), (0, graphql_yoga_1.filter)((payload) => {
|
29
|
+
const { domain: pdomain, tag: ptag, data } = payload.data;
|
30
|
+
return tag === ptag && subdomain === (pdomain === null || pdomain === void 0 ? void 0 : pdomain.subdomain);
|
31
|
+
}));
|
38
32
|
}
|
39
33
|
}),
|
40
34
|
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"data-resolver.js","sourceRoot":"","sources":["../../../server/service/subscription-data/data-resolver.ts"],"names":[],"mappings":";;;;AAAA
|
1
|
+
{"version":3,"file":"data-resolver.js","sourceRoot":"","sources":["../../../server/service/subscription-data/data-resolver.ts"],"names":[],"mappings":";;;;AAAA,+CAA2C;AAC3C,+CAAgE;AAEhE,yCAAqC;AACrC,6CAAmC;AAG5B,IAAM,YAAY,GAAlB,MAAM,YAAY;IAyBvB,IAAI,CAAS,OAAuB,EAAc,GAAW;QAC3D,OAAO,OAAO,CAAC,IAAI,CAAA;IACrB,C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A3BU,YAAY;IADxB,IAAA,uBAAQ,GAAE;GACE,YAAY,CA4BxB;AA5BY,oCAAY","sourcesContent":["import { filter, pipe } from 'graphql-yoga'\nimport { Arg, Resolver, Root, Subscription } from 'type-graphql'\n\nimport { pubsub } from '../../pubsub'\nimport { Data } from './data-types'\n\n@Resolver()\nexport class DataResolver {\n @Subscription({\n subscribe: ({ args, context, info }) => {\n const { domain, user } = context.state\n const { tag } = args\n const subdomain = domain?.subdomain\n\n if (!domain || !tag) {\n throw new Error('domain and tag required')\n }\n\n //@ts-ignore\n if (!user.domains?.find(d => d.subdomain === subdomain) && !process.superUserGranted(domain, user)) {\n throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`)\n }\n\n return pipe(\n pubsub.subscribe('data'),\n filter((payload: { data: Data }) => {\n const { domain: pdomain, tag: ptag, data } = payload.data\n return tag === ptag && subdomain === pdomain?.subdomain\n })\n )\n }\n })\n data(@Root() payload: { data: Data }, @Arg('tag') tag: string): Data {\n return payload.data\n }\n}\n"]}
|