This feature mostly already exists in v0.4.4. This issue is for tracking progress for this feature in the TypeScript rewrite of this package.
Tests to confirm this feature should be:
Golden Path Tests
[x] Database-based document instances...
[x] Can be created by a database client ".createOne()" method
All other document creation methods on a client typically use ".createOne()" internally, so this is key!
[x] Must contain appropriate properties such as database name and collection name
[x] A database client should successfully .create() a document instance per the Document's structure, where all data provided to create the document is valid.
[x] A database client should successfully .create() a document instance per the Document's structure, where any field that was not provided a value but has a default rule should create with the default data.
[x] A database client should successfully .create() per the Document's structure, where a field that has a type of another Document should store only the Document ID in its database entry.
[x] A Document instance should be able to .save() its data.
eg. Find a document to get a document instance. Then edit the document instance. Then save the document instance.
This is exclusive to Documents, not Embedded Documents. Saving a Document will save its Embedded Documents too though!
[x] A Document instance can .delete() itself, because the instance should know which collection and database it lives in. This has options:
[x] deleteReferences: boolean, delete all top-level referenced documents from any fields that are reference IDs as well.
deepDelete: boolean, delete all top-level and nested-level referenced documents from any fields that are reference IDs as well.
Not implementing this test (deepDelete) because it seems a bit needless. If it doesn't work, it can be reported by users - a workaround is to just get users to manually retrieve referenced document IDs and call delete... because that's exactly what deepDelete does internally.
[x] Databaseless document instances...
[x] Can be created using a constructor
[x] Validation does NOT occur on constructor-made document instances
[x] Can be validated by calling the instance method "validate"
[x] Some validation rules (eg. unique) get skipped or ignored in this process
[x] Cannot have a value provided for any document reference properties.
No database known on a databaseless document instance means that references would never work!
Regardless of database or databaseless...
[x] Custom model classes inheriting from NedbDocument to be compatible with the rest of the tests
[x] A Document that inherits from another Document-based class should adhere to all fields/rules/constraints/etc defined in the parent class.
[x] A Document that inherits from another Document-based class should be able to override all fields/rules/constraints/etc defined in the parent class.
[x] A Document instance method can return a JSON representation of the Document instance's data.
[x] A Document instance method can return a JSON representation of the Document instance's data, including populated data from referenced documents.
Error-Handling Tests
[x] A Document should throw an error when creating data where the Document fields are not meeting their defined required constraint.
[x] A Document should throw an error when creating data where the Document fields are not meeting their defined unique constraint.
[x] A Document should throw an error when creating data where the Document fields are not meeting their defined type constraint.
[x] A Document should throw an error when creating data where the Document fields are not meeting their defined min constraint.
[x] A Document should throw an error when creating data where the Document fields are not meeting their defined max constraint.
[x] A Document should throw an error when creating data where the Document fields are not meeting their defined choices constraint.
[x] A Document should throw an error when creating data where the Document fields are not meeting their defined validate constraint.
This feature mostly already exists in v0.4.4. This issue is for tracking progress for this feature in the TypeScript rewrite of this package.
Tests to confirm this feature should be:
Golden Path Tests
[x] Database-based document instances...
.create()
a document instance per the Document's structure, where all data provided to create the document is valid..create()
a document instance per the Document's structure, where any field that was not provided a value but has a default rule should create with the default data..create()
per the Document's structure, where a field that has a type of another Document should store only the Document ID in its database entry..save()
its data.delete()
itself, because the instance should know which collection and database it lives in. This has options:[x] Databaseless document instances...
Regardless of database or databaseless...
Error-Handling Tests