@apollo/client 3.7.7 → 3.7.8
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/apollo-client.cjs +3 -3
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/core/core.cjs +1 -1
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +1 -1
- package/invariantErrorCodes.js +1 -1
- package/link/core/types.d.ts +5 -6
- package/link/core/types.d.ts.map +1 -1
- package/link/core/types.js.map +1 -1
- package/package.json +12 -12
- package/testing/core/mocking/mockLink.d.ts +2 -2
- package/testing/core/mocking/mockLink.d.ts.map +1 -1
- package/testing/core/mocking/mockLink.js.map +1 -1
- package/utilities/observables/Concast.d.ts.map +1 -1
- package/utilities/observables/Concast.js +2 -2
- package/utilities/observables/Concast.js.map +1 -1
- package/utilities/utilities.cjs +2 -2
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +2 -2
- package/version.js +1 -1
package/core/core.cjs.native.js
CHANGED
|
@@ -15,7 +15,7 @@ var utils = require('../link/utils');
|
|
|
15
15
|
var tsInvariant = require('ts-invariant');
|
|
16
16
|
var graphqlTag = require('graphql-tag');
|
|
17
17
|
|
|
18
|
-
var version = '3.7.
|
|
18
|
+
var version = '3.7.8';
|
|
19
19
|
|
|
20
20
|
function isNonEmptyArray(value) {
|
|
21
21
|
return Array.isArray(value) && value.length > 0;
|
package/invariantErrorCodes.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// consult the @apollo/client/invariantErrorCodes.js file specific to
|
|
6
6
|
// your @apollo/client version. This file is not meant to be imported.
|
|
7
7
|
{
|
|
8
|
-
"@apollo/client version": "3.7.
|
|
8
|
+
"@apollo/client version": "3.7.8",
|
|
9
9
|
|
|
10
10
|
1: {
|
|
11
11
|
file: "@apollo/client/cache/inmemory/entityStore.js",
|
package/link/core/types.d.ts
CHANGED
|
@@ -3,18 +3,17 @@ import { DefaultContext } from "../../core";
|
|
|
3
3
|
export { DocumentNode };
|
|
4
4
|
import { Observable } from "../../utilities";
|
|
5
5
|
export type Path = ReadonlyArray<string | number>;
|
|
6
|
-
type Data<T> = T | null | undefined;
|
|
7
6
|
interface ExecutionPatchResultBase {
|
|
8
7
|
hasNext?: boolean;
|
|
9
8
|
}
|
|
10
9
|
export interface ExecutionPatchInitialResult<TData = Record<string, any>, TExtensions = Record<string, any>> extends ExecutionPatchResultBase {
|
|
11
|
-
data:
|
|
10
|
+
data: TData | null | undefined;
|
|
12
11
|
incremental?: never;
|
|
13
12
|
errors?: ReadonlyArray<GraphQLError>;
|
|
14
13
|
extensions?: TExtensions;
|
|
15
14
|
}
|
|
16
15
|
export interface IncrementalPayload<TData, TExtensions> {
|
|
17
|
-
data:
|
|
16
|
+
data: TData | null;
|
|
18
17
|
label?: string;
|
|
19
18
|
path: Path;
|
|
20
19
|
errors?: ReadonlyArray<GraphQLError>;
|
|
@@ -27,9 +26,9 @@ export interface ExecutionPatchIncrementalResult<TData = Record<string, any>, TE
|
|
|
27
26
|
extensions?: never;
|
|
28
27
|
}
|
|
29
28
|
export type ExecutionPatchResult<TData = Record<string, any>, TExtensions = Record<string, any>> = ExecutionPatchInitialResult<TData, TExtensions> | ExecutionPatchIncrementalResult<TData, TExtensions>;
|
|
30
|
-
export interface GraphQLRequest {
|
|
29
|
+
export interface GraphQLRequest<TVariables = Record<string, any>> {
|
|
31
30
|
query: DocumentNode;
|
|
32
|
-
variables?:
|
|
31
|
+
variables?: TVariables;
|
|
33
32
|
operationName?: string;
|
|
34
33
|
context?: DefaultContext;
|
|
35
34
|
extensions?: Record<string, any>;
|
|
@@ -43,7 +42,7 @@ export interface Operation {
|
|
|
43
42
|
getContext: () => DefaultContext;
|
|
44
43
|
}
|
|
45
44
|
export interface SingleExecutionResult<TData = Record<string, any>, TContext = DefaultContext, TExtensions = Record<string, any>> extends ExecutionResult<TData, TExtensions> {
|
|
46
|
-
data?:
|
|
45
|
+
data?: TData | null;
|
|
47
46
|
context?: TContext;
|
|
48
47
|
}
|
|
49
48
|
export type FetchResult<TData = Record<string, any>, TContext = Record<string, any>, TExtensions = Record<string, any>> = SingleExecutionResult<TData, TContext, TExtensions> | ExecutionPatchResult<TData, TExtensions>;
|
package/link/core/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/link/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,MAAM,MAAM,IAAI,GAAG,aAAa,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/link/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,MAAM,MAAM,IAAI,GAAG,aAAa,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;AAElD,UAAU,wBAAwB;IAChC,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,2BAA2B,CAC1C,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3B,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CACjC,SAAQ,wBAAwB;IAEhC,IAAI,EAAE,KAAK,GAAG,IAAI,GAAG,SAAS,CAAC;IAC/B,WAAW,CAAC,E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/types.ts"],"names":[],"mappings":"","sourcesContent":["import { DocumentNode, ExecutionResult, GraphQLError } from \"graphql\";\nimport { DefaultContext } from \"../../core\";\nexport { DocumentNode };\n\nimport { Observable } from \"../../utilities\";\n\nexport type Path = ReadonlyArray<string | number>;\
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/link/core/types.ts"],"names":[],"mappings":"","sourcesContent":["import { DocumentNode, ExecutionResult, GraphQLError } from \"graphql\";\nimport { DefaultContext } from \"../../core\";\nexport { DocumentNode };\n\nimport { Observable } from \"../../utilities\";\n\nexport type Path = ReadonlyArray<string | number>;\n\ninterface ExecutionPatchResultBase {\n hasNext?: boolean;\n}\n\nexport interface ExecutionPatchInitialResult<\n TData = Record<string, any>,\n TExtensions = Record<string, any>\n> extends ExecutionPatchResultBase {\n // if data is present, incremental is not\n data: TData | null | undefined;\n incremental?: never;\n errors?: ReadonlyArray<GraphQLError>;\n extensions?: TExtensions;\n}\n\nexport interface IncrementalPayload<\n TData,\n TExtensions,\n> {\n // data and path must both be present\n // https://github.com/graphql/graphql-spec/pull/742/files#diff-98d0cd153b72b63c417ad4238e8cc0d3385691ccbde7f7674bc0d2a718b896ecR288-R293\n data: TData | null;\n label?: string;\n path: Path;\n errors?: ReadonlyArray<GraphQLError>;\n extensions?: TExtensions;\n}\n\nexport interface ExecutionPatchIncrementalResult<\n TData = Record<string, any>,\n TExtensions = Record<string, any>\n> extends ExecutionPatchResultBase {\n // the reverse is also true: if incremental is present,\n // data (and errors and extensions) are not\n incremental?: IncrementalPayload<TData, TExtensions>[];\n data?: never;\n // Errors only exist for chunks, not at the top level\n // https://github.com/robrichard/defer-stream-wg/discussions/50#discussioncomment-3466739\n errors?: never;\n extensions?: never;\n}\n\nexport type ExecutionPatchResult<\n TData = Record<string, any>,\n TExtensions = Record<string, any>\n> =\n | ExecutionPatchInitialResult<TData, TExtensions>\n | ExecutionPatchIncrementalResult<TData, TExtensions>;\n\nexport interface GraphQLRequest<TVariables = Record<string, any>> {\n query: DocumentNode;\n variables?: TVariables;\n operationName?: string;\n context?: DefaultContext;\n extensions?: Record<string, any>;\n}\n\nexport interface Operation {\n query: DocumentNode;\n variables: Record<string, any>;\n operationName: string;\n extensions: Record<string, any>;\n setContext: (context: DefaultContext) => DefaultContext;\n getContext: () => DefaultContext;\n}\n\nexport interface SingleExecutionResult<\n TData = Record<string, any>,\n TContext = DefaultContext,\n TExtensions = Record<string, any>\n> extends ExecutionResult<TData, TExtensions> {\n data?: TData | null;\n context?: TContext;\n}\n\nexport type FetchResult<\n TData = Record<string, any>,\n TContext = Record<string, any>,\n TExtensions = Record<string, any>\n> =\n | SingleExecutionResult<TData, TContext, TExtensions>\n | ExecutionPatchResult<TData, TExtensions>;\n\nexport type NextLink = (operation: Operation) => Observable<FetchResult>;\n\nexport type RequestHandler = (\n operation: Operation,\n forward: NextLink\n) => Observable<FetchResult> | null;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apollo/client",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.8",
|
|
4
4
|
"description": "A fully-featured caching GraphQL client.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"keywords": [
|
|
@@ -66,10 +66,10 @@
|
|
|
66
66
|
"zen-observable-ts": "^1.2.5"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@babel/parser": "7.20.
|
|
69
|
+
"@babel/parser": "7.20.15",
|
|
70
70
|
"@changesets/changelog-github": "0.4.8",
|
|
71
71
|
"@changesets/cli": "2.26.0",
|
|
72
|
-
"@graphql-tools/schema": "9.0.
|
|
72
|
+
"@graphql-tools/schema": "9.0.16",
|
|
73
73
|
"@rollup/plugin-node-resolve": "11.2.1",
|
|
74
74
|
"@testing-library/react": "13.4.0",
|
|
75
75
|
"@testing-library/react-12": "npm:@testing-library/react@^12",
|
|
@@ -81,23 +81,23 @@
|
|
|
81
81
|
"@types/hoist-non-react-statics": "3.3.1",
|
|
82
82
|
"@types/jest": "29.2.6",
|
|
83
83
|
"@types/lodash": "4.14.191",
|
|
84
|
-
"@types/node": "18.
|
|
84
|
+
"@types/node": "18.13.0",
|
|
85
85
|
"@types/node-fetch": "2.6.2",
|
|
86
|
-
"@types/react": "18.0.
|
|
86
|
+
"@types/react": "18.0.28",
|
|
87
87
|
"@types/react-dom": "18.0.10",
|
|
88
88
|
"@types/use-sync-external-store": "0.0.3",
|
|
89
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
90
|
-
"@typescript-eslint/parser": "5.
|
|
89
|
+
"@typescript-eslint/eslint-plugin": "5.51.0",
|
|
90
|
+
"@typescript-eslint/parser": "5.51.0",
|
|
91
91
|
"acorn": "8.8.2",
|
|
92
92
|
"blob-polyfill": "7.0.20220408",
|
|
93
93
|
"bytes": "3.1.2",
|
|
94
94
|
"cross-fetch": "3.1.5",
|
|
95
|
-
"eslint": "8.
|
|
96
|
-
"eslint-plugin-testing-library": "5.10.
|
|
95
|
+
"eslint": "8.34.0",
|
|
96
|
+
"eslint-plugin-testing-library": "5.10.1",
|
|
97
97
|
"fetch-mock": "9.11.0",
|
|
98
98
|
"glob": "8.1.0",
|
|
99
99
|
"graphql": "16.6.0",
|
|
100
|
-
"graphql-ws": "5.11.
|
|
100
|
+
"graphql-ws": "5.11.3",
|
|
101
101
|
"jest": "29.3.1",
|
|
102
102
|
"jest-environment-jsdom": "29.3.1",
|
|
103
103
|
"jest-junit": "15.0.0",
|
|
@@ -114,11 +114,11 @@
|
|
|
114
114
|
"rollup-plugin-terser": "7.0.2",
|
|
115
115
|
"rxjs": "7.8.0",
|
|
116
116
|
"subscriptions-transport-ws": "0.11.0",
|
|
117
|
-
"terser": "5.16.
|
|
117
|
+
"terser": "5.16.3",
|
|
118
118
|
"ts-jest": "29.0.5",
|
|
119
119
|
"ts-node": "10.9.1",
|
|
120
120
|
"typedoc": "0.22.18",
|
|
121
|
-
"typescript": "4.9.
|
|
121
|
+
"typescript": "4.9.5",
|
|
122
122
|
"wait-for-observables": "1.0.3",
|
|
123
123
|
"web-streams-polyfill": "3.2.1",
|
|
124
124
|
"whatwg-fetch": "3.6.2"
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ApolloLink, Operation, GraphQLRequest, FetchResult } from '../../../link/core';
|
|
2
2
|
import { Observable } from '../../../utilities';
|
|
3
3
|
export type ResultFunction<T> = () => T;
|
|
4
|
-
export interface MockedResponse<TData = Record<string, any>> {
|
|
5
|
-
request: GraphQLRequest
|
|
4
|
+
export interface MockedResponse<TData = Record<string, any>, TVariables = Record<string, any>> {
|
|
5
|
+
request: GraphQLRequest<TVariables>;
|
|
6
6
|
result?: FetchResult<TData> | ResultFunction<FetchResult<TData>>;
|
|
7
7
|
error?: Error;
|
|
8
8
|
delay?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mockLink.d.ts","sourceRoot":"","sources":["../../../../src/testing/core/mocking/mockLink.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,UAAU,EACV,SAAS,EACT,cAAc,EACd,WAAW,EACZ,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,UAAU,EAMX,MAAM,oBAAoB,CAAC;AAE5B,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC;AAExC,MAAM,WAAW,cAAc,
|
|
1
|
+
{"version":3,"file":"mockLink.d.ts","sourceRoot":"","sources":["../../../../src/testing/core/mocking/mockLink.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,UAAU,EACV,SAAS,EACT,cAAc,EACd,WAAW,EACZ,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,UAAU,EAMX,MAAM,oBAAoB,CAAC;AAE5B,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC;AAExC,MAAM,WAAW,cAAc,CAC7B,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3B,UAAU,GAA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Ac;IAC5B,yBAA8B;SAA9B,UAA8B,EAA9B,qBAA8B,EAA9B,IAA8B;QAA9B,oCAA8B;;IAI9B,IAAI,aAAa,GAAG,eAAe,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAChE,IAAI,KAAK,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,EAAE,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAEjE,IAAI,OAAO,aAAa,KAAK,SAAS,EAAE;QACtC,KAAK,GAAG,eAAe,CAAC;QACxB,aAAa,GAAG,IAAI,CAAC;KACtB;IAED,OAAO,IAAI,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["import { invariant } from '../../../utilities/globals';\n\nimport { print } from 'graphql';\nimport { equal } from '@wry/equality';\n\nimport {\n ApolloLink,\n Operation,\n GraphQLRequest,\n FetchResult,\n} from '../../../link/core';\n\nimport {\n Observable,\n addTypenameToDocument,\n removeClientSetsFromDocument,\n removeConnectionDirectiveFromDocument,\n cloneDeep,\n stringifyForDisplay,\n} from '../../../utilities';\n\nexport type ResultFunction<T> = () => T;\n\nexport interface MockedResponse<TData = Record<string, any>> {\n request: GraphQLRequest;\n result?: FetchResult<TData> | ResultFunction<FetchResult<TData>>;\n error?: Error;\n delay?: number;\n newData?: ResultFunction<FetchResult>;\n}\n\nexport interface MockLinkOptions {\n showWarnings?: boolean;\n}\n\nfunction requestToKey(request: GraphQLRequest, addTypename: Boolean): string {\n const queryString =\n request.query &&\n print(addTypename ? addTypenameToDocument(request.query) : request.query);\n const requestKey = { query: queryString };\n return JSON.stringify(requestKey);\n}\n\nexport class MockLink extends ApolloLink {\n public operation: Operation;\n public addTypename: Boolean = true;\n public showWarnings: boolean = true;\n private mockedResponsesByKey: { [key: string]: MockedResponse[] } = {};\n\n constructor(\n mockedResponses: ReadonlyArray<MockedResponse>,\n addTypename: Boolean = true,\n options: MockLinkOptions = Object.create(null)\n ) {\n super();\n this.addTypename = addTypename;\n this.showWarnings = options.showWarnings ?? true;\n\n if (mockedResponses) {\n mockedResponses.forEach(mockedResponse => {\n this.addMockedResponse(mockedResponse);\n });\n }\n }\n\n public addMockedResponse(mockedResponse: MockedResponse) {\n const normalizedMockedResponse = this.normalizeMockedResponse(\n mockedResponse\n );\n const key = requestToKey(\n normalizedMockedResponse.request,\n this.addTypename\n );\n let mockedResponses = this.mockedResponsesByKey[key];\n if (!mockedResponses) {\n mockedResponses = [];\n this.mockedResponsesByKey[key] = mockedResponses;\n }\n mockedResponses.push(normalizedMockedResponse);\n }\n\n public request(operation: Operation): Observable<FetchResult> | null {\n this.operation = operation;\n const key = requestToKey(operation, this.addTypename);\n const unmatchedVars: Array<Record<string, any>> = [];\n const requestVariables = operation.variables || {};\n const mockedResponses = this.mockedResponsesByKey[key];\n const responseIndex = mockedResponses ? mockedResponses.findIndex((res, index) => {\n const mockedResponseVars = res.request.variables || {};\n if (equal(requestVariables, mockedResponseVars)) {\n return true;\n }\n unmatchedVars.push(mockedResponseVars);\n return false;\n }) : -1;\n\n const response = responseIndex >= 0\n ? mockedResponses[responseIndex]\n : void 0;\n\n let configError: Error;\n\n if (!response) {\n configError = new Error(\n`No more mocked responses for the query: ${print(operation.query)}\nExpected variables: ${stringifyForDisplay(operation.variables)}\n${unmatchedVars.length > 0 ? `\nFailed to match ${unmatchedVars.length} mock${\n unmatchedVars.length === 1 ? \"\" : \"s\"\n} for this query. The mocked response had the following variables:\n${unmatchedVars.map(d => ` ${stringifyForDisplay(d)}`).join('\\n')}\n` : \"\"}`);\n\n if (this.showWarnings) {\n console.warn(\n configError.message + \n '\\nThis typically indicates a configuration error in your mocks ' +\n 'setup, usually due to a typo or mismatched variable.'\n );\n }\n } else {\n mockedResponses.splice(responseIndex, 1);\n\n const { newData } = response;\n if (newData) {\n response.result = newData();\n mockedResponses.push(response);\n }\n\n if (!response.result && !response.error) {\n configError = new Error(\n `Mocked response should contain either result or error: ${key}`\n );\n }\n }\n\n return new Observable(observer => {\n const timer = setTimeout(() => {\n if (configError) {\n try {\n // The onError function can return false to indicate that\n // configError need not be passed to observer.error. For\n // example, the default implementation of onError calls\n // observer.error(configError) and then returns false to\n // prevent this extra (harmless) observer.error call.\n if (this.onError(configError, observer) !== false) {\n throw configError;\n }\n } catch (error) {\n observer.error(error);\n }\n } else if (response) {\n if (response.error) {\n observer.error(response.error);\n } else {\n if (response.result) {\n observer.next(\n typeof response.result === 'function'\n ? (response.result as ResultFunction<FetchResult>)()\n : response.result\n );\n }\n observer.complete();\n }\n }\n }, response && response.delay || 0);\n\n return () => {\n clearTimeout(timer);\n };\n });\n }\n\n private normalizeMockedResponse(\n mockedResponse: MockedResponse\n ): MockedResponse {\n const newMockedResponse = cloneDeep(mockedResponse);\n const queryWithoutConnection = removeConnectionDirectiveFromDocument(\n newMockedResponse.request.query\n );\n invariant(queryWithoutConnection, \"query is required\");\n newMockedResponse.request.query = queryWithoutConnection!;\n const query = removeClientSetsFromDocument(newMockedResponse.request.query);\n if (query) {\n newMockedResponse.request.query = query;\n }\n return newMockedResponse;\n }\n}\n\nexport interface MockApolloLink extends ApolloLink {\n operation?: Operation;\n}\n\n// Pass in multiple mocked responses, so that you can test flows that end up\n// making multiple queries to the server.\n// NOTE: The last arg can optionally be an `addTypename` arg.\nexport function mockSingleLink(\n ...mockedResponses: Array<any>\n): MockApolloLink {\n // To pull off the potential typename. If this isn't a boolean, we'll just\n // set it true later.\n let maybeTypename = mockedResponses[mockedResponses.length - 1];\n let mocks = mockedResponses.slice(0, mockedResponses.length - 1);\n\n if (typeof maybeTypename !== 'boolean') {\n mocks = mockedResponses;\n maybeTypename = true;\n }\n\n return new MockLink(mocks, maybeTypename);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mockLink.js","sourceRoot":"","sources":["../../../../src/testing/core/mocking/mockLink.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEvD,OAAO,EAAE,KAAK,EA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;IACH,eAAC;AAAD,CAAC,AAjJD,CAA8B,UAAU,GAiJvC;;AASD,MAAM,UAAU,cAAc;IAC5B,yBAA8B;SAA9B,UAA8B,EAA9B,qBAA8B,EAA9B,IAA8B;QAA9B,oCAA8B;;IAI9B,IAAI,aAAa,GAAG,eAAe,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAChE,IAAI,KAAK,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,EAAE,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAEjE,IAAI,OAAO,aAAa,KAAK,SAAS,EAAE;QACtC,KAAK,GAAG,eAAe,CAAC;QACxB,aAAa,GAAG,IAAI,CAAC;KACtB;IAED,OAAO,IAAI,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["import { invariant } from '../../../utilities/globals';\n\nimport { print } from 'graphql';\nimport { equal } from '@wry/equality';\n\nimport {\n ApolloLink,\n Operation,\n GraphQLRequest,\n FetchResult,\n} from '../../../link/core';\n\nimport {\n Observable,\n addTypenameToDocument,\n removeClientSetsFromDocument,\n removeConnectionDirectiveFromDocument,\n cloneDeep,\n stringifyForDisplay,\n} from '../../../utilities';\n\nexport type ResultFunction<T> = () => T;\n\nexport interface MockedResponse<\n TData = Record<string, any>,\n TVariables = Record<string, any>\n> {\n request: GraphQLRequest<TVariables>;\n result?: FetchResult<TData> | ResultFunction<FetchResult<TData>>;\n error?: Error;\n delay?: number;\n newData?: ResultFunction<FetchResult>;\n}\n\nexport interface MockLinkOptions {\n showWarnings?: boolean;\n}\n\nfunction requestToKey(request: GraphQLRequest, addTypename: Boolean): string {\n const queryString =\n request.query &&\n print(addTypename ? addTypenameToDocument(request.query) : request.query);\n const requestKey = { query: queryString };\n return JSON.stringify(requestKey);\n}\n\nexport class MockLink extends ApolloLink {\n public operation: Operation;\n public addTypename: Boolean = true;\n public showWarnings: boolean = true;\n private mockedResponsesByKey: { [key: string]: MockedResponse[] } = {};\n\n constructor(\n mockedResponses: ReadonlyArray<MockedResponse>,\n addTypename: Boolean = true,\n options: MockLinkOptions = Object.create(null)\n ) {\n super();\n this.addTypename = addTypename;\n this.showWarnings = options.showWarnings ?? true;\n\n if (mockedResponses) {\n mockedResponses.forEach(mockedResponse => {\n this.addMockedResponse(mockedResponse);\n });\n }\n }\n\n public addMockedResponse(mockedResponse: MockedResponse) {\n const normalizedMockedResponse = this.normalizeMockedResponse(\n mockedResponse\n );\n const key = requestToKey(\n normalizedMockedResponse.request,\n this.addTypename\n );\n let mockedResponses = this.mockedResponsesByKey[key];\n if (!mockedResponses) {\n mockedResponses = [];\n this.mockedResponsesByKey[key] = mockedResponses;\n }\n mockedResponses.push(normalizedMockedResponse);\n }\n\n public request(operation: Operation): Observable<FetchResult> | null {\n this.operation = operation;\n const key = requestToKey(operation, this.addTypename);\n const unmatchedVars: Array<Record<string, any>> = [];\n const requestVariables = operation.variables || {};\n const mockedResponses = this.mockedResponsesByKey[key];\n const responseIndex = mockedResponses ? mockedResponses.findIndex((res, index) => {\n const mockedResponseVars = res.request.variables || {};\n if (equal(requestVariables, mockedResponseVars)) {\n return true;\n }\n unmatchedVars.push(mockedResponseVars);\n return false;\n }) : -1;\n\n const response = responseIndex >= 0\n ? mockedResponses[responseIndex]\n : void 0;\n\n let configError: Error;\n\n if (!response) {\n configError = new Error(\n`No more mocked responses for the query: ${print(operation.query)}\nExpected variables: ${stringifyForDisplay(operation.variables)}\n${unmatchedVars.length > 0 ? `\nFailed to match ${unmatchedVars.length} mock${\n unmatchedVars.length === 1 ? \"\" : \"s\"\n} for this query. The mocked response had the following variables:\n${unmatchedVars.map(d => ` ${stringifyForDisplay(d)}`).join('\\n')}\n` : \"\"}`);\n\n if (this.showWarnings) {\n console.warn(\n configError.message + \n '\\nThis typically indicates a configuration error in your mocks ' +\n 'setup, usually due to a typo or mismatched variable.'\n );\n }\n } else {\n mockedResponses.splice(responseIndex, 1);\n\n const { newData } = response;\n if (newData) {\n response.result = newData();\n mockedResponses.push(response);\n }\n\n if (!response.result && !response.error) {\n configError = new Error(\n `Mocked response should contain either result or error: ${key}`\n );\n }\n }\n\n return new Observable(observer => {\n const timer = setTimeout(() => {\n if (configError) {\n try {\n // The onError function can return false to indicate that\n // configError need not be passed to observer.error. For\n // example, the default implementation of onError calls\n // observer.error(configError) and then returns false to\n // prevent this extra (harmless) observer.error call.\n if (this.onError(configError, observer) !== false) {\n throw configError;\n }\n } catch (error) {\n observer.error(error);\n }\n } else if (response) {\n if (response.error) {\n observer.error(response.error);\n } else {\n if (response.result) {\n observer.next(\n typeof response.result === 'function'\n ? (response.result as ResultFunction<FetchResult>)()\n : response.result\n );\n }\n observer.complete();\n }\n }\n }, response && response.delay || 0);\n\n return () => {\n clearTimeout(timer);\n };\n });\n }\n\n private normalizeMockedResponse(\n mockedResponse: MockedResponse\n ): MockedResponse {\n const newMockedResponse = cloneDeep(mockedResponse);\n const queryWithoutConnection = removeConnectionDirectiveFromDocument(\n newMockedResponse.request.query\n );\n invariant(queryWithoutConnection, \"query is required\");\n newMockedResponse.request.query = queryWithoutConnection!;\n const query = removeClientSetsFromDocument(newMockedResponse.request.query);\n if (query) {\n newMockedResponse.request.query = query;\n }\n return newMockedResponse;\n }\n}\n\nexport interface MockApolloLink extends ApolloLink {\n operation?: Operation;\n}\n\n// Pass in multiple mocked responses, so that you can test flows that end up\n// making multiple queries to the server.\n// NOTE: The last arg can optionally be an `addTypename` arg.\nexport function mockSingleLink(\n ...mockedResponses: Array<any>\n): MockApolloLink {\n // To pull off the potential typename. If this isn't a boolean, we'll just\n // set it true later.\n let maybeTypename = mockedResponses[mockedResponses.length - 1];\n let mocks = mockedResponses.slice(0, mockedResponses.length - 1);\n\n if (typeof maybeTypename !== 'boolean') {\n mocks = mockedResponses;\n maybeTypename = true;\n }\n\n return new MockLink(mocks, maybeTypename);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Concast.d.ts","sourceRoot":"","sources":["../../../src/utilities/observables/Concast.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAA0B,UAAU,EAAE,MAAM,cAAc,CAAC;AAIxF,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AAOxC,KAAK,MAAM,CAAC,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAE3C,MAAM,MAAM,sBAAsB,CAAC,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5D,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AA+BtD,qBAAa,OAAO,CAAC,CAAC,CAAE,SAAQ,UAAU,CAAC,CAAC,CAAC;IAI3C,OAAO,CAAC,SAAS,CAA0B;IAM3C,OAAO,CAAC,GAAG,CAAC,CAAgC;gBAIhC,OAAO,EAAE,UAAU,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"Concast.d.ts","sourceRoot":"","sources":["../../../src/utilities/observables/Concast.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAA0B,UAAU,EAAE,MAAM,cAAc,CAAC;AAIxF,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AAOxC,KAAK,MAAM,CAAC,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAE3C,MAAM,MAAM,sBAAsB,CAAC,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5D,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AA+BtD,qBAAa,OAAO,CAAC,CAAC,CAAE,SAAQ,UAAU,CAAC,CAAC,CAAC;IAI3C,OAAO,CAAC,SAAS,CAA0B;IAM3C,OAAO,CAAC,GAAG,CAAC,CAAgC;gBAIhC,OAAO,EAAE,UAAU,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;IAiC1E,OAAO,CAAC,OAAO,CAA0B;IAEzC,OAAO,CAAC,KAAK;IAeb,OAAO,CAAC,kBAAkB;IAkBnB,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;IASjC,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;IAgB3C,OAAO,CAAC,OAAO,CAAwC;IACvD,OAAO,CAAC,MAAM,CAAwB;IACtC,SAAgB,OAAO,aAGpB;IAIH,OAAO,CAAC,MAAM,CAAC,CAA+B;IAI9C,OAAO,CAAC,QAAQ,CAyDd;IAEF,OAAO,CAAC,mBAAmB,CAAiC;IAE5D,OAAO,CAAC,MAAM;IAmBd,UAAU,CAAC,QAAQ,EAAE,kBAAkB;IAWhC,MAAM,WAAY,GAAG,UAI3B;CACF;AAED,KAAK,kBAAkB,GAAG,CACxB,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,UAAU,EACrC,GAAG,CAAC,EAAE,GAAG,KACN,GAAG,CAAC"}
|
|
@@ -38,9 +38,9 @@ var Concast = (function (_super) {
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
complete: function () {
|
|
41
|
-
var sub =
|
|
41
|
+
var _a = _this, sub = _a.sub, _b = _a.sources, sources = _b === void 0 ? [] : _b;
|
|
42
42
|
if (sub !== null) {
|
|
43
|
-
var value =
|
|
43
|
+
var value = sources.shift();
|
|
44
44
|
if (!value) {
|
|
45
45
|
if (sub)
|
|
46
46
|
setTimeout(function () { return sub.unsubscribe(); });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Concast.js","sourceR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CAAC,GAAG,CAAC,UAAC,MAAM,EAAE,GAAG;YACvC,IAAI,CAAC,MAAM,EAAE;gBACX,MAAM,GAAG,IAAI,CAAC;gBACd,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;aACvB;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAQH,cAAC;AAAD,CAAC,AAhND,CAAgC,UAAU,GAgNzC;;AASD,qBAAqB,CAAC,OAAO,CAAC,CAAC","sourcesContent":["import { Observable, Observer, ObservableSubscription, Subscriber } from \"./Observable\";\nimport { iterateObserversSafely } from \"./iteration\";\nimport { fixObservableSubclass } from \"./subclassing\";\n\ntype MaybeAsync<T> = T | PromiseLike<T>;\n\nfunction isPromiseLike<T>(value: MaybeAsync<T>): value is PromiseLike<T> {\n return value && typeof (value as any).then === \"function\";\n}\n\n// Any individual Source<T> can be an Observable<T> or a promise for one.\ntype Source<T> = MaybeAsync<Observable<T>>;\n\nexport type ConcastSourcesIterable<T> = Iterable<Source<T>>;\nexport type ConcastSourcesArray<T> = Array<Source<T>>;\n\n// A Concast<T> observable concatenates the given sources into a single\n// non-overlapping sequence of Ts, automatically unwrapping any promises,\n// and broadcasts the T elements of that sequence to any number of\n// subscribers, all without creating a bunch of intermediary Observable\n// wrapper objects.\n//\n// Even though any number of observers can subscribe to the Concast, each\n// source observable is guaranteed to receive at most one subscribe call,\n// and the results are multicast to all observers.\n//\n// In addition to broadcasting every next/error message to this.observers,\n// the Concast stores the most recent message using this.latest, so any\n// new observers can immediately receive the latest message, even if it\n// was originally delivered in the past. This behavior means we can assume\n// every active observer in this.observers has received the same most\n// recent message.\n//\n// With the exception of this.latest replay, a Concast is a \"hot\"\n// observable in the sense that it does not replay past results from the\n// beginning of time for each new observer.\n//\n// Could we have used some existing RxJS class instead? Concast<T> is\n// similar to a BehaviorSubject<T>, because it is multicast and redelivers\n// the latest next/error message to new subscribers. Unlike Subject<T>,\n// Concast<T> does not expose an Observer<T> interface (this.handlers is\n// intentionally private), since Concast<T> gets its inputs from the\n// concatenated sources. If we ever switch to RxJS, there may be some\n// value in reusing their code, but for now we use zen-observable, which\n// does not contain any Subject implementations.\nexport class Concast<T> extends Observable<T> {\n // Active observers receiving broadcast messages. Thanks to this.latest,\n // we can assume all observers in this Set have received the same most\n // recent message, though possibly at different times in the past.\n private observers = new Set<Observer<T>>();\n\n // This property starts off undefined to indicate the initial\n // subscription has not yet begun, then points to each source\n // subscription in turn, and finally becomes null after the sources have\n // been exhausted. After that, it stays null.\n private sub?: ObservableSubscription | null;\n\n // Not only can the individual elements of the iterable be promises, but\n // also the iterable itself can be wrapped in a promise.\n constructor(sources: MaybeAsync<ConcastSourcesIterable<T>> | Subscriber<T>) {\n super(observer => {\n this.addObserver(observer);\n return () => this.removeObserver(observer);\n });\n\n // Suppress rejection warnings for this.promise, since it's perfectly\n // acceptable to pay no attention to this.promise if you're consuming\n // the results through the normal observable API.\n this.promise.catch(_ => {});\n\n // If someone accidentally tries to create a Concast using a subscriber\n // function, recover by creating an Observable from that subscriber and\n // using it as the source.\n if (typeof sources === \"function\") {\n sources = [new Observable(sources)];\n }\n\n if (isPromiseLike(sources)) {\n sources.then(\n iterable => this.start(iterable),\n this.handlers.error,\n );\n } else {\n this.start(sources);\n }\n }\n\n // A consumable array of source observables, incrementally consumed\n // each time this.handlers.complete is called.\n private sources: Source<T>[];\n\n private start(sources: ConcastSourcesIterable<T>) {\n if (this.sub !== void 0) return;\n\n // In practice, sources is most often simply an Array of observables.\n // TODO Consider using sources[Symbol.iterator]() to take advantage\n // of the laziness of non-Array iterables.\n this.sources = Array.from(sources);\n\n // Calling this.handlers.complete() kicks off consumption of the first\n // source observable. It's tempting to do this step lazily in\n // addObserver, but this.promise can be accessed without calling\n // addObserver, so consumption needs to begin eagerly.\n this.handlers.complete();\n }\n\n private deliverLastMessage(observer: Observer<T>) {\n if (this.latest) {\n const nextOrError = this.latest[0];\n const method = observer[nextOrError];\n if (method) {\n method.call(observer, this.latest[1]);\n }\n // If the subscription is already closed, and the last message was\n // a 'next' message, simulate delivery of the final 'complete'\n // message again.\n if (this.sub === null &&\n nextOrError === \"next\" &&\n observer.complete) {\n observer.complete();\n }\n }\n }\n\n public addObserver(observer: Observer<T>) {\n if (!this.observers.has(observer)) {\n // Immediately deliver the most recent message, so we can always\n // be sure all observers have the latest information.\n this.deliverLastMessage(observer);\n this.observers.add(observer);\n }\n }\n\n public removeObserver(observer: Observer<T>) {\n if (\n this.observers.delete(observer) &&\n this.observers.size < 1\n ) {\n // In case there are still any listeners in this.nextResultListeners, and\n // no error or completion has been broadcast yet, make sure those\n // observers have a chance to run and then remove themselves from\n // this.observers.\n this.handlers.complete();\n }\n }\n\n // Any Concast object can be trivially converted to a Promise, without\n // having to create a new wrapper Observable. This promise provides an\n // easy way to observe the final state of the Concast.\n private resolve: (result?: T | PromiseLike<T>) => void;\n private reject: (reason: any) => void;\n public readonly promise = new Promise<T>((resolve, reject) => {\n this.resolve = resolve;\n this.reject = reject;\n });\n\n // Name and argument of the most recently invoked observer method, used\n // to deliver latest results immediately to new observers.\n private latest?: [\"next\", T] | [\"error\", any];\n\n // Bound handler functions that can be reused for every internal\n // subscription.\n private handlers = {\n next: (result: T) => {\n if (this.sub !== null) {\n this.latest = [\"next\", result];\n this.notify(\"next\", result);\n iterateObserversSafely(this.observers, \"next\", result);\n }\n },\n\n error: (error: any) => {\n const { sub } = this;\n if (sub !== null) {\n // Delay unsubscribing from the underlying subscription slightly,\n // so that immediately subscribing another observer can keep the\n // subscription active.\n if (sub) setTimeout(() => sub.unsubscribe());\n this.sub = null;\n this.latest = [\"error\", error];\n this.reject(error);\n this.notify(\"error\", error);\n iterateObserversSafely(this.observers, \"error\", error);\n }\n },\n\n complete: () => {\n const { sub } = this;\n if (sub !== null) {\n const value = this.sources.shift();\n if (!value) {\n if (sub) setTimeout(() => sub.unsubscribe());\n this.sub = null;\n if (this.latest &&\n this.latest[0] === \"next\") {\n this.resolve(this.latest[1]);\n } else {\n this.resolve();\n }\n this.notify(\"complete\");\n // We do not store this.latest = [\"complete\"], because doing so\n // discards useful information about the previous next (or\n // error) message. Instead, if new observers subscribe after\n // this Concast has completed, they will receive the final\n // 'next' message (unless there was an error) immediately\n // followed by a 'complete' message (see addObserver).\n iterateObserversSafely(this.observers, \"complete\");\n } else if (isPromiseLike(value)) {\n value.then(obs => this.sub = obs.subscribe(this.handlers));\n } else {\n this.sub = value.subscribe(this.handlers);\n }\n }\n },\n };\n\n private nextResultListeners = new Set<NextResultListener>();\n\n private notify(\n method: Parameters<NextResultListener>[0],\n arg?: Parameters<NextResultListener>[1],\n ) {\n const { nextResultListeners } = this;\n if (nextResultListeners.size) {\n // Replacing this.nextResultListeners first ensures it does not grow while\n // we are iterating over it, potentially leading to infinite loops.\n this.nextResultListeners = new Set;\n nextResultListeners.forEach(listener => listener(method, arg));\n }\n }\n\n // We need a way to run callbacks just *before* the next result (or error or\n // completion) is delivered by this Concast, so we can be sure any code that\n // runs as a result of delivering that result/error observes the effects of\n // running the callback(s). It was tempting to reuse the Observer type instead\n // of introducing NextResultListener, but that messes with the sizing and\n // maintenance of this.observers, and ends up being more code overall.\n beforeNext(callback: NextResultListener) {\n let called = false;\n this.nextResultListeners.add((method, arg) => {\n if (!called) {\n called = true;\n callback(method, arg);\n }\n });\n }\n\n // A public way to abort observation and broadcast.\n public cancel = (reason: any) => {\n this.reject(reason);\n this.sources = [];\n this.handlers.complete();\n }\n}\n\ntype NextResultListener = (\n method: \"next\" | \"error\" | \"complete\",\n arg?: any,\n) => any;\n\n// Necessary because the Concast constructor has a different signature\n// than the Observable constructor.\nfixObservableSubclass(Concast);\n"]}
|
|
1
|
+
{"version":3,"file":"Concast.js","sourceRoot":"","sources":["../../../src/utilities/observables/Concast.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAgD,MAAM,cAAc,CAAC;AACxF,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;A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QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAQH,cAAC;AAAD,CAAC,AAxND,CAAgC,UAAU,GAwNzC;;AASD,qBAAqB,CAAC,OAAO,CAAC,CAAC","sourcesContent":["import { Observable, Observer, ObservableSubscription, Subscriber } from \"./Observable\";\nimport { iterateObserversSafely } from \"./iteration\";\nimport { fixObservableSubclass } from \"./subclassing\";\n\ntype MaybeAsync<T> = T | PromiseLike<T>;\n\nfunction isPromiseLike<T>(value: MaybeAsync<T>): value is PromiseLike<T> {\n return value && typeof (value as any).then === \"function\";\n}\n\n// Any individual Source<T> can be an Observable<T> or a promise for one.\ntype Source<T> = MaybeAsync<Observable<T>>;\n\nexport type ConcastSourcesIterable<T> = Iterable<Source<T>>;\nexport type ConcastSourcesArray<T> = Array<Source<T>>;\n\n// A Concast<T> observable concatenates the given sources into a single\n// non-overlapping sequence of Ts, automatically unwrapping any promises,\n// and broadcasts the T elements of that sequence to any number of\n// subscribers, all without creating a bunch of intermediary Observable\n// wrapper objects.\n//\n// Even though any number of observers can subscribe to the Concast, each\n// source observable is guaranteed to receive at most one subscribe call,\n// and the results are multicast to all observers.\n//\n// In addition to broadcasting every next/error message to this.observers,\n// the Concast stores the most recent message using this.latest, so any\n// new observers can immediately receive the latest message, even if it\n// was originally delivered in the past. This behavior means we can assume\n// every active observer in this.observers has received the same most\n// recent message.\n//\n// With the exception of this.latest replay, a Concast is a \"hot\"\n// observable in the sense that it does not replay past results from the\n// beginning of time for each new observer.\n//\n// Could we have used some existing RxJS class instead? Concast<T> is\n// similar to a BehaviorSubject<T>, because it is multicast and redelivers\n// the latest next/error message to new subscribers. Unlike Subject<T>,\n// Concast<T> does not expose an Observer<T> interface (this.handlers is\n// intentionally private), since Concast<T> gets its inputs from the\n// concatenated sources. If we ever switch to RxJS, there may be some\n// value in reusing their code, but for now we use zen-observable, which\n// does not contain any Subject implementations.\nexport class Concast<T> extends Observable<T> {\n // Active observers receiving broadcast messages. Thanks to this.latest,\n // we can assume all observers in this Set have received the same most\n // recent message, though possibly at different times in the past.\n private observers = new Set<Observer<T>>();\n\n // This property starts off undefined to indicate the initial\n // subscription has not yet begun, then points to each source\n // subscription in turn, and finally becomes null after the sources have\n // been exhausted. After that, it stays null.\n private sub?: ObservableSubscription | null;\n\n // Not only can the individual elements of the iterable be promises, but\n // also the iterable itself can be wrapped in a promise.\n constructor(sources: MaybeAsync<ConcastSourcesIterable<T>> | Subscriber<T>) {\n super(observer => {\n this.addObserver(observer);\n return () => this.removeObserver(observer);\n });\n\n // Suppress rejection warnings for this.promise, since it's perfectly\n // acceptable to pay no attention to this.promise if you're consuming\n // the results through the normal observable API.\n this.promise.catch(_ => {});\n\n // If someone accidentally tries to create a Concast using a subscriber\n // function, recover by creating an Observable from that subscriber and\n // using it as the source.\n if (typeof sources === \"function\") {\n sources = [new Observable(sources)];\n }\n\n if (isPromiseLike(sources)) {\n sources.then(\n iterable => this.start(iterable),\n this.handlers.error,\n );\n } else {\n this.start(sources);\n }\n }\n\n // A consumable array of source observables, incrementally consumed each time\n // this.handlers.complete is called. This private field is not initialized\n // until the concast.start method is called, which can happen asynchronously\n // if a Promise is passed to the Concast constructor, so undefined is a\n // possible value for this.sources before concast.start is called.\n private sources: Source<T>[] | undefined;\n\n private start(sources: ConcastSourcesIterable<T>) {\n if (this.sub !== void 0) return;\n\n // In practice, sources is most often simply an Array of observables.\n // TODO Consider using sources[Symbol.iterator]() to take advantage\n // of the laziness of non-Array iterables.\n this.sources = Array.from(sources);\n\n // Calling this.handlers.complete() kicks off consumption of the first\n // source observable. It's tempting to do this step lazily in\n // addObserver, but this.promise can be accessed without calling\n // addObserver, so consumption needs to begin eagerly.\n this.handlers.complete();\n }\n\n private deliverLastMessage(observer: Observer<T>) {\n if (this.latest) {\n const nextOrError = this.latest[0];\n const method = observer[nextOrError];\n if (method) {\n method.call(observer, this.latest[1]);\n }\n // If the subscription is already closed, and the last message was\n // a 'next' message, simulate delivery of the final 'complete'\n // message again.\n if (this.sub === null &&\n nextOrError === \"next\" &&\n observer.complete) {\n observer.complete();\n }\n }\n }\n\n public addObserver(observer: Observer<T>) {\n if (!this.observers.has(observer)) {\n // Immediately deliver the most recent message, so we can always\n // be sure all observers have the latest information.\n this.deliverLastMessage(observer);\n this.observers.add(observer);\n }\n }\n\n public removeObserver(observer: Observer<T>) {\n if (\n this.observers.delete(observer) &&\n this.observers.size < 1\n ) {\n // In case there are still any listeners in this.nextResultListeners, and\n // no error or completion has been broadcast yet, make sure those\n // observers have a chance to run and then remove themselves from\n // this.observers.\n this.handlers.complete();\n }\n }\n\n // Any Concast object can be trivially converted to a Promise, without\n // having to create a new wrapper Observable. This promise provides an\n // easy way to observe the final state of the Concast.\n private resolve: (result?: T | PromiseLike<T>) => void;\n private reject: (reason: any) => void;\n public readonly promise = new Promise<T>((resolve, reject) => {\n this.resolve = resolve;\n this.reject = reject;\n });\n\n // Name and argument of the most recently invoked observer method, used\n // to deliver latest results immediately to new observers.\n private latest?: [\"next\", T] | [\"error\", any];\n\n // Bound handler functions that can be reused for every internal\n // subscription.\n private handlers = {\n next: (result: T) => {\n if (this.sub !== null) {\n this.latest = [\"next\", result];\n this.notify(\"next\", result);\n iterateObserversSafely(this.observers, \"next\", result);\n }\n },\n\n error: (error: any) => {\n const { sub } = this;\n if (sub !== null) {\n // Delay unsubscribing from the underlying subscription slightly,\n // so that immediately subscribing another observer can keep the\n // subscription active.\n if (sub) setTimeout(() => sub.unsubscribe());\n this.sub = null;\n this.latest = [\"error\", error];\n this.reject(error);\n this.notify(\"error\", error);\n iterateObserversSafely(this.observers, \"error\", error);\n }\n },\n\n complete: () => {\n const { sub, sources = [] } = this;\n if (sub !== null) {\n // If complete is called before concast.start, this.sources may be\n // undefined, so we use a default value of [] for sources. That works\n // here because it falls into the if (!value) {...} block, which\n // appropriately terminates the Concast, even if this.sources might\n // eventually have been initialized to a non-empty array.\n const value = sources.shift();\n if (!value) {\n if (sub) setTimeout(() => sub.unsubscribe());\n this.sub = null;\n if (this.latest &&\n this.latest[0] === \"next\") {\n this.resolve(this.latest[1]);\n } else {\n this.resolve();\n }\n this.notify(\"complete\");\n // We do not store this.latest = [\"complete\"], because doing so\n // discards useful information about the previous next (or\n // error) message. Instead, if new observers subscribe after\n // this Concast has completed, they will receive the final\n // 'next' message (unless there was an error) immediately\n // followed by a 'complete' message (see addObserver).\n iterateObserversSafely(this.observers, \"complete\");\n } else if (isPromiseLike(value)) {\n value.then(obs => this.sub = obs.subscribe(this.handlers));\n } else {\n this.sub = value.subscribe(this.handlers);\n }\n }\n },\n };\n\n private nextResultListeners = new Set<NextResultListener>();\n\n private notify(\n method: Parameters<NextResultListener>[0],\n arg?: Parameters<NextResultListener>[1],\n ) {\n const { nextResultListeners } = this;\n if (nextResultListeners.size) {\n // Replacing this.nextResultListeners first ensures it does not grow while\n // we are iterating over it, potentially leading to infinite loops.\n this.nextResultListeners = new Set;\n nextResultListeners.forEach(listener => listener(method, arg));\n }\n }\n\n // We need a way to run callbacks just *before* the next result (or error or\n // completion) is delivered by this Concast, so we can be sure any code that\n // runs as a result of delivering that result/error observes the effects of\n // running the callback(s). It was tempting to reuse the Observer type instead\n // of introducing NextResultListener, but that messes with the sizing and\n // maintenance of this.observers, and ends up being more code overall.\n beforeNext(callback: NextResultListener) {\n let called = false;\n this.nextResultListeners.add((method, arg) => {\n if (!called) {\n called = true;\n callback(method, arg);\n }\n });\n }\n\n // A public way to abort observation and broadcast.\n public cancel = (reason: any) => {\n this.reject(reason);\n this.sources = [];\n this.handlers.complete();\n }\n}\n\ntype NextResultListener = (\n method: \"next\" | \"error\" | \"complete\",\n arg?: any,\n) => any;\n\n// Necessary because the Concast constructor has a different signature\n// than the Observable constructor.\nfixObservableSubclass(Concast);\n"]}
|
package/utilities/utilities.cjs
CHANGED
|
@@ -1085,9 +1085,9 @@ var Concast = (function (_super) {
|
|
|
1085
1085
|
}
|
|
1086
1086
|
},
|
|
1087
1087
|
complete: function () {
|
|
1088
|
-
var sub =
|
|
1088
|
+
var _a = _this, sub = _a.sub, _b = _a.sources, sources = _b === void 0 ? [] : _b;
|
|
1089
1089
|
if (sub !== null) {
|
|
1090
|
-
var value =
|
|
1090
|
+
var value = sources.shift();
|
|
1091
1091
|
if (!value) {
|
|
1092
1092
|
if (sub)
|
|
1093
1093
|
setTimeout(function () { return sub.unsubscribe(); });
|