@jupyterlite/contents 0.1.0-alpha.9 → 0.1.0-beta.10

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.
package/lib/contents.d.ts CHANGED
@@ -1,27 +1,55 @@
1
- import { Contents as ServerContents, ServerConnection } from '@jupyterlab/services';
2
- import { ModelDB } from '@jupyterlab/observables';
3
- import { ISignal } from '@lumino/signaling';
1
+ import { Contents as ServerContents } from '@jupyterlab/services';
2
+ import type localforage from 'localforage';
4
3
  import { IContents } from './tokens';
4
+ export declare type IModel = ServerContents.IModel;
5
5
  /**
6
6
  * A class to handle requests to /api/contents
7
7
  */
8
8
  export declare class Contents implements IContents {
9
9
  /**
10
- * A signal emitted when the file has changed.
10
+ * Construct a new localForage-powered contents provider
11
11
  */
12
- get fileChanged(): ISignal<ServerContents.IManager, ServerContents.IChangedArgs>;
12
+ constructor(options: Contents.IOptions);
13
13
  /**
14
- * Test whether the manager has been disposed.
14
+ * Finish any initialization after server has started and all extensions are applied.
15
15
  */
16
- get isDisposed(): boolean;
16
+ initialize(): Promise<void>;
17
17
  /**
18
- * Return the server settings.
18
+ * Initialize all storage instances
19
19
  */
20
- get serverSettings(): ServerConnection.ISettings;
20
+ protected initStorage(): Promise<void>;
21
21
  /**
22
- * Dispose of the resources held by the manager.
22
+ * A promise that resolves once all storage is fully initialized.
23
23
  */
24
- dispose(): void;
24
+ get ready(): Promise<void>;
25
+ /**
26
+ * A lazy reference to the underlying storage.
27
+ */
28
+ protected get storage(): Promise<LocalForage>;
29
+ /**
30
+ * A lazy reference to the underlying counters.
31
+ */
32
+ protected get counters(): Promise<LocalForage>;
33
+ /**
34
+ * A lazy reference to the underlying checkpoints.
35
+ */
36
+ protected get checkpoints(): Promise<LocalForage>;
37
+ /**
38
+ * Get default options for localForage instances
39
+ */
40
+ protected get defaultStorageOptions(): LocalForageOptions;
41
+ /**
42
+ * Initialize the default storage for contents.
43
+ */
44
+ protected createDefaultStorage(): LocalForage;
45
+ /**
46
+ * Initialize the default storage for counting file suffixes.
47
+ */
48
+ protected createDefaultCounters(): LocalForage;
49
+ /**
50
+ * Create the default checkpoint storage.
51
+ */
52
+ protected createDefaultCheckpoints(): LocalForage;
25
53
  /**
26
54
  * Create a new untitled file or directory in the specified directory path.
27
55
  *
@@ -29,7 +57,7 @@ export declare class Contents implements IContents {
29
57
  *
30
58
  * @returns A promise which resolves with the created file content when the file is created.
31
59
  */
32
- newUntitled(options?: ServerContents.ICreateOptions): Promise<ServerContents.IModel>;
60
+ newUntitled(options?: ServerContents.ICreateOptions): Promise<IModel | null>;
33
61
  /**
34
62
  * Copy a file into a given directory.
35
63
  *
@@ -42,7 +70,7 @@ export declare class Contents implements IContents {
42
70
  * #### Notes
43
71
  * The server will select the name of the copied file.
44
72
  */
45
- copy(path: string, toDir: string): Promise<ServerContents.IModel>;
73
+ copy(path: string, toDir: string): Promise<IModel>;
46
74
  /**
47
75
  * Get a file or directory.
48
76
  *
@@ -51,32 +79,7 @@ export declare class Contents implements IContents {
51
79
  *
52
80
  * @returns A promise which resolves with the file content.
53
81
  */
54
- get(path: string, options?: ServerContents.IFetchOptions): Promise<ServerContents.IModel>;
55
- /**
56
- * retrieve the contents for this path from the union of local storage and
57
- * `api/contents/{path}/all.json`.
58
- *
59
- * @param path - The contents path to retrieve
60
- *
61
- * @returns A promise which resolves with a Map of contents, keyed by local file name
62
- */
63
- getFolder(path: string): Promise<ServerContents.IModel>;
64
- private _serverContents;
65
- /**
66
- * retrieve the contents for this path from `__index__.json` in the appropriate
67
- * folder.
68
- *
69
- * @param newLocalPath - The new file path.
70
- *
71
- * @returns A promise which resolves with a Map of contents, keyed by local file name
72
- */
73
- getServerDirectory(path: string): Promise<Map<string, ServerContents.IModel>>;
74
- /**
75
- * Attempt to recover the model from `{:path}/__all__.json` file, fall back to
76
- * deriving the model (including content) off the file in `/files/`. Otherwise
77
- * return `null`.
78
- */
79
- getServerContents(path: string, options?: ServerContents.IFetchOptions): Promise<ServerContents.IModel | null>;
82
+ get(path: string, options?: ServerContents.IFetchOptions): Promise<IModel | null>;
80
83
  /**
81
84
  * Rename a file or directory.
82
85
  *
@@ -85,7 +88,7 @@ export declare class Contents implements IContents {
85
88
  *
86
89
  * @returns A promise which resolves with the new file content model when the file is renamed.
87
90
  */
88
- rename(oldLocalPath: string, newLocalPath: string): Promise<ServerContents.IModel>;
91
+ rename(oldLocalPath: string, newLocalPath: string): Promise<IModel>;
89
92
  /**
90
93
  * Save a file.
91
94
  *
@@ -94,13 +97,23 @@ export declare class Contents implements IContents {
94
97
  *
95
98
  * @returns A promise which resolves with the file content model when the file is saved.
96
99
  */
97
- save(path: string, options?: Partial<ServerContents.IModel>): Promise<ServerContents.IModel>;
100
+ save(path: string, options?: Partial<IModel>): Promise<IModel | null>;
101
+ unescapeContent(content: string): string;
98
102
  /**
99
- * Delete a file.
103
+ * Delete a file from browser storage.
104
+ *
105
+ * Has no effect on server-backed files, which will re-appear with their
106
+ * original timestamp.
100
107
  *
101
108
  * @param path - The path to the file.
102
109
  */
103
110
  delete(path: string): Promise<void>;
111
+ /**
112
+ * Remove the localForage and checkpoints for a path.
113
+ *
114
+ * @param path - The path to the file
115
+ */
116
+ protected forgetPath(path: string): Promise<void>;
104
117
  /**
105
118
  * Create a checkpoint for a file.
106
119
  *
@@ -119,6 +132,7 @@ export declare class Contents implements IContents {
119
132
  * the file.
120
133
  */
121
134
  listCheckpoints(path: string): Promise<ServerContents.ICheckpointModel[]>;
135
+ protected normalizeCheckpoint(model: IModel, id: number): ServerContents.ICheckpointModel;
122
136
  /**
123
137
  * Restore a file to a known checkpoint state.
124
138
  *
@@ -138,67 +152,33 @@ export declare class Contents implements IContents {
138
152
  */
139
153
  deleteCheckpoint(path: string, checkpointID: string): Promise<void>;
140
154
  /**
141
- * Add an `IDrive` to the manager.
142
- */
143
- addDrive(drive: ServerContents.IDrive): void;
144
- /**
145
- * Given a path of the form `drive:local/portion/of/it.txt`
146
- * get the local part of it.
147
- *
148
- * @param path: the path.
149
- *
150
- * @returns The local part of the path.
151
- */
152
- localPath(path: string): string;
153
- /**
154
- * Normalize a global path. Reduces '..' and '.' parts, and removes
155
- * leading slashes from the local part of the path, while retaining
156
- * the drive name if it exists.
157
- *
158
- * @param path: the path.
159
- *
160
- * @returns The normalized path.
161
- */
162
- normalize(path: string): string;
163
- /**
164
- * Resolve a global path, starting from the root path. Behaves like
165
- * posix-path.resolve, with 3 differences:
166
- * - will never prepend cwd
167
- * - if root has a drive name, the result is prefixed with "<drive>:"
168
- * - before adding drive name, leading slashes are removed
155
+ * retrieve the contents for this path from the union of local storage and
156
+ * `api/contents/{path}/all.json`.
169
157
  *
170
- * @param path: the path.
158
+ * @param path - The contents path to retrieve
171
159
  *
172
- * @returns The normalized path.
160
+ * @returns A promise which resolves with a Map of contents, keyed by local file name
173
161
  */
174
- resolvePath(root: string, path: string): string;
162
+ private _getFolder;
175
163
  /**
176
- * Given a path of the form `drive:local/portion/of/it.txt`
177
- * get the name of the drive. If the path is missing
178
- * a drive portion, returns an empty string.
179
- *
180
- * @param path: the path.
181
- *
182
- * @returns The drive name for the path, or the empty string.
164
+ * Attempt to recover the model from `{:path}/__all__.json` file, fall back to
165
+ * deriving the model (including content) off the file in `/files/`. Otherwise
166
+ * return `null`.
183
167
  */
184
- driveName(path: string): string;
168
+ private _getServerContents;
185
169
  /**
186
- * Given a path, get a ModelDB.IFactory from the
187
- * relevant backend. Returns `null` if the backend
188
- * does not provide one.
170
+ * A reducer for turning arbitrary binary into a string
189
171
  */
190
- getModelDBFactory(path: string): ModelDB.IFactory | null;
172
+ protected reduceBytesToString: (data: string, byte: number) => string;
191
173
  /**
192
- * Get an encoded download url given a file path.
193
- *
194
- * @param path - An absolute POSIX file path on the server.
174
+ * retrieve the contents for this path from `__index__.json` in the appropriate
175
+ * folder.
195
176
  *
196
- * #### Notes
197
- * It is expected that the path contains no relative paths.
177
+ * @param newLocalPath - The new file path.
198
178
  *
199
- * The returned URL may include a query parameter.
179
+ * @returns A promise which resolves with a Map of contents, keyed by local file name
200
180
  */
201
- getDownloadUrl(path: string): Promise<string>;
181
+ private _getServerDirectory;
202
182
  /**
203
183
  * Increment the counter for a given file type.
204
184
  * Used to avoid collisions when creating new untitled files.
@@ -206,9 +186,25 @@ export declare class Contents implements IContents {
206
186
  * @param type The file type to increment the counter for.
207
187
  */
208
188
  private _incrementCounter;
209
- private _isDisposed;
210
- private _fileChanged;
189
+ private _serverContents;
190
+ private _storageName;
191
+ private _storageDrivers;
192
+ private _ready;
211
193
  private _storage;
212
194
  private _counters;
213
195
  private _checkpoints;
196
+ private _localforage;
197
+ }
198
+ /**
199
+ * A namespace for contents information.
200
+ */
201
+ export declare namespace Contents {
202
+ interface IOptions {
203
+ /**
204
+ * The name of the storage instance on e.g. IndexedDB, localStorage
205
+ */
206
+ storageName?: string | null;
207
+ storageDrivers?: string[] | null;
208
+ localforage: typeof localforage;
209
+ }
214
210
  }