polite-crawler 0.7.11 → 0.7.13
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.
- package/README.md +22 -0
- package/build/api.d.mts +32 -1
- package/build/api.mjs +48 -2
- package/build/api.mjs.map +1 -1
- package/build/{browser-C_dFMvO3.mjs → browser-d8YE87vN.mjs} +3 -3
- package/build/{browser-C_dFMvO3.mjs.map → browser-d8YE87vN.mjs.map} +1 -1
- package/build/{cli-daemon-CX276Rtz.mjs → cli-daemon-BO4KheGn.mjs} +2 -2
- package/build/{cli-daemon-CX276Rtz.mjs.map → cli-daemon-BO4KheGn.mjs.map} +1 -1
- package/build/{cli-recipes-DBZzjwDF.mjs → cli-recipes-BzNwc3gz.mjs} +2 -2
- package/build/{cli-recipes-DBZzjwDF.mjs.map → cli-recipes-BzNwc3gz.mjs.map} +1 -1
- package/build/cli.mjs +15 -15
- package/build/{daemon-Ds_tQTbe.mjs → daemon-Cf5kfakp.mjs} +8 -8
- package/build/{daemon-Ds_tQTbe.mjs.map → daemon-Cf5kfakp.mjs.map} +1 -1
- package/build/{diff-CedQOqWF.mjs → diff-CfHnyfQt.mjs} +2 -2
- package/build/{diff-CedQOqWF.mjs.map → diff-CfHnyfQt.mjs.map} +1 -1
- package/build/{extract-BaYDYK4l.mjs → extract-CConywz8.mjs} +2 -2
- package/build/{extract-BaYDYK4l.mjs.map → extract-CConywz8.mjs.map} +1 -1
- package/build/html.mjs +2 -2
- package/build/index.d.mts +5 -5
- package/build/index.mjs +16 -16
- package/build/{log-CB5bADmd.mjs → log-BCu-Evbd.mjs} +1 -1
- package/build/{log-CB5bADmd.mjs.map → log-BCu-Evbd.mjs.map} +1 -1
- package/build/{mcp-package-D9ACY0Ux.mjs → mcp-package-BfWefRka.mjs} +1 -1
- package/build/{mcp-package-D9ACY0Ux.mjs.map → mcp-package-BfWefRka.mjs.map} +1 -1
- package/build/{ollama-B7eNmGhl.mjs → ollama-HOhb74X_.mjs} +1 -1
- package/build/{ollama-B7eNmGhl.mjs.map → ollama-HOhb74X_.mjs.map} +1 -1
- package/build/{open-B-VbHm5U.mjs → open-BlCyswse.mjs} +15 -15
- package/build/{open-B-VbHm5U.mjs.map → open-BlCyswse.mjs.map} +1 -1
- package/build/pinned.mjs +1 -1
- package/build/{reaction-Cqeo5kNs.mjs → reaction-CGDzx3sJ.mjs} +1 -1
- package/build/{reaction-Cqeo5kNs.mjs.map → reaction-CGDzx3sJ.mjs.map} +1 -1
- package/build/{recipe-BbavaUG2.mjs → recipe-lfg0UUxc.mjs} +3 -3
- package/build/{recipe-BbavaUG2.mjs.map → recipe-lfg0UUxc.mjs.map} +1 -1
- package/build/{recipe-product-CpQl83YU.mjs → recipe-product-pLJuBblR.mjs} +4 -4
- package/build/{recipe-product-CpQl83YU.mjs.map → recipe-product-pLJuBblR.mjs.map} +1 -1
- package/build/{render-B0NrFDkJ.mjs → render-DF3qFn1u.mjs} +1 -1
- package/build/{render-B0NrFDkJ.mjs.map → render-DF3qFn1u.mjs.map} +1 -1
- package/build/{runtime-tMl2now7.mjs → runtime-DjchTCwx.mjs} +13 -13
- package/build/{runtime-tMl2now7.mjs.map → runtime-DjchTCwx.mjs.map} +1 -1
- package/build/{transformers-Cb-KaPge.mjs → transformers-aT7aCYft.mjs} +1 -1
- package/build/{transformers-Cb-KaPge.mjs.map → transformers-aT7aCYft.mjs.map} +1 -1
- package/build/{version-B1sAEHHw.mjs → version-Hnv1EkvR.mjs} +2 -2
- package/build/{version-B1sAEHHw.mjs.map → version-Hnv1EkvR.mjs.map} +1 -1
- package/build/{wacz-ZXgVsmzT.mjs → wacz-B2ujEnnX.mjs} +4 -4
- package/build/{wacz-ZXgVsmzT.mjs.map → wacz-B2ujEnnX.mjs.map} +1 -1
- package/build/{warc-6l_5qZF-.mjs → warc-NkPLiB_Y.mjs} +11 -11
- package/build/{warc-6l_5qZF-.mjs.map → warc-NkPLiB_Y.mjs.map} +1 -1
- package/build/{webbotauth-DbiWmibz.mjs → webbotauth-kOH80wBp.mjs} +1 -1
- package/build/{webbotauth-DbiWmibz.mjs.map → webbotauth-kOH80wBp.mjs.map} +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1312,6 +1312,28 @@ if (polled.changed) {
|
|
|
1312
1312
|
- **The validator memo of the crawler.** Some hosts give an `ETag` that changes at each answer. With a store of the scheduler that keeps the validator memo, the poll then sends only `If-Modified-Since`, as the crawler does.
|
|
1313
1313
|
- **One store for one set of headers.** A store keeps one entry for each URL. Give a second store to a request with a different `accept` header.
|
|
1314
1314
|
|
|
1315
|
+
#### Keep the replies of a poll
|
|
1316
|
+
|
|
1317
|
+
A 304 has no body. A client that reads each body into many values keeps those values until the next changed body, so its memory grows with the data. `keptReplies` keeps the last full reply of each URL instead, with its body as compressed bytes. At a 304, the client reads the reply again.
|
|
1318
|
+
|
|
1319
|
+
```ts
|
|
1320
|
+
import { keptReplies, poll } from "polite-crawler/api";
|
|
1321
|
+
|
|
1322
|
+
const replies = keptReplies<{ fetched: number }>();
|
|
1323
|
+
const polled = await poll(pace, transport, conditions, input);
|
|
1324
|
+
if (polled.reply.status === 304) {
|
|
1325
|
+
const kept = await replies.get(input.exchange.url);
|
|
1326
|
+
// read kept.reply.body again, with kept.extra.fetched
|
|
1327
|
+
} else {
|
|
1328
|
+
replies.keep(input.exchange.url, polled.reply, { fetched: Date.now() });
|
|
1329
|
+
}
|
|
1330
|
+
```
|
|
1331
|
+
|
|
1332
|
+
- **The value of the client.** Each reply keeps a value of the client, for example the time of the fetch. Thus a new read gives the same result.
|
|
1333
|
+
- **Only the text gets the compression.** A reply with `bytes` keeps its bytes as they are.
|
|
1334
|
+
- **A failure gives no reply.** A failed compression or expansion rejects the `get`. Then the client has no earlier full answer: delete the condition of the URL, and the next poll asks for the full answer.
|
|
1335
|
+
- **One run only.** The store is in memory. `keptStore` keeps answers between two runs.
|
|
1336
|
+
|
|
1315
1337
|
### Keep the answers of an API
|
|
1316
1338
|
|
|
1317
1339
|
`poll` tells only if the data changed. A client that needs the data at each request uses `keptFetch`. It keeps the last full answer of each GET with its body. The next GET of the same URL sends the validators. A 304 then gives the kept answer: the status, the body and the kept headers, with the new fields of the 304. Some APIs do not count a 304 in the rate limit, for example the REST API of GitHub. A run that reads the same files again then counts fewer requests.
|
package/build/api.d.mts
CHANGED
|
@@ -209,6 +209,37 @@ export declare const isApiError: (value: unknown) => value is ApiError;
|
|
|
209
209
|
* @beta
|
|
210
210
|
*/
|
|
211
211
|
export declare function freshUntil(header: (name: string) => string | undefined, status: number, fetchedAt: number, lastModified: string | undefined, capMs: number): number | undefined;
|
|
212
|
+
/**
|
|
213
|
+
* One reply of a store of kept replies, with the value that the caller kept with it.
|
|
214
|
+
*
|
|
215
|
+
* @beta
|
|
216
|
+
*/
|
|
217
|
+
interface KeptReply<Extra> {
|
|
218
|
+
/** This value is the reply, with its body. */
|
|
219
|
+
readonly reply: Reply;
|
|
220
|
+
/** This value is the value that the caller kept with the reply. */
|
|
221
|
+
readonly extra: Extra;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* A store of the last full reply of each URL.
|
|
225
|
+
*
|
|
226
|
+
* @beta
|
|
227
|
+
*/
|
|
228
|
+
interface KeptReplies<Extra> {
|
|
229
|
+
/** This method keeps the full reply of a URL in place of the last one. */
|
|
230
|
+
keep(url: string, reply: Reply, extra: Extra): void;
|
|
231
|
+
/** This method gives the last full reply of a URL, or `undefined` when the store has none. */
|
|
232
|
+
get(url: string): Promise<KeptReply<Extra> | undefined>;
|
|
233
|
+
/** This method removes the reply of a URL. */
|
|
234
|
+
delete(url: string): void;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* This function makes a store of the last full reply of each URL of a poll, with each text body
|
|
238
|
+
* as compressed bytes. The store is in memory.
|
|
239
|
+
*
|
|
240
|
+
* @beta
|
|
241
|
+
*/
|
|
242
|
+
export declare function keptReplies<Extra>(): KeptReplies<Extra>;
|
|
212
243
|
/**
|
|
213
244
|
* The name and the version of the sealed format. It is the first line of the sealed bytes.
|
|
214
245
|
*
|
|
@@ -916,4 +947,4 @@ export interface Polled extends Answer {
|
|
|
916
947
|
* @beta
|
|
917
948
|
*/
|
|
918
949
|
export declare function poll<S extends Signal = AbortSignal>(pace: Pace<S>, transport: Transport<S>, conditions: Conditions, input: Send, signal?: S): Promise<Polled>;
|
|
919
|
-
export type { Classified, HostCounts, HostReaction, HostResult, HostStateStore, HostStop, KeepOptions, Kept, KeptAnswer, KeptMemory, KeptStore, OpenedKept, Outcome, OutcomeFacts, Paced, PolicyOptions, PolitenessPolicy, Quota, QuotaGate, QuotaGateOptions, QuotaHeaders, QuotaReading, QuotaRecord, QuotaState, QuotaStore, QuotaWindow, ReactionContext, SealOptions, ValidatorAnswer, ValidatorMemo, ValidatorReport, ValidatorVerdict, WithQuotaOptions };
|
|
950
|
+
export type { Classified, HostCounts, HostReaction, HostResult, HostStateStore, HostStop, KeepOptions, Kept, KeptAnswer, KeptMemory, KeptReplies, KeptReply, KeptStore, OpenedKept, Outcome, OutcomeFacts, Paced, PolicyOptions, PolitenessPolicy, Quota, QuotaGate, QuotaGateOptions, QuotaHeaders, QuotaReading, QuotaRecord, QuotaState, QuotaStore, QuotaWindow, ReactionContext, SealOptions, ValidatorAnswer, ValidatorMemo, ValidatorReport, ValidatorVerdict, WithQuotaOptions };
|
package/build/api.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { classify, parseRetryAfter } from "./classify.mjs";
|
|
2
2
|
import { policyFor, restAfter, validatorsToSend } from "./politeness.mjs";
|
|
3
|
-
import { i as freshUntil, n as reactToOutcome, t as outcomeResult } from "./reaction-
|
|
3
|
+
import { i as freshUntil, n as reactToOutcome, t as outcomeResult } from "./reaction-CGDzx3sJ.mjs";
|
|
4
4
|
import { keyedQuota, quotaProblems, takeQuotas } from "@mark1russell7/service/limiter";
|
|
5
5
|
// src/api-error.ts
|
|
6
6
|
/**
|
|
@@ -563,6 +563,50 @@ function readKept(data) {
|
|
|
563
563
|
}
|
|
564
564
|
return out;
|
|
565
565
|
}
|
|
566
|
+
// src/kept-replies.ts
|
|
567
|
+
/** This function gives the compressed bytes of a text. */
|
|
568
|
+
const deflate = async (text) => {
|
|
569
|
+
const stream = new Blob([text]).stream().pipeThrough(new CompressionStream("deflate-raw"));
|
|
570
|
+
return new Uint8Array(await new Response(stream).arrayBuffer());
|
|
571
|
+
};
|
|
572
|
+
/** This function gives the text of compressed bytes. */
|
|
573
|
+
const inflate = async (bytes) => new Response(new Blob([bytes]).stream().pipeThrough(new DecompressionStream("deflate-raw"))).text();
|
|
574
|
+
/**
|
|
575
|
+
* This function makes a store of the last full reply of each URL of a poll, with each text body
|
|
576
|
+
* as compressed bytes. The store is in memory.
|
|
577
|
+
*
|
|
578
|
+
* @beta
|
|
579
|
+
*/
|
|
580
|
+
function keptReplies() {
|
|
581
|
+
const entries = /* @__PURE__ */ new Map();
|
|
582
|
+
return {
|
|
583
|
+
keep(url, reply, extra) {
|
|
584
|
+
const { body, ...rest } = reply;
|
|
585
|
+
const entry = {
|
|
586
|
+
reply: rest,
|
|
587
|
+
body: deflate(body),
|
|
588
|
+
extra
|
|
589
|
+
};
|
|
590
|
+
entry.body.catch(() => void 0);
|
|
591
|
+
entries.set(url, entry);
|
|
592
|
+
},
|
|
593
|
+
async get(url) {
|
|
594
|
+
const entry = entries.get(url);
|
|
595
|
+
if (entry === void 0) return void 0;
|
|
596
|
+
const body = await inflate(await entry.body);
|
|
597
|
+
return {
|
|
598
|
+
reply: {
|
|
599
|
+
...entry.reply,
|
|
600
|
+
body
|
|
601
|
+
},
|
|
602
|
+
extra: entry.extra
|
|
603
|
+
};
|
|
604
|
+
},
|
|
605
|
+
delete(url) {
|
|
606
|
+
entries.delete(url);
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
}
|
|
566
610
|
// src/kept-seal.ts
|
|
567
611
|
/**
|
|
568
612
|
* The sealed form of a store of kept answers. Use it for a place that other people can read, for
|
|
@@ -738,6 +782,8 @@ async function openKept(sealed, secret, options = {}) {
|
|
|
738
782
|
* `keepAnswer` keep the last full answer of a GET with its body, so a 304 gives the kept answer. The
|
|
739
783
|
* client decides where the store is: a store is data. Each export is beta: a minor version can
|
|
740
784
|
* change it.
|
|
785
|
+
*
|
|
786
|
+
* `keptReplies` keeps the last full reply of each URL of a poll, with the body compressed.
|
|
741
787
|
*/
|
|
742
788
|
const unchanged = (text) => text;
|
|
743
789
|
const messageOf = (error) => error instanceof Error ? error.message : String(error);
|
|
@@ -1116,6 +1162,6 @@ async function poll(pace, transport, conditions, input, signal) {
|
|
|
1116
1162
|
changed
|
|
1117
1163
|
};
|
|
1118
1164
|
}
|
|
1119
|
-
export { API_TIMEOUT_MS, ApiError, KEPT_BODY_MAX, KEPT_HEADERS, KEPT_SEAL_FORMAT, KEPT_SEAL_SECRET_MIN, KEPT_STATUSES, QuotaError, TOKEN_MARGIN_MS, fetchTransport, freshUntil, hasValidator, isApiError, isQuotaError, isTextType, keepAnswer, keptFetch, keptKey, keptRequestHeaders, keptStore, memoryQuotaStore, openKept, outcomeResult, poll, quotaGate, reactToOutcome, readGrant, readKept, readQuotaHeaders, sealKept, send, sendWithToken, statusLine, tokenStore, withQuota };
|
|
1165
|
+
export { API_TIMEOUT_MS, ApiError, KEPT_BODY_MAX, KEPT_HEADERS, KEPT_SEAL_FORMAT, KEPT_SEAL_SECRET_MIN, KEPT_STATUSES, QuotaError, TOKEN_MARGIN_MS, fetchTransport, freshUntil, hasValidator, isApiError, isQuotaError, isTextType, keepAnswer, keptFetch, keptKey, keptReplies, keptRequestHeaders, keptStore, memoryQuotaStore, openKept, outcomeResult, poll, quotaGate, reactToOutcome, readGrant, readKept, readQuotaHeaders, sealKept, send, sendWithToken, statusLine, tokenStore, withQuota };
|
|
1120
1166
|
|
|
1121
1167
|
//# sourceMappingURL=api.mjs.map
|