@imbricate/core 0.1.0 → 1.0.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.
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Definition
5
+ * @description Listable
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Definition
5
+ * @description Promise
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Definition
5
+ * @description Script
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
package/index.js CHANGED
@@ -1,8 +1,31 @@
1
+ "use strict";
1
2
  /**
2
3
  * @author WMXPY
3
4
  * @description Index
4
5
  */
5
- export * from "./builder/interface";
6
- export * from "./schema/interface";
7
- export * from "./util/writable";
8
- export * from "./verify/interface";
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ __exportStar(require("./definition/listable"), exports);
22
+ __exportStar(require("./definition/promise"), exports);
23
+ __exportStar(require("./definition/script"), exports);
24
+ __exportStar(require("./origin/collection/interface"), exports);
25
+ __exportStar(require("./origin/collection/least-common-identifier"), exports);
26
+ __exportStar(require("./origin/interface"), exports);
27
+ __exportStar(require("./sandbox/feature/builder"), exports);
28
+ __exportStar(require("./sandbox/feature/feature"), exports);
29
+ __exportStar(require("./sandbox/sandbox"), exports);
30
+ __exportStar(require("./search/prefix"), exports);
31
+ __exportStar(require("./search/snippet"), exports);
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Origin_Collection
5
+ * @description Interface
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Origin_Collection
5
+ * @description Least Common Identifier
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.mapLeastCommonIdentifier = void 0;
9
+ class TrieNode {
10
+ static create() {
11
+ return new TrieNode();
12
+ }
13
+ constructor() {
14
+ this._items = [];
15
+ this._children = {};
16
+ }
17
+ get items() {
18
+ return this._items;
19
+ }
20
+ getChild(key) {
21
+ if (!this._children[key]) {
22
+ this._children[key] = TrieNode.create();
23
+ }
24
+ return this._children[key];
25
+ }
26
+ pushItem(item) {
27
+ this._items.push(item);
28
+ }
29
+ }
30
+ const mapLeastCommonIdentifier = (identifiers) => {
31
+ const root = TrieNode.create();
32
+ for (const identifier of identifiers) {
33
+ let current = root;
34
+ for (const char of identifier.identifier) {
35
+ current.pushItem(identifier.key);
36
+ current = current.getChild(char);
37
+ }
38
+ }
39
+ const result = {};
40
+ for (const identifier of identifiers) {
41
+ let current = root;
42
+ let currentIdentifier = "";
43
+ for (const char of identifier.identifier) {
44
+ current = current.getChild(char);
45
+ currentIdentifier += char;
46
+ if (current.items.length === 1) {
47
+ break;
48
+ }
49
+ }
50
+ result[identifier.key] = currentIdentifier;
51
+ }
52
+ return result;
53
+ };
54
+ exports.mapLeastCommonIdentifier = mapLeastCommonIdentifier;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Origin
5
+ * @description Interface
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@imbricate/core",
3
3
  "main": "index.js",
4
- "version": "0.1.0",
4
+ "version": "1.0.0",
5
5
  "description": "Core for Imbricate",
6
6
  "repository": {
7
7
  "type": "git",
@@ -15,5 +15,15 @@
15
15
  "bugs": {
16
16
  "url": "https://github.com/Imbricate/Imbricate-Core/issues"
17
17
  },
18
- "homepage": "https://imbricate.io"
18
+ "homepage": "https://imbricate.io",
19
+ "dependencies": {
20
+ "@sudoo/io": "^1.8.0",
21
+ "@sudoo/marked": "^3.21.4",
22
+ "@sudoo/marked-mixin-date": "^1.0.0",
23
+ "@sudoo/marked-mixin-json": "^1.0.0",
24
+ "@sudoo/marked-mixin-math": "^1.4.0",
25
+ "@sudoo/marked-mixin-object": "^1.3.0",
26
+ "@sudoo/marked-mixin-parse": "^1.0.0",
27
+ "@sudoo/uuid": "^1.1.0"
28
+ }
19
29
  }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Sandbox_Definition
5
+ * @description Config
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Sandbox_Definition
5
+ * @description Environment
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Sandbox_Definition
5
+ * @description Implementation
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Sandbox_Feature
5
+ * @description Builder
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.SandboxFeatureBuilder = void 0;
9
+ const feature_1 = require("./feature");
10
+ class SandboxFeatureBuilder {
11
+ static fromScratch() {
12
+ return new SandboxFeatureBuilder();
13
+ }
14
+ constructor() {
15
+ this._packageName = "";
16
+ this._methodName = "";
17
+ this._implementation = () => null;
18
+ }
19
+ withPackageName(packageName) {
20
+ this._packageName = packageName;
21
+ return this;
22
+ }
23
+ withMethodName(methodName) {
24
+ this._methodName = methodName;
25
+ return this;
26
+ }
27
+ withImplementation(implementation) {
28
+ this._implementation = implementation;
29
+ return this;
30
+ }
31
+ build() {
32
+ return feature_1.SandboxFeature.create(this._packageName, this._methodName, this._implementation);
33
+ }
34
+ }
35
+ exports.SandboxFeatureBuilder = SandboxFeatureBuilder;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Sandbox_Feature
5
+ * @description Feature
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.SandboxFeature = void 0;
9
+ class SandboxFeature {
10
+ static create(packageName, methodName, implementation) {
11
+ return new SandboxFeature(packageName, methodName, implementation);
12
+ }
13
+ constructor(packageName, methodName, implementation) {
14
+ this._packageName = packageName;
15
+ this._methodName = methodName;
16
+ this._implementation = implementation;
17
+ }
18
+ get packageName() {
19
+ return this._packageName;
20
+ }
21
+ get methodName() {
22
+ return this._methodName;
23
+ }
24
+ get implementation() {
25
+ return this._implementation;
26
+ }
27
+ }
28
+ exports.SandboxFeature = SandboxFeature;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Sandbox_Provide
5
+ * @description Feature
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.sandboxProvideFeatures = void 0;
9
+ const mapFeatures = (features) => {
10
+ const map = {};
11
+ for (const feature of features) {
12
+ if (!map[feature.packageName]) {
13
+ map[feature.packageName] = {};
14
+ }
15
+ map[feature.packageName][feature.methodName] = feature.implementation;
16
+ }
17
+ return map;
18
+ };
19
+ const sandboxProvideFeatures = (sandbox, features) => {
20
+ const mappedFeatures = mapFeatures(features);
21
+ for (const packageName of Object.keys(mappedFeatures)) {
22
+ const methods = mappedFeatures[packageName];
23
+ sandbox.provide(packageName, methods);
24
+ }
25
+ };
26
+ exports.sandboxProvideFeatures = sandboxProvideFeatures;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Sandbox
5
+ * @description Sandbox
6
+ */
7
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
+ return new (P || (P = Promise))(function (resolve, reject) {
10
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
14
+ });
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.executeSandboxScript = exports.createSandbox = void 0;
18
+ const marked_1 = require("@sudoo/marked");
19
+ const marked_mixin_date_1 = require("@sudoo/marked-mixin-date");
20
+ const marked_mixin_json_1 = require("@sudoo/marked-mixin-json");
21
+ const marked_mixin_math_1 = require("@sudoo/marked-mixin-math");
22
+ const marked_mixin_object_1 = require("@sudoo/marked-mixin-object");
23
+ const marked_mixin_parse_1 = require("@sudoo/marked-mixin-parse");
24
+ const feature_1 = require("./provide/feature");
25
+ const createSandbox = (features) => {
26
+ const sandbox = marked_1.Sandbox.fromAllEvaluators();
27
+ sandbox.use(marked_mixin_date_1.markedDateMixinFactory.createInjectMixin("Date"));
28
+ sandbox.use(marked_mixin_json_1.markedJsonMixinFactory.createInjectMixin("Json"));
29
+ sandbox.use(marked_mixin_math_1.markedMathMixinFactory.createInjectMixin("Math"));
30
+ sandbox.use(marked_mixin_object_1.markedObjectMixinFactory.createInjectMixin("Object"));
31
+ sandbox.use(marked_mixin_parse_1.markedParseMixinFactory.createInjectMixin("Parse"));
32
+ (0, feature_1.sandboxProvideFeatures)(sandbox, features);
33
+ return sandbox;
34
+ };
35
+ exports.createSandbox = createSandbox;
36
+ const executeSandboxScript = (script, features, environment, config) => __awaiter(void 0, void 0, void 0, function* () {
37
+ const sandbox = (0, exports.createSandbox)(features);
38
+ sandbox.inject("environment", environment);
39
+ sandbox.inject("config", config);
40
+ return yield sandbox.evaluate(script);
41
+ });
42
+ exports.executeSandboxScript = executeSandboxScript;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Search
5
+ * @description Prefix
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.getShortPrefixOfSnippet = void 0;
9
+ const snippet_1 = require("./snippet");
10
+ const getShortPrefixOfSnippet = (snippet) => {
11
+ switch (snippet.type) {
12
+ case snippet_1.IMBRICATE_SEARCH_SNIPPET_TYPE.PAGE: {
13
+ switch (snippet.source) {
14
+ case snippet_1.IMBRICATE_SEARCH_SNIPPET_PAGE_SNIPPET_SOURCE.TITLE: {
15
+ return "T";
16
+ }
17
+ case snippet_1.IMBRICATE_SEARCH_SNIPPET_PAGE_SNIPPET_SOURCE.CONTENT: {
18
+ return "C";
19
+ }
20
+ }
21
+ }
22
+ }
23
+ return "?";
24
+ };
25
+ exports.getShortPrefixOfSnippet = getShortPrefixOfSnippet;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Search
5
+ * @description Snippet
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.IMBRICATE_SEARCH_SNIPPET_PAGE_SNIPPET_SOURCE = exports.IMBRICATE_SEARCH_SNIPPET_TYPE = void 0;
9
+ var IMBRICATE_SEARCH_SNIPPET_TYPE;
10
+ (function (IMBRICATE_SEARCH_SNIPPET_TYPE) {
11
+ IMBRICATE_SEARCH_SNIPPET_TYPE["PAGE"] = "PAGE";
12
+ })(IMBRICATE_SEARCH_SNIPPET_TYPE || (exports.IMBRICATE_SEARCH_SNIPPET_TYPE = IMBRICATE_SEARCH_SNIPPET_TYPE = {}));
13
+ var IMBRICATE_SEARCH_SNIPPET_PAGE_SNIPPET_SOURCE;
14
+ (function (IMBRICATE_SEARCH_SNIPPET_PAGE_SNIPPET_SOURCE) {
15
+ IMBRICATE_SEARCH_SNIPPET_PAGE_SNIPPET_SOURCE["TITLE"] = "TITLE";
16
+ IMBRICATE_SEARCH_SNIPPET_PAGE_SNIPPET_SOURCE["CONTENT"] = "CONTENT";
17
+ })(IMBRICATE_SEARCH_SNIPPET_PAGE_SNIPPET_SOURCE || (exports.IMBRICATE_SEARCH_SNIPPET_PAGE_SNIPPET_SOURCE = IMBRICATE_SEARCH_SNIPPET_PAGE_SNIPPET_SOURCE = {}));
@@ -1,54 +0,0 @@
1
- /**
2
- * @author WMXPY
3
- * @namespace Builder
4
- * @description Interface
5
- */
6
- import { verifyInterface } from "../verify/interface";
7
- var ImbricateInterfaceBuilder = /** @class */ (function () {
8
- function ImbricateInterfaceBuilder() {
9
- this._interface = {};
10
- }
11
- ImbricateInterfaceBuilder.fromScratch = function () {
12
- return new ImbricateInterfaceBuilder();
13
- };
14
- ImbricateInterfaceBuilder.prototype.identifier = function (identifier) {
15
- this._interface.identifier = identifier;
16
- return this;
17
- };
18
- ImbricateInterfaceBuilder.prototype.version = function (version) {
19
- this._interface.version = version;
20
- return this;
21
- };
22
- ImbricateInterfaceBuilder.prototype.protocol = function (protocol) {
23
- this._interface.protocol = protocol;
24
- return this;
25
- };
26
- ImbricateInterfaceBuilder.prototype.matcher = function (matcher) {
27
- this._interface.matcher = matcher;
28
- return this;
29
- };
30
- ImbricateInterfaceBuilder.prototype.humanFriendlyName = function (humanFriendlyName) {
31
- this._interface.humanFriendlyName = humanFriendlyName;
32
- return this;
33
- };
34
- ImbricateInterfaceBuilder.prototype.description = function (description) {
35
- this._interface.description = description;
36
- return this;
37
- };
38
- ImbricateInterfaceBuilder.prototype.input = function () {
39
- this._interface.input = {};
40
- return this;
41
- };
42
- ImbricateInterfaceBuilder.prototype.output = function () {
43
- this._interface.output = {};
44
- return this;
45
- };
46
- ImbricateInterfaceBuilder.prototype.verify = function () {
47
- return verifyInterface(this._interface);
48
- };
49
- ImbricateInterfaceBuilder.prototype.build = function () {
50
- return this._interface;
51
- };
52
- return ImbricateInterfaceBuilder;
53
- }());
54
- export { ImbricateInterfaceBuilder };
@@ -1,6 +0,0 @@
1
- /**
2
- * @author WMXPY
3
- * @namespace Schema
4
- * @description Interface
5
- */
6
- export {};
package/util/writable.js DELETED
@@ -1,6 +0,0 @@
1
- /**
2
- * @author WMXPY
3
- * @namespace Util
4
- * @description Writable
5
- */
6
- export {};
@@ -1,20 +0,0 @@
1
- /**
2
- * @author WMXPY
3
- * @namespace Verify
4
- * @description Interface
5
- */
6
- export var verifyInterface = function (imbricateInterface) {
7
- if (typeof imbricateInterface.identifier !== "string") {
8
- return false;
9
- }
10
- if (typeof imbricateInterface.version !== "string") {
11
- return false;
12
- }
13
- if (typeof imbricateInterface.protocol !== "string") {
14
- return false;
15
- }
16
- if (typeof imbricateInterface.matcher !== "string") {
17
- return false;
18
- }
19
- return true;
20
- };