+4
-0
| # Changelog | ||
| ## 0.3.9 (2023-01-17) | ||
| - added: Accept a `hideProperties` configuration option to make certain properties non-enumerable. | ||
| ## 0.3.8 (2022-07-07) | ||
@@ -4,0 +8,0 @@ |
+13
-5
@@ -732,3 +732,3 @@ 'use strict'; | ||
| props[n] = { | ||
| enumerable: true, | ||
| enumerable: state.hideProperties.indexOf(n) < 0, | ||
| get: makeProxyGetter(magic, n) | ||
@@ -789,2 +789,3 @@ }; | ||
| var BridgeState = /*#__PURE__*/function () { | ||
| // Options: | ||
| // Objects: | ||
@@ -795,6 +796,12 @@ // Outgoing method calls: | ||
| function BridgeState(opts) { | ||
| var sendMessage = opts.sendMessage, | ||
| var _opts$hideProperties = opts.hideProperties, | ||
| hideProperties = _opts$hideProperties === void 0 ? [] : _opts$hideProperties, | ||
| sendMessage = opts.sendMessage, | ||
| _opts$throttleMs = opts.throttleMs, | ||
| throttleMs = _opts$throttleMs === void 0 ? 0 : _opts$throttleMs; // Objects: | ||
| throttleMs = _opts$throttleMs === void 0 ? 0 : _opts$throttleMs; // Options: | ||
| this.hideProperties = hideProperties; | ||
| this.sendMessage = sendMessage; | ||
| this.throttleMs = throttleMs; // Objects: | ||
| this.proxies = {}; | ||
@@ -810,6 +817,4 @@ this.objects = {}; | ||
| this.throttleMs = throttleMs; | ||
| this.lastUpdate = 0; | ||
| this.sendPending = false; | ||
| this.sendMessage = sendMessage; | ||
| } | ||
@@ -1225,2 +1230,3 @@ /** | ||
| cloneMessage = _opts$cloneMessage === void 0 ? nopClone : _opts$cloneMessage, | ||
| hideProperties = _opts.hideProperties, | ||
| throttleMs = _opts.throttleMs; | ||
@@ -1231,2 +1237,3 @@ var serverState = new BridgeState({ | ||
| }, | ||
| hideProperties: hideProperties, | ||
| throttleMs: throttleMs | ||
@@ -1238,2 +1245,3 @@ }); | ||
| }, | ||
| hideProperties: hideProperties, | ||
| throttleMs: throttleMs | ||
@@ -1240,0 +1248,0 @@ }); |
+13
-5
@@ -728,3 +728,3 @@ import { base64 } from 'rfc4648'; | ||
| props[n] = { | ||
| enumerable: true, | ||
| enumerable: state.hideProperties.indexOf(n) < 0, | ||
| get: makeProxyGetter(magic, n) | ||
@@ -785,2 +785,3 @@ }; | ||
| var BridgeState = /*#__PURE__*/function () { | ||
| // Options: | ||
| // Objects: | ||
@@ -791,6 +792,12 @@ // Outgoing method calls: | ||
| function BridgeState(opts) { | ||
| var sendMessage = opts.sendMessage, | ||
| var _opts$hideProperties = opts.hideProperties, | ||
| hideProperties = _opts$hideProperties === void 0 ? [] : _opts$hideProperties, | ||
| sendMessage = opts.sendMessage, | ||
| _opts$throttleMs = opts.throttleMs, | ||
| throttleMs = _opts$throttleMs === void 0 ? 0 : _opts$throttleMs; // Objects: | ||
| throttleMs = _opts$throttleMs === void 0 ? 0 : _opts$throttleMs; // Options: | ||
| this.hideProperties = hideProperties; | ||
| this.sendMessage = sendMessage; | ||
| this.throttleMs = throttleMs; // Objects: | ||
| this.proxies = {}; | ||
@@ -806,6 +813,4 @@ this.objects = {}; | ||
| this.throttleMs = throttleMs; | ||
| this.lastUpdate = 0; | ||
| this.sendPending = false; | ||
| this.sendMessage = sendMessage; | ||
| } | ||
@@ -1221,2 +1226,3 @@ /** | ||
| cloneMessage = _opts$cloneMessage === void 0 ? nopClone : _opts$cloneMessage, | ||
| hideProperties = _opts.hideProperties, | ||
| throttleMs = _opts.throttleMs; | ||
@@ -1227,2 +1233,3 @@ var serverState = new BridgeState({ | ||
| }, | ||
| hideProperties: hideProperties, | ||
| throttleMs: throttleMs | ||
@@ -1234,2 +1241,3 @@ }); | ||
| }, | ||
| hideProperties: hideProperties, | ||
| throttleMs: throttleMs | ||
@@ -1236,0 +1244,0 @@ }); |
+1
-1
| { | ||
| "name": "yaob", | ||
| "version": "0.3.8", | ||
| "version": "0.3.9", | ||
| "description": "Bridges an object-oriented API across a messaging layer", | ||
@@ -5,0 +5,0 @@ "repository": { |
+20
-0
@@ -292,2 +292,22 @@ # yaob | ||
| ### Hiding Properties | ||
| By default, yaob uses the JavaScript `enumerable` flag to hide bridged methods. This way, if you pass a bridged object to `console.log` or `JSON.stringify`, you will just see the values, not the methods. | ||
| If you want to hide additional properties, you can pass their names in a `hideProperites` bridge option. Yaob will hide any bridgeable object properties with names that match the list. | ||
| In this example, yaob automatically hides `someMethod`, since it's a method, and also hides the `hideMe` property because it's name is on the list: | ||
| ```js | ||
| const example = bridgifyObject({ | ||
| visible: 1, | ||
| hideMe: 2, | ||
| someMethod () {} | ||
| }) | ||
| const local = makeLocalBridge(example, { hideProperties: ["hideMe"] }) | ||
| JSON.stringify(local) // Returns {"visible":1} | ||
| ``` | ||
| ### Flow Types | ||
@@ -294,0 +314,0 @@ |
+5
-1
@@ -18,2 +18,3 @@ // @flow | ||
| sendMessage: SendMessage, | ||
| hideProperties?: string[], | ||
| throttleMs?: number | ||
@@ -27,2 +28,3 @@ } | ||
| cloneMessage?: (x: Object) => Object, | ||
| hideProperties?: string[], | ||
| throttleMs?: number | ||
@@ -71,3 +73,3 @@ } | ||
| } | ||
| const { cloneMessage = nopClone, throttleMs } = opts | ||
| const { cloneMessage = nopClone, hideProperties, throttleMs } = opts | ||
@@ -78,2 +80,3 @@ const serverState = new BridgeState({ | ||
| }, | ||
| hideProperties, | ||
| throttleMs | ||
@@ -85,2 +88,3 @@ }) | ||
| }, | ||
| hideProperties, | ||
| throttleMs | ||
@@ -87,0 +91,0 @@ }) |
+4
-1
@@ -116,3 +116,6 @@ // @flow | ||
| for (const n in create.props) { | ||
| props[n] = { enumerable: true, get: makeProxyGetter(magic, n) } | ||
| props[n] = { | ||
| enumerable: state.hideProperties.indexOf(n) < 0, | ||
| get: makeProxyGetter(magic, n) | ||
| } | ||
| } | ||
@@ -119,0 +122,0 @@ |
+11
-5
@@ -26,2 +26,7 @@ /* global setTimeout */ | ||
| export class BridgeState implements ObjectTable { | ||
| // Options: | ||
| +hideProperties: string[] | ||
| +sendMessage: SendMessage | ||
| +throttleMs: number | ||
| // Objects: | ||
@@ -44,10 +49,13 @@ +proxies: { [objectId: number]: Object } | ||
| closed: boolean | ||
| +throttleMs: number | ||
| lastUpdate: number | ||
| sendPending: boolean | ||
| +sendMessage: SendMessage | ||
| constructor(opts: BridgeOptions) { | ||
| const { sendMessage, throttleMs = 0 } = opts | ||
| const { hideProperties = [], sendMessage, throttleMs = 0 } = opts | ||
| // Options: | ||
| this.hideProperties = hideProperties | ||
| this.sendMessage = sendMessage | ||
| this.throttleMs = throttleMs | ||
| // Objects: | ||
@@ -67,6 +75,4 @@ this.proxies = {} | ||
| // Update scheduling: | ||
| this.throttleMs = throttleMs | ||
| this.lastUpdate = 0 | ||
| this.sendPending = false | ||
| this.sendMessage = sendMessage | ||
| } | ||
@@ -73,0 +79,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
256337
1.2%3431
0.73%319
6.69%