@typed/guard 0.7.0 → 0.7.1
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/dist/Guardable.d.ts +1 -1
- package/dist/Guardable.js +1 -1
- package/dist/Guardable.js.map +1 -1
- package/package.json +1 -1
- package/readme.md +4 -2
- package/src/ExtensibleFunction.test.ts +1 -3
- package/src/Guard.test.ts +2 -2
- package/src/Guardable.ts +5 -4
package/dist/Guardable.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Pipeable } from 'effect';
|
|
2
|
-
import { ExtensibleFunction } from './ExtensibleFunction';
|
|
2
|
+
import { ExtensibleFunction } from './ExtensibleFunction.js';
|
|
3
3
|
import type { Guard } from './Guard.js';
|
|
4
4
|
export declare const GUARDABLE: unique symbol;
|
|
5
5
|
export type GUARDABLE = typeof GUARDABLE;
|
package/dist/Guardable.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Pipeable } from 'effect';
|
|
2
|
-
import { ExtensibleFunction } from './ExtensibleFunction';
|
|
2
|
+
import { ExtensibleFunction } from './ExtensibleFunction.js';
|
|
3
3
|
export const GUARDABLE = Symbol.for('@typed/guard/Guardable');
|
|
4
4
|
export class Guardable extends ExtensibleFunction {
|
|
5
5
|
constructor() {
|
package/dist/Guardable.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Guardable.js","sourceRoot":"","sources":["../src/Guardable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Guardable.js","sourceRoot":"","sources":["../src/Guardable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAG5D,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAA;AAG7D,MAAM,OAAgB,SACpB,SAAQ,kBAAqC;IAG7C;QACE,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,CAAA;IAC1C,CAAC;IAID,IAAI;QACF,mEAAmE;QACnE,OAAO,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;IAChD,CAAC;CACF"}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -73,7 +73,7 @@ const stringToLength = (s: string) =>
|
|
|
73
73
|
Effect.succeed(s.length > 1 ? Option.some(s.length) : Option.none())
|
|
74
74
|
|
|
75
75
|
// Compose them together
|
|
76
|
-
const composed: Guard<number, number> = Guard.compose(
|
|
76
|
+
const composed: Guard<number, number> = Guard.compose(numberToString, stringLength)
|
|
77
77
|
```
|
|
78
78
|
|
|
79
79
|
#### Filtering and Mapping
|
|
@@ -108,12 +108,14 @@ const withTaggedRecovery = Guard.catchTag(
|
|
|
108
108
|
```typescript
|
|
109
109
|
import { Schema } from 'effect'
|
|
110
110
|
|
|
111
|
-
const PersonSchema = Schema.
|
|
111
|
+
const PersonSchema = Schema.Struct({
|
|
112
112
|
name: Schema.string,
|
|
113
113
|
age: Schema.number
|
|
114
114
|
})
|
|
115
115
|
|
|
116
116
|
const personGuard = Guard.fromSchemaDecode(PersonSchema)
|
|
117
|
+
const personGuard = Guard.fromSchemaDecodeUnknown(PersonSchema)
|
|
118
|
+
const personGuard = Guard.fromSchemaEncode(PersonSchema)
|
|
117
119
|
```
|
|
118
120
|
|
|
119
121
|
## Advanced Usage
|
package/src/Guard.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Effect,
|
|
1
|
+
import { Effect, Option, pipe, Predicate, Schema } from 'effect'
|
|
2
2
|
import { describe, expect, it } from 'vitest'
|
|
3
|
-
import * as Guard from './Guard'
|
|
3
|
+
import * as Guard from './Guard.js'
|
|
4
4
|
|
|
5
5
|
describe('Guard', () => {
|
|
6
6
|
// Helper function to run a guard and get the result
|
package/src/Guardable.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Pipeable } from 'effect'
|
|
2
|
-
import { ExtensibleFunction } from './ExtensibleFunction'
|
|
2
|
+
import { ExtensibleFunction } from './ExtensibleFunction.js'
|
|
3
3
|
import type { Guard } from './Guard.js'
|
|
4
4
|
|
|
5
5
|
export const GUARDABLE = Symbol.for('@typed/guard/Guardable')
|
|
6
6
|
export type GUARDABLE = typeof GUARDABLE
|
|
7
7
|
|
|
8
|
-
export abstract class Guardable<I, O, E = never, R = never>
|
|
9
|
-
Guard<I, O, E, R
|
|
10
|
-
|
|
8
|
+
export abstract class Guardable<I, O, E = never, R = never>
|
|
9
|
+
extends ExtensibleFunction<Guard<I, O, E, R>>
|
|
10
|
+
implements Pipeable.Pipeable
|
|
11
|
+
{
|
|
11
12
|
constructor() {
|
|
12
13
|
super((input) => this[GUARDABLE](input))
|
|
13
14
|
}
|