@imbricate/core 3.8.0 → 3.8.2

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 (84) hide show
  1. package/{src/author/definition.ts → author/definition.d.ts} +0 -4
  2. package/author/definition.js +7 -0
  3. package/{src/database/definition.ts → database/definition.d.ts} +15 -51
  4. package/database/definition.js +31 -0
  5. package/{src/database/interface.ts → database/interface.d.ts} +27 -69
  6. package/database/interface.js +7 -0
  7. package/{src/database/manager.ts → database/manager.d.ts} +9 -24
  8. package/database/manager.js +7 -0
  9. package/database/schema.d.ts +70 -0
  10. package/database/schema.js +78 -0
  11. package/database/validate.d.ts +15 -0
  12. package/database/validate.js +73 -0
  13. package/{src/document/definition.ts → document/definition.d.ts} +3 -31
  14. package/document/definition.js +17 -0
  15. package/{src/document/interface.ts → document/interface.d.ts} +15 -44
  16. package/document/interface.js +7 -0
  17. package/document/property/default-value.d.ts +7 -0
  18. package/document/property/default-value.js +25 -0
  19. package/{src/document/property/definition.ts → document/property/definition.d.ts} +1 -6
  20. package/document/property/definition.js +7 -0
  21. package/document/property/primary.d.ts +8 -0
  22. package/document/property/primary.js +20 -0
  23. package/document/property/triage-base.d.ts +31 -0
  24. package/document/property/triage-base.js +85 -0
  25. package/document/property/triage-manager.d.ts +30 -0
  26. package/document/property/triage-manager.js +50 -0
  27. package/document/property/triage.d.ts +8 -0
  28. package/document/property/triage.js +13 -0
  29. package/{src/document/property.ts → document/property.d.ts} +4 -23
  30. package/document/property.js +54 -0
  31. package/document/validate.d.ts +18 -0
  32. package/{src/document/validate.ts → document/validate.js} +21 -33
  33. package/{src/index.ts → index.d.ts} +0 -2
  34. package/index.js +47 -0
  35. package/{src/loader/definition.ts → loader/definition.d.ts} +1 -5
  36. package/loader/definition.js +7 -0
  37. package/loader/origin-loader.d.ts +29 -0
  38. package/loader/origin-loader.js +104 -0
  39. package/{src/loader/persistence.ts → loader/persistence.d.ts} +3 -12
  40. package/loader/persistence.js +19 -0
  41. package/{src/origin/definition.ts → origin/definition.d.ts} +0 -1
  42. package/origin/definition.js +7 -0
  43. package/{src/origin/interface.ts → origin/interface.d.ts} +7 -18
  44. package/origin/interface.js +7 -0
  45. package/{src/origin/search.ts → origin/search.d.ts} +13 -29
  46. package/origin/search.js +14 -0
  47. package/package.json +3 -27
  48. package/{src/static/definition.ts → static/definition.d.ts} +0 -3
  49. package/static/definition.js +7 -0
  50. package/{src/static/interface.ts → static/interface.d.ts} +1 -6
  51. package/static/interface.js +7 -0
  52. package/{src/static/manager.ts → static/manager.d.ts} +4 -11
  53. package/static/manager.js +7 -0
  54. package/{src/text/definition.ts → text/definition.d.ts} +0 -3
  55. package/text/definition.js +7 -0
  56. package/{src/text/interface.ts → text/interface.d.ts} +1 -6
  57. package/text/interface.js +7 -0
  58. package/{src/text/manager.ts → text/manager.d.ts} +4 -11
  59. package/text/manager.js +7 -0
  60. package/.editorconfig +0 -10
  61. package/.gitattributes +0 -4
  62. package/.github/dependabot.yml +0 -8
  63. package/.github/workflows/ci.yml +0 -48
  64. package/.vscode/settings.json +0 -8
  65. package/.yarn/releases/yarn-4.4.0.cjs +0 -925
  66. package/.yarnrc.yml +0 -3
  67. package/babel.config.js +0 -14
  68. package/docs/README.md +0 -70
  69. package/eslint.config.mjs +0 -64
  70. package/jest.config.ts +0 -14
  71. package/src/database/schema.ts +0 -165
  72. package/src/database/validate.ts +0 -77
  73. package/src/document/property/default-value.ts +0 -26
  74. package/src/document/property/primary.ts +0 -29
  75. package/src/document/property/triage-base.ts +0 -138
  76. package/src/document/property/triage-manager.ts +0 -68
  77. package/src/document/property/triage.ts +0 -15
  78. package/src/loader/origin-loader.ts +0 -88
  79. package/test/unit/database/schema.test.ts +0 -95
  80. package/test/unit/document/property/primary.test.ts +0 -87
  81. package/test/unit/document/property/triage.test.ts +0 -64
  82. package/test/unit/document/validate.test.ts +0 -138
  83. package/test/unit/loader/definition.test.ts +0 -55
  84. package/typescript/tsconfig.build.json +0 -23
@@ -3,12 +3,10 @@
3
3
  * @namespace Document
4
4
  * @description Property
5
5
  */
6
-
7
6
  /**
8
7
  * Document properties
9
8
  */
10
- export enum IMBRICATE_PROPERTY_TYPE {
11
-
9
+ export declare enum IMBRICATE_PROPERTY_TYPE {
12
10
  /**
13
11
  * BOOLEAN - boolean, store as boolean
14
12
  */
@@ -48,43 +46,26 @@ export enum IMBRICATE_PROPERTY_TYPE {
48
46
  * REFERENCE - reference, store as a list of other document unique identifier
49
47
  * Note: Reference is always stored as an array, even if it is a single reference
50
48
  */
51
- REFERENCE = "REFERENCE",
49
+ REFERENCE = "REFERENCE"
52
50
  }
53
-
54
51
  /**
55
52
  * Document properties
56
- *
53
+ *
57
54
  * Key - Property key, which should match schema properties unique identifier
58
55
  * Value - Property value, which should match schema properties type
59
56
  */
60
57
  export type DocumentProperties = Record<DocumentPropertyKey, DocumentPropertyValue<IMBRICATE_PROPERTY_TYPE>>;
61
-
62
58
  /**
63
59
  * Document property key, which should match schema properties unique identifier
64
60
  */
65
61
  export type DocumentPropertyKey = string;
66
62
  export type DocumentPropertyValue<T extends IMBRICATE_PROPERTY_TYPE> = {
67
-
68
63
  readonly type: T;
69
64
  readonly value: DocumentPropertyValueObject<T>;
70
65
  };
71
-
72
66
  export type DocumentPropertyValueObjectReference = {
73
-
74
67
  readonly originUniqueIdentifier: string;
75
68
  readonly databaseUniqueIdentifier: string;
76
69
  readonly documentUniqueIdentifier: string;
77
70
  };
78
-
79
- // IMBRICATE_PROPERTY_TYPE SWITCH
80
- export type DocumentPropertyValueObject<T extends IMBRICATE_PROPERTY_TYPE> =
81
- T extends IMBRICATE_PROPERTY_TYPE.BOOLEAN ? boolean :
82
- T extends IMBRICATE_PROPERTY_TYPE.STRING ? string :
83
- T extends IMBRICATE_PROPERTY_TYPE.NUMBER ? number :
84
- T extends IMBRICATE_PROPERTY_TYPE.MARKDOWN ? string :
85
- T extends IMBRICATE_PROPERTY_TYPE.JSON ? string :
86
- T extends IMBRICATE_PROPERTY_TYPE.IMBRISCRIPT ? string :
87
- T extends IMBRICATE_PROPERTY_TYPE.DATE ? string :
88
- T extends IMBRICATE_PROPERTY_TYPE.LABEL ? string[] :
89
- T extends IMBRICATE_PROPERTY_TYPE.REFERENCE ? DocumentPropertyValueObjectReference[] :
90
- never;
71
+ export type DocumentPropertyValueObject<T extends IMBRICATE_PROPERTY_TYPE> = T extends IMBRICATE_PROPERTY_TYPE.BOOLEAN ? boolean : T extends IMBRICATE_PROPERTY_TYPE.STRING ? string : T extends IMBRICATE_PROPERTY_TYPE.NUMBER ? number : T extends IMBRICATE_PROPERTY_TYPE.MARKDOWN ? string : T extends IMBRICATE_PROPERTY_TYPE.JSON ? string : T extends IMBRICATE_PROPERTY_TYPE.IMBRISCRIPT ? string : T extends IMBRICATE_PROPERTY_TYPE.DATE ? string : T extends IMBRICATE_PROPERTY_TYPE.LABEL ? string[] : T extends IMBRICATE_PROPERTY_TYPE.REFERENCE ? DocumentPropertyValueObjectReference[] : never;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Document
5
+ * @description Property
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.IMBRICATE_PROPERTY_TYPE = void 0;
9
+ /**
10
+ * Document properties
11
+ */
12
+ var IMBRICATE_PROPERTY_TYPE;
13
+ (function (IMBRICATE_PROPERTY_TYPE) {
14
+ /**
15
+ * BOOLEAN - boolean, store as boolean
16
+ */
17
+ IMBRICATE_PROPERTY_TYPE["BOOLEAN"] = "BOOLEAN";
18
+ /**
19
+ * STRING - string, store as plain text
20
+ */
21
+ IMBRICATE_PROPERTY_TYPE["STRING"] = "STRING";
22
+ /**
23
+ * NUMBER - number, store as number
24
+ */
25
+ IMBRICATE_PROPERTY_TYPE["NUMBER"] = "NUMBER";
26
+ /**
27
+ * MARKDOWN - markdown, store as text object unique identifier. Display as markdown
28
+ */
29
+ IMBRICATE_PROPERTY_TYPE["MARKDOWN"] = "MARKDOWN";
30
+ /**
31
+ * JSON - json, store as text object unique identifier. Display as JSON
32
+ */
33
+ IMBRICATE_PROPERTY_TYPE["JSON"] = "JSON";
34
+ /**
35
+ * IMBRISCRIPT - imbricate script, store as text object unique identifier. Display as imbricate script
36
+ * The script is executed in a sandbox environment, using customized javascript engine
37
+ */
38
+ IMBRICATE_PROPERTY_TYPE["IMBRISCRIPT"] = "IMBRISCRIPT";
39
+ /**
40
+ * DATE - date, store as string in ISO format
41
+ * For example - 2000-01-01T00:00:00.000Z
42
+ */
43
+ IMBRICATE_PROPERTY_TYPE["DATE"] = "DATE";
44
+ /**
45
+ * LABEL - label, store as a list of label id
46
+ * Note: Label is always stored as an array, even if it is a single label
47
+ */
48
+ IMBRICATE_PROPERTY_TYPE["LABEL"] = "LABEL";
49
+ /**
50
+ * REFERENCE - reference, store as a list of other document unique identifier
51
+ * Note: Reference is always stored as an array, even if it is a single reference
52
+ */
53
+ IMBRICATE_PROPERTY_TYPE["REFERENCE"] = "REFERENCE";
54
+ })(IMBRICATE_PROPERTY_TYPE || (exports.IMBRICATE_PROPERTY_TYPE = IMBRICATE_PROPERTY_TYPE = {}));
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @namespace Document
4
+ * @description Validate
5
+ */
6
+ import { ImbricateDatabaseSchema } from "../database/schema";
7
+ import { DocumentProperties } from "./property";
8
+ /**
9
+ * Validate properties with schema
10
+ *
11
+ * @param properties properties to validate
12
+ * @param schema database schema to validate
13
+ * @param allowExtraProperties allow extra properties, optional with default false
14
+ *
15
+ * @returns a string error message if validation failed
16
+ * null if validation passed
17
+ */
18
+ export declare const validateImbricateProperties: (properties: DocumentProperties, schema: ImbricateDatabaseSchema, allowExtraProperties?: boolean) => string | null;
@@ -1,105 +1,93 @@
1
+ "use strict";
1
2
  /**
2
3
  * @author WMXPY
3
4
  * @namespace Document
4
5
  * @description Validate
5
6
  */
6
-
7
- import { ImbricateDatabaseSchema, ImbricateDatabaseSchemaProperty } from "../database/schema";
8
- import { DocumentProperties, DocumentPropertyValue, IMBRICATE_PROPERTY_TYPE } from "./property";
9
-
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.validateImbricateProperties = void 0;
9
+ const property_1 = require("./property");
10
10
  /**
11
11
  * Validate properties with schema
12
- *
12
+ *
13
13
  * @param properties properties to validate
14
14
  * @param schema database schema to validate
15
15
  * @param allowExtraProperties allow extra properties, optional with default false
16
- *
16
+ *
17
17
  * @returns a string error message if validation failed
18
18
  * null if validation passed
19
19
  */
20
- export const validateImbricateProperties = (
21
- properties: DocumentProperties,
22
- schema: ImbricateDatabaseSchema,
23
- allowExtraProperties: boolean = false,
24
- ): string | null => {
25
-
20
+ const validateImbricateProperties = (properties, schema, allowExtraProperties = false) => {
26
21
  if (typeof properties !== "object") {
27
22
  return "Properties must be an object";
28
23
  }
29
-
30
- const keys: string[] = Object.keys(properties);
24
+ const keys = Object.keys(properties);
31
25
  for (const key of keys) {
32
-
33
- const property = schema.properties.find((each: ImbricateDatabaseSchemaProperty<IMBRICATE_PROPERTY_TYPE>) => {
26
+ const property = schema.properties.find((each) => {
34
27
  return each.propertyIdentifier === key;
35
28
  });
36
-
37
29
  if (!property) {
38
30
  if (allowExtraProperties) {
39
31
  continue;
40
32
  }
41
33
  return `Property ${key} not found in schema`;
42
34
  }
43
-
44
- const value: DocumentPropertyValue<IMBRICATE_PROPERTY_TYPE> = properties[key];
35
+ const value = properties[key];
45
36
  if (typeof value.type !== "string") {
46
37
  return `Property ${key} type must be a string`;
47
38
  }
48
-
49
39
  if (value.type !== property.propertyType) {
50
40
  return `Property ${key} type must be ${property.propertyType}, but got ${value.type}`;
51
41
  }
52
-
53
42
  // IMBRICATE_PROPERTY_TYPE SWITCH
54
43
  switch (value.type) {
55
-
56
- case IMBRICATE_PROPERTY_TYPE.BOOLEAN: {
44
+ case property_1.IMBRICATE_PROPERTY_TYPE.BOOLEAN: {
57
45
  if (typeof value.value !== "boolean") {
58
46
  return `Property ${key} value must be a boolean`;
59
47
  }
60
48
  break;
61
49
  }
62
- case IMBRICATE_PROPERTY_TYPE.STRING: {
50
+ case property_1.IMBRICATE_PROPERTY_TYPE.STRING: {
63
51
  if (typeof value.value !== "string") {
64
52
  return `Property ${key} value must be a string`;
65
53
  }
66
54
  break;
67
55
  }
68
- case IMBRICATE_PROPERTY_TYPE.NUMBER: {
56
+ case property_1.IMBRICATE_PROPERTY_TYPE.NUMBER: {
69
57
  if (typeof value.value !== "number") {
70
58
  return `Property ${key} value must be a number`;
71
59
  }
72
60
  break;
73
61
  }
74
- case IMBRICATE_PROPERTY_TYPE.MARKDOWN: {
62
+ case property_1.IMBRICATE_PROPERTY_TYPE.MARKDOWN: {
75
63
  if (typeof value.value !== "string") {
76
64
  return `Property ${key} value must be a string of text object reference`;
77
65
  }
78
66
  break;
79
67
  }
80
- case IMBRICATE_PROPERTY_TYPE.JSON: {
68
+ case property_1.IMBRICATE_PROPERTY_TYPE.JSON: {
81
69
  if (typeof value.value !== "string") {
82
70
  return `Property ${key} value must be a string of text object reference`;
83
71
  }
84
72
  break;
85
73
  }
86
- case IMBRICATE_PROPERTY_TYPE.IMBRISCRIPT: {
74
+ case property_1.IMBRICATE_PROPERTY_TYPE.IMBRISCRIPT: {
87
75
  if (typeof value.value !== "string") {
88
76
  return `Property ${key} value must be a string of text object reference`;
89
77
  }
90
78
  break;
91
79
  }
92
- case IMBRICATE_PROPERTY_TYPE.DATE: {
80
+ case property_1.IMBRICATE_PROPERTY_TYPE.DATE: {
93
81
  if (typeof value.value !== "string") {
94
82
  return `Property ${key} value must be a string of date in ISO format`;
95
83
  }
96
- const date: Date = new Date(value.value);
84
+ const date = new Date(value.value);
97
85
  if (isNaN(date.getTime())) {
98
86
  return `Property ${key} value must be a string of date in ISO format`;
99
87
  }
100
88
  break;
101
89
  }
102
- case IMBRICATE_PROPERTY_TYPE.LABEL: {
90
+ case property_1.IMBRICATE_PROPERTY_TYPE.LABEL: {
103
91
  if (!Array.isArray(value.value)) {
104
92
  return `Property ${key} value must be an array of string`;
105
93
  }
@@ -110,7 +98,7 @@ export const validateImbricateProperties = (
110
98
  }
111
99
  break;
112
100
  }
113
- case IMBRICATE_PROPERTY_TYPE.REFERENCE: {
101
+ case property_1.IMBRICATE_PROPERTY_TYPE.REFERENCE: {
114
102
  if (!Array.isArray(value.value)) {
115
103
  return `Property ${key} value must be an array of string`;
116
104
  }
@@ -132,6 +120,6 @@ export const validateImbricateProperties = (
132
120
  }
133
121
  }
134
122
  }
135
-
136
123
  return null;
137
124
  };
125
+ exports.validateImbricateProperties = validateImbricateProperties;
@@ -2,7 +2,6 @@
2
2
  * @author WMXPY
3
3
  * @description Index
4
4
  */
5
-
6
5
  export * from "./author/definition";
7
6
  export * from "./database/definition";
8
7
  export * from "./database/interface";
@@ -30,4 +29,3 @@ export * from "./static/manager";
30
29
  export * from "./text/definition";
31
30
  export * from "./text/interface";
32
31
  export * from "./text/manager";
33
-
package/index.js ADDED
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @description Index
5
+ */
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("./author/definition"), exports);
22
+ __exportStar(require("./database/definition"), exports);
23
+ __exportStar(require("./database/interface"), exports);
24
+ __exportStar(require("./database/manager"), exports);
25
+ __exportStar(require("./database/schema"), exports);
26
+ __exportStar(require("./database/validate"), exports);
27
+ __exportStar(require("./document/definition"), exports);
28
+ __exportStar(require("./document/interface"), exports);
29
+ __exportStar(require("./document/property"), exports);
30
+ __exportStar(require("./document/property/default-value"), exports);
31
+ __exportStar(require("./document/property/definition"), exports);
32
+ __exportStar(require("./document/property/primary"), exports);
33
+ __exportStar(require("./document/property/triage"), exports);
34
+ __exportStar(require("./document/property/triage-manager"), exports);
35
+ __exportStar(require("./document/validate"), exports);
36
+ __exportStar(require("./loader/definition"), exports);
37
+ __exportStar(require("./loader/origin-loader"), exports);
38
+ __exportStar(require("./loader/persistence"), exports);
39
+ __exportStar(require("./origin/definition"), exports);
40
+ __exportStar(require("./origin/interface"), exports);
41
+ __exportStar(require("./origin/search"), exports);
42
+ __exportStar(require("./static/definition"), exports);
43
+ __exportStar(require("./static/interface"), exports);
44
+ __exportStar(require("./static/manager"), exports);
45
+ __exportStar(require("./text/definition"), exports);
46
+ __exportStar(require("./text/interface"), exports);
47
+ __exportStar(require("./text/manager"), exports);
@@ -3,10 +3,6 @@
3
3
  * @namespace Loader
4
4
  * @description Definition
5
5
  */
6
-
7
6
  import { OriginPayload } from "../origin/definition";
8
7
  import { IImbricateOrigin } from "../origin/interface";
9
-
10
- export type ImbricateOriginLoader = (
11
- payload: OriginPayload,
12
- ) => IImbricateOrigin;
8
+ export type ImbricateOriginLoader = (payload: OriginPayload) => IImbricateOrigin;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Loader
5
+ * @description Definition
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @namespace Loader
4
+ * @description Origin Loader
5
+ */
6
+ import { IImbricateOrigin } from "../origin/interface";
7
+ import { ImbricateOriginPersistence, ImbricateOriginPersistenceOrigin } from "./persistence";
8
+ /**
9
+ * Load imbricate origin from persistence origin
10
+ * This function will load the origin from the persistence origin
11
+ * and initialize the origin with the payloads
12
+ *
13
+ * @param origin origin to persistence to load
14
+ *
15
+ * @returns a promise of the loaded origin
16
+ * if the origin is not found, return null
17
+ */
18
+ export declare const loadImbricateOriginFromPersistenceOrigin: (origin: ImbricateOriginPersistenceOrigin) => Promise<IImbricateOrigin | null>;
19
+ /**
20
+ * Load imbricate origins from persistence
21
+ * This function will load all origins from the persistence
22
+ * and initialize the origins with the payloads
23
+ * If the origin is not found, it will be ignored
24
+ *
25
+ * @param persistence persistence to load origins
26
+ *
27
+ * @returns a promise of the loaded origins, if the origin is not found, return empty array
28
+ */
29
+ export declare const loadImbricateOriginsFromPersistence: (persistence: ImbricateOriginPersistence) => Promise<IImbricateOrigin[]>;
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Loader
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 persistence_1 = require("./persistence");
52
+ /**
53
+ * Load imbricate origin from persistence origin
54
+ * This function will load the origin from the persistence origin
55
+ * and initialize the origin with the payloads
56
+ *
57
+ * @param origin origin to persistence to load
58
+ *
59
+ * @returns a promise of the loaded origin
60
+ * if the origin is not found, return null
61
+ */
62
+ const loadImbricateOriginFromPersistenceOrigin = (origin) => __awaiter(void 0, void 0, void 0, function* () {
63
+ switch (origin.originLoadType) {
64
+ case persistence_1.IMBRICATE_ORIGIN_LOAD_TYPE.NPM_PACKAGE: {
65
+ const originPackage = yield Promise.resolve(`${origin.originLoadValue}`).then(s => __importStar(require(s)));
66
+ if (typeof originPackage.default === "function") {
67
+ const initialized = originPackage.default.call(null, origin.originPayloads);
68
+ return initialized;
69
+ }
70
+ break;
71
+ }
72
+ case persistence_1.IMBRICATE_ORIGIN_LOAD_TYPE.FILE_SYSTEM: {
73
+ const originPackage = yield Promise.resolve(`${origin.originLoadValue}`).then(s => __importStar(require(s)));
74
+ if (typeof originPackage.default === "function") {
75
+ const initialized = originPackage.default.call(null, origin.originPayloads);
76
+ return initialized;
77
+ }
78
+ break;
79
+ }
80
+ }
81
+ return null;
82
+ });
83
+ exports.loadImbricateOriginFromPersistenceOrigin = loadImbricateOriginFromPersistenceOrigin;
84
+ /**
85
+ * Load imbricate origins from persistence
86
+ * This function will load all origins from the persistence
87
+ * and initialize the origins with the payloads
88
+ * If the origin is not found, it will be ignored
89
+ *
90
+ * @param persistence persistence to load origins
91
+ *
92
+ * @returns a promise of the loaded origins, if the origin is not found, return empty array
93
+ */
94
+ const loadImbricateOriginsFromPersistence = (persistence) => __awaiter(void 0, void 0, void 0, function* () {
95
+ const origins = [];
96
+ for (const origin of persistence.origins) {
97
+ const originInstance = yield (0, exports.loadImbricateOriginFromPersistenceOrigin)(origin);
98
+ if (originInstance) {
99
+ origins.push(originInstance);
100
+ }
101
+ }
102
+ return origins;
103
+ });
104
+ exports.loadImbricateOriginsFromPersistence = loadImbricateOriginsFromPersistence;
@@ -3,32 +3,23 @@
3
3
  * @namespace Loader
4
4
  * @description Persistence
5
5
  */
6
-
7
6
  import { OriginPayload } from "../origin/definition";
8
-
9
7
  /**
10
8
  * Imbricate Origin Load Type
11
- *
9
+ *
12
10
  * NPM_PACKAGE - load origin from npm package, as package name
13
11
  * FILE_SYSTEM - load origin from file system, as file path
14
12
  */
15
- export enum IMBRICATE_ORIGIN_LOAD_TYPE {
16
-
13
+ export declare enum IMBRICATE_ORIGIN_LOAD_TYPE {
17
14
  NPM_PACKAGE = "NPM_PACKAGE",
18
- FILE_SYSTEM = "FILE_SYSTEM",
15
+ FILE_SYSTEM = "FILE_SYSTEM"
19
16
  }
20
-
21
17
  export type ImbricateOriginPersistenceOrigin = {
22
-
23
18
  readonly originLoadType: IMBRICATE_ORIGIN_LOAD_TYPE;
24
19
  readonly originLoadValue: string;
25
-
26
20
  readonly originName: string;
27
-
28
21
  readonly originPayloads: OriginPayload;
29
22
  };
30
-
31
23
  export type ImbricateOriginPersistence = {
32
-
33
24
  readonly origins: ImbricateOriginPersistenceOrigin[];
34
25
  };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Loader
5
+ * @description Persistence
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.IMBRICATE_ORIGIN_LOAD_TYPE = void 0;
9
+ /**
10
+ * Imbricate Origin Load Type
11
+ *
12
+ * NPM_PACKAGE - load origin from npm package, as package name
13
+ * FILE_SYSTEM - load origin from file system, as file path
14
+ */
15
+ var IMBRICATE_ORIGIN_LOAD_TYPE;
16
+ (function (IMBRICATE_ORIGIN_LOAD_TYPE) {
17
+ IMBRICATE_ORIGIN_LOAD_TYPE["NPM_PACKAGE"] = "NPM_PACKAGE";
18
+ IMBRICATE_ORIGIN_LOAD_TYPE["FILE_SYSTEM"] = "FILE_SYSTEM";
19
+ })(IMBRICATE_ORIGIN_LOAD_TYPE || (exports.IMBRICATE_ORIGIN_LOAD_TYPE = IMBRICATE_ORIGIN_LOAD_TYPE = {}));
@@ -3,5 +3,4 @@
3
3
  * @namespace Origin
4
4
  * @description Definition
5
5
  */
6
-
7
6
  export type OriginPayload = Record<string, any>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Origin
5
+ * @description Definition
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -3,66 +3,55 @@
3
3
  * @namespace Origin
4
4
  * @description Interface
5
5
  */
6
-
7
6
  import { IImbricateDatabaseManager } from "../database/manager";
8
7
  import { IImbricateStaticManager } from "../static/manager";
9
8
  import { IImbricateTextManager } from "../text/manager";
10
9
  import { OriginPayload } from "./definition";
11
10
  import { ImbricateSearchResult } from "./search";
12
-
13
11
  export interface IImbricateOrigin {
14
-
15
12
  /**
16
13
  * Unique identifier of the origin
17
14
  */
18
15
  readonly uniqueIdentifier: string;
19
-
20
16
  /**
21
17
  * Payloads to initialize the origin
22
18
  */
23
19
  readonly payloads: OriginPayload;
24
-
25
20
  /**
26
21
  * Get the database manager of the origin
27
- *
22
+ *
28
23
  * @returns the database manager
29
24
  */
30
25
  getDatabaseManager(): IImbricateDatabaseManager;
31
-
32
26
  /**
33
27
  * Get the text manager of the origin
34
28
  * The text manager is used to manage text objects
35
- *
29
+ *
36
30
  * @returns the text manager
37
31
  */
38
32
  getTextManager(): IImbricateTextManager;
39
-
40
33
  /**
41
34
  * Get the static manager of the origin
42
35
  * The static manager is used to manage static objects
43
- *
36
+ *
44
37
  * @returns the static manager
45
38
  */
46
39
  getStaticManager(): IImbricateStaticManager;
47
-
48
40
  /**
49
41
  * Dispose the origin, optional
50
42
  * This method will be called when the origin is no longer needed
51
- *
43
+ *
52
44
  * If the origin needs to dispose resources, override this method
53
45
  * else, do not implement this method
54
- *
46
+ *
55
47
  * Example: close database connection, or close file system
56
48
  */
57
49
  dispose?(): PromiseLike<void>;
58
-
59
50
  /**
60
51
  * Search for items in the origin
61
- *
52
+ *
62
53
  * @param keyword the keyword to search
63
54
  * @returns the search
64
55
  */
65
- search(
66
- keyword: string,
67
- ): PromiseLike<ImbricateSearchResult>;
56
+ search(keyword: string): PromiseLike<ImbricateSearchResult>;
68
57
  }
@@ -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 });