@gram-data/gram-builder
Advanced tools
Comparing version 0.2.8 to 0.2.9
@@ -249,3 +249,3 @@ 'use strict'; | ||
var reduceRecord = function reduceRecord(properties) { | ||
var recordToMap = function recordToMap(properties) { | ||
return properties.reduce(function (acc, p) { | ||
@@ -262,3 +262,3 @@ acc[p.name] = p.value; | ||
var unfoldProperties = function unfoldProperties(properties) { | ||
var mapToRecord = function mapToRecord(properties) { | ||
return Object.entries(properties).reduce(function (acc, _ref) { | ||
@@ -271,2 +271,7 @@ var k = _ref[0], | ||
}; | ||
var pluck = function pluck(properties, path) { | ||
return properties.reduce(function (acc, prop) { | ||
return prop.name === path ? prop : acc; | ||
}); | ||
}; | ||
var property = function property(name, value) { | ||
@@ -375,4 +380,4 @@ var Node = { | ||
flatten: flatten, | ||
reduceRecord: reduceRecord, | ||
unfoldProperties: unfoldProperties | ||
recordToMap: recordToMap, | ||
mapToRecord: mapToRecord | ||
}; | ||
@@ -390,4 +395,5 @@ | ||
path: path, | ||
reduceRecord: reduceRecord, | ||
unfoldProperties: unfoldProperties, | ||
recordToMap: recordToMap, | ||
mapToRecord: mapToRecord, | ||
pluck: pluck, | ||
property: property, | ||
@@ -424,2 +430,3 @@ boolean: _boolean, | ||
exports.integer = integer; | ||
exports.mapToRecord = mapToRecord; | ||
exports.measurement = measurement; | ||
@@ -429,5 +436,6 @@ exports.node = node; | ||
exports.path = path; | ||
exports.pluck = pluck; | ||
exports.property = property; | ||
exports.recordToMap = recordToMap; | ||
exports.reduce = reduce; | ||
exports.reduceRecord = reduceRecord; | ||
exports.seq = seq; | ||
@@ -437,4 +445,3 @@ exports.string = string; | ||
exports.time = time; | ||
exports.unfoldProperties = unfoldProperties; | ||
exports.year = year; | ||
//# sourceMappingURL=gram-builder.cjs.development.js.map |
@@ -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,n,o,i){return t({type:"seq",id:n},o&&{labels:o},i&&{record:i},{children:r(e)})},o=function(e,t,r){return void 0===e&&(e="pair"),t.length>1?t.reduceRight((function(t,n){return i([n,t],{relation:e,id:r?""+r+0:void 0})}),a):t[0]},i=function(r,n){void 0===n&&(n={});var o=t({type:"path"},n.id&&{id:n.id},n.labels&&{labels:n.labels},n.record&&{record:n.record});if(void 0===r)return o.id&&o.id!==e.EMPTY_PATH_ID?(o.children=[],o):(o.children=void 0,a);if(0===r.length)return o.id===e.EMPTY_PATH_ID?a:(o.children=[],o);if(1===r.length){var i=r[0];return e.isGramEmptyPath(i)?(o.children=[],o):(o.children=[i],o)}if(2===r.length){if(n.relation&&"pair"!==n.relation&&e.isGramNode(r[0])&&e.isGramNode(r[1]))return o.relation=n.relation,o.children=[r[0],r[1]],o;if(e.isGramEmptyPath(r[0])&&e.isGramEmptyPath(r[1]))return o.relation=n.relation,o.children=[],o;o.children=[r[0],r[1]]}return o.relation=n.relation||"pair",o},a={type:"path",id:e.EMPTY_PATH_ID,labels:void 0,record:void 0,children:void 0},u=function(){return a},l=function(e,r,n){return t({type:"path"},e&&{id:e},r&&{labels:r},n&&{record:n},{children:[]})},d=function(e,r,n,o,i){return t({type:"path",id:n},o&&{labels:o},i&&{record:i},{relation:r,children:e})},c=function(e,r,n,o){return t({type:"path",id:r},n&&{labels:n},o&&{record:o},{children:e})},s=function(e){return e.reduce((function(e,t){return e[t.name]=t.value,e}),{})},p=function(e){return Object.entries(e).reduce((function(e,t){return e.push(f(t[0],t[1])),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}},m=function(e,t){return{type:"tagged",value:t,tag:e}},y=function(e){return{type:"integer",value:String(e)}},x=function(e){return{type:"decimal",value:String(e)}},v=function(e){return{type:"hexadecimal",value:"number"==typeof e?e.toString(16):e}},b=function(e){return{type:"octal",value:"number"==typeof e?e.toString(8):e}},P=function(e,t){return{type:"measurement",value:String(t),unit:e}},T=function(e){return m("date",e instanceof Date?e.getFullYear().toString():e)},_=function(e){return m("date",e instanceof Date?e.toISOString().slice(0,10):e)},M=function(e){return m("date",e instanceof Date?"--"+e.toISOString().slice(5,10):e)},S=function(e){return m("time",e instanceof Date?e.toTimeString():e)},D=function(e){return m("duration",e instanceof Date?"P"+(e.getUTCFullYear()-1970)+"Y"+e.getUTCMonth()+"M"+e.getUTCDate()+"DT"+e.getUTCHours()+"H"+e.getUTCMinutes()+"M"+e.getUTCMilliseconds()/1e3+"S":e)},O=function(e,t){return void 0===t&&(t=1),e.flat(t).filter((function(e){return null!==e}))},E={__proto__:null,seq:n,reduce:o,cons:i,EMPTY_PATH:a,empty:u,node:l,edge:d,path:c,reduceRecord:s,unfoldProperties:p,property:f,boolean:g,string:h,tagged:m,integer:y,decimal:x,hexadecimal:v,octal:b,measurement:P,year:T,date:_,dayOfMonth:M,time:S,duration:D,flatten:O,default:{seq:n,empty:u,cons:i,path:c,node:l,edge:d,property:f,boolean:g,string:h,tagged:m,integer:y,decimal:x,hexadecimal:v,octal:b,measurement:P,date:_,time:S,duration:D,flatten:O,reduceRecord:s,unfoldProperties:p}};exports.EMPTY_PATH=a,exports.boolean=g,exports.builder=E,exports.cons=i,exports.date=_,exports.dayOfMonth=M,exports.decimal=x,exports.duration=D,exports.edge=d,exports.empty=u,exports.flatten=O,exports.hexadecimal=v,exports.integer=y,exports.measurement=P,exports.node=l,exports.octal=b,exports.path=c,exports.property=f,exports.reduce=o,exports.reduceRecord=s,exports.seq=n,exports.string=h,exports.tagged=m,exports.time=S,exports.unfoldProperties=p,exports.year=T; | ||
"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,n,o,i){return t({type:"seq",id:n},o&&{labels:o},i&&{record:i},{children:r(e)})},o=function(e,t,r){return void 0===e&&(e="pair"),t.length>1?t.reduceRight((function(t,n){return i([n,t],{relation:e,id:r?""+r+0:void 0})}),a):t[0]},i=function(r,n){void 0===n&&(n={});var o=t({type:"path"},n.id&&{id:n.id},n.labels&&{labels:n.labels},n.record&&{record:n.record});if(void 0===r)return o.id&&o.id!==e.EMPTY_PATH_ID?(o.children=[],o):(o.children=void 0,a);if(0===r.length)return o.id===e.EMPTY_PATH_ID?a:(o.children=[],o);if(1===r.length){var i=r[0];return e.isGramEmptyPath(i)?(o.children=[],o):(o.children=[i],o)}if(2===r.length){if(n.relation&&"pair"!==n.relation&&e.isGramNode(r[0])&&e.isGramNode(r[1]))return o.relation=n.relation,o.children=[r[0],r[1]],o;if(e.isGramEmptyPath(r[0])&&e.isGramEmptyPath(r[1]))return o.relation=n.relation,o.children=[],o;o.children=[r[0],r[1]]}return o.relation=n.relation||"pair",o},a={type:"path",id:e.EMPTY_PATH_ID,labels:void 0,record:void 0,children:void 0},u=function(){return a},c=function(e,r,n){return t({type:"path"},e&&{id:e},r&&{labels:r},n&&{record:n},{children:[]})},l=function(e,r,n,o,i){return t({type:"path",id:n},o&&{labels:o},i&&{record:i},{relation:r,children:e})},d=function(e,r,n,o){return t({type:"path",id:r},n&&{labels:n},o&&{record:o},{children:e})},p=function(e){return e.reduce((function(e,t){return e[t.name]=t.value,e}),{})},s=function(e){return Object.entries(e).reduce((function(e,t){return e.push(g(t[0],t[1])),e}),[])},f=function(e,t){return e.reduce((function(e,r){return r.name===t?r:e}))},g=function(e,t){return{type:"property",name:e,value:t}},m=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}},x=function(e){return{type:"integer",value:String(e)}},v=function(e){return{type:"decimal",value:String(e)}},T=function(e){return{type:"hexadecimal",value:"number"==typeof e?e.toString(16):e}},b=function(e){return{type:"octal",value:"number"==typeof e?e.toString(8):e}},M=function(e,t){return{type:"measurement",value:String(t),unit:e}},P=function(e){return y("date",e instanceof Date?e.getFullYear().toString():e)},_=function(e){return y("date",e instanceof Date?e.toISOString().slice(0,10):e)},S=function(e){return y("date",e instanceof Date?"--"+e.toISOString().slice(5,10):e)},D=function(e){return y("time",e instanceof Date?e.toTimeString():e)},O=function(e){return y("duration",e instanceof Date?"P"+(e.getUTCFullYear()-1970)+"Y"+e.getUTCMonth()+"M"+e.getUTCDate()+"DT"+e.getUTCHours()+"H"+e.getUTCMinutes()+"M"+e.getUTCMilliseconds()/1e3+"S":e)},E=function(e,t){return void 0===t&&(t=1),e.flat(t).filter((function(e){return null!==e}))},Y={__proto__:null,seq:n,reduce:o,cons:i,EMPTY_PATH:a,empty:u,node:c,edge:l,path:d,recordToMap:p,mapToRecord:s,pluck:f,property:g,boolean:m,string:h,tagged:y,integer:x,decimal:v,hexadecimal:T,octal:b,measurement:M,year:P,date:_,dayOfMonth:S,time:D,duration:O,flatten:E,default:{seq:n,empty:u,cons:i,path:d,node:c,edge:l,property:g,boolean:m,string:h,tagged:y,integer:x,decimal:v,hexadecimal:T,octal:b,measurement:M,date:_,time:D,duration:O,flatten:E,recordToMap:p,mapToRecord:s}};exports.EMPTY_PATH=a,exports.boolean=m,exports.builder=Y,exports.cons=i,exports.date=_,exports.dayOfMonth=S,exports.decimal=v,exports.duration=O,exports.edge=l,exports.empty=u,exports.flatten=E,exports.hexadecimal=T,exports.integer=x,exports.mapToRecord=s,exports.measurement=M,exports.node=c,exports.octal=b,exports.path=d,exports.pluck=f,exports.property=g,exports.recordToMap=p,exports.reduce=o,exports.seq=n,exports.string=h,exports.tagged=y,exports.time=D,exports.year=P; | ||
//# sourceMappingURL=gram-builder.cjs.production.min.js.map |
@@ -80,3 +80,3 @@ /** | ||
*/ | ||
export declare const reduceRecord: (properties: GramRecord) => GramPropertyMap; | ||
export declare const recordToMap: (properties: GramRecord) => GramPropertyMap; | ||
/** | ||
@@ -87,3 +87,4 @@ * Unfolds a property map<string,GramRecordValue> into a property list[GramProperty]. | ||
*/ | ||
export declare const unfoldProperties: (properties: GramPropertyMap) => GramRecord; | ||
export declare const mapToRecord: (properties: GramPropertyMap) => GramRecord; | ||
export declare const pluck: (properties: GramRecord, path: string) => GramProperty; | ||
export declare const property: (name: string, value: GramRecordValue) => GramProperty; | ||
@@ -124,5 +125,5 @@ export declare const boolean: (value: boolean) => BooleanLiteral; | ||
flatten: (xs: any[], depth?: number) => any[]; | ||
reduceRecord: (properties: GramRecord) => GramPropertyMap; | ||
unfoldProperties: (properties: GramPropertyMap) => GramRecord; | ||
recordToMap: (properties: GramRecord) => GramPropertyMap; | ||
mapToRecord: (properties: GramPropertyMap) => GramRecord; | ||
}; | ||
export default _default; |
@@ -245,3 +245,3 @@ import { EMPTY_PATH_ID, isGramEmptyPath, isGramNode } from '@gram-data/gram-ast'; | ||
var reduceRecord = function reduceRecord(properties) { | ||
var recordToMap = function recordToMap(properties) { | ||
return properties.reduce(function (acc, p) { | ||
@@ -258,3 +258,3 @@ acc[p.name] = p.value; | ||
var unfoldProperties = function unfoldProperties(properties) { | ||
var mapToRecord = function mapToRecord(properties) { | ||
return Object.entries(properties).reduce(function (acc, _ref) { | ||
@@ -267,2 +267,7 @@ var k = _ref[0], | ||
}; | ||
var pluck = function pluck(properties, path) { | ||
return properties.reduce(function (acc, prop) { | ||
return prop.name === path ? prop : acc; | ||
}); | ||
}; | ||
var property = function property(name, value) { | ||
@@ -371,4 +376,4 @@ var Node = { | ||
flatten: flatten, | ||
reduceRecord: reduceRecord, | ||
unfoldProperties: unfoldProperties | ||
recordToMap: recordToMap, | ||
mapToRecord: mapToRecord | ||
}; | ||
@@ -386,4 +391,5 @@ | ||
path: path, | ||
reduceRecord: reduceRecord, | ||
unfoldProperties: unfoldProperties, | ||
recordToMap: recordToMap, | ||
mapToRecord: mapToRecord, | ||
pluck: pluck, | ||
property: property, | ||
@@ -407,3 +413,3 @@ boolean: _boolean, | ||
export { EMPTY_PATH, _boolean as boolean, gramBuilder$1 as builder, cons, date, dayOfMonth, decimal, duration, edge, empty, flatten, hexadecimal, integer, measurement, node, octal, path, property, reduce, reduceRecord, seq, string, tagged, time, unfoldProperties, year }; | ||
export { EMPTY_PATH, _boolean as boolean, gramBuilder$1 as builder, cons, date, dayOfMonth, decimal, duration, edge, empty, flatten, hexadecimal, integer, mapToRecord, measurement, node, octal, path, pluck, property, recordToMap, reduce, seq, string, tagged, time, year }; | ||
//# sourceMappingURL=gram-builder.esm.js.map |
@@ -304,3 +304,3 @@ (function (global, factory) { | ||
var reduceRecord = function reduceRecord(properties) { | ||
var recordToMap = function recordToMap(properties) { | ||
return properties.reduce(function (acc, p) { | ||
@@ -317,3 +317,3 @@ acc[p.name] = p.value; | ||
var unfoldProperties = function unfoldProperties(properties) { | ||
var mapToRecord = function mapToRecord(properties) { | ||
return Object.entries(properties).reduce(function (acc, _ref) { | ||
@@ -326,2 +326,7 @@ var k = _ref[0], | ||
}; | ||
var pluck = function pluck(properties, path) { | ||
return properties.reduce(function (acc, prop) { | ||
return prop.name === path ? prop : acc; | ||
}); | ||
}; | ||
var property = function property(name, value) { | ||
@@ -430,4 +435,4 @@ var Node = { | ||
flatten: flatten, | ||
reduceRecord: reduceRecord, | ||
unfoldProperties: unfoldProperties | ||
recordToMap: recordToMap, | ||
mapToRecord: mapToRecord | ||
}; | ||
@@ -445,4 +450,5 @@ | ||
path: path, | ||
reduceRecord: reduceRecord, | ||
unfoldProperties: unfoldProperties, | ||
recordToMap: recordToMap, | ||
mapToRecord: mapToRecord, | ||
pluck: pluck, | ||
property: property, | ||
@@ -479,2 +485,3 @@ boolean: _boolean, | ||
exports.integer = integer; | ||
exports.mapToRecord = mapToRecord; | ||
exports.measurement = measurement; | ||
@@ -484,5 +491,6 @@ exports.node = node; | ||
exports.path = path; | ||
exports.pluck = pluck; | ||
exports.property = property; | ||
exports.recordToMap = recordToMap; | ||
exports.reduce = reduce; | ||
exports.reduceRecord = reduceRecord; | ||
exports.seq = seq; | ||
@@ -492,3 +500,2 @@ exports.string = string; | ||
exports.time = time; | ||
exports.unfoldProperties = unfoldProperties; | ||
exports.year = year; | ||
@@ -495,0 +502,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e=e||self).gram=e.gram||{},e.gram.builder={}))}(this,(function(e){"use strict";function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var n=function(e){return!!e.type&&"path"===e.type},r=function(e){return n(e)&&void 0===e.children&&"ø"===e.id},i=function(e){return n(e)&&e.children&&0===e.children.length&&"ø"!==e.id};function o(e){return Array.isArray(e)?e:e instanceof Function?o(e()):void 0===e?[]:[e]}var u=function(e,n,r,i){return t({type:"seq",id:n},r&&{labels:r},i&&{record:i},{children:o(e)})},a=function(e,t,n){return void 0===e&&(e="pair"),t.length>1?t.reduceRight((function(t,r){return d([r,t],{relation:e,id:n?""+n+0:void 0})}),l):t[0]},d=function(e,n){void 0===n&&(n={});var o=t({type:"path"},n.id&&{id:n.id},n.labels&&{labels:n.labels},n.record&&{record:n.record});if(void 0===e)return o.id&&"ø"!==o.id?(o.children=[],o):(o.children=void 0,l);if(0===e.length)return"ø"===o.id?l:(o.children=[],o);if(1===e.length){var u=e[0];return r(u)?(o.children=[],o):(o.children=[u],o)}if(2===e.length){if(n.relation&&"pair"!==n.relation&&i(e[0])&&i(e[1]))return o.relation=n.relation,o.children=[e[0],e[1]],o;if(r(e[0])&&r(e[1]))return o.relation=n.relation,o.children=[],o;o.children=[e[0],e[1]]}return o.relation=n.relation||"pair",o},l={type:"path",id:"ø",labels:void 0,record:void 0,children:void 0},c=function(){return l},f=function(e,n,r){return t({type:"path"},e&&{id:e},n&&{labels:n},r&&{record:r},{children:[]})},p=function(e,n,r,i,o){return t({type:"path",id:r},i&&{labels:i},o&&{record:o},{relation:n,children:e})},s=function(e,n,r,i){return t({type:"path",id:n},r&&{labels:r},i&&{record:i},{children:e})},g=function(e){return e.reduce((function(e,t){return e[t.name]=t.value,e}),{})},h=function(e){return Object.entries(e).reduce((function(e,t){return e.push(y(t[0],t[1])),e}),[])},y=function(e,t){return{type:"property",name:e,value:t}},m=function(e){return{type:"boolean",value:e?"true":"false"}},v=function(e){return{type:"string",value:e}},b=function(e,t){return{type:"tagged",value:t,tag:e}},S=function(e){return{type:"integer",value:String(e)}},T=function(e){return{type:"decimal",value:String(e)}},M=function(e){return{type:"hexadecimal",value:"number"==typeof e?e.toString(16):e}},P=function(e){return{type:"octal",value:"number"==typeof e?e.toString(8):e}},O=function(e,t){return{type:"measurement",value:String(t),unit:e}},_=function(e){return b("date",e instanceof Date?e.getFullYear().toString():e)},x=function(e){return b("date",e instanceof Date?e.toISOString().slice(0,10):e)},D=function(e){return b("date",e instanceof Date?"--"+e.toISOString().slice(5,10):e)},C=function(e){return b("time",e instanceof Date?e.toTimeString():e)},U=function(e){return b("duration",e instanceof Date?"P"+(e.getUTCFullYear()-1970)+"Y"+e.getUTCMonth()+"M"+e.getUTCDate()+"DT"+e.getUTCHours()+"H"+e.getUTCMinutes()+"M"+e.getUTCMilliseconds()/1e3+"S":e)},j=function(e,t){return void 0===t&&(t=1),e.flat(t).filter((function(e){return null!==e}))},Y={__proto__:null,seq:u,reduce:a,cons:d,EMPTY_PATH:l,empty:c,node:f,edge:p,path:s,reduceRecord:g,unfoldProperties:h,property:y,boolean:m,string:v,tagged:b,integer:S,decimal:T,hexadecimal:M,octal:P,measurement:O,year:_,date:x,dayOfMonth:D,time:C,duration:U,flatten:j,default:{seq:u,empty:c,cons:d,path:s,node:f,edge:p,property:y,boolean:m,string:v,tagged:b,integer:S,decimal:T,hexadecimal:M,octal:P,measurement:O,date:x,time:C,duration:U,flatten:j,reduceRecord:g,unfoldProperties:h}};e.EMPTY_PATH=l,e.boolean=m,e.builder=Y,e.cons=d,e.date=x,e.dayOfMonth=D,e.decimal=T,e.duration=U,e.edge=p,e.empty=c,e.flatten=j,e.hexadecimal=M,e.integer=S,e.measurement=O,e.node=f,e.octal=P,e.path=s,e.property=y,e.reduce=a,e.reduceRecord=g,e.seq=u,e.string=v,e.tagged=b,e.time=C,e.unfoldProperties=h,e.year=_,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e=e||self).gram=e.gram||{},e.gram.builder={}))}(this,(function(e){"use strict";function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var n=function(e){return!!e.type&&"path"===e.type},r=function(e){return n(e)&&void 0===e.children&&"ø"===e.id},i=function(e){return n(e)&&e.children&&0===e.children.length&&"ø"!==e.id};function o(e){return Array.isArray(e)?e:e instanceof Function?o(e()):void 0===e?[]:[e]}var a=function(e,n,r,i){return t({type:"seq",id:n},r&&{labels:r},i&&{record:i},{children:o(e)})},u=function(e,t,n){return void 0===e&&(e="pair"),t.length>1?t.reduceRight((function(t,r){return c([r,t],{relation:e,id:n?""+n+0:void 0})}),d):t[0]},c=function(e,n){void 0===n&&(n={});var o=t({type:"path"},n.id&&{id:n.id},n.labels&&{labels:n.labels},n.record&&{record:n.record});if(void 0===e)return o.id&&"ø"!==o.id?(o.children=[],o):(o.children=void 0,d);if(0===e.length)return"ø"===o.id?d:(o.children=[],o);if(1===e.length){var a=e[0];return r(a)?(o.children=[],o):(o.children=[a],o)}if(2===e.length){if(n.relation&&"pair"!==n.relation&&i(e[0])&&i(e[1]))return o.relation=n.relation,o.children=[e[0],e[1]],o;if(r(e[0])&&r(e[1]))return o.relation=n.relation,o.children=[],o;o.children=[e[0],e[1]]}return o.relation=n.relation||"pair",o},d={type:"path",id:"ø",labels:void 0,record:void 0,children:void 0},l=function(){return d},f=function(e,n,r){return t({type:"path"},e&&{id:e},n&&{labels:n},r&&{record:r},{children:[]})},p=function(e,n,r,i,o){return t({type:"path",id:r},i&&{labels:i},o&&{record:o},{relation:n,children:e})},s=function(e,n,r,i){return t({type:"path",id:n},r&&{labels:r},i&&{record:i},{children:e})},g=function(e){return e.reduce((function(e,t){return e[t.name]=t.value,e}),{})},h=function(e){return Object.entries(e).reduce((function(e,t){return e.push(m(t[0],t[1])),e}),[])},y=function(e,t){return e.reduce((function(e,n){return n.name===t?n:e}))},m=function(e,t){return{type:"property",name:e,value:t}},v=function(e){return{type:"boolean",value:e?"true":"false"}},b=function(e){return{type:"string",value:e}},T=function(e,t){return{type:"tagged",value:t,tag:e}},M=function(e){return{type:"integer",value:String(e)}},S=function(e){return{type:"decimal",value:String(e)}},O=function(e){return{type:"hexadecimal",value:"number"==typeof e?e.toString(16):e}},_=function(e){return{type:"octal",value:"number"==typeof e?e.toString(8):e}},x=function(e,t){return{type:"measurement",value:String(t),unit:e}},D=function(e){return T("date",e instanceof Date?e.getFullYear().toString():e)},P=function(e){return T("date",e instanceof Date?e.toISOString().slice(0,10):e)},C=function(e){return T("date",e instanceof Date?"--"+e.toISOString().slice(5,10):e)},U=function(e){return T("time",e instanceof Date?e.toTimeString():e)},j=function(e){return T("duration",e instanceof Date?"P"+(e.getUTCFullYear()-1970)+"Y"+e.getUTCMonth()+"M"+e.getUTCDate()+"DT"+e.getUTCHours()+"H"+e.getUTCMinutes()+"M"+e.getUTCMilliseconds()/1e3+"S":e)},Y=function(e,t){return void 0===t&&(t=1),e.flat(t).filter((function(e){return null!==e}))},q={__proto__:null,seq:a,reduce:u,cons:c,EMPTY_PATH:d,empty:l,node:f,edge:p,path:s,recordToMap:g,mapToRecord:h,pluck:y,property:m,boolean:v,string:b,tagged:T,integer:M,decimal:S,hexadecimal:O,octal:_,measurement:x,year:D,date:P,dayOfMonth:C,time:U,duration:j,flatten:Y,default:{seq:a,empty:l,cons:c,path:s,node:f,edge:p,property:m,boolean:v,string:b,tagged:T,integer:M,decimal:S,hexadecimal:O,octal:_,measurement:x,date:P,time:U,duration:j,flatten:Y,recordToMap:g,mapToRecord:h}};e.EMPTY_PATH=d,e.boolean=v,e.builder=q,e.cons=c,e.date=P,e.dayOfMonth=C,e.decimal=S,e.duration=j,e.edge=p,e.empty=l,e.flatten=Y,e.hexadecimal=O,e.integer=M,e.mapToRecord=h,e.measurement=x,e.node=f,e.octal=_,e.path=s,e.pluck=y,e.property=m,e.recordToMap=g,e.reduce=u,e.seq=a,e.string=b,e.tagged=T,e.time=U,e.year=D,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=gram-builder.umd.production.min.js.map |
@@ -8,3 +8,3 @@ { | ||
], | ||
"version": "0.2.8", | ||
"version": "0.2.9", | ||
"license": "MIT", | ||
@@ -54,5 +54,5 @@ "repository": { | ||
"@types/unist": "^2.0.3", | ||
"@typescript-eslint/parser": "^4.6.0", | ||
"@typescript-eslint/parser": "^4.8.1", | ||
"husky": "^4.3.0", | ||
"npm-check-updates": "^9.2.3", | ||
"npm-check-updates": "^10.2.1", | ||
"npm-run-all": "^4.1.5", | ||
@@ -69,5 +69,5 @@ "serve": "^11.3.2", | ||
"dependencies": { | ||
"@gram-data/gram-ast": "^0.2.8" | ||
"@gram-data/gram-ast": "^0.2.9" | ||
}, | ||
"gitHead": "3d28a7b7186d406e75bfd22aac54cd1b4ba0dbfa", | ||
"gitHead": "1ff6bdb1c799a29a95540314bdb5b2a881971774", | ||
"publishConfig": { | ||
@@ -74,0 +74,0 @@ "access": "public" |
@@ -7,3 +7,3 @@ From nothing to a valid gram AST. | ||
``` | ||
``` bash | ||
npm install @gram-data/gram-builder | ||
@@ -14,3 +14,3 @@ ``` | ||
``` | ||
``` TypeScript | ||
import { node, edge } from '@gram-data/gram-builder'; | ||
@@ -17,0 +17,0 @@ |
@@ -255,3 +255,3 @@ /** | ||
*/ | ||
export const reduceRecord = (properties: GramRecord): GramPropertyMap => { | ||
export const recordToMap = (properties: GramRecord): GramPropertyMap => { | ||
return properties.reduce((acc: GramPropertyMap, p: GramProperty) => { | ||
@@ -268,3 +268,3 @@ acc[p.name] = p.value; | ||
*/ | ||
export const unfoldProperties = (properties: GramPropertyMap): GramRecord => { | ||
export const mapToRecord = (properties: GramPropertyMap): GramRecord => { | ||
return Object.entries(properties).reduce((acc: GramRecord, [k, v]) => { | ||
@@ -276,2 +276,8 @@ acc.push(property(k, v)); | ||
export const pluck = (properties: GramRecord, path:string) => { | ||
return properties.reduce( (acc, prop) => { | ||
return prop.name === path ? prop : acc | ||
}) | ||
} | ||
export const property = ( | ||
@@ -391,4 +397,4 @@ name: string, | ||
flatten, | ||
reduceRecord, | ||
unfoldProperties, | ||
recordToMap, | ||
mapToRecord, | ||
}; |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
142857
1778
Updated@gram-data/gram-ast@^0.2.9