[Core] Bring in core bundle from sandbox

Bring in bundle platform/core from the sandbox
branch, in preparation for clean up, tests, and
integration. WTD-573
This commit is contained in:
Victor Woeltjen
2014-11-20 12:58:21 -08:00
parent c50ca2e92b
commit 0fdce798f7
38 changed files with 2914 additions and 0 deletions

View File

@ -0,0 +1,41 @@
/*global define,Promise*/
/**
* Module defining ModelAggregator. Created by vwoeltje on 11/7/14.
*/
define(
[],
function () {
"use strict";
/**
*
* @constructor
*/
function ModelAggregator(providers) {
function mergeModels(provided, ids) {
var result = {};
ids.forEach(function (id) {
provided.forEach(function (models) {
if (models[id]) {
result[id] = models[id];
}
});
});
return result;
}
return {
getModels: function (ids) {
return Promise.all(providers.map(function (provider) {
return provider.getModels(ids);
})).then(function (provided) {
return mergeModels(provided, ids);
});
}
};
}
return ModelAggregator;
}
);

View File

@ -0,0 +1,36 @@
/*global define,Promise*/
/**
* Module defining PersistedModelProvider. Created by vwoeltje on 11/12/14.
*/
define(
[],
function () {
"use strict";
/**
*
* @constructor
*/
function PersistedModelProvider(persistenceService, $q, SPACE) {
function promiseModels(ids) {
return $q.all(ids.map(function (id) {
return persistenceService.readObject(SPACE, id);
})).then(function (models) {
var result = {};
ids.forEach(function (id, index) {
result[id] = models[index];
});
return result;
});
}
return {
getModels: promiseModels
};
}
return PersistedModelProvider;
}
);

View File

@ -0,0 +1,41 @@
/*global define,Promise*/
/**
* Module defining RootModelProvider. Created by vwoeltje on 11/7/14.
*/
define(
['./StaticModelProvider.js'],
function (StaticModelProvider) {
"use strict";
/**
* The root model provider works as the static model provider,
* except that it aggregates roots[] instead of models[], and
* exposes them all as composition of the root object ROOT.
*
* @constructor
*/
function RootModelProvider(roots, $log) {
var ids = roots.map(function (root) {
return root.id;
}),
baseProvider = new StaticModelProvider(roots, $log);
function addRoot(models) {
models.ROOT = {
name: "The root object",
composition: ids
};
return models;
}
return {
getModels: function(ids) {
return baseProvider.getModels(ids).then(addRoot);
}
};
}
return RootModelProvider;
}
);

View File

@ -0,0 +1,64 @@
/*global define,Promise*/
/**
* Module defining StaticModelProvider. Created by vwoeltje on 11/7/14.
*/
define(
[],
function () {
"use strict";
/**
* Loads static models, provided as declared extensions of bundles.
* @constructor
*/
function StaticModelProvider(models, $log) {
var modelMap = {};
function addModelToMap(model) {
// Skip models which don't look right
if (typeof model !== 'object' ||
typeof model.id !== 'string' ||
typeof model.model !== 'object') {
$log.warn([
"Skipping malformed domain object model exposed by ",
((model || {}).bundle || {}).path
].join(""));
} else {
modelMap[model.id] = model.model;
}
}
// Prepoulate maps with models to make subsequent lookup faster.
models.forEach(addModelToMap);
return {
/**
* Get models for these specified string identifiers.
* These will be given as an object containing keys
* and values, where keys are object identifiers and
* values are models.
* This result may contain either a subset or a
* superset of the total objects.
*
* @param {Array<string>} ids the string identifiers for
* models of interest.
* @returns {Promise<object>} a promise for an object
* containing key-value pairs, where keys are
* ids and values are models
* @method
* @memberof StaticModelProvider#
*/
getModels: function (ids) {
var result = {};
ids.forEach(function (id) {
result[id] = modelMap[id];
});
return Promise.resolve(result);
}
};
}
return StaticModelProvider;
}
);