@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
package/.yarnrc.yml DELETED
@@ -1,3 +0,0 @@
1
- nodeLinker: node-modules
2
-
3
- yarnPath: .yarn/releases/yarn-4.4.0.cjs
package/babel.config.js DELETED
@@ -1,14 +0,0 @@
1
- module.exports = {
2
- presets: [
3
- [
4
- "@babel/preset-env",
5
- {
6
- targets:
7
- {
8
- node: "current",
9
- },
10
- },
11
- ],
12
- "@babel/preset-typescript",
13
- ],
14
- };
package/docs/README.md DELETED
@@ -1,70 +0,0 @@
1
- # Imbricate ▦
2
-
3
- ```
4
- ┌───────┐
5
- │ I M B │
6
- │ R I C │
7
- │ A T E │
8
- └───────┘
9
- ```
10
-
11
- [![Continuous Integration](https://github.com/Imbricate/Imbricate/actions/workflows/ci.yml/badge.svg)](https://github.com/Imbricate/Imbricate/actions/workflows/ci.yml)
12
- [![codecov](https://codecov.io/gh/Imbricate/Imbricate/branch/main/graph/badge.svg)](https://codecov.io/gh/Imbricate/Imbricate)
13
- [![npm version](https://badge.fury.io/js/%40imbricate%2Fcore.svg)](https://badge.fury.io/js/%40imbricate%2Fcore)
14
- [![downloads](https://img.shields.io/npm/dm/@imbricate/core.svg)](https://www.npmjs.com/package/@imbricate/core)
15
-
16
- Yes to accountable notes, no to external hosting. Free, for everyone.
17
-
18
- ## Install
19
-
20
- ```sh
21
- yarn add @imbricate/core
22
- # Or
23
- npm install @imbricate/core --save
24
- ```
25
-
26
- ## Documentation
27
-
28
- Visit [imbricate.io](https://imbricate.io/).
29
-
30
- ## Quick Start with Imbricate VSCode Extension
31
-
32
- Imbricate VSCode Extension is available through the Visual Studio Code Marketplace. See [Imbricate VSCode Extension](https://marketplace.visualstudio.com/items?itemName=imbricate.imbricate).
33
-
34
- ## Quick Start with Imbricate CLI
35
-
36
- Imbricate CLI is available through NPM for package management. See https://github.com/imbricate/Imbricate-CLI.
37
-
38
- To install Imbricate CLI:
39
-
40
- ### Using Yarn
41
-
42
- Yarn 1.x
43
-
44
- ```sh
45
- yarn global add imbricate
46
- ```
47
-
48
- Yarn 2.x
49
-
50
- ```sh
51
- yarn dlx imbricate
52
- ```
53
-
54
- ### Using NPM
55
-
56
- ```sh
57
- npm install -g imbricate
58
- ```
59
-
60
- ## Usage
61
-
62
- ```sh
63
- imbricate --help
64
- ```
65
-
66
- ```
67
- ┌─────────────────────┐
68
- │ I M B R I C A T E ▦ │
69
- └─────────────────────┘
70
- ```
package/eslint.config.mjs DELETED
@@ -1,64 +0,0 @@
1
- import typescriptEslint from "@typescript-eslint/eslint-plugin";
2
- import typescriptParser from "@typescript-eslint/parser";
3
-
4
- export default [
5
- {
6
- files: ["**/*.{ts,tsx}"],
7
- languageOptions: {
8
- parser: typescriptParser,
9
- parserOptions: {
10
- sourceType: "module",
11
- },
12
- },
13
- },
14
- {
15
- plugins: {
16
- "@typescript-eslint": typescriptEslint,
17
- },
18
- rules: {
19
- "@typescript-eslint/no-explicit-any": "off",
20
- "@typescript-eslint/no-unused-vars": [
21
- "error",
22
- {
23
- "argsIgnorePattern": "^_",
24
- },
25
- ],
26
- "comma-dangle": [
27
- "error",
28
- {
29
- arrays: "always-multiline",
30
- objects: "always-multiline",
31
- functions: "always-multiline",
32
- imports: "always-multiline",
33
- exports: "always-multiline",
34
- },
35
- ],
36
- "sort-imports": [
37
- "error",
38
- {
39
- ignoreCase: false,
40
- ignoreDeclarationSort: true,
41
- ignoreMemberSort: false,
42
- allowSeparatedGroups: false,
43
- memberSyntaxSortOrder: [
44
- "none",
45
- "all",
46
- "multiple",
47
- "single",
48
- ],
49
- },
50
- ],
51
- quotes: [
52
- "error",
53
- "double",
54
- {
55
- avoidEscape: true,
56
- },
57
- ],
58
- semi: [
59
- "error",
60
- "always",
61
- ],
62
- },
63
- },
64
- ];
package/jest.config.ts DELETED
@@ -1,14 +0,0 @@
1
- import type { Config } from "jest";
2
-
3
- export default async (): Promise<Config> => {
4
- return {
5
- verbose: true,
6
- collectCoverageFrom: [
7
- "src/**/*.ts",
8
- ],
9
- coverageReporters: [
10
- "json",
11
- "text-summary",
12
- ],
13
- };
14
- };
@@ -1,165 +0,0 @@
1
- /**
2
- * @author WMXPY
3
- * @namespace Database
4
- * @description Schema
5
- */
6
-
7
- import { IMBRICATE_PROPERTY_TYPE } from "../document/property";
8
-
9
- export type ImbricateDatabaseSchemaProperty<T extends IMBRICATE_PROPERTY_TYPE> = {
10
-
11
- readonly propertyIdentifier: string;
12
- } & ImbricateDatabaseSchemaPropertyForCreation<T>;
13
-
14
- export type ImbricateDatabaseSchemaPropertyOptionsReferenceDatabase = {
15
-
16
- readonly originUniqueIdentifier: string;
17
- readonly databaseUniqueIdentifier: string;
18
- };
19
-
20
- export type ImbricateDatabaseSchemaPropertyOptionsLabelOption = {
21
-
22
- readonly labelIdentifier: string;
23
- readonly labelName: string;
24
-
25
- readonly labelColor: string;
26
- };
27
-
28
- export type ImbricateDatabaseSchemaPropertyOptionsLabel = {
29
-
30
- /**
31
- * Allow multiple labels
32
- */
33
- readonly allowMultiple: boolean;
34
- /**
35
- * Label Options
36
- */
37
- readonly labelOptions: ImbricateDatabaseSchemaPropertyOptionsLabelOption[];
38
- };
39
-
40
- export type ImbricateDatabaseSchemaPropertyOptionsReference = {
41
-
42
- /**
43
- * Allow multiple references
44
- */
45
- readonly allowMultiple: boolean;
46
- /**
47
- * Allow references from these databases
48
- * If empty, allow references from all databases
49
- */
50
- readonly databases: ImbricateDatabaseSchemaPropertyOptionsReferenceDatabase[];
51
- };
52
-
53
- // IMBRICATE_PROPERTY_TYPE SWITCH
54
- export type ImbricateDatabaseSchemaPropertyOptions<T extends IMBRICATE_PROPERTY_TYPE> =
55
- T extends IMBRICATE_PROPERTY_TYPE.BOOLEAN ? {} :
56
- T extends IMBRICATE_PROPERTY_TYPE.STRING ? {} :
57
- T extends IMBRICATE_PROPERTY_TYPE.NUMBER ? {} :
58
- T extends IMBRICATE_PROPERTY_TYPE.MARKDOWN ? {} :
59
- T extends IMBRICATE_PROPERTY_TYPE.JSON ? {} :
60
- T extends IMBRICATE_PROPERTY_TYPE.IMBRISCRIPT ? {} :
61
- T extends IMBRICATE_PROPERTY_TYPE.DATE ? {} :
62
- T extends IMBRICATE_PROPERTY_TYPE.LABEL ? ImbricateDatabaseSchemaPropertyOptionsLabel :
63
- T extends IMBRICATE_PROPERTY_TYPE.REFERENCE ? ImbricateDatabaseSchemaPropertyOptionsReference :
64
- never;
65
-
66
- export type ImbricateDatabaseSchemaPropertyForCreation<T extends IMBRICATE_PROPERTY_TYPE> = {
67
-
68
- readonly propertyName: string;
69
- readonly propertyType: T;
70
- readonly propertyOptions: ImbricateDatabaseSchemaPropertyOptions<T>;
71
-
72
- readonly isPrimaryKey?: boolean;
73
- };
74
-
75
- export type ImbricateDatabaseSchema = {
76
-
77
- readonly properties: Array<ImbricateDatabaseSchemaProperty<IMBRICATE_PROPERTY_TYPE>>
78
- };
79
-
80
- export type ImbricateDatabaseSchemaForCreation = {
81
-
82
- readonly properties: Array<ImbricateDatabaseSchemaPropertyForCreation<IMBRICATE_PROPERTY_TYPE>>
83
- };
84
-
85
- /**
86
- * Validate a schema property
87
- *
88
- * @param property property to validate
89
- *
90
- * @returns a string error message if validation failed
91
- * null if validation passed
92
- */
93
- export const validateImbricateSchemaProperty = (
94
- property: ImbricateDatabaseSchemaProperty<IMBRICATE_PROPERTY_TYPE>,
95
- ): string | null => {
96
-
97
- if (typeof property.propertyIdentifier !== "string") {
98
- return "Property identifier must be a string";
99
- }
100
- if (typeof property.propertyName !== "string") {
101
- return "Property name must be a string";
102
- }
103
- if (!Object.values(IMBRICATE_PROPERTY_TYPE).includes(property.propertyType)) {
104
- return "Property type must be a valid type";
105
- }
106
-
107
- switch (property.propertyType) {
108
-
109
- case IMBRICATE_PROPERTY_TYPE.REFERENCE: {
110
- if (typeof property.propertyOptions !== "object") {
111
- return "Property options must be an object";
112
- }
113
- if (typeof (property.propertyOptions as any).allowMultiple !== "boolean") {
114
- return "Property options allowMultiple must be a boolean";
115
- }
116
- if (!Array.isArray((property.propertyOptions as any).databases)) {
117
- return "Property options databases must be an array";
118
- }
119
- for (const database of (property.propertyOptions as any).databases) {
120
- if (typeof database.originUniqueIdentifier !== "string") {
121
- return "Database originUniqueIdentifier must be a string";
122
- }
123
- if (typeof database.databaseUniqueIdentifier !== "string") {
124
- return "Database databaseUniqueIdentifier must be a string";
125
- }
126
- }
127
- break;
128
- }
129
- }
130
-
131
- return null;
132
- };
133
-
134
- /**
135
- * Validate a schema
136
- *
137
- * @param schema database schema to validate
138
- *
139
- * @returns a string error message if validation failed
140
- * null if validation passed
141
- */
142
- export const validateImbricateSchema = (
143
- schema: ImbricateDatabaseSchema,
144
- ): string | null => {
145
-
146
- if (!Array.isArray(schema.properties)) {
147
- return "Properties must be an array";
148
- }
149
-
150
- const propertyNames: Set<string> = new Set();
151
- for (const property of schema.properties) {
152
-
153
- const propertyValidationResult: string | null = validateImbricateSchemaProperty(property);
154
- if (typeof propertyValidationResult === "string") {
155
- return `Invalid property ${property.propertyName}, ${propertyValidationResult}`;
156
- }
157
-
158
- if (propertyNames.has(property.propertyName)) {
159
- return `Duplicated property name ${property.propertyName}`;
160
- }
161
- propertyNames.add(property.propertyName);
162
- }
163
-
164
- return null;
165
- };
@@ -1,77 +0,0 @@
1
- /**
2
- * @author WMXPY
3
- * @namespace Database
4
- * @description Validate
5
- */
6
-
7
- import { ImbricateDocumentQuery } from "./definition";
8
-
9
- /**
10
- * Validate imbricate document query
11
- *
12
- * @param query query to validate
13
- *
14
- * @returns a string error message if validation failed
15
- * null if validation passed
16
- */
17
- export const validateImbricateDocumentQuery = (query: ImbricateDocumentQuery): string | null => {
18
-
19
- if (typeof query !== "object") {
20
- return "Query must be an object";
21
- }
22
-
23
- if (query.limit !== undefined && typeof query.limit !== "number" && query.limit <= 0) {
24
- return "Limit must be a number greater than 0 or undefined";
25
- }
26
- if (query.skip !== undefined && typeof query.skip !== "number" && query.skip < 0) {
27
- return "Skip must be a number greater than or equal to 0 or undefined";
28
- }
29
-
30
- if (query.propertyFilters !== undefined) {
31
- if (!Array.isArray(query.propertyFilters)) {
32
- return "Property filters must be an array";
33
- }
34
-
35
- for (const filter of query.propertyFilters) {
36
-
37
- if (typeof filter.propertyIdentifier !== "string") {
38
- return "Property identifier must be a string";
39
- }
40
-
41
- if (!Array.isArray(filter.conditions)) {
42
- return "Conditions must be an array";
43
- }
44
-
45
- for (const condition of filter.conditions) {
46
-
47
- if (typeof condition.target !== "string") {
48
- return "Target must be a string";
49
- }
50
- if (typeof condition.condition !== "string") {
51
- return "Condition must be a string";
52
- }
53
- }
54
- }
55
- }
56
-
57
- if (query.annotationFilters !== undefined) {
58
- if (!Array.isArray(query.annotationFilters)) {
59
- return "Annotation filters must be an array";
60
- }
61
-
62
- for (const filter of query.annotationFilters) {
63
-
64
- if (typeof filter.namespace !== "string") {
65
- return "Namespace must be a string";
66
- }
67
- if (typeof filter.identifier !== "string") {
68
- return "Identifier must be a string";
69
- }
70
- if (typeof filter.condition !== "string") {
71
- return "Condition must be a string";
72
- }
73
- }
74
- }
75
-
76
- return null;
77
- };
@@ -1,26 +0,0 @@
1
- /**
2
- * @author WMXPY
3
- * @namespace Document_Property
4
- * @description Default Value
5
- */
6
-
7
- import { DocumentPropertyValueObject, IMBRICATE_PROPERTY_TYPE } from "../property";
8
-
9
- // IMBRICATE_PROPERTY_TYPE SWITCH
10
- export const getImbricateDefaultValueOfProperty = (type: IMBRICATE_PROPERTY_TYPE): DocumentPropertyValueObject<IMBRICATE_PROPERTY_TYPE> => {
11
-
12
- switch (type) {
13
-
14
- case IMBRICATE_PROPERTY_TYPE.BOOLEAN: return false;
15
- case IMBRICATE_PROPERTY_TYPE.STRING: return "";
16
- case IMBRICATE_PROPERTY_TYPE.NUMBER: return 0;
17
- case IMBRICATE_PROPERTY_TYPE.MARKDOWN: return "";
18
- case IMBRICATE_PROPERTY_TYPE.JSON: return "";
19
- case IMBRICATE_PROPERTY_TYPE.IMBRISCRIPT: return "";
20
- case IMBRICATE_PROPERTY_TYPE.DATE: return new Date().toISOString();
21
- case IMBRICATE_PROPERTY_TYPE.LABEL: return [];
22
- case IMBRICATE_PROPERTY_TYPE.REFERENCE: return [];
23
- }
24
-
25
- return null as any;
26
- };
@@ -1,29 +0,0 @@
1
- /**
2
- * @author WMXPY
3
- * @namespace Document_Property
4
- * @description Primary
5
- */
6
-
7
- import { ImbricateDatabaseSchema } from "../../database/schema";
8
- import { DocumentProperties, DocumentPropertyValue, IMBRICATE_PROPERTY_TYPE } from "../property";
9
-
10
- export const findPrimaryProperty = (
11
- schema: ImbricateDatabaseSchema,
12
- properties: DocumentProperties,
13
- ): DocumentPropertyValue<IMBRICATE_PROPERTY_TYPE> | null => {
14
-
15
- for (const property of schema.properties) {
16
-
17
- if (property.isPrimaryKey) {
18
-
19
- const value: DocumentPropertyValue<IMBRICATE_PROPERTY_TYPE> | undefined =
20
- properties[property.propertyIdentifier];
21
-
22
- if (value) {
23
- return value;
24
- }
25
- }
26
- }
27
-
28
- return null;
29
- };
@@ -1,138 +0,0 @@
1
- /**
2
- * @author WMXPY
3
- * @namespace Document_Property
4
- * @description Triage Base
5
- */
6
-
7
- import { DocumentProperties, DocumentPropertyKey, IMBRICATE_PROPERTY_TYPE } from "../property";
8
- import { DocumentPropertyTriageFunction } from "./definition";
9
-
10
- // IMBRICATE_PROPERTY_TYPE SWITCH
11
- export class ImbricateDocumentPropertyTriageBase<Result> {
12
-
13
- private readonly _triageFunctionsByKey: Map<string, DocumentPropertyTriageFunction<any, Result>>;
14
- private readonly _triageFunctionsByType: Map<IMBRICATE_PROPERTY_TYPE, DocumentPropertyTriageFunction<any, Result>>;
15
-
16
- protected constructor() {
17
-
18
- this._triageFunctionsByKey = new Map();
19
- this._triageFunctionsByType = new Map();
20
- }
21
-
22
- /**
23
- * Set triage function for property key,
24
- * This action will override document value based triage functions
25
- *
26
- * @param propertyKey property key
27
- * @param triageFunction triage function
28
- * @returns triage manager
29
- */
30
- public forPropertyKey<T extends IMBRICATE_PROPERTY_TYPE>(
31
- propertyKey: DocumentPropertyKey,
32
- triageFunction: DocumentPropertyTriageFunction<T, Result>,
33
- ): this {
34
-
35
- this._triageFunctionsByKey.set(propertyKey, triageFunction);
36
- return this;
37
- }
38
-
39
- public forBoolean(
40
- triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.BOOLEAN, Result>,
41
- ): this {
42
-
43
- this._triageFunctionsByType.set(IMBRICATE_PROPERTY_TYPE.BOOLEAN, triageFunction);
44
- return this;
45
- }
46
-
47
- public forString(
48
- triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.STRING, Result>,
49
- ): this {
50
-
51
- this._triageFunctionsByType.set(IMBRICATE_PROPERTY_TYPE.STRING, triageFunction);
52
- return this;
53
- }
54
-
55
- public forNumber(
56
- triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.NUMBER, Result>,
57
- ): this {
58
-
59
- this._triageFunctionsByType.set(IMBRICATE_PROPERTY_TYPE.NUMBER, triageFunction);
60
- return this;
61
- }
62
-
63
- public forMarkdown(
64
- triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.MARKDOWN, Result>,
65
- ): this {
66
-
67
- this._triageFunctionsByType.set(IMBRICATE_PROPERTY_TYPE.MARKDOWN, triageFunction);
68
- return this;
69
- }
70
-
71
- public forJson(
72
- triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.JSON, Result>,
73
- ): this {
74
-
75
- this._triageFunctionsByType.set(IMBRICATE_PROPERTY_TYPE.JSON, triageFunction);
76
- return this;
77
- }
78
-
79
- public forImbriscript(
80
- triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.IMBRISCRIPT, Result>,
81
- ): this {
82
-
83
- this._triageFunctionsByType.set(IMBRICATE_PROPERTY_TYPE.IMBRISCRIPT, triageFunction);
84
- return this;
85
- }
86
-
87
- public forDate(
88
- triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.DATE, Result>,
89
- ): this {
90
-
91
- this._triageFunctionsByType.set(IMBRICATE_PROPERTY_TYPE.DATE, triageFunction);
92
- return this;
93
- }
94
-
95
- public forLabel(
96
- triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.LABEL, Result>,
97
- ): this {
98
-
99
- this._triageFunctionsByType.set(IMBRICATE_PROPERTY_TYPE.LABEL, triageFunction);
100
- return this;
101
- }
102
-
103
- public forReference(
104
- triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.REFERENCE, Result>,
105
- ): this {
106
-
107
- this._triageFunctionsByType.set(IMBRICATE_PROPERTY_TYPE.REFERENCE, triageFunction);
108
- return this;
109
- }
110
-
111
- protected _collect(properties: DocumentProperties): Map<DocumentPropertyKey, Result> {
112
-
113
- const keys: DocumentPropertyKey[] = Object.keys(properties);
114
- const result: Map<DocumentPropertyKey, Result> = new Map();
115
- for (const key of keys) {
116
-
117
- const property = properties[key];
118
- const triageFunction = this._triageFunctionsByKey.get(key);
119
-
120
- if (typeof triageFunction === "function") {
121
-
122
- const value: Result = triageFunction(key, property);
123
- result.set(key, value);
124
- continue;
125
- }
126
-
127
- const typeFunction = this._triageFunctionsByType.get(property.type);
128
- if (typeof typeFunction === "function") {
129
-
130
- const value: Result = typeFunction(key, property);
131
- result.set(key, value);
132
- continue;
133
- }
134
- }
135
-
136
- return result;
137
- }
138
- }
@@ -1,68 +0,0 @@
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
- }
@@ -1,15 +0,0 @@
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
- };