Skip to content

Commit

Permalink
porting of #3792 (#3793)
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti authored and tim-smart committed Oct 17, 2024
1 parent bba35b3 commit 3c7c1bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
13 changes: 5 additions & 8 deletions packages/effect/src/SchemaAST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2183,18 +2183,15 @@ export const getPropertyKeyIndexedAccess = (ast: AST, name: PropertyKey): Proper
case "Refinement":
return getPropertyKeyIndexedAccess(ast.from, name)
}
return new PropertySignature(name, neverKeyword, false, true)
throw new Error(errors_.getASTUnsupportedSchema(ast))
}

const getPropertyKeys = (ast: AST): Array<PropertyKey> => {
const annotation = getSurrogateAnnotation(ast)
if (Option.isSome(annotation)) {
return getPropertyKeys(annotation.value)
}
switch (ast._tag) {
case "Declaration": {
const annotation = getSurrogateAnnotation(ast)
if (Option.isSome(annotation)) {
return getPropertyKeys(annotation.value)
}
break
}
case "TypeLiteral":
return ast.propertySignatures.map((ps) => ps.name)
case "Suspend":
Expand Down
14 changes: 7 additions & 7 deletions packages/effect/test/Schema/Schema/pick.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { describe, expect, it } from "vitest"

describe("pick", () => {
it("Struct", async () => {
const a = Symbol.for("effect/Schema/test/a")
const a = Symbol.for("@effect/schema/test/a")
const schema = S.Struct({ [a]: S.String, b: S.NumberFromString, c: S.Boolean }).pipe(
S.pick(a, "b")
)
Expand Down Expand Up @@ -113,22 +113,22 @@ describe("pick", () => {
})

it("Record(symbol, number)", async () => {
const a = Symbol.for("effect/Schema/test/a")
const b = Symbol.for("effect/Schema/test/b")
const a = Symbol.for("@effect/schema/test/a")
const b = Symbol.for("@effect/schema/test/b")
const schema = S.Record({ key: S.SymbolFromSelf, value: S.Number }).pipe(S.pick(a, b))
await Util.expectDecodeUnknownSuccess(schema, { [a]: 1, [b]: 2 })
await Util.expectDecodeUnknownFailure(
schema,
{ [a]: "a", [b]: 2 },
`{ readonly Symbol(effect/Schema/test/a): number; readonly Symbol(effect/Schema/test/b): number }
└─ [Symbol(effect/Schema/test/a)]
`{ readonly Symbol(@effect/schema/test/a): number; readonly Symbol(@effect/schema/test/b): number }
└─ [Symbol(@effect/schema/test/a)]
└─ Expected number, actual "a"`
)
await Util.expectDecodeUnknownFailure(
schema,
{ [a]: 1, [b]: "b" },
`{ readonly Symbol(effect/Schema/test/a): number; readonly Symbol(effect/Schema/test/b): number }
└─ [Symbol(effect/Schema/test/b)]
`{ readonly Symbol(@effect/schema/test/a): number; readonly Symbol(@effect/schema/test/b): number }
└─ [Symbol(@effect/schema/test/b)]
└─ Expected number, actual "b"`
)
})
Expand Down

0 comments on commit 3c7c1bc

Please sign in to comment.