protean

An ever changing set of utilities.

Usage no npm install needed!

<script type="module">
  import protean from 'https://cdn.skypack.dev/protean';
</script>

README

Protean

An ever changing set of utilities.

Summary

Installation

% npm install protean

API

Modules

Protean
Falcor
## Classes
CollectionSourceProteanClass
CompositeSourceProteanClass
JSONGraphEnvelopeProxyProteanClass
NoCacheSourceProteanClass
PartitionedSourceProteanClass
ProxiedSourceProteanClass
StorageSourceProteanClass
ProteanClass : function
StorageProteanClass
StoreProteanClass
CollectionProteanClass
FiniteStateMachineSubject
LinkedListProteanClass
RecordProteanClass
## Typedefs
onNextFunction : function
onErrorFunction : function
onCompletedFunction : function
Observable
Observer
Disposable
SubjectObservable
DataSource
Sentinel : Object
Reference : Sentinel
RootReference : Reference
Atom : Sentinel
JSONEnvelope : Object
JSONGraph : Object
JSONGraphEnvelope : Object
Key : String | null
KeySet : Key | Range | Array.<(Key|Range)>
Path : Array.<Key>
PathSet : Array.<KeySet>
PathValue : Object
Range : Object
## Protean

Protean.Rx

Kind: static property of Protean

Rx.append ⇒ Observable.<String>

Kind: static property of Rx

Param Type
filepath String
data Buffer | String
[opts] Object | String

Rx.mv ⇒ Observable.<String>

File: rx/fs/mv.js

Kind: static property of Rx

Param Type Default
from String
to String
opts Object
[opts.mkdirp] Boolean false
[opts.clobber] Boolean false

Rx.fsWrapper ⇒ function

Kind: static property of Rx

Param Type
method String

Rx.write ⇒ Observable.<String>

Kind: static property of Rx

Param Type
filepath String
data Buffer | String
[opts] Object | String

Rx.from(arg) ⇒ Observable

File: rx/from.js

Kind: static method of Rx

Param Type
arg Observable | Promise | Array | Object

Rx.cp(from, to, [opts]) ⇒ Observable.<fs.Stats>

File: rx/fs/cp.js

Kind: static method of Rx

Param Type Default
from String | Array.<String> | Observable.<String> | Promise.<String>
to String
[opts] Object
[opts.recursive] Boolean true
[opts.force] Boolean false

Rx.glob(pattern, [opts]) ⇒ Observable.<String>

File: rx/glob.js

Kind: static method of Rx
Returns: Observable.<String> - An Observable emiting the paths found

Param Type Description
pattern String The glob pattern
[opts] Object https://github.com/isaacs/node-glob#options

Rx.isDirectory(paths) ⇒ Observable.<Boolean>

File: rx/is-directory.js

Kind: static method of Rx
Returns: Observable.<Boolean> - An Observable emiting the paths found

Param Type
paths String | Array.<String> | Observable.<String>

Rx.isFile(paths) ⇒ Observable.<Boolean>

File: rx/is-file.js

Kind: static method of Rx

Param Type
paths String | Array.<String> | Observable.<String>

Rx.mkdir(paths, [opts]) ⇒ Observable.<String>

Create the given paths in the file system.

File: rx/mkdir.js

Kind: static method of Rx

Param Type Default
paths String | Array.<String> | Observable.<String>
[opts] Object
[opts.mode] String '0777'

Rx.read(patterns, [enc]) ⇒ Observable.<(String|Buffer)>

File: rx/read.js

Kind: static method of Rx

Param Type
patterns String | Array.<String> | Observable.<String> | Promise.<String>
[enc] String

Rx.rm(patterns, [recursive]) ⇒ Observable.<String>

File: rx/rm.js

Kind: static method of Rx

Param Type Default
patterns String | Array.<String> | Observable.<String> | Promise.<String>
[recursive] Boolean true

Rx.stat(patterns) ⇒ Observable.<external:fs.Stats>

File: rx/stat.js

Kind: static method of Rx
Returns: Observable.<external:fs.Stats> - An Observable emiting the paths found

Param Type
patterns String | Array.<String> | Observable.<String> | Promise.<String>

stat.link(patterns) ⇒ Observable.<external:fs.Stats>

Kind: static method of stat

Param Type
patterns String | Array.<String> | Observable.<String> | Promise.<String>

stat.fd(fds) ⇒ Observable.<external:fs.Stats>

Kind: static method of stat

Param Type
fds Integer | Array.<Integer> | Observable.<Integer> | Promise.<Integer>

Protean.denominate ⇒ Object

Kind: static property of Protean
Returns: Object - The object now with a immutable 'name' property of the given name value

Param Type
obj Object
name String

Protean.invoke ⇒ *

Kind: static property of Protean

Param Type
property String
subject Object

Protean.pluck ⇒ * | function

File: object/pluck.js

Kind: static property of Protean

Param Type
key String
[obj] Object

Protean.classnames(arg) ⇒ String

Utility function to get a className string.

Supply a list of strings, or objects with class names -> boolean indicating whether that class should be used. The returned string will contain all the class names indicated without duplicates, and separated by spaces.

File: dom/classnames.js

Kind: static method of Protean

Param Type
arg String | Object.<String, Boolean>

Protean.classify([subclass], props, [properties]) ⇒ ProteanClass

Create a constructor function passing in it's prototype methods.

File: function/classify

Kind: static method of Protean

Param Type Description
[subclass] function The subclass constructor function.
props Object Bare properties for the constructor's prototype.
[properties] Object Object.defineProperty property definitions.

Protean.inherit(superclass, [subclass], [props], [properties]) ⇒ ProteanClass

Create a constructor function that inherits properties and methods from the given super constructor.

File: function/inherit.js

Kind: static method of Protean
Returns: ProteanClass - The constructor function.

Param Type Default Description
superclass function The function to inherit from.
[subclass] function Function The Subclass constructor function. If omitted, and a constructor property is not defined in props, defaults to a function that calls the superclass' constructor function.
[props] Object Bare properties to initialize the prototype with.
[properties] Object {} Object.defineProperty property definitions.

Protean.instantiate(fn, [args]) ⇒ Object

Create a new object and then apply the constructor function with the arguments.

File: function/instantiate.js

Kind: static method of Protean
Returns: Object - The new instance

Param Type Description
fn function The constructor function
[args] Array.<Mixed> Arguments to pass to the constructor function

Protean.augment(...obj) ⇒ Object

Like 'extend', but it preserves getters and setters, and will not overwrite existing properties defined directly on the source object.

File: object/augment.js

Kind: static method of Protean

Param Type
...obj Object

Protean.enmap(...args) ⇒ Object

Takes a list of alternating key/values and returns an object.

File: object/enmap.js

Kind: static method of Protean

Param Type
...args Mixed

Protean.enumerate() ⇒ Object

Takes an argument list of strings and returns an object with those keys, and their values being the index of that key plus one.

File: object/enumerate.js

Kind: static method of Protean

Type
String

Protean.traverse(obj, visitor, [post])

Kind: static method of Protean

Param Type Default Description
obj Object
visitor visitorFn
[post] Boolean false Do a post traversal

traverse.SKIP : String

Kind: static constant of traverse

traverse.CONTINUE : String

Kind: static constant of traverse

traverse.BREAK : String

Kind: static constant of traverse

traverse~visitorFn(path, value, context) ⇒ undefined | String

File: object/traverse.js

Kind: inner method of traverse
Returns: undefined | String - One of the constants of 'skip', 'continue', or 'break'. Returning undefined is the same as returing 'continue'.

Param Type Description
path Array.<String> The path to the value
value Mixed The value
context Object The original object

Protean.guid() ⇒ String

Fast GUID generator, RFC4122 version 4 compliant.

File: utility/guid.js

Kind: static method of Protean
See: http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
Author: Jeff Ward (jcward.com).
License: MIT license

Protean.mergeExports(receiver, supplier) ⇒ Object

File: utility/merge-exports.js

Kind: static method of Protean

Param Type
receiver Object
supplier function | Object

Falcor

Falcor.Graph

File: falcor/graph.js

Kind: static property of Falcor
See: https://github.com/Netflix/falcor-json-graph

Graph.set ⇒ Object

File: falcor/graph/set.js

Kind: static property of Graph

Param Type
source Object
path String | Array.<String>
value *

Graph.atoms(graph, fn)

File: falcor/graph/atoms.js

Kind: static method of Graph

Param Type
graph JSONGraph
fn Graph.atoms~visitorFn

atoms~visitorFn(path, atom, graph)

Kind: inner method of atoms

Param Type
path Path
atom Atom
graph JSONGraph

Graph.fromObject(obj, [opts]) ⇒ JSONGraph

Takes a normal javascript object and returns a JSONGraph.

File: falcor/graph/from-object.js

Kind: static method of Graph

Param Type Default
obj Object
[opts] Object
[opts.arrayIsRef] Boolean true
[opts.root] Path []

Graph.isAtom(sentinel) ⇒ Boolean

File: falcor/graph/is-atom.js

Kind: static method of Graph

Param Type
sentinel *

Graph.isError(sentinel) ⇒ Boolean

File: falcor/graph/is-error.js

Kind: static method of Graph

Param Type
sentinel *

Graph.isRef(sentinel) ⇒ Boolean

File: falcor/graph/is-ref.js

Kind: static method of Graph

Param Type
sentinel *

Graph.isRootRef(sentinel) ⇒ Boolean

File: falcor/graph/is-root-ref.js

Kind: static method of Graph

Param Type
sentinel *

Graph.isSentinel(sentinel) ⇒ Boolean

File: falcor/graph/is-sentinel.js

Kind: static method of Graph

Param Type
sentinel *

Graph.refs(graph, fn)

File: falcor/graph/refs.js

Kind: static method of Graph

Param Type
graph JSONGraph
fn Graph.atoms~visitorFn

refs~visitorFn(path, ref, graph)

Kind: inner method of refs

Param Type
path Path
ref Reference
graph JSONGraph

Graph.relative(root, graph) ⇒ JSONGraph

File: falcor/graph/relative.js

Kind: static method of Graph

Param Type
root Path
graph JSONGraph

Graph.resolve(root, graph) ⇒ JSONGraph

File: falcor/graph/resolve.js

Kind: static method of Graph

Param Type
root Path
graph JSONGraph

Graph.rootRef(path, value, props) ⇒ Reference

File: falcor/graph/root-ref.js

Kind: static method of Graph

Param Type
path Path
value Path
props Object

Graph.sentinels(graph, fn)

File: falcor/graph/sentinels.js

Kind: static method of Graph

Param Type
graph JSONGraph
fn Graph.sentinels~visitorFn

sentinels~visitorFn(path, sentinel, graph)

Kind: inner method of sentinels

Param Type
path Path
sentinel Sentinel
graph JSONGraph

Graph.toObject(graph, [opts]) ⇒ JSONGraph

Takes a JSONGraph and returns a Javascript Object.

File: falcor/graph/to-object.js

Kind: static method of Graph

Param Type
graph JSONGraph
[opts] Object

Falcor.Path

Kind: static property of Falcor
See: https://github.com/Netflix/falcor-path-utils

Path.relative(root, paths) ⇒ Array.<PathSet>

File: falcor/path/relative.js

Kind: static method of Path

Param Type
root Path
paths Array.<PathSet>

Path.resolve(root, paths) ⇒ Array.<PathSet>

File: falcor/path/resolve.js

Kind: static method of Path

Param Type
root Path
paths Array.<PathSet>

CollectionSource ⇐ ProteanClass

Kind: global class
Extends: ProteanClass
Implements: DataSource

new CollectionSource([collection], [opts])

file: falcor/data-source/collection.js

Param Type Default
[collection] Collection
[opts] Object
[opts.indexedPath] Path ['byIndex']
[opts.keyedPath] Path ['byId']

collectionSource.options

Default options

Kind: instance property of CollectionSource
Properties

Type
Object

options.indexedPath

Kind: static property of options
Properties

Type
Path

options.keyedPath

Kind: static property of options
Properties

Type
Path

options.lengthPath

Kind: static property of options
Properties

Type
Path

options.addPath

Kind: static property of options
Properties

Type
Path

options.removePath

Kind: static property of options
Properties

Type
Path

collectionSource.router

Kind: instance property of CollectionSource
See: http://netflix.github.io/falcor/documentation/router.html
Properties

Type
external:FalcorRouter

collectionSource.routes

Kind: instance property of CollectionSource
Properties

Type
Array.<Object>

collectionSource.get(paths) ⇒ Observable.<JSONGraphEnvelope>

Kind: instance method of CollectionSource
Implements: get

Param Type
paths Array.<PathSet>

collectionSource.set(envelope) ⇒ Observable.<JSONGraphEnvelope>

Kind: instance method of CollectionSource
Implements: set

Param Type
envelope JSONGraphEnvelope

collectionSource.call(path, args, refSuffixes, thisPaths) ⇒ Observable.<JSONGraphEnvelope>

Kind: instance method of CollectionSource
Implements: call

Param Type
path PathSet
args Array.<Mixed>
refSuffixes Array.<PathSet>
thisPaths Array.<PathSet>

collectionSource.getLength() ⇒ Observable.<JSONGraphEnvelope>

Kind: instance method of CollectionSource

collectionSource.getRecordByIndex(paths) ⇒ Observable.<JSONGraphEnvelope>

Kind: instance method of CollectionSource

Param Type
paths Array.<PathSets>

collectionSource.getRecordProps(paths) ⇒ Observable.<JSONGraphEnvelope>

Kind: instance method of CollectionSource

Param Type
paths Array.<PathSets>

collectionSource.setRecordProps(graph) ⇒ Observable.<JSONGraphEnvelope>

Kind: instance method of CollectionSource

Param Type
graph JSONGraph

collectionSource.addRecord(path, args, refSuffixes, thisPaths) ⇒ Observable.<JSONGraphEnvelope>

Kind: instance method of CollectionSource

Param Type
path PathSet
args Array.<Mixed>
refSuffixes Array.<PathSet>
thisPaths Array.<PathSet>

collectionSource.removeRecord(path, args, refSuffixes, thisPaths) ⇒ Observable.<JSONGraphEnvelope>

Kind: instance method of CollectionSource

Param Type
path PathSet
args Array.<Mixed>
refSuffixes Array.<PathSet>
thisPaths Array.<PathSet>

CompositeSource ⇐ ProteanClass

Kind: global class
Extends: ProteanClass
Implements: DataSource

new CompositeSource(...args)

A DataSource that allows for composing several different DataSources together through different Paths.

This allows individual DataSources to be constructed, used, and tested in their own domain. Then later you can compose them into a larger Graph.

The CompositeSource manages the re-writing of Paths and the resulting Graph so it appears that everything comes from a larger Graph.

Basically, all returned Paths/Graphs are updated to have any references relative to their Paths in the CompositeSource.

As a result, there was a need to create a new Falcor data type to express when a sub DataSource wanted to reference another part of the larger Graph. RootReference represents a Reference in the Graph that should not be kept local to the underlying DataSource, but should be interpreted from the root of the CompositeSource.

File: falcor/data-source/composite.js

Param Type
...args Array.<Path, DataSource>

compositeSource.sources

Kind: instance property of CompositeSource
Properties

Type
Object.<Path, ProxiedSource>

compositeSource.get(paths) ⇒ Observable.<JSONGraphEnvelope>

Kind: instance method of CompositeSource
Implements: get

Param Type
paths Array.<PathSets>

compositeSource.set(envelope) ⇒ Observable.<JSONGraphEnvelope>

Kind: instance method of CompositeSource
Implements: set

Param Type
envelope JSONGraphEnvelope

compositeSource.call(path, args, refSuffixes, thisPaths) ⇒ Observable.<JSONGraphEnvelope>

Kind: instance method of CompositeSource
Implements: call

Param Type
path Path
args Array.<Mixed>
refSuffixes Array.<PathSet>
thisPaths Array.<PathSet>

compositeSource.add(path, source) ⇒ CompositeSource

Kind: instance method of CompositeSource
Returns: CompositeSource - the CompositeSource instance

Param Type
path Path
source DataSource

JSONGraphEnvelopeProxy ⇐ ProteanClass

Kind: global class
Extends: ProteanClass
Implements: JSONGraphEnevelope

new JSONGraphEnvelopeProxy([opts])

Param Type Description
[opts] Object
[opts.expect] Array.<PathSet> Paths to expect
[opts.paths] Array.<PathSet> A starting set of paths
[opts.jsonGraph] JSONGraph A starting JSONGraph
[opts.invalidated] Array.<PathSet> A starting set of paths to invalidate

jsonGraphEnvelopeProxy.paths

Kind: instance property of JSONGraphEnvelopeProxy
Properties

Type
Array.<PathSet>

jsonGraphEnvelopeProxy.jsonGraph

Kind: instance property of JSONGraphEnvelopeProxy
Properties

Type
JSONGraph

jsonGraphEnvelopeProxy.invalidated

Kind: instance property of JSONGraphEnvelopeProxy
Properties

Type
Array.<PathSet>

jsonGraphEnvelopeProxy.expecting

Kind: instance property of JSONGraphEnvelopeProxy
Properties

Type
Object

jsonGraphEnvelopeProxy.pending

Get a list of paths this envelope is still expecting to fulfill

Kind: instance property of JSONGraphEnvelopeProxy
Read only: true
Properties

Type
Array.<Path>

jsonGraphEnvelopeProxy.set(pathOrGraph, [atom])

Kind: instance method of JSONGraphEnvelopeProxy

Param Type
pathOrGraph Path | JSONGraph
[atom] Atom

jsonGraphEnvelopeProxy.invalidate(...path)

Kind: instance method of JSONGraphEnvelopeProxy

Param Type
...path Path

jsonGraphEnvelopeProxy.fulfill(path)

Mark a path as fulfilled and set the given value on our jsonGraph

Kind: instance method of JSONGraphEnvelopeProxy

Param Type
path Path

jsonGraphEnvelopeProxy.expect(paths)

Prepare this envelope to expect to fulfill a certain set of paths.

Kind: instance method of JSONGraphEnvelopeProxy

Param Type
paths Array.<PathSet>

jsonGraphEnvelopeProxy.relativeFrom(from) ⇒ JSONGraphEnvelopeProxy

Kind: instance method of JSONGraphEnvelopeProxy
Returns: JSONGraphEnvelopeProxy - A copy

Param Type
from Path

jsonGraphEnvelopeProxy.resolvedFrom(from) ⇒ JSONGraphEnvelopeProxy

Kind: instance method of JSONGraphEnvelopeProxy
Returns: JSONGraphEnvelopeProxy - A copy

Param Type
from Path

jsonGraphEnvelopeProxy.merge(other)

Merge another JSONGraphEnvelope into this one

Kind: instance method of JSONGraphEnvelopeProxy

Param Type
other JSONGraphEnvelopeProxy | JSONGraphEnvelope

jsonGraphEnvelopeProxy.destroy()

Clear out our data so we do not have any dangling memory.

Kind: instance method of JSONGraphEnvelopeProxy

jsonGraphEnvelopeProxy.clone() ⇒ JSONGraphEnvelopeProxy

Get a copy of this proxy

Kind: instance method of JSONGraphEnvelopeProxy

jsonGraphEnvelopeProxy.valueOf() ⇒ JSONGraphEnvelope

Kind: instance method of JSONGraphEnvelopeProxy

jsonGraphEnvelopeProxy.finalize() ⇒ JSONGraphEnvelope

Kind: instance method of JSONGraphEnvelopeProxy

NoCacheSource ⇐ ProteanClass

Kind: global class
Extends: ProteanClass
Implements: DataSource

new NoCacheSource(opts)

A Falcor DataSource that proxies another data source and sets all returned atoms to expire immediately.

file: falcor/data-source/no-cache.js

Param Type
opts Object
opts.source DataSource

noCacheSource.get(paths) ⇒ Observable.<JSONGraphEnvelope>

Kind: instance method of NoCacheSource
Implements: get

Param Type
paths Array.<PathSets>

noCacheSource.set(envelope) ⇒ Observable.<JSONGraphEnvelope>

Kind: instance method of NoCacheSource
Implements: set

Param Type
envelope JSONGraphEnvelope

noCacheSource.call(path, args, refSuffixes, thisPaths) ⇒ Observable.<JSONGraphEnvelope>

Kind: instance method of NoCacheSource
Implements: call

Param Type
path PathSet
args Array.<Mixed>
refSuffixes Array.<PathSet>
thisPaths Array.<PathSet>

PartitionedSource ⇐ ProteanClass

Kind: global class
Extends: ProteanClass
Implements: DataSource

new PartitionedSource([opts])

A falcor DataSource that optionally reads from and writes to a variety of 'partitions' of other DataSources.

When reading (get) it will try the partitions in the order set by the 'reads' option. Any paths gone unfilled by the first, will be requested by the second, and so on. The final graph is a merge of all returned values from those partitions.

When writing (set/call) it will send the request to all given partitions in the 'writes' option. Again, returning a merged graph of all values writen.

Param Type Default
[opts] Object
[opts.reads] Array.<String> []
[opts.writes] Array.<String> []
[opts.partitions] Object.<String, DataSource> {}

partitionedSource.options

Default options

Kind: instance property of PartitionedSource
Properties

Type
Object

options.reads

Kind: static property of options
Properties

Type
Array.<String>

options.writes

Kind: static property of options
Properties

Type
Array.<String>

options.partitions

Kind: static property of options
Properties

Type
Object.<String, DataSource>

partitionedSource.get(paths) ⇒ Observable.<JSONGraphEnvelope>

Kind: instance method of PartitionedSource
Implements: get

Param Type
paths Array.<PathSet>

partitionedSource.set(envelope) ⇒ Observable.<JSONGraphEnvelope>

Kind: instance method of PartitionedSource
Implements: set

Param Type
envelope JSONGraphEnvelope

partitionedSource.call(path, args, refSuffixes, thisPaths) ⇒ Observable.<JSONGraphEnvelope>

Kind: instance method of PartitionedSource
Implements: call

Param Type
path PathSet
args Array.<Mixed>
refSuffixes Array.<PathSet>
thisPaths Array.<PathSet>

ProxiedSource ⇐ ProteanClass

Kind: global class
Extends: ProteanClass
Implements: DataSource

new ProxiedSource([opts])

A Falcor DataSource that proxies to another source, re-writing the returned paths, and the paths to the values within the JSONGraph.

File: falcor/data-source/proxied.js

Param Type
[opts] Object
[opts.source] DataSource
[opts.root] Path

proxiedSource.source

Kind: instance property of ProxiedSource
Properties

Type
DataSource

proxiedSource.root

Kind: instance property of ProxiedSource
Properties

Type
Path

proxiedSource.get(paths) ⇒ Observable.<JSONGraphEnvelope>

Kind: instance method of ProxiedSource
Implements: get

Param Type
paths Array.<PathSets>

proxiedSource.set(envelope) ⇒ Observable.<JSONGraphEnvelope>

Kind: instance method of ProxiedSource
Implements: set

Param Type
envelope JSONGraphEnvelope

proxiedSource.call(path, args, refSuffixes, thisPaths) ⇒ Observable.<JSONGraphEnvelope>

Kind: instance method of ProxiedSource
Implements: call

Param Type
path PathSet
args Array.<Mixed>
refSuffixes Array.<PathSet>
thisPaths Array.<PathSet>

proxiedSource.willGet(paths) ⇒ Boolean

Will the given paths be consumed by a get request against this datasource?

Kind: instance method of ProxiedSource

Param Type
paths Array.<PathSet>

proxiedSource.willSet(envelope) ⇒ Boolean

Will the given JSONGraphEnvelope be consumed by a set request against this datasource?

Kind: instance method of ProxiedSource

Param Type
envelope JSONGraphEnvelope

proxiedSource.willCall(path) ⇒ Boolean

Will the given path be consumed by a call request against this datasource?

Kind: instance method of ProxiedSource

Param Type
path Path

proxiedSource.getRelativeEnvelope(envelope) ⇒ JSONGraphEnvelope

Strip our leading path from the envelope's path(s) and jsonGraph object.

Kind: instance method of ProxiedSource

Param Type
envelope JSONGraphEnvelope

proxiedSource.getResolvedEnvelope(envelope) ⇒ JSONGraphEnvelope

Adjust the JSONGraphEnvelope to reflect our leading path information.

Kind: instance method of ProxiedSource

Param Type
envelope JSONGraphEnvelope

StorageSource ⇐ ProteanClass

Kind: global class
Extends: ProteanClass
Implements: DataSource