@webiny/app 0.0.0-unstable.e622468070 → 0.0.0-unstable.e6f0dc8ca7
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/App.d.ts +3 -3
- package/App.js +7 -10
- package/App.js.map +1 -1
- package/core/Plugin.d.ts +1 -1
- package/core/Plugins.d.ts +1 -1
- package/core/Plugins.js.map +1 -1
- package/exports/admin/env-config.d.ts +2 -0
- package/exports/admin/env-config.js +4 -0
- package/exports/admin/env-config.js.map +1 -0
- package/exports/admin/{graphqlClient.js → graphql-client.js} +1 -1
- package/exports/admin/graphql-client.js.map +1 -0
- package/exports/admin/{localStorage.js → local-storage.js} +1 -1
- package/exports/admin/local-storage.js.map +1 -0
- package/exports/admin/router.d.ts +1 -0
- package/exports/admin/router.js +1 -0
- package/exports/admin/router.js.map +1 -1
- package/exports/admin.d.ts +1 -0
- package/exports/admin.js +1 -0
- package/exports/admin.js.map +1 -1
- package/features/envConfig/EnvConfig.d.ts +1 -0
- package/features/envConfig/EnvConfig.js +3 -0
- package/features/envConfig/EnvConfig.js.map +1 -1
- package/features/envConfig/abstractions.d.ts +1 -0
- package/features/envConfig/abstractions.js.map +1 -1
- package/features/eventPublisher/feature.d.ts +3 -1
- package/features/eventPublisher/feature.js +5 -0
- package/features/eventPublisher/feature.js.map +1 -1
- package/features/graphqlClient/BatchingGraphQLClient.d.ts +1 -3
- package/features/graphqlClient/BatchingGraphQLClient.js +13 -14
- package/features/graphqlClient/BatchingGraphQLClient.js.map +1 -1
- package/features/graphqlClient/FetchGraphQLClient.d.ts +0 -3
- package/features/graphqlClient/FetchGraphQLClient.js +4 -8
- package/features/graphqlClient/FetchGraphQLClient.js.map +1 -1
- package/features/graphqlClient/RequestValue.d.ts +1 -0
- package/features/graphqlClient/RequestValue.js +3 -0
- package/features/graphqlClient/RequestValue.js.map +1 -1
- package/features/graphqlClient/__tests__/GraphQLClient.test.js +20 -0
- package/features/graphqlClient/__tests__/GraphQLClient.test.js.map +1 -1
- package/features/graphqlClient/abstractions.d.ts +1 -0
- package/features/graphqlClient/abstractions.js.map +1 -1
- package/features/mainGraphQLClient/MainGraphQLClient.d.ts +11 -0
- package/features/mainGraphQLClient/MainGraphQLClient.js +23 -0
- package/features/mainGraphQLClient/MainGraphQLClient.js.map +1 -0
- package/features/mainGraphQLClient/abstractions.d.ts +17 -0
- package/features/mainGraphQLClient/abstractions.js +4 -0
- package/features/mainGraphQLClient/abstractions.js.map +1 -0
- package/features/mainGraphQLClient/feature.d.ts +3 -0
- package/features/mainGraphQLClient/feature.js +16 -0
- package/features/mainGraphQLClient/feature.js.map +1 -0
- package/features/mainGraphQLClient/index.d.ts +1 -0
- package/features/mainGraphQLClient/index.js +3 -0
- package/features/mainGraphQLClient/index.js.map +1 -0
- package/features/router/HistoryRouterGateway.d.ts +7 -3
- package/features/router/HistoryRouterGateway.js +60 -24
- package/features/router/HistoryRouterGateway.js.map +1 -1
- package/features/router/Route.js +5 -5
- package/features/router/Route.js.map +1 -1
- package/features/router/RouterPresenter.d.ts +6 -2
- package/features/router/RouterPresenter.js +14 -2
- package/features/router/RouterPresenter.js.map +1 -1
- package/features/router/RouterRepository.d.ts +12 -3
- package/features/router/RouterRepository.js +61 -7
- package/features/router/RouterRepository.js.map +1 -1
- package/features/router/RouterRepository.test.js +42 -27
- package/features/router/RouterRepository.test.js.map +1 -1
- package/features/router/abstractions.d.ts +20 -7
- package/features/router/abstractions.js +2 -0
- package/features/router/abstractions.js.map +1 -1
- package/features/router/index.d.ts +1 -0
- package/features/router/index.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/package.json +29 -26
- package/plugins/components/Image.js.map +1 -1
- package/presentation/envConfig/useEnvConfig.d.ts +6 -0
- package/presentation/envConfig/useEnvConfig.js +13 -0
- package/presentation/envConfig/useEnvConfig.js.map +1 -0
- package/presentation/router/components/Redirect.d.ts +14 -0
- package/presentation/router/components/Redirect.js +15 -0
- package/presentation/router/components/Redirect.js.map +1 -0
- package/presentation/router/components/RouteContent.js +7 -1
- package/presentation/router/components/RouteContent.js.map +1 -1
- package/presentation/router/hooks/useRoute.js +1 -1
- package/presentation/router/hooks/useRoute.js.map +1 -1
- package/presentation/router/hooks/useRouter.d.ts +5 -1
- package/presentation/router/hooks/useRouter.js +5 -1
- package/presentation/router/hooks/useRouter.js.map +1 -1
- package/presentation/router/types.d.ts +1 -1
- package/presentation/router/types.js.map +1 -1
- package/react-butterfiles/Files.js +1 -1
- package/react-butterfiles/Files.js.map +1 -1
- package/renderApp.d.ts +1 -1
- package/renderApp.js.map +1 -1
- package/shared/di/useFeature.js +2 -12
- package/shared/di/useFeature.js.map +1 -1
- package/core/DebounceRender.d.ts +0 -12
- package/core/DebounceRender.js +0 -31
- package/core/DebounceRender.js.map +0 -1
- package/core/Routes.d.ts +0 -7
- package/core/Routes.js +0 -33
- package/core/Routes.js.map +0 -1
- package/exports/admin/envConfig.d.ts +0 -1
- package/exports/admin/envConfig.js +0 -3
- package/exports/admin/envConfig.js.map +0 -1
- package/exports/admin/graphqlClient.js.map +0 -1
- package/exports/admin/localStorage.js.map +0 -1
- /package/exports/admin/{graphqlClient.d.ts → graphql-client.d.ts} +0 -0
- /package/exports/admin/{localStorage.d.ts → local-storage.d.ts} +0 -0
package/App.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { Decorator, DecoratorsCollection, GenericComponent } from "@webiny/react-composition";
|
|
3
3
|
interface State {
|
|
4
|
-
plugins: JSX.Element[];
|
|
4
|
+
plugins: React.JSX.Element[];
|
|
5
5
|
providers: Decorator<GenericComponent<ProviderProps>>[];
|
|
6
6
|
}
|
|
7
7
|
interface AppContext extends State {
|
|
@@ -11,8 +11,8 @@ interface AppContext extends State {
|
|
|
11
11
|
declare const AppContext: React.Context<AppContext | undefined>;
|
|
12
12
|
export declare const useApp: () => AppContext;
|
|
13
13
|
export interface AppProps {
|
|
14
|
-
debounceRender?: number;
|
|
15
14
|
routes?: Array<any>;
|
|
15
|
+
plugins?: any[];
|
|
16
16
|
providers?: Array<Decorator<GenericComponent<ProviderProps>>>;
|
|
17
17
|
decorators?: DecoratorsCollection;
|
|
18
18
|
children?: React.ReactNode | React.ReactNode[];
|
|
@@ -20,6 +20,6 @@ export interface AppProps {
|
|
|
20
20
|
interface ProviderProps {
|
|
21
21
|
children: React.ReactNode;
|
|
22
22
|
}
|
|
23
|
-
export declare const AppBase: React.MemoExoticComponent<({
|
|
23
|
+
export declare const AppBase: React.MemoExoticComponent<({ routes, plugins, providers, children }: AppProps) => React.JSX.Element>;
|
|
24
24
|
export declare const App: ({ decorators, ...props }: AppProps) => React.JSX.Element;
|
|
25
25
|
export {};
|
package/App.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
|
|
1
|
+
import React, { createContext, Fragment, useCallback, useContext, useEffect, useMemo, useState } from "react";
|
|
2
2
|
import { compose, CompositionProvider } from "@webiny/react-composition";
|
|
3
|
-
import { DebounceRender } from "./core/DebounceRender.js";
|
|
4
3
|
import { PluginsProvider } from "./core/Plugins.js";
|
|
5
4
|
import { RouterWithConfig, useRouterConfig } from "./config/RouterConfig.js";
|
|
6
5
|
import { AppContainer } from "./AppContainer.js";
|
|
@@ -16,13 +15,13 @@ export const useApp = () => {
|
|
|
16
15
|
return appContext;
|
|
17
16
|
};
|
|
18
17
|
export const AppBase = /*#__PURE__*/React.memo(({
|
|
19
|
-
debounceRender = 50,
|
|
20
18
|
routes = [],
|
|
19
|
+
plugins = [],
|
|
21
20
|
providers = [],
|
|
22
21
|
children
|
|
23
22
|
}) => {
|
|
24
23
|
const [state, setState] = useState({
|
|
25
|
-
plugins
|
|
24
|
+
plugins,
|
|
26
25
|
providers
|
|
27
26
|
});
|
|
28
27
|
const addProvider = useCallback(component => {
|
|
@@ -65,17 +64,15 @@ export const AppBase = /*#__PURE__*/React.memo(({
|
|
|
65
64
|
return /*#__PURE__*/React.memo(compose(...(state.providers || []))(({
|
|
66
65
|
children
|
|
67
66
|
}) => {
|
|
68
|
-
return /*#__PURE__*/React.createElement(
|
|
69
|
-
wait: debounceRender
|
|
70
|
-
}, children);
|
|
67
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
71
68
|
}));
|
|
72
69
|
}, [state.providers.length]);
|
|
73
70
|
Providers.displayName = "Providers";
|
|
74
71
|
return /*#__PURE__*/React.createElement(AppContext.Provider, {
|
|
75
72
|
value: appContext
|
|
76
|
-
}, children, /*#__PURE__*/React.createElement(AppContainer, null, /*#__PURE__*/React.createElement(Providers, null, /*#__PURE__*/React.createElement(PluginsProvider, null, state.plugins
|
|
77
|
-
|
|
78
|
-
}, /*#__PURE__*/React.createElement(RouterWithConfig, null, /*#__PURE__*/React.createElement(AppRouter, null), /*#__PURE__*/React.createElement(RouteContent, null)))))
|
|
73
|
+
}, children, /*#__PURE__*/React.createElement(AppContainer, null, /*#__PURE__*/React.createElement(Providers, null, /*#__PURE__*/React.createElement(PluginsProvider, null, state.plugins.map((plugin, index) => /*#__PURE__*/React.createElement(Fragment, {
|
|
74
|
+
key: index
|
|
75
|
+
}, plugin))), /*#__PURE__*/React.createElement(RouterWithConfig, null, /*#__PURE__*/React.createElement(AppRouter, null), /*#__PURE__*/React.createElement(RouteContent, null)))));
|
|
79
76
|
});
|
|
80
77
|
AppBase.displayName = "AppBase";
|
|
81
78
|
export const App = ({
|
package/App.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","createContext","useCallback","useContext","useEffect","useMemo","useState","compose","CompositionProvider","
|
|
1
|
+
{"version":3,"names":["React","createContext","Fragment","useCallback","useContext","useEffect","useMemo","useState","compose","CompositionProvider","PluginsProvider","RouterWithConfig","useRouterConfig","AppContainer","RouteContent","useRouter","AppContext","undefined","displayName","useApp","appContext","Error","AppBase","memo","routes","plugins","providers","children","state","setState","addProvider","component","findIndex","m","addPlugin","element","AppRouter","router","routerConfig","routesFromConfig","combinedRoutes","setRoutes","length","Providers","createElement","Provider","value","map","plugin","index","key","App","decorators","props","Object","assign"],"sources":["App.tsx"],"sourcesContent":["import React, {\n createContext,\n Fragment,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState\n} from \"react\";\nimport {\n compose,\n CompositionProvider,\n Decorator,\n DecoratorsCollection,\n GenericComponent\n} from \"@webiny/react-composition\";\nimport { PluginsProvider } from \"./core/Plugins.js\";\nimport { RouterWithConfig, useRouterConfig } from \"./config/RouterConfig.js\";\nimport { AppContainer } from \"./AppContainer.js\";\nimport { RouteContent } from \"~/presentation/router/components/RouteContent.js\";\nimport { useRouter } from \"~/router.js\";\n\ninterface State {\n plugins: React.JSX.Element[];\n providers: Decorator<GenericComponent<ProviderProps>>[];\n}\n\ninterface AppContext extends State {\n addProvider(hoc: Decorator<GenericComponent<ProviderProps>>): void;\n addPlugin(plugin: React.ReactNode): void;\n}\n\nconst AppContext = createContext<AppContext | undefined>(undefined);\n\nAppContext.displayName = \"AppContext\";\n\nexport const useApp = () => {\n const appContext = useContext(AppContext);\n if (!appContext) {\n throw Error(\n `AppContext provider was not found. Are you using the \"useApp()\" hook in the right place?`\n );\n }\n return appContext;\n};\n\nexport interface AppProps {\n routes?: Array<any>;\n plugins?: any[];\n providers?: Array<Decorator<GenericComponent<ProviderProps>>>;\n decorators?: DecoratorsCollection;\n children?: React.ReactNode | React.ReactNode[];\n}\n\ninterface ProviderProps {\n children: React.ReactNode;\n}\n\ntype ComponentWithChildren = React.ComponentType<{ children?: React.ReactNode }>;\n\nexport const AppBase = React.memo(\n ({ routes = [], plugins = [], providers = [], children }: AppProps) => {\n const [state, setState] = useState<State>({\n plugins,\n providers\n });\n\n const addProvider = useCallback((component: Decorator<any>) => {\n setState(state => {\n if (state.providers.findIndex(m => m === component) > -1) {\n return state;\n }\n\n return {\n ...state,\n providers: [...state.providers, component]\n };\n });\n }, []);\n\n const addPlugin = useCallback((element: React.JSX.Element) => {\n setState(state => {\n return {\n ...state,\n plugins: [...state.plugins, element]\n };\n });\n }, []);\n\n const appContext = useMemo(\n () => ({\n ...state,\n addProvider,\n addPlugin\n }),\n [state]\n );\n\n const AppRouter = useMemo(() => {\n return function AppRouter() {\n const router = useRouter();\n const routerConfig = useRouterConfig();\n const routesFromConfig = routerConfig.routes;\n const combinedRoutes = [...routes, ...routesFromConfig];\n\n useEffect(() => {\n router.setRoutes(combinedRoutes);\n }, [combinedRoutes.length]);\n\n return null;\n };\n }, []);\n\n const Providers = useMemo(() => {\n return React.memo(\n compose(...(state.providers || []))(({ children }: ProviderProps) => {\n return <>{children}</>;\n })\n );\n }, [state.providers.length]) as ComponentWithChildren;\n\n Providers.displayName = \"Providers\";\n\n return (\n <AppContext.Provider value={appContext}>\n {children}\n <AppContainer>\n <Providers>\n <PluginsProvider>\n {state.plugins.map((plugin, index) => (\n <Fragment key={index}>{plugin}</Fragment>\n ))}\n </PluginsProvider>\n <RouterWithConfig>\n <AppRouter />\n <RouteContent />\n </RouterWithConfig>\n </Providers>\n </AppContainer>\n </AppContext.Provider>\n );\n }\n);\n\nAppBase.displayName = \"AppBase\";\n\nexport const App = ({ decorators, ...props }: AppProps) => {\n return (\n <CompositionProvider decorators={decorators}>\n <AppBase decorators={decorators} {...props} />\n </CompositionProvider>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,IACRC,aAAa,EACbC,QAAQ,EACRC,WAAW,EACXC,UAAU,EACVC,SAAS,EACTC,OAAO,EACPC,QAAQ,QACL,OAAO;AACd,SACIC,OAAO,EACPC,mBAAmB,QAIhB,2BAA2B;AAClC,SAASC,eAAe;AACxB,SAASC,gBAAgB,EAAEC,eAAe;AAC1C,SAASC,YAAY;AACrB,SAASC,YAAY;AACrB,SAASC,SAAS;AAYlB,MAAMC,UAAU,gBAAGf,aAAa,CAAyBgB,SAAS,CAAC;AAEnED,UAAU,CAACE,WAAW,GAAG,YAAY;AAErC,OAAO,MAA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ED,MAAiB,CAC3C,CACY,CAAC,eAClBhD,KAAA,CAAA4C,aAAA,CAACjC,gBAAgB,qBACbX,KAAA,CAAA4C,aAAA,CAACR,SAAS,MAAE,CAAC,eACbpC,KAAA,CAAA4C,aAAA,CAAC9B,YAAY,MAAE,CACD,CACX,CACD,CACG,CAAC;AAE9B,CACJ,CAAC;AAEDQ,OAAO,CAACJ,WAAW,GAAG,SAAS;AAE/B,OAAO,MAAMiC,GAAG,GAAGA,CAAC;EAAEC,UAAU;EAAE,GAAGC;AAAgB,CAAC,KAAK;EACvD,oBACIrD,KAAA,CAAA4C,aAAA,CAACnC,mBAAmB;IAAC2C,UAAU,EAAEA;EAAW,gBACxCpD,KAAA,CAAA4C,aAAA,CAACtB,OAAO,EAAAgC,MAAA,CAAAC,MAAA;IAACH,UAAU,EAAEA;EAAW,GAAKC,KAAK,CAAG,CAC5B,CAAC;AAE9B,CAAC","ignoreList":[]}
|
package/core/Plugin.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ interface PluginProps {
|
|
|
4
4
|
providers?: Decorator<GenericComponent>[];
|
|
5
5
|
children?: React.ReactNode;
|
|
6
6
|
}
|
|
7
|
-
export declare const Plugin: React.
|
|
7
|
+
export declare const Plugin: React.MemoExoticComponent<({ providers, children }: PluginProps) => React.JSX.Element>;
|
|
8
8
|
export {};
|
package/core/Plugins.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
export declare const PluginsContext: React.Context<boolean>;
|
|
3
3
|
interface PluginsProviderComponentProps {
|
|
4
|
-
children: JSX.Element[];
|
|
4
|
+
children: React.JSX.Element[];
|
|
5
5
|
}
|
|
6
6
|
export declare const PluginsProvider: React.MemoExoticComponent<({ children }: PluginsProviderComponentProps) => React.JSX.Element>;
|
|
7
7
|
/**
|
package/core/Plugins.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","Children","createContext","Fragment","memo","useContext","useEffect","useApp","PluginsContext","displayName","PluginsProviderComponent","children","createElement","Provider","value","PluginsProvider","Plugins","addPlugin","hasParentPlugin","forEach","child"],"sources":["Plugins.tsx"],"sourcesContent":["import React, { Children, createContext, Fragment, memo, useContext, useEffect } from \"react\";\nimport { useApp } from \"~/App.js\";\n\nexport const PluginsContext = createContext<boolean>(false);\nPluginsContext.displayName = \"PluginsContext\";\n\ninterface PluginsProviderComponentProps {\n children: JSX.Element[];\n}\nconst PluginsProviderComponent = ({ children }: PluginsProviderComponentProps) => {\n /**\n * This context only serves as a safeguard. We need to warn users when they mount a plugin without using\n * the <Plugins> component. In that case, the context will not be available, and we can log warnings.\n */\n return <PluginsContext.Provider value={true}>{children}</PluginsContext.Provider>;\n};\n\nexport const PluginsProvider = memo(PluginsProviderComponent);\n\n/**\n * @param children\n * @deprecated This component should not be used directly. Use the <Plugin> component to create plugins.\n */\ninterface PluginsComponentsProps {\n children: React.ReactNode;\n}\nexport const Plugins = React.memo(({ children }: PluginsComponentsProps) => {\n const { addPlugin } = useApp();\n const hasParentPlugin = useContext(PluginsContext);\n\n useEffect(() => {\n if (hasParentPlugin) {\n return;\n }\n\n Children.forEach(children, child => addPlugin(child));\n }, []);\n\n return hasParentPlugin ? <Fragment>{children}</Fragment> : null;\n});\n\nPlugins.displayName = \"Plugins\";\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,aAAa,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,UAAU,EAAEC,SAAS,QAAQ,OAAO;AAC7F,SAASC,MAAM;AAEf,OAAO,MAAMC,cAAc,gBAAGN,aAAa,CAAU,KAAK,CAAC;AAC3DM,cAAc,CAACC,WAAW,GAAG,gBAAgB;AAK7C,MAAMC,wBAAwB,GAAGA,CAAC;EAAEC;AAAwC,CAAC,KAAK;EAC9E;AACJ;AACA;AACA;EACI,oBAAOX,KAAA,CAAAY,aAAA,CAACJ,cAAc,CAACK,QAAQ;IAACC,KAAK,EAAE;EAAK,GAAEH,QAAkC,CAAC;AACrF,CAAC;AAED,OAAO,MAAMI,eAAe,gBAAGX,IAAI,CAACM,wBAAwB,CAAC;;AAE7D;AACA;AACA;AACA;;AAIA,OAAO,MAAMM,OAAO,gBAAGhB,KAAK,CAACI,IAAI,CAAC,CAAC;EAAEO;AAAiC,CAAC,KAAK;EACxE,MAAM;IAAEM;EAAU,CAAC,GAAGV,MAAM,CAAC,CAAC;EAC9B,MAAMW,eAAe,GAAGb,UAAU,CAACG,cAAc,CAAC;EAElDF,SAAS,CAAC,MAAM;IACZ,IAAIY,eAAe,EAAE;MACjB;IACJ;IAEAjB,QAAQ,CAACkB,OAAO,CAACR,QAAQ,EAAES,KAAK,IAAIH,SAAS,CAACG,KAAK,CAAC,CAAC;EACzD,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOF,eAAe,gBAAGlB,KAAA,CAAAY,aAAA,CAACT,QAAQ,QAAEQ,QAAmB,CAAC,GAAG,IAAI;AACnE,CAAC,CAAC;AAEFK,OAAO,CAACP,WAAW,GAAG,SAAS","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["React","Children","createContext","Fragment","memo","useContext","useEffect","useApp","PluginsContext","displayName","PluginsProviderComponent","children","createElement","Provider","value","PluginsProvider","Plugins","addPlugin","hasParentPlugin","forEach","child"],"sources":["Plugins.tsx"],"sourcesContent":["import React, { Children, createContext, Fragment, memo, useContext, useEffect } from \"react\";\nimport { useApp } from \"~/App.js\";\n\nexport const PluginsContext = createContext<boolean>(false);\nPluginsContext.displayName = \"PluginsContext\";\n\ninterface PluginsProviderComponentProps {\n children: React.JSX.Element[];\n}\nconst PluginsProviderComponent = ({ children }: PluginsProviderComponentProps) => {\n /**\n * This context only serves as a safeguard. We need to warn users when they mount a plugin without using\n * the <Plugins> component. In that case, the context will not be available, and we can log warnings.\n */\n return <PluginsContext.Provider value={true}>{children}</PluginsContext.Provider>;\n};\n\nexport const PluginsProvider = memo(PluginsProviderComponent);\n\n/**\n * @param children\n * @deprecated This component should not be used directly. Use the <Plugin> component to create plugins.\n */\ninterface PluginsComponentsProps {\n children: React.ReactNode;\n}\nexport const Plugins = React.memo(({ children }: PluginsComponentsProps) => {\n const { addPlugin } = useApp();\n const hasParentPlugin = useContext(PluginsContext);\n\n useEffect(() => {\n if (hasParentPlugin) {\n return;\n }\n\n Children.forEach(children, child => addPlugin(child));\n }, []);\n\n return hasParentPlugin ? <Fragment>{children}</Fragment> : null;\n});\n\nPlugins.displayName = \"Plugins\";\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,aAAa,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,UAAU,EAAEC,SAAS,QAAQ,OAAO;AAC7F,SAASC,MAAM;AAEf,OAAO,MAAMC,cAAc,gBAAGN,aAAa,CAAU,KAAK,CAAC;AAC3DM,cAAc,CAACC,WAAW,GAAG,gBAAgB;AAK7C,MAAMC,wBAAwB,GAAGA,CAAC;EAAEC;AAAwC,CAAC,KAAK;EAC9E;AACJ;AACA;AACA;EACI,oBAAOX,KAAA,CAAAY,aAAA,CAACJ,cAAc,CAACK,QAAQ;IAACC,KAAK,EAAE;EAAK,GAAEH,QAAkC,CAAC;AACrF,CAAC;AAED,OAAO,MAAMI,eAAe,gBAAGX,IAAI,CAACM,wBAAwB,CAAC;;AAE7D;AACA;AACA;AACA;;AAIA,OAAO,MAAMM,OAAO,gBAAGhB,KAAK,CAACI,IAAI,CAAC,CAAC;EAAEO;AAAiC,CAAC,KAAK;EACxE,MAAM;IAAEM;EAAU,CAAC,GAAGV,MAAM,CAAC,CAAC;EAC9B,MAAMW,eAAe,GAAGb,UAAU,CAACG,cAAc,CAAC;EAElDF,SAAS,CAAC,MAAM;IACZ,IAAIY,eAAe,EAAE;MACjB;IACJ;IAEAjB,QAAQ,CAACkB,OAAO,CAACR,QAAQ,EAAES,KAAK,IAAIH,SAAS,CAACG,KAAK,CAAC,CAAC;EACzD,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOF,eAAe,gBAAGlB,KAAA,CAAAY,aAAA,CAACT,QAAQ,QAAEQ,QAAmB,CAAC,GAAG,IAAI;AACnE,CAAC,CAAC;AAEFK,OAAO,CAACP,WAAW,GAAG,SAAS","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["EnvConfig","useEnvConfig"],"sources":["env-config.ts"],"sourcesContent":["export { EnvConfig } from \"~/features/envConfig/index.js\";\nexport { useEnvConfig } from \"~/presentation/envConfig/useEnvConfig.js\";\n"],"mappings":"AAAA,SAASA,SAAS;AAClB,SAASC,YAAY","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["GraphQLClient"],"sources":["graphql-client.ts"],"sourcesContent":["export { GraphQLClient } from \"~/features/graphqlClient/abstractions.js\";\n"],"mappings":"AAAA,SAASA,aAAa","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { LocalStorage } from "../../features/localStorage/abstractions.js";
|
|
2
2
|
export { useLocalStorage, useLocalStorageValue, useLocalStorageValues } from "../../presentation/localStorage/index.js";
|
|
3
3
|
|
|
4
|
-
//# sourceMappingURL=
|
|
4
|
+
//# sourceMappingURL=local-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["LocalStorage","useLocalStorage","useLocalStorageValue","useLocalStorageValues"],"sources":["local-storage.ts"],"sourcesContent":["export { LocalStorage } from \"~/features/localStorage/abstractions.js\";\nexport {\n useLocalStorage,\n useLocalStorageValue,\n useLocalStorageValues\n} from \"~/presentation/localStorage/index.js\";\n"],"mappings":"AAAA,SAASA,YAAY;AACrB,SACIC,eAAe,EACfC,oBAAoB,EACpBC,qBAAqB","ignoreList":[]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { Route } from "../../features/router/Route.js";
|
|
2
2
|
export { RouteLinkComponent } from "../../presentation/router/components/RouteLink.js";
|
|
3
3
|
export { LinkComponent } from "../../presentation/router/components/SimpleLink.js";
|
|
4
|
+
export { RedirectComponent } from "../../presentation/router/components/Redirect.js";
|
|
4
5
|
export { useRoute, useRouter } from "../../presentation/router/index.js";
|
package/exports/admin/router.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { Route } from "../../features/router/Route.js";
|
|
2
2
|
export { RouteLinkComponent } from "../../presentation/router/components/RouteLink.js";
|
|
3
3
|
export { LinkComponent } from "../../presentation/router/components/SimpleLink.js";
|
|
4
|
+
export { RedirectComponent } from "../../presentation/router/components/Redirect.js";
|
|
4
5
|
export { useRoute, useRouter } from "../../presentation/router/index.js";
|
|
5
6
|
|
|
6
7
|
//# sourceMappingURL=router.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Route","RouteLinkComponent","LinkComponent","useRoute","useRouter"],"sources":["router.ts"],"sourcesContent":["export { Route } from \"~/features/router/Route.js\";\nexport { RouteLinkComponent } from \"~/presentation/router/components/RouteLink.js\";\nexport { LinkComponent } from \"~/presentation/router/components/SimpleLink.js\";\nexport { useRoute, useRouter } from \"~/presentation/router/index.js\";\n"],"mappings":"AAAA,SAASA,KAAK;AACd,SAASC,kBAAkB;AAC3B,SAASC,aAAa;AACtB,SAASC,QAAQ,EAAEC,SAAS","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["Route","RouteLinkComponent","LinkComponent","RedirectComponent","useRoute","useRouter"],"sources":["router.ts"],"sourcesContent":["export { Route } from \"~/features/router/Route.js\";\nexport { RouteLinkComponent } from \"~/presentation/router/components/RouteLink.js\";\nexport { LinkComponent } from \"~/presentation/router/components/SimpleLink.js\";\nexport { RedirectComponent } from \"~/presentation/router/components/Redirect.js\";\nexport { useRoute, useRouter } from \"~/presentation/router/index.js\";\n"],"mappings":"AAAA,SAASA,KAAK;AACd,SAASC,kBAAkB;AAC3B,SAASC,aAAa;AACtB,SAASC,iBAAiB;AAC1B,SAASC,QAAQ,EAAEC,SAAS","ignoreList":[]}
|
package/exports/admin.d.ts
CHANGED
package/exports/admin.js
CHANGED
package/exports/admin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useFeature","NetworkErrorEventHandler","createProviderPlugin","createProvider","Provider","Plugin"],"sources":["admin.ts"],"sourcesContent":["export { useFeature } from \"~/shared/di/useFeature.js\";\nexport { NetworkErrorEventHandler } from \"~/errors/index.js\";\nexport { createProviderPlugin } from \"~/core/createProviderPlugin.js\";\nexport { createProvider } from \"~/core/createProvider.js\";\nexport { Provider } from \"~/core/Provider.js\";\nexport { Plugin } from \"~/core/Plugin.js\";\n"],"mappings":"AAAA,SAASA,UAAU;AACnB,SAASC,wBAAwB;AACjC,SAASC,oBAAoB;AAC7B,SAASC,cAAc;AACvB,SAASC,QAAQ;AACjB,SAASC,MAAM","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["MainGraphQLClient","useFeature","NetworkErrorEventHandler","createProviderPlugin","createProvider","Provider","Plugin"],"sources":["admin.ts"],"sourcesContent":["export { MainGraphQLClient } from \"~/features/mainGraphQLClient/index.js\";\nexport { useFeature } from \"~/shared/di/useFeature.js\";\nexport { NetworkErrorEventHandler } from \"~/errors/index.js\";\nexport { createProviderPlugin } from \"~/core/createProviderPlugin.js\";\nexport { createProvider } from \"~/core/createProvider.js\";\nexport { Provider } from \"~/core/Provider.js\";\nexport { Plugin } from \"~/core/Plugin.js\";\n"],"mappings":"AAAA,SAASA,iBAAiB;AAC1B,SAASC,UAAU;AACnB,SAASC,wBAAwB;AACjC,SAASC,oBAAoB;AAC7B,SAASC,cAAc;AACvB,SAASC,QAAQ;AACjB,SAASC,MAAM","ignoreList":[]}
|
|
@@ -3,4 +3,5 @@ export declare class DefaultEnvConfig implements Abstraction.Interface {
|
|
|
3
3
|
private readonly env;
|
|
4
4
|
constructor(env: Abstraction.Config);
|
|
5
5
|
get<K extends keyof Abstraction.Config>(key: K, defaultValue?: Abstraction.Config[K]): Abstraction.Config[K];
|
|
6
|
+
getAll(): Abstraction.Config;
|
|
6
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DefaultEnvConfig","constructor","env","get","key","defaultValue","rawValue","undefined"],"sources":["EnvConfig.ts"],"sourcesContent":["import { EnvConfig as Abstraction } from \"./abstractions.js\";\n\nexport class DefaultEnvConfig implements Abstraction.Interface {\n private readonly env: Abstraction.Config;\n\n constructor(env: Abstraction.Config) {\n this.env = env;\n }\n\n public get<K extends keyof Abstraction.Config>(\n key: K,\n defaultValue?: Abstraction.Config[K]\n ): Abstraction.Config[K] {\n const rawValue = this.env[key];\n\n if ((rawValue === undefined || rawValue === null) && defaultValue !== undefined) {\n return defaultValue;\n }\n\n return rawValue;\n }\n}\n"],"mappings":"AAEA,OAAO,MAAMA,gBAAgB,CAAkC;EAG3DC,WAAWA,CAACC,GAAuB,EAAE;IACjC,IAAI,CAACA,GAAG,GAAGA,GAAG;EAClB;EAEOC,GAAGA,CACNC,GAAM,EACNC,YAAoC,EACf;IACrB,MAAMC,QAAQ,GAAG,IAAI,CAACJ,GAAG,CAACE,GAAG,CAAC;IAE9B,IAAI,CAACE,QAAQ,KAAKC,SAAS,IAAID,QAAQ,KAAK,IAAI,KAAKD,YAAY,KAAKE,SAAS,EAAE;MAC7E,OAAOF,YAAY;IACvB;IAEA,OAAOC,QAAQ;EACnB;AACJ","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["DefaultEnvConfig","constructor","env","get","key","defaultValue","rawValue","undefined","getAll"],"sources":["EnvConfig.ts"],"sourcesContent":["import { EnvConfig as Abstraction } from \"./abstractions.js\";\n\nexport class DefaultEnvConfig implements Abstraction.Interface {\n private readonly env: Abstraction.Config;\n\n constructor(env: Abstraction.Config) {\n this.env = env;\n }\n\n public get<K extends keyof Abstraction.Config>(\n key: K,\n defaultValue?: Abstraction.Config[K]\n ): Abstraction.Config[K] {\n const rawValue = this.env[key];\n\n if ((rawValue === undefined || rawValue === null) && defaultValue !== undefined) {\n return defaultValue;\n }\n\n return rawValue;\n }\n\n getAll(): Abstraction.Config {\n return this.env;\n }\n}\n"],"mappings":"AAEA,OAAO,MAAMA,gBAAgB,CAAkC;EAG3DC,WAAWA,CAACC,GAAuB,EAAE;IACjC,IAAI,CAACA,GAAG,GAAGA,GAAG;EAClB;EAEOC,GAAGA,CACNC,GAAM,EACNC,YAAoC,EACf;IACrB,MAAMC,QAAQ,GAAG,IAAI,CAACJ,GAAG,CAACE,GAAG,CAAC;IAE9B,IAAI,CAACE,QAAQ,KAAKC,SAAS,IAAID,QAAQ,KAAK,IAAI,KAAKD,YAAY,KAAKE,SAAS,EAAE;MAC7E,OAAOF,YAAY;IACvB;IAEA,OAAOC,QAAQ;EACnB;EAEAE,MAAMA,CAAA,EAAuB;IACzB,OAAO,IAAI,CAACN,GAAG;EACnB;AACJ","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Abstraction","EnvConfig"],"sources":["abstractions.ts"],"sourcesContent":["import { Abstraction } from \"@webiny/di\";\n\ntype Env = {\n apiUrl: string;\n debug: boolean;\n deploymentId: string;\n graphqlApiUrl: string;\n telemetryEnabled: boolean;\n telemetryUserId: string | undefined;\n trashBinRetentionPeriodDays: number;\n wcpProjectId: string | undefined;\n websocketUrl: string;\n graphqlClient?: {\n retries: {\n maxRetries: number;\n delayInMillis: number;\n };\n };\n};\n\nexport interface IEnvConfig {\n get<K extends keyof Env>(key: K, defaultValue?: Env[K]): Env[K];\n}\n\nexport const EnvConfig = new Abstraction<IEnvConfig>(\"EnvConfig\");\n\nexport namespace EnvConfig {\n export type Interface = IEnvConfig;\n export type Config = Env;\n}\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,YAAY;
|
|
1
|
+
{"version":3,"names":["Abstraction","EnvConfig"],"sources":["abstractions.ts"],"sourcesContent":["import { Abstraction } from \"@webiny/di\";\n\ntype Env = {\n apiUrl: string;\n debug: boolean;\n deploymentId: string;\n graphqlApiUrl: string;\n telemetryEnabled: boolean;\n telemetryUserId: string | undefined;\n trashBinRetentionPeriodDays: number;\n wcpProjectId: string | undefined;\n websocketUrl: string;\n graphqlClient?: {\n retries: {\n maxRetries: number;\n delayInMillis: number;\n };\n };\n};\n\nexport interface IEnvConfig {\n get<K extends keyof Env>(key: K, defaultValue?: Env[K]): Env[K];\n getAll(): Env;\n}\n\nexport const EnvConfig = new Abstraction<IEnvConfig>(\"EnvConfig\");\n\nexport namespace EnvConfig {\n export type Interface = IEnvConfig;\n export type Config = Env;\n}\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,YAAY;AAyBxC,OAAO,MAAMC,SAAS,GAAG,IAAID,WAAW,CAAa,WAAW,CAAC","ignoreList":[]}
|
|
@@ -5,6 +5,11 @@ export const EventPublisherFeature = createFeature({
|
|
|
5
5
|
name: "EventPublisher",
|
|
6
6
|
register(container) {
|
|
7
7
|
container.registerInstance(EventPublisherAbstraction, new EventPublisher(container));
|
|
8
|
+
},
|
|
9
|
+
resolve(container) {
|
|
10
|
+
return {
|
|
11
|
+
eventPublisher: container.resolve(EventPublisherAbstraction)
|
|
12
|
+
};
|
|
8
13
|
}
|
|
9
14
|
});
|
|
10
15
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createFeature","EventPublisher","EventPublisherAbstraction","EventPublisherFeature","name","register","container","registerInstance"],"sources":["feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/admin\";\nimport { Container } from \"@webiny/di\";\nimport { EventPublisher as EventPublisherAbstraction } from \"./abstractions.js\";\nimport { EventPublisher } from \"./EventPublisher.js\";\n\nexport const EventPublisherFeature = createFeature({\n name: \"EventPublisher\",\n register(container: Container) {\n container.registerInstance(EventPublisherAbstraction, new EventPublisher(container));\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,uBAAuB;AAErD,SAASC,cAAc,IAAIC,yBAAyB;AACpD,SAASD,cAAc;AAEvB,OAAO,MAAME,qBAAqB,GAAGH,aAAa,CAAC;EAC/CI,IAAI,EAAE,gBAAgB;EACtBC,QAAQA,CAACC,SAAoB,EAAE;IAC3BA,SAAS,CAACC,gBAAgB,CAACL,yBAAyB,EAAE,IAAID,cAAc,CAACK,SAAS,CAAC,CAAC;EACxF;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["createFeature","EventPublisher","EventPublisherAbstraction","EventPublisherFeature","name","register","container","registerInstance","resolve","eventPublisher"],"sources":["feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/admin\";\nimport { Container } from \"@webiny/di\";\nimport { EventPublisher as EventPublisherAbstraction } from \"./abstractions.js\";\nimport { EventPublisher } from \"./EventPublisher.js\";\n\nexport const EventPublisherFeature = createFeature({\n name: \"EventPublisher\",\n register(container: Container) {\n container.registerInstance(EventPublisherAbstraction, new EventPublisher(container));\n },\n resolve(container: Container) {\n return {\n eventPublisher: container.resolve(EventPublisherAbstraction)\n };\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,uBAAuB;AAErD,SAASC,cAAc,IAAIC,yBAAyB;AACpD,SAASD,cAAc;AAEvB,OAAO,MAAME,qBAAqB,GAAGH,aAAa,CAAC;EAC/CI,IAAI,EAAE,gBAAgB;EACtBC,QAAQA,CAACC,SAAoB,EAAE;IAC3BA,SAAS,CAACC,gBAAgB,CAACL,yBAAyB,EAAE,IAAID,cAAc,CAACK,SAAS,CAAC,CAAC;EACxF,CAAC;EACDE,OAAOA,CAACF,SAAoB,EAAE;IAC1B,OAAO;MACHG,cAAc,EAAEH,SAAS,CAACE,OAAO,CAACN,yBAAyB;IAC/D,CAAC;EACL;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { GraphQLClient } from "./abstractions.js";
|
|
2
|
-
import { EnvConfig } from "../../features/envConfig/index.js";
|
|
3
2
|
declare class BatchingGraphQLClientImpl implements GraphQLClient.Interface {
|
|
4
|
-
private envConfig;
|
|
5
3
|
private decoratee;
|
|
6
4
|
private queue;
|
|
7
5
|
private batchTimeout;
|
|
8
6
|
private readonly batchWindowMs;
|
|
9
7
|
private readonly maxBatchSize;
|
|
10
|
-
constructor(
|
|
8
|
+
constructor(decoratee: GraphQLClient.Interface);
|
|
11
9
|
execute<TVariables = any, TResult = any>(params: GraphQLClient.Request<TVariables>): Promise<TResult>;
|
|
12
10
|
private flush;
|
|
13
11
|
private executeBatchGroup;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { createDecorator } from "@webiny/di";
|
|
2
2
|
import { GraphQLClient } from "./abstractions.js";
|
|
3
|
-
import { EnvConfig } from "../envConfig/index.js";
|
|
4
3
|
import { RequestValue } from "./RequestValue.js";
|
|
5
4
|
class BatchingGraphQLClientImpl {
|
|
6
5
|
queue = [];
|
|
7
6
|
batchTimeout = null;
|
|
8
|
-
constructor(
|
|
9
|
-
this.envConfig = envConfig;
|
|
7
|
+
constructor(decoratee) {
|
|
10
8
|
this.decoratee = decoratee;
|
|
11
9
|
// Default: 10ms window, max 10 operations per batch
|
|
12
10
|
this.batchWindowMs = 10;
|
|
@@ -56,18 +54,18 @@ class BatchingGraphQLClientImpl {
|
|
|
56
54
|
return;
|
|
57
55
|
}
|
|
58
56
|
|
|
59
|
-
// Group requests by headers (only batch requests with identical
|
|
60
|
-
const
|
|
57
|
+
// Group requests by endpoint + headers (only batch requests with identical target)
|
|
58
|
+
const grouped = new Map();
|
|
61
59
|
for (const item of batch) {
|
|
62
|
-
const
|
|
63
|
-
if (!
|
|
64
|
-
|
|
60
|
+
const groupKey = item.request.endpoint + "|" + this.serializeHeaders(item.request.headers);
|
|
61
|
+
if (!grouped.has(groupKey)) {
|
|
62
|
+
grouped.set(groupKey, []);
|
|
65
63
|
}
|
|
66
|
-
|
|
64
|
+
grouped.get(groupKey).push(item);
|
|
67
65
|
}
|
|
68
66
|
|
|
69
67
|
// Process each group separately
|
|
70
|
-
const batchPromises = Array.from(
|
|
68
|
+
const batchPromises = Array.from(grouped.entries()).map(requests => {
|
|
71
69
|
const group = requests[1];
|
|
72
70
|
if (group.length === 1) {
|
|
73
71
|
// Single request in this group - use decoratee directly
|
|
@@ -94,9 +92,10 @@ class BatchingGraphQLClientImpl {
|
|
|
94
92
|
variables: request.variables
|
|
95
93
|
};
|
|
96
94
|
});
|
|
95
|
+
const endpoint = group[0].request.endpoint;
|
|
97
96
|
const headers = group[0].request.headers;
|
|
98
97
|
try {
|
|
99
|
-
const results = await this.executeBatch(batchedOperations, headers);
|
|
98
|
+
const results = await this.executeBatch(endpoint, batchedOperations, headers);
|
|
100
99
|
group.forEach(({
|
|
101
100
|
resolve
|
|
102
101
|
}, index) => {
|
|
@@ -122,10 +121,10 @@ class BatchingGraphQLClientImpl {
|
|
|
122
121
|
}
|
|
123
122
|
return JSON.stringify(sortedHeaders);
|
|
124
123
|
}
|
|
125
|
-
async executeBatch(operations, headers) {
|
|
124
|
+
async executeBatch(endpoint, operations, headers) {
|
|
126
125
|
let response;
|
|
127
126
|
try {
|
|
128
|
-
response = await fetch(
|
|
127
|
+
response = await fetch(endpoint, {
|
|
129
128
|
method: "POST",
|
|
130
129
|
headers: {
|
|
131
130
|
"Content-Type": "application/json",
|
|
@@ -158,7 +157,7 @@ class BatchingGraphQLClientImpl {
|
|
|
158
157
|
export const BatchingGraphQLClient = createDecorator({
|
|
159
158
|
abstraction: GraphQLClient,
|
|
160
159
|
decorator: BatchingGraphQLClientImpl,
|
|
161
|
-
dependencies: [
|
|
160
|
+
dependencies: []
|
|
162
161
|
});
|
|
163
162
|
|
|
164
163
|
//# sourceMappingURL=BatchingGraphQLClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createDecorator","GraphQLClient","EnvConfig","RequestValue","BatchingGraphQLClientImpl","queue","batchTimeout","constructor","envConfig","decoratee","batchWindowMs","maxBatchSize","execute","params","Promise","resolve","reject","push","request","from","length","flush","setTimeout","clearTimeout","batch","splice","result","error","groupedByHeaders","Map","item","headersKey","serializeHeaders","headers","has","set","get","batchPromises","Array","entries","map","requests","group","then","catch","executeBatchGroup","all","batchedOperations","query","queryAsString","operationName","variables","results","executeBatch","forEach","index","sortedKeys","Object","keys","sort","sortedHeaders","key","String","JSON","stringify","operations","response","fetch","method","body","err","Error","message","json","isArray","errors","data","BatchingGraphQLClient","abstraction","decorator","dependencies"],"sources":["BatchingGraphQLClient.ts"],"sourcesContent":["import { createDecorator } from \"@webiny/di\";\nimport { GraphQLClient } from \"./abstractions.js\";\nimport { EnvConfig } from \"~/features/envConfig/index.js\";\nimport { RequestValue } from \"~/features/graphqlClient/RequestValue.js\";\n\ninterface BatchedRequest {\n request: RequestValue;\n resolve: (value: any) => void;\n reject: (error: any) => void;\n}\n\ninterface BatchOperation {\n operationName: string | undefined;\n query: string;\n variables?: any;\n}\n\nclass BatchingGraphQLClientImpl implements GraphQLClient.Interface {\n private queue: BatchedRequest[] = [];\n private batchTimeout: NodeJS.Timeout | null = null;\n private readonly batchWindowMs: number;\n private readonly maxBatchSize: number;\n\n constructor(\n private envConfig: EnvConfig.Interface,\n private decoratee: GraphQLClient.Interface\n ) {\n // Default: 10ms window, max 10 operations per batch\n this.batchWindowMs = 10;\n this.maxBatchSize = 10;\n }\n\n async execute<TVariables = any, TResult = any>(\n params: GraphQLClient.Request<TVariables>\n ): Promise<TResult> {\n return new Promise((resolve, reject) => {\n this.queue.push({ request: RequestValue.from(params), resolve, reject });\n\n if (this.queue.length >= this.maxBatchSize) {\n this.flush();\n return;\n }\n\n if (!this.batchTimeout) {\n this.batchTimeout = setTimeout(() => {\n this.flush();\n }, this.batchWindowMs);\n }\n });\n }\n\n private async flush(): Promise<void> {\n if (this.batchTimeout) {\n clearTimeout(this.batchTimeout);\n this.batchTimeout = null;\n }\n\n if (this.queue.length === 0) {\n return;\n }\n\n const batch = this.queue.splice(0, this.queue.length);\n\n // Single request - use decoratee directly (no batching needed)\n if (batch.length === 1) {\n const { request, resolve, reject } = batch[0];\n try {\n const result = await this.decoratee.execute(request.request);\n resolve(result);\n } catch (error) {\n reject(error);\n }\n return;\n }\n\n // Group requests by headers (only batch requests with identical headers)\n const groupedByHeaders = new Map<string, BatchedRequest[]>();\n for (const item of batch) {\n const headersKey = this.serializeHeaders(item.request.headers);\n if (!groupedByHeaders.has(headersKey)) {\n groupedByHeaders.set(headersKey, []);\n }\n groupedByHeaders.get(headersKey)!.push(item);\n }\n\n // Process each group separately\n const batchPromises = Array.from(groupedByHeaders.entries()).map(requests => {\n const group = requests[1];\n\n if (group.length === 1) {\n // Single request in this group - use decoratee directly\n const { request, resolve, reject } = group[0];\n return this.decoratee.execute(request.request).then(resolve).catch(reject);\n }\n\n // Multiple requests with same headers - batch them\n return this.executeBatchGroup(group);\n });\n\n await Promise.all(batchPromises);\n }\n\n private async executeBatchGroup(group: BatchedRequest[]): Promise<void> {\n const batchedOperations = group.map(({ request }): BatchOperation => {\n return {\n query: request.queryAsString,\n operationName: request.operationName,\n variables: request.variables\n };\n });\n\n const headers = group[0].request.headers;\n\n try {\n const results = await this.executeBatch(batchedOperations, headers);\n group.forEach(({ resolve }, index) => {\n resolve(results[index]);\n });\n } catch (error) {\n group.forEach(({ reject }) => {\n reject(error);\n });\n }\n }\n\n private serializeHeaders(headers?: GraphQLClient.Headers): string {\n if (!headers) {\n return \"{}\";\n }\n // Sort keys for consistent serialization\n const sortedKeys = Object.keys(headers).sort();\n const sortedHeaders: Record<string, string> = {};\n for (const key of sortedKeys) {\n sortedHeaders[key] = String(headers[key]);\n }\n return JSON.stringify(sortedHeaders);\n }\n\n private async executeBatch(\n operations: BatchOperation[],\n headers?: GraphQLClient.Headers\n ): Promise<any[]> {\n let response: Response;\n\n try {\n response = await fetch(this.envConfig.get(\"graphqlApiUrl\"), {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...(headers || {})\n },\n body: JSON.stringify(operations)\n });\n } catch (err) {\n throw new Error(`Network error: ${(err as Error).message}`);\n }\n\n let json: any;\n try {\n json = await response.json();\n } catch {\n throw new Error(\"Failed to parse GraphQL batch response as JSON.\");\n }\n\n if (!Array.isArray(json)) {\n throw new Error(\"Expected batch response to be an array\");\n }\n\n // Map each result, handling individual errors\n return json.map((result: any, index: number) => {\n if (result.errors && result.errors.length > 0) {\n throw new Error(\n `GraphQL errors in operation ${index}: ${JSON.stringify(result.errors)}`\n );\n }\n return result.data;\n });\n }\n}\n\nexport const BatchingGraphQLClient = createDecorator({\n abstraction: GraphQLClient,\n decorator: BatchingGraphQLClientImpl,\n dependencies: [EnvConfig]\n});\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,YAAY;AAC5C,SAASC,aAAa;AACtB,SAASC,SAAS;AAClB,SAASC,YAAY;AAcrB,MAAMC,yBAAyB,CAAoC;EACvDC,KAAK,GAAqB,EAAE;EAC5BC,YAAY,GAA0B,IAAI;EAIlDC,WAAWA,CACCC,SAA8B,EAC9BC,SAAkC,EAC5C;IAAA,KAFUD,SAA8B,GAA9BA,SAA8B;IAAA,KAC9BC,SAAkC,GAAlCA,SAAkC;IAE1C;IACA,IAAI,CAACC,aAAa,GAAG,EAAE;IACvB,IAAI,CAACC,YAAY,GAAG,EAAE;EAC1B;EAEA,MAAMC,OAAOA,CACTC,MAAyC,EACzB;IAChB,OAAO,IAAIC,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;MACpC,IAAI,CAACX,KAAK,CAACY,IAAI,CAAC;QAAEC,OAAO,EAAEf,YAAY,CAACgB,IAAI,CAACN,MAAM,CAAC;QAAEE,OAAO;QAAEC;MAAO,CAAC,CAAC;MAExE,IAAI,IAAI,CAACX,KAAK,CAACe,MAAM,IAAI,IAAI,CAACT,YAAY,EAAE;QACxC,IAAI,CAACU,KAAK,CAAC,CAAC;QACZ;MACJ;MAEA,IAAI,CAAC,IAAI,CAACf,YAAY,EAAE;QACpB,IAAI,CAACA,YAAY,GAAGgB,UAAU,CAAC,MAAM;UACjC,IAAI,CAACD,KAAK,CAAC,CAAC;QAChB,CAAC,EAAE,IAAI,CAACX,aAAa,CAAC;MAC1B;IACJ,CAAC,CAAC;EACN;EAEA,MAAc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OE,IAAI,CAACjC,GAAG,CAAC,CAACd,MAAW,EAAE6B,KAAa,KAAK;MAC5C,IAAI7B,MAAM,CAACiD,MAAM,IAAIjD,MAAM,CAACiD,MAAM,CAACvD,MAAM,GAAG,CAAC,EAAE;QAC3C,MAAM,IAAImD,KAAK,CACX,+BAA+BhB,KAAK,KAAKQ,IAAI,CAACC,SAAS,CAACtC,MAAM,CAACiD,MAAM,CAAC,EAC1E,CAAC;MACL;MACA,OAAOjD,MAAM,CAACkD,IAAI;IACtB,CAAC,CAAC;EACN;AACJ;AAEA,OAAO,MAAMC,qBAAqB,GAAG7E,eAAe,CAAC;EACjD8E,WAAW,EAAE7E,aAAa;EAC1B8E,SAAS,EAAE3E,yBAAyB;EACpC4E,YAAY,EAAE,CAAC9E,SAAS;AAC5B,CAAC,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["createDecorator","GraphQLClient","RequestValue","BatchingGraphQLClientImpl","queue","batchTimeout","constructor","decoratee","batchWindowMs","maxBatchSize","execute","params","Promise","resolve","reject","push","request","from","length","flush","setTimeout","clearTimeout","batch","splice","result","error","grouped","Map","item","groupKey","endpoint","serializeHeaders","headers","has","set","get","batchPromises","Array","entries","map","requests","group","then","catch","executeBatchGroup","all","batchedOperations","query","queryAsString","operationName","variables","results","executeBatch","forEach","index","sortedKeys","Object","keys","sort","sortedHeaders","key","String","JSON","stringify","operations","response","fetch","method","body","err","Error","message","json","isArray","errors","data","BatchingGraphQLClient","abstraction","decorator","dependencies"],"sources":["BatchingGraphQLClient.ts"],"sourcesContent":["import { createDecorator } from \"@webiny/di\";\nimport { GraphQLClient } from \"./abstractions.js\";\nimport { RequestValue } from \"~/features/graphqlClient/RequestValue.js\";\n\ninterface BatchedRequest {\n request: RequestValue;\n resolve: (value: any) => void;\n reject: (error: any) => void;\n}\n\ninterface BatchOperation {\n operationName: string | undefined;\n query: string;\n variables?: any;\n}\n\nclass BatchingGraphQLClientImpl implements GraphQLClient.Interface {\n private queue: BatchedRequest[] = [];\n private batchTimeout: NodeJS.Timeout | null = null;\n private readonly batchWindowMs: number;\n private readonly maxBatchSize: number;\n\n constructor(private decoratee: GraphQLClient.Interface) {\n // Default: 10ms window, max 10 operations per batch\n this.batchWindowMs = 10;\n this.maxBatchSize = 10;\n }\n\n async execute<TVariables = any, TResult = any>(\n params: GraphQLClient.Request<TVariables>\n ): Promise<TResult> {\n return new Promise((resolve, reject) => {\n this.queue.push({ request: RequestValue.from(params), resolve, reject });\n\n if (this.queue.length >= this.maxBatchSize) {\n this.flush();\n return;\n }\n\n if (!this.batchTimeout) {\n this.batchTimeout = setTimeout(() => {\n this.flush();\n }, this.batchWindowMs);\n }\n });\n }\n\n private async flush(): Promise<void> {\n if (this.batchTimeout) {\n clearTimeout(this.batchTimeout);\n this.batchTimeout = null;\n }\n\n if (this.queue.length === 0) {\n return;\n }\n\n const batch = this.queue.splice(0, this.queue.length);\n\n // Single request - use decoratee directly (no batching needed)\n if (batch.length === 1) {\n const { request, resolve, reject } = batch[0];\n try {\n const result = await this.decoratee.execute(request.request);\n resolve(result);\n } catch (error) {\n reject(error);\n }\n return;\n }\n\n // Group requests by endpoint + headers (only batch requests with identical target)\n const grouped = new Map<string, BatchedRequest[]>();\n for (const item of batch) {\n const groupKey =\n item.request.endpoint + \"|\" + this.serializeHeaders(item.request.headers);\n if (!grouped.has(groupKey)) {\n grouped.set(groupKey, []);\n }\n grouped.get(groupKey)!.push(item);\n }\n\n // Process each group separately\n const batchPromises = Array.from(grouped.entries()).map(requests => {\n const group = requests[1];\n\n if (group.length === 1) {\n // Single request in this group - use decoratee directly\n const { request, resolve, reject } = group[0];\n return this.decoratee.execute(request.request).then(resolve).catch(reject);\n }\n\n // Multiple requests with same headers - batch them\n return this.executeBatchGroup(group);\n });\n\n await Promise.all(batchPromises);\n }\n\n private async executeBatchGroup(group: BatchedRequest[]): Promise<void> {\n const batchedOperations = group.map(({ request }): BatchOperation => {\n return {\n query: request.queryAsString,\n operationName: request.operationName,\n variables: request.variables\n };\n });\n\n const endpoint = group[0].request.endpoint;\n const headers = group[0].request.headers;\n\n try {\n const results = await this.executeBatch(endpoint, batchedOperations, headers);\n group.forEach(({ resolve }, index) => {\n resolve(results[index]);\n });\n } catch (error) {\n group.forEach(({ reject }) => {\n reject(error);\n });\n }\n }\n\n private serializeHeaders(headers?: GraphQLClient.Headers): string {\n if (!headers) {\n return \"{}\";\n }\n // Sort keys for consistent serialization\n const sortedKeys = Object.keys(headers).sort();\n const sortedHeaders: Record<string, string> = {};\n for (const key of sortedKeys) {\n sortedHeaders[key] = String(headers[key]);\n }\n return JSON.stringify(sortedHeaders);\n }\n\n private async executeBatch(\n endpoint: string,\n operations: BatchOperation[],\n headers?: GraphQLClient.Headers\n ): Promise<any[]> {\n let response: Response;\n\n try {\n response = await fetch(endpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...(headers || {})\n },\n body: JSON.stringify(operations)\n });\n } catch (err) {\n throw new Error(`Network error: ${(err as Error).message}`);\n }\n\n let json: any;\n try {\n json = await response.json();\n } catch {\n throw new Error(\"Failed to parse GraphQL batch response as JSON.\");\n }\n\n if (!Array.isArray(json)) {\n throw new Error(\"Expected batch response to be an array\");\n }\n\n // Map each result, handling individual errors\n return json.map((result: any, index: number) => {\n if (result.errors && result.errors.length > 0) {\n throw new Error(\n `GraphQL errors in operation ${index}: ${JSON.stringify(result.errors)}`\n );\n }\n return result.data;\n });\n }\n}\n\nexport const BatchingGraphQLClient = createDecorator({\n abstraction: GraphQLClient,\n decorator: BatchingGraphQLClientImpl,\n dependencies: []\n});\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,YAAY;AAC5C,SAASC,aAAa;AACtB,SAASC,YAAY;AAcrB,MAAMC,yBAAyB,CAAoC;EACvDC,KAAK,GAAqB,EAAE;EAC5BC,YAAY,GAA0B,IAAI;EAIlDC,WAAWA,CAASC,SAAkC,EAAE;IAAA,KAApCA,SAAkC,GAAlCA,SAAkC;IAClD;IACA,IAAI,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,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { GraphQLClient } from "./abstractions.js";
|
|
2
|
-
import { EnvConfig } from "../../features/envConfig/index.js";
|
|
3
2
|
declare class GraphQLClientImpl implements GraphQLClient.Interface {
|
|
4
|
-
private readonly graphqlApiUrl;
|
|
5
|
-
constructor(envConfig: EnvConfig.Interface);
|
|
6
3
|
execute<TResult = any, TVariables = any>(params: GraphQLClient.Request<TVariables>): Promise<TResult>;
|
|
7
4
|
private fetch;
|
|
8
5
|
}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { createImplementation } from "@webiny/di";
|
|
2
2
|
import { GraphQLClient } from "./abstractions.js";
|
|
3
|
-
import { EnvConfig } from "../envConfig/index.js";
|
|
4
3
|
import { RequestValue } from "./RequestValue.js";
|
|
5
4
|
class GraphQLClientImpl {
|
|
6
|
-
constructor(envConfig) {
|
|
7
|
-
this.graphqlApiUrl = envConfig.get("graphqlApiUrl");
|
|
8
|
-
}
|
|
9
5
|
async execute(params) {
|
|
10
6
|
const request = RequestValue.from(params);
|
|
11
7
|
const body = JSON.stringify({
|
|
@@ -13,12 +9,12 @@ class GraphQLClientImpl {
|
|
|
13
9
|
variables: request.variables,
|
|
14
10
|
operationName: request.operationName
|
|
15
11
|
});
|
|
16
|
-
return this.fetch(body, request.headers);
|
|
12
|
+
return this.fetch(request.endpoint, body, request.headers);
|
|
17
13
|
}
|
|
18
|
-
async fetch(body, headers = {}) {
|
|
14
|
+
async fetch(endpoint, body, headers = {}) {
|
|
19
15
|
let response;
|
|
20
16
|
try {
|
|
21
|
-
response = await fetch(
|
|
17
|
+
response = await fetch(endpoint, {
|
|
22
18
|
method: "POST",
|
|
23
19
|
headers: {
|
|
24
20
|
"Content-Type": "application/json",
|
|
@@ -56,7 +52,7 @@ class GraphQLClientImpl {
|
|
|
56
52
|
export const FetchGraphQLClient = createImplementation({
|
|
57
53
|
abstraction: GraphQLClient,
|
|
58
54
|
implementation: GraphQLClientImpl,
|
|
59
|
-
dependencies: [
|
|
55
|
+
dependencies: []
|
|
60
56
|
});
|
|
61
57
|
|
|
62
58
|
//# sourceMappingURL=FetchGraphQLClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createImplementation","GraphQLClient","
|
|
1
|
+
{"version":3,"names":["createImplementation","GraphQLClient","RequestValue","GraphQLClientImpl","execute","params","request","from","body","JSON","stringify","query","queryAsString","variables","operationName","fetch","endpoint","headers","response","method","err","Error","message","json","status","code","errors","length","cause","data","FetchGraphQLClient","abstraction","implementation","dependencies"],"sources":["FetchGraphQLClient.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport { GraphQLClient } from \"./abstractions.js\";\nimport { RequestValue } from \"~/features/graphqlClient/RequestValue.js\";\n\nclass GraphQLClientImpl implements GraphQLClient.Interface {\n async execute<TResult = any, TVariables = any>(\n params: GraphQLClient.Request<TVariables>\n ): Promise<TResult> {\n const request = RequestValue.from(params);\n\n const body = JSON.stringify({\n query: request.queryAsString,\n variables: request.variables,\n operationName: request.operationName\n });\n\n return this.fetch<TResult>(request.endpoint, body, request.headers);\n }\n\n private async fetch<TResult = any>(\n endpoint: string,\n body: string,\n headers: GraphQLClient.Headers = {}\n ): Promise<TResult> {\n let response: Response;\n try {\n response = await fetch(endpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...(headers || {})\n },\n body\n });\n } catch (err) {\n throw new Error(`Network error: ${(err as Error).message}`);\n }\n let json: any;\n try {\n json = await response.json();\n } catch {\n throw new Error(\"Failed to parse GraphQL response as JSON.\");\n }\n\n // Check for generic API errors\n if (response.status !== 200) {\n throw { message: json.message, code: json.code };\n }\n\n // Check for GraphQL errors\n if (json.errors && json.errors.length > 0) {\n throw new Error(`GraphQL errors`, { cause: json.errors });\n }\n return json.data as TResult;\n }\n}\n\nexport const FetchGraphQLClient = createImplementation({\n abstraction: GraphQLClient,\n implementation: GraphQLClientImpl,\n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,CAACE;MAAK,CAAC;IACpD;;IAEA;IACA,IAAIF,IAAI,CAACG,MAAM,IAAIH,IAAI,CAACG,MAAM,CAACC,MAAM,GAAG,CAAC,EAAE;MACvC,MAAM,IAAIN,KAAK,CAAC,gBAAgB,EAAE;QAAEO,KAAK,EAAEL,IAAI,CAACG;MAAO,CAAC,CAAC;IAC7D;IACA,OAAOH,IAAI,CAACM,IAAI;EACpB;AACJ;AAEA,OAAO,MAAMC,kBAAkB,GAAG9B,oBAAoB,CAAC;EACnD+B,WAAW,EAAE9B,aAAa;EAC1B+B,cAAc,EAAE7B,iBAAiB;EACjC8B,YAAY,EAAE;AAClB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getOperationAST","parse","print","RequestValue","from","value","constructor","_request","query","_queryAsString","_queryAsDocumentNode","_operationName","getOperationName","request","variables","queryAsString","queryAsDocumentNode","headers","operationName","operationAST","undefined","name"],"sources":["RequestValue.ts"],"sourcesContent":["import { getOperationAST, parse, print, type DocumentNode } from \"graphql\";\nimport { GraphQLClient } from \"./abstractions.js\";\n\nexport class RequestValue {\n private readonly _operationName: string | undefined;\n private readonly _queryAsString: string;\n private readonly _queryAsDocumentNode: DocumentNode;\n private readonly _request: GraphQLClient.Request;\n\n static from(value: GraphQLClient.Request) {\n return new RequestValue(value);\n }\n\n private constructor(readonly value: GraphQLClient.Request) {\n this._request = value;\n if (typeof value.query === \"string\") {\n this._queryAsString = value.query;\n this._queryAsDocumentNode = parse(value.query);\n } else {\n this._queryAsString = print(value.query);\n this._queryAsDocumentNode = value.query;\n }\n\n this._operationName = this.getOperationName(this._queryAsDocumentNode);\n }\n\n get request() {\n return this._request;\n }\n\n get variables() {\n return this._request.variables;\n }\n\n get queryAsString() {\n return this._queryAsString;\n }\n\n get queryAsDocumentNode() {\n return this._queryAsDocumentNode;\n }\n\n get headers() {\n return this._request.headers;\n }\n\n get operationName() {\n return this._operationName;\n }\n\n private getOperationName(query: DocumentNode): string | undefined {\n const operationAST = getOperationAST(query, undefined);\n return operationAST?.name?.value;\n }\n}\n"],"mappings":"AAAA,SAASA,eAAe,EAAEC,KAAK,EAAEC,KAAK,QAA2B,SAAS;AAG1E,OAAO,MAAMC,YAAY,CAAC;EAMtB,OAAOC,IAAIA,CAACC,KAA4B,EAAE;IACtC,OAAO,IAAIF,YAAY,CAACE,KAAK,CAAC;EAClC;EAEQC,WAAWA,CAAUD,KAA4B,EAAE;IAAA,KAA9BA,KAA4B,GAA5BA,KAA4B;IACrD,IAAI,CAACE,QAAQ,GAAGF,KAAK;IACrB,IAAI,OAAOA,KAAK,CAACG,KAAK,KAAK,QAAQ,EAAE;MACjC,IAAI,CAACC,cAAc,GAAGJ,KAAK,CAACG,KAAK;MACjC,IAAI,CAACE,oBAAoB,GAAGT,KAAK,CAACI,KAAK,CAACG,KAAK,CAAC;IAClD,CAAC,MAAM;MACH,IAAI,CAACC,cAAc,GAAGP,KAAK,CAACG,KAAK,CAACG,KAAK,CAAC;MACxC,IAAI,CAACE,oBAAoB,GAAGL,KAAK,CAACG,KAAK;IAC3C;IAEA,IAAI,CAACG,cAAc,GAAG,IAAI,CAACC,gBAAgB,CAAC,IAAI,CAACF,oBAAoB,CAAC;EAC1E;EAEA,IAAIG,OAAOA,CAAA,EAAG;IACV,OAAO,IAAI,CAACN,QAAQ;EACxB;EAEA,IAAIO,SAASA,CAAA,EAAG;IACZ,OAAO,IAAI,CAACP,QAAQ,CAACO,SAAS;EAClC;EAEA,IAAIC,aAAaA,CAAA,EAAG;IAChB,OAAO,IAAI,CAACN,cAAc;EAC9B;EAEA,IAAIO,mBAAmBA,CAAA,EAAG;IACtB,OAAO,IAAI,CAACN,oBAAoB;EACpC;EAEA,IAAIO,OAAOA,CAAA,EAAG;IACV,OAAO,IAAI,CAACV,QAAQ,CAACU,OAAO;EAChC;EAEA,IAAIC,aAAaA,CAAA,EAAG;IAChB,OAAO,IAAI,
|
|
1
|
+
{"version":3,"names":["getOperationAST","parse","print","RequestValue","from","value","constructor","_request","query","_queryAsString","_queryAsDocumentNode","_operationName","getOperationName","request","variables","queryAsString","queryAsDocumentNode","headers","endpoint","operationName","operationAST","undefined","name"],"sources":["RequestValue.ts"],"sourcesContent":["import { getOperationAST, parse, print, type DocumentNode } from \"graphql\";\nimport { GraphQLClient } from \"./abstractions.js\";\n\nexport class RequestValue {\n private readonly _operationName: string | undefined;\n private readonly _queryAsString: string;\n private readonly _queryAsDocumentNode: DocumentNode;\n private readonly _request: GraphQLClient.Request;\n\n static from(value: GraphQLClient.Request) {\n return new RequestValue(value);\n }\n\n private constructor(readonly value: GraphQLClient.Request) {\n this._request = value;\n if (typeof value.query === \"string\") {\n this._queryAsString = value.query;\n this._queryAsDocumentNode = parse(value.query);\n } else {\n this._queryAsString = print(value.query);\n this._queryAsDocumentNode = value.query;\n }\n\n this._operationName = this.getOperationName(this._queryAsDocumentNode);\n }\n\n get request() {\n return this._request;\n }\n\n get variables() {\n return this._request.variables;\n }\n\n get queryAsString() {\n return this._queryAsString;\n }\n\n get queryAsDocumentNode() {\n return this._queryAsDocumentNode;\n }\n\n get headers() {\n return this._request.headers;\n }\n\n get endpoint() {\n return this._request.endpoint;\n }\n\n get operationName() {\n return this._operationName;\n }\n\n private getOperationName(query: DocumentNode): string | undefined {\n const operationAST = getOperationAST(query, undefined);\n return operationAST?.name?.value;\n }\n}\n"],"mappings":"AAAA,SAASA,eAAe,EAAEC,KAAK,EAAEC,KAAK,QAA2B,SAAS;AAG1E,OAAO,MAAMC,YAAY,CAAC;EAMtB,OAAOC,IAAIA,CAACC,KAA4B,EAAE;IACtC,OAAO,IAAIF,YAAY,CAACE,KAAK,CAAC;EAClC;EAEQC,WAAWA,CAAUD,KAA4B,EAAE;IAAA,KAA9BA,KAA4B,GAA5BA,KAA4B;IACrD,IAAI,CAACE,QAAQ,GAAGF,KAAK;IACrB,IAAI,OAAOA,KAAK,CAACG,KAAK,KAAK,QAAQ,EAAE;MACjC,IAAI,CAACC,c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