@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.
- package/{src/author/definition.ts → author/definition.d.ts} +0 -4
- package/author/definition.js +7 -0
- package/{src/database/definition.ts → database/definition.d.ts} +15 -51
- package/database/definition.js +31 -0
- package/{src/database/interface.ts → database/interface.d.ts} +27 -69
- package/database/interface.js +7 -0
- package/{src/database/manager.ts → database/manager.d.ts} +9 -24
- package/database/manager.js +7 -0
- package/database/schema.d.ts +70 -0
- package/database/schema.js +78 -0
- package/database/validate.d.ts +15 -0
- package/database/validate.js +73 -0
- package/{src/document/definition.ts → document/definition.d.ts} +3 -31
- package/document/definition.js +17 -0
- package/{src/document/interface.ts → document/interface.d.ts} +15 -44
- package/document/interface.js +7 -0
- package/document/property/default-value.d.ts +7 -0
- package/document/property/default-value.js +25 -0
- package/{src/document/property/definition.ts → document/property/definition.d.ts} +1 -6
- package/document/property/definition.js +7 -0
- package/document/property/primary.d.ts +8 -0
- package/document/property/primary.js +20 -0
- package/document/property/triage-base.d.ts +31 -0
- package/document/property/triage-base.js +85 -0
- package/document/property/triage-manager.d.ts +30 -0
- package/document/property/triage-manager.js +50 -0
- package/document/property/triage.d.ts +8 -0
- package/document/property/triage.js +13 -0
- package/{src/document/property.ts → document/property.d.ts} +4 -23
- package/document/property.js +54 -0
- package/document/validate.d.ts +18 -0
- package/{src/document/validate.ts → document/validate.js} +21 -33
- package/{src/index.ts → index.d.ts} +0 -2
- package/index.js +47 -0
- package/{src/loader/definition.ts → loader/definition.d.ts} +1 -5
- package/loader/definition.js +7 -0
- package/loader/origin-loader.d.ts +29 -0
- package/loader/origin-loader.js +104 -0
- package/{src/loader/persistence.ts → loader/persistence.d.ts} +3 -12
- package/loader/persistence.js +19 -0
- package/{src/origin/definition.ts → origin/definition.d.ts} +0 -1
- package/origin/definition.js +7 -0
- package/{src/origin/interface.ts → origin/interface.d.ts} +7 -18
- package/origin/interface.js +7 -0
- package/{src/origin/search.ts → origin/search.d.ts} +13 -29
- package/origin/search.js +14 -0
- package/package.json +3 -27
- package/{src/static/definition.ts → static/definition.d.ts} +0 -3
- package/static/definition.js +7 -0
- package/{src/static/interface.ts → static/interface.d.ts} +1 -6
- package/static/interface.js +7 -0
- package/{src/static/manager.ts → static/manager.d.ts} +4 -11
- package/static/manager.js +7 -0
- package/{src/text/definition.ts → text/definition.d.ts} +0 -3
- package/text/definition.js +7 -0
- package/{src/text/interface.ts → text/interface.d.ts} +1 -6
- package/text/interface.js +7 -0
- package/{src/text/manager.ts → text/manager.d.ts} +4 -11
- package/text/manager.js +7 -0
- package/.editorconfig +0 -10
- package/.gitattributes +0 -4
- package/.github/dependabot.yml +0 -8
- package/.github/workflows/ci.yml +0 -48
- package/.vscode/settings.json +0 -8
- package/.yarn/releases/yarn-4.4.0.cjs +0 -925
- package/.yarnrc.yml +0 -3
- package/babel.config.js +0 -14
- package/docs/README.md +0 -70
- package/eslint.config.mjs +0 -64
- package/jest.config.ts +0 -14
- package/src/database/schema.ts +0 -165
- package/src/database/validate.ts +0 -77
- package/src/document/property/default-value.ts +0 -26
- package/src/document/property/primary.ts +0 -29
- package/src/document/property/triage-base.ts +0 -138
- package/src/document/property/triage-manager.ts +0 -68
- package/src/document/property/triage.ts +0 -15
- package/src/loader/origin-loader.ts +0 -88
- package/test/unit/database/schema.test.ts +0 -95
- package/test/unit/document/property/primary.test.ts +0 -87
- package/test/unit/document/property/triage.test.ts +0 -64
- package/test/unit/document/validate.test.ts +0 -138
- package/test/unit/loader/definition.test.ts +0 -55
- package/typescript/tsconfig.build.json +0 -23
|
@@ -3,117 +3,81 @@
|
|
|
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
|
-
|
|
8
|
+
export declare enum IMBRICATE_QUERY_COMPARE_CONDITION {
|
|
12
9
|
EQUAL = "EQUAL",
|
|
10
|
+
EXIST = "EXIST"
|
|
13
11
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
export declare enum IMBRICATE_QUERY_ATTRIBUTE {
|
|
13
|
+
VALUE = "VALUE"
|
|
14
|
+
}
|
|
15
|
+
export declare enum IMBRICATE_QUERY_PROPERTY_CONDITION_TARGET {
|
|
17
16
|
PROPERTY_TYPE = "PROPERTY_TYPE",
|
|
18
|
-
PROPERTY_VALUE = "PROPERTY_VALUE"
|
|
17
|
+
PROPERTY_VALUE = "PROPERTY_VALUE"
|
|
19
18
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
export type ImbricateDocumentQueryPropertyFilter = {
|
|
20
|
+
readonly propertyIdentifier: string;
|
|
23
21
|
readonly target: IMBRICATE_QUERY_PROPERTY_CONDITION_TARGET;
|
|
22
|
+
readonly attribute: IMBRICATE_QUERY_ATTRIBUTE;
|
|
24
23
|
readonly condition: IMBRICATE_QUERY_COMPARE_CONDITION;
|
|
25
24
|
readonly value: any;
|
|
26
25
|
};
|
|
27
|
-
|
|
28
|
-
export type ImbricateDocumentQueryPropertyFilter = {
|
|
29
|
-
|
|
30
|
-
readonly propertyIdentifier: string;
|
|
31
|
-
readonly conditions: ImbricateDocumentQueryPropertyFilterCondition[];
|
|
32
|
-
};
|
|
33
|
-
|
|
34
26
|
export type ImbricateDocumentQueryAnnotationFilter = {
|
|
35
|
-
|
|
36
27
|
readonly namespace: string;
|
|
37
28
|
readonly identifier: string;
|
|
29
|
+
readonly attribute: IMBRICATE_QUERY_ATTRIBUTE;
|
|
38
30
|
readonly condition: IMBRICATE_QUERY_COMPARE_CONDITION;
|
|
39
31
|
readonly value: any;
|
|
40
32
|
};
|
|
41
|
-
|
|
42
33
|
/**
|
|
43
34
|
* Query of the document
|
|
44
|
-
*
|
|
35
|
+
*
|
|
45
36
|
* @param limit limit of the query
|
|
46
37
|
* @param skip skip of the query
|
|
47
38
|
*/
|
|
48
39
|
export type ImbricateDocumentQuery = {
|
|
49
|
-
|
|
50
40
|
readonly limit?: number;
|
|
51
41
|
readonly skip?: number;
|
|
52
|
-
|
|
53
42
|
readonly propertyFilters?: ImbricateDocumentQueryPropertyFilter[];
|
|
54
43
|
readonly annotationFilters?: ImbricateDocumentQueryAnnotationFilter[];
|
|
55
44
|
};
|
|
56
|
-
|
|
57
45
|
/**
|
|
58
46
|
* Edit record type of the document
|
|
59
47
|
*/
|
|
60
|
-
export enum IMBRICATE_DATABASE_EDIT_TYPE {
|
|
61
|
-
|
|
48
|
+
export declare enum IMBRICATE_DATABASE_EDIT_TYPE {
|
|
62
49
|
PUT_SCHEMA = "PUT_SCHEMA",
|
|
63
50
|
PUT_ANNOTATION = "PUT_ANNOTATION",
|
|
64
|
-
DELETE_ANNOTATION = "DELETE_ANNOTATION"
|
|
51
|
+
DELETE_ANNOTATION = "DELETE_ANNOTATION"
|
|
65
52
|
}
|
|
66
|
-
|
|
67
53
|
export type DatabaseEditOperationPutAnnotation = {
|
|
68
|
-
|
|
69
54
|
readonly annotationNamespace: string;
|
|
70
55
|
readonly annotationIdentifier: string;
|
|
71
|
-
|
|
72
56
|
readonly data: any;
|
|
73
57
|
};
|
|
74
|
-
|
|
75
58
|
export type DatabaseEditOperationDeleteAnnotation = {
|
|
76
|
-
|
|
77
59
|
readonly annotationNamespace: string;
|
|
78
60
|
readonly annotationIdentifier: string;
|
|
79
61
|
};
|
|
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
|
-
|
|
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;
|
|
88
63
|
export type DatabaseEditOperation<T extends IMBRICATE_DATABASE_EDIT_TYPE> = {
|
|
89
|
-
|
|
90
64
|
readonly action: T;
|
|
91
65
|
readonly value: DatabaseEditOperationValue<T>;
|
|
92
66
|
};
|
|
93
|
-
|
|
94
67
|
export type DatabaseEditRecord = {
|
|
95
|
-
|
|
96
68
|
readonly uniqueIdentifier: string;
|
|
97
69
|
readonly editAt: Date;
|
|
98
|
-
|
|
99
70
|
readonly operations: Array<DatabaseEditOperation<IMBRICATE_DATABASE_EDIT_TYPE>>;
|
|
100
|
-
|
|
101
71
|
readonly author?: ImbricateAuthor;
|
|
102
72
|
};
|
|
103
|
-
|
|
104
73
|
export type DatabaseAnnotations = Record<DatabaseAnnotationKey, DatabaseAnnotationValue>;
|
|
105
|
-
|
|
106
74
|
export type DatabaseAnnotationKey = string;
|
|
107
75
|
export type DatabaseAnnotationValue = {
|
|
108
|
-
|
|
109
76
|
readonly namespace: string;
|
|
110
77
|
readonly identifier: string;
|
|
111
|
-
|
|
112
78
|
readonly data: any;
|
|
113
79
|
};
|
|
114
|
-
|
|
115
80
|
export type ImbricateDatabaseAuditOptions = {
|
|
116
|
-
|
|
117
81
|
/**
|
|
118
82
|
* Do not add edit record, this is controlled an function may vary by origin
|
|
119
83
|
*/
|
|
@@ -0,0 +1,31 @@
|
|
|
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_ATTRIBUTE = 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["EXIST"] = "EXIST";
|
|
13
|
+
})(IMBRICATE_QUERY_COMPARE_CONDITION || (exports.IMBRICATE_QUERY_COMPARE_CONDITION = IMBRICATE_QUERY_COMPARE_CONDITION = {}));
|
|
14
|
+
var IMBRICATE_QUERY_ATTRIBUTE;
|
|
15
|
+
(function (IMBRICATE_QUERY_ATTRIBUTE) {
|
|
16
|
+
IMBRICATE_QUERY_ATTRIBUTE["VALUE"] = "VALUE";
|
|
17
|
+
})(IMBRICATE_QUERY_ATTRIBUTE || (exports.IMBRICATE_QUERY_ATTRIBUTE = IMBRICATE_QUERY_ATTRIBUTE = {}));
|
|
18
|
+
var IMBRICATE_QUERY_PROPERTY_CONDITION_TARGET;
|
|
19
|
+
(function (IMBRICATE_QUERY_PROPERTY_CONDITION_TARGET) {
|
|
20
|
+
IMBRICATE_QUERY_PROPERTY_CONDITION_TARGET["PROPERTY_TYPE"] = "PROPERTY_TYPE";
|
|
21
|
+
IMBRICATE_QUERY_PROPERTY_CONDITION_TARGET["PROPERTY_VALUE"] = "PROPERTY_VALUE";
|
|
22
|
+
})(IMBRICATE_QUERY_PROPERTY_CONDITION_TARGET || (exports.IMBRICATE_QUERY_PROPERTY_CONDITION_TARGET = IMBRICATE_QUERY_PROPERTY_CONDITION_TARGET = {}));
|
|
23
|
+
/**
|
|
24
|
+
* Edit record type of the document
|
|
25
|
+
*/
|
|
26
|
+
var IMBRICATE_DATABASE_EDIT_TYPE;
|
|
27
|
+
(function (IMBRICATE_DATABASE_EDIT_TYPE) {
|
|
28
|
+
IMBRICATE_DATABASE_EDIT_TYPE["PUT_SCHEMA"] = "PUT_SCHEMA";
|
|
29
|
+
IMBRICATE_DATABASE_EDIT_TYPE["PUT_ANNOTATION"] = "PUT_ANNOTATION";
|
|
30
|
+
IMBRICATE_DATABASE_EDIT_TYPE["DELETE_ANNOTATION"] = "DELETE_ANNOTATION";
|
|
31
|
+
})(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[]>;
|
|
@@ -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,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;
|