fix(core): update

This commit is contained in:
Philipp Kunz 2024-04-14 04:00:56 +02:00
parent b4cd6b0fe1
commit 06776d74c8
5 changed files with 104 additions and 123 deletions

View File

@ -15,9 +15,19 @@
"githost": "code.foss.global", "githost": "code.foss.global",
"gitscope": "push.rocks", "gitscope": "push.rocks",
"gitrepo": "smartdata", "gitrepo": "smartdata",
"description": "do more with data", "description": "An advanced library for NoSQL data organization and manipulation using TypeScript with support for MongoDB, data validation, collections, and custom data types.",
"npmPackagename": "@push.rocks/smartdata", "npmPackagename": "@push.rocks/smartdata",
"license": "MIT" "license": "MIT",
"keywords": [
"data manipulation",
"NoSQL",
"MongoDB",
"TypeScript",
"data validation",
"collections",
"custom data types",
"ODM"
]
} }
}, },
"tsdoc": { "tsdoc": {

View File

@ -2,7 +2,7 @@
"name": "@push.rocks/smartdata", "name": "@push.rocks/smartdata",
"version": "5.1.0", "version": "5.1.0",
"private": false, "private": false,
"description": "do more with data", "description": "An advanced library for NoSQL data organization and manipulation using TypeScript with support for MongoDB, data validation, collections, and custom data types.",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",
"type": "module", "type": "module",
@ -57,5 +57,15 @@
], ],
"browserslist": [ "browserslist": [
"last 1 chrome versions" "last 1 chrome versions"
],
"keywords": [
"data manipulation",
"NoSQL",
"MongoDB",
"TypeScript",
"data validation",
"collections",
"custom data types",
"ODM"
] ]
} }

0
readme.hints.md Normal file
View File

195
readme.md
View File

@ -1,154 +1,115 @@
# @push.rocks/smartdata # @push.rocks/smartdata
do more with data do more with data
## Availabililty and Links ## Install
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartdata) To install `@push.rocks/smartdata`, use npm:
* [gitlab.com (source)](https://gitlab.com/push.rocks/smartdata)
* [github.com (source mirror)](https://github.com/push.rocks/smartdata)
* [docs (typedoc)](https://push.rocks.gitlab.io/smartdata/)
## Status for master ```bash
npm install @push.rocks/smartdata --save
```
Status Category | Status Badge This will add `@push.rocks/smartdata` to your project's dependencies.
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/push.rocks/smartdata/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/push.rocks/smartdata/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@push.rocks/smartdata)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/push.rocks/smartdata)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@push.rocks/smartdata)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@push.rocks/smartdata)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@push.rocks/smartdata)](https://lossless.cloud)
## Usage ## Usage
`@push.rocks/smartdata` enables efficient data handling and operation management with a focus on using MongoDB. It leverages TypeScript for strong typing and ESM syntax for modern JavaScript usage. Below are various scenarios demonstrating how to utilize this package effectively in a project.
Use TypeScript for best in class instellisense. ### Setting Up and Connecting to the Database
Before interacting with the database, you need to set up and establish a connection. This is done by creating an instance of `SmartdataDb` and calling its `init` method with your MongoDB connection details.
smartdata is an ODM that adheres to TypeScript practices and uses classes to organize data.
It uses RethinkDB as persistent storage.
## Intention
There are many ODMs out there, however when we searched for an ODM that uses TypeScript,
acts smart while still embracing the NoSQL idea we didn't find a matching solution.
This is why we started smartdata.
How RethinkDB's terms map to the ones of smartdata:
| MongoDb term | smartdata class |
| ------------ | ----------------------------- |
| Database | smartdata.SmartdataDb |
| Collection | smartdata.SmartdataCollection |
| Document | smartdata.SmartadataDoc |
### class Db
represents a Database. Naturally it has .connect() etc. methods on it.
```typescript ```typescript
// Assuming toplevel await import { SmartdataDb } from '@push.rocks/smartdata';
import * as smartdata from 'smartdata';
const smartdataDb = new smartdata.SmartdataDb({ // Create a new instance of SmartdataDb with MongoDB connection details
mongoDbUrl: '//someurl', const db = new SmartdataDb({
mongoDbName: 'myDatabase', mongoDbUrl: 'mongodb://localhost:27017',
mongoDbPass: 'mypassword', mongoDbName: 'your-database-name',
mongoDbUser: 'your-username',
mongoDbPass: 'your-password',
}); });
await smartdataDb.connect(); // Initialize and connect to the database
await db.init();
``` ```
### class DbCollection ### Defining Data Models
Data models in `@push.rocks/smartdata` are classes that represent collections and documents in your MongoDB database. Use decorators such as `@Collection`, `@unI`, and `@svDb` to define your data models.
represents a collection of objects.
A collection is defined by the object class (that is extending smartdata.dbdoc) it respresents
So to get to get access to a specific collection you document
```typescript ```typescript
// Assuming toplevel await import { SmartDataDbDoc, Collection, unI, svDb } from '@push.rocks/smartdata';
// continues from the block before...
@smartdata.Collection(smartdataDb) @Collection(() => db) // Associate this model with the database instance
class MyObject extends smartdata.DbDoc<MyObject /* ,[an optional interface to implement] */> { class User extends SmartDataDbDoc<User, User> {
// read the next block about DbDoc @unI()
@smartdata.svDb() public id: string = 'unique-user-id'; // Mark 'id' as a unique index
property1: string; // @smartdata.svDb() marks the property for db save
@svDb()
property2: number; // this one is not marked, so it won't be save upon calling this.save() public username: string; // Mark 'username' to be saved in DB
constructor() { @svDb()
super(); // the super call is important ;) But you probably know that. public email: string; // Mark 'email' to be saved in DB
constructor(username: string, email: string) {
super();
this.username = username;
this.email = email;
} }
} }
// start to instantiate instances of classes from scratch or database
const localObject = new MyObject({
property1: 'hi',
property2: {
deep: 3,
},
});
await localObject.save(); // saves the object to the database
// start retrieving instances
// .getInstance is staticly inheritied, yet fully typed static function to get instances with fully typed filters
const myInstance = await MyObject.getInstance({
property1: 'hi',
property2: {
deep: {
$gt: 2,
} as any,
},
}); // outputs a new instance of MyObject with the values from db assigned
``` ```
### class DbDoc ### Performing CRUD Operations
`@push.rocks/smartdata` simplifies CRUD operations with intuitive methods on model instances.
represents a individual document in a collection #### Create
and thereby is ideally suited to extend the class you want to actually store. ```typescript
const newUser = new User('myUsername', 'myEmail@example.com');
await newUser.save(); // Save the new user to the database
```
### CRUD operations #### Read
```typescript
// Fetch a single user by a unique attribute
const user = await User.getInstance({ username: 'myUsername' });
smartdata supports full CRUD operations // Fetch multiple users that match criteria
const users = await User.getInstances({ email: 'myEmail@example.com' });
```
**Store** or **Update** instances of classes to MongoDB: #### Update
DbDoc extends your class with the following methods: ```typescript
// Assuming 'user' is an instance of User
user.email = 'newEmail@example.com';
await user.save(); // Update the user in the database
```
- async `.save()` will save (or update) the object you call it on only. Any referenced non-savable objects will not get stored. #### Delete
- async `.saveDeep()` does the same like `.save()`. ```typescript
In addition it will look for properties that reference an object // Assuming 'user' is an instance of User
that extends DbDoc as well and call .saveDeep() on them as well. await user.delete(); // Delete the user from the database
Loops are prevented ```
**Get** a new class instance from MongoDB: ### Advanced Usage
DbDoc exposes a static method that allows you specify a filter to retrieve a cloned class of the one you used to that doc at some point later in time: `@push.rocks/smartdata` also supports advanced features like watching for real-time changes in the database, handling distributed data coordination, and more. These features utilize MongoDB's capabilities to provide real-time data syncing and distributed systems coordination.
- static async `.getInstance({ /* filter props here */ })` gets you an instance that has the data of the first matched document as properties. ### Conclusion
- static async `getInstances({ /* filter props here */ })` get you an array instances (one instance for every matched document). With its focus on TypeScript, modern JavaScript syntax, and leveraging MongoDB's features, `@push.rocks/smartdata` offers a powerful toolkit for data handling and operations management in Node.js applications. Its design for ease of use, coupled with advanced features, makes it a versatile choice for developers looking to build efficient and scalable data-driven applications.
**Delete** instances from MongoDb: For more details on usage and additional features, refer to the [official documentation](https://gitlab.com/push.rocks/smartdata#README) and explore the various classes and methods provided by `@push.rocks/smartdata`.
smartdata extends your class with a method to easily delete the doucment from DB:
- async `.delete()`will delete the document from DB. ## License and Legal Information
## TypeScript This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
How does TypeScript play into this? **Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
Since you define your classes in TypeScript and types flow through smartdata in a generic way
you should get all the Intellisense and type checking you love when using smartdata.
smartdata itself also bundles typings. You don't need to install any additional types for smartdata.
## Contribution ### Trademarks
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :) This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
For further information read the linked docs at the top of this readme. ### Company Information
## Legal Task Venture Capital GmbH
> MIT licensed | **&copy;** [Task Venture Capital GmbH](https://task.vc) Registered at District court Bremen HRB 35230 HB, Germany
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartdata', name: '@push.rocks/smartdata',
version: '5.1.0', version: '5.1.1',
description: 'do more with data' description: 'An advanced library for NoSQL data organization and manipulation using TypeScript with support for MongoDB, data validation, collections, and custom data types.'
} }