Skip to content

Commit

Permalink
Prefer a named constructor to casting
Browse files Browse the repository at this point in the history
Refs #1834, #2165
  • Loading branch information
thewilkybarkid committed Jan 6, 2025
1 parent 6ce5eba commit 16ea422
Show file tree
Hide file tree
Showing 24 changed files with 80 additions and 80 deletions.
6 changes: 3 additions & 3 deletions integration/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { type MutableRedirectUri, OAuth2Server } from 'oauth2-mock-server'
import { Orcid } from 'orcid-id-ts'
import type { BrowserContextOptions } from 'playwright-core'
import { URL } from 'url'
import type { Uuid } from 'uuid-ts'
import { Uuid } from 'uuid-ts'
import {
EmptyDepositionC,
InProgressDepositionC,
Expand Down Expand Up @@ -1999,7 +1999,7 @@ export const hasAnUnverifiedEmailAddress: Fixtures<
ContactEmailAddressC.encode(
new UnverifiedContactEmailAddress({
value: EmailAddress('[email protected]'),
verificationToken: 'ff0d6f8e-7dca-4a26-b68b-93f2d2bc3c2a' as Uuid,
verificationToken: Uuid('ff0d6f8e-7dca-4a26-b68b-93f2d2bc3c2a'),
}),
),
)
Expand Down Expand Up @@ -2104,7 +2104,7 @@ export const invitedToBeAnAuthor: Fixtures<
name: 'Josiah Carberry' as NonEmptyString,
emailAddress: EmailAddress('[email protected]'),
},
'bec5727e-9992-4f3b-85be-6712df617b9d' as Uuid,
Uuid('bec5727e-9992-4f3b-85be-6712df617b9d'),
{
author: 'Josiah Carberry',
preprint: {
Expand Down
2 changes: 1 addition & 1 deletion src/types/uuid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as D from 'io-ts/lib/Decoder.js'
import { type Uuid, isUuid, v4 } from 'uuid-ts'
import * as FptsToEffect from '../FptsToEffect.js'

export type { Uuid } from 'uuid-ts'
export { Uuid } from 'uuid-ts'

export class GenerateUuid extends Context.Tag('GenerateUuid')<GenerateUuid, Effect.Effect<Uuid>>() {}

Expand Down
8 changes: 4 additions & 4 deletions test/Comments/Queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { Orcid } from 'orcid-id-ts'
import * as _ from '../../src/Comments/Queries.js'
import * as Comments from '../../src/Comments/index.js'
import { html } from '../../src/html.js'
import type { Uuid } from '../../src/types/index.js'
import { Uuid } from '../../src/types/index.js'
import * as fc from '../fc.js'

describe('GetNextExpectedCommandForUser', () => {
const authorId = Orcid('0000-0002-1825-0097')
const prereviewId = 123
const resourceId = '358f7fc0-9725-4192-8673-d7c64f398401' as Uuid.Uuid
const resourceId = Uuid.Uuid('358f7fc0-9725-4192-8673-d7c64f398401')
const commentWasStarted = new Comments.CommentWasStarted({ authorId, prereviewId })
const commentWasEntered = new Comments.CommentWasEntered({ comment: html`Some comment` })
const personaWasChosen = new Comments.PersonaWasChosen({ persona: 'public' })
Expand Down Expand Up @@ -172,7 +172,7 @@ describe('GetNextExpectedCommandForUser', () => {
describe('GetNextExpectedCommandForUserOnAComment', () => {
const authorId = Orcid('0000-0002-1825-0097')
const prereviewId = 123
const resourceId = '358f7fc0-9725-4192-8673-d7c64f398401' as Uuid.Uuid
const resourceId = Uuid.Uuid('358f7fc0-9725-4192-8673-d7c64f398401')
const commentWasStarted = new Comments.CommentWasStarted({ authorId, prereviewId })
const commentWasEntered = new Comments.CommentWasEntered({ comment: html`Some comment` })
const personaWasChosen = new Comments.PersonaWasChosen({ persona: 'public' })
Expand Down Expand Up @@ -313,7 +313,7 @@ describe('GetNextExpectedCommandForUserOnAComment', () => {
describe('GetACommentInNeedOfADoi', () => {
const authorId = Orcid('0000-0002-1825-0097')
const prereviewId = 123
const resourceId = '358f7fc0-9725-4192-8673-d7c64f398401' as Uuid.Uuid
const resourceId = Uuid.Uuid('358f7fc0-9725-4192-8673-d7c64f398401')
const commentWasStarted = new Comments.CommentWasStarted({ authorId, prereviewId })
const commentWasEntered = new Comments.CommentWasEntered({ comment: html`Some comment` })
const personaWasChosen = new Comments.PersonaWasChosen({ persona: 'public' })
Expand Down
4 changes: 2 additions & 2 deletions test/fc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
createResponse,
} from 'node-mocks-http'
import { type Orcid, isOrcid } from 'orcid-id-ts'
import { type Uuid, isUuid } from 'uuid-ts'
import { Uuid } from 'uuid-ts'
import type {
AssignedAuthorInvite,
AuthorInvite,
Expand Down Expand Up @@ -223,7 +223,7 @@ export const partialRecord = <T, TConstraints extends { requiredKeys: Array<keyo
),
)

export const uuid = (): fc.Arbitrary<Uuid> => fc.uuid().filter(isUuid)
export const uuid = (): fc.Arbitrary<Uuid> => fc.uuid().map(Uuid)

export const locale = (): fc.Arbitrary<string> =>
constantFrom(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Option } from 'effect'
import { Orcid } from 'orcid-id-ts'
import { html } from '../../../src/html.js'
import { DefaultLocale } from '../../../src/locales/index.js'
import type { NonEmptyString, Uuid } from '../../../src/types/index.js'
import { type NonEmptyString, Uuid } from '../../../src/types/index.js'
import type { Pseudonym } from '../../../src/types/pseudonym.js'
import type { User } from '../../../src/user.js'
import * as _ from '../../../src/WriteCommentFlow/CheckPage/CheckPage.js'
Expand All @@ -12,7 +12,7 @@ test('content looks right', async ({ showPage }) => {
const response = _.CheckPage({
competingInterests: Option.none(),
comment,
commentId: '7ad2f67d-dc01-48c5-b6ac-3490d494f67d' as Uuid.Uuid,
commentId: Uuid.Uuid('7ad2f67d-dc01-48c5-b6ac-3490d494f67d'),
locale: DefaultLocale,
persona: 'public',
user,
Expand All @@ -27,7 +27,7 @@ test('content looks right using a pseudonym', async ({ showPage }) => {
const response = _.CheckPage({
competingInterests: Option.none(),
comment,
commentId: '7ad2f67d-dc01-48c5-b6ac-3490d494f67d' as Uuid.Uuid,
commentId: Uuid.Uuid('7ad2f67d-dc01-48c5-b6ac-3490d494f67d'),
locale: DefaultLocale,
persona: 'pseudonym',
user,
Expand All @@ -44,7 +44,7 @@ test('content looks right with competing interests', async ({ showPage }) => {
'Lorem ipsum dolor sit amet, consectetur adipiscing elit.' as NonEmptyString.NonEmptyString,
),
comment,
commentId: '7ad2f67d-dc01-48c5-b6ac-3490d494f67d' as Uuid.Uuid,
commentId: Uuid.Uuid('7ad2f67d-dc01-48c5-b6ac-3490d494f67d'),
locale: DefaultLocale,
persona: 'public',
user,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Either } from 'effect'
import { Orcid } from 'orcid-id-ts'
import { DefaultLocale } from '../../../src/locales/index.js'
import type { Uuid } from '../../../src/types/index.js'
import { Uuid } from '../../../src/types/index.js'
import type { Pseudonym } from '../../../src/types/pseudonym.js'
import type { User } from '../../../src/user.js'
import * as ChoosePersonaForm from '../../../src/WriteCommentFlow/ChoosePersonaPage/ChoosePersonaForm.js'
Expand All @@ -10,7 +10,7 @@ import { expect, test } from '../../base.js'

test('content looks right', async ({ showPage }) => {
const response = _.ChoosePersonaPage({
commentId: '7ad2f67d-dc01-48c5-b6ac-3490d494f67d' as Uuid.Uuid,
commentId: Uuid.Uuid('7ad2f67d-dc01-48c5-b6ac-3490d494f67d'),
form: new ChoosePersonaForm.EmptyForm(),
locale: DefaultLocale,
user,
Expand All @@ -23,7 +23,7 @@ test('content looks right', async ({ showPage }) => {

test('content looks right when there is a persona', async ({ showPage }) => {
const response = _.ChoosePersonaPage({
commentId: '7ad2f67d-dc01-48c5-b6ac-3490d494f67d' as Uuid.Uuid,
commentId: Uuid.Uuid('7ad2f67d-dc01-48c5-b6ac-3490d494f67d'),
form: new ChoosePersonaForm.CompletedForm({ persona: 'public' }),
locale: DefaultLocale,
user,
Expand All @@ -36,7 +36,7 @@ test('content looks right when there is a persona', async ({ showPage }) => {

test('content looks right when the persona is missing', async ({ showPage }) => {
const response = _.ChoosePersonaPage({
commentId: '7ad2f67d-dc01-48c5-b6ac-3490d494f67d' as Uuid.Uuid,
commentId: Uuid.Uuid('7ad2f67d-dc01-48c5-b6ac-3490d494f67d'),
form: new ChoosePersonaForm.InvalidForm({ persona: Either.left(new ChoosePersonaForm.Missing()) }),
locale: DefaultLocale,
user,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Either } from 'effect'
import { DefaultLocale } from '../../../src/locales/index.js'
import type { Uuid } from '../../../src/types/index.js'
import { Uuid } from '../../../src/types/index.js'
import * as CodeOfConductForm from '../../../src/WriteCommentFlow/CodeOfConductPage/CodeOfConductForm.js'
import * as _ from '../../../src/WriteCommentFlow/CodeOfConductPage/CodeOfConductPage.js'
import { expect, test } from '../../base.js'

test('content looks right', async ({ showPage }) => {
const response = _.CodeOfConductPage({
commentId: '7ad2f67d-dc01-48c5-b6ac-3490d494f67d' as Uuid.Uuid,
commentId: Uuid.Uuid('7ad2f67d-dc01-48c5-b6ac-3490d494f67d'),
form: new CodeOfConductForm.EmptyForm(),
locale: DefaultLocale,
})
Expand All @@ -19,7 +19,7 @@ test('content looks right', async ({ showPage }) => {

test('content looks right when the agreement is missing', async ({ showPage }) => {
const response = _.CodeOfConductPage({
commentId: '7ad2f67d-dc01-48c5-b6ac-3490d494f67d' as Uuid.Uuid,
commentId: Uuid.Uuid('7ad2f67d-dc01-48c5-b6ac-3490d494f67d'),
form: new CodeOfConductForm.InvalidForm({ agree: Either.left(new CodeOfConductForm.Missing()) }),
locale: DefaultLocale,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Either } from 'effect'
import { DefaultLocale } from '../../../src/locales/index.js'
import type { NonEmptyString, Uuid } from '../../../src/types/index.js'
import { type NonEmptyString, Uuid } from '../../../src/types/index.js'
import * as CompetingInterestsForm from '../../../src/WriteCommentFlow/CompetingInterestsPage/CompetingInterestsForm.js'
import * as _ from '../../../src/WriteCommentFlow/CompetingInterestsPage/CompetingInterestsPage.js'
import { expect, test } from '../../base.js'

test('content looks right', async ({ showPage }) => {
const response = _.CompetingInterestsPage({
commentId: '7ad2f67d-dc01-48c5-b6ac-3490d494f67d' as Uuid.Uuid,
commentId: Uuid.Uuid('7ad2f67d-dc01-48c5-b6ac-3490d494f67d'),
form: new CompetingInterestsForm.EmptyForm(),
locale: DefaultLocale,
})
Expand All @@ -19,7 +19,7 @@ test('content looks right', async ({ showPage }) => {

test('content looks right when there are details', async ({ showPage }) => {
const response = _.CompetingInterestsPage({
commentId: '7ad2f67d-dc01-48c5-b6ac-3490d494f67d' as Uuid.Uuid,
commentId: Uuid.Uuid('7ad2f67d-dc01-48c5-b6ac-3490d494f67d'),
form: new CompetingInterestsForm.CompletedFormYes({
competingInterests: 'yes',
competingInterestsDetails:
Expand All @@ -35,7 +35,7 @@ test('content looks right when there are details', async ({ showPage }) => {

test('content looks right when missing', async ({ showPage }) => {
const response = _.CompetingInterestsPage({
commentId: '7ad2f67d-dc01-48c5-b6ac-3490d494f67d' as Uuid.Uuid,
commentId: Uuid.Uuid('7ad2f67d-dc01-48c5-b6ac-3490d494f67d'),
form: new CompetingInterestsForm.InvalidForm({
competingInterests: Either.left(new CompetingInterestsForm.Missing()),
competingInterestsDetails: Either.right(''),
Expand All @@ -50,7 +50,7 @@ test('content looks right when missing', async ({ showPage }) => {

test('content looks right when details are missing', async ({ showPage }) => {
const response = _.CompetingInterestsPage({
commentId: '7ad2f67d-dc01-48c5-b6ac-3490d494f67d' as Uuid.Uuid,
commentId: Uuid.Uuid('7ad2f67d-dc01-48c5-b6ac-3490d494f67d'),
form: new CompetingInterestsForm.InvalidForm({
competingInterests: Either.right('yes'),
competingInterestsDetails: Either.left(new CompetingInterestsForm.Missing()),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Either } from 'effect'
import { html } from '../../../src/html.js'
import { DefaultLocale } from '../../../src/locales/index.js'
import type { Uuid } from '../../../src/types/index.js'
import { Uuid } from '../../../src/types/index.js'
import * as EnterCommentForm from '../../../src/WriteCommentFlow/EnterCommentPage/EnterCommentForm.js'
import * as _ from '../../../src/WriteCommentFlow/EnterCommentPage/EnterCommentPage.js'
import { expect, test } from '../../base.js'

test('content looks right', async ({ showPage }) => {
const response = _.EnterCommentPage({
commentId: '7ad2f67d-dc01-48c5-b6ac-3490d494f67d' as Uuid.Uuid,
commentId: Uuid.Uuid('7ad2f67d-dc01-48c5-b6ac-3490d494f67d'),
form: new EnterCommentForm.EmptyForm(),
locale: DefaultLocale,
prereviewId: 10779310,
Expand All @@ -21,7 +21,7 @@ test('content looks right', async ({ showPage }) => {

test('content looks right when there is a comment', async ({ showPage }) => {
const response = _.EnterCommentPage({
commentId: '7ad2f67d-dc01-48c5-b6ac-3490d494f67d' as Uuid.Uuid,
commentId: Uuid.Uuid('7ad2f67d-dc01-48c5-b6ac-3490d494f67d'),
form: new EnterCommentForm.CompletedForm({ comment }),
locale: DefaultLocale,
prereviewId: 10779310,
Expand All @@ -34,7 +34,7 @@ test('content looks right when there is a comment', async ({ showPage }) => {

test('content looks right when the comment is missing', async ({ showPage }) => {
const response = _.EnterCommentPage({
commentId: '7ad2f67d-dc01-48c5-b6ac-3490d494f67d' as Uuid.Uuid,
commentId: Uuid.Uuid('7ad2f67d-dc01-48c5-b6ac-3490d494f67d'),
form: new EnterCommentForm.InvalidForm({ comment: Either.left(new EnterCommentForm.Missing()) }),
locale: DefaultLocale,
prereviewId: 10779310,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Either } from 'effect'
import { DefaultLocale } from '../../../src/locales/index.js'
import { EmailAddress, type Uuid } from '../../../src/types/index.js'
import { EmailAddress, Uuid } from '../../../src/types/index.js'
import * as EnterEmailAddressForm from '../../../src/WriteCommentFlow/EnterEmailAddressPage/EnterEmailAddressForm.js'
import * as _ from '../../../src/WriteCommentFlow/EnterEmailAddressPage/EnterEmailAddressPage.js'
import { expect, test } from '../../base.js'

test('content looks right', async ({ showPage }) => {
const response = _.EnterEmailAddressPage({
commentId: '7ad2f67d-dc01-48c5-b6ac-3490d494f67d' as Uuid.Uuid,
commentId: Uuid.Uuid('7ad2f67d-dc01-48c5-b6ac-3490d494f67d'),
form: new EnterEmailAddressForm.EmptyForm(),
locale: DefaultLocale,
})
Expand All @@ -19,7 +19,7 @@ test('content looks right', async ({ showPage }) => {

test('content looks right when there is an email address', async ({ showPage }) => {
const response = _.EnterEmailAddressPage({
commentId: '7ad2f67d-dc01-48c5-b6ac-3490d494f67d' as Uuid.Uuid,
commentId: Uuid.Uuid('7ad2f67d-dc01-48c5-b6ac-3490d494f67d'),
form: new EnterEmailAddressForm.CompletedForm({
emailAddress: EmailAddress.EmailAddress('[email protected]'),
}),
Expand All @@ -33,7 +33,7 @@ test('content looks right when there is an email address', async ({ showPage })

test('content looks right when the email address is missing', async ({ showPage }) => {
const response = _.EnterEmailAddressPage({
commentId: '7ad2f67d-dc01-48c5-b6ac-3490d494f67d' as Uuid.Uuid,
commentId: Uuid.Uuid('7ad2f67d-dc01-48c5-b6ac-3490d494f67d'),
form: new EnterEmailAddressForm.InvalidForm({ emailAddress: Either.left(new EnterEmailAddressForm.Missing()) }),
locale: DefaultLocale,
})
Expand All @@ -45,7 +45,7 @@ test('content looks right when the email address is missing', async ({ showPage

test('content looks right when the email address is invalid', async ({ showPage }) => {
const response = _.EnterEmailAddressPage({
commentId: '7ad2f67d-dc01-48c5-b6ac-3490d494f67d' as Uuid.Uuid,
commentId: Uuid.Uuid('7ad2f67d-dc01-48c5-b6ac-3490d494f67d'),
form: new EnterEmailAddressForm.InvalidForm({
emailAddress: Either.left(new EnterEmailAddressForm.Invalid({ value: 'not an email address' })),
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { DefaultLocale } from '../../../src/locales/index.js'
import { EmailAddress, type Uuid } from '../../../src/types/index.js'
import { EmailAddress, Uuid } from '../../../src/types/index.js'
import * as _ from '../../../src/WriteCommentFlow/NeedToVerifyEmailAddressPage/NeedToVerifyEmailAddressPage.js'
import { expect, test } from '../../base.js'

test('content looks right', async ({ showPage }) => {
const response = _.NeedToVerifyEmailAddressPage({
commentId: '7ad2f67d-dc01-48c5-b6ac-3490d494f67d' as Uuid.Uuid,
commentId: Uuid.Uuid('7ad2f67d-dc01-48c5-b6ac-3490d494f67d'),
emailAddress: EmailAddress.EmailAddress('[email protected]'),
locale: DefaultLocale,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as Doi from 'doi-ts'
import { DefaultLocale } from '../../../src/locales/index.js'
import type { Uuid } from '../../../src/types/index.js'
import { Uuid } from '../../../src/types/index.js'
import * as _ from '../../../src/WriteCommentFlow/PublishedPage/PublishedPage.js'
import { expect, test } from '../../base.js'

test('content looks right', async ({ showPage }) => {
const response = _.PublishedPage({
doi: Doi.Doi('10.5072/zenodo.107286'),
commentId: '7ad2f67d-dc01-48c5-b6ac-3490d494f67d' as Uuid.Uuid,
commentId: Uuid.Uuid('7ad2f67d-dc01-48c5-b6ac-3490d494f67d'),
locale: DefaultLocale,
prereviewId: 10779310,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { DefaultLocale } from '../../../src/locales/index.js'
import type { Uuid } from '../../../src/types/index.js'
import { Uuid } from '../../../src/types/index.js'
import * as _ from '../../../src/WriteCommentFlow/PublishingPage/PublishingPage.js'
import { expect, test } from '../../base.js'

test('content looks right', async ({ showPage }) => {
const response = _.PublishingPage({
commentId: '7ad2f67d-dc01-48c5-b6ac-3490d494f67d' as Uuid.Uuid,
commentId: Uuid.Uuid('7ad2f67d-dc01-48c5-b6ac-3490d494f67d'),
locale: DefaultLocale,
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { html } from '../../../src/html.js'
import { DefaultLocale } from '../../../src/locales/index.js'
import * as Prereview from '../../../src/Prereview.js'
import * as Routes from '../../../src/routes.js'
import type { Uuid } from '../../../src/types/index.js'
import { Uuid } from '../../../src/types/index.js'
import * as _ from '../../../src/WriteCommentFlow/StartNow/CarryOnPage.js'
import { expect, test } from '../../base.js'

import PlainDate = Temporal.PlainDate

test('content looks right', async ({ showPage }) => {
const response = _.CarryOnPage({
commentId: '7ad2f67d-dc01-48c5-b6ac-3490d494f67d' as Uuid.Uuid,
commentId: Uuid.Uuid('7ad2f67d-dc01-48c5-b6ac-3490d494f67d'),
nextPage: Routes.WriteCommentEnterComment,
prereview,
locale: DefaultLocale,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Orcid } from 'orcid-id-ts'
import type { Uuid } from 'uuid-ts'
import { Uuid } from 'uuid-ts'
import { checkPage } from '../../src/author-invite-flow/check-page/check-page.js'
import { failureMessage } from '../../src/author-invite-flow/check-page/failure-message.js'
import { DefaultLocale } from '../../src/locales/index.js'
Expand All @@ -8,7 +8,7 @@ import { expect, test } from '../base.js'

test('content looks right', async ({ showPage }) => {
const response = checkPage({
inviteId: 'ee9dd955-7b3b-4ad2-8a61-25dd42cb70f0' as Uuid,
inviteId: Uuid('ee9dd955-7b3b-4ad2-8a61-25dd42cb70f0'),
persona: 'public',
user: {
name: 'Josiah Carberry',
Expand All @@ -25,7 +25,7 @@ test('content looks right', async ({ showPage }) => {

test('content looks right when using a pseudonym', async ({ showPage }) => {
const response = checkPage({
inviteId: 'ee9dd955-7b3b-4ad2-8a61-25dd42cb70f0' as Uuid,
inviteId: Uuid('ee9dd955-7b3b-4ad2-8a61-25dd42cb70f0'),
persona: 'pseudonym',
user: {
name: 'Josiah Carberry',
Expand Down
Loading

0 comments on commit 16ea422

Please sign in to comment.