@based/client 3.3.0 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -336
- package/dist/Emitter.d.ts +7 -6
- package/dist/Emitter.js +31 -6
- package/dist/Emitter.js.map +1 -1
- package/dist/authState/parseAuthState.d.ts +3 -0
- package/dist/authState/parseAuthState.js +51 -0
- package/dist/authState/parseAuthState.js.map +1 -0
- package/dist/authState/updateAuthState.d.ts +3 -0
- package/dist/authState/updateAuthState.js +15 -0
- package/dist/authState/updateAuthState.js.map +1 -0
- package/dist/channel/cleanUp.d.ts +2 -0
- package/dist/channel/cleanUp.js +32 -0
- package/dist/channel/cleanUp.js.map +1 -0
- package/dist/channel/index.d.ts +12 -0
- package/dist/channel/index.js +67 -0
- package/dist/channel/index.js.map +1 -0
- package/dist/genObserveId.d.ts +1 -0
- package/dist/genObserveId.js +12 -0
- package/dist/genObserveId.js.map +1 -0
- package/dist/getTargetInfo.d.ts +6 -0
- package/dist/getTargetInfo.js +14 -0
- package/dist/getTargetInfo.js.map +1 -0
- package/dist/getUrlFromOpts.d.ts +3 -0
- package/dist/getUrlFromOpts.js +27 -0
- package/dist/getUrlFromOpts.js.map +1 -0
- package/dist/incoming/debug.d.ts +9 -0
- package/dist/incoming/debug.js +132 -0
- package/dist/incoming/debug.js.map +1 -0
- package/dist/incoming/index.d.ts +2 -0
- package/dist/incoming/index.js +341 -0
- package/dist/incoming/index.js.map +1 -0
- package/dist/incoming/protocol.d.ts +9 -0
- package/dist/incoming/protocol.js +62 -0
- package/dist/incoming/protocol.js.map +1 -0
- package/dist/index.d.ts +70 -127
- package/dist/index.js +225 -15
- package/dist/index.js.map +1 -1
- package/dist/outgoing/debug.d.ts +8 -0
- package/dist/outgoing/debug.js +70 -0
- package/dist/outgoing/debug.js.map +1 -0
- package/dist/outgoing/index.d.ts +14 -0
- package/dist/outgoing/index.js +227 -0
- package/dist/outgoing/index.js.map +1 -0
- package/dist/outgoing/protocol.d.ts +24 -0
- package/dist/outgoing/protocol.js +200 -0
- package/dist/outgoing/protocol.js.map +1 -0
- package/dist/persistentStorage/browser.d.ts +5 -0
- package/dist/persistentStorage/browser.js +150 -0
- package/dist/persistentStorage/browser.js.map +1 -0
- package/dist/persistentStorage/index.d.ts +6 -0
- package/dist/persistentStorage/index.js +56 -0
- package/dist/persistentStorage/index.js.map +1 -0
- package/dist/persistentStorage/node.d.ts +6 -0
- package/dist/persistentStorage/node.js +104 -0
- package/dist/persistentStorage/node.js.map +1 -0
- package/dist/query/index.d.ts +17 -0
- package/dist/query/index.js +112 -0
- package/dist/query/index.js.map +1 -0
- package/dist/stream/fetch.d.ts +4 -0
- package/dist/stream/fetch.js +38 -0
- package/dist/stream/fetch.js.map +1 -0
- package/dist/stream/index.d.ts +4 -0
- package/dist/stream/index.js +65 -0
- package/dist/stream/index.js.map +1 -0
- package/dist/stream/nodeStream.d.ts +6 -0
- package/dist/stream/nodeStream.js +114 -0
- package/dist/stream/nodeStream.js.map +1 -0
- package/dist/stream/types.d.ts +37 -0
- package/dist/stream/types.js +8 -0
- package/dist/stream/types.js.map +1 -0
- package/dist/stream/uploadFileBrowser.d.ts +4 -0
- package/dist/stream/uploadFileBrowser.js +106 -0
- package/dist/stream/uploadFileBrowser.js.map +1 -0
- package/dist/types/auth.d.ts +11 -0
- package/dist/{selvaTypes/get.js → types/auth.js} +1 -1
- package/dist/types/auth.js.map +1 -0
- package/dist/types/cache.d.ts +6 -0
- package/dist/{selvaTypes/set.js → types/cache.js} +1 -1
- package/dist/types/cache.js.map +1 -0
- package/dist/types/channel.d.ts +25 -0
- package/dist/types/channel.js +3 -0
- package/dist/types/channel.js.map +1 -0
- package/dist/types/error.d.ts +37 -0
- package/dist/types/error.js +41 -0
- package/dist/types/error.js.map +1 -0
- package/dist/types/events.d.ts +34 -0
- package/dist/{selvaTypes/schema.js → types/events.js} +1 -1
- package/dist/types/events.js.map +1 -0
- package/dist/types/functions.d.ts +8 -0
- package/dist/types/functions.js +3 -0
- package/dist/types/functions.js.map +1 -0
- package/dist/types/generic.d.ts +22 -0
- package/dist/types/generic.js +3 -0
- package/dist/types/generic.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/{subscriptions → types}/index.js +6 -10
- package/dist/types/index.js.map +1 -0
- package/dist/types/observe.d.ts +46 -0
- package/dist/types/observe.js +3 -0
- package/dist/types/observe.js.map +1 -0
- package/dist/websocket/index.d.ts +1 -1
- package/dist/websocket/index.js +19 -5
- package/dist/websocket/index.js.map +1 -1
- package/dist/websocket/types.d.ts +0 -0
- package/dist/websocket/types.js +0 -0
- package/dist/websocket/types.js.map +0 -0
- package/dist/websocket/urlLoader.d.ts +0 -0
- package/dist/websocket/urlLoader.js +0 -0
- package/dist/websocket/urlLoader.js.map +0 -0
- package/package.json +18 -27
- package/dist/Client.d.ts +0 -80
- package/dist/Client.js +0 -271
- package/dist/Client.js.map +0 -1
- package/dist/auth.d.ts +0 -13
- package/dist/auth.js +0 -87
- package/dist/auth.js.map +0 -1
- package/dist/createError.d.ts +0 -3
- package/dist/createError.js +0 -67
- package/dist/createError.js.map +0 -1
- package/dist/debug.d.ts +0 -2
- package/dist/debug.js +0 -21
- package/dist/debug.js.map +0 -1
- package/dist/file/fetch.d.ts +0 -6
- package/dist/file/fetch.js +0 -27
- package/dist/file/fetch.js.map +0 -1
- package/dist/file/getUrl.d.ts +0 -4
- package/dist/file/getUrl.js +0 -42
- package/dist/file/getUrl.js.map +0 -1
- package/dist/file/index.d.ts +0 -6
- package/dist/file/index.js +0 -95
- package/dist/file/index.js.map +0 -1
- package/dist/file/stream/browser.d.ts +0 -7
- package/dist/file/stream/browser.js +0 -17
- package/dist/file/stream/browser.js.map +0 -1
- package/dist/file/stream/index.d.ts +0 -7
- package/dist/file/stream/index.js +0 -86
- package/dist/file/stream/index.js.map +0 -1
- package/dist/file/uploadFileBrowser.d.ts +0 -3
- package/dist/file/uploadFileBrowser.js +0 -72
- package/dist/file/uploadFileBrowser.js.map +0 -1
- package/dist/findPrefix.d.ts +0 -3
- package/dist/findPrefix.js +0 -20
- package/dist/findPrefix.js.map +0 -1
- package/dist/idleTimeout.d.ts +0 -3
- package/dist/idleTimeout.js +0 -17
- package/dist/idleTimeout.js.map +0 -1
- package/dist/observable/index.d.ts +0 -28
- package/dist/observable/index.js +0 -84
- package/dist/observable/index.js.map +0 -1
- package/dist/printBasedObject.d.ts +0 -4
- package/dist/printBasedObject.js +0 -76
- package/dist/printBasedObject.js.map +0 -1
- package/dist/queue.d.ts +0 -5
- package/dist/queue.js +0 -53
- package/dist/queue.js.map +0 -1
- package/dist/request.d.ts +0 -6
- package/dist/request.js +0 -67
- package/dist/request.js.map +0 -1
- package/dist/selvaTypes/get.d.ts +0 -97
- package/dist/selvaTypes/get.js.map +0 -1
- package/dist/selvaTypes/schema.d.ts +0 -89
- package/dist/selvaTypes/schema.js.map +0 -1
- package/dist/selvaTypes/set.d.ts +0 -73
- package/dist/selvaTypes/set.js.map +0 -1
- package/dist/subscriptions/addGetSubscriber.d.ts +0 -3
- package/dist/subscriptions/addGetSubscriber.js +0 -87
- package/dist/subscriptions/addGetSubscriber.js.map +0 -1
- package/dist/subscriptions/addSubscriber.d.ts +0 -2
- package/dist/subscriptions/addSubscriber.js +0 -136
- package/dist/subscriptions/addSubscriber.js.map +0 -1
- package/dist/subscriptions/generateId.d.ts +0 -1
- package/dist/subscriptions/generateId.js +0 -11
- package/dist/subscriptions/generateId.js.map +0 -1
- package/dist/subscriptions/incomingSubscription.d.ts +0 -3
- package/dist/subscriptions/incomingSubscription.js +0 -87
- package/dist/subscriptions/incomingSubscription.js.map +0 -1
- package/dist/subscriptions/incomingSubscriptionDiff.d.ts +0 -3
- package/dist/subscriptions/incomingSubscriptionDiff.js +0 -85
- package/dist/subscriptions/incomingSubscriptionDiff.js.map +0 -1
- package/dist/subscriptions/index.d.ts +0 -10
- package/dist/subscriptions/index.js.map +0 -1
- package/dist/subscriptions/logoutSubscriptions.d.ts +0 -3
- package/dist/subscriptions/logoutSubscriptions.js +0 -36
- package/dist/subscriptions/logoutSubscriptions.js.map +0 -1
- package/dist/subscriptions/removeSendSubscriptionDataFromQueue.d.ts +0 -2
- package/dist/subscriptions/removeSendSubscriptionDataFromQueue.js +0 -14
- package/dist/subscriptions/removeSendSubscriptionDataFromQueue.js.map +0 -1
- package/dist/subscriptions/removeSubscriber.d.ts +0 -2
- package/dist/subscriptions/removeSubscriber.js +0 -44
- package/dist/subscriptions/removeSubscriber.js.map +0 -1
- package/dist/subscriptions/removeUnsubscribesFromQueue.d.ts +0 -2
- package/dist/subscriptions/removeUnsubscribesFromQueue.js +0 -14
- package/dist/subscriptions/removeUnsubscribesFromQueue.js.map +0 -1
- package/dist/subscriptions/sendAllSubscriptions.d.ts +0 -2
- package/dist/subscriptions/sendAllSubscriptions.js +0 -114
- package/dist/subscriptions/sendAllSubscriptions.js.map +0 -1
- package/dist/token.d.ts +0 -4
- package/dist/token.js +0 -35
- package/dist/token.js.map +0 -1
- package/dist/track.d.ts +0 -8
- package/dist/track.js +0 -71
- package/dist/track.js.map +0 -1
- package/docs/auth-based-ui-howto.md +0 -74
- package/docs/auth-howto.md +0 -166
- package/docs/auth.md +0 -93
- package/docs/authorize.md +0 -56
- package/docs/files.md +0 -66
- package/docs/get-started.md +0 -60
- package/docs/get.md +0 -759
- package/docs/schema.md +0 -244
- package/docs/set.md +0 -652
package/docs/set.md
DELETED
|
@@ -1,652 +0,0 @@
|
|
|
1
|
-
# _Set_ Method Query Reference
|
|
2
|
-
|
|
3
|
-
## Introduction
|
|
4
|
-
|
|
5
|
-
The `based.set()` method changes data in the database. It can either create a new node or modify existing ones.
|
|
6
|
-
As argument it takes a single object formatted using the based-db query language, and it returns an object containing the ID of the node it just operated on, or _undefined_ if the set was not succesful.
|
|
7
|
-
The query language supports several **operators** to change the behaviour of the set operation. These operators are prefixed with a _**$**_ (e.g. `$id`, `$operator`... ).
|
|
8
|
-
Fields without the **_$_** represent a specific field of the node.
|
|
9
|
-
|
|
10
|
-
Operators can act at the **node** level or at the **individual field** level.
|
|
11
|
-
|
|
12
|
-
- [**Node level operators**](#node-level-operators)
|
|
13
|
-
- [`$id`](#id-string)
|
|
14
|
-
- [`$db`](#db-string)
|
|
15
|
-
- [`aliases`](#aliases-string--string)
|
|
16
|
-
- [`$merge`](#merge-boolean)
|
|
17
|
-
- [`$language`](#language-string)
|
|
18
|
-
- [`$operation`](#operation-string)
|
|
19
|
-
- **Field type specific operators**
|
|
20
|
-
- [Basic operators](#basic-operators)
|
|
21
|
-
- `$default`
|
|
22
|
-
- `$delete`
|
|
23
|
-
- [`set` and `references` type field operators](#set-and-references-type-field-operators)
|
|
24
|
-
- `$add`
|
|
25
|
-
- `$delete`
|
|
26
|
-
- [`object` and `record` type field operators](#object-and-record-type-field-operators)
|
|
27
|
-
- `$merge`
|
|
28
|
-
- [`array` type field operators](#array-type-field-operators)
|
|
29
|
-
- `$push`
|
|
30
|
-
- `$insert`
|
|
31
|
-
- `$assign`
|
|
32
|
-
- `$remove`
|
|
33
|
-
|
|
34
|
-
---
|
|
35
|
-
|
|
36
|
-
## Node level operators
|
|
37
|
-
|
|
38
|
-
### `$id`: _string_
|
|
39
|
-
|
|
40
|
-
If provided, the operation is applied to the node the id points to. By default, if the node doesn't exist yet, a node with that id will be created and the operation will be applied to it.
|
|
41
|
-
This behaviour can be change with the `$operation` operator.
|
|
42
|
-
|
|
43
|
-
```js
|
|
44
|
-
// This sets the 'title' field on a node with id 'ma6d044a24' of type 'match'
|
|
45
|
-
const result = await client.set({
|
|
46
|
-
$id: 'ma6d044a24',
|
|
47
|
-
type: 'match',
|
|
48
|
-
title: {
|
|
49
|
-
en: 'hello',
|
|
50
|
-
},
|
|
51
|
-
})
|
|
52
|
-
// This creates a new node of type 'match' and fills the 'title' field with 'hello'.
|
|
53
|
-
// 'result' will hold the id of the node just set.
|
|
54
|
-
const result = await client.set({
|
|
55
|
-
type: 'match',
|
|
56
|
-
title: {
|
|
57
|
-
en: 'hello',
|
|
58
|
-
},
|
|
59
|
-
})
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
### `$db`: _string_
|
|
63
|
-
|
|
64
|
-
There will be cases in which you'll want to store data on different indipendent database instances.
|
|
65
|
-
Each instance can be assigned a name, which can be later specified with the `$db` operator.
|
|
66
|
-
It can be left empty if only one database instance is present.
|
|
67
|
-
|
|
68
|
-
```js
|
|
69
|
-
// Set operation on the 'users' server
|
|
70
|
-
const result = await client.set({
|
|
71
|
-
$db: 'users',
|
|
72
|
-
$id: 'ma6d044a24',
|
|
73
|
-
type: 'match',
|
|
74
|
-
title: {
|
|
75
|
-
en: 'hello',
|
|
76
|
-
},
|
|
77
|
-
})
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### `aliases`: _string | string[]_
|
|
81
|
-
|
|
82
|
-
An alias is an alternative way of referencing a node. Each node can have one or more aliases to be referenced by, and they can be set by modifying the `aliases` field of a node. This field is always present in a node.
|
|
83
|
-
|
|
84
|
-
This allows to later _get_ the node by using the alias instead of the ID.
|
|
85
|
-
|
|
86
|
-
**Setting**
|
|
87
|
-
|
|
88
|
-
```js
|
|
89
|
-
{
|
|
90
|
-
aliases: [ 'alias' ]
|
|
91
|
-
}
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
**Adding**
|
|
95
|
-
|
|
96
|
-
```js
|
|
97
|
-
{
|
|
98
|
-
aliases: { $add: [ 'nice' ] }
|
|
99
|
-
}
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
**Deleting**
|
|
103
|
-
|
|
104
|
-
```js
|
|
105
|
-
{
|
|
106
|
-
aliases: { $delete: [ 'nice' ] }
|
|
107
|
-
}
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
**Clearing**
|
|
111
|
-
|
|
112
|
-
```js
|
|
113
|
-
{
|
|
114
|
-
aliases: []
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// or
|
|
118
|
-
|
|
119
|
-
{
|
|
120
|
-
aliases: { $delete: true }
|
|
121
|
-
}
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
### `$merge`: _boolean_
|
|
125
|
-
|
|
126
|
-
Default value: `true`
|
|
127
|
-
|
|
128
|
-
The `$merge` operator can be used to specify whether any fields specified in the `.set()` should overwrite everything that currently exists in the database for that node (if it is updated), or whether any fields specified will be added or overwritten only if provided.
|
|
129
|
-
|
|
130
|
-
```js
|
|
131
|
-
/*
|
|
132
|
-
Let's assume the following node in database:
|
|
133
|
-
{
|
|
134
|
-
id: 'maASxsd3',
|
|
135
|
-
type: 'match',
|
|
136
|
-
value: 10,
|
|
137
|
-
title: {
|
|
138
|
-
en: 'yes'
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
*/
|
|
142
|
-
|
|
143
|
-
const result = await client.set({
|
|
144
|
-
$merge: true, // optional, defaults to true
|
|
145
|
-
type: 'match',
|
|
146
|
-
title: {
|
|
147
|
-
en: 'hello',
|
|
148
|
-
de: 'hallo',
|
|
149
|
-
},
|
|
150
|
-
name: 'match',
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
/*
|
|
154
|
-
Value of `const result`: `maASxsd3`
|
|
155
|
-
Resulting node in database:
|
|
156
|
-
{
|
|
157
|
-
|
|
158
|
-
id: 'maASxsd3',
|
|
159
|
-
type: 'match',
|
|
160
|
-
value: 10, // value remains
|
|
161
|
-
title: {
|
|
162
|
-
en: 'hello', // .en is overwritten
|
|
163
|
-
de: 'hallo' // .de is merged in
|
|
164
|
-
},
|
|
165
|
-
name: 'match' // name is merged in
|
|
166
|
-
}
|
|
167
|
-
*/
|
|
168
|
-
|
|
169
|
-
/* With $merge: false */
|
|
170
|
-
|
|
171
|
-
/*
|
|
172
|
-
Let's assume the following node in database:
|
|
173
|
-
{
|
|
174
|
-
id: 'maASxsd3',
|
|
175
|
-
type: 'match',
|
|
176
|
-
value: 10,
|
|
177
|
-
title: {
|
|
178
|
-
en: 'yes'
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
*/
|
|
182
|
-
|
|
183
|
-
const result = await client.set({
|
|
184
|
-
$merge: false,
|
|
185
|
-
title: {
|
|
186
|
-
de: 'hallo',
|
|
187
|
-
},
|
|
188
|
-
name: 'match',
|
|
189
|
-
})
|
|
190
|
-
|
|
191
|
-
/*
|
|
192
|
-
Value of `const result`: `maASxsd3`
|
|
193
|
-
Resulting node in database:
|
|
194
|
-
{
|
|
195
|
-
id: 'maASxsd3',
|
|
196
|
-
type: 'match',
|
|
197
|
-
title: {
|
|
198
|
-
de: 'hallo' // .de is added but .en is deleted
|
|
199
|
-
},
|
|
200
|
-
name: 'match' // name is added but value is deleted
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
*/
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
### `$language`: _string_
|
|
207
|
-
|
|
208
|
-
This operator changes how you set a value in a field of type `text`. See later for details. TODO
|
|
209
|
-
|
|
210
|
-
### `$operation`: _string_
|
|
211
|
-
|
|
212
|
-
Values: `upsert | create | update`, defaults to `upsert`.
|
|
213
|
-
|
|
214
|
-
This operator changes the _set_ operation type.
|
|
215
|
-
|
|
216
|
-
#### Upsert
|
|
217
|
-
|
|
218
|
-
_Upsert mode_ is the default set operation type. It updates an existing node or creates a new one if no node exists.
|
|
219
|
-
|
|
220
|
-
```js
|
|
221
|
-
const result = await client.set({
|
|
222
|
-
$operation: 'upsert', // optional, defaults to 'upsert'
|
|
223
|
-
$id: 'muASxsd3',
|
|
224
|
-
title: {
|
|
225
|
-
en: 'hello',
|
|
226
|
-
},
|
|
227
|
-
})
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
Upsert acts both as _create_ and _update_.
|
|
231
|
-
|
|
232
|
-
#### Create
|
|
233
|
-
|
|
234
|
-
_Create mode_ fails if a node already exists, and returns `undefined` instead of the ID of the created node. If no entry exists with the specified `$id` or `$alias`, then it succesfully creates a new node, and returns its ID.
|
|
235
|
-
|
|
236
|
-
```javascript
|
|
237
|
-
const result = await client.set({
|
|
238
|
-
$operation: 'create',
|
|
239
|
-
$id: 'maASxsd3',
|
|
240
|
-
title: {
|
|
241
|
-
en: 'hello',
|
|
242
|
-
},
|
|
243
|
-
})
|
|
244
|
-
|
|
245
|
-
/*
|
|
246
|
-
If no node with id = maASxsd3 exists, value of `result` = `maASxsd3`
|
|
247
|
-
If the node already exists, value of `result`= `undefined`. In this case nothing is set in the database and the node remains as it was.
|
|
248
|
-
*/
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
The same applies to `$alias`.
|
|
252
|
-
|
|
253
|
-
```javascript
|
|
254
|
-
const result = await client.set({
|
|
255
|
-
$operation: 'create',
|
|
256
|
-
$alias: 'myAlias',
|
|
257
|
-
title: {
|
|
258
|
-
en: 'hello',
|
|
259
|
-
},
|
|
260
|
-
})
|
|
261
|
-
|
|
262
|
-
/*
|
|
263
|
-
If no node exists, value of `const result`: `maASxsd3`
|
|
264
|
-
If the node already exists, value of `const result`: `undefined`. In this case nothing is set in the database and the node remains as it was.
|
|
265
|
-
*/
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
If neither `$id` nor `$alias` is provided but `type` is provided, a completely new node is created and and ID is generated for it.
|
|
269
|
-
|
|
270
|
-
```javascript
|
|
271
|
-
const result = await client.set({
|
|
272
|
-
$operation: 'create',
|
|
273
|
-
type: 'match',
|
|
274
|
-
title: {
|
|
275
|
-
en: 'hello',
|
|
276
|
-
},
|
|
277
|
-
})
|
|
278
|
-
|
|
279
|
-
/*
|
|
280
|
-
Value of `const result`: ma<random string> such as `maASxsd3`
|
|
281
|
-
Resulting node in database:
|
|
282
|
-
{
|
|
283
|
-
id: 'maASxsd3',
|
|
284
|
-
type: 'match',
|
|
285
|
-
title: {
|
|
286
|
-
en: 'hello'
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
*/
|
|
290
|
-
```
|
|
291
|
-
|
|
292
|
-
#### Update
|
|
293
|
-
|
|
294
|
-
_Update mode_ is the opposite of _create_, in that it fails if the node being updated does not exist.
|
|
295
|
-
|
|
296
|
-
```javascript
|
|
297
|
-
let result = await client.set({
|
|
298
|
-
$operation: 'create',
|
|
299
|
-
type: 'match',
|
|
300
|
-
title: {
|
|
301
|
-
en: 'hello',
|
|
302
|
-
},
|
|
303
|
-
})
|
|
304
|
-
|
|
305
|
-
/*
|
|
306
|
-
Value of `const result`: `undefined`
|
|
307
|
-
Node in the database remains untouched because we haven't provided an ID or alias.
|
|
308
|
-
*/
|
|
309
|
-
|
|
310
|
-
result = await client.set({
|
|
311
|
-
$operation: 'create',
|
|
312
|
-
$id: 'maASxsd3',
|
|
313
|
-
title: {
|
|
314
|
-
en: 'hello',
|
|
315
|
-
},
|
|
316
|
-
})
|
|
317
|
-
|
|
318
|
-
/*
|
|
319
|
-
If the node exists, value of `const result`: `maASxsd3`, and the fields are set.
|
|
320
|
-
If the node does not exist, value of `const result`: `undefined`. In this case nothing is set in the database and the node remains as it was.
|
|
321
|
-
*/
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
---
|
|
325
|
-
|
|
326
|
-
## Field type specific operators
|
|
327
|
-
|
|
328
|
-
### Basic operators
|
|
329
|
-
|
|
330
|
-
These operators can be applied to any field type. The syntax and explanation follows.
|
|
331
|
-
|
|
332
|
-
#### `$default` : _any_
|
|
333
|
-
|
|
334
|
-
Only sets a value if it isn't already set.
|
|
335
|
-
|
|
336
|
-
```js
|
|
337
|
-
client.set({
|
|
338
|
-
$id: 'maASxsd3',
|
|
339
|
-
username: { $default: 'giovanni' },
|
|
340
|
-
})
|
|
341
|
-
```
|
|
342
|
-
|
|
343
|
-
#### `$delete` : _boolean_
|
|
344
|
-
|
|
345
|
-
This unsets the node's field.
|
|
346
|
-
It can also be used on a field of a `record` in order to remove it.
|
|
347
|
-
|
|
348
|
-
```js
|
|
349
|
-
client.set({
|
|
350
|
-
$id: 'maASxsd3',
|
|
351
|
-
username: { $delete: true },
|
|
352
|
-
})
|
|
353
|
-
// This will delete the 'username' field.
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
### `set` and `references` type field operators
|
|
358
|
-
|
|
359
|
-
You can add and remove elements to _set_ and _references_ fields using the `$add` and `$delete` operators.
|
|
360
|
-
These operators can take a single value or an array of values.
|
|
361
|
-
|
|
362
|
-
#### `$add`: _any | [any, any, ...]_
|
|
363
|
-
|
|
364
|
-
The `$add` operator can be used to add one or more entries to a _set_ or _references_ type field. A single item type value or an array of item type values may be specified to `$add`. All the existing values in the set will remain, but no duplicates are allowed.
|
|
365
|
-
|
|
366
|
-
> :exclamation: **Please note:** Whenever a new node is created, if no parent is specified, it is implicitely set as a child of `root`. This is to avoid orphan nodes in the database. If you wish for new nodes _not_ to be children of `root`, you can simply specify `parents : ['parentId1', 'parentId2', ...]` without using the `$add` operator. **_Only use the `$add` operator to add extra references to a list_**.
|
|
367
|
-
|
|
368
|
-
```js
|
|
369
|
-
/*
|
|
370
|
-
Let's assume the following node in database, where availableSeats is of type 'set':
|
|
371
|
-
{
|
|
372
|
-
id: 'maASxsd3',
|
|
373
|
-
type: 'match',
|
|
374
|
-
availableSeats: ['a2', 'a3', 'b5']
|
|
375
|
-
}
|
|
376
|
-
*/
|
|
377
|
-
|
|
378
|
-
let result = await client.set({
|
|
379
|
-
id: 'maASxsd3',
|
|
380
|
-
availableSeats: { $add: 'b12' },
|
|
381
|
-
})
|
|
382
|
-
|
|
383
|
-
/*
|
|
384
|
-
Value of `const result`: `maASxsd3`
|
|
385
|
-
Resulting node in database:
|
|
386
|
-
{
|
|
387
|
-
id: 'maASxsd3',
|
|
388
|
-
type: 'match',
|
|
389
|
-
availableSeats: ['a2', 'a3', 'b5', 'b12']
|
|
390
|
-
}
|
|
391
|
-
*/
|
|
392
|
-
|
|
393
|
-
result = await client.set({
|
|
394
|
-
id: 'maASxsd3',
|
|
395
|
-
availableSeats: { $add: ['b13', 'b14'] },
|
|
396
|
-
})
|
|
397
|
-
|
|
398
|
-
/*
|
|
399
|
-
Value of `const result`: `maASxsd3`
|
|
400
|
-
Resulting node in database:
|
|
401
|
-
{
|
|
402
|
-
id: 'maASxsd3',
|
|
403
|
-
type: 'match',
|
|
404
|
-
availableSeats: ['a2', 'a3', 'b5', 'b12', 'b13', 'b14']
|
|
405
|
-
}
|
|
406
|
-
*/
|
|
407
|
-
```
|
|
408
|
-
|
|
409
|
-
#### `$delete`: _any | [any, any, ...]_
|
|
410
|
-
|
|
411
|
-
This operator is the opposite of the `$add` operator, and takes the same arguments.
|
|
412
|
-
|
|
413
|
-
```js
|
|
414
|
-
/*
|
|
415
|
-
Let's assume the following node in database:
|
|
416
|
-
{
|
|
417
|
-
id: 'maASxsd3',
|
|
418
|
-
type: 'match',
|
|
419
|
-
availableSeats: ['a2', 'a3', 'b5', 'b12', 'b13', 'b14']
|
|
420
|
-
}
|
|
421
|
-
*/
|
|
422
|
-
|
|
423
|
-
let result = await client.set({
|
|
424
|
-
id: 'maASxsd3',
|
|
425
|
-
availableSeats: { $delete: ['b13', 'b14'] },
|
|
426
|
-
})
|
|
427
|
-
|
|
428
|
-
/*
|
|
429
|
-
Value of `const result`: `maASxsd3`
|
|
430
|
-
Resulting node in database:
|
|
431
|
-
{
|
|
432
|
-
id: 'maASxsd3',
|
|
433
|
-
type: 'match',
|
|
434
|
-
availableSeats: ['a2', 'a3', 'b5', 'b12']
|
|
435
|
-
}
|
|
436
|
-
*/
|
|
437
|
-
|
|
438
|
-
result = await client.set({
|
|
439
|
-
id: 'maASxsd3',
|
|
440
|
-
availableSeats: { $delete: 'b12' },
|
|
441
|
-
})
|
|
442
|
-
|
|
443
|
-
/*
|
|
444
|
-
Value of `const result`: `maASxsd3`
|
|
445
|
-
Resulting node in database:
|
|
446
|
-
{
|
|
447
|
-
id: 'maASxsd3',
|
|
448
|
-
type: 'match',
|
|
449
|
-
availableSeats: ['a2', 'a3', 'b5']
|
|
450
|
-
}
|
|
451
|
-
*/
|
|
452
|
-
```
|
|
453
|
-
|
|
454
|
-
### `object` and `record` type field operators
|
|
455
|
-
|
|
456
|
-
The only operation for `objects` and `records` is the merge operation, which allows to either overwrite the whole structure, or merge it. See below.
|
|
457
|
-
|
|
458
|
-
#### `$merge`: _boolean_
|
|
459
|
-
|
|
460
|
-
Default value: `true`
|
|
461
|
-
|
|
462
|
-
The `$merge` option operates exactly the same way as the top-level set [`$merge` operator](#merge-boolean), but in the context of the fields of the object type. When an object is set with `$merge: false`, only the set fields will remain in the database.
|
|
463
|
-
|
|
464
|
-
```js
|
|
465
|
-
/*
|
|
466
|
-
Let's assume the following node in database:
|
|
467
|
-
{
|
|
468
|
-
id: 'maASxsd3',
|
|
469
|
-
type: 'match',
|
|
470
|
-
details: {
|
|
471
|
-
league: 'serie-a',
|
|
472
|
-
location: 'rome'
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
*/
|
|
476
|
-
|
|
477
|
-
let result = await client.set({
|
|
478
|
-
id: 'maASxsd3',
|
|
479
|
-
details: {
|
|
480
|
-
$merge: true, //optional, defaults to true
|
|
481
|
-
league: 'serie-b',
|
|
482
|
-
},
|
|
483
|
-
})
|
|
484
|
-
|
|
485
|
-
/*
|
|
486
|
-
Value of `const result`: `maASxsd3`
|
|
487
|
-
Resulting node in database:
|
|
488
|
-
{
|
|
489
|
-
id: 'maASxsd3',
|
|
490
|
-
type: 'match',
|
|
491
|
-
details: {
|
|
492
|
-
league: 'serie-b',
|
|
493
|
-
location: 'rome'
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
*/
|
|
497
|
-
|
|
498
|
-
let result = await client.set({
|
|
499
|
-
id: 'maASxsd3',
|
|
500
|
-
details: {
|
|
501
|
-
$merge: false,
|
|
502
|
-
league: 'serie-b',
|
|
503
|
-
},
|
|
504
|
-
})
|
|
505
|
-
|
|
506
|
-
/*
|
|
507
|
-
Value of `const result`: `maASxsd3`
|
|
508
|
-
Resulting node in database:
|
|
509
|
-
{
|
|
510
|
-
id: 'maASxsd3',
|
|
511
|
-
type: 'match',
|
|
512
|
-
details: {
|
|
513
|
-
league: 'serie-b',
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
*/
|
|
517
|
-
```
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
### `array` type field operators
|
|
521
|
-
|
|
522
|
-
#### `$push`: _array type_
|
|
523
|
-
|
|
524
|
-
Used to append an item at the end of the array. The type of `$push` must conform to the `items` field described in the schema.
|
|
525
|
-
|
|
526
|
-
```js
|
|
527
|
-
// in the case of the `items` type being an object with name, value, and status field
|
|
528
|
-
client.set({
|
|
529
|
-
$id: ar165415,
|
|
530
|
-
myobjectarray: {
|
|
531
|
-
$push: {
|
|
532
|
-
name: 'match ' + i,
|
|
533
|
-
value: i,
|
|
534
|
-
status: i < 5 ? 100 : 300,
|
|
535
|
-
},
|
|
536
|
-
},
|
|
537
|
-
})
|
|
538
|
-
|
|
539
|
-
// in the case of the `items` type being 'number'
|
|
540
|
-
client.set({
|
|
541
|
-
$id: ar165415,
|
|
542
|
-
mynumberarray: {
|
|
543
|
-
$push: 4.2
|
|
544
|
-
},
|
|
545
|
-
})
|
|
546
|
-
|
|
547
|
-
```
|
|
548
|
-
|
|
549
|
-
#### `$insert`: _object_
|
|
550
|
-
|
|
551
|
-
Used to insert an item at a specific index of the array. The item at the index and after get shifted appropriately.
|
|
552
|
-
The object must have fields `$idx` and `$value`.
|
|
553
|
-
|
|
554
|
-
##### `$idx`: _integer_
|
|
555
|
-
|
|
556
|
-
Index at which to insert the item. If the index is bigger than the size of the array, `null` items get added between the last item and the `$idx`.
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
##### `$value`: _array type_
|
|
560
|
-
|
|
561
|
-
Item to insert. This must conform to the `items` type described in the schema.
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
```js
|
|
565
|
-
// in the case of the `items` type being an object with name, value, and status field
|
|
566
|
-
client.set({
|
|
567
|
-
$id: 'ar165415',
|
|
568
|
-
myobjectarray: {
|
|
569
|
-
$insert: {
|
|
570
|
-
$idx: 25,
|
|
571
|
-
$value: {
|
|
572
|
-
name: 'match ' + i,
|
|
573
|
-
value: i,
|
|
574
|
-
status: i < 5 ? 100 : 300,
|
|
575
|
-
}
|
|
576
|
-
},
|
|
577
|
-
},
|
|
578
|
-
})
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
// in the case of the `items` type being 'number'
|
|
582
|
-
client.set({
|
|
583
|
-
$id: 'ar542875421',
|
|
584
|
-
mynumberarray: {
|
|
585
|
-
$insert: {
|
|
586
|
-
$idx: 21,
|
|
587
|
-
$value: 58
|
|
588
|
-
},
|
|
589
|
-
},
|
|
590
|
-
})
|
|
591
|
-
```
|
|
592
|
-
|
|
593
|
-
#### `$assign`: _object_
|
|
594
|
-
|
|
595
|
-
Used to change a value at a specific index of the array. Unlike `$insert`, this does not create a new node unless the index is past the size of the array. In that case it creates `null` items between the end of the array and the new item, just like `$insert`.
|
|
596
|
-
The object must have fields `$idx` and `$value`.
|
|
597
|
-
|
|
598
|
-
##### `$idx`: _integer_
|
|
599
|
-
|
|
600
|
-
Index at which to insert the item. If the index is bigger than the size of the array, `null` items get added between the last item and the `$idx`.
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
##### `$value`: _array type_
|
|
604
|
-
|
|
605
|
-
Item to insert. This must conform to the `items` type described in the schema.
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
```js
|
|
609
|
-
// in the case of the `items` type being an object with name, value, and status field
|
|
610
|
-
client.set({
|
|
611
|
-
$id: 'ar165415',
|
|
612
|
-
myobjectarray: {
|
|
613
|
-
$assing: {
|
|
614
|
-
$idx: 25,
|
|
615
|
-
$value: {
|
|
616
|
-
name: 'match ' + i,
|
|
617
|
-
value: i,
|
|
618
|
-
status: i < 5 ? 100 : 300,
|
|
619
|
-
}
|
|
620
|
-
},
|
|
621
|
-
},
|
|
622
|
-
})
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
// in the case of the `items` type being 'number'
|
|
626
|
-
client.set({
|
|
627
|
-
$id: 'ar542875421',
|
|
628
|
-
mynumberarray: {
|
|
629
|
-
$assign: {
|
|
630
|
-
$idx: 21,
|
|
631
|
-
$value: 58
|
|
632
|
-
},
|
|
633
|
-
},
|
|
634
|
-
})
|
|
635
|
-
```
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
#### `$remove`: _object_
|
|
639
|
-
|
|
640
|
-
This removes an item from the array at the specified index.
|
|
641
|
-
This object must have the `$idx` field.
|
|
642
|
-
|
|
643
|
-
```js
|
|
644
|
-
client.set({
|
|
645
|
-
$id: 'ar654984',
|
|
646
|
-
mynumberarray: {
|
|
647
|
-
$remove: {
|
|
648
|
-
$idx: 1,
|
|
649
|
-
},
|
|
650
|
-
},
|
|
651
|
-
})
|
|
652
|
-
```
|