@webiny/app 6.6.0-alpha.1 → 6.6.0-alpha.10
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/App.js +6 -1
- package/App.js.map +1 -1
- package/components/Image.d.ts +1 -1
- package/errors/GraphQLOperationError.d.ts +10 -0
- package/errors/GraphQLOperationError.js +11 -0
- package/errors/GraphQLOperationError.js.map +1 -0
- package/errors/__tests__/GraphQLOperationError.test.d.ts +1 -0
- package/errors/__tests__/GraphQLOperationError.test.js +97 -0
- package/errors/__tests__/GraphQLOperationError.test.js.map +1 -0
- package/errors/index.d.ts +2 -0
- package/errors/index.js +1 -0
- package/exports/admin.d.ts +2 -0
- package/exports/admin.js +2 -0
- package/features/apiRequestHeaders/ApiRequestHeadersResolver.d.ts +13 -0
- package/features/apiRequestHeaders/ApiRequestHeadersResolver.js +15 -0
- package/features/apiRequestHeaders/ApiRequestHeadersResolver.js.map +1 -0
- package/features/apiRequestHeaders/ApiStreamClientDecorator.d.ts +12 -0
- package/features/apiRequestHeaders/ApiStreamClientDecorator.js +25 -0
- package/features/apiRequestHeaders/ApiStreamClientDecorator.js.map +1 -0
- package/features/apiRequestHeaders/GraphQLClientDecorator.d.ts +12 -0
- package/features/apiRequestHeaders/GraphQLClientDecorator.js +25 -0
- package/features/apiRequestHeaders/GraphQLClientDecorator.js.map +1 -0
- package/features/apiRequestHeaders/__tests__/ApiRequestHeaders.test.d.ts +1 -0
- package/features/apiRequestHeaders/__tests__/ApiRequestHeaders.test.js +199 -0
- package/features/apiRequestHeaders/__tests__/ApiRequestHeaders.test.js.map +1 -0
- package/features/apiRequestHeaders/abstractions.d.ts +26 -0
- package/features/apiRequestHeaders/abstractions.js +6 -0
- package/features/apiRequestHeaders/abstractions.js.map +1 -0
- package/features/apiRequestHeaders/feature.d.ts +6 -0
- package/features/apiRequestHeaders/feature.js +16 -0
- package/features/apiRequestHeaders/feature.js.map +1 -0
- package/features/apiRequestHeaders/index.d.ts +2 -0
- package/features/apiRequestHeaders/index.js +2 -0
- package/features/apiRequestHeaders/mergeHeaders.d.ts +13 -0
- package/features/apiRequestHeaders/mergeHeaders.js +20 -0
- package/features/apiRequestHeaders/mergeHeaders.js.map +1 -0
- package/features/graphqlClient/BatchingGraphQLClient.d.ts +3 -1
- package/features/graphqlClient/BatchingGraphQLClient.js +13 -3
- package/features/graphqlClient/BatchingGraphQLClient.js.map +1 -1
- package/features/graphqlClient/FetchGraphQLClient.d.ts +3 -0
- package/features/graphqlClient/FetchGraphQLClient.js +18 -4
- package/features/graphqlClient/FetchGraphQLClient.js.map +1 -1
- package/features/graphqlClient/GraphQLExtensionsEvent.d.ts +18 -0
- package/features/graphqlClient/GraphQLExtensionsEvent.js +13 -0
- package/features/graphqlClient/GraphQLExtensionsEvent.js.map +1 -0
- package/features/graphqlClient/__tests__/GraphQLClient.test.js +202 -0
- package/features/graphqlClient/__tests__/GraphQLClient.test.js.map +1 -1
- package/features/graphqlClient/abstractions.d.ts +7 -0
- package/features/graphqlClient/abstractions.js +2 -1
- package/features/graphqlClient/abstractions.js.map +1 -1
- package/features/graphqlClient/index.d.ts +3 -0
- package/features/graphqlClient/index.js +2 -1
- package/features/graphqlClient/publishExtensions.d.ts +13 -0
- package/features/graphqlClient/publishExtensions.js +16 -0
- package/features/graphqlClient/publishExtensions.js.map +1 -0
- package/features/router/HistoryRouterGateway.test.js +68 -0
- package/features/router/HistoryRouterGateway.test.js.map +1 -1
- package/features/router/Router.d.ts +9 -2
- package/features/router/Router.js +4 -5
- package/features/router/Router.js.map +1 -1
- package/package.json +17 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/graphqlClient/__tests__/GraphQLClient.test.js","sources":["../../../../src/features/graphqlClient/__tests__/GraphQLClient.test.ts"],"sourcesContent":["import { describe, it, expect, vi, beforeEach } from \"vitest\";\nimport { Container } from \"@webiny/di\";\nimport { GraphQLClient } from \"../abstractions.js\";\nimport { FetchGraphQLClient } from \"../FetchGraphQLClient.js\";\nimport { BatchingGraphQLClient } from \"../BatchingGraphQLClient.js\";\nimport { RetryGraphQLClient } from \"../RetryGraphQLClient.js\";\nimport { EnvConfig } from \"~/features/envConfig/index.js\";\n\ndescribe(\"GraphQLClient Feature\", () => {\n let container: Container;\n let mockEnvConfig: EnvConfig.Interface;\n\n beforeEach(() => {\n container = new Container();\n\n mockEnvConfig = {\n get: vi.fn((key: string) => {\n if (key === \"graphqlApiUrl\") {\n return \"https://api.example.com/graphql\";\n }\n return undefined;\n })\n } as any;\n\n container.registerInstance(EnvConfig, mockEnvConfig);\n });\n\n describe(\"FetchGraphQLClient\", () => {\n beforeEach(() => {\n container.register(FetchGraphQLClient).inSingletonScope();\n });\n\n it(\"should execute a query successfully\", async () => {\n const mockResponse = {\n data: { user: { id: \"1\", name: \"John\" } }\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetUser { user { id name } }\"\n });\n\n expect(result).toEqual(mockResponse.data);\n expect(global.fetch).toHaveBeenCalledWith(\n \"https://api.example.com/graphql\",\n expect.objectContaining({\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" }\n })\n );\n });\n\n it(\"should execute a mutation successfully\", async () => {\n const mockResponse = {\n data: { createUser: { id: \"2\", name: \"Jane\" } }\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"mutation CreateUser($name: String!) { createUser(name: $name) { id name } }\",\n variables: { name: \"Jane\" }\n });\n\n expect(result).toEqual(mockResponse.data);\n });\n\n it(\"should include custom headers\", async () => {\n const mockResponse = { data: { user: { id: \"1\" } } };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n await client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetUser { user { id } }\",\n headers: { \"x-tenant\": \"root\", Authorization: \"Bearer token\" }\n });\n\n expect(global.fetch).toHaveBeenCalledWith(\n \"https://api.example.com/graphql\",\n expect.objectContaining({\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-tenant\": \"root\",\n Authorization: \"Bearer token\"\n }\n })\n );\n });\n\n it(\"should throw on network error\", async () => {\n global.fetch = vi.fn().mockRejectedValue(new Error(\"Network failure\"));\n\n const client = container.resolve(GraphQLClient);\n\n await expect(\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n })\n ).rejects.toThrow(\"Network error: Network failure\");\n });\n\n it(\"should throw on GraphQL errors\", async () => {\n const mockResponse = {\n errors: [{ message: \"User not found\" }],\n data: null\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n await expect(\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n })\n ).rejects.toThrow(\"GraphQL errors\");\n });\n\n it(\"should throw on invalid JSON response\", async () => {\n global.fetch = vi.fn().mockResolvedValue({\n json: async () => {\n throw new Error(\"Invalid JSON\");\n }\n });\n\n const client = container.resolve(GraphQLClient);\n\n await expect(\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n })\n ).rejects.toThrow(\"Failed to parse GraphQL response as JSON\");\n });\n });\n\n describe(\"BatchingGraphQLClient\", () => {\n beforeEach(() => {\n container.register(FetchGraphQLClient).inSingletonScope();\n container.registerDecorator(BatchingGraphQLClient);\n });\n\n it(\"should batch multiple requests within the batch window\", async () => {\n const mockResponse = [\n { data: { user: { id: \"1\", name: \"John\" } } },\n { data: { post: { id: \"2\", title: \"Hello\" } } }\n ];\n\n global.fetch = vi.fn().mockResolvedValue({\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n const [result1, result2] = await Promise.all([\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetUser { user { id name } }\"\n }),\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetPost { post { id title } }\"\n })\n ]);\n\n expect(result1).toEqual(mockResponse[0].data);\n expect(result2).toEqual(mockResponse[1].data);\n expect(global.fetch).toHaveBeenCalledTimes(1);\n\n const callBody = JSON.parse((global.fetch as any).mock.calls[0][1].body);\n expect(callBody).toHaveLength(2);\n });\n\n it(\"should execute single request without batching\", async () => {\n const mockResponse = {\n data: { user: { id: \"1\", name: \"John\" } }\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetUser { user { id name } }\"\n });\n\n expect(result).toEqual(mockResponse.data);\n\n // Should use decoratee directly for single request\n const callBody = JSON.parse((global.fetch as any).mock.calls[0][1].body);\n expect(callBody).toHaveProperty(\"query\");\n expect(callBody).not.toBeInstanceOf(Array);\n });\n\n it(\"should handle mixed queries and mutations in batch\", async () => {\n const mockResponse = [\n { data: { user: { id: \"1\" } } },\n { data: { createPost: { id: \"2\" } } }\n ];\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n await Promise.all([\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n }),\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"mutation { createPost { id } }\"\n })\n ]);\n\n expect(global.fetch).toHaveBeenCalledTimes(1);\n const callBody = JSON.parse((global.fetch as any).mock.calls[0][1].body);\n expect(callBody[0]).toHaveProperty(\"query\");\n expect(callBody[1]).toHaveProperty(\"query\");\n });\n\n it(\"should reject all requests if batch fails\", async () => {\n global.fetch = vi.fn().mockRejectedValue(new Error(\"Network error\"));\n\n const client = container.resolve(GraphQLClient);\n\n const promises = [\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n }),\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { post { id } }\"\n })\n ];\n\n await expect(Promise.all(promises)).rejects.toThrow(\"Network error\");\n });\n\n it(\"should handle GraphQL errors in batched operations\", async () => {\n const mockResponse = [\n { data: { user: { id: \"1\" } } },\n { errors: [{ message: \"Post not found\" }], data: null }\n ];\n\n global.fetch = vi.fn().mockResolvedValue({\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n const promises = [\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n }),\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { post { id } }\"\n })\n ];\n\n await expect(Promise.all(promises)).rejects.toThrow(\"GraphQL errors in operation 1\");\n });\n });\n\n describe(\"RetryGraphQLClient\", () => {\n beforeEach(() => {\n container.register(FetchGraphQLClient).inSingletonScope();\n container.registerDecorator(RetryGraphQLClient);\n });\n\n it(\"should retry on network errors\", async () => {\n const mockResponse = { data: { user: { id: \"1\" } } };\n\n global.fetch = vi\n .fn()\n .mockRejectedValueOnce(new Error(\"Network timeout\"))\n .mockRejectedValueOnce(new Error(\"Network timeout\"))\n .mockResolvedValueOnce({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n });\n\n expect(result).toEqual(mockResponse.data);\n expect(global.fetch).toHaveBeenCalledTimes(3);\n });\n\n it(\"should not retry on GraphQL errors\", async () => {\n const mockResponse = {\n errors: [{ message: \"Unauthorized\" }],\n data: null\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n await expect(\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n })\n ).rejects.toThrow(\"GraphQL errors\");\n\n expect(global.fetch).toHaveBeenCalledTimes(1);\n });\n\n it(\"should give up after max retries\", async () => {\n global.fetch = vi.fn().mockRejectedValue(new Error(\"Network error\"));\n\n const client = container.resolve(GraphQLClient);\n\n await expect(\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n })\n ).rejects.toThrow(\"Network error\");\n\n // Should try 4 times: initial + 3 retries\n expect(global.fetch).toHaveBeenCalledTimes(4);\n });\n });\n\n describe(\"Combined decorators (Retry + Batching)\", () => {\n beforeEach(() => {\n container.register(FetchGraphQLClient).inSingletonScope();\n container.registerDecorator(BatchingGraphQLClient);\n container.registerDecorator(RetryGraphQLClient);\n });\n\n it(\"should retry batched requests on failure\", async () => {\n const mockResponse = [{ data: { user: { id: \"1\" } } }, { data: { post: { id: \"2\" } } }];\n\n global.fetch = vi\n .fn()\n .mockRejectedValueOnce(new Error(\"Network error\"))\n .mockResolvedValueOnce({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n const [result1, result2] = await Promise.all([\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n }),\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { post { id } }\"\n })\n ]);\n\n expect(result1).toEqual(mockResponse[0].data);\n expect(result2).toEqual(mockResponse[1].data);\n expect(global.fetch).toHaveBeenCalledTimes(2);\n });\n });\n});\n"],"names":["describe","container","mockEnvConfig","beforeEach","Container","vi","key","EnvConfig","FetchGraphQLClient","it","mockResponse","global","client","GraphQLClient","result","expect","Error","BatchingGraphQLClient","result1","result2","Promise","callBody","JSON","Array","promises","RetryGraphQLClient"],"mappings":";;;;;;;;AAQAA,SAAS,yBAAyB;IAC9B,IAAIC;IACJ,IAAIC;IAEJC,WAAW;QACPF,YAAY,IAAIG;QAEhBF,gBAAgB;YACZ,KAAKG,GAAG,EAAE,CAAC,CAACC;gBACR,IAAIA,AAAQ,oBAARA,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CAA4C;YAC3C,MAAMC,eAAe;gBAAC;oBAAE,MAAM;wBAAE,MAAM;4BAAE,IAAI;wBAAI;oBAAE;gBAAE;gBAAG;oBAAE,MAAM;wBAAE,MAAM;4BAAE,IAAI;wBAAI;oBAAE;gBAAE;aAAE;YAEvFC,oBAAAA,CAAMA,CAAC,KAAK,GAAGN,GAAAA,EACR,GACF,qBAAqB,CAAC,IAAIW,MAAM,kBAChC,qBAAqB,CAAC;gBACnB,QAAQ;gBACR,MAAM,UAAYN;YACtB;YAEJ,MAAME,SAASX,UAAU,OAAO,CAACY;YAEjC,MAAM,CAACK,SAASC,QAAQ,GAAG,MAAMC,QAAQ,GAAG,CAAC;gBACzCR,OAAO,OAAO,CAAC;oBACX,UAAU;oBACV,OAAO;gBACX;gBACAA,OAAO,OAAO,CAAC;oBACX,UAAU;oBACV,OAAO;gBACX;aACH;YAEDG,OAAOG,SAAS,OAAO,CAACR,YAAY,CAAC,EAAE,CAAC,IAAI;YAC5CK,OAAOI,SAAS,OAAO,CAACT,YAAY,CAAC,EAAE,CAAC,IAAI;YAC5CK,OAAOJ,oBAAAA,CAAMA,CAAC,KAAK,EAAE,qBAAqB,CAAC;QAC/C;IACJ;AACJ"}
|
|
1
|
+
{"version":3,"file":"features/graphqlClient/__tests__/GraphQLClient.test.js","sources":["../../../../src/features/graphqlClient/__tests__/GraphQLClient.test.ts"],"sourcesContent":["import { describe, it, expect, vi, beforeEach } from \"vitest\";\nimport { Container } from \"@webiny/di\";\nimport { GraphQLClient } from \"../abstractions.js\";\nimport { FetchGraphQLClient } from \"../FetchGraphQLClient.js\";\nimport { BatchingGraphQLClient } from \"../BatchingGraphQLClient.js\";\nimport { RetryGraphQLClient } from \"../RetryGraphQLClient.js\";\nimport { EnvConfig } from \"~/features/envConfig/index.js\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { GraphQLExtensionsEvent } from \"../GraphQLExtensionsEvent.js\";\n\ndescribe(\"GraphQLClient Feature\", () => {\n let container: Container;\n let mockEnvConfig: EnvConfig.Interface;\n\n beforeEach(() => {\n container = new Container();\n\n mockEnvConfig = {\n get: vi.fn((key: string) => {\n if (key === \"graphqlApiUrl\") {\n return \"https://api.example.com/graphql\";\n }\n return undefined;\n })\n } as any;\n\n container.registerInstance(EnvConfig, mockEnvConfig);\n\n // The clients announce response extensions through the publisher, so it has to resolve.\n container.registerInstance(EventPublisher, { publish: vi.fn(async () => undefined) });\n });\n\n describe(\"FetchGraphQLClient\", () => {\n beforeEach(() => {\n container.register(FetchGraphQLClient).inSingletonScope();\n });\n\n it(\"should execute a query successfully\", async () => {\n const mockResponse = {\n data: { user: { id: \"1\", name: \"John\" } }\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetUser { user { id name } }\"\n });\n\n expect(result).toEqual(mockResponse.data);\n expect(global.fetch).toHaveBeenCalledWith(\n \"https://api.example.com/graphql\",\n expect.objectContaining({\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" }\n })\n );\n });\n\n it(\"should publish the response's extensions\", async () => {\n const extensions = { debug: { enabled: true, entries: [] } };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => ({ data: { user: null }, extensions })\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetUser { user { id } }\"\n });\n\n expect(result).toEqual({ user: null });\n\n const publish = vi.mocked(container.resolve(EventPublisher).publish);\n expect(publish).toHaveBeenCalledTimes(1);\n\n const event = publish.mock.calls[0][0];\n expect(event).toBeInstanceOf(GraphQLExtensionsEvent);\n expect(event.payload).toEqual({\n endpoint: \"https://api.example.com/graphql\",\n operationName: \"GetUser\",\n extensions\n });\n });\n\n it(\"should publish extensions even when the operation failed\", async () => {\n const extensions = { debug: { enabled: true, entries: [] } };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => ({ errors: [{ message: \"Boom\" }], extensions })\n });\n\n const client = container.resolve(GraphQLClient);\n await expect(\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetUser { user { id } }\"\n })\n ).rejects.toThrow(\"GraphQL errors\");\n\n const publish = vi.mocked(container.resolve(EventPublisher).publish);\n expect(publish).toHaveBeenCalledTimes(1);\n expect(publish.mock.calls[0][0].payload.extensions).toEqual(extensions);\n });\n\n it(\"should publish nothing when the response has no extensions\", async () => {\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => ({ data: { user: null } })\n });\n\n const client = container.resolve(GraphQLClient);\n await client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetUser { user { id } }\"\n });\n\n expect(container.resolve(EventPublisher).publish).not.toHaveBeenCalled();\n });\n\n it(\"should execute a mutation successfully\", async () => {\n const mockResponse = {\n data: { createUser: { id: \"2\", name: \"Jane\" } }\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"mutation CreateUser($name: String!) { createUser(name: $name) { id name } }\",\n variables: { name: \"Jane\" }\n });\n\n expect(result).toEqual(mockResponse.data);\n });\n\n it(\"should include custom headers\", async () => {\n const mockResponse = { data: { user: { id: \"1\" } } };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n await client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetUser { user { id } }\",\n headers: { \"x-tenant\": \"root\", Authorization: \"Bearer token\" }\n });\n\n expect(global.fetch).toHaveBeenCalledWith(\n \"https://api.example.com/graphql\",\n expect.objectContaining({\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-tenant\": \"root\",\n Authorization: \"Bearer token\"\n }\n })\n );\n });\n\n it(\"should throw on network error\", async () => {\n global.fetch = vi.fn().mockRejectedValue(new Error(\"Network failure\"));\n\n const client = container.resolve(GraphQLClient);\n\n await expect(\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n })\n ).rejects.toThrow(\"Network error: Network failure\");\n });\n\n it(\"should throw on GraphQL errors\", async () => {\n const mockResponse = {\n errors: [{ message: \"User not found\" }],\n data: null\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n await expect(\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n })\n ).rejects.toThrow(\"GraphQL errors\");\n });\n\n it(\"should return partial data when the response carries both data and errors\", async () => {\n const mockResponse = {\n data: { content: { data: [{ id: \"1\" }, { id: \"2\" }] } },\n errors: [{ message: \"Cannot return null for non-nullable field RefField.id.\" }]\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { content { data { id } } }\"\n });\n\n expect(result).toEqual(mockResponse.data);\n });\n\n it(\"should throw on invalid JSON response\", async () => {\n global.fetch = vi.fn().mockResolvedValue({\n json: async () => {\n throw new Error(\"Invalid JSON\");\n }\n });\n\n const client = container.resolve(GraphQLClient);\n\n await expect(\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n })\n ).rejects.toThrow(\"Failed to parse GraphQL response as JSON\");\n });\n });\n\n describe(\"BatchingGraphQLClient\", () => {\n beforeEach(() => {\n container.register(FetchGraphQLClient).inSingletonScope();\n container.registerDecorator(BatchingGraphQLClient);\n });\n\n it(\"should batch multiple requests within the batch window\", async () => {\n const mockResponse = [\n { data: { user: { id: \"1\", name: \"John\" } } },\n { data: { post: { id: \"2\", title: \"Hello\" } } }\n ];\n\n global.fetch = vi.fn().mockResolvedValue({\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n const [result1, result2] = await Promise.all([\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetUser { user { id name } }\"\n }),\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetPost { post { id title } }\"\n })\n ]);\n\n expect(result1).toEqual(mockResponse[0].data);\n expect(result2).toEqual(mockResponse[1].data);\n expect(global.fetch).toHaveBeenCalledTimes(1);\n\n const callBody = JSON.parse((global.fetch as any).mock.calls[0][1].body);\n expect(callBody).toHaveLength(2);\n });\n\n it(\"should publish the extensions of a batched response\", async () => {\n const extensions = { debug: { enabled: true, entries: [] } };\n const mockResponse = [\n { data: { user: { id: \"1\" } } },\n { data: { post: { id: \"2\" } }, extensions }\n ];\n\n global.fetch = vi.fn().mockResolvedValue({\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n await Promise.all([\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetUser { user { id } }\"\n }),\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetPost { post { id } }\"\n })\n ]);\n\n const publish = vi.mocked(container.resolve(EventPublisher).publish);\n expect(publish).toHaveBeenCalledTimes(1);\n expect(publish.mock.calls[0][0].payload).toEqual({\n endpoint: \"https://api.example.com/graphql\",\n operationName: \"GetPost\",\n extensions\n });\n });\n\n it(\"should execute single request without batching\", async () => {\n const mockResponse = {\n data: { user: { id: \"1\", name: \"John\" } }\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetUser { user { id name } }\"\n });\n\n expect(result).toEqual(mockResponse.data);\n\n // Should use decoratee directly for single request\n const callBody = JSON.parse((global.fetch as any).mock.calls[0][1].body);\n expect(callBody).toHaveProperty(\"query\");\n expect(callBody).not.toBeInstanceOf(Array);\n });\n\n it(\"should handle mixed queries and mutations in batch\", async () => {\n const mockResponse = [\n { data: { user: { id: \"1\" } } },\n { data: { createPost: { id: \"2\" } } }\n ];\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n await Promise.all([\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n }),\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"mutation { createPost { id } }\"\n })\n ]);\n\n expect(global.fetch).toHaveBeenCalledTimes(1);\n const callBody = JSON.parse((global.fetch as any).mock.calls[0][1].body);\n expect(callBody[0]).toHaveProperty(\"query\");\n expect(callBody[1]).toHaveProperty(\"query\");\n });\n\n it(\"should reject all requests if batch fails\", async () => {\n global.fetch = vi.fn().mockRejectedValue(new Error(\"Network error\"));\n\n const client = container.resolve(GraphQLClient);\n\n const promises = [\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n }),\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { post { id } }\"\n })\n ];\n\n await expect(Promise.all(promises)).rejects.toThrow(\"Network error\");\n });\n\n it(\"should handle GraphQL errors in batched operations\", async () => {\n const mockResponse = [\n { data: { user: { id: \"1\" } } },\n { errors: [{ message: \"Post not found\" }], data: null }\n ];\n\n global.fetch = vi.fn().mockResolvedValue({\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n const promises = [\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n }),\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { post { id } }\"\n })\n ];\n\n await expect(Promise.all(promises)).rejects.toThrow(\"GraphQL errors in operation 1\");\n });\n\n it(\"should return partial data for a batched operation that has data and errors\", async () => {\n const mockResponse = [\n { data: { user: { id: \"1\" } } },\n {\n data: { content: { data: [{ id: \"2\" }] } },\n errors: [{ message: \"Cannot return null for non-nullable field RefField.id.\" }]\n }\n ];\n\n global.fetch = vi.fn().mockResolvedValue({\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n const [result1, result2] = await Promise.all([\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n }),\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { content { data { id } } }\"\n })\n ]);\n\n expect(result1).toEqual(mockResponse[0].data);\n expect(result2).toEqual(mockResponse[1].data);\n });\n });\n\n describe(\"RetryGraphQLClient\", () => {\n beforeEach(() => {\n container.register(FetchGraphQLClient).inSingletonScope();\n container.registerDecorator(RetryGraphQLClient);\n });\n\n it(\"should retry on network errors\", async () => {\n const mockResponse = { data: { user: { id: \"1\" } } };\n\n global.fetch = vi\n .fn()\n .mockRejectedValueOnce(new Error(\"Network timeout\"))\n .mockRejectedValueOnce(new Error(\"Network timeout\"))\n .mockResolvedValueOnce({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n });\n\n expect(result).toEqual(mockResponse.data);\n expect(global.fetch).toHaveBeenCalledTimes(3);\n });\n\n it(\"should not retry on GraphQL errors\", async () => {\n const mockResponse = {\n errors: [{ message: \"Unauthorized\" }],\n data: null\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n await expect(\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n })\n ).rejects.toThrow(\"GraphQL errors\");\n\n expect(global.fetch).toHaveBeenCalledTimes(1);\n });\n\n it(\"should give up after max retries\", async () => {\n global.fetch = vi.fn().mockRejectedValue(new Error(\"Network error\"));\n\n const client = container.resolve(GraphQLClient);\n\n await expect(\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n })\n ).rejects.toThrow(\"Network error\");\n\n // Should try 4 times: initial + 3 retries\n expect(global.fetch).toHaveBeenCalledTimes(4);\n });\n });\n\n describe(\"Combined decorators (Retry + Batching)\", () => {\n beforeEach(() => {\n container.register(FetchGraphQLClient).inSingletonScope();\n container.registerDecorator(BatchingGraphQLClient);\n container.registerDecorator(RetryGraphQLClient);\n });\n\n it(\"should retry batched requests on failure\", async () => {\n const mockResponse = [{ data: { user: { id: \"1\" } } }, { data: { post: { id: \"2\" } } }];\n\n global.fetch = vi\n .fn()\n .mockRejectedValueOnce(new Error(\"Network error\"))\n .mockResolvedValueOnce({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n const [result1, result2] = await Promise.all([\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n }),\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { post { id } }\"\n })\n ]);\n\n expect(result1).toEqual(mockResponse[0].data);\n expect(result2).toEqual(mockResponse[1].data);\n expect(global.fetch).toHaveBeenCalledTimes(2);\n });\n });\n});\n"],"names":["describe","container","mockEnvConfig","beforeEach","Container","vi","key","EnvConfig","EventPublisher","undefined","FetchGraphQLClient","it","mockResponse","global","client","GraphQLClient","result","expect","extensions","publish","event","GraphQLExtensionsEvent","Error","BatchingGraphQLClient","result1","result2","Promise","callBody","JSON","Array","promises","RetryGraphQLClient"],"mappings":";;;;;;;;;;AAUAA,SAAS,yBAAyB;IAC9B,IAAIC;IACJ,IAAIC;IAEJC,WAAW;QACPF,YAAY,IAAIG;QAEhBF,gBAAgB;YACZ,KAAKG,GAAG,EAAE,CAAC,CAACC;gBACR,IAAIA,AAAQ,oBAARA,KACA,OAAO;YAGf;QACJ;QAEAL,UAAU,gBAAgB,CAACM,WAAWL;QAGtCD,UAAU,gBAAgB,CAACO,gBAAgB;YAAE,SAASH,GAAG,EAAE,CAAC,UAAYI;QAAW;IACvF;IAEAT,SAAS,sBAAsB;QAC3BG,WAAW;YACPF,UAAU,QAAQ,CAACS,oBAAoB,gBAAg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AI;oBAAE;gBAAE;gBAAG;oBAAE,MAAM;wBAAE,MAAM;4BAAE,IAAI;wBAAI;oBAAE;gBAAE;aAAE;YAEvFC,oBAAAA,CAAMA,CAAC,KAAK,GAAGR,GAAAA,EACR,GACF,qBAAqB,CAAC,IAAIiB,MAAM,kBAChC,qBAAqB,CAAC;gBACnB,QAAQ;gBACR,MAAM,UAAYV;YACtB;YAEJ,MAAME,SAASb,UAAU,OAAO,CAACc;YAEjC,MAAM,CAACS,SAASC,QAAQ,GAAG,MAAMC,QAAQ,GAAG,CAAC;gBACzCZ,OAAO,OAAO,CAAC;oBACX,UAAU;oBACV,OAAO;gBACX;gBACAA,OAAO,OAAO,CAAC;oBACX,UAAU;oBACV,OAAO;gBACX;aACH;YAEDG,OAAOO,SAAS,OAAO,CAACZ,YAAY,CAAC,EAAE,CAAC,IAAI;YAC5CK,OAAOQ,SAAS,OAAO,CAACb,YAAY,CAAC,EAAE,CAAC,IAAI;YAC5CK,OAAOJ,oBAAAA,CAAMA,CAAC,KAAK,EAAE,qBAAqB,CAAC;QAC/C;IACJ;AACJ"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { DocumentNode } from "graphql";
|
|
2
|
+
import type { IEventHandler } from "../../features/eventPublisher/index.js";
|
|
3
|
+
import type { GraphQLExtensionsEvent } from "./GraphQLExtensionsEvent.js";
|
|
2
4
|
type IHeaders = Record<string, string | number | undefined>;
|
|
3
5
|
type GraphQLRequest<TVariables = any> = {
|
|
4
6
|
endpoint: string;
|
|
@@ -15,4 +17,9 @@ export declare namespace GraphQLClient {
|
|
|
15
17
|
type Interface = IGraphQLClient;
|
|
16
18
|
type Request<TVariables = any> = GraphQLRequest<TVariables>;
|
|
17
19
|
}
|
|
20
|
+
export declare const GraphQLExtensionsEventHandler: import("@webiny/di").Abstraction<IEventHandler<GraphQLExtensionsEvent>>;
|
|
21
|
+
export declare namespace GraphQLExtensionsEventHandler {
|
|
22
|
+
type Interface = IEventHandler<GraphQLExtensionsEvent>;
|
|
23
|
+
type Event = GraphQLExtensionsEvent;
|
|
24
|
+
}
|
|
18
25
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/admin";
|
|
2
2
|
const GraphQLClient = createAbstraction("GraphQLClient");
|
|
3
|
-
|
|
3
|
+
const GraphQLExtensionsEventHandler = createAbstraction("GraphQLExtensionsEventHandler");
|
|
4
|
+
export { GraphQLClient, GraphQLExtensionsEventHandler };
|
|
4
5
|
|
|
5
6
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/graphqlClient/abstractions.js","sources":["../../../src/features/graphqlClient/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport type { DocumentNode } from \"graphql\";\n\ntype IHeaders = Record<string, string | number | undefined>;\n\ntype GraphQLRequest<TVariables = any> = {\n endpoint: string;\n query: DocumentNode | string;\n variables?: TVariables;\n headers?: IHeaders;\n};\n\nexport interface IGraphQLClient {\n execute<TResult = any, TVariables = any>(params: GraphQLRequest<TVariables>): Promise<TResult>;\n}\nexport const GraphQLClient = createAbstraction<IGraphQLClient>(\"GraphQLClient\");\n\nexport namespace GraphQLClient {\n export type Headers = IHeaders;\n export type Interface = IGraphQLClient;\n export type Request<TVariables = any> = GraphQLRequest<TVariables>;\n}\n"],"names":["GraphQLClient","createAbstraction"],"mappings":";
|
|
1
|
+
{"version":3,"file":"features/graphqlClient/abstractions.js","sources":["../../../src/features/graphqlClient/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport type { DocumentNode } from \"graphql\";\nimport type { IEventHandler } from \"~/features/eventPublisher/index.js\";\nimport type { GraphQLExtensionsEvent } from \"./GraphQLExtensionsEvent.js\";\n\ntype IHeaders = Record<string, string | number | undefined>;\n\ntype GraphQLRequest<TVariables = any> = {\n endpoint: string;\n query: DocumentNode | string;\n variables?: TVariables;\n headers?: IHeaders;\n};\n\nexport interface IGraphQLClient {\n execute<TResult = any, TVariables = any>(params: GraphQLRequest<TVariables>): Promise<TResult>;\n}\nexport const GraphQLClient = createAbstraction<IGraphQLClient>(\"GraphQLClient\");\n\nexport namespace GraphQLClient {\n export type Headers = IHeaders;\n export type Interface = IGraphQLClient;\n export type Request<TVariables = any> = GraphQLRequest<TVariables>;\n}\n\nexport const GraphQLExtensionsEventHandler = createAbstraction<\n IEventHandler<GraphQLExtensionsEvent>\n>(\"GraphQLExtensionsEventHandler\");\n\nexport namespace GraphQLExtensionsEventHandler {\n export type Interface = IEventHandler<GraphQLExtensionsEvent>;\n export type Event = GraphQLExtensionsEvent;\n}\n"],"names":["GraphQLClient","createAbstraction","GraphQLExtensionsEventHandler"],"mappings":";AAiBO,MAAMA,gBAAgBC,kBAAkC;AAQxD,MAAMC,gCAAgCD,kBAE3C"}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { GraphQLClient } from "./abstractions.js";
|
|
1
|
+
export { GraphQLClient, GraphQLExtensionsEventHandler } from "./abstractions.js";
|
|
2
|
+
export { GraphQLExtensionsEvent } from "./GraphQLExtensionsEvent.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { EventPublisher } from "../../features/eventPublisher/index.js";
|
|
2
|
+
export interface PublishExtensionsParams {
|
|
3
|
+
endpoint: string;
|
|
4
|
+
operationName?: string;
|
|
5
|
+
extensions: Record<string, any> | undefined;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Announces a response's `extensions`, if it carried any, so ordinary traffic pays nothing.
|
|
9
|
+
*
|
|
10
|
+
* Failing to announce them must not fail the request that produced them: an observer's problem is
|
|
11
|
+
* not the caller's problem.
|
|
12
|
+
*/
|
|
13
|
+
export declare const publishExtensions: (eventPublisher: EventPublisher.Interface, params: PublishExtensionsParams) => Promise<void>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { GraphQLExtensionsEvent } from "./GraphQLExtensionsEvent.js";
|
|
2
|
+
const publishExtensions = async (eventPublisher, params)=>{
|
|
3
|
+
const { endpoint, operationName, extensions } = params;
|
|
4
|
+
if (!extensions || "object" != typeof extensions) return;
|
|
5
|
+
try {
|
|
6
|
+
const event = new GraphQLExtensionsEvent({
|
|
7
|
+
endpoint,
|
|
8
|
+
operationName,
|
|
9
|
+
extensions
|
|
10
|
+
});
|
|
11
|
+
await eventPublisher.publish(event);
|
|
12
|
+
} catch {}
|
|
13
|
+
};
|
|
14
|
+
export { publishExtensions };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=publishExtensions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/graphqlClient/publishExtensions.js","sources":["../../../src/features/graphqlClient/publishExtensions.ts"],"sourcesContent":["import type { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { GraphQLExtensionsEvent } from \"./GraphQLExtensionsEvent.js\";\n\nexport interface PublishExtensionsParams {\n endpoint: string;\n operationName?: string;\n extensions: Record<string, any> | undefined;\n}\n\n/**\n * Announces a response's `extensions`, if it carried any, so ordinary traffic pays nothing.\n *\n * Failing to announce them must not fail the request that produced them: an observer's problem is\n * not the caller's problem.\n */\nexport const publishExtensions = async (\n eventPublisher: EventPublisher.Interface,\n params: PublishExtensionsParams\n): Promise<void> => {\n const { endpoint, operationName, extensions } = params;\n if (!extensions || typeof extensions !== \"object\") {\n return;\n }\n\n try {\n const event = new GraphQLExtensionsEvent({ endpoint, operationName, extensions });\n await eventPublisher.publish(event);\n } catch {\n // Nothing to do; the response itself is still good.\n }\n};\n"],"names":["publishExtensions","eventPublisher","params","endpoint","operationName","extensions","event","GraphQLExtensionsEvent"],"mappings":";AAeO,MAAMA,oBAAoB,OAC7BC,gBACAC;IAEA,MAAM,EAAEC,QAAQ,EAAEC,aAAa,EAAEC,UAAU,EAAE,GAAGH;IAChD,IAAI,CAACG,cAAc,AAAsB,YAAtB,OAAOA,YACtB;IAGJ,IAAI;QACA,MAAMC,QAAQ,IAAIC,uBAAuB;YAAEJ;YAAUC;YAAeC;QAAW;QAC/E,MAAMJ,eAAe,OAAO,CAACK;IACjC,EAAE,OAAM,CAER;AACJ"}
|
|
@@ -169,6 +169,16 @@ describe("Router Gateway", ()=>{
|
|
|
169
169
|
expect(spyWildcard).toHaveBeenCalledTimes(1);
|
|
170
170
|
vi.clearAllMocks();
|
|
171
171
|
gateway.setRoutes([
|
|
172
|
+
{
|
|
173
|
+
name: "wildcard",
|
|
174
|
+
path: "*",
|
|
175
|
+
onMatch: spyWildcard
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
name: "home",
|
|
179
|
+
path: "/",
|
|
180
|
+
onMatch: spyHome
|
|
181
|
+
},
|
|
172
182
|
{
|
|
173
183
|
name: "specific",
|
|
174
184
|
path: "/specific-route",
|
|
@@ -190,6 +200,64 @@ describe("Router Gateway", ()=>{
|
|
|
190
200
|
await wait();
|
|
191
201
|
expect(spyWildcard).toHaveBeenCalledTimes(1);
|
|
192
202
|
});
|
|
203
|
+
it("should drop routes that are no longer in the set and re-resolve the current path", async ()=>{
|
|
204
|
+
const spyUsers = vi.fn();
|
|
205
|
+
const spyWildcard = vi.fn();
|
|
206
|
+
const history = createMemoryHistory();
|
|
207
|
+
history.replace("/admin-users");
|
|
208
|
+
const gateway = new HistoryRouterGateway(history, "");
|
|
209
|
+
gateway.setRoutes([
|
|
210
|
+
{
|
|
211
|
+
name: "users",
|
|
212
|
+
path: "/admin-users",
|
|
213
|
+
onMatch: spyUsers
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
name: "wildcard",
|
|
217
|
+
path: "*",
|
|
218
|
+
onMatch: spyWildcard
|
|
219
|
+
}
|
|
220
|
+
]);
|
|
221
|
+
expect(spyUsers).toHaveBeenCalledTimes(1);
|
|
222
|
+
expect(spyWildcard).toHaveBeenCalledTimes(0);
|
|
223
|
+
gateway.setRoutes([
|
|
224
|
+
{
|
|
225
|
+
name: "wildcard",
|
|
226
|
+
path: "*",
|
|
227
|
+
onMatch: spyWildcard
|
|
228
|
+
}
|
|
229
|
+
]);
|
|
230
|
+
expect(spyUsers).toHaveBeenCalledTimes(1);
|
|
231
|
+
expect(spyWildcard).toHaveBeenCalledTimes(1);
|
|
232
|
+
expect(spyWildcard).toHaveBeenLastCalledWith(expect.objectContaining({
|
|
233
|
+
name: "wildcard",
|
|
234
|
+
pathname: "/admin-users"
|
|
235
|
+
}));
|
|
236
|
+
history.push("/admin-users");
|
|
237
|
+
await wait();
|
|
238
|
+
expect(spyUsers).toHaveBeenCalledTimes(1);
|
|
239
|
+
});
|
|
240
|
+
it("should keep one route per name, the last definition winning", async ()=>{
|
|
241
|
+
const spyBuiltIn = vi.fn();
|
|
242
|
+
const spyOverride = vi.fn();
|
|
243
|
+
const history = createMemoryHistory();
|
|
244
|
+
history.replace("/dashboard");
|
|
245
|
+
const gateway = new HistoryRouterGateway(history, "");
|
|
246
|
+
gateway.setRoutes([
|
|
247
|
+
{
|
|
248
|
+
name: "dashboard",
|
|
249
|
+
path: "/dashboard",
|
|
250
|
+
onMatch: spyBuiltIn
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
name: "dashboard",
|
|
254
|
+
path: "/dashboard",
|
|
255
|
+
onMatch: spyOverride
|
|
256
|
+
}
|
|
257
|
+
]);
|
|
258
|
+
expect(spyBuiltIn).toHaveBeenCalledTimes(0);
|
|
259
|
+
expect(spyOverride).toHaveBeenCalledTimes(1);
|
|
260
|
+
});
|
|
193
261
|
});
|
|
194
262
|
|
|
195
263
|
//# sourceMappingURL=HistoryRouterGateway.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/router/HistoryRouterGateway.test.js","sources":["../../../src/features/router/HistoryRouterGateway.test.ts"],"sourcesContent":["import { describe, it, beforeEach, expect, vi } from \"vitest\";\nimport { createMemoryHistory } from \"history\";\nimport { HistoryRouterGateway } from \"./HistoryRouterGateway.js\";\nimport { RouteUrl } from \"./RouteUrl.js\";\n\nconst wait = () => new Promise(resolve => setTimeout(resolve, 10));\n\ndescribe(\"Router Gateway\", () => {\n beforeEach(() => {\n vi.clearAllMocks();\n });\n\n it(\"should execute onMatch when history changes\", async () => {\n const spyHome = vi.fn();\n const spyLogin = vi.fn();\n const spyDynamic = vi.fn();\n\n // Create `history` and set the initial pathname to an unknown route\n const history = createMemoryHistory();\n history.replace(\"/__unknown__\");\n\n const gateway = new HistoryRouterGateway(history, \"\");\n gateway.setRoutes([\n { name: \"home\", path: \"/\", onMatch: spyHome },\n { name: \"login\", path: \"/login\", onMatch: spyLogin },\n { name: \"test\", path: \"/dynamic-route/:name\", onMatch: spyDynamic }\n ]);\n\n history.push(\"/login\");\n await wait();\n history.push(\"/\");\n await wait();\n history.push(\"/dynamic-route/cars\");\n await wait();\n history.push(\"/login\");\n await wait();\n history.push(\"/dynamic-route/blogs\");\n await wait();\n history.push(\"/dynamic-route/blogs?search=123\");\n await wait();\n\n expect(spyLogin).toHaveBeenCalledTimes(2);\n expect(spyLogin).toHaveBeenNthCalledWith(1, {\n name: \"login\",\n path: \"/login\",\n pathname: \"/login\",\n params: {}\n });\n expect(spyLogin).toHaveBeenNthCalledWith(2, {\n name: \"login\",\n path: \"/login\",\n pathname: \"/login\",\n params: {}\n });\n expect(spyHome).toHaveBeenCalledTimes(1);\n expect(spyHome).toHaveBeenLastCalledWith({\n name: \"home\",\n path: \"/\",\n pathname: \"/\",\n params: {}\n });\n expect(spyDynamic).toHaveBeenCalledTimes(3);\n expect(spyDynamic).toHaveBeenNthCalledWith(1, {\n name: \"test\",\n path: \"/dynamic-route/:name\",\n pathname: \"/dynamic-route/cars\",\n params: {\n name: \"cars\"\n }\n });\n expect(spyDynamic).toHaveBeenNthCalledWith(2, {\n name: \"test\",\n path: \"/dynamic-route/:name\",\n pathname: \"/dynamic-route/blogs\",\n params: {\n name: \"blogs\"\n }\n });\n expect(spyDynamic).toHaveBeenNthCalledWith(3, {\n name: \"test\",\n path: \"/dynamic-route/:name\",\n pathname: \"/dynamic-route/blogs\",\n params: {\n name: \"blogs\",\n search: \"123\"\n }\n });\n });\n\n it(\"should generate route URLs\", async () => {\n const urls = [\n RouteUrl.fromPattern(\"/\"),\n RouteUrl.fromPattern(\"/login\", {}),\n RouteUrl.fromPattern(\"/login\", { redirect: \"/\", reason: \"login\" }),\n RouteUrl.fromPattern(\"/dynamic-route/:name\", { name: \"cars\" }),\n RouteUrl.fromPattern(\"/dynamic-route\", { folderId: \"696556831e485d00027a1a0b#0001\" })\n ];\n expect(urls).toEqual([\n \"/\",\n \"/login\",\n \"/login?redirect=%2F&reason=login\",\n \"/dynamic-route/cars\",\n \"/dynamic-route?folderId=696556831e485d00027a1a0b%230001\"\n ]);\n });\n\n it(\"should handle baseUrl for route matching and URL generation\", async () => {\n const spyFileManager = vi.fn();\n const spyHome = vi.fn();\n\n // Create history with a tenant prefix\n const history = createMemoryHistory();\n history.replace(\"/tenant123/__unknown__\");\n\n const gateway = new HistoryRouterGateway(history, \"/tenant123\");\n gateway.setRoutes([\n { name: \"home\", path: \"/\", onMatch: spyHome },\n { name: \"fileManager\", path: \"/file-manager\", onMatch: spyFileManager }\n ]);\n\n // Navigate to /tenant123/file-manager\n history.push(\"/tenant123/file-manager\");\n await wait();\n\n // Should match the /file-manager route\n expect(spyFileManager).toHaveBeenCalledTimes(1);\n expect(spyFileManager).toHaveBeenCalledWith({\n name: \"fileManager\",\n path: \"/file-manager\",\n pathname: \"/tenant123/file-manager\",\n params: {}\n });\n\n // Test URL generation with baseUrl\n const urlWithBase = RouteUrl.fromPattern(\"/file-manager\", {}, \"/tenant123\");\n expect(urlWithBase).toBe(\"/tenant123/file-manager\");\n\n const urlWithBaseAndParams = RouteUrl.fromPattern(\n \"/file-manager\",\n { folder: \"abc\" },\n \"/tenant123\"\n );\n expect(urlWithBaseAndParams).toBe(\"/tenant123/file-manager?folder=abc\");\n });\n\n it(\"should properly sort routes with wildcards always at the bottom\", async () => {\n const spyWildcard = vi.fn();\n const spySpecific = vi.fn();\n const spyHome = vi.fn();\n\n const history = createMemoryHistory();\n // Start at a non-matching path to avoid initial route resolution\n history.replace(\"/initial\");\n\n const gateway = new HistoryRouterGateway(history, \"\");\n\n // Add wildcard first, then home route\n // Note: setRoutes will trigger route resolution for current path (/initial)\n gateway.setRoutes([\n { name: \"wildcard\", path: \"*\", onMatch: spyWildcard },\n { name: \"home\", path: \"/\", onMatch: spyHome }\n ]);\n\n // Wildcard should have matched /initial\n expect(spyWildcard).toHaveBeenCalledTimes(1);\n vi.clearAllMocks();\n\n // Now add a specific route after the wildcard - this should re-sort and keep wildcard at bottom\n // Note: setRoutes will trigger route resolution again for /initial, matching wildcard again\n gateway.setRoutes([{ name: \"specific\", path: \"/specific-route\", onMatch: spySpecific }]);\n\n // Wildcard should match /initial again after re-sorting\n expect(spyWildcard).toHaveBeenCalledTimes(1);\n vi.clearAllMocks();\n\n // Navigate to the specific route\n history.push(\"/specific-route\");\n await wait();\n\n // Should match the specific route, not the wildcard\n expect(spySpecific).toHaveBeenCalledTimes(1);\n expect(spyWildcard).toHaveBeenCalledTimes(0);\n expect(spyHome).toHaveBeenCalledTimes(0);\n\n // Navigate to home\n history.push(\"/\");\n await wait();\n\n // Should match home route\n expect(spyHome).toHaveBeenCalledTimes(1);\n expect(spyWildcard).toHaveBeenCalledTimes(0);\n\n // Navigate to unknown route\n history.push(\"/unknown\");\n await wait();\n\n // Should match wildcard\n expect(spyWildcard).toHaveBeenCalledTimes(1);\n });\n});\n"],"names":["wait","Promise","resolve","setTimeout","describe","beforeEach","vi","it","spyHome","spyLogin","spyDynamic","history","createMemoryHistory","gateway","HistoryRouterGateway","expect","urls","RouteUrl","spyFileManager","urlWithBase","urlWithBaseAndParams","spyWildcard","spySpecific"],"mappings":";;;;AAKA,MAAMA,OAAO,IAAM,IAAIC,QAAQC,CAAAA,UAAWC,WAAWD,SAAS;AAE9DE,SAAS,kBAAkB;IACvBC,WAAW;QACPC,GAAG,aAAa;IACpB;IAEAC,GAAG,+CAA+C;QAC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B,GAAG,EAAE;QACzB,MAAME,UAAUF,GAAG,EAAE;QAErB,MAAMK,UAAUC;QAEhBD,QAAQ,OAAO,CAAC;QAEhB,MAAME,UAAU,IAAIC,qBAAqBH,SAAS;QAIlDE,QAAQ,SAAS,CAAC;YACd;gBAAE,MAAM;gBAAY,MAAM;gBAAK,SAASQ;YAAY;YACpD;gBAAE,MAAM;gBAAQ,MAAM;gBAAK,SAASb;YAAQ;SAC/C;QAGDO,OAAOM,aAAa,qBAAqB,CAAC;QAC1Cf,GAAG,aAAa;QAIhBO,QAAQ,SAAS,CAAC;YAAC;gBAAE,MAAM;gBAAY,MAAM;gBAAmB,SAASS;YAAY;SAAE;QAGvFP,OAAOM,aAAa,qBAAqB,CAAC;QAC1Cf,GAAG,aAAa;QAGhBK,QAAQ,IAAI,CAAC;QACb,MAAMX;QAGNe,OAAOO,aAAa,qBAAqB,CAAC;QAC1CP,OAAOM,aAAa,qBAAqB,CAAC;QAC1CN,OAAOP,SAAS,qBAAqB,CAAC;QAGtCG,QAAQ,IAAI,CAAC;QACb,MAAMX;QAGNe,OAAOP,SAAS,qBAAqB,CAAC;QACtCO,OAAOM,aAAa,qBAAqB,CAAC;QAG1CV,QAAQ,IAAI,CAAC;QACb,MAAMX;QAGNe,OAAOM,aAAa,qBAAqB,CAAC;IAC9C;AACJ"}
|
|
1
|
+
{"version":3,"file":"features/router/HistoryRouterGateway.test.js","sources":["../../../src/features/router/HistoryRouterGateway.test.ts"],"sourcesContent":["import { describe, it, beforeEach, expect, vi } from \"vitest\";\nimport { createMemoryHistory } from \"history\";\nimport { HistoryRouterGateway } from \"./HistoryRouterGateway.js\";\nimport { RouteUrl } from \"./RouteUrl.js\";\n\nconst wait = () => new Promise(resolve => setTimeout(resolve, 10));\n\ndescribe(\"Router Gateway\", () => {\n beforeEach(() => {\n vi.clearAllMocks();\n });\n\n it(\"should execute onMatch when history changes\", async () => {\n const spyHome = vi.fn();\n const spyLogin = vi.fn();\n const spyDynamic = vi.fn();\n\n // Create `history` and set the initial pathname to an unknown route\n const history = createMemoryHistory();\n history.replace(\"/__unknown__\");\n\n const gateway = new HistoryRouterGateway(history, \"\");\n gateway.setRoutes([\n { name: \"home\", path: \"/\", onMatch: spyHome },\n { name: \"login\", path: \"/login\", onMatch: spyLogin },\n { name: \"test\", path: \"/dynamic-route/:name\", onMatch: spyDynamic }\n ]);\n\n history.push(\"/login\");\n await wait();\n history.push(\"/\");\n await wait();\n history.push(\"/dynamic-route/cars\");\n await wait();\n history.push(\"/login\");\n await wait();\n history.push(\"/dynamic-route/blogs\");\n await wait();\n history.push(\"/dynamic-route/blogs?search=123\");\n await wait();\n\n expect(spyLogin).toHaveBeenCalledTimes(2);\n expect(spyLogin).toHaveBeenNthCalledWith(1, {\n name: \"login\",\n path: \"/login\",\n pathname: \"/login\",\n params: {}\n });\n expect(spyLogin).toHaveBeenNthCalledWith(2, {\n name: \"login\",\n path: \"/login\",\n pathname: \"/login\",\n params: {}\n });\n expect(spyHome).toHaveBeenCalledTimes(1);\n expect(spyHome).toHaveBeenLastCalledWith({\n name: \"home\",\n path: \"/\",\n pathname: \"/\",\n params: {}\n });\n expect(spyDynamic).toHaveBeenCalledTimes(3);\n expect(spyDynamic).toHaveBeenNthCalledWith(1, {\n name: \"test\",\n path: \"/dynamic-route/:name\",\n pathname: \"/dynamic-route/cars\",\n params: {\n name: \"cars\"\n }\n });\n expect(spyDynamic).toHaveBeenNthCalledWith(2, {\n name: \"test\",\n path: \"/dynamic-route/:name\",\n pathname: \"/dynamic-route/blogs\",\n params: {\n name: \"blogs\"\n }\n });\n expect(spyDynamic).toHaveBeenNthCalledWith(3, {\n name: \"test\",\n path: \"/dynamic-route/:name\",\n pathname: \"/dynamic-route/blogs\",\n params: {\n name: \"blogs\",\n search: \"123\"\n }\n });\n });\n\n it(\"should generate route URLs\", async () => {\n const urls = [\n RouteUrl.fromPattern(\"/\"),\n RouteUrl.fromPattern(\"/login\", {}),\n RouteUrl.fromPattern(\"/login\", { redirect: \"/\", reason: \"login\" }),\n RouteUrl.fromPattern(\"/dynamic-route/:name\", { name: \"cars\" }),\n RouteUrl.fromPattern(\"/dynamic-route\", { folderId: \"696556831e485d00027a1a0b#0001\" })\n ];\n expect(urls).toEqual([\n \"/\",\n \"/login\",\n \"/login?redirect=%2F&reason=login\",\n \"/dynamic-route/cars\",\n \"/dynamic-route?folderId=696556831e485d00027a1a0b%230001\"\n ]);\n });\n\n it(\"should handle baseUrl for route matching and URL generation\", async () => {\n const spyFileManager = vi.fn();\n const spyHome = vi.fn();\n\n // Create history with a tenant prefix\n const history = createMemoryHistory();\n history.replace(\"/tenant123/__unknown__\");\n\n const gateway = new HistoryRouterGateway(history, \"/tenant123\");\n gateway.setRoutes([\n { name: \"home\", path: \"/\", onMatch: spyHome },\n { name: \"fileManager\", path: \"/file-manager\", onMatch: spyFileManager }\n ]);\n\n // Navigate to /tenant123/file-manager\n history.push(\"/tenant123/file-manager\");\n await wait();\n\n // Should match the /file-manager route\n expect(spyFileManager).toHaveBeenCalledTimes(1);\n expect(spyFileManager).toHaveBeenCalledWith({\n name: \"fileManager\",\n path: \"/file-manager\",\n pathname: \"/tenant123/file-manager\",\n params: {}\n });\n\n // Test URL generation with baseUrl\n const urlWithBase = RouteUrl.fromPattern(\"/file-manager\", {}, \"/tenant123\");\n expect(urlWithBase).toBe(\"/tenant123/file-manager\");\n\n const urlWithBaseAndParams = RouteUrl.fromPattern(\n \"/file-manager\",\n { folder: \"abc\" },\n \"/tenant123\"\n );\n expect(urlWithBaseAndParams).toBe(\"/tenant123/file-manager?folder=abc\");\n });\n\n it(\"should properly sort routes with wildcards always at the bottom\", async () => {\n const spyWildcard = vi.fn();\n const spySpecific = vi.fn();\n const spyHome = vi.fn();\n\n const history = createMemoryHistory();\n // Start at a non-matching path to avoid initial route resolution\n history.replace(\"/initial\");\n\n const gateway = new HistoryRouterGateway(history, \"\");\n\n // Add wildcard first, then home route\n // Note: setRoutes will trigger route resolution for current path (/initial)\n gateway.setRoutes([\n { name: \"wildcard\", path: \"*\", onMatch: spyWildcard },\n { name: \"home\", path: \"/\", onMatch: spyHome }\n ]);\n\n // Wildcard should have matched /initial\n expect(spyWildcard).toHaveBeenCalledTimes(1);\n vi.clearAllMocks();\n\n // Now add a specific route after the wildcard - this should re-sort and keep wildcard at bottom\n // Note: setRoutes takes the full set and triggers route resolution again for /initial.\n gateway.setRoutes([\n { name: \"wildcard\", path: \"*\", onMatch: spyWildcard },\n { name: \"home\", path: \"/\", onMatch: spyHome },\n { name: \"specific\", path: \"/specific-route\", onMatch: spySpecific }\n ]);\n\n // Wildcard should match /initial again after re-sorting\n expect(spyWildcard).toHaveBeenCalledTimes(1);\n vi.clearAllMocks();\n\n // Navigate to the specific route\n history.push(\"/specific-route\");\n await wait();\n\n // Should match the specific route, not the wildcard\n expect(spySpecific).toHaveBeenCalledTimes(1);\n expect(spyWildcard).toHaveBeenCalledTimes(0);\n expect(spyHome).toHaveBeenCalledTimes(0);\n\n // Navigate to home\n history.push(\"/\");\n await wait();\n\n // Should match home route\n expect(spyHome).toHaveBeenCalledTimes(1);\n expect(spyWildcard).toHaveBeenCalledTimes(0);\n\n // Navigate to unknown route\n history.push(\"/unknown\");\n await wait();\n\n // Should match wildcard\n expect(spyWildcard).toHaveBeenCalledTimes(1);\n });\n\n /*\n * The route config sends the complete set every time. A route behind `HasPermission` drops out\n * of it when the signed-in user changes, and the router must drop it too, or the current URL\n * keeps matching a route the new user has no access to.\n */\n it(\"should drop routes that are no longer in the set and re-resolve the current path\", async () => {\n const spyUsers = vi.fn();\n const spyWildcard = vi.fn();\n\n const history = createMemoryHistory();\n history.replace(\"/admin-users\");\n\n const gateway = new HistoryRouterGateway(history, \"\");\n gateway.setRoutes([\n { name: \"users\", path: \"/admin-users\", onMatch: spyUsers },\n { name: \"wildcard\", path: \"*\", onMatch: spyWildcard }\n ]);\n\n expect(spyUsers).toHaveBeenCalledTimes(1);\n expect(spyWildcard).toHaveBeenCalledTimes(0);\n\n gateway.setRoutes([{ name: \"wildcard\", path: \"*\", onMatch: spyWildcard }]);\n\n expect(spyUsers).toHaveBeenCalledTimes(1);\n expect(spyWildcard).toHaveBeenCalledTimes(1);\n expect(spyWildcard).toHaveBeenLastCalledWith(\n expect.objectContaining({ name: \"wildcard\", pathname: \"/admin-users\" })\n );\n\n history.push(\"/admin-users\");\n await wait();\n\n expect(spyUsers).toHaveBeenCalledTimes(1);\n });\n\n it(\"should keep one route per name, the last definition winning\", async () => {\n const spyBuiltIn = vi.fn();\n const spyOverride = vi.fn();\n\n const history = createMemoryHistory();\n history.replace(\"/dashboard\");\n\n const gateway = new HistoryRouterGateway(history, \"\");\n gateway.setRoutes([\n { name: \"dashboard\", path: \"/dashboard\", onMatch: spyBuiltIn },\n { name: \"dashboard\", path: \"/dashboard\", onMatch: spyOverride }\n ]);\n\n expect(spyBuiltIn).toHaveBeenCalledTimes(0);\n expect(spyOverride).toHaveBeenCalledTimes(1);\n });\n});\n"],"names":["wait","Promise","resolve","setTimeout","describe","beforeEach","vi","it","spyHome","spyLogin","spyDynamic","history","createMemoryHistory","gateway","HistoryRouterGateway","expect","urls","RouteUrl","spyFileManager","urlWithBase","urlWithBaseAndParams","spyWildcard","spySpecific","spyUsers","spyBuiltIn","spyOverride"],"mappings":";;;;AAKA,MAAMA,OAAO,IAAM,IAAIC,QAAQC,CAAAA,UAAWC,WAAWD,SAAS;AAE9DE,SAAS,kBAAkB;IACvBC,WAAW;QACPC,GAAG,aAAa;IACpB;IAEAC,GAAG,+CAA+C;QAC9C,MAAMC,UAAUF,GAAG,EAAE;QACrB,MAAMG,WAAWH,GAAG,EAAE;QACtB,MAAMI,aAAaJ,GAAG,EAAE;QAGxB,MAAMK,UAAUC;QAChBD,QAAQ,OAAO,CAAC;QAEhB,MAAME,UAAU,IAAIC,qBAAqBH,SAAS;QAClDE,QAAQ,SAAS,CAAC;YACd;gBAAE,MAAM;gBAAQ,MAAM;gBAAK,SAASL;YAAQ;YAC5C;gBAAE,MAAM;gBAAS,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AAE,MAAM;YAAY,UAAU;QAAe;QAGzEJ,QAAQ,IAAI,CAAC;QACb,MAAMX;QAENe,OAAOQ,UAAU,qBAAqB,CAAC;IAC3C;IAEAhB,GAAG,+DAA+D;QAC9D,MAAMiB,aAAalB,GAAG,EAAE;QACxB,MAAMmB,cAAcnB,GAAG,EAAE;QAEzB,MAAMK,UAAUC;QAChBD,QAAQ,OAAO,CAAC;QAEhB,MAAME,UAAU,IAAIC,qBAAqBH,SAAS;QAClDE,QAAQ,SAAS,CAAC;YACd;gBAAE,MAAM;gBAAa,MAAM;gBAAc,SAASW;YAAW;YAC7D;gBAAE,MAAM;gBAAa,MAAM;gBAAc,SAASC;YAAY;SACjE;QAEDV,OAAOS,YAAY,qBAAqB,CAAC;QACzCT,OAAOU,aAAa,qBAAqB,CAAC;IAC9C;AACJ"}
|
|
@@ -11,9 +11,16 @@ export declare class Router {
|
|
|
11
11
|
private baseUrl;
|
|
12
12
|
constructor(baseUrl?: string);
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* Replace the route definitions with `routes`, the complete current set.
|
|
15
15
|
*
|
|
16
|
-
*
|
|
16
|
+
* A route that is not in `routes` is dropped. Merging instead would keep routes that the config
|
|
17
|
+
* no longer registers, for example one behind `HasPermission` after the user changes, and the
|
|
18
|
+
* current URL would keep matching it.
|
|
19
|
+
*
|
|
20
|
+
* Names stay unique: a later definition with the same name replaces the earlier one in its
|
|
21
|
+
* position, which is how a route from the config overrides a built-in one.
|
|
22
|
+
*
|
|
23
|
+
* @param routes - All route definitions.
|
|
17
24
|
*/
|
|
18
25
|
setRoutes(routes: RouteDefinition[]): void;
|
|
19
26
|
/**
|
|
@@ -5,11 +5,10 @@ class Router {
|
|
|
5
5
|
this.baseUrl = baseUrl;
|
|
6
6
|
}
|
|
7
7
|
setRoutes(routes) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
});
|
|
8
|
+
const byName = new Map();
|
|
9
|
+
for (const route of routes)byName.set(route.name, route);
|
|
10
|
+
const uniqueRoutes = byName.values();
|
|
11
|
+
this.routes = Array.from(uniqueRoutes);
|
|
13
12
|
this.sortRoutes();
|
|
14
13
|
}
|
|
15
14
|
findRoute(name) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/router/Router.js","sources":["../../../src/features/router/Router.ts"],"sourcesContent":["import type { RouteDefinition, MatchedRoute } from \"./abstractions.js\";\nimport { RouteUrl } from \"./RouteUrl.js\";\n\ninterface ResolveResult {\n matchedRoute: MatchedRoute;\n onMatch: (route: MatchedRoute) => void;\n}\n\n/**\n * Router manages a collection of route definitions and resolves pathnames to matched routes.\n */\nexport class Router {\n private routes: RouteDefinition[] = [];\n private baseUrl: string;\n\n constructor(baseUrl: string = \"\") {\n this.baseUrl = baseUrl;\n }\n\n /**\n *
|
|
1
|
+
{"version":3,"file":"features/router/Router.js","sources":["../../../src/features/router/Router.ts"],"sourcesContent":["import type { RouteDefinition, MatchedRoute } from \"./abstractions.js\";\nimport { RouteUrl } from \"./RouteUrl.js\";\n\ninterface ResolveResult {\n matchedRoute: MatchedRoute;\n onMatch: (route: MatchedRoute) => void;\n}\n\n/**\n * Router manages a collection of route definitions and resolves pathnames to matched routes.\n */\nexport class Router {\n private routes: RouteDefinition[] = [];\n private baseUrl: string;\n\n constructor(baseUrl: string = \"\") {\n this.baseUrl = baseUrl;\n }\n\n /**\n * Replace the route definitions with `routes`, the complete current set.\n *\n * A route that is not in `routes` is dropped. Merging instead would keep routes that the config\n * no longer registers, for example one behind `HasPermission` after the user changes, and the\n * current URL would keep matching it.\n *\n * Names stay unique: a later definition with the same name replaces the earlier one in its\n * position, which is how a route from the config overrides a built-in one.\n *\n * @param routes - All route definitions.\n */\n setRoutes(routes: RouteDefinition[]): void {\n const byName = new Map<string, RouteDefinition>();\n for (const route of routes) {\n byName.set(route.name, route);\n }\n\n const uniqueRoutes = byName.values();\n this.routes = Array.from(uniqueRoutes);\n\n this.sortRoutes();\n }\n\n /**\n * Find a route by name.\n *\n * @param name - Route name to find\n * @returns Route definition if found, undefined otherwise\n */\n findRoute(name: string): RouteDefinition | undefined {\n return this.routes.find(r => r.name === name);\n }\n\n /**\n * Resolve a pathname to a matched route.\n * The pathname will be matched against patterns after stripping the baseUrl.\n *\n * @param pathname - The pathname to resolve (e.g., '/tenant123/cms/entries/123')\n * @param queryParams - Optional query parameters to merge into route params\n * @returns Matched route with onMatch callback, or null if no route matches\n */\n resolve(pathname: string, queryParams?: Record<string, unknown>): ResolveResult | null {\n for (const route of this.routes) {\n const pattern = route.path === \"*\" ? \"(.*)\" : route.path;\n const matchResult = RouteUrl.match(pathname, pattern, this.baseUrl);\n\n if (matchResult) {\n const matchedRoute: MatchedRoute = {\n name: route.name,\n path: route.path,\n pathname,\n params: { ...matchResult.params, ...(queryParams || {}) }\n };\n\n const onMatch = (matched: MatchedRoute) => {\n route.onMatch(matched);\n };\n\n return { matchedRoute, onMatch };\n }\n }\n\n return null;\n }\n\n /**\n * Get the current baseUrl.\n */\n getBaseUrl(): string {\n return this.baseUrl;\n }\n\n /**\n * Sort routes to ensure proper matching order.\n * Wildcard routes (*) and index routes (/) are moved to the bottom.\n */\n private sortRoutes(): void {\n const INDEX_PATH = \"/\";\n const WILDCARD_PATTERNS = [\"*\", \"(.*)\"];\n\n this.routes.sort((a, b) => {\n const pathA = a.path || \"*\";\n const pathB = b.path || \"*\";\n\n const isWildcardA = WILDCARD_PATTERNS.includes(pathA);\n const isWildcardB = WILDCARD_PATTERNS.includes(pathB);\n const isIndexA = pathA === INDEX_PATH;\n const isIndexB = pathB === INDEX_PATH;\n\n // Both are wildcards or both are index - maintain order\n if ((isWildcardA && isWildcardB) || (isIndexA && isIndexB)) {\n return 0;\n }\n\n // Index path should come before wildcard\n if (isIndexA && isWildcardB) {\n return -1;\n }\n if (isWildcardA && isIndexB) {\n return 1;\n }\n\n // Push wildcards to the bottom\n if (isWildcardA) {\n return 1;\n }\n if (isWildcardB) {\n return -1;\n }\n\n // Push index to the bottom (but above wildcards)\n if (isIndexA) {\n return 1;\n }\n if (isIndexB) {\n return -1;\n }\n\n // All other routes maintain their order\n return 0;\n });\n }\n}\n"],"names":["Router","baseUrl","routes","byName","Map","route","uniqueRoutes","Array","name","r","pathname","queryParams","pattern","matchResult","RouteUrl","matchedRoute","onMatch","matched","INDEX_PATH","WILDCARD_PATTERNS","a","b","pathA","pathB","isWildcardA","isWildcardB","isIndexA","isIndexB"],"mappings":";AAWO,MAAMA;IAIT,YAAYC,UAAkB,EAAE,CAAE;aAH1B,MAAM,GAAsB,EAAE;QAIlC,IAAI,CAAC,OAAO,GAAGA;IACnB;IAcA,UAAUC,MAAyB,EAAQ;QACvC,MAAMC,SAAS,IAAIC;QACnB,KAAK,MAAMC,SAASH,OAChBC,OAAO,GAAG,CAACE,MAAM,IAAI,EAAEA;QAG3B,MAAMC,eAAeH,OAAO,MAAM;QAClC,IAAI,CAAC,MAAM,GAAGI,MAAM,IAAI,CAACD;QAEzB,IAAI,CAAC,UAAU;IACnB;IAQA,UAAUE,IAAY,EAA+B;QACjD,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAACC,CAAAA,IAAKA,EAAE,IAAI,KAAKD;IAC5C;IAUA,QAAQE,QAAgB,EAAEC,WAAqC,EAAwB;QACnF,KAAK,MAAMN,SAAS,IAAI,CAAC,MAAM,CAAE;YAC7B,MAAMO,UAAUP,AAAe,QAAfA,MAAM,IAAI,GAAW,SAASA,MAAM,IAAI;YACxD,MAAMQ,cAAcC,SAAS,KAAK,CAACJ,UAAUE,SAAS,IAAI,CAAC,OAAO;YAElE,IAAIC,aAAa;gBACb,MAAME,eAA6B;oBAC/B,MAAMV,MAAM,IAAI;oBAChB,MAAMA,MAAM,IAAI;oBAChBK;oBACA,QAAQ;wBAAE,GAAGG,YAAY,MAAM;wBAAE,GAAIF,eAAe,CAAC,CAAC;oBAAE;gBAC5D;gBAEA,MAAMK,UAAU,CAACC;oBACbZ,MAAM,OAAO,CAACY;gBAClB;gBAEA,OAAO;oBAAEF;oBAAcC;gBAAQ;YACnC;QACJ;QAEA,OAAO;IACX;IAKA,aAAqB;QACjB,OAAO,IAAI,CAAC,OAAO;IACvB;IAMQ,aAAmB;QACvB,MAAME,aAAa;QACnB,MAAMC,oBAAoB;YAAC;YAAK;SAAO;QAEvC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAACC,GAAGC;YACjB,MAAMC,QAAQF,EAAE,IAAI,IAAI;YACxB,MAAMG,QAAQF,EAAE,IAAI,IAAI;YAExB,MAAMG,cAAcL,kBAAkB,QAAQ,CAACG;YAC/C,MAAMG,cAAcN,kBAAkB,QAAQ,CAACI;YAC/C,MAAMG,WAAWJ,UAAUJ;YAC3B,MAAMS,WAAWJ,UAAUL;YAG3B,IAAKM,eAAeC,eAAiBC,YAAYC,UAC7C,OAAO;YAIX,IAAID,YAAYD,aACZ,OAAO;YAEX,IAAID,eAAeG,UACf,OAAO;YAIX,IAAIH,aACA,OAAO;YAEX,IAAIC,aACA,OAAO;YAIX,IAAIC,UACA,OAAO;YAEX,IAAIC,UACA,OAAO;YAIX,OAAO;QACX;IACJ;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/app",
|
|
3
|
-
"version": "6.6.0-alpha.
|
|
3
|
+
"version": "6.6.0-alpha.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -18,32 +18,32 @@
|
|
|
18
18
|
],
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@types/react": "
|
|
22
|
-
"@webiny/di": "
|
|
23
|
-
"@webiny/feature": "6.6.0-alpha.
|
|
24
|
-
"@webiny/i18n": "6.6.0-alpha.
|
|
25
|
-
"@webiny/i18n-react": "6.6.0-alpha.
|
|
26
|
-
"@webiny/plugins": "6.6.0-alpha.
|
|
27
|
-
"@webiny/react-composition": "6.6.0-alpha.
|
|
28
|
-
"@webiny/react-properties": "6.6.0-alpha.
|
|
21
|
+
"@types/react": "19.3.0",
|
|
22
|
+
"@webiny/di": "2.0.0",
|
|
23
|
+
"@webiny/feature": "6.6.0-alpha.10",
|
|
24
|
+
"@webiny/i18n": "6.6.0-alpha.10",
|
|
25
|
+
"@webiny/i18n-react": "6.6.0-alpha.10",
|
|
26
|
+
"@webiny/plugins": "6.6.0-alpha.10",
|
|
27
|
+
"@webiny/react-composition": "6.6.0-alpha.10",
|
|
28
|
+
"@webiny/react-properties": "6.6.0-alpha.10",
|
|
29
29
|
"graphql": "16.14.2",
|
|
30
30
|
"history": "5.3.0",
|
|
31
31
|
"invariant": "2.2.4",
|
|
32
32
|
"lodash": "4.18.1",
|
|
33
|
-
"mobx": "7.
|
|
34
|
-
"react": "
|
|
35
|
-
"react-dom": "
|
|
33
|
+
"mobx": "7.1.4",
|
|
34
|
+
"react": "19.3.1",
|
|
35
|
+
"react-dom": "19.3.1",
|
|
36
36
|
"warning": "4.0.3",
|
|
37
|
-
"zod": "4.
|
|
37
|
+
"zod": "4.6.7"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@types/lodash": "4.17.
|
|
40
|
+
"@types/lodash": "4.17.27",
|
|
41
41
|
"@types/warning": "3.0.4",
|
|
42
|
-
"@webiny/build-tools": "6.6.0-alpha.
|
|
42
|
+
"@webiny/build-tools": "6.6.0-alpha.10",
|
|
43
43
|
"rimraf": "6.1.3",
|
|
44
|
-
"type-fest": "5.
|
|
44
|
+
"type-fest": "5.10.0",
|
|
45
45
|
"typescript": "7.0.2",
|
|
46
|
-
"vitest": "
|
|
46
|
+
"vitest": "5.0.5"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|