-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathmem.datasource.js.txt
106 lines (101 loc) · 2.13 KB
/
mem.datasource.js.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
const DataSource = require('loopback-datasource-juggler').DataSource;
const modelList = [
{
name: 'Test',
view: false,
schema: '',
},
{
name:'Schema',
view: false,
schema: 'aSchema'
},
{
name:'View',
view: true,
schema: ''
}
];
// In real model definitions, the schema is contained in options->connectorName->schema
const fullDefinitions = [
{
'name': 'Schema',
'schema': 'aSchema',
'properties': {}
},
{
'name': 'View',
'view': true,
'schema': '',
'properties': {}
},
{
'name': 'Test',
'properties': {
'dateTest': {
'type': 'Date',
'required': false,
'length': null,
'precision': null,
'scale': null,
},
'numberTest': {
'type': 'Number',
'required': false,
'length': null,
'precision': null,
'scale': null,
},
'stringTest': {
'type': 'String',
'required': false,
'length': null,
'precision': null,
'scale': null,
},
'booleanText': {
'type': 'Boolean',
'required': false,
'length': null,
'precision': null,
'scale': null,
},
'id': {
'type': 'Number',
'required': true,
'length': null,
'precision': null,
'scale': 0,
'id': 1,
},
},
},
];
// TODO add .txt to this extension so it doesn't get called by global tests`
class DiscoverOnly extends DataSource {
constructor() {
super();
this.name = 'mem';
this.connected = true;
}
async discoverModelDefinitions(options = {views: true}) {
let models = modelList;
if (!options.views) {
models = models.filter(m => !m.view);
}
if (options.schema) {
models = models.filter(m => m.schema === options.schema);
}
return models;
}
async discoverSchema(name, options = {schema:''}) {
let fullDefs = fullDefinitions;
if (options.schema) {
fullDefs = fullDefs.filter(d => d.schema === options.schema);
}
return fullDefs.find(d => d.name === name);
}
}
module.exports = {
DiscoverOnly
};