@imbricate/core 3.7.2 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/.editorconfig +10 -0
  2. package/.gitattributes +4 -0
  3. package/.github/dependabot.yml +8 -0
  4. package/.github/workflows/ci.yml +48 -0
  5. package/.vscode/settings.json +8 -0
  6. package/.yarn/releases/yarn-4.4.0.cjs +925 -0
  7. package/.yarnrc.yml +3 -0
  8. package/babel.config.js +14 -0
  9. package/docs/README.md +70 -0
  10. package/eslint.config.mjs +64 -0
  11. package/jest.config.ts +14 -0
  12. package/package.json +27 -3
  13. package/{author/definition.d.ts → src/author/definition.ts} +4 -0
  14. package/{database/definition.d.ts → src/database/definition.ts} +67 -4
  15. package/{database/interface.d.ts → src/database/interface.ts} +69 -27
  16. package/{database/manager.d.ts → src/database/manager.ts} +24 -9
  17. package/src/database/schema.ts +165 -0
  18. package/src/database/validate.ts +77 -0
  19. package/{document/definition.d.ts → src/document/definition.ts} +31 -3
  20. package/{document/interface.d.ts → src/document/interface.ts} +44 -15
  21. package/src/document/property/default-value.ts +26 -0
  22. package/{document/property/definition.d.ts → src/document/property/definition.ts} +6 -1
  23. package/src/document/property/primary.ts +29 -0
  24. package/src/document/property/triage-base.ts +138 -0
  25. package/src/document/property/triage-manager.ts +68 -0
  26. package/src/document/property/triage.ts +15 -0
  27. package/{document/property.d.ts → src/document/property.ts} +23 -4
  28. package/{document/validate.js → src/document/validate.ts} +33 -21
  29. package/{index.d.ts → src/index.ts} +3 -0
  30. package/{loader/definition.d.ts → src/loader/definition.ts} +5 -1
  31. package/src/loader/origin-loader.ts +88 -0
  32. package/{loader/persistence.d.ts → src/loader/persistence.ts} +12 -3
  33. package/{origin/definition.d.ts → src/origin/definition.ts} +1 -0
  34. package/{origin/interface.d.ts → src/origin/interface.ts} +18 -7
  35. package/{origin/search.d.ts → src/origin/search.ts} +29 -13
  36. package/{static/definition.d.ts → src/static/definition.ts} +3 -0
  37. package/{static/interface.d.ts → src/static/interface.ts} +6 -1
  38. package/{static/manager.d.ts → src/static/manager.ts} +11 -4
  39. package/{text/definition.d.ts → src/text/definition.ts} +3 -0
  40. package/{text/interface.d.ts → src/text/interface.ts} +6 -1
  41. package/{text/manager.d.ts → src/text/manager.ts} +11 -4
  42. package/test/unit/database/schema.test.ts +95 -0
  43. package/test/unit/document/property/primary.test.ts +87 -0
  44. package/test/unit/document/property/triage.test.ts +64 -0
  45. package/test/unit/document/validate.test.ts +138 -0
  46. package/test/unit/loader/definition.test.ts +55 -0
  47. package/typescript/tsconfig.build.json +23 -0
  48. package/author/definition.js +0 -7
  49. package/database/definition.js +0 -17
  50. package/database/interface.js +0 -7
  51. package/database/manager.js +0 -7
  52. package/database/schema.d.ts +0 -69
  53. package/database/schema.js +0 -78
  54. package/document/definition.js +0 -17
  55. package/document/interface.js +0 -7
  56. package/document/property/default-value.d.ts +0 -7
  57. package/document/property/default-value.js +0 -25
  58. package/document/property/definition.js +0 -7
  59. package/document/property/primary.d.ts +0 -8
  60. package/document/property/primary.js +0 -20
  61. package/document/property/triage-base.d.ts +0 -31
  62. package/document/property/triage-base.js +0 -85
  63. package/document/property/triage-manager.d.ts +0 -30
  64. package/document/property/triage-manager.js +0 -50
  65. package/document/property/triage.d.ts +0 -8
  66. package/document/property/triage.js +0 -13
  67. package/document/property.js +0 -54
  68. package/document/validate.d.ts +0 -18
  69. package/index.js +0 -46
  70. package/loader/definition.js +0 -7
  71. package/loader/origin-loader.d.ts +0 -29
  72. package/loader/origin-loader.js +0 -104
  73. package/loader/persistence.js +0 -19
  74. package/origin/definition.js +0 -7
  75. package/origin/interface.js +0 -7
  76. package/origin/search.js +0 -14
  77. package/static/definition.js +0 -7
  78. package/static/interface.js +0 -7
  79. package/static/manager.js +0 -7
  80. package/text/definition.js +0 -7
  81. package/text/interface.js +0 -7
  82. package/text/manager.js +0 -7
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @namespace Document_Property
4
+ * @description Triage Manager
5
+ */
6
+
7
+ import { DocumentProperties, DocumentPropertyKey } from "../property";
8
+ import { ImbricateDocumentPropertyTriageBase } from "./triage-base";
9
+
10
+ export class ImbricateDocumentPropertyTriageManager<Result> extends ImbricateDocumentPropertyTriageBase<Result> {
11
+
12
+ public static create<Result>(
13
+ properties: DocumentProperties,
14
+ ): ImbricateDocumentPropertyTriageManager<Result> {
15
+
16
+ return new ImbricateDocumentPropertyTriageManager<Result>(properties);
17
+ }
18
+
19
+ private readonly _properties: DocumentProperties;
20
+
21
+ private constructor(
22
+ properties: DocumentProperties,
23
+ ) {
24
+
25
+ super();
26
+ this._properties = properties;
27
+ }
28
+
29
+ /**
30
+ * Collect the result as array
31
+ *
32
+ * @returns collected result as array
33
+ */
34
+ public collectAsArray(): Result[] {
35
+
36
+ const result: Map<DocumentPropertyKey, Result> = super._collect(this._properties);
37
+ return Array.from(result.values());
38
+ }
39
+
40
+ /**
41
+ * Collect the result as map
42
+ *
43
+ * @returns collected result as map
44
+ */
45
+ public collectAsMap(): Map<DocumentPropertyKey, Result> {
46
+
47
+ return super._collect(this._properties);
48
+ }
49
+
50
+ /**
51
+ * Collect the result as object
52
+ *
53
+ * @returns collected result as object
54
+ */
55
+ public collectAsObject(): Record<DocumentPropertyKey, Result> {
56
+
57
+ const result: Map<DocumentPropertyKey, Result> = super._collect(this._properties);
58
+ const keys: DocumentPropertyKey[] = Array.from(result.keys());
59
+
60
+ const object: Record<DocumentPropertyKey, Result> = {} as Record<DocumentPropertyKey, Result>;
61
+ for (const key of keys) {
62
+
63
+ object[key] = result.get(key) as Result;
64
+ }
65
+
66
+ return object;
67
+ }
68
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @namespace Document_Property
4
+ * @description Triage
5
+ */
6
+
7
+ import { DocumentProperties } from "../property";
8
+ import { ImbricateDocumentPropertyTriageManager } from "./triage-manager";
9
+
10
+ export const triageImbricateDocumentProperties = <Result>(
11
+ properties: DocumentProperties,
12
+ ): ImbricateDocumentPropertyTriageManager<Result> => {
13
+
14
+ return ImbricateDocumentPropertyTriageManager.create<Result>(properties);
15
+ };
@@ -3,10 +3,12 @@
3
3
  * @namespace Document
4
4
  * @description Property
5
5
  */
6
+
6
7
  /**
7
8
  * Document properties
8
9
  */
9
- export declare enum IMBRICATE_PROPERTY_TYPE {
10
+ export enum IMBRICATE_PROPERTY_TYPE {
11
+
10
12
  /**
11
13
  * BOOLEAN - boolean, store as boolean
12
14
  */
@@ -46,26 +48,43 @@ export declare enum IMBRICATE_PROPERTY_TYPE {
46
48
  * REFERENCE - reference, store as a list of other document unique identifier
47
49
  * Note: Reference is always stored as an array, even if it is a single reference
48
50
  */
49
- REFERENCE = "REFERENCE"
51
+ REFERENCE = "REFERENCE",
50
52
  }
53
+
51
54
  /**
52
55
  * Document properties
53
- *
56
+ *
54
57
  * Key - Property key, which should match schema properties unique identifier
55
58
  * Value - Property value, which should match schema properties type
56
59
  */
57
60
  export type DocumentProperties = Record<DocumentPropertyKey, DocumentPropertyValue<IMBRICATE_PROPERTY_TYPE>>;
61
+
58
62
  /**
59
63
  * Document property key, which should match schema properties unique identifier
60
64
  */
61
65
  export type DocumentPropertyKey = string;
62
66
  export type DocumentPropertyValue<T extends IMBRICATE_PROPERTY_TYPE> = {
67
+
63
68
  readonly type: T;
64
69
  readonly value: DocumentPropertyValueObject<T>;
65
70
  };
71
+
66
72
  export type DocumentPropertyValueObjectReference = {
73
+
67
74
  readonly originUniqueIdentifier: string;
68
75
  readonly databaseUniqueIdentifier: string;
69
76
  readonly documentUniqueIdentifier: string;
70
77
  };
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;
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;
@@ -1,93 +1,105 @@
1
- "use strict";
2
1
  /**
3
2
  * @author WMXPY
4
3
  * @namespace Document
5
4
  * @description Validate
6
5
  */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.validateImbricateProperties = void 0;
9
- const property_1 = require("./property");
6
+
7
+ import { ImbricateDatabaseSchema, ImbricateDatabaseSchemaProperty } from "../database/schema";
8
+ import { DocumentProperties, DocumentPropertyValue, IMBRICATE_PROPERTY_TYPE } from "./property";
9
+
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
- const validateImbricateProperties = (properties, schema, allowExtraProperties = false) => {
20
+ export const validateImbricateProperties = (
21
+ properties: DocumentProperties,
22
+ schema: ImbricateDatabaseSchema,
23
+ allowExtraProperties: boolean = false,
24
+ ): string | null => {
25
+
21
26
  if (typeof properties !== "object") {
22
27
  return "Properties must be an object";
23
28
  }
24
- const keys = Object.keys(properties);
29
+
30
+ const keys: string[] = Object.keys(properties);
25
31
  for (const key of keys) {
26
- const property = schema.properties.find((each) => {
32
+
33
+ const property = schema.properties.find((each: ImbricateDatabaseSchemaProperty<IMBRICATE_PROPERTY_TYPE>) => {
27
34
  return each.propertyIdentifier === key;
28
35
  });
36
+
29
37
  if (!property) {
30
38
  if (allowExtraProperties) {
31
39
  continue;
32
40
  }
33
41
  return `Property ${key} not found in schema`;
34
42
  }
35
- const value = properties[key];
43
+
44
+ const value: DocumentPropertyValue<IMBRICATE_PROPERTY_TYPE> = properties[key];
36
45
  if (typeof value.type !== "string") {
37
46
  return `Property ${key} type must be a string`;
38
47
  }
48
+
39
49
  if (value.type !== property.propertyType) {
40
50
  return `Property ${key} type must be ${property.propertyType}, but got ${value.type}`;
41
51
  }
52
+
42
53
  // IMBRICATE_PROPERTY_TYPE SWITCH
43
54
  switch (value.type) {
44
- case property_1.IMBRICATE_PROPERTY_TYPE.BOOLEAN: {
55
+
56
+ case IMBRICATE_PROPERTY_TYPE.BOOLEAN: {
45
57
  if (typeof value.value !== "boolean") {
46
58
  return `Property ${key} value must be a boolean`;
47
59
  }
48
60
  break;
49
61
  }
50
- case property_1.IMBRICATE_PROPERTY_TYPE.STRING: {
62
+ case IMBRICATE_PROPERTY_TYPE.STRING: {
51
63
  if (typeof value.value !== "string") {
52
64
  return `Property ${key} value must be a string`;
53
65
  }
54
66
  break;
55
67
  }
56
- case property_1.IMBRICATE_PROPERTY_TYPE.NUMBER: {
68
+ case IMBRICATE_PROPERTY_TYPE.NUMBER: {
57
69
  if (typeof value.value !== "number") {
58
70
  return `Property ${key} value must be a number`;
59
71
  }
60
72
  break;
61
73
  }
62
- case property_1.IMBRICATE_PROPERTY_TYPE.MARKDOWN: {
74
+ case IMBRICATE_PROPERTY_TYPE.MARKDOWN: {
63
75
  if (typeof value.value !== "string") {
64
76
  return `Property ${key} value must be a string of text object reference`;
65
77
  }
66
78
  break;
67
79
  }
68
- case property_1.IMBRICATE_PROPERTY_TYPE.JSON: {
80
+ case IMBRICATE_PROPERTY_TYPE.JSON: {
69
81
  if (typeof value.value !== "string") {
70
82
  return `Property ${key} value must be a string of text object reference`;
71
83
  }
72
84
  break;
73
85
  }
74
- case property_1.IMBRICATE_PROPERTY_TYPE.IMBRISCRIPT: {
86
+ case IMBRICATE_PROPERTY_TYPE.IMBRISCRIPT: {
75
87
  if (typeof value.value !== "string") {
76
88
  return `Property ${key} value must be a string of text object reference`;
77
89
  }
78
90
  break;
79
91
  }
80
- case property_1.IMBRICATE_PROPERTY_TYPE.DATE: {
92
+ case IMBRICATE_PROPERTY_TYPE.DATE: {
81
93
  if (typeof value.value !== "string") {
82
94
  return `Property ${key} value must be a string of date in ISO format`;
83
95
  }
84
- const date = new Date(value.value);
96
+ const date: Date = new Date(value.value);
85
97
  if (isNaN(date.getTime())) {
86
98
  return `Property ${key} value must be a string of date in ISO format`;
87
99
  }
88
100
  break;
89
101
  }
90
- case property_1.IMBRICATE_PROPERTY_TYPE.LABEL: {
102
+ case IMBRICATE_PROPERTY_TYPE.LABEL: {
91
103
  if (!Array.isArray(value.value)) {
92
104
  return `Property ${key} value must be an array of string`;
93
105
  }
@@ -98,7 +110,7 @@ const validateImbricateProperties = (properties, schema, allowExtraProperties =
98
110
  }
99
111
  break;
100
112
  }
101
- case property_1.IMBRICATE_PROPERTY_TYPE.REFERENCE: {
113
+ case IMBRICATE_PROPERTY_TYPE.REFERENCE: {
102
114
  if (!Array.isArray(value.value)) {
103
115
  return `Property ${key} value must be an array of string`;
104
116
  }
@@ -120,6 +132,6 @@ const validateImbricateProperties = (properties, schema, allowExtraProperties =
120
132
  }
121
133
  }
122
134
  }
135
+
123
136
  return null;
124
137
  };
125
- exports.validateImbricateProperties = validateImbricateProperties;
@@ -2,11 +2,13 @@
2
2
  * @author WMXPY
3
3
  * @description Index
4
4
  */
5
+
5
6
  export * from "./author/definition";
6
7
  export * from "./database/definition";
7
8
  export * from "./database/interface";
8
9
  export * from "./database/manager";
9
10
  export * from "./database/schema";
11
+ export * from "./database/validate";
10
12
  export * from "./document/definition";
11
13
  export * from "./document/interface";
12
14
  export * from "./document/property";
@@ -28,3 +30,4 @@ export * from "./static/manager";
28
30
  export * from "./text/definition";
29
31
  export * from "./text/interface";
30
32
  export * from "./text/manager";
33
+
@@ -3,6 +3,10 @@
3
3
  * @namespace Loader
4
4
  * @description Definition
5
5
  */
6
+
6
7
  import { OriginPayload } from "../origin/definition";
7
8
  import { IImbricateOrigin } from "../origin/interface";
8
- export type ImbricateOriginLoader = (payload: OriginPayload) => IImbricateOrigin;
9
+
10
+ export type ImbricateOriginLoader = (
11
+ payload: OriginPayload,
12
+ ) => IImbricateOrigin;
@@ -0,0 +1,88 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @namespace Loader
4
+ * @description Origin Loader
5
+ */
6
+
7
+ import { IImbricateOrigin } from "../origin/interface";
8
+ import { IMBRICATE_ORIGIN_LOAD_TYPE, ImbricateOriginPersistence, ImbricateOriginPersistenceOrigin } from "./persistence";
9
+
10
+ /**
11
+ * Load imbricate origin from persistence origin
12
+ * This function will load the origin from the persistence origin
13
+ * and initialize the origin with the payloads
14
+ *
15
+ * @param origin origin to persistence to load
16
+ *
17
+ * @returns a promise of the loaded origin
18
+ * if the origin is not found, return null
19
+ */
20
+ export const loadImbricateOriginFromPersistenceOrigin = async (
21
+ origin: ImbricateOriginPersistenceOrigin,
22
+ ): Promise<IImbricateOrigin | null> => {
23
+
24
+ switch (origin.originLoadType) {
25
+
26
+ case IMBRICATE_ORIGIN_LOAD_TYPE.NPM_PACKAGE: {
27
+
28
+ const originPackage = await import(origin.originLoadValue);
29
+
30
+ if (typeof originPackage.default === "function") {
31
+
32
+ const initialized = originPackage.default.call(
33
+ null,
34
+ origin.originPayloads,
35
+ );
36
+
37
+ return initialized;
38
+ }
39
+ break;
40
+ }
41
+
42
+ case IMBRICATE_ORIGIN_LOAD_TYPE.FILE_SYSTEM: {
43
+
44
+ const originPackage = await import(origin.originLoadValue);
45
+
46
+ if (typeof originPackage.default === "function") {
47
+
48
+ const initialized = originPackage.default.call(
49
+ null,
50
+ origin.originPayloads,
51
+ );
52
+
53
+ return initialized;
54
+ }
55
+ break;
56
+ }
57
+ }
58
+
59
+ return null;
60
+ };
61
+
62
+ /**
63
+ * Load imbricate origins from persistence
64
+ * This function will load all origins from the persistence
65
+ * and initialize the origins with the payloads
66
+ * If the origin is not found, it will be ignored
67
+ *
68
+ * @param persistence persistence to load origins
69
+ *
70
+ * @returns a promise of the loaded origins, if the origin is not found, return empty array
71
+ */
72
+ export const loadImbricateOriginsFromPersistence = async (
73
+ persistence: ImbricateOriginPersistence,
74
+ ): Promise<IImbricateOrigin[]> => {
75
+
76
+ const origins: IImbricateOrigin[] = [];
77
+
78
+ for (const origin of persistence.origins) {
79
+
80
+ const originInstance: IImbricateOrigin | null = await loadImbricateOriginFromPersistenceOrigin(origin);
81
+
82
+ if (originInstance) {
83
+ origins.push(originInstance);
84
+ }
85
+ }
86
+
87
+ return origins;
88
+ };
@@ -3,23 +3,32 @@
3
3
  * @namespace Loader
4
4
  * @description Persistence
5
5
  */
6
+
6
7
  import { OriginPayload } from "../origin/definition";
8
+
7
9
  /**
8
10
  * Imbricate Origin Load Type
9
- *
11
+ *
10
12
  * NPM_PACKAGE - load origin from npm package, as package name
11
13
  * FILE_SYSTEM - load origin from file system, as file path
12
14
  */
13
- export declare enum IMBRICATE_ORIGIN_LOAD_TYPE {
15
+ export enum IMBRICATE_ORIGIN_LOAD_TYPE {
16
+
14
17
  NPM_PACKAGE = "NPM_PACKAGE",
15
- FILE_SYSTEM = "FILE_SYSTEM"
18
+ FILE_SYSTEM = "FILE_SYSTEM",
16
19
  }
20
+
17
21
  export type ImbricateOriginPersistenceOrigin = {
22
+
18
23
  readonly originLoadType: IMBRICATE_ORIGIN_LOAD_TYPE;
19
24
  readonly originLoadValue: string;
25
+
20
26
  readonly originName: string;
27
+
21
28
  readonly originPayloads: OriginPayload;
22
29
  };
30
+
23
31
  export type ImbricateOriginPersistence = {
32
+
24
33
  readonly origins: ImbricateOriginPersistenceOrigin[];
25
34
  };
@@ -3,4 +3,5 @@
3
3
  * @namespace Origin
4
4
  * @description Definition
5
5
  */
6
+
6
7
  export type OriginPayload = Record<string, any>;
@@ -3,55 +3,66 @@
3
3
  * @namespace Origin
4
4
  * @description Interface
5
5
  */
6
+
6
7
  import { IImbricateDatabaseManager } from "../database/manager";
7
8
  import { IImbricateStaticManager } from "../static/manager";
8
9
  import { IImbricateTextManager } from "../text/manager";
9
10
  import { OriginPayload } from "./definition";
10
11
  import { ImbricateSearchResult } from "./search";
12
+
11
13
  export interface IImbricateOrigin {
14
+
12
15
  /**
13
16
  * Unique identifier of the origin
14
17
  */
15
18
  readonly uniqueIdentifier: string;
19
+
16
20
  /**
17
21
  * Payloads to initialize the origin
18
22
  */
19
23
  readonly payloads: OriginPayload;
24
+
20
25
  /**
21
26
  * Get the database manager of the origin
22
- *
27
+ *
23
28
  * @returns the database manager
24
29
  */
25
30
  getDatabaseManager(): IImbricateDatabaseManager;
31
+
26
32
  /**
27
33
  * Get the text manager of the origin
28
34
  * The text manager is used to manage text objects
29
- *
35
+ *
30
36
  * @returns the text manager
31
37
  */
32
38
  getTextManager(): IImbricateTextManager;
39
+
33
40
  /**
34
41
  * Get the static manager of the origin
35
42
  * The static manager is used to manage static objects
36
- *
43
+ *
37
44
  * @returns the static manager
38
45
  */
39
46
  getStaticManager(): IImbricateStaticManager;
47
+
40
48
  /**
41
49
  * Dispose the origin, optional
42
50
  * This method will be called when the origin is no longer needed
43
- *
51
+ *
44
52
  * If the origin needs to dispose resources, override this method
45
53
  * else, do not implement this method
46
- *
54
+ *
47
55
  * Example: close database connection, or close file system
48
56
  */
49
57
  dispose?(): PromiseLike<void>;
58
+
50
59
  /**
51
60
  * Search for items in the origin
52
- *
61
+ *
53
62
  * @param keyword the keyword to search
54
63
  * @returns the search
55
64
  */
56
- search(keyword: string): PromiseLike<ImbricateSearchResult>;
65
+ search(
66
+ keyword: string,
67
+ ): PromiseLike<ImbricateSearchResult>;
57
68
  }
@@ -3,34 +3,48 @@
3
3
  * @namespace Origin
4
4
  * @description Search
5
5
  */
6
- export declare enum IMBRICATE_SEARCH_TARGET_TYPE {
6
+
7
+ export enum IMBRICATE_SEARCH_TARGET_TYPE {
8
+
7
9
  DATABASE = "DATABASE",
8
10
  DOCUMENT = "DOCUMENT",
9
- MARKDOWN = "MARKDOWN"
11
+ MARKDOWN = "MARKDOWN",
10
12
  }
11
- export type ImbricateSearchTargetSwitch<T extends IMBRICATE_SEARCH_TARGET_TYPE> = T extends IMBRICATE_SEARCH_TARGET_TYPE.DATABASE ? {
12
- databaseUniqueIdentifier: string;
13
- } : T extends IMBRICATE_SEARCH_TARGET_TYPE.DOCUMENT ? {
14
- databaseUniqueIdentifier: string;
15
- documentUniqueIdentifier: string;
16
- } : T extends IMBRICATE_SEARCH_TARGET_TYPE.MARKDOWN ? {
17
- databaseUniqueIdentifier: string;
18
- documentUniqueIdentifier: string;
19
- propertyUniqueIdentifier: string;
20
- lineNumber: number;
21
- } : never;
13
+
14
+ export type ImbricateSearchTargetSwitch<T extends IMBRICATE_SEARCH_TARGET_TYPE> =
15
+ T extends IMBRICATE_SEARCH_TARGET_TYPE.DATABASE ? {
16
+ databaseUniqueIdentifier: string;
17
+ } :
18
+ T extends IMBRICATE_SEARCH_TARGET_TYPE.DOCUMENT ? {
19
+ databaseUniqueIdentifier: string;
20
+ documentUniqueIdentifier: string;
21
+ } :
22
+ T extends IMBRICATE_SEARCH_TARGET_TYPE.MARKDOWN ? {
23
+ databaseUniqueIdentifier: string;
24
+ documentUniqueIdentifier: string;
25
+ propertyUniqueIdentifier: string;
26
+ lineNumber: number;
27
+ } :
28
+ never;
29
+
22
30
  export type ImbricateSearchTarget<T extends IMBRICATE_SEARCH_TARGET_TYPE> = {
31
+
23
32
  readonly type: T;
24
33
  readonly target: ImbricateSearchTargetSwitch<T>;
25
34
  };
35
+
26
36
  export type ImbricateSearchItem = {
37
+
27
38
  readonly target: ImbricateSearchTarget<IMBRICATE_SEARCH_TARGET_TYPE>;
39
+
28
40
  readonly primary: string;
41
+
29
42
  /**
30
43
  * @description Source are optional, use for source context
31
44
  */
32
45
  readonly sourceDatabaseName?: string;
33
46
  readonly sourceDocumentPrimaryKey?: string;
47
+
34
48
  /**
35
49
  * @description Previous are optional, use for previous context on the secondary object
36
50
  */
@@ -41,6 +55,8 @@ export type ImbricateSearchItem = {
41
55
  */
42
56
  readonly secondaryNext?: string[];
43
57
  };
58
+
44
59
  export type ImbricateSearchResult = {
60
+
45
61
  readonly items: ImbricateSearchItem[];
46
62
  };
@@ -3,8 +3,11 @@
3
3
  * @namespace Static
4
4
  * @description Definition
5
5
  */
6
+
6
7
  import { ImbricateAuthor } from "../author/definition";
8
+
7
9
  export type ImbricateStaticAuditOptions = {
10
+
8
11
  /**
9
12
  * Static author, this is controlled an function may vary by origin
10
13
  */
@@ -3,19 +3,24 @@
3
3
  * @namespace Static
4
4
  * @description Interface
5
5
  */
6
+
6
7
  import { ImbricateAuthor } from "../author/definition";
8
+
7
9
  export interface IImbricateStatic {
10
+
8
11
  /**
9
12
  * Unique identifier of the static object
10
13
  */
11
14
  readonly uniqueIdentifier: string;
15
+
12
16
  /**
13
17
  * Author of the text object
14
18
  */
15
19
  readonly author?: ImbricateAuthor;
20
+
16
21
  /**
17
22
  * Get the content of the static object
18
- *
23
+ *
19
24
  * @returns a promise of the content of the text, encoded in base64
20
25
  */
21
26
  getContentInBase64(): PromiseLike<string>;
@@ -3,24 +3,31 @@
3
3
  * @namespace Static
4
4
  * @description Manager
5
5
  */
6
+
6
7
  import { ImbricateStaticAuditOptions } from "./definition";
7
8
  import { IImbricateStatic } from "./interface";
9
+
8
10
  export interface IImbricateStaticManager {
11
+
9
12
  /**
10
13
  * Get the static object from the origin
11
- *
14
+ *
12
15
  * @returns a promise of the static object, null if not found
13
16
  */
14
17
  getStatic(uniqueIdentifier: string): PromiseLike<IImbricateStatic | null>;
18
+
15
19
  /**
16
20
  * Create a new static object in the origin, encoded in base64
17
21
  * Static object is immutable, once created, it cannot be changed
18
22
  * Patch a new static object if you want to change the content
19
- *
23
+ *
20
24
  * @param content content of the static object, encoded in base64
21
25
  * @param auditOptions audit options of the static object
22
- *
26
+ *
23
27
  * @returns a promise of the created static object
24
28
  */
25
- createInBase64(content: string, auditOptions?: ImbricateStaticAuditOptions): PromiseLike<IImbricateStatic>;
29
+ createInBase64(
30
+ content: string,
31
+ auditOptions?: ImbricateStaticAuditOptions,
32
+ ): PromiseLike<IImbricateStatic>;
26
33
  }
@@ -3,8 +3,11 @@
3
3
  * @namespace Text
4
4
  * @description Definition
5
5
  */
6
+
6
7
  import { ImbricateAuthor } from "../author/definition";
8
+
7
9
  export type ImbricateTextAuditOptions = {
10
+
8
11
  /**
9
12
  * Text author, this is controlled an function may vary by origin
10
13
  */