@imbricate/core 3.1.2 → 3.2.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/schema.d.ts +19 -7
- package/database/schema.js +11 -0
- package/document/property.d.ts +21 -5
- package/document/property.js +19 -3
- package/document/validate.js +23 -0
- package/loader/origin-loader.js +17 -7
- package/package.json +1 -1
package/database/schema.d.ts
CHANGED
|
@@ -4,18 +4,30 @@
|
|
|
4
4
|
* @description Schema
|
|
5
5
|
*/
|
|
6
6
|
import { IMBRICATE_PROPERTY_TYPE } from "../document/property";
|
|
7
|
-
export type ImbricateDatabaseSchemaProperty = {
|
|
7
|
+
export type ImbricateDatabaseSchemaProperty<T extends IMBRICATE_PROPERTY_TYPE> = {
|
|
8
8
|
readonly propertyIdentifier: string;
|
|
9
|
-
} & ImbricateDatabaseSchemaPropertyForCreation
|
|
10
|
-
export type
|
|
9
|
+
} & ImbricateDatabaseSchemaPropertyForCreation<T>;
|
|
10
|
+
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.REFERENCE ? {
|
|
11
|
+
/**
|
|
12
|
+
* Allow multiple references
|
|
13
|
+
*/
|
|
14
|
+
readonly allowMultiple: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Allow references from these databases
|
|
17
|
+
* If empty, allow references from all databases
|
|
18
|
+
*/
|
|
19
|
+
readonly databases: string[];
|
|
20
|
+
} : never;
|
|
21
|
+
export type ImbricateDatabaseSchemaPropertyForCreation<T extends IMBRICATE_PROPERTY_TYPE> = {
|
|
11
22
|
readonly propertyName: string;
|
|
12
|
-
readonly propertyType:
|
|
23
|
+
readonly propertyType: T;
|
|
24
|
+
readonly propertyOptions: ImbricateDatabaseSchemaPropertyOptions<T>;
|
|
13
25
|
};
|
|
14
26
|
export type ImbricateDatabaseSchema = {
|
|
15
|
-
readonly properties: ImbricateDatabaseSchemaProperty
|
|
27
|
+
readonly properties: Array<ImbricateDatabaseSchemaProperty<IMBRICATE_PROPERTY_TYPE>>;
|
|
16
28
|
};
|
|
17
29
|
export type ImbricateDatabaseSchemaForCreation = {
|
|
18
|
-
readonly properties: ImbricateDatabaseSchemaPropertyForCreation
|
|
30
|
+
readonly properties: Array<ImbricateDatabaseSchemaPropertyForCreation<IMBRICATE_PROPERTY_TYPE>>;
|
|
19
31
|
};
|
|
20
32
|
/**
|
|
21
33
|
* Validate a schema property
|
|
@@ -25,7 +37,7 @@ export type ImbricateDatabaseSchemaForCreation = {
|
|
|
25
37
|
* @returns a string error message if validation failed
|
|
26
38
|
* null if validation passed
|
|
27
39
|
*/
|
|
28
|
-
export declare const validateImbricateSchemaProperty: (property: ImbricateDatabaseSchemaProperty) => string | null;
|
|
40
|
+
export declare const validateImbricateSchemaProperty: (property: ImbricateDatabaseSchemaProperty<IMBRICATE_PROPERTY_TYPE>) => string | null;
|
|
29
41
|
/**
|
|
30
42
|
* Validate a schema
|
|
31
43
|
*
|
package/database/schema.js
CHANGED
|
@@ -25,6 +25,17 @@ const validateImbricateSchemaProperty = (property) => {
|
|
|
25
25
|
if (!Object.values(property_1.IMBRICATE_PROPERTY_TYPE).includes(property.propertyType)) {
|
|
26
26
|
return "Property type must be a valid type";
|
|
27
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
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
28
39
|
return null;
|
|
29
40
|
};
|
|
30
41
|
exports.validateImbricateSchemaProperty = validateImbricateSchemaProperty;
|
package/document/property.d.ts
CHANGED
|
@@ -5,13 +5,29 @@
|
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
7
|
* Document properties
|
|
8
|
-
*
|
|
9
|
-
* STRING - string, store as plain text
|
|
10
|
-
* MARKDOWN - markdown, store as text object unique identifier. Display as markdown
|
|
11
8
|
*/
|
|
12
9
|
export declare enum IMBRICATE_PROPERTY_TYPE {
|
|
10
|
+
/**
|
|
11
|
+
* BOOLEAN - boolean, store as boolean
|
|
12
|
+
*/
|
|
13
|
+
BOOLEAN = "BOOLEAN",
|
|
14
|
+
/**
|
|
15
|
+
* STRING - string, store as plain text
|
|
16
|
+
*/
|
|
13
17
|
STRING = "STRING",
|
|
14
|
-
|
|
18
|
+
/**
|
|
19
|
+
* NUMBER - number, store as number
|
|
20
|
+
*/
|
|
21
|
+
NUMBER = "NUMBER",
|
|
22
|
+
/**
|
|
23
|
+
* MARKDOWN - markdown, store as text object unique identifier. Display as markdown
|
|
24
|
+
*/
|
|
25
|
+
MARKDOWN = "MARKDOWN",
|
|
26
|
+
/**
|
|
27
|
+
* REFERENCE - reference, store as a list of other document unique identifier
|
|
28
|
+
* Note: Reference is always stored as an array, even if it is a single reference
|
|
29
|
+
*/
|
|
30
|
+
REFERENCE = "REFERENCE"
|
|
15
31
|
}
|
|
16
32
|
/**
|
|
17
33
|
* Document properties
|
|
@@ -28,7 +44,7 @@ export type DocumentPropertyValue<T extends IMBRICATE_PROPERTY_TYPE> = {
|
|
|
28
44
|
readonly type: T;
|
|
29
45
|
readonly value: DocumentPropertyValueObject<T>;
|
|
30
46
|
};
|
|
31
|
-
export type DocumentPropertyValueObject<T extends IMBRICATE_PROPERTY_TYPE> = T extends IMBRICATE_PROPERTY_TYPE.STRING ? string : T extends IMBRICATE_PROPERTY_TYPE.MARKDOWN ? string : never;
|
|
47
|
+
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.REFERENCE ? string[] : never;
|
|
32
48
|
/**
|
|
33
49
|
* Edit record type of the document
|
|
34
50
|
*/
|
package/document/property.js
CHANGED
|
@@ -8,14 +8,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
8
8
|
exports.IMBRICATE_DOCUMENT_EDIT_TYPE = exports.IMBRICATE_PROPERTY_TYPE = void 0;
|
|
9
9
|
/**
|
|
10
10
|
* Document properties
|
|
11
|
-
*
|
|
12
|
-
* STRING - string, store as plain text
|
|
13
|
-
* MARKDOWN - markdown, store as text object unique identifier. Display as markdown
|
|
14
11
|
*/
|
|
15
12
|
var IMBRICATE_PROPERTY_TYPE;
|
|
16
13
|
(function (IMBRICATE_PROPERTY_TYPE) {
|
|
14
|
+
/**
|
|
15
|
+
* BOOLEAN - boolean, store as boolean
|
|
16
|
+
*/
|
|
17
|
+
IMBRICATE_PROPERTY_TYPE["BOOLEAN"] = "BOOLEAN";
|
|
18
|
+
/**
|
|
19
|
+
* STRING - string, store as plain text
|
|
20
|
+
*/
|
|
17
21
|
IMBRICATE_PROPERTY_TYPE["STRING"] = "STRING";
|
|
22
|
+
/**
|
|
23
|
+
* NUMBER - number, store as number
|
|
24
|
+
*/
|
|
25
|
+
IMBRICATE_PROPERTY_TYPE["NUMBER"] = "NUMBER";
|
|
26
|
+
/**
|
|
27
|
+
* MARKDOWN - markdown, store as text object unique identifier. Display as markdown
|
|
28
|
+
*/
|
|
18
29
|
IMBRICATE_PROPERTY_TYPE["MARKDOWN"] = "MARKDOWN";
|
|
30
|
+
/**
|
|
31
|
+
* REFERENCE - reference, store as a list of other document unique identifier
|
|
32
|
+
* Note: Reference is always stored as an array, even if it is a single reference
|
|
33
|
+
*/
|
|
34
|
+
IMBRICATE_PROPERTY_TYPE["REFERENCE"] = "REFERENCE";
|
|
19
35
|
})(IMBRICATE_PROPERTY_TYPE || (exports.IMBRICATE_PROPERTY_TYPE = IMBRICATE_PROPERTY_TYPE = {}));
|
|
20
36
|
/**
|
|
21
37
|
* Edit record type of the document
|
package/document/validate.js
CHANGED
|
@@ -36,18 +36,41 @@ const validateImbricateProperties = (properties, schema) => {
|
|
|
36
36
|
return `Property ${key} type must be ${property.propertyType}, but got ${value.type}`;
|
|
37
37
|
}
|
|
38
38
|
switch (value.type) {
|
|
39
|
+
case property_1.IMBRICATE_PROPERTY_TYPE.BOOLEAN: {
|
|
40
|
+
if (typeof value.value !== "boolean") {
|
|
41
|
+
return `Property ${key} value must be a boolean`;
|
|
42
|
+
}
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
39
45
|
case property_1.IMBRICATE_PROPERTY_TYPE.STRING: {
|
|
40
46
|
if (typeof value.value !== "string") {
|
|
41
47
|
return `Property ${key} value must be a string`;
|
|
42
48
|
}
|
|
43
49
|
break;
|
|
44
50
|
}
|
|
51
|
+
case property_1.IMBRICATE_PROPERTY_TYPE.NUMBER: {
|
|
52
|
+
if (typeof value.value !== "number") {
|
|
53
|
+
return `Property ${key} value must be a number`;
|
|
54
|
+
}
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
45
57
|
case property_1.IMBRICATE_PROPERTY_TYPE.MARKDOWN: {
|
|
46
58
|
if (typeof value.value !== "string") {
|
|
47
59
|
return `Property ${key} value must be a string of text object reference`;
|
|
48
60
|
}
|
|
49
61
|
break;
|
|
50
62
|
}
|
|
63
|
+
case property_1.IMBRICATE_PROPERTY_TYPE.REFERENCE: {
|
|
64
|
+
if (!Array.isArray(value.value)) {
|
|
65
|
+
return `Property ${key} value must be an array of string`;
|
|
66
|
+
}
|
|
67
|
+
for (const reference of value.value) {
|
|
68
|
+
if (typeof reference !== "string") {
|
|
69
|
+
return `Property ${key} value must be an array of string, but got ${typeof reference}`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
51
74
|
}
|
|
52
75
|
}
|
|
53
76
|
return null;
|
package/loader/origin-loader.js
CHANGED
|
@@ -20,13 +20,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
20
20
|
}) : function(o, v) {
|
|
21
21
|
o["default"] = v;
|
|
22
22
|
});
|
|
23
|
-
var __importStar = (this && this.__importStar) || function (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
30
40
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
31
41
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
32
42
|
return new (P || (P = Promise))(function (resolve, reject) {
|