Skip to content

Commit 7a361b5

Browse files
committed
fix: don't reference unpublished hypercore-storage types in migration.js exports
hypercore-storage ships no types and our declarations for it in types/ are not published, so the emitted dist/migration.d.ts ended with a bare 'import CorestoreStorage from hypercore-storage' that gave consumers TS2307 (or silent any with skipLibCheck). Type the exported signatures with a subset of CorestoreStorage instead, making dist/migration.d.ts self-contained.
1 parent 9119ec6 commit 7a361b5

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/migration.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,21 @@ export async function storageForProject(projectCorestorePath) {
134134
}
135135
}
136136

137+
/**
138+
* Structural subset of hypercore-storage's `CorestoreStorage` used by the
139+
* migration. Referencing the `CorestoreStorage` type in exported signatures
140+
* would break the published `migration.d.ts`: hypercore-storage ships no
141+
* types, and our ambient declarations for it are not published.
142+
* @typedef {object} MigrationStorage
143+
* @property {() => Promise<void>} ready
144+
* @property {() => Promise<void>} close
145+
* @property {() => AsyncIterable<{ discoveryKey: Buffer }>} createCoreStream
146+
* @property {(discoveryKey: Buffer) => Promise<unknown>} resumeCore
147+
*/
148+
137149
/**
138150
* @param {string} path
139-
* @returns
151+
* @returns {MigrationStorage}
140152
*/
141153
export function makeDefaultCorestoreStorage(path) {
142154
return new CorestoreStorage(path, {
@@ -152,6 +164,7 @@ export function makeDefaultCorestoreStorage(path) {
152164
*
153165
* @param {string} managerPath - Path to the MapeoManager storage folder
154166
* @param {(doneSoFar: number, totalCores: number) => void} [onProgress] - Callback called after each core migrates
167+
* @param {(path: string) => MigrationStorage} [makeStorage] - Storage factory, only overridden in tests
155168
* @returns {Promise<Record<string, { migrated: boolean, error?: Error }>>}
156169
* Map of project IDs to migration status
157170
*/
@@ -190,7 +203,7 @@ export async function migrateStorage(
190203
await storage.ready()
191204

192205
// Run migration on corestore
193-
await migrateStore(storage, {
206+
await migrateStore(/** @type {any} */ (storage), {
194207
version: 1,
195208
dryRun: false,
196209
gc: true,

0 commit comments

Comments
 (0)