effect 3.10.7 → 3.10.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/Schema.ts CHANGED
@@ -8240,6 +8240,26 @@ export interface Class<Self, Fields extends Struct.Fields, I, R, C, Inherited, P
8240
8240
 
8241
8241
  readonly identifier: string
8242
8242
 
8243
+ /**
8244
+ * @example
8245
+ * import { Schema } from "effect"
8246
+ *
8247
+ * class MyClass extends Schema.Class<MyClass>("MyClass")({
8248
+ * myField: Schema.String
8249
+ * }) {
8250
+ * myMethod() {
8251
+ * return this.myField + "my"
8252
+ * }
8253
+ * }
8254
+ *
8255
+ * class NextClass extends MyClass.extend<NextClass>("NextClass")({
8256
+ * nextField: Schema.Number
8257
+ * }) {
8258
+ * nextMethod() {
8259
+ * return this.myMethod() + this.myField + this.nextField
8260
+ * }
8261
+ * }
8262
+ */
8243
8263
  extend<Extended = never>(identifier: string): <newFields extends Struct.Fields>(
8244
8264
  fields: newFields | HasFields<newFields>,
8245
8265
  annotations?: Annotations.Schema<Extended>
@@ -8254,6 +8274,33 @@ export interface Class<Self, Fields extends Struct.Fields, I, R, C, Inherited, P
8254
8274
  Proto
8255
8275
  >
8256
8276
 
8277
+ /**
8278
+ * @example
8279
+ * import { Effect, Schema } from "effect"
8280
+ *
8281
+ * class MyClass extends Schema.Class<MyClass>("MyClass")({
8282
+ * myField: Schema.String
8283
+ * }) {
8284
+ * myMethod() {
8285
+ * return this.myField + "my"
8286
+ * }
8287
+ * }
8288
+ *
8289
+ * class NextClass extends MyClass.transformOrFail<NextClass>("NextClass")({
8290
+ * nextField: Schema.Number
8291
+ * }, {
8292
+ * decode: (i) =>
8293
+ * Effect.succeed({
8294
+ * myField: i.myField,
8295
+ * nextField: i.myField.length
8296
+ * }),
8297
+ * encode: (a) => Effect.succeed({ myField: a.myField })
8298
+ * }) {
8299
+ * nextMethod() {
8300
+ * return this.myMethod() + this.myField + this.nextField
8301
+ * }
8302
+ * }
8303
+ */
8257
8304
  transformOrFail<Transformed = never>(identifier: string): <
8258
8305
  newFields extends Struct.Fields,
8259
8306
  R2,
@@ -8284,6 +8331,33 @@ export interface Class<Self, Fields extends Struct.Fields, I, R, C, Inherited, P
8284
8331
  Proto
8285
8332
  >
8286
8333
 
8334
+ /**
8335
+ * @example
8336
+ * import { Effect, Schema } from "effect"
8337
+ *
8338
+ * class MyClass extends Schema.Class<MyClass>("MyClass")({
8339
+ * myField: Schema.String
8340
+ * }) {
8341
+ * myMethod() {
8342
+ * return this.myField + "my"
8343
+ * }
8344
+ * }
8345
+ *
8346
+ * class NextClass extends MyClass.transformOrFailFrom<NextClass>("NextClass")({
8347
+ * nextField: Schema.Number
8348
+ * }, {
8349
+ * decode: (i) =>
8350
+ * Effect.succeed({
8351
+ * myField: i.myField,
8352
+ * nextField: i.myField.length
8353
+ * }),
8354
+ * encode: (a) => Effect.succeed({ myField: a.myField })
8355
+ * }) {
8356
+ * nextMethod() {
8357
+ * return this.myMethod() + this.myField + this.nextField
8358
+ * }
8359
+ * }
8360
+ */
8287
8361
  transformOrFailFrom<Transformed = never>(identifier: string): <
8288
8362
  newFields extends Struct.Fields,
8289
8363
  R2,
@@ -8334,6 +8408,17 @@ const getFieldsFromFieldsOr = <Fields extends Struct.Fields>(fieldsOr: Fields |
8334
8408
  isFields(fieldsOr) ? fieldsOr : getFields(fieldsOr)
8335
8409
 
8336
8410
  /**
8411
+ * @example
8412
+ * import { Schema } from "effect"
8413
+ *
8414
+ * class MyClass extends Schema.Class<MyClass>("MyClass")({
8415
+ * someField: Schema.String
8416
+ * }) {
8417
+ * someMethod() {
8418
+ * return this.someField + "bar"
8419
+ * }
8420
+ * }
8421
+ *
8337
8422
  * @category classes
8338
8423
  * @since 3.10.0
8339
8424
  */
@@ -8383,6 +8468,13 @@ export interface TaggedClass<Self, Tag extends string, Fields extends Struct.Fie
8383
8468
  }
8384
8469
 
8385
8470
  /**
8471
+ * @example
8472
+ * import { Schema } from "effect"
8473
+ *
8474
+ * class MyClass extends Schema.TaggedClass<MyClass>("MyClass")("MyClass", {
8475
+ * a: Schema.String
8476
+ * }) {}
8477
+ *
8386
8478
  * @category classes
8387
8479
  * @since 3.10.0
8388
8480
  */
@@ -8429,6 +8521,21 @@ export interface TaggedErrorClass<Self, Tag extends string, Fields extends Struc
8429
8521
  }
8430
8522
 
8431
8523
  /**
8524
+ * @example
8525
+ * import { Schema } from "effect"
8526
+ *
8527
+ * class MyError extends Schema.TaggedError<MyError>("MyError")(
8528
+ * "MyError",
8529
+ * {
8530
+ * module: Schema.String,
8531
+ * method: Schema.String,
8532
+ * description: Schema.String
8533
+ * }
8534
+ * ) {
8535
+ * get message(): string {
8536
+ * return `${this.module}.${this.method}: ${this.description}`
8537
+ * }
8538
+ * }
8432
8539
  * @category classes
8433
8540
  * @since 3.10.0
8434
8541
  */
@@ -10153,6 +10260,15 @@ export interface TaggedRequestClass<
10153
10260
  }
10154
10261
 
10155
10262
  /**
10263
+ * @example
10264
+ * import { Schema } from "effect"
10265
+ *
10266
+ * class MyRequest extends Schema.TaggedRequest<MyRequest>("MyRequest")("MyRequest", {
10267
+ * failure: Schema.String,
10268
+ * success: Schema.Number,
10269
+ * payload: { id: Schema.String }
10270
+ * }) {}
10271
+ *
10156
10272
  * @category classes
10157
10273
  * @since 3.10.0
10158
10274
  */
@@ -223,7 +223,7 @@ export const number = (name?: string): Config.Config<number> => {
223
223
  const config = primitive(
224
224
  "a number property",
225
225
  (text) => {
226
- const result = Number.parseFloat(text)
226
+ const result = Number(text)
227
227
  if (Number.isNaN(result)) {
228
228
  return Either.left(
229
229
  configError.InvalidData(
@@ -243,8 +243,8 @@ export const integer = (name?: string): Config.Config<number> => {
243
243
  const config = primitive(
244
244
  "an integer property",
245
245
  (text) => {
246
- const result = Number.parseInt(text, 10)
247
- if (Number.isNaN(result)) {
246
+ const result = Number(text)
247
+ if (!Number.isInteger(result)) {
248
248
  return Either.left(
249
249
  configError.InvalidData(
250
250
  [],
@@ -1330,11 +1330,6 @@ export class FiberRuntime<in out A, in out E = never> extends Effectable.Class<A
1330
1330
  }
1331
1331
  }
1332
1332
  try {
1333
- if (!("_op" in cur) || !((cur as core.Primitive)._op in this)) {
1334
- // @ts-expect-error
1335
- absurd(cur)
1336
- }
1337
-
1338
1333
  // @ts-expect-error
1339
1334
  cur = this.currentTracer.context(
1340
1335
  () => {
@@ -1369,7 +1364,9 @@ export class FiberRuntime<in out A, in out E = never> extends Effectable.Class<A
1369
1364
  core.exitFailCause(internalCause.die(op))
1370
1365
  }
1371
1366
  } catch (e) {
1372
- if (core.isEffectError(e)) {
1367
+ if (cur !== YieldedOp && !Predicate.hasProperty(cur, "_op") || !((cur as core.Primitive)._op in this)) {
1368
+ cur = core.dieMessage(`Not a valid effect: ${Inspectable.toStringUnknown(cur)}`)
1369
+ } else if (core.isEffectError(e)) {
1373
1370
  cur = core.exitFailCause(e.cause)
1374
1371
  } else if (core.isInterruptedException(e)) {
1375
1372
  cur = core.exitFailCause(
@@ -1,4 +1,4 @@
1
- let moduleVersion = "3.10.7"
1
+ let moduleVersion = "3.10.8"
2
2
 
3
3
  export const getCurrentVersion = () => moduleVersion
4
4