Skip to content

Commit a30cdcd

Browse files
authored
Merge pull request #25 from ryanbas21/refactor/tagged-struct
refactor: use Schema.TaggedStruct for discriminated unions
2 parents 73d061c + e611144 commit a30cdcd

2 files changed

Lines changed: 10 additions & 20 deletions

File tree

packages/devtools-types/src/lib/auth-event.schema.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ export const CorsFlagSchema = Schema.Struct({
3838

3939
export type CorsFlag = Schema.Schema.Type<typeof CorsFlagSchema>;
4040

41-
export const NetworkDataSchema = Schema.Struct({
42-
_tag: Schema.Literal('network'),
41+
export const NetworkDataSchema = Schema.TaggedStruct('network', {
4342
url: Schema.String,
4443
method: Schema.String,
4544
status: Schema.Number,
@@ -63,8 +62,7 @@ export const SdkAuthorizationSchema = Schema.Struct({
6362
state: Schema.optional(Schema.String),
6463
});
6564

66-
export const SdkDataSchema = Schema.Struct({
67-
_tag: Schema.Literal('sdk'),
65+
export const SdkDataSchema = Schema.TaggedStruct('sdk', {
6866
nodeStatus: Schema.String,
6967
previousStatus: Schema.optional(Schema.String),
7068
interactionId: Schema.optional(Schema.String),
@@ -82,26 +80,22 @@ export const SdkDataSchema = Schema.Struct({
8280
responseBody: Schema.optional(Schema.Unknown),
8381
});
8482

85-
export const SdkConfigDataSchema = Schema.Struct({
86-
_tag: Schema.Literal('sdk-config'),
83+
export const SdkConfigDataSchema = Schema.TaggedStruct('sdk-config', {
8784
config: Schema.Unknown,
8885
});
8986

90-
export const DomDataSchema = Schema.Struct({
91-
_tag: Schema.Literal('dom'),
87+
export const DomDataSchema = Schema.TaggedStruct('dom', {
9288
element: Schema.optional(Schema.String),
9389
url: Schema.optional(Schema.String),
9490
});
9591

96-
export const SessionDataSchema = Schema.Struct({
97-
_tag: Schema.Literal('session'),
92+
export const SessionDataSchema = Schema.TaggedStruct('session', {
9893
key: Schema.String,
9994
before: Schema.optional(Schema.String),
10095
after: Schema.optional(Schema.String),
10196
});
10297

103-
export const JourneyDataSchema = Schema.Struct({
104-
_tag: Schema.Literal('journey'),
98+
export const JourneyDataSchema = Schema.TaggedStruct('journey', {
10599
stepType: Schema.Union(
106100
Schema.Literal('Step'),
107101
Schema.Literal('LoginSuccess'),
@@ -120,8 +114,7 @@ export const JourneyDataSchema = Schema.Struct({
120114
errorReason: Schema.optional(Schema.String),
121115
});
122116

123-
export const OidcDataSchema = Schema.Struct({
124-
_tag: Schema.Literal('oidc'),
117+
export const OidcDataSchema = Schema.TaggedStruct('oidc', {
125118
phase: Schema.Union(
126119
Schema.Literal('authorize'),
127120
Schema.Literal('exchange'),
@@ -164,8 +157,7 @@ export const OidcErrorSchema = Schema.Struct({
164157
errorDescription: Schema.optional(Schema.String),
165158
});
166159

167-
export const OidcSemanticsSchema = Schema.Struct({
168-
_tag: Schema.Literal('oidc-semantics'),
160+
export const OidcSemanticsSchema = Schema.TaggedStruct('oidc-semantics', {
169161
oidcPhase: Schema.Union(
170162
Schema.Literal('discovery'),
171163
Schema.Literal('authorize'),

packages/treeshake-check/src/lib/schemas.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,10 @@ export type PackageJsonHints = typeof PackageJsonHints.Type;
8686
// ─── Top-level result ────────────────────────────────────────────────────────
8787

8888
export const TreeshakeResult = Schema.Union(
89-
Schema.Struct({
90-
_tag: Schema.Literal('FullyTreeshakeable'),
89+
Schema.TaggedStruct('FullyTreeshakeable', {
9190
hints: PackageJsonHints,
9291
}),
93-
Schema.Struct({
94-
_tag: Schema.Literal('HasSideEffects'),
92+
Schema.TaggedStruct('HasSideEffects', {
9593
totalOriginalBytes: Schema.Number,
9694
totalRenderedBytes: Schema.Number,
9795
modules: Schema.Array(ModuleAnalysis),

0 commit comments

Comments
 (0)