Gathering detailed insights and metrics for @medyll/idae-api
Gathering detailed insights and metrics for @medyll/idae-api
Gathering detailed insights and metrics for @medyll/idae-api
Gathering detailed insights and metrics for @medyll/idae-api
npm install @medyll/idae-api
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
30
A flexible and extensible Node.js API, based on the @medyll/idae-db library, allowing you to manage multiple types of databases (MongoDB, MySQL, etc.) and providing a complete TypeScript client to interact with your endpoints.
@medyll/idae-api
is a modular Node.js API framework designed to work with multiple database types thanks to the @medyll/idae-db library. It offers:
$in
, $gt
, $set
, etc.), making it intuitive for developers familiar with MongoDB.1npm install @medyll/idae-api 2 3npm install @medyll/idae-api --latest # to install the latest version 4npm install @medyll/idae-api --next # for the next version (if available) 5
1import { idaeApi } from '@medyll/idae-api'; 2 3idaeApi.setOptions({ 4 port: 3000, 5 enableAuth: true, // or false 6 jwtSecret: 'your-secret-key', 7 tokenExpiration: '1h', 8 routes: customRoutes // optional 9}); 10 11idaeApi.start();
1const customRoutes = [ 2 { 3 method: 'get', 4 path: '/custom/hello', 5 handler: async () => ({ message: 'Hello from custom route!' }), 6 requiresAuth: false 7 } 8]; 9 10idaeApi.router.addRoutes(customRoutes);
idae-api
relies on @medyll/idae-db
for connection and database operation management. You can:
DatabaseAdapter
interface in idae-db)An error handling middleware is included. You can customize it via the configureErrorHandling
method in the IdaeApi
class.
1import { IdaeApiClientConfig } from '@medyll/idae-api'; 2 3IdaeApiClientConfig.setOptions({ 4 host: 'localhost', 5 port: 3000, 6 method: 'http', 7 defaultDb: 'idae_base', 8 separator: '//' 9});
1import { IdaeApiClient } from '@medyll/idae-api'; 2 3const client = new IdaeApiClient();
getDbList()
: List available databasesgetCollections(dbName)
: List collections in a databasedb(dbName)
: Select a database (returns an object with collection
and getCollections
)collection(collectionName, dbName?)
: Select a collection (optionally in a given database)You can register hooks on all operations:
1const usersCollection = client.collection('user'); 2 3usersCollection.registerEvents({ 4 findById: { 5 pre: (id) => console.log(`Before searching for ID: ${id}`), 6 post: (result, id) => console.log(`Result for ${id}:`, result), 7 error: (error) => console.error('Error on findById:', error) 8 }, 9 // ... same for update, create, etc. 10}); 11 12#### CRUD Operations on a Collection 13 14All the following methods are available via the `IdaeApiClientCollection` object: 15 16- `findAll(params?)` : List all documents (with filters, sorting, pagination) 17- `findById(id)` : Get a document by its ID 18- `findOne(params)` : Get a document by a filter (inherited from idae-db) 19- `create(body)` : Create a document 20- `update(id, body)` : Update a document 21- `deleteById(id)` : Delete a document by its ID 22- `deleteManyByQuery(params)` : Delete multiple documents by filter 23 24#
All query and update operations use a syntax very close to MongoDB. For example, you can use operators like $in
, $gt
, $set
, etc. in your queries and updates.
1const dbList = await client.getDbList(); 2console.log('Databases:', dbList);
1const collections = await client.getCollections('idae_base'); 2console.log('Collections:', collections);
1const userCollection = client.db('app').collection('user'); 2const users = await userCollection.find({ 3 email: { $in: ["Karin@example.com", "Test@Value"] }, 4 age: 31, 5}); 6console.log(users);
1const newUser = await userCollection.create({ 2 name: "new user", 3 email: "Test@Value", 4}); 5console.log(newUser);
1const allDocs = await userCollection.findAll(); 2console.log(allDocs);
1const foundDoc = await userCollection.findById(newUser._id); 2console.log(foundDoc);
1const updatedDoc = await userCollection.update(newUser._id, { 2 $set: { value: "Updated Value" }, 3}); 4console.log(updatedDoc);
1const deleteResult = await userCollection.deleteById(newUser._id); 2console.log(deleteResult);
1const appSchemeCollection = client.db('idae_base').collection('appscheme'); 2const docs = await appSchemeCollection.findAll(); 3console.log(docs);
1const deleteResult2 = await client 2 .collection('appscheme_base') 3 .deleteManyByQuery({ testField: 'testValue' }); 4console.log(deleteResult2);
1const usersCollection = client.collection('user'); 2 3usersCollection.registerEvents({ 4 findById: { 5 pre: (id) => console.log(`Before searching for ID: ${id}`), 6 post: (result, id) => console.log(`Result for ${id}:`, result), 7 error: (error) => console.error('Error on findById:', error) 8 }, 9 // ... same for update, create, etc. 10});
find(params)
: Advanced search (filters, sorting, pagination)findOne(params)
: Find a single document by filterfindById(id)
: Find by IDcreate(data)
: Createupdate(id, data)
: UpdatedeleteById(id)
: Delete by IDdeleteManyByQuery(params)
: Bulk deleteregisterEvents(events)
: Register hooks (pre/post/error) on each methodcloseAllConnections()
: Close all active connectionsRequestParams
: Record<string, unknown>
HttpMethod
: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
RouteNamespace
: methods/${'dbs' | 'collections'}
UrlParams
: { dbName?: string; collectionName?: string; slug?: string; params?: Record<string, string>; routeNamespace?: RouteNamespace }
RequestOptions<T>
: UrlParams & { baseUrl?: string; method?: HttpMethod; body?: T; headers?: RequestInit['headers'] }
Contributions are welcome! Feel free to submit a Pull Request.
This project is licensed under the MIT License.
No vulnerabilities found.
No security vulnerabilities found.