urql-computed-exchange-plus 1.0.3

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.
Files changed (64) hide show
  1. package/.editorconfig +9 -0
  2. package/.eslintrc.js +58 -0
  3. package/.importsortrc +6 -0
  4. package/.prettierrc +12 -0
  5. package/CHANGELOG.md +50 -0
  6. package/LICENSE +24 -0
  7. package/README.md +367 -0
  8. package/jest.config.js +19 -0
  9. package/jest.integration.config.js +14 -0
  10. package/jest.performance.config.js +19 -0
  11. package/lib/async-computed.d.ts +16 -0
  12. package/lib/async-computed.js +68 -0
  13. package/lib/async-computed.js.map +1 -0
  14. package/lib/computed-exchange.d.ts +5 -0
  15. package/lib/computed-exchange.js +24 -0
  16. package/lib/computed-exchange.js.map +1 -0
  17. package/lib/create-entity.d.ts +2 -0
  18. package/lib/create-entity.js +7 -0
  19. package/lib/create-entity.js.map +1 -0
  20. package/lib/create-modern-entity.d.ts +2 -0
  21. package/lib/create-modern-entity.js +10 -0
  22. package/lib/create-modern-entity.js.map +1 -0
  23. package/lib/directive-utils.d.ts +6 -0
  24. package/lib/directive-utils.js +125 -0
  25. package/lib/directive-utils.js.map +1 -0
  26. package/lib/index.d.ts +6 -0
  27. package/lib/index.js +23 -0
  28. package/lib/index.js.map +1 -0
  29. package/lib/merge-entities.d.ts +2 -0
  30. package/lib/merge-entities.js +35 -0
  31. package/lib/merge-entities.js.map +1 -0
  32. package/lib/resolve-data.d.ts +2 -0
  33. package/lib/resolve-data.js +152 -0
  34. package/lib/resolve-data.js.map +1 -0
  35. package/lib/set-utils.d.ts +5 -0
  36. package/lib/set-utils.js +27 -0
  37. package/lib/set-utils.js.map +1 -0
  38. package/lib/tsconfig.tsbuildinfo +1 -0
  39. package/lib/types/augmented-operation-result.d.ts +6 -0
  40. package/lib/types/augmented-operation-result.js +3 -0
  41. package/lib/types/augmented-operation-result.js.map +1 -0
  42. package/lib/types/augmented-operation.d.ts +6 -0
  43. package/lib/types/augmented-operation.js +3 -0
  44. package/lib/types/augmented-operation.js.map +1 -0
  45. package/lib/types/entity.d.ts +13 -0
  46. package/lib/types/entity.js +3 -0
  47. package/lib/types/entity.js.map +1 -0
  48. package/lib/types/index.d.ts +4 -0
  49. package/lib/types/index.js +21 -0
  50. package/lib/types/index.js.map +1 -0
  51. package/lib/types/node-with-directives.d.ts +2 -0
  52. package/lib/types/node-with-directives.js +3 -0
  53. package/lib/types/node-with-directives.js.map +1 -0
  54. package/lib/types.d.ts +68 -0
  55. package/lib/types.js +18 -0
  56. package/lib/types.js.map +1 -0
  57. package/package.json +77 -0
  58. package/test/integration/computed-exchange.test.ts +541 -0
  59. package/test/performance/large-dataset.test.ts +66 -0
  60. package/test/utils/index.ts +2 -0
  61. package/test/utils/run-query.ts +15 -0
  62. package/test/utils/simple-mock-fetch.ts +75 -0
  63. package/tsconfig.build.json +4 -0
  64. package/tsconfig.json +29 -0
@@ -0,0 +1,75 @@
1
+ type HTTPMethod = 'GET' | 'POST';
2
+ type ResponseFunction = (data?: any) => Partial<Response>;
3
+ type MockResponse = Partial<Response> | ResponseFunction;
4
+ type Mappings = {
5
+ [K in HTTPMethod]?: Record<string, MockResponse>;
6
+ };
7
+
8
+ function mergeMappings(mappingsA: Mappings, mappingsB: Mappings): Mappings {
9
+ return {
10
+ GET: { ...mappingsA.GET, ...mappingsB.GET },
11
+ POST: { ...mappingsA.POST, ...mappingsB.POST },
12
+ };
13
+ }
14
+
15
+ function createMapping(method: HTTPMethod, url: string, response: MockResponse) {
16
+ return { [method]: { [url]: response } };
17
+ }
18
+
19
+ class SimpleMockFetch {
20
+ constructor(private readonly mappings: Mappings = {}) {}
21
+
22
+ post(url: string, response: MockResponse) {
23
+ return new SimpleMockFetch(mergeMappings(this.mappings, createMapping('POST', url, response)));
24
+ }
25
+
26
+ get(url: string, response: MockResponse) {
27
+ return new SimpleMockFetch(mergeMappings(this.mappings, createMapping('GET', url, response)));
28
+ }
29
+
30
+ build(): typeof fetch {
31
+ const mockFetch = async (input: string | URL | Request, init: RequestInit = {}) => {
32
+ if (typeof input !== 'string') {
33
+ throw new Error('Unimplemented behavior.');
34
+ }
35
+
36
+ const method: HTTPMethod = (init.method as HTTPMethod) ?? 'GET';
37
+ const url = input;
38
+
39
+ const response = this.getResponse(method as HTTPMethod, url);
40
+
41
+ if (method === 'POST') {
42
+ const result = typeof response === 'function' ? response(init.body) : response;
43
+ const jsonData = result.json ? await result.json() : result;
44
+ return new Response(JSON.stringify(jsonData), {
45
+ status: result.status || 200,
46
+ headers: { 'content-type': 'application/json' },
47
+ });
48
+ } else {
49
+ const result = typeof response === 'function' ? response() : response;
50
+ const jsonData = result.json ? await result.json() : result;
51
+ return new Response(JSON.stringify(jsonData), {
52
+ status: result.status || 200,
53
+ headers: { 'content-type': 'application/json' },
54
+ });
55
+ }
56
+ };
57
+
58
+ return mockFetch as typeof fetch;
59
+ }
60
+
61
+ private getResponse(method: HTTPMethod, url: string): MockResponse {
62
+ const methodMappings = this.mappings[method] ?? {};
63
+ const mockResponse = methodMappings[url];
64
+
65
+ if (mockResponse == null) {
66
+ throw new Error(`Mock response not found (method: ${method}, url: ${url}).`);
67
+ }
68
+
69
+ return mockResponse;
70
+ }
71
+ }
72
+
73
+ export function createMockFetch() {
74
+ return new SimpleMockFetch();
75
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
4
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "compilerOptions": {
3
+ // Checking
4
+ "noUnusedLocals": true,
5
+ "noUnusedParameters": true,
6
+ "strict": true,
7
+ // Resolution
8
+ "moduleResolution": "node",
9
+ "esModuleInterop": true,
10
+ "allowSyntheticDefaultImports": true,
11
+ "baseUrl": "./",
12
+ // Compilation
13
+ "jsx": "preserve",
14
+ "declaration": true,
15
+ "removeComments": true,
16
+ "emitDecoratorMetadata": true,
17
+ "experimentalDecorators": true,
18
+ "target": "ES2020",
19
+ "module": "commonjs",
20
+ "lib": ["ES2020"],
21
+ "sourceMap": true,
22
+ "incremental": true,
23
+ "outDir": "./lib",
24
+ "skipLibCheck": true,
25
+ "forceConsistentCasingInFileNames": true
26
+ },
27
+ "include": ["./src/**/*"],
28
+ "exclude": ["node_modules", "lib", "**/*.test.ts"]
29
+ }