Using Schema.decodeUnknownSync() within schema transform definitions: Is it a good practice?

We're building a CLI with Effect that syncs data from Notion API to various formats. We use Effect Schema for validation and transformation through multiple steps. Our schema transforms use helper functions that call Schema.decodeUnknownSync() internally:

/** Schema for Notion Title property */
const NotionTitlePropertySchema = Schema.Struct({
  type: Schema.Literal("title"),
  title: Schema.Array(
    Schema.Struct({
      plain_text: Schema.String,
    }),
  ),
});
...
// Helper functions that decode Notion property types
const decodeTitle = (prop: unknown): string => {
  const decoded = Schema.decodeUnknownSync(NotionTitlePropertySchema)(prop);
  return decoded.title.map((t) => t.plain_text).join("");
};

const decodeRelation = (prop: unknown): string[] => {
  const decoded = Schema.decodeUnknownSync(NotionRelationPropertySchema)(prop);
  return decoded.relation.map((r) => r.id);
};

// Used inside transform decode functions
export const NotionCoveredAreaFromDatabase = Schema.transform(
  CoveredAreaDatabaseSchema,
  NotionCoveredArea,
  {
    decode: (page) => ({
      "URN": decodeTitle(page.properties["URN"]),
      "Preview tilesets": decodeRelation(page.properties["Preview tilesets"]),
      // ... more fields
    }),
    encode: () => { throw new Error("Not implemented"); },
  }
);

The concern: Is it good practice to have Schema.decodeUnknownSync() calls inside schema transform definitions?
Was this page helpful?