@things-factory/shell 9.0.0-beta.19 → 9.0.0-beta.25

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.
@@ -1,22 +1,42 @@
1
1
  /**
2
2
  * Get the time range for the specified period relative to the current moment in a specific domain's timezone.
3
3
  *
4
- * @param {string} period - The time period to calculate the range for. Valid options are 'today', 'this month', '30 days', 'this year', '12 months'.
4
+ * @param {('today' | 'this month' | '30 days' | 'this year' | '12 months' | 'date range' | 'month')} period - The time period to calculate the range for.
5
+ * Valid options are 'today', 'this month', '30 days', 'this year', '12 months', 'date range', and 'month'.
6
+ * @param {Object} [options] - Optional parameters for 'date range' and 'month' periods.
7
+ * @param {string[]} [options.date] - The start date and end date for the 'date range' period.
8
+ * @param {string} [options.month] - The month for the 'month' period in 'YYYY-MM' format.
5
9
  * @param {Object} context - The context object containing domain information.
10
+ * @param {Object} context.state - The state object containing domain information.
11
+ * @param {Object} context.state.domain - The domain object containing timezone information.
12
+ * @param {string} context.state.domain.timezone - The timezone of the domain.
6
13
  * @returns {Promise<{ from: string; to: string }>} - A Promise that resolves to an object containing 'from' and 'to' ISO date strings representing the time range.
7
14
  */
8
- export declare function getTimesForPeriod(period: 'today' | 'this month' | '30 days' | 'this year' | '12 months', context: any): Promise<{
15
+ export declare function getTimesForPeriod(period: 'today' | 'this month' | '30 days' | 'this year' | '12 months' | 'date range' | 'month', options: {
16
+ date?: string[];
17
+ month?: string;
18
+ }, context: any): Promise<{
9
19
  from: string;
10
20
  to: string;
11
21
  }>;
12
22
  /**
13
23
  * Get the ISO date strings for the specified period relative to the current moment in a specific domain's timezone.
14
24
  *
15
- * @param {string} period - The time period to calculate the range for. Valid options are 'today', 'this month', '30 days', 'this year', '12 months'.
25
+ * @param {('today' | 'this month' | '30 days' | 'this year' | '12 months' | 'date range' | 'month')} period - The time period to calculate the range for.
26
+ * Valid options are 'today', 'this month', '30 days', 'this year', '12 months', 'date range', and 'month'.
27
+ * @param {Object} [options] - Optional parameters for 'date range' and 'month' periods.
28
+ * @param {string[]} [options.date] - The start date and end date for the 'date range' period.
29
+ * @param {string} [options.month] - The month for the 'month' period in 'YYYY-MM' format.
16
30
  * @param {Object} context - The context object containing domain information.
31
+ * @param {Object} context.state - The state object containing domain information.
32
+ * @param {Object} context.state.domain - The domain object containing timezone information.
33
+ * @param {string} context.state.domain.timezone - The timezone of the domain.
17
34
  * @returns {Promise<{ from: string; to: string }>} - A Promise that resolves to an object containing 'from' and 'to' ISO date strings representing the time range.
18
35
  */
19
- export declare function getISOStringsForPeriod(period: 'today' | 'this month' | '30 days' | 'this year' | '12 months', context: any): Promise<{
36
+ export declare function getISOStringsForPeriod(period: 'today' | 'this month' | '30 days' | 'this year' | '12 months' | 'date range' | 'month', options: {
37
+ date?: string[];
38
+ month?: string;
39
+ }, context: any): Promise<{
20
40
  from: string;
21
41
  to: string;
22
42
  }>;
@@ -7,11 +7,18 @@ const moment_timezone_1 = tslib_1.__importDefault(require("moment-timezone"));
7
7
  /**
8
8
  * Get the time range for the specified period relative to the current moment in a specific domain's timezone.
9
9
  *
10
- * @param {string} period - The time period to calculate the range for. Valid options are 'today', 'this month', '30 days', 'this year', '12 months'.
10
+ * @param {('today' | 'this month' | '30 days' | 'this year' | '12 months' | 'date range' | 'month')} period - The time period to calculate the range for.
11
+ * Valid options are 'today', 'this month', '30 days', 'this year', '12 months', 'date range', and 'month'.
12
+ * @param {Object} [options] - Optional parameters for 'date range' and 'month' periods.
13
+ * @param {string[]} [options.date] - The start date and end date for the 'date range' period.
14
+ * @param {string} [options.month] - The month for the 'month' period in 'YYYY-MM' format.
11
15
  * @param {Object} context - The context object containing domain information.
16
+ * @param {Object} context.state - The state object containing domain information.
17
+ * @param {Object} context.state.domain - The domain object containing timezone information.
18
+ * @param {string} context.state.domain.timezone - The timezone of the domain.
12
19
  * @returns {Promise<{ from: string; to: string }>} - A Promise that resolves to an object containing 'from' and 'to' ISO date strings representing the time range.
13
20
  */
14
- async function getTimesForPeriod(period, context) {
21
+ async function getTimesForPeriod(period, options = {}, context) {
15
22
  const { domain } = context.state;
16
23
  const theDate = moment_timezone_1.default.tz(new Date(), domain.timezone);
17
24
  if (period == 'today') {
@@ -39,17 +46,47 @@ async function getTimesForPeriod(period, context) {
39
46
  const to = theDate.clone().add(1, 'month').startOf('month').format('YYYY-MM-DD');
40
47
  return { from, to };
41
48
  }
49
+ else if (period == 'date range') {
50
+ const [fromDate, toDate] = (options === null || options === void 0 ? void 0 : options.date) || [
51
+ theDate.clone().startOf('month').format('YYYY-MM-DD'),
52
+ theDate.clone().format('YYYY-MM-DD')
53
+ ];
54
+ const from = moment_timezone_1.default.tz(fromDate, domain.timezone).startOf('day').format('YYYY-MM-DD');
55
+ const to = moment_timezone_1.default.tz(toDate, domain.timezone).add(1, 'day').startOf('day').format('YYYY-MM-DD');
56
+ return { from, to };
57
+ }
58
+ else if (period == 'month') {
59
+ const monthString = (options === null || options === void 0 ? void 0 : options.month) || theDate.clone().startOf('month').format('YYYY-MM');
60
+ const [year, month] = monthString.split('-').map(Number);
61
+ const from = moment_timezone_1.default
62
+ .tz({ year, month: month - 1, day: 1 }, domain.timezone)
63
+ .startOf('month')
64
+ .format('YYYY-MM-DD');
65
+ const to = moment_timezone_1.default
66
+ .tz({ year, month: month - 1, day: 1 }, domain.timezone)
67
+ .add(1, 'month')
68
+ .startOf('month')
69
+ .format('YYYY-MM-DD');
70
+ return { from, to };
71
+ }
42
72
  }
43
73
  /**
44
74
  * Get the ISO date strings for the specified period relative to the current moment in a specific domain's timezone.
45
75
  *
46
- * @param {string} period - The time period to calculate the range for. Valid options are 'today', 'this month', '30 days', 'this year', '12 months'.
76
+ * @param {('today' | 'this month' | '30 days' | 'this year' | '12 months' | 'date range' | 'month')} period - The time period to calculate the range for.
77
+ * Valid options are 'today', 'this month', '30 days', 'this year', '12 months', 'date range', and 'month'.
78
+ * @param {Object} [options] - Optional parameters for 'date range' and 'month' periods.
79
+ * @param {string[]} [options.date] - The start date and end date for the 'date range' period.
80
+ * @param {string} [options.month] - The month for the 'month' period in 'YYYY-MM' format.
47
81
  * @param {Object} context - The context object containing domain information.
82
+ * @param {Object} context.state - The state object containing domain information.
83
+ * @param {Object} context.state.domain - The domain object containing timezone information.
84
+ * @param {string} context.state.domain.timezone - The timezone of the domain.
48
85
  * @returns {Promise<{ from: string; to: string }>} - A Promise that resolves to an object containing 'from' and 'to' ISO date strings representing the time range.
49
86
  */
50
- async function getISOStringsForPeriod(period, context) {
87
+ async function getISOStringsForPeriod(period, options = {}, context) {
51
88
  const { domain } = context.state;
52
- const { from, to } = await getTimesForPeriod(period, context);
89
+ const { from, to } = await getTimesForPeriod(period, options, context);
53
90
  return {
54
91
  from: moment_timezone_1.default.tz(from, domain.timezone).toISOString(),
55
92
  to: moment_timezone_1.default.tz(to, domain.timezone).toISOString()
@@ -1 +1 @@
1
- {"version":3,"file":"get-times-for-period.js","sourceRoot":"","sources":["../../server/utils/get-times-for-period.ts"],"names":[],"mappings":";;AASA,8CA8BC;AASD,wDAWC;;AA3DD,8EAAoC;AAEpC;;;;;;GAMG;AACI,KAAK,UAAU,iBAAiB,CAAC,MAAsE,EAAE,OAAY;IAC1H,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;IAChC,MAAM,OAAO,GAAG,yBAAM,CAAC,EAAE,CAAC,IAAI,IAAI,EAAE,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAA;IAEtD,IAAI,MAAM,IAAI,OAAO,EAAE,CAAC;QACtB,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;QACjD,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;QAE5E,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAAA;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,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;QACxF,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;QAEhF,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAAA;IACrB,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,sBAAsB,CAC1C,MAAsE,EACtE,OAAY;IAEZ,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;IAChC,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAE7D,OAAO;QACL,IAAI,EAAE,yBAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE;QACpD,EAAE,EAAE,yBAAM,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE;KACjD,CAAA;AACH,CAAC","sourcesContent":["import moment from 'moment-timezone'\n\n/**\n * Get the time range for the specified period relative to the current moment in a specific domain's timezone.\n *\n * @param {string} period - The time period to calculate the range for. Valid options are 'today', 'this month', '30 days', 'this year', '12 months'.\n * @param {Object} context - The context object containing domain information.\n * @returns {Promise<{ from: string; to: string }>} - A Promise that resolves to an object containing 'from' and 'to' ISO date strings representing the time range.\n */\nexport async function getTimesForPeriod(period: 'today' | 'this month' | '30 days' | 'this year' | '12 months', context: any): Promise<{ from: string; to: string }> {\n const { domain } = context.state\n const theDate = moment.tz(new Date(), domain.timezone)\n\n if (period == 'today') {\n const from = theDate.clone().format('YYYY-MM-DD')\n const to = theDate.clone().add(1, 'day').startOf('day').format('YYYY-MM-DD')\n\n return { from, to }\n } else if (period == 'this month') {\n const from = theDate.clone().startOf('month').format('YYYY-MM-DD')\n const to = theDate.clone().add(1, 'month').startOf('month').format('YYYY-MM-DD')\n\n return { from, to }\n } else if (period == '30 days') {\n const from = theDate.clone().subtract(30, 'day').format('YYYY-MM-DD')\n const to = theDate.clone().add(1, 'day').startOf('day').format('YYYY-MM-DD')\n\n return { from, to }\n } else if (period == 'this year') {\n const from = theDate.clone().startOf('year').format('YYYY-MM-DD')\n const to = theDate.clone().add(1, 'year').startOf('year').format('YYYY-MM-DD')\n\n return { from, to }\n } else if (period == '12 months') {\n const from = theDate.clone().subtract(12, 'month').startOf('month').format('YYYY-MM-DD')\n const to = theDate.clone().add(1, 'month').startOf('month').format('YYYY-MM-DD')\n\n return { from, to }\n }\n}\n\n/**\n * Get the ISO date strings for the specified period relative to the current moment in a specific domain's timezone.\n *\n * @param {string} period - The time period to calculate the range for. Valid options are 'today', 'this month', '30 days', 'this year', '12 months'.\n * @param {Object} context - The context object containing domain information.\n * @returns {Promise<{ from: string; to: string }>} - A Promise that resolves to an object containing 'from' and 'to' ISO date strings representing the time range.\n */\nexport async function getISOStringsForPeriod(\n period: 'today' | 'this month' | '30 days' | 'this year' | '12 months',\n context: any\n): Promise<{ from: string; to: string }> {\n const { domain } = context.state\n const { from, to } = await getTimesForPeriod(period, context)\n\n return {\n from: moment.tz(from, domain.timezone).toISOString(),\n to: moment.tz(to, domain.timezone).toISOString()\n }\n}\n"]}
1
+ {"version":3,"file":"get-times-for-period.js","sourceRoot":"","sources":["../../server/utils/get-times-for-period.ts"],"names":[],"mappings":";;AAgBA,8CA2DC;AAgBD,wDAYC;;AAvGD,8EAAoC;AAEpC;;;;;;;;;;;;;GAaG;AACI,KAAK,UAAU,iBAAiB,CACrC,MAA+F,EAC/F,UAA+C,EAAE,EACjD,OAAY;IAEZ,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;IAChC,MAA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ACjD,OAAY;IAEZ,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;IAChC,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IAEtE,OAAO;QACL,IAAI,EAAE,yBAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE;QACpD,EAAE,EAAE,yBAAM,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE;KACjD,CAAA;AACH,CAAC","sourcesContent":["import moment from 'moment-timezone'\n\n/**\n * Get the time range for the specified period relative to the current moment in a specific domain's timezone.\n *\n * @param {('today' | 'this month' | '30 days' | 'this year' | '12 months' | 'date range' | 'month')} period - The time period to calculate the range for.\n * Valid options are 'today', 'this month', '30 days', 'this year', '12 months', 'date range', and 'month'.\n * @param {Object} [options] - Optional parameters for 'date range' and 'month' periods.\n * @param {string[]} [options.date] - The start date and end date for the 'date range' period.\n * @param {string} [options.month] - The month for the 'month' period in 'YYYY-MM' format.\n * @param {Object} context - The context object containing domain information.\n * @param {Object} context.state - The state object containing domain information.\n * @param {Object} context.state.domain - The domain object containing timezone information.\n * @param {string} context.state.domain.timezone - The timezone of the domain.\n * @returns {Promise<{ from: string; to: string }>} - A Promise that resolves to an object containing 'from' and 'to' ISO date strings representing the time range.\n */\nexport async function getTimesForPeriod(\n period: 'today' | 'this month' | '30 days' | 'this year' | '12 months' | 'date range' | 'month',\n options: { date?: string[]; month?: string } = {},\n context: any\n): Promise<{ from: string; to: string }> {\n const { domain } = context.state\n const theDate = moment.tz(new Date(), domain.timezone)\n\n if (period == 'today') {\n const from = theDate.clone().format('YYYY-MM-DD')\n const to = theDate.clone().add(1, 'day').startOf('day').format('YYYY-MM-DD')\n\n return { from, to }\n } else if (period == 'this month') {\n const from = theDate.clone().startOf('month').format('YYYY-MM-DD')\n const to = theDate.clone().add(1, 'month').startOf('month').format('YYYY-MM-DD')\n\n return { from, to }\n } else if (period == '30 days') {\n const from = theDate.clone().subtract(30, 'day').format('YYYY-MM-DD')\n const to = theDate.clone().add(1, 'day').startOf('day').format('YYYY-MM-DD')\n\n return { from, to }\n } else if (period == 'this year') {\n const from = theDate.clone().startOf('year').format('YYYY-MM-DD')\n const to = theDate.clone().add(1, 'year').startOf('year').format('YYYY-MM-DD')\n\n return { from, to }\n } else if (period == '12 months') {\n const from = theDate.clone().subtract(12, 'month').startOf('month').format('YYYY-MM-DD')\n const to = theDate.clone().add(1, 'month').startOf('month').format('YYYY-MM-DD')\n\n return { from, to }\n } else if (period == 'date range') {\n const [fromDate, toDate] = options?.date || [\n theDate.clone().startOf('month').format('YYYY-MM-DD'),\n theDate.clone().format('YYYY-MM-DD')\n ]\n\n const from = moment.tz(fromDate, domain.timezone).startOf('day').format('YYYY-MM-DD')\n const to = moment.tz(toDate, domain.timezone).add(1, 'day').startOf('day').format('YYYY-MM-DD')\n\n return { from, to }\n } else if (period == 'month') {\n const monthString = options?.month || theDate.clone().startOf('month').format('YYYY-MM')\n\n const [year, month] = monthString.split('-').map(Number)\n const from = moment\n .tz({ year, month: month - 1, day: 1 }, domain.timezone)\n .startOf('month')\n .format('YYYY-MM-DD')\n const to = moment\n .tz({ year, month: month - 1, day: 1 }, domain.timezone)\n .add(1, 'month')\n .startOf('month')\n .format('YYYY-MM-DD')\n\n return { from, to }\n }\n}\n\n/**\n * Get the ISO date strings for the specified period relative to the current moment in a specific domain's timezone.\n *\n * @param {('today' | 'this month' | '30 days' | 'this year' | '12 months' | 'date range' | 'month')} period - The time period to calculate the range for.\n * Valid options are 'today', 'this month', '30 days', 'this year', '12 months', 'date range', and 'month'.\n * @param {Object} [options] - Optional parameters for 'date range' and 'month' periods.\n * @param {string[]} [options.date] - The start date and end date for the 'date range' period.\n * @param {string} [options.month] - The month for the 'month' period in 'YYYY-MM' format.\n * @param {Object} context - The context object containing domain information.\n * @param {Object} context.state - The state object containing domain information.\n * @param {Object} context.state.domain - The domain object containing timezone information.\n * @param {string} context.state.domain.timezone - The timezone of the domain.\n * @returns {Promise<{ from: string; to: string }>} - A Promise that resolves to an object containing 'from' and 'to' ISO date strings representing the time range.\n */\nexport async function getISOStringsForPeriod(\n period: 'today' | 'this month' | '30 days' | 'this year' | '12 months' | 'date range' | 'month',\n options: { date?: string[]; month?: string } = {},\n context: any\n): Promise<{ from: string; to: string }> {\n const { domain } = context.state\n const { from, to } = await getTimesForPeriod(period, options, context)\n\n return {\n from: moment.tz(from, domain.timezone).toISOString(),\n to: moment.tz(to, domain.timezone).toISOString()\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/shell",
3
- "version": "9.0.0-beta.19",
3
+ "version": "9.0.0-beta.25",
4
4
  "description": "Core module for framework",
5
5
  "bin": {
6
6
  "things-factory": "bin/things-factory",
@@ -43,7 +43,6 @@
43
43
  "@graphql-tools/schema": "^8.5.0",
44
44
  "@graphql-tools/utils": "^10.1.2",
45
45
  "@graphql-yoga/redis-event-target": "^3.0.1",
46
- "@hatiolab/things-scene": "^9.0.0-beta",
47
46
  "@koa/cors": "^5.0.0",
48
47
  "@material/mwc-button": "^0.27.0",
49
48
  "@material/mwc-icon": "^0.27.0",
@@ -52,7 +51,6 @@
52
51
  "@material/mwc-textfield": "^0.27.0",
53
52
  "@material/web": "^2.0.0",
54
53
  "@open-wc/scoped-elements": "^2.1.3",
55
- "@operato/board": "^9.0.0-beta",
56
54
  "@operato/graphql": "^9.0.0-beta",
57
55
  "@operato/help": "^9.0.0-beta",
58
56
  "@operato/layout": "^9.0.0-beta",
@@ -130,5 +128,5 @@
130
128
  "pg": "^8.7.3",
131
129
  "sqlite3": "^5.0.8"
132
130
  },
133
- "gitHead": "b72aed659b0224f428d39034371b8dbd8f281dae"
131
+ "gitHead": "7b11df06e4b7586cc316da7dd5ab905592d85dcc"
134
132
  }
@@ -1,3 +0,0 @@
1
- import 'core-js/stable'
2
- import 'regenerator-runtime/runtime'
3
- import './things-scene-components.import'
@@ -1,103 +0,0 @@
1
- import './scene-components'
2
- import gql from 'graphql-tag'
3
-
4
- import { ReferenceMap, create, error } from '@hatiolab/things-scene'
5
-
6
- export { BoardViewer, BoardPlayer } from '@operato/board'
7
- import { client, gqlContext, subscribe } from '@operato/graphql'
8
-
9
- export const provider = new ReferenceMap(
10
- async (boardId, resolve, reject) => {
11
- try {
12
- const response = await client.query({
13
- query: gql`
14
- query FetchBoardById($id: String!) {
15
- board(id: $id) {
16
- model
17
- }
18
- }
19
- `,
20
- variables: { id: boardId },
21
- context: gqlContext()
22
- })
23
-
24
- const board = response.data.board
25
-
26
- var model = JSON.parse(board.model)
27
-
28
- var scene
29
-
30
- try {
31
- scene = await provider.get(boardId)
32
- console.warn('Board fetched more than twice.', boardId)
33
- } catch (e) {
34
- scene = create({
35
- model,
36
- mode: 0,
37
- refProvider: provider
38
- })
39
-
40
- // s.app.baseUrl = undefined;
41
- }
42
-
43
- resolve(scene)
44
- } catch (e) {
45
- error(e)
46
- reject(e)
47
- }
48
- },
49
- async (id, ref) => {
50
- ref.dispose()
51
- }
52
- )
53
-
54
- var subscriptionForAutoRefresh
55
-
56
- export const startSubscribingForAutoRefresh = async (playGroupId, callback) => {
57
- if (!playGroupId) {
58
- return
59
- }
60
-
61
- await stopSubscribing()
62
-
63
- subscriptionForAutoRefresh = await subscribe(
64
- {
65
- query: gql`
66
- subscription ($id: String!) {
67
- playGroup(id: $id) {
68
- id
69
- boards {
70
- id
71
- model
72
- }
73
- }
74
- }
75
- `,
76
- variables: {
77
- id: playGroupId
78
- }
79
- },
80
- {
81
- next: async ({ data }) => {
82
- const { id, boards = '{}' } = data.playGroup
83
-
84
- if (data) {
85
- callback &&
86
- (await callback({
87
- id,
88
- boards
89
- }))
90
- }
91
- }
92
- }
93
- )
94
- }
95
-
96
- export const stopSubscribing = async () => {
97
- await subscriptionForAutoRefresh?.unsubscribe()
98
- subscriptionForAutoRefresh = null
99
- }
100
-
101
- window['headlessSceneProvider'] = provider
102
- window['startSubscribingForAutoRefresh'] = startSubscribingForAutoRefresh
103
- window['stopSubscribing'] = stopSubscribing
@@ -1,106 +0,0 @@
1
- import './scene-components'
2
-
3
- import { ReferenceMap, create, error } from '@hatiolab/things-scene'
4
- import { client, gqlContext, subscribe } from '@operato/graphql'
5
-
6
- import gql from 'graphql-tag'
7
-
8
- export { BoardViewer } from '@operato/board'
9
-
10
- export const provider = new ReferenceMap(
11
- async (boardId, resolve, reject) => {
12
- try {
13
- const response = await client.query({
14
- query: gql`
15
- query FetchBoardById($id: String!) {
16
- board(id: $id) {
17
- model
18
- }
19
- }
20
- `,
21
- variables: { id: boardId },
22
- context: gqlContext()
23
- })
24
-
25
- const board = response.data.board
26
-
27
- var model = JSON.parse(board.model)
28
-
29
- var scene
30
-
31
- try {
32
- scene = await provider.get(boardId)
33
- console.warn('Board fetched more than twice.', boardId)
34
- } catch (e) {
35
- scene = create({
36
- model,
37
- mode: 0,
38
- refProvider: provider
39
- })
40
-
41
- // s.app.baseUrl = undefined;
42
- }
43
-
44
- resolve(scene)
45
-
46
- // resolve(scene, {
47
- // ...board,
48
- // model
49
- // })
50
- } catch (e) {
51
- error(e)
52
- reject(e)
53
- }
54
- },
55
- async (id, ref) => {
56
- ref.dispose()
57
- }
58
- )
59
-
60
- var subscriptionForAutoRefresh
61
-
62
- export const startSubscribingForAutoRefresh = async (boardId, callback) => {
63
- if (!boardId) {
64
- return
65
- }
66
-
67
- await stopSubscribing()
68
-
69
- subscriptionForAutoRefresh = await subscribe(
70
- {
71
- query: gql`
72
- subscription ($id: String!) {
73
- board(id: $id) {
74
- id
75
- model
76
- }
77
- }
78
- `,
79
- variables: {
80
- id: boardId
81
- }
82
- },
83
- {
84
- next: async ({ data }) => {
85
- const { id, model = '{}' } = data.board
86
-
87
- if (data) {
88
- callback &&
89
- (await callback({
90
- id,
91
- model: JSON.parse(model)
92
- }))
93
- }
94
- }
95
- }
96
- )
97
- }
98
-
99
- export const stopSubscribing = async () => {
100
- await subscriptionForAutoRefresh?.unsubscribe()
101
- subscriptionForAutoRefresh = null
102
- }
103
-
104
- window['headlessSceneProvider'] = provider
105
- window['startSubscribingForAutoRefresh'] = startSubscribingForAutoRefresh
106
- window['stopSubscribing'] = stopSubscribing
@@ -1 +0,0 @@
1
- /* 이 파일은 node_modules/@things-scene 아래에 설치된 컴포넌트들의 리스트를 스캔해서 자동으로 import 하기위해 things-scene-webpack-loader 에 의해 로드되는 파일이다. */