Skip to content

Commit

Permalink
Revise the ordering of type parameters within the SchemaStore inter… (
Browse files Browse the repository at this point in the history
#2792)

Co-authored-by: Tim <hello@timsmart.co>
  • Loading branch information
gcanti and tim-smart committed May 22, 2024
1 parent e376641 commit 78f6d4a
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 32 deletions.
5 changes: 5 additions & 0 deletions .changeset/light-foxes-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/platform": minor
---

Revise the ordering of type parameters within the `SchemaStore` interface to enhance consistency
2 changes: 1 addition & 1 deletion packages/platform/src/Http/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const catchTag: {
tag: K,
f: (e: Extract<E, { _tag: K }>) => Effect.Effect<A1, E1, R1>
): <A, R>(self: Client<A, E, R>) => Client<A1 | A, E1 | Exclude<E, { _tag: K }>, R1 | R>
<R, E extends { _tag: string }, A, K extends E["_tag"] & string, A1, E1, R1>(
<A, E extends { _tag: string }, R, K extends E["_tag"] & string, A1, E1, R1>(
self: Client<A, E, R>,
tag: K,
f: (e: Extract<E, { _tag: K }>) => Effect.Effect<A1, E1, R1>
Expand Down
8 changes: 4 additions & 4 deletions packages/platform/src/Http/IncomingMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const schemaBodyJsonScoped = <A, I, R>(schema: Schema.Schema<A, I, R>, op
* @since 1.0.0
* @category schema
*/
export const schemaBodyUrlParams = <R, I extends Readonly<Record<string, string>>, A>(
export const schemaBodyUrlParams = <A, I extends Readonly<Record<string, string>>, R>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => {
Expand All @@ -82,7 +82,7 @@ export const schemaBodyUrlParams = <R, I extends Readonly<Record<string, string>
* @since 1.0.0
* @category schema
*/
export const schemaBodyUrlParamsScoped = <R, I extends Readonly<Record<string, string>>, A>(
export const schemaBodyUrlParamsScoped = <A, I extends Readonly<Record<string, string>>, R>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => {
Expand All @@ -97,7 +97,7 @@ export const schemaBodyUrlParamsScoped = <R, I extends Readonly<Record<string, s
* @since 1.0.0
* @category schema
*/
export const schemaHeaders = <R, I extends Readonly<Record<string, string | undefined>>, A>(
export const schemaHeaders = <A, I extends Readonly<Record<string, string | undefined>>, R>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => {
Expand All @@ -109,7 +109,7 @@ export const schemaHeaders = <R, I extends Readonly<Record<string, string | unde
* @since 1.0.0
* @category schema
*/
export const schemaHeadersScoped = <R, I extends Readonly<Record<string, string>>, A>(
export const schemaHeadersScoped = <A, I extends Readonly<Record<string, string>>, R>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/platform/src/Http/Multipart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export const schemaJson: <A, I, R>(
* @since 1.0.0
* @category schema
*/
export const schemaPersisted: <R, I extends Partial<Persisted>, A>(
export const schemaPersisted: <A, I extends Partial<Persisted>, R>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => (persisted: Persisted) => Effect.Effect<A, ParseResult.ParseError, R> = internal.schemaPersisted
Expand Down
4 changes: 2 additions & 2 deletions packages/platform/src/Http/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export const schemaNoBody: <
* @since 1.0.0
* @category route context
*/
export const schemaParams: <R, I extends Readonly<Record<string, string | Array<string> | undefined>>, A>(
export const schemaParams: <A, I extends Readonly<Record<string, string | Array<string> | undefined>>, R>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => Effect.Effect<A, ParseResult.ParseError, R | RouteContext | ServerRequest.ParsedSearchParams> =
Expand All @@ -204,7 +204,7 @@ export const schemaParams: <R, I extends Readonly<Record<string, string | Array<
* @since 1.0.0
* @category route context
*/
export const schemaPathParams: <R, I extends Readonly<Record<string, string | undefined>>, A>(
export const schemaPathParams: <A, I extends Readonly<Record<string, string | undefined>>, R>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => Effect.Effect<A, ParseResult.ParseError, R | RouteContext> = internal.schemaPathParams
Expand Down
12 changes: 6 additions & 6 deletions packages/platform/src/Http/ServerRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const upgradeChannel: <IE = never>() => Channel<
* @since 1.0.0
* @category schema
*/
export const schemaCookies: <R, I extends Readonly<Record<string, string>>, A>(
export const schemaCookies: <A, I extends Readonly<Record<string, string>>, R>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => Effect.Effect<A, ParseResult.ParseError, ServerRequest | R> = internal.schemaCookies
Expand All @@ -142,7 +142,7 @@ export const schemaCookies: <R, I extends Readonly<Record<string, string>>, A>(
* @since 1.0.0
* @category schema
*/
export const schemaHeaders: <R, I extends Readonly<Record<string, string>>, A>(
export const schemaHeaders: <A, I extends Readonly<Record<string, string>>, R>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => Effect.Effect<A, ParseResult.ParseError, ServerRequest | R> = internal.schemaHeaders
Expand All @@ -151,7 +151,7 @@ export const schemaHeaders: <R, I extends Readonly<Record<string, string>>, A>(
* @since 1.0.0
* @category schema
*/
export const schemaSearchParams: <R, I extends Readonly<Record<string, string | Array<string> | undefined>>, A>(
export const schemaSearchParams: <A, I extends Readonly<Record<string, string | Array<string> | undefined>>, R>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => Effect.Effect<A, ParseResult.ParseError, ParsedSearchParams | R> = internal.schemaSearchParams
Expand All @@ -169,7 +169,7 @@ export const schemaBodyJson: <A, I, R>(
* @since 1.0.0
* @category schema
*/
export const schemaBodyForm: <R, I extends Partial<Multipart.Persisted>, A>(
export const schemaBodyForm: <A, I extends Partial<Multipart.Persisted>, R>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => Effect.Effect<
Expand All @@ -182,7 +182,7 @@ export const schemaBodyForm: <R, I extends Partial<Multipart.Persisted>, A>(
* @since 1.0.0
* @category schema
*/
export const schemaBodyUrlParams: <R, I extends Readonly<Record<string, string>>, A>(
export const schemaBodyUrlParams: <A, I extends Readonly<Record<string, string>>, R>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => Effect.Effect<A, ParseResult.ParseError | Error.RequestError, R | ServerRequest> = internal.schemaBodyUrlParams
Expand All @@ -191,7 +191,7 @@ export const schemaBodyUrlParams: <R, I extends Readonly<Record<string, string>>
* @since 1.0.0
* @category schema
*/
export const schemaBodyMultipart: <R, I extends Partial<Multipart.Persisted>, A>(
export const schemaBodyMultipart: <A, I extends Partial<Multipart.Persisted>, R>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => Effect.Effect<
Expand Down
8 changes: 4 additions & 4 deletions packages/platform/src/KeyValueStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export interface KeyValueStore {
/**
* Create a SchemaStore for the specified schema.
*/
readonly forSchema: <A, I, R>(schema: Schema.Schema<A, I, R>) => SchemaStore<R, A>
readonly forSchema: <A, I, R>(schema: Schema.Schema<A, I, R>) => SchemaStore<A, R>
}

/**
Expand Down Expand Up @@ -143,7 +143,7 @@ export type SchemaStoreTypeId = typeof SchemaStoreTypeId
* @since 1.0.0
* @category models
*/
export interface SchemaStore<R, A> {
export interface SchemaStore<A, R> {
readonly [SchemaStoreTypeId]: SchemaStoreTypeId
/**
* Returns the value of the specified key if it exists.
Expand Down Expand Up @@ -202,6 +202,6 @@ export const layerSchema: <A, I, R>(
schema: Schema.Schema<A, I, R>,
tagIdentifier: string
) => {
readonly tag: Context.Tag<SchemaStore<R, A>, SchemaStore<R, A>>
readonly layer: Layer.Layer<SchemaStore<R, A>, never, KeyValueStore>
readonly tag: Context.Tag<SchemaStore<A, R>, SchemaStore<A, R>>
readonly layer: Layer.Layer<SchemaStore<A, R>, never, KeyValueStore>
} = internal.layerSchema
4 changes: 2 additions & 2 deletions packages/platform/src/Transferable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ export const schema: {
<I>(
f: (_: I) => Iterable<globalThis.Transferable>
): <A, R>(self: Schema.Schema<A, I, R>) => Schema.Schema<A, I, R>
<R, I, A>(
<A, I, R>(
self: Schema.Schema<A, I, R>,
f: (_: I) => Iterable<globalThis.Transferable>
): Schema.Schema<A, I, R>
} = dual(2, <R, I, A>(
} = dual(2, <A, I, R>(
self: Schema.Schema<A, I, R>,
f: (_: I) => Iterable<globalThis.Transferable>
) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/platform/src/internal/http/multipart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const SingleFileSchema: Schema.transform<
})

/** @internal */
export const schemaPersisted = <R, I extends Partial<Multipart.Persisted>, A>(
export const schemaPersisted = <A, I extends Partial<Multipart.Persisted>, R>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/platform/src/internal/http/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const schemaNoBody = <
}

/** @internal */
export const schemaParams = <R, I extends Readonly<Record<string, string | Array<string> | undefined>>, A>(
export const schemaParams = <A, I extends Readonly<Record<string, string | Array<string> | undefined>>, R>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => {
Expand All @@ -128,7 +128,7 @@ export const schemaParams = <R, I extends Readonly<Record<string, string | Array
}

/** @internal */
export const schemaPathParams = <R, I extends Readonly<Record<string, string | undefined>>, A>(
export const schemaPathParams = <A, I extends Readonly<Record<string, string | undefined>>, R>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => {
Expand Down
12 changes: 6 additions & 6 deletions packages/platform/src/internal/http/serverRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const searchParamsFromURL = (url: URL): ReadonlyRecord<string, string | A
}

/** @internal */
export const schemaCookies = <R, I extends Readonly<Record<string, string>>, A>(
export const schemaCookies = <A, I extends Readonly<Record<string, string>>, R>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => {
Expand All @@ -70,7 +70,7 @@ export const schemaCookies = <R, I extends Readonly<Record<string, string>>, A>(
}

/** @internal */
export const schemaHeaders = <R, I extends Readonly<Record<string, string>>, A>(
export const schemaHeaders = <A, I extends Readonly<Record<string, string>>, R>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => {
Expand All @@ -79,7 +79,7 @@ export const schemaHeaders = <R, I extends Readonly<Record<string, string>>, A>(
}

/** @internal */
export const schemaSearchParams = <R, I extends Readonly<Record<string, string | Array<string> | undefined>>, A>(
export const schemaSearchParams = <A, I extends Readonly<Record<string, string | Array<string> | undefined>>, R>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => {
Expand All @@ -97,7 +97,7 @@ const isMultipart = (request: ServerRequest.ServerRequest) =>
request.headers["content-type"]?.toLowerCase().includes("multipart/form-data")

/** @internal */
export const schemaBodyForm = <R, I extends Partial<Multipart.Persisted>, A>(
export const schemaBodyForm = <A, I extends Partial<Multipart.Persisted>, R>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => {
Expand All @@ -116,7 +116,7 @@ export const schemaBodyForm = <R, I extends Partial<Multipart.Persisted>, A>(
}

/** @internal */
export const schemaBodyUrlParams = <R, I extends Readonly<Record<string, string>>, A>(
export const schemaBodyUrlParams = <A, I extends Readonly<Record<string, string>>, R>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => {
Expand All @@ -125,7 +125,7 @@ export const schemaBodyUrlParams = <R, I extends Readonly<Record<string, string>
}

/** @internal */
export const schemaBodyMultipart = <R, I extends Partial<Multipart.Persisted>, A>(
export const schemaBodyMultipart = <A, I extends Partial<Multipart.Persisted>, R>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/platform/src/internal/keyValueStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const SchemaStoreTypeId: KeyValueStore.SchemaStoreTypeId = Symbol.for(
const makeSchemaStore = <A, I, R>(
store: KeyValueStore.KeyValueStore,
schema: Schema.Schema<A, I, R>
): KeyValueStore.SchemaStore<R, A> => {
): KeyValueStore.SchemaStore<A, R> => {
const jsonSchema = Schema.parseJson(schema)
const parse = Schema.decodeUnknown(jsonSchema)
const encode = Schema.encode(jsonSchema)
Expand Down Expand Up @@ -170,7 +170,7 @@ export const layerSchema = <A, I, R>(
schema: Schema.Schema<A, I, R>,
tagIdentifier: string
) => {
const tag = Context.GenericTag<KeyValueStore.SchemaStore<R, A>>(tagIdentifier)
const tag = Context.GenericTag<KeyValueStore.SchemaStore<A, R>>(tagIdentifier)
const layer = Layer.effect(tag, Effect.map(keyValueStoreTag, (store) => store.forSchema(schema)))
return { tag, layer } as const
}
2 changes: 1 addition & 1 deletion packages/platform/test/KeyValueStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class User extends Schema.Class<User>("User")({
age: Schema.Number
}) {}
const UserStore = KeyValueStore.layerSchema(User, "UserStore")
const runUserStore = <E, A>(effect: Effect.Effect<A, E, KeyValueStore.SchemaStore<never, User>>) =>
const runUserStore = <E, A>(effect: Effect.Effect<A, E, KeyValueStore.SchemaStore<User, never>>) =>
Effect.runPromise(Effect.provide(effect, UserStore.layer.pipe(Layer.provide(KeyValueStore.layerMemory))))

describe("KeyValueStore / SchemaStore", () => {
Expand Down

0 comments on commit 78f6d4a

Please sign in to comment.