Skip to content

Commit 18b36d6

Browse files
committed
Make ConfiguredProps generic
Rewrite the `ConfiguredProps` type in such a way that we can have type safety based on the configurable props of a component. This mimics what the old SDK and `connect-react` already do.
1 parent e6c8fb1 commit 18b36d6

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

.fernignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ src/core/auth/ConnectTokenProvider.ts
3535
src/core/auth/StaticTokenProvider.ts
3636
src/core/auth/TokenProvider.ts
3737

38+
# Custom configuration props files
39+
src/api/types/ConfiguredProps.ts
40+
src/serialization/types/ConfiguredProps.ts
41+
3842
# Custom Proxy files
3943
src/api/resources/proxy/client/requests/ProxyPutRequest.ts
4044
src/api/resources/proxy/client/requests/ProxyGetRequest.ts

src/api/types/ConfiguredProps.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
1-
/**
2-
* This file was auto-generated by Fern from our API Definition.
3-
*/
1+
import type * as Pipedream from "./index.js";
2+
3+
export type ConfigurableProps = Readonly<Pipedream.ConfigurableProp[]>;
44

5-
import * as Pipedream from "../index.js";
5+
export type PropTypeMap = {
6+
alert: never;
7+
any: Pipedream.ConfiguredPropValueAny;
8+
app: Pipedream.ConfiguredPropValueApp;
9+
boolean: Pipedream.ConfiguredPropValueBoolean;
10+
integer: Pipedream.ConfiguredPropValueInteger;
11+
object: Pipedream.ConfiguredPropValueObject;
12+
string: Pipedream.ConfiguredPropValueString;
13+
"string[]": Pipedream.ConfiguredPropValueStringArray;
14+
sql: Pipedream.ConfiguredPropValueSql;
15+
};
16+
export type PropValue<T extends Pipedream.ConfigurableProp["type"]> = T extends keyof PropTypeMap
17+
? PropTypeMap[T]
18+
: never;
619

720
/**
821
* The configured properties of the component
922
*/
10-
export type ConfiguredProps = Record<string, Pipedream.ConfiguredPropValue>;
23+
export type ConfiguredProps<T extends ConfigurableProps = ConfigurableProps> = {
24+
[K in T[number] as K["name"]]?: PropValue<K["type"]>;
25+
};

src/serialization/types/ConfiguredProps.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import * as Pipedream from "../../api/index.js";
77
import * as core from "../../core/index.js";
88
import { ConfiguredPropValue } from "./ConfiguredPropValue.js";
99

10-
export const ConfiguredProps: core.serialization.Schema<serializers.ConfiguredProps.Raw, Pipedream.ConfiguredProps> =
11-
core.serialization.record(core.serialization.string(), ConfiguredPropValue);
10+
export const ConfiguredProps: core.serialization.Schema<
11+
serializers.ConfiguredProps.Raw,
12+
Pipedream.ConfiguredProps<any>
13+
> = core.serialization.record(core.serialization.string(), ConfiguredPropValue) as any;
1214

1315
export declare namespace ConfiguredProps {
1416
export type Raw = Record<string, ConfiguredPropValue.Raw>;

0 commit comments

Comments
 (0)