Socket
Socket
Sign inDemoInstall

@effection/subscription

Package Overview
Dependencies
Maintainers
1
Versions
151
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@effection/subscription - npm Package Compare versions

Comparing version 0.8.0 to 0.8.1-728efdb

dist/symbol-subscribable.d.ts

6

CHANGELOG.md
# @effection/subscription
## 0.8.1
### Patch Changes
- a7f9396: Retain resources created through `subscribe` properly
## 0.8.0

@@ -4,0 +10,0 @@

2

dist/chainable-subscription.d.ts
import { Operation } from 'effection';
import { Subscription } from './subscription';
import { DeepPartial } from './match';
import { SubscriptionSource } from './subscribable';
export declare class ChainableSubscription<T, TReturn> implements Subscription<T, TReturn> {
private subscription;
constructor(subscription: Subscription<T, TReturn>);
static of<T, TReturn>(source: SubscriptionSource<T, TReturn>): Operation<ChainableSubscription<T, TReturn>>;
filter(predicate: (value: T) => boolean): ChainableSubscription<T, TReturn>;

@@ -8,0 +10,0 @@ match(reference: DeepPartial<T>): ChainableSubscription<T, TReturn>;

3

dist/index.d.ts
export { Subscription, createSubscription } from './subscription';
export { SymbolSubscribable, SubscriptionSource, forEach, Subscribable } from './subscribable';
export { SymbolSubscribable } from './symbol-subscribable';
export { SubscriptionSource, forEach, Subscribable } from './subscribable';
export { ChainableSubscription } from './chainable-subscription';

@@ -4,0 +5,0 @@ import { Operation } from 'effection';

import { Operation } from 'effection';
import { Subscription, Subscriber } from './subscription';
import { DeepPartial } from './match';
export declare const SymbolSubscribable: unique symbol;
import { SymbolSubscribable } from './symbol-subscribable';
export interface Subscribable<T, TReturn> {

@@ -6,0 +6,0 @@ [SymbolSubscribable](): Operation<Subscription<T, TReturn>>;

@@ -23,2 +23,118 @@ 'use strict';

/**
* Hack Zone!
*
* tl;dr not only the symbol value, but also the symbol type must be
* global.
*
* In order to satisfy TypeScript that the SymbolSubscribable
* represents the same value across different versions of the same
* package, we need to declare a "fake" global variable that does not
* actually exist, but has a theoretical type. Since it is global,
* TypeScript will see it as the same type everywhere, and so we can
* use the `typeof` for the value, as the type of of our local symbol
* subscribable, and TypeScript will think that all of the types are
* the same.
*
* See https://github.com/microsoft/TypeScript/issues/8099#issuecomment-210134773
* for details.
*/
var SymbolSubscribable = /*#__PURE__*/Symbol["for"]('Symbol.subscription');
function* _forEach(source, visit) {
var subscription = yield subscribe(source);
while (true) {
var result = yield subscription.next();
if (result.done) {
return result.value;
} else {
yield visit(result.value);
}
}
}
var Subscribable = {
from: function from(source) {
return new Chain(source);
}
};
var Chain = /*#__PURE__*/function () {
function Chain(source) {
this.source = source;
}
var _proto = Chain.prototype;
_proto[SymbolSubscribable] = function () {
return subscribe(this.source);
};
_proto.map = function map(fn) {
return this.chain(function (source) {
return function (publish) {
return _forEach(source, function* (item) {
publish(fn(item));
});
};
});
};
_proto.filter = function filter(predicate) {
return this.chain(function (source) {
return function (publish) {
return _forEach(source, function* (item) {
if (predicate(item)) {
publish(item);
}
});
};
});
};
_proto.match = function match(reference) {
return this.filter(matcher(reference));
};
_proto.chain = function chain(next) {
return new Chain(createSubscription(next(this.source)));
};
_proto.forEach = function forEach(visit) {
return _forEach(this.source, visit);
};
_proto.first = function* first() {
var subscription = yield subscribe(this.source);
var _yield$subscription$n = yield subscription.next(),
done = _yield$subscription$n.done,
value = _yield$subscription$n.value;
if (done) {
return undefined;
} else {
return value;
}
};
return Chain;
}();
function subscribe(source) {
if (isSubscribable(source)) {
return source[SymbolSubscribable]();
} else {
return source;
}
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
function isSubscribable(value) {
return !!value[SymbolSubscribable];
}
var DUMMY = {
next: function next() {
throw new Error('dummy');
}
};
var ChainableSubscription = /*#__PURE__*/function () {

@@ -29,2 +145,10 @@ function ChainableSubscription(subscription) {

ChainableSubscription.of = function* of(source) {
var chain = new ChainableSubscription(DUMMY);
return yield effection.resource(chain, function* () {
chain.subscription = yield subscribe(source);
yield;
});
};
var _proto = ChainableSubscription.prototype;

@@ -189,111 +313,4 @@

var SymbolSubscribable = /*#__PURE__*/Symbol["for"]('Symbol.subscription');
function* _forEach(source, visit) {
var subscription = yield subscribe(source);
while (true) {
var result = yield subscription.next();
if (result.done) {
return result.value;
} else {
yield visit(result.value);
}
}
}
var Subscribable = {
from: function from(source) {
return new Chain(source);
}
};
var Chain = /*#__PURE__*/function () {
function Chain(source) {
this.source = source;
}
var _proto = Chain.prototype;
_proto[SymbolSubscribable] = function () {
return subscribe(this.source);
};
_proto.map = function map(fn) {
return this.chain(function (source) {
return function (publish) {
return _forEach(source, function* (item) {
publish(fn(item));
});
};
});
};
_proto.filter = function filter(predicate) {
return this.chain(function (source) {
return function (publish) {
return _forEach(source, function* (item) {
if (predicate(item)) {
publish(item);
}
});
};
});
};
_proto.match = function match(reference) {
return this.filter(matcher(reference));
};
_proto.chain = function chain(next) {
return new Chain(createSubscription(next(this.source)));
};
_proto.forEach = function forEach(visit) {
return _forEach(this.source, visit);
};
_proto.first = function* first() {
var subscription = yield subscribe(this.source);
var _yield$subscription$n = yield subscription.next(),
done = _yield$subscription$n.done,
value = _yield$subscription$n.value;
if (done) {
return undefined;
} else {
return value;
}
};
return Chain;
}();
function subscribe(source) {
if (isSubscribable(source)) {
var subscriber = getSubscriber(source);
if (subscriber) {
return subscriber.call(source);
} else {
var error = new Error("cannot subscribe to " + source + " because it does not contain Symbol.subscription");
error.name = 'TypeError';
throw error;
}
} else {
return source;
}
}
function isSubscribable(value) {
return !!getSubscriber(value);
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
function getSubscriber(source) {
return source[SymbolSubscribable];
}
function* subscribe$1(source) {
var inner = yield subscribe(source);
return new ChainableSubscription(inner);
return yield ChainableSubscription.of(source);
}

@@ -300,0 +317,0 @@

@@ -1,2 +0,2 @@

"use strict";var n=require("effection");function r(n){return function(t){if("object"==typeof t&&"object"==typeof n){var e=t;return Object.entries(n).every((function(n){var t=n[0];return r(n[1])(e[t])}))}return t===n}}var t=function(){function n(n){this.subscription=n}var t=n.prototype;return t.filter=function(r){var t=this.subscription;return new n({next:function*(){for(;;){var n=yield t.next();if(n.done)return n;if(r(n.value))return n}}})},t.match=function(n){return this.filter(r(n))},t.map=function(r){var t=this.subscription;return new n({next:function*(){for(;;){var n=yield t.next();return n.done?n:{done:!1,value:r(n.value)}}}})},t.first=function*(){var n=yield this.subscription.next();return n.done?void 0:n.value},t.expect=function*(){var n=yield this.subscription.next();if(n.done)throw new Error("expected subscription to contain a value");return n.value},t.forEach=function*(n){for(;;){var r=yield this.subscription.next();if(r.done)return r.value;yield n(r.value)}},t.next=function(){return this.subscription.next()},n}(),e=function(){var n=this;this.waiters=[],this.signal=function(r){var t=n.waiters.pop();t&&t(r)},this.wait=function(){return new Promise((function(r){return n.waiters.push(r)}))}};function i(r){return function*(){var i=[],u=new e,o=function(n){i.push({done:!1,value:n}),u.signal()};return yield n.resource(new t({next:function(){try{var n=u.wait();return i.length>0&&u.signal(),Promise.resolve(n.then((function(){return i.shift()})))}catch(n){return Promise.reject(n)}}}),(function*(){try{var n=yield r((function(n){return o(n)}));i.push({done:!0,value:n}),u.signal()}finally{o=function(n){throw function(n){var r=new Error("tried to publish a value: "+n+" on an already finished subscription");return r.name="TypeError",r}(n)}}}))}}var u=Symbol.for("Symbol.subscription");function*o(n,r){for(var t=yield a(n);;){var e=yield t.next();if(e.done)return e.value;yield r(e.value)}}var c={from:function(n){return new s(n)}},s=function(){function n(n){this.source=n}var t=n.prototype;return t[u]=function(){return a(this.source)},t.map=function(n){return this.chain((function(r){return function(t){return o(r,(function*(r){t(n(r))}))}}))},t.filter=function(n){return this.chain((function(r){return function(t){return o(r,(function*(r){n(r)&&t(r)}))}}))},t.match=function(n){return this.filter(r(n))},t.chain=function(r){return new n(i(r(this.source)))},t.forEach=function(n){return o(this.source,n)},t.first=function*(){var n=yield a(this.source),r=yield n.next();return r.done?void 0:r.value},n}();function a(n){if(f(n)){var r=f(n);if(r)return r.call(n);var t=new Error("cannot subscribe to "+n+" because it does not contain Symbol.subscription");throw t.name="TypeError",t}return n}function f(n){return n[u]}exports.ChainableSubscription=t,exports.Subscribable=c,exports.SymbolSubscribable=u,exports.createSubscription=i,exports.forEach=o,exports.subscribe=function*(n){var r=yield a(n);return new t(r)};
"use strict";var n=require("effection");function r(n){return function(t){if("object"==typeof t&&"object"==typeof n){var e=t;return Object.entries(n).every((function(n){var t=n[0];return r(n[1])(e[t])}))}return t===n}}var t=Symbol.for("Symbol.subscription");function*e(n,r){for(var t=yield o(n);;){var e=yield t.next();if(e.done)return e.value;yield r(e.value)}}var i={from:function(n){return new u(n)}},u=function(){function n(n){this.source=n}var i=n.prototype;return i[t]=function(){return o(this.source)},i.map=function(n){return this.chain((function(r){return function(t){return e(r,(function*(r){t(n(r))}))}}))},i.filter=function(n){return this.chain((function(r){return function(t){return e(r,(function*(r){n(r)&&t(r)}))}}))},i.match=function(n){return this.filter(r(n))},i.chain=function(r){return new n(a(r(this.source)))},i.forEach=function(n){return e(this.source,n)},i.first=function*(){var n=yield o(this.source),r=yield n.next();return r.done?void 0:r.value},n}();function o(n){return n[t]?n[t]():n}var c={next:function(){throw new Error("dummy")}},s=function(){function t(n){this.subscription=n}t.of=function*(r){var e=new t(c);return yield n.resource(e,(function*(){e.subscription=yield o(r),yield}))};var e=t.prototype;return e.filter=function(n){var r=this.subscription;return new t({next:function*(){for(;;){var t=yield r.next();if(t.done)return t;if(n(t.value))return t}}})},e.match=function(n){return this.filter(r(n))},e.map=function(n){var r=this.subscription;return new t({next:function*(){for(;;){var t=yield r.next();return t.done?t:{done:!1,value:n(t.value)}}}})},e.first=function*(){var n=yield this.subscription.next();return n.done?void 0:n.value},e.expect=function*(){var n=yield this.subscription.next();if(n.done)throw new Error("expected subscription to contain a value");return n.value},e.forEach=function*(n){for(;;){var r=yield this.subscription.next();if(r.done)return r.value;yield n(r.value)}},e.next=function(){return this.subscription.next()},t}(),f=function(){var n=this;this.waiters=[],this.signal=function(r){var t=n.waiters.pop();t&&t(r)},this.wait=function(){return new Promise((function(r){return n.waiters.push(r)}))}};function a(r){return function*(){var t=[],e=new f,i=function(n){t.push({done:!1,value:n}),e.signal()};return yield n.resource(new s({next:function(){try{var n=e.wait();return t.length>0&&e.signal(),Promise.resolve(n.then((function(){return t.shift()})))}catch(n){return Promise.reject(n)}}}),(function*(){try{var n=yield r((function(n){return i(n)}));t.push({done:!0,value:n}),e.signal()}finally{i=function(n){throw function(n){var r=new Error("tried to publish a value: "+n+" on an already finished subscription");return r.name="TypeError",r}(n)}}}))}}exports.ChainableSubscription=s,exports.Subscribable=i,exports.SymbolSubscribable=t,exports.createSubscription=a,exports.forEach=e,exports.subscribe=function*(n){return yield s.of(n)};
//# sourceMappingURL=subscription.cjs.production.min.js.map

@@ -21,2 +21,118 @@ import { resource } from 'effection';

/**
* Hack Zone!
*
* tl;dr not only the symbol value, but also the symbol type must be
* global.
*
* In order to satisfy TypeScript that the SymbolSubscribable
* represents the same value across different versions of the same
* package, we need to declare a "fake" global variable that does not
* actually exist, but has a theoretical type. Since it is global,
* TypeScript will see it as the same type everywhere, and so we can
* use the `typeof` for the value, as the type of of our local symbol
* subscribable, and TypeScript will think that all of the types are
* the same.
*
* See https://github.com/microsoft/TypeScript/issues/8099#issuecomment-210134773
* for details.
*/
var SymbolSubscribable = /*#__PURE__*/Symbol["for"]('Symbol.subscription');
function* _forEach(source, visit) {
var subscription = yield subscribe(source);
while (true) {
var result = yield subscription.next();
if (result.done) {
return result.value;
} else {
yield visit(result.value);
}
}
}
var Subscribable = {
from: function from(source) {
return new Chain(source);
}
};
var Chain = /*#__PURE__*/function () {
function Chain(source) {
this.source = source;
}
var _proto = Chain.prototype;
_proto[SymbolSubscribable] = function () {
return subscribe(this.source);
};
_proto.map = function map(fn) {
return this.chain(function (source) {
return function (publish) {
return _forEach(source, function* (item) {
publish(fn(item));
});
};
});
};
_proto.filter = function filter(predicate) {
return this.chain(function (source) {
return function (publish) {
return _forEach(source, function* (item) {
if (predicate(item)) {
publish(item);
}
});
};
});
};
_proto.match = function match(reference) {
return this.filter(matcher(reference));
};
_proto.chain = function chain(next) {
return new Chain(createSubscription(next(this.source)));
};
_proto.forEach = function forEach(visit) {
return _forEach(this.source, visit);
};
_proto.first = function* first() {
var subscription = yield subscribe(this.source);
var _yield$subscription$n = yield subscription.next(),
done = _yield$subscription$n.done,
value = _yield$subscription$n.value;
if (done) {
return undefined;
} else {
return value;
}
};
return Chain;
}();
function subscribe(source) {
if (isSubscribable(source)) {
return source[SymbolSubscribable]();
} else {
return source;
}
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
function isSubscribable(value) {
return !!value[SymbolSubscribable];
}
var DUMMY = {
next: function next() {
throw new Error('dummy');
}
};
var ChainableSubscription = /*#__PURE__*/function () {

@@ -27,2 +143,10 @@ function ChainableSubscription(subscription) {

ChainableSubscription.of = function* of(source) {
var chain = new ChainableSubscription(DUMMY);
return yield resource(chain, function* () {
chain.subscription = yield subscribe(source);
yield;
});
};
var _proto = ChainableSubscription.prototype;

@@ -187,111 +311,4 @@

var SymbolSubscribable = /*#__PURE__*/Symbol["for"]('Symbol.subscription');
function* _forEach(source, visit) {
var subscription = yield subscribe(source);
while (true) {
var result = yield subscription.next();
if (result.done) {
return result.value;
} else {
yield visit(result.value);
}
}
}
var Subscribable = {
from: function from(source) {
return new Chain(source);
}
};
var Chain = /*#__PURE__*/function () {
function Chain(source) {
this.source = source;
}
var _proto = Chain.prototype;
_proto[SymbolSubscribable] = function () {
return subscribe(this.source);
};
_proto.map = function map(fn) {
return this.chain(function (source) {
return function (publish) {
return _forEach(source, function* (item) {
publish(fn(item));
});
};
});
};
_proto.filter = function filter(predicate) {
return this.chain(function (source) {
return function (publish) {
return _forEach(source, function* (item) {
if (predicate(item)) {
publish(item);
}
});
};
});
};
_proto.match = function match(reference) {
return this.filter(matcher(reference));
};
_proto.chain = function chain(next) {
return new Chain(createSubscription(next(this.source)));
};
_proto.forEach = function forEach(visit) {
return _forEach(this.source, visit);
};
_proto.first = function* first() {
var subscription = yield subscribe(this.source);
var _yield$subscription$n = yield subscription.next(),
done = _yield$subscription$n.done,
value = _yield$subscription$n.value;
if (done) {
return undefined;
} else {
return value;
}
};
return Chain;
}();
function subscribe(source) {
if (isSubscribable(source)) {
var subscriber = getSubscriber(source);
if (subscriber) {
return subscriber.call(source);
} else {
var error = new Error("cannot subscribe to " + source + " because it does not contain Symbol.subscription");
error.name = 'TypeError';
throw error;
}
} else {
return source;
}
}
function isSubscribable(value) {
return !!getSubscriber(value);
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
function getSubscriber(source) {
return source[SymbolSubscribable];
}
function* subscribe$1(source) {
var inner = yield subscribe(source);
return new ChainableSubscription(inner);
return yield ChainableSubscription.of(source);
}

@@ -298,0 +315,0 @@

{
"name": "@effection/subscription",
"version": "0.8.0",
"version": "0.8.1-728efdb",
"description": "Effection Subscriptions",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -1,8 +0,20 @@

import { Operation } from 'effection';
import { Operation, resource } from 'effection';
import { Subscription } from './subscription';
import { DeepPartial, matcher } from './match';
import { SubscriptionSource, subscribe } from './subscribable';
const DUMMY = { next() { throw new Error('dummy') } };
export class ChainableSubscription<T,TReturn> implements Subscription<T,TReturn> {
constructor(private subscription: Subscription<T, TReturn>) {}
static *of<T, TReturn>(source: SubscriptionSource<T, TReturn>): Operation<ChainableSubscription<T, TReturn>> {
let chain = new ChainableSubscription(DUMMY);
return yield resource(chain, function*() {
chain.subscription = yield subscribe(source);
yield;
});
}
filter(predicate: (value: T) => boolean): ChainableSubscription<T, TReturn> {

@@ -9,0 +21,0 @@ let { subscription } = this;

export { Subscription, createSubscription } from './subscription';
export { SymbolSubscribable, SubscriptionSource, forEach, Subscribable } from './subscribable';
export { SymbolSubscribable } from './symbol-subscribable';
export { SubscriptionSource, forEach, Subscribable } from './subscribable';
export { ChainableSubscription } from './chainable-subscription';
import { Operation } from 'effection';
import { subscribe as rawSubscribe } from './subscribable';
import { ChainableSubscription } from './chainable-subscription';

@@ -11,4 +11,3 @@ import { SubscriptionSource } from './subscribable';

export function* subscribe<T, TReturn>(source: SubscriptionSource<T,TReturn>): Operation<ChainableSubscription<T,TReturn>> {
let inner = yield rawSubscribe(source);
return new ChainableSubscription<T, TReturn>(inner);
return yield ChainableSubscription.of(source);
}
import { Operation } from 'effection';
import { Subscription, createSubscription, Subscriber } from './subscription';
import { DeepPartial, matcher } from './match';
import { SymbolSubscribable } from './symbol-subscribable';
export const SymbolSubscribable: unique symbol = Symbol.for('Symbol.subscription');
export interface Subscribable<T,TReturn> {

@@ -75,10 +74,3 @@ [SymbolSubscribable](): Operation<Subscription<T,TReturn>>;

if (isSubscribable<T,TReturn>(source)) {
let subscriber = getSubscriber<T,TReturn>(source);
if (subscriber) {
return subscriber.call(source);
} else {
let error = new Error(`cannot subscribe to ${source} because it does not contain Symbol.subscription`)
error.name = 'TypeError';
throw error;
}
return source[SymbolSubscribable]()
} else {

@@ -89,9 +81,5 @@ return source;

function isSubscribable<T,TReturn>(value: unknown): value is Subscribable<T,TReturn> {
return !!getSubscriber<T,TReturn>(value);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function getSubscriber<T,TReturn>(source: any): undefined | (() => Operation<Subscription<T,TReturn>>) {
return source[SymbolSubscribable] as () => Operation<Subscription<T,TReturn>>;
function isSubscribable<T,TReturn>(value: any): value is Subscribable<T,TReturn> {
return !!value[SymbolSubscribable];
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc