@rvoh/dream 2.5.7 → 2.6.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 +37 -66
- package/dist/cjs/src/decorators/class/STI.js +2 -2
- package/dist/cjs/src/dream/LeftJoinLoadBuilder.js +16 -10
- package/dist/cjs/src/dream/LoadBuilder.js +70 -9
- package/dist/cjs/src/dream/Query.js +5 -6
- package/dist/cjs/src/dream/constants.js +2 -0
- package/dist/cjs/src/dream/internal/buildAssociationPaths.js +33 -0
- package/dist/cjs/src/dream/internal/buildDependentDestroyPreloadPaths.js +43 -0
- package/dist/cjs/src/dream/internal/buildSerializerPreloadPaths.js +38 -0
- package/dist/cjs/src/dream/internal/destroyAssociatedRecords.js +14 -6
- package/dist/cjs/src/dream/internal/destroyDream.js +7 -1
- package/dist/cjs/src/dream/internal/loadDependentDestroyTree.js +35 -0
- package/dist/cjs/src/dream/internal/resolveSerializerAssociationEdges.js +53 -0
- package/dist/cjs/src/serializer/SerializerRenderer.js +1 -1
- package/dist/cjs/src/serializer/builders/DreamSerializerBuilder.js +114 -52
- package/dist/cjs/src/serializer/builders/ObjectSerializerBuilder.js +111 -41
- package/dist/cjs/src/types/recursiveSerialization.js +1 -0
- package/dist/esm/src/Dream.js +37 -66
- package/dist/esm/src/decorators/class/STI.js +2 -2
- package/dist/esm/src/dream/LeftJoinLoadBuilder.js +16 -10
- package/dist/esm/src/dream/LoadBuilder.js +70 -9
- package/dist/esm/src/dream/Query.js +5 -6
- package/dist/esm/src/dream/constants.js +2 -0
- package/dist/esm/src/dream/internal/buildAssociationPaths.js +33 -0
- package/dist/esm/src/dream/internal/buildDependentDestroyPreloadPaths.js +43 -0
- package/dist/esm/src/dream/internal/buildSerializerPreloadPaths.js +38 -0
- package/dist/esm/src/dream/internal/destroyAssociatedRecords.js +14 -6
- package/dist/esm/src/dream/internal/destroyDream.js +7 -1
- package/dist/esm/src/dream/internal/loadDependentDestroyTree.js +35 -0
- package/dist/esm/src/dream/internal/resolveSerializerAssociationEdges.js +53 -0
- package/dist/esm/src/serializer/SerializerRenderer.js +1 -1
- package/dist/esm/src/serializer/builders/DreamSerializerBuilder.js +114 -52
- package/dist/esm/src/serializer/builders/ObjectSerializerBuilder.js +111 -41
- package/dist/esm/src/types/recursiveSerialization.js +1 -0
- package/dist/types/src/Dream.d.ts +25 -10
- package/dist/types/src/decorators/Decorators.d.ts +8 -0
- package/dist/types/src/decorators/class/STI.d.ts +1 -3
- package/dist/types/src/decorators/field/sortable/Sortable.d.ts +9 -0
- package/dist/types/src/decorators/field/validation/Validates.d.ts +4 -0
- package/dist/types/src/decorators/static-method/Scope.d.ts +4 -0
- package/dist/types/src/dream/LeftJoinLoadBuilder.d.ts +16 -10
- package/dist/types/src/dream/LoadBuilder.d.ts +63 -10
- package/dist/types/src/dream/Query.d.ts +1 -1
- package/dist/types/src/dream/constants.d.ts +2 -0
- package/dist/types/src/dream/internal/buildAssociationPaths.d.ts +12 -0
- package/dist/types/src/dream/internal/buildDependentDestroyPreloadPaths.d.ts +17 -0
- package/dist/types/src/dream/internal/buildSerializerPreloadPaths.d.ts +3 -0
- package/dist/types/src/dream/internal/convertDreamClassAndAssociationNameTupleArrayToPreloadArgs.d.ts +1 -1
- package/dist/types/src/dream/internal/destroyAssociatedRecords.d.ts +5 -1
- package/dist/types/src/dream/internal/loadDependentDestroyTree.d.ts +17 -0
- package/dist/types/src/dream/internal/resolveSerializerAssociationEdges.d.ts +13 -0
- package/dist/types/src/serializer/builders/DreamSerializerBuilder.d.ts +164 -63
- package/dist/types/src/serializer/builders/ObjectSerializerBuilder.d.ts +126 -43
- package/dist/types/src/types/associations/belongsTo.d.ts +34 -0
- package/dist/types/src/types/associations/belongsTo.ts +41 -0
- package/dist/types/src/types/associations/hasMany.d.ts +18 -0
- package/dist/types/src/types/associations/hasMany.ts +18 -0
- package/dist/types/src/types/associations/shared.d.ts +71 -0
- package/dist/types/src/types/associations/shared.ts +74 -0
- package/dist/types/src/types/dream.d.ts +16 -0
- package/dist/types/src/types/dream.ts +18 -0
- package/dist/types/src/types/lifecycle.d.ts +18 -0
- package/dist/types/src/types/lifecycle.ts +18 -0
- package/dist/types/src/types/query.d.ts +3 -0
- package/dist/types/src/types/query.ts +3 -0
- package/dist/types/src/types/recursiveSerialization.d.ts +8 -0
- package/dist/types/src/types/recursiveSerialization.ts +10 -0
- package/dist/types/src/types/serializer.d.ts +8 -1
- package/dist/types/src/types/serializer.ts +8 -1
- package/docs/classes/db.DreamMigrationHelpers.html +9 -9
- package/docs/classes/db.KyselyQueryDriver.html +32 -32
- package/docs/classes/db.PostgresQueryDriver.html +33 -33
- package/docs/classes/db.QueryDriverBase.html +31 -31
- package/docs/classes/errors.CheckConstraintViolation.html +3 -3
- package/docs/classes/errors.ColumnOverflow.html +3 -3
- package/docs/classes/errors.CreateOrFindByFailedToCreateAndFind.html +3 -3
- package/docs/classes/errors.DataIncompatibleWithDatabaseField.html +3 -3
- package/docs/classes/errors.DataTypeColumnTypeMismatch.html +3 -3
- package/docs/classes/errors.GlobalNameNotSet.html +3 -3
- package/docs/classes/errors.InvalidCalendarDate.html +2 -2
- package/docs/classes/errors.InvalidClockTime.html +2 -2
- package/docs/classes/errors.InvalidClockTimeTz.html +2 -2
- package/docs/classes/errors.InvalidDateTime.html +2 -2
- package/docs/classes/errors.MissingSerializersDefinition.html +3 -3
- package/docs/classes/errors.NonLoadedAssociation.html +3 -3
- package/docs/classes/errors.NotNullViolation.html +3 -3
- package/docs/classes/errors.RecordNotFound.html +3 -3
- package/docs/classes/errors.ValidationError.html +3 -3
- package/docs/classes/index.CalendarDate.html +33 -33
- package/docs/classes/index.ClockTime.html +32 -32
- package/docs/classes/index.ClockTimeTz.html +35 -35
- package/docs/classes/index.DateTime.html +86 -86
- package/docs/classes/index.Decorators.html +21 -20
- package/docs/classes/index.Dream.html +133 -126
- package/docs/classes/index.DreamApp.html +5 -5
- package/docs/classes/index.DreamTransaction.html +2 -2
- package/docs/classes/index.Env.html +2 -2
- package/docs/classes/index.Query.html +57 -57
- package/docs/classes/system.CliFileWriter.html +4 -4
- package/docs/classes/system.DreamBin.html +2 -2
- package/docs/classes/system.DreamCLI.html +6 -6
- package/docs/classes/system.DreamImporter.html +2 -2
- package/docs/classes/system.DreamLogos.html +2 -2
- package/docs/classes/system.DreamSerializerBuilder.html +177 -59
- package/docs/classes/system.ObjectSerializerBuilder.html +110 -34
- package/docs/classes/system.PathHelpers.html +3 -3
- package/docs/classes/utils.Encrypt.html +2 -2
- package/docs/classes/utils.Range.html +2 -2
- package/docs/functions/db.closeAllDbConnections.html +1 -1
- package/docs/functions/db.dreamDbConnections.html +1 -1
- package/docs/functions/db.untypedDb.html +1 -1
- package/docs/functions/db.validateColumn.html +1 -1
- package/docs/functions/db.validateTable.html +1 -1
- package/docs/functions/errors.pgErrorType.html +1 -1
- package/docs/functions/index.DreamSerializer.html +1 -1
- package/docs/functions/index.ObjectSerializer.html +1 -1
- package/docs/functions/index.ReplicaSafe.html +1 -1
- package/docs/functions/index.STI.html +1 -1
- package/docs/functions/index.SoftDelete.html +1 -1
- package/docs/functions/utils.camelize.html +1 -1
- package/docs/functions/utils.capitalize.html +1 -1
- package/docs/functions/utils.cloneDeepSafe.html +1 -1
- package/docs/functions/utils.compact.html +1 -1
- package/docs/functions/utils.groupBy.html +1 -1
- package/docs/functions/utils.hyphenize.html +1 -1
- package/docs/functions/utils.intersection.html +1 -1
- package/docs/functions/utils.isEmpty.html +1 -1
- package/docs/functions/utils.normalizeUnicode.html +1 -1
- package/docs/functions/utils.pascalize.html +1 -1
- package/docs/functions/utils.percent.html +1 -1
- package/docs/functions/utils.range.html +1 -1
- package/docs/functions/utils.round.html +1 -1
- package/docs/functions/utils.sanitizeString.html +1 -1
- package/docs/functions/utils.snakeify.html +1 -1
- package/docs/functions/utils.sort.html +1 -1
- package/docs/functions/utils.sortBy.html +1 -1
- package/docs/functions/utils.sortObjectByKey.html +1 -1
- package/docs/functions/utils.sortObjectByValue.html +1 -1
- package/docs/functions/utils.uncapitalize.html +1 -1
- package/docs/functions/utils.uniq.html +1 -1
- package/docs/interfaces/openapi.OpenapiDescription.html +2 -2
- package/docs/interfaces/openapi.OpenapiSchemaProperties.html +1 -1
- package/docs/interfaces/openapi.OpenapiSchemaPropertiesShorthand.html +1 -1
- package/docs/interfaces/openapi.OpenapiTypeFieldObject.html +1 -1
- package/docs/interfaces/types.BelongsToStatement.html +2 -2
- package/docs/interfaces/types.DecoratorContext.html +2 -2
- package/docs/interfaces/types.DreamAppInitOptions.html +2 -2
- package/docs/interfaces/types.DreamAppOpts.html +2 -2
- package/docs/interfaces/types.DurationObject.html +2 -2
- package/docs/interfaces/types.EncryptOptions.html +2 -2
- package/docs/interfaces/types.InternalAnyTypedSerializerRendersMany.html +2 -2
- package/docs/interfaces/types.InternalAnyTypedSerializerRendersOne.html +2 -2
- package/docs/interfaces/types.SerializerRendererOpts.html +2 -2
- package/docs/types/openapi.CommonOpenapiSchemaObjectFields.html +1 -1
- package/docs/types/openapi.OpenapiAllTypes.html +1 -1
- package/docs/types/openapi.OpenapiFormats.html +1 -1
- package/docs/types/openapi.OpenapiNumberFormats.html +1 -1
- package/docs/types/openapi.OpenapiPrimitiveBaseTypes.html +1 -1
- package/docs/types/openapi.OpenapiPrimitiveTypes.html +1 -1
- package/docs/types/openapi.OpenapiSchemaArray.html +1 -1
- package/docs/types/openapi.OpenapiSchemaArrayShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaBase.html +1 -1
- package/docs/types/openapi.OpenapiSchemaBody.html +1 -1
- package/docs/types/openapi.OpenapiSchemaBodyShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaCommonFields.html +1 -1
- package/docs/types/openapi.OpenapiSchemaExpressionAllOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaExpressionAnyOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaExpressionOneOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaExpressionRef.html +2 -2
- package/docs/types/openapi.OpenapiSchemaExpressionRefSchemaShorthand.html +2 -2
- package/docs/types/openapi.OpenapiSchemaInteger.html +1 -1
- package/docs/types/openapi.OpenapiSchemaNull.html +2 -2
- package/docs/types/openapi.OpenapiSchemaNumber.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObject.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAllOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAllOfShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAnyOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAnyOfShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectBase.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectBaseShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectOneOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectOneOfShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaPrimitiveGeneric.html +1 -1
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionAllOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionAnyOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionOneOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializableRef.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializerRef.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
- package/docs/types/openapi.OpenapiSchemaString.html +1 -1
- package/docs/types/openapi.OpenapiShorthandAllTypes.html +1 -1
- package/docs/types/openapi.OpenapiShorthandPrimitiveBaseTypes.html +1 -1
- package/docs/types/openapi.OpenapiShorthandPrimitiveTypes.html +1 -1
- package/docs/types/openapi.OpenapiTypeField.html +1 -1
- package/docs/types/system.DreamAppAllowedPackageManagersEnum.html +1 -1
- package/docs/types/types.CalendarDateDurationUnit.html +1 -1
- package/docs/types/types.CalendarDateObject.html +1 -1
- package/docs/types/types.Camelized.html +1 -1
- package/docs/types/types.ClockTimeObject.html +1 -1
- package/docs/types/types.DbConnectionType.html +1 -1
- package/docs/types/types.DbTypes.html +1 -1
- package/docs/types/types.DreamAssociationMetadata.html +1 -1
- package/docs/types/types.DreamAttributes.html +1 -1
- package/docs/types/types.DreamClassAssociationAndStatement.html +1 -1
- package/docs/types/types.DreamClassColumn.html +1 -1
- package/docs/types/types.DreamColumn.html +1 -1
- package/docs/types/types.DreamColumnNames.html +1 -1
- package/docs/types/types.DreamLogLevel.html +1 -1
- package/docs/types/types.DreamLogger.html +2 -2
- package/docs/types/types.DreamModelSerializerType.html +1 -1
- package/docs/types/types.DreamOrViewModelClassSerializerKey.html +1 -1
- package/docs/types/types.DreamOrViewModelSerializerKey.html +1 -1
- package/docs/types/types.DreamParamSafeAttributes.html +1 -1
- package/docs/types/types.DreamParamSafeColumnNames.html +1 -1
- package/docs/types/types.DreamSerializable.html +1 -1
- package/docs/types/types.DreamSerializableArray.html +1 -1
- package/docs/types/types.DreamSerializerKey.html +1 -1
- package/docs/types/types.DreamSerializers.html +1 -1
- package/docs/types/types.DreamVirtualColumns.html +1 -1
- package/docs/types/types.DurationUnit.html +1 -1
- package/docs/types/types.EncryptAlgorithm.html +1 -1
- package/docs/types/types.HasManyStatement.html +1 -1
- package/docs/types/types.HasOneStatement.html +1 -1
- package/docs/types/types.Hyphenized.html +1 -1
- package/docs/types/types.Pascalized.html +1 -1
- package/docs/types/types.PrimaryKeyType.html +1 -1
- package/docs/types/types.RoundingPrecision.html +1 -1
- package/docs/types/types.SerializerCasing.html +1 -1
- package/docs/types/types.SimpleObjectSerializerType.html +1 -1
- package/docs/types/types.Snakeified.html +1 -1
- package/docs/types/types.StrictInterface.html +1 -1
- package/docs/types/types.UpdateableAssociationProperties.html +1 -1
- package/docs/types/types.UpdateableProperties.html +1 -1
- package/docs/types/types.ValidationType.html +1 -1
- package/docs/types/types.ViewModel.html +2 -2
- package/docs/types/types.ViewModelClass.html +1 -1
- package/docs/types/types.WeekdayName.html +1 -1
- package/docs/types/types.WhereStatementForDream.html +1 -1
- package/docs/types/types.WhereStatementForDreamClass.html +1 -1
- package/docs/variables/index.DreamConst.html +1 -1
- package/docs/variables/index.ops.html +1 -1
- package/docs/variables/openapi.openapiPrimitiveTypes.html +1 -1
- package/docs/variables/openapi.openapiShorthandPrimitiveTypes.html +1 -1
- package/docs/variables/system.DreamAppAllowedPackageManagersEnumValues.html +1 -1
- package/docs/variables/system.primaryKeyTypes.html +1 -1
- package/package.json +1 -1
- package/dist/cjs/src/dream/internal/extractNestedPaths.js +0 -34
- package/dist/esm/src/dream/internal/extractNestedPaths.js +0 -34
- package/dist/types/src/dream/internal/extractNestedPaths.d.ts +0 -21
|
@@ -56,6 +56,10 @@ export default class Decorators<TD extends typeof Dream, T extends Dream = Insta
|
|
|
56
56
|
* @returns A Scope decorator
|
|
57
57
|
*/
|
|
58
58
|
Scope(this: Decorators<TD>, opts?: {
|
|
59
|
+
/**
|
|
60
|
+
* If `true`, this scope will be applied automatically to all queries involving this model.
|
|
61
|
+
* Defaults to `false`.
|
|
62
|
+
*/
|
|
59
63
|
default?: boolean;
|
|
60
64
|
}): any;
|
|
61
65
|
/**
|
|
@@ -116,10 +120,14 @@ export default class Decorators<TD extends typeof Dream, T extends Dream = Insta
|
|
|
116
120
|
* @returns A Validates decorator
|
|
117
121
|
*/
|
|
118
122
|
Validates<VT extends ValidationType, VTArgs extends VT extends 'numericality' ? {
|
|
123
|
+
/** The minimum allowed value (inclusive). */
|
|
119
124
|
min?: number;
|
|
125
|
+
/** The maximum allowed value (inclusive). */
|
|
120
126
|
max?: number;
|
|
121
127
|
} : VT extends 'length' ? {
|
|
128
|
+
/** The minimum allowed length (inclusive). */
|
|
122
129
|
min: number;
|
|
130
|
+
/** The maximum allowed length (inclusive). */
|
|
123
131
|
max?: number;
|
|
124
132
|
} : VT extends 'contains' ? string | RegExp : never>(this: Decorators<TD>, type: VT, args?: VTArgs): any;
|
|
125
133
|
/**
|
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import Dream from '../../Dream.js';
|
|
2
2
|
export declare const STI_SCOPE_NAME = "dream:STI";
|
|
3
|
-
export default function STI(dreamClass: typeof Dream
|
|
4
|
-
value?: string;
|
|
5
|
-
}): ClassDecorator;
|
|
3
|
+
export default function STI(dreamClass: typeof Dream): ClassDecorator;
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
export default function Sortable(opts?: SortableOpts): any;
|
|
2
2
|
interface SortableOpts {
|
|
3
|
+
/**
|
|
4
|
+
* A column name or array of column names that define the scope within which
|
|
5
|
+
* position values are unique. Records are sorted independently within each scope.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* @deco.Sortable({ scope: 'species' })
|
|
9
|
+
* public positionWithinSpecies: number
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
3
12
|
scope?: string | string[];
|
|
4
13
|
}
|
|
5
14
|
export interface SortableFieldConfig {
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import Dream from '../../../Dream.js';
|
|
2
2
|
import { ValidationType } from '../../../types/validation.js';
|
|
3
3
|
export default function Validates<VT extends ValidationType, VTArgs extends VT extends 'numericality' ? {
|
|
4
|
+
/** The minimum allowed value (inclusive). */
|
|
4
5
|
min?: number;
|
|
6
|
+
/** The maximum allowed value (inclusive). */
|
|
5
7
|
max?: number;
|
|
6
8
|
} : VT extends 'length' ? {
|
|
9
|
+
/** The minimum allowed length (inclusive). */
|
|
7
10
|
min: number;
|
|
11
|
+
/** The maximum allowed length (inclusive). */
|
|
8
12
|
max?: number;
|
|
9
13
|
} : VT extends 'contains' ? string | RegExp : never>(type: VT, args?: VTArgs): any;
|
|
10
14
|
export declare function validatesImplementation<VT extends ValidationType, VTArgs extends VT extends 'numericality' ? {
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import Dream from '../../Dream.js';
|
|
2
2
|
export default function Scope(opts?: {
|
|
3
|
+
/**
|
|
4
|
+
* If `true`, this scope will be applied automatically to all queries involving this model.
|
|
5
|
+
* Defaults to `false`.
|
|
6
|
+
*/
|
|
3
7
|
default?: boolean;
|
|
4
8
|
}): any;
|
|
5
9
|
export declare function scopeImplementation(t: typeof Dream, key: string, opts?: {
|
|
@@ -8,13 +8,16 @@ export default class LeftJoinLoadBuilder<DreamInstance extends Dream> {
|
|
|
8
8
|
private dream;
|
|
9
9
|
private query;
|
|
10
10
|
/**
|
|
11
|
-
* An intermediate
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* An intermediate builder for loading associations onto a Dream model
|
|
12
|
+
* via a single left-join SQL query. Accessed via `#leftJoinLoad`.
|
|
13
|
+
*
|
|
14
|
+
* **Note:** The LeftJoinLoadBuilder works on a clone of the original model.
|
|
15
|
+
* Call `.execute()` to get the clone with associations loaded.
|
|
14
16
|
*
|
|
15
17
|
* ```ts
|
|
16
18
|
* const user = await User.firstOrFail()
|
|
17
|
-
* await user.
|
|
19
|
+
* const loaded = await user.leftJoinLoad('settings').execute()
|
|
20
|
+
* loaded.settings // association is loaded on the returned clone
|
|
18
21
|
* ```
|
|
19
22
|
*/
|
|
20
23
|
constructor(dream: Dream, dreamTransaction?: (DreamTransaction<any> | null) | undefined);
|
|
@@ -32,17 +35,20 @@ export default class LeftJoinLoadBuilder<DreamInstance extends Dream> {
|
|
|
32
35
|
*/
|
|
33
36
|
leftJoinLoad<I extends LeftJoinLoadBuilder<DreamInstance>, DB extends DreamInstance['DB'], TableName extends DreamInstance['table'], Schema extends DreamInstance['schema'], const Arr extends readonly unknown[], const LastArg extends VariadicLeftJoinLoadArgs<DreamInstance, DB, Schema, TableName, Arr>>(this: I, ...args: [...Arr, LastArg]): I;
|
|
34
37
|
/**
|
|
35
|
-
*
|
|
36
|
-
* all associations
|
|
37
|
-
* instances.
|
|
38
|
+
* Executes the left-join load query, returning a **clone** of the original model
|
|
39
|
+
* with all requested associations loaded. The original instance is not modified.
|
|
38
40
|
*
|
|
39
41
|
* ```ts
|
|
40
42
|
* const user = await User.firstOrFail()
|
|
41
|
-
* await user
|
|
42
|
-
* .
|
|
43
|
-
* .
|
|
43
|
+
* const loaded = await user
|
|
44
|
+
* .leftJoinLoad('settings')
|
|
45
|
+
* .leftJoinLoad('posts', 'comments', 'replies')
|
|
44
46
|
* .execute()
|
|
47
|
+
*
|
|
48
|
+
* loaded.settings // works — associations are on the returned clone
|
|
45
49
|
* ```
|
|
50
|
+
*
|
|
51
|
+
* @returns A clone of the Dream instance with all requested associations loaded
|
|
46
52
|
*/
|
|
47
53
|
execute(): Promise<DreamInstance>;
|
|
48
54
|
private associationToPreloadedDreamsAndWhatTheyPointTo;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Dream from '../Dream.js';
|
|
2
2
|
import { PassthroughOnClause } from '../types/associations/shared.js';
|
|
3
|
-
import {
|
|
3
|
+
import { DbConnectionType } from '../types/db.js';
|
|
4
|
+
import { AllDefaultScopeNames, DreamSerializerKey, PassthroughColumnNames } from '../types/dream.js';
|
|
4
5
|
import { LoadForModifierFn } from '../types/query.js';
|
|
5
6
|
import { VariadicLoadArgs } from '../types/variadic.js';
|
|
6
7
|
import DreamTransaction from './DreamTransaction.js';
|
|
@@ -9,17 +10,66 @@ export default class LoadBuilder<DreamInstance extends Dream> {
|
|
|
9
10
|
private dream;
|
|
10
11
|
private query;
|
|
11
12
|
/**
|
|
12
|
-
* An intermediate
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* An intermediate builder for loading associations onto a Dream model.
|
|
14
|
+
* Accessed via the `#load` method on a Dream instance.
|
|
15
|
+
*
|
|
16
|
+
* **Note:** The LoadBuilder works on a clone of the original model.
|
|
17
|
+
* Call `.execute()` to get the clone with associations loaded.
|
|
15
18
|
*
|
|
16
19
|
* ```ts
|
|
17
20
|
* const user = await User.firstOrFail()
|
|
18
|
-
* await user.load('settings').execute()
|
|
21
|
+
* const loaded = await user.load('settings').execute()
|
|
22
|
+
* loaded.settings // association is loaded on the returned clone
|
|
19
23
|
* ```
|
|
20
24
|
*/
|
|
21
25
|
constructor(dream: Dream, dreamTransaction?: (DreamTransaction<any> | null) | undefined);
|
|
22
26
|
passthrough<I extends LoadBuilder<DreamInstance>, PassthroughColumns extends PassthroughColumnNames<DreamInstance>>(this: I, passthroughWhereStatement: PassthroughOnClause<PassthroughColumns>): I;
|
|
27
|
+
/**
|
|
28
|
+
* Prevents a specific default scope from applying when
|
|
29
|
+
* loading associations
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* const user = await User.firstOrFail()
|
|
33
|
+
* const loaded = await user
|
|
34
|
+
* .load('posts')
|
|
35
|
+
* .removeDefaultScope('dream:SoftDelete')
|
|
36
|
+
* .execute()
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @param scopeName - The default scope to bypass
|
|
40
|
+
* @returns The LoadBuilder instance for chaining
|
|
41
|
+
*/
|
|
42
|
+
removeDefaultScope<I extends LoadBuilder<DreamInstance>>(this: I, scopeName: AllDefaultScopeNames<DreamInstance>): I;
|
|
43
|
+
/**
|
|
44
|
+
* Prevents all default scopes from applying when
|
|
45
|
+
* loading associations
|
|
46
|
+
*
|
|
47
|
+
* ```ts
|
|
48
|
+
* const user = await User.firstOrFail()
|
|
49
|
+
* const loaded = await user
|
|
50
|
+
* .load('posts')
|
|
51
|
+
* .removeAllDefaultScopes()
|
|
52
|
+
* .execute()
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @returns The LoadBuilder instance for chaining
|
|
56
|
+
*/
|
|
57
|
+
removeAllDefaultScopes<I extends LoadBuilder<DreamInstance>>(this: I): I;
|
|
58
|
+
/**
|
|
59
|
+
* Sets the database connection to use when loading associations
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* const user = await User.firstOrFail()
|
|
63
|
+
* const loaded = await user
|
|
64
|
+
* .load('posts')
|
|
65
|
+
* .connection('replica')
|
|
66
|
+
* .execute()
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @param connection - The connection type ('primary' or 'replica')
|
|
70
|
+
* @returns The LoadBuilder instance for chaining
|
|
71
|
+
*/
|
|
72
|
+
connection<I extends LoadBuilder<DreamInstance>>(this: I, connection: DbConnectionType): I;
|
|
23
73
|
/**
|
|
24
74
|
* Attaches a load statement to the load builder
|
|
25
75
|
*
|
|
@@ -82,19 +132,22 @@ export default class LoadBuilder<DreamInstance extends Dream> {
|
|
|
82
132
|
*/
|
|
83
133
|
loadFor<I extends LoadBuilder<DreamInstance>, SerializerKey extends DreamSerializerKey<DreamInstance>>(this: I, serializerKey: SerializerKey, modifierFn?: LoadForModifierFn): I;
|
|
84
134
|
/**
|
|
85
|
-
* Executes
|
|
86
|
-
*
|
|
87
|
-
*
|
|
135
|
+
* Executes the load query, binding all associations to a **clone** of the
|
|
136
|
+
* original model instance. The original instance is not modified.
|
|
137
|
+
*
|
|
138
|
+
* You must use the returned value to access the loaded associations:
|
|
88
139
|
*
|
|
89
140
|
* ```ts
|
|
90
141
|
* const user = await User.firstOrFail()
|
|
91
|
-
* await user
|
|
142
|
+
* const loaded = await user
|
|
92
143
|
* .load('settings')
|
|
93
144
|
* .load('posts', 'comments', 'replies', ['image', 'localizedText'])
|
|
94
145
|
* .execute()
|
|
146
|
+
*
|
|
147
|
+
* loaded.settings // works — associations are on the returned clone
|
|
95
148
|
* ```
|
|
96
149
|
*
|
|
97
|
-
* @returns
|
|
150
|
+
* @returns A clone of the Dream instance with all requested associations loaded
|
|
98
151
|
*/
|
|
99
152
|
execute(): Promise<DreamInstance>;
|
|
100
153
|
}
|
|
@@ -1146,7 +1146,7 @@ export default class Query<DreamInstance extends Dream, QueryTypeOpts extends Re
|
|
|
1146
1146
|
* Updates all records matching the Query
|
|
1147
1147
|
*
|
|
1148
1148
|
* ```ts
|
|
1149
|
-
* await User.where({ email: ops.ilike('%burpcollaborator%') }).
|
|
1149
|
+
* await User.where({ email: ops.ilike('%burpcollaborator%') }).update({ email: null })
|
|
1150
1150
|
* // 12
|
|
1151
1151
|
* ```
|
|
1152
1152
|
* @param attributes - The attributes used to update the records
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export declare const primaryKeyTypes: readonly ["uuid7", "uuid4", "bigserial", "bigint", "integer"];
|
|
2
2
|
export declare const TRIGRAM_OPERATORS: readonly ["%", "<%", "<<%"];
|
|
3
|
+
export declare const RECURSIVE_SERIALIZATION_MAX_REPEATS = 4;
|
|
4
|
+
export declare const RECURSIVE_DESTROY_PRELOAD_MAX_REPEATS = 4;
|
|
3
5
|
declare class RequiredAttribute {
|
|
4
6
|
constructor();
|
|
5
7
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DreamClassAndAssociationNameTuple } from '../../types/recursiveSerialization.js';
|
|
2
|
+
export interface AssociationPathEdge<NodeType> {
|
|
3
|
+
nextNode: NodeType | null;
|
|
4
|
+
tuple: DreamClassAndAssociationNameTuple;
|
|
5
|
+
}
|
|
6
|
+
export default function buildAssociationPaths<NodeType>(rootNode: NodeType, opts: BuildAssociationPathsOptions<NodeType>): DreamClassAndAssociationNameTuple[][];
|
|
7
|
+
type BuildAssociationPathsOptions<NodeType> = {
|
|
8
|
+
getKey: (node: NodeType) => string;
|
|
9
|
+
getEdges: (node: NodeType) => AssociationPathEdge<NodeType>[];
|
|
10
|
+
maxRepeats: number;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Dream from '../../Dream.js';
|
|
2
|
+
import { DreamClassAndAssociationNameTuple } from '../../types/recursiveSerialization.js';
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*
|
|
6
|
+
* Recursively walks `dependent: 'destroy'` associations starting from the given
|
|
7
|
+
* Dream class, producing an array of preload paths. Each path is an array of
|
|
8
|
+
* [DreamClass, associationName] tuples representing a chain from root to leaf.
|
|
9
|
+
*
|
|
10
|
+
* Allows the same Dream class to appear up to MAX_REPEATS times in a single
|
|
11
|
+
* path to support tree structures (e.g. a Category with `dependent: 'destroy'`
|
|
12
|
+
* on its children, which are also Categories).
|
|
13
|
+
*
|
|
14
|
+
* Used to build a preload tree so that all records in the cascade can be loaded
|
|
15
|
+
* upfront, eliminating N+1 queries during destroy.
|
|
16
|
+
*/
|
|
17
|
+
export default function buildDependentDestroyPreloadPaths(dreamClass: typeof Dream): DreamClassAndAssociationNameTuple[][];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LoadForModifierFn } from '../../types/query.js';
|
|
2
|
-
import { DreamClassAndAssociationNameTuple } from '
|
|
2
|
+
import { DreamClassAndAssociationNameTuple } from '../../types/recursiveSerialization.js';
|
|
3
3
|
export default function convertDreamClassAndAssociationNameTupleArrayToPreloadArgs(dreamClassAndAssociationNameTupleArray: DreamClassAndAssociationNameTuple[], modifierFn?: LoadForModifierFn, counter?: {
|
|
4
4
|
count: number;
|
|
5
5
|
}): (string | {
|
|
@@ -5,6 +5,10 @@ import { ReallyDestroyOptions } from './destroyDream.js';
|
|
|
5
5
|
* @internal
|
|
6
6
|
*
|
|
7
7
|
* Destroys all HasOne/HasMany associations on this
|
|
8
|
-
* dream that are marked as `dependent: 'destroy'
|
|
8
|
+
* dream that are marked as `dependent: 'destroy'`.
|
|
9
|
+
*
|
|
10
|
+
* Expects associations to be preloaded onto the dream instance
|
|
11
|
+
* via `loadDependentDestroyTree`. Iterates loaded associations
|
|
12
|
+
* directly instead of querying the database.
|
|
9
13
|
*/
|
|
10
14
|
export default function destroyAssociatedRecords<I extends Dream>(dream: I, txn: DreamTransaction<I>, options: ReallyDestroyOptions<I>): Promise<void>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Dream from '../../Dream.js';
|
|
2
|
+
import { AllDefaultScopeNames } from '../../types/dream.js';
|
|
3
|
+
import DreamTransaction from '../DreamTransaction.js';
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*
|
|
7
|
+
* Loads all `dependent: 'destroy'` associations onto the dream instance
|
|
8
|
+
* upfront, eliminating N+1 queries during cascade destruction.
|
|
9
|
+
*
|
|
10
|
+
* Returns a clone of the dream with all associations loaded.
|
|
11
|
+
* If there are no dependent-destroy associations, returns the original dream.
|
|
12
|
+
*/
|
|
13
|
+
export default function loadDependentDestroyTree<I extends Dream>(dream: I, txn: DreamTransaction<I>, { reallyDestroy, bypassAllDefaultScopes, defaultScopesToBypass, }: {
|
|
14
|
+
reallyDestroy: boolean;
|
|
15
|
+
bypassAllDefaultScopes: boolean;
|
|
16
|
+
defaultScopesToBypass: AllDefaultScopeNames<I>[];
|
|
17
|
+
}): Promise<I>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Dream from '../../Dream.js';
|
|
2
|
+
import { DreamModelSerializerType, SimpleObjectSerializerType } from '../../types/serializer.js';
|
|
3
|
+
export interface ResolvedSerializerAssociationEdge {
|
|
4
|
+
associationAs: string;
|
|
5
|
+
sourceDreamClass: typeof Dream;
|
|
6
|
+
type: 'rendersOne' | 'rendersMany' | 'delegatedAttribute';
|
|
7
|
+
serializerAssociationName: string;
|
|
8
|
+
targets: {
|
|
9
|
+
dreamClass: typeof Dream;
|
|
10
|
+
serializer: DreamModelSerializerType | SimpleObjectSerializerType;
|
|
11
|
+
}[];
|
|
12
|
+
}
|
|
13
|
+
export default function resolveSerializerAssociationEdges(dreamClass: typeof Dream, serializer: DreamModelSerializerType | SimpleObjectSerializerType): ResolvedSerializerAssociationEdge[];
|