Skip to content

Commit 65d4512

Browse files
committed
chore(storage): supplementary examples
1 parent 150a35b commit 65d4512

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

examples/storage-example.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ async function datasetExample(client) {
1616
console.log(`Dataset created with ID: ${dataset.id}`);
1717

1818
// Add items to the dataset
19-
await client.storage.dataset.addItems([
19+
await client.storage.dataset.addItems(dataset.id, [
2020
{ name: 'Product 1', price: 19.99, category: 'Electronics' },
2121
{ name: 'Product 2', price: 29.99, category: 'Home' },
2222
{ name: 'Product 3', price: 9.99, category: 'Clothing' }
2323
]);
2424
console.log('Items added to dataset');
2525

2626
// Get items from the dataset
27-
const items = await client.storage.dataset.getItems({
27+
const items = await client.storage.dataset.getItems(dataset.id, {
2828
page: 1,
2929
pageSize: 10
3030
});
@@ -48,7 +48,7 @@ async function kvStorageExample(client) {
4848
console.log(`KV namespace created with ID: ${namespace.id}`);
4949

5050
// Set values in the namespace
51-
await client.storage.kv.setValue({
51+
await client.storage.kv.setValue(namespace.id, {
5252
key: 'appConfig',
5353
value: JSON.stringify({
5454
apiVersion: '1.0',
@@ -61,11 +61,11 @@ async function kvStorageExample(client) {
6161
console.log('Value set in KV store');
6262

6363
// Get value from the namespace
64-
const config = await client.storage.kv.getValue('appConfig');
64+
const config = await client.storage.kv.getValue(namespace.id, 'appConfig');
6565
console.log('Retrieved config:', JSON.parse(config));
6666

6767
// List keys in the namespace
68-
const keys = await client.storage.kv.listKeys({ page: 1, pageSize: 10 });
68+
const keys = await client.storage.kv.listKeys(namespace.id, { page: 1, pageSize: 10 });
6969
console.log('KV store keys:', keys);
7070

7171
console.log('KV storage example completed\n');
@@ -89,13 +89,13 @@ async function objectStorageExample(client) {
8989
console.log(`Object bucket created with ID: ${bucket.id}`);
9090

9191
// Upload a file to the bucket (in a real scenario, you would use a real file path)
92-
const uploadResult = await client.storage.object.put({
92+
const uploadResult = await client.storage.object.put(bucket.id, {
9393
file: 'example/sample-image.jpg'
9494
});
9595
console.log('File uploaded to object storage:', uploadResult);
9696

9797
// List objects in the bucket
98-
const objects = await client.storage.object.list({ page: 1, pageSize: 10 });
98+
const objects = await client.storage.object.list(bucket.id, { page: 1, pageSize: 10 });
9999
console.log('Objects in bucket:', objects);
100100

101101
console.log('Object storage example completed\n');
@@ -119,7 +119,7 @@ async function queueStorageExample(client) {
119119
console.log(`Queue created with ID: ${queue.id}`);
120120

121121
// Push messages to the queue
122-
const message1 = await client.storage.queue.push({
122+
const message1 = await client.storage.queue.push(queue.id, {
123123
name: 'processImage',
124124
payload: JSON.stringify({
125125
imageId: '123',
@@ -131,7 +131,7 @@ async function queueStorageExample(client) {
131131
});
132132
console.log('Message pushed to queue:', message1);
133133

134-
const message2 = await client.storage.queue.push({
134+
const message2 = await client.storage.queue.push(queue.id, {
135135
name: 'generateReport',
136136
payload: JSON.stringify({ reportType: 'monthly', format: 'pdf' }),
137137
retry: 2,
@@ -141,12 +141,12 @@ async function queueStorageExample(client) {
141141
console.log('Message pushed to queue:', message2);
142142

143143
// Pull messages from the queue
144-
const messages = await client.storage.queue.pull();
144+
const messages = await client.storage.queue.pull(queue.id);
145145
console.log('Messages pulled from queue:', messages);
146146

147147
// Acknowledge a message (if any)
148148
if (messages && messages.length > 0) {
149-
await client.storage.queue.ack(messages[0].id);
149+
await client.storage.queue.ack(queue.id, messages[0].id);
150150
console.log(`Message ${messages[0].id} acknowledged`);
151151
}
152152

@@ -169,7 +169,7 @@ async function runExample() {
169169
// Run the examples
170170
await datasetExample(client);
171171
await kvStorageExample(client);
172-
await objectStorageExample(client);
172+
// await objectStorageExample(client);
173173
await queueStorageExample(client);
174174

175175
console.log('All storage examples completed successfully');

src/services/memory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export abstract class MemoryService {
5757
if (metaData.name === name) {
5858
return true;
5959
}
60-
} catch (e) {
60+
} catch {
6161
continue;
6262
}
6363
}

src/services/storage/memory/dataset.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class LocalDatasetStorage extends MemoryService implements IDatasetStorag
3535
let entries: fs.Dirent[];
3636
try {
3737
entries = await fs.promises.readdir(dirPath, { withFileTypes: true });
38-
} catch (err) {
38+
} catch {
3939
return {
4040
items: [],
4141
total: 0,
@@ -53,7 +53,7 @@ export class LocalDatasetStorage extends MemoryService implements IDatasetStorag
5353
const file = await this.readFile(metaPath);
5454
const meta = JSON.parse(file);
5555
allDatasets.push(meta);
56-
} catch (e) {
56+
} catch {
5757
continue;
5858
}
5959
}

src/services/storage/memory/kv.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class LocalKVStorage extends MemoryService implements IKVStorage {
3838
let entries: fs.Dirent[];
3939
try {
4040
entries = await fs.promises.readdir(dirPath, { withFileTypes: true });
41-
} catch (err) {
41+
} catch {
4242
return {
4343
items: [],
4444
total: 0,
@@ -64,7 +64,7 @@ export class LocalKVStorage extends MemoryService implements IKVStorage {
6464
runId: meta.runId || '',
6565
stats: { count: 0, size: 0 }
6666
});
67-
} catch (e) {
67+
} catch {
6868
continue;
6969
}
7070
}
@@ -177,7 +177,7 @@ export class LocalKVStorage extends MemoryService implements IKVStorage {
177177
try {
178178
await this.rm(dirPath, { recursive: true, force: true });
179179
return { success: true };
180-
} catch (e) {
180+
} catch {
181181
return { success: false };
182182
}
183183
}
@@ -258,7 +258,7 @@ export class LocalKVStorage extends MemoryService implements IKVStorage {
258258
try {
259259
await this.rm(filePath);
260260
return { success: true };
261-
} catch (e) {
261+
} catch {
262262
return { success: false };
263263
}
264264
}

src/services/storage/memory/queue.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class LocalQueueStorage extends MemoryService implements IQueueStorage {
3939
let entries: fs.Dirent[];
4040
try {
4141
entries = await fs.promises.readdir(dirPath, { withFileTypes: true });
42-
} catch (err) {
42+
} catch {
4343
return {
4444
items: [],
4545
total: 0,
@@ -56,7 +56,7 @@ export class LocalQueueStorage extends MemoryService implements IQueueStorage {
5656
const file = await this.readFile(metaPath);
5757
const meta = JSON.parse(file);
5858
allQueues.push(meta);
59-
} catch (e) {
59+
} catch {
6060
continue;
6161
}
6262
}
@@ -163,7 +163,7 @@ export class LocalQueueStorage extends MemoryService implements IQueueStorage {
163163
try {
164164
await this.rm(dirPath, { recursive: true, force: true });
165165
return { success: true };
166-
} catch (e) {
166+
} catch {
167167
return { success: false };
168168
}
169169
}
@@ -214,7 +214,7 @@ export class LocalQueueStorage extends MemoryService implements IQueueStorage {
214214
let files: string[];
215215
try {
216216
files = await fs.promises.readdir(dirPath);
217-
} catch (e) {
217+
} catch {
218218
return [];
219219
}
220220
files = files.filter(f => f.endsWith('.json') && f !== 'metadata.json');
@@ -267,7 +267,7 @@ export class LocalQueueStorage extends MemoryService implements IQueueStorage {
267267
return { success: true };
268268
}
269269
return { success: false };
270-
} catch (e) {
270+
} catch {
271271
return { success: false };
272272
}
273273
}

0 commit comments

Comments
 (0)