Vault
Class: Vault
Section titled “Class: Vault”Defined in: storage/vault.svelte.ts:38
High-level file-system facade for the active vault.
Vault wraps a DataAdapter, maintains the in-memory file tree used by
the workspace, and emits Obsidian-style file lifecycle events.
Extends
Section titled “Extends”EventDispatcher<{all: [string,TAbstractFile,Record<string,unknown>];create: [TAbstractFile];delete: [TAbstractFile];load: [];modify: [TAbstractFile];rename: [TAbstractFile,string]; }>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Vault(
adapter):Vault
Defined in: storage/vault.svelte.ts:50
Parameters
Section titled “Parameters”adapter
Section titled “adapter”Returns
Section titled “Returns”Vault
Overrides
Section titled “Overrides”Properties
Section titled “Properties”adapter
Section titled “adapter”
readonlyadapter:DataAdapter
Defined in: storage/vault.svelte.ts:50
readonlycache:FileCache
Defined in: storage/vault.svelte.ts:48
configDir
Section titled “configDir”configDir:
string=".obsidian"
Defined in: storage/vault.svelte.ts:47
Methods
Section titled “Methods”append()
Section titled “append()”append(
file,data,options?):Promise<void>
Defined in: storage/vault.svelte.ts:494
Parameters
Section titled “Parameters”string
options?
Section titled “options?”Partial<FileProperties>
Returns
Section titled “Returns”Promise<void>
appendBinary()
Section titled “appendBinary()”appendBinary(
file,data,options?):Promise<void>
Defined in: storage/vault.svelte.ts:511
Parameters
Section titled “Parameters”ArrayBuffer
options?
Section titled “options?”Partial<FileProperties>
Returns
Section titled “Returns”Promise<void>
cachedRead()
Section titled “cachedRead()”cachedRead(
file):Promise<string>
Defined in: storage/vault.svelte.ts:348
Read the content of a plaintext file stored inside the vault Use this if you only want to display the content to the user. If you want to modify the file content afterward use Vault.read
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<string>
copy()
Section titled “copy()”copy<
T>(file,newPath):Promise<T>
Defined in: storage/vault.svelte.ts:532
Type Parameters
Section titled “Type Parameters”T extends TAbstractFile
Parameters
Section titled “Parameters”T
newPath
Section titled “newPath”string
Returns
Section titled “Returns”Promise<T>
create()
Section titled “create()”create(
path,data,options?):Promise<TFile>
Defined in: storage/vault.svelte.ts:151
Create a new plaintext file inside the vault.
Parameters
Section titled “Parameters”string
Vault absolute path for the new file, with extension.
string
Text content for the new file.
options?
Section titled “options?”Partial<FileProperties>
(Optional)
Returns
Section titled “Returns”Promise<TFile>
createBinary()
Section titled “createBinary()”createBinary(
path,data,options?):Promise<TFile>
Defined in: storage/vault.svelte.ts:188
Create a new binary file inside the vault.
Parameters
Section titled “Parameters”string
Vault absolute path for the new file, with extension.
ArrayBuffer
Content for the new file.
options?
Section titled “options?”Partial<FileProperties>
(Optional)
Returns
Section titled “Returns”Promise<TFile>
Throws
Section titled “Throws”Error if file already exists
createFolder()
Section titled “createFolder()”createFolder(
path):Promise<TFolder>
Defined in: storage/vault.svelte.ts:218
Create a new folder inside the vault.
Parameters
Section titled “Parameters”string
Vault absolute path for the new folder.
Returns
Section titled “Returns”Promise<TFolder>
Throws
Section titled “Throws”Error if folder already exists
delete()
Section titled “delete()”delete(
file,force?):Promise<void>
Defined in: storage/vault.svelte.ts:285
Deletes the file completely.
Parameters
Section titled “Parameters”The file or folder to be deleted
force?
Section titled “force?”boolean
Should attempt to delete folder even if it has hidden children
Returns
Section titled “Returns”Promise<void>
dispatch()
Section titled “dispatch()”dispatch<
T>(eventName, …args):boolean
Defined in: events.ts:105
Type Parameters
Section titled “Type Parameters”T extends "load" | "create" | "modify" | "delete" | "rename" | "all"
Parameters
Section titled “Parameters”eventName
Section titled “eventName”T
…ArgumentMap<{ all: [string, TAbstractFile, Record<string, unknown>]; create: [TAbstractFile]; delete: [TAbstractFile]; load: []; modify: [TAbstractFile]; rename: [TAbstractFile, string]; }>[Extract<T, "load" | "create" | "modify" | "delete" | "rename" | "all">]
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”emit()
Section titled “emit()”emit<
T>(eventName, …args):boolean
Defined in: events.ts:98
Type Parameters
Section titled “Type Parameters”T extends "load" | "create" | "modify" | "delete" | "rename" | "all"
Parameters
Section titled “Parameters”eventName
Section titled “eventName”T
…ArgumentMap<{ all: [string, TAbstractFile, Record<string, unknown>]; create: [TAbstractFile]; delete: [TAbstractFile]; load: []; modify: [TAbstractFile]; rename: [TAbstractFile, string]; }>[Extract<T, "load" | "create" | "modify" | "delete" | "rename" | "all">]
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”exists()
Section titled “exists()”exists(
path,sensitive?):Promise<boolean>
Defined in: storage/vault.svelte.ts:66
Parameters
Section titled “Parameters”string
sensitive?
Section titled “sensitive?”boolean
Returns
Section titled “Returns”Promise<boolean>
getAbstractFileByPath()
Section titled “getAbstractFileByPath()”getAbstractFileByPath(
path):TAbstractFile|null
Defined in: storage/vault.svelte.ts:587
Get a file or folder inside the vault at the given path. To check if the
return type is a file, use instanceof TFile. To check if it is a folder,
use instanceof TFolder.
Parameters
Section titled “Parameters”string
Vault absolute path to the folder or file, with extension, case sensitive.
Returns
Section titled “Returns”TAbstractFile | null
The abstract file, if it’s found.
getAllFolders()
Section titled “getAllFolders()”getAllFolders(
includeRoot?):TFolder[]
Defined in: storage/vault.svelte.ts:628
Get all folders in the vault.
Parameters
Section titled “Parameters”includeRoot?
Section titled “includeRoot?”boolean
Should the root folder (/) be returned
Returns
Section titled “Returns”TFolder[]
getAllLoadedFiles()
Section titled “getAllLoadedFiles()”getAllLoadedFiles():
TAbstractFile[]
Defined in: storage/vault.svelte.ts:618
Returns
Section titled “Returns”getFileByPath()
Section titled “getFileByPath()”getFileByPath(
path):TFile|null
Defined in: storage/vault.svelte.ts:552
Get a file inside the vault at the given path. Returns null if the file
does not exist.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”TFile | null
getFiles()
Section titled “getFiles()”getFiles():
TFile[]
Defined in: storage/vault.svelte.ts:639
Get all files in the vault.
Returns
Section titled “Returns”TFile[]
getFolderByPath()
Section titled “getFolderByPath()”getFolderByPath(
path):TFolder|null
Defined in: storage/vault.svelte.ts:568
Get a folder inside the vault at the given path. Returns null if the
folder does not exist.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”TFolder | null
getMarkdownFiles()
Section titled “getMarkdownFiles()”getMarkdownFiles():
TFile[]
Defined in: storage/vault.svelte.ts:643
Returns
Section titled “Returns”TFile[]
getName()
Section titled “getName()”getName():
string
Defined in: storage/vault.svelte.ts:62
Returns
Section titled “Returns”string
getResourcePath()
Section titled “getResourcePath()”getResourcePath(
file):string
Defined in: storage/vault.svelte.ts:601
Parameters
Section titled “Parameters”Returns
Section titled “Returns”string
getResourceUrl()
Section titled “getResourceUrl()”getResourceUrl(
file):Promise<string>
Defined in: storage/vault.svelte.ts:605
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<string>
getRoot()
Section titled “getRoot()”getRoot():
TFolder
Defined in: storage/vault.svelte.ts:597
Get the root folder of the current vault.
Returns
Section titled “Returns”list()
Section titled “list()”list(
path?):Promise<ListedFiles>
Defined in: storage/vault.svelte.ts:74
Parameters
Section titled “Parameters”string = "/"
Returns
Section titled “Returns”Promise<ListedFiles>
load()
Section titled “load()”load():
Promise<void>
Defined in: storage/vault.svelte.ts:79
Returns
Section titled “Returns”Promise<void>
loadPath()
Section titled “loadPath()”loadPath(
basePath?,sourceFiles?):Promise<Record<string,TAbstractFile>>
Defined in: storage/vault.svelte.ts:96
Parameters
Section titled “Parameters”basePath?
Section titled “basePath?”string = "/"
sourceFiles?
Section titled “sourceFiles?”Record<string, TAbstractFile> = ...
Returns
Section titled “Returns”Promise<Record<string, TAbstractFile>>
mkpath()
Section titled “mkpath()”mkpath(
path):Promise<TFolder>
Defined in: storage/vault.svelte.ts:249
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<TFolder>
modify()
Section titled “modify()”modify(
file,data,options?):Promise<void>
Defined in: storage/vault.svelte.ts:409
Modify the contents of a plaintext file.
Parameters
Section titled “Parameters”The file
string
The new file content
options?
Section titled “options?”Partial<FileProperties>
(Optional)
Returns
Section titled “Returns”Promise<void>
modifyBinary()
Section titled “modifyBinary()”modifyBinary(
file,data,options?):Promise<void>
Defined in: storage/vault.svelte.ts:440
Modify the contents of a binary file.
Parameters
Section titled “Parameters”The file
ArrayBuffer
The new file content
options?
Section titled “options?”Partial<FileProperties>
(Optional)
Returns
Section titled “Returns”Promise<void>
off<
T>(eventName,listener,context?,once?):void
Defined in: events.ts:78
Type Parameters
Section titled “Type Parameters”T extends "load" | "create" | "modify" | "delete" | "rename" | "all"
Parameters
Section titled “Parameters”eventName
Section titled “eventName”T
listener
Section titled “listener”(…args) => void
context?
Section titled “context?”any
boolean
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”offref()
Section titled “offref()”offref<
T>(ref):void
Defined in: events.ts:87
Type Parameters
Section titled “Type Parameters”T extends "load" | "create" | "modify" | "delete" | "rename" | "all"
Parameters
Section titled “Parameters”EventRef<{ all: [string, TAbstractFile, Record<string, unknown>]; create: [TAbstractFile]; delete: [TAbstractFile]; load: []; modify: [TAbstractFile]; rename: [TAbstractFile, string]; }, T>
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”on<
T>(eventName,listener,context?):EventRef<{all: [string,TAbstractFile,Record<string,unknown>];create: [TAbstractFile];delete: [TAbstractFile];load: [];modify: [TAbstractFile];rename: [TAbstractFile,string]; },T,any>
Defined in: events.ts:48
Type Parameters
Section titled “Type Parameters”T extends "load" | "create" | "modify" | "delete" | "rename" | "all"
Parameters
Section titled “Parameters”eventName
Section titled “eventName”T
listener
Section titled “listener”(…args) => void
context?
Section titled “context?”any
Returns
Section titled “Returns”EventRef<{ all: [string, TAbstractFile, Record<string, unknown>]; create: [TAbstractFile]; delete: [TAbstractFile]; load: []; modify: [TAbstractFile]; rename: [TAbstractFile, string]; }, T, any>
Inherited from
Section titled “Inherited from”once()
Section titled “once()”once<
T>(eventName,listener,context?):EventRef<{all: [string,TAbstractFile,Record<string,unknown>];create: [TAbstractFile];delete: [TAbstractFile];load: [];modify: [TAbstractFile];rename: [TAbstractFile,string]; },T,any>
Defined in: events.ts:63
Type Parameters
Section titled “Type Parameters”T extends "load" | "create" | "modify" | "delete" | "rename" | "all"
Parameters
Section titled “Parameters”eventName
Section titled “eventName”T
listener
Section titled “listener”(…args) => void
context?
Section titled “context?”any
Returns
Section titled “Returns”EventRef<{ all: [string, TAbstractFile, Record<string, unknown>]; create: [TAbstractFile]; delete: [TAbstractFile]; load: []; modify: [TAbstractFile]; rename: [TAbstractFile, string]; }, T, any>
Inherited from
Section titled “Inherited from”process()
Section titled “process()”process(
file,fn,options?):Promise<string>
Defined in: storage/vault.svelte.ts:481
Atomically read, modify, and save the contents of a note.
Parameters
Section titled “Parameters”The file to be read and modified.
(data) => string
A callback function which returns the new content of the note synchronously.
options?
Section titled “options?”Partial<FileProperties>
Write options.
Returns
Section titled “Returns”Promise<string>
String - the text value of the note that was written.
Example
Section titled “Example” app.vault.process(file, (data) => { return data.replace('Hello', 'World'); }); ```;
***
### read()
> **read**(`file`): `Promise`\<`string`\>
Defined in: [storage/vault.svelte.ts:334](https://code.ju.ma/lapis-notes/lapis/src/branch/main/packages/api/src/lib/storage/vault.svelte.ts#L334)
Read a plaintext file that is stored inside the vault, directly from disk.Use this if you intend to modify the file content afterwards. Use[Vault.cachedRead](#cachedread) otherwise for better performance.
#### Parameters
##### file
[`TFile`](TFile.md)
#### Returns
`Promise`\<`string`\>
***
### readBinary()
> **readBinary**(`file`): `Promise`\<`ArrayBuffer`\>
Defined in: [storage/vault.svelte.ts:360](https://code.ju.ma/lapis-notes/lapis/src/branch/main/packages/api/src/lib/storage/vault.svelte.ts#L360)
Read the content of a binary file stored inside the vault.
#### Parameters
##### file
[`TFile`](TFile.md)
#### Returns
`Promise`\<`ArrayBuffer`\>
***
### reload()
> **reload**(): `Promise`\<[`TFolder`](TFolder.md)\>
Defined in: [storage/vault.svelte.ts:87](https://code.ju.ma/lapis-notes/lapis/src/branch/main/packages/api/src/lib/storage/vault.svelte.ts#L87)
#### Returns
`Promise`\<[`TFolder`](TFolder.md)\>
***
### rename()
> **rename**(`file`, `newPath`): `Promise`\<`void`\>
Defined in: [storage/vault.svelte.ts:372](https://code.ju.ma/lapis-notes/lapis/src/branch/main/packages/api/src/lib/storage/vault.svelte.ts#L372)
Rename or move a file. To ensure links are automatically renamed, use[FileManager.renameFile](FileManager.md#renamefile) instead.
#### Parameters
##### file
[`TAbstractFile`](TAbstractFile.md)
The file to rename/move
##### newPath
`string`
Vault absolute path to move file to.
#### Returns
`Promise`\<`void`\>
***
### revokeResourceUrl()
> **revokeResourceUrl**(`url`): `void`
Defined in: [storage/vault.svelte.ts:613](https://code.ju.ma/lapis-notes/lapis/src/branch/main/packages/api/src/lib/storage/vault.svelte.ts#L613)
#### Parameters
##### url
`string`
#### Returns
`void`
***
### stat()
> **stat**(`path`): `Promise`\<`Stat` \| `null`\>
Defined in: [storage/vault.svelte.ts:70](https://code.ju.ma/lapis-notes/lapis/src/branch/main/packages/api/src/lib/storage/vault.svelte.ts#L70)
#### Parameters
##### path
`string`
#### Returns
`Promise`\<`Stat` \| `null`\>
***
### trash()
> **trash**(`file`, `system?`): `Promise`\<`void`\>
Defined in: [storage/vault.svelte.ts:311](https://code.ju.ma/lapis-notes/lapis/src/branch/main/packages/api/src/lib/storage/vault.svelte.ts#L311)
#### Parameters
##### file
[`TAbstractFile`](TAbstractFile.md)
##### system?
`boolean` = `true`
#### Returns
`Promise`\<`void`\>
***
### trigger()
> **trigger**\<`T`\>(`eventName`, ...`args`): `boolean`
Defined in: [events.ts:91](https://code.ju.ma/lapis-notes/lapis/src/branch/main/packages/api/src/lib/events.ts#L91)
#### Type Parameters
##### T
`T` *extends* `"load"` \| `"create"` \| `"modify"` \| `"delete"` \| `"rename"` \| `"all"`
#### Parameters
##### eventName
`T`
##### args
...`ArgumentMap`\<\{ `all`: \[`string`, [`TAbstractFile`](TAbstractFile.md), `Record`\<`string`, `unknown`\>\]; `create`: \[[`TAbstractFile`](TAbstractFile.md)\]; `delete`: \[[`TAbstractFile`](TAbstractFile.md)\]; `load`: \[\]; `modify`: \[[`TAbstractFile`](TAbstractFile.md)\]; `rename`: \[[`TAbstractFile`](TAbstractFile.md), `string`\]; \}\>\[`Extract`\<`T`, `"load"` \| `"create"` \| `"modify"` \| `"delete"` \| `"rename"` \| `"all"`\>\]
#### Returns
`boolean`
#### Inherited from
[`EventDispatcher`](EventDispatcher.md).[`trigger`](EventDispatcher.md#trigger)
***
### tryTrigger()
> **tryTrigger**\<`T`\>(`evt`, ...`args`): `void`
Defined in: [events.ts:112](https://code.ju.ma/lapis-notes/lapis/src/branch/main/packages/api/src/lib/events.ts#L112)
#### Type Parameters
##### T
`T` *extends* `"load"` \| `"create"` \| `"modify"` \| `"delete"` \| `"rename"` \| `"all"`
#### Parameters
##### evt
`EventRef`\<\{ `all`: \[`string`, [`TAbstractFile`](TAbstractFile.md), `Record`\<`string`, `unknown`\>\]; `create`: \[[`TAbstractFile`](TAbstractFile.md)\]; `delete`: \[[`TAbstractFile`](TAbstractFile.md)\]; `load`: \[\]; `modify`: \[[`TAbstractFile`](TAbstractFile.md)\]; `rename`: \[[`TAbstractFile`](TAbstractFile.md), `string`\]; \}, `T`\>
##### args
...`ArgumentMap`\<\{ `all`: \[`string`, [`TAbstractFile`](TAbstractFile.md), `Record`\<`string`, `unknown`\>\]; `create`: \[[`TAbstractFile`](TAbstractFile.md)\]; `delete`: \[[`TAbstractFile`](TAbstractFile.md)\]; `load`: \[\]; `modify`: \[[`TAbstractFile`](TAbstractFile.md)\]; `rename`: \[[`TAbstractFile`](TAbstractFile.md), `string`\]; \}\>\[`Extract`\<`T`, `"load"` \| `"create"` \| `"modify"` \| `"delete"` \| `"rename"` \| `"all"`\>\]
#### Returns
`void`
#### Inherited from
[`EventDispatcher`](EventDispatcher.md).[`tryTrigger`](EventDispatcher.md#trytrigger)
***
### recurseChildren()
> `static` **recurseChildren**(`root`, `cb`): `void`
Defined in: [storage/vault.svelte.ts:649](https://code.ju.ma/lapis-notes/lapis/src/branch/main/packages/api/src/lib/storage/vault.svelte.ts#L649)
#### Parameters
##### root
[`TFolder`](TFolder.md)
##### cb
(`file`) => `any`
#### Returns
`void`