API Docs for: 0.9.0
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

_getSpec

(
  • env
  • id
  • ctx
  • cb
)
private 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

  • cb Function

    callback used to return the results (or error)

    • err Error

      error encountered, or a falsy value if no error

    • spec Object

      the expanded mojit instance

_getType

(
  • env
  • type
  • ctx
  • cb
)
private 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

  • cb Function

    callback used to return the results (or error)

    • err Error

      error encountered, or a falsy value if no error

    • spec Object

      the mojit type details

_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:

_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:

blendStaticContext

(
  • ctx
)
Object

Returns the context provided blended with the static (non-runtime-sensitive) context.

Parameters:

  • ctx Object

    The context to blend.

Returns:

Object: the context

expandInstance

(
  • instance
  • ctx
  • cb
)
async

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

Parameters:

  • instance Map

    partial instance to expand

  • ctx Object

    the context

  • cb Function(err,instance)

    callback used to return the results (or error)

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
)
async

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)

expandInstanceForEnv

(
  • env
  • instance
  • ctx
  • cb
)
async

Expands the instance into all details necessary to dispatch the mojit.

Parameters:

  • env String

    the runtime environment (either client or server)

  • instance Map

    partial instance to expand

  • 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

getAllURLDetails

() Object

Sugar method that returns a hash table with the urls and the resource objects.

Returns:

Object: for all resources with a "url" metadatum, the key is that URL and the value is the results of the makeStaticHandlerDetails() call

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.

getAppConfig

(
  • ctx
)
Object

Returns a contextualized application configuration.

Parameters:

  • ctx Object

    the context

Returns:

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

getAppPkgMeta

() Object

Returns information about the application's NPM package. This is primarily useful when creating resources in makeResourceVersions().

Returns:

Object: metadata about the application's NPM package

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.

NOTE! This returns an object which is shared with similar calls to this method. If you intend to modify the object please make a deep copy first and use that instead.

Parameters:

  • env String

    the runtime environment (either client or server)

  • ctx Object

    the context

  • mojitType String

    mojit type

  • dest Object

    DEPRECATED: object in which to place the results

Returns:

Object: details about the mojit type

getResourceContent

(
  • details
  • callback
)
Undefined

Finds the file represented by the resource, and returns its contents and filesystem info.

Parameters:

  • details Object

    static handling details

  • callback Function

    callback used to return the resource content (or error)

    • err Error | Undefined

      Error that occurred, if any. If an error is given that the other two arguments will be undefined.

    • content Buffer

      the contents of the resource

    • stat Stat | | Null

      Stat object with details about the file on the filesystem Can be null if the resource doesn't have a direct representation on the filesystem.

Returns:

Undefined: nothing is returned, the results are returned via the callback

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

() Object

NOTE: 1. Routes are no longer contextualized on the server runtime. 2. Routes are still contextualized on the client runtime, will need to revisit.

TODO: remove contextualized routes on client runtime

Returns the routes configured in the application.

Returns:

Object: routes

getRoutes

() Object

Returns the routes configured in the application.

Returns:

Object: routes

getStaticAppConfig

() Object

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

Returns:

Object: the configuration from applications.json

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 context used to boot the application.

Returns:

Object: the static context.

getStaticContext

() Object

Returns the static (non-runtime-sensitive) context

Returns:

Object: the context

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

() Number

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:

Number: the number of loaded addons

loadConfigs

()

Loads the dimensions and configurations found in the app

makeResourceFSMeta

(
  • dir
  • dirType
  • subdir
  • file
  • isFile
)
Object

Creates the filesystem metadata for a resource. This is primarily useful when creating resources in makeResourceVersions().

Parameters:

  • dir String

    directory path

  • dirType String

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

  • subdir String

    directory path within "dir".

  • file String

    name of the file or directory

  • isFile Boolean

    indicates whether the path is a file (true) or diretory (false)

Returns:

Object: filesystem metadata

makeResourceVersions

() Nothing

Called by the ResourceStore to allow RS addons to create resource versions that don't otherwise have representation on dist. 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('makeResourceVersions', this._onMakeResourceVersions, this);

Returns:

Nothing:

makeStaticHandlerDetails

(
  • res
)
Object

turns a resource into a datastructure for the static handler

Parameters:

  • res Object

    The resource.

Returns:

Object: A concise version of the resource containing just the details necessary to serve the resource via the static handler.

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

optimizeForEnvironment

() Nothing

Optimizes this store for the specific runtime, or for "production" if none given in static context.

Returns:

Nothing:

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:

preloadInitial

() Nothing

Does initial preload of many parts of the application and framework. The full preload is done by preload().

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:

processResourceContent

(
  • details
  • content
  • callback.stat
  • callback
)
Nothing

A method that transforms the content of a resource as it's being read from the filesystem. This method does nothing, but provides a hook point for resource store addons to transform resource contents.

Parameters:

  • details Object

    static handling details

  • content Buffer

    the contents of the resource

  • callback.stat Stat | | Null

    Stat object with details about the file on the filesystem Can be null if the resource doesn't have a direct representation on the filesystem.

  • callback Function

    callback passed to getResourceContent().

Returns:

Nothing: results returned via the callback

resolveMojitDetails

(
  • env
  • posl
  • type
  • ress
  • mojitRes
)
Object

Cooks down the list of resolved mojit resources into a single structure.

Parameters:

  • env String

    the runtime environment (either client or server)

  • posl Object

    priority-ordered seletor list

  • type String

    name of mojit

  • ress Array

    array of resources for the mojit

  • mojitRes Object

    resource for the mojit itself

Returns:

Object: details for the mojit

resolveResourceVersions

()

For each resource, stuff it in a map mojitType->selector->affinity that will make it easy to retrieve it later. Then if the lazyResolve config is not set, go through all the possible combinations and resolve all resource versions.

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

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

resolveMojitDetails

Fired at the end of the resolveMojitDetails() method to allow modification of the results.

Event Payload:

  • args Object

    input arguments

    • env String

      the runtime environment (either client or server)

    • posl Array

      priority-ordered seletor list

    • type String

      name of mojit

    • ress Array

      array of resources for the mojit

    • mojitRes Object

      resource for the mojit itself

  • details Object

    details for the mojit