ResourceStore.server Class
Constructor
ResourceStore.server
-
config
Parameters:
-
configObjectconfiguration for the store
-
rootStringdirectory to manage (usually the application directory)
-
contextObjectstatic context
-
appConfigObjectoverrides for
application.json
-
Item Index
Methods
- @parseValidDims
- _expandSpec
- _findResourcesByConvention
- _globList
- _mockLib
- _preloadApp
- _preloadDirBundle
- _preloadDirMojit
- _preloadDirMojits
- _preloadPackage
- _resolveVersions
- _skipBadPath
- _sortedReaddirSync
- _walkDirRecursive
- _yuiUseSync
- addResourceVersion
- expandInstance
- expandInstanceForEnv
- findResourceVersionByConvention
- getAllURLs
- getAppConfig
- getFrameworkConfig
- getMojitTypeDetails
- getResources
- getResourceVersions
- getRoutes
- getSpec
- getStaticAppConfig
- getStaticContext
- getType
- initializer
- listAllMojits
- loadAddons
- mergeRecursive
- parseResourceVersion
- preload
- preloadResourceVersions
- resolveResourceVersions
- serializeClientStore
- validateContext
Properties
Methods
@parseValidDims
-
dims
Parameters:
-
dimsObjectcontents of dimensions.json
Returns:
_expandSpec
-
env -
ctx -
spec
Applies spec inheritance by following the base and merging up the
results.
Parameters:
-
envStringthe runtime environment (either
clientorserver) -
ctxObjectruntime context
-
specObjectspec to expand
Returns:
_findResourcesByConvention
-
dir -
dirType -
pkg -
mojitType
Finds resources based on our conventions. -Doesn't- load mojits or their contents. That's done elsewhere.
Parameters:
-
dirStringdirectory from which to find resources
-
dirTypeStringtype represented by the "dir" argument. values are "app", "bundle", "pkg", or "mojit"
-
pkgObjectmetadata (name and version) about the package
-
mojitTypeString | Nullname of mojit to which the resource belongs
Returns:
_globList
-
prefix -
list
Takes a list of globs and turns it into a list of matching paths.
Parameters:
-
prefixStringprefix for every path in the list
-
listArraylist of globs
Returns:
_mockLib
-
name -
lib
Used for unit testing.
Parameters:
-
nameStringname of library to mock out
-
libSituation-dependentlibrary to mock out
Returns:
_preloadApp
-
pkg
preloads metadata about resources in the application directory
(but not node_modules/)
Parameters:
-
pkgObjectmetadata (name and version) about the app's package
Returns:
_preloadDirBundle
-
dir -
pkg
preloads metadata about resources in a directory
Parameters:
-
dirStringdirectory path
-
pkgObjectmetadata (name and version) about the package
Returns:
_preloadDirMojit
-
dir -
dirType -
pkg
preloads a directory that represents a single mojit
Parameters:
-
dirStringdirectory path
-
dirTypeStringtype represented by the "dir" argument. values are "app", "bundle", "pkg", or "mojit"
-
pkgObjectmetadata (name and version) about the package
Returns:
_preloadDirMojits
-
dir -
dirType -
pkg
preloads a directory containing many mojits
Parameters:
-
dirStringdirectory path
-
dirTypeStringtype represented by the "dir" argument. values are "app", "bundle", "pkg", or "mojit"
-
pkgObjectmetadata (name and version) about the package
Returns:
_preloadPackage
-
info
preloads metadata about resources in a package
(but not subpackages in its node_modules/)
Parameters:
-
infoObjectmetadata about the package
Returns:
_resolveVersions
-
affinities -
selectors -
sourceBase -
srcs
Resolves versions for a list of resources.
The priority is based on passed-in configuration.
See resolveResourceVersions() for details.
Parameters:
-
affinitiesObjectlookup hash for priority adjustment for each affinity
-
selectorsObjectlookup hash for priority adjustment for each selector
-
sourceBaseIntmultiplier for order in source list
-
srcsArray of arraysresource versions to resolve
Returns:
_skipBadPath
-
pathParts
Indicates whether file should be skipped based on its path
Parameters:
-
pathPartsObjectthe "source.fs" part of the resource
Returns:
_sortedReaddirSync
-
path
A wrapper for fs.readdirSync() that guarantees ordering. The order
in which the file system is walked is significant within the resource
store, e.g., when looking up a matching context.
Parameters:
-
pathStringdirectory to read
Returns:
_walkDirRecursive
-
dir -
cb -
_subdir
Recursively walks a directory
Parameters:
-
dirStringdirectory to start at
-
cbFunction(error, subdir, name, isFile)callback called for each file
-
_subdirStringINTERNAL argument for recursion, please ignore
_yuiUseSync
-
modules
Augments this resource store's Y object with the specified YUI modules.
Parameters:
-
modulesObjectYUI module configuration information
Returns:
addResourceVersion
-
res
Called by the ResourceStore to register a resource version.
You most often don't want to call this directly, but instead to hook
into it using the AOP mechanism of Y.Plugin.Base:
this.beforeHostMethod('parseResourceVersion', this._myParseResource, this);
Parameters:
-
resObjectthe resource version
Returns:
expandInstance
-
instance -
ctx -
cb
This just calls expandInstanceForEnv() with env set to server.
Parameters:
-
instanceMappartial instance to expand
-
ctxObjectthe context
-
cbFunction(err,instance)callback used to return the results (or error)
expandInstanceForEnv
-
env -
instance -
ctx -
cb
Expands the instance into all details necessary to dispatch the mojit.
Parameters:
-
envStringthe runtime environment (either
clientorserver) -
instanceObject -
ctxObjectthe context
-
cbFunction(err,instance)callback used to return the results (or error)
findResourceVersionByConvention
-
source -
mojitType
Called by the ResourceStore to decide if a file should be considered
a resource. You most often don't want to call this directly, but
instead to hook into it using the AOP mechanism of Y.Plugin.Base:
this.afterHostMethod('findResourceVersionByConvention', this._myFindResourceByConvention, this);
Generally findResourceVersionByConvention() and parseResourceVersion() are meant to work together.
This method figures out the type (and subtype) of a file, and parseResourceVersion() turns
the file into an actual resource.
Parameters:
-
sourceObjectthe same as the
sourcepart of a resource -
mojitTypeStringthe name of the mojit
Returns:
source.fs.subDir to skip
getAllURLs
()
Object
Sugar method that returns all "url" metadata of all resources.
Returns:
getAppConfig
-
ctx
Returns a contextualized application configuration.
Parameters:
-
ctxObjectthe context
Returns:
getFrameworkConfig
()
Object
Returns Mojito's built-in configuration.
Returns:
getMojitTypeDetails
-
env -
ctx -
mojitType -
dest
Returns details about a mojit type.
As the last step of execution, this fires the getMojitTypeDetails
event so that Resource Store addons can augment the returned structure.
Parameters:
-
envStringthe runtime environment (either
clientorserver) -
ctxObjectthe context
-
mojitTypeStringmojit type
-
destObjectobject in which to place the results
Returns:
getResources
-
env -
ctx -
filter
Returns a list of resources that match the filter.
(To get the list of resources from all mojits, you'll need to call
listAllMojits() and iterate over that list, calling this method
with mojit: in the filter.)
Parameters:
-
envStringthe runtime environment (either
clientorserver) -
ctxObjectthe context
-
filterObjectlimit returned resources to only those whose keys/values match the filter
Returns:
getResourceVersions
-
filter
Returns a list of resource versions that match the filter.
(To get the list of resource versions from all mojits, you'll need
to call listAllMojits() and iterate over that list, calling this
method with mojit: in the filter.)
Parameters:
-
filterObjectlimit returned resource versions to only those whose keys/values match the filter
Returns:
getRoutes
-
ctx
Returns the routes configured in the application.
Parameters:
-
ctxObjectthe context
Returns:
getSpec
-
env -
id -
ctx -
callback
Returns, via callback, the fully expanded mojit instance specification.
Parameters:
-
envStringthe runtime environment (either
clientorserver) -
idStringthe ID of the spec to return
-
ctxObjectthe runtime context for the spec
-
callbackFunction(err,spec)callback used to return the results (or error)
getStaticAppConfig
()
Object
Returns the static (non-runtime-sensitive) version of the application.json.
Returns:
getStaticContext
()
Object
Returns the static (non-runtime-sensitive) context
Returns:
getType
-
env -
type -
ctx -
callback
Returns, via callback, the details of the mojit type.
Parameters:
-
envStringthe runtime environment (either
clientorserver) -
typeStringthe mojit type
-
ctxObjectthe runtime context for the type
-
callbackFunction(err,spec)callback used to return the results (or error)
initializer
-
cfg
This methods is part of Y.Base. See documentation for that for details.
Parameters:
-
cfgObjectConfiguration object as per Y.Base
Returns:
listAllMojits
()
Array
Returns a list of all mojits in the app, except for the "shared" mojit.
Returns:
loadAddons
()
Nothing
Augments this resource store with addons that we know about.
To find the addons, call preloadResourceVersions() first.
You most often don't want to call this directly, but instead to hook
into it using the AOP mechanism of Y.Plugin.Base:
this.afterHostMethod('loadAddons', this._myLoadAddons, this);
Returns:
mergeRecursive
-
dest -
src -
typeMatch
Recursively merge one object onto another. original implementation
Parameters:
-
destObjectobject to merge into
-
srcObjectobject to merge onto "dest"
-
typeMatchBooleancontrols whether a non-object in the src is allowed to clobber a non-object in the dest (if a different type)
Returns:
parseResourceVersion
-
source -
type -
subtype -
mojitType
Called by the ResourceStore to turn a file into a resource.
You most often don't want to call this directly, but instead to hook
into it using the AOP mechanism of Y.Plugin.Base:
this.beforeHostMethod('parseResourceVersion', this._myParseResource, this);
Generally findResourceVersionByConvention() and parseResourceVersion() are meant to work together.
findResourceVersionByConvention() figures out the type (and subtype) of a file, and
this method turns the file into an actual resource.
Parameters:
-
sourceObjectthe same as the
sourcepart of a resource -
typeStringthe resource type of the file
-
subtypeStringthe optional resource subtype of the file
-
mojitTypeStringthe name of the mojit
Returns:
preload
()
Nothing
Preloads everything in the app, and as well pertinent parts of the framework.
Returns:
preloadResourceVersions
()
Nothing
Preload metadata about all resource versions in the application (and Mojito framework).
You most often don't want to call this directly, but instead to hook
into it using the AOP mechanism of Y.Plugin.Base:
this.afterHostMethod('preloadResourceVersions', this._myPreloadResourceVersions, this);
Returns:
resolveResourceVersions
()
Nothing
For each possible runtime configuration (based on context), pre-calculates which versions of the resources will be used. The priority (highest to lowest): source, selector, affinity (env or "common").
Returns:
serializeClientStore
-
ctx
Returns a serializable object used to initialized Mojito on the client.
FUTURE: [issue 105] cache the output of this function cache key: all of ctx
Parameters:
-
ctxObjectthe context
Returns:
validateContext
-
ctx
Validates the context, and throws an exception if it isn't.
Parameters:
-
ctxObjectthe context
Returns:
Properties
selectors
Object
All selectors that are actually in the app.
Key is selector, value is just boolean true.
This won't be populated until preloadResourceVersions() is done.
Events
getMojitTypeDetails
Fired at the end of the getMojitTypeDetails() method to allow
modification of the results.
Event Payload:
-
argsObjectinput arguments
-
envStringthe runtime environment (either
clientorserver) -
ctxObjectruntime context
-
poslArraypriority-ordered seletor list
-
mojitTypeStringname of mojit
-
-
mojitObjectthe mojit type details
mojitResourcesResolved
Fired after the resources for a mojit have been resolved.
Event Payload:
-
envStringthe runtime environment (either
clientorserver) -
poslArraypriority-ordered seletor list
-
mojitStringname of the mojit
-
ressArraylist of resources in the mojit (for the
envandposl)
