Egose Documentation

website·Indexed 30 days ago

https://egose.github.io/

Documentation for the Egose ecosystem, including egose-acl for access control and CRUD lifecycle management, egose-adapter-js for model service interactions, and egose-swagger and egose-deco for backend configuration and installation.

Tokens
20.2K
Snippets
115
Records
145
Agent score
75%

What's inside Egose

  1. Overview of @egose/acl for Express and Mongoose

    @egose/acl is a package that provides REST API endpoints for Mongoose data models in Express routes. It secures backend databases by decorating Mongoose queries with access control lists (ACLs) to restrict access to sensitive data. It also supports dynamic, Mongoose-like query options from the frontend, allowing developers to manipulate and query data using familiar syntax while maintaining security boundaries.
  2. Overview of @egose/adapter-js

    The @egose/adapter-js package is a TypeScript/JavaScript client adapter designed to facilitate communication with Egose backend API endpoints. It acts as the bridge between the frontend application and the Egose backend services.
  3. Overview of @egose/deco Annotations

    The @egose/deco package provides TypeScript Decorators used to define @egose/acl configurations and options. These annotations are applied to classes, methods, parameters, and properties to streamline authorization logic and improve the organization and maintainability of backend codebases.
  4. Overview of Model Router Middleware Functions

    Middleware functions (hooks) in egose-acl execute during the lifecycle of asynchronous data model CRUD operations. They allow developers to intercept and modify requests and responses for tasks like validation and data transformation without altering core application logic.

    Critical Implementation Note: To access the Express Request Object via the this keyword inside a middleware function, you must use regular functions (function() {}) instead of arrow functions, as arrow functions do not have their own this context.

  5. Overview of @egose/swagger

    The @egose/swagger package provides support for the OpenAPI Specification (formerly known as Swagger Specification) to describe REST APIs. It is specifically designed to describe the API endpoints generated by the @egose/acl model routers.
  6. Limit blog post length in list views using truncate comments

    To limit the amount of content displayed for a blog post in the list view, insert the <!-- truncate --> HTML comment within the post content. Content appearing after this comment will be hidden in the list view and only visible on the full post page.
    This text will be visible in the list view.
    
    <!-- truncate -->
    
    This text will only be visible on the full blog post page.
  7. Simplify authorization logic using TypeScript decorators

    Use TypeScript decorators to improve code organization and readability when defining configurations and options for authorization logic. This approach allows for a more declarative way to handle permissions and access rules.
  8. Bind Model Router to Express

    After configuring the model router, bind its routes property to an Express router to expose the CRUDL API endpoints.
    import express from 'express';
    
    const app = express();
    const router = express.Router();
    
    // Create a model router for the User model
    const userRouter = egose.createRouter('User', { basePath: '/users' });
    
    // Bind the User model router routes to the Express router
    router.use('/', userRouter.routes);
    app.use('/api', router);
  9. Bootstrap @egose/deco in an Express server

    To activate the defined router modules and expose the API endpoints, use the EgoseFactory.bootstrap method, passing the module class and the Express application instance.
    import express from 'express';
    import { EgoseFactory } from '@egose/deco';
    import { RoutersModule } from './routers.module';
    
    const app = express();
    EgoseFactory.bootstrap(RoutersModule, app);
  10. Initialize a sub-document reference in egose-adapter-js

    To perform CRUD operations on sub-documents, use the id() method on a model service to target a specific parent document, and then call the subs() method specifying the name of the sub-document collection (array) you wish to manipulate.
    import egoseAdapter from '@egose/adapter-js';
    
    const adapter = egoseAdapter.createAdapter({ baseURL: 'http://127.0.0.1:3000/api' });
    
    interface Status {
      name: string;
      active: boolean;
    }
    
    interface User {
      name: string;
      statusHistory: Status[];
      [key: string]: any;
    }
    
    const userService = adapter.createModelService<User>({ modelName: 'User', basePath: 'users' });
    
    // Target a specific user by ID and access the 'statusHistory' sub-document collection
    const sub = userService.id('79c8c567b05e986509d55733a').subs('statusHistory');
  11. Initialize egose-adapter-js and create a Model Service

    The @egose/adapter-js library allows developers to create a service that binds to egose-acl Model API endpoints. To set this up, first create an adapter instance by specifying the baseURL of the API. Then, use the createModelService method, providing the modelName and the basePath for the specific resource you wish to manage.
    import egoseAdapter from '@egose/adapter-js';
    
    // Initialize the adapter with the API base URL
    const adapter = egoseAdapter.createAdapter({ baseURL: 'http://127.0.0.1:3000/api' });
    
    // Define the interface for the model
    interface User {
      name: string;
      role: string;
      public: boolean;
      [key: string]: any;
    }
    
    // Create a model service for the 'User' model at the 'users' path
    const userService = adapter.createModelService<User>({ 
      modelName: 'User', 
      basePath: 'users' 
    });