From 2ce1c340d629a962d686dbe352c54a6cf4d0b395 Mon Sep 17 00:00:00 2001 From: Malte Legenhausen Date: Mon, 22 Oct 2018 11:29:18 +0200 Subject: [PATCH 1/4] io-ts type added --- package-lock.json | 64 +++++++++++++++++- package.json | 5 +- src/__tests__/io-ts.spec.ts | 39 +++++++++++ src/io-ts.ts | 126 ++++++++++++++++++++++++++++++++++++ 4 files changed, 231 insertions(+), 3 deletions(-) create mode 100644 src/__tests__/io-ts.spec.ts create mode 100644 src/io-ts.ts diff --git a/package-lock.json b/package-lock.json index bd4d9d9..bfb8fad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1969,8 +1969,7 @@ "fp-ts": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/fp-ts/-/fp-ts-1.2.0.tgz", - "integrity": "sha512-GHUrakKieiz7BWL7eX9G7UMawnaeGSJ1HbZY5t+BbgvzhzgNCT2SXtfqrIl0pRZHkp/oiysdWLMoIxYVlXy66g==", - "dev": true + "integrity": "sha512-GHUrakKieiz7BWL7eX9G7UMawnaeGSJ1HbZY5t+BbgvzhzgNCT2SXtfqrIl0pRZHkp/oiysdWLMoIxYVlXy66g==" }, "fragment-cache": { "version": "0.2.1", @@ -2982,6 +2981,25 @@ "integrity": "sha1-EEqOSqym09jNFXqO+L+rLXo//bY=", "dev": true }, + "io-ts": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/io-ts/-/io-ts-1.3.1.tgz", + "integrity": "sha512-PqTcX4ojXogRZRk86o7gltg9996DtKrxN2qjv9OOjBYHI0DSEJtwiJBoK682To1YE7ONNNaqwd9phN4WF3nomQ==", + "requires": { + "fp-ts": "^1.0.0" + } + }, + "io-ts-types": { + "version": "0.3.14", + "resolved": "https://registry.npmjs.org/io-ts-types/-/io-ts-types-0.3.14.tgz", + "integrity": "sha512-hEUo+VpS0EXLji14CON7f/ThuLMExaA5kWfW6LIM9gC+X/INTxwLt3GYKkKQc6Fx0snM9xt/QDXd5BPjeXE1RQ==", + "requires": { + "fp-ts": "^1.0.0", + "io-ts": "^1.1.4", + "monocle-ts": "^1.0.0", + "newtype-ts": "^0.2.1" + } + }, "is-accessor-descriptor": { "version": "0.1.6", "resolved": "https://registry.npmjs.org/is-accessor-descriptor/-/is-accessor-descriptor-0.1.6.tgz", @@ -3491,6 +3509,7 @@ "jest-util": "^22.4.1", "jest-validate": "^22.4.4", "jest-worker": "^22.2.2", + "micromatch": "^2.3.11", "node-notifier": "^5.2.1", "realpath-native": "^1.0.0", "rimraf": "^2.5.4", @@ -3573,6 +3592,7 @@ "jest-docblock": "^22.4.3", "jest-serializer": "^22.4.3", "jest-worker": "^22.4.3", + "micromatch": "^2.3.11", "sane": "^2.0.0" } }, @@ -3623,6 +3643,7 @@ "requires": { "@babel/code-frame": "^7.0.0-beta.35", "chalk": "^2.0.1", + "micromatch": "^2.3.11", "slash": "^1.0.0", "stack-utils": "^1.0.1" } @@ -3697,6 +3718,7 @@ "jest-util": "^22.4.1", "jest-validate": "^22.4.4", "json-stable-stringify": "^1.0.1", + "micromatch": "^2.3.11", "realpath-native": "^1.0.0", "slash": "^1.0.0", "strip-bom": "3.0.0", @@ -4795,6 +4817,27 @@ "readable-stream": "^2.0.1" } }, + "micromatch": { + "version": "2.3.11", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-2.3.11.tgz", + "integrity": "sha1-hmd8l9FyCzY0MdBNDRUpO9OMFWU=", + "dev": true, + "requires": { + "arr-diff": "^2.0.0", + "array-unique": "^0.2.1", + "braces": "^1.8.2", + "expand-brackets": "^0.1.4", + "extglob": "^0.3.1", + "filename-regex": "^2.0.0", + "is-extglob": "^1.0.0", + "is-glob": "^2.0.1", + "kind-of": "^3.0.2", + "normalize-path": "^2.0.1", + "object.omit": "^2.0.0", + "parse-glob": "^3.0.4", + "regex-cache": "^0.4.2" + } + }, "mime-db": { "version": "1.36.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.36.0.tgz", @@ -4877,6 +4920,14 @@ "integrity": "sha512-xV2bxeN6F7oYjZWTe/YPAy6MN2M+sL4u/Rlm2AHCIVGfo2p1yGmBHQ6vHehl4bRTZBdHu3TSkWdYgkwpYzAGSw==", "dev": true }, + "monocle-ts": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/monocle-ts/-/monocle-ts-1.3.0.tgz", + "integrity": "sha512-oQrsdhh8ut2zRljic2y6EjjWs/NsUj2vDpEY1tLTTo3jE9WS70JOO72HzOY0lWkmgDRsu29pvDbE1aBD8LBkOA==", + "requires": { + "fp-ts": "^1.0.0" + } + }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", @@ -4935,6 +4986,15 @@ "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", "dev": true }, + "newtype-ts": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/newtype-ts/-/newtype-ts-0.2.1.tgz", + "integrity": "sha512-Gnch+o9P/7RgKdkwx5mqWr3iR+Sxxvk2mykPaH93Y9WDhnVQ/ojdOoAGb9O/qHjnYMqJYW0xee9uNebdfpyCLg==", + "requires": { + "fp-ts": "^1.0.0", + "monocle-ts": "^1.0.0" + } + }, "node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", diff --git a/package.json b/package.json index 7b486cf..3464730 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,10 @@ "fp-ts": "^1.2.0", "tslib": "^1.9.0" }, - "dependencies": {}, + "dependencies": { + "io-ts": "^1.3.1", + "io-ts-types": "^0.3.14" + }, "repository": { "type": "git", "url": "git+https://github.com/devex-web-frontend/remote-data-ts.git" diff --git a/src/__tests__/io-ts.spec.ts b/src/__tests__/io-ts.spec.ts new file mode 100644 index 0000000..a3fcc50 --- /dev/null +++ b/src/__tests__/io-ts.spec.ts @@ -0,0 +1,39 @@ +import { createRemoteDataFromJSON } from '../io-ts'; +import * as t from 'io-ts'; +import { initial, pending, failure, success, progress } from '../remote-data'; +import { right } from 'fp-ts/lib/Either'; +import { none, some } from 'fp-ts/lib/Option'; + +describe('RemoteDataFromJSONType', () => { + it('createRemoteDataFromJSON', () => { + const T = createRemoteDataFromJSON(t.string, t.number); + expect(T.decode({ type: 'Failure', error: 'error' })).toEqual(right(failure('error'))); + expect(T.decode({ type: 'Initial' })).toEqual(right(initial)); + expect(T.decode({ type: 'Pending', progress: null })).toEqual(right(pending)); + expect(T.decode({ type: 'Pending', progress: { loaded: 2, total: null } })).toEqual( + right(progress({ loaded: 2, total: none })), + ); + expect(T.decode({ type: 'Pending', progress: { loaded: 2, total: 5 } })).toEqual( + right(progress({ loaded: 2, total: some(5) })), + ); + expect(T.decode({ type: 'Success', value: 42 })).toEqual(right(success(42))); + expect(T.encode(failure('error'))).toEqual({ type: 'Failure', error: 'error' }); + expect(T.encode(initial)).toEqual({ type: 'Initial' }); + expect(T.encode(pending)).toEqual({ type: 'Pending', progress: null }); + expect(T.encode(progress({ loaded: 2, total: none }))).toEqual({ + type: 'Pending', + progress: { loaded: 2, total: null }, + }); + expect(T.encode(progress({ loaded: 2, total: some(5) }))).toEqual({ + type: 'Pending', + progress: { loaded: 2, total: 5 }, + }); + expect(T.encode(success(42))).toEqual({ type: 'Success', value: 42 }); + expect(T.is(failure('error'))).toBe(true); + expect(T.is(initial)).toBe(true); + expect(T.is(pending)).toBe(true); + expect(T.is(success(42))).toBe(true); + expect(T.is(failure(1))).toBe(false); + expect(T.is(success('invalid'))).toBe(false); + }); +}); diff --git a/src/io-ts.ts b/src/io-ts.ts new file mode 100644 index 0000000..ba89d57 --- /dev/null +++ b/src/io-ts.ts @@ -0,0 +1,126 @@ +import * as t from 'io-ts'; +import { createOptionFromNullable } from 'io-ts-types'; + +import { + failure, + initial, + pending, + RemoteData, + RemoteFailure, + RemoteInitial, + RemotePending, + RemoteSuccess, + success, + RemoteProgress, + progress, +} from './remote-data'; + +export interface JSONFailure { + type: 'Failure'; + error: L; +} + +export interface JSONInitial { + type: 'Initial'; +} + +export interface JSONPending { + type: 'Pending'; + progress: RemoteProgress | null; +} + +export interface JSONSuccess { + type: 'Success'; + value: A; +} + +export type JSONRemoteData = JSONFailure | JSONInitial | JSONPending | JSONSuccess; + +export class RemoteDataFromJSONType extends t.Type< + A, + O, + I +> { + readonly _tag: 'RemoteDataFromJSONType' = 'RemoteDataFromJSONType'; + constructor( + name: string, + is: RemoteDataFromJSONType['is'], + validate: RemoteDataFromJSONType['validate'], + serialize: RemoteDataFromJSONType['encode'], + readonly left: L, + readonly right: R, + ) { + super(name, is, validate, serialize); + } +} + +export function createRemoteDataFromJSON< + L extends t.Type, + R extends t.Type, + AL = t.TypeOf, + OL = t.OutputOf, + AR = t.TypeOf, + OR = t.OutputOf +>( + leftType: L, + rightType: R, + name: string = `RemoteData<${leftType.name}, ${rightType.name}>`, +): RemoteDataFromJSONType, JSONRemoteData, t.mixed> { + const JSONProgress = createOptionFromNullable( + t.type({ + loaded: t.number, + total: createOptionFromNullable(t.number), + }), + ); + const JSONFailure = t.type({ + type: t.literal('Failure'), + error: leftType, + }); + const JSONInitial = t.type({ + type: t.literal('Initial'), + }); + const JSONPending = t.type({ + type: t.literal('Pending'), + progress: JSONProgress, + }); + const JSONSuccess = t.type({ + type: t.literal('Success'), + value: rightType, + }); + const JSONRemoteData = t.taggedUnion('type', [JSONFailure, JSONInitial, JSONPending, JSONSuccess]); + return new RemoteDataFromJSONType( + name, + (m): m is RemoteData => + m instanceof RemoteInitial || + m instanceof RemotePending || + (m instanceof RemoteFailure && leftType.is(m.error)) || + (m instanceof RemoteSuccess && rightType.is(m.value)), + (m, c) => { + const validation = JSONRemoteData.validate(m, c); + if (validation.isLeft()) { + return validation as any; + } else { + const e = validation.value; + switch (e.type) { + case 'Failure': + return t.success(failure(e.error)); + case 'Initial': + return t.success(initial); + case 'Pending': + return e.progress.foldL(() => t.success(pending), p => t.success(progress(p))); + case 'Success': + return t.success(success(e.value)); + } + } + }, + a => + a.foldL>( + () => ({ type: 'Initial' }), + () => ({ type: 'Pending', progress: JSONProgress.encode((a as any).progress) }), + l => ({ type: 'Failure', error: leftType.encode(l) }), + a => ({ type: 'Success', value: rightType.encode(a) }), + ), + leftType, + rightType, + ); +} From 62f46e56abcafaf36834b243d7087da7ce5c0762 Mon Sep 17 00:00:00 2001 From: Malte Legenhausen Date: Tue, 23 Oct 2018 09:52:52 +0200 Subject: [PATCH 2/4] CI error fixes added. index.ts added --- .travis.yml | 1 + package-lock.json | 337 +++++++++++++++++++--------------------------- package.json | 12 +- src/index.ts | 2 + tsconfig.json | 1 + 5 files changed, 148 insertions(+), 205 deletions(-) create mode 100644 src/index.ts diff --git a/.travis.yml b/.travis.yml index cfcfe83..8948311 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: node_js node_js: - "8" + - "10" script: - npm run test && npm run build diff --git a/package-lock.json b/package-lock.json index bfb8fad..739f9b5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1969,7 +1969,8 @@ "fp-ts": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/fp-ts/-/fp-ts-1.2.0.tgz", - "integrity": "sha512-GHUrakKieiz7BWL7eX9G7UMawnaeGSJ1HbZY5t+BbgvzhzgNCT2SXtfqrIl0pRZHkp/oiysdWLMoIxYVlXy66g==" + "integrity": "sha512-GHUrakKieiz7BWL7eX9G7UMawnaeGSJ1HbZY5t+BbgvzhzgNCT2SXtfqrIl0pRZHkp/oiysdWLMoIxYVlXy66g==", + "dev": true }, "fragment-cache": { "version": "0.2.1", @@ -1999,24 +2000,28 @@ "dependencies": { "abbrev": { "version": "1.1.1", - "bundled": true, + "resolved": false, + "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", "dev": true, "optional": true }, "ansi-regex": { "version": "2.1.1", - "bundled": true, + "resolved": false, + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", "dev": true }, "aproba": { "version": "1.2.0", - "bundled": true, + "resolved": false, + "integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==", "dev": true, "optional": true }, "are-we-there-yet": { "version": "1.1.4", - "bundled": true, + "resolved": false, + "integrity": "sha1-u13KOCu5TwXhUZQ3PRb9O6HKEQ0=", "dev": true, "optional": true, "requires": { @@ -2026,12 +2031,14 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true, + "resolved": false, + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "dev": true }, "brace-expansion": { "version": "1.1.11", - "bundled": true, + "resolved": false, + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "dev": true, "requires": { "balanced-match": "^1.0.0", @@ -2040,34 +2047,40 @@ }, "chownr": { "version": "1.0.1", - "bundled": true, + "resolved": false, + "integrity": "sha1-4qdQQqlVGQi+vSW4Uj1fl2nXkYE=", "dev": true, "optional": true }, "code-point-at": { "version": "1.1.0", - "bundled": true, + "resolved": false, + "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", "dev": true }, "concat-map": { "version": "0.0.1", - "bundled": true, + "resolved": false, + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "dev": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true, + "resolved": false, + "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=", "dev": true }, "core-util-is": { "version": "1.0.2", - "bundled": true, + "resolved": false, + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", "dev": true, "optional": true }, "debug": { "version": "2.6.9", - "bundled": true, + "resolved": false, + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", "dev": true, "optional": true, "requires": { @@ -2076,25 +2089,29 @@ }, "deep-extend": { "version": "0.5.1", - "bundled": true, + "resolved": false, + "integrity": "sha512-N8vBdOa+DF7zkRrDCsaOXoCs/E2fJfx9B9MrKnnSiHNh4ws7eSys6YQE4KvT1cecKmOASYQBhbKjeuDD9lT81w==", "dev": true, "optional": true }, "delegates": { "version": "1.0.0", - "bundled": true, + "resolved": false, + "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=", "dev": true, "optional": true }, "detect-libc": { "version": "1.0.3", - "bundled": true, + "resolved": false, + "integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=", "dev": true, "optional": true }, "fs-minipass": { "version": "1.2.5", - "bundled": true, + "resolved": false, + "integrity": "sha512-JhBl0skXjUPCFH7x6x61gQxrKyXsxB5gcgePLZCwfyCGGsTISMoIeObbrvVeP6Xmyaudw4TT43qV2Gz+iyd2oQ==", "dev": true, "optional": true, "requires": { @@ -2103,13 +2120,15 @@ }, "fs.realpath": { "version": "1.0.0", - "bundled": true, + "resolved": false, + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true, "optional": true }, "gauge": { "version": "2.7.4", - "bundled": true, + "resolved": false, + "integrity": "sha1-LANAXHU4w51+s3sxcCLjJfsBi/c=", "dev": true, "optional": true, "requires": { @@ -2125,7 +2144,8 @@ }, "glob": { "version": "7.1.2", - "bundled": true, + "resolved": false, + "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", "dev": true, "optional": true, "requires": { @@ -2139,13 +2159,15 @@ }, "has-unicode": { "version": "2.0.1", - "bundled": true, + "resolved": false, + "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=", "dev": true, "optional": true }, "iconv-lite": { "version": "0.4.21", - "bundled": true, + "resolved": false, + "integrity": "sha512-En5V9za5mBt2oUA03WGD3TwDv0MKAruqsuxstbMUZaj9W9k/m1CV/9py3l0L5kw9Bln8fdHQmzHSYtvpvTLpKw==", "dev": true, "optional": true, "requires": { @@ -2154,7 +2176,8 @@ }, "ignore-walk": { "version": "3.0.1", - "bundled": true, + "resolved": false, + "integrity": "sha512-DTVlMx3IYPe0/JJcYP7Gxg7ttZZu3IInhuEhbchuqneY9wWe5Ojy2mXLBaQFUQmo0AW2r3qG7m1mg86js+gnlQ==", "dev": true, "optional": true, "requires": { @@ -2163,7 +2186,8 @@ }, "inflight": { "version": "1.0.6", - "bundled": true, + "resolved": false, + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", "dev": true, "optional": true, "requires": { @@ -2173,18 +2197,21 @@ }, "inherits": { "version": "2.0.3", - "bundled": true, + "resolved": false, + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", "dev": true }, "ini": { "version": "1.3.5", - "bundled": true, + "resolved": false, + "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==", "dev": true, "optional": true }, "is-fullwidth-code-point": { "version": "1.0.0", - "bundled": true, + "resolved": false, + "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", "dev": true, "requires": { "number-is-nan": "^1.0.0" @@ -2192,13 +2219,15 @@ }, "isarray": { "version": "1.0.0", - "bundled": true, + "resolved": false, + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", "dev": true, "optional": true }, "minimatch": { "version": "3.0.4", - "bundled": true, + "resolved": false, + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "dev": true, "requires": { "brace-expansion": "^1.1.7" @@ -2206,12 +2235,14 @@ }, "minimist": { "version": "0.0.8", - "bundled": true, + "resolved": false, + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", "dev": true }, "minipass": { "version": "2.2.4", - "bundled": true, + "resolved": false, + "integrity": "sha512-hzXIWWet/BzWhYs2b+u7dRHlruXhwdgvlTMDKC6Cb1U7ps6Ac6yQlR39xsbjWJE377YTCtKwIXIpJ5oP+j5y8g==", "dev": true, "requires": { "safe-buffer": "^5.1.1", @@ -2220,7 +2251,8 @@ }, "minizlib": { "version": "1.1.0", - "bundled": true, + "resolved": false, + "integrity": "sha512-4T6Ur/GctZ27nHfpt9THOdRZNgyJ9FZchYO1ceg5S8Q3DNLCKYy44nCZzgCJgcvx2UM8czmqak5BCxJMrq37lA==", "dev": true, "optional": true, "requires": { @@ -2229,7 +2261,8 @@ }, "mkdirp": { "version": "0.5.1", - "bundled": true, + "resolved": false, + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "dev": true, "requires": { "minimist": "0.0.8" @@ -2237,13 +2270,15 @@ }, "ms": { "version": "2.0.0", - "bundled": true, + "resolved": false, + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", "dev": true, "optional": true }, "needle": { "version": "2.2.0", - "bundled": true, + "resolved": false, + "integrity": "sha512-eFagy6c+TYayorXw/qtAdSvaUpEbBsDwDyxYFgLZ0lTojfH7K+OdBqAF7TAFwDokJaGpubpSGG0wO3iC0XPi8w==", "dev": true, "optional": true, "requires": { @@ -2254,7 +2289,8 @@ }, "node-pre-gyp": { "version": "0.10.0", - "bundled": true, + "resolved": false, + "integrity": "sha512-G7kEonQLRbcA/mOoFoxvlMrw6Q6dPf92+t/l0DFSMuSlDoWaI9JWIyPwK0jyE1bph//CUEL65/Fz1m2vJbmjQQ==", "dev": true, "optional": true, "requires": { @@ -2272,7 +2308,8 @@ }, "nopt": { "version": "4.0.1", - "bundled": true, + "resolved": false, + "integrity": "sha1-0NRoWv1UFRk8jHUFYC0NF81kR00=", "dev": true, "optional": true, "requires": { @@ -2282,13 +2319,15 @@ }, "npm-bundled": { "version": "1.0.3", - "bundled": true, + "resolved": false, + "integrity": "sha512-ByQ3oJ/5ETLyglU2+8dBObvhfWXX8dtPZDMePCahptliFX2iIuhyEszyFk401PZUNQH20vvdW5MLjJxkwU80Ow==", "dev": true, "optional": true }, "npm-packlist": { "version": "1.1.10", - "bundled": true, + "resolved": false, + "integrity": "sha512-AQC0Dyhzn4EiYEfIUjCdMl0JJ61I2ER9ukf/sLxJUcZHfo+VyEfz2rMJgLZSS1v30OxPQe1cN0LZA1xbcaVfWA==", "dev": true, "optional": true, "requires": { @@ -2298,7 +2337,8 @@ }, "npmlog": { "version": "4.1.2", - "bundled": true, + "resolved": false, + "integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==", "dev": true, "optional": true, "requires": { @@ -2310,18 +2350,21 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true, + "resolved": false, + "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", "dev": true }, "object-assign": { "version": "4.1.1", - "bundled": true, + "resolved": false, + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", "dev": true, "optional": true }, "once": { "version": "1.4.0", - "bundled": true, + "resolved": false, + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "dev": true, "requires": { "wrappy": "1" @@ -2329,19 +2372,22 @@ }, "os-homedir": { "version": "1.0.2", - "bundled": true, + "resolved": false, + "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", "dev": true, "optional": true }, "os-tmpdir": { "version": "1.0.2", - "bundled": true, + "resolved": false, + "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", "dev": true, "optional": true }, "osenv": { "version": "0.1.5", - "bundled": true, + "resolved": false, + "integrity": "sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==", "dev": true, "optional": true, "requires": { @@ -2351,19 +2397,22 @@ }, "path-is-absolute": { "version": "1.0.1", - "bundled": true, + "resolved": false, + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true, "optional": true }, "process-nextick-args": { "version": "2.0.0", - "bundled": true, + "resolved": false, + "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==", "dev": true, "optional": true }, "rc": { "version": "1.2.7", - "bundled": true, + "resolved": false, + "integrity": "sha512-LdLD8xD4zzLsAT5xyushXDNscEjB7+2ulnl8+r1pnESlYtlJtVSoCMBGr30eDRJ3+2Gq89jK9P9e4tCEH1+ywA==", "dev": true, "optional": true, "requires": { @@ -2375,7 +2424,8 @@ "dependencies": { "minimist": { "version": "1.2.0", - "bundled": true, + "resolved": false, + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", "dev": true, "optional": true } @@ -2383,7 +2433,8 @@ }, "readable-stream": { "version": "2.3.6", - "bundled": true, + "resolved": false, + "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "dev": true, "optional": true, "requires": { @@ -2398,7 +2449,8 @@ }, "rimraf": { "version": "2.6.2", - "bundled": true, + "resolved": false, + "integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==", "dev": true, "optional": true, "requires": { @@ -2407,42 +2459,49 @@ }, "safe-buffer": { "version": "5.1.1", - "bundled": true, + "resolved": false, + "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==", "dev": true }, "safer-buffer": { "version": "2.1.2", - "bundled": true, + "resolved": false, + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "dev": true, "optional": true }, "sax": { "version": "1.2.4", - "bundled": true, + "resolved": false, + "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==", "dev": true, "optional": true }, "semver": { "version": "5.5.0", - "bundled": true, + "resolved": false, + "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==", "dev": true, "optional": true }, "set-blocking": { "version": "2.0.0", - "bundled": true, + "resolved": false, + "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", "dev": true, "optional": true }, "signal-exit": { "version": "3.0.2", - "bundled": true, + "resolved": false, + "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", "dev": true, "optional": true }, "string-width": { "version": "1.0.2", - "bundled": true, + "resolved": false, + "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", "dev": true, "requires": { "code-point-at": "^1.0.0", @@ -2452,7 +2511,8 @@ }, "string_decoder": { "version": "1.1.1", - "bundled": true, + "resolved": false, + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", "dev": true, "optional": true, "requires": { @@ -2461,7 +2521,8 @@ }, "strip-ansi": { "version": "3.0.1", - "bundled": true, + "resolved": false, + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "dev": true, "requires": { "ansi-regex": "^2.0.0" @@ -2469,13 +2530,15 @@ }, "strip-json-comments": { "version": "2.0.1", - "bundled": true, + "resolved": false, + "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", "dev": true, "optional": true }, "tar": { "version": "4.4.1", - "bundled": true, + "resolved": false, + "integrity": "sha512-O+v1r9yN4tOsvl90p5HAP4AEqbYhx4036AGMm075fH9F8Qwi3oJ+v4u50FkT/KkvywNGtwkk0zRI+8eYm1X/xg==", "dev": true, "optional": true, "requires": { @@ -2490,13 +2553,15 @@ }, "util-deprecate": { "version": "1.0.2", - "bundled": true, + "resolved": false, + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", "dev": true, "optional": true }, "wide-align": { "version": "1.1.2", - "bundled": true, + "resolved": false, + "integrity": "sha512-ijDLlyQ7s6x1JgCLur53osjm/UXUYD9+0PbYKrBsYisYXzCxN+HC3mYDNy/dWdmf3AwqwU3CXwDCvsNgGK1S0w==", "dev": true, "optional": true, "requires": { @@ -2505,12 +2570,14 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true, + "resolved": false, + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "dev": true }, "yallist": { "version": "3.0.2", - "bundled": true, + "resolved": false, + "integrity": "sha1-hFK0u36Dx8GI2AQcGoN8dz1ti7k=", "dev": true } } @@ -2985,6 +3052,7 @@ "version": "1.3.1", "resolved": "https://registry.npmjs.org/io-ts/-/io-ts-1.3.1.tgz", "integrity": "sha512-PqTcX4ojXogRZRk86o7gltg9996DtKrxN2qjv9OOjBYHI0DSEJtwiJBoK682To1YE7ONNNaqwd9phN4WF3nomQ==", + "dev": true, "requires": { "fp-ts": "^1.0.0" } @@ -2993,6 +3061,7 @@ "version": "0.3.14", "resolved": "https://registry.npmjs.org/io-ts-types/-/io-ts-types-0.3.14.tgz", "integrity": "sha512-hEUo+VpS0EXLji14CON7f/ThuLMExaA5kWfW6LIM9gC+X/INTxwLt3GYKkKQc6Fx0snM9xt/QDXd5BPjeXE1RQ==", + "dev": true, "requires": { "fp-ts": "^1.0.0", "io-ts": "^1.1.4", @@ -3914,27 +3983,6 @@ "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", "dev": true }, - "micromatch": { - "version": "2.3.11", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-2.3.11.tgz", - "integrity": "sha1-hmd8l9FyCzY0MdBNDRUpO9OMFWU=", - "dev": true, - "requires": { - "arr-diff": "^2.0.0", - "array-unique": "^0.2.1", - "braces": "^1.8.2", - "expand-brackets": "^0.1.4", - "extglob": "^0.3.1", - "filename-regex": "^2.0.0", - "is-extglob": "^1.0.0", - "is-glob": "^2.0.1", - "kind-of": "^3.0.2", - "normalize-path": "^2.0.1", - "object.omit": "^2.0.0", - "parse-glob": "^3.0.4", - "regex-cache": "^0.4.2" - } - }, "strip-ansi": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", @@ -3966,29 +4014,6 @@ "jest-validate": "^23.6.0", "micromatch": "^2.3.11", "pretty-format": "^23.6.0" - }, - "dependencies": { - "micromatch": { - "version": "2.3.11", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-2.3.11.tgz", - "integrity": "sha1-hmd8l9FyCzY0MdBNDRUpO9OMFWU=", - "dev": true, - "requires": { - "arr-diff": "^2.0.0", - "array-unique": "^0.2.1", - "braces": "^1.8.2", - "expand-brackets": "^0.1.4", - "extglob": "^0.3.1", - "filename-regex": "^2.0.0", - "is-extglob": "^1.0.0", - "is-glob": "^2.0.1", - "kind-of": "^3.0.2", - "normalize-path": "^2.0.1", - "object.omit": "^2.0.0", - "parse-glob": "^3.0.4", - "regex-cache": "^0.4.2" - } - } } }, "jest-diff": { @@ -4070,27 +4095,6 @@ "requires": { "detect-newline": "^2.1.0" } - }, - "micromatch": { - "version": "2.3.11", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-2.3.11.tgz", - "integrity": "sha1-hmd8l9FyCzY0MdBNDRUpO9OMFWU=", - "dev": true, - "requires": { - "arr-diff": "^2.0.0", - "array-unique": "^0.2.1", - "braces": "^1.8.2", - "expand-brackets": "^0.1.4", - "extglob": "^0.3.1", - "filename-regex": "^2.0.0", - "is-extglob": "^1.0.0", - "is-glob": "^2.0.1", - "kind-of": "^3.0.2", - "normalize-path": "^2.0.1", - "object.omit": "^2.0.0", - "parse-glob": "^3.0.4", - "regex-cache": "^0.4.2" - } } } }, @@ -4145,29 +4149,6 @@ "micromatch": "^2.3.11", "slash": "^1.0.0", "stack-utils": "^1.0.1" - }, - "dependencies": { - "micromatch": { - "version": "2.3.11", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-2.3.11.tgz", - "integrity": "sha1-hmd8l9FyCzY0MdBNDRUpO9OMFWU=", - "dev": true, - "requires": { - "arr-diff": "^2.0.0", - "array-unique": "^0.2.1", - "braces": "^1.8.2", - "expand-brackets": "^0.1.4", - "extglob": "^0.3.1", - "filename-regex": "^2.0.0", - "is-extglob": "^1.0.0", - "is-glob": "^2.0.1", - "kind-of": "^3.0.2", - "normalize-path": "^2.0.1", - "object.omit": "^2.0.0", - "parse-glob": "^3.0.4", - "regex-cache": "^0.4.2" - } - } } }, "jest-mock": { @@ -4280,27 +4261,6 @@ "yargs": "^11.0.0" }, "dependencies": { - "micromatch": { - "version": "2.3.11", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-2.3.11.tgz", - "integrity": "sha1-hmd8l9FyCzY0MdBNDRUpO9OMFWU=", - "dev": true, - "requires": { - "arr-diff": "^2.0.0", - "array-unique": "^0.2.1", - "braces": "^1.8.2", - "expand-brackets": "^0.1.4", - "extglob": "^0.3.1", - "filename-regex": "^2.0.0", - "is-extglob": "^1.0.0", - "is-glob": "^2.0.1", - "kind-of": "^3.0.2", - "normalize-path": "^2.0.1", - "object.omit": "^2.0.0", - "parse-glob": "^3.0.4", - "regex-cache": "^0.4.2" - } - }, "strip-bom": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", @@ -4924,6 +4884,7 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/monocle-ts/-/monocle-ts-1.3.0.tgz", "integrity": "sha512-oQrsdhh8ut2zRljic2y6EjjWs/NsUj2vDpEY1tLTTo3jE9WS70JOO72HzOY0lWkmgDRsu29pvDbE1aBD8LBkOA==", + "dev": true, "requires": { "fp-ts": "^1.0.0" } @@ -4990,6 +4951,7 @@ "version": "0.2.1", "resolved": "https://registry.npmjs.org/newtype-ts/-/newtype-ts-0.2.1.tgz", "integrity": "sha512-Gnch+o9P/7RgKdkwx5mqWr3iR+Sxxvk2mykPaH93Y9WDhnVQ/ojdOoAGb9O/qHjnYMqJYW0xee9uNebdfpyCLg==", + "dev": true, "requires": { "fp-ts": "^1.0.0", "monocle-ts": "^1.0.0" @@ -6541,29 +6503,6 @@ "object-assign": "^4.1.0", "read-pkg-up": "^1.0.1", "require-main-filename": "^1.0.1" - }, - "dependencies": { - "micromatch": { - "version": "2.3.11", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-2.3.11.tgz", - "integrity": "sha1-hmd8l9FyCzY0MdBNDRUpO9OMFWU=", - "dev": true, - "requires": { - "arr-diff": "^2.0.0", - "array-unique": "^0.2.1", - "braces": "^1.8.2", - "expand-brackets": "^0.1.4", - "extglob": "^0.3.1", - "filename-regex": "^2.0.0", - "is-extglob": "^1.0.0", - "is-glob": "^2.0.1", - "kind-of": "^3.0.2", - "normalize-path": "^2.0.1", - "object.omit": "^2.0.0", - "parse-glob": "^3.0.4", - "regex-cache": "^0.4.2" - } - } } }, "text-extensions": { diff --git a/package.json b/package.json index 3464730..795579a 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "@devexperts/remote-data-ts", "version": "0.3.1", - "main": "dist/remote-data.js", - "typings": "dist/remote-data.d.ts", + "main": "dist/index.js", + "typings": "dist/index.d.ts", "scripts": { "build": "tsc", "test": "npm run tslint && npm run prettier && npm run jest", @@ -23,6 +23,8 @@ "fp-ts": "^1.2.0", "jest": "^22.4.2", "jest-cli": "^23.6.0", + "io-ts": "^1.3.1", + "io-ts-types": "^0.3.14", "prettier": "^1.10.2", "ts-jest": "^23.10.4", "tslib": "^1.9.0", @@ -33,11 +35,9 @@ }, "peerDependencies": { "fp-ts": "^1.2.0", - "tslib": "^1.9.0" - }, - "dependencies": { "io-ts": "^1.3.1", - "io-ts-types": "^0.3.14" + "io-ts-types": "^0.3.14", + "tslib": "^1.9.0" }, "repository": { "type": "git", diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..7fa10cb --- /dev/null +++ b/src/index.ts @@ -0,0 +1,2 @@ +export * from './io-ts'; +export * from './remote-data'; diff --git a/tsconfig.json b/tsconfig.json index cdfa170..db70e5e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,6 +2,7 @@ "compilerOptions": { "module": "commonjs", "target": "es5", + "lib": ["es6", "dom"], "outDir": "dist", "declaration": true, "strict": true, From db34964ea6c74a779a8dcbf82afc095c8ad80404 Mon Sep 17 00:00:00 2001 From: Malte Legenhausen Date: Mon, 29 Oct 2018 16:24:56 +0100 Subject: [PATCH 3/4] Changes from #20 integrated --- src/io-ts.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/io-ts.ts b/src/io-ts.ts index ba89d57..5c9945b 100644 --- a/src/io-ts.ts +++ b/src/io-ts.ts @@ -116,7 +116,7 @@ export function createRemoteDataFromJSON< a => a.foldL>( () => ({ type: 'Initial' }), - () => ({ type: 'Pending', progress: JSONProgress.encode((a as any).progress) }), + progress => ({ type: 'Pending', progress: JSONProgress.encode(progress) }), l => ({ type: 'Failure', error: leftType.encode(l) }), a => ({ type: 'Success', value: rightType.encode(a) }), ), From f2dea34791095f59463bbf44744ccda19263c66c Mon Sep 17 00:00:00 2001 From: Malte Legenhausen Date: Mon, 29 Oct 2018 16:59:17 +0100 Subject: [PATCH 4/4] io-ts.ts renamed to remote-data-io.ts --- .travis.yml | 1 - src/__tests__/{io-ts.spec.ts => remote-data-io.spec.ts} | 2 +- src/index.ts | 2 +- src/{io-ts.ts => remote-data-io.ts} | 0 4 files changed, 2 insertions(+), 3 deletions(-) rename src/__tests__/{io-ts.spec.ts => remote-data-io.spec.ts} (96%) rename src/{io-ts.ts => remote-data-io.ts} (100%) diff --git a/.travis.yml b/.travis.yml index 8948311..cfcfe83 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: node_js node_js: - "8" - - "10" script: - npm run test && npm run build diff --git a/src/__tests__/io-ts.spec.ts b/src/__tests__/remote-data-io.spec.ts similarity index 96% rename from src/__tests__/io-ts.spec.ts rename to src/__tests__/remote-data-io.spec.ts index a3fcc50..019470d 100644 --- a/src/__tests__/io-ts.spec.ts +++ b/src/__tests__/remote-data-io.spec.ts @@ -1,4 +1,4 @@ -import { createRemoteDataFromJSON } from '../io-ts'; +import { createRemoteDataFromJSON } from '../remote-data-io'; import * as t from 'io-ts'; import { initial, pending, failure, success, progress } from '../remote-data'; import { right } from 'fp-ts/lib/Either'; diff --git a/src/index.ts b/src/index.ts index 7fa10cb..e1e77c6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,2 @@ -export * from './io-ts'; export * from './remote-data'; +export * from './remote-data-io'; diff --git a/src/io-ts.ts b/src/remote-data-io.ts similarity index 100% rename from src/io-ts.ts rename to src/remote-data-io.ts