Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 0e09318d
authored
Nov 18, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
generate proper deprecation warning
1 parent
ff5db2f1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
8 deletions
lib/dao-factory.js
lib/utils/parameter-validator.js
package.json
lib/dao-factory.js
View file @
0e09318
...
@@ -540,7 +540,7 @@ module.exports = (function() {
...
@@ -540,7 +540,7 @@ module.exports = (function() {
DAOFactory
.
prototype
.
create
=
function
(
values
,
fieldsOrOptions
)
{
DAOFactory
.
prototype
.
create
=
function
(
values
,
fieldsOrOptions
)
{
Utils
.
validateParameter
(
values
,
Object
,
{
optional
:
true
})
Utils
.
validateParameter
(
values
,
Object
,
{
optional
:
true
})
Utils
.
validateParameter
(
fieldsOrOptions
,
Object
,
{
deprecated
:
Array
,
optional
:
true
})
Utils
.
validateParameter
(
fieldsOrOptions
,
Object
,
{
deprecated
:
Array
,
optional
:
true
,
index
:
2
,
method
:
'DAOFactory#create'
})
if
(
fieldsOrOptions
instanceof
Array
)
{
if
(
fieldsOrOptions
instanceof
Array
)
{
fieldsOrOptions
=
{
fields
:
fieldsOrOptions
}
fieldsOrOptions
=
{
fields
:
fieldsOrOptions
}
...
@@ -643,8 +643,8 @@ module.exports = (function() {
...
@@ -643,8 +643,8 @@ module.exports = (function() {
* multiple records
* multiple records
*/
*/
DAOFactory
.
prototype
.
bulkCreate
=
function
(
records
,
fieldsOrOptions
,
options
)
{
DAOFactory
.
prototype
.
bulkCreate
=
function
(
records
,
fieldsOrOptions
,
options
)
{
Utils
.
validateParameter
(
fieldsOrOptions
,
Object
,
{
deprecated
:
Array
,
optional
:
true
})
Utils
.
validateParameter
(
fieldsOrOptions
,
Object
,
{
deprecated
:
Array
,
optional
:
true
,
index
:
1
,
method
:
'DAOFactory#bulkCreate'
})
Utils
.
validateParameter
(
options
,
'undefined'
,
{
deprecated
:
Object
,
optional
:
true
})
Utils
.
validateParameter
(
options
,
'undefined'
,
{
deprecated
:
Object
,
optional
:
true
,
index
:
2
,
method
:
'DAOFactory#bulkCreate'
})
options
=
Utils
.
_
.
extend
({
options
=
Utils
.
_
.
extend
({
validate
:
false
,
validate
:
false
,
...
...
lib/utils/parameter-validator.js
View file @
0e09318
var
cJSON
=
require
(
'circular-json'
)
var
ParameterValidator
=
module
.
exports
=
{
var
ParameterValidator
=
module
.
exports
=
{
check
:
function
(
value
,
expectation
,
options
)
{
check
:
function
(
value
,
expectation
,
options
)
{
options
=
Utils
.
_
.
extend
({
options
=
Utils
.
_
.
extend
({
throwError
:
true
,
throwError
:
true
,
deprecated
:
false
,
deprecated
:
false
,
deprecationWarning
:
"Deprecated!"
,
deprecationWarning
:
generateDeprecationWarning
(
value
,
expectation
,
options
),
onDeprecated
:
function
(
s
){
console
.
log
(
'DEPRECATION WARNING:'
,
s
)
},
onDeprecated
:
function
(
s
)
{
console
.
log
(
'DEPRECATION WARNING:'
,
s
)
},
optional
:
false
index
:
null
,
method
:
null
,
optional
:
false
},
options
||
{})
},
options
||
{})
if
(
options
.
optional
&&
((
value
===
undefined
)
||
(
value
===
null
))
)
{
if
(
options
.
optional
&&
((
value
===
undefined
)
||
(
value
===
null
))
)
{
...
@@ -26,6 +30,23 @@ var ParameterValidator = module.exports = {
...
@@ -26,6 +30,23 @@ var ParameterValidator = module.exports = {
}
}
}
}
var
generateDeprecationWarning
=
function
(
value
,
expectation
,
options
)
{
options
=
options
||
{}
if
(
options
.
method
&&
options
.
index
)
{
return
[
'The'
,
{
1
:
'first'
,
2
:
'second'
,
3
:
'third'
,
4
:
'fourth'
,
5
:
'fifth'
}[
options
.
index
],
'parameter of'
,
options
.
method
,
'should be a'
,
extractClassName
(
expectation
)
+
'!'
].
join
(
" "
)
}
else
{
return
[
"Expected"
,
cJSON
.
stringify
(
value
),
"to be"
,
extractClassName
(
expectation
)
+
'!'
].
join
(
" "
)
}
}
var
matchesExpectation
=
function
(
value
,
expectation
)
{
var
matchesExpectation
=
function
(
value
,
expectation
)
{
if
(
typeof
expectation
===
'string'
)
{
if
(
typeof
expectation
===
'string'
)
{
return
(
typeof
value
===
expectation
.
toString
())
return
(
typeof
value
===
expectation
.
toString
())
...
@@ -52,8 +73,18 @@ var validate = function(value, expectation, options) {
...
@@ -52,8 +73,18 @@ var validate = function(value, expectation, options) {
return
false
return
false
}
else
{
}
else
{
var
_value
=
(
value
===
null
)
?
'null'
:
value
.
toString
()
var
_value
=
(
value
===
null
)
?
'null'
:
value
.
toString
()
,
_expectation
=
ex
pectation
.
toString
().
match
(
/function
([^\(]
+
)
/
)[
1
]
,
_expectation
=
ex
tractClassName
(
expectation
)
throw
new
Error
(
'The parameter (value: '
+
_value
+
') is no '
+
_expectation
+
'.'
)
throw
new
Error
(
'The parameter (value: '
+
_value
+
') is no '
+
_expectation
+
'.'
)
}
}
}
}
var
extractClassName
=
function
(
o
)
{
if
(
typeof
o
===
'string'
)
{
return
o
}
else
if
(
!!
o
)
{
return
o
.
toString
().
match
(
/function
([^\(]
+
)
/
)[
1
]
}
else
{
return
'undefined'
}
}
package.json
View file @
0e09318
...
@@ -46,7 +46,8 @@
...
@@ -46,7 +46,8 @@
"toposort-class"
:
"~0.2.0"
,
"toposort-class"
:
"~0.2.0"
,
"generic-pool"
:
"2.0.4"
,
"generic-pool"
:
"2.0.4"
,
"promise"
:
"~3.2.0"
,
"promise"
:
"~3.2.0"
,
"sql"
:
"~0.31.0"
"sql"
:
"~0.31.0"
,
"circular-json"
:
"~0.1.5"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
"sqlite3"
:
"~2.1.12"
,
"sqlite3"
:
"~2.1.12"
,
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment