@things-factory/integration-base 10.0.0-beta.95 → 10.0.0-zeta.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/service/connection/connection-subscription.js +4 -4
- package/dist-server/service/connection/connection-subscription.js.map +1 -1
- package/dist-server/service/scenario-instance/scenario-instance-subscription.js +4 -4
- package/dist-server/service/scenario-instance/scenario-instance-subscription.js.map +1 -1
- package/dist-server/service/scenario-queue/scenario-queue-subscription.js +2 -2
- package/dist-server/service/scenario-queue/scenario-queue-subscription.js.map +1 -1
- package/dist-server/service/state-register/data-resolver.js +4 -3
- package/dist-server/service/state-register/data-resolver.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
|
@@ -23,7 +23,7 @@ exports.ConnectionSubscription = ConnectionSubscription;
|
|
|
23
23
|
tslib_1.__decorate([
|
|
24
24
|
(0, type_graphql_1.Subscription)({
|
|
25
25
|
description: 'Subscribes to the state changes of connections.',
|
|
26
|
-
subscribe: ({ args, context, info }) => {
|
|
26
|
+
subscribe: async ({ args, context, info }) => {
|
|
27
27
|
const { domain, user } = context.state;
|
|
28
28
|
const { name } = args;
|
|
29
29
|
const subdomain = domain?.subdomain;
|
|
@@ -31,7 +31,7 @@ tslib_1.__decorate([
|
|
|
31
31
|
if (!domain) {
|
|
32
32
|
throw new Error('domain required.');
|
|
33
33
|
}
|
|
34
|
-
if (!user.domains?.find(d => d.subdomain === subdomain) && !process.superUserGranted(domain, user)) {
|
|
34
|
+
if (!user.domains?.find(d => d.subdomain === subdomain) && !(await process.superUserGranted(domain, user))) {
|
|
35
35
|
throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`);
|
|
36
36
|
}
|
|
37
37
|
// ancestor 도메인 ids 를 한 번만 계산하여 재사용 (subscribe 는 sync 라 lazy memoize)
|
|
@@ -76,7 +76,7 @@ tslib_1.__decorate([
|
|
|
76
76
|
tslib_1.__decorate([
|
|
77
77
|
(0, type_graphql_1.Subscription)({
|
|
78
78
|
description: 'Subscribes to log messages from connections.',
|
|
79
|
-
subscribe: ({ args, context, info }) => {
|
|
79
|
+
subscribe: async ({ args, context, info }) => {
|
|
80
80
|
const { domain, user } = context.state;
|
|
81
81
|
const { level } = args;
|
|
82
82
|
const subdomain = domain?.subdomain;
|
|
@@ -84,7 +84,7 @@ tslib_1.__decorate([
|
|
|
84
84
|
if (!domain) {
|
|
85
85
|
throw new Error('domain required');
|
|
86
86
|
}
|
|
87
|
-
if (!user.domains?.find(d => d.subdomain === subdomain) && !process.superUserGranted(domain, user)) {
|
|
87
|
+
if (!user.domains?.find(d => d.subdomain === subdomain) && !(await process.superUserGranted(domain, user))) {
|
|
88
88
|
throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`);
|
|
89
89
|
}
|
|
90
90
|
return (0, graphql_yoga_1.pipe)(shell_1.pubsub.subscribe('connection-log'), (0, graphql_yoga_1.filter)(async (payload) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-subscription.js","sourceRoot":"","sources":["../../../server/service/connection/connection-subscription.ts"],"names":[],"mappings":";;;;AAAA,+CAA2C;AAC3C,+CAAgE;AAChE,qCAA4B;AAE5B,iDAAkE;AAElE,wEAAmE;AACnE,6CAA2D;AAC3D,uDAAmD;AACnD,uEAA0E;AAE1E,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,oDAAoD,CAAC,CAAA;AAG7E,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IA2DjC,eAAe,CACL,OAA6C,EACpB,IAAY;QAE7C,OAAO,OAAO,CAAC,eAAe,CAAA;IAChC,CAAC;IAwCD,aAAa,CAAS,OAAqB,EAAoC,KAAa;QAC1F,OAAO,OAAO,CAAC,GAAG,CAAA;IACpB,CAAC;CACF,CAAA;AA3GY,wDAAsB;AA2DjC;IA1DC,IAAA,2BAAY,EAAC;QACZ,WAAW,EAAE,iDAAiD;QAC9D,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"connection-subscription.js","sourceRoot":"","sources":["../../../server/service/connection/connection-subscription.ts"],"names":[],"mappings":";;;;AAAA,+CAA2C;AAC3C,+CAAgE;AAChE,qCAA4B;AAE5B,iDAAkE;AAElE,wEAAmE;AACnE,6CAA2D;AAC3D,uDAAmD;AACnD,uEAA0E;AAE1E,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,oDAAoD,CAAC,CAAA;AAG7E,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IA2DjC,eAAe,CACL,OAA6C,EACpB,IAAY;QAE7C,OAAO,OAAO,CAAC,eAAe,CAAA;IAChC,CAAC;IAwCD,aAAa,CAAS,OAAqB,EAAoC,KAAa;QAC1F,OAAO,OAAO,CAAC,GAAG,CAAA;IACpB,CAAC;CACF,CAAA;AA3GY,wDAAsB;AA2DjC;IA1DC,IAAA,2BAAY,EAAC;QACZ,WAAW,EAAE,iDAAiD;QAC9D,SAAS,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE;YAC3C,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;YACtC,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAA;YACrB,MAAM,SAAS,GAAG,MAAM,EAAE,SAAS,CAAA;YAEnC,KAAK,CAAC,WAAW,EAAE,SAAS,CAAC,CAAA;YAC7B,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAA;YACrC,CAAC;YAED,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,SAAS,CAAC,IAAI,CAAC,CAAC,MAAM,OAAO,CAAC,gBAAgB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC;gBAC3G,MAAM,IAAI,KA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C,KAAK,IAAI,CAAC,CAAA;YACjF,CAAC;YAED,OAAO,IAAA,mBAAI,EACT,cAAM,CAAC,SAAS,CAAC,gBAAgB,CAAC,EAClC,IAAA,qBAAM,EAAC,KAAK,EAAE,OAAqB,EAAE,EAAE;gBACrC,gCAAgC;gBAChC,MAAM,EAAE,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAA;gBACnD,qCAAqC;gBAErC,0CAA0C;gBAC1C,iBAAiB;gBACjB,IAAI;gBAEJ,IAAI,KAAK,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;oBAC9B,OAAO,KAAK,CAAA;gBACd,CAAC;gBAED,OAAO,IAAI,CAAA;YACb,CAAC,CAAC,CACH,CAAA;QACH,CAAC;KACF,CAAC;IACa,mBAAA,IAAA,mBAAI,GAAE,CAAA;IAAyB,mBAAA,IAAA,kBAAG,EAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;;;4CAAiB,WAAG;2DAEjG;iCA1GU,sBAAsB;IADlC,IAAA,uBAAQ,EAAC,uBAAU,CAAC;GACR,sBAAsB,CA2GlC","sourcesContent":["import { filter, pipe } from 'graphql-yoga'\nimport { Arg, Resolver, Root, Subscription } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { getRepository, Log, pubsub } from '@things-factory/shell'\n\nimport { ConnectionManager } from '../../engine/connection-manager'\nimport { Connection, ConnectionStatus } from './connection'\nimport { ConnectionState } from './connection-type'\nimport { getDomainIdsWithAncestors } from '../../utils/domain-inheritance'\n\nconst debug = require('debug')('things-factory:integration:connection-subscription')\n\n@Resolver(Connection)\nexport class ConnectionSubscription {\n @Subscription({\n description: 'Subscribes to the state changes of connections.',\n subscribe: async ({ args, context, info }) => {\n const { domain, user } = context.state\n const { name } = args\n const subdomain = domain?.subdomain\n\n debug('subscribe', subdomain)\n if (!domain) {\n throw new Error('domain required.')\n }\n\n if (!user.domains?.find(d => d.subdomain === subdomain) && !(await process.superUserGranted(domain, user))) {\n throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`)\n }\n\n // ancestor 도메인 ids 를 한 번만 계산하여 재사용 (subscribe 는 sync 라 lazy memoize)\n let ancestorIdsPromise: Promise<string[]> | null = null\n const resolveAncestorIds = () =>\n (ancestorIdsPromise ||= getDomainIdsWithAncestors(domain))\n\n process.nextTick(async () => {\n const domainIds = await resolveAncestorIds()\n var where: any = { domain: { id: In(domainIds) } }\n if (name) {\n where['name'] = name\n }\n\n var connections = await getRepository(Connection).find({\n where,\n relations: ['domain', 'edge']\n })\n\n connections.forEach(connection => {\n pubsub.publish('connection-state', {\n connectionState: {\n ...connection,\n domain /* 상속 및 on-demand 연결에서 connection.domain 과 다를 수 있음 */,\n state: ConnectionManager.getConnectionInstance(connection)\n ? ConnectionStatus.CONNECTED\n : ConnectionStatus.DISCONNECTED,\n timestamp: new Date()\n }\n })\n })\n })\n\n return pipe(\n pubsub.subscribe('connection-state'),\n filter(async (payload: { connectionState: ConnectionState }) => {\n const { domain: pdomain, name: pname } = payload.connectionState\n const domainIds = await resolveAncestorIds()\n\n return (!name || name === pname) && domainIds.includes(pdomain?.id)\n })\n )\n }\n })\n connectionState(\n @Root() payload: { connectionState: ConnectionState },\n @Arg('name', { nullable: true }) name: string\n ): ConnectionState {\n return payload.connectionState\n }\n\n @Subscription({\n description: 'Subscribes to log messages from connections.',\n subscribe: async ({ args, context, info }) => {\n const { domain, user } = context.state\n const { level } = args\n\n const subdomain = domain?.subdomain\n\n debug('subscribe', subdomain)\n\n if (!domain) {\n throw new Error('domain required')\n }\n\n if (!user.domains?.find(d => d.subdomain === subdomain) && !(await 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('connection-log'),\n filter(async (payload: { log: Log }) => {\n // TODO support domain filtering\n const { /* source, */ level: plevel } = payload.log\n // const { domain: pdomain } = source\n\n // if (subdomain !== pdomain?.subdomain) {\n // return false\n // }\n\n if (level && level !== plevel) {\n return false\n }\n\n return true\n })\n )\n }\n })\n connectionLog(@Root() payload: { log: Log }, @Arg('level', { nullable: true }) level: string): Log {\n return payload.log\n }\n}\n"]}
|
|
@@ -20,7 +20,7 @@ exports.ScenarioInstanceSubscription = ScenarioInstanceSubscription;
|
|
|
20
20
|
tslib_1.__decorate([
|
|
21
21
|
(0, type_graphql_1.Subscription)({
|
|
22
22
|
description: 'Subscribes to log messages from scenario instances.',
|
|
23
|
-
subscribe: ({ args, context, info }) => {
|
|
23
|
+
subscribe: async ({ args, context, info }) => {
|
|
24
24
|
const { domain, user } = context.state;
|
|
25
25
|
const { instanceName, scenarioName, level } = args;
|
|
26
26
|
const subdomain = domain?.subdomain;
|
|
@@ -28,7 +28,7 @@ tslib_1.__decorate([
|
|
|
28
28
|
if (!domain) {
|
|
29
29
|
throw new Error('domain required');
|
|
30
30
|
}
|
|
31
|
-
if (!user.domains?.find(d => d.subdomain === subdomain) && !process.superUserGranted(domain, user)) {
|
|
31
|
+
if (!user.domains?.find(d => d.subdomain === subdomain) && !(await process.superUserGranted(domain, user))) {
|
|
32
32
|
throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`);
|
|
33
33
|
}
|
|
34
34
|
return (0, graphql_yoga_1.pipe)(shell_1.pubsub.subscribe('scenario-instance-log'), (0, graphql_yoga_1.filter)((payload) => {
|
|
@@ -61,7 +61,7 @@ tslib_1.__decorate([
|
|
|
61
61
|
tslib_1.__decorate([
|
|
62
62
|
(0, type_graphql_1.Subscription)({
|
|
63
63
|
description: 'Subscribes to state changes from scenario instances.',
|
|
64
|
-
subscribe: ({ args, context, info }) => {
|
|
64
|
+
subscribe: async ({ args, context, info }) => {
|
|
65
65
|
const { domain, user } = context.state;
|
|
66
66
|
const { instanceName, scenarioName } = args;
|
|
67
67
|
const subdomain = domain?.subdomain;
|
|
@@ -69,7 +69,7 @@ tslib_1.__decorate([
|
|
|
69
69
|
if (!domain) {
|
|
70
70
|
throw new Error('domain required');
|
|
71
71
|
}
|
|
72
|
-
if (!user.domains?.find(d => d.subdomain === subdomain) && !process.superUserGranted(domain, user)) {
|
|
72
|
+
if (!user.domains?.find(d => d.subdomain === subdomain) && !(await process.superUserGranted(domain, user))) {
|
|
73
73
|
throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`);
|
|
74
74
|
}
|
|
75
75
|
process.nextTick(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scenario-instance-subscription.js","sourceRoot":"","sources":["../../../server/service/scenario-instance/scenario-instance-subscription.ts"],"names":[],"mappings":";;;;AAAA,+CAAgE;AAChE,+CAA2C;AAC3C,iDAAmD;AACnD,qEAAkF;AAClF,yCAA6C;AAE7C,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,2DAA2D,CAAC,CAAA;AAGpF,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IA6CvC,mBAAmB,CACT,OAAqC,EACJ,YAAoB,EACpB,YAAoB,EAC3B,KAAa;QAE/C,OAAO,OAAO,CAAC,mBAAmB,CAAA;IACpC,CAAC;IA0DD,qBAAqB,CACX,OAAyD,EACxB,YAAoB,EACpB,YAAoB;QAE7D,OAAO,OAAO,CAAC,qBAAqB,CAAA;IACtC,CAAC;CACF,CAAA;AArHY,oEAA4B;AA6CvC;IA5CC,IAAA,2BAAY,EAAC;QACZ,WAAW,EAAE,qDAAqD;QAClE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"scenario-instance-subscription.js","sourceRoot":"","sources":["../../../server/service/scenario-instance/scenario-instance-subscription.ts"],"names":[],"mappings":";;;;AAAA,+CAAgE;AAChE,+CAA2C;AAC3C,iDAAmD;AACnD,qEAAkF;AAClF,yCAA6C;AAE7C,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,2DAA2D,CAAC,CAAA;AAGpF,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IA6CvC,mBAAmB,CACT,OAAqC,E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d,CAAC;gBAED,IAAI,YAAY,IAAI,aAAa,KAAK,YAAY,EAAE,CAAC;oBACnD,OAAO,KAAK,CAAA;gBACd,CAAC;gBAED,IAAI,YAAY,IAAI,aAAa,KAAK,YAAY,EAAE,CAAC;oBACnD,OAAO,KAAK,CAAA;gBACd,CAAC;gBAED,OAAO,IAAI,CAAA;YACb,CAAC,CAAC,CACH,CAAA;QACH,CAAC;KACF,CAAC;IAEC,mBAAA,IAAA,mBAAI,GAAE,CAAA;IACN,mBAAA,IAAA,kBAAG,EAAC,cAAc,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;IACvC,mBAAA,IAAA,kBAAG,EAAC,cAAc,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;;;4CACvC,8CAAqB;yEAEvB;uCApHU,4BAA4B;IADxC,IAAA,uBAAQ,EAAC,yCAAgB,CAAC;GACd,4BAA4B,CAqHxC","sourcesContent":["import { Resolver, Subscription, Root, Arg } from 'type-graphql'\nimport { filter, pipe } from 'graphql-yoga'\nimport { pubsub, Log } from '@things-factory/shell'\nimport { ScenarioInstance, ScenarioInstanceState } from './scenario-instance-type'\nimport { ScenarioEngine } from '../../engine'\n\nconst debug = require('debug')('things-factory:integration:scenario-instance-subscription')\n\n@Resolver(ScenarioInstance)\nexport class ScenarioInstanceSubscription {\n @Subscription({\n description: 'Subscribes to log messages from scenario instances.',\n subscribe: async ({ args, context, info }) => {\n const { domain, user } = context.state\n const { instanceName, scenarioName, level } = args\n const subdomain = domain?.subdomain\n\n debug('subscribe', subdomain, scenarioName, instanceName)\n\n if (!domain) {\n throw new Error('domain required')\n }\n\n if (!user.domains?.find(d => d.subdomain === subdomain) && !(await 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('scenario-instance-log'),\n filter((payload: { scenarioInstanceLog: Log }) => {\n const { source, level: plevel } = payload.scenarioInstanceLog\n const { domain: pdomain, scenarioName: pscenarioName, instanceName: pinstanceName } = source as any\n\n if (subdomain !== pdomain?.subdomain) {\n return false\n }\n\n if (scenarioName && pscenarioName !== scenarioName) {\n return false\n }\n\n if (instanceName && pinstanceName !== instanceName) {\n return false\n }\n\n if (level && level !== plevel) {\n return false\n }\n\n return true\n })\n )\n }\n })\n scenarioInstanceLog(\n @Root() payload: { scenarioInstanceLog: Log },\n @Arg('scenarioName', { nullable: true }) scenarioName: string,\n @Arg('instanceName', { nullable: true }) instanceName: string,\n @Arg('level', { nullable: true }) level: string\n ): Log {\n return payload.scenarioInstanceLog\n }\n\n @Subscription({\n description: 'Subscribes to state changes from scenario instances.',\n subscribe: async ({ args, context, info }) => {\n const { domain, user } = context.state\n const { instanceName, scenarioName } = args\n const subdomain = domain?.subdomain\n\n debug('subscribe', subdomain, scenarioName, instanceName)\n\n if (!domain) {\n throw new Error('domain required')\n }\n\n if (!user.domains?.find(d => d.subdomain === subdomain) && !(await process.superUserGranted(domain, user))) {\n throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`)\n }\n\n process.nextTick(() => {\n ScenarioEngine.getScenarioInstances(domain)\n .filter(instance => {\n return (\n (!instanceName || instance.instanceName === instanceName) &&\n (!scenarioName || instance.scenarioName === scenarioName)\n )\n })\n .forEach(instance => {\n instance.publishState()\n })\n })\n\n return pipe(\n pubsub.subscribe('scenario-instance-state'),\n filter((payload: { scenarioInstanceState: ScenarioInstanceState }) => {\n const {\n domain: pdomain,\n scenarioName: pscenarioName,\n instanceName: pinstanceName\n } = payload.scenarioInstanceState\n\n if (subdomain !== pdomain?.subdomain) {\n return false\n }\n\n if (scenarioName && pscenarioName !== scenarioName) {\n return false\n }\n\n if (instanceName && pinstanceName !== instanceName) {\n return false\n }\n\n return true\n })\n )\n }\n })\n scenarioInstanceState(\n @Root() payload: { scenarioInstanceState: ScenarioInstanceState },\n @Arg('scenarioName', { nullable: true }) scenarioName: string,\n @Arg('instanceName', { nullable: true }) instanceName: string\n ): ScenarioInstanceState {\n return payload.scenarioInstanceState\n }\n}\n"]}
|
|
@@ -17,14 +17,14 @@ exports.ScenarioQueueSubscription = ScenarioQueueSubscription;
|
|
|
17
17
|
tslib_1.__decorate([
|
|
18
18
|
(0, type_graphql_1.Subscription)({
|
|
19
19
|
description: 'Subscribes to changes in the scenario queue.',
|
|
20
|
-
subscribe: ({ args, context, info }) => {
|
|
20
|
+
subscribe: async ({ args, context, info }) => {
|
|
21
21
|
const { domain, user } = context.state;
|
|
22
22
|
const subdomain = domain?.subdomain;
|
|
23
23
|
debug('subscribe', subdomain);
|
|
24
24
|
if (!domain) {
|
|
25
25
|
throw new Error('domain required.');
|
|
26
26
|
}
|
|
27
|
-
if (!user.domains?.find(d => d.subdomain === subdomain) && !process.superUserGranted(domain, user)) {
|
|
27
|
+
if (!user.domains?.find(d => d.subdomain === subdomain) && !(await process.superUserGranted(domain, user))) {
|
|
28
28
|
throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`);
|
|
29
29
|
}
|
|
30
30
|
process.nextTick(async () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scenario-queue-subscription.js","sourceRoot":"","sources":["../../../server/service/scenario-queue/scenario-queue-subscription.ts"],"names":[],"mappings":";;;;AAAA,+CAAgE;AAChE,+DAA0D;AAC1D,iDAA8C;AAC9C,+CAA2C;AAC3C,yCAA6C;AAE7C,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,oDAAoD,CAAC,CAAA;AAG7E,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IA2CpC,kBAAkB,CAAS,OAAmD;QAC5E,OAAO,OAAO,CAAC,kBAAkB,CAAA;IACnC,CAAC;CACF,CAAA;AA9CY,8DAAyB;AA2CpC;IA1CC,IAAA,2BAAY,EAAC;QACZ,WAAW,EAAE,8CAA8C;QAC3D,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"scenario-queue-subscription.js","sourceRoot":"","sources":["../../../server/service/scenario-queue/sc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AO,CAAC,sBAAsB,EAAE;wBACrC,kBAAkB,EAAE;4BAClB,MAAM;4BACN,KAAK,EAAE,KAAK,CAAC,KAAK;yBACnB;qBACF,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC,CAAC,CAAA;YAEF,OAAO,IAAA,mBAAI,EACT,cAAM,CAAC,SAAS,CAAC,sBAAsB,CAAC,EACxC,IAAA,qBAAM,EAAC,CAAC,OAAmD,EAAE,EAAE;gBAC7D,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAA;gBAEtD,IAAI,OAAO,EAAE,SAAS,KAAK,SAAS,EAAE,CAAC;oBACrC,OAAO,KAAK,CAAA;gBACd,CAAC;gBAED,OAAO,IAAI,CAAA;YACb,CAAC,CAAC,CACH,CAAA;QACH,CAAC;KACF,CAAC;IACkB,mBAAA,IAAA,mBAAI,GAAE,CAAA;;;4CAAuD,wCAAkB;mEAElG;oCA7CU,yBAAyB;IADrC,IAAA,uBAAQ,GAAE;GACE,yBAAyB,CA8CrC","sourcesContent":["import { Resolver, Subscription, Root, Arg } from 'type-graphql'\nimport { ScenarioQueueState } from './scenario-queue-type'\nimport { pubsub } from '@things-factory/shell'\nimport { filter, pipe } from 'graphql-yoga'\nimport { ScenarioEngine } from '../../engine'\n\nconst debug = require('debug')('things-factory:integration:connection-subscription')\n\n@Resolver()\nexport class ScenarioQueueSubscription {\n @Subscription({\n description: 'Subscribes to changes in the scenario queue.',\n subscribe: async ({ args, context, info }) => {\n const { domain, user } = context.state\n const subdomain = domain?.subdomain\n\n debug('subscribe', subdomain)\n\n if (!domain) {\n throw new Error('domain required.')\n }\n\n if (!user.domains?.find(d => d.subdomain === subdomain) && !(await process.superUserGranted(domain, user))) {\n throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`)\n }\n\n process.nextTick(async () => {\n var queue = ScenarioEngine.getPendingQueue(domain)\n if (queue) {\n pubsub.publish('scenario-queue-state', {\n scenarioQueueState: {\n domain,\n queue: queue.queue\n }\n })\n }\n })\n\n return pipe(\n pubsub.subscribe('scenario-queue-state'),\n filter((payload: { scenarioQueueState: ScenarioQueueState }) => {\n const { domain: pdomain } = payload.scenarioQueueState\n\n if (pdomain?.subdomain !== subdomain) {\n return false\n }\n\n return true\n })\n )\n }\n })\n scenarioQueueState(@Root() payload: { scenarioQueueState: ScenarioQueueState }): ScenarioQueueState {\n return payload.scenarioQueueState\n }\n}\n"]}
|
|
@@ -9,13 +9,14 @@ const state_register_1 = require("./state-register");
|
|
|
9
9
|
/* 이 Resolver는 @things-factory/shell에서 등록한 DataResolver를 Overide 한 것이다. */
|
|
10
10
|
let DataResolver = class DataResolver {
|
|
11
11
|
data(payload, tag) {
|
|
12
|
-
|
|
12
|
+
// 전달 시점에 발행 타임스탬프(ts)를 무조건 스탬프 (클라이언트 데이터 지연 모니터링용).
|
|
13
|
+
return { ...payload.data, ts: Date.now() };
|
|
13
14
|
}
|
|
14
15
|
};
|
|
15
16
|
exports.DataResolver = DataResolver;
|
|
16
17
|
tslib_1.__decorate([
|
|
17
18
|
(0, type_graphql_1.Subscription)({
|
|
18
|
-
subscribe: ({ args, context, info }) => {
|
|
19
|
+
subscribe: async ({ args, context, info }) => {
|
|
19
20
|
const { domain, user } = context.state;
|
|
20
21
|
const { tag } = args;
|
|
21
22
|
const subdomain = domain?.subdomain;
|
|
@@ -23,7 +24,7 @@ tslib_1.__decorate([
|
|
|
23
24
|
throw new Error('domain and tag required');
|
|
24
25
|
}
|
|
25
26
|
//@ts-ignore
|
|
26
|
-
if (!user.domains?.find(d => d.subdomain === subdomain) && !process.superUserGranted(domain, user)) {
|
|
27
|
+
if (!user.domains?.find(d => d.subdomain === subdomain) && !(await process.superUserGranted(domain, user))) {
|
|
27
28
|
throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`);
|
|
28
29
|
}
|
|
29
30
|
process.nextTick(async () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-resolver.js","sourceRoot":"","sources":["../../../server/service/state-register/data-resolver.ts"],"names":[],"mappings":";;;;AAAA,+CAA2C;AAC3C,+CAAgE;AAEhE,iDAAmE;AACnE,qDAAgD;AAEhD,0EAA0E;AAEnE,IAAM,YAAY,GAAlB,MAAM,YAAY;IA4CvB,IAAI,CAAS,OAAuB,EAAc,GAAW;QAC3D,OAAO,OAAO,CAAC,IAAI,CAAA;
|
|
1
|
+
{"version":3,"file":"data-resolver.js","sourceRoot":"","sources":["../../../server/service/state-register/data-resolver.ts"],"names":[],"mappings":";;;;AAAA,+CAA2C;AAC3C,+CAAgE;AAEhE,iDAAmE;AACnE,qDAAgD;AAEhD,0EAA0E;AAEnE,IAAM,YAAY,GAAlB,MAAM,YAAY;IA4CvB,IAAI,CAAS,OAAuB,EAAc,GAAW;QAC3D,qDAAqD;QACrD,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAA;IAC5C,CAAC;CACF,CAAA;AAhDY,oCAAY;AA4CvB;IA3CC,IAAA,2BAAY,EAAC;QACZ,SAAS,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE;YAC3C,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;YACtC,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;YACpB,MAAM,SAAS,GAAG,MAAM,EAAE,SAAS,CAAA;YAEnC,IAAI,CAAC,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;gBACpB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;YAC5C,CAAC;YAED,YAAY;YACZ,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,SAAS,CAAC,IAAI,CAAC,CAAC,MAAM,OAAO,CAAC,gBAAgB,CAAC,MAAM,EAAE,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graphql-yoga'\nimport { Arg, Resolver, Root, Subscription } from 'type-graphql'\n\nimport { pubsub, Data, getRepository } from '@things-factory/shell'\nimport { StateRegister } from './state-register'\n\n/* 이 Resolver는 @things-factory/shell에서 등록한 DataResolver를 Overide 한 것이다. */\n@Resolver()\nexport class DataResolver {\n @Subscription({\n subscribe: async ({ 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) && !(await process.superUserGranted(domain, user))) {\n throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`)\n }\n\n process.nextTick(async () => {\n /* state-register에 등록된 태그라면, 현재 상태값을 publish 한다. */\n const { domain } = context.state\n\n const state = await getRepository(StateRegister).findOne({\n where: { domain: { id: domain.id }, name: tag }\n })\n\n if (state) {\n pubsub.publish('data', {\n data: {\n domain,\n tag,\n data: state.state\n }\n })\n }\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 // 전달 시점에 발행 타임스탬프(ts)를 무조건 스탬프 (클라이언트 데이터 지연 모니터링용).\n return { ...payload.data, ts: Date.now() }\n }\n}\n"]}
|