@osdk/widget.api 2.1.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/CHANGELOG.md +128 -0
- package/build/browser/config.js +41 -0
- package/build/browser/config.js.map +1 -0
- package/build/browser/config.test.js +243 -0
- package/build/browser/config.test.js.map +1 -0
- package/build/browser/index.js +22 -0
- package/build/browser/index.js.map +1 -0
- package/build/browser/manifest.js +18 -0
- package/build/browser/manifest.js.map +1 -0
- package/build/browser/manifest.test.js +57 -0
- package/build/browser/manifest.test.js.map +1 -0
- package/build/browser/messages/hostMessages.js +40 -0
- package/build/browser/messages/hostMessages.js.map +1 -0
- package/build/browser/messages/widgetMessages.js +37 -0
- package/build/browser/messages/widgetMessages.js.map +1 -0
- package/build/browser/messages/widgetMessages.test.js +94 -0
- package/build/browser/messages/widgetMessages.test.js.map +1 -0
- package/build/browser/metaTags.js +18 -0
- package/build/browser/metaTags.js.map +1 -0
- package/build/browser/parameters.js +23 -0
- package/build/browser/parameters.js.map +1 -0
- package/build/browser/parameters.test.js +38 -0
- package/build/browser/parameters.test.js.map +1 -0
- package/build/browser/utils/asyncValue.js +2 -0
- package/build/browser/utils/asyncValue.js.map +1 -0
- package/build/cjs/index.cjs +64 -0
- package/build/cjs/index.cjs.map +1 -0
- package/build/cjs/index.d.cts +289 -0
- package/build/esm/config.js +41 -0
- package/build/esm/config.js.map +1 -0
- package/build/esm/config.test.js +243 -0
- package/build/esm/config.test.js.map +1 -0
- package/build/esm/index.js +22 -0
- package/build/esm/index.js.map +1 -0
- package/build/esm/manifest.js +18 -0
- package/build/esm/manifest.js.map +1 -0
- package/build/esm/manifest.test.js +57 -0
- package/build/esm/manifest.test.js.map +1 -0
- package/build/esm/messages/hostMessages.js +40 -0
- package/build/esm/messages/hostMessages.js.map +1 -0
- package/build/esm/messages/widgetMessages.js +37 -0
- package/build/esm/messages/widgetMessages.js.map +1 -0
- package/build/esm/messages/widgetMessages.test.js +94 -0
- package/build/esm/messages/widgetMessages.test.js.map +1 -0
- package/build/esm/metaTags.js +18 -0
- package/build/esm/metaTags.js.map +1 -0
- package/build/esm/parameters.js +23 -0
- package/build/esm/parameters.js.map +1 -0
- package/build/esm/parameters.test.js +38 -0
- package/build/esm/parameters.test.js.map +1 -0
- package/build/esm/utils/asyncValue.js +2 -0
- package/build/esm/utils/asyncValue.js.map +1 -0
- package/build/types/config.d.ts +74 -0
- package/build/types/config.d.ts.map +1 -0
- package/build/types/config.test.d.ts +1 -0
- package/build/types/config.test.d.ts.map +1 -0
- package/build/types/index.d.ts +10 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/manifest.d.ts +64 -0
- package/build/types/manifest.d.ts.map +1 -0
- package/build/types/manifest.test.d.ts +1 -0
- package/build/types/manifest.test.d.ts.map +1 -0
- package/build/types/messages/hostMessages.d.ts +33 -0
- package/build/types/messages/hostMessages.d.ts.map +1 -0
- package/build/types/messages/widgetMessages.d.ts +36 -0
- package/build/types/messages/widgetMessages.d.ts.map +1 -0
- package/build/types/messages/widgetMessages.test.d.ts +1 -0
- package/build/types/messages/widgetMessages.test.d.ts.map +1 -0
- package/build/types/metaTags.d.ts +1 -0
- package/build/types/metaTags.d.ts.map +1 -0
- package/build/types/parameters.d.ts +43 -0
- package/build/types/parameters.d.ts.map +1 -0
- package/build/types/parameters.test.d.ts +1 -0
- package/build/types/parameters.test.d.ts.map +1 -0
- package/build/types/utils/asyncValue.d.ts +38 -0
- package/build/types/utils/asyncValue.d.ts.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widgetMessages.js","names":["WidgetMessage","isWidgetReadyMessage","event","type","isWidgetEmitEventMessage","visitWidgetMessage","message","visitor","payload","handler","_unknown"],"sources":["widgetMessages.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n EventId,\n EventParameterValueMap,\n WidgetConfig,\n} from \"../config.js\";\nimport type { HostMessage } from \"./hostMessages.js\";\n\n// Interfaces and type guards for messages passed from the widget to the host Foundry UI\n\ninterface WidgetBaseMessage<T extends string, P = unknown> {\n type: T;\n payload: P;\n}\n\ntype EmitEventIdMap<C extends WidgetConfig<C[\"parameters\"]>> = {\n [K in EventId<C>]: {\n eventId: K;\n parameterUpdates: EventParameterValueMap<C, K>;\n };\n};\n\nexport namespace WidgetMessage {\n export namespace Payload {\n export interface Ready {\n apiVersion: HostMessage.Version;\n }\n\n export type EmitEvent<C extends WidgetConfig<C[\"parameters\"]>> =\n EmitEventIdMap<C>[EventId<C>];\n }\n\n export type Payload<C extends WidgetConfig<C[\"parameters\"]>> =\n | Payload.Ready\n | Payload.EmitEvent<C>;\n\n /**\n * Emit when the widget is ready to start receiving messages from the host Foundry UI\n */\n export interface Ready\n extends WidgetBaseMessage<\"widget.ready\", Payload.Ready>\n {}\n\n /**\n * Event payload that the widget sends to the host Foundry UI\n */\n export interface EmitEvent<C extends WidgetConfig<C[\"parameters\"]>>\n extends WidgetBaseMessage<\"widget.emit-event\", Payload.EmitEvent<C>>\n {}\n}\n\nexport type WidgetMessage<C extends WidgetConfig<C[\"parameters\"]>> =\n | WidgetMessage.Ready\n | WidgetMessage.EmitEvent<C>;\n\nexport function isWidgetReadyMessage<C extends WidgetConfig<C[\"parameters\"]>>(\n event: WidgetMessage<C>,\n): event is WidgetMessage.Ready {\n return event.type === \"widget.ready\";\n}\n\nexport function isWidgetEmitEventMessage<\n C extends WidgetConfig<C[\"parameters\"]>,\n>(event: WidgetMessage<C>): event is WidgetMessage.EmitEvent<C> {\n return event.type === \"widget.emit-event\";\n}\n\ntype WidgetMessageVisitor<C extends WidgetConfig<C[\"parameters\"]>> =\n & {\n [T in WidgetMessage<C>[\"type\"]]: (\n payload: Extract<WidgetMessage<C>, { type: T }> extends {\n payload: infer P;\n } ? P\n : never,\n ) => void;\n }\n & {\n _unknown: (type: string) => void;\n };\n\nexport function visitWidgetMessage<C extends WidgetConfig<C[\"parameters\"]>>(\n message: WidgetMessage<C>,\n visitor: WidgetMessageVisitor<C>,\n): void {\n const { type, payload } = message;\n const handler = visitor[type];\n if (handler) {\n // Typescript creates an & of the parameters instead of a union\n (handler as any)(payload);\n } else {\n visitor._unknown(type);\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AASA;AAAA,WAciBA,aAAa;AAiC9B,OAAO,SAASC,oBAAoBA,CAClCC,KAAuB,EACO;EAC9B,OAAOA,KAAK,CAACC,IAAI,KAAK,cAAc;AACtC;AAEA,OAAO,SAASC,wBAAwBA,CAEtCF,KAAuB,EAAuC;EAC9D,OAAOA,KAAK,CAACC,IAAI,KAAK,mBAAmB;AAC3C;AAeA,OAAO,SAASE,kBAAkBA,CAChCC,OAAyB,EACzBC,OAAgC,EAC1B;EACN,MAAM;IAAEJ,IAAI;IAAEK;EAAQ,CAAC,GAAGF,OAAO;EACjC,MAAMG,OAAO,GAAGF,OAAO,CAACJ,IAAI,CAAC;EAC7B,IAAIM,OAAO,EAAE;IACX;IACCA,OAAO,CAASD,OAAO,CAAC;EAC3B,CAAC,MAAM;IACLD,OAAO,CAACG,QAAQ,CAACP,IAAI,CAAC;EACxB;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { describe, expectTypeOf, it } from "vitest";
|
|
18
|
+
import { defineConfig } from "../config.js";
|
|
19
|
+
describe("WidgetMessages", () => {
|
|
20
|
+
describe("EmitEvent", () => {
|
|
21
|
+
it("should emit an event with the correct payload", () => {
|
|
22
|
+
defineConfig({
|
|
23
|
+
id: "widgetId",
|
|
24
|
+
name: "Widget Name",
|
|
25
|
+
description: "Widget Description",
|
|
26
|
+
type: "workshop",
|
|
27
|
+
parameters: {
|
|
28
|
+
test: {
|
|
29
|
+
displayName: "Testing",
|
|
30
|
+
type: "array",
|
|
31
|
+
subType: "boolean"
|
|
32
|
+
},
|
|
33
|
+
test2: {
|
|
34
|
+
displayName: "Testing 2",
|
|
35
|
+
type: "array",
|
|
36
|
+
subType: "string"
|
|
37
|
+
},
|
|
38
|
+
test3: {
|
|
39
|
+
displayName: "Testing 3",
|
|
40
|
+
type: "number"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
events: {
|
|
44
|
+
myEvent: {
|
|
45
|
+
displayName: "My Event",
|
|
46
|
+
parameterUpdateIds: ["test"]
|
|
47
|
+
},
|
|
48
|
+
myEvent2: {
|
|
49
|
+
displayName: "My Event 2",
|
|
50
|
+
parameterUpdateIds: ["test", "test2"]
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
expectTypeOf().toMatchTypeOf();
|
|
55
|
+
expectTypeOf().toMatchTypeOf();
|
|
56
|
+
});
|
|
57
|
+
it("should be able to assign specific events to the union", () => {
|
|
58
|
+
defineConfig({
|
|
59
|
+
id: "widgetId",
|
|
60
|
+
name: "Widget Name",
|
|
61
|
+
description: "Widget Description",
|
|
62
|
+
type: "workshop",
|
|
63
|
+
parameters: {
|
|
64
|
+
test: {
|
|
65
|
+
displayName: "Testing",
|
|
66
|
+
type: "array",
|
|
67
|
+
subType: "boolean"
|
|
68
|
+
},
|
|
69
|
+
test2: {
|
|
70
|
+
displayName: "Testing 2",
|
|
71
|
+
type: "array",
|
|
72
|
+
subType: "string"
|
|
73
|
+
},
|
|
74
|
+
test3: {
|
|
75
|
+
displayName: "Testing 3",
|
|
76
|
+
type: "number"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
events: {
|
|
80
|
+
myEvent: {
|
|
81
|
+
displayName: "My Event",
|
|
82
|
+
parameterUpdateIds: ["test"]
|
|
83
|
+
},
|
|
84
|
+
myEvent2: {
|
|
85
|
+
displayName: "My Event 2",
|
|
86
|
+
parameterUpdateIds: ["test", "test2"]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
expectTypeOf().toMatchTypeOf();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
//# sourceMappingURL=widgetMessages.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widgetMessages.test.js","names":["describe","expectTypeOf","it","defineConfig","id","name","description","type","parameters","test","displayName","subType","test2","test3","events","myEvent","parameterUpdateIds","myEvent2","toMatchTypeOf"],"sources":["widgetMessages.test.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { describe, expectTypeOf, it } from \"vitest\";\nimport { defineConfig } from \"../config.js\";\nimport type { WidgetMessage } from \"./widgetMessages.js\";\n\ndescribe(\"WidgetMessages\", () => {\n describe(\"EmitEvent\", () => {\n it(\"should emit an event with the correct payload\", () => {\n const test = defineConfig({\n id: \"widgetId\",\n name: \"Widget Name\",\n description: \"Widget Description\",\n type: \"workshop\",\n parameters: {\n test: {\n displayName: \"Testing\",\n type: \"array\",\n subType: \"boolean\",\n },\n test2: {\n displayName: \"Testing 2\",\n type: \"array\",\n subType: \"string\",\n },\n test3: {\n displayName: \"Testing 3\",\n type: \"number\",\n },\n },\n events: {\n myEvent: {\n displayName: \"My Event\",\n parameterUpdateIds: [\"test\"],\n },\n myEvent2: {\n displayName: \"My Event 2\",\n parameterUpdateIds: [\"test\", \"test2\"],\n },\n },\n });\n expectTypeOf<{\n type: \"widget.emit-event\";\n payload: {\n eventId: \"myEvent\";\n parameterUpdates: {\n test: boolean[];\n };\n };\n }>().toMatchTypeOf<WidgetMessage<typeof test>>();\n expectTypeOf<{\n eventId: \"myEvent2\";\n parameterUpdates: {\n test: boolean[];\n test2: string[];\n };\n }>().toMatchTypeOf<WidgetMessage.Payload.EmitEvent<typeof test>>();\n });\n\n it(\"should be able to assign specific events to the union\", () => {\n const test = defineConfig({\n id: \"widgetId\",\n name: \"Widget Name\",\n description: \"Widget Description\",\n type: \"workshop\",\n parameters: {\n test: {\n displayName: \"Testing\",\n type: \"array\",\n subType: \"boolean\",\n },\n test2: {\n displayName: \"Testing 2\",\n type: \"array\",\n subType: \"string\",\n },\n test3: {\n displayName: \"Testing 3\",\n type: \"number\",\n },\n },\n events: {\n myEvent: {\n displayName: \"My Event\",\n parameterUpdateIds: [\"test\"],\n },\n myEvent2: {\n displayName: \"My Event 2\",\n parameterUpdateIds: [\"test\", \"test2\"],\n },\n },\n });\n expectTypeOf<{\n type: \"widget.emit-event\";\n payload: {\n eventId: \"myEvent\";\n parameterUpdates: {\n test: boolean[];\n };\n };\n }>().toMatchTypeOf<WidgetMessage<typeof test>>();\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,QAAQ,EAAEC,YAAY,EAAEC,EAAE,QAAQ,QAAQ;AACnD,SAASC,YAAY,QAAQ,cAAc;AAG3CH,QAAQ,CAAC,gBAAgB,EAAE,MAAM;EAC/BA,QAAQ,CAAC,WAAW,EAAE,MAAM;IAC1BE,EAAE,CAAC,+CAA+C,EAAE,MAAM;MAC3CC,YAAY,CAAC;QACxBC,EAAE,EAAE,UAAU;QACdC,IAAI,EAAE,aAAa;QACnBC,WAAW,EAAE,oBAAoB;QACjCC,IAAI,EAAE,UAAU;QAChBC,UAAU,EAAE;UACVC,IAAI,EAAE;YACJC,WAAW,EAAE,SAAS;YACtBH,IAAI,EAAE,OAAO;YACbI,OAAO,EAAE;UACX,CAAC;UACDC,KAAK,EAAE;YACLF,WAAW,EAAE,WAAW;YACxBH,IAAI,EAAE,OAAO;YACbI,OAAO,EAAE;UACX,CAAC;UACDE,KAAK,EAAE;YACLH,WAAW,EAAE,WAAW;YACxBH,IAAI,EAAE;UACR;QACF,CAAC;QACDO,MAAM,EAAE;UACNC,OAAO,EAAE;YACPL,WAAW,EAAE,UAAU;YACvBM,kBAAkB,EAAE,CAAC,MAAM;UAC7B,CAAC;UACDC,QAAQ,EAAE;YACRP,WAAW,EAAE,YAAY;YACzBM,kBAAkB,EAAE,CAAC,MAAM,EAAE,OAAO;UACtC;QACF;MACF,CAAC,CAAC;MACFf,YAAY,CAQT,CAAC,CAACiB,aAAa,CAA6B,CAAC;MAChDjB,YAAY,CAMT,CAAC,CAACiB,aAAa,CAA+C,CAAC;IACpE,CAAC,CAAC;IAEFhB,EAAE,CAAC,uDAAuD,EAAE,MAAM;MACnDC,YAAY,CAAC;QACxBC,EAAE,EAAE,UAAU;QACdC,IAAI,EAAE,aAAa;QACnBC,WAAW,EAAE,oBAAoB;QACjCC,IAAI,EAAE,UAAU;QAChBC,UAAU,EAAE;UACVC,IAAI,EAAE;YACJC,WAAW,EAAE,SAAS;YACtBH,IAAI,EAAE,OAAO;YACbI,OAAO,EAAE;UACX,CAAC;UACDC,KAAK,EAAE;YACLF,WAAW,EAAE,WAAW;YACxBH,IAAI,EAAE,OAAO;YACbI,OAAO,EAAE;UACX,CAAC;UACDE,KAAK,EAAE;YACLH,WAAW,EAAE,WAAW;YACxBH,IAAI,EAAE;UACR;QACF,CAAC;QACDO,MAAM,EAAE;UACNC,OAAO,EAAE;YACPL,WAAW,EAAE,UAAU;YACvBM,kBAAkB,EAAE,CAAC,MAAM;UAC7B,CAAC;UACDC,QAAQ,EAAE;YACRP,WAAW,EAAE,YAAY;YACzBM,kBAAkB,EAAE,CAAC,MAAM,EAAE,OAAO;UACtC;QACF;MACF,CAAC,CAAC;MACFf,YAAY,CAQT,CAAC,CAACiB,aAAa,CAA6B,CAAC;IAClD,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export const META_TAG_HOST_ORIGIN = "x-palantir-widgets-host-origin";
|
|
18
|
+
//# sourceMappingURL=metaTags.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metaTags.js","names":["META_TAG_HOST_ORIGIN"],"sources":["metaTags.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const META_TAG_HOST_ORIGIN = \"x-palantir-widgets-host-origin\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,MAAMA,oBAAoB,GAAG,gCAAgC","ignoreList":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Map of the name of the type to the corresponding JavaScript type.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Wire format of parameter values that will be sent through postMessage events to custom widgets.
|
|
21
|
+
*/
|
|
22
|
+
export let ParameterValue;
|
|
23
|
+
//# sourceMappingURL=parameters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parameters.js","names":["ParameterValue"],"sources":["parameters.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { AsyncValue } from \"./utils/asyncValue.js\";\n\n/**\n * Map of the name of the type to the corresponding JavaScript type.\n */\ntype PrimitiveParameterTypes = {\n boolean: boolean;\n /** Formatted as an ISO date string, e.g. YYYY-MM-DD */\n date: string;\n number: number;\n string: string;\n /** Formatted as an ISO datetime string */\n timestamp: string;\n};\ntype PrimitiveParameterType = keyof PrimitiveParameterTypes;\n\nexport interface AbstractParameterValue<T extends PrimitiveParameterType> {\n type: T;\n value: AsyncValue<PrimitiveParameterTypes[T]>;\n}\n\nexport interface GenericArrayParameterValue<T extends PrimitiveParameterType> {\n type: \"array\";\n subType: T;\n value: AsyncValue<PrimitiveParameterTypes[T][]>;\n}\n\n/**\n * Wire format of parameter values that will be sent through postMessage events to custom widgets.\n */\nexport namespace ParameterValue {\n export type String = AbstractParameterValue<\"string\">;\n export type Number = AbstractParameterValue<\"number\">;\n export type Boolean = AbstractParameterValue<\"boolean\">;\n export type Date = AbstractParameterValue<\"date\">;\n export type Timestamp = AbstractParameterValue<\"timestamp\">;\n\n export type StringArray = GenericArrayParameterValue<\"string\">;\n export type NumberArray = GenericArrayParameterValue<\"number\">;\n export type BooleanArray = GenericArrayParameterValue<\"boolean\">;\n export type DateArray = GenericArrayParameterValue<\"date\">;\n export type TimestampArray = GenericArrayParameterValue<\"timestamp\">;\n export type Array =\n | StringArray\n | NumberArray\n | BooleanArray\n | DateArray\n | TimestampArray;\n\n export type Type = ParameterValue[\"type\"];\n export type PrimitiveType = PrimitiveParameterType;\n}\nexport type ParameterValue =\n | ParameterValue.String\n | ParameterValue.Number\n | ParameterValue.Boolean\n | ParameterValue.Date\n | ParameterValue.Timestamp\n | ParameterValue.Array;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIA;AACA;AACA;AAuBA;AACA;AACA;AAFA,WAGiBA,cAAc","ignoreList":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { describe, expectTypeOf, it } from "vitest";
|
|
18
|
+
describe("Parameters", () => {
|
|
19
|
+
describe("ArrayParameterValue", () => {
|
|
20
|
+
it("should be able to narrow the type of the array value", () => {
|
|
21
|
+
expectTypeOf(testStringTypeNarrowing({
|
|
22
|
+
type: "array",
|
|
23
|
+
subType: "string",
|
|
24
|
+
value: {
|
|
25
|
+
type: "loaded",
|
|
26
|
+
value: ["a", "b", "c"]
|
|
27
|
+
}
|
|
28
|
+
})).toEqualTypeOf();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
function testStringTypeNarrowing(array) {
|
|
33
|
+
if (array.subType === "string" && array.value.type === "loaded") {
|
|
34
|
+
return array.value.value;
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=parameters.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parameters.test.js","names":["describe","expectTypeOf","it","testStringTypeNarrowing","type","subType","value","toEqualTypeOf","array","undefined"],"sources":["parameters.test.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { describe, expectTypeOf, it } from \"vitest\";\nimport type { ParameterValue } from \"./parameters.js\";\n\ndescribe(\"Parameters\", () => {\n describe(\"ArrayParameterValue\", () => {\n it(\"should be able to narrow the type of the array value\", () => {\n expectTypeOf(\n testStringTypeNarrowing({\n type: \"array\",\n subType: \"string\",\n value: { type: \"loaded\", value: [\"a\", \"b\", \"c\"] },\n }),\n ).toEqualTypeOf<string[] | undefined>();\n });\n });\n});\n\nfunction testStringTypeNarrowing(array: ParameterValue.Array) {\n if (array.subType === \"string\" && array.value.type === \"loaded\") {\n return array.value.value;\n }\n return undefined;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,QAAQ,EAAEC,YAAY,EAAEC,EAAE,QAAQ,QAAQ;AAGnDF,QAAQ,CAAC,YAAY,EAAE,MAAM;EAC3BA,QAAQ,CAAC,qBAAqB,EAAE,MAAM;IACpCE,EAAE,CAAC,sDAAsD,EAAE,MAAM;MAC/DD,YAAY,CACVE,uBAAuB,CAAC;QACtBC,IAAI,EAAE,OAAO;QACbC,OAAO,EAAE,QAAQ;QACjBC,KAAK,EAAE;UAAEF,IAAI,EAAE,QAAQ;UAAEE,KAAK,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG;QAAE;MAClD,CAAC,CACH,CAAC,CAACC,aAAa,CAAuB,CAAC;IACzC,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,SAASJ,uBAAuBA,CAACK,KAA2B,EAAE;EAC5D,IAAIA,KAAK,CAACH,OAAO,KAAK,QAAQ,IAAIG,KAAK,CAACF,KAAK,CAACF,IAAI,KAAK,QAAQ,EAAE;IAC/D,OAAOI,KAAK,CAACF,KAAK,CAACA,KAAK;EAC1B;EACA,OAAOG,SAAS;AAClB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asyncValue.js","names":[],"sources":["asyncValue.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport interface AsyncNotStartedLoadingValue {\n type: \"not-started\";\n value?: never;\n error?: never;\n}\n\nexport interface AsyncLoadingValue {\n type: \"loading\";\n value?: never;\n error?: never;\n}\n\nexport interface AsyncLoadedValue<V> {\n type: \"loaded\";\n value: V | undefined;\n error?: never;\n}\n\nexport interface AsyncReloadingValue<V> {\n type: \"reloading\";\n value: V | undefined;\n error?: never;\n}\n\nexport interface AsyncFailedValue<V, E = Error> {\n type: \"failed\";\n error: E;\n value: V | undefined;\n}\n\n/**\n * Represents a value that is loaded asynchronously.\n * This allows for type safe checking of what the value's loading state is.\n * The expected lifecycle is:\n * not-started -> loading -> loaded or failed -> reloading -> ....\n */\nexport type AsyncValue<V, E = Error> =\n | AsyncNotStartedLoadingValue\n | AsyncLoadingValue\n | AsyncLoadedValue<V>\n | AsyncReloadingValue<V>\n | AsyncFailedValue<V, E>;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/config.ts
|
|
4
|
+
function defineConfig(c) {
|
|
5
|
+
return c;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// src/manifest.ts
|
|
9
|
+
var MANIFEST_FILE_LOCATION = ".palantir/widgets.config.json";
|
|
10
|
+
|
|
11
|
+
// src/messages/hostMessages.ts
|
|
12
|
+
exports.HostMessage = void 0;
|
|
13
|
+
(function(_HostMessage) {
|
|
14
|
+
_HostMessage.Version = "1.0.0";
|
|
15
|
+
})(exports.HostMessage || (exports.HostMessage = {}));
|
|
16
|
+
function isHostParametersUpdatedMessage(event) {
|
|
17
|
+
return event.type === "host.update-parameters";
|
|
18
|
+
}
|
|
19
|
+
function visitHostMessage(message, visitor) {
|
|
20
|
+
const {
|
|
21
|
+
type,
|
|
22
|
+
payload
|
|
23
|
+
} = message;
|
|
24
|
+
const handler = visitor[type];
|
|
25
|
+
if (handler) {
|
|
26
|
+
handler(payload);
|
|
27
|
+
} else {
|
|
28
|
+
visitor._unknown(type);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/messages/widgetMessages.ts
|
|
33
|
+
function isWidgetReadyMessage(event) {
|
|
34
|
+
return event.type === "widget.ready";
|
|
35
|
+
}
|
|
36
|
+
function isWidgetEmitEventMessage(event) {
|
|
37
|
+
return event.type === "widget.emit-event";
|
|
38
|
+
}
|
|
39
|
+
function visitWidgetMessage(message, visitor) {
|
|
40
|
+
const {
|
|
41
|
+
type,
|
|
42
|
+
payload
|
|
43
|
+
} = message;
|
|
44
|
+
const handler = visitor[type];
|
|
45
|
+
if (handler) {
|
|
46
|
+
handler(payload);
|
|
47
|
+
} else {
|
|
48
|
+
visitor._unknown(type);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/metaTags.ts
|
|
53
|
+
var META_TAG_HOST_ORIGIN = "x-palantir-widgets-host-origin";
|
|
54
|
+
|
|
55
|
+
exports.MANIFEST_FILE_LOCATION = MANIFEST_FILE_LOCATION;
|
|
56
|
+
exports.META_TAG_HOST_ORIGIN = META_TAG_HOST_ORIGIN;
|
|
57
|
+
exports.defineConfig = defineConfig;
|
|
58
|
+
exports.isHostParametersUpdatedMessage = isHostParametersUpdatedMessage;
|
|
59
|
+
exports.isWidgetEmitEventMessage = isWidgetEmitEventMessage;
|
|
60
|
+
exports.isWidgetReadyMessage = isWidgetReadyMessage;
|
|
61
|
+
exports.visitHostMessage = visitHostMessage;
|
|
62
|
+
exports.visitWidgetMessage = visitWidgetMessage;
|
|
63
|
+
//# sourceMappingURL=index.cjs.map
|
|
64
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/config.ts","../../src/manifest.ts","../../src/messages/hostMessages.ts","../../src/messages/widgetMessages.ts","../../src/metaTags.ts"],"names":["HostMessage"],"mappings":";;;AAqCO,SAAS,aAAa,CAAG,EAAA;AAC9B,EAAO,OAAA,CAAA;AACT;;;ACvBO,IAAM,sBAAyB,GAAA;;;ACA3BA;AAAA,CACV,SAAU,YAAc,EAAA;AACvB,EAAgB,aAAa,OAAU,GAAA;AACzC,CAAG,EAAAA,mBAAA,KAAgBA,mBAAc,GAAA,EAAG,CAAA,CAAA;AAC7B,SAAS,+BAA+B,KAAO,EAAA;AACpD,EAAA,OAAO,MAAM,IAAS,KAAA,wBAAA;AACxB;AAIO,SAAS,gBAAA,CAAiB,SAAS,OAAS,EAAA;AACjD,EAAM,MAAA;AAAA,IACJ,IAAA;AAAA,IACA;AAAA,GACE,GAAA,OAAA;AACJ,EAAM,MAAA,OAAA,GAAU,QAAQ,IAAI,CAAA;AAC5B,EAAA,IAAI,OAAS,EAAA;AAEX,IAAA,OAAA,CAAQ,OAAO,CAAA;AAAA,GACV,MAAA;AACL,IAAA,OAAA,CAAQ,SAAS,IAAI,CAAA;AAAA;AAEzB;;;ACrBO,SAAS,qBAAqB,KAAO,EAAA;AAC1C,EAAA,OAAO,MAAM,IAAS,KAAA,cAAA;AACxB;AACO,SAAS,yBAAyB,KAAO,EAAA;AAC9C,EAAA,OAAO,MAAM,IAAS,KAAA,mBAAA;AACxB;AACO,SAAS,kBAAA,CAAmB,SAAS,OAAS,EAAA;AACnD,EAAM,MAAA;AAAA,IACJ,IAAA;AAAA,IACA;AAAA,GACE,GAAA,OAAA;AACJ,EAAM,MAAA,OAAA,GAAU,QAAQ,IAAI,CAAA;AAC5B,EAAA,IAAI,OAAS,EAAA;AAEX,IAAA,OAAA,CAAQ,OAAO,CAAA;AAAA,GACV,MAAA;AACL,IAAA,OAAA,CAAQ,SAAS,IAAI,CAAA;AAAA;AAEzB;;;ACnBO,IAAM,oBAAuB,GAAA","file":"index.cjs","sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Extracts the parameter ID strings as types from the given ParameterConfig.\n */\n\n/**\n * Extracts a map of parameter IDs to their async-wrapped value types from the given ParameterConfig.\n */\n\n/**\n * Extracts a map of parameter IDs to the raw parameter values from the given ParameterConfig.\n */\n\n/**\n * Extracts a list of strongly-typed parameter IDs from the given WidgetConfig for a given event ID.\n * If a parameter ID is referenced by an event but does not exist, its type will be never\n */\n\n/**\n * Extracts a map of event IDs to their raw parameter value types from the given WidgetConfig.\n */\n\nexport function defineConfig(c) {\n return c;\n}","/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const MANIFEST_FILE_LOCATION = \".palantir/widgets.config.json\";","/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n// Interfaces and type guards for messages passed from the host Foundry UI to the widget\nexport let HostMessage;\n(function (_HostMessage) {\n const Version = _HostMessage.Version = \"1.0.0\";\n})(HostMessage || (HostMessage = {}));\nexport function isHostParametersUpdatedMessage(event) {\n return event.type === \"host.update-parameters\";\n}\n/**\n * Strongly typed visitor to handle every type of host message\n */\nexport function visitHostMessage(message, visitor) {\n const {\n type,\n payload\n } = message;\n const handler = visitor[type];\n if (handler) {\n // Typescript creates an & of the parameters instead of a union\n handler(payload);\n } else {\n visitor._unknown(type);\n }\n}","/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n// Interfaces and type guards for messages passed from the widget to the host Foundry UI\nexport let WidgetMessage;\nexport function isWidgetReadyMessage(event) {\n return event.type === \"widget.ready\";\n}\nexport function isWidgetEmitEventMessage(event) {\n return event.type === \"widget.emit-event\";\n}\nexport function visitWidgetMessage(message, visitor) {\n const {\n type,\n payload\n } = message;\n const handler = visitor[type];\n if (handler) {\n // Typescript creates an & of the parameters instead of a union\n handler(payload);\n } else {\n visitor._unknown(type);\n }\n}","/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const META_TAG_HOST_ORIGIN = \"x-palantir-widgets-host-origin\";"]}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
interface AsyncNotStartedLoadingValue {
|
|
2
|
+
type: "not-started";
|
|
3
|
+
value?: never;
|
|
4
|
+
error?: never;
|
|
5
|
+
}
|
|
6
|
+
interface AsyncLoadingValue {
|
|
7
|
+
type: "loading";
|
|
8
|
+
value?: never;
|
|
9
|
+
error?: never;
|
|
10
|
+
}
|
|
11
|
+
interface AsyncLoadedValue<V> {
|
|
12
|
+
type: "loaded";
|
|
13
|
+
value: V | undefined;
|
|
14
|
+
error?: never;
|
|
15
|
+
}
|
|
16
|
+
interface AsyncReloadingValue<V> {
|
|
17
|
+
type: "reloading";
|
|
18
|
+
value: V | undefined;
|
|
19
|
+
error?: never;
|
|
20
|
+
}
|
|
21
|
+
interface AsyncFailedValue<V, E = Error> {
|
|
22
|
+
type: "failed";
|
|
23
|
+
error: E;
|
|
24
|
+
value: V | undefined;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Represents a value that is loaded asynchronously.
|
|
28
|
+
* This allows for type safe checking of what the value's loading state is.
|
|
29
|
+
* The expected lifecycle is:
|
|
30
|
+
* not-started -> loading -> loaded or failed -> reloading -> ....
|
|
31
|
+
*/
|
|
32
|
+
type AsyncValue<V, E = Error> = AsyncNotStartedLoadingValue | AsyncLoadingValue | AsyncLoadedValue<V> | AsyncReloadingValue<V> | AsyncFailedValue<V, E>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Map of the name of the type to the corresponding JavaScript type.
|
|
36
|
+
*/
|
|
37
|
+
type PrimitiveParameterTypes = {
|
|
38
|
+
boolean: boolean;
|
|
39
|
+
/** Formatted as an ISO date string, e.g. YYYY-MM-DD */
|
|
40
|
+
date: string;
|
|
41
|
+
number: number;
|
|
42
|
+
string: string;
|
|
43
|
+
/** Formatted as an ISO datetime string */
|
|
44
|
+
timestamp: string;
|
|
45
|
+
};
|
|
46
|
+
type PrimitiveParameterType = keyof PrimitiveParameterTypes;
|
|
47
|
+
interface AbstractParameterValue<T extends PrimitiveParameterType> {
|
|
48
|
+
type: T;
|
|
49
|
+
value: AsyncValue<PrimitiveParameterTypes[T]>;
|
|
50
|
+
}
|
|
51
|
+
interface GenericArrayParameterValue<T extends PrimitiveParameterType> {
|
|
52
|
+
type: "array";
|
|
53
|
+
subType: T;
|
|
54
|
+
value: AsyncValue<PrimitiveParameterTypes[T][]>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Wire format of parameter values that will be sent through postMessage events to custom widgets.
|
|
58
|
+
*/
|
|
59
|
+
declare namespace ParameterValue {
|
|
60
|
+
type String = AbstractParameterValue<"string">;
|
|
61
|
+
type Number = AbstractParameterValue<"number">;
|
|
62
|
+
type Boolean = AbstractParameterValue<"boolean">;
|
|
63
|
+
type Date = AbstractParameterValue<"date">;
|
|
64
|
+
type Timestamp = AbstractParameterValue<"timestamp">;
|
|
65
|
+
type StringArray = GenericArrayParameterValue<"string">;
|
|
66
|
+
type NumberArray = GenericArrayParameterValue<"number">;
|
|
67
|
+
type BooleanArray = GenericArrayParameterValue<"boolean">;
|
|
68
|
+
type DateArray = GenericArrayParameterValue<"date">;
|
|
69
|
+
type TimestampArray = GenericArrayParameterValue<"timestamp">;
|
|
70
|
+
type Array = StringArray | NumberArray | BooleanArray | DateArray | TimestampArray;
|
|
71
|
+
type Type = ParameterValue["type"];
|
|
72
|
+
type PrimitiveType = PrimitiveParameterType;
|
|
73
|
+
}
|
|
74
|
+
type ParameterValue = ParameterValue.String | ParameterValue.Number | ParameterValue.Boolean | ParameterValue.Date | ParameterValue.Timestamp | ParameterValue.Array;
|
|
75
|
+
|
|
76
|
+
interface PrimitiveParameterDefinition<T extends ParameterValue.PrimitiveType> {
|
|
77
|
+
type: T;
|
|
78
|
+
displayName: string;
|
|
79
|
+
}
|
|
80
|
+
interface ArrayParameterDefinition<S extends ParameterValue.PrimitiveType> {
|
|
81
|
+
type: ParameterValue.Array["type"];
|
|
82
|
+
displayName: string;
|
|
83
|
+
subType: S;
|
|
84
|
+
}
|
|
85
|
+
type ParameterDefinition = PrimitiveParameterDefinition<ParameterValue.PrimitiveType> | ArrayParameterDefinition<ParameterValue.PrimitiveType>;
|
|
86
|
+
interface EventDefinition<P extends ParameterConfig> {
|
|
87
|
+
displayName: string;
|
|
88
|
+
parameterUpdateIds: Array<ParameterId<P>>;
|
|
89
|
+
}
|
|
90
|
+
type ParameterConfig = Record<string, ParameterDefinition>;
|
|
91
|
+
interface WidgetConfig<P extends ParameterConfig> {
|
|
92
|
+
id: string;
|
|
93
|
+
name: string;
|
|
94
|
+
description?: string;
|
|
95
|
+
type: "workshop";
|
|
96
|
+
parameters: ParameterConfig;
|
|
97
|
+
events: {
|
|
98
|
+
[eventId: string]: EventDefinition<NoInfer<P>>;
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Extracts the parameter ID strings as types from the given ParameterConfig.
|
|
103
|
+
*/
|
|
104
|
+
type ParameterId<C extends ParameterConfig> = Extract<keyof C, string>;
|
|
105
|
+
/**
|
|
106
|
+
* Extracts a map of parameter IDs to their async-wrapped value types from the given ParameterConfig.
|
|
107
|
+
*/
|
|
108
|
+
type AsyncParameterValueMap<C extends WidgetConfig<C["parameters"]>> = {
|
|
109
|
+
[K in ParameterId<C["parameters"]>]: C["parameters"][K] extends ArrayParameterDefinition<infer S> ? Extract<ParameterValue.Array, {
|
|
110
|
+
type: C["parameters"][K]["type"];
|
|
111
|
+
subType: S;
|
|
112
|
+
}>["value"] extends AsyncValue<infer P> ? {
|
|
113
|
+
type: "array";
|
|
114
|
+
subType: S;
|
|
115
|
+
value: AsyncValue<P>;
|
|
116
|
+
} : never : Extract<ParameterValue, {
|
|
117
|
+
type: C["parameters"][K]["type"];
|
|
118
|
+
}>["value"] extends AsyncValue<infer P> ? {
|
|
119
|
+
type: C["parameters"][K]["type"];
|
|
120
|
+
value: AsyncValue<P>;
|
|
121
|
+
} : never;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Extracts a map of parameter IDs to the raw parameter values from the given ParameterConfig.
|
|
125
|
+
*/
|
|
126
|
+
type ParameterValueMap<C extends WidgetConfig<C["parameters"]>> = {
|
|
127
|
+
[K in ParameterId<C["parameters"]>]: C["parameters"][K] extends ArrayParameterDefinition<infer S> ? Extract<ParameterValue.Array, {
|
|
128
|
+
type: C["parameters"][K]["type"];
|
|
129
|
+
subType: S;
|
|
130
|
+
}>["value"] extends AsyncValue<infer P> ? P : never : Extract<ParameterValue, {
|
|
131
|
+
type: C["parameters"][K]["type"];
|
|
132
|
+
}>["value"] extends AsyncValue<infer P> ? P : never;
|
|
133
|
+
};
|
|
134
|
+
type EventId<C extends WidgetConfig<C["parameters"]>> = keyof C["events"];
|
|
135
|
+
/**
|
|
136
|
+
* Extracts a list of strongly-typed parameter IDs from the given WidgetConfig for a given event ID.
|
|
137
|
+
* If a parameter ID is referenced by an event but does not exist, its type will be never
|
|
138
|
+
*/
|
|
139
|
+
type EventParameterIdList<C extends WidgetConfig<C["parameters"]>, K extends EventId<C>> = C["events"][K]["parameterUpdateIds"] extends Array<ParameterId<C["parameters"]>> ? C["events"][K]["parameterUpdateIds"] : never;
|
|
140
|
+
/**
|
|
141
|
+
* Extracts a map of event IDs to their raw parameter value types from the given WidgetConfig.
|
|
142
|
+
*/
|
|
143
|
+
type EventParameterValueMap<C extends WidgetConfig<C["parameters"]>, K extends EventId<C>> = {
|
|
144
|
+
[P in EventParameterIdList<C, K>[number]]: ParameterValueMap<C>[P];
|
|
145
|
+
};
|
|
146
|
+
declare function defineConfig<const C extends WidgetConfig<any>>(c: C): C;
|
|
147
|
+
|
|
148
|
+
interface WidgetSetManifestV1 {
|
|
149
|
+
manifestVersion: "1.0.0";
|
|
150
|
+
widgetSet: WidgetSetManifestContentV1;
|
|
151
|
+
}
|
|
152
|
+
interface WidgetSetManifestContentV1 {
|
|
153
|
+
/**
|
|
154
|
+
* RID of the widget set that this config corresponds to
|
|
155
|
+
*/
|
|
156
|
+
rid: string;
|
|
157
|
+
/**
|
|
158
|
+
* The version of the widget to publish as
|
|
159
|
+
*/
|
|
160
|
+
version: string;
|
|
161
|
+
/**
|
|
162
|
+
* Set of widgets that are available to be rendered.
|
|
163
|
+
* The key can be arbitrary, and is usually the name of your entrypoint, e.g. "main"
|
|
164
|
+
*/
|
|
165
|
+
widgets: Record<string, WidgetManifestConfigV1>;
|
|
166
|
+
}
|
|
167
|
+
interface WidgetManifestConfigV1 {
|
|
168
|
+
/**
|
|
169
|
+
* The ID of this widget. Must be unique within the widget set
|
|
170
|
+
*/
|
|
171
|
+
id: string;
|
|
172
|
+
/**
|
|
173
|
+
* The user friendly name of this widget
|
|
174
|
+
*/
|
|
175
|
+
name: string;
|
|
176
|
+
/**
|
|
177
|
+
* A user friendly description of this widget
|
|
178
|
+
*/
|
|
179
|
+
description?: string;
|
|
180
|
+
/**
|
|
181
|
+
* The target Foundry UI that this widget is intended to be used in
|
|
182
|
+
*/
|
|
183
|
+
type: "workshopWidgetV1";
|
|
184
|
+
/**
|
|
185
|
+
* List of entrypoint JS files to be loaded, in order. These will be placed on the page in script tags
|
|
186
|
+
*/
|
|
187
|
+
entrypointJs: Array<{
|
|
188
|
+
/** Relative path of the JS file to load */
|
|
189
|
+
path: string;
|
|
190
|
+
/** The type to use in the script tag when loading this JS file */
|
|
191
|
+
type: "module" | "text/javascript";
|
|
192
|
+
}>;
|
|
193
|
+
/**
|
|
194
|
+
* Any CSS files to be loaded, in order.
|
|
195
|
+
* @optional
|
|
196
|
+
*/
|
|
197
|
+
entrypointCss?: Array<{
|
|
198
|
+
/** Relative path of the CSS file to load */
|
|
199
|
+
path: string;
|
|
200
|
+
}>;
|
|
201
|
+
/**
|
|
202
|
+
* The map of parameter IDs to their definition
|
|
203
|
+
*/
|
|
204
|
+
parameters: Record<string, ParameterDefinition>;
|
|
205
|
+
/**
|
|
206
|
+
* The map of events to their definition. Any parameter IDs referenced must be defined in the `parameters` field
|
|
207
|
+
*/
|
|
208
|
+
events: Record<string, EventDefinition<ParameterConfig>>;
|
|
209
|
+
}
|
|
210
|
+
declare const MANIFEST_FILE_LOCATION = ".palantir/widgets.config.json";
|
|
211
|
+
|
|
212
|
+
interface HostBaseMessage<T extends string, P = unknown> {
|
|
213
|
+
type: T;
|
|
214
|
+
payload: P;
|
|
215
|
+
}
|
|
216
|
+
declare namespace HostMessage {
|
|
217
|
+
const Version = "1.0.0";
|
|
218
|
+
type Version = typeof Version;
|
|
219
|
+
namespace Payload {
|
|
220
|
+
interface UpdateParameters<C extends WidgetConfig<C["parameters"]>> {
|
|
221
|
+
parameters: AsyncParameterValueMap<C>;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
type Payload = Payload.UpdateParameters<any>;
|
|
225
|
+
interface UpdateParameters<C extends WidgetConfig<C["parameters"]>> extends HostBaseMessage<"host.update-parameters", Payload.UpdateParameters<C>> {
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
type HostMessage<C extends WidgetConfig<C["parameters"]>> = HostMessage.UpdateParameters<C>;
|
|
229
|
+
declare function isHostParametersUpdatedMessage<C extends WidgetConfig<C["parameters"]>>(event: HostMessage<C>): event is HostMessage.UpdateParameters<C>;
|
|
230
|
+
type HostMessageVisitor<C extends WidgetConfig<C["parameters"]>> = {
|
|
231
|
+
[T in HostMessage<C>["type"]]: (payload: Extract<HostMessage<C>, {
|
|
232
|
+
type: T;
|
|
233
|
+
}> extends {
|
|
234
|
+
payload: infer P;
|
|
235
|
+
} ? P : never) => void;
|
|
236
|
+
} & {
|
|
237
|
+
_unknown: (type: string) => void;
|
|
238
|
+
};
|
|
239
|
+
/**
|
|
240
|
+
* Strongly typed visitor to handle every type of host message
|
|
241
|
+
*/
|
|
242
|
+
declare function visitHostMessage<C extends WidgetConfig<C["parameters"]>>(message: HostMessage<C>, visitor: HostMessageVisitor<C>): void;
|
|
243
|
+
|
|
244
|
+
interface WidgetBaseMessage<T extends string, P = unknown> {
|
|
245
|
+
type: T;
|
|
246
|
+
payload: P;
|
|
247
|
+
}
|
|
248
|
+
type EmitEventIdMap<C extends WidgetConfig<C["parameters"]>> = {
|
|
249
|
+
[K in EventId<C>]: {
|
|
250
|
+
eventId: K;
|
|
251
|
+
parameterUpdates: EventParameterValueMap<C, K>;
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
declare namespace WidgetMessage {
|
|
255
|
+
namespace Payload {
|
|
256
|
+
interface Ready {
|
|
257
|
+
apiVersion: HostMessage.Version;
|
|
258
|
+
}
|
|
259
|
+
type EmitEvent<C extends WidgetConfig<C["parameters"]>> = EmitEventIdMap<C>[EventId<C>];
|
|
260
|
+
}
|
|
261
|
+
type Payload<C extends WidgetConfig<C["parameters"]>> = Payload.Ready | Payload.EmitEvent<C>;
|
|
262
|
+
/**
|
|
263
|
+
* Emit when the widget is ready to start receiving messages from the host Foundry UI
|
|
264
|
+
*/
|
|
265
|
+
interface Ready extends WidgetBaseMessage<"widget.ready", Payload.Ready> {
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Event payload that the widget sends to the host Foundry UI
|
|
269
|
+
*/
|
|
270
|
+
interface EmitEvent<C extends WidgetConfig<C["parameters"]>> extends WidgetBaseMessage<"widget.emit-event", Payload.EmitEvent<C>> {
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
type WidgetMessage<C extends WidgetConfig<C["parameters"]>> = WidgetMessage.Ready | WidgetMessage.EmitEvent<C>;
|
|
274
|
+
declare function isWidgetReadyMessage<C extends WidgetConfig<C["parameters"]>>(event: WidgetMessage<C>): event is WidgetMessage.Ready;
|
|
275
|
+
declare function isWidgetEmitEventMessage<C extends WidgetConfig<C["parameters"]>>(event: WidgetMessage<C>): event is WidgetMessage.EmitEvent<C>;
|
|
276
|
+
type WidgetMessageVisitor<C extends WidgetConfig<C["parameters"]>> = {
|
|
277
|
+
[T in WidgetMessage<C>["type"]]: (payload: Extract<WidgetMessage<C>, {
|
|
278
|
+
type: T;
|
|
279
|
+
}> extends {
|
|
280
|
+
payload: infer P;
|
|
281
|
+
} ? P : never) => void;
|
|
282
|
+
} & {
|
|
283
|
+
_unknown: (type: string) => void;
|
|
284
|
+
};
|
|
285
|
+
declare function visitWidgetMessage<C extends WidgetConfig<C["parameters"]>>(message: WidgetMessage<C>, visitor: WidgetMessageVisitor<C>): void;
|
|
286
|
+
|
|
287
|
+
declare const META_TAG_HOST_ORIGIN = "x-palantir-widgets-host-origin";
|
|
288
|
+
|
|
289
|
+
export { type AsyncFailedValue, type AsyncLoadedValue, type AsyncLoadingValue, type AsyncNotStartedLoadingValue, type AsyncParameterValueMap, type AsyncReloadingValue, type AsyncValue, type EventId, type EventParameterValueMap, HostMessage, MANIFEST_FILE_LOCATION, META_TAG_HOST_ORIGIN, type ParameterConfig, type ParameterDefinition, ParameterValue, type ParameterValueMap, type WidgetConfig, type WidgetManifestConfigV1 as WidgetManifestConfig, WidgetMessage, type WidgetSetManifestV1 as WidgetSetManifest, defineConfig, isHostParametersUpdatedMessage, isWidgetEmitEventMessage, isWidgetReadyMessage, visitHostMessage, visitWidgetMessage };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Extracts the parameter ID strings as types from the given ParameterConfig.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Extracts a map of parameter IDs to their async-wrapped value types from the given ParameterConfig.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Extracts a map of parameter IDs to the raw parameter values from the given ParameterConfig.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Extracts a list of strongly-typed parameter IDs from the given WidgetConfig for a given event ID.
|
|
31
|
+
* If a parameter ID is referenced by an event but does not exist, its type will be never
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Extracts a map of event IDs to their raw parameter value types from the given WidgetConfig.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
export function defineConfig(c) {
|
|
39
|
+
return c;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=config.js.map
|