diff --git a/README.MD b/README.MD
index 4d074d6..9969a9a 100644
--- a/README.MD
+++ b/README.MD
@@ -48,5 +48,7 @@ By default RIDB is bundled with a default InMemory storage with support for writ
| **Data Encryption Plugin** | Secure data with encryption plugins |
| **Migration Plugin** | Support for data migrations |
| **Integrity Plugin** | Support for data has not been tampered with |
-| **IndexDB Storage** | Robust type safe replacement for Dexie
+| **IndexDB Storage** | Robust type safe replacement for Dexie
+| **InMemory Storage** | Robust type safe implementation of an inMemory storage
+| **LevelDB Storage** | Robust type safe implementation for LevelDB 'classic-level'
diff --git a/packages/ridb-level/README.MD b/packages/ridb-level/README.MD
index bea7701..96c8753 100644
--- a/packages/ridb-level/README.MD
+++ b/packages/ridb-level/README.MD
@@ -5,7 +5,6 @@
A secure light-weight and dependency free database wrapper for the web.
-
@@ -17,4 +16,37 @@
### Description
-This package is a leveldb wrapper for the ridb database.
\ No newline at end of file
+This package is a leveldb wrapper for the ridb database.
+
+## Installation & usage (typescript)
+```bash
+npm install @trust0/ridb-level # or yarn add @trust0/ridb-level
+```
+
+```typescript
+import { RIDB, SchemaFieldType, Doc } from '@trust0/ridb';
+import { LevelDB } from '@trust0/ridb-level';
+const db = new RIDB(
+ {
+ dbName: "test",
+ schemas: {
+ demo: {
+ version: 0,
+ primaryKey: 'id',
+ type: SchemaFieldType.object,
+ properties: {
+ id: {
+ type: SchemaFieldType.string,
+ maxLength: 60
+ }
+ }
+ }
+ } as const
+ }
+)
+await db.start({
+ storageType: LevelDB,
+ password: "test"
+});
+```
+
diff --git a/packages/ridb-level/docs/classes/LevelDB.md b/packages/ridb-level/docs/classes/LevelDB.md
index 017db24..52e356f 100644
--- a/packages/ridb-level/docs/classes/LevelDB.md
+++ b/packages/ridb-level/docs/classes/LevelDB.md
@@ -48,7 +48,7 @@
#### Defined in
-[packages/ridb-level/src/index.ts:44](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb-level/src/index.ts#L44)
+[ridb-level/src/index.ts:49](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb-level/src/index.ts#L49)
## Properties
@@ -62,7 +62,7 @@
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:403
+ridb-wasm/pkg/ridb\_wasm.d.ts:199
***
@@ -72,7 +72,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:403
#### Defined in
-[packages/ridb-level/src/index.ts:34](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb-level/src/index.ts#L34)
+[ridb-level/src/index.ts:39](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb-level/src/index.ts#L39)
***
@@ -86,7 +86,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:403
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:400
+ridb-wasm/pkg/ridb\_wasm.d.ts:196
***
@@ -100,7 +100,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:400
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:402
+ridb-wasm/pkg/ridb\_wasm.d.ts:198
***
@@ -114,7 +114,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:402
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:401
+ridb-wasm/pkg/ridb\_wasm.d.ts:197
## Methods
@@ -134,7 +134,7 @@ Close the database
#### Defined in
-[packages/ridb-level/src/index.ts:53](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb-level/src/index.ts#L53)
+[ridb-level/src/index.ts:58](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb-level/src/index.ts#L58)
***
@@ -164,7 +164,7 @@ keyof `T`
#### Defined in
-[packages/ridb-level/src/index.ts:99](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb-level/src/index.ts#L99)
+[ridb-level/src/index.ts:126](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb-level/src/index.ts#L126)
***
@@ -194,13 +194,13 @@ keyof `T`
#### Defined in
-[packages/ridb-level/src/index.ts:119](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb-level/src/index.ts#L119)
+[ridb-level/src/index.ts:146](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb-level/src/index.ts#L146)
***
### findDocumentById()
-> **findDocumentById**(`collectionName`, `id`): `Promise`\<`null` \| `Doc`\<`T`\[keyof `T`\]\>\>
+> **findDocumentById**(`collectionName`, `id`): `Promise`\<`undefined` \| `Doc`\<`T`\[keyof `T`\]\>\>
Find a document by its ID
@@ -216,7 +216,7 @@ keyof `T`
#### Returns
-`Promise`\<`null` \| `Doc`\<`T`\[keyof `T`\]\>\>
+`Promise`\<`undefined` \| `Doc`\<`T`\[keyof `T`\]\>\>
#### Overrides
@@ -224,7 +224,7 @@ keyof `T`
#### Defined in
-[packages/ridb-level/src/index.ts:57](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb-level/src/index.ts#L57)
+[ridb-level/src/index.ts:62](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb-level/src/index.ts#L62)
***
@@ -248,7 +248,7 @@ keyof `T`
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:411
+ridb-wasm/pkg/ridb\_wasm.d.ts:207
***
@@ -272,31 +272,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:411
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:412
-
-***
-
-### matchesQuery()
-
-> **matchesQuery**(`doc`, `query`): `boolean`
-
-#### Parameters
-
-##### doc
-
-`Doc`\<`T`\[keyof `T`\]\>
-
-##### query
-
-`Query`\<`any`\>
-
-#### Returns
-
-`boolean`
-
-#### Defined in
-
-[packages/ridb-level/src/index.ts:138](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb-level/src/index.ts#L138)
+ridb-wasm/pkg/ridb\_wasm.d.ts:208
***
@@ -316,7 +292,7 @@ Start the database
#### Defined in
-[packages/ridb-level/src/index.ts:49](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb-level/src/index.ts#L49)
+[ridb-level/src/index.ts:54](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb-level/src/index.ts#L54)
***
@@ -342,7 +318,7 @@ Write an operation (insert, update, delete)
#### Defined in
-[packages/ridb-level/src/index.ts:75](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb-level/src/index.ts#L75)
+[ridb-level/src/index.ts:83](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb-level/src/index.ts#L83)
***
@@ -378,4 +354,4 @@ Write an operation (insert, update, delete)
#### Defined in
-[packages/ridb-level/src/index.ts:35](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb-level/src/index.ts#L35)
+[ridb-level/src/index.ts:40](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb-level/src/index.ts#L40)
diff --git a/packages/ridb-level/src/index.ts b/packages/ridb-level/src/index.ts
index ffb75e3..cf2ba6d 100644
--- a/packages/ridb-level/src/index.ts
+++ b/packages/ridb-level/src/index.ts
@@ -62,15 +62,18 @@ export class LevelDB extends BaseStorage {
async findDocumentById(
collectionName: keyof T,
id: string
- ): Promise | null> {
+ ): Promise | undefined> {
const key = `${String(collectionName)}:${id}`;
try {
const value = await this.db.get(key);
+ if (!value) {
+ return undefined
+ }
const doc = JSON.parse(value);
return doc;
} catch (err: any) {
if (err.notFound) {
- return null;
+ return undefined;
} else {
throw err;
}
@@ -79,19 +82,38 @@ export class LevelDB extends BaseStorage {
/** Write an operation (insert, update, delete) */
async write(op: Operation): Promise> {
const collectionName = String(op.collection);
- const id = "id" in op.data ? op.data.id : null;
- if (!id) {
- throw new Error("Document ID is required");
- }
- const key = `${collectionName}:${id}`;
+ const primaryKey = this.getSchema(collectionName).primaryKey;
+
switch (op.opType) {
- case OpType.CREATE:
- case OpType.UPDATE: {
+ case OpType.CREATE: {
+ const id = primaryKey in op.data ? (op.data as any)[primaryKey] : null;
+ if (!id) {
+ throw new Error("Document ID is required");
+ }
+ const key = `${collectionName}:${id}`;
const value = JSON.stringify(op.data);
await this.db.put(key, value);
break;
}
+ case OpType.UPDATE: {
+ const id = primaryKey in op.data ? (op.data as any)[primaryKey] : null;
+ if (!id) {
+ throw new Error("Document ID is required");
+ }
+ const existingRecord = await this.findDocumentById(collectionName, id);
+ if (!existingRecord) {
+ throw new Error("Document ID not found");
+ }
+ const key = `${collectionName}:${id}`;
+ const value = JSON.stringify({
+ ...existingRecord,
+ ...op.data
+ });
+ await this.db.put(key, value);
+ break;
+ }
case OpType.DELETE: {
+ const key = `${collectionName}:${op.data}`;
await this.db.del(key);
break;
}
diff --git a/packages/ridb-wasm/build.sh b/packages/ridb-wasm/build.sh
index 18da246..651aa8a 100644
--- a/packages/ridb-wasm/build.sh
+++ b/packages/ridb-wasm/build.sh
@@ -10,7 +10,7 @@ PACKAGEJSON=./pkg/package.json
IMPORTFILE=./pkg/ridb_wasm.js
echo "Building the rust library"
-wasm-pack --log-level error build --target=web --scope trust0
+wasm-pack --log-level error build --target=web --scope trust0 --debug
if is_mac; then
diff --git a/packages/ridb-wasm/src/collection/mod.rs b/packages/ridb-wasm/src/collection/mod.rs
index 4cfadc1..c7c9e06 100644
--- a/packages/ridb-wasm/src/collection/mod.rs
+++ b/packages/ridb-wasm/src/collection/mod.rs
@@ -1,3 +1,4 @@
+use js_sys::{Object, Reflect};
use wasm_bindgen::prelude::wasm_bindgen;
use wasm_bindgen::JsValue;
use crate::schema::Schema;
@@ -207,10 +208,24 @@ impl Collection {
/// * `document` - A `JsValue` representing the partial document to update.
#[wasm_bindgen]
pub async fn update(&mut self, document: JsValue) -> Result {
+ let primary_key = self.schema()?.primary_key;
+ let doc_primary_key = Reflect::get(
+ &document,
+ &JsValue::from(primary_key)
+ )?;
+
+ let existing_doc = self.find_by_id(doc_primary_key).await?;
+ let merge_docs = JsValue::from(
+ Object::assign(
+ &Object::from(existing_doc),
+ &Object::from(document)
+ )
+ );
+
let processed_document = self.storage.call(
&self.name,
HookType::Create,
- document
+ merge_docs
).await?;
let res = match self.storage.write(&self.name, processed_document).await {
@@ -234,12 +249,14 @@ impl Collection {
/// * `document` - A `JsValue` representing the document to create.
#[wasm_bindgen]
pub async fn create(&mut self, document: JsValue) -> Result {
+ let schema = self.schema()?;
let processed_document = self.storage.call(
&self.name,
HookType::Create,
document
).await?;
+ schema.validate_document(processed_document.clone())?;
let res = match self.storage.write(&self.name, processed_document).await {
Ok(result) => Ok(result),
diff --git a/packages/ridb-wasm/src/lib.rs b/packages/ridb-wasm/src/lib.rs
index b78edb7..6903ec7 100644
--- a/packages/ridb-wasm/src/lib.rs
+++ b/packages/ridb-wasm/src/lib.rs
@@ -1,5 +1,6 @@
+use wasm_bindgen::prelude::*;
use wasm_bindgen::JsValue;
-use wasm_bindgen::prelude::wasm_bindgen;
+use std::panic;
pub mod error;
pub mod utils;
@@ -12,9 +13,9 @@ pub mod query;
pub mod operation;
pub mod plugin;
-
#[wasm_bindgen(start)]
pub fn main_js() -> Result<(), JsValue> {
+ panic::set_hook(Box::new(console_error_panic_hook::hook));
#[cfg(feature = "console_error_panic_hook")]
console_error_panic_hook::set_once();
Ok(())
@@ -32,8 +33,12 @@ pub fn is_debug_mode() -> bool {
}
fn get_debug_mode() -> bool {
+ use wasm_bindgen::prelude::*;
+ use js_sys::Reflect;
+
if let Some(win) = web_sys::window() {
- return win.local_storage()
+ // Browser environment
+ win.local_storage()
.ok()
.flatten()
.and_then(|storage| storage.get_item("DEBUG").ok().flatten())
@@ -42,20 +47,33 @@ fn get_debug_mode() -> bool {
.split(',')
.any(|s| s == "ridb" || s.starts_with("ridb:*"))
})
- .unwrap_or(false);
- }
-
- return std::env::var("DEBUG")
- .ok()
- .map(|debug_var| {
- debug_var
- .split(',')
- .any(|s| s == "ridb" || s.starts_with("ridb:*"))
- })
- .unwrap_or(false);
-}
+ .unwrap_or(false)
+ } else {
+ // Node.js environment
+ // Access process.env.DEBUG directly
+ let global = js_sys::global();
+ let process = Reflect::get(&global, &JsValue::from_str("process")).ok();
+ let env = process
+ .as_ref()
+ .and_then(|proc| Reflect::get(proc, &JsValue::from_str("env")).ok());
+ let debug_var = env
+ .as_ref()
+ .and_then(|env| Reflect::get(env, &JsValue::from_str("DEBUG")).ok());
+ if let Some(debug_js_value) = debug_var {
+ if let Some(debug_str) = debug_js_value.as_string() {
+ debug_str
+ .split(',')
+ .any(|s| s == "ridb" || s.starts_with("ridb:*"))
+ } else {
+ false
+ }
+ } else {
+ false
+ }
+ }
+}
mod logger {
use wasm_bindgen::prelude::*;
@@ -67,7 +85,6 @@ mod logger {
pub fn log(message: &JsValue) {
Logger::log_1(message);
}
-
pub fn debug(message: &JsValue) {
if crate::is_debug_mode() {
Logger::log_1(message);
@@ -75,7 +92,7 @@ mod logger {
}
fn log_1(message: &JsValue) {
- console::log_1(&message);
+ console::log_1(message);
}
}
}
\ No newline at end of file
diff --git a/packages/ridb-wasm/src/plugin/encryption/mod.rs b/packages/ridb-wasm/src/plugin/encryption/mod.rs
index 344faaf..4d1d86c 100644
--- a/packages/ridb-wasm/src/plugin/encryption/mod.rs
+++ b/packages/ridb-wasm/src/plugin/encryption/mod.rs
@@ -426,7 +426,7 @@ mod tests {
"number_field": {"type": "number"},
"boolean_field": {"type": "boolean"},
"object_field": {"type": "object", "properties": {"key":{"type":"string"}}},
- "array_field": {"type": "array", "items": [{"type": "number"}]}
+ "array_field": {"type": "array", "items": {"type": "number"}}
}
}"#;
let schema_value = JSON::parse(schema_js).unwrap();
diff --git a/packages/ridb-wasm/src/plugin/migration/mod.rs b/packages/ridb-wasm/src/plugin/migration/mod.rs
index 40814b7..fa24b00 100644
--- a/packages/ridb-wasm/src/plugin/migration/mod.rs
+++ b/packages/ridb-wasm/src/plugin/migration/mod.rs
@@ -427,7 +427,7 @@ mod tests {
"properties": {
"id": {"type": "string"},
"nested": {"type": "object", "properties": {"newp":{"type":"string"}}},
- "array": {"type": "array", "items": [{"type": "number"}]}
+ "array": {"type": "array", "items": {"type": "number"}}
}
}"#;
let schema_value = JSON::parse(schema_js).unwrap();
diff --git a/packages/ridb-wasm/src/schema/mod.rs b/packages/ridb-wasm/src/schema/mod.rs
index d53382d..d37db92 100644
--- a/packages/ridb-wasm/src/schema/mod.rs
+++ b/packages/ridb-wasm/src/schema/mod.rs
@@ -31,8 +31,6 @@ export type SchemaType = {
* The type of the schema.
*/
type: string;
-
- required?: string[];
indexes?: string[];
encrypted?: string[];
/**
@@ -87,11 +85,6 @@ export class Schema {
*/
readonly indexes?: (Extract)[];
- /**
- * An optional array of required fields.
- */
- readonly required?: (Extract)[];
-
/**
* An optional array of encrypted fields.
*/
@@ -111,6 +104,8 @@ export class Schema {
* @returns {SchemaType} The JSON representation of the schema.
*/
toJSON(): SchemaType;
+
+ validate(document: Doc>): boolean;
}
"#;
@@ -132,8 +127,6 @@ pub struct Schema {
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) indexes: Option>,
#[serde(skip_serializing_if = "Option::is_none")]
- pub(crate) required: Option>,
- #[serde(skip_serializing_if = "Option::is_none")]
pub(crate) encrypted: Option>
}
@@ -141,22 +134,47 @@ pub struct Schema {
#[wasm_bindgen]
impl Schema {
- pub fn validate_schema(&self, document: JsValue) -> Result<(), JsValue> {
- let required = self.required.clone().unwrap_or(Vec::new());
- let encrypted = self.encrypted.clone().unwrap_or(Vec::new());
+ #[wasm_bindgen(js_name="validate")]
+ pub fn validate_document(&self, document: JsValue) -> Result<(), JsValue> {
+ let schema_properties = self.properties.clone();
+
+ // Collect required fields
+ let required: Vec = schema_properties
+ .iter()
+ .filter(|(_, prop)| prop.required.unwrap_or(true))
+ .map(|(key, _)| key.clone())
+ .collect();
+ let encrypted = self.encrypted.clone().unwrap_or(Vec::new());
let properties = self.properties.clone();
for (key, prop) in properties {
+
let value = Reflect::get(&document, &JsValue::from_str(&key))
- .map_err(|e| JsValue::from_str(&format!("Failed to get property '{}': {:?}", key, e)))?;
+ .map_err(|_e| {
+ JsValue::from(
+ RIDBError::validation(
+ &format!("Missing required property '{}'", key)
+ )
+ )
+ })?;
if value.is_undefined() {
+ // If the property is required and not encrypted, it's an error
if required.contains(&key) && !encrypted.contains(&key) {
- return Err(JsValue::from_str(&format!("Field '{}' is required", key)));
+ return Err(
+ JsValue::from(
+ RIDBError::validation(
+ &format!("Missing required property '{}'", key)
+ )
+ )
+ );
}
} else {
- if !self.is_type_correct(&value, prop.property_type) {
+ let res = self.is_type_correct(&key, &value, &prop);
+ if let Err(err) = res {
+ return Err(err);
+ } else if !res.unwrap() {
return Err(JsValue::from_str(&format!(
"Field '{}' should be of type '{:?}'",
key, prop.property_type
@@ -168,25 +186,70 @@ impl Schema {
}
- fn is_type_correct(&self, value: &JsValue, prop_type: PropertyType) -> bool {
- match prop_type {
- PropertyType::String => value.is_string(),
+ fn is_type_correct(&self, key: &String, value: &JsValue, property: &Property) -> Result {
+ match property.property_type {
+ PropertyType::String => {
+ if let Some(string) = value.as_string() {
+ // Check maxLength and minLength if they exist
+ if let Some(max_length) = property.max_length {
+ if string.len() > max_length as usize {
+ return Err(JsValue::from(
+ RIDBError::validation(
+ &format!(
+ "Property '{}' exceeds maximum length of '{:?}'",
+ key, max_length
+ )))
+ );
+ }
+ }
+ if let Some(min_length) = property.min_length {
+ if string.len() < min_length as usize {
+ return Err(JsValue::from(
+ RIDBError::validation(
+ &format!(
+ "Property '{}' is lower than min length of '{:?}'",
+ key, min_length
+ )))
+ );
+ }
+ }
+ return Ok(true);
+ }
+ Ok(false)
+ },
PropertyType::Number => {
// Check if the value can be converted to an f64
- value.as_f64().is_some()
+ Ok(value.as_f64().is_some())
},
- PropertyType::Boolean => value.as_bool().is_some(),
+ PropertyType::Boolean => Ok(value.as_bool().is_some()),
PropertyType::Object => {
// Exclude null, arrays, and functions
- value.is_object()
+ Ok(value.is_object()
&& !value.is_null()
- && !js_sys::Array::is_array(value)
+ && !js_sys::Array::is_array(value))
+ },
+ PropertyType::Array => {
+ let arr = js_sys::Array::from(value);
+ if let Some(max_length) = property.max_items {
+ let len_js = arr.length();
+ let length = i32::try_from(len_js).unwrap();
+ if length > max_length {
+ return Err(JsValue::from(
+ RIDBError::validation(
+ &format!(
+ "Property '{}' exceeds maximum items of '{:?}'",
+ key, max_length
+ )))
+ );
+ }
+ }
+ Ok(true)
},
- PropertyType::Array => js_sys::Array::is_array(value),
// Add other property types as needed
- _ => false,
+ _ => Ok(false),
}
}
+
pub fn is_valid(&self) -> Result {
// Check if the schema type is "object"
@@ -265,11 +328,6 @@ impl Schema {
self.indexes.clone()
}
- #[wasm_bindgen(getter, js_name="required")]
- pub fn get_required(&self) -> Option> {
- self.required.clone()
- }
-
#[wasm_bindgen(getter, js_name="encrypted")]
pub fn get_encrypted(&self) -> Option> {
self.encrypted.clone()
diff --git a/packages/ridb-wasm/src/schema/property.rs b/packages/ridb-wasm/src/schema/property.rs
index f4a8cac..2de5eab 100644
--- a/packages/ridb-wasm/src/schema/property.rs
+++ b/packages/ridb-wasm/src/schema/property.rs
@@ -36,7 +36,7 @@ export class Property {
/**
* An optional array of nested properties for array-type properties.
*/
- readonly items?: Property[];
+ readonly items?: Property;
/**
* The maximum number of items for array-type properties, if applicable.
@@ -88,7 +88,7 @@ pub struct Property {
/// Optional nested items for array-type properties.
#[serde(skip_serializing_if = "Option::is_none")]
- pub(crate) items: Option>,
+ pub(crate) items: Option>,
/// Optional maximum number of items for array-type properties.
#[serde(rename = "maxItems", skip_serializing_if = "Option::is_none")]
@@ -113,6 +113,10 @@ pub struct Property {
/// Optional default value for the property.
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) default: Option,
+
+ /// Optional default value for the property.
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub(crate) required: Option,
}
#[wasm_bindgen]
@@ -139,27 +143,21 @@ impl Property {
PropertyType::Number => Ok(true),
PropertyType::Boolean => Ok(true),
PropertyType::Array => match self.clone().items {
- Some(items) => {
- let item = items.first();
- match item {
- Some(p) => {
- let is_valid = p.is_valid().unwrap();
- match is_valid {
- true => {
- let min = self.min_items.unwrap_or_else(|| 0);
- let max = self.max_items.unwrap_or_else(|| -1);
- if min < 0 {
- Err(RIDBError::validation("Min property not valid"))
- } else if min > max && max >= 1 {
- Err(RIDBError::validation("Min higher than max"))
- } else {
- Ok(true)
- }
- },
- false => Err(RIDBError::validation("Items property not valid"))
+ Some(item) => {
+ let is_valid = item.is_valid().unwrap();
+ match is_valid {
+ true => {
+ let min = self.min_items.unwrap_or_else(|| 0);
+ let max = self.max_items.unwrap_or_else(|| -1);
+ if min < 0 {
+ Err(RIDBError::validation("Min property not valid"))
+ } else if min > max && max >= 1 {
+ Err(RIDBError::validation("Min higher than max"))
+ } else {
+ Ok(true)
}
},
- None => Err(RIDBError::validation("Invalid property items"))
+ false => Err(RIDBError::validation("Items property not valid"))
}
},
None => Err(RIDBError::validation("Items is empty"))
@@ -275,6 +273,7 @@ mod tests {
min_length: None,
properties: None,
default: None,
+ required: Some(true)
};
assert_eq!(default_property.property_type, PropertyType::String);
assert!(default_property.items.is_none());
@@ -297,6 +296,7 @@ mod tests {
min_length: None,
properties: None,
default: None,
+ required: Some(true)
};
// Test default values to ensure proper initialization
assert_eq!(default_property.property_type, PropertyType::Array);
@@ -325,16 +325,18 @@ mod tests {
min_length: None,
properties: None,
default: None,
+ required: Some(true)
};
let default_property = Property {
property_type: PropertyType::Array,
- items: Some(vec![prop]),
+ items: Some(Box::new(prop)),
max_items: Some(-1),
min_items: Some(-1),
max_length: None,
min_length: None,
properties: None,
default: None,
+ required: Some(true)
};
let result = default_property.is_valid();
match result {
@@ -354,17 +356,19 @@ mod tests {
min_length: None,
properties: None,
default: None,
+ required: Some(true)
};
let default_property2 = Property {
property_type: PropertyType::Array,
- items: Some(vec![prop]),
+ items: Some(Box::new(prop)),
max_items: Some(1),
min_items: Some(2),
max_length: None,
min_length: None,
properties: None,
default: None,
+ required: Some(true)
};
let result = default_property2.is_valid();
// Check the result for an error message
@@ -386,17 +390,19 @@ mod tests {
min_length: None,
properties: None,
default: None,
+ required: Some(true)
};
let default_property2 = Property {
property_type: PropertyType::Array,
- items: Some(vec![prop]),
+ items: Some(Box::new(prop)),
max_items: Some(1),
min_items: Some(-1),
max_length: None,
min_length: None,
properties: None,
default: None,
+ required: Some(true)
};
let result = default_property2.is_valid();
// Check the result for an error message
@@ -418,6 +424,7 @@ mod tests {
min_length: None,
properties: None,
default: None,
+ required: Some(true)
};
let result = default_property2.is_valid();
// Check the result for an error message
@@ -438,6 +445,7 @@ mod tests {
min_length: None,
properties: None,
default: None,
+ required: Some(true)
};
let result = default_property2.is_valid();
// Check the result for an error message
@@ -458,6 +466,7 @@ mod tests {
min_length: Some(2),
properties: None,
default: None,
+ required: Some(true)
};
let result = default_property2.is_valid();
// Check the result for an error message
@@ -478,6 +487,7 @@ mod tests {
min_length: Some(-1),
properties: None,
default: None,
+ required: Some(true)
};
let result = default_property2.is_valid();
// Check the result for an error message
@@ -498,6 +508,7 @@ mod tests {
min_length: None,
properties: None,
default: None,
+ required: Some(true)
}.is_valid();
// Check the result for an error message
match result {
@@ -517,6 +528,7 @@ mod tests {
min_length: None,
properties: Some(HashMap::new()),
default: None,
+ required: Some(true)
}.is_valid();
// Check the result for an error message
match result {
diff --git a/packages/ridb-wasm/src/storage/internals/base_storage.rs b/packages/ridb-wasm/src/storage/internals/base_storage.rs
index 0708b71..4854118 100644
--- a/packages/ridb-wasm/src/storage/internals/base_storage.rs
+++ b/packages/ridb-wasm/src/storage/internals/base_storage.rs
@@ -38,7 +38,7 @@ export class BaseStorage extends StorageIntern
start(): Promise;
close(): Promise;
count(colectionName: keyof Schemas, query: QueryType): Promise;
- findDocumentById(collectionName: keyof Schemas, id: string): Promise | null>;
+ findDocumentById(collectionName: keyof Schemas, id: string): Promise | null | undefined>;
find(collectionName: keyof Schemas, query: QueryType): Promise[]>;
write(op: Operation): Promise>;
diff --git a/packages/ridb-wasm/src/storage/internals/core.rs b/packages/ridb-wasm/src/storage/internals/core.rs
index e7195b8..c1de26d 100644
--- a/packages/ridb-wasm/src/storage/internals/core.rs
+++ b/packages/ridb-wasm/src/storage/internals/core.rs
@@ -33,6 +33,22 @@ impl CoreStorage {
Self {}
}
+
+ #[wasm_bindgen(js_name = getPrimaryKey)]
+ pub fn get_primary_key(&self, value:JsValue) -> Result {
+ if value.is_undefined() || value.is_null() {
+ return Err(JsValue::from_str("Document must contain a primary key"));
+ }
+ if let Some(s) = value.as_string() {
+ Ok(s)
+ } else if let Some(n) = value.as_f64() {
+ Ok(n.to_string())
+ } else {
+ Err(JsValue::from_str(&format!("Failed to get primary key, must be number or string but is: {:?}", value)))
+ }
+ }
+
+
#[wasm_bindgen(js_name = matchesQuery)]
pub fn document_matches_query(
&self,
diff --git a/packages/ridb-wasm/src/storage/mod.rs b/packages/ridb-wasm/src/storage/mod.rs
index a080d84..e02d11f 100644
--- a/packages/ridb-wasm/src/storage/mod.rs
+++ b/packages/ridb-wasm/src/storage/mod.rs
@@ -1,10 +1,10 @@
use std::collections::HashMap;
-
use js_sys::Reflect;
use serde_wasm_bindgen::to_value;
use wasm_bindgen::{JsCast, JsValue};
use crate::{error::RIDBError, operation::{OpType, Operation}, plugin::BasePlugin, schema::{property_type::PropertyType, Schema}, storages::base::StorageExternal};
+use crate::logger::Logger;
pub mod internals;
@@ -170,62 +170,16 @@ impl Storage {
}
}
- /// Checks if a value is of the correct type based on the property type.
- ///
- /// # Arguments
- ///
- /// * `value` - The value to check.
- /// * `prop_type` - The expected property type.
- ///
- /// # Returns
- ///
- /// * `bool` - `true` if the value is of the correct type, otherwise `false`.
- pub fn is_type_correct(&self, value: &JsValue, prop_type: PropertyType) -> bool {
- match prop_type {
- PropertyType::String => value.is_string(),
- PropertyType::Number => value.as_f64().is_some(),
- PropertyType::Object => value.is_object(),
- PropertyType::Array => value.is_array(),
- PropertyType::Boolean => value.is_falsy() || value.is_truthy(),
- _ => false,
- }
- }
-
- pub fn validate_schema(&self, collection_name: &str, document_without_pk: JsValue) -> Result {
- let document = self.ensure_primary_key(collection_name, document_without_pk)?;
- let schema = self.get_schema(collection_name)?;
- let properties = schema.properties.clone();
- let required = schema.required.clone().unwrap_or(Vec::new());
- let encrypted = schema.encrypted.clone().unwrap_or(Vec::new());
-
- for (key, prop) in properties {
- let value = Reflect::get(&document, &JsValue::from_str(&key))?;
- if value.is_undefined() {
- if required.contains(&key) && !encrypted.contains(&key) {
- return Err(JsValue::from(RIDBError::error(
- &format!("Field {} is required", key),
- )));
- }
- } else {
- if !self.is_type_correct(&value, prop.property_type) {
- return Err(JsValue::from(RIDBError::error(
- &format!("Field {} should match type {:?}", key, prop.property_type),
- )));
- }
- }
- }
- Ok(document)
- }
-
pub(crate) async fn write(&self, collection_name: &str, document_without_pk: JsValue) -> Result {
// Move all the preparation logic before the async operation
+ let schema = self.get_schema(collection_name)?;
+ let primary_key = schema.primary_key.clone();
+ let indexes = schema.indexes.clone();
+ let document = self.ensure_primary_key(collection_name, document_without_pk)?;
+
+ schema.validate_document(document.clone())?;
+
let operation = {
- let schema = self.get_schema(collection_name)?;
- let primary_key = schema.primary_key.clone();
- let indexes = schema.indexes.clone();
-
- let document = self.validate_schema(collection_name, document_without_pk)?;
-
let indexes = match indexes {
Some(mut existing) => {
existing.push(primary_key.clone());
@@ -237,14 +191,11 @@ impl Storage {
new_index
}
};
-
let pk = Reflect::get(&document, &JsValue::from_str(primary_key.as_str()))
.map_err(|e| JsValue::from(RIDBError::from(e)))?;
-
// Find existing document
let existing = self.find_document_by_id(collection_name, pk).await?;
-
- let op_type = if existing.is_null() { OpType::CREATE } else { OpType::UPDATE };
+ let op_type = if existing.is_null() | existing.is_undefined() { OpType::CREATE } else { OpType::UPDATE };
Operation {
collection: collection_name.to_string(),
@@ -270,20 +221,47 @@ impl Storage {
}
pub(crate) async fn remove(&self, collection_name: &str, primary_key: JsValue) -> Result {
+ Logger::debug(&JsValue::from(&format!(
+ "Starting remove operation for collection: {}, primary_key: {:?}",
+ collection_name, primary_key
+ )));
+
let result = self.find_document_by_id(collection_name, primary_key.clone()).await?;
let schema = self.get_schema(collection_name)?;
- if result.is_null() {
+
+ Logger::debug(&JsValue::from(&format!(
+ "Found document for removal: {:?}",
+ result
+ )));
+
+ if result.is_undefined() | result.is_null() {
+ Logger::debug(&JsValue::from(
+ "Remove operation failed: Document not found"
+ ));
Err(JsValue::from_str("Invalid primary key value"))
} else {
+ let index_name = format!("pk_{}_{}", collection_name, schema.primary_key);
+
let op = Operation {
collection: collection_name.to_string(),
op_type: OpType::DELETE,
- data: result,
+ data: primary_key.clone(),
indexes: vec![
- schema.primary_key.clone()
+ index_name
],
};
+
+ Logger::debug(&JsValue::from(&format!(
+ "DELETE OPERATION {:?} ", op
+ )));
+
let result = self.internal.write(op).await;
+
+ match &result {
+ Ok(_) => Logger::debug(&JsValue::from("Remove operation completed successfully")),
+ Err(e) => Logger::debug(&JsValue::from(&format!("Remove operation failed: {:?}", e))),
+ }
+
result.map_err(|e| JsValue::from(RIDBError::from(e)))
}
}
diff --git a/packages/ridb-wasm/src/storages/base.rs b/packages/ridb-wasm/src/storages/base.rs
index 41ef4e4..4e3f973 100644
--- a/packages/ridb-wasm/src/storages/base.rs
+++ b/packages/ridb-wasm/src/storages/base.rs
@@ -29,7 +29,7 @@ export abstract class StorageInternal {
abstract findDocumentById(
collectionName: keyof Schemas,
id: string
- ): Promise | null>;
+ ): Promise | undefined | null>;
abstract find(
collectionName: keyof Schemas,
query: QueryType
diff --git a/packages/ridb-wasm/src/storages/indexdb/mod.rs b/packages/ridb-wasm/src/storages/indexdb/mod.rs
index a720b1e..0941d3e 100644
--- a/packages/ridb-wasm/src/storages/indexdb/mod.rs
+++ b/packages/ridb-wasm/src/storages/indexdb/mod.rs
@@ -149,10 +149,6 @@ impl Storage for IndexDB {
if pk_value.is_undefined() || pk_value.is_null() {
return Err(JsValue::from_str("Document must contain a primary key"));
}
-
- // Validate document against schema
- schema.validate_schema(document.clone())?;
-
// Store the document and wait for completion
let request = store.put_with_key(&document, &pk_value)?;
idb_request_result(request).await?;
@@ -258,28 +254,26 @@ impl Storage for IndexDB {
async fn find_document_by_id(&self, collection_name: &str, primary_key_value: JsValue) -> Result {
let store_name = collection_name;
+ if primary_key_value.is_undefined() || primary_key_value.is_null() {
+ return Err(JsValue::from_str("Primary key value is required"));
+ }
+
let transaction = self.db.transaction_with_str(store_name)?;
let store = transaction.object_store(store_name)?;
+ Logger::debug(&JsValue::from(&format!("Finding document with primary key: {:?}", primary_key_value)));
+
let request = store.get(&primary_key_value)?;
- let promise = Promise::new(&mut |resolve, reject| {
- let onsucess = Closure::once(Box::new(move |event: web_sys::Event| {
- let request: IdbRequest = event.target().unwrap().dyn_into().unwrap();
- let result = request.result().unwrap();
-
- if result.is_undefined() {
- reject.call1(&JsValue::undefined(), &JsValue::from_str("Document not found")).unwrap();
- } else {
- resolve.call1(&JsValue::undefined(), &result).unwrap();
- }
- }));
-
- request.set_onsuccess(Some(onsucess.as_ref().unchecked_ref()));
- onsucess.forget();
- });
+ let result = idb_request_result(request).await?;
- JsFuture::from(promise).await
+ if result.is_undefined() || result.is_null() {
+ Logger::debug(&JsValue::from("Document not found"));
+ Ok(JsValue::undefined())
+ } else {
+ Logger::debug(&JsValue::from("Document found"));
+ Ok(result)
+ }
}
async fn count(&self,collection_name: &str, query: Query) -> Result {
diff --git a/packages/ridb-wasm/src/storages/inmemory/mod.rs b/packages/ridb-wasm/src/storages/inmemory/mod.rs
index 7a55101..8d10b3d 100644
--- a/packages/ridb-wasm/src/storages/inmemory/mod.rs
+++ b/packages/ridb-wasm/src/storages/inmemory/mod.rs
@@ -7,7 +7,7 @@ use crate::query::Query;
use crate::storage::internals::base_storage::BaseStorage;
use crate::storage::internals::core::CoreStorage;
use std::sync::RwLock;
-
+use crate::logger::Logger;
use super::base::Storage;
#[wasm_bindgen(typescript_custom_section)]
@@ -45,11 +45,17 @@ pub struct InMemory {
impl Storage for InMemory {
+
+
+
async fn write(&self, op: &Operation) -> Result {
+
let schema = self.base.schemas.get(op.collection.as_str()).ok_or_else(|| JsValue::from_str("Collection not found"))?;
let primary_key = schema.primary_key.clone();
let index_name = format!("pk_{}_{}", op.collection, primary_key);
+ Logger::debug(&JsValue::from(&format!("Attempting to acquire write lock for index: {}", index_name)));
+
let mut index_guard = self.by_index.write().map_err(|_| JsValue::from_str("Failed to acquire write lock"))?;
let index = index_guard
.entry(index_name.clone())
@@ -63,60 +69,48 @@ impl Storage for InMemory {
let pk_value = Reflect::get(&document, &JsValue::from_str(&primary_key))
.map_err(|e| JsValue::from_str(&format!("Failed to get primary key: {:?}", e)))?;
- if pk_value.is_undefined() || pk_value.is_null() {
- return Err(JsValue::from_str("Document must contain a primary key"));
- }
+ let pk_str = self.core.get_primary_key(pk_value)?;
- let pk_str = if let Some(s) = pk_value.as_string() {
- s
- } else if let Some(n) = pk_value.as_f64() {
- n.to_string()
- } else {
- return Err(JsValue::from_str("Primary key must be a string or number"));
- };
+ Logger::debug(&JsValue::from(&format!("Primary key extracted: {}", pk_str)));
match op.op_type {
OpType::CREATE => {
- schema.validate_schema(document.clone())?;
-
+ Logger::debug(&JsValue::from(&format!("Creating document with primary key: {}", pk_str)));
+
if index.contains_key(&pk_str) {
+ Logger::debug(&JsValue::from("Document with this primary key already exists"));
return Err(JsValue::from_str("Document with this primary key already exists"));
}
index.insert(pk_str.clone(), document.clone());
+ Logger::debug(&JsValue::from(&format!("Document created with primary key: {}", pk_str)));
Ok(document)
}
OpType::UPDATE => {
- schema.validate_schema(document.clone())?;
-
+ Logger::debug(&JsValue::from(&format!("Updating document with primary key: {}", pk_str)));
+
if !index.contains_key(&pk_str) {
+ Logger::debug(&JsValue::from("Document with this primary key does not exist"));
return Err(JsValue::from_str("Document with this primary key does not exist"));
}
-
+
index.insert(pk_str.clone(), document.clone());
+ Logger::debug(&JsValue::from(&format!("Document updated with primary key: {}", pk_str)));
Ok(document)
}
_ => Err(JsValue::from_str("Unsupported operation type for this data"))
}
}
OpType::DELETE => {
- let pk_value = op.data.clone();
-
- if pk_value.is_undefined() || pk_value.is_null() {
- return Err(JsValue::from_str("Primary key value is required for delete operation"));
- }
+ Logger::debug(&JsValue::from(&format!("Deleting document with primary key: {}", primary_key)));
- let pk_str = if let Some(s) = pk_value.as_string() {
- s
- } else if let Some(n) = pk_value.as_f64() {
- n.to_string()
- } else {
- return Err(JsValue::from_str("Primary key must be a string or number"));
- };
+ let pk_str = self.core.get_primary_key(op.data.clone())?;
if index.remove(&pk_str).is_some() {
+ Logger::debug(&JsValue::from(&format!("Document deleted with primary key: {}", pk_str)));
Ok(JsValue::from_str("Document deleted"))
} else {
+ Logger::debug(&JsValue::from("Document with this primary key does not exist"));
Err(JsValue::from_str("Document with this primary key does not exist"))
}
}
@@ -153,14 +147,14 @@ impl Storage for InMemory {
let primary_key = schema.primary_key.clone();
let index_name = format!("pk_{}_{}", collection_name, primary_key);
+ Logger::debug(
+ &JsValue::from(
+ &format!("finding indes pk_{}_{}", collection_name, primary_key)
+ )
+ );
+
// Convert primary key value to string
- let pk_str = if let Some(s) = primary_key_value.as_string() {
- s
- } else if let Some(n) = primary_key_value.as_f64() {
- n.to_string()
- } else {
- return Err(JsValue::from_str("Invalid primary key value"));
- };
+ let pk_str = self.core.get_primary_key(primary_key_value)?;
// Retrieve the index
if let Some(index) = self.by_index.read().unwrap().get(&index_name) {
@@ -169,7 +163,7 @@ impl Storage for InMemory {
}
}
- Err(JsValue::from_str("Document not found"))
+ Ok(JsValue::undefined())
}
async fn count(&self, collection_name: &str, query: Query) -> Result {
@@ -221,6 +215,7 @@ impl Storage for InMemory {
#[wasm_bindgen]
impl InMemory {
+
#[wasm_bindgen]
pub async fn create(name: &str, schemas_js: Object) -> Result {
diff --git a/packages/ridb/docs/classes/BasePlugin.md b/packages/ridb/docs/classes/BasePlugin.md
index d613329..6d9a13f 100644
--- a/packages/ridb/docs/classes/BasePlugin.md
+++ b/packages/ridb/docs/classes/BasePlugin.md
@@ -32,7 +32,7 @@
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:631
+ridb-wasm/pkg/ridb\_wasm.d.ts:547
***
@@ -46,4 +46,4 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:631
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:632
+ridb-wasm/pkg/ridb\_wasm.d.ts:548
diff --git a/packages/ridb/docs/classes/BaseStorage.md b/packages/ridb/docs/classes/BaseStorage.md
index be52377..af94e00 100644
--- a/packages/ridb/docs/classes/BaseStorage.md
+++ b/packages/ridb/docs/classes/BaseStorage.md
@@ -49,7 +49,7 @@
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:394
+ridb-wasm/pkg/ridb\_wasm.d.ts:190
## Properties
@@ -59,7 +59,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:394
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:403
+ridb-wasm/pkg/ridb\_wasm.d.ts:199
***
@@ -69,7 +69,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:403
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:400
+ridb-wasm/pkg/ridb\_wasm.d.ts:196
***
@@ -79,7 +79,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:400
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:402
+ridb-wasm/pkg/ridb\_wasm.d.ts:198
***
@@ -89,7 +89,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:402
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:401
+ridb-wasm/pkg/ridb\_wasm.d.ts:197
## Methods
@@ -107,7 +107,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:401
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:405
+ridb-wasm/pkg/ridb\_wasm.d.ts:201
***
@@ -135,7 +135,7 @@ keyof `Schemas`
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:406
+ridb-wasm/pkg/ridb\_wasm.d.ts:202
***
@@ -163,13 +163,13 @@ keyof `Schemas`
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:408
+ridb-wasm/pkg/ridb\_wasm.d.ts:204
***
### findDocumentById()
-> **findDocumentById**(`collectionName`, `id`): `Promise`\<`null` \| [`Doc`](../type-aliases/Doc.md)\<`Schemas`\[keyof `Schemas`\]\>\>
+> **findDocumentById**(`collectionName`, `id`): `Promise`\<`undefined` \| `null` \| [`Doc`](../type-aliases/Doc.md)\<`Schemas`\[keyof `Schemas`\]\>\>
#### Parameters
@@ -183,7 +183,7 @@ keyof `Schemas`
#### Returns
-`Promise`\<`null` \| [`Doc`](../type-aliases/Doc.md)\<`Schemas`\[keyof `Schemas`\]\>\>
+`Promise`\<`undefined` \| `null` \| [`Doc`](../type-aliases/Doc.md)\<`Schemas`\[keyof `Schemas`\]\>\>
#### Overrides
@@ -191,7 +191,7 @@ keyof `Schemas`
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:407
+ridb-wasm/pkg/ridb\_wasm.d.ts:203
***
@@ -211,7 +211,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:407
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:411
+ridb-wasm/pkg/ridb\_wasm.d.ts:207
***
@@ -231,7 +231,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:411
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:412
+ridb-wasm/pkg/ridb\_wasm.d.ts:208
***
@@ -249,7 +249,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:412
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:404
+ridb-wasm/pkg/ridb\_wasm.d.ts:200
***
@@ -273,7 +273,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:404
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:409
+ridb-wasm/pkg/ridb\_wasm.d.ts:205
***
@@ -305,4 +305,4 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:409
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:384
+ridb-wasm/pkg/ridb\_wasm.d.ts:180
diff --git a/packages/ridb/docs/classes/Collection.md b/packages/ridb/docs/classes/Collection.md
index 3b031b4..a143db4 100644
--- a/packages/ridb/docs/classes/Collection.md
+++ b/packages/ridb/docs/classes/Collection.md
@@ -46,7 +46,7 @@ A promise that resolves to an array of documents.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:169
+ridb-wasm/pkg/ridb\_wasm.d.ts:305
***
@@ -72,7 +72,7 @@ A promise that resolves to the created document.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:191
+ridb-wasm/pkg/ridb\_wasm.d.ts:327
***
@@ -98,7 +98,7 @@ A promise that resolves when the deletion is complete.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:198
+ridb-wasm/pkg/ridb\_wasm.d.ts:334
***
@@ -122,7 +122,7 @@ A promise that resolves to an array of documents.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:163
+ridb-wasm/pkg/ridb\_wasm.d.ts:299
***
@@ -148,7 +148,7 @@ A promise that resolves to the found document.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:176
+ridb-wasm/pkg/ridb\_wasm.d.ts:312
***
@@ -174,4 +174,4 @@ A promise that resolves when the update is complete.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:184
+ridb-wasm/pkg/ridb\_wasm.d.ts:320
diff --git a/packages/ridb/docs/classes/CoreStorage.md b/packages/ridb/docs/classes/CoreStorage.md
index 8c938e5..7ceb03e 100644
--- a/packages/ridb/docs/classes/CoreStorage.md
+++ b/packages/ridb/docs/classes/CoreStorage.md
@@ -38,4 +38,4 @@
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:326
+ridb-wasm/pkg/ridb\_wasm.d.ts:95
diff --git a/packages/ridb/docs/classes/Database.md b/packages/ridb/docs/classes/Database.md
index 6e43203..c99c4fb 100644
--- a/packages/ridb/docs/classes/Database.md
+++ b/packages/ridb/docs/classes/Database.md
@@ -60,7 +60,7 @@ This is a read-only property where the key is the name of the collection and the
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:574
+ridb-wasm/pkg/ridb\_wasm.d.ts:397
***
@@ -70,7 +70,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:574
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:578
+ridb-wasm/pkg/ridb\_wasm.d.ts:401
## Methods
@@ -88,7 +88,7 @@ A promise that resolves when the database is closed.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:592
+ridb-wasm/pkg/ridb\_wasm.d.ts:415
***
@@ -106,7 +106,7 @@ A promise that resolves when the database is started.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:585
+ridb-wasm/pkg/ridb\_wasm.d.ts:408
***
@@ -162,4 +162,4 @@ A promise that resolves to the created `Database` instance.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:559
+ridb-wasm/pkg/ridb\_wasm.d.ts:382
diff --git a/packages/ridb/docs/classes/InMemory.md b/packages/ridb/docs/classes/InMemory.md
index a710cc3..413d798 100644
--- a/packages/ridb/docs/classes/InMemory.md
+++ b/packages/ridb/docs/classes/InMemory.md
@@ -48,7 +48,7 @@ The schema type.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:394
+ridb-wasm/pkg/ridb\_wasm.d.ts:190
## Properties
@@ -62,7 +62,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:394
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:403
+ridb-wasm/pkg/ridb\_wasm.d.ts:199
***
@@ -76,7 +76,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:403
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:400
+ridb-wasm/pkg/ridb\_wasm.d.ts:196
***
@@ -90,7 +90,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:400
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:402
+ridb-wasm/pkg/ridb\_wasm.d.ts:198
***
@@ -104,7 +104,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:402
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:401
+ridb-wasm/pkg/ridb\_wasm.d.ts:197
## Methods
@@ -122,7 +122,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:401
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:405
+ridb-wasm/pkg/ridb\_wasm.d.ts:201
***
@@ -150,7 +150,7 @@ keyof `T`
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:406
+ridb-wasm/pkg/ridb\_wasm.d.ts:202
***
@@ -178,13 +178,13 @@ keyof `T`
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:408
+ridb-wasm/pkg/ridb\_wasm.d.ts:204
***
### findDocumentById()
-> **findDocumentById**(`collectionName`, `id`): `Promise`\<`null` \| [`Doc`](../type-aliases/Doc.md)\<`T`\[keyof `T`\]\>\>
+> **findDocumentById**(`collectionName`, `id`): `Promise`\<`undefined` \| `null` \| [`Doc`](../type-aliases/Doc.md)\<`T`\[keyof `T`\]\>\>
#### Parameters
@@ -198,7 +198,7 @@ keyof `T`
#### Returns
-`Promise`\<`null` \| [`Doc`](../type-aliases/Doc.md)\<`T`\[keyof `T`\]\>\>
+`Promise`\<`undefined` \| `null` \| [`Doc`](../type-aliases/Doc.md)\<`T`\[keyof `T`\]\>\>
#### Inherited from
@@ -206,7 +206,7 @@ keyof `T`
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:407
+ridb-wasm/pkg/ridb\_wasm.d.ts:203
***
@@ -222,7 +222,7 @@ Frees the resources used by the in-memory storage.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:213
+ridb-wasm/pkg/ridb\_wasm.d.ts:659
***
@@ -246,7 +246,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:213
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:411
+ridb-wasm/pkg/ridb\_wasm.d.ts:207
***
@@ -270,7 +270,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:411
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:412
+ridb-wasm/pkg/ridb\_wasm.d.ts:208
***
@@ -288,7 +288,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:412
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:404
+ridb-wasm/pkg/ridb\_wasm.d.ts:200
***
@@ -312,7 +312,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:404
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:409
+ridb-wasm/pkg/ridb\_wasm.d.ts:205
***
@@ -344,4 +344,4 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:409
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:215
+ridb-wasm/pkg/ridb\_wasm.d.ts:661
diff --git a/packages/ridb/docs/classes/IndexDB.md b/packages/ridb/docs/classes/IndexDB.md
index 5fb30db..8bb0953 100644
--- a/packages/ridb/docs/classes/IndexDB.md
+++ b/packages/ridb/docs/classes/IndexDB.md
@@ -48,7 +48,7 @@ The schema type.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:394
+ridb-wasm/pkg/ridb\_wasm.d.ts:190
## Properties
@@ -62,7 +62,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:394
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:403
+ridb-wasm/pkg/ridb\_wasm.d.ts:199
***
@@ -76,7 +76,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:403
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:400
+ridb-wasm/pkg/ridb\_wasm.d.ts:196
***
@@ -90,7 +90,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:400
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:402
+ridb-wasm/pkg/ridb\_wasm.d.ts:198
***
@@ -104,7 +104,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:402
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:401
+ridb-wasm/pkg/ridb\_wasm.d.ts:197
## Methods
@@ -122,7 +122,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:401
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:405
+ridb-wasm/pkg/ridb\_wasm.d.ts:201
***
@@ -150,7 +150,7 @@ keyof `T`
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:406
+ridb-wasm/pkg/ridb\_wasm.d.ts:202
***
@@ -178,13 +178,13 @@ keyof `T`
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:408
+ridb-wasm/pkg/ridb\_wasm.d.ts:204
***
### findDocumentById()
-> **findDocumentById**(`collectionName`, `id`): `Promise`\<`null` \| [`Doc`](../type-aliases/Doc.md)\<`T`\[keyof `T`\]\>\>
+> **findDocumentById**(`collectionName`, `id`): `Promise`\<`undefined` \| `null` \| [`Doc`](../type-aliases/Doc.md)\<`T`\[keyof `T`\]\>\>
#### Parameters
@@ -198,7 +198,7 @@ keyof `T`
#### Returns
-`Promise`\<`null` \| [`Doc`](../type-aliases/Doc.md)\<`T`\[keyof `T`\]\>\>
+`Promise`\<`undefined` \| `null` \| [`Doc`](../type-aliases/Doc.md)\<`T`\[keyof `T`\]\>\>
#### Inherited from
@@ -206,7 +206,7 @@ keyof `T`
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:407
+ridb-wasm/pkg/ridb\_wasm.d.ts:203
***
@@ -222,7 +222,7 @@ Frees the resources used by the in-memory storage.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:75
+ridb-wasm/pkg/ridb\_wasm.d.ts:75
***
@@ -246,7 +246,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:75
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:411
+ridb-wasm/pkg/ridb\_wasm.d.ts:207
***
@@ -270,7 +270,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:411
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:412
+ridb-wasm/pkg/ridb\_wasm.d.ts:208
***
@@ -288,7 +288,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:412
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:404
+ridb-wasm/pkg/ridb\_wasm.d.ts:200
***
@@ -312,7 +312,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:404
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:409
+ridb-wasm/pkg/ridb\_wasm.d.ts:205
***
@@ -344,4 +344,4 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:409
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:77
+ridb-wasm/pkg/ridb\_wasm.d.ts:77
diff --git a/packages/ridb/docs/classes/Property.md b/packages/ridb/docs/classes/Property.md
index c965814..06e90c4 100644
--- a/packages/ridb/docs/classes/Property.md
+++ b/packages/ridb/docs/classes/Property.md
@@ -28,19 +28,19 @@ An optional default value for the property.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:308
+ridb-wasm/pkg/ridb\_wasm.d.ts:523
***
### items?
-> `readonly` `optional` **items**: [`Property`](Property.md)[]
+> `readonly` `optional` **items**: [`Property`](Property.md)
An optional array of nested properties for array-type properties.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:278
+ridb-wasm/pkg/ridb\_wasm.d.ts:493
***
@@ -52,7 +52,7 @@ The maximum number of items for array-type properties, if applicable.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:283
+ridb-wasm/pkg/ridb\_wasm.d.ts:498
***
@@ -64,7 +64,7 @@ The maximum length for string-type properties, if applicable.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:293
+ridb-wasm/pkg/ridb\_wasm.d.ts:508
***
@@ -76,7 +76,7 @@ The minimum number of items for array-type properties, if applicable.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:288
+ridb-wasm/pkg/ridb\_wasm.d.ts:503
***
@@ -88,7 +88,7 @@ The minimum length for string-type properties, if applicable.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:298
+ridb-wasm/pkg/ridb\_wasm.d.ts:513
***
@@ -100,7 +100,7 @@ The primary key of the property, if applicable.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:273
+ridb-wasm/pkg/ridb\_wasm.d.ts:488
***
@@ -116,7 +116,7 @@ An optional map of nested properties for object-type properties.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:313
+ridb-wasm/pkg/ridb\_wasm.d.ts:528
***
@@ -128,7 +128,7 @@ An optional array of required fields for object-type properties.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:303
+ridb-wasm/pkg/ridb\_wasm.d.ts:518
***
@@ -140,7 +140,7 @@ The type of the property.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:263
+ridb-wasm/pkg/ridb\_wasm.d.ts:478
***
@@ -152,4 +152,4 @@ The version of the property, if applicable.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:268
+ridb-wasm/pkg/ridb\_wasm.d.ts:483
diff --git a/packages/ridb/docs/classes/Query.md b/packages/ridb/docs/classes/Query.md
index 214d239..1756035 100644
--- a/packages/ridb/docs/classes/Query.md
+++ b/packages/ridb/docs/classes/Query.md
@@ -32,7 +32,7 @@
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:109
+ridb-wasm/pkg/ridb\_wasm.d.ts:168
## Properties
@@ -42,4 +42,4 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:109
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:110
+ridb-wasm/pkg/ridb\_wasm.d.ts:169
diff --git a/packages/ridb/docs/classes/RIDB.md b/packages/ridb/docs/classes/RIDB.md
index cc179dc..240bb84 100644
--- a/packages/ridb/docs/classes/RIDB.md
+++ b/packages/ridb/docs/classes/RIDB.md
@@ -30,7 +30,7 @@ Creates an instance of RIDB.
#### Defined in
-[packages/ridb/src/index.ts:184](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb/src/index.ts#L184)
+[ridb/src/index.ts:184](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb/src/index.ts#L184)
## Properties
@@ -40,7 +40,7 @@ Creates an instance of RIDB.
#### Defined in
-[packages/ridb/src/index.ts:177](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb/src/index.ts#L177)
+[ridb/src/index.ts:177](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb/src/index.ts#L177)
***
@@ -50,7 +50,7 @@ Creates an instance of RIDB.
#### Defined in
-[packages/ridb/src/index.ts:178](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb/src/index.ts#L178)
+[ridb/src/index.ts:178](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb/src/index.ts#L178)
***
@@ -60,7 +60,7 @@ Creates an instance of RIDB.
#### Defined in
-[packages/ridb/src/index.ts:175](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb/src/index.ts#L175)
+[ridb/src/index.ts:175](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb/src/index.ts#L175)
***
@@ -70,7 +70,7 @@ Creates an instance of RIDB.
#### Defined in
-[packages/ridb/src/index.ts:176](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb/src/index.ts#L176)
+[ridb/src/index.ts:176](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb/src/index.ts#L176)
***
@@ -80,7 +80,7 @@ Creates an instance of RIDB.
#### Defined in
-[packages/ridb/src/index.ts:174](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb/src/index.ts#L174)
+[ridb/src/index.ts:174](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb/src/index.ts#L174)
## Accessors
@@ -100,7 +100,7 @@ The collections object.
#### Defined in
-[packages/ridb/src/index.ts:232](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb/src/index.ts#L232)
+[ridb/src/index.ts:232](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb/src/index.ts#L232)
***
@@ -122,7 +122,7 @@ Will throw an error if the database is not started.
#### Defined in
-[packages/ridb/src/index.ts:217](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb/src/index.ts#L217)
+[ridb/src/index.ts:217](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb/src/index.ts#L217)
***
@@ -138,7 +138,7 @@ Will throw an error if the database is not started.
#### Defined in
-[packages/ridb/src/index.ts:224](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb/src/index.ts#L224)
+[ridb/src/index.ts:224](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb/src/index.ts#L224)
## Methods
@@ -152,7 +152,7 @@ Will throw an error if the database is not started.
#### Defined in
-[packages/ridb/src/index.ts:293](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb/src/index.ts#L293)
+[ridb/src/index.ts:292](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb/src/index.ts#L292)
***
@@ -176,7 +176,7 @@ Will throw an error if the database is not started.
#### Defined in
-[packages/ridb/src/index.ts:205](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb/src/index.ts#L205)
+[ridb/src/index.ts:205](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb/src/index.ts#L205)
***
@@ -200,7 +200,7 @@ A promise that resolves to the database instance.
#### Defined in
-[packages/ridb/src/index.ts:255](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb/src/index.ts#L255)
+[ridb/src/index.ts:255](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb/src/index.ts#L255)
***
@@ -218,4 +218,4 @@ A promise that resolves to the RIDB Rust module.
#### Defined in
-[packages/ridb/src/index.ts:241](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb/src/index.ts#L241)
+[ridb/src/index.ts:241](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb/src/index.ts#L241)
diff --git a/packages/ridb/docs/classes/Schema.md b/packages/ridb/docs/classes/Schema.md
index 7fd75b7..e910608 100644
--- a/packages/ridb/docs/classes/Schema.md
+++ b/packages/ridb/docs/classes/Schema.md
@@ -28,23 +28,25 @@ The schema type.
### encrypted?
-> `readonly` `optional` **encrypted**: `string`[]
+> `readonly` `optional` **encrypted**: `Extract`\[]
+
+An optional array of encrypted fields.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:497
+ridb-wasm/pkg/ridb\_wasm.d.ts:628
***
### indexes?
-> `readonly` `optional` **indexes**: `string`[]
+> `readonly` `optional` **indexes**: `Extract`\[]
An optional array of indexes.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:493
+ridb-wasm/pkg/ridb\_wasm.d.ts:623
***
@@ -56,7 +58,7 @@ The primary key of the schema.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:483
+ridb-wasm/pkg/ridb\_wasm.d.ts:610
***
@@ -68,17 +70,7 @@ The properties defined in the schema.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:502
-
-***
-
-### required?
-
-> `readonly` `optional` **required**: `string`[]
-
-#### Defined in
-
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:495
+ridb-wasm/pkg/ridb\_wasm.d.ts:633
***
@@ -90,7 +82,7 @@ The schema definition.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:464
+ridb-wasm/pkg/ridb\_wasm.d.ts:591
***
@@ -102,7 +94,7 @@ The type of the schema.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:488
+ridb-wasm/pkg/ridb\_wasm.d.ts:615
***
@@ -114,7 +106,7 @@ The version of the schema.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:478
+ridb-wasm/pkg/ridb\_wasm.d.ts:605
## Methods
@@ -132,7 +124,27 @@ The JSON representation of the schema.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:512
+ridb-wasm/pkg/ridb\_wasm.d.ts:643
+
+***
+
+### validate()
+
+> **validate**(`document`): `boolean`
+
+#### Parameters
+
+##### document
+
+[`Doc`](../type-aliases/Doc.md)\<[`Schema`](Schema.md)\<`T`\>\>
+
+#### Returns
+
+`boolean`
+
+#### Defined in
+
+ridb-wasm/pkg/ridb\_wasm.d.ts:645
***
@@ -162,4 +174,4 @@ The created `Schema` instance.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:473
+ridb-wasm/pkg/ridb\_wasm.d.ts:600
diff --git a/packages/ridb/docs/classes/StorageInternal.md b/packages/ridb/docs/classes/StorageInternal.md
index 5ef58bf..42f9446 100644
--- a/packages/ridb/docs/classes/StorageInternal.md
+++ b/packages/ridb/docs/classes/StorageInternal.md
@@ -36,7 +36,7 @@
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:645
+ridb-wasm/pkg/ridb\_wasm.d.ts:222
## Methods
@@ -50,7 +50,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:645
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:650
+ridb-wasm/pkg/ridb\_wasm.d.ts:227
***
@@ -74,7 +74,7 @@ keyof `Schemas`
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:651
+ridb-wasm/pkg/ridb\_wasm.d.ts:228
***
@@ -98,13 +98,13 @@ keyof `Schemas`
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:659
+ridb-wasm/pkg/ridb\_wasm.d.ts:236
***
### findDocumentById()
-> `abstract` **findDocumentById**(`collectionName`, `id`): `Promise`\<`null` \| [`Doc`](../type-aliases/Doc.md)\<`Schemas`\[keyof `Schemas`\]\>\>
+> `abstract` **findDocumentById**(`collectionName`, `id`): `Promise`\<`undefined` \| `null` \| [`Doc`](../type-aliases/Doc.md)\<`Schemas`\[keyof `Schemas`\]\>\>
#### Parameters
@@ -118,11 +118,11 @@ keyof `Schemas`
#### Returns
-`Promise`\<`null` \| [`Doc`](../type-aliases/Doc.md)\<`Schemas`\[keyof `Schemas`\]\>\>
+`Promise`\<`undefined` \| `null` \| [`Doc`](../type-aliases/Doc.md)\<`Schemas`\[keyof `Schemas`\]\>\>
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:655
+ridb-wasm/pkg/ridb\_wasm.d.ts:232
***
@@ -136,7 +136,7 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:655
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:649
+ridb-wasm/pkg/ridb\_wasm.d.ts:226
***
@@ -156,4 +156,4 @@ node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:649
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:663
+ridb-wasm/pkg/ridb\_wasm.d.ts:240
diff --git a/packages/ridb/docs/enumerations/OpType.md b/packages/ridb/docs/enumerations/OpType.md
index 34c2df0..72734e3 100644
--- a/packages/ridb/docs/enumerations/OpType.md
+++ b/packages/ridb/docs/enumerations/OpType.md
@@ -18,7 +18,7 @@ Count Operation.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:63
+ridb-wasm/pkg/ridb\_wasm.d.ts:63
***
@@ -30,7 +30,7 @@ Create operation.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:47
+ridb-wasm/pkg/ridb\_wasm.d.ts:47
***
@@ -42,7 +42,7 @@ Delete operation.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:55
+ridb-wasm/pkg/ridb\_wasm.d.ts:55
***
@@ -54,7 +54,7 @@ Query Operation.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:59
+ridb-wasm/pkg/ridb\_wasm.d.ts:59
***
@@ -66,4 +66,4 @@ Update operation.
#### Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:51
+ridb-wasm/pkg/ridb\_wasm.d.ts:51
diff --git a/packages/ridb/docs/enumerations/StorageType.md b/packages/ridb/docs/enumerations/StorageType.md
index ebe4081..2459b50 100644
--- a/packages/ridb/docs/enumerations/StorageType.md
+++ b/packages/ridb/docs/enumerations/StorageType.md
@@ -14,7 +14,7 @@
#### Defined in
-[packages/ridb/src/index.ts:123](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb/src/index.ts#L123)
+[ridb/src/index.ts:123](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb/src/index.ts#L123)
***
@@ -24,4 +24,4 @@
#### Defined in
-[packages/ridb/src/index.ts:122](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb/src/index.ts#L122)
+[ridb/src/index.ts:122](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb/src/index.ts#L122)
diff --git a/packages/ridb/docs/type-aliases/AnyVersionGreaterThan1.md b/packages/ridb/docs/type-aliases/AnyVersionGreaterThan1.md
index 1ec392a..8cb09a6 100644
--- a/packages/ridb/docs/type-aliases/AnyVersionGreaterThan1.md
+++ b/packages/ridb/docs/type-aliases/AnyVersionGreaterThan1.md
@@ -14,4 +14,4 @@
## Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:346
+ridb-wasm/pkg/ridb\_wasm.d.ts:115
diff --git a/packages/ridb/docs/type-aliases/BasePluginOptions.md b/packages/ridb/docs/type-aliases/BasePluginOptions.md
index 052df11..94f5840 100644
--- a/packages/ridb/docs/type-aliases/BasePluginOptions.md
+++ b/packages/ridb/docs/type-aliases/BasePluginOptions.md
@@ -20,4 +20,4 @@
## Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:625
+ridb-wasm/pkg/ridb\_wasm.d.ts:541
diff --git a/packages/ridb/docs/type-aliases/BaseStorageOptions.md b/packages/ridb/docs/type-aliases/BaseStorageOptions.md
index 74b0054..0d34f27 100644
--- a/packages/ridb/docs/type-aliases/BaseStorageOptions.md
+++ b/packages/ridb/docs/type-aliases/BaseStorageOptions.md
@@ -14,4 +14,4 @@
## Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:379
+ridb-wasm/pkg/ridb\_wasm.d.ts:175
diff --git a/packages/ridb/docs/type-aliases/CreateStorage.md b/packages/ridb/docs/type-aliases/CreateStorage.md
index a84d0a3..e90bc65 100644
--- a/packages/ridb/docs/type-aliases/CreateStorage.md
+++ b/packages/ridb/docs/type-aliases/CreateStorage.md
@@ -32,4 +32,4 @@ A promise that resolves to the created internals record.
## Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:602
+ridb-wasm/pkg/ridb\_wasm.d.ts:425
diff --git a/packages/ridb/docs/type-aliases/Doc.md b/packages/ridb/docs/type-aliases/Doc.md
index 06c30ab..80dbf65 100644
--- a/packages/ridb/docs/type-aliases/Doc.md
+++ b/packages/ridb/docs/type-aliases/Doc.md
@@ -6,7 +6,7 @@
# Type Alias: Doc\
-> **Doc**\<`T`\>: \{ \[K in keyof T\["properties"\] as T\["properties"\]\[K\]\["required"\] extends false \| (T\["properties"\]\[K\]\["default"\] extends undefined ? true : false) ? K : never\]?: ExtractType\ \} & `{ [K in keyof T["properties"] as T["properties"][K]["required"] extends false ? never : K]: ExtractType }` & `object`
+> **Doc**\<`T`\>: `{ [K in keyof T["properties"] as IsOptional extends true ? K : never]?: ExtractType }` & `{ [K in keyof T["properties"] as IsOptional extends false ? K : never]: ExtractType }` & `object`
Doc is a utility type that transforms a schema type into a document type where each property is mapped to its extracted type.
@@ -26,4 +26,4 @@ type Document = Doc; // Document is { name: string; age: number; }
## Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:145
+ridb-wasm/pkg/ridb\_wasm.d.ts:279
diff --git a/packages/ridb/docs/type-aliases/EnumerateFrom1To.md b/packages/ridb/docs/type-aliases/EnumerateFrom1To.md
index 27e2c6a..0d5ed1a 100644
--- a/packages/ridb/docs/type-aliases/EnumerateFrom1To.md
+++ b/packages/ridb/docs/type-aliases/EnumerateFrom1To.md
@@ -14,4 +14,4 @@
## Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:338
+ridb-wasm/pkg/ridb\_wasm.d.ts:107
diff --git a/packages/ridb/docs/type-aliases/EnumerateUpTo.md b/packages/ridb/docs/type-aliases/EnumerateUpTo.md
index c775d3b..053368b 100644
--- a/packages/ridb/docs/type-aliases/EnumerateUpTo.md
+++ b/packages/ridb/docs/type-aliases/EnumerateUpTo.md
@@ -16,4 +16,4 @@
## Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:331
+ridb-wasm/pkg/ridb\_wasm.d.ts:100
diff --git a/packages/ridb/docs/type-aliases/ExtractType.md b/packages/ridb/docs/type-aliases/ExtractType.md
index 55d8b25..7a64337 100644
--- a/packages/ridb/docs/type-aliases/ExtractType.md
+++ b/packages/ridb/docs/type-aliases/ExtractType.md
@@ -28,4 +28,4 @@ type ArrayType = ExtractType<'array'>; // ArrayType is Array
## Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:131
+ridb-wasm/pkg/ridb\_wasm.d.ts:261
diff --git a/packages/ridb/docs/type-aliases/Hook.md b/packages/ridb/docs/type-aliases/Hook.md
index f1c9fdb..7bf52b5 100644
--- a/packages/ridb/docs/type-aliases/Hook.md
+++ b/packages/ridb/docs/type-aliases/Hook.md
@@ -28,4 +28,4 @@
## Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:619
+ridb-wasm/pkg/ridb\_wasm.d.ts:535
diff --git a/packages/ridb/docs/type-aliases/InOperator.md b/packages/ridb/docs/type-aliases/InOperator.md
index 9375a15..e9844d4 100644
--- a/packages/ridb/docs/type-aliases/InOperator.md
+++ b/packages/ridb/docs/type-aliases/InOperator.md
@@ -20,4 +20,4 @@
## Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:95
+ridb-wasm/pkg/ridb\_wasm.d.ts:154
diff --git a/packages/ridb/docs/type-aliases/InternalsRecord.md b/packages/ridb/docs/type-aliases/InternalsRecord.md
index eb1962f..1228de3 100644
--- a/packages/ridb/docs/type-aliases/InternalsRecord.md
+++ b/packages/ridb/docs/type-aliases/InternalsRecord.md
@@ -14,4 +14,4 @@
## Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:116
+ridb-wasm/pkg/ridb\_wasm.d.ts:246
diff --git a/packages/ridb/docs/type-aliases/IsVersionGreaterThan0.md b/packages/ridb/docs/type-aliases/IsVersionGreaterThan0.md
index 2462aca..1c1aa83 100644
--- a/packages/ridb/docs/type-aliases/IsVersionGreaterThan0.md
+++ b/packages/ridb/docs/type-aliases/IsVersionGreaterThan0.md
@@ -14,4 +14,4 @@
## Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:342
+ridb-wasm/pkg/ridb\_wasm.d.ts:111
diff --git a/packages/ridb/docs/type-aliases/LogicalOperators.md b/packages/ridb/docs/type-aliases/LogicalOperators.md
index 4d27c91..789cbf1 100644
--- a/packages/ridb/docs/type-aliases/LogicalOperators.md
+++ b/packages/ridb/docs/type-aliases/LogicalOperators.md
@@ -24,4 +24,4 @@
## Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:97
+ridb-wasm/pkg/ridb\_wasm.d.ts:156
diff --git a/packages/ridb/docs/type-aliases/MigrationFunction.md b/packages/ridb/docs/type-aliases/MigrationFunction.md
index eb5337d..9c8fa34 100644
--- a/packages/ridb/docs/type-aliases/MigrationFunction.md
+++ b/packages/ridb/docs/type-aliases/MigrationFunction.md
@@ -24,4 +24,4 @@
## Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:352
+ridb-wasm/pkg/ridb\_wasm.d.ts:121
diff --git a/packages/ridb/docs/type-aliases/MigrationPathsForSchema.md b/packages/ridb/docs/type-aliases/MigrationPathsForSchema.md
index 842829b..31fe561 100644
--- a/packages/ridb/docs/type-aliases/MigrationPathsForSchema.md
+++ b/packages/ridb/docs/type-aliases/MigrationPathsForSchema.md
@@ -14,4 +14,4 @@
## Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:354
+ridb-wasm/pkg/ridb\_wasm.d.ts:123
diff --git a/packages/ridb/docs/type-aliases/MigrationPathsForSchemas.md b/packages/ridb/docs/type-aliases/MigrationPathsForSchemas.md
index 321f14d..d80b7ef 100644
--- a/packages/ridb/docs/type-aliases/MigrationPathsForSchemas.md
+++ b/packages/ridb/docs/type-aliases/MigrationPathsForSchemas.md
@@ -14,4 +14,4 @@
## Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:361
+ridb-wasm/pkg/ridb\_wasm.d.ts:130
diff --git a/packages/ridb/docs/type-aliases/MigrationsParameter.md b/packages/ridb/docs/type-aliases/MigrationsParameter.md
index 345c8f5..34eba71 100644
--- a/packages/ridb/docs/type-aliases/MigrationsParameter.md
+++ b/packages/ridb/docs/type-aliases/MigrationsParameter.md
@@ -14,4 +14,4 @@
## Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:367
+ridb-wasm/pkg/ridb\_wasm.d.ts:136
diff --git a/packages/ridb/docs/type-aliases/Operation.md b/packages/ridb/docs/type-aliases/Operation.md
index dbba047..4ae3d16 100644
--- a/packages/ridb/docs/type-aliases/Operation.md
+++ b/packages/ridb/docs/type-aliases/Operation.md
@@ -44,4 +44,4 @@ The type of operation to be performed (e.g., CREATE, UPDATE, DELETE).
## Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:232
+ridb-wasm/pkg/ridb\_wasm.d.ts:447
diff --git a/packages/ridb/docs/type-aliases/OperatorOrType.md b/packages/ridb/docs/type-aliases/OperatorOrType.md
index 459b8ad..59ac64a 100644
--- a/packages/ridb/docs/type-aliases/OperatorOrType.md
+++ b/packages/ridb/docs/type-aliases/OperatorOrType.md
@@ -14,4 +14,4 @@
## Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:96
+ridb-wasm/pkg/ridb\_wasm.d.ts:155
diff --git a/packages/ridb/docs/type-aliases/Operators.md b/packages/ridb/docs/type-aliases/Operators.md
index 5840769..0f61cd4 100644
--- a/packages/ridb/docs/type-aliases/Operators.md
+++ b/packages/ridb/docs/type-aliases/Operators.md
@@ -28,4 +28,4 @@
## Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:89
+ridb-wasm/pkg/ridb\_wasm.d.ts:148
diff --git a/packages/ridb/docs/type-aliases/QueryType.md b/packages/ridb/docs/type-aliases/QueryType.md
index ba572ad..bc78b55 100644
--- a/packages/ridb/docs/type-aliases/QueryType.md
+++ b/packages/ridb/docs/type-aliases/QueryType.md
@@ -14,4 +14,4 @@
## Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:101
+ridb-wasm/pkg/ridb\_wasm.d.ts:160
diff --git a/packages/ridb/docs/type-aliases/RIDBModule.md b/packages/ridb/docs/type-aliases/RIDBModule.md
index a6384db..10c7807 100644
--- a/packages/ridb/docs/type-aliases/RIDBModule.md
+++ b/packages/ridb/docs/type-aliases/RIDBModule.md
@@ -30,4 +30,4 @@ Plugin constructors array
## Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:609
+ridb-wasm/pkg/ridb\_wasm.d.ts:432
diff --git a/packages/ridb/docs/type-aliases/SchemaType.md b/packages/ridb/docs/type-aliases/SchemaType.md
index e37d3ce..e14a550 100644
--- a/packages/ridb/docs/type-aliases/SchemaType.md
+++ b/packages/ridb/docs/type-aliases/SchemaType.md
@@ -14,23 +14,21 @@ Represents the type definition for a schema.
### encrypted?
-> `readonly` `optional` **encrypted**: `string`[]
+> `optional` **encrypted**: `string`[]
### indexes?
-> `readonly` `optional` **indexes**: `string`[]
-
-An optional array of indexes.
+> `optional` **indexes**: `string`[]
### primaryKey
-> `readonly` **primaryKey**: `string`
+> **primaryKey**: `string`
The primary key of the schema.
### properties
-> `readonly` **properties**: `object`
+> **properties**: `object`
The properties defined in the schema.
@@ -38,24 +36,18 @@ The properties defined in the schema.
\[`name`: `string`\]: [`Property`](../classes/Property.md)
-### required?
-
-> `readonly` `optional` **required**: `string`[]
-
-An optional array of required fields.
-
### type
-> `readonly` **type**: `string`
+> **type**: `string`
The type of the schema.
### version
-> `readonly` **version**: `number`
+> **version**: `number`
The version of the schema.
## Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:421
+ridb-wasm/pkg/ridb\_wasm.d.ts:556
diff --git a/packages/ridb/docs/type-aliases/SchemaTypeRecord.md b/packages/ridb/docs/type-aliases/SchemaTypeRecord.md
index 2ea14ff..9164f23 100644
--- a/packages/ridb/docs/type-aliases/SchemaTypeRecord.md
+++ b/packages/ridb/docs/type-aliases/SchemaTypeRecord.md
@@ -16,4 +16,4 @@ Represents a record of schema types, where each key is a string and the value is
## Defined in
-node\_modules/@trust0/ridb-wasm/ridb\_wasm.d.ts:640
+ridb-wasm/pkg/ridb\_wasm.d.ts:217
diff --git a/packages/ridb/docs/type-aliases/StartOptions.md b/packages/ridb/docs/type-aliases/StartOptions.md
index f0c67ad..67f2b62 100644
--- a/packages/ridb/docs/type-aliases/StartOptions.md
+++ b/packages/ridb/docs/type-aliases/StartOptions.md
@@ -28,4 +28,4 @@
## Defined in
-[packages/ridb/src/index.ts:126](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb/src/index.ts#L126)
+[ridb/src/index.ts:126](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb/src/index.ts#L126)
diff --git a/packages/ridb/docs/variables/SchemaFieldType.md b/packages/ridb/docs/variables/SchemaFieldType.md
index c8d1c78..085c1c0 100644
--- a/packages/ridb/docs/variables/SchemaFieldType.md
+++ b/packages/ridb/docs/variables/SchemaFieldType.md
@@ -34,4 +34,4 @@ An enumeration of schema field types.
## Defined in
-[packages/ridb/src/index.ts:304](https://github.com/elribonazo/RIDB/blob/56953e7daf1db67092f8732dd6adee955f103a76/packages/ridb/src/index.ts#L304)
+[ridb/src/index.ts:302](https://github.com/elribonazo/RIDB/blob/04c29d6492c780dacdbe8ba762df162b604656ba/packages/ridb/src/index.ts#L302)
diff --git a/packages/testing/src/test/schemas.test.ts b/packages/testing/src/test/schemas.test.ts
index 577113a..7b9a0a8 100644
--- a/packages/testing/src/test/schemas.test.ts
+++ b/packages/testing/src/test/schemas.test.ts
@@ -576,7 +576,304 @@ export default (platform: string, storages: StoragesType[]) => {
expect(created.__version).to.eq(1);
})
- })
- })
+ it('Should handle array types in schema', async () => {
+ const db = new RIDB({
+ dbName: "test" + uuidv4(),
+ schemas: {
+ demo: {
+ version: 0,
+ primaryKey: 'id',
+ type: SchemaFieldType.object,
+ properties: {
+ id: { type: SchemaFieldType.string },
+ tags: {
+ type: SchemaFieldType.array,
+ items: { type: SchemaFieldType.string }
+ }
+ }
+ }
+ } as const
+ });
+ await db.start({
+ storageType: storage,
+ password: "test"
+ });
+ const created = await db.collections.demo.create({
+ id: "12345",
+ tags: ["tag1", "tag2"]
+ });
+ expect(created).to.not.be.undefined;
+ expect(created.tags).to.deep.equal(["tag1", "tag2"]);
+ });
+
+ it('Should handle nested object properties', async () => {
+ const db = new RIDB({
+ dbName: "test" + uuidv4(),
+ schemas: {
+ demo: {
+ version: 0,
+ primaryKey: 'id',
+ type: SchemaFieldType.object,
+ properties: {
+ id: { type: SchemaFieldType.string },
+ profile: {
+ type: SchemaFieldType.object,
+ properties: {
+ firstName: { type: SchemaFieldType.string },
+ lastName: { type: SchemaFieldType.string }
+ }
+ }
+ }
+ }
+ } as const
+ });
+ await db.start({
+ storageType: storage,
+ password: "test"
+ });
+ const created = await db.collections.demo.create({
+ id: "12345",
+ profile: {
+ firstName: "John",
+ lastName: "Doe"
+ }
+ });
+ expect(created).to.not.be.undefined;
+ expect(created.profile).to.deep.equal({
+ firstName: "John",
+ lastName: "Doe"
+ });
+ });
+
+ it('Should throw error when required property is missing', async () => {
+ const db = new RIDB({
+ dbName: "test" + uuidv4(),
+ schemas: {
+ demo: {
+ version: 0,
+ primaryKey: 'id',
+ type: SchemaFieldType.object,
+ properties: {
+ id: { type: SchemaFieldType.string },
+ name: { type: SchemaFieldType.string }
+ }
+ }
+ } as const
+ });
+ await db.start({
+ storageType: storage,
+ password: "test"
+ });
+ await expect(db.collections.demo.create({
+ id: "missing_property_12345"
+ } as any)).rejects.toThrowError("Validation Error: Missing required property 'name'");
+ });
+
+ it('Should support boolean types in schema', async () => {
+ const db = new RIDB({
+ dbName: "test" + uuidv4(),
+ schemas: {
+ demo: {
+ version: 0,
+ primaryKey: 'id',
+ type: SchemaFieldType.object,
+ properties: {
+ id: { type: SchemaFieldType.string },
+ isActive: { type: SchemaFieldType.boolean }
+ }
+ }
+ } as const
+ });
+ await db.start({
+ storageType: storage,
+ password: "test"
+ });
+ const created = await db.collections.demo.create({
+ id: "12345",
+ isActive: true
+ });
+ expect(created).to.not.be.undefined;
+ expect(created.isActive).to.be.true;
+ });
+
+ it('Should apply default values when creating documents', async () => {
+ const db = new RIDB({
+ dbName: "test" + uuidv4(),
+ schemas: {
+ demo: {
+ version: 0,
+ primaryKey: 'id',
+ type: SchemaFieldType.object,
+ properties: {
+ id: { type: SchemaFieldType.string },
+ status: { type: SchemaFieldType.string, default: 'active' }
+ }
+ }
+ } as const
+ });
+ await db.start({
+ storageType: storage,
+ password: "test"
+ });
+ const created = await db.collections.demo.create({
+ id: "12345"
+ });
+ expect(created).to.not.be.undefined;
+ expect(created.status).to.equal('active');
+ });
+
+ it('Should handle updates without affecting unspecified fields', async () => {
+ const db = new RIDB({
+ dbName: "test" + uuidv4(),
+ schemas: {
+ demo: {
+ version: 0,
+ primaryKey: 'id',
+ type: SchemaFieldType.object,
+ properties: {
+ id: { type: SchemaFieldType.string },
+ name: { type: SchemaFieldType.string },
+ age: { type: SchemaFieldType.number }
+ }
+ }
+ } as const
+ });
+ await db.start({
+ storageType: storage,
+ password: "test"
+ });
+ await db.collections.demo.create({
+ id: "12345",
+ name: "Alice",
+ age: 30
+ });
+ await db.collections.demo.update({
+ id: "12345",
+ name: "Bob"
+ });
+ const updated = await db.collections.demo.findById("12345");
+ expect(updated).to.not.be.undefined;
+ expect(updated?.name).to.equal("Bob");
+ expect(updated?.age).to.equal(30);
+ });
+
+ it('Should validate maxItems constraint on arrays', async () => {
+ const db = new RIDB({
+ dbName: "test" + uuidv4(),
+ schemas: {
+ demo: {
+ version: 0,
+ primaryKey: 'id',
+ type: SchemaFieldType.object,
+ properties: {
+ id: { type: SchemaFieldType.string },
+ tags: {
+ type: SchemaFieldType.array,
+ items: { type: SchemaFieldType.string, maxItems: 1 },
+ maxItems: 2
+ }
+ }
+ }
+ } as const
+ });
+ await db.start({
+ storageType: storage,
+ password: "test"
+ });
+ await expect(db.collections.demo.create({
+ id: "12345",
+ tags: ["tag1", "tag2", "tag3"]
+ })).rejects.toThrowError("Validation Error: Property 'tags' exceeds maximum items of '2'");
+ });
+
+ it('Should handle deletion of documents', async () => {
+ const db = new RIDB({
+ dbName: "test" + uuidv4(),
+ schemas: {
+ demo: {
+ version: 0,
+ primaryKey: 'id',
+ type: SchemaFieldType.object,
+ properties: {
+ id: { type: SchemaFieldType.string },
+ data: { type: SchemaFieldType.string }
+ }
+ }
+ } as const
+ });
+ await db.start({
+ storageType: storage,
+ password: "test"
+ });
+ await db.collections.demo.create({
+ id: "12345",
+ data: "Sample data"
+ });
+ await db.collections.demo.delete("12345");
+ const found = await db.collections.demo.findById("12345");
+ expect(found).to.be.undefined;
+ });
+
+ it('Should enforce maxLength on string properties', async () => {
+ const db = new RIDB({
+ dbName: "test" + uuidv4(),
+ schemas: {
+ demo: {
+ version: 0,
+ primaryKey: 'id',
+ type: SchemaFieldType.object,
+ properties: {
+ id: {
+ type: SchemaFieldType.string,
+ maxLength: 5
+ }
+ }
+ }
+ } as const
+ });
+ await db.start({
+ storageType: storage,
+ password: "test"
+ });
+ await expect(db.collections.demo.create({
+ id: "213123123123"
+ })).rejects.toThrowError("Validation Error: Property 'id' exceeds maximum length of '5'");
+ });
+
+ it('Should handle querying with complex conditions', async () => {
+ const db = new RIDB({
+ dbName: "test" + uuidv4(),
+ schemas: {
+ users: {
+ version: 0,
+ primaryKey: 'id',
+ type: SchemaFieldType.object,
+ properties: {
+ id: { type: SchemaFieldType.string },
+ age: { type: SchemaFieldType.number },
+ isActive: { type: SchemaFieldType.boolean }
+ }
+ }
+ } as const
+ });
+ await db.start({
+ storageType: storage,
+ password: "test"
+ });
+ await db.collections.users.create({ id: 'u1', age: 25, isActive: true });
+ await db.collections.users.create({ id: 'u2', age: 30, isActive: false });
+ await db.collections.users.create({ id: 'u3', age: 35, isActive: true });
+
+ const results = await db.collections.users.find({
+ $and: [
+ { age: { $gte: 30 } },
+ { isActive: true }
+ ]
+ });
+ expect(results.length).to.equal(1);
+ expect(results[0].id).to.equal('u3');
+ });
+ });
+ });
});
}
\ No newline at end of file