spyne 0.19.1 → 0.20.0
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/.eslintrc.js +4 -3
- package/.travis.yml +24 -11
- package/karma.conf.js +76 -86
- package/lib/spyne.esm.js +15 -0
- package/lib/spyne.esm.js.map +1 -0
- package/lib/spyne.umd.js +9565 -0
- package/package.json +47 -27
- package/rollup.config.js +26 -0
- package/src/spyne/channels/channel-fetch-class.js +39 -43
- package/src/spyne/channels/channel-payload-class.js +61 -74
- package/src/spyne/channels/channel-proxy.js +25 -26
- package/src/spyne/channels/channel.js +141 -149
- package/src/spyne/channels/channels-config.js +46 -47
- package/src/spyne/channels/channels-map.js +61 -65
- package/src/spyne/channels/spyne-channel-lifecycle.js +12 -12
- package/src/spyne/channels/spyne-channel-route.js +241 -250
- package/src/spyne/channels/spyne-channel-ui.js +213 -75
- package/src/spyne/channels/spyne-channel-window.js +157 -157
- package/src/spyne/spyne-app.js +32 -19
- package/src/spyne/spyne-plugins.js +55 -70
- package/src/spyne/spyne.js +23 -23
- package/src/spyne/utils/channel-config-validator.js +10 -10
- package/src/spyne/utils/channel-fetch-util.js +72 -55
- package/src/spyne/utils/channel-payload-filter.js +89 -100
- package/src/spyne/utils/deep-merge.js +31 -29
- package/src/spyne/utils/frp-tools.js +108 -92
- package/src/spyne/utils/gc.js +6 -6
- package/src/spyne/utils/mixins/base-core-mixins.js +17 -15
- package/src/spyne/utils/mixins/base-streams-mixins.js +9 -9
- package/src/spyne/utils/route-channel-updater.js +23 -29
- package/src/spyne/utils/safe-clone.js +40 -58
- package/src/spyne/utils/sanitize-html.js +35 -0
- package/src/spyne/utils/security-policy.js +11 -0
- package/src/spyne/utils/spyne-app-properties.js +110 -114
- package/src/spyne/utils/spyne-logger.js +4 -11
- package/src/spyne/utils/spyne-plugins-methods.js +38 -63
- package/src/spyne/utils/spyne-trait.js +33 -33
- package/src/spyne/utils/spyne-utils-channel-route-url.js +229 -153
- package/src/spyne/utils/spyne-utils-channel-route.js +128 -138
- package/src/spyne/utils/spyne-utils-channel-window.js +39 -39
- package/src/spyne/utils/viewstream-animations.js +12 -12
- package/src/spyne/utils/viewstream-observables.js +45 -45
- package/src/spyne/views/dom-element-template.js +111 -114
- package/src/spyne/views/dom-element.js +82 -84
- package/src/spyne/views/view-stream-broadcaster.js +66 -62
- package/src/spyne/views/view-stream-element.js +105 -106
- package/src/spyne/views/view-stream-payload.js +25 -27
- package/src/spyne/views/view-stream-selector.js +157 -163
- package/src/spyne/views/view-stream.js +416 -640
- package/src/tests/channels/channel-dom.test.js +15 -15
- package/src/tests/channels/channel-fetch.test.js +51 -62
- package/src/tests/channels/channel-payload-class.test.js +50 -63
- package/src/tests/channels/channel-payload-filter.test.js +133 -193
- package/src/tests/channels/channel-route.test.js +102 -112
- package/src/tests/channels/channel-stream-item.test.js +19 -19
- package/src/tests/channels/channel-ui.test.js +15 -27
- package/src/tests/channels/channel-util-dom.test.js +31 -31
- package/src/tests/channels/channel.test.js +20 -25
- package/src/tests/channels/route-utils.test.js +61 -66
- package/src/tests/channels/url-utils.test.js +151 -151
- package/src/tests/channels/view-stream-broadcaster.test.js +7 -7
- package/src/tests/import.test.js +5 -5
- package/src/tests/index.js +6 -7
- package/src/tests/index.test.js +6 -8
- package/src/tests/mocks/channel-payload-data.js +218 -220
- package/src/tests/mocks/enhancer.test.js +5 -5
- package/src/tests/mocks/payload-ui.js +87 -90
- package/src/tests/mocks/routes-data.js +264 -266
- package/src/tests/mocks/spyne-docs.mocks.js +3 -3
- package/src/tests/mocks/template-renderer.mocks.js +47 -47
- package/src/tests/mocks/utils-data.js +78 -79
- package/src/tests/mocks/viewstream-internal-payload.mocks.js +50 -50
- package/src/tests/mocks/window-events-arr.js +1 -1
- package/src/tests/package-json.spec.test.js +9 -0
- package/src/tests/spyne-app.test.js +15 -18
- package/src/tests/spyne-plugin.test.js +16 -20
- package/src/tests/utils/channel-action-filter.test.js +84 -86
- package/src/tests/utils/channel-data-packet-generator.unused.js +62 -86
- package/src/tests/utils/channel-fetch-util.test.js +64 -66
- package/src/tests/utils/frp-tools.test.js +19 -19
- package/src/tests/utils/plugins-methods.test.js +31 -55
- package/src/tests/utils/security.test.js +10 -0
- package/src/tests/utils/spyne-app-properties.test.js +4 -8
- package/src/tests/views/dom-el-selectors.test.js +112 -119
- package/src/tests/views/dom-el-template-proxy.test.js +7 -0
- package/src/tests/views/dom-el-template.test.js +186 -156
- package/src/tests/views/dom-el.test.js +58 -56
- package/src/tests/views/view-stream-enhancer-loader.test.js +2 -2
- package/src/tests/views/view-stream-enhancer.test.js +11 -11
- package/src/tests/views/view-stream.test.js +22 -33
- package/webpack.config.js +76 -67
- package/docs/-_%20Solves%20equations%20of%20the%20form%20a%20_%20x%20=%20b.html +0 -487
- package/docs/DomItem.html +0 -298
- package/docs/DomItem_DomItem.html +0 -314
- package/docs/ViewStream.html +0 -2249
- package/docs/ViewStream_ViewStream.html +0 -503
- package/docs/custom/css/jsdoc-viewstream.css +0 -377
- package/docs/custom/layout.tmpl +0 -47
- package/docs/dom-item.js.html +0 -213
- package/docs/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Bold-webfont.svg +0 -1830
- package/docs/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
- package/docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Italic-webfont.svg +0 -1830
- package/docs/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Light-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Light-webfont.svg +0 -1831
- package/docs/fonts/OpenSans-Light-webfont.woff +0 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
- package/docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Regular-webfont.svg +0 -1831
- package/docs/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/docs/global.html +0 -548
- package/docs/index-custom.html +0 -79
- package/docs/index.html +0 -82
- package/docs/jsdoc.config.json +0 -22
- package/docs/scripts/linenumber.js +0 -25
- package/docs/scripts/prettify/Apache-License-2.0.txt +0 -202
- package/docs/scripts/prettify/lang-css.js +0 -2
- package/docs/scripts/prettify/prettify.js +0 -28
- package/docs/styles/jsdoc-default.css +0 -358
- package/docs/styles/prettify-jsdoc.css +0 -111
- package/docs/styles/prettify-tomorrow.css +0 -132
- package/docs/view-stream.js.html +0 -767
|
@@ -1,117 +1,102 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { DomElement } from './views/dom-element'
|
|
2
|
+
import { SpyneAppProperties } from './utils/spyne-app-properties'
|
|
3
|
+
import { is, clone, pathSatisfies } from 'ramda'
|
|
3
4
|
export class SpynePlugin {
|
|
5
|
+
constructor(props = {}) {
|
|
6
|
+
let { name, config, parentEl } = props
|
|
7
|
+
this.props = props
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
this.props = props;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (config===undefined){
|
|
11
|
-
config = clone(props);
|
|
9
|
+
if (config === undefined) {
|
|
10
|
+
config = clone(props)
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
this.name = name || 'empty'
|
|
15
|
-
this.props.name = name
|
|
16
|
-
config = SpynePlugin.mergeDefaultConfig(config, this.defaultConfig())
|
|
17
|
-
this.props.parentEl = parentEl || SpynePlugin.createParentEl()
|
|
18
|
-
SpynePlugin.getSpyneApp(name, config)
|
|
13
|
+
this.name = name || 'empty'
|
|
14
|
+
this.props.name = name
|
|
15
|
+
config = SpynePlugin.mergeDefaultConfig(config, this.defaultConfig())
|
|
16
|
+
this.props.parentEl = parentEl || SpynePlugin.createParentEl()
|
|
17
|
+
SpynePlugin.getSpyneApp(name, config)
|
|
19
18
|
|
|
20
|
-
if (this.props.traits!==undefined){
|
|
21
|
-
this.addTraits(this.props.traits)
|
|
19
|
+
if (this.props.traits !== undefined) {
|
|
20
|
+
this.addTraits(this.props.traits)
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
this.onBeforeRegistered()
|
|
25
|
-
this.onRegistered()
|
|
26
|
-
this.onRender()
|
|
23
|
+
this.onBeforeRegistered()
|
|
24
|
+
this.onRegistered()
|
|
25
|
+
this.onRender()
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
static mergeDefaultConfig(config={}, defaultConfig=this.defaultConfig()){
|
|
30
|
-
return Object.assign(defaultConfig, config)
|
|
28
|
+
static mergeDefaultConfig(config = {}, defaultConfig = this.defaultConfig()) {
|
|
29
|
+
return Object.assign(defaultConfig, config)
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
static getSpyneApp(name, config){
|
|
34
|
-
if(SpyneAppProperties.initialized===false){
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
SpyneAppProperties.addPluginConfig(name, config);
|
|
32
|
+
static getSpyneApp(name, config) {
|
|
33
|
+
if (SpyneAppProperties.initialized === false) {
|
|
34
|
+
console.warn(`Spyne Warning: Unable to install plugin, ${name}! SpyneApp has not been initialized!`)
|
|
35
|
+
// SpyneApp.init()
|
|
36
|
+
} else {
|
|
37
|
+
SpyneAppProperties.addPluginConfig(name, config)
|
|
40
38
|
}
|
|
41
|
-
|
|
42
39
|
}
|
|
43
40
|
|
|
41
|
+
static updateSpyneConfig(spyneApp, pluginName, pluginConfig) {
|
|
42
|
+
const pathExists = pathSatisfies(is(Object), ['config', 'plugins', pluginName])(spyneApp)
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (pathExists===true){
|
|
49
|
-
if (spyneApp.config.debug===true) {
|
|
44
|
+
if (pathExists === true) {
|
|
45
|
+
if (spyneApp.config.debug === true) {
|
|
50
46
|
console.warn(`Spyne Warning: The plugin, ${pluginName}, already exists`)
|
|
51
47
|
}
|
|
52
|
-
|
|
48
|
+
return false
|
|
53
49
|
}
|
|
54
|
-
spyneApp.config.plugins[pluginName] = pluginConfig
|
|
55
|
-
return spyneApp.config.plugins[pluginName]
|
|
50
|
+
spyneApp.config.plugins[pluginName] = pluginConfig
|
|
51
|
+
return spyneApp.config.plugins[pluginName]
|
|
56
52
|
}
|
|
57
53
|
|
|
58
|
-
static createParentEl(el){
|
|
59
|
-
|
|
60
|
-
const createPluginParentEl = ()=>{
|
|
54
|
+
static createParentEl(el) {
|
|
55
|
+
const createPluginParentEl = () => {
|
|
61
56
|
const pluginEl = document.getElementById('spyne-plugins')
|
|
62
57
|
|
|
63
|
-
const createPluginEl = ()=>{
|
|
58
|
+
const createPluginEl = () => {
|
|
64
59
|
const pluginEl = new DomElement({
|
|
65
60
|
id: 'spyne-plugins'
|
|
66
|
-
})
|
|
67
|
-
document.body.appendChild(pluginEl.render())
|
|
61
|
+
})
|
|
62
|
+
document.body.appendChild(pluginEl.render())
|
|
68
63
|
const el = document.getElementById('spyne-plugins')
|
|
69
|
-
el.style.cssText=
|
|
70
|
-
return el
|
|
64
|
+
el.style.cssText = 'position:absolute; top:0;left:0;width:100%;height:100%;min-height:100vh;z-index:1000000; pointer-events:none'
|
|
65
|
+
return el
|
|
71
66
|
}
|
|
72
|
-
return pluginEl || createPluginEl()
|
|
67
|
+
return pluginEl || createPluginEl()
|
|
73
68
|
}
|
|
74
69
|
|
|
75
|
-
return el || createPluginParentEl()
|
|
70
|
+
return el || createPluginParentEl()
|
|
76
71
|
}
|
|
77
72
|
|
|
78
|
-
addTraits(traits){
|
|
79
|
-
if (traits.constructor.name!=='Array'){
|
|
80
|
-
traits = [traits]
|
|
73
|
+
addTraits(traits) {
|
|
74
|
+
if (traits.constructor.name !== 'Array') {
|
|
75
|
+
traits = [traits]
|
|
76
|
+
}
|
|
77
|
+
const addTrait = (TraitClass) => {
|
|
78
|
+
return new TraitClass(this)
|
|
81
79
|
}
|
|
82
|
-
const addTrait=(TraitClass)=>{
|
|
83
|
-
return new TraitClass(this);
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
traits.forEach(addTrait);
|
|
87
80
|
|
|
81
|
+
traits.forEach(addTrait)
|
|
88
82
|
}
|
|
89
83
|
|
|
90
|
-
onBeforeRegistered(){
|
|
91
|
-
this.props.pluginName = this.props.name
|
|
92
|
-
this.props.config = SpyneAppProperties.getPluginConfigByPluginName(this.props.pluginName)
|
|
84
|
+
onBeforeRegistered() {
|
|
85
|
+
this.props.pluginName = this.props.name
|
|
86
|
+
this.props.config = SpyneAppProperties.getPluginConfigByPluginName(this.props.pluginName)
|
|
93
87
|
}
|
|
94
88
|
|
|
95
|
-
defaultConfig(){
|
|
96
|
-
|
|
89
|
+
defaultConfig() {
|
|
97
90
|
return {
|
|
98
91
|
|
|
99
|
-
|
|
100
92
|
}
|
|
101
|
-
|
|
102
93
|
}
|
|
103
94
|
|
|
104
|
-
onRegistered(){
|
|
105
|
-
|
|
95
|
+
onRegistered() {
|
|
106
96
|
|
|
107
97
|
}
|
|
108
98
|
|
|
109
|
-
onRender(){
|
|
110
|
-
|
|
99
|
+
onRender() {
|
|
111
100
|
|
|
112
101
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
102
|
}
|
|
117
|
-
|
package/src/spyne/spyne.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { ChannelsMap } from './channels/channels-map'
|
|
2
|
-
import { DomElement } from './views/dom-element'
|
|
3
|
-
import {DomElementTemplate} from './views/dom-element-template'
|
|
4
|
-
import { ViewStreamElement } from './views/view-stream-element'
|
|
5
|
-
import { ViewStreamSelector} from './views/view-stream-selector'
|
|
6
|
-
import { ViewStream } from './views/view-stream'
|
|
7
|
-
import { ViewStreamBroadcaster } from './views/view-stream-broadcaster'
|
|
8
|
-
import { SpyneTrait } from './utils/spyne-trait'
|
|
9
|
-
import { ViewStreamPayload } from './views/view-stream-payload'
|
|
10
|
-
import { Channel } from './channels/channel'
|
|
11
|
-
import { ChannelFetch } from './channels/channel-fetch-class'
|
|
12
|
-
import {ChannelFetchUtil} from './utils/channel-fetch-util'
|
|
13
|
-
import { ChannelPayload } from './channels/channel-payload-class'
|
|
14
|
-
import {ChannelPayloadFilter} from './utils/channel-payload-filter'
|
|
15
|
-
import {SpynePlugin} from './spyne-plugins'
|
|
16
|
-
import { deepMerge } from './utils/deep-merge'
|
|
17
|
-
import {safeClone} from './utils/safe-clone'
|
|
18
|
-
import {SpyneAppProperties} from './utils/spyne-app-properties'
|
|
19
|
-
import {SpyneApp} from './spyne-app'
|
|
1
|
+
import { ChannelsMap } from './channels/channels-map'
|
|
2
|
+
import { DomElement } from './views/dom-element'
|
|
3
|
+
import { DomElementTemplate } from './views/dom-element-template'
|
|
4
|
+
import { ViewStreamElement } from './views/view-stream-element'
|
|
5
|
+
import { ViewStreamSelector } from './views/view-stream-selector'
|
|
6
|
+
import { ViewStream } from './views/view-stream'
|
|
7
|
+
import { ViewStreamBroadcaster } from './views/view-stream-broadcaster'
|
|
8
|
+
import { SpyneTrait } from './utils/spyne-trait'
|
|
9
|
+
import { ViewStreamPayload } from './views/view-stream-payload'
|
|
10
|
+
import { Channel } from './channels/channel'
|
|
11
|
+
import { ChannelFetch } from './channels/channel-fetch-class'
|
|
12
|
+
import { ChannelFetchUtil } from './utils/channel-fetch-util'
|
|
13
|
+
import { ChannelPayload } from './channels/channel-payload-class'
|
|
14
|
+
import { ChannelPayloadFilter } from './utils/channel-payload-filter'
|
|
15
|
+
import { SpynePlugin } from './spyne-plugins'
|
|
16
|
+
import { deepMerge } from './utils/deep-merge'
|
|
17
|
+
import { safeClone } from './utils/safe-clone'
|
|
18
|
+
import { SpyneAppProperties } from './utils/spyne-app-properties'
|
|
19
|
+
import { SpyneApp } from './spyne-app'
|
|
20
20
|
|
|
21
21
|
export {
|
|
22
22
|
ViewStreamElement,
|
|
23
23
|
Channel,
|
|
24
24
|
ChannelFetch,
|
|
25
|
-
|
|
25
|
+
ChannelFetchUtil,
|
|
26
26
|
ChannelsMap,
|
|
27
27
|
ViewStreamPayload,
|
|
28
28
|
ChannelPayload,
|
|
29
|
-
|
|
29
|
+
ChannelPayloadFilter,
|
|
30
30
|
DomElement,
|
|
31
31
|
DomElementTemplate,
|
|
32
32
|
ViewStream,
|
|
33
|
-
|
|
33
|
+
ViewStreamSelector,
|
|
34
34
|
ViewStreamBroadcaster,
|
|
35
35
|
SpyneTrait,
|
|
36
36
|
SpyneApp,
|
|
@@ -38,4 +38,4 @@ export {
|
|
|
38
38
|
SpynePlugin,
|
|
39
39
|
deepMerge,
|
|
40
40
|
safeClone
|
|
41
|
-
}
|
|
41
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import Validation from 'data.validation'
|
|
2
|
-
import {curry, curryN, length, always, reduce} from 'ramda'
|
|
3
|
-
const success = Validation.Success
|
|
4
|
-
const failure = Validation.Failure
|
|
5
|
-
let validate = () => {}
|
|
1
|
+
import Validation from 'data.validation'
|
|
2
|
+
import { curry, curryN, length, always, reduce } from 'ramda'
|
|
3
|
+
const success = Validation.Success
|
|
4
|
+
const failure = Validation.Failure
|
|
5
|
+
let validate = () => {}
|
|
6
6
|
if (curry !== undefined) {
|
|
7
7
|
validate = curry((validations, thing) => {
|
|
8
|
-
const initial = success(curryN(length(validations), always(thing)))
|
|
8
|
+
const initial = success(curryN(length(validations), always(thing)))
|
|
9
9
|
const run = (acc, v) =>
|
|
10
|
-
acc.ap(v.predicate(thing) ? success(thing) : failure([v.error]))
|
|
11
|
-
return reduce(run, initial, validations)
|
|
12
|
-
})
|
|
10
|
+
acc.ap(v.predicate(thing) ? success(thing) : failure([v.error]))
|
|
11
|
+
return reduce(run, initial, validations)
|
|
12
|
+
})
|
|
13
13
|
}
|
|
14
|
-
export { validate }
|
|
14
|
+
export { validate }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { from } from 'rxjs'
|
|
2
|
-
import { flatMap, map, publish, tap } from 'rxjs/operators'
|
|
3
|
-
import {compose, prop, defaultTo, over, lensProp, has, propEq, when, propIs, allPass, assoc, pick, mergeDeepRight} from 'ramda'
|
|
1
|
+
import { from } from 'rxjs'
|
|
2
|
+
import { flatMap, map, publish, tap } from 'rxjs/operators'
|
|
3
|
+
import { compose, prop, defaultTo, over, lensProp, has, propEq, when, propIs, allPass, assoc, pick, mergeDeepRight } from 'ramda'
|
|
4
4
|
export class ChannelFetchUtil {
|
|
5
5
|
/**
|
|
6
6
|
* @module ChannelFetchUtil
|
|
@@ -46,115 +46,132 @@ export class ChannelFetchUtil {
|
|
|
46
46
|
*
|
|
47
47
|
*/
|
|
48
48
|
|
|
49
|
-
|
|
50
49
|
constructor(options, subscriber, testMode, CHANNEL_NAME) {
|
|
50
|
+
const testSubscriber = (p) => console.log('FETCH RETURNED ', p)
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
this.
|
|
55
|
-
this.
|
|
56
|
-
this.
|
|
57
|
-
this.
|
|
58
|
-
this.
|
|
59
|
-
this.debug = options.debug !== undefined ? options.debug : false;
|
|
60
|
-
this.channelName = CHANNEL_NAME;
|
|
52
|
+
this._mapFn = ChannelFetchUtil.setMapFn(options)
|
|
53
|
+
this._url = ChannelFetchUtil.setUrl(options)
|
|
54
|
+
this._responseType = ChannelFetchUtil.setResponseType(options)
|
|
55
|
+
this._serverOptions = ChannelFetchUtil.setServerOptions(options)
|
|
56
|
+
this._subscriber = subscriber !== undefined ? subscriber : testSubscriber
|
|
57
|
+
this.debug = options.debug !== undefined ? options.debug : false
|
|
58
|
+
this.channelName = CHANNEL_NAME
|
|
61
59
|
|
|
62
|
-
|
|
60
|
+
const fetchProps = {
|
|
63
61
|
mapFn: this.mapFn,
|
|
64
62
|
url: this.url,
|
|
65
63
|
serverOptions: this.serverOptions,
|
|
66
64
|
responseType: this.responseType,
|
|
67
65
|
debug: this.debug
|
|
68
|
-
}
|
|
66
|
+
}
|
|
69
67
|
if (testMode !== true) {
|
|
70
|
-
ChannelFetchUtil.startWindowFetch(fetchProps, this._subscriber, this.channelName)
|
|
68
|
+
ChannelFetchUtil.startWindowFetch(fetchProps, this._subscriber, this.channelName)
|
|
71
69
|
}
|
|
72
70
|
}
|
|
73
71
|
|
|
74
72
|
static startWindowFetch(props, subscriber, channelName) {
|
|
75
|
-
|
|
76
|
-
const tapLogDebug = p => console.log('DEBUG FETCH :', p, {url, serverOptions, responseType, channelName})
|
|
77
|
-
const tapLog = debug === true ? tapLogDebug : () => {}
|
|
73
|
+
const { mapFn, url, serverOptions, responseType, debug } = props
|
|
74
|
+
const tapLogDebug = p => console.log('DEBUG FETCH :', p, { url, serverOptions, responseType, channelName })
|
|
75
|
+
const tapLog = debug === true ? tapLogDebug : () => {}
|
|
78
76
|
|
|
79
|
-
const mapWrapper = (mapMethod)=>{
|
|
80
|
-
const metadata = {channelName, url, responseType, serverOptions}
|
|
77
|
+
const mapWrapper = (mapMethod) => {
|
|
78
|
+
const metadata = { channelName, url, responseType, serverOptions }
|
|
81
79
|
|
|
82
|
-
return (data)=>{
|
|
83
|
-
return mapMethod(data, metadata)
|
|
80
|
+
return (data) => {
|
|
81
|
+
return mapMethod(data, metadata)
|
|
84
82
|
}
|
|
85
|
-
|
|
86
83
|
}
|
|
87
84
|
|
|
88
|
-
|
|
89
|
-
|
|
85
|
+
const response$ = from(window.fetch(url, serverOptions))
|
|
86
|
+
.pipe(tap(tapLog), flatMap(r => from(r[responseType]())),
|
|
90
87
|
map(mapWrapper(mapFn)),
|
|
91
|
-
publish())
|
|
88
|
+
publish())
|
|
92
89
|
|
|
93
|
-
response$.connect()
|
|
90
|
+
response$.connect()
|
|
94
91
|
|
|
95
|
-
response$.subscribe(subscriber)
|
|
92
|
+
response$.subscribe(subscriber)
|
|
96
93
|
}
|
|
97
94
|
|
|
98
95
|
static setMapFn(opts) {
|
|
99
|
-
const getFn = compose(defaultTo((p) => p), prop('mapFn'))
|
|
100
|
-
return getFn(opts)
|
|
96
|
+
const getFn = compose(defaultTo((p) => p), prop('mapFn'))
|
|
97
|
+
return getFn(opts)
|
|
101
98
|
}
|
|
102
99
|
|
|
103
100
|
static setUrl(opts) {
|
|
104
|
-
|
|
101
|
+
const url = prop('url', opts)
|
|
105
102
|
if (url === undefined) {
|
|
106
|
-
console.warn(
|
|
103
|
+
console.warn('SPYNE WARNING: URL is undefined for data channel')
|
|
107
104
|
}
|
|
108
|
-
return url
|
|
105
|
+
return url
|
|
109
106
|
}
|
|
110
107
|
|
|
111
108
|
static setResponseType(opts) {
|
|
112
|
-
return defaultTo('json', prop('responseType', opts))
|
|
109
|
+
return defaultTo('json', prop('responseType', opts))
|
|
113
110
|
}
|
|
114
111
|
|
|
115
112
|
get mapFn() {
|
|
116
|
-
return this._mapFn
|
|
113
|
+
return this._mapFn
|
|
117
114
|
}
|
|
118
115
|
|
|
119
116
|
get url() {
|
|
120
|
-
return this._url
|
|
117
|
+
return this._url
|
|
121
118
|
}
|
|
122
119
|
|
|
123
120
|
get serverOptions() {
|
|
124
|
-
return this._serverOptions
|
|
121
|
+
return this._serverOptions
|
|
125
122
|
}
|
|
126
123
|
|
|
127
124
|
get responseType() {
|
|
128
|
-
return this._responseType
|
|
125
|
+
return this._responseType
|
|
129
126
|
}
|
|
130
127
|
|
|
131
128
|
static stringifyBodyIfItExists(obj) {
|
|
132
|
-
const convertToJSON = when(propIs(Object, 'body'), compose(over(lensProp('body'), JSON.stringify)))
|
|
129
|
+
const convertToJSON = when(propIs(Object, 'body'), compose(over(lensProp('body'), JSON.stringify)))
|
|
133
130
|
|
|
134
|
-
return convertToJSON(obj)
|
|
131
|
+
return convertToJSON(obj)
|
|
135
132
|
}
|
|
136
133
|
|
|
137
134
|
static updateMethodWhenBodyExists(opts) {
|
|
138
|
-
const hasBody = has('body')
|
|
139
|
-
const methodIsGet = propEq('GET', 'method')
|
|
140
|
-
const pred = allPass([hasBody, methodIsGet])
|
|
141
|
-
return when(pred, assoc('method', 'POST'))(opts)
|
|
135
|
+
const hasBody = has('body')
|
|
136
|
+
const methodIsGet = propEq('GET', 'method')
|
|
137
|
+
const pred = allPass([hasBody, methodIsGet])
|
|
138
|
+
return when(pred, assoc('method', 'POST'))(opts)
|
|
142
139
|
}
|
|
143
140
|
|
|
144
141
|
static setServerOptions(opts) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
142
|
+
const options = pick([
|
|
143
|
+
'method',
|
|
144
|
+
'headers',
|
|
145
|
+
'body',
|
|
146
|
+
'mode',
|
|
147
|
+
'credentials',
|
|
148
|
+
'cache',
|
|
149
|
+
'redirect',
|
|
150
|
+
'referrer',
|
|
151
|
+
'referrerPolicy',
|
|
152
|
+
'integrity',
|
|
153
|
+
'keepalive'
|
|
154
|
+
], opts)
|
|
155
|
+
let mergedOptions = mergeDeepRight(ChannelFetchUtil.baseOptions(), options)
|
|
156
|
+
mergedOptions = ChannelFetchUtil.updateMethodWhenBodyExists(mergedOptions)
|
|
157
|
+
mergedOptions = ChannelFetchUtil.stringifyBodyIfItExists(mergedOptions)
|
|
158
|
+
return mergedOptions
|
|
150
159
|
}
|
|
151
160
|
|
|
152
161
|
static baseOptions() {
|
|
153
162
|
return {
|
|
154
|
-
method: 'GET',
|
|
155
|
-
headers: {
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
163
|
+
method: 'GET', // Default method
|
|
164
|
+
headers: new Headers({
|
|
165
|
+
Accept: 'application/json, text/plain, */*'
|
|
166
|
+
}),
|
|
167
|
+
mode: 'cors', // Default mode
|
|
168
|
+
credentials: 'same-origin', // Default credentials policy
|
|
169
|
+
cache: 'default', // Default cache policy
|
|
170
|
+
redirect: 'follow', // Default redirect policy
|
|
171
|
+
referrer: 'client', // Default referrer policy
|
|
172
|
+
referrerPolicy: 'no-referrer-when-downgrade', // Default referrer policy
|
|
173
|
+
integrity: '', // Default integrity
|
|
174
|
+
keepalive: false // Default keepalive
|
|
175
|
+
}
|
|
159
176
|
}
|
|
160
177
|
}
|