UNPKG

@ultipa-graph/ultipa-driver

Version:

NodeJS SDK for ultipa-server 5.1

153 lines 6.7 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PropertyUtils = void 0; const lodash_1 = require("lodash"); const ULTIPA = __importStar(require("../types/types")); var PropertyUtils; (function (PropertyUtils) { PropertyUtils.IsBasePropertyType = (...types) => { for (let index = 0; index < types.length; index++) { const t = types[index]; let isBase = [ ULTIPA.UltipaPropertyType.INT32, ULTIPA.UltipaPropertyType.STRING, ULTIPA.UltipaPropertyType.FLOAT, ULTIPA.UltipaPropertyType.DOUBLE, ULTIPA.UltipaPropertyType.UINT32, ULTIPA.UltipaPropertyType.INT64, ULTIPA.UltipaPropertyType.UINT64, ULTIPA.UltipaPropertyType.DATETIME, ULTIPA.UltipaPropertyType.TIMESTAMP, ULTIPA.UltipaPropertyType.TEXT, ].includes(t); if (!isBase) { return false; } } return true; }; PropertyUtils.propertyGet = (type) => { return ULTIPA.UltipaPropertyType[type]; }; PropertyUtils.PropertyTypeDescValid = (type, subTypes) => { let result = { ok: true, msg: "", }; let lengthCheck = 0; if (type === ULTIPA.UltipaPropertyType.LIST) { lengthCheck = 1; } if (type === ULTIPA.UltipaPropertyType.MAP) { lengthCheck = 2; } if (type === ULTIPA.UltipaPropertyType.SET) { lengthCheck = 1; } if ((subTypes?.length || 0) != lengthCheck) { result.ok = false; result.msg = `The length of the subtype of type ${PropertyUtils.propertyGet(type)} needs to be equal to ${lengthCheck}`; return result; } if (subTypes?.length > 0) { if (!PropertyUtils.IsBasePropertyType(...subTypes)) { result.ok = false; result.msg = `Type ${PropertyUtils.propertyGet(type)} does not support subtypes: ${JSON.stringify(subTypes.map(t => PropertyUtils.propertyGet(t)))}`; return result; } } return result; }; PropertyUtils.GetPropertyTypeDesc = (type, subTypes, extra) => { let validResult = PropertyUtils.PropertyTypeDescValid(type, subTypes); if (!validResult.ok) { throw new Error(validResult.msg); } if (type === ULTIPA.UltipaPropertyType.LIST) { let subType = subTypes[0]; if (PropertyUtils.IsBasePropertyType(subType)) { return `${PropertyUtils.propertyGet(subType)}[]`; } } if (type === ULTIPA.UltipaPropertyType.SET) { let subType = subTypes[0]; if (PropertyUtils.IsBasePropertyType(subType)) { return `set(${PropertyUtils.propertyGet(subType)})`; } } if (type === ULTIPA.UltipaPropertyType.MAP) { let [subTypeKey, subTypeValue] = subTypes; if (PropertyUtils.IsBasePropertyType(subTypeKey, subTypeValue)) { return `{${PropertyUtils.propertyGet(subTypeKey)}: ${PropertyUtils.propertyGet(subTypeValue)}}`; } } if (type == ULTIPA.UltipaPropertyType.DECIMAL) { return `decimal(${extra.precision},${extra.scale})`; } return PropertyUtils.propertyGet(type); }; PropertyUtils.GetPropertyType = (typeDesc) => { let result = { type: ULTIPA.UltipaPropertyType.UNSET, }; if (typeDesc.endsWith("]")) { let subTypeDesc = typeDesc.replace(/\[|\]/g, "").trim(); result.type = ULTIPA.UltipaPropertyType.LIST; result.subTypesDesc = [subTypeDesc]; result.subTypes = [ULTIPA.UltipaPropertyType[(0, lodash_1.upperCase)(subTypeDesc).replace(/\s/g, '')]]; return result; } if (typeDesc.trim().endsWith(">")) { let subTypeDesc = typeDesc.replace(/set\<|\>/g, "").trim(); result.type = ULTIPA.UltipaPropertyType.SET; result.subTypesDesc = [subTypeDesc]; result.subTypes = [ULTIPA.UltipaPropertyType[(0, lodash_1.upperCase)(subTypeDesc).replace(/\s/g, '')]]; return result; } if (typeDesc.trim().endsWith("}")) { let subTypesDesc = typeDesc.replace(/\{|\}/g, "").split(":").map(v => v.trim()); result.type = ULTIPA.UltipaPropertyType.MAP; result.subTypesDesc = subTypesDesc; result.subTypes = subTypesDesc.map(desc => ULTIPA.UltipaPropertyType[(0, lodash_1.upperCase)(desc).replace(/\s/g, '')]); return result; } if (typeDesc.trim().startsWith("decimal")) { let extra = typeDesc.replace(/decimal\(/g, "").replace(/\)/g, "").split(","); result.decimalExtra = { precision: parseInt(extra[0]), scale: parseInt(extra[1]), }; result.type = ULTIPA.UltipaPropertyType.DECIMAL; return result; } let typeString = (0, lodash_1.upperCase)(typeDesc).replace(/\s/g, ''); result.type = ULTIPA.UltipaPropertyType[typeString]; return result; }; PropertyUtils.GetPropertyTypeToString = (typeDescUpper) => { }; })(PropertyUtils = exports.PropertyUtils || (exports.PropertyUtils = {})); //# sourceMappingURL=property.js.map