@seedprotocol/sdk 0.3.10 → 0.3.11
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAGjC,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;AAO7C,eAAO,MAAM,UAAU,QAAO,MAE7B,CAAA;AAED,eAAO,MAAM,WAAW,QAAS,MAAM,WAEtC,CAAA;AAED,eAAO,MAAM,cAAc,QAAS,MAAM,iEA2BzC,CAAA;AAED,eAAO,MAAM,WAAW,WAAY,MAAM,kBAWzC,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,YAe1B,CAAA;AAED,eAAO,MAAM,qBAAqB,SAC1B,MAAM,KACX,aAAa,GAAG,QAAQ,GAAG,KAAK,GAAG,IAwBrC,CAAA;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;AAED,eAAO,MAAM,cAAc,SACnB,OAAO,KACZ,OAAO,CAAC,MAAM,CAEhB,CAAA;AAyBD,eAAO,MAAM,QAAQ,gBAAiB,WAAW,KAAG,OAwBnD,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { customAlphabet } from 'nanoid';
|
|
2
|
-
import
|
|
2
|
+
import * as sha3 from 'js-sha3';
|
|
3
3
|
import * as nanoIdDictionary from 'nanoid-dictionary';
|
|
4
4
|
import debug from 'debug';
|
|
5
5
|
import { BaseFileManager } from './FileManager/BaseFileManager.js';
|
|
@@ -7,6 +7,7 @@ import 'graphql-request';
|
|
|
7
7
|
import '../services/internal/constants.js';
|
|
8
8
|
|
|
9
9
|
const logger = debug('seedSdk:shared:helpers');
|
|
10
|
+
const { sha3_256, } = sha3;
|
|
10
11
|
const { alphanumeric } = nanoIdDictionary;
|
|
11
12
|
const generateId = () => {
|
|
12
13
|
return customAlphabet(alphanumeric, 10)();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/helpers/index.ts"],"sourcesContent":["import { customAlphabet } from 'nanoid'\nimport { Message
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/helpers/index.ts"],"sourcesContent":["import { customAlphabet } from 'nanoid'\nimport * as sha3 from 'js-sha3'\nimport { Message } 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\nconst { sha3_256, } = sha3\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":";;;;;;;;AAYA,MAAM,MAAM,GAAG,KAAK,CAAC,wBAAwB,CAAC;AAE9C,MAAM,EAAE,QAAQ,GAAG,GAAG,IAAI;AAE1B,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;AAC7B,QAAA,OAAO,EAAE,SAAS;AAClB,QAAA,GAAG,EAAE,SAAS;KACf;IACD,IAAI,CAAC,YAAY,EAAE;AACjB,QAAA,OAAO,EAAE;;AAEX,IAAA,IAAI,YAAY,CAAC,MAAM,KAAK,EAAE,EAAE;AAC9B,QAAA,EAAE,CAAC,OAAO,GAAG,Y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