@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.
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/es/basemanager.d.ts +94 -0
- package/es/basemanager.d.ts.map +1 -0
- package/es/basemanager.js +110 -0
- package/es/contents/contents-drive.d.ts +189 -0
- package/es/contents/contents-drive.d.ts.map +1 -0
- package/es/contents/contents-drive.js +792 -0
- package/es/contents/contents-manager.d.ts +229 -0
- package/es/contents/contents-manager.d.ts.map +1 -0
- package/es/contents/contents-manager.js +551 -0
- package/es/contents/contents-module.d.ts +3 -0
- package/es/contents/contents-module.d.ts.map +1 -0
- package/es/contents/contents-module.js +4 -0
- package/es/contents/contents-protocol.d.ts +487 -0
- package/es/contents/contents-protocol.d.ts.map +1 -0
- package/es/contents/contents-protocol.js +1 -0
- package/es/contents/index.d.ts +6 -0
- package/es/contents/index.d.ts.map +1 -0
- package/es/contents/index.js +5 -0
- package/es/contents/validate.d.ts +10 -0
- package/es/contents/validate.d.ts.map +1 -0
- package/es/contents/validate.js +22 -0
- package/es/index.d.ts +10 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +9 -0
- package/es/index.less +0 -0
- package/es/kernel/comm.d.ts +92 -0
- package/es/kernel/comm.d.ts.map +1 -0
- package/es/kernel/comm.js +216 -0
- package/es/kernel/future.d.ts +178 -0
- package/es/kernel/future.d.ts.map +1 -0
- package/es/kernel/future.js +587 -0
- package/es/kernel/index.d.ts +8 -0
- package/es/kernel/index.d.ts.map +1 -0
- package/es/kernel/index.js +8 -0
- package/es/kernel/kernel-connection.d.ts +550 -0
- package/es/kernel/kernel-connection.d.ts.map +1 -0
- package/es/kernel/kernel-connection.js +1957 -0
- package/es/kernel/kernel-module.d.ts +3 -0
- package/es/kernel/kernel-module.d.ts.map +1 -0
- package/es/kernel/kernel-module.js +32 -0
- package/es/kernel/libro-kernel-manager.d.ts +69 -0
- package/es/kernel/libro-kernel-manager.d.ts.map +1 -0
- package/es/kernel/libro-kernel-manager.js +349 -0
- package/es/kernel/libro-kernel-protocol.d.ts +675 -0
- package/es/kernel/libro-kernel-protocol.d.ts.map +1 -0
- package/es/kernel/libro-kernel-protocol.js +60 -0
- package/es/kernel/libro-kernel-utils.d.ts +95 -0
- package/es/kernel/libro-kernel-utils.d.ts.map +1 -0
- package/es/kernel/libro-kernel-utils.js +130 -0
- package/es/kernel/libro-kernel.d.ts +14 -0
- package/es/kernel/libro-kernel.d.ts.map +1 -0
- package/es/kernel/libro-kernel.js +54 -0
- package/es/kernel/messages.d.ts +845 -0
- package/es/kernel/messages.d.ts.map +1 -0
- package/es/kernel/messages.js +457 -0
- package/es/kernel/restapi.d.ts +78 -0
- package/es/kernel/restapi.d.ts.map +1 -0
- package/es/kernel/restapi.js +367 -0
- package/es/kernel/serialize.d.ts +10 -0
- package/es/kernel/serialize.d.ts.map +1 -0
- package/es/kernel/serialize.js +214 -0
- package/es/kernel/validate.d.ts +15 -0
- package/es/kernel/validate.d.ts.map +1 -0
- package/es/kernel/validate.js +125 -0
- package/es/kernelspec/index.d.ts +5 -0
- package/es/kernelspec/index.d.ts.map +1 -0
- package/es/kernelspec/index.js +4 -0
- package/es/kernelspec/kernelspec-module.d.ts +3 -0
- package/es/kernelspec/kernelspec-module.d.ts.map +1 -0
- package/es/kernelspec/kernelspec-module.js +4 -0
- package/es/kernelspec/kernelspec.d.ts +33 -0
- package/es/kernelspec/kernelspec.d.ts.map +1 -0
- package/es/kernelspec/kernelspec.js +1 -0
- package/es/kernelspec/manager.d.ts +81 -0
- package/es/kernelspec/manager.d.ts.map +1 -0
- package/es/kernelspec/manager.js +248 -0
- package/es/kernelspec/restapi.d.ts +71 -0
- package/es/kernelspec/restapi.d.ts.map +1 -0
- package/es/kernelspec/restapi.js +107 -0
- package/es/kernelspec/validate.d.ts +10 -0
- package/es/kernelspec/validate.d.ts.map +1 -0
- package/es/kernelspec/validate.js +69 -0
- package/es/libro-kernel-connection-manager.d.ts +19 -0
- package/es/libro-kernel-connection-manager.d.ts.map +1 -0
- package/es/libro-kernel-connection-manager.js +142 -0
- package/es/module.d.ts +3 -0
- package/es/module.d.ts.map +1 -0
- package/es/module.js +9 -0
- package/es/page-config.d.ts +36 -0
- package/es/page-config.d.ts.map +1 -0
- package/es/page-config.js +129 -0
- package/es/protocol.d.ts +13 -0
- package/es/protocol.d.ts.map +1 -0
- package/es/protocol.js +8 -0
- package/es/server/connection-error.d.ts +36 -0
- package/es/server/connection-error.d.ts.map +1 -0
- package/es/server/connection-error.js +109 -0
- package/es/server/index.d.ts +6 -0
- package/es/server/index.d.ts.map +1 -0
- package/es/server/index.js +5 -0
- package/es/server/server-connection-protocol.d.ts +49 -0
- package/es/server/server-connection-protocol.d.ts.map +1 -0
- package/es/server/server-connection-protocol.js +0 -0
- package/es/server/server-connection.d.ts +25 -0
- package/es/server/server-connection.d.ts.map +1 -0
- package/es/server/server-connection.js +159 -0
- package/es/server/server-manager.d.ts +22 -0
- package/es/server/server-manager.d.ts.map +1 -0
- package/es/server/server-manager.js +163 -0
- package/es/server/server-module.d.ts +3 -0
- package/es/server/server-module.d.ts.map +1 -0
- package/es/server/server-module.js +4 -0
- package/es/session/index.d.ts +5 -0
- package/es/session/index.d.ts.map +1 -0
- package/es/session/index.js +4 -0
- package/es/session/libro-session-manager.d.ts +71 -0
- package/es/session/libro-session-manager.d.ts.map +1 -0
- package/es/session/libro-session-manager.js +539 -0
- package/es/session/libro-session-protocol.d.ts +50 -0
- package/es/session/libro-session-protocol.d.ts.map +1 -0
- package/es/session/libro-session-protocol.js +21 -0
- package/es/session/libro-session.d.ts +12 -0
- package/es/session/libro-session.d.ts.map +1 -0
- package/es/session/libro-session.js +19 -0
- package/es/session/restapi.d.ts +28 -0
- package/es/session/restapi.d.ts.map +1 -0
- package/es/session/restapi.js +214 -0
- package/es/session/session-module.d.ts +3 -0
- package/es/session/session-module.d.ts.map +1 -0
- package/es/session/session-module.js +18 -0
- package/es/session/validate.d.ts +14 -0
- package/es/session/validate.d.ts.map +1 -0
- package/es/session/validate.js +37 -0
- package/es/utils.d.ts +4 -0
- package/es/utils.d.ts.map +1 -0
- package/es/utils.js +29 -0
- package/es/validate-property.d.ts +2 -0
- package/es/validate-property.d.ts.map +1 -0
- package/es/validate-property.js +35 -0
- package/package.json +62 -0
- package/src/basemanager.ts +133 -0
- package/src/contents/contents-drive.ts +495 -0
- package/src/contents/contents-manager.ts +465 -0
- package/src/contents/contents-module.ts +6 -0
- package/src/contents/contents-protocol.ts +604 -0
- package/src/contents/index.ts +5 -0
- package/src/contents/validate.ts +29 -0
- package/src/index.tsx +9 -0
- package/src/kernel/comm.ts +220 -0
- package/src/kernel/future.ts +474 -0
- package/src/kernel/index.ts +7 -0
- package/src/kernel/kernel-connection.ts +1770 -0
- package/src/kernel/kernel-module.ts +50 -0
- package/src/kernel/libro-kernel-manager.ts +199 -0
- package/src/kernel/libro-kernel-protocol.ts +858 -0
- package/src/kernel/libro-kernel-utils.ts +152 -0
- package/src/kernel/libro-kernel.ts +39 -0
- package/src/kernel/messages.ts +1104 -0
- package/src/kernel/restapi.ts +183 -0
- package/src/kernel/serialize.ts +262 -0
- package/src/kernel/validate.ts +101 -0
- package/src/kernelspec/index.ts +5 -0
- package/src/kernelspec/kernelspec-module.ts +9 -0
- package/src/kernelspec/kernelspec.ts +37 -0
- package/src/kernelspec/manager.ts +173 -0
- package/src/kernelspec/restapi.ts +104 -0
- package/src/kernelspec/validate.ts +80 -0
- package/src/libro-kernel-connection-manager.ts +73 -0
- package/src/module.ts +19 -0
- package/src/page-config.ts +106 -0
- package/src/protocol.ts +24 -0
- package/src/server/connection-error.ts +60 -0
- package/src/server/index.ts +5 -0
- package/src/server/server-connection-protocol.ts +57 -0
- package/src/server/server-connection.ts +144 -0
- package/src/server/server-manager.ts +76 -0
- package/src/server/server-module.ts +9 -0
- package/src/session/index.ts +4 -0
- package/src/session/libro-session-manager.ts +377 -0
- package/src/session/libro-session-protocol.ts +61 -0
- package/src/session/libro-session.ts +33 -0
- package/src/session/restapi.ts +126 -0
- package/src/session/session-module.ts +26 -0
- package/src/session/validate.ts +39 -0
- package/src/utils.ts +28 -0
- package/src/validate-property.ts +38 -0
|
@@ -0,0 +1,19 @@
|
|
|
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 _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); } }
|
|
4
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
5
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
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); }
|
|
7
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
|
+
import { transient, inject } from '@difizen/mana-app';
|
|
9
|
+
import { SessionMetaOption } from "./libro-session-protocol.js";
|
|
10
|
+
export var LibroSession = (_dec = transient(), _dec(_class = /*#__PURE__*/_createClass(function LibroSession(meta) {
|
|
11
|
+
_classCallCheck(this, LibroSession);
|
|
12
|
+
this.id = meta.id;
|
|
13
|
+
this.name = meta.name;
|
|
14
|
+
this.type = meta.type;
|
|
15
|
+
this.path = meta.path;
|
|
16
|
+
this.kernel = meta.kernel;
|
|
17
|
+
this.notebook = meta.notebook;
|
|
18
|
+
})) || _class);
|
|
19
|
+
LibroSession = inject(SessionMetaOption)(LibroSession, undefined, 0) || LibroSession;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ISettings } from '../server/index.js';
|
|
2
|
+
import { ServerConnection } from '../server/server-connection.js';
|
|
3
|
+
import type { ISessionOptions, SessionIModel, SessionMeta } from './libro-session-protocol.js';
|
|
4
|
+
export declare const SESSION_SERVICE_URL = "api/sessions";
|
|
5
|
+
export type DeepPartial<T> = {
|
|
6
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Get a session url.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getSessionUrl(baseUrl: string, id: string): string;
|
|
12
|
+
export declare class SessionRestAPI {
|
|
13
|
+
serverConnection: ServerConnection;
|
|
14
|
+
/**
|
|
15
|
+
* Create a new session, or return an existing session if the session path
|
|
16
|
+
* already exists.
|
|
17
|
+
*/
|
|
18
|
+
startSession(options: ISessionOptions, serverSettings?: Partial<ISettings>): Promise<SessionIModel>;
|
|
19
|
+
/**
|
|
20
|
+
* List the running sessions.
|
|
21
|
+
*/
|
|
22
|
+
listRunning(serverSettings?: Partial<ISettings>): Promise<SessionMeta[]>;
|
|
23
|
+
/**
|
|
24
|
+
* Send a PATCH to the server, updating the session path or the kernel.
|
|
25
|
+
*/
|
|
26
|
+
updateSession(model: Pick<SessionIModel, 'id'> & DeepPartial<Omit<SessionIModel, 'id'>>, serverSettings?: Partial<ISettings>): Promise<SessionIModel>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=restapi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restapi.d.ts","sourceRoot":"","sources":["../../src/session/restapi.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAElE,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACb,WAAW,EACZ,MAAM,6BAA6B,CAAC;AAGrC,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;AAElD,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;KAC1B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACnC,CAAC;AAEF;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED,qBACa,cAAc;IACC,gBAAgB,EAAE,gBAAgB,CAAC;IAuB7D;;;OAGG;IACG,YAAY,CAChB,OAAO,EAAE,eAAe,EACxB,cAAc,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,GAClC,OAAO,CAAC,aAAa,CAAC;IAmBzB;;OAEG;IACG,WAAW,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAoB9E;;OAEG;IACG,aAAa,CACjB,KAAK,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC,EACzE,cAAc,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,GAClC,OAAO,CAAC,aAAa,CAAC;CAiB1B"}
|
|
@@ -0,0 +1,214 @@
|
|
|
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, _dec2, _class, _class2, _descriptor;
|
|
3
|
+
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 exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
4
|
+
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; }
|
|
5
|
+
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; }
|
|
6
|
+
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; }
|
|
7
|
+
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); } }
|
|
8
|
+
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); }); }; }
|
|
9
|
+
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 }); }
|
|
10
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
11
|
+
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); } }
|
|
12
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
13
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
14
|
+
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); }
|
|
15
|
+
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; }
|
|
16
|
+
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.'); }
|
|
17
|
+
// import { default as axios } from 'axios';
|
|
18
|
+
import { URL } from '@difizen/libro-common';
|
|
19
|
+
import { inject, singleton } from '@difizen/mana-app';
|
|
20
|
+
import { createResponseError } from "../server/index.js";
|
|
21
|
+
import { ServerConnection } from "../server/server-connection.js";
|
|
22
|
+
import { updateLegacySessionModel, validateModel } from "./validate.js";
|
|
23
|
+
export var SESSION_SERVICE_URL = 'api/sessions';
|
|
24
|
+
/**
|
|
25
|
+
* Get a session url.
|
|
26
|
+
*/
|
|
27
|
+
export function getSessionUrl(baseUrl, id) {
|
|
28
|
+
return URL.join(baseUrl, SESSION_SERVICE_URL, id);
|
|
29
|
+
}
|
|
30
|
+
export var SessionRestAPI = (_dec = singleton(), _dec2 = inject(ServerConnection), _dec(_class = (_class2 = /*#__PURE__*/function () {
|
|
31
|
+
function SessionRestAPI() {
|
|
32
|
+
_classCallCheck(this, SessionRestAPI);
|
|
33
|
+
_initializerDefineProperty(this, "serverConnection", _descriptor, this);
|
|
34
|
+
}
|
|
35
|
+
_createClass(SessionRestAPI, [{
|
|
36
|
+
key: "startSession",
|
|
37
|
+
value: // async startNewSession(params: {
|
|
38
|
+
// fileName: string;
|
|
39
|
+
// kernelName: string;
|
|
40
|
+
// path: string;
|
|
41
|
+
// type: string;
|
|
42
|
+
// }) {
|
|
43
|
+
// try {
|
|
44
|
+
// const res = await axios.post(`/api/sessions`, {
|
|
45
|
+
// kernel: { name: params.kernelName }, // 来源于当前文件选择了哪一个kernel,名称来自于kernelspecs
|
|
46
|
+
// name: params.fileName,
|
|
47
|
+
// path: params.path,
|
|
48
|
+
// type: params.type,
|
|
49
|
+
// });
|
|
50
|
+
// if (res.status === 201 && res.data) {
|
|
51
|
+
// return res.data;
|
|
52
|
+
// }
|
|
53
|
+
// } catch (ex) {
|
|
54
|
+
// return undefined;
|
|
55
|
+
// }
|
|
56
|
+
// }
|
|
57
|
+
/**
|
|
58
|
+
* Create a new session, or return an existing session if the session path
|
|
59
|
+
* already exists.
|
|
60
|
+
*/
|
|
61
|
+
function () {
|
|
62
|
+
var _startSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options, serverSettings) {
|
|
63
|
+
var settings, url, init, response, err, data;
|
|
64
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
65
|
+
while (1) switch (_context.prev = _context.next) {
|
|
66
|
+
case 0:
|
|
67
|
+
settings = _objectSpread(_objectSpread({}, this.serverConnection.settings), serverSettings);
|
|
68
|
+
url = URL.join(settings.baseUrl, SESSION_SERVICE_URL);
|
|
69
|
+
init = {
|
|
70
|
+
method: 'POST',
|
|
71
|
+
body: JSON.stringify(options)
|
|
72
|
+
};
|
|
73
|
+
_context.next = 5;
|
|
74
|
+
return this.serverConnection.makeRequest(url, init, settings);
|
|
75
|
+
case 5:
|
|
76
|
+
response = _context.sent;
|
|
77
|
+
if (!(response.status !== 201)) {
|
|
78
|
+
_context.next = 11;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
_context.next = 9;
|
|
82
|
+
return createResponseError(response);
|
|
83
|
+
case 9:
|
|
84
|
+
err = _context.sent;
|
|
85
|
+
throw err;
|
|
86
|
+
case 11:
|
|
87
|
+
_context.next = 13;
|
|
88
|
+
return response.json();
|
|
89
|
+
case 13:
|
|
90
|
+
data = _context.sent;
|
|
91
|
+
updateLegacySessionModel(data);
|
|
92
|
+
validateModel(data);
|
|
93
|
+
return _context.abrupt("return", data);
|
|
94
|
+
case 17:
|
|
95
|
+
case "end":
|
|
96
|
+
return _context.stop();
|
|
97
|
+
}
|
|
98
|
+
}, _callee, this);
|
|
99
|
+
}));
|
|
100
|
+
function startSession(_x, _x2) {
|
|
101
|
+
return _startSession.apply(this, arguments);
|
|
102
|
+
}
|
|
103
|
+
return startSession;
|
|
104
|
+
}()
|
|
105
|
+
/**
|
|
106
|
+
* List the running sessions.
|
|
107
|
+
*/
|
|
108
|
+
}, {
|
|
109
|
+
key: "listRunning",
|
|
110
|
+
value: function () {
|
|
111
|
+
var _listRunning = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(serverSettings) {
|
|
112
|
+
var settings, url, response, err, data;
|
|
113
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
114
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
115
|
+
case 0:
|
|
116
|
+
settings = _objectSpread(_objectSpread({}, this.serverConnection.settings), serverSettings);
|
|
117
|
+
url = URL.join(settings.baseUrl, SESSION_SERVICE_URL);
|
|
118
|
+
_context2.next = 4;
|
|
119
|
+
return this.serverConnection.makeRequest(url, {}, settings);
|
|
120
|
+
case 4:
|
|
121
|
+
response = _context2.sent;
|
|
122
|
+
if (!(response.status !== 200)) {
|
|
123
|
+
_context2.next = 10;
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
_context2.next = 8;
|
|
127
|
+
return createResponseError(response);
|
|
128
|
+
case 8:
|
|
129
|
+
err = _context2.sent;
|
|
130
|
+
throw err;
|
|
131
|
+
case 10:
|
|
132
|
+
_context2.next = 12;
|
|
133
|
+
return response.json();
|
|
134
|
+
case 12:
|
|
135
|
+
data = _context2.sent;
|
|
136
|
+
if (Array.isArray(data)) {
|
|
137
|
+
_context2.next = 15;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
throw new Error('Invalid Session list');
|
|
141
|
+
case 15:
|
|
142
|
+
data.forEach(function (m) {
|
|
143
|
+
updateLegacySessionModel(m);
|
|
144
|
+
validateModel(m);
|
|
145
|
+
});
|
|
146
|
+
return _context2.abrupt("return", data);
|
|
147
|
+
case 17:
|
|
148
|
+
case "end":
|
|
149
|
+
return _context2.stop();
|
|
150
|
+
}
|
|
151
|
+
}, _callee2, this);
|
|
152
|
+
}));
|
|
153
|
+
function listRunning(_x3) {
|
|
154
|
+
return _listRunning.apply(this, arguments);
|
|
155
|
+
}
|
|
156
|
+
return listRunning;
|
|
157
|
+
}()
|
|
158
|
+
/**
|
|
159
|
+
* Send a PATCH to the server, updating the session path or the kernel.
|
|
160
|
+
*/
|
|
161
|
+
}, {
|
|
162
|
+
key: "updateSession",
|
|
163
|
+
value: function () {
|
|
164
|
+
var _updateSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(model, serverSettings) {
|
|
165
|
+
var settings, url, init, response, err, data;
|
|
166
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
167
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
168
|
+
case 0:
|
|
169
|
+
settings = _objectSpread(_objectSpread({}, this.serverConnection.settings), serverSettings);
|
|
170
|
+
url = getSessionUrl(settings.baseUrl, model.id);
|
|
171
|
+
init = {
|
|
172
|
+
method: 'PATCH',
|
|
173
|
+
body: JSON.stringify(model)
|
|
174
|
+
};
|
|
175
|
+
_context3.next = 5;
|
|
176
|
+
return this.serverConnection.makeRequest(url, init, settings);
|
|
177
|
+
case 5:
|
|
178
|
+
response = _context3.sent;
|
|
179
|
+
if (!(response.status !== 200)) {
|
|
180
|
+
_context3.next = 11;
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
_context3.next = 9;
|
|
184
|
+
return createResponseError(response);
|
|
185
|
+
case 9:
|
|
186
|
+
err = _context3.sent;
|
|
187
|
+
throw err;
|
|
188
|
+
case 11:
|
|
189
|
+
_context3.next = 13;
|
|
190
|
+
return response.json();
|
|
191
|
+
case 13:
|
|
192
|
+
data = _context3.sent;
|
|
193
|
+
updateLegacySessionModel(data);
|
|
194
|
+
validateModel(data);
|
|
195
|
+
return _context3.abrupt("return", data);
|
|
196
|
+
case 17:
|
|
197
|
+
case "end":
|
|
198
|
+
return _context3.stop();
|
|
199
|
+
}
|
|
200
|
+
}, _callee3, this);
|
|
201
|
+
}));
|
|
202
|
+
function updateSession(_x4, _x5) {
|
|
203
|
+
return _updateSession.apply(this, arguments);
|
|
204
|
+
}
|
|
205
|
+
return updateSession;
|
|
206
|
+
}()
|
|
207
|
+
}]);
|
|
208
|
+
return SessionRestAPI;
|
|
209
|
+
}(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "serverConnection", [_dec2], {
|
|
210
|
+
configurable: true,
|
|
211
|
+
enumerable: true,
|
|
212
|
+
writable: true,
|
|
213
|
+
initializer: null
|
|
214
|
+
})), _class2)) || _class);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-module.d.ts","sourceRoot":"","sources":["../../src/session/session-module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAQ/C,eAAO,MAAM,kBAAkB,YAiB9B,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ManaModule } from '@difizen/mana-app';
|
|
2
|
+
import { LibroSessionManager } from "./libro-session-manager.js";
|
|
3
|
+
import { LibroSessionFactory, SessionMetaOption } from "./libro-session-protocol.js";
|
|
4
|
+
import { LibroSession } from "./libro-session.js";
|
|
5
|
+
import { SessionRestAPI } from "./restapi.js";
|
|
6
|
+
export var LibroSessionModule = ManaModule.create().register(SessionRestAPI, LibroSession, LibroSessionManager, {
|
|
7
|
+
token: LibroSessionFactory,
|
|
8
|
+
useFactory: function useFactory(ctx) {
|
|
9
|
+
return function (sessionMeta) {
|
|
10
|
+
var child = ctx.container.createChild();
|
|
11
|
+
child.register({
|
|
12
|
+
token: SessionMetaOption,
|
|
13
|
+
useValue: sessionMeta
|
|
14
|
+
});
|
|
15
|
+
return child.get(LibroSession);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SessionMeta } from './libro-session-protocol.js';
|
|
2
|
+
/**
|
|
3
|
+
* Validate an `Session.IModel` object.
|
|
4
|
+
*/
|
|
5
|
+
export declare function validateModel(data: any): asserts data is SessionMeta;
|
|
6
|
+
/**
|
|
7
|
+
* Update model from legacy session data.
|
|
8
|
+
*/
|
|
9
|
+
export declare function updateLegacySessionModel(data: any): void;
|
|
10
|
+
/**
|
|
11
|
+
* Validate an array of `Session.IModel` objects.
|
|
12
|
+
*/
|
|
13
|
+
export declare function validateModels(models: SessionMeta[]): asserts models is SessionMeta[];
|
|
14
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/session/validate.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/D;;GAEG;AAEH,wBAAgB,aAAa,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,IAAI,WAAW,CAOpE;AAED;;GAEG;AAEH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,CAMxD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,MAAM,IAAI,WAAW,EAAE,CAKrF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { validateModel as validateKernelModel } from "../kernel/validate.js";
|
|
2
|
+
import { validateProperty } from "../validate-property.js";
|
|
3
|
+
/**
|
|
4
|
+
* Validate an `Session.IModel` object.
|
|
5
|
+
*/ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
6
|
+
export function validateModel(data) {
|
|
7
|
+
validateProperty(data, 'id', 'string');
|
|
8
|
+
validateProperty(data, 'type', 'string');
|
|
9
|
+
validateProperty(data, 'name', 'string');
|
|
10
|
+
validateProperty(data, 'path', 'string');
|
|
11
|
+
validateProperty(data, 'kernel', 'object');
|
|
12
|
+
validateKernelModel(data.kernel);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Update model from legacy session data.
|
|
17
|
+
*/
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
19
|
+
export function updateLegacySessionModel(data) {
|
|
20
|
+
if (data.path === undefined && data.notebook !== undefined) {
|
|
21
|
+
data.path = data.notebook.path;
|
|
22
|
+
data.type = 'notebook';
|
|
23
|
+
data.name = '';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Validate an array of `Session.IModel` objects.
|
|
29
|
+
*/
|
|
30
|
+
export function validateModels(models) {
|
|
31
|
+
if (!Array.isArray(models)) {
|
|
32
|
+
throw new Error('Invalid session list');
|
|
33
|
+
}
|
|
34
|
+
models.forEach(function (d) {
|
|
35
|
+
return validateModel(d);
|
|
36
|
+
});
|
|
37
|
+
}
|
package/es/utils.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const getPersist: (key?: string, needParse?: boolean, defaultVal?: string | undefined) => any;
|
|
2
|
+
export declare const setPersist: (key?: string, val?: string) => void;
|
|
3
|
+
export declare const removePersist: (key?: string) => void;
|
|
4
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,UAAU,mDAGT,MAAM,GAAG,SAAS,QAc/B,CAAC;AAGF,eAAO,MAAM,UAAU,sCAEtB,CAAC;AAEF,eAAO,MAAM,aAAa,wBAEzB,CAAC"}
|
package/es/utils.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// 从localstorage获取值
|
|
2
|
+
export var getPersist = function getPersist() {
|
|
3
|
+
var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
4
|
+
var needParse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
5
|
+
var defaultVal = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
|
|
6
|
+
var jsonStr = window.localStorage.getItem(key) || defaultVal;
|
|
7
|
+
if (!needParse) {
|
|
8
|
+
return jsonStr;
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
if (!jsonStr) {
|
|
12
|
+
return defaultVal;
|
|
13
|
+
}
|
|
14
|
+
return JSON.parse(jsonStr);
|
|
15
|
+
} catch (ex) {
|
|
16
|
+
return defaultVal;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// 向localstorage更新值
|
|
21
|
+
export var setPersist = function setPersist() {
|
|
22
|
+
var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
23
|
+
var val = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
24
|
+
window.localStorage.setItem(key, val);
|
|
25
|
+
};
|
|
26
|
+
export var removePersist = function removePersist() {
|
|
27
|
+
var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
28
|
+
window.localStorage.removeItem(key);
|
|
29
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-property.d.ts","sourceRoot":"","sources":["../src/validate-property.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,GAAG,EACX,IAAI,EAAE,MAAM,EACZ,QAAQ,CAAC,EAAE,MAAM,EACjB,MAAM,GAAE,GAAG,EAAO,GACjB,IAAI,CAgCN"}
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
export function validateProperty(object, name, typeName) {
|
|
3
|
+
var values = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
4
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
5
|
+
if (!object.hasOwnProperty(name)) {
|
|
6
|
+
throw new Error("Missing property '".concat(name));
|
|
7
|
+
}
|
|
8
|
+
var value = object[name];
|
|
9
|
+
if (typeName !== void 0) {
|
|
10
|
+
var valid = true;
|
|
11
|
+
if (typeName === 'array') {
|
|
12
|
+
valid = Array.isArray(value);
|
|
13
|
+
} else if (typeName === 'object') {
|
|
14
|
+
valid = typeof value !== 'undefined';
|
|
15
|
+
} else {
|
|
16
|
+
valid = _typeof(value) === typeName;
|
|
17
|
+
}
|
|
18
|
+
if (!valid) {
|
|
19
|
+
throw new Error("Property '".concat(name, "' is not of type '").concat(typeName, "'"));
|
|
20
|
+
}
|
|
21
|
+
if (values.length > 0) {
|
|
22
|
+
var isValid = true;
|
|
23
|
+
if (['string', 'number', 'boolean'].includes(typeName)) {
|
|
24
|
+
isValid = values.includes(value);
|
|
25
|
+
} else {
|
|
26
|
+
isValid = values.findIndex(function (v) {
|
|
27
|
+
return v === value;
|
|
28
|
+
}) >= 0;
|
|
29
|
+
}
|
|
30
|
+
if (!isValid) {
|
|
31
|
+
throw new Error("Property '".concat(name, "' is not one of the valid values ").concat(JSON.stringify(values)));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@difizen/libro-kernel",
|
|
3
|
+
"version": "0.0.2-alpha.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ai-infra",
|
|
7
|
+
"ai-infra-fe"
|
|
8
|
+
],
|
|
9
|
+
"repository": "git@github.com:difizen/libro.git",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"typings": "./es/index.d.ts",
|
|
15
|
+
"default": "./es/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./mock": {
|
|
18
|
+
"typings": "./es/mock/index.d.ts",
|
|
19
|
+
"default": "./es/mock/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./es/mock": {
|
|
22
|
+
"typings": "./es/mock/index.d.ts",
|
|
23
|
+
"default": "./es/mock/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"main": "es/index.js",
|
|
28
|
+
"module": "es/index.js",
|
|
29
|
+
"typings": "es/index.d.ts",
|
|
30
|
+
"files": [
|
|
31
|
+
"es",
|
|
32
|
+
"src"
|
|
33
|
+
],
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@difizen/libro-common": "^0.0.2-alpha.0",
|
|
36
|
+
"@difizen/libro-core": "^0.0.2-alpha.0",
|
|
37
|
+
"@difizen/mana-app": "alpha",
|
|
38
|
+
"minimist": "^1.2.8",
|
|
39
|
+
"query-string": "^8.1.0",
|
|
40
|
+
"uuid": "^9.0.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"react": "^18.2.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/react": "^18.2.25",
|
|
47
|
+
"@types/uuid": "^9.0.5"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"setup": "father build",
|
|
51
|
+
"build": "father build",
|
|
52
|
+
"test": ": Note: lint task is delegated to test:* scripts",
|
|
53
|
+
"test:vitest": "vitest run",
|
|
54
|
+
"test:jest": "jest",
|
|
55
|
+
"coverage": ": Note: lint task is delegated to coverage:* scripts",
|
|
56
|
+
"coverage:vitest": "vitest run --coverage",
|
|
57
|
+
"coverage:jest": "jest --coverage",
|
|
58
|
+
"lint": ": Note: lint task is delegated to lint:* scripts",
|
|
59
|
+
"lint:eslint": "eslint src",
|
|
60
|
+
"lint:tsc": "tsc --noEmit"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { Disposable, Event as ManaEvent } from '@difizen/mana-app';
|
|
2
|
+
import { Emitter } from '@difizen/mana-app';
|
|
3
|
+
import { singleton } from '@difizen/mana-app';
|
|
4
|
+
|
|
5
|
+
import type { ISettings, NetworkError } from './server/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* A disposable object with an observable `disposed` signal.
|
|
8
|
+
*/
|
|
9
|
+
export interface ObservableDisposable extends Disposable {
|
|
10
|
+
/**
|
|
11
|
+
* A signal emitted when the object is disposed.
|
|
12
|
+
*/
|
|
13
|
+
readonly onDisposed: ManaEvent<void>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Object which manages kernel instances for a given base url.
|
|
18
|
+
*
|
|
19
|
+
* #### Notes
|
|
20
|
+
* The manager is responsible for maintaining the state of kernel specs.
|
|
21
|
+
*/
|
|
22
|
+
export interface IManager extends ObservableDisposable {
|
|
23
|
+
/**
|
|
24
|
+
* A signal emitted when there is a connection failure.
|
|
25
|
+
*/
|
|
26
|
+
connectionFailure: ManaEvent<NetworkError>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The server settings for the manager.
|
|
30
|
+
*/
|
|
31
|
+
readonly serverSettings: ISettings;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Whether the manager is ready.
|
|
35
|
+
*/
|
|
36
|
+
readonly isReady: boolean;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A promise that resolves when the manager is initially ready.
|
|
40
|
+
*/
|
|
41
|
+
readonly ready: Promise<void>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Whether the manager is active.
|
|
45
|
+
*/
|
|
46
|
+
readonly isActive: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@singleton()
|
|
50
|
+
export class BaseManager implements IManager {
|
|
51
|
+
// constructor(options: BaseManager.IOptions) {
|
|
52
|
+
// this.serverSettings = options.serverSettings ?? ServerConnection.makeSettings();
|
|
53
|
+
// }
|
|
54
|
+
/**
|
|
55
|
+
* A signal emitted when the delegate is disposed.
|
|
56
|
+
*/
|
|
57
|
+
get onDisposed(): ManaEvent<void> {
|
|
58
|
+
return this.onDisposedEmitter.event;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* A signal emitted when there is a connection failure.
|
|
63
|
+
*/
|
|
64
|
+
get connectionFailure(): ManaEvent<Error> {
|
|
65
|
+
return this.connectionFailureEmitter.event;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Test whether the delegate has been disposed.
|
|
70
|
+
*/
|
|
71
|
+
get isDisposed(): boolean {
|
|
72
|
+
return this._isDisposed;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Test whether the manager is ready.
|
|
77
|
+
*/
|
|
78
|
+
get isReady(): boolean {
|
|
79
|
+
return this._isReady;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A promise that fulfills when the manager is ready.
|
|
84
|
+
*/
|
|
85
|
+
get ready(): Promise<void> {
|
|
86
|
+
return this._ready;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Whether the manager is active.
|
|
91
|
+
*/
|
|
92
|
+
get isActive(): boolean {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Dispose of the delegate and invoke the callback function.
|
|
98
|
+
*/
|
|
99
|
+
dispose(): void {
|
|
100
|
+
if (this.isDisposed) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
this.onDisposedEmitter.fire(undefined);
|
|
104
|
+
this.onDisposedEmitter.dispose();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The server settings of the manager.
|
|
109
|
+
*/
|
|
110
|
+
readonly serverSettings: ISettings;
|
|
111
|
+
|
|
112
|
+
protected _isDisposed = false;
|
|
113
|
+
protected onDisposedEmitter = new Emitter<void>();
|
|
114
|
+
|
|
115
|
+
protected connectionFailureEmitter = new Emitter<Error>();
|
|
116
|
+
_isReady = false;
|
|
117
|
+
_ready: Promise<void>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The namespace for `BaseManager` class statics.
|
|
122
|
+
*/
|
|
123
|
+
export namespace BaseManager {
|
|
124
|
+
/**
|
|
125
|
+
* The options used to initialize a SessionManager.
|
|
126
|
+
*/
|
|
127
|
+
export interface IOptions {
|
|
128
|
+
/**
|
|
129
|
+
* The server settings for the manager.
|
|
130
|
+
*/
|
|
131
|
+
serverSettings?: ISettings;
|
|
132
|
+
}
|
|
133
|
+
}
|