@kitmi/data
Version:
Jacaranda Framework Data Access Model
101 lines (100 loc) • 3.13 kB
JavaScript
/**
* Enable dataModel feature
* @module Feature_DataModel
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return _default;
}
});
const _jacaranda = require("@kitmi/jacaranda");
const _utils = require("@kitmi/utils");
const _default = {
stage: _jacaranda.Feature.SERVICE,
depends: [
'dataSource'
],
load_: async function(app, options, name) {
const config = app.featureConfig(options, {
schema: {
schemaPath: {
type: 'text',
optional: true,
default: 'xeml'
},
sourcePath: {
type: 'text',
optional: true,
default: 'src'
},
modelPath: {
type: 'text',
optional: true,
default: 'src/models'
},
migrationPath: {
type: 'text',
optional: true,
default: './migrations'
},
manifestPath: {
type: 'text',
optional: true,
default: './manifests'
},
schemaSet: {
type: 'object',
valueSchema: {
type: 'object',
schema: {
dataSource: {
type: 'text'
},
options: {
type: 'object',
optional: true
}
}
}
},
apiExtends: {
type: 'array',
optional: true,
element: {
type: 'text'
}
},
dependencies: {
type: 'object',
optional: true
},
useJsonSource: {
type: 'boolean',
optional: true
},
saveIntermediate: {
type: 'boolean',
optional: true
}
}
}, name);
const connectors = _utils._.mapValues(config.schemaSet, (repoConfig, name)=>{
let connector = app.getService(repoConfig.dataSource);
if (!connector) {
throw new Error(`Data source connector [${repoConfig.dataSource}] not found for schema "${name}".`);
}
return connector;
});
const service = {
config,
getConnectors: ()=>connectors,
getConnector: (schemaName)=>connectors[schemaName]
};
app.registerService(name, service);
}
};
//# sourceMappingURL=dataModel.js.map