forked from 418sec/js-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecorators.ts
60 lines (56 loc) · 1.94 KB
/
decorators.ts
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
import { Relation } from './relations'
export { belongsToType, hasManyType, hasOneType } from './relations'
/**
* BelongsTo relation decorator. You probably won't use this directly.
*
* @method
* @param {Mapper} related The relation the target belongs to.
* @param {object} opts Configuration options.
* @param {string} opts.foreignKey The field that holds the primary key of the
* related record.
* @param {string} opts.localField The field that holds a reference to the
* related record object.
* @returns {Function} Invocation function, which accepts the target as the only
* parameter.
*/
export function belongsTo (related, opts) {
return mapper => {
Relation.belongsTo(related, opts).assignTo(mapper)
}
}
/**
* HasMany relation decorator. You probably won't use this directly.
*
* @method
* @param {Mapper} related The relation of which the target has many.
* @param {object} opts Configuration options.
* @param {string} [opts.foreignKey] The field that holds the primary key of the
* related record.
* @param {string} opts.localField The field that holds a reference to the
* related record object.
* @returns {Function} Invocation function, which accepts the target as the only
* parameter.
*/
export function hasMany (related, opts) {
return mapper => {
Relation.hasMany(related, opts).assignTo(mapper)
}
}
/**
* HasOne relation decorator. You probably won't use this directly.
*
* @method
* @param {Mapper} related The relation of which the target has one.
* @param {object} opts Configuration options.
* @param {string} [opts.foreignKey] The field that holds the primary key of the
* related record.
* @param {string} opts.localField The field that holds a reference to the
* related record object.
* @returns {Function} Invocation function, which accepts the target as the only
* parameter.
*/
export function hasOne (related, opts) {
return mapper => {
Relation.hasOne(related, opts).assignTo(mapper)
}
}