@malloy-publisher/sdk 0.10.7 → 0.11.0
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/dist/{RenderedResult-BlYdT4lz.cjs.js → RenderedResult-C2r3Zkwl.cjs.js} +1 -1
- package/dist/{RenderedResult-B_sW7neX.es.js → RenderedResult-r3dg2xOJ.es.js} +2 -2
- package/dist/ServerProvider-CFHqDHFO.cjs.js +1 -0
- package/dist/{ServerProvider-BN399NH6.es.js → ServerProvider-DdGjhDhY.es.js} +2077 -1604
- package/dist/builder/index.cjs.js +1 -1
- package/dist/builder/index.es.js +3 -3
- package/dist/client/api.d.ts +673 -165
- package/dist/client/configuration.d.ts +1 -1
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.es.js +101 -92
- package/dist/components/Materializations/Materializations.d.ts +8 -1
- package/dist/components/Package/Package.d.ts +15 -1
- package/dist/components/Package/VersionSwitch.d.ts +51 -0
- package/dist/components/Package/index.d.ts +2 -0
- package/dist/components/Package/usePackageVersions.d.ts +48 -0
- package/dist/components/ServerProvider.d.ts +2 -1
- package/dist/hooks/useDimensionFiltersQuery.d.ts +2 -0
- package/dist/index.cjs.js +14 -14
- package/dist/index.es.js +8290 -7677
- package/dist/{useCompiledDocument-xJRD5DRP.es.js → useCompiledDocument-Bc0HuUtz.es.js} +3 -3
- package/dist/{useCompiledDocument-CyPOSStA.cjs.js → useCompiledDocument-QgySwHGA.cjs.js} +2 -2
- package/dist/utils/dataAppEmbed.d.ts +6 -1
- package/package.json +1 -1
- package/src/components/DataAppViewer/DataAppViewer.tsx +18 -5
- package/src/components/DocumentStorage/DocumentStorage.contract.spec.tsx +2 -0
- package/src/components/Environment/Packages.tsx +12 -5
- package/src/components/Environment/Packages.versions.spec.tsx +62 -0
- package/src/components/Materializations/Materializations.tsx +26 -6
- package/src/components/Materializations/Materializations.versions.spec.tsx +101 -0
- package/src/components/Package/Package.agents.spec.tsx +2 -0
- package/src/components/Package/Package.artifacts.spec.tsx +35 -0
- package/src/components/Package/Package.create.spec.tsx +37 -1
- package/src/components/Package/Package.notebooks.spec.tsx +2 -0
- package/src/components/Package/Package.spec.tsx +23 -11
- package/src/components/Package/Package.tsx +111 -20
- package/src/components/Package/VersionSwitch.spec.tsx +668 -0
- package/src/components/Package/VersionSwitch.tsx +779 -0
- package/src/components/Package/index.ts +7 -0
- package/src/components/Package/usePackageVersions.spec.tsx +78 -0
- package/src/components/Package/usePackageVersions.ts +146 -0
- package/src/components/ReportBuilder/ReportBuilder.controls.spec.tsx +4 -2
- package/src/components/ReportBuilder/ReportEditor.authoritative.spec.tsx +5 -1
- package/src/components/ServerProvider.tsx +2 -0
- package/src/hooks/useDimensionFiltersFromSpec.ts +1 -0
- package/src/hooks/useDimensionFiltersQuery.ts +5 -1
- package/src/utils/dataAppEmbed.spec.ts +27 -0
- package/src/utils/dataAppEmbed.ts +11 -3
- package/src/utils/formatting.spec.ts +25 -0
- package/src/utils/formatting.ts +2 -1
- package/test/serverProvider.tsx +15 -0
- package/dist/ServerProvider-e2369oom.cjs.js +0 -1
|
@@ -24,3 +24,10 @@ export {
|
|
|
24
24
|
} from "./NewDocumentDialog";
|
|
25
25
|
// Exported so a host decides Retry on its own failed requests as the dialog does.
|
|
26
26
|
export { canRetryRequest } from "../DocumentCreate/canRetry";
|
|
27
|
+
export {
|
|
28
|
+
packageVersionsQueryKey,
|
|
29
|
+
useInvalidatePackage,
|
|
30
|
+
usePackageVersions,
|
|
31
|
+
type PackageVersions,
|
|
32
|
+
} from "./usePackageVersions";
|
|
33
|
+
export { VersionSwitch, type VersionSwitchProps } from "./VersionSwitch";
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A package's version listing: what reads as "no versions" and what reads as
|
|
6
|
+
* a failure. A 404 (a package with none) and a 501 (a server, or a proxy in
|
|
7
|
+
* front of one, without the route) are no versions; anything else is a
|
|
8
|
+
* failure, so the page never treats a package it knows nothing about as one
|
|
9
|
+
* it may edit.
|
|
10
|
+
*/
|
|
11
|
+
import { beforeEach, describe, expect, it, mock } from "bun:test";
|
|
12
|
+
import { renderHook, waitFor } from "@testing-library/react";
|
|
13
|
+
import {
|
|
14
|
+
cacheKeys,
|
|
15
|
+
clearCache,
|
|
16
|
+
mockServerProvider,
|
|
17
|
+
serverWrapper,
|
|
18
|
+
TEST_SERVER,
|
|
19
|
+
} from "../../../test/serverProvider";
|
|
20
|
+
|
|
21
|
+
let answer: () => Promise<unknown> = () => Promise.resolve({ data: [] });
|
|
22
|
+
const listPackageVersions = mock((_env: string, _pkg: string) => answer());
|
|
23
|
+
|
|
24
|
+
mockServerProvider({ versions: { listPackageVersions } });
|
|
25
|
+
|
|
26
|
+
const { usePackageVersions } = await import("./usePackageVersions");
|
|
27
|
+
|
|
28
|
+
const failing = (status: number) => () =>
|
|
29
|
+
Promise.reject(
|
|
30
|
+
Object.assign(new Error(`Request failed with status code ${status}`), {
|
|
31
|
+
response: { status, data: { message: "no" } },
|
|
32
|
+
}),
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
clearCache();
|
|
37
|
+
listPackageVersions.mockClear();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe("usePackageVersions", () => {
|
|
41
|
+
it.each([404, 501])(
|
|
42
|
+
"reads a %d as no versions, without an error",
|
|
43
|
+
async (status) => {
|
|
44
|
+
answer = failing(status);
|
|
45
|
+
const { result } = renderHook(() => usePackageVersions("env", "pkg"), {
|
|
46
|
+
wrapper: serverWrapper,
|
|
47
|
+
});
|
|
48
|
+
await waitFor(() => expect(result.current.isPending).toBe(false));
|
|
49
|
+
expect(result.current.versions).toEqual([]);
|
|
50
|
+
expect(result.current.isError).toBe(false);
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
it.each([500, 403])(
|
|
55
|
+
"says a %d failed, rather than that there are no versions",
|
|
56
|
+
async (status) => {
|
|
57
|
+
answer = failing(status);
|
|
58
|
+
const { result } = renderHook(() => usePackageVersions("env", "pkg"), {
|
|
59
|
+
wrapper: serverWrapper,
|
|
60
|
+
});
|
|
61
|
+
await waitFor(() => expect(result.current.isError).toBe(true));
|
|
62
|
+
expect(result.current.versions).toEqual([]);
|
|
63
|
+
// Asked once: a failure is not retried behind the page's back.
|
|
64
|
+
expect(listPackageVersions).toHaveBeenCalledTimes(1);
|
|
65
|
+
},
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
it("keys the listing by server, as every other query", async () => {
|
|
69
|
+
answer = () => Promise.resolve({ data: [] });
|
|
70
|
+
const { result } = renderHook(() => usePackageVersions("env", "pkg"), {
|
|
71
|
+
wrapper: serverWrapper,
|
|
72
|
+
});
|
|
73
|
+
await waitFor(() => expect(result.current.isPending).toBe(false));
|
|
74
|
+
expect(cacheKeys("packageVersions")).toEqual([
|
|
75
|
+
JSON.stringify(["packageVersions", "env", "pkg", TEST_SERVER]),
|
|
76
|
+
]);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
5
|
+
import { useCallback } from "react";
|
|
6
|
+
import type { PackageVersion } from "../../client";
|
|
7
|
+
import { useServer } from "../ServerProvider";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The query key of a package's version listing, shared by every reader. The
|
|
11
|
+
* server comes last, as every other SDK query carries it, so two servers
|
|
12
|
+
* with the same environment and package names never share a list.
|
|
13
|
+
*/
|
|
14
|
+
export const packageVersionsQueryKey = (
|
|
15
|
+
environmentName: string,
|
|
16
|
+
packageName: string,
|
|
17
|
+
server: string,
|
|
18
|
+
) => ["packageVersions", environmentName, packageName, server] as const;
|
|
19
|
+
|
|
20
|
+
export interface PackageVersions {
|
|
21
|
+
/** Highest first, archived ones included. Empty for a package with none. */
|
|
22
|
+
versions: PackageVersion[];
|
|
23
|
+
/** The version a request that names none is served from, if there is one. */
|
|
24
|
+
latest: string | undefined;
|
|
25
|
+
/** True until the listing has answered once. */
|
|
26
|
+
isPending: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* True when the listing failed, so whether the package has versions is
|
|
29
|
+
* unknown. A package with none is not a failure.
|
|
30
|
+
*/
|
|
31
|
+
isError: boolean;
|
|
32
|
+
/** Ask for the listing again. */
|
|
33
|
+
refetch: () => void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A package's versions, as the server lists them. A 404 (a package with no
|
|
38
|
+
* versions, or a server that predates them) and a 501 (a server, or a proxy
|
|
39
|
+
* in front of one, that does not serve the route) both mean no versions; any
|
|
40
|
+
* other failure is thrown, so a reader can tell "none" from "unknown".
|
|
41
|
+
*/
|
|
42
|
+
async function listVersions(
|
|
43
|
+
apiClients: ReturnType<typeof useServer>["apiClients"],
|
|
44
|
+
environmentName: string,
|
|
45
|
+
packageName: string,
|
|
46
|
+
): Promise<PackageVersion[]> {
|
|
47
|
+
try {
|
|
48
|
+
const response = await apiClients.versions.listPackageVersions(
|
|
49
|
+
environmentName,
|
|
50
|
+
packageName,
|
|
51
|
+
);
|
|
52
|
+
return response.data;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
const status = (error as { response?: { status?: number } })?.response
|
|
55
|
+
?.status;
|
|
56
|
+
if (status === 404 || status === 501) return [];
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* A package's published versions.
|
|
63
|
+
*
|
|
64
|
+
* A package with none — versioning off, a package loaded from configuration —
|
|
65
|
+
* and a server that predates versions read as no versions, so the page draws
|
|
66
|
+
* exactly as it did before versions existed. A listing that failed reads as
|
|
67
|
+
* no versions too, but says so with `isError`: until it answers, nothing may
|
|
68
|
+
* assume the package can be edited.
|
|
69
|
+
*/
|
|
70
|
+
export function usePackageVersions(
|
|
71
|
+
environmentName: string,
|
|
72
|
+
packageName: string,
|
|
73
|
+
options: { enabled?: boolean } = {},
|
|
74
|
+
): PackageVersions {
|
|
75
|
+
const { apiClients, server } = useServer();
|
|
76
|
+
const enabled =
|
|
77
|
+
(options.enabled ?? true) && environmentName !== "" && packageName !== "";
|
|
78
|
+
const query = useQuery({
|
|
79
|
+
queryKey: packageVersionsQueryKey(environmentName, packageName, server),
|
|
80
|
+
queryFn: () => listVersions(apiClients, environmentName, packageName),
|
|
81
|
+
enabled,
|
|
82
|
+
staleTime: 30_000,
|
|
83
|
+
retry: false,
|
|
84
|
+
});
|
|
85
|
+
const { refetch: refetchQuery } = query;
|
|
86
|
+
const refetch = useCallback(() => void refetchQuery(), [refetchQuery]);
|
|
87
|
+
const versions = query.data ?? [];
|
|
88
|
+
return {
|
|
89
|
+
versions,
|
|
90
|
+
latest: versions.find((version) => version.latest)?.id,
|
|
91
|
+
isPending: enabled && query.isPending,
|
|
92
|
+
isError: enabled && query.isError,
|
|
93
|
+
refetch,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Read a package's versions now, never from the cache, and keep the answer
|
|
99
|
+
* for every other reader: what a change to a version is decided against,
|
|
100
|
+
* since another tab or client may have changed them since the page listed
|
|
101
|
+
* them. Rejects when the listing fails.
|
|
102
|
+
*/
|
|
103
|
+
export function useFetchPackageVersions(
|
|
104
|
+
environmentName: string,
|
|
105
|
+
packageName: string,
|
|
106
|
+
) {
|
|
107
|
+
const { apiClients, server } = useServer();
|
|
108
|
+
const queryClient = useQueryClient();
|
|
109
|
+
return useCallback(
|
|
110
|
+
() =>
|
|
111
|
+
queryClient.fetchQuery({
|
|
112
|
+
queryKey: packageVersionsQueryKey(
|
|
113
|
+
environmentName,
|
|
114
|
+
packageName,
|
|
115
|
+
server,
|
|
116
|
+
),
|
|
117
|
+
queryFn: () =>
|
|
118
|
+
listVersions(apiClients, environmentName, packageName),
|
|
119
|
+
staleTime: 0,
|
|
120
|
+
retry: false,
|
|
121
|
+
}),
|
|
122
|
+
[queryClient, apiClients, server, environmentName, packageName],
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Refresh everything drawn for one package: its version listing and every
|
|
128
|
+
* query keyed `[kind, environment, package, …]`. Moving `latest` or archiving
|
|
129
|
+
* a version changes what a request that names no version is served from, so
|
|
130
|
+
* nothing cached for the package can be trusted afterwards.
|
|
131
|
+
*/
|
|
132
|
+
export function useInvalidatePackage(
|
|
133
|
+
environmentName: string,
|
|
134
|
+
packageName: string,
|
|
135
|
+
) {
|
|
136
|
+
const queryClient = useQueryClient();
|
|
137
|
+
return useCallback(
|
|
138
|
+
() =>
|
|
139
|
+
queryClient.invalidateQueries({
|
|
140
|
+
predicate: (query) =>
|
|
141
|
+
query.queryKey[1] === environmentName &&
|
|
142
|
+
query.queryKey[2] === packageName,
|
|
143
|
+
}),
|
|
144
|
+
[queryClient, environmentName, packageName],
|
|
145
|
+
);
|
|
146
|
+
}
|
|
@@ -397,10 +397,12 @@ describe("a draft made before the report changed", () => {
|
|
|
397
397
|
const last = await mountIt();
|
|
398
398
|
await screen.findByText(/made before this report changed/);
|
|
399
399
|
act(() => last()?.add.text?.());
|
|
400
|
+
// A boolean, not the element: a failed toBeNull() on a happy-dom element
|
|
401
|
+
// formats its whole object graph, synchronously, on every poll.
|
|
400
402
|
await waitFor(() =>
|
|
401
403
|
expect(
|
|
402
|
-
screen.queryByText(/made before this report changed/),
|
|
403
|
-
).
|
|
404
|
+
screen.queryByText(/made before this report changed/) === null,
|
|
405
|
+
).toBe(true),
|
|
404
406
|
);
|
|
405
407
|
expect(last()?.restored).toBeUndefined();
|
|
406
408
|
// What is kept now is the edit, made over the current file.
|
|
@@ -656,8 +656,12 @@ describe("ReportEditor, when a new version of the file arrives", () => {
|
|
|
656
656
|
|
|
657
657
|
fireEvent.click(button("Load it"));
|
|
658
658
|
expect(await screen.findByText("Elsewhere")).toBeDefined();
|
|
659
|
+
// A boolean, not the element: a failed toBeNull() on a happy-dom element
|
|
660
|
+
// formats its whole object graph, synchronously, on every poll.
|
|
659
661
|
await waitFor(() =>
|
|
660
|
-
expect(
|
|
662
|
+
expect(
|
|
663
|
+
screen.queryByText(/changed since you opened it/) === null,
|
|
664
|
+
).toBe(true),
|
|
661
665
|
);
|
|
662
666
|
expect(button("Undo").hasAttribute("disabled")).toBe(true);
|
|
663
667
|
});
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
PackagesApi,
|
|
25
25
|
PublisherApi,
|
|
26
26
|
ReportsApi,
|
|
27
|
+
VersionsApi,
|
|
27
28
|
WatchModeApi,
|
|
28
29
|
} from "../client";
|
|
29
30
|
import { Configuration } from "../client/configuration";
|
|
@@ -165,6 +166,7 @@ const getApiClients = (
|
|
|
165
166
|
axiosInstance,
|
|
166
167
|
),
|
|
167
168
|
watchMode: new WatchModeApi(config, basePath, axiosInstance),
|
|
169
|
+
versions: new VersionsApi(config, basePath, axiosInstance),
|
|
168
170
|
};
|
|
169
171
|
};
|
|
170
172
|
|
|
@@ -26,6 +26,8 @@ export interface UseDimensionFiltersQueryParams {
|
|
|
26
26
|
fields?: string[];
|
|
27
27
|
/** Maximum number of results to return (default: 1000) */
|
|
28
28
|
limit?: number;
|
|
29
|
+
/** The published version to query; absent, the package's `latest`. */
|
|
30
|
+
versionId?: string;
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
/**
|
|
@@ -212,6 +214,7 @@ export function useDimensionFiltersQuery(
|
|
|
212
214
|
filterSelections,
|
|
213
215
|
fields,
|
|
214
216
|
limit = 1000,
|
|
217
|
+
versionId,
|
|
215
218
|
} = params;
|
|
216
219
|
|
|
217
220
|
// State to store the executed query result
|
|
@@ -232,8 +235,9 @@ export function useDimensionFiltersQuery(
|
|
|
232
235
|
environmentName: environment,
|
|
233
236
|
packageName,
|
|
234
237
|
modelPath: model,
|
|
238
|
+
versionId,
|
|
235
239
|
}),
|
|
236
|
-
[environment, packageName, model],
|
|
240
|
+
[environment, packageName, model, versionId],
|
|
237
241
|
);
|
|
238
242
|
|
|
239
243
|
// Check if query can be executed
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { describe, expect, it } from "bun:test";
|
|
5
5
|
import {
|
|
6
6
|
isPublisherResizeMessage,
|
|
7
|
+
packageFileUrl,
|
|
7
8
|
PUBLISHER_RESIZE_MESSAGE_TYPE,
|
|
8
9
|
serverBaseUrl,
|
|
9
10
|
} from "./dataAppEmbed";
|
|
@@ -31,6 +32,32 @@ describe("serverBaseUrl", () => {
|
|
|
31
32
|
});
|
|
32
33
|
});
|
|
33
34
|
|
|
35
|
+
describe("packageFileUrl", () => {
|
|
36
|
+
const at = (path: string, versionId?: string) =>
|
|
37
|
+
packageFileUrl({
|
|
38
|
+
server: "https://pub.example.com/api/v0",
|
|
39
|
+
environmentName: "env",
|
|
40
|
+
packageName: "pkg",
|
|
41
|
+
path,
|
|
42
|
+
...(versionId !== undefined ? { versionId } : {}),
|
|
43
|
+
});
|
|
44
|
+
it("names no version when given none, so the server serves latest", () => {
|
|
45
|
+
expect(at("public/index.html")).toBe(
|
|
46
|
+
"https://pub.example.com/environments/env/packages/pkg/index.html",
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
it("pins a version in the query string, encoding build metadata", () => {
|
|
50
|
+
expect(at("index.html", "1.2.0+build.5")).toBe(
|
|
51
|
+
"https://pub.example.com/environments/env/packages/pkg/index.html?versionId=1.2.0%2Bbuild.5",
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
it("adds the version to a path that already has a query", () => {
|
|
55
|
+
expect(at("app.html?tab=2", "1.2.0")).toBe(
|
|
56
|
+
"https://pub.example.com/environments/env/packages/pkg/app.html?tab=2&versionId=1.2.0",
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
34
61
|
describe("isPublisherResizeMessage", () => {
|
|
35
62
|
it("accepts a well-formed resize message", () => {
|
|
36
63
|
expect(
|
|
@@ -61,24 +61,32 @@ export function serverBaseUrl(server: string): string {
|
|
|
61
61
|
* the served path does not include it and a caller passing a path a reader typed
|
|
62
62
|
* would otherwise produce `public/public/<file>`, which 404s. The server's own
|
|
63
63
|
* redirect drops it for the same reason.
|
|
64
|
+
*
|
|
65
|
+
* `versionId` pins a published version: the static route reads it from the
|
|
66
|
+
* URL, and a page's runtime reads it there to pin its own queries. Absent, the
|
|
67
|
+
* server serves `latest`.
|
|
64
68
|
*/
|
|
65
69
|
export function packageFileUrl({
|
|
66
70
|
server,
|
|
67
71
|
environmentName,
|
|
68
72
|
packageName,
|
|
69
73
|
path,
|
|
74
|
+
versionId,
|
|
70
75
|
}: {
|
|
71
76
|
server: string;
|
|
72
77
|
environmentName: string;
|
|
73
78
|
packageName: string;
|
|
74
79
|
path: string;
|
|
80
|
+
versionId?: string;
|
|
75
81
|
}): string {
|
|
76
82
|
const relative = path.startsWith("public/")
|
|
77
83
|
? path.slice("public/".length)
|
|
78
84
|
: path;
|
|
79
|
-
|
|
85
|
+
const url =
|
|
80
86
|
`${serverBaseUrl(server)}/environments/${encodeURIComponent(
|
|
81
87
|
environmentName,
|
|
82
|
-
)}/packages/${encodeURIComponent(packageName)}/` + relative
|
|
83
|
-
|
|
88
|
+
)}/packages/${encodeURIComponent(packageName)}/` + relative;
|
|
89
|
+
return versionId === undefined
|
|
90
|
+
? url
|
|
91
|
+
: `${url}${url.includes("?") ? "&" : "?"}versionId=${encodeURIComponent(versionId)}`;
|
|
84
92
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
|
|
4
4
|
import { describe, expect, it } from "bun:test";
|
|
5
|
+
import { setSearchParams } from "../client/common";
|
|
5
6
|
import { encodeResourceUri, parseResourceUri } from "./formatting";
|
|
6
7
|
|
|
7
8
|
describe("parseResourceUri", () => {
|
|
@@ -137,3 +138,27 @@ describe("encodeResourceUri", () => {
|
|
|
137
138
|
).toThrow(/Failed to encode resource URI, missing environment name/);
|
|
138
139
|
});
|
|
139
140
|
});
|
|
141
|
+
|
|
142
|
+
describe("a versionId with build metadata", () => {
|
|
143
|
+
const versionId = "1.2.0+build.5";
|
|
144
|
+
|
|
145
|
+
it("round-trips through a resource URI", () => {
|
|
146
|
+
const uri = encodeResourceUri({
|
|
147
|
+
environmentName: "malloy-samples",
|
|
148
|
+
packageName: "names",
|
|
149
|
+
versionId,
|
|
150
|
+
});
|
|
151
|
+
expect(uri).toBe(
|
|
152
|
+
"publisher://environments/malloy-samples/packages/names?versionId=1.2.0%2Bbuild.5",
|
|
153
|
+
);
|
|
154
|
+
expect(parseResourceUri(uri).versionId).toBe(versionId);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("reaches the server intact from a generated client's query string", () => {
|
|
158
|
+
const url = new URL("http://localhost/api/v0/environments/e/packages/p");
|
|
159
|
+
setSearchParams(url, { versionId });
|
|
160
|
+
// What the server reads back from the query string.
|
|
161
|
+
expect(url.search).toBe("?versionId=1.2.0%2Bbuild.5");
|
|
162
|
+
expect(url.searchParams.get("versionId")).toBe(versionId);
|
|
163
|
+
});
|
|
164
|
+
});
|
package/src/utils/formatting.ts
CHANGED
|
@@ -57,7 +57,8 @@ export const encodeResourceUri = (resource: ParsedResource) => {
|
|
|
57
57
|
uri += `/models/${resource.modelPath}`;
|
|
58
58
|
}
|
|
59
59
|
if (resource.packageName && resource.versionId) {
|
|
60
|
-
|
|
60
|
+
// Encoded, so build metadata survives: a bare `+` reads back as a space.
|
|
61
|
+
uri += `?versionId=${encodeURIComponent(resource.versionId)}`;
|
|
61
62
|
}
|
|
62
63
|
return uri;
|
|
63
64
|
};
|
package/test/serverProvider.tsx
CHANGED
|
@@ -69,6 +69,21 @@ export function clearCache() {
|
|
|
69
69
|
globalQueryClient.clear();
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
/**
|
|
73
|
+
* The versions client of a server whose package has no versions: the listing
|
|
74
|
+
* answers 404, as the server does for a package with none. A spec that renders
|
|
75
|
+
* a package page and mocks no versions client reads this one, since a listing
|
|
76
|
+
* that fails otherwise (no client at all) turns the page's edits off.
|
|
77
|
+
*/
|
|
78
|
+
export const noVersions = {
|
|
79
|
+
listPackageVersions: () =>
|
|
80
|
+
Promise.reject(
|
|
81
|
+
Object.assign(new Error("Request failed with status code 404"), {
|
|
82
|
+
response: { status: 404, data: { message: "no versions" } },
|
|
83
|
+
}),
|
|
84
|
+
),
|
|
85
|
+
};
|
|
86
|
+
|
|
72
87
|
/** A request that never settles, so nothing renders past its loading state. */
|
|
73
88
|
export function pending<T = never>(): Promise<T> {
|
|
74
89
|
return new Promise<T>(() => {});
|