@based/client 3.2.2 → 4.0.1

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.
Files changed (205) hide show
  1. package/README.md +28 -330
  2. package/dist/Emitter.d.ts +7 -6
  3. package/dist/Emitter.js +31 -6
  4. package/dist/Emitter.js.map +1 -1
  5. package/dist/authState/parseAuthState.d.ts +3 -0
  6. package/dist/authState/parseAuthState.js +51 -0
  7. package/dist/authState/parseAuthState.js.map +1 -0
  8. package/dist/authState/updateAuthState.d.ts +3 -0
  9. package/dist/authState/updateAuthState.js +15 -0
  10. package/dist/authState/updateAuthState.js.map +1 -0
  11. package/dist/channel/cleanUp.d.ts +2 -0
  12. package/dist/channel/cleanUp.js +32 -0
  13. package/dist/channel/cleanUp.js.map +1 -0
  14. package/dist/channel/index.d.ts +12 -0
  15. package/dist/channel/index.js +67 -0
  16. package/dist/channel/index.js.map +1 -0
  17. package/dist/genObserveId.d.ts +1 -0
  18. package/dist/genObserveId.js +12 -0
  19. package/dist/genObserveId.js.map +1 -0
  20. package/dist/getTargetInfo.d.ts +6 -0
  21. package/dist/getTargetInfo.js +14 -0
  22. package/dist/getTargetInfo.js.map +1 -0
  23. package/dist/getUrlFromOpts.d.ts +3 -0
  24. package/dist/getUrlFromOpts.js +24 -0
  25. package/dist/getUrlFromOpts.js.map +1 -0
  26. package/dist/incoming/debug.d.ts +9 -0
  27. package/dist/incoming/debug.js +132 -0
  28. package/dist/incoming/debug.js.map +1 -0
  29. package/dist/incoming/index.d.ts +2 -0
  30. package/dist/incoming/index.js +341 -0
  31. package/dist/incoming/index.js.map +1 -0
  32. package/dist/incoming/protocol.d.ts +9 -0
  33. package/dist/incoming/protocol.js +62 -0
  34. package/dist/incoming/protocol.js.map +1 -0
  35. package/dist/index.d.ts +69 -127
  36. package/dist/index.js +224 -15
  37. package/dist/index.js.map +1 -1
  38. package/dist/outgoing/debug.d.ts +8 -0
  39. package/dist/outgoing/debug.js +70 -0
  40. package/dist/outgoing/debug.js.map +1 -0
  41. package/dist/outgoing/index.d.ts +14 -0
  42. package/dist/outgoing/index.js +227 -0
  43. package/dist/outgoing/index.js.map +1 -0
  44. package/dist/outgoing/protocol.d.ts +24 -0
  45. package/dist/outgoing/protocol.js +200 -0
  46. package/dist/outgoing/protocol.js.map +1 -0
  47. package/dist/persistentStorage/browser.d.ts +5 -0
  48. package/dist/persistentStorage/browser.js +150 -0
  49. package/dist/persistentStorage/browser.js.map +1 -0
  50. package/dist/persistentStorage/index.d.ts +6 -0
  51. package/dist/persistentStorage/index.js +56 -0
  52. package/dist/persistentStorage/index.js.map +1 -0
  53. package/dist/persistentStorage/node.d.ts +6 -0
  54. package/dist/persistentStorage/node.js +104 -0
  55. package/dist/persistentStorage/node.js.map +1 -0
  56. package/dist/query/index.d.ts +17 -0
  57. package/dist/query/index.js +112 -0
  58. package/dist/query/index.js.map +1 -0
  59. package/dist/stream/fetch.d.ts +4 -0
  60. package/dist/stream/fetch.js +42 -0
  61. package/dist/stream/fetch.js.map +1 -0
  62. package/dist/stream/index.d.ts +4 -0
  63. package/dist/stream/index.js +65 -0
  64. package/dist/stream/index.js.map +1 -0
  65. package/dist/stream/nodeStream.d.ts +7 -0
  66. package/dist/stream/nodeStream.js +117 -0
  67. package/dist/stream/nodeStream.js.map +1 -0
  68. package/dist/stream/types.d.ts +37 -0
  69. package/dist/stream/types.js +8 -0
  70. package/dist/stream/types.js.map +1 -0
  71. package/dist/stream/uploadFileBrowser.d.ts +4 -0
  72. package/dist/stream/uploadFileBrowser.js +113 -0
  73. package/dist/stream/uploadFileBrowser.js.map +1 -0
  74. package/dist/types/auth.d.ts +11 -0
  75. package/dist/{selvaTypes/get.js → types/auth.js} +1 -1
  76. package/dist/types/auth.js.map +1 -0
  77. package/dist/types/cache.d.ts +6 -0
  78. package/dist/{selvaTypes/set.js → types/cache.js} +1 -1
  79. package/dist/types/cache.js.map +1 -0
  80. package/dist/types/channel.d.ts +25 -0
  81. package/dist/types/channel.js +3 -0
  82. package/dist/types/channel.js.map +1 -0
  83. package/dist/types/error.d.ts +36 -0
  84. package/dist/types/error.js +40 -0
  85. package/dist/types/error.js.map +1 -0
  86. package/dist/types/events.d.ts +34 -0
  87. package/dist/{selvaTypes/schema.js → types/events.js} +1 -1
  88. package/dist/types/events.js.map +1 -0
  89. package/dist/types/functions.d.ts +8 -0
  90. package/dist/types/functions.js +3 -0
  91. package/dist/types/functions.js.map +1 -0
  92. package/dist/types/generic.d.ts +20 -0
  93. package/dist/types/generic.js +3 -0
  94. package/dist/types/generic.js.map +1 -0
  95. package/dist/types/index.d.ts +6 -0
  96. package/dist/{subscriptions → types}/index.js +6 -10
  97. package/dist/types/index.js.map +1 -0
  98. package/dist/types/observe.d.ts +46 -0
  99. package/dist/types/observe.js +3 -0
  100. package/dist/types/observe.js.map +1 -0
  101. package/dist/websocket/index.d.ts +1 -1
  102. package/dist/websocket/index.js +14 -5
  103. package/dist/websocket/index.js.map +1 -1
  104. package/package.json +17 -27
  105. package/dist/Client.d.ts +0 -80
  106. package/dist/Client.js +0 -271
  107. package/dist/Client.js.map +0 -1
  108. package/dist/auth.d.ts +0 -13
  109. package/dist/auth.js +0 -87
  110. package/dist/auth.js.map +0 -1
  111. package/dist/createError.d.ts +0 -3
  112. package/dist/createError.js +0 -67
  113. package/dist/createError.js.map +0 -1
  114. package/dist/debug.d.ts +0 -2
  115. package/dist/debug.js +0 -21
  116. package/dist/debug.js.map +0 -1
  117. package/dist/file/fetch.d.ts +0 -6
  118. package/dist/file/fetch.js +0 -27
  119. package/dist/file/fetch.js.map +0 -1
  120. package/dist/file/getUrl.d.ts +0 -4
  121. package/dist/file/getUrl.js +0 -42
  122. package/dist/file/getUrl.js.map +0 -1
  123. package/dist/file/index.d.ts +0 -6
  124. package/dist/file/index.js +0 -95
  125. package/dist/file/index.js.map +0 -1
  126. package/dist/file/stream/browser.d.ts +0 -7
  127. package/dist/file/stream/browser.js +0 -17
  128. package/dist/file/stream/browser.js.map +0 -1
  129. package/dist/file/stream/index.d.ts +0 -7
  130. package/dist/file/stream/index.js +0 -86
  131. package/dist/file/stream/index.js.map +0 -1
  132. package/dist/file/uploadFileBrowser.d.ts +0 -3
  133. package/dist/file/uploadFileBrowser.js +0 -72
  134. package/dist/file/uploadFileBrowser.js.map +0 -1
  135. package/dist/findPrefix.d.ts +0 -3
  136. package/dist/findPrefix.js +0 -20
  137. package/dist/findPrefix.js.map +0 -1
  138. package/dist/idleTimeout.d.ts +0 -3
  139. package/dist/idleTimeout.js +0 -17
  140. package/dist/idleTimeout.js.map +0 -1
  141. package/dist/observable/index.d.ts +0 -28
  142. package/dist/observable/index.js +0 -84
  143. package/dist/observable/index.js.map +0 -1
  144. package/dist/printBasedObject.d.ts +0 -4
  145. package/dist/printBasedObject.js +0 -76
  146. package/dist/printBasedObject.js.map +0 -1
  147. package/dist/queue.d.ts +0 -5
  148. package/dist/queue.js +0 -53
  149. package/dist/queue.js.map +0 -1
  150. package/dist/request.d.ts +0 -6
  151. package/dist/request.js +0 -67
  152. package/dist/request.js.map +0 -1
  153. package/dist/selvaTypes/get.d.ts +0 -97
  154. package/dist/selvaTypes/get.js.map +0 -1
  155. package/dist/selvaTypes/schema.d.ts +0 -89
  156. package/dist/selvaTypes/schema.js.map +0 -1
  157. package/dist/selvaTypes/set.d.ts +0 -73
  158. package/dist/selvaTypes/set.js.map +0 -1
  159. package/dist/subscriptions/addGetSubscriber.d.ts +0 -3
  160. package/dist/subscriptions/addGetSubscriber.js +0 -87
  161. package/dist/subscriptions/addGetSubscriber.js.map +0 -1
  162. package/dist/subscriptions/addSubscriber.d.ts +0 -2
  163. package/dist/subscriptions/addSubscriber.js +0 -136
  164. package/dist/subscriptions/addSubscriber.js.map +0 -1
  165. package/dist/subscriptions/generateId.d.ts +0 -1
  166. package/dist/subscriptions/generateId.js +0 -11
  167. package/dist/subscriptions/generateId.js.map +0 -1
  168. package/dist/subscriptions/incomingSubscription.d.ts +0 -3
  169. package/dist/subscriptions/incomingSubscription.js +0 -87
  170. package/dist/subscriptions/incomingSubscription.js.map +0 -1
  171. package/dist/subscriptions/incomingSubscriptionDiff.d.ts +0 -3
  172. package/dist/subscriptions/incomingSubscriptionDiff.js +0 -85
  173. package/dist/subscriptions/incomingSubscriptionDiff.js.map +0 -1
  174. package/dist/subscriptions/index.d.ts +0 -10
  175. package/dist/subscriptions/index.js.map +0 -1
  176. package/dist/subscriptions/logoutSubscriptions.d.ts +0 -3
  177. package/dist/subscriptions/logoutSubscriptions.js +0 -36
  178. package/dist/subscriptions/logoutSubscriptions.js.map +0 -1
  179. package/dist/subscriptions/removeSendSubscriptionDataFromQueue.d.ts +0 -2
  180. package/dist/subscriptions/removeSendSubscriptionDataFromQueue.js +0 -14
  181. package/dist/subscriptions/removeSendSubscriptionDataFromQueue.js.map +0 -1
  182. package/dist/subscriptions/removeSubscriber.d.ts +0 -2
  183. package/dist/subscriptions/removeSubscriber.js +0 -44
  184. package/dist/subscriptions/removeSubscriber.js.map +0 -1
  185. package/dist/subscriptions/removeUnsubscribesFromQueue.d.ts +0 -2
  186. package/dist/subscriptions/removeUnsubscribesFromQueue.js +0 -14
  187. package/dist/subscriptions/removeUnsubscribesFromQueue.js.map +0 -1
  188. package/dist/subscriptions/sendAllSubscriptions.d.ts +0 -2
  189. package/dist/subscriptions/sendAllSubscriptions.js +0 -114
  190. package/dist/subscriptions/sendAllSubscriptions.js.map +0 -1
  191. package/dist/token.d.ts +0 -4
  192. package/dist/token.js +0 -35
  193. package/dist/token.js.map +0 -1
  194. package/dist/track.d.ts +0 -8
  195. package/dist/track.js +0 -71
  196. package/dist/track.js.map +0 -1
  197. package/docs/auth-based-ui-howto.md +0 -74
  198. package/docs/auth-howto.md +0 -166
  199. package/docs/auth.md +0 -93
  200. package/docs/authorize.md +0 -56
  201. package/docs/files.md +0 -66
  202. package/docs/get-started.md +0 -60
  203. package/docs/get.md +0 -759
  204. package/docs/schema.md +0 -244
  205. 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
- ```