UNPKG

@kusto/monaco-kusto

Version:

CSL, KQL plugin for the Monaco Editor

85 lines (78 loc) 3.4 kB
/*!----------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * monaco-kusto version: 13.1.1(178105a761985a9b7c16d45b528f829e1c112ff0) * Released under the MIT license * https://https://github.com/Azure/monaco-kusto/blob/master/README.md *-----------------------------------------------------------------------------*/ // Definition of schema object in the context of language services. This model is exposed to consumers of this library. /** * An input parameter either be a scalar in which case it has a name, type and * cslType, or it can be columnar, in which case it will have a name, and a list * of scalar types which are the column types. */ /** * Schema types: * Engine – The main schema type. Contains clusters, databases, tables, table columns and functions. * Cluster Manager – Internal only. A schema for clusters that manages other clusters. * Data Management – Internal only. A schema for ingestion point operations. */ const dotnetTypeToKustoType = { 'System.SByte': 'bool', 'System.Byte': 'uint8', 'System.Int16': 'int16', 'System.UInt16': 'uint16', 'System.Int32': 'int', 'System.UInt32': 'uint', 'System.Int64': 'long', 'System.UInt64': 'ulong', 'System.String': 'string', 'System.Single': 'float', 'System.Double': 'real', 'System.DateTime': 'datetime', 'System.TimeSpan': 'timespan', 'System.Guid': 'guid', 'System.Boolean': 'bool', 'Newtonsoft.Json.Linq.JArray': 'dynamic', 'Newtonsoft.Json.Linq.JObject': 'dynamic', 'Newtonsoft.Json.Linq.JToken': 'dynamic', 'System.Object': 'dynamic', 'System.Data.SqlTypes.SqlDecimal': 'decimal' }; const getCslTypeNameFromClrType = clrType => dotnetTypeToKustoType[clrType] || clrType; const kustoTypeToEntityDataType = { object: 'Object', bool: 'Boolean', uint8: 'Byte', int16: 'Int16', uint16: 'UInt16', int: 'Int32', uint: 'UInt32', long: 'Int64', ulong: 'UInt64', float: 'Single', real: 'Double', decimal: 'Decimal', datetime: 'DateTime', string: 'String', dynamic: 'Dynamic', timespan: 'TimeSpan' }; const getEntityDataTypeFromCslType = cslType => kustoTypeToEntityDataType[cslType] || cslType; const getCallName = fn => `${fn.name}(${fn.inputParameters.map(p => `{${p.name}}`).join(',')})`; const getExpression = fn => `let ${fn.name} = ${getInputParametersAsCslString(fn.inputParameters)} ${fn.body}`; const getInputParametersAsCslString = inputParameters => `(${inputParameters.map(inputParameter => getInputParameterAsCslString(inputParameter)).join(',')})`; const getInputParameterAsCslString = inputParameter => { // If this is a tabular parameter if (inputParameter.columns && inputParameter.columns.length > 0) { const attributesAsString = inputParameter.columns.map(col => `${col.name}:${col.cslType || getCslTypeNameFromClrType(col.type)}`).join(','); return `${inputParameter.name}:${attributesAsString === '' ? '*' : attributesAsString}`; } else { return `${inputParameter.name}:${inputParameter.cslType || getCslTypeNameFromClrType(inputParameter.type)}`; } }; /** * This is the schema of the output of kusto command * .show schema as json */ let showSchema; export { getCallName as a, getExpression as b, getInputParametersAsCslString as c, getEntityDataTypeFromCslType as d, getCslTypeNameFromClrType as g, showSchema as s };