npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@alfercom/base-types

v1.0.0

Published

<div align="center"> <img src="./assets/alfercom-logo.png"> <img width="100" src="./assets/cardinal-logo.png"> </div>

Downloads

72

Readme

This repo provide a series of default types commonly used in alfercom/cardinal projects.

Index

Installation

npm i --save @alfercom/default-types

Primitive types

This library exposes a set of extended primitive types useful for quick implementation when declaring types that may not be immediately valued. These extensions help the developer to respect the syntax rules imposed by the project linter and to maintain a correct and simple legibility of the code.

Normal primitive in typescript extended by this package are

string  | number | boolean

These can be called with their extension ' _ ', which adds the definitions of null and undefined, such as:

_string  | _number | _boolean

Usage example

We want to define a user class that has as parameters: username, age and premium, in that case our class would be:

class User extends UserInterface {
  
  // Wrong declaration emitted by linter and refused by compiler
  public username: string;
  public age: number;
  public premium: boolean; 

  public getUsername(): string {
    return this.username
  }

}

If we have configurated our linter and tsconfig correctly, they will throw exceptions on our declarations cause we have not initialized our variables in any way. In order to eliminate these errors we should make the following changes to our code:

class User extends UserInterface {
  
  // These statements will accepted by linter and compiler
  public readonly username: string | undefined;
  public readonly age: number | undefined;
  public readonly premium: boolean | undefined; 
  
  public getUsername(): string | undefined {
    return this.username;
  }
}

That's right, but not very nice is it? So we can use our extended primitives to make this look prettier

class User extends UserInterface {
  
  public readonly username: _string;
  public readonly age: _number;
  public readonly premium: _boolean; 
  
  public getUsername(): _string {
    return this.username;
  }
}

Javascript interfaces

As like the extendend primitives this library provides olso some extensions of Javascript interfaces.

Normal javascript interfaces extended by this package are

Data  | Array | Record(Object)

These can be called with their extension ' _ ', which adds the definitions of null and undefined, such as:

_Date  | _Array | _Object

Custom types

/**
 * Declare that a type can be Null or Undefined
 */
type _nullable  = null | undefined;
/**
 * Type that provides 184 ISO 639-1 languages
 */
type _Locale = IsoLang  | _nullable;
/**
 * Extends mongo ObjectId instance and declare it nullable
 */
type _ObjectId = ObjectId  | _nullable;
/**
 * Basic event data
 */
type EventData = {
  /**
   * The event name
   */
  event: DefaultRecordEvent;
  /**
   * The user that generate the event
   */
  accountId: _ObjectId;
  /**
   * The Date of the event
   */
  date: _Date;
  /**
   * Message associated to the event
   */
  message: _string;
} | _nullable;
/**
 * 184 ISO 639-1 languages
 */
type IsoLang = "en" | "it" |... ;

Interfaces

  • Error

    /**
     * Error interface
      */
    interface _error {
      /**
      * Error Type
      */
      errorType: string;
      /**
      * The operation that generates the exception
      */
      operation?: string;
      /**
      * The source that call the failed operation
      */
      onRequest?: string;
      /**
      * Contraints
      */
      constraints?: Contraints[];
      /**
      * Optional error messages
      */
      messages: string[];
    }
    
    /**
     * Contraints
      */
    interface Contraints {
      /**
      * Type
      */
      type: string;
      /**
      * Raw message
      */
      rawMessage: string;
      /**
      * Message
      */
      message: string;
      /**
      * Priority
      */
      priority: string;
    }
  • Query object

    /**
     * This interface describe the model that should be used as params for dynamic query
      */
    interface BaseQueryObject {
      /**
      * Filter operations based on entity dictionary
      */
      filters: FilterOperation[];
      /**
      * Pagination offset
      */
      offset: _number
      /**
      * Pagination limit
      */
      limit: _number
      /**
      * Sort param
      */
      order: _string | _Object;
    }
  • request - response

    /**
     * This interface describe how an api request body should be at least.
     */
    interface BaseAPIRequest {
      /**
      * 
      */
      readonly [key: string]: any;
      /**
      * 
      */
      readonly extra?: any;
    }
    
    /**
    * This interface describe how a query request api should be at least
    */
    interface BaseQueryRequest extends BaseAPIRequest, BaseQueryObject { }
    
    /**
     * An interface that describe and provide base properties of an API operation response
     */
    interface BaseAPIResponse {
      /**
      * Provide interface for operation result
      */
      result: boolean;
      /**
      * Optional messages to attach at response
      */
      messages?: _string[];
      /**
      * Error validation catched by operation execution
      */
      validations?: _error[];
      /**
      * Provide next operation instruction to execute after operation result
      */
      nextOperation?: NextOperation;
    }
    
    /**
    * An interface that describe and provide base properties of a query API operation response
    */
    interface BaseQueryResponse<T> extends BaseAPIResponse, BaseQueryObject {
      /**
      * Number of results
      */
      total: _number
      /**
      * Query results
      */
      data: T | T[];
    }
  • next operation

    /**
     * This interface describe a way to trigger an event/function after an api response
      */
    interface NextOperation {
      /**
      * The event/function to trigger
      */
      event: any;
      /**
      * The params to pass as arguments to the triggered event/function
      */
      params?: any;
    }

Enumerations

  • Error

    /**
     * Base event enumeration that enum the events of CREATION | UPDATE | DELETE
     */
    export enum DefaultRecordEvent {
      CREATED = "CREATED",
      UPDATED = "UPDATED",
      DELETED = "DELETED",
    }

Classes

  • Database record

    /**
     * Standard Database Record
     */
    export class DatabaseRecord {
      /**
      * Record's realm ID
      */
      public realmId: _ObjectId;
      /**
      * Record's creation event
      */
      public creation: EventData;
      /**
      * Record's last edit event
      */
      public lastEdit: EventData;
      /**
      * Record's delete flag
      */
      public deleted: boolean;
      /**
      * Record's delete event
      */
      public deleteInfo: EventData;
      /**
      * Record's version
      */
      public version: _string;
    
      constructor(arg: DatabaseRecord) { }
    
      /**
       * Initialize db record on instance creation
       * @param account 
       * @param message 
       */
      public initializeRecordData(account?: any, message?: string): void
    
      /**
       * Initialize delete properties of an entity in order to declare it deleted
       * ATTENTION: This operation doesn't write on db!
       * @param args 
       */
      public declareDeleted(args?: { accountId: _ObjectId, message: _string }): void 
        
    }