@imbricate/core 3.7.3 → 3.8.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/.editorconfig +10 -0
- package/.gitattributes +4 -0
- package/.github/dependabot.yml +8 -0
- package/.github/workflows/ci.yml +48 -0
- package/.vscode/settings.json +8 -0
- package/.yarn/releases/yarn-4.4.0.cjs +925 -0
- package/.yarnrc.yml +3 -0
- package/babel.config.js +14 -0
- package/docs/README.md +70 -0
- package/eslint.config.mjs +64 -0
- package/jest.config.ts +14 -0
- package/package.json +27 -3
- package/{author/definition.d.ts → src/author/definition.ts} +4 -0
- package/{database/definition.d.ts → src/database/definition.ts} +67 -4
- package/{database/interface.d.ts → src/database/interface.ts} +69 -27
- package/{database/manager.d.ts → src/database/manager.ts} +24 -9
- package/src/database/schema.ts +165 -0
- package/src/database/validate.ts +77 -0
- package/{document/definition.d.ts → src/document/definition.ts} +31 -3
- package/{document/interface.d.ts → src/document/interface.ts} +44 -15
- package/src/document/property/default-value.ts +26 -0
- package/{document/property/definition.d.ts → src/document/property/definition.ts} +6 -1
- package/src/document/property/primary.ts +29 -0
- package/src/document/property/triage-base.ts +138 -0
- package/src/document/property/triage-manager.ts +68 -0
- package/src/document/property/triage.ts +15 -0
- package/{document/property.d.ts → src/document/property.ts} +23 -4
- package/{document/validate.js → src/document/validate.ts} +33 -21
- package/{index.d.ts → src/index.ts} +3 -0
- package/{loader/definition.d.ts → src/loader/definition.ts} +5 -1
- package/src/loader/origin-loader.ts +88 -0
- package/{loader/persistence.d.ts → src/loader/persistence.ts} +12 -3
- package/{origin/definition.d.ts → src/origin/definition.ts} +1 -0
- package/{origin/interface.d.ts → src/origin/interface.ts} +18 -7
- package/{origin/search.d.ts → src/origin/search.ts} +29 -13
- package/{static/definition.d.ts → src/static/definition.ts} +3 -0
- package/{static/interface.d.ts → src/static/interface.ts} +6 -1
- package/{static/manager.d.ts → src/static/manager.ts} +11 -4
- package/{text/definition.d.ts → src/text/definition.ts} +3 -0
- package/{text/interface.d.ts → src/text/interface.ts} +6 -1
- package/{text/manager.d.ts → src/text/manager.ts} +11 -4
- package/test/unit/database/schema.test.ts +95 -0
- package/test/unit/document/property/primary.test.ts +87 -0
- package/test/unit/document/property/triage.test.ts +64 -0
- package/test/unit/document/validate.test.ts +138 -0
- package/test/unit/loader/definition.test.ts +55 -0
- package/typescript/tsconfig.build.json +23 -0
- package/author/definition.js +0 -7
- package/database/definition.js +0 -17
- package/database/interface.js +0 -7
- package/database/manager.js +0 -7
- package/database/schema.d.ts +0 -70
- package/database/schema.js +0 -78
- package/document/definition.js +0 -17
- package/document/interface.js +0 -7
- package/document/property/default-value.d.ts +0 -7
- package/document/property/default-value.js +0 -25
- package/document/property/definition.js +0 -7
- package/document/property/primary.d.ts +0 -8
- package/document/property/primary.js +0 -20
- package/document/property/triage-base.d.ts +0 -31
- package/document/property/triage-base.js +0 -85
- package/document/property/triage-manager.d.ts +0 -30
- package/document/property/triage-manager.js +0 -50
- package/document/property/triage.d.ts +0 -8
- package/document/property/triage.js +0 -13
- package/document/property.js +0 -54
- package/document/validate.d.ts +0 -18
- package/index.js +0 -46
- package/loader/definition.js +0 -7
- package/loader/origin-loader.d.ts +0 -29
- package/loader/origin-loader.js +0 -104
- package/loader/persistence.js +0 -19
- package/origin/definition.js +0 -7
- package/origin/interface.js +0 -7
- package/origin/search.js +0 -14
- package/static/definition.js +0 -7
- package/static/interface.js +0 -7
- package/static/manager.js +0 -7
- package/text/definition.js +0 -7
- package/text/interface.js +0 -7
- package/text/manager.js +0 -7
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author WMXPY
|
|
3
|
+
* @namespace Document_Property
|
|
4
|
+
* @description Triage Manager
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { DocumentProperties, DocumentPropertyKey } from "../property";
|
|
8
|
+
import { ImbricateDocumentPropertyTriageBase } from "./triage-base";
|
|
9
|
+
|
|
10
|
+
export class ImbricateDocumentPropertyTriageManager<Result> extends ImbricateDocumentPropertyTriageBase<Result> {
|
|
11
|
+
|
|
12
|
+
public static create<Result>(
|
|
13
|
+
properties: DocumentProperties,
|
|
14
|
+
): ImbricateDocumentPropertyTriageManager<Result> {
|
|
15
|
+
|
|
16
|
+
return new ImbricateDocumentPropertyTriageManager<Result>(properties);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
private readonly _properties: DocumentProperties;
|
|
20
|
+
|
|
21
|
+
private constructor(
|
|
22
|
+
properties: DocumentProperties,
|
|
23
|
+
) {
|
|
24
|
+
|
|
25
|
+
super();
|
|
26
|
+
this._properties = properties;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Collect the result as array
|
|
31
|
+
*
|
|
32
|
+
* @returns collected result as array
|
|
33
|
+
*/
|
|
34
|
+
public collectAsArray(): Result[] {
|
|
35
|
+
|
|
36
|
+
const result: Map<DocumentPropertyKey, Result> = super._collect(this._properties);
|
|
37
|
+
return Array.from(result.values());
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Collect the result as map
|
|
42
|
+
*
|
|
43
|
+
* @returns collected result as map
|
|
44
|
+
*/
|
|
45
|
+
public collectAsMap(): Map<DocumentPropertyKey, Result> {
|
|
46
|
+
|
|
47
|
+
return super._collect(this._properties);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Collect the result as object
|
|
52
|
+
*
|
|
53
|
+
* @returns collected result as object
|
|
54
|
+
*/
|
|
55
|
+
public collectAsObject(): Record<DocumentPropertyKey, Result> {
|
|
56
|
+
|
|
57
|
+
const result: Map<DocumentPropertyKey, Result> = super._collect(this._properties);
|
|
58
|
+
const keys: DocumentPropertyKey[] = Array.from(result.keys());
|
|
59
|
+
|
|
60
|
+
const object: Record<DocumentPropertyKey, Result> = {} as Record<DocumentPropertyKey, Result>;
|
|
61
|
+
for (const key of keys) {
|
|
62
|
+
|
|
63
|
+
object[key] = result.get(key) as Result;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return object;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author WMXPY
|
|
3
|
+
* @namespace Document_Property
|
|
4
|
+
* @description Triage
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { DocumentProperties } from "../property";
|
|
8
|
+
import { ImbricateDocumentPropertyTriageManager } from "./triage-manager";
|
|
9
|
+
|
|
10
|
+
export const triageImbricateDocumentProperties = <Result>(
|
|
11
|
+
properties: DocumentProperties,
|
|
12
|
+
): ImbricateDocumentPropertyTriageManager<Result> => {
|
|
13
|
+
|
|
14
|
+
return ImbricateDocumentPropertyTriageManager.create<Result>(properties);
|
|
15
|
+
};
|
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
* @namespace Document
|
|
4
4
|
* @description Property
|
|
5
5
|
*/
|
|
6
|
+
|
|
6
7
|
/**
|
|
7
8
|
* Document properties
|
|
8
9
|
*/
|
|
9
|
-
export
|
|
10
|
+
export enum IMBRICATE_PROPERTY_TYPE {
|
|
11
|
+
|
|
10
12
|
/**
|
|
11
13
|
* BOOLEAN - boolean, store as boolean
|
|
12
14
|
*/
|
|
@@ -46,26 +48,43 @@ export declare enum IMBRICATE_PROPERTY_TYPE {
|
|
|
46
48
|
* REFERENCE - reference, store as a list of other document unique identifier
|
|
47
49
|
* Note: Reference is always stored as an array, even if it is a single reference
|
|
48
50
|
*/
|
|
49
|
-
REFERENCE = "REFERENCE"
|
|
51
|
+
REFERENCE = "REFERENCE",
|
|
50
52
|
}
|
|
53
|
+
|
|
51
54
|
/**
|
|
52
55
|
* Document properties
|
|
53
|
-
*
|
|
56
|
+
*
|
|
54
57
|
* Key - Property key, which should match schema properties unique identifier
|
|
55
58
|
* Value - Property value, which should match schema properties type
|
|
56
59
|
*/
|
|
57
60
|
export type DocumentProperties = Record<DocumentPropertyKey, DocumentPropertyValue<IMBRICATE_PROPERTY_TYPE>>;
|
|
61
|
+
|
|
58
62
|
/**
|
|
59
63
|
* Document property key, which should match schema properties unique identifier
|
|
60
64
|
*/
|
|
61
65
|
export type DocumentPropertyKey = string;
|
|
62
66
|
export type DocumentPropertyValue<T extends IMBRICATE_PROPERTY_TYPE> = {
|
|
67
|
+
|
|
63
68
|
readonly type: T;
|
|
64
69
|
readonly value: DocumentPropertyValueObject<T>;
|
|
65
70
|
};
|
|
71
|
+
|
|
66
72
|
export type DocumentPropertyValueObjectReference = {
|
|
73
|
+
|
|
67
74
|
readonly originUniqueIdentifier: string;
|
|
68
75
|
readonly databaseUniqueIdentifier: string;
|
|
69
76
|
readonly documentUniqueIdentifier: string;
|
|
70
77
|
};
|
|
71
|
-
|
|
78
|
+
|
|
79
|
+
// IMBRICATE_PROPERTY_TYPE SWITCH
|
|
80
|
+
export type DocumentPropertyValueObject<T extends IMBRICATE_PROPERTY_TYPE> =
|
|
81
|
+
T extends IMBRICATE_PROPERTY_TYPE.BOOLEAN ? boolean :
|
|
82
|
+
T extends IMBRICATE_PROPERTY_TYPE.STRING ? string :
|
|
83
|
+
T extends IMBRICATE_PROPERTY_TYPE.NUMBER ? number :
|
|
84
|
+
T extends IMBRICATE_PROPERTY_TYPE.MARKDOWN ? string :
|
|
85
|
+
T extends IMBRICATE_PROPERTY_TYPE.JSON ? string :
|
|
86
|
+
T extends IMBRICATE_PROPERTY_TYPE.IMBRISCRIPT ? string :
|
|
87
|
+
T extends IMBRICATE_PROPERTY_TYPE.DATE ? string :
|
|
88
|
+
T extends IMBRICATE_PROPERTY_TYPE.LABEL ? string[] :
|
|
89
|
+
T extends IMBRICATE_PROPERTY_TYPE.REFERENCE ? DocumentPropertyValueObjectReference[] :
|
|
90
|
+
never;
|
|
@@ -1,93 +1,105 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* @author WMXPY
|
|
4
3
|
* @namespace Document
|
|
5
4
|
* @description Validate
|
|
6
5
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
|
|
7
|
+
import { ImbricateDatabaseSchema, ImbricateDatabaseSchemaProperty } from "../database/schema";
|
|
8
|
+
import { DocumentProperties, DocumentPropertyValue, IMBRICATE_PROPERTY_TYPE } from "./property";
|
|
9
|
+
|
|
10
10
|
/**
|
|
11
11
|
* Validate properties with schema
|
|
12
|
-
*
|
|
12
|
+
*
|
|
13
13
|
* @param properties properties to validate
|
|
14
14
|
* @param schema database schema to validate
|
|
15
15
|
* @param allowExtraProperties allow extra properties, optional with default false
|
|
16
|
-
*
|
|
16
|
+
*
|
|
17
17
|
* @returns a string error message if validation failed
|
|
18
18
|
* null if validation passed
|
|
19
19
|
*/
|
|
20
|
-
const validateImbricateProperties = (
|
|
20
|
+
export const validateImbricateProperties = (
|
|
21
|
+
properties: DocumentProperties,
|
|
22
|
+
schema: ImbricateDatabaseSchema,
|
|
23
|
+
allowExtraProperties: boolean = false,
|
|
24
|
+
): string | null => {
|
|
25
|
+
|
|
21
26
|
if (typeof properties !== "object") {
|
|
22
27
|
return "Properties must be an object";
|
|
23
28
|
}
|
|
24
|
-
|
|
29
|
+
|
|
30
|
+
const keys: string[] = Object.keys(properties);
|
|
25
31
|
for (const key of keys) {
|
|
26
|
-
|
|
32
|
+
|
|
33
|
+
const property = schema.properties.find((each: ImbricateDatabaseSchemaProperty<IMBRICATE_PROPERTY_TYPE>) => {
|
|
27
34
|
return each.propertyIdentifier === key;
|
|
28
35
|
});
|
|
36
|
+
|
|
29
37
|
if (!property) {
|
|
30
38
|
if (allowExtraProperties) {
|
|
31
39
|
continue;
|
|
32
40
|
}
|
|
33
41
|
return `Property ${key} not found in schema`;
|
|
34
42
|
}
|
|
35
|
-
|
|
43
|
+
|
|
44
|
+
const value: DocumentPropertyValue<IMBRICATE_PROPERTY_TYPE> = properties[key];
|
|
36
45
|
if (typeof value.type !== "string") {
|
|
37
46
|
return `Property ${key} type must be a string`;
|
|
38
47
|
}
|
|
48
|
+
|
|
39
49
|
if (value.type !== property.propertyType) {
|
|
40
50
|
return `Property ${key} type must be ${property.propertyType}, but got ${value.type}`;
|
|
41
51
|
}
|
|
52
|
+
|
|
42
53
|
// IMBRICATE_PROPERTY_TYPE SWITCH
|
|
43
54
|
switch (value.type) {
|
|
44
|
-
|
|
55
|
+
|
|
56
|
+
case IMBRICATE_PROPERTY_TYPE.BOOLEAN: {
|
|
45
57
|
if (typeof value.value !== "boolean") {
|
|
46
58
|
return `Property ${key} value must be a boolean`;
|
|
47
59
|
}
|
|
48
60
|
break;
|
|
49
61
|
}
|
|
50
|
-
case
|
|
62
|
+
case IMBRICATE_PROPERTY_TYPE.STRING: {
|
|
51
63
|
if (typeof value.value !== "string") {
|
|
52
64
|
return `Property ${key} value must be a string`;
|
|
53
65
|
}
|
|
54
66
|
break;
|
|
55
67
|
}
|
|
56
|
-
case
|
|
68
|
+
case IMBRICATE_PROPERTY_TYPE.NUMBER: {
|
|
57
69
|
if (typeof value.value !== "number") {
|
|
58
70
|
return `Property ${key} value must be a number`;
|
|
59
71
|
}
|
|
60
72
|
break;
|
|
61
73
|
}
|
|
62
|
-
case
|
|
74
|
+
case IMBRICATE_PROPERTY_TYPE.MARKDOWN: {
|
|
63
75
|
if (typeof value.value !== "string") {
|
|
64
76
|
return `Property ${key} value must be a string of text object reference`;
|
|
65
77
|
}
|
|
66
78
|
break;
|
|
67
79
|
}
|
|
68
|
-
case
|
|
80
|
+
case IMBRICATE_PROPERTY_TYPE.JSON: {
|
|
69
81
|
if (typeof value.value !== "string") {
|
|
70
82
|
return `Property ${key} value must be a string of text object reference`;
|
|
71
83
|
}
|
|
72
84
|
break;
|
|
73
85
|
}
|
|
74
|
-
case
|
|
86
|
+
case IMBRICATE_PROPERTY_TYPE.IMBRISCRIPT: {
|
|
75
87
|
if (typeof value.value !== "string") {
|
|
76
88
|
return `Property ${key} value must be a string of text object reference`;
|
|
77
89
|
}
|
|
78
90
|
break;
|
|
79
91
|
}
|
|
80
|
-
case
|
|
92
|
+
case IMBRICATE_PROPERTY_TYPE.DATE: {
|
|
81
93
|
if (typeof value.value !== "string") {
|
|
82
94
|
return `Property ${key} value must be a string of date in ISO format`;
|
|
83
95
|
}
|
|
84
|
-
const date = new Date(value.value);
|
|
96
|
+
const date: Date = new Date(value.value);
|
|
85
97
|
if (isNaN(date.getTime())) {
|
|
86
98
|
return `Property ${key} value must be a string of date in ISO format`;
|
|
87
99
|
}
|
|
88
100
|
break;
|
|
89
101
|
}
|
|
90
|
-
case
|
|
102
|
+
case IMBRICATE_PROPERTY_TYPE.LABEL: {
|
|
91
103
|
if (!Array.isArray(value.value)) {
|
|
92
104
|
return `Property ${key} value must be an array of string`;
|
|
93
105
|
}
|
|
@@ -98,7 +110,7 @@ const validateImbricateProperties = (properties, schema, allowExtraProperties =
|
|
|
98
110
|
}
|
|
99
111
|
break;
|
|
100
112
|
}
|
|
101
|
-
case
|
|
113
|
+
case IMBRICATE_PROPERTY_TYPE.REFERENCE: {
|
|
102
114
|
if (!Array.isArray(value.value)) {
|
|
103
115
|
return `Property ${key} value must be an array of string`;
|
|
104
116
|
}
|
|
@@ -120,6 +132,6 @@ const validateImbricateProperties = (properties, schema, allowExtraProperties =
|
|
|
120
132
|
}
|
|
121
133
|
}
|
|
122
134
|
}
|
|
135
|
+
|
|
123
136
|
return null;
|
|
124
137
|
};
|
|
125
|
-
exports.validateImbricateProperties = validateImbricateProperties;
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
* @author WMXPY
|
|
3
3
|
* @description Index
|
|
4
4
|
*/
|
|
5
|
+
|
|
5
6
|
export * from "./author/definition";
|
|
6
7
|
export * from "./database/definition";
|
|
7
8
|
export * from "./database/interface";
|
|
8
9
|
export * from "./database/manager";
|
|
9
10
|
export * from "./database/schema";
|
|
11
|
+
export * from "./database/validate";
|
|
10
12
|
export * from "./document/definition";
|
|
11
13
|
export * from "./document/interface";
|
|
12
14
|
export * from "./document/property";
|
|
@@ -28,3 +30,4 @@ export * from "./static/manager";
|
|
|
28
30
|
export * from "./text/definition";
|
|
29
31
|
export * from "./text/interface";
|
|
30
32
|
export * from "./text/manager";
|
|
33
|
+
|
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* @namespace Loader
|
|
4
4
|
* @description Definition
|
|
5
5
|
*/
|
|
6
|
+
|
|
6
7
|
import { OriginPayload } from "../origin/definition";
|
|
7
8
|
import { IImbricateOrigin } from "../origin/interface";
|
|
8
|
-
|
|
9
|
+
|
|
10
|
+
export type ImbricateOriginLoader = (
|
|
11
|
+
payload: OriginPayload,
|
|
12
|
+
) => IImbricateOrigin;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author WMXPY
|
|
3
|
+
* @namespace Loader
|
|
4
|
+
* @description Origin Loader
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { IImbricateOrigin } from "../origin/interface";
|
|
8
|
+
import { IMBRICATE_ORIGIN_LOAD_TYPE, ImbricateOriginPersistence, ImbricateOriginPersistenceOrigin } from "./persistence";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Load imbricate origin from persistence origin
|
|
12
|
+
* This function will load the origin from the persistence origin
|
|
13
|
+
* and initialize the origin with the payloads
|
|
14
|
+
*
|
|
15
|
+
* @param origin origin to persistence to load
|
|
16
|
+
*
|
|
17
|
+
* @returns a promise of the loaded origin
|
|
18
|
+
* if the origin is not found, return null
|
|
19
|
+
*/
|
|
20
|
+
export const loadImbricateOriginFromPersistenceOrigin = async (
|
|
21
|
+
origin: ImbricateOriginPersistenceOrigin,
|
|
22
|
+
): Promise<IImbricateOrigin | null> => {
|
|
23
|
+
|
|
24
|
+
switch (origin.originLoadType) {
|
|
25
|
+
|
|
26
|
+
case IMBRICATE_ORIGIN_LOAD_TYPE.NPM_PACKAGE: {
|
|
27
|
+
|
|
28
|
+
const originPackage = await import(origin.originLoadValue);
|
|
29
|
+
|
|
30
|
+
if (typeof originPackage.default === "function") {
|
|
31
|
+
|
|
32
|
+
const initialized = originPackage.default.call(
|
|
33
|
+
null,
|
|
34
|
+
origin.originPayloads,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
return initialized;
|
|
38
|
+
}
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
case IMBRICATE_ORIGIN_LOAD_TYPE.FILE_SYSTEM: {
|
|
43
|
+
|
|
44
|
+
const originPackage = await import(origin.originLoadValue);
|
|
45
|
+
|
|
46
|
+
if (typeof originPackage.default === "function") {
|
|
47
|
+
|
|
48
|
+
const initialized = originPackage.default.call(
|
|
49
|
+
null,
|
|
50
|
+
origin.originPayloads,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
return initialized;
|
|
54
|
+
}
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return null;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Load imbricate origins from persistence
|
|
64
|
+
* This function will load all origins from the persistence
|
|
65
|
+
* and initialize the origins with the payloads
|
|
66
|
+
* If the origin is not found, it will be ignored
|
|
67
|
+
*
|
|
68
|
+
* @param persistence persistence to load origins
|
|
69
|
+
*
|
|
70
|
+
* @returns a promise of the loaded origins, if the origin is not found, return empty array
|
|
71
|
+
*/
|
|
72
|
+
export const loadImbricateOriginsFromPersistence = async (
|
|
73
|
+
persistence: ImbricateOriginPersistence,
|
|
74
|
+
): Promise<IImbricateOrigin[]> => {
|
|
75
|
+
|
|
76
|
+
const origins: IImbricateOrigin[] = [];
|
|
77
|
+
|
|
78
|
+
for (const origin of persistence.origins) {
|
|
79
|
+
|
|
80
|
+
const originInstance: IImbricateOrigin | null = await loadImbricateOriginFromPersistenceOrigin(origin);
|
|
81
|
+
|
|
82
|
+
if (originInstance) {
|
|
83
|
+
origins.push(originInstance);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return origins;
|
|
88
|
+
};
|
|
@@ -3,23 +3,32 @@
|
|
|
3
3
|
* @namespace Loader
|
|
4
4
|
* @description Persistence
|
|
5
5
|
*/
|
|
6
|
+
|
|
6
7
|
import { OriginPayload } from "../origin/definition";
|
|
8
|
+
|
|
7
9
|
/**
|
|
8
10
|
* Imbricate Origin Load Type
|
|
9
|
-
*
|
|
11
|
+
*
|
|
10
12
|
* NPM_PACKAGE - load origin from npm package, as package name
|
|
11
13
|
* FILE_SYSTEM - load origin from file system, as file path
|
|
12
14
|
*/
|
|
13
|
-
export
|
|
15
|
+
export enum IMBRICATE_ORIGIN_LOAD_TYPE {
|
|
16
|
+
|
|
14
17
|
NPM_PACKAGE = "NPM_PACKAGE",
|
|
15
|
-
FILE_SYSTEM = "FILE_SYSTEM"
|
|
18
|
+
FILE_SYSTEM = "FILE_SYSTEM",
|
|
16
19
|
}
|
|
20
|
+
|
|
17
21
|
export type ImbricateOriginPersistenceOrigin = {
|
|
22
|
+
|
|
18
23
|
readonly originLoadType: IMBRICATE_ORIGIN_LOAD_TYPE;
|
|
19
24
|
readonly originLoadValue: string;
|
|
25
|
+
|
|
20
26
|
readonly originName: string;
|
|
27
|
+
|
|
21
28
|
readonly originPayloads: OriginPayload;
|
|
22
29
|
};
|
|
30
|
+
|
|
23
31
|
export type ImbricateOriginPersistence = {
|
|
32
|
+
|
|
24
33
|
readonly origins: ImbricateOriginPersistenceOrigin[];
|
|
25
34
|
};
|
|
@@ -3,55 +3,66 @@
|
|
|
3
3
|
* @namespace Origin
|
|
4
4
|
* @description Interface
|
|
5
5
|
*/
|
|
6
|
+
|
|
6
7
|
import { IImbricateDatabaseManager } from "../database/manager";
|
|
7
8
|
import { IImbricateStaticManager } from "../static/manager";
|
|
8
9
|
import { IImbricateTextManager } from "../text/manager";
|
|
9
10
|
import { OriginPayload } from "./definition";
|
|
10
11
|
import { ImbricateSearchResult } from "./search";
|
|
12
|
+
|
|
11
13
|
export interface IImbricateOrigin {
|
|
14
|
+
|
|
12
15
|
/**
|
|
13
16
|
* Unique identifier of the origin
|
|
14
17
|
*/
|
|
15
18
|
readonly uniqueIdentifier: string;
|
|
19
|
+
|
|
16
20
|
/**
|
|
17
21
|
* Payloads to initialize the origin
|
|
18
22
|
*/
|
|
19
23
|
readonly payloads: OriginPayload;
|
|
24
|
+
|
|
20
25
|
/**
|
|
21
26
|
* Get the database manager of the origin
|
|
22
|
-
*
|
|
27
|
+
*
|
|
23
28
|
* @returns the database manager
|
|
24
29
|
*/
|
|
25
30
|
getDatabaseManager(): IImbricateDatabaseManager;
|
|
31
|
+
|
|
26
32
|
/**
|
|
27
33
|
* Get the text manager of the origin
|
|
28
34
|
* The text manager is used to manage text objects
|
|
29
|
-
*
|
|
35
|
+
*
|
|
30
36
|
* @returns the text manager
|
|
31
37
|
*/
|
|
32
38
|
getTextManager(): IImbricateTextManager;
|
|
39
|
+
|
|
33
40
|
/**
|
|
34
41
|
* Get the static manager of the origin
|
|
35
42
|
* The static manager is used to manage static objects
|
|
36
|
-
*
|
|
43
|
+
*
|
|
37
44
|
* @returns the static manager
|
|
38
45
|
*/
|
|
39
46
|
getStaticManager(): IImbricateStaticManager;
|
|
47
|
+
|
|
40
48
|
/**
|
|
41
49
|
* Dispose the origin, optional
|
|
42
50
|
* This method will be called when the origin is no longer needed
|
|
43
|
-
*
|
|
51
|
+
*
|
|
44
52
|
* If the origin needs to dispose resources, override this method
|
|
45
53
|
* else, do not implement this method
|
|
46
|
-
*
|
|
54
|
+
*
|
|
47
55
|
* Example: close database connection, or close file system
|
|
48
56
|
*/
|
|
49
57
|
dispose?(): PromiseLike<void>;
|
|
58
|
+
|
|
50
59
|
/**
|
|
51
60
|
* Search for items in the origin
|
|
52
|
-
*
|
|
61
|
+
*
|
|
53
62
|
* @param keyword the keyword to search
|
|
54
63
|
* @returns the search
|
|
55
64
|
*/
|
|
56
|
-
search(
|
|
65
|
+
search(
|
|
66
|
+
keyword: string,
|
|
67
|
+
): PromiseLike<ImbricateSearchResult>;
|
|
57
68
|
}
|
|
@@ -3,34 +3,48 @@
|
|
|
3
3
|
* @namespace Origin
|
|
4
4
|
* @description Search
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
export enum IMBRICATE_SEARCH_TARGET_TYPE {
|
|
8
|
+
|
|
7
9
|
DATABASE = "DATABASE",
|
|
8
10
|
DOCUMENT = "DOCUMENT",
|
|
9
|
-
MARKDOWN = "MARKDOWN"
|
|
11
|
+
MARKDOWN = "MARKDOWN",
|
|
10
12
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
|
|
14
|
+
export type ImbricateSearchTargetSwitch<T extends IMBRICATE_SEARCH_TARGET_TYPE> =
|
|
15
|
+
T extends IMBRICATE_SEARCH_TARGET_TYPE.DATABASE ? {
|
|
16
|
+
databaseUniqueIdentifier: string;
|
|
17
|
+
} :
|
|
18
|
+
T extends IMBRICATE_SEARCH_TARGET_TYPE.DOCUMENT ? {
|
|
19
|
+
databaseUniqueIdentifier: string;
|
|
20
|
+
documentUniqueIdentifier: string;
|
|
21
|
+
} :
|
|
22
|
+
T extends IMBRICATE_SEARCH_TARGET_TYPE.MARKDOWN ? {
|
|
23
|
+
databaseUniqueIdentifier: string;
|
|
24
|
+
documentUniqueIdentifier: string;
|
|
25
|
+
propertyUniqueIdentifier: string;
|
|
26
|
+
lineNumber: number;
|
|
27
|
+
} :
|
|
28
|
+
never;
|
|
29
|
+
|
|
22
30
|
export type ImbricateSearchTarget<T extends IMBRICATE_SEARCH_TARGET_TYPE> = {
|
|
31
|
+
|
|
23
32
|
readonly type: T;
|
|
24
33
|
readonly target: ImbricateSearchTargetSwitch<T>;
|
|
25
34
|
};
|
|
35
|
+
|
|
26
36
|
export type ImbricateSearchItem = {
|
|
37
|
+
|
|
27
38
|
readonly target: ImbricateSearchTarget<IMBRICATE_SEARCH_TARGET_TYPE>;
|
|
39
|
+
|
|
28
40
|
readonly primary: string;
|
|
41
|
+
|
|
29
42
|
/**
|
|
30
43
|
* @description Source are optional, use for source context
|
|
31
44
|
*/
|
|
32
45
|
readonly sourceDatabaseName?: string;
|
|
33
46
|
readonly sourceDocumentPrimaryKey?: string;
|
|
47
|
+
|
|
34
48
|
/**
|
|
35
49
|
* @description Previous are optional, use for previous context on the secondary object
|
|
36
50
|
*/
|
|
@@ -41,6 +55,8 @@ export type ImbricateSearchItem = {
|
|
|
41
55
|
*/
|
|
42
56
|
readonly secondaryNext?: string[];
|
|
43
57
|
};
|
|
58
|
+
|
|
44
59
|
export type ImbricateSearchResult = {
|
|
60
|
+
|
|
45
61
|
readonly items: ImbricateSearchItem[];
|
|
46
62
|
};
|
|
@@ -3,19 +3,24 @@
|
|
|
3
3
|
* @namespace Static
|
|
4
4
|
* @description Interface
|
|
5
5
|
*/
|
|
6
|
+
|
|
6
7
|
import { ImbricateAuthor } from "../author/definition";
|
|
8
|
+
|
|
7
9
|
export interface IImbricateStatic {
|
|
10
|
+
|
|
8
11
|
/**
|
|
9
12
|
* Unique identifier of the static object
|
|
10
13
|
*/
|
|
11
14
|
readonly uniqueIdentifier: string;
|
|
15
|
+
|
|
12
16
|
/**
|
|
13
17
|
* Author of the text object
|
|
14
18
|
*/
|
|
15
19
|
readonly author?: ImbricateAuthor;
|
|
20
|
+
|
|
16
21
|
/**
|
|
17
22
|
* Get the content of the static object
|
|
18
|
-
*
|
|
23
|
+
*
|
|
19
24
|
* @returns a promise of the content of the text, encoded in base64
|
|
20
25
|
*/
|
|
21
26
|
getContentInBase64(): PromiseLike<string>;
|
|
@@ -3,24 +3,31 @@
|
|
|
3
3
|
* @namespace Static
|
|
4
4
|
* @description Manager
|
|
5
5
|
*/
|
|
6
|
+
|
|
6
7
|
import { ImbricateStaticAuditOptions } from "./definition";
|
|
7
8
|
import { IImbricateStatic } from "./interface";
|
|
9
|
+
|
|
8
10
|
export interface IImbricateStaticManager {
|
|
11
|
+
|
|
9
12
|
/**
|
|
10
13
|
* Get the static object from the origin
|
|
11
|
-
*
|
|
14
|
+
*
|
|
12
15
|
* @returns a promise of the static object, null if not found
|
|
13
16
|
*/
|
|
14
17
|
getStatic(uniqueIdentifier: string): PromiseLike<IImbricateStatic | null>;
|
|
18
|
+
|
|
15
19
|
/**
|
|
16
20
|
* Create a new static object in the origin, encoded in base64
|
|
17
21
|
* Static object is immutable, once created, it cannot be changed
|
|
18
22
|
* Patch a new static object if you want to change the content
|
|
19
|
-
*
|
|
23
|
+
*
|
|
20
24
|
* @param content content of the static object, encoded in base64
|
|
21
25
|
* @param auditOptions audit options of the static object
|
|
22
|
-
*
|
|
26
|
+
*
|
|
23
27
|
* @returns a promise of the created static object
|
|
24
28
|
*/
|
|
25
|
-
createInBase64(
|
|
29
|
+
createInBase64(
|
|
30
|
+
content: string,
|
|
31
|
+
auditOptions?: ImbricateStaticAuditOptions,
|
|
32
|
+
): PromiseLike<IImbricateStatic>;
|
|
26
33
|
}
|