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

think-model

Package Overview
Dependencies
Maintainers
2
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

think-model - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

10

index.js

@@ -25,4 +25,5 @@ const helper = require('think-helper');

config = helper.parseAdapterConfig(modelConfig, config);
config.cache = helper.parseAdapterConfig(cacheConfig, config.cache);
return model(name, config, m);
const instance = model(name, config, m);
instance._cacheConfig = cacheConfig;
return instance;
}

@@ -46,5 +47,6 @@

config = helper.parseAdapterConfig(this.config('model'), config);
const instance = model(name, config, m);
// add adapter cache config
config.cache = helper.parseAdapterConfig(this.config('cache'), config.cache);
return model(name, config, m);
instance._cacheConfig = this.config('cache');
return instance;
}

@@ -51,0 +53,0 @@ }

32

lib/model.js

@@ -96,2 +96,3 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

instance.models = this.models;
instance._cacheConfig = this._cacheConfig;
return instance;

@@ -106,5 +107,3 @@ }

cache(key, config) {
if (key === undefined) {
return this;
}
if (key === undefined) return this;
if (!helper.isString(key)) {

@@ -116,7 +115,13 @@ [key, config] = ['', key];

}
const options = helper.parseAdapterConfig(this.config.cache, config);
if (!options.key) {
options.key = key;
const cacheConfig = this._cacheConfig;
if (cacheConfig) {
config = helper.parseAdapterConfig(cacheConfig, this.config.cache, config);
} else {
config = helper.parseAdapterConfig(this.config.cache, config);
}
this.options.cache = options;
if (!config.key) {
config.key = key;
}
assert(helper.isFunction(config.handle), 'cache.handle must be a function');
this.options.cache = config;
return this;

@@ -718,4 +723,15 @@ }

}
const fields = Object.keys(result);
// result is empty
if (fields.length === 0) {
const multi = field.indexOf(',') > -1 && field.indexOf('(') === -1;
if (multi) {
field.split(/\s*,\s*/).forEach(function (item) {
result[item] = [];
});
return result;
} else {
return [];
}
}
if (fields.length === 1) {

@@ -722,0 +738,0 @@ return result[fields[0]];

{
"name": "think-model",
"version": "1.0.1",
"version": "1.0.2",
"description": "An adapter-based ORM for ThinkJS 3.x",

@@ -5,0 +5,0 @@ "scripts": {

@@ -77,3 +77,3 @@ const {test} = require('ava');

test('model set cache option', t => {
t.plan(5);
t.plan(4);

@@ -83,3 +83,4 @@ const model = new Model('post', {

cache: {
type: 'file'
type: 'file',
handle: () => {}
}

@@ -90,4 +91,2 @@ });

t.is(model.options.cache.timeout, 500);
model.cache({type: 'session'});
t.is(model.options.cache.type, 'session');
model.cache('page', {timeout: 300});

@@ -94,0 +93,0 @@ t.is(model.options.cache.key, 'page');

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