@based/client 3.3.0 → 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.
- 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 +24 -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 +69 -127
- package/dist/index.js +224 -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 +42 -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 +7 -0
- package/dist/stream/nodeStream.js +117 -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 +113 -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 +36 -0
- package/dist/types/error.js +40 -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 +20 -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 +14 -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 +17 -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/schema.md
DELETED
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
# Schema of Based-db
|
|
2
|
-
|
|
3
|
-
<!-- - [Schema](#schema)
|
|
4
|
-
- [Fields](#fields)
|
|
5
|
-
- [Default](#default-fields)
|
|
6
|
-
- [Field types](#field-types) -->
|
|
7
|
-
|
|
8
|
-
<!-- The based query language allows you to set, delete and modify objects, subscriptions, and the database schema. The query language uses a format similar to JSON in order to describe the database operation(s) required. -->
|
|
9
|
-
|
|
10
|
-
## Introduction
|
|
11
|
-
|
|
12
|
-
The schema defines the properties of the nodes that the Based-DB instance will hold.
|
|
13
|
-
New properties can be added to the schema at any point using the `updateSchema()` method, **however existing properties cannot be removed or modified.**
|
|
14
|
-
|
|
15
|
-
## Schema object structure
|
|
16
|
-
|
|
17
|
-
The `configure()` method takes as argument a single object that follows a specific schema structure.
|
|
18
|
-
The schema object has three fields:
|
|
19
|
-
|
|
20
|
-
| Name | Type | Attributes | Description |
|
|
21
|
-
| ----------- | --------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
22
|
-
| `types` | Object | | This structure defines the type of nodes the database will hold and what fields they'll have. See [here](#types). |
|
|
23
|
-
| `languages` | list of strings | optional | This specifies which languages are allowed in a `text` field, and the fallback priority in case the requested language is not set. See later for more details |
|
|
24
|
-
| `rootType` | Object | optional | This can specify fields for the root object. Useful for example with the `$inherit` operator, to have a default property be inherited by all nodes. |
|
|
25
|
-
|
|
26
|
-
#### Example
|
|
27
|
-
|
|
28
|
-
```js
|
|
29
|
-
await client.configure({
|
|
30
|
-
languages: ['en', 'de', 'nl'],
|
|
31
|
-
rootType: {
|
|
32
|
-
fields: {
|
|
33
|
-
value: { type: 'number' },
|
|
34
|
-
nested: {
|
|
35
|
-
type: 'object',
|
|
36
|
-
properties: {
|
|
37
|
-
fun: { type: 'string' },
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
types: {
|
|
43
|
-
room: {
|
|
44
|
-
prefix: 'rm',
|
|
45
|
-
fields: {
|
|
46
|
-
name: { type: 'string' },
|
|
47
|
-
createdAt: { type: 'timestamp' },
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
items: {
|
|
51
|
-
fields: {
|
|
52
|
-
values: {
|
|
53
|
-
type: 'object',
|
|
54
|
-
properties: {
|
|
55
|
-
item1: { type: 'string' },
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
})
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
## Types
|
|
65
|
-
|
|
66
|
-
Whenever describing a new type of node in the schema, two fields can be specified:
|
|
67
|
-
| Name | Type | Attributes | description |
|
|
68
|
-
| -------- | ------ | --------- | ------------------------------------------------------------------------------------------------------------------- |
|
|
69
|
-
| `prefix` | string | optional | Two character string that identifies the type. The ID of each node of that type will then start with this prefix. |
|
|
70
|
-
| `fields` | Object | | Defines the [fields](#fields) for the type. Each object key is a field name and its value the field difinition. |
|
|
71
|
-
|
|
72
|
-
### Fields
|
|
73
|
-
|
|
74
|
-
Each new node type defined in the schema can have multiple fields, each with a specific [type](#types).
|
|
75
|
-
|
|
76
|
-
Each node type will always have a special field `id`, which contains a unique identifier for the node.
|
|
77
|
-
Each field must specify its type. The types allowed are [described here](#types), and they all have special behaviours and properties.
|
|
78
|
-
|
|
79
|
-
##### Default fields
|
|
80
|
-
|
|
81
|
-
A few fields are implicitely added to each node type, namely:
|
|
82
|
-
|
|
83
|
-
- `id`: _string_
|
|
84
|
-
- `type`: _string_
|
|
85
|
-
- `parents`: _references_
|
|
86
|
-
- `children`: _references_
|
|
87
|
-
- `ancestors`: _references_
|
|
88
|
-
- `descendants`: _references_
|
|
89
|
-
|
|
90
|
-
All these have special meaning which become apparent when learning about the [get method and queries.](get.md)
|
|
91
|
-
|
|
92
|
-
### Field types
|
|
93
|
-
|
|
94
|
-
The **type** of a field defines the data stored in it and the operations that can be applied to it.
|
|
95
|
-
The possible types and their properties are described here:
|
|
96
|
-
|
|
97
|
-
| Types | Description and properties |
|
|
98
|
-
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
99
|
-
| `boolean` | Holds a `true` or `false` value. |
|
|
100
|
-
| `float` | Holds a floating point number. |
|
|
101
|
-
| `int` | Holds an integer |
|
|
102
|
-
| `number` | Holds a number. Useful when the input could be either a float or an integer |
|
|
103
|
-
| `string` | Holds a string. |
|
|
104
|
-
| `text` | This is a special type that holds a string localized in multiple languages. See [here](TODO) for more details. |
|
|
105
|
-
| `digest` | Holds a hashed version of the string you put in it. |
|
|
106
|
-
| `url` | Holds a url. It checks that input conforms to a url. |
|
|
107
|
-
| `email` | Holds a email. It checks that input conforms to an email. |
|
|
108
|
-
| `phone` | Holds a phone number as a string. It checks that input conforms to a phone number. |
|
|
109
|
-
| `timestamp` | Holds a time stamp in milliseconds, following the [Unix epoch format](https://en.wikipedia.org/wiki/Unix_time) |
|
|
110
|
-
| `reference` | Holds a node ID. |
|
|
111
|
-
| `references` | Holds an array of node IDs |
|
|
112
|
-
| `object` | This type allows for nested structures, and its fields are then indexed, meaning they can then be referenced directly in a query, later. |
|
|
113
|
-
| `array` | A list of items of one type, which must be specified in the schema. Special operators such as `$push`, `$assing` `$insert`, `$remove` can be used to manipulate the array. |
|
|
114
|
-
| `record` | A record works similarly to an Hashmap, as in, the schema specify what type of value the record can take, and if the user tries to set a different one, it throws an error. See later for more examples. |
|
|
115
|
-
| `set` | A mathematical set. Holds a list of **unique** values of a single basic type (meaning it can't hold objects or arrays), specified in the `item` field. |
|
|
116
|
-
| `json` | This can hold anything and formats it to JSON, returning it in the most appropriate type when queried. Unlike the `oject` type, you can't query the fields if you decide to store a structure in it. Equivalent to storing something with `JSON.stringify()` and returning it with `JSON.parse()`. |
|
|
117
|
-
|
|
118
|
-
Currently Based also has two reserved field names with special properties:
|
|
119
|
-
|
|
120
|
-
- `createdAt` : _timestamp_
|
|
121
|
-
- `updatedAt` : _timestamp_
|
|
122
|
-
|
|
123
|
-
These are **only available if specifically mentioned in the schema**, and they are automatically populated by the server whenever the node is created or updated, respectively.
|
|
124
|
-
|
|
125
|
-
### Special fields and types
|
|
126
|
-
|
|
127
|
-
#### `languages` field in the schema object
|
|
128
|
-
|
|
129
|
-
When specifying the allowed languages in the [schema object](#schema-object-structure), we also implicitely specify the order on what to fall back if the required language isn't present. For example, if we were to query a text field with
|
|
130
|
-
|
|
131
|
-
```js
|
|
132
|
-
get({ $id: id, $language: 'de', myTextField: true })
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
but the requested object wasn't available in German, following this schema
|
|
136
|
-
|
|
137
|
-
```js
|
|
138
|
-
languages: ['en', 'de', 'nl'],
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
it would then try to return the English version of it and if that were to be missing too, Dutch.
|
|
142
|
-
|
|
143
|
-
If you want to learn more about the `get` query syntax, head over [here](TODO).
|
|
144
|
-
|
|
145
|
-
#### `text` type
|
|
146
|
-
|
|
147
|
-
The text type is a structure that contains for each key the same string localized to a different language. This is used in combination with the `$language` operator when setting or getting a value. See later for more info.
|
|
148
|
-
|
|
149
|
-
#### `object` type
|
|
150
|
-
|
|
151
|
-
When setting a field type to `object`, the schema must include another special field called `properties` where the values of the object are specified.
|
|
152
|
-
|
|
153
|
-
```js
|
|
154
|
-
types: {
|
|
155
|
-
// ...
|
|
156
|
-
movie: {
|
|
157
|
-
prefix: 'mo',
|
|
158
|
-
fields: {
|
|
159
|
-
title: { type: 'text' },
|
|
160
|
-
technicalData: {
|
|
161
|
-
type: 'object',
|
|
162
|
-
properties: {
|
|
163
|
-
runtime: { type: 'int' },
|
|
164
|
-
color: { type: 'string' },
|
|
165
|
-
aspectRatio: { type: 'string' }
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
#### `array` type
|
|
174
|
-
|
|
175
|
-
When setting a field type to `array`, the schema must include another special field called `items` where the type of the array is specified. This can be any other schema type, defined appropriately (i.e. `object`s must have `properties` and so on).
|
|
176
|
-
|
|
177
|
-
```js
|
|
178
|
-
types: {
|
|
179
|
-
// ...
|
|
180
|
-
thing: {
|
|
181
|
-
prefix: 'th',
|
|
182
|
-
fields: {
|
|
183
|
-
title: { type: 'text' },
|
|
184
|
-
myarray: {
|
|
185
|
-
type: 'array',
|
|
186
|
-
items: {
|
|
187
|
-
type: 'object',
|
|
188
|
-
properties: {
|
|
189
|
-
title: { type: 'text' },
|
|
190
|
-
name: { type: 'string' },
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
},
|
|
195
|
-
},
|
|
196
|
-
}
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
#### `set` type
|
|
200
|
-
|
|
201
|
-
When setting a field type to `set`, the schema must include another special field called `items` where the type of the set is specified.
|
|
202
|
-
|
|
203
|
-
```js
|
|
204
|
-
types: {
|
|
205
|
-
// ...
|
|
206
|
-
company:{
|
|
207
|
-
prefix: 'na',
|
|
208
|
-
fields: {
|
|
209
|
-
employees: {
|
|
210
|
-
type: 'set',
|
|
211
|
-
items: { type: 'string' }
|
|
212
|
-
},
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
#### `record` type
|
|
219
|
-
|
|
220
|
-
When setting a field type to `record`, the schema must include another special field called `values` where the type of value the record can hold is specified.
|
|
221
|
-
|
|
222
|
-
```js
|
|
223
|
-
types: {
|
|
224
|
-
// ...
|
|
225
|
-
company: {
|
|
226
|
-
prefix: 'na',
|
|
227
|
-
fields: {
|
|
228
|
-
employees: {
|
|
229
|
-
type: 'record',
|
|
230
|
-
values: { type: 'string' }
|
|
231
|
-
},
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
<!--
|
|
238
|
-
To add and remove items from the set, the following operators are supported:
|
|
239
|
-
|
|
240
|
-
- [`$default`](#default---any)
|
|
241
|
-
- [`$value`](#value---any)
|
|
242
|
-
- [`$ref`](#ref---string)
|
|
243
|
-
- [`$add`](#add---any)
|
|
244
|
-
- [`$delete`](#delete---any) -->
|