@crawlee/memory-storage 4.0.0-beta.65 → 4.0.0-beta.67

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 (80) hide show
  1. package/consts.d.ts +0 -12
  2. package/consts.d.ts.map +1 -1
  3. package/consts.js +0 -13
  4. package/consts.js.map +1 -1
  5. package/memory-storage.d.ts +16 -36
  6. package/memory-storage.d.ts.map +1 -1
  7. package/memory-storage.js +59 -239
  8. package/memory-storage.js.map +1 -1
  9. package/package.json +3 -6
  10. package/resource-clients/common/base-client.d.ts +0 -3
  11. package/resource-clients/common/base-client.d.ts.map +1 -1
  12. package/resource-clients/common/base-client.js +0 -6
  13. package/resource-clients/common/base-client.js.map +1 -1
  14. package/resource-clients/dataset.d.ts +9 -11
  15. package/resource-clients/dataset.d.ts.map +1 -1
  16. package/resource-clients/dataset.js +8 -42
  17. package/resource-clients/dataset.js.map +1 -1
  18. package/resource-clients/key-value-store.d.ts +18 -15
  19. package/resource-clients/key-value-store.d.ts.map +1 -1
  20. package/resource-clients/key-value-store.js +31 -47
  21. package/resource-clients/key-value-store.js.map +1 -1
  22. package/resource-clients/request-queue.d.ts +50 -20
  23. package/resource-clients/request-queue.d.ts.map +1 -1
  24. package/resource-clients/request-queue.js +251 -281
  25. package/resource-clients/request-queue.js.map +1 -1
  26. package/utils.d.ts +0 -14
  27. package/utils.d.ts.map +1 -1
  28. package/utils.js.map +1 -1
  29. package/background-handler/fs-utils.d.ts +0 -6
  30. package/background-handler/fs-utils.d.ts.map +0 -1
  31. package/background-handler/fs-utils.js +0 -63
  32. package/background-handler/fs-utils.js.map +0 -1
  33. package/background-handler/index.d.ts +0 -13
  34. package/background-handler/index.d.ts.map +0 -1
  35. package/background-handler/index.js +0 -29
  36. package/background-handler/index.js.map +0 -1
  37. package/cache-helpers.d.ts +0 -9
  38. package/cache-helpers.d.ts.map +0 -1
  39. package/cache-helpers.js +0 -319
  40. package/cache-helpers.js.map +0 -1
  41. package/fs/common.d.ts +0 -6
  42. package/fs/common.d.ts.map +0 -1
  43. package/fs/common.js +0 -2
  44. package/fs/common.js.map +0 -1
  45. package/fs/dataset/fs.d.ts +0 -11
  46. package/fs/dataset/fs.d.ts.map +0 -1
  47. package/fs/dataset/fs.js +0 -37
  48. package/fs/dataset/fs.js.map +0 -1
  49. package/fs/dataset/index.d.ts +0 -10
  50. package/fs/dataset/index.d.ts.map +0 -1
  51. package/fs/dataset/index.js +0 -9
  52. package/fs/dataset/index.js.map +0 -1
  53. package/fs/dataset/memory.d.ts +0 -8
  54. package/fs/dataset/memory.d.ts.map +0 -1
  55. package/fs/dataset/memory.js +0 -13
  56. package/fs/dataset/memory.js.map +0 -1
  57. package/fs/key-value-store/fs.d.ts +0 -17
  58. package/fs/key-value-store/fs.d.ts.map +0 -1
  59. package/fs/key-value-store/fs.js +0 -83
  60. package/fs/key-value-store/fs.js.map +0 -1
  61. package/fs/key-value-store/index.d.ts +0 -11
  62. package/fs/key-value-store/index.d.ts.map +0 -1
  63. package/fs/key-value-store/index.js +0 -9
  64. package/fs/key-value-store/index.js.map +0 -1
  65. package/fs/key-value-store/memory.d.ts +0 -9
  66. package/fs/key-value-store/memory.d.ts.map +0 -1
  67. package/fs/key-value-store/memory.js +0 -13
  68. package/fs/key-value-store/memory.js.map +0 -1
  69. package/fs/request-queue/fs.d.ts +0 -21
  70. package/fs/request-queue/fs.d.ts.map +0 -1
  71. package/fs/request-queue/fs.js +0 -72
  72. package/fs/request-queue/fs.js.map +0 -1
  73. package/fs/request-queue/index.d.ts +0 -9
  74. package/fs/request-queue/index.d.ts.map +0 -1
  75. package/fs/request-queue/index.js +0 -9
  76. package/fs/request-queue/index.js.map +0 -1
  77. package/fs/request-queue/memory.d.ts +0 -10
  78. package/fs/request-queue/memory.d.ts.map +0 -1
  79. package/fs/request-queue/memory.js +0 -15
  80. package/fs/request-queue/memory.js.map +0 -1
package/fs/dataset/fs.js DELETED
@@ -1,37 +0,0 @@
1
- import { readFile, rm } from 'node:fs/promises';
2
- import { dirname, resolve } from 'node:path';
3
- import { AsyncQueue } from '@sapphire/async-queue';
4
- import { ensureDir } from 'fs-extra/esm';
5
- import { lockAndWrite } from '../../background-handler/fs-utils.js';
6
- export class DatasetFileSystemEntry {
7
- filePath;
8
- fsQueue = new AsyncQueue();
9
- constructor(options) {
10
- this.filePath = resolve(options.storeDirectory, `${options.entityId}.json`);
11
- }
12
- async get() {
13
- await this.fsQueue.wait();
14
- try {
15
- return JSON.parse(await readFile(this.filePath, 'utf-8'));
16
- }
17
- finally {
18
- this.fsQueue.shift();
19
- }
20
- }
21
- async update(data) {
22
- await this.fsQueue.wait();
23
- try {
24
- await ensureDir(dirname(this.filePath));
25
- await lockAndWrite(this.filePath, data);
26
- }
27
- finally {
28
- this.fsQueue.shift();
29
- }
30
- }
31
- async delete() {
32
- await this.fsQueue.wait();
33
- await rm(this.filePath, { force: true });
34
- this.fsQueue.shift();
35
- }
36
- }
37
- //# sourceMappingURL=fs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fs.js","sourceRoot":"","sources":["../../../src/fs/dataset/fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AAIpE,MAAM,OAAO,sBAAsB;IACvB,QAAQ,CAAS;IACjB,OAAO,GAAG,IAAI,UAAU,EAAE,CAAC;IAEnC,YAAY,OAA2C;QACnD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,cAAc,EAAE,GAAG,OAAO,CAAC,QAAQ,OAAO,CAAC,CAAC;IAChF,CAAC;IAED,KAAK,CAAC,GAAG;QACL,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAC1B,IAAI,CAAC;YACD,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;QAC9D,CAAC;gBAAS,CAAC;YACP,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACzB,CAAC;IACL,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAAU;QACnB,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAC1B,IAAI,CAAC;YACD,MAAM,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;YACxC,MAAM,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC5C,CAAC;gBAAS,CAAC;YACP,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACzB,CAAC;IACL,CAAC;IAED,KAAK,CAAC,MAAM;QACR,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAC1B,MAAM,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACzC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;CACJ"}
@@ -1,10 +0,0 @@
1
- import type { Dictionary } from '@crawlee/types';
2
- import type { StorageImplementation } from '../common.js';
3
- export declare function createDatasetStorageImplementation<Data extends Dictionary>(options: CreateStorageImplementationOptions): StorageImplementation<Data>;
4
- export interface CreateStorageImplementationOptions {
5
- persistStorage: boolean;
6
- storeDirectory: string;
7
- /** The actual id of the file to save */
8
- entityId: string;
9
- }
10
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fs/dataset/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAI1D,wBAAgB,kCAAkC,CAAC,IAAI,SAAS,UAAU,EACtE,OAAO,EAAE,kCAAkC,GAC5C,qBAAqB,CAAC,IAAI,CAAC,CAM7B;AAED,MAAM,WAAW,kCAAkC;IAC/C,cAAc,EAAE,OAAO,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,wCAAwC;IACxC,QAAQ,EAAE,MAAM,CAAC;CACpB"}
@@ -1,9 +0,0 @@
1
- import { DatasetFileSystemEntry } from './fs.js';
2
- import { DatasetMemoryEntry } from './memory.js';
3
- export function createDatasetStorageImplementation(options) {
4
- if (options.persistStorage) {
5
- return new DatasetFileSystemEntry(options);
6
- }
7
- return new DatasetMemoryEntry();
8
- }
9
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/fs/dataset/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,UAAU,kCAAkC,CAC9C,OAA2C;IAE3C,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;QACzB,OAAO,IAAI,sBAAsB,CAAO,OAAO,CAAC,CAAC;IACrD,CAAC;IAED,OAAO,IAAI,kBAAkB,EAAQ,CAAC;AAC1C,CAAC"}
@@ -1,8 +0,0 @@
1
- import type { StorageImplementation } from '../common.js';
2
- export declare class DatasetMemoryEntry<Data> implements StorageImplementation<Data> {
3
- private data;
4
- get(): Promise<Data>;
5
- update(data: Data): void;
6
- delete(): void;
7
- }
8
- //# sourceMappingURL=memory.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/fs/dataset/memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAE1D,qBAAa,kBAAkB,CAAC,IAAI,CAAE,YAAW,qBAAqB,CAAC,IAAI,CAAC;IACxE,OAAO,CAAC,IAAI,CAAQ;IAEd,GAAG;IAIT,MAAM,CAAC,IAAI,EAAE,IAAI;IAIjB,MAAM;CAGT"}
@@ -1,13 +0,0 @@
1
- export class DatasetMemoryEntry {
2
- data;
3
- async get() {
4
- return this.data;
5
- }
6
- update(data) {
7
- this.data = data;
8
- }
9
- delete() {
10
- // No-op
11
- }
12
- }
13
- //# sourceMappingURL=memory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"memory.js","sourceRoot":"","sources":["../../../src/fs/dataset/memory.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,kBAAkB;IACnB,IAAI,CAAQ;IAEpB,KAAK,CAAC,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAED,MAAM,CAAC,IAAU;QACb,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;IAED,MAAM;QACF,QAAQ;IACZ,CAAC;CACJ"}
@@ -1,17 +0,0 @@
1
- import type { InternalKeyRecord } from '../../resource-clients/key-value-store.js';
2
- import type { StorageImplementation } from '../common.js';
3
- import type { CreateStorageImplementationOptions } from './index.js';
4
- export declare class KeyValueFileSystemEntry implements StorageImplementation<InternalKeyRecord> {
5
- private storeDirectory;
6
- private writeMetadata;
7
- private logger?;
8
- private filePath;
9
- private fileMetadataPath;
10
- private rawRecord;
11
- private fsQueue;
12
- constructor(options: CreateStorageImplementationOptions);
13
- get(): Promise<InternalKeyRecord>;
14
- update(data: InternalKeyRecord): Promise<void>;
15
- delete(): Promise<void>;
16
- }
17
- //# sourceMappingURL=fs.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../../src/fs/key-value-store/fs.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AACnF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,YAAY,CAAC;AAErE,qBAAa,uBAAwB,YAAW,qBAAqB,CAAC,iBAAiB,CAAC;IACpF,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,aAAa,CAAU;IAC/B,OAAO,CAAC,MAAM,CAAC,CAAgB;IAE/B,OAAO,CAAC,QAAQ,CAAU;IAC1B,OAAO,CAAC,gBAAgB,CAAU;IAClC,OAAO,CAAC,SAAS,CAAoC;IACrD,OAAO,CAAC,OAAO,CAAoB;gBAEvB,OAAO,EAAE,kCAAkC;IAMjD,GAAG,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAoCjC,MAAM,CAAC,IAAI,EAAE,iBAAiB;IA2B9B,MAAM;CAMf"}
@@ -1,83 +0,0 @@
1
- import { readFile, rm } from 'node:fs/promises';
2
- import { dirname, resolve } from 'node:path';
3
- import { basename } from 'node:path/win32';
4
- import { AsyncQueue } from '@sapphire/async-queue';
5
- import { ensureDir } from 'fs-extra/esm';
6
- import mime from 'mime-types';
7
- import { lockAndWrite } from '../../background-handler/fs-utils.js';
8
- export class KeyValueFileSystemEntry {
9
- storeDirectory;
10
- writeMetadata;
11
- logger;
12
- filePath;
13
- fileMetadataPath;
14
- rawRecord;
15
- fsQueue = new AsyncQueue();
16
- constructor(options) {
17
- this.storeDirectory = options.storeDirectory;
18
- this.writeMetadata = options.writeMetadata;
19
- this.logger = options.logger;
20
- }
21
- async get() {
22
- await this.fsQueue.wait();
23
- let file;
24
- try {
25
- file = await readFile(this.filePath);
26
- }
27
- catch {
28
- try {
29
- const noExtFilePath = resolve(this.storeDirectory, this.rawRecord.key);
30
- // Try without extension
31
- file = await readFile(noExtFilePath);
32
- this.logger?.warning([
33
- `Key-value entry "${this.rawRecord.key}" for store ${basename(this.storeDirectory)} does not have a file extension, assuming it as text.`,
34
- 'If you want to have correct interpretation of the file, you should add a file extension to the entry.',
35
- ].join('\n'));
36
- file = file.toString('utf-8');
37
- this.filePath = noExtFilePath;
38
- }
39
- catch {
40
- // This is impossible to happen, but just in case
41
- throw new Error(`Could not find file at ${this.filePath}`);
42
- }
43
- }
44
- finally {
45
- this.fsQueue.shift();
46
- }
47
- return {
48
- ...this.rawRecord,
49
- value: file,
50
- filePath: this.filePath,
51
- };
52
- }
53
- async update(data) {
54
- await this.fsQueue.wait();
55
- const contentType = mime.contentType(data.key);
56
- const fileName =
57
- // the content type might include charset, e.g. `text/html; charset=utf-8`, so we check via `startsWith` instead of `===`
58
- contentType && data.contentType && contentType.startsWith(data.contentType)
59
- ? data.key
60
- : `${data.key}.${data.extension}`;
61
- this.filePath ??= resolve(this.storeDirectory, fileName);
62
- this.fileMetadataPath ??= resolve(this.storeDirectory, `${data.key}.__metadata__.json`);
63
- const { value, ...rest } = data;
64
- this.rawRecord = rest;
65
- try {
66
- await ensureDir(dirname(this.filePath));
67
- await lockAndWrite(this.filePath, value, false);
68
- if (this.writeMetadata) {
69
- await lockAndWrite(this.fileMetadataPath, JSON.stringify(rest), true);
70
- }
71
- }
72
- finally {
73
- this.fsQueue.shift();
74
- }
75
- }
76
- async delete() {
77
- await this.fsQueue.wait();
78
- await rm(this.filePath, { force: true });
79
- await rm(this.fileMetadataPath, { force: true });
80
- this.fsQueue.shift();
81
- }
82
- }
83
- //# sourceMappingURL=fs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fs.js","sourceRoot":"","sources":["../../../src/fs/key-value-store/fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAG3C,OAAO,EAAE,UAAU,EAAE,MAAM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EAAE,KAAK,CAAC,CAAC;YAEhD,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;gBACrB,MAAM,YAAY,CAAC,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;YAC1E,CAAC;QACL,CAAC;gBAAS,CAAC;YACP,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACzB,CAAC;IACL,CAAC;IAED,KAAK,CAAC,MAAM;QACR,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAC1B,MAAM,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACzC,MAAM,EAAE,CAAC,IAAI,CAAC,gBAAgB,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACjD,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;CACJ"}
@@ -1,11 +0,0 @@
1
- import type { CrawleeLogger } from '@crawlee/types';
2
- import type { InternalKeyRecord } from '../../resource-clients/key-value-store.js';
3
- import type { StorageImplementation } from '../common.js';
4
- export declare function createKeyValueStorageImplementation(options: CreateStorageImplementationOptions): StorageImplementation<InternalKeyRecord>;
5
- export interface CreateStorageImplementationOptions {
6
- persistStorage: boolean;
7
- storeDirectory: string;
8
- writeMetadata: boolean;
9
- logger?: CrawleeLogger;
10
- }
11
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fs/key-value-store/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AACnF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAI1D,wBAAgB,mCAAmC,CAC/C,OAAO,EAAE,kCAAkC,GAC5C,qBAAqB,CAAC,iBAAiB,CAAC,CAM1C;AAED,MAAM,WAAW,kCAAkC;IAC/C,cAAc,EAAE,OAAO,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,OAAO,CAAC;IACvB,MAAM,CAAC,EAAE,aAAa,CAAC;CAC1B"}
@@ -1,9 +0,0 @@
1
- import { KeyValueFileSystemEntry } from './fs.js';
2
- import { KeyValueMemoryEntry } from './memory.js';
3
- export function createKeyValueStorageImplementation(options) {
4
- if (options.persistStorage) {
5
- return new KeyValueFileSystemEntry(options);
6
- }
7
- return new KeyValueMemoryEntry();
8
- }
9
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/fs/key-value-store/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,MAAM,UAAU,mCAAmC,CAC/C,OAA2C;IAE3C,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;QACzB,OAAO,IAAI,uBAAuB,CAAC,OAAO,CAAC,CAAC;IAChD,CAAC;IAED,OAAO,IAAI,mBAAmB,EAAE,CAAC;AACrC,CAAC"}
@@ -1,9 +0,0 @@
1
- import type { InternalKeyRecord } from '../../resource-clients/key-value-store.js';
2
- import type { StorageImplementation } from '../common.js';
3
- export declare class KeyValueMemoryEntry implements StorageImplementation<InternalKeyRecord> {
4
- private data;
5
- get(): Promise<InternalKeyRecord>;
6
- update(data: InternalKeyRecord): void;
7
- delete(): void;
8
- }
9
- //# sourceMappingURL=memory.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/fs/key-value-store/memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AACnF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAE1D,qBAAa,mBAAoB,YAAW,qBAAqB,CAAC,iBAAiB,CAAC;IAChF,OAAO,CAAC,IAAI,CAAqB;IAE3B,GAAG;IAIT,MAAM,CAAC,IAAI,EAAE,iBAAiB;IAI9B,MAAM;CAGT"}
@@ -1,13 +0,0 @@
1
- export class KeyValueMemoryEntry {
2
- data;
3
- async get() {
4
- return this.data;
5
- }
6
- update(data) {
7
- this.data = data;
8
- }
9
- delete() {
10
- // No-op
11
- }
12
- }
13
- //# sourceMappingURL=memory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"memory.js","sourceRoot":"","sources":["../../../src/fs/key-value-store/memory.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,mBAAmB;IACpB,IAAI,CAAqB;IAEjC,KAAK,CAAC,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAED,MAAM,CAAC,IAAuB;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;IAED,MAAM;QACF,QAAQ;IACZ,CAAC;CACJ"}
@@ -1,21 +0,0 @@
1
- import type { InternalRequest } from '../../resource-clients/request-queue.js';
2
- import type { StorageImplementation } from '../common.js';
3
- import type { CreateStorageImplementationOptions } from './index.js';
4
- export declare class RequestQueueFileSystemEntry implements StorageImplementation<InternalRequest> {
5
- private filePath;
6
- private fsQueue;
7
- private data?;
8
- private directoryExists;
9
- /**
10
- * A "sweep" timeout that is created/refreshed whenever this entry is accessed/updated.
11
- * It exists to ensure that the entry is not kept in memory indefinitely, by sweeping it after 60 seconds of inactivity (in order to keep memory usage low)
12
- */
13
- private sweepTimeout?;
14
- orderNo?: number | null;
15
- constructor(options: CreateStorageImplementationOptions);
16
- get(force?: boolean): Promise<any>;
17
- update(data: InternalRequest): Promise<void>;
18
- delete(): Promise<void>;
19
- private setOrRefreshSweepTimeout;
20
- }
21
- //# sourceMappingURL=fs.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../../src/fs/request-queue/fs.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,YAAY,CAAC;AAErE,qBAAa,2BAA4B,YAAW,qBAAqB,CAAC,eAAe,CAAC;IACtF,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,IAAI,CAAC,CAAkB;IAC/B,OAAO,CAAC,eAAe,CAAS;IAEhC;;;OAGG;IACH,OAAO,CAAC,YAAY,CAAC,CAAiB;IAE/B,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;gBAEnB,OAAO,EAAE,kCAAkC;IAIjD,GAAG,CAAC,KAAK,UAAQ;IAuBjB,MAAM,CAAC,IAAI,EAAE,eAAe;IAmB5B,MAAM;IAMZ,OAAO,CAAC,wBAAwB;CAUnC"}
@@ -1,72 +0,0 @@
1
- import { readFile, rm } from 'node:fs/promises';
2
- import { dirname, resolve } from 'node:path';
3
- import { AsyncQueue } from '@sapphire/async-queue';
4
- import { ensureDir } from 'fs-extra/esm';
5
- import { lockAndCallback, lockAndWrite } from '../../background-handler/fs-utils.js';
6
- export class RequestQueueFileSystemEntry {
7
- filePath;
8
- fsQueue = new AsyncQueue();
9
- data;
10
- directoryExists = false;
11
- /**
12
- * A "sweep" timeout that is created/refreshed whenever this entry is accessed/updated.
13
- * It exists to ensure that the entry is not kept in memory indefinitely, by sweeping it after 60 seconds of inactivity (in order to keep memory usage low)
14
- */
15
- sweepTimeout;
16
- orderNo;
17
- constructor(options) {
18
- this.filePath = resolve(options.storeDirectory, `${options.requestId}.json`);
19
- }
20
- async get(force = false) {
21
- await this.fsQueue.wait();
22
- this.setOrRefreshSweepTimeout();
23
- if (this.data && !force) {
24
- this.fsQueue.shift();
25
- return this.data;
26
- }
27
- try {
28
- return await lockAndCallback(this.filePath, async () => {
29
- const req = JSON.parse(await readFile(this.filePath, 'utf-8'));
30
- this.data = req;
31
- this.orderNo = req.orderNo;
32
- return req;
33
- });
34
- }
35
- finally {
36
- this.fsQueue.shift();
37
- }
38
- }
39
- async update(data) {
40
- await this.fsQueue.wait();
41
- this.data = data;
42
- try {
43
- if (!this.directoryExists) {
44
- await ensureDir(dirname(this.filePath));
45
- this.directoryExists = true;
46
- }
47
- await lockAndWrite(this.filePath, data);
48
- this.orderNo = data.orderNo;
49
- }
50
- finally {
51
- this.setOrRefreshSweepTimeout();
52
- this.fsQueue.shift();
53
- }
54
- }
55
- async delete() {
56
- await this.fsQueue.wait();
57
- await rm(this.filePath, { force: true });
58
- this.fsQueue.shift();
59
- }
60
- setOrRefreshSweepTimeout() {
61
- if (this.sweepTimeout) {
62
- this.sweepTimeout.refresh();
63
- }
64
- else {
65
- this.sweepTimeout = setTimeout(() => {
66
- this.sweepTimeout = undefined;
67
- this.data = undefined;
68
- }, 60_000).unref();
69
- }
70
- }
71
- }
72
- //# sourceMappingURL=fs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fs.js","sourceRoot":"","sources":["../../../src/fs/request-queue/fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAC;AAKrF,MAAM,OAAO,2BAA2B;IAC5B,QAAQ,CAAS;IACjB,OAAO,GAAG,IAAI,UAAU,EAAE,CAAC;IAC3B,IAAI,C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QAAQ,CAAC,CAAC,CAAC;gBACxC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;YAChC,CAAC;YAED,MAAM,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YAExC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAChC,CAAC;gBAAS,CAAC;YACP,IAAI,CAAC,wBAAwB,EAAE,CAAC;YAChC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACzB,CAAC;IACL,CAAC;IAED,KAAK,CAAC,MAAM;QACR,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAC1B,MAAM,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACzC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;IAEO,wBAAwB;QAC5B,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACpB,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;QAChC,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,GAAG,EAAE;gBAChC,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;gBAC9B,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;YAC1B,CAAC,EAAE,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;IACL,CAAC;CACJ"}
@@ -1,9 +0,0 @@
1
- import { RequestQueueFileSystemEntry } from './fs.js';
2
- import { RequestQueueMemoryEntry } from './memory.js';
3
- export declare function createRequestQueueStorageImplementation(options: CreateStorageImplementationOptions): RequestQueueMemoryEntry | RequestQueueFileSystemEntry;
4
- export interface CreateStorageImplementationOptions {
5
- persistStorage: boolean;
6
- storeDirectory: string;
7
- requestId: string;
8
- }
9
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fs/request-queue/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,wBAAgB,uCAAuC,CAAC,OAAO,EAAE,kCAAkC,yDAMlG;AAED,MAAM,WAAW,kCAAkC;IAC/C,cAAc,EAAE,OAAO,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;CACrB"}
@@ -1,9 +0,0 @@
1
- import { RequestQueueFileSystemEntry } from './fs.js';
2
- import { RequestQueueMemoryEntry } from './memory.js';
3
- export function createRequestQueueStorageImplementation(options) {
4
- if (options.persistStorage) {
5
- return new RequestQueueFileSystemEntry(options);
6
- }
7
- return new RequestQueueMemoryEntry();
8
- }
9
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/fs/request-queue/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,MAAM,UAAU,uCAAuC,CAAC,OAA2C;IAC/F,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;QACzB,OAAO,IAAI,2BAA2B,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC;IAED,OAAO,IAAI,uBAAuB,EAAE,CAAC;AACzC,CAAC"}
@@ -1,10 +0,0 @@
1
- import type { InternalRequest } from '../../resource-clients/request-queue.js';
2
- import type { StorageImplementation } from '../common.js';
3
- export declare class RequestQueueMemoryEntry implements StorageImplementation<InternalRequest> {
4
- private data;
5
- orderNo?: number | null;
6
- get(): Promise<InternalRequest>;
7
- update(data: InternalRequest): void;
8
- delete(): void;
9
- }
10
- //# sourceMappingURL=memory.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/fs/request-queue/memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAE1D,qBAAa,uBAAwB,YAAW,qBAAqB,CAAC,eAAe,CAAC;IAClF,OAAO,CAAC,IAAI,CAAmB;IAExB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEzB,GAAG;IAIT,MAAM,CAAC,IAAI,EAAE,eAAe;IAK5B,MAAM;CAGT"}
@@ -1,15 +0,0 @@
1
- export class RequestQueueMemoryEntry {
2
- data;
3
- orderNo;
4
- async get() {
5
- return this.data;
6
- }
7
- update(data) {
8
- this.data = data;
9
- this.orderNo = data.orderNo;
10
- }
11
- delete() {
12
- // No-op
13
- }
14
- }
15
- //# sourceMappingURL=memory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"memory.js","sourceRoot":"","sources":["../../../src/fs/request-queue/memory.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,uBAAuB;IACxB,IAAI,CAAmB;IAExB,OAAO,CAAiB;IAE/B,KAAK,CAAC,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAED,MAAM,CAAC,IAAqB;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;IAChC,CAAC;IAED,MAAM;QACF,QAAQ;IACZ,CAAC;CACJ"}