CodBi
    Preparing search index...

    Class JSON_OP

    A DBC demanding that an object has specific properties of specific types.

    Maintainer: Callari, Salvatore (XDBC@WaXCode.net)

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    checkElements: boolean = false
    infringementSettings: { logToConsole: boolean; throwException: boolean } = ...

    Stores the settings concerning infringements

    necessaryProperties: { name: string; type: string }[]
    warningSettings: { logToConsole: boolean } = ...

    Stores settings concerning warnings.

    Infringement: typeof __class = ...

    An Error to be thrown whenever an infringement is detected.

    paramValueRequests: Map<
        object,
        Map<string | symbol, Map<number, ((value: any) => undefined)[]>>,
    > = ...

    Stores all request for parameter values registered by decPrecondition.

    Methods

    • Reports a field-infringement via reportInfringement also generating a proper string-wrapper for the given message & name.

      Parameters

      • message: string

        A string describing the infringement and it's provenience.

      • target: object
      • path: string

        The dotted-path string that leads to the value not fulfilling the contract starting from the tagged one.

      • key: string

        The property key.

      • value: unknown

        The value not fulfilling a contract.

      Returns undefined

    • Reports an infringement according to the infringementSettings also generating a proper string-wrapper for the given "message" & violator.

      Parameters

      • message: string

        The string describing the infringement and it's provenience.

      • violator: string

        The string describing or naming the violator.

      • target: object
      • path: string

      Returns undefined

    • Reports a parameter-infringement via reportInfringement also generating a proper string-wrapper for the given "message","method", parameter-"index" & value.

      Parameters

      • message: string

        The string describing the infringement and it's provenience.

      • target: object
      • path: string
      • method: string

        The string describing or naming the violator.

      • index: number

        The index of the parameter within the argument listing.

      • value: unknown

        The parameter's value.

      Returns undefined

    • Reports a returnvalue-infringement according via reportInfringement also generating a proper string-wrapper for the given "message","method" & value.

      Parameters

      • message: string

        The string describing the infringement and it's provenience.

      • target: object
      • path: string
      • method: string

        The string describing or naming the violator.

      • value: any

        The parameter's value.

      Returns void

    • Reports a warning.

      Parameters

      • message: string

        The message containing the warning.

      Returns undefined

    • Checks if the object toCheck has the necessaryProperties of necessary type.

      Parameters

      • toCheck: any

        The object to check for the necessary properties.

      • necessaryProperties: { name: string; type: string }[]

        The **{ name : string, type : string }**s defining the properties and type the object to check needs to have.

      • checkElements: any

        Indicates if toCheck is an iterable object of which all elements have to be checked. Elements will only be checked if toCheck is iterable, otherwise toCheck itself will be checked.

      Returns string | boolean

      TRUE if the value toCheck or it's elements, if checkElements is TRUE, has all necessaryProperties, otherwise a string to report the infringement.

    • A property-decorator factory serving as a Design By Contract Invariant. Since the value must be initialized or set according to the specified contracts the value will only be checked when assigning it.

      Parameters

      • contracts: { check: (toCheck: unknown) => string | boolean }[]

        The DBC-Contracts the value shall uphold.

      • path: string = undefined
      • dbc: string = "WaXCode.DBC"

      Returns (target: unknown, propertyKey: string | symbol) => void

      A DBC.Infringement whenever the property is tried to be set to a value that does not comply to the specified contracts, by the returned method.

    • A method decorator factory checking the result of a method whenever it is invoked thus also usable on getters.

      Parameters

      • check: (toCheck: any, object: any, string: any) => string | boolean

        The (toCheck: any, object, string) => boolean | string to use for checking.

      • dbc: string
      • path: string = undefined

        The dotted path referring to the actual value to check, starting form the specified one.

      Returns (
          target: object,
          propertyKey: string,
          descriptor: PropertyDescriptor,
      ) => PropertyDescriptor

      The ( target : object, propertyKey : string, descriptor : PropertyDescriptor ) : PropertyDescriptor invoked by Typescript.

    • A parameter-decorator factory that requests the tagged parameter's value passing it to the provided "check"-method when the value becomes available.

      Parameters

      • check: (unknown: any, object: any, string: any, number: any) => string | boolean

        The "( unknown ) => void" to be invoked along with the tagged parameter's value as soon as it becomes available.

      • dbc: string
      • path: string = undefined

        The dotted path referring to the actual value to check, starting form the specified one.

      Returns (target: object, methodName: string | symbol, parameterIndex: number) => void

      The (target: object, methodName: string | symbol, parameterIndex: number ) => void invoked by Typescript-

    • A field-decorator factory using the JSON_OP.checkAlgorithm to determine whether this DBC is fulfilled by the tagged field.

      Parameters

      • necessaryProperties: { name: string; type: string }[]
      • checkElements: boolean = false
      • path: string = undefined
      • dbc: string = "WaXCode.DBC"

      Returns (target: unknown, propertyKey: string | symbol) => void

      See DBC.decPostcondition.

    • A method-decorator factory checking the paramValueRequests for value-requests of the method's parameter thus also usable on setters. When found it will invoke the "receptor" registered there, inter alia by requestParamValue, with the parameter's value.

      Parameters

      • target: object

        The object hosting the tagged method as provided by the runtime.

      • propertyKey: string

        The tagged method's name as provided by the runtime.

      • descriptor: PropertyDescriptor

        The PropertyDescriptor as provided by the runtime.

      Returns PropertyDescriptor

      The PropertyDescriptor that was passed by the runtime.

    StaticPOST

    • POST(
          necessaryProperties: { name: string; type: string }[],
          checkElements?: boolean,
          path?: string,
          dbc?: string,
      ): (
          target: object,
          propertyKey: string,
          descriptor: PropertyDescriptor,
      ) => PropertyDescriptor

      A method-decorator factory using the JSON_OP.checkAlgorithm to determine whether this DBC is fulfilled by the tagged method's returnvalue.

      Parameters

      • necessaryProperties: { name: string; type: string }[]
      • checkElements: boolean = false
      • path: string = undefined

        See DBC.Postcondition.

      • dbc: string = "WaXCode.DBC"

      Returns (
          target: object,
          propertyKey: string,
          descriptor: PropertyDescriptor,
      ) => PropertyDescriptor

      See DBC.decPostcondition.

    • A parameter-decorator factory using the JSON_OP.checkAlgorithm to determine whether this DBC is fulfilled by the tagged parameter.

      Parameters

      Returns (target: object, methodName: string | symbol, parameterIndex: number) => void

      See DBC.decPrecondition.

    • Make a request to get the value of a certain parameter of specific method in a specific object. That request gets enlisted in paramValueRequests which is used by ParamvalueProvider to invoke the given "receptor" with the parameter value stored in there. Thus a parameter decorator using this method will not receive any value of the top method is not tagged with ParamvalueProvider.

      Parameters

      • target: object

        The object containing the method with the parameter which's value is requested.

      • methodName: string | symbol

        The name of the method with the parameter which's value is requested.

      • index: number

        The index of the parameter which's value is requested.

      • receptor: (value: any) => undefined

        The method the requested parameter-value shall be passed to when it becomes available.

      Returns undefined

    • Resolves the desired object out a given one toResolveFrom using the specified path.

      Parameters

      • toResolveFrom: unknown

        The object starting to resolve from.

      • path: string

        The dotted path-string. This string uses ., [...], and () to represent accessing nested properties, array elements/object keys, and calling methods, respectively, mimicking JavaScript syntax to navigate an object's structure. Code, e.g. something like a.b( 1 as number ).c, will not be executed and thus make the retrieval fail.

      Returns unknown

      The requested object, NULL or UNDEFINED.

    • Resolves the specified dotted string-path to a DBC.

      Parameters

      • obj: any

        The object to start resolving from.

      • path: any

        The dotted string-path leading to the DBC.

      Returns DBC

      The requested DBC.