@crawlee/fs-storage-native 0.1.3 → 0.1.5-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. package/index.d.ts +98 -78
  2. package/index.js +555 -729
  3. package/lib.d.ts +5 -24
  4. package/lib.js +11 -15
  5. package/package.json +15 -7
package/index.d.ts CHANGED
@@ -73,95 +73,115 @@ export interface AddRequestsResponse {
73
73
  processedRequests: ProcessedRequest[];
74
74
  unprocessedRequests: UnprocessedRequest[];
75
75
  }
76
+
77
+ // The following `interface` declarations merge with the napi-generated `declare class`es
78
+ // further down in this file, adding the JS-side wrappers defined in `lib.js` directly onto
79
+ // the class signatures.
80
+
81
+ export interface DatasetItemIterator {
82
+ [Symbol.asyncIterator](): AsyncIterator<Record<string, unknown>>;
83
+ }
84
+
85
+ export interface KvsKeyIterator {
86
+ [Symbol.asyncIterator](): AsyncIterator<KeyValueStoreRecordMetadata>;
87
+ }
88
+
89
+ export interface FileSystemKeyValueStoreClient {
90
+ /** Get a value as a ReadableStream of bytes. Returns null if the key doesn't exist. */
91
+ getValueStream(key: string): Promise<KeyValueStoreStreamRecord | null>;
92
+ /** Set a value from a ReadableStream. Consumes the entire stream and writes atomically. */
93
+ setValueStream(
94
+ key: string,
95
+ stream: ReadableStream<Uint8Array>,
96
+ contentType?: string | null,
97
+ ): Promise<void>;
98
+ }
76
99
  export declare class DatasetItemIterator {
77
- /** Fetch the next item. Returns null when iteration is exhausted. */
78
- next(): Promise<Record<string, unknown> | null>;
100
+ /** Fetch the next item. Returns null when iteration is exhausted. */
101
+ next(): Promise<Record<string, unknown> | null>
79
102
  }
80
103
 
81
104
  export declare class FileSystemDatasetClient {
82
- static open(
83
- id?: string | undefined | null,
84
- name?: string | undefined | null,
85
- alias?: string | undefined | null,
86
- storageDir?: string | undefined | null,
87
- ): Promise<FileSystemDatasetClient>;
88
- get pathToDataset(): string;
89
- get pathToMetadata(): string;
90
- getMetadata(): Promise<DatasetMetadata>;
91
- dropStorage(): Promise<void>;
92
- purge(): Promise<void>;
93
- pushData(data: Record<string, unknown> | Record<string, unknown>[]): Promise<void>;
94
- getData(
95
- offset?: number | undefined | null,
96
- limit?: number | undefined | null,
97
- desc?: boolean | undefined | null,
98
- skipEmpty?: boolean | undefined | null,
99
- ): Promise<DatasetItemsListPage>;
100
- iterateItems(
101
- offset?: number | undefined | null,
102
- limit?: number | undefined | null,
103
- desc?: boolean | undefined | null,
104
- skipEmpty?: boolean | undefined | null,
105
- pageSize?: number | undefined | null,
106
- ): Promise<DatasetItemIterator>;
105
+ static open(id?: string | undefined | null, name?: string | undefined | null, alias?: string | undefined | null, storageDir?: string | undefined | null, useTestClock?: boolean | undefined | null): Promise<FileSystemDatasetClient>
106
+ /**
107
+ * Advance the client's clock by `millis` milliseconds. Only usable when
108
+ * the client was opened with `useTestClock: true`; throws otherwise.
109
+ */
110
+ advanceClockForTesting(millis: number): void
111
+ get pathToDataset(): string
112
+ get pathToMetadata(): string
113
+ getMetadata(): Promise<DatasetMetadata>
114
+ dropStorage(): Promise<void>
115
+ purge(): Promise<void>
116
+ pushData(data: Record<string, unknown> | Record<string, unknown>[]): Promise<void>
117
+ getData(offset?: number | undefined | null, limit?: number | undefined | null, desc?: boolean | undefined | null, skipEmpty?: boolean | undefined | null): Promise<DatasetItemsListPage>
118
+ iterateItems(offset?: number | undefined | null, limit?: number | undefined | null, desc?: boolean | undefined | null, skipEmpty?: boolean | undefined | null, pageSize?: number | undefined | null): Promise<DatasetItemIterator>
107
119
  }
108
120
 
109
121
  export declare class FileSystemKeyValueStoreClient {
110
- static open(
111
- id?: string | undefined | null,
112
- name?: string | undefined | null,
113
- alias?: string | undefined | null,
114
- storageDir?: string | undefined | null,
115
- ): Promise<FileSystemKeyValueStoreClient>;
116
- get pathToKvs(): string;
117
- get pathToMetadata(): string;
118
- getMetadata(): Promise<KeyValueStoreMetadata>;
119
- dropStorage(): Promise<void>;
120
- purge(): Promise<void>;
121
- /** Get a record by key. Returns the raw value bytes as a Buffer. */
122
- getValue(key: string): Promise<KeyValueStoreRecord | null>;
123
- /** Set a value from a Buffer. */
124
- setValue(key: string, value: Buffer, contentType?: string | undefined | null): Promise<void>;
125
- deleteValue(key: string): Promise<void>;
126
- iterateKeys(
127
- exclusiveStartKey?: string | undefined | null,
128
- limit?: number | undefined | null,
129
- pageSize?: number | undefined | null,
130
- ): Promise<KvsKeyIterator>;
131
- getPublicUrl(key: string): Promise<string>;
132
- recordExists(key: string): Promise<boolean>;
122
+ static open(id?: string | undefined | null, name?: string | undefined | null, alias?: string | undefined | null, storageDir?: string | undefined | null, useTestClock?: boolean | undefined | null): Promise<FileSystemKeyValueStoreClient>
123
+ /**
124
+ * Advance the client's clock by `millis` milliseconds. Only usable when
125
+ * the client was opened with `useTestClock: true`; throws otherwise.
126
+ */
127
+ advanceClockForTesting(millis: number): void
128
+ get pathToKvs(): string
129
+ get pathToMetadata(): string
130
+ getMetadata(): Promise<KeyValueStoreMetadata>
131
+ dropStorage(): Promise<void>
132
+ purge(): Promise<void>
133
+ /** Get a record by key. Returns the raw value bytes as a Buffer. */
134
+ getValue(key: string): Promise<KeyValueStoreRecord | null>
135
+ /** Set a value from a Buffer. */
136
+ setValue(key: string, value: Buffer, contentType?: string | undefined | null): Promise<void>
137
+ deleteValue(key: string): Promise<void>
138
+ iterateKeys(exclusiveStartKey?: string | undefined | null, limit?: number | undefined | null, pageSize?: number | undefined | null): Promise<KvsKeyIterator>
139
+ getPublicUrl(key: string): Promise<string>
140
+ recordExists(key: string): Promise<boolean>
133
141
  }
134
142
 
135
143
  export declare class FileSystemRequestQueueClient {
136
- static open(
137
- id?: string | undefined | null,
138
- name?: string | undefined | null,
139
- alias?: string | undefined | null,
140
- storageDir?: string | undefined | null,
141
- ): Promise<FileSystemRequestQueueClient>;
142
- get pathToRq(): string;
143
- get pathToMetadata(): string;
144
- getMetadata(): Promise<RequestQueueMetadata>;
145
- dropStorage(): Promise<void>;
146
- purge(): Promise<void>;
147
- addBatchOfRequests(
148
- requests: Record<string, unknown>[],
149
- forefront?: boolean | undefined | null,
150
- ): Promise<AddRequestsResponse>;
151
- getRequest(uniqueKey: string): Promise<Record<string, unknown> | null>;
152
- fetchNextRequest(): Promise<Record<string, unknown> | null>;
153
- markRequestAsHandled(request: Record<string, unknown>): Promise<ProcessedRequest | null>;
154
- reclaimRequest(
155
- request: Record<string, unknown>,
156
- forefront?: boolean | undefined | null,
157
- ): Promise<ProcessedRequest | null>;
158
- isEmpty(): Promise<boolean>;
159
- isFinished(): Promise<boolean>;
160
- setExpectedRequestProcessingTime(secs: number): Promise<void>;
161
- persistState(): Promise<void>;
144
+ /**
145
+ * Open a request queue.
146
+ *
147
+ * `useTestClock`: see `advanceClockForTesting` below.
148
+ *
149
+ * `assumeSoleOwner` (default `false`): controls how locks on disk are
150
+ * treated at open time. With `false` (the safe default), any future-dated
151
+ * `orderNo` is respected as a potential live peer's lock — crashed peers'
152
+ * locks expire naturally on the wall clock. With `true`, the caller
153
+ * asserts nothing else is using this queue and any in-progress locks are
154
+ * reclaimed immediately, so a request whose previous run died is
155
+ * instantly re-fetchable. Set to `true` only if you know you're the sole
156
+ * consumer; otherwise you risk two peers processing the same request.
157
+ */
158
+ static open(id?: string | undefined | null, name?: string | undefined | null, alias?: string | undefined | null, storageDir?: string | undefined | null, useTestClock?: boolean | undefined | null, assumeSoleOwner?: boolean | undefined | null): Promise<FileSystemRequestQueueClient>
159
+ /**
160
+ * Advance the client's clock by `millis` milliseconds. Only usable when
161
+ * the client was opened with `useTestClock: true`; throws otherwise.
162
+ *
163
+ * This is the hook that lets JS tests using `vi.useFakeTimers()` exercise
164
+ * lock-expiry behavior fake JS timers don't reach into native code, so
165
+ * the test must drive the Rust-side clock explicitly via this method.
166
+ */
167
+ advanceClockForTesting(millis: number): void
168
+ get pathToRq(): string
169
+ get pathToMetadata(): string
170
+ getMetadata(): Promise<RequestQueueMetadata>
171
+ dropStorage(): Promise<void>
172
+ purge(): Promise<void>
173
+ addBatchOfRequests(requests: Record<string, unknown>[], forefront?: boolean | undefined | null): Promise<AddRequestsResponse>
174
+ getRequest(uniqueKey: string): Promise<Record<string, unknown> | null>
175
+ fetchNextRequest(): Promise<Record<string, unknown> | null>
176
+ markRequestAsHandled(request: Record<string, unknown>): Promise<ProcessedRequest | null>
177
+ reclaimRequest(request: Record<string, unknown>, forefront?: boolean | undefined | null): Promise<ProcessedRequest | null>
178
+ isEmpty(): Promise<boolean>
179
+ isFinished(): Promise<boolean>
180
+ setExpectedRequestProcessingTime(secs: number): Promise<void>
181
+ persistState(): Promise<void>
162
182
  }
163
183
 
164
184
  export declare class KvsKeyIterator {
165
- /** Fetch the next key metadata entry. Returns null when iteration is exhausted. */
166
- next(): Promise<KeyValueStoreRecordMetadata | null>;
185
+ /** Fetch the next key metadata entry. Returns null when iteration is exhausted. */
186
+ next(): Promise<KeyValueStoreRecordMetadata | null>
167
187
  }