@typed/guard 0.5.0 → 0.7.0

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/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ 22
package/biome.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "organizeImports": {
3
+ "enabled": true
4
+ },
5
+ "linter": {
6
+ "enabled": true,
7
+ "rules": {
8
+ "recommended": true,
9
+ "suspicious": {
10
+ "noExplicitAny": "off",
11
+ "noAssignInExpressions": "off",
12
+ "noShadowRestrictedNames": "off"
13
+ },
14
+ "style": {
15
+ "noParameterAssign": "off",
16
+ "noUselessElse": "off"
17
+ },
18
+ "complexity": {
19
+ "noBannedTypes": "off"
20
+ }
21
+ }
22
+ },
23
+ "formatter": {
24
+ "enabled": true,
25
+ "indentStyle": "space",
26
+ "indentWidth": 2,
27
+ "lineWidth": 100
28
+ },
29
+ "javascript": {
30
+ "formatter": {
31
+ "quoteStyle": "single",
32
+ "trailingCommas": "all",
33
+ "semicolons": "asNeeded"
34
+ }
35
+ }
36
+ }
@@ -0,0 +1 @@
1
+ export declare const ExtensibleFunction: new <F extends (...inputs: readonly any[]) => any>(f: F) => F;
@@ -0,0 +1,7 @@
1
+ function Extensible(f) {
2
+ return Object.setPrototypeOf(f, new.target.prototype);
3
+ }
4
+ Extensible.prototype = Function.prototype;
5
+ // Hack to make the type inference work
6
+ export const ExtensibleFunction = Extensible;
7
+ //# sourceMappingURL=ExtensibleFunction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExtensibleFunction.js","sourceRoot":"","sources":["../src/ExtensibleFunction.ts"],"names":[],"mappings":"AAAA,SAAS,UAAU,CAAO,CAAkB;IAC1C,OAAO,MAAM,CAAC,cAAc,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;AACvD,CAAC;AACD,UAAU,CAAC,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAA;AAEzC,uCAAuC;AACvC,MAAM,CAAC,MAAM,kBAAkB,GAC7B,UAAiB,CAAA"}
@@ -0,0 +1,143 @@
1
+ import { type Cause, type Context, Effect, type Layer, Option, Pipeable, type Predicate, type Runtime, Schema } from 'effect';
2
+ export type Guard<I, O = never, E = never, R = never> = (input: I) => Effect.Effect<Option.Option<O>, E, R> | Effect.Effect<never, E, R>;
3
+ export declare namespace Guard {
4
+ type Input<T> = [T] extends [Guard<infer I, infer _R, infer _E, infer _O>] ? I : never;
5
+ type Output<T> = [T] extends [Guard<infer _I, infer O, infer _E, infer _R>] ? O : never;
6
+ type Error<T> = [T] extends [Guard<infer _I, infer _O, infer E, infer _R>] ? E : never;
7
+ type Context<T> = [T] extends [Guard<infer _I, infer _O, infer _E, infer R>] ? R : never;
8
+ }
9
+ export declare const identity: <A>(a: A) => Effect.Effect<Option.Option<A>>;
10
+ export declare const compose: {
11
+ <O, B, E2, R2>(output: Guard<O, B, E2, R2>): <I, R, E>(input: Guard<I, O, E, R>) => Guard<I, B, E | E2, R | R2>;
12
+ <I, O, E, R, B, E2, R2>(input: Guard<I, O, E, R>, output: Guard<O, B, E2, R2>): Guard<I, B, E | E2, R | R2>;
13
+ };
14
+ export declare const mapEffect: {
15
+ <O, B, E2, R2>(f: (o: O) => Effect.Effect<B, E2, R2>): <I, R, E>(guard: Guard<I, O, E, R>) => Guard<I, B, E | E2, R | R2>;
16
+ <I, O, E, R, B, E2, R2>(guard: Guard<I, O, E, R>, f: (o: O) => Effect.Effect<B, E2, R2>): Guard<I, B, E | E2, R | R2>;
17
+ };
18
+ export declare const map: {
19
+ <O, B>(f: (o: O) => B): <I, R, E>(guard: Guard<I, O, E, R>) => Guard<I, B, E, R>;
20
+ <I, O, E, R, B>(guard: Guard<I, O, E, R>, f: (o: O) => B): Guard<I, B, E, R>;
21
+ };
22
+ export declare const tap: {
23
+ <O, B, E2, R2>(f: (o: O) => Effect.Effect<B, E2, R2>): <I, R, E>(guard: Guard<I, O, E, R>) => Guard<I, O, E | E2, R | R2>;
24
+ <I, O, E, R, B, E2, R2>(guard: Guard<I, O, E, R>, f: (o: O) => Effect.Effect<B, E2, R2>): Guard<I, O, E | E2, R | R2>;
25
+ };
26
+ export declare const filterMap: {
27
+ <O, B>(f: (o: O) => Option.Option<B>): <I, R, E>(guard: Guard<I, O, E, R>) => Guard<I, B, E, R>;
28
+ <I, O, E, R, B>(guard: Guard<I, O, E, R>, f: (o: O) => Option.Option<B>): Guard<I, B, E, R>;
29
+ };
30
+ export declare const filter: {
31
+ <O, O2 extends O>(predicate: (o: O) => o is O2): <I, R, E>(guard: Guard<I, O, E, R>) => Guard<I, O, E, R>;
32
+ <O>(predicate: (o: O) => boolean): <I, R, E>(guard: Guard<I, O, E, R>) => Guard<I, O, E, R>;
33
+ <I, O, E, R, O2 extends O>(guard: Guard<I, O, E, R>, predicate: (o: O) => o is O2): Guard<I, O, E, R>;
34
+ <I, O, E, R>(guard: Guard<I, O, E, R>, predicate: (o: O) => boolean): Guard<I, O, E, R>;
35
+ };
36
+ export declare function any<const GS extends Readonly<Record<string, Guard<any, any, any, any>>>>(guards: GS): Guard<AnyInput<GS>, AnyOutput<GS>, Guard.Error<GS[keyof GS]>, Guard.Context<GS[keyof GS]>>;
37
+ export type AnyInput<GS extends Readonly<Record<string, Guard<any, any, any, any>>>> = Guard.Input<GS[keyof GS]>;
38
+ export type AnyOutput<GS extends Readonly<Record<string, Guard<any, any, any, any>>>> = [
39
+ {
40
+ [K in keyof GS]: {
41
+ readonly _tag: K;
42
+ readonly value: Guard.Output<GS[K]>;
43
+ };
44
+ }[keyof GS]
45
+ ] extends [infer R] ? R : never;
46
+ export declare function liftPredicate<A, B extends A>(predicate: Predicate.Refinement<A, B>): Guard<A, B>;
47
+ export declare function liftPredicate<A>(predicate: Predicate.Predicate<A>): Guard<A, A>;
48
+ export declare const catchAllCause: {
49
+ <E = never, O2 = never, E2 = never, R2 = never>(f: (e: Cause.Cause<E>) => Effect.Effect<O2, E2, R2>): <I = never, O = never, R = never>(guard: Guard<I, O, E, R>) => Guard<I, O | O2, E2, R | R2>;
50
+ <I = never, O = never, E = never, R = never, O2 = never, E2 = never, R2 = never>(guard: Guard<I, O, E, R>, f: (e: Cause.Cause<E>) => Effect.Effect<O2, E2, R2>): Guard<I, O | O2, E2, R | R2>;
51
+ };
52
+ export declare const catchAll: {
53
+ <E = never, O2 = never, E2 = never, R2 = never>(f: (e: E) => Effect.Effect<O2, E2, R2>): <I = never, O = never, R = never>(guard: Guard<I, O, E, R>) => Guard<I, O | O2, E2, R | R2>;
54
+ <I = never, O = never, E = never, R = never, O2 = never, E2 = never, R2 = never>(guard: Guard<I, O, E, R>, f: (e: E) => Effect.Effect<O2, E2, R2>): Guard<I, O | O2, E2, R | R2>;
55
+ };
56
+ export declare const catchTag: {
57
+ <E = never, K extends E extends {
58
+ _tag: string;
59
+ } ? E['_tag'] : never = never, O2 = never, E2 = never, R2 = never>(tag: K, f: (e: Extract<E, {
60
+ _tag: K;
61
+ }>) => Effect.Effect<O2, E2, R2>): <I = never, O = never, R = never>(guard: Guard<I, O, E, R>) => Guard<I, O | O2, E2 | Exclude<E, {
62
+ _tag: K;
63
+ }>, R | R2>;
64
+ <I = never, O = never, E = never, R = never, K extends E extends {
65
+ _tag: string;
66
+ } ? E['_tag'] : never = never, O2 = never, E2 = never, R2 = never>(guard: Guard<I, O, E, R>, tag: K, f: (e: Extract<E, {
67
+ _tag: K;
68
+ }>) => Effect.Effect<O2, E2, R2>): Guard<I, O | O2, E2 | Exclude<E, {
69
+ _tag: K;
70
+ }>, R | R2>;
71
+ };
72
+ export declare const provide: {
73
+ <R2>(provided: Context.Context<R2>): <I, O, E, R>(guard: Guard<I, O, E, R>) => Guard<I, O, E, Exclude<R, R2>>;
74
+ <R2>(provided: Runtime.Runtime<R2>): <I, O, E, R>(guard: Guard<I, O, E, R>) => Guard<I, O, E, Exclude<R, R2>>;
75
+ <R2, E2, R3>(provided: Layer.Layer<R2, E2, R3>): <I, O, E, R>(guard: Guard<I, O, E, R>) => Guard<I, O, E | E2, Exclude<R, R2> | R3>;
76
+ <I, O, E, R, R2>(guard: Guard<I, O, E, R>, provided: Context.Context<R2>): Guard<I, O, E, Exclude<R, R2>>;
77
+ <I, O, E, R, R2>(guard: Guard<I, O, E, R>, provided: Runtime.Runtime<R2>): Guard<I, O, E, Exclude<R, R2>>;
78
+ <I, O, E, R, R2, E2, R3>(guard: Guard<I, O, E, R>, provided: Layer.Layer<R2, E2, R3>): Guard<I, O, E | E2, Exclude<R, R2> | R3>;
79
+ };
80
+ export declare const provideService: {
81
+ <Id, S>(tag: Context.Tag<Id, S>, service: S): <I, O, E, R>(guard: Guard<I, O, E, R>) => Guard<I, O, E, Exclude<R, Id>>;
82
+ <I, O, E, R, Id, S>(guard: Guard<I, O, E, R>, tag: Context.Tag<Id, S>, service: S): Guard<I, O, E, Exclude<R, Id>>;
83
+ };
84
+ export declare const provideServiceEffect: {
85
+ <Id, S, E2, R2>(tag: Context.Tag<Id, S>, service: Effect.Effect<S, E2, R2>): <I, O, E, R>(guard: Guard<I, O, E, R>) => Guard<I, O, E | E2, Exclude<R, Id> | R2>;
86
+ <I, O, E, R, Id, S, E2, R2>(guard: Guard<I, O, E, R>, tag: Context.Tag<Id, S>, service: Effect.Effect<S, E2, R2>): Guard<I, O, E | E2, Exclude<R, Id> | R2>;
87
+ };
88
+ export declare function fromSchemaDecode<A, I, R>(schema: Schema.Schema<A, I, R>): Guard<I, A, never, R>;
89
+ export declare function fromSchemaDecodeUnknown<A, I, R>(schema: Schema.Schema<A, I, R>): Guard<unknown, A, never, R>;
90
+ export declare function fromSchemaEncode<A, I, R>(schema: Schema.Schema<A, I, R>): Guard<A, I, never, R>;
91
+ export declare const decode: {
92
+ <A, O, R2>(schema: Schema.Schema<A, O, R2>): <I, E = never, R = never>(guard: Guard<I, O, E, R>) => Guard<I, A, E, R | R2>;
93
+ <I, O, E, R, A, R2>(guard: Guard<I, O, E, R>, schema: Schema.Schema<A, O, R2>): Guard<I, A, E, R | R2>;
94
+ };
95
+ export declare const encode: {
96
+ <O, A, R2>(schema: Schema.Schema<O, A, R2>): <I, E = never, R = never>(guard: Guard<I, O, E, R>) => Guard<I, A, E, R | R2>;
97
+ <I, O, E, R, A, R2>(guard: Guard<I, O, E, R>, schema: Schema.Schema<O, A, R2>): Guard<I, A, E, R | R2>;
98
+ };
99
+ declare const let_: {
100
+ <O, K extends PropertyKey, B>(key: K, value: (o: O) => B): <I, E = never, R = never>(guard: Guard<I, O, E, R>) => Guard<I, O & {
101
+ [k in K]: B;
102
+ }, E, R>;
103
+ <I, O, E, R, K extends PropertyKey, B>(guard: Guard<I, O, E, R>, key: K, value: (o: O) => B): Guard<I, O & {
104
+ [k in K]: B;
105
+ }, E, R>;
106
+ };
107
+ export { let_ as let };
108
+ export declare const attachProperty: {
109
+ <K extends PropertyKey, B>(key: K, value: B): <I, O, E, R>(guard: Guard<I, O, E, R>) => Guard<I, O & {
110
+ readonly [k in K]: B;
111
+ }, E, R>;
112
+ <I, O, E, R, K extends PropertyKey, B>(guard: Guard<I, O, E, R>, key: K, value: B): Guard<I, O & {
113
+ readonly [k in K]: B;
114
+ }, E, R>;
115
+ };
116
+ export declare const addTag: {
117
+ <B>(value: B): <I, O, E = never, R = never>(guard: Guard<I, O, E, R>) => Guard<I, O & {
118
+ readonly _tag: B;
119
+ }, E, R>;
120
+ <I, O, E, R, B>(guard: Guard<I, O, E, R>, value: B): Guard<I, O & {
121
+ readonly _tag: B;
122
+ }, E, R>;
123
+ };
124
+ export declare const bindTo: {
125
+ <K extends PropertyKey>(key: K): <I, O, E, R>(guard: Guard<I, O, E, R>) => Guard<I, {
126
+ [k in K]: O;
127
+ }, E, R>;
128
+ <I, O, E, R, K extends PropertyKey>(guard: Guard<I, O, E, R>, key: K): Guard<I, {
129
+ [k in K]: O;
130
+ }, E, R>;
131
+ };
132
+ export declare const bind: {
133
+ <I, O, E, R, K extends PropertyKey, B, E2, R2>(key: K, f: Guard<O, B, E2, R2>): (guard: Guard<I, O, E, R>) => Guard<I, O & {
134
+ [k in K]: B;
135
+ }, E | E2, R | R2>;
136
+ <I, O, E, R, K extends PropertyKey, B, E2, R2>(guard: Guard<I, O, E, R>, key: K, f: Guard<O, B, E2, R2>): Guard<I, O & {
137
+ [k in K]: B;
138
+ }, E | E2, R | R2>;
139
+ };
140
+ declare global {
141
+ interface Function extends Pipeable.Pipeable {
142
+ }
143
+ }
@@ -1,64 +1,30 @@
1
- /**
2
- * @since 1.0.0
3
- */
4
- import * as Schema from "@effect/schema/Schema";
5
- import * as Effect from "effect/Effect";
6
- import { dual } from "effect/Function";
7
- import * as Option from "effect/Option";
8
- /**
9
- * @since 1.0.0
10
- */
11
- export const getGuard = (guard) => "asGuard" in guard ? guard.asGuard() : guard;
12
- /**
13
- * @since 1.0.0
14
- */
1
+ import { Effect, Option, Pipeable, Schema, } from 'effect';
2
+ import { dual } from 'effect/Function';
3
+ export const identity = Effect.succeedSome;
15
4
  export const compose = dual(2, function flatMap(input, output) {
16
- const g1 = getGuard(input);
17
- const g2 = getGuard(output);
18
- return (i) => Effect.flatMap(g1(i), Option.match({
5
+ return (i) => Effect.flatMap(input(i), Option.match({
19
6
  onNone: () => Effect.succeedNone,
20
- onSome: g2
7
+ onSome: output,
21
8
  }));
22
9
  });
23
- /**
24
- * @since 1.0.0
25
- */
26
10
  export const mapEffect = dual(2, function mapEffect(guard, f) {
27
11
  return compose(guard, (o) => Effect.asSome(f(o)));
28
12
  });
29
- /**
30
- * @since 1.0.0
31
- */
32
13
  export const map = dual(2, function map(guard, f) {
33
14
  return mapEffect(guard, (o) => Effect.sync(() => f(o)));
34
15
  });
35
- /**
36
- * @since 1.0.0
37
- */
38
16
  export const tap = dual(2, function tap(guard, f) {
39
17
  return compose(guard, (o) => Effect.as(f(o), Option.some(o)));
40
18
  });
41
- /**
42
- * @since 1.0.0
43
- */
44
19
  export const filterMap = dual(2, (guard, f) => {
45
- const g = getGuard(guard);
46
- return (i) => Effect.map(g(i), Option.filterMap(f));
20
+ return (i) => Effect.map(guard(i), Option.filterMap(f));
47
21
  });
48
- /**
49
- * @since 1.0.0
50
- */
51
22
  export const filter = dual(2, (guard, predicate) => {
52
- const g = getGuard(guard);
53
- return (i) => Effect.map(g(i), Option.filter(predicate));
23
+ return (i) => Effect.map(guard(i), Option.filter(predicate));
54
24
  });
55
- /**
56
- * @since 1.0.0
57
- */
58
25
  export function any(guards) {
59
- const entries = Object.entries(guards).map(([k, v]) => [k, getGuard(v)]);
60
26
  return (i) => Effect.gen(function* () {
61
- for (const [_tag, guard] of entries) {
27
+ for (const [_tag, guard] of Object.entries(guards)) {
62
28
  const match = yield* guard(i);
63
29
  if (Option.isSome(match)) {
64
30
  return Option.some({ _tag, value: match.value });
@@ -70,101 +36,60 @@ export function any(guards) {
70
36
  export function liftPredicate(predicate) {
71
37
  return (a) => Effect.sync(() => (predicate(a) ? Option.some(a) : Option.none()));
72
38
  }
73
- /**
74
- * @since 1.0.0
75
- */
76
39
  export const catchAllCause = dual(2, function catchAllCause(guard, f) {
77
- const g = getGuard(guard);
78
- return (i) => Effect.catchAllCause(g(i), (a) => Effect.asSome(f(a)));
40
+ return (i) => Effect.catchAllCause(guard(i), (a) => Effect.asSome(f(a)));
79
41
  });
80
- /**
81
- * @since 1.0.0
82
- */
83
42
  export const catchAll = dual(2, function catchAll(guard, f) {
84
- const g = getGuard(guard);
85
- return (i) => Effect.catchAll(g(i), (a) => Effect.asSome(f(a)));
43
+ return (i) => Effect.catchAll(guard(i), (a) => Effect.asSome(f(a)));
86
44
  });
87
- /**
88
- * @since 1.0.0
89
- */
90
45
  export const catchTag = dual(3, function catchTag(guard, tag, f) {
91
- const g = getGuard(guard);
92
- return (i) => Effect.catchTag(g(i), tag, (e) => Effect.asSome(f(e)));
46
+ return (i) => Effect.catchTag(guard(i), tag, (e) => Effect.asSome(f(e)));
93
47
  });
94
- /**
95
- * @since 1.0.0
96
- */
97
48
  export const provide = dual(2, function provide(guard, provided) {
98
- const g = getGuard(guard);
99
- return (i) => Effect.provide(g(i), provided);
49
+ return (i) => Effect.provide(guard(i), provided);
100
50
  });
101
- /**
102
- * @since 1.0.0
103
- */
104
51
  export const provideService = dual(3, function provideService(guard, tag, service) {
105
- const g = getGuard(guard);
106
- return (i) => Effect.provideService(g(i), tag, service);
52
+ return (i) => Effect.provideService(guard(i), tag, service);
107
53
  });
108
- /**
109
- * @since 1.0.0
110
- */
111
54
  export const provideServiceEffect = dual(3, function provideServiceEffect(guard, tag, service) {
112
- const g = getGuard(guard);
113
- return (i) => Effect.provideServiceEffect(g(i), tag, service);
55
+ return (i) => Effect.provideServiceEffect(guard(i), tag, service);
114
56
  });
115
- const parseOptions = { errors: "all", onExcessProperty: "ignore" };
116
- /**
117
- * @since 1.0.0
118
- */
57
+ const parseOptions = { errors: 'all', onExcessProperty: 'ignore' };
119
58
  export function fromSchemaDecode(schema) {
120
59
  const decode_ = Schema.decode(schema);
121
- return (i) => Effect.asSome(decode_(i, parseOptions));
60
+ return (i) => decode_(i, parseOptions).pipe(Effect.asSome, Effect.catchTag('ParseError', (e) => Effect.succeedNone));
61
+ }
62
+ export function fromSchemaDecodeUnknown(schema) {
63
+ const decode_ = Schema.decodeUnknown(schema);
64
+ return (i) => decode_(i, parseOptions).pipe(Effect.asSome, Effect.catchTag('ParseError', () => Effect.succeedNone));
122
65
  }
123
- /**
124
- * @since 1.0.0
125
- */
126
66
  export function fromSchemaEncode(schema) {
127
67
  const encode_ = Schema.encode(schema);
128
- return (a) => Effect.asSome(encode_(a, parseOptions));
68
+ return (a) => encode_(a, parseOptions).pipe(Effect.asSome, Effect.catchTag('ParseError', () => Effect.succeedNone));
129
69
  }
130
- /**
131
- * @since 1.0.0
132
- */
133
70
  export const decode = dual(2, function decode(guard, schema) {
134
71
  return compose(guard, fromSchemaDecode(schema));
135
72
  });
136
- /**
137
- * @since 1.0.0
138
- */
139
73
  export const encode = dual(2, function encode(guard, schema) {
140
74
  return compose(guard, fromSchemaEncode(schema));
141
75
  });
142
- /**
143
- * @since 1.0.0
144
- */
145
- const let_ = dual(3, function attachProperty(guard, key, value) {
76
+ const let_ = dual(3, function let_(guard, key, value) {
77
+ return map(guard, (a) => ({ ...a, [key]: value(a) }));
78
+ });
79
+ export { let_ as let };
80
+ export const attachProperty = dual(3, function attachProperty(guard, key, value) {
146
81
  return map(guard, (a) => ({ ...a, [key]: value }));
147
82
  });
148
- export {
149
- /**
150
- * @since 1.0.0
151
- */
152
- let_ as let };
153
- /**
154
- * @since 1.0.0
155
- */
156
- export const addTag = dual(2, function attachProperty(guard, value) {
83
+ export const addTag = dual(2, function addTag(guard, value) {
157
84
  return map(guard, (a) => ({ ...a, _tag: value }));
158
85
  });
159
- /**
160
- * @since 1.0.0
161
- */
162
86
  export const bindTo = dual(2, (guard, key) => map(guard, (a) => ({ [key]: a })));
163
- /**
164
- * @since 1.0.0
165
- */
166
87
  export const bind = dual(3, function bind(guard, key, f) {
167
88
  const f_ = bindTo(f, key);
168
89
  return compose(guard, (o) => Effect.map(f_(o), Option.map((b) => ({ ...o, ...b }))));
169
90
  });
170
- //# sourceMappingURL=index.js.map
91
+ Function.prototype.pipe = function pipe() {
92
+ // biome-ignore lint/style/noArguments: This is a pipeable function
93
+ return Pipeable.pipeArguments(this, arguments);
94
+ };
95
+ //# sourceMappingURL=Guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Guard.js","sourceRoot":"","sources":["../src/Guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,MAAM,EAEN,MAAM,EACN,QAAQ,EAGR,MAAM,GACP,MAAM,QAAQ,CAAA;AACf,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAiBtC,MAAM,CAAC,MAAM,QAAQ,GAAiD,MAAM,CAAC,WAAW,CAAA;AAExF,MAAM,CAAC,MAAM,OAAO,GAQhB,IAAI,CAAC,CAAC,EAAE,SAAS,OAAO,CAQ1B,KAAwB,EAAE,MAA2B;IACrD,OAAO,CAAC,CAAC,EAAE,EA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A"}
@@ -0,0 +1,10 @@
1
+ import { Pipeable } from 'effect';
2
+ import { ExtensibleFunction } from './ExtensibleFunction';
3
+ import type { Guard } from './Guard.js';
4
+ export declare const GUARDABLE: unique symbol;
5
+ export type GUARDABLE = typeof GUARDABLE;
6
+ export declare abstract class Guardable<I, O, E = never, R = never> extends ExtensibleFunction<Guard<I, O, E, R>> implements Pipeable.Pipeable {
7
+ constructor();
8
+ abstract readonly [GUARDABLE]: Guard<I, O, E, R>;
9
+ pipe(): unknown;
10
+ }
@@ -0,0 +1,13 @@
1
+ import { Pipeable } from 'effect';
2
+ import { ExtensibleFunction } from './ExtensibleFunction';
3
+ export const GUARDABLE = Symbol.for('@typed/guard/Guardable');
4
+ export class Guardable extends ExtensibleFunction {
5
+ constructor() {
6
+ super((input) => this[GUARDABLE](input));
7
+ }
8
+ pipe() {
9
+ // biome-ignore lint/style/noArguments: This is a pipeable function
10
+ return Pipeable.pipeArguments(this, arguments);
11
+ }
12
+ }
13
+ //# sourceMappingURL=Guardable.js.map
@@ -0,0 +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,sBAAsB,CAAA;AAGzD,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAA;AAG7D,MAAM,OAAgB,SAAsC,SAAQ,kBAEnE;IACC;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"}
@@ -0,0 +1,3 @@
1
+ export * from './ExtensibleFunction.js';
2
+ export * from './Guard.js';
3
+ export * from './Guardable.js';
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from './ExtensibleFunction.js';
2
+ export * from './Guard.js';
3
+ export * from './Guardable.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA;AACvC,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA"}
package/package.json CHANGED
@@ -1,27 +1,35 @@
1
1
  {
2
2
  "name": "@typed/guard",
3
- "version": "0.5.0",
4
- "description": "",
3
+ "version": "0.7.0",
4
+ "description": "Guards with Effect",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "module",
8
+ "keywords": [
9
+ "guard",
10
+ "effect",
11
+ "typescript"
12
+ ],
13
+ "author": "Tylor Steinberger <tlsteinberger167@gmail.com>",
5
14
  "license": "MIT",
6
- "repository": {
7
- "type": "git",
8
- "url": "https://github.com/tylors/typed.git"
9
- },
10
- "sideEffects": [],
11
- "author": "Typed contributors",
12
15
  "dependencies": {
13
- "@effect/schema": "^0.68.1",
14
- "effect": "^3.3.5"
16
+ "effect": "^3.11.9"
17
+ },
18
+ "peerDependencies": {
19
+ "effect": "^3.11.9"
20
+ },
21
+ "devDependencies": {
22
+ "@biomejs/biome": "^1.9.4",
23
+ "@effect/vitest": "^0.16.0",
24
+ "typescript": "^5.4.2",
25
+ "vitest": "^2.1.8"
15
26
  },
16
- "main": "./dist/cjs/index.js",
17
- "module": "./dist/esm/index.js",
18
- "types": "./dist/dts/index.d.ts",
19
- "exports": {
20
- "./package.json": "./package.json",
21
- ".": {
22
- "types": "./dist/dts/index.d.ts",
23
- "import": "./dist/esm/index.js",
24
- "default": "./dist/cjs/index.js"
25
- }
27
+ "scripts": {
28
+ "build": "tsc",
29
+ "dev": "tsc --watch",
30
+ "lint": "biome lint --write",
31
+ "test:watch": "vitest --typecheck",
32
+ "test": "vitest run --typecheck",
33
+ "typecheck": "tsc --noEmit"
26
34
  }
27
35
  }