@anephenix/objection-relations 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/package.json +12 -10
- package/dist/helpers.d.ts +0 -15
- package/dist/index.d.ts +0 -43
- package/dist/index.js +0 -8
- package/dist/objection-relations.cjs.development.js +0 -292
- package/dist/objection-relations.cjs.development.js.map +0 -1
- package/dist/objection-relations.cjs.production.min.js +0 -2
- package/dist/objection-relations.cjs.production.min.js.map +0 -1
- package/dist/objection-relations.esm.js +0 -286
- package/dist/objection-relations.esm.js.map +0 -1
- package/dist/relations.d.ts +0 -58
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# objection-relations
|
|
2
2
|
|
|
3
|
+
[](https://github.com/anephenix/objection-relations/actions/workflows/node.js.yml) [](https://codeclimate.com/github/anephenix/objection-relations/maintainability) [](https://codeclimate.com/github/anephenix/objection-relations/test_coverage)
|
|
4
|
+
|
|
3
5
|
A relations helper for Objection.js. This provides a convenient way to define
|
|
4
6
|
relations in the `relationMappings` function on an Objection.js model.
|
|
5
7
|
|
|
@@ -256,4 +258,4 @@ npm t
|
|
|
256
258
|
|
|
257
259
|
## Licence and credits
|
|
258
260
|
|
|
259
|
-
©
|
|
261
|
+
©2025 Anephenix OÜ. Objection-relations is licenced under the MIT Licence.
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0.
|
|
2
|
+
"version": "0.0.3",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -17,25 +17,27 @@
|
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@size-limit/preset-small-lib": "^7.0.8",
|
|
20
|
-
"@types/jest": "^
|
|
20
|
+
"@types/jest": "^29.5.14",
|
|
21
21
|
"@types/lodash.snakecase": "^4.1.6",
|
|
22
|
-
"@types/pluralize": "^0.0.
|
|
23
|
-
"husky": "^
|
|
22
|
+
"@types/pluralize": "^0.0.33",
|
|
23
|
+
"husky": "^9.1.7",
|
|
24
24
|
"npm-upgrade": "^3.1.0",
|
|
25
25
|
"size-limit": "^7.0.8",
|
|
26
26
|
"tsdx": "^0.14.1",
|
|
27
|
-
"tslib": "^
|
|
28
|
-
"typescript": "^
|
|
27
|
+
"tslib": "^2.8.1",
|
|
28
|
+
"typescript": "^5.7.3"
|
|
29
29
|
},
|
|
30
30
|
"author": "Paul Jensen <paul@anephenix.com>",
|
|
31
31
|
"scripts": {
|
|
32
|
-
"
|
|
32
|
+
"analyze": "size-limit --why",
|
|
33
33
|
"build": "tsdx build --target node",
|
|
34
|
-
"test": "tsdx test --collectCoverage",
|
|
35
34
|
"lint": "tsdx lint --fix",
|
|
36
|
-
"prepare": "
|
|
35
|
+
"prepare-patch-release": "npm run update-changelog && git add CHANGELOG.md && git commit -m \"Updated changelog\" && npm version patch",
|
|
36
|
+
"publish-patch-release": "npm run prepare-patch-release && git push origin main && git push --tags",
|
|
37
37
|
"size": "size-limit",
|
|
38
|
-
"
|
|
38
|
+
"start": "tsdx watch --target node",
|
|
39
|
+
"test": "tsdx test --collectCoverage",
|
|
40
|
+
"update-changelog": "node scripts/update-changelog.js"
|
|
39
41
|
},
|
|
40
42
|
"husky": {
|
|
41
43
|
"hooks": {
|
package/dist/helpers.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { CommonRelationOrTableOrForeignKeyProps } from './global';
|
|
2
|
-
declare type SubjectProps = CommonRelationOrTableOrForeignKeyProps & {
|
|
3
|
-
subject: string;
|
|
4
|
-
};
|
|
5
|
-
declare type ObjectProps = CommonRelationOrTableOrForeignKeyProps & {
|
|
6
|
-
object: string;
|
|
7
|
-
};
|
|
8
|
-
declare type ViaProps = string | undefined;
|
|
9
|
-
export declare function getSubjectTable({ subject, options }: SubjectProps): string;
|
|
10
|
-
export declare function getObjectTable({ object, options }: ObjectProps): string;
|
|
11
|
-
export declare function getSubjectForeignKey({ subject, options }: SubjectProps): string;
|
|
12
|
-
export declare function getObjectForeignKey({ object, options }: ObjectProps): string;
|
|
13
|
-
export declare function getModelClass({ object, options }: ObjectProps): string;
|
|
14
|
-
export declare function getViaTable(via: ViaProps): string | null;
|
|
15
|
-
export {};
|
package/dist/index.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { OptionsProps } from './global';
|
|
2
|
-
declare type ObjectionRelationProps = {
|
|
3
|
-
subject: string;
|
|
4
|
-
modelPath: string;
|
|
5
|
-
};
|
|
6
|
-
export declare class ObjectionRelation {
|
|
7
|
-
subject: string;
|
|
8
|
-
modelPath: string;
|
|
9
|
-
constructor({ subject, modelPath }: ObjectionRelationProps);
|
|
10
|
-
belongsTo(object: string, options?: OptionsProps): {
|
|
11
|
-
relation: import("objection").RelationType;
|
|
12
|
-
modelClass: string;
|
|
13
|
-
join: {
|
|
14
|
-
from: string;
|
|
15
|
-
to: string;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
hasOne(object: string, options?: OptionsProps): {
|
|
19
|
-
relation: import("objection").RelationType;
|
|
20
|
-
modelClass: string;
|
|
21
|
-
join: {
|
|
22
|
-
from: string;
|
|
23
|
-
to: string;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
hasMany(object: string, options?: OptionsProps): {
|
|
27
|
-
relation: import("objection").RelationType;
|
|
28
|
-
modelClass: string;
|
|
29
|
-
join: {
|
|
30
|
-
from: string;
|
|
31
|
-
to: string;
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
hasManyThrough(object: string, via: string, options?: OptionsProps): {
|
|
35
|
-
relation: import("objection").RelationType;
|
|
36
|
-
modelClass: string;
|
|
37
|
-
join: {
|
|
38
|
-
from: string;
|
|
39
|
-
to: string;
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
export {};
|
package/dist/index.js
DELETED
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
-
|
|
7
|
-
var objection = require('objection');
|
|
8
|
-
var snakeCase = _interopDefault(require('lodash.snakecase'));
|
|
9
|
-
var pluralize = _interopDefault(require('pluralize'));
|
|
10
|
-
var path = require('path');
|
|
11
|
-
|
|
12
|
-
/*
|
|
13
|
-
Gets the SQL table for the subject, either from the options object or the
|
|
14
|
-
plural version of the subject model.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
function getSubjectTable({
|
|
18
|
-
subject,
|
|
19
|
-
options
|
|
20
|
-
}) {
|
|
21
|
-
return (options == null ? void 0 : options.subjectTable) || pluralize(snakeCase(subject));
|
|
22
|
-
}
|
|
23
|
-
/*
|
|
24
|
-
Gets the SQL table for the object, either from the options object or the
|
|
25
|
-
plural version of the object model.
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
function getObjectTable({
|
|
29
|
-
object,
|
|
30
|
-
options
|
|
31
|
-
}) {
|
|
32
|
-
return (options == null ? void 0 : options.objectTable) || pluralize(snakeCase(object));
|
|
33
|
-
}
|
|
34
|
-
/*
|
|
35
|
-
Gets the SQL foreign key for the subject, either from the options object
|
|
36
|
-
or the snake case of the subject model.
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
function getSubjectForeignKey({
|
|
40
|
-
subject,
|
|
41
|
-
options
|
|
42
|
-
}) {
|
|
43
|
-
return (options == null ? void 0 : options.subjectForeignKey) || snakeCase(subject) + '_id';
|
|
44
|
-
}
|
|
45
|
-
/*
|
|
46
|
-
Gets the SQL foreign key for the object, either from the options object
|
|
47
|
-
or the snake case of the object model.
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
function getObjectForeignKey({
|
|
51
|
-
object,
|
|
52
|
-
options
|
|
53
|
-
}) {
|
|
54
|
-
return (options == null ? void 0 : options.objectForeignKey) || snakeCase(object) + '_id';
|
|
55
|
-
}
|
|
56
|
-
/*
|
|
57
|
-
Allows you to define the model path for a model
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
|
-
function getModelClass({
|
|
61
|
-
object,
|
|
62
|
-
options
|
|
63
|
-
}) {
|
|
64
|
-
return options != null && options.modelPath ? path.join(options.modelPath, object) : object;
|
|
65
|
-
}
|
|
66
|
-
function getViaTable(via) {
|
|
67
|
-
return via ? pluralize(snakeCase(via)) : null;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Dependencies
|
|
71
|
-
const {
|
|
72
|
-
HasOneRelation,
|
|
73
|
-
BelongsToOneRelation,
|
|
74
|
-
HasManyRelation,
|
|
75
|
-
ManyToManyRelation
|
|
76
|
-
} = objection.Model;
|
|
77
|
-
/*
|
|
78
|
-
Defines a relationship where a record in one model can belong to a record in
|
|
79
|
-
another model.
|
|
80
|
-
*/
|
|
81
|
-
|
|
82
|
-
function belongsRelation({
|
|
83
|
-
modelClass,
|
|
84
|
-
from,
|
|
85
|
-
to
|
|
86
|
-
}) {
|
|
87
|
-
return {
|
|
88
|
-
relation: BelongsToOneRelation,
|
|
89
|
-
modelClass,
|
|
90
|
-
join: {
|
|
91
|
-
from,
|
|
92
|
-
to
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
/*
|
|
97
|
-
Defines a relationship where a record in one model can own a record in another
|
|
98
|
-
model.
|
|
99
|
-
*/
|
|
100
|
-
|
|
101
|
-
function hasOneRelation({
|
|
102
|
-
modelClass,
|
|
103
|
-
from,
|
|
104
|
-
to
|
|
105
|
-
}) {
|
|
106
|
-
return {
|
|
107
|
-
relation: HasOneRelation,
|
|
108
|
-
modelClass,
|
|
109
|
-
join: {
|
|
110
|
-
from,
|
|
111
|
-
to
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
/*
|
|
116
|
-
Defines a relationship where a record in one model can own many records in
|
|
117
|
-
another model.
|
|
118
|
-
*/
|
|
119
|
-
|
|
120
|
-
function hasManyRelation({
|
|
121
|
-
modelClass,
|
|
122
|
-
from,
|
|
123
|
-
to
|
|
124
|
-
}) {
|
|
125
|
-
return {
|
|
126
|
-
relation: HasManyRelation,
|
|
127
|
-
modelClass,
|
|
128
|
-
join: {
|
|
129
|
-
from,
|
|
130
|
-
to
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
/*
|
|
135
|
-
Defines a relationship where a record in one model can own many records in
|
|
136
|
-
another model, via a join table
|
|
137
|
-
*/
|
|
138
|
-
|
|
139
|
-
function hasManyThroughRelation({
|
|
140
|
-
modelClass,
|
|
141
|
-
from,
|
|
142
|
-
through,
|
|
143
|
-
to
|
|
144
|
-
}) {
|
|
145
|
-
return {
|
|
146
|
-
relation: ManyToManyRelation,
|
|
147
|
-
modelClass,
|
|
148
|
-
join: {
|
|
149
|
-
from,
|
|
150
|
-
through,
|
|
151
|
-
to
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
/*
|
|
156
|
-
Defines a relationship by passing the subject, the predicate, and the object,
|
|
157
|
-
along with an optional via model.
|
|
158
|
-
*/
|
|
159
|
-
|
|
160
|
-
function relation({
|
|
161
|
-
subject,
|
|
162
|
-
relType,
|
|
163
|
-
object,
|
|
164
|
-
via,
|
|
165
|
-
options
|
|
166
|
-
}) {
|
|
167
|
-
const subjectTable = getSubjectTable({
|
|
168
|
-
subject,
|
|
169
|
-
options
|
|
170
|
-
});
|
|
171
|
-
const objectTable = getObjectTable({
|
|
172
|
-
object,
|
|
173
|
-
options
|
|
174
|
-
});
|
|
175
|
-
const subjectForeignKey = getSubjectForeignKey({
|
|
176
|
-
subject,
|
|
177
|
-
options
|
|
178
|
-
});
|
|
179
|
-
const objectForeignKey = getObjectForeignKey({
|
|
180
|
-
object,
|
|
181
|
-
options
|
|
182
|
-
});
|
|
183
|
-
const modelClass = getModelClass({
|
|
184
|
-
object,
|
|
185
|
-
options
|
|
186
|
-
});
|
|
187
|
-
const viaTable = getViaTable(via);
|
|
188
|
-
|
|
189
|
-
switch (relType) {
|
|
190
|
-
case 'hasOne':
|
|
191
|
-
return hasOneRelation({
|
|
192
|
-
modelClass,
|
|
193
|
-
from: `${subjectTable}.id`,
|
|
194
|
-
to: `${objectTable}.${subjectForeignKey}`
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
case 'hasMany':
|
|
198
|
-
return hasManyRelation({
|
|
199
|
-
modelClass,
|
|
200
|
-
from: `${subjectTable}.id`,
|
|
201
|
-
to: `${objectTable}.${subjectForeignKey}`
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
case 'hasManyThrough':
|
|
205
|
-
return hasManyThroughRelation({
|
|
206
|
-
modelClass,
|
|
207
|
-
from: `${subjectTable}.id`,
|
|
208
|
-
through: {
|
|
209
|
-
from: `${viaTable}.${subjectForeignKey}`,
|
|
210
|
-
to: `${viaTable}.${objectForeignKey}`
|
|
211
|
-
},
|
|
212
|
-
to: `${objectTable}.id`
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
case 'belongsTo':
|
|
216
|
-
return belongsRelation({
|
|
217
|
-
modelClass,
|
|
218
|
-
from: `${subjectTable}.${objectForeignKey}`,
|
|
219
|
-
to: `${objectTable}.id`
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
default:
|
|
223
|
-
throw new Error('No valid relationship type specified');
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
class ObjectionRelation {
|
|
228
|
-
constructor({
|
|
229
|
-
subject,
|
|
230
|
-
modelPath
|
|
231
|
-
}) {
|
|
232
|
-
this.subject = subject;
|
|
233
|
-
this.modelPath = modelPath;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
belongsTo(object, options) {
|
|
237
|
-
if (!options) options = {
|
|
238
|
-
modelPath: this.modelPath
|
|
239
|
-
};
|
|
240
|
-
if (!options.modelPath) options.modelPath = this.modelPath;
|
|
241
|
-
return relation({
|
|
242
|
-
subject: this.subject,
|
|
243
|
-
relType: 'belongsTo',
|
|
244
|
-
object,
|
|
245
|
-
options
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
hasOne(object, options) {
|
|
250
|
-
if (!options) options = {
|
|
251
|
-
modelPath: this.modelPath
|
|
252
|
-
};
|
|
253
|
-
if (!options.modelPath) options.modelPath = this.modelPath;
|
|
254
|
-
return relation({
|
|
255
|
-
subject: this.subject,
|
|
256
|
-
relType: 'hasOne',
|
|
257
|
-
object,
|
|
258
|
-
options
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
hasMany(object, options) {
|
|
263
|
-
if (!options) options = {
|
|
264
|
-
modelPath: this.modelPath
|
|
265
|
-
};
|
|
266
|
-
if (!options.modelPath) options.modelPath = this.modelPath;
|
|
267
|
-
return relation({
|
|
268
|
-
subject: this.subject,
|
|
269
|
-
relType: 'hasMany',
|
|
270
|
-
object,
|
|
271
|
-
options
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
hasManyThrough(object, via, options) {
|
|
276
|
-
if (!options) options = {
|
|
277
|
-
modelPath: this.modelPath
|
|
278
|
-
};
|
|
279
|
-
if (!options.modelPath) options.modelPath = this.modelPath;
|
|
280
|
-
return relation({
|
|
281
|
-
subject: this.subject,
|
|
282
|
-
relType: 'hasManyThrough',
|
|
283
|
-
object,
|
|
284
|
-
via,
|
|
285
|
-
options
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
exports.ObjectionRelation = ObjectionRelation;
|
|
292
|
-
//# sourceMappingURL=objection-relations.cjs.development.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"objection-relations.cjs.development.js","sources":["../src/helpers.ts","../src/relations.ts","../src/index.ts"],"sourcesContent":["import snakeCase from 'lodash.snakecase';\nimport pluralize from 'pluralize';\nimport { join } from 'path';\nimport { CommonRelationOrTableOrForeignKeyProps } from './global';\n\n// Types\n\ntype SubjectProps = CommonRelationOrTableOrForeignKeyProps & {\n subject: string;\n};\n\ntype ObjectProps = CommonRelationOrTableOrForeignKeyProps & {\n object: string;\n};\n\ntype ViaProps = string | undefined;\n\n/*\n Gets the SQL table for the subject, either from the options object or the\n plural version of the subject model.\n*/\nexport function getSubjectTable({ subject, options }: SubjectProps) {\n return options?.subjectTable || pluralize(snakeCase(subject));\n}\n\n/*\n Gets the SQL table for the object, either from the options object or the\n plural version of the object model.\n*/\nexport function getObjectTable({ object, options }: ObjectProps) {\n return options?.objectTable || pluralize(snakeCase(object));\n}\n\n/*\n Gets the SQL foreign key for the subject, either from the options object \n or the snake case of the subject model.\n*/\nexport function getSubjectForeignKey({ subject, options }: SubjectProps) {\n return options?.subjectForeignKey || snakeCase(subject) + '_id';\n}\n\n/*\n Gets the SQL foreign key for the object, either from the options object \n or the snake case of the object model.\n*/\nexport function getObjectForeignKey({ object, options }: ObjectProps) {\n return options?.objectForeignKey || snakeCase(object) + '_id';\n}\n\n/*\n\tAllows you to define the model path for a model\n*/\nexport function getModelClass({ object, options }: ObjectProps) {\n return options?.modelPath ? join(options.modelPath, object) : object;\n}\n\nexport function getViaTable(via: ViaProps) {\n return via ? pluralize(snakeCase(via)) : null;\n}\n","// Dependencies\nimport { Model } from 'objection';\nimport {\n RelationTypeProps,\n CommonRelationOrTableOrForeignKeyProps,\n} from './global';\nimport {\n getSubjectTable,\n getSubjectForeignKey,\n getObjectTable,\n getObjectForeignKey,\n getModelClass,\n getViaTable,\n} from './helpers';\n\nconst {\n HasOneRelation,\n BelongsToOneRelation,\n HasManyRelation,\n ManyToManyRelation,\n} = Model;\n\n// Types\n\ntype AdvancedRelationTypeProps = RelationTypeProps & {\n through: {\n from: string;\n to: string;\n };\n};\n\n/*\n Defines a relationship where a record in one model can belong to a record in\n another model.\n*/\nexport function belongsRelation({ modelClass, from, to }: RelationTypeProps) {\n return {\n relation: BelongsToOneRelation,\n modelClass,\n join: { from, to },\n };\n}\n\n/*\n\tDefines a relationship where a record in one model can own a record in another\n\tmodel.\n*/\nexport function hasOneRelation({ modelClass, from, to }: RelationTypeProps) {\n return {\n relation: HasOneRelation,\n modelClass,\n join: { from, to },\n };\n}\n\n/*\n\tDefines a relationship where a record in one model can own many records in\n\tanother model.\n*/\nexport function hasManyRelation({ modelClass, from, to }: RelationTypeProps) {\n return {\n relation: HasManyRelation,\n modelClass,\n join: { from, to },\n };\n}\n\n/*\n\tDefines a relationship where a record in one model can own many records in\n\tanother model, via a join table\n*/\nexport function hasManyThroughRelation({\n modelClass,\n from,\n through,\n to,\n}: AdvancedRelationTypeProps) {\n return {\n relation: ManyToManyRelation,\n modelClass,\n join: { from, through, to },\n };\n}\n\ntype RelationProps = CommonRelationOrTableOrForeignKeyProps & {\n subject: string;\n relType: 'hasOne' | 'hasMany' | 'hasManyThrough' | 'belongsTo';\n object: string;\n via?: string;\n};\n\n/*\n\tDefines a relationship by passing the subject, the predicate, and the object,\n\talong with an optional via model.\n*/\nexport function relation({\n subject,\n relType,\n object,\n via,\n options,\n}: RelationProps) {\n const subjectTable = getSubjectTable({ subject, options });\n const objectTable = getObjectTable({ object, options });\n const subjectForeignKey = getSubjectForeignKey({ subject, options });\n const objectForeignKey = getObjectForeignKey({ object, options });\n const modelClass = getModelClass({ object, options });\n const viaTable = getViaTable(via);\n switch (relType) {\n case 'hasOne':\n return hasOneRelation({\n modelClass,\n from: `${subjectTable}.id`,\n to: `${objectTable}.${subjectForeignKey}`,\n });\n case 'hasMany':\n return hasManyRelation({\n modelClass,\n from: `${subjectTable}.id`,\n to: `${objectTable}.${subjectForeignKey}`,\n });\n case 'hasManyThrough':\n return hasManyThroughRelation({\n modelClass,\n from: `${subjectTable}.id`,\n through: {\n from: `${viaTable}.${subjectForeignKey}`,\n to: `${viaTable}.${objectForeignKey}`,\n },\n to: `${objectTable}.id`,\n });\n case 'belongsTo':\n return belongsRelation({\n modelClass,\n from: `${subjectTable}.${objectForeignKey}`,\n to: `${objectTable}.id`,\n });\n default:\n throw new Error('No valid relationship type specified');\n }\n}\n","// Dependencies\nimport { OptionsProps } from './global';\nimport { relation } from './relations';\n\n// Types\n\ntype ObjectionRelationProps = {\n subject: string;\n modelPath: string;\n};\n\nexport class ObjectionRelation {\n subject: string;\n modelPath: string;\n constructor({ subject, modelPath }: ObjectionRelationProps) {\n this.subject = subject;\n this.modelPath = modelPath;\n }\n\n belongsTo(object: string, options?: OptionsProps) {\n if (!options) options = { modelPath: this.modelPath };\n if (!options.modelPath) options.modelPath = this.modelPath;\n return relation({\n subject: this.subject,\n relType: 'belongsTo',\n object,\n options,\n });\n }\n\n hasOne(object: string, options?: OptionsProps) {\n if (!options) options = { modelPath: this.modelPath };\n if (!options.modelPath) options.modelPath = this.modelPath;\n return relation({\n subject: this.subject,\n relType: 'hasOne',\n object,\n options,\n });\n }\n\n hasMany(object: string, options?: OptionsProps) {\n if (!options) options = { modelPath: this.modelPath };\n if (!options.modelPath) options.modelPath = this.modelPath;\n return relation({\n subject: this.subject,\n relType: 'hasMany',\n object,\n options,\n });\n }\n\n hasManyThrough(object: string, via: string, options?: OptionsProps) {\n if (!options) options = { modelPath: this.modelPath };\n if (!options.modelPath) options.modelPath = this.modelPath;\n return relation({\n subject: this.subject,\n relType: 'hasManyThrough',\n object,\n via,\n options,\n });\n }\n}\n"],"names":["getSubjectTable","subject","options","subjectTable","pluralize","snakeCase","getObjectTable","object","objectTable","getSubjectForeignKey","subjectForeignKey","getObjectForeignKey","objectForeignKey","getModelClass","modelPath","join","getViaTable","via","HasOneRelation","BelongsToOneRelation","HasManyRelation","ManyToManyRelation","Model","belongsRelation","modelClass","from","to","relation","hasOneRelation","hasManyRelation","hasManyThroughRelation","through","relType","viaTable","Error","ObjectionRelation","constructor","belongsTo","hasOne","hasMany","hasManyTh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Ed+B,MAAAA,OAAO,EAAE,SAFK;AAGdzB,MAAAA,MAHc;AAIdL,MAAAA;AAJc,KAAD,CAAf;AAMD;;AAEDsC,EAAAA,cAAc,CAACjC,MAAD,EAAiBU,GAAjB,EAA8Bf,OAA9B;AACZ,QAAI,CAACA,OAAL,EAAcA,OAAO,GAAG;AAAEY,MAAAA,SAAS,EAAE,KAAKA;AAAlB,KAAV;AACd,QAAI,CAACZ,OAAO,CAACY,SAAb,EAAwBZ,OAAO,CAACY,SAAR,GAAoB,KAAKA,SAAzB;AACxB,WAAOa,QAAQ,CAAC;AACd1B,MAAAA,OAAO,EAAE,KAAKA,OADA;AAEd+B,MAAAA,OAAO,EAAE,gBAFK;AAGdzB,MAAAA,MAHc;AAIdU,MAAAA,GAJc;AAKdf,MAAAA;AALc,KAAD,CAAf;AAOD;;;;;;"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";function o(o){return o&&"object"==typeof o&&"default"in o?o.default:o}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("objection"),e=o(require("lodash.snakecase")),n=o(require("pluralize")),s=require("path");const{HasOneRelation:l,BelongsToOneRelation:r,HasManyRelation:a,ManyToManyRelation:i}=t.Model;function u({subject:o,relType:t,object:u,via:h,options:c}){const d=function({subject:o,options:t}){return(null==t?void 0:t.subjectTable)||n(e(o))}({subject:o,options:c}),m=function({object:o,options:t}){return(null==t?void 0:t.objectTable)||n(e(o))}({object:u,options:c}),b=function({subject:o,options:t}){return(null==t?void 0:t.subjectForeignKey)||e(o)+"_id"}({subject:o,options:c}),j=function({object:o,options:t}){return(null==t?void 0:t.objectForeignKey)||e(o)+"_id"}({object:u,options:c}),f=function({object:o,options:t}){return null!=t&&t.modelPath?s.join(t.modelPath,o):o}({object:u,options:c}),p=function(o){return o?n(e(o)):null}(h);switch(t){case"hasOne":return function({modelClass:o,from:t,to:e}){return{relation:l,modelClass:o,join:{from:t,to:e}}}({modelClass:f,from:d+".id",to:`${m}.${b}`});case"hasMany":return function({modelClass:o,from:t,to:e}){return{relation:a,modelClass:o,join:{from:t,to:e}}}({modelClass:f,from:d+".id",to:`${m}.${b}`});case"hasManyThrough":return function({modelClass:o,from:t,through:e,to:n}){return{relation:i,modelClass:o,join:{from:t,through:e,to:n}}}({modelClass:f,from:d+".id",through:{from:`${p}.${b}`,to:`${p}.${j}`},to:m+".id"});case"belongsTo":return function({modelClass:o,from:t,to:e}){return{relation:r,modelClass:o,join:{from:t,to:e}}}({modelClass:f,from:`${d}.${j}`,to:m+".id"});default:throw new Error("No valid relationship type specified")}}exports.ObjectionRelation=class{constructor({subject:o,modelPath:t}){this.subject=o,this.modelPath=t}belongsTo(o,t){return t||(t={modelPath:this.modelPath}),t.modelPath||(t.modelPath=this.modelPath),u({subject:this.subject,relType:"belongsTo",object:o,options:t})}hasOne(o,t){return t||(t={modelPath:this.modelPath}),t.modelPath||(t.modelPath=this.modelPath),u({subject:this.subject,relType:"hasOne",object:o,options:t})}hasMany(o,t){return t||(t={modelPath:this.modelPath}),t.modelPath||(t.modelPath=this.modelPath),u({subject:this.subject,relType:"hasMany",object:o,options:t})}hasManyThrough(o,t,e){return e||(e={modelPath:this.modelPath}),e.modelPath||(e.modelPath=this.modelPath),u({subject:this.subject,relType:"hasManyThrough",object:o,via:t,options:e})}};
|
|
2
|
-
//# sourceMappingURL=objection-relations.cjs.production.min.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"objection-relations.cjs.production.min.js","sources":["../src/relations.ts","../src/helpers.ts","../src/index.ts"],"sourcesContent":["// Dependencies\nimport { Model } from 'objection';\nimport {\n RelationTypeProps,\n CommonRelationOrTableOrForeignKeyProps,\n} from './global';\nimport {\n getSubjectTable,\n getSubjectForeignKey,\n getObjectTable,\n getObjectForeignKey,\n getModelClass,\n getViaTable,\n} from './helpers';\n\nconst {\n HasOneRelation,\n BelongsToOneRelation,\n HasManyRelation,\n ManyToManyRelation,\n} = Model;\n\n// Types\n\ntype AdvancedRelationTypeProps = RelationTypeProps & {\n through: {\n from: string;\n to: string;\n };\n};\n\n/*\n Defines a relationship where a record in one model can belong to a record in\n another model.\n*/\nexport function belongsRelation({ modelClass, from, to }: RelationTypeProps) {\n return {\n relation: BelongsToOneRelation,\n modelClass,\n join: { from, to },\n };\n}\n\n/*\n\tDefines a relationship where a record in one model can own a record in another\n\tmodel.\n*/\nexport function hasOneRelation({ modelClass, from, to }: RelationTypeProps) {\n return {\n relation: HasOneRelation,\n modelClass,\n join: { from, to },\n };\n}\n\n/*\n\tDefines a relationship where a record in one model can own many records in\n\tanother model.\n*/\nexport function hasManyRelation({ modelClass, from, to }: RelationTypeProps) {\n return {\n relation: HasManyRelation,\n modelClass,\n join: { from, to },\n };\n}\n\n/*\n\tDefines a relationship where a record in one model can own many records in\n\tanother model, via a join table\n*/\nexport function hasManyThroughRelation({\n modelClass,\n from,\n through,\n to,\n}: AdvancedRelationTypeProps) {\n return {\n relation: ManyToManyRelation,\n modelClass,\n join: { from, through, to },\n };\n}\n\ntype RelationProps = CommonRelationOrTableOrForeignKeyProps & {\n subject: string;\n relType: 'hasOne' | 'hasMany' | 'hasManyThrough' | 'belongsTo';\n object: string;\n via?: string;\n};\n\n/*\n\tDefines a relationship by passing the subject, the predicate, and the object,\n\talong with an optional via model.\n*/\nexport function relation({\n subject,\n relType,\n object,\n via,\n options,\n}: RelationProps) {\n const subjectTable = getSubjectTable({ subject, options });\n const objectTable = getObjectTable({ object, options });\n const subjectForeignKey = getSubjectForeignKey({ subject, options });\n const objectForeignKey = getObjectForeignKey({ object, options });\n const modelClass = getModelClass({ object, options });\n const viaTable = getViaTable(via);\n switch (relType) {\n case 'hasOne':\n return hasOneRelation({\n modelClass,\n from: `${subjectTable}.id`,\n to: `${objectTable}.${subjectForeignKey}`,\n });\n case 'hasMany':\n return hasManyRelation({\n modelClass,\n from: `${subjectTable}.id`,\n to: `${objectTable}.${subjectForeignKey}`,\n });\n case 'hasManyThrough':\n return hasManyThroughRelation({\n modelClass,\n from: `${subjectTable}.id`,\n through: {\n from: `${viaTable}.${subjectForeignKey}`,\n to: `${viaTable}.${objectForeignKey}`,\n },\n to: `${objectTable}.id`,\n });\n case 'belongsTo':\n return belongsRelation({\n modelClass,\n from: `${subjectTable}.${objectForeignKey}`,\n to: `${objectTable}.id`,\n });\n default:\n throw new Error('No valid relationship type specified');\n }\n}\n","import snakeCase from 'lodash.snakecase';\nimport pluralize from 'pluralize';\nimport { join } from 'path';\nimport { CommonRelationOrTableOrForeignKeyProps } from './global';\n\n// Types\n\ntype SubjectProps = CommonRelationOrTableOrForeignKeyProps & {\n subject: string;\n};\n\ntype ObjectProps = CommonRelationOrTableOrForeignKeyProps & {\n object: string;\n};\n\ntype ViaProps = string | undefined;\n\n/*\n Gets the SQL table for the subject, either from the options object or the\n plural version of the subject model.\n*/\nexport function getSubjectTable({ subject, options }: SubjectProps) {\n return options?.subjectTable || pluralize(snakeCase(subject));\n}\n\n/*\n Gets the SQL table for the object, either from the options object or the\n plural version of the object model.\n*/\nexport function getObjectTable({ object, options }: ObjectProps) {\n return options?.objectTable || pluralize(snakeCase(object));\n}\n\n/*\n Gets the SQL foreign key for the subject, either from the options object \n or the snake case of the subject model.\n*/\nexport function getSubjectForeignKey({ subject, options }: SubjectProps) {\n return options?.subjectForeignKey || snakeCase(subject) + '_id';\n}\n\n/*\n Gets the SQL foreign key for the object, either from the options object \n or the snake case of the object model.\n*/\nexport function getObjectForeignKey({ object, options }: ObjectProps) {\n return options?.objectForeignKey || snakeCase(object) + '_id';\n}\n\n/*\n\tAllows you to define the model path for a model\n*/\nexport function getModelClass({ object, options }: ObjectProps) {\n return options?.modelPath ? join(options.modelPath, object) : object;\n}\n\nexport function getViaTable(via: ViaProps) {\n return via ? pluralize(snakeCase(via)) : null;\n}\n","// Dependencies\nimport { OptionsProps } from './global';\nimport { relation } from './relations';\n\n// Types\n\ntype ObjectionRelationProps = {\n subject: string;\n modelPath: string;\n};\n\nexport class ObjectionRelation {\n subject: string;\n modelPath: string;\n constructor({ subject, modelPath }: ObjectionRelationProps) {\n this.subject = subject;\n this.modelPath = modelPath;\n }\n\n belongsTo(object: string, options?: OptionsProps) {\n if (!options) options = { modelPath: this.modelPath };\n if (!options.modelPath) options.modelPath = this.modelPath;\n return relation({\n subject: this.subject,\n relType: 'belongsTo',\n object,\n options,\n });\n }\n\n hasOne(object: string, options?: OptionsProps) {\n if (!options) options = { modelPath: this.modelPath };\n if (!options.modelPath) options.modelPath = this.modelPath;\n return relation({\n subject: this.subject,\n relType: 'hasOne',\n object,\n options,\n });\n }\n\n hasMany(object: string, options?: OptionsProps) {\n if (!options) options = { modelPath: this.modelPath };\n if (!options.modelPath) options.modelPath = this.modelPath;\n return relation({\n subject: this.subject,\n relType: 'hasMany',\n object,\n options,\n });\n }\n\n hasManyThrough(object: string, via: string, options?: OptionsProps) {\n if (!options) options = { modelPath: this.modelPath };\n if (!options.modelPath) options.modelPath = this.modelPath;\n return relation({\n subject: this.subject,\n relType: 'hasManyThrough',\n object,\n via,\n options,\n });\n }\n}\n"],"names":["HasOneRelation","BelongsToOneRelation","HasManyRelation","ManyToManyRelation","Model","relation","subject","relType","object","via","options","subjectTable","pluralize","snakeCase","getSubjectTable","objectTable","getObjectTable","subjectForeignKey","getSubjectForeignKey","objectForeignKey","getObjectForeignKey","modelClass","modelPath","join","getModelClass","viaTable","getViaTable","from","to","hasOneRelation","hasManyRelation","through","hasManyThroughRelation","belongsRelation","Error","constructor","belongsTo","this","hasOne","hasMany","hasManyThrough"],"mappings":"kPAeA,MAAMA,eACJA,EADIC,qBAEJA,EAFIC,gBAGJA,EAHIC,mBAIJA,GACEC,QA2EJ,SAAgBC,GAASC,QACvBA,EADuBC,QAEvBA,EAFuBC,OAGvBA,EAHuBC,IAIvBA,EAJuBC,QAKvBA,UAEMC,YCjFwBL,QAAEA,EAAFI,QAAWA,iBAClCA,SAAAA,EAASC,eAAgBC,EAAUC,EAAUP,IDgF/BQ,CAAgB,CAAER,QAAAA,EAASI,QAAAA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ecase';
|
|
3
|
-
import pluralize from 'pluralize';
|
|
4
|
-
import { join } from 'path';
|
|
5
|
-
|
|
6
|
-
/*
|
|
7
|
-
Gets the SQL table for the subject, either from the options object or the
|
|
8
|
-
plural version of the subject model.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
function getSubjectTable({
|
|
12
|
-
subject,
|
|
13
|
-
options
|
|
14
|
-
}) {
|
|
15
|
-
return (options == null ? void 0 : options.subjectTable) || pluralize(snakeCase(subject));
|
|
16
|
-
}
|
|
17
|
-
/*
|
|
18
|
-
Gets the SQL table for the object, either from the options object or the
|
|
19
|
-
plural version of the object model.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
function getObjectTable({
|
|
23
|
-
object,
|
|
24
|
-
options
|
|
25
|
-
}) {
|
|
26
|
-
return (options == null ? void 0 : options.objectTable) || pluralize(snakeCase(object));
|
|
27
|
-
}
|
|
28
|
-
/*
|
|
29
|
-
Gets the SQL foreign key for the subject, either from the options object
|
|
30
|
-
or the snake case of the subject model.
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
function getSubjectForeignKey({
|
|
34
|
-
subject,
|
|
35
|
-
options
|
|
36
|
-
}) {
|
|
37
|
-
return (options == null ? void 0 : options.subjectForeignKey) || snakeCase(subject) + '_id';
|
|
38
|
-
}
|
|
39
|
-
/*
|
|
40
|
-
Gets the SQL foreign key for the object, either from the options object
|
|
41
|
-
or the snake case of the object model.
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
function getObjectForeignKey({
|
|
45
|
-
object,
|
|
46
|
-
options
|
|
47
|
-
}) {
|
|
48
|
-
return (options == null ? void 0 : options.objectForeignKey) || snakeCase(object) + '_id';
|
|
49
|
-
}
|
|
50
|
-
/*
|
|
51
|
-
Allows you to define the model path for a model
|
|
52
|
-
*/
|
|
53
|
-
|
|
54
|
-
function getModelClass({
|
|
55
|
-
object,
|
|
56
|
-
options
|
|
57
|
-
}) {
|
|
58
|
-
return options != null && options.modelPath ? join(options.modelPath, object) : object;
|
|
59
|
-
}
|
|
60
|
-
function getViaTable(via) {
|
|
61
|
-
return via ? pluralize(snakeCase(via)) : null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Dependencies
|
|
65
|
-
const {
|
|
66
|
-
HasOneRelation,
|
|
67
|
-
BelongsToOneRelation,
|
|
68
|
-
HasManyRelation,
|
|
69
|
-
ManyToManyRelation
|
|
70
|
-
} = Model;
|
|
71
|
-
/*
|
|
72
|
-
Defines a relationship where a record in one model can belong to a record in
|
|
73
|
-
another model.
|
|
74
|
-
*/
|
|
75
|
-
|
|
76
|
-
function belongsRelation({
|
|
77
|
-
modelClass,
|
|
78
|
-
from,
|
|
79
|
-
to
|
|
80
|
-
}) {
|
|
81
|
-
return {
|
|
82
|
-
relation: BelongsToOneRelation,
|
|
83
|
-
modelClass,
|
|
84
|
-
join: {
|
|
85
|
-
from,
|
|
86
|
-
to
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
/*
|
|
91
|
-
Defines a relationship where a record in one model can own a record in another
|
|
92
|
-
model.
|
|
93
|
-
*/
|
|
94
|
-
|
|
95
|
-
function hasOneRelation({
|
|
96
|
-
modelClass,
|
|
97
|
-
from,
|
|
98
|
-
to
|
|
99
|
-
}) {
|
|
100
|
-
return {
|
|
101
|
-
relation: HasOneRelation,
|
|
102
|
-
modelClass,
|
|
103
|
-
join: {
|
|
104
|
-
from,
|
|
105
|
-
to
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
/*
|
|
110
|
-
Defines a relationship where a record in one model can own many records in
|
|
111
|
-
another model.
|
|
112
|
-
*/
|
|
113
|
-
|
|
114
|
-
function hasManyRelation({
|
|
115
|
-
modelClass,
|
|
116
|
-
from,
|
|
117
|
-
to
|
|
118
|
-
}) {
|
|
119
|
-
return {
|
|
120
|
-
relation: HasManyRelation,
|
|
121
|
-
modelClass,
|
|
122
|
-
join: {
|
|
123
|
-
from,
|
|
124
|
-
to
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
/*
|
|
129
|
-
Defines a relationship where a record in one model can own many records in
|
|
130
|
-
another model, via a join table
|
|
131
|
-
*/
|
|
132
|
-
|
|
133
|
-
function hasManyThroughRelation({
|
|
134
|
-
modelClass,
|
|
135
|
-
from,
|
|
136
|
-
through,
|
|
137
|
-
to
|
|
138
|
-
}) {
|
|
139
|
-
return {
|
|
140
|
-
relation: ManyToManyRelation,
|
|
141
|
-
modelClass,
|
|
142
|
-
join: {
|
|
143
|
-
from,
|
|
144
|
-
through,
|
|
145
|
-
to
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
/*
|
|
150
|
-
Defines a relationship by passing the subject, the predicate, and the object,
|
|
151
|
-
along with an optional via model.
|
|
152
|
-
*/
|
|
153
|
-
|
|
154
|
-
function relation({
|
|
155
|
-
subject,
|
|
156
|
-
relType,
|
|
157
|
-
object,
|
|
158
|
-
via,
|
|
159
|
-
options
|
|
160
|
-
}) {
|
|
161
|
-
const subjectTable = getSubjectTable({
|
|
162
|
-
subject,
|
|
163
|
-
options
|
|
164
|
-
});
|
|
165
|
-
const objectTable = getObjectTable({
|
|
166
|
-
object,
|
|
167
|
-
options
|
|
168
|
-
});
|
|
169
|
-
const subjectForeignKey = getSubjectForeignKey({
|
|
170
|
-
subject,
|
|
171
|
-
options
|
|
172
|
-
});
|
|
173
|
-
const objectForeignKey = getObjectForeignKey({
|
|
174
|
-
object,
|
|
175
|
-
options
|
|
176
|
-
});
|
|
177
|
-
const modelClass = getModelClass({
|
|
178
|
-
object,
|
|
179
|
-
options
|
|
180
|
-
});
|
|
181
|
-
const viaTable = getViaTable(via);
|
|
182
|
-
|
|
183
|
-
switch (relType) {
|
|
184
|
-
case 'hasOne':
|
|
185
|
-
return hasOneRelation({
|
|
186
|
-
modelClass,
|
|
187
|
-
from: `${subjectTable}.id`,
|
|
188
|
-
to: `${objectTable}.${subjectForeignKey}`
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
case 'hasMany':
|
|
192
|
-
return hasManyRelation({
|
|
193
|
-
modelClass,
|
|
194
|
-
from: `${subjectTable}.id`,
|
|
195
|
-
to: `${objectTable}.${subjectForeignKey}`
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
case 'hasManyThrough':
|
|
199
|
-
return hasManyThroughRelation({
|
|
200
|
-
modelClass,
|
|
201
|
-
from: `${subjectTable}.id`,
|
|
202
|
-
through: {
|
|
203
|
-
from: `${viaTable}.${subjectForeignKey}`,
|
|
204
|
-
to: `${viaTable}.${objectForeignKey}`
|
|
205
|
-
},
|
|
206
|
-
to: `${objectTable}.id`
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
case 'belongsTo':
|
|
210
|
-
return belongsRelation({
|
|
211
|
-
modelClass,
|
|
212
|
-
from: `${subjectTable}.${objectForeignKey}`,
|
|
213
|
-
to: `${objectTable}.id`
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
default:
|
|
217
|
-
throw new Error('No valid relationship type specified');
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
class ObjectionRelation {
|
|
222
|
-
constructor({
|
|
223
|
-
subject,
|
|
224
|
-
modelPath
|
|
225
|
-
}) {
|
|
226
|
-
this.subject = subject;
|
|
227
|
-
this.modelPath = modelPath;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
belongsTo(object, options) {
|
|
231
|
-
if (!options) options = {
|
|
232
|
-
modelPath: this.modelPath
|
|
233
|
-
};
|
|
234
|
-
if (!options.modelPath) options.modelPath = this.modelPath;
|
|
235
|
-
return relation({
|
|
236
|
-
subject: this.subject,
|
|
237
|
-
relType: 'belongsTo',
|
|
238
|
-
object,
|
|
239
|
-
options
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
hasOne(object, options) {
|
|
244
|
-
if (!options) options = {
|
|
245
|
-
modelPath: this.modelPath
|
|
246
|
-
};
|
|
247
|
-
if (!options.modelPath) options.modelPath = this.modelPath;
|
|
248
|
-
return relation({
|
|
249
|
-
subject: this.subject,
|
|
250
|
-
relType: 'hasOne',
|
|
251
|
-
object,
|
|
252
|
-
options
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
hasMany(object, options) {
|
|
257
|
-
if (!options) options = {
|
|
258
|
-
modelPath: this.modelPath
|
|
259
|
-
};
|
|
260
|
-
if (!options.modelPath) options.modelPath = this.modelPath;
|
|
261
|
-
return relation({
|
|
262
|
-
subject: this.subject,
|
|
263
|
-
relType: 'hasMany',
|
|
264
|
-
object,
|
|
265
|
-
options
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
hasManyThrough(object, via, options) {
|
|
270
|
-
if (!options) options = {
|
|
271
|
-
modelPath: this.modelPath
|
|
272
|
-
};
|
|
273
|
-
if (!options.modelPath) options.modelPath = this.modelPath;
|
|
274
|
-
return relation({
|
|
275
|
-
subject: this.subject,
|
|
276
|
-
relType: 'hasManyThrough',
|
|
277
|
-
object,
|
|
278
|
-
via,
|
|
279
|
-
options
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
export { ObjectionRelation };
|
|
286
|
-
//# sourceMappingURL=objection-relations.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"objection-relations.esm.js","sources":["../src/helpers.ts","../src/relations.ts","../src/index.ts"],"sourcesContent":["import snakeCase from 'lodash.snakecase';\nimport pluralize from 'pluralize';\nimport { join } from 'path';\nimport { CommonRelationOrTableOrForeignKeyProps } from './global';\n\n// Types\n\ntype SubjectProps = CommonRelationOrTableOrForeignKeyProps & {\n subject: string;\n};\n\ntype ObjectProps = CommonRelationOrTableOrForeignKeyProps & {\n object: string;\n};\n\ntype ViaProps = string | undefined;\n\n/*\n Gets the SQL table for the subject, either from the options object or the\n plural version of the subject model.\n*/\nexport function getSubjectTable({ subject, options }: SubjectProps) {\n return options?.subjectTable || pluralize(snakeCase(subject));\n}\n\n/*\n Gets the SQL table for the object, either from the options object or the\n plural version of the object model.\n*/\nexport function getObjectTable({ object, options }: ObjectProps) {\n return options?.objectTable || pluralize(snakeCase(object));\n}\n\n/*\n Gets the SQL foreign key for the subject, either from the options object \n or the snake case of the subject model.\n*/\nexport function getSubjectForeignKey({ subject, options }: SubjectProps) {\n return options?.subjectForeignKey || snakeCase(subject) + '_id';\n}\n\n/*\n Gets the SQL foreign key for the object, either from the options object \n or the snake case of the object model.\n*/\nexport function getObjectForeignKey({ object, options }: ObjectProps) {\n return options?.objectForeignKey || snakeCase(object) + '_id';\n}\n\n/*\n\tAllows you to define the model path for a model\n*/\nexport function getModelClass({ object, options }: ObjectProps) {\n return options?.modelPath ? join(options.modelPath, object) : object;\n}\n\nexport function getViaTable(via: ViaProps) {\n return via ? pluralize(snakeCase(via)) : null;\n}\n","// Dependencies\nimport { Model } from 'objection';\nimport {\n RelationTypeProps,\n CommonRelationOrTableOrForeignKeyProps,\n} from './global';\nimport {\n getSubjectTable,\n getSubjectForeignKey,\n getObjectTable,\n getObjectForeignKey,\n getModelClass,\n getViaTable,\n} from './helpers';\n\nconst {\n HasOneRelation,\n BelongsToOneRelation,\n HasManyRelation,\n ManyToManyRelation,\n} = Model;\n\n// Types\n\ntype AdvancedRelationTypeProps = RelationTypeProps & {\n through: {\n from: string;\n to: string;\n };\n};\n\n/*\n Defines a relationship where a record in one model can belong to a record in\n another model.\n*/\nexport function belongsRelation({ modelClass, from, to }: RelationTypeProps) {\n return {\n relation: BelongsToOneRelation,\n modelClass,\n join: { from, to },\n };\n}\n\n/*\n\tDefines a relationship where a record in one model can own a record in another\n\tmodel.\n*/\nexport function hasOneRelation({ modelClass, from, to }: RelationTypeProps) {\n return {\n relation: HasOneRelation,\n modelClass,\n join: { from, to },\n };\n}\n\n/*\n\tDefines a relationship where a record in one model can own many records in\n\tanother model.\n*/\nexport function hasManyRelation({ modelClass, from, to }: RelationTypeProps) {\n return {\n relation: HasManyRelation,\n modelClass,\n join: { from, to },\n };\n}\n\n/*\n\tDefines a relationship where a record in one model can own many records in\n\tanother model, via a join table\n*/\nexport function hasManyThroughRelation({\n modelClass,\n from,\n through,\n to,\n}: AdvancedRelationTypeProps) {\n return {\n relation: ManyToManyRelation,\n modelClass,\n join: { from, through, to },\n };\n}\n\ntype RelationProps = CommonRelationOrTableOrForeignKeyProps & {\n subject: string;\n relType: 'hasOne' | 'hasMany' | 'hasManyThrough' | 'belongsTo';\n object: string;\n via?: string;\n};\n\n/*\n\tDefines a relationship by passing the subject, the predicate, and the object,\n\talong with an optional via model.\n*/\nexport function relation({\n subject,\n relType,\n object,\n via,\n options,\n}: RelationProps) {\n const subjectTable = getSubjectTable({ subject, options });\n const objectTable = getObjectTable({ object, options });\n const subjectForeignKey = getSubjectForeignKey({ subject, options });\n const objectForeignKey = getObjectForeignKey({ object, options });\n const modelClass = getModelClass({ object, options });\n const viaTable = getViaTable(via);\n switch (relType) {\n case 'hasOne':\n return hasOneRelation({\n modelClass,\n from: `${subjectTable}.id`,\n to: `${objectTable}.${subjectForeignKey}`,\n });\n case 'hasMany':\n return hasManyRelation({\n modelClass,\n from: `${subjectTable}.id`,\n to: `${objectTable}.${subjectForeignKey}`,\n });\n case 'hasManyThrough':\n return hasManyThroughRelation({\n modelClass,\n from: `${subjectTable}.id`,\n through: {\n from: `${viaTable}.${subjectForeignKey}`,\n to: `${viaTable}.${objectForeignKey}`,\n },\n to: `${objectTable}.id`,\n });\n case 'belongsTo':\n return belongsRelation({\n modelClass,\n from: `${subjectTable}.${objectForeignKey}`,\n to: `${objectTable}.id`,\n });\n default:\n throw new Error('No valid relationship type specified');\n }\n}\n","// Dependencies\nimport { OptionsProps } from './global';\nimport { relation } from './relations';\n\n// Types\n\ntype ObjectionRelationProps = {\n subject: string;\n modelPath: string;\n};\n\nexport class ObjectionRelation {\n subject: string;\n modelPath: string;\n constructor({ subject, modelPath }: ObjectionRelationProps) {\n this.subject = subject;\n this.modelPath = modelPath;\n }\n\n belongsTo(object: string, options?: OptionsProps) {\n if (!options) options = { modelPath: this.modelPath };\n if (!options.modelPath) options.modelPath = this.modelPath;\n return relation({\n subject: this.subject,\n relType: 'belongsTo',\n object,\n options,\n });\n }\n\n hasOne(object: string, options?: OptionsProps) {\n if (!options) options = { modelPath: this.modelPath };\n if (!options.modelPath) options.modelPath = this.modelPath;\n return relation({\n subject: this.subject,\n relType: 'hasOne',\n object,\n options,\n });\n }\n\n hasMany(object: string, options?: OptionsProps) {\n if (!options) options = { modelPath: this.modelPath };\n if (!options.modelPath) options.modelPath = this.modelPath;\n return relation({\n subject: this.subject,\n relType: 'hasMany',\n object,\n options,\n });\n }\n\n hasManyThrough(object: string, via: string, options?: OptionsProps) {\n if (!options) options = { modelPath: this.modelPath };\n if (!options.modelPath) options.modelPath = this.modelPath;\n return relation({\n subject: this.subject,\n relType: 'hasManyThrough',\n object,\n via,\n options,\n });\n }\n}\n"],"names":["getSubjectTable","subject","options","subjectTable","pluralize","snakeCase","getObjectTable","object","objectTable","getSubjectForeignKey","subjectForeignKey","getObjectForeignKey","objectForeignKey","getModelClass","modelPath","join","getViaTable","via","HasOneRelation","BelongsToOneRelation","HasManyRelation","ManyToManyRelation","Model","belongsRelation","modelClass","from","to","relation","hasOneRelation","hasManyRelation","hasManyThroughRelation","through","relType","viaTable","Error","ObjectionRelation","constructor","belongsTo","hasOne","hasMany","hasManyThrough"],"mappings":";;;;;AAiBA;;;;;SAIgBA,gBAAgB;AAAEC,EAAAA,OAAF;AAAWC,EAAAA;AAAX;AAC9B,SAAO,CAAAA,OAAO,QAAP,YAAAA,OAAO,CAAEC,YAAT,KAAyBC,SAAS,CAACC,SAAS,CAACJ,OAAD,CAAV,CAAzC;AACD;AAED;;;;;SAIgBK,eAAe;AAAEC,EAAAA,MAAF;AAAUL,EAAAA;AAAV;AAC7B,SAAO,CAAAA,OAAO,QAAP,YAA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R,GAAoB,KAAKA,SAAzB;AACxB,WAAOa,QAAQ,CAAC;AACd1B,MAAAA,OAAO,EAAE,KAAKA,OADA;AAEd+B,MAAAA,OAAO,EAAE,gBAFK;AAGdzB,MAAAA,MAHc;AAIdU,MAAAA,GAJc;AAKdf,MAAAA;AALc,KAAD,CAAf;AAOD;;;;;;"}
|
package/dist/relations.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { RelationTypeProps, CommonRelationOrTableOrForeignKeyProps } from './global';
|
|
2
|
-
declare type AdvancedRelationTypeProps = RelationTypeProps & {
|
|
3
|
-
through: {
|
|
4
|
-
from: string;
|
|
5
|
-
to: string;
|
|
6
|
-
};
|
|
7
|
-
};
|
|
8
|
-
export declare function belongsRelation({ modelClass, from, to }: RelationTypeProps): {
|
|
9
|
-
relation: import("objection").RelationType;
|
|
10
|
-
modelClass: string;
|
|
11
|
-
join: {
|
|
12
|
-
from: string;
|
|
13
|
-
to: string;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
export declare function hasOneRelation({ modelClass, from, to }: RelationTypeProps): {
|
|
17
|
-
relation: import("objection").RelationType;
|
|
18
|
-
modelClass: string;
|
|
19
|
-
join: {
|
|
20
|
-
from: string;
|
|
21
|
-
to: string;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
export declare function hasManyRelation({ modelClass, from, to }: RelationTypeProps): {
|
|
25
|
-
relation: import("objection").RelationType;
|
|
26
|
-
modelClass: string;
|
|
27
|
-
join: {
|
|
28
|
-
from: string;
|
|
29
|
-
to: string;
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
export declare function hasManyThroughRelation({ modelClass, from, through, to, }: AdvancedRelationTypeProps): {
|
|
33
|
-
relation: import("objection").RelationType;
|
|
34
|
-
modelClass: string;
|
|
35
|
-
join: {
|
|
36
|
-
from: string;
|
|
37
|
-
through: {
|
|
38
|
-
from: string;
|
|
39
|
-
to: string;
|
|
40
|
-
};
|
|
41
|
-
to: string;
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
declare type RelationProps = CommonRelationOrTableOrForeignKeyProps & {
|
|
45
|
-
subject: string;
|
|
46
|
-
relType: 'hasOne' | 'hasMany' | 'hasManyThrough' | 'belongsTo';
|
|
47
|
-
object: string;
|
|
48
|
-
via?: string;
|
|
49
|
-
};
|
|
50
|
-
export declare function relation({ subject, relType, object, via, options, }: RelationProps): {
|
|
51
|
-
relation: import("objection").RelationType;
|
|
52
|
-
modelClass: string;
|
|
53
|
-
join: {
|
|
54
|
-
from: string;
|
|
55
|
-
to: string;
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
export {};
|