Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

alaska

Package Overview
Dependencies
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alaska - npm Package Compare versions

Comparing version 0.4.2 to 0.5.0

lib/service/loadSleds.js

4

lib/alaska.js

@@ -145,2 +145,3 @@ 'use strict';

this._app.subdomainOffset = this.config('subdomainOffset');
require('koa-qs')(this._app);
}

@@ -231,5 +232,2 @@ return this._app;

yield _this._main.init();
yield _this._main.loadModels();
yield _this._main.route();
yield _this._main.launch();

@@ -236,0 +234,0 @@

@@ -51,5 +51,5 @@ 'use strict';

session: {
type: 'alaska-cache-lru',
cookie: {},
store: {
type: 'alaska-cache-lru',
maxAge: 1000 * 60 * 60

@@ -152,5 +152,3 @@ }

prefix: false,
store: {
maxAge: 3600 * 24 * 1000
}
maxAge: 3600 * 24
},

@@ -157,0 +155,0 @@ /**

@@ -68,15 +68,15 @@ 'use strict';

required: field.required,
fullWidth: field.fullWidth
fullWidth: field.fullWidth,
cell: field.cell,
view: field.view
};
if (this.type.views) {
if (field.cell) {
options.cell = field.cell;
} else if (this.type.views.cell) {
options.cell = this.type.views.cell.name;
let type = this.type;
if (type.views) {
if (!options.cell && type.views.cell) {
options.cell = type.views.cell.name;
}
if (field.view) {
options.view = field.view;
} else if (this.type.views.view) {
options.view = this.type.views.view.name;
if (!options.view && type.views.view) {
options.view = type.views.view.name;
}

@@ -87,3 +87,7 @@ }

this.type.viewOptions.forEach(function (key) {
if (field[key] !== undefined) {
if (typeof key === 'function') {
key(options, field);
} else if (typeof key === 'object' && key.key) {
options[key.key] = key.value;
} else if (field[key] !== undefined) {
options[key] = field[key];

@@ -90,0 +94,0 @@ }

@@ -138,2 +138,4 @@ 'use strict';

let name = model.name;
model.id = util.nameToKey(name);
model.key = service.id + '.' + model.id;
if (!model.fields) {

@@ -144,3 +146,3 @@ throw new Error(name + ' model has no fields.');

let schema = model.schema = new Schema({}, {
collection: model.collection || (model.prefix || service.dbPrefix) + name.replace(/([a-z])([A-Z])/g, (a, b, c) => b + '_' + c).toLowerCase()
collection: model.collection || (model.prefix || service.dbPrefix) + model.id.replace(/\-/g, '_')
});

@@ -255,2 +257,26 @@

});
model.relationships = _.map(model.relationships, r => {
//'Model'
let res = {
service: service.id,
ref: r.ref,
path: r.path,
title: r.title,
filters: r.filters
};
if (typeof r.ref === 'function') {
res.ref = r.ref.name;
if (r.ref.service) {
res.service = r.ref.service.id;
}
}
//{ref:'user.User'}
if (res.ref.indexOf('.') > -1) {
let arr = res.ref.split('.');
res.service = arr[0];
res.ref = arr[1];
}
return res;
});
if (model.api === 1) {

@@ -257,0 +283,0 @@ model.api = {

@@ -16,2 +16,3 @@ 'use strict';

const defaultConfig = require('./config');
const Sled = require('./Sled');
const debug = require('debug')('alaska');

@@ -33,5 +34,11 @@

/**
* 所依赖的子Service实例对象别名映射表
* @type {object}
* Model基类
* @type {Model}
*/
/**
* 所依赖的子Service实例对象列表
* @type {[Service]}
* @private

@@ -41,4 +48,4 @@ */

/**
* 本Service的所有额外配置目录
* @type {[string]}
* 本Service的配置项
* @type {object}
* @private

@@ -48,4 +55,4 @@ */

/**
* 数据库连接实例
* @type {mongoose.Connection}
* 本Service数据模型列表
* @type {object}
* @private

@@ -63,2 +70,3 @@ */

this._apiControllers = {};
this._sleds = {};
this._models = {};

@@ -73,8 +81,18 @@ this._db = null;

this.Model = require('./model');
this.Sled = null;
const service = this;
this.panic = alaska.panic;
this.error = alaska.error;
this.try = alaska.try;
this.Sled = class ServiceSled extends Sled {};
this.Sled.service = service;
this.Sled.__defineGetter__('key', function () {
return util.nameToKey(service.id + '.' + this.name);
});
collie(this, 'init', require('./service/init'));
collie(this, 'loadModels', require('./service/loadModels'));
collie(this, 'loadSleds', require('./service/loadSleds'));
collie(this, 'route', require('./service/route'));

@@ -137,4 +155,4 @@ collie(this, 'loadAppMiddlewares', require('./service/loadAppMiddlewares'));

/**
* 所依赖的子Service实例对象列表
* @type {[Service]}
* 所依赖的子Service实例对象别名映射表
* @type {object}
* @private

@@ -144,4 +162,4 @@ */

/**
* 本Service的配置项
* @type {object}
* 本Service的所有额外配置目录
* @type {[string]}
* @private

@@ -151,3 +169,9 @@ */

/**
* 本Service数据模型列表
* 数据库连接实例
* @type {mongoose.Connection}
* @private
*/
/**
* 本ServiceSled列表
* @type {object}

@@ -230,2 +254,7 @@ * @private

/**
* [async] 加载Sled列表
* @method loadSleds
*/
/**
* [async]配置路由

@@ -273,2 +302,3 @@ * @method route

yield _this.loadModels();
yield _this.loadSleds();
yield _this.route();

@@ -330,3 +360,3 @@ })();

* 获取缓存驱动
* @returns {LruDriver|*}
* @returns {LruCacheDriver|*}
*/

@@ -344,3 +374,3 @@ get cache() {

let Driver = require(options.type);
this._cache = new Driver(options.store || {});
this._cache = new Driver(options);
}

@@ -413,3 +443,3 @@ }

}
throw new Error(`"${ name }" model not found`);
this.panic(`"${ name }" model not found`);
}

@@ -432,4 +462,44 @@

/**
* 找回此Service下定义的Sled
* @param {string} name sled名称,例如Register或user.Register
* @returns {Sled|null}
*/
sled(name) {
if (this._sleds[name]) {
return this._sleds[name];
}
let index = name.indexOf('.');
if (index > -1) {
let serviceId = name.substr(0, index);
name = name.substr(index + 1);
let service = this._alias[serviceId];
if (!service) {
service = this.alaska.service(serviceId);
}
if (service) {
return service.sled(name);
}
}
this.panic(`"${ name }" sled not found`);
}
/**
* 运行一个Sled
* @param {string} name
* @param {object} data
* @returns {*}
*/
run(name, data) {
try {
let Sled = this.sled(name);
let sled = new Sled(data);
return sled.run();
} catch (error) {
return Promise.reject(error);
}
}
}
module.exports = Service;

@@ -28,5 +28,4 @@ 'use strict';

let models = _.reduce(this._models, (res, Model, name) => {
name = name.replace(/([a-z])([A-Z])/g, (a, b, c) => b + '-' + c.toLowerCase()).toLowerCase();
res[name] = Model;
let models = _.reduce(this._models, (res, Model) => {
res[Model.id] = Model;
return res;

@@ -33,0 +32,0 @@ }, {});

@@ -17,3 +17,2 @@ 'use strict';

this.loadModels = util.noop;
this.debug('%s load', this.id);

@@ -20,0 +19,0 @@ for (let service of this._services) {

@@ -29,12 +29,7 @@ 'use strict';

if (sessionOpts) {
if (typeof sessionOpts === 'string') {
sessionOpts = {
type: sessionOpts
};
}
let storeOpts = sessionOpts.store || {};
let cookieOpts = sessionOpts.cookie || {};
let key = sessionOpts.key || 'alaska.sid';
let key = cookieOpts.key || 'alaska.sid';
let Session = require('../session');
let Store = require(sessionOpts.type);
let Store = require(storeOpts.type);
let store = new Store(storeOpts);

@@ -41,0 +36,0 @@ let random = require('string-random');

@@ -115,2 +115,11 @@ 'use strict';

);
};
/**
* 将驼峰样式字符串转为小写字符串样式
* @param {string} name
* @returns {string}
*/
exports.nameToKey = function (name) {
return name.replace(/([a-z])([A-Z])/g, (a, b, c) => b + '-' + c.toLowerCase()).toLowerCase();
};
{
"name": "alaska",
"version": "0.4.2",
"version": "0.5.0",
"description": "Componentized and pluggable web framework for Node.js",

@@ -14,3 +14,3 @@ "keywords": [

"dependencies": {
"alaska-cache-lru": "^0.1.3",
"alaska-cache-lru": "^0.2.1",
"async-busboy": "0.0.4",

@@ -23,2 +23,3 @@ "collie": "^0.2.1",

"koa-router": "^7.0.1",
"koa-qs": "^2.0.0",
"lodash": "^4.0.0",

@@ -25,0 +26,0 @@ "mime": "^1.3.4",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc