fortepiano 0.1.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.
Files changed (94) hide show
  1. package/README.md +3 -0
  2. package/lib/Aggregate.d.ts +4 -0
  3. package/lib/Aggregate.js +2 -0
  4. package/lib/Binary.d.ts +5 -0
  5. package/lib/Binary.js +15 -0
  6. package/lib/Buffer.d.ts +5 -0
  7. package/lib/Buffer.js +45 -0
  8. package/lib/Cache.d.ts +18 -0
  9. package/lib/Cache.js +50 -0
  10. package/lib/Console.d.ts +20 -0
  11. package/lib/Console.js +25 -0
  12. package/lib/Crypto.d.ts +5 -0
  13. package/lib/Crypto.js +39 -0
  14. package/lib/Date.d.ts +4 -0
  15. package/lib/Date.js +30 -0
  16. package/lib/Eq.d.ts +4 -0
  17. package/lib/Eq.js +29 -0
  18. package/lib/Error.d.ts +6 -0
  19. package/lib/Error.js +56 -0
  20. package/lib/GeneratorL.d.ts +208 -0
  21. package/lib/GeneratorL.js +501 -0
  22. package/lib/Http.d.ts +60 -0
  23. package/lib/Http.js +131 -0
  24. package/lib/IOAsyncGenerator.d.ts +102 -0
  25. package/lib/IOAsyncGenerator.js +456 -0
  26. package/lib/Log.d.ts +4 -0
  27. package/lib/Log.js +5 -0
  28. package/lib/Magma.d.ts +2 -0
  29. package/lib/Magma.js +26 -0
  30. package/lib/Matrix.d.ts +9 -0
  31. package/lib/Matrix.js +36 -0
  32. package/lib/Mock.d.ts +76 -0
  33. package/lib/Mock.js +113 -0
  34. package/lib/Option.d.ts +2 -0
  35. package/lib/Option.js +26 -0
  36. package/lib/Random.d.ts +7 -0
  37. package/lib/Random.js +7 -0
  38. package/lib/Reader.d.ts +4 -0
  39. package/lib/Reader.js +31 -0
  40. package/lib/ReaderEither.d.ts +9 -0
  41. package/lib/ReaderEither.js +34 -0
  42. package/lib/ReaderTask.d.ts +8 -0
  43. package/lib/ReaderTask.js +35 -0
  44. package/lib/ReaderTaskEither.d.ts +17 -0
  45. package/lib/ReaderTaskEither.js +42 -0
  46. package/lib/ReadonlyArray.d.ts +75 -0
  47. package/lib/ReadonlyArray.js +70 -0
  48. package/lib/ReadonlyRecord.d.ts +4 -0
  49. package/lib/ReadonlyRecord.js +28 -0
  50. package/lib/ReadonlyTuple.d.ts +14 -0
  51. package/lib/ReadonlyTuple.js +34 -0
  52. package/lib/Storage.d.ts +15 -0
  53. package/lib/Storage.js +57 -0
  54. package/lib/Stream.d.ts +5 -0
  55. package/lib/Stream.js +31 -0
  56. package/lib/TaskEither.d.ts +2 -0
  57. package/lib/TaskEither.js +32 -0
  58. package/lib/Type.d.ts +11 -0
  59. package/lib/Type.js +53 -0
  60. package/lib/Validation.d.ts +4 -0
  61. package/lib/Validation.js +30 -0
  62. package/lib/cache/Memcached.d.ts +4 -0
  63. package/lib/cache/Memcached.js +50 -0
  64. package/lib/cache/Memory.d.ts +2 -0
  65. package/lib/cache/Memory.js +66 -0
  66. package/lib/cache/Redis.d.ts +4 -0
  67. package/lib/cache/Redis.js +58 -0
  68. package/lib/cache/Storage.d.ts +4 -0
  69. package/lib/cache/Storage.js +62 -0
  70. package/lib/function.d.ts +52 -0
  71. package/lib/function.js +101 -0
  72. package/lib/http/Axios.d.ts +3 -0
  73. package/lib/http/Axios.js +59 -0
  74. package/lib/http/Fetch.d.ts +2 -0
  75. package/lib/http/Fetch.js +71 -0
  76. package/lib/http/Got.d.ts +3 -0
  77. package/lib/http/Got.js +60 -0
  78. package/lib/http/Mock.d.ts +2 -0
  79. package/lib/http/Mock.js +52 -0
  80. package/lib/index.d.ts +48 -0
  81. package/lib/index.js +86 -0
  82. package/lib/log/Void.d.ts +3 -0
  83. package/lib/log/Void.js +6 -0
  84. package/lib/number.d.ts +3 -0
  85. package/lib/number.js +8 -0
  86. package/lib/storage/Flydrive.d.ts +4 -0
  87. package/lib/storage/Flydrive.js +67 -0
  88. package/lib/storage/Fs.d.ts +3 -0
  89. package/lib/storage/Fs.js +53 -0
  90. package/lib/string.d.ts +5 -0
  91. package/lib/string.js +33 -0
  92. package/lib/struct.d.ts +9 -0
  93. package/lib/struct.js +47 -0
  94. package/package.json +87 -0
package/lib/Http.js ADDED
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.mock = exports.log = exports.pool = exports.cache = exports.buffer = exports.json = exports.HttpErrorC = exports.HttpResponseC = exports.HttpMethodC = exports.HttpError = void 0;
23
+ const Ei = __importStar(require("fp-ts/Either"));
24
+ const function_1 = require("fp-ts/function");
25
+ const J = __importStar(require("fp-ts/Json"));
26
+ const O = __importStar(require("fp-ts/Option"));
27
+ const R = __importStar(require("fp-ts/Random"));
28
+ const TE = __importStar(require("fp-ts/TaskEither"));
29
+ const t = __importStar(require("io-ts"));
30
+ const io_ts_types_1 = require("io-ts-types");
31
+ const $T = __importStar(require("./Type"));
32
+ const $Er = __importStar(require("./Error"));
33
+ const Mock_1 = require("./http/Mock");
34
+ Object.defineProperty(exports, "mock", { enumerable: true, get: function () { return Mock_1.mock; } });
35
+ const $L = __importStar(require("./Log"));
36
+ const $R = __importStar(require("./Random"));
37
+ const $Stri = __importStar(require("./string"));
38
+ const ERRORS = {
39
+ BadRequest: 400,
40
+ Unauthorized: 401,
41
+ Forbidden: 403,
42
+ NotFound: 404,
43
+ UnprocessableEntity: 422,
44
+ };
45
+ class HttpError extends Error {
46
+ constructor(response, message) {
47
+ super(message);
48
+ this.response = response;
49
+ }
50
+ }
51
+ exports.HttpError = HttpError;
52
+ const HttpMethods = [
53
+ 'delete',
54
+ 'get',
55
+ 'head',
56
+ 'options',
57
+ 'patch',
58
+ 'post',
59
+ 'put',
60
+ ];
61
+ exports.HttpMethodC = $T.literalUnion(HttpMethods, 'HttpMethod');
62
+ const HttpResponseC = (codec) => t.type({
63
+ url: t.string,
64
+ status: t.number,
65
+ headers: t.readonly(t.record(t.string, t.union([t.string, t.readonlyArray(t.string)]))),
66
+ body: codec,
67
+ }, `HttpResponse(${codec.name})`);
68
+ exports.HttpResponseC = HttpResponseC;
69
+ const is = (type) => (u) => $Er.ErrorC.is(u) &&
70
+ t
71
+ .type({
72
+ response: t.intersection([
73
+ exports.HttpResponseC(t.unknown),
74
+ t.type({ status: type ? t.literal(ERRORS[type]) : t.number }),
75
+ ]),
76
+ })
77
+ .is(Object.assign({}, u));
78
+ const HttpErrorC = (type) => new t.Type(`Http${type || ''}Error`, is(type), (u, c) => (is(type)(u) ? t.success(u) : t.failure(u, c)), function_1.identity);
79
+ exports.HttpErrorC = HttpErrorC;
80
+ const _json = (request) => (url, options) => request(url, Object.assign(Object.assign({}, options), { json: true, buffer: false }));
81
+ const json = (http) => ({
82
+ delete: _json(http.delete),
83
+ get: _json(http.get),
84
+ patch: _json(http.patch),
85
+ post: _json(http.post),
86
+ put: _json(http.put),
87
+ head: _json(http.head),
88
+ options: _json(http.options),
89
+ });
90
+ exports.json = json;
91
+ const _buffer = (request) => (url, options) => request(url, Object.assign(Object.assign({}, options), { buffer: true, json: false }));
92
+ const buffer = (http) => ({
93
+ delete: _buffer(http.delete),
94
+ get: _buffer(http.get),
95
+ patch: _buffer(http.patch),
96
+ post: _buffer(http.post),
97
+ put: _buffer(http.put),
98
+ head: _buffer(http.head),
99
+ options: _buffer(http.options),
100
+ });
101
+ exports.buffer = buffer;
102
+ const cache = (cache) => (http) => (Object.assign(Object.assign({}, http), { get: (url, options) => function_1.pipe([url, options], J.stringify, Ei.match(() => http.get(url, options), (key) => function_1.pipe(cache.get(key, exports.HttpResponseC(t.unknown)), TE.alt(() => function_1.pipe(http.get(url, options), TE.chainFirst((response) => function_1.pipe(response, cache.set(key, exports.HttpResponseC(io_ts_types_1.Json)), TE.altW(() => TE.of(undefined))))))))) }));
103
+ exports.cache = cache;
104
+ const pool = (http) => {
105
+ const pool = new Map();
106
+ return Object.assign(Object.assign({}, http), { get: (url, options) => {
107
+ const key = [url, options];
108
+ return function_1.pipe(pool.get(key), O.fromNullable, O.match(() => () => {
109
+ const promise = http
110
+ .get(url, options)()
111
+ .finally(() => pool.delete(key));
112
+ pool.set(key, promise);
113
+ return promise;
114
+ }, function_1.constant));
115
+ } });
116
+ };
117
+ exports.pool = pool;
118
+ const _log = (method, request, log) => (url, options) => $R.salt(TE.MonadIO)(R.randomInt(0, Number.MAX_SAFE_INTEGER), (salt) => {
119
+ const message = `[${salt}] \r${$Stri.uppercase(method)} ${url}`;
120
+ return function_1.pipe(log.start(message), TE.fromIO, TE.chain(() => request(url, options)), TE.chainFirstIOK(() => log.end(message)), TE.orElseW((error) => function_1.pipe(log.end(message), TE.fromIO, TE.chain(() => TE.left(error)))));
121
+ });
122
+ const log = (logStart, logEnd = $L.void) => (http) => ({
123
+ delete: _log('delete', http.delete, { start: logStart, end: logEnd }),
124
+ get: _log('get', http.get, { start: logStart, end: logEnd }),
125
+ patch: _log('patch', http.patch, { start: logStart, end: logEnd }),
126
+ post: _log('post', http.post, { start: logStart, end: logEnd }),
127
+ put: _log('put', http.put, { start: logStart, end: logEnd }),
128
+ head: _log('head', http.head, { start: logStart, end: logEnd }),
129
+ options: _log('options', http.options, { start: logStart, end: logEnd }),
130
+ });
131
+ exports.log = log;
@@ -0,0 +1,102 @@
1
+ import * as Appli from 'fp-ts/Applicative';
2
+ import * as _Apply from 'fp-ts/Apply';
3
+ import * as Ch from 'fp-ts/Chain';
4
+ import * as Co from 'fp-ts/Compactable';
5
+ import * as Ei from 'fp-ts/Either';
6
+ import * as Eq from 'fp-ts/Eq';
7
+ import * as Fi from 'fp-ts/Filterable';
8
+ import * as FiWI from 'fp-ts/FilterableWithIndex';
9
+ import * as FIO from 'fp-ts/FromIO';
10
+ import { Lazy, Predicate, Refinement } from 'fp-ts/function';
11
+ import * as Fu from 'fp-ts/Functor';
12
+ import * as FuWI from 'fp-ts/FunctorWithIndex';
13
+ import * as IO from 'fp-ts/IO';
14
+ import * as Mona from 'fp-ts/Monad';
15
+ import * as MIO from 'fp-ts/MonadIO';
16
+ import * as Mono from 'fp-ts/Monoid';
17
+ import * as O from 'fp-ts/Option';
18
+ import * as P from 'fp-ts/Pointed';
19
+ import * as S from 'fp-ts/Separated';
20
+ import * as T from 'fp-ts/Task';
21
+ import * as $IOG from './GeneratorL';
22
+ export declare const URI = "IOAsyncGenerator";
23
+ export declare type URI = typeof URI;
24
+ declare module 'fp-ts/HKT' {
25
+ interface URItoKind<A> {
26
+ [URI]: IOAsyncGenerator<A>;
27
+ }
28
+ }
29
+ export declare type IOAsyncGenerator<A> = IO.IO<AsyncGenerator<A>>;
30
+ export declare const getMonoid: <A>() => Mono.Monoid<IOAsyncGenerator<A>>;
31
+ export declare const fromIOGenerator: <A>(as: $IOG.GeneratorL<A>) => IOAsyncGenerator<A>;
32
+ export declare const Functor: Fu.Functor1<URI>;
33
+ export declare const map: <A, B>(a: (a: A) => B) => (b: IOAsyncGenerator<A>) => IOAsyncGenerator<B>;
34
+ export declare const flap: <A>(a: A) => <B>(fab: IOAsyncGenerator<(a: A) => B>) => IOAsyncGenerator<B>;
35
+ export declare const bindTo: <N extends string>(name: N) => <A>(fa: IOAsyncGenerator<A>) => IOAsyncGenerator<{ readonly [K in N]: A; }>;
36
+ export declare const FunctorWithIndex: FuWI.FunctorWithIndex1<URI, number>;
37
+ export declare const Pointed: P.Pointed1<URI>;
38
+ export declare const of: <A>(a: A) => IOAsyncGenerator<A>;
39
+ export declare const Do: IOAsyncGenerator<{}>;
40
+ export declare const ApplyPar: _Apply.Apply1<URI>;
41
+ /**
42
+ *
43
+ */
44
+ export declare const ApplySeq: _Apply.Apply1<URI>;
45
+ export declare const ap: <A, B>(a: IOAsyncGenerator<A>) => (b: IOAsyncGenerator<(a: A) => B>) => IOAsyncGenerator<B>;
46
+ export declare const apFirst: <B>(second: IOAsyncGenerator<B>) => <A>(first: IOAsyncGenerator<A>) => IOAsyncGenerator<A>;
47
+ export declare const apSecond: <B>(second: IOAsyncGenerator<B>) => <A>(first: IOAsyncGenerator<A>) => IOAsyncGenerator<B>;
48
+ export declare const apS: <N extends string, A, B>(name: Exclude<N, keyof A>, fb: IOAsyncGenerator<B>) => (fa: IOAsyncGenerator<A>) => IOAsyncGenerator<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B; }>;
49
+ export declare const ApplicativePar: Appli.Applicative1<URI>;
50
+ export declare const ApplicativeSeq: Appli.Applicative1<URI>;
51
+ export declare const Chain: Ch.Chain1<URI>;
52
+ export declare const chain: <A, B>(a: (a: A) => IOAsyncGenerator<B>) => (b: IOAsyncGenerator<A>) => IOAsyncGenerator<B>;
53
+ export declare const chainFirst: <A, B>(f: (a: A) => IOAsyncGenerator<B>) => (first: IOAsyncGenerator<A>) => IOAsyncGenerator<A>;
54
+ export declare const bind: <N extends string, A, B>(name: Exclude<N, keyof A>, f: (a: A) => IOAsyncGenerator<B>) => (ma: IOAsyncGenerator<A>) => IOAsyncGenerator<{ readonly [K in N | keyof A]: K extends keyof A ? A[K] : B; }>;
55
+ export declare const Monad: Mona.Monad1<URI>;
56
+ export declare const FromIO: FIO.FromIO1<URI>;
57
+ export declare const fromIO: import("fp-ts/lib/NaturalTransformation").NaturalTransformation11<"IO", "IOAsyncGenerator">;
58
+ export declare const fromIOK: <A extends readonly unknown[], B>(f: (...a: A) => IO.IO<B>) => (...a: A) => IOAsyncGenerator<B>;
59
+ export declare const chainIOK: <A, B>(f: (a: A) => IO.IO<B>) => (first: IOAsyncGenerator<A>) => IOAsyncGenerator<B>;
60
+ export declare const chainFirstIOK: <A, B>(f: (a: A) => IO.IO<B>) => (first: IOAsyncGenerator<A>) => IOAsyncGenerator<A>;
61
+ export declare const fromIOReadonlyArray: <A>(fa: IO.IO<readonly A[]>) => IOAsyncGenerator<A>;
62
+ export declare const fromIOReadonlyArrayK: <A extends readonly unknown[], B>(f: (...a: A) => IO.IO<readonly B[]>) => (...a: A) => IOAsyncGenerator<B>;
63
+ export declare const chainIOReadonlyArrayK: <A, B>(f: (a: A) => IO.IO<readonly B[]>) => (b: IOAsyncGenerator<A>) => IOAsyncGenerator<B>;
64
+ export declare const MonadIO: MIO.MonadIO1<URI>;
65
+ export declare const Compactable: Co.Compactable1<URI>;
66
+ export declare const compact: <A>(fa: IOAsyncGenerator<O.Option<A>>) => IOAsyncGenerator<A>;
67
+ export declare const separate: <A, B>(fa: IOAsyncGenerator<Ei.Either<A, B>>) => S.Separated<IOAsyncGenerator<A>, IOAsyncGenerator<B>>;
68
+ export declare const Filterable: Fi.Filterable1<URI>;
69
+ export declare function filter<A, B extends A>(refinement: Refinement<A, B>): (fa: IOAsyncGenerator<A>) => IOAsyncGenerator<B>;
70
+ export declare function filter<A>(predicate: Predicate<A>): (fa: IOAsyncGenerator<A>) => IOAsyncGenerator<A>;
71
+ export declare const filterMap: <A, B>(a: (a: A) => O.Option<B>) => (b: IOAsyncGenerator<A>) => IOAsyncGenerator<B>;
72
+ export declare function partition<A, B extends A>(refinement: Refinement<A, B>): (fa: IOAsyncGenerator<A>) => S.Separated<IOAsyncGenerator<A>, IOAsyncGenerator<B>>;
73
+ export declare function partition<A>(predicate: Predicate<A>): (fa: IOAsyncGenerator<A>) => S.Separated<IOAsyncGenerator<A>, IOAsyncGenerator<A>>;
74
+ export declare const partitionMap: <A, B, C>(a: (a: A) => Ei.Either<B, C>) => (b: IOAsyncGenerator<A>) => S.Separated<IOAsyncGenerator<B>, IOAsyncGenerator<C>>;
75
+ export declare const FilterableWithIndex: FiWI.FilterableWithIndex1<URI, number>;
76
+ export declare function filterWithIndex<A, B extends A>(refinementWithIndex: (i: number, a: A) => a is B): (fa: IOAsyncGenerator<A>) => IOAsyncGenerator<B>;
77
+ export declare function filterWithIndex<A>(predicateWithIndex: (i: number, a: A) => boolean): (fa: IOAsyncGenerator<A>) => IOAsyncGenerator<A>;
78
+ export declare const filterMapWithIndex: <A, B>(a: (i: number, a: A) => O.Option<B>) => (b: IOAsyncGenerator<A>) => IOAsyncGenerator<B>;
79
+ export declare function partitionWithIndex<A, B extends A>(refinementWithIndex: (i: number, a: A) => a is B): (fa: IOAsyncGenerator<A>) => S.Separated<IOAsyncGenerator<A>, IOAsyncGenerator<B>>;
80
+ export declare function partitionWithIndex<A>(predicateWithIndex: (i: number, a: A) => boolean): (fa: IOAsyncGenerator<A>) => S.Separated<IOAsyncGenerator<A>, IOAsyncGenerator<A>>;
81
+ export declare const partitionMapWithIndex: <A, B, C>(a: (i: number, a: A) => Ei.Either<B, C>) => (b: IOAsyncGenerator<A>) => S.Separated<IOAsyncGenerator<B>, IOAsyncGenerator<C>>;
82
+ export declare const range: (start: number, end?: number | undefined) => IOAsyncGenerator<number>;
83
+ export declare const replicate: <A>(a: A) => IOAsyncGenerator<A>;
84
+ export declare const fromReadonlyArray: <A>(x: readonly A[]) => IOAsyncGenerator<A>;
85
+ export declare const sieve: <A>(f: (init: readonly A[], a: A) => boolean) => (as: IOAsyncGenerator<A>) => IOAsyncGenerator<A>;
86
+ export declare const prime: IOAsyncGenerator<number>;
87
+ export declare const exp: IOAsyncGenerator<number>;
88
+ export declare const fibonacci: IOAsyncGenerator<number>;
89
+ export declare const flatten: <A>(as: IOAsyncGenerator<IOAsyncGenerator<A>>) => IOAsyncGenerator<A>;
90
+ export declare const take: <A>(n: number) => (as: IOAsyncGenerator<A>) => IOAsyncGenerator<A>;
91
+ export declare const drop: <A>(n: number) => (as: IOAsyncGenerator<A>) => IOAsyncGenerator<A>;
92
+ export declare const zip: <A, B>(bs: IOAsyncGenerator<B>) => (as: IOAsyncGenerator<A>) => IOAsyncGenerator<readonly [A, B]>;
93
+ export declare const uniq: <A>(E: Eq.Eq<A>) => (as: IOAsyncGenerator<A>) => IOAsyncGenerator<A>;
94
+ export declare const match: <A, B>(onEmpty: Lazy<B>, onNonEmpty: (head: A, tail: IOAsyncGenerator<A>) => B) => (as: IOAsyncGenerator<A>) => T.Task<B>;
95
+ export declare const toTask: <A>(as: IOAsyncGenerator<A>) => T.Task<readonly A[]>;
96
+ export declare const isEmpty: (as: IOAsyncGenerator<unknown>) => T.Task<boolean>;
97
+ export declare const isNonEmpty: (as: IOAsyncGenerator<unknown>) => T.Task<boolean>;
98
+ export declare const lookup: <A>(i: number) => (as: IOAsyncGenerator<A>) => T.Task<O.Option<A>>;
99
+ export declare const head: <A>(as: IOAsyncGenerator<A>) => T.Task<O.Option<A>>;
100
+ export declare function find<A, B extends A>(refinement: Refinement<A, B>): (as: IOAsyncGenerator<A>) => T.Task<O.Option<B>>;
101
+ export declare function find<A>(predicate: Predicate<A>): (as: IOAsyncGenerator<A>) => T.Task<O.Option<A>>;
102
+ export declare const elem: <A>(Eq: Eq.Eq<A>) => (a: A) => (as: IOAsyncGenerator<A>) => T.Task<O.Option<A>>;