const ODataAnnotationId = 'SelectExpandAnnotationId'
type ODataAnnotationValue = 'select' | 'expand'
const getODataAnnotation = AST.getAnnotation<ODataAnnotationValue>(ODataAnnotationId)
type ODataAnnotatedSchema<I, A> = Schema.Schema<I, A> & Brand.Brand<'ODataAnnotatedSchema'>
const oDataAnnotatedSchema =
(value: ODataAnnotationValue) =>
<I, A>(self: Schema.Schema<I, A>) =>
pipe(
AST.setAnnotation(self.ast, ODataAnnotationId, value),
Schema.make,
Brand.nominal<ODataAnnotatedSchema<I, A>>(),
)
const oDataSelect = oDataAnnotatedSchema('select')
const oDataExpand = oDataAnnotatedSchema('expand')
// Good:
// const foo: ODataAnnotatedSchema<string, string>
const foo = oDataSelect(Schema.string)
// Bad:
// const fooObj: Schema.Schema<{
// readonly foo: string;
// readonly bar: string;
// }, {
// readonly foo: string;
// readonly bar: string;
// }>
const fooObj = Schema.struct({
foo,
bar: Schema.string,
})
const ODataAnnotationId = 'SelectExpandAnnotationId'
type ODataAnnotationValue = 'select' | 'expand'
const getODataAnnotation = AST.getAnnotation<ODataAnnotationValue>(ODataAnnotationId)
type ODataAnnotatedSchema<I, A> = Schema.Schema<I, A> & Brand.Brand<'ODataAnnotatedSchema'>
const oDataAnnotatedSchema =
(value: ODataAnnotationValue) =>
<I, A>(self: Schema.Schema<I, A>) =>
pipe(
AST.setAnnotation(self.ast, ODataAnnotationId, value),
Schema.make,
Brand.nominal<ODataAnnotatedSchema<I, A>>(),
)
const oDataSelect = oDataAnnotatedSchema('select')
const oDataExpand = oDataAnnotatedSchema('expand')
// Good:
// const foo: ODataAnnotatedSchema<string, string>
const foo = oDataSelect(Schema.string)
// Bad:
// const fooObj: Schema.Schema<{
// readonly foo: string;
// readonly bar: string;
// }, {
// readonly foo: string;
// readonly bar: string;
// }>
const fooObj = Schema.struct({
foo,
bar: Schema.string,
})