-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatasets.ts
More file actions
62 lines (58 loc) · 1.84 KB
/
Copy pathdatasets.ts
File metadata and controls
62 lines (58 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { and, eq } from 'drizzle-orm'
import { Cli, z } from 'incur'
import { contextMiddleware, contextSchema } from '../middleware.ts'
import { globalOptions } from '../utils.ts'
export const datasets = Cli.create('datasets', {
description: 'Dataset commands',
options: globalOptions,
vars: contextSchema,
})
datasets.command('list', {
description: 'List all datasets',
options: globalOptions.extend({
providerId: z.coerce.bigint().optional().describe('Filter datasets by provider ID'),
}),
middleware: [contextMiddleware],
run: async (c) => {
try {
const schema = c.var.indexerDb._.fullSchema
const conditions = [
eq(schema.dataSets.deleted, false),
eq(schema.dataSets.payer, c.var.client.account.address.toLowerCase()),
]
if (c.options.providerId != null) {
conditions.push(eq(schema.dataSets.providerId, c.options.providerId))
}
const datasets = await c.var.indexerDb.query.dataSets.findMany({
where: and(...conditions),
with: {
provider: true,
pieces: true,
},
})
const datasetsFlattened = datasets.map((dataset) => {
const { provider, pieces } = dataset
return {
id: dataset.dataSetId,
withCdn: dataset.withCdn,
withIpfsIndexing: dataset.withIpfsIndexing,
source: dataset.source,
provider: provider.serviceUrl,
pdpEndEpoch: dataset.pdpEndEpoch,
pieces: pieces.length,
// metadata: JSON.stringify(dataset.metadata),
}
})
return c.ok({
datasets: datasetsFlattened,
})
} catch (error) {
console.error(error)
return c.error({
code: 'DATASETS_FAILED',
message: error instanceof Error ? error.message : 'Failed to list datasets',
retryable: true,
})
}
},
})