@rvoh/dream 0.34.0 → 0.35.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 +14 -0
- package/dist/cjs/src/dream/DreamInstanceTransactionBuilder.js +14 -0
- package/dist/cjs/src/dream/internal/destroyDream.js +1 -2
- package/dist/cjs/src/dream/internal/runHooksFor.js +66 -28
- package/dist/cjs/src/dream/internal/saveDream.js +2 -4
- package/dist/cjs/src/dream/internal/undestroyDream.js +1 -2
- package/dist/cjs/src/errors/associations/CannotAssociationQueryOnUnpersistedDream.js +18 -0
- package/dist/cjs/src/errors/associations/CannotCreateAssociationOnUnpersistedDream.js +18 -0
- package/dist/cjs/src/errors/associations/CannotDestroyAssociationOnUnpersistedDream.js +18 -0
- package/dist/cjs/src/errors/associations/CannotUpdateAssociationOnUnpersistedDream.js +18 -0
- package/dist/cjs/src/helpers/DreamLogos/DreamLogos.js +12 -0
- package/dist/cjs/src/helpers/{DreamGlam/howyadoins/whaaaaaaaaaaok.js → DreamLogos/logos.js} +2 -2
- package/dist/cjs/src/helpers/cli/autoGeneratedFileDisclaimer.js +2 -2
- package/dist/cjs/src/helpers/cli/generateDreamContent.js +2 -2
- package/dist/cjs/src/helpers/cli/generateSerializerContent.js +14 -6
- package/dist/cjs/src/index.js +3 -3
- package/dist/esm/src/Dream.js +14 -0
- package/dist/esm/src/dream/DreamInstanceTransactionBuilder.js +14 -0
- package/dist/esm/src/dream/internal/destroyDream.js +1 -2
- package/dist/esm/src/dream/internal/runHooksFor.js +66 -28
- package/dist/esm/src/dream/internal/saveDream.js +2 -4
- package/dist/esm/src/dream/internal/undestroyDream.js +1 -2
- package/dist/esm/src/errors/associations/CannotAssociationQueryOnUnpersistedDream.js +15 -0
- package/dist/esm/src/errors/associations/CannotCreateAssociationOnUnpersistedDream.js +15 -0
- package/dist/esm/src/errors/associations/CannotDestroyAssociationOnUnpersistedDream.js +15 -0
- package/dist/esm/src/errors/associations/CannotUpdateAssociationOnUnpersistedDream.js +15 -0
- package/dist/esm/src/helpers/DreamLogos/DreamLogos.js +9 -0
- package/dist/esm/src/helpers/{DreamGlam/howyadoins/whaaaaaaaaaaok.js → DreamLogos/logos.js} +1 -1
- package/dist/esm/src/helpers/cli/autoGeneratedFileDisclaimer.js +2 -2
- package/dist/esm/src/helpers/cli/generateDreamContent.js +2 -2
- package/dist/esm/src/helpers/cli/generateSerializerContent.js +14 -6
- package/dist/esm/src/index.js +1 -1
- package/dist/types/src/decorators/Decorators.d.ts +27 -27
- package/dist/types/src/errors/associations/CannotAssociationQueryOnUnpersistedDream.d.ts +7 -0
- package/dist/types/src/errors/associations/CannotCreateAssociationOnUnpersistedDream.d.ts +7 -0
- package/dist/types/src/errors/associations/CannotDestroyAssociationOnUnpersistedDream.d.ts +7 -0
- package/dist/types/src/errors/associations/CannotUpdateAssociationOnUnpersistedDream.d.ts +7 -0
- package/dist/types/src/helpers/DreamLogos/DreamLogos.d.ts +4 -0
- package/dist/types/src/helpers/DreamLogos/logos.d.ts +2 -0
- package/dist/types/src/index.d.ts +1 -1
- 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/CreateOrFindByFailedToCreateAndFind.html +3 -3
- package/docs/classes/Decorators.html +38 -38
- package/docs/classes/Dream.html +126 -126
- package/docs/classes/DreamApplication.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 +4 -0
- 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/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/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/untypedDb.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/modules.html +1 -1
- 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/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 +3 -3
- package/dist/cjs/src/dream/internal/safelyRunCommitHooks.js +0 -15
- package/dist/cjs/src/helpers/DreamGlam/DreamGlam.js +0 -16
- package/dist/cjs/src/helpers/DreamGlam/howyadoins/fluffstopherwalkin.js +0 -42
- package/dist/esm/src/dream/internal/safelyRunCommitHooks.js +0 -12
- package/dist/esm/src/helpers/DreamGlam/DreamGlam.js +0 -13
- package/dist/esm/src/helpers/DreamGlam/howyadoins/fluffstopherwalkin.js +0 -39
- package/dist/types/src/dream/internal/safelyRunCommitHooks.d.ts +0 -7
- package/dist/types/src/helpers/DreamGlam/DreamGlam.d.ts +0 -5
- package/dist/types/src/helpers/DreamGlam/howyadoins/fluffstopherwalkin.d.ts +0 -1
- package/dist/types/src/helpers/DreamGlam/howyadoins/whaaaaaaaaaaok.d.ts +0 -2
- package/docs/classes/DreamGlam.html +0 -5
package/dist/cjs/src/Dream.js
CHANGED
|
@@ -26,7 +26,11 @@ const undestroyDream_js_1 = require("./dream/internal/undestroyDream.js");
|
|
|
26
26
|
const LeftJoinLoadBuilder_js_1 = require("./dream/LeftJoinLoadBuilder.js");
|
|
27
27
|
const LoadBuilder_js_1 = require("./dream/LoadBuilder.js");
|
|
28
28
|
const Query_js_1 = require("./dream/Query.js");
|
|
29
|
+
const CannotAssociationQueryOnUnpersistedDream_js_1 = require("./errors/associations/CannotAssociationQueryOnUnpersistedDream.js");
|
|
30
|
+
const CannotCreateAssociationOnUnpersistedDream_js_1 = require("./errors/associations/CannotCreateAssociationOnUnpersistedDream.js");
|
|
31
|
+
const CannotDestroyAssociationOnUnpersistedDream_js_1 = require("./errors/associations/CannotDestroyAssociationOnUnpersistedDream.js");
|
|
29
32
|
const CannotPassNullOrUndefinedToRequiredBelongsTo_js_1 = require("./errors/associations/CannotPassNullOrUndefinedToRequiredBelongsTo.js");
|
|
33
|
+
const CannotUpdateAssociationOnUnpersistedDream_js_1 = require("./errors/associations/CannotUpdateAssociationOnUnpersistedDream.js");
|
|
30
34
|
const CanOnlyPassBelongsToModelParam_js_1 = require("./errors/associations/CanOnlyPassBelongsToModelParam.js");
|
|
31
35
|
const NonLoadedAssociation_js_1 = require("./errors/associations/NonLoadedAssociation.js");
|
|
32
36
|
const CannotCallUndestroyOnANonSoftDeleteModel_js_1 = require("./errors/CannotCallUndestroyOnANonSoftDeleteModel.js");
|
|
@@ -2547,6 +2551,8 @@ class Dream {
|
|
|
2547
2551
|
* @returns The created association
|
|
2548
2552
|
*/
|
|
2549
2553
|
async createAssociation(associationName, attributes = {}) {
|
|
2554
|
+
if (this.isNewRecord)
|
|
2555
|
+
throw new CannotCreateAssociationOnUnpersistedDream_js_1.default(this, associationName);
|
|
2550
2556
|
return (0, createAssociation_js_1.default)(this, null, associationName, attributes);
|
|
2551
2557
|
}
|
|
2552
2558
|
/**
|
|
@@ -2567,6 +2573,8 @@ class Dream {
|
|
|
2567
2573
|
* @returns The number of records deleted
|
|
2568
2574
|
*/
|
|
2569
2575
|
async destroyAssociation(associationName, options) {
|
|
2576
|
+
if (this.isNewRecord)
|
|
2577
|
+
throw new CannotDestroyAssociationOnUnpersistedDream_js_1.default(this, associationName);
|
|
2570
2578
|
return await (0, destroyAssociation_js_1.default)(this, null, associationName, {
|
|
2571
2579
|
...(0, destroyOptions_js_1.destroyOptions)(options),
|
|
2572
2580
|
joinOnStatements: {
|
|
@@ -2599,6 +2607,8 @@ class Dream {
|
|
|
2599
2607
|
* @returns The number of records deleted
|
|
2600
2608
|
*/
|
|
2601
2609
|
async reallyDestroyAssociation(associationName, options) {
|
|
2610
|
+
if (this.isNewRecord)
|
|
2611
|
+
throw new CannotDestroyAssociationOnUnpersistedDream_js_1.default(this, associationName);
|
|
2602
2612
|
return await (0, destroyAssociation_js_1.default)(this, null, associationName, {
|
|
2603
2613
|
...(0, destroyOptions_js_1.reallyDestroyOptions)(options),
|
|
2604
2614
|
joinOnStatements: {
|
|
@@ -2650,6 +2660,8 @@ class Dream {
|
|
|
2650
2660
|
*
|
|
2651
2661
|
*/
|
|
2652
2662
|
associationQuery(associationName, joinOnStatements) {
|
|
2663
|
+
if (this.isNewRecord)
|
|
2664
|
+
throw new CannotAssociationQueryOnUnpersistedDream_js_1.default(this, associationName);
|
|
2653
2665
|
return (0, associationQuery_js_1.default)(this, null, associationName, {
|
|
2654
2666
|
joinOnStatements: joinOnStatements,
|
|
2655
2667
|
bypassAllDefaultScopes: scopeHelpers_js_1.DEFAULT_BYPASS_ALL_DEFAULT_SCOPES,
|
|
@@ -2679,6 +2691,8 @@ class Dream {
|
|
|
2679
2691
|
* @returns The number of updated records
|
|
2680
2692
|
*/
|
|
2681
2693
|
async updateAssociation(associationName, attributes, updateAssociationOptions) {
|
|
2694
|
+
if (this.isNewRecord)
|
|
2695
|
+
throw new CannotUpdateAssociationOnUnpersistedDream_js_1.default(this, associationName);
|
|
2682
2696
|
return (0, associationUpdateQuery_js_1.default)(this, null, associationName, {
|
|
2683
2697
|
joinOnStatements: {
|
|
2684
2698
|
on: updateAssociationOptions?.on,
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const CannotAssociationQueryOnUnpersistedDream_js_1 = require("../errors/associations/CannotAssociationQueryOnUnpersistedDream.js");
|
|
4
|
+
const CannotCreateAssociationOnUnpersistedDream_js_1 = require("../errors/associations/CannotCreateAssociationOnUnpersistedDream.js");
|
|
5
|
+
const CannotDestroyAssociationOnUnpersistedDream_js_1 = require("../errors/associations/CannotDestroyAssociationOnUnpersistedDream.js");
|
|
6
|
+
const CannotUpdateAssociationOnUnpersistedDream_js_1 = require("../errors/associations/CannotUpdateAssociationOnUnpersistedDream.js");
|
|
3
7
|
const associationQuery_js_1 = require("./internal/associations/associationQuery.js");
|
|
4
8
|
const associationUpdateQuery_js_1 = require("./internal/associations/associationUpdateQuery.js");
|
|
5
9
|
const createAssociation_js_1 = require("./internal/associations/createAssociation.js");
|
|
@@ -310,6 +314,8 @@ class DreamInstanceTransactionBuilder {
|
|
|
310
314
|
* @returns A Query scoped to the specified association on the current instance
|
|
311
315
|
*/
|
|
312
316
|
associationQuery(associationName, joinOnStatements) {
|
|
317
|
+
if (this.dreamInstance.isNewRecord)
|
|
318
|
+
throw new CannotAssociationQueryOnUnpersistedDream_js_1.default(this.dreamInstance, associationName);
|
|
313
319
|
return (0, associationQuery_js_1.default)(this.dreamInstance, this.dreamTransaction, associationName, {
|
|
314
320
|
joinOnStatements: joinOnStatements,
|
|
315
321
|
bypassAllDefaultScopes: scopeHelpers_js_1.DEFAULT_BYPASS_ALL_DEFAULT_SCOPES,
|
|
@@ -341,6 +347,8 @@ class DreamInstanceTransactionBuilder {
|
|
|
341
347
|
* @returns The number of updated records
|
|
342
348
|
*/
|
|
343
349
|
async updateAssociation(associationName, attributes, updateAssociationOptions) {
|
|
350
|
+
if (this.dreamInstance.isNewRecord)
|
|
351
|
+
throw new CannotUpdateAssociationOnUnpersistedDream_js_1.default(this.dreamInstance, associationName);
|
|
344
352
|
return await (0, associationUpdateQuery_js_1.default)(this.dreamInstance, this.dreamTransaction, associationName, {
|
|
345
353
|
joinOnStatements: {
|
|
346
354
|
on: updateAssociationOptions?.on,
|
|
@@ -367,6 +375,8 @@ class DreamInstanceTransactionBuilder {
|
|
|
367
375
|
* @returns The created association
|
|
368
376
|
*/
|
|
369
377
|
async createAssociation(associationName, opts = {}) {
|
|
378
|
+
if (this.dreamInstance.isNewRecord)
|
|
379
|
+
throw new CannotCreateAssociationOnUnpersistedDream_js_1.default(this.dreamInstance, associationName);
|
|
370
380
|
return await (0, createAssociation_js_1.default)(this.dreamInstance, this.dreamTransaction, associationName, opts);
|
|
371
381
|
}
|
|
372
382
|
/**
|
|
@@ -389,6 +399,8 @@ class DreamInstanceTransactionBuilder {
|
|
|
389
399
|
* @returns The number of records deleted
|
|
390
400
|
*/
|
|
391
401
|
async destroyAssociation(associationName, options) {
|
|
402
|
+
if (this.dreamInstance.isNewRecord)
|
|
403
|
+
throw new CannotDestroyAssociationOnUnpersistedDream_js_1.default(this.dreamInstance, associationName);
|
|
392
404
|
return await (0, destroyAssociation_js_1.default)(this.dreamInstance, this.dreamTransaction, associationName, {
|
|
393
405
|
...(0, destroyOptions_js_1.destroyOptions)(options),
|
|
394
406
|
joinOnStatements: {
|
|
@@ -423,6 +435,8 @@ class DreamInstanceTransactionBuilder {
|
|
|
423
435
|
* @returns The number of records deleted
|
|
424
436
|
*/
|
|
425
437
|
async reallyDestroyAssociation(associationName, options) {
|
|
438
|
+
if (this.dreamInstance.isNewRecord)
|
|
439
|
+
throw new CannotDestroyAssociationOnUnpersistedDream_js_1.default(this.dreamInstance, associationName);
|
|
426
440
|
return await (0, destroyAssociation_js_1.default)(this.dreamInstance, this.dreamTransaction, associationName, {
|
|
427
441
|
...(0, destroyOptions_js_1.reallyDestroyOptions)(options),
|
|
428
442
|
joinOnStatements: {
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.default = destroyDream;
|
|
4
4
|
const destroyAssociatedRecords_js_1 = require("./destroyAssociatedRecords.js");
|
|
5
5
|
const runHooksFor_js_1 = require("./runHooksFor.js");
|
|
6
|
-
const safelyRunCommitHooks_js_1 = require("./safelyRunCommitHooks.js");
|
|
7
6
|
const softDeleteDream_js_1 = require("./softDeleteDream.js");
|
|
8
7
|
/**
|
|
9
8
|
* @internal
|
|
@@ -42,7 +41,7 @@ async function destroyDreamWithTransaction(dream, txn, options) {
|
|
|
42
41
|
await maybeDestroyDream(dream, txn, reallyDestroy);
|
|
43
42
|
if (!skipHooks) {
|
|
44
43
|
await (0, runHooksFor_js_1.default)('afterDestroy', dream, true, null, txn || undefined);
|
|
45
|
-
await (0,
|
|
44
|
+
await (0, runHooksFor_js_1.default)('afterDestroyCommit', dream, true, null, txn);
|
|
46
45
|
}
|
|
47
46
|
if (shouldSoftDelete(dream, reallyDestroy)) {
|
|
48
47
|
await dream.txn(txn).reload();
|
|
@@ -4,48 +4,90 @@ exports.default = runHooksFor;
|
|
|
4
4
|
exports.runHook = runHook;
|
|
5
5
|
async function runHooksFor(key, dream, alreadyPersisted, beforeSaveChanges, txn) {
|
|
6
6
|
const Base = dream.constructor;
|
|
7
|
-
for (const
|
|
8
|
-
if (
|
|
7
|
+
for (const hook of Base['hooks'][key]) {
|
|
8
|
+
if (hook.ifChanging?.length) {
|
|
9
9
|
switch (key) {
|
|
10
10
|
case 'beforeCreate':
|
|
11
|
-
|
|
11
|
+
if (shouldRunBeforeCreateHook(dream, hook)) {
|
|
12
|
+
await runHook(hook, dream, txn);
|
|
13
|
+
}
|
|
12
14
|
break;
|
|
13
15
|
case 'beforeSave':
|
|
14
|
-
if (alreadyPersisted)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
if ((alreadyPersisted && shouldRunBeforeUpdateHook(dream, hook)) ||
|
|
17
|
+
(!alreadyPersisted && shouldRunBeforeCreateHook(dream, hook))) {
|
|
18
|
+
await runHook(hook, dream, txn);
|
|
19
|
+
}
|
|
18
20
|
break;
|
|
19
21
|
case 'beforeUpdate':
|
|
20
|
-
|
|
22
|
+
if (shouldRunBeforeUpdateHook(dream, hook)) {
|
|
23
|
+
await runHook(hook, dream, txn);
|
|
24
|
+
}
|
|
21
25
|
break;
|
|
22
26
|
default:
|
|
23
27
|
throw new Error(`Unexpected statement key detected with ifChanging clause: ${key}`);
|
|
24
28
|
}
|
|
25
29
|
}
|
|
26
|
-
else if (
|
|
30
|
+
else if (hook.ifChanged?.length) {
|
|
27
31
|
switch (key) {
|
|
28
32
|
case 'afterCreate':
|
|
33
|
+
if (shouldRunAfterCreateHook(dream, hook, beforeSaveChanges)) {
|
|
34
|
+
await runHook(hook, dream, txn);
|
|
35
|
+
}
|
|
36
|
+
break;
|
|
29
37
|
case 'afterCreateCommit':
|
|
30
|
-
|
|
38
|
+
if (shouldRunAfterCreateHook(dream, hook, beforeSaveChanges)) {
|
|
39
|
+
if (txn)
|
|
40
|
+
txn.addCommitHook(hook, dream);
|
|
41
|
+
else
|
|
42
|
+
await runHook(hook, dream);
|
|
43
|
+
}
|
|
31
44
|
break;
|
|
32
45
|
case 'afterSave':
|
|
46
|
+
if ((alreadyPersisted && shouldRunAfterUpdateHook(dream, hook)) ||
|
|
47
|
+
(!alreadyPersisted && shouldRunAfterCreateHook(dream, hook, beforeSaveChanges))) {
|
|
48
|
+
await runHook(hook, dream, txn);
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
33
51
|
case 'afterSaveCommit':
|
|
34
|
-
if (alreadyPersisted)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
52
|
+
if ((alreadyPersisted && shouldRunAfterUpdateHook(dream, hook)) ||
|
|
53
|
+
(!alreadyPersisted && shouldRunAfterCreateHook(dream, hook, beforeSaveChanges))) {
|
|
54
|
+
if (txn)
|
|
55
|
+
txn.addCommitHook(hook, dream);
|
|
56
|
+
else
|
|
57
|
+
await runHook(hook, dream);
|
|
58
|
+
}
|
|
38
59
|
break;
|
|
39
60
|
case 'afterUpdate':
|
|
61
|
+
if (shouldRunAfterUpdateHook(dream, hook)) {
|
|
62
|
+
await runHook(hook, dream, txn);
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
40
65
|
case 'afterUpdateCommit':
|
|
41
|
-
|
|
66
|
+
if (shouldRunAfterUpdateHook(dream, hook)) {
|
|
67
|
+
if (txn)
|
|
68
|
+
txn.addCommitHook(hook, dream);
|
|
69
|
+
else
|
|
70
|
+
await runHook(hook, dream);
|
|
71
|
+
}
|
|
42
72
|
break;
|
|
43
73
|
default:
|
|
44
74
|
throw new Error(`Unexpected statement key detected with ifChanged clause: ${key}`);
|
|
45
75
|
}
|
|
46
76
|
}
|
|
47
77
|
else {
|
|
48
|
-
|
|
78
|
+
switch (key) {
|
|
79
|
+
case 'afterCreateCommit':
|
|
80
|
+
case 'afterSaveCommit':
|
|
81
|
+
case 'afterUpdateCommit':
|
|
82
|
+
case 'afterDestroyCommit':
|
|
83
|
+
if (txn)
|
|
84
|
+
txn.addCommitHook(hook, dream);
|
|
85
|
+
else
|
|
86
|
+
await runHook(hook, dream);
|
|
87
|
+
break;
|
|
88
|
+
default:
|
|
89
|
+
await runHook(hook, dream, txn);
|
|
90
|
+
}
|
|
49
91
|
}
|
|
50
92
|
}
|
|
51
93
|
}
|
|
@@ -60,40 +102,36 @@ Please make sure "${statement.method}" is defined on ${dream['sanitizedConstruct
|
|
|
60
102
|
}
|
|
61
103
|
await dream[statement.method](txn);
|
|
62
104
|
}
|
|
63
|
-
|
|
105
|
+
function shouldRunBeforeCreateHook(dream, statement) {
|
|
64
106
|
let shouldRun = false;
|
|
65
107
|
for (const attribute of statement.ifChanging) {
|
|
66
108
|
if (dream[attribute] !== undefined)
|
|
67
109
|
shouldRun = true;
|
|
68
110
|
}
|
|
69
|
-
|
|
70
|
-
await runHook(statement, dream, txn);
|
|
111
|
+
return shouldRun;
|
|
71
112
|
}
|
|
72
|
-
|
|
113
|
+
function shouldRunAfterCreateHook(dream, statement, beforeSaveChanges) {
|
|
73
114
|
let shouldRun = false;
|
|
74
115
|
for (const attribute of statement.ifChanged) {
|
|
75
116
|
if (beforeSaveChanges?.[attribute] &&
|
|
76
117
|
beforeSaveChanges[attribute].was !== beforeSaveChanges[attribute].now)
|
|
77
118
|
shouldRun = true;
|
|
78
119
|
}
|
|
79
|
-
|
|
80
|
-
await runHook(statement, dream, txn);
|
|
120
|
+
return shouldRun;
|
|
81
121
|
}
|
|
82
|
-
|
|
122
|
+
function shouldRunBeforeUpdateHook(dream, statement) {
|
|
83
123
|
let shouldRun = false;
|
|
84
124
|
for (const attribute of statement.ifChanging) {
|
|
85
125
|
if (dream.willSaveChangeToAttribute(attribute))
|
|
86
126
|
shouldRun = true;
|
|
87
127
|
}
|
|
88
|
-
|
|
89
|
-
await runHook(statement, dream, txn);
|
|
128
|
+
return shouldRun;
|
|
90
129
|
}
|
|
91
|
-
|
|
130
|
+
function shouldRunAfterUpdateHook(dream, statement) {
|
|
92
131
|
let shouldRun = false;
|
|
93
132
|
for (const attribute of statement.ifChanged) {
|
|
94
133
|
if (dream.savedChangeToAttribute(attribute))
|
|
95
134
|
shouldRun = true;
|
|
96
135
|
}
|
|
97
|
-
|
|
98
|
-
await runHook(statement, dream, txn);
|
|
136
|
+
return shouldRun;
|
|
99
137
|
}
|
|
@@ -8,7 +8,6 @@ const namespaceColumn_js_1 = require("../../helpers/namespaceColumn.js");
|
|
|
8
8
|
const sqlAttributes_js_1 = require("../../helpers/sqlAttributes.js");
|
|
9
9
|
const executeDatabaseQuery_js_1 = require("./executeDatabaseQuery.js");
|
|
10
10
|
const runHooksFor_js_1 = require("./runHooksFor.js");
|
|
11
|
-
const safelyRunCommitHooks_js_1 = require("./safelyRunCommitHooks.js");
|
|
12
11
|
async function saveDream(dream, txn = null, { skipHooks = false } = {}) {
|
|
13
12
|
const db = txn?.kyselyTransaction || (0, index_js_1.default)('primary');
|
|
14
13
|
const alreadyPersisted = dream.isPersisted;
|
|
@@ -59,9 +58,8 @@ async function saveDream(dream, txn = null, { skipHooks = false } = {}) {
|
|
|
59
58
|
await (0, runHooksFor_js_1.default)('afterUpdate', dream, alreadyPersisted, beforeSaveChanges, txn);
|
|
60
59
|
else
|
|
61
60
|
await (0, runHooksFor_js_1.default)('afterCreate', dream, alreadyPersisted, beforeSaveChanges, txn);
|
|
62
|
-
|
|
63
|
-
await (0,
|
|
64
|
-
await (0, safelyRunCommitHooks_js_1.default)(dream, 'afterSaveCommit', alreadyPersisted, beforeSaveChanges, txn);
|
|
61
|
+
await (0, runHooksFor_js_1.default)(alreadyPersisted ? 'afterUpdateCommit' : 'afterCreateCommit', dream, alreadyPersisted, beforeSaveChanges, txn);
|
|
62
|
+
await (0, runHooksFor_js_1.default)('afterSaveCommit', dream, alreadyPersisted, beforeSaveChanges, txn);
|
|
65
63
|
}
|
|
66
64
|
return dream;
|
|
67
65
|
}
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.default = undestroyDream;
|
|
4
4
|
const setPosition_js_1 = require("../../decorators/field/sortable/helpers/setPosition.js");
|
|
5
5
|
const runHooksFor_js_1 = require("./runHooksFor.js");
|
|
6
|
-
const safelyRunCommitHooks_js_1 = require("./safelyRunCommitHooks.js");
|
|
7
6
|
/**
|
|
8
7
|
* @internal
|
|
9
8
|
*
|
|
@@ -41,7 +40,7 @@ async function undestroyDreamWithTransaction(dream, txn, options) {
|
|
|
41
40
|
}
|
|
42
41
|
if (!skipHooks) {
|
|
43
42
|
await (0, runHooksFor_js_1.default)('afterUpdate', dream, true, null, txn);
|
|
44
|
-
await (0,
|
|
43
|
+
await (0, runHooksFor_js_1.default)('afterUpdateCommit', dream, true, null, txn);
|
|
45
44
|
}
|
|
46
45
|
await dream.txn(txn).reload();
|
|
47
46
|
return dream;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class CannotAssociationQueryOnUnpersistedDream extends Error {
|
|
4
|
+
dream;
|
|
5
|
+
associationName;
|
|
6
|
+
constructor(dream, associationName) {
|
|
7
|
+
super();
|
|
8
|
+
this.dream = dream;
|
|
9
|
+
this.associationName = associationName;
|
|
10
|
+
}
|
|
11
|
+
get message() {
|
|
12
|
+
return `Cannot perform associationQuery on an unpersisted Dream.
|
|
13
|
+
Dream class: ${this.dream.sanitizedConstructorName}
|
|
14
|
+
Association: ${this.associationName.toString()}
|
|
15
|
+
`;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.default = CannotAssociationQueryOnUnpersistedDream;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class CannotCreateAssociationOnUnpersistedDream extends Error {
|
|
4
|
+
dream;
|
|
5
|
+
associationName;
|
|
6
|
+
constructor(dream, associationName) {
|
|
7
|
+
super();
|
|
8
|
+
this.dream = dream;
|
|
9
|
+
this.associationName = associationName;
|
|
10
|
+
}
|
|
11
|
+
get message() {
|
|
12
|
+
return `Cannot perform createAssociation on an unpersisted Dream.
|
|
13
|
+
Dream class: ${this.dream.sanitizedConstructorName}
|
|
14
|
+
Association: ${this.associationName.toString()}
|
|
15
|
+
`;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.default = CannotCreateAssociationOnUnpersistedDream;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class CannotDestroyAssociationOnUnpersistedDream extends Error {
|
|
4
|
+
dream;
|
|
5
|
+
associationName;
|
|
6
|
+
constructor(dream, associationName) {
|
|
7
|
+
super();
|
|
8
|
+
this.dream = dream;
|
|
9
|
+
this.associationName = associationName;
|
|
10
|
+
}
|
|
11
|
+
get message() {
|
|
12
|
+
return `Cannot perform destroyAssociation on an unpersisted Dream.
|
|
13
|
+
Dream class: ${this.dream.sanitizedConstructorName}
|
|
14
|
+
Association: ${this.associationName.toString()}
|
|
15
|
+
`;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.default = CannotDestroyAssociationOnUnpersistedDream;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class CannotUpdateAssociationOnUnpersistedDream extends Error {
|
|
4
|
+
dream;
|
|
5
|
+
associationName;
|
|
6
|
+
constructor(dream, associationName) {
|
|
7
|
+
super();
|
|
8
|
+
this.dream = dream;
|
|
9
|
+
this.associationName = associationName;
|
|
10
|
+
}
|
|
11
|
+
get message() {
|
|
12
|
+
return `Cannot perform updateAssociation on an unpersisted Dream.
|
|
13
|
+
Dream class: ${this.dream.sanitizedConstructorName}
|
|
14
|
+
Association: ${this.associationName.toString()}
|
|
15
|
+
`;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.default = CannotUpdateAssociationOnUnpersistedDream;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const logos_js_1 = require("./logos.js");
|
|
4
|
+
class DreamLogos {
|
|
5
|
+
static colorful() {
|
|
6
|
+
return (0, logos_js_1.default)();
|
|
7
|
+
}
|
|
8
|
+
static monochrome() {
|
|
9
|
+
return (0, logos_js_1.monochromeLogo)();
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.default = DreamLogos;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = whaaaaaaaaaaok;
|
|
4
|
-
exports.
|
|
4
|
+
exports.monochromeLogo = monochromeLogo;
|
|
5
5
|
const yoctocolors_1 = require("yoctocolors");
|
|
6
6
|
function whaaaaaaaaaaok() {
|
|
7
7
|
return (yoctocolors_1.default.bgMagentaBright(yoctocolors_1.default.black(`
|
|
@@ -45,7 +45,7 @@ function whaaaaaaaaaaok() {
|
|
|
45
45
|
|
|
46
46
|
`)));
|
|
47
47
|
}
|
|
48
|
-
function
|
|
48
|
+
function monochromeLogo() {
|
|
49
49
|
return `
|
|
50
50
|
,▄█▄
|
|
51
51
|
]█▄▄ ╓█████▌
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = autogeneratedFileDisclaimer;
|
|
4
|
-
const
|
|
4
|
+
const DreamLogos_js_1 = require("../DreamLogos/DreamLogos.js");
|
|
5
5
|
function autogeneratedFileDisclaimer(startComment = '\n/*', endComment = '\n*/') {
|
|
6
6
|
return `\
|
|
7
7
|
${startComment}
|
|
8
|
-
${
|
|
8
|
+
${DreamLogos_js_1.default.monochrome()}
|
|
9
9
|
|
|
10
10
|
This file was automatically generated by my cat, Aster.
|
|
11
11
|
He does not want you mucking about with his files,
|
|
@@ -78,7 +78,7 @@ public ${(0, camelize_js_1.default)(attributeName)}: ${getAttributeType(attribut
|
|
|
78
78
|
return `\
|
|
79
79
|
import { ${(0, uniq_js_1.default)(dreamImports).join(', ')} } from '@rvoh/dream'${(0, uniq_js_1.default)(modelImportStatements).join('')}
|
|
80
80
|
|
|
81
|
-
const deco = new Decorators<
|
|
81
|
+
const deco = new Decorators<typeof ${modelClassName}>()
|
|
82
82
|
|
|
83
83
|
${isSTI ? `\n@STI(${parentModelClassName})` : ''}
|
|
84
84
|
export default class ${modelClassName} extends ${isSTI ? parentModelClassName : 'ApplicationModel'} {
|
|
@@ -89,7 +89,7 @@ ${isSTI
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
`}${serializer
|
|
92
|
-
? ` public get serializers(): DreamSerializers<${modelClassName}> {
|
|
92
|
+
? ` public ${isSTI ? 'override ' : ''}get serializers(): DreamSerializers<${modelClassName}> {
|
|
93
93
|
return {
|
|
94
94
|
default: '${(0, serializerNameFromFullyQualifiedModelName_js_1.default)(fullyQualifiedModelName)}',
|
|
95
95
|
summary: '${(0, serializerNameFromFullyQualifiedModelName_js_1.default)(fullyQualifiedModelName, 'summary')}',
|
|
@@ -32,13 +32,13 @@ function generateSerializerContent({ fullyQualifiedModelName, columnsWithTypes =
|
|
|
32
32
|
Passthrough extends object,
|
|
33
33
|
>`;
|
|
34
34
|
dreamSerializerTypeArgs = `<DataType, Passthrough>`;
|
|
35
|
-
const defaultSerialzerClassName = (0,
|
|
36
|
-
const summarySerialzerClassName = (0,
|
|
35
|
+
const defaultSerialzerClassName = (0, serializerNameFromFullyQualifiedModelName_js_1.default)(fullyQualifiedModelNameToSerializerBaseName(fullyQualifiedModelName));
|
|
36
|
+
const summarySerialzerClassName = (0, serializerNameFromFullyQualifiedModelName_js_1.default)(fullyQualifiedModelNameToSerializerBaseName(fullyQualifiedModelName), 'summary');
|
|
37
37
|
const defaultSerialzerExtends = isSTI
|
|
38
|
-
? (0,
|
|
38
|
+
? (0, serializerNameFromFullyQualifiedModelName_js_1.default)(fullyQualifiedModelNameToSerializerBaseName(fullyQualifiedParentName))
|
|
39
39
|
: summarySerialzerClassName;
|
|
40
40
|
const summarySerialzerExtends = isSTI
|
|
41
|
-
? (0,
|
|
41
|
+
? (0, serializerNameFromFullyQualifiedModelName_js_1.default)(fullyQualifiedModelNameToSerializerBaseName(fullyQualifiedParentName), 'summary')
|
|
42
42
|
: 'DreamSerializer';
|
|
43
43
|
const additionalModelImports = [];
|
|
44
44
|
columnsWithTypes.forEach(attr => {
|
|
@@ -101,8 +101,16 @@ function attributeOptionsSpecifier(type, attr) {
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
function importStatementForSerializer(originModelName, destinationModelName) {
|
|
104
|
-
|
|
104
|
+
const defaultSerializer = (0, globalClassNameFromFullyQualifiedModelName_js_1.default)((0, serializerNameFromFullyQualifiedModelName_js_1.default)(fullyQualifiedModelNameToSerializerBaseName(destinationModelName)));
|
|
105
|
+
const summarySerializer = (0, globalClassNameFromFullyQualifiedModelName_js_1.default)((0, serializerNameFromFullyQualifiedModelName_js_1.default)(fullyQualifiedModelNameToSerializerBaseName(destinationModelName), 'summary'));
|
|
106
|
+
const importFrom = (0, relativeDreamPath_js_1.default)('serializers', 'serializers', originModelName, destinationModelName);
|
|
107
|
+
return `\nimport ${defaultSerializer}, { ${summarySerializer} } from '${importFrom}'`;
|
|
105
108
|
}
|
|
106
109
|
function importStatementForModel(originModelName, destinationModelName = originModelName) {
|
|
107
|
-
|
|
110
|
+
const modelName = (0, globalClassNameFromFullyQualifiedModelName_js_1.default)(destinationModelName);
|
|
111
|
+
const importFrom = (0, relativeDreamPath_js_1.default)('serializers', 'models', originModelName, destinationModelName);
|
|
112
|
+
return `\nimport ${modelName} from '${importFrom}'`;
|
|
113
|
+
}
|
|
114
|
+
function fullyQualifiedModelNameToSerializerBaseName(fullyQualifiedModelName) {
|
|
115
|
+
return fullyQualifiedModelName.split('/').pop() ?? '';
|
|
108
116
|
}
|
package/dist/cjs/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.range = exports.Range = exports.sharedPathPrefix = exports.relativeDreamPath = exports.dreamPath = exports.pascalize = exports.loadRepl = exports.isEmpty = exports.inferSerializerFromDreamOrViewModel = exports.inferSerializerFromDreamClassOrViewModelClass = exports.hyphenize = exports.globalClassNameFromFullyQualifiedModelName = exports.Env = exports.
|
|
3
|
+
exports.range = exports.Range = exports.sharedPathPrefix = exports.relativeDreamPath = exports.dreamPath = exports.pascalize = exports.loadRepl = exports.isEmpty = exports.inferSerializerFromDreamOrViewModel = exports.inferSerializerFromDreamClassOrViewModelClass = exports.hyphenize = exports.globalClassNameFromFullyQualifiedModelName = exports.Env = exports.DreamLogos = exports.debug = exports.DateTime = exports.compact = exports.generateDream = exports.capitalize = exports.camelize = exports.CalendarDate = exports.Benchmark = exports.ValidationError = exports.RecordNotFound = exports.GlobalNameNotSet = exports.CreateOrFindByFailedToCreateAndFind = exports.NonLoadedAssociation = exports.Encrypt = exports.Query = exports.DreamTransaction = exports.openapiShorthandPrimitiveTypes = exports.openapiPrimitiveTypes = exports.DreamConst = exports.Dream = exports.DreamApplication = 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.DreamBin = void 0;
|
|
4
4
|
exports.DreamSerializer = exports.Attribute = exports.RendersOne = exports.RendersMany = exports.ops = exports.uniq = exports.uncapitalize = exports.standardizeFullyQualifiedModelName = exports.sortBy = exports.sort = exports.snakeify = exports.serializerNameFromFullyQualifiedModelName = exports.round = 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; } });
|
|
@@ -71,8 +71,8 @@ var DateTime_js_1 = require("./helpers/DateTime.js");
|
|
|
71
71
|
Object.defineProperty(exports, "DateTime", { enumerable: true, get: function () { return DateTime_js_1.DateTime; } });
|
|
72
72
|
var debug_js_1 = require("./helpers/debug.js");
|
|
73
73
|
Object.defineProperty(exports, "debug", { enumerable: true, get: function () { return debug_js_1.default; } });
|
|
74
|
-
var
|
|
75
|
-
Object.defineProperty(exports, "
|
|
74
|
+
var DreamLogos_js_1 = require("./helpers/DreamLogos/DreamLogos.js");
|
|
75
|
+
Object.defineProperty(exports, "DreamLogos", { enumerable: true, get: function () { return DreamLogos_js_1.default; } });
|
|
76
76
|
var Env_js_1 = require("./helpers/Env.js");
|
|
77
77
|
Object.defineProperty(exports, "Env", { enumerable: true, get: function () { return Env_js_1.default; } });
|
|
78
78
|
var globalClassNameFromFullyQualifiedModelName_js_1 = require("./helpers/globalClassNameFromFullyQualifiedModelName.js");
|
package/dist/esm/src/Dream.js
CHANGED
|
@@ -24,7 +24,11 @@ import undestroyDream from './dream/internal/undestroyDream.js';
|
|
|
24
24
|
import LeftJoinLoadBuilder from './dream/LeftJoinLoadBuilder.js';
|
|
25
25
|
import LoadBuilder from './dream/LoadBuilder.js';
|
|
26
26
|
import Query from './dream/Query.js';
|
|
27
|
+
import CannotAssociationQueryOnUnpersistedDream from './errors/associations/CannotAssociationQueryOnUnpersistedDream.js';
|
|
28
|
+
import CannotCreateAssociationOnUnpersistedDream from './errors/associations/CannotCreateAssociationOnUnpersistedDream.js';
|
|
29
|
+
import CannotDestroyAssociationOnUnpersistedDream from './errors/associations/CannotDestroyAssociationOnUnpersistedDream.js';
|
|
27
30
|
import CannotPassNullOrUndefinedToRequiredBelongsTo from './errors/associations/CannotPassNullOrUndefinedToRequiredBelongsTo.js';
|
|
31
|
+
import CannotUpdateAssociationOnUnpersistedDream from './errors/associations/CannotUpdateAssociationOnUnpersistedDream.js';
|
|
28
32
|
import CanOnlyPassBelongsToModelParam from './errors/associations/CanOnlyPassBelongsToModelParam.js';
|
|
29
33
|
import NonLoadedAssociation from './errors/associations/NonLoadedAssociation.js';
|
|
30
34
|
import CannotCallUndestroyOnANonSoftDeleteModel from './errors/CannotCallUndestroyOnANonSoftDeleteModel.js';
|
|
@@ -2545,6 +2549,8 @@ export default class Dream {
|
|
|
2545
2549
|
* @returns The created association
|
|
2546
2550
|
*/
|
|
2547
2551
|
async createAssociation(associationName, attributes = {}) {
|
|
2552
|
+
if (this.isNewRecord)
|
|
2553
|
+
throw new CannotCreateAssociationOnUnpersistedDream(this, associationName);
|
|
2548
2554
|
return createAssociation(this, null, associationName, attributes);
|
|
2549
2555
|
}
|
|
2550
2556
|
/**
|
|
@@ -2565,6 +2571,8 @@ export default class Dream {
|
|
|
2565
2571
|
* @returns The number of records deleted
|
|
2566
2572
|
*/
|
|
2567
2573
|
async destroyAssociation(associationName, options) {
|
|
2574
|
+
if (this.isNewRecord)
|
|
2575
|
+
throw new CannotDestroyAssociationOnUnpersistedDream(this, associationName);
|
|
2568
2576
|
return await destroyAssociation(this, null, associationName, {
|
|
2569
2577
|
...destroyOptions(options),
|
|
2570
2578
|
joinOnStatements: {
|
|
@@ -2597,6 +2605,8 @@ export default class Dream {
|
|
|
2597
2605
|
* @returns The number of records deleted
|
|
2598
2606
|
*/
|
|
2599
2607
|
async reallyDestroyAssociation(associationName, options) {
|
|
2608
|
+
if (this.isNewRecord)
|
|
2609
|
+
throw new CannotDestroyAssociationOnUnpersistedDream(this, associationName);
|
|
2600
2610
|
return await destroyAssociation(this, null, associationName, {
|
|
2601
2611
|
...reallyDestroyOptions(options),
|
|
2602
2612
|
joinOnStatements: {
|
|
@@ -2648,6 +2658,8 @@ export default class Dream {
|
|
|
2648
2658
|
*
|
|
2649
2659
|
*/
|
|
2650
2660
|
associationQuery(associationName, joinOnStatements) {
|
|
2661
|
+
if (this.isNewRecord)
|
|
2662
|
+
throw new CannotAssociationQueryOnUnpersistedDream(this, associationName);
|
|
2651
2663
|
return associationQuery(this, null, associationName, {
|
|
2652
2664
|
joinOnStatements: joinOnStatements,
|
|
2653
2665
|
bypassAllDefaultScopes: DEFAULT_BYPASS_ALL_DEFAULT_SCOPES,
|
|
@@ -2677,6 +2689,8 @@ export default class Dream {
|
|
|
2677
2689
|
* @returns The number of updated records
|
|
2678
2690
|
*/
|
|
2679
2691
|
async updateAssociation(associationName, attributes, updateAssociationOptions) {
|
|
2692
|
+
if (this.isNewRecord)
|
|
2693
|
+
throw new CannotUpdateAssociationOnUnpersistedDream(this, associationName);
|
|
2680
2694
|
return associationUpdateQuery(this, null, associationName, {
|
|
2681
2695
|
joinOnStatements: {
|
|
2682
2696
|
on: updateAssociationOptions?.on,
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import CannotAssociationQueryOnUnpersistedDream from '../errors/associations/CannotAssociationQueryOnUnpersistedDream.js';
|
|
2
|
+
import CannotCreateAssociationOnUnpersistedDream from '../errors/associations/CannotCreateAssociationOnUnpersistedDream.js';
|
|
3
|
+
import CannotDestroyAssociationOnUnpersistedDream from '../errors/associations/CannotDestroyAssociationOnUnpersistedDream.js';
|
|
4
|
+
import CannotUpdateAssociationOnUnpersistedDream from '../errors/associations/CannotUpdateAssociationOnUnpersistedDream.js';
|
|
1
5
|
import associationQuery from './internal/associations/associationQuery.js';
|
|
2
6
|
import associationUpdateQuery from './internal/associations/associationUpdateQuery.js';
|
|
3
7
|
import createAssociation from './internal/associations/createAssociation.js';
|
|
@@ -308,6 +312,8 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
308
312
|
* @returns A Query scoped to the specified association on the current instance
|
|
309
313
|
*/
|
|
310
314
|
associationQuery(associationName, joinOnStatements) {
|
|
315
|
+
if (this.dreamInstance.isNewRecord)
|
|
316
|
+
throw new CannotAssociationQueryOnUnpersistedDream(this.dreamInstance, associationName);
|
|
311
317
|
return associationQuery(this.dreamInstance, this.dreamTransaction, associationName, {
|
|
312
318
|
joinOnStatements: joinOnStatements,
|
|
313
319
|
bypassAllDefaultScopes: DEFAULT_BYPASS_ALL_DEFAULT_SCOPES,
|
|
@@ -339,6 +345,8 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
339
345
|
* @returns The number of updated records
|
|
340
346
|
*/
|
|
341
347
|
async updateAssociation(associationName, attributes, updateAssociationOptions) {
|
|
348
|
+
if (this.dreamInstance.isNewRecord)
|
|
349
|
+
throw new CannotUpdateAssociationOnUnpersistedDream(this.dreamInstance, associationName);
|
|
342
350
|
return await associationUpdateQuery(this.dreamInstance, this.dreamTransaction, associationName, {
|
|
343
351
|
joinOnStatements: {
|
|
344
352
|
on: updateAssociationOptions?.on,
|
|
@@ -365,6 +373,8 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
365
373
|
* @returns The created association
|
|
366
374
|
*/
|
|
367
375
|
async createAssociation(associationName, opts = {}) {
|
|
376
|
+
if (this.dreamInstance.isNewRecord)
|
|
377
|
+
throw new CannotCreateAssociationOnUnpersistedDream(this.dreamInstance, associationName);
|
|
368
378
|
return await createAssociation(this.dreamInstance, this.dreamTransaction, associationName, opts);
|
|
369
379
|
}
|
|
370
380
|
/**
|
|
@@ -387,6 +397,8 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
387
397
|
* @returns The number of records deleted
|
|
388
398
|
*/
|
|
389
399
|
async destroyAssociation(associationName, options) {
|
|
400
|
+
if (this.dreamInstance.isNewRecord)
|
|
401
|
+
throw new CannotDestroyAssociationOnUnpersistedDream(this.dreamInstance, associationName);
|
|
390
402
|
return await destroyAssociation(this.dreamInstance, this.dreamTransaction, associationName, {
|
|
391
403
|
...destroyOptions(options),
|
|
392
404
|
joinOnStatements: {
|
|
@@ -421,6 +433,8 @@ export default class DreamInstanceTransactionBuilder {
|
|
|
421
433
|
* @returns The number of records deleted
|
|
422
434
|
*/
|
|
423
435
|
async reallyDestroyAssociation(associationName, options) {
|
|
436
|
+
if (this.dreamInstance.isNewRecord)
|
|
437
|
+
throw new CannotDestroyAssociationOnUnpersistedDream(this.dreamInstance, associationName);
|
|
424
438
|
return await destroyAssociation(this.dreamInstance, this.dreamTransaction, associationName, {
|
|
425
439
|
...reallyDestroyOptions(options),
|
|
426
440
|
joinOnStatements: {
|