@rvoh/dream 2.3.0-alpha.6 → 2.3.0-alpha.8

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 (302) hide show
  1. package/dist/cjs/src/Dream.js +2 -40
  2. package/dist/cjs/src/cli/index.js +4 -0
  3. package/dist/cjs/src/dream/Query.js +14 -11
  4. package/dist/cjs/src/dream/QueryDriver/Base.js +0 -14
  5. package/dist/cjs/src/dream/QueryDriver/Kysely.js +86 -74
  6. package/dist/cjs/src/dream/QueryDriver/Postgres.js +10 -2
  7. package/dist/cjs/src/dream/internal/extractAssignableAssociationAttributes.js +9 -0
  8. package/dist/cjs/src/errors/db/DataIncompatibleWithDatabaseField.js +1 -3
  9. package/dist/cjs/src/helpers/areEqual.js +5 -0
  10. package/dist/cjs/src/helpers/cli/ASTBuilder.js +54 -2
  11. package/dist/cjs/src/helpers/cli/ASTKyselyCodegenEnhancer.js +84 -0
  12. package/dist/cjs/src/helpers/cli/ASTSchemaBuilder.js +17 -1
  13. package/dist/cjs/src/helpers/cli/generateFactoryContent.js +16 -0
  14. package/dist/cjs/src/helpers/cloneDeepSafe.js +21 -10
  15. package/dist/cjs/src/helpers/customPgParsers.js +18 -1
  16. package/dist/cjs/src/helpers/db/normalizeDataForDb.js +81 -0
  17. package/dist/cjs/src/helpers/db/types/helpers.js +5 -0
  18. package/dist/cjs/src/helpers/db/types/isDatetimeOrDatetimeArrayColumn.js +2 -1
  19. package/dist/cjs/src/helpers/sortBy.js +7 -5
  20. package/dist/cjs/src/helpers/sqlAttributes.js +4 -53
  21. package/dist/cjs/src/helpers/stringCasing.js +6 -5
  22. package/dist/cjs/src/helpers/toSafeObject.js +17 -0
  23. package/dist/cjs/src/package-exports/errors.js +2 -0
  24. package/dist/cjs/src/package-exports/index.js +2 -0
  25. package/dist/cjs/src/serializer/SerializerRenderer.js +11 -11
  26. package/dist/cjs/src/types/clocktime.js +1 -0
  27. package/dist/cjs/src/utils/datetime/BaseClockTime.js +363 -0
  28. package/dist/cjs/src/utils/datetime/CalendarDate.js +110 -119
  29. package/dist/cjs/src/utils/datetime/ClockTime.js +173 -0
  30. package/dist/cjs/src/utils/datetime/ClockTimeTz.js +232 -0
  31. package/dist/cjs/src/utils/datetime/DateTime.js +288 -193
  32. package/dist/cjs/src/utils/datetime/helpers/isoTimeDecimalString.js +1 -1
  33. package/dist/esm/src/Dream.js +2 -40
  34. package/dist/esm/src/cli/index.js +4 -0
  35. package/dist/esm/src/dream/Query.js +14 -11
  36. package/dist/esm/src/dream/QueryDriver/Base.js +0 -14
  37. package/dist/esm/src/dream/QueryDriver/Kysely.js +86 -74
  38. package/dist/esm/src/dream/QueryDriver/Postgres.js +10 -2
  39. package/dist/esm/src/dream/internal/extractAssignableAssociationAttributes.js +9 -0
  40. package/dist/esm/src/errors/db/DataIncompatibleWithDatabaseField.js +1 -3
  41. package/dist/esm/src/helpers/areEqual.js +5 -0
  42. package/dist/esm/src/helpers/cli/ASTBuilder.js +54 -2
  43. package/dist/esm/src/helpers/cli/ASTKyselyCodegenEnhancer.js +84 -0
  44. package/dist/esm/src/helpers/cli/ASTSchemaBuilder.js +17 -1
  45. package/dist/esm/src/helpers/cli/generateFactoryContent.js +16 -0
  46. package/dist/esm/src/helpers/cloneDeepSafe.js +21 -10
  47. package/dist/esm/src/helpers/customPgParsers.js +18 -1
  48. package/dist/esm/src/helpers/db/normalizeDataForDb.js +81 -0
  49. package/dist/esm/src/helpers/db/types/helpers.js +5 -0
  50. package/dist/esm/src/helpers/db/types/isDatetimeOrDatetimeArrayColumn.js +2 -1
  51. package/dist/esm/src/helpers/sortBy.js +7 -5
  52. package/dist/esm/src/helpers/sqlAttributes.js +4 -53
  53. package/dist/esm/src/helpers/stringCasing.js +6 -5
  54. package/dist/esm/src/helpers/toSafeObject.js +17 -0
  55. package/dist/esm/src/package-exports/errors.js +2 -0
  56. package/dist/esm/src/package-exports/index.js +2 -0
  57. package/dist/esm/src/serializer/SerializerRenderer.js +11 -11
  58. package/dist/esm/src/types/clocktime.js +1 -0
  59. package/dist/esm/src/utils/datetime/BaseClockTime.js +363 -0
  60. package/dist/esm/src/utils/datetime/CalendarDate.js +110 -119
  61. package/dist/esm/src/utils/datetime/ClockTime.js +173 -0
  62. package/dist/esm/src/utils/datetime/ClockTimeTz.js +232 -0
  63. package/dist/esm/src/utils/datetime/DateTime.js +288 -193
  64. package/dist/esm/src/utils/datetime/helpers/isoTimeDecimalString.js +1 -1
  65. package/dist/types/src/Dream.d.ts +29 -33
  66. package/dist/types/src/dream/DreamClassTransactionBuilder.d.ts +9 -10
  67. package/dist/types/src/dream/DreamInstanceTransactionBuilder.d.ts +16 -16
  68. package/dist/types/src/dream/LeftJoinLoadBuilder.d.ts +1 -1
  69. package/dist/types/src/dream/LoadBuilder.d.ts +1 -1
  70. package/dist/types/src/dream/Query.d.ts +16 -16
  71. package/dist/types/src/dream/QueryDriver/Base.d.ts +0 -1
  72. package/dist/types/src/dream/QueryDriver/Kysely.d.ts +1 -0
  73. package/dist/types/src/dream/internal/associations/associationQuery.d.ts +1 -1
  74. package/dist/types/src/dream/internal/associations/associationUpdateQuery.d.ts +1 -1
  75. package/dist/types/src/dream/internal/associations/destroyAssociation.d.ts +1 -1
  76. package/dist/types/src/dream/internal/associations/throughAssociationHasOptionsBesidesThroughAndSource.d.ts +4 -2
  77. package/dist/types/src/dream/internal/associations/undestroyAssociation.d.ts +1 -1
  78. package/dist/types/src/dream/internal/extractAssignableAssociationAttributes.d.ts +3 -0
  79. package/dist/types/src/dream/internal/similarity/SimilarityBuilder.d.ts +7 -7
  80. package/dist/types/src/errors/db/DataIncompatibleWithDatabaseField.d.ts +2 -7
  81. package/dist/types/src/helpers/cli/ASTBuilder.d.ts +31 -0
  82. package/dist/types/src/helpers/cli/ASTKyselyCodegenEnhancer.d.ts +13 -0
  83. package/dist/types/src/helpers/customPgParsers.d.ts +5 -0
  84. package/dist/types/src/helpers/db/normalizeDataForDb.d.ts +6 -0
  85. package/dist/types/src/helpers/db/types/helpers.d.ts +5 -0
  86. package/dist/types/src/helpers/sort.d.ts +2 -1
  87. package/dist/types/src/helpers/sortBy.d.ts +3 -0
  88. package/dist/types/src/helpers/toSafeObject.d.ts +8 -0
  89. package/dist/types/src/package-exports/errors.d.ts +2 -0
  90. package/dist/types/src/package-exports/index.d.ts +2 -0
  91. package/dist/types/src/package-exports/types.d.ts +2 -1
  92. package/dist/types/src/types/associations/shared.d.ts +15 -13
  93. package/dist/types/src/types/associations/shared.ts +81 -41
  94. package/dist/types/src/types/calendardate.d.ts +22 -1
  95. package/dist/types/src/types/calendardate.ts +33 -1
  96. package/dist/types/src/types/clocktime.d.ts +22 -0
  97. package/dist/types/src/types/clocktime.ts +59 -0
  98. package/dist/types/src/types/datetime.d.ts +11 -18
  99. package/dist/types/src/types/datetime.ts +16 -21
  100. package/dist/types/src/types/dream.d.ts +27 -13
  101. package/dist/types/src/types/dream.ts +40 -14
  102. package/dist/types/src/types/variadic.d.ts +10 -9
  103. package/dist/types/src/types/variadic.ts +30 -5
  104. package/dist/types/src/utils/datetime/BaseClockTime.d.ts +287 -0
  105. package/dist/types/src/utils/datetime/CalendarDate.d.ts +65 -47
  106. package/dist/types/src/utils/datetime/ClockTime.d.ts +138 -0
  107. package/dist/types/src/utils/datetime/ClockTimeTz.d.ts +194 -0
  108. package/dist/types/src/utils/datetime/DateTime.d.ts +142 -56
  109. package/dist/types/src/utils/datetime/helpers/isoTimeDecimalString.d.ts +1 -1
  110. package/docs/assets/navigation.js +1 -1
  111. package/docs/assets/search.js +1 -1
  112. package/docs/classes/db.DreamMigrationHelpers.html +9 -9
  113. package/docs/classes/db.KyselyQueryDriver.html +33 -34
  114. package/docs/classes/db.PostgresQueryDriver.html +34 -35
  115. package/docs/classes/db.QueryDriverBase.html +32 -33
  116. package/docs/classes/errors.CheckConstraintViolation.html +4 -6
  117. package/docs/classes/errors.ColumnOverflow.html +4 -6
  118. package/docs/classes/errors.CreateOrFindByFailedToCreateAndFind.html +3 -3
  119. package/docs/classes/errors.DataIncompatibleWithDatabaseField.html +4 -6
  120. package/docs/classes/errors.DataTypeColumnTypeMismatch.html +4 -6
  121. package/docs/classes/errors.GlobalNameNotSet.html +3 -3
  122. package/docs/classes/errors.InvalidCalendarDate.html +2 -2
  123. package/docs/classes/errors.InvalidClockTime.html +17 -0
  124. package/docs/classes/errors.InvalidClockTimeTz.html +17 -0
  125. package/docs/classes/errors.InvalidDateTime.html +2 -2
  126. package/docs/classes/errors.MissingSerializersDefinition.html +3 -3
  127. package/docs/classes/errors.NonLoadedAssociation.html +3 -3
  128. package/docs/classes/errors.NotNullViolation.html +4 -6
  129. package/docs/classes/errors.RecordNotFound.html +3 -3
  130. package/docs/classes/errors.ValidationError.html +3 -3
  131. package/docs/classes/index.CalendarDate.html +80 -92
  132. package/docs/classes/index.ClockTime.html +232 -0
  133. package/docs/classes/index.ClockTimeTz.html +253 -0
  134. package/docs/classes/index.DateTime.html +123 -129
  135. package/docs/classes/index.Decorators.html +19 -19
  136. package/docs/classes/index.Dream.html +127 -127
  137. package/docs/classes/index.DreamApp.html +5 -5
  138. package/docs/classes/index.DreamTransaction.html +2 -2
  139. package/docs/classes/index.Env.html +2 -2
  140. package/docs/classes/index.Query.html +71 -71
  141. package/docs/classes/system.CliFileWriter.html +2 -2
  142. package/docs/classes/system.DreamBin.html +2 -2
  143. package/docs/classes/system.DreamCLI.html +5 -5
  144. package/docs/classes/system.DreamImporter.html +2 -2
  145. package/docs/classes/system.DreamLogos.html +2 -2
  146. package/docs/classes/system.DreamSerializerBuilder.html +8 -8
  147. package/docs/classes/system.ObjectSerializerBuilder.html +8 -8
  148. package/docs/classes/system.PathHelpers.html +3 -3
  149. package/docs/classes/utils.Encrypt.html +2 -2
  150. package/docs/classes/utils.Range.html +2 -2
  151. package/docs/functions/db.closeAllDbConnections.html +1 -1
  152. package/docs/functions/db.dreamDbConnections.html +1 -1
  153. package/docs/functions/db.untypedDb.html +1 -1
  154. package/docs/functions/db.validateColumn.html +1 -1
  155. package/docs/functions/db.validateTable.html +1 -1
  156. package/docs/functions/errors.pgErrorType.html +1 -1
  157. package/docs/functions/index.DreamSerializer.html +1 -1
  158. package/docs/functions/index.ObjectSerializer.html +1 -1
  159. package/docs/functions/index.ReplicaSafe.html +1 -1
  160. package/docs/functions/index.STI.html +1 -1
  161. package/docs/functions/index.SoftDelete.html +1 -1
  162. package/docs/functions/utils.camelize.html +1 -1
  163. package/docs/functions/utils.capitalize.html +1 -1
  164. package/docs/functions/utils.cloneDeepSafe.html +1 -1
  165. package/docs/functions/utils.compact.html +1 -1
  166. package/docs/functions/utils.groupBy.html +1 -1
  167. package/docs/functions/utils.hyphenize.html +1 -1
  168. package/docs/functions/utils.intersection.html +1 -1
  169. package/docs/functions/utils.isEmpty.html +1 -1
  170. package/docs/functions/utils.normalizeUnicode.html +1 -1
  171. package/docs/functions/utils.pascalize.html +1 -1
  172. package/docs/functions/utils.percent.html +1 -1
  173. package/docs/functions/utils.range-1.html +1 -1
  174. package/docs/functions/utils.round.html +1 -1
  175. package/docs/functions/utils.sanitizeString.html +1 -1
  176. package/docs/functions/utils.snakeify.html +1 -1
  177. package/docs/functions/utils.sort.html +1 -1
  178. package/docs/functions/utils.sortBy.html +1 -1
  179. package/docs/functions/utils.sortObjectByKey.html +1 -1
  180. package/docs/functions/utils.sortObjectByValue.html +1 -1
  181. package/docs/functions/utils.uncapitalize.html +1 -1
  182. package/docs/functions/utils.uniq.html +1 -1
  183. package/docs/interfaces/openapi.OpenapiDescription.html +2 -2
  184. package/docs/interfaces/openapi.OpenapiSchemaProperties.html +1 -1
  185. package/docs/interfaces/openapi.OpenapiSchemaPropertiesShorthand.html +1 -1
  186. package/docs/interfaces/openapi.OpenapiTypeFieldObject.html +1 -1
  187. package/docs/interfaces/types.BelongsToStatement.html +2 -2
  188. package/docs/interfaces/types.DecoratorContext.html +2 -2
  189. package/docs/interfaces/types.DreamAppInitOptions.html +2 -2
  190. package/docs/interfaces/types.DreamAppOpts.html +2 -2
  191. package/docs/interfaces/types.DurationObject.html +5 -5
  192. package/docs/interfaces/types.EncryptOptions.html +2 -2
  193. package/docs/interfaces/types.InternalAnyTypedSerializerRendersMany.html +2 -2
  194. package/docs/interfaces/types.InternalAnyTypedSerializerRendersOne.html +2 -2
  195. package/docs/interfaces/types.SerializerRendererOpts.html +2 -2
  196. package/docs/modules/db.html +1 -1
  197. package/docs/modules/errors.html +3 -1
  198. package/docs/modules/index.html +3 -1
  199. package/docs/modules/openapi.html +1 -1
  200. package/docs/modules/system.html +1 -1
  201. package/docs/modules/types.html +3 -1
  202. package/docs/modules/utils.html +1 -1
  203. package/docs/types/openapi.CommonOpenapiSchemaObjectFields.html +1 -1
  204. package/docs/types/openapi.OpenapiAllTypes.html +1 -1
  205. package/docs/types/openapi.OpenapiFormats.html +1 -1
  206. package/docs/types/openapi.OpenapiNumberFormats.html +1 -1
  207. package/docs/types/openapi.OpenapiPrimitiveBaseTypes.html +1 -1
  208. package/docs/types/openapi.OpenapiPrimitiveTypes.html +1 -1
  209. package/docs/types/openapi.OpenapiSchemaArray.html +1 -1
  210. package/docs/types/openapi.OpenapiSchemaArrayShorthand.html +1 -1
  211. package/docs/types/openapi.OpenapiSchemaBase.html +1 -1
  212. package/docs/types/openapi.OpenapiSchemaBody.html +1 -1
  213. package/docs/types/openapi.OpenapiSchemaBodyShorthand.html +1 -1
  214. package/docs/types/openapi.OpenapiSchemaCommonFields.html +1 -1
  215. package/docs/types/openapi.OpenapiSchemaExpressionAllOf.html +1 -1
  216. package/docs/types/openapi.OpenapiSchemaExpressionAnyOf.html +1 -1
  217. package/docs/types/openapi.OpenapiSchemaExpressionOneOf.html +1 -1
  218. package/docs/types/openapi.OpenapiSchemaExpressionRef.html +1 -1
  219. package/docs/types/openapi.OpenapiSchemaExpressionRefSchemaShorthand.html +1 -1
  220. package/docs/types/openapi.OpenapiSchemaInteger.html +1 -1
  221. package/docs/types/openapi.OpenapiSchemaNull.html +1 -1
  222. package/docs/types/openapi.OpenapiSchemaNumber.html +1 -1
  223. package/docs/types/openapi.OpenapiSchemaObject.html +1 -1
  224. package/docs/types/openapi.OpenapiSchemaObjectAllOf.html +1 -1
  225. package/docs/types/openapi.OpenapiSchemaObjectAllOfShorthand.html +1 -1
  226. package/docs/types/openapi.OpenapiSchemaObjectAnyOf.html +1 -1
  227. package/docs/types/openapi.OpenapiSchemaObjectAnyOfShorthand.html +1 -1
  228. package/docs/types/openapi.OpenapiSchemaObjectBase.html +1 -1
  229. package/docs/types/openapi.OpenapiSchemaObjectBaseShorthand.html +1 -1
  230. package/docs/types/openapi.OpenapiSchemaObjectOneOf.html +1 -1
  231. package/docs/types/openapi.OpenapiSchemaObjectOneOfShorthand.html +1 -1
  232. package/docs/types/openapi.OpenapiSchemaObjectShorthand.html +1 -1
  233. package/docs/types/openapi.OpenapiSchemaPrimitiveGeneric.html +1 -1
  234. package/docs/types/openapi.OpenapiSchemaShorthandExpressionAllOf.html +1 -1
  235. package/docs/types/openapi.OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
  236. package/docs/types/openapi.OpenapiSchemaShorthandExpressionOneOf.html +1 -1
  237. package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
  238. package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
  239. package/docs/types/openapi.OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
  240. package/docs/types/openapi.OpenapiSchemaString.html +1 -1
  241. package/docs/types/openapi.OpenapiShorthandAllTypes.html +1 -1
  242. package/docs/types/openapi.OpenapiShorthandPrimitiveBaseTypes.html +1 -1
  243. package/docs/types/openapi.OpenapiShorthandPrimitiveTypes.html +1 -1
  244. package/docs/types/openapi.OpenapiTypeField.html +1 -1
  245. package/docs/types/system.DreamAppAllowedPackageManagersEnum.html +1 -1
  246. package/docs/types/types.CalendarDateDurationUnit.html +1 -1
  247. package/docs/types/types.CalendarDateObject.html +2 -0
  248. package/docs/types/types.Camelized.html +1 -1
  249. package/docs/types/types.ClockTimeObject.html +2 -0
  250. package/docs/types/types.DbConnectionType.html +1 -1
  251. package/docs/types/types.DbTypes.html +1 -1
  252. package/docs/types/types.DreamAssociationMetadata.html +1 -1
  253. package/docs/types/types.DreamAttributes.html +1 -1
  254. package/docs/types/types.DreamClassAssociationAndStatement.html +1 -1
  255. package/docs/types/types.DreamClassColumn.html +1 -1
  256. package/docs/types/types.DreamColumn.html +1 -1
  257. package/docs/types/types.DreamColumnNames.html +1 -1
  258. package/docs/types/types.DreamLogLevel.html +1 -1
  259. package/docs/types/types.DreamLogger.html +1 -1
  260. package/docs/types/types.DreamModelSerializerType.html +1 -1
  261. package/docs/types/types.DreamOrViewModelClassSerializerKey.html +1 -1
  262. package/docs/types/types.DreamOrViewModelSerializerKey.html +1 -1
  263. package/docs/types/types.DreamParamSafeAttributes.html +1 -1
  264. package/docs/types/types.DreamParamSafeColumnNames.html +1 -1
  265. package/docs/types/types.DreamSerializable.html +1 -1
  266. package/docs/types/types.DreamSerializableArray.html +1 -1
  267. package/docs/types/types.DreamSerializerKey.html +1 -1
  268. package/docs/types/types.DreamSerializers.html +1 -1
  269. package/docs/types/types.DreamVirtualColumns.html +1 -1
  270. package/docs/types/types.DurationUnit.html +2 -4
  271. package/docs/types/types.EncryptAlgorithm.html +1 -1
  272. package/docs/types/types.HasManyStatement.html +1 -1
  273. package/docs/types/types.HasOneStatement.html +1 -1
  274. package/docs/types/types.Hyphenized.html +1 -1
  275. package/docs/types/types.Pascalized.html +1 -1
  276. package/docs/types/types.PrimaryKeyType.html +1 -1
  277. package/docs/types/types.RoundingPrecision.html +1 -1
  278. package/docs/types/types.SerializerCasing.html +1 -1
  279. package/docs/types/types.SimpleObjectSerializerType.html +1 -1
  280. package/docs/types/types.Snakeified.html +1 -1
  281. package/docs/types/types.StrictInterface.html +1 -1
  282. package/docs/types/types.UpdateableAssociationProperties.html +1 -1
  283. package/docs/types/types.UpdateableProperties.html +1 -1
  284. package/docs/types/types.ValidationType.html +1 -1
  285. package/docs/types/types.ViewModel.html +1 -1
  286. package/docs/types/types.ViewModelClass.html +1 -1
  287. package/docs/types/types.WeekdayName.html +1 -1
  288. package/docs/types/types.WhereStatementForDream.html +1 -1
  289. package/docs/types/types.WhereStatementForDreamClass.html +1 -1
  290. package/docs/variables/index.DreamConst.html +1 -1
  291. package/docs/variables/index.ops.html +1 -1
  292. package/docs/variables/openapi.openapiPrimitiveTypes-1.html +1 -1
  293. package/docs/variables/openapi.openapiShorthandPrimitiveTypes-1.html +1 -1
  294. package/docs/variables/system.DreamAppAllowedPackageManagersEnumValues.html +1 -1
  295. package/docs/variables/system.primaryKeyTypes.html +1 -1
  296. package/package.json +2 -2
  297. package/dist/cjs/src/helpers/db/types/isDateOrDateArrayColumn.js +0 -3
  298. package/dist/cjs/src/helpers/db/types/isTextOrTextArrayColumn.js +0 -3
  299. package/dist/esm/src/helpers/db/types/isDateOrDateArrayColumn.js +0 -3
  300. package/dist/esm/src/helpers/db/types/isTextOrTextArrayColumn.js +0 -3
  301. package/dist/types/src/helpers/db/types/isDateOrDateArrayColumn.d.ts +0 -2
  302. package/dist/types/src/helpers/db/types/isTextOrTextArrayColumn.d.ts +0 -2
@@ -44,14 +44,13 @@ import DreamMissingRequiredOverride from './errors/DreamMissingRequiredOverride.
44
44
  import NonExistentScopeProvidedToResort from './errors/NonExistentScopeProvidedToResort.js';
45
45
  import RecordNotFound from './errors/RecordNotFound.js';
46
46
  import MissingSerializersDefinition from './errors/serializers/MissingSerializersDefinition.js';
47
+ import areEqual from './helpers/areEqual.js';
47
48
  import cloneDeepSafe from './helpers/cloneDeepSafe.js';
48
49
  import compact from './helpers/compact.js';
49
50
  import cachedTypeForAttribute from './helpers/db/cachedTypeForAttribute.js';
50
51
  import isJsonColumn from './helpers/db/types/isJsonColumn.js';
51
52
  import notEqual from './helpers/notEqual.js';
52
53
  import { inferSerializersFromDreamClassOrViewModelClass } from './serializer/helpers/inferSerializerFromDreamOrViewModel.js';
53
- import CalendarDate from './utils/datetime/CalendarDate.js';
54
- import { DateTime } from './utils/datetime/DateTime.js';
55
54
  const RECURSIVE_SERIALIZATION_MAX_REPEATS = 4;
56
55
  export default class Dream {
57
56
  DB;
@@ -2890,7 +2889,6 @@ export default class Dream {
2890
2889
  dirtyAttributes() {
2891
2890
  const obj = {};
2892
2891
  this.columns().forEach(column => {
2893
- // TODO: clean up types
2894
2892
  if (this.attributeIsDirty(column))
2895
2893
  obj[column] = this.getAttribute(column);
2896
2894
  });
@@ -2902,45 +2900,9 @@ export default class Dream {
2902
2900
  * @returns A boolean
2903
2901
  */
2904
2902
  attributeIsDirty(attribute) {
2905
- const frozenValue = this.frozenAttributes[attribute];
2906
- const currentValue = this.getAttribute(attribute);
2907
2903
  if (this.isNewRecord)
2908
2904
  return true;
2909
- if (frozenValue instanceof DateTime) {
2910
- return frozenValue.toMicroseconds() !== this.unknownValueToMicroseconds(currentValue);
2911
- }
2912
- else if (frozenValue instanceof CalendarDate) {
2913
- return frozenValue.toISO() !== this.unknownValueToDateString(currentValue);
2914
- }
2915
- else {
2916
- return frozenValue !== currentValue;
2917
- }
2918
- }
2919
- /**
2920
- * @internal
2921
- */
2922
- unknownValueToMicroseconds(currentValue) {
2923
- if (!currentValue)
2924
- return;
2925
- if (typeof currentValue === 'string')
2926
- currentValue = DateTime.fromISO(currentValue);
2927
- if (currentValue instanceof CalendarDate)
2928
- currentValue = currentValue.toDateTime();
2929
- if (currentValue instanceof DateTime)
2930
- return currentValue.toMicroseconds();
2931
- }
2932
- /**
2933
- * @internal
2934
- */
2935
- unknownValueToDateString(currentValue) {
2936
- if (!currentValue)
2937
- return;
2938
- if (typeof currentValue === 'string')
2939
- currentValue = CalendarDate.fromISO(currentValue);
2940
- if (currentValue instanceof DateTime)
2941
- currentValue = CalendarDate.fromDateTime(currentValue);
2942
- if (currentValue instanceof CalendarDate)
2943
- return currentValue.toISO();
2905
+ return !areEqual(this.frozenAttributes[attribute], this.getAttribute(attribute));
2944
2906
  }
2945
2907
  /**
2946
2908
  * Deletes the record represented by this instance
@@ -32,6 +32,10 @@ ${INDENT} - date
32
32
  ${INDENT} - date[]
33
33
  ${INDENT} - datetime
34
34
  ${INDENT} - datetime[]
35
+ ${INDENT} - time
36
+ ${INDENT} - time[]
37
+ ${INDENT} - timetz
38
+ ${INDENT} - timetz[]
35
39
  ${INDENT} - integer
36
40
  ${INDENT} - integer[]
37
41
  ${INDENT}
@@ -15,6 +15,7 @@ import cloneDeepSafe from '../helpers/cloneDeepSafe.js';
15
15
  import isObject from '../helpers/isObject.js';
16
16
  import namespaceColumn from '../helpers/namespaceColumn.js';
17
17
  import protectAgainstPollutingAssignment from '../helpers/protectAgainstPollutingAssignment.js';
18
+ import { toSafeObject } from '../helpers/toSafeObject.js';
18
19
  import ops from '../ops/index.js';
19
20
  import computedPaginatePage from './internal/computedPaginatePage.js';
20
21
  import convertDreamClassAndAssociationNameTupleArrayToPreloadArgs from './internal/convertDreamClassAndAssociationNameTupleArrayToPreloadArgs.js';
@@ -543,8 +544,8 @@ export default class Query {
543
544
  */
544
545
  innerJoin(...args) {
545
546
  const innerJoinDreamClasses = [...this.innerJoinDreamClasses];
546
- const innerJoinStatements = cloneDeepSafe(this.innerJoinStatements);
547
- const innerJoinAndStatements = cloneDeepSafe(this.innerJoinAndStatements);
547
+ const innerJoinStatements = toSafeObject(cloneDeepSafe(this.innerJoinStatements));
548
+ const innerJoinAndStatements = toSafeObject(cloneDeepSafe(this.innerJoinAndStatements));
548
549
  this.fleshOutJoinStatements(innerJoinDreamClasses, innerJoinStatements, innerJoinAndStatements, null, [...args]);
549
550
  return this.clone({
550
551
  innerJoinDreamClasses,
@@ -560,8 +561,8 @@ export default class Query {
560
561
  */
561
562
  leftJoin(...args) {
562
563
  const innerJoinDreamClasses = [...this.innerJoinDreamClasses];
563
- const leftJoinStatements = cloneDeepSafe(this.leftJoinStatements);
564
- const leftJoinAndStatements = cloneDeepSafe(this.leftJoinAndStatements);
564
+ const leftJoinStatements = toSafeObject(cloneDeepSafe(this.leftJoinStatements));
565
+ const leftJoinAndStatements = toSafeObject(cloneDeepSafe(this.leftJoinAndStatements));
565
566
  this.fleshOutJoinStatements(innerJoinDreamClasses, leftJoinStatements, leftJoinAndStatements, null, [
566
567
  ...args,
567
568
  ]);
@@ -582,13 +583,15 @@ export default class Query {
582
583
  }
583
584
  else if (typeof nextAssociationStatement === 'string') {
584
585
  const nextStatement = nextAssociationStatement;
585
- if (!joinStatements[nextStatement])
586
- joinStatements[protectAgainstPollutingAssignment(nextStatement)] = {};
587
- if (!joinAndStatements[nextStatement])
588
- joinAndStatements[protectAgainstPollutingAssignment(nextStatement)] = {};
586
+ const safeKey = protectAgainstPollutingAssignment(nextStatement);
587
+ // Use prototype-less containers so assigning untrusted keys cannot pollute Object.prototype.
588
+ if (!joinStatements[safeKey])
589
+ joinStatements[safeKey] = Object.create(null);
590
+ if (!joinAndStatements[safeKey])
591
+ joinAndStatements[safeKey] = Object.create(null);
589
592
  const nextDreamClass = this.addAssociatedDreamClassToInnerJoinDreamClasses(previousDreamClass, nextStatement, innerJoinDreamClasses);
590
- const nextJoinsStatements = joinStatements[nextStatement];
591
- const nextJoinsOnStatements = joinAndStatements[nextStatement];
593
+ const nextJoinsStatements = joinStatements[safeKey];
594
+ const nextJoinsOnStatements = joinAndStatements[safeKey];
592
595
  this.fleshOutJoinStatements(innerJoinDreamClasses, nextJoinsStatements, nextJoinsOnStatements, nextStatement, associationStatements, nextDreamClass);
593
596
  //
594
597
  }
@@ -598,7 +601,7 @@ export default class Query {
598
601
  this.addAssociatedDreamClassToInnerJoinDreamClasses(previousDreamClass, associationName, innerJoinDreamClasses);
599
602
  });
600
603
  nextAssociationStatement.forEach(associationStatement => {
601
- joinStatements[protectAgainstPollutingAssignment(associationStatement)] = {};
604
+ joinStatements[protectAgainstPollutingAssignment(associationStatement)] = Object.create(null);
602
605
  });
603
606
  //
604
607
  }
@@ -1,5 +1,3 @@
1
- import CalendarDate from '../../utils/datetime/CalendarDate.js';
2
- import { DateTime } from '../../utils/datetime/DateTime.js';
3
1
  export default class QueryDriverBase {
4
2
  query;
5
3
  dreamClass;
@@ -176,18 +174,6 @@ export default class QueryDriverBase {
176
174
  allTableAssociationData) {
177
175
  throw new Error('implement getColumnData in child class');
178
176
  }
179
- static serializeDbType(type, val) {
180
- switch (type) {
181
- case 'datetime':
182
- case 'date':
183
- if (val instanceof DateTime || val instanceof CalendarDate) {
184
- return val.toSQL();
185
- }
186
- throw new Error(`unrecognized value found when trying to serialize for date/datetime: ${val}`);
187
- default:
188
- return val;
189
- }
190
- }
191
177
  /**
192
178
  * @internal
193
179
  *
@@ -17,6 +17,7 @@ import { default as _db } from '../../db/index.js';
17
17
  import associationToGetterSetterProp from '../../decorators/field/association/associationToGetterSetterProp.js';
18
18
  import PackageManager from '../../dream-app/helpers/PackageManager.js';
19
19
  import DreamApp from '../../dream-app/index.js';
20
+ import Dream from '../../Dream.js';
20
21
  import ArrayTargetIncompatibleWithThroughAssociation from '../../errors/associations/ArrayTargetIncompatibleWithThroughAssociation.js';
21
22
  import CannotJoinPolymorphicBelongsToError from '../../errors/associations/CannotJoinPolymorphicBelongsToError.js';
22
23
  import JoinAttemptedOnMissingAssociation from '../../errors/associations/JoinAttemptedOnMissingAssociation.js';
@@ -37,12 +38,12 @@ import ASTGlobalSchemaBuilder from '../../helpers/cli/ASTGlobalSchemaBuilder.js'
37
38
  import ASTSchemaBuilder from '../../helpers/cli/ASTSchemaBuilder.js';
38
39
  import generateMigration from '../../helpers/cli/generateMigration.js';
39
40
  import compact from '../../helpers/compact.js';
41
+ import { normalizeDataForDb } from '../../helpers/db/normalizeDataForDb.js';
40
42
  import EnvInternal from '../../helpers/EnvInternal.js';
41
43
  import groupBy from '../../helpers/groupBy.js';
42
44
  import isEmpty from '../../helpers/isEmpty.js';
43
45
  import maybeNamespacedColumnNameToColumnName from '../../helpers/maybeNamespacedColumnNameToColumnName.js';
44
46
  import namespaceColumn from '../../helpers/namespaceColumn.js';
45
- import normalizeUnicode from '../../helpers/normalizeUnicode.js';
46
47
  import objectPathsToArrays from '../../helpers/objectPathsToArrays.js';
47
48
  import pascalize from '../../helpers/pascalize.js';
48
49
  import protectAgainstPollutingAssignment from '../../helpers/protectAgainstPollutingAssignment.js';
@@ -52,13 +53,12 @@ import sqlAttributes from '../../helpers/sqlAttributes.js';
52
53
  import uniq from '../../helpers/uniq.js';
53
54
  import CurriedOpsStatement from '../../ops/curried-ops-statement.js';
54
55
  import OpsStatement from '../../ops/ops-statement.js';
55
- import CalendarDate from '../../utils/datetime/CalendarDate.js';
56
- import { DateTime } from '../../utils/datetime/DateTime.js';
57
56
  import { DreamConst, primaryKeyTypes } from '../constants.js';
58
57
  import DreamTransaction from '../DreamTransaction.js';
59
58
  import throughAssociationHasOptionsBesidesThroughAndSource from '../internal/associations/throughAssociationHasOptionsBesidesThroughAndSource.js';
60
59
  import associationStringToNameAndAlias from '../internal/associationStringToNameAndAlias.js';
61
60
  import executeDatabaseQuery from '../internal/executeDatabaseQuery.js';
61
+ import extractAssignableAssociationAttributes from '../internal/extractAssignableAssociationAttributes.js';
62
62
  import orderByDirection from '../internal/orderByDirection.js';
63
63
  import shouldBypassDefaultScope from '../internal/shouldBypassDefaultScope.js';
64
64
  import SimilarityBuilder from '../internal/similarity/SimilarityBuilder.js';
@@ -614,25 +614,13 @@ export default class KyselyQueryDriver extends QueryDriverBase {
614
614
  catch (error) {
615
615
  switch (pgErrorType(error)) {
616
616
  case COLUMN_OVERFLOW:
617
- throw new ColumnOverflow({
618
- dream,
619
- error: error instanceof Error ? error : new Error('database column overflow'),
620
- });
617
+ throw new ColumnOverflow(error instanceof Error ? error : new Error('database column overflow'));
621
618
  case INVALID_INPUT_SYNTAX:
622
- throw new DataTypeColumnTypeMismatch({
623
- dream,
624
- error: error instanceof Error ? error : new Error('database column type error'),
625
- });
619
+ throw new DataTypeColumnTypeMismatch(error instanceof Error ? error : new Error('database column type error'));
626
620
  case NOT_NULL_VIOLATION:
627
- throw new NotNullViolation({
628
- dream,
629
- error: error instanceof Error ? error : new Error('not null violation'),
630
- });
621
+ throw new NotNullViolation(error instanceof Error ? error : new Error('not null violation'));
631
622
  case CHECK_VIOLATION:
632
- throw new CheckConstraintViolation({
633
- dream,
634
- error: error instanceof Error ? error : new Error('check constraint violation'),
635
- });
623
+ throw new CheckConstraintViolation(error instanceof Error ? error : new Error('check constraint violation'));
636
624
  }
637
625
  throw error;
638
626
  }
@@ -959,35 +947,35 @@ export default class KyselyQueryDriver extends QueryDriverBase {
959
947
  });
960
948
  return dream;
961
949
  }
962
- applyJoinAndStatement(join, joinAndStatement, rootTableOrAssociationAlias) {
950
+ applyJoinAndStatement(dreamClass, join, joinAndStatement, rootTableOrAssociationAlias) {
963
951
  if (!joinAndStatement)
964
952
  return join;
965
- join = this._applyJoinAndStatements(join, joinAndStatement.and, rootTableOrAssociationAlias);
966
- join = this._applyJoinAndStatements(join, joinAndStatement.andNot, rootTableOrAssociationAlias, {
953
+ join = this._applyJoinAndStatements(dreamClass, join, joinAndStatement.and, rootTableOrAssociationAlias);
954
+ join = this._applyJoinAndStatements(dreamClass, join, joinAndStatement.andNot, rootTableOrAssociationAlias, {
967
955
  negate: true,
968
956
  });
969
- join = this._applyJoinAndAnyStatements(join, joinAndStatement.andAny, rootTableOrAssociationAlias);
957
+ join = this._applyJoinAndAnyStatements(dreamClass, join, joinAndStatement.andAny, rootTableOrAssociationAlias);
970
958
  return join;
971
959
  }
972
- _applyJoinAndStatements(join, joinAndStatement, rootTableOrAssociationAlias, { negate = false, } = {}) {
960
+ _applyJoinAndStatements(dreamClass, join, joinAndStatement, rootTableOrAssociationAlias, { negate = false, } = {}) {
973
961
  if (!joinAndStatement)
974
962
  return join;
975
- return join.on((eb) => this.joinAndStatementToExpressionWrapper(joinAndStatement, rootTableOrAssociationAlias, eb, {
963
+ return join.on((eb) => this.joinAndStatementToExpressionWrapper(dreamClass, joinAndStatement, rootTableOrAssociationAlias, eb, {
976
964
  negate,
977
965
  disallowSimilarityOperator: negate,
978
966
  }));
979
967
  }
980
- _applyJoinAndAnyStatements(join, joinAndAnyStatement, rootTableOrAssociationAlias) {
968
+ _applyJoinAndAnyStatements(dreamClass, join, joinAndAnyStatement, rootTableOrAssociationAlias) {
981
969
  if (!joinAndAnyStatement)
982
970
  return join;
983
971
  if (!joinAndAnyStatement.length)
984
972
  return join;
985
973
  return join.on((eb) => {
986
- return eb.or(joinAndAnyStatement.map(joinAndStatement => this.joinAndStatementToExpressionWrapper(joinAndStatement, rootTableOrAssociationAlias, eb)));
974
+ return eb.or(joinAndAnyStatement.map(joinAndStatement => this.joinAndStatementToExpressionWrapper(dreamClass, joinAndStatement, rootTableOrAssociationAlias, eb)));
987
975
  });
988
976
  }
989
- joinAndStatementToExpressionWrapper(joinAndStatement, rootTableOrAssociationAlias, eb, { negate = false, disallowSimilarityOperator = true, } = {}) {
990
- return this.whereStatementToExpressionWrapper(eb, Object.keys(joinAndStatement).reduce((agg, key) => {
977
+ joinAndStatementToExpressionWrapper(dreamClass, joinAndStatement, rootTableOrAssociationAlias, eb, { negate = false, disallowSimilarityOperator = true, } = {}) {
978
+ return this.whereStatementToExpressionWrapper(dreamClass, eb, Object.keys(joinAndStatement).reduce((agg, key) => {
991
979
  agg[this.namespaceColumn(key.toString(), rootTableOrAssociationAlias)] = joinAndStatement[key];
992
980
  return agg;
993
981
  }, {}), {
@@ -1032,16 +1020,18 @@ export default class KyselyQueryDriver extends QueryDriverBase {
1032
1020
  query['whereNotStatements'].length ||
1033
1021
  query['whereAnyStatements'].length) {
1034
1022
  kyselyQuery = kyselyQuery.where((eb) => eb.and([
1035
- ...this.aliasWhereStatements(query['whereStatements'], query['baseSqlAlias']).map(whereStatement => this.whereStatementToExpressionWrapper(eb, whereStatement, {
1023
+ ...this.aliasWhereStatements(query['whereStatements'], query['baseSqlAlias']).map(whereStatement => this.whereStatementToExpressionWrapper(this.dreamClass, eb, whereStatement, {
1036
1024
  disallowSimilarityOperator: false,
1037
1025
  })),
1038
- ...this.aliasWhereStatements(query['whereNotStatements'], query['baseSqlAlias']).map(whereNotStatement => this.whereStatementToExpressionWrapper(eb, whereNotStatement, { negate: true })),
1039
- ...query['whereAnyStatements'].map(whereAnyStatements => eb.or(this.aliasWhereStatements(whereAnyStatements, query['baseSqlAlias']).map(whereAnyStatement => this.whereStatementToExpressionWrapper(eb, whereAnyStatement)))),
1026
+ ...this.aliasWhereStatements(query['whereNotStatements'], query['baseSqlAlias']).map(whereNotStatement => this.whereStatementToExpressionWrapper(this.dreamClass, eb, whereNotStatement, {
1027
+ negate: true,
1028
+ })),
1029
+ ...query['whereAnyStatements'].map(whereAnyStatements => eb.or(this.aliasWhereStatements(whereAnyStatements, query['baseSqlAlias']).map(whereAnyStatement => this.whereStatementToExpressionWrapper(this.dreamClass, eb, whereAnyStatement)))),
1040
1030
  ]));
1041
1031
  }
1042
1032
  return kyselyQuery;
1043
1033
  }
1044
- whereStatementToExpressionWrapper(eb, whereStatement, { negate = false, disallowSimilarityOperator = true, } = {}) {
1034
+ whereStatementToExpressionWrapper(dreamClass, eb, whereStatement, { negate = false, disallowSimilarityOperator = true, } = {}) {
1045
1035
  const clauses = compact(Object.keys(whereStatement)
1046
1036
  .filter(key => whereStatement[key] !== DreamConst.required)
1047
1037
  .map(attr => {
@@ -1054,7 +1044,7 @@ export default class KyselyQueryDriver extends QueryDriverBase {
1054
1044
  // and should be ommited from the where clause directly
1055
1045
  return;
1056
1046
  }
1057
- const { a, b, c, a2, b2, c2 } = this.dreamWhereStatementToExpressionBuilderParts(attr, val);
1047
+ const { a, b, c, a2, b2, c2 } = this.dreamWhereStatementToExpressionBuilderParts(dreamClass, attr, val);
1058
1048
  // postgres is unable to handle WHERE IN statements with blank arrays, such as in
1059
1049
  // "WHERE id IN ()", meaning that:
1060
1050
  // 1. If we receive a blank array during an IN comparison,
@@ -1138,23 +1128,36 @@ export default class KyselyQueryDriver extends QueryDriverBase {
1138
1128
  return eb.and([eb(a, 'not in', compactedC), isNotNullStatement]);
1139
1129
  return isNotNullStatement;
1140
1130
  }
1141
- dreamWhereStatementToExpressionBuilderParts(attr, val) {
1131
+ dreamWhereStatementToExpressionBuilderParts(dreamClass, attr, val) {
1142
1132
  let a;
1143
1133
  let b;
1144
1134
  let c;
1145
1135
  let a2 = null;
1146
1136
  let b2 = null;
1147
1137
  let c2 = null;
1138
+ const isolatedColumn = maybeNamespacedColumnNameToColumnName(attr);
1148
1139
  if (val instanceof Function && val !== DreamConst.passthrough) {
1149
1140
  val = val();
1150
1141
  }
1151
1142
  else if (val === DreamConst.passthrough) {
1152
- const column = maybeNamespacedColumnNameToColumnName(attr);
1153
- if (this.query['passthroughOnStatement'][column] === undefined)
1154
- throw new MissingRequiredPassthroughForAssociationAndClause(column);
1155
- val = this.query['passthroughOnStatement'][column];
1143
+ if (this.query['passthroughOnStatement'][isolatedColumn] === undefined)
1144
+ throw new MissingRequiredPassthroughForAssociationAndClause(isolatedColumn);
1145
+ val = this.query['passthroughOnStatement'][isolatedColumn];
1146
+ }
1147
+ if (dreamClass.associationNames.includes(isolatedColumn) && val instanceof Dream) {
1148
+ const association = dreamClass['associationMetadataMap']()[isolatedColumn];
1149
+ const associationAttrs = extractAssignableAssociationAttributes(association, val);
1150
+ const attrKeys = Object.keys(associationAttrs);
1151
+ a = attrKeys[0];
1152
+ b = '=';
1153
+ c = associationAttrs[attrKeys[0]];
1154
+ if (attrKeys.length > 1) {
1155
+ a2 = attrKeys[1];
1156
+ b2 = '=';
1157
+ c2 = associationAttrs[attrKeys[1]];
1158
+ }
1156
1159
  }
1157
- if (val === null) {
1160
+ else if (val === null) {
1158
1161
  a = attr;
1159
1162
  b = 'is';
1160
1163
  c = val;
@@ -1167,14 +1170,10 @@ export default class KyselyQueryDriver extends QueryDriverBase {
1167
1170
  else if (Array.isArray(val)) {
1168
1171
  a = attr;
1169
1172
  b = 'in';
1170
- c = val.map(v => v instanceof DateTime || v instanceof CalendarDate
1171
- ? v.toSQL()
1172
- : typeof v === 'string'
1173
- ? normalizeUnicode(v)
1174
- : v);
1173
+ c = val;
1175
1174
  }
1176
1175
  else if (val instanceof CurriedOpsStatement) {
1177
- val = val.toOpsStatement(this.dreamClass, attr);
1176
+ val = val.toOpsStatement(dreamClass, attr);
1178
1177
  a = attr;
1179
1178
  b = val.operator;
1180
1179
  c = val.value;
@@ -1212,20 +1211,21 @@ export default class KyselyQueryDriver extends QueryDriverBase {
1212
1211
  b = '=';
1213
1212
  c = val;
1214
1213
  }
1215
- if (c instanceof DateTime || c instanceof CalendarDate)
1216
- c = c.toSQL();
1217
- else if (typeof c === 'string')
1218
- c = normalizeUnicode(c);
1219
- if (c2 instanceof DateTime || c2 instanceof CalendarDate)
1220
- c2 = c2.toSQL();
1221
- else if (typeof c2 === 'string')
1222
- c2 = normalizeUnicode(c2);
1214
+ c = this.normalizedWhereValue(dreamClass, attr, c);
1215
+ c2 = this.normalizedWhereValue(dreamClass, attr, c2);
1223
1216
  if (a && c === undefined)
1224
1217
  throw new CannotPassUndefinedAsAValueToAWhereClause(this.dreamClass, a);
1225
1218
  if (a2 && c2 === undefined)
1226
1219
  throw new CannotPassUndefinedAsAValueToAWhereClause(this.dreamClass, a2);
1227
1220
  return { a, b, c, a2, b2, c2 };
1228
1221
  }
1222
+ normalizedWhereValue(dreamClass, attr, val) {
1223
+ return normalizeDataForDb({
1224
+ val,
1225
+ dreamClass,
1226
+ column: maybeNamespacedColumnNameToColumnName(attr),
1227
+ });
1228
+ }
1229
1229
  recursivelyJoin({ query, joinStatement, joinAndStatements, dreamClass, previousTableAlias, joinType, }) {
1230
1230
  for (const associationString of Object.keys(joinStatement)) {
1231
1231
  const joinAndStatement = joinAndStatements[associationString];
@@ -1398,13 +1398,16 @@ export default class KyselyQueryDriver extends QueryDriverBase {
1398
1398
  const value = preloadOnStatements[key];
1399
1399
  if (value === undefined)
1400
1400
  throw new UnexpectedUndefined();
1401
- // filter out plain objects, but not ops and not and/andNot/andAny statements
1402
- // because plain objects are just the next level of nested preload
1401
+ // filter out plain objects and prototype-less containers (used for nested preload),
1402
+ // but not ops and not and/andNot/andAny statements
1403
+ const isNestedPreloadContainer = typeof value === 'object' &&
1404
+ value !== null &&
1405
+ (value.constructor === Object || Object.getPrototypeOf(value) === null);
1403
1406
  if (key === 'and' ||
1404
1407
  key === 'andNot' ||
1405
1408
  key === 'andAny' ||
1406
1409
  value === null ||
1407
- value.constructor !== Object) {
1410
+ !isNestedPreloadContainer) {
1408
1411
  agg[key] = value;
1409
1412
  }
1410
1413
  return agg;
@@ -1561,18 +1564,18 @@ export default class KyselyQueryDriver extends QueryDriverBase {
1561
1564
  dreamClassThroughAssociationWantsToHydrate: undefined,
1562
1565
  });
1563
1566
  }
1564
- const dreamClassWithSourceAssociation = associationReferencedByThroughAssociation.modelCB();
1565
- if (Array.isArray(dreamClassWithSourceAssociation))
1567
+ const associatedDreamClass = associationReferencedByThroughAssociation.modelCB();
1568
+ if (Array.isArray(associatedDreamClass))
1566
1569
  throw new ArrayTargetIncompatibleWithThroughAssociation({
1567
1570
  dreamClass: dreamClassTheAssociationIsDefinedOn,
1568
1571
  association: throughAssociation,
1569
1572
  });
1570
- const sourceAssociation = getSourceAssociation(dreamClassWithSourceAssociation, throughAssociation.source);
1573
+ const sourceAssociation = getSourceAssociation(associatedDreamClass, throughAssociation.source);
1571
1574
  if (!sourceAssociation)
1572
1575
  throw new MissingThroughAssociationSource({
1573
1576
  dreamClass: dreamClassTheAssociationIsDefinedOn,
1574
1577
  association: throughAssociation,
1575
- throughClass: dreamClassWithSourceAssociation,
1578
+ throughClass: associatedDreamClass,
1576
1579
  });
1577
1580
  /**
1578
1581
  * When the source is a polymorphic BelongsTo association, use the target of the through
@@ -1588,7 +1591,7 @@ export default class KyselyQueryDriver extends QueryDriverBase {
1588
1591
  */
1589
1592
  return this.applyOneJoin({
1590
1593
  query: recursiveResult.query,
1591
- dreamClass: dreamClassWithSourceAssociation,
1594
+ dreamClass: associatedDreamClass,
1592
1595
  association: sourceAssociation,
1593
1596
  // since joinsBridgeThroughAssociations passes undefined to explicitAlias recursively, we know this is only set on the
1594
1597
  // first call to joinsBridgeThroughAssociations, which corresponds to the outermoset through association and therefore
@@ -1668,6 +1671,10 @@ export default class KyselyQueryDriver extends QueryDriverBase {
1668
1671
  */
1669
1672
  previousTableAlias, selfTableAlias, joinAndStatement, previousThroughAssociation, joinType, dreamClassThroughAssociationWantsToHydrate, }) {
1670
1673
  const currentTableAlias = explicitAlias ?? association.as;
1674
+ const _associatedDreamClass = association.modelCB();
1675
+ const associatedDreamClass = Array.isArray(_associatedDreamClass)
1676
+ ? _associatedDreamClass[0]
1677
+ : _associatedDreamClass;
1671
1678
  if (previousThroughAssociation?.type === 'HasMany') {
1672
1679
  if (query?.distinctOn && previousThroughAssociation.distinct) {
1673
1680
  query = query.distinctOn(this.distinctColumnNameForAssociation({
@@ -1700,11 +1707,12 @@ export default class KyselyQueryDriver extends QueryDriverBase {
1700
1707
  }), currentTableAlias));
1701
1708
  if (previousThroughAssociation) {
1702
1709
  if (dreamClassThroughAssociationWantsToHydrate) {
1703
- join = join.on((eb) => this.whereStatementToExpressionWrapper(eb, this.aliasWhereStatement({
1710
+ join = join.on((eb) => this.whereStatementToExpressionWrapper(dreamClass, eb, this.aliasWhereStatement({
1704
1711
  [association.foreignKeyTypeField()]: dreamClassThroughAssociationWantsToHydrate.sanitizedName,
1705
1712
  }, previousThroughAssociation.through)));
1706
1713
  }
1707
1714
  join = this.applyAssociationAndStatementsToJoinStatement({
1715
+ dreamClass,
1708
1716
  join,
1709
1717
  association: previousThroughAssociation,
1710
1718
  currentTableAlias,
@@ -1713,12 +1721,13 @@ export default class KyselyQueryDriver extends QueryDriverBase {
1713
1721
  });
1714
1722
  }
1715
1723
  join = this.conditionallyApplyDefaultScopesDependentOnAssociation({
1724
+ dreamClass,
1716
1725
  join,
1717
1726
  tableNameOrAlias: currentTableAlias,
1718
1727
  association,
1719
1728
  throughAssociatedClassOverride: dreamClassThroughAssociationWantsToHydrate,
1720
1729
  });
1721
- join = this.applyJoinAndStatement(join, joinAndStatement, currentTableAlias);
1730
+ join = this.applyJoinAndStatement(associatedDreamClass, join, joinAndStatement, currentTableAlias);
1722
1731
  return join;
1723
1732
  });
1724
1733
  }
@@ -1728,7 +1737,7 @@ export default class KyselyQueryDriver extends QueryDriverBase {
1728
1737
  query = query[(joinType === 'inner' ? 'innerJoin' : 'leftJoin')](joinTableExpression, (join) => {
1729
1738
  join = join.onRef(this.namespaceColumn(association.primaryKey(), previousTableAlias), '=', this.namespaceColumn(association.foreignKey(), currentTableAlias));
1730
1739
  if (association.polymorphic) {
1731
- join = join.on((eb) => this.whereStatementToExpressionWrapper(eb, this.aliasWhereStatement({
1740
+ join = join.on((eb) => this.whereStatementToExpressionWrapper(dreamClass, eb, this.aliasWhereStatement({
1732
1741
  [association.foreignKeyTypeField()]: dreamClassThroughAssociationWantsToHydrate
1733
1742
  ? dreamClassThroughAssociationWantsToHydrate.referenceTypeString
1734
1743
  : dreamClass.referenceTypeString,
@@ -1736,6 +1745,7 @@ export default class KyselyQueryDriver extends QueryDriverBase {
1736
1745
  }
1737
1746
  if (previousThroughAssociation) {
1738
1747
  join = this.applyAssociationAndStatementsToJoinStatement({
1748
+ dreamClass,
1739
1749
  join,
1740
1750
  association: previousThroughAssociation,
1741
1751
  currentTableAlias,
@@ -1744,6 +1754,7 @@ export default class KyselyQueryDriver extends QueryDriverBase {
1744
1754
  });
1745
1755
  }
1746
1756
  join = this.applyAssociationAndStatementsToJoinStatement({
1757
+ dreamClass,
1747
1758
  join,
1748
1759
  association,
1749
1760
  currentTableAlias,
@@ -1751,12 +1762,13 @@ export default class KyselyQueryDriver extends QueryDriverBase {
1751
1762
  joinAndStatement,
1752
1763
  });
1753
1764
  join = this.conditionallyApplyDefaultScopesDependentOnAssociation({
1765
+ dreamClass,
1754
1766
  join,
1755
1767
  tableNameOrAlias: currentTableAlias,
1756
1768
  association,
1757
1769
  throughAssociatedClassOverride: dreamClassThroughAssociationWantsToHydrate,
1758
1770
  });
1759
- join = this.applyJoinAndStatement(join, joinAndStatement, currentTableAlias);
1771
+ join = this.applyJoinAndStatement(associatedDreamClass, join, joinAndStatement, currentTableAlias);
1760
1772
  return join;
1761
1773
  });
1762
1774
  if (association.type === 'HasMany') {
@@ -1804,26 +1816,26 @@ export default class KyselyQueryDriver extends QueryDriverBase {
1804
1816
  return this.namespaceColumn(foreignKey, tableNameOrAlias);
1805
1817
  return this.namespaceColumn(association.distinct, tableNameOrAlias);
1806
1818
  }
1807
- applyAssociationAndStatementsToJoinStatement({ join, currentTableAlias, selfTableAlias, association, joinAndStatement, }) {
1819
+ applyAssociationAndStatementsToJoinStatement({ dreamClass, join, currentTableAlias, selfTableAlias, association, joinAndStatement, }) {
1808
1820
  if (association.and) {
1809
1821
  this.throwUnlessAllRequiredWhereClausesProvided(association, currentTableAlias, joinAndStatement);
1810
- join = join.on((eb) => this.whereStatementToExpressionWrapper(eb, this.aliasWhereStatement(association.and, currentTableAlias), { disallowSimilarityOperator: false }));
1822
+ join = join.on((eb) => this.whereStatementToExpressionWrapper(dreamClass, eb, this.aliasWhereStatement(association.and, currentTableAlias), { disallowSimilarityOperator: false }));
1811
1823
  }
1812
1824
  if (association.andNot) {
1813
- join = join.on((eb) => this.whereStatementToExpressionWrapper(eb, this.aliasWhereStatement(association.andNot, currentTableAlias), { negate: true }));
1825
+ join = join.on((eb) => this.whereStatementToExpressionWrapper(dreamClass, eb, this.aliasWhereStatement(association.andNot, currentTableAlias), { negate: true }));
1814
1826
  }
1815
1827
  if (association.andAny) {
1816
- join = join.on((eb) => eb.or(association.andAny.map(whereAnyStatement => this.whereStatementToExpressionWrapper(eb, this.aliasWhereStatement(whereAnyStatement, currentTableAlias), { disallowSimilarityOperator: false }))));
1828
+ join = join.on((eb) => eb.or(association.andAny.map(whereAnyStatement => this.whereStatementToExpressionWrapper(dreamClass, eb, this.aliasWhereStatement(whereAnyStatement, currentTableAlias), { disallowSimilarityOperator: false }))));
1817
1829
  }
1818
1830
  if (association.selfAnd) {
1819
- join = join.on((eb) => this.whereStatementToExpressionWrapper(eb, this.rawifiedSelfOnClause({
1831
+ join = join.on((eb) => this.whereStatementToExpressionWrapper(dreamClass, eb, this.rawifiedSelfOnClause({
1820
1832
  associationAlias: association.as,
1821
1833
  selfAlias: selfTableAlias,
1822
1834
  selfAndClause: association.selfAnd,
1823
1835
  })));
1824
1836
  }
1825
1837
  if (association.selfAndNot) {
1826
- join = join.on((eb) => this.whereStatementToExpressionWrapper(eb, this.rawifiedSelfOnClause({
1838
+ join = join.on((eb) => this.whereStatementToExpressionWrapper(dreamClass, eb, this.rawifiedSelfOnClause({
1827
1839
  associationAlias: association.as,
1828
1840
  selfAlias: selfTableAlias,
1829
1841
  selfAndClause: association.selfAndNot,
@@ -1842,7 +1854,7 @@ export default class KyselyQueryDriver extends QueryDriverBase {
1842
1854
  if (missingRequiredWhereStatements.length)
1843
1855
  throw new MissingRequiredAssociationAndClause(association, missingRequiredWhereStatements[0]);
1844
1856
  }
1845
- conditionallyApplyDefaultScopesDependentOnAssociation({ join, tableNameOrAlias, association, throughAssociatedClassOverride, }) {
1857
+ conditionallyApplyDefaultScopesDependentOnAssociation({ dreamClass, join, tableNameOrAlias, association, throughAssociatedClassOverride, }) {
1846
1858
  let scopesQuery = new Query(this.dreamInstance);
1847
1859
  const associationClass = throughAssociatedClassOverride ?? association.modelCB();
1848
1860
  const associationScopes = associationClass['scopes'].default;
@@ -1864,7 +1876,7 @@ export default class KyselyQueryDriver extends QueryDriverBase {
1864
1876
  }
1865
1877
  }
1866
1878
  if (scopesQuery['whereStatements'].length) {
1867
- join = join.on((eb) => eb.and(scopesQuery['whereStatements'].flatMap(whereStatement => this.whereStatementToExpressionWrapper(eb, this.aliasWhereStatement(whereStatement, tableNameOrAlias), { disallowSimilarityOperator: false }))));
1879
+ join = join.on((eb) => eb.and(scopesQuery['whereStatements'].flatMap(whereStatement => this.whereStatementToExpressionWrapper(dreamClass, eb, this.aliasWhereStatement(whereStatement, tableNameOrAlias), { disallowSimilarityOperator: false }))));
1868
1880
  }
1869
1881
  return join;
1870
1882
  }
@@ -12,7 +12,7 @@ import DreamCLI from '../../cli/index.js';
12
12
  import { isPrimitiveDataType } from '../../db/dataTypes.js';
13
13
  import DreamApp from '../../dream-app/index.js';
14
14
  import camelize from '../../helpers/camelize.js';
15
- import { findCitextArrayOid, findCorrespondingArrayOid, findEnumArrayOids, parsePostgresBigint, parsePostgresDate, parsePostgresDatetime, parsePostgresDecimal, } from '../../helpers/customPgParsers.js';
15
+ import { findCitextArrayOid, findCorrespondingArrayOid, findEnumArrayOids, parsePostgresBigint, parsePostgresDate, parsePostgresDatetime, parsePostgresDatetimeTz, parsePostgresDecimal, parsePostgresTime, parsePostgresTimeTz, } from '../../helpers/customPgParsers.js';
16
16
  import EnvInternal from '../../helpers/EnvInternal.js';
17
17
  import createDb from './helpers/pg/createDb.js';
18
18
  import _dropDb from './helpers/pg/dropDb.js';
@@ -70,7 +70,9 @@ export default class PostgresQueryDriver extends KyselyQueryDriver {
70
70
  const kyselyDb = this.dbFor(connectionName, 'primary');
71
71
  pgTypes.setTypeParser(pgTypes.builtins.DATE, parsePostgresDate);
72
72
  pgTypes.setTypeParser(pgTypes.builtins.TIMESTAMP, parsePostgresDatetime);
73
- pgTypes.setTypeParser(pgTypes.builtins.TIMESTAMPTZ, parsePostgresDatetime);
73
+ pgTypes.setTypeParser(pgTypes.builtins.TIMESTAMPTZ, parsePostgresDatetimeTz);
74
+ pgTypes.setTypeParser(pgTypes.builtins.TIME, parsePostgresTime);
75
+ pgTypes.setTypeParser(pgTypes.builtins.TIMETZ, parsePostgresTimeTz);
74
76
  pgTypes.setTypeParser(pgTypes.builtins.NUMERIC, parsePostgresDecimal);
75
77
  pgTypes.setTypeParser(pgTypes.builtins.INT8, parsePostgresBigint);
76
78
  const textArrayOid = await findCorrespondingArrayOid(kyselyDb, pgTypes.builtins.TEXT);
@@ -97,6 +99,12 @@ export default class PostgresQueryDriver extends KyselyQueryDriver {
97
99
  oid = await findCorrespondingArrayOid(kyselyDb, pgTypes.builtins.TIMESTAMPTZ);
98
100
  if (oid)
99
101
  pgTypes.setTypeParser(oid, transformPostgresArray(parsePostgresDatetime));
102
+ oid = await findCorrespondingArrayOid(kyselyDb, pgTypes.builtins.TIME);
103
+ if (oid)
104
+ pgTypes.setTypeParser(oid, transformPostgresArray(parsePostgresTime));
105
+ oid = await findCorrespondingArrayOid(kyselyDb, pgTypes.builtins.TIMETZ);
106
+ if (oid)
107
+ pgTypes.setTypeParser(oid, transformPostgresArray(parsePostgresTimeTz));
100
108
  oid = await findCorrespondingArrayOid(kyselyDb, pgTypes.builtins.NUMERIC);
101
109
  if (oid)
102
110
  pgTypes.setTypeParser(oid, transformPostgresArray(parsePostgresDecimal));
@@ -0,0 +1,9 @@
1
+ export default function extractAssignableAssociationAttributes(association, dreamInstance) {
2
+ const returnObj = {
3
+ [association.foreignKey()]: association.primaryKeyValue(dreamInstance),
4
+ };
5
+ if (association.polymorphic) {
6
+ returnObj[association.foreignKeyTypeField()] = dreamInstance.referenceTypeString;
7
+ }
8
+ return returnObj;
9
+ }
@@ -1,9 +1,7 @@
1
1
  export default class DataIncompatibleWithDatabaseField extends Error {
2
- dream;
3
2
  error;
4
- constructor({ dream, error }) {
3
+ constructor(error) {
5
4
  super();
6
- this.dream = dream;
7
5
  this.error = error;
8
6
  }
9
7
  get message() {