@imbricate/core 3.10.1 → 3.11.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.
- package/database/definition.d.ts +15 -0
- package/database/feature.d.ts +21 -0
- package/database/feature.js +58 -0
- package/database/interface.d.ts +29 -4
- package/document/feature.d.ts +17 -0
- package/document/feature.js +42 -0
- package/document/interface.d.ts +21 -4
- package/document/property/default-value.js +3 -3
- package/document/property.d.ts +1 -1
- package/document/validate.js +21 -6
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +1 -1
package/database/definition.d.ts
CHANGED
|
@@ -60,10 +60,16 @@ export type DatabaseEditOperationDeleteAnnotation = {
|
|
|
60
60
|
readonly annotationIdentifier: string;
|
|
61
61
|
};
|
|
62
62
|
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;
|
|
63
|
+
/**
|
|
64
|
+
* Edit operation of the database
|
|
65
|
+
*/
|
|
63
66
|
export type DatabaseEditOperation<T extends IMBRICATE_DATABASE_EDIT_TYPE> = {
|
|
64
67
|
readonly action: T;
|
|
65
68
|
readonly value: DatabaseEditOperationValue<T>;
|
|
66
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* Edit record of the database
|
|
72
|
+
*/
|
|
67
73
|
export type DatabaseEditRecord = {
|
|
68
74
|
readonly uniqueIdentifier: string;
|
|
69
75
|
readonly editAt: Date;
|
|
@@ -72,8 +78,17 @@ export type DatabaseEditRecord = {
|
|
|
72
78
|
readonly operations: Array<DatabaseEditOperation<IMBRICATE_DATABASE_EDIT_TYPE>>;
|
|
73
79
|
readonly author?: ImbricateAuthor;
|
|
74
80
|
};
|
|
81
|
+
/**
|
|
82
|
+
* Annotations of the database
|
|
83
|
+
*/
|
|
75
84
|
export type DatabaseAnnotations = Record<DatabaseAnnotationKey, DatabaseAnnotationValue>;
|
|
85
|
+
/**
|
|
86
|
+
* Annotation key of the database
|
|
87
|
+
*/
|
|
76
88
|
export type DatabaseAnnotationKey = string;
|
|
89
|
+
/**
|
|
90
|
+
* Annotation value of the database
|
|
91
|
+
*/
|
|
77
92
|
export type DatabaseAnnotationValue = {
|
|
78
93
|
readonly namespace: string;
|
|
79
94
|
readonly identifier: string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author WMXPY
|
|
3
|
+
* @namespace Database
|
|
4
|
+
* @description Feature
|
|
5
|
+
*/
|
|
6
|
+
export declare enum IMBRICATE_DATABASE_FEATURE {
|
|
7
|
+
DATABASE_PUT_SCHEMA = "DATABASE_PUT_SCHEMA",
|
|
8
|
+
DATABASE_CREATE_DOCUMENT = "DATABASE_CREATE_DOCUMENT",
|
|
9
|
+
DATABASE_UPDATE_DOCUMENT = "DATABASE_UPDATE_DOCUMENT",
|
|
10
|
+
DATABASE_DELETE_DOCUMENT = "DATABASE_DELETE_DOCUMENT",
|
|
11
|
+
DATABASE_PUT_ANNOTATION = "DATABASE_PUT_ANNOTATION",
|
|
12
|
+
DATABASE_REMOVE_ANNOTATION = "DATABASE_REMOVE_ANNOTATION",
|
|
13
|
+
DATABASE_QUERY_DOCUMENT = "DATABASE_QUERY_DOCUMENT",
|
|
14
|
+
DATABASE_PUT_EDIT_RECORD = "DATABASE_PUT_EDIT_RECORD",
|
|
15
|
+
DATABASE_GET_EDIT_RECORD = "DATABASE_GET_EDIT_RECORD"
|
|
16
|
+
}
|
|
17
|
+
export declare const fullSupportedDatabaseFeatures: IMBRICATE_DATABASE_FEATURE[];
|
|
18
|
+
export declare const editRecordExcludedDatabaseFeatures: IMBRICATE_DATABASE_FEATURE[];
|
|
19
|
+
export declare const annotationExcludedDatabaseFeatures: IMBRICATE_DATABASE_FEATURE[];
|
|
20
|
+
export declare const IMBRICATE_DATABASE_PRESET_FEATURES: Record<string, IMBRICATE_DATABASE_FEATURE[]>;
|
|
21
|
+
export declare const checkImbricateDatabaseFeatureSupported: (features: IMBRICATE_DATABASE_FEATURE[], feature: IMBRICATE_DATABASE_FEATURE) => boolean;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @author WMXPY
|
|
4
|
+
* @namespace Database
|
|
5
|
+
* @description Feature
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.checkImbricateDatabaseFeatureSupported = exports.IMBRICATE_DATABASE_PRESET_FEATURES = exports.annotationExcludedDatabaseFeatures = exports.editRecordExcludedDatabaseFeatures = exports.fullSupportedDatabaseFeatures = exports.IMBRICATE_DATABASE_FEATURE = void 0;
|
|
9
|
+
var IMBRICATE_DATABASE_FEATURE;
|
|
10
|
+
(function (IMBRICATE_DATABASE_FEATURE) {
|
|
11
|
+
IMBRICATE_DATABASE_FEATURE["DATABASE_PUT_SCHEMA"] = "DATABASE_PUT_SCHEMA";
|
|
12
|
+
IMBRICATE_DATABASE_FEATURE["DATABASE_CREATE_DOCUMENT"] = "DATABASE_CREATE_DOCUMENT";
|
|
13
|
+
IMBRICATE_DATABASE_FEATURE["DATABASE_UPDATE_DOCUMENT"] = "DATABASE_UPDATE_DOCUMENT";
|
|
14
|
+
IMBRICATE_DATABASE_FEATURE["DATABASE_DELETE_DOCUMENT"] = "DATABASE_DELETE_DOCUMENT";
|
|
15
|
+
IMBRICATE_DATABASE_FEATURE["DATABASE_PUT_ANNOTATION"] = "DATABASE_PUT_ANNOTATION";
|
|
16
|
+
IMBRICATE_DATABASE_FEATURE["DATABASE_REMOVE_ANNOTATION"] = "DATABASE_REMOVE_ANNOTATION";
|
|
17
|
+
IMBRICATE_DATABASE_FEATURE["DATABASE_QUERY_DOCUMENT"] = "DATABASE_QUERY_DOCUMENT";
|
|
18
|
+
IMBRICATE_DATABASE_FEATURE["DATABASE_PUT_EDIT_RECORD"] = "DATABASE_PUT_EDIT_RECORD";
|
|
19
|
+
IMBRICATE_DATABASE_FEATURE["DATABASE_GET_EDIT_RECORD"] = "DATABASE_GET_EDIT_RECORD";
|
|
20
|
+
})(IMBRICATE_DATABASE_FEATURE || (exports.IMBRICATE_DATABASE_FEATURE = IMBRICATE_DATABASE_FEATURE = {}));
|
|
21
|
+
exports.fullSupportedDatabaseFeatures = [
|
|
22
|
+
IMBRICATE_DATABASE_FEATURE.DATABASE_PUT_SCHEMA,
|
|
23
|
+
IMBRICATE_DATABASE_FEATURE.DATABASE_CREATE_DOCUMENT,
|
|
24
|
+
IMBRICATE_DATABASE_FEATURE.DATABASE_UPDATE_DOCUMENT,
|
|
25
|
+
IMBRICATE_DATABASE_FEATURE.DATABASE_DELETE_DOCUMENT,
|
|
26
|
+
IMBRICATE_DATABASE_FEATURE.DATABASE_PUT_ANNOTATION,
|
|
27
|
+
IMBRICATE_DATABASE_FEATURE.DATABASE_REMOVE_ANNOTATION,
|
|
28
|
+
IMBRICATE_DATABASE_FEATURE.DATABASE_QUERY_DOCUMENT,
|
|
29
|
+
IMBRICATE_DATABASE_FEATURE.DATABASE_PUT_EDIT_RECORD,
|
|
30
|
+
IMBRICATE_DATABASE_FEATURE.DATABASE_GET_EDIT_RECORD,
|
|
31
|
+
];
|
|
32
|
+
exports.editRecordExcludedDatabaseFeatures = [
|
|
33
|
+
IMBRICATE_DATABASE_FEATURE.DATABASE_PUT_SCHEMA,
|
|
34
|
+
IMBRICATE_DATABASE_FEATURE.DATABASE_CREATE_DOCUMENT,
|
|
35
|
+
IMBRICATE_DATABASE_FEATURE.DATABASE_UPDATE_DOCUMENT,
|
|
36
|
+
IMBRICATE_DATABASE_FEATURE.DATABASE_DELETE_DOCUMENT,
|
|
37
|
+
IMBRICATE_DATABASE_FEATURE.DATABASE_PUT_ANNOTATION,
|
|
38
|
+
IMBRICATE_DATABASE_FEATURE.DATABASE_REMOVE_ANNOTATION,
|
|
39
|
+
IMBRICATE_DATABASE_FEATURE.DATABASE_QUERY_DOCUMENT,
|
|
40
|
+
];
|
|
41
|
+
exports.annotationExcludedDatabaseFeatures = [
|
|
42
|
+
IMBRICATE_DATABASE_FEATURE.DATABASE_PUT_SCHEMA,
|
|
43
|
+
IMBRICATE_DATABASE_FEATURE.DATABASE_CREATE_DOCUMENT,
|
|
44
|
+
IMBRICATE_DATABASE_FEATURE.DATABASE_UPDATE_DOCUMENT,
|
|
45
|
+
IMBRICATE_DATABASE_FEATURE.DATABASE_DELETE_DOCUMENT,
|
|
46
|
+
IMBRICATE_DATABASE_FEATURE.DATABASE_PUT_EDIT_RECORD,
|
|
47
|
+
IMBRICATE_DATABASE_FEATURE.DATABASE_GET_EDIT_RECORD,
|
|
48
|
+
IMBRICATE_DATABASE_FEATURE.DATABASE_QUERY_DOCUMENT,
|
|
49
|
+
];
|
|
50
|
+
exports.IMBRICATE_DATABASE_PRESET_FEATURES = {
|
|
51
|
+
FULL_SUPPORTED_FEATURES: exports.fullSupportedDatabaseFeatures,
|
|
52
|
+
EDIT_RECORD_EXCLUDED_FEATURES: exports.editRecordExcludedDatabaseFeatures,
|
|
53
|
+
ANNOTATION_EXCLUDED_FEATURES: exports.annotationExcludedDatabaseFeatures,
|
|
54
|
+
};
|
|
55
|
+
const checkImbricateDatabaseFeatureSupported = (features, feature) => {
|
|
56
|
+
return features.includes(feature);
|
|
57
|
+
};
|
|
58
|
+
exports.checkImbricateDatabaseFeatureSupported = checkImbricateDatabaseFeatureSupported;
|
package/database/interface.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { IImbricateDocument } from "../document/interface";
|
|
7
7
|
import { DocumentProperties } from "../document/property";
|
|
8
8
|
import { DatabaseAnnotationValue, DatabaseAnnotations, DatabaseEditRecord, ImbricateDatabaseAuditOptions, ImbricateDocumentQuery } from "./definition";
|
|
9
|
+
import { IMBRICATE_DATABASE_FEATURE } from "./feature";
|
|
9
10
|
import { ImbricateDatabaseSchema } from "./schema";
|
|
10
11
|
export interface IImbricateDatabase {
|
|
11
12
|
/**
|
|
@@ -28,10 +29,16 @@ export interface IImbricateDatabase {
|
|
|
28
29
|
* Annotations of the database
|
|
29
30
|
*/
|
|
30
31
|
readonly annotations: DatabaseAnnotations;
|
|
32
|
+
/**
|
|
33
|
+
* Supported features of the database
|
|
34
|
+
*/
|
|
35
|
+
readonly supportedFeatures: IMBRICATE_DATABASE_FEATURE[];
|
|
31
36
|
/**
|
|
32
37
|
* Put and replace the schema of the database
|
|
33
38
|
* Existing documents will still be kept, and stays unchanged
|
|
34
39
|
*
|
|
40
|
+
* RequireFeature: DATABASE_PUT_SCHEMA
|
|
41
|
+
*
|
|
35
42
|
* @param schema schema of the database
|
|
36
43
|
* @param auditOptions audit options of the database
|
|
37
44
|
*
|
|
@@ -44,6 +51,8 @@ export interface IImbricateDatabase {
|
|
|
44
51
|
* Create a new document in the database
|
|
45
52
|
* If origin supports Document Edit Record, the edit record will be added by default
|
|
46
53
|
*
|
|
54
|
+
* RequireFeature: DATABASE_CREATE_DOCUMENT
|
|
55
|
+
*
|
|
47
56
|
* @param properties properties of the document
|
|
48
57
|
* @param auditOptions audit options of the document
|
|
49
58
|
*
|
|
@@ -53,6 +62,8 @@ export interface IImbricateDatabase {
|
|
|
53
62
|
/**
|
|
54
63
|
* Get one document from the database
|
|
55
64
|
*
|
|
65
|
+
* RequireFeature: DATABASE_GET_DOCUMENT
|
|
66
|
+
*
|
|
56
67
|
* @param uniqueIdentifier unique identifier of the document
|
|
57
68
|
*
|
|
58
69
|
* @returns a promise of the documents in the database, null if not found
|
|
@@ -61,6 +72,8 @@ export interface IImbricateDatabase {
|
|
|
61
72
|
/**
|
|
62
73
|
* Query documents from the database
|
|
63
74
|
*
|
|
75
|
+
* RequireFeature: DATABASE_QUERY_DOCUMENT
|
|
76
|
+
*
|
|
64
77
|
* @param query query of the documents
|
|
65
78
|
*
|
|
66
79
|
* @returns a promise of the documents in the database
|
|
@@ -69,6 +82,8 @@ export interface IImbricateDatabase {
|
|
|
69
82
|
/**
|
|
70
83
|
* Count documents in the database
|
|
71
84
|
*
|
|
85
|
+
* RequireFeature: DATABASE_COUNT_DOCUMENT
|
|
86
|
+
*
|
|
72
87
|
* @param query query of the documents
|
|
73
88
|
*
|
|
74
89
|
* @returns a promise of the count of the documents in the database
|
|
@@ -77,12 +92,16 @@ export interface IImbricateDatabase {
|
|
|
77
92
|
/**
|
|
78
93
|
* Remove a document from the database
|
|
79
94
|
*
|
|
95
|
+
* RequireFeature: DATABASE_DELETE_DOCUMENT
|
|
96
|
+
*
|
|
80
97
|
* @param uniqueIdentifier unique identifier of the document
|
|
81
98
|
* @param auditOptions audit options of the document
|
|
82
99
|
*/
|
|
83
100
|
removeDocument(uniqueIdentifier: string, auditOptions?: ImbricateDatabaseAuditOptions): PromiseLike<void>;
|
|
84
101
|
/**
|
|
85
|
-
*
|
|
102
|
+
* Put annotation to the database, optional
|
|
103
|
+
*
|
|
104
|
+
* RequireFeature: DATABASE_PUT_ANNOTATION
|
|
86
105
|
*
|
|
87
106
|
* @param namespace namespace of the annotation
|
|
88
107
|
* @param identifier identifier of the annotation
|
|
@@ -93,9 +112,11 @@ export interface IImbricateDatabase {
|
|
|
93
112
|
* Note: if the origin supports Document Edit Record, the edit record will be added by default
|
|
94
113
|
* If you do not want to add the edit record, set `noEditRecord` to true in audit options
|
|
95
114
|
*/
|
|
96
|
-
putAnnotation(namespace: string, identifier: string, value: DatabaseAnnotationValue, auditOptions?: ImbricateDatabaseAuditOptions): PromiseLike<DatabaseEditRecord[]>;
|
|
115
|
+
putAnnotation?(namespace: string, identifier: string, value: DatabaseAnnotationValue, auditOptions?: ImbricateDatabaseAuditOptions): PromiseLike<DatabaseEditRecord[]>;
|
|
97
116
|
/**
|
|
98
|
-
* Delete annotation from the database
|
|
117
|
+
* Delete annotation from the database, optional
|
|
118
|
+
*
|
|
119
|
+
* RequireFeature: DATABASE_REMOVE_ANNOTATION
|
|
99
120
|
*
|
|
100
121
|
* @param namespace namespace of the annotation
|
|
101
122
|
* @param identifier identifier of the annotation
|
|
@@ -105,13 +126,15 @@ export interface IImbricateDatabase {
|
|
|
105
126
|
* Note: if the origin supports Document Edit Record, the edit record will be added by default
|
|
106
127
|
* If you do not want to add the edit record, set `noEditRecord` to true in audit options
|
|
107
128
|
*/
|
|
108
|
-
deleteAnnotation(namespace: string, identifier: string, auditOptions?: ImbricateDatabaseAuditOptions): PromiseLike<DatabaseEditRecord[]>;
|
|
129
|
+
deleteAnnotation?(namespace: string, identifier: string, auditOptions?: ImbricateDatabaseAuditOptions): PromiseLike<DatabaseEditRecord[]>;
|
|
109
130
|
/**
|
|
110
131
|
* Add edit records to the database, optional
|
|
111
132
|
* This method is optional, if not implemented, means the origin
|
|
112
133
|
* 1. The origin does not support edit records
|
|
113
134
|
* 2. The origin force to add edit records when put properties
|
|
114
135
|
*
|
|
136
|
+
* RequireFeature: DATABASE_PUT_EDIT_RECORD
|
|
137
|
+
*
|
|
115
138
|
* @param records database edit records
|
|
116
139
|
*/
|
|
117
140
|
addEditRecords?(records: DatabaseEditRecord[]): PromiseLike<void>;
|
|
@@ -121,6 +144,8 @@ export interface IImbricateDatabase {
|
|
|
121
144
|
* 1. The origin does not support edit records
|
|
122
145
|
* 2. The origin force to add edit records when put properties
|
|
123
146
|
*
|
|
147
|
+
* RequireFeature: DATABASE_GET_EDIT_RECORD
|
|
148
|
+
*
|
|
124
149
|
* @returns a promise of the edit records of the database
|
|
125
150
|
*/
|
|
126
151
|
getEditRecords?(): PromiseLike<DatabaseEditRecord[]>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author WMXPY
|
|
3
|
+
* @namespace Document
|
|
4
|
+
* @description Feature
|
|
5
|
+
*/
|
|
6
|
+
export declare enum IMBRICATE_DOCUMENT_FEATURE {
|
|
7
|
+
DOCUMENT_PUT_PROPERTY = "DOCUMENT_PUT_PROPERTY",
|
|
8
|
+
DOCUMENT_PUT_ANNOTATION = "DOCUMENT_PUT_ANNOTATION",
|
|
9
|
+
DOCUMENT_REMOVE_ANNOTATION = "DOCUMENT_REMOVE_ANNOTATION",
|
|
10
|
+
DOCUMENT_PUT_EDIT_RECORD = "DOCUMENT_PUT_EDIT_RECORD",
|
|
11
|
+
DOCUMENT_GET_EDIT_RECORD = "DOCUMENT_GET_EDIT_RECORD"
|
|
12
|
+
}
|
|
13
|
+
export declare const fullSupportedDocumentFeatures: IMBRICATE_DOCUMENT_FEATURE[];
|
|
14
|
+
export declare const annotationExcludedDocumentFeatures: IMBRICATE_DOCUMENT_FEATURE[];
|
|
15
|
+
export declare const editRecordExcludedDocumentFeatures: IMBRICATE_DOCUMENT_FEATURE[];
|
|
16
|
+
export declare const IMBRICATE_DOCUMENT_PRESET_FEATURES: Record<string, IMBRICATE_DOCUMENT_FEATURE[]>;
|
|
17
|
+
export declare const checkImbricateDocumentFeatureSupported: (features: IMBRICATE_DOCUMENT_FEATURE[], feature: IMBRICATE_DOCUMENT_FEATURE) => boolean;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @author WMXPY
|
|
4
|
+
* @namespace Document
|
|
5
|
+
* @description Feature
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.checkImbricateDocumentFeatureSupported = exports.IMBRICATE_DOCUMENT_PRESET_FEATURES = exports.editRecordExcludedDocumentFeatures = exports.annotationExcludedDocumentFeatures = exports.fullSupportedDocumentFeatures = exports.IMBRICATE_DOCUMENT_FEATURE = void 0;
|
|
9
|
+
var IMBRICATE_DOCUMENT_FEATURE;
|
|
10
|
+
(function (IMBRICATE_DOCUMENT_FEATURE) {
|
|
11
|
+
IMBRICATE_DOCUMENT_FEATURE["DOCUMENT_PUT_PROPERTY"] = "DOCUMENT_PUT_PROPERTY";
|
|
12
|
+
IMBRICATE_DOCUMENT_FEATURE["DOCUMENT_PUT_ANNOTATION"] = "DOCUMENT_PUT_ANNOTATION";
|
|
13
|
+
IMBRICATE_DOCUMENT_FEATURE["DOCUMENT_REMOVE_ANNOTATION"] = "DOCUMENT_REMOVE_ANNOTATION";
|
|
14
|
+
IMBRICATE_DOCUMENT_FEATURE["DOCUMENT_PUT_EDIT_RECORD"] = "DOCUMENT_PUT_EDIT_RECORD";
|
|
15
|
+
IMBRICATE_DOCUMENT_FEATURE["DOCUMENT_GET_EDIT_RECORD"] = "DOCUMENT_GET_EDIT_RECORD";
|
|
16
|
+
})(IMBRICATE_DOCUMENT_FEATURE || (exports.IMBRICATE_DOCUMENT_FEATURE = IMBRICATE_DOCUMENT_FEATURE = {}));
|
|
17
|
+
exports.fullSupportedDocumentFeatures = [
|
|
18
|
+
IMBRICATE_DOCUMENT_FEATURE.DOCUMENT_PUT_PROPERTY,
|
|
19
|
+
IMBRICATE_DOCUMENT_FEATURE.DOCUMENT_PUT_ANNOTATION,
|
|
20
|
+
IMBRICATE_DOCUMENT_FEATURE.DOCUMENT_REMOVE_ANNOTATION,
|
|
21
|
+
IMBRICATE_DOCUMENT_FEATURE.DOCUMENT_PUT_EDIT_RECORD,
|
|
22
|
+
IMBRICATE_DOCUMENT_FEATURE.DOCUMENT_GET_EDIT_RECORD,
|
|
23
|
+
];
|
|
24
|
+
exports.annotationExcludedDocumentFeatures = [
|
|
25
|
+
IMBRICATE_DOCUMENT_FEATURE.DOCUMENT_PUT_PROPERTY,
|
|
26
|
+
IMBRICATE_DOCUMENT_FEATURE.DOCUMENT_PUT_EDIT_RECORD,
|
|
27
|
+
IMBRICATE_DOCUMENT_FEATURE.DOCUMENT_GET_EDIT_RECORD,
|
|
28
|
+
];
|
|
29
|
+
exports.editRecordExcludedDocumentFeatures = [
|
|
30
|
+
IMBRICATE_DOCUMENT_FEATURE.DOCUMENT_PUT_PROPERTY,
|
|
31
|
+
IMBRICATE_DOCUMENT_FEATURE.DOCUMENT_PUT_ANNOTATION,
|
|
32
|
+
IMBRICATE_DOCUMENT_FEATURE.DOCUMENT_REMOVE_ANNOTATION,
|
|
33
|
+
];
|
|
34
|
+
exports.IMBRICATE_DOCUMENT_PRESET_FEATURES = {
|
|
35
|
+
FULL_SUPPORTED_FEATURES: exports.fullSupportedDocumentFeatures,
|
|
36
|
+
ANNOTATION_EXCLUDED_FEATURES: exports.annotationExcludedDocumentFeatures,
|
|
37
|
+
EDIT_RECORD_EXCLUDED_FEATURES: exports.editRecordExcludedDocumentFeatures,
|
|
38
|
+
};
|
|
39
|
+
const checkImbricateDocumentFeatureSupported = (features, feature) => {
|
|
40
|
+
return features.includes(feature);
|
|
41
|
+
};
|
|
42
|
+
exports.checkImbricateDocumentFeatureSupported = checkImbricateDocumentFeatureSupported;
|
package/document/interface.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @description Interface
|
|
5
5
|
*/
|
|
6
6
|
import { DocumentAnnotationValue, DocumentAnnotations, DocumentEditRecord, ImbricateDocumentAuditOptions } from "./definition";
|
|
7
|
+
import { IMBRICATE_DOCUMENT_FEATURE } from "./feature";
|
|
7
8
|
import { DocumentProperties, DocumentPropertyKey, DocumentPropertyValue, IMBRICATE_PROPERTY_TYPE } from "./property";
|
|
8
9
|
export interface IImbricateDocument {
|
|
9
10
|
/**
|
|
@@ -22,9 +23,15 @@ export interface IImbricateDocument {
|
|
|
22
23
|
* Annotations of the database
|
|
23
24
|
*/
|
|
24
25
|
readonly annotations: DocumentAnnotations;
|
|
26
|
+
/**
|
|
27
|
+
* Supported features of the document
|
|
28
|
+
*/
|
|
29
|
+
readonly supportedFeatures: IMBRICATE_DOCUMENT_FEATURE[];
|
|
25
30
|
/**
|
|
26
31
|
* Update a property from the document
|
|
27
32
|
*
|
|
33
|
+
* RequireFeature: DOCUMENT_PUT_PROPERTY
|
|
34
|
+
*
|
|
28
35
|
* @param key key of the property
|
|
29
36
|
* @param value value of the property
|
|
30
37
|
* @param auditOptions audit options of the document
|
|
@@ -35,7 +42,9 @@ export interface IImbricateDocument {
|
|
|
35
42
|
*/
|
|
36
43
|
putProperty(key: DocumentPropertyKey, value: DocumentPropertyValue<IMBRICATE_PROPERTY_TYPE>, auditOptions?: ImbricateDocumentAuditOptions): PromiseLike<DocumentEditRecord[]>;
|
|
37
44
|
/**
|
|
38
|
-
* Put and replace all properties of the document
|
|
45
|
+
* Put and replace all properties of the document, optional
|
|
46
|
+
*
|
|
47
|
+
* RequireFeature: DOCUMENT_PUT_PROPERTIES
|
|
39
48
|
*
|
|
40
49
|
* @param properties properties of the document
|
|
41
50
|
* @param auditOptions audit options of the document
|
|
@@ -46,7 +55,9 @@ export interface IImbricateDocument {
|
|
|
46
55
|
*/
|
|
47
56
|
putProperties(properties: DocumentProperties, auditOptions?: ImbricateDocumentAuditOptions): PromiseLike<DocumentEditRecord[]>;
|
|
48
57
|
/**
|
|
49
|
-
*
|
|
58
|
+
* Put annotation to the document, optional
|
|
59
|
+
*
|
|
60
|
+
* RequireFeature: DOCUMENT_PUT_ANNOTATION
|
|
50
61
|
*
|
|
51
62
|
* @param namespace namespace of the annotation
|
|
52
63
|
* @param identifier identifier of the annotation
|
|
@@ -57,10 +68,12 @@ export interface IImbricateDocument {
|
|
|
57
68
|
* Note: if the origin supports Document Edit Record, the edit record will be added by default
|
|
58
69
|
* If you do not want to add the edit record, set `noEditRecord` to true in audit options
|
|
59
70
|
*/
|
|
60
|
-
putAnnotation(namespace: string, identifier: string, value: DocumentAnnotationValue, auditOptions?: ImbricateDocumentAuditOptions): PromiseLike<DocumentEditRecord[]>;
|
|
71
|
+
putAnnotation?(namespace: string, identifier: string, value: DocumentAnnotationValue, auditOptions?: ImbricateDocumentAuditOptions): PromiseLike<DocumentEditRecord[]>;
|
|
61
72
|
/**
|
|
62
73
|
* Delete annotation from the document
|
|
63
74
|
*
|
|
75
|
+
* RequireFeature: DOCUMENT_REMOVE_ANNOTATION
|
|
76
|
+
*
|
|
64
77
|
* @param namespace namespace of the annotation
|
|
65
78
|
* @param identifier identifier of the annotation
|
|
66
79
|
* @param auditOptions audit options of the document
|
|
@@ -69,13 +82,15 @@ export interface IImbricateDocument {
|
|
|
69
82
|
* Note: if the origin supports Document Edit Record, the edit record will be added by default
|
|
70
83
|
* If you do not want to add the edit record, set `noEditRecord` to true in audit options
|
|
71
84
|
*/
|
|
72
|
-
deleteAnnotation(namespace: string, identifier: string, auditOptions?: ImbricateDocumentAuditOptions): PromiseLike<DocumentEditRecord[]>;
|
|
85
|
+
deleteAnnotation?(namespace: string, identifier: string, auditOptions?: ImbricateDocumentAuditOptions): PromiseLike<DocumentEditRecord[]>;
|
|
73
86
|
/**
|
|
74
87
|
* Add edit records to the document, optional
|
|
75
88
|
* This method is optional, if not implemented, means the origin
|
|
76
89
|
* 1. The origin does not support edit records
|
|
77
90
|
* 2. The origin force to add edit records when put properties
|
|
78
91
|
*
|
|
92
|
+
* RequireFeature: DOCUMENT_PUT_EDIT_RECORD
|
|
93
|
+
*
|
|
79
94
|
* @param records document edit records
|
|
80
95
|
*/
|
|
81
96
|
addEditRecords?(records: DocumentEditRecord[]): PromiseLike<void>;
|
|
@@ -85,6 +100,8 @@ export interface IImbricateDocument {
|
|
|
85
100
|
* 1. The origin does not support edit records
|
|
86
101
|
* 2. The origin force to add edit records when put properties
|
|
87
102
|
*
|
|
103
|
+
* RequireFeature: DOCUMENT_GET_EDIT_RECORD
|
|
104
|
+
*
|
|
88
105
|
* @returns a promise of the edit records of the document
|
|
89
106
|
*/
|
|
90
107
|
getEditRecords?(): PromiseLike<DocumentEditRecord[]>;
|
|
@@ -13,9 +13,9 @@ const getImbricateDefaultValueOfProperty = (type) => {
|
|
|
13
13
|
case property_1.IMBRICATE_PROPERTY_TYPE.BOOLEAN: return false;
|
|
14
14
|
case property_1.IMBRICATE_PROPERTY_TYPE.STRING: return "";
|
|
15
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
|
|
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
19
|
case property_1.IMBRICATE_PROPERTY_TYPE.DATE: return new Date().toISOString();
|
|
20
20
|
case property_1.IMBRICATE_PROPERTY_TYPE.LABEL: return [];
|
|
21
21
|
case property_1.IMBRICATE_PROPERTY_TYPE.REFERENCE: return [];
|
package/document/property.d.ts
CHANGED
|
@@ -68,4 +68,4 @@ export type DocumentPropertyValueObjectReference = {
|
|
|
68
68
|
readonly databaseUniqueIdentifier: string;
|
|
69
69
|
readonly documentUniqueIdentifier: string;
|
|
70
70
|
};
|
|
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;
|
|
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;
|
package/document/validate.js
CHANGED
|
@@ -60,20 +60,35 @@ const validateImbricateProperties = (properties, schema, allowExtraProperties =
|
|
|
60
60
|
break;
|
|
61
61
|
}
|
|
62
62
|
case property_1.IMBRICATE_PROPERTY_TYPE.MARKDOWN: {
|
|
63
|
-
if (
|
|
64
|
-
return `Property ${key} value must be
|
|
63
|
+
if (!Array.isArray(value.value)) {
|
|
64
|
+
return `Property ${key} value must be an array of string`;
|
|
65
|
+
}
|
|
66
|
+
for (const markdown of value.value) {
|
|
67
|
+
if (typeof markdown !== "string") {
|
|
68
|
+
return `Property ${key} markdown must be a string`;
|
|
69
|
+
}
|
|
65
70
|
}
|
|
66
71
|
break;
|
|
67
72
|
}
|
|
68
73
|
case property_1.IMBRICATE_PROPERTY_TYPE.JSON: {
|
|
69
|
-
if (
|
|
70
|
-
return `Property ${key} value must be
|
|
74
|
+
if (!Array.isArray(value.value)) {
|
|
75
|
+
return `Property ${key} value must be an array of string`;
|
|
76
|
+
}
|
|
77
|
+
for (const json of value.value) {
|
|
78
|
+
if (typeof json !== "string") {
|
|
79
|
+
return `Property ${key} json must be a string`;
|
|
80
|
+
}
|
|
71
81
|
}
|
|
72
82
|
break;
|
|
73
83
|
}
|
|
74
84
|
case property_1.IMBRICATE_PROPERTY_TYPE.IMBRISCRIPT: {
|
|
75
|
-
if (
|
|
76
|
-
return `Property ${key} value must be
|
|
85
|
+
if (!Array.isArray(value.value)) {
|
|
86
|
+
return `Property ${key} value must be an array of string`;
|
|
87
|
+
}
|
|
88
|
+
for (const imbriscript of value.value) {
|
|
89
|
+
if (typeof imbriscript !== "string") {
|
|
90
|
+
return `Property ${key} imbriscript must be a string`;
|
|
91
|
+
}
|
|
77
92
|
}
|
|
78
93
|
break;
|
|
79
94
|
}
|
package/index.d.ts
CHANGED
|
@@ -4,11 +4,13 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export * from "./author/definition";
|
|
6
6
|
export * from "./database/definition";
|
|
7
|
+
export * from "./database/feature";
|
|
7
8
|
export * from "./database/interface";
|
|
8
9
|
export * from "./database/manager";
|
|
9
10
|
export * from "./database/schema";
|
|
10
11
|
export * from "./database/validate";
|
|
11
12
|
export * from "./document/definition";
|
|
13
|
+
export * from "./document/feature";
|
|
12
14
|
export * from "./document/interface";
|
|
13
15
|
export * from "./document/property";
|
|
14
16
|
export * from "./document/property/default-value";
|
package/index.js
CHANGED
|
@@ -20,11 +20,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
21
|
__exportStar(require("./author/definition"), exports);
|
|
22
22
|
__exportStar(require("./database/definition"), exports);
|
|
23
|
+
__exportStar(require("./database/feature"), exports);
|
|
23
24
|
__exportStar(require("./database/interface"), exports);
|
|
24
25
|
__exportStar(require("./database/manager"), exports);
|
|
25
26
|
__exportStar(require("./database/schema"), exports);
|
|
26
27
|
__exportStar(require("./database/validate"), exports);
|
|
27
28
|
__exportStar(require("./document/definition"), exports);
|
|
29
|
+
__exportStar(require("./document/feature"), exports);
|
|
28
30
|
__exportStar(require("./document/interface"), exports);
|
|
29
31
|
__exportStar(require("./document/property"), exports);
|
|
30
32
|
__exportStar(require("./document/property/default-value"), exports);
|