@imbricate/core 3.8.0 → 3.8.1

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 (83) 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} +8 -47
  4. package/database/definition.js +26 -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/{src/database/validate.ts → database/validate.js} +7 -18
  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/document/property/default-value.ts +0 -26
  73. package/src/document/property/primary.ts +0 -29
  74. package/src/document/property/triage-base.ts +0 -138
  75. package/src/document/property/triage-manager.ts +0 -68
  76. package/src/document/property/triage.ts +0 -15
  77. package/src/loader/origin-loader.ts +0 -88
  78. package/test/unit/database/schema.test.ts +0 -95
  79. package/test/unit/document/property/primary.test.ts +0 -87
  80. package/test/unit/document/property/triage.test.ts +0 -64
  81. package/test/unit/document/validate.test.ts +0 -138
  82. package/test/unit/loader/definition.test.ts +0 -55
  83. package/typescript/tsconfig.build.json +0 -23
@@ -3,13 +3,9 @@
3
3
  * @namespace Author
4
4
  * @description Definition
5
5
  */
6
-
7
6
  export type ImbricateAuthor = {
8
-
9
7
  readonly category: string;
10
8
  readonly identifier: string;
11
-
12
9
  readonly isAutomation: boolean;
13
-
14
10
  readonly onBehalfOf?: ImbricateAuthor;
15
11
  };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Author
5
+ * @description Definition
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -3,117 +3,78 @@
3
3
  * @namespace Database
4
4
  * @description Definition
5
5
  */
6
-
7
6
  import { ImbricateAuthor } from "../author/definition";
8
7
  import { ImbricateDatabaseSchema } from "./schema";
9
-
10
- export enum IMBRICATE_QUERY_COMPARE_CONDITION {
11
-
12
- EQUAL = "EQUAL",
8
+ export declare enum IMBRICATE_QUERY_COMPARE_CONDITION {
9
+ EQUAL = "EQUAL"
13
10
  }
14
-
15
- export enum IMBRICATE_QUERY_PROPERTY_CONDITION_TARGET {
16
-
11
+ export declare enum IMBRICATE_QUERY_PROPERTY_CONDITION_TARGET {
17
12
  PROPERTY_TYPE = "PROPERTY_TYPE",
18
- PROPERTY_VALUE = "PROPERTY_VALUE",
13
+ PROPERTY_VALUE = "PROPERTY_VALUE"
19
14
  }
20
-
21
15
  export type ImbricateDocumentQueryPropertyFilterCondition = {
22
-
23
16
  readonly target: IMBRICATE_QUERY_PROPERTY_CONDITION_TARGET;
24
17
  readonly condition: IMBRICATE_QUERY_COMPARE_CONDITION;
25
18
  readonly value: any;
26
19
  };
27
-
28
20
  export type ImbricateDocumentQueryPropertyFilter = {
29
-
30
21
  readonly propertyIdentifier: string;
31
22
  readonly conditions: ImbricateDocumentQueryPropertyFilterCondition[];
32
23
  };
33
-
34
24
  export type ImbricateDocumentQueryAnnotationFilter = {
35
-
36
25
  readonly namespace: string;
37
26
  readonly identifier: string;
38
27
  readonly condition: IMBRICATE_QUERY_COMPARE_CONDITION;
39
28
  readonly value: any;
40
29
  };
41
-
42
30
  /**
43
31
  * Query of the document
44
- *
32
+ *
45
33
  * @param limit limit of the query
46
34
  * @param skip skip of the query
47
35
  */
48
36
  export type ImbricateDocumentQuery = {
49
-
50
37
  readonly limit?: number;
51
38
  readonly skip?: number;
52
-
53
39
  readonly propertyFilters?: ImbricateDocumentQueryPropertyFilter[];
54
40
  readonly annotationFilters?: ImbricateDocumentQueryAnnotationFilter[];
55
41
  };
56
-
57
42
  /**
58
43
  * Edit record type of the document
59
44
  */
60
- export enum IMBRICATE_DATABASE_EDIT_TYPE {
61
-
45
+ export declare enum IMBRICATE_DATABASE_EDIT_TYPE {
62
46
  PUT_SCHEMA = "PUT_SCHEMA",
63
47
  PUT_ANNOTATION = "PUT_ANNOTATION",
64
- DELETE_ANNOTATION = "DELETE_ANNOTATION",
48
+ DELETE_ANNOTATION = "DELETE_ANNOTATION"
65
49
  }
66
-
67
50
  export type DatabaseEditOperationPutAnnotation = {
68
-
69
51
  readonly annotationNamespace: string;
70
52
  readonly annotationIdentifier: string;
71
-
72
53
  readonly data: any;
73
54
  };
74
-
75
55
  export type DatabaseEditOperationDeleteAnnotation = {
76
-
77
56
  readonly annotationNamespace: string;
78
57
  readonly annotationIdentifier: string;
79
58
  };
80
-
81
- // IMBRICATE_DATABASE_EDIT_TYPE SWITCH
82
- export type DatabaseEditOperationValue<T extends IMBRICATE_DATABASE_EDIT_TYPE> =
83
- T extends IMBRICATE_DATABASE_EDIT_TYPE.PUT_SCHEMA ? ImbricateDatabaseSchema :
84
- T extends IMBRICATE_DATABASE_EDIT_TYPE.PUT_ANNOTATION ? DatabaseEditOperationPutAnnotation :
85
- T extends IMBRICATE_DATABASE_EDIT_TYPE.DELETE_ANNOTATION ? DatabaseEditOperationDeleteAnnotation :
86
- never;
87
-
59
+ export type DatabaseEditOperationValue<T extends IMBRICATE_DATABASE_EDIT_TYPE> = T extends IMBRICATE_DATABASE_EDIT_TYPE.PUT_SCHEMA ? ImbricateDatabaseSchema : T extends IMBRICATE_DATABASE_EDIT_TYPE.PUT_ANNOTATION ? DatabaseEditOperationPutAnnotation : T extends IMBRICATE_DATABASE_EDIT_TYPE.DELETE_ANNOTATION ? DatabaseEditOperationDeleteAnnotation : never;
88
60
  export type DatabaseEditOperation<T extends IMBRICATE_DATABASE_EDIT_TYPE> = {
89
-
90
61
  readonly action: T;
91
62
  readonly value: DatabaseEditOperationValue<T>;
92
63
  };
93
-
94
64
  export type DatabaseEditRecord = {
95
-
96
65
  readonly uniqueIdentifier: string;
97
66
  readonly editAt: Date;
98
-
99
67
  readonly operations: Array<DatabaseEditOperation<IMBRICATE_DATABASE_EDIT_TYPE>>;
100
-
101
68
  readonly author?: ImbricateAuthor;
102
69
  };
103
-
104
70
  export type DatabaseAnnotations = Record<DatabaseAnnotationKey, DatabaseAnnotationValue>;
105
-
106
71
  export type DatabaseAnnotationKey = string;
107
72
  export type DatabaseAnnotationValue = {
108
-
109
73
  readonly namespace: string;
110
74
  readonly identifier: string;
111
-
112
75
  readonly data: any;
113
76
  };
114
-
115
77
  export type ImbricateDatabaseAuditOptions = {
116
-
117
78
  /**
118
79
  * Do not add edit record, this is controlled an function may vary by origin
119
80
  */
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Database
5
+ * @description Definition
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.IMBRICATE_DATABASE_EDIT_TYPE = exports.IMBRICATE_QUERY_PROPERTY_CONDITION_TARGET = exports.IMBRICATE_QUERY_COMPARE_CONDITION = void 0;
9
+ var IMBRICATE_QUERY_COMPARE_CONDITION;
10
+ (function (IMBRICATE_QUERY_COMPARE_CONDITION) {
11
+ IMBRICATE_QUERY_COMPARE_CONDITION["EQUAL"] = "EQUAL";
12
+ })(IMBRICATE_QUERY_COMPARE_CONDITION || (exports.IMBRICATE_QUERY_COMPARE_CONDITION = IMBRICATE_QUERY_COMPARE_CONDITION = {}));
13
+ var IMBRICATE_QUERY_PROPERTY_CONDITION_TARGET;
14
+ (function (IMBRICATE_QUERY_PROPERTY_CONDITION_TARGET) {
15
+ IMBRICATE_QUERY_PROPERTY_CONDITION_TARGET["PROPERTY_TYPE"] = "PROPERTY_TYPE";
16
+ IMBRICATE_QUERY_PROPERTY_CONDITION_TARGET["PROPERTY_VALUE"] = "PROPERTY_VALUE";
17
+ })(IMBRICATE_QUERY_PROPERTY_CONDITION_TARGET || (exports.IMBRICATE_QUERY_PROPERTY_CONDITION_TARGET = IMBRICATE_QUERY_PROPERTY_CONDITION_TARGET = {}));
18
+ /**
19
+ * Edit record type of the document
20
+ */
21
+ var IMBRICATE_DATABASE_EDIT_TYPE;
22
+ (function (IMBRICATE_DATABASE_EDIT_TYPE) {
23
+ IMBRICATE_DATABASE_EDIT_TYPE["PUT_SCHEMA"] = "PUT_SCHEMA";
24
+ IMBRICATE_DATABASE_EDIT_TYPE["PUT_ANNOTATION"] = "PUT_ANNOTATION";
25
+ IMBRICATE_DATABASE_EDIT_TYPE["DELETE_ANNOTATION"] = "DELETE_ANNOTATION";
26
+ })(IMBRICATE_DATABASE_EDIT_TYPE || (exports.IMBRICATE_DATABASE_EDIT_TYPE = IMBRICATE_DATABASE_EDIT_TYPE = {}));
@@ -3,162 +3,120 @@
3
3
  * @namespace Database
4
4
  * @description Interface
5
5
  */
6
-
7
6
  import { IImbricateDocument } from "../document/interface";
8
7
  import { DocumentProperties } from "../document/property";
9
8
  import { DatabaseAnnotationValue, DatabaseAnnotations, DatabaseEditRecord, ImbricateDatabaseAuditOptions, ImbricateDocumentQuery } from "./definition";
10
9
  import { ImbricateDatabaseSchema } from "./schema";
11
-
12
10
  export interface IImbricateDatabase {
13
-
14
11
  /**
15
12
  * Unique identifier of the database
16
13
  */
17
14
  readonly uniqueIdentifier: string;
18
-
19
15
  /**
20
16
  * Name of the database
21
17
  */
22
18
  readonly databaseName: string;
23
-
24
19
  /**
25
20
  * Schema of the database
26
21
  */
27
22
  readonly schema: ImbricateDatabaseSchema;
28
-
29
23
  /**
30
24
  * Annotations of the database
31
25
  */
32
26
  readonly annotations: DatabaseAnnotations;
33
-
34
27
  /**
35
28
  * Put and replace the schema of the database
36
29
  * Existing documents will still be kept, and stays unchanged
37
- *
30
+ *
38
31
  * @param schema schema of the database
39
- * @param auditOptions audit options of the database
40
- *
32
+ * @param auditOptions audit options of the database
33
+ *
41
34
  * @returns a promise of the edit records of the database
42
35
  * Note: if the origin supports Document Edit Record, the edit record will be added by default
43
36
  * If you do not want to add the edit record, set `noEditRecord` to true
44
37
  */
45
- putSchema(
46
- schema: ImbricateDatabaseSchema,
47
- auditOptions?: ImbricateDatabaseAuditOptions,
48
- ): PromiseLike<DatabaseEditRecord[]>;
49
-
38
+ putSchema(schema: ImbricateDatabaseSchema, auditOptions?: ImbricateDatabaseAuditOptions): PromiseLike<DatabaseEditRecord[]>;
50
39
  /**
51
40
  * Create a new document in the database
52
41
  * If origin supports Document Edit Record, the edit record will be added by default
53
- *
42
+ *
54
43
  * @param properties properties of the document
55
44
  * @param auditOptions audit options of the document
56
- *
45
+ *
57
46
  * @returns a promise of the created document
58
47
  */
59
- createDocument(
60
- properties: DocumentProperties,
61
- auditOptions?: ImbricateDatabaseAuditOptions,
62
- ): PromiseLike<IImbricateDocument>;
63
-
48
+ createDocument(properties: DocumentProperties, auditOptions?: ImbricateDatabaseAuditOptions): PromiseLike<IImbricateDocument>;
64
49
  /**
65
50
  * Get one document from the database
66
- *
51
+ *
67
52
  * @param uniqueIdentifier unique identifier of the document
68
- *
53
+ *
69
54
  * @returns a promise of the documents in the database, null if not found
70
55
  */
71
- getDocument(
72
- uniqueIdentifier: string,
73
- ): PromiseLike<IImbricateDocument | null>;
74
-
56
+ getDocument(uniqueIdentifier: string): PromiseLike<IImbricateDocument | null>;
75
57
  /**
76
58
  * Query documents from the database
77
- *
59
+ *
78
60
  * @param query query of the documents
79
- *
61
+ *
80
62
  * @returns a promise of the documents in the database
81
63
  */
82
- queryDocuments(
83
- query: ImbricateDocumentQuery,
84
- ): PromiseLike<IImbricateDocument[]>;
85
-
64
+ queryDocuments(query: ImbricateDocumentQuery): PromiseLike<IImbricateDocument[]>;
86
65
  /**
87
66
  * Count documents in the database
88
- *
67
+ *
89
68
  * @param query query of the documents
90
- *
69
+ *
91
70
  * @returns a promise of the count of the documents in the database
92
71
  */
93
- countDocuments(
94
- query: ImbricateDocumentQuery,
95
- ): PromiseLike<number>;
96
-
72
+ countDocuments(query: ImbricateDocumentQuery): PromiseLike<number>;
97
73
  /**
98
74
  * Remove a document from the database
99
- *
75
+ *
100
76
  * @param uniqueIdentifier unique identifier of the document
101
77
  * @param auditOptions audit options of the document
102
78
  */
103
- removeDocument(
104
- uniqueIdentifier: string,
105
- auditOptions?: ImbricateDatabaseAuditOptions,
106
- ): PromiseLike<void>;
107
-
79
+ removeDocument(uniqueIdentifier: string, auditOptions?: ImbricateDatabaseAuditOptions): PromiseLike<void>;
108
80
  /**
109
81
  * put annotation to the database
110
- *
82
+ *
111
83
  * @param namespace namespace of the annotation
112
84
  * @param identifier identifier of the annotation
113
85
  * @param value value of the annotation
114
86
  * @param auditOptions audit options of the database
115
- *
87
+ *
116
88
  * @returns a promise of the edit records of the database
117
89
  * Note: if the origin supports Document Edit Record, the edit record will be added by default
118
90
  * If you do not want to add the edit record, set `noEditRecord` to true in audit options
119
91
  */
120
- putAnnotation(
121
- namespace: string,
122
- identifier: string,
123
- value: DatabaseAnnotationValue,
124
- auditOptions?: ImbricateDatabaseAuditOptions,
125
- ): PromiseLike<DatabaseEditRecord[]>;
126
-
92
+ putAnnotation(namespace: string, identifier: string, value: DatabaseAnnotationValue, auditOptions?: ImbricateDatabaseAuditOptions): PromiseLike<DatabaseEditRecord[]>;
127
93
  /**
128
94
  * Delete annotation from the database
129
- *
95
+ *
130
96
  * @param namespace namespace of the annotation
131
97
  * @param identifier identifier of the annotation
132
98
  * @param auditOptions audit options of the database
133
- *
99
+ *
134
100
  * @returns a promise of the edit records of the database
135
101
  * Note: if the origin supports Document Edit Record, the edit record will be added by default
136
102
  * If you do not want to add the edit record, set `noEditRecord` to true in audit options
137
103
  */
138
- deleteAnnotation(
139
- namespace: string,
140
- identifier: string,
141
- auditOptions?: ImbricateDatabaseAuditOptions,
142
- ): PromiseLike<DatabaseEditRecord[]>;
143
-
104
+ deleteAnnotation(namespace: string, identifier: string, auditOptions?: ImbricateDatabaseAuditOptions): PromiseLike<DatabaseEditRecord[]>;
144
105
  /**
145
106
  * Add edit records to the database, optional
146
107
  * This method is optional, if not implemented, means the origin
147
108
  * 1. The origin does not support edit records
148
109
  * 2. The origin force to add edit records when put properties
149
- *
110
+ *
150
111
  * @param records database edit records
151
112
  */
152
- addEditRecords?(
153
- records: DatabaseEditRecord[],
154
- ): PromiseLike<void>;
155
-
113
+ addEditRecords?(records: DatabaseEditRecord[]): PromiseLike<void>;
156
114
  /**
157
115
  * Get edit records of the database, optional
158
116
  * This method is optional, if not implemented, means the origin
159
117
  * 1. The origin does not support edit records
160
118
  * 2. The origin force to add edit records when put properties
161
- *
119
+ *
162
120
  * @returns a promise of the edit records of the database
163
121
  */
164
122
  getEditRecords?(): PromiseLike<DatabaseEditRecord[]>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Database
5
+ * @description Interface
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -3,54 +3,39 @@
3
3
  * @namespace Database
4
4
  * @description Manager
5
5
  */
6
-
7
6
  import { ImbricateDatabaseAuditOptions } from "./definition";
8
7
  import { IImbricateDatabase } from "./interface";
9
8
  import { ImbricateDatabaseSchemaForCreation } from "./schema";
10
-
11
9
  export interface IImbricateDatabaseManager {
12
-
13
10
  /**
14
11
  * List all databases in the origin
15
- *
12
+ *
16
13
  * @returns a promise of the databases in the origin
17
14
  */
18
15
  listDatabases(): PromiseLike<IImbricateDatabase[]>;
19
-
20
16
  /**
21
17
  * Get one database from the origin
22
- *
18
+ *
23
19
  * @param uniqueIdentifier unique identifier of the database
24
- *
20
+ *
25
21
  * @returns a promise of the database, null if not found
26
22
  */
27
- getDatabase(
28
- uniqueIdentifier: string,
29
- ): PromiseLike<IImbricateDatabase | null>;
30
-
23
+ getDatabase(uniqueIdentifier: string): PromiseLike<IImbricateDatabase | null>;
31
24
  /**
32
25
  * Create a new database
33
- *
26
+ *
34
27
  * @param databaseName name of the database
35
28
  * @param schema schema of the database
36
29
  * @param auditOptions audit options of the database
37
- *
30
+ *
38
31
  * @returns a promise of the created database
39
32
  */
40
- createDatabase(
41
- databaseName: string,
42
- schema: ImbricateDatabaseSchemaForCreation,
43
- auditOptions?: ImbricateDatabaseAuditOptions,
44
- ): PromiseLike<IImbricateDatabase>;
45
-
33
+ createDatabase(databaseName: string, schema: ImbricateDatabaseSchemaForCreation, auditOptions?: ImbricateDatabaseAuditOptions): PromiseLike<IImbricateDatabase>;
46
34
  /**
47
35
  * Remove a database from the origin
48
- *
36
+ *
49
37
  * @param uniqueIdentifier unique identifier of the database
50
38
  * @param auditOptions audit options of deletion
51
39
  */
52
- removeDatabase(
53
- uniqueIdentifier: string,
54
- auditOptions?: ImbricateDatabaseAuditOptions,
55
- ): PromiseLike<void>;
40
+ removeDatabase(uniqueIdentifier: string, auditOptions?: ImbricateDatabaseAuditOptions): PromiseLike<void>;
56
41
  }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Database
5
+ * @description Manager
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,70 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @namespace Database
4
+ * @description Schema
5
+ */
6
+ import { IMBRICATE_PROPERTY_TYPE } from "../document/property";
7
+ export type ImbricateDatabaseSchemaProperty<T extends IMBRICATE_PROPERTY_TYPE> = {
8
+ readonly propertyIdentifier: string;
9
+ } & ImbricateDatabaseSchemaPropertyForCreation<T>;
10
+ export type ImbricateDatabaseSchemaPropertyOptionsReferenceDatabase = {
11
+ readonly originUniqueIdentifier: string;
12
+ readonly databaseUniqueIdentifier: string;
13
+ };
14
+ export type ImbricateDatabaseSchemaPropertyOptionsLabelOption = {
15
+ readonly labelIdentifier: string;
16
+ readonly labelName: string;
17
+ readonly labelColor: string;
18
+ };
19
+ export type ImbricateDatabaseSchemaPropertyOptionsLabel = {
20
+ /**
21
+ * Allow multiple labels
22
+ */
23
+ readonly allowMultiple: boolean;
24
+ /**
25
+ * Label Options
26
+ */
27
+ readonly labelOptions: ImbricateDatabaseSchemaPropertyOptionsLabelOption[];
28
+ };
29
+ export type ImbricateDatabaseSchemaPropertyOptionsReference = {
30
+ /**
31
+ * Allow multiple references
32
+ */
33
+ readonly allowMultiple: boolean;
34
+ /**
35
+ * Allow references from these databases
36
+ * If empty, allow references from all databases
37
+ */
38
+ readonly databases: ImbricateDatabaseSchemaPropertyOptionsReferenceDatabase[];
39
+ };
40
+ export type ImbricateDatabaseSchemaPropertyOptions<T extends IMBRICATE_PROPERTY_TYPE> = T extends IMBRICATE_PROPERTY_TYPE.BOOLEAN ? {} : T extends IMBRICATE_PROPERTY_TYPE.STRING ? {} : T extends IMBRICATE_PROPERTY_TYPE.NUMBER ? {} : T extends IMBRICATE_PROPERTY_TYPE.MARKDOWN ? {} : T extends IMBRICATE_PROPERTY_TYPE.JSON ? {} : T extends IMBRICATE_PROPERTY_TYPE.IMBRISCRIPT ? {} : T extends IMBRICATE_PROPERTY_TYPE.DATE ? {} : T extends IMBRICATE_PROPERTY_TYPE.LABEL ? ImbricateDatabaseSchemaPropertyOptionsLabel : T extends IMBRICATE_PROPERTY_TYPE.REFERENCE ? ImbricateDatabaseSchemaPropertyOptionsReference : never;
41
+ export type ImbricateDatabaseSchemaPropertyForCreation<T extends IMBRICATE_PROPERTY_TYPE> = {
42
+ readonly propertyName: string;
43
+ readonly propertyType: T;
44
+ readonly propertyOptions: ImbricateDatabaseSchemaPropertyOptions<T>;
45
+ readonly isPrimaryKey?: boolean;
46
+ };
47
+ export type ImbricateDatabaseSchema = {
48
+ readonly properties: Array<ImbricateDatabaseSchemaProperty<IMBRICATE_PROPERTY_TYPE>>;
49
+ };
50
+ export type ImbricateDatabaseSchemaForCreation = {
51
+ readonly properties: Array<ImbricateDatabaseSchemaPropertyForCreation<IMBRICATE_PROPERTY_TYPE>>;
52
+ };
53
+ /**
54
+ * Validate a schema property
55
+ *
56
+ * @param property property to validate
57
+ *
58
+ * @returns a string error message if validation failed
59
+ * null if validation passed
60
+ */
61
+ export declare const validateImbricateSchemaProperty: (property: ImbricateDatabaseSchemaProperty<IMBRICATE_PROPERTY_TYPE>) => string | null;
62
+ /**
63
+ * Validate a schema
64
+ *
65
+ * @param schema database schema to validate
66
+ *
67
+ * @returns a string error message if validation failed
68
+ * null if validation passed
69
+ */
70
+ export declare const validateImbricateSchema: (schema: ImbricateDatabaseSchema) => string | null;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ /**
3
+ * @author WMXPY
4
+ * @namespace Database
5
+ * @description Schema
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.validateImbricateSchema = exports.validateImbricateSchemaProperty = void 0;
9
+ const property_1 = require("../document/property");
10
+ /**
11
+ * Validate a schema property
12
+ *
13
+ * @param property property to validate
14
+ *
15
+ * @returns a string error message if validation failed
16
+ * null if validation passed
17
+ */
18
+ const validateImbricateSchemaProperty = (property) => {
19
+ if (typeof property.propertyIdentifier !== "string") {
20
+ return "Property identifier must be a string";
21
+ }
22
+ if (typeof property.propertyName !== "string") {
23
+ return "Property name must be a string";
24
+ }
25
+ if (!Object.values(property_1.IMBRICATE_PROPERTY_TYPE).includes(property.propertyType)) {
26
+ return "Property type must be a valid type";
27
+ }
28
+ switch (property.propertyType) {
29
+ case property_1.IMBRICATE_PROPERTY_TYPE.REFERENCE: {
30
+ if (typeof property.propertyOptions !== "object") {
31
+ return "Property options must be an object";
32
+ }
33
+ if (typeof property.propertyOptions.allowMultiple !== "boolean") {
34
+ return "Property options allowMultiple must be a boolean";
35
+ }
36
+ if (!Array.isArray(property.propertyOptions.databases)) {
37
+ return "Property options databases must be an array";
38
+ }
39
+ for (const database of property.propertyOptions.databases) {
40
+ if (typeof database.originUniqueIdentifier !== "string") {
41
+ return "Database originUniqueIdentifier must be a string";
42
+ }
43
+ if (typeof database.databaseUniqueIdentifier !== "string") {
44
+ return "Database databaseUniqueIdentifier must be a string";
45
+ }
46
+ }
47
+ break;
48
+ }
49
+ }
50
+ return null;
51
+ };
52
+ exports.validateImbricateSchemaProperty = validateImbricateSchemaProperty;
53
+ /**
54
+ * Validate a schema
55
+ *
56
+ * @param schema database schema to validate
57
+ *
58
+ * @returns a string error message if validation failed
59
+ * null if validation passed
60
+ */
61
+ const validateImbricateSchema = (schema) => {
62
+ if (!Array.isArray(schema.properties)) {
63
+ return "Properties must be an array";
64
+ }
65
+ const propertyNames = new Set();
66
+ for (const property of schema.properties) {
67
+ const propertyValidationResult = (0, exports.validateImbricateSchemaProperty)(property);
68
+ if (typeof propertyValidationResult === "string") {
69
+ return `Invalid property ${property.propertyName}, ${propertyValidationResult}`;
70
+ }
71
+ if (propertyNames.has(property.propertyName)) {
72
+ return `Duplicated property name ${property.propertyName}`;
73
+ }
74
+ propertyNames.add(property.propertyName);
75
+ }
76
+ return null;
77
+ };
78
+ exports.validateImbricateSchema = validateImbricateSchema;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @namespace Database
4
+ * @description Validate
5
+ */
6
+ import { ImbricateDocumentQuery } from "./definition";
7
+ /**
8
+ * Validate imbricate document query
9
+ *
10
+ * @param query query to validate
11
+ *
12
+ * @returns a string error message if validation failed
13
+ * null if validation passed
14
+ */
15
+ export declare const validateImbricateDocumentQuery: (query: ImbricateDocumentQuery) => string | null;