@backstage/plugin-signals-react 0.0.1-next.1 → 0.0.1-next.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @backstage/plugin-signals-react
2
2
 
3
+ ## 0.0.1-next.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 8472188: Added or fixed the `repository` field in `package.json`.
8
+ - 1ab22c4: Allow defining signal type to publish and receive
9
+ - Updated dependencies
10
+ - @backstage/core-plugin-api@1.9.0-next.1
11
+ - @backstage/types@1.1.1
12
+
13
+ ## 0.0.1-next.2
14
+
15
+ ### Patch Changes
16
+
17
+ - 447d210: Fix disconnect loop on server start
18
+ - Updated dependencies
19
+ - @backstage/core-plugin-api@1.9.0-next.1
20
+ - @backstage/types@1.1.1
21
+
3
22
  ## 0.0.1-next.1
4
23
 
5
24
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -4,15 +4,18 @@ import { JsonObject } from '@backstage/types';
4
4
  /** @public */
5
5
  declare const signalApiRef: _backstage_core_plugin_api.ApiRef<SignalApi>;
6
6
  /** @public */
7
- type SignalApi = {
8
- subscribe(channel: string, onMessage: (message: JsonObject) => void): {
9
- unsubscribe: () => void;
10
- };
11
- };
7
+ interface SignalSubscriber {
8
+ unsubscribe(): void;
9
+ }
10
+ /** @public */
11
+ interface SignalApi {
12
+ subscribe<TMessage extends JsonObject = JsonObject>(channel: string, onMessage: (message: TMessage) => void): SignalSubscriber;
13
+ }
12
14
 
13
15
  /** @public */
14
- declare const useSignal: (channel: string) => {
15
- lastSignal: JsonObject | null;
16
+ declare const useSignal: <TMessage extends JsonObject = JsonObject>(channel: string) => {
17
+ lastSignal: TMessage | null;
18
+ isSignalsAvailable: boolean;
16
19
  };
17
20
 
18
- export { SignalApi, signalApiRef, useSignal };
21
+ export { SignalApi, SignalSubscriber, signalApiRef, useSignal };
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createApiRef, useApiHolder } from '@backstage/core-plugin-api';
2
- import { useState, useEffect } from 'react';
2
+ import { useState, useEffect, useMemo } from 'react';
3
3
 
4
4
  const signalApiRef = createApiRef({
5
5
  id: "plugin.signal.service"
@@ -12,9 +12,12 @@ const useSignal = (channel) => {
12
12
  useEffect(() => {
13
13
  let unsub = null;
14
14
  if (signals) {
15
- const { unsubscribe } = signals.subscribe(channel, (msg) => {
16
- setLastSignal(msg);
17
- });
15
+ const { unsubscribe } = signals.subscribe(
16
+ channel,
17
+ (msg) => {
18
+ setLastSignal(msg);
19
+ }
20
+ );
18
21
  unsub = unsubscribe;
19
22
  }
20
23
  return () => {
@@ -23,7 +26,8 @@ const useSignal = (channel) => {
23
26
  }
24
27
  };
25
28
  }, [signals, channel]);
26
- return { lastSignal };
29
+ const isSignalsAvailable = useMemo(() => !signals, [signals]);
30
+ return { lastSignal, isSignalsAvailable };
27
31
  };
28
32
 
29
33
  export { signalApiRef, useSignal };
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/api/SignalApi.ts","../src/hooks/useSignal.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { createApiRef } from '@backstage/core-plugin-api';\nimport { JsonObject } from '@backstage/types';\n\n/** @public */\nexport const signalApiRef = createApiRef<SignalApi>({\n id: 'plugin.signal.service',\n});\n\n/** @public */\nexport type SignalApi = {\n subscribe(\n channel: string,\n onMessage: (message: JsonObject) => void,\n ): { unsubscribe: () => void };\n};\n","/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { signalApiRef } from '../api';\nimport { useApiHolder } from '@backstage/core-plugin-api';\nimport { JsonObject } from '@backstage/types';\nimport { useEffect, useState } from 'react';\n\n/** @public */\nexport const useSignal = (channel: string) => {\n const apiHolder = useApiHolder();\n // Use apiHolder instead useApi in case signalApi is not available in the\n // backstage instance this is used\n const signals = apiHolder.get(signalApiRef);\n const [lastSignal, setLastSignal] = useState<JsonObject | null>(null);\n useEffect(() => {\n let unsub: null | (() => void) = null;\n if (signals) {\n const { unsubscribe } = signals.subscribe(channel, (msg: JsonObject) => {\n setLastSignal(msg);\n });\n unsub = unsubscribe;\n }\n return () => {\n if (signals && unsub) {\n unsub();\n }\n };\n }, [signals, channel]);\n\n return { lastSignal };\n};\n"],"names":[],"mappings":";;;AAmBO,MAAM,eAAe,YAAwB,CAAA;AAAA,EAClD,EAAI,EAAA,uBAAA;AACN,CAAC;;ACAY,MAAA,SAAA,GAAY,CAAC,OAAoB,KAAA;AAC5C,EAAA,MAAM,YAAY,YAAa,EAAA,CAAA;AAG/B,EAAM,MAAA,OAAA,GAAU,SAAU,CAAA,GAAA,CAAI,YAAY,CAAA,CAAA;AAC1C,EAAA,MAAM,CAAC,UAAA,EAAY,aAAa,CAAA,GAAI,SAA4B,IAAI,CAAA,CAAA;AACpE,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,KAA6B,GAAA,IAAA,CAAA;AACjC,IAAA,IAAI,OAAS,EAAA;AACX,MAAA,MAAM,EAAE,WAAY,EAAA,GAAI,QAAQ,SAAU,CAAA,OAAA,EAAS,CAAC,GAAoB,KAAA;AACtE,QAAA,aAAA,CAAc,GAAG,CAAA,CAAA;AAAA,OAClB,CAAA,CAAA;AACD,MAAQ,KAAA,GAAA,WAAA,CAAA;AAAA,KACV;AACA,IAAA,OAAO,MAAM;AACX,MAAA,IAAI,WAAW,KAAO,EAAA;AACpB,QAAM,KAAA,EAAA,CAAA;AAAA,OACR;AAAA,KACF,CAAA;AAAA,GACC,EAAA,CAAC,OAAS,EAAA,OAAO,CAAC,CAAA,CAAA;AAErB,EAAA,OAAO,EAAE,UAAW,EAAA,CAAA;AACtB;;;;"}
1
+ {"version":3,"file":"index.esm.js","sources":["../src/api/SignalApi.ts","../src/hooks/useSignal.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { createApiRef } from '@backstage/core-plugin-api';\nimport { JsonObject } from '@backstage/types';\n\n/** @public */\nexport const signalApiRef = createApiRef<SignalApi>({\n id: 'plugin.signal.service',\n});\n\n/** @public */\nexport interface SignalSubscriber {\n unsubscribe(): void;\n}\n\n/** @public */\nexport interface SignalApi {\n subscribe<TMessage extends JsonObject = JsonObject>(\n channel: string,\n onMessage: (message: TMessage) => void,\n ): SignalSubscriber;\n}\n","/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { signalApiRef } from '../api';\nimport { useApiHolder } from '@backstage/core-plugin-api';\nimport { JsonObject } from '@backstage/types';\nimport { useEffect, useMemo, useState } from 'react';\n\n/** @public */\nexport const useSignal = <TMessage extends JsonObject = JsonObject>(\n channel: string,\n): { lastSignal: TMessage | null; isSignalsAvailable: boolean } => {\n const apiHolder = useApiHolder();\n // Use apiHolder instead useApi in case signalApi is not available in the\n // backstage instance this is used\n const signals = apiHolder.get(signalApiRef);\n const [lastSignal, setLastSignal] = useState<TMessage | null>(null);\n useEffect(() => {\n let unsub: null | (() => void) = null;\n if (signals) {\n const { unsubscribe } = signals.subscribe<TMessage>(\n channel,\n (msg: TMessage) => {\n setLastSignal(msg);\n },\n );\n unsub = unsubscribe;\n }\n return () => {\n if (signals && unsub) {\n unsub();\n }\n };\n }, [signals, channel]);\n\n // Can be used to fallback (for example to long polling) if signals are not available in the system\n const isSignalsAvailable = useMemo(() => !signals, [signals]);\n\n return { lastSignal, isSignalsAvailable };\n};\n"],"names":[],"mappings":";;;AAmBO,MAAM,eAAe,YAAwB,CAAA;AAAA,EAClD,EAAI,EAAA,uBAAA;AACN,CAAC;;ACAY,MAAA,SAAA,GAAY,CACvB,OACiE,KAAA;AACjE,EAAA,MAAM,YAAY,YAAa,EAAA,CAAA;AAG/B,EAAM,MAAA,OAAA,GAAU,SAAU,CAAA,GAAA,CAAI,YAAY,CAAA,CAAA;AAC1C,EAAA,MAAM,CAAC,UAAA,EAAY,aAAa,CAAA,GAAI,SAA0B,IAAI,CAAA,CAAA;AAClE,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,KAA6B,GAAA,IAAA,CAAA;AACjC,IAAA,IAAI,OAAS,EAAA;AACX,MAAM,MAAA,EAAE,WAAY,EAAA,GAAI,OAAQ,CAAA,SAAA;AAAA,QAC9B,OAAA;AAAA,QACA,CAAC,GAAkB,KAAA;AACjB,UAAA,aAAA,CAAc,GAAG,CAAA,CAAA;AAAA,SACnB;AAAA,OACF,CAAA;AACA,MAAQ,KAAA,GAAA,WAAA,CAAA;AAAA,KACV;AACA,IAAA,OAAO,MAAM;AACX,MAAA,IAAI,WAAW,KAAO,EAAA;AACpB,QAAM,KAAA,EAAA,CAAA;AAAA,OACR;AAAA,KACF,CAAA;AAAA,GACC,EAAA,CAAC,OAAS,EAAA,OAAO,CAAC,CAAA,CAAA;AAGrB,EAAA,MAAM,qBAAqB,OAAQ,CAAA,MAAM,CAAC,OAAS,EAAA,CAAC,OAAO,CAAC,CAAA,CAAA;AAE5D,EAAO,OAAA,EAAE,YAAY,kBAAmB,EAAA,CAAA;AAC1C;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@backstage/plugin-signals-react",
3
3
  "description": "Web library for the signals plugin",
4
- "version": "0.0.1-next.1",
4
+ "version": "0.0.1-next.3",
5
5
  "main": "dist/index.esm.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "Apache-2.0",
@@ -10,6 +10,11 @@
10
10
  "main": "dist/index.esm.js",
11
11
  "types": "dist/index.d.ts"
12
12
  },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/backstage/backstage",
16
+ "directory": "plugins/signals-react"
17
+ },
13
18
  "backstage": {
14
19
  "role": "web-library"
15
20
  },
@@ -24,7 +29,7 @@
24
29
  "postpack": "backstage-cli package postpack"
25
30
  },
26
31
  "dependencies": {
27
- "@backstage/core-plugin-api": "^1.8.3-next.0",
32
+ "@backstage/core-plugin-api": "^1.9.0-next.1",
28
33
  "@backstage/types": "^1.1.1",
29
34
  "@material-ui/core": "^4.12.4"
30
35
  },
@@ -32,8 +37,8 @@
32
37
  "react": "^16.13.1 || ^17.0.0"
33
38
  },
34
39
  "devDependencies": {
35
- "@backstage/cli": "^0.25.2-next.1",
36
- "@backstage/test-utils": "^1.5.0-next.1",
40
+ "@backstage/cli": "^0.25.2-next.3",
41
+ "@backstage/test-utils": "^1.5.0-next.3",
37
42
  "@testing-library/jest-dom": "^6.0.0",
38
43
  "@testing-library/react": "^14.0.0"
39
44
  },