Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@effect/schema

Package Overview
Dependencies
Maintainers
3
Versions
335
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@effect/schema - npm Package Compare versions

Comparing version 0.35.0 to 0.35.1

6

package.json
{
"name": "@effect/schema",
"version": "0.35.0",
"version": "0.35.1",
"description": "Modeling the schema of data structures as first-class values",

@@ -31,5 +31,5 @@ "license": "MIT",

"peerDependencies": {
"@effect/data": "^0.18.3",
"@effect/io": "^0.40.0"
"@effect/data": "^0.18.5",
"@effect/io": "^0.40.1"
}
}

@@ -158,3 +158,3 @@ <h3 align="center">

```ts
interface Person extends S.To<typeof Person> {}
interface Person extends S.Schema.To<typeof Person> {}
/*

@@ -313,4 +313,4 @@ interface Person {

// Age is a schema that can parse a string to a number and encode a number to a string
const Age = S.numberFromString(S.string);
// Age is a schema that can decode a string to a number and encode a number to a string
const Age = S.NumberFromString;

@@ -641,3 +641,3 @@ const Person = S.struct({

const UserId = S.string.pipe(S.brand("UserId"));
type UserId = S.To<typeof UserId>; // string & Brand<"UserId">
type UserId = S.Schema.To<typeof UserId>; // string & Brand<"UserId">
```

@@ -653,3 +653,3 @@

const UserId = S.string.pipe(S.brand(UserIdBrand));
type UserId = S.To<typeof UserId>; // string & Brand<typeof UserIdBrand>
type UserId = S.Schema.To<typeof UserId>; // string & Brand<typeof UserIdBrand>
```

@@ -1270,3 +1270,3 @@

```ts
<I1, A1, I2, A2>(from: Schema<I1, A1>, to: Schema<I2, A2>, decode: (a1: A1) => I2, encode: (i2: I2) => A1): Schema<I1, A2>
<A, B, C, D>(from: Schema<A, B>, to: Schema<C, D>, decode: (b: B) => unknown, encode: (c: C) => unknown): Schema<A, D>
```

@@ -1276,9 +1276,9 @@

flowchart TD
schema1["from: Schema&lt;I1, A1&gt;"]
schema2["to: Schema&lt;I2, A2&gt;"]
schema1--decode: A1 -> I2-->schema2
schema2--encode: I2 -> A1-->schema1
schema1["from: Schema&lt;A, B&gt;"]
schema2["to: Schema&lt;C, D&gt;"]
schema1--decode: B -> C-->schema2
schema2--encode: C -> B-->schema1
```
The `transform` combinator takes a target schema, a transformation function from the source type to the target type, and a reverse transformation function from the target type back to the source type. It returns a new schema that applies the transformation function to the output of the original schema before returning it. If the original schema fails to parse a value, the transformed schema will also fail.
The `transform` combinator takes a source schema, a target schema, a transformation function from the source type to the target type, and a reverse transformation function from the target type back to the source type. It returns a new schema that applies the transformation function to the output of the original schema before returning it. If the original schema fails to parse a value, the transformed schema will also fail.

@@ -1307,3 +1307,3 @@ ```ts

```ts
import * as PR from "@effect/schema/ParseResult";
import * as ParseResult from "@effect/schema/ParseResult";
import * as S from "@effect/schema/Schema";

@@ -1317,8 +1317,10 @@

s === "true"
? PR.success(true)
? ParseResult.success(true)
: s === "false"
? PR.success(false)
: PR.failure(PR.type(S.literal("true", "false").ast, s)),
? ParseResult.success(false)
: ParseResult.failure(
ParseResult.type(S.literal("true", "false").ast, s)
),
// define a function that converts a boolean into a string
(b) => PR.success(String(b))
(b) => ParseResult.success(String(b))
);

@@ -1331,5 +1333,5 @@ ```

import * as S from "@effect/schema/Schema";
import * as PR from "@effect/schema/ParseResult";
import * as ParseResult from "@effect/schema/ParseResult";
import * as Effect from "@effect/io/Effect";
import * as TF from "@effect/schema/TreeFormatter";
import * as TreeFormatter from "@effect/schema/TreeFormatter";

@@ -1355,6 +1357,7 @@ const api = (url: string) =>

Effect.mapBoth(api(`https://swapi.dev/api/people/${s}`), {
onFailure: (e) => PR.parseError([PR.type(PeopleId.ast, s, e.message)]),
onFailure: (e) =>
ParseResult.parseError([ParseResult.type(PeopleId.ast, s, e.message)]),
onSuccess: () => s
}),
PR.success
ParseResult.success
);

@@ -1364,3 +1367,3 @@

Effect.mapError(S.parse(PeopleIdFromString)(id), (e) =>
TF.formatErrors(e.errors)
TreeFormatter.formatErrors(e.errors)
);

@@ -1502,5 +1505,21 @@

### Symbol transformations
#### symbol
Transforms a `string` into a `symbol` by parsing the string using `Symbol.for`.
```ts
import * as S from "@effect/schema/Schema";
// $ExpectType Schema<string, symbol>
const schema = S.symbol;
const parse = S.parseSync(schema);
parse("a"); // Symbol.for("a")
```
### Bigint transformations
#### BigintFromString
#### bigint

@@ -1513,3 +1532,3 @@ Transforms a `string` into a `bigint` by parsing the string using `BigInt`.

// $ExpectType Schema<string, bigint>
const schema = S.BigintFromString;
const schema = S.bigint;
const parse = S.parseSync(schema);

@@ -1799,3 +1818,3 @@

import * as AST from "@effect/schema/AST";
import * as O from "@effect/data/Option";
import * as Option from "@effect/data/Option";

@@ -1809,3 +1828,3 @@ const pair = <A>(schema: S.Schema<A>): S.Schema<readonly [A, A]> => {

[element, element], // <= elements definitions
O.none, // <= rest element
Option.none(), // <= rest element
true // <= is readonly?

@@ -1894,3 +1913,3 @@ );

```ts
import * as O from "@effect/data/Option";
import * as Option from "@effect/data/Option";
import { pipe } from "@effect/data/Function";

@@ -1901,3 +1920,3 @@

AST.getAnnotation<boolean>(DeprecatedId)(schema.ast),
O.getOrElse(() => false)
Option.getOrElse(() => false)
);

@@ -1904,0 +1923,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc