@siafoundation/sia-storage 0.1.0 → 0.1.2
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.
- package/README.md +93 -1
- package/dist/chunk-QYQQIWFH.js +74 -0
- package/dist/chunk-QYQQIWFH.js.map +1 -0
- package/dist/cli.js +13 -0
- package/dist/index.d.ts +89 -1
- package/dist/index.js +303 -0
- package/dist/index.js.map +1 -1
- package/dist/index.node.cjs +52 -12
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.ts +32 -6
- package/dist/next.d.ts +3 -0
- package/dist/next.js +12 -0
- package/dist/sia-storage-sw.js +2 -0
- package/dist/stream-worker.d.ts +51 -0
- package/dist/stream-worker.js +441 -0
- package/dist/stream-worker.js.map +1 -0
- package/dist/vite.d.ts +39 -0
- package/dist/vite.js +32 -0
- package/package.json +26 -10
- package/wasm/sia_storage_wasm.d.ts +21 -12
- package/wasm/sia_storage_wasm.js +33 -32
- package/wasm/sia_storage_wasm_bg.wasm +0 -0
- package/wasm/sia_storage_wasm_bg.wasm.d.ts +8 -8
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Browser entry; lazily initializes WASM on first use.\n\nimport wasmInit from '../wasm/sia_storage_wasm.js'\n\nlet initPromise: Promise<unknown> | null = null\n\n/** Initialize the WASM module. Safe to call multiple times. */\nexport async function initSia(): Promise<void> {\n if (!initPromise) initPromise = wasmInit()\n await initPromise\n}\n\nexport {\n AppKey,\n Builder,\n KeyRecord,\n ObjectEvent,\n PackedUpload,\n PinnedObject,\n Sdk,\n SharedSdk,\n SharingKey,\n encodedSize,\n generateRecoveryPhrase,\n setLogger,\n validateRecoveryPhrase,\n} from '../wasm/sia_storage_wasm.js'\nexport type {\n Account,\n AppMetadata,\n DownloadOptions,\n Host,\n HostQuery,\n KeyStats,\n PinnedSlab,\n Sector,\n SealedObject,\n ShardProgress,\n Slab,\n UploadOptions,\n} from '../wasm/sia_storage_wasm.js'\n"],"mappings":";AAEA,OAAO,cAAc;AAUrB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAtBP,IAAI,cAAuC;AAG3C,eAAsB,UAAyB;AAC7C,MAAI,CAAC,YAAa,eAAc,SAAS;AACzC,QAAM;AACR;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/relay.ts","../src/stream/fallback.ts","../src/stream/page.ts"],"sourcesContent":["// Browser entry; lazily initializes WASM on first use.\n\nimport wasmInit from '../wasm/sia_storage_wasm.js'\n\nexport { detectPrivateRelay } from './relay'\nexport { enableStreaming, openStreams } from './stream/page'\nexport type {\n AppCredentials,\n CredentialsFor,\n FileOptions,\n SharedCredentials,\n StreamedFile,\n Streams,\n StreamingOptions,\n} from './stream/page'\n\nlet initPromise: Promise<unknown> | null = null\n\n/** Initialize the WASM module. Safe to call multiple times. */\nexport async function initSia(): Promise<void> {\n if (!initPromise) initPromise = wasmInit()\n await initPromise\n}\n\nexport {\n AppKey,\n Builder,\n KeyRecord,\n ObjectEvent,\n PackedUpload,\n PinnedObject,\n Sdk,\n SharedSdk,\n SharingKey,\n encodedSize,\n generateRecoveryPhrase,\n setLogger,\n validateRecoveryPhrase,\n} from '../wasm/sia_storage_wasm.js'\nexport type {\n Account,\n AppMetadata,\n DownloadOptions,\n Host,\n HostQuery,\n KeyStats,\n PinnedSlab,\n Sector,\n SealedObject,\n ShardProgress,\n Slab,\n UploadOptions,\n} from '../wasm/sia_storage_wasm.js'\n","/**\n * Whether the visitor is on iCloud Private Relay, which the SDK does not work\n * through. Show them a way to turn it off in iCloud settings.\n *\n * Asks check-relay.sia.storage, a Sia Foundation service that compares the\n * caller's address with Apple's published list of Private Relay addresses.\n * Only Safari's traffic goes through Private Relay, so other browsers resolve\n * false without a request. The answer is kept for the page's lifetime, and a\n * failure to get one resolves false.\n */\nconst RELAY_CHECK_URL = 'https://check-relay.sia.storage'\nconst TIMEOUT = 5000\n\nlet answer: Promise<boolean> | undefined\n\nexport function detectPrivateRelay(): Promise<boolean> {\n answer ??=\n typeof navigator === 'undefined'\n ? Promise.resolve(false)\n : checkPrivateRelay(navigator.userAgent, fetch)\n return answer\n}\n\n/** `detectPrivateRelay` without the caching, for tests. */\nexport async function checkPrivateRelay(\n userAgent: string,\n request: typeof fetch,\n): Promise<boolean> {\n const safari =\n /Version\\/\\S+.*Safari\\//.test(userAgent) &&\n !/Chrome|Chromium|CriOS|FxiOS|Edg|OPR|OPiOS|Ddg\\/|Android/.test(userAgent)\n if (!safari) return false\n try {\n const response = await request(RELAY_CHECK_URL, {\n signal: AbortSignal.timeout(TIMEOUT),\n })\n const body = (await response.json()) as { relay?: unknown }\n return body.relay === true\n } catch {\n return false\n }\n}\n","/**\n * Previews and downloads for pages that cannot stream through the service\n * worker, where the page reads the object itself. A preview holds the whole\n * file in memory as a Blob. A download writes straight to disk through the\n * save picker where the browser has one, and buffers a Blob where it does not.\n */\nimport type { PinnedObject, Sdk, SharedSdk } from '../../wasm/sia_storage_wasm.js'\n\ntype AnySdk = Pick<Sdk | SharedSdk, 'download'>\n\ntype Chunk = Uint8Array<ArrayBuffer>\n\n// The File System Access save picker, in Chromium only and not yet in\n// TypeScript's DOM types.\ntype SavePicker = (options: {\n suggestedName: string\n}) => Promise<FileSystemFileHandle & { createWritable(): Promise<WritableStream<Chunk>> }>\n\nfunction chunks(stream: ReadableStream): ReadableStreamDefaultReader<Chunk> {\n return stream.getReader() as ReadableStreamDefaultReader<Chunk>\n}\n\n/** The whole object as a Blob, stopping early when `signal` aborts. */\nexport async function readBlob(\n sdk: AnySdk,\n object: PinnedObject,\n type: string | undefined,\n onProgress: (bytesDownloaded: number) => void,\n signal: AbortSignal,\n) {\n const reader = chunks(sdk.download(object))\n const onAbort = () => void reader.cancel()\n signal.addEventListener('abort', onAbort)\n const parts: Chunk[] = []\n let bytesDownloaded = 0\n try {\n while (true) {\n const { done, value } = await reader.read()\n if (done) break\n parts.push(value)\n bytesDownloaded += value.length\n onProgress(bytesDownloaded)\n }\n } finally {\n signal.removeEventListener('abort', onAbort)\n }\n signal.throwIfAborted()\n return new Blob(parts, type ? { type } : {})\n}\n\nexport function saveBlob(blob: Blob, name: string) {\n const url = URL.createObjectURL(blob)\n const a = document.createElement('a')\n a.href = url\n a.download = name\n a.click()\n // Some browsers cancel the download if the URL goes away in the same task.\n setTimeout(() => URL.revokeObjectURL(url), 0)\n}\n\n/** False if the visitor closes the save picker. */\nexport async function saveToDisk(\n sdk: AnySdk,\n object: PinnedObject,\n name: string,\n type: string | undefined,\n onProgress: (bytesDownloaded: number) => void,\n) {\n const picker = (window as { showSaveFilePicker?: SavePicker })\n .showSaveFilePicker\n if (!picker) {\n const blob = await readBlob(\n sdk,\n object,\n type,\n onProgress,\n new AbortController().signal,\n )\n saveBlob(blob, name)\n return true\n }\n\n // The picker must open inside the click that asked for it, so nothing is\n // awaited before this call.\n let handle: Awaited<ReturnType<SavePicker>>\n try {\n handle = await picker.call(window, { suggestedName: name })\n } catch (e) {\n if (e instanceof DOMException && e.name === 'AbortError') return false\n throw e\n }\n let bytesDownloaded = 0\n const progress = new TransformStream<Chunk, Chunk>({\n transform(chunk, controller) {\n bytesDownloaded += chunk.length\n onProgress(bytesDownloaded)\n controller.enqueue(chunk)\n },\n })\n const file = await handle.createWritable()\n await (sdk.download(object) as ReadableStream<Chunk>)\n .pipeThrough(progress)\n .pipeTo(file)\n return true\n}\n","/**\n * The page side of streaming.\n *\n * `openStreams` hands out same-origin URLs that the library's service worker\n * answers with ranged reads of an object, so a `<video>` seeks without loading\n * the whole file and a download goes to the browser's download manager instead\n * of the page's memory. The worker connects its own SDK of the same kind, with\n * credentials this page hands it over a message port and it keeps in memory.\n * Where the worker is unavailable, the same calls read the object in the page.\n */\nimport type {\n AppKey,\n AppMetadata,\n PinnedObject,\n SealedObject,\n Sdk,\n SharedSdk,\n} from '../../wasm/sia_storage_wasm.js'\nimport { reportStreamError, streamErrorMessage } from './errors'\nimport { readBlob, saveToDisk } from './fallback'\nimport {\n type ClientReply,\n type Connection,\n isAppMetadata,\n type PageMessage,\n requestReply,\n type SourceReply,\n streamPath,\n type WorkerMessage,\n} from './protocol'\n\nexport type StreamingOptions = {\n /** Where the site serves the worker file. Defaults to `/sia-storage-sw.js`. */\n workerUrl?: string\n /** The worker's scope. Defaults to the directory `workerUrl` is in. */\n scope?: string\n /** `'module'` when `workerUrl` is an ES module worker of your own. */\n type?: WorkerType\n}\n\n/** What a `SharedSdk` was connected with. */\nexport type SharedCredentials = { indexerUrl: string; seed: string }\n\n/** What an `Sdk`'s `Builder` was made with. The key comes from `sdk.appKey()`. */\nexport type AppCredentials = { indexerUrl: string; appMeta: AppMetadata }\n\n/** The credentials `openStreams` takes for each kind of SDK. */\nexport type CredentialsFor<S extends Sdk | SharedSdk> = S extends SharedSdk\n ? SharedCredentials\n : AppCredentials\n\nexport type FileOptions = {\n /** Used for downloads and for the browser's media handling. */\n name: string\n /** The MIME type. Defaults to `application/octet-stream`. */\n type?: string\n /** A failure after streaming started. Without it, failures are logged. */\n onError?: (message: string) => void\n /** Bytes read so far, when the page reads the object itself. */\n onProgress?: (bytesDownloaded: number) => void\n}\n\n/** A URL for an `<img>`, `<video>`, `<audio>`, `<iframe>` or `fetch`. */\nexport type StreamedFile = {\n url: string\n /** The whole file, when the page read it itself instead of streaming. */\n blob?: Blob\n /** Frees the URL. Call it when the element showing it goes away. */\n release(): void\n}\n\nexport type Streams = {\n /** A URL serving the object. Streams where it can, else reads it whole. */\n url(\n object: PinnedObject,\n options: FileOptions & { signal?: AbortSignal },\n ): Promise<StreamedFile>\n /**\n * Saves the object, from a click handler. Streams to the browser's download\n * manager where it can, else opens the save picker, else saves a Blob.\n * Awaits nothing before the picker opens, so the browser still counts it as\n * part of the click.\n */\n download(\n object: PinnedObject,\n options: FileOptions,\n ): Promise<'streaming' | 'saved' | 'cancelled'>\n /**\n * Cancels the streams this handle made. Other handles on the same SDK keep\n * theirs. Call it when you stop using the handle.\n */\n close(): void\n}\n\nconst DEFAULT_WORKER_URL = '/sia-storage-sw.js'\n// Covers registering the worker, its first activation, and the handshake.\nconst SETUP_TIMEOUT = 5000\n\n/** A stream URL this page handed out, and what the worker needs to serve it. */\ntype StreamEntry = {\n handle: Opened\n objectId: string\n sealed: SealedObject | undefined\n size: number\n name: string\n mime: string\n onError: ((message: string) => void) | undefined\n}\n\n/**\n * One `openStreams` call, and how the worker reconnects its SDK. Each call gets\n * its own session, so closing one handle leaves another on the same SDK open.\n */\ntype Opened = { session: string; connection: Connection; appKey?: AppKey }\n\nconst entries = new Map<string, StreamEntry>()\nconst opened = new Set<Opened>()\nlet worker: { clientId: string; scope: string } | undefined\nlet initialization: Promise<boolean> | undefined\nlet initOptions: StreamingOptions = {}\n// The page's controller when setup last failed. Undefined unless it failed.\nlet failedController: ServiceWorker | null | undefined\n\n/**\n * Registers the streaming worker and resolves whether this page can stream.\n * `openStreams` calls it with the defaults, so call it yourself only to pass\n * options, and before the first `openStreams`. Later calls return the first\n * call's answer, except when setup failed or timed out and a different worker\n * has since taken control of the page. Then the next call tries again, with\n * the first call's options.\n */\nexport function enableStreaming(\n options: StreamingOptions = {},\n): Promise<boolean> {\n if (!initialization) {\n initOptions = options\n } else if (failedController === undefined) {\n return initialization\n } else {\n // Only a new controller is worth a retry. Retrying against the same one,\n // or none, would wait out SETUP_TIMEOUT again on every call.\n const controller = navigator.serviceWorker.controller\n if (!controller || controller === failedController) return initialization\n }\n failedController = undefined\n initialization = initialize(initOptions).catch(() => {\n failedController = navigator.serviceWorker.controller\n return false\n })\n return initialization\n}\n\nasync function initialize({\n workerUrl = DEFAULT_WORKER_URL,\n scope,\n type,\n}: StreamingOptions) {\n if (\n typeof window === 'undefined' ||\n !('serviceWorker' in navigator) ||\n !window.isSecureContext\n ) {\n return false\n }\n const { serviceWorker } = navigator\n serviceWorker.addEventListener('message', onWorkerMessage)\n const deadline = AbortSignal.timeout(SETUP_TIMEOUT)\n // A hard reload (Shift+Reload) loads the page without its worker, and an\n // active worker only claims pages when it first activates. Waiting would\n // run out the whole deadline, so fall back at once.\n const existing = await within(serviceWorker.getRegistration(), deadline)\n if (existing?.active && !serviceWorker.controller) return false\n const registration = await within(\n serviceWorker\n .register(workerUrl, { ...(scope && { scope }), ...(type && { type }) })\n .then(() => serviceWorker.ready),\n deadline,\n )\n // On a first visit, the page is controlled once the new worker claims it.\n if (!serviceWorker.controller) {\n await within(\n new Promise((resolve) =>\n serviceWorker.addEventListener('controllerchange', resolve, {\n once: true,\n }),\n ),\n deadline,\n )\n }\n const controller = serviceWorker.controller\n if (!controller) return false\n const request = { type: 'sia-client' } satisfies PageMessage\n const reply = (await requestReply(controller, request, {\n signal: deadline,\n })) as ClientReply\n if (!reply.supported) return false\n worker = { clientId: reply.clientId, scope: registration.scope }\n return true\n}\n\n/** `promise`, or a rejection if `signal` aborts first. */\nfunction within<T>(promise: Promise<T>, signal: AbortSignal): Promise<T> {\n return new Promise((resolve, reject) => {\n signal.throwIfAborted()\n signal.addEventListener('abort', () => reject(signal.reason), {\n once: true,\n })\n promise.then(resolve, reject)\n })\n}\n\n/**\n * Previews and downloads for one SDK's objects, from an `Sdk` or a `SharedSdk`.\n *\n * The worker cannot use this page's SDK, so it connects its own with\n * `credentials`: the indexer URL and seed a `SharedSdk` was connected with, or\n * the indexer URL and app metadata an `Sdk`'s `Builder` was made with.\n */\nexport function openStreams<S extends Sdk | SharedSdk>(\n sdk: S,\n credentials: CredentialsFor<S>,\n): Streams {\n const handle = openedFor(sdk, credentials)\n opened.add(handle)\n // Started now, so it has usually finished by the first download click,\n // which cannot wait for it.\n void enableStreaming()\n return {\n async url(object, options) {\n await enableStreaming()\n options.signal?.throwIfAborted()\n const stream = streamUrl(handle, object, options)\n if (stream) return stream\n const blob = await readBlob(\n sdk,\n object,\n options.type,\n options.onProgress ?? (() => {}),\n options.signal ?? new AbortController().signal,\n )\n const url = URL.createObjectURL(blob)\n return { url, blob, release: () => URL.revokeObjectURL(url) }\n },\n async download(object, options) {\n const stream = streamUrl(handle, object, options)\n if (stream) {\n // A hidden frame, so a worker error loads there instead of replacing\n // the page. Nothing signals when the download has started, so it stays.\n const frame = document.createElement('iframe')\n frame.hidden = true\n frame.src = `${stream.url}?download=1`\n document.body.append(frame)\n // Never released here. The URL stays valid until `close()`, so\n // delayed starts and browser retries still work.\n return 'streaming'\n }\n const saved = await saveToDisk(\n sdk,\n object,\n options.name,\n options.type,\n options.onProgress ?? (() => {}),\n )\n return saved ? 'saved' : 'cancelled'\n },\n close() {\n releaseStreams(handle)\n },\n }\n}\n\n/**\n * Checked at runtime too, for callers without types. An `Sdk` is told apart\n * by its `appKey()`, which a `SharedSdk` does not have.\n */\nfunction openedFor(sdk: Sdk | SharedSdk, credentials: unknown): Opened {\n const { indexerUrl, seed, appMeta } = (credentials ?? {}) as {\n indexerUrl?: unknown\n seed?: unknown\n appMeta?: unknown\n }\n const session = crypto.randomUUID()\n if (typeof (sdk as Partial<Sdk>).appKey === 'function') {\n if (typeof indexerUrl !== 'string' || !isAppMetadata(appMeta)) {\n throw new TypeError('openStreams(Sdk) needs { indexerUrl, appMeta }.')\n }\n const appKey = (sdk as Sdk).appKey()\n const connection: Connection = {\n kind: 'app',\n indexerUrl,\n appKey: toHex(appKey.export()),\n appMeta,\n }\n return { session, connection, appKey }\n }\n if (typeof indexerUrl !== 'string' || typeof seed !== 'string') {\n throw new TypeError('openStreams(SharedSdk) needs { indexerUrl, seed }.')\n }\n return { session, connection: { kind: 'shared', indexerUrl, seed } }\n}\n\nfunction toHex(bytes: Uint8Array) {\n return Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('')\n}\n\nfunction streamUrl(\n handle: Opened,\n object: PinnedObject,\n { name, type, onError }: FileOptions,\n): StreamedFile | undefined {\n if (!worker || !navigator.serviceWorker.controller || !opened.has(handle)) {\n return undefined\n }\n const token = crypto.randomUUID()\n entries.set(token, {\n handle,\n objectId: object.id(),\n sealed: handle.appKey && object.seal(handle.appKey),\n size: object.size(),\n name,\n mime: type || 'application/octet-stream',\n onError,\n })\n return {\n url: streamPath(worker.scope, worker.clientId, token),\n release() {\n entries.delete(token)\n const message = { type: 'sia-release', token } satisfies PageMessage\n navigator.serviceWorker.controller?.postMessage(message)\n },\n }\n}\n\nfunction releaseStreams(handle: Opened) {\n for (const [token, entry] of entries) {\n if (entry.handle === handle) entries.delete(token)\n }\n if (!opened.delete(handle)) return\n const message = {\n type: 'sia-release-share',\n session: handle.session,\n } satisfies PageMessage\n navigator.serviceWorker.controller?.postMessage(message)\n}\n\nfunction onWorkerMessage(event: MessageEvent) {\n if (event.source !== navigator.serviceWorker.controller) return\n const data = event.data as WorkerMessage | undefined\n if (data?.type === 'sia-stream-error') {\n const entry = entries.get(data.token)\n if (!entry) return\n const { offset, length } = data\n const range =\n offset !== undefined && length !== undefined\n ? { offset, length }\n : undefined\n if (entry.onError) entry.onError(streamErrorMessage(data.message))\n else reportStreamError(data.message, entry.name, range)\n } else if (data?.type === 'sia-source') {\n const port = event.ports[0]\n if (!port) return\n const entry = entries.get(data.token)\n const reply: SourceReply =\n entry\n ? {\n type: 'source',\n session: entry.handle.session,\n connection: entry.handle.connection,\n objectId: entry.objectId,\n ...(entry.sealed && { sealed: entry.sealed }),\n size: entry.size,\n mime: entry.mime,\n name: entry.name,\n }\n : { type: 'error' }\n port.postMessage(reply)\n port.close()\n }\n}\n"],"mappings":";;;;;;;;;AAEA,OAAO,cAAc;;;ACQrB,IAAM,kBAAkB;AACxB,IAAM,UAAU;AAEhB,IAAI;AAEG,SAAS,qBAAuC;AACrD,aACE,OAAO,cAAc,cACjB,QAAQ,QAAQ,KAAK,IACrB,kBAAkB,UAAU,WAAW,KAAK;AAClD,SAAO;AACT;AAGA,eAAsB,kBACpB,WACA,SACkB;AAClB,QAAM,SACJ,y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AtBP,IAAI,cAAuC;AAG3C,eAAsB,UAAyB;AAC7C,MAAI,CAAC,YAAa,eAAc,SAAS;AACzC,QAAM;AACR;","names":[]}
|
package/dist/index.node.cjs
CHANGED
|
@@ -29,40 +29,62 @@ __export(index_node_exports, {
|
|
|
29
29
|
Sdk: () => Sdk,
|
|
30
30
|
SharedSdk: () => SharedSdk,
|
|
31
31
|
SharingKey: () => SharingKey,
|
|
32
|
+
detectPrivateRelay: () => detectPrivateRelay,
|
|
33
|
+
enableStreaming: () => enableStreaming,
|
|
32
34
|
encodedSize: () => encodedSize,
|
|
33
35
|
generateRecoveryPhrase: () => generateRecoveryPhrase,
|
|
34
36
|
initSia: () => initSia,
|
|
37
|
+
openStreams: () => openStreams,
|
|
35
38
|
setLogger: () => setLogger,
|
|
36
39
|
validateRecoveryPhrase: () => validateRecoveryPhrase
|
|
37
40
|
});
|
|
38
41
|
module.exports = __toCommonJS(index_node_exports);
|
|
39
42
|
|
|
43
|
+
// src/node/platforms.ts
|
|
44
|
+
var NATIVE_PACKAGES = {
|
|
45
|
+
"darwin-arm64": "@siafoundation/sia-storage-darwin-arm64",
|
|
46
|
+
"darwin-x64": "@siafoundation/sia-storage-darwin-x64",
|
|
47
|
+
"linux-x64": "@siafoundation/sia-storage-linux-x64-gnu",
|
|
48
|
+
"linux-arm64": "@siafoundation/sia-storage-linux-arm64-gnu",
|
|
49
|
+
"win32-x64": "@siafoundation/sia-storage-win32-x64-msvc"
|
|
50
|
+
};
|
|
51
|
+
|
|
40
52
|
// src/node/load.ts
|
|
41
53
|
var addon = null;
|
|
42
54
|
function loadNativeAddon() {
|
|
43
55
|
if (addon) return addon;
|
|
44
|
-
const
|
|
45
|
-
|
|
56
|
+
const target = `${process.platform}-${process.arch}`;
|
|
57
|
+
let cause;
|
|
46
58
|
try {
|
|
47
|
-
if (
|
|
59
|
+
if (target === "darwin-arm64") {
|
|
48
60
|
addon = require("@siafoundation/sia-storage-darwin-arm64");
|
|
49
|
-
} else if (
|
|
61
|
+
} else if (target === "darwin-x64") {
|
|
50
62
|
addon = require("@siafoundation/sia-storage-darwin-x64");
|
|
51
|
-
} else if (
|
|
63
|
+
} else if (target === "linux-x64") {
|
|
52
64
|
addon = require("@siafoundation/sia-storage-linux-x64-gnu");
|
|
53
|
-
} else if (
|
|
65
|
+
} else if (target === "linux-arm64") {
|
|
54
66
|
addon = require("@siafoundation/sia-storage-linux-arm64-gnu");
|
|
55
|
-
} else if (
|
|
67
|
+
} else if (target === "win32-x64") {
|
|
56
68
|
addon = require("@siafoundation/sia-storage-win32-x64-msvc");
|
|
57
69
|
}
|
|
58
|
-
} catch {
|
|
70
|
+
} catch (error) {
|
|
71
|
+
cause = error;
|
|
59
72
|
}
|
|
60
|
-
if (!addon)
|
|
61
|
-
|
|
62
|
-
|
|
73
|
+
if (!addon) throw addonLoadError(target, cause);
|
|
74
|
+
return addon;
|
|
75
|
+
}
|
|
76
|
+
function addonLoadError(target, cause) {
|
|
77
|
+
const packageName = NATIVE_PACKAGES[target];
|
|
78
|
+
if (!packageName) {
|
|
79
|
+
return new Error(
|
|
80
|
+
`@siafoundation/sia-storage: no native addon is published for ${target}. Use the browser/WASM build.`
|
|
63
81
|
);
|
|
64
82
|
}
|
|
65
|
-
|
|
83
|
+
const reason = cause instanceof Error ? cause.message : String(cause);
|
|
84
|
+
return new Error(
|
|
85
|
+
`@siafoundation/sia-storage: could not load the native addon for ${target} from ${packageName}: ${reason}`,
|
|
86
|
+
{ cause }
|
|
87
|
+
);
|
|
66
88
|
}
|
|
67
89
|
|
|
68
90
|
// src/node/napi.ts
|
|
@@ -85,6 +107,21 @@ var {
|
|
|
85
107
|
async function initSia() {
|
|
86
108
|
loadNativeAddon();
|
|
87
109
|
}
|
|
110
|
+
|
|
111
|
+
// src/index.node.ts
|
|
112
|
+
async function detectPrivateRelay() {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
async function enableStreaming() {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
function openStreams() {
|
|
119
|
+
const unavailable = () => Promise.reject(
|
|
120
|
+
new Error("openStreams is for browser pages. In Node, use sdk.download().")
|
|
121
|
+
);
|
|
122
|
+
return { url: unavailable, download: unavailable, close() {
|
|
123
|
+
} };
|
|
124
|
+
}
|
|
88
125
|
// Annotate the CommonJS export names for ESM import in node:
|
|
89
126
|
0 && (module.exports = {
|
|
90
127
|
AppKey,
|
|
@@ -96,9 +133,12 @@ async function initSia() {
|
|
|
96
133
|
Sdk,
|
|
97
134
|
SharedSdk,
|
|
98
135
|
SharingKey,
|
|
136
|
+
detectPrivateRelay,
|
|
137
|
+
enableStreaming,
|
|
99
138
|
encodedSize,
|
|
100
139
|
generateRecoveryPhrase,
|
|
101
140
|
initSia,
|
|
141
|
+
openStreams,
|
|
102
142
|
setLogger,
|
|
103
143
|
validateRecoveryPhrase
|
|
104
144
|
});
|
package/dist/index.node.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.node.ts","../src/node/load.ts","../src/node/napi.ts"],"sourcesContent":["export * from './node/napi'\nexport type * from './node/napi'\n","import type * as Addon from './napi.generated'\n\nlet addon: typeof Addon | null = null\n\nexport function loadNativeAddon(): typeof Addon {\n if (addon) return addon\n\n const
|
|
1
|
+
{"version":3,"sources":["../src/index.node.ts","../src/node/platforms.ts","../src/node/load.ts","../src/node/napi.ts"],"sourcesContent":["export * from './node/napi'\nexport type * from './node/napi'\n\n/** Node's traffic never goes through iCloud Private Relay, which is Safari's. */\nexport async function detectPrivateRelay(): Promise<boolean> {\n return false\n}\n\n// openStreams hands a browser page URLs that a service worker serves. Node\n// streams objects with sdk.download() directly, so these only let code shared\n// with the browser import them, and server rendering call them, without\n// crashing.\nexport async function enableStreaming(): Promise<boolean> {\n return false\n}\n\nexport function openStreams() {\n const unavailable = () =>\n Promise.reject(\n new Error('openStreams is for browser pages. In Node, use sdk.download().'),\n )\n return { url: unavailable, download: unavailable, close() {} }\n}\n","/**\n * The npm package that ships the native addon for each platform, keyed by\n * `${process.platform}-${process.arch}`. The Linux and Windows packages name\n * the C library or toolchain their binary was built against, so a package\n * name is not always the platform key with a prefix.\n *\n * scripts/publish.ts publishes these and lists them as the main package's\n * optionalDependencies.\n */\nexport const NATIVE_PACKAGES: Record<string, string> = {\n 'darwin-arm64': '@siafoundation/sia-storage-darwin-arm64',\n 'darwin-x64': '@siafoundation/sia-storage-darwin-x64',\n 'linux-x64': '@siafoundation/sia-storage-linux-x64-gnu',\n 'linux-arm64': '@siafoundation/sia-storage-linux-arm64-gnu',\n 'win32-x64': '@siafoundation/sia-storage-win32-x64-msvc',\n}\n","import type * as Addon from './napi.generated'\nimport { NATIVE_PACKAGES } from './platforms'\n\nlet addon: typeof Addon | null = null\n\nexport function loadNativeAddon(): typeof Addon {\n if (addon) return addon\n\n const target = `${process.platform}-${process.arch}`\n let cause: unknown\n\n // One literal require per package, rather than require(NATIVE_PACKAGES[...]),\n // so bundlers, including `bun build --compile`, can find and embed the addon.\n try {\n if (target === 'darwin-arm64') {\n addon = require('@siafoundation/sia-storage-darwin-arm64')\n } else if (target === 'darwin-x64') {\n addon = require('@siafoundation/sia-storage-darwin-x64')\n } else if (target === 'linux-x64') {\n addon = require('@siafoundation/sia-storage-linux-x64-gnu')\n } else if (target === 'linux-arm64') {\n addon = require('@siafoundation/sia-storage-linux-arm64-gnu')\n } else if (target === 'win32-x64') {\n addon = require('@siafoundation/sia-storage-win32-x64-msvc')\n }\n } catch (error) {\n cause = error\n }\n\n if (!addon) throw addonLoadError(target, cause)\n return addon\n}\n\n/**\n * Why the addon could not load. A missing package and a binary that fails to\n * load read differently, so the require error is kept as the cause and its\n * message is part of this one.\n */\nexport function addonLoadError(target: string, cause: unknown): Error {\n const packageName = NATIVE_PACKAGES[target]\n if (!packageName) {\n return new Error(\n `@siafoundation/sia-storage: no native addon is published for ${target}. ` +\n 'Use the browser/WASM build.',\n )\n }\n const reason = cause instanceof Error ? cause.message : String(cause)\n return new Error(\n `@siafoundation/sia-storage: could not load the native addon for ${target} ` +\n `from ${packageName}: ${reason}`,\n { cause },\n )\n}\n","import { loadNativeAddon } from './load'\n\nconst addon = loadNativeAddon()\n\nexport const {\n AppKey,\n Builder,\n Sdk,\n PinnedObject,\n PackedUpload,\n ObjectEvent,\n SharingKey,\n KeyRecord,\n SharedSdk,\n generateRecoveryPhrase,\n validateRecoveryPhrase,\n setLogger,\n encodedSize,\n} = addon\n\nexport type * from './napi.generated'\n\n/** Force-load the native addon to surface missing-binary errors at startup. */\nexport async function initSia(): Promise<void> {\n loadNativeAddon()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSO,IAAM,kBAA0C;AAAA,EACrD,gBAAgB;AAAA,EAChB,cAAc;AAAA,EACd,aAAa;AAAA,EACb,eAAe;AAAA,EACf,aAAa;AACf;;;ACZA,IAAI,QAA6B;AAE1B,SAAS,kBAAgC;AAC9C,MAAI,MAAO,QAAO;AAElB,QAAM,SAAS,GAAG,QAAQ,QAAQ,IAAI,QAAQ,IAAI;AAClD,MAAI;AAIJ,MAAI;AACF,QAAI,WAAW,gBAAgB;AAC7B,cAAQ,QAAQ,yCAAyC;AAAA,IAC3D,WAAW,WAAW,cAAc;AAClC,cAAQ,QAAQ,uCAAuC;AAAA,IACzD,WAAW,WAAW,aAAa;AACjC,cAAQ,QAAQ,0CAA0C;AAAA,IAC5D,WAAW,WAAW,eAAe;AACnC,cAAQ,QAAQ,4CAA4C;AAAA,IAC9D,WAAW,WAAW,aAAa;AACjC,cAAQ,QAAQ,2CAA2C;AAAA,IAC7D;AAAA,EACF,SAAS,OAAO;AACd,YAAQ;AAAA,EACV;AAEA,MAAI,CAAC,MAAO,OAAM,eAAe,QAAQ,KAAK;AAC9C,SAAO;AACT;AAOO,SAAS,eAAe,QAAgB,OAAuB;AACpE,QAAM,cAAc,gBAAgB,MAAM;AAC1C,MAAI,CAAC,aAAa;AAChB,WAAO,IAAI;AAAA,MACT,gEAAgE,MAAM;AAAA,IAExE;AAAA,EACF;AACA,QAAM,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACpE,SAAO,IAAI;AAAA,IACT,mEAAmE,MAAM,SAC/D,WAAW,KAAK,MAAM;AAAA,IAChC,EAAE,MAAM;AAAA,EACV;AACF;;;AClDA,IAAMA,SAAQ,gBAAgB;AAEvB,IAAM;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,IAAIA;AAKJ,eAAsB,UAAyB;AAC7C,kBAAgB;AAClB;;;AHrBA,eAAsB,qBAAuC;AAC3D,SAAO;AACT;AAMA,eAAsB,kBAAoC;AACxD,SAAO;AACT;AAEO,SAAS,cAAc;AAC5B,QAAM,cAAc,MAClB,QAAQ;AAAA,IACN,IAAI,MAAM,gEAAgE;AAAA,EAC5E;AACF,SAAO,EAAE,KAAK,aAAa,UAAU,aAAa,QAAQ;AAAA,EAAC,EAAE;AAC/D;","names":["addon"]}
|
package/dist/index.node.d.ts
CHANGED
|
@@ -115,6 +115,8 @@ export declare class PackedUpload {
|
|
|
115
115
|
length(): bigint
|
|
116
116
|
/** Returns the number of slabs in the upload. */
|
|
117
117
|
slabs(): bigint
|
|
118
|
+
/** Returns the optimal size of each slab in bytes. */
|
|
119
|
+
optimalDataSize(): bigint
|
|
118
120
|
/**
|
|
119
121
|
* Adds a new object to the upload. The data is read until EOF and packed into
|
|
120
122
|
* the current slab. Returns the number of bytes consumed; call
|
|
@@ -233,8 +235,8 @@ export declare class Sdk {
|
|
|
233
235
|
* of the object's data.
|
|
234
236
|
*/
|
|
235
237
|
download(object: PinnedObject, options?: DownloadOptions | undefined | null): ReadableStream
|
|
236
|
-
/** Returns a list of
|
|
237
|
-
hosts(): Promise<Array<Host>>
|
|
238
|
+
/** Returns a list of usable hosts, optionally filtered by a query. */
|
|
239
|
+
hosts(query?: HostQuery | undefined | null): Promise<Array<Host>>
|
|
238
240
|
/** Returns object events from the indexer for syncing. */
|
|
239
241
|
objectEvents(cursor: ObjectsCursor | undefined | null, limit: number): Promise<Array<ObjectEvent>>
|
|
240
242
|
/** Updates the metadata of an object stored in the indexer. */
|
|
@@ -276,11 +278,11 @@ export declare class SharedSdk {
|
|
|
276
278
|
/** Lists and decrypts a page of the objects the key grants access to. */
|
|
277
279
|
objects(offset: number, limit: number): Promise<Array<PinnedObject>>
|
|
278
280
|
/**
|
|
279
|
-
* Returns the hosts serving this key's objects
|
|
280
|
-
* is scoped to the sharing key, so the
|
|
281
|
-
* holding its objects.
|
|
281
|
+
* Returns the hosts serving this key's objects, optionally filtered by a
|
|
282
|
+
* query. Mirrors `Sdk.hosts()` but is scoped to the sharing key, so the
|
|
283
|
+
* set is already limited to hosts holding its objects.
|
|
282
284
|
*/
|
|
283
|
-
hosts(): Promise<Array<Host>>
|
|
285
|
+
hosts(query?: HostQuery | undefined | null): Promise<Array<Host>>
|
|
284
286
|
/** Streams a shared object's data, paying hosts with the owner's tokens. */
|
|
285
287
|
download(object: PinnedObject, options?: DownloadOptions | undefined | null): ReadableStream
|
|
286
288
|
}
|
|
@@ -353,6 +355,12 @@ export declare function encodedSize(size: bigint, dataShards: number, parityShar
|
|
|
353
355
|
/** Generates a new BIP-39 12-word recovery phrase. */
|
|
354
356
|
export declare function generateRecoveryPhrase(): string
|
|
355
357
|
|
|
358
|
+
/** Geographic coordinates used to sort hosts by proximity. */
|
|
359
|
+
export interface GeoLocation {
|
|
360
|
+
latitude: number
|
|
361
|
+
longitude: number
|
|
362
|
+
}
|
|
363
|
+
|
|
356
364
|
/** Information about a storage provider on the Sia network. */
|
|
357
365
|
export interface Host {
|
|
358
366
|
publicKey: string
|
|
@@ -363,6 +371,15 @@ export interface Host {
|
|
|
363
371
|
goodForUpload: boolean
|
|
364
372
|
}
|
|
365
373
|
|
|
374
|
+
/** Query parameters for filtering hosts. */
|
|
375
|
+
export interface HostQuery {
|
|
376
|
+
location?: GeoLocation
|
|
377
|
+
protocol?: AddressProtocol
|
|
378
|
+
country?: string
|
|
379
|
+
limit?: number
|
|
380
|
+
offset?: number
|
|
381
|
+
}
|
|
382
|
+
|
|
366
383
|
/**
|
|
367
384
|
* A snapshot of what a sharing key grants access to. The counts reflect the
|
|
368
385
|
* moment the record was fetched, not a live view.
|
|
@@ -465,3 +482,12 @@ export interface UploadOptions {
|
|
|
465
482
|
export declare function validateRecoveryPhrase(phrase: string): void
|
|
466
483
|
|
|
467
484
|
export declare function initSia(): Promise<void>
|
|
485
|
+
export declare function detectPrivateRelay(): Promise<boolean>
|
|
486
|
+
/** Always false. Service worker streaming is for browser pages. */
|
|
487
|
+
export declare function enableStreaming(options?: { workerUrl?: string; scope?: string; type?: 'classic' | 'module' }): Promise<boolean>
|
|
488
|
+
/** For browser pages. In Node, `url` and `download` reject, and `sdk.download()` streams objects directly. */
|
|
489
|
+
export declare function openStreams(sdk: object, credentials: { indexerUrl: string; appMeta: AppMetadata } | { indexerUrl: string; seed: string }): {
|
|
490
|
+
url(object: PinnedObject, options: { name: string; type?: string }): Promise<never>
|
|
491
|
+
download(object: PinnedObject, options: { name: string; type?: string }): Promise<never>
|
|
492
|
+
close(): void
|
|
493
|
+
}
|
package/dist/next.d.ts
ADDED