@kaumlaut/pure 0.1.7 → 0.1.9
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/guard/index.d.ts +2 -2
- package/dist/guard/index.d.ts.map +1 -0
- package/dist/guard/index.js +1 -1
- package/dist/maybe/index.d.ts +17 -2
- package/dist/maybe/index.d.ts.map +1 -0
- package/dist/maybe/index.js +39 -1
- package/dist/parse/index.d.ts +4 -1
- package/dist/parse/index.d.ts.map +1 -0
- package/dist/parse/index.js +15 -1
- package/dist/result/index.d.ts +17 -2
- package/dist/result/index.d.ts.map +1 -0
- package/dist/result/index.js +36 -1
- package/dist/{effect/Fetch.d.ts → runtime/effect/fetch/index.d.ts} +4 -3
- package/dist/runtime/effect/fetch/index.d.ts.map +1 -0
- package/dist/{effect/Fetch.js → runtime/effect/fetch/index.js} +3 -3
- package/dist/{effect/Effect.d.ts → runtime/effect/index.d.ts} +4 -3
- package/dist/runtime/effect/index.d.ts.map +1 -0
- package/dist/{effect/Effect.js → runtime/effect/index.js} +1 -1
- package/dist/runtime/effect/none/index.d.ts +3 -0
- package/dist/runtime/effect/none/index.d.ts.map +1 -0
- package/dist/runtime/effect/none/index.js +7 -0
- package/dist/runtime/index.d.ts +18 -3
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +3 -2
- package/dist/runtime/persistence/index.d.ts +8 -3
- package/dist/runtime/persistence/index.d.ts.map +1 -0
- package/dist/runtime/persistence/index.js +1 -2
- package/dist/runtime/persistence/{LocalStorage.d.ts → localStorage/index.d.ts} +3 -2
- package/dist/runtime/persistence/localStorage/index.d.ts.map +1 -0
- package/dist/runtime/persistence/{LocalStorage.js → localStorage/index.js} +1 -1
- package/dist/runtime/persistence/{None.d.ts → none/index.d.ts} +3 -2
- package/dist/runtime/persistence/none/index.d.ts.map +1 -0
- package/dist/runtime/persistence/{None.js → none/index.js} +1 -1
- package/package.json +10 -30
- package/dist/effect/None.d.ts +0 -2
- package/dist/effect/None.js +0 -7
- package/dist/effect/index.d.ts +0 -4
- package/dist/effect/index.js +0 -3
- package/dist/guard/Guard.d.ts +0 -1
- package/dist/guard/Guard.js +0 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -6
- package/dist/maybe/Maybe.d.ts +0 -16
- package/dist/maybe/Maybe.js +0 -39
- package/dist/parse/Parse.d.ts +0 -3
- package/dist/parse/Parse.js +0 -15
- package/dist/result/Result.d.ts +0 -16
- package/dist/result/Result.js +0 -36
- package/dist/runtime/Runtime.d.ts +0 -18
- package/dist/runtime/Runtime.js +0 -9
- package/dist/runtime/persistence/Persistence.d.ts +0 -7
- package/dist/runtime/persistence/Persistence.js +0 -1
package/dist/guard/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export type Guard<T> = (value: unknown) => value is T;
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/guard/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,CAAA"}
|
package/dist/guard/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export {};
|
package/dist/maybe/index.d.ts
CHANGED
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export type Just<T> = {
|
|
2
|
+
type: 'maybe-just';
|
|
3
|
+
value: T;
|
|
4
|
+
};
|
|
5
|
+
export type Nothing = {
|
|
6
|
+
type: 'maybe-nothing';
|
|
7
|
+
};
|
|
8
|
+
export type Maybe<T> = Just<T> | Nothing;
|
|
9
|
+
export declare function nothing(): Nothing;
|
|
10
|
+
export declare function just<T>(value: T): Just<T>;
|
|
11
|
+
export declare function isNothing<T>(maybe: Maybe<T>): maybe is Nothing;
|
|
12
|
+
export declare function isJust<T>(maybe: Maybe<T>): maybe is Just<T>;
|
|
13
|
+
export declare function isMaybe<T>(value: unknown): value is Maybe<T>;
|
|
14
|
+
export declare function map<T, R>(maybe: Maybe<T>, func: (value: T) => R): Maybe<R>;
|
|
15
|
+
export declare function filter<T>(maybe: Maybe<T>, func: (value: T) => boolean): Maybe<T>;
|
|
16
|
+
export declare function withDefault<T>(maybe: Maybe<T>, defaultValue: T): T;
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/maybe/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI;IACpB,IAAI,EAAE,YAAY,CAAA;IAClB,KAAK,EAAE,CAAC,CAAA;CACT,CAAA;AAED,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,eAAe,CAAA;CACtB,CAAA;AAED,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,OAAO,CAAA;AAExC,wBAAgB,OAAO,IAAI,OAAO,CAIjC;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAKzC;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,OAAO,CAE9D;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,CAE3D;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,CAG5D;AAED,wBAAgB,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAM1E;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAMhF;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,CAMlE"}
|
package/dist/maybe/index.js
CHANGED
|
@@ -1 +1,39 @@
|
|
|
1
|
-
export
|
|
1
|
+
export function nothing() {
|
|
2
|
+
return {
|
|
3
|
+
type: 'maybe-nothing',
|
|
4
|
+
};
|
|
5
|
+
}
|
|
6
|
+
export function just(value) {
|
|
7
|
+
return {
|
|
8
|
+
type: 'maybe-just',
|
|
9
|
+
value,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export function isNothing(maybe) {
|
|
13
|
+
return maybe.type === 'maybe-nothing';
|
|
14
|
+
}
|
|
15
|
+
export function isJust(maybe) {
|
|
16
|
+
return maybe.type === 'maybe-just';
|
|
17
|
+
}
|
|
18
|
+
export function isMaybe(value) {
|
|
19
|
+
//@ts-expect-error is validated
|
|
20
|
+
return value.type === 'maybe-just' || value.type === 'maybe-nothing';
|
|
21
|
+
}
|
|
22
|
+
export function map(maybe, func) {
|
|
23
|
+
if (isJust(maybe)) {
|
|
24
|
+
return just(func(maybe.value));
|
|
25
|
+
}
|
|
26
|
+
return maybe;
|
|
27
|
+
}
|
|
28
|
+
export function filter(maybe, func) {
|
|
29
|
+
if (isJust(maybe) && func(maybe.value)) {
|
|
30
|
+
return maybe;
|
|
31
|
+
}
|
|
32
|
+
return nothing();
|
|
33
|
+
}
|
|
34
|
+
export function withDefault(maybe, defaultValue) {
|
|
35
|
+
if (isJust(maybe)) {
|
|
36
|
+
return maybe.value;
|
|
37
|
+
}
|
|
38
|
+
return defaultValue;
|
|
39
|
+
}
|
package/dist/parse/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/parse/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,WAAW,CAAA;AAEhD,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQ3D;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQ7D"}
|
package/dist/parse/index.js
CHANGED
|
@@ -1 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import { err, ok } from '../result';
|
|
2
|
+
export function asInt(value) {
|
|
3
|
+
const parsed = parseInt(value, 10);
|
|
4
|
+
if (Number.isNaN(parsed)) {
|
|
5
|
+
return err('Number is NaN');
|
|
6
|
+
}
|
|
7
|
+
return ok(parsed);
|
|
8
|
+
}
|
|
9
|
+
export function asFloat(value) {
|
|
10
|
+
const parsed = parseFloat(value);
|
|
11
|
+
if (Number.isNaN(parsed)) {
|
|
12
|
+
return err('Number is NaN');
|
|
13
|
+
}
|
|
14
|
+
return ok(parsed);
|
|
15
|
+
}
|
package/dist/result/index.d.ts
CHANGED
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export type Ok<T> = {
|
|
2
|
+
type: 'ok-result';
|
|
3
|
+
value: T;
|
|
4
|
+
};
|
|
5
|
+
export type Err<T> = {
|
|
6
|
+
type: 'error-result';
|
|
7
|
+
error: T;
|
|
8
|
+
};
|
|
9
|
+
export declare function isOk<T, E>(result: Result<T, E>): result is Ok<T>;
|
|
10
|
+
export declare function isErr<T, E>(result: Result<T, E>): result is Err<E>;
|
|
11
|
+
export declare function ok<T>(value: T): Ok<T>;
|
|
12
|
+
export declare function err<E>(error: E): Err<E>;
|
|
13
|
+
export type Result<T, E> = Ok<T> | Err<E>;
|
|
14
|
+
export declare function map<T, E, R>(result: Result<T, E>, func: (value: T) => R): Result<R, E>;
|
|
15
|
+
export declare function mapErr<T, E, R>(result: Result<T, E>, func: (value: E) => R): Result<T, R>;
|
|
16
|
+
export declare function withDefault<T, E>(result: Result<T, E>, defaultValue: T): T;
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/result/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,EAAE,CAAC,CAAC,IAAI;IAClB,IAAI,EAAE,WAAW,CAAA;IACjB,KAAK,EAAE,CAAC,CAAA;CACT,CAAA;AAED,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI;IACnB,IAAI,EAAE,cAAc,CAAA;IACpB,KAAK,EAAE,CAAC,CAAA;CACT,CAAA;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC,CAEhE;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,CAElE;AAED,wBAAgB,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAKrC;AAED,wBAAgB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAKvC;AAED,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;AAEzC,wBAAgB,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAMtF;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAMzF;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,CAM1E"}
|
package/dist/result/index.js
CHANGED
|
@@ -1 +1,36 @@
|
|
|
1
|
-
export
|
|
1
|
+
export function isOk(result) {
|
|
2
|
+
return result.type === 'ok-result';
|
|
3
|
+
}
|
|
4
|
+
export function isErr(result) {
|
|
5
|
+
return result.type === 'error-result';
|
|
6
|
+
}
|
|
7
|
+
export function ok(value) {
|
|
8
|
+
return {
|
|
9
|
+
type: 'ok-result',
|
|
10
|
+
value,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function err(error) {
|
|
14
|
+
return {
|
|
15
|
+
type: 'error-result',
|
|
16
|
+
error,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function map(result, func) {
|
|
20
|
+
if (isOk(result)) {
|
|
21
|
+
return ok(func(result.value));
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
export function mapErr(result, func) {
|
|
26
|
+
if (isErr(result)) {
|
|
27
|
+
return err(func(result.error));
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
export function withDefault(result, defaultValue) {
|
|
32
|
+
if (isErr(result)) {
|
|
33
|
+
return defaultValue;
|
|
34
|
+
}
|
|
35
|
+
return result.value;
|
|
36
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import { Message } from '../../index';
|
|
2
|
+
import { Guard } from '../../../guard';
|
|
3
|
+
import { Effect, ReceiveEffectResult } from '../index';
|
|
4
4
|
type HttpError = {
|
|
5
5
|
code: number;
|
|
6
6
|
message: string;
|
|
@@ -15,3 +15,4 @@ export declare function isClient(error: FetchError): boolean;
|
|
|
15
15
|
export declare function isServer(error: FetchError): boolean;
|
|
16
16
|
export declare function fetchJson<T, M extends Message>(url: string, headers: [string, string][], method: string, guard: Guard<T>, receiver: ReceiveEffectResult<T, FetchError, M>): Effect<M>;
|
|
17
17
|
export {};
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/runtime/effect/fetch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAEtC,OAAO,EAAE,MAAM,EAAE,mBAAmB,EAAY,MAAM,UAAU,CAAA;AAEhE,KAAK,SAAS,GAAG;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,KAAK,qBAAqB,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,KAAK,UAAU,GAAG,SAAS,GAAG,qBAAqB,CAAA;AAEnD,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAErD;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,KAAK,IAAI,SAAS,CAE5D;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAEnD;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAEnD;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAC5C,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAC3B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EACf,QAAQ,EAAE,mBAAmB,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,GAC9C,MAAM,CAAC,CAAC,CAAC,CA0CX"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { err, ok } from '
|
|
2
|
-
import {
|
|
1
|
+
import { err, ok } from '../../../result';
|
|
2
|
+
import { withName } from '../index';
|
|
3
3
|
export function isNotFound(error) {
|
|
4
4
|
return isHttp(error) && error.code === 404;
|
|
5
5
|
}
|
|
@@ -13,7 +13,7 @@ export function isServer(error) {
|
|
|
13
13
|
return isHttp(error) && error.code > 499;
|
|
14
14
|
}
|
|
15
15
|
export function fetchJson(url, headers, method, guard, receiver) {
|
|
16
|
-
return
|
|
16
|
+
return withName('fetchJson', async () => {
|
|
17
17
|
try {
|
|
18
18
|
const result = await fetch(url, {
|
|
19
19
|
method,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { Message } from '../index';
|
|
2
|
+
import { Result } from '../../result';
|
|
3
3
|
export type AsyncEffect<T extends Message> = () => Promise<T>;
|
|
4
4
|
export type SyncEffect<T extends Message> = () => T;
|
|
5
5
|
export type NullEffect = () => null;
|
|
@@ -10,5 +10,6 @@ export type Effect<T extends Message> = {
|
|
|
10
10
|
name: string;
|
|
11
11
|
meta: object | null;
|
|
12
12
|
};
|
|
13
|
-
export declare function
|
|
13
|
+
export declare function withName<T extends Message>(name: string, effect: EffectType<T>, meta?: object | null): Effect<T>;
|
|
14
14
|
export type ReceiveEffectResult<T, E, R> = (result: Result<T, E>) => R;
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtime/effect/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,OAAO,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,CAAA;AAC7D,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,OAAO,IAAI,MAAM,CAAC,CAAA;AACnD,MAAM,MAAM,UAAU,GAAG,MAAM,IAAI,CAAA;AACnC,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;AACjD,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,OAAO,IACpC,WAAW,CAAC,CAAC,CAAC,GACd,UAAU,CAAC,CAAC,CAAC,GACb,UAAU,GACV,eAAe,CAAA;AACnB,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,OAAO,IAAI;IACtC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,CAAA;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CACpB,CAAA;AAED,wBAAgB,QAAQ,CAAC,CAAC,SAAS,OAAO,EACxC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EACrB,IAAI,GAAE,MAAM,GAAG,IAAW,GACzB,MAAM,CAAC,CAAC,CAAC,CAMX;AAED,MAAM,MAAM,mBAAmB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/runtime/effect/none/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAY,MAAM,UAAU,CAAA;AAE3C,wBAAgB,KAAK,IAAI,MAAM,CAAC,GAAG,CAAC,CAInC"}
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
1
|
+
import { Effect } from './effect';
|
|
2
|
+
export type Message<N extends string = string, T = any> = {
|
|
3
|
+
value: T;
|
|
4
|
+
name: N;
|
|
5
|
+
};
|
|
6
|
+
export type Update<Model, CustomMessage extends Message> = (model: Model, msg: CustomMessage) => [Model, Effect<CustomMessage>];
|
|
7
|
+
export type Init<Model, CustomMessage extends Message> = () => [Model, Effect<CustomMessage>];
|
|
8
|
+
export type Change<CustomMessage extends Message, Model> = [
|
|
9
|
+
CustomMessage | null,
|
|
10
|
+
model: Model,
|
|
11
|
+
effect: {
|
|
12
|
+
name: string;
|
|
13
|
+
meta: object | null;
|
|
14
|
+
} | null
|
|
15
|
+
];
|
|
16
|
+
export type Changes<CustomMessage extends Message, Model> = Change<CustomMessage, Model>[];
|
|
17
|
+
export declare function is<CustomMessage extends Message<A>, A extends string>(name: A, message: Message): message is CustomMessage;
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,GAAG,IAAI;IACxD,KAAK,EAAE,CAAC,CAAA;IACR,IAAI,EAAE,CAAC,CAAA;CACR,CAAA;AAED,MAAM,MAAM,MAAM,CAAC,KAAK,EAAE,aAAa,SAAS,OAAO,IAAI,CACzD,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,aAAa,KACf,CAAC,KAAK,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC,CAAA;AAEnC,MAAM,MAAM,IAAI,CAAC,KAAK,EAAE,aAAa,SAAS,OAAO,IAAI,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC,CAAA;AAE7F,MAAM,MAAM,MAAM,CAAC,aAAa,SAAS,OAAO,EAAE,KAAK,IAAI;IACzD,aAAa,GAAG,IAAI;IACpB,KAAK,EAAE,KAAK;IACZ,MAAM,EAAE;QACN,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;KACpB,GAAG,IAAI;CACT,CAAA;AAED,MAAM,MAAM,OAAO,CAAC,aAAa,SAAS,OAAO,EAAE,KAAK,IAAI,MAAM,CAAC,aAAa,EAAE,KAAK,CAAC,EAAE,CAAA;AAE1F,wBAAgB,EAAE,CAAC,aAAa,SAAS,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EACnE,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,OAAO,GACf,OAAO,IAAI,aAAa,CAE1B"}
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export function is(name, message) {
|
|
2
|
+
return message.name === name;
|
|
3
|
+
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Init, Message } from '../index';
|
|
2
|
+
import { Guard } from '../../guard';
|
|
3
|
+
import { Result } from '../../result';
|
|
4
|
+
export type Persistence<Model, CustomMessage extends Message> = {
|
|
5
|
+
persist(model: Model): void;
|
|
6
|
+
read(guard: Guard<Model>, init: Init<Model, CustomMessage>): Result<Model, string>;
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtime/persistence/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,MAAM,MAAM,WAAW,CAAC,KAAK,EAAE,aAAa,SAAS,OAAO,IAAI;IAC9D,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;IAC3B,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,aAAa,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;CACnF,CAAA"}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from "./None";
|
|
1
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { Persistence } from '../index';
|
|
2
|
+
import { Message } from '../../index';
|
|
3
3
|
export declare const localStoragePersistence: <Model, CustomMessage extends Message>(name: string) => Persistence<Model, CustomMessage>;
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/runtime/persistence/localStorage/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,EAAQ,OAAO,EAAE,MAAM,aAAa,CAAA;AAI3C,eAAO,MAAM,uBAAuB,GAAI,KAAK,EAAE,aAAa,SAAS,OAAO,EAC1E,MAAM,MAAM,KACX,WAAW,CAAC,KAAK,EAAE,aAAa,CAwBjC,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { Message } from '../../index';
|
|
2
|
+
import { Persistence } from '../index';
|
|
3
3
|
export declare const noPersistence: <Model, CustomMessage extends Message>() => Persistence<Model, CustomMessage>;
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/runtime/persistence/none/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,OAAO,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAItC,eAAO,MAAM,aAAa,GAAI,KAAK,EAAE,aAAa,SAAS,OAAO,OAAK,WAAW,CAChF,KAAK,EACL,aAAa,CAOb,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaumlaut/pure",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Types and functions for state management inspired by Elm and functional programming",
|
|
3
|
+
"version": "0.1.9",
|
|
5
4
|
"main": "dist/index.js",
|
|
6
5
|
"types": "dist/index.d.ts",
|
|
7
6
|
"module": "dist/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
"./*": {
|
|
9
|
+
"import": "./dist/*/index.js",
|
|
10
|
+
"types": "./dist/*/index.d.ts"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
8
13
|
"scripts": {
|
|
9
14
|
"build": "tsc",
|
|
10
15
|
"test": "vitest",
|
|
@@ -13,37 +18,12 @@
|
|
|
13
18
|
"files": [
|
|
14
19
|
"dist"
|
|
15
20
|
],
|
|
16
|
-
"exports": {
|
|
17
|
-
"./effect": {
|
|
18
|
-
"import": "./dist/effect/index.js",
|
|
19
|
-
"types": "./dist/effect/index.d.ts"
|
|
20
|
-
},
|
|
21
|
-
"./result": {
|
|
22
|
-
"import": "./dist/result/index.js",
|
|
23
|
-
"types": "./dist/result/index.d.ts"
|
|
24
|
-
},
|
|
25
|
-
"./runtime": {
|
|
26
|
-
"import": "./dist/runtime/index.js",
|
|
27
|
-
"types": "./dist/runtime/index.d.ts"
|
|
28
|
-
},
|
|
29
|
-
"./maybe": {
|
|
30
|
-
"import": "./dist/maybe/index.js",
|
|
31
|
-
"types": "./dist/maybe/index.d.ts"
|
|
32
|
-
},
|
|
33
|
-
"./guard": {
|
|
34
|
-
"import": "./dist/guard/index.js",
|
|
35
|
-
"types": "./dist/guard/index.d.ts"
|
|
36
|
-
},
|
|
37
|
-
"./parse": {
|
|
38
|
-
"import": "./dist/parse/index.js",
|
|
39
|
-
"types": "./dist/parse/index.d.ts"
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
21
|
"type": "module",
|
|
43
|
-
"author": "Max Kaemmerer",
|
|
44
|
-
"license": "MIT",
|
|
45
22
|
"devDependencies": {
|
|
46
23
|
"typescript": "^5.8.2",
|
|
47
24
|
"vitest": "^3.0.8"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"lodash": "^4.17.21"
|
|
48
28
|
}
|
|
49
29
|
}
|
package/dist/effect/None.d.ts
DELETED
package/dist/effect/None.js
DELETED
package/dist/effect/index.d.ts
DELETED
package/dist/effect/index.js
DELETED
package/dist/guard/Guard.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type Guard<T> = (value: unknown) => value is T;
|
package/dist/guard/Guard.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
package/dist/maybe/Maybe.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export type Just<T> = {
|
|
2
|
-
type: 'maybe-just';
|
|
3
|
-
value: T;
|
|
4
|
-
};
|
|
5
|
-
export type Nothing = {
|
|
6
|
-
type: 'maybe-nothing';
|
|
7
|
-
};
|
|
8
|
-
export type Maybe<T> = Just<T> | Nothing;
|
|
9
|
-
export declare function nothing(): Nothing;
|
|
10
|
-
export declare function just<T>(value: T): Just<T>;
|
|
11
|
-
export declare function isNothing<T>(maybe: Maybe<T>): maybe is Nothing;
|
|
12
|
-
export declare function isJust<T>(maybe: Maybe<T>): maybe is Just<T>;
|
|
13
|
-
export declare function isMaybe<T>(value: unknown): value is Maybe<T>;
|
|
14
|
-
export declare function mapMaybe<T, R>(maybe: Maybe<T>, func: (value: T) => R): Maybe<R>;
|
|
15
|
-
export declare function filterMaybe<T>(maybe: Maybe<T>, func: (value: T) => boolean): Maybe<T>;
|
|
16
|
-
export declare function maybeWithDefault<T>(maybe: Maybe<T>, defaultValue: T): T;
|
package/dist/maybe/Maybe.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export function nothing() {
|
|
2
|
-
return {
|
|
3
|
-
type: 'maybe-nothing',
|
|
4
|
-
};
|
|
5
|
-
}
|
|
6
|
-
export function just(value) {
|
|
7
|
-
return {
|
|
8
|
-
type: 'maybe-just',
|
|
9
|
-
value,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
export function isNothing(maybe) {
|
|
13
|
-
return maybe.type === 'maybe-nothing';
|
|
14
|
-
}
|
|
15
|
-
export function isJust(maybe) {
|
|
16
|
-
return maybe.type === 'maybe-just';
|
|
17
|
-
}
|
|
18
|
-
export function isMaybe(value) {
|
|
19
|
-
//@ts-expect-error is validated
|
|
20
|
-
return value.type === 'maybe-just' || value.type === 'maybe-nothing';
|
|
21
|
-
}
|
|
22
|
-
export function mapMaybe(maybe, func) {
|
|
23
|
-
if (isJust(maybe)) {
|
|
24
|
-
return just(func(maybe.value));
|
|
25
|
-
}
|
|
26
|
-
return maybe;
|
|
27
|
-
}
|
|
28
|
-
export function filterMaybe(maybe, func) {
|
|
29
|
-
if (isJust(maybe) && func(maybe.value)) {
|
|
30
|
-
return maybe;
|
|
31
|
-
}
|
|
32
|
-
return nothing();
|
|
33
|
-
}
|
|
34
|
-
export function maybeWithDefault(maybe, defaultValue) {
|
|
35
|
-
if (isJust(maybe)) {
|
|
36
|
-
return maybe.value;
|
|
37
|
-
}
|
|
38
|
-
return defaultValue;
|
|
39
|
-
}
|
package/dist/parse/Parse.d.ts
DELETED
package/dist/parse/Parse.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { err, ok } from '../result/Result';
|
|
2
|
-
export function asInt(value) {
|
|
3
|
-
const parsed = parseInt(value, 10);
|
|
4
|
-
if (Number.isNaN(parsed)) {
|
|
5
|
-
return err('Number is NaN');
|
|
6
|
-
}
|
|
7
|
-
return ok(parsed);
|
|
8
|
-
}
|
|
9
|
-
export function asFloat(value) {
|
|
10
|
-
const parsed = parseFloat(value);
|
|
11
|
-
if (Number.isNaN(parsed)) {
|
|
12
|
-
return err('Number is NaN');
|
|
13
|
-
}
|
|
14
|
-
return ok(parsed);
|
|
15
|
-
}
|
package/dist/result/Result.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export type Ok<T> = {
|
|
2
|
-
type: 'ok-result';
|
|
3
|
-
value: T;
|
|
4
|
-
};
|
|
5
|
-
export type Err<T> = {
|
|
6
|
-
type: 'error-result';
|
|
7
|
-
error: T;
|
|
8
|
-
};
|
|
9
|
-
export type Result<T, E> = Ok<T> | Err<E>;
|
|
10
|
-
export declare function isOk<T, E>(result: Result<T, E>): result is Ok<T>;
|
|
11
|
-
export declare function isErr<T, E>(result: Result<T, E>): result is Err<E>;
|
|
12
|
-
export declare function ok<T>(value: T): Ok<T>;
|
|
13
|
-
export declare function err<E>(error: E): Err<E>;
|
|
14
|
-
export declare function map<T, E, R>(result: Result<T, E>, func: (value: T) => R): Result<R, E>;
|
|
15
|
-
export declare function mapErr<T, E, R>(result: Result<T, E>, func: (value: E) => R): Result<T, R>;
|
|
16
|
-
export declare function withDefault<T, E>(result: Result<T, E>, defaultValue: T): T;
|
package/dist/result/Result.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export function isOk(result) {
|
|
2
|
-
return result.type === 'ok-result';
|
|
3
|
-
}
|
|
4
|
-
export function isErr(result) {
|
|
5
|
-
return result.type === 'error-result';
|
|
6
|
-
}
|
|
7
|
-
export function ok(value) {
|
|
8
|
-
return {
|
|
9
|
-
type: 'ok-result',
|
|
10
|
-
value,
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
export function err(error) {
|
|
14
|
-
return {
|
|
15
|
-
type: 'error-result',
|
|
16
|
-
error,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
export function map(result, func) {
|
|
20
|
-
if (isOk(result)) {
|
|
21
|
-
return ok(func(result.value));
|
|
22
|
-
}
|
|
23
|
-
return result;
|
|
24
|
-
}
|
|
25
|
-
export function mapErr(result, func) {
|
|
26
|
-
if (isErr(result)) {
|
|
27
|
-
return err(func(result.error));
|
|
28
|
-
}
|
|
29
|
-
return result;
|
|
30
|
-
}
|
|
31
|
-
export function withDefault(result, defaultValue) {
|
|
32
|
-
if (isErr(result)) {
|
|
33
|
-
return defaultValue;
|
|
34
|
-
}
|
|
35
|
-
return result.value;
|
|
36
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Effect } from '../effect/Effect';
|
|
2
|
-
export type Message<N extends string = string, T = any> = {
|
|
3
|
-
value: T;
|
|
4
|
-
name: N;
|
|
5
|
-
};
|
|
6
|
-
export type Update<Model, CustomMessage extends Message> = (model: Model, msg: CustomMessage) => [Model, Effect<CustomMessage>];
|
|
7
|
-
export type Init<Model, CustomMessage extends Message> = () => [Model, Effect<CustomMessage>];
|
|
8
|
-
export type Change<CustomMessage extends Message, Model> = [
|
|
9
|
-
CustomMessage | null,
|
|
10
|
-
model: Model,
|
|
11
|
-
effect: {
|
|
12
|
-
name: string;
|
|
13
|
-
meta: object | null;
|
|
14
|
-
} | null
|
|
15
|
-
];
|
|
16
|
-
export type Changes<CustomMessage extends Message, Model> = Change<CustomMessage, Model>[];
|
|
17
|
-
export declare function is<CustomMessage extends Message<A>, A extends string>(name: A, message: Message): message is CustomMessage;
|
|
18
|
-
export declare function create<MN extends string, T>(name: MN, value: T): Message<MN, T>;
|
package/dist/runtime/Runtime.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Guard } from '../../guard/Guard';
|
|
2
|
-
import type { Result } from '../../result/Result';
|
|
3
|
-
import type { Init, Message } from '../Runtime';
|
|
4
|
-
export type Persistence<Model, CustomMessage extends Message> = {
|
|
5
|
-
persist(model: Model): void;
|
|
6
|
-
read(guard: Guard<Model>, init: Init<Model, CustomMessage>): Result<Model, string>;
|
|
7
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|