@filoz/repair-cli 0.4.0 → 1.1.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 (115) hide show
  1. package/dist/package.json +4 -4
  2. package/dist/src/api.d.ts +35 -0
  3. package/dist/src/api.d.ts.map +1 -0
  4. package/dist/src/api.js +118 -0
  5. package/dist/src/api.js.map +1 -0
  6. package/dist/src/commands/datasets.d.ts +5 -7
  7. package/dist/src/commands/datasets.d.ts.map +1 -1
  8. package/dist/src/commands/datasets.js +33 -35
  9. package/dist/src/commands/datasets.js.map +1 -1
  10. package/dist/src/commands/providers.d.ts +5 -7
  11. package/dist/src/commands/providers.d.ts.map +1 -1
  12. package/dist/src/commands/providers.js +32 -33
  13. package/dist/src/commands/providers.js.map +1 -1
  14. package/dist/src/commands/repair.d.ts +5 -7
  15. package/dist/src/commands/repair.d.ts.map +1 -1
  16. package/dist/src/commands/repair.js +5 -1
  17. package/dist/src/commands/repair.js.map +1 -1
  18. package/dist/src/commands/replicate.d.ts +5 -7
  19. package/dist/src/commands/replicate.d.ts.map +1 -1
  20. package/dist/src/commands/replicate.js +5 -1
  21. package/dist/src/commands/replicate.js.map +1 -1
  22. package/dist/src/commands/second-copy.d.ts +5 -7
  23. package/dist/src/commands/second-copy.d.ts.map +1 -1
  24. package/dist/src/commands/second-copy.js +5 -1
  25. package/dist/src/commands/second-copy.js.map +1 -1
  26. package/dist/src/commands/session-key.d.ts +5 -7
  27. package/dist/src/commands/session-key.d.ts.map +1 -1
  28. package/dist/src/commands/setup.d.ts.map +1 -1
  29. package/dist/src/commands/setup.js +11 -32
  30. package/dist/src/commands/setup.js.map +1 -1
  31. package/dist/src/commands/wallet.d.ts +5 -7
  32. package/dist/src/commands/wallet.d.ts.map +1 -1
  33. package/dist/src/db/dedupe-cids.d.ts +6 -7
  34. package/dist/src/db/dedupe-cids.d.ts.map +1 -1
  35. package/dist/src/db/dedupe-cids.js +2 -14
  36. package/dist/src/db/dedupe-cids.js.map +1 -1
  37. package/dist/src/db/find-repair-dataset.d.ts +3 -3
  38. package/dist/src/db/find-repair-dataset.d.ts.map +1 -1
  39. package/dist/src/db/find-repair-dataset.js +16 -14
  40. package/dist/src/db/find-repair-dataset.js.map +1 -1
  41. package/dist/src/db/get-active-data-set-ids.d.ts +9 -0
  42. package/dist/src/db/get-active-data-set-ids.d.ts.map +1 -0
  43. package/dist/src/db/get-active-data-set-ids.js +9 -0
  44. package/dist/src/db/get-active-data-set-ids.js.map +1 -0
  45. package/dist/src/db/get-alternate-provider-urls.d.ts +6 -0
  46. package/dist/src/db/get-alternate-provider-urls.d.ts.map +1 -0
  47. package/dist/src/db/get-alternate-provider-urls.js +24 -0
  48. package/dist/src/db/get-alternate-provider-urls.js.map +1 -0
  49. package/dist/src/db/get-pieces.d.ts +8 -27
  50. package/dist/src/db/get-pieces.d.ts.map +1 -1
  51. package/dist/src/db/get-pieces.js +44 -97
  52. package/dist/src/db/get-pieces.js.map +1 -1
  53. package/dist/src/db/get-repair-provider.d.ts +2 -2
  54. package/dist/src/db/get-repair-provider.d.ts.map +1 -1
  55. package/dist/src/db/get-repair-provider.js +8 -20
  56. package/dist/src/db/get-repair-provider.js.map +1 -1
  57. package/dist/src/db/repair-create.js +3 -3
  58. package/dist/src/db/repair-create.js.map +1 -1
  59. package/dist/src/db/replicate-create.d.ts.map +1 -1
  60. package/dist/src/db/replicate-create.js +13 -21
  61. package/dist/src/db/replicate-create.js.map +1 -1
  62. package/dist/src/db/second-copy-create.js +2 -2
  63. package/dist/src/db/second-copy-create.js.map +1 -1
  64. package/dist/src/local-schema.d.ts +1 -1
  65. package/dist/src/middleware.d.ts +12 -16
  66. package/dist/src/middleware.d.ts.map +1 -1
  67. package/dist/src/middleware.js +6 -10
  68. package/dist/src/middleware.js.map +1 -1
  69. package/dist/src/pipeline/add-pieces.d.ts +4 -4
  70. package/dist/src/pipeline/add-pieces.d.ts.map +1 -1
  71. package/dist/src/pipeline/add-pieces.js +32 -19
  72. package/dist/src/pipeline/add-pieces.js.map +1 -1
  73. package/dist/src/pipeline/create-datasets.d.ts +4 -4
  74. package/dist/src/pipeline/create-datasets.d.ts.map +1 -1
  75. package/dist/src/pipeline/create-datasets.js +7 -14
  76. package/dist/src/pipeline/create-datasets.js.map +1 -1
  77. package/dist/src/types.d.ts +8 -9
  78. package/dist/src/types.d.ts.map +1 -1
  79. package/dist/src/utils.d.ts +45 -37
  80. package/dist/src/utils.d.ts.map +1 -1
  81. package/dist/src/utils.js +47 -2
  82. package/dist/src/utils.js.map +1 -1
  83. package/package.json +4 -4
  84. package/readme.md +22 -19
  85. package/src/api.ts +220 -0
  86. package/src/commands/datasets.ts +33 -38
  87. package/src/commands/providers.ts +34 -42
  88. package/src/commands/repair.ts +5 -1
  89. package/src/commands/replicate.ts +5 -1
  90. package/src/commands/second-copy.ts +5 -1
  91. package/src/commands/setup.ts +12 -35
  92. package/src/db/dedupe-cids.ts +7 -24
  93. package/src/db/find-repair-dataset.ts +17 -28
  94. package/src/db/get-active-data-set-ids.ts +29 -0
  95. package/src/db/get-alternate-provider-urls.ts +43 -0
  96. package/src/db/get-pieces.ts +82 -214
  97. package/src/db/get-repair-provider.ts +10 -30
  98. package/src/db/repair-create.ts +3 -3
  99. package/src/db/replicate-create.ts +13 -21
  100. package/src/db/second-copy-create.ts +2 -2
  101. package/src/middleware.ts +10 -14
  102. package/src/pipeline/add-pieces.ts +52 -24
  103. package/src/pipeline/create-datasets.ts +9 -29
  104. package/src/types.ts +11 -9
  105. package/src/utils.ts +71 -7
  106. package/dist/src/db/find-providers-by-cid.d.ts +0 -9
  107. package/dist/src/db/find-providers-by-cid.d.ts.map +0 -1
  108. package/dist/src/db/find-providers-by-cid.js +0 -43
  109. package/dist/src/db/find-providers-by-cid.js.map +0 -1
  110. package/dist/src/indexer-schema.d.ts +0 -549
  111. package/dist/src/indexer-schema.d.ts.map +0 -1
  112. package/dist/src/indexer-schema.js +0 -56
  113. package/dist/src/indexer-schema.js.map +0 -1
  114. package/src/db/find-providers-by-cid.ts +0 -70
  115. package/src/indexer-schema.ts +0 -77
@@ -1,70 +0,0 @@
1
- import { and, asc, eq, inArray, isNull, lte, or } from 'drizzle-orm'
2
- import type { IndexerDatabase, RepairProvider } from '../types.ts'
3
-
4
- export type FindProvidersByCidOptions = {
5
- indexerDb: IndexerDatabase
6
- cids: readonly string[]
7
- blockNumber: bigint
8
- }
9
-
10
- /**
11
- * Map of piece CID to providers that store that CID at the repair block.
12
- */
13
- export type ProvidersByCid = Record<string, RepairProvider[]>
14
-
15
- /**
16
- * Find alternate providers for each CID, excluding the given provider IDs.
17
- *
18
- * Deleted datasets and removed pieces are ignored. Only approved or endorsed providers are
19
- * included. Every requested CID is present in the result; CIDs with no alternate providers
20
- * map to an empty array.
21
- */
22
- export async function findProvidersByCid({
23
- indexerDb,
24
- cids,
25
- blockNumber,
26
- }: FindProvidersByCidOptions): Promise<ProvidersByCid> {
27
- const schema = indexerDb._.fullSchema
28
- const providersByCid = Object.fromEntries(cids.map((cid) => [cid, []])) as ProvidersByCid
29
- if (cids.length === 0) return providersByCid
30
-
31
- const filters = [
32
- inArray(schema.pieces.cid, [...cids]),
33
- eq(schema.dataSets.deleted, false),
34
- or(isNull(schema.dataSets.pdpEndEpoch), lte(schema.dataSets.pdpEndEpoch, blockNumber)),
35
- eq(schema.pieces.removed, false),
36
- or(eq(schema.providers.approved, true), eq(schema.providers.endorsed, true)),
37
- ]
38
-
39
- // Join through datasets because providers own datasets, while pieces only reference dataset IDs.
40
- const rows = await indexerDb
41
- .selectDistinct({
42
- cid: schema.pieces.cid,
43
- providerId: schema.providers.providerId,
44
- providerAddress: schema.providers.providerAddress,
45
- name: schema.providers.name,
46
- serviceUrl: schema.providers.serviceUrl,
47
- approved: schema.providers.approved,
48
- endorsed: schema.providers.endorsed,
49
- })
50
- .from(schema.pieces)
51
- .innerJoin(schema.dataSets, eq(schema.pieces.dataSetId, schema.dataSets.dataSetId))
52
- .innerJoin(schema.providers, eq(schema.dataSets.providerId, schema.providers.providerId))
53
- .where(and(...filters))
54
- .orderBy(asc(schema.pieces.cid), asc(schema.providers.providerId))
55
-
56
- for (const { cid, ...provider } of rows) {
57
- if (provider.providerAddress && provider.serviceUrl && provider.name) {
58
- providersByCid[cid]?.push({
59
- providerId: provider.providerId,
60
- providerAddress: provider.providerAddress,
61
- name: provider.name,
62
- serviceUrl: provider.serviceUrl,
63
- approved: provider.approved,
64
- endorsed: provider.endorsed,
65
- })
66
- }
67
- }
68
-
69
- return providersByCid
70
- }
@@ -1,77 +0,0 @@
1
- import { relations } from 'drizzle-orm'
2
- import { bigint, boolean, index, jsonb, pgSchema, primaryKey, text } from 'drizzle-orm/pg-core'
3
- import type { Address } from 'viem'
4
-
5
- export type JsonRecord = Record<string, string>
6
-
7
- const schema = pgSchema('early-repair')
8
-
9
- export const providers = schema.table(
10
- 'providers',
11
- {
12
- providerId: bigint('provider_id', { mode: 'bigint' }).primaryKey(),
13
- providerAddress: text('provider_address').$type<Address>(),
14
- name: text('name'),
15
- serviceUrl: text('service_url'),
16
- providerActive: boolean('provider_active').notNull(),
17
- pdpProductActive: boolean('pdp_product_active').notNull(),
18
- approved: boolean('approved').notNull().default(false),
19
- endorsed: boolean('endorsed').notNull().default(false),
20
- createdAtBlock: bigint('created_at_block', { mode: 'bigint' }),
21
- updatedAtBlock: bigint('updated_at_block', { mode: 'bigint' }).notNull(),
22
- },
23
- (table) => [index('providers_provider_address_idx').on(table.providerAddress)]
24
- )
25
-
26
- export const providersRelations = relations(providers, ({ many }) => ({
27
- dataSets: many(dataSets),
28
- }))
29
-
30
- export const dataSets = schema.table(
31
- 'data_sets',
32
- {
33
- dataSetId: bigint('data_set_id', { mode: 'bigint' }).primaryKey(),
34
- providerId: bigint('provider_id', { mode: 'bigint' }).notNull(),
35
- metadata: jsonb('metadata').$type<JsonRecord | null>(),
36
- payer: text('payer').notNull(),
37
- source: text('source'),
38
- withCdn: boolean('with_cdn').notNull(),
39
- withIpfsIndexing: boolean('with_ipfs_indexing').notNull(),
40
- pdpEndEpoch: bigint('pdp_end_epoch', { mode: 'bigint' }).notNull(),
41
- deleted: boolean('deleted').notNull(),
42
- createdAtBlock: bigint('created_at_block', { mode: 'bigint' }).notNull(),
43
- updatedAtBlock: bigint('updated_at_block', { mode: 'bigint' }).notNull(),
44
- },
45
- (table) => [index('data_sets_provider_id_idx').on(table.providerId)]
46
- )
47
-
48
- export const dataSetsRelations = relations(dataSets, ({ one, many }) => ({
49
- provider: one(providers, {
50
- fields: [dataSets.providerId],
51
- references: [providers.providerId],
52
- }),
53
- pieces: many(pieces),
54
- }))
55
-
56
- export const pieces = schema.table(
57
- 'pieces',
58
- {
59
- dataSetId: bigint('data_set_id', { mode: 'bigint' }).notNull(),
60
- pieceId: bigint('piece_id', { mode: 'bigint' }).notNull(),
61
- cid: text('cid').notNull(),
62
- rawSize: bigint('raw_size', { mode: 'bigint' }).notNull(),
63
- metadata: jsonb('metadata').$type<JsonRecord | null>(),
64
- removed: boolean('removed').notNull(),
65
- addedAtBlock: bigint('added_at_block', { mode: 'bigint' }).notNull(),
66
- removedAtBlock: bigint('removed_at_block', { mode: 'bigint' }),
67
- updatedAtBlock: bigint('updated_at_block', { mode: 'bigint' }).notNull(),
68
- },
69
- (table) => [primaryKey({ columns: [table.dataSetId, table.pieceId] }), index('pieces_cid_idx').on(table.cid)]
70
- )
71
-
72
- export const piecesRelations = relations(pieces, ({ one }) => ({
73
- dataSet: one(dataSets, {
74
- fields: [pieces.dataSetId],
75
- references: [dataSets.dataSetId],
76
- }),
77
- }))