typescript: Add types in several packages (#9583)

* feat: add types for fs (#9515)

* feat: add types for fs

* fix: update from review

* fix: update devDep

* feat: add types from @xen-orchestra/fs/path

* feat: export types based on async-each

* fix: remove ts-expect-error because async-each is now typed

* fix: export backups types and packages

* fix: update tsconfig async-each and fix types in MergeRemoteDisk

* fix: extractIdsFromSimplePattern from backups

* fix: package.json

* feat: export vhd-lib types

* feat(disks): export types

* fix(backups/disks): make params optional

* fix(backups/disks): small update in jsdoc

* bump: update yarn.lock

* fix: update vhd-lib exports

* fix(vhd-lib): update package exports

* fix: revert to previous import

* fix: new approach without exports

* fix: revert types except for asyncEach, openDisk

* fix(disks): import in vhd-lib

* fix(remoteVhdDisk): update typedef
This commit is contained in:
Pierre Brunet
2026-03-16 10:55:18 +01:00
committed by GitHub
parent 2aff87d6d6
commit 45aee36ae7
6 changed files with 39 additions and 8 deletions

5
@vates/async-each/index.d.ts vendored Normal file
View File

@@ -0,0 +1,5 @@
export function asyncEach<Item>(
iterable: Iterable<Item> | AsyncIterable<Item>,
iteratee: (item: Item, index: number, iterable: Iterable<Item> | AsyncIterable<Item>) => Promise<void>,
opts?: { concurrency?: number; signal?: AbortSignal; stopOnError?: boolean }
): Promise<void>

View File

@@ -24,6 +24,7 @@
"url": "https://vates.fr"
},
"license": "ISC",
"types": "index.d.ts",
"version": "1.0.1",
"engines": {
"node": ">=8.10"

View File

@@ -22,6 +22,7 @@ const { warn } = createLogger('remote-disk:merge')
* @property {number} mergedDataSize
* @property {'mergeBlocks' | 'cleanup'} step
* @property {number} diskSize
* @typedef {(message: string, data?: Record<string, unknown>) => void} Logger
*/
export class MergeRemoteDisk {
@@ -85,11 +86,11 @@ export class MergeRemoteDisk {
/**
* @param {FileAccessor} handler
* @param {Object} params
* @param {Function} params.onProgress
* @param {Logger | Function} params.logInfo
* @param {boolean} params.removeUnused
* @param {number} params.mergeBlockConcurrency
* @param {number} params.writeStateDelay
* @param {Function} [params.onProgress]
* @param {Logger | Function} [params.logInfo]
* @param {boolean} [params.removeUnused]
* @param {number} [params.mergeBlockConcurrency]
* @param {number} [params.writeStateDelay]
*/
constructor(
handler,
@@ -202,8 +203,8 @@ export class MergeRemoteDisk {
parentDisk.setAllocatedBlocks(alreadyMergedBlocks)
} else {
this.#state.child = { uuid: childDisk.getUuid() ?? 0 }
this.#state.parent = { uuid: parentDisk.getUuid() ?? 0 }
this.#state.child = { uuid: childDisk.getUuid() ?? undefined }
this.#state.parent = { uuid: parentDisk.getUuid() ?? undefined }
// Finds first allocated block for the 2 following loops
while (this.#state.currentBlock < getMaxBlockCount && !childDisk.hasBlock(this.#state.currentBlock)) {

View File

@@ -0,0 +1,21 @@
import { RemoteVhdDisk } from './RemoteVhdDisk.mjs'
export { RemoteDisk } from './RemoteDisk.mjs'
export { openDiskChain } from './openDiskChain.mjs'
/**
* @typedef {import('../../disk-transform/src/FileAccessor.mjs').FileAccessor} FileAccessor
* @typedef {import('./RemoteDisk.mjs').RemoteDisk} RemoteDisk
*/
/**
* @param {Object} params
* @param {FileAccessor} params.handler
* @param {string} params.path
* @returns {Promise<RemoteDisk>}
*/
export async function openDisk({ handler, path }) {
const disk = new RemoteVhdDisk({ handler, path })
await disk.init()
return disk
}

View File

@@ -68,5 +68,9 @@
"author": {
"name": "Vates SAS",
"url": "https://vates.fr"
},
"exports": {
"./disks": "./disks/index.mjs",
"./*": "./*"
}
}

View File

@@ -1,4 +1,3 @@
// @ts-expect-error async-each is not typed
import { asyncEach } from '@vates/async-each'
import { Disk, DiskBlock } from '../Disk.mjs'
import { DebugDisk } from './DebugDisk.mjs'