@imbricate/core 3.1.2 → 3.2.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/schema.d.ts +23 -7
- package/database/schema.js +22 -0
- package/document/property.d.ts +26 -5
- package/document/property.js +19 -3
- package/document/validate.js +32 -0
- package/loader/origin-loader.js +17 -7
- package/package.json +1 -1
package/database/schema.d.ts
CHANGED
|
@@ -4,18 +4,34 @@
|
|
|
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 ImbricateDatabaseSchemaPropertyOptionsReferenceDatabase = {
|
|
11
|
+
readonly originUniqueIdentifier: string;
|
|
12
|
+
readonly databaseUniqueIdentifier: string;
|
|
13
|
+
};
|
|
14
|
+
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 ? {
|
|
15
|
+
/**
|
|
16
|
+
* Allow multiple references
|
|
17
|
+
*/
|
|
18
|
+
readonly allowMultiple: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Allow references from these databases
|
|
21
|
+
* If empty, allow references from all databases
|
|
22
|
+
*/
|
|
23
|
+
readonly databases: ImbricateDatabaseSchemaPropertyOptionsReferenceDatabase[];
|
|
24
|
+
} : never;
|
|
25
|
+
export type ImbricateDatabaseSchemaPropertyForCreation<T extends IMBRICATE_PROPERTY_TYPE> = {
|
|
11
26
|
readonly propertyName: string;
|
|
12
|
-
readonly propertyType:
|
|
27
|
+
readonly propertyType: T;
|
|
28
|
+
readonly propertyOptions: ImbricateDatabaseSchemaPropertyOptions<T>;
|
|
13
29
|
};
|
|
14
30
|
export type ImbricateDatabaseSchema = {
|
|
15
|
-
readonly properties: ImbricateDatabaseSchemaProperty
|
|
31
|
+
readonly properties: Array<ImbricateDatabaseSchemaProperty<IMBRICATE_PROPERTY_TYPE>>;
|
|
16
32
|
};
|
|
17
33
|
export type ImbricateDatabaseSchemaForCreation = {
|
|
18
|
-
readonly properties: ImbricateDatabaseSchemaPropertyForCreation
|
|
34
|
+
readonly properties: Array<ImbricateDatabaseSchemaPropertyForCreation<IMBRICATE_PROPERTY_TYPE>>;
|
|
19
35
|
};
|
|
20
36
|
/**
|
|
21
37
|
* Validate a schema property
|
|
@@ -25,7 +41,7 @@ export type ImbricateDatabaseSchemaForCreation = {
|
|
|
25
41
|
* @returns a string error message if validation failed
|
|
26
42
|
* null if validation passed
|
|
27
43
|
*/
|
|
28
|
-
export declare const validateImbricateSchemaProperty: (property: ImbricateDatabaseSchemaProperty) => string | null;
|
|
44
|
+
export declare const validateImbricateSchemaProperty: (property: ImbricateDatabaseSchemaProperty<IMBRICATE_PROPERTY_TYPE>) => string | null;
|
|
29
45
|
/**
|
|
30
46
|
* Validate a schema
|
|
31
47
|
*
|
package/database/schema.js
CHANGED
|
@@ -25,6 +25,28 @@ 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
|
+
if (!Array.isArray(property.propertyOptions.databases)) {
|
|
37
|
+
return "Property options databases must be an array";
|
|
38
|
+
}
|
|
39
|
+
for (const database of property.propertyOptions.databases) {
|
|
40
|
+
if (typeof database.originUniqueIdentifier !== "string") {
|
|
41
|
+
return "Database originUniqueIdentifier must be a string";
|
|
42
|
+
}
|
|
43
|
+
if (typeof database.databaseUniqueIdentifier !== "string") {
|
|
44
|
+
return "Database databaseUniqueIdentifier must be a string";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
28
50
|
return null;
|
|
29
51
|
};
|
|
30
52
|
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,12 @@ export type DocumentPropertyValue<T extends IMBRICATE_PROPERTY_TYPE> = {
|
|
|
28
44
|
readonly type: T;
|
|
29
45
|
readonly value: DocumentPropertyValueObject<T>;
|
|
30
46
|
};
|
|
31
|
-
export type
|
|
47
|
+
export type DocumentPropertyValueObjectReference = {
|
|
48
|
+
readonly originUniqueIdentifier: string;
|
|
49
|
+
readonly databaseUniqueIdentifier: string;
|
|
50
|
+
readonly documentUniqueIdentifier: string;
|
|
51
|
+
};
|
|
52
|
+
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 ? DocumentPropertyValueObjectReference[] : never;
|
|
32
53
|
/**
|
|
33
54
|
* Edit record type of the document
|
|
34
55
|
*/
|
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,50 @@ 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 !== "object") {
|
|
69
|
+
return `Property ${key} reference must be an object`;
|
|
70
|
+
}
|
|
71
|
+
if (typeof reference.originUniqueIdentifier !== "string") {
|
|
72
|
+
return `Property ${key} reference originUniqueIdentifier must be a string`;
|
|
73
|
+
}
|
|
74
|
+
if (typeof reference.databaseUniqueIdentifier !== "string") {
|
|
75
|
+
return `Property ${key} reference databaseUniqueIdentifier must be a string`;
|
|
76
|
+
}
|
|
77
|
+
if (typeof reference.documentUniqueIdentifier !== "string") {
|
|
78
|
+
return `Property ${key} reference documentUniqueIdentifier must be a string`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
51
83
|
}
|
|
52
84
|
}
|
|
53
85
|
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) {
|