@rvoh/dream 0.29.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 (1019) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +382 -0
  3. package/boilerplate/app/models/ApplicationModel.ts +14 -0
  4. package/boilerplate/app/serializers/.gitkeep +0 -0
  5. package/boilerplate/bin/esm.js +19 -0
  6. package/boilerplate/cli/helpers/initializeDreamApplication.ts +6 -0
  7. package/boilerplate/cli/index.ts +22 -0
  8. package/boilerplate/conf/inflections.ts +5 -0
  9. package/boilerplate/conf/loadEnv.ts +4 -0
  10. package/boilerplate/conf/repl.ts +11 -0
  11. package/boilerplate/eslint.config.js +21 -0
  12. package/boilerplate/package.json +42 -0
  13. package/boilerplate/tsconfig.build.json +41 -0
  14. package/boilerplate/tsconfig.json +12 -0
  15. package/boilerplate/types/db.ts +5 -0
  16. package/boilerplate/types/dream.ts +3 -0
  17. package/dist/cjs/boilerplate/package.json +42 -0
  18. package/dist/cjs/src/Dream.js +2984 -0
  19. package/dist/cjs/src/bin/helpers/sync.js +109 -0
  20. package/dist/cjs/src/bin/index.js +107 -0
  21. package/dist/cjs/src/cli/index.js +155 -0
  22. package/dist/cjs/src/db/ConnectedToDB.js +43 -0
  23. package/dist/cjs/src/db/ConnectionConfRetriever.js +22 -0
  24. package/dist/cjs/src/db/DreamDbConnection.js +77 -0
  25. package/dist/cjs/src/db/dataTypes.js +58 -0
  26. package/dist/cjs/src/db/errors.js +17 -0
  27. package/dist/cjs/src/db/index.js +12 -0
  28. package/dist/cjs/src/db/migration-helpers/DreamMigrationHelpers.js +193 -0
  29. package/dist/cjs/src/db/reflections.js +2 -0
  30. package/dist/cjs/src/db/types.js +2 -0
  31. package/dist/cjs/src/db/validators/validateColumn.js +11 -0
  32. package/dist/cjs/src/db/validators/validateTable.js +9 -0
  33. package/dist/cjs/src/db/validators/validateTableAlias.js +55 -0
  34. package/dist/cjs/src/decorators/DecoratorContextType.js +2 -0
  35. package/dist/cjs/src/decorators/Decorators.js +326 -0
  36. package/dist/cjs/src/decorators/Encrypted.js +83 -0
  37. package/dist/cjs/src/decorators/ReplicaSafe.js +12 -0
  38. package/dist/cjs/src/decorators/STI.js +35 -0
  39. package/dist/cjs/src/decorators/Scope.js +31 -0
  40. package/dist/cjs/src/decorators/SoftDelete.js +54 -0
  41. package/dist/cjs/src/decorators/Virtual.js +28 -0
  42. package/dist/cjs/src/decorators/associations/BelongsTo.js +77 -0
  43. package/dist/cjs/src/decorators/associations/HasMany.js +100 -0
  44. package/dist/cjs/src/decorators/associations/HasOne.js +96 -0
  45. package/dist/cjs/src/decorators/associations/associationToGetterSetterProp.js +6 -0
  46. package/dist/cjs/src/decorators/associations/shared.js +132 -0
  47. package/dist/cjs/src/decorators/helpers/freezeBaseClassArrayMap.js +10 -0
  48. package/dist/cjs/src/decorators/hooks/AfterCreate.js +26 -0
  49. package/dist/cjs/src/decorators/hooks/AfterCreateCommit.js +43 -0
  50. package/dist/cjs/src/decorators/hooks/AfterDestroy.js +25 -0
  51. package/dist/cjs/src/decorators/hooks/AfterDestroyCommit.js +40 -0
  52. package/dist/cjs/src/decorators/hooks/AfterSave.js +26 -0
  53. package/dist/cjs/src/decorators/hooks/AfterSaveCommit.js +43 -0
  54. package/dist/cjs/src/decorators/hooks/AfterUpdate.js +26 -0
  55. package/dist/cjs/src/decorators/hooks/AfterUpdateCommit.js +43 -0
  56. package/dist/cjs/src/decorators/hooks/BeforeCreate.js +26 -0
  57. package/dist/cjs/src/decorators/hooks/BeforeDestroy.js +25 -0
  58. package/dist/cjs/src/decorators/hooks/BeforeSave.js +26 -0
  59. package/dist/cjs/src/decorators/hooks/BeforeUpdate.js +26 -0
  60. package/dist/cjs/src/decorators/hooks/shared.js +23 -0
  61. package/dist/cjs/src/decorators/sortable/Sortable.js +160 -0
  62. package/dist/cjs/src/decorators/sortable/helpers/applySortableScopeToQuery.js +17 -0
  63. package/dist/cjs/src/decorators/sortable/helpers/clearCachedSortableValues.js +11 -0
  64. package/dist/cjs/src/decorators/sortable/helpers/decrementScopedRecordsGreaterThanPosition.js +26 -0
  65. package/dist/cjs/src/decorators/sortable/helpers/getColumnForSortableScope.js +18 -0
  66. package/dist/cjs/src/decorators/sortable/helpers/isSortedCorrectly.js +7 -0
  67. package/dist/cjs/src/decorators/sortable/helpers/positionIsInvalid.js +11 -0
  68. package/dist/cjs/src/decorators/sortable/helpers/resortAllRecords.js +38 -0
  69. package/dist/cjs/src/decorators/sortable/helpers/scopeArray.js +10 -0
  70. package/dist/cjs/src/decorators/sortable/helpers/setPosition.js +158 -0
  71. package/dist/cjs/src/decorators/sortable/helpers/sortableCacheKeyName.js +7 -0
  72. package/dist/cjs/src/decorators/sortable/helpers/sortableCacheValuesName.js +7 -0
  73. package/dist/cjs/src/decorators/sortable/helpers/sortableQueryExcludingDream.js +10 -0
  74. package/dist/cjs/src/decorators/sortable/hooks/afterSortableCreate.js +18 -0
  75. package/dist/cjs/src/decorators/sortable/hooks/afterSortableDestroy.js +14 -0
  76. package/dist/cjs/src/decorators/sortable/hooks/afterSortableUpdate.js +31 -0
  77. package/dist/cjs/src/decorators/sortable/hooks/beforeSortableSave.js +65 -0
  78. package/dist/cjs/src/decorators/validations/Validate.js +22 -0
  79. package/dist/cjs/src/decorators/validations/Validates.js +70 -0
  80. package/dist/cjs/src/decorators/validations/shared.js +2 -0
  81. package/dist/cjs/src/dream/DreamClassTransactionBuilder.js +592 -0
  82. package/dist/cjs/src/dream/DreamInstanceTransactionBuilder.js +480 -0
  83. package/dist/cjs/src/dream/DreamTransaction.js +26 -0
  84. package/dist/cjs/src/dream/LeftJoinLoadBuilder.js +77 -0
  85. package/dist/cjs/src/dream/LoadBuilder.js +68 -0
  86. package/dist/cjs/src/dream/Query.js +2618 -0
  87. package/dist/cjs/src/dream/internal/applyScopeBypassingSettingsToQuery.js +11 -0
  88. package/dist/cjs/src/dream/internal/associations/associationQuery.js +23 -0
  89. package/dist/cjs/src/dream/internal/associations/associationUpdateQuery.js +36 -0
  90. package/dist/cjs/src/dream/internal/associations/createAssociation.js +55 -0
  91. package/dist/cjs/src/dream/internal/associations/destroyAssociation.js +17 -0
  92. package/dist/cjs/src/dream/internal/associations/undestroyAssociation.js +12 -0
  93. package/dist/cjs/src/dream/internal/checkSingleValidation.js +52 -0
  94. package/dist/cjs/src/dream/internal/destroyAssociatedRecords.js +21 -0
  95. package/dist/cjs/src/dream/internal/destroyDream.js +72 -0
  96. package/dist/cjs/src/dream/internal/destroyOptions.js +32 -0
  97. package/dist/cjs/src/dream/internal/ensureSTITypeFieldIsSet.js +10 -0
  98. package/dist/cjs/src/dream/internal/executeDatabaseQuery.js +24 -0
  99. package/dist/cjs/src/dream/internal/extractAssociationMetadataFromAssociationName.js +8 -0
  100. package/dist/cjs/src/dream/internal/orderByDirection.js +15 -0
  101. package/dist/cjs/src/dream/internal/reload.js +21 -0
  102. package/dist/cjs/src/dream/internal/runHooksFor.js +99 -0
  103. package/dist/cjs/src/dream/internal/runValidations.js +16 -0
  104. package/dist/cjs/src/dream/internal/safelyRunCommitHooks.js +15 -0
  105. package/dist/cjs/src/dream/internal/saveDream.js +67 -0
  106. package/dist/cjs/src/dream/internal/scopeHelpers.js +13 -0
  107. package/dist/cjs/src/dream/internal/shouldBypassDefaultScope.js +12 -0
  108. package/dist/cjs/src/dream/internal/similarity/SimilarityBuilder.js +331 -0
  109. package/dist/cjs/src/dream/internal/similarity/similaritySelectSql.js +21 -0
  110. package/dist/cjs/src/dream/internal/similarity/similarityWhereSql.js +21 -0
  111. package/dist/cjs/src/dream/internal/softDeleteDream.js +22 -0
  112. package/dist/cjs/src/dream/internal/sqlResultToDreamInstance.js +38 -0
  113. package/dist/cjs/src/dream/internal/undestroyDream.js +90 -0
  114. package/dist/cjs/src/dream/types.js +98 -0
  115. package/dist/cjs/src/dream-application/cache.js +13 -0
  116. package/dist/cjs/src/dream-application/helpers/DreamImporter.js +52 -0
  117. package/dist/cjs/src/dream-application/helpers/globalModelKeyFromPath.js +10 -0
  118. package/dist/cjs/src/dream-application/helpers/globalSerializerKeyFromPath.js +17 -0
  119. package/dist/cjs/src/dream-application/helpers/globalServiceKeyFromPath.js +11 -0
  120. package/dist/cjs/src/dream-application/helpers/importers/importModels.js +81 -0
  121. package/dist/cjs/src/dream-application/helpers/importers/importSerializers.js +63 -0
  122. package/dist/cjs/src/dream-application/helpers/importers/importServices.js +43 -0
  123. package/dist/cjs/src/dream-application/helpers/lookupClassByGlobalName.js +17 -0
  124. package/dist/cjs/src/dream-application/helpers/lookupModelByGlobalName.js +13 -0
  125. package/dist/cjs/src/dream-application/helpers/lookupModelByGlobalNameOrNames.js +10 -0
  126. package/dist/cjs/src/dream-application/index.js +284 -0
  127. package/dist/cjs/src/encrypt/InternalEncrypt.js +32 -0
  128. package/dist/cjs/src/encrypt/algorithms/aes-gcm/decryptAESGCM.js +26 -0
  129. package/dist/cjs/src/encrypt/algorithms/aes-gcm/encryptAESGCM.js +12 -0
  130. package/dist/cjs/src/encrypt/algorithms/aes-gcm/generateKeyAESGCM.js +7 -0
  131. package/dist/cjs/src/encrypt/algorithms/aes-gcm/validateKeyAESGCM.js +11 -0
  132. package/dist/cjs/src/encrypt/index.js +95 -0
  133. package/dist/cjs/src/errors/AttemptingToMarshalInvalidArrayType.js +20 -0
  134. package/dist/cjs/src/errors/CannotCallUndestroyOnANonSoftDeleteModel.js +21 -0
  135. package/dist/cjs/src/errors/CannotDefineAssociationWithBothDependentAndPassthrough.js +19 -0
  136. package/dist/cjs/src/errors/CannotDefineAssociationWithBothDependentAndRequiredOnClause.js +19 -0
  137. package/dist/cjs/src/errors/CannotNegateSimilarityClause.js +22 -0
  138. package/dist/cjs/src/errors/CannotPassAdditionalFieldsToPluckEachAfterCallback.js +22 -0
  139. package/dist/cjs/src/errors/CannotPassUndefinedAsAValueToAWhereClause.js +20 -0
  140. package/dist/cjs/src/errors/CannotReloadUnsavedDream.js +16 -0
  141. package/dist/cjs/src/errors/ConstructorOnlyForInternalUse.js +9 -0
  142. package/dist/cjs/src/errors/CreateOrFindByFailedToCreateAndFind.js +18 -0
  143. package/dist/cjs/src/errors/DoNotSetEncryptedFieldsDirectly.js +23 -0
  144. package/dist/cjs/src/errors/InvalidColumnName.js +19 -0
  145. package/dist/cjs/src/errors/InvalidDecimalFieldPassedToGenerator.js +19 -0
  146. package/dist/cjs/src/errors/InvalidTableAlias.js +30 -0
  147. package/dist/cjs/src/errors/InvalidTableName.js +23 -0
  148. package/dist/cjs/src/errors/LeftJoinPreloadIncompatibleWithFindEach.js +12 -0
  149. package/dist/cjs/src/errors/MissingDB.js +10 -0
  150. package/dist/cjs/src/errors/MissingDeletedAtFieldForSoftDelete.js +24 -0
  151. package/dist/cjs/src/errors/MissingRequiredCallbackFunctionToPluckEach.js +22 -0
  152. package/dist/cjs/src/errors/MissingSerializersDefinition.js +26 -0
  153. package/dist/cjs/src/errors/MissingTable.js +27 -0
  154. package/dist/cjs/src/errors/NoUpdateAllOnJoins.js +13 -0
  155. package/dist/cjs/src/errors/NoUpdateOnAssociationQuery.js +10 -0
  156. package/dist/cjs/src/errors/NonBelongsToAssociationProvidedAsSortableDecoratorScope.js +23 -0
  157. package/dist/cjs/src/errors/NonExistentScopeProvidedToResort.js +23 -0
  158. package/dist/cjs/src/errors/PrototypePollutingAssignment.js +13 -0
  159. package/dist/cjs/src/errors/RecordNotFound.js +15 -0
  160. package/dist/cjs/src/errors/SortableDecoratorRequiresColumnOrBelongsToAssociation.js +26 -0
  161. package/dist/cjs/src/errors/ValidationError.js +19 -0
  162. package/dist/cjs/src/errors/associations/CanOnlyPassBelongsToModelParam.js +20 -0
  163. package/dist/cjs/src/errors/associations/CannotAssociateThroughPolymorphic.js +19 -0
  164. package/dist/cjs/src/errors/associations/CannotCreateAssociationWithThroughContext.js +19 -0
  165. package/dist/cjs/src/errors/associations/CannotJoinPolymorphicBelongsToError.js +27 -0
  166. package/dist/cjs/src/errors/associations/CannotPassNullOrUndefinedToRequiredBelongsTo.js +19 -0
  167. package/dist/cjs/src/errors/associations/InvalidComputedForeignKey.js +64 -0
  168. package/dist/cjs/src/errors/associations/JoinAttemptedOnMissingAssociation.js +27 -0
  169. package/dist/cjs/src/errors/associations/MissingRequiredAssociationOnClause.js +19 -0
  170. package/dist/cjs/src/errors/associations/MissingRequiredPassthroughForAssociationOnClause.js +16 -0
  171. package/dist/cjs/src/errors/associations/MissingThroughAssociation.js +27 -0
  172. package/dist/cjs/src/errors/associations/MissingThroughAssociationSource.js +42 -0
  173. package/dist/cjs/src/errors/associations/NonLoadedAssociation.js +18 -0
  174. package/dist/cjs/src/errors/dream-application/DreamApplicationInitMissingCallToLoadModels.js +18 -0
  175. package/dist/cjs/src/errors/dream-application/DreamApplicationInitMissingMissingProjectRoot.js +19 -0
  176. package/dist/cjs/src/errors/dream-application/GlobalNameNotSet.js +14 -0
  177. package/dist/cjs/src/errors/dream-application/SerializerNameConflict.js +15 -0
  178. package/dist/cjs/src/errors/encrypt/MissingColumnEncryptionOpts.js +27 -0
  179. package/dist/cjs/src/errors/encrypt/MissingEncryptionKey.js +12 -0
  180. package/dist/cjs/src/errors/environment/MissingRequiredEnvironmentVariable.js +13 -0
  181. package/dist/cjs/src/errors/ops/AnyRequiresArrayColumn.js +18 -0
  182. package/dist/cjs/src/errors/ops/ScoreMustBeANormalNumber.js +17 -0
  183. package/dist/cjs/src/errors/schema-builder/FailedToIdentifyAssociation.js +80 -0
  184. package/dist/cjs/src/errors/serializers/FailedToRenderThroughAssociationForSerializer.js +17 -0
  185. package/dist/cjs/src/errors/sortable/CannotCallSortableOnSTIChild.js +18 -0
  186. package/dist/cjs/src/errors/sti/STIChildMissing.js +23 -0
  187. package/dist/cjs/src/errors/sti/StiChildCannotDefineNewAssociations.js +20 -0
  188. package/dist/cjs/src/errors/sti/StiChildIncompatibleWithReplicaSafeDecorator.js +17 -0
  189. package/dist/cjs/src/errors/sti/StiChildIncompatibleWithSoftDeleteDecorator.js +17 -0
  190. package/dist/cjs/src/global-cli/dream.js +46 -0
  191. package/dist/cjs/src/global-cli/file-builders/DreamtsBuilder.js +69 -0
  192. package/dist/cjs/src/global-cli/file-builders/EnvBuilder.js +27 -0
  193. package/dist/cjs/src/global-cli/file-builders/EslintConfBuilder.js +29 -0
  194. package/dist/cjs/src/global-cli/file-builders/PackagejsonBuilder.js +9 -0
  195. package/dist/cjs/src/global-cli/helpers/argAndValue.js +15 -0
  196. package/dist/cjs/src/global-cli/helpers/autogeneratedFileMessage.js +71 -0
  197. package/dist/cjs/src/global-cli/helpers/buildNewDreamApp.js +63 -0
  198. package/dist/cjs/src/global-cli/helpers/copyRecursive.js +20 -0
  199. package/dist/cjs/src/global-cli/helpers/filterObjectByKey.js +23 -0
  200. package/dist/cjs/src/global-cli/helpers/generateEncryptionKey.js +26 -0
  201. package/dist/cjs/src/global-cli/helpers/globalCliSnakeify.js +1 -0
  202. package/dist/cjs/src/global-cli/helpers/initDreamAppIntoExistingProject.js +85 -0
  203. package/dist/cjs/src/global-cli/helpers/log.js +28 -0
  204. package/dist/cjs/src/global-cli/helpers/logo.js +81 -0
  205. package/dist/cjs/src/global-cli/helpers/primaryKeyTypes.js +13 -0
  206. package/dist/cjs/src/global-cli/helpers/prompt.js +33 -0
  207. package/dist/cjs/src/global-cli/helpers/select.js +113 -0
  208. package/dist/cjs/src/global-cli/helpers/sleep.js +10 -0
  209. package/dist/cjs/src/global-cli/helpers/sspawn.js +21 -0
  210. package/dist/cjs/src/global-cli/helpers/welcomeMessage.js +41 -0
  211. package/dist/cjs/src/global-cli/init.js +56 -0
  212. package/dist/cjs/src/global-cli/new.js +10 -0
  213. package/dist/cjs/src/helpers/CalendarDate.js +172 -0
  214. package/dist/cjs/src/helpers/Env.js +78 -0
  215. package/dist/cjs/src/helpers/EnvInternal.js +5 -0
  216. package/dist/cjs/src/helpers/allNestedObjectKeys.js +12 -0
  217. package/dist/cjs/src/helpers/benchmark.js +18 -0
  218. package/dist/cjs/src/helpers/camelize.js +15 -0
  219. package/dist/cjs/src/helpers/capitalize.js +6 -0
  220. package/dist/cjs/src/helpers/cli/SchemaBuilder.js +378 -0
  221. package/dist/cjs/src/helpers/cli/generateDream.js +48 -0
  222. package/dist/cjs/src/helpers/cli/generateDreamContent.js +107 -0
  223. package/dist/cjs/src/helpers/cli/generateFactory.js +26 -0
  224. package/dist/cjs/src/helpers/cli/generateFactoryContent.js +58 -0
  225. package/dist/cjs/src/helpers/cli/generateMigration.js +56 -0
  226. package/dist/cjs/src/helpers/cli/generateMigrationContent.js +196 -0
  227. package/dist/cjs/src/helpers/cli/generateSerializer.js +26 -0
  228. package/dist/cjs/src/helpers/cli/generateSerializerContent.js +130 -0
  229. package/dist/cjs/src/helpers/cli/generateStiMigrationContent.js +7 -0
  230. package/dist/cjs/src/helpers/cli/generateUnitSpec.js +26 -0
  231. package/dist/cjs/src/helpers/cli/generateUnitSpecContent.js +10 -0
  232. package/dist/cjs/src/helpers/cloneDeepSafe.js +69 -0
  233. package/dist/cjs/src/helpers/compact.js +14 -0
  234. package/dist/cjs/src/helpers/customPgParsers.js +39 -0
  235. package/dist/cjs/src/helpers/db/cachedTypeForAttribute.js +6 -0
  236. package/dist/cjs/src/helpers/db/createDb.js +20 -0
  237. package/dist/cjs/src/helpers/db/dropDb.js +36 -0
  238. package/dist/cjs/src/helpers/db/foreignKeyTypeFromPrimaryKey.js +11 -0
  239. package/dist/cjs/src/helpers/db/loadPgClient.js +20 -0
  240. package/dist/cjs/src/helpers/db/primaryKeyType.js +23 -0
  241. package/dist/cjs/src/helpers/db/runMigration.js +97 -0
  242. package/dist/cjs/src/helpers/db/truncateDb.js +27 -0
  243. package/dist/cjs/src/helpers/db/types/isDatabaseArrayColumn.js +6 -0
  244. package/dist/cjs/src/helpers/db/types/isDateColumn.js +6 -0
  245. package/dist/cjs/src/helpers/db/types/isDateTimeColumn.js +6 -0
  246. package/dist/cjs/src/helpers/db/types/isJsonColumn.js +6 -0
  247. package/dist/cjs/src/helpers/debug.js +11 -0
  248. package/dist/cjs/src/helpers/dreamOrPsychicCoreDevelopment.js +10 -0
  249. package/dist/cjs/src/helpers/filterObjectByKey.js +14 -0
  250. package/dist/cjs/src/helpers/getFiles.js +20 -0
  251. package/dist/cjs/src/helpers/globalClassNameFromFullyQualifiedModelName.js +7 -0
  252. package/dist/cjs/src/helpers/hyphenize.js +11 -0
  253. package/dist/cjs/src/helpers/inferSerializerFromDreamOrViewModel.js +16 -0
  254. package/dist/cjs/src/helpers/isEmpty.js +8 -0
  255. package/dist/cjs/src/helpers/loadEnv.js +37 -0
  256. package/dist/cjs/src/helpers/loadRepl.js +25 -0
  257. package/dist/cjs/src/helpers/migrationVersion.js +6 -0
  258. package/dist/cjs/src/helpers/namespaceColumn.js +8 -0
  259. package/dist/cjs/src/helpers/objectPathsToArrays.js +19 -0
  260. package/dist/cjs/src/helpers/pascalize.js +12 -0
  261. package/dist/cjs/src/helpers/pascalizePath.js +10 -0
  262. package/dist/cjs/src/helpers/path/dreamFileAndDirPaths.js +16 -0
  263. package/dist/cjs/src/helpers/path/dreamPath.js +25 -0
  264. package/dist/cjs/src/helpers/path/relativeDreamPath.js +50 -0
  265. package/dist/cjs/src/helpers/path/sharedPathPrefix.js +14 -0
  266. package/dist/cjs/src/helpers/propertyNameFromFullyQualifiedModelName.js +8 -0
  267. package/dist/cjs/src/helpers/protectAgainstPollutingAssignment.js +14 -0
  268. package/dist/cjs/src/helpers/range.js +20 -0
  269. package/dist/cjs/src/helpers/round.js +7 -0
  270. package/dist/cjs/src/helpers/serializerNameFromFullyQualifiedModelName.js +13 -0
  271. package/dist/cjs/src/helpers/snakeify.js +14 -0
  272. package/dist/cjs/src/helpers/sortBy.js +31 -0
  273. package/dist/cjs/src/helpers/sqlAttributes.js +28 -0
  274. package/dist/cjs/src/helpers/sspawn.js +21 -0
  275. package/dist/cjs/src/helpers/standardizeFullyQualifiedModelName.js +10 -0
  276. package/dist/cjs/src/helpers/stringCasing.js +34 -0
  277. package/dist/cjs/src/helpers/typechecks.js +16 -0
  278. package/dist/cjs/src/helpers/typeutils.js +2 -0
  279. package/dist/cjs/src/helpers/uncapitalize.js +6 -0
  280. package/dist/cjs/src/helpers/uniq.js +21 -0
  281. package/dist/cjs/src/index.js +154 -0
  282. package/dist/cjs/src/openapi/types.js +26 -0
  283. package/dist/cjs/src/ops/curried-ops-statement.js +12 -0
  284. package/dist/cjs/src/ops/index.js +42 -0
  285. package/dist/cjs/src/ops/ops-statement.js +38 -0
  286. package/dist/cjs/src/serializer/decorators/associations/RendersMany.js +84 -0
  287. package/dist/cjs/src/serializer/decorators/associations/RendersOne.js +87 -0
  288. package/dist/cjs/src/serializer/decorators/associations/shared.js +10 -0
  289. package/dist/cjs/src/serializer/decorators/attribute.js +161 -0
  290. package/dist/cjs/src/serializer/decorators/helpers/dreamAttributeOpenapiShape.js +78 -0
  291. package/dist/cjs/src/serializer/decorators/helpers/hasSerializersGetter.js +11 -0
  292. package/dist/cjs/src/serializer/decorators/helpers/maybeSerializableToDreamSerializerCallbackFunction.js +20 -0
  293. package/dist/cjs/src/serializer/index.js +271 -0
  294. package/dist/esm/boilerplate/package.json +42 -0
  295. package/dist/esm/src/Dream.js +2981 -0
  296. package/dist/esm/src/bin/helpers/sync.js +106 -0
  297. package/dist/esm/src/bin/index.js +104 -0
  298. package/dist/esm/src/cli/index.js +152 -0
  299. package/dist/esm/src/db/ConnectedToDB.js +40 -0
  300. package/dist/esm/src/db/ConnectionConfRetriever.js +19 -0
  301. package/dist/esm/src/db/DreamDbConnection.js +72 -0
  302. package/dist/esm/src/db/dataTypes.js +53 -0
  303. package/dist/esm/src/db/errors.js +13 -0
  304. package/dist/esm/src/db/index.js +9 -0
  305. package/dist/esm/src/db/migration-helpers/DreamMigrationHelpers.js +190 -0
  306. package/dist/esm/src/db/reflections.js +1 -0
  307. package/dist/esm/src/db/types.js +1 -0
  308. package/dist/esm/src/db/validators/validateColumn.js +8 -0
  309. package/dist/esm/src/db/validators/validateTable.js +6 -0
  310. package/dist/esm/src/db/validators/validateTableAlias.js +52 -0
  311. package/dist/esm/src/decorators/DecoratorContextType.js +1 -0
  312. package/dist/esm/src/decorators/Decorators.js +323 -0
  313. package/dist/esm/src/decorators/Encrypted.js +80 -0
  314. package/dist/esm/src/decorators/ReplicaSafe.js +9 -0
  315. package/dist/esm/src/decorators/STI.js +31 -0
  316. package/dist/esm/src/decorators/Scope.js +27 -0
  317. package/dist/esm/src/decorators/SoftDelete.js +50 -0
  318. package/dist/esm/src/decorators/Virtual.js +25 -0
  319. package/dist/esm/src/decorators/associations/BelongsTo.js +74 -0
  320. package/dist/esm/src/decorators/associations/HasMany.js +97 -0
  321. package/dist/esm/src/decorators/associations/HasOne.js +93 -0
  322. package/dist/esm/src/decorators/associations/associationToGetterSetterProp.js +3 -0
  323. package/dist/esm/src/decorators/associations/shared.js +123 -0
  324. package/dist/esm/src/decorators/helpers/freezeBaseClassArrayMap.js +7 -0
  325. package/dist/esm/src/decorators/hooks/AfterCreate.js +22 -0
  326. package/dist/esm/src/decorators/hooks/AfterCreateCommit.js +39 -0
  327. package/dist/esm/src/decorators/hooks/AfterDestroy.js +21 -0
  328. package/dist/esm/src/decorators/hooks/AfterDestroyCommit.js +36 -0
  329. package/dist/esm/src/decorators/hooks/AfterSave.js +22 -0
  330. package/dist/esm/src/decorators/hooks/AfterSaveCommit.js +39 -0
  331. package/dist/esm/src/decorators/hooks/AfterUpdate.js +22 -0
  332. package/dist/esm/src/decorators/hooks/AfterUpdateCommit.js +39 -0
  333. package/dist/esm/src/decorators/hooks/BeforeCreate.js +22 -0
  334. package/dist/esm/src/decorators/hooks/BeforeDestroy.js +21 -0
  335. package/dist/esm/src/decorators/hooks/BeforeSave.js +22 -0
  336. package/dist/esm/src/decorators/hooks/BeforeUpdate.js +22 -0
  337. package/dist/esm/src/decorators/hooks/shared.js +20 -0
  338. package/dist/esm/src/decorators/sortable/Sortable.js +157 -0
  339. package/dist/esm/src/decorators/sortable/helpers/applySortableScopeToQuery.js +14 -0
  340. package/dist/esm/src/decorators/sortable/helpers/clearCachedSortableValues.js +8 -0
  341. package/dist/esm/src/decorators/sortable/helpers/decrementScopedRecordsGreaterThanPosition.js +23 -0
  342. package/dist/esm/src/decorators/sortable/helpers/getColumnForSortableScope.js +15 -0
  343. package/dist/esm/src/decorators/sortable/helpers/isSortedCorrectly.js +4 -0
  344. package/dist/esm/src/decorators/sortable/helpers/positionIsInvalid.js +8 -0
  345. package/dist/esm/src/decorators/sortable/helpers/resortAllRecords.js +35 -0
  346. package/dist/esm/src/decorators/sortable/helpers/scopeArray.js +7 -0
  347. package/dist/esm/src/decorators/sortable/helpers/setPosition.js +154 -0
  348. package/dist/esm/src/decorators/sortable/helpers/sortableCacheKeyName.js +4 -0
  349. package/dist/esm/src/decorators/sortable/helpers/sortableCacheValuesName.js +4 -0
  350. package/dist/esm/src/decorators/sortable/helpers/sortableQueryExcludingDream.js +7 -0
  351. package/dist/esm/src/decorators/sortable/hooks/afterSortableCreate.js +15 -0
  352. package/dist/esm/src/decorators/sortable/hooks/afterSortableDestroy.js +11 -0
  353. package/dist/esm/src/decorators/sortable/hooks/afterSortableUpdate.js +28 -0
  354. package/dist/esm/src/decorators/sortable/hooks/beforeSortableSave.js +62 -0
  355. package/dist/esm/src/decorators/validations/Validate.js +19 -0
  356. package/dist/esm/src/decorators/validations/Validates.js +64 -0
  357. package/dist/esm/src/decorators/validations/shared.js +1 -0
  358. package/dist/esm/src/dream/DreamClassTransactionBuilder.js +589 -0
  359. package/dist/esm/src/dream/DreamInstanceTransactionBuilder.js +477 -0
  360. package/dist/esm/src/dream/DreamTransaction.js +23 -0
  361. package/dist/esm/src/dream/LeftJoinLoadBuilder.js +74 -0
  362. package/dist/esm/src/dream/LoadBuilder.js +65 -0
  363. package/dist/esm/src/dream/Query.js +2615 -0
  364. package/dist/esm/src/dream/internal/applyScopeBypassingSettingsToQuery.js +8 -0
  365. package/dist/esm/src/dream/internal/associations/associationQuery.js +20 -0
  366. package/dist/esm/src/dream/internal/associations/associationUpdateQuery.js +33 -0
  367. package/dist/esm/src/dream/internal/associations/createAssociation.js +52 -0
  368. package/dist/esm/src/dream/internal/associations/destroyAssociation.js +14 -0
  369. package/dist/esm/src/dream/internal/associations/undestroyAssociation.js +9 -0
  370. package/dist/esm/src/dream/internal/checkSingleValidation.js +49 -0
  371. package/dist/esm/src/dream/internal/destroyAssociatedRecords.js +18 -0
  372. package/dist/esm/src/dream/internal/destroyDream.js +69 -0
  373. package/dist/esm/src/dream/internal/destroyOptions.js +27 -0
  374. package/dist/esm/src/dream/internal/ensureSTITypeFieldIsSet.js +7 -0
  375. package/dist/esm/src/dream/internal/executeDatabaseQuery.js +21 -0
  376. package/dist/esm/src/dream/internal/extractAssociationMetadataFromAssociationName.js +5 -0
  377. package/dist/esm/src/dream/internal/orderByDirection.js +12 -0
  378. package/dist/esm/src/dream/internal/reload.js +18 -0
  379. package/dist/esm/src/dream/internal/runHooksFor.js +95 -0
  380. package/dist/esm/src/dream/internal/runValidations.js +13 -0
  381. package/dist/esm/src/dream/internal/safelyRunCommitHooks.js +12 -0
  382. package/dist/esm/src/dream/internal/saveDream.js +64 -0
  383. package/dist/esm/src/dream/internal/scopeHelpers.js +9 -0
  384. package/dist/esm/src/dream/internal/shouldBypassDefaultScope.js +9 -0
  385. package/dist/esm/src/dream/internal/similarity/SimilarityBuilder.js +327 -0
  386. package/dist/esm/src/dream/internal/similarity/similaritySelectSql.js +18 -0
  387. package/dist/esm/src/dream/internal/similarity/similarityWhereSql.js +18 -0
  388. package/dist/esm/src/dream/internal/softDeleteDream.js +19 -0
  389. package/dist/esm/src/dream/internal/sqlResultToDreamInstance.js +34 -0
  390. package/dist/esm/src/dream/internal/undestroyDream.js +87 -0
  391. package/dist/esm/src/dream/types.js +95 -0
  392. package/dist/esm/src/dream-application/cache.js +9 -0
  393. package/dist/esm/src/dream-application/helpers/DreamImporter.js +49 -0
  394. package/dist/esm/src/dream-application/helpers/globalModelKeyFromPath.js +7 -0
  395. package/dist/esm/src/dream-application/helpers/globalSerializerKeyFromPath.js +14 -0
  396. package/dist/esm/src/dream-application/helpers/globalServiceKeyFromPath.js +8 -0
  397. package/dist/esm/src/dream-application/helpers/importers/importModels.js +75 -0
  398. package/dist/esm/src/dream-application/helpers/importers/importSerializers.js +57 -0
  399. package/dist/esm/src/dream-application/helpers/importers/importServices.js +37 -0
  400. package/dist/esm/src/dream-application/helpers/lookupClassByGlobalName.js +14 -0
  401. package/dist/esm/src/dream-application/helpers/lookupModelByGlobalName.js +10 -0
  402. package/dist/esm/src/dream-application/helpers/lookupModelByGlobalNameOrNames.js +7 -0
  403. package/dist/esm/src/dream-application/index.js +281 -0
  404. package/dist/esm/src/encrypt/InternalEncrypt.js +29 -0
  405. package/dist/esm/src/encrypt/algorithms/aes-gcm/decryptAESGCM.js +23 -0
  406. package/dist/esm/src/encrypt/algorithms/aes-gcm/encryptAESGCM.js +9 -0
  407. package/dist/esm/src/encrypt/algorithms/aes-gcm/generateKeyAESGCM.js +4 -0
  408. package/dist/esm/src/encrypt/algorithms/aes-gcm/validateKeyAESGCM.js +8 -0
  409. package/dist/esm/src/encrypt/index.js +92 -0
  410. package/dist/esm/src/errors/AttemptingToMarshalInvalidArrayType.js +17 -0
  411. package/dist/esm/src/errors/CannotCallUndestroyOnANonSoftDeleteModel.js +18 -0
  412. package/dist/esm/src/errors/CannotDefineAssociationWithBothDependentAndPassthrough.js +16 -0
  413. package/dist/esm/src/errors/CannotDefineAssociationWithBothDependentAndRequiredOnClause.js +16 -0
  414. package/dist/esm/src/errors/CannotNegateSimilarityClause.js +19 -0
  415. package/dist/esm/src/errors/CannotPassAdditionalFieldsToPluckEachAfterCallback.js +19 -0
  416. package/dist/esm/src/errors/CannotPassUndefinedAsAValueToAWhereClause.js +17 -0
  417. package/dist/esm/src/errors/CannotReloadUnsavedDream.js +13 -0
  418. package/dist/esm/src/errors/ConstructorOnlyForInternalUse.js +6 -0
  419. package/dist/esm/src/errors/CreateOrFindByFailedToCreateAndFind.js +15 -0
  420. package/dist/esm/src/errors/DoNotSetEncryptedFieldsDirectly.js +20 -0
  421. package/dist/esm/src/errors/InvalidColumnName.js +16 -0
  422. package/dist/esm/src/errors/InvalidDecimalFieldPassedToGenerator.js +16 -0
  423. package/dist/esm/src/errors/InvalidTableAlias.js +27 -0
  424. package/dist/esm/src/errors/InvalidTableName.js +20 -0
  425. package/dist/esm/src/errors/LeftJoinPreloadIncompatibleWithFindEach.js +9 -0
  426. package/dist/esm/src/errors/MissingDB.js +7 -0
  427. package/dist/esm/src/errors/MissingDeletedAtFieldForSoftDelete.js +21 -0
  428. package/dist/esm/src/errors/MissingRequiredCallbackFunctionToPluckEach.js +19 -0
  429. package/dist/esm/src/errors/MissingSerializersDefinition.js +23 -0
  430. package/dist/esm/src/errors/MissingTable.js +24 -0
  431. package/dist/esm/src/errors/NoUpdateAllOnJoins.js +10 -0
  432. package/dist/esm/src/errors/NoUpdateOnAssociationQuery.js +7 -0
  433. package/dist/esm/src/errors/NonBelongsToAssociationProvidedAsSortableDecoratorScope.js +20 -0
  434. package/dist/esm/src/errors/NonExistentScopeProvidedToResort.js +20 -0
  435. package/dist/esm/src/errors/PrototypePollutingAssignment.js +10 -0
  436. package/dist/esm/src/errors/RecordNotFound.js +12 -0
  437. package/dist/esm/src/errors/SortableDecoratorRequiresColumnOrBelongsToAssociation.js +23 -0
  438. package/dist/esm/src/errors/ValidationError.js +16 -0
  439. package/dist/esm/src/errors/associations/CanOnlyPassBelongsToModelParam.js +17 -0
  440. package/dist/esm/src/errors/associations/CannotAssociateThroughPolymorphic.js +16 -0
  441. package/dist/esm/src/errors/associations/CannotCreateAssociationWithThroughContext.js +16 -0
  442. package/dist/esm/src/errors/associations/CannotJoinPolymorphicBelongsToError.js +24 -0
  443. package/dist/esm/src/errors/associations/CannotPassNullOrUndefinedToRequiredBelongsTo.js +16 -0
  444. package/dist/esm/src/errors/associations/InvalidComputedForeignKey.js +58 -0
  445. package/dist/esm/src/errors/associations/JoinAttemptedOnMissingAssociation.js +24 -0
  446. package/dist/esm/src/errors/associations/MissingRequiredAssociationOnClause.js +16 -0
  447. package/dist/esm/src/errors/associations/MissingRequiredPassthroughForAssociationOnClause.js +13 -0
  448. package/dist/esm/src/errors/associations/MissingThroughAssociation.js +24 -0
  449. package/dist/esm/src/errors/associations/MissingThroughAssociationSource.js +39 -0
  450. package/dist/esm/src/errors/associations/NonLoadedAssociation.js +15 -0
  451. package/dist/esm/src/errors/dream-application/DreamApplicationInitMissingCallToLoadModels.js +15 -0
  452. package/dist/esm/src/errors/dream-application/DreamApplicationInitMissingMissingProjectRoot.js +16 -0
  453. package/dist/esm/src/errors/dream-application/GlobalNameNotSet.js +11 -0
  454. package/dist/esm/src/errors/dream-application/SerializerNameConflict.js +12 -0
  455. package/dist/esm/src/errors/encrypt/MissingColumnEncryptionOpts.js +24 -0
  456. package/dist/esm/src/errors/encrypt/MissingEncryptionKey.js +9 -0
  457. package/dist/esm/src/errors/environment/MissingRequiredEnvironmentVariable.js +10 -0
  458. package/dist/esm/src/errors/ops/AnyRequiresArrayColumn.js +15 -0
  459. package/dist/esm/src/errors/ops/ScoreMustBeANormalNumber.js +14 -0
  460. package/dist/esm/src/errors/schema-builder/FailedToIdentifyAssociation.js +77 -0
  461. package/dist/esm/src/errors/serializers/FailedToRenderThroughAssociationForSerializer.js +14 -0
  462. package/dist/esm/src/errors/sortable/CannotCallSortableOnSTIChild.js +15 -0
  463. package/dist/esm/src/errors/sti/STIChildMissing.js +20 -0
  464. package/dist/esm/src/errors/sti/StiChildCannotDefineNewAssociations.js +17 -0
  465. package/dist/esm/src/errors/sti/StiChildIncompatibleWithReplicaSafeDecorator.js +14 -0
  466. package/dist/esm/src/errors/sti/StiChildIncompatibleWithSoftDeleteDecorator.js +14 -0
  467. package/dist/esm/src/global-cli/dream.js +44 -0
  468. package/dist/esm/src/global-cli/file-builders/DreamtsBuilder.js +66 -0
  469. package/dist/esm/src/global-cli/file-builders/EnvBuilder.js +24 -0
  470. package/dist/esm/src/global-cli/file-builders/EslintConfBuilder.js +26 -0
  471. package/dist/esm/src/global-cli/file-builders/PackagejsonBuilder.js +6 -0
  472. package/dist/esm/src/global-cli/helpers/argAndValue.js +12 -0
  473. package/dist/esm/src/global-cli/helpers/autogeneratedFileMessage.js +68 -0
  474. package/dist/esm/src/global-cli/helpers/buildNewDreamApp.js +60 -0
  475. package/dist/esm/src/global-cli/helpers/copyRecursive.js +17 -0
  476. package/dist/esm/src/global-cli/helpers/filterObjectByKey.js +20 -0
  477. package/dist/esm/src/global-cli/helpers/generateEncryptionKey.js +23 -0
  478. package/dist/esm/src/global-cli/helpers/globalCliSnakeify.js +1 -0
  479. package/dist/esm/src/global-cli/helpers/initDreamAppIntoExistingProject.js +82 -0
  480. package/dist/esm/src/global-cli/helpers/log.js +24 -0
  481. package/dist/esm/src/global-cli/helpers/logo.js +77 -0
  482. package/dist/esm/src/global-cli/helpers/primaryKeyTypes.js +10 -0
  483. package/dist/esm/src/global-cli/helpers/prompt.js +30 -0
  484. package/dist/esm/src/global-cli/helpers/select.js +110 -0
  485. package/dist/esm/src/global-cli/helpers/sleep.js +7 -0
  486. package/dist/esm/src/global-cli/helpers/sspawn.js +17 -0
  487. package/dist/esm/src/global-cli/helpers/welcomeMessage.js +38 -0
  488. package/dist/esm/src/global-cli/init.js +53 -0
  489. package/dist/esm/src/global-cli/new.js +7 -0
  490. package/dist/esm/src/helpers/CalendarDate.js +169 -0
  491. package/dist/esm/src/helpers/Env.js +75 -0
  492. package/dist/esm/src/helpers/EnvInternal.js +3 -0
  493. package/dist/esm/src/helpers/allNestedObjectKeys.js +9 -0
  494. package/dist/esm/src/helpers/benchmark.js +15 -0
  495. package/dist/esm/src/helpers/camelize.js +11 -0
  496. package/dist/esm/src/helpers/capitalize.js +3 -0
  497. package/dist/esm/src/helpers/cli/SchemaBuilder.js +375 -0
  498. package/dist/esm/src/helpers/cli/generateDream.js +45 -0
  499. package/dist/esm/src/helpers/cli/generateDreamContent.js +104 -0
  500. package/dist/esm/src/helpers/cli/generateFactory.js +23 -0
  501. package/dist/esm/src/helpers/cli/generateFactoryContent.js +55 -0
  502. package/dist/esm/src/helpers/cli/generateMigration.js +53 -0
  503. package/dist/esm/src/helpers/cli/generateMigrationContent.js +193 -0
  504. package/dist/esm/src/helpers/cli/generateSerializer.js +23 -0
  505. package/dist/esm/src/helpers/cli/generateSerializerContent.js +127 -0
  506. package/dist/esm/src/helpers/cli/generateStiMigrationContent.js +4 -0
  507. package/dist/esm/src/helpers/cli/generateUnitSpec.js +23 -0
  508. package/dist/esm/src/helpers/cli/generateUnitSpecContent.js +7 -0
  509. package/dist/esm/src/helpers/cloneDeepSafe.js +64 -0
  510. package/dist/esm/src/helpers/compact.js +11 -0
  511. package/dist/esm/src/helpers/customPgParsers.js +31 -0
  512. package/dist/esm/src/helpers/db/cachedTypeForAttribute.js +3 -0
  513. package/dist/esm/src/helpers/db/createDb.js +17 -0
  514. package/dist/esm/src/helpers/db/dropDb.js +33 -0
  515. package/dist/esm/src/helpers/db/foreignKeyTypeFromPrimaryKey.js +8 -0
  516. package/dist/esm/src/helpers/db/loadPgClient.js +17 -0
  517. package/dist/esm/src/helpers/db/primaryKeyType.js +20 -0
  518. package/dist/esm/src/helpers/db/runMigration.js +94 -0
  519. package/dist/esm/src/helpers/db/truncateDb.js +24 -0
  520. package/dist/esm/src/helpers/db/types/isDatabaseArrayColumn.js +3 -0
  521. package/dist/esm/src/helpers/db/types/isDateColumn.js +3 -0
  522. package/dist/esm/src/helpers/db/types/isDateTimeColumn.js +3 -0
  523. package/dist/esm/src/helpers/db/types/isJsonColumn.js +3 -0
  524. package/dist/esm/src/helpers/debug.js +8 -0
  525. package/dist/esm/src/helpers/dreamOrPsychicCoreDevelopment.js +7 -0
  526. package/dist/esm/src/helpers/filterObjectByKey.js +11 -0
  527. package/dist/esm/src/helpers/getFiles.js +17 -0
  528. package/dist/esm/src/helpers/globalClassNameFromFullyQualifiedModelName.js +4 -0
  529. package/dist/esm/src/helpers/hyphenize.js +8 -0
  530. package/dist/esm/src/helpers/inferSerializerFromDreamOrViewModel.js +12 -0
  531. package/dist/esm/src/helpers/isEmpty.js +5 -0
  532. package/dist/esm/src/helpers/loadEnv.js +35 -0
  533. package/dist/esm/src/helpers/loadRepl.js +22 -0
  534. package/dist/esm/src/helpers/migrationVersion.js +3 -0
  535. package/dist/esm/src/helpers/namespaceColumn.js +5 -0
  536. package/dist/esm/src/helpers/objectPathsToArrays.js +16 -0
  537. package/dist/esm/src/helpers/pascalize.js +9 -0
  538. package/dist/esm/src/helpers/pascalizePath.js +7 -0
  539. package/dist/esm/src/helpers/path/dreamFileAndDirPaths.js +13 -0
  540. package/dist/esm/src/helpers/path/dreamPath.js +22 -0
  541. package/dist/esm/src/helpers/path/relativeDreamPath.js +46 -0
  542. package/dist/esm/src/helpers/path/sharedPathPrefix.js +11 -0
  543. package/dist/esm/src/helpers/propertyNameFromFullyQualifiedModelName.js +5 -0
  544. package/dist/esm/src/helpers/protectAgainstPollutingAssignment.js +11 -0
  545. package/dist/esm/src/helpers/range.js +15 -0
  546. package/dist/esm/src/helpers/round.js +4 -0
  547. package/dist/esm/src/helpers/serializerNameFromFullyQualifiedModelName.js +10 -0
  548. package/dist/esm/src/helpers/snakeify.js +10 -0
  549. package/dist/esm/src/helpers/sortBy.js +26 -0
  550. package/dist/esm/src/helpers/sqlAttributes.js +25 -0
  551. package/dist/esm/src/helpers/sspawn.js +17 -0
  552. package/dist/esm/src/helpers/standardizeFullyQualifiedModelName.js +7 -0
  553. package/dist/esm/src/helpers/stringCasing.js +31 -0
  554. package/dist/esm/src/helpers/typechecks.js +12 -0
  555. package/dist/esm/src/helpers/typeutils.js +1 -0
  556. package/dist/esm/src/helpers/uncapitalize.js +3 -0
  557. package/dist/esm/src/helpers/uniq.js +18 -0
  558. package/dist/esm/src/index.js +73 -0
  559. package/dist/esm/src/openapi/types.js +23 -0
  560. package/dist/esm/src/ops/curried-ops-statement.js +9 -0
  561. package/dist/esm/src/ops/index.js +40 -0
  562. package/dist/esm/src/ops/ops-statement.js +35 -0
  563. package/dist/esm/src/serializer/decorators/associations/RendersMany.js +81 -0
  564. package/dist/esm/src/serializer/decorators/associations/RendersOne.js +84 -0
  565. package/dist/esm/src/serializer/decorators/associations/shared.js +7 -0
  566. package/dist/esm/src/serializer/decorators/attribute.js +158 -0
  567. package/dist/esm/src/serializer/decorators/helpers/dreamAttributeOpenapiShape.js +73 -0
  568. package/dist/esm/src/serializer/decorators/helpers/hasSerializersGetter.js +8 -0
  569. package/dist/esm/src/serializer/decorators/helpers/maybeSerializableToDreamSerializerCallbackFunction.js +17 -0
  570. package/dist/esm/src/serializer/index.js +268 -0
  571. package/dist/types/src/Dream.d.ts +2211 -0
  572. package/dist/types/src/bin/helpers/sync.d.ts +2 -0
  573. package/dist/types/src/bin/index.d.ts +20 -0
  574. package/dist/types/src/cli/index.d.ts +20 -0
  575. package/dist/types/src/db/ConnectedToDB.d.ts +26 -0
  576. package/dist/types/src/db/ConnectionConfRetriever.d.ts +6 -0
  577. package/dist/types/src/db/DreamDbConnection.d.ts +10 -0
  578. package/dist/types/src/db/dataTypes.d.ts +6 -0
  579. package/dist/types/src/db/errors.d.ts +6 -0
  580. package/dist/types/src/db/index.d.ts +5 -0
  581. package/dist/types/src/db/migration-helpers/DreamMigrationHelpers.d.ts +116 -0
  582. package/dist/types/src/db/reflections.d.ts +5 -0
  583. package/dist/types/src/db/types.d.ts +1 -0
  584. package/dist/types/src/db/validators/validateColumn.d.ts +1 -0
  585. package/dist/types/src/db/validators/validateTable.d.ts +1 -0
  586. package/dist/types/src/db/validators/validateTableAlias.d.ts +1 -0
  587. package/dist/types/src/decorators/DecoratorContextType.d.ts +13 -0
  588. package/dist/types/src/decorators/Decorators.d.ts +214 -0
  589. package/dist/types/src/decorators/Encrypted.d.ts +5 -0
  590. package/dist/types/src/decorators/ReplicaSafe.d.ts +1 -0
  591. package/dist/types/src/decorators/STI.d.ts +5 -0
  592. package/dist/types/src/decorators/Scope.d.ts +11 -0
  593. package/dist/types/src/decorators/SoftDelete.d.ts +37 -0
  594. package/dist/types/src/decorators/Virtual.d.ts +6 -0
  595. package/dist/types/src/decorators/associations/BelongsTo.d.ts +33 -0
  596. package/dist/types/src/decorators/associations/HasMany.d.ts +19 -0
  597. package/dist/types/src/decorators/associations/HasOne.d.ts +11 -0
  598. package/dist/types/src/decorators/associations/associationToGetterSetterProp.d.ts +5 -0
  599. package/dist/types/src/decorators/associations/shared.d.ts +118 -0
  600. package/dist/types/src/decorators/helpers/freezeBaseClassArrayMap.d.ts +1 -0
  601. package/dist/types/src/decorators/hooks/AfterCreate.d.ts +4 -0
  602. package/dist/types/src/decorators/hooks/AfterCreateCommit.d.ts +21 -0
  603. package/dist/types/src/decorators/hooks/AfterDestroy.d.ts +3 -0
  604. package/dist/types/src/decorators/hooks/AfterDestroyCommit.d.ts +18 -0
  605. package/dist/types/src/decorators/hooks/AfterSave.d.ts +4 -0
  606. package/dist/types/src/decorators/hooks/AfterSaveCommit.d.ts +21 -0
  607. package/dist/types/src/decorators/hooks/AfterUpdate.d.ts +4 -0
  608. package/dist/types/src/decorators/hooks/AfterUpdateCommit.d.ts +21 -0
  609. package/dist/types/src/decorators/hooks/BeforeCreate.d.ts +4 -0
  610. package/dist/types/src/decorators/hooks/BeforeDestroy.d.ts +3 -0
  611. package/dist/types/src/decorators/hooks/BeforeSave.d.ts +4 -0
  612. package/dist/types/src/decorators/hooks/BeforeUpdate.d.ts +4 -0
  613. package/dist/types/src/decorators/hooks/shared.d.ts +34 -0
  614. package/dist/types/src/decorators/sortable/Sortable.d.ts +9 -0
  615. package/dist/types/src/decorators/sortable/helpers/applySortableScopeToQuery.d.ts +9 -0
  616. package/dist/types/src/decorators/sortable/helpers/clearCachedSortableValues.d.ts +2 -0
  617. package/dist/types/src/decorators/sortable/helpers/decrementScopedRecordsGreaterThanPosition.d.ts +8 -0
  618. package/dist/types/src/decorators/sortable/helpers/getColumnForSortableScope.d.ts +2 -0
  619. package/dist/types/src/decorators/sortable/helpers/isSortedCorrectly.d.ts +1 -0
  620. package/dist/types/src/decorators/sortable/helpers/positionIsInvalid.d.ts +8 -0
  621. package/dist/types/src/decorators/sortable/helpers/resortAllRecords.d.ts +2 -0
  622. package/dist/types/src/decorators/sortable/helpers/scopeArray.d.ts +1 -0
  623. package/dist/types/src/decorators/sortable/helpers/setPosition.d.ts +14 -0
  624. package/dist/types/src/decorators/sortable/helpers/sortableCacheKeyName.d.ts +1 -0
  625. package/dist/types/src/decorators/sortable/helpers/sortableCacheValuesName.d.ts +1 -0
  626. package/dist/types/src/decorators/sortable/helpers/sortableQueryExcludingDream.d.ts +9 -0
  627. package/dist/types/src/decorators/sortable/hooks/afterSortableCreate.d.ts +10 -0
  628. package/dist/types/src/decorators/sortable/hooks/afterSortableDestroy.d.ts +8 -0
  629. package/dist/types/src/decorators/sortable/hooks/afterSortableUpdate.d.ts +10 -0
  630. package/dist/types/src/decorators/sortable/hooks/beforeSortableSave.d.ts +8 -0
  631. package/dist/types/src/decorators/validations/Validate.d.ts +1 -0
  632. package/dist/types/src/decorators/validations/Validates.d.ts +18 -0
  633. package/dist/types/src/decorators/validations/shared.d.ts +19 -0
  634. package/dist/types/src/dream/DreamClassTransactionBuilder.d.ts +549 -0
  635. package/dist/types/src/dream/DreamInstanceTransactionBuilder.d.ts +316 -0
  636. package/dist/types/src/dream/DreamTransaction.d.ts +15 -0
  637. package/dist/types/src/dream/LeftJoinLoadBuilder.d.ts +48 -0
  638. package/dist/types/src/dream/LoadBuilder.d.ts +47 -0
  639. package/dist/types/src/dream/Query.d.ts +1132 -0
  640. package/dist/types/src/dream/internal/applyScopeBypassingSettingsToQuery.d.ts +13 -0
  641. package/dist/types/src/dream/internal/associations/associationQuery.d.ts +9 -0
  642. package/dist/types/src/dream/internal/associations/associationUpdateQuery.d.ts +9 -0
  643. package/dist/types/src/dream/internal/associations/createAssociation.d.ts +4 -0
  644. package/dist/types/src/dream/internal/associations/destroyAssociation.d.ts +11 -0
  645. package/dist/types/src/dream/internal/associations/undestroyAssociation.d.ts +10 -0
  646. package/dist/types/src/dream/internal/checkSingleValidation.d.ts +3 -0
  647. package/dist/types/src/dream/internal/destroyAssociatedRecords.d.ts +10 -0
  648. package/dist/types/src/dream/internal/destroyDream.d.ts +19 -0
  649. package/dist/types/src/dream/internal/destroyOptions.d.ts +46 -0
  650. package/dist/types/src/dream/internal/ensureSTITypeFieldIsSet.d.ts +2 -0
  651. package/dist/types/src/dream/internal/executeDatabaseQuery.d.ts +1 -0
  652. package/dist/types/src/dream/internal/extractAssociationMetadataFromAssociationName.d.ts +4 -0
  653. package/dist/types/src/dream/internal/orderByDirection.d.ts +2 -0
  654. package/dist/types/src/dream/internal/reload.d.ts +3 -0
  655. package/dist/types/src/dream/internal/runHooksFor.d.ts +8 -0
  656. package/dist/types/src/dream/internal/runValidations.d.ts +2 -0
  657. package/dist/types/src/dream/internal/safelyRunCommitHooks.d.ts +7 -0
  658. package/dist/types/src/dream/internal/saveDream.d.ts +5 -0
  659. package/dist/types/src/dream/internal/scopeHelpers.d.ts +7 -0
  660. package/dist/types/src/dream/internal/shouldBypassDefaultScope.d.ts +4 -0
  661. package/dist/types/src/dream/internal/similarity/SimilarityBuilder.d.ts +38 -0
  662. package/dist/types/src/dream/internal/similarity/similaritySelectSql.d.ts +11 -0
  663. package/dist/types/src/dream/internal/similarity/similarityWhereSql.d.ts +10 -0
  664. package/dist/types/src/dream/internal/softDeleteDream.d.ts +3 -0
  665. package/dist/types/src/dream/internal/sqlResultToDreamInstance.d.ts +4 -0
  666. package/dist/types/src/dream/internal/undestroyDream.d.ts +16 -0
  667. package/dist/types/src/dream/types.d.ts +184 -0
  668. package/dist/types/src/dream-application/cache.d.ts +3 -0
  669. package/dist/types/src/dream-application/helpers/DreamImporter.d.ts +8 -0
  670. package/dist/types/src/dream-application/helpers/globalModelKeyFromPath.d.ts +1 -0
  671. package/dist/types/src/dream-application/helpers/globalSerializerKeyFromPath.d.ts +1 -0
  672. package/dist/types/src/dream-application/helpers/globalServiceKeyFromPath.d.ts +1 -0
  673. package/dist/types/src/dream-application/helpers/importers/importModels.d.ts +5 -0
  674. package/dist/types/src/dream-application/helpers/importers/importSerializers.d.ts +5 -0
  675. package/dist/types/src/dream-application/helpers/importers/importServices.d.ts +4 -0
  676. package/dist/types/src/dream-application/helpers/lookupClassByGlobalName.d.ts +1 -0
  677. package/dist/types/src/dream-application/helpers/lookupModelByGlobalName.d.ts +1 -0
  678. package/dist/types/src/dream-application/helpers/lookupModelByGlobalNameOrNames.d.ts +1 -0
  679. package/dist/types/src/dream-application/index.d.ts +143 -0
  680. package/dist/types/src/encrypt/InternalEncrypt.d.ts +6 -0
  681. package/dist/types/src/encrypt/algorithms/aes-gcm/decryptAESGCM.d.ts +2 -0
  682. package/dist/types/src/encrypt/algorithms/aes-gcm/encryptAESGCM.d.ts +2 -0
  683. package/dist/types/src/encrypt/algorithms/aes-gcm/generateKeyAESGCM.d.ts +2 -0
  684. package/dist/types/src/encrypt/algorithms/aes-gcm/validateKeyAESGCM.d.ts +2 -0
  685. package/dist/types/src/encrypt/index.d.ts +26 -0
  686. package/dist/types/src/errors/AttemptingToMarshalInvalidArrayType.d.ts +5 -0
  687. package/dist/types/src/errors/CannotCallUndestroyOnANonSoftDeleteModel.d.ts +6 -0
  688. package/dist/types/src/errors/CannotDefineAssociationWithBothDependentAndPassthrough.d.ts +7 -0
  689. package/dist/types/src/errors/CannotDefineAssociationWithBothDependentAndRequiredOnClause.d.ts +7 -0
  690. package/dist/types/src/errors/CannotNegateSimilarityClause.d.ts +7 -0
  691. package/dist/types/src/errors/CannotPassAdditionalFieldsToPluckEachAfterCallback.d.ts +6 -0
  692. package/dist/types/src/errors/CannotPassUndefinedAsAValueToAWhereClause.d.ts +7 -0
  693. package/dist/types/src/errors/CannotReloadUnsavedDream.d.ts +6 -0
  694. package/dist/types/src/errors/ConstructorOnlyForInternalUse.d.ts +3 -0
  695. package/dist/types/src/errors/CreateOrFindByFailedToCreateAndFind.d.ts +6 -0
  696. package/dist/types/src/errors/DoNotSetEncryptedFieldsDirectly.d.ts +8 -0
  697. package/dist/types/src/errors/InvalidColumnName.d.ts +6 -0
  698. package/dist/types/src/errors/InvalidDecimalFieldPassedToGenerator.d.ts +5 -0
  699. package/dist/types/src/errors/InvalidTableAlias.d.ts +5 -0
  700. package/dist/types/src/errors/InvalidTableName.d.ts +6 -0
  701. package/dist/types/src/errors/LeftJoinPreloadIncompatibleWithFindEach.d.ts +3 -0
  702. package/dist/types/src/errors/MissingDB.d.ts +3 -0
  703. package/dist/types/src/errors/MissingDeletedAtFieldForSoftDelete.d.ts +6 -0
  704. package/dist/types/src/errors/MissingRequiredCallbackFunctionToPluckEach.d.ts +6 -0
  705. package/dist/types/src/errors/MissingSerializersDefinition.d.ts +6 -0
  706. package/dist/types/src/errors/MissingTable.d.ts +6 -0
  707. package/dist/types/src/errors/NoUpdateAllOnJoins.d.ts +3 -0
  708. package/dist/types/src/errors/NoUpdateOnAssociationQuery.d.ts +3 -0
  709. package/dist/types/src/errors/NonBelongsToAssociationProvidedAsSortableDecoratorScope.d.ts +7 -0
  710. package/dist/types/src/errors/NonExistentScopeProvidedToResort.d.ts +7 -0
  711. package/dist/types/src/errors/PrototypePollutingAssignment.d.ts +5 -0
  712. package/dist/types/src/errors/RecordNotFound.d.ts +5 -0
  713. package/dist/types/src/errors/SortableDecoratorRequiresColumnOrBelongsToAssociation.d.ts +7 -0
  714. package/dist/types/src/errors/ValidationError.d.ts +11 -0
  715. package/dist/types/src/errors/associations/CanOnlyPassBelongsToModelParam.d.ts +9 -0
  716. package/dist/types/src/errors/associations/CannotAssociateThroughPolymorphic.d.ts +12 -0
  717. package/dist/types/src/errors/associations/CannotCreateAssociationWithThroughContext.d.ts +12 -0
  718. package/dist/types/src/errors/associations/CannotJoinPolymorphicBelongsToError.d.ts +15 -0
  719. package/dist/types/src/errors/associations/CannotPassNullOrUndefinedToRequiredBelongsTo.d.ts +8 -0
  720. package/dist/types/src/errors/associations/InvalidComputedForeignKey.d.ts +19 -0
  721. package/dist/types/src/errors/associations/JoinAttemptedOnMissingAssociation.d.ts +10 -0
  722. package/dist/types/src/errors/associations/MissingRequiredAssociationOnClause.d.ts +8 -0
  723. package/dist/types/src/errors/associations/MissingRequiredPassthroughForAssociationOnClause.d.ts +5 -0
  724. package/dist/types/src/errors/associations/MissingThroughAssociation.d.ts +12 -0
  725. package/dist/types/src/errors/associations/MissingThroughAssociationSource.d.ts +14 -0
  726. package/dist/types/src/errors/associations/NonLoadedAssociation.d.ts +10 -0
  727. package/dist/types/src/errors/dream-application/DreamApplicationInitMissingCallToLoadModels.d.ts +3 -0
  728. package/dist/types/src/errors/dream-application/DreamApplicationInitMissingMissingProjectRoot.d.ts +3 -0
  729. package/dist/types/src/errors/dream-application/GlobalNameNotSet.d.ts +5 -0
  730. package/dist/types/src/errors/dream-application/SerializerNameConflict.d.ts +5 -0
  731. package/dist/types/src/errors/encrypt/MissingColumnEncryptionOpts.d.ts +3 -0
  732. package/dist/types/src/errors/encrypt/MissingEncryptionKey.d.ts +3 -0
  733. package/dist/types/src/errors/environment/MissingRequiredEnvironmentVariable.d.ts +5 -0
  734. package/dist/types/src/errors/ops/AnyRequiresArrayColumn.d.ts +7 -0
  735. package/dist/types/src/errors/ops/ScoreMustBeANormalNumber.d.ts +5 -0
  736. package/dist/types/src/errors/schema-builder/FailedToIdentifyAssociation.d.ts +9 -0
  737. package/dist/types/src/errors/serializers/FailedToRenderThroughAssociationForSerializer.d.ts +6 -0
  738. package/dist/types/src/errors/sortable/CannotCallSortableOnSTIChild.d.ts +6 -0
  739. package/dist/types/src/errors/sti/STIChildMissing.d.ts +8 -0
  740. package/dist/types/src/errors/sti/StiChildCannotDefineNewAssociations.d.ts +7 -0
  741. package/dist/types/src/errors/sti/StiChildIncompatibleWithReplicaSafeDecorator.d.ts +6 -0
  742. package/dist/types/src/errors/sti/StiChildIncompatibleWithSoftDeleteDecorator.d.ts +6 -0
  743. package/dist/types/src/global-cli/dream.d.ts +2 -0
  744. package/dist/types/src/global-cli/file-builders/DreamtsBuilder.d.ts +4 -0
  745. package/dist/types/src/global-cli/file-builders/EnvBuilder.d.ts +6 -0
  746. package/dist/types/src/global-cli/file-builders/EslintConfBuilder.d.ts +3 -0
  747. package/dist/types/src/global-cli/file-builders/PackagejsonBuilder.d.ts +3 -0
  748. package/dist/types/src/global-cli/helpers/argAndValue.d.ts +1 -0
  749. package/dist/types/src/global-cli/helpers/autogeneratedFileMessage.d.ts +1 -0
  750. package/dist/types/src/global-cli/helpers/buildNewDreamApp.d.ts +2 -0
  751. package/dist/types/src/global-cli/helpers/copyRecursive.d.ts +1 -0
  752. package/dist/types/src/global-cli/helpers/filterObjectByKey.d.ts +1 -0
  753. package/dist/types/src/global-cli/helpers/generateEncryptionKey.d.ts +1 -0
  754. package/dist/types/src/global-cli/helpers/globalCliSnakeify.d.ts +0 -0
  755. package/dist/types/src/global-cli/helpers/initDreamAppIntoExistingProject.d.ts +2 -0
  756. package/dist/types/src/global-cli/helpers/log.d.ts +10 -0
  757. package/dist/types/src/global-cli/helpers/logo.d.ts +2 -0
  758. package/dist/types/src/global-cli/helpers/primaryKeyTypes.d.ts +22 -0
  759. package/dist/types/src/global-cli/helpers/prompt.d.ts +8 -0
  760. package/dist/types/src/global-cli/helpers/select.d.ts +17 -0
  761. package/dist/types/src/global-cli/helpers/sleep.d.ts +1 -0
  762. package/dist/types/src/global-cli/helpers/sspawn.d.ts +2 -0
  763. package/dist/types/src/global-cli/helpers/welcomeMessage.d.ts +1 -0
  764. package/dist/types/src/global-cli/init.d.ts +2 -0
  765. package/dist/types/src/global-cli/new.d.ts +2 -0
  766. package/dist/types/src/helpers/CalendarDate.d.ts +51 -0
  767. package/dist/types/src/helpers/Env.d.ts +37 -0
  768. package/dist/types/src/helpers/EnvInternal.d.ts +6 -0
  769. package/dist/types/src/helpers/allNestedObjectKeys.d.ts +1 -0
  770. package/dist/types/src/helpers/benchmark.d.ts +6 -0
  771. package/dist/types/src/helpers/camelize.d.ts +3 -0
  772. package/dist/types/src/helpers/capitalize.d.ts +1 -0
  773. package/dist/types/src/helpers/cli/SchemaBuilder.d.ts +17 -0
  774. package/dist/types/src/helpers/cli/generateDream.d.ts +8 -0
  775. package/dist/types/src/helpers/cli/generateDreamContent.d.ts +6 -0
  776. package/dist/types/src/helpers/cli/generateFactory.d.ts +4 -0
  777. package/dist/types/src/helpers/cli/generateFactoryContent.d.ts +4 -0
  778. package/dist/types/src/helpers/cli/generateMigration.d.ts +6 -0
  779. package/dist/types/src/helpers/cli/generateMigrationContent.d.ts +7 -0
  780. package/dist/types/src/helpers/cli/generateSerializer.d.ts +5 -0
  781. package/dist/types/src/helpers/cli/generateSerializerContent.d.ts +5 -0
  782. package/dist/types/src/helpers/cli/generateStiMigrationContent.d.ts +6 -0
  783. package/dist/types/src/helpers/cli/generateUnitSpec.d.ts +3 -0
  784. package/dist/types/src/helpers/cli/generateUnitSpecContent.d.ts +3 -0
  785. package/dist/types/src/helpers/cloneDeepSafe.d.ts +18 -0
  786. package/dist/types/src/helpers/compact.d.ts +19 -0
  787. package/dist/types/src/helpers/customPgParsers.d.ts +9 -0
  788. package/dist/types/src/helpers/db/cachedTypeForAttribute.d.ts +2 -0
  789. package/dist/types/src/helpers/db/createDb.d.ts +2 -0
  790. package/dist/types/src/helpers/db/dropDb.d.ts +2 -0
  791. package/dist/types/src/helpers/db/foreignKeyTypeFromPrimaryKey.d.ts +2 -0
  792. package/dist/types/src/helpers/db/loadPgClient.d.ts +3 -0
  793. package/dist/types/src/helpers/db/primaryKeyType.d.ts +1 -0
  794. package/dist/types/src/helpers/db/runMigration.d.ts +6 -0
  795. package/dist/types/src/helpers/db/truncateDb.d.ts +1 -0
  796. package/dist/types/src/helpers/db/types/isDatabaseArrayColumn.d.ts +2 -0
  797. package/dist/types/src/helpers/db/types/isDateColumn.d.ts +2 -0
  798. package/dist/types/src/helpers/db/types/isDateTimeColumn.d.ts +2 -0
  799. package/dist/types/src/helpers/db/types/isJsonColumn.d.ts +2 -0
  800. package/dist/types/src/helpers/debug.d.ts +4 -0
  801. package/dist/types/src/helpers/dreamOrPsychicCoreDevelopment.d.ts +1 -0
  802. package/dist/types/src/helpers/filterObjectByKey.d.ts +1 -0
  803. package/dist/types/src/helpers/getFiles.d.ts +1 -0
  804. package/dist/types/src/helpers/globalClassNameFromFullyQualifiedModelName.d.ts +1 -0
  805. package/dist/types/src/helpers/hyphenize.d.ts +2 -0
  806. package/dist/types/src/helpers/inferSerializerFromDreamOrViewModel.d.ts +4 -0
  807. package/dist/types/src/helpers/isEmpty.d.ts +1 -0
  808. package/dist/types/src/helpers/loadEnv.d.ts +1 -0
  809. package/dist/types/src/helpers/loadRepl.d.ts +2 -0
  810. package/dist/types/src/helpers/migrationVersion.d.ts +1 -0
  811. package/dist/types/src/helpers/namespaceColumn.d.ts +1 -0
  812. package/dist/types/src/helpers/objectPathsToArrays.d.ts +2 -0
  813. package/dist/types/src/helpers/pascalize.d.ts +2 -0
  814. package/dist/types/src/helpers/pascalizePath.d.ts +1 -0
  815. package/dist/types/src/helpers/path/dreamFileAndDirPaths.d.ts +5 -0
  816. package/dist/types/src/helpers/path/dreamPath.d.ts +3 -0
  817. package/dist/types/src/helpers/path/relativeDreamPath.d.ts +3 -0
  818. package/dist/types/src/helpers/path/sharedPathPrefix.d.ts +1 -0
  819. package/dist/types/src/helpers/propertyNameFromFullyQualifiedModelName.d.ts +1 -0
  820. package/dist/types/src/helpers/protectAgainstPollutingAssignment.d.ts +1 -0
  821. package/dist/types/src/helpers/range.d.ts +7 -0
  822. package/dist/types/src/helpers/round.d.ts +2 -0
  823. package/dist/types/src/helpers/serializerNameFromFullyQualifiedModelName.d.ts +1 -0
  824. package/dist/types/src/helpers/snakeify.d.ts +3 -0
  825. package/dist/types/src/helpers/sortBy.d.ts +8 -0
  826. package/dist/types/src/helpers/sqlAttributes.d.ts +4 -0
  827. package/dist/types/src/helpers/sspawn.d.ts +2 -0
  828. package/dist/types/src/helpers/standardizeFullyQualifiedModelName.d.ts +1 -0
  829. package/dist/types/src/helpers/stringCasing.d.ts +28 -0
  830. package/dist/types/src/helpers/typechecks.d.ts +2 -0
  831. package/dist/types/src/helpers/typeutils.d.ts +115 -0
  832. package/dist/types/src/helpers/uncapitalize.d.ts +1 -0
  833. package/dist/types/src/helpers/uniq.d.ts +1 -0
  834. package/dist/types/src/index.d.ts +78 -0
  835. package/dist/types/src/openapi/types.d.ts +139 -0
  836. package/dist/types/src/ops/curried-ops-statement.d.ts +7 -0
  837. package/dist/types/src/ops/index.d.ts +49 -0
  838. package/dist/types/src/ops/ops-statement.d.ts +14 -0
  839. package/dist/types/src/serializer/decorators/associations/RendersMany.d.ts +42 -0
  840. package/dist/types/src/serializer/decorators/associations/RendersOne.d.ts +46 -0
  841. package/dist/types/src/serializer/decorators/associations/shared.d.ts +23 -0
  842. package/dist/types/src/serializer/decorators/attribute.d.ts +29 -0
  843. package/dist/types/src/serializer/decorators/helpers/dreamAttributeOpenapiShape.d.ts +7 -0
  844. package/dist/types/src/serializer/decorators/helpers/hasSerializersGetter.d.ts +2 -0
  845. package/dist/types/src/serializer/decorators/helpers/maybeSerializableToDreamSerializerCallbackFunction.d.ts +2 -0
  846. package/dist/types/src/serializer/index.d.ts +56 -0
  847. package/docs/.nojekyll +1 -0
  848. package/docs/assets/highlight.css +92 -0
  849. package/docs/assets/icons.js +18 -0
  850. package/docs/assets/icons.svg +1 -0
  851. package/docs/assets/main.js +60 -0
  852. package/docs/assets/navigation.js +1 -0
  853. package/docs/assets/search.js +1 -0
  854. package/docs/assets/style.css +1448 -0
  855. package/docs/classes/Benchmark.html +4 -0
  856. package/docs/classes/CalendarDate.html +34 -0
  857. package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +12 -0
  858. package/docs/classes/Decorators.html +81 -0
  859. package/docs/classes/Dream.html +896 -0
  860. package/docs/classes/DreamApplication.html +37 -0
  861. package/docs/classes/DreamBin.html +11 -0
  862. package/docs/classes/DreamCLI.html +7 -0
  863. package/docs/classes/DreamImporter.html +6 -0
  864. package/docs/classes/DreamMigrationHelpers.html +32 -0
  865. package/docs/classes/DreamSerializer.html +19 -0
  866. package/docs/classes/DreamTransaction.html +5 -0
  867. package/docs/classes/Encrypt.html +8 -0
  868. package/docs/classes/Env.html +20 -0
  869. package/docs/classes/GlobalNameNotSet.html +12 -0
  870. package/docs/classes/NonLoadedAssociation.html +14 -0
  871. package/docs/classes/Query.html +383 -0
  872. package/docs/classes/Range.html +5 -0
  873. package/docs/classes/RecordNotFound.html +13 -0
  874. package/docs/classes/ValidationError.html +14 -0
  875. package/docs/functions/AfterCreate.html +1 -0
  876. package/docs/functions/AfterCreateCommit.html +13 -0
  877. package/docs/functions/AfterDestroy.html +1 -0
  878. package/docs/functions/AfterDestroyCommit.html +13 -0
  879. package/docs/functions/AfterSave.html +1 -0
  880. package/docs/functions/AfterSaveCommit.html +13 -0
  881. package/docs/functions/AfterUpdate.html +1 -0
  882. package/docs/functions/AfterUpdateCommit.html +13 -0
  883. package/docs/functions/Attribute.html +1 -0
  884. package/docs/functions/BeforeCreate.html +1 -0
  885. package/docs/functions/BeforeDestroy.html +1 -0
  886. package/docs/functions/BeforeSave.html +1 -0
  887. package/docs/functions/BeforeUpdate.html +1 -0
  888. package/docs/functions/RendersMany.html +16 -0
  889. package/docs/functions/RendersOne.html +16 -0
  890. package/docs/functions/ReplicaSafe.html +1 -0
  891. package/docs/functions/STI.html +1 -0
  892. package/docs/functions/Scope.html +1 -0
  893. package/docs/functions/SoftDelete.html +19 -0
  894. package/docs/functions/Sortable.html +1 -0
  895. package/docs/functions/Validate.html +1 -0
  896. package/docs/functions/Validates.html +1 -0
  897. package/docs/functions/Virtual.html +1 -0
  898. package/docs/functions/camelize.html +1 -0
  899. package/docs/functions/capitalize.html +1 -0
  900. package/docs/functions/closeAllDbConnections.html +1 -0
  901. package/docs/functions/compact.html +1 -0
  902. package/docs/functions/db.html +1 -0
  903. package/docs/functions/debug.html +1 -0
  904. package/docs/functions/dreamDbConnections.html +1 -0
  905. package/docs/functions/dreamPath.html +1 -0
  906. package/docs/functions/generateDream.html +1 -0
  907. package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -0
  908. package/docs/functions/hyphenize.html +1 -0
  909. package/docs/functions/inferSerializerFromDreamClassOrViewModelClass.html +1 -0
  910. package/docs/functions/inferSerializerFromDreamOrViewModel.html +1 -0
  911. package/docs/functions/isEmpty.html +1 -0
  912. package/docs/functions/loadRepl.html +1 -0
  913. package/docs/functions/lookupClassByGlobalName.html +1 -0
  914. package/docs/functions/pascalize.html +1 -0
  915. package/docs/functions/pgErrorType.html +1 -0
  916. package/docs/functions/range-1.html +1 -0
  917. package/docs/functions/relativeDreamPath.html +1 -0
  918. package/docs/functions/round.html +1 -0
  919. package/docs/functions/serializerNameFromFullyQualifiedModelName.html +1 -0
  920. package/docs/functions/sharedPathPrefix.html +1 -0
  921. package/docs/functions/snakeify.html +1 -0
  922. package/docs/functions/sortBy.html +1 -0
  923. package/docs/functions/standardizeFullyQualifiedModelName.html +1 -0
  924. package/docs/functions/uncapitalize.html +1 -0
  925. package/docs/functions/uniq.html +1 -0
  926. package/docs/functions/validateColumn.html +1 -0
  927. package/docs/functions/validateTable.html +1 -0
  928. package/docs/index.html +123 -0
  929. package/docs/interfaces/AttributeStatement.html +6 -0
  930. package/docs/interfaces/DecoratorContext.html +8 -0
  931. package/docs/interfaces/DreamApplicationInitOptions.html +2 -0
  932. package/docs/interfaces/DreamApplicationOpts.html +8 -0
  933. package/docs/interfaces/DreamSerializerAssociationStatement.html +11 -0
  934. package/docs/interfaces/EncryptOptions.html +3 -0
  935. package/docs/interfaces/OpenapiSchemaProperties.html +1 -0
  936. package/docs/interfaces/OpenapiSchemaPropertiesShorthand.html +1 -0
  937. package/docs/interfaces/OpenapiTypeFieldObject.html +1 -0
  938. package/docs/modules.html +163 -0
  939. package/docs/types/Camelized.html +1 -0
  940. package/docs/types/CommonOpenapiSchemaObjectFields.html +1 -0
  941. package/docs/types/DreamAssociationMetadata.html +1 -0
  942. package/docs/types/DreamAttributes.html +1 -0
  943. package/docs/types/DreamClassColumn.html +1 -0
  944. package/docs/types/DreamColumn.html +1 -0
  945. package/docs/types/DreamColumnNames.html +1 -0
  946. package/docs/types/DreamLogLevel.html +1 -0
  947. package/docs/types/DreamLogger.html +1 -0
  948. package/docs/types/DreamOrViewModelSerializerKey.html +1 -0
  949. package/docs/types/DreamParamSafeAttributes.html +1 -0
  950. package/docs/types/DreamParamSafeColumnNames.html +1 -0
  951. package/docs/types/DreamSerializerKey.html +1 -0
  952. package/docs/types/DreamSerializers.html +1 -0
  953. package/docs/types/DreamTableSchema.html +1 -0
  954. package/docs/types/DreamVirtualColumns.html +1 -0
  955. package/docs/types/EncryptAlgorithm.html +1 -0
  956. package/docs/types/Hyphenized.html +1 -0
  957. package/docs/types/IdType.html +1 -0
  958. package/docs/types/OpenapiAllTypes.html +1 -0
  959. package/docs/types/OpenapiFormats.html +1 -0
  960. package/docs/types/OpenapiNumberFormats.html +1 -0
  961. package/docs/types/OpenapiPrimitiveTypes.html +1 -0
  962. package/docs/types/OpenapiSchemaArray.html +1 -0
  963. package/docs/types/OpenapiSchemaArrayShorthand.html +1 -0
  964. package/docs/types/OpenapiSchemaBase.html +1 -0
  965. package/docs/types/OpenapiSchemaBody.html +1 -0
  966. package/docs/types/OpenapiSchemaBodyShorthand.html +1 -0
  967. package/docs/types/OpenapiSchemaCommonFields.html +1 -0
  968. package/docs/types/OpenapiSchemaExpressionAllOf.html +1 -0
  969. package/docs/types/OpenapiSchemaExpressionAnyOf.html +1 -0
  970. package/docs/types/OpenapiSchemaExpressionOneOf.html +1 -0
  971. package/docs/types/OpenapiSchemaExpressionRef.html +1 -0
  972. package/docs/types/OpenapiSchemaExpressionRefSchemaShorthand.html +1 -0
  973. package/docs/types/OpenapiSchemaInteger.html +1 -0
  974. package/docs/types/OpenapiSchemaNull.html +1 -0
  975. package/docs/types/OpenapiSchemaNumber.html +1 -0
  976. package/docs/types/OpenapiSchemaObject.html +1 -0
  977. package/docs/types/OpenapiSchemaObjectAllOf.html +1 -0
  978. package/docs/types/OpenapiSchemaObjectAllOfShorthand.html +1 -0
  979. package/docs/types/OpenapiSchemaObjectAnyOf.html +1 -0
  980. package/docs/types/OpenapiSchemaObjectAnyOfShorthand.html +1 -0
  981. package/docs/types/OpenapiSchemaObjectBase.html +1 -0
  982. package/docs/types/OpenapiSchemaObjectBaseShorthand.html +1 -0
  983. package/docs/types/OpenapiSchemaObjectOneOf.html +1 -0
  984. package/docs/types/OpenapiSchemaObjectOneOfShorthand.html +1 -0
  985. package/docs/types/OpenapiSchemaObjectShorthand.html +1 -0
  986. package/docs/types/OpenapiSchemaPartialSegment.html +1 -0
  987. package/docs/types/OpenapiSchemaPrimitiveGeneric.html +1 -0
  988. package/docs/types/OpenapiSchemaShorthandExpressionAllOf.html +1 -0
  989. package/docs/types/OpenapiSchemaShorthandExpressionAnyOf.html +1 -0
  990. package/docs/types/OpenapiSchemaShorthandExpressionOneOf.html +1 -0
  991. package/docs/types/OpenapiSchemaShorthandExpressionSerializableRef.html +1 -0
  992. package/docs/types/OpenapiSchemaShorthandExpressionSerializerRef.html +1 -0
  993. package/docs/types/OpenapiSchemaShorthandPrimitiveGeneric.html +1 -0
  994. package/docs/types/OpenapiSchemaString.html +1 -0
  995. package/docs/types/OpenapiShorthandAllTypes.html +1 -0
  996. package/docs/types/OpenapiShorthandPrimitiveTypes.html +1 -0
  997. package/docs/types/OpenapiTypeField.html +1 -0
  998. package/docs/types/Pascalized.html +1 -0
  999. package/docs/types/PrimaryKeyType.html +1 -0
  1000. package/docs/types/RoundingPrecision.html +1 -0
  1001. package/docs/types/SerializableClassOrSerializerCallback.html +1 -0
  1002. package/docs/types/SerializableDreamClassOrViewModelClass.html +1 -0
  1003. package/docs/types/SerializableDreamOrViewModel.html +1 -0
  1004. package/docs/types/SerializableTypes.html +1 -0
  1005. package/docs/types/Snakeified.html +1 -0
  1006. package/docs/types/Timestamp.html +1 -0
  1007. package/docs/types/UpdateableAssociationProperties.html +1 -0
  1008. package/docs/types/UpdateableProperties.html +1 -0
  1009. package/docs/types/ValidationType.html +1 -0
  1010. package/docs/types/ViewModelSerializerKey.html +1 -0
  1011. package/docs/types/WhereStatementForDream.html +1 -0
  1012. package/docs/types/WhereStatementForDreamClass.html +1 -0
  1013. package/docs/variables/DreamConst.html +1 -0
  1014. package/docs/variables/TRIGRAM_OPERATORS.html +1 -0
  1015. package/docs/variables/openapiPrimitiveTypes-1.html +1 -0
  1016. package/docs/variables/openapiShorthandPrimitiveTypes-1.html +1 -0
  1017. package/docs/variables/ops.html +1 -0
  1018. package/docs/variables/primaryKeyTypes.html +1 -0
  1019. package/package.json +83 -0
@@ -0,0 +1,2211 @@
1
+ import { CompiledQuery, DeleteQueryBuilder, InsertQueryBuilder, SelectQueryBuilder, Updateable, UpdateQueryBuilder } from 'kysely';
2
+ import { AssociationTableNames } from './db/reflections.js';
3
+ import { DbConnectionType } from './db/types.js';
4
+ import { AssociationStatementsMap, PassthroughOnClause, WhereStatement } from './decorators/associations/shared.js';
5
+ import { HookStatement, HookStatementMap } from './decorators/hooks/shared.js';
6
+ import { ScopeStatement } from './decorators/Scope.js';
7
+ import { SortableFieldConfig } from './decorators/sortable/Sortable.js';
8
+ import ValidationStatement, { ValidationType } from './decorators/validations/shared.js';
9
+ import { VirtualAttributeStatement } from './decorators/Virtual.js';
10
+ import DreamClassTransactionBuilder from './dream/DreamClassTransactionBuilder.js';
11
+ import DreamInstanceTransactionBuilder from './dream/DreamInstanceTransactionBuilder.js';
12
+ import DreamTransaction from './dream/DreamTransaction.js';
13
+ import { DestroyOptions } from './dream/internal/destroyOptions.js';
14
+ import LeftJoinLoadBuilder from './dream/LeftJoinLoadBuilder.js';
15
+ import LoadBuilder from './dream/LoadBuilder.js';
16
+ import Query, { BaseModelColumnTypes, DefaultQueryTypeOptions, FindEachOpts, QueryWithJoinedAssociationsType, QueryWithJoinedAssociationsTypeAndNoPreload } from './dream/Query.js';
17
+ import { AllDefaultScopeNames, AssociationNameToDream, AttributeKeys, DefaultOrNamedScopeName, DreamAssociationNames, DreamAssociationNamesWithoutRequiredOnClauses, DreamAttributes, DreamColumnNames, DreamParamSafeColumnNames, DreamSerializeOptions, IdType, JoinedAssociation, JoinedAssociationsTypeFromAssociations, JoinOnStatements, NextPreloadArgumentType, OrderDir, PassthroughColumnNames, PluckEachArgs, PrimaryKeyForFind, RequiredOnClauseKeys, TableColumnNames, UpdateableAssociationProperties, UpdateableProperties, UpdateablePropertiesForClass, VariadicJoinsArgs, VariadicLeftJoinLoadArgs, VariadicLoadArgs } from './dream/types.js';
18
+ export default class Dream {
19
+ DB: any;
20
+ /**
21
+ * @internal
22
+ *
23
+ * This getter will throw an error when developers use .toEqual instead of
24
+ * useToMatchDreamModels or useToMatchDreamModel in a jest spec. This
25
+ * must be the first getter in the class in order for this to work, so don't move it.
26
+ *
27
+ */
28
+ private get _useToMatchDreamModels();
29
+ /**
30
+ * @internal
31
+ *
32
+ * Modern Javascript sets all properties that do not have an explicit
33
+ * assignment within the constructor to undefined in an implicit constructor.
34
+ * Since the Dream constructor sets the value of properties of instances of
35
+ * classes that extend Dream (e.g. when passing attributes to #new or #create
36
+ * or when loading a model via one of the #find methods or #all), we need to
37
+ * prevent those properties from being set back to undefined. Since all
38
+ * properties corresponding to a database column get a setter, we achieve this
39
+ * protection by including a guard in the setters that returns if this
40
+ * property is set.
41
+ *
42
+ */
43
+ protected columnSetterGuardActivated: boolean;
44
+ /**
45
+ * @internal
46
+ *
47
+ * Certain features (e.g. passing a Dream instance to `create` so that it automatically destructures polymorphic type and primary key)
48
+ * need static access to things set up by decorators (e.g. associations). Stage 3 Decorators change the context that is available
49
+ * at decoration time such that the class of a property being decorated is only avilable during instance instantiation. In order
50
+ * to only apply static values once, on boot, `globallyInitializingDecorators` is set to true on Dream, and all Dream models are instantiated.
51
+ *
52
+ */
53
+ private static globallyInitializingDecorators;
54
+ get schema(): any;
55
+ get globalSchema(): any;
56
+ /**
57
+ * Shadows #primaryKey, a getter which can be overwritten to customize the id field
58
+ * for a given model.
59
+ *
60
+ * @returns string
61
+ */
62
+ static get primaryKey(): "id";
63
+ /**
64
+ * Shadows #table, a getter which can be overwritten to customize the table field
65
+ * for a given model.
66
+ *
67
+ * @returns string
68
+ */
69
+ static get table(): string;
70
+ /**
71
+ * A getter which can be overwritten to customize the automatic createdAt timestamp field
72
+ * for a given model.
73
+ *
74
+ * ```ts
75
+ * class User extends ApplicationModel {
76
+ * public get createdAtField() {
77
+ * return 'createdAtTimestamp' as const
78
+ * }
79
+ * }
80
+ *
81
+ * const user = await User.first()
82
+ * user.createdAtTimestamp // returns the DateTime that this user was created
83
+ *
84
+ * @returns string
85
+ */
86
+ get createdAtField(): Readonly<string>;
87
+ /**
88
+ * A getter which can be overwritten to customize the automatic updatedAt timestamp field
89
+ * for a given model.
90
+ *
91
+ * ```ts
92
+ * class User extends ApplicationModel {
93
+ * public get updatedAtField() {
94
+ * return 'updatedAtTimestamp' as const
95
+ * }
96
+ * }
97
+ *
98
+ * const user = await User.first()
99
+ * user.updatedAtTimestamp // returns the DateTime that this user was updated
100
+ * ```
101
+ *
102
+ * @returns string
103
+ */
104
+ get updatedAtField(): Readonly<string>;
105
+ get deletedAtField(): Readonly<string>;
106
+ /**
107
+ * @internal
108
+ *
109
+ * Model storage for association metadata, set when using the association decorators like:
110
+ * @Deco.HasOne
111
+ * @Deco.HasMany
112
+ * @Deco.BelongsTo
113
+ */
114
+ protected static associationMetadataByType: AssociationStatementsMap;
115
+ /**
116
+ * @internal
117
+ *
118
+ * Model storage for scope metadata, set when using the Scope decorator
119
+ * (this default assignment simply ensures that it is
120
+ * always an array rather than undefined,
121
+ * freezing ensures that we never modify the static array on the inherited Dream class)
122
+ */
123
+ protected static scopes: {
124
+ default: readonly ScopeStatement[] | ScopeStatement[];
125
+ named: readonly ScopeStatement[] | ScopeStatement[];
126
+ };
127
+ /**
128
+ * @internal
129
+ *
130
+ * Model storage for virtual attribute metadata, set on the inheriting class when
131
+ * using the Virtual decorator (this default assignment simply ensures that it is
132
+ * always an array rather than undefined,
133
+ * freezing ensures that we never modify the static array on the inherited Dream class)
134
+ */
135
+ protected static virtualAttributes: readonly VirtualAttributeStatement[] | VirtualAttributeStatement[];
136
+ /**
137
+ * @internal
138
+ *
139
+ * Model storage for additional columns that may not be set via the new/create/update
140
+ * methods. Set on the inheriting class when using the Virtual decorator (this default
141
+ * assignment simply ensures that it is always an array rather than undefined)
142
+ */
143
+ protected static explicitUnsafeParamColumns: readonly string[] | string[];
144
+ /**
145
+ * @internal
146
+ *
147
+ * Model storage for sortable metadata, set when using the Sortable decorator
148
+ * (this default assignment simply ensures that it is always an array rather than undefined,
149
+ * freezing ensures that we never modify the static array on the inherited Dream class)
150
+ *
151
+ */
152
+ protected static sortableFields: readonly SortableFieldConfig[] | SortableFieldConfig[];
153
+ /**
154
+ * @internal
155
+ *
156
+ * Model storage for STI metadata, set when using the STI decorator
157
+ */
158
+ protected static extendedBy: (typeof Dream)[] | null;
159
+ /**
160
+ * @internal
161
+ *
162
+ * Model storage for STI metadata, set when using the STI decorator
163
+ * (this default assignment simply ensures that it is always a valid object rather than undefined,
164
+ * freezing ensures that we never modify the static array on the inherited Dream class)
165
+ */
166
+ protected static sti: {
167
+ active: boolean;
168
+ baseClass: typeof Dream | null;
169
+ value: string | null;
170
+ };
171
+ /**
172
+ * @internal
173
+ *
174
+ * Model storage for model hook metadata, set when using the following decorators:
175
+ * BeforeCreate
176
+ * BeforeUpdate
177
+ * BeforeSave
178
+ * BeforeDestroy
179
+ * AfterCreate
180
+ * AfterCreateCommit
181
+ * AfterUpdate
182
+ * AfterUpdateCommit
183
+ * AfterSave
184
+ * AfterSaveCommit
185
+ * AfterDestroy
186
+ * AfterDestroyCommit
187
+ */
188
+ protected static hooks: Readonly<HookStatementMap>;
189
+ /**
190
+ * @internal
191
+ *
192
+ * Model storage for validation metadata, set when using the Validates decorator
193
+ * (this default assignment simply ensures that it is always an array rather than undefined,
194
+ * freezing ensures that we never modify the static array on the inherited Dream class)
195
+ */
196
+ protected static validations: readonly ValidationStatement[] | ValidationStatement[];
197
+ /**
198
+ * @internal
199
+ *
200
+ * Model storage for custom validation metadata, set when using the Validate decorator
201
+ * (this default assignment simply ensures that it is always an array rather than undefined,
202
+ * freezing ensures that we never modify the static array on the inherited Dream class)
203
+ *
204
+ */
205
+ protected static customValidations: readonly string[] | string[];
206
+ /**
207
+ * @internal
208
+ *
209
+ * Model storage for replica-safe metadata, set when using the ReplicaSafe decorator
210
+ */
211
+ protected static replicaSafe: boolean;
212
+ /**
213
+ * @internal
214
+ *
215
+ * Model storage for soft-delete metadata, set when using the SoftDelete decorator
216
+ */
217
+ protected static softDelete: boolean;
218
+ /**
219
+ * @internal
220
+ *
221
+ * Provided to distinguish between Dream and other classes
222
+ *
223
+ * @returns true
224
+ */
225
+ static get isDream(): boolean;
226
+ /**
227
+ * @internal
228
+ *
229
+ * Returns true if this model class is the base class of other STI models
230
+ *
231
+ * @returns boolean
232
+ */
233
+ protected static get isSTIBase(): boolean;
234
+ /**
235
+ * @internal
236
+ *
237
+ * Returns true if this model class a child class of a base STI model
238
+ *
239
+ * @returns boolean
240
+ */
241
+ protected static get isSTIChild(): boolean;
242
+ /**
243
+ * @internal
244
+ *
245
+ * Returns either the base STI class, or else this class
246
+ *
247
+ * @returns A dream class
248
+ */
249
+ protected static get stiBaseClassOrOwnClass(): typeof Dream;
250
+ /**
251
+ * @internal
252
+ *
253
+ * Shadows .stiBaseClassOrOwnClass. Returns either the base STI class, or else this class
254
+ *
255
+ * @returns A dream class
256
+ */
257
+ protected get stiBaseClassOrOwnClass(): typeof Dream;
258
+ /**
259
+ * @internal
260
+ *
261
+ * Used by model hook decorators to apply a hook to a specific model.
262
+ *
263
+ * @param hookType - the type of hook you want to attach the provided statement to
264
+ * @param statement - the statement to couple to the provided hookType
265
+ * @returns void
266
+ */
267
+ protected static addHook(hookType: keyof typeof this.hooks, statement: HookStatement): void;
268
+ /**
269
+ * @internal
270
+ *
271
+ * Returns a unique global name for the given model.
272
+ *
273
+ * @returns A string representing a unique key for this model
274
+ */
275
+ static get globalName(): string;
276
+ private static _globalName;
277
+ /**
278
+ * @internal
279
+ *
280
+ * Used by DreamApplication during the load process
281
+ * for models, services, and controllers to assign
282
+ * unique global names to each model based on the file
283
+ * name of that model.
284
+ */
285
+ private static setGlobalName;
286
+ /**
287
+ * Returns the column names for the given model
288
+ *
289
+ * @returns The column names for the given model
290
+ */
291
+ static columns<T extends typeof Dream, I extends InstanceType<T>, DB extends I['DB'], TableName extends keyof DB = InstanceType<T>['table'] & keyof DB, Table extends DB[keyof DB] = DB[TableName], RetType = Set<keyof Table & string>>(this: T): RetType;
292
+ private static _columns;
293
+ /**
294
+ * Returns the list of column names that are safe for
295
+ * casting automatically using `.paramsFor` within a
296
+ * psychic controller. It will return a subset of the
297
+ * `.columns` getter, but which filters out the following:
298
+ * * createdAt
299
+ * * updatedAt
300
+ * * deletedAt
301
+ * * type fields for STI models
302
+ * * foreign key fields for belongs to associations (these should usually be verified before being set)
303
+ * * type fields corresponding to polymorphic associations
304
+ *
305
+ * @returns A subset of columns for the given dream class
306
+ */
307
+ static paramSafeColumnsOrFallback<T extends typeof Dream, I extends InstanceType<T>, ParamSafeColumnsOverride extends InstanceType<T>['paramSafeColumns' & keyof InstanceType<T>] extends never ? undefined : InstanceType<T>['paramSafeColumns' & keyof InstanceType<T>] & string[], ReturnVal extends ParamSafeColumnsOverride extends string[] ? Extract<DreamParamSafeColumnNames<I>, ParamSafeColumnsOverride[number] & DreamParamSafeColumnNames<I>>[] : DreamParamSafeColumnNames<I>[]>(this: T): ReturnVal;
308
+ protected static defaultParamSafeColumns<T extends typeof Dream, I extends InstanceType<T>>(this: T): DreamParamSafeColumnNames<I>[];
309
+ /**
310
+ * @internal
311
+ *
312
+ * Returns true if the column is virtual (set using the Virtual decorator)
313
+ *
314
+ * @param columnName - the name of the property you are checking for
315
+ * @returns boolean
316
+ */
317
+ static isVirtualColumn<T extends typeof Dream>(this: T, columnName: string): boolean;
318
+ /**
319
+ * @internal
320
+ *
321
+ * Locates an association's metadata by key
322
+ *
323
+ * ```ts
324
+ * Post.getAssociationMetadata('user')
325
+ * // {
326
+ * // modelCB: [Function (anonymous)],
327
+ * // type: 'BelongsTo',
328
+ * // as: 'user',
329
+ * // optional: false,
330
+ * // polymorphic: false,
331
+ * // primaryKeyOverride: null,
332
+ * // primaryKey: [Function: primaryKey],
333
+ * // primaryKeyValue: [Function: primaryKeyValue],
334
+ * // foreignKey: [Function: foreignKey],
335
+ * // foreignKeyTypeField: [Function: foreignKeyTypeField]
336
+ * // }
337
+ * ```
338
+ *
339
+ * @param associationName - the name of the association you wish to retrieve metadata for
340
+ * @returns Association metadata for the requested association
341
+ */
342
+ private static getAssociationMetadata;
343
+ /**
344
+ * @internal
345
+ *
346
+ * Returns an array containing all of the associations for this dream class
347
+ *
348
+ * @returns An array containing all of the associations for this dream class
349
+ */
350
+ private static associationMetadataMap;
351
+ /**
352
+ * @internal
353
+ *
354
+ * Returns all of the association names for this dream class
355
+ *
356
+ * @returns All of the association names for this dream class
357
+ */
358
+ static get associationNames(): string[];
359
+ /**
360
+ * Returns a query for this model which disregards default scopes
361
+ *
362
+ * @returns A query for this model which disregards default scopes
363
+ */
364
+ static removeAllDefaultScopes<T extends typeof Dream>(this: T): Query<InstanceType<T>>;
365
+ /**
366
+ * Prevents a specific default scope from applying when
367
+ * the Query is executed
368
+ *
369
+ * @returns A new Query which will prevent a specific default scope from applying
370
+ */
371
+ static removeDefaultScope<T extends typeof Dream>(this: T, scopeName: AllDefaultScopeNames<InstanceType<T>>): Query<InstanceType<T>>;
372
+ /**
373
+ * Retrieves an array containing all records corresponding to
374
+ * this model. Be careful using this, since it will attempt to
375
+ * pull every record into memory at once. For a large number
376
+ * of records, consider using `.findEach`, which will pull
377
+ * the records in batches.
378
+ *
379
+ * ```ts
380
+ * await User.all()
381
+ * ```
382
+ *
383
+ * @returns an array of dreams
384
+ */
385
+ static all<T extends typeof Dream>(this: T, options?: {
386
+ columns?: DreamColumnNames<InstanceType<T>>[];
387
+ }): Promise<InstanceType<T>[]>;
388
+ /**
389
+ * Forces use of a database connection (e.g. 'primary') during the query.
390
+ *
391
+ * NOTE: all queries within a transaction always use the 'primary' replica, so
392
+ * explicitly setting connection within a transaction has no effect.
393
+ *
394
+ * @param connection - The connection you wish to access ('primary' or 'replica')
395
+ * @returns A Query with the requested connection
396
+ */
397
+ static connection<T extends typeof Dream>(this: T, connection: DbConnectionType): Query<InstanceType<T>>;
398
+ /**
399
+ * Retrieves the number of records corresponding
400
+ * to this model.
401
+ *
402
+ * @returns The number of records corresponding to this model
403
+ */
404
+ static count<T extends typeof Dream>(this: T): Promise<number>;
405
+ /**
406
+ * Retrieves the max value of the specified column
407
+ * for this model's records.
408
+ *
409
+ * ```ts
410
+ * await User.max('id')
411
+ * // 99
412
+ * ```
413
+ *
414
+ * @param columnName - a column name on the model
415
+ * @returns the max value of the specified column for this model's records
416
+ */
417
+ static max<T extends typeof Dream, ColumnName extends DreamColumnNames<InstanceType<T>>>(this: T, columnName: ColumnName): Promise<InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]["columns" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]][ColumnName & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]["columns" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]]]["coercedType" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]["columns" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]][ColumnName & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]["columns" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]]]]>;
418
+ /**
419
+ * Retrieves the min value of the specified column
420
+ * for this model's records.
421
+ *
422
+ *
423
+ * ```ts
424
+ * await User.min('id')
425
+ * // 1
426
+ * ```
427
+ *
428
+ * @param columnName - a column name on the model
429
+ * @returns the min value of the specified column for this model's records
430
+ */
431
+ static min<T extends typeof Dream, ColumnName extends DreamColumnNames<InstanceType<T>>>(this: T, columnName: ColumnName): Promise<InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]["columns" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]][ColumnName & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]["columns" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]]]["coercedType" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]["columns" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]][ColumnName & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]["columns" & keyof InstanceType<T>["schema"][InstanceType<T>["table"] & keyof InstanceType<T>["schema"]]]]]>;
432
+ /**
433
+ * Persists a new record, setting the provided attributes
434
+ *
435
+ * ```ts
436
+ * const user = await User.create({ email: 'how@yadoin' })
437
+ * await Post.create({ body: 'howdy', user })
438
+ * ```
439
+ *
440
+ * @param attributes - attributes or belongs to associations you wish to set on this model before persisting
441
+ * @returns A newly persisted dream instance
442
+ */
443
+ static create<T extends typeof Dream>(this: T, attributes?: UpdateablePropertiesForClass<T>): Promise<InstanceType<T>>;
444
+ /**
445
+ * Attempt to create the model. If creation fails
446
+ * due to uniqueness constraint, then find the existing
447
+ * model.
448
+ *
449
+ * This is useful in situations where we want to avoid
450
+ * a race condition creating duplicate records.
451
+ *
452
+ * IMPORTANT: A unique index/uniqueness constraint must exist on
453
+ * at least one of the provided attributes
454
+ *
455
+ * ```ts
456
+ * const logEntry = await LogEntry.createOrFindBy({ externalId }, { createWith: params })
457
+ * ```
458
+ *
459
+ * @param attributes - The base attributes to persist, but also the attributes to use to find when create fails
460
+ * @param extraOpts.createWith - additional attributes to persist when creating, but not used for finding
461
+ * @returns A dream instance
462
+ */
463
+ static createOrFindBy<T extends typeof Dream>(this: T, attributes: UpdateablePropertiesForClass<T>, extraOpts?: CreateOrFindByExtraOps<T>): Promise<InstanceType<T>>;
464
+ /**
465
+ * Returns a new query instance with the distinct query applied.
466
+ * If no columnName is provided, then distinct will apply to the
467
+ * primary key by default.
468
+ *
469
+ * ```ts
470
+ * await User.distinct('name').pluck('name')
471
+ * ```
472
+ *
473
+ * @param columnName - The column name you wish to apply the distinct clause to
474
+ * @returns A Query scoped to this Dream model with the distinct clause applied
475
+ */
476
+ static distinct<T extends typeof Dream, I extends InstanceType<T>, DB extends I['DB'], TableName extends InstanceType<T>['table']>(this: T, columnName?: TableColumnNames<DB, TableName> | null | boolean): Query<InstanceType<T>, Readonly<{
477
+ joinedAssociations: Readonly<[]>;
478
+ rootTableName: InstanceType<T>["table"];
479
+ rootTableAlias: InstanceType<T> extends infer T_1 ? T_1 extends InstanceType<T> ? T_1 extends Dream ? T_1["table"] : T_1 : never : never;
480
+ allowPreload: true;
481
+ allowLeftJoinPreload: true;
482
+ }>>;
483
+ /**
484
+ * Finds a record for the corresponding model with the
485
+ * specified primary key. If not found, null
486
+ * is returned
487
+ *
488
+ * ```ts
489
+ * await User.query().find(123)
490
+ * // User{id: 123}
491
+ * ```
492
+ *
493
+ * @param primaryKey - The primaryKey of the record to look up
494
+ * @returns Either the found record, or else null
495
+ */
496
+ static find<T extends typeof Dream, I extends InstanceType<T>>(this: T, primaryKey: PrimaryKeyForFind<I>): Promise<InstanceType<T> | null>;
497
+ /**
498
+ * Finds a record for the corresponding model with the
499
+ * specified primary key. If not found, an exception is raised.
500
+ *
501
+ * ```ts
502
+ * await User.query().findOrFail(123)
503
+ * // User{id: 123}
504
+ * ```
505
+ *
506
+ * @param primaryKey - The primaryKey of the record to look up
507
+ * @returns Either the found record, or else null
508
+ */
509
+ static findOrFail<T extends typeof Dream, I extends InstanceType<T>>(this: T, primaryKey: PrimaryKeyForFind<I>): Promise<InstanceType<T>>;
510
+ /**
511
+ * Finds all records for the corresponding model in batches,
512
+ * and then calls the provided callback
513
+ * for each found record. Once all records
514
+ * have been passed for a given batch, the next set of
515
+ * records will be fetched and passed to your callback, until all
516
+ * records matching the corresponding model have been fetched.
517
+ *
518
+ * ```ts
519
+ * await User.findEach(user => {
520
+ * console.log(user)
521
+ * })
522
+ * // User{email: 'hello@world'}
523
+ * // User{email: 'goodbye@world'}
524
+ * ```
525
+ *
526
+ * @param cb - The callback to call for each found record
527
+ * @param opts.batchSize - the batch size you wish to collect records in. If not provided, it will default to 1000
528
+ * @returns void
529
+ */
530
+ static findEach<T extends typeof Dream>(this: T, cb: (instance: InstanceType<T>) => void | Promise<void>, opts?: FindEachOpts): Promise<void>;
531
+ /**
532
+ * Returns a new instance of Query scoped to the given
533
+ * model class
534
+ *
535
+ * ```ts
536
+ * await User.query().all()
537
+ * // [User{id: 1}, User{id: 2}, ...]
538
+ * ```
539
+ *
540
+ * @returns A new Query instance scoped to this Dream class
541
+ *
542
+ */
543
+ static query<T extends typeof Dream, I extends InstanceType<T>>(this: T): Query<I>;
544
+ /**
545
+ * @internal
546
+ *
547
+ * Returns a new instance of Query scoped to the given
548
+ * Dream instance
549
+ *
550
+ * ```ts
551
+ * await user = User.first()
552
+ * await user.query()
553
+ * ```
554
+ *
555
+ * @returns A new Query instance scoped to this Dream instance
556
+ *
557
+ */
558
+ private query;
559
+ /**
560
+ * Finds the first record—ordered by primary key—matching
561
+ * the corresponding model and the specified where statement.
562
+ * If not found, null is returned.
563
+ *
564
+ * ```ts
565
+ * await User.findBy({ email: 'how@yadoin' })
566
+ * // User{email: 'how@yadoin'}
567
+ * ```
568
+ *
569
+ * @param whereStatement - The where statement used to locate the record
570
+ * @returns The first model found matching the whereStatement
571
+ */
572
+ static findBy<T extends typeof Dream, I extends InstanceType<T>>(this: T, whereStatement: WhereStatement<I['DB'], I['schema'], I['table']>): Promise<InstanceType<T> | null>;
573
+ /**
574
+ * Finds the first record—ordered by primary key—matching
575
+ * the corresponding model and the specified where statement.
576
+ * If not found, an exception is raised.
577
+ *
578
+ * ```ts
579
+ * await User.findOrFailBy({ email: 'how@yadoin' })
580
+ * // User{email: 'how@yadoin'}
581
+ * ```
582
+ *
583
+ * @param whereStatement - The where statement used to locate the record
584
+ * @returns The first model found matching the whereStatement
585
+ */
586
+ static findOrFailBy<T extends typeof Dream, I extends InstanceType<T>>(this: T, whereStatement: WhereStatement<I['DB'], I['schema'], I['table']>): Promise<InstanceType<T>>;
587
+ /**
588
+ * Attempt to find the model with the given attributes.
589
+ * If no record is found, then a new record is created.
590
+ *
591
+ * ```ts
592
+ * const user = await User.findOrCreateBy({ email }, { createWith: params })
593
+ * ```
594
+ *
595
+ * @param attributes - The base attributes for finding, but also the attributes to use when creating
596
+ * @param extraOpts.createWith - additional attributes to persist when creating, but not used for finding
597
+ * @returns A dream instance
598
+ */
599
+ static findOrCreateBy<T extends typeof Dream>(this: T, attributes: UpdateablePropertiesForClass<T>, extraOpts?: CreateOrFindByExtraOps<T>): Promise<InstanceType<T>>;
600
+ /**
601
+ * Returns true if a record exists for the given
602
+ * model class
603
+ *
604
+ * ```ts
605
+ * await User.exists()
606
+ * // false
607
+ *
608
+ * await User.create({ email: 'how@yadoin' })
609
+ *
610
+ * await User.exists()
611
+ * // true
612
+ * ```
613
+ *
614
+ * @returns boolean
615
+ */
616
+ static exists<T extends typeof Dream>(this: T): Promise<boolean>;
617
+ /**
618
+ * Load each specified association using a single SQL query.
619
+ * See {@link #preload} for preloading in separate queries.
620
+ *
621
+ * Note: since leftJoinPreload loads via single query, it has
622
+ * some downsides and that may be avoided using {@link #preload}:
623
+ * 1. `limit` and `offset` will be automatically removed
624
+ * 2. `through` associations will bring additional namespaces into the query that can conflict with through associations from other associations, creating an invalid query
625
+ * 3. each nested association will result in an additional record which duplicates data from the outer record. E.g., given `.leftJoinPreload('a', 'b', 'c')`, if each `a` has 10 `b` and each `b` has 10 `c`, then for one `a`, 100 records will be returned, each of which has all of the columns of `a`. `.preload('a', 'b', 'c')` would perform three separate SQL queries, but the data for a single `a` would only be returned once.
626
+ * 4. the individual query becomes more complex the more associations are included
627
+ * 5. associations loading associations loading associations could result in exponential amounts of data; in those cases, `.preload(...).findEach(...)` avoids instantiating massive amounts of data at once
628
+ *
629
+ * ```ts
630
+ * const user = await User.leftJoinPreload('posts', 'comments', { visibilty: 'public' }, 'replies').first()
631
+ * console.log(user.posts[0].comments[0].replies)
632
+ * // [Reply{id: 1}, Reply{id: 2}]
633
+ * ```
634
+ *
635
+ * @param args - A chain of association names and where clauses
636
+ * @returns A query for this model with the include statement applied
637
+ */
638
+ static leftJoinPreload<T extends typeof Dream, I extends InstanceType<T>, DB extends I['DB'], TableName extends InstanceType<T>['table'], Schema extends I['schema'], const Arr extends readonly unknown[], const LastArg extends VariadicLeftJoinLoadArgs<DB, Schema, TableName, Arr>, const JoinedAssociationsCandidate = JoinedAssociationsTypeFromAssociations<DB, Schema, TableName, [
639
+ ...Arr,
640
+ LastArg
641
+ ]>, const JoinedAssociations extends readonly JoinedAssociation[] = JoinedAssociationsCandidate extends readonly JoinedAssociation[] ? JoinedAssociationsCandidate : never, RetQuery = QueryWithJoinedAssociationsTypeAndNoPreload<Query<I>, JoinedAssociations>>(this: T, ...args: [...Arr, LastArg]): RetQuery;
642
+ /**
643
+ * Applies preload statement to a Query scoped to this model.
644
+ * Upon instantiating records of this model type,
645
+ * specified associations will be preloaded.
646
+ *
647
+ * Preloading/loading/including is necessary prior to accessing associations
648
+ * on a Dream instance.
649
+ *
650
+ * Preload is useful for avoiding the N+1 query problem
651
+ *
652
+ * ```ts
653
+ * const user = await User.preload('posts', 'comments', { visibilty: 'public' }, 'replies').first()
654
+ * console.log(user.posts[0].comments[0].replies)
655
+ * // [Reply{id: 1}, Reply{id: 2}]
656
+ * ```
657
+ *
658
+ * @param args - A chain of association names and where clauses
659
+ * @returns A query for this model with the preload statement applied
660
+ */
661
+ static preload<T extends typeof Dream, I extends InstanceType<T>, DB extends I['DB'], TableName extends InstanceType<T>['table'], Schema extends I['schema'], const Arr extends readonly unknown[]>(this: T, ...args: [...Arr, VariadicLoadArgs<DB, Schema, TableName, Arr>]): Query<InstanceType<T>, Readonly<{
662
+ joinedAssociations: readonly [];
663
+ rootTableName: InstanceType<T>["table"];
664
+ rootTableAlias: InstanceType<T> extends infer T_1 ? T_1 extends InstanceType<T> ? T_1 extends Dream ? T_1["table"] : T_1 : never : never;
665
+ allowPreload: true;
666
+ allowLeftJoinPreload: false;
667
+ }>>;
668
+ /**
669
+ * Returns a new Query instance with the provided
670
+ * inner join statement attached
671
+ *
672
+ * ```ts
673
+ * await User.innerJoin('posts').first()
674
+ * ```
675
+ *
676
+ * @param args - A chain of association names and where clauses
677
+ * @returns A Query for this model with the inner join clause applied
678
+ */
679
+ static innerJoin<T extends typeof Dream, I extends InstanceType<T>, DB extends I['DB'], Schema extends I['schema'], TableName extends I['table'] & keyof Schema, const Arr extends readonly unknown[], const LastArg extends VariadicJoinsArgs<DB, Schema, TableName, Arr>, const JoinedAssociationsCandidate = JoinedAssociationsTypeFromAssociations<DB, Schema, TableName, [
680
+ ...Arr,
681
+ LastArg
682
+ ]>, const JoinedAssociations extends readonly JoinedAssociation[] = JoinedAssociationsCandidate extends readonly JoinedAssociation[] ? JoinedAssociationsCandidate : never, RetQuery = QueryWithJoinedAssociationsType<Query<I>, JoinedAssociations>>(this: T, ...args: [...Arr, LastArg]): RetQuery;
683
+ /**
684
+ * Returns a new Query instance with the provided
685
+ * inner join statement attached
686
+ *
687
+ * ```ts
688
+ * await user.innerJoin('posts').first()
689
+ * ```
690
+ *
691
+ * @param args - A chain of association names and where clauses
692
+ * @returns A Query for this model with the inner join clause applied
693
+ */
694
+ innerJoin<I extends Dream, DB extends I['DB'], Schema extends I['schema'], TableName extends I['table'] & keyof Schema, const Arr extends readonly unknown[], const LastArg extends VariadicJoinsArgs<DB, Schema, TableName, Arr>, const JoinedAssociationsCandidate = JoinedAssociationsTypeFromAssociations<DB, Schema, TableName, [
695
+ ...Arr,
696
+ LastArg
697
+ ]>, const JoinedAssociations extends readonly JoinedAssociation[] = JoinedAssociationsCandidate extends readonly JoinedAssociation[] ? JoinedAssociationsCandidate : never, RetQuery = QueryWithJoinedAssociationsType<Query<I>, JoinedAssociations>>(this: I, ...args: [...Arr, LastArg]): RetQuery;
698
+ /**
699
+ * Returns a new Query instance with the provided
700
+ * left join statement attached
701
+ *
702
+ * ```ts
703
+ * await User.leftJoin('posts').first()
704
+ * ```
705
+ *
706
+ * @param args - A chain of association names and where clauses
707
+ * @returns A Query for this model with the left join clause applied
708
+ */
709
+ static leftJoin<T extends typeof Dream, I extends InstanceType<T>, DB extends I['DB'], Schema extends I['schema'], TableName extends I['table'] & keyof Schema, const Arr extends readonly unknown[], const LastArg extends VariadicJoinsArgs<DB, Schema, TableName, Arr>, const JoinedAssociationsCandidate = JoinedAssociationsTypeFromAssociations<DB, Schema, TableName, [
710
+ ...Arr,
711
+ LastArg
712
+ ]>, const JoinedAssociations extends readonly JoinedAssociation[] = JoinedAssociationsCandidate extends readonly JoinedAssociation[] ? JoinedAssociationsCandidate : never, RetQuery = QueryWithJoinedAssociationsType<Query<I>, JoinedAssociations>>(this: T, ...args: [...Arr, LastArg]): RetQuery;
713
+ /**
714
+ * Returns a new Query instance with the provided
715
+ * left join statement attached
716
+ *
717
+ * ```ts
718
+ * await user.leftJoin('posts').first()
719
+ * ```
720
+ *
721
+ * @param args - A chain of association names and where clauses
722
+ * @returns A Query for this model with the left join clause applied
723
+ */
724
+ leftJoin<I extends Dream, DB extends I['DB'], Schema extends I['schema'], TableName extends I['table'] & keyof Schema, const Arr extends readonly unknown[], const LastArg extends VariadicJoinsArgs<DB, Schema, TableName, Arr>, const JoinedAssociationsCandidate = JoinedAssociationsTypeFromAssociations<DB, Schema, TableName, [
725
+ ...Arr,
726
+ LastArg
727
+ ]>, const JoinedAssociations extends readonly JoinedAssociation[] = JoinedAssociationsCandidate extends readonly JoinedAssociation[] ? JoinedAssociationsCandidate : never, RetQuery = QueryWithJoinedAssociationsType<Query<I>, JoinedAssociations>>(this: I, ...args: [...Arr, LastArg]): RetQuery;
728
+ /**
729
+ * Returns the first record corresponding to the
730
+ * model, ordered by primary key.
731
+ *
732
+ * ```ts
733
+ * await User.first()
734
+ * // User{id: 1}
735
+ * ```
736
+ *
737
+ * @returns First record, or null if no record exists
738
+ */
739
+ static first<T extends typeof Dream>(this: T): Promise<InstanceType<T> | null>;
740
+ /**
741
+ * Returns the first record corresponding to the
742
+ * model, ordered by primary key. If no record is
743
+ * found, an exception is raised.
744
+ *
745
+ * ```ts
746
+ * await User.firstOrFail()
747
+ * // User{id: 1}
748
+ * ```
749
+ *
750
+ * @returns First record
751
+ */
752
+ static firstOrFail<T extends typeof Dream>(this: T): Promise<InstanceType<T>>;
753
+ /**
754
+ * Returns the last record corresponding to the
755
+ * model, ordered by primary key.
756
+ *
757
+ * ```ts
758
+ * await User.last()
759
+ * // User{id: 99}
760
+ * ```
761
+ *
762
+ * @returns Last record, or null if no record exists
763
+ */
764
+ static last<T extends typeof Dream>(this: T): Promise<InstanceType<T> | null>;
765
+ /**
766
+ * Returns the last record corresponding to the
767
+ * model, ordered by primary key. If no record
768
+ * is found, an exception is raised.
769
+ *
770
+ * ```ts
771
+ * await User.lastOrFail()
772
+ * // User{id: 99}
773
+ * ```
774
+ *
775
+ * @returns Last record
776
+ */
777
+ static lastOrFail<T extends typeof Dream>(this: T): Promise<InstanceType<T>>;
778
+ /**
779
+ * Returns a new Query instance, specifying a limit
780
+ *
781
+ * ```ts
782
+ * await User.limit(2).all()
783
+ * // [User{}, User{}]
784
+ * ```
785
+ *
786
+ * @returns A Query for this model with the limit clause applied
787
+ */
788
+ static limit<T extends typeof Dream>(this: T, count: number | null): Query<InstanceType<T>, Readonly<{
789
+ joinedAssociations: Readonly<[]>;
790
+ rootTableName: InstanceType<T>["table"];
791
+ rootTableAlias: InstanceType<T> extends infer T_1 ? T_1 extends InstanceType<T> ? T_1 extends Dream ? T_1["table"] : T_1 : never : never;
792
+ allowPreload: true;
793
+ allowLeftJoinPreload: true;
794
+ }>>;
795
+ /**
796
+ * Returns a new Query instance, specifying an offset
797
+ *
798
+ * ```ts
799
+ * await User.offset(2).order('id').limit(2).all()
800
+ * // [User{id: 3}, User{id: 4}]
801
+ * ```
802
+ *
803
+ * @returns A Query for this model with the offset clause applied
804
+ */
805
+ static offset<T extends typeof Dream>(this: T, offset: number | null): Query<InstanceType<T>, Readonly<{
806
+ joinedAssociations: Readonly<[]>;
807
+ rootTableName: InstanceType<T>["table"];
808
+ rootTableAlias: InstanceType<T> extends infer T_1 ? T_1 extends InstanceType<T> ? T_1 extends Dream ? T_1["table"] : T_1 : never : never;
809
+ allowPreload: true;
810
+ allowLeftJoinPreload: true;
811
+ }>>;
812
+ /**
813
+ * Returns a new Query instance, attaching the provided
814
+ * order statement
815
+ *
816
+ * ```ts
817
+ * await User.order('id').all()
818
+ * // [User{id: 1}, User{id: 2}, ...]
819
+ * ```
820
+ *
821
+ * ```ts
822
+ * await User.order({ name: 'asc', id: 'desc' }).all()
823
+ * // [User{name: 'a', id: 99}, User{name: 'a', id: 97}, User{ name: 'b', id: 98 } ...]
824
+ * ```
825
+ *
826
+ * @param orderStatement - Either a string or an object specifying order. If a string, the order is implicitly ascending. If the orderStatement is an object, statements will be provided in the order of the keys set in the object
827
+ * @returns A query for this model with the order clause applied
828
+ */
829
+ static order<T extends typeof Dream, I extends InstanceType<T>>(this: T, orderStatement: DreamColumnNames<I> | Partial<Record<DreamColumnNames<I>, OrderDir>> | null): Query<InstanceType<T>>;
830
+ /**
831
+ * Plucks the provided fields from the corresponding model
832
+ *
833
+ * ```ts
834
+ * await User.pluck('id')
835
+ * // [1, 3, 2]
836
+ * ```
837
+ *
838
+ * If more than one column is requested, a multi-dimensional
839
+ * array is returned:
840
+ *
841
+ * ```ts
842
+ * await User.order('id').pluck('id', 'email')
843
+ * // [[1, 'a@a.com'], [2, 'b@b.com']]
844
+ * ```
845
+ *
846
+ * @param columnNames - The column or array of columns to pluck
847
+ * @returns An array of pluck results
848
+ */
849
+ static pluck<T extends typeof Dream, I extends InstanceType<T>, ColumnNames extends TableColumnNames<I['DB'], I['table']>[], ReturnValue extends ColumnNames['length'] extends 1 ? BaseModelColumnTypes<ColumnNames, I>[0][] : BaseModelColumnTypes<ColumnNames, I>[]>(this: T, ...columnNames: ColumnNames): Promise<ReturnValue>;
850
+ /**
851
+ * Plucks the specified fields from the given dream class table
852
+ * in batches, passing each found columns into the
853
+ * provided callback function
854
+ *
855
+ * ```ts
856
+ * await User.order('id').pluckEach('id', (id) => {
857
+ * console.log(id)
858
+ * })
859
+ * // 1
860
+ * // 2
861
+ * // 3
862
+ * ```
863
+ *
864
+ * @param fields - a list of fields to pluck, followed by a callback function to call for each set of found fields
865
+ * @returns void
866
+ */
867
+ static pluckEach<T extends typeof Dream, I extends InstanceType<T>, ColumnNames extends TableColumnNames<I['DB'], I['table']>[], CbArgTypes extends BaseModelColumnTypes<ColumnNames, I>>(this: T, ...args: PluckEachArgs<ColumnNames, CbArgTypes>): Promise<void>;
868
+ /**
869
+ * Used in conjunction with the Sortable decorator, `resort`
870
+ * takes a list of sortable fields, and for each one, finds and
871
+ * sorts each record in the DB matching the field based on the
872
+ * scope provided for each Sortable decorator found.
873
+ *
874
+ * Calling this method shouldn't be necessary, but if
875
+ * the contents of the database have shifted without firing the
876
+ * correct callback mechanisms at the application layer, calling
877
+ * `resort` will ensure that all sortable fields are set from 1..n
878
+ * with no gaps, accounting for the scopes specified in the
879
+ * corresponding Sortable decorator.
880
+ *
881
+ * ```ts
882
+ * class Post extends ApplicationModel {
883
+ * @Sortable({ scope: ['user']})
884
+ * public position: DreamColumn<User, 'position'>
885
+ * }
886
+ *
887
+ * await Post.all()
888
+ * // [Post{position: 1}, Post{position: 3}, Post{position: 5}]
889
+ *
890
+ * await Post.resort('position')
891
+ * await Post.all()
892
+ * // [Post{position: 1}, Post{position: 2}, Post{position: 3}]
893
+ * ```
894
+ *
895
+ * @param fields - A list of sortable fields to resort
896
+ * @returns void
897
+ *
898
+ */
899
+ static resort<T extends typeof Dream>(this: T, ...fields: DreamColumnNames<InstanceType<T>>[]): Promise<void>;
900
+ /**
901
+ * Returns a Query scoped to this model with
902
+ * the specified scope applied.
903
+ *
904
+ * ```ts
905
+ * class User extends ApplicationModel {
906
+ * @Scope()
907
+ * public visible(query: Query<User>) {
908
+ * return query.where({ hidden: false })
909
+ * }
910
+ * }
911
+ *
912
+ * await User.scope('visible').all()
913
+ * // [User{hidden: false}, User{hidden: false}]
914
+ * ```
915
+ *
916
+ * @param scopeName - The name of the scope
917
+ * @returns a Query scoped to this model with the specified scope applied
918
+ */
919
+ static scope<T extends typeof Dream>(this: T, scopeName: DefaultOrNamedScopeName<InstanceType<T>>): Query<InstanceType<T>>;
920
+ /**
921
+ * Returns the sql that would be executed by a Query
922
+ * scoped to this model.
923
+ *
924
+ * ```ts
925
+ * User.sql()
926
+ * // {
927
+ * // query: {
928
+ * // kind: 'SelectQueryNode',
929
+ * // from: { kind: 'FromNode', froms: [Array] },
930
+ * // selections: [ [Object] ],
931
+ * // distinctOn: undefined,
932
+ * // joins: undefined,
933
+ * // groupBy: undefined,
934
+ * // orderBy: undefined,
935
+ * // where: { kind: 'WhereNode', where: [Object] },
936
+ * // frontModifiers: undefined,
937
+ * // endModifiers: undefined,
938
+ * // limit: undefined,
939
+ * // offset: undefined,
940
+ * // with: undefined,
941
+ * // having: undefined,
942
+ * // explain: undefined,
943
+ * // setOperations: undefined
944
+ * // },
945
+ * // sql: 'select "users".* from "users" where "users"."deleted_at" is null',
946
+ * // parameters: []
947
+ * //}
948
+ * ```
949
+ *
950
+ * @returns An object representing the underlying sql statement
951
+ *
952
+ */
953
+ static sql<T extends typeof Dream>(this: T): CompiledQuery<object>;
954
+ /**
955
+ * Converts the given Dream class into a Kysely query, enabling
956
+ * you to build custom queries using the Kysely API
957
+ *
958
+ * ```ts
959
+ * await User.toKysely('select').where('email', '=', 'how@yadoin').execute()
960
+ * ```
961
+ *
962
+ * @param type - The type of Kysely query builder instance you would like to obtain
963
+ * @returns A Kysely query. Depending on the type passed, it will return either a SelectQueryBuilder, DeleteQueryBuilder, UpdateQueryBuilder, or an InsertQueryBuilder
964
+ */
965
+ static toKysely<T extends typeof Dream, QueryType extends 'select' | 'delete' | 'update' | 'insert', ToKyselyReturnType = QueryType extends 'select' ? SelectQueryBuilder<InstanceType<T>['DB'], InstanceType<T>['table'], unknown> : QueryType extends 'delete' ? DeleteQueryBuilder<InstanceType<T>['DB'], InstanceType<T>['table'], unknown> : QueryType extends 'update' ? UpdateQueryBuilder<InstanceType<T>['DB'], InstanceType<T>['table'], InstanceType<T>['table'], unknown> : QueryType extends 'insert' ? InsertQueryBuilder<InstanceType<T>['DB'], InstanceType<T>['table'], unknown> : never>(this: T, type: QueryType): ToKyselyReturnType;
966
+ /**
967
+ * Applies transaction to a new Query scoped
968
+ * to this model
969
+ *
970
+ * ```ts
971
+ * await ApplicationModel.transaction(async txn => {
972
+ * await User.txn(txn).create({ email: 'how@yadoin' })
973
+ * })
974
+ * ```
975
+ *
976
+ * @param txn - A DreamTransaction instance (usually collected by calling `ApplicationModel.transaction`)
977
+ * @returns A Query scoped to this model with the transaction applied
978
+ */
979
+ static txn<T extends typeof Dream, I extends InstanceType<T>>(this: T, txn: DreamTransaction<I>): DreamClassTransactionBuilder<I>;
980
+ /**
981
+ * Builds a new DreamTransaction instance, provides
982
+ * the instance to the provided callback.
983
+ *
984
+ * ```ts
985
+ * await ApplicationModel.transaction(async txn => {
986
+ * const user = await User.txn(txn).create({ email: 'how@yadoin' })
987
+ * await Pet.txn(txn).create({ user })
988
+ * })
989
+ * ```
990
+ *
991
+ * @param callback - A callback function to call. The transaction provided to the callback can be passed to subsequent database calls within the transaction callback
992
+ * @returns void
993
+ */
994
+ static transaction<T extends typeof Dream, CB extends (txn: DreamTransaction<InstanceType<T>>) => unknown, RetType extends ReturnType<CB>>(this: T, callback: CB): Promise<RetType>;
995
+ /**
996
+ * Sends data through for use as passthrough data
997
+ * for the associations that require it.
998
+ *
999
+ * ```ts
1000
+ * class Post {
1001
+ * @Deco.HasMany('LocalizedText')
1002
+ * public localizedTexts: LocalizedText[]
1003
+ *
1004
+ * @Deco.HasOne('LocalizedText', {
1005
+ * where: { locale: DreamConst.passthrough },
1006
+ * })
1007
+ * public currentLocalizedText: LocalizedText
1008
+ * }
1009
+ *
1010
+ * await User.passthrough({ locale: 'es-ES' })
1011
+ * .preload('posts', 'currentLocalizedText')
1012
+ * .first()
1013
+ * ```
1014
+ *
1015
+ * @param passthroughWhereStatement - Where statement used for associations that require passthrough data
1016
+ * @returns A Query for this model with the passthrough data
1017
+ */
1018
+ static passthrough<T extends typeof Dream, I extends InstanceType<T>, PassthroughColumns extends PassthroughColumnNames<I>>(this: T, passthroughWhereStatement: PassthroughOnClause<PassthroughColumns>): Query<InstanceType<T>>;
1019
+ /**
1020
+ * Applies a where statement to a new Query instance
1021
+ * scoped to this model
1022
+ *
1023
+ * ```ts
1024
+ * await User.where({ email: 'how@yadoin' }).first()
1025
+ * // User{email: 'how@yadoin'}
1026
+ * ```
1027
+ *
1028
+ * @param whereStatement - Where statement to apply to the Query
1029
+ * @returns A Query for this model with the where clause applied
1030
+ */
1031
+ static where<T extends typeof Dream, I extends InstanceType<T>, DB extends I['DB'], Schema extends I['schema'], TableName extends AssociationTableNames<DB, Schema> & keyof DB = InstanceType<T>['table']>(this: T, whereStatement: WhereStatement<DB, Schema, TableName>): Query<InstanceType<T>>;
1032
+ /**
1033
+ * Applies "OR"'d where statements to a Query scoped
1034
+ * to this model.
1035
+ *
1036
+ * ```ts
1037
+ * await User.whereAny([{ email: 'how@yadoin' }, { name: 'fred' }]).first()
1038
+ * // [User{email: 'how@yadoin'}, User{name: 'fred'}, User{name: 'fred'}]
1039
+ * ```
1040
+ *
1041
+ * @param whereStatements - a list of where statements to `OR` together
1042
+ * @returns A Query for this model with the whereAny clause applied
1043
+ */
1044
+ static whereAny<T extends typeof Dream, I extends InstanceType<T>, DB extends I['DB'], Schema extends I['schema'], TableName extends AssociationTableNames<DB, Schema> & keyof DB = InstanceType<T>['table']>(this: T, statements: WhereStatement<DB, Schema, TableName>[]): Query<InstanceType<T>>;
1045
+ /**
1046
+ * Applies a whereNot statement to a new Query instance
1047
+ * scoped to this model.
1048
+ *
1049
+ * ```ts
1050
+ * await User.whereNot({ email: 'how@yadoin' }).first()
1051
+ * // User{email: 'hello@world'}
1052
+ * ```
1053
+ *
1054
+ * @param whereStatement - A where statement to negate and apply to the Query
1055
+ * @returns A Query for this model with the whereNot clause applied
1056
+ */
1057
+ static whereNot<T extends typeof Dream, I extends InstanceType<T>, DB extends I['DB'], Schema extends I['schema'], TableName extends AssociationTableNames<DB, Schema> & keyof DB = InstanceType<T>['table']>(this: T, attributes: WhereStatement<DB, Schema, TableName>): Query<InstanceType<T>>;
1058
+ /**
1059
+ * @internal
1060
+ *
1061
+ * Given a column, checks to see if it is a foreign key
1062
+ * belonging to a BelongsTo association
1063
+ *
1064
+ * ```ts
1065
+ * Post.isBelongsToAssociationForeignKey('id')
1066
+ * // false
1067
+ * Post.isBelongsToAssociationForeignKey('userId')
1068
+ * // true
1069
+ * ```
1070
+ *
1071
+ * @param column - A column on this Dream class
1072
+ * @returns A boolean
1073
+ */
1074
+ private static isBelongsToAssociationForeignKey;
1075
+ /**
1076
+ * @internal
1077
+ *
1078
+ * Given a column, checks to see if it is a belongs to
1079
+ * polymorphic type field
1080
+ *
1081
+ * ```ts
1082
+ * LocalizedText.isBelongsToAssociationPolymorphicTypeField('localizableId')
1083
+ * // false
1084
+ * LocalizedText.isBelongsToAssociationPolymorphicTypeField('localizableType')
1085
+ * // true
1086
+ * ```
1087
+ *
1088
+ * @param column - a column on this dream class
1089
+ * @returns A boolean
1090
+ */
1091
+ private static isBelongsToAssociationPolymorphicTypeField;
1092
+ /**
1093
+ * @internal
1094
+ *
1095
+ * Returns an array of column names that are belongs
1096
+ * to foreign keys on this dream class
1097
+ *
1098
+ * ```ts
1099
+ * Post.belongsToAssociationForeignKeys()
1100
+ * // ['userId']
1101
+ * ```
1102
+ *
1103
+ * @returns An array of column names that are belongs to foreign keys on this dream class
1104
+ */
1105
+ private static belongsToAssociationForeignKeys;
1106
+ /**
1107
+ * @internal
1108
+ *
1109
+ * Returns all polymorphic type columns
1110
+ *
1111
+ * ```ts
1112
+ * LocalizedText.polymorphicTypeColumns()
1113
+ * // ['localizableType']
1114
+ * ```
1115
+ *
1116
+ * @returns An array of column names that are polymorphic type fields on the given dream class
1117
+ */
1118
+ private static polymorphicTypeColumns;
1119
+ /**
1120
+ * @internal
1121
+ *
1122
+ * Returns a list of association names which
1123
+ * correspond to belongs to associations
1124
+ * on this model class.
1125
+ *
1126
+ * ```ts
1127
+ * Post.belongsToAssociationNames()
1128
+ * // ['user']
1129
+ * ```
1130
+ *
1131
+ * @returns An array of belongs to association names
1132
+ */
1133
+ private static belongsToAssociationNames;
1134
+ /**
1135
+ * @internal
1136
+ *
1137
+ * Returns a list of association names which
1138
+ * have `dependent: destroy` set
1139
+ *
1140
+ * ```ts
1141
+ * Post.dependentDestroyAssociationNames()
1142
+ * // ['user']
1143
+ * ```
1144
+ *
1145
+ * @returns An array of HasOne/HasMany association names with `dependent: 'destroy'` defined
1146
+ */
1147
+ private static dependentDestroyAssociationNames;
1148
+ /**
1149
+ * @internal
1150
+ *
1151
+ * Returns the metadata for the provided association
1152
+ *
1153
+ * ```ts
1154
+ * new Post()['getAssociationMetadata']('user')
1155
+ * // {
1156
+ * // modelCB: [Function (anonymous)],
1157
+ * // type: 'BelongsTo',
1158
+ * // as: 'user',
1159
+ * // optional: false,
1160
+ * // polymorphic: false,
1161
+ * // primaryKeyOverride: null,
1162
+ * // primaryKey: [Function: primaryKey],
1163
+ * // primaryKeyValue: [Function: primaryKeyValue],
1164
+ * // foreignKey: [Function: foreignKey],
1165
+ * // foreignKeyTypeField: [Function: foreignKeyTypeField]
1166
+ * // }
1167
+ * ```
1168
+ *
1169
+ * @returns Association metadata
1170
+ *
1171
+ */
1172
+ private getAssociationMetadata;
1173
+ /**
1174
+ * @internal
1175
+ *
1176
+ * Returns all association metadata for the given dream class
1177
+ *
1178
+ * ```ts
1179
+ * new Post()['associationMetadataMap']()
1180
+ * // {
1181
+ * // user: {
1182
+ * // modelCB: [Function (anonymous)],
1183
+ * // type: 'BelongsTo',
1184
+ * // as: 'user',
1185
+ * // optional: false,
1186
+ * // polymorphic: false,
1187
+ * // primaryKeyOverride: null,
1188
+ * // primaryKey: [Function: primaryKey],
1189
+ * // primaryKeyValue: [Function: primaryKeyValue],
1190
+ * // foreignKey: [Function: foreignKey],
1191
+ * // foreignKeyTypeField: [Function: foreignKeyTypeField]
1192
+ * // },
1193
+ * // ratings: {
1194
+ * // modelCB: [Function (anonymous)],
1195
+ * // type: 'HasMany',
1196
+ * // as: 'ratings',
1197
+ * // polymorphic: true,
1198
+ * // source: 'ratings',
1199
+ * // preloadThroughColumns: undefined,
1200
+ * // where: undefined,
1201
+ * // whereNot: undefined,
1202
+ * // selfWhere: undefined,
1203
+ * // selfWhereNot: undefined,
1204
+ * // primaryKeyOverride: null,
1205
+ * // primaryKey: [Function: primaryKey],
1206
+ * // primaryKeyValue: [Function: primaryKeyValue],
1207
+ * // through: undefined,
1208
+ * // distinct: undefined,
1209
+ * // order: undefined,
1210
+ * // foreignKey: [Function: foreignKey],
1211
+ * // foreignKeyTypeField: [Function: foreignKeyTypeField]
1212
+ * // },
1213
+ * // ...
1214
+ * // }
1215
+ * ```
1216
+ *
1217
+ * @returns association metadata
1218
+ */
1219
+ private associationMetadataMap;
1220
+ /**
1221
+ * @internal
1222
+ *
1223
+ * returns all association data for the given dream class,
1224
+ * organized by the type of association
1225
+ *
1226
+ * ```ts
1227
+ * new Post().associationMetadataByType
1228
+ * // {
1229
+ * // belongsTo: [
1230
+ * // {
1231
+ * // modelCB: [Function (anonymous)],
1232
+ * // type: 'BelongsTo',
1233
+ * // as: 'user',
1234
+ * // optional: false,
1235
+ * // polymorphic: false,
1236
+ * // primaryKeyOverride: null,
1237
+ * // primaryKey: [Function: primaryKey],
1238
+ * // primaryKeyValue: [Function: primaryKeyValue],
1239
+ * // foreignKey: [Function: foreignKey],
1240
+ * // foreignKeyTypeField: [Function: foreignKeyTypeField]
1241
+ * // },
1242
+ * // ],
1243
+ * // hasMany: [
1244
+ * // ],
1245
+ * // hasOne: []
1246
+ * // }
1247
+ * // }
1248
+ * ```
1249
+ *
1250
+ * @returns association metadata by type
1251
+ *
1252
+ */
1253
+ private get associationMetadataByType();
1254
+ /**
1255
+ * @internal
1256
+ *
1257
+ * Returns an array of association names for the
1258
+ * given dream class
1259
+ *
1260
+ * ```ts
1261
+ * new Post().associationNames
1262
+ * // [ 'user', 'postVisibility', 'ratings', 'heartRatings' ]
1263
+ * ```
1264
+ *
1265
+ * @returns association names array
1266
+ */
1267
+ get associationNames(): string[];
1268
+ /**
1269
+ * Returns true if any of the attributes on the instance
1270
+ * have changed since it was last pulled from the database.
1271
+ * It will also return true if the instance is not yet
1272
+ * persisted.
1273
+ *
1274
+ * ```ts
1275
+ * const post = Post.new({ body: 'howyadoin' })
1276
+ * post.isDirty
1277
+ * // true
1278
+ *
1279
+ * await post.save()
1280
+ * post.isDirty
1281
+ * // false
1282
+ *
1283
+ * post.body = 'groiyyyt'
1284
+ * post.isDirty
1285
+ * // true
1286
+ * ```
1287
+ *
1288
+ * @returns A boolean
1289
+ */
1290
+ get isDirty(): boolean;
1291
+ /**
1292
+ * Returns true. This is useful for identifying
1293
+ * dream instances from other objects
1294
+ *
1295
+ * @returns true
1296
+ */
1297
+ get isDreamInstance(): boolean;
1298
+ /**
1299
+ * Runs validation checks against all validations
1300
+ * declared using the Validate and Validates decorators,
1301
+ * and returns true if any of them fail.
1302
+ *
1303
+ * ```ts
1304
+ * class User extends ApplicationModel {
1305
+ * @Validates('presence')
1306
+ * public email: DreamColumn<User, 'email'>
1307
+ * }
1308
+ * const user = User.new()
1309
+ * user.isInvalid
1310
+ * // true
1311
+ *
1312
+ * user.email = 'how@yadoin'
1313
+ * user.isInvalid
1314
+ * // false
1315
+ * ```
1316
+ *
1317
+ * @returns A boolean
1318
+ */
1319
+ get isInvalid(): boolean;
1320
+ /**
1321
+ * Returns true if the model has not been persisted
1322
+ * to the database.
1323
+ *
1324
+ * ```ts
1325
+ * const user = User.new({ email: 'howyadoin' })
1326
+ * user.isNewRecord
1327
+ * // true
1328
+ *
1329
+ * await user.save()
1330
+ * user.isNewRecord
1331
+ * // false
1332
+ * ```
1333
+ *
1334
+ * @returns A boolean
1335
+ */
1336
+ get isNewRecord(): boolean;
1337
+ /**
1338
+ * Runs validation checks against all validations
1339
+ * declared using the Validate and Validates decorators.
1340
+ * Returns true if none of the validations fail.
1341
+ *
1342
+ * NOTE: Any validations that fail will leave the errors
1343
+ * field populated on your model instance.
1344
+ *
1345
+ * ```ts
1346
+ * class User extends ApplicationModel {
1347
+ * @Validates('presence')
1348
+ * public email: DreamColumn<User, 'email'>
1349
+ * }
1350
+ *
1351
+ * const user = User.new()
1352
+ * user.isValid
1353
+ * // false
1354
+ *
1355
+ * user.email = 'how@yadoin'
1356
+ * user.isValid
1357
+ * // true
1358
+ * ```
1359
+ *
1360
+ * @returns A boolean
1361
+ */
1362
+ get isValid(): boolean;
1363
+ /**
1364
+ * The name of the primary key column on this model.
1365
+ * NOTE: Must specify `as const` when defining a custom
1366
+ * primary key.
1367
+ *
1368
+ * ```ts
1369
+ * class User extends ApplicationModel {
1370
+ * public customIdField: DreamColumn<User, 'customIdField'>
1371
+ *
1372
+ * public get primaryKey() {
1373
+ * return 'customIdField' as const
1374
+ * }
1375
+ * }
1376
+ * ```
1377
+ *
1378
+ * @returns The primary key column name
1379
+ */
1380
+ get primaryKey(): "id";
1381
+ /**
1382
+ * Returns the value of the primary key
1383
+ *
1384
+ * @returns The value of the primary key field for this Dream instance
1385
+ */
1386
+ get primaryKeyValue(): IdType;
1387
+ /**
1388
+ * This must be defined on every model, and it must point
1389
+ * to a table in your database. In addition, you must
1390
+ * return the value using the `as const` suffix, like so:
1391
+ *
1392
+ * ```ts
1393
+ * class User extends ApplicationModel {
1394
+ * public get table() {
1395
+ * return 'users' as const
1396
+ * }
1397
+ * }
1398
+ * ```
1399
+ *
1400
+ * @returns The table name for this model
1401
+ */
1402
+ get table(): AssociationTableNames<any, any>;
1403
+ /**
1404
+ * @internal
1405
+ *
1406
+ * _errors is used to inform validation errors,
1407
+ * and is built whenever validations are run on
1408
+ * a dream instance.
1409
+ */
1410
+ private _errors;
1411
+ /**
1412
+ * @internal
1413
+ *
1414
+ * Used for the changes api
1415
+ */
1416
+ private frozenAttributes;
1417
+ /**
1418
+ * @internal
1419
+ *
1420
+ * Used for the changes api
1421
+ */
1422
+ private originalAttributes;
1423
+ /**
1424
+ * @internal
1425
+ *
1426
+ * Used for the changes api
1427
+ */
1428
+ private currentAttributes;
1429
+ /**
1430
+ * @internal
1431
+ *
1432
+ * Used for the changes api
1433
+ */
1434
+ private attributesFromBeforeLastSave;
1435
+ /**
1436
+ * @internal
1437
+ *
1438
+ * Stores whether the record has been persisted or not
1439
+ */
1440
+ private _isPersisted;
1441
+ /**
1442
+ * Returns true if the model has been persisted
1443
+ * to the database.
1444
+ *
1445
+ * ```ts
1446
+ * const user = User.new({ email: 'howyadoin' })
1447
+ * user.isPersisted
1448
+ * // false
1449
+ *
1450
+ * await user.save()
1451
+ * user.isPersisted
1452
+ * // true
1453
+ * ```
1454
+ *
1455
+ * @returns A boolean
1456
+ */
1457
+ get isPersisted(): boolean;
1458
+ protected set isPersisted(val: boolean);
1459
+ /**
1460
+ * Since typescript prevents constructor functions
1461
+ * from absorbing type generics, we provide the `new`
1462
+ * method to instantiate with type protection
1463
+ *
1464
+ * ```ts
1465
+ * const user = User.new({ email: 'how@yadoin' })
1466
+ * ```
1467
+ *
1468
+ * @returns A new (unpersisted) instance of the provided dream class
1469
+ */
1470
+ static new<T extends typeof Dream>(this: T, opts?: UpdateablePropertiesForClass<T>, additionalOpts?: {
1471
+ bypassUserDefinedSetters?: boolean;
1472
+ }): InstanceType<T>;
1473
+ /**
1474
+ * @internal
1475
+ *
1476
+ * NOTE: avoid using the constructor function directly.
1477
+ * Use the static `.new` or `.create` methods instead, which
1478
+ * will provide type guarding for your attributes.
1479
+ *
1480
+ * Since typescript prevents constructor functions
1481
+ * from absorbing type generics, we provide the `new`
1482
+ * method to instantiate with type protection.
1483
+ *
1484
+ * ```ts
1485
+ * const user = User.new({ email: 'how@yadoin' })
1486
+ * ```
1487
+ *
1488
+ * @returns A new (unpersisted) instance of the provided dream class
1489
+ */
1490
+ constructor(opts: any, additionalOpts: {
1491
+ bypassUserDefinedSetters?: boolean;
1492
+ isPersisted?: boolean;
1493
+ _internalUseOnly: true;
1494
+ });
1495
+ /**
1496
+ * @internal
1497
+ *
1498
+ * Used for determining which attributes to update
1499
+ */
1500
+ protected static extractAttributesFromUpdateableProperties<T extends typeof Dream>(this: T, attributes: UpdateablePropertiesForClass<T>, dreamInstance?: InstanceType<T>, { bypassUserDefinedSetters }?: {
1501
+ bypassUserDefinedSetters?: boolean;
1502
+ }): WhereStatement<InstanceType<T>['DB'], InstanceType<T>['schema'], InstanceType<T>['table']>;
1503
+ /**
1504
+ * @internal
1505
+ *
1506
+ * defines attribute setters and getters for every column
1507
+ * set within your types/dream.ts file
1508
+ */
1509
+ private defineAttributeAccessors;
1510
+ /**
1511
+ * @internal
1512
+ *
1513
+ * Modern Javascript applies implicit accessors to instance properties that
1514
+ * shadow prototype accessors applied by Dream. This method is called after
1515
+ * every Dream model is initialized to delete the instance accessors so that
1516
+ * the prototype accessors can be reached.
1517
+ */
1518
+ protected unshadowColumnPropertyPrototypeAccessors(): void;
1519
+ protected finalizeConstruction(): void;
1520
+ /**
1521
+ * Returns true if the columnName passed is marked by a
1522
+ * Virtual attribute decorator
1523
+ *
1524
+ * @param columnName - A property on this model to check
1525
+ * @returns A boolean
1526
+ */
1527
+ isVirtualColumn<T extends Dream>(this: T, columnName: string): boolean;
1528
+ /**
1529
+ * Returns an object with column names for keys, and an
1530
+ * array of strings representing validation errors for values.
1531
+ *
1532
+ * @returns An error object
1533
+ */
1534
+ get errors(): {
1535
+ [key: string]: ValidationType[];
1536
+ };
1537
+ /**
1538
+ * Adds an error to the model. Any errors added to the model
1539
+ * will cause the model to be invalid, and will prevent the
1540
+ * model from saving.
1541
+ *
1542
+ * ```ts
1543
+ * class User extends ApplicationModel {
1544
+ * ...
1545
+ * @Validate()
1546
+ * public async validateName() {
1547
+ * if (typeof this.name === 'number')
1548
+ * this.addError('name', 'name cannot be a number')
1549
+ * }
1550
+ * }
1551
+ * ```
1552
+ *
1553
+ * @returns void
1554
+ */
1555
+ addError<I extends Dream, Key extends AttributeKeys<I>>(this: I, column: Key & string, error: string): void;
1556
+ /**
1557
+ * Changes the attribute value for a single attribute,
1558
+ * leveraging any custom-defined setters. If you would like to
1559
+ * bypass custom-defined setters, use #setAttribute instead
1560
+ *
1561
+ * ```ts
1562
+ * const user = new User()
1563
+ * user.assignAttribute('email', 'sally@gmail.com')
1564
+ * ```
1565
+ */
1566
+ assignAttribute<I extends Dream, Key extends AttributeKeys<I>>(this: I, attr: Key & string, val: any): void;
1567
+ /**
1568
+ * Changes the attribute value for a single attribute internally,
1569
+ * bypassing any custom-defined setters. If you would like to set attributes
1570
+ * without bypassing custom-defined setters, use #assignAttribute instead
1571
+ *
1572
+ * ```ts
1573
+ * const user = new User()
1574
+ * user.setAttribute('email', 'sally@gmail.com')
1575
+ * ```
1576
+ */
1577
+ setAttribute<I extends Dream, Key extends AttributeKeys<I>>(this: I, attr: Key & string, val: any): void;
1578
+ /**
1579
+ * Returns the value for a columnName provided,
1580
+ * bypassing the getters.
1581
+ *
1582
+ * ```ts
1583
+ * const user = User.new({ email: 'how@yadoin' })
1584
+ * user.getAttribute('email') // 'how@yadoin'
1585
+ * ```
1586
+ */
1587
+ getAttribute<I extends Dream, Key extends AttributeKeys<I>>(this: I, columnName: Key & string): DreamAttributes<I>[Key];
1588
+ /**
1589
+ * Returns an object containing all the columns
1590
+ * on this dream class, as well as their values,
1591
+ * bypassing getters.
1592
+ *
1593
+ * ```ts
1594
+ * const user = User.new({ email: 'how@yadoin' })
1595
+ * user.attributes()
1596
+ * // {
1597
+ * // email: 'how@yadoin',
1598
+ * // ...
1599
+ * // }
1600
+ * ```
1601
+ */
1602
+ getAttributes<I extends Dream, DB extends I['DB']>(this: I): Updateable<DB[I['table']]>;
1603
+ /**
1604
+ * @internal
1605
+ *
1606
+ * Returns the db type stored within the database
1607
+ */
1608
+ protected static cachedTypeFor<T extends typeof Dream, DB extends InstanceType<T>['DB'], TableName extends keyof DB = InstanceType<T>['table'] & keyof DB, Table extends DB[keyof DB] = DB[TableName]>(this: T, attribute: keyof Table): string;
1609
+ /**
1610
+ * Returns the attributes that have changed since
1611
+ * being persisted to the database, with the values
1612
+ * that were last persisted to the database.
1613
+ *
1614
+ * ```ts
1615
+ * const user = User.new({ email: 'original@email', password: 'howyadoin' })
1616
+ * await user.save()
1617
+ *
1618
+ * user.email = 'new@email'
1619
+ * user.changedAttributes()
1620
+ * // { email: 'original@email' }
1621
+ *
1622
+ * user.email = 'original@email'
1623
+ * user.changedAttributes()
1624
+ * // {}
1625
+ * ```
1626
+ *
1627
+ * @returns An object containing changed attributes and their original values
1628
+ */
1629
+ changedAttributes<I extends Dream, DB extends I['DB'], Schema extends I['schema'], TableName extends AssociationTableNames<DB, Schema> & keyof DB = I['table'] & AssociationTableNames<DB, Schema>, Table extends DB[keyof DB] = DB[TableName]>(this: I): Updateable<Table>;
1630
+ /**
1631
+ * Returns an object containing the attributes that have
1632
+ * changed since last persisting, along with their current
1633
+ * and previously persisted values.
1634
+ *
1635
+ * ```ts
1636
+ * const pet = Pet.new({ species: 'dog' })
1637
+ * pet.changes()
1638
+ * // {
1639
+ * // species: {
1640
+ * // was: undefined,
1641
+ * // now: 'dog',
1642
+ * // }
1643
+ * // }
1644
+ *
1645
+ * await pet.save()
1646
+ * pet.changes()
1647
+ * // {
1648
+ * // species: {
1649
+ * // was: undefined,
1650
+ * // now: 'dog',
1651
+ * // }
1652
+ * // }
1653
+ *
1654
+ * pet.species = 'cat'
1655
+ * pet.species = 'frog'
1656
+ * pet.changes()
1657
+ * // {
1658
+ * // species: {
1659
+ * // was: 'dog',
1660
+ * // now: 'frog',
1661
+ * // }
1662
+ * // }
1663
+ *
1664
+ * await pet.save()
1665
+ * pet.changes()
1666
+ * // {
1667
+ * // species: {
1668
+ * // was: 'dog',
1669
+ * // now: 'frog',
1670
+ * // }
1671
+ * // }
1672
+ * ```
1673
+ *
1674
+ * @returns An object containing changed attributes
1675
+ */
1676
+ changes<I extends Dream, DB extends I['DB'], TableName extends I['table'], Table extends DB[TableName], RetType = Partial<Record<DreamColumnNames<I>, {
1677
+ was: Updateable<Table>[DreamColumnNames<I>];
1678
+ now: Updateable<Table>[DreamColumnNames<I>];
1679
+ }>>>(this: I): RetType;
1680
+ /**
1681
+ * Returns the value most recently persisted
1682
+ * to the database.
1683
+ *
1684
+ * ```ts
1685
+ * const pet = Pet.new({ species: 'cat' })
1686
+ * pet.previousValueForAttribute('species')
1687
+ * // undefined
1688
+ *
1689
+ * await pet.save()
1690
+ * pet.previousValueForAttribute('species')
1691
+ * // undefined
1692
+ *
1693
+ * pet.species = 'dog'
1694
+ * pet.previousValueForAttribute('species')
1695
+ * // 'cat'
1696
+ *
1697
+ * await pet.save()
1698
+ * pet.previousValueForAttribute('species')
1699
+ * // 'cat'
1700
+ *
1701
+ * await pet.update({ species: 'cat' })
1702
+ * pet.previousValueForAttribute('species')
1703
+ * // 'dog'
1704
+ * ```
1705
+ *
1706
+ * @param columName - The column name you want the previous value for
1707
+ * @returns Returns the previous value for an attribute
1708
+ */
1709
+ previousValueForAttribute<I extends Dream, DB extends I['DB'], TableName extends I['table'], Table extends DB[TableName], ColumnName extends DreamColumnNames<I>>(this: I, columnName: ColumnName): Updateable<Table>[ColumnName];
1710
+ /**
1711
+ * Returns true if the columnName provided has
1712
+ * changes that were persisted during the most
1713
+ * recent save.
1714
+ *
1715
+ * @param columnName - the column name to check
1716
+ * @returns A boolean
1717
+ */
1718
+ savedChangeToAttribute<I extends Dream>(this: I, columnName: DreamColumnNames<I>): boolean;
1719
+ /**
1720
+ * Returns true if the columnName provided has
1721
+ * changes that have not yet been persisted.
1722
+ *
1723
+ * @param columnName - the column name to check
1724
+ * @returns A boolean
1725
+ */
1726
+ willSaveChangeToAttribute<I extends Dream>(this: I, attribute: DreamColumnNames<I>): boolean;
1727
+ /**
1728
+ * Returns the column names for the given model
1729
+ *
1730
+ * @returns The column names for the given model
1731
+ */
1732
+ columns<I extends Dream, DB extends I['DB'], TableName extends keyof DB = I['table'] & keyof DB, Table extends DB[keyof DB] = DB[TableName]>(this: I): Set<keyof Table>;
1733
+ /**
1734
+ * Returns an object containing the column names
1735
+ * of columns that have changed since last persist,
1736
+ * and their current values.
1737
+ *
1738
+ * ```ts
1739
+ * const user = User.new({ email: 'hello@world' })
1740
+ * user.dirtyAttributes()
1741
+ * // { email: 'hello@world' }
1742
+ *
1743
+ * await user.save()
1744
+ *
1745
+ * user.email = 'hello@world'
1746
+ * user.dirtyAttributes()
1747
+ * // {}
1748
+ *
1749
+ * user.email = 'goodbye@world'
1750
+ * user.dirtyAttributes()
1751
+ * // { email: 'goodbye@world' }
1752
+ *
1753
+ * user.email = 'hello@world'
1754
+ * user.dirtyAttributes()
1755
+ * // {}
1756
+ * ```
1757
+ *
1758
+ * @returns An object containing the changed attributes
1759
+ */
1760
+ dirtyAttributes<I extends Dream, DB extends I['DB'], Schema extends I['schema'], TableName extends AssociationTableNames<DB, Schema> & keyof DB = I['table'] & AssociationTableNames<DB, Schema>, Table extends DB[keyof DB] = DB[TableName]>(this: I): Updateable<Table>;
1761
+ /**
1762
+ * Returns true if an attribute has changes since last persist
1763
+ *
1764
+ * @returns A boolean
1765
+ */
1766
+ private attributeIsDirty;
1767
+ /**
1768
+ * @internal
1769
+ */
1770
+ private unknownValueToMillis;
1771
+ /**
1772
+ * @internal
1773
+ */
1774
+ private unknownValueToDateString;
1775
+ /**
1776
+ * Deletes the record represented by this instance
1777
+ * from the database, calling any destroy
1778
+ * hooks on this model.
1779
+ *
1780
+ * ```ts
1781
+ * const user = await User.last()
1782
+ * await user.destroy()
1783
+ * ```
1784
+ *
1785
+ * @param options - Options for destroying the instance
1786
+ * @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
1787
+ * @param options.cascade - If false, skips destroying associations marked `dependent: 'destroy'`. Defaults to true
1788
+ * @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when cascade destroying. Defaults to false
1789
+ * @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade destroying. Defaults to an empty array
1790
+ * @returns The instance that was destroyed
1791
+ */
1792
+ destroy<I extends Dream>(this: I, options?: DestroyOptions<I>): Promise<I>;
1793
+ /**
1794
+ * Deletes the record represented by this instance
1795
+ * from the database, calling any destroy
1796
+ * hooks on this model.
1797
+ *
1798
+ * If the record being destroyed is using
1799
+ * a SoftDelete decorator, the soft delete
1800
+ * will be bypassed, causing the record
1801
+ * to be permanently removed from the database.
1802
+ *
1803
+ * ```ts
1804
+ * const user = await User.last()
1805
+ * await user.reallyDestroy()
1806
+ * ```
1807
+ *
1808
+ * @param options - Options for destroying the instance
1809
+ * @param options.skipHooks - If true, skips applying model hooks during the destroy operation. Defaults to false
1810
+ * @param options.cascade - If false, skips destroying associations marked `dependent: 'destroy'`. Defaults to true
1811
+ * @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when cascade destroying. Defaults to false
1812
+ * @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade destroying. Defaults to an empty array
1813
+ * @returns The instance that was destroyed
1814
+ */
1815
+ reallyDestroy<I extends Dream>(this: I, options?: DestroyOptions<I>): Promise<I>;
1816
+ /**
1817
+ * Undestroys a SoftDelete model, unsetting
1818
+ * the `deletedAt` field in the database.
1819
+ *
1820
+ * If the model is not a SoftDelete model,
1821
+ * this will raise an exception.
1822
+ *
1823
+ * ```ts
1824
+ * const user = await User.removeAllDefaultScopes().last()
1825
+ * await user.undestroy()
1826
+ * ```
1827
+ *
1828
+ * @param options - Options for undestroying the instance
1829
+ * @param options.skipHooks - If true, skips applying model hooks during the undestroy operation. Defaults to false
1830
+ * @param options.cascade - If false, skips undestroying associations marked `dependent: 'destroy'`. Defaults to true
1831
+ * @param options.bypassAllDefaultScopes - If true, bypasses all default scopes when cascade undestroying. Defaults to false
1832
+ * @param options.defaultScopesToBypass - An array of default scope names to bypass when cascade undestroying (soft delete is always bypassed). Defaults to an empty array
1833
+ * @returns The undestroyed record
1834
+ */
1835
+ undestroy<I extends Dream>(this: I, options?: DestroyOptions<I>): Promise<I>;
1836
+ /**
1837
+ * Returns true if the argument is the same Dream class
1838
+ * with the same primary key value.
1839
+ *
1840
+ * NOTE: This does not compare attribute values other than
1841
+ * the primary key.
1842
+ *
1843
+ * @returns A boolean
1844
+ */
1845
+ equals(other: any): boolean;
1846
+ /**
1847
+ * @internal
1848
+ *
1849
+ * Used for changes API
1850
+ */
1851
+ protected freezeAttributes(): void;
1852
+ /**
1853
+ * Deep clones the model and its non-association attributes.
1854
+ * Unsets primaryKey, created and updated fields.
1855
+ *
1856
+ * @returns Non-persisted, cloned Dream instance
1857
+ */
1858
+ dup<I extends Dream>(this: I): I;
1859
+ /**
1860
+ * Deep clones the model and it's attributes, but maintains references to
1861
+ * loaded associations
1862
+ */
1863
+ private clone;
1864
+ /**
1865
+ * Creates an association for an instance. Automatically
1866
+ * handles setting foreign key and, in the case of polymorphism,
1867
+ * foreign key type.
1868
+ *
1869
+ * ```ts
1870
+ * await user.createAssociation('posts', { body: 'hello world' })
1871
+ * ```
1872
+ *
1873
+ * @param associationName - the name of the association to create
1874
+ * @param attributes - the attributes with which to create the associated model
1875
+ * @returns The created association
1876
+ */
1877
+ createAssociation<I extends Dream, AssociationName extends DreamAssociationNames<I>, PossibleArrayAssociationType = I[AssociationName & keyof I], AssociationType = PossibleArrayAssociationType extends (infer ElementType)[] ? ElementType : PossibleArrayAssociationType, RestrictedAssociationType extends AssociationType extends Dream ? AssociationType : never = AssociationType extends Dream ? AssociationType : never>(this: I, associationName: AssociationName, attributes?: UpdateableAssociationProperties<I, RestrictedAssociationType>): Promise<NonNullable<AssociationType>>;
1878
+ destroyAssociation<I extends Dream, DB extends I['DB'], TableName extends I['table'], Schema extends I['schema'], AssociationName extends DreamAssociationNames<I>, RequiredOnClauseKeysForThisAssociation extends RequiredOnClauseKeys<Schema, TableName, AssociationName>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table']>(this: I, associationName: AssociationName, options: DestroyOptions<I> & JoinOnStatements<DB, Schema, AssociationTableName, RequiredOnClauseKeysForThisAssociation>): Promise<number>;
1879
+ destroyAssociation<I extends Dream, DB extends I['DB'], Schema extends I['schema'], AssociationName extends DreamAssociationNamesWithoutRequiredOnClauses<I>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table']>(this: I, associationName: AssociationName, options?: DestroyOptions<I> & JoinOnStatements<DB, Schema, AssociationTableName, null>): Promise<number>;
1880
+ reallyDestroyAssociation<I extends Dream, DB extends I['DB'], TableName extends I['table'], Schema extends I['schema'], AssociationName extends DreamAssociationNames<I>, RequiredOnClauseKeysForThisAssociation extends RequiredOnClauseKeys<Schema, TableName, AssociationName>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table']>(this: I, associationName: AssociationName, options: DestroyOptions<I> & JoinOnStatements<DB, Schema, AssociationTableName, RequiredOnClauseKeysForThisAssociation>): Promise<number>;
1881
+ reallyDestroyAssociation<I extends Dream, DB extends I['DB'], Schema extends I['schema'], AssociationName extends DreamAssociationNamesWithoutRequiredOnClauses<I>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table']>(this: I, associationName: AssociationName, options?: DestroyOptions<I> & JoinOnStatements<DB, Schema, AssociationTableName, null>): Promise<number>;
1882
+ undestroyAssociation<I extends Dream, DB extends I['DB'], TableName extends I['table'], Schema extends I['schema'], AssociationName extends DreamAssociationNames<I>, RequiredOnClauseKeysForThisAssociation extends RequiredOnClauseKeys<Schema, TableName, AssociationName>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table']>(this: I, associationName: AssociationName, options: DestroyOptions<I> & JoinOnStatements<DB, Schema, AssociationTableName, RequiredOnClauseKeysForThisAssociation>): Promise<number>;
1883
+ undestroyAssociation<I extends Dream, DB extends I['DB'], Schema extends I['schema'], AssociationName extends DreamAssociationNamesWithoutRequiredOnClauses<I>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table']>(this: I, associationName: AssociationName, options?: DestroyOptions<I> & JoinOnStatements<DB, Schema, AssociationTableName, null>): Promise<number>;
1884
+ associationQuery<I extends Dream, DB extends I['DB'], TableName extends I['table'], Schema extends I['schema'], AssociationName extends DreamAssociationNames<I>, RequiredOnClauseKeysForThisAssociation extends RequiredOnClauseKeys<Schema, TableName, AssociationName>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table']>(this: I, associationName: AssociationName, joinOnStatements: JoinOnStatements<DB, Schema, AssociationTableName, RequiredOnClauseKeysForThisAssociation>): Query<AssociationDream, DefaultQueryTypeOptions<AssociationDream, AssociationName & string>>;
1885
+ associationQuery<I extends Dream, DB extends I['DB'], Schema extends I['schema'], AssociationName extends DreamAssociationNamesWithoutRequiredOnClauses<I>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table']>(this: I, associationName: AssociationName, joinOnStatements?: JoinOnStatements<DB, Schema, AssociationTableName, null>): Query<AssociationDream, DefaultQueryTypeOptions<AssociationDream, AssociationName & string>>;
1886
+ updateAssociation<I extends Dream, DB extends I['DB'], TableName extends I['table'], Schema extends I['schema'], AssociationName extends DreamAssociationNames<I>, RequiredOnClauseKeysForThisAssociation extends RequiredOnClauseKeys<Schema, TableName, AssociationName>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table']>(this: I, associationName: AssociationName, attributes: Partial<DreamAttributes<AssociationNameToDream<I, AssociationName>>>, updateAssociationOptions: {
1887
+ bypassAllDefaultScopes?: boolean;
1888
+ defaultScopesToBypass?: AllDefaultScopeNames<I>[];
1889
+ skipHooks?: boolean;
1890
+ } & JoinOnStatements<DB, Schema, AssociationTableName, RequiredOnClauseKeysForThisAssociation>): Promise<number>;
1891
+ updateAssociation<I extends Dream, DB extends I['DB'], Schema extends I['schema'], AssociationName extends DreamAssociationNamesWithoutRequiredOnClauses<I>, AssociationDream extends AssociationNameToDream<I, AssociationName>, AssociationTableName extends AssociationDream['table']>(this: I, associationName: AssociationName, attributes: Partial<DreamAttributes<AssociationNameToDream<I, AssociationName>>>, updateAssociationOptions?: {
1892
+ bypassAllDefaultScopes?: boolean;
1893
+ defaultScopesToBypass?: AllDefaultScopeNames<I>[];
1894
+ skipHooks?: boolean;
1895
+ } & JoinOnStatements<DB, Schema, AssociationTableName, null>): Promise<number>;
1896
+ /**
1897
+ * Sends data through for use as passthrough data
1898
+ * for the associations that require it.
1899
+ *
1900
+ * ```ts
1901
+ * class Post {
1902
+ * @Deco.HasMany('LocalizedText')
1903
+ * public localizedTexts: LocalizedText[]
1904
+ *
1905
+ * @Deco.HasOne('LocalizedText', {
1906
+ * where: { locale: DreamConst.passthrough },
1907
+ * })
1908
+ * public currentLocalizedText: LocalizedText
1909
+ * }
1910
+ *
1911
+ * await User.passthrough({ locale: 'es-ES' })
1912
+ * .preload('posts', 'currentLocalizedText')
1913
+ * .first()
1914
+ * ```
1915
+ *
1916
+ * @param passthroughWhereStatement - where statement used for associations that require passthrough data
1917
+ * @returns A cloned Query with the passthrough data
1918
+ */
1919
+ passthrough<I extends Dream, PassthroughColumns extends PassthroughColumnNames<I>>(this: I, passthroughWhereStatement: PassthroughOnClause<PassthroughColumns>): LoadBuilder<I>;
1920
+ /**
1921
+ * Loads the requested associations upon execution
1922
+ *
1923
+ * NOTE: {@link #preload} is often a preferrable way of achieving the
1924
+ * same goal.
1925
+ *
1926
+ * ```ts
1927
+ * await user
1928
+ * .load('posts', { body: ops.ilike('%hello world%') }, 'comments', 'replies')
1929
+ * .load('images')
1930
+ * .execute()
1931
+ *
1932
+ * user.posts[0].comments[0].replies[0]
1933
+ * // Reply{}
1934
+ *
1935
+ * user.images[0]
1936
+ * // Image{}
1937
+ * ```
1938
+ *
1939
+ * @param args - A list of associations (and optional where clauses) to load
1940
+ * @returns A chainable LoadBuilder instance
1941
+ */
1942
+ load<I extends Dream, DB extends I['DB'], TableName extends I['table'], Schema extends I['schema'], const Arr extends readonly unknown[]>(this: I, ...args: [...Arr, VariadicLoadArgs<DB, Schema, TableName, Arr>]): LoadBuilder<I>;
1943
+ /**
1944
+ * Load each specified association using a single SQL query.
1945
+ * See {@link #load} for loading in separate queries.
1946
+ *
1947
+ * Note: since leftJoinPreload loads via single query, it has
1948
+ * some downsides and that may be avoided using {@link #load}:
1949
+ * 1. `limit` and `offset` will be automatically removed
1950
+ * 2. `through` associations will bring additional namespaces into the query that can conflict with through associations from other associations, creating an invalid query
1951
+ * 3. each nested association will result in an additional record which duplicates data from the outer record. E.g., given `.leftJoinPreload('a', 'b', 'c')`, if each `a` has 10 `b` and each `b` has 10 `c`, then for one `a`, 100 records will be returned, each of which has all of the columns of `a`. `.load('a', 'b', 'c')` would perform three separate SQL queries, but the data for a single `a` would only be returned once.
1952
+ * 4. the individual query becomes more complex the more associations are included
1953
+ * 5. associations loading associations loading associations could result in exponential amounts of data; in those cases, `.load(...).findEach(...)` avoids instantiating massive amounts of data at once
1954
+ * Loads the requested associations upon execution
1955
+ *
1956
+ * NOTE: {@link #leftJoinPreload} is often a preferrable way of achieving the
1957
+ * same goal.
1958
+ *
1959
+ * ```ts
1960
+ * await user
1961
+ * .leftJoinLoad('posts', { body: ops.ilike('%hello world%') }, 'comments', 'replies')
1962
+ * .leftJoinLoad('images')
1963
+ * .execute()
1964
+ *
1965
+ * user.posts[0].comments[0].replies[0]
1966
+ * // Reply{}
1967
+ *
1968
+ * user.images[0]
1969
+ * // Image{}
1970
+ * ```
1971
+ *
1972
+ * @param args - A list of associations (and optional where clauses) to load
1973
+ * @returns A chainable LeftJoinLoadBuilder instance
1974
+ */
1975
+ leftJoinLoad<I extends Dream, DB extends I['DB'], TableName extends I['table'], Schema extends I['schema'], const Arr extends readonly unknown[]>(this: I, ...args: [...Arr, VariadicLeftJoinLoadArgs<DB, Schema, TableName, Arr>]): LeftJoinLoadBuilder<I>;
1976
+ /**
1977
+ * Returns true if the association specified has
1978
+ * been loaded on this instance
1979
+ *
1980
+ * Since accessing associations that haven't been
1981
+ * loaded/preloaded will raise an exception, `loaded`
1982
+ * is useful for conditionally loading from the database
1983
+ * in contexts where an association may not yet be loaded.
1984
+ *
1985
+ * ```ts
1986
+ * user.loaded('posts')
1987
+ * // false
1988
+ *
1989
+ * user = await user.load('posts').execute()
1990
+ * user.loaded('posts')
1991
+ * // true
1992
+ * ```
1993
+ *
1994
+ * @param associationName - the association name you wish to check the loading of
1995
+ * @returns A boolean
1996
+ */
1997
+ loaded<I extends Dream, TableName extends I['table'], Schema extends I['schema'], AssociationName extends NextPreloadArgumentType<Schema, TableName>>(this: I, associationName: AssociationName): boolean;
1998
+ /**
1999
+ * Reloads an instance, refreshing all it's attribute values
2000
+ * to those in the database.
2001
+ *
2002
+ * NOTE: this does not refresh associations
2003
+ *
2004
+ * ```ts
2005
+ * await user.reload()
2006
+ * ```
2007
+ *
2008
+ * @returns void
2009
+ */
2010
+ reload<I extends Dream>(this: I): Promise<void>;
2011
+ /**
2012
+ * Serializes an instance. You can specify a serializer key,
2013
+ * or else the default will be used
2014
+ *
2015
+ * ```ts
2016
+ * // uses the default serializer provided in the model's `serializers` getter
2017
+ * await user.serialize()
2018
+ *
2019
+ * // uses the summary serializer provided in the model's `serializers` getter
2020
+ * await user.serialize({ serializerKey: 'summary' })
2021
+ * ```
2022
+ *
2023
+ * @param args.casing - Which casing to use when serializing (camel or snake, default camel)
2024
+ * @param args.serializerKey - The key to use when referencing the object returned by the `serializers` getter on the given model instance (defaults to "default")
2025
+ * @returns A serialized representation of the model
2026
+ */
2027
+ serialize<I extends Dream>(this: I, { casing, serializerKey }?: DreamSerializeOptions<I>): {
2028
+ [key: string]: any;
2029
+ };
2030
+ /**
2031
+ * Takes the attributes passed in and sets their values,
2032
+ * leveraging any custom setters defined for these attributes.
2033
+ *
2034
+ * NOTE:
2035
+ * To bypass custom-defined setters, use `#setAttributes` instead.
2036
+ *
2037
+ * ```ts
2038
+ * const user = new User()
2039
+ * user.assignAttributes({ email: 'my@email', password: 'my password' })
2040
+ * ```
2041
+ */
2042
+ assignAttributes<I extends Dream>(this: I, attributes: UpdateableProperties<I>): Partial<import("./helpers/typeutils.js").MergeUnionOfRecordTypes<{
2043
+ [x: string]: any;
2044
+ } | Partial<{
2045
+ [x: string]: any;
2046
+ }>>>;
2047
+ /**
2048
+ * Takes the attributes passed in and sets their values internally,
2049
+ * bypassing any custom setters defined for these attributes.
2050
+ *
2051
+ * NOTE:
2052
+ * To leverage custom-defined setters, use `#assignAttributes` instead.
2053
+ *
2054
+ * ```ts
2055
+ * const user = new User()
2056
+ * user.setAttributes({ email: 'my@email', password: 'my password' })
2057
+ * ```
2058
+ */
2059
+ setAttributes<I extends Dream>(this: I, attributes: UpdateableProperties<I>): Partial<import("./helpers/typeutils.js").MergeUnionOfRecordTypes<{
2060
+ [x: string]: any;
2061
+ } | Partial<{
2062
+ [x: string]: any;
2063
+ }>>>;
2064
+ private _setAttributes;
2065
+ /**
2066
+ * Saves the state of the current instance to the
2067
+ * database. For new instances (that have not been
2068
+ * persisted), `save` and `create` model hooks will be called.
2069
+ * For instances that have already been persisted,
2070
+ * the `save` and `update` model hooks will be called.
2071
+ *
2072
+ * Upon saving a new instance, the primary key, timestamp
2073
+ * fields (if defined), and `type` (if STI) will be set on
2074
+ * the model.
2075
+ *
2076
+ * Upon updating an instance, the update timestamp (if defined)
2077
+ * will be updated on the model.
2078
+ *
2079
+ * ```ts
2080
+ * const user = User.new({ email: 'how@yadoin' })
2081
+ * user.name = 'fred'
2082
+ * await user.save()
2083
+ *
2084
+ * user.email // 'how@yadoin'
2085
+ * user.name // 'fred'
2086
+ * user.id // 1
2087
+ * user.createdAt // A DateTime object
2088
+ * user.updatedAt // A DateTime object
2089
+ *
2090
+ * // If User were STI:
2091
+ * user.type // 'User'
2092
+ * ```
2093
+ *
2094
+ * @param opts.skipHooks - if true, will skip applying model hooks. Defaults to false
2095
+ * @returns void
2096
+ */
2097
+ save<I extends Dream>(this: I, { skipHooks }?: {
2098
+ skipHooks?: boolean;
2099
+ }): Promise<void>;
2100
+ /**
2101
+ * Applies transaction to a new Query instance
2102
+ *
2103
+ * ```ts
2104
+ * await ApplicationModel.transaction(async txn => {
2105
+ * const user = await User.txn(txn).create({ email: 'how@yadoin' })
2106
+ * await Pet.txn(txn).create({ user })
2107
+ * })
2108
+ * ```
2109
+ *
2110
+ * @param txn - A DreamTransaction instance (collected by calling `ApplicationModel.transaction`)
2111
+ * @returns A Query scoped to this model with the transaction applied
2112
+ */
2113
+ txn<I extends Dream>(this: I, txn: DreamTransaction<Dream>): DreamInstanceTransactionBuilder<I>;
2114
+ /**
2115
+ * Applies all attribute changes passed to the Dream
2116
+ * instance, leveraging any custom-defined setters,
2117
+ * and then saves the Dream instance. Can be called
2118
+ * on an unpersisted Dream instance.
2119
+ *
2120
+ * See {@link Dream.save | save} for details on
2121
+ * the side effects of saving.
2122
+ *
2123
+ * NOTE:
2124
+ * To bypass custom-defined setters, use {@link Dream.updateAttributes | updateAttributes} instead.
2125
+ *
2126
+ * ```ts
2127
+ * const user = await User.create({ email: 'saly@gmail.com' })
2128
+ * await user.update({ email: 'sally@gmail.com' })
2129
+ * ```
2130
+ *
2131
+ * @param attributes - the attributes to set on the model
2132
+ * @param opts.skipHooks - if true, will skip applying model hooks. Defaults to false
2133
+ * @returns void
2134
+ */
2135
+ update<I extends Dream>(this: I, attributes: UpdateableProperties<I>, { skipHooks }?: {
2136
+ skipHooks?: boolean;
2137
+ }): Promise<void>;
2138
+ /**
2139
+ * Applies all attribute changes passed to the dream,
2140
+ * bypassing any custom-defined setters,
2141
+ * and then saves the dream instance. Does not bypass
2142
+ * model hooks.
2143
+ *
2144
+ * See {@link Dream.save | save} for details on
2145
+ * the side effects of saving.
2146
+ *
2147
+ * NOTE:
2148
+ * To update the values without bypassing any custom-defined
2149
+ * setters, use {@link Dream.update | update} instead.
2150
+ *
2151
+ * ```ts
2152
+ * const user = await User.create({ email: 'saly@gmail.com' })
2153
+ * await user.updateAttributes({ email: 'sally@gmail.com' })
2154
+ * ```
2155
+ *
2156
+ * @param attributes - The attributes to update on this instance
2157
+ * @param opts.skipHooks - if true, will skip applying model hooks. Defaults to false
2158
+ * @returns - void
2159
+ */
2160
+ updateAttributes<I extends Dream>(this: I, attributes: UpdateableProperties<I>, { skipHooks }?: {
2161
+ skipHooks?: boolean;
2162
+ }): Promise<void>;
2163
+ /**
2164
+ * Flags a dream model so that it does not
2165
+ * actually destroy when in a destroy phase.
2166
+ * This is usually used for a soft-delete
2167
+ * pattern
2168
+ *
2169
+ * ```ts
2170
+ * class User extends ApplicationModel {
2171
+ * @Deco.BeforeDestroy()
2172
+ * public softDelete() {
2173
+ * await this.update({ deletedAt: DateTime.now() })
2174
+ * this.preventDeletion()
2175
+ * }
2176
+ * }
2177
+ * ```
2178
+ *
2179
+ * @returns void
2180
+ */
2181
+ preventDeletion(): void;
2182
+ /**
2183
+ * Flags a dream model so that it allows
2184
+ * deletion once again.
2185
+ *
2186
+ * Undoes {@link Dream.(preventDeletion:instance) | preventDeletion}
2187
+ *
2188
+ * ```ts
2189
+ * class User extends ApplicationModel {
2190
+ * @Deco.BeforeDestroy()
2191
+ * public async softDelete() {
2192
+ * await this.update({ deletedAt: DateTime.now() })
2193
+ * this.preventDeletion()
2194
+ * }
2195
+ *
2196
+ * @Deco.BeforeDestroy()
2197
+ * public async undoSoftDelete() {
2198
+ * await this.update({ deletedAt: null })
2199
+ * this.unpreventDeletion()
2200
+ * }
2201
+ * }
2202
+ * ```
2203
+ *
2204
+ * @returns void
2205
+ */
2206
+ unpreventDeletion(): this;
2207
+ private _preventDeletion;
2208
+ }
2209
+ export interface CreateOrFindByExtraOps<T extends typeof Dream> {
2210
+ createWith?: WhereStatement<InstanceType<T>['DB'], InstanceType<T>['schema'], InstanceType<T>['table']> | UpdateablePropertiesForClass<T>;
2211
+ }