Skip to content

Commit 5c854bd

Browse files
author
Tom Kirkpatrick
committed
feat: update to support loopback 3.x
1 parent 5f2485d commit 5c854bd

File tree

12 files changed

+37
-74
lines changed

12 files changed

+37
-74
lines changed

index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ module.exports = function (app, options) {
3737
modelDefinition.acls = options.acls
3838
}
3939

40+
// Support for loopback 2.x.
41+
if (app.loopback.version.startsWith(2)) {
42+
Object.keys(modelDefinition.methods).forEach(method => {
43+
modelDefinition.methods[method].isStatic = true
44+
})
45+
}
46+
4047
const NewModel = dataSource.createModel(
4148
modelDefinition.name,
4249
modelDefinition.properties,

models/meta.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,24 @@ module.exports = function (Meta, options) {
5656
}
5757

5858
// Get the following keys from the settings object, if they are set
59-
const keys = [
60-
'acls',
61-
'base',
62-
'description',
63-
'hidden',
64-
'idInjection',
65-
'methods',
66-
'mixins',
67-
'persistUndefinedAsNull',
68-
'plural',
69-
'relations',
70-
'strict',
71-
'validations'
72-
]
59+
const keys = {
60+
'acls': [],
61+
'base': '',
62+
'description': '',
63+
'hidden': [],
64+
'idInjection': true,
65+
'methods': {},
66+
'mixins': {},
67+
'persistUndefinedAsNull': false,
68+
'plural': '',
69+
'relations': {},
70+
'strict': false,
71+
'validations': [],
72+
}
7373

7474
// Loop through the keys and add them to the result with their value
75-
keys.forEach((key) => {
76-
result[ key ] = _.get(model.definition.settings, key)
75+
Object.keys(keys).forEach(key => {
76+
result[ key ] = _.get(model.definition.settings, key, keys[ key ])
7777
})
7878
return result
7979
}

models/meta.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"relations": {},
1313
"methods": {
1414
"getModels": {
15-
"isStatic": true,
1615
"accepts": [],
1716
"returns": {
1817
"arg": "result",
@@ -26,7 +25,6 @@
2625
}
2726
},
2827
"getModelById": {
29-
"isStatic": true,
3028
"accepts": {
3129
"arg": "name",
3230
"type": "any",
@@ -45,7 +43,6 @@
4543
}
4644
},
4745
"graphviz": {
48-
"isStatic": true,
4946
"accepts": [
5047
{
5148
"arg": "res",

package.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,16 @@
2525
"homepage": "https://github.com/beeman/loopback-component-meta#readme",
2626
"dependencies": {
2727
"debug": "2.2.0",
28-
"lodash": "4.6.1",
29-
"loopback": "2.27.0",
30-
"loopback-datasource-juggler": "2.45.2"
31-
},
32-
"optionalDependencies": {
33-
"loopback-component-explorer": "2.3.0"
28+
"lodash": "4.17.4"
3429
},
3530
"devDependencies": {
3631
"babel-cli": "6.9.0",
3732
"bluebird": "3.3.4",
3833
"chai": "3.5.0",
39-
"debug": "2.2.0",
34+
"loopback": "3.8.0",
4035
"loopback-boot": "2.18.0",
41-
"mocha": "2.4.5"
36+
"loopback-component-explorer": "2.3.0",
37+
"mocha": "2.4.5",
38+
"strong-error-handler": "2.1.0"
4239
}
4340
}

test/component-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('Component test', function() {
2020
return Meta.getModels()
2121
.then((res) => {
2222
expect(res).to.be.an('array')
23-
expect(res.length).to.equal(10)
23+
expect(res.length).to.equal(9)
2424
})
2525
})
2626

test/fixtures/simple-app/common/models/base-model.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
"options": {
66
"validateUpsert": true
77
},
8-
"mixins": {
9-
"ModifiedTimestamp": {}
10-
},
118
"properties": {
129
"created": {
1310
"type": "Date",

test/fixtures/simple-app/common/models/person.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
"options": {
66
"validateUpsert": true
77
},
8-
"mixins": {
9-
"Paginate": {
10-
"limit": "10"
11-
}
12-
},
138
"properties": {
149
"firstName": {
1510
"type": "string",

test/fixtures/simple-app/common/models/user.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/fixtures/simple-app/common/models/user.json

Lines changed: 0 additions & 24 deletions
This file was deleted.

test/fixtures/simple-app/server/config.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
"host": "0.0.0.0",
44
"port": 3000,
55
"remoting": {
6-
"context": {
7-
"enableHttpContext": false
8-
},
6+
"context": false,
97
"rest": {
108
"normalizeHttpPath": false,
119
"xml": false
@@ -19,9 +17,7 @@
1917
"limit": "100kb"
2018
},
2119
"cors": false,
22-
"errorHandler": {
23-
"disableStackTrace": false
24-
}
20+
"handleErrors": false
2521
},
2622
"legacyExplorer": false
2723
}

0 commit comments

Comments
 (0)