Skip to content

Commit 1ed5283

Browse files
fix: use StorageManager for upload (#262)
* use StorageManager for upload * mock StorageManager.upload * fix: use existing context * deps: update synapse-sdk --------- Co-authored-by: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com>
1 parent 565e126 commit 1ed5283

File tree

6 files changed

+14
-11
lines changed

6 files changed

+14
-11
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@
103103
"homepage": "https://github.com/filecoin-project/filecoin-pin#readme",
104104
"dependencies": {
105105
"@clack/prompts": "^0.11.0",
106-
"@filoz/synapse-sdk": "^0.35.3",
106+
"@filoz/synapse-core": "^0.1.3",
107+
"@filoz/synapse-sdk": "^0.36.0",
107108
"@helia/unixfs": "^6.0.1",
108109
"@ipld/car": "^5.4.2",
109110
"commander": "^14.0.1",

src/core/data-set/get-data-set-pieces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* @module core/data-set/get-data-set-pieces
77
*/
88

9+
import { getSizeFromPieceCID } from '@filoz/synapse-core/piece'
910
import { METADATA_KEYS, type StorageContext, type Synapse, WarmStorageService } from '@filoz/synapse-sdk'
10-
import { getSizeFromPieceCID } from '@filoz/synapse-sdk/piece'
1111
import { isStorageContextWithDataSetId } from './type-guards.js'
1212
import type {
1313
DataSetPiecesResult,

src/core/upload/synapse.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This module provides a reusable upload pattern for CAR files to Filecoin
55
* via Synapse SDK, used by both the import command and pinning server.
66
*/
7-
import type { PieceCID, UploadOptions } from '@filoz/synapse-sdk'
7+
import type { PieceCID } from '@filoz/synapse-sdk'
88
import { METADATA_KEYS, type ProviderInfo, type UploadCallbacks } from '@filoz/synapse-sdk'
99
import type { CID } from 'multiformats/cid'
1010
import type { Logger } from 'pino'
@@ -129,15 +129,16 @@ export async function uploadToSynapse(
129129
}
130130

131131
// Upload using Synapse with IPFS root CID metadata
132-
const uploadOptions: UploadOptions = {
132+
const uploadOptions: Parameters<typeof synapseService.synapse.storage.upload>[1] = {
133133
...uploadCallbacks,
134134
metadata: {
135135
...(options.pieceMetadata ?? {}),
136136
[METADATA_KEYS.IPFS_ROOT_CID]: rootCid.toString(), // Associate piece with IPFS root CID
137137
},
138+
context: synapseService.storage,
138139
}
139140

140-
const synapseResult = await synapseService.storage.upload(carData, uploadOptions)
141+
const synapseResult = await synapseService.synapse.storage.upload(carData, uploadOptions)
141142

142143
// Log success
143144
logger.info(

src/test/mocks/synapse-mocks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export class MockSynapse extends EventEmitter {
9898
// Storage namespace matches SDK structure
9999
public readonly storage = {
100100
createContext: this.createStorageContext.bind(this),
101+
upload: (data: any, options: any) => this._storageContext?.upload(data, options),
101102
}
102103

103104
/**

src/test/unit/core-data-set.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ vi.mock('@filoz/synapse-sdk', async () => {
8585
})
8686

8787
// Mock piece size calculation
88-
vi.mock('@filoz/synapse-sdk/piece', () => ({
88+
vi.mock('@filoz/synapse-core/piece', () => ({
8989
getSizeFromPieceCID: vi.fn((cid: { toString: () => string } | string) => {
9090
// Map specific CIDs to sizes for testing
9191
const cidString = typeof cid === 'string' ? cid : cid.toString()
@@ -97,11 +97,11 @@ vi.mock('@filoz/synapse-sdk/piece', () => ({
9797
}))
9898
vi.mock('@filoz/synapse-sdk/sp-registry', () => {
9999
return {
100-
SPRegistryService: vi.fn().mockImplementation(function () {
101-
return {
102-
getProviders: mockGetProviders,
100+
SPRegistryService: class {
101+
async getProviders(providerIds: number[]) {
102+
return mockGetProviders(providerIds)
103103
}
104-
}),
104+
},
105105
}
106106
})
107107

src/test/unit/data-set.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ vi.mock('@filoz/synapse-sdk', async () => {
160160
})
161161

162162
// Mock piece size calculation
163-
vi.mock('@filoz/synapse-sdk/piece', () => ({
163+
vi.mock('@filoz/synapse-core/piece', () => ({
164164
getSizeFromPieceCID: vi.fn(() => {
165165
// Return a realistic piece size (1 MiB = 1048576 bytes)
166166
return 1048576

0 commit comments

Comments
 (0)