graphql-pub-sub-with-initial-value 2.0.1 → 2.0.2

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.
@@ -0,0 +1,11 @@
1
+ import { PubSub } from "graphql-subscriptions";
2
+ export interface AsyncIterableIteratorWithInitialState<T> extends AsyncIterableIterator<T> {
3
+ initialValuePushed: boolean;
4
+ }
5
+ export const withCancel: <T, P>(asyncIterator: AsyncIterator<T | undefined>, onCancel: (args?: P) => void, args?: P) => AsyncIterator<T | undefined>;
6
+ export class PubSubWithIntialValue extends PubSub {
7
+ asyncIteratorWithInitialValue<T>(topic: string | string[], initialValueFn: () => Promise<T>): AsyncIterableIteratorWithInitialState<T>;
8
+ withCancel<T, P>(asyncIterator: AsyncIterator<T | undefined>, onCancel: (args?: P) => void, args?: P): AsyncIterator<T, any, undefined>;
9
+ }
10
+
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"mappings":";AAEA,uDAAuD,CAAC,CAAE,SAAQ,qBAAqB,CAAC,CAAC,CAAC;IACxF,kBAAkB,EAAE,OAAO,CAAA;CAC5B;AAED,OAAO,MAAM,aAAc,CAAC,EAAE,CAAC,EAC7B,eAAe,aAAa,CAAC,CAAC,GAAG,SAAS,CAAC,EAC3C,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,IAAI,EAC5B,OAAO,CAAC,KACP,aAAa,CAAC,CAAC,GAAG,SAAS,CAe7B,CAAA;AAED,kCAAmC,SAAQ,MAAM;IA2BxC,6BAA6B,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,sCAAsC,CAAC,CAAC;eAI3H,CAAC,EAAE,CAAC,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,EAAE,GAAG,EAAE,SAAS,CAAC;CAG/I","sources":["src/src/index.ts","src/index.ts"],"sourcesContent":[null,"import { PubSub } from 'graphql-subscriptions'\n\nexport interface AsyncIterableIteratorWithInitialState<T> extends AsyncIterableIterator<T> {\n initialValuePushed: boolean\n}\n\nexport const withCancel = <T, P>(\n asyncIterator: AsyncIterator<T | undefined>,\n onCancel: (args?: P) => void,\n args?: P\n): AsyncIterator<T | undefined> => {\n if (!asyncIterator.return) {\n asyncIterator.return = () => Promise.resolve({\n done: true,\n value: undefined\n })\n }\n\n const savedReturn = asyncIterator.return.bind(asyncIterator)\n asyncIterator.return = () => {\n onCancel(args)\n return savedReturn()\n }\n\n return asyncIterator\n}\n\nexport class PubSubWithIntialValue extends PubSub {\n private withInitialValue<T>(iterator: AsyncIterator<T>, getInitialValue: () => Promise<T>): AsyncIterableIteratorWithInitialState<T> {\n return {\n [Symbol.asyncIterator](): AsyncIterableIterator<T> { return this },\n initialValuePushed: false,\n next(value?: any): Promise<IteratorResult<T>> {\n if (this.initialValuePushed) {\n return iterator.next(value).then(({ value, done }: IteratorResult<T>): IteratorResult<T> => ({\n done,\n value\n }))\n } else {\n return getInitialValue().then((value: T): IteratorResult<T> => {\n this.initialValuePushed = true\n return { done: false, value }\n })\n }\n },\n return(value?: any): Promise<IteratorResult<T>> {\n return iterator.return!(value)\n },\n throw(value?: any): Promise<IteratorResult<T>> {\n return iterator.throw!(value)\n }\n }\n }\n\n public asyncIteratorWithInitialValue<T>(topic: string | string[], initialValueFn: () => Promise<T>): AsyncIterableIteratorWithInitialState<T> {\n return this.withInitialValue(this.asyncIterableIterator<T>(topic), (): Promise<T> => initialValueFn())\n }\n\n public withCancel<T, P>(asyncIterator: AsyncIterator<T | undefined>, onCancel: (args?: P) => void, args?: P): AsyncIterator<T, any, undefined> {\n return withCancel<T, P>(asyncIterator, onCancel, args)\n }\n}\n"],"names":[],"version":3,"file":"index.d.ts.map","sourceRoot":"../../"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphql-pub-sub-with-initial-value",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "GraphQL PubSub with intial value handling",
5
5
  "scripts": {
6
6
  "test": "node_modules/.bin/jest --coverage && npm run lint",
@@ -24,21 +24,21 @@
24
24
  "node": "24.11.0"
25
25
  },
26
26
  "devDependencies": {
27
- "@eslint/eslintrc": "^3.3.3",
28
- "@eslint/js": "^9.27.0",
27
+ "@eslint/eslintrc": "^3.3.5",
28
+ "@eslint/js": "^9.39.4",
29
29
  "@parcel/bundler-library": "^2.16.4",
30
30
  "@parcel/packager-ts": "^2.16.4",
31
31
  "@parcel/transformer-typescript-types": "^2.16.4",
32
32
  "@types/jest": "^30.0.0",
33
- "@types/node": "^24.10.13",
34
- "@typescript-eslint/eslint-plugin": "^8.55.0",
35
- "@typescript-eslint/parser": "^8.55.0",
36
- "acorn": "^8.15.0",
33
+ "@types/node": "^24.12.0",
34
+ "@typescript-eslint/eslint-plugin": "^8.58.0",
35
+ "@typescript-eslint/parser": "^8.58.0",
36
+ "acorn": "^8.16.0",
37
37
  "esbuild": "0.27.3",
38
- "eslint": "^9.39.2",
39
- "graphql": "^16.12.0",
38
+ "eslint": "^9.39.4",
39
+ "graphql": "^16.13.2",
40
40
  "graphql-subscriptions": "^3.0.0",
41
- "jest": "^30.2.0",
41
+ "jest": "^30.3.0",
42
42
  "parcel": "^2.16.4",
43
43
  "ts-jest": "^29.4.6",
44
44
  "typescript": "~5.9.3"