@abedmurrar/objection 4.0.0-beta.6 → 4.0.0-beta.7

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.
@@ -1,53 +1,55 @@
1
- 'use strict';
2
- const { clone } = require('./modelClone');
3
- const { bindKnex } = require('./modelBindKnex');
4
- const { validate } = require('./modelValidate');
5
- const { isMsSql, isMySql } = require('../utils/knexUtils');
6
- const { visitModels } = require('./modelVisitor');
7
- const { hasId, getSetId } = require('./modelId');
8
- const { map: promiseMap } = require('../utils/promiseUtils');
9
- const { toJson, toDatabaseJson } = require('./modelToJson');
10
- const { values, propKey, hasProps } = require('./modelValues');
11
- const { defineNonEnumerableProperty } = require('./modelUtils');
12
- const { parseRelationsIntoModelInstances } = require('./modelParseRelations');
13
- const { fetchTableMetadata, tableMetadata } = require('./modelTableMetadata');
14
- const { asArray, isFunction, isString, asSingle } = require('../utils/objectUtils');
15
- const { setJson, setFast, setRelated, appendRelated, setDatabaseJson } = require('./modelSet');
16
- const { getJsonAttributes, parseJsonAttributes, formatJsonAttributes, } = require('./modelJsonAttributes');
17
- const { columnNameToPropertyName, propertyNameToColumnName } = require('./modelColPropMap');
18
- const { raw } = require('../queryBuilder/RawBuilder');
19
- const { ref } = require('../queryBuilder/ReferenceBuilder');
20
- const { fn } = require('../queryBuilder/FunctionBuilder');
21
- const { AjvValidator } = require('./AjvValidator');
22
- const { QueryBuilder } = require('../queryBuilder/QueryBuilder');
23
- const { markDefaultStaticHook } = require('../queryBuilder/StaticHookArguments');
24
- const { setDefaultGetConcurrency } = require('./modelConcurrency');
25
- const { NotFoundError } = require('./NotFoundError');
26
- const { ValidationError } = require('./ValidationError');
27
- const { ModifierNotFoundError } = require('./ModifierNotFoundError');
28
- const { RelationProperty } = require('../relations/RelationProperty');
29
- const { RelationOwner } = require('../relations/RelationOwner');
30
- const { HasOneRelation } = require('../relations/hasOne/HasOneRelation');
31
- const { HasManyRelation } = require('../relations/hasMany/HasManyRelation');
32
- const { ManyToManyRelation } = require('../relations/manyToMany/ManyToManyRelation');
33
- const { BelongsToOneRelation } = require('../relations/belongsToOne/BelongsToOneRelation');
34
- const { HasOneThroughRelation } = require('../relations/hasOneThrough/HasOneThroughRelation');
35
- const { InstanceFindOperation } = require('../queryBuilder/operations/InstanceFindOperation');
36
- const { InstanceInsertOperation } = require('../queryBuilder/operations/InstanceInsertOperation');
37
- const { InstanceUpdateOperation } = require('../queryBuilder/operations/InstanceUpdateOperation');
38
- const { InstanceDeleteOperation } = require('../queryBuilder/operations/InstanceDeleteOperation');
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Model = void 0;
4
+ const modelClone_1 = require("./modelClone");
5
+ const modelBindKnex_1 = require("./modelBindKnex");
6
+ const modelValidate_1 = require("./modelValidate");
7
+ const knexUtils_1 = require("../utils/knexUtils");
8
+ const modelVisitor_1 = require("./modelVisitor");
9
+ const modelId_1 = require("./modelId");
10
+ const promiseUtils_1 = require("../utils/promiseUtils");
11
+ const modelToJson_1 = require("./modelToJson");
12
+ const modelValues_1 = require("./modelValues");
13
+ const modelUtils_1 = require("./modelUtils");
14
+ const modelParseRelations_1 = require("./modelParseRelations");
15
+ const modelTableMetadata_1 = require("./modelTableMetadata");
16
+ const objectUtils_1 = require("../utils/objectUtils");
17
+ const modelSet_1 = require("./modelSet");
18
+ const modelJsonAttributes_1 = require("./modelJsonAttributes");
19
+ const modelColPropMap_1 = require("./modelColPropMap");
20
+ const RawBuilder_1 = require("../queryBuilder/RawBuilder");
21
+ const ReferenceBuilder_1 = require("../queryBuilder/ReferenceBuilder");
22
+ const FunctionBuilder_1 = require("../queryBuilder/FunctionBuilder");
23
+ const AjvValidator_1 = require("./AjvValidator");
24
+ const QueryBuilder_1 = require("../queryBuilder/QueryBuilder");
25
+ const StaticHookArguments_1 = require("../queryBuilder/StaticHookArguments");
26
+ const modelConcurrency_1 = require("./modelConcurrency");
27
+ const NotFoundError_1 = require("./NotFoundError");
28
+ const ValidationError_1 = require("./ValidationError");
29
+ const ModifierNotFoundError_1 = require("./ModifierNotFoundError");
30
+ const RelationProperty_1 = require("../relations/RelationProperty");
31
+ const RelationOwner_1 = require("../relations/RelationOwner");
32
+ const HasOneRelation_1 = require("../relations/hasOne/HasOneRelation");
33
+ const HasManyRelation_1 = require("../relations/hasMany/HasManyRelation");
34
+ const ManyToManyRelation_1 = require("../relations/manyToMany/ManyToManyRelation");
35
+ const BelongsToOneRelation_1 = require("../relations/belongsToOne/BelongsToOneRelation");
36
+ const HasOneThroughRelation_1 = require("../relations/hasOneThrough/HasOneThroughRelation");
37
+ const InstanceFindOperation_1 = require("../queryBuilder/operations/InstanceFindOperation");
38
+ const InstanceInsertOperation_1 = require("../queryBuilder/operations/InstanceInsertOperation");
39
+ const InstanceUpdateOperation_1 = require("../queryBuilder/operations/InstanceUpdateOperation");
40
+ const InstanceDeleteOperation_1 = require("../queryBuilder/operations/InstanceDeleteOperation");
39
41
  class Model {
40
42
  get $modelClass() {
41
43
  return this.constructor;
42
44
  }
43
45
  $id(maybeId) {
44
- return getSetId(this, maybeId);
46
+ return (0, modelId_1.getSetId)(this, maybeId);
45
47
  }
46
48
  $hasId() {
47
- return hasId(this);
49
+ return (0, modelId_1.hasId)(this);
48
50
  }
49
51
  $hasProps(props) {
50
- return hasProps(this, props);
52
+ return (0, modelValues_1.hasProps)(this, props);
51
53
  }
52
54
  $query(trx) {
53
55
  return instanceQuery({
@@ -71,7 +73,7 @@ class Model {
71
73
  return jsonSchema;
72
74
  }
73
75
  $validate(json, options) {
74
- return validate(this, json, options);
76
+ return (0, modelValidate_1.validate)(this, json, options);
75
77
  }
76
78
  $afterValidate(json, options) {
77
79
  // Do nothing by default.
@@ -81,11 +83,11 @@ class Model {
81
83
  if (columnNameMappers) {
82
84
  json = columnNameMappers.parse(json);
83
85
  }
84
- return parseJsonAttributes(json, this.constructor);
86
+ return (0, modelJsonAttributes_1.parseJsonAttributes)(json, this.constructor);
85
87
  }
86
88
  $formatDatabaseJson(json) {
87
89
  const columnNameMappers = this.constructor.getColumnNameMappers();
88
- json = formatJsonAttributes(json, this.constructor);
90
+ json = (0, modelJsonAttributes_1.formatJsonAttributes)(json, this.constructor);
89
91
  if (columnNameMappers) {
90
92
  json = columnNameMappers.format(json);
91
93
  }
@@ -98,28 +100,28 @@ class Model {
98
100
  return json;
99
101
  }
100
102
  $setJson(json, options) {
101
- return setJson(this, json, options);
103
+ return (0, modelSet_1.setJson)(this, json, options);
102
104
  }
103
105
  $setDatabaseJson(json) {
104
- return setDatabaseJson(this, json);
106
+ return (0, modelSet_1.setDatabaseJson)(this, json);
105
107
  }
106
108
  $set(obj) {
107
- return setFast(this, obj);
109
+ return (0, modelSet_1.setFast)(this, obj);
108
110
  }
109
111
  $setRelated(relation, models) {
110
- return setRelated(this, relation, models);
112
+ return (0, modelSet_1.setRelated)(this, relation, models);
111
113
  }
112
114
  $appendRelated(relation, models) {
113
- return appendRelated(this, relation, models);
115
+ return (0, modelSet_1.appendRelated)(this, relation, models);
114
116
  }
115
117
  $toJson(opt) {
116
- return toJson(this, opt);
118
+ return (0, modelToJson_1.toJson)(this, opt);
117
119
  }
118
120
  toJSON(opt) {
119
121
  return this.$toJson(opt);
120
122
  }
121
123
  $toDatabaseJson(builder) {
122
- return toDatabaseJson(this, builder);
124
+ return (0, modelToJson_1.toDatabaseJson)(this, builder);
123
125
  }
124
126
  $beforeInsert(queryContext) {
125
127
  // Do nothing by default.
@@ -143,16 +145,16 @@ class Model {
143
145
  // Do nothing by default.
144
146
  }
145
147
  $values(props) {
146
- return values(this, props);
148
+ return (0, modelValues_1.values)(this, props);
147
149
  }
148
150
  $propKey(props) {
149
- return propKey(this, props);
151
+ return (0, modelValues_1.propKey)(this, props);
150
152
  }
151
153
  $idKey() {
152
154
  return this.$propKey(this.constructor.getIdPropertyArray());
153
155
  }
154
156
  $clone(opt) {
155
- return clone(this, !!(opt && opt.shallow), false);
157
+ return (0, modelClone_1.clone)(this, !!(opt && opt.shallow), false);
156
158
  }
157
159
  $traverse(filterConstructor, callback) {
158
160
  if (callback === undefined) {
@@ -170,24 +172,24 @@ class Model {
170
172
  return this.constructor.traverseAsync(filterConstructor, this, callback);
171
173
  }
172
174
  $omitFromJson(...props) {
173
- if (arguments.length === 0) {
175
+ if (props.length === 0) {
174
176
  return this.$$omitFromJson;
175
177
  }
176
178
  else {
177
179
  if (!Object.hasOwn(this, '$$omitFromJson')) {
178
- defineNonEnumerableProperty(this, '$$omitFromJson', []);
180
+ (0, modelUtils_1.defineNonEnumerableProperty)(this, '$$omitFromJson', []);
179
181
  }
180
182
  this.$$omitFromJson = this.$$omitFromJson.concat(asPropsArray(props));
181
183
  return this;
182
184
  }
183
185
  }
184
186
  $omitFromDatabaseJson(...props) {
185
- if (arguments.length === 0) {
187
+ if (props.length === 0) {
186
188
  return this.$$omitFromDatabaseJson;
187
189
  }
188
190
  else {
189
191
  if (!Object.hasOwn(this, '$$omitFromDatabaseJson')) {
190
- defineNonEnumerableProperty(this, '$$omitFromDatabaseJson', []);
192
+ (0, modelUtils_1.defineNonEnumerableProperty)(this, '$$omitFromDatabaseJson', []);
191
193
  }
192
194
  this.$$omitFromDatabaseJson = this.$$omitFromDatabaseJson.concat(asPropsArray(props));
193
195
  return this;
@@ -249,7 +251,7 @@ class Model {
249
251
  return `${relationPath}_join`;
250
252
  }
251
253
  static createValidator() {
252
- return new AjvValidator({
254
+ return new AjvValidator_1.AjvValidator({
253
255
  options: {
254
256
  allErrors: true,
255
257
  validateSchema: false,
@@ -269,17 +271,17 @@ class Model {
269
271
  }
270
272
  static getTableName() {
271
273
  let tableName = this.tableName;
272
- if (isFunction(tableName)) {
274
+ if ((0, objectUtils_1.isFunction)(tableName)) {
273
275
  tableName = this.tableName();
274
276
  }
275
- if (!isString(tableName)) {
277
+ if (!(0, objectUtils_1.isString)(tableName)) {
276
278
  throw new Error(`Model ${this.name} must have a static property tableName`);
277
279
  }
278
280
  return tableName;
279
281
  }
280
282
  static getIdColumn() {
281
283
  let idColumn = this.idColumn;
282
- if (isFunction(idColumn)) {
284
+ if ((0, objectUtils_1.isFunction)(idColumn)) {
283
285
  idColumn = this.idColumn();
284
286
  }
285
287
  return idColumn;
@@ -291,7 +293,7 @@ class Model {
291
293
  return cachedGet(this, '$$jsonSchema', getJsonSchema);
292
294
  }
293
295
  static getJsonAttributes() {
294
- return cachedGet(this, '$$jsonAttributes', getJsonAttributes);
296
+ return cachedGet(this, '$$jsonAttributes', modelJsonAttributes_1.getJsonAttributes);
295
297
  }
296
298
  static getColumnNameMappers() {
297
299
  return cachedGet(this, '$$columnNameMappers', getColumnNameMappers);
@@ -306,7 +308,7 @@ class Model {
306
308
  // On MySQL, concurrent graph updates and deletes deadlock: MySQL needs
307
309
  // them wrapped in a subquery, which locks the rows of the join tables
308
310
  // it reads.
309
- if (isMsSql(knex) || isMySql(knex)) {
311
+ if ((0, knexUtils_1.isMsSql)(knex) || (0, knexUtils_1.isMySql)(knex)) {
310
312
  return 1;
311
313
  }
312
314
  else {
@@ -314,7 +316,7 @@ class Model {
314
316
  }
315
317
  }
316
318
  else {
317
- if (isFunction(this.concurrency)) {
319
+ if ((0, objectUtils_1.isFunction)(this.concurrency)) {
318
320
  return this.concurrency();
319
321
  }
320
322
  else {
@@ -329,7 +331,7 @@ class Model {
329
331
  const colToProp = cachedGet(this, '$$colToProp', () => new Map());
330
332
  let propertyName = colToProp.get(columnName);
331
333
  if (!propertyName) {
332
- propertyName = columnNameToPropertyName(this, columnName);
334
+ propertyName = (0, modelColPropMap_1.columnNameToPropertyName)(this, columnName);
333
335
  colToProp.set(columnName, propertyName);
334
336
  }
335
337
  return propertyName;
@@ -338,7 +340,7 @@ class Model {
338
340
  const propToCol = cachedGet(this, '$$propToCol', () => new Map());
339
341
  let columnName = propToCol.get(propertyName);
340
342
  if (!columnName) {
341
- columnName = propertyNameToColumnName(this, propertyName);
343
+ columnName = (0, modelColPropMap_1.propertyNameToColumnName)(this, propertyName);
342
344
  propToCol.set(propertyName, columnName);
343
345
  }
344
346
  return columnName;
@@ -403,14 +405,14 @@ class Model {
403
405
  });
404
406
  }
405
407
  static fetchTableMetadata(opt) {
406
- return fetchTableMetadata(this, opt);
408
+ return (0, modelTableMetadata_1.fetchTableMetadata)(this, opt);
407
409
  }
408
410
  static tableMetadata(opt) {
409
- return tableMetadata(this, opt);
411
+ return (0, modelTableMetadata_1.tableMetadata)(this, opt);
410
412
  }
411
413
  static knex(...args) {
412
414
  if (args.length) {
413
- defineNonEnumerableProperty(this, '$$knex', args[0]);
415
+ (0, modelUtils_1.defineNonEnumerableProperty)(this, '$$knex', args[0]);
414
416
  }
415
417
  else {
416
418
  return this.$$knex;
@@ -428,15 +430,15 @@ class Model {
428
430
  return transaction.start(knexOrTrx || this.knex());
429
431
  }
430
432
  static get raw() {
431
- return raw;
433
+ return RawBuilder_1.raw;
432
434
  }
433
435
  static get ref() {
434
436
  return (...args) => {
435
- return ref(...args).model(this);
437
+ return (0, ReferenceBuilder_1.ref)(...args).model(this);
436
438
  };
437
439
  }
438
440
  static get fn() {
439
- return fn;
441
+ return FunctionBuilder_1.fn;
440
442
  }
441
443
  static knexQuery() {
442
444
  return this.knex().table(this.getTableName());
@@ -450,10 +452,10 @@ class Model {
450
452
  }
451
453
  }
452
454
  static bindKnex(knex) {
453
- return bindKnex(this, knex);
455
+ return (0, modelBindKnex_1.bindKnex)(this, knex);
454
456
  }
455
457
  static bindTransaction(trx) {
456
- return bindKnex(this, trx);
458
+ return (0, modelBindKnex_1.bindKnex)(this, trx);
457
459
  }
458
460
  static ensureModel(model, options) {
459
461
  const modelClass = this;
@@ -461,7 +463,7 @@ class Model {
461
463
  return null;
462
464
  }
463
465
  if (model instanceof modelClass) {
464
- return parseRelationsIntoModelInstances(model, model, options);
466
+ return (0, modelParseRelations_1.parseRelationsIntoModelInstances)(model, model, options);
465
467
  }
466
468
  else {
467
469
  return modelClass.fromJson(model, options);
@@ -488,7 +490,7 @@ class Model {
488
490
  return null;
489
491
  }
490
492
  if (!Object.hasOwn(this, '$$relations')) {
491
- defineNonEnumerableProperty(this, '$$relations', Object.create(null));
493
+ (0, modelUtils_1.defineNonEnumerableProperty)(this, '$$relations', Object.create(null));
492
494
  }
493
495
  if (!this.$$relations[name]) {
494
496
  this.$$relations[name] = new mapping.relation(name, this);
@@ -512,11 +514,11 @@ class Model {
512
514
  }
513
515
  static traverse(...args) {
514
516
  const { traverser, models, filterConstructor } = getTraverseArgs(...args);
515
- if (!asSingle(models)) {
517
+ if (!(0, objectUtils_1.asSingle)(models)) {
516
518
  return;
517
519
  }
518
- const modelClass = asSingle(models).constructor;
519
- visitModels(models, modelClass, (model, _, parent, relation) => {
520
+ const modelClass = (0, objectUtils_1.asSingle)(models).constructor;
521
+ (0, modelVisitor_1.visitModels)(models, modelClass, (model, _, parent, relation) => {
520
522
  if (!filterConstructor || model instanceof filterConstructor) {
521
523
  traverser(model, parent, relation && relation.name);
522
524
  }
@@ -525,20 +527,23 @@ class Model {
525
527
  }
526
528
  static traverseAsync(...args) {
527
529
  const { traverser, models, filterConstructor } = getTraverseArgs(...args);
528
- if (!asSingle(models)) {
530
+ if (!(0, objectUtils_1.asSingle)(models)) {
529
531
  return Promise.resolve();
530
532
  }
531
- const modelClass = asSingle(models).constructor;
533
+ const modelClass = (0, objectUtils_1.asSingle)(models).constructor;
532
534
  const promises = [];
533
- visitModels(models, modelClass, (model, _, parent, relation) => {
535
+ (0, modelVisitor_1.visitModels)(models, modelClass, (model, _, parent, relation) => {
534
536
  if (!filterConstructor || model instanceof filterConstructor) {
535
537
  const maybePromise = traverser(model, parent, relation && relation.name);
536
538
  promises.push(maybePromise);
537
539
  }
538
540
  });
539
- return promiseMap(promises, (it) => it, { concurrency: this.getConcurrency(this.knex()) });
541
+ return (0, promiseUtils_1.map)(promises, (it) => it, {
542
+ concurrency: this.getConcurrency(this.knex()),
543
+ });
540
544
  }
541
545
  }
546
+ exports.Model = Model;
542
547
  Object.defineProperties(Model, {
543
548
  isObjectionModelClass: {
544
549
  enumerable: false,
@@ -568,21 +573,21 @@ for (const hookName of [
568
573
  'beforeDelete',
569
574
  'afterDelete',
570
575
  ]) {
571
- markDefaultStaticHook(Model[hookName]);
576
+ (0, StaticHookArguments_1.markDefaultStaticHook)(Model[hookName]);
572
577
  }
573
- setDefaultGetConcurrency(Model.getConcurrency);
574
- Model.QueryBuilder = QueryBuilder;
575
- Model.HasOneRelation = HasOneRelation;
576
- Model.HasManyRelation = HasManyRelation;
577
- Model.ManyToManyRelation = ManyToManyRelation;
578
- Model.BelongsToOneRelation = BelongsToOneRelation;
579
- Model.HasOneThroughRelation = HasOneThroughRelation;
578
+ (0, modelConcurrency_1.setDefaultGetConcurrency)(Model.getConcurrency);
579
+ Model.QueryBuilder = QueryBuilder_1.QueryBuilder;
580
+ Model.HasOneRelation = HasOneRelation_1.HasOneRelation;
581
+ Model.HasManyRelation = HasManyRelation_1.HasManyRelation;
582
+ Model.ManyToManyRelation = ManyToManyRelation_1.ManyToManyRelation;
583
+ Model.BelongsToOneRelation = BelongsToOneRelation_1.BelongsToOneRelation;
584
+ Model.HasOneThroughRelation = HasOneThroughRelation_1.HasOneThroughRelation;
580
585
  Model.JoinEagerAlgorithm = 'JoinEagerAlgorithm';
581
586
  Model.NaiveEagerAlgorithm = 'NaiveEagerAlgorithm';
582
587
  Model.WhereInEagerAlgorithm = 'WhereInEagerAlgorithm';
583
- Model.ValidationError = ValidationError;
584
- Model.NotFoundError = NotFoundError;
585
- Model.ModifierNotFoundError = ModifierNotFoundError;
588
+ Model.ValidationError = ValidationError_1.ValidationError;
589
+ Model.NotFoundError = NotFoundError_1.NotFoundError;
590
+ Model.ModifierNotFoundError = ModifierNotFoundError_1.ModifierNotFoundError;
586
591
  Model.tableName = null;
587
592
  Model.jsonSchema = null;
588
593
  Model.idColumn = 'id';
@@ -604,27 +609,27 @@ Model.columnNameMappers = null;
604
609
  Model.relatedFindQueryMutates = false;
605
610
  Model.relatedInsertQueryMutates = false;
606
611
  Model.concurrency = null;
607
- function instanceQuery({ instance, transaction }) {
612
+ function instanceQuery({ instance, transaction, }) {
608
613
  const modelClass = instance.constructor;
609
614
  return modelClass
610
615
  .query(transaction)
611
616
  .findOperationFactory(() => {
612
- return new InstanceFindOperation('find', { instance });
617
+ return new InstanceFindOperation_1.InstanceFindOperation('find', { instance });
613
618
  })
614
619
  .insertOperationFactory(() => {
615
- return new InstanceInsertOperation('insert', { instance });
620
+ return new InstanceInsertOperation_1.InstanceInsertOperation('insert', { instance });
616
621
  })
617
622
  .updateOperationFactory(() => {
618
- return new InstanceUpdateOperation('update', { instance });
623
+ return new InstanceUpdateOperation_1.InstanceUpdateOperation('update', { instance });
619
624
  })
620
625
  .patchOperationFactory(() => {
621
- return new InstanceUpdateOperation('patch', {
626
+ return new InstanceUpdateOperation_1.InstanceUpdateOperation('patch', {
622
627
  instance,
623
628
  modelOptions: { patch: true },
624
629
  });
625
630
  })
626
631
  .deleteOperationFactory(() => {
627
- return new InstanceDeleteOperation('delete', { instance });
632
+ return new InstanceDeleteOperation_1.InstanceDeleteOperation('delete', { instance });
628
633
  })
629
634
  .relateOperationFactory(() => {
630
635
  throw new Error('`relate` makes no sense in this context');
@@ -633,7 +638,7 @@ function instanceQuery({ instance, transaction }) {
633
638
  throw new Error('`unrelate` makes no sense in this context');
634
639
  });
635
640
  }
636
- function relatedQuery({ modelClass, relationName, transaction, alwaysReturnArray } = {}) {
641
+ function relatedQuery({ modelClass, relationName, transaction, alwaysReturnArray, } = {}) {
637
642
  const relation = modelClass.getRelation(relationName);
638
643
  const relatedModelClass = relation.relatedModelClass;
639
644
  const query = relatedModelClass
@@ -641,8 +646,8 @@ function relatedQuery({ modelClass, relationName, transaction, alwaysReturnArray
641
646
  .findOperationFactory((builder) => {
642
647
  const isSubQuery = !builder.for();
643
648
  const owner = isSubQuery
644
- ? RelationOwner.createParentReference(builder, relation)
645
- : RelationOwner.create(builder.for());
649
+ ? RelationOwner_1.RelationOwner.createParentReference(builder, relation)
650
+ : RelationOwner_1.RelationOwner.create(builder.for());
646
651
  const operation = relation.find(builder, owner);
647
652
  operation.assignResultToOwner = modelClass.getRelatedFindQueryMutates();
648
653
  operation.alwaysReturnArray = alwaysReturnArray;
@@ -686,11 +691,11 @@ function writeOperationOwner(builder, method) {
686
691
  // when the query is built or executed.
687
692
  builder._forError = new Error(`relatedQuery(): for() must be called before ${method}()`);
688
693
  }
689
- return RelationOwner.create(owner);
694
+ return RelationOwner_1.RelationOwner.create(owner);
690
695
  }
691
696
  function cachedGet(target, hiddenPropertyName, creator) {
692
697
  if (!Object.hasOwn(target, hiddenPropertyName)) {
693
- defineNonEnumerableProperty(target, hiddenPropertyName, creator(target));
698
+ (0, modelUtils_1.defineNonEnumerableProperty)(target, hiddenPropertyName, creator(target));
694
699
  }
695
700
  return target[hiddenPropertyName];
696
701
  }
@@ -704,8 +709,8 @@ function getColumnNameMappers(modelClass) {
704
709
  return modelClass.columnNameMappers;
705
710
  }
706
711
  function getIdRelationProperty(modelClass) {
707
- const idColumn = asArray(modelClass.getIdColumn());
708
- return new RelationProperty(idColumn.map((idCol) => `${modelClass.getTableName()}.${idCol}`), () => modelClass);
712
+ const idColumn = (0, objectUtils_1.asArray)(modelClass.getIdColumn());
713
+ return new RelationProperty_1.RelationProperty(idColumn.map((idCol) => `${modelClass.getTableName()}.${idCol}`), () => modelClass);
709
714
  }
710
715
  function getReadOnlyAttributes(modelClass) {
711
716
  return [...new Set(getReadOnlyAttributesRecursively(modelClass))];
@@ -720,13 +725,13 @@ function getReadOnlyAttributesRecursively(modelClass) {
720
725
  ...getReadOnlyAttributes(Object.getPrototypeOf(modelClass)),
721
726
  ...propertyNames.filter((propName) => {
722
727
  const desc = Object.getOwnPropertyDescriptor(modelClass.prototype, propName);
723
- return (desc.get && !desc.set) || desc.writable === false || isFunction(desc.value);
728
+ return (desc.get && !desc.set) || desc.writable === false || (0, objectUtils_1.isFunction)(desc.value);
724
729
  }),
725
730
  ];
726
731
  }
727
732
  function getRelationMappings(modelClass) {
728
733
  let relationMappings = modelClass.relationMappings;
729
- if (isFunction(relationMappings)) {
734
+ if ((0, objectUtils_1.isFunction)(relationMappings)) {
730
735
  relationMappings = relationMappings.call(modelClass);
731
736
  }
732
737
  return relationMappings || {};
@@ -744,7 +749,7 @@ function getTraverseArgs(filterConstructor, models, traverser) {
744
749
  models = filterConstructor;
745
750
  filterConstructor = null;
746
751
  }
747
- if (!isFunction(traverser)) {
752
+ if (!(0, objectUtils_1.isFunction)(traverser)) {
748
753
  throw new Error('traverser must be a function');
749
754
  }
750
755
  return {
@@ -767,6 +772,3 @@ function asPropsArray(props) {
767
772
  }
768
773
  return props;
769
774
  }
770
- module.exports = {
771
- Model,
772
- };
@@ -1,10 +1,10 @@
1
- 'use strict';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ModifierNotFoundError = void 0;
2
4
  class ModifierNotFoundError extends Error {
3
5
  constructor(modifierName) {
4
6
  super(`Unable to determine modify function from provided value: "${modifierName}".`);
5
7
  this.modifierName = modifierName;
6
8
  }
7
9
  }
8
- module.exports = {
9
- ModifierNotFoundError,
10
- };
10
+ exports.ModifierNotFoundError = ModifierNotFoundError;
@@ -1,4 +1,6 @@
1
- 'use strict';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotFoundError = void 0;
2
4
  class NotFoundError extends Error {
3
5
  constructor({ modelClass, data = {}, statusCode = 404, ...rest } = {}) {
4
6
  super(rest.message || 'NotFoundError');
@@ -14,6 +16,4 @@ class NotFoundError extends Error {
14
16
  });
15
17
  }
16
18
  }
17
- module.exports = {
18
- NotFoundError,
19
- };
19
+ exports.NotFoundError = NotFoundError;
@@ -1,4 +1,6 @@
1
- 'use strict';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RelationDoesNotExistError = void 0;
2
4
  class RelationDoesNotExistError extends Error {
3
5
  constructor(relationName) {
4
6
  super(`unknown relation "${relationName}" in a relation expression`);
@@ -6,6 +8,4 @@ class RelationDoesNotExistError extends Error {
6
8
  this.relationName = relationName;
7
9
  }
8
10
  }
9
- module.exports = {
10
- RelationDoesNotExistError,
11
- };
11
+ exports.RelationDoesNotExistError = RelationDoesNotExistError;
@@ -1,11 +1,14 @@
1
- 'use strict';
2
- const { asArray, isString } = require('../utils/objectUtils');
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValidationErrorType = exports.ValidationError = void 0;
4
+ const objectUtils_1 = require("../utils/objectUtils");
3
5
  const ValidationErrorType = {
4
6
  ModelValidation: 'ModelValidation',
5
7
  RelationExpression: 'RelationExpression',
6
8
  UnallowedRelation: 'UnallowedRelation',
7
9
  InvalidGraph: 'InvalidGraph',
8
10
  };
11
+ exports.ValidationErrorType = ValidationErrorType;
9
12
  class ValidationError extends Error {
10
13
  static get Type() {
11
14
  return ValidationErrorType;
@@ -24,23 +27,20 @@ class ValidationError extends Error {
24
27
  });
25
28
  }
26
29
  }
30
+ exports.ValidationError = ValidationError;
27
31
  function errorsToMessage(data) {
28
32
  return Object.keys(data)
29
33
  .reduce((messages, key) => {
30
- messages.push(`${key}: ${asArray(data[key]).map(message).join(', ')}`);
34
+ messages.push(`${key}: ${(0, objectUtils_1.asArray)(data[key]).map(message).join(', ')}`);
31
35
  return messages;
32
36
  }, [])
33
37
  .join(', ');
34
38
  }
35
39
  function message(it) {
36
- if (isString(it)) {
40
+ if ((0, objectUtils_1.isString)(it)) {
37
41
  return it;
38
42
  }
39
43
  else {
40
44
  return it.message;
41
45
  }
42
46
  }
43
- module.exports = {
44
- ValidationError,
45
- ValidationErrorType,
46
- };
@@ -1,13 +1,16 @@
1
- 'use strict';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Validator = void 0;
2
4
  class Validator {
3
5
  constructor(...args) {
4
6
  this.constructor.init(this, ...args);
5
7
  }
6
- static init() { }
8
+ static init(..._args) { }
7
9
  beforeValidate({ model, json, options }) {
8
10
  model.$beforeValidate(null, json, options);
9
11
  }
10
- validate() {
12
+ // A rest parameter keeps `validate.length` 0, as it was in JavaScript.
13
+ validate(..._args) {
11
14
  /* istanbul ignore next */
12
15
  throw new Error('not implemented');
13
16
  }
@@ -15,6 +18,4 @@ class Validator {
15
18
  model.$afterValidate(json, options);
16
19
  }
17
20
  }
18
- module.exports = {
19
- Validator,
20
- };
21
+ exports.Validator = Validator;
@@ -1,7 +1,7 @@
1
- 'use strict';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getModel = void 0;
2
4
  // A small helper method for cached lazy-importing of the Model class.
3
5
  let Model;
4
6
  const getModel = () => Model || (Model = require('./Model').Model);
5
- module.exports = {
6
- getModel,
7
- };
7
+ exports.getModel = getModel;