prismic-ts-codegen 0.1.21-alpha.0 → 0.1.22

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 (48) hide show
  1. package/README.md +2 -2
  2. package/dist/_node_modules/@prismicio/client/dist/BaseClient.cjs +97 -0
  3. package/dist/_node_modules/@prismicio/client/dist/BaseClient.cjs.map +1 -0
  4. package/dist/_node_modules/@prismicio/client/dist/BaseClient.js +97 -0
  5. package/dist/_node_modules/@prismicio/client/dist/BaseClient.js.map +1 -0
  6. package/dist/_node_modules/@prismicio/client/dist/Client.cjs +1179 -0
  7. package/dist/_node_modules/@prismicio/client/dist/Client.cjs.map +1 -0
  8. package/dist/_node_modules/@prismicio/client/dist/Client.js +1179 -0
  9. package/dist/_node_modules/@prismicio/client/dist/Client.js.map +1 -0
  10. package/dist/_node_modules/@prismicio/client/dist/buildQueryURL.cjs +7 -0
  11. package/dist/_node_modules/@prismicio/client/dist/buildQueryURL.cjs.map +1 -1
  12. package/dist/_node_modules/@prismicio/client/dist/buildQueryURL.js +7 -0
  13. package/dist/_node_modules/@prismicio/client/dist/buildQueryURL.js.map +1 -1
  14. package/dist/_node_modules/@prismicio/client/dist/createClient.cjs +2 -1172
  15. package/dist/_node_modules/@prismicio/client/dist/createClient.cjs.map +1 -1
  16. package/dist/_node_modules/@prismicio/client/dist/createClient.js +1 -1171
  17. package/dist/_node_modules/@prismicio/client/dist/createClient.js.map +1 -1
  18. package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs +1 -4
  19. package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs.map +1 -1
  20. package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js +1 -4
  21. package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js.map +1 -1
  22. package/dist/_node_modules/@prismicio/client/dist/getRepositoryName.cjs +7 -2
  23. package/dist/_node_modules/@prismicio/client/dist/getRepositoryName.cjs.map +1 -1
  24. package/dist/_node_modules/@prismicio/client/dist/getRepositoryName.js +7 -2
  25. package/dist/_node_modules/@prismicio/client/dist/getRepositoryName.js.map +1 -1
  26. package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs +1 -0
  27. package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs.map +1 -1
  28. package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js +1 -0
  29. package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js.map +1 -1
  30. package/dist/_node_modules/@prismicio/client/dist/lib/pLimit.cjs +49 -0
  31. package/dist/_node_modules/@prismicio/client/dist/lib/pLimit.cjs.map +1 -0
  32. package/dist/_node_modules/@prismicio/client/dist/lib/pLimit.js +49 -0
  33. package/dist/_node_modules/@prismicio/client/dist/lib/pLimit.js.map +1 -0
  34. package/dist/_node_modules/@prismicio/client/dist/package.json.cjs +1 -1
  35. package/dist/_node_modules/@prismicio/client/dist/package.json.cjs.map +1 -1
  36. package/dist/_node_modules/@prismicio/client/dist/package.json.js +1 -1
  37. package/dist/_node_modules/@prismicio/client/dist/package.json.js.map +1 -1
  38. package/dist/generateTypes.cjs +12 -0
  39. package/dist/generateTypes.cjs.map +1 -1
  40. package/dist/generateTypes.js +12 -0
  41. package/dist/generateTypes.js.map +1 -1
  42. package/dist/lib/buildFieldProperties.cjs +4 -4
  43. package/dist/lib/buildFieldProperties.cjs.map +1 -1
  44. package/dist/lib/buildFieldProperties.js +4 -4
  45. package/dist/lib/buildFieldProperties.js.map +1 -1
  46. package/package.json +3 -6
  47. package/src/generateTypes.ts +24 -0
  48. package/src/lib/buildFieldProperties.ts +10 -8
package/README.md CHANGED
@@ -127,12 +127,12 @@ Whether you're helping us fix bugs, improve the docs, or spread the word, we'd l
127
127
 
128
128
  **Submitting code changes**: For small fixes, feel free to [open a pull request][repo-pull-requests] with a description of your changes. For large changes, please first [open an issue][repo-feature-request] so we can discuss if and how the changes should be implemented.
129
129
 
130
- For more clarity on this project and its structure you can also check out the detailed [CONTRIBUTING.md][contributing] document.
130
+ For more clarity on this project, check out the detailed [CONTRIBUTING.md][contributing] document.
131
131
 
132
132
  ## License
133
133
 
134
134
  ```
135
- Copyright 2013-2022 Prismic <contact@prismic.io> (https://prismic.io)
135
+ Copyright 2013-2024 Prismic <contact@prismic.io> (https://prismic.io)
136
136
 
137
137
  Licensed under the Apache License, Version 2.0 (the "License");
138
138
  you may not use this file except in compliance with the License.
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const pLimit = require("./lib/pLimit.cjs");
4
+ const PrismicError = require("./errors/PrismicError.cjs");
5
+ var __defProp = Object.defineProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
+ const UNKNOWN_RATE_LIMIT_DELAY = 1500;
9
+ class BaseClient {
10
+ constructor(options) {
11
+ __publicField(this, "fetchFn");
12
+ __publicField(this, "fetchOptions");
13
+ __publicField(this, "queuedFetchJobs", {});
14
+ __publicField(this, "dedupedFetchJobs", {});
15
+ this.fetchOptions = options.fetchOptions;
16
+ if (typeof options.fetch === "function") {
17
+ this.fetchFn = options.fetch;
18
+ } else if (typeof globalThis.fetch === "function") {
19
+ this.fetchFn = globalThis.fetch;
20
+ } else {
21
+ throw new PrismicError.PrismicError("A valid fetch implementation was not provided. In environments where fetch is not available (including Node.js), a fetch implementation must be provided via a polyfill or the `fetch` option.", void 0, void 0);
22
+ }
23
+ if (this.fetchFn === globalThis.fetch) {
24
+ this.fetchFn = this.fetchFn.bind(globalThis);
25
+ }
26
+ }
27
+ async fetch(url, params = {}) {
28
+ var _a, _b, _c, _d, _e;
29
+ const requestInit = {
30
+ ...this.fetchOptions,
31
+ ...params.fetchOptions,
32
+ headers: {
33
+ ...(_a = this.fetchOptions) == null ? void 0 : _a.headers,
34
+ ...(_b = params.fetchOptions) == null ? void 0 : _b.headers
35
+ },
36
+ signal: ((_c = params.fetchOptions) == null ? void 0 : _c.signal) || params.signal || ((_d = this.fetchOptions) == null ? void 0 : _d.signal)
37
+ };
38
+ if ((_e = params.fetchOptions) == null ? void 0 : _e.body) {
39
+ return this.queueFetch(url, requestInit);
40
+ } else {
41
+ return this.dedupeFetch(url, requestInit);
42
+ }
43
+ }
44
+ queueFetch(url, requestInit = {}) {
45
+ const hostname = new URL(url).hostname;
46
+ if (!this.queuedFetchJobs[hostname]) {
47
+ this.queuedFetchJobs[hostname] = pLimit.pLimit({
48
+ interval: UNKNOWN_RATE_LIMIT_DELAY
49
+ });
50
+ }
51
+ return this.queuedFetchJobs[hostname](() => this.createFetchJob(url, requestInit));
52
+ }
53
+ dedupeFetch(url, requestInit = {}) {
54
+ let job;
55
+ if (this.dedupedFetchJobs[url] && this.dedupedFetchJobs[url].has(requestInit.signal)) {
56
+ job = this.dedupedFetchJobs[url].get(requestInit.signal);
57
+ } else {
58
+ this.dedupedFetchJobs[url] = this.dedupedFetchJobs[url] || /* @__PURE__ */ new Map();
59
+ job = this.createFetchJob(url, requestInit).finally(() => {
60
+ var _a, _b;
61
+ (_a = this.dedupedFetchJobs[url]) == null ? void 0 : _a.delete(requestInit.signal);
62
+ if (((_b = this.dedupedFetchJobs[url]) == null ? void 0 : _b.size) === 0) {
63
+ delete this.dedupedFetchJobs[url];
64
+ }
65
+ });
66
+ this.dedupedFetchJobs[url].set(requestInit.signal, job);
67
+ }
68
+ return job;
69
+ }
70
+ createFetchJob(url, requestInit = {}) {
71
+ return this.fetchFn(url, requestInit).then(async (res) => {
72
+ let json = void 0;
73
+ let text = void 0;
74
+ if (res.ok) {
75
+ try {
76
+ json = await res.json();
77
+ } catch {
78
+ }
79
+ } else {
80
+ try {
81
+ text = await res.text();
82
+ json = JSON.parse(text);
83
+ } catch {
84
+ }
85
+ }
86
+ return {
87
+ status: res.status,
88
+ headers: res.headers,
89
+ json,
90
+ text
91
+ };
92
+ });
93
+ }
94
+ }
95
+ exports.BaseClient = BaseClient;
96
+ exports.UNKNOWN_RATE_LIMIT_DELAY = UNKNOWN_RATE_LIMIT_DELAY;
97
+ //# sourceMappingURL=BaseClient.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseClient.cjs","sources":["../../../../../node_modules/@prismicio/client/dist/BaseClient.js"],"sourcesContent":["var __defProp = Object.defineProperty;\nvar __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;\nvar __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== \"symbol\" ? key + \"\" : key, value);\nimport { pLimit } from \"./lib/pLimit.js\";\nimport { PrismicError } from \"./errors/PrismicError.js\";\nconst UNKNOWN_RATE_LIMIT_DELAY = 1500;\nclass BaseClient {\n constructor(options) {\n /**\n * The function used to make network requests to the Prismic REST API. In\n * environments where a global `fetch` function does not exist, such as\n * Node.js, this function must be provided.\n */\n __publicField(this, \"fetchFn\");\n __publicField(this, \"fetchOptions\");\n /**\n * Active queued `fetch()` jobs keyed by URL and AbortSignal (if it exists).\n */\n __publicField(this, \"queuedFetchJobs\", {});\n /**\n * Active deduped `fetch()` jobs keyed by URL and AbortSignal (if it exists).\n */\n __publicField(this, \"dedupedFetchJobs\", {});\n this.fetchOptions = options.fetchOptions;\n if (typeof options.fetch === \"function\") {\n this.fetchFn = options.fetch;\n } else if (typeof globalThis.fetch === \"function\") {\n this.fetchFn = globalThis.fetch;\n } else {\n throw new PrismicError(\"A valid fetch implementation was not provided. In environments where fetch is not available (including Node.js), a fetch implementation must be provided via a polyfill or the `fetch` option.\", void 0, void 0);\n }\n if (this.fetchFn === globalThis.fetch) {\n this.fetchFn = this.fetchFn.bind(globalThis);\n }\n }\n async fetch(url, params = {}) {\n var _a, _b, _c, _d, _e;\n const requestInit = {\n ...this.fetchOptions,\n ...params.fetchOptions,\n headers: {\n ...(_a = this.fetchOptions) == null ? void 0 : _a.headers,\n ...(_b = params.fetchOptions) == null ? void 0 : _b.headers\n },\n signal: ((_c = params.fetchOptions) == null ? void 0 : _c.signal) || params.signal || ((_d = this.fetchOptions) == null ? void 0 : _d.signal)\n };\n if ((_e = params.fetchOptions) == null ? void 0 : _e.body) {\n return this.queueFetch(url, requestInit);\n } else {\n return this.dedupeFetch(url, requestInit);\n }\n }\n queueFetch(url, requestInit = {}) {\n const hostname = new URL(url).hostname;\n if (!this.queuedFetchJobs[hostname]) {\n this.queuedFetchJobs[hostname] = pLimit({\n interval: UNKNOWN_RATE_LIMIT_DELAY\n });\n }\n return this.queuedFetchJobs[hostname](() => this.createFetchJob(url, requestInit));\n }\n dedupeFetch(url, requestInit = {}) {\n let job;\n if (this.dedupedFetchJobs[url] && this.dedupedFetchJobs[url].has(requestInit.signal)) {\n job = this.dedupedFetchJobs[url].get(requestInit.signal);\n } else {\n this.dedupedFetchJobs[url] = this.dedupedFetchJobs[url] || /* @__PURE__ */ new Map();\n job = this.createFetchJob(url, requestInit).finally(() => {\n var _a, _b;\n (_a = this.dedupedFetchJobs[url]) == null ? void 0 : _a.delete(requestInit.signal);\n if (((_b = this.dedupedFetchJobs[url]) == null ? void 0 : _b.size) === 0) {\n delete this.dedupedFetchJobs[url];\n }\n });\n this.dedupedFetchJobs[url].set(requestInit.signal, job);\n }\n return job;\n }\n createFetchJob(url, requestInit = {}) {\n return this.fetchFn(url, requestInit).then(async (res) => {\n let json = void 0;\n let text = void 0;\n if (res.ok) {\n try {\n json = await res.json();\n } catch {\n }\n } else {\n try {\n text = await res.text();\n json = JSON.parse(text);\n } catch {\n }\n }\n return {\n status: res.status,\n headers: res.headers,\n json,\n text\n };\n });\n }\n}\nexport {\n BaseClient,\n UNKNOWN_RATE_LIMIT_DELAY\n};\n//# sourceMappingURL=BaseClient.js.map\n"],"names":["PrismicError","pLimit"],"mappings":";;;;AAAA,IAAI,YAAY,OAAO;AACvB,IAAI,kBAAkB,CAAC,KA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I;AACF,iBAAO,MAAM,IAAI;QAC3B,QAAU;AAAA,QACD;AAAA,MACT,OAAa;AACL,YAAI;AACF,iBAAO,MAAM,IAAI;AACjB,iBAAO,KAAK,MAAM,IAAI;AAAA,QAChC,QAAU;AAAA,QACD;AAAA,MACF;AACD,aAAO;AAAA,QACL,QAAQ,IAAI;AAAA,QACZ,SAAS,IAAI;AAAA,QACb;AAAA,QACA;AAAA,MACR;AAAA,IACA,CAAK;AAAA,EACF;AACH;;;","x_google_ignoreList":[0]}
@@ -0,0 +1,97 @@
1
+ import { pLimit } from "./lib/pLimit.js";
2
+ import { PrismicError } from "./errors/PrismicError.js";
3
+ var __defProp = Object.defineProperty;
4
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
+ const UNKNOWN_RATE_LIMIT_DELAY = 1500;
7
+ class BaseClient {
8
+ constructor(options) {
9
+ __publicField(this, "fetchFn");
10
+ __publicField(this, "fetchOptions");
11
+ __publicField(this, "queuedFetchJobs", {});
12
+ __publicField(this, "dedupedFetchJobs", {});
13
+ this.fetchOptions = options.fetchOptions;
14
+ if (typeof options.fetch === "function") {
15
+ this.fetchFn = options.fetch;
16
+ } else if (typeof globalThis.fetch === "function") {
17
+ this.fetchFn = globalThis.fetch;
18
+ } else {
19
+ throw new PrismicError("A valid fetch implementation was not provided. In environments where fetch is not available (including Node.js), a fetch implementation must be provided via a polyfill or the `fetch` option.", void 0, void 0);
20
+ }
21
+ if (this.fetchFn === globalThis.fetch) {
22
+ this.fetchFn = this.fetchFn.bind(globalThis);
23
+ }
24
+ }
25
+ async fetch(url, params = {}) {
26
+ var _a, _b, _c, _d, _e;
27
+ const requestInit = {
28
+ ...this.fetchOptions,
29
+ ...params.fetchOptions,
30
+ headers: {
31
+ ...(_a = this.fetchOptions) == null ? void 0 : _a.headers,
32
+ ...(_b = params.fetchOptions) == null ? void 0 : _b.headers
33
+ },
34
+ signal: ((_c = params.fetchOptions) == null ? void 0 : _c.signal) || params.signal || ((_d = this.fetchOptions) == null ? void 0 : _d.signal)
35
+ };
36
+ if ((_e = params.fetchOptions) == null ? void 0 : _e.body) {
37
+ return this.queueFetch(url, requestInit);
38
+ } else {
39
+ return this.dedupeFetch(url, requestInit);
40
+ }
41
+ }
42
+ queueFetch(url, requestInit = {}) {
43
+ const hostname = new URL(url).hostname;
44
+ if (!this.queuedFetchJobs[hostname]) {
45
+ this.queuedFetchJobs[hostname] = pLimit({
46
+ interval: UNKNOWN_RATE_LIMIT_DELAY
47
+ });
48
+ }
49
+ return this.queuedFetchJobs[hostname](() => this.createFetchJob(url, requestInit));
50
+ }
51
+ dedupeFetch(url, requestInit = {}) {
52
+ let job;
53
+ if (this.dedupedFetchJobs[url] && this.dedupedFetchJobs[url].has(requestInit.signal)) {
54
+ job = this.dedupedFetchJobs[url].get(requestInit.signal);
55
+ } else {
56
+ this.dedupedFetchJobs[url] = this.dedupedFetchJobs[url] || /* @__PURE__ */ new Map();
57
+ job = this.createFetchJob(url, requestInit).finally(() => {
58
+ var _a, _b;
59
+ (_a = this.dedupedFetchJobs[url]) == null ? void 0 : _a.delete(requestInit.signal);
60
+ if (((_b = this.dedupedFetchJobs[url]) == null ? void 0 : _b.size) === 0) {
61
+ delete this.dedupedFetchJobs[url];
62
+ }
63
+ });
64
+ this.dedupedFetchJobs[url].set(requestInit.signal, job);
65
+ }
66
+ return job;
67
+ }
68
+ createFetchJob(url, requestInit = {}) {
69
+ return this.fetchFn(url, requestInit).then(async (res) => {
70
+ let json = void 0;
71
+ let text = void 0;
72
+ if (res.ok) {
73
+ try {
74
+ json = await res.json();
75
+ } catch {
76
+ }
77
+ } else {
78
+ try {
79
+ text = await res.text();
80
+ json = JSON.parse(text);
81
+ } catch {
82
+ }
83
+ }
84
+ return {
85
+ status: res.status,
86
+ headers: res.headers,
87
+ json,
88
+ text
89
+ };
90
+ });
91
+ }
92
+ }
93
+ export {
94
+ BaseClient,
95
+ UNKNOWN_RATE_LIMIT_DELAY
96
+ };
97
+ //# sourceMappingURL=BaseClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseClient.js","sources":["../../../../../node_modules/@prismicio/client/dist/BaseClient.js"],"sourcesContent":["var __defProp = Object.defineProperty;\nvar __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;\nvar __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== \"symbol\" ? key + \"\" : key, value);\nimport { pLimit } from \"./lib/pLimit.js\";\nimport { PrismicError } from \"./errors/PrismicError.js\";\nconst UNKNOWN_RATE_LIMIT_DELAY = 1500;\nclass BaseClient {\n constructor(options) {\n /**\n * The function used to make network requests to the Prismic REST API. In\n * environments where a global `fetch` function does not exist, such as\n * Node.js, this function must be provided.\n */\n __publicField(this, \"fetchFn\");\n __publicField(this, \"fetchOptions\");\n /**\n * Active queued `fetch()` jobs keyed by URL and AbortSignal (if it exists).\n */\n __publicField(this, \"queuedFetchJobs\", {});\n /**\n * Active deduped `fetch()` jobs keyed by URL and AbortSignal (if it exists).\n */\n __publicField(this, \"dedupedFetchJobs\", {});\n this.fetchOptions = options.fetchOptions;\n if (typeof options.fetch === \"function\") {\n this.fetchFn = options.fetch;\n } else if (typeof globalThis.fetch === \"function\") {\n this.fetchFn = globalThis.fetch;\n } else {\n throw new PrismicError(\"A valid fetch implementation was not provided. In environments where fetch is not available (including Node.js), a fetch implementation must be provided via a polyfill or the `fetch` option.\", void 0, void 0);\n }\n if (this.fetchFn === globalThis.fetch) {\n this.fetchFn = this.fetchFn.bind(globalThis);\n }\n }\n async fetch(url, params = {}) {\n var _a, _b, _c, _d, _e;\n const requestInit = {\n ...this.fetchOptions,\n ...params.fetchOptions,\n headers: {\n ...(_a = this.fetchOptions) == null ? void 0 : _a.headers,\n ...(_b = params.fetchOptions) == null ? void 0 : _b.headers\n },\n signal: ((_c = params.fetchOptions) == null ? void 0 : _c.signal) || params.signal || ((_d = this.fetchOptions) == null ? void 0 : _d.signal)\n };\n if ((_e = params.fetchOptions) == null ? void 0 : _e.body) {\n return this.queueFetch(url, requestInit);\n } else {\n return this.dedupeFetch(url, requestInit);\n }\n }\n queueFetch(url, requestInit = {}) {\n const hostname = new URL(url).hostname;\n if (!this.queuedFetchJobs[hostname]) {\n this.queuedFetchJobs[hostname] = pLimit({\n interval: UNKNOWN_RATE_LIMIT_DELAY\n });\n }\n return this.queuedFetchJobs[hostname](() => this.createFetchJob(url, requestInit));\n }\n dedupeFetch(url, requestInit = {}) {\n let job;\n if (this.dedupedFetchJobs[url] && this.dedupedFetchJobs[url].has(requestInit.signal)) {\n job = this.dedupedFetchJobs[url].get(requestInit.signal);\n } else {\n this.dedupedFetchJobs[url] = this.dedupedFetchJobs[url] || /* @__PURE__ */ new Map();\n job = this.createFetchJob(url, requestInit).finally(() => {\n var _a, _b;\n (_a = this.dedupedFetchJobs[url]) == null ? void 0 : _a.delete(requestInit.signal);\n if (((_b = this.dedupedFetchJobs[url]) == null ? void 0 : _b.size) === 0) {\n delete this.dedupedFetchJobs[url];\n }\n });\n this.dedupedFetchJobs[url].set(requestInit.signal, job);\n }\n return job;\n }\n createFetchJob(url, requestInit = {}) {\n return this.fetchFn(url, requestInit).then(async (res) => {\n let json = void 0;\n let text = void 0;\n if (res.ok) {\n try {\n json = await res.json();\n } catch {\n }\n } else {\n try {\n text = await res.text();\n json = JSON.parse(text);\n } catch {\n }\n }\n return {\n status: res.status,\n headers: res.headers,\n json,\n text\n };\n });\n }\n}\nexport {\n BaseClient,\n UNKNOWN_RATE_LIMIT_DELAY\n};\n//# sourceMappingURL=BaseClient.js.map\n"],"names":[],"mappings":";;AAAA,IAAI,YAAY,OAAO;AACvB,IAAI,kBAAkB,CAAC,KAAK,KAAK,UAAU,OAAO,MAAM,UAAU,KAAK,KAAK,EAAE,YAAY,MAAM,cAAc,MAA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