API Docs for: 0.4
Show:

ResourceStore.server Class

Constructor

ResourceStore.server

(
  • config
)

Parameters:

  • config Object

    configuration for the store

    • root String

      directory to manage (usually the application directory)

    • context Object

      static context

    • appConfig Object

      overrides for application.json

Methods

@parseValidDims

(
  • dims
)
Object private

Parameters:

  • dims Object

    contents of dimensions.json

Returns:

Object: lookup hash for dimension keys and values

_expandSpec

(
  • env
  • ctx
  • spec
)
Object private

Applies spec inheritance by following the base and merging up the results.

Parameters:

  • env String

    the runtime environment (either client or server)

  • ctx Object

    runtime context

  • spec Object

    spec to expand

Returns:

Object: expanded sped

_findResourcesByConvention

(
  • dir
  • dirType
  • pkg
  • mojitType
)
Array private

Finds resources based on our conventions. -Doesn't- load mojits or their contents. That's done elsewhere.

Parameters:

  • dir String

    directory from which to find resources

  • dirType String

    type represented by the "dir" argument. values are "app", "bundle", "pkg", or "mojit"

  • pkg Object

    metadata (name and version) about the package

  • mojitType String | Null

    name of mojit to which the resource belongs

Returns:

Array: list of resources

_globList

(
  • prefix
  • list
)
Array private

Takes a list of globs and turns it into a list of matching paths.

Parameters:

  • prefix String

    prefix for every path in the list

  • list Array

    list of globs

Returns:

Array: list of paths matching the globs

_mockLib

(
  • name
  • lib
)
Nothing private

Used for unit testing.

Parameters:

  • name String

    name of library to mock out

  • lib Situation-dependent

    library to mock out

Returns:

Nothing:

_preloadApp

(
  • pkg
)
Nothing private

preloads metadata about resources in the application directory (but not node_modules/)

Parameters:

  • pkg Object

    metadata (name and version) about the app's package

Returns:

Nothing:

_preloadDirBundle

(
  • dir
  • pkg
)
Nothing private

preloads metadata about resources in a directory

Parameters:

  • dir String

    directory path

  • pkg Object

    metadata (name and version) about the package

Returns:

Nothing:

_preloadDirMojit

(
  • dir
  • dirType
  • pkg
)
Nothing private

preloads a directory that represents a single mojit

Parameters:

  • dir String

    directory path

  • dirType String

    type represented by the "dir" argument. values are "app", "bundle", "pkg", or "mojit"

  • pkg Object

    metadata (name and version) about the package

Returns:

Nothing:

_preloadDirMojits

(
  • dir
  • dirType
  • pkg
)
Nothing private

preloads a directory containing many mojits

Parameters:

  • dir String

    directory path

  • dirType String

    type represented by the "dir" argument. values are "app", "bundle", "pkg", or "mojit"

  • pkg Object

    metadata (name and version) about the package

Returns:

Nothing:

_preloadPackage

(
  • info
)
Nothing private

preloads metadata about resources in a package (but not subpackages in its node_modules/)

Parameters:

  • info Object

    metadata about the package

Returns:

Nothing:

_resolveVersions

(
  • affinities
  • selectors
  • sourceBase
  • srcs
)
Array private

Resolves versions for a list of resources. The priority is based on passed-in configuration. See resolveResourceVersions() for details.

Parameters:

  • affinities Object

    lookup hash for priority adjustment for each affinity

  • selectors Object

    lookup hash for priority adjustment for each selector

  • sourceBase Int

    multiplier for order in source list

  • srcs Array of arrays

    resource versions to resolve

Returns:

Array: list of resolved resources

_skipBadPath

(
  • pathParts
)
Boolean private

Indicates whether file should be skipped based on its path

Parameters:

  • pathParts Object

    the "source.fs" part of the resource

Returns:

Boolean: true indicates that the file should be skipped

_sortedReaddirSync

(
  • path
)
Array private

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:

  • path String

    directory to read

Returns:

Array: files in the directory

_walkDirRecursive

(
  • dir
  • cb
  • _subdir
)
private

Recursively walks a directory

Parameters:

  • dir String

    directory to start at

  • cb Function(error, subdir, name, isFile)

    callback called for each file

  • _subdir String

    INTERNAL argument for recursion, please ignore

_yuiUseSync

(
  • modules
)
Nothing private

Augments this resource store's Y object with the specified YUI modules.

Parameters:

  • modules Object

    YUI module configuration information

Returns:

Nothing:

addResourceVersion

(
  • res
)
Nothing

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:

  • res Object

    the resource version

Returns:

Nothing:

expandInstance

(
  • instance
  • ctx
  • cb
)
async

This just calls expandInstanceForEnv() with env set to server.

Parameters:

  • instance Map

    partial instance to expand

  • ctx Object

    the context

  • cb Function(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:

  • env String

    the runtime environment (either client or server)

  • instance Object
  • ctx Object

    the context

  • cb Function(err,instance)

    callback used to return the results (or error)

findResourceVersionByConvention

(
  • source
  • mojitType
)
Boolean | Object

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:

  • source Object

    the same as the source part of a resource

  • mojitType String

    the name of the mojit

Returns:

Boolean | Object: If the source is a directory, a boolean can be returned. True indicates that the directory contents should be scanned, while false indicates that the directory should be skipped. If the source does represent a resource, then an object with the following fields should be returned: type {string} type of the resource, subtype {string} optional subtype of the resource, skipSubdirParts {integer} number of path parts of source.fs.subDir to skip

getAllURLs

() Object

Sugar method that returns all "url" metadata of all resources.

Returns:

Object: for all resources with a "url" metadatum, the key is that URL and the value the filesystem path

getAppConfig

(
  • ctx
)
Object

Returns a contextualized application configuration.

Parameters:

  • ctx Object

    the context

Returns:

Object: the application configuration contextualized by the "ctx" argument.

getFrameworkConfig

() Object

Returns Mojito's built-in configuration.

Returns:

Object: the configuration for mojito

getMojitTypeDetails

(
  • env
  • ctx
  • mojitType
  • dest
)
Object

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:

  • env String

    the runtime environment (either client or server)

  • ctx Object

    the context

  • mojitType String

    mojit type

  • dest Object

    object in which to place the results

Returns:

Object: returns the "dest" parameter, which has had details added to it

getResources

(
  • env
  • ctx
  • filter
)
Array of objects

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:

  • env String

    the runtime environment (either client or server)

  • ctx Object

    the context

  • filter Object

    limit returned resources to only those whose keys/values match the filter

Returns:

Array of objects: list of matching resources

getResourceVersions

(
  • filter
)
Array of objects

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:

  • filter Object

    limit returned resource versions to only those whose keys/values match the filter

Returns:

Array of objects: list of matching resource versions

getRoutes

(
  • ctx
)
Object

Returns the routes configured in the application.

Parameters:

  • ctx Object

    the context

Returns:

Object: routes

getSpec

(
  • env
  • id
  • ctx
  • callback
)
async

Returns, via callback, the fully expanded mojit instance specification.

Parameters:

  • env String

    the runtime environment (either client or server)

  • id String

    the ID of the spec to return

  • ctx Object

    the runtime context for the spec

  • callback Function(err,spec)

    callback used to return the results (or error)

getStaticAppConfig

() Object

Returns the static (non-runtime-sensitive) version of the application.json.

Returns:

Object: the configuration from applications.json

getStaticContext

() Object

Returns the static (non-runtime-sensitive) context

Returns:

Object: the context

getType

(
  • env
  • type
  • ctx
  • callback
)
async

Returns, via callback, the details of the mojit type.

Parameters:

  • env String

    the runtime environment (either client or server)

  • type String

    the mojit type

  • ctx Object

    the runtime context for the type

  • callback Function(err,spec)

    callback used to return the results (or error)

initializer

(
  • cfg
)
Nothing

This methods is part of Y.Base. See documentation for that for details.

Parameters:

  • cfg Object

    Configuration object as per Y.Base

Returns:

Nothing:

listAllMojits

() Array

Returns a list of all mojits in the app, except for the "shared" mojit.

Returns:

Array: list of mojits

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:

Nothing:

mergeRecursive

(
  • dest
  • src
  • typeMatch
)
Object

Recursively merge one object onto another. original implementation

Parameters:

  • dest Object

    object to merge into

  • src Object

    object to merge onto "dest"

  • typeMatch Boolean

    controls whether a non-object in the src is allowed to clobber a non-object in the dest (if a different type)

Returns:

Object: the modified "dest" object is also returned directly

parseResourceVersion

(
  • source
  • type
  • subtype
  • mojitType
)
Object | Undefined

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:

  • source Object

    the same as the source part of a resource

  • type String

    the resource type of the file

  • subtype String

    the optional resource subtype of the file

  • mojitType String

    the name of the mojit

Returns:

Object | Undefined: the resource version

preload

() Nothing

Preloads everything in the app, and as well pertinent parts of the framework.

Returns:

Nothing:

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:

Nothing:

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:

Nothing:

serializeClientStore

(
  • ctx
)
Object

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:

  • ctx Object

    the context

Returns:

Object: object that should be serialized and used to initialize MojitoClient

validateContext

(
  • ctx
)
Nothing

Validates the context, and throws an exception if it isn't.

Parameters:

  • ctx Object

    the context

Returns:

Nothing: if this method returns at all then the context is valid

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:

  • args Object

    input arguments

    • env String

      the runtime environment (either client or server)

    • ctx Object

      runtime context

    • posl Array

      priority-ordered seletor list

    • mojitType String

      name of mojit

  • mojit Object

    the mojit type details

mojitResourcesResolved

Fired after the resources for a mojit have been resolved.

Event Payload:

  • env String

    the runtime environment (either client or server)

  • posl Array

    priority-ordered seletor list

  • mojit String

    name of the mojit

  • ress Array

    list of resources in the mojit (for the env and posl)