diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..205df23 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "git.enabled": false +} \ No newline at end of file diff --git a/data/blob.ts b/data/blob.ts deleted file mode 100644 index 62c0d48..0000000 --- a/data/blob.ts +++ /dev/null @@ -1,99 +0,0 @@ -import { CID, RAW_BIN_MULTICODEC, SHA2_256_MULTIHASH_CODE } from "./cid.ts"; -import { isPlainObject } from "./object.ts"; - -export type BlobRef = { - $type: "blob"; - mimeType: string; - ref: CID; - size: number; -}; - -export function isBlobRef( - input: unknown, - options?: { strict?: boolean }, -): input is BlobRef { - if (!isPlainObject(input)) { - return false; - } - - if (input?.$type !== "blob") { - return false; - } - - const { mimeType, size, ref } = input; - if (typeof mimeType !== "string") { - return false; - } - - if (typeof size !== "number" || size < 0 || !Number.isInteger(size)) { - return false; - } - - if (typeof ref !== "object" || ref === null) { - return false; - } - - for (const key in input) { - if ( - key !== "$type" && - key !== "mimeType" && - key !== "ref" && - key !== "size" - ) { - return false; - } - } - - const cid = CID.asCID(ref); - if (!cid) { - return false; - } - - if (options?.strict) { - if (cid.version !== 1) { - return false; - } - if (cid.code !== RAW_BIN_MULTICODEC) { - return false; - } - if (cid.multihash.code !== SHA2_256_MULTIHASH_CODE) { - return false; - } - } - - return true; -} - -export type LegacyBlobRef = { - cid: string; - mimeType: string; -}; - -export function isLegacyBlobRef(input: unknown): input is LegacyBlobRef { - if (!isPlainObject(input)) { - return false; - } - - const { cid, mimeType } = input; - if (typeof cid !== "string") { - return false; - } - - if (typeof mimeType !== "string") { - return false; - } - - for (const key in input) { - if (key !== "cid" && key !== "mimeType") { - return false; - } - } - - try { - CID.parse(cid); - } catch { - return false; - } - - return true; -} diff --git a/data/cid.ts b/data/cid.ts deleted file mode 100644 index 5f7430c..0000000 --- a/data/cid.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { CID } from "multiformats/cid"; - -export const DAG_CBOR_MULTICODEC = 0x71; -export const RAW_BIN_MULTICODEC = 0x55; - -export const SHA2_256_MULTIHASH_CODE = 0x12; - -export { CID }; - -export function isCid( - value: unknown, - options?: { strict?: boolean }, -): value is CID { - const cid = CID.asCID(value); - if (!cid) { - return false; - } - - if (options?.strict) { - if (cid.version !== 1) { - return false; - } - if (cid.code !== RAW_BIN_MULTICODEC && cid.code !== DAG_CBOR_MULTICODEC) { - return false; - } - if (cid.multihash.code !== SHA2_256_MULTIHASH_CODE) { - return false; - } - } - - return true; -} - -export function validateCidString(input: string): boolean { - return parseCidString(input)?.toString() === input; -} - -export function parseCidString(input: string): CID | undefined { - try { - return CID.parse(input); - } catch { - return undefined; - } -} - -export function ensureValidCidString(input: string): void { - if (!validateCidString(input)) { - throw new Error(`Invalid CID string`); - } -} diff --git a/data/deno.json b/data/deno.json deleted file mode 100644 index a81eedd..0000000 --- a/data/deno.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "@atp/data", - "version": "0.1.0-alpha.1", - "exports": "./mod.ts", - "license": "MIT", - "imports": { - "multiformats": "npm:multiformats@^13.4.1" - } -} diff --git a/data/language.ts b/data/language.ts deleted file mode 100644 index ef33d31..0000000 --- a/data/language.ts +++ /dev/null @@ -1,40 +0,0 @@ -const BCP47_REGEXP = - /^((?(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang))|((?([A-Za-z]{2,3}(-(?[A-Za-z]{3}(-[A-Za-z]{3}){0,2}))?)|[A-Za-z]{4}|[A-Za-z]{5,8})(-(?