@imbricate/core 3.4.0 → 3.6.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 +10 -0
- package/database/interface.d.ts +5 -6
- package/database/schema.d.ts +4 -1
- package/document/definition.d.ts +10 -0
- package/document/interface.d.ts +5 -7
- package/document/property/default-value.d.ts +7 -0
- package/document/property/default-value.js +25 -0
- package/document/property/triage-base.d.ts +1 -0
- package/document/property/triage-base.js +4 -0
- package/document/property.d.ts +5 -1
- package/document/property.js +4 -0
- package/document/validate.js +6 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +1 -1
package/database/definition.d.ts
CHANGED
|
@@ -31,3 +31,13 @@ export type DatabaseEditRecord = {
|
|
|
31
31
|
readonly author: ImbricateAuthor;
|
|
32
32
|
readonly operations: DatabaseEditOperation[];
|
|
33
33
|
};
|
|
34
|
+
export type ImbricateDatabaseAuditOptions = {
|
|
35
|
+
/**
|
|
36
|
+
* Do not add edit record, this is controlled an function may vary by origin
|
|
37
|
+
*/
|
|
38
|
+
readonly noEditRecord?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Use this author to add edit record, this is controlled an function may vary by origin
|
|
41
|
+
*/
|
|
42
|
+
readonly author?: ImbricateAuthor;
|
|
43
|
+
};
|
package/database/interface.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { IImbricateDocument } from "../document/interface";
|
|
7
7
|
import { DocumentProperties } from "../document/property";
|
|
8
|
-
import { DatabaseEditRecord, ImbricateDocumentQuery } from "./definition";
|
|
8
|
+
import { DatabaseEditRecord, ImbricateDatabaseAuditOptions, ImbricateDocumentQuery } from "./definition";
|
|
9
9
|
import { ImbricateDatabaseSchema } from "./schema";
|
|
10
10
|
export interface IImbricateDatabase {
|
|
11
11
|
/**
|
|
@@ -25,24 +25,23 @@ export interface IImbricateDatabase {
|
|
|
25
25
|
* Existing documents will still be kept, and stays unchanged
|
|
26
26
|
*
|
|
27
27
|
* @param schema schema of the database
|
|
28
|
-
* @param
|
|
28
|
+
* @param auditOptions audit options of the database
|
|
29
29
|
*
|
|
30
30
|
* @returns a promise of the updated schema
|
|
31
31
|
* Note: if the origin supports Document Edit Record, the edit record will be added by default
|
|
32
32
|
* If you do not want to add the edit record, set `noEditRecord` to true
|
|
33
33
|
*/
|
|
34
|
-
putSchema(schema: ImbricateDatabaseSchema,
|
|
34
|
+
putSchema(schema: ImbricateDatabaseSchema, auditOptions?: ImbricateDatabaseAuditOptions): PromiseLike<void>;
|
|
35
35
|
/**
|
|
36
36
|
* Create a new document in the database
|
|
37
37
|
* If origin supports Document Edit Record, the edit record will be added by default
|
|
38
38
|
*
|
|
39
39
|
* @param properties properties of the document
|
|
40
|
-
* @param
|
|
41
|
-
* if not provided, a unique identifier will be generated
|
|
40
|
+
* @param auditOptions audit options of the document
|
|
42
41
|
*
|
|
43
42
|
* @returns a promise of the created document
|
|
44
43
|
*/
|
|
45
|
-
createDocument(properties: DocumentProperties,
|
|
44
|
+
createDocument(properties: DocumentProperties, auditOptions?: ImbricateDatabaseAuditOptions): PromiseLike<IImbricateDocument>;
|
|
46
45
|
/**
|
|
47
46
|
* Get one document from the database
|
|
48
47
|
*
|
package/database/schema.d.ts
CHANGED
|
@@ -20,6 +20,9 @@ export type ImbricateDatabaseSchemaPropertyOptionsLabel = {
|
|
|
20
20
|
* Allow multiple labels
|
|
21
21
|
*/
|
|
22
22
|
readonly allowMultiple: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Label Options
|
|
25
|
+
*/
|
|
23
26
|
readonly labelOptions: ImbricateDatabaseSchemaPropertyOptionsLabelOption[];
|
|
24
27
|
};
|
|
25
28
|
export type ImbricateDatabaseSchemaPropertyOptionsReference = {
|
|
@@ -33,7 +36,7 @@ export type ImbricateDatabaseSchemaPropertyOptionsReference = {
|
|
|
33
36
|
*/
|
|
34
37
|
readonly databases: ImbricateDatabaseSchemaPropertyOptionsReferenceDatabase[];
|
|
35
38
|
};
|
|
36
|
-
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.IMBRISCRIPT ? {} : T extends IMBRICATE_PROPERTY_TYPE.DATE ? {} : T extends IMBRICATE_PROPERTY_TYPE.LABEL ? ImbricateDatabaseSchemaPropertyOptionsLabel : T extends IMBRICATE_PROPERTY_TYPE.REFERENCE ? ImbricateDatabaseSchemaPropertyOptionsReference : never;
|
|
39
|
+
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;
|
|
37
40
|
export type ImbricateDatabaseSchemaPropertyForCreation<T extends IMBRICATE_PROPERTY_TYPE> = {
|
|
38
41
|
readonly propertyName: string;
|
|
39
42
|
readonly propertyType: T;
|
package/document/definition.d.ts
CHANGED
|
@@ -16,3 +16,13 @@ export type DocumentEditRecord = {
|
|
|
16
16
|
readonly author: ImbricateAuthor;
|
|
17
17
|
readonly operations: DocumentEditOperation[];
|
|
18
18
|
};
|
|
19
|
+
export type ImbricateDocumentAuditOptions = {
|
|
20
|
+
/**
|
|
21
|
+
* Do not add edit record, this is controlled an function may vary by origin
|
|
22
|
+
*/
|
|
23
|
+
readonly noEditRecord?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Use this author to add edit record, this is controlled an function may vary by origin
|
|
26
|
+
*/
|
|
27
|
+
readonly author?: ImbricateAuthor;
|
|
28
|
+
};
|
package/document/interface.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @namespace Document
|
|
4
4
|
* @description Interface
|
|
5
5
|
*/
|
|
6
|
-
import { DocumentEditRecord } from "./definition";
|
|
6
|
+
import { DocumentEditRecord, ImbricateDocumentAuditOptions } from "./definition";
|
|
7
7
|
import { DocumentProperties, DocumentPropertyKey, DocumentPropertyValue, IMBRICATE_PROPERTY_TYPE } from "./property";
|
|
8
8
|
export interface IImbricateDocument {
|
|
9
9
|
/**
|
|
@@ -19,26 +19,24 @@ export interface IImbricateDocument {
|
|
|
19
19
|
*
|
|
20
20
|
* @param key key of the property
|
|
21
21
|
* @param value value of the property
|
|
22
|
-
* @param
|
|
23
|
-
* Default to false, if set to true, the edit record will not be added to the document
|
|
22
|
+
* @param auditOptions audit options of the document
|
|
24
23
|
*
|
|
25
24
|
* @returns a promise of the edit records of the document
|
|
26
25
|
* Note: the edit records will not be added to the document if `noEditRecord` is true,
|
|
27
26
|
* Call `addEditRecords` to add the edit records manually.
|
|
28
27
|
*/
|
|
29
|
-
putProperty(key: DocumentPropertyKey, value: DocumentPropertyValue<IMBRICATE_PROPERTY_TYPE>,
|
|
28
|
+
putProperty(key: DocumentPropertyKey, value: DocumentPropertyValue<IMBRICATE_PROPERTY_TYPE>, auditOptions?: ImbricateDocumentAuditOptions): PromiseLike<DocumentEditRecord[]>;
|
|
30
29
|
/**
|
|
31
30
|
* Put and replace all properties of the document
|
|
32
31
|
*
|
|
33
32
|
* @param properties properties of the document
|
|
34
|
-
* @param
|
|
35
|
-
* Default to false, if set to true, the edit record will not be added to the document
|
|
33
|
+
* @param auditOptions audit options of the document
|
|
36
34
|
*
|
|
37
35
|
* @returns a promise of the edit records of the document
|
|
38
36
|
* Note: the edit records will not be added to the document if `noEditRecord` is true,
|
|
39
37
|
* Call `addEditRecords` to add the edit records manually.
|
|
40
38
|
*/
|
|
41
|
-
putProperties(properties: DocumentProperties,
|
|
39
|
+
putProperties(properties: DocumentProperties, auditOptions?: ImbricateDocumentAuditOptions): PromiseLike<DocumentEditRecord[]>;
|
|
42
40
|
/**
|
|
43
41
|
* Add edit records to the document, optional
|
|
44
42
|
* This method is optional, if not implemented, means the origin
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author WMXPY
|
|
3
|
+
* @namespace Document_Property
|
|
4
|
+
* @description Default Value
|
|
5
|
+
*/
|
|
6
|
+
import { DocumentPropertyValueObject, IMBRICATE_PROPERTY_TYPE } from "../property";
|
|
7
|
+
export declare const getImbricateDefaultValueOfProperty: (type: IMBRICATE_PROPERTY_TYPE) => DocumentPropertyValueObject<IMBRICATE_PROPERTY_TYPE>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @author WMXPY
|
|
4
|
+
* @namespace Document_Property
|
|
5
|
+
* @description Default Value
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.getImbricateDefaultValueOfProperty = void 0;
|
|
9
|
+
const property_1 = require("../property");
|
|
10
|
+
// IMBRICATE_PROPERTY_TYPE SWITCH
|
|
11
|
+
const getImbricateDefaultValueOfProperty = (type) => {
|
|
12
|
+
switch (type) {
|
|
13
|
+
case property_1.IMBRICATE_PROPERTY_TYPE.BOOLEAN: return false;
|
|
14
|
+
case property_1.IMBRICATE_PROPERTY_TYPE.STRING: return "";
|
|
15
|
+
case property_1.IMBRICATE_PROPERTY_TYPE.NUMBER: return 0;
|
|
16
|
+
case property_1.IMBRICATE_PROPERTY_TYPE.MARKDOWN: return "";
|
|
17
|
+
case property_1.IMBRICATE_PROPERTY_TYPE.JSON: return "";
|
|
18
|
+
case property_1.IMBRICATE_PROPERTY_TYPE.IMBRISCRIPT: return "";
|
|
19
|
+
case property_1.IMBRICATE_PROPERTY_TYPE.DATE: return new Date().toISOString();
|
|
20
|
+
case property_1.IMBRICATE_PROPERTY_TYPE.LABEL: return [];
|
|
21
|
+
case property_1.IMBRICATE_PROPERTY_TYPE.REFERENCE: return [];
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
};
|
|
25
|
+
exports.getImbricateDefaultValueOfProperty = getImbricateDefaultValueOfProperty;
|
|
@@ -22,6 +22,7 @@ export declare class ImbricateDocumentPropertyTriageBase<Result> {
|
|
|
22
22
|
forString(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.STRING, Result>): this;
|
|
23
23
|
forNumber(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.NUMBER, Result>): this;
|
|
24
24
|
forMarkdown(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.MARKDOWN, Result>): this;
|
|
25
|
+
forJson(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.JSON, Result>): this;
|
|
25
26
|
forImbriscript(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.IMBRISCRIPT, Result>): this;
|
|
26
27
|
forDate(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.DATE, Result>): this;
|
|
27
28
|
forLabel(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.LABEL, Result>): this;
|
|
@@ -41,6 +41,10 @@ class ImbricateDocumentPropertyTriageBase {
|
|
|
41
41
|
this._triageFunctionsByType.set(property_1.IMBRICATE_PROPERTY_TYPE.MARKDOWN, triageFunction);
|
|
42
42
|
return this;
|
|
43
43
|
}
|
|
44
|
+
forJson(triageFunction) {
|
|
45
|
+
this._triageFunctionsByType.set(property_1.IMBRICATE_PROPERTY_TYPE.JSON, triageFunction);
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
44
48
|
forImbriscript(triageFunction) {
|
|
45
49
|
this._triageFunctionsByType.set(property_1.IMBRICATE_PROPERTY_TYPE.IMBRISCRIPT, triageFunction);
|
|
46
50
|
return this;
|
package/document/property.d.ts
CHANGED
|
@@ -23,6 +23,10 @@ export declare enum IMBRICATE_PROPERTY_TYPE {
|
|
|
23
23
|
* MARKDOWN - markdown, store as text object unique identifier. Display as markdown
|
|
24
24
|
*/
|
|
25
25
|
MARKDOWN = "MARKDOWN",
|
|
26
|
+
/**
|
|
27
|
+
* JSON - json, store as text object unique identifier. Display as JSON
|
|
28
|
+
*/
|
|
29
|
+
JSON = "JSON",
|
|
26
30
|
/**
|
|
27
31
|
* IMBRISCRIPT - imbricate script, store as text object unique identifier. Display as imbricate script
|
|
28
32
|
* The script is executed in a sandbox environment, using customized javascript engine
|
|
@@ -64,7 +68,7 @@ export type DocumentPropertyValueObjectReference = {
|
|
|
64
68
|
readonly databaseUniqueIdentifier: string;
|
|
65
69
|
readonly documentUniqueIdentifier: string;
|
|
66
70
|
};
|
|
67
|
-
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.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;
|
|
68
72
|
/**
|
|
69
73
|
* Edit record type of the document
|
|
70
74
|
*/
|
package/document/property.js
CHANGED
|
@@ -27,6 +27,10 @@ var IMBRICATE_PROPERTY_TYPE;
|
|
|
27
27
|
* MARKDOWN - markdown, store as text object unique identifier. Display as markdown
|
|
28
28
|
*/
|
|
29
29
|
IMBRICATE_PROPERTY_TYPE["MARKDOWN"] = "MARKDOWN";
|
|
30
|
+
/**
|
|
31
|
+
* JSON - json, store as text object unique identifier. Display as JSON
|
|
32
|
+
*/
|
|
33
|
+
IMBRICATE_PROPERTY_TYPE["JSON"] = "JSON";
|
|
30
34
|
/**
|
|
31
35
|
* IMBRISCRIPT - imbricate script, store as text object unique identifier. Display as imbricate script
|
|
32
36
|
* The script is executed in a sandbox environment, using customized javascript engine
|
package/document/validate.js
CHANGED
|
@@ -65,6 +65,12 @@ const validateImbricateProperties = (properties, schema, allowExtraProperties =
|
|
|
65
65
|
}
|
|
66
66
|
break;
|
|
67
67
|
}
|
|
68
|
+
case property_1.IMBRICATE_PROPERTY_TYPE.JSON: {
|
|
69
|
+
if (typeof value.value !== "string") {
|
|
70
|
+
return `Property ${key} value must be a string of text object reference`;
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
68
74
|
case property_1.IMBRICATE_PROPERTY_TYPE.IMBRISCRIPT: {
|
|
69
75
|
if (typeof value.value !== "string") {
|
|
70
76
|
return `Property ${key} value must be a string of text object reference`;
|
package/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from "./database/schema";
|
|
|
10
10
|
export * from "./document/definition";
|
|
11
11
|
export * from "./document/interface";
|
|
12
12
|
export * from "./document/property";
|
|
13
|
+
export * from "./document/property/default-value";
|
|
13
14
|
export * from "./document/property/definition";
|
|
14
15
|
export * from "./document/property/primary";
|
|
15
16
|
export * from "./document/property/triage";
|
package/index.js
CHANGED
|
@@ -26,6 +26,7 @@ __exportStar(require("./database/schema"), exports);
|
|
|
26
26
|
__exportStar(require("./document/definition"), exports);
|
|
27
27
|
__exportStar(require("./document/interface"), exports);
|
|
28
28
|
__exportStar(require("./document/property"), exports);
|
|
29
|
+
__exportStar(require("./document/property/default-value"), exports);
|
|
29
30
|
__exportStar(require("./document/property/definition"), exports);
|
|
30
31
|
__exportStar(require("./document/property/primary"), exports);
|
|
31
32
|
__exportStar(require("./document/property/triage"), exports);
|