@palmares/schemas 0.0.1 → 0.1.1

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.
Files changed (175) hide show
  1. package/.turbo/turbo-build$colon$watch.log +12 -410
  2. package/.turbo/turbo-build.log +13 -4
  3. package/CHANGELOG.md +26 -0
  4. package/__tests__/.drizzle/migrations/0000_skinny_harrier.sql +22 -0
  5. package/__tests__/.drizzle/migrations/meta/0000_snapshot.json +156 -0
  6. package/__tests__/.drizzle/migrations/meta/_journal.json +13 -0
  7. package/__tests__/.drizzle/schema.ts +35 -0
  8. package/__tests__/drizzle.config.ts +11 -0
  9. package/__tests__/eslint.config.js +10 -0
  10. package/__tests__/manage.ts +5 -0
  11. package/__tests__/node_modules/.bin/drizzle-kit +17 -0
  12. package/__tests__/node_modules/.bin/esbuild +14 -0
  13. package/__tests__/node_modules/.bin/tsc +17 -0
  14. package/__tests__/node_modules/.bin/tsserver +17 -0
  15. package/__tests__/node_modules/.bin/tsx +17 -0
  16. package/__tests__/package.json +36 -0
  17. package/__tests__/sqlite.db +0 -0
  18. package/__tests__/src/core/array.test.ts +130 -0
  19. package/__tests__/src/core/boolean.test.ts +66 -0
  20. package/__tests__/src/core/datetime.test.ts +102 -0
  21. package/__tests__/src/core/index.ts +35 -0
  22. package/__tests__/src/core/model.test.ts +260 -0
  23. package/__tests__/src/core/models.ts +50 -0
  24. package/__tests__/src/core/numbers.test.ts +177 -0
  25. package/__tests__/src/core/object.test.ts +198 -0
  26. package/__tests__/src/core/string.test.ts +222 -0
  27. package/__tests__/src/core/test.test.ts +59 -0
  28. package/__tests__/src/core/types.test.ts +97 -0
  29. package/__tests__/src/core/union.test.ts +99 -0
  30. package/__tests__/src/settings.ts +71 -0
  31. package/__tests__/tsconfig.json +11 -0
  32. package/dist/cjs/src/adapter/fields/index.js +2 -2
  33. package/dist/cjs/src/adapter/fields/object.js +9 -0
  34. package/dist/cjs/src/adapter/index.js +1 -0
  35. package/dist/cjs/src/constants.js +1 -7
  36. package/dist/cjs/src/domain.js +146 -1
  37. package/dist/cjs/src/index.js +69 -74
  38. package/dist/cjs/src/model.js +206 -206
  39. package/dist/cjs/src/schema/array.js +185 -58
  40. package/dist/cjs/src/schema/boolean.js +105 -44
  41. package/dist/cjs/src/schema/datetime.js +104 -38
  42. package/dist/cjs/src/schema/number.js +134 -114
  43. package/dist/cjs/src/schema/object.js +106 -43
  44. package/dist/cjs/src/schema/schema.js +123 -75
  45. package/dist/cjs/src/schema/string.js +152 -58
  46. package/dist/cjs/src/schema/union.js +412 -290
  47. package/dist/cjs/src/utils.js +42 -15
  48. package/dist/cjs/src/validators/array.js +6 -1
  49. package/dist/cjs/src/validators/boolean.js +2 -0
  50. package/dist/cjs/src/validators/datetime.js +4 -0
  51. package/dist/cjs/src/validators/number.js +12 -40
  52. package/dist/cjs/src/validators/object.js +1 -0
  53. package/dist/cjs/src/validators/schema.js +5 -1
  54. package/dist/cjs/src/validators/string.js +30 -2
  55. package/dist/cjs/src/validators/union.js +5 -4
  56. package/dist/cjs/src/validators/utils.js +99 -27
  57. package/dist/cjs/tsconfig.types.tsbuildinfo +1 -1
  58. package/dist/cjs/types/adapter/fields/array.d.ts +2 -2
  59. package/dist/cjs/types/adapter/fields/array.d.ts.map +1 -1
  60. package/dist/cjs/types/adapter/fields/boolean.d.ts.map +1 -1
  61. package/dist/cjs/types/adapter/fields/datetime.d.ts.map +1 -1
  62. package/dist/cjs/types/adapter/fields/index.d.ts +2 -2
  63. package/dist/cjs/types/adapter/fields/index.d.ts.map +1 -1
  64. package/dist/cjs/types/adapter/fields/number.d.ts.map +1 -1
  65. package/dist/cjs/types/adapter/fields/object.d.ts +2 -1
  66. package/dist/cjs/types/adapter/fields/object.d.ts.map +1 -1
  67. package/dist/cjs/types/adapter/fields/string.d.ts.map +1 -1
  68. package/dist/cjs/types/adapter/fields/union.d.ts.map +1 -1
  69. package/dist/cjs/types/adapter/index.d.ts +1 -0
  70. package/dist/cjs/types/adapter/index.d.ts.map +1 -1
  71. package/dist/cjs/types/adapter/types.d.ts +28 -18
  72. package/dist/cjs/types/adapter/types.d.ts.map +1 -1
  73. package/dist/cjs/types/constants.d.ts +0 -1
  74. package/dist/cjs/types/constants.d.ts.map +1 -1
  75. package/dist/cjs/types/domain.d.ts +5 -4
  76. package/dist/cjs/types/domain.d.ts.map +1 -1
  77. package/dist/cjs/types/index.d.ts +78 -55
  78. package/dist/cjs/types/index.d.ts.map +1 -1
  79. package/dist/cjs/types/model.d.ts +17 -17
  80. package/dist/cjs/types/model.d.ts.map +1 -1
  81. package/dist/cjs/types/schema/array.d.ts +168 -47
  82. package/dist/cjs/types/schema/array.d.ts.map +1 -1
  83. package/dist/cjs/types/schema/boolean.d.ts +103 -44
  84. package/dist/cjs/types/schema/boolean.d.ts.map +1 -1
  85. package/dist/cjs/types/schema/datetime.d.ts +90 -30
  86. package/dist/cjs/types/schema/datetime.d.ts.map +1 -1
  87. package/dist/cjs/types/schema/number.d.ts +133 -125
  88. package/dist/cjs/types/schema/number.d.ts.map +1 -1
  89. package/dist/cjs/types/schema/object.d.ts +104 -35
  90. package/dist/cjs/types/schema/object.d.ts.map +1 -1
  91. package/dist/cjs/types/schema/schema.d.ts +62 -44
  92. package/dist/cjs/types/schema/schema.d.ts.map +1 -1
  93. package/dist/cjs/types/schema/string.d.ts +152 -65
  94. package/dist/cjs/types/schema/string.d.ts.map +1 -1
  95. package/dist/cjs/types/schema/types.d.ts +11 -2
  96. package/dist/cjs/types/schema/types.d.ts.map +1 -1
  97. package/dist/cjs/types/schema/union.d.ts +133 -40
  98. package/dist/cjs/types/schema/union.d.ts.map +1 -1
  99. package/dist/cjs/types/types.d.ts +35 -0
  100. package/dist/cjs/types/types.d.ts.map +1 -1
  101. package/dist/cjs/types/utils.d.ts +41 -27
  102. package/dist/cjs/types/utils.d.ts.map +1 -1
  103. package/dist/cjs/types/validators/array.d.ts.map +1 -1
  104. package/dist/cjs/types/validators/boolean.d.ts.map +1 -1
  105. package/dist/cjs/types/validators/datetime.d.ts.map +1 -1
  106. package/dist/cjs/types/validators/number.d.ts +5 -6
  107. package/dist/cjs/types/validators/number.d.ts.map +1 -1
  108. package/dist/cjs/types/validators/object.d.ts.map +1 -1
  109. package/dist/cjs/types/validators/schema.d.ts +2 -2
  110. package/dist/cjs/types/validators/schema.d.ts.map +1 -1
  111. package/dist/cjs/types/validators/string.d.ts +9 -9
  112. package/dist/cjs/types/validators/string.d.ts.map +1 -1
  113. package/dist/cjs/types/validators/utils.d.ts +44 -27
  114. package/dist/cjs/types/validators/utils.d.ts.map +1 -1
  115. package/dist/esm/src/adapter/fields/index.js +2 -2
  116. package/dist/esm/src/adapter/fields/object.js +6 -0
  117. package/dist/esm/src/adapter/index.js +1 -0
  118. package/dist/esm/src/constants.js +1 -2
  119. package/dist/esm/src/domain.js +11 -1
  120. package/dist/esm/src/index.js +38 -73
  121. package/dist/esm/src/model.js +83 -78
  122. package/dist/esm/src/schema/array.js +136 -54
  123. package/dist/esm/src/schema/boolean.js +98 -44
  124. package/dist/esm/src/schema/datetime.js +91 -38
  125. package/dist/esm/src/schema/number.js +127 -110
  126. package/dist/esm/src/schema/object.js +98 -43
  127. package/dist/esm/src/schema/schema.js +102 -67
  128. package/dist/esm/src/schema/string.js +147 -59
  129. package/dist/esm/src/schema/union.js +119 -40
  130. package/dist/esm/src/types.js +14 -1
  131. package/dist/esm/src/utils.js +56 -27
  132. package/dist/esm/src/validators/array.js +6 -1
  133. package/dist/esm/src/validators/boolean.js +2 -0
  134. package/dist/esm/src/validators/datetime.js +4 -0
  135. package/dist/esm/src/validators/number.js +9 -23
  136. package/dist/esm/src/validators/object.js +1 -0
  137. package/dist/esm/src/validators/schema.js +5 -1
  138. package/dist/esm/src/validators/string.js +30 -2
  139. package/dist/esm/src/validators/union.js +5 -4
  140. package/dist/esm/src/validators/utils.js +62 -36
  141. package/package.json +3 -3
  142. package/src/adapter/fields/array.ts +2 -2
  143. package/src/adapter/fields/boolean.ts +3 -8
  144. package/src/adapter/fields/datetime.ts +3 -9
  145. package/src/adapter/fields/index.ts +11 -11
  146. package/src/adapter/fields/number.ts +3 -9
  147. package/src/adapter/fields/object.ts +13 -10
  148. package/src/adapter/fields/string.ts +3 -9
  149. package/src/adapter/fields/union.ts +3 -9
  150. package/src/adapter/index.ts +1 -0
  151. package/src/adapter/types.ts +60 -45
  152. package/src/constants.ts +1 -3
  153. package/src/domain.ts +15 -1
  154. package/src/index.ts +189 -211
  155. package/src/model.ts +119 -115
  156. package/src/schema/array.ts +274 -90
  157. package/src/schema/boolean.ts +145 -60
  158. package/src/schema/datetime.ts +133 -49
  159. package/src/schema/number.ts +210 -173
  160. package/src/schema/object.ts +167 -74
  161. package/src/schema/schema.ts +205 -126
  162. package/src/schema/string.ts +221 -94
  163. package/src/schema/types.ts +44 -16
  164. package/src/schema/union.ts +193 -68
  165. package/src/types.ts +53 -0
  166. package/src/utils.ts +115 -57
  167. package/src/validators/array.ts +46 -27
  168. package/src/validators/boolean.ts +13 -7
  169. package/src/validators/datetime.ts +24 -16
  170. package/src/validators/number.ts +53 -63
  171. package/src/validators/object.ts +6 -5
  172. package/src/validators/schema.ts +33 -25
  173. package/src/validators/string.ts +122 -59
  174. package/src/validators/union.ts +8 -8
  175. package/src/validators/utils.ts +67 -42
@@ -409,218 +409,218 @@ function modelSchema(model, options) {
409
409
  lazyModelSchema.__model = model;
410
410
  // Add this callback to transform the model fields
411
411
  parentSchema.__runBeforeParseAndData = /*#__PURE__*/ _async_to_generator(function() {
412
- var fieldsOfModels, fieldsAsEntries, fieldsWithAutomaticRelations, fields, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _loop, _iterator, _step;
412
+ var promise;
413
413
  return _ts_generator(this, function(_state) {
414
- switch(_state.label){
415
- case 0:
416
- if (parentSchema.__alreadyAppliedModel) return [
417
- 2
418
- ];
419
- parentSchema.__alreadyAppliedModel = true;
420
- fieldsOfModels = model._fields();
421
- fieldsAsEntries = Object.entries(fieldsOfModels);
422
- fieldsWithAutomaticRelations = new Map();
423
- return [
424
- 4,
425
- fieldsAsEntries.reduce(function() {
426
- var _ref = _async_to_generator(function(accumulatorAsPromise, param) {
427
- var _param, key, value, schema, optionsForForeignKeyRelation, _parentSchema___getParent, newSchema, _optionsForForeignKeyRelation_foreignKeyRelation, rootSchema, existingRelations, accumulator;
428
- return _ts_generator(this, function(_state) {
429
- switch(_state.label){
430
- case 0:
431
- _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
432
- if (omitAsSet.has(key)) return [
433
- 2,
434
- accumulatorAsPromise
435
- ];
436
- if (showAsSet.size > 0 && !showAsSet.has(key)) return [
437
- 2,
438
- accumulatorAsPromise
439
- ];
440
- schema = fieldsAsObject[key];
441
- optionsForForeignKeyRelation = {};
442
- if (!(!schema || _instanceof(value, _databases.ForeignKeyField))) return [
443
- 3,
444
- 2
445
- ];
446
- return [
447
- 4,
448
- getSchemaFromModelField(model, value, parentSchema === null || parentSchema === void 0 ? void 0 : (_parentSchema___getParent = parentSchema.__getParent) === null || _parentSchema___getParent === void 0 ? void 0 : _parentSchema___getParent.call(parentSchema), options === null || options === void 0 ? void 0 : options.fields, options === null || options === void 0 ? void 0 : options.engineInstance, optionsForForeignKeyRelation)
449
- ];
450
- case 1:
451
- newSchema = _state.sent();
452
- if (!schema) schema = newSchema;
453
- _state.label = 2;
454
- case 2:
455
- // Appends the foreign key relation to the schema automatically.
456
- if (optionsForForeignKeyRelation.foreignKeyRelation) {
457
- ;
458
- rootSchema = (optionsForForeignKeyRelation === null || optionsForForeignKeyRelation === void 0 ? void 0 : (_optionsForForeignKeyRelation_foreignKeyRelation = optionsForForeignKeyRelation.foreignKeyRelation) === null || _optionsForForeignKeyRelation_foreignKeyRelation === void 0 ? void 0 : _optionsForForeignKeyRelation_foreignKeyRelation.schema) || lazyModelSchema;
459
- existingRelations = fieldsWithAutomaticRelations.get(rootSchema) || [];
460
- existingRelations.push({
461
- relationOrRelatedName: optionsForForeignKeyRelation.foreignKeyRelation.relationOrRelatedName,
462
- isArray: optionsForForeignKeyRelation.foreignKeyRelation.isArray,
463
- model: optionsForForeignKeyRelation.foreignKeyRelation.model,
464
- fieldToSearchOnModel: optionsForForeignKeyRelation.foreignKeyRelation.fieldToSearchOnModel,
465
- fieldToGetFromData: optionsForForeignKeyRelation.foreignKeyRelation.fieldToGetFromData
466
- });
467
- fieldsWithAutomaticRelations.set(rootSchema, existingRelations);
468
- }
469
- return [
470
- 4,
471
- accumulatorAsPromise
472
- ];
473
- case 3:
474
- accumulator = _state.sent();
475
- accumulator[key] = schema;
476
- return [
477
- 2,
478
- accumulator
479
- ];
414
+ promise = new Promise(function(resolve) {
415
+ var fieldsOfModels = model._fields();
416
+ var fieldsAsEntries = Object.entries(fieldsOfModels);
417
+ var fieldsWithAutomaticRelations = new Map();
418
+ var fields = fieldsAsObject;
419
+ Promise.all(fieldsAsEntries.map(function() {
420
+ var _ref = _async_to_generator(function(param) {
421
+ var _param, key, value, schema, optionsForForeignKeyRelation, _parentSchema___getParent, newSchema, _optionsForForeignKeyRelation_foreignKeyRelation, rootSchema, existingRelations;
422
+ return _ts_generator(this, function(_state) {
423
+ switch(_state.label){
424
+ case 0:
425
+ _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
426
+ if (omitAsSet.has(key)) return [
427
+ 2
428
+ ];
429
+ if (showAsSet.size > 0 && !showAsSet.has(key)) return [
430
+ 2
431
+ ];
432
+ schema = fieldsAsObject[key];
433
+ optionsForForeignKeyRelation = {};
434
+ if (!(!schema || _instanceof(value, _databases.ForeignKeyField))) return [
435
+ 3,
436
+ 2
437
+ ];
438
+ return [
439
+ 4,
440
+ getSchemaFromModelField(model, value, parentSchema === null || parentSchema === void 0 ? void 0 : (_parentSchema___getParent = parentSchema.__getParent) === null || _parentSchema___getParent === void 0 ? void 0 : _parentSchema___getParent.call(parentSchema), options === null || options === void 0 ? void 0 : options.fields, options === null || options === void 0 ? void 0 : options.engineInstance, optionsForForeignKeyRelation)
441
+ ];
442
+ case 1:
443
+ newSchema = _state.sent();
444
+ if (!schema) schema = newSchema;
445
+ _state.label = 2;
446
+ case 2:
447
+ // Appends the foreign key relation to the schema automatically.
448
+ if (optionsForForeignKeyRelation.foreignKeyRelation) {
449
+ ;
450
+ rootSchema = (optionsForForeignKeyRelation === null || optionsForForeignKeyRelation === void 0 ? void 0 : (_optionsForForeignKeyRelation_foreignKeyRelation = optionsForForeignKeyRelation.foreignKeyRelation) === null || _optionsForForeignKeyRelation_foreignKeyRelation === void 0 ? void 0 : _optionsForForeignKeyRelation_foreignKeyRelation.schema) || lazyModelSchema;
451
+ existingRelations = fieldsWithAutomaticRelations.get(rootSchema) || [];
452
+ existingRelations.push({
453
+ relationOrRelatedName: optionsForForeignKeyRelation.foreignKeyRelation.relationOrRelatedName,
454
+ isArray: optionsForForeignKeyRelation.foreignKeyRelation.isArray,
455
+ model: optionsForForeignKeyRelation.foreignKeyRelation.model,
456
+ fieldToSearchOnModel: optionsForForeignKeyRelation.foreignKeyRelation.fieldToSearchOnModel,
457
+ fieldToGetFromData: optionsForForeignKeyRelation.foreignKeyRelation.fieldToGetFromData
458
+ });
459
+ fieldsWithAutomaticRelations.set(rootSchema, existingRelations);
480
460
  }
481
- });
482
- });
483
- return function(accumulatorAsPromise, _) {
484
- return _ref.apply(this, arguments);
485
- };
486
- }(), Promise.resolve(fieldsAsObject))
487
- ];
488
- case 1:
489
- fields = _state.sent();
490
- if (fieldsWithAutomaticRelations.size > 0) {
491
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
492
- try {
493
- _loop = function() {
494
- var _step_value = _sliced_to_array(_step.value, 2), schema = _step_value[0], relations = _step_value[1];
495
- schema.toRepresentation(function() {
496
- var _ref = _async_to_generator(function(data) {
497
- var allData;
498
- return _ts_generator(this, function(_state) {
499
- switch(_state.label){
500
- case 0:
501
- allData = Array.isArray(data) ? data : [
502
- data
503
- ];
504
- // since we are changing the data by reference, just return the data itself.
505
- return [
506
- 4,
507
- Promise.all(allData.map(function() {
508
- var _ref = _async_to_generator(function(data) {
509
- return _ts_generator(this, function(_state) {
510
- return [
511
- 2,
512
- Promise.all(relations.map(function() {
513
- var _ref = _async_to_generator(function(relation) {
514
- var relationData;
515
- return _ts_generator(this, function(_state) {
516
- switch(_state.label){
517
- case 0:
518
- // Ignore if the data of the relation already exists
519
- if (relation.relationOrRelatedName in data) return [
520
- 2
521
- ];
522
- return [
523
- 4,
524
- relation.model.default.get({
525
- search: _define_property({}, relation.fieldToSearchOnModel, data[relation.fieldToGetFromData])
526
- })
527
- ];
528
- case 1:
529
- relationData = _state.sent();
530
- if (relation.isArray !== true) relationData = relationData[0];
531
- data[relation.relationOrRelatedName] = relationData;
532
- if (schema.__omitRelation.has(relation.relationOrRelatedName)) delete data[relation.fieldToGetFromData];
533
- return [
534
- 2
535
- ];
536
- }
537
- });
461
+ fieldsAsObject[key] = schema;
462
+ return [
463
+ 2,
464
+ fieldsAsObject
465
+ ];
466
+ }
467
+ });
468
+ });
469
+ return function(_) {
470
+ return _ref.apply(this, arguments);
471
+ };
472
+ }())).then(/*#__PURE__*/ _async_to_generator(function() {
473
+ var _iteratorNormalCompletion, _didIteratorError, _iteratorError, _loop, _iterator, _step;
474
+ return _ts_generator(this, function(_state) {
475
+ switch(_state.label){
476
+ case 0:
477
+ if (fieldsWithAutomaticRelations.size > 0) {
478
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
479
+ try {
480
+ _loop = function() {
481
+ var _step_value = _sliced_to_array(_step.value, 2), schema = _step_value[0], relations = _step_value[1];
482
+ schema.toRepresentation(function() {
483
+ var _ref = _async_to_generator(function(data) {
484
+ var allData;
485
+ return _ts_generator(this, function(_state) {
486
+ switch(_state.label){
487
+ case 0:
488
+ allData = Array.isArray(data) ? data : [
489
+ data
490
+ ];
491
+ // since we are changing the data by reference, just return the data itself.
492
+ return [
493
+ 4,
494
+ Promise.all(allData.map(function() {
495
+ var _ref = _async_to_generator(function(data) {
496
+ return _ts_generator(this, function(_state) {
497
+ return [
498
+ 2,
499
+ Promise.all(relations.map(function() {
500
+ var _ref = _async_to_generator(function(relation) {
501
+ var relationData;
502
+ return _ts_generator(this, function(_state) {
503
+ switch(_state.label){
504
+ case 0:
505
+ // Ignore if the data of the relation already exists
506
+ if (relation.relationOrRelatedName in data) return [
507
+ 2
508
+ ];
509
+ return [
510
+ 4,
511
+ relation.model.default.get({
512
+ search: _define_property({}, relation.fieldToSearchOnModel, data[relation.fieldToGetFromData])
513
+ })
514
+ ];
515
+ case 1:
516
+ relationData = _state.sent();
517
+ if (relation.isArray !== true) relationData = relationData[0];
518
+ data[relation.relationOrRelatedName] = relationData;
519
+ if (schema.__omitRelation.has(relation.relationOrRelatedName)) delete data[relation.fieldToGetFromData];
520
+ return [
521
+ 2
522
+ ];
523
+ }
524
+ });
525
+ });
526
+ return function(relation) {
527
+ return _ref.apply(this, arguments);
528
+ };
529
+ }()))
530
+ ];
538
531
  });
539
- return function(relation) {
540
- return _ref.apply(this, arguments);
541
- };
542
- }()))
543
- ];
544
- });
545
- });
546
- return function(data) {
547
- return _ref.apply(this, arguments);
548
- };
549
- }()))
550
- ];
551
- case 1:
552
- _state.sent();
553
- return [
554
- 2,
555
- data
556
- ];
532
+ });
533
+ return function(data) {
534
+ return _ref.apply(this, arguments);
535
+ };
536
+ }()))
537
+ ];
538
+ case 1:
539
+ _state.sent();
540
+ return [
541
+ 2,
542
+ data
543
+ ];
544
+ }
545
+ });
546
+ });
547
+ return function(data) {
548
+ return _ref.apply(this, arguments);
549
+ };
550
+ }(), {
551
+ after: true
552
+ });
553
+ };
554
+ // This way we can get all of the relations concurrently with Promise.all
555
+ for(_iterator = fieldsWithAutomaticRelations.entries()[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
556
+ } catch (err) {
557
+ _didIteratorError = true;
558
+ _iteratorError = err;
559
+ } finally{
560
+ try {
561
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
562
+ _iterator.return();
557
563
  }
558
- });
559
- });
560
- return function(data) {
561
- return _ref.apply(this, arguments);
562
- };
563
- }(), {
564
- after: true
565
- });
566
- };
567
- // This way we can get all of the relations concurrently with Promise.all
568
- for(_iterator = fieldsWithAutomaticRelations.entries()[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
569
- } catch (err) {
570
- _didIteratorError = true;
571
- _iteratorError = err;
572
- } finally{
573
- try {
574
- if (!_iteratorNormalCompletion && _iterator.return != null) {
575
- _iterator.return();
576
- }
577
- } finally{
578
- if (_didIteratorError) {
579
- throw _iteratorError;
564
+ } finally{
565
+ if (_didIteratorError) {
566
+ throw _iteratorError;
567
+ }
568
+ }
569
+ }
580
570
  }
581
- }
571
+ lazyModelSchema.__data = fields;
572
+ return [
573
+ 4,
574
+ Promise.all(customFieldValues.map(function() {
575
+ var _ref = _async_to_generator(function(schema) {
576
+ return _ts_generator(this, function(_state) {
577
+ switch(_state.label){
578
+ case 0:
579
+ schema['__getParent'] = function() {
580
+ return lazyModelSchema;
581
+ };
582
+ if (!schema['__runBeforeParseAndData']) return [
583
+ 3,
584
+ 2
585
+ ];
586
+ return [
587
+ 4,
588
+ schema['__runBeforeParseAndData'](schema)
589
+ ];
590
+ case 1:
591
+ _state.sent();
592
+ _state.label = 2;
593
+ case 2:
594
+ return [
595
+ 2
596
+ ];
597
+ }
598
+ });
599
+ });
600
+ return function(schema) {
601
+ return _ref.apply(this, arguments);
602
+ };
603
+ }()))
604
+ ];
605
+ case 1:
606
+ _state.sent();
607
+ resolve(undefined);
608
+ return [
609
+ 2
610
+ ];
582
611
  }
583
- }
584
- lazyModelSchema.__data = fields;
585
- return [
586
- 4,
587
- Promise.all(customFieldValues.map(function() {
588
- var _ref = _async_to_generator(function(schema) {
589
- return _ts_generator(this, function(_state) {
590
- switch(_state.label){
591
- case 0:
592
- schema['__getParent'] = function() {
593
- return lazyModelSchema;
594
- };
595
- if (!schema['__runBeforeParseAndData']) return [
596
- 3,
597
- 2
598
- ];
599
- return [
600
- 4,
601
- schema['__runBeforeParseAndData'](schema)
602
- ];
603
- case 1:
604
- _state.sent();
605
- _state.label = 2;
606
- case 2:
607
- return [
608
- 2
609
- ];
610
- }
611
- });
612
- });
613
- return function(schema) {
614
- return _ref.apply(this, arguments);
615
- };
616
- }()))
617
- ];
618
- case 2:
619
- _state.sent();
620
- return [
621
- 2
622
- ];
623
- }
612
+ });
613
+ }));
614
+ });
615
+ if (parentSchema.__alreadyAppliedModel) return [
616
+ 2,
617
+ parentSchema.__alreadyAppliedModel
618
+ ];
619
+ parentSchema.__alreadyAppliedModel = promise;
620
+ return [
621
+ 2,
622
+ promise
623
+ ];
624
624
  });
625
625
  });
626
626
  if ((options === null || options === void 0 ? void 0 : options.ignoreExtraneousFields) !== true) lazyModelSchema.removeExtraneous();