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,5 +1,5 @@
|
|
|
1
|
-
import {isEmpty, head, values, compose, prop, complement, isNil, allPass, reduce, filter, equals, toPairs, replace, either, propEq, __,invert,path,zipObj, reject, keys, find, assoc, is,has, when, split, always, concat, join, flatten, map, ifElse, test, findLastIndex,last, defaultTo,fromPairs } from 'ramda'
|
|
2
|
-
import {SpyneAppProperties} from './spyne-app-properties'
|
|
1
|
+
import { isEmpty, head, values, compose, prop, complement, isNil, allPass, reduce, filter, equals, toPairs, replace, either, propEq, __, invert, path, zipObj, reject, keys, find, assoc, is, has, when, split, always, concat, join, flatten, map, ifElse, test, findLastIndex, last, defaultTo, fromPairs } from 'ramda'
|
|
2
|
+
import { SpyneAppProperties } from './spyne-app-properties'
|
|
3
3
|
|
|
4
4
|
export class SpyneUtilsChannelRouteUrl {
|
|
5
5
|
constructor() {
|
|
@@ -11,189 +11,265 @@ export class SpyneUtilsChannelRouteUrl {
|
|
|
11
11
|
* @desc
|
|
12
12
|
* Internal url methods for the SpyneRouteChannel
|
|
13
13
|
*/
|
|
14
|
-
this.checkIfObjIsNotEmptyOrNil = SpyneUtilsChannelRouteUrl.checkIfObjIsNotEmptyOrNil.bind(this)
|
|
14
|
+
this.checkIfObjIsNotEmptyOrNil = SpyneUtilsChannelRouteUrl.checkIfObjIsNotEmptyOrNil.bind(this)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
static checkIfObjIsNotEmptyOrNil(obj) {
|
|
18
|
-
const isNotEmpty = compose(complement(isEmpty), head, values)
|
|
19
|
-
const isNotNil = compose(complement(isNil), head, values)
|
|
20
|
-
const isNotNilAndIsNotEmpty = allPass([isNotEmpty, isNotNil])
|
|
21
|
-
return isNotNilAndIsNotEmpty(obj)
|
|
18
|
+
const isNotEmpty = compose(complement(isEmpty), head, values)
|
|
19
|
+
const isNotNil = compose(complement(isNil), head, values)
|
|
20
|
+
const isNotNilAndIsNotEmpty = allPass([isNotEmpty, isNotNil])
|
|
21
|
+
return isNotNilAndIsNotEmpty(obj)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
static checkIfParamValueMatchesRegex(paramValue, routeObj) {
|
|
25
|
-
const rejectParamKey = reject(equals('routeName'))
|
|
26
|
-
const keysArr = compose(rejectParamKey, keys)
|
|
27
|
-
const testForRegexMatch = str => test(new RegExp(str), paramValue)
|
|
28
|
-
const checker = compose(find(testForRegexMatch), keysArr)
|
|
29
|
-
const regexMatchStr = checker(routeObj)
|
|
25
|
+
const rejectParamKey = reject(equals('routeName'))
|
|
26
|
+
const keysArr = compose(rejectParamKey, keys)
|
|
27
|
+
const testForRegexMatch = str => test(new RegExp(str), paramValue)
|
|
28
|
+
const checker = compose(find(testForRegexMatch), keysArr)
|
|
29
|
+
const regexMatchStr = checker(routeObj)
|
|
30
30
|
if (is(String, regexMatchStr)) {
|
|
31
|
-
routeObj = assoc(paramValue, prop(regexMatchStr, routeObj), routeObj)
|
|
31
|
+
routeObj = assoc(paramValue, prop(regexMatchStr, routeObj), routeObj)
|
|
32
32
|
}
|
|
33
|
-
return routeObj
|
|
33
|
+
return routeObj
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
static formatStrAsWindowLocation(str) {
|
|
37
|
-
const hash = str
|
|
38
|
-
const search = str
|
|
39
|
-
const pathname = str
|
|
40
|
-
return { hash, search, pathname }
|
|
37
|
+
const hash = str
|
|
38
|
+
const search = str
|
|
39
|
+
const pathname = str
|
|
40
|
+
return { hash, search, pathname }
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
static getLocationStrByType(t, isHash = false, loc = window.location) {
|
|
44
|
-
const type = isHash === true ? 'hash' : t
|
|
44
|
+
const type = isHash === true ? 'hash' : t
|
|
45
45
|
|
|
46
46
|
const typeMap = {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
const propVal = typeMap[type]
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
slash: 'pathname',
|
|
48
|
+
query: 'search',
|
|
49
|
+
hash: 'hash'
|
|
50
|
+
}
|
|
51
|
+
const propVal = typeMap[type]
|
|
52
|
+
const str = prop(propVal, loc)
|
|
53
|
+
const checkForSlashAndHash = /^(\/)?(#)?(\/)?(.*)$/
|
|
54
54
|
// console.log("DATA LOC STR ",{str, loc, prop, type,isHash});
|
|
55
|
-
return str.replace(checkForSlashAndHash, '$4')
|
|
55
|
+
return str.replace(checkForSlashAndHash, '$4')
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
static createRouteArrayFromParams(data, route, t = 'slash', paramsFromLoc) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
let paramValFromData = data[keyword] !== undefined ? data[keyword] : prop(keyword, paramsFromLoc)
|
|
64
|
-
const paramValType = typeof (routeObj[paramValFromData])
|
|
59
|
+
const urlArr = []
|
|
60
|
+
const loopThroughParam = (routeObj) => {
|
|
61
|
+
const urlObj = {}
|
|
62
|
+
const keyword = routeObj.routeName // PARAM FORM SPYNE CONFIG
|
|
63
|
+
let paramValFromData = data[keyword] !== undefined ? data[keyword] : prop(keyword, paramsFromLoc) // PULL VALUE FOR THIS PARAM FROM DATA
|
|
64
|
+
const paramValType = typeof (routeObj[paramValFromData])
|
|
65
65
|
|
|
66
66
|
if (paramValType === 'string') {
|
|
67
|
-
paramValFromData = routeObj[paramValFromData]
|
|
67
|
+
paramValFromData = routeObj[paramValFromData]
|
|
68
68
|
} else if (paramValType === 'undefined') {
|
|
69
|
-
routeObj = this.checkIfParamValueMatchesRegex(paramValFromData, routeObj)
|
|
69
|
+
routeObj = this.checkIfParamValueMatchesRegex(paramValFromData, routeObj)
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
urlObj[keyword] = paramValFromData
|
|
72
|
+
urlObj[keyword] = paramValFromData
|
|
73
73
|
|
|
74
74
|
if (this.checkIfObjIsNotEmptyOrNil(urlObj)) {
|
|
75
|
-
urlArr.push(urlObj)
|
|
76
|
-
} else {
|
|
77
|
-
|
|
75
|
+
urlArr.push(urlObj)
|
|
78
76
|
}
|
|
79
77
|
|
|
80
|
-
const isObject = is(Object, routeObj)
|
|
81
|
-
const objectParamExists = has(paramValFromData, routeObj)
|
|
82
|
-
const objectContainsRoute = has('routePath', routeObj)
|
|
83
|
-
const recursivelyCallLoopBool = objectParamExists && isObject
|
|
78
|
+
const isObject = is(Object, routeObj)
|
|
79
|
+
const objectParamExists = has(paramValFromData, routeObj)
|
|
80
|
+
const objectContainsRoute = has('routePath', routeObj)
|
|
81
|
+
const recursivelyCallLoopBool = objectParamExists && isObject
|
|
84
82
|
if (recursivelyCallLoopBool === true) {
|
|
85
|
-
|
|
83
|
+
const newObj = routeObj[paramValFromData]
|
|
86
84
|
if (has('routePath', newObj)) {
|
|
87
|
-
loopThroughParam(newObj.routePath)
|
|
85
|
+
loopThroughParam(newObj.routePath)
|
|
88
86
|
}
|
|
89
87
|
} else if (objectContainsRoute === true && paramValFromData !== undefined) {
|
|
90
|
-
loopThroughParam(routeObj.routePath)
|
|
88
|
+
loopThroughParam(routeObj.routePath)
|
|
91
89
|
}
|
|
92
|
-
}
|
|
90
|
+
}
|
|
93
91
|
|
|
94
|
-
loopThroughParam(route)
|
|
92
|
+
loopThroughParam(route)
|
|
95
93
|
|
|
96
|
-
return urlArr
|
|
94
|
+
return urlArr
|
|
97
95
|
}
|
|
98
96
|
|
|
99
97
|
static createSlashString(arr) {
|
|
100
|
-
const arrClear = reject(isNil)
|
|
101
|
-
const notUndefined = when(complement(isNil, __), join('/'))
|
|
102
|
-
const stripRegex = replace(/^(\^*)(.*|^\$)(\$)$/,
|
|
103
|
-
const joiner = compose(stripRegex, notUndefined, arrClear, flatten, map(values))
|
|
104
|
-
return joiner(arr)
|
|
98
|
+
const arrClear = reject(isNil)
|
|
99
|
+
const notUndefined = when(complement(isNil, __), join('/'))
|
|
100
|
+
const stripRegex = replace(/^(\^*)(.*|^\$)(\$)$/, '$2')
|
|
101
|
+
const joiner = compose(stripRegex, notUndefined, arrClear, flatten, map(values))
|
|
102
|
+
return joiner(arr)
|
|
105
103
|
}
|
|
106
104
|
|
|
107
105
|
static createQueryString(arr) {
|
|
108
|
-
const arrClear = reject(isNil)
|
|
106
|
+
const arrClear = reject(isNil)
|
|
109
107
|
|
|
110
|
-
const isNotNilAndIsNotEmpty = this.checkIfObjIsNotEmptyOrNil
|
|
108
|
+
const isNotNilAndIsNotEmpty = this.checkIfObjIsNotEmptyOrNil
|
|
111
109
|
|
|
112
110
|
const createPair = compose(
|
|
113
111
|
join('='),
|
|
114
112
|
flatten,
|
|
115
|
-
toPairs)
|
|
113
|
+
toPairs)
|
|
116
114
|
|
|
117
115
|
const checkPair = ifElse(
|
|
118
116
|
isNotNilAndIsNotEmpty,
|
|
119
117
|
createPair,
|
|
120
118
|
always(undefined)
|
|
121
|
-
)
|
|
119
|
+
)
|
|
122
120
|
|
|
123
|
-
const mapArrayOfPairs = map(checkPair)
|
|
121
|
+
const mapArrayOfPairs = map(checkPair)
|
|
124
122
|
|
|
125
123
|
const checkIfStrIsEmpty = when(
|
|
126
124
|
complement(isEmpty),
|
|
127
|
-
concat('?'))
|
|
125
|
+
concat('?'))
|
|
128
126
|
|
|
129
127
|
const createQs = compose(
|
|
130
128
|
checkIfStrIsEmpty,
|
|
131
129
|
join('&'),
|
|
132
130
|
arrClear,
|
|
133
|
-
mapArrayOfPairs)
|
|
131
|
+
mapArrayOfPairs)
|
|
134
132
|
|
|
135
|
-
return createQs(arr)
|
|
133
|
+
return createQs(arr)
|
|
136
134
|
}
|
|
137
135
|
|
|
138
136
|
static checkPayloadForRegexOverrides(urlsArr, data, parseString = 'Value') {
|
|
139
137
|
// CHECK IF PAYLOAD HAS ANY OVERRIDES
|
|
140
|
-
const getPropValOverride = (key) => prop(`${key}${parseString}`, data)
|
|
138
|
+
const getPropValOverride = (key) => prop(`${key}${parseString}`, data)
|
|
141
139
|
|
|
142
140
|
// GET ANY POSSIBLE VALUE USING THE CURRENT KEY
|
|
143
|
-
const getOverrideVal = compose(getPropValOverride, head, keys)
|
|
141
|
+
const getOverrideVal = compose(getPropValOverride, head, keys)
|
|
144
142
|
|
|
145
143
|
// MAP ALL OBJECT VALS TO TEST FOR OVERRIDES
|
|
146
144
|
const mapUrlProps = (prop) => {
|
|
147
|
-
|
|
145
|
+
const overrideVal = getOverrideVal(prop)
|
|
148
146
|
|
|
149
147
|
// console.log("override val ",overrideVal, data);
|
|
150
148
|
// if regex value is found
|
|
151
149
|
if (overrideVal !== undefined) {
|
|
152
|
-
return assoc(compose(head, keys)(prop), overrideVal, prop)
|
|
150
|
+
return assoc(compose(head, keys)(prop), overrideVal, prop)
|
|
153
151
|
}
|
|
154
152
|
// identity
|
|
155
|
-
return prop
|
|
156
|
-
}
|
|
153
|
+
return prop
|
|
154
|
+
}
|
|
157
155
|
|
|
158
|
-
return map(mapUrlProps, urlsArr)
|
|
156
|
+
return map(mapUrlProps, urlsArr)
|
|
159
157
|
}
|
|
160
158
|
|
|
161
|
-
static
|
|
162
|
-
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
159
|
+
static checkForRouteValWithMultipleVals(urlsArr) {
|
|
160
|
+
// Define the internal method to extract the string before the pipe
|
|
161
|
+
const getStringBeforePipe = (input) => {
|
|
162
|
+
const match = input.match(/^[^|]*/)
|
|
163
|
+
return match ? (match[0] === '^$' ? '' : match[0]) : input
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const mapUrlArrObj = (obj) => {
|
|
167
|
+
const pipeReducer = (acc, key) => {
|
|
168
|
+
acc[key] = getStringBeforePipe(obj[key])
|
|
169
|
+
return acc
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (typeof obj === 'object') {
|
|
173
|
+
obj = Object.keys(obj).reduce(pipeReducer, {})
|
|
174
|
+
}
|
|
175
|
+
return obj
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (Array.isArray(urlsArr) === true) {
|
|
179
|
+
return urlsArr.map(mapUrlArrObj)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return urlsArr
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
static checkForRouteValsPartMatch(urlsArr, data = {}) {
|
|
186
|
+
/**
|
|
187
|
+
* 1. Loop through urlsArr
|
|
188
|
+
* 2. Loop through properties
|
|
189
|
+
* 3. Apply matchGlobPattern to each property value and check for match with data object property
|
|
190
|
+
* 4. Return the updated object with matched values, or keep the original pattern if no match
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
const matchGlobPattern = (str, globPattern) => {
|
|
194
|
+
const globPatternMatch = (pattern, value) => {
|
|
195
|
+
const escapedPattern = pattern
|
|
196
|
+
.replace(/[-/\\^$+?.()|[\]{}]/g, '\\$&') // Escape special characters
|
|
197
|
+
.replace(/\*/g, '[\\w\\d_-]*') // * should match any sequence of alphanumeric, underscores, or dashes
|
|
168
198
|
|
|
169
|
-
|
|
170
|
-
|
|
199
|
+
const regexPattern = new RegExp(`^${escapedPattern}$`) // Match the full string
|
|
200
|
+
return regexPattern.test(value)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Split the globPattern by pipe (|)
|
|
204
|
+
const patterns = globPattern.split('|')
|
|
205
|
+
|
|
206
|
+
// Check if the string matches any of the patterns
|
|
207
|
+
const hasMatch = patterns.some((pattern) => globPatternMatch(pattern, str))
|
|
208
|
+
|
|
209
|
+
// Return the string if there's a match, otherwise return the glob pattern
|
|
210
|
+
return hasMatch ? str : globPattern
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Function to check and replace matching properties
|
|
214
|
+
const replaceMatchingProperty = (obj) => {
|
|
215
|
+
const updatedObj = { ...obj } // Create a copy of the object to avoid mutation
|
|
216
|
+
|
|
217
|
+
// Function to check each property and apply matchGlobPattern
|
|
218
|
+
const checkAndReplaceProperty = (key) => {
|
|
219
|
+
if (Object.prototype.hasOwnProperty.call(updatedObj, key) && data[key]) {
|
|
220
|
+
updatedObj[key] = matchGlobPattern(data[key], updatedObj[key])
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Loop through the properties of the object
|
|
225
|
+
Object.keys(updatedObj).forEach(checkAndReplaceProperty)
|
|
226
|
+
|
|
227
|
+
return updatedObj
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Loop through the array and replace matching properties
|
|
231
|
+
return urlsArr.map(replaceMatchingProperty)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
static convertParamsToRoute(data, r = SpyneAppProperties.config.channels.ROUTE, t, locStr) {
|
|
235
|
+
const urlType = t !== undefined ? t : r.type
|
|
236
|
+
const isHash = r.isHash
|
|
237
|
+
const route = r.routes.routePath
|
|
238
|
+
const locationStr = locStr !== undefined ? locStr : this.getLocationStrByType(urlType, isHash)
|
|
239
|
+
const paramsFromCurrentLocation = this.convertRouteToParams(locationStr, r, urlType).routeData
|
|
240
|
+
let urlArr = this.createRouteArrayFromParams(data, route, urlType, paramsFromCurrentLocation)
|
|
241
|
+
|
|
242
|
+
urlArr = SpyneUtilsChannelRouteUrl.checkPayloadForRegexOverrides(urlArr, data)
|
|
243
|
+
urlArr = SpyneUtilsChannelRouteUrl.checkForRouteValWithMultipleVals(urlArr)
|
|
244
|
+
// THIS WILL MATCH EXACTLY THE PROPERTY ID, SO pageId="dashboard_1" will return that instead of globPattern[0]
|
|
245
|
+
// urlArr = SpyneUtilsChannelRouteUrl.checkForRouteValsPartMatch(urlArr, data)
|
|
246
|
+
// console.log('PARAMS TO ROUTE ', { data, r, urlArr, locationStr, paramsFromCurrentLocation })
|
|
171
247
|
|
|
172
248
|
// THIS CREATES A QUERY PATH STR
|
|
173
249
|
if (urlType === 'query') {
|
|
174
|
-
return this.createQueryString(urlArr)
|
|
250
|
+
return this.createQueryString(urlArr)
|
|
175
251
|
}
|
|
176
252
|
|
|
177
|
-
return this.createSlashString(urlArr)
|
|
253
|
+
return this.createSlashString(urlArr)
|
|
178
254
|
}
|
|
179
255
|
|
|
180
256
|
static findIndexOfMatchedStringOrRegex(mainStr, paramsArr) {
|
|
181
|
-
const checkForEmpty = replace(/^$/, '^$')
|
|
257
|
+
const checkForEmpty = replace(/^$/, '^$')
|
|
182
258
|
const createStrRegexTest = (str) => {
|
|
183
|
-
const reFn = s => new RegExp(s)
|
|
259
|
+
const reFn = s => new RegExp(s)
|
|
184
260
|
return {
|
|
185
261
|
str,
|
|
186
262
|
re: reFn(str)
|
|
187
|
-
}
|
|
188
|
-
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
189
265
|
|
|
190
266
|
const checkForEitherStrOrReMatch = either(
|
|
191
267
|
propEq(mainStr, 'str'), compose(test(__, mainStr), prop('re'))
|
|
192
|
-
)
|
|
268
|
+
)
|
|
193
269
|
|
|
194
|
-
const findMatchIndex = compose(findLastIndex(equals(true)), map(checkForEitherStrOrReMatch), map(createStrRegexTest), map(checkForEmpty))
|
|
270
|
+
const findMatchIndex = compose(findLastIndex(equals(true)), map(checkForEitherStrOrReMatch), map(createStrRegexTest), map(checkForEmpty))
|
|
195
271
|
|
|
196
|
-
return findMatchIndex(paramsArr)
|
|
272
|
+
return findMatchIndex(paramsArr)
|
|
197
273
|
}
|
|
198
274
|
|
|
199
275
|
static checkIfValueShouldMapToParam(obj, str, regexTokens) {
|
|
@@ -211,126 +287,126 @@ export class SpyneUtilsChannelRouteUrl {
|
|
|
211
287
|
|
|
212
288
|
// GO THROUGH ROUTE CONFIG TO FIGURE OUT IF VAL OR KEY SHOULD BE COMPARED
|
|
213
289
|
// if the value is an object, choose the key of the route path to check against
|
|
214
|
-
const getValCompareArr = compose(map(last), map(filter(is(String))), toPairs)
|
|
290
|
+
const getValCompareArr = compose(map(last), map(filter(is(String))), toPairs)
|
|
215
291
|
|
|
216
292
|
// CREATE THE ARRAY OF EITHER VALS OR KEYS
|
|
217
|
-
|
|
293
|
+
const paramsArr = getValCompareArr(obj)
|
|
218
294
|
|
|
219
295
|
// RESULTS FROM PARAM CHECK
|
|
220
296
|
// let paramIndex = checkForParamsMatch(paramsArr);
|
|
221
297
|
|
|
222
|
-
|
|
298
|
+
const paramIndex = SpyneUtilsChannelRouteUrl.findIndexOfMatchedStringOrRegex(str, paramsArr)
|
|
223
299
|
|
|
224
300
|
// DEFAULT VAL FOR STRING
|
|
225
|
-
let paramStr = str
|
|
301
|
+
let paramStr = str
|
|
226
302
|
|
|
227
303
|
// LEGACY METHOD -- TURN OFF
|
|
228
304
|
// WHEN THERE IS A MATCH FROM THE CURRENT ROUTE PATH OBJECT
|
|
229
305
|
if (paramIndex >= 0) {
|
|
230
|
-
|
|
231
|
-
|
|
306
|
+
const param = paramsArr[paramIndex]
|
|
307
|
+
const invertedObj = invert(obj)
|
|
232
308
|
|
|
233
309
|
// PULL INVERTED OBJECT TO SEE IF STR MATCHES
|
|
234
|
-
|
|
235
|
-
|
|
310
|
+
const getParamInverted = compose(head, defaultTo([]), prop(param))
|
|
311
|
+
const paramInverted = getParamInverted(invertedObj)
|
|
236
312
|
// spyne 11.0.1;
|
|
237
|
-
|
|
238
|
-
|
|
313
|
+
const re = /^([-$\w]*)$/
|
|
314
|
+
const keyMatch = re.test(paramInverted)
|
|
239
315
|
|
|
240
316
|
if (keyMatch === true && is(String, paramInverted) === true) {
|
|
241
|
-
paramStr = paramInverted
|
|
317
|
+
paramStr = paramInverted
|
|
242
318
|
}
|
|
243
319
|
}
|
|
244
320
|
|
|
245
|
-
return paramStr
|
|
321
|
+
return paramStr
|
|
246
322
|
}
|
|
247
323
|
|
|
248
324
|
static createArrFromSlashStr(str) {
|
|
249
|
-
const slashRe = /^([/])?(.*)
|
|
250
|
-
return str.replace(slashRe, '$2').split('/')
|
|
325
|
+
const slashRe = /^([/])?(.*)$/
|
|
326
|
+
return str.replace(slashRe, '$2').split('/')
|
|
251
327
|
}
|
|
252
328
|
|
|
253
329
|
static convertSlashRouteStrToParamsObj(topLevelRoute, str, regexTokens) {
|
|
254
|
-
const routeValue = str
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
let latestObj = topLevelRoute
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
latestObj = this.checkIfParamValueMatchesRegex(currentValue, latestObj)
|
|
263
|
-
const prevPathNotEqCurrentPath = (str)=>str!==last(paths)
|
|
264
|
-
|
|
265
|
-
const isEmptyOrNil = either(isEmpty,isNil)
|
|
266
|
-
|
|
267
|
-
if (latestObj !== undefined && prevPathNotEqCurrentPath(latestObj.routeName) && isEmptyOrNil(routeValueStr)===false) {
|
|
268
|
-
paths.push(latestObj.routeName)
|
|
269
|
-
routedValuesArr.push(routeValueStr)
|
|
330
|
+
const routeValue = str
|
|
331
|
+
const valuesArr = this.createArrFromSlashStr(str)
|
|
332
|
+
const paths = []
|
|
333
|
+
const routedValuesArr = []
|
|
334
|
+
let latestObj = topLevelRoute
|
|
335
|
+
const createParamsFromStr = (total, currentValue) => {
|
|
336
|
+
const routeValueStr = this.checkIfValueShouldMapToParam(latestObj, currentValue, regexTokens)
|
|
337
|
+
|
|
338
|
+
latestObj = this.checkIfParamValueMatchesRegex(currentValue, latestObj)
|
|
339
|
+
const prevPathNotEqCurrentPath = (str) => str !== last(paths)
|
|
340
|
+
|
|
341
|
+
const isEmptyOrNil = either(isEmpty, isNil)
|
|
342
|
+
|
|
343
|
+
if (latestObj !== undefined && prevPathNotEqCurrentPath(latestObj.routeName) && isEmptyOrNil(routeValueStr) === false) {
|
|
344
|
+
paths.push(latestObj.routeName)
|
|
345
|
+
routedValuesArr.push(routeValueStr)
|
|
270
346
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
347
|
+
const strPath = [currentValue, 'routePath']
|
|
348
|
+
const routeParamPath = ['routePath']
|
|
349
|
+
const objectFromStr = path(strPath, latestObj)
|
|
350
|
+
const objectFromRouteParam = path(routeParamPath, latestObj)
|
|
275
351
|
|
|
276
352
|
if (objectFromStr !== undefined) {
|
|
277
|
-
latestObj = objectFromStr
|
|
353
|
+
latestObj = objectFromStr
|
|
278
354
|
} else if (objectFromRouteParam !== undefined) {
|
|
279
|
-
latestObj = objectFromRouteParam
|
|
355
|
+
latestObj = objectFromRouteParam
|
|
280
356
|
}
|
|
281
|
-
}
|
|
357
|
+
}
|
|
282
358
|
|
|
283
|
-
reduce(createParamsFromStr, 0, valuesArr)
|
|
284
|
-
|
|
285
|
-
const pathInnermost = this.getLastArrVal(paths)
|
|
286
|
-
return { paths, pathInnermost, routeData, routeValue }
|
|
359
|
+
reduce(createParamsFromStr, 0, valuesArr)
|
|
360
|
+
const routeData = zipObj(paths, routedValuesArr)
|
|
361
|
+
const pathInnermost = this.getLastArrVal(paths)
|
|
362
|
+
return { paths, pathInnermost, routeData, routeValue }
|
|
287
363
|
}
|
|
288
364
|
|
|
289
365
|
static getLastArrVal(arr) {
|
|
290
|
-
const getLastParam = (a) => last(a) !== undefined ? last(a) : ''
|
|
291
|
-
return getLastParam(arr)
|
|
366
|
+
const getLastParam = (a) => last(a) !== undefined ? last(a) : ''
|
|
367
|
+
return getLastParam(arr)
|
|
292
368
|
}
|
|
293
369
|
|
|
294
370
|
static createDefaultParamFromEmptyStr(topLevelRoute, str) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
obj[keyword] = this.checkIfValueShouldMapToParam(topLevelRoute, str)
|
|
298
|
-
return obj
|
|
371
|
+
const obj = {}
|
|
372
|
+
const keyword = topLevelRoute.routeName
|
|
373
|
+
obj[keyword] = this.checkIfValueShouldMapToParam(topLevelRoute, str)
|
|
374
|
+
return obj
|
|
299
375
|
}
|
|
300
376
|
|
|
301
377
|
static convertQueryStrToParams(topLevelRoute, str, regexTokens) {
|
|
302
|
-
const queryRe = /^([?])?(.*)
|
|
303
|
-
const routeValue = str
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
let routeData = fromPairs(paramsArr)
|
|
378
|
+
const queryRe = /^([?])?(.*)$/
|
|
379
|
+
const routeValue = str
|
|
380
|
+
const strArr = str.replace(queryRe, '$2')
|
|
381
|
+
const convertToParams = compose(map(split('=')), split('&'))
|
|
382
|
+
const paramsArr = convertToParams(strArr)
|
|
383
|
+
let routeData = fromPairs(paramsArr)
|
|
308
384
|
|
|
309
|
-
let paths = map(head, paramsArr)
|
|
385
|
+
let paths = map(head, paramsArr)
|
|
310
386
|
|
|
311
387
|
if (isEmpty(str) === true) {
|
|
312
|
-
routeData = this.createDefaultParamFromEmptyStr(topLevelRoute, str, regexTokens)
|
|
313
|
-
paths = keys(routeData)
|
|
388
|
+
routeData = this.createDefaultParamFromEmptyStr(topLevelRoute, str, regexTokens)
|
|
389
|
+
paths = keys(routeData)
|
|
314
390
|
}
|
|
315
|
-
|
|
391
|
+
const pathInnermost = this.getLastArrVal(paths)
|
|
316
392
|
|
|
317
|
-
return { paths, pathInnermost, routeData, routeValue }
|
|
393
|
+
return { paths, pathInnermost, routeData, routeValue }
|
|
318
394
|
}
|
|
319
395
|
|
|
320
396
|
static convertRouteToParams(str, routeConfig, t) {
|
|
321
|
-
const addSlash = (url)=>url.replace(/\/$|$/, '/')
|
|
397
|
+
const addSlash = (url) => url.replace(/\/$|$/, '/')
|
|
322
398
|
if (routeConfig === undefined) {
|
|
323
|
-
return {}
|
|
399
|
+
return {}
|
|
324
400
|
}
|
|
325
|
-
const type = t !== undefined ? t : routeConfig.type
|
|
326
|
-
const regexTokens = defaultTo({}, prop('regexTokens', routeConfig))
|
|
327
|
-
|
|
401
|
+
const type = t !== undefined ? t : routeConfig.type
|
|
402
|
+
const regexTokens = defaultTo({}, prop('regexTokens', routeConfig))
|
|
403
|
+
const topLevelRoute = routeConfig.routes.routePath
|
|
328
404
|
|
|
329
405
|
if (type === 'query') {
|
|
330
|
-
return this.convertQueryStrToParams(topLevelRoute, str)
|
|
406
|
+
return this.convertQueryStrToParams(topLevelRoute, str)
|
|
331
407
|
}
|
|
332
|
-
str = addSlash(str)
|
|
408
|
+
str = addSlash(str)
|
|
333
409
|
|
|
334
|
-
return this.convertSlashRouteStrToParamsObj(topLevelRoute, str, regexTokens)
|
|
410
|
+
return this.convertSlashRouteStrToParamsObj(topLevelRoute, str, regexTokens)
|
|
335
411
|
}
|
|
336
412
|
}
|