Skip to content

Commit

Permalink
chore: mark ipfs fns as deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
alfetopito committed Sep 5, 2024
1 parent 6cd7e05 commit 9e7bea2
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/api/appDataHexToCid.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import { MetaDataError } from '../consts'

/**
* @deprecated AppData is not longer stored on IPFS nor it's derived from IPFS content hashes
*
* @param appDataHex
* @returns
*/
export async function appDataHexToCid(appDataHex: string): Promise<string> {
const cid = await _appDataHexToCid(appDataHex)
_assertCid(cid, appDataHex)

return cid
}

/**
* @deprecated AppData is not longer stored on IPFS nor it's derived from IPFS content hashes
*
* @param appDataHex
* @returns
*/
export async function appDataHexToCidLegacy(appDataHex: string): Promise<string> {
const cid = await _appDataHexToCidLegacy(appDataHex)
_assertCid(cid, appDataHex)
Expand Down
16 changes: 16 additions & 0 deletions src/api/appDataToCid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { validateAppDataDoc } from './validateAppDataDoc'
/**
* Calculates appDataHex without publishing file to IPFS
*
* @deprecated AppData is not longer stored on IPFS nor it's derived from IPFS content hashes
*
* This method is intended to quickly generate the appDataHex independent
* of IPFS upload/pinning
*
Expand All @@ -19,13 +21,21 @@ export async function appDataToCid(appData: AnyAppDataDocVersion): Promise<IpfsH
/**
* Calculates appDataHex without publishing file to IPFS
*
* @deprecated AppData is not longer stored on IPFS nor it's derived from IPFS content hashes
*
* This method is intended to quickly generate the appDataHex independent
* of IPFS upload/pinning
*
* @param fullAppData JSON string with the full appData document
*/
export async function appDataToCid(fullAppData: string): Promise<IpfsHashInfo | void>

/**
* @deprecated AppData is not longer stored on IPFS nor it's derived from IPFS content hashes
*
* @param appDataAux
* @returns
*/
export async function appDataToCid(appDataAux: AnyAppDataDocVersion | string): Promise<IpfsHashInfo> {
return _appDataToCidAux(appDataAux, _appDataToCid)
}
Expand Down Expand Up @@ -54,6 +64,12 @@ export async function appDataToCidLegacy(appData: AnyAppDataDocVersion): Promise
*/
export async function appDataToCidLegacy(fullAppData: string): Promise<IpfsHashInfo | void>

/**
* @deprecated AppData is not longer stored on IPFS nor it's derived from IPFS content hashes
*
* @param appDataAux
* @returns
*/
export async function appDataToCidLegacy(appDataAux: AnyAppDataDocVersion | string): Promise<IpfsHashInfo | void> {
// For the legacy-mode we use plain JSON.stringify to mantain backwards compatibility, however this is not a good idea to do since JSON.stringify. Better specify the doc as a fullAppData string or use stringifyDeterministic
const fullAppData = JSON.stringify(appDataAux)
Expand Down
6 changes: 6 additions & 0 deletions src/api/cidToAppDataHex.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { extractDigest } from '../utils/ipfs'

/**
* @deprecated AppData is not longer stored on IPFS nor it's derived from IPFS content hashes
*
* @param cid
* @returns
*/
export async function cidToAppDataHex(cid: string): Promise<string> {
return extractDigest(cid)
}
4 changes: 3 additions & 1 deletion src/api/fetchDocFromAppData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { appDataHexToCid, appDataHexToCidLegacy } from './appDataHexToCid'
import { fetchDocFromCid } from './fetchDocFromCid'

/**
*
* @deprecated AppData is not longer stored on IPFS nor it's derived from IPFS content hashes
*
* @param appDataHex Derives the CID from the appData hex, and fetches and parses the document from IPFS
* @param ipfsUri URL of the IPFS gateway to use for the fetch
Expand All @@ -20,7 +22,7 @@ export async function fetchDocFromAppDataHex(
/**
* Fetches the document from IPFS using the appData hex
*
* @deprecated
* @deprecated AppData is not longer stored on IPFS nor it's derived from IPFS content hashes
*
* @param appDataHex
* @param ipfsUri
Expand Down
7 changes: 7 additions & 0 deletions src/api/fetchDocFromCid.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { AnyAppDataDocVersion } from 'generatedTypes'
import { DEFAULT_IPFS_READ_URI } from '../consts'

/**
* @deprecated AppData is not longer stored on IPFS nor it's derived from IPFS content hashes
*
* @param cid
* @param ipfsUri
* @returns
*/
export async function fetchDocFromCid(cid: string, ipfsUri = DEFAULT_IPFS_READ_URI): Promise<AnyAppDataDocVersion> {
const { default: fetch } = await import('cross-fetch')
const response = await fetch(`${ipfsUri}/${cid}`)
Expand Down
7 changes: 4 additions & 3 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ export class MetadataApi {
generateAppDataDoc = generateAppDataDoc
validateAppDataDoc = validateAppDataDoc

// appData / CID conversion
// ---- Deprecated methods ----

// appData / CID conversion (deprecated)
appDataToCid = appDataToCid // (appData | fullAppData) --> cid
appDataHexToCid = appDataHexToCid // appDataHex --> cid
cidToAppDataHex = cidToAppDataHex // cid --> appDataHex

// Fetch appData document from IPFS
// Fetch appData document from IPFS (deprecated)
fetchDocFromCid = fetchDocFromCid // cid --> document
fetchDocFromAppDataHex = fetchDocFromAppDataHex // appDataHex --> appData

// ---- Deprecated methods ----
// Upload to IPFS (deprecated)
uploadMetadataDocToIpfsLegacy = uploadMetadataDocToIpfsLegacy // appData --> cid + publish IPFS
appDataToCidLegacy = appDataToCidLegacy // (appData | fullAppData) --> cid
Expand Down

0 comments on commit 9e7bea2

Please sign in to comment.