-
Notifications
You must be signed in to change notification settings - Fork 7
feat: align main exports across node and browser #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a39a864
feat: align main exports across node and browser
SgtPooki d2238f2
fix: vitest matches all integration tests
SgtPooki fb91dfc
test: fix isomorphic import test
SgtPooki 488ee8e
test: fix package import test for windows
SgtPooki 3af855e
chore: remove playwright alias
SgtPooki b56f98c
Merge branch 'master' into fix/high-level-api
SgtPooki 028daeb
chore: remove default export
SgtPooki a87a8ad
fix: less export duplication
SgtPooki 9132792
test: fix test after removing default export
SgtPooki ec2452c
chore: minor cleanup
SgtPooki cab56f8
fix: remove initializeSynapse from FilecoinPinAPI
SgtPooki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import type { getDataSetPieces, getDetailedDataSet, listDataSets } from './core/data-set/index.js' | ||
| import type { getPaymentStatus, validatePaymentCapacity } from './core/payments/index.js' | ||
| import type { cleanupSynapseService, setupSynapse } from './core/synapse/index.js' | ||
| import type { createCarFromFile, createCarFromFiles } from './core/unixfs/browser-car-builder.js' | ||
| import type { createCarFromPath } from './core/unixfs/car-builder.js' | ||
| import type { checkUploadReadiness, executeUpload } from './core/upload/index.js' | ||
|
|
||
| export interface FilecoinPinAPI { | ||
| getDataSetPieces: typeof getDataSetPieces | ||
| getDetailedDataSet: typeof getDetailedDataSet | ||
| listDataSets: typeof listDataSets | ||
| getPaymentStatus: typeof getPaymentStatus | ||
| validatePaymentCapacity: typeof validatePaymentCapacity | ||
| cleanupSynapseService: typeof cleanupSynapseService | ||
| setupSynapse: typeof setupSynapse | ||
| createCarFromFile: typeof createCarFromFile | ||
| createCarFromFiles: typeof createCarFromFiles | ||
| createCarFromPath: typeof createCarFromPath | ||
| checkUploadReadiness: typeof checkUploadReadiness | ||
| executeUpload: typeof executeUpload | ||
| } | ||
|
|
||
| export type { ProviderInfo } from '@filoz/synapse-sdk' | ||
| export type { | ||
| DataSetPiecesResult, | ||
| DataSetSummary, | ||
| GetDataSetPiecesOptions, | ||
| ListDataSetsOptions, | ||
| PieceInfo, | ||
| Warning as DataSetWarning, | ||
| } from './core/data-set/index.js' | ||
| export type { PaymentCapacityCheck, PaymentStatus } from './core/payments/index.js' | ||
| export type { | ||
| CreateStorageContextOptions, | ||
| DatasetOptions, | ||
| SynapseService, | ||
| SynapseSetupConfig, | ||
| } from './core/synapse/index.js' | ||
| export type { CreateCarOptions, CreateCarResult } from './core/unixfs/car-builder.js' | ||
| export type { | ||
| SynapseUploadOptions, | ||
| SynapseUploadResult, | ||
| UploadExecutionOptions, | ||
| UploadExecutionResult, | ||
| UploadProgressEvents, | ||
| UploadReadinessOptions, | ||
| UploadReadinessResult, | ||
| } from './core/upload/index.js' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /** | ||
| * High-level API for filecoin-pin | ||
| * | ||
| * This file exports the most common functions and types for interacting with the filecoin-pin library in the browser. | ||
| * For more advanced use cases, you can import from the granular `./core/*` modules. | ||
| */ | ||
| import * as dataSet from './core/data-set/index.js' | ||
| import * as payments from './core/payments/index.js' | ||
| import * as synapse from './core/synapse/index.js' | ||
| import * as browserCar from './core/unixfs/browser-car-builder.js' | ||
| import type { CreateCarOptions } from './core/unixfs/car-builder.js' | ||
| import * as upload from './core/upload/index.js' | ||
| import type { FilecoinPinAPI } from './index-types.js' | ||
|
|
||
| export * from './index-types.js' | ||
|
|
||
| const publicApi = { | ||
| getDataSetPieces: dataSet.getDataSetPieces, | ||
| getDetailedDataSet: dataSet.getDetailedDataSet, | ||
| listDataSets: dataSet.listDataSets, | ||
| getPaymentStatus: payments.getPaymentStatus, | ||
| validatePaymentCapacity: payments.validatePaymentCapacity, | ||
| cleanupSynapseService: synapse.cleanupSynapseService, | ||
| setupSynapse: synapse.setupSynapse, | ||
| createCarFromFile: browserCar.createCarFromFile, | ||
| createCarFromFiles: browserCar.createCarFromFiles, | ||
| /** | ||
| * Not available in the browser; use createCarFromFile or createCarFromFiles. | ||
| * | ||
| * @remarks Node-only helper; preserved for API parity with the Node entrypoint. | ||
| * @throws Always throws in browser builds. | ||
| */ | ||
| createCarFromPath: (_path: string, _options?: CreateCarOptions): never => { | ||
| throw new Error('Function not available in the browser.') | ||
| }, | ||
| checkUploadReadiness: upload.checkUploadReadiness, | ||
| executeUpload: upload.executeUpload, | ||
| } satisfies FilecoinPinAPI | ||
|
|
||
| export const { | ||
| getDataSetPieces, | ||
| getDetailedDataSet, | ||
| listDataSets, | ||
| getPaymentStatus, | ||
| validatePaymentCapacity, | ||
| cleanupSynapseService, | ||
| setupSynapse, | ||
| createCarFromFile, | ||
| createCarFromFiles, | ||
| createCarFromPath, | ||
| checkUploadReadiness, | ||
| executeUpload, | ||
| } = publicApi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /** | ||
| * High-level API for filecoin-pin | ||
| * | ||
| * This file exports the most common functions and types for interacting with the filecoin-pin library in Node.js. | ||
| * For more advanced use cases, you can import from the granular `./core/*` modules. | ||
| */ | ||
| import { createCarFromPath as createCarFromPathCore } from './core/unixfs/car-builder.js' | ||
| import * as browser from './index.browser.js' | ||
| import type { FilecoinPinAPI } from './index-types.js' | ||
|
|
||
| export * from './index-types.js' | ||
|
|
||
| const publicApi = { | ||
| ...browser, | ||
| createCarFromPath: createCarFromPathCore, | ||
| } satisfies FilecoinPinAPI | ||
|
|
||
| export const { | ||
| getDataSetPieces, | ||
| getDetailedDataSet, | ||
| listDataSets, | ||
| getPaymentStatus, | ||
| validatePaymentCapacity, | ||
| cleanupSynapseService, | ||
| setupSynapse, | ||
| createCarFromFile, | ||
| createCarFromFiles, | ||
| createCarFromPath, | ||
| checkUploadReadiness, | ||
| executeUpload, | ||
| } = publicApi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| describe('filecoin-pin isomorphic import', () => { | ||
| it('doesnt throw when importing filecoin-pin', async () => { | ||
| await expect(import('filecoin-pin')).resolves.toBeDefined() | ||
| }) | ||
|
|
||
| it('browser and node.js exports are handled properly', async () => { | ||
SgtPooki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const { createCarFromPath, createCarFromFiles, createCarFromFile } = await import('filecoin-pin') | ||
|
|
||
| expect(typeof createCarFromPath).toBe('function') | ||
| expect(typeof createCarFromFile).toBe('function') | ||
| expect(typeof createCarFromFiles).toBe('function') | ||
| if (typeof window !== 'undefined') { | ||
| expect(() => createCarFromPath('foo')).toThrow('Function not available in the browser.') | ||
| } else { | ||
| await expect(createCarFromPath('foo')).rejects.toThrow('ENOENT') | ||
| } | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,45 @@ | ||
| import { playwright } from '@vitest/browser-playwright' | ||
| import { defineConfig } from 'vitest/config' | ||
|
|
||
| export default defineConfig({ | ||
| test: { | ||
| globals: true, | ||
| environment: 'node', | ||
| root: '.', | ||
| include: ['src/**/*.test.ts'], | ||
| setupFiles: ['src/test/setup.ts'], | ||
| projects: [ | ||
| { | ||
| // unit tests for node.js (also isomorphic tests) | ||
| test: { | ||
| name: 'unit', | ||
| environment: 'node', | ||
| include: ['src/test/unit/**/*.test.ts', 'src/test/**/*.iso.test.ts'], | ||
| exclude: ['src/test/**/*.browser.test.ts'], | ||
| setupFiles: ['src/test/setup.ts'], | ||
| }, | ||
| }, | ||
| { | ||
| // integration tests | ||
| test: { | ||
| name: 'integration', | ||
| environment: 'node', | ||
| include: ['src/test/integration/**/*.test.ts'], | ||
| exclude: ['src/test/**/*.browser.test.ts'], | ||
| setupFiles: ['src/test/setup.ts'], | ||
| }, | ||
| }, | ||
| { | ||
| // browser tests (also isomorphic tests) | ||
| test: { | ||
| name: 'browser', | ||
| include: ['src/test/**/*.browser.test.ts', 'src/test/**/*.iso.test.ts'], | ||
| browser: { | ||
| enabled: true, | ||
| provider: playwright(), | ||
| instances: [{ browser: 'chromium' }], | ||
| headless: true, | ||
| screenshotFailures: false, | ||
| }, | ||
| }, | ||
SgtPooki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| ], | ||
| }, | ||
| }) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.