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
▸ Constboolean(value: boolean): BooleanLiteral
Defined in packages/gram-builder/src/index.ts:410
Parameters:
| Name | Type |
|---|---|
value |
boolean |
Returns: BooleanLiteral
cons
▸ Constcons(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
▸ Constdate(value: string | Date): DateLiteral
Defined in packages/gram-builder/src/index.ts:461
Parameters:
| Name | Type |
|---|---|
value |
string | Date |
Returns: DateLiteral
dayOfMonth
▸ ConstdayOfMonth(value: string | Date): DateLiteral
Defined in packages/gram-builder/src/index.ts:467
Parameters:
| Name | Type |
|---|---|
value |
string | Date |
Returns: DateLiteral
decimal
▸ Constdecimal(value: string | number): DecimalLiteral
Defined in packages/gram-builder/src/index.ts:431
Parameters:
| Name | Type |
|---|---|
value |
string | number |
Returns: DecimalLiteral
duration
▸ Constduration(value: string | Date): DurationLiteral
Defined in packages/gram-builder/src/index.ts:479
Parameters:
| Name | Type |
|---|---|
value |
string | Date |
Returns: DurationLiteral
edge
▸ Constedge(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
▸ Constempty(): GramEmptyPath
Defined in packages/gram-builder/src/index.ts:181
Convenience function for retrieving the singleton GramEmptyPath.
Returns: GramEmptyPath
emptyRecord
▸ ConstemptyRecord(): Map<string, GramRecordValue>
Defined in packages/gram-builder/src/index.ts:269
Create a new, empty GramRecord.
Returns: Map<string, GramRecordValue>
flatten
▸ Constflatten(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
▸ ConstgetDown(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
▸ ConstgetLiteral(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
▸ ConstgetRecord(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
▸ ConstgetValue(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
▸ Consthexadecimal(value: string | number): HexadecimalLiteral
Defined in packages/gram-builder/src/index.ts:436
Parameters:
| Name | Type |
|---|---|
value |
string | number |
Returns: HexadecimalLiteral
integer
▸ Constinteger(value: string | number): IntegerLiteral
Defined in packages/gram-builder/src/index.ts:426
Parameters:
| Name | Type |
|---|---|
value |
string | number |
Returns: IntegerLiteral
listToPath
▸ ConstlistToPath(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
▸ Constmeasurement(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
▸ Constnode(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
▸ ConstobjectToRecord(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
▸ Constoctal(value: string | number): OctalLiteral
Defined in packages/gram-builder/src/index.ts:441
Parameters:
| Name | Type |
|---|---|
value |
string | number |
Returns: OctalLiteral
pair
▸ Constpair(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
▸ Constpath(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
▸ ConstpropertiesToRecord(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
▸ Constproperty(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
▸ ConstpropertyValue(value: any): GramRecordValue
Defined in packages/gram-builder/src/index.ts:382
Parameters:
| Name | Type |
|---|---|
value |
any |
Returns: GramRecordValue
seq
▸ Constseq(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
▸ Conststring(value: string): StringLiteral
Defined in packages/gram-builder/src/index.ts:415
Parameters:
| Name | Type |
|---|---|
value |
string |
Returns: StringLiteral
tagged
▸ Consttagged(tag: string, value: string): TaggedTextLiteral
Defined in packages/gram-builder/src/index.ts:420
Parameters:
| Name | Type |
|---|---|
tag |
string |
value |
string |
Returns: TaggedTextLiteral
time
▸ Consttime(value: string | Date): TimeLiteral
Defined in packages/gram-builder/src/index.ts:473
Parameters:
| Name | Type |
|---|---|
value |
string | Date |
Returns: TimeLiteral
year
▸ Constyear(value: string | Date): DateLiteral
Defined in packages/gram-builder/src/index.ts:455
Parameters:
| Name | Type |
|---|---|
value |
string | Date |
Returns: DateLiteral