diff --git a/nodsoft_moltenobsidian_ssg_client/manifest-client.ts b/nodsoft_moltenobsidian_ssg_client/manifest-client.ts new file mode 100644 index 0000000..bf65884 --- /dev/null +++ b/nodsoft_moltenobsidian_ssg_client/manifest-client.ts @@ -0,0 +1,38 @@ +import {VaultFile, VaultManifest} from 'vault-manifest' + +/** + * Represents a client for resolving a MoltenObsidian vault's assets from its manifest. + * @class + * @public + */ +export class VaultManifestClient { + public static fromManifest(manifest: VaultManifest): VaultManifestClient { + return new VaultManifestClient(manifest); + } + + public static async fromPath(path: string | URL): Promise { + // Check if the path is a string + if (typeof path === 'string') { + // Check if the path is an absolute URL + if (path.startsWith('http://') || path.startsWith('https://')) { + path = new URL(path); + } else { + // Assume the path is a relative path, from base URL (defined in tag) + path = new URL(path, document.baseURI ?? window.location.href); + } + } + + // Fetch the manifest from the URL + const response = await fetch(path.toString()); + if (!response.ok) { + throw new Error(`Failed to fetch manifest from ${path.toString()}: ${response.statusText}`); + } + + const manifest = await response.json() as VaultManifest; + return VaultManifestClient.fromManifest(manifest); + } + + protected constructor( + public readonly Manifest: VaultManifest + ) { } +} \ No newline at end of file diff --git a/nodsoft_moltenobsidian_ssg_client/package.json b/nodsoft_moltenobsidian_ssg_client/package.json index 24e65a3..41d555f 100644 --- a/nodsoft_moltenobsidian_ssg_client/package.json +++ b/nodsoft_moltenobsidian_ssg_client/package.json @@ -1,5 +1,17 @@ { + "name": "moltenobsidian-ssg-client", + "author": "Nodsoft Systems", + "description": "SSG Client for MoltenObsidian vaults", + "license": "ISC", + "scripts": { + "build": "tsc" + }, + "devDependencies": { "typescript": "^5.1.6" + }, + + "dependencies": { + "@types/mime-types": "^2.1.1" } } diff --git a/nodsoft_moltenobsidian_ssg_client/pnpm-lock.yaml b/nodsoft_moltenobsidian_ssg_client/pnpm-lock.yaml index acc2406..046a07b 100644 --- a/nodsoft_moltenobsidian_ssg_client/pnpm-lock.yaml +++ b/nodsoft_moltenobsidian_ssg_client/pnpm-lock.yaml @@ -4,6 +4,11 @@ settings: autoInstallPeers: true excludeLinksFromLockfile: false +dependencies: + '@types/mime-types': + specifier: ^2.1.1 + version: 2.1.1 + devDependencies: typescript: specifier: ^5.1.6 @@ -11,6 +16,10 @@ devDependencies: packages: + /@types/mime-types@2.1.1: + resolution: {integrity: sha512-vXOTGVSLR2jMw440moWTC7H19iUyLtP3Z1YTj7cSsubOICinjMxFeb/V57v9QdyyPGbbWolUFSSmSiRSn94tFw==} + dev: false + /typescript@5.1.6: resolution: {integrity: sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==} engines: {node: '>=14.17'} diff --git a/nodsoft_moltenobsidian_ssg_client/tsconfig.json b/nodsoft_moltenobsidian_ssg_client/tsconfig.json index e075f97..5401611 100644 --- a/nodsoft_moltenobsidian_ssg_client/tsconfig.json +++ b/nodsoft_moltenobsidian_ssg_client/tsconfig.json @@ -28,7 +28,7 @@ "module": "commonjs", /* Specify what module code is generated. */ // "rootDir": "./", /* Specify the root folder within your source files. */ // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ - // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + "baseUrl": ".", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ diff --git a/nodsoft_moltenobsidian_ssg_client/vault-manifest.ts b/nodsoft_moltenobsidian_ssg_client/vault-manifest.ts new file mode 100644 index 0000000..50591eb --- /dev/null +++ b/nodsoft_moltenobsidian_ssg_client/vault-manifest.ts @@ -0,0 +1,50 @@ +/** + * Represents a manifest for a MoltenObsidian vault. + * @interface + */ +export interface VaultManifest { + /** + * The name of the vault. + * @type {string} + */ + name: string; + + /** + * List of files in the vault. + * @type {VaultFile[]} + */ + files: VaultFile[]; +} + +/** + * Represents a file in a MoltenObsidian vault manifest + * @interface + */ +export interface VaultFile { + /** + * The path of the file. + * @type {string} + * @example "README.md" + * @example "super/secret/file.md" + */ + path: string; + + /** + * The size of the file in bytes. + * @type {number} + */ + size: number; + + /** + * The hash of the file. + * @type {string} + */ + hash: string | null; + + /** + * The content type of the file, as a MIME type. + * @type {string} + * @example "text/markdown" + */ + contentType: string | null; +}