UNPKG

@ultipa-graph/ultipa-driver

Version:

NodeJS SDK for ultipa-server 5.1

259 lines 8.95 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.printAttrList = exports.printAnyArray = void 0; const ULTIPA = __importStar(require("../types/types")); function printAnyArray(datas) { if (datas === null) { console.log(null); return; } console.log(datas); } exports.printAnyArray = printAnyArray; function printAttrList(attr, datas) { if (datas === null) { console.log(null); return; } if (datas?.length == 0) { console.log(datas); return; } printAnyArray(datas); // if (attr.has_attr_data) { // datas.forEach(d => { // if (attr.type && d.nodes) { // } else { // } // }) // } } exports.printAttrList = printAttrList; // export function printAttrObj(attr: ULTIPA.Attr) { // let values = attr?.values // console.log(`ResultType: ${chalk.yellow(attr.resultType)}`) // switch (attr.resultType) { // case ULTIPA.ResultType.RESULT_TYPE_ATTR: // printAttrList(attr, values) // break // case ULTIPA.ResultType.RESULT_TYPE_PATH: // values.forEach((paths, index) => { // let infos = (paths) // console.log(`Index: ${chalk.yellow(`${index}`)}`) // console.table(infos) // }) // break // case ULTIPA.ResultType.RESULT_TYPE_EDGE: // values.forEach((edges, index) => { // let infos = getEdgesPrintInfo(edges, { onlyRows: true }) // console.log(`Index: ${chalk.yellow(`${index}`)}`) // console.table(infos) // }) // break // case ULTIPA.ResultType.RESULT_TYPE_NODE: // values.forEach((nodes, index) => { // let infos = getNodesPrintInfo(nodes, { onlyRows: true }) // console.log(`Index: ${chalk.yellow(`${index}`)}`) // console.table(infos) // }) // break // } // } // export function printAttr(dataItem?: ULTIPA.DataItem) { // if (!dataItem) { // return // } // printAlias(dataItem) // let attr = dataItem.asAttr() // // printAttrObj(attr) // } // class AttrPrint { // tags: AttrTags // header: string // rows: any[] // prints: AttrPrint[] // constructor(init: { // tags: AttrTags, // header: string, // rows: any[], // prints: AttrPrint[] // }) { // this.tags = init.tags // this.header = init.header // this.rows = init.rows // this.prints = init.prints // } // public static log(prints: AttrPrint[] | AttrPrint) { // if (!Array.isArray(prints)) { // prints = [prints] // } // prints.forEach(p => { // let { tags } = p // console.log(`${tags.isEmpty() ? "" : `${chalk.green(tags.desc())} `}${p.header}`) // console.table(p.rows) // if (p.prints?.length > 0) { // AttrPrint.log(p.prints) // } // }) // } // } class AttrTags { tags; constructor() { this.tags = []; } appendChild() { this.tags.push(0); } increase() { this.tags[this.tags.length - 1] += 1; } clone() { let one = new AttrTags(); one.tags = [...this.tags]; return one; } isEmpty() { return this.tags?.length == 0; } desc() { return `Tag[${this.tags.join("_")}]`; } } let attrIsList = (attr) => { return attr?.propertyType == ULTIPA.UltipaPropertyType.LIST; }; // let attrInfo = (attr: ULTIPA.Attr, params: AttrListInfoParams) => { // let isList = attrIsList(attr) // let rows: any[] = [] // let newTags = params.tags.clone() // newTags.appendChild() // let prints: AttrPrint[] = [] // if (isList) { // attr.values.forEach(v => { // let vListData: ULTIPA.AttrListData = v // if (!v.type) { // if (Array.isArray(v)) { // rows.push(JSON.stringify(v)) // } else { // rows.push(v) // } // // rows.push(JSON.stringify(v)) // // v = v || [] // // v.forEach(vi => { // // if (Array.isArray(vi)) { // // rows.push(JSON.stringify(vi)) // // } else { // // rows.push(vi) // // } // // }) // return // } // let result_type = ULTIPA.ResultType[v.type] // // rows.push({ // // "*result_type": result_type // // }) // switch (v.type) { // case ULTIPA.ResultType.RESULT_TYPE_PATH: // let paths = getPathsPrintInfo(vListData.paths) // rows.push(...paths) // break // case ULTIPA.ResultType.RESULT_TYPE_EDGE: // let edges = getEdgesPrintInfo(vListData.edges, { onlyRows: true }) // rows.push(...edges) // break // case ULTIPA.ResultType.RESULT_TYPE_NODE: // let nodes = getNodesPrintInfo(vListData.nodes, { onlyRows: true }) // rows.push(...nodes) // break // case ULTIPA.ResultType.RESULT_TYPE_ATTR: // vListData.attrs.forEach((attr) => { // if (attrIsList(attr)) { // newTags.increase() // } // let result = printAttrStruct(attr, v.type, { // returnJson: true, // tags: newTags.clone(), // }) // if (result) { // rows.push(result.json) // prints.push(...result.prints) // } else { // rows.push(result) // } // }) // break // } // }) // } else { // rows.push(attr.values) // } // return new AttrPrint({ // tags: params.tags, // header: `Result Type: ${chalk.yellow(ULTIPA.ResultType[params.result_type])} Property Type: ${chalk.yellow(PropertyUtils.propertyGet(attr.propertyType))}`, // rows, // prints, // }) // } // export function printAttrStruct(attr: ULTIPA.Attr, result_type: ULTIPA.ResultType, params?: AttrInfoParams) { // if (!attr) { // return null // } // let prints: AttrPrint[] = [] // if (!params) { // params = { // tags: new AttrTags(), // } // } // let isList = attrIsList(attr) // if (!params.returnJson) { // let v = attrInfo(attr, { // result_type, // tags: params.tags, // }) // prints.push(v) // AttrPrint.log(prints) // return // } // let values: any = attr.values // if (isList) { // let t = `See: ${params.tags.desc()}` // values = t // let v = attrInfo(attr, { // result_type, // tags: params.tags, // }) // prints.push(v) // } // return { // json: { // ...attr, // values: values, // }, // prints, // } // } //# sourceMappingURL=array.aio.js.map