@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,31 @@
1
+ import StiChildCannotDefineNewAssociations from '../errors/sti/StiChildCannotDefineNewAssociations.js';
2
+ import StiChildIncompatibleWithReplicaSafeDecorator from '../errors/sti/StiChildIncompatibleWithReplicaSafeDecorator.js';
3
+ import StiChildIncompatibleWithSoftDeleteDecorator from '../errors/sti/StiChildIncompatibleWithSoftDeleteDecorator.js';
4
+ import { scopeImplementation } from './Scope.js';
5
+ export const STI_SCOPE_NAME = 'dream:STI';
6
+ export default function STI(dreamClass, { value } = {}) {
7
+ return function (target) {
8
+ const stiChildClass = target;
9
+ const baseClass = dreamClass['sti'].baseClass || dreamClass;
10
+ if (Object.getOwnPropertyDescriptor(stiChildClass, 'associationMetadataByType'))
11
+ throw new StiChildCannotDefineNewAssociations(baseClass, stiChildClass);
12
+ if (Object.getOwnPropertyDescriptor(stiChildClass, 'replicaSafe'))
13
+ throw new StiChildIncompatibleWithReplicaSafeDecorator(stiChildClass);
14
+ if (Object.getOwnPropertyDescriptor(stiChildClass, 'softDelete'))
15
+ throw new StiChildIncompatibleWithSoftDeleteDecorator(stiChildClass);
16
+ if (!Object.getOwnPropertyDescriptor(stiChildClass, 'extendedBy'))
17
+ stiChildClass['extendedBy'] = [];
18
+ if (!Object.getOwnPropertyDescriptor(dreamClass, 'extendedBy'))
19
+ dreamClass['extendedBy'] = [];
20
+ dreamClass['extendedBy'].push(stiChildClass);
21
+ stiChildClass['sti'] = {
22
+ active: true,
23
+ baseClass,
24
+ value: value || stiChildClass.name,
25
+ };
26
+ stiChildClass[STI_SCOPE_NAME] = function (query) {
27
+ return query.where({ type: stiChildClass['sti'].value });
28
+ };
29
+ scopeImplementation(stiChildClass, STI_SCOPE_NAME, { default: true });
30
+ };
31
+ }
@@ -0,0 +1,27 @@
1
+ export default function Scope(opts = {}) {
2
+ return function (_, context) {
3
+ const key = context.name;
4
+ context.addInitializer(function () {
5
+ // this is already a typeof Dream here, because scopes
6
+ // can only be set on static methods
7
+ const t = this;
8
+ scopeImplementation(t, key, opts);
9
+ });
10
+ };
11
+ }
12
+ export function scopeImplementation(t, key, opts = {}) {
13
+ const branch = opts.default ? 'default' : 'named';
14
+ if (!Object.getOwnPropertyDescriptor(t, 'scopes'))
15
+ t['scopes'] = {
16
+ default: [...(t['scopes']?.default || [])],
17
+ named: [...(t['scopes']?.named || [])],
18
+ };
19
+ const alreadyApplied = !!t['scopes'][branch].find(scope => scope.method === key);
20
+ if (!alreadyApplied) {
21
+ ;
22
+ t['scopes'][branch].push({
23
+ method: key,
24
+ default: opts.default || false,
25
+ });
26
+ }
27
+ }
@@ -0,0 +1,50 @@
1
+ import StiChildIncompatibleWithSoftDeleteDecorator from '../errors/sti/StiChildIncompatibleWithSoftDeleteDecorator.js';
2
+ import { scopeImplementation } from './Scope.js';
3
+ export const SOFT_DELETE_SCOPE_NAME = 'dream:SoftDelete';
4
+ /**
5
+ * Instructs the model to set a timestamp when deleting,
6
+ * rather than actually removing the record from the
7
+ * database.
8
+ *
9
+ * By default, the SoftDelete decorator will expect a
10
+ * `deletedAt` field to be set on your model, pointing
11
+ * to a `timestamp` field in the database, like so:
12
+ *
13
+ * ```ts
14
+ * export async function up(db: Kysely<any>): Promise<void> {
15
+ * await db.schema
16
+ * .createTable('posts')
17
+ * .addColumn('id', 'bigserial', col => col.primaryKey())
18
+ * .addColumn('deleted_at', 'timestamp', col => col.defaultTo(null))
19
+ * .addColumn('created_at', 'timestamp', col => col.notNull())
20
+ * .addColumn('updated_at', 'timestamp', col => col.notNull())
21
+ * .execute()
22
+ * }
23
+ *
24
+ * @SoftDelete()
25
+ * class Post extends ApplicationModel {}
26
+ * ```
27
+ *
28
+ * If you would like to use a different column to hold the
29
+ * deleted status, you can specify a custom column in your model,
30
+ * like so:
31
+ *
32
+ * @SoftDelete()
33
+ * class Post extends ApplicationModel {
34
+ * public get deletedAtField() {
35
+ * return 'customDatetimeField' as const
36
+ * }
37
+ * }
38
+ */
39
+ export default function SoftDelete() {
40
+ return function (target) {
41
+ const dreamClass = target;
42
+ if (dreamClass['isSTIChild'])
43
+ throw new StiChildIncompatibleWithSoftDeleteDecorator(dreamClass);
44
+ dreamClass['softDelete'] = true;
45
+ target[SOFT_DELETE_SCOPE_NAME] = function (query) {
46
+ return query.where({ [dreamClass.prototype.deletedAtField]: null });
47
+ };
48
+ scopeImplementation(target, SOFT_DELETE_SCOPE_NAME, { default: true });
49
+ };
50
+ }
@@ -0,0 +1,25 @@
1
+ export default function Virtual(type) {
2
+ return function (_, context) {
3
+ const key = context.name;
4
+ context.addInitializer(function () {
5
+ const t = this.constructor;
6
+ if (!t['globallyInitializingDecorators'])
7
+ return;
8
+ if (!Object.getOwnPropertyDescriptor(t, 'virtualAttributes')) {
9
+ // This pattern allows `virtualAttributes` on a base STI class and on
10
+ // child STI classes. The new `virtualAttributes` property will be created
11
+ // on the child STI class, but it will include all the `virtualAttributes`
12
+ // already declared on the base STI class.
13
+ t['virtualAttributes'] = [...t['virtualAttributes']];
14
+ }
15
+ ;
16
+ t['virtualAttributes'].push({
17
+ property: key,
18
+ type,
19
+ });
20
+ });
21
+ return function () {
22
+ return this[key];
23
+ };
24
+ };
25
+ }
@@ -0,0 +1,74 @@
1
+ import lookupModelByGlobalNameOrNames from '../../dream-application/helpers/lookupModelByGlobalNameOrNames.js';
2
+ import { validatesImplementation } from '../validations/Validates.js';
3
+ import { applyGetterAndSetter, associationPrimaryKeyAccessors, blankAssociationsFactory, finalForeignKey, foreignKeyTypeField, } from './shared.js';
4
+ /**
5
+ * Establishes a "BelongsTo" association between the base dream
6
+ * and the child dream, where the base dream has a foreign key
7
+ * which points back to the child dream.
8
+ *
9
+ * ```ts
10
+ * class UserSettings extends ApplicationModel {
11
+ * @Deco.BelongsTo('User')
12
+ * public user: User
13
+ * public userId: DreamColumn<UserSettings, 'userId'>
14
+ * }
15
+ *
16
+ * class User extends ApplicationModel {
17
+ * @Deco.HasOne('UserSettings')
18
+ * public userSettings: UserSettings
19
+ * }
20
+ * ```
21
+ *
22
+ * @param opts.foreignKey - A custom column name to use for the foreign key.
23
+ * @param opts.optional - Whether or not this association is optional. Defaults to false.
24
+ * @param opts.polymorphic - If true, this association will be treated as a polymorphic association.
25
+ * @param opts.primaryKeyOverride - A custom column name to use for the primary key.
26
+ * @param opts.withoutDefaultScopes - A list of default scopes to bypass when loading this association
27
+ */
28
+ export default function BelongsTo(globalAssociationNameOrNames, opts = {}) {
29
+ const { foreignKey, optional = false, polymorphic = false, primaryKeyOverride = null, withoutDefaultScopes, } = opts;
30
+ return function (_, context) {
31
+ const key = context.name;
32
+ context.addInitializer(function () {
33
+ const target = this;
34
+ const dreamClass = target.constructor;
35
+ if (!dreamClass['globallyInitializingDecorators']) {
36
+ /**
37
+ * Modern Javascript applies implicit accessors to instance properties
38
+ * that don't have an accessor explicitly defined in the class definition.
39
+ * The instance accessors shadow prototype accessors.
40
+ * `addInitializer` is called by Decorators after an instance has been fully
41
+ * constructed. We leverage this opportunity to delete the instance accessors
42
+ * so that the prototype accessors applied by this decorator can be reached.
43
+ */
44
+ delete this[key];
45
+ return;
46
+ }
47
+ const partialAssociation = associationPrimaryKeyAccessors({
48
+ modelCB: () => lookupModelByGlobalNameOrNames(globalAssociationNameOrNames),
49
+ globalAssociationNameOrNames,
50
+ type: 'BelongsTo',
51
+ as: key,
52
+ optional,
53
+ polymorphic,
54
+ primaryKeyOverride,
55
+ withoutDefaultScopes,
56
+ }, dreamClass);
57
+ const association = {
58
+ ...partialAssociation,
59
+ foreignKey() {
60
+ return finalForeignKey(foreignKey, dreamClass, partialAssociation);
61
+ },
62
+ foreignKeyTypeField() {
63
+ return foreignKeyTypeField(foreignKey, dreamClass, partialAssociation);
64
+ },
65
+ };
66
+ if (!Object.getOwnPropertyDescriptor(dreamClass, 'associationMetadataByType'))
67
+ dreamClass['associationMetadataByType'] = blankAssociationsFactory(dreamClass);
68
+ dreamClass['associationMetadataByType']['belongsTo'].push(association);
69
+ applyGetterAndSetter(target, association, { isBelongsTo: true, foreignKeyBase: foreignKey });
70
+ if (!optional)
71
+ validatesImplementation(target, key, 'requiredBelongsTo');
72
+ });
73
+ };
74
+ }
@@ -0,0 +1,97 @@
1
+ import lookupModelByGlobalNameOrNames from '../../dream-application/helpers/lookupModelByGlobalNameOrNames.js';
2
+ import { applyGetterAndSetter, associationPrimaryKeyAccessors, blankAssociationsFactory, finalForeignKey, foreignKeyTypeField, validateHasStatementArgs, } from './shared.js';
3
+ /**
4
+ * Establishes a "HasMany" association between the base dream
5
+ * and the child dream, where the child dream has a foreign key
6
+ * which points back to the base dream.
7
+ *
8
+ * ```ts
9
+ * class User extends ApplicationModel {
10
+ * @Deco.HasMany('Post')
11
+ * public posts: Post[]
12
+ * }
13
+ *
14
+ * class Post extends ApplicationModel {
15
+ * @Deco.BelongsTo('User')
16
+ * public user: User
17
+ * public userId: DreamColumn<Post, 'userId'>
18
+ * }
19
+ * ```
20
+ *
21
+ * @param opts.dependent - Can be either "destroy" or undefined. If "destroy", this record will be cascade deleted if the base model is destroyed.
22
+ * @param opts.distinct - Can be a column name, or else a boolean. If a column name, a distinct clause will be applied to the column. If true, a distinct clause will be applied to the primary key.
23
+ * @param opts.foreignKey - A custom column name to use for the foreign key.
24
+ * @param opts.on - An on clause to be applied when this association is loaded
25
+ * @param opts.notOn - A not on clause to be applied when this association is loaded
26
+ * @param opts.onAny - An onAny clause to be applied when this association is loaded
27
+ * @param opts.order - A custom order statement to apply to this association.
28
+ * @param opts.polymorphic - If true, this association will be treated as a polymorphic association.
29
+ * @param opts.preloadThroughColumns - An array of columns to pluck off the through association attached to this association. Can only be set if `through` is also set.
30
+ * @param opts.primaryKeyOverride - A custom column name to use for the primary key.
31
+ * @param opts.selfOn - Adds an on clause to an association between a column on the associated model and a column on this model.
32
+ * @param opts.selfNotOn - Adds a not on clause to an association between a column on the associated model and a column on this model.
33
+ * @param opts.source - Used in conjunction with 'through' to specify the source association on a child model.
34
+ * @param opts.through - If passed, this association will travel through another association.
35
+ * @param opts.withoutDefaultScopes - A list of default scopes to bypass when loading this association
36
+ */
37
+ export default function HasMany(globalAssociationNameOrNames, opts = {}) {
38
+ const { dependent, distinct, foreignKey, on, notOn, onAny, order, polymorphic = false, preloadThroughColumns, primaryKeyOverride = null, selfOn, selfNotOn, source, through, withoutDefaultScopes, } = opts;
39
+ return function (_, context) {
40
+ const key = context.name;
41
+ context.addInitializer(function () {
42
+ const target = this;
43
+ const dreamClass = target.constructor;
44
+ if (!dreamClass['globallyInitializingDecorators']) {
45
+ /**
46
+ * Modern Javascript applies implicit accessors to instance properties
47
+ * that don't have an accessor explicitly defined in the class definition.
48
+ * The instance accessors shadow prototype accessors.
49
+ * `addInitializer` is called by Decorators after an instance has been fully
50
+ * constructed. We leverage this opportunity to delete the instance accessors
51
+ * so that the prototype accessors applied by this decorator can be reached.
52
+ */
53
+ delete this[key];
54
+ return;
55
+ }
56
+ validateHasStatementArgs({
57
+ dreamClass,
58
+ dependent: dependent ?? null,
59
+ methodName: key,
60
+ on: on ?? null,
61
+ });
62
+ const partialAssociation = associationPrimaryKeyAccessors({
63
+ modelCB: () => lookupModelByGlobalNameOrNames(globalAssociationNameOrNames),
64
+ as: key,
65
+ dependent,
66
+ globalAssociationNameOrNames,
67
+ on,
68
+ notOn,
69
+ onAny,
70
+ polymorphic,
71
+ preloadThroughColumns,
72
+ primaryKeyOverride,
73
+ selfOn,
74
+ selfNotOn,
75
+ source: source || key,
76
+ type: 'HasMany',
77
+ withoutDefaultScopes,
78
+ }, dreamClass);
79
+ const association = {
80
+ ...partialAssociation,
81
+ through,
82
+ distinct,
83
+ order,
84
+ foreignKey() {
85
+ return finalForeignKey(foreignKey, dreamClass, partialAssociation);
86
+ },
87
+ foreignKeyTypeField() {
88
+ return foreignKeyTypeField(foreignKey, dreamClass, partialAssociation);
89
+ },
90
+ };
91
+ if (!Object.getOwnPropertyDescriptor(dreamClass, 'associationMetadataByType'))
92
+ dreamClass['associationMetadataByType'] = blankAssociationsFactory(dreamClass);
93
+ dreamClass['associationMetadataByType']['hasMany'].push(association);
94
+ applyGetterAndSetter(target, association);
95
+ });
96
+ };
97
+ }
@@ -0,0 +1,93 @@
1
+ import lookupModelByGlobalNameOrNames from '../../dream-application/helpers/lookupModelByGlobalNameOrNames.js';
2
+ import { applyGetterAndSetter, associationPrimaryKeyAccessors, blankAssociationsFactory, finalForeignKey, foreignKeyTypeField, validateHasStatementArgs, } from './shared.js';
3
+ /**
4
+ * Establishes a "HasOne" association between the base dream
5
+ * and the child dream, where the child dream has a foreign key
6
+ * which points back to the base dream.
7
+ *
8
+ * ```ts
9
+ * class User extends ApplicationModel {
10
+ * @Deco.HasOne('UserSettings')
11
+ * public userSettings: UserSettings
12
+ * }
13
+ *
14
+ * class UserSettings extends ApplicationModel {
15
+ * @Deco.BelongsTo('User')
16
+ * public user: User
17
+ * public userId: DreamColumn<UserSettings, 'userId'>
18
+ * }
19
+ * ```
20
+ *
21
+ * @param opts.dependent - Can be either "destroy" or undefined. If "destroy", this record will be cascade deleted if the base model is destroyed.
22
+ * @param opts.foreignKey - A custom column name to use for the foreign key.
23
+ * @param opts.on - An on clause to be applied when this association is loaded
24
+ * @param opts.notOn - A not on clause to be applied when this association is loaded
25
+ * @param opts.onAny - An onAny clause to be applied when this association is loaded
26
+ * @param opts.polymorphic - If true, this association will be treated as a polymorphic association.
27
+ * @param opts.preloadThroughColumns - An array of columns to pluck off the through association attached to this association. Can only be set if `through` is also set.
28
+ * @param opts.primaryKeyOverride - A custom column name to use for the primary key.
29
+ * @param opts.selfOn - Adds an on clause to an association between a column on the associated model and a column on this model.
30
+ * @param opts.selfNotOn - Adds a not on clause to an association between a column on the associated model and a column on this model.
31
+ * @param opts.source - Used in conjunction with 'through' to specify the source association on a child model.
32
+ * @param opts.through - If passed, this association will travel through another association.
33
+ * @param opts.withoutDefaultScopes - A list of default scopes to bypass when loading this association
34
+ */
35
+ export default function HasOne(globalAssociationNameOrNames, opts = {}) {
36
+ const { dependent, foreignKey, on, notOn, onAny, polymorphic = false, preloadThroughColumns, primaryKeyOverride = null, selfOn, selfNotOn, source, through, withoutDefaultScopes, } = opts;
37
+ return function (_, context) {
38
+ const key = context.name;
39
+ context.addInitializer(function () {
40
+ const target = this;
41
+ const dreamClass = target.constructor;
42
+ if (!dreamClass['globallyInitializingDecorators']) {
43
+ /**
44
+ * Modern Javascript applies implicit accessors to instance properties
45
+ * that don't have an accessor explicitly defined in the class definition.
46
+ * The instance accessors shadow prototype accessors.
47
+ * `addInitializer` is called by Decorators after an instance has been fully
48
+ * constructed. We leverage this opportunity to delete the instance accessors
49
+ * so that the prototype accessors applied by this decorator can be reached.
50
+ */
51
+ delete this[key];
52
+ return;
53
+ }
54
+ validateHasStatementArgs({
55
+ dreamClass,
56
+ dependent: dependent ?? null,
57
+ methodName: key,
58
+ on: on ?? null,
59
+ });
60
+ const partialAssociation = associationPrimaryKeyAccessors({
61
+ modelCB: () => lookupModelByGlobalNameOrNames(globalAssociationNameOrNames),
62
+ as: key,
63
+ dependent,
64
+ globalAssociationNameOrNames,
65
+ on,
66
+ notOn,
67
+ onAny,
68
+ polymorphic,
69
+ preloadThroughColumns,
70
+ primaryKeyOverride,
71
+ selfOn,
72
+ selfNotOn,
73
+ source: source || key,
74
+ through,
75
+ type: 'HasOne',
76
+ withoutDefaultScopes,
77
+ }, dreamClass);
78
+ const association = {
79
+ ...partialAssociation,
80
+ foreignKey() {
81
+ return finalForeignKey(foreignKey, dreamClass, partialAssociation);
82
+ },
83
+ foreignKeyTypeField() {
84
+ return foreignKeyTypeField(foreignKey, dreamClass, partialAssociation);
85
+ },
86
+ };
87
+ if (!Object.getOwnPropertyDescriptor(dreamClass, 'associationMetadataByType'))
88
+ dreamClass['associationMetadataByType'] = blankAssociationsFactory(dreamClass);
89
+ dreamClass['associationMetadataByType']['hasOne'].push(association);
90
+ applyGetterAndSetter(target, association);
91
+ });
92
+ };
93
+ }
@@ -0,0 +1,3 @@
1
+ export default function associationToGetterSetterProp(association) {
2
+ return `__${association.as}__`;
3
+ }
@@ -0,0 +1,123 @@
1
+ import pluralize from 'pluralize-esm';
2
+ import { DreamConst, } from '../../dream/types.js';
3
+ import { checkForeignKey } from '../../errors/associations/InvalidComputedForeignKey.js';
4
+ import NonLoadedAssociation from '../../errors/associations/NonLoadedAssociation.js';
5
+ import CannotDefineAssociationWithBothDependentAndPassthrough from '../../errors/CannotDefineAssociationWithBothDependentAndPassthrough.js';
6
+ import CannotDefineAssociationWithBothDependentAndRequiredOnClause from '../../errors/CannotDefineAssociationWithBothDependentAndRequiredOnClause.js';
7
+ import camelize from '../../helpers/camelize.js';
8
+ import freezeBaseClassArrayMap from '../helpers/freezeBaseClassArrayMap.js';
9
+ import associationToGetterSetterProp from './associationToGetterSetterProp.js';
10
+ export function blankAssociationsFactory(dreamClass, { freeze = false, } = {}) {
11
+ // This pattern allows associations to be defined on a base STI class and on
12
+ // child STI classes. The new `associationsMap` property will be created
13
+ // on the child STI class, but it will include all the associations already
14
+ // declared on the base STI class.
15
+ const associationsMap = {
16
+ belongsTo: [...(dreamClass['associationMetadataByType']?.belongsTo || [])],
17
+ hasMany: [...(dreamClass['associationMetadataByType']?.hasMany || [])],
18
+ hasOne: [...(dreamClass['associationMetadataByType']?.hasOne || [])],
19
+ };
20
+ if (freeze)
21
+ return freezeBaseClassArrayMap(associationsMap);
22
+ return associationsMap;
23
+ }
24
+ export function finalForeignKey(foreignKey, dreamClass, partialAssociation) {
25
+ let computedForeignKey = foreignKey;
26
+ if (!computedForeignKey) {
27
+ const table = partialAssociation.type === 'BelongsTo'
28
+ ? modelCBtoSingleDreamClass(dreamClass, partialAssociation).table
29
+ : dreamClass.table;
30
+ computedForeignKey = camelize(pluralize.singular(table)) + 'Id';
31
+ }
32
+ if (partialAssociation.type === 'BelongsTo' || !partialAssociation.through)
33
+ checkForeignKey(foreignKey, computedForeignKey, dreamClass, partialAssociation);
34
+ return computedForeignKey;
35
+ }
36
+ export function foreignKeyTypeField(foreignKey, dream, partialAssociation) {
37
+ return finalForeignKey(foreignKey, dream, partialAssociation).replace(/Id$/, 'Type');
38
+ }
39
+ export function modelCBtoSingleDreamClass(dreamClass, partialAssociation) {
40
+ if (Array.isArray(partialAssociation.modelCB()))
41
+ throw new Error(`Polymorphic association ${partialAssociation.as} on model ${dreamClass.name} requires an explicit foreignKey`);
42
+ return partialAssociation.modelCB();
43
+ }
44
+ export function applyGetterAndSetter(target, partialAssociation, { foreignKeyBase, isBelongsTo, } = {}) {
45
+ const dreamPrototype = Object.getPrototypeOf(target);
46
+ const dreamClass = target.constructor;
47
+ Object.defineProperty(dreamPrototype, partialAssociation.as, {
48
+ configurable: true,
49
+ get: function () {
50
+ const value = this[associationToGetterSetterProp(partialAssociation)];
51
+ if (value === undefined)
52
+ throw new NonLoadedAssociation({ dreamClass, associationName: partialAssociation.as });
53
+ else
54
+ return value;
55
+ },
56
+ set: function (associatedModel) {
57
+ /**
58
+ *
59
+ * Modern Javascript sets all properties that do not have an explicit
60
+ * assignment within the constructor to undefined in an implicit constructor.
61
+ * Since the Dream constructor sets the value of properties of instances of
62
+ * classes that extend Dream (e.g. when passing attributes to #new or #create
63
+ * or when loading a model via one of the #find methods or #all), we need to
64
+ * prevent those properties from being set back to undefined. Since all
65
+ * properties corresponding to a database column get a setter, we achieve this
66
+ * protection by including a guard in the setters that returns if this
67
+ * property is set.
68
+ *
69
+ */
70
+ if (this['columnSetterGuardActivated'])
71
+ return;
72
+ this[associationToGetterSetterProp(partialAssociation)] = associatedModel;
73
+ if (isBelongsTo) {
74
+ ;
75
+ this[finalForeignKey(foreignKeyBase, dreamClass, partialAssociation)] =
76
+ partialAssociation.primaryKeyValue(associatedModel);
77
+ if (partialAssociation.polymorphic)
78
+ this[foreignKeyTypeField(foreignKeyBase, dreamClass, partialAssociation)] =
79
+ associatedModel?.constructor?.name;
80
+ }
81
+ },
82
+ });
83
+ }
84
+ export function associationPrimaryKeyAccessors(partialAssociation, dreamClass) {
85
+ return {
86
+ ...partialAssociation,
87
+ primaryKey(associationInstance) {
88
+ if (this.primaryKeyOverride)
89
+ return this.primaryKeyOverride;
90
+ if (associationInstance)
91
+ return associationInstance.primaryKey;
92
+ const associationClass = this.modelCB();
93
+ if (Array.isArray(associationClass)) {
94
+ throw new Error(`
95
+ Cannot lookup primaryKey on polymorphic association:
96
+ dream class: ${dreamClass.name}
97
+ association: ${this.as}
98
+ `);
99
+ }
100
+ return associationClass.primaryKey;
101
+ },
102
+ primaryKeyValue(associationInstance) {
103
+ if (associationInstance === undefined)
104
+ return undefined;
105
+ if (associationInstance === null)
106
+ return null;
107
+ return associationInstance[this.primaryKey(associationInstance)];
108
+ },
109
+ };
110
+ }
111
+ export function validateHasStatementArgs({ dreamClass, dependent, methodName, on, }) {
112
+ const hasPassthroughOn = Object.values(on || {}).find(val => val === DreamConst.passthrough);
113
+ const hasRequiredOn = Object.values(on || {}).find(val => val === DreamConst.required);
114
+ if (dependent && hasPassthroughOn)
115
+ throw new CannotDefineAssociationWithBothDependentAndPassthrough(dreamClass, methodName);
116
+ if (dependent && hasRequiredOn)
117
+ throw new CannotDefineAssociationWithBothDependentAndRequiredOnClause(dreamClass, methodName);
118
+ }
119
+ // function hydratedSourceValue(dream: Dream | typeof Dream | undefined, sourceName: string) {
120
+ // if (!dream) return
121
+ // if (!sourceName) return
122
+ // return (dream as any)[sourceName] || (dream as any)[singular(sourceName)]
123
+ // }
@@ -0,0 +1,7 @@
1
+ export default function freezeBaseClassArrayMap(map) {
2
+ return Object.freeze(Object.keys(map).reduce((frozenMap, key) => {
3
+ ;
4
+ frozenMap[key] = Object.freeze(map[key]);
5
+ return frozenMap;
6
+ }, {}));
7
+ }
@@ -0,0 +1,22 @@
1
+ import { blankHooksFactory } from './shared.js';
2
+ export default function AfterCreate(opts = {}) {
3
+ return function (_, context) {
4
+ context.addInitializer(function () {
5
+ afterCreateImplementation(this, context.name, opts);
6
+ });
7
+ };
8
+ }
9
+ export function afterCreateImplementation(target, key, opts = {}) {
10
+ const dreamClass = target.constructor;
11
+ if (!dreamClass['globallyInitializingDecorators'])
12
+ return;
13
+ if (!Object.getOwnPropertyDescriptor(dreamClass, 'hooks'))
14
+ dreamClass['hooks'] = blankHooksFactory(dreamClass);
15
+ const hookStatement = {
16
+ className: dreamClass.name,
17
+ method: key,
18
+ type: 'afterCreate',
19
+ ifChanged: opts.ifChanged,
20
+ };
21
+ dreamClass['addHook']('afterCreate', hookStatement);
22
+ }
@@ -0,0 +1,39 @@
1
+ import { blankHooksFactory } from './shared.js';
2
+ /**
3
+ * Calls the decorated method whenever a dream has finished
4
+ * being created. If the save takes place within a transaction,
5
+ * this method will not be called until the transaction is
6
+ * committed. However, if the save is not taking place in
7
+ * a transaction, the method will be run after the save
8
+ * is complete.
9
+ *
10
+ * class User extends ApplicationModel {
11
+ * @Deco.AfterCreateCommit()
12
+ * public doSomething() {
13
+ * ...
14
+ * }
15
+ * }
16
+ *
17
+ * @param opts.ifChanged - Optional. A list of columns which should must change in order for this function to be called.
18
+ */
19
+ export default function AfterCreateCommit(opts = {}) {
20
+ return function (_, context) {
21
+ context.addInitializer(function () {
22
+ afterCreateCommitImplementation(this, context.name, opts);
23
+ });
24
+ };
25
+ }
26
+ export function afterCreateCommitImplementation(target, key, opts = {}) {
27
+ const dreamClass = target.constructor;
28
+ if (!dreamClass['globallyInitializingDecorators'])
29
+ return;
30
+ if (!Object.getOwnPropertyDescriptor(dreamClass, 'hooks'))
31
+ dreamClass['hooks'] = blankHooksFactory(dreamClass);
32
+ const hookStatement = {
33
+ className: dreamClass.name,
34
+ method: key,
35
+ type: 'afterCreateCommit',
36
+ ifChanged: opts.ifChanged,
37
+ };
38
+ dreamClass['addHook']('afterCreateCommit', hookStatement);
39
+ }
@@ -0,0 +1,21 @@
1
+ import { blankHooksFactory } from './shared.js';
2
+ export default function AfterDestroy() {
3
+ return function (_, context) {
4
+ context.addInitializer(function () {
5
+ afterDestroyImplementation(this, context.name);
6
+ });
7
+ };
8
+ }
9
+ export function afterDestroyImplementation(target, key) {
10
+ const dreamClass = target.constructor;
11
+ if (!dreamClass['globallyInitializingDecorators'])
12
+ return;
13
+ if (!Object.getOwnPropertyDescriptor(dreamClass, 'hooks'))
14
+ dreamClass['hooks'] = blankHooksFactory(dreamClass);
15
+ const hookStatement = {
16
+ className: dreamClass.name,
17
+ method: key,
18
+ type: 'afterDestroy',
19
+ };
20
+ dreamClass['addHook']('afterDestroy', hookStatement);
21
+ }
@@ -0,0 +1,36 @@
1
+ import { blankHooksFactory } from './shared.js';
2
+ /**
3
+ * Calls the decorated method whenever a dream has finished
4
+ * being destroyed. If the destroy takes place within a transaction,
5
+ * this method will not be called until the transaction is
6
+ * committed. However, if the destroy is not taking place in
7
+ * a transaction, the method will be run after the save
8
+ * is complete.
9
+ *
10
+ * class User extends ApplicationModel {
11
+ * @Deco.AfterDestroyCommit()
12
+ * public doSomething() {
13
+ * ...
14
+ * }
15
+ * }
16
+ */
17
+ export default function AfterDestroyCommit() {
18
+ return function (_, context) {
19
+ context.addInitializer(function () {
20
+ afterDestroyCommitImplementation(this, context.name);
21
+ });
22
+ };
23
+ }
24
+ export function afterDestroyCommitImplementation(target, key) {
25
+ const dreamClass = target.constructor;
26
+ if (!dreamClass['globallyInitializingDecorators'])
27
+ return;
28
+ if (!Object.getOwnPropertyDescriptor(dreamClass, 'hooks'))
29
+ dreamClass['hooks'] = blankHooksFactory(dreamClass);
30
+ const hookStatement = {
31
+ className: dreamClass.name,
32
+ method: key,
33
+ type: 'afterDestroyCommit',
34
+ };
35
+ dreamClass['addHook']('afterDestroyCommit', hookStatement);
36
+ }