Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@gram-data/gram-builder

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gram-data/gram-builder - npm Package Compare versions

Comparing version 0.2.15 to 0.2.18

35

dist/gram-builder.cjs.development.js

@@ -386,3 +386,3 @@ 'use strict';

};
var gramBuilder = {
var index = {
seq: seq,

@@ -412,35 +412,3 @@ empty: empty,

var gramBuilder$1 = {
__proto__: null,
seq: seq,
listToPath: listToPath,
cons: cons,
empty: empty,
node: node,
edge: edge,
path: path,
pair: pair,
recordToMap: recordToMap,
mapToRecord: mapToRecord,
pluck: pluck,
property: property,
boolean: _boolean,
string: string,
tagged: tagged,
integer: integer,
decimal: decimal,
hexadecimal: hexadecimal,
octal: octal,
measurement: measurement,
year: year,
date: date,
dayOfMonth: dayOfMonth,
time: time,
duration: duration,
flatten: flatten,
'default': gramBuilder
};
exports.boolean = _boolean;
exports.builder = gramBuilder$1;
exports.cons = cons;

@@ -450,2 +418,3 @@ exports.date = date;

exports.decimal = decimal;
exports.default = index;
exports.duration = duration;

@@ -452,0 +421,0 @@ exports.edge = edge;

2

dist/gram-builder.cjs.production.min.js

@@ -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,i,o){return t({type:"seq",id:n},i&&{labels:i},o&&{record:o},{children:r(e)})},i=function(e,t){return void 0===e&&(e="pair"),t.length>1?t.slice(0,t.length-1).reduceRight((function(t,r){return o([r,t],{kind:e})}),t[t.length-1]):t[0]},o=function(r,n){void 0===n&&(n={});var i=t({type:"path"},n.id&&{id:n.id},n.labels&&{labels:n.labels},n.record&&{record:n.record});if(void 0===r)return i.id&&i.id!==e.EMPTY_PATH_ID?(i.children=[],i):(i.children=void 0,a);if(0===r.length)return i.id===e.EMPTY_PATH_ID?a:(i.children=[],i);if(1===r.length){var o=r[0];return e.isGramEmptyPath(o)?(i.children=[],i):(i.children=[o],i)}if(2===r.length){if(n.kind&&"pair"!==n.kind&&e.isGramNode(r[0])&&e.isGramNode(r[1]))return i.kind=n.kind,i.children=[r[0],r[1]],i;if(e.isGramEmptyPath(r[0])&&e.isGramEmptyPath(r[1]))return i.kind=n.kind,i.children=[],i;i.children=[r[0],r[1]]}return i.kind=n.kind||"pair",i},a={type:"path",id:e.EMPTY_PATH_ID,labels:void 0,record:void 0,children:[]},u=function(){return a},c=function(e,r,n){return t({type:"path"},e&&{id:e},r&&{labels:r},n&&{record:n},{children:[]})},d=function(e,r,n,i,o){return t({type:"path",id:n},i&&{labels:i},o&&{record:o},{kind:r,children:e})},l=function(e,r,n,i,o){return t({type:"path",kind:e,id:n},i&&{labels:i},o&&{record:o},{children:r})},p=function(e,t,r,n){return l("pair",e,t,r,n)},s=function(e){return e.reduce((function(e,t){return e[t.name]=t.value,e}),{})},f=function(e){return Object.entries(e).reduce((function(e,t){return e.push(h(t[0],t[1])),e}),[])},g=function(e,t){return e.reduce((function(e,r){return r.name===t?r:e}))},h=function(e,t){return{type:"property",name:e,value:t}},m=function(e){return{type:"boolean",value:e?"true":"false"}},y=function(e){return{type:"string",value:e}},x=function(e,t){return{type:"tagged",value:t,tag:e}},v=function(e){return{type:"integer",value:String(e)}},T=function(e){return{type:"decimal",value:String(e)}},b=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}},M=function(e,t){return{type:"measurement",value:String(t),unit:e}},k=function(e){return x("date",e instanceof Date?e.getFullYear().toString():e)},S=function(e){return x("date",e instanceof Date?e.toISOString().slice(0,10):e)},_=function(e){return x("date",e instanceof Date?"--"+e.toISOString().slice(5,10):e)},D=function(e){return x("time",e instanceof Date?e.toTimeString():e)},O=function(e){return x("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)},C=function(e,t){return void 0===t&&(t=1),e.flat(t).filter((function(e){return null!==e}))},E={__proto__:null,seq:n,listToPath:i,cons:o,empty:u,node:c,edge:d,path:l,pair:p,recordToMap:s,mapToRecord:f,pluck:g,property:h,boolean:m,string:y,tagged:x,integer:v,decimal:T,hexadecimal:b,octal:P,measurement:M,year:k,date:S,dayOfMonth:_,time:D,duration:O,flatten:C,default:{seq:n,empty:u,cons:o,pair:p,listToPath:i,node:c,edge:d,property:h,boolean:m,string:y,tagged:x,integer:v,decimal:T,hexadecimal:b,octal:P,measurement:M,date:S,time:D,duration:O,flatten:C,recordToMap:s,mapToRecord:f}};exports.boolean=m,exports.builder=E,exports.cons=o,exports.date=S,exports.dayOfMonth=_,exports.decimal=T,exports.duration=O,exports.edge=d,exports.empty=u,exports.flatten=C,exports.hexadecimal=b,exports.integer=v,exports.listToPath=i,exports.mapToRecord=f,exports.measurement=M,exports.node=c,exports.octal=P,exports.pair=p,exports.path=l,exports.pluck=g,exports.property=h,exports.recordToMap=s,exports.seq=n,exports.string=y,exports.tagged=x,exports.time=D,exports.year=k;
"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,i,o){return t({type:"seq",id:n},i&&{labels:i},o&&{record:o},{children:r(e)})},i=function(e,t){return void 0===e&&(e="pair"),t.length>1?t.slice(0,t.length-1).reduceRight((function(t,r){return o([r,t],{kind:e})}),t[t.length-1]):t[0]},o=function(r,n){void 0===n&&(n={});var i=t({type:"path"},n.id&&{id:n.id},n.labels&&{labels:n.labels},n.record&&{record:n.record});if(void 0===r)return i.id&&i.id!==e.EMPTY_PATH_ID?(i.children=[],i):(i.children=void 0,a);if(0===r.length)return i.id===e.EMPTY_PATH_ID?a:(i.children=[],i);if(1===r.length){var o=r[0];return e.isGramEmptyPath(o)?(i.children=[],i):(i.children=[o],i)}if(2===r.length){if(n.kind&&"pair"!==n.kind&&e.isGramNode(r[0])&&e.isGramNode(r[1]))return i.kind=n.kind,i.children=[r[0],r[1]],i;if(e.isGramEmptyPath(r[0])&&e.isGramEmptyPath(r[1]))return i.kind=n.kind,i.children=[],i;i.children=[r[0],r[1]]}return i.kind=n.kind||"pair",i},a={type:"path",id:e.EMPTY_PATH_ID,labels:void 0,record:void 0,children:[]},u=function(){return a},c=function(e,r,n){return t({type:"path"},e&&{id:e},r&&{labels:r},n&&{record:n},{children:[]})},d=function(e,r,n,i,o){return t({type:"path",id:n},i&&{labels:i},o&&{record:o},{kind:r,children:e})},l=function(e,r,n,i,o){return t({type:"path",kind:e,id:n},i&&{labels:i},o&&{record:o},{children:r})},p=function(e,t,r,n){return l("pair",e,t,r,n)},s=function(e){return e.reduce((function(e,t){return e[t.name]=t.value,e}),{})},f=function(e){return Object.entries(e).reduce((function(e,t){return e.push(g(t[0],t[1])),e}),[])},g=function(e,t){return{type:"property",name:e,value:t}},h=function(e){return{type:"boolean",value:e?"true":"false"}},m=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}},P=function(e,t){return{type:"measurement",value:String(t),unit:e}},k=function(e){return y("date",e instanceof Date?e.toISOString().slice(0,10):e)},M=function(e){return y("time",e instanceof Date?e.toTimeString():e)},S=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)},D=function(e,t){return void 0===t&&(t=1),e.flat(t).filter((function(e){return null!==e}))},O={seq:n,empty:u,cons:o,pair:p,listToPath:i,node:c,edge:d,property:g,boolean:h,string:m,tagged:y,integer:x,decimal:v,hexadecimal:T,octal:b,measurement:P,date:k,time:M,duration:S,flatten:D,recordToMap:s,mapToRecord:f};exports.boolean=h,exports.cons=o,exports.date=k,exports.dayOfMonth=function(e){return y("date",e instanceof Date?"--"+e.toISOString().slice(5,10):e)},exports.decimal=v,exports.default=O,exports.duration=S,exports.edge=d,exports.empty=u,exports.flatten=D,exports.hexadecimal=T,exports.integer=x,exports.listToPath=i,exports.mapToRecord=f,exports.measurement=P,exports.node=c,exports.octal=b,exports.pair=p,exports.path=l,exports.pluck=function(e,t){return e.reduce((function(e,r){return r.name===t?r:e}))},exports.property=g,exports.recordToMap=s,exports.seq=n,exports.string=m,exports.tagged=y,exports.time=M,exports.year=function(e){return y("date",e instanceof Date?e.getFullYear().toString():e)};
//# sourceMappingURL=gram-builder.cjs.production.min.js.map

@@ -382,3 +382,3 @@ import { EMPTY_PATH_ID, isGramEmptyPath, isGramNode } from '@gram-data/gram-ast';

};
var gramBuilder = {
var index = {
seq: seq,

@@ -408,34 +408,4 @@ empty: empty,

var gramBuilder$1 = {
__proto__: null,
seq: seq,
listToPath: listToPath,
cons: cons,
empty: empty,
node: node,
edge: edge,
path: path,
pair: pair,
recordToMap: recordToMap,
mapToRecord: mapToRecord,
pluck: pluck,
property: property,
boolean: _boolean,
string: string,
tagged: tagged,
integer: integer,
decimal: decimal,
hexadecimal: hexadecimal,
octal: octal,
measurement: measurement,
year: year,
date: date,
dayOfMonth: dayOfMonth,
time: time,
duration: duration,
flatten: flatten,
'default': gramBuilder
};
export { _boolean as boolean, gramBuilder$1 as builder, cons, date, dayOfMonth, decimal, duration, edge, empty, flatten, hexadecimal, integer, listToPath, mapToRecord, measurement, node, octal, pair, path, pluck, property, recordToMap, seq, string, tagged, time, year };
export default index;
export { _boolean as boolean, cons, date, dayOfMonth, decimal, duration, edge, empty, flatten, hexadecimal, integer, listToPath, mapToRecord, measurement, node, octal, pair, path, pluck, property, recordToMap, seq, string, tagged, time, year };
//# sourceMappingURL=gram-builder.esm.js.map

@@ -35,3 +35,7 @@ (function (global, factory) {

};
/**
* Constant identity for empty paths: `ø`.
*/
var EMPTY_PATH_ID = 'ø';

@@ -41,8 +45,2 @@ /**

*
* In practice both nodes and empty paths both have no children.
* The distinguishing feature is that all empty paths have
* no labels, no record, and always has the identity `ø`, while
* a node may have labels, a record and always has an identity
* other than `ø`.
*
* @param o any object

@@ -57,8 +55,2 @@ */

*
* In practice both nodes and empty paths both have no children.
* The distinguishing feature is that all empty paths have
* no labels, no record, and always has the identity `ø`, while
* a node may have labels, a record and always has an identity
* other than `ø`.
*
* @param o any object

@@ -433,3 +425,3 @@ */

};
var gramBuilder = {
var index = {
seq: seq,

@@ -459,35 +451,3 @@ empty: empty,

var gramBuilder$1 = {
__proto__: null,
seq: seq,
listToPath: listToPath,
cons: cons,
empty: empty,
node: node,
edge: edge,
path: path,
pair: pair,
recordToMap: recordToMap,
mapToRecord: mapToRecord,
pluck: pluck,
property: property,
boolean: _boolean,
string: string,
tagged: tagged,
integer: integer,
decimal: decimal,
hexadecimal: hexadecimal,
octal: octal,
measurement: measurement,
year: year,
date: date,
dayOfMonth: dayOfMonth,
time: time,
duration: duration,
flatten: flatten,
'default': gramBuilder
};
exports.boolean = _boolean;
exports.builder = gramBuilder$1;
exports.cons = cons;

@@ -497,2 +457,3 @@ exports.date = date;

exports.decimal = decimal;
exports.default = index;
exports.duration = duration;

@@ -499,0 +460,0 @@ exports.edge = edge;

@@ -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)&&"ø"===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){return void 0===e&&(e="pair"),t.length>1?t.slice(0,t.length-1).reduceRight((function(t,n){return c([n,t],{kind:e})}),t[t.length-1]):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.kind&&"pair"!==n.kind&&i(e[0])&&i(e[1]))return o.kind=n.kind,o.children=[e[0],e[1]],o;if(r(e[0])&&r(e[1]))return o.kind=n.kind,o.children=[],o;o.children=[e[0],e[1]]}return o.kind=n.kind||"pair",o},d={type:"path",id:"ø",labels:void 0,record:void 0,children:[]},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},{kind:n,children:e})},s=function(e,n,r,i,o){return t({type:"path",kind:e,id:r},i&&{labels:i},o&&{record:o},{children:n})},g=function(e,t,n,r){return s("pair",e,t,n,r)},h=function(e){return e.reduce((function(e,t){return e[t.name]=t.value,e}),{})},y=function(e){return Object.entries(e).reduce((function(e,t){return e.push(v(t[0],t[1])),e}),[])},m=function(e,t){return e.reduce((function(e,n){return n.name===t?n:e}))},v=function(e,t){return{type:"property",name:e,value:t}},b=function(e){return{type:"boolean",value:e?"true":"false"}},T=function(e){return{type:"string",value:e}},k=function(e,t){return{type:"tagged",value:t,tag:e}},S=function(e){return{type:"integer",value:String(e)}},M=function(e){return{type:"decimal",value:String(e)}},O=function(e){return{type:"hexadecimal",value:"number"==typeof e?e.toString(16):e}},x=function(e){return{type:"octal",value:"number"==typeof e?e.toString(8):e}},D=function(e,t){return{type:"measurement",value:String(t),unit:e}},C=function(e){return k("date",e instanceof Date?e.getFullYear().toString():e)},P=function(e){return k("date",e instanceof Date?e.toISOString().slice(0,10):e)},U=function(e){return k("date",e instanceof Date?"--"+e.toISOString().slice(5,10):e)},_=function(e){return k("time",e instanceof Date?e.toTimeString():e)},j=function(e){return k("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)},q=function(e,t){return void 0===t&&(t=1),e.flat(t).filter((function(e){return null!==e}))},R={__proto__:null,seq:a,listToPath:u,cons:c,empty:l,node:f,edge:p,path:s,pair:g,recordToMap:h,mapToRecord:y,pluck:m,property:v,boolean:b,string:T,tagged:k,integer:S,decimal:M,hexadecimal:O,octal:x,measurement:D,year:C,date:P,dayOfMonth:U,time:_,duration:j,flatten:q,default:{seq:a,empty:l,cons:c,pair:g,listToPath:u,node:f,edge:p,property:v,boolean:b,string:T,tagged:k,integer:S,decimal:M,hexadecimal:O,octal:x,measurement:D,date:P,time:_,duration:j,flatten:q,recordToMap:h,mapToRecord:y}};e.boolean=b,e.builder=R,e.cons=c,e.date=P,e.dayOfMonth=U,e.decimal=M,e.duration=j,e.edge=p,e.empty=l,e.flatten=q,e.hexadecimal=O,e.integer=S,e.listToPath=u,e.mapToRecord=y,e.measurement=D,e.node=f,e.octal=x,e.pair=g,e.path=s,e.pluck=m,e.property=v,e.recordToMap=h,e.seq=a,e.string=T,e.tagged=k,e.time=_,e.year=C,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(((e=e||self).gram=e.gram||{},e.gram.builder={}))}(this,(function(e){"use strict";function n(){return(n=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}var t=function(e){return!!e.type&&"path"===e.type},r=function(e){return t(e)&&"ø"===e.id},i=function(e){return t(e)&&e.children&&0===e.children.length&&"ø"!==e.id};function u(e){return Array.isArray(e)?e:e instanceof Function?u(e()):void 0===e?[]:[e]}var o=function(e,t,r,i){return n({type:"seq",id:t},r&&{labels:r},i&&{record:i},{children:u(e)})},a=function(e,n){return void 0===e&&(e="pair"),n.length>1?n.slice(0,n.length-1).reduceRight((function(n,t){return c([t,n],{kind:e})}),n[n.length-1]):n[0]},c=function(e,t){void 0===t&&(t={});var u=n({type:"path"},t.id&&{id:t.id},t.labels&&{labels:t.labels},t.record&&{record:t.record});if(void 0===e)return u.id&&"ø"!==u.id?(u.children=[],u):(u.children=void 0,d);if(0===e.length)return"ø"===u.id?d:(u.children=[],u);if(1===e.length){var o=e[0];return r(o)?(u.children=[],u):(u.children=[o],u)}if(2===e.length){if(t.kind&&"pair"!==t.kind&&i(e[0])&&i(e[1]))return u.kind=t.kind,u.children=[e[0],e[1]],u;if(r(e[0])&&r(e[1]))return u.kind=t.kind,u.children=[],u;u.children=[e[0],e[1]]}return u.kind=t.kind||"pair",u},d={type:"path",id:"ø",labels:void 0,record:void 0,children:[]},l=function(){return d},f=function(e,t,r){return n({type:"path"},e&&{id:e},t&&{labels:t},r&&{record:r},{children:[]})},p=function(e,t,r,i,u){return n({type:"path",id:r},i&&{labels:i},u&&{record:u},{kind:t,children:e})},s=function(e,t,r,i,u){return n({type:"path",kind:e,id:r},i&&{labels:i},u&&{record:u},{children:t})},g=function(e,n,t,r){return s("pair",e,n,t,r)},h=function(e){return e.reduce((function(e,n){return e[n.name]=n.value,e}),{})},y=function(e){return Object.entries(e).reduce((function(e,n){return e.push(m(n[0],n[1])),e}),[])},m=function(e,n){return{type:"property",name:e,value:n}},v=function(e){return{type:"boolean",value:e?"true":"false"}},b=function(e){return{type:"string",value:e}},T=function(e,n){return{type:"tagged",value:n,tag:e}},k=function(e){return{type:"integer",value:String(e)}},S=function(e){return{type:"decimal",value:String(e)}},M=function(e){return{type:"hexadecimal",value:"number"==typeof e?e.toString(16):e}},O=function(e){return{type:"octal",value:"number"==typeof e?e.toString(8):e}},D=function(e,n){return{type:"measurement",value:String(n),unit:e}},x=function(e){return T("date",e instanceof Date?e.toISOString().slice(0,10):e)},C=function(e){return T("time",e instanceof Date?e.toTimeString():e)},U=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)},j=function(e,n){return void 0===n&&(n=1),e.flat(n).filter((function(e){return null!==e}))},P={seq:o,empty:l,cons:c,pair:g,listToPath:a,node:f,edge:p,property:m,boolean:v,string:b,tagged:T,integer:k,decimal:S,hexadecimal:M,octal:O,measurement:D,date:x,time:C,duration:U,flatten:j,recordToMap:h,mapToRecord:y};e.boolean=v,e.cons=c,e.date=x,e.dayOfMonth=function(e){return T("date",e instanceof Date?"--"+e.toISOString().slice(5,10):e)},e.decimal=S,e.default=P,e.duration=U,e.edge=p,e.empty=l,e.flatten=j,e.hexadecimal=M,e.integer=k,e.listToPath=a,e.mapToRecord=y,e.measurement=D,e.node=f,e.octal=O,e.pair=g,e.path=s,e.pluck=function(e,n){return e.reduce((function(e,t){return t.name===n?t:e}))},e.property=m,e.recordToMap=h,e.seq=o,e.string=b,e.tagged=T,e.time=C,e.year=function(e){return T("date",e instanceof Date?e.getFullYear().toString():e)},Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=gram-builder.umd.production.min.js.map

@@ -1,3 +0,139 @@

import * as builder from './gram-builder';
export * from './gram-builder';
export { builder };
/**
* gram-builder package.
*
* @packageDocumentation
*/
import { GramSeq, GramPath, GramNode, GramEdge, GramProperty, GramRecordValue, BooleanLiteral, StringLiteral, IntegerLiteral, DecimalLiteral, HexadecimalLiteral, OctalLiteral, MeasurementLiteral, GramRecord, GramEmptyPath, GramPropertyMap, DateLiteral, TimeLiteral, DurationLiteral, PathKind, RelationshipKind, TaggedTextLiteral } from '@gram-data/gram-ast';
export declare type Children<T> = T | T[] | (() => T | T[]);
/**
* Build a path sequence that represents a graph.
*
* @param paths sequence of paths through history
* @param id optional reference identifier. The "name" of this graph instance.
* @param labels optional labels
* @param record optional graph-level data
*/
export declare const seq: (paths: Children<GramPath>, id?: string | undefined, labels?: string[] | undefined, record?: GramRecord | undefined) => GramSeq;
export interface PathAttributes {
id?: string;
labels?: string[];
record?: GramRecord;
kind?: PathKind;
}
/**
* Reduce a list of paths into a single path composed using the given kind.
*
* @param kind the kind to apply to all sub-paths
* @param pathlist sub-paths to be paired
* @param baseID the baseID from which path expressions will derive new IDs
*/
export declare const listToPath: (kind: "left" | "right" | "either" | "pair" | undefined, pathlist: GramPath[]) => GramPath;
/**
* Build a path.
*
* @param members sub-paths to compose
* @param attributes attributes
*/
export declare const cons: (members?: [] | [GramPath] | [GramPath, GramPath] | undefined, attributes?: PathAttributes) => GramPath;
/**
* Convenience function for retrieving the singleton GramEmptyPath.
*/
export declare const empty: () => GramEmptyPath;
/**
* Build a GramNode.
*
* @param id identifier
* @param labels
* @param record
* @param annotation
*/
export declare const node: (id?: string | undefined, labels?: string[] | undefined, record?: GramRecord | undefined) => GramNode;
/**
* Build an Edge.
*
* @param children
* @param kind
* @param id
* @param labels
* @param record
*/
export declare const edge: (children: [GramNode, GramNode], kind: RelationshipKind, id?: string | undefined, labels?: string[] | undefined, record?: GramRecord | undefined) => GramEdge;
/**
* Build a path
*
* @param children
* @param id
* @param labels
* @param record
*/
/**
* Build a pair
*
* @param children
* @param id
* @param labels
* @param record
*/
export declare const path: (kind: PathKind, members: [GramPath, GramPath], id?: string | undefined, labels?: string[] | undefined, record?: GramRecord | undefined) => GramPath;
/**
* Build a pair
*
* @param children
* @param id
* @param labels
* @param record
*/
export declare const pair: (members: [GramPath, GramPath], id?: string | undefined, labels?: string[] | undefined, record?: GramRecord | undefined) => GramPath;
/**
* Reduces an array of GramProperties into a map.
*
* @param properties
*/
export declare const recordToMap: (properties: GramRecord) => GramPropertyMap;
/**
* Unfolds a property map<string,GramRecordValue> into a property list[GramProperty].
*
* @param properties
*/
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;
export declare const boolean: (value: boolean) => BooleanLiteral;
export declare const string: (value: string) => StringLiteral;
export declare const tagged: (tag: string, value: string) => TaggedTextLiteral;
export declare const integer: (value: string | number) => IntegerLiteral;
export declare const decimal: (value: string | number) => DecimalLiteral;
export declare const hexadecimal: (value: string | number) => HexadecimalLiteral;
export declare const octal: (value: string | number) => OctalLiteral;
export declare const measurement: (unit: string, value: string | number) => MeasurementLiteral;
export declare const year: (value: string | Date) => DateLiteral;
export declare const date: (value: string | Date) => DateLiteral;
export declare const dayOfMonth: (value: string | Date) => DateLiteral;
export declare const time: (value: string | Date) => TimeLiteral;
export declare const duration: (value: string | Date) => DurationLiteral;
export declare const flatten: (xs: any[], depth?: number) => any[];
declare const _default: {
seq: (paths: Children<GramPath>, id?: string | undefined, labels?: string[] | undefined, record?: GramRecord | undefined) => GramSeq;
empty: () => GramEmptyPath;
cons: (members?: [] | [GramPath] | [GramPath, GramPath] | undefined, attributes?: PathAttributes) => GramPath;
pair: (members: [GramPath, GramPath], id?: string | undefined, labels?: string[] | undefined, record?: GramRecord | undefined) => GramPath;
listToPath: (kind: "left" | "right" | "either" | "pair" | undefined, pathlist: GramPath[]) => GramPath;
node: (id?: string | undefined, labels?: string[] | undefined, record?: GramRecord | undefined) => GramNode;
edge: (children: [GramNode, GramNode], kind: RelationshipKind, id?: string | undefined, labels?: string[] | undefined, record?: GramRecord | undefined) => GramEdge;
property: (name: string, value: GramRecordValue) => GramProperty;
boolean: (value: boolean) => BooleanLiteral;
string: (value: string) => StringLiteral;
tagged: (tag: string, value: string) => TaggedTextLiteral;
integer: (value: string | number) => IntegerLiteral;
decimal: (value: string | number) => DecimalLiteral;
hexadecimal: (value: string | number) => HexadecimalLiteral;
octal: (value: string | number) => OctalLiteral;
measurement: (unit: string, value: string | number) => MeasurementLiteral;
date: (value: string | Date) => DateLiteral;
time: (value: string | Date) => TimeLiteral;
duration: (value: string | Date) => DurationLiteral;
flatten: (xs: any[], depth?: number) => any[];
recordToMap: (properties: GramRecord) => GramPropertyMap;
mapToRecord: (properties: GramPropertyMap) => GramRecord;
};
export default _default;

@@ -8,3 +8,3 @@ {

],
"version": "0.2.15",
"version": "0.2.18",
"license": "MIT",

@@ -70,5 +70,5 @@ "repository": {

"dependencies": {
"@gram-data/gram-ast": "^0.2.15"
"@gram-data/gram-ast": "^0.2.18"
},
"gitHead": "c3049970cbd258e0a930927b71558b5245621758",
"gitHead": "3f14810a45eb375bef4c583130123f6fa1ec1e0b",
"publishConfig": {

@@ -75,0 +75,0 @@ "access": "public"

@@ -1,3 +0,5 @@

From nothing to a valid gram AST.
`()-[build]->(ast)`
Build valid `gram` AST.
## How to gram-builder

@@ -11,3 +13,3 @@

### Build an AST using [[gram-builder]]:
### Build an AST:

@@ -24,4 +26,4 @@ ``` TypeScript

- Transform to js objects using [[gram-value]]
- Write back to a string using [[gram-stringify]]
- Enrich record properties with js objects using [[gram-value]]
- Serializes to a string using [[gram-stringify]]
- Introspect the AST using [[gram-ast]]

@@ -1,5 +0,432 @@

import * as builder from './gram-builder';
/**
* gram-builder package.
*
* @packageDocumentation
*/
export * from './gram-builder';
import { Node as UnistNode } from 'unist';
import {
GramSeq,
GramPath,
GramNode,
GramEdge,
GramProperty,
GramRecordValue,
BooleanLiteral,
StringLiteral,
IntegerLiteral,
DecimalLiteral,
HexadecimalLiteral,
OctalLiteral,
MeasurementLiteral,
GramRecord,
GramEmptyPath,
isGramNode,
isGramEmptyPath,
EMPTY_PATH_ID,
GramPropertyMap,
DateLiteral,
TimeLiteral,
DurationLiteral,
PathKind,
RelationshipKind,
TaggedTextLiteral,
} from '@gram-data/gram-ast';
export { builder };
export type Children<T> = T | T[] | (() => T | T[]);
function normalizeChildren<T extends UnistNode>(children?: Children<T>): T[] {
if (Array.isArray(children)) {
return children;
} else if (children instanceof Function) {
const res = children();
return normalizeChildren<T>(res);
} else if (typeof children === 'undefined') {
return [];
} else {
return [children];
}
}
const dateToYMD = (d: Date) => d.toISOString().slice(0, 10);
const dateToDayOfMonth = (d: Date) => '--' + d.toISOString().slice(5, 10);
/**
* Build a path sequence that represents a graph.
*
* @param paths sequence of paths through history
* @param id optional reference identifier. The "name" of this graph instance.
* @param labels optional labels
* @param record optional graph-level data
*/
export const seq = (
paths: Children<GramPath>,
id?: string,
labels?: string[],
record?: GramRecord
): GramSeq => ({
type: 'seq',
id,
...(labels && { labels }),
...(record && { record }),
children: normalizeChildren<GramPath>(paths),
});
export interface PathAttributes {
id?: string;
labels?: string[];
record?: GramRecord;
kind?: PathKind;
}
/**
* Reduce a list of paths into a single path composed using the given kind.
*
* @param kind the kind to apply to all sub-paths
* @param pathlist sub-paths to be paired
* @param baseID the baseID from which path expressions will derive new IDs
*/
export const listToPath = (
kind: PathKind = 'pair',
pathlist: GramPath[]
): GramPath => {
if (pathlist.length > 1) {
return pathlist
.slice(0, pathlist.length - 1)
.reduceRight((acc: GramPath, curr) => {
return cons([curr, acc], { kind });
}, pathlist[pathlist.length - 1]);
} else {
return pathlist[0];
}
};
/**
* Build a path.
*
* @param members sub-paths to compose
* @param attributes attributes
*/
export const cons = (
members?: [] | [GramPath] | [GramPath, GramPath],
attributes: PathAttributes = {}
): GramPath => {
const element: any = {
type: 'path',
...(attributes.id && { id: attributes.id }),
...(attributes.labels && { labels: attributes.labels }),
...(attributes.record && { record: attributes.record }),
// children: members ? members.filter(child => child && !isGramEmptyPath(child)) : undefined,
};
if (members === undefined) {
if (element.id && element.id !== EMPTY_PATH_ID) {
element.children = [];
return element;
}
element.children = undefined;
return EMPTY_PATH;
} else if (members.length === 0) {
if (element.id === EMPTY_PATH_ID) {
return EMPTY_PATH;
}
element.children = [];
return element as GramNode;
} else if (members.length === 1) {
const lhs = members[0];
if (isGramEmptyPath(lhs)) {
element.children = [];
return element as GramNode;
} else {
element.children = [lhs];
return element as GramPath;
}
} else if (members.length === 2) {
if (
attributes.kind &&
attributes.kind !== 'pair' &&
isGramNode(members[0]) &&
isGramNode(members[1])
) {
element.kind = attributes.kind;
element.children = [members[0], members[1]];
return element as GramEdge;
} else if (isGramEmptyPath(members[0]) && isGramEmptyPath(members[1])) {
element.kind = attributes.kind;
element.children = [];
return element as GramNode;
}
element.children = [members[0], members[1]];
}
element.kind = attributes.kind || 'pair';
return element as GramPath;
};
/**
* Singleton instance of GramEmptyPath
*/
const EMPTY_PATH: GramEmptyPath = {
type: 'path',
id: EMPTY_PATH_ID,
labels: undefined,
record: undefined,
children: [],
};
/**
* Convenience function for retrieving the singleton GramEmptyPath.
*/
export const empty = (): GramEmptyPath => EMPTY_PATH;
/**
* Build a GramNode.
*
* @param id identifier
* @param labels
* @param record
* @param annotation
*/
export const node = (
id?: string,
labels?: string[],
record?: GramRecord
): GramNode => ({
type: 'path',
...(id && { id }),
...(labels && { labels }),
...(record && { record }),
children: [],
});
/**
* Build an Edge.
*
* @param children
* @param kind
* @param id
* @param labels
* @param record
*/
export const edge = (
children: [GramNode, GramNode],
kind: RelationshipKind,
id?: string,
labels?: string[],
record?: GramRecord
): GramEdge => ({
type: 'path',
id,
...(labels && { labels }),
...(record && { record }),
kind,
children,
});
/**
* Build a path
*
* @param children
* @param id
* @param labels
* @param record
*/
// export const path = (
// members: [GramPath] | [GramPath, GramPath],
// id?: string,
// labels?: string[],
// record?: GramRecord
// ): GramPath => ({
// type: 'path',
// id,
// ...(labels && { labels }),
// ...(record && { record }),
// children: members,
// });
/**
* Build a pair
*
* @param children
* @param id
* @param labels
* @param record
*/
export const path = (
kind: PathKind,
members: [GramPath, GramPath],
id?: string,
labels?: string[],
record?: GramRecord
): GramPath => ({
type: 'path',
kind,
id,
...(labels && { labels }),
...(record && { record }),
children: members,
});
/**
* Build a pair
*
* @param children
* @param id
* @param labels
* @param record
*/
export const pair = (
members: [GramPath, GramPath],
id?: string,
labels?: string[],
record?: GramRecord
): GramPath => path('pair', members, id, labels, record);
/**
* Reduces an array of GramProperties into a map.
*
* @param properties
*/
export const recordToMap = (properties: GramRecord): GramPropertyMap => {
return properties.reduce((acc: GramPropertyMap, p: GramProperty) => {
acc[p.name] = p.value;
return acc;
}, {} as GramPropertyMap);
};
/**
* Unfolds a property map<string,GramRecordValue> into a property list[GramProperty].
*
* @param properties
*/
export const mapToRecord = (properties: GramPropertyMap): GramRecord => {
return Object.entries(properties).reduce((acc: GramRecord, [k, v]) => {
acc.push(property(k, v));
return acc;
}, [] as GramRecord);
};
export const pluck = (properties: GramRecord, path: string) => {
return properties.reduce((acc, prop) => {
return prop.name === path ? prop : acc;
});
};
export const property = (
name: string,
value: GramRecordValue
): GramProperty => {
const Node: GramProperty = {
type: 'property',
name,
value,
};
return Node;
};
export const boolean = (value: boolean): BooleanLiteral => ({
type: 'boolean',
value: value ? 'true' : 'false',
});
export const string = (value: string): StringLiteral => ({
type: 'string',
value,
});
export const tagged = (tag: string, value: string): TaggedTextLiteral => ({
type: 'tagged',
value,
tag,
});
export const integer = (value: string | number): IntegerLiteral => ({
type: 'integer',
value: String(value),
});
export const decimal = (value: string | number): DecimalLiteral => ({
type: 'decimal',
value: String(value),
});
export const hexadecimal = (value: string | number): HexadecimalLiteral => ({
type: 'hexadecimal',
value: typeof value === 'number' ? value.toString(16) : value,
});
export const octal = (value: string | number): OctalLiteral => ({
type: 'octal',
value: typeof value === 'number' ? value.toString(8) : value,
});
export const measurement = (
unit: string,
value: string | number
): MeasurementLiteral => ({
type: 'measurement',
value: String(value),
unit,
});
export const year = (value: string | Date): DateLiteral =>
tagged(
'date',
value instanceof Date ? value.getFullYear().toString() : value
) as DateLiteral;
export const date = (value: string | Date): DateLiteral =>
tagged(
'date',
value instanceof Date ? dateToYMD(value) : value
) as DateLiteral;
export const dayOfMonth = (value: string | Date): DateLiteral =>
tagged(
'date',
value instanceof Date ? dateToDayOfMonth(value) : value
) as DateLiteral;
export const time = (value: string | Date): TimeLiteral =>
tagged(
'time',
value instanceof Date ? value.toTimeString() : value
) as TimeLiteral;
export const duration = (value: string | Date): DurationLiteral =>
tagged(
'duration',
value instanceof Date
? `P${value.getUTCFullYear() -
1970}Y${value.getUTCMonth()}M${value.getUTCDate()}DT${value.getUTCHours()}H${value.getUTCMinutes()}M${value.getUTCMilliseconds() /
1000}S`
: value
) as DurationLiteral;
export const flatten = (xs: any[], depth = 1) =>
xs.flat(depth).filter(x => x !== null);
export default {
seq,
empty,
cons,
pair,
listToPath,
node,
edge,
property,
boolean,
string,
tagged,
integer,
decimal,
hexadecimal,
octal,
measurement,
date,
time,
duration,
flatten,
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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc