@rvoh/dream 2.5.0 → 2.5.2

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.
Files changed (203) hide show
  1. package/dist/cjs/src/Dream.js +0 -9
  2. package/dist/cjs/src/decorators/field/Encrypted.js +2 -1
  3. package/dist/cjs/src/helpers/db/columnAllowsNull.js +3 -0
  4. package/dist/cjs/src/helpers/db/normalizeDataForDb.js +2 -1
  5. package/dist/cjs/src/helpers/db/types/isDatabaseArrayColumn.js +2 -1
  6. package/dist/cjs/src/helpers/db/types/isDatetimeOrDatetimeArrayColumn.js +2 -1
  7. package/dist/cjs/src/helpers/db/types/isJsonColumn.js +2 -1
  8. package/dist/cjs/src/ops/index.js +2 -1
  9. package/dist/esm/src/Dream.js +0 -9
  10. package/dist/esm/src/decorators/field/Encrypted.js +2 -1
  11. package/dist/esm/src/helpers/db/columnAllowsNull.js +3 -0
  12. package/dist/esm/src/helpers/db/normalizeDataForDb.js +2 -1
  13. package/dist/esm/src/helpers/db/types/isDatabaseArrayColumn.js +2 -1
  14. package/dist/esm/src/helpers/db/types/isDatetimeOrDatetimeArrayColumn.js +2 -1
  15. package/dist/esm/src/helpers/db/types/isJsonColumn.js +2 -1
  16. package/dist/esm/src/ops/index.js +2 -1
  17. package/dist/types/src/Dream.d.ts +0 -6
  18. package/dist/types/src/helpers/db/columnAllowsNull.d.ts +2 -0
  19. package/dist/types/src/serializer/builders/DreamSerializerBuilder.d.ts +2 -2
  20. package/dist/types/src/types/dream.d.ts +34 -0
  21. package/dist/types/src/types/dream.ts +46 -0
  22. package/dist/types/src/types/serializer.d.ts +4 -4
  23. package/dist/types/src/types/serializer.ts +4 -14
  24. package/dist/types/src/types/variadic.d.ts +15 -6
  25. package/dist/types/src/types/variadic.ts +129 -31
  26. package/docs/classes/db.DreamMigrationHelpers.html +9 -9
  27. package/docs/classes/db.KyselyQueryDriver.html +32 -32
  28. package/docs/classes/db.PostgresQueryDriver.html +33 -33
  29. package/docs/classes/db.QueryDriverBase.html +31 -31
  30. package/docs/classes/errors.CheckConstraintViolation.html +3 -3
  31. package/docs/classes/errors.ColumnOverflow.html +3 -3
  32. package/docs/classes/errors.CreateOrFindByFailedToCreateAndFind.html +3 -3
  33. package/docs/classes/errors.DataIncompatibleWithDatabaseField.html +3 -3
  34. package/docs/classes/errors.DataTypeColumnTypeMismatch.html +3 -3
  35. package/docs/classes/errors.GlobalNameNotSet.html +3 -3
  36. package/docs/classes/errors.InvalidCalendarDate.html +2 -2
  37. package/docs/classes/errors.InvalidClockTime.html +2 -2
  38. package/docs/classes/errors.InvalidClockTimeTz.html +2 -2
  39. package/docs/classes/errors.InvalidDateTime.html +2 -2
  40. package/docs/classes/errors.MissingSerializersDefinition.html +3 -3
  41. package/docs/classes/errors.NonLoadedAssociation.html +3 -3
  42. package/docs/classes/errors.NotNullViolation.html +3 -3
  43. package/docs/classes/errors.RecordNotFound.html +3 -3
  44. package/docs/classes/errors.ValidationError.html +3 -3
  45. package/docs/classes/index.CalendarDate.html +33 -33
  46. package/docs/classes/index.ClockTime.html +32 -32
  47. package/docs/classes/index.ClockTimeTz.html +35 -35
  48. package/docs/classes/index.DateTime.html +86 -86
  49. package/docs/classes/index.Decorators.html +19 -19
  50. package/docs/classes/index.Dream.html +118 -118
  51. package/docs/classes/index.DreamApp.html +5 -5
  52. package/docs/classes/index.DreamTransaction.html +2 -2
  53. package/docs/classes/index.Env.html +2 -2
  54. package/docs/classes/index.Query.html +56 -56
  55. package/docs/classes/system.CliFileWriter.html +4 -4
  56. package/docs/classes/system.DreamBin.html +2 -2
  57. package/docs/classes/system.DreamCLI.html +6 -6
  58. package/docs/classes/system.DreamImporter.html +2 -2
  59. package/docs/classes/system.DreamLogos.html +2 -2
  60. package/docs/classes/system.DreamSerializerBuilder.html +13 -13
  61. package/docs/classes/system.ObjectSerializerBuilder.html +8 -8
  62. package/docs/classes/system.PathHelpers.html +3 -3
  63. package/docs/classes/utils.Encrypt.html +2 -2
  64. package/docs/classes/utils.Range.html +2 -2
  65. package/docs/functions/db.closeAllDbConnections.html +1 -1
  66. package/docs/functions/db.dreamDbConnections.html +1 -1
  67. package/docs/functions/db.untypedDb.html +1 -1
  68. package/docs/functions/db.validateColumn.html +1 -1
  69. package/docs/functions/db.validateTable.html +1 -1
  70. package/docs/functions/errors.pgErrorType.html +1 -1
  71. package/docs/functions/index.DreamSerializer.html +1 -1
  72. package/docs/functions/index.ObjectSerializer.html +1 -1
  73. package/docs/functions/index.ReplicaSafe.html +1 -1
  74. package/docs/functions/index.STI.html +1 -1
  75. package/docs/functions/index.SoftDelete.html +1 -1
  76. package/docs/functions/utils.camelize.html +1 -1
  77. package/docs/functions/utils.capitalize.html +1 -1
  78. package/docs/functions/utils.cloneDeepSafe.html +1 -1
  79. package/docs/functions/utils.compact.html +1 -1
  80. package/docs/functions/utils.groupBy.html +1 -1
  81. package/docs/functions/utils.hyphenize.html +1 -1
  82. package/docs/functions/utils.intersection.html +1 -1
  83. package/docs/functions/utils.isEmpty.html +1 -1
  84. package/docs/functions/utils.normalizeUnicode.html +1 -1
  85. package/docs/functions/utils.pascalize.html +1 -1
  86. package/docs/functions/utils.percent.html +1 -1
  87. package/docs/functions/utils.range.html +1 -1
  88. package/docs/functions/utils.round.html +1 -1
  89. package/docs/functions/utils.sanitizeString.html +1 -1
  90. package/docs/functions/utils.snakeify.html +1 -1
  91. package/docs/functions/utils.sort.html +1 -1
  92. package/docs/functions/utils.sortBy.html +1 -1
  93. package/docs/functions/utils.sortObjectByKey.html +1 -1
  94. package/docs/functions/utils.sortObjectByValue.html +1 -1
  95. package/docs/functions/utils.uncapitalize.html +1 -1
  96. package/docs/functions/utils.uniq.html +1 -1
  97. package/docs/interfaces/openapi.OpenapiDescription.html +2 -2
  98. package/docs/interfaces/openapi.OpenapiSchemaProperties.html +1 -1
  99. package/docs/interfaces/openapi.OpenapiSchemaPropertiesShorthand.html +1 -1
  100. package/docs/interfaces/openapi.OpenapiTypeFieldObject.html +1 -1
  101. package/docs/interfaces/types.BelongsToStatement.html +2 -2
  102. package/docs/interfaces/types.DecoratorContext.html +2 -2
  103. package/docs/interfaces/types.DreamAppInitOptions.html +2 -2
  104. package/docs/interfaces/types.DreamAppOpts.html +2 -2
  105. package/docs/interfaces/types.DurationObject.html +2 -2
  106. package/docs/interfaces/types.EncryptOptions.html +2 -2
  107. package/docs/interfaces/types.InternalAnyTypedSerializerRendersMany.html +2 -2
  108. package/docs/interfaces/types.InternalAnyTypedSerializerRendersOne.html +2 -2
  109. package/docs/interfaces/types.SerializerRendererOpts.html +2 -2
  110. package/docs/types/openapi.CommonOpenapiSchemaObjectFields.html +1 -1
  111. package/docs/types/openapi.OpenapiAllTypes.html +1 -1
  112. package/docs/types/openapi.OpenapiFormats.html +1 -1
  113. package/docs/types/openapi.OpenapiNumberFormats.html +1 -1
  114. package/docs/types/openapi.OpenapiPrimitiveBaseTypes.html +1 -1
  115. package/docs/types/openapi.OpenapiPrimitiveTypes.html +1 -1
  116. package/docs/types/openapi.OpenapiSchemaArray.html +1 -1
  117. package/docs/types/openapi.OpenapiSchemaArrayShorthand.html +1 -1
  118. package/docs/types/openapi.OpenapiSchemaBase.html +1 -1
  119. package/docs/types/openapi.OpenapiSchemaBody.html +1 -1
  120. package/docs/types/openapi.OpenapiSchemaBodyShorthand.html +1 -1
  121. package/docs/types/openapi.OpenapiSchemaCommonFields.html +1 -1
  122. package/docs/types/openapi.OpenapiSchemaExpressionAllOf.html +2 -2
  123. package/docs/types/openapi.OpenapiSchemaExpressionAnyOf.html +2 -2
  124. package/docs/types/openapi.OpenapiSchemaExpressionOneOf.html +2 -2
  125. package/docs/types/openapi.OpenapiSchemaExpressionRef.html +2 -2
  126. package/docs/types/openapi.OpenapiSchemaExpressionRefSchemaShorthand.html +2 -2
  127. package/docs/types/openapi.OpenapiSchemaInteger.html +1 -1
  128. package/docs/types/openapi.OpenapiSchemaNull.html +2 -2
  129. package/docs/types/openapi.OpenapiSchemaNumber.html +1 -1
  130. package/docs/types/openapi.OpenapiSchemaObject.html +1 -1
  131. package/docs/types/openapi.OpenapiSchemaObjectAllOf.html +1 -1
  132. package/docs/types/openapi.OpenapiSchemaObjectAllOfShorthand.html +1 -1
  133. package/docs/types/openapi.OpenapiSchemaObjectAnyOf.html +1 -1
  134. package/docs/types/openapi.OpenapiSchemaObjectAnyOfShorthand.html +1 -1
  135. package/docs/types/openapi.OpenapiSchemaObjectBase.html +1 -1
  136. package/docs/types/openapi.OpenapiSchemaObjectBaseShorthand.html +1 -1
  137. package/docs/types/openapi.OpenapiSchemaObjectOneOf.html +1 -1
  138. package/docs/types/openapi.OpenapiSchemaObjectOneOfShorthand.html +1 -1
  139. package/docs/types/openapi.OpenapiSchemaObjectShorthand.html +1 -1
  140. package/docs/types/openapi.OpenapiSchemaPrimitiveGeneric.html +1 -1
  141. package/docs/types/openapi.OpenapiSchemaShorthandExpressionAllOf.html +2 -2
  142. package/docs/types/openapi.OpenapiSchemaShorthandExpressionAnyOf.html +2 -2
  143. package/docs/types/openapi.OpenapiSchemaShorthandExpressionOneOf.html +2 -2
  144. package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializableRef.html +2 -2
  145. package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializerRef.html +2 -2
  146. package/docs/types/openapi.OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
  147. package/docs/types/openapi.OpenapiSchemaString.html +1 -1
  148. package/docs/types/openapi.OpenapiShorthandAllTypes.html +1 -1
  149. package/docs/types/openapi.OpenapiShorthandPrimitiveBaseTypes.html +1 -1
  150. package/docs/types/openapi.OpenapiShorthandPrimitiveTypes.html +1 -1
  151. package/docs/types/openapi.OpenapiTypeField.html +1 -1
  152. package/docs/types/system.DreamAppAllowedPackageManagersEnum.html +1 -1
  153. package/docs/types/types.CalendarDateDurationUnit.html +1 -1
  154. package/docs/types/types.CalendarDateObject.html +1 -1
  155. package/docs/types/types.Camelized.html +1 -1
  156. package/docs/types/types.ClockTimeObject.html +1 -1
  157. package/docs/types/types.DbConnectionType.html +1 -1
  158. package/docs/types/types.DbTypes.html +1 -1
  159. package/docs/types/types.DreamAssociationMetadata.html +1 -1
  160. package/docs/types/types.DreamAttributes.html +1 -1
  161. package/docs/types/types.DreamClassAssociationAndStatement.html +1 -1
  162. package/docs/types/types.DreamClassColumn.html +1 -1
  163. package/docs/types/types.DreamColumn.html +1 -1
  164. package/docs/types/types.DreamColumnNames.html +1 -1
  165. package/docs/types/types.DreamLogLevel.html +1 -1
  166. package/docs/types/types.DreamLogger.html +2 -2
  167. package/docs/types/types.DreamModelSerializerType.html +1 -1
  168. package/docs/types/types.DreamOrViewModelClassSerializerKey.html +1 -1
  169. package/docs/types/types.DreamOrViewModelSerializerKey.html +1 -1
  170. package/docs/types/types.DreamParamSafeAttributes.html +1 -1
  171. package/docs/types/types.DreamParamSafeColumnNames.html +1 -1
  172. package/docs/types/types.DreamSerializable.html +1 -1
  173. package/docs/types/types.DreamSerializableArray.html +1 -1
  174. package/docs/types/types.DreamSerializerKey.html +1 -1
  175. package/docs/types/types.DreamSerializers.html +1 -1
  176. package/docs/types/types.DreamVirtualColumns.html +1 -1
  177. package/docs/types/types.DurationUnit.html +1 -1
  178. package/docs/types/types.EncryptAlgorithm.html +1 -1
  179. package/docs/types/types.HasManyStatement.html +1 -1
  180. package/docs/types/types.HasOneStatement.html +1 -1
  181. package/docs/types/types.Hyphenized.html +1 -1
  182. package/docs/types/types.Pascalized.html +1 -1
  183. package/docs/types/types.PrimaryKeyType.html +1 -1
  184. package/docs/types/types.RoundingPrecision.html +1 -1
  185. package/docs/types/types.SerializerCasing.html +1 -1
  186. package/docs/types/types.SimpleObjectSerializerType.html +1 -1
  187. package/docs/types/types.Snakeified.html +1 -1
  188. package/docs/types/types.StrictInterface.html +1 -1
  189. package/docs/types/types.UpdateableAssociationProperties.html +1 -1
  190. package/docs/types/types.UpdateableProperties.html +1 -1
  191. package/docs/types/types.ValidationType.html +1 -1
  192. package/docs/types/types.ViewModel.html +2 -2
  193. package/docs/types/types.ViewModelClass.html +1 -1
  194. package/docs/types/types.WeekdayName.html +1 -1
  195. package/docs/types/types.WhereStatementForDream.html +1 -1
  196. package/docs/types/types.WhereStatementForDreamClass.html +1 -1
  197. package/docs/variables/index.DreamConst.html +1 -1
  198. package/docs/variables/index.ops.html +1 -1
  199. package/docs/variables/openapi.openapiPrimitiveTypes.html +1 -1
  200. package/docs/variables/openapi.openapiShorthandPrimitiveTypes.html +1 -1
  201. package/docs/variables/system.DreamAppAllowedPackageManagersEnumValues.html +1 -1
  202. package/docs/variables/system.primaryKeyTypes.html +1 -1
  203. package/package.json +1 -1
@@ -47,7 +47,6 @@ import MissingSerializersDefinition from './errors/serializers/MissingSerializer
47
47
  import areEqual from './helpers/areEqual.js';
48
48
  import cloneDeepSafe from './helpers/cloneDeepSafe.js';
49
49
  import compact from './helpers/compact.js';
50
- import cachedTypeForAttribute from './helpers/db/cachedTypeForAttribute.js';
51
50
  import isJsonColumn from './helpers/db/types/isJsonColumn.js';
52
51
  import notEqual from './helpers/notEqual.js';
53
52
  import { inferSerializersFromDreamClassOrViewModelClass } from './serializer/helpers/inferSerializerFromDreamOrViewModel.js';
@@ -2701,14 +2700,6 @@ export default class Dream {
2701
2700
  getAttributes() {
2702
2701
  return { ...this.currentAttributes };
2703
2702
  }
2704
- /**
2705
- * @internal
2706
- *
2707
- * Returns the db type stored within the database
2708
- */
2709
- static cachedTypeFor(attribute) {
2710
- return cachedTypeForAttribute(this, attribute);
2711
- }
2712
2703
  /**
2713
2704
  * Returns the attributes that have changed since
2714
2705
  * being persisted to the database, with the values
@@ -1,5 +1,6 @@
1
1
  import InternalEncrypt from '../../encrypt/InternalEncrypt.js';
2
2
  import DoNotSetEncryptedFieldsDirectly from '../../errors/DoNotSetEncryptedFieldsDirectly.js';
3
+ import columnAllowsNull from '../../helpers/db/columnAllowsNull.js';
3
4
  import pascalize from '../../helpers/pascalize.js';
4
5
  export default function Encrypted(encryptedColumnName) {
5
6
  return function (_, context) {
@@ -29,7 +30,7 @@ export default function Encrypted(encryptedColumnName) {
29
30
  ;
30
31
  dreamClass['virtualAttributes'].push({
31
32
  property: key,
32
- type: 'string',
33
+ type: columnAllowsNull(dreamClass, encryptedKey) ? ['string', 'null'] : 'string',
33
34
  });
34
35
  if (!Object.getOwnPropertyDescriptor(dreamClass, 'explicitUnsafeParamColumns')) {
35
36
  // This pattern allows `explicitUnsafeParamColumns` on a base STI class and on
@@ -0,0 +1,3 @@
1
+ export default function columnAllowsNull(dreamClass, attribute) {
2
+ return dreamClass.prototype.schema[dreamClass.table]?.['columns']?.[attribute]?.['allowNull'] ?? false;
3
+ }
@@ -1,3 +1,4 @@
1
+ import cachedTypeForAttribute from './cachedTypeForAttribute.js';
1
2
  import DataTypeColumnTypeMismatch from '../../errors/db/DataTypeColumnTypeMismatch.js';
2
3
  import BaseClockTime from '../../utils/datetime/BaseClockTime.js';
3
4
  import CalendarDate from '../../utils/datetime/CalendarDate.js';
@@ -7,7 +8,7 @@ import { DateTime } from '../../utils/datetime/DateTime.js';
7
8
  import normalizeUnicode from '../normalizeUnicode.js';
8
9
  import { DATE_OR_DATE_ARRAY_COLUMN_CHECK_REGEXP, DATETIME_OR_DATETIME_ARRAY_COLUMN_CHECK_REGEXP, STRING_OR_STRING_ARRAY_COLUMN_CHECK_REGEXP, TIME_WITH_TIMEZONE_COLUMN_CHECK_REGEXP, TIME_WITHOUT_TIMEZONE_COLUMN_CHECK_REGEXP, } from './types/helpers.js';
9
10
  export function normalizeDataForDb({ val, dreamClass, column, }) {
10
- const columnType = dreamClass['cachedTypeFor'](column);
11
+ const columnType = cachedTypeForAttribute(dreamClass, column);
11
12
  if (val instanceof DateTime || DATETIME_OR_DATETIME_ARRAY_COLUMN_CHECK_REGEXP.test(columnType)) {
12
13
  return dateTimeOrDateToSql(DateTime, val);
13
14
  //
@@ -1,3 +1,4 @@
1
+ import cachedTypeForAttribute from '../cachedTypeForAttribute.js';
1
2
  export default function isDatabaseArrayColumn(dreamClass, column) {
2
- return /\[\]$/.test(dreamClass['cachedTypeFor'](column));
3
+ return /\[\]$/.test(cachedTypeForAttribute(dreamClass, column));
3
4
  }
@@ -1,4 +1,5 @@
1
+ import cachedTypeForAttribute from '../cachedTypeForAttribute.js';
1
2
  import { DATETIME_OR_DATETIME_ARRAY_COLUMN_CHECK_REGEXP } from './helpers.js';
2
3
  export default function isDatetimeOrDatetimeArrayColumn(dreamClass, column) {
3
- return DATETIME_OR_DATETIME_ARRAY_COLUMN_CHECK_REGEXP.test(dreamClass['cachedTypeFor'](column));
4
+ return DATETIME_OR_DATETIME_ARRAY_COLUMN_CHECK_REGEXP.test(cachedTypeForAttribute(dreamClass, column));
4
5
  }
@@ -1,3 +1,4 @@
1
+ import cachedTypeForAttribute from '../cachedTypeForAttribute.js';
1
2
  export default function isJsonColumn(dreamClass, column) {
2
- return ['json', 'jsonb'].includes(dreamClass['cachedTypeFor'](column));
3
+ return ['json', 'jsonb'].includes(cachedTypeForAttribute(dreamClass, column));
3
4
  }
@@ -1,5 +1,6 @@
1
1
  import { sql } from 'kysely';
2
2
  import AnyRequiresArrayColumn from '../errors/ops/AnyRequiresArrayColumn.js';
3
+ import cachedTypeForAttribute from '../helpers/db/cachedTypeForAttribute.js';
3
4
  import isDatabaseArrayColumn from '../helpers/db/types/isDatabaseArrayColumn.js';
4
5
  import CurriedOpsStatement from './curried-ops-statement.js';
5
6
  import OpsStatement from './ops-statement.js';
@@ -10,7 +11,7 @@ const ops = {
10
11
  const column = fieldName.replace(/^.*\./, '');
11
12
  if (!isDatabaseArrayColumn(dreamClass, column))
12
13
  throw new AnyRequiresArrayColumn(dreamClass, column);
13
- const castType = dreamClass['cachedTypeFor'](column);
14
+ const castType = cachedTypeForAttribute(dreamClass, column);
14
15
  return new OpsStatement('@>', sql `ARRAY[${sql.join([value])}]::${sql.raw(castType)}`);
15
16
  }),
16
17
  like: (like) => new OpsStatement('like', like),
@@ -47,7 +47,6 @@ import MissingSerializersDefinition from './errors/serializers/MissingSerializer
47
47
  import areEqual from './helpers/areEqual.js';
48
48
  import cloneDeepSafe from './helpers/cloneDeepSafe.js';
49
49
  import compact from './helpers/compact.js';
50
- import cachedTypeForAttribute from './helpers/db/cachedTypeForAttribute.js';
51
50
  import isJsonColumn from './helpers/db/types/isJsonColumn.js';
52
51
  import notEqual from './helpers/notEqual.js';
53
52
  import { inferSerializersFromDreamClassOrViewModelClass } from './serializer/helpers/inferSerializerFromDreamOrViewModel.js';
@@ -2701,14 +2700,6 @@ export default class Dream {
2701
2700
  getAttributes() {
2702
2701
  return { ...this.currentAttributes };
2703
2702
  }
2704
- /**
2705
- * @internal
2706
- *
2707
- * Returns the db type stored within the database
2708
- */
2709
- static cachedTypeFor(attribute) {
2710
- return cachedTypeForAttribute(this, attribute);
2711
- }
2712
2703
  /**
2713
2704
  * Returns the attributes that have changed since
2714
2705
  * being persisted to the database, with the values
@@ -1,5 +1,6 @@
1
1
  import InternalEncrypt from '../../encrypt/InternalEncrypt.js';
2
2
  import DoNotSetEncryptedFieldsDirectly from '../../errors/DoNotSetEncryptedFieldsDirectly.js';
3
+ import columnAllowsNull from '../../helpers/db/columnAllowsNull.js';
3
4
  import pascalize from '../../helpers/pascalize.js';
4
5
  export default function Encrypted(encryptedColumnName) {
5
6
  return function (_, context) {
@@ -29,7 +30,7 @@ export default function Encrypted(encryptedColumnName) {
29
30
  ;
30
31
  dreamClass['virtualAttributes'].push({
31
32
  property: key,
32
- type: 'string',
33
+ type: columnAllowsNull(dreamClass, encryptedKey) ? ['string', 'null'] : 'string',
33
34
  });
34
35
  if (!Object.getOwnPropertyDescriptor(dreamClass, 'explicitUnsafeParamColumns')) {
35
36
  // This pattern allows `explicitUnsafeParamColumns` on a base STI class and on
@@ -0,0 +1,3 @@
1
+ export default function columnAllowsNull(dreamClass, attribute) {
2
+ return dreamClass.prototype.schema[dreamClass.table]?.['columns']?.[attribute]?.['allowNull'] ?? false;
3
+ }
@@ -1,3 +1,4 @@
1
+ import cachedTypeForAttribute from './cachedTypeForAttribute.js';
1
2
  import DataTypeColumnTypeMismatch from '../../errors/db/DataTypeColumnTypeMismatch.js';
2
3
  import BaseClockTime from '../../utils/datetime/BaseClockTime.js';
3
4
  import CalendarDate from '../../utils/datetime/CalendarDate.js';
@@ -7,7 +8,7 @@ import { DateTime } from '../../utils/datetime/DateTime.js';
7
8
  import normalizeUnicode from '../normalizeUnicode.js';
8
9
  import { DATE_OR_DATE_ARRAY_COLUMN_CHECK_REGEXP, DATETIME_OR_DATETIME_ARRAY_COLUMN_CHECK_REGEXP, STRING_OR_STRING_ARRAY_COLUMN_CHECK_REGEXP, TIME_WITH_TIMEZONE_COLUMN_CHECK_REGEXP, TIME_WITHOUT_TIMEZONE_COLUMN_CHECK_REGEXP, } from './types/helpers.js';
9
10
  export function normalizeDataForDb({ val, dreamClass, column, }) {
10
- const columnType = dreamClass['cachedTypeFor'](column);
11
+ const columnType = cachedTypeForAttribute(dreamClass, column);
11
12
  if (val instanceof DateTime || DATETIME_OR_DATETIME_ARRAY_COLUMN_CHECK_REGEXP.test(columnType)) {
12
13
  return dateTimeOrDateToSql(DateTime, val);
13
14
  //
@@ -1,3 +1,4 @@
1
+ import cachedTypeForAttribute from '../cachedTypeForAttribute.js';
1
2
  export default function isDatabaseArrayColumn(dreamClass, column) {
2
- return /\[\]$/.test(dreamClass['cachedTypeFor'](column));
3
+ return /\[\]$/.test(cachedTypeForAttribute(dreamClass, column));
3
4
  }
@@ -1,4 +1,5 @@
1
+ import cachedTypeForAttribute from '../cachedTypeForAttribute.js';
1
2
  import { DATETIME_OR_DATETIME_ARRAY_COLUMN_CHECK_REGEXP } from './helpers.js';
2
3
  export default function isDatetimeOrDatetimeArrayColumn(dreamClass, column) {
3
- return DATETIME_OR_DATETIME_ARRAY_COLUMN_CHECK_REGEXP.test(dreamClass['cachedTypeFor'](column));
4
+ return DATETIME_OR_DATETIME_ARRAY_COLUMN_CHECK_REGEXP.test(cachedTypeForAttribute(dreamClass, column));
4
5
  }
@@ -1,3 +1,4 @@
1
+ import cachedTypeForAttribute from '../cachedTypeForAttribute.js';
1
2
  export default function isJsonColumn(dreamClass, column) {
2
- return ['json', 'jsonb'].includes(dreamClass['cachedTypeFor'](column));
3
+ return ['json', 'jsonb'].includes(cachedTypeForAttribute(dreamClass, column));
3
4
  }
@@ -1,5 +1,6 @@
1
1
  import { sql } from 'kysely';
2
2
  import AnyRequiresArrayColumn from '../errors/ops/AnyRequiresArrayColumn.js';
3
+ import cachedTypeForAttribute from '../helpers/db/cachedTypeForAttribute.js';
3
4
  import isDatabaseArrayColumn from '../helpers/db/types/isDatabaseArrayColumn.js';
4
5
  import CurriedOpsStatement from './curried-ops-statement.js';
5
6
  import OpsStatement from './ops-statement.js';
@@ -10,7 +11,7 @@ const ops = {
10
11
  const column = fieldName.replace(/^.*\./, '');
11
12
  if (!isDatabaseArrayColumn(dreamClass, column))
12
13
  throw new AnyRequiresArrayColumn(dreamClass, column);
13
- const castType = dreamClass['cachedTypeFor'](column);
14
+ const castType = cachedTypeForAttribute(dreamClass, column);
14
15
  return new OpsStatement('@>', sql `ARRAY[${sql.join([value])}]::${sql.raw(castType)}`);
15
16
  }),
16
17
  like: (like) => new OpsStatement('like', like),
@@ -2061,12 +2061,6 @@ export default class Dream {
2061
2061
  * ```
2062
2062
  */
2063
2063
  getAttributes<I extends Dream, DB extends I['DB']>(this: I): Selectable<DB[I['table']]>;
2064
- /**
2065
- * @internal
2066
- *
2067
- * Returns the db type stored within the database
2068
- */
2069
- private static cachedTypeFor;
2070
2064
  /**
2071
2065
  * Returns the attributes that have changed since
2072
2066
  * being persisted to the database, with the values
@@ -0,0 +1,2 @@
1
+ import Dream from '../../Dream.js';
2
+ export default function columnAllowsNull<T extends typeof Dream, DB extends InstanceType<T>['DB'], TableName extends keyof DB = InstanceType<T>['table'] & keyof DB, Table extends DB[keyof DB] = DB[TableName]>(dreamClass: T, attribute: keyof Table): boolean;
@@ -38,7 +38,7 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
38
38
  attribute(name: NonJsonDreamColumnNames<DataType> & keyof DataType & 'type', options?: AutomaticSerializerAttributeOptionsForType): DreamSerializerBuilder<DataTypeForOpenapi, MaybeNullDataType, PassthroughDataType, DataType>;
39
39
  attribute(name: DreamVirtualColumns<DataType>[number], options?: SerializerAttributeOptionsForVirtualColumn): DreamSerializerBuilder<DataTypeForOpenapi, MaybeNullDataType, PassthroughDataType, DataType>;
40
40
  attribute<MaybeAttributeName extends NonJsonDreamColumnNames<DataType> | (keyof DataType & string), AttributeName extends MaybeAttributeName extends NonJsonDreamColumnNames<DataType> ? never : Exclude<keyof DataType, keyof Dream> & string>(name: AttributeName, options: NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption): DreamSerializerBuilder<DataTypeForOpenapi, MaybeNullDataType, PassthroughDataType, DataType>;
41
- attribute<AttributeName extends NonJsonDreamColumnNames<DataType> & keyof DataType & string>(name: AttributeName, options?: AutomaticSerializerAttributeOptions<DataType, AttributeName>): DreamSerializerBuilder<DataTypeForOpenapi, MaybeNullDataType, PassthroughDataType, DataType>;
41
+ attribute<AttributeName extends NonJsonDreamColumnNames<DataType> & keyof DataType & string>(name: AttributeName, options?: AutomaticSerializerAttributeOptions): DreamSerializerBuilder<DataTypeForOpenapi, MaybeNullDataType, PassthroughDataType, DataType>;
42
42
  /**
43
43
  * Includes an attribute from a nested object in the serialized output.
44
44
  *
@@ -67,7 +67,7 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
67
67
  *
68
68
  * See: {@link https://your-docs-url.com/docs/serializers/attributes | Serializer Attributes Documentation}
69
69
  */
70
- delegatedAttribute<ProvidedModelType = undefined, ProvidedTargetName extends ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, keyof Dream> = ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, keyof Dream>, ActualDataType extends ProvidedModelType extends undefined ? DataType : ProvidedModelType = ProvidedModelType extends undefined ? DataType : ProvidedModelType, TargetName extends ProvidedTargetName extends undefined ? Exclude<keyof ActualDataType, keyof Dream> : ProvidedTargetName & keyof ActualDataType = ProvidedTargetName extends undefined ? Exclude<keyof ActualDataType, keyof Dream> : ProvidedTargetName & keyof ActualDataType, AssociatedModelType = Exclude<ActualDataType[TargetName], null>, TargetAttributeName extends AssociatedModelType extends object ? Exclude<keyof AssociatedModelType, keyof Dream> & string : never = AssociatedModelType extends object ? Exclude<keyof AssociatedModelType, keyof Dream> & string : never>(targetName: TargetName, name: TargetAttributeName, options?: AssociatedModelType extends Dream ? TargetAttributeName extends NonJsonDreamColumnNames<AssociatedModelType> & keyof AssociatedModelType & 'type' ? AutomaticSerializerAttributeOptionsForType : TargetAttributeName extends DreamVirtualColumns<AssociatedModelType>[number] ? SerializerAttributeOptionsForVirtualColumn : TargetAttributeName extends AssociatedModelType & keyof AssociatedModelType & string ? AutomaticSerializerAttributeOptions<AssociatedModelType, TargetAttributeName> | NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption : NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption : NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption): this;
70
+ delegatedAttribute<ProvidedModelType = undefined, ProvidedTargetName extends ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, keyof Dream> = ProvidedModelType extends undefined ? undefined : Exclude<keyof ProvidedModelType, keyof Dream>, ActualDataType extends ProvidedModelType extends undefined ? DataType : ProvidedModelType = ProvidedModelType extends undefined ? DataType : ProvidedModelType, TargetName extends ProvidedTargetName extends undefined ? Exclude<keyof ActualDataType, keyof Dream> : ProvidedTargetName & keyof ActualDataType = ProvidedTargetName extends undefined ? Exclude<keyof ActualDataType, keyof Dream> : ProvidedTargetName & keyof ActualDataType, AssociatedModelType = Exclude<ActualDataType[TargetName], null>, TargetAttributeName extends AssociatedModelType extends object ? Exclude<keyof AssociatedModelType, keyof Dream> & string : never = AssociatedModelType extends object ? Exclude<keyof AssociatedModelType, keyof Dream> & string : never>(targetName: TargetName, name: TargetAttributeName, options?: AssociatedModelType extends Dream ? TargetAttributeName extends NonJsonDreamColumnNames<AssociatedModelType> & keyof AssociatedModelType & 'type' ? AutomaticSerializerAttributeOptionsForType : TargetAttributeName extends DreamVirtualColumns<AssociatedModelType>[number] ? SerializerAttributeOptionsForVirtualColumn : TargetAttributeName extends AssociatedModelType & keyof AssociatedModelType & string ? AutomaticSerializerAttributeOptions | NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption : NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption : NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption): this;
71
71
  /**
72
72
  * Includes a computed value in the serialized output.
73
73
  *
@@ -80,6 +80,40 @@ type AssociationMetadataForTable<Schema, TableName extends keyof Schema> = Schem
80
80
  export type AssociationNamesForTable<Schema, TableName extends keyof Schema> = keyof AssociationMetadataForTable<Schema, TableName> | AliasedSchemaAssociation<Schema, TableName>;
81
81
  type MetadataForAssociation<Schema, TableName extends keyof Schema, AssociationName, AssociationMetadata = AssociationMetadataForTable<Schema, TableName>> = AssociationMetadata[AssociationName & keyof AssociationMetadata];
82
82
  export type AssociationTableName<Schema, TableName extends keyof Schema, AssociationName, AssociationData = MetadataForAssociation<Schema, TableName, AssociationName>> = (AssociationData['tables' & keyof AssociationData] & any[])[0] & keyof Schema;
83
+ /**
84
+ * @internal
85
+ *
86
+ * Union of all table names for an association, accounting
87
+ * for polymorphic associations, which contain more than one
88
+ * table.
89
+ *
90
+ * ```ts
91
+ * AssociationTableNamesForAssociation<Schema, 'ratings', 'rateable'>
92
+ * // 'compositions' | 'posts'
93
+ * ```
94
+ */
95
+ export type AssociationTableNamesForAssociation<Schema, TableName extends keyof Schema, AssociationName, AssociationData = MetadataForAssociation<Schema, TableName, AssociationName>> = (AssociationData['tables' & keyof AssociationData] & readonly (keyof Schema)[])[number];
96
+ /**
97
+ * @internal
98
+ *
99
+ * Union of all association names for an association, accounting
100
+ * for polymorphic associations. In a polymorphic scenario, an association
101
+ * like `Rating#rateable` will point to multiple models, in this case
102
+ * either Composition or Post. Both of these models have some shared associations
103
+ * (i.e. `user`), but also some differing associations. This type helper
104
+ * will union all of these possibilities together, enabling us to preload
105
+ * inner associations safely at the type layer, since it is already
106
+ * supported at the implementation layer.
107
+ *
108
+ * In the example below, `compositionAssets` will come from the Composition model,
109
+ * while `comments` will come from the Post model.
110
+ *
111
+ * ```ts
112
+ * AssociationNamesForAssociation<Schema, 'ratings', 'rateable'>
113
+ * // 'compositionAssets' | 'comments' ...
114
+ * ```
115
+ */
116
+ export type AssociationNamesForAssociation<Schema, TableName extends keyof Schema, AssociationName, TableNamesUnion = AssociationTableNamesForAssociation<Schema, TableName, AssociationName>> = TableNamesUnion extends keyof Schema ? AssociationNamesForTable<Schema, TableNamesUnion> : never;
83
117
  export type DreamClassAssociationAndStatement<DreamClass extends typeof Dream, AssociationName, DreamInstance extends InstanceType<DreamClass> = InstanceType<DreamClass>, DB extends DreamInstance['DB'] = DreamInstance['DB'], Schema extends DreamInstance['schema'] = DreamInstance['schema'], TableName extends DreamInstance['table'] = DreamInstance['table'], AssocTableName extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB = AssociationTableName<Schema, TableName, AssociationName>, RequiredOnClauseKeysForThisAssociation extends RequiredOnClauseKeys<Schema, TableName, AssociationName> = RequiredOnClauseKeys<Schema, TableName, AssociationName>, Statements extends JoinAndStatements<DreamInstance, DB, Schema, AssocTableName, RequiredOnClauseKeysForThisAssociation> = JoinAndStatements<DreamInstance, DB, Schema, AssocTableName, RequiredOnClauseKeysForThisAssociation>> = Statements;
84
118
  export type JoinAndStatements<I extends Dream, DB, Schema, TableName extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB, RequiredOnClauseKeysForThisAssociation> = RequiredOnClauseKeysForThisAssociation extends null ? {
85
119
  and?: InternalWhereStatement<I, DB, Schema, TableName>;
@@ -375,6 +375,52 @@ export type AssociationTableName<
375
375
  AssociationData = MetadataForAssociation<Schema, TableName, AssociationName>,
376
376
  > = (AssociationData['tables' & keyof AssociationData] & any[])[0] & keyof Schema
377
377
 
378
+ /**
379
+ * @internal
380
+ *
381
+ * Union of all table names for an association, accounting
382
+ * for polymorphic associations, which contain more than one
383
+ * table.
384
+ *
385
+ * ```ts
386
+ * AssociationTableNamesForAssociation<Schema, 'ratings', 'rateable'>
387
+ * // 'compositions' | 'posts'
388
+ * ```
389
+ */
390
+ export type AssociationTableNamesForAssociation<
391
+ Schema,
392
+ TableName extends keyof Schema,
393
+ AssociationName,
394
+ AssociationData = MetadataForAssociation<Schema, TableName, AssociationName>,
395
+ > = (AssociationData['tables' & keyof AssociationData] & readonly (keyof Schema)[])[number]
396
+
397
+ /**
398
+ * @internal
399
+ *
400
+ * Union of all association names for an association, accounting
401
+ * for polymorphic associations. In a polymorphic scenario, an association
402
+ * like `Rating#rateable` will point to multiple models, in this case
403
+ * either Composition or Post. Both of these models have some shared associations
404
+ * (i.e. `user`), but also some differing associations. This type helper
405
+ * will union all of these possibilities together, enabling us to preload
406
+ * inner associations safely at the type layer, since it is already
407
+ * supported at the implementation layer.
408
+ *
409
+ * In the example below, `compositionAssets` will come from the Composition model,
410
+ * while `comments` will come from the Post model.
411
+ *
412
+ * ```ts
413
+ * AssociationNamesForAssociation<Schema, 'ratings', 'rateable'>
414
+ * // 'compositionAssets' | 'comments' ...
415
+ * ```
416
+ */
417
+ export type AssociationNamesForAssociation<
418
+ Schema,
419
+ TableName extends keyof Schema,
420
+ AssociationName,
421
+ TableNamesUnion = AssociationTableNamesForAssociation<Schema, TableName, AssociationName>,
422
+ > = TableNamesUnion extends keyof Schema ? AssociationNamesForTable<Schema, TableNamesUnion> : never
423
+
378
424
  export type DreamClassAssociationAndStatement<
379
425
  DreamClass extends typeof Dream,
380
426
  AssociationName,
@@ -2,8 +2,8 @@ import Dream from '../Dream.js';
2
2
  import { RoundingPrecision } from '../helpers/round.js';
3
3
  import DreamSerializerBuilder from '../serializer/builders/DreamSerializerBuilder.js';
4
4
  import ObjectSerializerBuilder from '../serializer/builders/ObjectSerializerBuilder.js';
5
- import { DreamAttributeDbTypes, DreamSerializable, DreamSerializableArray, ViewModelClass } from './dream.js';
6
- import { DecimalOpenapiTypesIncludingDbTypes, OpenapiDescription, OpenapiSchemaBodyShorthand, OpenapiShorthandPrimitiveTypes } from './openapi.js';
5
+ import { DreamSerializable, DreamSerializableArray, ViewModelClass } from './dream.js';
6
+ import { OpenapiDescription, OpenapiSchemaBodyShorthand, OpenapiShorthandPrimitiveTypes } from './openapi.js';
7
7
  export type SerializerCasing = 'camel' | 'snake';
8
8
  export type DreamsOrSerializersOrViewModels = DreamSerializable | DreamSerializableArray;
9
9
  export interface InternalAnyTypedSerializerAttribute {
@@ -45,11 +45,11 @@ export interface InternalAnyTypedSerializerRendersMany<DataType, AttributeName e
45
45
  name: AttributeName;
46
46
  options: InternalAnyRendersOneOrManyOpts;
47
47
  }
48
- export type AutomaticSerializerAttributeOptions<DreamInstance extends Dream, AttributeName extends keyof DreamInstance & string> = {
48
+ export type AutomaticSerializerAttributeOptions = {
49
49
  as?: string;
50
50
  default?: any;
51
51
  openapi?: OpenapiDescription;
52
- precision?: DreamAttributeDbTypes<DreamInstance>[AttributeName] extends DecimalOpenapiTypesIncludingDbTypes ? RoundingPrecision : never;
52
+ precision?: RoundingPrecision;
53
53
  required?: false;
54
54
  };
55
55
  export type AutomaticSerializerAttributeOptionsForType = {
@@ -2,13 +2,8 @@ import Dream from '../Dream.js'
2
2
  import { RoundingPrecision } from '../helpers/round.js'
3
3
  import DreamSerializerBuilder from '../serializer/builders/DreamSerializerBuilder.js'
4
4
  import ObjectSerializerBuilder from '../serializer/builders/ObjectSerializerBuilder.js'
5
- import { DreamAttributeDbTypes, DreamSerializable, DreamSerializableArray, ViewModelClass } from './dream.js'
6
- import {
7
- DecimalOpenapiTypesIncludingDbTypes,
8
- OpenapiDescription,
9
- OpenapiSchemaBodyShorthand,
10
- OpenapiShorthandPrimitiveTypes,
11
- } from './openapi.js'
5
+ import { DreamSerializable, DreamSerializableArray, ViewModelClass } from './dream.js'
6
+ import { OpenapiDescription, OpenapiSchemaBodyShorthand, OpenapiShorthandPrimitiveTypes } from './openapi.js'
12
7
 
13
8
  export type SerializerCasing = 'camel' | 'snake'
14
9
  export type DreamsOrSerializersOrViewModels = DreamSerializable | DreamSerializableArray
@@ -62,16 +57,11 @@ export interface InternalAnyTypedSerializerRendersMany<
62
57
  options: InternalAnyRendersOneOrManyOpts
63
58
  }
64
59
 
65
- export type AutomaticSerializerAttributeOptions<
66
- DreamInstance extends Dream,
67
- AttributeName extends keyof DreamInstance & string,
68
- > = {
60
+ export type AutomaticSerializerAttributeOptions = {
69
61
  as?: string
70
62
  default?: any
71
63
  openapi?: OpenapiDescription
72
- precision?: DreamAttributeDbTypes<DreamInstance>[AttributeName] extends DecimalOpenapiTypesIncludingDbTypes
73
- ? RoundingPrecision
74
- : never
64
+ precision?: RoundingPrecision
75
65
  required?: false
76
66
  }
77
67
 
@@ -1,23 +1,32 @@
1
1
  import Dream from '../Dream.js';
2
2
  import { Camelized } from '../helpers/stringCasing.js';
3
3
  import { AssociationTableNames } from './db.js';
4
- import { AssociationNamesForTable, AssociationTableName, DreamAssociationNameToAssociatedModel, JoinAndStatements, MAX_VARIADIC_DEPTH, RequiredOnClauseKeys } from './dream.js';
4
+ import { AssociationNamesForAssociation, AssociationNamesForTable, AssociationTableName, AssociationTableNamesForAssociation, DreamAssociationNameToAssociatedModel, JoinAndStatements, MAX_VARIADIC_DEPTH, RequiredOnClauseKeys } from './dream.js';
5
5
  import { Inc, ReadonlyTail } from './utils.js';
6
6
  type VALID = 'valid';
7
7
  type INVALID = 'invalid';
8
8
  type IS_ASSOCIATION_ALIAS = 'association_alias';
9
9
  type IS_ASSOCIATION_NAME = 'association_name';
10
10
  type IS_NOT_ASSOCIATION_NAME = 'not_association_name';
11
+ type IS_CROSS_POLYMORPHIC_ASSOCIATION_NAME = 'cross_polymorphic_association_name';
11
12
  type RecursionTypes = 'load' | 'leftJoinLoad' | 'join';
13
+ /**
14
+ * Given a union of table names and an association name, returns the
15
+ * specific table(s) from the union that have that association defined.
16
+ * Used when traversing through a polymorphic association to a descendant
17
+ * that only exists on one of the polymorphic targets.
18
+ */
19
+ type TableContainingAssociationInUnion<Schema, TableNamesUnion, AssociationName> = TableNamesUnion extends keyof Schema ? AssociationName extends keyof Schema[TableNamesUnion]['associations' & keyof Schema[TableNamesUnion]] ? TableNamesUnion : never : never;
12
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', ConcreteTableName, 0, null, never, AllowedNextArgValues | Readonly<AllowedNextArgValues[]>>;
13
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 = (keyof SchemaAssociations & string) | AliasedSchemaAssociation<Schema, ConcreteTableName>> = VariadicCheckThenRecurse<I, DB, Schema, ConcreteTableName, ConcreteArgs, 'leftJoinLoad', Camelized<ConcreteTableName>, 0, null, never, AllowedNextArgValues | Readonly<AllowedNextArgValues[]>>;
14
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 = (keyof SchemaAssociations & string) | AliasedSchemaAssociation<Schema, ConcreteTableName>> = VariadicCheckThenRecurse<I, DB, Schema, ConcreteTableName, ConcreteArgs, 'join', Camelized<ConcreteTableName>, 0, null, never, AllowedNextArgValues>;
15
- 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]], NthArgument extends VALID | INVALID = ConcreteArgs['length'] extends 0 ? VALID : ConcreteArgs[0] extends keyof SchemaAssociations & string ? VALID : ConcreteArgs[0] extends AliasedSchemaAssociation<Schema, ConcreteTableName> ? VALID : ConcreteArgs[0] extends JoinAndStatements<LastDream, DB, Schema, ConcreteTableName, RequiredOnClauseKeys<Schema, PreviousConcreteTableName, ConcreteAssociationName>> ? VALID : INVALID> = 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>;
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]], AllowedNamesForArrayArg = PreviousConcreteTableName extends keyof Schema ? AssociationNamesForAssociation<Schema, PreviousConcreteTableName, ConcreteAssociationName> : keyof SchemaAssociations & string, NthArgument extends VALID | INVALID = ConcreteArgs['length'] extends 0 ? VALID : ConcreteArgs[0] extends keyof SchemaAssociations & string ? VALID : ConcreteArgs[0] extends AliasedSchemaAssociation<Schema, ConcreteTableName> ? VALID : ConcreteArgs[0] extends JoinAndStatements<LastDream, DB, Schema, ConcreteTableName, RequiredOnClauseKeys<Schema, PreviousConcreteTableName, ConcreteAssociationName>> ? VALID : ConcreteArgs[0] extends readonly AllowedNamesForArrayArg[] ? VALID : ConcreteArgs[0] extends JoinAndStatements<LastDream, DB, Schema, ConcreteTableName, RequiredOnClauseKeys<Schema, PreviousConcreteTableName, ConcreteAssociationName>> ? VALID : ConcreteArgs[0] extends AllowedNamesForArrayArg ? VALID : INVALID> = 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>;
16
24
  export type AliasedSchemaAssociation<Schema, ConcreteTableName extends keyof Schema, SchemaAssociations = Schema[ConcreteTableName]['associations' & keyof Schema[ConcreteTableName]]> = `${keyof SchemaAssociations & string} as ${string}`;
17
- 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]], ConcreteNthArg extends (keyof SchemaAssociations & string) | AliasedSchemaAssociation<Schema, ConcreteTableName> | 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> : null, NextUsedNamespaces = ConcreteArgs[0] extends undefined ? never : ConcreteArgs[0] extends null ? never : ConcreteArgs[0] extends keyof SchemaAssociations & string ? UsedNamespaces | ConcreteNthArg : UsedNamespaces, CurrentArgumentType extends IS_ASSOCIATION_NAME | IS_ASSOCIATION_ALIAS | IS_NOT_ASSOCIATION_NAME = ConcreteNthArg extends null ? IS_NOT_ASSOCIATION_NAME : ConcreteNthArg extends keyof SchemaAssociations & string ? IS_ASSOCIATION_NAME : ConcreteNthArg extends AliasedSchemaAssociation<Schema, ConcreteTableName> ? IS_ASSOCIATION_ALIAS : IS_NOT_ASSOCIATION_NAME, NextPreviousConcreteTableName = CurrentArgumentType extends IS_ASSOCIATION_NAME ? ConcreteTableName : CurrentArgumentType extends IS_ASSOCIATION_ALIAS ? ConcreteTableName : PreviousConcreteTableName, NextUnaliasedAssociationName = CurrentArgumentType extends IS_ASSOCIATION_NAME ? ConcreteNthArg : CurrentArgumentType extends IS_ASSOCIATION_ALIAS ? ConcreteNthArg extends `${infer AssocName extends string} as ${string}` ? AssocName & keyof SchemaAssociations & string : never : never, NextAliasedAssociationName = CurrentArgumentType extends IS_ASSOCIATION_NAME ? ConcreteNthArg : CurrentArgumentType extends IS_ASSOCIATION_ALIAS ? ConcreteNthArg extends `${string} as ${infer AssocAlias extends string}` ? AssocAlias & string : 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, AllowedNextArgValues = RecursionType extends 'load' ? AllowedNextArgValuesForLoad<DreamAssociationNameToAssociatedModel<LastDream, ConcreteArgs[0] & keyof LastDream>, DB, Schema, NextTableName, RequiredOnClauseKeys<Schema, ConcreteTableName, NextAliasedAssociationName>> : RecursionType extends 'leftJoinLoad' ? AllowedNextArgValuesForLeftJoinLoad<DreamAssociationNameToAssociatedModel<LastDream, ConcreteArgs[0] & keyof LastDream>, DB, Schema, NextTableName, RequiredOnClauseKeys<Schema, ConcreteTableName, NextAliasedAssociationName>, NextUsedNamespaces> : RecursionType extends 'join' ? AllowedNextArgValuesForJoin<DreamAssociationNameToAssociatedModel<LastDream, ConcreteArgs[0] & keyof LastDream>, DB, Schema, NextTableName, RequiredOnClauseKeys<Schema, ConcreteTableName, NextAliasedAssociationName>, NextUsedNamespaces> : never> = Depth extends MAX_VARIADIC_DEPTH ? never : VariadicCheckThenRecurse<I, DB, Schema, NextTableName, ReadonlyTail<ConcreteArgs>, RecursionType, NextUsedNamespaces, Inc<Depth>, NextPreviousConcreteTableName, NextAliasedAssociationName, AllowedNextArgValues, DreamAssociationNameToAssociatedModel<LastDream, ConcreteArgs[0] & keyof LastDream> extends Dream ? DreamAssociationNameToAssociatedModel<LastDream, ConcreteArgs[0] & keyof LastDream> : LastDream>;
18
- type AllowedNextArgValuesForLoad<I extends Dream, DB, Schema, TableName extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB, RequiredOnClauseKeysForThisAssociation> = AssociationNamesForTable<Schema, TableName> | AssociationNamesForTable<Schema, TableName>[] | JoinAndStatements<I, DB, Schema, TableName, RequiredOnClauseKeysForThisAssociation>;
19
- type AllowedNextArgValuesForLeftJoinLoad<I extends Dream, DB, Schema, TableName extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB, RequiredOnClauseKeysForThisAssociation, UsedNamespaces> = Exclude<AssociationNamesForTable<Schema, TableName>, UsedNamespaces> | Exclude<AssociationNamesForTable<Schema, TableName>, UsedNamespaces>[] | JoinAndStatements<I, DB, Schema, TableName, RequiredOnClauseKeysForThisAssociation>;
20
- type AllowedNextArgValuesForJoin<I extends Dream, DB, Schema, TableName extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB, RequiredOnClauseKeysForThisAssociation, UsedNamespaces> = Exclude<AssociationNamesForTable<Schema, TableName>, UsedNamespaces> | JoinAndStatements<I, DB, Schema, TableName, RequiredOnClauseKeysForThisAssociation>;
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 = ConcreteArgs[0] extends string ? TableContainingAssociationInUnion<Schema, PolymorphicTableNamesUnion, ConcreteArgs[0]> : never, EffectiveConcreteTableName extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB = ConcreteArgs[0] 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]], ConcreteNthArg extends (keyof SchemaAssociations & string) | (keyof EffectiveSchemaAssociations & string) | AliasedSchemaAssociation<Schema, ConcreteTableName> | 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 keyof EffectiveSchemaAssociations & string ? ConcreteArgs[0] & keyof EffectiveSchemaAssociations & string : null, NextUsedNamespaces = ConcreteArgs[0] extends undefined ? never : ConcreteArgs[0] extends null ? never : ConcreteNthArg extends null ? UsedNamespaces : UsedNamespaces | ConcreteNthArg, CurrentArgumentType extends IS_ASSOCIATION_NAME | IS_ASSOCIATION_ALIAS | IS_CROSS_POLYMORPHIC_ASSOCIATION_NAME | IS_NOT_ASSOCIATION_NAME = ConcreteNthArg extends null ? IS_NOT_ASSOCIATION_NAME : ConcreteNthArg extends keyof SchemaAssociations & string ? IS_ASSOCIATION_NAME : ConcreteNthArg extends AliasedSchemaAssociation<Schema, ConcreteTableName> ? IS_ASSOCIATION_ALIAS : ConcreteNthArg extends keyof EffectiveSchemaAssociations & string ? IS_CROSS_POLYMORPHIC_ASSOCIATION_NAME : IS_NOT_ASSOCIATION_NAME, NextPreviousConcreteTableName = CurrentArgumentType extends IS_ASSOCIATION_NAME ? ConcreteTableName : CurrentArgumentType extends IS_ASSOCIATION_ALIAS ? ConcreteTableName : CurrentArgumentType extends IS_CROSS_POLYMORPHIC_ASSOCIATION_NAME ? EffectiveConcreteTableName : PreviousConcreteTableName, NextUnaliasedAssociationName = CurrentArgumentType extends IS_ASSOCIATION_NAME ? ConcreteNthArg : CurrentArgumentType extends IS_ASSOCIATION_ALIAS ? ConcreteNthArg extends `${infer AssocName extends string} as ${string}` ? AssocName & keyof SchemaAssociations & string : never : CurrentArgumentType extends IS_CROSS_POLYMORPHIC_ASSOCIATION_NAME ? ConcreteNthArg : never, NextAliasedAssociationName = CurrentArgumentType extends IS_ASSOCIATION_NAME ? ConcreteNthArg : CurrentArgumentType extends IS_ASSOCIATION_ALIAS ? ConcreteNthArg extends `${string} as ${infer AssocAlias extends string}` ? AssocAlias & string : ConcreteAssociationName : CurrentArgumentType extends IS_CROSS_POLYMORPHIC_ASSOCIATION_NAME ? ConcreteNthArg : ConcreteAssociationName, IsAssociationNameOrAlias extends boolean = CurrentArgumentType extends IS_ASSOCIATION_NAME | IS_ASSOCIATION_ALIAS | IS_CROSS_POLYMORPHIC_ASSOCIATION_NAME ? true : false, NextTableName extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB = IsAssociationNameOrAlias extends true ? AssociationTableName<Schema, EffectiveConcreteTableName, NextUnaliasedAssociationName> : ConcreteTableName & AssociationTableNames<DB, Schema> & keyof DB, 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
26
+ AssociationTableOrConcreteTable extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB = IsAssociationNameOrAlias extends true ? AssociationTableName<Schema, EffectiveConcreteTableName, NextUnaliasedAssociationName> : ConcreteTableName, CurrentRequiredOnClauseKeys = IsAssociationNameOrAlias extends true ? RequiredOnClauseKeys<Schema, EffectiveConcreteTableName, NextAliasedAssociationName> : RequiredOnClauseKeys<Schema, PreviousConcreteTableName, ConcreteAssociationName>, AllowedNextArgValues = RecursionType extends 'load' ? AllowedNextArgValuesForLoad<DreamAssociationNameToAssociatedModel<LastDream, ConcreteArgs[0] & keyof LastDream>, DB, Schema, AllowedAssociationNames, AssociationTableOrConcreteTable, CurrentRequiredOnClauseKeys> : RecursionType extends 'leftJoinLoad' ? AllowedNextArgValuesForLeftJoinLoad<DreamAssociationNameToAssociatedModel<LastDream, ConcreteArgs[0] & keyof LastDream>, DB, Schema, AllowedAssociationNames, AssociationTableOrConcreteTable, CurrentRequiredOnClauseKeys, NextUsedNamespaces> : RecursionType extends 'join' ? AllowedNextArgValuesForJoin<DreamAssociationNameToAssociatedModel<LastDream, ConcreteArgs[0] & keyof LastDream>, DB, Schema, AllowedAssociationNames, AssociationTableOrConcreteTable, CurrentRequiredOnClauseKeys, NextUsedNamespaces> : never> = Depth extends MAX_VARIADIC_DEPTH ? never : VariadicCheckThenRecurse<I, DB, Schema, NextTableName, ReadonlyTail<ConcreteArgs>, RecursionType, NextUsedNamespaces, Inc<Depth>, NextPreviousConcreteTableName, NextAliasedAssociationName, AllowedNextArgValues, DreamAssociationNameToAssociatedModel<LastDream, ConcreteArgs[0] & keyof LastDream> extends Dream ? DreamAssociationNameToAssociatedModel<LastDream, ConcreteArgs[0] & keyof LastDream> : LastDream>;
27
+ type AllowedNextArgValuesForLoad<I extends Dream, DB, Schema, AllowedNames, TableForJoin extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB, RequiredOnClauseKeysForThisAssociation> = AllowedNames | AllowedNames[] | JoinAndStatements<I, DB, Schema, TableForJoin, RequiredOnClauseKeysForThisAssociation>;
28
+ type AllowedNextArgValuesForLeftJoinLoad<I extends Dream, DB, Schema, AllowedNames, TableForJoin extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB, RequiredOnClauseKeysForThisAssociation, UsedNamespaces> = Exclude<AllowedNames, UsedNamespaces> | Exclude<AllowedNames, UsedNamespaces>[] | JoinAndStatements<I, DB, Schema, TableForJoin, RequiredOnClauseKeysForThisAssociation>;
29
+ type AllowedNextArgValuesForJoin<I extends Dream, DB, Schema, AllowedNames, TableForJoin extends keyof Schema & AssociationTableNames<DB, Schema> & keyof DB, RequiredOnClauseKeysForThisAssociation, UsedNamespaces> = Exclude<AllowedNames, UsedNamespaces> | JoinAndStatements<I, DB, Schema, TableForJoin, RequiredOnClauseKeysForThisAssociation>;
21
30
  export interface JoinedAssociation {
22
31
  table: string;
23
32
  alias: string;