-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e7fefe0
Showing
14 changed files
with
256 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/bower_components/ | ||
/node_modules/ | ||
/.pulp-cache/ | ||
/output/ | ||
/generated-docs/ | ||
/.psc-package/ | ||
/.psc* | ||
/.purs* | ||
/.psa* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Awake Security | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# purescript-web-streams |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "purescript-web-streams", | ||
"homepage": "https://github.com/purescript-web/purescript-web-streams", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/purescript-web/purescript-web-streams.git" | ||
}, | ||
"ignore": [ | ||
"**/.*", | ||
"bower_components", | ||
"node_modules", | ||
"output", | ||
"bower.json", | ||
"package.json" | ||
], | ||
"dependencies": { | ||
"purescript-prelude": "^4.0.0", | ||
"purescript-effect": "^2.0.0", | ||
"purescript-nullable": "^4.0.0", | ||
"purescript-arraybuffer-types": "^2.0.0", | ||
"purescript-tuples": "^5.0.0", | ||
"purescript-web-promise": "https://github.com/purescript-web/purescript-web-promise.git#^1.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
exports.new = function(options) { | ||
return function() { | ||
return new QueuingStrategy(options); | ||
}; | ||
}; | ||
|
||
exports.byteLengthQueuingStrategy = function(options) { | ||
return function() { | ||
return new ByteLengthQueuingStrategy(options); | ||
}; | ||
}; | ||
|
||
exports.countQueuingStrategy = function(options) { | ||
return function() { | ||
return new CountQueuingStrategy(options); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Web.Streams.QueuingStrategy where | ||
|
||
import Data.ArrayBuffer.Types (Uint8Array) | ||
import Effect (Effect) | ||
|
||
foreign import data QueuingStrategy :: Type -> Type | ||
|
||
foreign import new :: forall chunk. { size :: chunk -> Int, highWaterMark :: Int } -> Effect (QueuingStrategy chunk) | ||
|
||
foreign import byteLengthQueuingStrategy :: { highWaterMark :: Int } -> Effect (QueuingStrategy Uint8Array) | ||
|
||
foreign import countQueuingStrategy :: forall a. { highWaterMark :: Int } -> Effect (QueuingStrategy a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
exports._new = function(source, strategy) { | ||
return new ReadableStream(source, strategy); | ||
}; | ||
|
||
exports.cancel = function(stream) { | ||
return function() { | ||
return stream.cancel(); | ||
}; | ||
}; | ||
|
||
exports.locked = function(stream) { | ||
return function() { | ||
return stream.locked; | ||
}; | ||
}; | ||
|
||
exports.getReader = function(stream) { | ||
return function() { | ||
return stream.getReader(); | ||
}; | ||
}; | ||
|
||
exports._tee = function(tuple, stream) { | ||
var r = stream.tee(); | ||
return tuple(r[0])(r[1]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Web.Streams.ReadableStream | ||
( ReadableStream | ||
, new | ||
, cancel | ||
, locked | ||
, getReader | ||
, tee | ||
) where | ||
|
||
import Data.Maybe (Maybe) | ||
import Data.Nullable (Nullable, toNullable) | ||
import Data.Tuple (Tuple(..)) | ||
import Effect (Effect) | ||
import Effect.Uncurried (EffectFn2, runEffectFn2) | ||
import Prelude (Unit) | ||
import Web.Promise (Promise) | ||
import Web.Streams.QueuingStrategy (QueuingStrategy) | ||
import Web.Streams.Reader (Reader) | ||
import Web.Streams.Source (Source) | ||
|
||
foreign import data ReadableStream :: Type -> Type | ||
|
||
foreign import _new :: forall chunk. EffectFn2 (Source chunk) (Nullable (QueuingStrategy chunk)) (ReadableStream chunk) | ||
|
||
foreign import cancel :: forall chunk. ReadableStream chunk -> Effect (Promise Unit) | ||
|
||
foreign import locked :: forall chunk. ReadableStream chunk -> Effect Boolean | ||
|
||
foreign import getReader :: forall chunk. ReadableStream chunk -> Effect (Reader chunk) | ||
|
||
foreign import _tee :: forall chunk. EffectFn2 (forall a b. a -> b -> Tuple a b) (ReadableStream chunk) (Tuple (ReadableStream chunk) (ReadableStream chunk)) | ||
|
||
new :: forall chunk. Source chunk -> Maybe (QueuingStrategy chunk) -> Effect (ReadableStream chunk) | ||
new source strategy = runEffectFn2 _new source (toNullable strategy) | ||
|
||
tee :: forall chunk. ReadableStream chunk -> Effect (Tuple (ReadableStream chunk) (ReadableStream chunk)) | ||
tee = runEffectFn2 _tee Tuple |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
exports.enqueue = function(chunk) { | ||
return function(controller) { | ||
return function() { | ||
return controller.enqueue(chunk); | ||
}; | ||
}; | ||
}; | ||
|
||
exports.close = function(controller) { | ||
return function() { | ||
return controller.close(); | ||
}; | ||
}; | ||
|
||
exports.error = function(error) { | ||
return function(controller) { | ||
return function() { | ||
return controller.error(error); | ||
}; | ||
}; | ||
}; | ||
|
||
exports.desiredSize = function(controller) { | ||
return function() { | ||
return controller.desiredSize; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Web.Streams.ReadableStreamController where | ||
|
||
import Effect (Effect) | ||
import Error (Error) | ||
import Prelude (Unit) | ||
|
||
foreign import data ReadableStreamController :: Type -> Type | ||
|
||
foreign import enqueue :: forall chunk. chunk -> ReadableStreamController chunk -> Effect Unit | ||
|
||
foreign import close :: forall chunk. ReadableStreamController chunk -> Effect Unit | ||
|
||
foreign import error :: forall chunk. Error -> ReadableStreamController chunk -> Effect Unit | ||
|
||
foreign import desiredSize :: forall chunk. ReadableStreamController chunk -> Effect Int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
exports._read = function(nothing, just, reader) { | ||
return reader.read().then(function(res) { | ||
if (res.done) { | ||
return nothing; | ||
} | ||
return just(res.value); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Web.Streams.Reader where | ||
|
||
import Data.Maybe (Maybe(..)) | ||
import Effect (Effect) | ||
import Effect.Uncurried (EffectFn3, runEffectFn3) | ||
import Web.Promise (Promise) | ||
|
||
foreign import data Reader :: Type -> Type | ||
|
||
foreign import _read :: forall chunk. EffectFn3 (forall a. Maybe a) (forall a. a -> Maybe a) (Reader chunk) (Promise (Maybe chunk)) | ||
|
||
read :: forall chunk. Reader chunk -> Effect (Promise (Maybe chunk)) | ||
read = runEffectFn3 _read Nothing Just |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
exports._make = function(options) { | ||
var newOptions = { | ||
start: function(controller) { | ||
return options.start(controller)(); | ||
} | ||
}; | ||
if (options.pull) { | ||
newOptions.pull = function(controller) { | ||
return options.pull(controller)(); | ||
}; | ||
} | ||
if (options.cancel) { | ||
newOptions.cancel = function() { | ||
return options.cancel(); | ||
}; | ||
} | ||
return newOptions; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Web.Streams.Source | ||
( Source | ||
, make | ||
) where | ||
|
||
import Effect (Effect) | ||
import Prelude (Unit) | ||
import Prim.Row as Row | ||
import Web.Promise (Promise) | ||
import Web.Streams.ReadableStreamController (ReadableStreamController) | ||
|
||
foreign import data Source :: Type -> Type | ||
|
||
type Required chunk r = | ||
( start :: ReadableStreamController chunk -> Effect (Promise Unit) | ||
| r | ||
) | ||
|
||
type Optional chunk = | ||
( pull :: ReadableStreamController chunk -> Effect (Promise Unit) | ||
, cancel :: Effect (Promise Unit) | ||
) | ||
|
||
foreign import _make :: forall r chunk. { | r } -> Source chunk | ||
|
||
make :: forall r rx chunk. Row.Union r rx (Optional chunk) => { | Required chunk r } -> Source chunk | ||
make = _make |