New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

backk-frontend-utils

Package Overview
Dependencies
Maintainers
1
Versions
126
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

backk-frontend-utils

Web frontend utils for Backk microservices

  • 1.0.128
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-96.53%
Maintainers
1
Weekly downloads
 
Created
Source

Backk Frontend Utils

This contains utilities needed to run generated Backk frontend clients in your frontend client project.

Installation

npm install --save --save-exact backk-frontend-utils

Utility functions

getInputType

function getInputType<T extends Record<string, any>>(
  Class: new () => T,
  propertyName: keyof T
): string 

Gets the input type for property propertyName of class Class

Possible return values are:

  • text
  • email
  • password
  • search
  • tel
  • url
  • color
  • file
  • checkbox
  • number
  • month
  • date
  • time
  • datetime-local
  • select

getInstanceWithUndefinedRemovedFromArrays

function getInstanceWithUndefinedRemovedFromArrays(instance: any): any

creates and returns a new instance from instance where undefined values are removed from array type properties. The instance supplied in argument is not changed.

getSelectInputPossibleValues

function getSelectInputPossibleValues<T extends Record<string, any>>(
  Class: new () => T,
  propertyName: keyof T
) 

When property propertyName of class Class has input type 'select', this function returns the possible values allowed for the property.

isBuiltInTypeArrayProperty

function isBuiltInTypeArrayProperty<T extends Record<string, any>>(
  Class: new () => T,
  propertyName: keyof T
)

Returns true if the property propertyName of class Class is an array of a built-in type (number[], string[], boolean[])

isMultipleSelectInput

function isMultipleSelectInput<T extends Record<string, any>>(
  Class: new () => T,
  propertyName: keyof T
)

Returns true if the input rendered for the property propertyName of class Class should be a multiple select input.

isObjectProperty

function isObjectProperty<T extends Record<string, any>>(
  Class: new () => T,
  propertyName: keyof T
)

Returns true if property propertyName of class Class is instance of a class or array of class instances.

isOptionalProperty

function isOptionalProperty<T extends Record<string, any>>(
  Class: new () => T,
  propertyName: keyof T
)

Returns true if property propertyName of class Class is an optional property

removeUnchangedProperties

function removeUnchangedProperties<T extends Record<string, any>>(
  newInstance: T,
  currentInstance: T
)

When comparing properties of newInstance to currentInstance, if property value is the same in both, property will be removed from the newInstance.

shouldPropertyBePresent

function shouldPropertyBePresent<T extends Record<string, any>>(
  Class: new () => T,
  propertyName: keyof T,
  serviceFunctionType: ServiceFunctionType
)

type ServiceFunctionType = 'create' | 'update' | 'other';

Tells if property propertyName of class Class should be present or not when instance of Classis given as an argument for service function of type serviceFunctionType.

getInputValidationProps

function getInputValidationProps<T extends Record<string, any>>(
  Class: new () => T,
  propertyName: keyof T
) 

Gets validation related properties for HTML input element for property propertyName of class Class. Validation related properties can include properties like minLength and maxLength etc...

getValidationMessage

function getValidationMessage(possibleErrorMessage: PossibleString): string

type PossibleString = string | null | undefined

Gets validation message from possibleErrorMessage. If property has not been validated, the possibleErrorMessage should be undefined and this function returns empty string. If property has been validated without error, possibleErrorMessage should be null and this function returns string 'OK'. In case of validation failure, this function returns the possibleErrorMessage

getValidationMessageHtmlClassName

function getValidationMessageHtmlClassNames(errorMessage: PossibleString)

type PossibleString = string | null | undefined

If errorMessage is string, returns 'validationMessage error', otherwise returns 'validationMessage'

validateServiceFunctionArgument

async function validateServiceFunctionArgument<T extends object>(
  serviceFunctionArgument: T | Partial<T>,
  ArgumentClass: new () => T,
  serviceFunctionType: ServiceFunctionType
): Promise<string | null>

type ServiceFunctionType = 'create' | 'update' | 'other';

Validates serviceFunctionArgument of class ArgumentClass when service function type is serviceFunctionType. On successful validation, returns Promise<null> and on validation failure returns promise of error message Promise<string>.

validateServiceFunctionArgumentOrThrow

async function validateServiceFunctionArgumentOrThrow<T extends object>(
  serviceFunctionArgument: T | Partial<T>,
  ArgumentClass: new () => T,
  serviceFunctionType: ServiceFunctionType
): Promise<void>

type ServiceFunctionType = 'create' | 'update' | 'other';

Validates serviceFunctionArgument of class ArgumentClass when service function type is serviceFunctionType. On successful validation, returns Promise<void> and on validation failure throws an exception.

validateServiceFunctionArgumentProperty

async function validateServiceFunctionArgumentProperty<
  T extends Record<string, any>,
  K extends keyof T,
  V extends T[K]
>(
  ArgumentClass: new () => T,
  propertyName: K,
  propertyValue: V,
  serviceFunctionType: ServiceFunctionType
): Promise<string | null>

type ServiceFunctionType = 'create' | 'update' | 'other';

Validates property value propertyValue of property propertyName of class ArgumentClass when service function type is serviceFunctionType. On successful validation, returns Promise<null> and on validation failure returns promise of error message Promise<string>.

Keywords

FAQs

Package last updated on 15 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc