UNPKG

@ultipa-graph/ultipa-driver

Version:

NodeJS SDK for ultipa-server 5.2

203 lines 8.81 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, ULTIPA.UltipaPropertyType.LOCAL_DATETIME, ULTIPA.UltipaPropertyType.ZONED_DATETIME, ULTIPA.UltipaPropertyType.DATE, ULTIPA.UltipaPropertyType.ZONED_TIME, ULTIPA.UltipaPropertyType.LOCAL_TIME, ULTIPA.UltipaPropertyType.YEAR_TO_MONTH, ULTIPA.UltipaPropertyType.DAY_TO_SECOND, ULTIPA.UltipaPropertyType.JSON ].includes(t); if (!isBase) { return false; } } return true; }; PropertyUtils.propertyGet = (type) => { if (type === ULTIPA.UltipaPropertyType.LOCAL_DATETIME || type === ULTIPA.UltipaPropertyType.ZONED_DATETIME || type === ULTIPA.UltipaPropertyType.LOCAL_TIME || type === ULTIPA.UltipaPropertyType.ZONED_TIME) { return ULTIPA.UltipaPropertyType[type].replace("_", " "); } if (type === ULTIPA.UltipaPropertyType.YEAR_TO_MONTH) { return `duration(year to month)`; } if (type === ULTIPA.UltipaPropertyType.DAY_TO_SECOND) { return `duration(day to second)`; } 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 = [PropertyUtils.GetPropertyBaseType(subTypeDesc).type]; return result; } if (typeDesc.trim().endsWith(">")) { let subTypeDesc = typeDesc.replace(/set\<|\>/g, "").trim(); result.type = ULTIPA.UltipaPropertyType.SET; result.subTypesDesc = [subTypeDesc]; result.subTypes = [PropertyUtils.GetPropertyBaseType(subTypeDesc).type]; 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 => PropertyUtils.GetPropertyBaseType(desc).type); return result; } return PropertyUtils.GetPropertyBaseType(typeDesc); }; PropertyUtils.GetPropertyBaseType = (typeDesc) => { let result = { type: ULTIPA.UltipaPropertyType.UNSET, }; 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; } if (typeDesc.trim() == "local datetime") { result.type = ULTIPA.UltipaPropertyType.LOCAL_DATETIME; return result; } if (typeDesc.trim() == "zoned datetime") { result.type = ULTIPA.UltipaPropertyType.ZONED_DATETIME; return result; } if (typeDesc.trim() == "local time") { result.type = ULTIPA.UltipaPropertyType.LOCAL_TIME; return result; } if (typeDesc.trim() == "zoned time") { result.type = ULTIPA.UltipaPropertyType.ZONED_TIME; return result; } if (typeDesc.trim() == "duration(year to month)") { result.type = ULTIPA.UltipaPropertyType.YEAR_TO_MONTH; return result; } if (typeDesc.trim() == "duration(day to second)") { result.type = ULTIPA.UltipaPropertyType.DAY_TO_SECOND; 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