@webiny/app 0.0.0-mt-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -0
  3. package/apollo-client/InMemoryCache.d.ts +7 -0
  4. package/apollo-client/InMemoryCache.js +59 -0
  5. package/components/Image.d.ts +3 -0
  6. package/components/Image.js +28 -0
  7. package/components/Routes.d.ts +2 -0
  8. package/components/Routes.js +35 -0
  9. package/components/View.d.ts +8 -0
  10. package/components/View.js +23 -0
  11. package/components/index.d.ts +1 -0
  12. package/components/index.js +1 -0
  13. package/contexts/Ui/index.d.ts +27 -0
  14. package/contexts/Ui/index.js +69 -0
  15. package/hooks/useAutocomplete/index.d.ts +1 -0
  16. package/hooks/useAutocomplete/index.js +1 -0
  17. package/hooks/useAutocomplete/useAutocomplete.d.ts +6 -0
  18. package/hooks/useAutocomplete/useAutocomplete.js +27 -0
  19. package/hooks/useDataList/functions/getData.d.ts +2 -0
  20. package/hooks/useDataList/functions/getData.js +4 -0
  21. package/hooks/useDataList/functions/getError.d.ts +2 -0
  22. package/hooks/useDataList/functions/getError.js +4 -0
  23. package/hooks/useDataList/functions/getMeta.d.ts +2 -0
  24. package/hooks/useDataList/functions/getMeta.js +4 -0
  25. package/hooks/useDataList/functions/index.d.ts +3 -0
  26. package/hooks/useDataList/functions/index.js +3 -0
  27. package/hooks/useDataList/functions/searchDataByKey.d.ts +2 -0
  28. package/hooks/useDataList/functions/searchDataByKey.js +21 -0
  29. package/hooks/useDataList/index.d.ts +1 -0
  30. package/hooks/useDataList/index.js +1 -0
  31. package/hooks/useDataList/useDataList.d.ts +36 -0
  32. package/hooks/useDataList/useDataList.js +193 -0
  33. package/hooks/useDataList/utils/index.d.ts +2 -0
  34. package/hooks/useDataList/utils/index.js +2 -0
  35. package/hooks/useDataList/utils/prepareLoadListParams.d.ts +4 -0
  36. package/hooks/useDataList/utils/prepareLoadListParams.js +34 -0
  37. package/hooks/useDataList/utils/redirectToRouteWithQueryParams.d.ts +5 -0
  38. package/hooks/useDataList/utils/redirectToRouteWithQueryParams.js +22 -0
  39. package/hooks/useDataList/utils/types.d.ts +34 -0
  40. package/hooks/useDataList/utils/types.js +1 -0
  41. package/hooks/useHandler.d.ts +1 -0
  42. package/hooks/useHandler.js +12 -0
  43. package/hooks/useHandlers.d.ts +11 -0
  44. package/hooks/useHandlers.js +19 -0
  45. package/hooks/useUi.d.ts +2 -0
  46. package/hooks/useUi.js +5 -0
  47. package/i18n/i18n.d.ts +2 -0
  48. package/i18n/i18n.js +5 -0
  49. package/i18n/index.d.ts +1 -0
  50. package/i18n/index.js +1 -0
  51. package/package.json +70 -0
  52. package/plugins/AddQuerySelectionPlugin.d.ts +15 -0
  53. package/plugins/AddQuerySelectionPlugin.js +101 -0
  54. package/plugins/ApolloCacheObjectIdPlugin.d.ts +15 -0
  55. package/plugins/ApolloCacheObjectIdPlugin.js +40 -0
  56. package/plugins/ApolloDynamicLink.d.ts +5 -0
  57. package/plugins/ApolloDynamicLink.js +62 -0
  58. package/plugins/ApolloLinkPlugin.d.ts +13 -0
  59. package/plugins/ApolloLinkPlugin.js +43 -0
  60. package/plugins/ConsoleLinkPlugin.d.ts +8 -0
  61. package/plugins/ConsoleLinkPlugin.js +47 -0
  62. package/plugins/LocaleHeaderLinkPlugin.d.ts +14 -0
  63. package/plugins/LocaleHeaderLinkPlugin.js +61 -0
  64. package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.d.ts +6 -0
  65. package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.js +76 -0
  66. package/plugins/NetworkErrorLinkPlugin/StyledComponents.d.ts +3 -0
  67. package/plugins/NetworkErrorLinkPlugin/StyledComponents.js +9 -0
  68. package/plugins/NetworkErrorLinkPlugin/assets/close_24px.svg +1 -0
  69. package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.d.ts +5 -0
  70. package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.js +27 -0
  71. package/plugins/NetworkErrorLinkPlugin.d.ts +7 -0
  72. package/plugins/NetworkErrorLinkPlugin.js +45 -0
  73. package/plugins/OmitTypenameLinkPlugin.d.ts +8 -0
  74. package/plugins/OmitTypenameLinkPlugin.js +41 -0
  75. package/plugins/RoutePlugin.d.ts +12 -0
  76. package/plugins/RoutePlugin.js +36 -0
  77. package/plugins/TenantHeaderLinkPlugin.d.ts +14 -0
  78. package/plugins/TenantHeaderLinkPlugin.js +71 -0
  79. package/plugins/ViewPlugin.d.ts +14 -0
  80. package/plugins/ViewPlugin.js +41 -0
  81. package/plugins/image.d.ts +3 -0
  82. package/plugins/image.js +165 -0
  83. package/plugins/index.d.ts +20 -0
  84. package/plugins/index.js +73 -0
  85. package/types.d.ts +62 -0
  86. package/types.js +2 -0
@@ -0,0 +1,2 @@
1
+ export { default as prepareLoadListParams } from "./prepareLoadListParams";
2
+ export { default as redirectToRouteWithQueryParams } from "./redirectToRouteWithQueryParams";
@@ -0,0 +1,2 @@
1
+ export { default as prepareLoadListParams } from "./prepareLoadListParams";
2
+ export { default as redirectToRouteWithQueryParams } from "./redirectToRouteWithQueryParams";
@@ -0,0 +1,4 @@
1
+ declare const _default: (location: any) => {
2
+ [key: string]: any;
3
+ };
4
+ export default _default;
@@ -0,0 +1,34 @@
1
+ export default (function (location) {
2
+ var params = {};
3
+
4
+ if (location) {
5
+ var query = new URLSearchParams(location.search);
6
+ var after = query.get("after");
7
+ var before = query.get("before");
8
+ var limit = query.get("limit");
9
+
10
+ if (after) {
11
+ params.after = after;
12
+ }
13
+
14
+ if (before) {
15
+ params.before = before;
16
+ }
17
+
18
+ if (limit) {
19
+ params.limit = parseInt(limit);
20
+ }
21
+
22
+ ["sort", "where", "search"].forEach(function (key) {
23
+ if (typeof query.get(key) === "string") {
24
+ try {
25
+ params[key] = JSON.parse(query.get(key));
26
+ } catch (e) {
27
+ params[key] = query.get(key);
28
+ }
29
+ }
30
+ });
31
+ }
32
+
33
+ return params;
34
+ });
@@ -0,0 +1,5 @@
1
+ declare const _default: (params: any, { history, location }: {
2
+ history: any;
3
+ location: any;
4
+ }) => void;
5
+ export default _default;
@@ -0,0 +1,22 @@
1
+ export default (function (params, _ref) {
2
+ var history = _ref.history,
3
+ location = _ref.location;
4
+ var paramsClone = Object.assign({}, params);
5
+ ["sort", "search", "where"].forEach(function (key) {
6
+ if (typeof paramsClone[key] === "object") {
7
+ paramsClone[key] = JSON.stringify(paramsClone[key]);
8
+ }
9
+ });
10
+ var keys = ["limit", "after", "before", "where", "search", "sort"];
11
+ var query = new URLSearchParams(location.search);
12
+ keys.forEach(function (key) {
13
+ if (typeof paramsClone[key] !== "undefined") {
14
+ query.set(key, paramsClone[key]);
15
+ } else {
16
+ query.delete(key);
17
+ }
18
+ });
19
+ history.push({
20
+ search: query.toString()
21
+ });
22
+ });
@@ -0,0 +1,34 @@
1
+ export declare type UseDataListParams = {
2
+ load?: boolean;
3
+ name: string;
4
+ type: string;
5
+ fields: string;
6
+ limit?: number;
7
+ sort?: Object;
8
+ where?: Object;
9
+ search?: Object;
10
+ };
11
+ export declare type SearchParams = {
12
+ query: string;
13
+ operator?: "and" | "or";
14
+ fields?: Array<string>;
15
+ };
16
+ export declare type UseDataListProps = {
17
+ data: Array<Object>;
18
+ meta: Object;
19
+ init: () => void;
20
+ refresh: (params?: Object) => void;
21
+ delete: (id: string, options: Object) => void;
22
+ setPerPage: (perPage: number) => void;
23
+ setPage: (page: number) => void;
24
+ setSearch: (search: SearchParams | any) => void;
25
+ setWhere: (where: Object) => void;
26
+ setSorters: (sort: Object) => void;
27
+ multiSelect: (item: Object, value: boolean) => void;
28
+ multiSelectAll: (value: boolean) => void;
29
+ isMultiSelected: (item: Object) => boolean;
30
+ isAllMultiSelected: () => boolean;
31
+ isNoneMultiSelected: () => boolean;
32
+ getMultiSelected: () => Array<Object>;
33
+ __loadParams: UseDataListParams;
34
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare function useHandler(props: any, factory: any): (...args: any[]) => any;
@@ -0,0 +1,12 @@
1
+ import { useRef, useEffect } from "react";
2
+ export function useHandler(props, factory) {
3
+ var propsRef = useRef(props);
4
+ var handlerRef = useRef(function () {
5
+ var handler = factory(propsRef.current);
6
+ return handler.apply(void 0, arguments);
7
+ });
8
+ useEffect(function () {
9
+ propsRef.current = props;
10
+ });
11
+ return handlerRef.current;
12
+ }
@@ -0,0 +1,11 @@
1
+ declare type HandlerProps = {
2
+ [key: string]: any;
3
+ };
4
+ declare type HandlerFactories = {
5
+ [key: string]: (props: HandlerProps) => (...params: any[]) => any;
6
+ };
7
+ declare type Handlers = {
8
+ [K in keyof HandlerFactories]: (...params: any[]) => any;
9
+ };
10
+ export declare function useHandlers(props: HandlerProps, factories: HandlerFactories): Handlers;
11
+ export {};
@@ -0,0 +1,19 @@
1
+ import { useRef, useEffect } from "react";
2
+ export function useHandlers(props, factories) {
3
+ var propsRef = useRef(props);
4
+ var handlersRef = useRef(function () {
5
+ var names = Object.keys(factories);
6
+ return names.reduce(function (handlers, name) {
7
+ handlers[name] = function () {
8
+ var handler = factories[name](propsRef.current);
9
+ return handler.apply(void 0, arguments);
10
+ };
11
+
12
+ return handlers;
13
+ }, {});
14
+ }());
15
+ useEffect(function () {
16
+ propsRef.current = props;
17
+ });
18
+ return handlersRef.current;
19
+ }
@@ -0,0 +1,2 @@
1
+ import { UiContextValue } from "../contexts/Ui";
2
+ export declare const useUi: () => UiContextValue;
package/hooks/useUi.js ADDED
@@ -0,0 +1,5 @@
1
+ import { useContext } from "react";
2
+ import { UiContext } from "./../contexts/Ui";
3
+ export var useUi = function useUi() {
4
+ return useContext(UiContext);
5
+ };
package/i18n/i18n.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import i18n from "@webiny/i18n";
2
+ export default i18n;
package/i18n/i18n.js ADDED
@@ -0,0 +1,5 @@
1
+ import i18n, { defaultProcessor, defaultModifiers } from "@webiny/i18n";
2
+ import reactProcessor from "@webiny/i18n-react";
3
+ i18n.registerProcessors([defaultProcessor, reactProcessor]);
4
+ i18n.registerModifiers(defaultModifiers);
5
+ export default i18n;
@@ -0,0 +1 @@
1
+ export { default as i18n } from "./i18n";
package/i18n/index.js ADDED
@@ -0,0 +1 @@
1
+ export { default as i18n } from "./i18n";
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@webiny/app",
3
+ "version": "0.0.0-mt-1",
4
+ "main": "index.js",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/webiny/webiny-js.git"
8
+ },
9
+ "description": "The base package for building Webiny and React powered web apps.",
10
+ "contributors": [
11
+ "Pavel Denisjuk <pavel@webiny.com>",
12
+ "Sven Al Hamad <sven@webiny.com>",
13
+ "Adrian Smijulj <adrian@webiny.com>"
14
+ ],
15
+ "license": "MIT",
16
+ "dependencies": {
17
+ "@apollo/react-hooks": "3.1.5",
18
+ "@babel/runtime": "7.15.4",
19
+ "@emotion/styled": "10.0.27",
20
+ "@types/react": "16.14.2",
21
+ "@webiny/i18n": "0.0.0-mt-1",
22
+ "@webiny/i18n-react": "0.0.0-mt-1",
23
+ "@webiny/plugins": "0.0.0-mt-1",
24
+ "@webiny/react-router": "0.0.0-mt-1",
25
+ "@webiny/ui": "0.0.0-mt-1",
26
+ "apollo-cache": "1.3.5",
27
+ "apollo-cache-inmemory": "1.6.6",
28
+ "apollo-client": "2.6.10",
29
+ "apollo-link": "1.2.14",
30
+ "apollo-link-context": "1.0.20",
31
+ "apollo-link-error": "1.1.13",
32
+ "apollo-utilities": "1.3.4",
33
+ "boolean": "3.1.4",
34
+ "graphql": "14.7.0",
35
+ "invariant": "2.2.4",
36
+ "lodash": "4.17.21",
37
+ "react": "16.14.0",
38
+ "react-dom": "16.14.0",
39
+ "warning": "4.0.3"
40
+ },
41
+ "devDependencies": {
42
+ "@babel/cli": "^7.5.5",
43
+ "@babel/core": "^7.5.5",
44
+ "@babel/plugin-proposal-class-properties": "^7.5.5",
45
+ "@babel/preset-env": "^7.5.5",
46
+ "@babel/preset-react": "^7.0.0",
47
+ "@babel/preset-typescript": "^7.8.3",
48
+ "@webiny/cli": "^0.0.0-mt-1",
49
+ "@webiny/project-utils": "^0.0.0-mt-1",
50
+ "babel-plugin-lodash": "^3.3.4",
51
+ "rimraf": "^3.0.2",
52
+ "typescript": "^4.1.3"
53
+ },
54
+ "publishConfig": {
55
+ "access": "public",
56
+ "directory": "dist"
57
+ },
58
+ "scripts": {
59
+ "build": "yarn webiny run build",
60
+ "watch": "yarn webiny run watch"
61
+ },
62
+ "adio": {
63
+ "ignore": {
64
+ "dependencies": [
65
+ "react-dom"
66
+ ]
67
+ }
68
+ },
69
+ "gitHead": "37736d8456a6ecb342a6c3645060bd9a3f2d4bb0"
70
+ }
@@ -0,0 +1,15 @@
1
+ import { ApolloLink } from "apollo-link";
2
+ import { DocumentNode } from "graphql";
3
+ import { ApolloLinkPlugin } from "./ApolloLinkPlugin";
4
+ interface Config {
5
+ operationName: string;
6
+ selectionPath: string;
7
+ addSelection: DocumentNode;
8
+ }
9
+ export declare class AddQuerySelectionPlugin extends ApolloLinkPlugin {
10
+ private config;
11
+ constructor(config: Config);
12
+ createLink(): ApolloLink;
13
+ addSelectionToQuery(operationName: string, query: DocumentNode): void;
14
+ }
15
+ export {};
@@ -0,0 +1,101 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/createForOfIteratorHelper";
3
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
+ import _createClass from "@babel/runtime/helpers/createClass";
5
+ import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
6
+ import _inherits from "@babel/runtime/helpers/inherits";
7
+ import _createSuper from "@babel/runtime/helpers/createSuper";
8
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
9
+ import { ApolloLink } from "apollo-link";
10
+ import { ApolloLinkPlugin } from "./ApolloLinkPlugin";
11
+ export var AddQuerySelectionPlugin = /*#__PURE__*/function (_ApolloLinkPlugin) {
12
+ _inherits(AddQuerySelectionPlugin, _ApolloLinkPlugin);
13
+
14
+ var _super = _createSuper(AddQuerySelectionPlugin);
15
+
16
+ function AddQuerySelectionPlugin(config) {
17
+ var _this;
18
+
19
+ _classCallCheck(this, AddQuerySelectionPlugin);
20
+
21
+ _this = _super.call(this);
22
+
23
+ _defineProperty(_assertThisInitialized(_this), "config", void 0);
24
+
25
+ _this.config = config;
26
+ return _this;
27
+ }
28
+
29
+ _createClass(AddQuerySelectionPlugin, [{
30
+ key: "createLink",
31
+ value: function createLink() {
32
+ var _this2 = this;
33
+
34
+ return new ApolloLink(function (operation, forward) {
35
+ if (operation.operationName !== _this2.config.operationName) {
36
+ return forward(operation);
37
+ }
38
+
39
+ _this2.addSelectionToQuery(operation.operationName, operation.query);
40
+
41
+ return forward(operation);
42
+ });
43
+ }
44
+ }, {
45
+ key: "addSelectionToQuery",
46
+ value: function addSelectionToQuery(operationName, query) {
47
+ var _tree;
48
+
49
+ if (operationName !== this.config.operationName) {
50
+ return;
51
+ }
52
+
53
+ var _this$config = this.config,
54
+ addSelection = _this$config.addSelection,
55
+ selectionPath = _this$config.selectionPath; // TODO: check if the selection is already in the query and don't add it again if not necessary.
56
+ // @ts-ignore
57
+
58
+ var tree = query.definitions[0].selectionSet.selections;
59
+ var fields = selectionPath.split(".");
60
+
61
+ var _iterator = _createForOfIteratorHelper(fields),
62
+ _step;
63
+
64
+ try {
65
+ fieldLoop: for (_iterator.s(); !(_step = _iterator.n()).done;) {
66
+ var field = _step.value;
67
+
68
+ var _iterator2 = _createForOfIteratorHelper(tree),
69
+ _step2;
70
+
71
+ try {
72
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
73
+ var selection = _step2.value;
74
+
75
+ if (selection.name.value === field) {
76
+ tree = selection.selectionSet.selections;
77
+ continue fieldLoop;
78
+ }
79
+ } // If we get here, it means we didn't find the necessary selection
80
+
81
+ } catch (err) {
82
+ _iterator2.e(err);
83
+ } finally {
84
+ _iterator2.f();
85
+ }
86
+
87
+ return;
88
+ }
89
+ } catch (err) {
90
+ _iterator.e(err);
91
+ } finally {
92
+ _iterator.f();
93
+ } // @ts-ignore
94
+
95
+
96
+ (_tree = tree).push.apply(_tree, _toConsumableArray(addSelection.definitions[0].selectionSet.selections));
97
+ }
98
+ }]);
99
+
100
+ return AddQuerySelectionPlugin;
101
+ }(ApolloLinkPlugin);
@@ -0,0 +1,15 @@
1
+ import { Plugin } from "@webiny/plugins";
2
+ export interface Object {
3
+ __typename?: string;
4
+ [key: string]: any;
5
+ }
6
+ interface Callable<T> {
7
+ (data: T): any;
8
+ }
9
+ export declare class ApolloCacheObjectIdPlugin<T extends Object = Object> extends Plugin {
10
+ static readonly type = "cache-get-object-id";
11
+ private _getObjectId;
12
+ constructor(getObjectId?: Callable<T>);
13
+ getObjectId(data: T): any;
14
+ }
15
+ export {};
@@ -0,0 +1,40 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
4
+ import _inherits from "@babel/runtime/helpers/inherits";
5
+ import _createSuper from "@babel/runtime/helpers/createSuper";
6
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
7
+ import { Plugin } from "@webiny/plugins";
8
+ export var ApolloCacheObjectIdPlugin = /*#__PURE__*/function (_Plugin) {
9
+ _inherits(ApolloCacheObjectIdPlugin, _Plugin);
10
+
11
+ var _super = _createSuper(ApolloCacheObjectIdPlugin);
12
+
13
+ function ApolloCacheObjectIdPlugin(getObjectId) {
14
+ var _this;
15
+
16
+ _classCallCheck(this, ApolloCacheObjectIdPlugin);
17
+
18
+ _this = _super.call(this);
19
+
20
+ _defineProperty(_assertThisInitialized(_this), "_getObjectId", void 0);
21
+
22
+ _this._getObjectId = getObjectId;
23
+ return _this;
24
+ }
25
+
26
+ _createClass(ApolloCacheObjectIdPlugin, [{
27
+ key: "getObjectId",
28
+ value: function getObjectId(data) {
29
+ if (typeof this._getObjectId !== "function") {
30
+ throw Error("You must provide a \"getObjectId\" callable to the plugin constructor or extend the ApolloCacheObjectIdPlugin.");
31
+ }
32
+
33
+ return this._getObjectId(data);
34
+ }
35
+ }]);
36
+
37
+ return ApolloCacheObjectIdPlugin;
38
+ }(Plugin);
39
+
40
+ _defineProperty(ApolloCacheObjectIdPlugin, "type", "cache-get-object-id");
@@ -0,0 +1,5 @@
1
+ import { ApolloLink } from "apollo-link";
2
+ export declare class ApolloDynamicLink extends ApolloLink {
3
+ private cache;
4
+ request(operation: any, forward: any): any;
5
+ }
@@ -0,0 +1,62 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
4
+ import _inherits from "@babel/runtime/helpers/inherits";
5
+ import _createSuper from "@babel/runtime/helpers/createSuper";
6
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
7
+ import { ApolloLink } from "apollo-link";
8
+ import { plugins } from "@webiny/plugins";
9
+
10
+ function createLink(plugin) {
11
+ try {
12
+ return plugin.createLink();
13
+ } catch (e) {
14
+ console.error("Caught an error while executing \"createLink\" on plugin", plugin);
15
+ console.error(e);
16
+ }
17
+ }
18
+
19
+ export var ApolloDynamicLink = /*#__PURE__*/function (_ApolloLink) {
20
+ _inherits(ApolloDynamicLink, _ApolloLink);
21
+
22
+ var _super = _createSuper(ApolloDynamicLink);
23
+
24
+ function ApolloDynamicLink() {
25
+ var _this;
26
+
27
+ _classCallCheck(this, ApolloDynamicLink);
28
+
29
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
30
+ args[_key] = arguments[_key];
31
+ }
32
+
33
+ _this = _super.call.apply(_super, [this].concat(args));
34
+
35
+ _defineProperty(_assertThisInitialized(_this), "cache", new Map());
36
+
37
+ return _this;
38
+ }
39
+
40
+ _createClass(ApolloDynamicLink, [{
41
+ key: "request",
42
+ value: function request(operation, forward) {
43
+ var linkPlugins = plugins.byType("apollo-link");
44
+
45
+ if (!linkPlugins.length) {
46
+ return forward(operation);
47
+ }
48
+
49
+ var cacheKey = linkPlugins.map(function (pl) {
50
+ return pl.cacheKey;
51
+ }).join(",");
52
+
53
+ if (!this.cache.has(cacheKey)) {
54
+ this.cache.set(cacheKey, ApolloLink.from(linkPlugins.map(createLink)));
55
+ }
56
+
57
+ return this.cache.get(cacheKey).request(operation, forward);
58
+ }
59
+ }]);
60
+
61
+ return ApolloDynamicLink;
62
+ }(ApolloLink);
@@ -0,0 +1,13 @@
1
+ import { ApolloLink } from "apollo-link";
2
+ import { Plugin } from "@webiny/plugins";
3
+ interface ApolloLinkFactory {
4
+ (): ApolloLink;
5
+ }
6
+ export declare class ApolloLinkPlugin extends Plugin {
7
+ static readonly type = "apollo-link";
8
+ readonly cacheKey: any;
9
+ private factory;
10
+ constructor(factory?: ApolloLinkFactory);
11
+ createLink(): ApolloLink;
12
+ }
13
+ export {};
@@ -0,0 +1,43 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
4
+ import _inherits from "@babel/runtime/helpers/inherits";
5
+ import _createSuper from "@babel/runtime/helpers/createSuper";
6
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
7
+ import { Plugin } from "@webiny/plugins";
8
+ export var ApolloLinkPlugin = /*#__PURE__*/function (_Plugin) {
9
+ _inherits(ApolloLinkPlugin, _Plugin);
10
+
11
+ var _super = _createSuper(ApolloLinkPlugin);
12
+
13
+ function ApolloLinkPlugin(factory) {
14
+ var _this;
15
+
16
+ _classCallCheck(this, ApolloLinkPlugin);
17
+
18
+ _this = _super.call(this);
19
+
20
+ _defineProperty(_assertThisInitialized(_this), "cacheKey", void 0);
21
+
22
+ _defineProperty(_assertThisInitialized(_this), "factory", void 0);
23
+
24
+ _this.factory = factory;
25
+ _this.cacheKey = Date.now();
26
+ return _this;
27
+ }
28
+
29
+ _createClass(ApolloLinkPlugin, [{
30
+ key: "createLink",
31
+ value: function createLink() {
32
+ if (typeof this.factory === "function") {
33
+ return this.factory();
34
+ }
35
+
36
+ throw Error("Missing ApolloLinkFactory in plugin \"".concat(this.name, "\"! Either pass a factory to ApolloLinkPlugin constructor or extend the class and override the \"createLink\" method."));
37
+ }
38
+ }]);
39
+
40
+ return ApolloLinkPlugin;
41
+ }(Plugin);
42
+
43
+ _defineProperty(ApolloLinkPlugin, "type", "apollo-link");
@@ -0,0 +1,8 @@
1
+ import { ApolloLink } from "apollo-link";
2
+ import { ApolloLinkPlugin } from "./ApolloLinkPlugin";
3
+ /**
4
+ * This link checks for presence of `extensions.console` in the response and logs all items to browser console.
5
+ */
6
+ export declare class ConsoleLinkPlugin extends ApolloLinkPlugin {
7
+ createLink(): ApolloLink;
8
+ }
@@ -0,0 +1,47 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
+ import _createClass from "@babel/runtime/helpers/createClass";
4
+ import _inherits from "@babel/runtime/helpers/inherits";
5
+ import _createSuper from "@babel/runtime/helpers/createSuper";
6
+ import { ApolloLink } from "apollo-link";
7
+ import { ApolloLinkPlugin } from "./ApolloLinkPlugin";
8
+ /**
9
+ * This link checks for presence of `extensions.console` in the response and logs all items to browser console.
10
+ */
11
+
12
+ export var ConsoleLinkPlugin = /*#__PURE__*/function (_ApolloLinkPlugin) {
13
+ _inherits(ConsoleLinkPlugin, _ApolloLinkPlugin);
14
+
15
+ var _super = _createSuper(ConsoleLinkPlugin);
16
+
17
+ function ConsoleLinkPlugin() {
18
+ _classCallCheck(this, ConsoleLinkPlugin);
19
+
20
+ return _super.apply(this, arguments);
21
+ }
22
+
23
+ _createClass(ConsoleLinkPlugin, [{
24
+ key: "createLink",
25
+ value: function createLink() {
26
+ return new ApolloLink(function (operation, forward) {
27
+ var isQuery = operation.query.definitions[0]["operation"] === "query";
28
+ return forward(operation).map(function (data) {
29
+ if (data.extensions && Array.isArray(data.extensions.console) && data.extensions.console.length) {
30
+ var variables = isQuery ? JSON.stringify(operation.variables) : "{ see request details in the Network tab }";
31
+ console.groupCollapsed("Logs for graphQL ".concat(isQuery ? "query" : "mutation", ": %c").concat(operation.operationName || "anonymous operation", " %c").concat(variables, "%c"), "color: #fa5a28", "color: #6b6b6b", "color: black");
32
+ data.extensions.console.forEach(function (log) {
33
+ var _console;
34
+
35
+ (_console = console)[log.method].apply(_console, _toConsumableArray(log.args));
36
+ });
37
+ console.groupEnd();
38
+ }
39
+
40
+ return data;
41
+ });
42
+ });
43
+ }
44
+ }]);
45
+
46
+ return ConsoleLinkPlugin;
47
+ }(ApolloLinkPlugin);
@@ -0,0 +1,14 @@
1
+ import { ApolloLinkPlugin } from "./ApolloLinkPlugin";
2
+ declare global {
3
+ interface Window {
4
+ __PS_RENDER_LOCALE__: string;
5
+ }
6
+ }
7
+ /**
8
+ * Append `x-i18n-locale` header from URL query (necessary for prerendering service).
9
+ */
10
+ export declare class LocaleHeaderLinkPlugin extends ApolloLinkPlugin {
11
+ private locale;
12
+ constructor(locale?: string);
13
+ createLink(): import("apollo-link").ApolloLink;
14
+ }