@rvoh/dream 0.44.9 → 0.45.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/src/Dream.js +328 -23
- package/dist/cjs/src/cli/index.js +16 -0
- package/dist/cjs/src/db/migration-helpers/DreamMigrationHelpers.js +18 -14
- package/dist/cjs/src/decorators/Decorators.js +2 -1
- package/dist/cjs/src/dream/DreamClassTransactionBuilder.js +92 -0
- package/dist/cjs/src/dream/DreamInstanceTransactionBuilder.js +98 -0
- package/dist/cjs/src/dream/LeftJoinLoadBuilder.js +52 -1
- package/dist/cjs/src/dream/LoadBuilder.js +49 -0
- package/dist/cjs/src/dream/Query.js +136 -24
- package/dist/cjs/src/dream/internal/convertDreamClassAndAssociationNameTupleArrayToPreloadArgs.js +18 -0
- package/dist/cjs/src/dream/internal/extractNestedPaths.js +37 -0
- package/dist/cjs/src/dream/internal/unaliasTableName.js +7 -0
- package/dist/cjs/src/helpers/indent.js +18 -0
- package/dist/cjs/src/serializer/SerializerRenderer.js +2 -17
- package/dist/cjs/src/serializer/builders/DreamSerializerBuilder.js +139 -3
- package/dist/cjs/src/serializer/builders/ObjectSerializerBuilder.js +176 -3
- package/dist/cjs/src/serializer/helpers/serializerForAssociatedClass.js +20 -0
- package/dist/esm/src/Dream.js +328 -23
- package/dist/esm/src/cli/index.js +16 -0
- package/dist/esm/src/db/migration-helpers/DreamMigrationHelpers.js +18 -14
- package/dist/esm/src/decorators/Decorators.js +2 -1
- package/dist/esm/src/dream/DreamClassTransactionBuilder.js +92 -0
- package/dist/esm/src/dream/DreamInstanceTransactionBuilder.js +98 -0
- package/dist/esm/src/dream/LeftJoinLoadBuilder.js +52 -1
- package/dist/esm/src/dream/LoadBuilder.js +49 -0
- package/dist/esm/src/dream/Query.js +136 -24
- package/dist/esm/src/dream/internal/convertDreamClassAndAssociationNameTupleArrayToPreloadArgs.js +15 -0
- package/dist/esm/src/dream/internal/extractNestedPaths.js +34 -0
- package/dist/esm/src/dream/internal/unaliasTableName.js +4 -0
- package/dist/esm/src/helpers/indent.js +15 -0
- package/dist/esm/src/serializer/SerializerRenderer.js +2 -17
- package/dist/esm/src/serializer/builders/DreamSerializerBuilder.js +139 -3
- package/dist/esm/src/serializer/builders/ObjectSerializerBuilder.js +176 -3
- package/dist/esm/src/serializer/helpers/serializerForAssociatedClass.js +17 -0
- package/dist/types/src/Dream.d.ts +283 -25
- package/dist/types/src/db/migration-helpers/DreamMigrationHelpers.d.ts +18 -14
- package/dist/types/src/decorators/Decorators.d.ts +2 -1
- package/dist/types/src/dream/DreamClassTransactionBuilder.d.ts +108 -2
- package/dist/types/src/dream/DreamInstanceTransactionBuilder.d.ts +96 -2
- package/dist/types/src/dream/LeftJoinLoadBuilder.d.ts +48 -1
- package/dist/types/src/dream/LoadBuilder.d.ts +48 -1
- package/dist/types/src/dream/Query.d.ts +128 -26
- package/dist/types/src/dream/internal/convertDreamClassAndAssociationNameTupleArrayToPreloadArgs.d.ts +9 -0
- package/dist/types/src/dream/internal/extractNestedPaths.d.ts +21 -0
- package/dist/types/src/dream/internal/unaliasTableName.d.ts +1 -0
- package/dist/types/src/helpers/indent.d.ts +3 -0
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/serializer/builders/DreamSerializerBuilder.d.ts +176 -5
- package/dist/types/src/serializer/builders/ObjectSerializerBuilder.d.ts +176 -3
- package/dist/types/src/serializer/helpers/serializerForAssociatedClass.d.ts +9 -0
- package/dist/types/src/types/dream.d.ts +2 -1
- package/dist/types/src/types/dream.ts +26 -1
- package/dist/types/src/types/query.d.ts +5 -0
- package/dist/types/src/types/query.ts +5 -0
- package/docs/assets/highlight.css +7 -0
- 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 +21 -20
- package/docs/classes/Dream.html +339 -226
- package/docs/classes/DreamApp.html +4 -4
- package/docs/classes/DreamBin.html +2 -2
- package/docs/classes/DreamCLI.html +4 -4
- package/docs/classes/DreamImporter.html +2 -2
- package/docs/classes/DreamLogos.html +2 -2
- package/docs/classes/DreamMigrationHelpers.html +21 -8
- package/docs/classes/DreamSerializerBuilder.html +66 -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/ObjectSerializerBuilder.html +66 -2
- package/docs/classes/Query.html +122 -78
- package/docs/classes/Range.html +2 -2
- package/docs/classes/RecordNotFound.html +3 -3
- package/docs/classes/ValidationError.html +3 -3
- package/docs/functions/DreamSerializer.html +1 -1
- package/docs/functions/ObjectSerializer.html +1 -1
- package/docs/functions/ReplicaSafe.html +1 -1
- package/docs/functions/STI.html +1 -1
- package/docs/functions/SoftDelete.html +1 -1
- package/docs/functions/camelize.html +1 -1
- package/docs/functions/capitalize.html +1 -1
- package/docs/functions/cloneDeepSafe.html +1 -1
- package/docs/functions/closeAllDbConnections.html +1 -1
- package/docs/functions/compact.html +1 -1
- package/docs/functions/dreamDbConnections.html +1 -1
- package/docs/functions/dreamPath.html +1 -1
- package/docs/functions/expandStiClasses.html +1 -1
- package/docs/functions/generateDream.html +1 -1
- package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -1
- package/docs/functions/groupBy.html +1 -1
- package/docs/functions/hyphenize.html +1 -1
- package/docs/functions/inferSerializerFromDreamOrViewModel.html +1 -1
- package/docs/functions/inferSerializersFromDreamClassOrViewModelClass.html +1 -1
- package/docs/functions/intersection.html +1 -1
- package/docs/functions/isDreamSerializer.html +1 -1
- package/docs/functions/isEmpty.html +1 -1
- package/docs/functions/loadRepl.html +1 -1
- package/docs/functions/lookupClassByGlobalName.html +1 -1
- package/docs/functions/normalizeUnicode.html +1 -1
- package/docs/functions/pascalize.html +1 -1
- package/docs/functions/pgErrorType.html +1 -1
- package/docs/functions/range-1.html +1 -1
- package/docs/functions/relativeDreamPath.html +1 -1
- package/docs/functions/round.html +1 -1
- package/docs/functions/serializerNameFromFullyQualifiedModelName.html +1 -1
- package/docs/functions/sharedPathPrefix.html +1 -1
- package/docs/functions/snakeify.html +1 -1
- package/docs/functions/sort.html +1 -1
- package/docs/functions/sortBy.html +1 -1
- package/docs/functions/sortObjectByKey.html +1 -1
- package/docs/functions/sortObjectByValue.html +1 -1
- package/docs/functions/standardizeFullyQualifiedModelName.html +1 -1
- package/docs/functions/uncapitalize.html +1 -1
- package/docs/functions/uniq.html +1 -1
- package/docs/functions/untypedDb.html +1 -1
- package/docs/functions/validateColumn.html +1 -1
- package/docs/functions/validateTable.html +1 -1
- package/docs/interfaces/BelongsToStatement.html +2 -2
- package/docs/interfaces/DecoratorContext.html +2 -2
- package/docs/interfaces/DreamAppInitOptions.html +2 -2
- package/docs/interfaces/DreamAppOpts.html +2 -2
- package/docs/interfaces/EncryptOptions.html +2 -2
- package/docs/interfaces/InternalAnyTypedSerializerRendersMany.html +2 -2
- package/docs/interfaces/InternalAnyTypedSerializerRendersOne.html +2 -2
- package/docs/interfaces/OpenapiDescription.html +2 -2
- package/docs/interfaces/OpenapiSchemaProperties.html +1 -1
- package/docs/interfaces/OpenapiSchemaPropertiesShorthand.html +1 -1
- package/docs/interfaces/OpenapiTypeFieldObject.html +1 -1
- package/docs/interfaces/SerializerRendererOpts.html +2 -2
- package/docs/modules.html +1 -0
- package/docs/types/Camelized.html +1 -1
- package/docs/types/CommonOpenapiSchemaObjectFields.html +1 -1
- package/docs/types/DateTime.html +1 -1
- package/docs/types/DbConnectionType.html +1 -1
- package/docs/types/DbTypes.html +1 -1
- package/docs/types/DreamAssociationMetadata.html +1 -1
- package/docs/types/DreamAttributes.html +1 -1
- package/docs/types/DreamClassAssociationAndStatement.html +1 -0
- package/docs/types/DreamClassColumn.html +1 -1
- package/docs/types/DreamColumn.html +1 -1
- package/docs/types/DreamColumnNames.html +1 -1
- package/docs/types/DreamLogLevel.html +1 -1
- package/docs/types/DreamLogger.html +1 -1
- package/docs/types/DreamModelSerializerType.html +1 -1
- package/docs/types/DreamOrViewModelClassSerializerKey.html +1 -1
- package/docs/types/DreamOrViewModelSerializerKey.html +1 -1
- package/docs/types/DreamParamSafeAttributes.html +1 -1
- package/docs/types/DreamParamSafeColumnNames.html +1 -1
- package/docs/types/DreamSerializable.html +1 -1
- package/docs/types/DreamSerializableArray.html +1 -1
- package/docs/types/DreamSerializerKey.html +1 -1
- package/docs/types/DreamSerializers.html +1 -1
- package/docs/types/DreamTableSchema.html +1 -1
- package/docs/types/DreamVirtualColumns.html +1 -1
- package/docs/types/EncryptAlgorithm.html +1 -1
- package/docs/types/HasManyStatement.html +1 -1
- package/docs/types/HasOneStatement.html +1 -1
- package/docs/types/Hyphenized.html +1 -1
- package/docs/types/IdType.html +1 -1
- package/docs/types/OpenapiAllTypes.html +1 -1
- package/docs/types/OpenapiFormats.html +1 -1
- package/docs/types/OpenapiNumberFormats.html +1 -1
- package/docs/types/OpenapiPrimitiveBaseTypes.html +1 -1
- package/docs/types/OpenapiPrimitiveTypes.html +1 -1
- package/docs/types/OpenapiSchemaArray.html +1 -1
- package/docs/types/OpenapiSchemaArrayShorthand.html +1 -1
- package/docs/types/OpenapiSchemaBase.html +1 -1
- package/docs/types/OpenapiSchemaBody.html +1 -1
- package/docs/types/OpenapiSchemaBodyShorthand.html +1 -1
- package/docs/types/OpenapiSchemaCommonFields.html +1 -1
- package/docs/types/OpenapiSchemaExpressionAllOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionOneOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionRef.html +1 -1
- package/docs/types/OpenapiSchemaExpressionRefSchemaShorthand.html +1 -1
- package/docs/types/OpenapiSchemaInteger.html +1 -1
- package/docs/types/OpenapiSchemaNull.html +1 -1
- package/docs/types/OpenapiSchemaNumber.html +1 -1
- package/docs/types/OpenapiSchemaObject.html +1 -1
- package/docs/types/OpenapiSchemaObjectAllOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectAllOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectAnyOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectBase.html +1 -1
- package/docs/types/OpenapiSchemaObjectBaseShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectOneOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectOneOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectShorthand.html +1 -1
- package/docs/types/OpenapiSchemaPrimitiveGeneric.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionAllOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionOneOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
- package/docs/types/OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
- package/docs/types/OpenapiSchemaString.html +1 -1
- package/docs/types/OpenapiShorthandAllTypes.html +1 -1
- package/docs/types/OpenapiShorthandPrimitiveBaseTypes.html +1 -1
- package/docs/types/OpenapiShorthandPrimitiveTypes.html +1 -1
- package/docs/types/OpenapiTypeField.html +1 -1
- package/docs/types/Pascalized.html +1 -1
- package/docs/types/PrimaryKeyType.html +1 -1
- package/docs/types/RoundingPrecision.html +1 -1
- package/docs/types/SerializerCasing.html +1 -1
- package/docs/types/SimpleObjectSerializerType.html +1 -1
- package/docs/types/Snakeified.html +1 -1
- package/docs/types/Timestamp.html +1 -1
- package/docs/types/UpdateableAssociationProperties.html +1 -1
- package/docs/types/UpdateableProperties.html +1 -1
- package/docs/types/ValidationType.html +1 -1
- package/docs/types/ViewModel.html +1 -1
- package/docs/types/ViewModelClass.html +1 -1
- package/docs/types/WhereStatementForDream.html +1 -1
- package/docs/types/WhereStatementForDreamClass.html +1 -1
- package/docs/variables/DateTime-1.html +1 -1
- package/docs/variables/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/esm/src/Dream.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import yoctocolors from 'yoctocolors';
|
|
1
2
|
import { pgErrorType } from './db/errors.js';
|
|
2
3
|
import db from './db/index.js';
|
|
3
4
|
import associationToGetterSetterProp from './decorators/field/association/associationToGetterSetterProp.js';
|
|
@@ -45,7 +46,10 @@ import cloneDeepSafe from './helpers/cloneDeepSafe.js';
|
|
|
45
46
|
import { DateTime } from './helpers/DateTime.js';
|
|
46
47
|
import cachedTypeForAttribute from './helpers/db/cachedTypeForAttribute.js';
|
|
47
48
|
import isJsonColumn from './helpers/db/types/isJsonColumn.js';
|
|
49
|
+
import { indent } from './helpers/indent.js';
|
|
48
50
|
import notEqual from './helpers/notEqual.js';
|
|
51
|
+
import { inferSerializersFromDreamClassOrViewModelClass } from './serializer/helpers/inferSerializerFromDreamOrViewModel.js';
|
|
52
|
+
import { serializerForAssociatedClass } from './serializer/helpers/serializerForAssociatedClass.js';
|
|
49
53
|
export default class Dream {
|
|
50
54
|
DB;
|
|
51
55
|
/**
|
|
@@ -102,6 +106,46 @@ export default class Dream {
|
|
|
102
106
|
get globalSchema() {
|
|
103
107
|
throw new DreamMissingRequiredOverride(this.constructor, 'globalSchema');
|
|
104
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Determines if the provided Dream class is the same as or a subclass of this Dream class.
|
|
111
|
+
* This method is particularly useful for runtime type checking and works with STI (Single Table Inheritance) classes.
|
|
112
|
+
*
|
|
113
|
+
* For regular Dream classes, this checks if the provided class is exactly the same class.
|
|
114
|
+
* For STI classes, this checks inheritance relationships - a child STI class will return true
|
|
115
|
+
* when compared against its parent class.
|
|
116
|
+
*
|
|
117
|
+
* ```ts
|
|
118
|
+
* // Regular class comparison
|
|
119
|
+
* User.typeof(User) // true
|
|
120
|
+
* User.typeof(Pet) // false
|
|
121
|
+
*
|
|
122
|
+
* // STI inheritance checking
|
|
123
|
+
* class Balloon extends ApplicationModel {
|
|
124
|
+
* // base STI class
|
|
125
|
+
* }
|
|
126
|
+
*
|
|
127
|
+
* class Mylar extends Balloon {
|
|
128
|
+
* // STI child class
|
|
129
|
+
* }
|
|
130
|
+
*
|
|
131
|
+
* Balloon.typeof(Balloon) // true
|
|
132
|
+
* Balloon.typeof(Mylar) // false
|
|
133
|
+
* Mylar.typeof(Balloon) // true (child recognizes parent)
|
|
134
|
+
* Mylar.typeof(Mylar) // true
|
|
135
|
+
*
|
|
136
|
+
* // Runtime type checking with variables
|
|
137
|
+
* const dreamClass: typeof Dream = getRandomDreamClass()
|
|
138
|
+
* if (dreamClass.typeof(Pet)) {
|
|
139
|
+
* // dreamClass is Pet or a subclass of Pet
|
|
140
|
+
* }
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* @param dreamClass - The Dream class to compare against this class
|
|
144
|
+
* @returns `true` if the provided class is the same as this class or if this class is a subclass of the provided class (STI inheritance), `false` otherwise
|
|
145
|
+
*/
|
|
146
|
+
static typeof(dreamClass) {
|
|
147
|
+
return this.new() instanceof dreamClass;
|
|
148
|
+
}
|
|
105
149
|
/**
|
|
106
150
|
* Shadows #primaryKey, a getter which can be overwritten to customize the id field
|
|
107
151
|
* for a given model.
|
|
@@ -421,6 +465,65 @@ export default class Dream {
|
|
|
421
465
|
static setGlobalName(globalName) {
|
|
422
466
|
this._globalName = globalName;
|
|
423
467
|
}
|
|
468
|
+
static serializationMap(serializerKey) {
|
|
469
|
+
const key = serializerKey || 'default';
|
|
470
|
+
const serializer = inferSerializersFromDreamClassOrViewModelClass(this, key)[0] ?? null;
|
|
471
|
+
if (!serializer)
|
|
472
|
+
throw new Error(`unable to find serializer with key: ${key}`);
|
|
473
|
+
return this.recursiveSerializationMap(serializer);
|
|
474
|
+
}
|
|
475
|
+
static displaySerialization(serializerKey) {
|
|
476
|
+
const key = serializerKey || 'default';
|
|
477
|
+
const serializer = inferSerializersFromDreamClassOrViewModelClass(this, key)[0] ?? null;
|
|
478
|
+
if (!serializer)
|
|
479
|
+
throw new Error(`unable to find serializer with key: ${key}`);
|
|
480
|
+
console.log(yoctocolors.cyan(this.sanitizedName));
|
|
481
|
+
console.log(yoctocolors.gray(serializer.globalName));
|
|
482
|
+
return this.recursiveSerializationMap(serializer, {
|
|
483
|
+
forDisplay: true,
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
static recursiveSerializationMap(serializer, { forDisplay = false, forDisplayDepth = 0, } = {}) {
|
|
487
|
+
const serializerBuilder = serializer(undefined, undefined);
|
|
488
|
+
const serializerAssociations = serializerBuilder['attributes'].filter(attribute => ['rendersOne', 'rendersMany', 'delegatedAttribute'].includes(attribute.type));
|
|
489
|
+
return serializerAssociations.reduce((acc, serializerAssociation) => {
|
|
490
|
+
const serializerAssociationName = serializerAssociation.targetName ??
|
|
491
|
+
serializerAssociation.name;
|
|
492
|
+
const serializerAssociationType = serializerAssociation.type;
|
|
493
|
+
const association = this['getAssociationMetadata'](serializerAssociationName);
|
|
494
|
+
if (!association)
|
|
495
|
+
return acc;
|
|
496
|
+
const associatedClasses = association.modelCB();
|
|
497
|
+
const associatedClass = Array.isArray(associatedClasses) ? associatedClasses[0] : associatedClasses;
|
|
498
|
+
if (!associatedClass)
|
|
499
|
+
throw new Error(`No class defined on ${serializerAssociationName} association on ${this.sanitizedName}`);
|
|
500
|
+
const associationSerializer = serializerForAssociatedClass(this.prototype, serializerAssociationName, serializerAssociation.options);
|
|
501
|
+
if (!associationSerializer)
|
|
502
|
+
throw new Error(`No serializer found to render ${serializerAssociationName} on ${this.sanitizedName}`);
|
|
503
|
+
if (forDisplay && serializerAssociationType !== 'delegatedAttribute') {
|
|
504
|
+
const hierarchyLine = '└───';
|
|
505
|
+
const indentation = indent((hierarchyLine.length + 1) * forDisplayDepth, {
|
|
506
|
+
tabWidth: 1,
|
|
507
|
+
});
|
|
508
|
+
const prefix = `${hierarchyLine} `;
|
|
509
|
+
const nestedAssociationDisplay = indentation + `${prefix}${serializerAssociationType} ${yoctocolors.cyan(serializerAssociationName)}`;
|
|
510
|
+
console.log(nestedAssociationDisplay);
|
|
511
|
+
console.log(yoctocolors.gray(indentation +
|
|
512
|
+
indent(prefix.length, { tabWidth: 1 }) +
|
|
513
|
+
associationSerializer.globalName));
|
|
514
|
+
}
|
|
515
|
+
acc[association.as] = {
|
|
516
|
+
parentDreamClass: this,
|
|
517
|
+
nestedSerializerInfo: serializerAssociation.type === 'delegatedAttribute'
|
|
518
|
+
? {}
|
|
519
|
+
: associatedClass['recursiveSerializationMap'](associationSerializer, {
|
|
520
|
+
forDisplay,
|
|
521
|
+
forDisplayDepth: forDisplayDepth + 1,
|
|
522
|
+
}),
|
|
523
|
+
};
|
|
524
|
+
return acc;
|
|
525
|
+
}, {});
|
|
526
|
+
}
|
|
424
527
|
/**
|
|
425
528
|
* Returns the column names for the given model
|
|
426
529
|
*
|
|
@@ -622,12 +725,14 @@ export default class Dream {
|
|
|
622
725
|
* // 2
|
|
623
726
|
* ```
|
|
624
727
|
*
|
|
728
|
+
* @param opts - Pagination options
|
|
625
729
|
* @param opts.page - the page number that you want to fetch results for
|
|
626
730
|
* @param opts.pageSize - the number of results per page (optional)
|
|
627
|
-
* @returns
|
|
628
|
-
*
|
|
629
|
-
*
|
|
630
|
-
*
|
|
731
|
+
* @returns A paginated result object containing:
|
|
732
|
+
* - `recordCount` - A number representing the total number of records matching your query
|
|
733
|
+
* - `pageCount` - The number of pages needed to encapsulate all the matching records
|
|
734
|
+
* - `currentPage` - The current page (same as what is provided in the paginate args)
|
|
735
|
+
* - `results` - An array of records matching the current record
|
|
631
736
|
*/
|
|
632
737
|
static async paginate(opts) {
|
|
633
738
|
return await this.query().paginate(opts);
|
|
@@ -695,7 +800,8 @@ export default class Dream {
|
|
|
695
800
|
* ```
|
|
696
801
|
*
|
|
697
802
|
* @param attributes - attributes or belongs to associations you wish to set on this model before persisting
|
|
698
|
-
* @param
|
|
803
|
+
* @param __namedParameters - optional parameters
|
|
804
|
+
* @param __namedParameters.skipHooks - if true, will skip applying model hooks. Defaults to false
|
|
699
805
|
* @returns A newly persisted dream instance
|
|
700
806
|
*/
|
|
701
807
|
static async create(attributes, { skipHooks } = {}) {
|
|
@@ -719,6 +825,7 @@ export default class Dream {
|
|
|
719
825
|
* ```
|
|
720
826
|
*
|
|
721
827
|
* @param attributes - The base attributes to persist, but also the attributes to use to find when create fails
|
|
828
|
+
* @param extraOpts - Additional options
|
|
722
829
|
* @param extraOpts.createWith - additional attributes to persist when creating, but not used for finding
|
|
723
830
|
* @returns A dream instance
|
|
724
831
|
*/
|
|
@@ -751,6 +858,7 @@ export default class Dream {
|
|
|
751
858
|
* ```
|
|
752
859
|
*
|
|
753
860
|
* @param attributes - The base attributes for finding which record to update, also used when creating
|
|
861
|
+
* @param extraOpts - Additional options
|
|
754
862
|
* @param extraOpts.with - additional attributes to persist when updating and creating, but not used for finding
|
|
755
863
|
* @param extraOpts.skipHooks - if true, will skip applying model hooks. Defaults to false
|
|
756
864
|
* @returns A dream instance
|
|
@@ -771,6 +879,7 @@ export default class Dream {
|
|
|
771
879
|
* at least one of the provided attributes
|
|
772
880
|
*
|
|
773
881
|
* @param attributes - The base attributes for finding which record to update, also used when creating
|
|
882
|
+
* @param extraOpts - Additional options
|
|
774
883
|
* @param extraOpts.with - additional attributes to persist when updating and creating, but not used for finding
|
|
775
884
|
* @param extraOpts.skipHooks - if true, will skip applying model hooks. Defaults to false
|
|
776
885
|
* @returns A dream instance
|
|
@@ -860,6 +969,7 @@ export default class Dream {
|
|
|
860
969
|
* ```
|
|
861
970
|
*
|
|
862
971
|
* @param cb - The callback to call for each found record
|
|
972
|
+
* @param opts - Optional parameters for batch processing
|
|
863
973
|
* @param opts.batchSize - the batch size you wish to collect records in. If not provided, it will default to 1000
|
|
864
974
|
* @returns void
|
|
865
975
|
*/
|
|
@@ -944,6 +1054,7 @@ export default class Dream {
|
|
|
944
1054
|
* ```
|
|
945
1055
|
*
|
|
946
1056
|
* @param attributes - The base attributes for finding, but also the attributes to use when creating
|
|
1057
|
+
* @param extraOpts - Additional options
|
|
947
1058
|
* @param extraOpts.createWith - additional attributes to persist when creating, but not used for finding
|
|
948
1059
|
* @returns A dream instance
|
|
949
1060
|
*/
|
|
@@ -971,10 +1082,10 @@ export default class Dream {
|
|
|
971
1082
|
}
|
|
972
1083
|
/**
|
|
973
1084
|
* Load each specified association using a single SQL query.
|
|
974
|
-
* See {@link
|
|
1085
|
+
* See {@link Dream.preload} for preloading in separate queries.
|
|
975
1086
|
*
|
|
976
1087
|
* Note: since leftJoinPreload loads via single query, it has
|
|
977
|
-
* some downsides and that may be avoided using {@link
|
|
1088
|
+
* some downsides and that may be avoided using {@link Dream.preload}:
|
|
978
1089
|
* 1. `limit` and `offset` will be automatically removed
|
|
979
1090
|
* 2. `through` associations will bring additional namespaces into the query that can conflict with through associations from other associations, creating an invalid query
|
|
980
1091
|
* 3. each nested association will result in an additional record which duplicates data from the outer record. E.g., given `.leftJoinPreload('a', 'b', 'c')`, if each `a` has 10 `b` and each `b` has 10 `c`, then for one `a`, 100 records will be returned, each of which has all of the columns of `a`. `.preload('a', 'b', 'c')` would perform three separate SQL queries, but the data for a single `a` would only be returned once.
|
|
@@ -1015,6 +1126,102 @@ export default class Dream {
|
|
|
1015
1126
|
static preload(...args) {
|
|
1016
1127
|
return this.query().preload(...args);
|
|
1017
1128
|
}
|
|
1129
|
+
/**
|
|
1130
|
+
* Recursively preloads all Dream associations referenced by `rendersOne` and `rendersMany`
|
|
1131
|
+
* in a DreamSerializer. This traverses the entire content tree of serializers to automatically
|
|
1132
|
+
* load all necessary associations, eliminating N+1 query problems and removing the need to
|
|
1133
|
+
* manually remember which associations to preload for serialization.
|
|
1134
|
+
*
|
|
1135
|
+
* This method decouples data loading code from data rendering code by having the serializer
|
|
1136
|
+
* (rendering code) inform the query (loading code) about which associations are needed.
|
|
1137
|
+
* As serializers evolve over time - adding new `rendersOne` and `rendersMany` calls or
|
|
1138
|
+
* modifying existing ones - the loading code automatically adapts without requiring
|
|
1139
|
+
* corresponding modifications to preload statements.
|
|
1140
|
+
*
|
|
1141
|
+
* This method analyzes the serializer (specified by `serializerKey` or 'default') and
|
|
1142
|
+
* automatically preloads all associations that will be needed during serialization.
|
|
1143
|
+
*
|
|
1144
|
+
* ```ts
|
|
1145
|
+
* // Instead of manually specifying all associations:
|
|
1146
|
+
* await User.preload('posts', 'comments', 'replies').all()
|
|
1147
|
+
*
|
|
1148
|
+
* // Automatically preload everything needed for serialization:
|
|
1149
|
+
* await User.preloadFor('summary').all()
|
|
1150
|
+
*
|
|
1151
|
+
* // Add where conditions to specific associations during preloading:
|
|
1152
|
+
* await User.preloadFor('default', (dreamClass, associationName) => {
|
|
1153
|
+
* if (dreamClass.typeof(Post) && associationName === 'comments') {
|
|
1154
|
+
* return { and: { published: true } }
|
|
1155
|
+
* }
|
|
1156
|
+
* }).all()
|
|
1157
|
+
*
|
|
1158
|
+
* // Skip preloading specific associations to handle them manually:
|
|
1159
|
+
* await User.preloadFor('summary', (dreamClass, associationName) => {
|
|
1160
|
+
* if (dreamClass.typeof(User) && associationName === 'posts') {
|
|
1161
|
+
* return 'omit' // Handle posts preloading separately with custom logic
|
|
1162
|
+
* }
|
|
1163
|
+
* })
|
|
1164
|
+
* .preload('posts', { and: { featured: true } }) // Custom preloading
|
|
1165
|
+
* .all()
|
|
1166
|
+
* ```
|
|
1167
|
+
*
|
|
1168
|
+
* @param serializerKey - The serializer key to use for determining which associations to preload.
|
|
1169
|
+
* @param modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
|
|
1170
|
+
* @returns A Query with all serialization associations preloaded
|
|
1171
|
+
*/
|
|
1172
|
+
static preloadFor(serializerKey, modifierFn) {
|
|
1173
|
+
return this.query().preloadFor(serializerKey, modifierFn);
|
|
1174
|
+
}
|
|
1175
|
+
/**
|
|
1176
|
+
* Recursively preloads all Dream associations referenced by `rendersOne` and `rendersMany`
|
|
1177
|
+
* in a DreamSerializer using left join preloading. This traverses the entire content tree
|
|
1178
|
+
* of serializers to automatically load all necessary associations in a single query,
|
|
1179
|
+
* eliminating N+1 query problems and removing the need to manually remember which
|
|
1180
|
+
* associations to preload for serialization.
|
|
1181
|
+
*
|
|
1182
|
+
* This method decouples data loading code from data rendering code by having the serializer
|
|
1183
|
+
* (rendering code) inform the query (loading code) about which associations are needed.
|
|
1184
|
+
* As serializers evolve over time - adding new `rendersOne` and `rendersMany` calls or
|
|
1185
|
+
* modifying existing ones - the loading code automatically adapts without requiring
|
|
1186
|
+
* corresponding modifications to left join preload statements.
|
|
1187
|
+
*
|
|
1188
|
+
* This method analyzes the serializer (specified by `serializerKey` or 'default') and
|
|
1189
|
+
* automatically left join preloads all associations that will be needed during serialization.
|
|
1190
|
+
*
|
|
1191
|
+
* Note: Left join preloading loads all data in a single SQL query but has trade-offs compared
|
|
1192
|
+
* to regular preloading. See {@link Dream.leftJoinPreload} for details about limitations.
|
|
1193
|
+
*
|
|
1194
|
+
* ```ts
|
|
1195
|
+
* // Instead of manually specifying all associations:
|
|
1196
|
+
* await User.leftJoinPreload('posts', 'comments', 'replies').all()
|
|
1197
|
+
*
|
|
1198
|
+
* // Automatically left join preload everything needed for serialization:
|
|
1199
|
+
* await User.leftJoinPreloadFor('summary').all()
|
|
1200
|
+
*
|
|
1201
|
+
* // Add where conditions to specific associations during left join preloading:
|
|
1202
|
+
* await User.leftJoinPreloadFor('detailed', (dreamClass, associationName) => {
|
|
1203
|
+
* if (dreamClass.typeof(Post) && associationName === 'comments') {
|
|
1204
|
+
* return { and: { published: true } }
|
|
1205
|
+
* }
|
|
1206
|
+
* }).all()
|
|
1207
|
+
*
|
|
1208
|
+
* // Skip left join preloading specific associations to handle them manually:
|
|
1209
|
+
* await User.leftJoinPreloadFor('summary', (dreamClass, associationName) => {
|
|
1210
|
+
* if (dreamClass.typeof(User) && associationName === 'posts') {
|
|
1211
|
+
* return 'omit' // Handle posts preloading separately with custom logic
|
|
1212
|
+
* }
|
|
1213
|
+
* })
|
|
1214
|
+
* .preload('posts', { and: { featured: true } }) // Custom preloading instead
|
|
1215
|
+
* .all()
|
|
1216
|
+
* ```
|
|
1217
|
+
*
|
|
1218
|
+
* @param serializerKey - The serializer key to use for determining which associations to preload.
|
|
1219
|
+
* @param modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
|
|
1220
|
+
* @returns A Query with all serialization associations left join preloaded
|
|
1221
|
+
*/
|
|
1222
|
+
static leftJoinPreloadFor(serializerKey, modifierFn) {
|
|
1223
|
+
return this.query().leftJoinPreloadFor(serializerKey, modifierFn);
|
|
1224
|
+
}
|
|
1018
1225
|
/**
|
|
1019
1226
|
* Returns a new Query instance with the provided
|
|
1020
1227
|
* inner join statement attached
|
|
@@ -1211,7 +1418,7 @@ export default class Dream {
|
|
|
1211
1418
|
* // 3
|
|
1212
1419
|
* ```
|
|
1213
1420
|
*
|
|
1214
|
-
* @param
|
|
1421
|
+
* @param args - a list of fields to pluck, followed by a callback function to call for each set of found fields
|
|
1215
1422
|
* @returns void
|
|
1216
1423
|
*/
|
|
1217
1424
|
static async pluckEach(...args) {
|
|
@@ -1420,7 +1627,7 @@ export default class Dream {
|
|
|
1420
1627
|
* // [User{email: 'how@yadoin'}, User{name: 'fred'}, User{name: 'fred'}]
|
|
1421
1628
|
* ```
|
|
1422
1629
|
*
|
|
1423
|
-
* @param
|
|
1630
|
+
* @param statements - a list of where statements to `OR` together
|
|
1424
1631
|
* @returns A Query for this model with the whereAny clause applied
|
|
1425
1632
|
*/
|
|
1426
1633
|
static whereAny(statements) {
|
|
@@ -1435,7 +1642,7 @@ export default class Dream {
|
|
|
1435
1642
|
* // User{email: 'hello@world'}
|
|
1436
1643
|
* ```
|
|
1437
1644
|
*
|
|
1438
|
-
* @param
|
|
1645
|
+
* @param attributes - A where statement to negate and apply to the Query
|
|
1439
1646
|
* @returns A Query for this model with the whereNot clause applied
|
|
1440
1647
|
*/
|
|
1441
1648
|
static whereNot(attributes) {
|
|
@@ -2375,7 +2582,7 @@ export default class Dream {
|
|
|
2375
2582
|
* // 'dog'
|
|
2376
2583
|
* ```
|
|
2377
2584
|
*
|
|
2378
|
-
* @param
|
|
2585
|
+
* @param columnName - The column name you want the previous value for
|
|
2379
2586
|
* @returns Returns the previous value for an attribute
|
|
2380
2587
|
*/
|
|
2381
2588
|
previousValueForAttribute(columnName) {
|
|
@@ -2401,7 +2608,7 @@ export default class Dream {
|
|
|
2401
2608
|
* Returns true if the columnName provided has
|
|
2402
2609
|
* changes that have not yet been persisted.
|
|
2403
2610
|
*
|
|
2404
|
-
* @param
|
|
2611
|
+
* @param attribute - the column name to check
|
|
2405
2612
|
* @returns A boolean
|
|
2406
2613
|
*/
|
|
2407
2614
|
willSaveChangeToAttribute(attribute) {
|
|
@@ -2838,7 +3045,7 @@ export default class Dream {
|
|
|
2838
3045
|
/**
|
|
2839
3046
|
* Loads the requested associations upon execution
|
|
2840
3047
|
*
|
|
2841
|
-
* NOTE: {@link
|
|
3048
|
+
* NOTE: {@link Dream.preload} is often a preferrable way of achieving the
|
|
2842
3049
|
* same goal.
|
|
2843
3050
|
*
|
|
2844
3051
|
* ```ts
|
|
@@ -2860,20 +3067,67 @@ export default class Dream {
|
|
|
2860
3067
|
load(...args) {
|
|
2861
3068
|
return new LoadBuilder(this).load(...args);
|
|
2862
3069
|
}
|
|
3070
|
+
/**
|
|
3071
|
+
* Recursively loads all Dream associations referenced by `rendersOne` and `rendersMany`
|
|
3072
|
+
* in a DreamSerializer. This traverses the entire content tree of serializers to automatically
|
|
3073
|
+
* load all necessary associations, eliminating N+1 query problems and removing the need to
|
|
3074
|
+
* manually remember which associations to preload for serialization.
|
|
3075
|
+
*
|
|
3076
|
+
* This method decouples data loading code from data rendering code by having the serializer
|
|
3077
|
+
* (rendering code) inform the query (loading code) about which associations are needed.
|
|
3078
|
+
* As serializers evolve over time - adding new `rendersOne` and `rendersMany` calls or
|
|
3079
|
+
* modifying existing ones - the loading code automatically adapts without requiring
|
|
3080
|
+
* corresponding modifications to preload statements.
|
|
3081
|
+
*
|
|
3082
|
+
* This method analyzes the serializer (specified by `serializerKey` or 'default') and
|
|
3083
|
+
* automatically preloads all associations that will be needed during serialization.
|
|
3084
|
+
*
|
|
3085
|
+
* ```ts
|
|
3086
|
+
* // Instead of manually specifying all associations:
|
|
3087
|
+
* await User.preload('posts', 'comments', 'replies').all()
|
|
3088
|
+
*
|
|
3089
|
+
* // Automatically preload everything needed for serialization:
|
|
3090
|
+
* await user.loadFor('summary').execute()
|
|
3091
|
+
*
|
|
3092
|
+
* // Add where conditions to specific associations during preloading:
|
|
3093
|
+
* await user.loadFor('detailed', (dreamClass, associationName) => {
|
|
3094
|
+
* if (dreamClass.typeof(Post) && associationName === 'comments') {
|
|
3095
|
+
* return { and: { published: true } }
|
|
3096
|
+
* }
|
|
3097
|
+
* })
|
|
3098
|
+
* .execute()
|
|
3099
|
+
*
|
|
3100
|
+
* // Skip preloading specific associations to handle them manually:
|
|
3101
|
+
* await user
|
|
3102
|
+
* .loadFor('summary', (dreamClass, associationName) => {
|
|
3103
|
+
* if (dreamClass.typeof(User) && associationName === 'posts') {
|
|
3104
|
+
* return 'omit' // Handle posts preloading separately with custom logic
|
|
3105
|
+
* }
|
|
3106
|
+
* })
|
|
3107
|
+
* .load('posts', { and: { featured: true } }) // Custom preloading
|
|
3108
|
+
* .execute()
|
|
3109
|
+
* ```
|
|
3110
|
+
*
|
|
3111
|
+
* @param serializerKey - The serializer key to use for determining which associations to preload.
|
|
3112
|
+
* @param modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
|
|
3113
|
+
* @returns A Query with all serialization associations preloaded
|
|
3114
|
+
*/
|
|
3115
|
+
loadFor(serializerKey, modifierFn) {
|
|
3116
|
+
return new LoadBuilder(this)['loadFor'](serializerKey, modifierFn);
|
|
3117
|
+
}
|
|
2863
3118
|
/**
|
|
2864
3119
|
* Load each specified association using a single SQL query.
|
|
2865
|
-
* See {@link
|
|
3120
|
+
* See {@link Dream.load} for loading in separate queries.
|
|
2866
3121
|
*
|
|
2867
|
-
* Note: since
|
|
2868
|
-
* some downsides and that may be avoided using {@link
|
|
3122
|
+
* Note: since leftJoinLoad loads via single query, it has
|
|
3123
|
+
* some downsides and that may be avoided using {@link Dream.load}:
|
|
2869
3124
|
* 1. `limit` and `offset` will be automatically removed
|
|
2870
3125
|
* 2. `through` associations will bring additional namespaces into the query that can conflict with through associations from other associations, creating an invalid query
|
|
2871
|
-
* 3. each nested association will result in an additional record which duplicates data from the outer record. E.g., given `.
|
|
3126
|
+
* 3. each nested association will result in an additional record which duplicates data from the outer record. E.g., given `.leftJoinLoad('a', 'b', 'c')`, if each `a` has 10 `b` and each `b` has 10 `c`, then for one `a`, 100 records will be returned, each of which has all of the columns of `a`. `.load('a', 'b', 'c')` would perform three separate SQL queries, but the data for a single `a` would only be returned once.
|
|
2872
3127
|
* 4. the individual query becomes more complex the more associations are included
|
|
2873
3128
|
* 5. associations loading associations loading associations could result in exponential amounts of data; in those cases, `.load(...).findEach(...)` avoids instantiating massive amounts of data at once
|
|
2874
|
-
* Loads the requested associations upon execution
|
|
2875
3129
|
*
|
|
2876
|
-
* NOTE: {@link
|
|
3130
|
+
* NOTE: {@link Dream.leftJoinPreload} is often a preferrable way of achieving the
|
|
2877
3131
|
* same goal.
|
|
2878
3132
|
*
|
|
2879
3133
|
* ```ts
|
|
@@ -2895,6 +3149,54 @@ export default class Dream {
|
|
|
2895
3149
|
leftJoinLoad(...args) {
|
|
2896
3150
|
return new LeftJoinLoadBuilder(this).leftJoinLoad(...args);
|
|
2897
3151
|
}
|
|
3152
|
+
/**
|
|
3153
|
+
* Recursively loads all Dream associations referenced by `rendersOne` and `rendersMany`
|
|
3154
|
+
* in a DreamSerializer. This traverses the entire content tree of serializers to automatically
|
|
3155
|
+
* load all necessary associations, eliminating N+1 query problems and removing the need to
|
|
3156
|
+
* manually remember which associations to preload for serialization.
|
|
3157
|
+
*
|
|
3158
|
+
* This method decouples data loading code from data rendering code by having the serializer
|
|
3159
|
+
* (rendering code) inform the query (loading code) about which associations are needed.
|
|
3160
|
+
* As serializers evolve over time - adding new `rendersOne` and `rendersMany` calls or
|
|
3161
|
+
* modifying existing ones - the loading code automatically adapts without requiring
|
|
3162
|
+
* corresponding modifications to preload statements.
|
|
3163
|
+
*
|
|
3164
|
+
* This method analyzes the serializer (specified by `serializerKey` or 'default') and
|
|
3165
|
+
* automatically preloads all associations that will be needed during serialization.
|
|
3166
|
+
*
|
|
3167
|
+
* ```ts
|
|
3168
|
+
* // Instead of manually specifying all associations:
|
|
3169
|
+
* await User.preload('posts', 'comments', 'replies').all()
|
|
3170
|
+
*
|
|
3171
|
+
* // Automatically preload everything needed for serialization:
|
|
3172
|
+
* await user.leftJoinLoadFor('summary').execute()
|
|
3173
|
+
*
|
|
3174
|
+
* // Add where conditions to specific associations during preloading:
|
|
3175
|
+
* await user.leftJoinLoadFor('detailed', (dreamClass, associationName) => {
|
|
3176
|
+
* if (dreamClass.typeof(Post) && associationName === 'comments') {
|
|
3177
|
+
* return { and: { published: true } }
|
|
3178
|
+
* }
|
|
3179
|
+
* })
|
|
3180
|
+
* .execute()
|
|
3181
|
+
*
|
|
3182
|
+
* // Skip preloading specific associations to handle them manually:
|
|
3183
|
+
* await user
|
|
3184
|
+
* .loadFor('summary', (dreamClass, associationName) => {
|
|
3185
|
+
* if (dreamClass.typeof(User) && associationName === 'posts') {
|
|
3186
|
+
* return 'omit' // Handle posts preloading separately with custom logic
|
|
3187
|
+
* }
|
|
3188
|
+
* })
|
|
3189
|
+
* .load('posts', { and: { featured: true } }) // Custom preloading
|
|
3190
|
+
* .execute()
|
|
3191
|
+
* ```
|
|
3192
|
+
*
|
|
3193
|
+
* @param serializerKey - The serializer key to use for determining which associations to preload.
|
|
3194
|
+
* @param modifierFn - Optional callback function to modify or omit specific associations during preloading. Called for each association with the Dream class and association name. Return an object with `and`, `andAny`, or `andNot` properties to add where conditions, return 'omit' to skip preloading that association (useful when you want to handle it manually), or return undefined to use default preloading
|
|
3195
|
+
* @returns A Query with all serialization associations preloaded
|
|
3196
|
+
*/
|
|
3197
|
+
leftJoinLoadFor(serializerKey, modifierFn) {
|
|
3198
|
+
return new LeftJoinLoadBuilder(this)['leftJoinLoadFor'](serializerKey, modifierFn);
|
|
3199
|
+
}
|
|
2898
3200
|
/**
|
|
2899
3201
|
* Returns true if the association specified has
|
|
2900
3202
|
* been loaded on this instance
|
|
@@ -3007,7 +3309,8 @@ export default class Dream {
|
|
|
3007
3309
|
* user.type // 'User'
|
|
3008
3310
|
* ```
|
|
3009
3311
|
*
|
|
3010
|
-
* @param
|
|
3312
|
+
* @param __namedParameters - optional parameters
|
|
3313
|
+
* @param __namedParameters.skipHooks - if true, will skip applying model hooks. Defaults to false
|
|
3011
3314
|
* @returns void
|
|
3012
3315
|
*/
|
|
3013
3316
|
async save({ skipHooks } = {}) {
|
|
@@ -3047,7 +3350,8 @@ export default class Dream {
|
|
|
3047
3350
|
* ```
|
|
3048
3351
|
*
|
|
3049
3352
|
* @param attributes - the attributes to set on the model
|
|
3050
|
-
* @param
|
|
3353
|
+
* @param __namedParameters - optional parameters
|
|
3354
|
+
* @param __namedParameters.skipHooks - if true, will skip applying model hooks. Defaults to false
|
|
3051
3355
|
* @returns void
|
|
3052
3356
|
*/
|
|
3053
3357
|
async update(attributes, { skipHooks } = {}) {
|
|
@@ -3074,7 +3378,8 @@ export default class Dream {
|
|
|
3074
3378
|
* ```
|
|
3075
3379
|
*
|
|
3076
3380
|
* @param attributes - The attributes to update on this instance
|
|
3077
|
-
* @param
|
|
3381
|
+
* @param __namedParameters - optional parameters
|
|
3382
|
+
* @param __namedParameters.skipHooks - if true, will skip applying model hooks. Defaults to false
|
|
3078
3383
|
* @returns - void
|
|
3079
3384
|
*/
|
|
3080
3385
|
async updateAttributes(attributes, { skipHooks } = {}) {
|
|
@@ -3107,7 +3412,7 @@ export default class Dream {
|
|
|
3107
3412
|
* Flags a dream model so that it allows
|
|
3108
3413
|
* deletion once again.
|
|
3109
3414
|
*
|
|
3110
|
-
* Undoes {@link Dream.
|
|
3415
|
+
* Undoes {@link Dream.preventDeletion}
|
|
3111
3416
|
*
|
|
3112
3417
|
* ```ts
|
|
3113
3418
|
* class User extends ApplicationModel {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { InvalidArgumentError } from 'commander';
|
|
2
2
|
import DreamBin from '../bin/index.js';
|
|
3
|
+
import DreamApp from '../dream-app/index.js';
|
|
3
4
|
import EnvInternal from '../helpers/EnvInternal.js';
|
|
4
5
|
import sspawn from '../helpers/sspawn.js';
|
|
5
6
|
import DreamCliLogger from './logger/DreamCliLogger.js';
|
|
@@ -139,6 +140,21 @@ export default class DreamCLI {
|
|
|
139
140
|
await seedDb();
|
|
140
141
|
process.exit();
|
|
141
142
|
});
|
|
143
|
+
program
|
|
144
|
+
.command('inspect:serialization')
|
|
145
|
+
.alias('i:serialization')
|
|
146
|
+
.description('displays a serialization map to help understand the rendering logic for a particular model')
|
|
147
|
+
.argument('<globalName>', 'the global name of the model you want to look up')
|
|
148
|
+
.argument('[serializerKey]', 'the serializer key you wish to use')
|
|
149
|
+
.action(async (globalName, serializerKey) => {
|
|
150
|
+
await initializeDreamApp();
|
|
151
|
+
const dreamApp = DreamApp.getOrFail();
|
|
152
|
+
const modelClass = dreamApp.models[globalName];
|
|
153
|
+
if (!modelClass)
|
|
154
|
+
throw new Error(`failed to locate model by global name: ${globalName}`);
|
|
155
|
+
modelClass['displaySerialization'](serializerKey);
|
|
156
|
+
process.exit();
|
|
157
|
+
});
|
|
142
158
|
}
|
|
143
159
|
/*
|
|
144
160
|
* the default spawn provided by node:child_process is incompatible
|
|
@@ -9,8 +9,9 @@ export default class DreamMigrationHelpers {
|
|
|
9
9
|
*
|
|
10
10
|
* @param db - The Kysely database object passed into the migration up/down function
|
|
11
11
|
* @param constraintName - The name of the constraint to create
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
12
|
+
* @param options - Configuration options
|
|
13
|
+
* @param options.table - The name of the table
|
|
14
|
+
* @param options.columns - The names of the columns to include in the constraint
|
|
14
15
|
*
|
|
15
16
|
*/
|
|
16
17
|
static async addDeferrableUniqueConstraint(db, constraintName, { table, columns, }) {
|
|
@@ -28,9 +29,9 @@ export default class DreamMigrationHelpers {
|
|
|
28
29
|
* Note that this always includes "IF NOT EXISTS", so is safe to re-run multiple times.
|
|
29
30
|
*
|
|
30
31
|
* @param db - The Kysely database object passed into the migration up/down function
|
|
31
|
-
* @param
|
|
32
|
-
* @param
|
|
33
|
-
*
|
|
32
|
+
* @param __namedParameters - The options for adding the enum value
|
|
33
|
+
* @param __namedParameters.enumName - The name of the enum to modify
|
|
34
|
+
* @param __namedParameters.value - The name of the value to add to the enum
|
|
34
35
|
*/
|
|
35
36
|
static async addEnumValue(db, { enumName, value }) {
|
|
36
37
|
await sql `ALTER TYPE ${sql.raw(enumName)} ADD VALUE IF NOT EXISTS '${sql.raw(value)}';`.execute(db);
|
|
@@ -48,8 +49,9 @@ export default class DreamMigrationHelpers {
|
|
|
48
49
|
*
|
|
49
50
|
* @param db - The Kysely database object passed into the migration up/down function
|
|
50
51
|
* @param extensionName - The name of the database extension to add
|
|
51
|
-
* @param
|
|
52
|
-
* @param
|
|
52
|
+
* @param options - Configuration options
|
|
53
|
+
* @param options.ifNotExists - Only add the extension if it doesn't already exist
|
|
54
|
+
* @param options.publicSchema - Create using the public schema
|
|
53
55
|
*
|
|
54
56
|
*/
|
|
55
57
|
static async createExtension(db, extensionName, { ifNotExists = true, publicSchema = true } = {}) {
|
|
@@ -64,8 +66,9 @@ export default class DreamMigrationHelpers {
|
|
|
64
66
|
*
|
|
65
67
|
* @param db - The Kysely database object passed into the migration up/down function
|
|
66
68
|
* @param indexName - The name of the constraint to create
|
|
67
|
-
* @param
|
|
68
|
-
* @param
|
|
69
|
+
* @param options - Configuration options
|
|
70
|
+
* @param options.table - The name of the table
|
|
71
|
+
* @param options.column - The name of the column to index
|
|
69
72
|
*
|
|
70
73
|
*/
|
|
71
74
|
static async createGinIndex(db, indexName, { table, column }) {
|
|
@@ -80,7 +83,8 @@ export default class DreamMigrationHelpers {
|
|
|
80
83
|
*
|
|
81
84
|
* @param db - The Kysely database object passed into the migration up/down function
|
|
82
85
|
* @param constraintName - The name of the constraint to create
|
|
83
|
-
* @param
|
|
86
|
+
* @param options - Configuration options
|
|
87
|
+
* @param options.table - The name of the table
|
|
84
88
|
*
|
|
85
89
|
*/
|
|
86
90
|
static async dropConstraint(db, constraintName, { table }) {
|
|
@@ -92,10 +96,10 @@ export default class DreamMigrationHelpers {
|
|
|
92
96
|
* Drop a value from an enum and replace it (or optionally remove it from array columns)
|
|
93
97
|
*
|
|
94
98
|
* @param db - The Kysely database object passed into the migration up/down function
|
|
95
|
-
* @param
|
|
96
|
-
* @param
|
|
97
|
-
* @param
|
|
98
|
-
*
|
|
99
|
+
* @param __namedParameters - The options for dropping the enum value
|
|
100
|
+
* @param __namedParameters.enumName - The name of the enum to modify
|
|
101
|
+
* @param __namedParameters.value - The name of the value to drop from the enum
|
|
102
|
+
* @param __namedParameters.replacements - Details about which table and column to change and which value to replace the dropped value with (or remove it if the column is an array)
|
|
99
103
|
*/
|
|
100
104
|
static async dropEnumValue(db, { enumName, value, replacements }) {
|
|
101
105
|
// temporarily set all table columns depending on this enum to an acceptable alternate type
|
|
@@ -159,7 +159,8 @@ export default class Decorators {
|
|
|
159
159
|
* }
|
|
160
160
|
* ```
|
|
161
161
|
*
|
|
162
|
-
* @param
|
|
162
|
+
* @param opts - Configuration options for the sortable decorator
|
|
163
|
+
* @param opts.scope - The column, association, or combination thereof which you would like to restrict the incrementing logic to. Can be a single column name, a single belongs-to association name, or an array of column/association names
|
|
163
164
|
* @returns A Sortable decorator
|
|
164
165
|
*/
|
|
165
166
|
Sortable(opts) {
|