gingersnap 0.23.8 → 0.23.9

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/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"gingersnap","version":"0.23.8","description":"A general purpose library built with the aim of filling the gaps of javascript shortcomings","dependencies":{"@msgpack/msgpack":"^3.0.0-beta2","browser-or-node":"^3.0.0-pre.0","modern-isomorphic-ws":"^1.0.5","object-hash":"^3.0.0","papaparse":"^5.4.1","protobufjs":"^7.2.6","ramda":"^0.30.1","reflect-metadata":"^0.2.2","tslib":"^2.6.3","uuid":"^9.0.1","ws":"^8.16.0","x2js":"^3.4.4"},"author":"CookieNerds LLC","exports":{"./synchronize":{"import":{"types":"./synchronize.d.ts","default":"./synchronize.mjs"},"require":{"types":"./synchronize.d.ts","default":"./synchronize.cjs"}},"./mocks":{"import":{"types":"./mocks.d.ts","default":"./mocks.mjs"},"require":{"types":"./mocks.d.ts","default":"./mocks.cjs"}},"./socket":{"import":{"types":"./socket.d.ts","default":"./socket.mjs"},"require":{"types":"./socket.d.ts","default":"./socket.cjs"}},"./typing":{"import":{"types":"./typing.d.ts","default":"./typing.mjs"},"require":{"types":"./typing.d.ts","default":"./typing.cjs"}},"./stream":{"import":{"types":"./stream/index.d.ts","default":"./stream.mjs"},"require":{"types":"./stream/index.d.ts","default":"./stream.cjs"}},"./reflection/injector":{"import":{"types":"./reflection/injector.d.ts","default":"./reflection/injector.mjs"},"require":{"types":"./reflection/injector.d.ts","default":"./reflection/injector.cjs"}},"./stream/call":{"import":{"types":"./stream/call.d.ts","default":"./stream/call.mjs"},"require":{"types":"./stream/call.d.ts","default":"./stream/call.cjs"}},"./stream/state":{"import":{"types":"./stream/state.d.ts","default":"./stream/state.mjs"},"require":{"types":"./stream/state.d.ts","default":"./stream/state.cjs"}},"./stream/collector":{"import":{"types":"./stream/collector.d.ts","default":"./stream/collector.mjs"},"require":{"types":"./stream/collector.d.ts","default":"./stream/collector.cjs"}},"./stream/observable":{"import":{"types":"./stream/observable.d.ts","default":"./stream/observable.mjs"},"require":{"types":"./stream/observable.d.ts","default":"./stream/observable.cjs"}},"./networking":{"import":{"types":"./networking/index.d.ts","default":"./networking.mjs"},"require":{"types":"./networking/index.d.ts","default":"./networking.cjs"}},"./managers":{"import":{"types":"./managers/index.d.ts","default":"./managers.mjs"},"require":{"types":"./managers/index.d.ts","default":"./managers.cjs"}},"./future":{"import":{"types":"./future/index.d.ts","default":"./future.mjs"},"require":{"types":"./future/index.d.ts","default":"./future.cjs"}},"./errors":{"import":{"types":"./errors/index.d.ts","default":"./errors.mjs"},"require":{"types":"./errors/index.d.ts","default":"./errors.cjs"}},"./data-structures/array":{"import":{"types":"./data-structures/array/index.d.ts","default":"./data-structures/array.mjs"},"require":{"types":"./data-structures/array/index.d.ts","default":"./data-structures/array.cjs"}},"./data-structures/object":{"import":{"types":"./data-structures/object/index.d.ts","default":"./data-structures/object.mjs"},"require":{"types":"./data-structures/object/index.d.ts","default":"./data-structures/object.cjs"}},"./data/decoders":{"import":{"types":"./data/decoders/index.d.ts","default":"./data/decoders.mjs"},"require":{"types":"./data/decoders/index.d.ts","default":"./data/decoders.cjs"}},"./data/model":{"import":{"types":"./data/model/index.d.ts","default":"./data/model.mjs"},"require":{"types":"./data/model/index.d.ts","default":"./data/model.cjs"}},"./data/bus":{"import":{"types":"./data/bus.d.ts","default":"./data/bus.mjs"},"require":{"types":"./data/bus.d.ts","default":"./data/bus.cjs"}},"./data/AtomicValue":{"import":{"types":"./data/AtomicValue.d.ts","default":"./data/AtomicValue.mjs"},"require":{"types":"./data/AtomicValue.d.ts","default":"./data/AtomicValue.cjs"}},"./data/store":{"import":{"types":"./data/store/index.d.ts","default":"./data/store.mjs"},"require":{"types":"./data/store/index.d.ts","default":"./data/store.cjs"}},"./functools":{"import":{"types":"./functools/index.d.ts","default":"./functools.mjs"},"require":{"types":"./functools/index.d.ts","default":"./functools.cjs"}}}}
1
+ {"name":"gingersnap","version":"0.23.9","description":"A general purpose library built with the aim of filling the gaps of javascript shortcomings","dependencies":{"@msgpack/msgpack":"^3.0.0-beta2","browser-or-node":"^3.0.0-pre.0","modern-isomorphic-ws":"^1.0.5","object-hash":"^3.0.0","papaparse":"^5.4.1","protobufjs":"^7.2.6","ramda":"^0.30.1","reflect-metadata":"^0.2.2","tslib":"^2.6.3","uuid":"^9.0.1","ws":"^8.16.0","x2js":"^3.4.4"},"author":"CookieNerds LLC","exports":{"./synchronize":{"import":{"types":"./synchronize.d.ts","default":"./synchronize.mjs"},"require":{"types":"./synchronize.d.ts","default":"./synchronize.cjs"}},"./mocks":{"import":{"types":"./mocks.d.ts","default":"./mocks.mjs"},"require":{"types":"./mocks.d.ts","default":"./mocks.cjs"}},"./socket":{"import":{"types":"./socket.d.ts","default":"./socket.mjs"},"require":{"types":"./socket.d.ts","default":"./socket.cjs"}},"./typing":{"import":{"types":"./typing.d.ts","default":"./typing.mjs"},"require":{"types":"./typing.d.ts","default":"./typing.cjs"}},"./stream":{"import":{"types":"./stream/index.d.ts","default":"./stream.mjs"},"require":{"types":"./stream/index.d.ts","default":"./stream.cjs"}},"./reflection/injector":{"import":{"types":"./reflection/injector.d.ts","default":"./reflection/injector.mjs"},"require":{"types":"./reflection/injector.d.ts","default":"./reflection/injector.cjs"}},"./stream/call":{"import":{"types":"./stream/call.d.ts","default":"./stream/call.mjs"},"require":{"types":"./stream/call.d.ts","default":"./stream/call.cjs"}},"./stream/state":{"import":{"types":"./stream/state.d.ts","default":"./stream/state.mjs"},"require":{"types":"./stream/state.d.ts","default":"./stream/state.cjs"}},"./stream/collector":{"import":{"types":"./stream/collector.d.ts","default":"./stream/collector.mjs"},"require":{"types":"./stream/collector.d.ts","default":"./stream/collector.cjs"}},"./stream/observable":{"import":{"types":"./stream/observable.d.ts","default":"./stream/observable.mjs"},"require":{"types":"./stream/observable.d.ts","default":"./stream/observable.cjs"}},"./networking":{"import":{"types":"./networking/index.d.ts","default":"./networking.mjs"},"require":{"types":"./networking/index.d.ts","default":"./networking.cjs"}},"./managers":{"import":{"types":"./managers/index.d.ts","default":"./managers.mjs"},"require":{"types":"./managers/index.d.ts","default":"./managers.cjs"}},"./future":{"import":{"types":"./future/index.d.ts","default":"./future.mjs"},"require":{"types":"./future/index.d.ts","default":"./future.cjs"}},"./errors":{"import":{"types":"./errors/index.d.ts","default":"./errors.mjs"},"require":{"types":"./errors/index.d.ts","default":"./errors.cjs"}},"./data-structures/array":{"import":{"types":"./data-structures/array/index.d.ts","default":"./data-structures/array.mjs"},"require":{"types":"./data-structures/array/index.d.ts","default":"./data-structures/array.cjs"}},"./data-structures/object":{"import":{"types":"./data-structures/object/index.d.ts","default":"./data-structures/object.mjs"},"require":{"types":"./data-structures/object/index.d.ts","default":"./data-structures/object.cjs"}},"./data/decoders":{"import":{"types":"./data/decoders/index.d.ts","default":"./data/decoders.mjs"},"require":{"types":"./data/decoders/index.d.ts","default":"./data/decoders.cjs"}},"./data/model":{"import":{"types":"./data/model/index.d.ts","default":"./data/model.mjs"},"require":{"types":"./data/model/index.d.ts","default":"./data/model.cjs"}},"./data/bus":{"import":{"types":"./data/bus.d.ts","default":"./data/bus.mjs"},"require":{"types":"./data/bus.d.ts","default":"./data/bus.cjs"}},"./data/AtomicValue":{"import":{"types":"./data/AtomicValue.d.ts","default":"./data/AtomicValue.mjs"},"require":{"types":"./data/AtomicValue.d.ts","default":"./data/AtomicValue.cjs"}},"./data/store":{"import":{"types":"./data/store/index.d.ts","default":"./data/store.mjs"},"require":{"types":"./data/store/index.d.ts","default":"./data/store.cjs"}},"./functools":{"import":{"types":"./functools/index.d.ts","default":"./functools.mjs"},"require":{"types":"./functools/index.d.ts","default":"./functools.cjs"}}}}
package/stream/index.d.ts CHANGED
@@ -227,6 +227,15 @@ export declare class Stream<T> implements AsyncGenerator<T> {
227
227
  * @param period
228
228
  */
229
229
  rateLimit(count: number, period: WaitPeriod): this;
230
+ /**
231
+ * Applies rate limiting by dropping data that is flowing through the stream that exceeds the count per period limit.
232
+ * This count and period limit can be changed, via the input stream provided.
233
+ * @param stream
234
+ */
235
+ liveRateLimit(stream: Stream<{
236
+ count: number;
237
+ period: WaitPeriod;
238
+ }>): this;
230
239
  /**
231
240
  * Flattens any nested structure from the data arriving on the stream
232
241
  */
package/stream.cjs CHANGED
@@ -759,6 +759,47 @@ class Stream {
759
759
  });
760
760
  return this;
761
761
  }
762
+ /**
763
+ * Applies rate limiting by dropping data that is flowing through the stream that exceeds the count per period limit.
764
+ * This count and period limit can be changed, via the input stream provided.
765
+ * @param stream
766
+ */
767
+ liveRateLimit(stream) {
768
+ if (!this.canAlterStream)
769
+ throw new IllegalOperationError.IllegalOperationError("Cannot alter the stream as it is frozen");
770
+ let i = 0;
771
+ let start;
772
+ let count = 0;
773
+ let periodValue = 0;
774
+ const readyEvt = new synchronize.FutureEvent();
775
+ const notifyReady = R__namespace.once(() => readyEvt.set());
776
+ const startInputStream = R__namespace.once(() => stream.forEach((v) => {
777
+ count = v.count;
778
+ periodValue = future.calculatePeriodValue(v.period);
779
+ notifyReady();
780
+ }));
781
+ this.actions.push({
782
+ type: ActionType.TRANSFORM,
783
+ functor: (value) => _tslib.__awaiter(this, void 0, void 0, function* () {
784
+ if (!start) {
785
+ start = new Date().getTime();
786
+ }
787
+ const diff = new Date().getTime() - start;
788
+ i++;
789
+ startInputStream();
790
+ yield readyEvt.wait();
791
+ if (i >= count && diff <= periodValue) {
792
+ return null;
793
+ }
794
+ else if (diff > periodValue) {
795
+ start = new Date().getTime();
796
+ i = 1;
797
+ }
798
+ return value;
799
+ }),
800
+ });
801
+ return this;
802
+ }
762
803
  /**
763
804
  * Flattens any nested structure from the data arriving on the stream
764
805
  */
package/stream.mjs CHANGED
@@ -6,7 +6,7 @@ import { StreamEnded } from './errors/StreamEnded.mjs';
6
6
  import * as R from 'ramda';
7
7
  import { Future, calculatePeriodValue } from './future/future.mjs';
8
8
  import { FutureResult } from './future/result.mjs';
9
- import { Lock } from './synchronize.mjs';
9
+ import { Lock, FutureEvent } from './synchronize.mjs';
10
10
  import { ExecutorState } from './stream/state.mjs';
11
11
  import { TimeableObject } from './data-structures/object/TimeableObject.mjs';
12
12
  import { IllegalOperationError } from './errors/IllegalOperationError.mjs';
@@ -738,6 +738,47 @@ class Stream {
738
738
  });
739
739
  return this;
740
740
  }
741
+ /**
742
+ * Applies rate limiting by dropping data that is flowing through the stream that exceeds the count per period limit.
743
+ * This count and period limit can be changed, via the input stream provided.
744
+ * @param stream
745
+ */
746
+ liveRateLimit(stream) {
747
+ if (!this.canAlterStream)
748
+ throw new IllegalOperationError("Cannot alter the stream as it is frozen");
749
+ let i = 0;
750
+ let start;
751
+ let count = 0;
752
+ let periodValue = 0;
753
+ const readyEvt = new FutureEvent();
754
+ const notifyReady = R.once(() => readyEvt.set());
755
+ const startInputStream = R.once(() => stream.forEach((v) => {
756
+ count = v.count;
757
+ periodValue = calculatePeriodValue(v.period);
758
+ notifyReady();
759
+ }));
760
+ this.actions.push({
761
+ type: ActionType.TRANSFORM,
762
+ functor: (value) => __awaiter(this, void 0, void 0, function* () {
763
+ if (!start) {
764
+ start = new Date().getTime();
765
+ }
766
+ const diff = new Date().getTime() - start;
767
+ i++;
768
+ startInputStream();
769
+ yield readyEvt.wait();
770
+ if (i >= count && diff <= periodValue) {
771
+ return null;
772
+ }
773
+ else if (diff > periodValue) {
774
+ start = new Date().getTime();
775
+ i = 1;
776
+ }
777
+ return value;
778
+ }),
779
+ });
780
+ return this;
781
+ }
741
782
  /**
742
783
  * Flattens any nested structure from the data arriving on the stream
743
784
  */