spyne 0.20.4 → 0.20.5

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.
@@ -1,16 +1,21 @@
1
1
  /*!
2
- * Spyne 0.20.4
2
+ * Spyne 0.20.5
3
3
  * https://spynejs.org
4
4
  *
5
- * @license Copyright 2017-2021, Frank Batista, Relevant Context, LLC. All rights reserved.
6
- * Spyne is licensed under the GNU Lesser General Public License v3.0
5
+ * @license
6
+ * Copyright 2017-2025, Frank Batista,
7
+ * Relevant Context, LLC. All rights reserved.
7
8
  *
8
- * @author: Frank Batista,
9
- * @email: frbatista.nyc@gmail.com
10
- */
9
+ * Licensed under the GNU Lesser General Public License v3.0 (the "License");
10
+ * You may not use this file except in compliance with the License.
11
+ * A copy of the License is located in the project root, or at:
12
+ * https://www.gnu.org/licenses/lgpl-3.0.html
13
+ *
14
+ * This notice may not be removed or altered from any distribution.
15
+ */
11
16
 
12
17
  /*!
13
- * spynejs 0.20.4
18
+ * spynejs 0.20.5
14
19
  * https://spynejs.org
15
20
  * (c) 2017-present Frank Batista
16
21
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spyne",
3
- "version": "0.20.4",
3
+ "version": "0.20.5",
4
4
  "description": "Reactive Real-DOM Framework for Advanced Javascript applications",
5
5
  "sideEffects": true,
6
6
  "main": "./lib/spyne.esm.js",
@@ -2,8 +2,8 @@ import { registeredStreamNames } from './channels-config'
2
2
  import { ChannelPayload } from './channel-payload-class'
3
3
  import { SpyneAppProperties } from '../utils/spyne-app-properties'
4
4
  import { RouteChannelUpdater } from '../utils/route-channel-updater'
5
- import { ReplaySubject, Subject } from 'rxjs'
6
- import { filter, map } from 'rxjs/operators'
5
+ import { ReplaySubject, Subject, forkJoin, combineLatest } from 'rxjs'
6
+ import { filter, map, take } from 'rxjs/operators'
7
7
  import {
8
8
  ifElse,
9
9
  identity,
@@ -398,6 +398,46 @@ export class Channel {
398
398
  return fn(channelName)
399
399
  }
400
400
 
401
+ /**
402
+ * Merge Channels is a convenience method to forkJoin Channel.observer$
403
+ *
404
+ * */
405
+
406
+ mergeChannels(channelsOrNames, persistent = false) {
407
+ // 1) Convert strings to Observables
408
+ const channelObservables = channelsOrNames.map(item => {
409
+ if (typeof item === 'string') {
410
+ const chan$ = this.getChannel(item)
411
+ return persistent ? chan$ : chan$.pipe(take(1))
412
+ } else {
413
+ // Already an Observable
414
+ return persistent ? item : item.pipe(take(1))
415
+ }
416
+ })
417
+
418
+ // 2) Decide which RxJS operator
419
+ const combiningOperator = persistent
420
+ ? combineLatest
421
+ : forkJoin
422
+
423
+ // 3) Combine them into an array emission
424
+ const combined$ = combiningOperator(channelObservables)
425
+
426
+ // 4) Map the array [result1, result2, ...] => { CHANNEL_1: result1, CHANNEL_2: result2, ... }
427
+ return combined$.pipe(
428
+ map((arr) => {
429
+ // Build an object keyed by the channel name (or index if you prefer).
430
+ const resultObj = {}
431
+ channelsOrNames.forEach((item, idx) => {
432
+ // item might be a string or Observable
433
+ const channelName = (typeof item === 'string') ? item : `channel_${idx}`
434
+ resultObj[channelName] = arr[idx]
435
+ })
436
+ return resultObj
437
+ })
438
+ )
439
+ }
440
+
401
441
  static checkForNotTrackFlag(props = {}) {
402
442
  if (props.doNotTrack === true) {
403
443
  SpyneAppProperties.doNotTrackChannel(props.channelName)
@@ -5,7 +5,7 @@ import { SpyneAppProperties } from './utils/spyne-app-properties'
5
5
  import { sanitizeHTMLConfigure } from './utils/sanitize-html'
6
6
 
7
7
  const _channels = new ChannelsMap()
8
- const version = '0.20.4'
8
+ const version = '0.20.5'
9
9
 
10
10
  class SpyneApplication {
11
11
  /**
@@ -42,15 +42,20 @@ class SpyneApplication {
42
42
  init(config = {}, testMode = false) {
43
43
  // this.channels = new ChannelsMap();
44
44
  /*!
45
- * Spyne 0.20.4
45
+ * Spyne 0.20.5
46
46
  * https://spynejs.org
47
47
  *
48
- * @license Copyright 2017-2021, Frank Batista, Relevant Context, LLC. All rights reserved.
49
- * Spyne is licensed under the GNU Lesser General Public License v3.0
48
+ * @license
49
+ * Copyright 2017-2025, Frank Batista,
50
+ * Relevant Context, LLC. All rights reserved.
50
51
  *
51
- * @author: Frank Batista,
52
- * @email: frbatista.nyc@gmail.com
53
- */
52
+ * Licensed under the GNU Lesser General Public License v3.0 (the "License");
53
+ * You may not use this file except in compliance with the License.
54
+ * A copy of the License is located in the project root, or at:
55
+ * https://www.gnu.org/licenses/lgpl-3.0.html
56
+ *
57
+ * This notice may not be removed or altered from any distribution.
58
+ */
54
59
  /* eslint-disable */
55
60
 
56
61
 
@@ -14,6 +14,7 @@ import {
14
14
  where,
15
15
  defaultTo,
16
16
  mergeAll,
17
+ F,
17
18
  omit,
18
19
  flatten,
19
20
  any,
@@ -31,6 +32,11 @@ const isNonEmptyArr = allPass([is(Array), isNotEmpty])
31
32
  const isObjectFn = compose(allPass([isNotArr, is(Object)]))
32
33
  const isNonEmptyObjectFn = compose(allPass([isNotEmpty, isNotArr, is(Object)]))
33
34
 
35
+ const isString = (val) => is(String, val)
36
+ const isBoolean = (val) => is(Boolean, val)
37
+ const isNumber = (val) => is(Number, val)
38
+ const isArrayFn = (val) => is(Array, val)
39
+
34
40
  export class ChannelPayloadFilter {
35
41
  /**
36
42
  * @module ChannelPayloadFilter
@@ -160,7 +166,18 @@ export class ChannelPayloadFilter {
160
166
  return str === compareStr
161
167
  }
162
168
  const checkToConvertToFn = (val, key, obj) => {
163
- const fnVal = is(String, val) === true ? createCurryComparator(val) : val
169
+ let fnVal = F
170
+ if (isString(val) || isBoolean(val) || isNumber(val)) {
171
+ fnVal = createCurryComparator(val)
172
+ } else if (typeof val === 'function') {
173
+ return val
174
+ } else if (isArrayFn(val) || isObjectFn(val)) {
175
+ console.warn(
176
+ `ChannelPayloadFilter: Property "${val}" is an array/object, which is not allowed. ` +
177
+ 'This property will always return false.'
178
+ )
179
+ return fnVal
180
+ }
164
181
  return fnVal
165
182
  }
166
183
  filterJson = rMap(checkToConvertToFn, filterJson)
@@ -96,7 +96,18 @@ export class ViewStreamBroadcaster {
96
96
  data.srcElement.srcEvent = event
97
97
  data.srcElement.el = q
98
98
  // select the correct payload
99
- const channelPayload = channel !== undefined ? channelPayloads[channel] : channelPayloads.UI
99
+
100
+ function getValidChannel(ch) {
101
+ if (ch === 'ROUTE' || ch === 'CHANNEL_ROUTE') {
102
+ return 'ROUTE'
103
+ }
104
+ if (ch !== 'UI' && ch !== 'CHANNEL_UI' && ch !== undefined) {
105
+ console.warn(`SpyneJS warning: The channel, ${ch}, is not allowed here, only "UI" or "ROUTE" are valid channels, defaulting to CHANNEL_UI`)
106
+ }
107
+ return 'UI'
108
+ }
109
+
110
+ const channelPayload = channelPayloads[getValidChannel(channel)]
100
111
  // run payload
101
112
  channelPayload(observable, data)
102
113
  }