@rvoh/dream 1.2.1 → 1.3.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.
- package/dist/cjs/src/Dream.js +101 -33
- package/dist/cjs/src/db/errors.js +16 -6
- package/dist/cjs/src/dream/QueryDriver/Kysely.js +33 -20
- package/dist/cjs/src/dream/internal/printSerializerHierarchyLevel.js +17 -0
- package/dist/cjs/src/dream-app/cache.js +12 -2
- package/dist/cjs/src/errors/db/CheckConstraintViolation.js +15 -0
- package/dist/cjs/src/errors/db/DataTypeColumnTypeMismatch.js +1 -5
- package/dist/cjs/src/errors/db/NotNullViolation.js +15 -0
- package/dist/cjs/src/helpers/cli/generateMigration.js +1 -0
- package/dist/cjs/src/helpers/cli/generateMigrationContent.js +20 -5
- package/dist/cjs/src/helpers/cli/generateStiMigrationContent.js +8 -2
- package/dist/cjs/src/index.js +6 -2
- package/dist/cjs/src/serializer/helpers/serializerForAssociatedClass.js +3 -2
- package/dist/esm/src/Dream.js +102 -34
- package/dist/esm/src/db/errors.js +14 -4
- package/dist/esm/src/dream/QueryDriver/Kysely.js +34 -21
- package/dist/esm/src/dream/internal/printSerializerHierarchyLevel.js +14 -0
- package/dist/esm/src/dream-app/cache.js +12 -2
- package/dist/esm/src/errors/db/CheckConstraintViolation.js +12 -0
- package/dist/esm/src/errors/db/DataTypeColumnTypeMismatch.js +1 -5
- package/dist/esm/src/errors/db/NotNullViolation.js +12 -0
- package/dist/esm/src/helpers/cli/generateMigration.js +1 -0
- package/dist/esm/src/helpers/cli/generateMigrationContent.js +20 -5
- package/dist/esm/src/helpers/cli/generateStiMigrationContent.js +8 -2
- package/dist/esm/src/index.js +2 -0
- package/dist/esm/src/serializer/helpers/serializerForAssociatedClass.js +3 -2
- package/dist/types/src/Dream.d.ts +77 -52
- package/dist/types/src/db/errors.d.ts +14 -2
- package/dist/types/src/dream/QueryDriver/Kysely.d.ts +1 -0
- package/dist/types/src/dream/internal/printSerializerHierarchyLevel.d.ts +7 -0
- package/dist/types/src/errors/db/CheckConstraintViolation.d.ts +10 -0
- package/dist/types/src/errors/db/NotNullViolation.d.ts +10 -0
- package/dist/types/src/helpers/cli/generateMigrationContent.d.ts +2 -1
- package/dist/types/src/helpers/cli/generateStiMigrationContent.d.ts +2 -1
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/serializer/builders/DreamSerializerBuilder.d.ts +1 -1
- package/dist/types/src/types/dream.d.ts +1 -1
- package/dist/types/src/types/dream.ts +2 -2
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/Benchmark.html +2 -2
- package/docs/classes/CalendarDate.html +2 -2
- package/docs/classes/CheckConstraintViolation.html +14 -0
- package/docs/classes/CliFileWriter.html +2 -2
- package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +3 -3
- package/docs/classes/DataTypeColumnTypeMismatch.html +3 -3
- package/docs/classes/Decorators.html +19 -19
- package/docs/classes/Dream.html +209 -308
- package/docs/classes/DreamApp.html +4 -4
- package/docs/classes/DreamBin.html +2 -2
- package/docs/classes/DreamCLI.html +4 -4
- package/docs/classes/DreamImporter.html +2 -2
- package/docs/classes/DreamLogos.html +2 -2
- package/docs/classes/DreamMigrationHelpers.html +7 -7
- package/docs/classes/DreamSerializerBuilder.html +8 -8
- package/docs/classes/DreamTransaction.html +2 -2
- package/docs/classes/Encrypt.html +2 -2
- package/docs/classes/Env.html +2 -2
- package/docs/classes/GlobalNameNotSet.html +3 -3
- package/docs/classes/NonLoadedAssociation.html +3 -3
- package/docs/classes/NotNullViolation.html +14 -0
- package/docs/classes/ObjectSerializerBuilder.html +8 -8
- package/docs/classes/Query.html +60 -60
- package/docs/classes/Range.html +2 -2
- package/docs/classes/RecordNotFound.html +3 -3
- package/docs/classes/ValidationError.html +3 -3
- package/docs/functions/DreamSerializer.html +1 -1
- package/docs/functions/ObjectSerializer.html +1 -1
- package/docs/functions/ReplicaSafe.html +1 -1
- package/docs/functions/STI.html +1 -1
- package/docs/functions/SoftDelete.html +1 -1
- package/docs/functions/camelize.html +1 -1
- package/docs/functions/capitalize.html +1 -1
- package/docs/functions/cloneDeepSafe.html +1 -1
- package/docs/functions/closeAllDbConnections.html +1 -1
- package/docs/functions/compact.html +1 -1
- package/docs/functions/dreamDbConnections.html +1 -1
- package/docs/functions/dreamPath.html +1 -1
- package/docs/functions/expandStiClasses.html +1 -1
- package/docs/functions/generateDream.html +1 -1
- package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -1
- package/docs/functions/groupBy.html +1 -1
- package/docs/functions/hyphenize.html +1 -1
- package/docs/functions/inferSerializerFromDreamOrViewModel.html +1 -1
- package/docs/functions/inferSerializersFromDreamClassOrViewModelClass.html +1 -1
- package/docs/functions/intersection.html +1 -1
- package/docs/functions/isDreamSerializer.html +1 -1
- package/docs/functions/isEmpty.html +1 -1
- package/docs/functions/loadRepl.html +1 -1
- package/docs/functions/lookupClassByGlobalName.html +1 -1
- package/docs/functions/normalizeUnicode.html +1 -1
- package/docs/functions/pascalize.html +1 -1
- package/docs/functions/pgErrorType.html +1 -1
- package/docs/functions/range-1.html +1 -1
- package/docs/functions/relativeDreamPath.html +1 -1
- package/docs/functions/round.html +1 -1
- package/docs/functions/serializerNameFromFullyQualifiedModelName.html +1 -1
- package/docs/functions/sharedPathPrefix.html +1 -1
- package/docs/functions/snakeify.html +1 -1
- package/docs/functions/sort.html +1 -1
- package/docs/functions/sortBy.html +1 -1
- package/docs/functions/sortObjectByKey.html +1 -1
- package/docs/functions/sortObjectByValue.html +1 -1
- package/docs/functions/standardizeFullyQualifiedModelName.html +1 -1
- package/docs/functions/uncapitalize.html +1 -1
- package/docs/functions/uniq.html +1 -1
- package/docs/functions/untypedDb.html +1 -1
- package/docs/functions/validateColumn.html +1 -1
- package/docs/functions/validateTable.html +1 -1
- package/docs/interfaces/BelongsToStatement.html +2 -2
- package/docs/interfaces/DecoratorContext.html +2 -2
- package/docs/interfaces/DreamAppInitOptions.html +2 -2
- package/docs/interfaces/DreamAppOpts.html +2 -2
- package/docs/interfaces/EncryptOptions.html +2 -2
- package/docs/interfaces/InternalAnyTypedSerializerRendersMany.html +2 -2
- package/docs/interfaces/InternalAnyTypedSerializerRendersOne.html +2 -2
- package/docs/interfaces/OpenapiDescription.html +2 -2
- package/docs/interfaces/OpenapiSchemaProperties.html +1 -1
- package/docs/interfaces/OpenapiSchemaPropertiesShorthand.html +1 -1
- package/docs/interfaces/OpenapiTypeFieldObject.html +1 -1
- package/docs/interfaces/SerializerRendererOpts.html +2 -2
- package/docs/modules.html +2 -0
- package/docs/types/Camelized.html +1 -1
- package/docs/types/CommonOpenapiSchemaObjectFields.html +1 -1
- package/docs/types/DateTime.html +1 -1
- package/docs/types/DbConnectionType.html +1 -1
- package/docs/types/DbTypes.html +1 -1
- package/docs/types/DreamAppAllowedPackageManagersEnum.html +1 -1
- package/docs/types/DreamAssociationMetadata.html +1 -1
- package/docs/types/DreamAttributes.html +1 -1
- package/docs/types/DreamClassAssociationAndStatement.html +1 -1
- package/docs/types/DreamClassColumn.html +1 -1
- package/docs/types/DreamColumn.html +1 -1
- package/docs/types/DreamColumnNames.html +1 -1
- package/docs/types/DreamLogLevel.html +1 -1
- package/docs/types/DreamLogger.html +1 -1
- package/docs/types/DreamModelSerializerType.html +1 -1
- package/docs/types/DreamOrViewModelClassSerializerKey.html +1 -1
- package/docs/types/DreamOrViewModelSerializerKey.html +1 -1
- package/docs/types/DreamParamSafeAttributes.html +1 -1
- package/docs/types/DreamParamSafeColumnNames.html +1 -1
- package/docs/types/DreamSerializable.html +1 -1
- package/docs/types/DreamSerializableArray.html +1 -1
- package/docs/types/DreamSerializerKey.html +1 -1
- package/docs/types/DreamSerializers.html +1 -1
- package/docs/types/DreamTableSchema.html +1 -1
- package/docs/types/DreamVirtualColumns.html +1 -1
- package/docs/types/EncryptAlgorithm.html +1 -1
- package/docs/types/HasManyStatement.html +1 -1
- package/docs/types/HasOneStatement.html +1 -1
- package/docs/types/Hyphenized.html +1 -1
- package/docs/types/IdType.html +1 -1
- package/docs/types/OpenapiAllTypes.html +1 -1
- package/docs/types/OpenapiFormats.html +1 -1
- package/docs/types/OpenapiNumberFormats.html +1 -1
- package/docs/types/OpenapiPrimitiveBaseTypes.html +1 -1
- package/docs/types/OpenapiPrimitiveTypes.html +1 -1
- package/docs/types/OpenapiSchemaArray.html +1 -1
- package/docs/types/OpenapiSchemaArrayShorthand.html +1 -1
- package/docs/types/OpenapiSchemaBase.html +1 -1
- package/docs/types/OpenapiSchemaBody.html +1 -1
- package/docs/types/OpenapiSchemaBodyShorthand.html +1 -1
- package/docs/types/OpenapiSchemaCommonFields.html +1 -1
- package/docs/types/OpenapiSchemaExpressionAllOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionOneOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionRef.html +1 -1
- package/docs/types/OpenapiSchemaExpressionRefSchemaShorthand.html +1 -1
- package/docs/types/OpenapiSchemaInteger.html +1 -1
- package/docs/types/OpenapiSchemaNull.html +1 -1
- package/docs/types/OpenapiSchemaNumber.html +1 -1
- package/docs/types/OpenapiSchemaObject.html +1 -1
- package/docs/types/OpenapiSchemaObjectAllOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectAllOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectAnyOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectBase.html +1 -1
- package/docs/types/OpenapiSchemaObjectBaseShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectOneOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectOneOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectShorthand.html +1 -1
- package/docs/types/OpenapiSchemaPrimitiveGeneric.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionAllOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionOneOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
- package/docs/types/OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
- package/docs/types/OpenapiSchemaString.html +1 -1
- package/docs/types/OpenapiShorthandAllTypes.html +1 -1
- package/docs/types/OpenapiShorthandPrimitiveBaseTypes.html +1 -1
- package/docs/types/OpenapiShorthandPrimitiveTypes.html +1 -1
- package/docs/types/OpenapiTypeField.html +1 -1
- package/docs/types/Pascalized.html +1 -1
- package/docs/types/PrimaryKeyType.html +1 -1
- package/docs/types/RoundingPrecision.html +1 -1
- package/docs/types/SerializerCasing.html +1 -1
- package/docs/types/SimpleObjectSerializerType.html +1 -1
- package/docs/types/Snakeified.html +1 -1
- package/docs/types/Timestamp.html +1 -1
- package/docs/types/UpdateableAssociationProperties.html +1 -1
- package/docs/types/UpdateableProperties.html +1 -1
- package/docs/types/ValidationType.html +1 -1
- package/docs/types/ViewModel.html +1 -1
- package/docs/types/ViewModelClass.html +1 -1
- package/docs/types/WhereStatementForDream.html +1 -1
- package/docs/types/WhereStatementForDreamClass.html +1 -1
- package/docs/variables/DateTime-1.html +1 -1
- package/docs/variables/DreamAppAllowedPackageManagersEnumValues.html +1 -1
- package/docs/variables/DreamConst.html +1 -1
- package/docs/variables/TRIGRAM_OPERATORS.html +1 -1
- package/docs/variables/openapiPrimitiveTypes-1.html +1 -1
- package/docs/variables/openapiShorthandPrimitiveTypes-1.html +1 -1
- package/docs/variables/ops.html +1 -1
- package/docs/variables/primaryKeyTypes.html +1 -1
- package/package.json +1 -1
package/dist/cjs/src/Dream.js
CHANGED
|
@@ -21,6 +21,7 @@ const destroyDream_js_1 = require("./dream/internal/destroyDream.js");
|
|
|
21
21
|
const destroyOptions_js_1 = require("./dream/internal/destroyOptions.js");
|
|
22
22
|
const ensureSTITypeFieldIsSet_js_1 = require("./dream/internal/ensureSTITypeFieldIsSet.js");
|
|
23
23
|
const findOrCreateBy_js_1 = require("./dream/internal/findOrCreateBy.js");
|
|
24
|
+
const printSerializerHierarchyLevel_js_1 = require("./dream/internal/printSerializerHierarchyLevel.js");
|
|
24
25
|
const reload_js_1 = require("./dream/internal/reload.js");
|
|
25
26
|
const runValidations_js_1 = require("./dream/internal/runValidations.js");
|
|
26
27
|
const saveDream_js_1 = require("./dream/internal/saveDream.js");
|
|
@@ -49,10 +50,8 @@ const cloneDeepSafe_js_1 = require("./helpers/cloneDeepSafe.js");
|
|
|
49
50
|
const DateTime_js_1 = require("./helpers/DateTime.js");
|
|
50
51
|
const cachedTypeForAttribute_js_1 = require("./helpers/db/cachedTypeForAttribute.js");
|
|
51
52
|
const isJsonColumn_js_1 = require("./helpers/db/types/isJsonColumn.js");
|
|
52
|
-
const indent_js_1 = require("./helpers/indent.js");
|
|
53
53
|
const notEqual_js_1 = require("./helpers/notEqual.js");
|
|
54
54
|
const inferSerializerFromDreamOrViewModel_js_1 = require("./serializer/helpers/inferSerializerFromDreamOrViewModel.js");
|
|
55
|
-
const serializerForAssociatedClass_js_1 = require("./serializer/helpers/serializerForAssociatedClass.js");
|
|
56
55
|
class Dream {
|
|
57
56
|
DB;
|
|
58
57
|
/**
|
|
@@ -489,42 +488,65 @@ class Dream {
|
|
|
489
488
|
static recursiveSerializationMap(serializer, { forDisplay = false, forDisplayDepth = 0, } = {}) {
|
|
490
489
|
const serializerBuilder = serializer(undefined, undefined);
|
|
491
490
|
const serializerAssociations = serializerBuilder['attributes'].filter(attribute => ['rendersOne', 'rendersMany', 'delegatedAttribute'].includes(attribute.type));
|
|
492
|
-
return serializerAssociations.reduce((
|
|
491
|
+
return serializerAssociations.reduce((accumulator, serializerAssociation) => {
|
|
493
492
|
const serializerAssociationName = serializerAssociation.targetName ??
|
|
494
493
|
serializerAssociation.name;
|
|
495
494
|
const serializerAssociationType = serializerAssociation.type;
|
|
496
495
|
const association = this['getAssociationMetadata'](serializerAssociationName);
|
|
497
496
|
if (!association)
|
|
498
|
-
return
|
|
499
|
-
const
|
|
500
|
-
|
|
501
|
-
if (!associatedClass)
|
|
497
|
+
return accumulator;
|
|
498
|
+
const maybeAssociatedClasses = association.modelCB();
|
|
499
|
+
if (!maybeAssociatedClasses)
|
|
502
500
|
throw new Error(`No class defined on ${serializerAssociationName} association on ${this.sanitizedName}`);
|
|
503
|
-
const
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
501
|
+
const associatedClasses = Array.isArray(maybeAssociatedClasses)
|
|
502
|
+
? maybeAssociatedClasses
|
|
503
|
+
: [maybeAssociatedClasses];
|
|
504
|
+
/////////////////////////////////////////////////
|
|
505
|
+
// map associated classes to their serializers //
|
|
506
|
+
/////////////////////////////////////////////////
|
|
507
|
+
const associatedClassSerializerTuples = associatedClasses.flatMap(associatedClass => {
|
|
508
|
+
/**
|
|
509
|
+
* `serializers` is an array because `associatedClass` may be an STI
|
|
510
|
+
* base, with each of its STI children having its own serializer
|
|
511
|
+
*/
|
|
512
|
+
const serializers = serializerAssociation.options.serializer
|
|
513
|
+
? [serializerAssociation.options.serializer]
|
|
514
|
+
: (0, inferSerializerFromDreamOrViewModel_js_1.inferSerializersFromDreamClassOrViewModelClass)(associatedClass, serializerAssociation.options.serializerKey);
|
|
515
|
+
if (!serializers.length)
|
|
516
|
+
throw new Error(`No serializer found to render ${serializerAssociationName} on ${this.sanitizedName}`);
|
|
517
|
+
return serializers.map(serializer => [associatedClass, serializer]);
|
|
518
|
+
});
|
|
519
|
+
/////////////////////////////////////////////////////
|
|
520
|
+
// end:map associated classes to their serializers //
|
|
521
|
+
/////////////////////////////////////////////////////
|
|
522
|
+
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
523
|
+
// reduce over all associated serializers, recursively building out their associated serializers //
|
|
524
|
+
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
525
|
+
const innerAssociationSerializerInfo = associatedClassSerializerTuples.reduce((innerAccumulator, [associatedClass, associatedSerializer]) => {
|
|
526
|
+
if (forDisplay && serializerAssociationType !== 'delegatedAttribute') {
|
|
527
|
+
(0, printSerializerHierarchyLevel_js_1.default)({
|
|
528
|
+
serializerAssociationType,
|
|
529
|
+
serializerAssociationName,
|
|
530
|
+
associationSerializer: associatedSerializer,
|
|
531
|
+
forDisplayDepth,
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
return {
|
|
535
|
+
...innerAccumulator,
|
|
536
|
+
...associatedClass['recursiveSerializationMap'](associatedSerializer, {
|
|
523
537
|
forDisplay,
|
|
524
538
|
forDisplayDepth: forDisplayDepth + 1,
|
|
525
539
|
}),
|
|
540
|
+
};
|
|
541
|
+
}, {});
|
|
542
|
+
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
543
|
+
// end:reduce over all associated serializers, recursively building out their associated serializers //
|
|
544
|
+
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
545
|
+
accumulator[association.as] = {
|
|
546
|
+
parentDreamClass: this,
|
|
547
|
+
nestedSerializerInfo: serializerAssociation.type === 'delegatedAttribute' ? {} : innerAssociationSerializerInfo,
|
|
526
548
|
};
|
|
527
|
-
return
|
|
549
|
+
return accumulator;
|
|
528
550
|
}, {});
|
|
529
551
|
}
|
|
530
552
|
/**
|
|
@@ -659,11 +681,57 @@ class Dream {
|
|
|
659
681
|
return map;
|
|
660
682
|
}
|
|
661
683
|
/**
|
|
662
|
-
*
|
|
684
|
+
* Checks whether the specified association has been defined on this Dream model.
|
|
685
|
+
*
|
|
686
|
+
* ```ts
|
|
687
|
+
* const user = User.new()
|
|
688
|
+
*
|
|
689
|
+
* user.hasAssociation('posts')
|
|
690
|
+
* // true (if User has a posts association defined)
|
|
691
|
+
*
|
|
692
|
+
* user.hasAssociation('nonExistentAssociation')
|
|
693
|
+
* // false
|
|
694
|
+
*
|
|
695
|
+
* // Useful for conditional association handling
|
|
696
|
+
* if (user.hasAssociation('posts')) {
|
|
697
|
+
* user = await user.load('posts').execute()
|
|
698
|
+
* }
|
|
699
|
+
* ```
|
|
700
|
+
*
|
|
701
|
+
* @param associationName - The name of the association to check for
|
|
702
|
+
* @returns `true` if the association exists on this model, `false` otherwise
|
|
703
|
+
*/
|
|
704
|
+
hasAssociation(associationName) {
|
|
705
|
+
return !!(this.associationMetadataByType.belongsTo.find(association => association.as === associationName) ||
|
|
706
|
+
this.associationMetadataByType.hasOne.find(association => association.as === associationName) ||
|
|
707
|
+
this.associationMetadataByType.hasMany.find(association => association.as === associationName));
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Returns all of the association names for this Dream class.
|
|
711
|
+
* This includes all BelongsTo, HasOne, and HasMany associations
|
|
712
|
+
* defined on the model.
|
|
663
713
|
*
|
|
664
|
-
*
|
|
714
|
+
* This is useful for introspection, debugging, or dynamically working
|
|
715
|
+
* with all associations on a model.
|
|
716
|
+
*
|
|
717
|
+
* ```ts
|
|
718
|
+
* class User extends ApplicationModel {
|
|
719
|
+
* @deco.HasMany('Post')
|
|
720
|
+
* public posts: Post[]
|
|
721
|
+
*
|
|
722
|
+
* @deco.HasOne('Profile')
|
|
723
|
+
* public profile: Profile
|
|
724
|
+
*
|
|
725
|
+
* @deco.BelongsTo('Company')
|
|
726
|
+
* public company: Company
|
|
727
|
+
* }
|
|
728
|
+
*
|
|
729
|
+
* User.associationNames
|
|
730
|
+
* // ['posts', 'profile', 'company']
|
|
731
|
+
* })
|
|
732
|
+
* ```
|
|
665
733
|
*
|
|
666
|
-
* @returns
|
|
734
|
+
* @returns An array containing all association names defined on this Dream class
|
|
667
735
|
*/
|
|
668
736
|
static get associationNames() {
|
|
669
737
|
const allAssociations = [
|
|
@@ -855,7 +923,7 @@ class Dream {
|
|
|
855
923
|
return dreamModel;
|
|
856
924
|
}
|
|
857
925
|
catch (err) {
|
|
858
|
-
if ((0, errors_js_1.pgErrorType)(err) ===
|
|
926
|
+
if ((0, errors_js_1.pgErrorType)(err) === errors_js_1.UNIQUE_VIOLATION) {
|
|
859
927
|
const dreamModel = await this.findBy(this.extractAttributesFromUpdateableProperties(attributes));
|
|
860
928
|
if (!dreamModel)
|
|
861
929
|
throw new CreateOrFindByFailedToCreateAndFind_js_1.default(this);
|
|
@@ -909,7 +977,7 @@ class Dream {
|
|
|
909
977
|
}, skipHooks ? { skipHooks } : undefined);
|
|
910
978
|
}
|
|
911
979
|
catch (err) {
|
|
912
|
-
if ((0, errors_js_1.pgErrorType)(err) ===
|
|
980
|
+
if ((0, errors_js_1.pgErrorType)(err) === errors_js_1.UNIQUE_VIOLATION) {
|
|
913
981
|
const existingRecord = await this.findBy(this.extractAttributesFromUpdateableProperties(attributes));
|
|
914
982
|
if (!existingRecord)
|
|
915
983
|
throw new CreateOrUpdateByFailedToCreateAndUpdate_js_1.default(this);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PG_ERRORS = void 0;
|
|
3
|
+
exports.PG_ERRORS = exports.UNIQUE_VIOLATION = exports.RESTRICT_VIOLATION = exports.NOT_NULL_VIOLATION = exports.INVALID_INPUT_SYNTAX = exports.INTEGRITY_CONSTRAINT_VIOLATION = exports.FOREIGN_KEY_VIOLATION = exports.CHECK_VIOLATION = void 0;
|
|
4
4
|
exports.pgErrorType = pgErrorType;
|
|
5
5
|
// after building for esm, importing pg using the following:
|
|
6
6
|
//
|
|
@@ -11,12 +11,22 @@ exports.pgErrorType = pgErrorType;
|
|
|
11
11
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
12
12
|
// @ts-ignore
|
|
13
13
|
const pg_1 = require("pg");
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
exports.CHECK_VIOLATION = 'CHECK_VIOLATION';
|
|
15
|
+
exports.FOREIGN_KEY_VIOLATION = 'FOREIGN_KEY_VIOLATION';
|
|
16
|
+
exports.INTEGRITY_CONSTRAINT_VIOLATION = 'INTEGRITY_CONSTRAINT_VIOLATION';
|
|
17
|
+
exports.INVALID_INPUT_SYNTAX = 'INVALID_INPUT_SYNTAX';
|
|
18
|
+
exports.NOT_NULL_VIOLATION = 'NOT_NULL_VIOLATION';
|
|
19
|
+
exports.RESTRICT_VIOLATION = 'RESTRICT_VIOLATION';
|
|
20
|
+
exports.UNIQUE_VIOLATION = 'UNIQUE_VIOLATION';
|
|
16
21
|
exports.PG_ERRORS = {
|
|
17
|
-
'23505':
|
|
18
|
-
'
|
|
19
|
-
'
|
|
22
|
+
'23505': exports.UNIQUE_VIOLATION,
|
|
23
|
+
'22007': exports.INVALID_INPUT_SYNTAX,
|
|
24
|
+
'22P02': exports.INVALID_INPUT_SYNTAX,
|
|
25
|
+
'23502': exports.NOT_NULL_VIOLATION,
|
|
26
|
+
'23514': exports.CHECK_VIOLATION,
|
|
27
|
+
'23000': exports.INTEGRITY_CONSTRAINT_VIOLATION,
|
|
28
|
+
'23001': exports.RESTRICT_VIOLATION,
|
|
29
|
+
'23503': exports.FOREIGN_KEY_VIOLATION,
|
|
20
30
|
};
|
|
21
31
|
function pgErrorFromCode(code) {
|
|
22
32
|
return exports.PG_ERRORS[code] || null;
|
|
@@ -20,7 +20,9 @@ const MissingThroughAssociationSource_js_1 = require("../../errors/associations/
|
|
|
20
20
|
const ThroughAssociationConditionsIncompatibleWithThroughAssociationSource_js_1 = require("../../errors/associations/ThroughAssociationConditionsIncompatibleWithThroughAssociationSource.js");
|
|
21
21
|
const CannotNegateSimilarityClause_js_1 = require("../../errors/CannotNegateSimilarityClause.js");
|
|
22
22
|
const CannotPassUndefinedAsAValueToAWhereClause_js_1 = require("../../errors/CannotPassUndefinedAsAValueToAWhereClause.js");
|
|
23
|
+
const CheckConstraintViolation_js_1 = require("../../errors/db/CheckConstraintViolation.js");
|
|
23
24
|
const DataTypeColumnTypeMismatch_js_1 = require("../../errors/db/DataTypeColumnTypeMismatch.js");
|
|
25
|
+
const NotNullViolation_js_1 = require("../../errors/db/NotNullViolation.js");
|
|
24
26
|
const UnexpectedUndefined_js_1 = require("../../errors/UnexpectedUndefined.js");
|
|
25
27
|
const CalendarDate_js_1 = require("../../helpers/CalendarDate.js");
|
|
26
28
|
const camelize_js_1 = require("../../helpers/camelize.js");
|
|
@@ -33,6 +35,7 @@ const dropDb_js_1 = require("../../helpers/db/dropDb.js");
|
|
|
33
35
|
const loadPgClient_js_1 = require("../../helpers/db/loadPgClient.js");
|
|
34
36
|
const runMigration_js_1 = require("../../helpers/db/runMigration.js");
|
|
35
37
|
const EnvInternal_js_1 = require("../../helpers/EnvInternal.js");
|
|
38
|
+
const groupBy_js_1 = require("../../helpers/groupBy.js");
|
|
36
39
|
const isEmpty_js_1 = require("../../helpers/isEmpty.js");
|
|
37
40
|
const namespaceColumn_js_1 = require("../../helpers/namespaceColumn.js");
|
|
38
41
|
const normalizeUnicode_js_1 = require("../../helpers/normalizeUnicode.js");
|
|
@@ -435,11 +438,21 @@ class KyselyQueryDriver extends Base_js_1.default {
|
|
|
435
438
|
}
|
|
436
439
|
catch (error) {
|
|
437
440
|
switch ((0, errors_js_1.pgErrorType)(error)) {
|
|
438
|
-
case
|
|
441
|
+
case errors_js_1.INVALID_INPUT_SYNTAX:
|
|
439
442
|
throw new DataTypeColumnTypeMismatch_js_1.default({
|
|
440
443
|
dream,
|
|
441
444
|
error: error instanceof Error ? error : new Error('database column type error'),
|
|
442
445
|
});
|
|
446
|
+
case errors_js_1.NOT_NULL_VIOLATION:
|
|
447
|
+
throw new NotNullViolation_js_1.default({
|
|
448
|
+
dream,
|
|
449
|
+
error: error instanceof Error ? error : new Error('not null violation'),
|
|
450
|
+
});
|
|
451
|
+
case errors_js_1.CHECK_VIOLATION:
|
|
452
|
+
throw new CheckConstraintViolation_js_1.default({
|
|
453
|
+
dream,
|
|
454
|
+
error: error instanceof Error ? error : new Error('check constraint violation'),
|
|
455
|
+
});
|
|
443
456
|
}
|
|
444
457
|
throw error;
|
|
445
458
|
}
|
|
@@ -1204,7 +1217,7 @@ class KyselyQueryDriver extends Base_js_1.default {
|
|
|
1204
1217
|
const keys = Object.keys(preloadStatement);
|
|
1205
1218
|
for (const key of keys) {
|
|
1206
1219
|
const nestedDreams = await this.applyOnePreload(key, dream, this.applyablePreloadOnStatements(preloadOnStatements[key]));
|
|
1207
|
-
if (nestedDreams) {
|
|
1220
|
+
if (nestedDreams.length) {
|
|
1208
1221
|
await this.applyPreload(preloadStatement[key], preloadOnStatements[key], nestedDreams);
|
|
1209
1222
|
}
|
|
1210
1223
|
}
|
|
@@ -1699,18 +1712,10 @@ class KyselyQueryDriver extends Base_js_1.default {
|
|
|
1699
1712
|
*
|
|
1700
1713
|
* Used to preload polymorphic belongs to associations
|
|
1701
1714
|
*/
|
|
1702
|
-
async preloadPolymorphicBelongsTo(association, dreams) {
|
|
1703
|
-
|
|
1704
|
-
throw new Error(`Association ${association.as} points to an array of models but is not designated polymorphic`);
|
|
1705
|
-
if (association.type !== 'BelongsTo')
|
|
1706
|
-
throw new Error(`Polymorphic association ${association.as} points to an array of models but is ${association.type}. Only BelongsTo associations may point to an array of models.`);
|
|
1707
|
-
const nestedDreamsForNextRoundOfPreloading = [];
|
|
1708
|
-
for (const associatedModel of association.modelCB()) {
|
|
1709
|
-
await this.preloadPolymorphicAssociationModel(dreams, association, associatedModel, nestedDreamsForNextRoundOfPreloading);
|
|
1710
|
-
}
|
|
1711
|
-
return nestedDreamsForNextRoundOfPreloading;
|
|
1715
|
+
async preloadPolymorphicBelongsTo(association, associatedModels, dreams) {
|
|
1716
|
+
return (0, compact_js_1.default)(await Promise.all(associatedModels.map(associatedModel => this.preloadPolymorphicAssociationModel(dreams, association, associatedModel)))).flat();
|
|
1712
1717
|
}
|
|
1713
|
-
async preloadPolymorphicAssociationModel(dreams, association, associatedDreamClass
|
|
1718
|
+
async preloadPolymorphicAssociationModel(dreams, association, associatedDreamClass) {
|
|
1714
1719
|
const relevantAssociatedModels = dreams.filter((dream) => {
|
|
1715
1720
|
const field = association.foreignKeyTypeField();
|
|
1716
1721
|
return dream[field] === associatedDreamClass['stiBaseClassOrOwnClassName'] || dream[field] === null;
|
|
@@ -1729,7 +1734,6 @@ class KyselyQueryDriver extends Base_js_1.default {
|
|
|
1729
1734
|
[associatedDreamClass.primaryKey]: relevantAssociatedModels.map((dream) => dream[association.foreignKey()]),
|
|
1730
1735
|
})
|
|
1731
1736
|
.all();
|
|
1732
|
-
loadedAssociations.forEach((loadedAssociation) => nestedDreamsForNextRoundOfPreloading.push(loadedAssociation));
|
|
1733
1737
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
|
1734
1738
|
// Associate each loaded association with each dream based on primary key and foreign key type
|
|
1735
1739
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
|
@@ -1744,6 +1748,7 @@ class KyselyQueryDriver extends Base_js_1.default {
|
|
|
1744
1748
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
1745
1749
|
// end: Associate each loaded association with each dream based on primary key and foreign key type
|
|
1746
1750
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
1751
|
+
return loadedAssociations;
|
|
1747
1752
|
}
|
|
1748
1753
|
}
|
|
1749
1754
|
/**
|
|
@@ -1782,12 +1787,18 @@ class KyselyQueryDriver extends Base_js_1.default {
|
|
|
1782
1787
|
*
|
|
1783
1788
|
* Applies a preload statement
|
|
1784
1789
|
*/
|
|
1785
|
-
async applyOnePreload(
|
|
1790
|
+
async applyOnePreload(associationNameAndMaybeAlias, dreams, onStatement = {}) {
|
|
1786
1791
|
if (!Array.isArray(dreams))
|
|
1787
1792
|
dreams = [dreams];
|
|
1788
|
-
const
|
|
1789
|
-
|
|
1790
|
-
|
|
1793
|
+
const { name: associationName } = (0, associationStringToNameAndAlias_js_1.default)(associationNameAndMaybeAlias);
|
|
1794
|
+
dreams = dreams.filter(dream => dream.hasAssociation(associationName));
|
|
1795
|
+
const groupedDreams = (0, groupBy_js_1.default)(dreams, dream => dream.sanitizedConstructorName);
|
|
1796
|
+
return (await Promise.all(Object.keys(groupedDreams).map(key => this._applyOnePreload(associationName, groupedDreams[key], onStatement)))).flat();
|
|
1797
|
+
}
|
|
1798
|
+
async _applyOnePreload(associationName, dreams, onStatement = {}) {
|
|
1799
|
+
if (!dreams.length)
|
|
1800
|
+
return [];
|
|
1801
|
+
const dream = dreams[0];
|
|
1791
1802
|
const { name, alias: _alias } = (0, associationStringToNameAndAlias_js_1.default)(associationName);
|
|
1792
1803
|
const alias = _alias || name;
|
|
1793
1804
|
const association = dream['getAssociationMetadata'](name);
|
|
@@ -1795,8 +1806,10 @@ class KyselyQueryDriver extends Base_js_1.default {
|
|
|
1795
1806
|
throw new UnexpectedUndefined_js_1.default();
|
|
1796
1807
|
const dreamClass = dream.constructor;
|
|
1797
1808
|
const dreamClassToHydrate = association.modelCB();
|
|
1798
|
-
if (
|
|
1799
|
-
|
|
1809
|
+
if (Array.isArray(dreamClassToHydrate)) {
|
|
1810
|
+
const preloadedPolymorphicBelongsTos = await this.preloadPolymorphicBelongsTo(association, dreamClassToHydrate, dreams);
|
|
1811
|
+
return preloadedPolymorphicBelongsTos;
|
|
1812
|
+
}
|
|
1800
1813
|
const dreamClassToHydrateColumns = [...dreamClassToHydrate.columns()];
|
|
1801
1814
|
const columnsToPluck = dreamClassToHydrateColumns.map(column => this.namespaceColumn(column.toString(), alias));
|
|
1802
1815
|
columnsToPluck.push(this.namespaceColumn(dreamClass.primaryKey, dreamClass.table));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = printSerializerHierarchyLevel;
|
|
4
|
+
const yoctocolors_1 = require("yoctocolors");
|
|
5
|
+
const indent_js_1 = require("../../helpers/indent.js");
|
|
6
|
+
function printSerializerHierarchyLevel({ serializerAssociationType, serializerAssociationName, associationSerializer, forDisplayDepth, }) {
|
|
7
|
+
const hierarchyLine = '└───';
|
|
8
|
+
const indentation = (0, indent_js_1.indent)((hierarchyLine.length + 1) * forDisplayDepth, {
|
|
9
|
+
tabWidth: 1,
|
|
10
|
+
});
|
|
11
|
+
const prefix = `${hierarchyLine} `;
|
|
12
|
+
const nestedAssociationDisplay = indentation + `${prefix}${serializerAssociationType} ${yoctocolors_1.default.cyan(serializerAssociationName)}`;
|
|
13
|
+
console.log(nestedAssociationDisplay);
|
|
14
|
+
console.log(yoctocolors_1.default.gray(indentation +
|
|
15
|
+
(0, indent_js_1.indent)(prefix.length, { tabWidth: 1 }) +
|
|
16
|
+
associationSerializer.globalName));
|
|
17
|
+
}
|
|
@@ -2,12 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cacheDreamApp = cacheDreamApp;
|
|
4
4
|
exports.getCachedDreamAppOrFail = getCachedDreamAppOrFail;
|
|
5
|
+
const EnvInternal_js_1 = require("../helpers/EnvInternal.js");
|
|
5
6
|
let _dreamApp = undefined;
|
|
6
7
|
function cacheDreamApp(dreamconf) {
|
|
7
8
|
_dreamApp = dreamconf;
|
|
8
9
|
}
|
|
9
10
|
function getCachedDreamAppOrFail() {
|
|
10
|
-
if (!_dreamApp)
|
|
11
|
-
|
|
11
|
+
if (!_dreamApp) {
|
|
12
|
+
const baseErrorMessage = 'Must call `initializeDreamApp` or `initializePsychicApp` before loading cached DreamApp.getOrFail().';
|
|
13
|
+
if (EnvInternal_js_1.default.isTest) {
|
|
14
|
+
throw new Error(`${baseErrorMessage}
|
|
15
|
+
|
|
16
|
+
Check for specs running directly in a \`describe\` or \`context\` block rather than nested within an \`it\` block.`);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
throw new Error(baseErrorMessage);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
12
22
|
return _dreamApp;
|
|
13
23
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class CheckConstraintViolation extends Error {
|
|
4
|
+
dream;
|
|
5
|
+
error;
|
|
6
|
+
constructor({ dream, error }) {
|
|
7
|
+
super();
|
|
8
|
+
this.dream = dream;
|
|
9
|
+
this.error = error;
|
|
10
|
+
}
|
|
11
|
+
get message() {
|
|
12
|
+
return this.error.message;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.default = CheckConstraintViolation;
|
|
@@ -9,11 +9,7 @@ class DataTypeColumnTypeMismatch extends Error {
|
|
|
9
9
|
this.error = error;
|
|
10
10
|
}
|
|
11
11
|
get message() {
|
|
12
|
-
return
|
|
13
|
-
Failed to save ${this.dream.sanitizedConstructorName}:
|
|
14
|
-
|
|
15
|
-
${this.error.message}
|
|
16
|
-
`;
|
|
12
|
+
return this.error.message;
|
|
17
13
|
}
|
|
18
14
|
}
|
|
19
15
|
exports.default = DataTypeColumnTypeMismatch;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class NotNullViolation extends Error {
|
|
4
|
+
dream;
|
|
5
|
+
error;
|
|
6
|
+
constructor({ dream, error }) {
|
|
7
|
+
super();
|
|
8
|
+
this.dream = dream;
|
|
9
|
+
this.error = error;
|
|
10
|
+
}
|
|
11
|
+
get message() {
|
|
12
|
+
return this.error.message;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.default = NotNullViolation;
|
|
@@ -22,6 +22,7 @@ async function generateMigration({ migrationName, columnsWithTypes, fullyQualifi
|
|
|
22
22
|
table: (0, snakeify_js_1.default)((0, pluralize_esm_1.default)((0, pascalizePath_js_1.default)(fullyQualifiedParentName))),
|
|
23
23
|
columnsWithTypes,
|
|
24
24
|
primaryKeyType: (0, primaryKeyType_js_1.default)(),
|
|
25
|
+
stiChildClassName: (0, pascalizePath_js_1.default)(fullyQualifiedModelName),
|
|
25
26
|
});
|
|
26
27
|
}
|
|
27
28
|
else if (fullyQualifiedModelName) {
|
|
@@ -9,13 +9,17 @@ const foreignKeyTypeFromPrimaryKey_js_1 = require("../db/foreignKeyTypeFromPrima
|
|
|
9
9
|
const snakeify_js_1 = require("../snakeify.js");
|
|
10
10
|
const STI_TYPE_COLUMN_NAME = 'type';
|
|
11
11
|
const COLUMNS_TO_INDEX = [STI_TYPE_COLUMN_NAME];
|
|
12
|
-
function generateMigrationContent({ table, columnsWithTypes = [], primaryKeyType = 'bigserial', createOrAlter = 'create', } = {}) {
|
|
12
|
+
function generateMigrationContent({ table, columnsWithTypes = [], primaryKeyType = 'bigserial', createOrAlter = 'create', stiChildClassName, } = {}) {
|
|
13
13
|
const altering = createOrAlter === 'alter';
|
|
14
14
|
let requireCitextExtension = false;
|
|
15
|
-
const
|
|
15
|
+
const checkConstraints = [];
|
|
16
|
+
const { columnDefs, columnDrops, indexDefs, indexDrops } = columnsWithTypes.reduce((acc, attributeDeclaration) => {
|
|
16
17
|
const { columnDefs, columnDrops, indexDefs, indexDrops } = acc;
|
|
17
|
-
const [nonStandardAttributeName, attributeType, ...descriptors] =
|
|
18
|
-
const
|
|
18
|
+
const [nonStandardAttributeName, attributeType, ...descriptors] = attributeDeclaration.split(':');
|
|
19
|
+
const userWantsThisOptional = optionalFromDescriptors(descriptors);
|
|
20
|
+
// when creating a migration for an STI child, we don't want to include notNull;
|
|
21
|
+
// instead, we'll add a check constraint that uses the STI child class name
|
|
22
|
+
const optional = userWantsThisOptional || !!stiChildClassName;
|
|
19
23
|
const sqlAttributeType = getAttributeType(attributeType, descriptors);
|
|
20
24
|
let attributeName = (0, snakeify_js_1.default)(nonStandardAttributeName);
|
|
21
25
|
if (attributeName === undefined)
|
|
@@ -24,6 +28,17 @@ function generateMigrationContent({ table, columnsWithTypes = [], primaryKeyType
|
|
|
24
28
|
return acc;
|
|
25
29
|
if (attributeType === 'citext')
|
|
26
30
|
requireCitextExtension = true;
|
|
31
|
+
if (stiChildClassName && !userWantsThisOptional) {
|
|
32
|
+
checkConstraints.push(`
|
|
33
|
+
|
|
34
|
+
await db.schema
|
|
35
|
+
.alterTable('${table}')
|
|
36
|
+
.addCheckConstraint(
|
|
37
|
+
'${table}_not_null_${attributeName}',
|
|
38
|
+
sql\`type != '${stiChildClassName}' OR ${attributeName} IS NOT NULL\`,
|
|
39
|
+
)
|
|
40
|
+
.execute()`);
|
|
41
|
+
}
|
|
27
42
|
switch (attributeType) {
|
|
28
43
|
case 'belongs_to':
|
|
29
44
|
columnDefs.push(generateBelongsToStr(attributeName, {
|
|
@@ -100,7 +115,7 @@ ${citextExtension}${generateEnumStatements(columnsWithTypes)} await db.schema
|
|
|
100
115
|
".addColumn('created_at', 'timestamp', col => col.notNull())" +
|
|
101
116
|
newlineDoubleIndent +
|
|
102
117
|
".addColumn('updated_at', 'timestamp', col => col.notNull())"}
|
|
103
|
-
.execute()${indexDefs.length ? `\n${newlineIndent}` : ''}${indexDefs.join(newlineDoubleIndent)}
|
|
118
|
+
.execute()${indexDefs.length ? `\n${newlineIndent}` : ''}${indexDefs.join(newlineDoubleIndent)}${checkConstraints.join('')}
|
|
104
119
|
}
|
|
105
120
|
|
|
106
121
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = generateStiMigrationContent;
|
|
4
4
|
const generateMigrationContent_js_1 = require("./generateMigrationContent.js");
|
|
5
|
-
function generateStiMigrationContent({ table, columnsWithTypes = [], primaryKeyType = 'bigserial',
|
|
6
|
-
return (0, generateMigrationContent_js_1.default)({
|
|
5
|
+
function generateStiMigrationContent({ table, columnsWithTypes = [], primaryKeyType = 'bigserial', stiChildClassName, }) {
|
|
6
|
+
return (0, generateMigrationContent_js_1.default)({
|
|
7
|
+
table,
|
|
8
|
+
columnsWithTypes,
|
|
9
|
+
primaryKeyType,
|
|
10
|
+
createOrAlter: 'alter',
|
|
11
|
+
stiChildClassName,
|
|
12
|
+
});
|
|
7
13
|
}
|
package/dist/cjs/src/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.ObjectSerializerBuilder = exports.DreamSerializerBuilder = exports.ObjectSerializer = exports.DreamSerializer = exports.serializerNameFromFullyQualifiedModelName = exports.isDreamSerializer = exports.inferSerializersFromDreamClassOrViewModelClass = exports.inferSerializerFromDreamOrViewModel = exports.ops = exports.uniq = exports.uncapitalize = exports.expandStiClasses = exports.standardizeFullyQualifiedModelName = exports.sortObjectByValue = exports.sortObjectByKey = exports.sortBy = exports.sort = exports.snakeify = exports.round = exports.range = exports.Range = exports.sharedPathPrefix = exports.relativeDreamPath = void 0;
|
|
3
|
+
exports.normalizeUnicode = exports.loadRepl = exports.isEmpty = exports.intersection = exports.hyphenize = exports.groupBy = exports.globalClassNameFromFullyQualifiedModelName = exports.Env = exports.DreamLogos = exports.DateTime = exports.compact = exports.cloneDeepSafe = exports.generateDream = exports.capitalize = exports.camelize = exports.CalendarDate = exports.Benchmark = exports.ValidationError = exports.RecordNotFound = exports.GlobalNameNotSet = exports.NotNullViolation = exports.DataTypeColumnTypeMismatch = exports.CheckConstraintViolation = exports.CreateOrFindByFailedToCreateAndFind = exports.NonLoadedAssociation = exports.Encrypt = exports.Query = exports.DreamTransaction = exports.openapiShorthandPrimitiveTypes = exports.openapiPrimitiveTypes = exports.DreamConst = exports.Dream = exports.DreamAppAllowedPackageManagersEnumValues = exports.DreamApp = exports.lookupClassByGlobalName = exports.DreamImporter = exports.Decorators = exports.STI = exports.SoftDelete = exports.ReplicaSafe = exports.validateTable = exports.validateColumn = exports.DreamMigrationHelpers = exports.untypedDb = exports.pgErrorType = exports.dreamDbConnections = exports.closeAllDbConnections = exports.DreamCLI = exports.CliFileWriter = exports.DreamBin = void 0;
|
|
4
|
+
exports.ObjectSerializerBuilder = exports.DreamSerializerBuilder = exports.ObjectSerializer = exports.DreamSerializer = exports.serializerNameFromFullyQualifiedModelName = exports.isDreamSerializer = exports.inferSerializersFromDreamClassOrViewModelClass = exports.inferSerializerFromDreamOrViewModel = exports.ops = exports.uniq = exports.uncapitalize = exports.expandStiClasses = exports.standardizeFullyQualifiedModelName = exports.sortObjectByValue = exports.sortObjectByKey = exports.sortBy = exports.sort = exports.snakeify = exports.round = exports.range = exports.Range = exports.sharedPathPrefix = exports.relativeDreamPath = exports.dreamPath = exports.pascalize = void 0;
|
|
5
5
|
var index_js_1 = require("./bin/index.js");
|
|
6
6
|
Object.defineProperty(exports, "DreamBin", { enumerable: true, get: function () { return index_js_1.default; } });
|
|
7
7
|
var CliFileWriter_js_1 = require("./cli/CliFileWriter.js");
|
|
@@ -52,8 +52,12 @@ var NonLoadedAssociation_js_1 = require("./errors/associations/NonLoadedAssociat
|
|
|
52
52
|
Object.defineProperty(exports, "NonLoadedAssociation", { enumerable: true, get: function () { return NonLoadedAssociation_js_1.default; } });
|
|
53
53
|
var CreateOrFindByFailedToCreateAndFind_js_1 = require("./errors/CreateOrFindByFailedToCreateAndFind.js");
|
|
54
54
|
Object.defineProperty(exports, "CreateOrFindByFailedToCreateAndFind", { enumerable: true, get: function () { return CreateOrFindByFailedToCreateAndFind_js_1.default; } });
|
|
55
|
+
var CheckConstraintViolation_js_1 = require("./errors/db/CheckConstraintViolation.js");
|
|
56
|
+
Object.defineProperty(exports, "CheckConstraintViolation", { enumerable: true, get: function () { return CheckConstraintViolation_js_1.default; } });
|
|
55
57
|
var DataTypeColumnTypeMismatch_js_1 = require("./errors/db/DataTypeColumnTypeMismatch.js");
|
|
56
58
|
Object.defineProperty(exports, "DataTypeColumnTypeMismatch", { enumerable: true, get: function () { return DataTypeColumnTypeMismatch_js_1.default; } });
|
|
59
|
+
var NotNullViolation_js_1 = require("./errors/db/NotNullViolation.js");
|
|
60
|
+
Object.defineProperty(exports, "NotNullViolation", { enumerable: true, get: function () { return NotNullViolation_js_1.default; } });
|
|
57
61
|
var GlobalNameNotSet_js_1 = require("./errors/dream-app/GlobalNameNotSet.js");
|
|
58
62
|
Object.defineProperty(exports, "GlobalNameNotSet", { enumerable: true, get: function () { return GlobalNameNotSet_js_1.default; } });
|
|
59
63
|
var RecordNotFound_js_1 = require("./errors/RecordNotFound.js");
|
|
@@ -14,7 +14,8 @@ function serializerForAssociatedClass(object, associationName, options) {
|
|
|
14
14
|
return null;
|
|
15
15
|
const dream = object;
|
|
16
16
|
const association = dream['getAssociationMetadata'](associationName);
|
|
17
|
-
const
|
|
18
|
-
|
|
17
|
+
const associatedClass = association.modelCB();
|
|
18
|
+
if (Array.isArray(associatedClass))
|
|
19
|
+
throw new Error('rendersOne flatten is incompatible with a polymorphic belongs-to association');
|
|
19
20
|
return (0, inferSerializerFromDreamOrViewModel_js_1.inferSerializersFromDreamClassOrViewModelClass)(associatedClass, options.serializerKey)[0] ?? null;
|
|
20
21
|
}
|