Defining Pagination Parameters with Effect Typescript and SQL Integration

Is there a better way to define something like this:
export const PaginationParams = Schema.Struct({
  limit: Schema.optional(
    Schema.NumberFromString.pipe(
      Schema.greaterThan(0),
      Schema.lessThanOrEqualTo(25),
    ),
  ).pipe(Schema.withDecodingDefault(() => 10)),
  offset: Schema.optional(
    Schema.NumberFromString.pipe(Schema.greaterThanOrEqualTo(0)),
  ).pipe(Schema.withDecodingDefault(() => 0)),
});


This is a struct that is exposed to the API's url params for certain routes. Though I noticed that if I feed the same struct to my
@effect/sql
repo in the
Request
part, the parameters in the execute callback are not inferred as number but as string | undefined.
    const getByOrganizationId = SqlSchema.findAll({
      Request: Schema.Struct({
        organizationId: OrganizationId,
        pagination: PaginationParams,
      }),
      Result: Case,
      execute: ({ organizationId, pagination: { limit, offset } }) =>
        sql`SELECT * FROM cases WHERE organizationId = ${sql(
          organizationId,
        )} ORDER BY createdAt DESC LIMIT ${limit} OFFSET ${offset}`,
    });

(property) pagination: {
    readonly limit?: string | undefined;
    readonly offset?: string | undefined;
}


Even though the limit and offset will never be undefined. Just wondering if I'm missing something.

PS: If I infer the type of the PaginationParams struct with typeof PaginationParams.Type, both fields get inferred correctly as just number
type PaginationParams = {
    readonly limit: number;
    readonly offset: number;
}
Was this page helpful?