@rvoh/dream 0.42.2 → 0.43.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (374) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/src/Dream.js +55 -32
  3. package/dist/cjs/src/bin/index.js +6 -1
  4. package/dist/cjs/src/cli/index.js +1 -0
  5. package/dist/cjs/src/decorators/field/validation/Validates.js +5 -2
  6. package/dist/cjs/src/dream/DreamClassTransactionBuilder.js +32 -0
  7. package/dist/cjs/src/dream/Query.js +61 -8
  8. package/dist/cjs/src/dream/constants.js +7 -9
  9. package/dist/cjs/src/dream/internal/checkSingleValidation.js +5 -2
  10. package/dist/cjs/src/dream/internal/computedPaginatePage.js +10 -0
  11. package/dist/cjs/src/dream/internal/findOrCreateBy.js +1 -1
  12. package/dist/cjs/src/dream/internal/orderByDirection.js +5 -2
  13. package/dist/cjs/src/dream/internal/updateOrCreateBy.js +1 -1
  14. package/dist/cjs/src/dream-app/helpers/DreamImporter.js +2 -2
  15. package/dist/cjs/src/dream-app/helpers/importers/importModels.js +1 -1
  16. package/dist/cjs/src/dream-app/helpers/importers/importSerializers.js +5 -26
  17. package/dist/cjs/src/dream-app/index.js +12 -2
  18. package/dist/cjs/src/encrypt/index.js +20 -8
  19. package/dist/cjs/src/errors/pagination/CannotPaginateWithLimit.js +17 -0
  20. package/dist/cjs/src/errors/pagination/CannotPaginateWithOffset.js +17 -0
  21. package/dist/cjs/src/errors/serializers/AttemptedToDeriveDescendentSerializersFromNonSerializer.js +16 -0
  22. package/dist/cjs/src/errors/serializers/DelegationTargetDoesNotExist.js +13 -0
  23. package/dist/cjs/src/errors/serializers/MissingSerializersDefinition.js +26 -0
  24. package/dist/cjs/src/errors/serializers/MissingSerializersDefinitionForKey.js +29 -0
  25. package/dist/cjs/src/errors/serializers/NoGlobalSerializerForSpecifiedKey.js +21 -0
  26. package/dist/cjs/src/errors/serializers/NoSerializerFoundForRendersOneAndMany.js +16 -0
  27. package/dist/cjs/src/errors/serializers/NonDreamSerializerDerivedFromGlobalSerializerForSpecifiedKey.js +26 -0
  28. package/dist/cjs/src/errors/serializers/NonSerializerPassedToSerializerOpenapiRenderer.js +16 -0
  29. package/dist/cjs/src/errors/serializers/NonSerializerSerializerOverrideProvided.js +23 -0
  30. package/dist/cjs/src/errors/serializers/ObjectSerializerRendersOneAndManyRequireClassType.js +19 -0
  31. package/dist/cjs/src/errors/serializers/RendersManyMustReceiveArray.js +18 -0
  32. package/dist/cjs/src/errors/serializers/SerializerInsteadOfSerializerCallback.js +49 -0
  33. package/dist/cjs/src/helpers/cli/generateDream.js +7 -2
  34. package/dist/cjs/src/helpers/cli/generateDreamContent.js +1 -1
  35. package/dist/cjs/src/helpers/cli/generateFactoryContent.js +1 -1
  36. package/dist/cjs/src/helpers/cli/generateSerializer.js +7 -2
  37. package/dist/cjs/src/helpers/cli/generateSerializerContent.js +41 -66
  38. package/dist/cjs/src/helpers/compact.js +2 -2
  39. package/dist/cjs/src/helpers/db/primaryKeyType.js +5 -2
  40. package/dist/cjs/src/helpers/sortObjectByKey.js +11 -0
  41. package/dist/cjs/src/helpers/sti/expandStiClasses.js +17 -0
  42. package/dist/cjs/src/index.js +29 -15
  43. package/dist/cjs/src/openapi/allSerializersFromHandWrittenOpenapi.js +26 -0
  44. package/dist/cjs/src/openapi/allSerializersToRefsInOpenapi.js +41 -0
  45. package/dist/cjs/src/openapi/dreamAttributeOpenapiShape.js +138 -0
  46. package/dist/cjs/src/openapi/isOpenapiShorthand.js +11 -0
  47. package/dist/cjs/src/openapi/maybeNullOpenapiShorthandToOpenapiShorthand.js +17 -0
  48. package/dist/cjs/src/openapi/openapiShorthandToOpenapi.js +106 -0
  49. package/dist/cjs/src/serializer/DreamSerializer.js +7 -0
  50. package/dist/cjs/src/serializer/ObjectSerializer.js +7 -0
  51. package/dist/cjs/src/serializer/SerializerOpenapiRenderer.js +325 -0
  52. package/dist/cjs/src/serializer/SerializerRenderer.js +194 -0
  53. package/dist/cjs/src/serializer/builders/DreamSerializerBuilder.js +65 -0
  54. package/dist/cjs/src/serializer/builders/ObjectSerializerBuilder.js +63 -0
  55. package/dist/cjs/src/serializer/helpers/inferSerializerFromDreamOrViewModel.js +38 -0
  56. package/dist/cjs/src/serializer/helpers/isDreamSerializer.js +19 -0
  57. package/dist/cjs/src/{helpers → serializer/helpers}/serializerNameFromFullyQualifiedModelName.js +1 -1
  58. package/dist/cjs/src/serializer/index.js +0 -282
  59. package/dist/cjs/src/types/serializer.js +2 -0
  60. package/dist/esm/src/Dream.js +55 -32
  61. package/dist/esm/src/bin/index.js +6 -1
  62. package/dist/esm/src/cli/index.js +1 -0
  63. package/dist/esm/src/decorators/field/validation/Validates.js +5 -2
  64. package/dist/esm/src/dream/DreamClassTransactionBuilder.js +32 -0
  65. package/dist/esm/src/dream/Query.js +59 -6
  66. package/dist/esm/src/dream/constants.js +7 -9
  67. package/dist/esm/src/dream/internal/checkSingleValidation.js +5 -2
  68. package/dist/esm/src/dream/internal/computedPaginatePage.js +7 -0
  69. package/dist/esm/src/dream/internal/findOrCreateBy.js +1 -1
  70. package/dist/esm/src/dream/internal/orderByDirection.js +5 -2
  71. package/dist/esm/src/dream/internal/updateOrCreateBy.js +1 -1
  72. package/dist/esm/src/dream-app/helpers/DreamImporter.js +2 -2
  73. package/dist/esm/src/dream-app/helpers/importers/importModels.js +1 -1
  74. package/dist/esm/src/dream-app/helpers/importers/importSerializers.js +5 -26
  75. package/dist/esm/src/dream-app/index.js +12 -2
  76. package/dist/esm/src/encrypt/index.js +20 -8
  77. package/dist/esm/src/errors/pagination/CannotPaginateWithLimit.js +14 -0
  78. package/dist/esm/src/errors/pagination/CannotPaginateWithOffset.js +14 -0
  79. package/dist/esm/src/errors/serializers/AttemptedToDeriveDescendentSerializersFromNonSerializer.js +13 -0
  80. package/dist/esm/src/errors/serializers/DelegationTargetDoesNotExist.js +10 -0
  81. package/dist/esm/src/errors/serializers/MissingSerializersDefinition.js +23 -0
  82. package/dist/esm/src/errors/serializers/MissingSerializersDefinitionForKey.js +26 -0
  83. package/dist/esm/src/errors/serializers/NoGlobalSerializerForSpecifiedKey.js +18 -0
  84. package/dist/esm/src/errors/serializers/NoSerializerFoundForRendersOneAndMany.js +13 -0
  85. package/dist/esm/src/errors/serializers/NonDreamSerializerDerivedFromGlobalSerializerForSpecifiedKey.js +23 -0
  86. package/dist/esm/src/errors/serializers/NonSerializerPassedToSerializerOpenapiRenderer.js +13 -0
  87. package/dist/esm/src/errors/serializers/NonSerializerSerializerOverrideProvided.js +20 -0
  88. package/dist/esm/src/errors/serializers/ObjectSerializerRendersOneAndManyRequireClassType.js +16 -0
  89. package/dist/esm/src/errors/serializers/RendersManyMustReceiveArray.js +15 -0
  90. package/dist/esm/src/errors/serializers/SerializerInsteadOfSerializerCallback.js +46 -0
  91. package/dist/esm/src/helpers/cli/generateDream.js +7 -2
  92. package/dist/esm/src/helpers/cli/generateDreamContent.js +1 -1
  93. package/dist/esm/src/helpers/cli/generateFactoryContent.js +1 -1
  94. package/dist/esm/src/helpers/cli/generateSerializer.js +7 -2
  95. package/dist/esm/src/helpers/cli/generateSerializerContent.js +41 -66
  96. package/dist/esm/src/helpers/compact.js +2 -2
  97. package/dist/esm/src/helpers/db/primaryKeyType.js +5 -2
  98. package/dist/esm/src/helpers/sortObjectByKey.js +8 -0
  99. package/dist/esm/src/helpers/sti/expandStiClasses.js +14 -0
  100. package/dist/esm/src/index.js +13 -6
  101. package/dist/esm/src/openapi/allSerializersFromHandWrittenOpenapi.js +23 -0
  102. package/dist/esm/src/openapi/allSerializersToRefsInOpenapi.js +38 -0
  103. package/dist/esm/src/openapi/dreamAttributeOpenapiShape.js +132 -0
  104. package/dist/esm/src/openapi/isOpenapiShorthand.js +8 -0
  105. package/dist/esm/src/openapi/maybeNullOpenapiShorthandToOpenapiShorthand.js +14 -0
  106. package/dist/esm/src/openapi/openapiShorthandToOpenapi.js +100 -0
  107. package/dist/esm/src/serializer/DreamSerializer.js +4 -0
  108. package/dist/esm/src/serializer/ObjectSerializer.js +4 -0
  109. package/dist/esm/src/serializer/SerializerOpenapiRenderer.js +322 -0
  110. package/dist/esm/src/serializer/SerializerRenderer.js +191 -0
  111. package/dist/esm/src/serializer/builders/DreamSerializerBuilder.js +62 -0
  112. package/dist/esm/src/serializer/builders/ObjectSerializerBuilder.js +60 -0
  113. package/dist/esm/src/serializer/helpers/inferSerializerFromDreamOrViewModel.js +33 -0
  114. package/dist/esm/src/serializer/helpers/isDreamSerializer.js +16 -0
  115. package/dist/esm/src/{helpers → serializer/helpers}/serializerNameFromFullyQualifiedModelName.js +1 -1
  116. package/dist/esm/src/serializer/index.js +1 -280
  117. package/dist/esm/src/types/serializer.js +1 -0
  118. package/dist/types/src/Dream.d.ts +48 -21
  119. package/dist/types/src/bin/index.d.ts +1 -0
  120. package/dist/types/src/decorators/Decorators.d.ts +2 -2
  121. package/dist/types/src/decorators/field-or-getter/Virtual.d.ts +3 -3
  122. package/dist/types/src/dream/DreamClassTransactionBuilder.d.ts +31 -1
  123. package/dist/types/src/dream/Query.d.ts +29 -1
  124. package/dist/types/src/dream/constants.d.ts +2 -2
  125. package/dist/types/src/dream/internal/computedPaginatePage.d.ts +1 -0
  126. package/dist/types/src/dream-app/helpers/DreamImporter.d.ts +2 -2
  127. package/dist/types/src/dream-app/helpers/importers/importSerializers.d.ts +5 -5
  128. package/dist/types/src/dream-app/index.d.ts +6 -4
  129. package/dist/types/src/errors/pagination/CannotPaginateWithLimit.d.ts +3 -0
  130. package/dist/types/src/errors/pagination/CannotPaginateWithOffset.d.ts +3 -0
  131. package/dist/types/src/errors/serializers/AttemptedToDeriveDescendentSerializersFromNonSerializer.d.ts +5 -0
  132. package/dist/types/src/errors/serializers/DelegationTargetDoesNotExist.d.ts +5 -0
  133. package/dist/types/src/errors/serializers/FailedToRenderThroughAssociationForSerializer.d.ts +2 -2
  134. package/dist/types/src/errors/serializers/MissingSerializersDefinition.d.ts +7 -0
  135. package/dist/types/src/errors/serializers/MissingSerializersDefinitionForKey.d.ts +8 -0
  136. package/dist/types/src/errors/serializers/NoGlobalSerializerForSpecifiedKey.d.ts +9 -0
  137. package/dist/types/src/errors/serializers/NoSerializerFoundForRendersOneAndMany.d.ts +5 -0
  138. package/dist/types/src/errors/serializers/NonDreamSerializerDerivedFromGlobalSerializerForSpecifiedKey.d.ts +10 -0
  139. package/dist/types/src/errors/serializers/NonSerializerPassedToSerializerOpenapiRenderer.d.ts +5 -0
  140. package/dist/types/src/errors/serializers/NonSerializerSerializerOverrideProvided.d.ts +6 -0
  141. package/dist/types/src/errors/serializers/ObjectSerializerRendersOneAndManyRequireClassType.d.ts +5 -0
  142. package/dist/types/src/errors/serializers/RendersManyMustReceiveArray.d.ts +7 -0
  143. package/dist/types/src/errors/serializers/SerializerInsteadOfSerializerCallback.d.ts +8 -0
  144. package/dist/types/src/helpers/cli/generateDream.d.ts +1 -0
  145. package/dist/types/src/helpers/cli/generateSerializer.d.ts +2 -1
  146. package/dist/types/src/helpers/cli/generateSerializerContent.d.ts +2 -1
  147. package/dist/types/src/helpers/sortObjectByKey.d.ts +1 -0
  148. package/dist/types/src/helpers/sti/expandStiClasses.d.ts +3 -0
  149. package/dist/types/src/index.d.ts +18 -11
  150. package/dist/types/src/openapi/allSerializersFromHandWrittenOpenapi.d.ts +3 -0
  151. package/dist/types/src/openapi/allSerializersToRefsInOpenapi.d.ts +2 -0
  152. package/dist/types/src/openapi/dreamAttributeOpenapiShape.d.ts +796 -0
  153. package/dist/types/src/openapi/isOpenapiShorthand.d.ts +1 -0
  154. package/dist/types/src/openapi/maybeNullOpenapiShorthandToOpenapiShorthand.d.ts +2 -0
  155. package/dist/types/src/openapi/openapiShorthandToOpenapi.d.ts +16 -0
  156. package/dist/types/src/serializer/DreamSerializer.d.ts +3 -0
  157. package/dist/types/src/serializer/ObjectSerializer.d.ts +3 -0
  158. package/dist/types/src/serializer/SerializerOpenapiRenderer.d.ts +23 -0
  159. package/dist/types/src/serializer/SerializerRenderer.d.ts +13 -0
  160. package/dist/types/src/serializer/builders/DreamSerializerBuilder.d.ts +52 -0
  161. package/dist/types/src/serializer/builders/ObjectSerializerBuilder.d.ts +52 -0
  162. package/dist/types/src/serializer/helpers/inferSerializerFromDreamOrViewModel.d.ts +6 -0
  163. package/dist/types/src/serializer/helpers/isDreamSerializer.d.ts +1 -0
  164. package/dist/types/src/serializer/index.d.ts +1 -54
  165. package/dist/types/src/types/dream.d.ts +2 -5
  166. package/dist/types/src/types/dream.ts +13 -7
  167. package/dist/types/src/types/openapi.d.ts +10 -4
  168. package/dist/types/src/types/openapi.ts +20 -4
  169. package/dist/types/src/types/query.d.ts +28 -0
  170. package/dist/types/src/types/query.ts +34 -0
  171. package/dist/types/src/types/serializer.d.ts +66 -0
  172. package/dist/types/src/types/serializer.ts +112 -0
  173. package/docs/assets/navigation.js +1 -1
  174. package/docs/assets/search.js +1 -1
  175. package/docs/classes/Benchmark.html +2 -2
  176. package/docs/classes/CalendarDate.html +2 -2
  177. package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +3 -3
  178. package/docs/classes/Decorators.html +20 -20
  179. package/docs/classes/Dream.html +220 -211
  180. package/docs/classes/DreamApp.html +5 -4
  181. package/docs/classes/DreamBin.html +2 -2
  182. package/docs/classes/DreamCLI.html +4 -4
  183. package/docs/classes/DreamImporter.html +2 -2
  184. package/docs/classes/DreamLogos.html +2 -2
  185. package/docs/classes/DreamMigrationHelpers.html +7 -7
  186. package/docs/classes/DreamSerializerBuilder.html +17 -0
  187. package/docs/classes/DreamTransaction.html +2 -2
  188. package/docs/classes/Encrypt.html +2 -2
  189. package/docs/classes/Env.html +2 -2
  190. package/docs/classes/GlobalNameNotSet.html +3 -3
  191. package/docs/classes/NonLoadedAssociation.html +3 -3
  192. package/docs/classes/ObjectSerializerBuilder.html +16 -0
  193. package/docs/classes/Query.html +58 -50
  194. package/docs/classes/Range.html +2 -2
  195. package/docs/classes/RecordNotFound.html +3 -3
  196. package/docs/classes/SerializerOpenapiRenderer.html +6 -0
  197. package/docs/classes/SerializerRenderer.html +3 -0
  198. package/docs/classes/ValidationError.html +3 -3
  199. package/docs/functions/DreamSerializer.html +1 -0
  200. package/docs/functions/ObjectSerializer.html +1 -0
  201. package/docs/functions/ReplicaSafe.html +1 -1
  202. package/docs/functions/STI.html +1 -1
  203. package/docs/functions/SoftDelete.html +1 -1
  204. package/docs/functions/camelize.html +1 -1
  205. package/docs/functions/capitalize.html +1 -1
  206. package/docs/functions/closeAllDbConnections.html +1 -1
  207. package/docs/functions/compact.html +1 -1
  208. package/docs/functions/dreamDbConnections.html +1 -1
  209. package/docs/functions/dreamPath.html +1 -1
  210. package/docs/functions/generateDream.html +1 -1
  211. package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -1
  212. package/docs/functions/hyphenize.html +1 -1
  213. package/docs/functions/inferSerializerFromDreamOrViewModel.html +1 -1
  214. package/docs/functions/inferSerializersFromDreamClassOrViewModelClass.html +1 -0
  215. package/docs/functions/intersection.html +1 -1
  216. package/docs/functions/isDreamSerializer.html +1 -0
  217. package/docs/functions/isEmpty.html +1 -1
  218. package/docs/functions/isOpenapiShorthand.html +1 -0
  219. package/docs/functions/loadRepl.html +1 -1
  220. package/docs/functions/lookupClassByGlobalName.html +1 -1
  221. package/docs/functions/maybeNullOpenapiShorthandToOpenapiShorthand.html +1 -0
  222. package/docs/functions/openapiShorthandToOpenapi.html +1 -0
  223. package/docs/functions/pascalize.html +1 -1
  224. package/docs/functions/pgErrorType.html +1 -1
  225. package/docs/functions/range-1.html +1 -1
  226. package/docs/functions/relativeDreamPath.html +1 -1
  227. package/docs/functions/round.html +1 -1
  228. package/docs/functions/serializerNameFromFullyQualifiedModelName.html +1 -1
  229. package/docs/functions/sharedPathPrefix.html +1 -1
  230. package/docs/functions/snakeify.html +1 -1
  231. package/docs/functions/sort.html +1 -1
  232. package/docs/functions/sortBy.html +1 -1
  233. package/docs/functions/sortObjectByKey.html +1 -0
  234. package/docs/functions/standardizeFullyQualifiedModelName.html +1 -1
  235. package/docs/functions/uncapitalize.html +1 -1
  236. package/docs/functions/uniq.html +1 -1
  237. package/docs/functions/untypedDb.html +1 -1
  238. package/docs/functions/validateColumn.html +1 -1
  239. package/docs/functions/validateTable.html +1 -1
  240. package/docs/index.html +1 -1
  241. package/docs/interfaces/DecoratorContext.html +2 -2
  242. package/docs/interfaces/DreamAppInitOptions.html +2 -2
  243. package/docs/interfaces/DreamAppOpts.html +2 -2
  244. package/docs/interfaces/EncryptOptions.html +2 -2
  245. package/docs/interfaces/OpenapiSchemaProperties.html +1 -1
  246. package/docs/interfaces/OpenapiSchemaPropertiesShorthand.html +1 -1
  247. package/docs/interfaces/OpenapiTypeFieldObject.html +1 -1
  248. package/docs/modules.html +18 -10
  249. package/docs/types/Camelized.html +1 -1
  250. package/docs/types/CommonOpenapiSchemaObjectFields.html +1 -1
  251. package/docs/types/DateTime.html +1 -1
  252. package/docs/types/DbConnectionType.html +1 -1
  253. package/docs/types/DreamAssociationMetadata.html +1 -1
  254. package/docs/types/DreamAttributes.html +1 -1
  255. package/docs/types/DreamClassColumn.html +1 -1
  256. package/docs/types/DreamColumn.html +1 -1
  257. package/docs/types/DreamColumnNames.html +1 -1
  258. package/docs/types/DreamLogLevel.html +1 -1
  259. package/docs/types/DreamLogger.html +1 -1
  260. package/docs/types/DreamModelSerializerType.html +1 -0
  261. package/docs/types/DreamOrViewModelClassSerializerArrayKeys.html +1 -1
  262. package/docs/types/DreamOrViewModelClassSerializerKey.html +1 -1
  263. package/docs/types/DreamOrViewModelSerializerKey.html +1 -1
  264. package/docs/types/DreamParamSafeAttributes.html +1 -1
  265. package/docs/types/DreamParamSafeColumnNames.html +1 -1
  266. package/docs/types/DreamSerializable.html +1 -1
  267. package/docs/types/DreamSerializableArray.html +1 -1
  268. package/docs/types/DreamSerializerKey.html +1 -1
  269. package/docs/types/DreamSerializers.html +1 -1
  270. package/docs/types/DreamTableSchema.html +1 -1
  271. package/docs/types/DreamVirtualColumns.html +1 -1
  272. package/docs/types/EncryptAlgorithm.html +1 -1
  273. package/docs/types/Hyphenized.html +1 -1
  274. package/docs/types/IdType.html +1 -1
  275. package/docs/types/OpenapiAllTypes.html +1 -1
  276. package/docs/types/OpenapiFormats.html +1 -1
  277. package/docs/types/OpenapiNumberFormats.html +1 -1
  278. package/docs/types/OpenapiPrimitiveBaseTypes.html +1 -0
  279. package/docs/types/OpenapiPrimitiveTypes.html +1 -1
  280. package/docs/types/OpenapiSchemaArray.html +1 -1
  281. package/docs/types/OpenapiSchemaArrayShorthand.html +1 -1
  282. package/docs/types/OpenapiSchemaBase.html +1 -1
  283. package/docs/types/OpenapiSchemaBody.html +1 -1
  284. package/docs/types/OpenapiSchemaBodyShorthand.html +1 -1
  285. package/docs/types/OpenapiSchemaCommonFields.html +1 -1
  286. package/docs/types/OpenapiSchemaExpressionAllOf.html +1 -1
  287. package/docs/types/OpenapiSchemaExpressionAnyOf.html +1 -1
  288. package/docs/types/OpenapiSchemaExpressionOneOf.html +1 -1
  289. package/docs/types/OpenapiSchemaExpressionRef.html +1 -1
  290. package/docs/types/OpenapiSchemaExpressionRefSchemaShorthand.html +1 -1
  291. package/docs/types/OpenapiSchemaInteger.html +1 -1
  292. package/docs/types/OpenapiSchemaNull.html +1 -1
  293. package/docs/types/OpenapiSchemaNumber.html +1 -1
  294. package/docs/types/OpenapiSchemaObject.html +1 -1
  295. package/docs/types/OpenapiSchemaObjectAllOf.html +1 -1
  296. package/docs/types/OpenapiSchemaObjectAllOfShorthand.html +1 -1
  297. package/docs/types/OpenapiSchemaObjectAnyOf.html +1 -1
  298. package/docs/types/OpenapiSchemaObjectAnyOfShorthand.html +1 -1
  299. package/docs/types/OpenapiSchemaObjectBase.html +1 -1
  300. package/docs/types/OpenapiSchemaObjectBaseShorthand.html +1 -1
  301. package/docs/types/OpenapiSchemaObjectOneOf.html +1 -1
  302. package/docs/types/OpenapiSchemaObjectOneOfShorthand.html +1 -1
  303. package/docs/types/OpenapiSchemaObjectShorthand.html +1 -1
  304. package/docs/types/OpenapiSchemaPrimitiveGeneric.html +1 -1
  305. package/docs/types/OpenapiSchemaShorthandExpressionAllOf.html +1 -1
  306. package/docs/types/OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
  307. package/docs/types/OpenapiSchemaShorthandExpressionOneOf.html +1 -1
  308. package/docs/types/OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
  309. package/docs/types/OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
  310. package/docs/types/OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
  311. package/docs/types/OpenapiSchemaString.html +1 -1
  312. package/docs/types/OpenapiShorthandAllTypes.html +1 -1
  313. package/docs/types/OpenapiShorthandPrimitiveBaseTypes.html +1 -0
  314. package/docs/types/OpenapiShorthandPrimitiveTypes.html +1 -1
  315. package/docs/types/OpenapiTypeField.html +1 -1
  316. package/docs/types/Pascalized.html +1 -1
  317. package/docs/types/PrimaryKeyType.html +1 -1
  318. package/docs/types/RoundingPrecision.html +1 -1
  319. package/docs/types/SerializerCasing.html +1 -0
  320. package/docs/types/SimpleObjectSerializerType.html +1 -0
  321. package/docs/types/Snakeified.html +1 -1
  322. package/docs/types/Timestamp.html +1 -1
  323. package/docs/types/UpdateableAssociationProperties.html +1 -1
  324. package/docs/types/UpdateableProperties.html +1 -1
  325. package/docs/types/ValidationType.html +1 -1
  326. package/docs/types/ViewModel.html +1 -1
  327. package/docs/types/ViewModelClass.html +1 -1
  328. package/docs/types/WhereStatementForDream.html +1 -1
  329. package/docs/types/WhereStatementForDreamClass.html +1 -1
  330. package/docs/variables/DateTime-1.html +1 -1
  331. package/docs/variables/DreamConst.html +1 -1
  332. package/docs/variables/TRIGRAM_OPERATORS.html +1 -1
  333. package/docs/variables/openapiPrimitiveTypes-1.html +1 -1
  334. package/docs/variables/openapiShorthandPrimitiveTypes-1.html +1 -1
  335. package/docs/variables/ops.html +1 -1
  336. package/docs/variables/primaryKeyTypes.html +1 -1
  337. package/package.json +3 -4
  338. package/dist/cjs/src/errors/MissingSerializersDefinition.js +0 -26
  339. package/dist/cjs/src/helpers/inferSerializerFromDreamOrViewModel.js +0 -16
  340. package/dist/cjs/src/serializer/decorators/associations/RendersMany.js +0 -84
  341. package/dist/cjs/src/serializer/decorators/associations/RendersOne.js +0 -87
  342. package/dist/cjs/src/serializer/decorators/associations/shared.js +0 -10
  343. package/dist/cjs/src/serializer/decorators/attribute.js +0 -167
  344. package/dist/cjs/src/serializer/decorators/helpers/dreamAttributeOpenapiShape.js +0 -74
  345. package/dist/cjs/src/serializer/decorators/helpers/hasSerializersGetter.js +0 -11
  346. package/dist/cjs/src/serializer/decorators/helpers/maybeSerializableToDreamSerializerCallbackFunction.js +0 -20
  347. package/dist/esm/src/errors/MissingSerializersDefinition.js +0 -23
  348. package/dist/esm/src/helpers/inferSerializerFromDreamOrViewModel.js +0 -12
  349. package/dist/esm/src/serializer/decorators/associations/RendersMany.js +0 -81
  350. package/dist/esm/src/serializer/decorators/associations/RendersOne.js +0 -84
  351. package/dist/esm/src/serializer/decorators/associations/shared.js +0 -7
  352. package/dist/esm/src/serializer/decorators/attribute.js +0 -164
  353. package/dist/esm/src/serializer/decorators/helpers/dreamAttributeOpenapiShape.js +0 -69
  354. package/dist/esm/src/serializer/decorators/helpers/hasSerializersGetter.js +0 -8
  355. package/dist/esm/src/serializer/decorators/helpers/maybeSerializableToDreamSerializerCallbackFunction.js +0 -17
  356. package/dist/types/src/errors/MissingSerializersDefinition.d.ts +0 -6
  357. package/dist/types/src/helpers/inferSerializerFromDreamOrViewModel.d.ts +0 -4
  358. package/dist/types/src/serializer/decorators/associations/RendersMany.d.ts +0 -42
  359. package/dist/types/src/serializer/decorators/associations/RendersOne.d.ts +0 -46
  360. package/dist/types/src/serializer/decorators/associations/shared.d.ts +0 -24
  361. package/dist/types/src/serializer/decorators/attribute.d.ts +0 -28
  362. package/dist/types/src/serializer/decorators/helpers/dreamAttributeOpenapiShape.d.ts +0 -7
  363. package/dist/types/src/serializer/decorators/helpers/hasSerializersGetter.d.ts +0 -2
  364. package/dist/types/src/serializer/decorators/helpers/maybeSerializableToDreamSerializerCallbackFunction.d.ts +0 -2
  365. package/docs/classes/DreamSerializer.html +0 -19
  366. package/docs/functions/Attribute.html +0 -1
  367. package/docs/functions/RendersMany.html +0 -16
  368. package/docs/functions/RendersOne.html +0 -16
  369. package/docs/functions/inferSerializerFromDreamClassOrViewModelClass.html +0 -1
  370. package/docs/interfaces/AttributeStatement.html +0 -6
  371. package/docs/interfaces/DreamSerializerAssociationStatement.html +0 -11
  372. package/docs/types/SerializableClassOrSerializerCallback.html +0 -1
  373. package/docs/types/SerializableTypes.html +0 -1
  374. /package/dist/types/src/{helpers → serializer/helpers}/serializerNameFromFullyQualifiedModelName.d.ts +0 -0
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- > ATTENTION: we are currently in the process of releasing this code to the world, as of the afternoon of March 10th, 2025. This notice will be removed, and the version of this repo will be bumped to 1.0.0, once all of the repos have been migrated to the new spaces and we can verify that it is all working. This is anticipated to take 1 day.
1
+ > ATTENTION: we are currently in the process of releasing this code to the world, as of the afternoon of May 21st, 2025. This notice will be removed, and the version of this repo will be bumped to 1.0.0, once all of the repos have been migrated to the new spaces and we can verify that it is all working. This should happen sometime in the next month.
2
2
 
3
3
  Dream is a typescript-driven, esm-first ORM built on top of [kysely](http://kysely.dev). It is built to operate within the [Psychic web framework](https://psychic-docs.netlify.app), but can be brought into other projects and used without the encapsulating framework (though this is theoretical, and we do not encourage it at this time). It is actively being developed to support production-grade applications in use within the [RVOHealth organization](https://www.rvohealth.com), who has kindly sponsored the continued development of this ORM, as well as the Psychic web framework as a whole.
4
4
 
@@ -41,14 +41,12 @@ const CreateOrFindByFailedToCreateAndFind_js_1 = require("./errors/CreateOrFindB
41
41
  const CreateOrUpdateByFailedToCreateAndUpdate_js_1 = require("./errors/CreateOrUpdateByFailedToCreateAndUpdate.js");
42
42
  const GlobalNameNotSet_js_1 = require("./errors/dream-app/GlobalNameNotSet.js");
43
43
  const DreamMissingRequiredOverride_js_1 = require("./errors/DreamMissingRequiredOverride.js");
44
- const MissingSerializersDefinition_js_1 = require("./errors/MissingSerializersDefinition.js");
45
44
  const NonExistentScopeProvidedToResort_js_1 = require("./errors/NonExistentScopeProvidedToResort.js");
46
45
  const CalendarDate_js_1 = require("./helpers/CalendarDate.js");
47
46
  const cloneDeepSafe_js_1 = require("./helpers/cloneDeepSafe.js");
48
47
  const DateTime_js_1 = require("./helpers/DateTime.js");
49
48
  const cachedTypeForAttribute_js_1 = require("./helpers/db/cachedTypeForAttribute.js");
50
49
  const isJsonColumn_js_1 = require("./helpers/db/types/isJsonColumn.js");
51
- const inferSerializerFromDreamOrViewModel_js_1 = require("./helpers/inferSerializerFromDreamOrViewModel.js");
52
50
  const notEqual_js_1 = require("./helpers/notEqual.js");
53
51
  const typechecks_js_1 = require("./helpers/typechecks.js");
54
52
  class Dream {
@@ -489,6 +487,17 @@ class Dream {
489
487
  ...new Set([...columns, ...this.virtualAttributes.map(attr => attr.property)]),
490
488
  ];
491
489
  }
490
+ /**
491
+ * @internal
492
+ *
493
+ * Returns true if the column is a column in the database
494
+ *
495
+ * @param columnName - the name of the property you are checking for
496
+ * @returns boolean
497
+ */
498
+ static isColumn(columnName) {
499
+ return this.prototype.isColumn(columnName);
500
+ }
492
501
  /**
493
502
  * @internal
494
503
  *
@@ -596,6 +605,36 @@ class Dream {
596
605
  static async all(options = {}) {
597
606
  return await this.query().all(options);
598
607
  }
608
+ /**
609
+ * Paginates the results of your query, accepting a pageSize and page argument,
610
+ * which it uses to segment your query into pages, leveraging limit and offset
611
+ * to deliver your query to you in pages.
612
+ *
613
+ * ```ts
614
+ * const paginated = await User.paginate({ pageSize: 100, page: 2 })
615
+ * paginated.results
616
+ * // [ { User{id: 101}, User{id: 102}, ...}]
617
+ *
618
+ * paginated.recordCount
619
+ * // 350
620
+ *
621
+ * paginated.pageCount
622
+ * // 4
623
+ *
624
+ * paginated.currentPage
625
+ * // 2
626
+ * ```
627
+ *
628
+ * @param opts.page - the page number that you want to fetch results for
629
+ * @param opts.pageSize - the number of results per page (optional)
630
+ * @returns results.recordCount - A number representing the total number of records matching your query
631
+ * @returns results.pageCount - The number of pages needed to encapsulate all the matching records
632
+ * @returns results.currentPage - The current page (same as what is provided in the paginate args)
633
+ * @returns results.results - An array of records matching the current record
634
+ */
635
+ static async paginate(opts) {
636
+ return await this.query().paginate(opts);
637
+ }
599
638
  /**
600
639
  * Forces use of a database connection (e.g. 'primary') during the query.
601
640
  *
@@ -690,7 +729,7 @@ class Dream {
690
729
  try {
691
730
  const dreamModel = this.new({
692
731
  ...attributes,
693
- ...(extraOpts?.createWith || {}),
732
+ ...extraOpts?.createWith,
694
733
  });
695
734
  await dreamModel.save();
696
735
  return dreamModel;
@@ -744,7 +783,7 @@ class Dream {
744
783
  try {
745
784
  return await this.create({
746
785
  ...attributes,
747
- ...(extraOpts?.with || {}),
786
+ ...extraOpts?.with,
748
787
  }, skipHooks ? { skipHooks } : undefined);
749
788
  }
750
789
  catch (err) {
@@ -2112,6 +2151,17 @@ class Dream {
2112
2151
  */
2113
2152
  this.unshadowColumnPropertyPrototypeAccessors();
2114
2153
  }
2154
+ /**
2155
+ * @internal
2156
+ *
2157
+ * Returns true if the column is a column in the database
2158
+ *
2159
+ * @param columnName - the name of the property you are checking for
2160
+ * @returns boolean
2161
+ */
2162
+ isColumn(columnName) {
2163
+ return this.columns().has(columnName);
2164
+ }
2115
2165
  /**
2116
2166
  * Returns true if the columnName passed is marked by a
2117
2167
  * Virtual attribute decorator
@@ -2120,9 +2170,7 @@ class Dream {
2120
2170
  * @returns A boolean
2121
2171
  */
2122
2172
  isVirtualColumn(columnName) {
2123
- return this.constructor.virtualAttributes
2124
- .map(attr => attr.property)
2125
- .includes(columnName);
2173
+ return !!this.constructor.virtualAttributes.find(attr => attr.property === columnName);
2126
2174
  }
2127
2175
  /**
2128
2176
  * Returns an object with column names for keys, and an
@@ -2896,31 +2944,6 @@ class Dream {
2896
2944
  async reload() {
2897
2945
  await (0, reload_js_1.default)(this);
2898
2946
  }
2899
- /**
2900
- * Serializes an instance. You can specify a serializer key,
2901
- * or else the default will be used
2902
- *
2903
- * ```ts
2904
- * // uses the default serializer provided in the model's `serializers` getter
2905
- * await user.serialize()
2906
- *
2907
- * // uses the summary serializer provided in the model's `serializers` getter
2908
- * await user.serialize({ serializerKey: 'summary' })
2909
- * ```
2910
- *
2911
- * @param args.casing - Which casing to use when serializing (camel or snake, default camel)
2912
- * @param args.serializerKey - The key to use when referencing the object returned by the `serializers` getter on the given model instance (defaults to "default")
2913
- * @returns A serialized representation of the model
2914
- */
2915
- serialize({ casing = null, serializerKey } = {}) {
2916
- const serializerClass = (0, inferSerializerFromDreamOrViewModel_js_1.default)(this, serializerKey?.toString());
2917
- if (!serializerClass)
2918
- throw new MissingSerializersDefinition_js_1.default(this.constructor);
2919
- const serializer = new serializerClass(this);
2920
- if (casing)
2921
- serializer.casing(casing);
2922
- return serializer.render();
2923
- }
2924
2947
  /**
2925
2948
  * Takes the attributes passed in and sets their values,
2926
2949
  * leveraging any custom setters defined for these attributes.
@@ -81,7 +81,12 @@ class DreamBin {
81
81
  await (0, generateDream_js_1.default)({ fullyQualifiedModelName, columnsWithTypes, options });
82
82
  }
83
83
  static async generateStiChild(fullyQualifiedModelName, fullyQualifiedParentName, columnsWithTypes, options) {
84
- await (0, generateDream_js_1.default)({ fullyQualifiedModelName, columnsWithTypes, options, fullyQualifiedParentName });
84
+ await (0, generateDream_js_1.default)({
85
+ fullyQualifiedModelName,
86
+ columnsWithTypes,
87
+ options: { ...options, stiBaseSerializer: false },
88
+ fullyQualifiedParentName,
89
+ });
85
90
  }
86
91
  static async generateMigration(migrationName, columnsWithTypes) {
87
92
  await (0, generateMigration_js_1.default)({ migrationName, columnsWithTypes });
@@ -46,6 +46,7 @@ class DreamCLI {
46
46
  .alias('generate:dream')
47
47
  .alias('g:dream')
48
48
  .option('--no-serializer')
49
+ .option('--sti-base-serializer', 'Omits the serializer from the dream model, but does create the serializer so it can be extended by STI children')
49
50
  .description('create a new Dream model')
50
51
  .argument('<modelName>', 'the name of the model to create, e.g. Post or Settings/CommunicationPreferences')
51
52
  .argument('[columnsWithTypes...]', 'properties of the model property1:text/string/enum/etc. property2:text/string/enum/etc. ... propertyN:text/string/enum/etc.')
@@ -61,8 +61,11 @@ function extractValidationOptionsFromArgs(type, args) {
61
61
  }
62
62
  case 'requiredBelongsTo':
63
63
  return {};
64
- default:
65
- throw new Error(`Unhandled validation type when caching options: ${type}`);
64
+ default: {
65
+ // protection so that if a new ValidationType is ever added, this will throw a type error at build time
66
+ const _never = type;
67
+ throw new Error(`Unhandled ValidationType: ${_never}`);
68
+ }
66
69
  }
67
70
  }
68
71
  class ValidationInstantiationError extends Error {
@@ -38,6 +38,38 @@ class DreamClassTransactionBuilder {
38
38
  async all(options = {}) {
39
39
  return this.queryInstance().all(options);
40
40
  }
41
+ /**
42
+ * Paginates the results of your query, accepting a pageSize and page argument,
43
+ * which it uses to segment your query into pages, leveraging limit and offset
44
+ * to deliver your query to you in pages.
45
+ *
46
+ * ```ts
47
+ * await ApplicationModel.transaction(async txn => {
48
+ * const paginated = await User.txn(txn).paginate({ pageSize: 100, page: 2 })
49
+ * paginated.results
50
+ * // [ { User{id: 101}, User{id: 102}, ...}]
51
+ *
52
+ * paginated.recordCount
53
+ * // 350
54
+ *
55
+ * paginated.pageCount
56
+ * // 4
57
+ *
58
+ * paginated.currentPage
59
+ * // 2
60
+ * })
61
+ * ```
62
+ *
63
+ * @param opts.page - the page number that you want to fetch results for
64
+ * @param opts.pageSize - the number of results per page (optional)
65
+ * @returns results.recordCount - A number representing the total number of records matching your query
66
+ * @returns results.pageCount - The number of pages needed to encapsulate all the matching records
67
+ * @returns results.currentPage - The current page (same as what is provided in the paginate args)
68
+ * @returns results.results - An array of records matching the current record
69
+ */
70
+ async paginate(opts) {
71
+ return await this.queryInstance().paginate(opts);
72
+ }
41
73
  /**
42
74
  * Retrieves the number of records corresponding
43
75
  * to this model.
@@ -5,6 +5,7 @@ const pluralize_esm_1 = require("pluralize-esm");
5
5
  const ConnectedToDB_js_1 = require("../db/ConnectedToDB.js");
6
6
  const SoftDelete_js_1 = require("../decorators/class/SoftDelete.js");
7
7
  const associationToGetterSetterProp_js_1 = require("../decorators/field/association/associationToGetterSetterProp.js");
8
+ const index_js_1 = require("../dream-app/index.js");
8
9
  const AssociationDeclaredWithoutAssociatedDreamClass_js_1 = require("../errors/associations/AssociationDeclaredWithoutAssociatedDreamClass.js");
9
10
  const CannotAssociateThroughPolymorphic_js_1 = require("../errors/associations/CannotAssociateThroughPolymorphic.js");
10
11
  const CannotJoinPolymorphicBelongsToError_js_1 = require("../errors/associations/CannotJoinPolymorphicBelongsToError.js");
@@ -21,6 +22,8 @@ const LeftJoinPreloadIncompatibleWithFindEach_js_1 = require("../errors/LeftJoin
21
22
  const MissingRequiredCallbackFunctionToPluckEach_js_1 = require("../errors/MissingRequiredCallbackFunctionToPluckEach.js");
22
23
  const NoUpdateAllOnJoins_js_1 = require("../errors/NoUpdateAllOnJoins.js");
23
24
  const NoUpdateOnAssociationQuery_js_1 = require("../errors/NoUpdateOnAssociationQuery.js");
25
+ const CannotPaginateWithLimit_js_1 = require("../errors/pagination/CannotPaginateWithLimit.js");
26
+ const CannotPaginateWithOffset_js_1 = require("../errors/pagination/CannotPaginateWithOffset.js");
24
27
  const RecordNotFound_js_1 = require("../errors/RecordNotFound.js");
25
28
  const UnexpectedUndefined_js_1 = require("../errors/UnexpectedUndefined.js");
26
29
  const CalendarDate_js_1 = require("../helpers/CalendarDate.js");
@@ -38,9 +41,10 @@ const snakeify_js_1 = require("../helpers/snakeify.js");
38
41
  const typechecks_js_1 = require("../helpers/typechecks.js");
39
42
  const uniq_js_1 = require("../helpers/uniq.js");
40
43
  const curried_ops_statement_js_1 = require("../ops/curried-ops-statement.js");
41
- const index_js_1 = require("../ops/index.js");
44
+ const index_js_2 = require("../ops/index.js");
42
45
  const ops_statement_js_1 = require("../ops/ops-statement.js");
43
46
  const constants_js_1 = require("./constants.js");
47
+ const computedPaginatePage_js_1 = require("./internal/computedPaginatePage.js");
44
48
  const executeDatabaseQuery_js_1 = require("./internal/executeDatabaseQuery.js");
45
49
  const extractAssociationMetadataFromAssociationName_js_1 = require("./internal/extractAssociationMetadataFromAssociationName.js");
46
50
  const orderByDirection_js_1 = require("./internal/orderByDirection.js");
@@ -297,7 +301,7 @@ class Query extends ConnectedToDB_js_1.default {
297
301
  baseSelectQuery: opts.baseSelectQuery || this.baseSelectQuery,
298
302
  passthroughOnStatement: {
299
303
  ...this.passthroughOnStatement,
300
- ...(opts.passthroughOnStatement || {}),
304
+ ...opts.passthroughOnStatement,
301
305
  },
302
306
  where: opts.where === null ? [] : [...this.whereStatements, ...(opts.where || [])],
303
307
  whereNot: opts.whereNot === null ? [] : [...this.whereNotStatements, ...(opts.whereNot || [])],
@@ -438,13 +442,13 @@ class Query extends ConnectedToDB_js_1.default {
438
442
  let lastId = null;
439
443
  do {
440
444
  if (lastId)
441
- records = await query.where({ [this.dreamInstance.primaryKey]: index_js_1.default.greaterThan(lastId) }).all();
445
+ records = await query.where({ [this.dreamInstance.primaryKey]: index_js_2.default.greaterThan(lastId) }).all();
442
446
  else
443
447
  records = await query.all();
444
448
  for (const record of records) {
445
449
  await cb(record);
446
450
  }
447
- lastId = records[records.length - 1]?.primaryKeyValue;
451
+ lastId = records.at(-1)?.primaryKeyValue;
448
452
  } while (records.length > 0 && records.length === batchSize);
449
453
  }
450
454
  /**
@@ -999,8 +1003,11 @@ class Query extends ConnectedToDB_js_1.default {
999
1003
  return this.buildUpdate({});
1000
1004
  // TODO: in the future, we should support insert type, but don't yet, since inserts are done outside
1001
1005
  // the query class for some reason.
1002
- default:
1003
- throw new Error('never');
1006
+ default: {
1007
+ // protection so that if a new QueryType is ever added, this will throw a type error at build time
1008
+ const _never = type;
1009
+ throw new Error(`Unhandled QueryType: ${_never}`);
1010
+ }
1004
1011
  }
1005
1012
  }
1006
1013
  /**
@@ -1414,6 +1421,52 @@ class Query extends ConnectedToDB_js_1.default {
1414
1421
  await this.applyPreload(this.preloadStatements, this.preloadOnStatements, theAll);
1415
1422
  return theAll;
1416
1423
  }
1424
+ /**
1425
+ * Paginates the results of your query, accepting a pageSize and page argument,
1426
+ * which it uses to segment your query into pages, leveraging limit and offset
1427
+ * to deliver your query to you in pages.
1428
+ *
1429
+ * ```ts
1430
+ * const paginated = await User.order('email').paginate({ pageSize: 100, page: 2 })
1431
+ * paginated.results
1432
+ * // [ { User{id: 101}, User{id: 102}, ...}]
1433
+ *
1434
+ * paginated.recordCount
1435
+ * // 350
1436
+ *
1437
+ * paginated.pageCount
1438
+ * // 4
1439
+ *
1440
+ * paginated.currentPage
1441
+ * // 2
1442
+ * ```
1443
+ *
1444
+ * @param opts.page - the page number that you want to fetch results for
1445
+ * @param opts.pageSize - the number of results per page (optional)
1446
+ * @returns results.recordCount - A number representing the total number of records matching your query
1447
+ * @returns results.pageCount - The number of pages needed to encapsulate all the matching records
1448
+ * @returns results.currentPage - The current page (same as what is provided in the paginate args)
1449
+ * @returns results.results - An array of records matching the current record
1450
+ */
1451
+ async paginate(opts) {
1452
+ if (this.limitStatement)
1453
+ throw new CannotPaginateWithLimit_js_1.default();
1454
+ if (this.offsetStatement)
1455
+ throw new CannotPaginateWithOffset_js_1.default();
1456
+ const page = (0, computedPaginatePage_js_1.default)(opts.page);
1457
+ const recordCount = await this.count();
1458
+ const pageSize = opts.pageSize || index_js_1.default.getOrFail().paginationPageSize;
1459
+ const pageCount = Math.ceil(recordCount / pageSize);
1460
+ const results = await this.limit(pageSize)
1461
+ .offset((page - 1) * pageSize)
1462
+ .all();
1463
+ return {
1464
+ recordCount,
1465
+ pageCount,
1466
+ currentPage: page,
1467
+ results,
1468
+ };
1469
+ }
1417
1470
  /**
1418
1471
  * Forces use of a database connection (e.g. 'primary') during the query.
1419
1472
  *
@@ -1924,7 +1977,7 @@ class Query extends ConnectedToDB_js_1.default {
1924
1977
  pluckedData[dreamClassToHydrateColumns.length + index]));
1925
1978
  return {
1926
1979
  dream: hydratedDream,
1927
- pointsToPrimaryKey: pluckedData[pluckedData.length - 1],
1980
+ pointsToPrimaryKey: pluckedData.at(-1),
1928
1981
  };
1929
1982
  });
1930
1983
  this.hydrateAssociation(dreams, association, preloadedDreamsAndWhatTheyPointTo);
@@ -2430,7 +2483,7 @@ class Query extends ConnectedToDB_js_1.default {
2430
2483
  val = val();
2431
2484
  }
2432
2485
  else if (val === constants_js_1.DreamConst.passthrough) {
2433
- const column = attr.split('.').pop();
2486
+ const column = attr.split('.').at(-1);
2434
2487
  if (this.passthroughOnStatement[column] === undefined)
2435
2488
  throw new MissingRequiredPassthroughForAssociationAndClause_js_1.default(column);
2436
2489
  val = this.passthroughOnStatement[column];
@@ -14,25 +14,23 @@ exports.DreamConst = {
14
14
  required: RequiredAttribute,
15
15
  };
16
16
  exports.openapiPrimitiveTypes = [
17
- 'string',
18
17
  'boolean',
19
- 'number',
20
- 'date',
21
18
  'date-time',
22
- 'double',
19
+ 'date',
23
20
  'integer',
24
21
  'null',
22
+ 'number',
23
+ 'string',
25
24
  ];
26
25
  exports.openapiShorthandPrimitiveTypes = [
27
26
  ...exports.openapiPrimitiveTypes,
28
- 'decimal',
29
- 'string[]',
30
27
  'boolean[]',
31
- 'number[]',
32
- 'date[]',
33
28
  'date-time[]',
29
+ 'date[]',
30
+ 'decimal',
34
31
  'decimal[]',
35
- 'double[]',
36
32
  'integer[]',
37
33
  'json',
34
+ 'number[]',
35
+ 'string[]',
38
36
  ];
@@ -50,8 +50,11 @@ function checkSingleValidation(dream, validation) {
50
50
  if (associationMetadata === undefined)
51
51
  throw new UnexpectedUndefined_js_1.default();
52
52
  return !!(value || dream[associationMetadata.foreignKey()]);
53
- default:
54
- throw new Error(`Unhandled validation type found while running validations: ${validation.type}`);
53
+ default: {
54
+ // protection so that if a new ValidationType is ever added, this will throw a type error at build time
55
+ const _never = validation.type;
56
+ throw new Error(`Unhandled ValidationType: ${_never}`);
57
+ }
55
58
  }
56
59
  }
57
60
  function isBlank(value) {
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = computedPaginatePage;
4
+ function computedPaginatePage(page) {
5
+ if (page === null)
6
+ return 1;
7
+ if (page === undefined)
8
+ return 1;
9
+ return page <= 1 ? 1 : Math.floor(page);
10
+ }
@@ -9,7 +9,7 @@ async function findOrCreateBy(dreamClass, txn = null, attributes, extraOpts = {}
9
9
  return existingRecord;
10
10
  const dreamModel = dreamClass.new({
11
11
  ...attributes,
12
- ...(extraOpts?.createWith || {}),
12
+ ...extraOpts?.createWith,
13
13
  });
14
14
  await dreamModel.txn(txn).save();
15
15
  return dreamModel;
@@ -9,7 +9,10 @@ function orderByDirection(dir) {
9
9
  return (0, kysely_1.sql) `asc nulls first`;
10
10
  case 'desc':
11
11
  return (0, kysely_1.sql) `desc nulls last`;
12
- default:
13
- throw new Error(`Unrecognized orderBy direction: ${dir}`);
12
+ default: {
13
+ // protection so that if a new OrderDir is ever added, this will throw a type error at build time
14
+ const _never = dir;
15
+ throw new Error(`Unhandled OrderDir: ${_never}`);
16
+ }
14
17
  }
15
18
  }
@@ -13,6 +13,6 @@ async function updateOrCreateBy(dreamClass, txn = null, attributes, extraOpts =
13
13
  }
14
14
  return await dreamClass.txn(txn).create({
15
15
  ...attributes,
16
- ...(extraOpts?.with || {}),
16
+ ...extraOpts?.with,
17
17
  }, skipHooks ? { skipHooks } : undefined);
18
18
  }
@@ -31,11 +31,11 @@ class DreamImporter {
31
31
  }
32
32
  static async importSerializers(pathToSerializers, importCb) {
33
33
  const serializerPaths = await DreamImporter.ls(pathToSerializers);
34
- const serializerClasses = (await Promise.all(serializerPaths.map(serializerPath => importCb(serializerPath).then(serializerClass => [
34
+ const pathsNamesAndSerializers = (await Promise.all(serializerPaths.map(serializerPath => importCb(serializerPath).then(serializerClass => [
35
35
  serializerPath,
36
36
  serializerClass,
37
37
  ]))));
38
- return serializerClasses;
38
+ return pathsNamesAndSerializers;
39
39
  }
40
40
  }
41
41
  exports.default = DreamImporter;
@@ -73,7 +73,7 @@ function setCachedModels(models) {
73
73
  }
74
74
  function getModelsOrFail() {
75
75
  if (!_models)
76
- throw new Error('Must call loadModels before calling getModelsOrFail');
76
+ throw new Error('Must call importModels before calling getModelsOrFail');
77
77
  return _models;
78
78
  }
79
79
  function getModelsOrBlank() {
@@ -5,7 +5,7 @@ exports.setCachedSerializers = setCachedSerializers;
5
5
  exports.getSerializersOrFail = getSerializersOrFail;
6
6
  exports.getSerializersOrBlank = getSerializersOrBlank;
7
7
  const SerializerNameConflict_js_1 = require("../../../errors/dream-app/SerializerNameConflict.js");
8
- const index_js_1 = require("../../../serializer/index.js");
8
+ const isDreamSerializer_js_1 = require("../../../serializer/helpers/isDreamSerializer.js");
9
9
  const DreamImporter_js_1 = require("../DreamImporter.js");
10
10
  const globalSerializerKeyFromPath_js_1 = require("../globalSerializerKeyFromPath.js");
11
11
  let _serializers;
@@ -13,41 +13,20 @@ async function importSerializers(serializersPath, serializerImportCb) {
13
13
  if (_serializers)
14
14
  return _serializers;
15
15
  const serializerClasses = await DreamImporter_js_1.default.importSerializers(serializersPath, serializerImportCb);
16
- /**
17
- * Certain features (e.g. building OpenAPI specs from Attribute and RendersOne/Many decorators)
18
- * need static access to things set up by decorators. Stage 3 Decorators change the context that is available
19
- * at decoration time such that the class of a property being decorated is only avilable during instance instantiation. In order
20
- * to only apply static values once, on boot, `globallyInitializingDecorators` is set to true on DreamSerializer, and all serializers are instantiated.
21
- */
22
- index_js_1.default['globallyInitializingDecorators'] = true;
23
16
  _serializers = {};
24
17
  for (const [serializerPath, allSerializers] of serializerClasses) {
25
18
  Object.keys(allSerializers).forEach(key => {
26
19
  const potentialSerializer = allSerializers[key];
27
- if (potentialSerializer?.isDreamSerializer) {
20
+ if (potentialSerializer && (0, isDreamSerializer_js_1.default)(potentialSerializer)) {
28
21
  const serializerKey = (0, globalSerializerKeyFromPath_js_1.default)(serializerPath, serializersPath, key);
29
22
  if (_serializers[serializerKey])
30
23
  throw new SerializerNameConflict_js_1.default(serializerKey);
31
- const serializerClass = potentialSerializer;
32
- serializerClass['setGlobalName'](serializerKey);
33
- /**
34
- * Certain features (e.g. building OpenAPI specs from Attribute and RendersOne/Many decorators)
35
- * need static access to things set up by decorators. Stage 3 Decorators change the context that is available
36
- * at decoration time such that the class of a property being decorated is only avilable during instance instantiation. In order
37
- * to only apply static values once, on boot, `globallyInitializingDecorators` is set to true on DreamSerializer, and all serializers are instantiated.
38
- */
39
- new serializerClass({});
24
+ const serializer = potentialSerializer;
25
+ serializer['globalName'] = serializerKey;
40
26
  _serializers[serializerKey] = potentialSerializer;
41
27
  }
42
28
  });
43
29
  }
44
- /**
45
- * Certain features (e.g. building OpenAPI specs from Attribute and RendersOne/Many decorators)
46
- * need static access to things set up by decorators. Stage 3 Decorators change the context that is available
47
- * at decoration time such that the class of a property being decorated is only avilable during instance instantiation. In order
48
- * to only apply static values once, on boot, `globallyInitializingDecorators` is set to true on DreamSerializer, and all serializers are instantiated.
49
- */
50
- index_js_1.default['globallyInitializingDecorators'] = false;
51
30
  return _serializers;
52
31
  }
53
32
  function setCachedSerializers(serializers) {
@@ -55,7 +34,7 @@ function setCachedSerializers(serializers) {
55
34
  }
56
35
  function getSerializersOrFail() {
57
36
  if (!_serializers)
58
- throw new Error('Must call loadSerializers before calling getSerializersOrFail');
37
+ throw new Error('Must call importSerializers before calling getSerializersOrFail');
59
38
  return _serializers;
60
39
  }
61
40
  function getSerializersOrBlank() {
@@ -179,6 +179,10 @@ Try setting it to something valid, like:
179
179
  get unicodeNormalization() {
180
180
  return this._unicodeNormalization;
181
181
  }
182
+ _paginationPageSize = 25;
183
+ get paginationPageSize() {
184
+ return this._paginationPageSize;
185
+ }
182
186
  _primaryKeyType = 'bigserial';
183
187
  get primaryKeyType() {
184
188
  return this._primaryKeyType;
@@ -310,8 +314,14 @@ Try setting it to something valid, like:
310
314
  case 'unicodeNormalization':
311
315
  this._unicodeNormalization = options;
312
316
  break;
313
- default:
314
- throw new Error(`Unhandled applyOption encountered in Dreamconf: ${applyOption}`);
317
+ case 'paginationPageSize':
318
+ this._paginationPageSize = options;
319
+ break;
320
+ default: {
321
+ // protection so that if a new ApplyOpt is ever added, this will throw a type error at build time
322
+ const _never = applyOption;
323
+ throw new Error(`Unhandled ApplyOpt: ${_never}`);
324
+ }
315
325
  }
316
326
  }
317
327
  on(hookEventType, cb) {
@@ -15,8 +15,11 @@ class Encrypt {
15
15
  case 'aes-192-gcm':
16
16
  case 'aes-128-gcm':
17
17
  return (0, encryptAESGCM_js_1.default)(algorithm, data, key);
18
- default:
19
- throw new Error(`unrecognized algorith provided to encrypt: ${algorithm}`);
18
+ default: {
19
+ // protection so that if a new EncryptAlgorithm is ever added, this will throw a type error at build time
20
+ const _never = algorithm;
21
+ throw new Error(`Unhandled EncryptAlgorithm: ${_never}`);
22
+ }
20
23
  }
21
24
  }
22
25
  static decrypt(encrypted, { algorithm, key }, legacyOpts) {
@@ -36,8 +39,11 @@ class Encrypt {
36
39
  catch {
37
40
  return null;
38
41
  }
39
- default:
40
- throw new Error(`unrecognized algorith provided to decrypt: ${algorithm}`);
42
+ default: {
43
+ // protection so that if a new EncryptAlgorithm is ever added, this will throw a type error at build time
44
+ const _never = algorithm;
45
+ throw new Error(`Unhandled EncryptAlgorithm: ${_never}`);
46
+ }
41
47
  }
42
48
  }
43
49
  static attemptDecryptionWithLegacyKeys(encrypted, { algorithm, key }, legacyOpts) {
@@ -54,8 +60,11 @@ class Encrypt {
54
60
  return (0, generateKeyAESGCM_js_1.default)(192);
55
61
  case 'aes-128-gcm':
56
62
  return (0, generateKeyAESGCM_js_1.default)(128);
57
- default:
58
- throw new Error(`unrecognized algorithm provided to generateKey: ${algorithm}`);
63
+ default: {
64
+ // protection so that if a new EncryptAlgorithm is ever added, this will throw a type error at build time
65
+ const _never = algorithm;
66
+ throw new Error(`Unhandled EncryptAlgorithm: ${_never}`);
67
+ }
59
68
  }
60
69
  }
61
70
  static validateKey(base64EncodedKey, algorithm) {
@@ -66,8 +75,11 @@ class Encrypt {
66
75
  return (0, validateKeyAESGCM_js_1.default)(base64EncodedKey, 192);
67
76
  case 'aes-128-gcm':
68
77
  return (0, validateKeyAESGCM_js_1.default)(base64EncodedKey, 128);
69
- default:
70
- throw new Error(`unrecognized algorith provided to validateKey: ${algorithm}`);
78
+ default: {
79
+ // protection so that if a new EncryptAlgorithm is ever added, this will throw a type error at build time
80
+ const _never = algorithm;
81
+ throw new Error(`Unhandled EncryptAlgorithm: ${_never}`);
82
+ }
71
83
  }
72
84
  }
73
85
  }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class CannotPaginateWithLimit extends Error {
4
+ get message() {
5
+ return `\
6
+ Cannot call paginate on a query which has a limit applied.
7
+
8
+ Limit statements are automatically generated by the paginate method,
9
+ and adding custom limits interferes with paginate's ability to provide
10
+ a total count.
11
+
12
+ fix:
13
+ remove the limit statement from your query
14
+ `;
15
+ }
16
+ }
17
+ exports.default = CannotPaginateWithLimit;