@samatawy/rules
    Preparing search index...

    Class TypeParser

    Parser class for parsing type definitions from JSON syntax into RootType objects. This parser is designed to handle type definitions that can include atomic types, array types, complex types (objects), and object array types. The expected syntax for type definitions is JSON-based, where a RootType must have a "key" property and either a "type" or "properties" property. The parser includes validation to ensure that the provided JSON syntax conforms to the expected structure for type definitions. You can use static methods to validate specific type structures (like atomic types, array types, complex types, etc.). This parser is primarily used internally when creating types from syntax, and you should not need to instantiate it directly.

    Index

    Constructors

    Methods

    • Parse a root type from its JSON syntax string and return the corresponding RootType object. Should be able to read strict and relaxed JSON syntax for type definitions, such as: { "key": "Person", "type": "object", "properties": { "name": "string", "age": "number" } } or with relaxed JSON syntax like: { key: 'Person', type: 'object', properties: { name: 'string', age: 'number' } }

      Parameters

      • syntax: string

        The JSON syntax string of the root type to parse.

      Returns RootType

      The parsed RootType object if successful.

      An error if the syntax is invalid or if parsing fails for any reason.

    • Check if a given type is an atomic type (string, number, boolean, or date).

      Parameters

      • type: unknown

        the type to check.

      Returns type is AtomicType

      true if the type is an atomic type, otherwise false.

    • Check if a given type is an array type (string[], number[], boolean[], or date[]), knowing that Array Object types are also accepted as array types. The loosely typed 'array' is also accepted by this function.

      Parameters

      • type: unknown

        the type to check.

      Returns type is ArrayType

      true if the type is an array type, otherwise false.

    • Check if a given type is an object type or the unspecified type 'object'.

      Parameters

      • type: unknown

        the type to check.

      Returns type is ComplexType

      true if the type is an object type, otherwise false.

    • Check if a given type is a stringly-typed Object type. The type 'object' is not accepted by this function.

      Parameters

      • type: unknown

        the type to check.

      Returns type is ObjectType

      true if the type is a stringly-typed object, otherwise false.

    • Check if a given type is a stringly-type Array of Objects type. The loose type 'array' is not accepted by this function.

      Parameters

      • type: unknown

        the type to check.

      Returns type is ObjectArrayType

      true if the type is a stringly-typed Array type, otherwise false.

    • Check if a given type can be used in type definitions as a PropertyType. Any Property type can be used in the type registry.

      Parameters

      • type: unknown

        the type to check.

      Returns type is PropertyType

      true if the type can be used in the type regitsyr, otherwise false.