gram_builder
Globals / gram-builder
Package: gram-builder
()-[build]->(ast)
Build valid gram
AST.
How to gram-builder
Install:
npm install @gram-data/gram-builder
Build an AST:
import { node, edge } from '@gram-data/gram-builder';
const left = node('a');
const right = node('b');
const ast = edge([left, right], 'right');
Next Steps
- Enrich record properties with js objects using gram-value
- Serializes to a string using gram-stringify
- Introspect the AST using gram-ast
Index
Interfaces
Type aliases
Functions
- boolean
- cons
- date
- dayOfMonth
- decimal
- duration
- edge
- empty
- emptyRecord
- flatten
- getDown
- getLiteral
- getRecord
- getValue
- hexadecimal
- integer
- listToPath
- measurement
- node
- objectToRecord
- octal
- pair
- path
- propertiesToRecord
- property
- propertyValue
- seq
- string
- tagged
- time
- year
Type aliases
Children
Ƭ Children<T>: T | T[] | () => T | T[]
Defined in packages/gram-builder/src/index.ts:37
Type parameters:
Name |
---|
T |
Functions
boolean
▸ Const
boolean(value
: boolean): BooleanLiteral
Defined in packages/gram-builder/src/index.ts:410
Parameters:
Name | Type |
---|---|
value |
boolean |
Returns: BooleanLiteral
cons
▸ Const
cons(members?
: [] | [GramPath] | [GramPath, GramPath], attributes?
: PathAttributes): GramPath
Defined in packages/gram-builder/src/index.ts:112
Build a path.
Parameters:
Name | Type | Default value | Description |
---|---|---|---|
members? |
[] | [GramPath] | [GramPath, GramPath] | - | sub-paths to compose |
attributes |
PathAttributes | {} | attributes |
Returns: GramPath
date
▸ Const
date(value
: string | Date): DateLiteral
Defined in packages/gram-builder/src/index.ts:461
Parameters:
Name | Type |
---|---|
value |
string | Date |
Returns: DateLiteral
dayOfMonth
▸ Const
dayOfMonth(value
: string | Date): DateLiteral
Defined in packages/gram-builder/src/index.ts:467
Parameters:
Name | Type |
---|---|
value |
string | Date |
Returns: DateLiteral
decimal
▸ Const
decimal(value
: string | number): DecimalLiteral
Defined in packages/gram-builder/src/index.ts:431
Parameters:
Name | Type |
---|---|
value |
string | number |
Returns: DecimalLiteral
duration
▸ Const
duration(value
: string | Date): DurationLiteral
Defined in packages/gram-builder/src/index.ts:479
Parameters:
Name | Type |
---|---|
value |
string | Date |
Returns: DurationLiteral
edge
▸ Const
edge(children
: [GramNode, GramNode], kind
: RelationshipKind, id?
: undefined | string, labels?
: string[], record?
: GramRecord): GramEdge
Defined in packages/gram-builder/src/index.ts:212
Build an Edge.
Parameters:
Name | Type | Description |
---|---|---|
children |
[GramNode, GramNode] | |
kind |
RelationshipKind | |
id? |
undefined | string | |
labels? |
string[] | |
record? |
GramRecord |
Returns: GramEdge
empty
▸ Const
empty(): GramEmptyPath
Defined in packages/gram-builder/src/index.ts:181
Convenience function for retrieving the singleton GramEmptyPath.
Returns: GramEmptyPath
emptyRecord
▸ Const
emptyRecord(): Map<string, GramRecordValue>
Defined in packages/gram-builder/src/index.ts:269
Create a new, empty GramRecord.
Returns: Map<string, GramRecordValue>
flatten
▸ Const
flatten(xs
: any[], depth?
: number): any[]
Defined in packages/gram-builder/src/index.ts:489
Parameters:
Name | Type | Default value |
---|---|---|
xs |
any[] | - |
depth |
number | 1 |
Returns: any[]
getDown
▸ Const
getDown(hierarchy
: string[] | string, f?
: undefined | (r: GramRecordValue) => any): (Anonymous function)
Defined in packages/gram-builder/src/index.ts:354
Produces a Lens down into nested GramRecords.
Examples:
Descend using either an array of names, or dot notation.
const o = g.objectToRecord({a:{b:{c:g.string("value")}}})
const getAbc1 = g.getDown(['a','b','c']);
const getAbc2 = g.getDown("a.b.c");
expect(getAbc1(o)).toStrictEqual(getAbc2(o));
Descend, then apply a function to extract the text value.
const o = objectToRecord({a:{b:{c:string("value")}}})
const getAbc = getDown("a.b.c", getValue);
expect(getAbc(o)).toBe("value");
Parameters:
Name | Type | Description |
---|---|---|
hierarchy |
string[] | string | array or dot-notation path to descend |
f? |
undefined | (r: GramRecordValue) => any | - |
Returns: (Anonymous function)
getLiteral
▸ Const
getLiteral(name
: string): (Anonymous function)
Defined in packages/gram-builder/src/index.ts:308
Produces a Lens into a literal value with a GramRecord.
Parameters:
Name | Type |
---|---|
name |
string |
Returns: (Anonymous function)
getRecord
▸ Const
getRecord(name
: string): (Anonymous function)
Defined in packages/gram-builder/src/index.ts:320
Produces a Lens into a record value with a GramRecord.
Parameters:
Name | Type |
---|---|
name |
string |
Returns: (Anonymous function)
getValue
▸ Const
getValue(l
: GramRecordValue | undefined): undefined | string
Defined in packages/gram-builder/src/index.ts:300
Extracts the value from a GramLiteral, if available.
Parameters:
Name | Type | Description |
---|---|---|
l |
GramRecordValue | undefined |
Returns: undefined | string
hexadecimal
▸ Const
hexadecimal(value
: string | number): HexadecimalLiteral
Defined in packages/gram-builder/src/index.ts:436
Parameters:
Name | Type |
---|---|
value |
string | number |
Returns: HexadecimalLiteral
integer
▸ Const
integer(value
: string | number): IntegerLiteral
Defined in packages/gram-builder/src/index.ts:426
Parameters:
Name | Type |
---|---|
value |
string | number |
Returns: IntegerLiteral
listToPath
▸ Const
listToPath(kind?
: PathKind, pathlist
: GramPath[]): GramPath
Defined in packages/gram-builder/src/index.ts:91
Reduce a list of paths into a single path composed using the given kind.
Parameters:
Name | Type | Default value | Description |
---|---|---|---|
kind |
PathKind | “pair” | the kind to apply to all sub-paths |
pathlist |
GramPath[] | - | sub-paths to be paired |
Returns: GramPath
measurement
▸ Const
measurement(unit
: string, value
: string | number): MeasurementLiteral
Defined in packages/gram-builder/src/index.ts:446
Parameters:
Name | Type |
---|---|
unit |
string |
value |
string | number |
Returns: MeasurementLiteral
node
▸ Const
node(id?
: undefined | string, labels?
: string[], record?
: GramRecord): GramNode
Defined in packages/gram-builder/src/index.ts:191
Build a GramNode.
Parameters:
Name | Type | Description |
---|---|---|
id? |
undefined | string | identifier |
labels? |
string[] | |
record? |
GramRecord |
Returns: GramNode
objectToRecord
▸ Const
objectToRecord(o
: any): GramRecord
Defined in packages/gram-builder/src/index.ts:288
Transforms a plain js object into a GramRecord.
Parameters:
Name | Type | Description |
---|---|---|
o |
any |
Returns: GramRecord
octal
▸ Const
octal(value
: string | number): OctalLiteral
Defined in packages/gram-builder/src/index.ts:441
Parameters:
Name | Type |
---|---|
value |
string | number |
Returns: OctalLiteral
pair
▸ Const
pair(members
: [GramPath, GramPath], id?
: undefined | string, labels?
: string[], record?
: GramRecord): GramPath
Defined in packages/gram-builder/src/index.ts:258
Build a pair
Parameters:
Name | Type | Description |
---|---|---|
members |
[GramPath, GramPath] | - |
id? |
undefined | string | |
labels? |
string[] | |
record? |
GramRecord |
Returns: GramPath
path
▸ Const
path(kind
: PathKind, members
: [GramPath, GramPath], id?
: undefined | string, labels?
: string[], record?
: GramRecord): GramPath
Defined in packages/gram-builder/src/index.ts:235
Build a pair
Parameters:
Name | Type | Description |
---|---|---|
kind |
PathKind | - |
members |
[GramPath, GramPath] | - |
id? |
undefined | string | |
labels? |
string[] | |
record? |
GramRecord |
Returns: GramPath
propertiesToRecord
▸ Const
propertiesToRecord(properties
: GramProperty[]): GramRecord
Defined in packages/gram-builder/src/index.ts:276
Reduces an array of GramProperties into a GramRecord.
Parameters:
Name | Type | Description |
---|---|---|
properties |
GramProperty[] |
Returns: GramRecord
property
▸ Const
property(name
: string, value
: any): GramProperty
Defined in packages/gram-builder/src/index.ts:373
Builds a GramProperty from a name
Parameters:
Name | Type | Description |
---|---|---|
name |
string | |
value |
any |
Returns: GramProperty
propertyValue
▸ Const
propertyValue(value
: any): GramRecordValue
Defined in packages/gram-builder/src/index.ts:382
Parameters:
Name | Type |
---|---|
value |
any |
Returns: GramRecordValue
seq
▸ Const
seq(paths
: Children<GramPath>, id?
: undefined | string, labels?
: string[], record?
: GramRecord): GramSeq
Defined in packages/gram-builder/src/index.ts:64
Build a path sequence that represents a graph.
Parameters:
Name | Type | Description |
---|---|---|
paths |
Children<GramPath> | sequence of paths through history |
id? |
undefined | string | optional reference identifier. The “name” of this graph instance. |
labels? |
string[] | optional labels |
record? |
GramRecord | optional graph-level data |
Returns: GramSeq
string
▸ Const
string(value
: string): StringLiteral
Defined in packages/gram-builder/src/index.ts:415
Parameters:
Name | Type |
---|---|
value |
string |
Returns: StringLiteral
tagged
▸ Const
tagged(tag
: string, value
: string): TaggedTextLiteral
Defined in packages/gram-builder/src/index.ts:420
Parameters:
Name | Type |
---|---|
tag |
string |
value |
string |
Returns: TaggedTextLiteral
time
▸ Const
time(value
: string | Date): TimeLiteral
Defined in packages/gram-builder/src/index.ts:473
Parameters:
Name | Type |
---|---|
value |
string | Date |
Returns: TimeLiteral
year
▸ Const
year(value
: string | Date): DateLiteral
Defined in packages/gram-builder/src/index.ts:455
Parameters:
Name | Type |
---|---|
value |
string | Date |
Returns: DateLiteral