Class: Contents#
@jupyterlite/contents.Contents
A class to handle requests to /api/contents
Implements#
Constructors#
constructor#
new Contents(options)
Construct a new localForage-powered contents provider
Parameters#
Name |
Type |
|---|---|
|
Defined in#
Properties#
_checkpoints#
Private_checkpoints:undefined|LocalForage
Defined in#
_counters#
Private_counters:undefined|LocalForage
Defined in#
_localforage#
Private_localforage:LocalForage
Defined in#
_ready#
Private_ready:PromiseDelegate<void>
Defined in#
_serverContents#
Private_serverContents:Map<string,Map<string,IModel>>
Defined in#
_storage#
Private_storage:undefined|LocalForage
Defined in#
_storageDrivers#
Private_storageDrivers:null|string[] =null
Defined in#
_storageName#
Private_storageName:string=DEFAULT_STORAGE_NAME
Defined in#
Accessors#
checkpoints#
Protectedgetcheckpoints():Promise<LocalForage>
A lazy reference to the underlying checkpoints.
Returns#
Promise<LocalForage>
Defined in#
counters#
Protectedgetcounters():Promise<LocalForage>
A lazy reference to the underlying counters.
Returns#
Promise<LocalForage>
Defined in#
defaultStorageOptions#
ProtectedgetdefaultStorageOptions():LocalForageOptions
Get default options for localForage instances
Returns#
LocalForageOptions
Defined in#
ready#
getready():Promise<void>
A promise that resolves once all storage is fully initialized.
Returns#
Promise<void>
Implementation of#
IContents.ready
Defined in#
storage#
Protectedgetstorage():Promise<LocalForage>
A lazy reference to the underlying storage.
Returns#
Promise<LocalForage>
Defined in#
Methods#
_getFolder#
Private_getFolder(path):Promise<null|IModel>
retrieve the contents for this path from the union of local storage and
api/contents/{path}/all.json.
Parameters#
Name |
Type |
Description |
|---|---|---|
|
|
The contents path to retrieve |
Returns#
Promise<null | IModel>
A promise which resolves with a Map of contents, keyed by local file name
Defined in#
_getServerContents#
Private_getServerContents(path,options?):Promise<null|IModel>
Attempt to recover the model from {:path}/__all__.json file, fall back to deriving the
model (including content) off the file in /files/. Otherwise return null.
Parameters#
Name |
Type |
|---|---|
|
|
|
|
Returns#
Promise<null | IModel>
Defined in#
_getServerDirectory#
Private_getServerDirectory(path):Promise<Map<string,IModel>>
retrieve the contents for this path from __index__.json in the appropriate folder.
Parameters#
Name |
Type |
|---|---|
|
|
Returns#
Promise<Map<string, IModel>>
A promise which resolves with a Map of contents, keyed by local file name
Defined in#
_incrementCounter#
Private_incrementCounter(type):Promise<number>
Increment the counter for a given file type. Used to avoid collisions when creating new untitled files.
Parameters#
Name |
Type |
Description |
|---|---|---|
|
|
The file type to increment the counter for. |
Returns#
Promise<number>
Defined in#
copy#
copy(path,toDir):Promise<IModel>
Copy a file into a given directory.
Parameters#
Name |
Type |
Description |
|---|---|---|
|
|
The original file path. |
|
|
The destination directory path. |
Returns#
Promise<IModel>
A promise which resolves with the new contents model when the file is copied.
Notes#
The server will select the name of the copied file.
Implementation of#
IContents.copy
Defined in#
createCheckpoint#
createCheckpoint(path):Promise<ICheckpointModel>
Create a checkpoint for a file.
Parameters#
Name |
Type |
Description |
|---|---|---|
|
|
The path of the file. |
Returns#
Promise<ICheckpointModel>
A promise which resolves with the new checkpoint model when the checkpoint is created.
Implementation of#
IContents.createCheckpoint
Defined in#
createDefaultCheckpoints#
ProtectedcreateDefaultCheckpoints():LocalForage
Create the default checkpoint storage.
Returns#
LocalForage
Defined in#
createDefaultCounters#
ProtectedcreateDefaultCounters():LocalForage
Initialize the default storage for counting file suffixes.
Returns#
LocalForage
Defined in#
createDefaultStorage#
ProtectedcreateDefaultStorage():LocalForage
Initialize the default storage for contents.
Returns#
LocalForage
Defined in#
delete#
delete(path):Promise<void>
Delete a file from browser storage.
Has no effect on server-backed files, which will re-appear with their original timestamp.
Parameters#
Name |
Type |
Description |
|---|---|---|
|
|
The path to the file. |
Returns#
Promise<void>
Implementation of#
IContents.delete
Defined in#
deleteCheckpoint#
deleteCheckpoint(path,checkpointID):Promise<void>
Delete a checkpoint for a file.
Parameters#
Name |
Type |
Description |
|---|---|---|
|
|
The path of the file. |
|
|
The id of the checkpoint to delete. |
Returns#
Promise<void>
A promise which resolves when the checkpoint is deleted.
Implementation of#
IContents.deleteCheckpoint
Defined in#
forgetPath#
ProtectedforgetPath(path):Promise<void>
Remove the localForage and checkpoints for a path.
Parameters#
Name |
Type |
Description |
|---|---|---|
|
|
The path to the file |
Returns#
Promise<void>
Defined in#
get#
get(path,options?):Promise<null|IModel>
Get a file or directory.
Parameters#
Name |
Type |
|---|---|
|
|
|
|
Returns#
Promise<null | IModel>
A promise which resolves with the file content.
Implementation of#
IContents.get
Defined in#
initStorage#
ProtectedinitStorage():Promise<void>
Initialize all storage instances
Returns#
Promise<void>
Defined in#
initialize#
initialize():Promise<void>
Finish any initialization after server has started and all extensions are applied.
Returns#
Promise<void>
Defined in#
listCheckpoints#
listCheckpoints(path):Promise<ICheckpointModel[]>
List available checkpoints for a file.
Parameters#
Name |
Type |
Description |
|---|---|---|
|
|
The path of the file. |
Returns#
Promise<ICheckpointModel[]>
A promise which resolves with a list of checkpoint models for the file.
Implementation of#
IContents.listCheckpoints
Defined in#
newUntitled#
newUntitled(options?):Promise<null|IModel>
Create a new untitled file or directory in the specified directory path.
Parameters#
Name |
Type |
|---|---|
|
|
Returns#
Promise<null | IModel>
A promise which resolves with the created file content when the file is created.
Implementation of#
IContents.newUntitled
Defined in#
normalizeCheckpoint#
ProtectednormalizeCheckpoint(model,id):ICheckpointModel
Parameters#
Name |
Type |
|---|---|
|
|
|
|
Returns#
ICheckpointModel
Defined in#
reduceBytesToString#
ProtectedreduceBytesToString(data,byte):string
A reducer for turning arbitrary binary into a string
Parameters#
Name |
Type |
|---|---|
|
|
|
|
Returns#
string
Defined in#
rename#
rename(oldLocalPath,newLocalPath):Promise<IModel>
Rename a file or directory.
Parameters#
Name |
Type |
Description |
|---|---|---|
|
|
The original file path. |
|
|
The new file path. |
Returns#
Promise<IModel>
A promise which resolves with the new file content model when the file is renamed.
Implementation of#
IContents.rename
Defined in#
restoreCheckpoint#
restoreCheckpoint(path,checkpointID):Promise<void>
Restore a file to a known checkpoint state.
Parameters#
Name |
Type |
Description |
|---|---|---|
|
|
The path of the file. |
|
|
The id of the checkpoint to restore. |
Returns#
Promise<void>
A promise which resolves when the checkpoint is restored.
Implementation of#
IContents.restoreCheckpoint
Defined in#
save#
save(path,options?):Promise<null|IModel>
Save a file.
Parameters#
Name |
Type |
Description |
|---|---|---|
|
|
The desired file path. |
|
|
Optional overrides to the model. |
Returns#
Promise<null | IModel>
A promise which resolves with the file content model when the file is saved.
Implementation of#
IContents.save
Defined in#
unescapeContent#
unescapeContent(content):string
Parameters#
Name |
Type |
|---|---|
|
|
Returns#
string