@rvoh/dream 0.31.4 → 0.32.0
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 +9 -9
- package/dist/cjs/src/bin/helpers/sync.js +7 -7
- package/dist/cjs/src/cli/logger/DreamCliLogger.js +2 -2
- package/dist/cjs/src/cli/logger/loggable/colorize.js +1 -1
- package/dist/cjs/src/db/DreamDbConnection.js +1 -1
- package/dist/cjs/src/decorators/field/sortable/hooks/beforeSortableSave.js +6 -3
- package/dist/cjs/src/dream/DreamInstanceTransactionBuilder.js +3 -3
- package/dist/cjs/src/dream/LeftJoinLoadBuilder.js +5 -1
- package/dist/cjs/src/dream/Query.js +74 -12
- package/dist/cjs/src/dream/internal/associations/associationUpdateQuery.js +3 -0
- package/dist/cjs/src/dream/internal/associations/createAssociation.js +3 -0
- package/dist/cjs/src/dream/internal/checkSingleValidation.js +8 -1
- package/dist/cjs/src/dream/internal/extractAssociationMetadataFromAssociationName.js +7 -3
- package/dist/cjs/src/errors/MissingTable.js +1 -1
- package/dist/cjs/src/errors/UnexpectedUndefined.js +14 -0
- package/dist/cjs/src/errors/associations/AssociationDeclaredWithoutAssociatedDreamClass.js +17 -0
- package/dist/cjs/src/global-cli/helpers/argAndValue.js +4 -4
- package/dist/cjs/src/helpers/CalendarDate.js +1 -1
- package/dist/cjs/src/helpers/cli/SchemaBuilder.js +52 -17
- package/dist/cjs/src/helpers/cli/generateDreamContent.js +3 -1
- package/dist/cjs/src/helpers/cli/generateFactoryContent.js +7 -3
- package/dist/cjs/src/helpers/cli/generateMigrationContent.js +53 -21
- package/dist/cjs/src/helpers/cli/generateSerializerContent.js +3 -25
- package/dist/cjs/src/helpers/objectPathsToArrays.js +2 -1
- package/dist/esm/src/Dream.js +9 -9
- package/dist/esm/src/bin/helpers/sync.js +4 -4
- package/dist/esm/src/cli/logger/DreamCliLogger.js +2 -2
- package/dist/esm/src/cli/logger/loggable/colorize.js +1 -1
- package/dist/esm/src/db/DreamDbConnection.js +1 -1
- package/dist/esm/src/decorators/field/sortable/hooks/beforeSortableSave.js +6 -3
- package/dist/esm/src/dream/DreamInstanceTransactionBuilder.js +3 -3
- package/dist/esm/src/dream/LeftJoinLoadBuilder.js +5 -1
- package/dist/esm/src/dream/Query.js +74 -12
- package/dist/esm/src/dream/internal/associations/associationUpdateQuery.js +3 -0
- package/dist/esm/src/dream/internal/associations/createAssociation.js +3 -0
- package/dist/esm/src/dream/internal/checkSingleValidation.js +8 -1
- package/dist/esm/src/dream/internal/extractAssociationMetadataFromAssociationName.js +7 -3
- package/dist/esm/src/errors/MissingTable.js +1 -1
- package/dist/esm/src/errors/UnexpectedUndefined.js +11 -0
- package/dist/esm/src/errors/associations/AssociationDeclaredWithoutAssociatedDreamClass.js +14 -0
- package/dist/esm/src/global-cli/dream.js +0 -0
- package/dist/esm/src/global-cli/helpers/argAndValue.js +4 -4
- package/dist/esm/src/helpers/CalendarDate.js +1 -1
- package/dist/esm/src/helpers/cli/SchemaBuilder.js +52 -17
- package/dist/esm/src/helpers/cli/generateDreamContent.js +3 -1
- package/dist/esm/src/helpers/cli/generateFactoryContent.js +7 -3
- package/dist/esm/src/helpers/cli/generateMigrationContent.js +53 -21
- package/dist/esm/src/helpers/cli/generateSerializerContent.js +3 -25
- package/dist/esm/src/helpers/objectPathsToArrays.js +2 -1
- package/dist/types/src/Dream.d.ts +1 -1
- package/dist/types/src/cli/logger/loggable/DreamCliLoggable.d.ts +3 -3
- package/dist/types/src/cli/logger/loggable/DreamCliLoggableText.d.ts +5 -5
- package/dist/types/src/cli/logger/loggable/colorize.d.ts +3 -3
- package/dist/types/src/db/ConnectedToDB.d.ts +3 -3
- package/dist/types/src/decorators/field/sortable/helpers/decrementScopedRecordsGreaterThanPosition.d.ts +1 -1
- package/dist/types/src/decorators/field/sortable/helpers/positionIsInvalid.d.ts +1 -1
- package/dist/types/src/decorators/field/sortable/helpers/setPosition.d.ts +2 -2
- package/dist/types/src/decorators/field/sortable/hooks/afterSortableCreate.d.ts +2 -2
- package/dist/types/src/decorators/field/sortable/hooks/afterSortableDestroy.d.ts +1 -1
- package/dist/types/src/decorators/field/sortable/hooks/afterSortableUpdate.d.ts +2 -2
- package/dist/types/src/decorators/field/sortable/hooks/beforeSortableSave.d.ts +1 -1
- package/dist/types/src/decorators/field-or-getter/Virtual.d.ts +1 -1
- package/dist/types/src/dream/Query.d.ts +26 -26
- package/dist/types/src/dream/internal/destroyOptions.d.ts +4 -4
- package/dist/types/src/dream/internal/similarity/SimilarityBuilder.d.ts +4 -4
- package/dist/types/src/errors/UnexpectedUndefined.d.ts +4 -0
- package/dist/types/src/errors/associations/AssociationDeclaredWithoutAssociatedDreamClass.d.ts +7 -0
- package/dist/types/src/errors/associations/MissingRequiredAssociationOnClause.d.ts +1 -1
- package/dist/types/src/helpers/cli/generateDream.d.ts +1 -1
- package/dist/types/src/helpers/cli/generateDreamContent.d.ts +1 -1
- package/dist/types/src/helpers/cli/generateMigration.d.ts +2 -2
- package/dist/types/src/helpers/cli/generateMigrationContent.d.ts +4 -4
- package/dist/types/src/helpers/cli/generateSerializer.d.ts +1 -1
- package/dist/types/src/helpers/cli/generateSerializerContent.d.ts +2 -2
- package/dist/types/src/types/associations/shared.d.ts +1 -6
- package/dist/types/src/types/dream.d.ts +2 -13
- package/dist/types/src/types/lifecycle.d.ts +2 -2
- package/dist/types/src/types/logger.d.ts +3 -3
- package/docs/assets/icons.js +1 -1
- package/docs/assets/icons.svg +1 -1
- package/docs/assets/main.js +1 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +66 -21
- package/docs/classes/Benchmark.html +2 -2
- package/docs/classes/CalendarDate.html +2 -2
- package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +6 -5
- package/docs/classes/Decorators.html +19 -19
- package/docs/classes/Dream.html +131 -131
- package/docs/classes/DreamApplication.html +4 -4
- package/docs/classes/DreamBin.html +2 -2
- package/docs/classes/DreamCLI.html +4 -4
- package/docs/classes/DreamDbConnection.html +2 -2
- package/docs/classes/DreamGlam.html +2 -2
- package/docs/classes/DreamImporter.html +2 -2
- package/docs/classes/DreamMigrationHelpers.html +7 -7
- package/docs/classes/DreamSerializer.html +2 -2
- 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 +6 -5
- package/docs/classes/NonLoadedAssociation.html +6 -5
- package/docs/classes/Query.html +51 -51
- package/docs/classes/Range.html +2 -2
- package/docs/classes/RecordNotFound.html +6 -5
- package/docs/classes/ValidationError.html +6 -5
- package/docs/functions/Attribute.html +1 -1
- package/docs/functions/RendersMany.html +1 -1
- package/docs/functions/RendersOne.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/closeAllDbConnections.html +1 -1
- package/docs/functions/compact.html +1 -1
- package/docs/functions/db.html +1 -1
- package/docs/functions/debug.html +1 -1
- package/docs/functions/dreamDbConnections.html +1 -1
- package/docs/functions/dreamPath.html +1 -1
- package/docs/functions/generateDream.html +1 -1
- package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -1
- package/docs/functions/hyphenize.html +1 -1
- package/docs/functions/inferSerializerFromDreamClassOrViewModelClass.html +1 -1
- package/docs/functions/inferSerializerFromDreamOrViewModel.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/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/standardizeFullyQualifiedModelName.html +1 -1
- package/docs/functions/uncapitalize.html +1 -1
- package/docs/functions/uniq.html +1 -1
- package/docs/functions/validateColumn.html +1 -1
- package/docs/functions/validateTable.html +1 -1
- package/docs/index.html +7 -7
- package/docs/interfaces/AttributeStatement.html +2 -2
- package/docs/interfaces/DecoratorContext.html +2 -2
- package/docs/interfaces/DreamApplicationInitOptions.html +2 -2
- package/docs/interfaces/DreamApplicationOpts.html +2 -2
- package/docs/interfaces/DreamSerializerAssociationStatement.html +2 -2
- package/docs/interfaces/EncryptOptions.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/modules.html +8 -8
- package/docs/types/Camelized.html +1 -1
- package/docs/types/CommonOpenapiSchemaObjectFields.html +1 -1
- package/docs/types/DateTime.html +1 -1
- package/docs/types/DreamAssociationMetadata.html +1 -1
- package/docs/types/DreamAttributes.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/DreamOrViewModelSerializerKey.html +1 -1
- package/docs/types/DreamParamSafeAttributes.html +1 -1
- package/docs/types/DreamParamSafeColumnNames.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/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/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/OpenapiSchemaPartialSegment.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/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/SerializableClassOrSerializerCallback.html +1 -1
- package/docs/types/SerializableDreamClassOrViewModelClass.html +1 -1
- package/docs/types/SerializableDreamOrViewModel.html +1 -1
- package/docs/types/SerializableTypes.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/ViewModelSerializerKey.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/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 +2 -2
package/dist/cjs/src/Dream.js
CHANGED
|
@@ -1408,7 +1408,7 @@ class Dream {
|
|
|
1408
1408
|
*/
|
|
1409
1409
|
static belongsToAssociationForeignKeys() {
|
|
1410
1410
|
const associationMap = this.associationMetadataMap();
|
|
1411
|
-
return this.belongsToAssociationNames().map(belongsToKey => associationMap[belongsToKey]
|
|
1411
|
+
return this.belongsToAssociationNames().map(belongsToKey => associationMap[belongsToKey]?.foreignKey());
|
|
1412
1412
|
}
|
|
1413
1413
|
/**
|
|
1414
1414
|
* @internal
|
|
@@ -1425,8 +1425,8 @@ class Dream {
|
|
|
1425
1425
|
static polymorphicTypeColumns() {
|
|
1426
1426
|
const associationMap = this.associationMetadataMap();
|
|
1427
1427
|
return this.belongsToAssociationNames()
|
|
1428
|
-
.filter(key => associationMap[key]
|
|
1429
|
-
.map(belongsToKey => associationMap[belongsToKey]
|
|
1428
|
+
.filter(key => associationMap[key]?.polymorphic)
|
|
1429
|
+
.map(belongsToKey => associationMap[belongsToKey]?.foreignKeyTypeField());
|
|
1430
1430
|
}
|
|
1431
1431
|
/**
|
|
1432
1432
|
* @internal
|
|
@@ -1444,7 +1444,7 @@ class Dream {
|
|
|
1444
1444
|
*/
|
|
1445
1445
|
static belongsToAssociationNames() {
|
|
1446
1446
|
const associationMap = this.associationMetadataMap();
|
|
1447
|
-
return Object.keys(associationMap).filter(key => associationMap[key]
|
|
1447
|
+
return Object.keys(associationMap).filter(key => associationMap[key]?.type === 'BelongsTo');
|
|
1448
1448
|
}
|
|
1449
1449
|
/**
|
|
1450
1450
|
* @internal
|
|
@@ -1697,7 +1697,7 @@ class Dream {
|
|
|
1697
1697
|
get isValid() {
|
|
1698
1698
|
this._errors = {};
|
|
1699
1699
|
(0, runValidations_js_1.default)(this);
|
|
1700
|
-
return !Object.keys(this.errors).filter(key => !!this.errors[key]
|
|
1700
|
+
return !Object.keys(this.errors).filter(key => !!this.errors[key]?.length).length;
|
|
1701
1701
|
}
|
|
1702
1702
|
/**
|
|
1703
1703
|
* The name of the primary key column on this model.
|
|
@@ -1734,7 +1734,7 @@ class Dream {
|
|
|
1734
1734
|
*
|
|
1735
1735
|
* ```ts
|
|
1736
1736
|
* class User extends ApplicationModel {
|
|
1737
|
-
* public get table() {
|
|
1737
|
+
* public override get table() {
|
|
1738
1738
|
* return 'users' as const
|
|
1739
1739
|
* }
|
|
1740
1740
|
* }
|
|
@@ -2919,7 +2919,7 @@ class Dream {
|
|
|
2919
2919
|
* @returns void
|
|
2920
2920
|
*/
|
|
2921
2921
|
async save({ skipHooks } = {}) {
|
|
2922
|
-
await (0, saveDream_js_1.default)(this, null, { skipHooks });
|
|
2922
|
+
await (0, saveDream_js_1.default)(this, null, skipHooks ? { skipHooks } : undefined);
|
|
2923
2923
|
}
|
|
2924
2924
|
/**
|
|
2925
2925
|
* Applies transaction to a new Query instance
|
|
@@ -2961,7 +2961,7 @@ class Dream {
|
|
|
2961
2961
|
async update(attributes, { skipHooks } = {}) {
|
|
2962
2962
|
// use #assignAttributes to leverage any custom-defined setters
|
|
2963
2963
|
this.assignAttributes(attributes);
|
|
2964
|
-
await this.save({ skipHooks });
|
|
2964
|
+
await this.save(skipHooks ? { skipHooks } : undefined);
|
|
2965
2965
|
}
|
|
2966
2966
|
/**
|
|
2967
2967
|
* Applies all attribute changes passed to the dream,
|
|
@@ -2988,7 +2988,7 @@ class Dream {
|
|
|
2988
2988
|
async updateAttributes(attributes, { skipHooks } = {}) {
|
|
2989
2989
|
// use #setAttributes to bypass any custom-defined setters
|
|
2990
2990
|
this.setAttributes(attributes);
|
|
2991
|
-
await this.save({ skipHooks });
|
|
2991
|
+
await this.save(skipHooks ? { skipHooks } : undefined);
|
|
2992
2992
|
}
|
|
2993
2993
|
/**
|
|
2994
2994
|
* Flags a dream model so that it does not
|
|
@@ -4,24 +4,24 @@ exports.default = writeSyncFile;
|
|
|
4
4
|
require("../../helpers/loadEnv.js");
|
|
5
5
|
const fs = require("fs/promises");
|
|
6
6
|
const path = require("path");
|
|
7
|
+
const index_js_1 = require("../../cli/index.js");
|
|
8
|
+
const colorize_js_1 = require("../../cli/logger/loggable/colorize.js");
|
|
7
9
|
const ConnectionConfRetriever_js_1 = require("../../db/ConnectionConfRetriever.js");
|
|
8
|
-
const
|
|
10
|
+
const index_js_2 = require("../../dream-application/index.js");
|
|
9
11
|
const autogeneratedFileMessage_js_1 = require("../../global-cli/helpers/autogeneratedFileMessage.js");
|
|
10
12
|
const compact_js_1 = require("../../helpers/compact.js");
|
|
11
13
|
const EnvInternal_js_1 = require("../../helpers/EnvInternal.js");
|
|
12
14
|
const dreamPath_js_1 = require("../../helpers/path/dreamPath.js");
|
|
13
15
|
const snakeify_js_1 = require("../../helpers/snakeify.js");
|
|
14
16
|
const sspawn_js_1 = require("../../helpers/sspawn.js");
|
|
15
|
-
const index_js_2 = require("../../cli/index.js");
|
|
16
|
-
const colorize_js_1 = require("../../cli/logger/loggable/colorize.js");
|
|
17
17
|
async function writeSyncFile() {
|
|
18
18
|
const dbConf = new ConnectionConfRetriever_js_1.default().getConnectionConf('primary');
|
|
19
|
-
const dreamApp =
|
|
19
|
+
const dreamApp = index_js_2.default.getOrFail();
|
|
20
20
|
const dbSyncFilePath = path.join((0, dreamPath_js_1.default)('types'), 'db.ts');
|
|
21
21
|
const absoluteDbSyncPath = path.join(dreamApp.projectRoot, dbSyncFilePath);
|
|
22
22
|
await (0, sspawn_js_1.default)(`kysely-codegen --dialect=postgres --url=postgres://${dbConf.user}:${dbConf.password}@${dbConf.host}:${dbConf.port}/${dbConf.name} --out-file=${absoluteDbSyncPath}`, {
|
|
23
23
|
onStdout: message => {
|
|
24
|
-
|
|
24
|
+
index_js_1.default.logger.logContinueProgress((0, colorize_js_1.default)(`[db]`, { color: 'cyan' }) + ' ' + message, {
|
|
25
25
|
logPrefixColor: 'cyan',
|
|
26
26
|
});
|
|
27
27
|
},
|
|
@@ -107,8 +107,8 @@ export const ${typeDeclaration}Values = [
|
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
function transformName(str) {
|
|
110
|
-
const name = str.split(' {')[0]
|
|
111
|
-
if (name === 'DB')
|
|
110
|
+
const name = str.split(' {')[0]?.replace(/\s/g, '');
|
|
111
|
+
if (name === undefined || name === 'DB')
|
|
112
112
|
return null;
|
|
113
113
|
return name;
|
|
114
114
|
}
|
|
@@ -13,10 +13,10 @@ class DreamCliLogger {
|
|
|
13
13
|
logStartProgress(text, { logPrefix = '✺ ┌', logPrefixColor, logPrefixBgColor } = {}) {
|
|
14
14
|
this.log(text, { logPrefix, logPrefixColor, logPrefixBgColor });
|
|
15
15
|
}
|
|
16
|
-
logContinueProgress(text, { logPrefix = '
|
|
16
|
+
logContinueProgress(text, { logPrefix = ' ├', logPrefixColor, logPrefixBgColor } = {}) {
|
|
17
17
|
this.log(text, { logPrefix, logPrefixColor, logPrefixBgColor });
|
|
18
18
|
}
|
|
19
|
-
logEndProgress(text = 'complete', { logPrefix = '
|
|
19
|
+
logEndProgress(text = 'complete', { logPrefix = ' └', logPrefixColor, logPrefixBgColor } = {}) {
|
|
20
20
|
this.log(text, { logPrefix, logPrefixColor, logPrefixBgColor });
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = colorize;
|
|
4
4
|
const yoctocolors_1 = require("yoctocolors");
|
|
5
|
-
function colorize(text, { color, bgColor }) {
|
|
5
|
+
function colorize(text, { color, bgColor, }) {
|
|
6
6
|
const foregroundApplied = color ? yoctocolors_1.default[color](text) : text;
|
|
7
7
|
return bgColor ? yoctocolors_1.default[bgColor](foregroundApplied) : foregroundApplied;
|
|
8
8
|
}
|
|
@@ -9,9 +9,12 @@ async function beforeSortableSave({ positionField, dream, query, scope, }) {
|
|
|
9
9
|
const cacheKey = (0, sortableCacheKeyName_js_1.default)(positionField);
|
|
10
10
|
const cachedValuesName = (0, sortableCacheValuesName_js_1.default)(positionField);
|
|
11
11
|
const dreamAsAny = dream;
|
|
12
|
-
const changingScope = (0, scopeArray_js_1.default)(scope).filter(scopeField =>
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const changingScope = (0, scopeArray_js_1.default)(scope).filter(scopeField => {
|
|
13
|
+
const association = dream['getAssociationMetadata'](scopeField);
|
|
14
|
+
return association
|
|
15
|
+
? dream.willSaveChangeToAttribute(association.foreignKey())
|
|
16
|
+
: dream.willSaveChangeToAttribute(scopeField);
|
|
17
|
+
}).length;
|
|
15
18
|
if (!dream.willSaveChangeToAttribute(positionField) && !changingScope)
|
|
16
19
|
return;
|
|
17
20
|
const onlyChangingScope = !dream.willSaveChangeToAttribute(positionField) && changingScope;
|
|
@@ -211,7 +211,7 @@ class DreamInstanceTransactionBuilder {
|
|
|
211
211
|
*/
|
|
212
212
|
async update(attributes, { skipHooks } = {}) {
|
|
213
213
|
this.dreamInstance.assignAttributes(attributes);
|
|
214
|
-
await (0, saveDream_js_1.default)(this.dreamInstance, this.dreamTransaction, { skipHooks });
|
|
214
|
+
await (0, saveDream_js_1.default)(this.dreamInstance, this.dreamTransaction, skipHooks ? { skipHooks } : undefined);
|
|
215
215
|
}
|
|
216
216
|
/**
|
|
217
217
|
* Applies all attribute changes passed to the dream,
|
|
@@ -239,7 +239,7 @@ class DreamInstanceTransactionBuilder {
|
|
|
239
239
|
*/
|
|
240
240
|
async updateAttributes(attributes, { skipHooks } = {}) {
|
|
241
241
|
this.dreamInstance.setAttributes(attributes);
|
|
242
|
-
await (0, saveDream_js_1.default)(this.dreamInstance, this.dreamTransaction, { skipHooks });
|
|
242
|
+
await (0, saveDream_js_1.default)(this.dreamInstance, this.dreamTransaction, skipHooks ? { skipHooks } : undefined);
|
|
243
243
|
}
|
|
244
244
|
/**
|
|
245
245
|
* Reloads an instance, refreshing all it's attribute values
|
|
@@ -294,7 +294,7 @@ class DreamInstanceTransactionBuilder {
|
|
|
294
294
|
* @returns void
|
|
295
295
|
*/
|
|
296
296
|
async save({ skipHooks } = {}) {
|
|
297
|
-
await (0, saveDream_js_1.default)(this.dreamInstance, this.dreamTransaction, { skipHooks });
|
|
297
|
+
await (0, saveDream_js_1.default)(this.dreamInstance, this.dreamTransaction, skipHooks ? { skipHooks } : undefined);
|
|
298
298
|
}
|
|
299
299
|
/**
|
|
300
300
|
* Returns a Query instance for the specified
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const UnexpectedUndefined_js_1 = require("../errors/UnexpectedUndefined.js");
|
|
3
4
|
class LeftJoinLoadBuilder {
|
|
4
5
|
dream;
|
|
5
6
|
dreamTransaction;
|
|
@@ -63,7 +64,10 @@ class LeftJoinLoadBuilder {
|
|
|
63
64
|
}
|
|
64
65
|
const dreamWithLoadedAssociations = await this.query.firstOrFail();
|
|
65
66
|
Object.keys(this.query['leftJoinStatements']).forEach(associationName => {
|
|
66
|
-
|
|
67
|
+
const associationMetadata = this.dream['getAssociationMetadata'](associationName);
|
|
68
|
+
if (associationMetadata === undefined)
|
|
69
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
70
|
+
this.query['hydrateAssociation']([this.dream], associationMetadata, this.associationToPreloadedDreamsAndWhatTheyPointTo({
|
|
67
71
|
pointsToPrimaryKey: this.dream.primaryKeyValue,
|
|
68
72
|
associatedModels: dreamWithLoadedAssociations[associationName],
|
|
69
73
|
}));
|
|
@@ -5,6 +5,7 @@ const pluralize_esm_1 = require("pluralize-esm");
|
|
|
5
5
|
const ConnectedToDB_js_1 = require("../db/ConnectedToDB.js");
|
|
6
6
|
const SoftDelete_js_1 = require("../decorators/class/SoftDelete.js");
|
|
7
7
|
const associationToGetterSetterProp_js_1 = require("../decorators/field/association/associationToGetterSetterProp.js");
|
|
8
|
+
const AssociationDeclaredWithoutAssociatedDreamClass_js_1 = require("../errors/associations/AssociationDeclaredWithoutAssociatedDreamClass.js");
|
|
8
9
|
const CannotAssociateThroughPolymorphic_js_1 = require("../errors/associations/CannotAssociateThroughPolymorphic.js");
|
|
9
10
|
const CannotJoinPolymorphicBelongsToError_js_1 = require("../errors/associations/CannotJoinPolymorphicBelongsToError.js");
|
|
10
11
|
const JoinAttemptedOnMissingAssociation_js_1 = require("../errors/associations/JoinAttemptedOnMissingAssociation.js");
|
|
@@ -21,6 +22,7 @@ const MissingRequiredCallbackFunctionToPluckEach_js_1 = require("../errors/Missi
|
|
|
21
22
|
const NoUpdateAllOnJoins_js_1 = require("../errors/NoUpdateAllOnJoins.js");
|
|
22
23
|
const NoUpdateOnAssociationQuery_js_1 = require("../errors/NoUpdateOnAssociationQuery.js");
|
|
23
24
|
const RecordNotFound_js_1 = require("../errors/RecordNotFound.js");
|
|
25
|
+
const UnexpectedUndefined_js_1 = require("../errors/UnexpectedUndefined.js");
|
|
24
26
|
const CalendarDate_js_1 = require("../helpers/CalendarDate.js");
|
|
25
27
|
const camelize_js_1 = require("../helpers/camelize.js");
|
|
26
28
|
const cloneDeepSafe_js_1 = require("../helpers/cloneDeepSafe.js");
|
|
@@ -575,7 +577,10 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
575
577
|
associationNamesToDreamClassesMap(associationNames, associationsToDreamClassesMap = {}) {
|
|
576
578
|
const namesToAssociationsAndDreamClasses = this.associationNamesToAssociationDataAndDreamClassesMap(associationNames);
|
|
577
579
|
return Object.keys(namesToAssociationsAndDreamClasses).reduce((remap, associationName) => {
|
|
578
|
-
|
|
580
|
+
const associationAndDreamClass = namesToAssociationsAndDreamClasses[associationName];
|
|
581
|
+
if (associationAndDreamClass === undefined)
|
|
582
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
583
|
+
remap[associationName] = associationAndDreamClass.dreamClass;
|
|
579
584
|
return remap;
|
|
580
585
|
}, associationsToDreamClassesMap);
|
|
581
586
|
}
|
|
@@ -587,7 +592,10 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
587
592
|
associationNamesToAssociationsMap(associationNames, associationsToAssociations = {}) {
|
|
588
593
|
const namesToAssociationsAndDreamClasses = this.associationNamesToAssociationDataAndDreamClassesMap(associationNames);
|
|
589
594
|
return Object.keys(namesToAssociationsAndDreamClasses).reduce((remap, associationName) => {
|
|
590
|
-
|
|
595
|
+
const associationAndDreamClass = namesToAssociationsAndDreamClasses[associationName];
|
|
596
|
+
if (associationAndDreamClass === undefined)
|
|
597
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
598
|
+
remap[associationName] = associationAndDreamClass.association;
|
|
591
599
|
return remap;
|
|
592
600
|
}, associationsToAssociations);
|
|
593
601
|
}
|
|
@@ -599,6 +607,8 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
599
607
|
associationNames.reduce((dreamClass, associationName) => {
|
|
600
608
|
const { name, alias } = (0, extractAssociationMetadataFromAssociationName_js_1.default)(associationName);
|
|
601
609
|
const association = dreamClass['getAssociationMetadata'](name);
|
|
610
|
+
if (association === undefined)
|
|
611
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
602
612
|
const through = association.through;
|
|
603
613
|
if (through) {
|
|
604
614
|
const { throughAssociation, throughAssociationDreamClass } = this.throughAssociationDetails(dreamClass, through);
|
|
@@ -608,6 +618,8 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
608
618
|
};
|
|
609
619
|
}
|
|
610
620
|
const nextDreamClass = association.modelCB();
|
|
621
|
+
if (alias === undefined)
|
|
622
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
611
623
|
associationsToDreamClassesMap[alias] = { association, dreamClass: nextDreamClass };
|
|
612
624
|
return nextDreamClass;
|
|
613
625
|
}, this.dreamClass);
|
|
@@ -618,6 +630,8 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
618
630
|
*/
|
|
619
631
|
throughAssociationDetails(dreamClass, through) {
|
|
620
632
|
const throughAssociation = dreamClass['getAssociationMetadata'](through);
|
|
633
|
+
if (throughAssociation === undefined)
|
|
634
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
621
635
|
const throughAssociationDreamClass = throughAssociation.modelCB();
|
|
622
636
|
return { throughAssociation, throughAssociationDreamClass };
|
|
623
637
|
}
|
|
@@ -656,7 +670,10 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
656
670
|
this.addThroughAssociatedDreamClassToInnerJoinDreamClasses(previousDreamClass, association, innerJoinDreamClasses);
|
|
657
671
|
const dreamClasses = [association.modelCB()].flat();
|
|
658
672
|
dreamClasses.forEach(dreamClass => innerJoinDreamClasses.push(dreamClass));
|
|
659
|
-
|
|
673
|
+
const dreamClass = dreamClasses[0];
|
|
674
|
+
if (dreamClass === undefined)
|
|
675
|
+
throw new AssociationDeclaredWithoutAssociatedDreamClass_js_1.default(previousDreamClass, association.as);
|
|
676
|
+
return dreamClass;
|
|
660
677
|
}
|
|
661
678
|
addThroughAssociatedDreamClassToInnerJoinDreamClasses(dreamClass, _association, innerJoinDreamClasses) {
|
|
662
679
|
const association = _association;
|
|
@@ -667,6 +684,8 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
667
684
|
if (!throughAssociation)
|
|
668
685
|
return;
|
|
669
686
|
const throughDreamClass = [throughAssociation.modelCB()].flat()[0];
|
|
687
|
+
if (throughDreamClass === undefined)
|
|
688
|
+
throw new AssociationDeclaredWithoutAssociatedDreamClass_js_1.default(dreamClass, throughAssociation.as);
|
|
670
689
|
innerJoinDreamClasses.push(throughDreamClass);
|
|
671
690
|
this.addThroughAssociatedDreamClassToInnerJoinDreamClasses(dreamClass, throughAssociation, innerJoinDreamClasses);
|
|
672
691
|
}
|
|
@@ -1125,8 +1144,12 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
1125
1144
|
let nextColumnAliasCounter = 0;
|
|
1126
1145
|
aliases.forEach((aliasOrExpression) => {
|
|
1127
1146
|
const alias = (0, extractAssociationMetadataFromAssociationName_js_1.default)(aliasOrExpression).alias;
|
|
1147
|
+
if (alias === undefined)
|
|
1148
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
1128
1149
|
associationAliasToColumnAliasMap[alias] ||= {};
|
|
1129
1150
|
const aliasedDreamClass = aliasToDreamClassesMap[alias];
|
|
1151
|
+
if (aliasedDreamClass === undefined)
|
|
1152
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
1130
1153
|
const association = aliasToAssociationsMap[alias];
|
|
1131
1154
|
const columns = alias === this.baseSqlAlias
|
|
1132
1155
|
? options.columns
|
|
@@ -1136,12 +1159,18 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
1136
1159
|
columns.forEach((column) => {
|
|
1137
1160
|
const columnAlias = `dr${nextColumnAliasCounter++}`;
|
|
1138
1161
|
kyselyQuery = kyselyQuery.select(`${this.namespaceColumn(column, alias)} as ${columnAlias}`);
|
|
1139
|
-
associationAliasToColumnAliasMap[alias]
|
|
1162
|
+
const columnAliasMap = associationAliasToColumnAliasMap[alias];
|
|
1163
|
+
if (columnAliasMap === undefined)
|
|
1164
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
1165
|
+
columnAliasMap[column] = columnAlias;
|
|
1140
1166
|
});
|
|
1141
1167
|
if (association?.type === 'HasOne' || association?.type === 'HasMany') {
|
|
1142
1168
|
const setupPreloadData = (dbColumnName) => {
|
|
1143
1169
|
const columnAlias = `dr${nextColumnAliasCounter++}`;
|
|
1144
|
-
associationAliasToColumnAliasMap[association.through]
|
|
1170
|
+
const columnAliasMap = associationAliasToColumnAliasMap[association.through];
|
|
1171
|
+
if (columnAliasMap === undefined)
|
|
1172
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
1173
|
+
columnAliasMap[dbColumnName] = columnAlias;
|
|
1145
1174
|
kyselyQuery = kyselyQuery.select(`${this.namespaceColumn(dbColumnName, association.through)} as ${columnAlias}`);
|
|
1146
1175
|
};
|
|
1147
1176
|
if (association.through && association.preloadThroughColumns) {
|
|
@@ -1174,20 +1203,35 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
1174
1203
|
}
|
|
1175
1204
|
fleshOutJoinLoadExecutionResults({ currentAlias, singleSqlResult, aliasToDreamIdMap, associationAliasToColumnAliasMap, aliasToAssociationsMap, aliasToDreamClassesMap, leftJoinStatements, }) {
|
|
1176
1205
|
const dreamClass = aliasToDreamClassesMap[currentAlias];
|
|
1206
|
+
if (dreamClass === undefined)
|
|
1207
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
1177
1208
|
const columnToColumnAliasMap = associationAliasToColumnAliasMap[currentAlias];
|
|
1178
|
-
|
|
1209
|
+
if (columnToColumnAliasMap === undefined)
|
|
1210
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
1211
|
+
const primaryKeyName = dreamClass.primaryKey;
|
|
1212
|
+
if (primaryKeyName === undefined)
|
|
1213
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
1214
|
+
const columnAlias = columnToColumnAliasMap[primaryKeyName];
|
|
1215
|
+
if (columnAlias === undefined)
|
|
1216
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
1217
|
+
const primaryKeyValue = singleSqlResult[columnAlias];
|
|
1179
1218
|
if (!primaryKeyValue)
|
|
1180
1219
|
return null;
|
|
1181
1220
|
aliasToDreamIdMap[currentAlias] ||= new Map();
|
|
1182
1221
|
if (!aliasToDreamIdMap[currentAlias].get(primaryKeyValue)) {
|
|
1183
1222
|
const columnValueMap = Object.keys(columnToColumnAliasMap).reduce((columnNameValueMap, columnName) => {
|
|
1184
|
-
|
|
1223
|
+
const columnAlias = columnToColumnAliasMap[columnName];
|
|
1224
|
+
if (columnAlias === undefined)
|
|
1225
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
1226
|
+
columnNameValueMap[columnName] = singleSqlResult[columnAlias];
|
|
1185
1227
|
return columnNameValueMap;
|
|
1186
1228
|
}, {});
|
|
1187
1229
|
const dream = (0, sqlResultToDreamInstance_js_1.default)(dreamClass, columnValueMap);
|
|
1188
1230
|
const association = aliasToAssociationsMap[currentAlias];
|
|
1189
1231
|
if (association && association.through && association.preloadThroughColumns) {
|
|
1190
1232
|
const throughAssociationColumnToColumnAliasMap = associationAliasToColumnAliasMap[association.through];
|
|
1233
|
+
if (throughAssociationColumnToColumnAliasMap === undefined)
|
|
1234
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
1191
1235
|
this.hydratePreloadedThroughColumns({
|
|
1192
1236
|
association,
|
|
1193
1237
|
columnToColumnAliasMap: throughAssociationColumnToColumnAliasMap,
|
|
@@ -1195,12 +1239,14 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
1195
1239
|
singleSqlResult,
|
|
1196
1240
|
});
|
|
1197
1241
|
}
|
|
1198
|
-
aliasToDreamIdMap[(0, protectAgainstPollutingAssignment_js_1.default)(currentAlias)]
|
|
1242
|
+
aliasToDreamIdMap[(0, protectAgainstPollutingAssignment_js_1.default)(currentAlias)]?.set(primaryKeyValue, dream);
|
|
1199
1243
|
}
|
|
1200
1244
|
const dream = aliasToDreamIdMap[currentAlias].get(primaryKeyValue);
|
|
1201
1245
|
Object.keys(leftJoinStatements).forEach(nextAlias => {
|
|
1202
1246
|
const { name: associationName, alias } = (0, extractAssociationMetadataFromAssociationName_js_1.default)(nextAlias);
|
|
1203
1247
|
const association = dreamClass['getAssociationMetadata'](associationName);
|
|
1248
|
+
if (association === undefined)
|
|
1249
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
1204
1250
|
const associatedDream = this.fleshOutJoinLoadExecutionResults({
|
|
1205
1251
|
currentAlias: alias,
|
|
1206
1252
|
singleSqlResult,
|
|
@@ -1253,8 +1299,17 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
1253
1299
|
return columnName;
|
|
1254
1300
|
});
|
|
1255
1301
|
}
|
|
1256
|
-
columnNames.forEach(columnName =>
|
|
1257
|
-
|
|
1302
|
+
columnNames.forEach(columnName => {
|
|
1303
|
+
const preloadedThroughColumnName = columnNameToPreloadedThroughColumnNameMap[columnName];
|
|
1304
|
+
if (preloadedThroughColumnName === undefined)
|
|
1305
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
1306
|
+
const columnAlias = columnToColumnAliasMap[columnName];
|
|
1307
|
+
if (columnAlias === undefined) {
|
|
1308
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
1309
|
+
}
|
|
1310
|
+
;
|
|
1311
|
+
dream.preloadedThroughColumns[preloadedThroughColumnName] = singleSqlResult[columnAlias];
|
|
1312
|
+
});
|
|
1258
1313
|
}
|
|
1259
1314
|
/**
|
|
1260
1315
|
* Plucks the provided fields from the given dream class table
|
|
@@ -1807,6 +1862,8 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
1807
1862
|
return;
|
|
1808
1863
|
const { name, alias } = (0, extractAssociationMetadataFromAssociationName_js_1.default)(associationName);
|
|
1809
1864
|
const association = dream['getAssociationMetadata'](name);
|
|
1865
|
+
if (association === undefined)
|
|
1866
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
1810
1867
|
const dreamClass = dream.constructor;
|
|
1811
1868
|
const dreamClassToHydrate = association.modelCB();
|
|
1812
1869
|
if ((association.polymorphic && association.type === 'BelongsTo') || Array.isArray(dreamClassToHydrate))
|
|
@@ -1896,6 +1953,8 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
1896
1953
|
return undefined;
|
|
1897
1954
|
return Object.keys(preloadOnStatements).reduce((agg, key) => {
|
|
1898
1955
|
const value = preloadOnStatements[key];
|
|
1956
|
+
if (value === undefined)
|
|
1957
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
1899
1958
|
// filter out plain objects, but not ops and not on/notOn/onAny statements
|
|
1900
1959
|
// because plain objects are just the next level of nested preload
|
|
1901
1960
|
if (key === 'on' ||
|
|
@@ -2011,7 +2070,7 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
2011
2070
|
query = results.query;
|
|
2012
2071
|
dreamClass = results.dreamClass;
|
|
2013
2072
|
association = results.association;
|
|
2014
|
-
const timeToApplyThroughAssociations = throughAssociations.length && throughAssociations[0]
|
|
2073
|
+
const timeToApplyThroughAssociations = throughAssociations.length && throughAssociations[0]?.source === association.as;
|
|
2015
2074
|
const originalPreviousAssociationTableOrAlias = previousAssociationTableOrAlias;
|
|
2016
2075
|
previousAssociationTableOrAlias = results.previousAssociationTableOrAlias;
|
|
2017
2076
|
const throughClass = results.throughClass;
|
|
@@ -2503,7 +2562,10 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
2503
2562
|
checkForQueryViolations() {
|
|
2504
2563
|
const invalidWhereNotClauses = this.similarityStatementBuilder().whereNotStatementsWithSimilarityClauses();
|
|
2505
2564
|
if (invalidWhereNotClauses.length) {
|
|
2506
|
-
const
|
|
2565
|
+
const invalidWhereNotClause = invalidWhereNotClauses[0];
|
|
2566
|
+
if (invalidWhereNotClause === undefined)
|
|
2567
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
2568
|
+
const { tableName, columnName, opsStatement } = invalidWhereNotClause;
|
|
2507
2569
|
throw new CannotNegateSimilarityClause_js_1.default(tableName, columnName, opsStatement.value);
|
|
2508
2570
|
}
|
|
2509
2571
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = associationUpdateQuery;
|
|
4
|
+
const UnexpectedUndefined_js_1 = require("../../../errors/UnexpectedUndefined.js");
|
|
4
5
|
const namespaceColumn_js_1 = require("../../../helpers/namespaceColumn.js");
|
|
5
6
|
const applyScopeBypassingSettingsToQuery_js_1 = require("../applyScopeBypassingSettingsToQuery.js");
|
|
6
7
|
function associationUpdateQuery(dream, txn = null, associationName, { joinOnStatements, bypassAllDefaultScopes, defaultScopesToBypass, }) {
|
|
7
8
|
const association = dream['associationMetadataMap']()[associationName];
|
|
9
|
+
if (association === undefined)
|
|
10
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
8
11
|
const associationClass = association.modelCB();
|
|
9
12
|
if (Array.isArray(associationClass)) {
|
|
10
13
|
throw new Error('Cannot update a polymorphic association using associationUpdateQuery');
|
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = createAssociation;
|
|
4
4
|
const CannotCreateAssociationWithThroughContext_js_1 = require("../../../errors/associations/CannotCreateAssociationWithThroughContext.js");
|
|
5
|
+
const UnexpectedUndefined_js_1 = require("../../../errors/UnexpectedUndefined.js");
|
|
5
6
|
async function createAssociation(dream, txn = null, associationName, opts = {}) {
|
|
6
7
|
const association = dream['associationMetadataMap']()[associationName];
|
|
8
|
+
if (association === undefined)
|
|
9
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
7
10
|
if (Array.isArray(association.modelCB())) {
|
|
8
11
|
throw new Error(`
|
|
9
12
|
Cannot create polymorphic associations using createAssociation
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = checkSingleValidation;
|
|
4
4
|
const NonLoadedAssociation_js_1 = require("../../errors/associations/NonLoadedAssociation.js");
|
|
5
|
+
const UnexpectedUndefined_js_1 = require("../../errors/UnexpectedUndefined.js");
|
|
5
6
|
function checkSingleValidation(dream, validation) {
|
|
6
7
|
let value;
|
|
7
8
|
try {
|
|
@@ -12,6 +13,8 @@ function checkSingleValidation(dream, validation) {
|
|
|
12
13
|
throw error;
|
|
13
14
|
}
|
|
14
15
|
let parsedFloat;
|
|
16
|
+
let metadataMap;
|
|
17
|
+
let associationMetadata;
|
|
15
18
|
switch (validation.type) {
|
|
16
19
|
case 'presence':
|
|
17
20
|
return !isBlank(value);
|
|
@@ -42,7 +45,11 @@ function checkSingleValidation(dream, validation) {
|
|
|
42
45
|
validation.options.length.max &&
|
|
43
46
|
value.length <= validation.options.length.max);
|
|
44
47
|
case 'requiredBelongsTo':
|
|
45
|
-
|
|
48
|
+
metadataMap = dream['associationMetadataMap']();
|
|
49
|
+
associationMetadata = metadataMap[validation.column];
|
|
50
|
+
if (associationMetadata === undefined)
|
|
51
|
+
throw new UnexpectedUndefined_js_1.default();
|
|
52
|
+
return !!(value || dream[associationMetadata.foreignKey()]);
|
|
46
53
|
default:
|
|
47
54
|
throw new Error(`Unhandled validation type found while running validations: ${validation.type}`);
|
|
48
55
|
}
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = extractAssociationMetadataFromAssociationName;
|
|
4
4
|
function extractAssociationMetadataFromAssociationName(associationName) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
if (/ as /.test(associationName)) {
|
|
6
|
+
const [name, alias] = associationName.split(/ as /);
|
|
7
|
+
return { name: name ?? associationName, alias: alias ?? associationName };
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
return { name: associationName, alias: associationName };
|
|
11
|
+
}
|
|
8
12
|
}
|
|
@@ -17,7 +17,7 @@ Try something like this in your ${this.dreamClass.sanitizedName}'s table getter:
|
|
|
17
17
|
|
|
18
18
|
class ${this.dreamClass.sanitizedName} {
|
|
19
19
|
...
|
|
20
|
-
public get table() {
|
|
20
|
+
public override get table() {
|
|
21
21
|
return '${(0, pluralize_esm_1.default)((0, snakeify_js_1.default)(this.dreamClass.sanitizedName))}'
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class UnexpectedUndefined extends Error {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
6
|
+
}
|
|
7
|
+
get message() {
|
|
8
|
+
return `Undefined detected where it should never happen since we are iterating
|
|
9
|
+
over keys of an internal object that should not have undefined values.
|
|
10
|
+
|
|
11
|
+
This was added as part of activating noUncheckedIndexedAccess in tsconfig.`;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.default = UnexpectedUndefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class AssociationDeclaredWithoutAssociatedDreamClass extends Error {
|
|
4
|
+
dreamClass;
|
|
5
|
+
associationName;
|
|
6
|
+
constructor(dreamClass, associationName) {
|
|
7
|
+
super();
|
|
8
|
+
this.dreamClass = dreamClass;
|
|
9
|
+
this.associationName = associationName;
|
|
10
|
+
}
|
|
11
|
+
get message() {
|
|
12
|
+
return `Association ${String(this.associationName)} on Dream class
|
|
13
|
+
${this.dreamClass.sanitizedName} was declared without the global name
|
|
14
|
+
of a Dream class.`;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.default = AssociationDeclaredWithoutAssociatedDreamClass;
|
|
@@ -5,11 +5,11 @@ function argAndValue(arg, args) {
|
|
|
5
5
|
const argIndex = args.findIndex(a => a === arg);
|
|
6
6
|
const foundArg = argIndex === -1 ? null : args[argIndex];
|
|
7
7
|
const foundValue = argIndex === -1 ? null : valueOrNull(argIndex, args);
|
|
8
|
-
return [foundArg, foundValue];
|
|
8
|
+
return [foundArg ?? null, foundValue];
|
|
9
9
|
}
|
|
10
10
|
function valueOrNull(argIndex, args) {
|
|
11
|
-
|
|
12
|
-
if (/--/.test(value))
|
|
13
|
-
|
|
11
|
+
const value = args[argIndex + 1];
|
|
12
|
+
if (value === undefined || /--/.test(value))
|
|
13
|
+
return null;
|
|
14
14
|
return value;
|
|
15
15
|
}
|
|
@@ -20,7 +20,7 @@ class CalendarDate {
|
|
|
20
20
|
return new CalendarDate(dateTime);
|
|
21
21
|
}
|
|
22
22
|
static fromJSDate(javascriptDate, { zone } = {}) {
|
|
23
|
-
return new CalendarDate(DateTime_js_1.DateTime.fromJSDate(javascriptDate, { zone }));
|
|
23
|
+
return new CalendarDate(DateTime_js_1.DateTime.fromJSDate(javascriptDate, zone ? { zone } : undefined));
|
|
24
24
|
}
|
|
25
25
|
static newInvalidDate() {
|
|
26
26
|
return new CalendarDate(null);
|