@filoz/synapse-react 0.2.1 → 0.2.3
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/dist/src/warm-storage/index.d.ts +1 -0
- package/dist/src/warm-storage/index.d.ts.map +1 -1
- package/dist/src/warm-storage/index.js +1 -0
- package/dist/src/warm-storage/index.js.map +1 -1
- package/dist/src/warm-storage/use-data-sets.d.ts +3 -2
- package/dist/src/warm-storage/use-data-sets.d.ts.map +1 -1
- package/dist/src/warm-storage/use-delete-piece.d.ts +0 -2
- package/dist/src/warm-storage/use-delete-piece.d.ts.map +1 -1
- package/dist/src/warm-storage/use-delete-piece.js +1 -6
- package/dist/src/warm-storage/use-delete-piece.js.map +1 -1
- package/dist/src/warm-storage/use-upload-simple.d.ts +20 -0
- package/dist/src/warm-storage/use-upload-simple.d.ts.map +1 -0
- package/dist/src/warm-storage/use-upload-simple.js +31 -0
- package/dist/src/warm-storage/use-upload-simple.js.map +1 -0
- package/dist/src/warm-storage/use-upload.d.ts +8 -17
- package/dist/src/warm-storage/use-upload.d.ts.map +1 -1
- package/dist/src/warm-storage/use-upload.js +13 -17
- package/dist/src/warm-storage/use-upload.js.map +1 -1
- package/package.json +8 -6
- package/src/warm-storage/index.ts +1 -0
- package/src/warm-storage/use-delete-piece.ts +1 -9
- package/src/warm-storage/use-upload-simple.ts +47 -0
- package/src/warm-storage/use-upload.ts +19 -27
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/warm-storage/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/warm-storage/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/warm-storage/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/warm-storage/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA"}
|
|
@@ -25,7 +25,8 @@ export declare function useDataSets(props: UseDataSetsProps): import("@tanstack/
|
|
|
25
25
|
live: boolean;
|
|
26
26
|
managed: boolean;
|
|
27
27
|
cdn: boolean;
|
|
28
|
-
metadata: import("@filoz/synapse-
|
|
29
|
-
provider: import("@filoz/synapse-
|
|
28
|
+
metadata: import("@filoz/synapse-sdk").MetadataObject;
|
|
29
|
+
provider: import("@filoz/synapse-sdk").PDPProvider;
|
|
30
|
+
activePieceCount: bigint;
|
|
30
31
|
}[], Error>;
|
|
31
32
|
//# sourceMappingURL=use-data-sets.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-data-sets.d.ts","sourceRoot":"","sources":["../../../src/warm-storage/use-data-sets.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,KAAK,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AAC1G,OAAO,EAAa,KAAK,eAAe,EAAY,MAAM,uBAAuB,CAAA;AACjF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAGnC,MAAM,WAAW,iBAAkB,SAAQ,UAAU;IACnD,MAAM,EAAE,iBAAiB,EAAE,CAAA;CAC5B;AAED,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,EAAE,CAAA;AAEnD,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,KAAK,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC,iBAAiB,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC,CAAA;CACzE;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB
|
|
1
|
+
{"version":3,"file":"use-data-sets.d.ts","sourceRoot":"","sources":["../../../src/warm-storage/use-data-sets.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,KAAK,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AAC1G,OAAO,EAAa,KAAK,eAAe,EAAY,MAAM,uBAAuB,CAAA;AACjF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAGnC,MAAM,WAAW,iBAAkB,SAAQ,UAAU;IACnD,MAAM,EAAE,iBAAiB,EAAE,CAAA;CAC5B;AAED,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,EAAE,CAAA;AAEnD,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,KAAK,CAAC,EAAE,IAAI,CAAC,eAAe,CAAC,iBAAiB,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC,CAAA;CACzE;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB;;;;;;;;;;;;;;;;;;;YAyBlD"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import type { SessionKey } from '@filoz/synapse-core/session-key';
|
|
2
1
|
import type { PdpDataSet } from '@filoz/synapse-core/warm-storage';
|
|
3
2
|
import { type MutateOptions } from '@tanstack/react-query';
|
|
4
3
|
import type { TransactionReceipt } from 'viem';
|
|
5
4
|
export interface UseDeletePieceProps {
|
|
6
5
|
onHash?: (hash: string) => void;
|
|
7
|
-
sessionKey?: SessionKey;
|
|
8
6
|
mutation?: Omit<MutateOptions<TransactionReceipt, Error, UseDeletePieceVariables>, 'mutationFn'>;
|
|
9
7
|
}
|
|
10
8
|
export interface UseDeletePieceVariables {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-delete-piece.d.ts","sourceRoot":"","sources":["../../../src/warm-storage/use-delete-piece.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"use-delete-piece.d.ts","sourceRoot":"","sources":["../../../src/warm-storage/use-delete-piece.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;AAClE,OAAO,EAAE,KAAK,aAAa,EAA+B,MAAM,uBAAuB,CAAA;AACvF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAA;AAK9C,MAAM,WAAW,mBAAmB;IAIlC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAC/B,QAAQ,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,kBAAkB,EAAE,KAAK,EAAE,uBAAuB,CAAC,EAAE,YAAY,CAAC,CAAA;CACjG;AAED,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,UAAU,CAAA;IACnB,OAAO,EAAE,MAAM,CAAA;CAChB;AACD,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,kHA+BxD"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getChain } from '@filoz/synapse-core/chains';
|
|
2
1
|
import * as SP from '@filoz/synapse-core/sp';
|
|
3
2
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
4
3
|
import { waitForTransactionReceipt } from 'viem/actions';
|
|
@@ -7,20 +6,16 @@ import { getConnectorClient } from 'wagmi/actions';
|
|
|
7
6
|
export function useDeletePiece(props) {
|
|
8
7
|
const config = useConfig();
|
|
9
8
|
const chainId = useChainId({ config });
|
|
10
|
-
const chain = getChain(chainId);
|
|
11
9
|
const account = useAccount({ config });
|
|
12
10
|
const queryClient = useQueryClient();
|
|
13
11
|
const client = config.getClient();
|
|
14
12
|
return useMutation({
|
|
15
13
|
...props?.mutation,
|
|
16
14
|
mutationFn: async ({ dataSet, pieceId }) => {
|
|
17
|
-
|
|
15
|
+
const connectorClient = await getConnectorClient(config, {
|
|
18
16
|
account: account.address,
|
|
19
17
|
chainId,
|
|
20
18
|
});
|
|
21
|
-
if (props?.sessionKey && (await props?.sessionKey.isValid(connectorClient, 'SchedulePieceRemovals'))) {
|
|
22
|
-
connectorClient = props?.sessionKey.client(chain, client.transport);
|
|
23
|
-
}
|
|
24
19
|
const deletePieceRsp = await SP.schedulePieceDeletion(connectorClient, {
|
|
25
20
|
serviceURL: dataSet.provider.pdp.serviceURL,
|
|
26
21
|
dataSetId: dataSet.dataSetId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-delete-piece.js","sourceRoot":"","sources":["../../../src/warm-storage/use-delete-piece.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"use-delete-piece.js","sourceRoot":"","sources":["../../../src/warm-storage/use-delete-piece.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAE5C,OAAO,EAAsB,WAAW,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEvF,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,OAAO,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AC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type AddPiecesSuccess } from '@filoz/synapse-core/sp';
|
|
2
|
+
import { type MutateOptions } from '@tanstack/react-query';
|
|
3
|
+
export interface UseUploadSimpleProps {
|
|
4
|
+
onHash?: (hash: string) => void;
|
|
5
|
+
mutation?: Omit<MutateOptions<AddPiecesSuccess, Error, UseUploadSimpleVariables>, 'mutationFn'>;
|
|
6
|
+
}
|
|
7
|
+
export interface UseUploadSimpleVariables {
|
|
8
|
+
files: File[];
|
|
9
|
+
dataSetId: bigint;
|
|
10
|
+
}
|
|
11
|
+
export declare function useUploadSimple(props: UseUploadSimpleProps): import("@tanstack/react-query").UseMutationResult<{
|
|
12
|
+
txHash: `0x${string}`;
|
|
13
|
+
txStatus: "confirmed";
|
|
14
|
+
dataSetId: bigint;
|
|
15
|
+
pieceCount: number;
|
|
16
|
+
addMessageOk: true;
|
|
17
|
+
piecesAdded: true;
|
|
18
|
+
confirmedPieceIds: bigint[];
|
|
19
|
+
}, Error, UseUploadSimpleVariables, unknown>;
|
|
20
|
+
//# sourceMappingURL=use-upload-simple.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-upload-simple.d.ts","sourceRoot":"","sources":["../../../src/warm-storage/use-upload-simple.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,gBAAgB,EAAU,MAAM,wBAAwB,CAAA;AACtE,OAAO,EAAE,KAAK,aAAa,EAA+B,MAAM,uBAAuB,CAAA;AAIvF,MAAM,WAAW,oBAAoB;IAInC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAC/B,QAAQ,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,gBAAgB,EAAE,KAAK,EAAE,wBAAwB,CAAC,EAAE,YAAY,CAAC,CAAA;CAChG;AAED,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,IAAI,EAAE,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;CAClB;AACD,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB;;;;;;;;6CA4B1D"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as SP from '@filoz/synapse-core/sp';
|
|
2
|
+
import { upload } from '@filoz/synapse-core/sp';
|
|
3
|
+
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
4
|
+
import { useChainId, useConfig, useConnection } from 'wagmi';
|
|
5
|
+
import { getConnectorClient } from 'wagmi/actions';
|
|
6
|
+
export function useUploadSimple(props) {
|
|
7
|
+
const config = useConfig();
|
|
8
|
+
const chainId = useChainId({ config });
|
|
9
|
+
const account = useConnection({ config });
|
|
10
|
+
const queryClient = useQueryClient();
|
|
11
|
+
return useMutation({
|
|
12
|
+
...props?.mutation,
|
|
13
|
+
mutationFn: async ({ files, dataSetId }) => {
|
|
14
|
+
const connectorClient = await getConnectorClient(config, {
|
|
15
|
+
account: account.address,
|
|
16
|
+
chainId,
|
|
17
|
+
});
|
|
18
|
+
const uploadRsp = await upload(connectorClient, {
|
|
19
|
+
dataSetId,
|
|
20
|
+
data: files,
|
|
21
|
+
});
|
|
22
|
+
props?.onHash?.(uploadRsp.txHash);
|
|
23
|
+
const rsp = await SP.waitForAddPieces(uploadRsp);
|
|
24
|
+
queryClient.invalidateQueries({
|
|
25
|
+
queryKey: ['synapse-warm-storage-data-sets', account.address, config.getClient().chain.id],
|
|
26
|
+
});
|
|
27
|
+
return rsp;
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=use-upload-simple.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-upload-simple.js","sourceRoot":"","sources":["../../../src/warm-storage/use-upload-simple.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAC5C,OAAO,EAAyB,MAAM,EAAE,MAAM,wBAAwB,CAAA;AACtE,OAAO,EAAsB,WAAW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
import { type UploadResult } from '@filoz/synapse-sdk';
|
|
2
|
+
import type { StorageManagerUploadOptions } from '@filoz/synapse-sdk/storage';
|
|
3
3
|
import { type MutateOptions } from '@tanstack/react-query';
|
|
4
|
-
export interface UseUploadProps {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
mutation?: Omit<MutateOptions<AddPiecesSuccess, Error, UseUploadVariables>, 'mutationFn'>;
|
|
4
|
+
export interface UseUploadProps extends Omit<StorageManagerUploadOptions, 'contexts' | 'pieceMetadata'> {
|
|
5
|
+
source: string | null;
|
|
6
|
+
mutation?: Omit<MutateOptions<UploadResult, Error, UseUploadVariables>, 'mutationFn'>;
|
|
8
7
|
}
|
|
9
8
|
export interface UseUploadVariables {
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
file: File;
|
|
10
|
+
metadata?: Record<string, string>;
|
|
12
11
|
}
|
|
13
|
-
export declare function useUpload(props: UseUploadProps): import("@tanstack/react-query").UseMutationResult<
|
|
14
|
-
txHash: `0x${string}`;
|
|
15
|
-
txStatus: "confirmed";
|
|
16
|
-
dataSetId: bigint;
|
|
17
|
-
pieceCount: number;
|
|
18
|
-
addMessageOk: true;
|
|
19
|
-
piecesAdded: true;
|
|
20
|
-
confirmedPieceIds: bigint[];
|
|
21
|
-
}, Error, UseUploadVariables, unknown>;
|
|
12
|
+
export declare function useUpload(props: UseUploadProps): import("@tanstack/react-query").UseMutationResult<UploadResult, Error, UseUploadVariables, unknown>;
|
|
22
13
|
//# sourceMappingURL=use-upload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-upload.d.ts","sourceRoot":"","sources":["../../../src/warm-storage/use-upload.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"use-upload.d.ts","sourceRoot":"","sources":["../../../src/warm-storage/use-upload.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAA;AAC7E,OAAO,EAAE,KAAK,aAAa,EAA+B,MAAM,uBAAuB,CAAA;AAIvF,MAAM,WAAW,cAAe,SAAQ,IAAI,CAAC,2BAA2B,EAAE,UAAU,GAAG,eAAe,CAAC;IACrG,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,QAAQ,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,KAAK,EAAE,kBAAkB,CAAC,EAAE,YAAY,CAAC,CAAA;CACtF;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,IAAI,CAAA;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAClC;AACD,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,uGA8B9C"}
|
|
@@ -1,32 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { upload } from '@filoz/synapse-core/sp';
|
|
1
|
+
import { asClient } from '@filoz/synapse-core/chains';
|
|
2
|
+
import { Synapse } from '@filoz/synapse-sdk';
|
|
4
3
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
5
|
-
import {
|
|
4
|
+
import { useChainId, useConfig, useConnection } from 'wagmi';
|
|
6
5
|
import { getConnectorClient } from 'wagmi/actions';
|
|
7
6
|
export function useUpload(props) {
|
|
8
7
|
const config = useConfig();
|
|
9
8
|
const chainId = useChainId({ config });
|
|
10
|
-
const
|
|
11
|
-
const account = useAccount({ config });
|
|
9
|
+
const account = useConnection({ config });
|
|
12
10
|
const queryClient = useQueryClient();
|
|
13
|
-
const client = config.getClient();
|
|
14
11
|
return useMutation({
|
|
15
12
|
...props?.mutation,
|
|
16
|
-
mutationFn: async ({
|
|
17
|
-
|
|
13
|
+
mutationFn: async ({ file, metadata }) => {
|
|
14
|
+
const connectorClient = await getConnectorClient(config, {
|
|
18
15
|
account: account.address,
|
|
19
16
|
chainId,
|
|
20
17
|
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
const synapse = new Synapse({
|
|
19
|
+
client: asClient(connectorClient),
|
|
20
|
+
source: props.source,
|
|
21
|
+
});
|
|
22
|
+
const rsp = await synapse.storage.upload(new Uint8Array(await file.arrayBuffer()), {
|
|
23
|
+
...props,
|
|
24
|
+
pieceMetadata: metadata,
|
|
27
25
|
});
|
|
28
|
-
props?.onHash?.(uploadRsp.txHash);
|
|
29
|
-
const rsp = await SP.waitForAddPieces(uploadRsp);
|
|
30
26
|
queryClient.invalidateQueries({
|
|
31
27
|
queryKey: ['synapse-warm-storage-data-sets', account.address, config.getClient().chain.id],
|
|
32
28
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-upload.js","sourceRoot":"","sources":["../../../src/warm-storage/use-upload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"use-upload.js","sourceRoot":"","sources":["../../../src/warm-storage/use-upload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AACrD,OAAO,EAAE,OAAO,EAAqB,MAAM,oBAAoB,CAAA;AAE/D,OAAO,EAAsB,WAAW,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACvF,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAWlD,MAAM,UAAU,SAAS,CAAC,KAAqB;IAC7C,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;IAC1B,MAAM,OAAO,GAAG,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IACtC,MAAM,OAAO,GAAG,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IACzC,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;IAEpC,OAAO,WAAW,CAAC;QACjB,GAAG,KAAK,EAAE,QAAQ;QAClB,UAAU,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAsB,EAAE,EAAE;YAC3D,MAAM,eAAe,GAAG,MAAM,kBAAkB,CAAC,MAAM,EAAE;gBACvD,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,OAAO;aACR,CAAC,CAAA;YAEF,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC;gBAC1B,MAAM,EAAE,QAAQ,CAAC,eAAe,CAAC;gBACjC,MAAM,EAAE,KAAK,CAAC,MAAM;aACrB,CAAC,CAAA;YAEF,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE;gBACjF,GAAG,KAAK;gBACR,aAAa,EAAE,QAAQ;aACxB,CAAC,CAAA;YAEF,WAAW,CAAC,iBAAiB,CAAC;gBAC5B,QAAQ,EAAE,CAAC,gCAAgC,EAAE,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;aAC3F,CAAC,CAAA;YACF,OAAO,GAAG,CAAA;QACZ,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@filoz/synapse-react",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "React hooks for interacting with Filecoin Onchain Cloud smart contracts",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -60,7 +60,8 @@
|
|
|
60
60
|
"dist/**"
|
|
61
61
|
],
|
|
62
62
|
"dependencies": [
|
|
63
|
-
"../synapse-core:build"
|
|
63
|
+
"../synapse-core:build",
|
|
64
|
+
"../synapse-sdk:build"
|
|
64
65
|
]
|
|
65
66
|
},
|
|
66
67
|
"lint": {
|
|
@@ -77,14 +78,15 @@
|
|
|
77
78
|
},
|
|
78
79
|
"dependencies": {
|
|
79
80
|
"@hugomrdias/filsnap-adapter": "^3.3.8",
|
|
80
|
-
"@filoz/synapse-
|
|
81
|
+
"@filoz/synapse-sdk": "^0.40.1",
|
|
82
|
+
"@filoz/synapse-core": "^0.3.3"
|
|
81
83
|
},
|
|
82
84
|
"devDependencies": {
|
|
83
|
-
"@biomejs/biome": "2.
|
|
84
|
-
"@types/node": "^25.
|
|
85
|
+
"@biomejs/biome": "2.4.8",
|
|
86
|
+
"@types/node": "^25.3.5",
|
|
85
87
|
"type-fest": "^5.4.3",
|
|
86
88
|
"typescript": "5.9.3",
|
|
87
|
-
"viem": "^2.
|
|
89
|
+
"viem": "^2.47.0"
|
|
88
90
|
},
|
|
89
91
|
"publishConfig": {
|
|
90
92
|
"access": "public"
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { getChain } from '@filoz/synapse-core/chains'
|
|
2
|
-
import type { SessionKey } from '@filoz/synapse-core/session-key'
|
|
3
1
|
import * as SP from '@filoz/synapse-core/sp'
|
|
4
2
|
import type { PdpDataSet } from '@filoz/synapse-core/warm-storage'
|
|
5
3
|
import { type MutateOptions, useMutation, useQueryClient } from '@tanstack/react-query'
|
|
@@ -13,7 +11,6 @@ export interface UseDeletePieceProps {
|
|
|
13
11
|
* The callback to call when the hash is available.
|
|
14
12
|
*/
|
|
15
13
|
onHash?: (hash: string) => void
|
|
16
|
-
sessionKey?: SessionKey
|
|
17
14
|
mutation?: Omit<MutateOptions<TransactionReceipt, Error, UseDeletePieceVariables>, 'mutationFn'>
|
|
18
15
|
}
|
|
19
16
|
|
|
@@ -24,7 +21,6 @@ export interface UseDeletePieceVariables {
|
|
|
24
21
|
export function useDeletePiece(props: UseDeletePieceProps) {
|
|
25
22
|
const config = useConfig()
|
|
26
23
|
const chainId = useChainId({ config })
|
|
27
|
-
const chain = getChain(chainId)
|
|
28
24
|
const account = useAccount({ config })
|
|
29
25
|
const queryClient = useQueryClient()
|
|
30
26
|
const client = config.getClient()
|
|
@@ -32,15 +28,11 @@ export function useDeletePiece(props: UseDeletePieceProps) {
|
|
|
32
28
|
return useMutation({
|
|
33
29
|
...props?.mutation,
|
|
34
30
|
mutationFn: async ({ dataSet, pieceId }: UseDeletePieceVariables) => {
|
|
35
|
-
|
|
31
|
+
const connectorClient = await getConnectorClient(config, {
|
|
36
32
|
account: account.address,
|
|
37
33
|
chainId,
|
|
38
34
|
})
|
|
39
35
|
|
|
40
|
-
if (props?.sessionKey && (await props?.sessionKey.isValid(connectorClient, 'SchedulePieceRemovals'))) {
|
|
41
|
-
connectorClient = props?.sessionKey.client(chain, client.transport)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
36
|
const deletePieceRsp = await SP.schedulePieceDeletion(connectorClient, {
|
|
45
37
|
serviceURL: dataSet.provider.pdp.serviceURL,
|
|
46
38
|
dataSetId: dataSet.dataSetId,
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as SP from '@filoz/synapse-core/sp'
|
|
2
|
+
import { type AddPiecesSuccess, upload } from '@filoz/synapse-core/sp'
|
|
3
|
+
import { type MutateOptions, useMutation, useQueryClient } from '@tanstack/react-query'
|
|
4
|
+
import { useChainId, useConfig, useConnection } from 'wagmi'
|
|
5
|
+
import { getConnectorClient } from 'wagmi/actions'
|
|
6
|
+
|
|
7
|
+
export interface UseUploadSimpleProps {
|
|
8
|
+
/**
|
|
9
|
+
* The callback to call when the hash is available.
|
|
10
|
+
*/
|
|
11
|
+
onHash?: (hash: string) => void
|
|
12
|
+
mutation?: Omit<MutateOptions<AddPiecesSuccess, Error, UseUploadSimpleVariables>, 'mutationFn'>
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface UseUploadSimpleVariables {
|
|
16
|
+
files: File[]
|
|
17
|
+
dataSetId: bigint
|
|
18
|
+
}
|
|
19
|
+
export function useUploadSimple(props: UseUploadSimpleProps) {
|
|
20
|
+
const config = useConfig()
|
|
21
|
+
const chainId = useChainId({ config })
|
|
22
|
+
const account = useConnection({ config })
|
|
23
|
+
const queryClient = useQueryClient()
|
|
24
|
+
|
|
25
|
+
return useMutation({
|
|
26
|
+
...props?.mutation,
|
|
27
|
+
mutationFn: async ({ files, dataSetId }: UseUploadSimpleVariables) => {
|
|
28
|
+
const connectorClient = await getConnectorClient(config, {
|
|
29
|
+
account: account.address,
|
|
30
|
+
chainId,
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const uploadRsp = await upload(connectorClient, {
|
|
34
|
+
dataSetId,
|
|
35
|
+
data: files,
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
props?.onHash?.(uploadRsp.txHash)
|
|
39
|
+
const rsp = await SP.waitForAddPieces(uploadRsp)
|
|
40
|
+
|
|
41
|
+
queryClient.invalidateQueries({
|
|
42
|
+
queryKey: ['synapse-warm-storage-data-sets', account.address, config.getClient().chain.id],
|
|
43
|
+
})
|
|
44
|
+
return rsp
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
}
|
|
@@ -1,50 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type
|
|
3
|
-
import
|
|
4
|
-
import { type AddPiecesSuccess, upload } from '@filoz/synapse-core/sp'
|
|
1
|
+
import { asClient } from '@filoz/synapse-core/chains'
|
|
2
|
+
import { Synapse, type UploadResult } from '@filoz/synapse-sdk'
|
|
3
|
+
import type { StorageManagerUploadOptions } from '@filoz/synapse-sdk/storage'
|
|
5
4
|
import { type MutateOptions, useMutation, useQueryClient } from '@tanstack/react-query'
|
|
6
|
-
import {
|
|
5
|
+
import { useChainId, useConfig, useConnection } from 'wagmi'
|
|
7
6
|
import { getConnectorClient } from 'wagmi/actions'
|
|
8
7
|
|
|
9
|
-
export interface UseUploadProps {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*/
|
|
13
|
-
onHash?: (hash: string) => void
|
|
14
|
-
sessionKey?: SessionKey
|
|
15
|
-
mutation?: Omit<MutateOptions<AddPiecesSuccess, Error, UseUploadVariables>, 'mutationFn'>
|
|
8
|
+
export interface UseUploadProps extends Omit<StorageManagerUploadOptions, 'contexts' | 'pieceMetadata'> {
|
|
9
|
+
source: string | null
|
|
10
|
+
mutation?: Omit<MutateOptions<UploadResult, Error, UseUploadVariables>, 'mutationFn'>
|
|
16
11
|
}
|
|
17
12
|
|
|
18
13
|
export interface UseUploadVariables {
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
file: File
|
|
15
|
+
metadata?: Record<string, string>
|
|
21
16
|
}
|
|
22
17
|
export function useUpload(props: UseUploadProps) {
|
|
23
18
|
const config = useConfig()
|
|
24
19
|
const chainId = useChainId({ config })
|
|
25
|
-
const
|
|
26
|
-
const account = useAccount({ config })
|
|
20
|
+
const account = useConnection({ config })
|
|
27
21
|
const queryClient = useQueryClient()
|
|
28
|
-
const client = config.getClient()
|
|
29
22
|
|
|
30
23
|
return useMutation({
|
|
31
24
|
...props?.mutation,
|
|
32
|
-
mutationFn: async ({
|
|
33
|
-
|
|
25
|
+
mutationFn: async ({ file, metadata }: UseUploadVariables) => {
|
|
26
|
+
const connectorClient = await getConnectorClient(config, {
|
|
34
27
|
account: account.address,
|
|
35
28
|
chainId,
|
|
36
29
|
})
|
|
37
|
-
if (props?.sessionKey && (await props?.sessionKey.isValid(connectorClient, 'AddPieces'))) {
|
|
38
|
-
connectorClient = props?.sessionKey.client(chain, client.transport)
|
|
39
|
-
}
|
|
40
30
|
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
31
|
+
const synapse = new Synapse({
|
|
32
|
+
client: asClient(connectorClient),
|
|
33
|
+
source: props.source,
|
|
44
34
|
})
|
|
45
35
|
|
|
46
|
-
|
|
47
|
-
|
|
36
|
+
const rsp = await synapse.storage.upload(new Uint8Array(await file.arrayBuffer()), {
|
|
37
|
+
...props,
|
|
38
|
+
pieceMetadata: metadata,
|
|
39
|
+
})
|
|
48
40
|
|
|
49
41
|
queryClient.invalidateQueries({
|
|
50
42
|
queryKey: ['synapse-warm-storage-data-sets', account.address, config.getClient().chain.id],
|