@rvoh/dream 0.29.3 → 0.29.5
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 +58 -1
- package/dist/cjs/src/db/DreamDbConnection.js +7 -1
- package/dist/cjs/src/db/errors.js +10 -3
- package/dist/cjs/src/decorators/STI.js +1 -1
- package/dist/cjs/src/decorators/associations/shared.js +3 -3
- package/dist/cjs/src/decorators/hooks/AfterCreate.js +1 -1
- package/dist/cjs/src/decorators/hooks/AfterCreateCommit.js +1 -1
- package/dist/cjs/src/decorators/hooks/AfterDestroy.js +1 -1
- package/dist/cjs/src/decorators/hooks/AfterDestroyCommit.js +1 -1
- package/dist/cjs/src/decorators/hooks/AfterSave.js +1 -1
- package/dist/cjs/src/decorators/hooks/AfterSaveCommit.js +1 -1
- package/dist/cjs/src/decorators/hooks/AfterUpdate.js +1 -1
- package/dist/cjs/src/decorators/hooks/AfterUpdateCommit.js +1 -1
- package/dist/cjs/src/decorators/hooks/BeforeCreate.js +1 -1
- package/dist/cjs/src/decorators/hooks/BeforeDestroy.js +1 -1
- package/dist/cjs/src/decorators/hooks/BeforeSave.js +1 -1
- package/dist/cjs/src/decorators/hooks/BeforeUpdate.js +1 -1
- package/dist/cjs/src/dream/Query.js +40 -20
- package/dist/cjs/src/dream/internal/associations/createAssociation.js +1 -1
- package/dist/cjs/src/dream/internal/runHooksFor.js +1 -1
- package/dist/cjs/src/dream/internal/saveDream.js +1 -1
- package/dist/cjs/src/dream/internal/sqlResultToDreamInstance.js +1 -1
- package/dist/cjs/src/dream-application/index.js +6 -0
- package/dist/cjs/src/errors/CannotCallUndestroyOnANonSoftDeleteModel.js +1 -1
- package/dist/cjs/src/errors/CannotDefineAssociationWithBothDependentAndPassthrough.js +1 -1
- package/dist/cjs/src/errors/CannotDefineAssociationWithBothDependentAndRequiredOnClause.js +1 -1
- package/dist/cjs/src/errors/CannotPassUndefinedAsAValueToAWhereClause.js +1 -1
- package/dist/cjs/src/errors/CannotReloadUnsavedDream.js +1 -1
- package/dist/cjs/src/errors/CreateOrFindByFailedToCreateAndFind.js +1 -1
- package/dist/cjs/src/errors/DoNotSetEncryptedFieldsDirectly.js +1 -1
- package/dist/cjs/src/errors/MissingDeletedAtFieldForSoftDelete.js +1 -1
- package/dist/cjs/src/errors/MissingSerializersDefinition.js +5 -5
- package/dist/cjs/src/errors/MissingTable.js +4 -4
- package/dist/cjs/src/errors/NonBelongsToAssociationProvidedAsSortableDecoratorScope.js +2 -2
- package/dist/cjs/src/errors/NonExistentScopeProvidedToResort.js +2 -2
- package/dist/cjs/src/errors/SortableDecoratorRequiresColumnOrBelongsToAssociation.js +3 -3
- package/dist/cjs/src/errors/associations/CanOnlyPassBelongsToModelParam.js +1 -1
- package/dist/cjs/src/errors/associations/CannotAssociateThroughPolymorphic.js +1 -1
- package/dist/cjs/src/errors/associations/CannotCreateAssociationWithThroughContext.js +1 -1
- package/dist/cjs/src/errors/associations/CannotJoinPolymorphicBelongsToError.js +1 -1
- package/dist/cjs/src/errors/associations/CannotPassNullOrUndefinedToRequiredBelongsTo.js +1 -1
- package/dist/cjs/src/errors/associations/InvalidComputedForeignKey.js +2 -2
- package/dist/cjs/src/errors/associations/JoinAttemptedOnMissingAssociation.js +4 -4
- package/dist/cjs/src/errors/associations/MissingThroughAssociation.js +4 -4
- package/dist/cjs/src/errors/associations/MissingThroughAssociationSource.js +10 -10
- package/dist/cjs/src/errors/associations/NonLoadedAssociation.js +1 -1
- package/dist/cjs/src/errors/ops/AnyRequiresArrayColumn.js +1 -1
- package/dist/cjs/src/errors/schema-builder/FailedToIdentifyAssociation.js +4 -4
- package/dist/cjs/src/errors/sti/STIChildMissing.js +1 -1
- package/dist/cjs/src/errors/sti/StiChildIncompatibleWithSoftDeleteDecorator.js +1 -1
- package/dist/cjs/src/helpers/db/loadPgClient.js +6 -0
- package/dist/esm/src/Dream.js +58 -1
- package/dist/esm/src/db/DreamDbConnection.js +7 -1
- package/dist/esm/src/db/errors.js +10 -3
- package/dist/esm/src/decorators/STI.js +1 -1
- package/dist/esm/src/decorators/associations/shared.js +3 -3
- package/dist/esm/src/decorators/hooks/AfterCreate.js +1 -1
- package/dist/esm/src/decorators/hooks/AfterCreateCommit.js +1 -1
- package/dist/esm/src/decorators/hooks/AfterDestroy.js +1 -1
- package/dist/esm/src/decorators/hooks/AfterDestroyCommit.js +1 -1
- package/dist/esm/src/decorators/hooks/AfterSave.js +1 -1
- package/dist/esm/src/decorators/hooks/AfterSaveCommit.js +1 -1
- package/dist/esm/src/decorators/hooks/AfterUpdate.js +1 -1
- package/dist/esm/src/decorators/hooks/AfterUpdateCommit.js +1 -1
- package/dist/esm/src/decorators/hooks/BeforeCreate.js +1 -1
- package/dist/esm/src/decorators/hooks/BeforeDestroy.js +1 -1
- package/dist/esm/src/decorators/hooks/BeforeSave.js +1 -1
- package/dist/esm/src/decorators/hooks/BeforeUpdate.js +1 -1
- package/dist/esm/src/dream/Query.js +40 -20
- package/dist/esm/src/dream/internal/associations/createAssociation.js +1 -1
- package/dist/esm/src/dream/internal/runHooksFor.js +1 -1
- package/dist/esm/src/dream/internal/saveDream.js +1 -1
- package/dist/esm/src/dream/internal/sqlResultToDreamInstance.js +1 -1
- package/dist/esm/src/dream-application/index.js +6 -0
- package/dist/esm/src/errors/CannotCallUndestroyOnANonSoftDeleteModel.js +1 -1
- package/dist/esm/src/errors/CannotDefineAssociationWithBothDependentAndPassthrough.js +1 -1
- package/dist/esm/src/errors/CannotDefineAssociationWithBothDependentAndRequiredOnClause.js +1 -1
- package/dist/esm/src/errors/CannotPassUndefinedAsAValueToAWhereClause.js +1 -1
- package/dist/esm/src/errors/CannotReloadUnsavedDream.js +1 -1
- package/dist/esm/src/errors/CreateOrFindByFailedToCreateAndFind.js +1 -1
- package/dist/esm/src/errors/DoNotSetEncryptedFieldsDirectly.js +1 -1
- package/dist/esm/src/errors/MissingDeletedAtFieldForSoftDelete.js +1 -1
- package/dist/esm/src/errors/MissingSerializersDefinition.js +5 -5
- package/dist/esm/src/errors/MissingTable.js +4 -4
- package/dist/esm/src/errors/NonBelongsToAssociationProvidedAsSortableDecoratorScope.js +2 -2
- package/dist/esm/src/errors/NonExistentScopeProvidedToResort.js +2 -2
- package/dist/esm/src/errors/SortableDecoratorRequiresColumnOrBelongsToAssociation.js +3 -3
- package/dist/esm/src/errors/associations/CanOnlyPassBelongsToModelParam.js +1 -1
- package/dist/esm/src/errors/associations/CannotAssociateThroughPolymorphic.js +1 -1
- package/dist/esm/src/errors/associations/CannotCreateAssociationWithThroughContext.js +1 -1
- package/dist/esm/src/errors/associations/CannotJoinPolymorphicBelongsToError.js +1 -1
- package/dist/esm/src/errors/associations/CannotPassNullOrUndefinedToRequiredBelongsTo.js +1 -1
- package/dist/esm/src/errors/associations/InvalidComputedForeignKey.js +2 -2
- package/dist/esm/src/errors/associations/JoinAttemptedOnMissingAssociation.js +4 -4
- package/dist/esm/src/errors/associations/MissingThroughAssociation.js +4 -4
- package/dist/esm/src/errors/associations/MissingThroughAssociationSource.js +10 -10
- package/dist/esm/src/errors/associations/NonLoadedAssociation.js +1 -1
- package/dist/esm/src/errors/ops/AnyRequiresArrayColumn.js +1 -1
- package/dist/esm/src/errors/schema-builder/FailedToIdentifyAssociation.js +4 -4
- package/dist/esm/src/errors/sti/STIChildMissing.js +1 -1
- package/dist/esm/src/errors/sti/StiChildIncompatibleWithSoftDeleteDecorator.js +1 -1
- package/dist/esm/src/helpers/db/loadPgClient.js +6 -0
- package/dist/types/src/Dream.d.ts +49 -0
- package/dist/types/src/dream/Query.d.ts +11 -0
- package/docs/assets/search.js +1 -1
- package/docs/classes/Benchmark.html +2 -2
- package/docs/classes/CalendarDate.html +2 -2
- package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +3 -3
- package/docs/classes/Decorators.html +14 -14
- package/docs/classes/Dream.html +146 -122
- package/docs/classes/DreamApplication.html +4 -4
- package/docs/classes/DreamBin.html +2 -2
- package/docs/classes/DreamCLI.html +3 -3
- 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 +3 -3
- package/docs/classes/NonLoadedAssociation.html +3 -3
- package/docs/classes/Query.html +50 -50
- package/docs/classes/Range.html +2 -2
- package/docs/classes/RecordNotFound.html +3 -3
- package/docs/classes/ValidationError.html +3 -3
- 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/Scope.html +1 -1
- package/docs/functions/SoftDelete.html +1 -1
- package/docs/functions/Validate.html +1 -1
- package/docs/functions/Validates.html +1 -1
- package/docs/functions/Virtual.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/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/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/types/Camelized.html +1 -1
- package/docs/types/CommonOpenapiSchemaObjectFields.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/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
|
@@ -313,6 +313,43 @@ class Dream {
|
|
|
313
313
|
static get stiBaseClassOrOwnClass() {
|
|
314
314
|
return this.sti.baseClass || this;
|
|
315
315
|
}
|
|
316
|
+
/**
|
|
317
|
+
* @internal
|
|
318
|
+
*
|
|
319
|
+
* Returns either the base STI class name, or else this class name
|
|
320
|
+
*
|
|
321
|
+
* NOTE: This is necessary due to changes in esbuild strategy WRT esm,
|
|
322
|
+
* compiled class names can contain a prefixing underscore if they contain
|
|
323
|
+
* private fields.
|
|
324
|
+
*
|
|
325
|
+
* This can create confusion when the class name is used as an attribute,
|
|
326
|
+
* as is done in the case of polymorphic associations, which use the class
|
|
327
|
+
* name as the "type" value for the polymorphic association.
|
|
328
|
+
*
|
|
329
|
+
* As such, any time the class name is being used as a value, it should be
|
|
330
|
+
* done using this value, rather than going to the class name directly.
|
|
331
|
+
*
|
|
332
|
+
* see https://github.com/evanw/esbuild/issues/1260 for more information
|
|
333
|
+
*
|
|
334
|
+
* @returns string
|
|
335
|
+
*/
|
|
336
|
+
static get stiBaseClassOrOwnClassName() {
|
|
337
|
+
return this.stiBaseClassOrOwnClass.sanitizedName;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* @internal
|
|
341
|
+
*
|
|
342
|
+
* Returns the class name, replacing prefixed underscores, since esbuild
|
|
343
|
+
* will translate some class names to have underscore prefixes, which can
|
|
344
|
+
* cause unexpected behavior.
|
|
345
|
+
*
|
|
346
|
+
* see https://github.com/evanw/esbuild/issues/1260 for more information
|
|
347
|
+
*
|
|
348
|
+
* @returns string
|
|
349
|
+
*/
|
|
350
|
+
static get sanitizedName() {
|
|
351
|
+
return this.name.replace(/^_/, '');
|
|
352
|
+
}
|
|
316
353
|
/**
|
|
317
354
|
* @internal
|
|
318
355
|
*
|
|
@@ -323,6 +360,26 @@ class Dream {
|
|
|
323
360
|
get stiBaseClassOrOwnClass() {
|
|
324
361
|
return this.constructor.stiBaseClassOrOwnClass;
|
|
325
362
|
}
|
|
363
|
+
/**
|
|
364
|
+
* @internal
|
|
365
|
+
*
|
|
366
|
+
* Shadows .stiBaseClassOrOwnClassName. Returns a string
|
|
367
|
+
*
|
|
368
|
+
* @returns A string
|
|
369
|
+
*/
|
|
370
|
+
get stiBaseClassOrOwnClassName() {
|
|
371
|
+
return this.constructor.stiBaseClassOrOwnClassName;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* @internal
|
|
375
|
+
*
|
|
376
|
+
* Shadows .sanitizedName. Returns a string
|
|
377
|
+
*
|
|
378
|
+
* @returns A string
|
|
379
|
+
*/
|
|
380
|
+
get sanitizedConstructorName() {
|
|
381
|
+
return this.constructor.sanitizedName;
|
|
382
|
+
}
|
|
326
383
|
/**
|
|
327
384
|
* @internal
|
|
328
385
|
*
|
|
@@ -1858,7 +1915,7 @@ class Dream {
|
|
|
1858
1915
|
}
|
|
1859
1916
|
if (belongsToAssociationMetaData.polymorphic) {
|
|
1860
1917
|
const foreignKeyTypeField = belongsToAssociationMetaData.foreignKeyTypeField();
|
|
1861
|
-
returnValues[foreignKeyTypeField] = associatedObject?.
|
|
1918
|
+
returnValues[foreignKeyTypeField] = associatedObject?.stiBaseClassOrOwnClassName;
|
|
1862
1919
|
setAttributeOnDreamInstance(foreignKeyTypeField, returnValues[foreignKeyTypeField]);
|
|
1863
1920
|
}
|
|
1864
1921
|
}
|
|
@@ -2,10 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.dreamDbConnections = dreamDbConnections;
|
|
4
4
|
exports.closeAllDbConnections = closeAllDbConnections;
|
|
5
|
-
|
|
5
|
+
// after building for esm, importing pg using the following:
|
|
6
|
+
//
|
|
7
|
+
// import * as pg from 'pg'
|
|
8
|
+
//
|
|
9
|
+
// will crash. This is difficult to discover, since it only happens
|
|
10
|
+
// when being imported from our esm build.
|
|
6
11
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
7
12
|
// @ts-ignore
|
|
8
13
|
const pg_1 = require("pg");
|
|
14
|
+
const kysely_1 = require("kysely");
|
|
9
15
|
const index_js_1 = require("../dream-application/index.js");
|
|
10
16
|
const ConnectionConfRetriever_js_1 = require("./ConnectionConfRetriever.js");
|
|
11
17
|
let connections = {};
|
|
@@ -2,8 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PG_ERRORS = void 0;
|
|
4
4
|
exports.pgErrorType = pgErrorType;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
// after building for esm, importing pg using the following:
|
|
6
|
+
//
|
|
7
|
+
// import * as pg from 'pg'
|
|
8
|
+
//
|
|
9
|
+
// will crash. This is difficult to discover, since it only happens
|
|
10
|
+
// when being imported from our esm build.
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
const pg_1 = require("pg");
|
|
7
14
|
exports.PG_ERRORS = {
|
|
8
15
|
23505: 'UNIQUE_CONSTRAINT_VIOLATION',
|
|
9
16
|
};
|
|
@@ -11,7 +18,7 @@ function pgErrorFromCode(code) {
|
|
|
11
18
|
return exports.PG_ERRORS[code] || null;
|
|
12
19
|
}
|
|
13
20
|
function pgErrorType(error) {
|
|
14
|
-
if (error instanceof DatabaseError)
|
|
21
|
+
if (error instanceof pg_1.default.DatabaseError)
|
|
15
22
|
return pgErrorFromCode(error.code);
|
|
16
23
|
return null;
|
|
17
24
|
}
|
|
@@ -25,7 +25,7 @@ function STI(dreamClass, { value } = {}) {
|
|
|
25
25
|
stiChildClass['sti'] = {
|
|
26
26
|
active: true,
|
|
27
27
|
baseClass,
|
|
28
|
-
value: value || stiChildClass.
|
|
28
|
+
value: value || stiChildClass.sanitizedName,
|
|
29
29
|
};
|
|
30
30
|
stiChildClass[exports.STI_SCOPE_NAME] = function (query) {
|
|
31
31
|
return query.where({ type: stiChildClass['sti'].value });
|
|
@@ -47,7 +47,7 @@ function foreignKeyTypeField(foreignKey, dream, partialAssociation) {
|
|
|
47
47
|
}
|
|
48
48
|
function modelCBtoSingleDreamClass(dreamClass, partialAssociation) {
|
|
49
49
|
if (Array.isArray(partialAssociation.modelCB()))
|
|
50
|
-
throw new Error(`Polymorphic association ${partialAssociation.as} on model ${dreamClass.
|
|
50
|
+
throw new Error(`Polymorphic association ${partialAssociation.as} on model ${dreamClass.sanitizedName} requires an explicit foreignKey`);
|
|
51
51
|
return partialAssociation.modelCB();
|
|
52
52
|
}
|
|
53
53
|
function applyGetterAndSetter(target, partialAssociation, { foreignKeyBase, isBelongsTo, } = {}) {
|
|
@@ -85,7 +85,7 @@ function applyGetterAndSetter(target, partialAssociation, { foreignKeyBase, isBe
|
|
|
85
85
|
partialAssociation.primaryKeyValue(associatedModel);
|
|
86
86
|
if (partialAssociation.polymorphic)
|
|
87
87
|
this[foreignKeyTypeField(foreignKeyBase, dreamClass, partialAssociation)] =
|
|
88
|
-
associatedModel?.
|
|
88
|
+
associatedModel?.['sanitizedConstructorName'];
|
|
89
89
|
}
|
|
90
90
|
},
|
|
91
91
|
});
|
|
@@ -102,7 +102,7 @@ function associationPrimaryKeyAccessors(partialAssociation, dreamClass) {
|
|
|
102
102
|
if (Array.isArray(associationClass)) {
|
|
103
103
|
throw new Error(`
|
|
104
104
|
Cannot lookup primaryKey on polymorphic association:
|
|
105
|
-
dream class: ${dreamClass.
|
|
105
|
+
dream class: ${dreamClass.sanitizedName}
|
|
106
106
|
association: ${this.as}
|
|
107
107
|
`);
|
|
108
108
|
}
|
|
@@ -17,7 +17,7 @@ function afterCreateImplementation(target, key, opts = {}) {
|
|
|
17
17
|
if (!Object.getOwnPropertyDescriptor(dreamClass, 'hooks'))
|
|
18
18
|
dreamClass['hooks'] = (0, shared_js_1.blankHooksFactory)(dreamClass);
|
|
19
19
|
const hookStatement = {
|
|
20
|
-
className: dreamClass.
|
|
20
|
+
className: dreamClass.sanitizedName,
|
|
21
21
|
method: key,
|
|
22
22
|
type: 'afterCreate',
|
|
23
23
|
ifChanged: opts.ifChanged,
|
|
@@ -34,7 +34,7 @@ function afterCreateCommitImplementation(target, key, opts = {}) {
|
|
|
34
34
|
if (!Object.getOwnPropertyDescriptor(dreamClass, 'hooks'))
|
|
35
35
|
dreamClass['hooks'] = (0, shared_js_1.blankHooksFactory)(dreamClass);
|
|
36
36
|
const hookStatement = {
|
|
37
|
-
className: dreamClass.
|
|
37
|
+
className: dreamClass.sanitizedName,
|
|
38
38
|
method: key,
|
|
39
39
|
type: 'afterCreateCommit',
|
|
40
40
|
ifChanged: opts.ifChanged,
|
|
@@ -17,7 +17,7 @@ function afterDestroyImplementation(target, key) {
|
|
|
17
17
|
if (!Object.getOwnPropertyDescriptor(dreamClass, 'hooks'))
|
|
18
18
|
dreamClass['hooks'] = (0, shared_js_1.blankHooksFactory)(dreamClass);
|
|
19
19
|
const hookStatement = {
|
|
20
|
-
className: dreamClass.
|
|
20
|
+
className: dreamClass.sanitizedName,
|
|
21
21
|
method: key,
|
|
22
22
|
type: 'afterDestroy',
|
|
23
23
|
};
|
|
@@ -32,7 +32,7 @@ function afterDestroyCommitImplementation(target, key) {
|
|
|
32
32
|
if (!Object.getOwnPropertyDescriptor(dreamClass, 'hooks'))
|
|
33
33
|
dreamClass['hooks'] = (0, shared_js_1.blankHooksFactory)(dreamClass);
|
|
34
34
|
const hookStatement = {
|
|
35
|
-
className: dreamClass.
|
|
35
|
+
className: dreamClass.sanitizedName,
|
|
36
36
|
method: key,
|
|
37
37
|
type: 'afterDestroyCommit',
|
|
38
38
|
};
|
|
@@ -17,7 +17,7 @@ function afterSaveImplementation(target, key, opts = {}) {
|
|
|
17
17
|
if (!Object.getOwnPropertyDescriptor(dreamClass, 'hooks'))
|
|
18
18
|
dreamClass['hooks'] = (0, shared_js_1.blankHooksFactory)(dreamClass);
|
|
19
19
|
const hookStatement = {
|
|
20
|
-
className: dreamClass.
|
|
20
|
+
className: dreamClass.sanitizedName,
|
|
21
21
|
method: key,
|
|
22
22
|
type: 'afterSave',
|
|
23
23
|
ifChanged: opts.ifChanged,
|
|
@@ -34,7 +34,7 @@ function afterSaveCommitImplementation(target, key, opts = {}) {
|
|
|
34
34
|
if (!Object.getOwnPropertyDescriptor(dreamClass, 'hooks'))
|
|
35
35
|
dreamClass['hooks'] = (0, shared_js_1.blankHooksFactory)(dreamClass);
|
|
36
36
|
const hookStatement = {
|
|
37
|
-
className: dreamClass.
|
|
37
|
+
className: dreamClass.sanitizedName,
|
|
38
38
|
method: key,
|
|
39
39
|
type: 'afterSaveCommit',
|
|
40
40
|
ifChanged: opts.ifChanged,
|
|
@@ -17,7 +17,7 @@ function afterUpdateImplementation(target, key, opts = {}) {
|
|
|
17
17
|
if (!Object.getOwnPropertyDescriptor(dreamClass, 'hooks'))
|
|
18
18
|
dreamClass['hooks'] = (0, shared_js_1.blankHooksFactory)(dreamClass);
|
|
19
19
|
const hookStatement = {
|
|
20
|
-
className: dreamClass.
|
|
20
|
+
className: dreamClass.sanitizedName,
|
|
21
21
|
method: key,
|
|
22
22
|
type: 'afterUpdate',
|
|
23
23
|
ifChanged: opts.ifChanged,
|
|
@@ -34,7 +34,7 @@ function afterUpdateCommitImplementation(target, key, opts = {}) {
|
|
|
34
34
|
if (!Object.getOwnPropertyDescriptor(dreamClass, 'hooks'))
|
|
35
35
|
dreamClass['hooks'] = (0, shared_js_1.blankHooksFactory)(dreamClass);
|
|
36
36
|
const hookStatement = {
|
|
37
|
-
className: dreamClass.
|
|
37
|
+
className: dreamClass.sanitizedName,
|
|
38
38
|
method: key,
|
|
39
39
|
type: 'afterUpdateCommit',
|
|
40
40
|
ifChanged: opts.ifChanged,
|
|
@@ -17,7 +17,7 @@ function beforeCreateImplementation(target, key, opts = {}) {
|
|
|
17
17
|
if (!Object.getOwnPropertyDescriptor(dreamClass, 'hooks'))
|
|
18
18
|
dreamClass['hooks'] = (0, shared_js_1.blankHooksFactory)(dreamClass);
|
|
19
19
|
const hookStatement = {
|
|
20
|
-
className: dreamClass.
|
|
20
|
+
className: dreamClass.sanitizedName,
|
|
21
21
|
method: key,
|
|
22
22
|
type: 'beforeCreate',
|
|
23
23
|
ifChanging: opts.ifChanging,
|
|
@@ -17,7 +17,7 @@ function beforeDestroyImplementation(target, key) {
|
|
|
17
17
|
if (!Object.getOwnPropertyDescriptor(dreamClass, 'hooks'))
|
|
18
18
|
dreamClass['hooks'] = (0, shared_js_1.blankHooksFactory)(dreamClass);
|
|
19
19
|
const hookStatement = {
|
|
20
|
-
className: dreamClass.
|
|
20
|
+
className: dreamClass.sanitizedName,
|
|
21
21
|
method: key,
|
|
22
22
|
type: 'beforeDestroy',
|
|
23
23
|
};
|
|
@@ -17,7 +17,7 @@ function beforeSaveImplementation(target, key, opts = {}) {
|
|
|
17
17
|
if (!Object.getOwnPropertyDescriptor(dreamClass, 'hooks'))
|
|
18
18
|
dreamClass['hooks'] = (0, shared_js_1.blankHooksFactory)(dreamClass);
|
|
19
19
|
const hookStatement = {
|
|
20
|
-
className: dreamClass.
|
|
20
|
+
className: dreamClass.sanitizedName,
|
|
21
21
|
method: key,
|
|
22
22
|
type: 'beforeSave',
|
|
23
23
|
ifChanging: opts.ifChanging,
|
|
@@ -17,7 +17,7 @@ function beforeUpdateImplementation(target, key, opts = {}) {
|
|
|
17
17
|
if (!Object.getOwnPropertyDescriptor(dreamClass, 'hooks'))
|
|
18
18
|
dreamClass['hooks'] = (0, shared_js_1.blankHooksFactory)(dreamClass);
|
|
19
19
|
const hookStatement = {
|
|
20
|
-
className: dreamClass.
|
|
20
|
+
className: dreamClass.sanitizedName,
|
|
21
21
|
method: key,
|
|
22
22
|
type: 'beforeUpdate',
|
|
23
23
|
ifChanging: opts.ifChanging,
|
|
@@ -367,7 +367,7 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
367
367
|
async findOrFail(primaryKey) {
|
|
368
368
|
const record = await this.find(primaryKey);
|
|
369
369
|
if (!record)
|
|
370
|
-
throw new RecordNotFound_js_1.default(this.dreamInstance
|
|
370
|
+
throw new RecordNotFound_js_1.default(this.dreamInstance['sanitizedConstructorName']);
|
|
371
371
|
return record;
|
|
372
372
|
}
|
|
373
373
|
/**
|
|
@@ -402,7 +402,7 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
402
402
|
async findOrFailBy(whereStatement) {
|
|
403
403
|
const record = await this.findBy(whereStatement);
|
|
404
404
|
if (!record)
|
|
405
|
-
throw new RecordNotFound_js_1.default(this.dreamInstance
|
|
405
|
+
throw new RecordNotFound_js_1.default(this.dreamInstance['sanitizedConstructorName']);
|
|
406
406
|
return record;
|
|
407
407
|
}
|
|
408
408
|
/**
|
|
@@ -1101,6 +1101,9 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
1101
1101
|
// base model, it will be underscored (to match the table name), but when the selected column
|
|
1102
1102
|
// comes back from Kysely camelCased
|
|
1103
1103
|
aliases.push(field.includes('_') ? (0, camelize_js_1.default)(field) : field);
|
|
1104
|
+
// namespace the selection so that when plucking the same column name from
|
|
1105
|
+
// multpile tables, they don't get saved as the same name (e.g. select results with two `id` columns,
|
|
1106
|
+
// which the pg package then returns in an object with a single `id` key)
|
|
1104
1107
|
kyselyQuery = kyselyQuery.select(`${this.namespaceColumn(field)} as ${field}`);
|
|
1105
1108
|
});
|
|
1106
1109
|
return (await (0, executeDatabaseQuery_js_1.default)(kyselyQuery, 'execute')).map(singleResult => aliases.map(alias => singleResult[alias]));
|
|
@@ -1422,7 +1425,7 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
1422
1425
|
async firstOrFail() {
|
|
1423
1426
|
const record = await this.first();
|
|
1424
1427
|
if (!record)
|
|
1425
|
-
throw new RecordNotFound_js_1.default(this.dreamInstance
|
|
1428
|
+
throw new RecordNotFound_js_1.default(this.dreamInstance['sanitizedConstructorName']);
|
|
1426
1429
|
return record;
|
|
1427
1430
|
}
|
|
1428
1431
|
/**
|
|
@@ -1461,7 +1464,7 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
1461
1464
|
async lastOrFail() {
|
|
1462
1465
|
const record = await this.last();
|
|
1463
1466
|
if (!record)
|
|
1464
|
-
throw new RecordNotFound_js_1.default(this.dreamInstance
|
|
1467
|
+
throw new RecordNotFound_js_1.default(this.dreamInstance['sanitizedConstructorName']);
|
|
1465
1468
|
return record;
|
|
1466
1469
|
}
|
|
1467
1470
|
/**
|
|
@@ -1756,7 +1759,7 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
1756
1759
|
}
|
|
1757
1760
|
async preloadPolymorphicAssociationModel(dreams, association, associatedDreamClass, associatedDreams) {
|
|
1758
1761
|
const relevantAssociatedModels = dreams.filter((dream) => {
|
|
1759
|
-
return dream[association.foreignKeyTypeField()] === associatedDreamClass['
|
|
1762
|
+
return dream[association.foreignKeyTypeField()] === associatedDreamClass['stiBaseClassOrOwnClassName'];
|
|
1760
1763
|
});
|
|
1761
1764
|
if (relevantAssociatedModels.length) {
|
|
1762
1765
|
dreams.forEach((dream) => {
|
|
@@ -1779,7 +1782,7 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
1779
1782
|
for (const loadedAssociation of loadedAssociations) {
|
|
1780
1783
|
dreams
|
|
1781
1784
|
.filter((dream) => {
|
|
1782
|
-
return (dream[association.foreignKeyTypeField()] === loadedAssociation['
|
|
1785
|
+
return (dream[association.foreignKeyTypeField()] === loadedAssociation['stiBaseClassOrOwnClassName'] &&
|
|
1783
1786
|
dream[association.foreignKey()] === association.primaryKeyValue(loadedAssociation));
|
|
1784
1787
|
})
|
|
1785
1788
|
.forEach((dream) => {
|
|
@@ -1802,14 +1805,15 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
1802
1805
|
const dream = dreams.find(dream => dream['getAssociationMetadata'](associationName));
|
|
1803
1806
|
if (!dream)
|
|
1804
1807
|
return;
|
|
1805
|
-
const
|
|
1808
|
+
const { name, alias } = (0, extractAssociationMetadataFromAssociationName_js_1.default)(associationName);
|
|
1809
|
+
const association = dream['getAssociationMetadata'](name);
|
|
1806
1810
|
const dreamClass = dream.constructor;
|
|
1807
1811
|
const dreamClassToHydrate = association.modelCB();
|
|
1808
1812
|
if ((association.polymorphic && association.type === 'BelongsTo') || Array.isArray(dreamClassToHydrate))
|
|
1809
1813
|
return this.preloadPolymorphicBelongsTo(association, dreams);
|
|
1810
1814
|
const dreamClassToHydrateColumns = [...dreamClassToHydrate.columns()];
|
|
1811
1815
|
const throughColumnsToHydrate = [];
|
|
1812
|
-
const columnsToPluck = dreamClassToHydrateColumns.map(column => this.namespaceColumn(column.toString(),
|
|
1816
|
+
const columnsToPluck = dreamClassToHydrateColumns.map(column => this.namespaceColumn(column.toString(), alias));
|
|
1813
1817
|
const asHasAssociation = association;
|
|
1814
1818
|
if (asHasAssociation.through && asHasAssociation.preloadThroughColumns) {
|
|
1815
1819
|
if ((0, typechecks_js_1.isObject)(asHasAssociation.preloadThroughColumns)) {
|
|
@@ -1921,9 +1925,17 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
1921
1925
|
}
|
|
1922
1926
|
return query;
|
|
1923
1927
|
}
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1928
|
+
/**
|
|
1929
|
+
* Each association in the chain is pushed onto `throughAssociations`
|
|
1930
|
+
* and `applyOneJoin` is recursively called. The trick is that the
|
|
1931
|
+
* through associations don't get written into the SQL; they
|
|
1932
|
+
* locate the next association we need to build into the SQL,
|
|
1933
|
+
* which is only run by the association that started the `through`
|
|
1934
|
+
* chain. The final association at the end of the `through` chain _is_
|
|
1935
|
+
* written into the SQL as a full association, but the modifications from
|
|
1936
|
+
* the `through` association are only added when the recursion returns
|
|
1937
|
+
* back to the association that kicked off the through associations.
|
|
1938
|
+
*/
|
|
1927
1939
|
joinsBridgeThroughAssociations({ query, dreamClass, association, previousAssociationTableOrAlias, throughAssociations, joinType, }) {
|
|
1928
1940
|
if (association.type === 'BelongsTo' || !association.through) {
|
|
1929
1941
|
return {
|
|
@@ -2004,25 +2016,33 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
2004
2016
|
previousAssociationTableOrAlias = results.previousAssociationTableOrAlias;
|
|
2005
2017
|
const throughClass = results.throughClass;
|
|
2006
2018
|
if (timeToApplyThroughAssociations) {
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2019
|
+
/**
|
|
2020
|
+
* Each association in the chain is pushed onto `throughAssociations`
|
|
2021
|
+
* and `applyOneJoin` is recursively called. The trick is that the
|
|
2022
|
+
* through associations don't get written into the SQL; they
|
|
2023
|
+
* locate the next association we need to build into the SQL,
|
|
2024
|
+
* which is only run by the association that started the `through`
|
|
2025
|
+
* chain (thus the
|
|
2026
|
+
* `throughAssociations.length && throughAssociations[0].source === association.as`
|
|
2027
|
+
* above). The final association at the end of the `through` chain _is_
|
|
2028
|
+
* written into the SQL as a full association, but the modifications from
|
|
2029
|
+
* the `through` association are only added when the recursion returns
|
|
2030
|
+
* back to the association that kicked off the through associations.
|
|
2031
|
+
*/
|
|
2012
2032
|
throughAssociations.forEach((throughAssociation) => {
|
|
2013
2033
|
if (throughAssociation.type === 'HasMany') {
|
|
2014
2034
|
if (query?.distinctOn && throughAssociation.distinct) {
|
|
2015
2035
|
query = query.distinctOn(this.distinctColumnNameForAssociation({
|
|
2016
2036
|
association: throughAssociation,
|
|
2017
|
-
tableNameOrAlias:
|
|
2037
|
+
tableNameOrAlias: currentAssociationTableOrAlias,
|
|
2018
2038
|
foreignKey: throughAssociation.primaryKey(),
|
|
2019
2039
|
}));
|
|
2020
2040
|
}
|
|
2021
2041
|
if (throughAssociation.order) {
|
|
2022
2042
|
query = this.applyOrderStatementForAssociation({
|
|
2023
2043
|
query,
|
|
2024
|
-
tableNameOrAlias: throughAssociation.as,
|
|
2025
2044
|
association: throughAssociation,
|
|
2045
|
+
tableNameOrAlias: currentAssociationTableOrAlias,
|
|
2026
2046
|
});
|
|
2027
2047
|
}
|
|
2028
2048
|
}
|
|
@@ -2072,8 +2092,8 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
2072
2092
|
if (association.polymorphic) {
|
|
2073
2093
|
join = join.on((eb) => this.whereStatementToExpressionWrapper(eb, this.aliasWhereStatement({
|
|
2074
2094
|
[association.foreignKeyTypeField()]: throughClass
|
|
2075
|
-
? throughClass['
|
|
2076
|
-
: dreamClass['
|
|
2095
|
+
? throughClass['stiBaseClassOrOwnClassName']
|
|
2096
|
+
: dreamClass['stiBaseClassOrOwnClassName'],
|
|
2077
2097
|
}, currentAssociationTableOrAlias)));
|
|
2078
2098
|
}
|
|
2079
2099
|
if (timeToApplyThroughAssociations) {
|
|
@@ -28,7 +28,7 @@ async function createAssociation(dream, txn = null, associationName, opts = {})
|
|
|
28
28
|
...opts,
|
|
29
29
|
};
|
|
30
30
|
if (hasAssociation.polymorphic) {
|
|
31
|
-
modifiedOpts[hasAssociation.foreignKeyTypeField()] = dream['
|
|
31
|
+
modifiedOpts[hasAssociation.foreignKeyTypeField()] = dream['stiBaseClassOrOwnClassName'];
|
|
32
32
|
}
|
|
33
33
|
if (txn) {
|
|
34
34
|
hasresult = await associationClass.txn(txn).create(modifiedOpts);
|
|
@@ -55,7 +55,7 @@ async function runHook(statement, dream, txn) {
|
|
|
55
55
|
Attempting to run ${statement.method} as part of the ${statement.type}
|
|
56
56
|
Dream model hook sequence, but we encountered a method that does not exist.
|
|
57
57
|
|
|
58
|
-
Please make sure "${statement.method}" is defined on ${dream
|
|
58
|
+
Please make sure "${statement.method}" is defined on ${dream['sanitizedConstructorName']}
|
|
59
59
|
`);
|
|
60
60
|
}
|
|
61
61
|
await dream[statement.method](txn);
|
|
@@ -23,7 +23,7 @@ async function saveDream(dream, txn = null, { skipHooks = false } = {}) {
|
|
|
23
23
|
// need to check validations after running before hooks, or else
|
|
24
24
|
// model hooks that might make a model valid cannot run
|
|
25
25
|
if (dream.isInvalid)
|
|
26
|
-
throw new ValidationError_js_1.default(dream
|
|
26
|
+
throw new ValidationError_js_1.default(dream['sanitizedConstructorName'], dream.errors);
|
|
27
27
|
if (alreadyPersisted && !dream.isDirty)
|
|
28
28
|
return dream;
|
|
29
29
|
let query;
|
|
@@ -29,7 +29,7 @@ function sqlResultToDreamInstance(dreamClass, sqlResult) {
|
|
|
29
29
|
function findExtendingDreamClass(dreamClass, type) {
|
|
30
30
|
if (!dreamClass['extendedBy'])
|
|
31
31
|
return undefined;
|
|
32
|
-
const extendingDreamClass = dreamClass['extendedBy'].find(extendingDreamClass => extendingDreamClass.
|
|
32
|
+
const extendingDreamClass = dreamClass['extendedBy'].find(extendingDreamClass => extendingDreamClass.sanitizedName === type);
|
|
33
33
|
if (extendingDreamClass)
|
|
34
34
|
return extendingDreamClass;
|
|
35
35
|
return dreamClass['extendedBy']
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// after building for esm, importing pg using the following:
|
|
4
|
+
//
|
|
5
|
+
// import * as pg from 'pg'
|
|
6
|
+
//
|
|
7
|
+
// will crash. This is difficult to discover, since it only happens
|
|
8
|
+
// when being imported from our esm build.
|
|
3
9
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4
10
|
// @ts-ignore
|
|
5
11
|
const pg_1 = require("pg");
|
|
@@ -12,7 +12,7 @@ Cannot call "undestroy" on a non-SoftDelete model. Ensure that your
|
|
|
12
12
|
model has @SoftDelete applied before calling "undestroy":
|
|
13
13
|
|
|
14
14
|
@SoftDelete()
|
|
15
|
-
class ${this.dreamClass.
|
|
15
|
+
class ${this.dreamClass.sanitizedName} extends ApplicationModel {
|
|
16
16
|
...
|
|
17
17
|
}
|
|
18
18
|
`;
|
|
@@ -12,7 +12,7 @@ class CannotDefineAssociationWithBothDependentAndPassthrough extends Error {
|
|
|
12
12
|
return `
|
|
13
13
|
Cannot define association with both "dependent" and "DreamConst.passthrough".
|
|
14
14
|
Error found when trying to parse "${this.associationName}" on the
|
|
15
|
-
${this.dreamClass.
|
|
15
|
+
${this.dreamClass.sanitizedName} dream class.
|
|
16
16
|
`;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -12,7 +12,7 @@ class CannotDefineAssociationWithBothDependentAndRequiredOnClause extends Error
|
|
|
12
12
|
return `
|
|
13
13
|
Cannot define association with both "dependent" and "DreamConst.required".
|
|
14
14
|
Error found when trying to parse "${this.associationName}" on the
|
|
15
|
-
${this.dreamClass.
|
|
15
|
+
${this.dreamClass.sanitizedName} dream class.
|
|
16
16
|
`;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -12,7 +12,7 @@ class CannotPassUndefinedAsAValueToAWhereClause extends Error {
|
|
|
12
12
|
return `
|
|
13
13
|
Cannot pass undefined as a value to a where clause.
|
|
14
14
|
|
|
15
|
-
dream class: ${this.dreamClass.
|
|
15
|
+
dream class: ${this.dreamClass.sanitizedName}
|
|
16
16
|
key receiving an undefined value: ${this.key}
|
|
17
17
|
`;
|
|
18
18
|
}
|
|
@@ -8,7 +8,7 @@ class CreateOrFindByFailedToCreateAndFind extends Error {
|
|
|
8
8
|
}
|
|
9
9
|
get message() {
|
|
10
10
|
return `
|
|
11
|
-
Failed to create instance of ${this.dreamClass.
|
|
11
|
+
Failed to create instance of ${this.dreamClass.sanitizedName} and no matching model exists.
|
|
12
12
|
|
|
13
13
|
The likely cause is that one of the \`createWith\` fields violates
|
|
14
14
|
a uniqueness constraint.
|
|
@@ -15,7 +15,7 @@ class DoNotSetEncryptedFieldsDirectly extends Error {
|
|
|
15
15
|
Do not set @Encrypted columns directly. Instead, set their accessors, so that
|
|
16
16
|
those fields can be encrypted by Dream internally.
|
|
17
17
|
|
|
18
|
-
Dream class: ${this.dreamClass.
|
|
18
|
+
Dream class: ${this.dreamClass.sanitizedName}
|
|
19
19
|
Problematic setter: ${this.encryptedColumnName}
|
|
20
20
|
Setter to be used instead: ${this.encryptedProperty}`;
|
|
21
21
|
}
|
|
@@ -14,7 +14,7 @@ Whenever the using SoftDelete decorator, you must have either a deletedAt column
|
|
|
14
14
|
or else another column defined, along with an ovrriding getter on your model, like so:
|
|
15
15
|
|
|
16
16
|
@SoftDelete()
|
|
17
|
-
class ${this.dreamClass.
|
|
17
|
+
class ${this.dreamClass.sanitizedName} extends ApplicationModel {
|
|
18
18
|
public get deletedAtField() {
|
|
19
19
|
return 'customDeletedAtField' as const
|
|
20
20
|
}
|
|
@@ -9,14 +9,14 @@ class MissingSerializersDefinition extends Error {
|
|
|
9
9
|
get message() {
|
|
10
10
|
return `
|
|
11
11
|
Missing serializers definition on the following class
|
|
12
|
-
Dream class: ${this.dreamClass.
|
|
12
|
+
Dream class: ${this.dreamClass.sanitizedName}
|
|
13
13
|
|
|
14
|
-
Try something like this in your ${this.dreamClass.
|
|
14
|
+
Try something like this in your ${this.dreamClass.sanitizedName}'s serializer getter:
|
|
15
15
|
|
|
16
|
-
class ${this.dreamClass.
|
|
17
|
-
public get serializers(): DreamSerializers<${this.dreamClass.
|
|
16
|
+
class ${this.dreamClass.sanitizedName} {
|
|
17
|
+
public get serializers(): DreamSerializers<${this.dreamClass.sanitizedName}> {
|
|
18
18
|
return {
|
|
19
|
-
default: '${this.dreamClass.
|
|
19
|
+
default: '${this.dreamClass.sanitizedName}Serializer'
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
...
|
|
@@ -11,14 +11,14 @@ class MissingTable extends Error {
|
|
|
11
11
|
get message() {
|
|
12
12
|
return `
|
|
13
13
|
Missing table definition on the following dream class:
|
|
14
|
-
Dream class: ${this.dreamClass.
|
|
14
|
+
Dream class: ${this.dreamClass.sanitizedName}
|
|
15
15
|
|
|
16
|
-
Try something like this in your ${this.dreamClass.
|
|
16
|
+
Try something like this in your ${this.dreamClass.sanitizedName}'s table getter:
|
|
17
17
|
|
|
18
|
-
class ${this.dreamClass.
|
|
18
|
+
class ${this.dreamClass.sanitizedName} {
|
|
19
19
|
...
|
|
20
20
|
public get table() {
|
|
21
|
-
return '${(0, pluralize_esm_1.default)((0, snakeify_js_1.default)(this.dreamClass.
|
|
21
|
+
return '${(0, pluralize_esm_1.default)((0, snakeify_js_1.default)(this.dreamClass.sanitizedName))}'
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
`;
|
|
@@ -12,10 +12,10 @@ class NonBelongsToAssociationProvidedAsSortableDecoratorScope extends Error {
|
|
|
12
12
|
return `
|
|
13
13
|
Only BelongsTo associations are supported as scopes for the @Sortable decorator.
|
|
14
14
|
received:
|
|
15
|
-
dream model class: ${this.dreamClass.
|
|
15
|
+
dream model class: ${this.dreamClass.sanitizedName}
|
|
16
16
|
scope: ${this.scope}
|
|
17
17
|
|
|
18
|
-
BelongsTo scopes on ${this.dreamClass.
|
|
18
|
+
BelongsTo scopes on ${this.dreamClass.sanitizedName} are:
|
|
19
19
|
${this.dreamClass['associationMetadataByType'].belongsTo.map(assoc => assoc.as).join('\n ')}
|
|
20
20
|
`;
|
|
21
21
|
}
|