@prismicio/client 7.10.0-alpha.0 → 7.10.0

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 (121) hide show
  1. package/dist/BaseClient.cjs +108 -0
  2. package/dist/BaseClient.cjs.map +1 -0
  3. package/dist/BaseClient.d.ts +152 -0
  4. package/dist/BaseClient.js +108 -0
  5. package/dist/BaseClient.js.map +1 -0
  6. package/dist/Client.cjs +1217 -0
  7. package/dist/Client.cjs.map +1 -0
  8. package/dist/Client.d.ts +924 -0
  9. package/dist/Client.js +1217 -0
  10. package/dist/Client.js.map +1 -0
  11. package/dist/Migration.cjs +318 -0
  12. package/dist/Migration.cjs.map +1 -0
  13. package/dist/Migration.d.ts +213 -0
  14. package/dist/Migration.js +318 -0
  15. package/dist/Migration.js.map +1 -0
  16. package/dist/WriteClient.cjs +512 -0
  17. package/dist/WriteClient.cjs.map +1 -0
  18. package/dist/WriteClient.d.ts +314 -0
  19. package/dist/WriteClient.js +512 -0
  20. package/dist/WriteClient.js.map +1 -0
  21. package/dist/createClient.cjs +2 -1215
  22. package/dist/createClient.cjs.map +1 -1
  23. package/dist/createClient.d.ts +2 -1003
  24. package/dist/createClient.js +1 -1214
  25. package/dist/createClient.js.map +1 -1
  26. package/dist/createMigration.cjs +6 -0
  27. package/dist/createMigration.cjs.map +1 -0
  28. package/dist/createMigration.d.ts +24 -0
  29. package/dist/createMigration.js +6 -0
  30. package/dist/createMigration.js.map +1 -0
  31. package/dist/createWriteClient.cjs +6 -0
  32. package/dist/createWriteClient.cjs.map +1 -0
  33. package/dist/createWriteClient.d.ts +32 -0
  34. package/dist/createWriteClient.js +6 -0
  35. package/dist/createWriteClient.js.map +1 -0
  36. package/dist/getRepositoryName.cjs +7 -2
  37. package/dist/getRepositoryName.cjs.map +1 -1
  38. package/dist/getRepositoryName.d.ts +3 -6
  39. package/dist/getRepositoryName.js +7 -2
  40. package/dist/getRepositoryName.js.map +1 -1
  41. package/dist/index.cjs +14 -1
  42. package/dist/index.cjs.map +1 -1
  43. package/dist/index.d.ts +17 -2
  44. package/dist/index.js +14 -1
  45. package/dist/index.js.map +1 -1
  46. package/dist/lib/isMigrationValue.cjs +24 -0
  47. package/dist/lib/isMigrationValue.cjs.map +1 -0
  48. package/dist/lib/isMigrationValue.d.ts +62 -0
  49. package/dist/lib/isMigrationValue.js +24 -0
  50. package/dist/lib/isMigrationValue.js.map +1 -0
  51. package/dist/lib/isValue.cjs +53 -0
  52. package/dist/lib/isValue.cjs.map +1 -0
  53. package/dist/lib/isValue.d.ts +72 -0
  54. package/dist/lib/isValue.js +53 -0
  55. package/dist/lib/isValue.js.map +1 -0
  56. package/dist/lib/pLimit.cjs +49 -0
  57. package/dist/lib/pLimit.cjs.map +1 -0
  58. package/dist/lib/pLimit.d.ts +22 -0
  59. package/dist/lib/pLimit.js +49 -0
  60. package/dist/lib/pLimit.js.map +1 -0
  61. package/dist/lib/resolveMigrationDocumentData.cjs +123 -0
  62. package/dist/lib/resolveMigrationDocumentData.cjs.map +1 -0
  63. package/dist/lib/resolveMigrationDocumentData.d.ts +52 -0
  64. package/dist/lib/resolveMigrationDocumentData.js +123 -0
  65. package/dist/lib/resolveMigrationDocumentData.js.map +1 -0
  66. package/dist/lib/validateAssetMetadata.cjs +28 -0
  67. package/dist/lib/validateAssetMetadata.cjs.map +1 -0
  68. package/dist/lib/validateAssetMetadata.d.ts +10 -0
  69. package/dist/lib/validateAssetMetadata.js +28 -0
  70. package/dist/lib/validateAssetMetadata.js.map +1 -0
  71. package/dist/package.json.cjs +1 -1
  72. package/dist/package.json.js +1 -1
  73. package/dist/types/api/asset/asset.d.ts +177 -0
  74. package/dist/types/api/asset/tag.d.ts +53 -0
  75. package/dist/types/api/migration/document.d.ts +60 -0
  76. package/dist/types/migration/Asset.cjs +33 -0
  77. package/dist/types/migration/Asset.cjs.map +1 -0
  78. package/dist/types/migration/Asset.d.ts +109 -0
  79. package/dist/types/migration/Asset.js +33 -0
  80. package/dist/types/migration/Asset.js.map +1 -0
  81. package/dist/types/migration/ContentRelationship.d.ts +17 -0
  82. package/dist/types/migration/Document.cjs +47 -0
  83. package/dist/types/migration/Document.cjs.map +1 -0
  84. package/dist/types/migration/Document.d.ts +94 -0
  85. package/dist/types/migration/Document.js +47 -0
  86. package/dist/types/migration/Document.js.map +1 -0
  87. package/dist/types/model/link.cjs.map +1 -1
  88. package/dist/types/model/link.d.ts +0 -1
  89. package/dist/types/model/link.js.map +1 -1
  90. package/dist/types/model/linkToMedia.d.ts +0 -1
  91. package/dist/types/value/contentRelationship.d.ts +0 -1
  92. package/dist/types/value/link.cjs.map +1 -1
  93. package/dist/types/value/link.d.ts +0 -2
  94. package/dist/types/value/link.js.map +1 -1
  95. package/dist/types/value/linkToMedia.d.ts +0 -1
  96. package/package.json +2 -2
  97. package/src/BaseClient.ts +330 -0
  98. package/src/Client.ts +1787 -0
  99. package/src/Migration.ts +531 -0
  100. package/src/WriteClient.ts +911 -0
  101. package/src/createClient.ts +3 -1931
  102. package/src/createMigration.ts +31 -0
  103. package/src/createWriteClient.ts +43 -0
  104. package/src/getRepositoryName.ts +19 -14
  105. package/src/index.ts +32 -4
  106. package/src/lib/isMigrationValue.ts +126 -0
  107. package/src/lib/isValue.ts +196 -0
  108. package/src/lib/pLimit.ts +106 -0
  109. package/src/lib/resolveMigrationDocumentData.ts +233 -0
  110. package/src/lib/validateAssetMetadata.ts +82 -0
  111. package/src/types/api/asset/asset.ts +211 -0
  112. package/src/types/api/asset/tag.ts +59 -0
  113. package/src/types/api/migration/document.ts +84 -0
  114. package/src/types/migration/Asset.ts +156 -0
  115. package/src/types/migration/ContentRelationship.ts +36 -0
  116. package/src/types/migration/Document.ts +157 -0
  117. package/src/types/model/link.ts +0 -1
  118. package/src/types/model/linkToMedia.ts +0 -1
  119. package/src/types/value/contentRelationship.ts +0 -1
  120. package/src/types/value/link.ts +0 -2
  121. package/src/types/value/linkToMedia.ts +0 -1
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
6
+ const pLimit = require("./lib/pLimit.cjs");
7
+ const PrismicError = require("./errors/PrismicError.cjs");
8
+ const UNKNOWN_RATE_LIMIT_DELAY = 1500;
9
+ class BaseClient {
10
+ constructor(options) {
11
+ /**
12
+ * The function used to make network requests to the Prismic REST API. In
13
+ * environments where a global `fetch` function does not exist, such as
14
+ * Node.js, this function must be provided.
15
+ */
16
+ __publicField(this, "fetchFn");
17
+ __publicField(this, "fetchOptions");
18
+ /**
19
+ * Active queued `fetch()` jobs keyed by URL and AbortSignal (if it exists).
20
+ */
21
+ __publicField(this, "queuedFetchJobs", {});
22
+ /**
23
+ * Active deduped `fetch()` jobs keyed by URL and AbortSignal (if it exists).
24
+ */
25
+ __publicField(this, "dedupedFetchJobs", {});
26
+ this.fetchOptions = options.fetchOptions;
27
+ if (typeof options.fetch === "function") {
28
+ this.fetchFn = options.fetch;
29
+ } else if (typeof globalThis.fetch === "function") {
30
+ this.fetchFn = globalThis.fetch;
31
+ } else {
32
+ 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);
33
+ }
34
+ if (this.fetchFn === globalThis.fetch) {
35
+ this.fetchFn = this.fetchFn.bind(globalThis);
36
+ }
37
+ }
38
+ async fetch(url, params = {}) {
39
+ var _a, _b, _c, _d, _e;
40
+ const requestInit = {
41
+ ...this.fetchOptions,
42
+ ...params.fetchOptions,
43
+ headers: {
44
+ ...(_a = this.fetchOptions) == null ? void 0 : _a.headers,
45
+ ...(_b = params.fetchOptions) == null ? void 0 : _b.headers
46
+ },
47
+ signal: ((_c = params.fetchOptions) == null ? void 0 : _c.signal) || params.signal || ((_d = this.fetchOptions) == null ? void 0 : _d.signal)
48
+ };
49
+ if ((_e = params.fetchOptions) == null ? void 0 : _e.body) {
50
+ return this.queueFetch(url, requestInit);
51
+ } else {
52
+ return this.dedupeFetch(url, requestInit);
53
+ }
54
+ }
55
+ queueFetch(url, requestInit = {}) {
56
+ const hostname = new URL(url).hostname;
57
+ if (!this.queuedFetchJobs[hostname]) {
58
+ this.queuedFetchJobs[hostname] = pLimit.pLimit({
59
+ interval: UNKNOWN_RATE_LIMIT_DELAY
60
+ });
61
+ }
62
+ return this.queuedFetchJobs[hostname](() => this.createFetchJob(url, requestInit));
63
+ }
64
+ dedupeFetch(url, requestInit = {}) {
65
+ let job;
66
+ if (this.dedupedFetchJobs[url] && this.dedupedFetchJobs[url].has(requestInit.signal)) {
67
+ job = this.dedupedFetchJobs[url].get(requestInit.signal);
68
+ } else {
69
+ this.dedupedFetchJobs[url] = this.dedupedFetchJobs[url] || /* @__PURE__ */ new Map();
70
+ job = this.createFetchJob(url, requestInit).finally(() => {
71
+ var _a, _b;
72
+ (_a = this.dedupedFetchJobs[url]) == null ? void 0 : _a.delete(requestInit.signal);
73
+ if (((_b = this.dedupedFetchJobs[url]) == null ? void 0 : _b.size) === 0) {
74
+ delete this.dedupedFetchJobs[url];
75
+ }
76
+ });
77
+ this.dedupedFetchJobs[url].set(requestInit.signal, job);
78
+ }
79
+ return job;
80
+ }
81
+ createFetchJob(url, requestInit = {}) {
82
+ return this.fetchFn(url, requestInit).then(async (res) => {
83
+ let json = void 0;
84
+ let text = void 0;
85
+ if (res.ok) {
86
+ try {
87
+ json = await res.json();
88
+ } catch {
89
+ }
90
+ } else {
91
+ try {
92
+ text = await res.text();
93
+ json = JSON.parse(text);
94
+ } catch {
95
+ }
96
+ }
97
+ return {
98
+ status: res.status,
99
+ headers: res.headers,
100
+ json,
101
+ text
102
+ };
103
+ });
104
+ }
105
+ }
106
+ exports.BaseClient = BaseClient;
107
+ exports.UNKNOWN_RATE_LIMIT_DELAY = UNKNOWN_RATE_LIMIT_DELAY;
108
+ //# sourceMappingURL=BaseClient.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseClient.cjs","sources":["../../src/BaseClient.ts"],"sourcesContent":["import { type LimitFunction, pLimit } from \"./lib/pLimit\"\n\nimport { PrismicError } from \"./errors/PrismicError\"\n\n/**\n * The default delay used with APIs not providing rate limit headers.\n *\n * @internal\n */\nexport const UNKNOWN_RATE_LIMIT_DELAY = 1500\n\n/**\n * A universal API to make network requests. A subset of the `fetch()` API.\n *\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/fetch}\n */\nexport type FetchLike = (\n\tinput: string,\n\tinit?: RequestInitLike,\n) => Promise<ResponseLike>\n\n/**\n * An object that allows you to abort a `fetch()` request if needed via an\n * `AbortController` object\n *\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}\n */\n// `any` is used often here to ensure this type is universally valid among\n// different AbortSignal implementations. The types of each property are not\n// important to validate since it is blindly passed to a given `fetch()`\n// function.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AbortSignalLike = any\n\n/**\n * A subset of RequestInit properties to configure a `fetch()` request.\n */\n// Only options relevant to the client are included. Extending from the full\n// RequestInit would cause issues, such as accepting Header objects.\n//\n// An interface is used to allow other libraries to augment the type with\n// environment-specific types.\nexport interface RequestInitLike extends Pick<RequestInit, \"cache\"> {\n\t/**\n\t * The HTTP method to use for the request.\n\t */\n\tmethod?: string\n\n\t/**\n\t * The request body to send with the request.\n\t */\n\t// We want to keep the body type as compatible as possible, so\n\t// we only declare the type we need and accept anything else.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tbody?: any | FormData | string\n\n\t/**\n\t * An object literal to set the `fetch()` request's headers.\n\t */\n\theaders?: Record<string, string>\n\n\t/**\n\t * An AbortSignal to set the `fetch()` request's signal.\n\t *\n\t * See:\n\t * [https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)\n\t */\n\t// NOTE: `AbortSignalLike` is `any`! It is left as `AbortSignalLike`\n\t// for backwards compatibility (the type is exported) and to signal to\n\t// other readers that this should be an AbortSignal-like object.\n\tsignal?: AbortSignalLike\n}\n\n/**\n * The minimum required properties from Response.\n */\nexport interface ResponseLike {\n\tok: boolean\n\tstatus: number\n\theaders: HeadersLike\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tjson(): Promise<any>\n\ttext(): Promise<string>\n\tblob(): Promise<Blob>\n}\n\n/**\n * The minimum required properties from Headers.\n */\nexport interface HeadersLike {\n\tget(name: string): string | null\n}\n\n/**\n * The minimum required properties to treat as an HTTP Request for automatic\n * Prismic preview support.\n */\nexport type HttpRequestLike =\n\t| /**\n\t * Web API Request\n\t *\n\t * @see http://developer.mozilla.org/en-US/docs/Web/API/Request\n\t */\n\t{\n\t\t\theaders?: {\n\t\t\t\tget(name: string): string | null\n\t\t\t}\n\t\t\turl?: string\n\t }\n\n\t/**\n\t * Express-style Request\n\t */\n\t| {\n\t\t\theaders?: {\n\t\t\t\tcookie?: string\n\t\t\t}\n\t\t\tquery?: Record<string, unknown>\n\t }\n\n/**\n * Configuration for clients that determine how APIs are queried.\n */\nexport type BaseClientConfig = {\n\t/**\n\t * The function used to make network requests to the Prismic REST API. In\n\t * environments where a global `fetch` function does not exist, such as\n\t * Node.js, this function must be provided.\n\t */\n\tfetch?: FetchLike\n\n\t/**\n\t * Options provided to the client's `fetch()` on all network requests. These\n\t * options will be merged with internally required options. They can also be\n\t * overriden on a per-query basis using the query's `fetchOptions` parameter.\n\t */\n\tfetchOptions?: RequestInitLike\n}\n\n/**\n * Parameters for any client method that use `fetch()`.\n */\nexport type FetchParams = {\n\t/**\n\t * Options provided to the client's `fetch()` on all network requests. These\n\t * options will be merged with internally required options. They can also be\n\t * overriden on a per-query basis using the query's `fetchOptions` parameter.\n\t */\n\tfetchOptions?: RequestInitLike\n\n\t/**\n\t * An `AbortSignal` provided by an `AbortController`. This allows the network\n\t * request to be cancelled if necessary.\n\t *\n\t * @deprecated Move the `signal` parameter into `fetchOptions.signal`:\n\t *\n\t * @see \\<https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal\\>\n\t */\n\tsignal?: AbortSignalLike\n}\n\n/**\n * The result of a `fetch()` job.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype FetchJobResult<TJSON = any> = {\n\tstatus: number\n\theaders: HeadersLike\n\tjson: TJSON\n\ttext?: string\n}\n\nexport abstract class BaseClient {\n\t/**\n\t * The function used to make network requests to the Prismic REST API. In\n\t * environments where a global `fetch` function does not exist, such as\n\t * Node.js, this function must be provided.\n\t */\n\tfetchFn: FetchLike\n\n\tfetchOptions?: RequestInitLike\n\n\t/**\n\t * Active queued `fetch()` jobs keyed by URL and AbortSignal (if it exists).\n\t */\n\tprivate queuedFetchJobs: Record<string, LimitFunction> = {}\n\n\t/**\n\t * Active deduped `fetch()` jobs keyed by URL and AbortSignal (if it exists).\n\t */\n\tprivate dedupedFetchJobs: Record<\n\t\tstring,\n\t\tMap<AbortSignalLike | undefined, Promise<FetchJobResult>>\n\t> = {}\n\n\tconstructor(options: BaseClientConfig) {\n\t\tthis.fetchOptions = options.fetchOptions\n\n\t\tif (typeof options.fetch === \"function\") {\n\t\t\tthis.fetchFn = options.fetch\n\t\t} else if (typeof globalThis.fetch === \"function\") {\n\t\t\tthis.fetchFn = globalThis.fetch as FetchLike\n\t\t} else {\n\t\t\tthrow new PrismicError(\n\t\t\t\t\"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.\",\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t)\n\t\t}\n\n\t\t// If the global fetch function is used, we must bind it to the global scope.\n\t\tif (this.fetchFn === globalThis.fetch) {\n\t\t\tthis.fetchFn = this.fetchFn.bind(globalThis)\n\t\t}\n\t}\n\n\tprotected async fetch(\n\t\turl: string,\n\t\tparams: FetchParams = {},\n\t): Promise<FetchJobResult> {\n\t\tconst requestInit: RequestInitLike = {\n\t\t\t...this.fetchOptions,\n\t\t\t...params.fetchOptions,\n\t\t\theaders: {\n\t\t\t\t...this.fetchOptions?.headers,\n\t\t\t\t...params.fetchOptions?.headers,\n\t\t\t},\n\t\t\tsignal:\n\t\t\t\tparams.fetchOptions?.signal ||\n\t\t\t\tparams.signal ||\n\t\t\t\tthis.fetchOptions?.signal,\n\t\t}\n\n\t\t// Request with a `body` are throttled, others are deduped.\n\t\tif (params.fetchOptions?.body) {\n\t\t\treturn this.queueFetch(url, requestInit)\n\t\t} else {\n\t\t\treturn this.dedupeFetch(url, requestInit)\n\t\t}\n\t}\n\n\tprivate queueFetch(\n\t\turl: string,\n\t\trequestInit: RequestInitLike = {},\n\t): Promise<FetchJobResult> {\n\t\t// Rate limiting is done per hostname.\n\t\tconst hostname = new URL(url).hostname\n\n\t\tif (!this.queuedFetchJobs[hostname]) {\n\t\t\tthis.queuedFetchJobs[hostname] = pLimit({\n\t\t\t\tinterval: UNKNOWN_RATE_LIMIT_DELAY,\n\t\t\t})\n\t\t}\n\n\t\treturn this.queuedFetchJobs[hostname](() =>\n\t\t\tthis.createFetchJob(url, requestInit),\n\t\t)\n\t}\n\n\tprivate dedupeFetch(\n\t\turl: string,\n\t\trequestInit: RequestInitLike = {},\n\t): Promise<FetchJobResult> {\n\t\tlet job: Promise<FetchJobResult>\n\n\t\t// `fetchJobs` is keyed twice: first by the URL and again by is\n\t\t// signal, if one exists.\n\t\t//\n\t\t// Using two keys allows us to reuse fetch requests for\n\t\t// equivalent URLs, but eject when we detect unique signals.\n\t\tif (\n\t\t\tthis.dedupedFetchJobs[url] &&\n\t\t\tthis.dedupedFetchJobs[url].has(requestInit.signal)\n\t\t) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tjob = this.dedupedFetchJobs[url].get(requestInit.signal)!\n\t\t} else {\n\t\t\tthis.dedupedFetchJobs[url] = this.dedupedFetchJobs[url] || new Map()\n\n\t\t\tjob = this.createFetchJob(url, requestInit).finally(() => {\n\t\t\t\tthis.dedupedFetchJobs[url]?.delete(requestInit.signal)\n\n\t\t\t\tif (this.dedupedFetchJobs[url]?.size === 0) {\n\t\t\t\t\tdelete this.dedupedFetchJobs[url]\n\t\t\t\t}\n\t\t\t})\n\n\t\t\tthis.dedupedFetchJobs[url].set(requestInit.signal, job)\n\t\t}\n\n\t\treturn job\n\t}\n\n\tprivate createFetchJob(\n\t\turl: string,\n\t\trequestInit: RequestInitLike = {},\n\t): Promise<FetchJobResult> {\n\t\treturn this.fetchFn(url, requestInit).then(async (res) => {\n\t\t\t// We can assume Prismic REST API responses\n\t\t\t// will have a `application/json`\n\t\t\t// Content Type. If not, this will\n\t\t\t// throw, signaling an invalid\n\t\t\t// response.\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\tlet json: any = undefined\n\t\t\tlet text: string | undefined = undefined\n\t\t\tif (res.ok) {\n\t\t\t\ttry {\n\t\t\t\t\tjson = await res.json()\n\t\t\t\t} catch {\n\t\t\t\t\t// noop\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\ttext = await res.text()\n\t\t\t\t\tjson = JSON.parse(text)\n\t\t\t\t} catch {\n\t\t\t\t\t// noop\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tstatus: res.status,\n\t\t\t\theaders: res.headers,\n\t\t\t\tjson,\n\t\t\t\ttext,\n\t\t\t}\n\t\t})\n\t}\n}\n"],"names":["PrismicError","pLimit"],"mappings":";;;;;;;AASO,MAAM,2BAA2B;MAmKlB,WAAU;AAAA,EAuB/B,YAAY,SAAyB;AAjBrC;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA;AAKQ;AAAA;AAAA;AAAA,2CAAiD,CAAA;AAKjD;AAAA;AAAA;AAAA,4CAGJ,CAAA;AAGH,SAAK,eAAe,QAAQ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AAG,EAAE,IAAI,YAAY,MAAM;AAAA,IAAA,OACjD;AACD,WAAA,iBAAiB,GAAG,IAAI,KAAK,iBAAiB,GAAG,yBAAS;AAE/D,YAAM,KAAK,eAAe,KAAK,WAAW,EAAE,QAAQ,MAAK;;AACxD,mBAAK,iBAAiB,GAAG,MAAzB,mBAA4B,OAAO,YAAY;AAE/C,cAAI,UAAK,iBAAiB,GAAG,MAAzB,mBAA4B,UAAS,GAAG;AACpC,iBAAA,KAAK,iBAAiB,GAAG;AAAA,QACjC;AAAA,MAAA,CACA;AAED,WAAK,iBAAiB,GAAG,EAAE,IAAI,YAAY,QAAQ,GAAG;AAAA,IACvD;AAEO,WAAA;AAAA,EACR;AAAA,EAEQ,eACP,KACA,cAA+B,IAAE;AAEjC,WAAO,KAAK,QAAQ,KAAK,WAAW,EAAE,KAAK,OAAO,QAAO;AAOxD,UAAI,OAAY;AAChB,UAAI,OAA2B;AAC/B,UAAI,IAAI,IAAI;AACP,YAAA;AACI,iBAAA,MAAM,IAAI;gBACV;AAAA,QAER;AAAA,MAAA,OACM;AACF,YAAA;AACI,iBAAA,MAAM,IAAI;AACV,iBAAA,KAAK,MAAM,IAAI;AAAA,QAAA,QACf;AAAA,QAER;AAAA,MACD;AAEO,aAAA;AAAA,QACN,QAAQ,IAAI;AAAA,QACZ,SAAS,IAAI;AAAA,QACb;AAAA,QACA;AAAA,MAAA;AAAA,KAED;AAAA,EACF;AACA;;;"}
@@ -0,0 +1,152 @@
1
+ /**
2
+ * The default delay used with APIs not providing rate limit headers.
3
+ *
4
+ * @internal
5
+ */
6
+ export declare const UNKNOWN_RATE_LIMIT_DELAY = 1500;
7
+ /**
8
+ * A universal API to make network requests. A subset of the `fetch()` API.
9
+ *
10
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/fetch}
11
+ */
12
+ export type FetchLike = (input: string, init?: RequestInitLike) => Promise<ResponseLike>;
13
+ /**
14
+ * An object that allows you to abort a `fetch()` request if needed via an
15
+ * `AbortController` object
16
+ *
17
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}
18
+ */
19
+ export type AbortSignalLike = any;
20
+ /**
21
+ * A subset of RequestInit properties to configure a `fetch()` request.
22
+ */
23
+ export interface RequestInitLike extends Pick<RequestInit, "cache"> {
24
+ /**
25
+ * The HTTP method to use for the request.
26
+ */
27
+ method?: string;
28
+ /**
29
+ * The request body to send with the request.
30
+ */
31
+ body?: any | FormData | string;
32
+ /**
33
+ * An object literal to set the `fetch()` request's headers.
34
+ */
35
+ headers?: Record<string, string>;
36
+ /**
37
+ * An AbortSignal to set the `fetch()` request's signal.
38
+ *
39
+ * See:
40
+ * [https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)
41
+ */
42
+ signal?: AbortSignalLike;
43
+ }
44
+ /**
45
+ * The minimum required properties from Response.
46
+ */
47
+ export interface ResponseLike {
48
+ ok: boolean;
49
+ status: number;
50
+ headers: HeadersLike;
51
+ json(): Promise<any>;
52
+ text(): Promise<string>;
53
+ blob(): Promise<Blob>;
54
+ }
55
+ /**
56
+ * The minimum required properties from Headers.
57
+ */
58
+ export interface HeadersLike {
59
+ get(name: string): string | null;
60
+ }
61
+ /**
62
+ * The minimum required properties to treat as an HTTP Request for automatic
63
+ * Prismic preview support.
64
+ */
65
+ export type HttpRequestLike = /**
66
+ * Web API Request
67
+ *
68
+ * @see http://developer.mozilla.org/en-US/docs/Web/API/Request
69
+ */ {
70
+ headers?: {
71
+ get(name: string): string | null;
72
+ };
73
+ url?: string;
74
+ }
75
+ /**
76
+ * Express-style Request
77
+ */
78
+ | {
79
+ headers?: {
80
+ cookie?: string;
81
+ };
82
+ query?: Record<string, unknown>;
83
+ };
84
+ /**
85
+ * Configuration for clients that determine how APIs are queried.
86
+ */
87
+ export type BaseClientConfig = {
88
+ /**
89
+ * The function used to make network requests to the Prismic REST API. In
90
+ * environments where a global `fetch` function does not exist, such as
91
+ * Node.js, this function must be provided.
92
+ */
93
+ fetch?: FetchLike;
94
+ /**
95
+ * Options provided to the client's `fetch()` on all network requests. These
96
+ * options will be merged with internally required options. They can also be
97
+ * overriden on a per-query basis using the query's `fetchOptions` parameter.
98
+ */
99
+ fetchOptions?: RequestInitLike;
100
+ };
101
+ /**
102
+ * Parameters for any client method that use `fetch()`.
103
+ */
104
+ export type FetchParams = {
105
+ /**
106
+ * Options provided to the client's `fetch()` on all network requests. These
107
+ * options will be merged with internally required options. They can also be
108
+ * overriden on a per-query basis using the query's `fetchOptions` parameter.
109
+ */
110
+ fetchOptions?: RequestInitLike;
111
+ /**
112
+ * An `AbortSignal` provided by an `AbortController`. This allows the network
113
+ * request to be cancelled if necessary.
114
+ *
115
+ * @deprecated Move the `signal` parameter into `fetchOptions.signal`:
116
+ *
117
+ * @see \<https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal\>
118
+ */
119
+ signal?: AbortSignalLike;
120
+ };
121
+ /**
122
+ * The result of a `fetch()` job.
123
+ */
124
+ type FetchJobResult<TJSON = any> = {
125
+ status: number;
126
+ headers: HeadersLike;
127
+ json: TJSON;
128
+ text?: string;
129
+ };
130
+ export declare abstract class BaseClient {
131
+ /**
132
+ * The function used to make network requests to the Prismic REST API. In
133
+ * environments where a global `fetch` function does not exist, such as
134
+ * Node.js, this function must be provided.
135
+ */
136
+ fetchFn: FetchLike;
137
+ fetchOptions?: RequestInitLike;
138
+ /**
139
+ * Active queued `fetch()` jobs keyed by URL and AbortSignal (if it exists).
140
+ */
141
+ private queuedFetchJobs;
142
+ /**
143
+ * Active deduped `fetch()` jobs keyed by URL and AbortSignal (if it exists).
144
+ */
145
+ private dedupedFetchJobs;
146
+ constructor(options: BaseClientConfig);
147
+ protected fetch(url: string, params?: FetchParams): Promise<FetchJobResult>;
148
+ private queueFetch;
149
+ private dedupeFetch;
150
+ private createFetchJob;
151
+ }
152
+ export {};
@@ -0,0 +1,108 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ import { pLimit } from "./lib/pLimit.js";
5
+ import { PrismicError } from "./errors/PrismicError.js";
6
+ const UNKNOWN_RATE_LIMIT_DELAY = 1500;
7
+ class BaseClient {
8
+ constructor(options) {
9
+ /**
10
+ * The function used to make network requests to the Prismic REST API. In
11
+ * environments where a global `fetch` function does not exist, such as
12
+ * Node.js, this function must be provided.
13
+ */
14
+ __publicField(this, "fetchFn");
15
+ __publicField(this, "fetchOptions");
16
+ /**
17
+ * Active queued `fetch()` jobs keyed by URL and AbortSignal (if it exists).
18
+ */
19
+ __publicField(this, "queuedFetchJobs", {});
20
+ /**
21
+ * Active deduped `fetch()` jobs keyed by URL and AbortSignal (if it exists).
22
+ */
23
+ __publicField(this, "dedupedFetchJobs", {});
24
+ this.fetchOptions = options.fetchOptions;
25
+ if (typeof options.fetch === "function") {
26
+ this.fetchFn = options.fetch;
27
+ } else if (typeof globalThis.fetch === "function") {
28
+ this.fetchFn = globalThis.fetch;
29
+ } else {
30
+ 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);
31
+ }
32
+ if (this.fetchFn === globalThis.fetch) {
33
+ this.fetchFn = this.fetchFn.bind(globalThis);
34
+ }
35
+ }
36
+ async fetch(url, params = {}) {
37
+ var _a, _b, _c, _d, _e;
38
+ const requestInit = {
39
+ ...this.fetchOptions,
40
+ ...params.fetchOptions,
41
+ headers: {
42
+ ...(_a = this.fetchOptions) == null ? void 0 : _a.headers,
43
+ ...(_b = params.fetchOptions) == null ? void 0 : _b.headers
44
+ },
45
+ signal: ((_c = params.fetchOptions) == null ? void 0 : _c.signal) || params.signal || ((_d = this.fetchOptions) == null ? void 0 : _d.signal)
46
+ };
47
+ if ((_e = params.fetchOptions) == null ? void 0 : _e.body) {
48
+ return this.queueFetch(url, requestInit);
49
+ } else {
50
+ return this.dedupeFetch(url, requestInit);
51
+ }
52
+ }
53
+ queueFetch(url, requestInit = {}) {
54
+ const hostname = new URL(url).hostname;
55
+ if (!this.queuedFetchJobs[hostname]) {
56
+ this.queuedFetchJobs[hostname] = pLimit({
57
+ interval: UNKNOWN_RATE_LIMIT_DELAY
58
+ });
59
+ }
60
+ return this.queuedFetchJobs[hostname](() => this.createFetchJob(url, requestInit));
61
+ }
62
+ dedupeFetch(url, requestInit = {}) {
63
+ let job;
64
+ if (this.dedupedFetchJobs[url] && this.dedupedFetchJobs[url].has(requestInit.signal)) {
65
+ job = this.dedupedFetchJobs[url].get(requestInit.signal);
66
+ } else {
67
+ this.dedupedFetchJobs[url] = this.dedupedFetchJobs[url] || /* @__PURE__ */ new Map();
68
+ job = this.createFetchJob(url, requestInit).finally(() => {
69
+ var _a, _b;
70
+ (_a = this.dedupedFetchJobs[url]) == null ? void 0 : _a.delete(requestInit.signal);
71
+ if (((_b = this.dedupedFetchJobs[url]) == null ? void 0 : _b.size) === 0) {
72
+ delete this.dedupedFetchJobs[url];
73
+ }
74
+ });
75
+ this.dedupedFetchJobs[url].set(requestInit.signal, job);
76
+ }
77
+ return job;
78
+ }
79
+ createFetchJob(url, requestInit = {}) {
80
+ return this.fetchFn(url, requestInit).then(async (res) => {
81
+ let json = void 0;
82
+ let text = void 0;
83
+ if (res.ok) {
84
+ try {
85
+ json = await res.json();
86
+ } catch {
87
+ }
88
+ } else {
89
+ try {
90
+ text = await res.text();
91
+ json = JSON.parse(text);
92
+ } catch {
93
+ }
94
+ }
95
+ return {
96
+ status: res.status,
97
+ headers: res.headers,
98
+ json,
99
+ text
100
+ };
101
+ });
102
+ }
103
+ }
104
+ export {
105
+ BaseClient,
106
+ UNKNOWN_RATE_LIMIT_DELAY
107
+ };
108
+ //# sourceMappingURL=BaseClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseClient.js","sources":["../../src/BaseClient.ts"],"sourcesContent":["import { type LimitFunction, pLimit } from \"./lib/pLimit\"\n\nimport { PrismicError } from \"./errors/PrismicError\"\n\n/**\n * The default delay used with APIs not providing rate limit headers.\n *\n * @internal\n */\nexport const UNKNOWN_RATE_LIMIT_DELAY = 1500\n\n/**\n * A universal API to make network requests. A subset of the `fetch()` API.\n *\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/fetch}\n */\nexport type FetchLike = (\n\tinput: string,\n\tinit?: RequestInitLike,\n) => Promise<ResponseLike>\n\n/**\n * An object that allows you to abort a `fetch()` request if needed via an\n * `AbortController` object\n *\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}\n */\n// `any` is used often here to ensure this type is universally valid among\n// different AbortSignal implementations. The types of each property are not\n// important to validate since it is blindly passed to a given `fetch()`\n// function.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AbortSignalLike = any\n\n/**\n * A subset of RequestInit properties to configure a `fetch()` request.\n */\n// Only options relevant to the client are included. Extending from the full\n// RequestInit would cause issues, such as accepting Header objects.\n//\n// An interface is used to allow other libraries to augment the type with\n// environment-specific types.\nexport interface RequestInitLike extends Pick<RequestInit, \"cache\"> {\n\t/**\n\t * The HTTP method to use for the request.\n\t */\n\tmethod?: string\n\n\t/**\n\t * The request body to send with the request.\n\t */\n\t// We want to keep the body type as compatible as possible, so\n\t// we only declare the type we need and accept anything else.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tbody?: any | FormData | string\n\n\t/**\n\t * An object literal to set the `fetch()` request's headers.\n\t */\n\theaders?: Record<string, string>\n\n\t/**\n\t * An AbortSignal to set the `fetch()` request's signal.\n\t *\n\t * See:\n\t * [https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)\n\t */\n\t// NOTE: `AbortSignalLike` is `any`! It is left as `AbortSignalLike`\n\t// for backwards compatibility (the type is exported) and to signal to\n\t// other readers that this should be an AbortSignal-like object.\n\tsignal?: AbortSignalLike\n}\n\n/**\n * The minimum required properties from Response.\n */\nexport interface ResponseLike {\n\tok: boolean\n\tstatus: number\n\theaders: HeadersLike\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tjson(): Promise<any>\n\ttext(): Promise<string>\n\tblob(): Promise<Blob>\n}\n\n/**\n * The minimum required properties from Headers.\n */\nexport interface HeadersLike {\n\tget(name: string): string | null\n}\n\n/**\n * The minimum required properties to treat as an HTTP Request for automatic\n * Prismic preview support.\n */\nexport type HttpRequestLike =\n\t| /**\n\t * Web API Request\n\t *\n\t * @see http://developer.mozilla.org/en-US/docs/Web/API/Request\n\t */\n\t{\n\t\t\theaders?: {\n\t\t\t\tget(name: string): string | null\n\t\t\t}\n\t\t\turl?: string\n\t }\n\n\t/**\n\t * Express-style Request\n\t */\n\t| {\n\t\t\theaders?: {\n\t\t\t\tcookie?: string\n\t\t\t}\n\t\t\tquery?: Record<string, unknown>\n\t }\n\n/**\n * Configuration for clients that determine how APIs are queried.\n */\nexport type BaseClientConfig = {\n\t/**\n\t * The function used to make network requests to the Prismic REST API. In\n\t * environments where a global `fetch` function does not exist, such as\n\t * Node.js, this function must be provided.\n\t */\n\tfetch?: FetchLike\n\n\t/**\n\t * Options provided to the client's `fetch()` on all network requests. These\n\t * options will be merged with internally required options. They can also be\n\t * overriden on a per-query basis using the query's `fetchOptions` parameter.\n\t */\n\tfetchOptions?: RequestInitLike\n}\n\n/**\n * Parameters for any client method that use `fetch()`.\n */\nexport type FetchParams = {\n\t/**\n\t * Options provided to the client's `fetch()` on all network requests. These\n\t * options will be merged with internally required options. They can also be\n\t * overriden on a per-query basis using the query's `fetchOptions` parameter.\n\t */\n\tfetchOptions?: RequestInitLike\n\n\t/**\n\t * An `AbortSignal` provided by an `AbortController`. This allows the network\n\t * request to be cancelled if necessary.\n\t *\n\t * @deprecated Move the `signal` parameter into `fetchOptions.signal`:\n\t *\n\t * @see \\<https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal\\>\n\t */\n\tsignal?: AbortSignalLike\n}\n\n/**\n * The result of a `fetch()` job.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype FetchJobResult<TJSON = any> = {\n\tstatus: number\n\theaders: HeadersLike\n\tjson: TJSON\n\ttext?: string\n}\n\nexport abstract class BaseClient {\n\t/**\n\t * The function used to make network requests to the Prismic REST API. In\n\t * environments where a global `fetch` function does not exist, such as\n\t * Node.js, this function must be provided.\n\t */\n\tfetchFn: FetchLike\n\n\tfetchOptions?: RequestInitLike\n\n\t/**\n\t * Active queued `fetch()` jobs keyed by URL and AbortSignal (if it exists).\n\t */\n\tprivate queuedFetchJobs: Record<string, LimitFunction> = {}\n\n\t/**\n\t * Active deduped `fetch()` jobs keyed by URL and AbortSignal (if it exists).\n\t */\n\tprivate dedupedFetchJobs: Record<\n\t\tstring,\n\t\tMap<AbortSignalLike | undefined, Promise<FetchJobResult>>\n\t> = {}\n\n\tconstructor(options: BaseClientConfig) {\n\t\tthis.fetchOptions = options.fetchOptions\n\n\t\tif (typeof options.fetch === \"function\") {\n\t\t\tthis.fetchFn = options.fetch\n\t\t} else if (typeof globalThis.fetch === \"function\") {\n\t\t\tthis.fetchFn = globalThis.fetch as FetchLike\n\t\t} else {\n\t\t\tthrow new PrismicError(\n\t\t\t\t\"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.\",\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t)\n\t\t}\n\n\t\t// If the global fetch function is used, we must bind it to the global scope.\n\t\tif (this.fetchFn === globalThis.fetch) {\n\t\t\tthis.fetchFn = this.fetchFn.bind(globalThis)\n\t\t}\n\t}\n\n\tprotected async fetch(\n\t\turl: string,\n\t\tparams: FetchParams = {},\n\t): Promise<FetchJobResult> {\n\t\tconst requestInit: RequestInitLike = {\n\t\t\t...this.fetchOptions,\n\t\t\t...params.fetchOptions,\n\t\t\theaders: {\n\t\t\t\t...this.fetchOptions?.headers,\n\t\t\t\t...params.fetchOptions?.headers,\n\t\t\t},\n\t\t\tsignal:\n\t\t\t\tparams.fetchOptions?.signal ||\n\t\t\t\tparams.signal ||\n\t\t\t\tthis.fetchOptions?.signal,\n\t\t}\n\n\t\t// Request with a `body` are throttled, others are deduped.\n\t\tif (params.fetchOptions?.body) {\n\t\t\treturn this.queueFetch(url, requestInit)\n\t\t} else {\n\t\t\treturn this.dedupeFetch(url, requestInit)\n\t\t}\n\t}\n\n\tprivate queueFetch(\n\t\turl: string,\n\t\trequestInit: RequestInitLike = {},\n\t): Promise<FetchJobResult> {\n\t\t// Rate limiting is done per hostname.\n\t\tconst hostname = new URL(url).hostname\n\n\t\tif (!this.queuedFetchJobs[hostname]) {\n\t\t\tthis.queuedFetchJobs[hostname] = pLimit({\n\t\t\t\tinterval: UNKNOWN_RATE_LIMIT_DELAY,\n\t\t\t})\n\t\t}\n\n\t\treturn this.queuedFetchJobs[hostname](() =>\n\t\t\tthis.createFetchJob(url, requestInit),\n\t\t)\n\t}\n\n\tprivate dedupeFetch(\n\t\turl: string,\n\t\trequestInit: RequestInitLike = {},\n\t): Promise<FetchJobResult> {\n\t\tlet job: Promise<FetchJobResult>\n\n\t\t// `fetchJobs` is keyed twice: first by the URL and again by is\n\t\t// signal, if one exists.\n\t\t//\n\t\t// Using two keys allows us to reuse fetch requests for\n\t\t// equivalent URLs, but eject when we detect unique signals.\n\t\tif (\n\t\t\tthis.dedupedFetchJobs[url] &&\n\t\t\tthis.dedupedFetchJobs[url].has(requestInit.signal)\n\t\t) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tjob = this.dedupedFetchJobs[url].get(requestInit.signal)!\n\t\t} else {\n\t\t\tthis.dedupedFetchJobs[url] = this.dedupedFetchJobs[url] || new Map()\n\n\t\t\tjob = this.createFetchJob(url, requestInit).finally(() => {\n\t\t\t\tthis.dedupedFetchJobs[url]?.delete(requestInit.signal)\n\n\t\t\t\tif (this.dedupedFetchJobs[url]?.size === 0) {\n\t\t\t\t\tdelete this.dedupedFetchJobs[url]\n\t\t\t\t}\n\t\t\t})\n\n\t\t\tthis.dedupedFetchJobs[url].set(requestInit.signal, job)\n\t\t}\n\n\t\treturn job\n\t}\n\n\tprivate createFetchJob(\n\t\turl: string,\n\t\trequestInit: RequestInitLike = {},\n\t): Promise<FetchJobResult> {\n\t\treturn this.fetchFn(url, requestInit).then(async (res) => {\n\t\t\t// We can assume Prismic REST API responses\n\t\t\t// will have a `application/json`\n\t\t\t// Content Type. If not, this will\n\t\t\t// throw, signaling an invalid\n\t\t\t// response.\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\tlet json: any = undefined\n\t\t\tlet text: string | undefined = undefined\n\t\t\tif (res.ok) {\n\t\t\t\ttry {\n\t\t\t\t\tjson = await res.json()\n\t\t\t\t} catch {\n\t\t\t\t\t// noop\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\ttext = await res.text()\n\t\t\t\t\tjson = JSON.parse(text)\n\t\t\t\t} catch {\n\t\t\t\t\t// noop\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tstatus: res.status,\n\t\t\t\theaders: res.headers,\n\t\t\t\tjson,\n\t\t\t\ttext,\n\t\t\t}\n\t\t})\n\t}\n}\n"],"names":[],"mappings":";;;;;AASO,MAAM,2BAA2B;MAmKlB,WAAU;AAAA,EAuB/B,YAAY,SAAyB;AAjBrC;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA;AAKQ;AAAA;AAAA;AAAA,2CAAiD,CAAA;AAKjD;AAAA;AAAA;AAAA,4CAGJ,CAAA;AAGH,SAAK,eAAe,QAAQ;AAExB,QAAA,OAAO,QAAQ,UAAU,YAAY;AACxC,WAAK,UAAU,QAAQ;AAAA,IACb,WAAA,OAAO,WAAW,UAAU,YAAY;AAClD,WAAK,UAAU,WAAW;AAAA,IAAA,OACpB;AACN,YAAM,IAAI,a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