@crawlee/core 3.0.0-alpha.2 → 3.0.0-alpha.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 (159) hide show
  1. package/autoscaling/autoscaled_pool.d.ts +296 -0
  2. package/autoscaling/autoscaled_pool.d.ts.map +1 -0
  3. package/autoscaling/autoscaled_pool.js +673 -0
  4. package/autoscaling/autoscaled_pool.js.map +1 -0
  5. package/autoscaling/index.d.ts +4 -0
  6. package/autoscaling/index.d.ts.map +1 -0
  7. package/autoscaling/index.js +7 -0
  8. package/autoscaling/index.js.map +1 -0
  9. package/autoscaling/snapshotter.d.ts +193 -0
  10. package/autoscaling/snapshotter.d.ts.map +1 -0
  11. package/autoscaling/snapshotter.js +377 -0
  12. package/autoscaling/snapshotter.js.map +1 -0
  13. package/autoscaling/system_status.d.ts +181 -0
  14. package/autoscaling/system_status.d.ts.map +1 -0
  15. package/autoscaling/system_status.js +194 -0
  16. package/autoscaling/system_status.js.map +1 -0
  17. package/cache_container.d.ts +18 -0
  18. package/cache_container.d.ts.map +1 -0
  19. package/cache_container.js +42 -0
  20. package/cache_container.js.map +1 -0
  21. package/configuration.d.ts +150 -0
  22. package/configuration.d.ts.map +1 -0
  23. package/configuration.js +284 -0
  24. package/configuration.js.map +1 -0
  25. package/constants.d.ts +3 -0
  26. package/constants.d.ts.map +1 -0
  27. package/constants.js +6 -0
  28. package/constants.js.map +1 -0
  29. package/crawlers/crawler_commons.d.ts +25 -0
  30. package/crawlers/crawler_commons.d.ts.map +1 -0
  31. package/crawlers/crawler_commons.js +3 -0
  32. package/crawlers/crawler_commons.js.map +1 -0
  33. package/crawlers/crawler_extension.d.ts +11 -0
  34. package/crawlers/crawler_extension.d.ts.map +1 -0
  35. package/crawlers/crawler_extension.js +30 -0
  36. package/crawlers/crawler_extension.js.map +1 -0
  37. package/crawlers/crawler_utils.d.ts +20 -0
  38. package/crawlers/crawler_utils.d.ts.map +1 -0
  39. package/crawlers/crawler_utils.js +61 -0
  40. package/crawlers/crawler_utils.js.map +1 -0
  41. package/crawlers/index.d.ts +5 -0
  42. package/crawlers/index.d.ts.map +1 -0
  43. package/crawlers/index.js +8 -0
  44. package/crawlers/index.js.map +1 -0
  45. package/crawlers/statistics.d.ts +147 -0
  46. package/crawlers/statistics.d.ts.map +1 -0
  47. package/crawlers/statistics.js +360 -0
  48. package/crawlers/statistics.js.map +1 -0
  49. package/enqueue_links/enqueue_links.d.ts +151 -0
  50. package/enqueue_links/enqueue_links.d.ts.map +1 -0
  51. package/enqueue_links/enqueue_links.js +152 -0
  52. package/enqueue_links/enqueue_links.js.map +1 -0
  53. package/enqueue_links/index.d.ts +3 -0
  54. package/enqueue_links/index.d.ts.map +1 -0
  55. package/enqueue_links/index.js +6 -0
  56. package/enqueue_links/index.js.map +1 -0
  57. package/enqueue_links/shared.d.ts +60 -0
  58. package/enqueue_links/shared.d.ts.map +1 -0
  59. package/enqueue_links/shared.js +148 -0
  60. package/enqueue_links/shared.js.map +1 -0
  61. package/errors.d.ts +8 -0
  62. package/errors.d.ts.map +1 -0
  63. package/errors.js +12 -0
  64. package/errors.js.map +1 -0
  65. package/events/event_manager.d.ts +41 -0
  66. package/events/event_manager.d.ts.map +1 -0
  67. package/events/event_manager.js +103 -0
  68. package/events/event_manager.js.map +1 -0
  69. package/events/index.d.ts +3 -0
  70. package/events/index.d.ts.map +1 -0
  71. package/events/index.js +6 -0
  72. package/events/index.js.map +1 -0
  73. package/events/local_event_manager.d.ts +32 -0
  74. package/events/local_event_manager.d.ts.map +1 -0
  75. package/events/local_event_manager.js +114 -0
  76. package/events/local_event_manager.js.map +1 -0
  77. package/index.d.ts +14 -0
  78. package/index.d.ts.map +1 -0
  79. package/index.js +17 -0
  80. package/index.js.map +1 -0
  81. package/index.mjs +61 -0
  82. package/log.d.ts +3 -0
  83. package/log.d.ts.map +1 -0
  84. package/log.js +12 -0
  85. package/log.js.map +1 -0
  86. package/package.json +4 -8
  87. package/proxy_configuration.d.ts +181 -0
  88. package/proxy_configuration.d.ts.map +1 -0
  89. package/proxy_configuration.js +209 -0
  90. package/proxy_configuration.js.map +1 -0
  91. package/request.d.ts +185 -0
  92. package/request.d.ts.map +1 -0
  93. package/request.js +330 -0
  94. package/request.js.map +1 -0
  95. package/serialization.d.ts +33 -0
  96. package/serialization.d.ts.map +1 -0
  97. package/serialization.js +146 -0
  98. package/serialization.js.map +1 -0
  99. package/session_pool/errors.d.ts +8 -0
  100. package/session_pool/errors.d.ts.map +1 -0
  101. package/session_pool/errors.js +20 -0
  102. package/session_pool/errors.js.map +1 -0
  103. package/session_pool/events.d.ts +3 -0
  104. package/session_pool/events.d.ts.map +1 -0
  105. package/session_pool/events.js +6 -0
  106. package/session_pool/events.js.map +1 -0
  107. package/session_pool/index.d.ts +6 -0
  108. package/session_pool/index.d.ts.map +1 -0
  109. package/session_pool/index.js +9 -0
  110. package/session_pool/index.js.map +1 -0
  111. package/session_pool/session.d.ts +212 -0
  112. package/session_pool/session.d.ts.map +1 -0
  113. package/session_pool/session.js +360 -0
  114. package/session_pool/session.js.map +1 -0
  115. package/session_pool/session_pool.d.ts +222 -0
  116. package/session_pool/session_pool.d.ts.map +1 -0
  117. package/session_pool/session_pool.js +389 -0
  118. package/session_pool/session_pool.js.map +1 -0
  119. package/session_pool/session_utils.d.ts +9 -0
  120. package/session_pool/session_utils.d.ts.map +1 -0
  121. package/session_pool/session_utils.js +19 -0
  122. package/session_pool/session_utils.js.map +1 -0
  123. package/storages/dataset.d.ts +317 -0
  124. package/storages/dataset.d.ts.map +1 -0
  125. package/storages/dataset.js +367 -0
  126. package/storages/dataset.js.map +1 -0
  127. package/storages/index.d.ts +7 -0
  128. package/storages/index.d.ts.map +1 -0
  129. package/storages/index.js +11 -0
  130. package/storages/index.js.map +1 -0
  131. package/storages/key_value_store.d.ts +242 -0
  132. package/storages/key_value_store.d.ts.map +1 -0
  133. package/storages/key_value_store.js +320 -0
  134. package/storages/key_value_store.js.map +1 -0
  135. package/storages/request_list.d.ts +469 -0
  136. package/storages/request_list.d.ts.map +1 -0
  137. package/storages/request_list.js +724 -0
  138. package/storages/request_list.js.map +1 -0
  139. package/storages/request_queue.d.ts +315 -0
  140. package/storages/request_queue.d.ts.map +1 -0
  141. package/storages/request_queue.js +730 -0
  142. package/storages/request_queue.js.map +1 -0
  143. package/storages/storage.d.ts +260 -0
  144. package/storages/storage.d.ts.map +1 -0
  145. package/storages/storage.js +3 -0
  146. package/storages/storage.js.map +1 -0
  147. package/storages/storage_manager.d.ts +40 -0
  148. package/storages/storage_manager.d.ts.map +1 -0
  149. package/storages/storage_manager.js +119 -0
  150. package/storages/storage_manager.js.map +1 -0
  151. package/tsconfig.build.tsbuildinfo +1 -0
  152. package/typedefs.d.ts +12 -0
  153. package/typedefs.d.ts.map +1 -0
  154. package/typedefs.js +15 -0
  155. package/typedefs.js.map +1 -0
  156. package/validators.d.ts +21 -0
  157. package/validators.d.ts.map +1 -0
  158. package/validators.js +26 -0
  159. package/validators.js.map +1 -0
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveBaseUrl = exports.enqueueLinks = exports.EnqueueStrategy = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const tldts_1 = require("tldts");
6
+ const ow_1 = tslib_1.__importDefault(require("ow"));
7
+ const log_1 = tslib_1.__importDefault(require("@apify/log"));
8
+ const shared_1 = require("./shared");
9
+ var EnqueueStrategy;
10
+ (function (EnqueueStrategy) {
11
+ /**
12
+ * Matches any URLs found
13
+ */
14
+ EnqueueStrategy["All"] = "all";
15
+ /**
16
+ * Matches any URLs that have the same subdomain as the base URL
17
+ */
18
+ EnqueueStrategy["SameSubdomain"] = "same-subdomain";
19
+ /**
20
+ * Matches any URLs that have the same hostname.
21
+ * For example, `https://wow.an.example.com` and `https://example.com` will both be matched for a base url of
22
+ * `https://example.com`.
23
+ */
24
+ EnqueueStrategy["SameHostname"] = "same-hostname";
25
+ })(EnqueueStrategy = exports.EnqueueStrategy || (exports.EnqueueStrategy = {}));
26
+ /**
27
+ * The function finds elements matching a specific CSS selector (HTML anchor (`<a>`) by default)
28
+ * either in a Puppeteer/Playwright page, or in a Cheerio object (parsed HTML),
29
+ * and enqueues the URLs in their `href` attributes to the provided {@link RequestQueue}.
30
+ * If you're looking to find URLs in JavaScript heavy pages where links are not available
31
+ * in `href` elements, but rather navigations are triggered in click handlers
32
+ * see {@link puppeteerUtils.enqueueLinksByClickingElements}.
33
+ *
34
+ * Optionally, the function allows you to filter the target links' URLs using an array of {@link PseudoUrl} objects
35
+ * and override settings of the enqueued {@link Request} objects.
36
+ *
37
+ * **Example usage**
38
+ *
39
+ * ```javascript
40
+ * await enqueueLinks({
41
+ * page,
42
+ * requestQueue,
43
+ * selector: 'a.product-detail',
44
+ * pseudoUrls: [
45
+ * 'https://www.example.com/handbags/[.*]',
46
+ * 'https://www.example.com/purses/[.*]'
47
+ * ],
48
+ * });
49
+ * ```
50
+ *
51
+ * @param options All `enqueueLinks()` parameters are passed via an options object.
52
+ * @returns Promise that resolves to {@link BatchAddRequestsResult} object.
53
+ */
54
+ async function enqueueLinks(options) {
55
+ (0, ow_1.default)(options, ow_1.default.object.exactShape({
56
+ urls: ow_1.default.array.ofType(ow_1.default.string),
57
+ requestQueue: ow_1.default.object.hasKeys('fetchNextRequest', 'addRequest'),
58
+ limit: ow_1.default.optional.number,
59
+ selector: ow_1.default.optional.string,
60
+ baseUrl: ow_1.default.optional.string,
61
+ pseudoUrls: ow_1.default.optional.array.ofType(ow_1.default.any(ow_1.default.string, ow_1.default.object.hasKeys('purl'))),
62
+ globs: ow_1.default.optional.array.ofType(ow_1.default.any(ow_1.default.string, ow_1.default.object.hasKeys('glob'))),
63
+ regexps: ow_1.default.optional.array.ofType(ow_1.default.any(ow_1.default.regExp, ow_1.default.object.hasKeys('regexp'))),
64
+ transformRequestFunction: ow_1.default.optional.function,
65
+ strategy: ow_1.default.optional.string.oneOf([
66
+ EnqueueStrategy.All,
67
+ EnqueueStrategy.SameSubdomain,
68
+ EnqueueStrategy.SameHostname,
69
+ ]),
70
+ }));
71
+ const { requestQueue, limit, urls, pseudoUrls, globs, regexps, transformRequestFunction, } = options;
72
+ const urlPatternObjects = [];
73
+ if (pseudoUrls?.length) {
74
+ log_1.default.deprecated('`pseudoUrls` option is deprecated, use `globs` or `regexps` instead');
75
+ urlPatternObjects.push(...(0, shared_1.constructRegExpObjectsFromPseudoUrls)(pseudoUrls));
76
+ }
77
+ if (globs?.length) {
78
+ urlPatternObjects.push(...(0, shared_1.constructGlobObjectsFromGlobs)(globs));
79
+ }
80
+ if (regexps?.length) {
81
+ urlPatternObjects.push(...(0, shared_1.constructRegExpObjectsFromRegExps)(regexps));
82
+ }
83
+ if (!urlPatternObjects.length) {
84
+ options.strategy ?? (options.strategy = EnqueueStrategy.SameSubdomain);
85
+ }
86
+ if (options.baseUrl) {
87
+ switch (options.strategy) {
88
+ case EnqueueStrategy.SameSubdomain:
89
+ // We need to get the origin of the passed in domain in the event someone sets baseUrl
90
+ // to an url like https://example.com/deep/default/path and one of the found urls is an
91
+ // absolute relative path (/path/to/page)
92
+ urlPatternObjects.push({ glob: `${new URL(options.baseUrl).origin}/**` });
93
+ break;
94
+ case EnqueueStrategy.SameHostname: {
95
+ const url = new URL(options.baseUrl);
96
+ // Get the actual hostname from the base url
97
+ const baseUrlHostname = (0, tldts_1.getDomain)(url.hostname, { mixedInputs: false });
98
+ if (baseUrlHostname) {
99
+ // We have a hostname, so we can use it to match all links on the page that point to it and any subdomains of it
100
+ url.hostname = baseUrlHostname;
101
+ urlPatternObjects.push({ glob: `${url.origin.replace(baseUrlHostname, `*.${baseUrlHostname}`)}/**` }, { glob: `${url.origin}/**` });
102
+ }
103
+ else {
104
+ // We don't have a hostname (can happen for ips for instance), so reproduce the same behavior
105
+ // as SameDomainAndSubdomain
106
+ urlPatternObjects.push({ glob: `${url.origin}/**` });
107
+ }
108
+ break;
109
+ }
110
+ case EnqueueStrategy.All:
111
+ default:
112
+ break;
113
+ }
114
+ }
115
+ let requestOptions = (0, shared_1.createRequestOptions)(urls);
116
+ if (transformRequestFunction) {
117
+ requestOptions = requestOptions.map((request) => transformRequestFunction(request)).filter((r) => !!r);
118
+ }
119
+ let requests = (0, shared_1.createRequests)(requestOptions, urlPatternObjects);
120
+ if (limit)
121
+ requests = requests.slice(0, limit);
122
+ return requestQueue.addRequests(requests);
123
+ }
124
+ exports.enqueueLinks = enqueueLinks;
125
+ /**
126
+ * @internal
127
+ */
128
+ function resolveBaseUrl({ enqueueStrategy, finalRequestUrl, originalRequestUrl, userProvidedBaseUrl, }) {
129
+ // User provided base url takes priority
130
+ if (userProvidedBaseUrl) {
131
+ return userProvidedBaseUrl;
132
+ }
133
+ const originalUrlOrigin = new URL(originalRequestUrl).origin;
134
+ const finalUrlOrigin = new URL(finalRequestUrl ?? originalRequestUrl).origin;
135
+ // We can assume users want to go off the domain in this case
136
+ if (enqueueStrategy === EnqueueStrategy.All) {
137
+ return finalUrlOrigin ?? originalUrlOrigin;
138
+ }
139
+ // Ensure links use the same hostname
140
+ if (enqueueStrategy === EnqueueStrategy.SameHostname) {
141
+ const originalHostname = (0, tldts_1.getDomain)(originalUrlOrigin, { mixedInputs: false });
142
+ const finalHostname = (0, tldts_1.getDomain)(finalUrlOrigin, { mixedInputs: false });
143
+ if (originalHostname === finalHostname) {
144
+ return finalUrlOrigin;
145
+ }
146
+ return undefined;
147
+ }
148
+ // Always enqueue urls that are from the same origin
149
+ return originalUrlOrigin;
150
+ }
151
+ exports.resolveBaseUrl = resolveBaseUrl;
152
+ //# sourceMappingURL=enqueue_links.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enqueue_links.js","sourceRoot":"","sources":["../../src/enqueue_links/enqueue_links.ts"],"names":[],"mappings":";;;;AAAA,iCAAkC;AAClC,oDAAoB;AACpB,6DAA6B;AAC7B,qCAWkB;AAwGlB,IAAY,eAeX;AAfD,WAAY,eAAe;IACvB;;OAEG;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C;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,EAC3B,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,mBAAmB,GACN;IACb,wCAAwC;IACxC,IAAI,mBAAmB,EAAE;QACrB,OAAO,mBAAmB,CAAC;KAC9B;IAED,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC;IAC7D,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,eAAe,IAAI,kBAAkB,CAAC,CAAC,MAAM,CAAC;IAE7E,6DAA6D;IAC7D,IAAI,eAAe,KAAK,eAAe,CAAC,GAAG,EAAE;QACzC,OAAO,cAAc,IAAI,iBAAiB,CAAC;KAC9C;IAED,qCAAqC;IACrC,IAAI,eAAe,KAAK,eAAe,CAAC,YAAY,EAAE;QAClD,MAAM,gBAAgB,GAAG,IAAA,iBAAS,EAAC,iBAAiB,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,CAAE,CAAC;QAC/E,MAAM,aAAa,GAAG,IAAA,iBAAS,EAAC,cAAc,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,CAAE,CAAC;QAEzE,IAAI,gBAAgB,KAAK,aAAa,EAAE;YACpC,OAAO,cAAc,CAAC;SACzB;QAED,OAAO,SAAS,CAAC;KACpB;IAED,oDAAoD;IACpD,OAAO,iBAAiB,CAAC;AAC7B,CAAC;AAjCD,wCAiCC"}
@@ -0,0 +1,3 @@
1
+ export * from './enqueue_links';
2
+ export * from './shared';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/enqueue_links/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./enqueue_links"), exports);
5
+ tslib_1.__exportStar(require("./shared"), exports);
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/enqueue_links/index.ts"],"names":[],"mappings":";;;AAAA,0DAAgC;AAChC,mDAAyB"}
@@ -0,0 +1,60 @@
1
+ import { Request, RequestOptions } from '../request';
2
+ export declare type UrlPatternObject = {
3
+ glob?: string;
4
+ regexp?: RegExp;
5
+ } & Pick<RequestOptions, 'method' | 'payload' | 'userData' | 'headers'>;
6
+ export declare type PseudoUrlObject = {
7
+ purl: string;
8
+ } & Pick<RequestOptions, 'method' | 'payload' | 'userData' | 'headers'>;
9
+ export declare type PseudoUrlInput = string | PseudoUrlObject;
10
+ export declare type GlobObject = {
11
+ glob: string;
12
+ } & Pick<RequestOptions, 'method' | 'payload' | 'userData' | 'headers'>;
13
+ export declare type GlobInput = string | GlobObject;
14
+ export declare type RegExpObject = {
15
+ regexp: RegExp;
16
+ } & Pick<RequestOptions, 'method' | 'payload' | 'userData' | 'headers'>;
17
+ export declare type RegExpInput = RegExp | RegExpObject;
18
+ /**
19
+ * @ignore
20
+ */
21
+ export declare function updateEnqueueLinksPatternCache(item: GlobInput | RegExpInput | PseudoUrlInput, pattern: RegExpObject | GlobObject): void;
22
+ /**
23
+ * Helper factory used in the `enqueueLinks()` and enqueueLinksByClickingElements() function
24
+ * to construct RegExps from PseudoUrl strings.
25
+ * @ignore
26
+ */
27
+ export declare function constructRegExpObjectsFromPseudoUrls(pseudoUrls: PseudoUrlInput[]): RegExpObject[];
28
+ /**
29
+ * Helper factory used in the `enqueueLinks()` and enqueueLinksByClickingElements() function
30
+ * to construct Glob objects from Glob pattern strings.
31
+ * @ignore
32
+ */
33
+ export declare function constructGlobObjectsFromGlobs(globs: GlobInput[]): GlobObject[];
34
+ export declare function validateGlobPattern(glob: string): string;
35
+ /**
36
+ * Helper factory used in the `enqueueLinks()` and enqueueLinksByClickingElements() function
37
+ * to check RegExps input and return valid RegExps.
38
+ * @ignore
39
+ */
40
+ export declare function constructRegExpObjectsFromRegExps(regexps: RegExpInput[]): RegExpObject[];
41
+ /**
42
+ * @ignore
43
+ */
44
+ export declare function createRequests(requestOptions: (string | RequestOptions)[], urlPatternObjects?: UrlPatternObject[]): Request[];
45
+ /**
46
+ * @ignore
47
+ */
48
+ export declare function createRequestOptions(sources: (string | Record<string, unknown>)[]): RequestOptions[];
49
+ /**
50
+ * Takes an Apify {@link RequestOptions} object and changes its attributes in a desired way. This user-function is used
51
+ * {@link enqueueLinks} to modify requests before enqueuing them.
52
+ */
53
+ export interface RequestTransform {
54
+ /**
55
+ * @param original Request options to be modified.
56
+ * @returns The modified request options to enqueue.
57
+ */
58
+ (original: RequestOptions): RequestOptions | false | undefined | null;
59
+ }
60
+ //# sourceMappingURL=shared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/enqueue_links/shared.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAYrD,oBAAY,gBAAgB,GAAG;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB,GAAG,IAAI,CAAC,cAAc,EAAE,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC,CAAC;AAExE,oBAAY,eAAe,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,cAAc,EAAE,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC,CAAC;AAErH,oBAAY,cAAc,GAAG,MAAM,GAAG,eAAe,CAAC;AAEtD,oBAAY,UAAU,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,cAAc,EAAE,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC,CAAC;AAEhH,oBAAY,SAAS,GAAG,MAAM,G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= exports.constructRegExpObjectsFromRegExps = exports.validateGlobPattern = exports.constructGlobObjectsFromGlobs = exports.constructRegExpObjectsFromPseudoUrls = exports.updateEnqueueLinksPatternCache = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const url_1 = require("url");
6
+ const pseudo_url_1 = require("@apify/pseudo_url");
7
+ const minimatch_1 = tslib_1.__importDefault(require("minimatch"));
8
+ const request_1 = require("../request");
9
+ const MAX_ENQUEUE_LINKS_CACHE_SIZE = 1000;
10
+ /**
11
+ * To enable direct use of the Actor UI `globs`/`regexps`/`pseudoUrls` output while keeping high performance,
12
+ * all the regexps from the output are only constructed once and kept in a cache
13
+ * by the `enqueueLinks()` function.
14
+ * @ignore
15
+ */
16
+ const enqueueLinksPatternCache = new Map();
17
+ /**
18
+ * @ignore
19
+ */
20
+ function updateEnqueueLinksPatternCache(item, pattern) {
21
+ enqueueLinksPatternCache.set(item, pattern);
22
+ if (enqueueLinksPatternCache.size > MAX_ENQUEUE_LINKS_CACHE_SIZE) {
23
+ const key = enqueueLinksPatternCache.keys().next().value;
24
+ enqueueLinksPatternCache.delete(key);
25
+ }
26
+ }
27
+ exports.updateEnqueueLinksPatternCache = updateEnqueueLinksPatternCache;
28
+ /**
29
+ * Helper factory used in the `enqueueLinks()` and enqueueLinksByClickingElements() function
30
+ * to construct RegExps from PseudoUrl strings.
31
+ * @ignore
32
+ */
33
+ function constructRegExpObjectsFromPseudoUrls(pseudoUrls) {
34
+ return pseudoUrls.map((item) => {
35
+ // Get pseudoUrl object from cache.
36
+ let regexpObject = enqueueLinksPatternCache.get(item);
37
+ if (regexpObject)
38
+ return regexpObject;
39
+ if (typeof item === 'string') {
40
+ regexpObject = { regexp: (0, pseudo_url_1.purlToRegExp)(item) };
41
+ }
42
+ else {
43
+ const { purl, ...requestOptions } = item;
44
+ regexpObject = { regexp: (0, pseudo_url_1.purlToRegExp)(purl), ...requestOptions };
45
+ }
46
+ updateEnqueueLinksPatternCache(item, regexpObject);
47
+ return regexpObject;
48
+ });
49
+ }
50
+ exports.constructRegExpObjectsFromPseudoUrls = constructRegExpObjectsFromPseudoUrls;
51
+ /**
52
+ * Helper factory used in the `enqueueLinks()` and enqueueLinksByClickingElements() function
53
+ * to construct Glob objects from Glob pattern strings.
54
+ * @ignore
55
+ */
56
+ function constructGlobObjectsFromGlobs(globs) {
57
+ return globs.map((item) => {
58
+ // Get glob object from cache.
59
+ let globObject = enqueueLinksPatternCache.get(item);
60
+ if (globObject)
61
+ return globObject;
62
+ if (typeof item === 'string') {
63
+ globObject = { glob: validateGlobPattern(item) };
64
+ }
65
+ else {
66
+ const { glob, ...requestOptions } = item;
67
+ globObject = { glob: validateGlobPattern(glob), ...requestOptions };
68
+ }
69
+ updateEnqueueLinksPatternCache(item, globObject);
70
+ return globObject;
71
+ });
72
+ }
73
+ exports.constructGlobObjectsFromGlobs = constructGlobObjectsFromGlobs;
74
+ function validateGlobPattern(glob) {
75
+ const globTrimmed = glob.trim();
76
+ if (globTrimmed.length === 0)
77
+ throw new Error(`Cannot parse Glob pattern '${globTrimmed}': it must be an non-empty string`);
78
+ return globTrimmed;
79
+ }
80
+ exports.validateGlobPattern = validateGlobPattern;
81
+ /**
82
+ * Helper factory used in the `enqueueLinks()` and enqueueLinksByClickingElements() function
83
+ * to check RegExps input and return valid RegExps.
84
+ * @ignore
85
+ */
86
+ function constructRegExpObjectsFromRegExps(regexps) {
87
+ return regexps.map((item) => {
88
+ // Get regexp object from cache.
89
+ let regexpObject = enqueueLinksPatternCache.get(item);
90
+ if (regexpObject)
91
+ return regexpObject;
92
+ if (item instanceof RegExp) {
93
+ regexpObject = { regexp: item };
94
+ }
95
+ else {
96
+ regexpObject = item;
97
+ }
98
+ updateEnqueueLinksPatternCache(item, regexpObject);
99
+ return regexpObject;
100
+ });
101
+ }
102
+ exports.constructRegExpObjectsFromRegExps = constructRegExpObjectsFromRegExps;
103
+ /**
104
+ * @ignore
105
+ */
106
+ function createRequests(requestOptions, urlPatternObjects) {
107
+ if (!urlPatternObjects || !urlPatternObjects.length) {
108
+ return requestOptions
109
+ .map((opts) => new request_1.Request(typeof opts === 'string' ? { url: opts } : opts));
110
+ }
111
+ const requests = [];
112
+ for (const urlPatternObject of urlPatternObjects) {
113
+ const { regexp, glob, ...requestRegExpOptions } = urlPatternObject;
114
+ for (const opts of requestOptions) {
115
+ const urlToMatch = typeof opts === 'string' ? opts : opts.url;
116
+ if ((regexp && urlToMatch.match(regexp)) || // eslint-disable-line
117
+ (glob && (0, minimatch_1.default)(urlToMatch, glob, { nocase: true }))) {
118
+ const request = typeof opts === 'string'
119
+ ? { url: opts, ...requestRegExpOptions }
120
+ : { ...opts, ...requestRegExpOptions };
121
+ requests.push(new request_1.Request(request));
122
+ }
123
+ }
124
+ }
125
+ return requests;
126
+ }
127
+ exports.createRequests = createRequests;
128
+ /**
129
+ * @ignore
130
+ */
131
+ function createRequestOptions(sources) {
132
+ return sources
133
+ .map((src) => (typeof src === 'string' ? { url: src } : src))
134
+ .filter(({ url }) => {
135
+ try {
136
+ return new url_1.URL(url).href;
137
+ }
138
+ catch (err) {
139
+ return false;
140
+ }
141
+ })
142
+ .map((requestOptions) => {
143
+ requestOptions.userData ?? (requestOptions.userData = {});
144
+ return requestOptions;
145
+ });
146
+ }
147
+ exports.createRequestOptions = createRequestOptions;
148
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/enqueue_links/shared.ts"],"names":[],"mappings":";;;;AAAA,6BAA0B;AAC1B,kDAAiD;AACjD,kEAAkC;AAClC,wCAAqD;AAErD,MAAM,4BAA4B,GAAG,IAAI,CAAC;AAE1C;;;;;GAKG;AACH,MAAM,wBAAwB,GAAG,IAAI,GAAG,EAAE,CAAC;AAmB3C;;GAEG;AACH,SAAgB,8BAA8B,CAAC,IAA8C,EAAE,OAAkC;IAC7H,wBAAwB,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC5C,IAAI,wBAA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ACzF,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE;QAChB,IAAI;YACA,OAAO,IAAI,SAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;SAC5B;QAAC,OAAO,GAAG,EAAE;YACV,OAAO,KAAK,CAAC;SAChB;IACL,CAAC,CAAC;SACD,GAAG,CAAC,CAAC,cAAc,EAAE,EAAE;QACpB,cAAc,CAAC,QAAQ,KAAvB,cAAc,CAAC,QAAQ,GAAK,EAAE,EAAC;QAC/B,OAAO,cAAc,CAAC;IAC1B,CAAC,CAAC,CAAC;AACX,CAAC;AAdD,oDAcC"}
package/errors.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * TimeoutError class.
3
+ * This error should be thrown after request timeout from `requestAsBrowser`.
4
+ * @ignore
5
+ */
6
+ export declare class TimeoutError extends Error {
7
+ }
8
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,YAAa,SAAQ,KAAK;CAAG"}
package/errors.js ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TimeoutError = void 0;
4
+ /**
5
+ * TimeoutError class.
6
+ * This error should be thrown after request timeout from `requestAsBrowser`.
7
+ * @ignore
8
+ */
9
+ class TimeoutError extends Error {
10
+ }
11
+ exports.TimeoutError = TimeoutError;
12
+ //# sourceMappingURL=errors.js.map
package/errors.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,MAAa,YAAa,SAAQ,KAAK;CAAG;AAA1C,oCAA0C"}
@@ -0,0 +1,41 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'events';
3
+ import { BetterIntervalID } from '@apify/utilities';
4
+ import { Configuration } from '../configuration';
5
+ export declare const enum EventType {
6
+ PERSIST_STATE = "persistState",
7
+ SYSTEM_INFO = "systemInfo",
8
+ MIGRATING = "migrating",
9
+ ABORTING = "aborting"
10
+ }
11
+ export declare type EventTypeName = EventType | 'systemInfo' | 'persistState' | 'migrating' | 'aborting';
12
+ export declare abstract class EventManager {
13
+ readonly config: Configuration;
14
+ protected events: EventEmitter;
15
+ protected initialized: boolean;
16
+ protected persistStateInterval?: BetterIntervalID;
17
+ protected log: import("@apify/log").Log;
18
+ constructor(config?: Configuration);
19
+ /**
20
+ * Initializes `Actor.events` event emitter by creating a connection to a websocket that provides them.
21
+ * This is an internal function that is automatically called by `Actor.main()`.
22
+ */
23
+ init(): Promise<void>;
24
+ /**
25
+ * Closes websocket providing events from Actor infrastructure and also stops sending internal events
26
+ * of Apify package such as `persistState`. This is automatically called at the end of `Actor.main()`.
27
+ */
28
+ close(): Promise<void>;
29
+ on(event: EventTypeName, listener: (...args: any[]) => any): void;
30
+ off(event: EventTypeName, listener?: (...args: any[]) => any): void;
31
+ emit(event: EventTypeName, ...args: unknown[]): void;
32
+ /**
33
+ * @internal
34
+ */
35
+ listenerCount(event: EventTypeName): number;
36
+ /**
37
+ * @internal
38
+ */
39
+ listeners(event: EventTypeName): (() => Promise<unknown>)[];
40
+ }
41
+ //# sourceMappingURL=event_manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event_manager.d.ts","sourceRoot":"","sources":["../../src/events/event_manager.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAuB,gBAAgB,EAAqB,MAAM,kBAAkB,CAAC;AAC5F,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,0BAAkB,SAAS;IACvB,aAAa,iBAAiB;IAC9B,WAAW,eAAe;IAC1B,SAAS,cAAc;IACvB,QAAQ,aAAa;CACxB;AAED,oBAAY,aAAa,GAAG,SAAS,GAAG,YAAY,GAAG,cAAc,GAAG,WAAW,GAAG,UAAU,CAAC;AAEjG,8BAAsB,YAAY;IAMlB,QAAQ,CAAC,MAAM;IAL3B,SAAS,CAAC,MAAM,eAAsB;IACtC,SAAS,CAAC,WAAW,UAAS;IAC9B,SAAS,CAAC,oBAAoB,CAAC,EAAE,gBAAgB,CAAC;IAClD,SAAS,CAAC,GAAG,2BAAmC;gBAE3B,MAAM,gBAAkC;IAE7D;;;OAGG;IACG,IAAI;IAaV;;;OAGG;IACG,KAAK;IASX,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAAG,IAAI;IAIjE,GAAG,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAAG,IAAI;IAQnE,IAAI,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAIpD;;OAEG;IACH,aAAa,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM;IAI3C;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,aAAa,GAAG,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE;CAG9D"}
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventManager = exports.EventType = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const log_1 = tslib_1.__importDefault(require("@apify/log"));
6
+ const events_1 = require("events");
7
+ const utilities_1 = require("@apify/utilities");
8
+ const configuration_1 = require("../configuration");
9
+ var EventType;
10
+ (function (EventType) {
11
+ EventType["PERSIST_STATE"] = "persistState";
12
+ EventType["SYSTEM_INFO"] = "systemInfo";
13
+ EventType["MIGRATING"] = "migrating";
14
+ EventType["ABORTING"] = "aborting";
15
+ })(EventType = exports.EventType || (exports.EventType = {}));
16
+ class EventManager {
17
+ constructor(config = configuration_1.Configuration.getGlobalConfig()) {
18
+ Object.defineProperty(this, "config", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: config
23
+ });
24
+ Object.defineProperty(this, "events", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: new events_1.EventEmitter()
29
+ });
30
+ Object.defineProperty(this, "initialized", {
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true,
34
+ value: false
35
+ });
36
+ Object.defineProperty(this, "persistStateInterval", {
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true,
40
+ value: void 0
41
+ });
42
+ Object.defineProperty(this, "log", {
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true,
46
+ value: log_1.default.child({ prefix: 'Events' })
47
+ });
48
+ }
49
+ /**
50
+ * Initializes `Actor.events` event emitter by creating a connection to a websocket that provides them.
51
+ * This is an internal function that is automatically called by `Actor.main()`.
52
+ */
53
+ async init() {
54
+ if (this.initialized) {
55
+ return;
56
+ }
57
+ const persistStateIntervalMillis = this.config.get('persistStateIntervalMillis');
58
+ this.persistStateInterval = (0, utilities_1.betterSetInterval)((intervalCallback) => {
59
+ this.emit("persistState" /* PERSIST_STATE */, { isMigrating: false });
60
+ intervalCallback();
61
+ }, persistStateIntervalMillis);
62
+ this.initialized = true;
63
+ }
64
+ /**
65
+ * Closes websocket providing events from Actor infrastructure and also stops sending internal events
66
+ * of Apify package such as `persistState`. This is automatically called at the end of `Actor.main()`.
67
+ */
68
+ async close() {
69
+ if (!this.initialized) {
70
+ return;
71
+ }
72
+ (0, utilities_1.betterClearInterval)(this.persistStateInterval);
73
+ this.initialized = false;
74
+ }
75
+ on(event, listener) {
76
+ this.events.on(event, listener);
77
+ }
78
+ off(event, listener) {
79
+ if (listener) {
80
+ this.events.removeListener(event, listener);
81
+ }
82
+ else {
83
+ this.events.removeAllListeners(event);
84
+ }
85
+ }
86
+ emit(event, ...args) {
87
+ this.events.emit(event, ...args);
88
+ }
89
+ /**
90
+ * @internal
91
+ */
92
+ listenerCount(event) {
93
+ return this.events.listenerCount(event);
94
+ }
95
+ /**
96
+ * @internal
97
+ */
98
+ listeners(event) {
99
+ return this.events.listeners(event);
100
+ }
101
+ }
102
+ exports.EventManager = EventManager;
103
+ //# sourceMappingURL=event_manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event_manager.js","sourceRoot":"","sources":["../../src/events/event_manager.ts"],"names":[],"mappings":";;;;AAAA,6DAA6B;AAC7B,mCAAsC;AACtC,gDAA4F;AAC5F,oDAAiD;AAEjD,IAAkB,SAKjB;AALD,WAAkB,SAAS;IACvB,2CAA8B,CAAA;IAC9B,uCAA0B,CAAA;IAC1B,oCAAuB,CAAA;IACvB,kCAAqB,CAAA;AACzB,CAAC,EALiB,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAK1B;AAID,MAAsB,YAAY;IAM9B,YAAqB,SAAS,6BAAa,CAAC,eAAe,EAAE;;;;;mBAAxC;;QALrB;;;;mBAAmB,IAAI,qBAAY,EAAE;WAAC;QACtC;;;;mBAAwB,KAAK;WAAC;QAC9B;;;;;WAAkD;QAClD;;;;mBAAgB,aAAG,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;WAAC;IAEgB,CAAC;IAEjE;;;OAGG;IACH,KAAK,CAAC,IAAI;QACN,IAAI,IAAI,CAAC,WAAW,EAAE;YAClB,OAAO;SACV;QAED,MAAM,0BAA0B,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAE,CAAC;QAClF,IAAI,CAAC,oBAAoB,GAAG,IAAA,6BAAiB,EAAC,CAAC,gBAA+B,EAAE,EAAE;YAC9E,IAAI,CAAC,IAAI,qCAA0B,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;YAC3D,gBAAgB,EAAE,CAAC;QACvB,CAAC,EAAE,0BAA0B,CAAC,CAAC;QAC/B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,KAAK;QACP,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACnB,OAAO;SACV;QAED,IAAA,+BAAmB,EAAC,IAAI,CAAC,oBAAqB,CAAC,CAAC;QAChD,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;IAC7B,CAAC;IAED,EAAE,CAAC,KAAoB,EAAE,QAAiC;QACtD,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACpC,CAAC;IAED,GAAG,CAAC,KAAoB,EAAE,QAAkC;QACxD,IAAI,QAAQ,EAAE;YACV,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;SAC/C;aAAM;YACH,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;SACzC;IACL,CAAC;IAED,IAAI,CAAC,KAAoB,EAAE,GAAG,IAAe;QACzC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,aAAa,CAAC,KAAoB;QAC9B,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,KAAoB;QAC1B,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAA+B,CAAC;IACtE,CAAC;CACJ;AAnED,oCAmEC"}
@@ -0,0 +1,3 @@
1
+ export * from './event_manager';
2
+ export * from './local_event_manager';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./event_manager"), exports);
5
+ tslib_1.__exportStar(require("./local_event_manager"), exports);
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":";;;AAAA,0DAAgC;AAChC,gEAAsC"}
@@ -0,0 +1,32 @@
1
+ import { EventManager } from './event_manager';
2
+ export declare class LocalEventManager extends EventManager {
3
+ private intervals;
4
+ private previousTicks;
5
+ /**
6
+ * Initializes `Actor.events` event emitter by creating a connection to a websocket that provides them.
7
+ * This is an internal function that is automatically called by `Actor.main()`.
8
+ */
9
+ init(): Promise<void>;
10
+ /**
11
+ * Closes websocket providing events from Actor infrastructure and also stops sending internal events
12
+ * of Apify package such as `persistState`.
13
+ * This is automatically called at the end of `Actor.main()`.
14
+ */
15
+ close(): Promise<void>;
16
+ /**
17
+ * @internal
18
+ */
19
+ emitSystemInfoEvent(intervalCallback: () => unknown): Promise<void>;
20
+ private getCurrentCpuTicks;
21
+ /**
22
+ * Creates a SystemInfo object based on local metrics.
23
+ */
24
+ private createSystemInfo;
25
+ private createCpuInfo;
26
+ private createMemoryInfo;
27
+ /**
28
+ * Helper method for easier mocking.
29
+ */
30
+ private _getMemoryInfo;
31
+ }
32
+ //# sourceMappingURL=local_event_manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local_event_manager.d.ts","sourceRoot":"","sources":["../../src/events/local_event_manager.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAa,MAAM,iBAAiB,CAAC;AAO1D,qBAAa,iBAAkB,SAAQ,YAAY;IAC/C,OAAO,CAAC,SAAS,CAAiB;IAClC,OAAO,CAAC,aAAa,CAAyB;IAE9C;;;OAGG;IACY,IAAI;IAYnB;;;;OAIG;IACY,KAAK;IASpB;;OAEG;IACG,mBAAmB,CAAC,gBAAgB,EAAE,MAAM,OAAO;IAQzD,OAAO,CAAC,kBAAkB;IAW1B;;OAEG;YACW,gBAAgB;IAQ9B,OAAO,CAAC,aAAa;YAaP,gBAAgB;IAc9B;;OAEG;YACW,cAAc;CAG/B"}