@seedprotocol/sdk 0.3.13 → 0.3.14

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.
@@ -1,7 +1,8 @@
1
1
  import { getArweave } from '../../helpers/ArweaveClient/index.js';
2
- import { getCorrectId, getContentHash } from '../../helpers/index.js';
2
+ import { getCorrectId } from '../../helpers/index.js';
3
3
  import { getSegmentedItemProperties } from '../../helpers/getSegmentedItemProperties.js';
4
4
  import debug from 'debug';
5
+ import { getContentHash } from '../../helpers/crypto.js';
5
6
  import { BaseItem } from '../../Item/BaseItem.js';
6
7
  import { BaseFileManager } from '../../helpers/FileManager/BaseFileManager.js';
7
8
 
@@ -1 +1 @@
1
- {"version":3,"file":"getPublishUploads.js","sources":["../../../../../src/db/read/getPublishUploads.ts"],"sourcesContent":["import Transaction from 'arweave'\nimport { CreateTransactionInterface } from 'arweave/web'\nimport { getArweave } from '@/helpers/ArweaveClient'\nimport { BaseFileManager, getCorrectId } from '@/helpers'\nimport { getSegmentedItemProperties } from '@/helpers/getSegmentedItemProperties'\nimport debug from 'debug'\nimport { IItem, IItemProperty } from '@/interfaces'\nimport { getContentHash } from '@/helpers'\nimport { BaseItem } from '@/Item/BaseItem'\nconst logger = debug('seedSdk:item:getPublishUploads')\n\n\nexport const prepareArweaveTransaction = async (\n data: string | Uint8Array,\n contentHash: string | undefined,\n): Promise<Transaction> => {\n const transactionData: Partial<CreateTransactionInterface> = {\n data,\n tags: [],\n }\n\n const tx = await getArweave()!.createTransaction(transactionData)\n\n if (contentHash) {\n logger('contentHash', contentHash)\n logger('adding content hash tag to tx.id:', tx.id)\n tx.addTag('Content-SHA-256', contentHash)\n }\n\n return tx\n}\n\n\nconst getImageUploads = async (itemImageProperties: IItemProperty<any>[]) => {\n const uploads: PublishUpload[] = []\n\n for (const itemImageProperty of itemImageProperties) {\n\n const filePath = `/files/images/${itemImageProperty.refResolvedValue}`\n\n if (!filePath) {\n continue\n }\n\n const exists = await BaseFileManager.pathExists(filePath)\n if (!exists) {\n continue\n }\n\n const fileContents = await BaseFileManager.readFileAsString(filePath)\n\n const contentHash = await getContentHash(fileContents)\n\n const transaction = await prepareArweaveTransaction(fileContents, contentHash)\n\n uploads.push({\n itemPropertyName: itemImageProperty.propertyName,\n itemPropertyLocalId: itemImageProperty.localId,\n seedLocalId: itemImageProperty.seedLocalId!,\n versionLocalId: itemImageProperty.versionLocalId!,\n transactionToSign: transaction,\n })\n }\n\n return uploads\n}\n\n\nexport type UploadProperty = {\n itemProperty: IItemProperty<any>\n childProperties: IItemProperty<any>[]\n}\ntype ChildUploadData = {\n propertyName: string\n localStoragePath: string\n}\nconst processUploadProperty = async (\n uploadProperty: UploadProperty,\n uploads: PublishUpload[],\n relatedItemProperty?: IItemProperty<any>,\n): Promise<PublishUpload[]> => {\n const itemProperty = uploadProperty.itemProperty\n\n const childUploads: ChildUploadData[] = []\n\n for (const childProperty of uploadProperty.childProperties) {\n const filePath = childProperty.localStoragePath\n\n if (!filePath || filePath.endsWith('undefined')) {\n continue\n }\n\n const exists = await BaseFileManager.pathExists(filePath)\n if (!exists) {\n continue\n }\n\n childUploads.push({\n propertyName: childProperty.propertyName,\n localStoragePath: filePath,\n })\n }\n\n let fileContents\n let transaction: Transaction\n\n if (!childUploads || childUploads.length === 0) {\n if (relatedItemProperty && relatedItemProperty.localStoragePath) {\n const filePath = relatedItemProperty.localStoragePath\n\n if (!filePath || filePath.endsWith('undefined')) {\n return uploads\n }\n\n const exists = await BaseFileManager.pathExists(filePath)\n if (!exists) {\n return uploads\n\n }\n\n try {\n fileContents = await BaseFileManager.readFileAsString(filePath)\n } catch (e) {\n const fs = await BaseFileManager.getFs()\n fileContents = fs.readFileSync(filePath)\n }\n }\n if (!fileContents) {\n return uploads\n }\n }\n\n if (childUploads.length > 0) {\n const separator = '===FILE_SEPARATOR==='\n // let compositeFileContents = `${itemProperty.propertyName}${separator}${mainFileContents}`\n let compositeFileContents = ''\n\n for (const childUpload of childUploads) {\n let childUploadContents\n\n const fs = await BaseFileManager.getFs()\n\n try {\n childUploadContents = await fs.promises.readFile(\n childUpload.localStoragePath,\n )\n } catch (e) {\n childUploadContents = fs.readFileSync(childUpload.localStoragePath)\n }\n\n compositeFileContents += `${separator}${childUpload.propertyName}${separator}${childUploadContents}`\n }\n\n if (typeof document !== 'undefined') {\n fileContents = new TextEncoder().encode(compositeFileContents)\n } else {\n fileContents = Buffer.from(compositeFileContents)\n }\n }\n\n if (!fileContents) {\n throw new Error(`No file contents found for ${itemProperty.propertyName}`)\n }\n\n const uint8Array = new Uint8Array(\n fileContents.buffer,\n fileContents.byteOffset,\n fileContents.byteLength,\n )\n\n const contentHash = await getContentHash(uint8Array)\n\n transaction = await prepareArweaveTransaction(fileContents, contentHash)\n\n let itemPropertyLocalId = relatedItemProperty\n ? relatedItemProperty.localId\n : itemProperty.localId\n let itemPropertyName = relatedItemProperty\n ? relatedItemProperty.propertyName\n : itemProperty.propertyName\n\n uploads.push({\n itemPropertyName,\n itemPropertyLocalId,\n seedLocalId: itemProperty.seedLocalId!,\n versionLocalId: itemProperty.versionLocalId!,\n transactionToSign: transaction,\n })\n\n return uploads\n}\n\n\nexport type PublishUpload = {\n itemPropertyName: string\n itemPropertyLocalId: string\n seedLocalId: string\n versionLocalId: string\n transactionToSign: Transaction\n}\nexport const getPublishUploads = async (\n item: IItem<any>,\n uploads: PublishUpload[] = [],\n relatedItemProperty?: IItemProperty<any>,\n) => {\n // if (item.modelName === 'Post') {\n // if (!item.authors) {\n // item.authors = [\n // 'Sr0bIx9Fwj',\n // '0xc2879650e9503a303ceb46f966e55baab480b267dc20cede23ef503622eee6d7',\n // ]\n // }\n // }\n\n const { itemUploadProperties, itemRelationProperties, itemImageProperties } =\n getSegmentedItemProperties(item)\n\n for (const uploadProperty of itemUploadProperties) {\n uploads = await processUploadProperty(\n uploadProperty,\n uploads,\n relatedItemProperty,\n )\n }\n\n const imageUploads = await getImageUploads(itemImageProperties)\n uploads.push(...imageUploads)\n\n for (const relationProperty of itemRelationProperties) {\n const propertyValue = relationProperty.getService().getSnapshot()\n .context.propertyValue\n\n if (!propertyValue || relationProperty.uid) {\n continue\n }\n\n const { localId: seedLocalId, uid: seedUid } = getCorrectId(propertyValue)\n\n const relatedItem = await BaseItem.find({\n seedLocalId,\n seedUid,\n })\n\n if (!relatedItem) {\n throw new Error(\n `No relatedItem found for ${relationProperty.propertyName}`,\n )\n }\n\n uploads = await getPublishUploads(relatedItem, uploads, relationProperty)\n }\n\n return uploads\n}\n"],"names":[],"mappings":";;;;;;;AASA,MAAM,MAAM,GAAG,KAAK,CAAC,gCAAgC,CAAC;AAGzC,MAAA,yBAAyB,GAAG,OACvC,IAAyB,EACzB,WAA+B,KACP;AACxB,IAAA,MAAM,eAAe,GAAwC;QAC3D,IAAI;AACJ,QAAA,IAAI,EAAE,EAAE;KACT;IAED,MAAM,EAAE,GAAG,MAAM,UAAU,EAAG,CAAC,iBAAiB,CAAC,eAAe,CAAC;IAEjE,IAAI,WAAW,EAAE;AACf,QAAA,MAAM,CAAC,aAAa,EAAE,WAAW,CAAC;AAClC,QAAA,MAAM,CAAC,mCAAmC,EAAE,EAAE,CAAC,EAAE,CAAC;AAClD,QAAA,EAAE,CAAC,MAAM,CAAC,iBAAiB,EAAE,WAAW,CAAC;;AAG3C,IAAA,OAAO,EAAE;AACX;AAGA,MAAM,eAAe,GAAG,OAAO,mBAAyC,KAAI;IAC1E,MAAM,OAAO,GAAoB,EAAE;AAEnC,IAAA,KAAK,MAAM,iBAAiB,IAAI,mBAAmB,EAAE;AAEnD,QAAA,MAAM,QAAQ,GAAG,CAAA,cAAA,EAAiB,iBAAiB,CAAC,gBAAgB,EAAE;QAEtE,IAAI,CAAC,QAAQ,EAAE;YACb;;QAGF,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,UAAU,CAAC,QAAQ,CAAC;QACzD,IAAI,CAAC,MAAM,EAAE;YACX;;QAGF,MAAM,YAAY,GAAG,MAAM,eAAe,CAAC,gB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,IAAA,OAAO,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC;AAE7B,IAAA,KAAK,MAAM,gBAAgB,IAAI,sBAAsB,EAAE;QACrD,MAAM,aAAa,GAAG,gBAAgB,CAAC,UAAU,EAAE,CAAC,WAAW;aAC5D,OAAO,CAAC,aAAa;AAExB,QAAA,IAAI,CAAC,aAAa,IAAI,gBAAgB,CAAC,GAAG,EAAE;YAC1C;;AAGF,QAAA,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,YAAY,CAAC,aAAa,CAAC;AAE1E,QAAA,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC;YACtC,WAAW;YACX,OAAO;AACR,SAAA,CAAC;QAEF,IAAI,CAAC,WAAW,EAAE;YAChB,MAAM,IAAI,KAAK,CACb,CAAA,yBAAA,EAA4B,gBAAgB,CAAC,YAAY,CAAE,CAAA,CAC5D;;QAGH,OAAO,GAAG,MAAM,iBAAiB,CAAC,WAAW,EAAE,OAAO,EAAE,gBAAgB,CAAC;;AAG3E,IAAA,OAAO,OAAO;AAChB;;;;"}
1
+ {"version":3,"file":"getPublishUploads.js","sources":["../../../../../src/db/read/getPublishUploads.ts"],"sourcesContent":["import Transaction from 'arweave'\nimport { CreateTransactionInterface } from 'arweave/web'\nimport { getArweave } from '@/helpers/ArweaveClient'\nimport { BaseFileManager, getCorrectId } from '@/helpers'\nimport { getSegmentedItemProperties } from '@/helpers/getSegmentedItemProperties'\nimport debug from 'debug'\nimport { IItem, IItemProperty } from '@/interfaces'\nimport { getContentHash } from '@/helpers/crypto'\nimport { BaseItem } from '@/Item/BaseItem'\nconst logger = debug('seedSdk:item:getPublishUploads')\n\n\nexport const prepareArweaveTransaction = async (\n data: string | Uint8Array,\n contentHash: string | undefined,\n): Promise<Transaction> => {\n const transactionData: Partial<CreateTransactionInterface> = {\n data,\n tags: [],\n }\n\n const tx = await getArweave()!.createTransaction(transactionData)\n\n if (contentHash) {\n logger('contentHash', contentHash)\n logger('adding content hash tag to tx.id:', tx.id)\n tx.addTag('Content-SHA-256', contentHash)\n }\n\n return tx\n}\n\n\nconst getImageUploads = async (itemImageProperties: IItemProperty<any>[]) => {\n const uploads: PublishUpload[] = []\n\n for (const itemImageProperty of itemImageProperties) {\n\n const filePath = `/files/images/${itemImageProperty.refResolvedValue}`\n\n if (!filePath) {\n continue\n }\n\n const exists = await BaseFileManager.pathExists(filePath)\n if (!exists) {\n continue\n }\n\n const fileContents = await BaseFileManager.readFileAsString(filePath)\n\n const contentHash = await getContentHash(fileContents)\n\n const transaction = await prepareArweaveTransaction(fileContents, contentHash)\n\n uploads.push({\n itemPropertyName: itemImageProperty.propertyName,\n itemPropertyLocalId: itemImageProperty.localId,\n seedLocalId: itemImageProperty.seedLocalId!,\n versionLocalId: itemImageProperty.versionLocalId!,\n transactionToSign: transaction,\n })\n }\n\n return uploads\n}\n\n\nexport type UploadProperty = {\n itemProperty: IItemProperty<any>\n childProperties: IItemProperty<any>[]\n}\ntype ChildUploadData = {\n propertyName: string\n localStoragePath: string\n}\nconst processUploadProperty = async (\n uploadProperty: UploadProperty,\n uploads: PublishUpload[],\n relatedItemProperty?: IItemProperty<any>,\n): Promise<PublishUpload[]> => {\n const itemProperty = uploadProperty.itemProperty\n\n const childUploads: ChildUploadData[] = []\n\n for (const childProperty of uploadProperty.childProperties) {\n const filePath = childProperty.localStoragePath\n\n if (!filePath || filePath.endsWith('undefined')) {\n continue\n }\n\n const exists = await BaseFileManager.pathExists(filePath)\n if (!exists) {\n continue\n }\n\n childUploads.push({\n propertyName: childProperty.propertyName,\n localStoragePath: filePath,\n })\n }\n\n let fileContents\n let transaction: Transaction\n\n if (!childUploads || childUploads.length === 0) {\n if (relatedItemProperty && relatedItemProperty.localStoragePath) {\n const filePath = relatedItemProperty.localStoragePath\n\n if (!filePath || filePath.endsWith('undefined')) {\n return uploads\n }\n\n const exists = await BaseFileManager.pathExists(filePath)\n if (!exists) {\n return uploads\n\n }\n\n try {\n fileContents = await BaseFileManager.readFileAsString(filePath)\n } catch (e) {\n const fs = await BaseFileManager.getFs()\n fileContents = fs.readFileSync(filePath)\n }\n }\n if (!fileContents) {\n return uploads\n }\n }\n\n if (childUploads.length > 0) {\n const separator = '===FILE_SEPARATOR==='\n // let compositeFileContents = `${itemProperty.propertyName}${separator}${mainFileContents}`\n let compositeFileContents = ''\n\n for (const childUpload of childUploads) {\n let childUploadContents\n\n const fs = await BaseFileManager.getFs()\n\n try {\n childUploadContents = await fs.promises.readFile(\n childUpload.localStoragePath,\n )\n } catch (e) {\n childUploadContents = fs.readFileSync(childUpload.localStoragePath)\n }\n\n compositeFileContents += `${separator}${childUpload.propertyName}${separator}${childUploadContents}`\n }\n\n if (typeof document !== 'undefined') {\n fileContents = new TextEncoder().encode(compositeFileContents)\n } else {\n fileContents = Buffer.from(compositeFileContents)\n }\n }\n\n if (!fileContents) {\n throw new Error(`No file contents found for ${itemProperty.propertyName}`)\n }\n\n const uint8Array = new Uint8Array(\n fileContents.buffer,\n fileContents.byteOffset,\n fileContents.byteLength,\n )\n\n const contentHash = await getContentHash(uint8Array)\n\n transaction = await prepareArweaveTransaction(fileContents, contentHash)\n\n let itemPropertyLocalId = relatedItemProperty\n ? relatedItemProperty.localId\n : itemProperty.localId\n let itemPropertyName = relatedItemProperty\n ? relatedItemProperty.propertyName\n : itemProperty.propertyName\n\n uploads.push({\n itemPropertyName,\n itemPropertyLocalId,\n seedLocalId: itemProperty.seedLocalId!,\n versionLocalId: itemProperty.versionLocalId!,\n transactionToSign: transaction,\n })\n\n return uploads\n}\n\n\nexport type PublishUpload = {\n itemPropertyName: string\n itemPropertyLocalId: string\n seedLocalId: string\n versionLocalId: string\n transactionToSign: Transaction\n}\nexport const getPublishUploads = async (\n item: IItem<any>,\n uploads: PublishUpload[] = [],\n relatedItemProperty?: IItemProperty<any>,\n) => {\n // if (item.modelName === 'Post') {\n // if (!item.authors) {\n // item.authors = [\n // 'Sr0bIx9Fwj',\n // '0xc2879650e9503a303ceb46f966e55baab480b267dc20cede23ef503622eee6d7',\n // ]\n // }\n // }\n\n const { itemUploadProperties, itemRelationProperties, itemImageProperties } =\n getSegmentedItemProperties(item)\n\n for (const uploadProperty of itemUploadProperties) {\n uploads = await processUploadProperty(\n uploadProperty,\n uploads,\n relatedItemProperty,\n )\n }\n\n const imageUploads = await getImageUploads(itemImageProperties)\n uploads.push(...imageUploads)\n\n for (const relationProperty of itemRelationProperties) {\n const propertyValue = relationProperty.getService().getSnapshot()\n .context.propertyValue\n\n if (!propertyValue || relationProperty.uid) {\n continue\n }\n\n const { localId: seedLocalId, uid: seedUid } = getCorrectId(propertyValue)\n\n const relatedItem = await BaseItem.find({\n seedLocalId,\n seedUid,\n })\n\n if (!relatedItem) {\n throw new Error(\n `No relatedItem found for ${relationProperty.propertyName}`,\n )\n }\n\n uploads = await getPublishUploads(relatedItem, uploads, relationProperty)\n }\n\n return uploads\n}\n"],"names":[],"mappings":";;;;;;;;AASA,MAAM,MAAM,GAAG,KAAK,CAAC,gCAAgC,CAAC;AAGzC,MAAA,yBAAyB,GAAG,OACvC,IAAyB,EACzB,WAA+B,KACP;AACxB,IAAA,MAAM,eAAe,GAAwC;QAC3D,IAAI;AACJ,QAAA,IAAI,EAAE,EAAE;KACT;IAED,MAAM,EAAE,GAAG,MAAM,UAAU,EAAG,CAAC,iBAAiB,CAAC,eAAe,CAAC;IAEjE,IAAI,WAAW,EAAE;AACf,QAAA,MAAM,CAAC,aAAa,EAAE,WAAW,CAAC;AAClC,QAAA,MAAM,CAAC,mCAAmC,EAAE,EAAE,CAAC,EAAE,CAAC;AAClD,QAAA,EAAE,CAAC,MAAM,CAAC,iBAAiB,EAAE,WAAW,CAAC;;AAG3C,IAAA,OAAO,EAAE;AACX;AAGA,MAAM,eAAe,GAAG,OAAO,mBAAyC,KAAI;IAC1E,MAAM,OAAO,GAAoB,EAAE;AAEnC,IAAA,KAAK,MAAM,iBAAiB,IAAI,mBAAmB,EAAE;AA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B,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,GACzE,0BAA0B,CAAC,IAAI,CAAC;AAElC,IAAA,KAAK,MAAM,cAAc,IAAI,oBAAoB,EAAE;QACjD,OAAO,GAAG,MAAM,qBAAqB,CACnC,cAAc,EACd,OAAO,EACP,mBAAmB,CACpB;;AAGH,IAAA,MAAM,YAAY,GAAG,MAAM,eAAe,CAAC,mBAAmB,CAAC;AAC/D,IAAA,OAAO,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC;AAE7B,IAAA,KAAK,MAAM,gBAAgB,IAAI,sBAAsB,EAAE;QACrD,MAAM,aAAa,GAAG,gBAAgB,CAAC,UAAU,EAAE,CAAC,WAAW;aAC5D,OAAO,CAAC,aAAa;AAExB,QAAA,IAAI,CAAC,aAAa,IAAI,gBAAgB,CAAC,GAAG,EAAE;YAC1C;;AAGF,QAAA,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,YAAY,CAAC,aAAa,CAAC;AAE1E,QAAA,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC;YACtC,WAAW;YACX,OAAO;AACR,SAAA,CAAC;QAEF,IAAI,CAAC,WAAW,EAAE;YAChB,MAAM,IAAI,KAAK,CACb,CAAA,yBAAA,EAA4B,gBAAgB,CAAC,YAAY,CAAE,CAAA,CAC5D;;QAGH,OAAO,GAAG,MAAM,iBAAiB,CAAC,WAAW,EAAE,OAAO,EAAE,gBAAgB,CAAC;;AAG3E,IAAA,OAAO,OAAO;AAChB;;;;"}
@@ -0,0 +1,3 @@
1
+ import * as sha3 from 'js-sha3';
2
+ export declare const getContentHash: (data: sha3.Message) => Promise<string>;
3
+ //# sourceMappingURL=crypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../../src/helpers/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,SAAS,CAAA;AAK/B,eAAO,MAAM,cAAc,SACnB,IAAI,CAAC,OAAO,KACjB,OAAO,CAAC,MAAM,CAEhB,CAAA"}
@@ -0,0 +1,9 @@
1
+ import * as sha3 from 'js-sha3';
2
+
3
+ const { sha3_256, } = sha3;
4
+ const getContentHash = async (data) => {
5
+ return sha3_256(data);
6
+ };
7
+
8
+ export { getContentHash };
9
+ //# sourceMappingURL=crypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.js","sources":["../../../../src/helpers/crypto.ts"],"sourcesContent":["import * as sha3 from 'js-sha3'\n\nconst { sha3_256, } = sha3\n\n\nexport const getContentHash = async (\n data: sha3.Message\n): Promise<string> => {\n return sha3_256(data)\n}"],"names":[],"mappings":";;AAEA,MAAM,EAAE,QAAQ,GAAG,GAAG,IAAI;MAGb,cAAc,GAAG,OAC5B,IAAkB,KACC;AACnB,IAAA,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB;;;;"}
@@ -1,4 +1,3 @@
1
- import { Message } from 'js-sha3';
2
1
  import { GetCorrectId } from '@/types/helpers';
3
2
  export * from './ArweaveClient/BaseArweaveClient';
4
3
  export * from './EasClient/BaseEasClient';
@@ -18,6 +17,5 @@ export declare const parseEasRelationPropertyName: (easPropertyName: string) =>
18
17
  modelName: string;
19
18
  isList: boolean;
20
19
  };
21
- export declare const getContentHash: (data: Message) => Promise<string>;
22
20
  export declare const isBinary: (arrayBuffer: ArrayBuffer) => boolean;
23
21
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAa,MAAkB,SAAS,CAAA;AAGxD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAG9C,cAAc,mCAAmC,CAAA;AACjD,cAAc,2BAA2B,CAAA;AACzC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,+BAA+B,CAAA;AAM7C,eAAO,MAAM,UAA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AA;AAED,eAAO,MAAM,kBAAkB,SACvB,MAAM,KACX,OAAO,CAAC,MAAM,GAAG,SAAS,CAc5B,CAAA;AAED,eAAO,MAAM,gBAAgB,2CAI5B,CAAA;AAED,eAAO,MAAM,qBAAqB,WAAY,MAAM,WACF,CAAA;AAElD,eAAO,MAAM,4BAA4B,oBAAqB,MAAM;;;;CAiBnE,CAAA;AAGD,eAAO,MAAM,QAAQ,gBAAiB,WAAW,KAAG,OAwBnD,CAAA"}
@@ -1,5 +1,4 @@
1
1
  import { customAlphabet } from 'nanoid';
2
- import { sha3_256 } from 'js-sha3';
3
2
  import * as nanoIdDictionary from 'nanoid-dictionary';
4
3
  import debug from 'debug';
5
4
  import { BaseFileManager } from './FileManager/BaseFileManager.js';
@@ -86,9 +85,6 @@ const parseEasRelationPropertyName = (easPropertyName) => {
86
85
  isList, // True if the property is a list (e.g., 'ids' is present)
87
86
  };
88
87
  };
89
- const getContentHash = async (data) => {
90
- return sha3_256(data);
91
- };
92
88
 
93
- export { BaseFileManager, convertTxIdToImage, generateId, getContentHash, getCorrectId, getDataTypeFromString, getMimeType, parseEasRelationPropertyName, toSnakeCase };
89
+ export { BaseFileManager, convertTxIdToImage, generateId, getCorrectId, getDataTypeFromString, getMimeType, parseEasRelationPropertyName, toSnakeCase };
94
90
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/helpers/index.ts"],"sourcesContent":["import { customAlphabet } from 'nanoid'\nimport { Message, sha3_256, } from 'js-sha3'\nimport * as nanoIdDictionary from 'nanoid-dictionary'\nimport debug from 'debug'\nimport { GetCorrectId } from '@/types/helpers'\nimport { GetCorrectIdReturn } from '@/types/helpers'\nimport { BaseFileManager } from './FileManager/BaseFileManager'\nexport * from './ArweaveClient/BaseArweaveClient'\nexport * from './EasClient/BaseEasClient'\nexport * from './QueryClient/BaseQueryClient'\nexport * from './FileManager/BaseFileManager'\nconst logger = debug('seedSdk:shared:helpers')\n\n\nconst { alphanumeric } = nanoIdDictionary\n\nexport const generateId = (): string => {\n return customAlphabet(alphanumeric, 10)()\n}\n\nexport const toSnakeCase = (str: string) => {\n return str.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase()\n}\n\nexport const identifyString = (str: string) => {\n try {\n JSON.parse(str)\n return 'json'\n } catch (e) {\n // Not JSON\n }\n\n if (!str) {\n return\n }\n\n if (str.trim().startsWith('<') && str.trim().endsWith('>')) {\n return 'html'\n }\n\n // Simple markdown checks (very naive)\n if (/^#{1,6}\\s|^-{3,}|\\*{3,}|^-{1,2}\\s|\\*\\s/.test(str)) {\n return 'markdown'\n }\n\n if (/^data:image\\/[a-zA-Z]+;base64,[A-Za-z0-9+/]+={0,2}$/.test(str)) {\n return 'base64'\n }\n\n // Default to plain text if unsure\n return 'text'\n}\n\nexport const getMimeType = (base64: string) => {\n if (!base64) {\n return null\n }\n const result = base64.match(/^data:([a-zA-Z0-9]+\\/[a-zA-Z0-9-.+]+).*,/)\n\n if (result && result.length > 1) {\n return result[1]\n } else {\n return null // MIME type could not be determined\n }\n}\n\nexport const getCorrectId: GetCorrectId = (localIdOrUid: string) => {\n const id: GetCorrectIdReturn = {\n localId: undefined,\n uid: undefined,\n }\n if (!localIdOrUid) {\n return id\n }\n if (localIdOrUid.length === 10) {\n id.localId = localIdOrUid\n }\n if (localIdOrUid.startsWith('0x') && localIdOrUid.length === 66) {\n id.uid = localIdOrUid\n }\n return id\n}\n\nexport const getDataTypeFromString = (\n data: string,\n): 'imageBase64' | 'base64' | 'url' | null => {\n const nonImageBase64Regex =\n /^(?!data:image\\/(?:jpeg|png|gif|bmp|webp);base64,)[A-Za-z0-9+/=]+$/\n\n if (nonImageBase64Regex.test(data)) {\n return 'base64'\n }\n\n // Regular expression for base64 (simple version, checking for base64 format)\n const imageBase64Regex = /^data:image\\/[a-zA-Z]+;base64,[A-Za-z0-9+/]+={0,2}$/\n\n if (imageBase64Regex.test(data)) {\n return 'imageBase64'\n }\n\n // Regular expression for URL (simple version, checking for common URL format)\n const urlRegex =\n /^(http:\\/\\/www\\.|https:\\/\\/www\\.|http:\\/\\/|https:\\/\\/)?[a-z0-9]+([\\-\\.]{1}[a-z0-9]+)*\\.[a-z]{2,5}(:[0-9]{1,5})?(\\/.*)?$/\n\n if (urlRegex.test(data)) {\n return 'url'\n }\n\n return null\n}\n\nexport const convertTxIdToImage = async (\n txId: string,\n): Promise<string | undefined> => {\n const imageFilePath = `/files/images/${txId}`\n const fileExists = await BaseFileManager.pathExists(imageFilePath)\n if (!fileExists) {\n logger(`[ItemView] [updateImage] ${imageFilePath} does not exist`)\n return\n }\n const buffer = await BaseFileManager.readFileAsBuffer(imageFilePath)\n\n const uint = new Uint8Array(buffer)\n\n const imageBlob = new Blob([uint])\n\n return URL.createObjectURL(imageBlob)\n}\n\nexport const getExecutionTime = async (task, args) => {\n const start = Date.now()\n await task(...args)\n return Date.now() - start\n}\n\nexport const capitalizeFirstLetter = (string: string) =>\n string.charAt(0).toUpperCase() + string.slice(1)\n\nexport const parseEasRelationPropertyName = (easPropertyName: string) => {\n // Split the input string on the first underscore\n const [singularProperty, modelName, idSegment] = easPropertyName.split('_')\n\n // If there are any other parts, assume it is a list (e.g., has 'ids' or other suffix)\n const isList = idSegment === 'ids'\n\n // Create the final property name by pluralizing the singular part\n const propertyName = singularProperty.endsWith('s')\n ? singularProperty\n : singularProperty + 's'\n\n return {\n propertyName, // Plural form of the property name\n modelName, // Model name extracted from the second part\n isList, // True if the property is a list (e.g., 'ids' is present)\n }\n}\n\nexport const getContentHash = async (\n data: Message\n): Promise<string> => {\n return sha3_256(data)\n}\n\n// export const getContentHash = async (\n// base64: string | null | undefined,\n// uint: Uint8Array | undefined,\n// ): Promise<string> => {\n// let data\n\n// if (base64 && !uint) {\n// const encoder = new TextEncoder()\n// data = encoder.encode(base64)\n// }\n\n// if (uint) {\n// data = uint\n// }\n\n// // Hash the data with SHA-256\n// const hashBuffer = await crypto.subtle.digest('SHA-256', data as Uint8Array)\n\n// // Convert the ArrayBuffer to a hex string\n// const hashArray = Array.from(new Uint8Array(hashBuffer))\n// return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('')\n// }\n\nexport const isBinary = (arrayBuffer: ArrayBuffer): boolean => {\n const view = new Uint8Array(arrayBuffer);\n\n let nonTextCount = 0;\n const threshold = 0.2; // Adjust as needed (e.g., 20% non-text implies binary)\n\n for (let i = 0; i < view.length; i++) {\n const byte = view[i];\n\n // ASCII printable characters (32-126) and common whitespace (9, 10, 13)\n if (\n (byte >= 32 && byte <= 126) || // Printable ASCII\n byte === 9 || byte === 10 || byte === 13 // Tab, LF, CR\n ) {\n continue;\n }\n\n nonTextCount++;\n if (nonTextCount / view.length > threshold) {\n return true; // More than threshold are non-text bytes\n }\n }\n\n return false; // Fewer than threshold are non-text bytes\n}\n"],"names":[],"mappings":";;;;;;;;AAWA,MAAM,MAAM,GAAG,KAAK,CAAC,wBAAwB,CAAC;AAG9C,MAAM,EAAE,YAAY,EAAE,GAAG,gBAAgB;AAElC,MAAM,UAAU,GAAG,MAAa;AACrC,IAAA,OAAO,cAAc,CAAC,YAAY,EAAE,EAAE,CAAC,EAAE;AAC3C;AAEa,MAAA,WAAW,GAAG,CAAC,GAAW,KAAI;IACzC,OAAO,GAAG,CAAC,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC,WAAW,EAAE;AAC9D;AA+Ba,MAAA,WAAW,GAAG,CAAC,MAAc,KAAI;IAC5C,IAAI,CAAC,MAAM,EAAE;AACX,QAAA,OAAO,IAAI;;IAEb,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,0CAA0C,CAAC;IAEvE,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;AAC/B,QAAA,OAAO,MAAM,CAAC,CAAC,CAAC;;SACX;QACL,OAAO,IAAI,CAAA;;AAEf;AAEa,MAAA,YAAY,GAAiB,CAAC,YAAoB,KAAI;AACjE,IAAA,MAAM,EAAE,GAAuB;AAC7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AC,MAAM,CAAC;IAEnC,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;AAElC,IAAA,OAAO,GAAG,CAAC,eAAe,CAAC,SAAS,CAAC;AACvC;AAWa,MAAA,4BAA4B,GAAG,CAAC,eAAuB,KAAI;;AAEtE,IAAA,MAAM,CAAC,gBAAgB,EAAE,SAAS,EAAE,SAAS,CAAC,GAAG,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC;;AAG3E,IAAA,MAAM,MAAM,GAAG,SAAS,KAAK,KAAK;;AAGlC,IAAA,MAAM,YAAY,GAAG,gBAAgB,CAAC,QAAQ,CAAC,GAAG;AAChD,UAAE;AACF,UAAE,gBAAgB,GAAG,GAAG;IAE1B,OAAO;AACL,QAAA,YAAY;AACZ,QAAA,SAAS;AACT,QAAA,MAAM;KACP;AACH;MAEa,cAAc,GAAG,OAC5B,IAAa,KACM;AACnB,IAAA,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/helpers/index.ts"],"sourcesContent":["import { customAlphabet } from 'nanoid'\nimport * as nanoIdDictionary from 'nanoid-dictionary'\nimport debug from 'debug'\nimport { GetCorrectId } from '@/types/helpers'\nimport { GetCorrectIdReturn } from '@/types/helpers'\nimport { BaseFileManager } from './FileManager/BaseFileManager'\nexport * from './ArweaveClient/BaseArweaveClient'\nexport * from './EasClient/BaseEasClient'\nexport * from './QueryClient/BaseQueryClient'\nexport * from './FileManager/BaseFileManager'\nconst logger = debug('seedSdk:shared:helpers')\n\n\nconst { alphanumeric } = nanoIdDictionary\n\nexport const generateId = (): string => {\n return customAlphabet(alphanumeric, 10)()\n}\n\nexport const toSnakeCase = (str: string) => {\n return str.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase()\n}\n\nexport const identifyString = (str: string) => {\n try {\n JSON.parse(str)\n return 'json'\n } catch (e) {\n // Not JSON\n }\n\n if (!str) {\n return\n }\n\n if (str.trim().startsWith('<') && str.trim().endsWith('>')) {\n return 'html'\n }\n\n // Simple markdown checks (very naive)\n if (/^#{1,6}\\s|^-{3,}|\\*{3,}|^-{1,2}\\s|\\*\\s/.test(str)) {\n return 'markdown'\n }\n\n if (/^data:image\\/[a-zA-Z]+;base64,[A-Za-z0-9+/]+={0,2}$/.test(str)) {\n return 'base64'\n }\n\n // Default to plain text if unsure\n return 'text'\n}\n\nexport const getMimeType = (base64: string) => {\n if (!base64) {\n return null\n }\n const result = base64.match(/^data:([a-zA-Z0-9]+\\/[a-zA-Z0-9-.+]+).*,/)\n\n if (result && result.length > 1) {\n return result[1]\n } else {\n return null // MIME type could not be determined\n }\n}\n\nexport const getCorrectId: GetCorrectId = (localIdOrUid: string) => {\n const id: GetCorrectIdReturn = {\n localId: undefined,\n uid: undefined,\n }\n if (!localIdOrUid) {\n return id\n }\n if (localIdOrUid.length === 10) {\n id.localId = localIdOrUid\n }\n if (localIdOrUid.startsWith('0x') && localIdOrUid.length === 66) {\n id.uid = localIdOrUid\n }\n return id\n}\n\nexport const getDataTypeFromString = (\n data: string,\n): 'imageBase64' | 'base64' | 'url' | null => {\n const nonImageBase64Regex =\n /^(?!data:image\\/(?:jpeg|png|gif|bmp|webp);base64,)[A-Za-z0-9+/=]+$/\n\n if (nonImageBase64Regex.test(data)) {\n return 'base64'\n }\n\n // Regular expression for base64 (simple version, checking for base64 format)\n const imageBase64Regex = /^data:image\\/[a-zA-Z]+;base64,[A-Za-z0-9+/]+={0,2}$/\n\n if (imageBase64Regex.test(data)) {\n return 'imageBase64'\n }\n\n // Regular expression for URL (simple version, checking for common URL format)\n const urlRegex =\n /^(http:\\/\\/www\\.|https:\\/\\/www\\.|http:\\/\\/|https:\\/\\/)?[a-z0-9]+([\\-\\.]{1}[a-z0-9]+)*\\.[a-z]{2,5}(:[0-9]{1,5})?(\\/.*)?$/\n\n if (urlRegex.test(data)) {\n return 'url'\n }\n\n return null\n}\n\nexport const convertTxIdToImage = async (\n txId: string,\n): Promise<string | undefined> => {\n const imageFilePath = `/files/images/${txId}`\n const fileExists = await BaseFileManager.pathExists(imageFilePath)\n if (!fileExists) {\n logger(`[ItemView] [updateImage] ${imageFilePath} does not exist`)\n return\n }\n const buffer = await BaseFileManager.readFileAsBuffer(imageFilePath)\n\n const uint = new Uint8Array(buffer)\n\n const imageBlob = new Blob([uint])\n\n return URL.createObjectURL(imageBlob)\n}\n\nexport const getExecutionTime = async (task, args) => {\n const start = Date.now()\n await task(...args)\n return Date.now() - start\n}\n\nexport const capitalizeFirstLetter = (string: string) =>\n string.charAt(0).toUpperCase() + string.slice(1)\n\nexport const parseEasRelationPropertyName = (easPropertyName: string) => {\n // Split the input string on the first underscore\n const [singularProperty, modelName, idSegment] = easPropertyName.split('_')\n\n // If there are any other parts, assume it is a list (e.g., has 'ids' or other suffix)\n const isList = idSegment === 'ids'\n\n // Create the final property name by pluralizing the singular part\n const propertyName = singularProperty.endsWith('s')\n ? singularProperty\n : singularProperty + 's'\n\n return {\n propertyName, // Plural form of the property name\n modelName, // Model name extracted from the second part\n isList, // True if the property is a list (e.g., 'ids' is present)\n }\n}\n\n\nexport const isBinary = (arrayBuffer: ArrayBuffer): boolean => {\n const view = new Uint8Array(arrayBuffer);\n\n let nonTextCount = 0;\n const threshold = 0.2; // Adjust as needed (e.g., 20% non-text implies binary)\n\n for (let i = 0; i < view.length; i++) {\n const byte = view[i];\n\n // ASCII printable characters (32-126) and common whitespace (9, 10, 13)\n if (\n (byte >= 32 && byte <= 126) || // Printable ASCII\n byte === 9 || byte === 10 || byte === 13 // Tab, LF, CR\n ) {\n continue;\n }\n\n nonTextCount++;\n if (nonTextCount / view.length > threshold) {\n return true; // More than threshold are non-text bytes\n }\n }\n\n return false; // Fewer than threshold are non-text bytes\n}\n"],"names":[],"mappings":";;;;;;;AAUA,MAAM,MAAM,GAAG,KAAK,CAAC,wBAAwB,CAAC;AAG9C,MAAM,EAAE,YAAY,EAAE,GAAG,gBAAgB;AAElC,MAAM,UAAU,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
4
4
  "description": "The SDK for Seed Protocol",
5
5
  "type": "module",
6
6
  "engines": {