Initial Save

This commit is contained in:
jackbeeby
2025-03-28 12:30:19 +11:00
parent e381994f19
commit d8773925e8
9910 changed files with 982718 additions and 0 deletions

View File

@@ -0,0 +1,81 @@
## Authorize on connect
When client side creates the WebSocket instance and connects to the subscriptions server, it must provide the authorization token, but there are some issues with that:
1. Its not possible to provide custom headers when creating WebSocket connection in browser.
> related to https://github.com/apollostack/subscriptions-transport-ws/issues/50 ,
https://github.com/apollostack/subscriptions-transport-ws/pull/45
A possible workaround is to send the auth token in the url as query parameter and parse in on sever side while doing the connection handshake
> (Note: graphql-subscription does not expose onConnection callback, only onSubscribe, which occur after the connection)
2. You have to create the actual connection and then reject it in the server side if there is an error with the users authorization token.
At the moment, graphql-subscription does not expose `unsubscribe` or `disconnect` feature for a connection (should be part of `onConnection`)
> related to https://github.com/apollostack/subscriptions-transport-ws/issues/51 , https://github.com/apollostack/subscriptions-transport-ws/pull/17
3. At the moment, the client side can provide the “context” object for the subscription (and not for the connection), which can contain his auth token.
Another option is to send the auth token from the client side on a separate message (like, `ON_INIT`) before creating the subscriptions.
## Authorization Lifecycle
Another issue is the lifecycle of the authorization token, there are some cases that needs a solution:
1. How to handle invalidation of the auth token?
If the client side logout from the application, its the client sides responsibility to disconnect the WebSocket.
2. How to handle expiration of token?
At the moment, If the client sides token no longer valid, it should logout the user and disconnect the token.
## Authorization Validation
What is the server sides responsibility when dealing with authorized WebSocket and subscriptions?
If the client side does not disconnects the WebSocket when needed (for example, on logout or on expiration), and the WebSocket remains open, the client side will receive the publications of its existing subscriptions.
Its not an option to validate the auth token on the server before each publication, for each user that subscribed.
## Existing WebSocket Authorization Solutions
* Socket.io-auth (https://github.com/facundoolano/socketio-auth )
* Provides a similar flow to onConnection and onAuthorize with a token, the server can validate and authorize the connection only when the connection created.
* The auth token send via a custom WebSocket message.
* Features callbacks for `onAuthorize`, `onAuthorized`, `onReject`, `postAuthenticate`.
* Sockjs-node (https://github.com/sockjs/sockjs-node#authorisation )
* Does not provide a built-in solution and suggest a self-implemented authorization.
* https://gist.github.com/subudeepak/9897212
* https://auth0.com/blog/auth-with-socket-io/
* https://auth0.com/blog/auth-with-socket-io/
* Suggests using authorization on connection using url parameter with the auth token.
* Meteor/DDP
* The DDP protocol itself has no concept of authentication. Authentication is done via normal method calls.
* The Meteor DDP server implementation allows method calls to store state on the connection object representing the current user ID, which is accessible from other methods and publications. If the user ID ever changes, all publications are basically re-evaluated from scratch (inside the server). Nothing special is done on the server side to allow methods to notice if the user ID changes while they are running; however, methods run in series unless they explicitly ask to unblock the connection (and the client tries to not send login methods in parallel with other methods).
* The Meteor Accounts package tracks DDP connections associated with resume tokens and disconnects them if the resume token associated with that connection is deleted from the database.
* Personal opinion from @glasser: having auth just be "another method" wasn't the best idea. It works better if it's an established-at-beginning-of-connection, disconnect-to-change thing. However, the general idea of having a way for changes to authn/authz to "rerun publishers" or "disconnect connections" is nice.
## Implementation possibility:
* Client creates a networkInterface with WebSocket client, and provides the auth token using one of the following:
* URL parameter with the auth token.
* Custom object that will be translated into INIT_MESSAGE and will be sent after initial connection handshake.
* Server side “onConnection” fires and validate the token, if the token is invalid, it rejects the connection / disconnects the socket.
#### Pros:
* Simple to implement.
* Server side - need to add “onConnection” callback with ability to reject the connection.
* Client side - need to add ability to send custom object with the auth token (or take if from the requested URL).
* Custom auth for each application.
#### Cons:
* Forces the client side to handle logout/expiration of the token
* Server publications not validated.

View File

@@ -0,0 +1,12 @@
<!--**Issue Labels**
While not necessary, you can help organize our issues by labeling this issue when you open it. To add a label automatically, simply [x] mark the appropriate box below:
- [ ] has-reproduction
- [ ] feature
- [ ] blocking
- [ ] good first issue
To add a label not listed above, simply place `/label another-label-name` on a line by itself.
-->

View File

@@ -0,0 +1,12 @@
<!--**Pull Request Labels**
While not necessary, you can help organize our pull requests by labeling this issue when you open it. To add a label automatically, simply [x] mark the appropriate box below:
- [ ] has-reproduction
- [ ] feature
- [ ] blocking
- [ ] good first review
To add a label not listed above, simply place `/label another-label-name` on a line by itself.
-->

15
node_modules/graphql-subscriptions/.travis.yml generated vendored Normal file
View File

@@ -0,0 +1,15 @@
language: node_js
node_js:
- "12"
install:
- npm install -g coveralls
- npm install
script:
- npm test
- npm run coverage
- coveralls < ./coverage/lcov.info || true # ignore coveralls error
# Allow Travis tests to run in containers.
# sudo: false

11
node_modules/graphql-subscriptions/AUTHORS generated vendored Normal file
View File

@@ -0,0 +1,11 @@
Authors
Jonas Helfer <helfer@users.noreply.github.com>
Jonas Helfer <jonas@helfer.email>
Quint Stoffers <quintstoffers@users.noreply.github.com>
Sashko Stubailo <s.stubailo@gmail.com>
Sashko Stubailo <sashko@stubailo.com>
David Yahalomi <davidyaha@users.noreply.github.com>
Alexander Anich <Anichale@users.noreply.github.com>
Francois Valdy <gluck@users.noreply.github.com>
Daniel Rinehart <NeoPhi@users.noreply.github.com>

92
node_modules/graphql-subscriptions/CHANGELOG.md generated vendored Normal file
View File

@@ -0,0 +1,92 @@
# Changelog
### 1.2.1
- Fix memory leak in `withFilter`. [PR #209](https://github.com/apollographql/graphql-subscriptions/pull/209)
### 1.2.0
- Add `graphql@15` to `peerDependencies`.
### 1.1.0
- Fix [#132](https://github.com/apollographql/graphql-subscriptions/issues/132) - withFilter was previously always passing undefined as its first argument to the filterFn
- Partially attempt to fix [#143](https://github.com/apollographql/graphql-subscriptions/issues/143) - try to reduce occurrence of certain memory leaks with the built-in PubSubEngine implementation
- Replaced `eventEmitterAsyncIterator` with default generic `AsyncIterator` named `PubSubAsyncIterator`. `extends PubSubEngine` automatically uses generic implementation. No breaking changes for those who continue to use `implements PubSubEngine`. See PR [#78](https://github.com/apollographql/graphql-subscriptions/pull/78).
### 1.0.0
- BREAKING CHANGE: Changed return type of `publish`. <br/>
[@grantwwu](https://github.com/grantwwu) in [#162](https://github.com/apollographql/graphql-subscriptions/pull/162)
- Bump versions of various devDependencies to fix security issues, use
newer tslint config. <br/>
[@grantwwu](https://github.com/grantwwu) in [#163](https://github.com/apollographql/graphql-subscriptions/pull/163)
- Allows `graphql` 14 as a peer dep, forces `graphql` 14 as a dev dep, and
has been updated to use `@types/graphql` 14. <br/>
[@hwillson](https://github.com/hwillson) in [#172](https://github.com/apollographql/graphql-subscriptions/pull/172)
### 0.5.8
- Bump iterall version
### 0.5.7
- Add `graphql@0.13` to `peerDependencies`.
### 0.5.6
- Add `graphql@0.12` to `peerDependencies`.
### 0.5.5
- FilterFn can return a Promise<boolean>
- Allow passing in a custom `EventEmitter` to `PubSub`
### 0.5.4
- Better define `withFilter` return type [PR #111](https://github.com/apollographql/graphql-subscriptions/pull/111)
### 0.5.3
- Require iterall ^1.1.3 to address unhandled exceptions
### 0.5.2
- Require iterall ^1.1.2 to address memory leak [Issue #97] (https://github.com/apollographql/graphql-subscriptions/issues/97)
- Remove `@types/graphql` dependency. [PR #105] (https://github.com/apollographql/graphql-subscriptions/pull/105)
### 0.5.1
- `withFilter` now called with `(rootValue, args, context, info)` [PR #103] (https://github.com/apollographql/graphql-subscriptions/pull/103)
### 0.5.0
- BREAKING CHANGE: Removed deprecated code. [PR #104] (https://github.com/apollographql/graphql-subscriptions/pull/104)
- BREAKING CHANGE: Minimum GraphQL version bumped to 0.10.X. [PR #104] (https://github.com/apollographql/graphql-subscriptions/pull/104)
### 0.4.4
- Avoid infinite loop after the last consumer unsubscribes, [Issue #81](https://github.com/apollographql/graphql-subscriptions/issues/81) [PR #84](https://github.com/apollographql/graphql-subscriptions/pull/84)
### 0.4.3
- Properly propagate return() and throw() through withFilter [PR #74](https://github.com/apollographql/graphql-subscriptions/pull/74)
### 0.4.2
- Fixed issue with `withFilter` causing to use the same iterator [PR #69](https://github.com/apollographql/graphql-subscriptions/pull/69)
### 0.4.1
- Fixed exports issue with TypeScript [PR #65](https://github.com/apollographql/graphql-subscriptions/pull/65)
### 0.4.0
- Added `asyncIterator(channelName: string)` to `PubSub` implementation [PR #60](https://github.com/apollographql/graphql-subscriptions/pull/60)
- Added `withFilter` to allow `AsyncIterator` filtering [PR #60](https://github.com/apollographql/graphql-subscriptions/pull/60)
- Deprecate `SubscriptionManager` [PR #60](https://github.com/apollographql/graphql-subscriptions/pull/60)
- Fixed `withFilter` issue caused multiple subscribers to execute with the same AsyncIterator [PR #69](https://github.com/apollographql/graphql-subscriptions/pull/69)
### 0.3.1
- Add support for `defaultValue`, fixes [#49](https://github.com/apollographql/graphql-subscriptions/issues/49) (https://github.com/apollographql/graphql-subscriptions/pull/50)
### 0.3.0
- Allow `setupFunctions` to be async (return `Promise`) (https://github.com/apollographql/graphql-subscriptions/pull/41)
- Refactor promise chaining in pubsub engine (https://github.com/apollographql/graphql-subscriptions/pull/41)
- Fixed a possible bug with managing subscriptions internally (https://github.com/apollographql/graphql-subscriptions/pull/29)
- Return the `Promise` from `onMessage` of PubSub engine (https://github.com/apollographql/graphql-subscriptions/pull/33)
### 0.2.3
- update `graphql` dependency to 0.9.0
### 0.2.2
- made `graphql` a peer dependency and updated it to 0.8.2
### v 0.2.1
- Fixed a bug that caused subscriptions without operationName to fail

82
node_modules/graphql-subscriptions/CONTRIBUTING.md generated vendored Normal file
View File

@@ -0,0 +1,82 @@
# Apollo Contributor Guide
Excited about Apollo and want to make it better? Were excited too!
Apollo is a community of developers just like you, striving to create the best tools and libraries around GraphQL. We welcome anyone who wants to contribute or provide constructive feedback, no matter the age or level of experience. If you want to help but don't know where to start, let us know, and we'll find something for you.
Oh, and if you haven't already, sign up for the [Apollo Slack](http://www.apollodata.com/#slack).
Here are some ways to contribute to the project, from easiest to most difficult:
* [Reporting bugs](#reporting-bugs)
* [Improving the documentation](#improving-the-documentation)
* [Responding to issues](#responding-to-issues)
* [Small bug fixes](#small-bug-fixes)
* [Suggesting features](#suggesting-features)
* [Big pull requests](#big-prs)
## Issues
### Reporting bugs
If you encounter a bug, please file an issue on GitHub via the repository of the sub-project you think contains the bug. If an issue you have is already reported, please add additional information or add a 👍 reaction to indicate your agreement.
While we will try to be as helpful as we can on any issue reported, please include the following to maximize the chances of a quick fix:
1. **Intended outcome:** What you were trying to accomplish when the bug occurred, and as much code as possible related to the source of the problem.
2. **Actual outcome:** A description of what actually happened, including a screenshot or copy-paste of any related error messages, logs, or other output that might be related. Places to look for information include your browser console, server console, and network logs. Please avoid non-specific phrases like “didnt work” or “broke”.
3. **How to reproduce the issue:** Instructions for how the issue can be reproduced by a maintainer or contributor. Be as specific as possible, and only mention what is necessary to reproduce the bug. If possible, try to isolate the exact circumstances in which the bug occurs and avoid speculation over what the cause might be.
Creating a good reproduction really helps contributors investigate and resolve your issue quickly. In many cases, the act of creating a minimal reproduction illuminates that the source of the bug was somewhere outside the library in question, saving time and effort for everyone.
### Improving the documentation
Improving the documentation, examples, and other open source content can be the easiest way to contribute to the library. If you see a piece of content that can be better, open a PR with an improvement, no matter how small! If you would like to suggest a big change or major rewrite, wed love to hear your ideas but please open an issue for discussion before writing the PR.
### Responding to issues
In addition to reporting issues, a great way to contribute to Apollo is to respond to other peoples' issues and try to identify the problem or help them work around it. If youre interested in taking a more active role in this process, please go ahead and respond to issues. And don't forget to say "Hi" on Apollo Slack!
### Small bug fixes
For a small bug fix change (less than 20 lines of code changed), feel free to open a pull request. Well try to merge it as fast as possible and ideally publish a new release on the same day. The only requirement is, make sure you also add a test that verifies the bug you are trying to fix.
### Suggesting features
Most of the features in Apollo came from suggestions by you, the community! We welcome any ideas about how to make Apollo better for your use case. Unless there is overwhelming demand for a feature, it might not get implemented immediately, but please include as much information as possible that will help people have a discussion about your proposal:
1. **Use case:** What are you trying to accomplish, in specific terms? Often, there might already be a good way to do what you need and a new feature is unnecessary, but its hard to know without information about the specific use case.
2. **Could this be a plugin?** In many cases, a feature might be too niche to be included in the core of a library, and is better implemented as a companion package. If there isnt a way to extend the library to do what you want, could we add additional plugin APIs? Its important to make the case for why a feature should be part of the core functionality of the library.
3. **Is there a workaround?** Is this a more convenient way to do something that is already possible, or is there some blocker that makes a workaround unfeasible?
Feature requests will be labeled as such, and we encourage using GitHub issues as a place to discuss new features and possible implementation designs. Please refrain from submitting a pull request to implement a proposed feature until there is consensus that it should be included. This way, you can avoid putting in work that cant be merged in.
Once there is a consensus on the need for a new feature, proceed as listed below under “Big PRs”.
## Big PRs
This includes:
- Big bug fixes
- New features
For significant changes to a repository, its important to settle on a design before starting on the implementation. This way, we can make sure that major improvements get the care and attention they deserve. Since big changes can be risky and might not always get merged, its good to reduce the amount of possible wasted effort by agreeing on an implementation design/plan first.
1. **Open an issue.** Open an issue about your bug or feature, as described above.
2. **Reach consensus.** Some contributors and community members should reach an agreement that this feature or bug is important, and that someone should work on implementing or fixing it.
3. **Agree on intended behavior.** On the issue, reach an agreement about the desired behavior. In the case of a bug fix, it should be clear what it means for the bug to be fixed, and in the case of a feature, it should be clear what it will be like for developers to use the new feature.
4. **Agree on implementation plan.** Write a plan for how this feature or bug fix should be implemented. What modules need to be added or rewritten? Should this be one pull request or multiple incremental improvements? Who is going to do each part?
5. **Submit PR.** In the case where multiple dependent patches need to be made to implement the change, only submit one at a time. Otherwise, the others might get stale while the first is reviewed and merged. Make sure to avoid “while were here” type changes - if something isnt relevant to the improvement at hand, it should be in a separate PR; this especially includes code style changes of unrelated code.
6. **Review.** At least one core contributor should sign off on the change before its merged. Look at the “code review” section below to learn about factors are important in the code review. If you want to expedite the code being merged, try to review your own code first!
7. **Merge and release!**
### Code review guidelines
Its important that every piece of code in Apollo packages is reviewed by at least one core contributor familiar with that codebase. Here are some things we look for:
1. **Required CI checks pass.** This is a prerequisite for the review, and it is the PR author's responsibility. As long as the tests dont pass, the PR won't get reviewed.
2. **Simplicity.** Is this the simplest way to achieve the intended goal? If there are too many files, redundant functions, or complex lines of code, suggest a simpler way to do the same thing. In particular, avoid implementing an overly general solution when a simple, small, and pragmatic fix will do.
3. **Testing.** Do the tests ensure this code wont break when other stuff changes around it? When it does break, will the tests added help us identify which part of the library has the problem? Did we cover an appropriate set of edge cases? Look at the test coverage report if there is one. Are all significant code paths in the new code exercised at least once?
4. **No unnecessary or unrelated changes.** PRs shouldnt come with random formatting changes, especially in unrelated parts of the code. If there is some refactoring that needs to be done, it should be in a separate PR from a bug fix or feature, if possible.
5. **Code has appropriate comments.** Code should be commented, or written in a clear “self-documenting” way.
6. **Idiomatic use of the language.** In TypeScript, make sure the typings are specific and correct. In ES2015, make sure to use imports rather than require and const instead of var, etc. Ideally a linter enforces a lot of this, but use your common sense and follow the style of the surrounding code.

22
node_modules/graphql-subscriptions/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2015 - 2016 Meteor Development Group, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

246
node_modules/graphql-subscriptions/README.md generated vendored Normal file
View File

@@ -0,0 +1,246 @@
[![npm version](https://badge.fury.io/js/graphql-subscriptions.svg)](https://badge.fury.io/js/graphql-subscriptions) [![GitHub license](https://img.shields.io/github/license/apollostack/graphql-subscriptions.svg)](https://github.com/apollographql/graphql-subscriptions/blob/master/LICENSE)
# graphql-subscriptions
GraphQL subscriptions is a simple npm package that lets you wire up GraphQL with a pubsub system (like Redis) to implement subscriptions in GraphQL.
You can use it with any GraphQL client and server (not only Apollo).
### Installation
`npm install graphql-subscriptions graphql` or `yarn add graphql-subscriptions graphql`
> This package should be used with a network transport, for example [subscriptions-transport-ws](https://github.com/apollographql/subscriptions-transport-ws).
### TypeScript
If you are developing a project that uses this module with TypeScript:
* ensure that your `tsconfig.json` `lib` definition includes `"esnext.asynciterable"`
* `npm install @types/graphql` or `yarn add @types/graphql`
### Getting started with your first subscription
To begin with GraphQL subscriptions, start by defining a GraphQL `Subscription` type in your schema:
```graphql
type Subscription {
somethingChanged: Result
}
type Result {
id: String
}
```
Next, add the `Subscription` type to your `schema` definition:
```graphql
schema {
query: Query
mutation: Mutation
subscription: Subscription
}
```
Now, let's create a simple `PubSub` instance - it is a simple pubsub implementation, based on `EventEmitter`. Alternative `EventEmitter` implementations can be passed by an options object
to the `PubSub` constructor.
```js
import { PubSub } from 'graphql-subscriptions';
export const pubsub = new PubSub();
```
Now, implement your Subscriptions type resolver, using the `pubsub.asyncIterator` to map the event you need:
```js
const SOMETHING_CHANGED_TOPIC = 'something_changed';
export const resolvers = {
Subscription: {
somethingChanged: {
subscribe: () => pubsub.asyncIterator(SOMETHING_CHANGED_TOPIC),
},
},
}
```
> Subscriptions resolvers are not a function, but an object with `subscribe` method, that returns `AsyncIterable`.
Now, the GraphQL engine knows that `somethingChanged` is a subscription, and every time we use `pubsub.publish` over this topic - it will publish it using the transport we use:
```js
pubsub.publish(SOMETHING_CHANGED_TOPIC, { somethingChanged: { id: "123" }});
```
> Note that the default PubSub implementation is intended for demo purposes. It only works if you have a single instance of your server and doesn't scale beyond a couple of connections.
> For production usage you'll want to use one of the [PubSub implementations](#pubsub-implementations) backed by an external store. (e.g. Redis)
### Filters
When publishing data to subscribers, we need to make sure that each subscriber gets only the data it needs.
To do so, we can use `withFilter` helper from this package, which wraps `AsyncIterator` with a filter function, and lets you control each publication for each user.
`withFilter` API:
- `asyncIteratorFn: (rootValue, args, context, info) => AsyncIterator<any>` : A function that returns `AsyncIterator` you got from your `pubsub.asyncIterator`.
- `filterFn: (payload, variables, context, info) => boolean | Promise<boolean>` - A filter function, executed with the payload (the published value), variables, context and operation info, must return `boolean` or `Promise<boolean>` indicating if the payload should pass to the subscriber.
For example, if `somethingChanged` would also accept a variable with the ID that is relevant, we can use the following code to filter according to it:
```js
import { withFilter } from 'graphql-subscriptions';
const SOMETHING_CHANGED_TOPIC = 'something_changed';
export const resolvers = {
Subscription: {
somethingChanged: {
subscribe: withFilter(() => pubsub.asyncIterator(SOMETHING_CHANGED_TOPIC), (payload, variables) => {
return payload.somethingChanged.id === variables.relevantId;
}),
},
},
}
```
> Note that when using `withFilter`, you don't need to wrap your return value with a function.
### Channels Mapping
You can map multiple channels into the same subscription, for example when there are multiple events that trigger the same subscription in the GraphQL engine.
```js
const SOMETHING_UPDATED = 'something_updated';
const SOMETHING_CREATED = 'something_created';
const SOMETHING_REMOVED = 'something_removed';
export const resolvers = {
Subscription: {
somethingChanged: {
subscribe: () => pubsub.asyncIterator([ SOMETHING_UPDATED, SOMETHING_CREATED, SOMETHING_REMOVED ]),
},
},
}
````
### Payload Manipulation
You can also manipulate the published payload, by adding `resolve` methods to your subscription:
```js
const SOMETHING_UPDATED = 'something_updated';
export const resolvers = {
Subscription: {
somethingChanged: {
resolve: (payload, args, context, info) => {
// Manipulate and return the new value
return payload.somethingChanged;
},
subscribe: () => pubsub.asyncIterator(SOMETHING_UPDATED),
},
},
}
````
### Usage with callback listeners
Your database might have callback-based listeners for changes, for example something like this:
```JS
const listenToNewMessages = (callback) => {
return db.table('messages').listen(newMessage => callback(newMessage));
}
// Kick off the listener
listenToNewMessages(message => {
console.log(message);
})
```
The `callback` function would be called every time a new message is saved in the database. Unfortunately, that doesn't play very well with async iterators out of the box because callbacks are push-based, where async iterators are pull-based.
We recommend using the [`callback-to-async-iterator`](https://github.com/withspectrum/callback-to-async-iterator) module to convert your callback-based listener into an async iterator:
```js
import asyncify from 'callback-to-async-iterator';
export const resolvers = {
Subscription: {
somethingChanged: {
subscribe: () => asyncify(listenToNewMessages),
},
},
}
````
### Custom `AsyncIterator` Wrappers
The value you should return from your `subscribe` resolver must be an `AsyncIterator`.
You can use this value and wrap it with another `AsyncIterator` to implement custom logic over your subscriptions.
For example, the following implementation manipulate the payload by adding some static fields:
```typescript
import { $$asyncIterator } from 'iterall';
export const withStaticFields = (asyncIterator: AsyncIterator<any>, staticFields: Object): Function => {
return (rootValue: any, args: any, context: any, info: any): AsyncIterator<any> => {
return {
next() {
return asyncIterator.next().then(({ value, done }) => {
return {
value: {
...value,
...staticFields,
},
done,
};
});
},
return() {
return Promise.resolve({ value: undefined, done: true });
},
throw(error) {
return Promise.reject(error);
},
[$$asyncIterator]() {
return this;
},
};
};
};
```
> You can also take a look at `withFilter` for inspiration.
For more information about `AsyncIterator`:
- [TC39 Proposal](https://github.com/tc39/proposal-async-iteration)
- [iterall](https://github.com/leebyron/iterall)
- [IxJS](https://github.com/ReactiveX/IxJS)
### PubSub Implementations
It can be easily replaced with some other implementations of [PubSubEngine abstract class](https://github.com/apollographql/graphql-subscriptions/blob/master/src/pubsub-engine.ts). Here are a few of them:
- Use Redis with https://github.com/davidyaha/graphql-redis-subscriptions
- Use Google PubSub with https://github.com/axelspringer/graphql-google-pubsub
- Use MQTT enabled broker with https://github.com/davidyaha/graphql-mqtt-subscriptions
- Use RabbitMQ with https://github.com/cdmbase/graphql-rabbitmq-subscriptions
- Use AMQP (RabbitMQ) with https://github.com/Surnet/graphql-amqp-subscriptions
- Use Kafka with https://github.com/ancashoria/graphql-kafka-subscriptions
- Use Postgres with https://github.com/GraphQLCollege/graphql-postgres-subscriptions
- Use NATS with https://github.com/moonwalker/graphql-nats-subscriptions
- Use multiple backends with https://github.com/jcoreio/graphql-multiplex-subscriptions
- [Add your implementation...](https://github.com/apollographql/graphql-subscriptions/pull/new/master)
You can also implement a `PubSub` of your own, by using the exported abstract class `PubSubEngine` from this package. By using `extends PubSubEngine` you use the default `asyncIterator` method implementation; by using `implements PubSubEngine` you must implement your own `AsyncIterator`.
#### SubscriptionManager **@deprecated**
`SubscriptionManager` is the previous alternative for using `graphql-js` subscriptions directly, and it's now deprecated.
If you are looking for its API docs, refer to [a previous commit of the repository](https://github.com/apollographql/graphql-subscriptions/blob/5eaee92cd50060b3f3637f00c53960f51a07d0b2/README.md)

3
node_modules/graphql-subscriptions/dist/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,3 @@
export { PubSubEngine } from './pubsub-engine';
export { PubSub, PubSubOptions } from './pubsub';
export { withFilter, ResolverFn, FilterFn } from './with-filter';

9
node_modules/graphql-subscriptions/dist/index.js generated vendored Normal file
View File

@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var pubsub_engine_1 = require("./pubsub-engine");
Object.defineProperty(exports, "PubSubEngine", { enumerable: true, get: function () { return pubsub_engine_1.PubSubEngine; } });
var pubsub_1 = require("./pubsub");
Object.defineProperty(exports, "PubSub", { enumerable: true, get: function () { return pubsub_1.PubSub; } });
var with_filter_1 = require("./with-filter");
Object.defineProperty(exports, "withFilter", { enumerable: true, get: function () { return with_filter_1.withFilter; } });
//# sourceMappingURL=index.js.map

1
node_modules/graphql-subscriptions/dist/index.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,iDAA+C;AAAtC,6GAAA,YAAY,OAAA;AACrB,mCAAiD;AAAxC,gGAAA,MAAM,OAAA;AACf,6CAAiE;AAAxD,yGAAA,UAAU,OAAA"}

View File

@@ -0,0 +1,20 @@
import { $$asyncIterator } from 'iterall';
import { PubSubEngine } from './pubsub-engine';
export declare class PubSubAsyncIterator<T> implements AsyncIterator<T> {
private pullQueue;
private pushQueue;
private eventsArray;
private allSubscribed;
private running;
private pubsub;
constructor(pubsub: PubSubEngine, eventNames: string | string[]);
next(): Promise<IteratorResult<T>>;
return(): Promise<IteratorResult<T>>;
throw(error: any): Promise<never>;
[$$asyncIterator](): this;
private pushValue;
private pullValue;
private emptyQueue;
private subscribeAll;
private unsubscribeAll;
}

View File

@@ -0,0 +1,161 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PubSubAsyncIterator = void 0;
var iterall_1 = require("iterall");
var PubSubAsyncIterator = (function () {
function PubSubAsyncIterator(pubsub, eventNames) {
this.pubsub = pubsub;
this.pullQueue = [];
this.pushQueue = [];
this.running = true;
this.allSubscribed = null;
this.eventsArray = typeof eventNames === 'string' ? [eventNames] : eventNames;
}
PubSubAsyncIterator.prototype.next = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!!this.allSubscribed) return [3, 2];
return [4, (this.allSubscribed = this.subscribeAll())];
case 1:
_a.sent();
_a.label = 2;
case 2: return [2, this.pullValue()];
}
});
});
};
PubSubAsyncIterator.prototype.return = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.emptyQueue()];
case 1:
_a.sent();
return [2, { value: undefined, done: true }];
}
});
});
};
PubSubAsyncIterator.prototype.throw = function (error) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.emptyQueue()];
case 1:
_a.sent();
return [2, Promise.reject(error)];
}
});
});
};
PubSubAsyncIterator.prototype[iterall_1.$$asyncIterator] = function () {
return this;
};
PubSubAsyncIterator.prototype.pushValue = function (event) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.allSubscribed];
case 1:
_a.sent();
if (this.pullQueue.length !== 0) {
this.pullQueue.shift()(this.running
? { value: event, done: false }
: { value: undefined, done: true });
}
else {
this.pushQueue.push(event);
}
return [2];
}
});
});
};
PubSubAsyncIterator.prototype.pullValue = function () {
var _this = this;
return new Promise(function (resolve) {
if (_this.pushQueue.length !== 0) {
resolve(_this.running
? { value: _this.pushQueue.shift(), done: false }
: { value: undefined, done: true });
}
else {
_this.pullQueue.push(resolve);
}
});
};
PubSubAsyncIterator.prototype.emptyQueue = function () {
return __awaiter(this, void 0, void 0, function () {
var subscriptionIds;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.running) return [3, 2];
this.running = false;
this.pullQueue.forEach(function (resolve) { return resolve({ value: undefined, done: true }); });
this.pullQueue.length = 0;
this.pushQueue.length = 0;
return [4, this.allSubscribed];
case 1:
subscriptionIds = _a.sent();
if (subscriptionIds) {
this.unsubscribeAll(subscriptionIds);
}
_a.label = 2;
case 2: return [2];
}
});
});
};
PubSubAsyncIterator.prototype.subscribeAll = function () {
var _this = this;
return Promise.all(this.eventsArray.map(function (eventName) { return _this.pubsub.subscribe(eventName, _this.pushValue.bind(_this), {}); }));
};
PubSubAsyncIterator.prototype.unsubscribeAll = function (subscriptionIds) {
for (var _i = 0, subscriptionIds_1 = subscriptionIds; _i < subscriptionIds_1.length; _i++) {
var subscriptionId = subscriptionIds_1[_i];
this.pubsub.unsubscribe(subscriptionId);
}
};
return PubSubAsyncIterator;
}());
exports.PubSubAsyncIterator = PubSubAsyncIterator;
//# sourceMappingURL=pubsub-async-iterator.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"pubsub-async-iterator.js","sourceRoot":"","sources":["../src/pubsub-async-iterator.ts"],"names":[],"mappings":"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"}

View File

@@ -0,0 +1,6 @@
export declare abstract class PubSubEngine {
abstract publish(triggerName: string, payload: any): Promise<void>;
abstract subscribe(triggerName: string, onMessage: Function, options: Object): Promise<number>;
abstract unsubscribe(subId: number): any;
asyncIterator<T>(triggers: string | string[]): AsyncIterator<T>;
}

View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PubSubEngine = void 0;
var pubsub_async_iterator_1 = require("./pubsub-async-iterator");
var PubSubEngine = (function () {
function PubSubEngine() {
}
PubSubEngine.prototype.asyncIterator = function (triggers) {
return new pubsub_async_iterator_1.PubSubAsyncIterator(this, triggers);
};
return PubSubEngine;
}());
exports.PubSubEngine = PubSubEngine;
//# sourceMappingURL=pubsub-engine.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"pubsub-engine.js","sourceRoot":"","sources":["../src/pubsub-engine.ts"],"names":[],"mappings":";;;AAAA,iEAA4D;AAE5D;IAAA;IAOA,CAAC;IAHQ,oCAAa,GAApB,UAAwB,QAA2B;QACjD,OAAO,IAAI,2CAAmB,CAAI,IAAI,EAAE,QAAQ,CAAC,CAAC;IACpD,CAAC;IACH,mBAAC;AAAD,CAAC,AAPD,IAOC;AAPqB,oCAAY"}

15
node_modules/graphql-subscriptions/dist/pubsub.d.ts generated vendored Normal file
View File

@@ -0,0 +1,15 @@
/// <reference types="node" />
import { EventEmitter } from 'events';
import { PubSubEngine } from './pubsub-engine';
export interface PubSubOptions {
eventEmitter?: EventEmitter;
}
export declare class PubSub extends PubSubEngine {
protected ee: EventEmitter;
private subscriptions;
private subIdCounter;
constructor(options?: PubSubOptions);
publish(triggerName: string, payload: any): Promise<void>;
subscribe(triggerName: string, onMessage: (...args: any[]) => void): Promise<number>;
unsubscribe(subId: number): void;
}

47
node_modules/graphql-subscriptions/dist/pubsub.js generated vendored Normal file
View File

@@ -0,0 +1,47 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.PubSub = void 0;
var events_1 = require("events");
var pubsub_engine_1 = require("./pubsub-engine");
var PubSub = (function (_super) {
__extends(PubSub, _super);
function PubSub(options) {
if (options === void 0) { options = {}; }
var _this = _super.call(this) || this;
_this.ee = options.eventEmitter || new events_1.EventEmitter();
_this.subscriptions = {};
_this.subIdCounter = 0;
return _this;
}
PubSub.prototype.publish = function (triggerName, payload) {
this.ee.emit(triggerName, payload);
return Promise.resolve();
};
PubSub.prototype.subscribe = function (triggerName, onMessage) {
this.ee.addListener(triggerName, onMessage);
this.subIdCounter = this.subIdCounter + 1;
this.subscriptions[this.subIdCounter] = [triggerName, onMessage];
return Promise.resolve(this.subIdCounter);
};
PubSub.prototype.unsubscribe = function (subId) {
var _a = this.subscriptions[subId], triggerName = _a[0], onMessage = _a[1];
delete this.subscriptions[subId];
this.ee.removeListener(triggerName, onMessage);
};
return PubSub;
}(pubsub_engine_1.PubSubEngine));
exports.PubSub = PubSub;
//# sourceMappingURL=pubsub.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"pubsub.js","sourceRoot":"","sources":["../src/pubsub.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iCAAsC;AACtC,iDAA+C;AAM/C;IAA4B,0BAAY;IAKtC,gBAAY,OAA2B;QAA3B,wBAAA,EAAA,YAA2B;QAAvC,YACE,iBAAO,SAIR;QAHC,KAAI,CAAC,EAAE,GAAG,OAAO,CAAC,YAAY,IAAI,IAAI,qBAAY,EAAE,CAAC;QACrD,KAAI,CAAC,aAAa,GAAG,EAAE,CAAC;QACxB,KAAI,CAAC,YAAY,GAAG,CAAC,CAAC;;IACxB,CAAC;IAEM,wBAAO,GAAd,UAAe,WAAmB,EAAE,OAAY;QAC9C,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QACnC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAEM,0BAAS,GAAhB,UAAiB,WAAmB,EAAE,SAAmC;QACvE,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;QAC5C,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC;QAC1C,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;QAEjE,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC5C,CAAC;IAEM,4BAAW,GAAlB,UAAmB,KAAa;QACxB,IAAA,KAA2B,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAnD,WAAW,QAAA,EAAE,SAAS,QAA6B,CAAC;QAC3D,OAAO,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QACjC,IAAI,CAAC,EAAE,CAAC,cAAc,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IACjD,CAAC;IACH,aAAC;AAAD,CAAC,AA9BD,CAA4B,4BAAY,GA8BvC;AA9BY,wBAAM"}

View File

@@ -0,0 +1,3 @@
export declare type FilterFn = (rootValue?: any, args?: any, context?: any, info?: any) => boolean | Promise<boolean>;
export declare type ResolverFn = (rootValue?: any, args?: any, context?: any, info?: any) => AsyncIterator<any>;
export declare const withFilter: (asyncIteratorFn: ResolverFn, filterFn: FilterFn) => ResolverFn;

56
node_modules/graphql-subscriptions/dist/with-filter.js generated vendored Normal file
View File

@@ -0,0 +1,56 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.withFilter = void 0;
var iterall_1 = require("iterall");
exports.withFilter = function (asyncIteratorFn, filterFn) {
return function (rootValue, args, context, info) {
var _a;
var asyncIterator = asyncIteratorFn(rootValue, args, context, info);
var getNextPromise = function () {
return new Promise(function (resolve, reject) {
var inner = function () {
asyncIterator
.next()
.then(function (payload) {
if (payload.done === true) {
resolve(payload);
return;
}
Promise.resolve(filterFn(payload.value, args, context, info))
.catch(function () { return false; })
.then(function (filterResult) {
if (filterResult === true) {
resolve(payload);
return;
}
inner();
return;
});
})
.catch(function (err) {
reject(err);
return;
});
};
inner();
});
};
var asyncIterator2 = (_a = {
next: function () {
return getNextPromise();
},
return: function () {
return asyncIterator.return();
},
throw: function (error) {
return asyncIterator.throw(error);
}
},
_a[iterall_1.$$asyncIterator] = function () {
return this;
},
_a);
return asyncIterator2;
};
};
//# sourceMappingURL=with-filter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"with-filter.js","sourceRoot":"","sources":["../src/with-filter.ts"],"names":[],"mappings":";;;AAAA,mCAA0C;AAS7B,QAAA,UAAU,GAAG,UAAC,eAA2B,EAAE,QAAkB;IACxE,OAAO,UAAC,SAAc,EAAE,IAAS,EAAE,OAAY,EAAE,IAAS;;QACxD,IAAM,aAAa,GAAG,eAAe,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QAEtE,IAAM,cAAc,GAAG;YACrB,OAAO,IAAI,OAAO,CAAsB,UAAC,OAAO,EAAE,MAAM;gBAEtD,IAAM,KAAK,GAAG;oBACZ,aAAa;yBACV,IAAI,EAAE;yBACN,IAAI,CAAC,UAAA,OAAO;wBACX,IAAI,OAAO,CAAC,IAAI,KAAK,IAAI,EAAE;4BACzB,OAAO,CAAC,OAAO,CAAC,CAAC;4BACjB,OAAO;yBACR;wBACD,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;6BAC1D,KAAK,CAAC,cAAM,OAAA,KAAK,EAAL,CAAK,CAAC;6BAClB,IAAI,CAAC,UAAA,YAAY;4BAChB,IAAI,YAAY,KAAK,IAAI,EAAE;gCACzB,OAAO,CAAC,OAAO,CAAC,CAAC;gCACjB,OAAO;6BACR;4BAED,KAAK,EAAE,CAAC;4BACR,OAAO;wBACT,CAAC,CAAC,CAAC;oBACP,CAAC,CAAC;yBACD,KAAK,CAAC,UAAC,GAAG;wBACT,MAAM,CAAC,GAAG,CAAC,CAAC;wBACZ,OAAO;oBACT,CAAC,CAAC,CAAC;gBACP,CAAC,CAAC;gBAEF,KAAK,EAAE,CAAC;YAEV,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;QAEF,IAAM,cAAc;gBAClB,IAAI;oBACF,OAAO,cAAc,EAAE,CAAC;gBAC1B,CAAC;gBACD,MAAM;oBACJ,OAAO,aAAa,CAAC,MAAM,EAAE,CAAC;gBAChC,CAAC;gBACD,KAAK,YAAC,KAAK;oBACT,OAAO,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBACpC,CAAC;;YACD,GAAC,yBAAe,IAAhB;gBACE,OAAO,IAAI,CAAC;YACd,CAAC;eACF,CAAC;QAEF,OAAO,cAAc,CAAC;IACxB,CAAC,CAAC;AACJ,CAAC,CAAC"}

53
node_modules/graphql-subscriptions/package.json generated vendored Normal file
View File

@@ -0,0 +1,53 @@
{
"name": "graphql-subscriptions",
"version": "1.2.1",
"description": "GraphQL subscriptions for node.js",
"main": "dist/index.js",
"repository": {
"type": "git",
"url": "https://github.com/apollostack/graphql-subscriptions.git"
},
"dependencies": {
"iterall": "^1.3.0"
},
"peerDependencies": {
"graphql": "^0.10.5 || ^0.11.3 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
},
"scripts": {
"clean": "rimraf dist coverage",
"compile": "tsc",
"pretest": "npm run compile",
"test": "npm run testonly --",
"posttest": "npm run lint",
"lint": "tslint --project ./tsconfig.json ./src/**/*.ts",
"watch": "tsc -w",
"testonly": "node --expose-gc ./node_modules/.bin/mocha --reporter spec --full-trace ./dist/test/tests.js ./dist/test/asyncIteratorSubscription.js",
"coverage": "node --expose-gc ./node_modules/istanbul/lib/cli.js cover _mocha -- --full-trace ./dist/test/tests.js ./dist/test/asyncIteratorSubscription.js",
"postcoverage": "remap-istanbul --input coverage/coverage.raw.json --type lcovonly --output coverage/lcov.info",
"prepublishOnly": "npm run clean && npm run compile"
},
"devDependencies": {
"@types/chai-as-promised": "^7.1.3",
"@types/graphql": "^14.5.0",
"@types/mocha": "^8.0.0",
"@types/node": "^14.0.23",
"@types/sinon": "9.0.4",
"@types/sinon-chai": "^3.2.4",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"graphql": "^14.0.0",
"istanbul": "^1.0.0-alpha.2",
"mocha": "^8.0.1",
"remap-istanbul": "^0.13.0",
"rimraf": "^3.0.2",
"sinon": "^9.0.2",
"sinon-chai": "^3.5.0",
"tslint": "^6.1.2",
"typescript": "^3.9.6"
},
"typings": "dist/index.d.ts",
"typescript": {
"definition": "dist/index.d.ts"
},
"license": "MIT"
}