@gram-data/gram-builder
Advanced tools
Comparing version 0.1.7 to 0.1.8
@@ -70,26 +70,50 @@ 'use strict'; | ||
/** | ||
* Reduce paths into a single path composed using the given relation. | ||
* | ||
* @parm relation the relation to apply to all sub-paths | ||
* @param paths sub-paths to be paired | ||
*/ | ||
var reduce = function reduce(relation, paths) { | ||
if (relation === void 0) { | ||
relation = 'pair'; | ||
} | ||
var pathlist = normalizeChildren(paths); | ||
if (pathlist) { | ||
if (pathlist.length > 1) { | ||
return [pathlist.reduceRight(function (acc, curr) { | ||
return cons([curr, acc], { | ||
relation: relation | ||
}); | ||
}, UNIT)]; | ||
} else { | ||
return [pathlist[0]]; | ||
} | ||
} | ||
return []; | ||
}; | ||
/** | ||
* Build any path-like element | ||
* | ||
* @param description | ||
* @param id | ||
* @param labels | ||
* @param record | ||
* @param direction | ||
* @param members sub-paths to compose | ||
* @param attributes attributes | ||
*/ | ||
var cons = function cons(description // children: [] | [GramPathlike] | [GramPathlike, GramPathlike], | ||
// id?: string, | ||
// labels?: string[], | ||
// record?: GramRecord, | ||
// direction?: RelationshipOperator | ||
) { | ||
var cons = function cons(members, attributes) { | ||
if (attributes === void 0) { | ||
attributes = {}; | ||
} | ||
var element = _extends({ | ||
type: 'path', | ||
id: description.id | ||
}, description.labels && { | ||
labels: description.labels | ||
}, description.record && { | ||
record: description.record | ||
id: attributes.id | ||
}, attributes.labels && { | ||
labels: attributes.labels | ||
}, attributes.record && { | ||
record: attributes.record | ||
}, { | ||
children: description.operands.filter(function (child) { | ||
children: members.filter(function (child) { | ||
return child && !gramAst.isGramUnit(child); | ||
@@ -100,4 +124,5 @@ }) | ||
if (element.children.length === 0) { | ||
if (element.id) { | ||
if (element.id || element.labels && element.labels.length > 0 || element.record) { | ||
element.type = 'node'; | ||
element.id = element.id || gramAst.identity.shortID(); | ||
return element; | ||
@@ -126,6 +151,6 @@ } else { | ||
} else if (element.children.length === 2) { | ||
if (description.operator && description.operator !== 'pair' && gramAst.isGramNode(element.children[0]) && gramAst.isGramNode(element.children[1])) { | ||
if (attributes.relation && attributes.relation !== 'pair' && gramAst.isGramNode(element.children[0]) && gramAst.isGramNode(element.children[1])) { | ||
element.type = 'edge'; | ||
element.id = element.id || gramAst.identity.shortID(); | ||
element.direction = description.operator; | ||
element.relation = attributes.relation; | ||
return element; | ||
@@ -136,3 +161,3 @@ } | ||
element.id = element.id || gramAst.identity.shortID(); | ||
element.direction = description.operator || 'pair'; | ||
element.relation = attributes.relation || 'pair'; | ||
return element; | ||
@@ -183,3 +208,3 @@ }; | ||
* @param children | ||
* @param direction | ||
* @param relation | ||
* @param id | ||
@@ -190,5 +215,5 @@ * @param labels | ||
var edge = function edge(children, direction, id, labels, record) { | ||
if (direction === void 0) { | ||
direction = 'right'; | ||
var edge = function edge(children, relation, id, labels, record) { | ||
if (relation === void 0) { | ||
relation = 'right'; | ||
} | ||
@@ -204,3 +229,3 @@ | ||
}, { | ||
direction: direction, | ||
relation: relation, | ||
children: children | ||
@@ -218,3 +243,3 @@ }); | ||
var path = function path(children, id, labels, record) { | ||
var path = function path(members, id, labels, record) { | ||
return _extends({ | ||
@@ -229,3 +254,3 @@ type: 'path' | ||
}, { | ||
children: children | ||
children: members | ||
}); | ||
@@ -344,2 +369,3 @@ }; | ||
seq: seq, | ||
reduce: reduce, | ||
cons: cons, | ||
@@ -386,2 +412,3 @@ UNIT: UNIT, | ||
exports.record = record; | ||
exports.reduce = reduce; | ||
exports.seq = seq; | ||
@@ -388,0 +415,0 @@ exports.string = string; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@gram-data/gram-ast");function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function r(e){return Array.isArray(e)?e:e instanceof Function?r(e()):void 0===e?[]:[e]}var n=function(e){return e.toISOString().slice(0,10)},i=function(e,n,i,o){return t({type:"seq"},n&&{id:n},i&&{labels:i},o&&{record:o},{children:r(e)})},o=function(r){var n=t({type:"path",id:r.id},r.labels&&{labels:r.labels},r.record&&{record:r.record},{children:r.operands.filter((function(t){return t&&!e.isGramUnit(t)}))});if(0===n.children.length)return n.id?(n.type="node",n):a;if(1===n.children.length){var i=n.children[0];if(n.id)return e.isGramUnit(i)?(n.type="node",n.children=[],n):n;if(e.isGramUnit(i))return i;if(n.id=e.identity.shortID(),e.isGramNode(i))return i;if(e.isGramEdge(i))return i;if(e.isGramPath(i))return i}else if(2===n.children.length&&r.operator&&"pair"!==r.operator&&e.isGramNode(n.children[0])&&e.isGramNode(n.children[1]))return n.type="edge",n.id=n.id||e.identity.shortID(),n.direction=r.operator,n;return n.id=n.id||e.identity.shortID(),n.direction=r.operator||"pair",n},a={type:"unit",id:e.UNIT_ID,labels:void 0,record:void 0,children:[]},u=function(){return a},d=function(r,n,i){return t({type:"node",id:r||e.identity.shortID()},n&&{labels:n},i&&{record:i},{children:[]})},c=function(r,n,i,o,a){return void 0===n&&(n="right"),t({type:"edge",id:i||e.identity.shortID()},o&&{labels:o},a&&{record:a},{direction:n,children:r})},l=function(e,r,n,i){return t({type:"path"},r&&{id:r},n&&{labels:n},i&&{record:i},{children:e})},s=function(e){return e.reduce((function(e,t){return e[t.name]=t.value,e}),{})},p=function(e,t){return{type:"property",name:e,value:t}},f=function(e){return{type:"boolean",value:e?"true":"false"}},g=function(e){return{type:"string",value:e}},h=function(e,t){return{type:"tagged",value:t,tag:e}},y=function(e){return{type:"integer",value:String(e)}},m=function(e){return{type:"decimal",value:String(e)}},x=function(e){return{type:"hexadecimal",value:e}},v=function(e){return{type:"octal",value:e}},b=function(e,t){return{type:"measurement",value:String(t),unit:e}},I=function(e){return h(e instanceof Date?e.getFullYear().toString():e,"date")},D=function(e){return h(e instanceof Date?n(e):e,"date")},G=function(e){return h(e instanceof Date?"--"+e.toISOString().slice(5,10):e,"date")},O=function(e){return h(e instanceof Date?n(e):e,"time")},S=function(e,t){return void 0===t&&(t=1),e.flat(t).filter((function(e){return null!==e}))},_={__proto__:null,seq:i,cons:o,UNIT:a,unit:u,node:d,edge:c,path:l,record:s,property:p,boolean:f,string:g,tagged:h,integer:y,decimal:m,hexadecimal:x,octal:v,measurement:b,year:I,date:D,dayOfMonth:G,time:O,flatten:S,default:{seq:i,unit:u,cons:o,path:l,node:d,edge:c,record:s,property:p,boolean:f,string:g,tagged:h,integer:y,decimal:m,hexadecimal:x,octal:v,measurement:b,date:D,time:O,flatten:S}};exports.UNIT=a,exports.boolean=f,exports.cons=o,exports.date=D,exports.dayOfMonth=G,exports.decimal=m,exports.default=_,exports.edge=c,exports.flatten=S,exports.hexadecimal=x,exports.integer=y,exports.measurement=b,exports.node=d,exports.octal=v,exports.path=l,exports.property=p,exports.record=s,exports.seq=i,exports.string=g,exports.tagged=h,exports.time=O,exports.unit=u,exports.year=I; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@gram-data/gram-ast");function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function r(e){return Array.isArray(e)?e:e instanceof Function?r(e()):void 0===e?[]:[e]}var n=function(e){return e.toISOString().slice(0,10)},i=function(e,n,i,o){return t({type:"seq"},n&&{id:n},i&&{labels:i},o&&{record:o},{children:r(e)})},o=function(e,t){void 0===e&&(e="pair");var n=r(t);return n?n.length>1?[n.reduceRight((function(t,r){return a([r,t],{relation:e})}),u)]:[n[0]]:[]},a=function(r,n){void 0===n&&(n={});var i=t({type:"path",id:n.id},n.labels&&{labels:n.labels},n.record&&{record:n.record},{children:r.filter((function(t){return t&&!e.isGramUnit(t)}))});if(0===i.children.length)return i.id||i.labels&&i.labels.length>0||i.record?(i.type="node",i.id=i.id||e.identity.shortID(),i):u;if(1===i.children.length){var o=i.children[0];if(i.id)return e.isGramUnit(o)?(i.type="node",i.children=[],i):i;if(e.isGramUnit(o))return o;if(i.id=e.identity.shortID(),e.isGramNode(o))return o;if(e.isGramEdge(o))return o;if(e.isGramPath(o))return o}else if(2===i.children.length&&n.relation&&"pair"!==n.relation&&e.isGramNode(i.children[0])&&e.isGramNode(i.children[1]))return i.type="edge",i.id=i.id||e.identity.shortID(),i.relation=n.relation,i;return i.id=i.id||e.identity.shortID(),i.relation=n.relation||"pair",i},u={type:"unit",id:e.UNIT_ID,labels:void 0,record:void 0,children:[]},d=function(){return u},l=function(r,n,i){return t({type:"node",id:r||e.identity.shortID()},n&&{labels:n},i&&{record:i},{children:[]})},c=function(r,n,i,o,a){return void 0===n&&(n="right"),t({type:"edge",id:i||e.identity.shortID()},o&&{labels:o},a&&{record:a},{relation:n,children:r})},s=function(e,r,n,i){return t({type:"path"},r&&{id:r},n&&{labels:n},i&&{record:i},{children:e})},p=function(e){return e.reduce((function(e,t){return e[t.name]=t.value,e}),{})},f=function(e,t){return{type:"property",name:e,value:t}},g=function(e){return{type:"boolean",value:e?"true":"false"}},h=function(e){return{type:"string",value:e}},y=function(e,t){return{type:"tagged",value:t,tag:e}},m=function(e){return{type:"integer",value:String(e)}},x=function(e){return{type:"decimal",value:String(e)}},v=function(e){return{type:"hexadecimal",value:e}},b=function(e){return{type:"octal",value:e}},I=function(e,t){return{type:"measurement",value:String(t),unit:e}},D=function(e){return y(e instanceof Date?e.getFullYear().toString():e,"date")},G=function(e){return y(e instanceof Date?n(e):e,"date")},O=function(e){return y(e instanceof Date?"--"+e.toISOString().slice(5,10):e,"date")},S=function(e){return y(e instanceof Date?n(e):e,"time")},_=function(e,t){return void 0===t&&(t=1),e.flat(t).filter((function(e){return null!==e}))},N={__proto__:null,seq:i,reduce:o,cons:a,UNIT:u,unit:d,node:l,edge:c,path:s,record:p,property:f,boolean:g,string:h,tagged:y,integer:m,decimal:x,hexadecimal:v,octal:b,measurement:I,year:D,date:G,dayOfMonth:O,time:S,flatten:_,default:{seq:i,unit:d,cons:a,path:s,node:l,edge:c,record:p,property:f,boolean:g,string:h,tagged:y,integer:m,decimal:x,hexadecimal:v,octal:b,measurement:I,date:G,time:S,flatten:_}};exports.UNIT=u,exports.boolean=g,exports.cons=a,exports.date=G,exports.dayOfMonth=O,exports.decimal=x,exports.default=N,exports.edge=c,exports.flatten=_,exports.hexadecimal=v,exports.integer=m,exports.measurement=I,exports.node=l,exports.octal=b,exports.path=s,exports.property=f,exports.record=p,exports.reduce=o,exports.seq=i,exports.string=h,exports.tagged=y,exports.time=S,exports.unit=d,exports.year=D; | ||
//# sourceMappingURL=gram-builder.cjs.production.min.js.map |
@@ -6,3 +6,3 @@ /** | ||
*/ | ||
import { GramPathSeq, GramPath, GramNode, GramEdge, GramProperty, GramLiteral, RelationshipOperator, BooleanLiteral, StringLiteral, TaggedLiteral, IntegerLiteral, DecimalLiteral, HexadecimalLiteral, OctalLiteral, MeasurementLiteral, GramRecord, GramPathlike, GramUnit } from '@gram-data/gram-ast'; | ||
import { GramPathSeq, GramPath, GramNode, GramEdge, GramProperty, GramLiteral, Relation, Navigation, BooleanLiteral, StringLiteral, TaggedLiteral, IntegerLiteral, DecimalLiteral, HexadecimalLiteral, OctalLiteral, MeasurementLiteral, GramRecord, GramPathlike, GramUnit } from '@gram-data/gram-ast'; | ||
export declare type Children<T> = T | T[] | (() => T | T[]); | ||
@@ -19,19 +19,22 @@ /** | ||
export declare const seq: (paths: Children<GramPathlike>, id?: string | undefined, labels?: string[] | undefined, record?: GramRecord | undefined) => GramPathSeq; | ||
export interface PathDescription { | ||
operands: [] | [GramPathlike] | [GramPathlike, GramPathlike]; | ||
operator?: RelationshipOperator; | ||
export interface PathAttributes { | ||
id?: string; | ||
labels?: string[]; | ||
record?: GramRecord; | ||
relation?: Relation; | ||
} | ||
/** | ||
* Reduce paths into a single path composed using the given relation. | ||
* | ||
* @parm relation the relation to apply to all sub-paths | ||
* @param paths sub-paths to be paired | ||
*/ | ||
export declare const reduce: (relation: "left" | "right" | "either" | "pair" | undefined, paths: Children<GramPathlike>) => [GramPathlike] | []; | ||
/** | ||
* Build any path-like element | ||
* | ||
* @param description | ||
* @param id | ||
* @param labels | ||
* @param record | ||
* @param direction | ||
* @param members sub-paths to compose | ||
* @param attributes attributes | ||
*/ | ||
export declare const cons: (description: PathDescription) => GramPathlike; | ||
export declare const cons: (members: [] | [GramPathlike] | [GramPathlike, GramPathlike], attributes?: PathAttributes) => GramPathlike; | ||
/** | ||
@@ -58,3 +61,3 @@ * Singleton instance of GramUnit | ||
* @param children | ||
* @param direction | ||
* @param relation | ||
* @param id | ||
@@ -64,3 +67,3 @@ * @param labels | ||
*/ | ||
export declare const edge: (children: [GramNode, GramNode], direction?: RelationshipOperator, id?: string | undefined, labels?: string[] | undefined, record?: GramRecord | undefined) => GramEdge; | ||
export declare const edge: (children: [GramNode, GramNode], relation?: Navigation, id?: string | undefined, labels?: string[] | undefined, record?: GramRecord | undefined) => GramEdge; | ||
/** | ||
@@ -74,3 +77,3 @@ * Build a path | ||
*/ | ||
export declare const path: (children: [GramPathlike] | [GramPathlike, GramPathlike], id?: string | undefined, labels?: string[] | undefined, record?: GramRecord | undefined) => GramPath; | ||
export declare const path: (members: [GramPathlike] | [GramPathlike, GramPathlike], id?: string | undefined, labels?: string[] | undefined, record?: GramRecord | undefined) => GramPath; | ||
export declare const record: (properties: GramProperty[]) => GramRecord; | ||
@@ -94,6 +97,6 @@ export declare const property: (name: string, value: GramLiteral | GramLiteral[]) => GramProperty; | ||
unit: () => GramUnit; | ||
cons: (description: PathDescription) => GramPathlike; | ||
path: (children: [GramPathlike] | [GramPathlike, GramPathlike], id?: string | undefined, labels?: string[] | undefined, record?: GramRecord | undefined) => GramPath; | ||
cons: (members: [] | [GramPathlike] | [GramPathlike, GramPathlike], attributes?: PathAttributes) => GramPathlike; | ||
path: (members: [GramPathlike] | [GramPathlike, GramPathlike], id?: string | undefined, labels?: string[] | undefined, record?: GramRecord | undefined) => GramPath; | ||
node: (id?: string | undefined, labels?: string[] | undefined, record?: GramRecord | undefined) => GramNode; | ||
edge: (children: [GramNode, GramNode], direction?: RelationshipOperator, id?: string | undefined, labels?: string[] | undefined, record?: GramRecord | undefined) => GramEdge; | ||
edge: (children: [GramNode, GramNode], relation?: Navigation, id?: string | undefined, labels?: string[] | undefined, record?: GramRecord | undefined) => GramEdge; | ||
record: (properties: GramProperty[]) => GramRecord; | ||
@@ -100,0 +103,0 @@ property: (name: string, value: GramLiteral | GramLiteral[]) => GramProperty; |
@@ -66,26 +66,50 @@ import { isGramUnit, identity, isGramNode, isGramEdge, isGramPath, UNIT_ID } from '@gram-data/gram-ast'; | ||
/** | ||
* Reduce paths into a single path composed using the given relation. | ||
* | ||
* @parm relation the relation to apply to all sub-paths | ||
* @param paths sub-paths to be paired | ||
*/ | ||
var reduce = function reduce(relation, paths) { | ||
if (relation === void 0) { | ||
relation = 'pair'; | ||
} | ||
var pathlist = normalizeChildren(paths); | ||
if (pathlist) { | ||
if (pathlist.length > 1) { | ||
return [pathlist.reduceRight(function (acc, curr) { | ||
return cons([curr, acc], { | ||
relation: relation | ||
}); | ||
}, UNIT)]; | ||
} else { | ||
return [pathlist[0]]; | ||
} | ||
} | ||
return []; | ||
}; | ||
/** | ||
* Build any path-like element | ||
* | ||
* @param description | ||
* @param id | ||
* @param labels | ||
* @param record | ||
* @param direction | ||
* @param members sub-paths to compose | ||
* @param attributes attributes | ||
*/ | ||
var cons = function cons(description // children: [] | [GramPathlike] | [GramPathlike, GramPathlike], | ||
// id?: string, | ||
// labels?: string[], | ||
// record?: GramRecord, | ||
// direction?: RelationshipOperator | ||
) { | ||
var cons = function cons(members, attributes) { | ||
if (attributes === void 0) { | ||
attributes = {}; | ||
} | ||
var element = _extends({ | ||
type: 'path', | ||
id: description.id | ||
}, description.labels && { | ||
labels: description.labels | ||
}, description.record && { | ||
record: description.record | ||
id: attributes.id | ||
}, attributes.labels && { | ||
labels: attributes.labels | ||
}, attributes.record && { | ||
record: attributes.record | ||
}, { | ||
children: description.operands.filter(function (child) { | ||
children: members.filter(function (child) { | ||
return child && !isGramUnit(child); | ||
@@ -96,4 +120,5 @@ }) | ||
if (element.children.length === 0) { | ||
if (element.id) { | ||
if (element.id || element.labels && element.labels.length > 0 || element.record) { | ||
element.type = 'node'; | ||
element.id = element.id || identity.shortID(); | ||
return element; | ||
@@ -122,6 +147,6 @@ } else { | ||
} else if (element.children.length === 2) { | ||
if (description.operator && description.operator !== 'pair' && isGramNode(element.children[0]) && isGramNode(element.children[1])) { | ||
if (attributes.relation && attributes.relation !== 'pair' && isGramNode(element.children[0]) && isGramNode(element.children[1])) { | ||
element.type = 'edge'; | ||
element.id = element.id || identity.shortID(); | ||
element.direction = description.operator; | ||
element.relation = attributes.relation; | ||
return element; | ||
@@ -132,3 +157,3 @@ } | ||
element.id = element.id || identity.shortID(); | ||
element.direction = description.operator || 'pair'; | ||
element.relation = attributes.relation || 'pair'; | ||
return element; | ||
@@ -179,3 +204,3 @@ }; | ||
* @param children | ||
* @param direction | ||
* @param relation | ||
* @param id | ||
@@ -186,5 +211,5 @@ * @param labels | ||
var edge = function edge(children, direction, id, labels, record) { | ||
if (direction === void 0) { | ||
direction = 'right'; | ||
var edge = function edge(children, relation, id, labels, record) { | ||
if (relation === void 0) { | ||
relation = 'right'; | ||
} | ||
@@ -200,3 +225,3 @@ | ||
}, { | ||
direction: direction, | ||
relation: relation, | ||
children: children | ||
@@ -214,3 +239,3 @@ }); | ||
var path = function path(children, id, labels, record) { | ||
var path = function path(members, id, labels, record) { | ||
return _extends({ | ||
@@ -225,3 +250,3 @@ type: 'path' | ||
}, { | ||
children: children | ||
children: members | ||
}); | ||
@@ -340,2 +365,3 @@ }; | ||
seq: seq, | ||
reduce: reduce, | ||
cons: cons, | ||
@@ -366,3 +392,3 @@ UNIT: UNIT, | ||
export default builder; | ||
export { UNIT, _boolean as boolean, cons, date, dayOfMonth, decimal, edge, flatten, hexadecimal, integer, measurement, node, octal, path, property, record, seq, string, tagged, time, unit, year }; | ||
export { UNIT, _boolean as boolean, cons, date, dayOfMonth, decimal, edge, flatten, hexadecimal, integer, measurement, node, octal, path, property, record, reduce, seq, string, tagged, time, unit, year }; | ||
//# sourceMappingURL=gram-builder.esm.js.map |
{ | ||
"name": "@gram-data/gram-builder", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"license": "MIT", | ||
@@ -44,8 +44,10 @@ "main": "dist/index.js", | ||
"tslib": "^2.0.0", | ||
"typescript": "^3.9.6" | ||
"typescript": "^3.9.6", | ||
"unist-util-inspect": "^6.0.0", | ||
"unist-util-size": "^2.0.0" | ||
}, | ||
"dependencies": { | ||
"@gram-data/gram-ast": "^0.1.7" | ||
"@gram-data/gram-ast": "^0.1.8" | ||
}, | ||
"gitHead": "465acfabcb817c9806d048c47f29afa65107899c", | ||
"gitHead": "767922021318156135c4fc0e755bdaa888f7a057", | ||
"publishConfig": { | ||
@@ -52,0 +54,0 @@ "access": "public" |
@@ -15,3 +15,4 @@ /** | ||
GramLiteral, | ||
RelationshipOperator, | ||
Relation, | ||
Navigation, | ||
BooleanLiteral, | ||
@@ -77,38 +78,54 @@ StringLiteral, | ||
export interface PathDescription { | ||
operands: [] | [GramPathlike] | [GramPathlike, GramPathlike]; | ||
operator?: RelationshipOperator; | ||
export interface PathAttributes { | ||
id?: string; | ||
labels?: string[]; | ||
record?: GramRecord; | ||
relation?: Relation | ||
} | ||
/** | ||
* Reduce paths into a single path composed using the given relation. | ||
* | ||
* @parm relation the relation to apply to all sub-paths | ||
* @param paths sub-paths to be paired | ||
*/ | ||
export const reduce = ( | ||
relation: Relation = 'pair', | ||
paths: Children<GramPathlike>, | ||
): [GramPathlike] | [] => { | ||
const pathlist = normalizeChildren(paths); | ||
if (pathlist) { | ||
if (pathlist.length > 1) { | ||
return [ | ||
pathlist.reduceRight( (acc, curr) => { return cons([curr,acc], {relation}) }, UNIT) | ||
]; | ||
} else { | ||
return [pathlist[0]]; | ||
} | ||
} | ||
return []; | ||
} | ||
/** | ||
* Build any path-like element | ||
* | ||
* @param description | ||
* @param id | ||
* @param labels | ||
* @param record | ||
* @param direction | ||
* @param members sub-paths to compose | ||
* @param attributes attributes | ||
*/ | ||
export const cons = ( | ||
description: PathDescription | ||
// children: [] | [GramPathlike] | [GramPathlike, GramPathlike], | ||
// id?: string, | ||
// labels?: string[], | ||
// record?: GramRecord, | ||
// direction?: RelationshipOperator | ||
members: [] | [GramPathlike] | [GramPathlike, GramPathlike], | ||
attributes: PathAttributes = {} | ||
): GramPathlike => { | ||
const element: any = { | ||
type: 'path', | ||
id: description.id, | ||
...(description.labels && { labels: description.labels }), | ||
...(description.record && { record: description.record }), | ||
children: description.operands.filter(child => child && !isGramUnit(child)), | ||
// children: children.filter(child => (child)), | ||
id: attributes.id, | ||
...(attributes.labels && { labels: attributes.labels }), | ||
...(attributes.record && { record: attributes.record }), | ||
children: members.filter(child => child && !isGramUnit(child)) | ||
}; | ||
if (element.children.length === 0) { | ||
if (element.id) { | ||
if (element.id || (element.labels && element.labels.length > 0) || element.record ) { | ||
element.type = 'node'; | ||
element.id = element.id || identity.shortID(); | ||
return element as GramNode; | ||
@@ -136,4 +153,3 @@ } else { | ||
if ( | ||
description.operator && | ||
description.operator !== 'pair' && | ||
attributes.relation && attributes.relation !== 'pair' && | ||
isGramNode(element.children[0]) && | ||
@@ -144,3 +160,3 @@ isGramNode(element.children[1]) | ||
element.id = element.id || identity.shortID(); | ||
element.direction = description.operator; | ||
element.relation = attributes.relation; | ||
return element as GramEdge; | ||
@@ -150,3 +166,3 @@ } | ||
element.id = element.id || identity.shortID(); | ||
element.direction = description.operator || 'pair'; | ||
element.relation = attributes.relation || 'pair'; | ||
return element as GramPath; | ||
@@ -195,3 +211,3 @@ }; | ||
* @param children | ||
* @param direction | ||
* @param relation | ||
* @param id | ||
@@ -203,3 +219,3 @@ * @param labels | ||
children: [GramNode, GramNode], | ||
direction: RelationshipOperator = 'right', | ||
relation: Navigation = 'right', | ||
id?: string, | ||
@@ -213,3 +229,3 @@ labels?: string[], | ||
...(record && { record }), | ||
direction, | ||
relation, | ||
children, | ||
@@ -227,3 +243,3 @@ }); | ||
export const path = ( | ||
children: [GramPathlike] | [GramPathlike, GramPathlike], | ||
members: [GramPathlike] | [GramPathlike, GramPathlike], | ||
id?: string, | ||
@@ -237,3 +253,3 @@ labels?: string[], | ||
...(record && { record }), | ||
children: children, | ||
children: members, | ||
}); | ||
@@ -240,0 +256,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
82983
1189
10
Updated@gram-data/gram-ast@^0.1.8