@backstage/core-compat-api 0.5.9-next.1 → 0.5.9-next.2

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,16 @@
1
1
  # @backstage/core-compat-api
2
2
 
3
+ ## 0.5.9-next.2
4
+
5
+ ### Patch Changes
6
+
7
+ - b15a685: Added `withApis`, which is a Higher-Order Component for providing APIs as props to a component via `useApiHolder`.
8
+ - Updated dependencies
9
+ - @backstage/frontend-plugin-api@0.15.0-next.1
10
+ - @backstage/core-plugin-api@1.12.4-next.1
11
+ - @backstage/plugin-catalog-react@2.1.0-next.2
12
+ - @backstage/plugin-app-react@0.2.1-next.1
13
+
3
14
  ## 0.5.9-next.1
4
15
 
5
16
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode, JSX, ComponentType } from 'react';
2
+ import { ReactNode, JSX, ComponentType, PropsWithChildren } from 'react';
3
3
  import { AnalyticsApi, AnalyticsEvent, AnyApiFactory, IconComponent, BackstagePlugin, AppComponents, AppTheme, FeatureFlag, AnyRouteRefParams, RouteRef, SubRouteRef, ExternalRouteRef } from '@backstage/core-plugin-api';
4
- import { AnalyticsApi as AnalyticsApi$1, AnalyticsEvent as AnalyticsEvent$1, FrontendPlugin, FrontendModule, ExtensionDefinition, RouteRef as RouteRef$1, SubRouteRef as SubRouteRef$1, ExternalRouteRef as ExternalRouteRef$1 } from '@backstage/frontend-plugin-api';
4
+ import { AnalyticsApi as AnalyticsApi$1, AnalyticsEvent as AnalyticsEvent$1, FrontendPlugin, FrontendModule, ExtensionDefinition, RouteRef as RouteRef$1, SubRouteRef as SubRouteRef$1, ExternalRouteRef as ExternalRouteRef$1, TypesToApiRefs } from '@backstage/frontend-plugin-api';
5
5
 
6
6
  /**
7
7
  * Wraps a React element in a bidirectional compatibility provider, allow APIs
@@ -201,5 +201,16 @@ declare function convertLegacyRouteRef<TParams extends AnyRouteRefParams>(ref: S
201
201
  */
202
202
  declare function convertLegacyRouteRef<TParams extends AnyRouteRefParams>(ref: ExternalRouteRef$1<TParams>): ExternalRouteRef<TParams, true>;
203
203
 
204
- export { MultipleAnalyticsApi, NoOpAnalyticsApi, compatWrapper, convertLegacyApp, convertLegacyAppOptions, convertLegacyAppRoot, convertLegacyPageExtension, convertLegacyPlugin, convertLegacyRouteRef, convertLegacyRouteRefs };
204
+ /**
205
+ * Wrapper for giving component an API context.
206
+ *
207
+ * @param apis - APIs for the context.
208
+ * @public
209
+ */
210
+ declare function withApis<T extends {}>(apis: TypesToApiRefs<T>): <TProps extends T>(WrappedComponent: ComponentType<TProps>) => {
211
+ (props: PropsWithChildren<Omit<TProps, keyof T>>): react_jsx_runtime.JSX.Element;
212
+ displayName: string;
213
+ };
214
+
215
+ export { MultipleAnalyticsApi, NoOpAnalyticsApi, compatWrapper, convertLegacyApp, convertLegacyAppOptions, convertLegacyAppRoot, convertLegacyPageExtension, convertLegacyPlugin, convertLegacyRouteRef, convertLegacyRouteRefs, withApis };
205
216
  export type { ConvertLegacyAppOptions, ConvertLegacyAppRootOptions, ToNewRouteRef };
package/dist/index.esm.js CHANGED
@@ -6,4 +6,5 @@ export { convertLegacyAppOptions } from './convertLegacyAppOptions.esm.js';
6
6
  export { convertLegacyPlugin } from './convertLegacyPlugin.esm.js';
7
7
  export { convertLegacyPageExtension } from './convertLegacyPageExtension.esm.js';
8
8
  export { convertLegacyRouteRef, convertLegacyRouteRefs } from './convertLegacyRouteRef.esm.js';
9
+ export { withApis } from './withApis.esm.js';
9
10
  //# sourceMappingURL=index.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
1
+ {"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
@@ -0,0 +1,31 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { useApiHolder } from '@backstage/frontend-plugin-api';
3
+ import { NotImplementedError } from '@backstage/errors';
4
+
5
+ function withApis(apis) {
6
+ return function withApisWrapper(WrappedComponent) {
7
+ const Hoc = (props) => {
8
+ const apiHolder = useApiHolder();
9
+ const impls = {};
10
+ for (const key in apis) {
11
+ if (Object.hasOwn(apis, key)) {
12
+ const ref = apis[key];
13
+ const api = apiHolder.get(ref);
14
+ if (!api) {
15
+ throw new NotImplementedError(
16
+ `No implementation available for ${ref}`
17
+ );
18
+ }
19
+ impls[key] = api;
20
+ }
21
+ }
22
+ return /* @__PURE__ */ jsx(WrappedComponent, { ...props, ...impls });
23
+ };
24
+ const displayName = WrappedComponent.displayName || WrappedComponent.name || "Component";
25
+ Hoc.displayName = `withApis(${displayName})`;
26
+ return Hoc;
27
+ };
28
+ }
29
+
30
+ export { withApis };
31
+ //# sourceMappingURL=withApis.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withApis.esm.js","sources":["../src/withApis.tsx"],"sourcesContent":["/*\n * Copyright 2020 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 */\n\nimport { ComponentType, PropsWithChildren } from 'react';\nimport { TypesToApiRefs, useApiHolder } from '@backstage/frontend-plugin-api';\nimport { NotImplementedError } from '@backstage/errors';\n\n/**\n * Wrapper for giving component an API context.\n *\n * @param apis - APIs for the context.\n * @public\n */\nexport function withApis<T extends {}>(apis: TypesToApiRefs<T>) {\n return function withApisWrapper<TProps extends T>(\n WrappedComponent: ComponentType<TProps>,\n ) {\n const Hoc = (props: PropsWithChildren<Omit<TProps, keyof T>>) => {\n const apiHolder = useApiHolder();\n\n const impls = {} as T;\n\n for (const key in apis) {\n if (Object.hasOwn(apis, key)) {\n const ref = apis[key];\n\n const api = apiHolder.get(ref);\n if (!api) {\n throw new NotImplementedError(\n `No implementation available for ${ref}`,\n );\n }\n impls[key] = api;\n }\n }\n\n return <WrappedComponent {...(props as TProps)} {...impls} />;\n };\n const displayName =\n WrappedComponent.displayName || WrappedComponent.name || 'Component';\n\n Hoc.displayName = `withApis(${displayName})`;\n\n return Hoc;\n };\n}\n"],"names":[],"mappings":";;;;AA0BO,SAAS,SAAuB,IAAA,EAAyB;AAC9D,EAAA,OAAO,SAAS,gBACd,gBAAA,EACA;AACA,IAAA,MAAM,GAAA,GAAM,CAAC,KAAA,KAAoD;AAC/D,MAAA,MAAM,YAAY,YAAA,EAAa;AAE/B,MAAA,MAAM,QAAQ,EAAC;AAEf,MAAA,KAAA,MAAW,OAAO,IAAA,EAAM;AACtB,QAAA,IAAI,MAAA,CAAO,MAAA,CAAO,IAAA,EAAM,GAAG,CAAA,EAAG;AAC5B,UAAA,MAAM,GAAA,GAAM,KAAK,GAAG,CAAA;AAEpB,UAAA,MAAM,GAAA,GAAM,SAAA,CAAU,GAAA,CAAI,GAAG,CAAA;AAC7B,UAAA,IAAI,CAAC,GAAA,EAAK;AACR,YAAA,MAAM,IAAI,mBAAA;AAAA,cACR,mCAAmC,GAAG,CAAA;AAAA,aACxC;AAAA,UACF;AACA,UAAA,KAAA,CAAM,GAAG,CAAA,GAAI,GAAA;AAAA,QACf;AAAA,MACF;AAEA,MAAA,uBAAO,GAAA,CAAC,gBAAA,EAAA,EAAkB,GAAI,KAAA,EAAmB,GAAG,KAAA,EAAO,CAAA;AAAA,IAC7D,CAAA;AACA,IAAA,MAAM,WAAA,GACJ,gBAAA,CAAiB,WAAA,IAAe,gBAAA,CAAiB,IAAA,IAAQ,WAAA;AAE3D,IAAA,GAAA,CAAI,WAAA,GAAc,YAAY,WAAW,CAAA,CAAA,CAAA;AAEzC,IAAA,OAAO,GAAA;AAAA,EACT,CAAA;AACF;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/core-compat-api",
3
- "version": "0.5.9-next.1",
3
+ "version": "0.5.9-next.2",
4
4
  "backstage": {
5
5
  "role": "web-library"
6
6
  },
@@ -31,21 +31,22 @@
31
31
  "test": "backstage-cli package test"
32
32
  },
33
33
  "dependencies": {
34
- "@backstage/core-plugin-api": "1.12.4-next.0",
35
- "@backstage/frontend-plugin-api": "0.14.2-next.0",
36
- "@backstage/plugin-app-react": "0.2.1-next.0",
37
- "@backstage/plugin-catalog-react": "2.1.0-next.1",
34
+ "@backstage/core-plugin-api": "1.12.4-next.1",
35
+ "@backstage/errors": "1.2.7",
36
+ "@backstage/frontend-plugin-api": "0.15.0-next.1",
37
+ "@backstage/plugin-app-react": "0.2.1-next.1",
38
+ "@backstage/plugin-catalog-react": "2.1.0-next.2",
38
39
  "@backstage/types": "1.2.2",
39
40
  "@backstage/version-bridge": "1.0.12",
40
41
  "lodash": "^4.17.21",
41
42
  "zod": "^3.25.76"
42
43
  },
43
44
  "devDependencies": {
44
- "@backstage/cli": "0.36.0-next.1",
45
- "@backstage/core-app-api": "1.19.6-next.0",
46
- "@backstage/frontend-app-api": "0.15.1-next.0",
47
- "@backstage/frontend-test-utils": "0.5.1-next.1",
48
- "@backstage/plugin-catalog": "1.34.0-next.1",
45
+ "@backstage/cli": "0.36.0-next.2",
46
+ "@backstage/core-app-api": "1.19.6-next.1",
47
+ "@backstage/frontend-app-api": "0.16.0-next.1",
48
+ "@backstage/frontend-test-utils": "0.5.1-next.2",
49
+ "@backstage/plugin-catalog": "2.0.0-next.2",
49
50
  "@backstage/test-utils": "1.7.16-next.0",
50
51
  "@backstage/types": "1.2.2",
51
52
  "@testing-library/jest-dom": "^6.0.0",