Skip to content

Commit

Permalink
change partOf -> parts
Browse files Browse the repository at this point in the history
  • Loading branch information
gobengo committed Jan 9, 2024
1 parent d35cfe6 commit d35bf20
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
15 changes: 10 additions & 5 deletions packages/api/test/fixtures/pgrest/get-user-uploads.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export default [
}
],
type: 'Car',
updated: '2021-07-14T19:27:14.934572+00:00'
updated: '2021-07-14T19:27:14.934572+00:00',
parts: []
},
{
_id: '8',
Expand All @@ -48,7 +49,8 @@ export default [
}
],
type: 'Car',
updated: '2021-07-14T19:27:14.934572+00:00'
updated: '2021-07-14T19:27:14.934572+00:00',
parts: []
},
{
_id: '1',
Expand All @@ -59,7 +61,8 @@ export default [
created: '2021-07-09T16:20:33.946845+00:00',
updated: '2021-07-09T16:20:33.946845+00:00',
deals: [],
pins: []
pins: [],
parts: []
},
{
_id: '2',
Expand All @@ -70,7 +73,8 @@ export default [
created: '2021-07-09T10:40:35.408884+00:00',
updated: '2021-07-09T10:40:35.408884+00:00',
deals: [],
pins: []
pins: [],
parts: []
},
{
_id: '3',
Expand All @@ -81,6 +85,7 @@ export default [
created: '2021-07-09T10:36:05.862862+00:00',
updated: '2021-07-09T10:36:05.862862+00:00',
deals: [],
pins: []
pins: [],
parts: []
}
]
7 changes: 5 additions & 2 deletions packages/db/db-client-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,11 @@ export type UploadItemOutput = {
dagSize?: definitions['content']['dag_size']
pins: Array<PinItemOutput>,
deals: Array<Deal>
// array of links to things containing this Upload (e.g. CARs)
partOf: Array<string>
/**
* the graph from `cid` can be recreated from the blocks in these parts
* @see https://github.com/web3-storage/content-claims#partition-claim
*/
parts: Array<string>
}

export type UploadOutput = definitions['upload'] & {
Expand Down
8 changes: 4 additions & 4 deletions packages/db/test/upload.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ describe('upload', () => {
assert.ok(userUploads.find(upload => upload.cid === sourceCid))
})

it('lists user uploads with CAR links in partOf', async () => {
it('lists user uploads with CAR links in parts', async () => {
const contentCid = 'bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi'
const sourceCid = 'QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR'
const exampleCarParkUrl = 'https://carpark-dev.web3.storage/bagbaiera6xcx7hiicm7sc523axbjf2otuu5nptt6brdzt4a5ulgn6qcfdwea/bagbaiera6xcx7hiicm7sc523axbjf2otuu5nptt6brdzt4a5ulgn6qcfdwea.car'
Expand All @@ -303,12 +303,12 @@ describe('upload', () => {
for (const upload of uploads) {
// backupUrls raw is private
assert.ok(!('backupUrls' in upload), 'upload does not have backupUrls property')
assert.ok(Array.isArray(upload.partOf), 'upload.partOf is an array')
assert.ok(Array.isArray(upload.parts), 'upload.parts is an array')
}
const namedUpload = uploads.find(u => u.name === name)
assert.deepEqual(namedUpload.partOf, [
assert.deepEqual(namedUpload.parts, [
// this corresponds to `exampleCarParkUrl`
'ipfs://bagbaiera6xcx7hiicm7sc523axbjf2otuu5nptt6brdzt4a5ulgn6qcfdwea'
'bagbaiera6xcx7hiicm7sc523axbjf2otuu5nptt6brdzt4a5ulgn6qcfdwea'
])
})

Expand Down
7 changes: 4 additions & 3 deletions packages/db/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export function normalizeUpload (upload) {
delete nUpload.content
delete nUpload.sourceCid

const partOf = [...carUrlsFromBackupUrls(backupUrls)]
/** @type {import('./db-client-types').UploadItemOutput['parts']} */
const parts = [...carUrlsFromBackupUrls(backupUrls)]

return {
...nUpload,
Expand All @@ -20,7 +21,7 @@ export function normalizeUpload (upload) {
pins: normalizePins(upload.content.pins, {
isOkStatuses: true
}),
partOf
parts
}
}

Expand All @@ -36,7 +37,7 @@ function carUrlsFromBackupUrls (backupUrls) {
// there are also backupUrls from s3 with .car suffix and path stem is base32(multihash) (not a CID). exclude those.
const carCidFileSuffixMatch = String(backupUrl).match(/\/(ba[^/]+).car$/)
if (!carCidFileSuffixMatch) continue
carCIDUrls.add(`ipfs://${carCidFileSuffixMatch[1]}`)
carCIDUrls.add(carCidFileSuffixMatch[1])
}
return carCIDUrls
}
Expand Down

0 comments on commit d35bf20

Please sign in to comment.