Skip to content

Commit a99dda6

Browse files
committed
Updated README with docs for all functions. Use FQLib suffix for all functions that are alternates to existing FQL functions
1 parent 1080b9b commit a99dda6

File tree

1 file changed

+91
-18
lines changed

1 file changed

+91
-18
lines changed

README.md

Lines changed: 91 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,57 +24,130 @@ import { query as q } from "faunadb-fql-lib"
2424
Or import each function as needed.
2525

2626
```
27-
import { MapExtended } from "faunadb-fql-lib"
27+
import { MapFQLib } from "faunadb-fql-lib"
2828
```
2929

30-
## Functions
30+
## List of all functions
31+
32+
All functions in this library are built using pure FQL. That means that they are also safe to use in stored Fauna Functions.
33+
34+
### [`Functions`](#Functions)
3135

32-
* [`MapExtended`](#MapExtended)
33-
* [`ObjectKeys`](#ObjectKeys)
3436
* [`ArrayReverse`](#ArrayReverse)
37+
* [`ObjectKeys`](#ObjectKeys)
3538
* [`PaginateReverse`](#PaginateReverse)
39+
* [`PageToObject`](#PageToObject)
40+
* [`StringSplit`](#PaginateReverse)
3641

37-
### `MapExtended`
42+
### [`FQLib functions - alternatives to built-in FQL functions`](#FQLibFunctions)
3843

39-
A wrapper around `Map` that also works on "Page-like" objects. There is currently no way to construct a Page object
40-
in FQL so passing `{ data: []}` to Map will not work.
44+
These are functions that extend and/or alternate the behaviour of existing FQL functions.
45+
All functions suffixed with `FQLib` already exists but behaves differently.
4146

42-
```js
43-
import { MapExtended } from "faunadb-fql-lib"
47+
* [`ContainsFQLib`](#ContainsFQLib)
48+
* [`MapFQLib`](#MapFQLib)
49+
* [`SelectFQLib`](#SelectFQLib)
4450

45-
MapExtended({ data: ["foo", "bar"]}, Lambda("item", q.Var("item"))) // => ["foo", "bar"]
46-
```
51+
## Functions
4752

48-
### `ObjectKeys`
4953

50-
Return the keys as array from an object
54+
### `ArrayReverse`
5155

5256
```js
5357
import { query as q } from "faunadb-fql-lib"
5458

55-
q.ObjectKeys({ foo: "1", bar: "2" }) // => ["foo", "bar"]
59+
q.ArrayReverse([1, 2, 3]) // => [3,2,1]
5660
```
5761

5862

59-
### `ArrayReverse`
63+
### `ObjectKeys`
6064

6165
```js
6266
import { query as q } from "faunadb-fql-lib"
6367

64-
q.ArrayReverse([1, 2, 3]) // => [3,2,1]
68+
q.ObjectKeys({ foo: "1", bar: "2" }) // => ["foo", "bar"]
6569
```
6670

6771
### `PaginateReverse`
6872

6973
Paging a set in reverse is possible but a bit tricky. This pure FQL function takes away the pain. Use it like Paginate.
7074

71-
NOTE: Wrapping `PaginateReverse` in `Map` will fail. Use `MapExtended` instead.
75+
NOTE: Wrapping `PaginateReverse` in `Map` will fail. Use `MapFQLib` instead.
7276

7377
```js
7478
import { query as q } from "faunadb-fql-lib"
7579

76-
q.MapExtended(
80+
q.MapFQLib(
7781
q.PaginateReverse(setRef, opts),
7882
q.Lambda("ref", q.Get(q.Var("ref")))
7983
)
8084
```
85+
86+
### `PageToObject`
87+
88+
This function takes the `before`, `after` and `data` properties on Page and creates an Object.
89+
Usful with other functions that don"t accept Pages. PageToObject is used by MapFQLib.
90+
91+
```js
92+
import { query as q } from "faunadb-fql-lib"
93+
94+
q.PageToObject(q.Paginate(...))
95+
```
96+
97+
### `StringSplit`
98+
99+
Takes a string and an optional delimiter (defaults to `.`) and splits the string into an array.
100+
101+
```js
102+
import { query as q } from "faunadb-fql-lib"
103+
104+
q.StringSplit("foo.bar.fooBar") // => ["foo", "bar", "fooBar"]
105+
q.StringSplit("foo bar fooBar", " ") // => ["foo", "bar", "fooBar"]
106+
q.StringSplit("foo-bar-fooBar", "-") // => ["foo", "bar", "fooBar"]
107+
```
108+
109+
## FQLib functions
110+
111+
### `ContainsFQLib`
112+
113+
Alternative to `Contains` that supports both array and string as path.
114+
115+
```js
116+
import { query as q } from "faunadb-fql-lib"
117+
118+
ContainsFQLib([foo, 1], { foo: ["a", "b"] }) // => true
119+
ContainsFQLib("foo.1", { foo: ["a", "b"] }) // => true
120+
```
121+
122+
### `MapFQLib`
123+
124+
A wrapper around `Map` that also works on "Page-like" objects. There is currently no way
125+
to construct a Page object in FQL so passing `{ data: [] }` to Map will not work.
126+
127+
```js
128+
import { MapFQLib } from "faunadb-fql-lib"
129+
130+
MapFQLib({ data: ["foo", "bar"]}, Lambda("item", q.Var("item"))) // => ["foo", "bar"]
131+
```
132+
133+
### `SelectFQLib`
134+
135+
Alternative to `Select` that supports both array and string as path and does not evaluate
136+
the default value unless there is no match.
137+
138+
```js
139+
import { query as q } from "faunadb-fql-lib"
140+
141+
SelectFQLib([foo, 1], { foo: ["a", "b"] }) // => "b"
142+
SelectFQLib("foo.1", { foo: ["a", "b"] }) // => "b"
143+
SelectFQLib("bar.2", { foo: ["a", "b"] }, "default") // => "default"
144+
145+
/*
146+
The below will create a document even if the value was found
147+
*/
148+
149+
Select(["bar", 0], { foo: ["a", "b"] }, q.Create(q.Collection('Foos'))) // => "a" + document created in Foos
150+
SelectFQLib(["bar", 0], { foo: ["a", "b"] }, q.Create(q.Collection('Foos'))) // => "a" no ducument created
151+
```
152+
153+

0 commit comments

Comments
 (0)