@difizen/libro-kernel 0.0.2-alpha.0

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 +792 -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/index.less +0 -0
  28. package/es/kernel/comm.d.ts +92 -0
  29. package/es/kernel/comm.d.ts.map +1 -0
  30. package/es/kernel/comm.js +216 -0
  31. package/es/kernel/future.d.ts +178 -0
  32. package/es/kernel/future.d.ts.map +1 -0
  33. package/es/kernel/future.js +587 -0
  34. package/es/kernel/index.d.ts +8 -0
  35. package/es/kernel/index.d.ts.map +1 -0
  36. package/es/kernel/index.js +8 -0
  37. package/es/kernel/kernel-connection.d.ts +550 -0
  38. package/es/kernel/kernel-connection.d.ts.map +1 -0
  39. package/es/kernel/kernel-connection.js +1957 -0
  40. package/es/kernel/kernel-module.d.ts +3 -0
  41. package/es/kernel/kernel-module.d.ts.map +1 -0
  42. package/es/kernel/kernel-module.js +32 -0
  43. package/es/kernel/libro-kernel-manager.d.ts +69 -0
  44. package/es/kernel/libro-kernel-manager.d.ts.map +1 -0
  45. package/es/kernel/libro-kernel-manager.js +349 -0
  46. package/es/kernel/libro-kernel-protocol.d.ts +675 -0
  47. package/es/kernel/libro-kernel-protocol.d.ts.map +1 -0
  48. package/es/kernel/libro-kernel-protocol.js +60 -0
  49. package/es/kernel/libro-kernel-utils.d.ts +95 -0
  50. package/es/kernel/libro-kernel-utils.d.ts.map +1 -0
  51. package/es/kernel/libro-kernel-utils.js +130 -0
  52. package/es/kernel/libro-kernel.d.ts +14 -0
  53. package/es/kernel/libro-kernel.d.ts.map +1 -0
  54. package/es/kernel/libro-kernel.js +54 -0
  55. package/es/kernel/messages.d.ts +845 -0
  56. package/es/kernel/messages.d.ts.map +1 -0
  57. package/es/kernel/messages.js +457 -0
  58. package/es/kernel/restapi.d.ts +78 -0
  59. package/es/kernel/restapi.d.ts.map +1 -0
  60. package/es/kernel/restapi.js +367 -0
  61. package/es/kernel/serialize.d.ts +10 -0
  62. package/es/kernel/serialize.d.ts.map +1 -0
  63. package/es/kernel/serialize.js +214 -0
  64. package/es/kernel/validate.d.ts +15 -0
  65. package/es/kernel/validate.d.ts.map +1 -0
  66. package/es/kernel/validate.js +125 -0
  67. package/es/kernelspec/index.d.ts +5 -0
  68. package/es/kernelspec/index.d.ts.map +1 -0
  69. package/es/kernelspec/index.js +4 -0
  70. package/es/kernelspec/kernelspec-module.d.ts +3 -0
  71. package/es/kernelspec/kernelspec-module.d.ts.map +1 -0
  72. package/es/kernelspec/kernelspec-module.js +4 -0
  73. package/es/kernelspec/kernelspec.d.ts +33 -0
  74. package/es/kernelspec/kernelspec.d.ts.map +1 -0
  75. package/es/kernelspec/kernelspec.js +1 -0
  76. package/es/kernelspec/manager.d.ts +81 -0
  77. package/es/kernelspec/manager.d.ts.map +1 -0
  78. package/es/kernelspec/manager.js +248 -0
  79. package/es/kernelspec/restapi.d.ts +71 -0
  80. package/es/kernelspec/restapi.d.ts.map +1 -0
  81. package/es/kernelspec/restapi.js +107 -0
  82. package/es/kernelspec/validate.d.ts +10 -0
  83. package/es/kernelspec/validate.d.ts.map +1 -0
  84. package/es/kernelspec/validate.js +69 -0
  85. package/es/libro-kernel-connection-manager.d.ts +19 -0
  86. package/es/libro-kernel-connection-manager.d.ts.map +1 -0
  87. package/es/libro-kernel-connection-manager.js +142 -0
  88. package/es/module.d.ts +3 -0
  89. package/es/module.d.ts.map +1 -0
  90. package/es/module.js +9 -0
  91. package/es/page-config.d.ts +36 -0
  92. package/es/page-config.d.ts.map +1 -0
  93. package/es/page-config.js +129 -0
  94. package/es/protocol.d.ts +13 -0
  95. package/es/protocol.d.ts.map +1 -0
  96. package/es/protocol.js +8 -0
  97. package/es/server/connection-error.d.ts +36 -0
  98. package/es/server/connection-error.d.ts.map +1 -0
  99. package/es/server/connection-error.js +109 -0
  100. package/es/server/index.d.ts +6 -0
  101. package/es/server/index.d.ts.map +1 -0
  102. package/es/server/index.js +5 -0
  103. package/es/server/server-connection-protocol.d.ts +49 -0
  104. package/es/server/server-connection-protocol.d.ts.map +1 -0
  105. package/es/server/server-connection-protocol.js +0 -0
  106. package/es/server/server-connection.d.ts +25 -0
  107. package/es/server/server-connection.d.ts.map +1 -0
  108. package/es/server/server-connection.js +159 -0
  109. package/es/server/server-manager.d.ts +22 -0
  110. package/es/server/server-manager.d.ts.map +1 -0
  111. package/es/server/server-manager.js +163 -0
  112. package/es/server/server-module.d.ts +3 -0
  113. package/es/server/server-module.d.ts.map +1 -0
  114. package/es/server/server-module.js +4 -0
  115. package/es/session/index.d.ts +5 -0
  116. package/es/session/index.d.ts.map +1 -0
  117. package/es/session/index.js +4 -0
  118. package/es/session/libro-session-manager.d.ts +71 -0
  119. package/es/session/libro-session-manager.d.ts.map +1 -0
  120. package/es/session/libro-session-manager.js +539 -0
  121. package/es/session/libro-session-protocol.d.ts +50 -0
  122. package/es/session/libro-session-protocol.d.ts.map +1 -0
  123. package/es/session/libro-session-protocol.js +21 -0
  124. package/es/session/libro-session.d.ts +12 -0
  125. package/es/session/libro-session.d.ts.map +1 -0
  126. package/es/session/libro-session.js +19 -0
  127. package/es/session/restapi.d.ts +28 -0
  128. package/es/session/restapi.d.ts.map +1 -0
  129. package/es/session/restapi.js +214 -0
  130. package/es/session/session-module.d.ts +3 -0
  131. package/es/session/session-module.d.ts.map +1 -0
  132. package/es/session/session-module.js +18 -0
  133. package/es/session/validate.d.ts +14 -0
  134. package/es/session/validate.d.ts.map +1 -0
  135. package/es/session/validate.js +37 -0
  136. package/es/utils.d.ts +4 -0
  137. package/es/utils.d.ts.map +1 -0
  138. package/es/utils.js +29 -0
  139. package/es/validate-property.d.ts +2 -0
  140. package/es/validate-property.d.ts.map +1 -0
  141. package/es/validate-property.js +35 -0
  142. package/package.json +62 -0
  143. package/src/basemanager.ts +133 -0
  144. package/src/contents/contents-drive.ts +495 -0
  145. package/src/contents/contents-manager.ts +465 -0
  146. package/src/contents/contents-module.ts +6 -0
  147. package/src/contents/contents-protocol.ts +604 -0
  148. package/src/contents/index.ts +5 -0
  149. package/src/contents/validate.ts +29 -0
  150. package/src/index.tsx +9 -0
  151. package/src/kernel/comm.ts +220 -0
  152. package/src/kernel/future.ts +474 -0
  153. package/src/kernel/index.ts +7 -0
  154. package/src/kernel/kernel-connection.ts +1770 -0
  155. package/src/kernel/kernel-module.ts +50 -0
  156. package/src/kernel/libro-kernel-manager.ts +199 -0
  157. package/src/kernel/libro-kernel-protocol.ts +858 -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 +173 -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 +73 -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 +76 -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 +377 -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,551 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ var _dec, _class;
3
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
5
+ 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; }
6
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
7
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
10
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
12
+ 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."); }
13
+ 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); }
14
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
15
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
16
+ 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; }
17
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18
+ 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); } }
19
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
20
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
21
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
22
+ import { PathExt } from '@difizen/libro-common';
23
+ import { inject, singleton } from '@difizen/mana-app';
24
+ import { Emitter } from '@difizen/mana-app';
25
+ import { Drive } from "./contents-drive.js";
26
+ /**
27
+ * A contents manager that passes file operations to the server.
28
+ * Multiple servers implementing the `IContentsDrive` interface can be
29
+ * attached to the contents manager, so that the same session can
30
+ * perform file operations on multiple backends.
31
+ *
32
+ * This includes checkpointing with the normal file operations.
33
+ */
34
+ export var ContentsManager = (_dec = singleton(), _dec(_class = /*#__PURE__*/function () {
35
+ function ContentsManager(defaultDrive) {
36
+ var _this = this;
37
+ _classCallCheck(this, ContentsManager);
38
+ this._isDisposed = false;
39
+ this.additionalDrives = new Map();
40
+ this.fileChangedEmitter = new Emitter();
41
+ this.defaultDrive = defaultDrive;
42
+ this.defaultDrive.fileChanged(function (args) {
43
+ return _this.onFileChanged(_this.defaultDrive, args);
44
+ });
45
+ }
46
+
47
+ /**
48
+ * The server settings associated with the manager.
49
+ */
50
+ // serverSettings: ISettings;
51
+
52
+ /**
53
+ * A signal emitted when a file operation takes place.
54
+ */
55
+ ContentsManager = inject(Drive)(ContentsManager, undefined, 0) || ContentsManager;
56
+ _createClass(ContentsManager, [{
57
+ key: "fileChanged",
58
+ get: function get() {
59
+ // return this._fileChanged;
60
+ return this.fileChangedEmitter.event;
61
+ }
62
+
63
+ /**
64
+ * Test whether the manager has been disposed.
65
+ */
66
+ }, {
67
+ key: "isDisposed",
68
+ get: function get() {
69
+ return this._isDisposed;
70
+ }
71
+
72
+ /**
73
+ * Dispose of the resources held by the manager.
74
+ */
75
+ }, {
76
+ key: "dispose",
77
+ value: function dispose() {
78
+ if (this.isDisposed) {
79
+ return;
80
+ }
81
+ this._isDisposed = true;
82
+ this.fileChangedEmitter.dispose();
83
+ }
84
+
85
+ /**
86
+ * Add an `IContentsDrive` to the manager.
87
+ */
88
+ }, {
89
+ key: "addDrive",
90
+ value: function addDrive(drive) {
91
+ var _this2 = this;
92
+ this.additionalDrives.set(drive.name, drive);
93
+ drive.fileChanged(function (args) {
94
+ return _this2.onFileChanged(drive, args);
95
+ });
96
+ }
97
+
98
+ /**
99
+ * Given a path, get a ModelDB.IFactory from the
100
+ * relevant backend. Returns `undefined` if the backend
101
+ * does not provide one.
102
+ */
103
+ // getModelDBFactory(path: string): ModelDB.IFactory | null {
104
+ // const [drive] = this.driveForPath(path);
105
+ // return drive?.modelDBFactory ?? null;
106
+ // }
107
+
108
+ /**
109
+ * Given a path of the form `drive:local/portion/of/it.txt`
110
+ * get the local part of it.
111
+ *
112
+ * @param path: the path.
113
+ *
114
+ * @returns The local part of the path.
115
+ */
116
+ }, {
117
+ key: "localPath",
118
+ value: function localPath(path) {
119
+ var parts = path.split('/');
120
+ var firstParts = parts[0].split(':');
121
+ if (firstParts.length === 1 || !this.additionalDrives.has(firstParts[0])) {
122
+ return PathExt.removeSlash(path);
123
+ }
124
+ return PathExt.join.apply(PathExt, [firstParts.slice(1).join(':')].concat(_toConsumableArray(parts.slice(1))));
125
+ }
126
+
127
+ /**
128
+ * Normalize a global path. Reduces '..' and '.' parts, and removes
129
+ * leading slashes from the local part of the path, while retaining
130
+ * the drive name if it exists.
131
+ *
132
+ * @param path: the path.
133
+ *
134
+ * @returns The normalized path.
135
+ */
136
+ }, {
137
+ key: "normalize",
138
+ value: function normalize(path) {
139
+ var parts = path.split(':');
140
+ if (parts.length === 1) {
141
+ return PathExt.normalize(path);
142
+ }
143
+ return "".concat(parts[0], ":").concat(PathExt.normalize(parts.slice(1).join(':')));
144
+ }
145
+
146
+ /**
147
+ * Resolve a global path, starting from the root path. Behaves like
148
+ * posix-path.resolve, with 3 differences:
149
+ * - will never prepend cwd
150
+ * - if root has a drive name, the result is prefixed with "<drive>:"
151
+ * - before adding drive name, leading slashes are removed
152
+ *
153
+ * @param path: the path.
154
+ *
155
+ * @returns The normalized path.
156
+ */
157
+ }, {
158
+ key: "resolvePath",
159
+ value: function resolvePath(root, path) {
160
+ var driveName = this.driveName(root);
161
+ var localPath = this.localPath(root);
162
+ var resolved = PathExt.resolve('/', localPath, path);
163
+ return driveName ? "".concat(driveName, ":").concat(resolved) : resolved;
164
+ }
165
+
166
+ /**
167
+ * Given a path of the form `drive:local/portion/of/it.txt`
168
+ * get the name of the drive. If the path is missing
169
+ * a drive portion, returns an empty string.
170
+ *
171
+ * @param path: the path.
172
+ *
173
+ * @returns The drive name for the path, or the empty string.
174
+ */
175
+ }, {
176
+ key: "driveName",
177
+ value: function driveName(path) {
178
+ var parts = path.split('/');
179
+ var firstParts = parts[0].split(':');
180
+ if (firstParts.length === 1) {
181
+ return '';
182
+ }
183
+ if (this.additionalDrives.has(firstParts[0])) {
184
+ return firstParts[0];
185
+ }
186
+ return '';
187
+ }
188
+
189
+ /**
190
+ * Get a file or directory.
191
+ *
192
+ * @param path: The path to the file.
193
+ *
194
+ * @param options: The options used to fetch the file.
195
+ *
196
+ * @returns A promise which resolves with the file content.
197
+ */
198
+ }, {
199
+ key: "get",
200
+ value: function get(path, options) {
201
+ var _this3 = this;
202
+ var _this$driveForPath = this.driveForPath(path),
203
+ _this$driveForPath2 = _slicedToArray(_this$driveForPath, 2),
204
+ drive = _this$driveForPath2[0],
205
+ localPath = _this$driveForPath2[1];
206
+ return drive.get(localPath, options).then(function (contentsModel) {
207
+ var listing = [];
208
+ if (contentsModel.type === 'directory' && contentsModel.content) {
209
+ var _iterator = _createForOfIteratorHelper(contentsModel.content),
210
+ _step;
211
+ try {
212
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
213
+ var item = _step.value;
214
+ listing.push(_objectSpread(_objectSpread({}, item), {}, {
215
+ path: _this3.toGlobalPath(drive, item.path)
216
+ }));
217
+ }
218
+ } catch (err) {
219
+ _iterator.e(err);
220
+ } finally {
221
+ _iterator.f();
222
+ }
223
+ return _objectSpread(_objectSpread({}, contentsModel), {}, {
224
+ path: _this3.toGlobalPath(drive, localPath),
225
+ content: listing
226
+ });
227
+ } else {
228
+ return _objectSpread(_objectSpread({}, contentsModel), {}, {
229
+ path: _this3.toGlobalPath(drive, localPath)
230
+ });
231
+ }
232
+ });
233
+ }
234
+
235
+ /**
236
+ * Get an encoded download url given a file path.
237
+ *
238
+ * @param path - An absolute POSIX file path on the server.
239
+ *
240
+ * #### Notes
241
+ * It is expected that the path contains no relative paths.
242
+ *
243
+ * The returned URL may include a query parameter.
244
+ */
245
+ }, {
246
+ key: "getDownloadUrl",
247
+ value: function getDownloadUrl(path, options) {
248
+ var _this$driveForPath3 = this.driveForPath(path),
249
+ _this$driveForPath4 = _slicedToArray(_this$driveForPath3, 2),
250
+ drive = _this$driveForPath4[0],
251
+ localPath = _this$driveForPath4[1];
252
+ return drive.getDownloadUrl(localPath, options);
253
+ }
254
+
255
+ /**
256
+ * Create a new untitled file or directory in the specified directory path.
257
+ *
258
+ * @param options: The options used to create the file.
259
+ *
260
+ * @returns A promise which resolves with the created file content when the
261
+ * file is created.
262
+ */
263
+ }, {
264
+ key: "newUntitled",
265
+ value: function newUntitled() {
266
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
267
+ if (options.path) {
268
+ var globalPath = this.normalize(options.path);
269
+ var _this$driveForPath5 = this.driveForPath(globalPath),
270
+ _this$driveForPath6 = _slicedToArray(_this$driveForPath5, 2),
271
+ drive = _this$driveForPath6[0],
272
+ localPath = _this$driveForPath6[1];
273
+ return drive.newUntitled(_objectSpread(_objectSpread({}, options), {}, {
274
+ path: localPath
275
+ })).then(function (contentsModel) {
276
+ return _objectSpread(_objectSpread({}, contentsModel), {}, {
277
+ path: PathExt.join(globalPath, contentsModel.name)
278
+ });
279
+ });
280
+ } else {
281
+ return this.defaultDrive.newUntitled(options);
282
+ }
283
+ }
284
+
285
+ /**
286
+ * Delete a file.
287
+ *
288
+ * @param path - The path to the file.
289
+ *
290
+ * @returns A promise which resolves when the file is deleted.
291
+ */
292
+ }, {
293
+ key: "delete",
294
+ value: function _delete(path, options) {
295
+ var _this$driveForPath7 = this.driveForPath(path),
296
+ _this$driveForPath8 = _slicedToArray(_this$driveForPath7, 2),
297
+ drive = _this$driveForPath8[0],
298
+ localPath = _this$driveForPath8[1];
299
+ return drive.delete(localPath, options);
300
+ }
301
+
302
+ /**
303
+ * Rename a file or directory.
304
+ *
305
+ * @param path - The original file path.
306
+ *
307
+ * @param newPath - The new file path.
308
+ *
309
+ * @returns A promise which resolves with the new file contents model when
310
+ * the file is renamed.
311
+ */
312
+ }, {
313
+ key: "rename",
314
+ value: function rename(path, newPath, options) {
315
+ var _this4 = this;
316
+ var _this$driveForPath9 = this.driveForPath(path),
317
+ _this$driveForPath10 = _slicedToArray(_this$driveForPath9, 2),
318
+ drive1 = _this$driveForPath10[0],
319
+ path1 = _this$driveForPath10[1];
320
+ var _this$driveForPath11 = this.driveForPath(newPath),
321
+ _this$driveForPath12 = _slicedToArray(_this$driveForPath11, 2),
322
+ drive2 = _this$driveForPath12[0],
323
+ path2 = _this$driveForPath12[1];
324
+ if (drive1 !== drive2) {
325
+ throw Error('ContentsManager: renaming files must occur within a Drive');
326
+ }
327
+ return drive1.rename(path1, path2, options).then(function (contentsModel) {
328
+ return _objectSpread(_objectSpread({}, contentsModel), {}, {
329
+ path: _this4.toGlobalPath(drive1, path2)
330
+ });
331
+ });
332
+ }
333
+
334
+ /**
335
+ * Save a file.
336
+ *
337
+ * @param path - The desired file path.
338
+ *
339
+ * @param options - Optional overrides to the model.
340
+ *
341
+ * @returns A promise which resolves with the file content model when the
342
+ * file is saved.
343
+ *
344
+ * #### Notes
345
+ * Ensure that `model.content` is populated for the file.
346
+ */
347
+ }, {
348
+ key: "save",
349
+ value: function save(path) {
350
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
351
+ var globalPath = this.normalize(path);
352
+ var _this$driveForPath13 = this.driveForPath(path),
353
+ _this$driveForPath14 = _slicedToArray(_this$driveForPath13, 2),
354
+ drive = _this$driveForPath14[0],
355
+ localPath = _this$driveForPath14[1];
356
+ return drive.save(localPath, _objectSpread(_objectSpread({}, options), {}, {
357
+ path: localPath
358
+ })).then(function (contentsModel) {
359
+ return _objectSpread(_objectSpread({}, contentsModel), {}, {
360
+ path: globalPath
361
+ });
362
+ });
363
+ }
364
+
365
+ /**
366
+ * Copy a file into a given directory.
367
+ *
368
+ * @param path - The original file path.
369
+ *
370
+ * @param toDir - The destination directory path.
371
+ *
372
+ * @returns A promise which resolves with the new contents model when the
373
+ * file is copied.
374
+ *
375
+ * #### Notes
376
+ * The server will select the name of the copied file.
377
+ */
378
+ }, {
379
+ key: "copy",
380
+ value: function copy(fromFile, toDir, options) {
381
+ var _this5 = this;
382
+ var _this$driveForPath15 = this.driveForPath(fromFile),
383
+ _this$driveForPath16 = _slicedToArray(_this$driveForPath15, 2),
384
+ drive1 = _this$driveForPath16[0],
385
+ path1 = _this$driveForPath16[1];
386
+ var _this$driveForPath17 = this.driveForPath(toDir),
387
+ _this$driveForPath18 = _slicedToArray(_this$driveForPath17, 2),
388
+ drive2 = _this$driveForPath18[0],
389
+ path2 = _this$driveForPath18[1];
390
+ if (drive1 === drive2) {
391
+ return drive1.copy(path1, path2, options).then(function (contentsModel) {
392
+ return _objectSpread(_objectSpread({}, contentsModel), {}, {
393
+ path: _this5.toGlobalPath(drive1, contentsModel.path)
394
+ });
395
+ });
396
+ } else {
397
+ throw Error('Copying files between drives is not currently implemented');
398
+ }
399
+ }
400
+
401
+ /**
402
+ * Create a checkpoint for a file.
403
+ *
404
+ * @param path - The path of the file.
405
+ *
406
+ * @returns A promise which resolves with the new checkpoint model when the
407
+ * checkpoint is created.
408
+ */
409
+ }, {
410
+ key: "createCheckpoint",
411
+ value: function createCheckpoint(path, options) {
412
+ var _this$driveForPath19 = this.driveForPath(path),
413
+ _this$driveForPath20 = _slicedToArray(_this$driveForPath19, 2),
414
+ drive = _this$driveForPath20[0],
415
+ localPath = _this$driveForPath20[1];
416
+ return drive.createCheckpoint(localPath, options);
417
+ }
418
+
419
+ /**
420
+ * List available checkpoints for a file.
421
+ *
422
+ * @param path - The path of the file.
423
+ *
424
+ * @returns A promise which resolves with a list of checkpoint models for
425
+ * the file.
426
+ */
427
+ }, {
428
+ key: "listCheckpoints",
429
+ value: function listCheckpoints(path, options) {
430
+ var _this$driveForPath21 = this.driveForPath(path),
431
+ _this$driveForPath22 = _slicedToArray(_this$driveForPath21, 2),
432
+ drive = _this$driveForPath22[0],
433
+ localPath = _this$driveForPath22[1];
434
+ return drive.listCheckpoints(localPath, options);
435
+ }
436
+
437
+ /**
438
+ * Restore a file to a known checkpoint state.
439
+ *
440
+ * @param path - The path of the file.
441
+ *
442
+ * @param checkpointID - The id of the checkpoint to restore.
443
+ *
444
+ * @returns A promise which resolves when the checkpoint is restored.
445
+ */
446
+ }, {
447
+ key: "restoreCheckpoint",
448
+ value: function restoreCheckpoint(path, checkpointID, options) {
449
+ var _this$driveForPath23 = this.driveForPath(path),
450
+ _this$driveForPath24 = _slicedToArray(_this$driveForPath23, 2),
451
+ drive = _this$driveForPath24[0],
452
+ localPath = _this$driveForPath24[1];
453
+ return drive.restoreCheckpoint(localPath, checkpointID, options);
454
+ }
455
+
456
+ /**
457
+ * Delete a checkpoint for a file.
458
+ *
459
+ * @param path - The path of the file.
460
+ *
461
+ * @param checkpointID - The id of the checkpoint to delete.
462
+ *
463
+ * @returns A promise which resolves when the checkpoint is deleted.
464
+ */
465
+ }, {
466
+ key: "deleteCheckpoint",
467
+ value: function deleteCheckpoint(path, checkpointID, options) {
468
+ var _this$driveForPath25 = this.driveForPath(path),
469
+ _this$driveForPath26 = _slicedToArray(_this$driveForPath25, 2),
470
+ drive = _this$driveForPath26[0],
471
+ localPath = _this$driveForPath26[1];
472
+ return drive.deleteCheckpoint(localPath, checkpointID, options);
473
+ }
474
+
475
+ /**
476
+ * Given a drive and a local path, construct a fully qualified
477
+ * path. The inverse of `driveForPath`.
478
+ *
479
+ * @param drive: an `IContentsDrive`.
480
+ *
481
+ * @param localPath: the local path on the drive.
482
+ *
483
+ * @returns the fully qualified path.
484
+ */
485
+ }, {
486
+ key: "toGlobalPath",
487
+ value: function toGlobalPath(drive, localPath) {
488
+ if (drive === this.defaultDrive) {
489
+ return PathExt.removeSlash(localPath);
490
+ } else {
491
+ return "".concat(drive.name, ":").concat(PathExt.removeSlash(localPath));
492
+ }
493
+ }
494
+
495
+ /**
496
+ * Given a path, get the `IContentsDrive to which it refers,
497
+ * where the path satisfies the pattern
498
+ * `'driveName:path/to/file'`. If there is no `driveName`
499
+ * prepended to the path, it returns the default drive.
500
+ *
501
+ * @param path: a path to a file.
502
+ *
503
+ * @returns A tuple containing an `IContentsDrive` object for the path,
504
+ * and a local path for that drive.
505
+ */
506
+ }, {
507
+ key: "driveForPath",
508
+ value: function driveForPath(path) {
509
+ var driveName = this.driveName(path);
510
+ var localPath = this.localPath(path);
511
+ if (driveName) {
512
+ return [this.additionalDrives.get(driveName), localPath];
513
+ } else {
514
+ return [this.defaultDrive, localPath];
515
+ }
516
+ }
517
+
518
+ /**
519
+ * Respond to fileChanged signals from the drives attached to
520
+ * the manager. This prepends the drive name to the path if necessary,
521
+ * and then forwards the signal.
522
+ */
523
+ }, {
524
+ key: "onFileChanged",
525
+ value: function onFileChanged(sender, args) {
526
+ if (sender === this.defaultDrive) {
527
+ this.fileChangedEmitter.fire(args);
528
+ } else {
529
+ var _args$newValue, _args$oldValue;
530
+ var newValue = null;
531
+ var oldValue = null;
532
+ if ((_args$newValue = args.newValue) !== null && _args$newValue !== void 0 && _args$newValue.path) {
533
+ newValue = _objectSpread(_objectSpread({}, args.newValue), {}, {
534
+ path: this.toGlobalPath(sender, args.newValue.path)
535
+ });
536
+ }
537
+ if ((_args$oldValue = args.oldValue) !== null && _args$oldValue !== void 0 && _args$oldValue.path) {
538
+ oldValue = _objectSpread(_objectSpread({}, args.oldValue), {}, {
539
+ path: this.toGlobalPath(sender, args.oldValue.path)
540
+ });
541
+ }
542
+ this.fileChangedEmitter.fire({
543
+ type: args.type,
544
+ newValue: newValue,
545
+ oldValue: oldValue
546
+ });
547
+ }
548
+ }
549
+ }]);
550
+ return ContentsManager;
551
+ }()) || _class);
@@ -0,0 +1,3 @@
1
+ import { ManaModule } from '@difizen/mana-app';
2
+ export declare const LibroContentsModule: ManaModule;
3
+ //# sourceMappingURL=contents-module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contents-module.d.ts","sourceRoot":"","sources":["../../src/contents/contents-module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAK/C,eAAO,MAAM,mBAAmB,YAAuD,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { ManaModule } from '@difizen/mana-app';
2
+ import { Drive } from "./contents-drive.js";
3
+ import { ContentsManager } from "./contents-manager.js";
4
+ export var LibroContentsModule = ManaModule.create().register(Drive, ContentsManager);