@imbricate/core 3.3.1 → 3.3.4
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
CHANGED
|
@@ -38,6 +38,7 @@ export type ImbricateDatabaseSchemaPropertyForCreation<T extends IMBRICATE_PROPE
|
|
|
38
38
|
readonly propertyName: string;
|
|
39
39
|
readonly propertyType: T;
|
|
40
40
|
readonly propertyOptions: ImbricateDatabaseSchemaPropertyOptions<T>;
|
|
41
|
+
readonly isPrimaryKey?: boolean;
|
|
41
42
|
};
|
|
42
43
|
export type ImbricateDatabaseSchema = {
|
|
43
44
|
readonly properties: Array<ImbricateDatabaseSchemaProperty<IMBRICATE_PROPERTY_TYPE>>;
|
|
@@ -18,7 +18,12 @@ export declare class ImbricateDocumentPropertyTriageBase<Result> {
|
|
|
18
18
|
* @returns triage manager
|
|
19
19
|
*/
|
|
20
20
|
forPropertyKey<T extends IMBRICATE_PROPERTY_TYPE>(propertyKey: DocumentPropertyKey, triageFunction: DocumentPropertyTriageFunction<T, Result>): this;
|
|
21
|
+
forBoolean(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.BOOLEAN, Result>): this;
|
|
21
22
|
forString(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.STRING, Result>): this;
|
|
23
|
+
forNumber(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.NUMBER, Result>): this;
|
|
22
24
|
forMarkdown(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.MARKDOWN, Result>): this;
|
|
25
|
+
forDate(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.DATE, Result>): this;
|
|
26
|
+
forLabel(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.LABEL, Result>): this;
|
|
27
|
+
forReference(triageFunction: DocumentPropertyTriageFunction<IMBRICATE_PROPERTY_TYPE.REFERENCE, Result>): this;
|
|
23
28
|
protected _collect(properties: DocumentProperties): Map<DocumentPropertyKey, Result>;
|
|
24
29
|
}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.ImbricateDocumentPropertyTriageBase = void 0;
|
|
9
9
|
const property_1 = require("../property");
|
|
10
|
+
// IMBRICATE_PROPERTY_TYPE SWITCH
|
|
10
11
|
class ImbricateDocumentPropertyTriageBase {
|
|
11
12
|
constructor() {
|
|
12
13
|
this._triageFunctionsByKey = new Map();
|
|
@@ -24,14 +25,34 @@ class ImbricateDocumentPropertyTriageBase {
|
|
|
24
25
|
this._triageFunctionsByKey.set(propertyKey, triageFunction);
|
|
25
26
|
return this;
|
|
26
27
|
}
|
|
28
|
+
forBoolean(triageFunction) {
|
|
29
|
+
this._triageFunctionsByType.set(property_1.IMBRICATE_PROPERTY_TYPE.BOOLEAN, triageFunction);
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
27
32
|
forString(triageFunction) {
|
|
28
33
|
this._triageFunctionsByType.set(property_1.IMBRICATE_PROPERTY_TYPE.STRING, triageFunction);
|
|
29
34
|
return this;
|
|
30
35
|
}
|
|
36
|
+
forNumber(triageFunction) {
|
|
37
|
+
this._triageFunctionsByType.set(property_1.IMBRICATE_PROPERTY_TYPE.NUMBER, triageFunction);
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
31
40
|
forMarkdown(triageFunction) {
|
|
32
41
|
this._triageFunctionsByType.set(property_1.IMBRICATE_PROPERTY_TYPE.MARKDOWN, triageFunction);
|
|
33
42
|
return this;
|
|
34
43
|
}
|
|
44
|
+
forDate(triageFunction) {
|
|
45
|
+
this._triageFunctionsByType.set(property_1.IMBRICATE_PROPERTY_TYPE.DATE, triageFunction);
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
forLabel(triageFunction) {
|
|
49
|
+
this._triageFunctionsByType.set(property_1.IMBRICATE_PROPERTY_TYPE.LABEL, triageFunction);
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
forReference(triageFunction) {
|
|
53
|
+
this._triageFunctionsByType.set(property_1.IMBRICATE_PROPERTY_TYPE.REFERENCE, triageFunction);
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
35
56
|
_collect(properties) {
|
|
36
57
|
const keys = Object.keys(properties);
|
|
37
58
|
const result = new Map();
|
package/document/validate.d.ts
CHANGED
|
@@ -10,8 +10,9 @@ import { DocumentProperties } from "./property";
|
|
|
10
10
|
*
|
|
11
11
|
* @param properties properties to validate
|
|
12
12
|
* @param schema database schema to validate
|
|
13
|
+
* @param allowExtraProperties allow extra properties, optional with default false
|
|
13
14
|
*
|
|
14
15
|
* @returns a string error message if validation failed
|
|
15
16
|
* null if validation passed
|
|
16
17
|
*/
|
|
17
|
-
export declare const validateImbricateProperties: (properties: DocumentProperties, schema: ImbricateDatabaseSchema) => string | null;
|
|
18
|
+
export declare const validateImbricateProperties: (properties: DocumentProperties, schema: ImbricateDatabaseSchema, allowExtraProperties?: boolean) => string | null;
|
package/document/validate.js
CHANGED
|
@@ -12,11 +12,12 @@ const property_1 = require("./property");
|
|
|
12
12
|
*
|
|
13
13
|
* @param properties properties to validate
|
|
14
14
|
* @param schema database schema to validate
|
|
15
|
+
* @param allowExtraProperties allow extra properties, optional with default false
|
|
15
16
|
*
|
|
16
17
|
* @returns a string error message if validation failed
|
|
17
18
|
* null if validation passed
|
|
18
19
|
*/
|
|
19
|
-
const validateImbricateProperties = (properties, schema) => {
|
|
20
|
+
const validateImbricateProperties = (properties, schema, allowExtraProperties = false) => {
|
|
20
21
|
if (typeof properties !== "object") {
|
|
21
22
|
return "Properties must be an object";
|
|
22
23
|
}
|
|
@@ -26,6 +27,9 @@ const validateImbricateProperties = (properties, schema) => {
|
|
|
26
27
|
return each.propertyIdentifier === key;
|
|
27
28
|
});
|
|
28
29
|
if (!property) {
|
|
30
|
+
if (allowExtraProperties) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
29
33
|
return `Property ${key} not found in schema`;
|
|
30
34
|
}
|
|
31
35
|
const value = properties[key];
|
|
@@ -35,6 +39,7 @@ const validateImbricateProperties = (properties, schema) => {
|
|
|
35
39
|
if (value.type !== property.propertyType) {
|
|
36
40
|
return `Property ${key} type must be ${property.propertyType}, but got ${value.type}`;
|
|
37
41
|
}
|
|
42
|
+
// IMBRICATE_PROPERTY_TYPE SWITCH
|
|
38
43
|
switch (value.type) {
|
|
39
44
|
case property_1.IMBRICATE_PROPERTY_TYPE.BOOLEAN: {
|
|
40
45
|
if (typeof value.value !== "boolean") {
|
|
@@ -60,6 +65,27 @@ const validateImbricateProperties = (properties, schema) => {
|
|
|
60
65
|
}
|
|
61
66
|
break;
|
|
62
67
|
}
|
|
68
|
+
case property_1.IMBRICATE_PROPERTY_TYPE.DATE: {
|
|
69
|
+
if (typeof value.value !== "string") {
|
|
70
|
+
return `Property ${key} value must be a string of date in ISO format`;
|
|
71
|
+
}
|
|
72
|
+
const date = new Date(value.value);
|
|
73
|
+
if (isNaN(date.getTime())) {
|
|
74
|
+
return `Property ${key} value must be a string of date in ISO format`;
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
case property_1.IMBRICATE_PROPERTY_TYPE.LABEL: {
|
|
79
|
+
if (!Array.isArray(value.value)) {
|
|
80
|
+
return `Property ${key} value must be an array of string`;
|
|
81
|
+
}
|
|
82
|
+
for (const label of value.value) {
|
|
83
|
+
if (typeof label !== "string") {
|
|
84
|
+
return `Property ${key} label must be a string`;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
63
89
|
case property_1.IMBRICATE_PROPERTY_TYPE.REFERENCE: {
|
|
64
90
|
if (!Array.isArray(value.value)) {
|
|
65
91
|
return `Property ${key} value must be an array of string`;
|