@magnetarjs/core
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -723,2 +723,7 @@ 'use strict'; | ||
throwOnIncompleteStreamResponses(streamInfoPerStore, doOnStreamFns); | ||
// create a function to closeStream from the stream of each store | ||
const closeStream = () => { | ||
Object.values(streamInfoPerStore).forEach(({ stop }) => stop()); | ||
cacheStream(() => { }, null); | ||
}; | ||
// handle caching the returned promises | ||
@@ -729,11 +734,11 @@ const streamPromises = Object.values(streamInfoPerStore).map((res) => res.streaming); | ||
Promise.all(streamPromises) | ||
// todo: why can I not just write then(resolve) | ||
.then(() => resolve()) | ||
.catch(reject); | ||
.then(() => { | ||
resolve(); | ||
closeStream(); | ||
}) | ||
.catch((e) => { | ||
reject(e); | ||
closeStream(); | ||
}); | ||
}); | ||
// create a function to closeStream from the stream of each store | ||
const closeStream = () => { | ||
Object.values(streamInfoPerStore).forEach(({ stop }) => stop()); | ||
cacheStream(() => { }, null); | ||
}; | ||
cacheStream(closeStream, streamPromise); | ||
@@ -740,0 +745,0 @@ // return the stream promise |
@@ -719,2 +719,7 @@ import { merge, mergeAndConcat } from 'merge-anything'; | ||
throwOnIncompleteStreamResponses(streamInfoPerStore, doOnStreamFns); | ||
// create a function to closeStream from the stream of each store | ||
const closeStream = () => { | ||
Object.values(streamInfoPerStore).forEach(({ stop }) => stop()); | ||
cacheStream(() => { }, null); | ||
}; | ||
// handle caching the returned promises | ||
@@ -725,11 +730,11 @@ const streamPromises = Object.values(streamInfoPerStore).map((res) => res.streaming); | ||
Promise.all(streamPromises) | ||
// todo: why can I not just write then(resolve) | ||
.then(() => resolve()) | ||
.catch(reject); | ||
.then(() => { | ||
resolve(); | ||
closeStream(); | ||
}) | ||
.catch((e) => { | ||
reject(e); | ||
closeStream(); | ||
}); | ||
}); | ||
// create a function to closeStream from the stream of each store | ||
const closeStream = () => { | ||
Object.values(streamInfoPerStore).forEach(({ stop }) => stop()); | ||
cacheStream(() => { }, null); | ||
}; | ||
cacheStream(closeStream, streamPromise); | ||
@@ -736,0 +741,0 @@ // return the stream promise |
{ | ||
"name": "@magnetarjs/core", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"sideEffects": false, | ||
@@ -26,3 +26,3 @@ "description": "Magnetar core library.", | ||
"devDependencies": { | ||
"@magnetarjs/test-utils": "^0.1.14" | ||
"@magnetarjs/test-utils": "^0.1.15" | ||
}, | ||
@@ -70,3 +70,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "fde13d32215c919424b19af838ed89a4c00255b7" | ||
"gitHead": "72bec5a9d9b395dbbafef6f9d732c60f6ed69d20" | ||
} |
@@ -165,2 +165,7 @@ import { O } from 'ts-toolbelt' | ||
// create a function to closeStream from the stream of each store | ||
const closeStream = (): void => { | ||
Object.values(streamInfoPerStore).forEach(({ stop }) => stop()) | ||
cacheStream(() => {}, null) | ||
} | ||
// handle caching the returned promises | ||
@@ -171,11 +176,11 @@ const streamPromises = Object.values(streamInfoPerStore).map((res) => res.streaming) | ||
Promise.all(streamPromises) | ||
// todo: why can I not just write then(resolve) | ||
.then(() => resolve()) | ||
.catch(reject) | ||
.then(() => { | ||
resolve() | ||
closeStream() | ||
}) | ||
.catch((e) => { | ||
reject(e) | ||
closeStream() | ||
}) | ||
}) | ||
// create a function to closeStream from the stream of each store | ||
const closeStream = (): void => { | ||
Object.values(streamInfoPerStore).forEach(({ stop }) => stop()) | ||
cacheStream(() => {}, null) | ||
} | ||
cacheStream(closeStream, streamPromise) | ||
@@ -182,0 +187,0 @@ // return the stream promise |
@@ -20,3 +20,3 @@ import { pokedex } from '@magnetarjs/test-utils' | ||
const { pokedexModule } = createMagnetarInstance() | ||
t.is(pokedexModule.data.size, 1) | ||
t.deepEqual(pokedexModule.data.size, 1) | ||
t.deepEqual(pokedexModule.data.get('1'), pokedex(1)) | ||
@@ -29,3 +29,3 @@ | ||
} | ||
t.is(pokedexModule.data.size, 0) | ||
t.deepEqual(pokedexModule.data.size, 0) | ||
t.deepEqual(pokedexModule.data.get('1'), undefined) | ||
@@ -32,0 +32,0 @@ }) |
@@ -10,3 +10,3 @@ import test from 'ava' | ||
t.deepEqual(pokedexModule.doc('136').data, undefined) | ||
t.is(pokedexModule.data.size, 1) | ||
t.deepEqual(pokedexModule.data.size, 1) | ||
@@ -20,3 +20,3 @@ try { | ||
t.deepEqual(pokedexModule.doc('136').data, pokedex(136)) | ||
t.is(pokedexModule.data.size, 151) | ||
t.deepEqual(pokedexModule.data.size, 151) | ||
}) | ||
@@ -23,0 +23,0 @@ |
@@ -9,3 +9,3 @@ import test from 'ava' | ||
t.deepEqual(pokedexModule.data.get('1'), pokedex(1)) | ||
t.is(pokedexModule.data.size, 1) | ||
t.deepEqual(pokedexModule.data.size, 1) | ||
t.deepEqual(pokedexModule.streaming(), null) | ||
@@ -30,5 +30,5 @@ | ||
t.deepEqual(pokedexModule.data.get('3'), pokedex(3)) | ||
t.is(pokedexModule.data.size, 3) | ||
t.deepEqual(pokedexModule.data.size, 3) | ||
await waitMs(1000) | ||
t.is(pokedexModule.data.size, 3) | ||
t.deepEqual(pokedexModule.data.size, 3) | ||
// '4': charmander should come in next, but doesn't because we closed the stream | ||
@@ -65,3 +65,3 @@ }) | ||
// the original state has 1 Pokemon already | ||
t.is(pokedexModule.data.size, 1) | ||
t.deepEqual(pokedexModule.data.size, 1) | ||
// let's get some more | ||
@@ -89,3 +89,3 @@ const pokedexModuleWithQuery = pokedexModule | ||
// the main instance has one Pokemon from the beginning | ||
t.is(pokedexModule.data.size, 4) | ||
t.deepEqual(pokedexModule.data.size, 4) | ||
}) | ||
@@ -92,0 +92,0 @@ |
@@ -110,3 +110,3 @@ import test from 'ava' | ||
t.deepEqual(pokedexModule.data.get('1'), pokedex(1)) | ||
t.is(pokedexModule.data.size, 1) | ||
t.deepEqual(pokedexModule.data.size, 1) | ||
try { | ||
@@ -121,3 +121,3 @@ const result = await pokedexModule.fetch({ force: true }) | ||
t.deepEqual(pokedexModule.data.get('136'), pokedex(136)) | ||
t.is(pokedexModule.data.size, 151) | ||
t.deepEqual(pokedexModule.data.size, 151) | ||
}) | ||
@@ -124,0 +124,0 @@ |
@@ -26,3 +26,3 @@ import test from 'ava' | ||
} | ||
t.is(pokedexModule.data.get('testid'), undefined) | ||
t.deepEqual(pokedexModule.data.get('testid'), undefined) | ||
}) | ||
@@ -74,3 +74,3 @@ | ||
} | ||
t.is(pokedexModule.data.get('testid'), undefined) | ||
t.deepEqual(pokedexModule.data.get('testid'), undefined) | ||
}) | ||
@@ -87,3 +87,3 @@ | ||
if (storeName === 'local') { | ||
t.is(actionName, 'insert') | ||
t.deepEqual(actionName, 'insert') | ||
} | ||
@@ -105,3 +105,3 @@ }, | ||
} | ||
t.is(pokedexModule.data.get('testid'), undefined) | ||
t.deepEqual(pokedexModule.data.get('testid'), undefined) | ||
}) | ||
@@ -134,3 +134,3 @@ | ||
} | ||
t.is(pokedexModule.data.get('testid'), undefined) | ||
t.deepEqual(pokedexModule.data.get('testid'), undefined) | ||
}) | ||
@@ -137,0 +137,0 @@ |
@@ -20,3 +20,3 @@ import test from 'ava' | ||
}) | ||
t.is(ranAllEvents.length, 4) | ||
t.deepEqual(ranAllEvents.length, 4) | ||
}) | ||
@@ -52,3 +52,3 @@ | ||
}) | ||
t.is(ranAllEvents.length, 4) | ||
t.deepEqual(ranAllEvents.length, 4) | ||
}) | ||
@@ -107,3 +107,3 @@ | ||
} | ||
t.is(ranAllEvents.length, 2) | ||
t.deepEqual(ranAllEvents.length, 2) | ||
}) |
@@ -9,3 +9,3 @@ import test from 'ava' | ||
t.deepEqual(pokedexModule.data.get('1'), pokedex(1)) | ||
t.is(pokedexModule.data.size, 1) | ||
t.deepEqual(pokedexModule.data.size, 1) | ||
try { | ||
@@ -20,3 +20,3 @@ const result = await pokedexModule.fetch({ force: true }) | ||
t.deepEqual(pokedexModule.data.get('136'), pokedex(136)) | ||
t.is(pokedexModule.data.size, 151) | ||
t.deepEqual(pokedexModule.data.size, 151) | ||
}) | ||
@@ -36,3 +36,3 @@ | ||
} catch (error) { | ||
t.is(!!error, true) | ||
t.deepEqual(!!error, true) | ||
} | ||
@@ -62,3 +62,3 @@ t.deepEqual(pokedexModule.data.get('135'), pokedex(135)) | ||
// make sure the remote store was only triggered once | ||
t.is(storeNames.filter((n) => n === 'remote').length, 1) | ||
t.deepEqual(storeNames.filter((n) => n === 'remote').length, 1) | ||
@@ -73,3 +73,3 @@ try { | ||
// make sure the remote store was only triggered once more | ||
t.is(storeNames.filter((n) => n === 'remote').length, 2) | ||
t.deepEqual(storeNames.filter((n) => n === 'remote').length, 2) | ||
@@ -101,3 +101,3 @@ t.deepEqual(trainerModule.data, { name: 'Luca', age: 10, dream: 'job' }) | ||
// make sure the remote store was only triggered once | ||
t.is(storeNames.filter((n) => n === 'remote').length, 1) | ||
t.deepEqual(storeNames.filter((n) => n === 'remote').length, 1) | ||
@@ -112,5 +112,5 @@ try { | ||
// make sure the remote store was not triggered again | ||
t.is(storeNames.filter((n) => n === 'remote').length, 1) | ||
t.deepEqual(storeNames.filter((n) => n === 'remote').length, 1) | ||
t.deepEqual(trainerModule.data, { name: 'Luca', age: 10, dream: 'job' }) | ||
}) |
@@ -9,3 +9,3 @@ import test from 'ava' | ||
t.deepEqual(pokedexModule.data.get('1'), pokedex(1)) | ||
t.is(pokedexModule.data.size, 1) | ||
t.deepEqual(pokedexModule.data.size, 1) | ||
// do not await, because it only resolves when the stream is closed | ||
@@ -20,5 +20,5 @@ pokedexModule.stream().catch((e: any) => t.fail(e.message)) // prettier-ignore | ||
t.deepEqual(pokedexModule.data.get('3'), pokedex(3)) | ||
t.is(pokedexModule.data.size, 3) | ||
t.deepEqual(pokedexModule.data.size, 3) | ||
await waitMs(1000) | ||
t.is(pokedexModule.data.size, 3) | ||
t.deepEqual(pokedexModule.data.size, 3) | ||
// '4': charmander should come in next, but doesn't because we closed the stream | ||
@@ -110,3 +110,3 @@ }) | ||
// t.deepEqual(pokedexModule.data.get('1'), pokedex(1)) | ||
// t.is(pokedexModule.data.size, 1) | ||
// t.deepEqual(pokedexModule.data.size, 1) | ||
// pokedexModule.doc('1').merge({ name: 'B' }) | ||
@@ -139,1 +139,33 @@ // pokedexModule.stream().catch((e: any) => t.fail(e.message)) // prettier-ignore | ||
}) | ||
test('stream should throw', async (t) => { | ||
const { pokedexModule } = createMagnetarInstance() | ||
t.deepEqual(pokedexModule.data.get('1'), pokedex(1)) | ||
t.deepEqual(pokedexModule.data.size, 1) | ||
try { | ||
// we expect this to fail, so we can await the throw | ||
await pokedexModule.stream({ shouldFail: 'remote' }) | ||
} catch (e: any) { | ||
t.deepEqual(e.message, 'failed') | ||
} | ||
}) | ||
test('stream should not throw again after throwing once', async (t) => { | ||
const { pokedexModule } = createMagnetarInstance() | ||
t.deepEqual(pokedexModule.data.size, 1) | ||
try { | ||
// we expect this to fail, so we can await the throw | ||
await pokedexModule.stream({ shouldFail: 'remote' }) | ||
} catch (e: any) { | ||
t.deepEqual(e.message, 'failed') | ||
} | ||
// the second time around the stream should NOT fail and open correctly | ||
t.deepEqual(pokedexModule.data.size, 1) | ||
// we expect this NOT to fail!!! | ||
const streaming = pokedexModule.stream() | ||
streaming.catch((e) => (t.fail(e.message))) | ||
await waitMs(600) | ||
// close the stream: | ||
pokedexModule.closeStream() | ||
t.deepEqual(pokedexModule.data.size, 3) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
301861
6950