@nxtedition/lib 21.0.0 → 21.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/deepstream.js +18 -9
- package/package.json +1 -1
package/deepstream.js
CHANGED
|
@@ -3,15 +3,22 @@ import qs from 'qs'
|
|
|
3
3
|
import cached from './util/cached.js'
|
|
4
4
|
import * as rxjs from 'rxjs'
|
|
5
5
|
|
|
6
|
+
const EMPTY_OPT = {}
|
|
7
|
+
const RECURSIVE_OPT = { recursive: true }
|
|
8
|
+
|
|
6
9
|
function provide(ds, domain, callback, options) {
|
|
7
10
|
if (typeof domain !== 'string') {
|
|
8
11
|
throw new Error('domain must be a string')
|
|
9
12
|
}
|
|
10
13
|
|
|
11
|
-
if (
|
|
12
|
-
options =
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
if (options === true) {
|
|
15
|
+
options = RECURSIVE_OPT
|
|
16
|
+
} else if (options == null) {
|
|
17
|
+
options = EMPTY_OPT
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (typeof options !== 'object') {
|
|
21
|
+
throw new Error('options must be an object, nully or `true`')
|
|
15
22
|
}
|
|
16
23
|
|
|
17
24
|
if (options.cached) {
|
|
@@ -30,20 +37,22 @@ function provide(ds, domain, callback, options) {
|
|
|
30
37
|
callback = cached(callback, options, (id, options, key) => key)
|
|
31
38
|
}
|
|
32
39
|
|
|
33
|
-
let idExpr
|
|
40
|
+
let idExpr
|
|
34
41
|
if (options.id === true) {
|
|
35
|
-
idExpr = '
|
|
42
|
+
idExpr = '[^}]:'
|
|
36
43
|
} else if (options.id === false) {
|
|
37
|
-
idExpr = '
|
|
44
|
+
idExpr = '[}]:'
|
|
45
|
+
} else {
|
|
46
|
+
idExpr = ':'
|
|
38
47
|
}
|
|
39
48
|
|
|
40
49
|
return ds.record.provide(
|
|
41
|
-
|
|
50
|
+
`${idExpr}(?:${domain})(?:[?].*)${options.strict ? '' : '?'}$`,
|
|
42
51
|
(key) => {
|
|
43
52
|
const [id, options] = parseKey(key)
|
|
44
53
|
return callback(id, options, key)
|
|
45
54
|
},
|
|
46
|
-
|
|
55
|
+
options,
|
|
47
56
|
)
|
|
48
57
|
}
|
|
49
58
|
|