@makeswift/runtime 0.28.7-canary.3 → 0.28.7-canary.5

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 (189) hide show
  1. package/dist/cjs/api/graphql/documents/queries.js +6 -6
  2. package/dist/cjs/api/graphql/documents/queries.js.map +1 -1
  3. package/dist/cjs/api/graphql/generated/types.js.map +1 -1
  4. package/dist/cjs/api/graphql-api-client.js +61 -0
  5. package/dist/cjs/api/graphql-api-client.js.map +1 -0
  6. package/dist/cjs/api/{client.js → host-api-resources-client.js} +7 -15
  7. package/dist/cjs/api/host-api-resources-client.js.map +1 -0
  8. package/dist/cjs/api/rest-api-client.js +187 -0
  9. package/dist/cjs/api/rest-api-client.js.map +1 -0
  10. package/dist/cjs/api/schema/index.js +23 -0
  11. package/dist/cjs/api/schema/index.js.map +1 -0
  12. package/dist/cjs/api/schema/page-pathname-slice.js +38 -0
  13. package/dist/cjs/api/schema/page-pathname-slice.js.map +1 -0
  14. package/dist/cjs/api-handler/handlers/manifest.js +1 -1
  15. package/dist/cjs/client/component-snapshot.js +63 -0
  16. package/dist/cjs/client/component-snapshot.js.map +1 -0
  17. package/dist/cjs/client/index.js +102 -360
  18. package/dist/cjs/client/index.js.map +1 -1
  19. package/dist/cjs/client/page-snapshot.js +33 -0
  20. package/dist/cjs/client/page-snapshot.js.map +1 -0
  21. package/dist/cjs/client/schema/component-document.js +45 -0
  22. package/dist/cjs/client/schema/component-document.js.map +1 -0
  23. package/dist/cjs/client/schema/fonts.js +38 -0
  24. package/dist/cjs/client/schema/fonts.js.map +1 -0
  25. package/dist/cjs/client/schema/get-page.js +39 -0
  26. package/dist/cjs/client/schema/get-page.js.map +1 -0
  27. package/dist/cjs/client/schema/get-pages.js +68 -0
  28. package/dist/cjs/client/schema/get-pages.js.map +1 -0
  29. package/dist/cjs/client/schema/index.js +31 -0
  30. package/dist/cjs/client/schema/index.js.map +1 -0
  31. package/dist/cjs/client/schema/preview-token-payload.js +34 -0
  32. package/dist/cjs/client/schema/preview-token-payload.js.map +1 -0
  33. package/dist/cjs/components/builtin/Form/Form.js +2 -2
  34. package/dist/cjs/components/builtin/Form/Form.js.map +1 -1
  35. package/dist/cjs/next/components/tests/controls/color-control/fixtures.js.map +1 -1
  36. package/dist/cjs/next/components/tests/controls/page-control-prop-rendering.js.map +1 -1
  37. package/dist/cjs/next/components/tests/controls/rich-text-v2-control/fixtures.js.map +1 -1
  38. package/dist/cjs/next/testing/element-data.js +3 -3
  39. package/dist/cjs/next/testing/element-data.js.map +1 -1
  40. package/dist/cjs/runtimes/react/components/GoogleFontLink.js +2 -2
  41. package/dist/cjs/runtimes/react/components/GoogleFontLink.js.map +1 -1
  42. package/dist/cjs/runtimes/react/components/hooks/use-page-snippets.js +2 -2
  43. package/dist/cjs/runtimes/react/components/hooks/use-page-snippets.js.map +1 -1
  44. package/dist/cjs/runtimes/react/components/page/PageHead.js +2 -2
  45. package/dist/cjs/runtimes/react/components/page/PageHead.js.map +1 -1
  46. package/dist/cjs/runtimes/react/hooks/makeswift-api.js +10 -10
  47. package/dist/cjs/runtimes/react/hooks/makeswift-api.js.map +1 -1
  48. package/dist/cjs/runtimes/react/{host-api-client.js → hooks/use-api-resources-client.js} +9 -9
  49. package/dist/cjs/runtimes/react/hooks/use-api-resources-client.js.map +1 -0
  50. package/dist/cjs/runtimes/react/hooks/use-cache-data.js +2 -2
  51. package/dist/cjs/runtimes/react/hooks/use-cache-data.js.map +1 -1
  52. package/dist/cjs/runtimes/react/hooks/use-graphql-api-client.js +35 -0
  53. package/dist/cjs/runtimes/react/hooks/use-graphql-api-client.js.map +1 -0
  54. package/dist/cjs/runtimes/react/hooks/use-resource-resolver.js +3 -3
  55. package/dist/cjs/runtimes/react/hooks/use-resource-resolver.js.map +1 -1
  56. package/dist/cjs/runtimes/react/runtime-core.js +12 -7
  57. package/dist/cjs/runtimes/react/runtime-core.js.map +1 -1
  58. package/dist/cjs/state/middleware/makeswift-api-client-sync.js.map +1 -1
  59. package/dist/cjs/state/store.js +3 -3
  60. package/dist/cjs/state/store.js.map +1 -1
  61. package/dist/esm/api/graphql/documents/queries.js +4 -4
  62. package/dist/esm/api/graphql/documents/queries.js.map +1 -1
  63. package/dist/esm/api/graphql/generated/types.js.map +1 -1
  64. package/dist/esm/api/graphql-api-client.js +42 -0
  65. package/dist/esm/api/graphql-api-client.js.map +1 -0
  66. package/dist/esm/api/{client.js → host-api-resources-client.js} +3 -11
  67. package/dist/esm/api/host-api-resources-client.js.map +1 -0
  68. package/dist/esm/api/rest-api-client.js +152 -0
  69. package/dist/esm/api/rest-api-client.js.map +1 -0
  70. package/dist/esm/api/schema/index.js +2 -0
  71. package/dist/esm/api/schema/index.js.map +1 -0
  72. package/dist/esm/api/schema/page-pathname-slice.js +14 -0
  73. package/dist/esm/api/schema/page-pathname-slice.js.map +1 -0
  74. package/dist/esm/api-handler/handlers/manifest.js +1 -1
  75. package/dist/esm/client/component-snapshot.js +39 -0
  76. package/dist/esm/client/component-snapshot.js.map +1 -0
  77. package/dist/esm/client/index.js +67 -329
  78. package/dist/esm/client/index.js.map +1 -1
  79. package/dist/esm/client/page-snapshot.js +9 -0
  80. package/dist/esm/client/page-snapshot.js.map +1 -0
  81. package/dist/esm/client/schema/component-document.js +20 -0
  82. package/dist/esm/client/schema/component-document.js.map +1 -0
  83. package/dist/esm/client/schema/fonts.js +14 -0
  84. package/dist/esm/client/schema/fonts.js.map +1 -0
  85. package/dist/esm/client/schema/get-page.js +15 -0
  86. package/dist/esm/client/schema/get-page.js.map +1 -0
  87. package/dist/esm/client/schema/get-pages.js +42 -0
  88. package/dist/esm/client/schema/get-pages.js.map +1 -0
  89. package/dist/esm/client/schema/index.js +6 -0
  90. package/dist/esm/client/schema/index.js.map +1 -0
  91. package/dist/esm/client/schema/preview-token-payload.js +10 -0
  92. package/dist/esm/client/schema/preview-token-payload.js.map +1 -0
  93. package/dist/esm/components/builtin/Form/Form.js +2 -2
  94. package/dist/esm/components/builtin/Form/Form.js.map +1 -1
  95. package/dist/esm/next/components/tests/controls/color-control/fixtures.js.map +1 -1
  96. package/dist/esm/next/components/tests/controls/page-control-prop-rendering.js.map +1 -1
  97. package/dist/esm/next/components/tests/controls/rich-text-v2-control/fixtures.js.map +1 -1
  98. package/dist/esm/next/testing/element-data.js +1 -1
  99. package/dist/esm/next/testing/element-data.js.map +1 -1
  100. package/dist/esm/runtimes/react/components/GoogleFontLink.js +2 -2
  101. package/dist/esm/runtimes/react/components/GoogleFontLink.js.map +1 -1
  102. package/dist/esm/runtimes/react/components/hooks/use-page-snippets.js +2 -2
  103. package/dist/esm/runtimes/react/components/hooks/use-page-snippets.js.map +1 -1
  104. package/dist/esm/runtimes/react/components/page/PageHead.js +2 -2
  105. package/dist/esm/runtimes/react/components/page/PageHead.js.map +1 -1
  106. package/dist/esm/runtimes/react/hooks/makeswift-api.js +10 -10
  107. package/dist/esm/runtimes/react/hooks/makeswift-api.js.map +1 -1
  108. package/dist/esm/runtimes/react/hooks/use-api-resources-client.js +9 -0
  109. package/dist/esm/runtimes/react/hooks/use-api-resources-client.js.map +1 -0
  110. package/dist/esm/runtimes/react/hooks/use-cache-data.js +2 -2
  111. package/dist/esm/runtimes/react/hooks/use-cache-data.js.map +1 -1
  112. package/dist/esm/runtimes/react/hooks/use-graphql-api-client.js +11 -0
  113. package/dist/esm/runtimes/react/hooks/use-graphql-api-client.js.map +1 -0
  114. package/dist/esm/runtimes/react/hooks/use-resource-resolver.js +3 -3
  115. package/dist/esm/runtimes/react/hooks/use-resource-resolver.js.map +1 -1
  116. package/dist/esm/runtimes/react/runtime-core.js +12 -7
  117. package/dist/esm/runtimes/react/runtime-core.js.map +1 -1
  118. package/dist/esm/state/middleware/makeswift-api-client-sync.js.map +1 -1
  119. package/dist/esm/state/store.js +3 -3
  120. package/dist/esm/state/store.js.map +1 -1
  121. package/dist/types/api/__tests__/rest-api-client.error-handling.test.d.ts +2 -0
  122. package/dist/types/api/__tests__/rest-api-client.error-handling.test.d.ts.map +1 -0
  123. package/dist/types/api/__tests__/rest-api-client.get-resources.test.d.ts +2 -0
  124. package/dist/types/api/__tests__/rest-api-client.get-resources.test.d.ts.map +1 -0
  125. package/dist/types/api/graphql/documents/queries.d.ts +1 -1
  126. package/dist/types/api/graphql/documents/queries.d.ts.map +1 -1
  127. package/dist/types/api/graphql/generated/types.d.ts +2 -2
  128. package/dist/types/api/graphql/generated/types.d.ts.map +1 -1
  129. package/dist/types/api/graphql-api-client.d.ts +14 -0
  130. package/dist/types/api/graphql-api-client.d.ts.map +1 -0
  131. package/dist/types/api/{client.d.ts → host-api-resources-client.d.ts} +3 -7
  132. package/dist/types/api/host-api-resources-client.d.ts.map +1 -0
  133. package/dist/types/api/rest-api-client.d.ts +27 -0
  134. package/dist/types/api/rest-api-client.d.ts.map +1 -0
  135. package/dist/types/api/schema/index.d.ts +2 -0
  136. package/dist/types/api/schema/index.d.ts.map +1 -0
  137. package/dist/types/api/schema/page-pathname-slice.d.ts +21 -0
  138. package/dist/types/api/schema/page-pathname-slice.d.ts.map +1 -0
  139. package/dist/types/client/component-snapshot.d.ts +25 -0
  140. package/dist/types/client/component-snapshot.d.ts.map +1 -0
  141. package/dist/types/client/index.d.ts +19 -640
  142. package/dist/types/client/index.d.ts.map +1 -1
  143. package/dist/types/client/page-snapshot.d.ts +62 -0
  144. package/dist/types/client/page-snapshot.d.ts.map +1 -0
  145. package/dist/types/client/schema/component-document.d.ts +285 -0
  146. package/dist/types/client/schema/component-document.d.ts.map +1 -0
  147. package/dist/types/client/schema/fonts.d.ts +27 -0
  148. package/dist/types/client/schema/fonts.d.ts.map +1 -0
  149. package/dist/types/client/schema/get-page.d.ts +30 -0
  150. package/dist/types/client/schema/get-page.d.ts.map +1 -0
  151. package/dist/types/client/schema/get-pages.d.ts +202 -0
  152. package/dist/types/client/schema/get-pages.d.ts.map +1 -0
  153. package/dist/types/client/schema/index.d.ts +6 -0
  154. package/dist/types/client/schema/index.d.ts.map +1 -0
  155. package/dist/types/client/schema/preview-token-payload.d.ts +19 -0
  156. package/dist/types/client/schema/preview-token-payload.d.ts.map +1 -0
  157. package/dist/types/next/components/tests/controls/color-control/fixtures.d.ts +1 -1
  158. package/dist/types/next/components/tests/controls/color-control/fixtures.d.ts.map +1 -1
  159. package/dist/types/next/components/tests/controls/page-control-prop-rendering.d.ts +1 -1
  160. package/dist/types/next/components/tests/controls/page-control-prop-rendering.d.ts.map +1 -1
  161. package/dist/types/next/components/tests/controls/rich-text-v2-control/fixtures.d.ts +1 -1
  162. package/dist/types/next/components/tests/controls/rich-text-v2-control/fixtures.d.ts.map +1 -1
  163. package/dist/types/runtimes/react/components/GoogleFontLink.d.ts.map +1 -1
  164. package/dist/types/runtimes/react/components/page/PageHead.d.ts.map +1 -1
  165. package/dist/types/runtimes/react/hooks/use-api-resources-client.d.ts +3 -0
  166. package/dist/types/runtimes/react/hooks/use-api-resources-client.d.ts.map +1 -0
  167. package/dist/types/runtimes/react/hooks/use-cache-data.d.ts +1 -1
  168. package/dist/types/runtimes/react/hooks/use-cache-data.d.ts.map +1 -1
  169. package/dist/types/runtimes/react/hooks/use-graphql-api-client.d.ts +3 -0
  170. package/dist/types/runtimes/react/hooks/use-graphql-api-client.d.ts.map +1 -0
  171. package/dist/types/runtimes/react/runtime-core.d.ts +2 -0
  172. package/dist/types/runtimes/react/runtime-core.d.ts.map +1 -1
  173. package/dist/types/state/middleware/makeswift-api-client-sync.d.ts +2 -2
  174. package/dist/types/state/middleware/makeswift-api-client-sync.d.ts.map +1 -1
  175. package/dist/types/state/store.d.ts +4 -4
  176. package/dist/types/state/store.d.ts.map +1 -1
  177. package/package.json +1 -1
  178. package/dist/cjs/api/client.js.map +0 -1
  179. package/dist/cjs/runtimes/react/host-api-client.js.map +0 -1
  180. package/dist/esm/api/client.js.map +0 -1
  181. package/dist/esm/runtimes/react/host-api-client.js +0 -9
  182. package/dist/esm/runtimes/react/host-api-client.js.map +0 -1
  183. package/dist/types/api/client.d.ts.map +0 -1
  184. package/dist/types/client/tests/client.error-handling.test.d.ts +0 -2
  185. package/dist/types/client/tests/client.error-handling.test.d.ts.map +0 -1
  186. package/dist/types/client/tests/client.get-resources.test.d.ts +0 -2
  187. package/dist/types/client/tests/client.get-resources.test.d.ts.map +0 -1
  188. package/dist/types/runtimes/react/host-api-client.d.ts +0 -3
  189. package/dist/types/runtimes/react/host-api-client.d.ts.map +0 -1
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var use_graphql_api_client_exports = {};
21
+ __export(use_graphql_api_client_exports, {
22
+ useMakeswiftGraphQLApiClient: () => useMakeswiftGraphQLApiClient
23
+ });
24
+ module.exports = __toCommonJS(use_graphql_api_client_exports);
25
+ var import_graphql_api_client = require("../../../api/graphql-api-client");
26
+ var import_use_react_runtime = require("./use-react-runtime");
27
+ function useMakeswiftGraphQLApiClient() {
28
+ const runtime = (0, import_use_react_runtime.useReactRuntime)();
29
+ return new import_graphql_api_client.MakeswiftGraphQLApiClient({ endpoint: runtime.graphqlApiEndpoint });
30
+ }
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
33
+ useMakeswiftGraphQLApiClient
34
+ });
35
+ //# sourceMappingURL=use-graphql-api-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-graphql-api-client.tsx"],"sourcesContent":["'use client'\n\nimport { MakeswiftGraphQLApiClient } from '../../../api/graphql-api-client'\n\nimport { useReactRuntime } from './use-react-runtime'\n\nexport function useMakeswiftGraphQLApiClient(): MakeswiftGraphQLApiClient {\n const runtime = useReactRuntime()\n return new MakeswiftGraphQLApiClient({ endpoint: runtime.graphqlApiEndpoint })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,gCAA0C;AAE1C,+BAAgC;AAEzB,SAAS,+BAA0D;AACxE,QAAM,cAAU,0CAAgB;AAChC,SAAO,IAAI,oDAA0B,EAAE,UAAU,QAAQ,mBAAmB,CAAC;AAC/E;","names":[]}
@@ -22,13 +22,13 @@ __export(use_resource_resolver_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(use_resource_resolver_exports);
24
24
  var import_react = require("react");
25
- var import_host_api_client = require("../host-api-client");
26
25
  var import_resource_resolver = require("../resource-resolver");
27
- var import_use_store = require("./use-store");
26
+ var import_use_api_resources_client = require("./use-api-resources-client");
28
27
  var import_use_document_context = require("./use-document-context");
28
+ var import_use_store = require("./use-store");
29
29
  function useResourceResolver() {
30
30
  const store = (0, import_use_store.useStore)();
31
- const apiClient = (0, import_host_api_client.useMakeswiftHostApiClient)();
31
+ const apiClient = (0, import_use_api_resources_client.useApiResourcesClient)();
32
32
  const documentKey = (0, import_use_document_context.useDocumentKey)();
33
33
  const locale = (0, import_use_document_context.useDocumentLocale)();
34
34
  return (0, import_react.useMemo)(
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resource-resolver.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { type ResourceResolver } from '@makeswift/controls'\n\nimport { useMakeswiftHostApiClient } from '../host-api-client'\nimport { createResourceResolver } from '../resource-resolver'\n\nimport { useStore } from './use-store'\nimport { useDocumentKey, useDocumentLocale } from './use-document-context'\n\nexport function useResourceResolver(): ResourceResolver {\n const store = useStore()\n const apiClient = useMakeswiftHostApiClient()\n\n const documentKey = useDocumentKey()\n const locale = useDocumentLocale()\n\n return useMemo<ResourceResolver>(\n () =>\n createResourceResolver({\n store,\n apiClient,\n documentKey,\n locale,\n }),\n [store, apiClient, documentKey, locale],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwB;AAGxB,6BAA0C;AAC1C,+BAAuC;AAEvC,uBAAyB;AACzB,kCAAkD;AAE3C,SAAS,sBAAwC;AACtD,QAAM,YAAQ,2BAAS;AACvB,QAAM,gBAAY,kDAA0B;AAE5C,QAAM,kBAAc,4CAAe;AACnC,QAAM,aAAS,+CAAkB;AAEjC,aAAO;AAAA,IACL,UACE,iDAAuB;AAAA,MACrB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH,CAAC,OAAO,WAAW,aAAa,MAAM;AAAA,EACxC;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resource-resolver.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { type ResourceResolver } from '@makeswift/controls'\n\nimport { createResourceResolver } from '../resource-resolver'\n\nimport { useApiResourcesClient } from './use-api-resources-client'\nimport { useDocumentKey, useDocumentLocale } from './use-document-context'\nimport { useStore } from './use-store'\n\nexport function useResourceResolver(): ResourceResolver {\n const store = useStore()\n const apiClient = useApiResourcesClient()\n\n const documentKey = useDocumentKey()\n const locale = useDocumentLocale()\n\n return useMemo<ResourceResolver>(\n () =>\n createResourceResolver({\n store,\n apiClient,\n documentKey,\n locale,\n }),\n [store, apiClient, documentKey, locale],\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwB;AAGxB,+BAAuC;AAEvC,sCAAsC;AACtC,kCAAkD;AAClD,uBAAyB;AAElB,SAAS,sBAAwC;AACtD,QAAM,YAAQ,2BAAS;AACvB,QAAM,gBAAY,uDAAsB;AAExC,QAAM,kBAAc,4CAAe;AACnC,QAAM,aAAS,+CAAkB;AAEjC,aAAO;AAAA,IACL,UACE,iDAAuB;AAAA,MACrB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH,CAAC,OAAO,WAAW,aAAa,MAAM;AAAA,EACxC;AACF;","names":[]}
@@ -21,7 +21,7 @@ __export(runtime_core_exports, {
21
21
  RuntimeCore: () => RuntimeCore
22
22
  });
23
23
  module.exports = __toCommonJS(runtime_core_exports);
24
- var import_client = require("../../api/client");
24
+ var import_host_api_resources_client = require("../../api/host-api-resources-client");
25
25
  var import_breakpoints = require("../../state/modules/breakpoints");
26
26
  var import_copy_element_tree = require("../../state/ops/copy-element-tree");
27
27
  var import_read_only_state = require("../../state/read-only-state");
@@ -65,16 +65,12 @@ class RuntimeCore {
65
65
  getOrCreateStore({ siteVersion, locale }) {
66
66
  const key = storeCacheKey({ siteVersion, locale });
67
67
  const createStore = () => {
68
- const hostApiClient = new import_client.MakeswiftHostApiClient({
69
- uri: new URL("graphql", this.apiOrigin).href,
70
- fetch: this.fetch,
71
- preloadedState: { siteVersion, locale }
72
- });
68
+ const apiResourcesClient = this.createApiResourcesClient({ siteVersion, locale });
73
69
  const isReadOnly = siteVersion == null;
74
70
  return (0, import_store.configureReadWriteStore)({
75
71
  name: `Runtime read-write store (site version: ${key})`,
76
72
  appOrigin: this.appOrigin,
77
- hostApiClient,
73
+ apiResourcesClient,
78
74
  preloadedState: { ...this.protoStore.getState(), siteVersion, isReadOnly, locale }
79
75
  });
80
76
  };
@@ -107,6 +103,15 @@ class RuntimeCore {
107
103
  getBreakpoints() {
108
104
  return (0, import_read_only_state.getBreakpoints)(this.protoStore.getState());
109
105
  }
106
+ get graphqlApiEndpoint() {
107
+ return new URL("graphql", this.apiOrigin).href;
108
+ }
109
+ createApiResourcesClient(preloadedState) {
110
+ return new import_host_api_resources_client.HostApiResourcesClient({
111
+ fetch: this.fetch,
112
+ preloadedState
113
+ });
114
+ }
110
115
  shouldUsePersistentStore(key) {
111
116
  return !(0, import_is_server.isServer)() || this.requestKey !== void 0 && storeCacheKey(this.requestKey) === key;
112
117
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtimes/react/runtime-core.ts"],"sourcesContent":["import { type SerializableReplacementContext } from '@makeswift/controls'\n\nimport { MakeswiftHostApiClient } from '../../api/client'\nimport { type HttpFetch } from '../../state/api-client/fetch-api-resource'\nimport { type SiteVersion } from '../../api/site-version'\n\nimport {\n Breakpoints,\n BreakpointsInput,\n parseBreakpointsInput,\n} from '../../state/modules/breakpoints'\n\nimport { copyElementTree } from '../../state/ops/copy-element-tree'\n\nimport { getBreakpoints, type Element, type ElementData } from '../../state/read-only-state'\nimport {\n configureProtoStore,\n configureReadWriteStore,\n type ProtoStore,\n type Store,\n} from '../../state/store'\n\nimport { RefCountedMap } from '../../utils/ref-counted-map'\nimport { isServer } from '../../utils/is-server'\n\nexport type StoreKey = {\n siteVersion: SiteVersion | null\n locale: string | undefined\n}\n\nconst VERSION_TAG_LIVE = 'ref:live'\n\nexport class RuntimeCore {\n // The unowned entry TTL affects performance, not correctness. The TTL controls how long an unretained store stays\n // in the map. If an entry expires and is removed from the map before React commits, the store remains retained\n // via `<StoreContext.Provider>`. The only impact is that future lookups will create a new store instance instead of\n // reusing the existing one, reducing cache efficiency.\n private readonly activeStores = new RefCountedMap<string | null, Store>({\n unownedEntryTtlMs: 1000,\n // Checking on retain/release is sufficient on the client, and we don't need to check on get on the server\n // as the only scenario in which we add the store to the map is when the runtime is already bound to the\n // requested site version, which should be the only site version for which the store is requested\n ttlCheck: RefCountedMap.TTLCheck.ON_RETAIN | RefCountedMap.TTLCheck.ON_RELEASE,\n })\n\n readonly protoStore: ProtoStore\n readonly appOrigin: string\n readonly apiOrigin: string\n readonly requestKey: StoreKey | undefined\n readonly fetch: HttpFetch\n\n constructor({\n appOrigin = 'https://app.makeswift.com',\n apiOrigin = 'https://api.makeswift.com',\n breakpoints,\n requestKey,\n fetch,\n }: {\n appOrigin?: string\n apiOrigin?: string\n breakpoints?: BreakpointsInput\n requestKey?: StoreKey\n fetch: HttpFetch\n }) {\n this.appOrigin = validateOrigin(appOrigin, 'appOrigin')\n this.apiOrigin = validateOrigin(apiOrigin, 'apiOrigin')\n this.requestKey = requestKey\n this.fetch = fetch\n\n this.protoStore = configureProtoStore({\n name: 'Runtime proto-store',\n breakpoints: breakpoints ? parseBreakpointsInput(breakpoints) : undefined,\n })\n }\n\n getOrCreateStore({ siteVersion, locale }: StoreKey): Store {\n const key = storeCacheKey({ siteVersion, locale })\n\n const createStore = () => {\n // host API client includes an in-memory cache of the site's resources and thus also has to be versioned\n const hostApiClient = new MakeswiftHostApiClient({\n uri: new URL('graphql', this.apiOrigin).href,\n fetch: this.fetch,\n preloadedState: { siteVersion, locale },\n })\n\n // TODO: we need to decouple editability from the site version; specifically, previewing\n // a draft version of the site should not lead to switching to the read-write state\n const isReadOnly = siteVersion == null\n\n return configureReadWriteStore({\n name: `Runtime read-write store (site version: ${key})`,\n appOrigin: this.appOrigin,\n hostApiClient,\n preloadedState: { ...this.protoStore.getState(), siteVersion, isReadOnly, locale },\n })\n }\n\n // On the server, stores are ephemeral by default so SSR does not retain them in a long-lived runtime.\n // The exception is a runtime that is already bound to the requested site version & locale, where we\n // can safely reuse the store across multiple root regions and benefit from the host API client's\n // in-memory cache.\n //\n // On the client, stores are reference-counted by site version so multiple root regions can share a store\n // instance, which preserves the pre-v0.17 per-site-version store behavior without requiring a separate\n // runtime per root.\n const usePersistentStore = this.shouldUsePersistentStore(key)\n return usePersistentStore ? this.activeStores.getOrCreate(key, createStore) : createStore()\n }\n\n retainStore({ siteVersion, locale }: StoreKey, store: Store): void {\n const key = storeCacheKey({ siteVersion, locale })\n\n if (!this.shouldUsePersistentStore(key)) {\n console.error('RuntimeCore: attempt to retain an ephemeral store', { key })\n return\n }\n\n if (this.activeStores.retain(key, store)) {\n store.startBreakpointWatch()\n }\n }\n\n releaseStore({ siteVersion, locale }: StoreKey, store: Store): void {\n const key = storeCacheKey({ siteVersion, locale })\n\n if (!this.shouldUsePersistentStore(key)) {\n console.error('RuntimeCore: attempt to release an ephemeral store', { key })\n return\n }\n\n if (this.activeStores.release(key, store)) {\n store.stopBreakpointWatch()\n }\n }\n\n copyElementTree(\n elementTree: ElementData,\n replacementContext: SerializableReplacementContext,\n ): Element {\n return copyElementTree(this.protoStore.getState(), elementTree, replacementContext)\n }\n\n getBreakpoints(): Breakpoints {\n return getBreakpoints(this.protoStore.getState())\n }\n\n private shouldUsePersistentStore(key: string): boolean {\n // don't persist stores on the server unless the runtime instance is bound to a request\n // and the requested store matches the request's site version and locale\n return !isServer() || (this.requestKey !== undefined && storeCacheKey(this.requestKey) === key)\n }\n}\n\nconst storeCacheKey = ({ siteVersion, locale }: StoreKey): string =>\n `${siteVersionTag(siteVersion)}/${locale ?? 'default'}`\n\nconst siteVersionTag = (siteVersion: SiteVersion | null): string =>\n siteVersion?.version ?? VERSION_TAG_LIVE\n\nfunction validateOrigin(url: string, name: string): string {\n try {\n return new URL(url).origin\n } catch {\n throw new Error(`The Makeswift runtime received an invalid \\`${name}\\` parameter: \"${url}\".`)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAuC;AAIvC,yBAIO;AAEP,+BAAgC;AAEhC,6BAA+D;AAC/D,mBAKO;AAEP,6BAA8B;AAC9B,uBAAyB;AAOzB,MAAM,mBAAmB;AAElB,MAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA,EAKN,eAAe,IAAI,qCAAoC;AAAA,IACtE,mBAAmB;AAAA;AAAA;AAAA;AAAA,IAInB,UAAU,qCAAc,SAAS,YAAY,qCAAc,SAAS;AAAA,EACtE,CAAC;AAAA,EAEQ;AAAA,EACA;AAAA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AAG;AACxC,YAAM,qBAAqB;AAAA,IAC7B;AAAA,EACF;AAAA,EAEA,aAAa,EAAE,aAAa,OAAO,GAAa,OAAoB;AAClE,UAAM,MAAM,cAAc,EAAE,aAAa,OAAO,CAAC;AAEjD,QAAI,CAAC,KAAK,yBAAyB,GAAG,GAAG;AACvC,cAAQ,MAAM,sDAAsD,EAAE,IAAI,CAAC;AAC3E;AAAA,IACF;AAEA,QAAI,KAAK,aAAa,QAAQ,KAAK,KAAK,GAAG;AACzC,YAAM,oBAAoB;AAAA,IAC5B;AAAA,EACF;AAAA,EAEA,gBACE,aACA,oBACS;AACT,eAAO,0CAAgB,KAAK,WAAW,SAAS,GAAG,aAAa,kBAAkB;AAAA,EACpF;AAAA,EAEA,iBAA8B;AAC5B,eAAO,uCAAe,KAAK,WAAW,SAAS,CAAC;AAAA,EAClD;AAAA,EAEQ,yBAAyB,KAAsB;AAGrD,WAAO,KAAC,2BAAS,KAAM,KAAK,eAAe,UAAa,cAAc,KAAK,UAAU,MAAM;AAAA,EAC7F;AACF;AAEA,MAAM,gBAAgB,CAAC,EAAE,aAAa,OAAO,MAC3C,GAAG,eAAe,WAAW,CAAC,IAAI,UAAU,SAAS;AAEvD,MAAM,iBAAiB,CAAC,gBACtB,aAAa,WAAW;AAE1B,SAAS,eAAe,KAAa,MAAsB;AACzD,MAAI;AACF,WAAO,IAAI,IAAI,GAAG,EAAE;AAAA,EACtB,QAAQ;AACN,UAAM,IAAI,MAAM,+CAA+C,IAAI,kBAAkB,GAAG,IAAI;AAAA,EAC9F;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/runtimes/react/runtime-core.ts"],"sourcesContent":["import { type SerializableReplacementContext } from '@makeswift/controls'\n\nimport { HostApiResourcesClient } from '../../api/host-api-resources-client'\nimport { type HttpFetch } from '../../state/api-client/fetch-api-resource'\nimport { type SiteVersion } from '../../api/site-version'\n\nimport {\n Breakpoints,\n BreakpointsInput,\n parseBreakpointsInput,\n} from '../../state/modules/breakpoints'\n\nimport { copyElementTree } from '../../state/ops/copy-element-tree'\n\nimport { getBreakpoints, type Element, type ElementData } from '../../state/read-only-state'\nimport {\n configureProtoStore,\n configureReadWriteStore,\n type ProtoStore,\n type Store,\n} from '../../state/store'\n\nimport { RefCountedMap } from '../../utils/ref-counted-map'\nimport { isServer } from '../../utils/is-server'\n\nexport type StoreKey = {\n siteVersion: SiteVersion | null\n locale: string | undefined\n}\n\nconst VERSION_TAG_LIVE = 'ref:live'\n\nexport class RuntimeCore {\n // The unowned entry TTL affects performance, not correctness. The TTL controls how long an unretained store stays\n // in the map. If an entry expires and is removed from the map before React commits, the store remains retained\n // via `<StoreContext.Provider>`. The only impact is that future lookups will create a new store instance instead of\n // reusing the existing one, reducing cache efficiency.\n private readonly activeStores = new RefCountedMap<string | null, Store>({\n unownedEntryTtlMs: 1000,\n // Checking on retain/release is sufficient on the client, and we don't need to check on get on the server\n // as the only scenario in which we add the store to the map is when the runtime is already bound to the\n // requested site version, which should be the only site version for which the store is requested\n ttlCheck: RefCountedMap.TTLCheck.ON_RETAIN | RefCountedMap.TTLCheck.ON_RELEASE,\n })\n\n readonly protoStore: ProtoStore\n readonly appOrigin: string\n readonly apiOrigin: string\n readonly requestKey: StoreKey | undefined\n readonly fetch: HttpFetch\n\n constructor({\n appOrigin = 'https://app.makeswift.com',\n apiOrigin = 'https://api.makeswift.com',\n breakpoints,\n requestKey,\n fetch,\n }: {\n appOrigin?: string\n apiOrigin?: string\n breakpoints?: BreakpointsInput\n requestKey?: StoreKey\n fetch: HttpFetch\n }) {\n this.appOrigin = validateOrigin(appOrigin, 'appOrigin')\n this.apiOrigin = validateOrigin(apiOrigin, 'apiOrigin')\n this.requestKey = requestKey\n this.fetch = fetch\n\n this.protoStore = configureProtoStore({\n name: 'Runtime proto-store',\n breakpoints: breakpoints ? parseBreakpointsInput(breakpoints) : undefined,\n })\n }\n\n getOrCreateStore({ siteVersion, locale }: StoreKey): Store {\n const key = storeCacheKey({ siteVersion, locale })\n\n const createStore = () => {\n // API resources client includes an in-memory cache of the site's resources and thus also has to be versioned\n const apiResourcesClient = this.createApiResourcesClient({ siteVersion, locale })\n\n // TODO: we need to decouple editability from the site version; specifically, previewing\n // a draft version of the site should not lead to switching to the read-write state\n const isReadOnly = siteVersion == null\n\n return configureReadWriteStore({\n name: `Runtime read-write store (site version: ${key})`,\n appOrigin: this.appOrigin,\n apiResourcesClient,\n preloadedState: { ...this.protoStore.getState(), siteVersion, isReadOnly, locale },\n })\n }\n\n // On the server, stores are ephemeral by default so SSR does not retain them in a long-lived runtime.\n // The exception is a runtime that is already bound to the requested site version & locale, where we\n // can safely reuse the store across multiple root regions and benefit from the host API client's\n // in-memory cache.\n //\n // On the client, stores are reference-counted by site version so multiple root regions can share a store\n // instance, which preserves the pre-v0.17 per-site-version store behavior without requiring a separate\n // runtime per root.\n const usePersistentStore = this.shouldUsePersistentStore(key)\n return usePersistentStore ? this.activeStores.getOrCreate(key, createStore) : createStore()\n }\n\n retainStore({ siteVersion, locale }: StoreKey, store: Store): void {\n const key = storeCacheKey({ siteVersion, locale })\n\n if (!this.shouldUsePersistentStore(key)) {\n console.error('RuntimeCore: attempt to retain an ephemeral store', { key })\n return\n }\n\n if (this.activeStores.retain(key, store)) {\n store.startBreakpointWatch()\n }\n }\n\n releaseStore({ siteVersion, locale }: StoreKey, store: Store): void {\n const key = storeCacheKey({ siteVersion, locale })\n\n if (!this.shouldUsePersistentStore(key)) {\n console.error('RuntimeCore: attempt to release an ephemeral store', { key })\n return\n }\n\n if (this.activeStores.release(key, store)) {\n store.stopBreakpointWatch()\n }\n }\n\n copyElementTree(\n elementTree: ElementData,\n replacementContext: SerializableReplacementContext,\n ): Element {\n return copyElementTree(this.protoStore.getState(), elementTree, replacementContext)\n }\n\n getBreakpoints(): Breakpoints {\n return getBreakpoints(this.protoStore.getState())\n }\n\n get graphqlApiEndpoint(): string {\n return new URL('graphql', this.apiOrigin).href\n }\n\n private createApiResourcesClient(preloadedState: {\n siteVersion: SiteVersion | null\n locale: string | undefined\n }) {\n return new HostApiResourcesClient({\n fetch: this.fetch,\n preloadedState,\n })\n }\n\n private shouldUsePersistentStore(key: string): boolean {\n // don't persist stores on the server unless the runtime instance is bound to a request\n // and the requested store matches the request's site version and locale\n return !isServer() || (this.requestKey !== undefined && storeCacheKey(this.requestKey) === key)\n }\n}\n\nconst storeCacheKey = ({ siteVersion, locale }: StoreKey): string =>\n `${siteVersionTag(siteVersion)}/${locale ?? 'default'}`\n\nconst siteVersionTag = (siteVersion: SiteVersion | null): string =>\n siteVersion?.version ?? VERSION_TAG_LIVE\n\nfunction validateOrigin(url: string, name: string): string {\n try {\n return new URL(url).origin\n } catch {\n throw new Error(`The Makeswift runtime received an invalid \\`${name}\\` parameter: \"${url}\".`)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,uCAAuC;AAIvC,yBAIO;AAEP,+BAAgC;AAEhC,6BAA+D;AAC/D,mBAKO;AAEP,6BAA8B;AAC9B,uBAAyB;AAOzB,MAAM,mBAAmB;AAElB,MAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA,EAKN,eAAe,IAAI,qCAAoC;AAAA,IACtE,mBAAmB;AAAA;AAAA;AAAA;AAAA,IAInB,UAAU,qCAAc,SAAS,YAAY,qCAAc,SAAS;AAAA,EACtE,CAAC;AAAA,EAEQ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY;AAAA,IACV,YAAY;AAAA,IACZ,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAMG;AACD,SAAK,YAAY,eAAe,WAAW,WAAW;AACtD,SAAK,YAAY,eAAe,WAAW,WAAW;AACtD,SAAK,aAAa;AAClB,SAAK,QAAQ;AAEb,SAAK,iBAAa,kCAAoB;AAAA,MACpC,MAAM;AAAA,MACN,aAAa,kBAAc,0CAAsB,WAAW,IAAI;AAAA,IAClE,CAAC;AAAA,EAC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A8B;AAC5B,eAAO,uCAAe,KAAK,WAAW,SAAS,CAAC;AAAA,EAClD;AAAA,EAEA,IAAI,qBAA6B;AAC/B,WAAO,IAAI,IAAI,WAAW,KAAK,SAAS,EAAE;AAAA,EAC5C;AAAA,EAEQ,yBAAyB,gBAG9B;AACD,WAAO,IAAI,wDAAuB;AAAA,MAChC,OAAO,KAAK;AAAA,MACZ;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEQ,yBAAyB,KAAsB;AAGrD,WAAO,KAAC,2BAAS,KAAM,KAAK,eAAe,UAAa,cAAc,KAAK,UAAU,MAAM;AAAA,EAC7F;AACF;AAEA,MAAM,gBAAgB,CAAC,EAAE,aAAa,OAAO,MAC3C,GAAG,eAAe,WAAW,CAAC,IAAI,UAAU,SAAS;AAEvD,MAAM,iBAAiB,CAAC,gBACtB,aAAa,WAAW;AAE1B,SAAS,eAAe,KAAa,MAAsB;AACzD,MAAI;AACF,WAAO,IAAI,IAAI,GAAG,EAAE;AAAA,EACtB,QAAQ;AACN,UAAM,IAAI,MAAM,+CAA+C,IAAI,kBAAkB,GAAG,IAAI;AAAA,EAC9F;AACF;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/state/middleware/makeswift-api-client-sync.ts"],"sourcesContent":["import { type Middleware } from '@reduxjs/toolkit'\n\nimport { MakeswiftHostApiClient } from '../../api/client'\n\nimport { type Action } from '../actions'\nimport { actionMiddleware } from '../toolkit'\nimport { type State, type Dispatch } from '../unified-state'\n\nexport function makeswiftApiClientSyncMiddleware(\n client: MakeswiftHostApiClient,\n): Middleware<Dispatch, State, Dispatch> {\n return actionMiddleware(() => next => {\n return (action: Action) => {\n client.store.dispatch(action)\n\n return next(action)\n }\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,IAAAA,kBAAiC;AAG1B,SAAS,iCACd,QACuC;AACvC,aAAO,kCAAiB,MAAM,UAAQ;AACpC,WAAO,CAAC,WAAmB;AACzB,aAAO,MAAM,SAAS,MAAM;AAE5B,aAAO,KAAK,MAAM;AAAA,IACpB;AAAA,EACF,CAAC;AACH;","names":["import_toolkit"]}
1
+ {"version":3,"sources":["../../../../src/state/middleware/makeswift-api-client-sync.ts"],"sourcesContent":["import { type Middleware } from '@reduxjs/toolkit'\n\nimport { ApiResourcesClient } from '../../api/api-resources-client'\n\nimport { type Action } from '../actions'\nimport { actionMiddleware } from '../toolkit'\nimport { type State, type Dispatch } from '../unified-state'\n\nexport function makeswiftApiClientSyncMiddleware(\n client: ApiResourcesClient,\n): Middleware<Dispatch, State, Dispatch> {\n return actionMiddleware(() => next => {\n return (action: Action) => {\n client.store.dispatch(action)\n\n return next(action)\n }\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,IAAAA,kBAAiC;AAG1B,SAAS,iCACd,QACuC;AACvC,aAAO,kCAAiB,MAAM,UAAQ;AACpC,WAAO,CAAC,WAAmB;AACzB,aAAO,MAAM,SAAS,MAAM;AAE5B,aAAO,KAAK,MAAM;AAAA,IACpB;AAAA,EACF,CAAC;AACH;","names":["import_toolkit"]}
@@ -124,7 +124,7 @@ function withMixin(mixin) {
124
124
  function configureReadWriteStore({
125
125
  name,
126
126
  appOrigin,
127
- hostApiClient,
127
+ apiResourcesClient,
128
128
  preloadedState
129
129
  }) {
130
130
  const readWriteMiddlewareRef = {
@@ -168,7 +168,7 @@ function configureReadWriteStore({
168
168
  name,
169
169
  preloadedState,
170
170
  middleware: () => [
171
- (0, import_makeswift_api_client_sync.makeswiftApiClientSyncMiddleware)(hostApiClient),
171
+ (0, import_makeswift_api_client_sync.makeswiftApiClientSyncMiddleware)(apiResourcesClient),
172
172
  conditionalReadWriteMiddleware(readWriteMiddlewareRef)
173
173
  ],
174
174
  enhancers: () => new import_toolkit.Tuple(
@@ -180,7 +180,7 @@ function configureReadWriteStore({
180
180
  })
181
181
  ),
182
182
  withMixin({
183
- hostApiClient,
183
+ apiResourcesClient,
184
184
  loadReadWriteStateIfNeeded: async () => {
185
185
  const { isReadOnly } = store.getState();
186
186
  if (isReadOnly) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/state/store.ts"],"sourcesContent":["import {\n type Middleware,\n type StoreEnhancer,\n type MiddlewareAPI,\n Tuple,\n configureStore as configureReduxStore,\n combineReducers,\n compose,\n} from '@reduxjs/toolkit'\n\nimport { MakeswiftHostApiClient } from '../api/client'\n\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\nimport { BuilderActionTypes } from './builder-api/actions'\nimport { HostActionTypes } from './host-api'\n\nimport * as Breakpoints from './modules/breakpoints'\n\nimport { readOnlyElementTreeMiddleware } from './middleware/read-only-element-tree'\nimport { makeswiftApiClientSyncMiddleware } from './middleware/makeswift-api-client-sync'\nimport { type BreakpointWatch, breakpointWatchMixin } from './mixins/breakpoint-watch'\n\nimport { type Action } from './actions'\n\nimport { type State as ReadWriteState } from './read-write-state'\nimport * as ReadOnlyState from './read-only-state'\nimport {\n type State,\n type Dispatch,\n type ReadOnlyReducer,\n type ReadWriteDispatch,\n} from './unified-state'\n\nexport { type State } from './unified-state'\n\nconst configureStore = <Items extends readonly StoreEnhancer[] = []>({\n name,\n preloadedState,\n enhancers,\n middleware,\n}: {\n name: string\n preloadedState: Partial<State>\n enhancers: () => Tuple<Items>\n middleware?: () => Middleware[]\n}) => {\n const store = configureReduxStore({\n reducer: combineReducers(ReadOnlyState.reducers),\n preloadedState,\n\n middleware: getDefaultMiddleware =>\n getDefaultMiddleware(middlewareOptions).concat([\n readOnlyElementTreeMiddleware(),\n ...(middleware ? middleware() : []),\n ]),\n\n enhancers: getDefaultEnhancers => getDefaultEnhancers().concat(enhancers()),\n\n devTools: devToolsConfig({\n name: `${name} (${new Date().toISOString()})`,\n actionsDenylist: [\n HostActionTypes.BUILDER_POINTER_MOVE,\n BuilderActionTypes.HANDLE_POINTER_MOVE,\n BuilderActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n }),\n })\n\n return store\n}\n\nexport function configureProtoStore({\n name,\n breakpoints,\n}: {\n name: string\n breakpoints: Breakpoints.Breakpoints | undefined\n}) {\n return configureStore({\n name,\n preloadedState: {\n breakpoints: Breakpoints.getInitialState(breakpoints),\n },\n enhancers: () => new Tuple(),\n })\n}\n\nexport type ProtoStore = ReturnType<typeof configureProtoStore>\n\ntype ReadWriteMiddleware = ReturnType<\n typeof import('./middleware/read-write').createReadWriteMiddleware\n>\n\ntype ReadWriteMiddlewareRef = {\n current: ReadWriteMiddleware | null\n}\n\nexport function conditionalReadWriteMiddleware(\n middlewareRef: ReadWriteMiddlewareRef,\n): Middleware<Dispatch, State, Dispatch> {\n let readWriteActionBuffer: Action[] = []\n let middlewares: ReadWriteMiddleware | null = null\n let enhancedDispatch: Dispatch | null = null\n\n return actionMiddleware(({ dispatch, getState }) => next => {\n return (action: Action) => {\n const state = getState()\n\n if (middlewareRef.current == null) {\n if (!state.isReadOnly) {\n // because switching to the read-write state is an asynchronous operation,\n // we need to buffer all actions dispatched after the isReadOnly state is\n // set to false but before the read-write middleware is installed\n readWriteActionBuffer.push(action)\n }\n\n return next(action)\n }\n\n if (state.isReadOnly) {\n console.error('Read-write state mismatch', {\n isReadOnly: state.isReadOnly,\n middlewareRef: middlewareRef.current,\n siteVersion: state.siteVersion,\n })\n }\n\n // build and cache the enhanced dispatch chain when read-write middleware is installed\n if (enhancedDispatch == null || middlewares !== middlewareRef.current) {\n middlewares = middlewareRef.current\n\n const middlewareApi = { dispatch, getState } as MiddlewareAPI<\n ReadWriteDispatch,\n ReadWriteState\n >\n\n enhancedDispatch = compose<Dispatch>(...middlewares.map(mw => mw(middlewareApi)))(next)\n }\n\n // dispatch buffered actions, if any\n if (readWriteActionBuffer.length > 0) {\n const readWriteActions = [...readWriteActionBuffer]\n readWriteActionBuffer = []\n\n // Note that we're rerunning the actions through the entire middleware chain,\n // including the read-only middleware and the reducers, some of which have\n // already processed these actions once. This is safe to do because actions that\n // are run as part of page initialization are idempotent.\n for (const bufferedAction of readWriteActions) {\n enhancedDispatch(bufferedAction)\n }\n }\n\n return enhancedDispatch(action)\n }\n })\n}\n\nexport interface ReadWriteStateMixin {\n readonly hostApiClient: MakeswiftHostApiClient\n\n loadReadWriteStateIfNeeded(): Promise<() => void>\n}\n\nfunction withMixin<M extends {}>(mixin: M): StoreEnhancer<M> {\n return next => (reducer, preloadedState?) => ({\n ...next(reducer, preloadedState),\n ...mixin,\n })\n}\n\nexport function configureReadWriteStore({\n name,\n appOrigin,\n hostApiClient,\n preloadedState,\n}: {\n name: string\n appOrigin: string\n hostApiClient: MakeswiftHostApiClient\n preloadedState: Partial<State>\n}) {\n const readWriteMiddlewareRef: ReadWriteMiddlewareRef = {\n current: null,\n }\n\n let refCount = 0\n let readWriteCleanup: (() => void) | null = null\n let readWriteSetupPromise: Promise<void> | null = null\n\n const loadReadWriteState = async (): Promise<void> => {\n if (readWriteCleanup != null) {\n return\n }\n\n if (readWriteSetupPromise != null) {\n await readWriteSetupPromise\n return\n }\n\n readWriteSetupPromise = (async () => {\n // import all the modules needed for read-write mode before proceeding with\n // the setup to avoid race conditions when `setup` is called concurrently\n // in two different page regions\n const { BuilderAPIProxy } = await import('./builder-api/proxy')\n const { createRootReducer, setupBuilderProxy } = await import('./read-write-state')\n const { createReadWriteMiddleware } = await import('./middleware/read-write')\n\n // IMPORTANT: only synchronous code after this point\n\n // with all modules imported, check if another concurrent setup already\n // initialized the read-write middleware\n if (readWriteMiddlewareRef.current != null) {\n return\n }\n\n store.replaceReducer(createRootReducer() as ReadOnlyReducer)\n\n const builderProxy = new BuilderAPIProxy({ appOrigin })\n readWriteMiddlewareRef.current = createReadWriteMiddleware({ builderProxy })\n\n const dispatch = store.dispatch as ReadWriteDispatch\n const builderProxyCleanup = dispatch(setupBuilderProxy(builderProxy))\n\n readWriteCleanup = () => {\n readWriteMiddlewareRef.current = null\n builderProxyCleanup()\n }\n })()\n\n try {\n await readWriteSetupPromise\n } finally {\n readWriteSetupPromise = null\n }\n }\n\n const store = configureStore({\n name,\n preloadedState,\n\n middleware: () => [\n makeswiftApiClientSyncMiddleware(hostApiClient),\n conditionalReadWriteMiddleware(readWriteMiddlewareRef),\n ],\n\n enhancers: () =>\n new Tuple(\n withMixin<BreakpointWatch>(\n breakpointWatchMixin({\n dispatch: (...args: Parameters<Dispatch>) => store.dispatch(...args),\n getState: (): State => store.getState(),\n subscribe: (listener): VoidFunction => store.subscribe(listener),\n }),\n ),\n\n withMixin<ReadWriteStateMixin>({\n hostApiClient,\n loadReadWriteStateIfNeeded: async () => {\n const { isReadOnly } = store.getState()\n\n if (isReadOnly) {\n if (refCount > 0) {\n console.error('Read-write state mismatch', { isReadOnly, refCount })\n }\n\n return () => {}\n }\n\n await loadReadWriteState()\n refCount += 1\n\n let didCleanup = false\n return () => {\n if (didCleanup) {\n return\n }\n\n didCleanup = true\n refCount -= 1\n if (refCount === 0 && readWriteCleanup != null) {\n readWriteCleanup()\n readWriteCleanup = null\n }\n }\n },\n }),\n ),\n })\n\n return store\n}\n\nexport type Store = ReturnType<typeof configureReadWriteStore>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAQO;AAIP,IAAAA,kBAAoE;AACpE,qBAAmC;AACnC,sBAAgC;AAEhC,kBAA6B;AAE7B,oCAA8C;AAC9C,uCAAiD;AACjD,8BAA2D;AAK3D,oBAA+B;AAU/B,MAAM,iBAAiB,CAA8C;AAAA,EACnE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAKM;AACJ,QAAM,YAAQ,eAAAC,gBAAoB;AAAA,IAChC,aAAS,gCAAgB,cAAc,QAAQ;AAAA,IAC/C;AAAA,IAEA,YAAY,0BACV,qBAAqB,iCAAiB,EAAE,OAAO;AAAA,UAC7C,6DAA8B;AAAA,MAC9B,GAAI,aAAa,WAAW,IAAI,CAAC;AAAA,IACnC,CAAC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BAAwB;AAAA,IAC1B;AAAA,EACF;AAEA,QAAM,QAAQ,eAAe;AAAA,IAC3B;AAAA,IACA;AAAA,IAEA,YAAY,MAAM;AAAA,UAChB,mEAAiC,aAAa;AAAA,MAC9C,+BAA+B,sBAAsB;AAAA,IACvD;AAAA,IAEA,WAAW,MACT,IAAI;AAAA,MACF;AAAA,YACE,8CAAqB;AAAA,UACnB,UAAU,IAAI,SAA+B,MAAM,SAAS,GAAG,IAAI;AAAA,UACnE,UAAU,MAAa,MAAM,SAAS;AAAA,UACtC,WAAW,CAAC,aAA2B,MAAM,UAAU,QAAQ;AAAA,QACjE,CAAC;AAAA,MACH;AAAA,MAEA,UAA+B;AAAA,QAC7B;AAAA,QACA,4BAA4B,YAAY;AACtC,gBAAM,EAAE,WAAW,IAAI,MAAM,SAAS;AAEtC,cAAI,YAAY;AACd,gBAAI,WAAW,GAAG;AAChB,sBAAQ,MAAM,6BAA6B,EAAE,YAAY,SAAS,CAAC;AAAA,YACrE;AAEA,mBAAO,MAAM;AAAA,YAAC;AAAA,UAChB;AAEA,gBAAM,mBAAmB;AACzB,sBAAY;AAEZ,cAAI,aAAa;AACjB,iBAAO,MAAM;AACX,gBAAI,YAAY;AACd;AAAA,YACF;AAEA,yBAAa;AACb,wBAAY;AACZ,gBAAI,aAAa,KAAK,oBAAoB,MAAM;AAC9C,+BAAiB;AACjB,iCAAmB;AAAA,YACrB;AAAA,UACF;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACJ,CAAC;AAED,SAAO;AACT;","names":["import_toolkit","configureReduxStore"]}
1
+ {"version":3,"sources":["../../../src/state/store.ts"],"sourcesContent":["import {\n type Middleware,\n type StoreEnhancer,\n type MiddlewareAPI,\n Tuple,\n configureStore as configureReduxStore,\n combineReducers,\n compose,\n} from '@reduxjs/toolkit'\n\nimport { ApiResourcesClient } from '../api/api-resources-client'\n\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\nimport { BuilderActionTypes } from './builder-api/actions'\nimport { HostActionTypes } from './host-api'\n\nimport * as Breakpoints from './modules/breakpoints'\n\nimport { readOnlyElementTreeMiddleware } from './middleware/read-only-element-tree'\nimport { makeswiftApiClientSyncMiddleware } from './middleware/makeswift-api-client-sync'\nimport { type BreakpointWatch, breakpointWatchMixin } from './mixins/breakpoint-watch'\n\nimport { type Action } from './actions'\n\nimport { type State as ReadWriteState } from './read-write-state'\nimport * as ReadOnlyState from './read-only-state'\nimport {\n type State,\n type Dispatch,\n type ReadOnlyReducer,\n type ReadWriteDispatch,\n} from './unified-state'\n\nexport { type State } from './unified-state'\n\nconst configureStore = <Items extends readonly StoreEnhancer[] = []>({\n name,\n preloadedState,\n enhancers,\n middleware,\n}: {\n name: string\n preloadedState: Partial<State>\n enhancers: () => Tuple<Items>\n middleware?: () => Middleware[]\n}) => {\n const store = configureReduxStore({\n reducer: combineReducers(ReadOnlyState.reducers),\n preloadedState,\n\n middleware: getDefaultMiddleware =>\n getDefaultMiddleware(middlewareOptions).concat([\n readOnlyElementTreeMiddleware(),\n ...(middleware ? middleware() : []),\n ]),\n\n enhancers: getDefaultEnhancers => getDefaultEnhancers().concat(enhancers()),\n\n devTools: devToolsConfig({\n name: `${name} (${new Date().toISOString()})`,\n actionsDenylist: [\n HostActionTypes.BUILDER_POINTER_MOVE,\n BuilderActionTypes.HANDLE_POINTER_MOVE,\n BuilderActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n }),\n })\n\n return store\n}\n\nexport function configureProtoStore({\n name,\n breakpoints,\n}: {\n name: string\n breakpoints: Breakpoints.Breakpoints | undefined\n}) {\n return configureStore({\n name,\n preloadedState: {\n breakpoints: Breakpoints.getInitialState(breakpoints),\n },\n enhancers: () => new Tuple(),\n })\n}\n\nexport type ProtoStore = ReturnType<typeof configureProtoStore>\n\ntype ReadWriteMiddleware = ReturnType<\n typeof import('./middleware/read-write').createReadWriteMiddleware\n>\n\ntype ReadWriteMiddlewareRef = {\n current: ReadWriteMiddleware | null\n}\n\nexport function conditionalReadWriteMiddleware(\n middlewareRef: ReadWriteMiddlewareRef,\n): Middleware<Dispatch, State, Dispatch> {\n let readWriteActionBuffer: Action[] = []\n let middlewares: ReadWriteMiddleware | null = null\n let enhancedDispatch: Dispatch | null = null\n\n return actionMiddleware(({ dispatch, getState }) => next => {\n return (action: Action) => {\n const state = getState()\n\n if (middlewareRef.current == null) {\n if (!state.isReadOnly) {\n // because switching to the read-write state is an asynchronous operation,\n // we need to buffer all actions dispatched after the isReadOnly state is\n // set to false but before the read-write middleware is installed\n readWriteActionBuffer.push(action)\n }\n\n return next(action)\n }\n\n if (state.isReadOnly) {\n console.error('Read-write state mismatch', {\n isReadOnly: state.isReadOnly,\n middlewareRef: middlewareRef.current,\n siteVersion: state.siteVersion,\n })\n }\n\n // build and cache the enhanced dispatch chain when read-write middleware is installed\n if (enhancedDispatch == null || middlewares !== middlewareRef.current) {\n middlewares = middlewareRef.current\n\n const middlewareApi = { dispatch, getState } as MiddlewareAPI<\n ReadWriteDispatch,\n ReadWriteState\n >\n\n enhancedDispatch = compose<Dispatch>(...middlewares.map(mw => mw(middlewareApi)))(next)\n }\n\n // dispatch buffered actions, if any\n if (readWriteActionBuffer.length > 0) {\n const readWriteActions = [...readWriteActionBuffer]\n readWriteActionBuffer = []\n\n // Note that we're rerunning the actions through the entire middleware chain,\n // including the read-only middleware and the reducers, some of which have\n // already processed these actions once. This is safe to do because actions that\n // are run as part of page initialization are idempotent.\n for (const bufferedAction of readWriteActions) {\n enhancedDispatch(bufferedAction)\n }\n }\n\n return enhancedDispatch(action)\n }\n })\n}\n\nexport interface ReadWriteStateMixin {\n readonly apiResourcesClient: ApiResourcesClient\n\n loadReadWriteStateIfNeeded(): Promise<() => void>\n}\n\nfunction withMixin<M extends {}>(mixin: M): StoreEnhancer<M> {\n return next => (reducer, preloadedState?) => ({\n ...next(reducer, preloadedState),\n ...mixin,\n })\n}\n\nexport function configureReadWriteStore({\n name,\n appOrigin,\n apiResourcesClient,\n preloadedState,\n}: {\n name: string\n appOrigin: string\n apiResourcesClient: ApiResourcesClient\n preloadedState: Partial<State>\n}) {\n const readWriteMiddlewareRef: ReadWriteMiddlewareRef = {\n current: null,\n }\n\n let refCount = 0\n let readWriteCleanup: (() => void) | null = null\n let readWriteSetupPromise: Promise<void> | null = null\n\n const loadReadWriteState = async (): Promise<void> => {\n if (readWriteCleanup != null) {\n return\n }\n\n if (readWriteSetupPromise != null) {\n await readWriteSetupPromise\n return\n }\n\n readWriteSetupPromise = (async () => {\n // import all the modules needed for read-write mode before proceeding with\n // the setup to avoid race conditions when `setup` is called concurrently\n // in two different page regions\n const { BuilderAPIProxy } = await import('./builder-api/proxy')\n const { createRootReducer, setupBuilderProxy } = await import('./read-write-state')\n const { createReadWriteMiddleware } = await import('./middleware/read-write')\n\n // IMPORTANT: only synchronous code after this point\n\n // with all modules imported, check if another concurrent setup already\n // initialized the read-write middleware\n if (readWriteMiddlewareRef.current != null) {\n return\n }\n\n store.replaceReducer(createRootReducer() as ReadOnlyReducer)\n\n const builderProxy = new BuilderAPIProxy({ appOrigin })\n readWriteMiddlewareRef.current = createReadWriteMiddleware({ builderProxy })\n\n const dispatch = store.dispatch as ReadWriteDispatch\n const builderProxyCleanup = dispatch(setupBuilderProxy(builderProxy))\n\n readWriteCleanup = () => {\n readWriteMiddlewareRef.current = null\n builderProxyCleanup()\n }\n })()\n\n try {\n await readWriteSetupPromise\n } finally {\n readWriteSetupPromise = null\n }\n }\n\n const store = configureStore({\n name,\n preloadedState,\n\n middleware: () => [\n makeswiftApiClientSyncMiddleware(apiResourcesClient),\n conditionalReadWriteMiddleware(readWriteMiddlewareRef),\n ],\n\n enhancers: () =>\n new Tuple(\n withMixin<BreakpointWatch>(\n breakpointWatchMixin({\n dispatch: (...args: Parameters<Dispatch>) => store.dispatch(...args),\n getState: (): State => store.getState(),\n subscribe: (listener): VoidFunction => store.subscribe(listener),\n }),\n ),\n\n withMixin<ReadWriteStateMixin>({\n apiResourcesClient,\n loadReadWriteStateIfNeeded: async () => {\n const { isReadOnly } = store.getState()\n\n if (isReadOnly) {\n if (refCount > 0) {\n console.error('Read-write state mismatch', { isReadOnly, refCount })\n }\n\n return () => {}\n }\n\n await loadReadWriteState()\n refCount += 1\n\n let didCleanup = false\n return () => {\n if (didCleanup) {\n return\n }\n\n didCleanup = true\n refCount -= 1\n if (refCount === 0 && readWriteCleanup != null) {\n readWriteCleanup()\n readWriteCleanup = null\n }\n }\n },\n }),\n ),\n })\n\n return store\n}\n\nexport type Store = ReturnType<typeof configureReadWriteStore>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAQO;AAIP,IAAAA,kBAAoE;AACpE,qBAAmC;AACnC,sBAAgC;AAEhC,kBAA6B;AAE7B,oCAA8C;AAC9C,uCAAiD;AACjD,8BAA2D;AAK3D,oBAA+B;AAU/B,MAAM,iBAAiB,CAA8C;AAAA,EACnE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAKM;AACJ,QAAM,YAAQ,eAAAC,gBAAoB;AAAA,IAChC,aAAS,gCAAgB,cAAc,QAAQ;AAAA,IAC/C;AAAA,IAEA,YAAY,0BACV,qBAAqB,iCAAiB,EAAE,OAAO;AAAA,UAC7C,6DAA8B;AAAA,MAC9B,GAAI,aAAa,WAAW,IAAI,CAAC;AAAA,IACnC,CAAC;AAAA,IAEH,WAAW,yBAAuB,oBAAoB,EAAE,OAAO,UAAU,CAAC;AAAA,IAE1E,cAAU,gCAAe;AAAA,MACvB,MAAM,GAAG,IAAI,MAAK,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,MAC1C,iBAAiB;AAAA,QACf,gCAAgB;AAAA,QAChB,kCAAmB;AAAA,QACnB,kCAAmB;AAAA,MACrB;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AAED,SAAO;AACT;AAEO,SAAS,oBAAoB;AAAA,EAClC;AAAA,EACA;AACF,GAGG;AACD,SA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AM,UAAU,QAAQ;AAAA,QACjE,CAAC;AAAA,MACH;AAAA,MAEA,UAA+B;AAAA,QAC7B;AAAA,QACA,4BAA4B,YAAY;AACtC,gBAAM,EAAE,WAAW,IAAI,MAAM,SAAS;AAEtC,cAAI,YAAY;AACd,gBAAI,WAAW,GAAG;AAChB,sBAAQ,MAAM,6BAA6B,EAAE,YAAY,SAAS,CAAC;AAAA,YACrE;AAEA,mBAAO,MAAM;AAAA,YAAC;AAAA,UAChB;AAEA,gBAAM,mBAAmB;AACzB,sBAAY;AAEZ,cAAI,aAAa;AACjB,iBAAO,MAAM;AACX,gBAAI,YAAY;AACd;AAAA,YACF;AAEA,yBAAa;AACb,wBAAY;AACZ,gBAAI,aAAa,KAAK,oBAAoB,MAAM;AAC9C,+BAAiB;AACjB,iCAAmB;AAAA,YACrB;AAAA,UACF;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACJ,CAAC;AAED,SAAO;AACT;","names":["import_toolkit","configureReduxStore"]}
@@ -5,10 +5,10 @@ import {
5
5
  TableFragment,
6
6
  TypographyFragment
7
7
  } from "./fragments";
8
- const IntrospectedResourcesQuery = (
8
+ const UnversionedResourcesQuery = (
9
9
  /* GraphQL */
10
10
  `
11
- query IntrospectedResources($fileIds: [ID!]!, $tableIds: [ID!]!) {
11
+ query UnversionedResources($fileIds: [ID!]!, $tableIds: [ID!]!) {
12
12
  files(ids: $fileIds) {
13
13
  ...File
14
14
  }
@@ -110,10 +110,10 @@ export {
110
110
  CreateTableRecordMutation,
111
111
  FileQuery,
112
112
  GlobalElementQuery,
113
- IntrospectedResourcesQuery,
114
113
  SwatchQuery,
115
114
  TableQuery,
116
115
  TypographiesQuery,
117
- TypographyQuery
116
+ TypographyQuery,
117
+ UnversionedResourcesQuery
118
118
  };
119
119
  //# sourceMappingURL=queries.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/api/graphql/documents/queries.ts"],"sourcesContent":["import {\n FileFragment,\n GlobalElementFragment,\n SwatchFragment,\n TableFragment,\n TypographyFragment,\n} from './fragments'\n\nexport const IntrospectedResourcesQuery = /* GraphQL */ `\n query IntrospectedResources($fileIds: [ID!]!, $tableIds: [ID!]!) {\n files(ids: $fileIds) {\n ...File\n }\n\n tables(ids: $tableIds) {\n ...Table\n }\n }\n\n ${FileFragment}\n ${TableFragment}\n`\n\nexport const SwatchQuery = /* GraphQL */ `\n query Swatch($swatchId: ID!) {\n swatch(id: $swatchId) {\n ...Swatch\n }\n }\n\n ${SwatchFragment}\n`\n\nexport const FileQuery = /* GraphQL */ `\n query File($fileId: ID!) {\n file(id: $fileId) {\n ...File\n }\n }\n\n ${FileFragment}\n`\n\nexport const TypographyQuery = /* GraphQL */ `\n query Typography($typographyId: ID!) {\n typography(id: $typographyId) {\n ...Typography\n }\n }\n\n ${TypographyFragment}\n`\n\nexport const TableQuery = /* GraphQL */ `\n query Table($tableId: ID!) {\n table(id: $tableId) {\n ...Table\n }\n }\n\n ${TableFragment}\n`\n\nexport const TypographiesQuery = /* GraphQL */ `\n query Typographies($typographyIds: [ID!]!) {\n typographies(ids: $typographyIds) {\n ...Typography\n }\n }\n\n ${TypographyFragment}\n`\n\nexport const GlobalElementQuery = /* GraphQL */ `\n query GlobalElement($globalElementId: ID!) {\n globalElement(id: $globalElementId) {\n ...GlobalElement\n }\n }\n\n ${GlobalElementFragment}\n`\n\nexport const CreateTableRecordMutation = /* GraphQL */ `\n mutation CreateTableRecord($input: CreateTableRecordInput!) {\n createTableRecord(input: $input) {\n tableRecord {\n id\n }\n }\n }\n`\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,MAAM;AAAA;AAAA,EAA2C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAWpD,YAAY;AAAA,IACZ,aAAa;AAAA;AAAA;AAGV,MAAM;AAAA;AAAA,EAA4B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOrC,cAAc;AAAA;AAAA;AAGX,MAAM;AAAA;AAAA,EAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOnC,YAAY;AAAA;AAAA;AAGT,MAAM;AAAA;AAAA,EAAgC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOzC,kBAAkB;AAAA;AAAA;AAGf,MAAM;AAAA;AAAA,EAA2B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOpC,aAAa;AAAA;AAAA;AAGV,MAAM;AAAA;AAAA,EAAkC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAO3C,kBAAkB;AAAA;AAAA;AAGf,MAAM;AAAA;AAAA,EAAmC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAO5C,qBAAqB;AAAA;AAAA;AAGlB,MAAM;AAAA;AAAA,EAA0C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/api/graphql/documents/queries.ts"],"sourcesContent":["import {\n FileFragment,\n GlobalElementFragment,\n SwatchFragment,\n TableFragment,\n TypographyFragment,\n} from './fragments'\n\nexport const UnversionedResourcesQuery = /* GraphQL */ `\n query UnversionedResources($fileIds: [ID!]!, $tableIds: [ID!]!) {\n files(ids: $fileIds) {\n ...File\n }\n\n tables(ids: $tableIds) {\n ...Table\n }\n }\n\n ${FileFragment}\n ${TableFragment}\n`\n\nexport const SwatchQuery = /* GraphQL */ `\n query Swatch($swatchId: ID!) {\n swatch(id: $swatchId) {\n ...Swatch\n }\n }\n\n ${SwatchFragment}\n`\n\nexport const FileQuery = /* GraphQL */ `\n query File($fileId: ID!) {\n file(id: $fileId) {\n ...File\n }\n }\n\n ${FileFragment}\n`\n\nexport const TypographyQuery = /* GraphQL */ `\n query Typography($typographyId: ID!) {\n typography(id: $typographyId) {\n ...Typography\n }\n }\n\n ${TypographyFragment}\n`\n\nexport const TableQuery = /* GraphQL */ `\n query Table($tableId: ID!) {\n table(id: $tableId) {\n ...Table\n }\n }\n\n ${TableFragment}\n`\n\nexport const TypographiesQuery = /* GraphQL */ `\n query Typographies($typographyIds: [ID!]!) {\n typographies(ids: $typographyIds) {\n ...Typography\n }\n }\n\n ${TypographyFragment}\n`\n\nexport const GlobalElementQuery = /* GraphQL */ `\n query GlobalElement($globalElementId: ID!) {\n globalElement(id: $globalElementId) {\n ...GlobalElement\n }\n }\n\n ${GlobalElementFragment}\n`\n\nexport const CreateTableRecordMutation = /* GraphQL */ `\n mutation CreateTableRecord($input: CreateTableRecordInput!) {\n createTableRecord(input: $input) {\n tableRecord {\n id\n }\n }\n }\n`\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,MAAM;AAAA;AAAA,EAA0C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAWnD,YAAY;AAAA,IACZ,aAAa;AAAA;AAAA;AAGV,MAAM;AAAA;AAAA,EAA4B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOrC,cAAc;AAAA;AAAA;AAGX,MAAM;AAAA;AAAA,EAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOnC,YAAY;AAAA;AAAA;AAGT,MAAM;AAAA;AAAA,EAAgC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOzC,kBAAkB;AAAA;AAAA;AAGf,MAAM;AAAA;AAAA,EAA2B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOpC,aAAa;AAAA;AAAA;AAGV,MAAM;AAAA;AAAA,EAAkC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAO3C,kBAAkB;AAAA;AAAA;AAGf,MAAM;AAAA;AAAA,EAAmC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAO5C,qBAAqB;AAAA;AAAA;AAGlB,MAAM;AAAA;AAAA,EAA0C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/api/graphql/generated/types.ts"],"sourcesContent":["export type Maybe<T> = T | null\nexport type InputMaybe<T> = Maybe<T>\nexport type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] }\n\ntype Json = null | boolean | number | string | Json[] | { [key: string]: Json }\n\ntype Scalars = {\n ID: string\n JSON: Json\n Locale: string\n}\n\nexport type CreateTableRecordInput = {\n data: CreateTableRecordInputData\n}\n\nexport type CreateTableRecordInputData = {\n columns: Array<CreateTableRecordInputDataColumn>\n tableId?: InputMaybe<Scalars['ID']>\n}\n\nexport type CreateTableRecordInputDataColumn = {\n columnId: Scalars['ID']\n data: Scalars['JSON']\n}\n\nexport const SnippetLocation = {\n Body: 'BODY',\n Head: 'HEAD',\n} as const\n\nexport type SnippetLocation = (typeof SnippetLocation)[keyof typeof SnippetLocation]\n\nexport type SwatchFragment = {\n __typename: 'Swatch'\n id: string\n hue: number\n saturation: number\n lightness: number\n}\n\nexport type FileFragment = {\n __typename: 'File'\n id: string\n name: string\n extension: string | null\n publicUrl: string\n dimensions: { width: number; height: number } | null\n}\n\nexport type TypographyFragment = {\n __typename: 'Typography'\n id: string\n name: string\n style: Array<{\n deviceId: string\n value: {\n fontFamily: string | null\n lineHeight: number | null\n letterSpacing: number | null\n fontWeight: number | null\n textAlign: string | null\n uppercase: boolean | null\n underline: boolean | null\n strikethrough: boolean | null\n italic: boolean | null\n fontSize: { value: number | null; unit: string | null } | null\n color: { swatchId: string | null; alpha: number | null } | null\n }\n }>\n}\n\nexport type PagePathnameSliceFragment = {\n __typename: 'PagePathnameSlice'\n id: string\n pathname: string\n}\n\nexport type GlobalElementFragment = { __typename: 'GlobalElement'; id: string; data: Json }\n\nexport type LocalizedGlobalElementFragment = {\n __typename: 'LocalizedGlobalElement'\n id: string\n data: Json\n}\n\nexport type TableFragment = {\n __typename: 'Table'\n id: string\n name: string\n columns: Array<\n | { __typename: 'CheckboxTableColumn'; id: string; name: string }\n | { __typename: 'EmailTableColumn'; id: string; name: string }\n | { __typename: 'LongTextTableColumn'; id: string; name: string }\n | {\n __typename: 'MultipleSelectTableColumn'\n id: string\n name: string\n options: Array<{ id: string; name: string }>\n }\n | { __typename: 'NumberTableColumn'; id: string; name: string }\n | { __typename: 'PhoneNumberTableColumn'; id: string; name: string }\n | { __typename: 'SingleLineTextTableColumn'; id: string; name: string }\n | {\n __typename: 'SingleSelectTableColumn'\n id: string\n name: string\n options: Array<{ id: string; name: string }>\n }\n | { __typename: 'URLTableColumn'; id: string; name: string }\n >\n}\n\nexport type SnippetFragment = {\n __typename: 'Snippet'\n id: string\n name: string\n code: string\n cleanup: string | null\n location: SnippetLocation\n shouldAddToNewPages: boolean\n liveEnabled: boolean\n builderEnabled: boolean\n}\n\nexport type PageFragment = {\n __typename: 'Page'\n id: string\n snippets: Array<{\n __typename: 'Snippet'\n id: string\n name: string\n code: string\n cleanup: string | null\n location: SnippetLocation\n shouldAddToNewPages: boolean\n liveEnabled: boolean\n builderEnabled: boolean\n }>\n}\n\nexport type SiteFragment = {\n __typename: 'Site'\n id: string\n googleFonts: {\n edges: Array<{\n activeVariants: Array<{ specifier: string }>\n node: { family: string; variants: Array<{ specifier: string }> }\n } | null>\n }\n}\n\nexport type IntrospectedResourcesQueryVariables = Exact<{\n fileIds: Array<Scalars['ID']> | Scalars['ID']\n tableIds: Array<Scalars['ID']> | Scalars['ID']\n}>\n\nexport type IntrospectedResourcesQueryResult = {\n files: Array<{\n __typename: 'File'\n id: string\n name: string\n extension: string | null\n publicUrl: string\n dimensions: { width: number; height: number } | null\n } | null>\n tables: Array<{\n __typename: 'Table'\n id: string\n name: string\n columns: Array<\n | { __typename: 'CheckboxTableColumn'; id: string; name: string }\n | { __typename: 'EmailTableColumn'; id: string; name: string }\n | { __typename: 'LongTextTableColumn'; id: string; name: string }\n | {\n __typename: 'MultipleSelectTableColumn'\n id: string\n name: string\n options: Array<{ id: string; name: string }>\n }\n | { __typename: 'NumberTableColumn'; id: string; name: string }\n | { __typename: 'PhoneNumberTableColumn'; id: string; name: string }\n | { __typename: 'SingleLineTextTableColumn'; id: string; name: string }\n | {\n __typename: 'SingleSelectTableColumn'\n id: string\n name: string\n options: Array<{ id: string; name: string }>\n }\n | { __typename: 'URLTableColumn'; id: string; name: string }\n >\n } | null>\n}\n\nexport type SwatchQueryVariables = Exact<{\n swatchId: Scalars['ID']\n}>\n\nexport type SwatchQueryResult = {\n swatch: {\n __typename: 'Swatch'\n id: string\n hue: number\n saturation: number\n lightness: number\n } | null\n}\n\nexport type FileQueryVariables = Exact<{\n fileId: Scalars['ID']\n}>\n\nexport type FileQueryResult = {\n file: {\n __typename: 'File'\n id: string\n name: string\n extension: string | null\n publicUrl: string\n dimensions: { width: number; height: number } | null\n } | null\n}\n\nexport type TypographyQueryVariables = Exact<{\n typographyId: Scalars['ID']\n}>\n\nexport type TypographyQueryResult = {\n typography: {\n __typename: 'Typography'\n id: string\n name: string\n style: Array<{\n deviceId: string\n value: {\n fontFamily: string | null\n lineHeight: number | null\n letterSpacing: number | null\n fontWeight: number | null\n textAlign: string | null\n uppercase: boolean | null\n underline: boolean | null\n strikethrough: boolean | null\n italic: boolean | null\n fontSize: { value: number | null; unit: string | null } | null\n color: { swatchId: string | null; alpha: number | null } | null\n }\n }>\n } | null\n}\n\nexport type TableQueryVariables = Exact<{\n tableId: Scalars['ID']\n}>\n\nexport type TableQueryResult = {\n table: {\n __typename: 'Table'\n id: string\n name: string\n columns: Array<\n | { __typename: 'CheckboxTableColumn'; id: string; name: string }\n | { __typename: 'EmailTableColumn'; id: string; name: string }\n | { __typename: 'LongTextTableColumn'; id: string; name: string }\n | {\n __typename: 'MultipleSelectTableColumn'\n id: string\n name: string\n options: Array<{ id: string; name: string }>\n }\n | { __typename: 'NumberTableColumn'; id: string; name: string }\n | { __typename: 'PhoneNumberTableColumn'; id: string; name: string }\n | { __typename: 'SingleLineTextTableColumn'; id: string; name: string }\n | {\n __typename: 'SingleSelectTableColumn'\n id: string\n name: string\n options: Array<{ id: string; name: string }>\n }\n | { __typename: 'URLTableColumn'; id: string; name: string }\n >\n } | null\n}\n\nexport type TypographiesQueryVariables = Exact<{\n typographyIds: Array<Scalars['ID']> | Scalars['ID']\n}>\n\nexport type TypographiesQueryResult = {\n typographies: Array<{\n __typename: 'Typography'\n id: string\n name: string\n style: Array<{\n deviceId: string\n value: {\n fontFamily: string | null\n lineHeight: number | null\n letterSpacing: number | null\n fontWeight: number | null\n textAlign: string | null\n uppercase: boolean | null\n underline: boolean | null\n strikethrough: boolean | null\n italic: boolean | null\n fontSize: { value: number | null; unit: string | null } | null\n color: { swatchId: string | null; alpha: number | null } | null\n }\n }>\n } | null>\n}\n\nexport type GlobalElementQueryVariables = Exact<{\n globalElementId: Scalars['ID']\n}>\n\nexport type GlobalElementQueryResult = {\n globalElement: { __typename: 'GlobalElement'; id: string; data: Json } | null\n}\n\nexport type CreateTableRecordMutationVariables = Exact<{\n input: CreateTableRecordInput\n}>\n\nexport type CreateTableRecordMutationResult = { createTableRecord: { tableRecord: { id: string } } }\n"],"mappings":"AA0BO,MAAM,kBAAkB;AAAA,EAC7B,MAAM;AAAA,EACN,MAAM;AACR;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/api/graphql/generated/types.ts"],"sourcesContent":["export type Maybe<T> = T | null\nexport type InputMaybe<T> = Maybe<T>\nexport type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] }\n\ntype Json = null | boolean | number | string | Json[] | { [key: string]: Json }\n\ntype Scalars = {\n ID: string\n JSON: Json\n Locale: string\n}\n\nexport type CreateTableRecordInput = {\n data: CreateTableRecordInputData\n}\n\nexport type CreateTableRecordInputData = {\n columns: Array<CreateTableRecordInputDataColumn>\n tableId?: InputMaybe<Scalars['ID']>\n}\n\nexport type CreateTableRecordInputDataColumn = {\n columnId: Scalars['ID']\n data: Scalars['JSON']\n}\n\nexport const SnippetLocation = {\n Body: 'BODY',\n Head: 'HEAD',\n} as const\n\nexport type SnippetLocation = (typeof SnippetLocation)[keyof typeof SnippetLocation]\n\nexport type SwatchFragment = {\n __typename: 'Swatch'\n id: string\n hue: number\n saturation: number\n lightness: number\n}\n\nexport type FileFragment = {\n __typename: 'File'\n id: string\n name: string\n extension: string | null\n publicUrl: string\n dimensions: { width: number; height: number } | null\n}\n\nexport type TypographyFragment = {\n __typename: 'Typography'\n id: string\n name: string\n style: Array<{\n deviceId: string\n value: {\n fontFamily: string | null\n lineHeight: number | null\n letterSpacing: number | null\n fontWeight: number | null\n textAlign: string | null\n uppercase: boolean | null\n underline: boolean | null\n strikethrough: boolean | null\n italic: boolean | null\n fontSize: { value: number | null; unit: string | null } | null\n color: { swatchId: string | null; alpha: number | null } | null\n }\n }>\n}\n\nexport type PagePathnameSliceFragment = {\n __typename: 'PagePathnameSlice'\n id: string\n pathname: string\n}\n\nexport type GlobalElementFragment = { __typename: 'GlobalElement'; id: string; data: Json }\n\nexport type LocalizedGlobalElementFragment = {\n __typename: 'LocalizedGlobalElement'\n id: string\n data: Json\n}\n\nexport type TableFragment = {\n __typename: 'Table'\n id: string\n name: string\n columns: Array<\n | { __typename: 'CheckboxTableColumn'; id: string; name: string }\n | { __typename: 'EmailTableColumn'; id: string; name: string }\n | { __typename: 'LongTextTableColumn'; id: string; name: string }\n | {\n __typename: 'MultipleSelectTableColumn'\n id: string\n name: string\n options: Array<{ id: string; name: string }>\n }\n | { __typename: 'NumberTableColumn'; id: string; name: string }\n | { __typename: 'PhoneNumberTableColumn'; id: string; name: string }\n | { __typename: 'SingleLineTextTableColumn'; id: string; name: string }\n | {\n __typename: 'SingleSelectTableColumn'\n id: string\n name: string\n options: Array<{ id: string; name: string }>\n }\n | { __typename: 'URLTableColumn'; id: string; name: string }\n >\n}\n\nexport type SnippetFragment = {\n __typename: 'Snippet'\n id: string\n name: string\n code: string\n cleanup: string | null\n location: SnippetLocation\n shouldAddToNewPages: boolean\n liveEnabled: boolean\n builderEnabled: boolean\n}\n\nexport type PageFragment = {\n __typename: 'Page'\n id: string\n snippets: Array<{\n __typename: 'Snippet'\n id: string\n name: string\n code: string\n cleanup: string | null\n location: SnippetLocation\n shouldAddToNewPages: boolean\n liveEnabled: boolean\n builderEnabled: boolean\n }>\n}\n\nexport type SiteFragment = {\n __typename: 'Site'\n id: string\n googleFonts: {\n edges: Array<{\n activeVariants: Array<{ specifier: string }>\n node: { family: string; variants: Array<{ specifier: string }> }\n } | null>\n }\n}\n\nexport type UnversionedResourcesQueryVariables = Exact<{\n fileIds: Array<Scalars['ID']> | Scalars['ID']\n tableIds: Array<Scalars['ID']> | Scalars['ID']\n}>\n\nexport type UnversionedResourcesQueryResult = {\n files: Array<{\n __typename: 'File'\n id: string\n name: string\n extension: string | null\n publicUrl: string\n dimensions: { width: number; height: number } | null\n } | null>\n tables: Array<{\n __typename: 'Table'\n id: string\n name: string\n columns: Array<\n | { __typename: 'CheckboxTableColumn'; id: string; name: string }\n | { __typename: 'EmailTableColumn'; id: string; name: string }\n | { __typename: 'LongTextTableColumn'; id: string; name: string }\n | {\n __typename: 'MultipleSelectTableColumn'\n id: string\n name: string\n options: Array<{ id: string; name: string }>\n }\n | { __typename: 'NumberTableColumn'; id: string; name: string }\n | { __typename: 'PhoneNumberTableColumn'; id: string; name: string }\n | { __typename: 'SingleLineTextTableColumn'; id: string; name: string }\n | {\n __typename: 'SingleSelectTableColumn'\n id: string\n name: string\n options: Array<{ id: string; name: string }>\n }\n | { __typename: 'URLTableColumn'; id: string; name: string }\n >\n } | null>\n}\n\nexport type SwatchQueryVariables = Exact<{\n swatchId: Scalars['ID']\n}>\n\nexport type SwatchQueryResult = {\n swatch: {\n __typename: 'Swatch'\n id: string\n hue: number\n saturation: number\n lightness: number\n } | null\n}\n\nexport type FileQueryVariables = Exact<{\n fileId: Scalars['ID']\n}>\n\nexport type FileQueryResult = {\n file: {\n __typename: 'File'\n id: string\n name: string\n extension: string | null\n publicUrl: string\n dimensions: { width: number; height: number } | null\n } | null\n}\n\nexport type TypographyQueryVariables = Exact<{\n typographyId: Scalars['ID']\n}>\n\nexport type TypographyQueryResult = {\n typography: {\n __typename: 'Typography'\n id: string\n name: string\n style: Array<{\n deviceId: string\n value: {\n fontFamily: string | null\n lineHeight: number | null\n letterSpacing: number | null\n fontWeight: number | null\n textAlign: string | null\n uppercase: boolean | null\n underline: boolean | null\n strikethrough: boolean | null\n italic: boolean | null\n fontSize: { value: number | null; unit: string | null } | null\n color: { swatchId: string | null; alpha: number | null } | null\n }\n }>\n } | null\n}\n\nexport type TableQueryVariables = Exact<{\n tableId: Scalars['ID']\n}>\n\nexport type TableQueryResult = {\n table: {\n __typename: 'Table'\n id: string\n name: string\n columns: Array<\n | { __typename: 'CheckboxTableColumn'; id: string; name: string }\n | { __typename: 'EmailTableColumn'; id: string; name: string }\n | { __typename: 'LongTextTableColumn'; id: string; name: string }\n | {\n __typename: 'MultipleSelectTableColumn'\n id: string\n name: string\n options: Array<{ id: string; name: string }>\n }\n | { __typename: 'NumberTableColumn'; id: string; name: string }\n | { __typename: 'PhoneNumberTableColumn'; id: string; name: string }\n | { __typename: 'SingleLineTextTableColumn'; id: string; name: string }\n | {\n __typename: 'SingleSelectTableColumn'\n id: string\n name: string\n options: Array<{ id: string; name: string }>\n }\n | { __typename: 'URLTableColumn'; id: string; name: string }\n >\n } | null\n}\n\nexport type TypographiesQueryVariables = Exact<{\n typographyIds: Array<Scalars['ID']> | Scalars['ID']\n}>\n\nexport type TypographiesQueryResult = {\n typographies: Array<{\n __typename: 'Typography'\n id: string\n name: string\n style: Array<{\n deviceId: string\n value: {\n fontFamily: string | null\n lineHeight: number | null\n letterSpacing: number | null\n fontWeight: number | null\n textAlign: string | null\n uppercase: boolean | null\n underline: boolean | null\n strikethrough: boolean | null\n italic: boolean | null\n fontSize: { value: number | null; unit: string | null } | null\n color: { swatchId: string | null; alpha: number | null } | null\n }\n }>\n } | null>\n}\n\nexport type GlobalElementQueryVariables = Exact<{\n globalElementId: Scalars['ID']\n}>\n\nexport type GlobalElementQueryResult = {\n globalElement: { __typename: 'GlobalElement'; id: string; data: Json } | null\n}\n\nexport type CreateTableRecordMutationVariables = Exact<{\n input: CreateTableRecordInput\n}>\n\nexport type CreateTableRecordMutationResult = { createTableRecord: { tableRecord: { id: string } } }\n"],"mappings":"AA0BO,MAAM,kBAAkB;AAAA,EAC7B,MAAM;AAAA,EACN,MAAM;AACR;","names":[]}
@@ -0,0 +1,42 @@
1
+ import { GraphQLClient } from "./graphql/client";
2
+ import {
3
+ CreateTableRecordMutation,
4
+ FileQuery,
5
+ TableQuery,
6
+ UnversionedResourcesQuery
7
+ } from "./graphql/documents";
8
+ class MakeswiftGraphQLApiClient {
9
+ graphqlClient;
10
+ constructor({ endpoint }) {
11
+ this.graphqlClient = new GraphQLClient(endpoint, {
12
+ "makeswift-runtime-version": "0.28.7-canary.5"
13
+ });
14
+ }
15
+ async createTableRecord(tableId, columns) {
16
+ await this.graphqlClient.request(CreateTableRecordMutation, { input: { data: { tableId, columns } } });
17
+ }
18
+ async getUnversionedResources({
19
+ fileIds,
20
+ tableIds
21
+ }) {
22
+ return await this.graphqlClient.request(UnversionedResourcesQuery, { fileIds, tableIds });
23
+ }
24
+ async getFile(fileId) {
25
+ const result = await this.graphqlClient.request(
26
+ FileQuery,
27
+ { fileId }
28
+ );
29
+ return result.file;
30
+ }
31
+ async getTable(tableId) {
32
+ const result = await this.graphqlClient.request(
33
+ TableQuery,
34
+ { tableId }
35
+ );
36
+ return result.table;
37
+ }
38
+ }
39
+ export {
40
+ MakeswiftGraphQLApiClient
41
+ };
42
+ //# sourceMappingURL=graphql-api-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/api/graphql-api-client.ts"],"sourcesContent":["import { GraphQLClient } from './graphql/client'\n\nimport {\n CreateTableRecordMutation,\n FileQuery,\n TableQuery,\n UnversionedResourcesQuery,\n} from './graphql/documents'\n\nimport {\n type CreateTableRecordMutationResult,\n type CreateTableRecordMutationVariables,\n type FileQueryResult,\n type FileQueryVariables,\n type TableQueryResult,\n type TableQueryVariables,\n type UnversionedResourcesQueryResult,\n type UnversionedResourcesQueryVariables,\n} from './graphql/generated/types'\n\nimport { type File, type Table } from './types'\n\nexport class MakeswiftGraphQLApiClient {\n readonly graphqlClient: GraphQLClient\n\n constructor({ endpoint }: { endpoint: string }) {\n this.graphqlClient = new GraphQLClient(endpoint, {\n 'makeswift-runtime-version': PACKAGE_VERSION,\n })\n }\n\n async createTableRecord(tableId: string, columns: any): Promise<void> {\n await this.graphqlClient.request<\n CreateTableRecordMutationResult,\n CreateTableRecordMutationVariables\n >(CreateTableRecordMutation, { input: { data: { tableId, columns } } })\n }\n\n async getUnversionedResources({\n fileIds,\n tableIds,\n }: UnversionedResourcesQueryVariables): Promise<UnversionedResourcesQueryResult> {\n return await this.graphqlClient.request<\n UnversionedResourcesQueryResult,\n UnversionedResourcesQueryVariables\n >(UnversionedResourcesQuery, { fileIds, tableIds })\n }\n\n async getFile(fileId: string): Promise<File | null> {\n const result = await this.graphqlClient.request<FileQueryResult, FileQueryVariables>(\n FileQuery,\n { fileId },\n )\n\n return result.file\n }\n\n async getTable(tableId: string): Promise<Table | null> {\n const result = await this.graphqlClient.request<TableQueryResult, TableQueryVariables>(\n TableQuery,\n { tableId },\n )\n\n return result.table\n }\n}\n"],"mappings":"AAAA,SAAS,qBAAqB;AAE9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAeA,MAAM,0BAA0B;AAAA,EAC5B;AAAA,EAET,YAAY,EAAE,SAAS,GAAyB;AAC9C,SAAK,gBAAgB,IAAI,cAAc,UAAU;AAAA,MAC/C,6BAA6B;AAAA,IAC/B,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,kBAAkB,SAAiB,SAA6B;AACpE,UAAM,KAAK,cAAc,QAGvB,2BAA2B,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,QAAQ,EAAE,EAAE,CAAC;AAAA,EACxE;AAAA,EAEA,MAAM,wBAAwB;AAAA,IAC5B;AAAA,IACA;AAAA,EACF,GAAiF;AAC/E,WAAO,MAAM,KAAK,cAAc,QAG9B,2BAA2B,EAAE,SAAS,SAAS,CAAC;AAAA,EACpD;AAAA,EAEA,MAAM,QAAQ,QAAsC;AAClD,UAAM,SAAS,MAAM,KAAK,cAAc;AAAA,MACtC;AAAA,MACA,EAAE,OAAO;AAAA,IACX;AAEA,WAAO,OAAO;AAAA,EAChB;AAAA,EAEA,MAAM,SAAS,SAAwC;AACrD,UAAM,SAAS,MAAM,KAAK,cAAc;AAAA,MACtC;AAAA,MACA,EAAE,QAAQ;AAAA,IACZ;AAEA,WAAO,OAAO;AAAA,EAChB;AACF;","names":[]}
@@ -3,22 +3,17 @@ import { configureClientStore } from "../state/api-client/client-store";
3
3
  import {
4
4
  APIResourceType
5
5
  } from "./types";
6
- import { GraphQLClient } from "./graphql/client";
7
- import { CreateTableRecordMutation } from "./graphql/documents";
8
6
  import { ApiResourcesClient } from "./api-resources-client";
9
7
  import { CacheData } from "./api-resources-client";
10
- class MakeswiftHostApiClient extends ApiResourcesClient {
11
- graphqlClient;
8
+ class HostApiResourcesClient extends ApiResourcesClient {
12
9
  fetch;
13
10
  constructor({
14
- uri,
15
11
  fetch,
16
12
  preloadedState
17
13
  }) {
18
14
  super({
19
15
  store: configureClientStore({ preloadedState })
20
16
  });
21
- this.graphqlClient = new GraphQLClient(uri);
22
17
  this.fetch = fetch;
23
18
  }
24
19
  async fetchSwatch(swatchId) {
@@ -56,12 +51,9 @@ class MakeswiftHostApiClient extends ApiResourcesClient {
56
51
  async fetchTable(tableId) {
57
52
  return await this.store.dispatch(fetchAPIResource(APIResourceType.Table, tableId, this.fetch));
58
53
  }
59
- async createTableRecord(tableId, columns) {
60
- await this.graphqlClient.request(CreateTableRecordMutation, { input: { data: { tableId, columns } } });
61
- }
62
54
  }
63
55
  export {
64
56
  CacheData,
65
- MakeswiftHostApiClient
57
+ HostApiResourcesClient
66
58
  };
67
- //# sourceMappingURL=client.js.map
59
+ //# sourceMappingURL=host-api-resources-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/api/host-api-resources-client.ts"],"sourcesContent":["import { type State as ApiClientState } from '../state/api-client/state'\nimport { type HttpFetch, fetchAPIResource } from '../state/api-client/fetch-api-resource'\nimport { configureClientStore } from '../state/api-client/client-store'\n\nimport {\n type File,\n type GlobalElement,\n type LocalizedGlobalElement,\n type PagePathnameSlice,\n type Swatch,\n type Table,\n type Typography,\n APIResourceType,\n} from './types'\n\nimport { ApiResourcesClient } from './api-resources-client'\n\nexport { CacheData } from './api-resources-client'\n\n/**\n * NOTE(miguel): This \"client\" is used to fetch Makeswift API resources needed for the host. For\n * example, swatches, files, typographies, etc. Ideally it's internal to the runtime and is only\n * used by controls to transform API references to API resources.\n *\n * Moreover, its use should be reserved for the builder only, since for live pages all Makeswift\n * API resources should be embedded in the \"page snapshot\". In the builder, this client serves the\n * purpose of sending requests for API resources and keeping a cache so that changes that happen in\n * the builder, like modifying a swatch, can be sent via `postMessage` to the host and the cache can\n * immediately update the value and re-render.\n *\n * Furthermore, the API resources requested shouldn't be requested directly from the Makeswift API\n * as that would require those resources to not be authenticated since the requests come from the\n * browser when running the host. Instead, the requests should go to the host directly, at the\n * Makeswift API endpoint (i.g., `/api/makeswift/[...makeswift]` dynamic route) where the host's\n * API key can be used, securely, in the server. For this reason, this client should really be a\n * client of the host's API, not Makeswift's, intended to build and continuously maintain a realtime\n * snapshot for use in the builder, not the lives pages.\n */\nexport class HostApiResourcesClient extends ApiResourcesClient {\n readonly fetch: HttpFetch\n\n constructor({\n fetch,\n preloadedState,\n }: {\n fetch: HttpFetch\n preloadedState: Partial<ApiClientState>\n }) {\n super({\n store: configureClientStore({ preloadedState }),\n })\n\n this.fetch = fetch\n }\n\n async fetchSwatch(swatchId: string): Promise<Swatch | null> {\n return await this.store.dispatch(fetchAPIResource(APIResourceType.Swatch, swatchId, this.fetch))\n }\n\n async fetchFile(fileId: string): Promise<File | null> {\n return await this.store.dispatch(fetchAPIResource(APIResourceType.File, fileId, this.fetch))\n }\n\n async fetchTypography(typographyId: string): Promise<Typography | null> {\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.Typography, typographyId, this.fetch),\n )\n }\n\n async fetchGlobalElement(globalElementId: string): Promise<GlobalElement | null> {\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.GlobalElement, globalElementId, this.fetch),\n )\n }\n\n async fetchLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): Promise<LocalizedGlobalElement | null> {\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.LocalizedGlobalElement, globalElementId, this.fetch, locale),\n )\n }\n\n async fetchPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): Promise<PagePathnameSlice | null> {\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.PagePathnameSlice, pageId, this.fetch, locale),\n )\n }\n\n async fetchTable(tableId: string): Promise<Table | null> {\n return await this.store.dispatch(fetchAPIResource(APIResourceType.Table, tableId, this.fetch))\n }\n}\n"],"mappings":"AACA,SAAyB,wBAAwB;AACjD,SAAS,4BAA4B;AAErC;AAAA,EAQE;AAAA,OACK;AAEP,SAAS,0BAA0B;AAEnC,SAAS,iBAAiB;AAqBnB,MAAM,+BAA+B,mBAAmB;AAAA,EACpD;AAAA,EAET,YAAY;AAAA,IACV;AAAA,IACA;AAAA,EACF,GAGG;AACD,UAAM;AAAA,MACJ,OAAO,qBAAqB,EAAE,eAAe,CAAC;AAAA,IAChD,CAAC;AAED,SAAK,QAAQ;AAAA,EACf;AAAA,EAEA,MAAM,YAAY,UAA0C;AAC1D,WAAO,MAAM,KAAK,MAAM,SAAS,iBAAiB,gBAAgB,QAAQ,UAAU,KAAK,KAAK,CAAC;AAAA,EACjG;AAAA,EAEA,MAAM,UAAU,QAAsC;AACpD,WAAO,MAAM,KAAK,MAAM,SAAS,iBAAiB,gBAAgB,MAAM,QAAQ,KAAK,KAAK,CAAC;AAAA,EAC7F;AAAA,EAEA,MAAM,gBAAgB,cAAkD;AACtE,WAAO,MAAM,KAAK,MAAM;AAAA,MACtB,iBAAiB,gBAAgB,YAAY,cAAc,KAAK,KAAK;AAAA,IACvE;AAAA,EACF;AAAA,EAEA,MAAM,mBAAmB,iBAAwD;AAC/E,WAAO,MAAM,KAAK,MAAM;AAAA,MACtB,iBAAiB,gBAAgB,eAAe,iBAAiB,KAAK,KAAK;AAAA,IAC7E;AAAA,EACF;AAAA,EAEA,MAAM,4BAA4B;AAAA,IAChC;AAAA,IACA;AAAA,EACF,GAG2C;AACzC,WAAO,MAAM,KAAK,MAAM;AAAA,MACtB,iBAAiB,gBAAgB,wBAAwB,iBAAiB,KAAK,OAAO,MAAM;AAAA,IAC9F;AAAA,EACF;AAAA,EAEA,MAAM,uBAAuB;AAAA,IAC3B;AAAA,IACA;AAAA,EACF,GAGsC;AACpC,WAAO,MAAM,KAAK,MAAM;AAAA,MACtB,iBAAiB,gBAAgB,mBAAmB,QAAQ,KAAK,OAAO,MAAM;AAAA,IAChF;AAAA,EACF;AAAA,EAEA,MAAM,WAAW,SAAwC;AACvD,WAAO,MAAM,KAAK,MAAM,SAAS,iBAAiB,gBAAgB,OAAO,SAAS,KAAK,KAAK,CAAC;AAAA,EAC/F;AACF;","names":[]}
@@ -0,0 +1,152 @@
1
+ import * as Schema from "./schema";
2
+ class MakeswiftRestAPIClient {
3
+ apiKey;
4
+ apiOrigin;
5
+ constructor({ apiKey, apiOrigin }) {
6
+ this.apiKey = apiKey;
7
+ this.apiOrigin = apiOrigin;
8
+ }
9
+ async getSwatch(swatchId, siteVersion) {
10
+ const response = await this.fetch(`v3/swatches/${swatchId}`, siteVersion);
11
+ if (!response.ok) {
12
+ const failedBody = await failedResponseBody(response);
13
+ if (response.status !== 404) {
14
+ console.error(`Failed to get swatch '${swatchId}'`, {
15
+ response: failedBody,
16
+ siteVersion
17
+ });
18
+ }
19
+ return null;
20
+ }
21
+ const swatch = await response.json();
22
+ return swatch;
23
+ }
24
+ async getTypography(typographyId, siteVersion) {
25
+ const response = await this.fetch(`v3/typographies/${typographyId}`, siteVersion);
26
+ if (!response.ok) {
27
+ const failedBody = await failedResponseBody(response);
28
+ if (response.status !== 404) {
29
+ console.error(`Failed to get typography '${typographyId}'`, {
30
+ response: failedBody,
31
+ siteVersion
32
+ });
33
+ }
34
+ return null;
35
+ }
36
+ const typography = await response.json();
37
+ return typography;
38
+ }
39
+ async getGlobalElement(globalElementId, siteVersion) {
40
+ const response = await this.fetch(`v3/global-elements/${globalElementId}`, siteVersion);
41
+ if (!response.ok) {
42
+ const failedBody = await failedResponseBody(response);
43
+ if (response.status !== 404) {
44
+ console.error(`Failed to get global element '${globalElementId}'`, {
45
+ response: failedBody,
46
+ siteVersion
47
+ });
48
+ }
49
+ return null;
50
+ }
51
+ const globalElement = await response.json();
52
+ return globalElement;
53
+ }
54
+ async getLocalizedGlobalElement(globalElementId, locale, siteVersion) {
55
+ const response = await this.fetch(
56
+ `v3/localized-global-elements/${globalElementId}?locale=${locale}`,
57
+ siteVersion
58
+ );
59
+ if (!response.ok) {
60
+ const failedBody = await failedResponseBody(response);
61
+ if (response.status !== 404) {
62
+ console.error(`Failed to get localized global element '${globalElementId}'`, {
63
+ response: failedBody,
64
+ siteVersion,
65
+ locale
66
+ });
67
+ }
68
+ return null;
69
+ }
70
+ const localizedGlobalElement = await response.json();
71
+ return localizedGlobalElement;
72
+ }
73
+ async getPagePathnameSlices(pageIds, siteVersion, { locale }) {
74
+ if (pageIds.length === 0)
75
+ return [];
76
+ const url = new URL(`v3/page-pathname-slices/bulk`, this.apiOrigin);
77
+ pageIds.forEach((id) => url.searchParams.append("ids", id));
78
+ if (locale != null)
79
+ url.searchParams.set("locale", locale);
80
+ const response = await this.fetch(url.pathname + url.search, siteVersion);
81
+ if (!response.ok) {
82
+ console.error(`Failed to get page pathname slice(s) for ${pageIds.join(", ")}`, {
83
+ response: await failedResponseBody(response),
84
+ siteVersion,
85
+ locale
86
+ });
87
+ return [];
88
+ }
89
+ const json = await response.json();
90
+ const pagePathnameSlices = Schema.pagePathnameSlices.parse(json);
91
+ return pagePathnameSlices.map((pagePathnameSlice) => {
92
+ if (pagePathnameSlice == null)
93
+ return null;
94
+ return {
95
+ ...pagePathnameSlice,
96
+ id: pagePathnameSlice.basePageId,
97
+ localizedPathname: pagePathnameSlice.localizedPathname ?? null
98
+ };
99
+ });
100
+ }
101
+ async getPagePathnameSlice(pageId, siteVersion, { locale } = {}) {
102
+ const pagePathnameSlices = await this.getPagePathnameSlices([pageId], siteVersion, { locale });
103
+ return pagePathnameSlices.at(0) ?? null;
104
+ }
105
+ async fetch(path, siteVersion, init) {
106
+ const requestUrl = new URL(path, this.apiOrigin);
107
+ const requestHeaders = new Headers({
108
+ "x-api-key": this.apiKey,
109
+ "makeswift-site-api-key": this.apiKey,
110
+ "makeswift-runtime-version": "0.28.7-canary.5"
111
+ });
112
+ if (siteVersion?.token) {
113
+ requestUrl.searchParams.set("version", siteVersion.version);
114
+ requestHeaders.set("makeswift-preview-token", siteVersion.token);
115
+ }
116
+ if (init?.headers) {
117
+ new Headers(init.headers).forEach((value, key) => {
118
+ requestHeaders.set(key, value);
119
+ });
120
+ }
121
+ const response = await fetch(requestUrl.toString(), {
122
+ ...init,
123
+ headers: requestHeaders,
124
+ ...siteVersion != null ? { cache: "no-store" } : {},
125
+ ...this.fetchOptions(siteVersion)
126
+ });
127
+ return response;
128
+ }
129
+ /**
130
+ * Override this method to provide additional fetch options, e.g. revalidation, cache tags, etc.
131
+ */
132
+ fetchOptions(_siteVersion) {
133
+ return {};
134
+ }
135
+ }
136
+ async function failedResponseBody(response) {
137
+ try {
138
+ const text = await response.text();
139
+ try {
140
+ return JSON.parse(text);
141
+ } catch {
142
+ return text;
143
+ }
144
+ } catch (e) {
145
+ return `Failed to extract response body: ${e}`;
146
+ }
147
+ }
148
+ export {
149
+ MakeswiftRestAPIClient,
150
+ failedResponseBody
151
+ };
152
+ //# sourceMappingURL=rest-api-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/api/rest-api-client.ts"],"sourcesContent":["import {\n type GlobalElement,\n type LocalizedGlobalElement,\n type PagePathnameSlice,\n type Swatch,\n type Typography,\n} from './types'\n\nimport { type SiteVersion } from './site-version'\nimport * as Schema from './schema'\n\nexport class MakeswiftRestAPIClient {\n readonly apiKey: string\n readonly apiOrigin: string\n\n constructor({ apiKey, apiOrigin }: { apiKey: string; apiOrigin: string }) {\n this.apiKey = apiKey\n this.apiOrigin = apiOrigin\n }\n\n async getSwatch(swatchId: string, siteVersion: SiteVersion | null): Promise<Swatch | null> {\n const response = await this.fetch(`v3/swatches/${swatchId}`, siteVersion)\n\n if (!response.ok) {\n const failedBody = await failedResponseBody(response)\n if (response.status !== 404) {\n console.error(`Failed to get swatch '${swatchId}'`, {\n response: failedBody,\n siteVersion,\n })\n }\n\n return null\n }\n\n const swatch = await response.json()\n\n return swatch\n }\n\n async getTypography(\n typographyId: string,\n siteVersion: SiteVersion | null,\n ): Promise<Typography | null> {\n const response = await this.fetch(`v3/typographies/${typographyId}`, siteVersion)\n\n if (!response.ok) {\n const failedBody = await failedResponseBody(response)\n if (response.status !== 404) {\n console.error(`Failed to get typography '${typographyId}'`, {\n response: failedBody,\n siteVersion,\n })\n }\n\n return null\n }\n\n const typography = await response.json()\n\n return typography\n }\n\n async getGlobalElement(\n globalElementId: string,\n siteVersion: SiteVersion | null,\n ): Promise<GlobalElement | null> {\n const response = await this.fetch(`v3/global-elements/${globalElementId}`, siteVersion)\n\n if (!response.ok) {\n const failedBody = await failedResponseBody(response)\n if (response.status !== 404) {\n console.error(`Failed to get global element '${globalElementId}'`, {\n response: failedBody,\n siteVersion,\n })\n }\n\n return null\n }\n\n const globalElement = await response.json()\n\n return globalElement\n }\n\n async getLocalizedGlobalElement(\n globalElementId: string,\n locale: string,\n siteVersion: SiteVersion | null,\n ): Promise<LocalizedGlobalElement | null> {\n const response = await this.fetch(\n `v3/localized-global-elements/${globalElementId}?locale=${locale}`,\n siteVersion,\n )\n\n if (!response.ok) {\n const failedBody = await failedResponseBody(response)\n if (response.status !== 404) {\n console.error(`Failed to get localized global element '${globalElementId}'`, {\n response: failedBody,\n siteVersion,\n locale,\n })\n }\n\n return null\n }\n\n const localizedGlobalElement = await response.json()\n\n return localizedGlobalElement\n }\n\n async getPagePathnameSlices(\n pageIds: string[],\n siteVersion: SiteVersion | null,\n { locale }: { locale?: string | null },\n ): Promise<(PagePathnameSlice | null)[]> {\n if (pageIds.length === 0) return []\n\n const url = new URL(`v3/page-pathname-slices/bulk`, this.apiOrigin)\n\n pageIds.forEach(id => url.searchParams.append('ids', id))\n if (locale != null) url.searchParams.set('locale', locale)\n\n const response = await this.fetch(url.pathname + url.search, siteVersion)\n\n if (!response.ok) {\n console.error(`Failed to get page pathname slice(s) for ${pageIds.join(', ')}`, {\n response: await failedResponseBody(response),\n siteVersion,\n locale,\n })\n\n return []\n }\n\n const json = await response.json()\n\n const pagePathnameSlices = Schema.pagePathnameSlices.parse(json)\n\n // We're mapping the basePageId to be the id, because we're still using the GraphQL\n // fragment as our APIResource. The id on the APIResource needs to match the pageId\n // so that we can find the corresponding page pathname slice when we call getPagePathnameSlice(pageId).\n // TODO: Update this once we move away from the GraphQL fragments.\n return pagePathnameSlices.map(pagePathnameSlice => {\n if (pagePathnameSlice == null) return null\n\n return {\n ...pagePathnameSlice,\n id: pagePathnameSlice.basePageId,\n localizedPathname: pagePathnameSlice.localizedPathname ?? null,\n }\n })\n }\n\n async getPagePathnameSlice(\n pageId: string,\n siteVersion: SiteVersion | null,\n { locale }: { locale?: string } = {},\n ): Promise<PagePathnameSlice | null> {\n const pagePathnameSlices = await this.getPagePathnameSlices([pageId], siteVersion, { locale })\n\n return pagePathnameSlices.at(0) ?? null\n }\n\n protected async fetch(\n path: string,\n siteVersion: SiteVersion | null,\n init?: RequestInit,\n ): Promise<Response> {\n const requestUrl = new URL(path, this.apiOrigin)\n\n const requestHeaders = new Headers({\n 'x-api-key': this.apiKey,\n 'makeswift-site-api-key': this.apiKey,\n 'makeswift-runtime-version': PACKAGE_VERSION,\n })\n\n if (siteVersion?.token) {\n requestUrl.searchParams.set('version', siteVersion.version)\n requestHeaders.set('makeswift-preview-token', siteVersion.token)\n }\n\n if (init?.headers) {\n new Headers(init.headers).forEach((value, key) => {\n requestHeaders.set(key, value)\n })\n }\n\n const response = await fetch(requestUrl.toString(), {\n ...init,\n headers: requestHeaders,\n ...(siteVersion != null ? { cache: 'no-store' } : {}),\n ...this.fetchOptions(siteVersion),\n })\n\n return response\n }\n\n /**\n * Override this method to provide additional fetch options, e.g. revalidation, cache tags, etc.\n */\n protected fetchOptions(_siteVersion: SiteVersion | null): Record<string, unknown> {\n return {}\n }\n}\n\n// This function attempts to consume the response body of a failed response, and\n// returns either the parsed JSON or raw text. This is useful for logging more\n// detailed error information when an API request fails.\n//\n// Cloudflare Worker Note: The Cloudflare Worker runtime has automatic deadlock\n// prevention (in the form of auto-cancelling responses) that triggers when too\n// many response bodies are unconsumed. This applies for error responses as\n// well. As such, in this client we use this function to consume the response\n// body whenever the request fails, even if we don't end up logging the body\n// itself, to avoid hitting the deadlock prevention.\nexport async function failedResponseBody(response: Response): Promise<unknown> {\n try {\n const text = await response.text()\n try {\n return JSON.parse(text)\n } catch {\n return text\n }\n } catch (e) {\n return `Failed to extract response body: ${e}`\n }\n}\n"],"mappings":"AASA,YAAY,YAAY;AAEjB,MAAM,uBAAuB;AAAA,EACzB;AAAA,EACA;AAAA,EAET,YAAY,EAAE,QAAQ,UAAU,GAA0C;AACxE,SAAK,SAAS;AACd,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,MAAM,UAAU,UAAkB,aAAyD;AACzF,UAAM,WAAW,MAAM,KAAK,MA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