@difizen/libro-kernel 0.0.0-snapshot-20241017072317

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 (188) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/es/basemanager.d.ts +94 -0
  4. package/es/basemanager.d.ts.map +1 -0
  5. package/es/basemanager.js +110 -0
  6. package/es/contents/contents-drive.d.ts +189 -0
  7. package/es/contents/contents-drive.d.ts.map +1 -0
  8. package/es/contents/contents-drive.js +802 -0
  9. package/es/contents/contents-manager.d.ts +229 -0
  10. package/es/contents/contents-manager.d.ts.map +1 -0
  11. package/es/contents/contents-manager.js +551 -0
  12. package/es/contents/contents-module.d.ts +3 -0
  13. package/es/contents/contents-module.d.ts.map +1 -0
  14. package/es/contents/contents-module.js +4 -0
  15. package/es/contents/contents-protocol.d.ts +487 -0
  16. package/es/contents/contents-protocol.d.ts.map +1 -0
  17. package/es/contents/contents-protocol.js +1 -0
  18. package/es/contents/index.d.ts +6 -0
  19. package/es/contents/index.d.ts.map +1 -0
  20. package/es/contents/index.js +5 -0
  21. package/es/contents/validate.d.ts +10 -0
  22. package/es/contents/validate.d.ts.map +1 -0
  23. package/es/contents/validate.js +22 -0
  24. package/es/index.d.ts +10 -0
  25. package/es/index.d.ts.map +1 -0
  26. package/es/index.js +9 -0
  27. package/es/kernel/comm.d.ts +92 -0
  28. package/es/kernel/comm.d.ts.map +1 -0
  29. package/es/kernel/comm.js +216 -0
  30. package/es/kernel/future.d.ts +178 -0
  31. package/es/kernel/future.d.ts.map +1 -0
  32. package/es/kernel/future.js +593 -0
  33. package/es/kernel/index.d.ts +8 -0
  34. package/es/kernel/index.d.ts.map +1 -0
  35. package/es/kernel/index.js +8 -0
  36. package/es/kernel/kernel-connection.d.ts +553 -0
  37. package/es/kernel/kernel-connection.d.ts.map +1 -0
  38. package/es/kernel/kernel-connection.js +1974 -0
  39. package/es/kernel/kernel-module.d.ts +3 -0
  40. package/es/kernel/kernel-module.d.ts.map +1 -0
  41. package/es/kernel/kernel-module.js +32 -0
  42. package/es/kernel/libro-kernel-manager.d.ts +89 -0
  43. package/es/kernel/libro-kernel-manager.d.ts.map +1 -0
  44. package/es/kernel/libro-kernel-manager.js +469 -0
  45. package/es/kernel/libro-kernel-protocol.d.ts +678 -0
  46. package/es/kernel/libro-kernel-protocol.d.ts.map +1 -0
  47. package/es/kernel/libro-kernel-protocol.js +60 -0
  48. package/es/kernel/libro-kernel-utils.d.ts +95 -0
  49. package/es/kernel/libro-kernel-utils.d.ts.map +1 -0
  50. package/es/kernel/libro-kernel-utils.js +130 -0
  51. package/es/kernel/libro-kernel.d.ts +14 -0
  52. package/es/kernel/libro-kernel.d.ts.map +1 -0
  53. package/es/kernel/libro-kernel.js +54 -0
  54. package/es/kernel/messages.d.ts +845 -0
  55. package/es/kernel/messages.d.ts.map +1 -0
  56. package/es/kernel/messages.js +513 -0
  57. package/es/kernel/restapi.d.ts +78 -0
  58. package/es/kernel/restapi.d.ts.map +1 -0
  59. package/es/kernel/restapi.js +372 -0
  60. package/es/kernel/serialize.d.ts +10 -0
  61. package/es/kernel/serialize.d.ts.map +1 -0
  62. package/es/kernel/serialize.js +213 -0
  63. package/es/kernel/validate.d.ts +15 -0
  64. package/es/kernel/validate.d.ts.map +1 -0
  65. package/es/kernel/validate.js +125 -0
  66. package/es/kernelspec/index.d.ts +5 -0
  67. package/es/kernelspec/index.d.ts.map +1 -0
  68. package/es/kernelspec/index.js +4 -0
  69. package/es/kernelspec/kernelspec-module.d.ts +3 -0
  70. package/es/kernelspec/kernelspec-module.d.ts.map +1 -0
  71. package/es/kernelspec/kernelspec-module.js +4 -0
  72. package/es/kernelspec/kernelspec.d.ts +33 -0
  73. package/es/kernelspec/kernelspec.d.ts.map +1 -0
  74. package/es/kernelspec/kernelspec.js +1 -0
  75. package/es/kernelspec/manager.d.ts +81 -0
  76. package/es/kernelspec/manager.d.ts.map +1 -0
  77. package/es/kernelspec/manager.js +245 -0
  78. package/es/kernelspec/restapi.d.ts +71 -0
  79. package/es/kernelspec/restapi.d.ts.map +1 -0
  80. package/es/kernelspec/restapi.js +107 -0
  81. package/es/kernelspec/validate.d.ts +10 -0
  82. package/es/kernelspec/validate.d.ts.map +1 -0
  83. package/es/kernelspec/validate.js +70 -0
  84. package/es/libro-kernel-connection-manager.d.ts +20 -0
  85. package/es/libro-kernel-connection-manager.d.ts.map +1 -0
  86. package/es/libro-kernel-connection-manager.js +146 -0
  87. package/es/module.d.ts +3 -0
  88. package/es/module.d.ts.map +1 -0
  89. package/es/module.js +9 -0
  90. package/es/page-config.d.ts +36 -0
  91. package/es/page-config.d.ts.map +1 -0
  92. package/es/page-config.js +129 -0
  93. package/es/protocol.d.ts +13 -0
  94. package/es/protocol.d.ts.map +1 -0
  95. package/es/protocol.js +8 -0
  96. package/es/server/connection-error.d.ts +36 -0
  97. package/es/server/connection-error.d.ts.map +1 -0
  98. package/es/server/connection-error.js +109 -0
  99. package/es/server/index.d.ts +6 -0
  100. package/es/server/index.d.ts.map +1 -0
  101. package/es/server/index.js +5 -0
  102. package/es/server/server-connection-protocol.d.ts +49 -0
  103. package/es/server/server-connection-protocol.d.ts.map +1 -0
  104. package/es/server/server-connection-protocol.js +0 -0
  105. package/es/server/server-connection.d.ts +25 -0
  106. package/es/server/server-connection.d.ts.map +1 -0
  107. package/es/server/server-connection.js +159 -0
  108. package/es/server/server-manager.d.ts +23 -0
  109. package/es/server/server-manager.d.ts.map +1 -0
  110. package/es/server/server-manager.js +178 -0
  111. package/es/server/server-module.d.ts +3 -0
  112. package/es/server/server-module.d.ts.map +1 -0
  113. package/es/server/server-module.js +4 -0
  114. package/es/session/index.d.ts +5 -0
  115. package/es/session/index.d.ts.map +1 -0
  116. package/es/session/index.js +4 -0
  117. package/es/session/libro-session-manager.d.ts +73 -0
  118. package/es/session/libro-session-manager.d.ts.map +1 -0
  119. package/es/session/libro-session-manager.js +568 -0
  120. package/es/session/libro-session-protocol.d.ts +50 -0
  121. package/es/session/libro-session-protocol.d.ts.map +1 -0
  122. package/es/session/libro-session-protocol.js +21 -0
  123. package/es/session/libro-session.d.ts +12 -0
  124. package/es/session/libro-session.d.ts.map +1 -0
  125. package/es/session/libro-session.js +19 -0
  126. package/es/session/restapi.d.ts +28 -0
  127. package/es/session/restapi.d.ts.map +1 -0
  128. package/es/session/restapi.js +215 -0
  129. package/es/session/session-module.d.ts +3 -0
  130. package/es/session/session-module.d.ts.map +1 -0
  131. package/es/session/session-module.js +18 -0
  132. package/es/session/validate.d.ts +14 -0
  133. package/es/session/validate.d.ts.map +1 -0
  134. package/es/session/validate.js +38 -0
  135. package/es/utils.d.ts +4 -0
  136. package/es/utils.d.ts.map +1 -0
  137. package/es/utils.js +29 -0
  138. package/es/validate-property.d.ts +2 -0
  139. package/es/validate-property.d.ts.map +1 -0
  140. package/es/validate-property.js +35 -0
  141. package/package.json +62 -0
  142. package/src/basemanager.ts +133 -0
  143. package/src/contents/contents-drive.ts +496 -0
  144. package/src/contents/contents-manager.ts +465 -0
  145. package/src/contents/contents-module.ts +6 -0
  146. package/src/contents/contents-protocol.ts +604 -0
  147. package/src/contents/index.ts +5 -0
  148. package/src/contents/validate.ts +29 -0
  149. package/src/index.spec.ts +16 -0
  150. package/src/index.tsx +9 -0
  151. package/src/kernel/comm.ts +220 -0
  152. package/src/kernel/future.ts +477 -0
  153. package/src/kernel/index.ts +7 -0
  154. package/src/kernel/kernel-connection.ts +1780 -0
  155. package/src/kernel/kernel-module.ts +50 -0
  156. package/src/kernel/libro-kernel-manager.ts +274 -0
  157. package/src/kernel/libro-kernel-protocol.ts +861 -0
  158. package/src/kernel/libro-kernel-utils.ts +152 -0
  159. package/src/kernel/libro-kernel.ts +39 -0
  160. package/src/kernel/messages.ts +1104 -0
  161. package/src/kernel/restapi.ts +183 -0
  162. package/src/kernel/serialize.ts +262 -0
  163. package/src/kernel/validate.ts +101 -0
  164. package/src/kernelspec/index.ts +5 -0
  165. package/src/kernelspec/kernelspec-module.ts +9 -0
  166. package/src/kernelspec/kernelspec.ts +37 -0
  167. package/src/kernelspec/manager.ts +162 -0
  168. package/src/kernelspec/restapi.ts +104 -0
  169. package/src/kernelspec/validate.ts +80 -0
  170. package/src/libro-kernel-connection-manager.ts +76 -0
  171. package/src/module.ts +19 -0
  172. package/src/page-config.ts +106 -0
  173. package/src/protocol.ts +24 -0
  174. package/src/server/connection-error.ts +60 -0
  175. package/src/server/index.ts +5 -0
  176. package/src/server/server-connection-protocol.ts +57 -0
  177. package/src/server/server-connection.ts +144 -0
  178. package/src/server/server-manager.ts +90 -0
  179. package/src/server/server-module.ts +9 -0
  180. package/src/session/index.ts +4 -0
  181. package/src/session/libro-session-manager.ts +406 -0
  182. package/src/session/libro-session-protocol.ts +61 -0
  183. package/src/session/libro-session.ts +33 -0
  184. package/src/session/restapi.ts +126 -0
  185. package/src/session/session-module.ts +26 -0
  186. package/src/session/validate.ts +39 -0
  187. package/src/utils.ts +28 -0
  188. package/src/validate-property.ts +38 -0
@@ -0,0 +1,802 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _dec, _dec2, _class, _class2, _descriptor;
3
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
5
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
7
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
8
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
10
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
14
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
15
+ function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
16
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
18
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
19
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
20
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
21
+ function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
22
+ function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
23
+ import { URL as URLUtil } from '@difizen/libro-common';
24
+ import { inject, singleton } from '@difizen/mana-app';
25
+ import { Emitter } from '@difizen/mana-app';
26
+ import qs from 'query-string';
27
+ import { createResponseError, ServerConnection } from "../server/index.js";
28
+ import * as validate from "./validate.js";
29
+
30
+ /**
31
+ * The url for the default drive service.
32
+ */
33
+ var SERVICE_DRIVE_URL = 'api/contents';
34
+
35
+ /**
36
+ * The url for the file access.
37
+ */
38
+ var FILES_URL = 'files';
39
+ function normalizeExtension(extension) {
40
+ if (extension.length > 0 && extension.indexOf('.') !== 0) {
41
+ // eslint-disable-next-line no-param-reassign
42
+ extension = ".".concat(extension);
43
+ }
44
+ return extension;
45
+ }
46
+ /**
47
+ * A default implementation for an `IContentsDrive`, talking to the
48
+ * server using the Jupyter REST API.
49
+ */
50
+ export var Drive = (_dec = singleton(), _dec2 = inject(ServerConnection), _dec(_class = (_class2 = /*#__PURE__*/function () {
51
+ /**
52
+ * Construct a new contents manager object.
53
+ *
54
+ * @param options - The options used to initialize the object.
55
+ */
56
+ function Drive() {
57
+ _classCallCheck(this, Drive);
58
+ _initializerDefineProperty(this, "serverConnection", _descriptor, this);
59
+ this._isDisposed = false;
60
+ this.fileChangedEmitter = new Emitter();
61
+ this.apiEndpoint = SERVICE_DRIVE_URL;
62
+ }
63
+
64
+ /**
65
+ * The name of the drive, which is used at the leading
66
+ * component of file paths.
67
+ */
68
+ _createClass(Drive, [{
69
+ key: "fileChanged",
70
+ get:
71
+ /**
72
+ * A signal emitted when a file operation takes place.
73
+ */
74
+ function get() {
75
+ return this.fileChangedEmitter.event;
76
+ }
77
+
78
+ /**
79
+ * The server settings of the drive.
80
+ */
81
+ // readonly serverSettings: ISettings;
82
+
83
+ /**
84
+ * Test whether the manager has been disposed.
85
+ */
86
+ }, {
87
+ key: "isDisposed",
88
+ get: function get() {
89
+ return this._isDisposed;
90
+ }
91
+
92
+ /**
93
+ * Dispose of the resources held by the manager.
94
+ */
95
+ }, {
96
+ key: "dispose",
97
+ value: function dispose() {
98
+ if (this.isDisposed) {
99
+ return;
100
+ }
101
+ this._isDisposed = true;
102
+ this.fileChangedEmitter.dispose();
103
+ }
104
+
105
+ /**
106
+ * Get a file or directory.
107
+ *
108
+ * @param localPath: The path to the file.
109
+ *
110
+ * @param options: The options used to fetch the file.
111
+ *
112
+ * @returns A promise which resolves with the file content.
113
+ *
114
+ * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model.
115
+ */
116
+ }, {
117
+ key: "get",
118
+ value: (function () {
119
+ var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(localPath, options) {
120
+ var url, settings, content, params, response, err, data;
121
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
122
+ while (1) switch (_context.prev = _context.next) {
123
+ case 0:
124
+ url = this.getUrl(options === null || options === void 0 ? void 0 : options.baseUrl, localPath);
125
+ settings = this._getSettings(options === null || options === void 0 ? void 0 : options.baseUrl);
126
+ if (options) {
127
+ // The notebook type cannot take an format option.
128
+ if (options.type === 'notebook') {
129
+ delete options.format;
130
+ }
131
+ if (options.baseUrl) {
132
+ delete options.baseUrl;
133
+ }
134
+ content = options.content ? '1' : '0';
135
+ params = _objectSpread(_objectSpread({}, options), {}, {
136
+ content: content
137
+ });
138
+ url += "?".concat(qs.stringify(params));
139
+ }
140
+ _context.next = 5;
141
+ return this.serverConnection.makeRequest(url, {}, settings);
142
+ case 5:
143
+ response = _context.sent;
144
+ if (!(response.status !== 200)) {
145
+ _context.next = 11;
146
+ break;
147
+ }
148
+ _context.next = 9;
149
+ return createResponseError(response);
150
+ case 9:
151
+ err = _context.sent;
152
+ throw err;
153
+ case 11:
154
+ _context.next = 13;
155
+ return response.json();
156
+ case 13:
157
+ data = _context.sent;
158
+ validate.validateContentsModel(data);
159
+ return _context.abrupt("return", data);
160
+ case 16:
161
+ case "end":
162
+ return _context.stop();
163
+ }
164
+ }, _callee, this);
165
+ }));
166
+ function get(_x, _x2) {
167
+ return _get.apply(this, arguments);
168
+ }
169
+ return get;
170
+ }()
171
+ /**
172
+ * Get an encoded download url given a file path.
173
+ *
174
+ * @param localPath - An absolute POSIX file path on the server.
175
+ *
176
+ * #### Notes
177
+ * It is expected that the path contains no relative paths.
178
+ *
179
+ * The returned URL may include a query parameter.
180
+ */
181
+ )
182
+ }, {
183
+ key: "getDownloadUrl",
184
+ value: function getDownloadUrl(localPath, options) {
185
+ var baseUrl = (options === null || options === void 0 ? void 0 : options.baseUrl) || this.serverConnection.settings.baseUrl;
186
+ var url = URLUtil.join(baseUrl, FILES_URL, URLUtil.encodeParts(localPath));
187
+ var xsrfTokenMatch = document.cookie.match('\\b_xsrf=([^;]*)\\b');
188
+ if (xsrfTokenMatch) {
189
+ var fullUrl = new URL(url);
190
+ fullUrl.searchParams.append('_xsrf', xsrfTokenMatch[1]);
191
+ url = fullUrl.toString();
192
+ }
193
+ return Promise.resolve(url);
194
+ }
195
+
196
+ /**
197
+ * Create a new untitled file or directory in the specified directory path.
198
+ *
199
+ * @param options: The options used to create the file.
200
+ *
201
+ * @returns A promise which resolves with the created file content when the
202
+ * file is created.
203
+ *
204
+ * #### Notes
205
+ * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model.
206
+ */
207
+ }, {
208
+ key: "newUntitled",
209
+ value: (function () {
210
+ var _newUntitled = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
211
+ var _options$path;
212
+ var options,
213
+ body,
214
+ url,
215
+ settings,
216
+ init,
217
+ response,
218
+ err,
219
+ data,
220
+ _args2 = arguments;
221
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
222
+ while (1) switch (_context2.prev = _context2.next) {
223
+ case 0:
224
+ options = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
225
+ body = '{}';
226
+ url = this.getUrl(options.baseUrl, (_options$path = options.path) !== null && _options$path !== void 0 ? _options$path : '');
227
+ settings = this._getSettings(options.baseUrl);
228
+ if (options) {
229
+ if (options.ext) {
230
+ options.ext = normalizeExtension(options.ext);
231
+ }
232
+ if (options.baseUrl) {
233
+ delete options.baseUrl;
234
+ }
235
+ body = JSON.stringify(options);
236
+ }
237
+ init = {
238
+ method: 'POST',
239
+ body: body
240
+ };
241
+ _context2.next = 8;
242
+ return this.serverConnection.makeRequest(url, init, settings);
243
+ case 8:
244
+ response = _context2.sent;
245
+ if (!(response.status !== 201)) {
246
+ _context2.next = 14;
247
+ break;
248
+ }
249
+ _context2.next = 12;
250
+ return createResponseError(response);
251
+ case 12:
252
+ err = _context2.sent;
253
+ throw err;
254
+ case 14:
255
+ _context2.next = 16;
256
+ return response.json();
257
+ case 16:
258
+ data = _context2.sent;
259
+ validate.validateContentsModel(data);
260
+ this.fileChangedEmitter.fire({
261
+ type: 'new',
262
+ oldValue: null,
263
+ newValue: data
264
+ });
265
+ return _context2.abrupt("return", data);
266
+ case 20:
267
+ case "end":
268
+ return _context2.stop();
269
+ }
270
+ }, _callee2, this);
271
+ }));
272
+ function newUntitled() {
273
+ return _newUntitled.apply(this, arguments);
274
+ }
275
+ return newUntitled;
276
+ }()
277
+ /**
278
+ * Delete a file.
279
+ *
280
+ * @param localPath - The path to the file.
281
+ *
282
+ * @returns A promise which resolves when the file is deleted.
283
+ *
284
+ * #### Notes
285
+ * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents).
286
+ */
287
+ )
288
+ }, {
289
+ key: "delete",
290
+ value: (function () {
291
+ var _delete2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(localPath, options) {
292
+ var url, init, settings, response, err;
293
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
294
+ while (1) switch (_context3.prev = _context3.next) {
295
+ case 0:
296
+ url = this.getUrl(options === null || options === void 0 ? void 0 : options.baseUrl, localPath);
297
+ init = {
298
+ method: 'DELETE'
299
+ };
300
+ settings = this._getSettings(options === null || options === void 0 ? void 0 : options.baseUrl);
301
+ _context3.next = 5;
302
+ return this.serverConnection.makeRequest(url, init, settings);
303
+ case 5:
304
+ response = _context3.sent;
305
+ if (!(response.status !== 204)) {
306
+ _context3.next = 11;
307
+ break;
308
+ }
309
+ _context3.next = 9;
310
+ return createResponseError(response);
311
+ case 9:
312
+ err = _context3.sent;
313
+ throw err;
314
+ case 11:
315
+ this.fileChangedEmitter.fire({
316
+ type: 'delete',
317
+ oldValue: {
318
+ path: localPath
319
+ },
320
+ newValue: null
321
+ });
322
+ case 12:
323
+ case "end":
324
+ return _context3.stop();
325
+ }
326
+ }, _callee3, this);
327
+ }));
328
+ function _delete(_x3, _x4) {
329
+ return _delete2.apply(this, arguments);
330
+ }
331
+ return _delete;
332
+ }()
333
+ /**
334
+ * Rename a file or directory.
335
+ *
336
+ * @param oldLocalPath - The original file path.
337
+ *
338
+ * @param newLocalPath - The new file path.
339
+ *
340
+ * @returns A promise which resolves with the new file contents model when
341
+ * the file is renamed.
342
+ *
343
+ * #### Notes
344
+ * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model.
345
+ */
346
+ )
347
+ }, {
348
+ key: "rename",
349
+ value: (function () {
350
+ var _rename = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(oldLocalPath, newLocalPath, options) {
351
+ var url, init, settings, response, err, data;
352
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
353
+ while (1) switch (_context4.prev = _context4.next) {
354
+ case 0:
355
+ url = this.getUrl(options === null || options === void 0 ? void 0 : options.baseUrl, oldLocalPath);
356
+ init = {
357
+ method: 'PATCH',
358
+ body: JSON.stringify({
359
+ path: newLocalPath
360
+ })
361
+ };
362
+ settings = this._getSettings(options === null || options === void 0 ? void 0 : options.baseUrl);
363
+ _context4.next = 5;
364
+ return this.serverConnection.makeRequest(url, init, settings);
365
+ case 5:
366
+ response = _context4.sent;
367
+ if (!(response.status !== 200)) {
368
+ _context4.next = 11;
369
+ break;
370
+ }
371
+ _context4.next = 9;
372
+ return createResponseError(response);
373
+ case 9:
374
+ err = _context4.sent;
375
+ throw err;
376
+ case 11:
377
+ _context4.next = 13;
378
+ return response.json();
379
+ case 13:
380
+ data = _context4.sent;
381
+ validate.validateContentsModel(data);
382
+ this.fileChangedEmitter.fire({
383
+ type: 'rename',
384
+ oldValue: {
385
+ path: oldLocalPath
386
+ },
387
+ newValue: data
388
+ });
389
+ return _context4.abrupt("return", data);
390
+ case 17:
391
+ case "end":
392
+ return _context4.stop();
393
+ }
394
+ }, _callee4, this);
395
+ }));
396
+ function rename(_x5, _x6, _x7) {
397
+ return _rename.apply(this, arguments);
398
+ }
399
+ return rename;
400
+ }()
401
+ /**
402
+ * Save a file.
403
+ *
404
+ * @param localPath - The desired file path.
405
+ *
406
+ * @param options - Optional overrides to the model.
407
+ *
408
+ * @returns A promise which resolves with the file content model when the
409
+ * file is saved.
410
+ *
411
+ * #### Notes
412
+ * Ensure that `model.content` is populated for the file.
413
+ *
414
+ * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model.
415
+ */
416
+ )
417
+ }, {
418
+ key: "save",
419
+ value: (function () {
420
+ var _save = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(localPath) {
421
+ var options,
422
+ url,
423
+ settings,
424
+ init,
425
+ response,
426
+ err,
427
+ data,
428
+ _args5 = arguments;
429
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
430
+ while (1) switch (_context5.prev = _context5.next) {
431
+ case 0:
432
+ options = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
433
+ url = this.getUrl(options.baseUrl, localPath);
434
+ settings = this._getSettings(options.baseUrl);
435
+ if (options) {
436
+ if (options.baseUrl) {
437
+ delete options.baseUrl;
438
+ }
439
+ }
440
+ init = {
441
+ method: 'PUT',
442
+ body: JSON.stringify(options)
443
+ };
444
+ _context5.next = 7;
445
+ return this.serverConnection.makeRequest(url, init, settings);
446
+ case 7:
447
+ response = _context5.sent;
448
+ if (!(response.status !== 200 && response.status !== 201)) {
449
+ _context5.next = 13;
450
+ break;
451
+ }
452
+ _context5.next = 11;
453
+ return createResponseError(response);
454
+ case 11:
455
+ err = _context5.sent;
456
+ throw err;
457
+ case 13:
458
+ _context5.next = 15;
459
+ return response.json();
460
+ case 15:
461
+ data = _context5.sent;
462
+ validate.validateContentsModel(data);
463
+ this.fileChangedEmitter.fire({
464
+ type: 'save',
465
+ oldValue: null,
466
+ newValue: data
467
+ });
468
+ return _context5.abrupt("return", data);
469
+ case 19:
470
+ case "end":
471
+ return _context5.stop();
472
+ }
473
+ }, _callee5, this);
474
+ }));
475
+ function save(_x8) {
476
+ return _save.apply(this, arguments);
477
+ }
478
+ return save;
479
+ }()
480
+ /**
481
+ * Copy a file into a given directory.
482
+ *
483
+ * @param localPath - The original file path.
484
+ *
485
+ * @param toDir - The destination directory path.
486
+ *
487
+ * @returns A promise which resolves with the new contents model when the
488
+ * file is copied.
489
+ *
490
+ * #### Notes
491
+ * The server will select the name of the copied file.
492
+ *
493
+ * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model.
494
+ */
495
+ )
496
+ }, {
497
+ key: "copy",
498
+ value: (function () {
499
+ var _copy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(fromFile, toDir, options) {
500
+ var url, init, settings, response, err, data;
501
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
502
+ while (1) switch (_context6.prev = _context6.next) {
503
+ case 0:
504
+ url = this.getUrl(options === null || options === void 0 ? void 0 : options.baseUrl, toDir);
505
+ init = {
506
+ method: 'POST',
507
+ body: JSON.stringify({
508
+ copy_from: fromFile
509
+ })
510
+ };
511
+ settings = this._getSettings(options === null || options === void 0 ? void 0 : options.baseUrl);
512
+ _context6.next = 5;
513
+ return this.serverConnection.makeRequest(url, init, settings);
514
+ case 5:
515
+ response = _context6.sent;
516
+ if (!(response.status !== 201)) {
517
+ _context6.next = 11;
518
+ break;
519
+ }
520
+ _context6.next = 9;
521
+ return createResponseError(response);
522
+ case 9:
523
+ err = _context6.sent;
524
+ throw err;
525
+ case 11:
526
+ _context6.next = 13;
527
+ return response.json();
528
+ case 13:
529
+ data = _context6.sent;
530
+ validate.validateContentsModel(data);
531
+ this.fileChangedEmitter.fire({
532
+ type: 'new',
533
+ oldValue: null,
534
+ newValue: data
535
+ });
536
+ return _context6.abrupt("return", data);
537
+ case 17:
538
+ case "end":
539
+ return _context6.stop();
540
+ }
541
+ }, _callee6, this);
542
+ }));
543
+ function copy(_x9, _x10, _x11) {
544
+ return _copy.apply(this, arguments);
545
+ }
546
+ return copy;
547
+ }()
548
+ /**
549
+ * Create a checkpoint for a file.
550
+ *
551
+ * @param localPath - The path of the file.
552
+ *
553
+ * @returns A promise which resolves with the new checkpoint model when the
554
+ * checkpoint is created.
555
+ *
556
+ * #### Notes
557
+ * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model.
558
+ */
559
+ )
560
+ }, {
561
+ key: "createCheckpoint",
562
+ value: (function () {
563
+ var _createCheckpoint = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(localPath, options) {
564
+ var url, init, settings, response, err, data;
565
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
566
+ while (1) switch (_context7.prev = _context7.next) {
567
+ case 0:
568
+ url = this.getUrl(options === null || options === void 0 ? void 0 : options.baseUrl, localPath, 'checkpoints');
569
+ init = {
570
+ method: 'POST'
571
+ };
572
+ settings = this._getSettings(options === null || options === void 0 ? void 0 : options.baseUrl);
573
+ _context7.next = 5;
574
+ return this.serverConnection.makeRequest(url, init, settings);
575
+ case 5:
576
+ response = _context7.sent;
577
+ if (!(response.status !== 201)) {
578
+ _context7.next = 11;
579
+ break;
580
+ }
581
+ _context7.next = 9;
582
+ return createResponseError(response);
583
+ case 9:
584
+ err = _context7.sent;
585
+ throw err;
586
+ case 11:
587
+ _context7.next = 13;
588
+ return response.json();
589
+ case 13:
590
+ data = _context7.sent;
591
+ validate.validateCheckpointModel(data);
592
+ return _context7.abrupt("return", data);
593
+ case 16:
594
+ case "end":
595
+ return _context7.stop();
596
+ }
597
+ }, _callee7, this);
598
+ }));
599
+ function createCheckpoint(_x12, _x13) {
600
+ return _createCheckpoint.apply(this, arguments);
601
+ }
602
+ return createCheckpoint;
603
+ }()
604
+ /**
605
+ * List available checkpoints for a file.
606
+ *
607
+ * @param localPath - The path of the file.
608
+ *
609
+ * @returns A promise which resolves with a list of checkpoint models for
610
+ * the file.
611
+ *
612
+ * #### Notes
613
+ * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model.
614
+ */
615
+ )
616
+ }, {
617
+ key: "listCheckpoints",
618
+ value: (function () {
619
+ var _listCheckpoints = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(localPath, options) {
620
+ var url, settings, response, err, data, i;
621
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
622
+ while (1) switch (_context8.prev = _context8.next) {
623
+ case 0:
624
+ url = this.getUrl(options === null || options === void 0 ? void 0 : options.baseUrl, localPath, 'checkpoints');
625
+ settings = this._getSettings(options === null || options === void 0 ? void 0 : options.baseUrl);
626
+ _context8.next = 4;
627
+ return this.serverConnection.makeRequest(url, {}, settings);
628
+ case 4:
629
+ response = _context8.sent;
630
+ if (!(response.status !== 200)) {
631
+ _context8.next = 10;
632
+ break;
633
+ }
634
+ _context8.next = 8;
635
+ return createResponseError(response);
636
+ case 8:
637
+ err = _context8.sent;
638
+ throw err;
639
+ case 10:
640
+ _context8.next = 12;
641
+ return response.json();
642
+ case 12:
643
+ data = _context8.sent;
644
+ if (Array.isArray(data)) {
645
+ _context8.next = 15;
646
+ break;
647
+ }
648
+ throw new Error('Invalid Checkpoint list');
649
+ case 15:
650
+ for (i = 0; i < data.length; i++) {
651
+ validate.validateCheckpointModel(data[i]);
652
+ }
653
+ return _context8.abrupt("return", data);
654
+ case 17:
655
+ case "end":
656
+ return _context8.stop();
657
+ }
658
+ }, _callee8, this);
659
+ }));
660
+ function listCheckpoints(_x14, _x15) {
661
+ return _listCheckpoints.apply(this, arguments);
662
+ }
663
+ return listCheckpoints;
664
+ }()
665
+ /**
666
+ * Restore a file to a known checkpoint state.
667
+ *
668
+ * @param localPath - The path of the file.
669
+ *
670
+ * @param checkpointID - The id of the checkpoint to restore.
671
+ *
672
+ * @returns A promise which resolves when the checkpoint is restored.
673
+ *
674
+ * #### Notes
675
+ * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents).
676
+ */
677
+ )
678
+ }, {
679
+ key: "restoreCheckpoint",
680
+ value: (function () {
681
+ var _restoreCheckpoint = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(localPath, checkpointID, options) {
682
+ var url, settings, init, response, err;
683
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
684
+ while (1) switch (_context9.prev = _context9.next) {
685
+ case 0:
686
+ url = this.getUrl(options === null || options === void 0 ? void 0 : options.baseUrl, localPath, 'checkpoints', checkpointID);
687
+ settings = this._getSettings(options === null || options === void 0 ? void 0 : options.baseUrl);
688
+ init = {
689
+ method: 'POST'
690
+ };
691
+ _context9.next = 5;
692
+ return this.serverConnection.makeRequest(url, init, settings);
693
+ case 5:
694
+ response = _context9.sent;
695
+ if (!(response.status !== 204)) {
696
+ _context9.next = 11;
697
+ break;
698
+ }
699
+ _context9.next = 9;
700
+ return createResponseError(response);
701
+ case 9:
702
+ err = _context9.sent;
703
+ throw err;
704
+ case 11:
705
+ case "end":
706
+ return _context9.stop();
707
+ }
708
+ }, _callee9, this);
709
+ }));
710
+ function restoreCheckpoint(_x16, _x17, _x18) {
711
+ return _restoreCheckpoint.apply(this, arguments);
712
+ }
713
+ return restoreCheckpoint;
714
+ }()
715
+ /**
716
+ * Delete a checkpoint for a file.
717
+ *
718
+ * @param localPath - The path of the file.
719
+ *
720
+ * @param checkpointID - The id of the checkpoint to delete.
721
+ *
722
+ * @returns A promise which resolves when the checkpoint is deleted.
723
+ *
724
+ * #### Notes
725
+ * Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents).
726
+ */
727
+ )
728
+ }, {
729
+ key: "deleteCheckpoint",
730
+ value: (function () {
731
+ var _deleteCheckpoint = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(localPath, checkpointID, options) {
732
+ var url, init, settings, response, err;
733
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
734
+ while (1) switch (_context10.prev = _context10.next) {
735
+ case 0:
736
+ url = this.getUrl(options === null || options === void 0 ? void 0 : options.baseUrl, localPath, 'checkpoints', checkpointID);
737
+ init = {
738
+ method: 'DELETE'
739
+ };
740
+ settings = this._getSettings(options === null || options === void 0 ? void 0 : options.baseUrl);
741
+ _context10.next = 5;
742
+ return this.serverConnection.makeRequest(url, init, settings);
743
+ case 5:
744
+ response = _context10.sent;
745
+ if (!(response.status !== 204)) {
746
+ _context10.next = 11;
747
+ break;
748
+ }
749
+ _context10.next = 9;
750
+ return createResponseError(response);
751
+ case 9:
752
+ err = _context10.sent;
753
+ throw err;
754
+ case 11:
755
+ case "end":
756
+ return _context10.stop();
757
+ }
758
+ }, _callee10, this);
759
+ }));
760
+ function deleteCheckpoint(_x19, _x20, _x21) {
761
+ return _deleteCheckpoint.apply(this, arguments);
762
+ }
763
+ return deleteCheckpoint;
764
+ }()
765
+ /**
766
+ * Get a REST url for a file given a path.
767
+ */
768
+ )
769
+ }, {
770
+ key: "getUrl",
771
+ value: function getUrl(base) {
772
+ var baseUrl = base;
773
+ if (!baseUrl) {
774
+ baseUrl = this.serverConnection.settings.baseUrl;
775
+ }
776
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
777
+ args[_key - 1] = arguments[_key];
778
+ }
779
+ var parts = args.map(function (path) {
780
+ return URLUtil.encodeParts(path);
781
+ });
782
+ return URLUtil.join.apply(URLUtil, [baseUrl, this.apiEndpoint].concat(_toConsumableArray(parts)));
783
+ }
784
+ }, {
785
+ key: "_getSettings",
786
+ value: function _getSettings(baseUrl) {
787
+ var settings = this.serverConnection.settings;
788
+ if (baseUrl) {
789
+ return _objectSpread(_objectSpread({}, settings), {}, {
790
+ baseUrl: baseUrl
791
+ });
792
+ }
793
+ return settings;
794
+ }
795
+ }]);
796
+ return Drive;
797
+ }(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "serverConnection", [_dec2], {
798
+ configurable: true,
799
+ enumerable: true,
800
+ writable: true,
801
+ initializer: null
802
+ })), _class2)) || _class);