@imbricate/core 3.0.0 → 3.0.1
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/interface.d.ts +1 -1
- package/database/manager.d.ts +12 -4
- package/database/schema.d.ts +24 -1
- package/database/schema.js +49 -0
- package/document/definition.d.ts +1 -13
- package/document/definition.js +0 -10
- package/document/interface.d.ts +2 -1
- package/document/property.d.ts +18 -0
- package/document/property.js +17 -0
- package/document/validate.d.ts +17 -0
- package/document/validate.js +55 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/loader/origin-loader.d.ts +2 -1
- package/loader/origin-loader.js +26 -18
- package/package.json +1 -1
package/database/interface.d.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* @namespace Database
|
|
4
4
|
* @description Interface
|
|
5
5
|
*/
|
|
6
|
-
import { DocumentProperties } from "../document/definition";
|
|
7
6
|
import { IImbricateDocument } from "../document/interface";
|
|
7
|
+
import { DocumentProperties } from "../document/property";
|
|
8
8
|
import { ImbricateDocumentQuery } from "./definition";
|
|
9
9
|
import { ImbricateDatabaseSchema } from "./schema";
|
|
10
10
|
export interface IImbricateDatabase {
|
package/database/manager.d.ts
CHANGED
|
@@ -4,14 +4,22 @@
|
|
|
4
4
|
* @description Manager
|
|
5
5
|
*/
|
|
6
6
|
import { IImbricateDatabase } from "./interface";
|
|
7
|
-
import {
|
|
7
|
+
import { ImbricateDatabaseSchemaForCreation } from "./schema";
|
|
8
8
|
export interface IImbricateDatabaseManager {
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* List all databases in the origin
|
|
11
11
|
*
|
|
12
12
|
* @returns a promise of the databases in the origin
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
listDatabases(): PromiseLike<IImbricateDatabase[]>;
|
|
15
|
+
/**
|
|
16
|
+
* Get one database from the origin
|
|
17
|
+
*
|
|
18
|
+
* @param uniqueIdentifier unique identifier of the database
|
|
19
|
+
*
|
|
20
|
+
* @returns a promise of the database, null if not found
|
|
21
|
+
*/
|
|
22
|
+
getDatabase(uniqueIdentifier: string): PromiseLike<IImbricateDatabase | null>;
|
|
15
23
|
/**
|
|
16
24
|
* Create a new database
|
|
17
25
|
*
|
|
@@ -22,5 +30,5 @@ export interface IImbricateDatabaseManager {
|
|
|
22
30
|
*
|
|
23
31
|
* @returns a promise of the created database
|
|
24
32
|
*/
|
|
25
|
-
createDatabase(databaseName: string, schema:
|
|
33
|
+
createDatabase(databaseName: string, schema: ImbricateDatabaseSchemaForCreation, uniqueIdentifier?: string): PromiseLike<IImbricateDatabase>;
|
|
26
34
|
}
|
package/database/schema.d.ts
CHANGED
|
@@ -3,12 +3,35 @@
|
|
|
3
3
|
* @namespace Database
|
|
4
4
|
* @description Schema
|
|
5
5
|
*/
|
|
6
|
-
import { IMBRICATE_PROPERTY_TYPE } from "../document/
|
|
6
|
+
import { IMBRICATE_PROPERTY_TYPE } from "../document/property";
|
|
7
7
|
export type ImbricateDatabaseSchemaProperty = {
|
|
8
8
|
readonly propertyIdentifier: string;
|
|
9
|
+
} & ImbricateDatabaseSchemaPropertyForCreation;
|
|
10
|
+
export type ImbricateDatabaseSchemaPropertyForCreation = {
|
|
9
11
|
readonly propertyName: string;
|
|
10
12
|
readonly propertyType: IMBRICATE_PROPERTY_TYPE;
|
|
11
13
|
};
|
|
12
14
|
export type ImbricateDatabaseSchema = {
|
|
13
15
|
readonly properties: ImbricateDatabaseSchemaProperty[];
|
|
14
16
|
};
|
|
17
|
+
export type ImbricateDatabaseSchemaForCreation = {
|
|
18
|
+
readonly properties: ImbricateDatabaseSchemaPropertyForCreation[];
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Validate a schema property
|
|
22
|
+
*
|
|
23
|
+
* @param property property to validate
|
|
24
|
+
*
|
|
25
|
+
* @returns a string error message if validation failed
|
|
26
|
+
* null if validation passed
|
|
27
|
+
*/
|
|
28
|
+
export declare const validateImbricateSchemaProperty: (property: ImbricateDatabaseSchemaProperty) => string | null;
|
|
29
|
+
/**
|
|
30
|
+
* Validate a schema
|
|
31
|
+
*
|
|
32
|
+
* @param schema database schema to validate
|
|
33
|
+
*
|
|
34
|
+
* @returns a string error message if validation failed
|
|
35
|
+
* null if validation passed
|
|
36
|
+
*/
|
|
37
|
+
export declare const validateImbricateSchema: (schema: ImbricateDatabaseSchema) => string | null;
|
package/database/schema.js
CHANGED
|
@@ -5,3 +5,52 @@
|
|
|
5
5
|
* @description Schema
|
|
6
6
|
*/
|
|
7
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
|
+
return null;
|
|
29
|
+
};
|
|
30
|
+
exports.validateImbricateSchemaProperty = validateImbricateSchemaProperty;
|
|
31
|
+
/**
|
|
32
|
+
* Validate a schema
|
|
33
|
+
*
|
|
34
|
+
* @param schema database schema to validate
|
|
35
|
+
*
|
|
36
|
+
* @returns a string error message if validation failed
|
|
37
|
+
* null if validation passed
|
|
38
|
+
*/
|
|
39
|
+
const validateImbricateSchema = (schema) => {
|
|
40
|
+
if (!Array.isArray(schema.properties)) {
|
|
41
|
+
return "Properties must be an array";
|
|
42
|
+
}
|
|
43
|
+
const propertyNames = new Set();
|
|
44
|
+
for (const property of schema.properties) {
|
|
45
|
+
const propertyValidationResult = (0, exports.validateImbricateSchemaProperty)(property);
|
|
46
|
+
if (typeof propertyValidationResult === "string") {
|
|
47
|
+
return `Invalid property ${property.propertyName}, ${propertyValidationResult}`;
|
|
48
|
+
}
|
|
49
|
+
if (propertyNames.has(property.propertyName)) {
|
|
50
|
+
return `Duplicated property name ${property.propertyName}`;
|
|
51
|
+
}
|
|
52
|
+
propertyNames.add(property.propertyName);
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
};
|
|
56
|
+
exports.validateImbricateSchema = validateImbricateSchema;
|
package/document/definition.d.ts
CHANGED
|
@@ -4,19 +4,7 @@
|
|
|
4
4
|
* @description Definition
|
|
5
5
|
*/
|
|
6
6
|
import { ImbricateAuthor } from "../author/definition";
|
|
7
|
-
|
|
8
|
-
STRING = "STRING",
|
|
9
|
-
MARKDOWN = "MARKDOWN"
|
|
10
|
-
}
|
|
11
|
-
export type DocumentProperties = Record<DocumentPropertyKey, DocumentPropertyValue>;
|
|
12
|
-
export type DocumentPropertyKey = string;
|
|
13
|
-
export type DocumentPropertyValue = {
|
|
14
|
-
readonly type: IMBRICATE_PROPERTY_TYPE;
|
|
15
|
-
readonly value: any;
|
|
16
|
-
};
|
|
17
|
-
export declare enum IMBRICATE_DOCUMENT_EDIT_TYPE {
|
|
18
|
-
PUT = "PUT"
|
|
19
|
-
}
|
|
7
|
+
import { DocumentPropertyKey, DocumentPropertyValue, IMBRICATE_DOCUMENT_EDIT_TYPE } from "./property";
|
|
20
8
|
export type DocumentEditOperation = {
|
|
21
9
|
readonly key: DocumentPropertyKey;
|
|
22
10
|
readonly action: IMBRICATE_DOCUMENT_EDIT_TYPE;
|
package/document/definition.js
CHANGED
|
@@ -5,13 +5,3 @@
|
|
|
5
5
|
* @description Definition
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.IMBRICATE_DOCUMENT_EDIT_TYPE = exports.IMBRICATE_PROPERTY_TYPE = void 0;
|
|
9
|
-
var IMBRICATE_PROPERTY_TYPE;
|
|
10
|
-
(function (IMBRICATE_PROPERTY_TYPE) {
|
|
11
|
-
IMBRICATE_PROPERTY_TYPE["STRING"] = "STRING";
|
|
12
|
-
IMBRICATE_PROPERTY_TYPE["MARKDOWN"] = "MARKDOWN";
|
|
13
|
-
})(IMBRICATE_PROPERTY_TYPE || (exports.IMBRICATE_PROPERTY_TYPE = IMBRICATE_PROPERTY_TYPE = {}));
|
|
14
|
-
var IMBRICATE_DOCUMENT_EDIT_TYPE;
|
|
15
|
-
(function (IMBRICATE_DOCUMENT_EDIT_TYPE) {
|
|
16
|
-
IMBRICATE_DOCUMENT_EDIT_TYPE["PUT"] = "PUT";
|
|
17
|
-
})(IMBRICATE_DOCUMENT_EDIT_TYPE || (exports.IMBRICATE_DOCUMENT_EDIT_TYPE = IMBRICATE_DOCUMENT_EDIT_TYPE = {}));
|
package/document/interface.d.ts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* @namespace Document
|
|
4
4
|
* @description Interface
|
|
5
5
|
*/
|
|
6
|
-
import { DocumentEditRecord
|
|
6
|
+
import { DocumentEditRecord } from "./definition";
|
|
7
|
+
import { DocumentProperties, DocumentPropertyKey, DocumentPropertyValue } from "./property";
|
|
7
8
|
export interface IImbricateDocument {
|
|
8
9
|
/**
|
|
9
10
|
* Unique identifier of the database
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author WMXPY
|
|
3
|
+
* @namespace Document
|
|
4
|
+
* @description Property
|
|
5
|
+
*/
|
|
6
|
+
export declare enum IMBRICATE_PROPERTY_TYPE {
|
|
7
|
+
STRING = "STRING",
|
|
8
|
+
MARKDOWN = "MARKDOWN"
|
|
9
|
+
}
|
|
10
|
+
export type DocumentProperties = Record<DocumentPropertyKey, DocumentPropertyValue>;
|
|
11
|
+
export type DocumentPropertyKey = string;
|
|
12
|
+
export type DocumentPropertyValue = {
|
|
13
|
+
readonly type: IMBRICATE_PROPERTY_TYPE;
|
|
14
|
+
readonly value: any;
|
|
15
|
+
};
|
|
16
|
+
export declare enum IMBRICATE_DOCUMENT_EDIT_TYPE {
|
|
17
|
+
PUT = "PUT"
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @author WMXPY
|
|
4
|
+
* @namespace Document
|
|
5
|
+
* @description Property
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.IMBRICATE_DOCUMENT_EDIT_TYPE = exports.IMBRICATE_PROPERTY_TYPE = void 0;
|
|
9
|
+
var IMBRICATE_PROPERTY_TYPE;
|
|
10
|
+
(function (IMBRICATE_PROPERTY_TYPE) {
|
|
11
|
+
IMBRICATE_PROPERTY_TYPE["STRING"] = "STRING";
|
|
12
|
+
IMBRICATE_PROPERTY_TYPE["MARKDOWN"] = "MARKDOWN";
|
|
13
|
+
})(IMBRICATE_PROPERTY_TYPE || (exports.IMBRICATE_PROPERTY_TYPE = IMBRICATE_PROPERTY_TYPE = {}));
|
|
14
|
+
var IMBRICATE_DOCUMENT_EDIT_TYPE;
|
|
15
|
+
(function (IMBRICATE_DOCUMENT_EDIT_TYPE) {
|
|
16
|
+
IMBRICATE_DOCUMENT_EDIT_TYPE["PUT"] = "PUT";
|
|
17
|
+
})(IMBRICATE_DOCUMENT_EDIT_TYPE || (exports.IMBRICATE_DOCUMENT_EDIT_TYPE = IMBRICATE_DOCUMENT_EDIT_TYPE = {}));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author WMXPY
|
|
3
|
+
* @namespace Document
|
|
4
|
+
* @description Validate
|
|
5
|
+
*/
|
|
6
|
+
import { ImbricateDatabaseSchema } from "../database/schema";
|
|
7
|
+
import { DocumentProperties } from "./property";
|
|
8
|
+
/**
|
|
9
|
+
* Validate properties with schema
|
|
10
|
+
*
|
|
11
|
+
* @param properties properties to validate
|
|
12
|
+
* @param schema database schema to validate
|
|
13
|
+
*
|
|
14
|
+
* @returns a string error message if validation failed
|
|
15
|
+
* null if validation passed
|
|
16
|
+
*/
|
|
17
|
+
export declare const validateImbricateProperties: (properties: DocumentProperties, schema: ImbricateDatabaseSchema) => string | null;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @author WMXPY
|
|
4
|
+
* @namespace Document
|
|
5
|
+
* @description Validate
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.validateImbricateProperties = void 0;
|
|
9
|
+
const property_1 = require("./property");
|
|
10
|
+
/**
|
|
11
|
+
* Validate properties with schema
|
|
12
|
+
*
|
|
13
|
+
* @param properties properties to validate
|
|
14
|
+
* @param schema database schema to validate
|
|
15
|
+
*
|
|
16
|
+
* @returns a string error message if validation failed
|
|
17
|
+
* null if validation passed
|
|
18
|
+
*/
|
|
19
|
+
const validateImbricateProperties = (properties, schema) => {
|
|
20
|
+
if (typeof properties !== "object") {
|
|
21
|
+
return "Properties must be an object";
|
|
22
|
+
}
|
|
23
|
+
const keys = Object.keys(properties);
|
|
24
|
+
for (const key of keys) {
|
|
25
|
+
const property = schema.properties.find((each) => {
|
|
26
|
+
return each.propertyName === key;
|
|
27
|
+
});
|
|
28
|
+
if (!property) {
|
|
29
|
+
return `Property ${key} not found in schema`;
|
|
30
|
+
}
|
|
31
|
+
const value = properties[key];
|
|
32
|
+
if (typeof value.type !== "string") {
|
|
33
|
+
return `Property ${key} type must be a string`;
|
|
34
|
+
}
|
|
35
|
+
if (value.type !== property.propertyType) {
|
|
36
|
+
return `Property ${key} type must be ${property.propertyType}, but got ${value.type}`;
|
|
37
|
+
}
|
|
38
|
+
switch (value.type) {
|
|
39
|
+
case property_1.IMBRICATE_PROPERTY_TYPE.STRING: {
|
|
40
|
+
if (typeof value.value !== "string") {
|
|
41
|
+
return `Property ${key} value must be a string`;
|
|
42
|
+
}
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
case property_1.IMBRICATE_PROPERTY_TYPE.MARKDOWN: {
|
|
46
|
+
if (typeof value.value !== "string") {
|
|
47
|
+
return `Property ${key} value must be a string of text object reference`;
|
|
48
|
+
}
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
};
|
|
55
|
+
exports.validateImbricateProperties = validateImbricateProperties;
|
package/index.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export * from "./database/manager";
|
|
|
9
9
|
export * from "./database/schema";
|
|
10
10
|
export * from "./document/definition";
|
|
11
11
|
export * from "./document/interface";
|
|
12
|
+
export * from "./document/property";
|
|
13
|
+
export * from "./document/validate";
|
|
12
14
|
export * from "./loader/definition";
|
|
13
15
|
export * from "./loader/origin-loader";
|
|
14
16
|
export * from "./loader/persistance";
|
package/index.js
CHANGED
|
@@ -25,6 +25,8 @@ __exportStar(require("./database/manager"), exports);
|
|
|
25
25
|
__exportStar(require("./database/schema"), exports);
|
|
26
26
|
__exportStar(require("./document/definition"), exports);
|
|
27
27
|
__exportStar(require("./document/interface"), exports);
|
|
28
|
+
__exportStar(require("./document/property"), exports);
|
|
29
|
+
__exportStar(require("./document/validate"), exports);
|
|
28
30
|
__exportStar(require("./loader/definition"), exports);
|
|
29
31
|
__exportStar(require("./loader/origin-loader"), exports);
|
|
30
32
|
__exportStar(require("./loader/persistance"), exports);
|
|
@@ -4,5 +4,6 @@
|
|
|
4
4
|
* @description Origin Loader
|
|
5
5
|
*/
|
|
6
6
|
import { IImbricateOrigin } from "../origin/interface";
|
|
7
|
-
import { ImbricateOriginPersistance } from "./persistance";
|
|
7
|
+
import { ImbricateOriginPersistance, ImbricateOriginPersistanceOrigin } from "./persistance";
|
|
8
|
+
export declare const loadImbricateOriginFromPersistanceOrigin: (origin: ImbricateOriginPersistanceOrigin) => Promise<IImbricateOrigin | null>;
|
|
8
9
|
export declare const loadImbricateOriginsFromPersistance: (persistance: ImbricateOriginPersistance) => Promise<IImbricateOrigin[]>;
|
package/loader/origin-loader.js
CHANGED
|
@@ -37,28 +37,36 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
37
37
|
});
|
|
38
38
|
};
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
exports.loadImbricateOriginsFromPersistance = void 0;
|
|
40
|
+
exports.loadImbricateOriginsFromPersistance = exports.loadImbricateOriginFromPersistanceOrigin = void 0;
|
|
41
41
|
const persistance_1 = require("./persistance");
|
|
42
|
+
const loadImbricateOriginFromPersistanceOrigin = (origin) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
switch (origin.originLoadType) {
|
|
44
|
+
case persistance_1.IMBRICATE_ORIGIN_LOAD_TYPE.NPM_PACKAGE: {
|
|
45
|
+
const originPackage = yield Promise.resolve(`${origin.originLoadValue}`).then(s => __importStar(require(s)));
|
|
46
|
+
if (typeof originPackage.default === "function") {
|
|
47
|
+
const initialized = originPackage.default.call(null, origin.originPayloads);
|
|
48
|
+
return initialized;
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case persistance_1.IMBRICATE_ORIGIN_LOAD_TYPE.FILE_SYSTEM: {
|
|
53
|
+
const originPackage = yield Promise.resolve(`${origin.originLoadValue}`).then(s => __importStar(require(s)));
|
|
54
|
+
if (typeof originPackage.default === "function") {
|
|
55
|
+
const initialized = originPackage.default.call(null, origin.originPayloads);
|
|
56
|
+
return initialized;
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
});
|
|
63
|
+
exports.loadImbricateOriginFromPersistanceOrigin = loadImbricateOriginFromPersistanceOrigin;
|
|
42
64
|
const loadImbricateOriginsFromPersistance = (persistance) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
65
|
const origins = [];
|
|
44
66
|
for (const origin of persistance.origins) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (typeof originPackage.default === "function") {
|
|
49
|
-
const initialized = originPackage.default.call(null, origin.originPayloads);
|
|
50
|
-
origins.push(initialized);
|
|
51
|
-
}
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
case persistance_1.IMBRICATE_ORIGIN_LOAD_TYPE.FILE_SYSTEM: {
|
|
55
|
-
const originPackage = yield Promise.resolve(`${origin.originLoadValue}`).then(s => __importStar(require(s)));
|
|
56
|
-
if (typeof originPackage.default === "function") {
|
|
57
|
-
const initialized = originPackage.default.call(null, origin.originPayloads);
|
|
58
|
-
origins.push(initialized);
|
|
59
|
-
}
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
67
|
+
const originInstance = yield (0, exports.loadImbricateOriginFromPersistanceOrigin)(origin);
|
|
68
|
+
if (originInstance) {
|
|
69
|
+
origins.push(originInstance);
|
|
62
70
|
}
|
|
63
71
|
}
|
|
64
72
|
return origins;
|