@imbricate/origin-loader 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 WMXPY
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @namespace OriginLoader
4
+ * @description Built-in Origin Loader
5
+ */
6
+ import { IImbricateOrigin, ImbricateOriginPersistenceOrigin } from "@imbricate/core";
7
+ /**
8
+ * Load imbricate origin from built-in origin
9
+ * This function will load the origin from the built-in origin
10
+ * and initialize the origin with the payloads
11
+ *
12
+ * @param origin origin to persistence to load
13
+ *
14
+ * @returns a promise of the loaded origin
15
+ * if the origin is not found, return null
16
+ */
17
+ export declare const loadImbricateOriginFromBuiltInOrigin: (origin: ImbricateOriginPersistenceOrigin) => Promise<IImbricateOrigin | null>;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace OriginLoader
5
+ * @description Built-in Origin Loader
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.loadImbricateOriginFromBuiltInOrigin = void 0;
21
+ const core_1 = require("@imbricate/core");
22
+ const origin_file_system_1 = __importDefault(require("@imbricate/origin-file-system"));
23
+ const origin_quick_action_1 = __importDefault(require("@imbricate/origin-quick-action"));
24
+ /**
25
+ * Load imbricate origin from built-in origin
26
+ * This function will load the origin from the built-in origin
27
+ * and initialize the origin with the payloads
28
+ *
29
+ * @param origin origin to persistence to load
30
+ *
31
+ * @returns a promise of the loaded origin
32
+ * if the origin is not found, return null
33
+ */
34
+ const loadImbricateOriginFromBuiltInOrigin = (origin) => __awaiter(void 0, void 0, void 0, function* () {
35
+ if (origin.originLoadType !== core_1.IMBRICATE_ORIGIN_LOAD_TYPE.BUILT_IN) {
36
+ return null;
37
+ }
38
+ switch (origin.originLoadValue) {
39
+ case core_1.IMBRICATE_ORIGIN_BUILT_IN.ORIGIN_FILE_SYSTEM: {
40
+ return (0, origin_file_system_1.default)(origin.originPayloads);
41
+ }
42
+ case core_1.IMBRICATE_ORIGIN_BUILT_IN.ORIGIN_QUICK_ACTION: {
43
+ return (0, origin_quick_action_1.default)(origin.originPayloads);
44
+ }
45
+ default: {
46
+ console.log(`Origin load value ${origin.originLoadValue} is not found`);
47
+ console.log(`Available built-in origin load values: ${core_1.ImbricateOriginBuiltInList.join(", ")}`);
48
+ return null;
49
+ }
50
+ }
51
+ return null;
52
+ });
53
+ exports.loadImbricateOriginFromBuiltInOrigin = loadImbricateOriginFromBuiltInOrigin;
package/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @namespace OriginLoader
4
+ * @description Index
5
+ */
6
+ export * from "./built-in-origin-loader";
7
+ export * from "./origin-loader";
8
+ export { IMBRICATE_ORIGIN_BUILT_IN, IMBRICATE_ORIGIN_LOAD_TYPE, } from "@imbricate/core";
9
+ export type { ImbricateOriginLoader, ImbricateOriginPersistence, ImbricateOriginPersistenceOrigin, } from "@imbricate/core";
package/index.js ADDED
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace OriginLoader
5
+ * @description Index
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.IMBRICATE_ORIGIN_LOAD_TYPE = exports.IMBRICATE_ORIGIN_BUILT_IN = void 0;
23
+ __exportStar(require("./built-in-origin-loader"), exports);
24
+ __exportStar(require("./origin-loader"), exports);
25
+ // Re-export types from core for convenience
26
+ var core_1 = require("@imbricate/core");
27
+ Object.defineProperty(exports, "IMBRICATE_ORIGIN_BUILT_IN", { enumerable: true, get: function () { return core_1.IMBRICATE_ORIGIN_BUILT_IN; } });
28
+ Object.defineProperty(exports, "IMBRICATE_ORIGIN_LOAD_TYPE", { enumerable: true, get: function () { return core_1.IMBRICATE_ORIGIN_LOAD_TYPE; } });
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @namespace OriginLoader
4
+ * @description Origin Loader
5
+ */
6
+ import { IImbricateOrigin, ImbricateOriginPersistence, ImbricateOriginPersistenceOrigin } from "@imbricate/core";
7
+ /**
8
+ * Load imbricate origin from persistence origin
9
+ * This function will load the origin from the persistence origin
10
+ * and initialize the origin with the payloads
11
+ *
12
+ * @param origin origin to persistence to load
13
+ *
14
+ * @returns a promise of the loaded origin
15
+ * if the origin is not found, return null
16
+ */
17
+ export declare const loadImbricateOriginFromPersistenceOrigin: (origin: ImbricateOriginPersistenceOrigin) => Promise<IImbricateOrigin | null>;
18
+ /**
19
+ * Load imbricate origins from persistence
20
+ * This function will load all origins from the persistence
21
+ * and initialize the origins with the payloads
22
+ * If the origin is not found, it will be ignored
23
+ *
24
+ * @param persistence persistence to load origins
25
+ *
26
+ * @returns a promise of the loaded origins, if the origin is not found, return empty array
27
+ */
28
+ export declare const loadImbricateOriginsFromPersistence: (persistence: ImbricateOriginPersistence) => Promise<IImbricateOrigin[]>;
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace OriginLoader
5
+ * @description Origin Loader
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || (function () {
24
+ var ownKeys = function(o) {
25
+ ownKeys = Object.getOwnPropertyNames || function (o) {
26
+ var ar = [];
27
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
+ return ar;
29
+ };
30
+ return ownKeys(o);
31
+ };
32
+ return function (mod) {
33
+ if (mod && mod.__esModule) return mod;
34
+ var result = {};
35
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
+ __setModuleDefault(result, mod);
37
+ return result;
38
+ };
39
+ })();
40
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
41
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
42
+ return new (P || (P = Promise))(function (resolve, reject) {
43
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
44
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
45
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
46
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
47
+ });
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.loadImbricateOriginsFromPersistence = exports.loadImbricateOriginFromPersistenceOrigin = void 0;
51
+ const core_1 = require("@imbricate/core");
52
+ const built_in_origin_loader_1 = require("./built-in-origin-loader");
53
+ /**
54
+ * Load imbricate origin from persistence origin
55
+ * This function will load the origin from the persistence origin
56
+ * and initialize the origin with the payloads
57
+ *
58
+ * @param origin origin to persistence to load
59
+ *
60
+ * @returns a promise of the loaded origin
61
+ * if the origin is not found, return null
62
+ */
63
+ const loadImbricateOriginFromPersistenceOrigin = (origin) => __awaiter(void 0, void 0, void 0, function* () {
64
+ switch (origin.originLoadType) {
65
+ case core_1.IMBRICATE_ORIGIN_LOAD_TYPE.BUILT_IN: {
66
+ return (0, built_in_origin_loader_1.loadImbricateOriginFromBuiltInOrigin)(origin);
67
+ }
68
+ case core_1.IMBRICATE_ORIGIN_LOAD_TYPE.NPM_PACKAGE: {
69
+ const originPackage = yield Promise.resolve(`${origin.originLoadValue}`).then(s => __importStar(require(s)));
70
+ if (typeof originPackage.default === "function") {
71
+ const initialized = originPackage.default.call(null, origin.originPayloads);
72
+ return initialized;
73
+ }
74
+ break;
75
+ }
76
+ case core_1.IMBRICATE_ORIGIN_LOAD_TYPE.FILE_SYSTEM: {
77
+ const originPackage = yield Promise.resolve(`${origin.originLoadValue}`).then(s => __importStar(require(s)));
78
+ if (typeof originPackage.default === "function") {
79
+ const initialized = originPackage.default.call(null, origin.originPayloads);
80
+ return initialized;
81
+ }
82
+ break;
83
+ }
84
+ default: {
85
+ console.log(`Origin load type ${origin.originLoadType} is not found`);
86
+ console.log(`Available origin load types: ${core_1.ImbricateOriginLoadTypeList.join(", ")}`);
87
+ return null;
88
+ }
89
+ }
90
+ return null;
91
+ });
92
+ exports.loadImbricateOriginFromPersistenceOrigin = loadImbricateOriginFromPersistenceOrigin;
93
+ /**
94
+ * Load imbricate origins from persistence
95
+ * This function will load all origins from the persistence
96
+ * and initialize the origins with the payloads
97
+ * If the origin is not found, it will be ignored
98
+ *
99
+ * @param persistence persistence to load origins
100
+ *
101
+ * @returns a promise of the loaded origins, if the origin is not found, return empty array
102
+ */
103
+ const loadImbricateOriginsFromPersistence = (persistence) => __awaiter(void 0, void 0, void 0, function* () {
104
+ const origins = [];
105
+ for (const origin of persistence.origins) {
106
+ const originInstance = yield (0, exports.loadImbricateOriginFromPersistenceOrigin)(origin);
107
+ if (originInstance) {
108
+ origins.push(originInstance);
109
+ }
110
+ }
111
+ return origins;
112
+ });
113
+ exports.loadImbricateOriginsFromPersistence = loadImbricateOriginsFromPersistence;
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@imbricate/origin-loader",
3
+ "main": "index.js",
4
+ "version": "1.0.0",
5
+ "description": "Origin Loader for Imbricate",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/Imbricate/Imbricate.git"
9
+ },
10
+ "keywords": [
11
+ "imbricate",
12
+ "loader"
13
+ ],
14
+ "author": "WMXPY",
15
+ "license": "MIT",
16
+ "bugs": {
17
+ "url": "https://github.com/Imbricate/Imbricate/issues"
18
+ },
19
+ "homepage": "https://imbricate.io",
20
+ "dependencies": {
21
+ "@imbricate/origin-file-system": "^3.20.0",
22
+ "@imbricate/origin-quick-action": "^0.0.0"
23
+ },
24
+ "peerDependencies": {
25
+ "@imbricate/core": "*"
26
+ }
27
+ }