@jupyterlite/contents 0.1.0-alpha.20 → 0.1.0-alpha.24

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.
Files changed (2) hide show
  1. package/lib/contents.js +26 -26
  2. package/package.json +5 -5
package/lib/contents.js CHANGED
@@ -18,7 +18,7 @@ const EXTRA_TEXT_MIME_TYPES = new Set([
18
18
  'application/manifest+json',
19
19
  'application/x-python-code',
20
20
  'application/xml',
21
- 'image/svg+xml'
21
+ 'image/svg+xml',
22
22
  ]);
23
23
  /**
24
24
  * A class to handle requests to /api/contents
@@ -43,7 +43,7 @@ export class Contents {
43
43
  name: this._storageName,
44
44
  description: 'Offline Storage for Notebooks and Files',
45
45
  storeName: 'files',
46
- version: 1
46
+ version: 1,
47
47
  });
48
48
  }
49
49
  /**
@@ -54,7 +54,7 @@ export class Contents {
54
54
  name: this._storageName,
55
55
  description: 'Store the current file suffix counters',
56
56
  storeName: 'counters',
57
- version: 1
57
+ version: 1,
58
58
  });
59
59
  }
60
60
  /**
@@ -65,7 +65,7 @@ export class Contents {
65
65
  name: this._storageName,
66
66
  description: 'Offline Storage for Checkpoints',
67
67
  storeName: 'checkpoints',
68
- version: 1
68
+ version: 1,
69
69
  });
70
70
  }
71
71
  /**
@@ -117,7 +117,7 @@ export class Contents {
117
117
  content: null,
118
118
  size: undefined,
119
119
  writable: true,
120
- type: 'directory'
120
+ type: 'directory',
121
121
  };
122
122
  break;
123
123
  }
@@ -136,7 +136,7 @@ export class Contents {
136
136
  content: '',
137
137
  size: 0,
138
138
  writable: true,
139
- type: 'file'
139
+ type: 'file',
140
140
  };
141
141
  break;
142
142
  }
@@ -153,7 +153,7 @@ export class Contents {
153
153
  content: Private.EMPTY_NB,
154
154
  size: JSON.stringify(Private.EMPTY_NB).length,
155
155
  writable: true,
156
- type: 'notebook'
156
+ type: 'notebook',
157
157
  };
158
158
  break;
159
159
  }
@@ -191,7 +191,7 @@ export class Contents {
191
191
  item = {
192
192
  ...item,
193
193
  name,
194
- path: toPath
194
+ path: toPath,
195
195
  };
196
196
  await this._storage.setItem(toPath, item);
197
197
  return item;
@@ -220,7 +220,7 @@ export class Contents {
220
220
  return {
221
221
  ...model,
222
222
  content: null,
223
- size: undefined
223
+ size: undefined,
224
224
  };
225
225
  }
226
226
  // for directories, find all files with the path as the prefix
@@ -252,7 +252,7 @@ export class Contents {
252
252
  content,
253
253
  size: undefined,
254
254
  writable: true,
255
- type: 'directory'
255
+ type: 'directory',
256
256
  };
257
257
  }
258
258
  return model;
@@ -277,7 +277,7 @@ export class Contents {
277
277
  ...file,
278
278
  name,
279
279
  path: newLocalPath,
280
- last_modified: modified
280
+ last_modified: modified,
281
281
  };
282
282
  await this._storage.setItem(newLocalPath, newFile);
283
283
  // remove the old file
@@ -313,19 +313,19 @@ export class Contents {
313
313
  item = {
314
314
  ...item,
315
315
  ...options,
316
- last_modified: modified
316
+ last_modified: modified,
317
317
  };
318
318
  // process the file if coming from an upload
319
319
  const ext = PathExt.extname((_a = options.name) !== null && _a !== void 0 ? _a : '');
320
320
  if (options.content && options.format === 'base64') {
321
321
  // TODO: keep base64 if not a text file (image)
322
- const content = atob(options.content);
322
+ const content = decodeURIComponent(escape(atob(options.content)));
323
323
  const nb = ext === '.ipynb';
324
324
  item = {
325
325
  ...item,
326
326
  content: nb ? JSON.parse(content) : content,
327
327
  format: nb ? 'json' : 'text',
328
- type: nb ? 'notebook' : 'file'
328
+ type: nb ? 'notebook' : 'file',
329
329
  };
330
330
  }
331
331
  await this._storage.setItem(path, item);
@@ -348,7 +348,7 @@ export class Contents {
348
348
  await Promise.all(toDelete.map(async (p) => {
349
349
  return Promise.all([
350
350
  this._storage.removeItem(p),
351
- this._checkpoints.removeItem(p)
351
+ this._checkpoints.removeItem(p),
352
352
  ]);
353
353
  }));
354
354
  }
@@ -367,7 +367,7 @@ export class Contents {
367
367
  if (!item) {
368
368
  throw Error(`Could not find file with path ${path}`);
369
369
  }
370
- const copies = ((_a = (await this._checkpoints.getItem(path))) !== null && _a !== void 0 ? _a : []).filter(item => !!item);
370
+ const copies = ((_a = (await this._checkpoints.getItem(path))) !== null && _a !== void 0 ? _a : []).filter((item) => !!item);
371
371
  copies.push(item);
372
372
  // keep only a certain amount of checkpoints per file
373
373
  if (copies.length > N_CHECKPOINTS) {
@@ -377,7 +377,7 @@ export class Contents {
377
377
  const id = `${copies.length - 1}`;
378
378
  return {
379
379
  id,
380
- last_modified: item.last_modified
380
+ last_modified: item.last_modified,
381
381
  };
382
382
  }
383
383
  /**
@@ -392,11 +392,11 @@ export class Contents {
392
392
  const copies = ((await this._checkpoints.getItem(path)) ||
393
393
  []);
394
394
  return copies
395
- .filter(item => !!item)
395
+ .filter((item) => !!item)
396
396
  .map((file, id) => {
397
397
  return {
398
398
  id: id.toString(),
399
- last_modified: file.last_modified
399
+ last_modified: file.last_modified,
400
400
  };
401
401
  });
402
402
  }
@@ -468,7 +468,7 @@ export class Contents {
468
468
  content: Array.from(content.values()),
469
469
  size: undefined,
470
470
  writable: true,
471
- type: 'directory'
471
+ type: 'directory',
472
472
  };
473
473
  }
474
474
  /**
@@ -492,7 +492,7 @@ export class Contents {
492
492
  mimetype: 'text/plain',
493
493
  type: 'file',
494
494
  writable: true,
495
- content: null
495
+ content: null,
496
496
  };
497
497
  if (options === null || options === void 0 ? void 0 : options.content) {
498
498
  if (model.type === 'directory') {
@@ -513,7 +513,7 @@ export class Contents {
513
513
  ...model,
514
514
  content: await response.json(),
515
515
  format: 'json',
516
- mimetype: model.mimetype || 'application/json'
516
+ mimetype: model.mimetype || 'application/json',
517
517
  };
518
518
  }
519
519
  else if (mimetype.indexOf('text') !== -1 ||
@@ -522,7 +522,7 @@ export class Contents {
522
522
  ...model,
523
523
  content: await response.text(),
524
524
  format: 'text',
525
- mimetype: mimetype || 'text/plain'
525
+ mimetype: mimetype || 'text/plain',
526
526
  };
527
527
  }
528
528
  else {
@@ -530,7 +530,7 @@ export class Contents {
530
530
  ...model,
531
531
  content: btoa(String.fromCharCode(...new Uint8Array(await response.arrayBuffer()))),
532
532
  format: 'base64',
533
- mimetype: mimetype || 'octet/stream'
533
+ mimetype: mimetype || 'octet/stream',
534
534
  };
535
535
  }
536
536
  }
@@ -588,10 +588,10 @@ var Private;
588
588
  */
589
589
  Private.EMPTY_NB = {
590
590
  metadata: {
591
- orig_nbformat: 4
591
+ orig_nbformat: 4,
592
592
  },
593
593
  nbformat_minor: 4,
594
594
  nbformat: 4,
595
- cells: []
595
+ cells: [],
596
596
  };
597
597
  })(Private || (Private = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyterlite/contents",
3
- "version": "0.1.0-alpha.20",
3
+ "version": "0.1.0-alpha.24",
4
4
  "description": "JupyterLite - Contents",
5
5
  "homepage": "https://github.com/jupyterlite/jupyterlite",
6
6
  "bugs": {
@@ -42,20 +42,20 @@
42
42
  "watch": "tsc -b --watch"
43
43
  },
44
44
  "dependencies": {
45
- "@jupyterlab/nbformat": "~3.2.6",
46
- "@jupyterlab/services": "~6.2.6",
45
+ "@jupyterlab/nbformat": "~3.2.9",
46
+ "@jupyterlab/services": "~6.2.9",
47
47
  "@lumino/coreutils": "^1.8.0",
48
48
  "localforage": "^1.9.0"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@babel/core": "^7.11.6",
52
52
  "@babel/preset-env": "^7.12.1",
53
- "@jupyterlab/testutils": "~3.2.6",
53
+ "@jupyterlab/testutils": "~3.2.9",
54
54
  "@types/jest": "^26.0.10",
55
55
  "jest": "^26.4.2",
56
56
  "rimraf": "~3.0.0",
57
57
  "ts-jest": "^26.3.0",
58
- "typescript": "~4.2.3"
58
+ "typescript": "~4.5.2"
59
59
  },
60
60
  "publishConfig": {
61
61
  "access": "public"