@rvoh/dream 2.18.1 → 2.19.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 +103 -0
- package/dist/cjs/src/db/DreamDbConnection.js +6 -0
- package/dist/cjs/src/decorators/class/SoftDelete.js +12 -0
- package/dist/cjs/src/dream/DreamClassTransactionBuilder.js +113 -0
- package/dist/cjs/src/dream/Query.js +137 -0
- package/dist/cjs/src/dream/QueryDriver/Base.js +84 -0
- package/dist/cjs/src/dream/QueryDriver/Kysely.js +358 -67
- package/dist/cjs/src/errors/CannotNamespaceAssociationFilterToAnotherTable.js +27 -0
- package/dist/cjs/src/helpers/cli/generateMigrationContent.js +21 -13
- package/dist/esm/src/Dream.js +103 -0
- package/dist/esm/src/db/DreamDbConnection.js +6 -0
- package/dist/esm/src/decorators/class/SoftDelete.js +12 -0
- package/dist/esm/src/dream/DreamClassTransactionBuilder.js +113 -0
- package/dist/esm/src/dream/Query.js +137 -0
- package/dist/esm/src/dream/QueryDriver/Base.js +84 -0
- package/dist/esm/src/dream/QueryDriver/Kysely.js +358 -67
- package/dist/esm/src/errors/CannotNamespaceAssociationFilterToAnotherTable.js +27 -0
- package/dist/esm/src/helpers/cli/generateMigrationContent.js +21 -13
- package/dist/types/src/Dream.d.ts +97 -4
- package/dist/types/src/decorators/class/SoftDelete.d.ts +12 -0
- package/dist/types/src/dream/DreamClassTransactionBuilder.d.ts +103 -0
- package/dist/types/src/dream/Query.d.ts +127 -0
- package/dist/types/src/dream/QueryDriver/Base.d.ts +69 -0
- package/dist/types/src/dream/QueryDriver/Kysely.d.ts +166 -8
- package/dist/types/src/errors/CannotNamespaceAssociationFilterToAnotherTable.d.ts +8 -0
- package/dist/types/src/types/associations/shared.d.ts +4 -1
- package/dist/types/src/types/dream.d.ts +17 -0
- package/dist/types/src/types/types/associations/shared.ts +10 -1
- package/dist/types/src/types/types/dream.ts +53 -0
- package/dist/types/src/types/types/variadic.ts +179 -140
- package/dist/types/src/types/variadic.d.ts +15 -10
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/db.DreamMigrationHelpers.html +11 -11
- package/docs/classes/db.KyselyQueryDriver.html +78 -34
- package/docs/classes/db.PostgresQueryDriver.html +79 -35
- package/docs/classes/db.QueryDriverBase.html +77 -33
- 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.DecryptionError.html +2 -2
- package/docs/classes/errors.DecryptionParseError.html +2 -2
- package/docs/classes/errors.DecryptionRotationError.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 +19 -19
- package/docs/classes/index.Dream.html +182 -119
- package/docs/classes/index.DreamApp.html +10 -10
- package/docs/classes/index.DreamTransaction.html +2 -2
- package/docs/classes/index.Env.html +2 -2
- package/docs/classes/index.Query.html +144 -57
- package/docs/classes/system.CliFileWriter.html +4 -4
- package/docs/classes/system.DreamBin.html +2 -2
- package/docs/classes/system.DreamCLI.html +7 -7
- package/docs/classes/system.DreamImporter.html +2 -2
- package/docs/classes/system.DreamLogos.html +2 -2
- package/docs/classes/system.DreamSerializerBuilder.html +11 -11
- package/docs/classes/system.ObjectSerializerBuilder.html +8 -8
- package/docs/classes/system.PathHelpers.html +3 -3
- package/docs/classes/utils.Encrypt.html +3 -3
- 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 +12 -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/hierarchy.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.DreamDbConfig.html +5 -5
- 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 +3 -3
- package/dist/cjs/src/dream/internal/associations/throughAssociationHasOptionsBesidesThroughAndSource.js +0 -11
- package/dist/cjs/src/errors/associations/ThroughAssociationConditionsIncompatibleWithThroughAssociationSource.js +0 -17
- package/dist/esm/src/dream/internal/associations/throughAssociationHasOptionsBesidesThroughAndSource.js +0 -11
- package/dist/esm/src/errors/associations/ThroughAssociationConditionsIncompatibleWithThroughAssociationSource.js +0 -17
- package/dist/types/src/dream/internal/associations/throughAssociationHasOptionsBesidesThroughAndSource.d.ts +0 -13
- package/dist/types/src/errors/associations/ThroughAssociationConditionsIncompatibleWithThroughAssociationSource.d.ts +0 -12
|
@@ -8,18 +8,23 @@ import {
|
|
|
8
8
|
AssociationTableNamesForAssociation,
|
|
9
9
|
DreamAssociationNameToAssociatedModel,
|
|
10
10
|
IsNonOptionalBelongsToAssociation,
|
|
11
|
+
IsPolymorphicBelongsToAssociation,
|
|
11
12
|
JoinAndStatements,
|
|
12
13
|
MAX_VARIADIC_DEPTH,
|
|
14
|
+
PolymorphicBelongsToAssociationNames,
|
|
13
15
|
RequiredOnClauseKeys,
|
|
14
16
|
} from './dream.js'
|
|
15
17
|
import { Inc, ReadonlyTail } from './utils.js'
|
|
16
18
|
|
|
17
19
|
type VALID = 'valid'
|
|
18
20
|
type INVALID = 'invalid'
|
|
21
|
+
type INVALID_NON_TERMINAL_ARRAY = 'invalid_non_terminal_array'
|
|
22
|
+
type INVALID_NAMESPACE_REUSE = 'invalid_namespace_reuse'
|
|
23
|
+
type INVALID_POLYMORPHIC_BELONGS_TO_JOIN = 'invalid_polymorphic_belongs_to_join'
|
|
24
|
+
type INVALID_CONSTRAINT_ON_REQUIRED_BELONGS_TO = 'invalid_constraint_on_required_belongs_to'
|
|
19
25
|
type IS_ASSOCIATION_ALIAS = 'association_alias'
|
|
20
26
|
type IS_ASSOCIATION_NAME = 'association_name'
|
|
21
27
|
type IS_NOT_ASSOCIATION_NAME = 'not_association_name'
|
|
22
|
-
type IS_CROSS_POLYMORPHIC_ASSOCIATION_NAME = 'cross_polymorphic_association_name'
|
|
23
28
|
type RecursionTypes = 'load' | 'leftJoinLoad' | 'join'
|
|
24
29
|
|
|
25
30
|
/**
|
|
@@ -56,7 +61,10 @@ export type VariadicLoadArgs<
|
|
|
56
61
|
ConcreteTableName,
|
|
57
62
|
ConcreteArgs,
|
|
58
63
|
'load',
|
|
59
|
-
|
|
64
|
+
// load/preload issue a separate query per association, so reusing an
|
|
65
|
+
// association name or alias never causes a namespace collision, and no
|
|
66
|
+
// namespaces are tracked.
|
|
67
|
+
never,
|
|
60
68
|
0,
|
|
61
69
|
null,
|
|
62
70
|
never,
|
|
@@ -76,9 +84,15 @@ export type VariadicLeftJoinLoadArgs<
|
|
|
76
84
|
ConcreteArgs extends readonly unknown[],
|
|
77
85
|
//
|
|
78
86
|
SchemaAssociations = Schema[ConcreteTableName]['associations' & keyof Schema[ConcreteTableName]],
|
|
87
|
+
// joining a polymorphic BelongsTo raises CannotJoinPolymorphicBelongsToError
|
|
88
|
+
// at runtime, so exclude those association names (and their aliased forms)
|
|
89
|
+
PolymorphicBelongsToNames = PolymorphicBelongsToAssociationNames<Schema, ConcreteTableName>,
|
|
79
90
|
AllowedNextArgValues =
|
|
80
|
-
|
|
|
81
|
-
|
|
|
91
|
+
| Exclude<keyof SchemaAssociations & string, PolymorphicBelongsToNames>
|
|
92
|
+
| Exclude<
|
|
93
|
+
AliasedSchemaAssociation<Schema, ConcreteTableName>,
|
|
94
|
+
`${PolymorphicBelongsToNames & string} as ${string}`
|
|
95
|
+
>,
|
|
82
96
|
> = VariadicCheckThenRecurse<
|
|
83
97
|
I,
|
|
84
98
|
DB,
|
|
@@ -111,9 +125,15 @@ export type VariadicJoinsArgs<
|
|
|
111
125
|
ConcreteArgs extends readonly unknown[],
|
|
112
126
|
//
|
|
113
127
|
SchemaAssociations = Schema[ConcreteTableName]['associations' & keyof Schema[ConcreteTableName]],
|
|
128
|
+
// joining a polymorphic BelongsTo raises CannotJoinPolymorphicBelongsToError
|
|
129
|
+
// at runtime, so exclude those association names (and their aliased forms)
|
|
130
|
+
PolymorphicBelongsToNames = PolymorphicBelongsToAssociationNames<Schema, ConcreteTableName>,
|
|
114
131
|
AllowedNextArgValues =
|
|
115
|
-
|
|
|
116
|
-
|
|
|
132
|
+
| Exclude<keyof SchemaAssociations & string, PolymorphicBelongsToNames>
|
|
133
|
+
| Exclude<
|
|
134
|
+
AliasedSchemaAssociation<Schema, ConcreteTableName>,
|
|
135
|
+
`${PolymorphicBelongsToNames & string} as ${string}`
|
|
136
|
+
>,
|
|
117
137
|
> = VariadicCheckThenRecurse<
|
|
118
138
|
I,
|
|
119
139
|
DB,
|
|
@@ -126,7 +146,6 @@ export type VariadicJoinsArgs<
|
|
|
126
146
|
// Without camelizing, the table name of the starting model could conflict with the
|
|
127
147
|
// snake-cased version of an association name. By camelizing the table that goes
|
|
128
148
|
// into the UsedNamespaces, we prevent this from happeing at the type level.
|
|
129
|
-
// Camelized<ConcreteTableName>,
|
|
130
149
|
Camelized<ConcreteTableName>,
|
|
131
150
|
0,
|
|
132
151
|
null,
|
|
@@ -154,15 +173,48 @@ type VariadicCheckThenRecurse<
|
|
|
154
173
|
LastDream extends Dream = I,
|
|
155
174
|
//
|
|
156
175
|
SchemaAssociations = Schema[ConcreteTableName]['associations' & keyof Schema[ConcreteTableName]],
|
|
157
|
-
|
|
176
|
+
// The association names reachable at this position: when traversing through a
|
|
177
|
+
// polymorphic association, the union of association names across all of the
|
|
178
|
+
// polymorphic target tables (plus their aliased forms); otherwise, the
|
|
179
|
+
// association names on the current table.
|
|
180
|
+
AllowedNamesForNthArg = PreviousConcreteTableName extends keyof Schema
|
|
158
181
|
? AssociationNamesForAssociation<Schema, PreviousConcreteTableName, ConcreteAssociationName>
|
|
159
182
|
: keyof SchemaAssociations & string,
|
|
160
|
-
|
|
183
|
+
// The current arg with any ` as alias` suffix stripped, so aliased
|
|
184
|
+
// associations resolve to the same metadata as their unaliased counterparts.
|
|
185
|
+
UnaliasedNthArg = ConcreteArgs[0] extends `${infer AssociationName extends string} as ${string}`
|
|
186
|
+
? AssociationName
|
|
187
|
+
: ConcreteArgs[0],
|
|
188
|
+
// The namespace the current arg would claim: its alias when aliased,
|
|
189
|
+
// otherwise the association name itself.
|
|
190
|
+
NthArgumentNamespace = ConcreteArgs[0] extends `${string} as ${infer Alias extends string}`
|
|
191
|
+
? Alias
|
|
192
|
+
: ConcreteArgs[0],
|
|
193
|
+
NthArgument extends
|
|
194
|
+
| VALID
|
|
195
|
+
| INVALID
|
|
196
|
+
| INVALID_NON_TERMINAL_ARRAY
|
|
197
|
+
| INVALID_NAMESPACE_REUSE
|
|
198
|
+
| INVALID_POLYMORPHIC_BELONGS_TO_JOIN
|
|
199
|
+
| INVALID_CONSTRAINT_ON_REQUIRED_BELONGS_TO = ConcreteArgs['length'] extends 0
|
|
161
200
|
? VALID
|
|
162
|
-
: ConcreteArgs[0] extends
|
|
163
|
-
|
|
164
|
-
|
|
201
|
+
: ConcreteArgs[0] extends
|
|
202
|
+
| (keyof SchemaAssociations & string)
|
|
203
|
+
| AliasedSchemaAssociation<Schema, ConcreteTableName>
|
|
204
|
+
| AllowedNamesForNthArg
|
|
205
|
+
? RecursionType extends 'load'
|
|
165
206
|
? VALID
|
|
207
|
+
: NthArgumentNamespace extends UsedNamespaces
|
|
208
|
+
? INVALID_NAMESPACE_REUSE
|
|
209
|
+
: IsPolymorphicBelongsToAssociation<Schema, ConcreteTableName, UnaliasedNthArg> extends true
|
|
210
|
+
? INVALID_POLYMORPHIC_BELONGS_TO_JOIN
|
|
211
|
+
: VALID
|
|
212
|
+
: ConcreteArgs[0] extends readonly unknown[]
|
|
213
|
+
? // the runtime only supports an array of association names as the final
|
|
214
|
+
// argument (everything after a mid-chain array is silently dropped), so
|
|
215
|
+
// arrays are only valid in the terminal position, which is validated
|
|
216
|
+
// against AllowedNextArgValues rather than by this check
|
|
217
|
+
INVALID_NON_TERMINAL_ARRAY
|
|
166
218
|
: ConcreteArgs[0] extends JoinAndStatements<
|
|
167
219
|
LastDream,
|
|
168
220
|
DB,
|
|
@@ -170,37 +222,41 @@ type VariadicCheckThenRecurse<
|
|
|
170
222
|
ConcreteTableName,
|
|
171
223
|
RequiredOnClauseKeys<Schema, PreviousConcreteTableName, ConcreteAssociationName>
|
|
172
224
|
>
|
|
173
|
-
?
|
|
174
|
-
: ConcreteArgs[0] extends readonly AllowedNamesForArrayArg[]
|
|
225
|
+
? RecursionType extends 'join'
|
|
175
226
|
? VALID
|
|
176
|
-
:
|
|
177
|
-
LastDream,
|
|
178
|
-
DB,
|
|
227
|
+
: IsNonOptionalBelongsToAssociation<
|
|
179
228
|
Schema,
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
>
|
|
183
|
-
?
|
|
184
|
-
:
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
229
|
+
PreviousConcreteTableName,
|
|
230
|
+
ConcreteAssociationName
|
|
231
|
+
> extends true
|
|
232
|
+
? INVALID_CONSTRAINT_ON_REQUIRED_BELONGS_TO
|
|
233
|
+
: VALID
|
|
234
|
+
: INVALID,
|
|
235
|
+
> = NthArgument extends INVALID_NON_TERMINAL_ARRAY
|
|
236
|
+
? `an array of association names is only allowed as the final argument (argument ${Inc<Depth>})`
|
|
237
|
+
: NthArgument extends INVALID_NAMESPACE_REUSE
|
|
238
|
+
? `association name or alias already used earlier in this chain (argument ${Inc<Depth>})`
|
|
239
|
+
: NthArgument extends INVALID_POLYMORPHIC_BELONGS_TO_JOIN
|
|
240
|
+
? `cannot join a polymorphic BelongsTo association (argument ${Inc<Depth>})`
|
|
241
|
+
: NthArgument extends INVALID_CONSTRAINT_ON_REQUIRED_BELONGS_TO
|
|
242
|
+
? `${CannotConstrainRequiredBelongsTo} (argument ${Inc<Depth>})`
|
|
243
|
+
: NthArgument extends INVALID
|
|
244
|
+
? `invalid where clause in argument ${Inc<Depth>}`
|
|
245
|
+
: ConcreteArgs['length'] extends 0
|
|
246
|
+
? AssociationNamesOrOnClause
|
|
247
|
+
: VariadicRecurse<
|
|
248
|
+
I,
|
|
249
|
+
DB,
|
|
250
|
+
Schema,
|
|
251
|
+
ConcreteTableName,
|
|
252
|
+
ConcreteArgs,
|
|
253
|
+
RecursionType,
|
|
254
|
+
UsedNamespaces,
|
|
255
|
+
Depth,
|
|
256
|
+
PreviousConcreteTableName,
|
|
257
|
+
ConcreteAssociationName,
|
|
258
|
+
LastDream
|
|
259
|
+
>
|
|
204
260
|
|
|
205
261
|
export type AliasedSchemaAssociation<
|
|
206
262
|
Schema,
|
|
@@ -223,6 +279,11 @@ type VariadicRecurse<
|
|
|
223
279
|
LastDream extends Dream,
|
|
224
280
|
//
|
|
225
281
|
SchemaAssociations = Schema[ConcreteTableName]['associations' & keyof Schema[ConcreteTableName]],
|
|
282
|
+
// The current arg with any ` as alias` suffix stripped, so aliased
|
|
283
|
+
// associations resolve to the same metadata as their unaliased counterparts.
|
|
284
|
+
UnaliasedNthArg = ConcreteArgs[0] extends `${infer AssociationName extends string} as ${string}`
|
|
285
|
+
? AssociationName
|
|
286
|
+
: ConcreteArgs[0],
|
|
226
287
|
// Union of all table names reachable via the previous polymorphic association.
|
|
227
288
|
// When PreviousConcreteTableName is not a schema key (e.g. at depth 0), fall back to ConcreteTableName.
|
|
228
289
|
PolymorphicTableNamesUnion = PreviousConcreteTableName extends keyof Schema
|
|
@@ -230,8 +291,8 @@ type VariadicRecurse<
|
|
|
230
291
|
: ConcreteTableName,
|
|
231
292
|
// The specific table from the polymorphic union that owns the current arg as an association.
|
|
232
293
|
// Used when the arg is not directly on ConcreteTableName (i.e. cross-polymorphic traversal).
|
|
233
|
-
CrossPolymorphicTableForCurrentArg =
|
|
234
|
-
? TableContainingAssociationInUnion<Schema, PolymorphicTableNamesUnion,
|
|
294
|
+
CrossPolymorphicTableForCurrentArg = UnaliasedNthArg extends string
|
|
295
|
+
? TableContainingAssociationInUnion<Schema, PolymorphicTableNamesUnion, UnaliasedNthArg>
|
|
235
296
|
: never,
|
|
236
297
|
// The effective table for looking up the current arg's association:
|
|
237
298
|
// - ConcreteTableName when the arg is directly on it (normal case)
|
|
@@ -241,7 +302,7 @@ type VariadicRecurse<
|
|
|
241
302
|
// to become `never` if we used a plain conditional.
|
|
242
303
|
EffectiveConcreteTableName extends keyof Schema &
|
|
243
304
|
AssociationTableNames<DB, Schema> &
|
|
244
|
-
keyof DB =
|
|
305
|
+
keyof DB = UnaliasedNthArg extends keyof SchemaAssociations & string
|
|
245
306
|
? ConcreteTableName
|
|
246
307
|
: [CrossPolymorphicTableForCurrentArg] extends [never]
|
|
247
308
|
? ConcreteTableName
|
|
@@ -251,83 +312,45 @@ type VariadicRecurse<
|
|
|
251
312
|
// Schema associations on the effective table (may differ from SchemaAssociations when cross-polymorphic).
|
|
252
313
|
EffectiveSchemaAssociations = Schema[EffectiveConcreteTableName]['associations' &
|
|
253
314
|
keyof Schema[EffectiveConcreteTableName]],
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
: ConcreteArgs[0] extends keyof SchemaAssociations & string
|
|
263
|
-
? ConcreteArgs[0] & keyof SchemaAssociations & string
|
|
264
|
-
: ConcreteArgs[0] extends AliasedSchemaAssociation<Schema, ConcreteTableName>
|
|
265
|
-
? ConcreteArgs[0] & AliasedSchemaAssociation<Schema, ConcreteTableName>
|
|
266
|
-
: ConcreteArgs[0] extends keyof EffectiveSchemaAssociations & string
|
|
267
|
-
? ConcreteArgs[0] & keyof EffectiveSchemaAssociations & string
|
|
268
|
-
: null,
|
|
269
|
-
NextUsedNamespaces = ConcreteArgs[0] extends undefined
|
|
270
|
-
? never
|
|
271
|
-
: ConcreteArgs[0] extends null
|
|
272
|
-
? never
|
|
273
|
-
: ConcreteNthArg extends null
|
|
274
|
-
? UsedNamespaces
|
|
275
|
-
: UsedNamespaces | ConcreteNthArg,
|
|
276
|
-
//
|
|
277
|
-
CurrentArgumentType extends
|
|
278
|
-
| IS_ASSOCIATION_NAME
|
|
279
|
-
| IS_ASSOCIATION_ALIAS
|
|
280
|
-
| IS_CROSS_POLYMORPHIC_ASSOCIATION_NAME
|
|
281
|
-
| IS_NOT_ASSOCIATION_NAME = ConcreteNthArg extends null
|
|
282
|
-
? IS_NOT_ASSOCIATION_NAME
|
|
283
|
-
: ConcreteNthArg extends keyof SchemaAssociations & string
|
|
284
|
-
? IS_ASSOCIATION_NAME
|
|
285
|
-
: ConcreteNthArg extends AliasedSchemaAssociation<Schema, ConcreteTableName>
|
|
286
|
-
? IS_ASSOCIATION_ALIAS
|
|
287
|
-
: ConcreteNthArg extends keyof EffectiveSchemaAssociations & string
|
|
288
|
-
? IS_CROSS_POLYMORPHIC_ASSOCIATION_NAME
|
|
289
|
-
: IS_NOT_ASSOCIATION_NAME,
|
|
315
|
+
// True when the current arg names an association (aliased or not) on the
|
|
316
|
+
// effective table. EffectiveConcreteTableName falls back to ConcreteTableName,
|
|
317
|
+
// so this covers direct names, aliased names, cross-polymorphic names, and
|
|
318
|
+
// aliased cross-polymorphic names with a single check.
|
|
319
|
+
IsAssociationNameOrAlias extends boolean = UnaliasedNthArg extends keyof EffectiveSchemaAssociations &
|
|
320
|
+
string
|
|
321
|
+
? true
|
|
322
|
+
: false,
|
|
290
323
|
//
|
|
291
|
-
|
|
292
|
-
?
|
|
293
|
-
:
|
|
294
|
-
? ConcreteTableName
|
|
295
|
-
: CurrentArgumentType extends IS_CROSS_POLYMORPHIC_ASSOCIATION_NAME
|
|
296
|
-
? EffectiveConcreteTableName
|
|
297
|
-
: PreviousConcreteTableName,
|
|
324
|
+
NextUnaliasedAssociationName = IsAssociationNameOrAlias extends true
|
|
325
|
+
? UnaliasedNthArg & keyof EffectiveSchemaAssociations & string
|
|
326
|
+
: never,
|
|
298
327
|
//
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
:
|
|
306
|
-
|
|
307
|
-
: never,
|
|
328
|
+
// The namespace claimed by the current arg: its alias when aliased, otherwise
|
|
329
|
+
// the association name itself. Non-association args leave the namespace of the
|
|
330
|
+
// previously consumed association in place.
|
|
331
|
+
NextAliasedAssociationName = IsAssociationNameOrAlias extends true
|
|
332
|
+
? ConcreteArgs[0] extends `${string} as ${infer AssociationAlias extends string}`
|
|
333
|
+
? AssociationAlias
|
|
334
|
+
: NextUnaliasedAssociationName
|
|
335
|
+
: ConcreteAssociationName,
|
|
308
336
|
//
|
|
309
|
-
|
|
310
|
-
?
|
|
311
|
-
:
|
|
312
|
-
? ConcreteNthArg extends `${string} as ${infer AssocAlias extends string}`
|
|
313
|
-
? AssocAlias & string
|
|
314
|
-
: ConcreteAssociationName
|
|
315
|
-
: CurrentArgumentType extends IS_CROSS_POLYMORPHIC_ASSOCIATION_NAME
|
|
316
|
-
? ConcreteNthArg
|
|
317
|
-
: ConcreteAssociationName,
|
|
337
|
+
NextPreviousConcreteTableName = IsAssociationNameOrAlias extends true
|
|
338
|
+
? EffectiveConcreteTableName
|
|
339
|
+
: PreviousConcreteTableName,
|
|
318
340
|
//
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
341
|
+
// load/preload issue a separate query per association, so namespaces are not
|
|
342
|
+
// tracked for the load recursion type
|
|
343
|
+
NextUsedNamespaces = RecursionType extends 'load'
|
|
344
|
+
? never
|
|
345
|
+
: IsAssociationNameOrAlias extends true
|
|
346
|
+
? UsedNamespaces | NextAliasedAssociationName
|
|
347
|
+
: UsedNamespaces,
|
|
325
348
|
//
|
|
326
349
|
NextTableName extends keyof Schema &
|
|
327
350
|
AssociationTableNames<DB, Schema> &
|
|
328
351
|
keyof DB = IsAssociationNameOrAlias extends true
|
|
329
352
|
? AssociationTableName<Schema, EffectiveConcreteTableName, NextUnaliasedAssociationName>
|
|
330
|
-
: ConcreteTableName
|
|
353
|
+
: ConcreteTableName,
|
|
331
354
|
//
|
|
332
355
|
AllowedAssociationNames = IsAssociationNameOrAlias extends true
|
|
333
356
|
? AssociationNamesForAssociation<Schema, EffectiveConcreteTableName, NextUnaliasedAssociationName>
|
|
@@ -335,12 +358,6 @@ type VariadicRecurse<
|
|
|
335
358
|
? AssociationNamesForAssociation<Schema, PreviousConcreteTableName, ConcreteAssociationName>
|
|
336
359
|
: AssociationNamesForTable<Schema, ConcreteTableName>, // fall back to association names for table for root only
|
|
337
360
|
//
|
|
338
|
-
AssociationTableOrConcreteTable extends keyof Schema &
|
|
339
|
-
AssociationTableNames<DB, Schema> &
|
|
340
|
-
keyof DB = IsAssociationNameOrAlias extends true
|
|
341
|
-
? AssociationTableName<Schema, EffectiveConcreteTableName, NextUnaliasedAssociationName>
|
|
342
|
-
: ConcreteTableName,
|
|
343
|
-
//
|
|
344
361
|
CurrentRequiredOnClauseKeys = IsAssociationNameOrAlias extends true
|
|
345
362
|
? RequiredOnClauseKeys<Schema, EffectiveConcreteTableName, NextUnaliasedAssociationName>
|
|
346
363
|
: RequiredOnClauseKeys<Schema, PreviousConcreteTableName, ConcreteAssociationName>,
|
|
@@ -353,34 +370,64 @@ type VariadicRecurse<
|
|
|
353
370
|
? IsNonOptionalBelongsToAssociation<Schema, EffectiveConcreteTableName, NextUnaliasedAssociationName>
|
|
354
371
|
: IsNonOptionalBelongsToAssociation<Schema, PreviousConcreteTableName, ConcreteAssociationName>,
|
|
355
372
|
//
|
|
373
|
+
// The Dream model reached after consuming the current arg. Distributes over
|
|
374
|
+
// LastDream so that traversing through a polymorphic association resolves to
|
|
375
|
+
// the specific polymorphic target that owns the association, and uses the
|
|
376
|
+
// unaliased association name so that aliased traversal advances the model the
|
|
377
|
+
// same way unaliased traversal does. Falls back to LastDream for
|
|
378
|
+
// non-association args (e.g. and-clauses), which do not advance the chain.
|
|
379
|
+
NextDreamCandidate = IsAssociationNameOrAlias extends true
|
|
380
|
+
? LastDream extends Dream
|
|
381
|
+
? NextUnaliasedAssociationName extends keyof LastDream
|
|
382
|
+
? DreamAssociationNameToAssociatedModel<LastDream, NextUnaliasedAssociationName & keyof LastDream>
|
|
383
|
+
: never
|
|
384
|
+
: never
|
|
385
|
+
: LastDream,
|
|
386
|
+
NextDream extends Dream = [NextDreamCandidate] extends [never]
|
|
387
|
+
? LastDream
|
|
388
|
+
: NextDreamCandidate extends Dream
|
|
389
|
+
? NextDreamCandidate
|
|
390
|
+
: LastDream,
|
|
391
|
+
//
|
|
392
|
+
// The join recursion types exclude polymorphic BelongsTo association names
|
|
393
|
+
// (and their aliased forms), since joining a polymorphic BelongsTo raises
|
|
394
|
+
// CannotJoinPolymorphicBelongsToError at runtime.
|
|
395
|
+
NextPolymorphicBelongsToNames = RecursionType extends 'load'
|
|
396
|
+
? never
|
|
397
|
+
: PolymorphicBelongsToAssociationNames<Schema, NextTableName>,
|
|
398
|
+
JoinSafeAllowedAssociationNames = Exclude<
|
|
399
|
+
AllowedAssociationNames,
|
|
400
|
+
NextPolymorphicBelongsToNames | `${NextPolymorphicBelongsToNames & string} as ${string}`
|
|
401
|
+
>,
|
|
402
|
+
//
|
|
356
403
|
AllowedNextArgValues = RecursionType extends 'load'
|
|
357
404
|
? AllowedNextArgValuesForLoad<
|
|
358
|
-
|
|
405
|
+
NextDream,
|
|
359
406
|
DB,
|
|
360
407
|
Schema,
|
|
361
408
|
AllowedAssociationNames,
|
|
362
|
-
|
|
409
|
+
NextTableName,
|
|
363
410
|
CurrentRequiredOnClauseKeys,
|
|
364
411
|
CurrentAssociationIsNonOptionalBelongsTo
|
|
365
412
|
>
|
|
366
413
|
: RecursionType extends 'leftJoinLoad'
|
|
367
414
|
? AllowedNextArgValuesForLeftJoinLoad<
|
|
368
|
-
|
|
415
|
+
NextDream,
|
|
369
416
|
DB,
|
|
370
417
|
Schema,
|
|
371
|
-
|
|
372
|
-
|
|
418
|
+
JoinSafeAllowedAssociationNames,
|
|
419
|
+
NextTableName,
|
|
373
420
|
CurrentRequiredOnClauseKeys,
|
|
374
421
|
NextUsedNamespaces,
|
|
375
422
|
CurrentAssociationIsNonOptionalBelongsTo
|
|
376
423
|
>
|
|
377
424
|
: RecursionType extends 'join'
|
|
378
425
|
? AllowedNextArgValuesForJoin<
|
|
379
|
-
|
|
426
|
+
NextDream,
|
|
380
427
|
DB,
|
|
381
428
|
Schema,
|
|
382
|
-
|
|
383
|
-
|
|
429
|
+
JoinSafeAllowedAssociationNames,
|
|
430
|
+
NextTableName,
|
|
384
431
|
CurrentRequiredOnClauseKeys,
|
|
385
432
|
NextUsedNamespaces
|
|
386
433
|
>
|
|
@@ -397,11 +444,13 @@ type VariadicRecurse<
|
|
|
397
444
|
NextUsedNamespaces,
|
|
398
445
|
Inc<Depth>,
|
|
399
446
|
NextPreviousConcreteTableName,
|
|
400
|
-
|
|
447
|
+
// the real (unaliased) association name: downstream lookups
|
|
448
|
+
// (RequiredOnClauseKeys, IsNonOptionalBelongsToAssociation,
|
|
449
|
+
// AssociationNamesForAssociation) index schema metadata by real name,
|
|
450
|
+
// and an alias would silently collapse them to null
|
|
451
|
+
[NextUnaliasedAssociationName] extends [never] ? ConcreteAssociationName : NextUnaliasedAssociationName,
|
|
401
452
|
AllowedNextArgValues,
|
|
402
|
-
|
|
403
|
-
? DreamAssociationNameToAssociatedModel<LastDream, ConcreteArgs[0] & keyof LastDream>
|
|
404
|
-
: LastDream
|
|
453
|
+
NextDream
|
|
405
454
|
>
|
|
406
455
|
|
|
407
456
|
/**
|
|
@@ -477,8 +526,6 @@ export type JoinedAssociationsTypeFromAssociations<
|
|
|
477
526
|
ConcreteArgs extends readonly unknown[],
|
|
478
527
|
Depth extends number = 0,
|
|
479
528
|
//
|
|
480
|
-
//
|
|
481
|
-
PreviousConcreteTableName = ConcreteTableName,
|
|
482
529
|
ConcreteAssociationName = never,
|
|
483
530
|
//
|
|
484
531
|
JoinedAssociationsType extends Readonly<JoinedAssociation[]> = Readonly<[]>,
|
|
@@ -513,12 +560,6 @@ export type JoinedAssociationsTypeFromAssociations<
|
|
|
513
560
|
? IS_ASSOCIATION_ALIAS
|
|
514
561
|
: IS_NOT_ASSOCIATION_NAME,
|
|
515
562
|
//
|
|
516
|
-
NextPreviousConcreteTableName = CurrentArgumentType extends IS_ASSOCIATION_NAME
|
|
517
|
-
? ConcreteTableName
|
|
518
|
-
: CurrentArgumentType extends IS_ASSOCIATION_ALIAS
|
|
519
|
-
? ConcreteTableName
|
|
520
|
-
: PreviousConcreteTableName,
|
|
521
|
-
//
|
|
522
563
|
NextUnaliasedAssociationName = CurrentArgumentType extends IS_ASSOCIATION_NAME
|
|
523
564
|
? ConcreteNthArg
|
|
524
565
|
: CurrentArgumentType extends IS_ASSOCIATION_ALIAS
|
|
@@ -555,7 +596,6 @@ export type JoinedAssociationsTypeFromAssociations<
|
|
|
555
596
|
NextTableName,
|
|
556
597
|
ReadonlyTail<ConcreteArgs>,
|
|
557
598
|
Inc<Depth>,
|
|
558
|
-
NextPreviousConcreteTableName,
|
|
559
599
|
NextAliasedAssociationName,
|
|
560
600
|
CurrentArgumentType extends IS_NOT_ASSOCIATION_NAME
|
|
561
601
|
? JoinedAssociationsType
|
|
@@ -572,7 +612,6 @@ export type JoinedAssociationsTypeFromAssociations<
|
|
|
572
612
|
NextTableName,
|
|
573
613
|
ReadonlyTail<ConcreteArgs>,
|
|
574
614
|
Inc<Depth>,
|
|
575
|
-
NextPreviousConcreteTableName,
|
|
576
615
|
NextAliasedAssociationName,
|
|
577
616
|
CurrentArgumentType extends IS_NOT_ASSOCIATION_NAME
|
|
578
617
|
? JoinedAssociationsType
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import Dream from '../Dream.js';
|
|
2
2
|
import { Camelized } from '../helpers/stringCasing.js';
|
|
3
3
|
import { AssociationTableNames } from './db.js';
|
|
4
|
-
import { AssociationNamesForAssociation, AssociationNamesForTable, AssociationTableName, AssociationTableNamesForAssociation, DreamAssociationNameToAssociatedModel, IsNonOptionalBelongsToAssociation, JoinAndStatements, MAX_VARIADIC_DEPTH, RequiredOnClauseKeys } from './dream.js';
|
|
4
|
+
import { AssociationNamesForAssociation, AssociationNamesForTable, AssociationTableName, AssociationTableNamesForAssociation, DreamAssociationNameToAssociatedModel, IsNonOptionalBelongsToAssociation, IsPolymorphicBelongsToAssociation, JoinAndStatements, MAX_VARIADIC_DEPTH, PolymorphicBelongsToAssociationNames, RequiredOnClauseKeys } from './dream.js';
|
|
5
5
|
import { Inc, ReadonlyTail } from './utils.js';
|
|
6
6
|
type VALID = 'valid';
|
|
7
7
|
type INVALID = 'invalid';
|
|
8
|
+
type INVALID_NON_TERMINAL_ARRAY = 'invalid_non_terminal_array';
|
|
9
|
+
type INVALID_NAMESPACE_REUSE = 'invalid_namespace_reuse';
|
|
10
|
+
type INVALID_POLYMORPHIC_BELONGS_TO_JOIN = 'invalid_polymorphic_belongs_to_join';
|
|
11
|
+
type INVALID_CONSTRAINT_ON_REQUIRED_BELONGS_TO = 'invalid_constraint_on_required_belongs_to';
|
|
8
12
|
type IS_ASSOCIATION_ALIAS = 'association_alias';
|
|
9
13
|
type IS_ASSOCIATION_NAME = 'association_name';
|
|
10
14
|
type IS_NOT_ASSOCIATION_NAME = 'not_association_name';
|
|
11
|
-
type IS_CROSS_POLYMORPHIC_ASSOCIATION_NAME = 'cross_polymorphic_association_name';
|
|
12
15
|
type RecursionTypes = 'load' | 'leftJoinLoad' | 'join';
|
|
13
16
|
/**
|
|
14
17
|
* Given a union of table names and an association name, returns the
|
|
@@ -17,13 +20,15 @@ type RecursionTypes = 'load' | 'leftJoinLoad' | 'join';
|
|
|
17
20
|
* that only exists on one of the polymorphic targets.
|
|
18
21
|
*/
|
|
19
22
|
type TableContainingAssociationInUnion<Schema, TableNamesUnion, AssociationName> = TableNamesUnion extends keyof Schema ? AssociationName extends keyof Schema[TableNamesUnion]['associations' & keyof Schema[TableNamesUnion]] ? TableNamesUnion : never : never;
|
|
20
|
-
export type VariadicLoadArgs<I extends Dream, DB, Schema, ConcreteTableName extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB, ConcreteArgs extends readonly unknown[], SchemaAssociations = Schema[ConcreteTableName]['associations' & keyof Schema[ConcreteTableName]], AllowedNextArgValues = (keyof SchemaAssociations & string) | AliasedSchemaAssociation<Schema, ConcreteTableName>> = VariadicCheckThenRecurse<I, DB, Schema, ConcreteTableName, ConcreteArgs, 'load',
|
|
21
|
-
export type VariadicLeftJoinLoadArgs<I extends Dream, DB, Schema, ConcreteTableName extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB, ConcreteArgs extends readonly unknown[], SchemaAssociations = Schema[ConcreteTableName]['associations' & keyof Schema[ConcreteTableName]], AllowedNextArgValues =
|
|
22
|
-
export type VariadicJoinsArgs<I extends Dream, DB, Schema, ConcreteTableName extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB, ConcreteArgs extends readonly unknown[], SchemaAssociations = Schema[ConcreteTableName]['associations' & keyof Schema[ConcreteTableName]], AllowedNextArgValues =
|
|
23
|
-
type VariadicCheckThenRecurse<I extends Dream, DB, Schema, ConcreteTableName extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB, ConcreteArgs extends readonly unknown[], RecursionType extends RecursionTypes, UsedNamespaces, Depth extends number, PreviousConcreteTableName, ConcreteAssociationName, AssociationNamesOrOnClause, LastDream extends Dream = I, SchemaAssociations = Schema[ConcreteTableName]['associations' & keyof Schema[ConcreteTableName]],
|
|
23
|
+
export type VariadicLoadArgs<I extends Dream, DB, Schema, ConcreteTableName extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB, ConcreteArgs extends readonly unknown[], SchemaAssociations = Schema[ConcreteTableName]['associations' & keyof Schema[ConcreteTableName]], AllowedNextArgValues = (keyof SchemaAssociations & string) | AliasedSchemaAssociation<Schema, ConcreteTableName>> = VariadicCheckThenRecurse<I, DB, Schema, ConcreteTableName, ConcreteArgs, 'load', never, 0, null, never, AllowedNextArgValues | Readonly<AllowedNextArgValues[]>>;
|
|
24
|
+
export type VariadicLeftJoinLoadArgs<I extends Dream, DB, Schema, ConcreteTableName extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB, ConcreteArgs extends readonly unknown[], SchemaAssociations = Schema[ConcreteTableName]['associations' & keyof Schema[ConcreteTableName]], PolymorphicBelongsToNames = PolymorphicBelongsToAssociationNames<Schema, ConcreteTableName>, AllowedNextArgValues = Exclude<keyof SchemaAssociations & string, PolymorphicBelongsToNames> | Exclude<AliasedSchemaAssociation<Schema, ConcreteTableName>, `${PolymorphicBelongsToNames & string} as ${string}`>> = VariadicCheckThenRecurse<I, DB, Schema, ConcreteTableName, ConcreteArgs, 'leftJoinLoad', Camelized<ConcreteTableName>, 0, null, never, AllowedNextArgValues | Readonly<AllowedNextArgValues[]>>;
|
|
25
|
+
export type VariadicJoinsArgs<I extends Dream, DB, Schema, ConcreteTableName extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB, ConcreteArgs extends readonly unknown[], SchemaAssociations = Schema[ConcreteTableName]['associations' & keyof Schema[ConcreteTableName]], PolymorphicBelongsToNames = PolymorphicBelongsToAssociationNames<Schema, ConcreteTableName>, AllowedNextArgValues = Exclude<keyof SchemaAssociations & string, PolymorphicBelongsToNames> | Exclude<AliasedSchemaAssociation<Schema, ConcreteTableName>, `${PolymorphicBelongsToNames & string} as ${string}`>> = VariadicCheckThenRecurse<I, DB, Schema, ConcreteTableName, ConcreteArgs, 'join', Camelized<ConcreteTableName>, 0, null, never, AllowedNextArgValues>;
|
|
26
|
+
type VariadicCheckThenRecurse<I extends Dream, DB, Schema, ConcreteTableName extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB, ConcreteArgs extends readonly unknown[], RecursionType extends RecursionTypes, UsedNamespaces, Depth extends number, PreviousConcreteTableName, ConcreteAssociationName, AssociationNamesOrOnClause, LastDream extends Dream = I, SchemaAssociations = Schema[ConcreteTableName]['associations' & keyof Schema[ConcreteTableName]], AllowedNamesForNthArg = PreviousConcreteTableName extends keyof Schema ? AssociationNamesForAssociation<Schema, PreviousConcreteTableName, ConcreteAssociationName> : keyof SchemaAssociations & string, UnaliasedNthArg = ConcreteArgs[0] extends `${infer AssociationName extends string} as ${string}` ? AssociationName : ConcreteArgs[0], NthArgumentNamespace = ConcreteArgs[0] extends `${string} as ${infer Alias extends string}` ? Alias : ConcreteArgs[0], NthArgument extends VALID | INVALID | INVALID_NON_TERMINAL_ARRAY | INVALID_NAMESPACE_REUSE | INVALID_POLYMORPHIC_BELONGS_TO_JOIN | INVALID_CONSTRAINT_ON_REQUIRED_BELONGS_TO = ConcreteArgs['length'] extends 0 ? VALID : ConcreteArgs[0] extends (keyof SchemaAssociations & string) | AliasedSchemaAssociation<Schema, ConcreteTableName> | AllowedNamesForNthArg ? RecursionType extends 'load' ? VALID : NthArgumentNamespace extends UsedNamespaces ? INVALID_NAMESPACE_REUSE : IsPolymorphicBelongsToAssociation<Schema, ConcreteTableName, UnaliasedNthArg> extends true ? INVALID_POLYMORPHIC_BELONGS_TO_JOIN : VALID : ConcreteArgs[0] extends readonly unknown[] ? INVALID_NON_TERMINAL_ARRAY : ConcreteArgs[0] extends JoinAndStatements<LastDream, DB, Schema, ConcreteTableName, RequiredOnClauseKeys<Schema, PreviousConcreteTableName, ConcreteAssociationName>> ? RecursionType extends 'join' ? VALID : IsNonOptionalBelongsToAssociation<Schema, PreviousConcreteTableName, ConcreteAssociationName> extends true ? INVALID_CONSTRAINT_ON_REQUIRED_BELONGS_TO : VALID : INVALID> = NthArgument extends INVALID_NON_TERMINAL_ARRAY ? `an array of association names is only allowed as the final argument (argument ${Inc<Depth>})` : NthArgument extends INVALID_NAMESPACE_REUSE ? `association name or alias already used earlier in this chain (argument ${Inc<Depth>})` : NthArgument extends INVALID_POLYMORPHIC_BELONGS_TO_JOIN ? `cannot join a polymorphic BelongsTo association (argument ${Inc<Depth>})` : NthArgument extends INVALID_CONSTRAINT_ON_REQUIRED_BELONGS_TO ? `${CannotConstrainRequiredBelongsTo} (argument ${Inc<Depth>})` : NthArgument extends INVALID ? `invalid where clause in argument ${Inc<Depth>}` : ConcreteArgs['length'] extends 0 ? AssociationNamesOrOnClause : VariadicRecurse<I, DB, Schema, ConcreteTableName, ConcreteArgs, RecursionType, UsedNamespaces, Depth, PreviousConcreteTableName, ConcreteAssociationName, LastDream>;
|
|
24
27
|
export type AliasedSchemaAssociation<Schema, ConcreteTableName extends keyof Schema, SchemaAssociations = Schema[ConcreteTableName]['associations' & keyof Schema[ConcreteTableName]]> = `${keyof SchemaAssociations & string} as ${string}`;
|
|
25
|
-
type VariadicRecurse<I extends Dream, DB, Schema, ConcreteTableName extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB, ConcreteArgs extends readonly unknown[], RecursionType extends RecursionTypes, UsedNamespaces, Depth extends number, PreviousConcreteTableName, ConcreteAssociationName, LastDream extends Dream, SchemaAssociations = Schema[ConcreteTableName]['associations' & keyof Schema[ConcreteTableName]], PolymorphicTableNamesUnion = PreviousConcreteTableName extends keyof Schema ? AssociationTableNamesForAssociation<Schema, PreviousConcreteTableName, ConcreteAssociationName> : ConcreteTableName, CrossPolymorphicTableForCurrentArg =
|
|
26
|
-
|
|
28
|
+
type VariadicRecurse<I extends Dream, DB, Schema, ConcreteTableName extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB, ConcreteArgs extends readonly unknown[], RecursionType extends RecursionTypes, UsedNamespaces, Depth extends number, PreviousConcreteTableName, ConcreteAssociationName, LastDream extends Dream, SchemaAssociations = Schema[ConcreteTableName]['associations' & keyof Schema[ConcreteTableName]], UnaliasedNthArg = ConcreteArgs[0] extends `${infer AssociationName extends string} as ${string}` ? AssociationName : ConcreteArgs[0], PolymorphicTableNamesUnion = PreviousConcreteTableName extends keyof Schema ? AssociationTableNamesForAssociation<Schema, PreviousConcreteTableName, ConcreteAssociationName> : ConcreteTableName, CrossPolymorphicTableForCurrentArg = UnaliasedNthArg extends string ? TableContainingAssociationInUnion<Schema, PolymorphicTableNamesUnion, UnaliasedNthArg> : never, EffectiveConcreteTableName extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB = UnaliasedNthArg extends keyof SchemaAssociations & string ? ConcreteTableName : [CrossPolymorphicTableForCurrentArg] extends [never] ? ConcreteTableName : CrossPolymorphicTableForCurrentArg extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB ? CrossPolymorphicTableForCurrentArg : ConcreteTableName, EffectiveSchemaAssociations = Schema[EffectiveConcreteTableName]['associations' & keyof Schema[EffectiveConcreteTableName]], IsAssociationNameOrAlias extends boolean = UnaliasedNthArg extends keyof EffectiveSchemaAssociations & string ? true : false, NextUnaliasedAssociationName = IsAssociationNameOrAlias extends true ? UnaliasedNthArg & keyof EffectiveSchemaAssociations & string : never, NextAliasedAssociationName = IsAssociationNameOrAlias extends true ? ConcreteArgs[0] extends `${string} as ${infer AssociationAlias extends string}` ? AssociationAlias : NextUnaliasedAssociationName : ConcreteAssociationName, NextPreviousConcreteTableName = IsAssociationNameOrAlias extends true ? EffectiveConcreteTableName : PreviousConcreteTableName, NextUsedNamespaces = RecursionType extends 'load' ? never : IsAssociationNameOrAlias extends true ? UsedNamespaces | NextAliasedAssociationName : UsedNamespaces, NextTableName extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB = IsAssociationNameOrAlias extends true ? AssociationTableName<Schema, EffectiveConcreteTableName, NextUnaliasedAssociationName> : ConcreteTableName, AllowedAssociationNames = IsAssociationNameOrAlias extends true ? AssociationNamesForAssociation<Schema, EffectiveConcreteTableName, NextUnaliasedAssociationName> : PreviousConcreteTableName extends keyof Schema ? AssociationNamesForAssociation<Schema, PreviousConcreteTableName, ConcreteAssociationName> : AssociationNamesForTable<Schema, ConcreteTableName>, // fall back to association names for table for root only
|
|
29
|
+
CurrentRequiredOnClauseKeys = IsAssociationNameOrAlias extends true ? RequiredOnClauseKeys<Schema, EffectiveConcreteTableName, NextUnaliasedAssociationName> : RequiredOnClauseKeys<Schema, PreviousConcreteTableName, ConcreteAssociationName>, CurrentAssociationIsNonOptionalBelongsTo = IsAssociationNameOrAlias extends true ? IsNonOptionalBelongsToAssociation<Schema, EffectiveConcreteTableName, NextUnaliasedAssociationName> : IsNonOptionalBelongsToAssociation<Schema, PreviousConcreteTableName, ConcreteAssociationName>, NextDreamCandidate = IsAssociationNameOrAlias extends true ? LastDream extends Dream ? NextUnaliasedAssociationName extends keyof LastDream ? DreamAssociationNameToAssociatedModel<LastDream, NextUnaliasedAssociationName & keyof LastDream> : never : never : LastDream, NextDream extends Dream = [NextDreamCandidate] extends [never] ? LastDream : NextDreamCandidate extends Dream ? NextDreamCandidate : LastDream, NextPolymorphicBelongsToNames = RecursionType extends 'load' ? never : PolymorphicBelongsToAssociationNames<Schema, NextTableName>, JoinSafeAllowedAssociationNames = Exclude<AllowedAssociationNames, NextPolymorphicBelongsToNames | `${NextPolymorphicBelongsToNames & string} as ${string}`>, AllowedNextArgValues = RecursionType extends 'load' ? AllowedNextArgValuesForLoad<NextDream, DB, Schema, AllowedAssociationNames, NextTableName, CurrentRequiredOnClauseKeys, CurrentAssociationIsNonOptionalBelongsTo> : RecursionType extends 'leftJoinLoad' ? AllowedNextArgValuesForLeftJoinLoad<NextDream, DB, Schema, JoinSafeAllowedAssociationNames, NextTableName, CurrentRequiredOnClauseKeys, NextUsedNamespaces, CurrentAssociationIsNonOptionalBelongsTo> : RecursionType extends 'join' ? AllowedNextArgValuesForJoin<NextDream, DB, Schema, JoinSafeAllowedAssociationNames, NextTableName, CurrentRequiredOnClauseKeys, NextUsedNamespaces> : never> = Depth extends MAX_VARIADIC_DEPTH ? never : VariadicCheckThenRecurse<I, DB, Schema, NextTableName, ReadonlyTail<ConcreteArgs>, RecursionType, NextUsedNamespaces, Inc<Depth>, NextPreviousConcreteTableName, [
|
|
30
|
+
NextUnaliasedAssociationName
|
|
31
|
+
] extends [never] ? ConcreteAssociationName : NextUnaliasedAssociationName, AllowedNextArgValues, NextDream>;
|
|
27
32
|
/**
|
|
28
33
|
* Error string surfaced when a trailing load-time constraint is applied to a
|
|
29
34
|
* non-optional BelongsTo association in a hydrating load variant.
|
|
@@ -46,13 +51,13 @@ export type QueryTypeOptions = {
|
|
|
46
51
|
allowOffset: boolean;
|
|
47
52
|
allowPaginate: boolean;
|
|
48
53
|
};
|
|
49
|
-
export type JoinedAssociationsTypeFromAssociations<DB, Schema, ConcreteTableName extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB, ConcreteArgs extends readonly unknown[], Depth extends number = 0,
|
|
54
|
+
export type JoinedAssociationsTypeFromAssociations<DB, Schema, ConcreteTableName extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB, ConcreteArgs extends readonly unknown[], Depth extends number = 0, ConcreteAssociationName = never, JoinedAssociationsType extends Readonly<JoinedAssociation[]> = Readonly<[]>, SchemaAssociations = Schema[ConcreteTableName]['associations' & keyof Schema[ConcreteTableName]], ConcreteNthArg extends (keyof SchemaAssociations & string) | AliasedSchemaAssociation<Schema, ConcreteTableName> | Readonly<unknown[]> | null = ConcreteArgs[0] extends undefined ? null : ConcreteArgs[0] extends null ? null : ConcreteArgs[0] extends keyof SchemaAssociations & string ? ConcreteArgs[0] & keyof SchemaAssociations & string : ConcreteArgs[0] extends AliasedSchemaAssociation<Schema, ConcreteTableName> ? ConcreteArgs[0] & AliasedSchemaAssociation<Schema, ConcreteTableName> : ConcreteArgs[0] extends Readonly<unknown[]> ? Readonly<unknown[]> : null, CurrentArgumentType extends IS_ASSOCIATION_NAME | IS_ASSOCIATION_ALIAS | IS_NOT_ASSOCIATION_NAME = ConcreteNthArg extends null ? IS_NOT_ASSOCIATION_NAME : ConcreteNthArg extends Readonly<unknown[]> ? IS_NOT_ASSOCIATION_NAME : ConcreteNthArg extends keyof SchemaAssociations & string ? IS_ASSOCIATION_NAME : ConcreteNthArg extends AliasedSchemaAssociation<Schema, ConcreteTableName> ? IS_ASSOCIATION_ALIAS : IS_NOT_ASSOCIATION_NAME, NextUnaliasedAssociationName = CurrentArgumentType extends IS_ASSOCIATION_NAME ? ConcreteNthArg : CurrentArgumentType extends IS_ASSOCIATION_ALIAS ? ConcreteNthArg extends `${infer AssocName extends string} as ${string}` ? AssocName & keyof SchemaAssociations : never : never, NextAliasedAssociationName = CurrentArgumentType extends IS_ASSOCIATION_NAME ? ConcreteNthArg : CurrentArgumentType extends IS_ASSOCIATION_ALIAS ? ConcreteNthArg extends `${string} as ${infer Alias extends string}` ? Alias : ConcreteAssociationName : ConcreteAssociationName, NextTableName extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB = CurrentArgumentType extends IS_ASSOCIATION_NAME ? AssociationTableName<Schema, ConcreteTableName, NextUnaliasedAssociationName> : CurrentArgumentType extends IS_ASSOCIATION_ALIAS ? AssociationTableName<Schema, ConcreteTableName, NextUnaliasedAssociationName> : ConcreteTableName & AssociationTableNames<DB, Schema> & keyof DB> = ConcreteArgs['length'] extends 0 ? JoinedAssociationsType : Depth extends MAX_VARIADIC_DEPTH ? never : ConcreteArgs['length'] extends 1 ? ConcreteNthArg extends Readonly<unknown[]> ? JoinedAssociationsType : JoinedAssociationsTypeFromAssociations<DB, Schema, NextTableName, ReadonlyTail<ConcreteArgs>, Inc<Depth>, NextAliasedAssociationName, CurrentArgumentType extends IS_NOT_ASSOCIATION_NAME ? JoinedAssociationsType : Readonly<[
|
|
50
55
|
...JoinedAssociationsType,
|
|
51
56
|
{
|
|
52
57
|
table: NextTableName & string;
|
|
53
58
|
alias: NextAliasedAssociationName & string;
|
|
54
59
|
}
|
|
55
|
-
]>> : JoinedAssociationsTypeFromAssociations<DB, Schema, NextTableName, ReadonlyTail<ConcreteArgs>, Inc<Depth>,
|
|
60
|
+
]>> : JoinedAssociationsTypeFromAssociations<DB, Schema, NextTableName, ReadonlyTail<ConcreteArgs>, Inc<Depth>, NextAliasedAssociationName, CurrentArgumentType extends IS_NOT_ASSOCIATION_NAME ? JoinedAssociationsType : Readonly<[
|
|
56
61
|
...JoinedAssociationsType,
|
|
57
62
|
{
|
|
58
63
|
table: NextTableName & string;
|
package/docs/assets/hierarchy.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
window.hierarchyData = "
|
|
1
|
+
window.hierarchyData = "eJyVksFOAjEQht9lzgW3SwpLj0JMjBE1MXogHMru4DZ0W9J2MRvCu5vKpSK65TTNZP75v87MAawx3gFfUjahhFK6ImBxo7D00mgH/ACU0hC0aBA4vLRou7mVe7S3wiEQ2EpdAad5QaC1CjiUSjiH7qZaD8+qh7VvFJBTBXDwrhoE+eCUIFDWUlUWNfBlXtDVkUBexO4PnUPVRV17/H/VX0NA82keEEKMGJ6N8x8WXTrFBUUPR3BlIxa5zmostzOjnbdCav8mjRJhRf9Zo7XGuuFf0hQGNooZjGob/bRHu1HmM8X5hyDFbxJvey68uNelaXbCy7XCd+nrkFsLh3cSVZWA0NvjqotgI0bCUAhl04zQcVZ8HwibZmfYr90OT78Pr0fpGuHLOpH3sjhhfOOsiDgWxi9apa45lXNJn+fx+AXCu279"
|