export type Scalar = string | number | null ; export enum ParamTransform { Scalar , Spread , Pick , PickSpread } export interface IScalarParam { name : string ; type : ParamTransform . Scalar ; required : boolean ; assignedIndex : number ; } export interface IDictParam { name : string ; type : ParamTransform . Pick ; dict : { [ key ] : IScalarParam ; } ; } export interface IScalarArrayParam { name : string ; type : ParamTransform . Spread ; required : boolean ; assignedIndex : number | number [ ] ; } export interface IDictArrayParam { name : string ; type : ParamTransform . PickSpread ; dict : { [ key ] : IScalarParam ; } ; } export type QueryParam = IScalarParam | IScalarArrayParam | IDictParam | IDictArrayParam ; export interface IInterpolatedQuery { query : string ; mapping : QueryParam [ ] ; bindings : Scalar [ ] ; } export interface INestedParameters { [ subParamName ] : Scalar ; } export interface IQueryParameters { [ paramName ] : Scalar | INestedParameters | Scalar [ ] | INestedParameters [ ] ; } export function replaceIntervals ( str , intervals ) { if ( intervals . length === 0 ) { return str ; } intervals . sort ( ( x , y ) => x . a - y . a ) ; let offset = 0 ; let result = '' ; for ( const interval of intervals ) { const a = str . slice ( 0 , interval . a + offset ) ; const c = str . slice ( interval . b + offset + 1 , str . length ) ; result = a + interval . sub + c ; offset += result . length - str . length ; str = result ; } return result ; }