Skip to content

Schema using optionalWith produce Unsupported Schema Error #29

@christophe-g

Description

@christophe-g

this:

it('should allow optional struct with default value', async () => {
  const FirestoreMock = Layer.mock(FirestoreService, {
      get: (path) => {
        if (path === 'm/test') {
          return Effect.succeed(Option.some([{ id: 'test', path }, { id: 'test' }]))
        }
        return Effect.succeed(Option.none())
      }
    })

    const structWithDefault = Schema.Struct({
      a: Schema.optionalWith(Schema.String, { default: () => 'a' })
    })
    const id = Schema.String

    class M extends Model.Class<M>('M')({
      id: Model.Generated(id),
      ...structWithDefault.fields
    }) {
      static idField = 'id' as const
    }

    const MRepo = Model.makeRepository(M, {
      collectionPath: 'm',
      idField: M.idField,
      spanPrefix: 'm.repository',
    })

    const getM = Effect.gen(function* () {
      const m = yield* MRepo
      return yield* m.getById('test').pipe(Effect.map(Option.getOrUndefined))
    })

    const program = getM.pipe(
      Effect.provide(FirestoreMock)
    )
    const result = await Effect.runPromise(program)

    expect(result).toBeDefined()
    expect(result?.a).toBe('a')
  })
})

produce :

(FiberFailure) Error: Unsupported schema
schema (Transformation): ({ readonly a?: string | undefined } <-> { readonly a: string })

with latest effect and effect-firebase versions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions