@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
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Database
5
+ * @description Validate
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.validateImbricateDocumentQuery = void 0;
9
+ const definition_1 = require("./definition");
10
+ /**
11
+ * Validate imbricate document query
12
+ *
13
+ * @param query query to validate
14
+ *
15
+ * @returns a string error message if validation failed
16
+ * null if validation passed
17
+ */
18
+ const validateImbricateDocumentQuery = (query) => {
19
+ if (typeof query !== "object") {
20
+ return "Query must be an object";
21
+ }
22
+ if (query.limit !== undefined && (typeof query.limit !== "number" || query.limit <= 0)) {
23
+ return "Limit must be a number greater than 0 or undefined";
24
+ }
25
+ if (query.skip !== undefined && (typeof query.skip !== "number" || query.skip < 0)) {
26
+ return "Skip must be a number greater than or equal to 0 or undefined";
27
+ }
28
+ if (query.propertyFilters !== undefined) {
29
+ if (!Array.isArray(query.propertyFilters)) {
30
+ return "Property filters must be an array";
31
+ }
32
+ for (const filter of query.propertyFilters) {
33
+ if (typeof filter.propertyIdentifier !== "string") {
34
+ return "Property identifier must be a string";
35
+ }
36
+ if (typeof filter.target !== "string"
37
+ || !Object.values(definition_1.IMBRICATE_QUERY_PROPERTY_CONDITION_TARGET).includes(filter.target)) {
38
+ return "Target must be a valid target";
39
+ }
40
+ if (typeof filter.attribute !== "string"
41
+ || !Object.values(definition_1.IMBRICATE_QUERY_ATTRIBUTE).includes(filter.attribute)) {
42
+ return "Attribute must be a valid attribute";
43
+ }
44
+ if (typeof filter.condition !== "string"
45
+ || !Object.values(definition_1.IMBRICATE_QUERY_COMPARE_CONDITION).includes(filter.condition)) {
46
+ return "Condition must be a valid condition";
47
+ }
48
+ }
49
+ }
50
+ if (query.annotationFilters !== undefined) {
51
+ if (!Array.isArray(query.annotationFilters)) {
52
+ return "Annotation filters must be an array";
53
+ }
54
+ for (const filter of query.annotationFilters) {
55
+ if (typeof filter.namespace !== "string") {
56
+ return "Namespace must be a string";
57
+ }
58
+ if (typeof filter.identifier !== "string") {
59
+ return "Identifier must be a string";
60
+ }
61
+ if (typeof filter.attribute !== "string"
62
+ || !Object.values(definition_1.IMBRICATE_QUERY_ATTRIBUTE).includes(filter.attribute)) {
63
+ return "Attribute must be a valid attribute";
64
+ }
65
+ if (typeof filter.condition !== "string"
66
+ || !Object.values(definition_1.IMBRICATE_QUERY_COMPARE_CONDITION).includes(filter.condition)) {
67
+ return "Condition must be a valid condition";
68
+ }
69
+ }
70
+ }
71
+ return null;
72
+ };
73
+ exports.validateImbricateDocumentQuery = validateImbricateDocumentQuery;
@@ -3,76 +3,48 @@
3
3
  * @namespace Document
4
4
  * @description Definition
5
5
  */
6
-
7
6
  import { ImbricateAuthor } from "../author/definition";
8
7
  import { DocumentPropertyKey, DocumentPropertyValue, IMBRICATE_PROPERTY_TYPE } from "./property";
9
-
10
8
  /**
11
9
  * Edit record type of the document
12
10
  */
13
- export enum IMBRICATE_DOCUMENT_EDIT_TYPE {
14
-
11
+ export declare enum IMBRICATE_DOCUMENT_EDIT_TYPE {
15
12
  PUT_PROPERTY = "PUT_PROPERTY",
16
13
  PUT_ANNOTATION = "PUT_ANNOTATION",
17
- DELETE_ANNOTATION = "DELETE_ANNOTATION",
14
+ DELETE_ANNOTATION = "DELETE_ANNOTATION"
18
15
  }
19
-
20
16
  export type DocumentEditOperationValuePutProperty = {
21
-
22
17
  readonly key: DocumentPropertyKey;
23
18
  readonly value: DocumentPropertyValue<IMBRICATE_PROPERTY_TYPE>;
24
19
  };
25
-
26
20
  export type DocumentEditOperationPutAnnotation = {
27
-
28
21
  readonly annotationNamespace: string;
29
22
  readonly annotationIdentifier: string;
30
-
31
23
  readonly data: any;
32
24
  };
33
-
34
25
  export type DocumentEditOperationDeleteAnnotation = {
35
-
36
26
  readonly annotationNamespace: string;
37
27
  readonly annotationIdentifier: string;
38
28
  };
39
-
40
- // IMBRICATE_DOCUMENT_EDIT_TYPE SWITCH
41
- export type DocumentEditOperationValue<T extends IMBRICATE_DOCUMENT_EDIT_TYPE> =
42
- T extends IMBRICATE_DOCUMENT_EDIT_TYPE.PUT_PROPERTY ? DocumentEditOperationValuePutProperty :
43
- T extends IMBRICATE_DOCUMENT_EDIT_TYPE.PUT_ANNOTATION ? DocumentEditOperationPutAnnotation :
44
- T extends IMBRICATE_DOCUMENT_EDIT_TYPE.DELETE_ANNOTATION ? DocumentEditOperationDeleteAnnotation :
45
- never;
46
-
29
+ export type DocumentEditOperationValue<T extends IMBRICATE_DOCUMENT_EDIT_TYPE> = T extends IMBRICATE_DOCUMENT_EDIT_TYPE.PUT_PROPERTY ? DocumentEditOperationValuePutProperty : T extends IMBRICATE_DOCUMENT_EDIT_TYPE.PUT_ANNOTATION ? DocumentEditOperationPutAnnotation : T extends IMBRICATE_DOCUMENT_EDIT_TYPE.DELETE_ANNOTATION ? DocumentEditOperationDeleteAnnotation : never;
47
30
  export type DocumentEditOperation<T extends IMBRICATE_DOCUMENT_EDIT_TYPE> = {
48
-
49
31
  readonly action: T;
50
32
  readonly value: DocumentEditOperationValue<T>;
51
33
  };
52
-
53
34
  export type DocumentEditRecord = {
54
-
55
35
  readonly uniqueIdentifier: string;
56
36
  readonly editAt: Date;
57
-
58
37
  readonly operations: Array<DocumentEditOperation<IMBRICATE_DOCUMENT_EDIT_TYPE>>;
59
-
60
38
  readonly author?: ImbricateAuthor;
61
39
  };
62
-
63
40
  export type DocumentAnnotations = Record<DocumentAnnotationKey, DocumentAnnotationValue>;
64
-
65
41
  export type DocumentAnnotationKey = string;
66
42
  export type DocumentAnnotationValue = {
67
-
68
43
  readonly namespace: string;
69
44
  readonly identifier: string;
70
-
71
45
  readonly data: any;
72
46
  };
73
-
74
47
  export type ImbricateDocumentAuditOptions = {
75
-
76
48
  /**
77
49
  * Do not add edit record, this is controlled an function may vary by origin
78
50
  */
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Document
5
+ * @description Definition
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.IMBRICATE_DOCUMENT_EDIT_TYPE = void 0;
9
+ /**
10
+ * Edit record type of the document
11
+ */
12
+ var IMBRICATE_DOCUMENT_EDIT_TYPE;
13
+ (function (IMBRICATE_DOCUMENT_EDIT_TYPE) {
14
+ IMBRICATE_DOCUMENT_EDIT_TYPE["PUT_PROPERTY"] = "PUT_PROPERTY";
15
+ IMBRICATE_DOCUMENT_EDIT_TYPE["PUT_ANNOTATION"] = "PUT_ANNOTATION";
16
+ IMBRICATE_DOCUMENT_EDIT_TYPE["DELETE_ANNOTATION"] = "DELETE_ANNOTATION";
17
+ })(IMBRICATE_DOCUMENT_EDIT_TYPE || (exports.IMBRICATE_DOCUMENT_EDIT_TYPE = IMBRICATE_DOCUMENT_EDIT_TYPE = {}));
@@ -3,113 +3,84 @@
3
3
  * @namespace Document
4
4
  * @description Interface
5
5
  */
6
-
7
6
  import { DocumentAnnotationValue, DocumentAnnotations, DocumentEditRecord, ImbricateDocumentAuditOptions } from "./definition";
8
7
  import { DocumentProperties, DocumentPropertyKey, DocumentPropertyValue, IMBRICATE_PROPERTY_TYPE } from "./property";
9
-
10
8
  export interface IImbricateDocument {
11
-
12
9
  /**
13
10
  * Unique identifier of the database
14
11
  */
15
12
  readonly uniqueIdentifier: string;
16
-
17
13
  /**
18
14
  * Properties of the document
19
15
  */
20
16
  readonly properties: DocumentProperties;
21
-
22
17
  /**
23
18
  * Annotations of the database
24
19
  */
25
20
  readonly annotations: DocumentAnnotations;
26
-
27
21
  /**
28
22
  * Update a property from the document
29
- *
23
+ *
30
24
  * @param key key of the property
31
25
  * @param value value of the property
32
26
  * @param auditOptions audit options of the document
33
- *
27
+ *
34
28
  * @returns a promise of the edit records of the document
35
29
  * Note: the edit records will not be added to the document if `noEditRecord` is true,
36
30
  * Call `addEditRecords` to add the edit records manually.
37
31
  */
38
- putProperty(
39
- key: DocumentPropertyKey,
40
- value: DocumentPropertyValue<IMBRICATE_PROPERTY_TYPE>,
41
- auditOptions?: ImbricateDocumentAuditOptions,
42
- ): PromiseLike<DocumentEditRecord[]>;
43
-
32
+ putProperty(key: DocumentPropertyKey, value: DocumentPropertyValue<IMBRICATE_PROPERTY_TYPE>, auditOptions?: ImbricateDocumentAuditOptions): PromiseLike<DocumentEditRecord[]>;
44
33
  /**
45
34
  * Put and replace all properties of the document
46
- *
35
+ *
47
36
  * @param properties properties of the document
48
37
  * @param auditOptions audit options of the document
49
- *
38
+ *
50
39
  * @returns a promise of the edit records of the document
51
40
  * Note: the edit records will not be added to the document if `noEditRecord` is true,
52
41
  * Call `addEditRecords` to add the edit records manually.
53
42
  */
54
- putProperties(
55
- properties: DocumentProperties,
56
- auditOptions?: ImbricateDocumentAuditOptions,
57
- ): PromiseLike<DocumentEditRecord[]>;
58
-
43
+ putProperties(properties: DocumentProperties, auditOptions?: ImbricateDocumentAuditOptions): PromiseLike<DocumentEditRecord[]>;
59
44
  /**
60
45
  * put annotation to the document
61
- *
46
+ *
62
47
  * @param namespace namespace of the annotation
63
48
  * @param identifier identifier of the annotation
64
49
  * @param value value of the annotation
65
50
  * @param auditOptions audit options of the document
66
- *
51
+ *
67
52
  * @returns a promise of the edit records of the document
68
53
  * Note: if the origin supports Document Edit Record, the edit record will be added by default
69
54
  * If you do not want to add the edit record, set `noEditRecord` to true in audit options
70
55
  */
71
- putAnnotation(
72
- namespace: string,
73
- identifier: string,
74
- value: DocumentAnnotationValue,
75
- auditOptions?: ImbricateDocumentAuditOptions,
76
- ): PromiseLike<DocumentEditRecord[]>;
77
-
56
+ putAnnotation(namespace: string, identifier: string, value: DocumentAnnotationValue, auditOptions?: ImbricateDocumentAuditOptions): PromiseLike<DocumentEditRecord[]>;
78
57
  /**
79
58
  * Delete annotation from the document
80
- *
59
+ *
81
60
  * @param namespace namespace of the annotation
82
61
  * @param identifier identifier of the annotation
83
62
  * @param auditOptions audit options of the document
84
- *
63
+ *
85
64
  * @returns a promise of the edit records of the document
86
65
  * Note: if the origin supports Document Edit Record, the edit record will be added by default
87
66
  * If you do not want to add the edit record, set `noEditRecord` to true in audit options
88
67
  */
89
- deleteAnnotation(
90
- namespace: string,
91
- identifier: string,
92
- auditOptions?: ImbricateDocumentAuditOptions,
93
- ): PromiseLike<DocumentEditRecord[]>;
94
-
68
+ deleteAnnotation(namespace: string, identifier: string, auditOptions?: ImbricateDocumentAuditOptions): PromiseLike<DocumentEditRecord[]>;
95
69
  /**
96
70
  * Add edit records to the document, optional
97
71
  * This method is optional, if not implemented, means the origin
98
72
  * 1. The origin does not support edit records
99
73
  * 2. The origin force to add edit records when put properties
100
- *
74
+ *
101
75
  * @param records document edit records
102
76
  */
103
- addEditRecords?(
104
- records: DocumentEditRecord[],
105
- ): PromiseLike<void>;
106
-
77
+ addEditRecords?(records: DocumentEditRecord[]): PromiseLike<void>;
107
78
  /**
108
79
  * Get edit records of the document, optional
109
80
  * This method is optional, if not implemented, means the origin
110
81
  * 1. The origin does not support edit records
111
82
  * 2. The origin force to add edit records when put properties
112
- *
83
+ *
113
84
  * @returns a promise of the edit records of the document
114
85
  */
115
86
  getEditRecords?(): PromiseLike<DocumentEditRecord[]>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Document
5
+ * @description Interface
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @namespace Document_Property
4
+ * @description Default Value
5
+ */
6
+ import { DocumentPropertyValueObject, IMBRICATE_PROPERTY_TYPE } from "../property";
7
+ export declare const getImbricateDefaultValueOfProperty: (type: IMBRICATE_PROPERTY_TYPE) => DocumentPropertyValueObject<IMBRICATE_PROPERTY_TYPE>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Document_Property
5
+ * @description Default Value
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.getImbricateDefaultValueOfProperty = void 0;
9
+ const property_1 = require("../property");
10
+ // IMBRICATE_PROPERTY_TYPE SWITCH
11
+ const getImbricateDefaultValueOfProperty = (type) => {
12
+ switch (type) {
13
+ case property_1.IMBRICATE_PROPERTY_TYPE.BOOLEAN: return false;
14
+ case property_1.IMBRICATE_PROPERTY_TYPE.STRING: return "";
15
+ case property_1.IMBRICATE_PROPERTY_TYPE.NUMBER: return 0;
16
+ case property_1.IMBRICATE_PROPERTY_TYPE.MARKDOWN: return "";
17
+ case property_1.IMBRICATE_PROPERTY_TYPE.JSON: return "";
18
+ case property_1.IMBRICATE_PROPERTY_TYPE.IMBRISCRIPT: return "";
19
+ case property_1.IMBRICATE_PROPERTY_TYPE.DATE: return new Date().toISOString();
20
+ case property_1.IMBRICATE_PROPERTY_TYPE.LABEL: return [];
21
+ case property_1.IMBRICATE_PROPERTY_TYPE.REFERENCE: return [];
22
+ }
23
+ return null;
24
+ };
25
+ exports.getImbricateDefaultValueOfProperty = getImbricateDefaultValueOfProperty;
@@ -3,10 +3,5 @@
3
3
  * @namespace Document_Property
4
4
  * @description Definition
5
5
  */
6
-
7
6
  import { DocumentPropertyKey, DocumentPropertyValue, IMBRICATE_PROPERTY_TYPE } from "../property";
8
-
9
- export type DocumentPropertyTriageFunction<T extends IMBRICATE_PROPERTY_TYPE, Result> = (
10
- propertyKey: DocumentPropertyKey,
11
- value: DocumentPropertyValue<T>
12
- ) => Result;
7
+ export type DocumentPropertyTriageFunction<T extends IMBRICATE_PROPERTY_TYPE, Result> = (propertyKey: DocumentPropertyKey, value: DocumentPropertyValue<T>) => Result;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Document_Property
5
+ * @description Definition
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @namespace Document_Property
4
+ * @description Primary
5
+ */
6
+ import { ImbricateDatabaseSchema } from "../../database/schema";
7
+ import { DocumentProperties, DocumentPropertyValue, IMBRICATE_PROPERTY_TYPE } from "../property";
8
+ export declare const findPrimaryProperty: (schema: ImbricateDatabaseSchema, properties: DocumentProperties) => DocumentPropertyValue<IMBRICATE_PROPERTY_TYPE> | null;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Document_Property
5
+ * @description Primary
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.findPrimaryProperty = void 0;
9
+ const findPrimaryProperty = (schema, properties) => {
10
+ for (const property of schema.properties) {
11
+ if (property.isPrimaryKey) {
12
+ const value = properties[property.propertyIdentifier];
13
+ if (value) {
14
+ return value;
15
+ }
16
+ }
17
+ }
18
+ return null;
19
+ };
20
+ exports.findPrimaryProperty = findPrimaryProperty;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @namespace Document_Property
4
+ * @description Triage Base
5
+ */
6
+ import { DocumentProperties, DocumentPropertyKey, IMBRICATE_PROPERTY_TYPE } from "../property";
7
+ import { DocumentPropertyTriageFunction } from "./definition";
8
+ export declare class ImbricateDocumentPropertyTriageBase<Result> {
9
+ private readonly _triageFunctionsByKey;
10
+ private readonly _triageFunctionsByType;
11
+ protected constructor();
12
+ /**
13
+ * Set triage function for property key,
14
+ * This action will override document value based triage functions
15
+ *
16
+ * @param propertyKey property key
17
+ * @param triageFunction triage function
18
+ * @returns triage manager
19
+ */
20
+ forPropertyKey<T extends IMBRICATE_PROPERTY_TYPE>(propertyKey: DocumentPropertyKey, triageFunction: DocumentPropertyTriageFunction<T, Result>): this;
21
+ forBoolean(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.BOOLEAN, Result>): this;
22
+ forString(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.STRING, Result>): this;
23
+ forNumber(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.NUMBER, Result>): this;
24
+ forMarkdown(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.MARKDOWN, Result>): this;
25
+ forJson(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.JSON, Result>): this;
26
+ forImbriscript(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.IMBRISCRIPT, Result>): this;
27
+ forDate(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.DATE, Result>): this;
28
+ forLabel(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.LABEL, Result>): this;
29
+ forReference(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.REFERENCE, Result>): this;
30
+ protected _collect(properties: DocumentProperties): Map<DocumentPropertyKey, Result>;
31
+ }
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Document_Property
5
+ * @description Triage Base
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.ImbricateDocumentPropertyTriageBase = void 0;
9
+ const property_1 = require("../property");
10
+ // IMBRICATE_PROPERTY_TYPE SWITCH
11
+ class ImbricateDocumentPropertyTriageBase {
12
+ constructor() {
13
+ this._triageFunctionsByKey = new Map();
14
+ this._triageFunctionsByType = new Map();
15
+ }
16
+ /**
17
+ * Set triage function for property key,
18
+ * This action will override document value based triage functions
19
+ *
20
+ * @param propertyKey property key
21
+ * @param triageFunction triage function
22
+ * @returns triage manager
23
+ */
24
+ forPropertyKey(propertyKey, triageFunction) {
25
+ this._triageFunctionsByKey.set(propertyKey, triageFunction);
26
+ return this;
27
+ }
28
+ forBoolean(triageFunction) {
29
+ this._triageFunctionsByType.set(property_1.IMBRICATE_PROPERTY_TYPE.BOOLEAN, triageFunction);
30
+ return this;
31
+ }
32
+ forString(triageFunction) {
33
+ this._triageFunctionsByType.set(property_1.IMBRICATE_PROPERTY_TYPE.STRING, triageFunction);
34
+ return this;
35
+ }
36
+ forNumber(triageFunction) {
37
+ this._triageFunctionsByType.set(property_1.IMBRICATE_PROPERTY_TYPE.NUMBER, triageFunction);
38
+ return this;
39
+ }
40
+ forMarkdown(triageFunction) {
41
+ this._triageFunctionsByType.set(property_1.IMBRICATE_PROPERTY_TYPE.MARKDOWN, triageFunction);
42
+ return this;
43
+ }
44
+ forJson(triageFunction) {
45
+ this._triageFunctionsByType.set(property_1.IMBRICATE_PROPERTY_TYPE.JSON, triageFunction);
46
+ return this;
47
+ }
48
+ forImbriscript(triageFunction) {
49
+ this._triageFunctionsByType.set(property_1.IMBRICATE_PROPERTY_TYPE.IMBRISCRIPT, triageFunction);
50
+ return this;
51
+ }
52
+ forDate(triageFunction) {
53
+ this._triageFunctionsByType.set(property_1.IMBRICATE_PROPERTY_TYPE.DATE, triageFunction);
54
+ return this;
55
+ }
56
+ forLabel(triageFunction) {
57
+ this._triageFunctionsByType.set(property_1.IMBRICATE_PROPERTY_TYPE.LABEL, triageFunction);
58
+ return this;
59
+ }
60
+ forReference(triageFunction) {
61
+ this._triageFunctionsByType.set(property_1.IMBRICATE_PROPERTY_TYPE.REFERENCE, triageFunction);
62
+ return this;
63
+ }
64
+ _collect(properties) {
65
+ const keys = Object.keys(properties);
66
+ const result = new Map();
67
+ for (const key of keys) {
68
+ const property = properties[key];
69
+ const triageFunction = this._triageFunctionsByKey.get(key);
70
+ if (typeof triageFunction === "function") {
71
+ const value = triageFunction(key, property);
72
+ result.set(key, value);
73
+ continue;
74
+ }
75
+ const typeFunction = this._triageFunctionsByType.get(property.type);
76
+ if (typeof typeFunction === "function") {
77
+ const value = typeFunction(key, property);
78
+ result.set(key, value);
79
+ continue;
80
+ }
81
+ }
82
+ return result;
83
+ }
84
+ }
85
+ exports.ImbricateDocumentPropertyTriageBase = ImbricateDocumentPropertyTriageBase;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @namespace Document_Property
4
+ * @description Triage Manager
5
+ */
6
+ import { DocumentProperties, DocumentPropertyKey } from "../property";
7
+ import { ImbricateDocumentPropertyTriageBase } from "./triage-base";
8
+ export declare class ImbricateDocumentPropertyTriageManager<Result> extends ImbricateDocumentPropertyTriageBase<Result> {
9
+ static create<Result>(properties: DocumentProperties): ImbricateDocumentPropertyTriageManager<Result>;
10
+ private readonly _properties;
11
+ private constructor();
12
+ /**
13
+ * Collect the result as array
14
+ *
15
+ * @returns collected result as array
16
+ */
17
+ collectAsArray(): Result[];
18
+ /**
19
+ * Collect the result as map
20
+ *
21
+ * @returns collected result as map
22
+ */
23
+ collectAsMap(): Map<DocumentPropertyKey, Result>;
24
+ /**
25
+ * Collect the result as object
26
+ *
27
+ * @returns collected result as object
28
+ */
29
+ collectAsObject(): Record<DocumentPropertyKey, Result>;
30
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Document_Property
5
+ * @description Triage Manager
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.ImbricateDocumentPropertyTriageManager = void 0;
9
+ const triage_base_1 = require("./triage-base");
10
+ class ImbricateDocumentPropertyTriageManager extends triage_base_1.ImbricateDocumentPropertyTriageBase {
11
+ static create(properties) {
12
+ return new ImbricateDocumentPropertyTriageManager(properties);
13
+ }
14
+ constructor(properties) {
15
+ super();
16
+ this._properties = properties;
17
+ }
18
+ /**
19
+ * Collect the result as array
20
+ *
21
+ * @returns collected result as array
22
+ */
23
+ collectAsArray() {
24
+ const result = super._collect(this._properties);
25
+ return Array.from(result.values());
26
+ }
27
+ /**
28
+ * Collect the result as map
29
+ *
30
+ * @returns collected result as map
31
+ */
32
+ collectAsMap() {
33
+ return super._collect(this._properties);
34
+ }
35
+ /**
36
+ * Collect the result as object
37
+ *
38
+ * @returns collected result as object
39
+ */
40
+ collectAsObject() {
41
+ const result = super._collect(this._properties);
42
+ const keys = Array.from(result.keys());
43
+ const object = {};
44
+ for (const key of keys) {
45
+ object[key] = result.get(key);
46
+ }
47
+ return object;
48
+ }
49
+ }
50
+ exports.ImbricateDocumentPropertyTriageManager = ImbricateDocumentPropertyTriageManager;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @namespace Document_Property
4
+ * @description Triage
5
+ */
6
+ import { DocumentProperties } from "../property";
7
+ import { ImbricateDocumentPropertyTriageManager } from "./triage-manager";
8
+ export declare const triageImbricateDocumentProperties: <Result>(properties: DocumentProperties) => ImbricateDocumentPropertyTriageManager<Result>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Document_Property
5
+ * @description Triage
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.triageImbricateDocumentProperties = void 0;
9
+ const triage_manager_1 = require("./triage-manager");
10
+ const triageImbricateDocumentProperties = (properties) => {
11
+ return triage_manager_1.ImbricateDocumentPropertyTriageManager.create(properties);
12
+ };
13
+ exports.triageImbricateDocumentProperties = triageImbricateDocumentProperties;