@kaumlaut/pure 0.1.8 → 0.1.10

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.
Files changed (48) hide show
  1. package/dist/guard/index.d.ts +1 -0
  2. package/dist/guard/index.d.ts.map +1 -0
  3. package/dist/maybe/index.d.ts +4 -3
  4. package/dist/maybe/index.d.ts.map +1 -0
  5. package/dist/maybe/index.js +3 -3
  6. package/dist/parse/index.d.ts +1 -0
  7. package/dist/parse/index.d.ts.map +1 -0
  8. package/dist/result/index.d.ts +2 -1
  9. package/dist/result/index.d.ts.map +1 -0
  10. package/dist/{effect/Fetch.d.ts → runtime/effect/fetch/index.d.ts} +4 -3
  11. package/dist/runtime/effect/fetch/index.d.ts.map +1 -0
  12. package/dist/{effect/Fetch.js → runtime/effect/fetch/index.js} +3 -3
  13. package/dist/{effect/Effect.d.ts → runtime/effect/index.d.ts} +4 -3
  14. package/dist/runtime/effect/index.d.ts.map +1 -0
  15. package/dist/{effect/Effect.js → runtime/effect/index.js} +1 -1
  16. package/dist/runtime/effect/none/index.d.ts +3 -0
  17. package/dist/runtime/effect/none/index.d.ts.map +1 -0
  18. package/dist/{effect/None.js → runtime/effect/none/index.js} +2 -2
  19. package/dist/runtime/index.d.ts +2 -3
  20. package/dist/runtime/index.d.ts.map +1 -0
  21. package/dist/runtime/index.js +0 -7
  22. package/dist/runtime/persistence/index.d.ts +4 -5
  23. package/dist/runtime/persistence/index.d.ts.map +1 -0
  24. package/dist/runtime/persistence/index.js +1 -2
  25. package/dist/runtime/persistence/{LocalStorage.d.ts → localStorage/index.d.ts} +3 -2
  26. package/dist/runtime/persistence/localStorage/index.d.ts.map +1 -0
  27. package/dist/runtime/persistence/{LocalStorage.js → localStorage/index.js} +1 -1
  28. package/dist/runtime/persistence/{None.d.ts → none/index.d.ts} +3 -2
  29. package/dist/runtime/persistence/none/index.d.ts.map +1 -0
  30. package/dist/runtime/persistence/{None.js → none/index.js} +1 -1
  31. package/package.json +7 -15
  32. package/dist/effect/None.d.ts +0 -2
  33. package/dist/effect/index.d.ts +0 -16
  34. package/dist/effect/index.js +0 -9
  35. package/dist/guard/Guard.d.ts +0 -1
  36. package/dist/guard/Guard.js +0 -1
  37. package/dist/index.d.ts +0 -6
  38. package/dist/index.js +0 -6
  39. package/dist/maybe/Maybe.d.ts +0 -16
  40. package/dist/maybe/Maybe.js +0 -39
  41. package/dist/parse/Parse.d.ts +0 -3
  42. package/dist/parse/Parse.js +0 -15
  43. package/dist/result/Result.d.ts +0 -16
  44. package/dist/result/Result.js +0 -36
  45. package/dist/runtime/Runtime.d.ts +0 -18
  46. package/dist/runtime/Runtime.js +0 -9
  47. package/dist/runtime/persistence/Persistence.d.ts +0 -7
  48. package/dist/runtime/persistence/Persistence.js +0 -1
@@ -1 +1,2 @@
1
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"}
@@ -11,6 +11,7 @@ export declare function just<T>(value: T): Just<T>;
11
11
  export declare function isNothing<T>(maybe: Maybe<T>): maybe is Nothing;
12
12
  export declare function isJust<T>(maybe: Maybe<T>): maybe is Just<T>;
13
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;
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"}
@@ -19,19 +19,19 @@ export function isMaybe(value) {
19
19
  //@ts-expect-error is validated
20
20
  return value.type === 'maybe-just' || value.type === 'maybe-nothing';
21
21
  }
22
- export function mapMaybe(maybe, func) {
22
+ export function map(maybe, func) {
23
23
  if (isJust(maybe)) {
24
24
  return just(func(maybe.value));
25
25
  }
26
26
  return maybe;
27
27
  }
28
- export function filterMaybe(maybe, func) {
28
+ export function filter(maybe, func) {
29
29
  if (isJust(maybe) && func(maybe.value)) {
30
30
  return maybe;
31
31
  }
32
32
  return nothing();
33
33
  }
34
- export function maybeWithDefault(maybe, defaultValue) {
34
+ export function withDefault(maybe, defaultValue) {
35
35
  if (isJust(maybe)) {
36
36
  return maybe.value;
37
37
  }
@@ -1,3 +1,4 @@
1
1
  import { type Result } from '../result';
2
2
  export declare function asInt(value: string): Result<number, string>;
3
3
  export declare function asFloat(value: string): Result<number, string>;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -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"}
@@ -6,11 +6,12 @@ export type Err<T> = {
6
6
  type: 'error-result';
7
7
  error: T;
8
8
  };
9
- export type Result<T, E> = Ok<T> | Err<E>;
10
9
  export declare function isOk<T, E>(result: Result<T, E>): result is Ok<T>;
11
10
  export declare function isErr<T, E>(result: Result<T, E>): result is Err<E>;
12
11
  export declare function ok<T>(value: T): Ok<T>;
13
12
  export declare function err<E>(error: E): Err<E>;
13
+ export type Result<T, E> = Ok<T> | Err<E>;
14
14
  export declare function map<T, E, R>(result: Result<T, E>, func: (value: T) => R): Result<R, E>;
15
15
  export declare function mapErr<T, E, R>(result: Result<T, E>, func: (value: E) => R): Result<T, R>;
16
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"}
@@ -1,6 +1,6 @@
1
- import { ReceiveEffectResult, Effect } from '.';
2
- import type { Guard } from '../guard';
3
- import type { Message } from '../runtime';
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 { effectWithName } from '.';
2
- import { err, ok } from '../result';
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 effectWithName('fetchJson', async () => {
16
+ return withName('fetchJson', async () => {
17
17
  try {
18
18
  const result = await fetch(url, {
19
19
  method,
@@ -1,5 +1,5 @@
1
- import type { Result } from '../result/Result';
2
- import type { Message } from '../runtime/Runtime';
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 effectWithName<T extends Message>(name: string, effect: EffectType<T>, meta?: object | null): Effect<T>;
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"}
@@ -1,4 +1,4 @@
1
- export function effectWithName(name, effect, meta = null) {
1
+ export function withName(name, effect, meta = null) {
2
2
  return {
3
3
  name,
4
4
  effectType: effect,
@@ -0,0 +1,3 @@
1
+ import { Effect } from '../index';
2
+ export declare function none(): Effect<any>;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -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,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,CAIlC"}
@@ -1,7 +1,7 @@
1
- import { effectWithName } from '.';
2
1
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
+ import { withName } from '../index';
3
3
  export function none() {
4
- return effectWithName('none', () => {
4
+ return withName('none', () => {
5
5
  return null;
6
6
  });
7
7
  }
@@ -1,5 +1,4 @@
1
- import type { Effect } from '../effect';
2
- export * from "./persistence";
1
+ import { Effect } from './effect';
3
2
  export type Message<N extends string = string, T = any> = {
4
3
  value: T;
5
4
  name: N;
@@ -16,4 +15,4 @@ export type Change<CustomMessage extends Message, Model> = [
16
15
  ];
17
16
  export type Changes<CustomMessage extends Message, Model> = Change<CustomMessage, Model>[];
18
17
  export declare function is<CustomMessage extends Message<A>, A extends string>(name: A, message: Message): message is CustomMessage;
19
- export declare function create<MN extends string, T>(name: MN, value: T): Message<MN, T>;
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"}
@@ -1,10 +1,3 @@
1
- export * from "./persistence";
2
1
  export function is(name, message) {
3
2
  return message.name === name;
4
3
  }
5
- export function create(name, value) {
6
- return {
7
- name,
8
- value
9
- };
10
- }
@@ -1,9 +1,8 @@
1
- import { Guard } from "../../guard";
2
- import { Result } from "../../result";
3
- import { Message, Init } from "..";
4
- export * from "./LocalStorage";
5
- export * from "./None";
1
+ import { Init, Message } from '../index';
2
+ import { Guard } from '../../guard';
3
+ import { Result } from '../../result';
6
4
  export type Persistence<Model, CustomMessage extends Message> = {
7
5
  persist(model: Model): void;
8
6
  read(guard: Guard<Model>, init: Init<Model, CustomMessage>): Result<Model, string>;
9
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 * from "./LocalStorage";
2
- export * from "./None";
1
+ export {};
@@ -1,3 +1,4 @@
1
- import type { Message } from '..';
2
- import type { Persistence } from '.';
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,4 +1,4 @@
1
- import { err, ok } from '../../result';
1
+ import { err, ok } from '../../../result';
2
2
  export const localStoragePersistence = (name) => ({
3
3
  persist(model) {
4
4
  window.localStorage.setItem(name, btoa(JSON.stringify(model)));
@@ -1,3 +1,4 @@
1
- import type { Message } from '..';
2
- import type { Persistence } from '.';
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"}
@@ -1,4 +1,4 @@
1
- import { ok } from '../../result';
1
+ import { ok } from '../../../result';
2
2
  export const noPersistence = () => ({
3
3
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
4
4
  persist(model) { },
package/package.json CHANGED
@@ -1,33 +1,25 @@
1
1
  {
2
2
  "name": "@kaumlaut/pure",
3
- "version": "0.1.8",
4
- "description": "Types and functions for state management inspired by Elm and functional programming",
3
+ "version": "0.1.10",
5
4
  "main": "dist/index.js",
6
5
  "types": "dist/index.d.ts",
7
6
  "module": "dist/index.js",
8
- "markdown": "standard",
9
- "readme": "docs/README.md",
7
+ "exports": {
8
+ "./*": {
9
+ "import": "./dist/*/index.js",
10
+ "types": "./dist/*/index.d.ts"
11
+ }
12
+ },
10
13
  "scripts": {
11
14
  "build": "tsc",
12
15
  "test": "vitest",
13
- "typedoc": "typedoc",
14
16
  "release": "npm run build && npm publish --access public"
15
17
  },
16
18
  "files": [
17
19
  "dist"
18
20
  ],
19
- "exports": {
20
- "./*": {
21
- "import": "./dist/*/index.js",
22
- "types": "./dist/*/index.d.ts"
23
- }
24
- },
25
21
  "type": "module",
26
- "author": "Max Kaemmerer",
27
- "license": "MIT",
28
22
  "devDependencies": {
29
- "typedoc": "^0.27.9",
30
- "typedoc-plugin-markdown": "^4.4.2",
31
23
  "typescript": "^5.8.2",
32
24
  "vitest": "^3.0.8"
33
25
  }
@@ -1,2 +0,0 @@
1
- import { type Effect } from '.';
2
- export declare function none(): Effect<any>;
@@ -1,16 +0,0 @@
1
- export * from "./Fetch";
2
- export * from "./None";
3
- import type { Result } from '../result';
4
- import type { Message } from '../runtime';
5
- export type AsyncEffect<T extends Message> = () => Promise<T>;
6
- export type SyncEffect<T extends Message> = () => T;
7
- export type NullEffect = () => null;
8
- export type AsyncNullEffect = () => Promise<null>;
9
- export type EffectType<T extends Message> = AsyncEffect<T> | SyncEffect<T> | NullEffect | AsyncNullEffect;
10
- export type Effect<T extends Message> = {
11
- effectType: EffectType<T>;
12
- name: string;
13
- meta: object | null;
14
- };
15
- export declare function effectWithName<T extends Message>(name: string, effect: EffectType<T>, meta?: object | null): Effect<T>;
16
- export type ReceiveEffectResult<T, E, R> = (result: Result<T, E>) => R;
@@ -1,9 +0,0 @@
1
- export * from "./Fetch";
2
- export * from "./None";
3
- export function effectWithName(name, effect, meta = null) {
4
- return {
5
- name,
6
- effectType: effect,
7
- meta,
8
- };
9
- }
@@ -1 +0,0 @@
1
- export type Guard<T> = (value: unknown) => value is T;
@@ -1 +0,0 @@
1
- export {};
package/dist/index.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export * from "./effect";
2
- export * from "./guard";
3
- export * from "./maybe";
4
- export * from "./parse";
5
- export * from "./result";
6
- export * from "./runtime";
package/dist/index.js DELETED
@@ -1,6 +0,0 @@
1
- export * from "./effect";
2
- export * from "./guard";
3
- export * from "./maybe";
4
- export * from "./parse";
5
- export * from "./result";
6
- export * from "./runtime";
@@ -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;
@@ -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
- }
@@ -1,3 +0,0 @@
1
- import { type Result } from '../result/Result';
2
- export declare function asInt(value: string): Result<number, string>;
3
- export declare function asFloat(value: string): Result<number, string>;
@@ -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
- }
@@ -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;
@@ -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>;
@@ -1,9 +0,0 @@
1
- export function is(name, message) {
2
- return message.name === name;
3
- }
4
- export function create(name, value) {
5
- return {
6
- name,
7
- value
8
- };
9
- }
@@ -1,7 +0,0 @@
1
- import type { Guard } from '../../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 {};