@crawlee/memory-storage 3.0.0-alpha.34
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/LICENSE.md +201 -0
- package/README.md +214 -0
- package/body-parser.d.ts +13 -0
- package/body-parser.d.ts.map +1 -0
- package/body-parser.js +65 -0
- package/body-parser.js.map +1 -0
- package/consts.d.ts +17 -0
- package/consts.d.ts.map +1 -0
- package/consts.js +22 -0
- package/consts.js.map +1 -0
- package/index.d.ts +2 -0
- package/index.d.ts.map +1 -0
- package/index.js +5 -0
- package/index.js.map +1 -0
- package/index.mjs +4 -0
- package/memory-storage.d.ts +29 -0
- package/memory-storage.d.ts.map +1 -0
- package/memory-storage.js +102 -0
- package/memory-storage.js.map +1 -0
- package/package.json +60 -0
- package/resource-clients/common/base-client.d.ts +8 -0
- package/resource-clients/common/base-client.d.ts.map +1 -0
- package/resource-clients/common/base-client.js +22 -0
- package/resource-clients/common/base-client.js.map +1 -0
- package/resource-clients/dataset-collection.d.ts +14 -0
- package/resource-clients/dataset-collection.d.ts.map +1 -0
- package/resource-clients/dataset-collection.js +60 -0
- package/resource-clients/dataset-collection.js.map +1 -0
- package/resource-clients/dataset.d.ts +42 -0
- package/resource-clients/dataset.d.ts.map +1 -0
- package/resource-clients/dataset.js +235 -0
- package/resource-clients/dataset.js.map +1 -0
- package/resource-clients/key-value-store-collection.d.ts +14 -0
- package/resource-clients/key-value-store-collection.d.ts.map +1 -0
- package/resource-clients/key-value-store-collection.js +60 -0
- package/resource-clients/key-value-store-collection.js.map +1 -0
- package/resource-clients/key-value-store.d.ts +36 -0
- package/resource-clients/key-value-store.d.ts.map +1 -0
- package/resource-clients/key-value-store.js +300 -0
- package/resource-clients/key-value-store.js.map +1 -0
- package/resource-clients/request-queue-collection.d.ts +14 -0
- package/resource-clients/request-queue-collection.d.ts.map +1 -0
- package/resource-clients/request-queue-collection.js +60 -0
- package/resource-clients/request-queue-collection.js.map +1 -0
- package/resource-clients/request-queue.d.ts +48 -0
- package/resource-clients/request-queue.d.ts.map +1 -0
- package/resource-clients/request-queue.js +353 -0
- package/resource-clients/request-queue.js.map +1 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/utils.d.ts +44 -0
- package/utils.d.ts.map +1 -0
- package/utils.js +59 -0
- package/utils.js.map +1 -0
- package/workers/file-storage-worker-emulator.d.ts +5 -0
- package/workers/file-storage-worker-emulator.d.ts.map +1 -0
- package/workers/file-storage-worker-emulator.js +12 -0
- package/workers/file-storage-worker-emulator.js.map +1 -0
- package/workers/file-storage-worker.d.ts +2 -0
- package/workers/file-storage-worker.d.ts.map +1 -0
- package/workers/file-storage-worker.js +15 -0
- package/workers/file-storage-worker.js.map +1 -0
- package/workers/instance.d.ts +4 -0
- package/workers/instance.d.ts.map +1 -0
- package/workers/instance.js +35 -0
- package/workers/instance.js.map +1 -0
- package/workers/worker-utils.d.ts +9 -0
- package/workers/worker-utils.d.ts.map +1 -0
- package/workers/worker-utils.js +79 -0
- package/workers/worker-utils.js.map +1 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemoryStorage = void 0;
|
|
4
|
+
const shapeshift_1 = require("@sapphire/shapeshift");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const dataset_1 = require("./resource-clients/dataset");
|
|
7
|
+
const dataset_collection_1 = require("./resource-clients/dataset-collection");
|
|
8
|
+
const key_value_store_1 = require("./resource-clients/key-value-store");
|
|
9
|
+
const key_value_store_collection_1 = require("./resource-clients/key-value-store-collection");
|
|
10
|
+
const request_queue_1 = require("./resource-clients/request-queue");
|
|
11
|
+
const request_queue_collection_1 = require("./resource-clients/request-queue-collection");
|
|
12
|
+
const instance_1 = require("./workers/instance");
|
|
13
|
+
class MemoryStorage {
|
|
14
|
+
constructor(options = {}) {
|
|
15
|
+
Object.defineProperty(this, "localDataDirectory", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: void 0
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(this, "datasetsDirectory", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: void 0
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(this, "keyValueStoresDirectory", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true,
|
|
31
|
+
value: void 0
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(this, "requestQueuesDirectory", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true,
|
|
37
|
+
value: void 0
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(this, "keyValueStoresHandled", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
configurable: true,
|
|
42
|
+
writable: true,
|
|
43
|
+
value: []
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(this, "datasetClientsHandled", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
writable: true,
|
|
49
|
+
value: []
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(this, "requestQueuesHandled", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
configurable: true,
|
|
54
|
+
writable: true,
|
|
55
|
+
value: []
|
|
56
|
+
});
|
|
57
|
+
shapeshift_1.s.object({
|
|
58
|
+
localDataDirectory: shapeshift_1.s.string.optional,
|
|
59
|
+
}).parse(options);
|
|
60
|
+
this.localDataDirectory = options.localDataDirectory ?? process.env.CRAWLEE_STORAGE_DIR ?? './memory_storage';
|
|
61
|
+
this.datasetsDirectory = (0, node_path_1.resolve)(this.localDataDirectory, 'datasets');
|
|
62
|
+
this.keyValueStoresDirectory = (0, node_path_1.resolve)(this.localDataDirectory, 'key_value_stores');
|
|
63
|
+
this.requestQueuesDirectory = (0, node_path_1.resolve)(this.localDataDirectory, 'request_queues');
|
|
64
|
+
(0, instance_1.initWorkerIfNeeded)();
|
|
65
|
+
}
|
|
66
|
+
datasets() {
|
|
67
|
+
return new dataset_collection_1.DatasetCollectionClient({
|
|
68
|
+
baseStorageDirectory: this.datasetsDirectory,
|
|
69
|
+
client: this,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
dataset(id) {
|
|
73
|
+
shapeshift_1.s.string.parse(id);
|
|
74
|
+
return new dataset_1.DatasetClient({ id, baseStorageDirectory: this.datasetsDirectory, client: this });
|
|
75
|
+
}
|
|
76
|
+
keyValueStores() {
|
|
77
|
+
return new key_value_store_collection_1.KeyValueStoreCollectionClient({
|
|
78
|
+
baseStorageDirectory: this.keyValueStoresDirectory,
|
|
79
|
+
client: this,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
keyValueStore(id) {
|
|
83
|
+
shapeshift_1.s.string.parse(id);
|
|
84
|
+
return new key_value_store_1.KeyValueStoreClient({ id, baseStorageDirectory: this.keyValueStoresDirectory, client: this });
|
|
85
|
+
}
|
|
86
|
+
requestQueues() {
|
|
87
|
+
return new request_queue_collection_1.RequestQueueCollectionClient({
|
|
88
|
+
baseStorageDirectory: this.requestQueuesDirectory,
|
|
89
|
+
client: this,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
requestQueue(id, options = {}) {
|
|
93
|
+
shapeshift_1.s.string.parse(id);
|
|
94
|
+
shapeshift_1.s.object({
|
|
95
|
+
clientKey: shapeshift_1.s.string.optional,
|
|
96
|
+
timeoutSecs: shapeshift_1.s.number.optional,
|
|
97
|
+
}).parse(options);
|
|
98
|
+
return new request_queue_1.RequestQueueClient({ id, baseStorageDirectory: this.requestQueuesDirectory, client: this, ...options });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.MemoryStorage = MemoryStorage;
|
|
102
|
+
//# sourceMappingURL=memory-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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,uBAAa,CAAC,EAAE,EAAE,EAAE,oBAAoB,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IACjG,CAAC;IAED,cAAc;QACV,OAAO,IAAI,0DAA6B,CAAC;YACrC,oBAAoB,EAAE,IAAI,CAAC,uBAAuB;YAClD,MAAM,EAAE,IAAI;SACf,CAAC,CAAC;IACP,CAAC;IAED,aAAa,CAAC,EAAU;QACpB,cAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAEnB,OAAO,IAAI,qCAAmB,CAAC,EAAE,EAAE,EAAE,oBAAoB,EAAE,IAAI,CAAC,uBAAuB,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7G,CAAC;IAED,aAAa;QACT,OAAO,IAAI,uDAA4B,CAAC;YACpC,oBAAoB,EAAE,IAAI,CAAC,sBAAsB;YACjD,MAAM,EAAE,IAAI;SACf,CAAC,CAAC;IACP,CAAC;IAED,YAAY,CAAC,EAAU,EAAE,UAAuC,EAAE;QAC9D,cAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACnB,cAAC,CAAC,MAAM,CAAC;YACL,SAAS,EAAE,cAAC,CAAC,MAAM,CAAC,QAAQ;YAC5B,WAAW,EAAE,cAAC,CAAC,MAAM,CAAC,QAAQ;SACjC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAElB,OAAO,IAAI,kCAAkB,CAAC,EAAE,EAAE,EAAE,oBAAoB,EAAE,IAAI,CAAC,sBAAsB,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IACvH,CAAC;CACJ;AAjED,sCAiEC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@crawlee/memory-storage",
|
|
3
|
+
"version": "3.0.0-alpha.34",
|
|
4
|
+
"description": "A simple in-memory storage implementation of the Apify API",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">= 16"
|
|
7
|
+
},
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"module": "index.mjs",
|
|
10
|
+
"types": "index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./index.mjs",
|
|
14
|
+
"require": "./index.js",
|
|
15
|
+
"types": "./index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"apify",
|
|
21
|
+
"api",
|
|
22
|
+
"memory"
|
|
23
|
+
],
|
|
24
|
+
"author": {
|
|
25
|
+
"name": "Apify",
|
|
26
|
+
"email": "support@apify.com",
|
|
27
|
+
"url": "https://apify.com"
|
|
28
|
+
},
|
|
29
|
+
"contributors": [
|
|
30
|
+
"Vlad Frangu <kingdgrizzle@gmail.com>"
|
|
31
|
+
],
|
|
32
|
+
"license": "Apache-2.0",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/apify/apify-js"
|
|
36
|
+
},
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/apify/apify-js/issues"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://sdk.apify.com/",
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "npm run clean && npm run compile && npm run copy",
|
|
43
|
+
"clean": "rimraf ./dist",
|
|
44
|
+
"compile": "tsc -p tsconfig.build.json && gen-esm-wrapper ./index.js ./index.mjs",
|
|
45
|
+
"copy": "ts-node -T ../../scripts/copy.ts"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@apify/log": "^1.2.0",
|
|
52
|
+
"@crawlee/types": "^3.0.0-alpha.34",
|
|
53
|
+
"@crawlee/utils": "^3.0.0-alpha.34",
|
|
54
|
+
"@sapphire/shapeshift": "^3.0.0",
|
|
55
|
+
"content-type": "^1.0.4",
|
|
56
|
+
"fs-extra": "^10.1.0",
|
|
57
|
+
"mime-types": "^2.1.35",
|
|
58
|
+
"tslib": "^2.4.0"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { StorageTypes } from '../../consts';
|
|
2
|
+
export declare class BaseClient {
|
|
3
|
+
id: string;
|
|
4
|
+
constructor(id: string);
|
|
5
|
+
protected throwOnNonExisting(clientType: StorageTypes): never;
|
|
6
|
+
protected throwOnDuplicateEntry(clientType: StorageTypes, keyName: string, value: string): never;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=base-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-client.d.ts","sourceRoot":"","sources":["../../../src/resource-clients/common/base-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,qBAAa,UAAU;IACnB,EAAE,EAAE,MAAM,CAAC;gBAEC,EAAE,EAAE,MAAM;IAItB,SAAS,CAAC,kBAAkB,CAAC,UAAU,EAAE,YAAY,GAAG,KAAK;IAI7D,SAAS,CAAC,qBAAqB,CAAC,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK;CAGnG"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseClient = void 0;
|
|
4
|
+
class BaseClient {
|
|
5
|
+
constructor(id) {
|
|
6
|
+
Object.defineProperty(this, "id", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true,
|
|
10
|
+
value: void 0
|
|
11
|
+
});
|
|
12
|
+
this.id = id;
|
|
13
|
+
}
|
|
14
|
+
throwOnNonExisting(clientType) {
|
|
15
|
+
throw new Error(`${clientType} with id: ${this.id} does not exist.`);
|
|
16
|
+
}
|
|
17
|
+
throwOnDuplicateEntry(clientType, keyName, value) {
|
|
18
|
+
throw new Error(`${clientType} with ${keyName}: ${value} already exists.`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.BaseClient = BaseClient;
|
|
22
|
+
//# sourceMappingURL=base-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-client.js","sourceRoot":"","sources":["../../../src/resource-clients/common/base-client.ts"],"names":[],"mappings":";;;AAEA,MAAa,UAAU;IAGnB,YAAY,EAAU;QAFtB;;;;;WAAW;QAGP,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACjB,CAAC;IAES,kBAAkB,CAAC,UAAwB;QACjD,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,aAAa,IAAI,CAAC,EAAE,kBAAkB,CAAC,CAAC;IACzE,CAAC;IAES,qBAAqB,CAAC,UAAwB,EAAE,OAAe,EAAE,KAAa;QACpF,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,SAAS,OAAO,KAAK,KAAK,kBAAkB,CAAC,CAAC;IAC/E,CAAC;CACJ;AAdD,gCAcC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type * as storage from '@crawlee/types';
|
|
2
|
+
import { MemoryStorage } from '../index';
|
|
3
|
+
export interface DatasetCollectionClientOptions {
|
|
4
|
+
baseStorageDirectory: string;
|
|
5
|
+
client: MemoryStorage;
|
|
6
|
+
}
|
|
7
|
+
export declare class DatasetCollectionClient implements storage.DatasetCollectionClient {
|
|
8
|
+
private readonly datasetsDirectory;
|
|
9
|
+
private readonly client;
|
|
10
|
+
constructor({ baseStorageDirectory, client }: DatasetCollectionClientOptions);
|
|
11
|
+
list(): ReturnType<storage.DatasetCollectionClient['list']>;
|
|
12
|
+
getOrCreate(name?: string): Promise<storage.DatasetInfo>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=dataset-collection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataset-collection.d.ts","sourceRoot":"","sources":["../../src/resource-clients/dataset-collection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAG/C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAIzC,MAAM,WAAW,8BAA8B;IAC3C,oBAAoB,EAAE,MAAM,CAAC;IAC7B,MAAM,EAAE,aAAa,CAAC;CACzB;AAED,qBAAa,uBAAwB,YAAW,OAAO,CAAC,uBAAuB;IAC3E,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;gBAE3B,EAAE,oBAAoB,EAAE,MAAM,EAAE,EAAE,8BAA8B;IAKtE,IAAI,IAAI,UAAU,CAAC,OAAO,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;IAa3D,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC;CA2BjE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DatasetCollectionClient = void 0;
|
|
4
|
+
const shapeshift_1 = require("@sapphire/shapeshift");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const instance_1 = require("../workers/instance");
|
|
7
|
+
const dataset_1 = require("./dataset");
|
|
8
|
+
class DatasetCollectionClient {
|
|
9
|
+
constructor({ baseStorageDirectory, client }) {
|
|
10
|
+
Object.defineProperty(this, "datasetsDirectory", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value: void 0
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(this, "client", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true,
|
|
20
|
+
value: void 0
|
|
21
|
+
});
|
|
22
|
+
this.datasetsDirectory = (0, path_1.resolve)(baseStorageDirectory);
|
|
23
|
+
this.client = client;
|
|
24
|
+
}
|
|
25
|
+
async list() {
|
|
26
|
+
return {
|
|
27
|
+
total: this.client.datasetClientsHandled.length,
|
|
28
|
+
count: this.client.datasetClientsHandled.length,
|
|
29
|
+
offset: 0,
|
|
30
|
+
limit: this.client.datasetClientsHandled.length,
|
|
31
|
+
desc: false,
|
|
32
|
+
items: this.client.datasetClientsHandled.map((store) => store.toDatasetInfo())
|
|
33
|
+
.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime()),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
async getOrCreate(name) {
|
|
37
|
+
shapeshift_1.s.string.optional.parse(name);
|
|
38
|
+
if (name) {
|
|
39
|
+
const found = this.client.datasetClientsHandled.find((store) => store.name === name);
|
|
40
|
+
if (found) {
|
|
41
|
+
return found.toDatasetInfo();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const newStore = new dataset_1.DatasetClient({ name, baseStorageDirectory: this.datasetsDirectory, client: this.client });
|
|
45
|
+
this.client.datasetClientsHandled.push(newStore);
|
|
46
|
+
// Schedule the worker to write to the disk
|
|
47
|
+
const datasetInfo = newStore.toDatasetInfo();
|
|
48
|
+
// eslint-disable-next-line dot-notation
|
|
49
|
+
(0, instance_1.sendWorkerMessage)({
|
|
50
|
+
action: 'update-metadata',
|
|
51
|
+
entityType: 'datasets',
|
|
52
|
+
entityDirectory: newStore.datasetDirectory,
|
|
53
|
+
id: datasetInfo.name ?? datasetInfo.id,
|
|
54
|
+
data: datasetInfo,
|
|
55
|
+
});
|
|
56
|
+
return datasetInfo;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.DatasetCollectionClient = DatasetCollectionClient;
|
|
60
|
+
//# sourceMappingURL=dataset-collection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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AK,EAAE;gBACP,OAAO,KAAK,CAAC,aAAa,EAAE,CAAC;aAChC;SACJ;QAED,MAAM,QAAQ,GAAG,IAAI,uBAAa,CAAC,EAAE,IAAI,EAAE,oBAAoB,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QAChH,IAAI,CAAC,MAAM,CAAC,qBAAqB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEjD,2CAA2C;QAC3C,MAAM,WAAW,GAAG,QAAQ,CAAC,aAAa,EAAE,CAAC;QAC7C,wCAAwC;QACxC,IAAA,4BAAiB,EAAC;YACd,MAAM,EAAE,iBAAiB;YACzB,UAAU,EAAE,UAAU;YACtB,eAAe,EAAE,QAAQ,CAAC,gBAAgB;YAC1C,EAAE,EAAE,WAAW,CAAC,IAAI,IAAI,WAAW,CAAC,EAAE;YACtC,IAAI,EAAE,WAAW;SACpB,CAAC,CAAC;QAEH,OAAO,WAAW,CAAC;IACvB,CAAC;CACJ;AAjDD,0DAiDC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type * as storage from '@crawlee/types';
|
|
3
|
+
import { Dictionary } from '@crawlee/utils';
|
|
4
|
+
import { MemoryStorage } from '../index';
|
|
5
|
+
import { BaseClient } from './common/base-client';
|
|
6
|
+
export interface DatasetClientOptions {
|
|
7
|
+
id?: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
baseStorageDirectory: string;
|
|
10
|
+
client: MemoryStorage;
|
|
11
|
+
}
|
|
12
|
+
export declare class DatasetClient<Data extends Dictionary = Dictionary> extends BaseClient implements storage.DatasetClient<Data> {
|
|
13
|
+
name?: string;
|
|
14
|
+
createdAt: Date;
|
|
15
|
+
accessedAt: Date;
|
|
16
|
+
modifiedAt: Date;
|
|
17
|
+
itemCount: number;
|
|
18
|
+
datasetDirectory: string;
|
|
19
|
+
private readonly datasetEntries;
|
|
20
|
+
private readonly client;
|
|
21
|
+
constructor(options: DatasetClientOptions);
|
|
22
|
+
get(): Promise<storage.DatasetInfo | undefined>;
|
|
23
|
+
update(newFields?: storage.DatasetClientUpdateOptions): Promise<storage.DatasetInfo>;
|
|
24
|
+
delete(): Promise<void>;
|
|
25
|
+
downloadItems(): Promise<Buffer>;
|
|
26
|
+
listItems(options?: storage.DatasetClientListOptions): Promise<storage.PaginatedList<Data>>;
|
|
27
|
+
pushItems(items: string | Data | string[] | Data[]): Promise<void>;
|
|
28
|
+
toDatasetInfo(): storage.DatasetInfo;
|
|
29
|
+
private generateLocalEntryName;
|
|
30
|
+
private getStartAndEndIndexes;
|
|
31
|
+
/**
|
|
32
|
+
* To emulate API and split arrays of items into individual dataset items,
|
|
33
|
+
* we need to normalize the input items - which can be strings, objects
|
|
34
|
+
* or arrays of those - into objects, so that we can save them one by one
|
|
35
|
+
* later. We could potentially do this directly with strings, but let's
|
|
36
|
+
* not optimize prematurely.
|
|
37
|
+
*/
|
|
38
|
+
private normalizeItems;
|
|
39
|
+
private normalizeItem;
|
|
40
|
+
private updateTimestamps;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=dataset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataset.d.ts","sourceRoot":"","sources":["../../src/resource-clients/dataset.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAM5C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAelD,MAAM,WAAW,oBAAoB;IACjC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oBAAoB,EAAE,MAAM,CAAC;IAC7B,MAAM,EAAE,aAAa,CAAC;CACzB;AAED,qBAAa,aAAa,CAAC,IAAI,SAAS,UAAU,GAAG,UAAU,CAAE,SAAQ,UAAW,YAAW,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC;IACtH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,OAAc;IACvB,UAAU,OAAc;IACxB,UAAU,OAAc;IACxB,SAAS,SAAK;IACd,gBAAgB,EAAE,MAAM,CAAC;IAEzB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA2B;IAC1D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;gBAE3B,OAAO,EAAE,oBAAoB;IAOnC,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAW/C,MAAM,CAAC,SAAS,GAAE,OAAO,CAAC,0BAA+B,GAAG,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC;IAsCxF,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAYvB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAIhC,SAAS,CAAC,OAAO,GAAE,OAAO,CAAC,wBAA6B,GAAG,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAuC/F,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAqCxE,aAAa,IAAI,OAAO,CAAC,WAAW;IAWpC,OAAO,CAAC,sBAAsB;IAI9B,OAAO,CAAC,qBAAqB;IAM7B;;;;;;OAMG;IACH,OAAO,CAAC,cAAc;IAUtB,OAAO,CAAC,aAAa;IAgBrB,OAAO,CAAC,gBAAgB;CAgB3B"}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DatasetClient = void 0;
|
|
4
|
+
const shapeshift_1 = require("@sapphire/shapeshift");
|
|
5
|
+
const node_crypto_1 = require("node:crypto");
|
|
6
|
+
const promises_1 = require("node:fs/promises");
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
8
|
+
const fs_extra_1 = require("fs-extra");
|
|
9
|
+
const consts_1 = require("../consts");
|
|
10
|
+
const base_client_1 = require("./common/base-client");
|
|
11
|
+
const instance_1 = require("../workers/instance");
|
|
12
|
+
/**
|
|
13
|
+
* This is what API returns in the x-apify-pagination-limit
|
|
14
|
+
* header when no limit query parameter is used.
|
|
15
|
+
*/
|
|
16
|
+
const LIST_ITEMS_LIMIT = 999999999999;
|
|
17
|
+
/**
|
|
18
|
+
* Number of characters of the dataset item file names.
|
|
19
|
+
* E.g.: 000000019.json - 9 digits
|
|
20
|
+
*/
|
|
21
|
+
const LOCAL_ENTRY_NAME_DIGITS = 9;
|
|
22
|
+
class DatasetClient extends base_client_1.BaseClient {
|
|
23
|
+
constructor(options) {
|
|
24
|
+
super(options.id ?? (0, node_crypto_1.randomUUID)());
|
|
25
|
+
Object.defineProperty(this, "name", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
value: void 0
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(this, "createdAt", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: true,
|
|
35
|
+
value: new Date()
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(this, "accessedAt", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
writable: true,
|
|
41
|
+
value: new Date()
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(this, "modifiedAt", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
configurable: true,
|
|
46
|
+
writable: true,
|
|
47
|
+
value: new Date()
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(this, "itemCount", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
configurable: true,
|
|
52
|
+
writable: true,
|
|
53
|
+
value: 0
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(this, "datasetDirectory", {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
configurable: true,
|
|
58
|
+
writable: true,
|
|
59
|
+
value: void 0
|
|
60
|
+
});
|
|
61
|
+
Object.defineProperty(this, "datasetEntries", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
configurable: true,
|
|
64
|
+
writable: true,
|
|
65
|
+
value: new Map()
|
|
66
|
+
});
|
|
67
|
+
Object.defineProperty(this, "client", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
configurable: true,
|
|
70
|
+
writable: true,
|
|
71
|
+
value: void 0
|
|
72
|
+
});
|
|
73
|
+
this.name = options.name;
|
|
74
|
+
this.datasetDirectory = (0, node_path_1.resolve)(options.baseStorageDirectory, this.name ?? this.id);
|
|
75
|
+
this.client = options.client;
|
|
76
|
+
}
|
|
77
|
+
async get() {
|
|
78
|
+
const found = this.client.datasetClientsHandled.find((store) => store.id === this.id);
|
|
79
|
+
if (found) {
|
|
80
|
+
found.updateTimestamps(false);
|
|
81
|
+
return found.toDatasetInfo();
|
|
82
|
+
}
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
async update(newFields = {}) {
|
|
86
|
+
const parsed = shapeshift_1.s.object({
|
|
87
|
+
name: shapeshift_1.s.string.lengthGreaterThan(0).optional,
|
|
88
|
+
}).parse(newFields);
|
|
89
|
+
// Check by id
|
|
90
|
+
const existingStoreById = this.client.datasetClientsHandled.find((store) => store.id === this.id);
|
|
91
|
+
if (!existingStoreById) {
|
|
92
|
+
this.throwOnNonExisting(consts_1.StorageTypes.Dataset);
|
|
93
|
+
}
|
|
94
|
+
// Skip if no changes
|
|
95
|
+
if (!parsed.name) {
|
|
96
|
+
return existingStoreById.toDatasetInfo();
|
|
97
|
+
}
|
|
98
|
+
// Check that name is not in use already
|
|
99
|
+
const existingStoreByName = this.client.datasetClientsHandled.find((store) => store.name?.toLowerCase() === parsed.name.toLowerCase());
|
|
100
|
+
if (existingStoreByName) {
|
|
101
|
+
this.throwOnDuplicateEntry(consts_1.StorageTypes.Dataset, 'name', parsed.name);
|
|
102
|
+
}
|
|
103
|
+
existingStoreById.name = parsed.name;
|
|
104
|
+
const previousDir = existingStoreById.datasetDirectory;
|
|
105
|
+
existingStoreById.datasetDirectory = (0, node_path_1.resolve)(this.client.datasetsDirectory, parsed.name ?? existingStoreById.name ?? existingStoreById.id);
|
|
106
|
+
await (0, fs_extra_1.move)(previousDir, existingStoreById.datasetDirectory, { overwrite: true });
|
|
107
|
+
// Update timestamps
|
|
108
|
+
existingStoreById.updateTimestamps(true);
|
|
109
|
+
return existingStoreById.toDatasetInfo();
|
|
110
|
+
}
|
|
111
|
+
async delete() {
|
|
112
|
+
const storeIndex = this.client.datasetClientsHandled.findIndex((store) => store.id === this.id);
|
|
113
|
+
if (storeIndex !== -1) {
|
|
114
|
+
const [oldClient] = this.client.datasetClientsHandled.splice(storeIndex, 1);
|
|
115
|
+
oldClient.itemCount = 0;
|
|
116
|
+
oldClient.datasetEntries.clear();
|
|
117
|
+
await (0, promises_1.rm)(oldClient.datasetDirectory, { recursive: true });
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async downloadItems() {
|
|
121
|
+
throw new Error('This method is not implemented in @crawlee/memory-storage');
|
|
122
|
+
}
|
|
123
|
+
async listItems(options = {}) {
|
|
124
|
+
const { limit = LIST_ITEMS_LIMIT, offset = 0, desc, } = shapeshift_1.s.object({
|
|
125
|
+
desc: shapeshift_1.s.boolean.optional,
|
|
126
|
+
limit: shapeshift_1.s.number.int.optional,
|
|
127
|
+
offset: shapeshift_1.s.number.int.optional,
|
|
128
|
+
}).parse(options);
|
|
129
|
+
// Check by id
|
|
130
|
+
const existingStoreById = this.client.datasetClientsHandled.find((store) => store.id === this.id);
|
|
131
|
+
if (!existingStoreById) {
|
|
132
|
+
this.throwOnNonExisting(consts_1.StorageTypes.Dataset);
|
|
133
|
+
}
|
|
134
|
+
const [start, end] = this.getStartAndEndIndexes(offset, limit);
|
|
135
|
+
const items = [];
|
|
136
|
+
for (let idx = start; idx < end; idx++) {
|
|
137
|
+
const entryNumber = this.generateLocalEntryName(idx);
|
|
138
|
+
items.push(existingStoreById.datasetEntries.get(entryNumber));
|
|
139
|
+
}
|
|
140
|
+
existingStoreById.updateTimestamps(false);
|
|
141
|
+
return {
|
|
142
|
+
count: items.length,
|
|
143
|
+
desc: desc ?? false,
|
|
144
|
+
items: desc ? items.reverse() : items,
|
|
145
|
+
limit,
|
|
146
|
+
offset,
|
|
147
|
+
total: this.itemCount,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
async pushItems(items) {
|
|
151
|
+
const rawItems = shapeshift_1.s.union(shapeshift_1.s.string, shapeshift_1.s.object({}).passthrough, shapeshift_1.s.array(shapeshift_1.s.union(shapeshift_1.s.string, shapeshift_1.s.object({}).passthrough))).parse(items);
|
|
152
|
+
// Check by id
|
|
153
|
+
const existingStoreById = this.client.datasetClientsHandled.find((store) => store.id === this.id);
|
|
154
|
+
if (!existingStoreById) {
|
|
155
|
+
this.throwOnNonExisting(consts_1.StorageTypes.Dataset);
|
|
156
|
+
}
|
|
157
|
+
const normalized = this.normalizeItems(rawItems);
|
|
158
|
+
const addedIds = [];
|
|
159
|
+
for (const entry of normalized) {
|
|
160
|
+
const idx = this.generateLocalEntryName(++existingStoreById.itemCount);
|
|
161
|
+
existingStoreById.datasetEntries.set(idx, entry);
|
|
162
|
+
addedIds.push(idx);
|
|
163
|
+
}
|
|
164
|
+
const dataEntries = addedIds.map((id) => [id, existingStoreById.datasetEntries.get(id)]);
|
|
165
|
+
existingStoreById.updateTimestamps(true);
|
|
166
|
+
(0, instance_1.sendWorkerMessage)({
|
|
167
|
+
data: dataEntries,
|
|
168
|
+
action: 'update-entries',
|
|
169
|
+
entityType: 'datasets',
|
|
170
|
+
entityDirectory: existingStoreById.datasetDirectory,
|
|
171
|
+
id: existingStoreById.name ?? existingStoreById.id,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
toDatasetInfo() {
|
|
175
|
+
return {
|
|
176
|
+
id: this.id,
|
|
177
|
+
accessedAt: this.accessedAt,
|
|
178
|
+
createdAt: this.createdAt,
|
|
179
|
+
itemCount: this.itemCount,
|
|
180
|
+
modifiedAt: this.modifiedAt,
|
|
181
|
+
name: this.name,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
generateLocalEntryName(idx) {
|
|
185
|
+
return idx.toString().padStart(LOCAL_ENTRY_NAME_DIGITS, '0');
|
|
186
|
+
}
|
|
187
|
+
getStartAndEndIndexes(offset, limit = this.itemCount) {
|
|
188
|
+
const start = offset + 1;
|
|
189
|
+
const end = Math.min(offset + limit, this.itemCount) + 1;
|
|
190
|
+
return [start, end];
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* To emulate API and split arrays of items into individual dataset items,
|
|
194
|
+
* we need to normalize the input items - which can be strings, objects
|
|
195
|
+
* or arrays of those - into objects, so that we can save them one by one
|
|
196
|
+
* later. We could potentially do this directly with strings, but let's
|
|
197
|
+
* not optimize prematurely.
|
|
198
|
+
*/
|
|
199
|
+
normalizeItems(items) {
|
|
200
|
+
if (typeof items === 'string') {
|
|
201
|
+
items = JSON.parse(items);
|
|
202
|
+
}
|
|
203
|
+
return Array.isArray(items)
|
|
204
|
+
? items.map((item) => this.normalizeItem(item))
|
|
205
|
+
: [this.normalizeItem(items)];
|
|
206
|
+
}
|
|
207
|
+
normalizeItem(item) {
|
|
208
|
+
if (typeof item === 'string') {
|
|
209
|
+
item = JSON.parse(item);
|
|
210
|
+
}
|
|
211
|
+
if (Array.isArray(item)) {
|
|
212
|
+
throw new Error(`Each dataset item can only be a single JSON object, not an array. Received: [${item.join(',\n')}]`);
|
|
213
|
+
}
|
|
214
|
+
if (typeof item !== 'object' || item === null) {
|
|
215
|
+
throw new Error(`Each dataset item must be a JSON object. Received: ${item}`);
|
|
216
|
+
}
|
|
217
|
+
return item;
|
|
218
|
+
}
|
|
219
|
+
updateTimestamps(hasBeenModified) {
|
|
220
|
+
this.accessedAt = new Date();
|
|
221
|
+
if (hasBeenModified) {
|
|
222
|
+
this.modifiedAt = new Date();
|
|
223
|
+
}
|
|
224
|
+
const data = this.toDatasetInfo();
|
|
225
|
+
(0, instance_1.sendWorkerMessage)({
|
|
226
|
+
action: 'update-metadata',
|
|
227
|
+
data,
|
|
228
|
+
entityType: 'datasets',
|
|
229
|
+
entityDirectory: this.datasetDirectory,
|
|
230
|
+
id: this.name ?? this.id,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
exports.DatasetClient = DatasetClient;
|
|
235
|
+
//# sourceMappingURL=dataset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataset.js","sourceRoot":"","sources":["../../src/resource-clients/dataset.ts"],"names":[],"mappings":";;;AAEA,qDAAyC;AACzC,6CAAyC;AACzC,+CAAsC;AACtC,yCAAoC;AACpC,uCAAgC;AAEhC,sCAAyC;AACzC,sDAAkD;AAClD,kDAAwD;AAExD;;;GAGG;AACH,MAAM,gBAAgB,GAAG,YAAe,CAAC;AAEzC;;;GAGG;AACH,MAAM,uBAAuB,GAAG,CAAC,CAAC;AASlC,MAAa,aAAoD,SAAQ,wBAAU;IAW/E,YAAY,OAA6B;QACrC,KAAK,CAAC,OAAO,CAAC,EAAE,IAAI,IAAA,wBAAU,GAAE,CAAC,CAAC;QAXtC;;;;;WAAc;QACd;;;;mBAAY,IAAI,IAAI,EAAE;WAAC;QACvB;;;;mBAAa,IAAI,IAAI,EAAE;WAAC;QACxB;;;;mBAAa,IAAI,IAAI,EAAE;WAAC;QACxB;;;;mBAAY,CAAC;WAAC;QACd;;;;;WAAyB;QAEzB;;;;mBAAkC,IAAI,GAAG,EAAgB;WAAC;QAC1D;;;;;WAAuC;QAInC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,gBAAgB,GAAG,IAAA,mBAAO,EAAC,OAAO,CAAC,oBA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* as storage from '@crawlee/types';
|
|
2
|
+
import { MemoryStorage } from '../index';
|
|
3
|
+
export interface KeyValueStoreCollectionClientOptions {
|
|
4
|
+
baseStorageDirectory: string;
|
|
5
|
+
client: MemoryStorage;
|
|
6
|
+
}
|
|
7
|
+
export declare class KeyValueStoreCollectionClient implements storage.KeyValueStoreCollectionClient {
|
|
8
|
+
private readonly keyValueStoresDirectory;
|
|
9
|
+
private readonly client;
|
|
10
|
+
constructor({ baseStorageDirectory, client }: KeyValueStoreCollectionClientOptions);
|
|
11
|
+
list(): ReturnType<storage.KeyValueStoreCollectionClient['list']>;
|
|
12
|
+
getOrCreate(name?: string): Promise<storage.KeyValueStoreInfo>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=key-value-store-collection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key-value-store-collection.d.ts","sourceRoot":"","sources":["../../src/resource-clients/key-value-store-collection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAG/C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAIzC,MAAM,WAAW,oCAAoC;IACjD,oBAAoB,EAAE,MAAM,CAAC;IAC7B,MAAM,EAAE,aAAa,CAAC;CACzB;AAED,qBAAa,6BAA8B,YAAW,OAAO,CAAC,6BAA6B;IACvF,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAS;IACjD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;gBAE3B,EAAE,oBAAoB,EAAE,MAAM,EAAE,EAAE,oCAAoC;IAK5E,IAAI,IAAI,UAAU,CAAC,OAAO,CAAC,6BAA6B,CAAC,MAAM,CAAC,CAAC;IAajE,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC;CA2BvE"}
|