import { defineParameterType } from "@cucumber/cucumber" ; import DataTable from "@cucumber/cucumber/lib/models/data_table" ; import { AttributeType } from "../../../dist/api/concept/type/AttributeType" ; import { TransactionType } from "../../../dist/api/connection/TypeDBTransaction" ; export function parseBool ( value ) { return value === "true" ; } defineParameterType ( { name : "bool" , regexp : /true|false/ , transformer : parseBool , } ) ; defineParameterType ( { name : "number" , regexp : /[0-9]+/ , transformer : s => parseInt ( s ) , } ) ; defineParameterType ( { name : "datetime" , regexp : /\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d/ , transformer : s => new Date ( s ) } ) ; defineParameterType ( { name : "root_label" , regexp : /entity|attribute|relation/ , transformer : s => { switch ( s ) { case "entity" : return RootLabel . ENTITY ; case "attribute" : return RootLabel . ATTRIBUTE ; case "relation" : return RootLabel . RELATION ; default : throw `Root label "${ s }" was unrecognised.` ; } } } ) ; export class ScopedLabel { private readonly _scope : string ; private readonly _role : string ; constructor ( scope , role ) { this . _scope = scope ; this . _role = role ; } static parse ( value ) { const split = value . split ( ":" ) ; return new ScopedLabel ( split [ 0 ] , split [ 1 ] ) ; } get scope ( ) : string { return this . _scope ; } get role ( ) : string { return this . _role ; } toString ( ) { return this . _scope + ":" + this . _role ; } } defineParameterType ( { name : "scoped_label" , regexp : /[a-zA-Z0-9-_]+:[a-zA-Z0-9-_]+/ , transformer : ScopedLabel . parse , } ) ; defineParameterType ( { name : "value_type" , regexp : /long|double|string|boolean|datetime/ , transformer : s => { switch ( s ) { case "long" : return AttributeType . ValueType . LONG ; case "double" : return AttributeType . ValueType . DOUBLE ; case "string" : return AttributeType . ValueType . STRING ; case "boolean" : return AttributeType . ValueType . BOOLEAN ; case "datetime" : return AttributeType . ValueType . DATETIME ; default : throw "Unrecognised value type in step definition" ; } } , } ) ; defineParameterType ( { name : "var" , regexp : /\$([a-zA-Z0-9]+)/ , transformer : s => s } ) ; export function parseVar ( value ) { return value . slice ( 1 ) ; } defineParameterType ( { name : "type_label" , regexp : /[a-zA-Z0-9-_]+/ , transformer : s => s } ) ; defineParameterType ( { name : "transaction_type" , regexp : /read|write/ , transformer : s => s === "read" ? TransactionType . READ : TransactionType . WRITE } ) ; export enum RootLabel { ATTRIBUTE , ENTITY , RELATION } export function parseList ( dataTable ) ; export function parseList < T > ( dataTable , parseFn ) ; export function parseList < T > ( dataTable , parseFn = val => val ) { return dataTable . raw ( ) . map ( row => parseFn ( row [ 0 ] ) ) ; }