@imbricate/core 3.0.2 → 3.0.3
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/document/definition.d.ts +2 -2
- package/document/interface.d.ts +2 -2
- package/document/property/definition.d.ts +7 -0
- package/document/property/definition.js +7 -0
- package/document/property/triage-base.d.ts +24 -0
- package/document/property/triage-base.js +56 -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/document/property.d.ts +4 -3
- package/index.d.ts +3 -0
- package/index.js +3 -0
- package/package.json +1 -1
package/document/definition.d.ts
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* @description Definition
|
|
5
5
|
*/
|
|
6
6
|
import { ImbricateAuthor } from "../author/definition";
|
|
7
|
-
import { DocumentPropertyKey, DocumentPropertyValue, IMBRICATE_DOCUMENT_EDIT_TYPE } from "./property";
|
|
7
|
+
import { DocumentPropertyKey, DocumentPropertyValue, IMBRICATE_DOCUMENT_EDIT_TYPE, IMBRICATE_PROPERTY_TYPE } from "./property";
|
|
8
8
|
export type DocumentEditOperation = {
|
|
9
9
|
readonly key: DocumentPropertyKey;
|
|
10
10
|
readonly action: IMBRICATE_DOCUMENT_EDIT_TYPE;
|
|
11
|
-
readonly value: DocumentPropertyValue
|
|
11
|
+
readonly value: DocumentPropertyValue<IMBRICATE_PROPERTY_TYPE>;
|
|
12
12
|
};
|
|
13
13
|
export type DocumentEditRecord = {
|
|
14
14
|
readonly uniqueIdentifier: string;
|
package/document/interface.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @description Interface
|
|
5
5
|
*/
|
|
6
6
|
import { DocumentEditRecord } from "./definition";
|
|
7
|
-
import { DocumentProperties, DocumentPropertyKey, DocumentPropertyValue } from "./property";
|
|
7
|
+
import { DocumentProperties, DocumentPropertyKey, DocumentPropertyValue, IMBRICATE_PROPERTY_TYPE } from "./property";
|
|
8
8
|
export interface IImbricateDocument {
|
|
9
9
|
/**
|
|
10
10
|
* Unique identifier of the database
|
|
@@ -22,7 +22,7 @@ export interface IImbricateDocument {
|
|
|
22
22
|
* Note: the edit records will not be added to the document if `noEditRecord` is true,
|
|
23
23
|
* Call `addEditRecords` to add the edit records manually.
|
|
24
24
|
*/
|
|
25
|
-
putProperty(key: DocumentPropertyKey, value: DocumentPropertyValue
|
|
25
|
+
putProperty(key: DocumentPropertyKey, value: DocumentPropertyValue<IMBRICATE_PROPERTY_TYPE>, noEditRecord?: boolean): PromiseLike<DocumentEditRecord[]>;
|
|
26
26
|
/**
|
|
27
27
|
* Put and replace all properties of the document
|
|
28
28
|
*
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author WMXPY
|
|
3
|
+
* @namespace Document_Property
|
|
4
|
+
* @description Definition
|
|
5
|
+
*/
|
|
6
|
+
import { DocumentPropertyKey, DocumentPropertyValue, IMBRICATE_PROPERTY_TYPE } from "../property";
|
|
7
|
+
export type DocumentPropertyTriageFunction<T extends IMBRICATE_PROPERTY_TYPE, Result> = (propertyKey: DocumentPropertyKey, value: DocumentPropertyValue<T>) => Result;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author WMXPY
|
|
3
|
+
* @namespace Document_Property
|
|
4
|
+
* @description Triage Base
|
|
5
|
+
*/
|
|
6
|
+
import { DocumentProperties, DocumentPropertyKey, IMBRICATE_PROPERTY_TYPE } from "../property";
|
|
7
|
+
import { DocumentPropertyTriageFunction } from "./definition";
|
|
8
|
+
export declare class ImbricateDocumentPropertyTriageBase<Result> {
|
|
9
|
+
private readonly _triageFunctionsByKey;
|
|
10
|
+
private readonly _triageFunctionsByType;
|
|
11
|
+
protected constructor();
|
|
12
|
+
/**
|
|
13
|
+
* Set triage function for property key,
|
|
14
|
+
* This action will override document value based triage functions
|
|
15
|
+
*
|
|
16
|
+
* @param propertyKey property key
|
|
17
|
+
* @param triageFunction triage function
|
|
18
|
+
* @returns triage manager
|
|
19
|
+
*/
|
|
20
|
+
forPropertyKey<T extends IMBRICATE_PROPERTY_TYPE>(propertyKey: DocumentPropertyKey, triageFunction: DocumentPropertyTriageFunction<T, Result>): this;
|
|
21
|
+
forString(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.STRING, Result>): this;
|
|
22
|
+
forMarkdown(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.MARKDOWN, Result>): this;
|
|
23
|
+
protected _collect(properties: DocumentProperties): Map<DocumentPropertyKey, Result>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @author WMXPY
|
|
4
|
+
* @namespace Document_Property
|
|
5
|
+
* @description Triage Base
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.ImbricateDocumentPropertyTriageBase = void 0;
|
|
9
|
+
const property_1 = require("../property");
|
|
10
|
+
class ImbricateDocumentPropertyTriageBase {
|
|
11
|
+
constructor() {
|
|
12
|
+
this._triageFunctionsByKey = new Map();
|
|
13
|
+
this._triageFunctionsByType = new Map();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Set triage function for property key,
|
|
17
|
+
* This action will override document value based triage functions
|
|
18
|
+
*
|
|
19
|
+
* @param propertyKey property key
|
|
20
|
+
* @param triageFunction triage function
|
|
21
|
+
* @returns triage manager
|
|
22
|
+
*/
|
|
23
|
+
forPropertyKey(propertyKey, triageFunction) {
|
|
24
|
+
this._triageFunctionsByKey.set(propertyKey, triageFunction);
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
forString(triageFunction) {
|
|
28
|
+
this._triageFunctionsByType.set(property_1.IMBRICATE_PROPERTY_TYPE.STRING, triageFunction);
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
forMarkdown(triageFunction) {
|
|
32
|
+
this._triageFunctionsByType.set(property_1.IMBRICATE_PROPERTY_TYPE.MARKDOWN, triageFunction);
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
_collect(properties) {
|
|
36
|
+
const keys = Object.keys(properties);
|
|
37
|
+
const result = new Map();
|
|
38
|
+
for (const key of keys) {
|
|
39
|
+
const property = properties[key];
|
|
40
|
+
const triageFunction = this._triageFunctionsByKey.get(key);
|
|
41
|
+
if (typeof triageFunction === "function") {
|
|
42
|
+
const value = triageFunction(key, property);
|
|
43
|
+
result.set(key, value);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const typeFunction = this._triageFunctionsByType.get(property.type);
|
|
47
|
+
if (typeof typeFunction === "function") {
|
|
48
|
+
const value = typeFunction(key, property);
|
|
49
|
+
result.set(key, value);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.ImbricateDocumentPropertyTriageBase = ImbricateDocumentPropertyTriageBase;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author WMXPY
|
|
3
|
+
* @namespace Document_Property
|
|
4
|
+
* @description Triage Manager
|
|
5
|
+
*/
|
|
6
|
+
import { DocumentProperties, DocumentPropertyKey } from "../property";
|
|
7
|
+
import { ImbricateDocumentPropertyTriageBase } from "./triage-base";
|
|
8
|
+
export declare class ImbricateDocumentPropertyTriageManager<Result> extends ImbricateDocumentPropertyTriageBase<Result> {
|
|
9
|
+
static create<Result>(properties: DocumentProperties): ImbricateDocumentPropertyTriageManager<Result>;
|
|
10
|
+
private readonly _properties;
|
|
11
|
+
private constructor();
|
|
12
|
+
/**
|
|
13
|
+
* Collect the result as array
|
|
14
|
+
*
|
|
15
|
+
* @returns collected result as array
|
|
16
|
+
*/
|
|
17
|
+
collectAsArray(): Result[];
|
|
18
|
+
/**
|
|
19
|
+
* Collect the result as map
|
|
20
|
+
*
|
|
21
|
+
* @returns collected result as map
|
|
22
|
+
*/
|
|
23
|
+
collectAsMap(): Map<DocumentPropertyKey, Result>;
|
|
24
|
+
/**
|
|
25
|
+
* Collect the result as object
|
|
26
|
+
*
|
|
27
|
+
* @returns collected result as object
|
|
28
|
+
*/
|
|
29
|
+
collectAsObject(): Record<DocumentPropertyKey, Result>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @author WMXPY
|
|
4
|
+
* @namespace Document_Property
|
|
5
|
+
* @description Triage Manager
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.ImbricateDocumentPropertyTriageManager = void 0;
|
|
9
|
+
const triage_base_1 = require("./triage-base");
|
|
10
|
+
class ImbricateDocumentPropertyTriageManager extends triage_base_1.ImbricateDocumentPropertyTriageBase {
|
|
11
|
+
static create(properties) {
|
|
12
|
+
return new ImbricateDocumentPropertyTriageManager(properties);
|
|
13
|
+
}
|
|
14
|
+
constructor(properties) {
|
|
15
|
+
super();
|
|
16
|
+
this._properties = properties;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Collect the result as array
|
|
20
|
+
*
|
|
21
|
+
* @returns collected result as array
|
|
22
|
+
*/
|
|
23
|
+
collectAsArray() {
|
|
24
|
+
const result = super._collect(this._properties);
|
|
25
|
+
return Array.from(result.values());
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Collect the result as map
|
|
29
|
+
*
|
|
30
|
+
* @returns collected result as map
|
|
31
|
+
*/
|
|
32
|
+
collectAsMap() {
|
|
33
|
+
return super._collect(this._properties);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Collect the result as object
|
|
37
|
+
*
|
|
38
|
+
* @returns collected result as object
|
|
39
|
+
*/
|
|
40
|
+
collectAsObject() {
|
|
41
|
+
const result = super._collect(this._properties);
|
|
42
|
+
const keys = Array.from(result.keys());
|
|
43
|
+
const object = {};
|
|
44
|
+
for (const key of keys) {
|
|
45
|
+
object[key] = result.get(key);
|
|
46
|
+
}
|
|
47
|
+
return object;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.ImbricateDocumentPropertyTriageManager = ImbricateDocumentPropertyTriageManager;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author WMXPY
|
|
3
|
+
* @namespace Document_Property
|
|
4
|
+
* @description Triage
|
|
5
|
+
*/
|
|
6
|
+
import { DocumentProperties } from "../property";
|
|
7
|
+
import { ImbricateDocumentPropertyTriageManager } from "./triage-manager";
|
|
8
|
+
export declare const triageImbricateDocumentProperties: <Result>(properties: DocumentProperties) => ImbricateDocumentPropertyTriageManager<Result>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @author WMXPY
|
|
4
|
+
* @namespace Document_Property
|
|
5
|
+
* @description Triage
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.triageImbricateDocumentProperties = void 0;
|
|
9
|
+
const triage_manager_1 = require("./triage-manager");
|
|
10
|
+
const triageImbricateDocumentProperties = (properties) => {
|
|
11
|
+
return triage_manager_1.ImbricateDocumentPropertyTriageManager.create(properties);
|
|
12
|
+
};
|
|
13
|
+
exports.triageImbricateDocumentProperties = triageImbricateDocumentProperties;
|
package/document/property.d.ts
CHANGED
|
@@ -16,12 +16,13 @@ export declare enum IMBRICATE_PROPERTY_TYPE {
|
|
|
16
16
|
/**
|
|
17
17
|
* Document properties
|
|
18
18
|
*/
|
|
19
|
-
export type DocumentProperties = Record<DocumentPropertyKey, DocumentPropertyValue
|
|
19
|
+
export type DocumentProperties = Record<DocumentPropertyKey, DocumentPropertyValue<IMBRICATE_PROPERTY_TYPE>>;
|
|
20
20
|
export type DocumentPropertyKey = string;
|
|
21
|
-
export type DocumentPropertyValue = {
|
|
21
|
+
export type DocumentPropertyValue<T extends IMBRICATE_PROPERTY_TYPE> = {
|
|
22
22
|
readonly type: IMBRICATE_PROPERTY_TYPE;
|
|
23
|
-
readonly value:
|
|
23
|
+
readonly value: DocumentPropertyValueObject<T>;
|
|
24
24
|
};
|
|
25
|
+
export type DocumentPropertyValueObject<T extends IMBRICATE_PROPERTY_TYPE> = T extends IMBRICATE_PROPERTY_TYPE.STRING ? string : T extends IMBRICATE_PROPERTY_TYPE.MARKDOWN ? string : never;
|
|
25
26
|
/**
|
|
26
27
|
* Edit record type of the document
|
|
27
28
|
*/
|
package/index.d.ts
CHANGED
|
@@ -10,6 +10,9 @@ 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/definition";
|
|
14
|
+
export * from "./document/property/triage";
|
|
15
|
+
export * from "./document/property/triage-manager";
|
|
13
16
|
export * from "./document/validate";
|
|
14
17
|
export * from "./loader/definition";
|
|
15
18
|
export * from "./loader/origin-loader";
|
package/index.js
CHANGED
|
@@ -26,6 +26,9 @@ __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/definition"), exports);
|
|
30
|
+
__exportStar(require("./document/property/triage"), exports);
|
|
31
|
+
__exportStar(require("./document/property/triage-manager"), exports);
|
|
29
32
|
__exportStar(require("./document/validate"), exports);
|
|
30
33
|
__exportStar(require("./loader/definition"), exports);
|
|
31
34
|
__exportStar(require("./loader/origin-loader"), exports);
|