montycat 1.1.1 → 1.1.2
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/dist/classes/generic.js +9 -10
- package/dist/core/schema.d.ts +18 -2
- package/dist/core/schema.js +24 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/dist/classes/generic.js
CHANGED
|
@@ -230,7 +230,6 @@ class GenericKV {
|
|
|
230
230
|
};
|
|
231
231
|
return await runQuery(this, JSON.stringify(query));
|
|
232
232
|
}
|
|
233
|
-
// how to make it available for TS only ?
|
|
234
233
|
/**
|
|
235
234
|
* Enforces a schema on the store.
|
|
236
235
|
* @param schema - The schema to enforce. Should be an instance of the Schema class.
|
|
@@ -239,15 +238,15 @@ class GenericKV {
|
|
|
239
238
|
*/
|
|
240
239
|
static async enforceSchema(schema) {
|
|
241
240
|
function parseType(fieldType) {
|
|
242
|
-
switch (fieldType) {
|
|
243
|
-
case "String": return "String";
|
|
244
|
-
case "Number": return "Number";
|
|
245
|
-
case "Boolean": return "Boolean";
|
|
246
|
-
case "Array": return "Array";
|
|
247
|
-
case "Object": return "Object";
|
|
248
|
-
case "Pointer": return "Pointer";
|
|
249
|
-
case "Timestamp": return "Timestamp";
|
|
250
|
-
default: throw new TypeError(`Unsupported field type: ${fieldType}`);
|
|
241
|
+
switch (fieldType.getType()) {
|
|
242
|
+
case "String": return ["String", fieldType.getNullable()];
|
|
243
|
+
case "Number": return ["Number", fieldType.getNullable()];
|
|
244
|
+
case "Boolean": return ["Boolean", fieldType.getNullable()];
|
|
245
|
+
case "Array": return ["Array", fieldType.getNullable()];
|
|
246
|
+
case "Object": return ["Object", fieldType.getNullable()];
|
|
247
|
+
case "Pointer": return ["Pointer", fieldType.getNullable()];
|
|
248
|
+
case "Timestamp": return ["Timestamp", fieldType.getNullable()];
|
|
249
|
+
default: throw new TypeError(`Unsupported field type: ${fieldType.getType()}`);
|
|
251
250
|
}
|
|
252
251
|
}
|
|
253
252
|
let schemaTypes = {};
|
package/dist/core/schema.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ interface TimestampRangeConfig {
|
|
|
43
43
|
*/
|
|
44
44
|
declare class Schema {
|
|
45
45
|
[key: string]: any;
|
|
46
|
-
static metadata: Record<string,
|
|
46
|
+
static metadata: Record<string, Field> | null;
|
|
47
47
|
constructor(properties: {
|
|
48
48
|
[key: string]: any;
|
|
49
49
|
});
|
|
@@ -90,4 +90,20 @@ declare class Timestamp {
|
|
|
90
90
|
};
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Field class
|
|
95
|
+
* @class
|
|
96
|
+
* @param fieldType - The type of the field
|
|
97
|
+
* @param nullable - Whether the field is nullable // default is false
|
|
98
|
+
* @returns The field object
|
|
99
|
+
* @example
|
|
100
|
+
* const field = new Field('String', true);
|
|
101
|
+
*/
|
|
102
|
+
declare class Field {
|
|
103
|
+
fieldType: string;
|
|
104
|
+
nullable: boolean;
|
|
105
|
+
constructor(fieldType: string, nullable?: boolean);
|
|
106
|
+
getType(): string;
|
|
107
|
+
getNullable(): boolean;
|
|
108
|
+
}
|
|
109
|
+
export { Schema, Pointer, Timestamp, Field };
|
package/dist/core/schema.js
CHANGED
|
@@ -110,4 +110,27 @@ class Timestamp {
|
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Field class
|
|
115
|
+
* @class
|
|
116
|
+
* @param fieldType - The type of the field
|
|
117
|
+
* @param nullable - Whether the field is nullable // default is false
|
|
118
|
+
* @returns The field object
|
|
119
|
+
* @example
|
|
120
|
+
* const field = new Field('String', true);
|
|
121
|
+
*/
|
|
122
|
+
class Field {
|
|
123
|
+
fieldType;
|
|
124
|
+
nullable;
|
|
125
|
+
constructor(fieldType, nullable = false) {
|
|
126
|
+
this.fieldType = fieldType;
|
|
127
|
+
this.nullable = nullable;
|
|
128
|
+
}
|
|
129
|
+
getType() {
|
|
130
|
+
return this.fieldType;
|
|
131
|
+
}
|
|
132
|
+
getNullable() {
|
|
133
|
+
return this.nullable;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
export { Schema, Pointer, Timestamp, Field };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Engine, ValidPermissions } from "./core/engine.js";
|
|
2
2
|
import Keyspace from "./core/store.js";
|
|
3
|
-
import { Pointer, Timestamp, Schema } from "./core/schema.js";
|
|
4
|
-
export { Engine, ValidPermissions, Keyspace, Pointer, Timestamp, Schema };
|
|
3
|
+
import { Pointer, Timestamp, Schema, Field } from "./core/schema.js";
|
|
4
|
+
export { Engine, ValidPermissions, Keyspace, Pointer, Timestamp, Schema, Field };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Engine, ValidPermissions } from "./core/engine.js";
|
|
2
2
|
import Keyspace from "./core/store.js";
|
|
3
|
-
import { Pointer, Timestamp, Schema } from "./core/schema.js";
|
|
4
|
-
export { Engine, ValidPermissions, Keyspace, Pointer, Timestamp, Schema };
|
|
3
|
+
import { Pointer, Timestamp, Schema, Field } from "./core/schema.js";
|
|
4
|
+
export { Engine, ValidPermissions, Keyspace, Pointer, Timestamp, Schema, Field };
|