@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,375 @@
1
+ import * as fs from 'fs/promises';
2
+ import { sql } from 'kysely';
3
+ import * as path from 'path';
4
+ import { isPrimitiveDataType } from '../../db/dataTypes.js';
5
+ import _db from '../../db/index.js';
6
+ import DreamApplication from '../../dream-application/index.js';
7
+ import { DreamConst } from '../../dream/types.js';
8
+ import FailedToIdentifyAssociation from '../../errors/schema-builder/FailedToIdentifyAssociation.js';
9
+ import autogeneratedFileDisclaimer from '../../global-cli/helpers/autogeneratedFileMessage.js';
10
+ import camelize from '../camelize.js';
11
+ import EnvInternal from '../EnvInternal.js';
12
+ import pascalize from '../pascalize.js';
13
+ import sortBy from '../sortBy.js';
14
+ import uniq from '../uniq.js';
15
+ export default class SchemaBuilder {
16
+ async build() {
17
+ const { schemaConstContent, passthroughColumns, allDefaultScopeNames } = await this.buildSchemaContent();
18
+ const imports = await this.getSchemaImports(schemaConstContent);
19
+ const importStr = imports.length
20
+ ? `\
21
+ import {
22
+ ${imports.sort().join(',\n ')}
23
+ } from './db'`
24
+ : '';
25
+ const calendarDateImportStatement = EnvInternal.boolean('DREAM_CORE_DEVELOPMENT')
26
+ ? "import CalendarDate from '../../src/helpers/CalendarDate'"
27
+ : "import { CalendarDate } from '@rvohealth/dream'";
28
+ const dreamApp = DreamApplication.getOrFail();
29
+ const newSchemaFileContents = `\
30
+ ${autogeneratedFileDisclaimer()}
31
+ ${calendarDateImportStatement}
32
+ import { DateTime } from 'luxon'
33
+ ${importStr}
34
+
35
+ ${schemaConstContent}
36
+
37
+ export const globalSchema = {
38
+ passthroughColumns: ${stringifyArray(uniq(passthroughColumns.sort()), { indent: 4 })},
39
+ allDefaultScopeNames: ${stringifyArray(uniq(allDefaultScopeNames.sort()), { indent: 4 })},
40
+ globalNames: {
41
+ models: ${this.globalModelNames()},
42
+ serializers: ${stringifyArray(Object.keys(dreamApp.serializers || {}).sort(), { indent: 6 })},
43
+ },
44
+ } as const
45
+ `;
46
+ // const newSchemaFileContents = `\
47
+ // ${schemaConstContent}
48
+ // `
49
+ const schemaPath = path.join(dreamApp.projectRoot, dreamApp.paths.types, 'dream.ts');
50
+ await fs.writeFile(schemaPath, newSchemaFileContents);
51
+ }
52
+ globalModelNames() {
53
+ const dreamApp = DreamApplication.getOrFail();
54
+ return `{
55
+ ${Object.keys(dreamApp.models)
56
+ .map(key => `'${key}': '${dreamApp.models[key].prototype.table}'`)
57
+ .join(',\n ')}
58
+ }`;
59
+ }
60
+ async buildSchemaContent() {
61
+ let passthroughColumns = [];
62
+ let allDefaultScopeNames = [];
63
+ const schemaData = await this.getSchemaData();
64
+ const fileContents = await this.loadDbSyncFile();
65
+ const schemaConstContent = `\
66
+ export const schema = {
67
+ ${Object.keys(schemaData)
68
+ .map(tableName => {
69
+ const tableData = schemaData[tableName];
70
+ const defaultScopeNames = tableData.scopes.default;
71
+ const namedScopeNames = tableData.scopes.named;
72
+ allDefaultScopeNames = [...allDefaultScopeNames, ...defaultScopeNames];
73
+ return `\
74
+ ${tableName}: {
75
+ primaryKey: '${tableData.primaryKey}',
76
+ createdAtField: '${tableData.createdAtField}',
77
+ updatedAtField: '${tableData.updatedAtField}',
78
+ deletedAtField: '${tableData.deletedAtField}',
79
+ serializerKeys: ${stringifyArray(tableData.serializerKeys)},
80
+ scopes: {
81
+ default: ${stringifyArray(defaultScopeNames)},
82
+ named: ${stringifyArray(namedScopeNames)},
83
+ },
84
+ columns: {
85
+ ${Object.keys(schemaData[tableName].columns)
86
+ .sort()
87
+ .map(columnName => {
88
+ const columnData = tableData.columns[columnName];
89
+ const kyselyType = this.kyselyType(tableName, columnName, fileContents);
90
+ return `${columnName}: {
91
+ coercedType: {} as ${this.coercedType(kyselyType, columnData.dbType)},
92
+ enumType: ${columnData.enumType ? `{} as ${columnData.enumType}` : 'null'},
93
+ enumArrayType: ${columnData.enumType ? `[] as ${columnData.enumType}[]` : 'null'},
94
+ enumValues: ${columnData.enumValues ?? 'null'},
95
+ dbType: '${columnData.dbType}',
96
+ allowNull: ${columnData.allowNull},
97
+ isArray: ${columnData.isArray},
98
+ },`;
99
+ })
100
+ .join('\n ')}
101
+ },
102
+ virtualColumns: ${stringifyArray(schemaData[tableName].virtualColumns)},
103
+ associations: {
104
+ ${Object.keys(schemaData[tableName].associations)
105
+ .sort()
106
+ .map(associationName => {
107
+ const associationMetadata = tableData.associations[associationName];
108
+ const whereStatement = associationMetadata.where;
109
+ const requiredOnClauses = whereStatement === null
110
+ ? []
111
+ : Object.keys(whereStatement).filter(column => whereStatement[column] === DreamConst.required);
112
+ passthroughColumns =
113
+ whereStatement === null
114
+ ? passthroughColumns
115
+ : [
116
+ ...passthroughColumns,
117
+ ...Object.keys(whereStatement).filter(column => whereStatement[column] === DreamConst.passthrough),
118
+ ];
119
+ return `${associationName}: {
120
+ type: '${associationMetadata.type}',
121
+ foreignKey: ${associationMetadata.foreignKey ? `'${associationMetadata.foreignKey}'` : 'null'},
122
+ tables: ${stringifyArray(associationMetadata.tables)},
123
+ optional: ${associationMetadata.optional},
124
+ requiredOnClauses: ${requiredOnClauses.length === 0 ? 'null' : stringifyArray(requiredOnClauses)},
125
+ },`;
126
+ })
127
+ .join('\n ')}
128
+ },
129
+ },\
130
+ `;
131
+ })
132
+ .join('\n ')}
133
+ } as const`;
134
+ return { schemaConstContent, passthroughColumns, allDefaultScopeNames };
135
+ }
136
+ async getSchemaImports(schemaContent) {
137
+ const allExports = await this.getExportedModulesFromDbSync();
138
+ const schemaContentWithoutImports = schemaContent.replace(/import {[^}]*}/gm, '');
139
+ return allExports.filter(exportedModule => {
140
+ if (new RegExp(`coercedType: {} as ${exportedModule}`).test(schemaContentWithoutImports))
141
+ return true;
142
+ if (new RegExp(`coercedType: {} as ArrayType<${exportedModule}`).test(schemaContentWithoutImports))
143
+ return true;
144
+ if (new RegExp(`enumType: {} as ${exportedModule}`).test(schemaContentWithoutImports))
145
+ return true;
146
+ if (new RegExp(`enumValues: ${exportedModule}`).test(schemaContentWithoutImports))
147
+ return true;
148
+ return false;
149
+ });
150
+ }
151
+ async tableData(tableName) {
152
+ const dreamApp = DreamApplication.getOrFail();
153
+ const models = Object.values(dreamApp.models);
154
+ const model = models.find(model => model.table === tableName);
155
+ if (!model)
156
+ throw new Error(`
157
+ Could not find a Dream model with table "${tableName}".
158
+
159
+ If you recently changed the name of a table in a migration, you
160
+ may need to update the table getter in the corresponding Dream.
161
+ `);
162
+ const associationData = this.getAssociationData(tableName);
163
+ let serializers;
164
+ try {
165
+ serializers =
166
+ model?.prototype?.['serializers'] || {};
167
+ }
168
+ catch {
169
+ serializers = {};
170
+ }
171
+ return {
172
+ primaryKey: model.prototype.primaryKey,
173
+ createdAtField: model.prototype.createdAtField,
174
+ updatedAtField: model.prototype.updatedAtField,
175
+ deletedAtField: model.prototype.deletedAtField,
176
+ scopes: {
177
+ default: model['scopes'].default.map(scopeStatement => scopeStatement.method),
178
+ named: model['scopes'].named.map(scopeStatement => scopeStatement.method),
179
+ },
180
+ columns: await this.getColumnData(tableName, associationData),
181
+ virtualColumns: this.getVirtualColumns(tableName),
182
+ associations: associationData,
183
+ serializerKeys: Object.keys(serializers),
184
+ };
185
+ }
186
+ async getColumnData(tableName, associationData) {
187
+ const db = _db('primary');
188
+ const sqlQuery = sql `SELECT column_name, udt_name::regtype, is_nullable, data_type FROM information_schema.columns WHERE table_name = ${tableName}`;
189
+ const columnToDBTypeMap = await sqlQuery.execute(db);
190
+ const rows = columnToDBTypeMap.rows;
191
+ const columnData = {};
192
+ rows.forEach(row => {
193
+ const isEnum = ['USER-DEFINED', 'ARRAY'].includes(row.dataType) && !isPrimitiveDataType(row.udtName);
194
+ const isArray = ['ARRAY'].includes(row.dataType);
195
+ const associationMetadata = associationData[row.columnName];
196
+ columnData[camelize(row.columnName)] = {
197
+ dbType: row.udtName,
198
+ allowNull: row.isNullable === 'YES',
199
+ enumType: isEnum ? this.enumType(row) : null,
200
+ enumValues: isEnum ? `${this.enumType(row)}Values` : null,
201
+ isArray,
202
+ foreignKey: associationMetadata?.foreignKey || null,
203
+ };
204
+ });
205
+ return Object.keys(columnData)
206
+ .sort()
207
+ .reduce((acc, key) => {
208
+ acc[key] = columnData[key];
209
+ return acc;
210
+ }, {});
211
+ }
212
+ enumType(row) {
213
+ const enumName = pascalize(row.udtName.replace(/\[\]$/, ''));
214
+ return enumName;
215
+ }
216
+ getVirtualColumns(tableName) {
217
+ const dreamApp = DreamApplication.getOrFail();
218
+ const models = sortBy(Object.values(dreamApp.models), m => m.table);
219
+ const model = models.find(model => model.table === tableName);
220
+ return model?.['virtualAttributes']?.map(prop => prop.property) || [];
221
+ }
222
+ async getSchemaData() {
223
+ const tables = await this.getTables();
224
+ const schemaData = {};
225
+ for (const table of tables) {
226
+ schemaData[table] = await this.tableData(table);
227
+ }
228
+ return schemaData;
229
+ }
230
+ getAssociationData(tableName, targetAssociationType) {
231
+ const dreamApp = DreamApplication.getOrFail();
232
+ const models = sortBy(Object.values(dreamApp.models), m => m.table);
233
+ const tableAssociationData = {};
234
+ for (const model of models.filter(model => model.table === tableName)) {
235
+ for (const associationName of model.associationNames) {
236
+ const associationMetaData = model['associationMetadataMap']()[associationName];
237
+ if (targetAssociationType && associationMetaData.type !== targetAssociationType)
238
+ continue;
239
+ const dreamClassOrClasses = associationMetaData.modelCB();
240
+ if (!dreamClassOrClasses)
241
+ throw new FailedToIdentifyAssociation(model, associationMetaData.type, associationName, associationMetaData.globalAssociationNameOrNames);
242
+ const optional = associationMetaData.type === 'BelongsTo' ? associationMetaData.optional === true : null;
243
+ const where = associationMetaData.type === 'HasMany' || associationMetaData.type === 'HasOne'
244
+ ? associationMetaData.on || null
245
+ : null;
246
+ // NOTE
247
+ // this try-catch is here because the SchemaBuilder currently needs to be run twice to generate foreignKey
248
+ // correctly. The first time will raise, since calling Dream.columns is dependant on the schema const to
249
+ // introspect columns during a foreign key check. This will be repaired once kysely types have been successfully
250
+ // split off into a separate file from the types we diliver in types/dream.ts
251
+ let foreignKey = null;
252
+ try {
253
+ const _foreignKey = associationMetaData.foreignKey();
254
+ foreignKey = _foreignKey;
255
+ }
256
+ catch {
257
+ // noop
258
+ }
259
+ tableAssociationData[associationName] ||= {
260
+ tables: [],
261
+ type: associationMetaData.type,
262
+ polymorphic: associationMetaData.polymorphic,
263
+ foreignKey,
264
+ optional,
265
+ where,
266
+ };
267
+ if (foreignKey)
268
+ tableAssociationData[associationName]['foreignKey'] = foreignKey;
269
+ if (Array.isArray(dreamClassOrClasses)) {
270
+ const tables = dreamClassOrClasses.map(dreamClass => dreamClass.table);
271
+ tableAssociationData[associationName].tables = [
272
+ ...tableAssociationData[associationName].tables,
273
+ ...tables,
274
+ ];
275
+ }
276
+ else {
277
+ tableAssociationData[associationName].tables.push(dreamClassOrClasses.table);
278
+ }
279
+ // guarantee unique
280
+ tableAssociationData[associationName].tables = [
281
+ ...new Set(tableAssociationData[associationName].tables),
282
+ ];
283
+ }
284
+ }
285
+ return Object.keys(tableAssociationData)
286
+ .sort()
287
+ .reduce((acc, key) => {
288
+ acc[key] = tableAssociationData[key];
289
+ return acc;
290
+ }, {});
291
+ }
292
+ async getExportedModulesFromDbSync() {
293
+ const fileContents = await this.loadDbSyncFile();
294
+ const exportedConsts = [...fileContents.matchAll(/export\s+const\s+([a-zA-Z0-9_]+)/g)].map(res => res[1]);
295
+ const exportedTypes = [...fileContents.matchAll(/export\s+type\s+([a-zA-Z0-9_]+)/g)].map(res => res[1]);
296
+ const exportedInterfaces = [...fileContents.matchAll(/export\s+interface\s+([a-zA-Z0-9_]+)/g)].map(res => res[1]);
297
+ const allExports = [...exportedConsts, ...exportedTypes, ...exportedInterfaces];
298
+ return allExports;
299
+ }
300
+ async getTables() {
301
+ const fileContents = await this.loadDbSyncFile();
302
+ const tableLines = /export interface DB {([^}]*)}/.exec(fileContents)[1];
303
+ const tables = tableLines
304
+ .split('\n')
305
+ .map(line => line.split(':')[0].replace(/\s*/, ''))
306
+ .filter(line => !!line);
307
+ return tables;
308
+ }
309
+ kyselyType(tableName, columnName, fileContents) {
310
+ const tableLines = /export interface DB {([^}]*)}/.exec(fileContents)[1];
311
+ const interfaceName = tableLines
312
+ .split('\n')
313
+ .filter(line => !!line)
314
+ .filter(line => new RegExp(`^ ${tableName}:`).test(line))[0]
315
+ .split(':')[1]
316
+ ?.replace(/[\s;]*/g, '');
317
+ const interfaceLines = new RegExp(`export interface ${interfaceName} {([^}]*)}`).exec(fileContents)[1];
318
+ const kyselyType = interfaceLines
319
+ .split('\n')
320
+ .filter(line => !!line)
321
+ .filter(line => new RegExp(` ${columnName}:`).test(line))[0]
322
+ .split(':')[1]
323
+ ?.replace(/[\s;]*/g, '');
324
+ return kyselyType;
325
+ }
326
+ coercedType(kyselyType, dbType) {
327
+ const postfix = /\[\]$/.test(dbType) ? '[]' : '';
328
+ return kyselyType
329
+ .replace(/\s/g, '')
330
+ .replace(/Generated<(.*)>/g, '$1')
331
+ .replace(/ArrayType<(.*)>/g, '$1[]')
332
+ .split('|')
333
+ .map(individualType => {
334
+ switch (individualType) {
335
+ case 'Numeric':
336
+ case 'Numeric[]':
337
+ return `number${postfix}`;
338
+ case 'Timestamp':
339
+ case 'Timestamp[]':
340
+ return /^date[[\]]*$/.test(dbType) ? `CalendarDate${postfix}` : `DateTime${postfix}`;
341
+ case 'Int8':
342
+ case 'Int8[]':
343
+ return `IdType${postfix}`;
344
+ default:
345
+ return individualType;
346
+ }
347
+ })
348
+ .join(' | ');
349
+ }
350
+ async loadDbSyncFile() {
351
+ const dreamApp = DreamApplication.getOrFail();
352
+ const dbSyncPath = path.join(dreamApp.projectRoot, dreamApp.paths.types, 'db.ts');
353
+ return (await fs.readFile(dbSyncPath)).toString();
354
+ }
355
+ }
356
+ function stringifyArray(arr = [], { indent } = {}) {
357
+ if (indent && arr.length > 3) {
358
+ let spaces = '';
359
+ for (let i = 0; i < indent; i++) {
360
+ spaces = `${spaces} `;
361
+ }
362
+ return `[
363
+ ${spaces}${[...arr]
364
+ .sort()
365
+ .map(val => `'${val}'`)
366
+ .join(`,\n${spaces}`)}
367
+ ${spaces.replace(/\s{2}$/, '')}]`;
368
+ }
369
+ else {
370
+ return `[${[...arr]
371
+ .sort()
372
+ .map(val => `'${val}'`)
373
+ .join(', ')}]`;
374
+ }
375
+ }
@@ -0,0 +1,45 @@
1
+ import * as fs from 'fs/promises';
2
+ import dreamFileAndDirPaths from '../path/dreamFileAndDirPaths.js';
3
+ import dreamPath from '../path/dreamPath.js';
4
+ import standardizeFullyQualifiedModelName from '../standardizeFullyQualifiedModelName.js';
5
+ import generateDreamContent from './generateDreamContent.js';
6
+ import generateFactory from './generateFactory.js';
7
+ import generateMigration from './generateMigration.js';
8
+ import generateSerializer from './generateSerializer.js';
9
+ import generateUnitSpec from './generateUnitSpec.js';
10
+ export default async function generateDream({ fullyQualifiedModelName, columnsWithTypes, options, fullyQualifiedParentName, }) {
11
+ fullyQualifiedModelName = standardizeFullyQualifiedModelName(fullyQualifiedModelName);
12
+ const { relFilePath, absDirPath, absFilePath } = dreamFileAndDirPaths(dreamPath('models'), `${fullyQualifiedModelName}.ts`);
13
+ try {
14
+ console.log(`generating dream: ${relFilePath}`);
15
+ await fs.mkdir(absDirPath, { recursive: true });
16
+ await fs.writeFile(absFilePath, generateDreamContent({
17
+ fullyQualifiedModelName,
18
+ columnsWithTypes,
19
+ fullyQualifiedParentName,
20
+ serializer: options.serializer,
21
+ }));
22
+ }
23
+ catch (error) {
24
+ throw new Error(`
25
+ Something happened while trying to create the Dream file:
26
+ ${relFilePath}
27
+
28
+ Does this file already exist? Here is the error that was raised:
29
+ ${error.message}
30
+ `);
31
+ }
32
+ await generateUnitSpec({ fullyQualifiedModelName });
33
+ await generateFactory({ fullyQualifiedModelName, columnsWithTypes });
34
+ if (options.serializer)
35
+ await generateSerializer({ fullyQualifiedModelName, columnsWithTypes, fullyQualifiedParentName });
36
+ const isSTI = !!fullyQualifiedParentName;
37
+ if (columnsWithTypes.length || !isSTI) {
38
+ await generateMigration({
39
+ migrationName: fullyQualifiedModelName,
40
+ columnsWithTypes,
41
+ fullyQualifiedModelName,
42
+ fullyQualifiedParentName,
43
+ });
44
+ }
45
+ }
@@ -0,0 +1,104 @@
1
+ import pluralize from 'pluralize-esm';
2
+ import camelize from '../camelize.js';
3
+ import globalClassNameFromFullyQualifiedModelName from '../globalClassNameFromFullyQualifiedModelName.js';
4
+ import relativeDreamPath from '../path/relativeDreamPath.js';
5
+ import serializerNameFromFullyQualifiedModelName from '../serializerNameFromFullyQualifiedModelName.js';
6
+ import snakeify from '../snakeify.js';
7
+ import standardizeFullyQualifiedModelName from '../standardizeFullyQualifiedModelName.js';
8
+ import uniq from '../uniq.js';
9
+ export default function generateDreamContent({ fullyQualifiedModelName, columnsWithTypes, fullyQualifiedParentName, serializer, }) {
10
+ fullyQualifiedModelName = standardizeFullyQualifiedModelName(fullyQualifiedModelName);
11
+ const modelClassName = globalClassNameFromFullyQualifiedModelName(fullyQualifiedModelName);
12
+ let parentModelClassName;
13
+ const dreamImports = ['Decorators', 'DreamColumn'];
14
+ if (serializer)
15
+ dreamImports.push('DreamSerializers');
16
+ const isSTI = !!fullyQualifiedParentName;
17
+ if (isSTI) {
18
+ fullyQualifiedParentName = standardizeFullyQualifiedModelName(fullyQualifiedParentName);
19
+ parentModelClassName = globalClassNameFromFullyQualifiedModelName(fullyQualifiedParentName);
20
+ dreamImports.push('STI');
21
+ }
22
+ const idTypescriptType = `DreamColumn<${modelClassName}, 'id'>`;
23
+ const modelImportStatements = isSTI
24
+ ? [importStatementForModel(fullyQualifiedModelName, fullyQualifiedParentName)]
25
+ : [importStatementForModel(fullyQualifiedModelName, 'ApplicationModel')];
26
+ const attributeStatements = columnsWithTypes.map(attribute => {
27
+ const [attributeName, attributeType, ...descriptors] = attribute.split(':');
28
+ const fullyQualifiedAssociatedModelName = standardizeFullyQualifiedModelName(attributeName);
29
+ const associationModelName = globalClassNameFromFullyQualifiedModelName(fullyQualifiedAssociatedModelName);
30
+ const associationImportStatement = importStatementForModel(fullyQualifiedModelName, fullyQualifiedAssociatedModelName);
31
+ const associationName = camelize(associationModelName);
32
+ if (!attributeType)
33
+ throw new Error(`must pass a column type for ${attributeName} (i.e. ${attributeName}:string)`);
34
+ switch (attributeType) {
35
+ case 'belongs_to':
36
+ modelImportStatements.push(associationImportStatement);
37
+ return `
38
+ @Deco.BelongsTo('${fullyQualifiedAssociatedModelName}'${descriptors.includes('optional') ? ', { optional: true }' : ''})
39
+ public ${associationName}: ${associationModelName}${descriptors.includes('optional') ? ' | null' : ''}
40
+ public ${associationName}Id: DreamColumn<${modelClassName}, '${associationName}Id'>
41
+ `;
42
+ case 'has_one':
43
+ case 'has_many':
44
+ return '';
45
+ case 'encrypted':
46
+ dreamImports.push('Encrypted');
47
+ return `
48
+ @Encrypted()
49
+ public ${camelize(attributeName)}: ${getAttributeType(attribute, modelClassName)}\
50
+ `;
51
+ default:
52
+ return `
53
+ public ${camelize(attributeName)}: ${getAttributeType(attribute, modelClassName)}\
54
+ `;
55
+ }
56
+ });
57
+ const formattedFields = attributeStatements
58
+ .filter(attr => !/^\n@/.test(attr))
59
+ .map(s => s.split('\n').join('\n '))
60
+ .join('');
61
+ const formattedDecorators = attributeStatements
62
+ .filter(attr => /^\n@/.test(attr))
63
+ .map(s => s.split('\n').join('\n '))
64
+ .join('\n ')
65
+ .replace(/\n {2}$/, '');
66
+ let timestamps = `
67
+ public createdAt: DreamColumn<${modelClassName}, 'createdAt'>
68
+ public updatedAt: DreamColumn<${modelClassName}, 'updatedAt'>
69
+ `;
70
+ if (!formattedDecorators.length)
71
+ timestamps = timestamps.replace(/\n$/, '');
72
+ const tableName = snakeify(pluralize(fullyQualifiedModelName.replace(/\//g, '_')));
73
+ return `\
74
+ import { ${uniq(dreamImports).join(', ')} } from '@rvohealth/dream'${uniq(modelImportStatements).join('')}
75
+
76
+ const Deco = new Decorators<InstanceType<typeof ${modelClassName}>>()
77
+
78
+ ${isSTI ? `\n@STI(${parentModelClassName})` : ''}
79
+ export default class ${modelClassName} extends ${isSTI ? parentModelClassName : 'ApplicationModel'} {
80
+ ${isSTI
81
+ ? ''
82
+ : ` public get table() {
83
+ return '${tableName}' as const
84
+ }
85
+
86
+ `}${serializer
87
+ ? ` public get serializers(): DreamSerializers<${modelClassName}> {
88
+ return {
89
+ default: '${serializerNameFromFullyQualifiedModelName(fullyQualifiedModelName)}',
90
+ summary: '${serializerNameFromFullyQualifiedModelName(fullyQualifiedModelName, 'summary')}',
91
+ }
92
+ }
93
+
94
+ `
95
+ : ''}${isSTI ? formattedFields : ` public id: ${idTypescriptType}${formattedFields}${timestamps}`}${formattedDecorators}
96
+ }
97
+ `.replace(/^\s*$/gm, '');
98
+ }
99
+ function getAttributeType(attribute, modelClassName) {
100
+ return `DreamColumn<${modelClassName}, '${camelize(attribute.split(':')[0])}'>`;
101
+ }
102
+ function importStatementForModel(originModelName, destinationModelName = originModelName) {
103
+ return `\nimport ${globalClassNameFromFullyQualifiedModelName(destinationModelName)} from '${relativeDreamPath('models', 'models', originModelName, destinationModelName)}'`;
104
+ }
@@ -0,0 +1,23 @@
1
+ import * as fs from 'fs/promises';
2
+ import dreamFileAndDirPaths from '../path/dreamFileAndDirPaths.js';
3
+ import dreamPath from '../path/dreamPath.js';
4
+ import standardizeFullyQualifiedModelName from '../standardizeFullyQualifiedModelName.js';
5
+ import generateFactoryContent from './generateFactoryContent.js';
6
+ export default async function generateFactory({ fullyQualifiedModelName, columnsWithTypes, }) {
7
+ fullyQualifiedModelName = standardizeFullyQualifiedModelName(fullyQualifiedModelName);
8
+ const { relFilePath, absDirPath, absFilePath } = dreamFileAndDirPaths(dreamPath('factories'), `${fullyQualifiedModelName}Factory.ts`);
9
+ try {
10
+ console.log(`generating factory: ${relFilePath}`);
11
+ await fs.mkdir(absDirPath, { recursive: true });
12
+ await fs.writeFile(absFilePath, generateFactoryContent({ fullyQualifiedModelName, columnsWithTypes }));
13
+ }
14
+ catch (error) {
15
+ throw new Error(`
16
+ Something happened while trying to create the spec file:
17
+ ${relFilePath}
18
+
19
+ Does this file already exist? Here is the error that was raised:
20
+ ${error.message}
21
+ `);
22
+ }
23
+ }
@@ -0,0 +1,55 @@
1
+ import camelize from '../camelize.js';
2
+ import globalClassNameFromFullyQualifiedModelName from '../globalClassNameFromFullyQualifiedModelName.js';
3
+ import relativeDreamPath from '../path/relativeDreamPath.js';
4
+ import standardizeFullyQualifiedModelName from '../standardizeFullyQualifiedModelName.js';
5
+ import uniq from '../uniq.js';
6
+ export default function generateFactoryContent({ fullyQualifiedModelName, columnsWithTypes, }) {
7
+ fullyQualifiedModelName = standardizeFullyQualifiedModelName(fullyQualifiedModelName);
8
+ const dreamImports = ['UpdateableProperties'];
9
+ const additionalImports = [];
10
+ const belongsToNames = [];
11
+ const belongsToTypedNames = [];
12
+ const associationCreationStatements = [];
13
+ const stringAttributes = [];
14
+ let firstStringAttr = true;
15
+ for (const attribute of columnsWithTypes) {
16
+ const [attributeName, attributeType, ...descriptors] = attribute.split(':');
17
+ const fullyQualifiedAssociatedModelName = standardizeFullyQualifiedModelName(attributeName);
18
+ const associationModelName = globalClassNameFromFullyQualifiedModelName(fullyQualifiedAssociatedModelName);
19
+ const associationFactoryImportStatement = `import create${associationModelName} from '${relativeDreamPath('factories', 'factories', fullyQualifiedModelName, fullyQualifiedAssociatedModelName)}'`;
20
+ const associationName = camelize(associationModelName);
21
+ if (/_type$/.test(attributeName))
22
+ continue;
23
+ if (!attributeType)
24
+ throw new Error(`Must pass a column type for ${fullyQualifiedAssociatedModelName} (i.e. ${fullyQualifiedAssociatedModelName}:string)`);
25
+ switch (attributeType) {
26
+ case 'belongs_to':
27
+ belongsToNames.push(associationName);
28
+ belongsToTypedNames.push(`${associationName}: ${associationModelName}`);
29
+ additionalImports.push(associationFactoryImportStatement);
30
+ associationCreationStatements.push(`attrs.${associationName} ||= await create${associationModelName}()`);
31
+ break;
32
+ case 'string':
33
+ case 'text':
34
+ case 'citext':
35
+ stringAttributes.push(`attrs.${camelize(attributeName)} ||= \`${fullyQualifiedModelName} ${camelize(attributeName)} ${firstStringAttr ? '${++counter}' : '${counter}'}\``);
36
+ firstStringAttr = false;
37
+ break;
38
+ case 'enum':
39
+ stringAttributes.push(`attrs.${camelize(attributeName)} ||= '${(descriptors[descriptors.length - 1] || '<tbd>').split(',')[0]}'`);
40
+ break;
41
+ default:
42
+ // noop
43
+ }
44
+ }
45
+ const relativePath = relativeDreamPath('factories', 'models', fullyQualifiedModelName);
46
+ const modelClassName = globalClassNameFromFullyQualifiedModelName(fullyQualifiedModelName);
47
+ return `\
48
+ import { ${uniq(dreamImports).join(', ')} } from '@rvohealth/dream'
49
+ import ${modelClassName} from '${relativePath}'${additionalImports.length ? '\n' + uniq(additionalImports).join('\n') : ''}
50
+ ${stringAttributes.length ? '\nlet counter = 0\n' : ''}
51
+ export default async function create${modelClassName}(attrs: UpdateableProperties<${modelClassName}> = {}) {
52
+ ${associationCreationStatements.length ? associationCreationStatements.join('\n ') + '\n ' : ''}${stringAttributes.length ? stringAttributes.join('\n ') + '\n ' : ''}return await ${modelClassName}.create(attrs)
53
+ }
54
+ `;
55
+ }
@@ -0,0 +1,53 @@
1
+ import * as fs from 'fs/promises';
2
+ import * as path from 'path';
3
+ import pluralize from 'pluralize-esm';
4
+ import generateMigrationContent from '../cli/generateMigrationContent.js';
5
+ import primaryKeyType from '../db/primaryKeyType.js';
6
+ import hyphenize from '../hyphenize.js';
7
+ import migrationVersion from '../migrationVersion.js';
8
+ import pascalizePath from '../pascalizePath.js';
9
+ import dreamFileAndDirPaths from '../path/dreamFileAndDirPaths.js';
10
+ import dreamPath from '../path/dreamPath.js';
11
+ import snakeify from '../snakeify.js';
12
+ import generateStiMigrationContent from './generateStiMigrationContent.js';
13
+ export default async function generateMigration({ migrationName, columnsWithTypes, fullyQualifiedModelName, fullyQualifiedParentName, }) {
14
+ const { relFilePath, absFilePath } = dreamFileAndDirPaths(path.join(dreamPath('db'), 'migrations'), `${migrationVersion()}-${hyphenize(migrationName).replace(/\//g, '-')}.ts`);
15
+ const isSTI = !!fullyQualifiedParentName;
16
+ let finalContent = '';
17
+ if (isSTI) {
18
+ finalContent = generateStiMigrationContent({
19
+ table: snakeify(pluralize(pascalizePath(fullyQualifiedParentName))),
20
+ columnsWithTypes,
21
+ primaryKeyType: primaryKeyType(),
22
+ });
23
+ }
24
+ else if (fullyQualifiedModelName) {
25
+ finalContent = generateMigrationContent({
26
+ table: snakeify(pluralize(pascalizePath(fullyQualifiedModelName))),
27
+ columnsWithTypes,
28
+ primaryKeyType: primaryKeyType(),
29
+ });
30
+ }
31
+ else {
32
+ const tableName = migrationName.match(/-to-(.+)$/)?.[1];
33
+ finalContent = generateMigrationContent({
34
+ table: tableName ? pluralize(snakeify(tableName)) : '<table-name>',
35
+ columnsWithTypes,
36
+ primaryKeyType: primaryKeyType(),
37
+ createOrAlter: 'alter',
38
+ });
39
+ }
40
+ try {
41
+ console.log(`generating migration: ${relFilePath}`);
42
+ await fs.writeFile(absFilePath, finalContent);
43
+ }
44
+ catch (error) {
45
+ throw new Error(`
46
+ Something happened while trying to create the migration file:
47
+ ${relFilePath}
48
+
49
+ Does this file already exist? Here is the error that was raised:
50
+ ${error.message}
51
+ `);
52
+ }
53
+ }