@rvoh/dream 1.2.1 → 1.3.0

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 (198) hide show
  1. package/dist/cjs/src/Dream.js +99 -31
  2. package/dist/cjs/src/dream/QueryDriver/Kysely.js +20 -19
  3. package/dist/cjs/src/dream/internal/printSerializerHierarchyLevel.js +17 -0
  4. package/dist/cjs/src/dream-app/cache.js +12 -2
  5. package/dist/cjs/src/helpers/cli/generateMigration.js +1 -0
  6. package/dist/cjs/src/helpers/cli/generateMigrationContent.js +20 -5
  7. package/dist/cjs/src/helpers/cli/generateStiMigrationContent.js +8 -2
  8. package/dist/cjs/src/serializer/helpers/serializerForAssociatedClass.js +3 -2
  9. package/dist/esm/src/Dream.js +99 -31
  10. package/dist/esm/src/dream/QueryDriver/Kysely.js +20 -19
  11. package/dist/esm/src/dream/internal/printSerializerHierarchyLevel.js +14 -0
  12. package/dist/esm/src/dream-app/cache.js +12 -2
  13. package/dist/esm/src/helpers/cli/generateMigration.js +1 -0
  14. package/dist/esm/src/helpers/cli/generateMigrationContent.js +20 -5
  15. package/dist/esm/src/helpers/cli/generateStiMigrationContent.js +8 -2
  16. package/dist/esm/src/serializer/helpers/serializerForAssociatedClass.js +3 -2
  17. package/dist/types/src/Dream.d.ts +77 -52
  18. package/dist/types/src/dream/QueryDriver/Kysely.d.ts +1 -0
  19. package/dist/types/src/dream/internal/printSerializerHierarchyLevel.d.ts +7 -0
  20. package/dist/types/src/helpers/cli/generateMigrationContent.d.ts +2 -1
  21. package/dist/types/src/helpers/cli/generateStiMigrationContent.d.ts +2 -1
  22. package/dist/types/src/serializer/builders/DreamSerializerBuilder.d.ts +1 -1
  23. package/dist/types/src/types/dream.d.ts +1 -1
  24. package/dist/types/src/types/dream.ts +2 -2
  25. package/docs/assets/search.js +1 -1
  26. package/docs/classes/Benchmark.html +2 -2
  27. package/docs/classes/CalendarDate.html +2 -2
  28. package/docs/classes/CliFileWriter.html +2 -2
  29. package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +3 -3
  30. package/docs/classes/DataTypeColumnTypeMismatch.html +3 -3
  31. package/docs/classes/Decorators.html +19 -19
  32. package/docs/classes/Dream.html +209 -308
  33. package/docs/classes/DreamApp.html +4 -4
  34. package/docs/classes/DreamBin.html +2 -2
  35. package/docs/classes/DreamCLI.html +4 -4
  36. package/docs/classes/DreamImporter.html +2 -2
  37. package/docs/classes/DreamLogos.html +2 -2
  38. package/docs/classes/DreamMigrationHelpers.html +7 -7
  39. package/docs/classes/DreamSerializerBuilder.html +8 -8
  40. package/docs/classes/DreamTransaction.html +2 -2
  41. package/docs/classes/Encrypt.html +2 -2
  42. package/docs/classes/Env.html +2 -2
  43. package/docs/classes/GlobalNameNotSet.html +3 -3
  44. package/docs/classes/NonLoadedAssociation.html +3 -3
  45. package/docs/classes/ObjectSerializerBuilder.html +8 -8
  46. package/docs/classes/Query.html +60 -60
  47. package/docs/classes/Range.html +2 -2
  48. package/docs/classes/RecordNotFound.html +3 -3
  49. package/docs/classes/ValidationError.html +3 -3
  50. package/docs/functions/DreamSerializer.html +1 -1
  51. package/docs/functions/ObjectSerializer.html +1 -1
  52. package/docs/functions/ReplicaSafe.html +1 -1
  53. package/docs/functions/STI.html +1 -1
  54. package/docs/functions/SoftDelete.html +1 -1
  55. package/docs/functions/camelize.html +1 -1
  56. package/docs/functions/capitalize.html +1 -1
  57. package/docs/functions/cloneDeepSafe.html +1 -1
  58. package/docs/functions/closeAllDbConnections.html +1 -1
  59. package/docs/functions/compact.html +1 -1
  60. package/docs/functions/dreamDbConnections.html +1 -1
  61. package/docs/functions/dreamPath.html +1 -1
  62. package/docs/functions/expandStiClasses.html +1 -1
  63. package/docs/functions/generateDream.html +1 -1
  64. package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -1
  65. package/docs/functions/groupBy.html +1 -1
  66. package/docs/functions/hyphenize.html +1 -1
  67. package/docs/functions/inferSerializerFromDreamOrViewModel.html +1 -1
  68. package/docs/functions/inferSerializersFromDreamClassOrViewModelClass.html +1 -1
  69. package/docs/functions/intersection.html +1 -1
  70. package/docs/functions/isDreamSerializer.html +1 -1
  71. package/docs/functions/isEmpty.html +1 -1
  72. package/docs/functions/loadRepl.html +1 -1
  73. package/docs/functions/lookupClassByGlobalName.html +1 -1
  74. package/docs/functions/normalizeUnicode.html +1 -1
  75. package/docs/functions/pascalize.html +1 -1
  76. package/docs/functions/pgErrorType.html +1 -1
  77. package/docs/functions/range-1.html +1 -1
  78. package/docs/functions/relativeDreamPath.html +1 -1
  79. package/docs/functions/round.html +1 -1
  80. package/docs/functions/serializerNameFromFullyQualifiedModelName.html +1 -1
  81. package/docs/functions/sharedPathPrefix.html +1 -1
  82. package/docs/functions/snakeify.html +1 -1
  83. package/docs/functions/sort.html +1 -1
  84. package/docs/functions/sortBy.html +1 -1
  85. package/docs/functions/sortObjectByKey.html +1 -1
  86. package/docs/functions/sortObjectByValue.html +1 -1
  87. package/docs/functions/standardizeFullyQualifiedModelName.html +1 -1
  88. package/docs/functions/uncapitalize.html +1 -1
  89. package/docs/functions/uniq.html +1 -1
  90. package/docs/functions/untypedDb.html +1 -1
  91. package/docs/functions/validateColumn.html +1 -1
  92. package/docs/functions/validateTable.html +1 -1
  93. package/docs/interfaces/BelongsToStatement.html +2 -2
  94. package/docs/interfaces/DecoratorContext.html +2 -2
  95. package/docs/interfaces/DreamAppInitOptions.html +2 -2
  96. package/docs/interfaces/DreamAppOpts.html +2 -2
  97. package/docs/interfaces/EncryptOptions.html +2 -2
  98. package/docs/interfaces/InternalAnyTypedSerializerRendersMany.html +2 -2
  99. package/docs/interfaces/InternalAnyTypedSerializerRendersOne.html +2 -2
  100. package/docs/interfaces/OpenapiDescription.html +2 -2
  101. package/docs/interfaces/OpenapiSchemaProperties.html +1 -1
  102. package/docs/interfaces/OpenapiSchemaPropertiesShorthand.html +1 -1
  103. package/docs/interfaces/OpenapiTypeFieldObject.html +1 -1
  104. package/docs/interfaces/SerializerRendererOpts.html +2 -2
  105. package/docs/types/Camelized.html +1 -1
  106. package/docs/types/CommonOpenapiSchemaObjectFields.html +1 -1
  107. package/docs/types/DateTime.html +1 -1
  108. package/docs/types/DbConnectionType.html +1 -1
  109. package/docs/types/DbTypes.html +1 -1
  110. package/docs/types/DreamAppAllowedPackageManagersEnum.html +1 -1
  111. package/docs/types/DreamAssociationMetadata.html +1 -1
  112. package/docs/types/DreamAttributes.html +1 -1
  113. package/docs/types/DreamClassAssociationAndStatement.html +1 -1
  114. package/docs/types/DreamClassColumn.html +1 -1
  115. package/docs/types/DreamColumn.html +1 -1
  116. package/docs/types/DreamColumnNames.html +1 -1
  117. package/docs/types/DreamLogLevel.html +1 -1
  118. package/docs/types/DreamLogger.html +1 -1
  119. package/docs/types/DreamModelSerializerType.html +1 -1
  120. package/docs/types/DreamOrViewModelClassSerializerKey.html +1 -1
  121. package/docs/types/DreamOrViewModelSerializerKey.html +1 -1
  122. package/docs/types/DreamParamSafeAttributes.html +1 -1
  123. package/docs/types/DreamParamSafeColumnNames.html +1 -1
  124. package/docs/types/DreamSerializable.html +1 -1
  125. package/docs/types/DreamSerializableArray.html +1 -1
  126. package/docs/types/DreamSerializerKey.html +1 -1
  127. package/docs/types/DreamSerializers.html +1 -1
  128. package/docs/types/DreamTableSchema.html +1 -1
  129. package/docs/types/DreamVirtualColumns.html +1 -1
  130. package/docs/types/EncryptAlgorithm.html +1 -1
  131. package/docs/types/HasManyStatement.html +1 -1
  132. package/docs/types/HasOneStatement.html +1 -1
  133. package/docs/types/Hyphenized.html +1 -1
  134. package/docs/types/IdType.html +1 -1
  135. package/docs/types/OpenapiAllTypes.html +1 -1
  136. package/docs/types/OpenapiFormats.html +1 -1
  137. package/docs/types/OpenapiNumberFormats.html +1 -1
  138. package/docs/types/OpenapiPrimitiveBaseTypes.html +1 -1
  139. package/docs/types/OpenapiPrimitiveTypes.html +1 -1
  140. package/docs/types/OpenapiSchemaArray.html +1 -1
  141. package/docs/types/OpenapiSchemaArrayShorthand.html +1 -1
  142. package/docs/types/OpenapiSchemaBase.html +1 -1
  143. package/docs/types/OpenapiSchemaBody.html +1 -1
  144. package/docs/types/OpenapiSchemaBodyShorthand.html +1 -1
  145. package/docs/types/OpenapiSchemaCommonFields.html +1 -1
  146. package/docs/types/OpenapiSchemaExpressionAllOf.html +1 -1
  147. package/docs/types/OpenapiSchemaExpressionAnyOf.html +1 -1
  148. package/docs/types/OpenapiSchemaExpressionOneOf.html +1 -1
  149. package/docs/types/OpenapiSchemaExpressionRef.html +1 -1
  150. package/docs/types/OpenapiSchemaExpressionRefSchemaShorthand.html +1 -1
  151. package/docs/types/OpenapiSchemaInteger.html +1 -1
  152. package/docs/types/OpenapiSchemaNull.html +1 -1
  153. package/docs/types/OpenapiSchemaNumber.html +1 -1
  154. package/docs/types/OpenapiSchemaObject.html +1 -1
  155. package/docs/types/OpenapiSchemaObjectAllOf.html +1 -1
  156. package/docs/types/OpenapiSchemaObjectAllOfShorthand.html +1 -1
  157. package/docs/types/OpenapiSchemaObjectAnyOf.html +1 -1
  158. package/docs/types/OpenapiSchemaObjectAnyOfShorthand.html +1 -1
  159. package/docs/types/OpenapiSchemaObjectBase.html +1 -1
  160. package/docs/types/OpenapiSchemaObjectBaseShorthand.html +1 -1
  161. package/docs/types/OpenapiSchemaObjectOneOf.html +1 -1
  162. package/docs/types/OpenapiSchemaObjectOneOfShorthand.html +1 -1
  163. package/docs/types/OpenapiSchemaObjectShorthand.html +1 -1
  164. package/docs/types/OpenapiSchemaPrimitiveGeneric.html +1 -1
  165. package/docs/types/OpenapiSchemaShorthandExpressionAllOf.html +1 -1
  166. package/docs/types/OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
  167. package/docs/types/OpenapiSchemaShorthandExpressionOneOf.html +1 -1
  168. package/docs/types/OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
  169. package/docs/types/OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
  170. package/docs/types/OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
  171. package/docs/types/OpenapiSchemaString.html +1 -1
  172. package/docs/types/OpenapiShorthandAllTypes.html +1 -1
  173. package/docs/types/OpenapiShorthandPrimitiveBaseTypes.html +1 -1
  174. package/docs/types/OpenapiShorthandPrimitiveTypes.html +1 -1
  175. package/docs/types/OpenapiTypeField.html +1 -1
  176. package/docs/types/Pascalized.html +1 -1
  177. package/docs/types/PrimaryKeyType.html +1 -1
  178. package/docs/types/RoundingPrecision.html +1 -1
  179. package/docs/types/SerializerCasing.html +1 -1
  180. package/docs/types/SimpleObjectSerializerType.html +1 -1
  181. package/docs/types/Snakeified.html +1 -1
  182. package/docs/types/Timestamp.html +1 -1
  183. package/docs/types/UpdateableAssociationProperties.html +1 -1
  184. package/docs/types/UpdateableProperties.html +1 -1
  185. package/docs/types/ValidationType.html +1 -1
  186. package/docs/types/ViewModel.html +1 -1
  187. package/docs/types/ViewModelClass.html +1 -1
  188. package/docs/types/WhereStatementForDream.html +1 -1
  189. package/docs/types/WhereStatementForDreamClass.html +1 -1
  190. package/docs/variables/DateTime-1.html +1 -1
  191. package/docs/variables/DreamAppAllowedPackageManagersEnumValues.html +1 -1
  192. package/docs/variables/DreamConst.html +1 -1
  193. package/docs/variables/TRIGRAM_OPERATORS.html +1 -1
  194. package/docs/variables/openapiPrimitiveTypes-1.html +1 -1
  195. package/docs/variables/openapiShorthandPrimitiveTypes-1.html +1 -1
  196. package/docs/variables/ops.html +1 -1
  197. package/docs/variables/primaryKeyTypes.html +1 -1
  198. package/package.json +1 -1
@@ -31,6 +31,7 @@ import _dropDb from '../../helpers/db/dropDb.js';
31
31
  import loadPgClient from '../../helpers/db/loadPgClient.js';
32
32
  import runMigration from '../../helpers/db/runMigration.js';
33
33
  import EnvInternal from '../../helpers/EnvInternal.js';
34
+ import groupBy from '../../helpers/groupBy.js';
34
35
  import isEmpty from '../../helpers/isEmpty.js';
35
36
  import namespaceColumn from '../../helpers/namespaceColumn.js';
36
37
  import normalizeUnicode from '../../helpers/normalizeUnicode.js';
@@ -1202,7 +1203,7 @@ export default class KyselyQueryDriver extends QueryDriverBase {
1202
1203
  const keys = Object.keys(preloadStatement);
1203
1204
  for (const key of keys) {
1204
1205
  const nestedDreams = await this.applyOnePreload(key, dream, this.applyablePreloadOnStatements(preloadOnStatements[key]));
1205
- if (nestedDreams) {
1206
+ if (nestedDreams.length) {
1206
1207
  await this.applyPreload(preloadStatement[key], preloadOnStatements[key], nestedDreams);
1207
1208
  }
1208
1209
  }
@@ -1697,18 +1698,10 @@ export default class KyselyQueryDriver extends QueryDriverBase {
1697
1698
  *
1698
1699
  * Used to preload polymorphic belongs to associations
1699
1700
  */
1700
- async preloadPolymorphicBelongsTo(association, dreams) {
1701
- if (!association.polymorphic)
1702
- throw new Error(`Association ${association.as} points to an array of models but is not designated polymorphic`);
1703
- if (association.type !== 'BelongsTo')
1704
- throw new Error(`Polymorphic association ${association.as} points to an array of models but is ${association.type}. Only BelongsTo associations may point to an array of models.`);
1705
- const nestedDreamsForNextRoundOfPreloading = [];
1706
- for (const associatedModel of association.modelCB()) {
1707
- await this.preloadPolymorphicAssociationModel(dreams, association, associatedModel, nestedDreamsForNextRoundOfPreloading);
1708
- }
1709
- return nestedDreamsForNextRoundOfPreloading;
1701
+ async preloadPolymorphicBelongsTo(association, associatedModels, dreams) {
1702
+ return compact(await Promise.all(associatedModels.map(associatedModel => this.preloadPolymorphicAssociationModel(dreams, association, associatedModel)))).flat();
1710
1703
  }
1711
- async preloadPolymorphicAssociationModel(dreams, association, associatedDreamClass, nestedDreamsForNextRoundOfPreloading) {
1704
+ async preloadPolymorphicAssociationModel(dreams, association, associatedDreamClass) {
1712
1705
  const relevantAssociatedModels = dreams.filter((dream) => {
1713
1706
  const field = association.foreignKeyTypeField();
1714
1707
  return dream[field] === associatedDreamClass['stiBaseClassOrOwnClassName'] || dream[field] === null;
@@ -1727,7 +1720,6 @@ export default class KyselyQueryDriver extends QueryDriverBase {
1727
1720
  [associatedDreamClass.primaryKey]: relevantAssociatedModels.map((dream) => dream[association.foreignKey()]),
1728
1721
  })
1729
1722
  .all();
1730
- loadedAssociations.forEach((loadedAssociation) => nestedDreamsForNextRoundOfPreloading.push(loadedAssociation));
1731
1723
  //////////////////////////////////////////////////////////////////////////////////////////////
1732
1724
  // Associate each loaded association with each dream based on primary key and foreign key type
1733
1725
  //////////////////////////////////////////////////////////////////////////////////////////////
@@ -1742,6 +1734,7 @@ export default class KyselyQueryDriver extends QueryDriverBase {
1742
1734
  ///////////////////////////////////////////////////////////////////////////////////////////////////
1743
1735
  // end: Associate each loaded association with each dream based on primary key and foreign key type
1744
1736
  ///////////////////////////////////////////////////////////////////////////////////////////////////
1737
+ return loadedAssociations;
1745
1738
  }
1746
1739
  }
1747
1740
  /**
@@ -1780,12 +1773,18 @@ export default class KyselyQueryDriver extends QueryDriverBase {
1780
1773
  *
1781
1774
  * Applies a preload statement
1782
1775
  */
1783
- async applyOnePreload(associationName, dreams, onStatement = {}) {
1776
+ async applyOnePreload(associationNameAndMaybeAlias, dreams, onStatement = {}) {
1784
1777
  if (!Array.isArray(dreams))
1785
1778
  dreams = [dreams];
1786
- const dream = dreams.find(dream => dream['getAssociationMetadata'](associationName));
1787
- if (!dream)
1788
- return;
1779
+ const { name: associationName } = associationStringToNameAndAlias(associationNameAndMaybeAlias);
1780
+ dreams = dreams.filter(dream => dream.hasAssociation(associationName));
1781
+ const groupedDreams = groupBy(dreams, dream => dream.sanitizedConstructorName);
1782
+ return (await Promise.all(Object.keys(groupedDreams).map(key => this._applyOnePreload(associationName, groupedDreams[key], onStatement)))).flat();
1783
+ }
1784
+ async _applyOnePreload(associationName, dreams, onStatement = {}) {
1785
+ if (!dreams.length)
1786
+ return [];
1787
+ const dream = dreams[0];
1789
1788
  const { name, alias: _alias } = associationStringToNameAndAlias(associationName);
1790
1789
  const alias = _alias || name;
1791
1790
  const association = dream['getAssociationMetadata'](name);
@@ -1793,8 +1792,10 @@ export default class KyselyQueryDriver extends QueryDriverBase {
1793
1792
  throw new UnexpectedUndefined();
1794
1793
  const dreamClass = dream.constructor;
1795
1794
  const dreamClassToHydrate = association.modelCB();
1796
- if ((association.polymorphic && association.type === 'BelongsTo') || Array.isArray(dreamClassToHydrate))
1797
- return this.preloadPolymorphicBelongsTo(association, dreams);
1795
+ if (Array.isArray(dreamClassToHydrate)) {
1796
+ const preloadedPolymorphicBelongsTos = await this.preloadPolymorphicBelongsTo(association, dreamClassToHydrate, dreams);
1797
+ return preloadedPolymorphicBelongsTos;
1798
+ }
1798
1799
  const dreamClassToHydrateColumns = [...dreamClassToHydrate.columns()];
1799
1800
  const columnsToPluck = dreamClassToHydrateColumns.map(column => this.namespaceColumn(column.toString(), alias));
1800
1801
  columnsToPluck.push(this.namespaceColumn(dreamClass.primaryKey, dreamClass.table));
@@ -0,0 +1,14 @@
1
+ import yoctocolors from 'yoctocolors';
2
+ import { indent } from '../../helpers/indent.js';
3
+ export default function printSerializerHierarchyLevel({ serializerAssociationType, serializerAssociationName, associationSerializer, forDisplayDepth, }) {
4
+ const hierarchyLine = '└───';
5
+ const indentation = indent((hierarchyLine.length + 1) * forDisplayDepth, {
6
+ tabWidth: 1,
7
+ });
8
+ const prefix = `${hierarchyLine} `;
9
+ const nestedAssociationDisplay = indentation + `${prefix}${serializerAssociationType} ${yoctocolors.cyan(serializerAssociationName)}`;
10
+ console.log(nestedAssociationDisplay);
11
+ console.log(yoctocolors.gray(indentation +
12
+ indent(prefix.length, { tabWidth: 1 }) +
13
+ associationSerializer.globalName));
14
+ }
@@ -1,9 +1,19 @@
1
+ import EnvInternal from '../helpers/EnvInternal.js';
1
2
  let _dreamApp = undefined;
2
3
  export function cacheDreamApp(dreamconf) {
3
4
  _dreamApp = dreamconf;
4
5
  }
5
6
  export function getCachedDreamAppOrFail() {
6
- if (!_dreamApp)
7
- throw new Error('Must call `initializeDreamApp` or `initializePsychicApp` before loading cached DreamApp.getOrFail()');
7
+ if (!_dreamApp) {
8
+ const baseErrorMessage = 'Must call `initializeDreamApp` or `initializePsychicApp` before loading cached DreamApp.getOrFail().';
9
+ if (EnvInternal.isTest) {
10
+ throw new Error(`${baseErrorMessage}
11
+
12
+ Check for specs running directly in a \`describe\` or \`context\` block rather than nested within an \`it\` block.`);
13
+ }
14
+ else {
15
+ throw new Error(baseErrorMessage);
16
+ }
17
+ }
8
18
  return _dreamApp;
9
19
  }
@@ -19,6 +19,7 @@ export default async function generateMigration({ migrationName, columnsWithType
19
19
  table: snakeify(pluralize(pascalizePath(fullyQualifiedParentName))),
20
20
  columnsWithTypes,
21
21
  primaryKeyType: primaryKeyType(),
22
+ stiChildClassName: pascalizePath(fullyQualifiedModelName),
22
23
  });
23
24
  }
24
25
  else if (fullyQualifiedModelName) {
@@ -5,13 +5,17 @@ import foreignKeyTypeFromPrimaryKey from '../db/foreignKeyTypeFromPrimaryKey.js'
5
5
  import snakeify from '../snakeify.js';
6
6
  const STI_TYPE_COLUMN_NAME = 'type';
7
7
  const COLUMNS_TO_INDEX = [STI_TYPE_COLUMN_NAME];
8
- export default function generateMigrationContent({ table, columnsWithTypes = [], primaryKeyType = 'bigserial', createOrAlter = 'create', } = {}) {
8
+ export default function generateMigrationContent({ table, columnsWithTypes = [], primaryKeyType = 'bigserial', createOrAlter = 'create', stiChildClassName, } = {}) {
9
9
  const altering = createOrAlter === 'alter';
10
10
  let requireCitextExtension = false;
11
- const { columnDefs, columnDrops, indexDefs, indexDrops } = columnsWithTypes.reduce((acc, attribute) => {
11
+ const checkConstraints = [];
12
+ const { columnDefs, columnDrops, indexDefs, indexDrops } = columnsWithTypes.reduce((acc, attributeDeclaration) => {
12
13
  const { columnDefs, columnDrops, indexDefs, indexDrops } = acc;
13
- const [nonStandardAttributeName, attributeType, ...descriptors] = attribute.split(':');
14
- const optional = optionalFromDescriptors(descriptors);
14
+ const [nonStandardAttributeName, attributeType, ...descriptors] = attributeDeclaration.split(':');
15
+ const userWantsThisOptional = optionalFromDescriptors(descriptors);
16
+ // when creating a migration for an STI child, we don't want to include notNull;
17
+ // instead, we'll add a check constraint that uses the STI child class name
18
+ const optional = userWantsThisOptional || !!stiChildClassName;
15
19
  const sqlAttributeType = getAttributeType(attributeType, descriptors);
16
20
  let attributeName = snakeify(nonStandardAttributeName);
17
21
  if (attributeName === undefined)
@@ -20,6 +24,17 @@ export default function generateMigrationContent({ table, columnsWithTypes = [],
20
24
  return acc;
21
25
  if (attributeType === 'citext')
22
26
  requireCitextExtension = true;
27
+ if (stiChildClassName && !userWantsThisOptional) {
28
+ checkConstraints.push(`
29
+
30
+ await db.schema
31
+ .alterTable('${table}')
32
+ .addCheckConstraint(
33
+ '${table}_not_null_${attributeName}',
34
+ sql\`type != '${stiChildClassName}' OR ${attributeName} IS NOT NULL\`,
35
+ )
36
+ .execute()`);
37
+ }
23
38
  switch (attributeType) {
24
39
  case 'belongs_to':
25
40
  columnDefs.push(generateBelongsToStr(attributeName, {
@@ -96,7 +111,7 @@ ${citextExtension}${generateEnumStatements(columnsWithTypes)} await db.schema
96
111
  ".addColumn('created_at', 'timestamp', col => col.notNull())" +
97
112
  newlineDoubleIndent +
98
113
  ".addColumn('updated_at', 'timestamp', col => col.notNull())"}
99
- .execute()${indexDefs.length ? `\n${newlineIndent}` : ''}${indexDefs.join(newlineDoubleIndent)}
114
+ .execute()${indexDefs.length ? `\n${newlineIndent}` : ''}${indexDefs.join(newlineDoubleIndent)}${checkConstraints.join('')}
100
115
  }
101
116
 
102
117
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -1,4 +1,10 @@
1
1
  import generateMigrationContent from './generateMigrationContent.js';
2
- export default function generateStiMigrationContent({ table, columnsWithTypes = [], primaryKeyType = 'bigserial', } = {}) {
3
- return generateMigrationContent({ table, columnsWithTypes, primaryKeyType, createOrAlter: 'alter' });
2
+ export default function generateStiMigrationContent({ table, columnsWithTypes = [], primaryKeyType = 'bigserial', stiChildClassName, }) {
3
+ return generateMigrationContent({
4
+ table,
5
+ columnsWithTypes,
6
+ primaryKeyType,
7
+ createOrAlter: 'alter',
8
+ stiChildClassName,
9
+ });
4
10
  }
@@ -11,7 +11,8 @@ export function serializerForAssociatedClass(object, associationName, options) {
11
11
  return null;
12
12
  const dream = object;
13
13
  const association = dream['getAssociationMetadata'](associationName);
14
- const associatedClasses = association.modelCB();
15
- const associatedClass = Array.isArray(associatedClasses) ? associatedClasses[0] : associatedClasses;
14
+ const associatedClass = association.modelCB();
15
+ if (Array.isArray(associatedClass))
16
+ throw new Error('rendersOne flatten is incompatible with a polymorphic belongs-to association');
16
17
  return inferSerializersFromDreamClassOrViewModelClass(associatedClass, options.serializerKey)[0] ?? null;
17
18
  }
@@ -1,22 +1,17 @@
1
1
  import { CompiledQuery, Updateable } from 'kysely';
2
- import { VirtualAttributeStatement } from './decorators/field-or-getter/Virtual.js';
3
- import { SortableFieldConfig } from './decorators/field/sortable/Sortable.js';
4
- import { ScopeStatement } from './decorators/static-method/Scope.js';
5
2
  import DreamClassTransactionBuilder from './dream/DreamClassTransactionBuilder.js';
6
3
  import DreamInstanceTransactionBuilder from './dream/DreamInstanceTransactionBuilder.js';
7
4
  import DreamTransaction from './dream/DreamTransaction.js';
8
5
  import { DestroyOptions } from './dream/internal/destroyOptions.js';
9
- import { RecursiveSerializerInfo } from './dream/internal/extractNestedPaths.js';
10
6
  import LeftJoinLoadBuilder from './dream/LeftJoinLoadBuilder.js';
11
7
  import LoadBuilder from './dream/LoadBuilder.js';
12
8
  import Query from './dream/Query.js';
13
- import { AssociationStatementsMap, PassthroughOnClause, WhereStatement } from './types/associations/shared.js';
9
+ import { PassthroughOnClause, WhereStatement } from './types/associations/shared.js';
14
10
  import { AssociationTableNames, DbConnectionType } from './types/db.js';
15
11
  import { AllDefaultScopeNames, AssociationNameToDream, AttributeKeys, CreateOrFindByExtraOpts, DefaultOrNamedScopeName, DreamAssociationNames, DreamAssociationNamesWithoutRequiredOnClauses, DreamAttributes, DreamColumnNames, DreamParamSafeColumnNames, DreamSerializerKey, IdType, JoinAndStatements, NextPreloadArgumentType, OrderDir, PassthroughColumnNames, PluckEachArgs, PrimaryKeyForFind, TableColumnNames, UpdateableAssociationProperties, UpdateableProperties, UpdateablePropertiesForClass, UpdateOrCreateByExtraOpts } from './types/dream.js';
16
- import { HookStatement, HookStatementMap } from './types/lifecycle.js';
17
12
  import { BaseModelColumnTypes, DefaultQueryTypeOptions, FindEachOpts, LoadForModifierFn, PaginatedDreamQueryOptions, PaginatedDreamQueryResult, QueryWithJoinedAssociationsType, QueryWithJoinedAssociationsTypeAndNoPreload } from './types/query.js';
18
13
  import { DreamModelSerializerType, SimpleObjectSerializerType } from './types/serializer.js';
19
- import { ValidationStatement, ValidationType } from './types/validation.js';
14
+ import { ValidationType } from './types/validation.js';
20
15
  import { JoinedAssociation, JoinedAssociationsTypeFromAssociations, RequiredOnClauseKeys, VariadicJoinsArgs, VariadicLeftJoinLoadArgs, VariadicLoadArgs } from './types/variadic.js';
21
16
  export default class Dream {
22
17
  DB: any;
@@ -43,7 +38,7 @@ export default class Dream {
43
38
  * property is set.
44
39
  *
45
40
  */
46
- protected columnSetterGuardActivated: boolean;
41
+ private columnSetterGuardActivated;
47
42
  /**
48
43
  * @internal
49
44
  *
@@ -152,7 +147,7 @@ export default class Dream {
152
147
  * @deco.HasMany
153
148
  * @deco.BelongsTo
154
149
  */
155
- protected static associationMetadataByType: AssociationStatementsMap;
150
+ private static associationMetadataByType;
156
151
  /**
157
152
  * @internal
158
153
  *
@@ -161,10 +156,7 @@ export default class Dream {
161
156
  * always an array rather than undefined,
162
157
  * freezing ensures that we never modify the static array on the inherited Dream class)
163
158
  */
164
- protected static scopes: {
165
- default: readonly ScopeStatement[] | ScopeStatement[];
166
- named: readonly ScopeStatement[] | ScopeStatement[];
167
- };
159
+ private static scopes;
168
160
  /**
169
161
  * @internal
170
162
  *
@@ -173,7 +165,7 @@ export default class Dream {
173
165
  * always an array rather than undefined,
174
166
  * freezing ensures that we never modify the static array on the inherited Dream class)
175
167
  */
176
- protected static virtualAttributes: readonly VirtualAttributeStatement[] | VirtualAttributeStatement[];
168
+ private static virtualAttributes;
177
169
  /**
178
170
  * @internal
179
171
  *
@@ -181,7 +173,7 @@ export default class Dream {
181
173
  * methods. Set on the inheriting class when using the Virtual decorator (this default
182
174
  * assignment simply ensures that it is always an array rather than undefined)
183
175
  */
184
- protected static explicitUnsafeParamColumns: readonly string[] | string[];
176
+ private static explicitUnsafeParamColumns;
185
177
  /**
186
178
  * @internal
187
179
  *
@@ -190,13 +182,13 @@ export default class Dream {
190
182
  * freezing ensures that we never modify the static array on the inherited Dream class)
191
183
  *
192
184
  */
193
- protected static sortableFields: readonly SortableFieldConfig[] | SortableFieldConfig[];
185
+ private static sortableFields;
194
186
  /**
195
187
  * @internal
196
188
  *
197
189
  * Model storage for STI metadata, set when using the STI decorator
198
190
  */
199
- protected static extendedBy: (typeof Dream)[] | null;
191
+ private static extendedBy;
200
192
  /**
201
193
  * @internal
202
194
  *
@@ -204,11 +196,7 @@ export default class Dream {
204
196
  * (this default assignment simply ensures that it is always a valid object rather than undefined,
205
197
  * freezing ensures that we never modify the static array on the inherited Dream class)
206
198
  */
207
- protected static sti: {
208
- active: boolean;
209
- baseClass: typeof Dream | null;
210
- value: string | null;
211
- };
199
+ private static sti;
212
200
  /**
213
201
  * @internal
214
202
  *
@@ -226,7 +214,7 @@ export default class Dream {
226
214
  * AfterDestroy
227
215
  * AfterDestroyCommit
228
216
  */
229
- protected static hooks: Readonly<HookStatementMap>;
217
+ private static hooks;
230
218
  /**
231
219
  * @internal
232
220
  *
@@ -234,7 +222,7 @@ export default class Dream {
234
222
  * (this default assignment simply ensures that it is always an array rather than undefined,
235
223
  * freezing ensures that we never modify the static array on the inherited Dream class)
236
224
  */
237
- protected static validations: readonly ValidationStatement[] | ValidationStatement[];
225
+ private static validations;
238
226
  /**
239
227
  * @internal
240
228
  *
@@ -243,19 +231,19 @@ export default class Dream {
243
231
  * freezing ensures that we never modify the static array on the inherited Dream class)
244
232
  *
245
233
  */
246
- protected static customValidations: readonly string[] | string[];
234
+ private static customValidations;
247
235
  /**
248
236
  * @internal
249
237
  *
250
238
  * Model storage for replica-safe metadata, set when using the ReplicaSafe decorator
251
239
  */
252
- protected static replicaSafe: boolean;
240
+ private static replicaSafe;
253
241
  /**
254
242
  * @internal
255
243
  *
256
244
  * Model storage for soft-delete metadata, set when using the SoftDelete decorator
257
245
  */
258
- protected static softDelete: boolean;
246
+ private static softDelete;
259
247
  /**
260
248
  * @internal
261
249
  *
@@ -271,7 +259,7 @@ export default class Dream {
271
259
  *
272
260
  * @returns boolean
273
261
  */
274
- protected static get isSTIBase(): boolean;
262
+ private static get isSTIBase();
275
263
  /**
276
264
  * @internal
277
265
  *
@@ -279,7 +267,7 @@ export default class Dream {
279
267
  *
280
268
  * @returns boolean
281
269
  */
282
- protected static get isSTIChild(): boolean;
270
+ private static get isSTIChild();
283
271
  /**
284
272
  * @internal
285
273
  *
@@ -287,7 +275,7 @@ export default class Dream {
287
275
  *
288
276
  * @returns A dream class
289
277
  */
290
- protected static get stiBaseClassOrOwnClass(): typeof Dream;
278
+ private static get stiBaseClassOrOwnClass();
291
279
  /**
292
280
  * @internal
293
281
  *
@@ -308,7 +296,7 @@ export default class Dream {
308
296
  *
309
297
  * @returns string
310
298
  */
311
- protected static get stiBaseClassOrOwnClassName(): string;
299
+ private static get stiBaseClassOrOwnClassName();
312
300
  /**
313
301
  * @internal
314
302
  *
@@ -328,7 +316,7 @@ export default class Dream {
328
316
  *
329
317
  * @returns A dream class
330
318
  */
331
- protected get stiBaseClassOrOwnClass(): typeof Dream;
319
+ private get stiBaseClassOrOwnClass();
332
320
  /**
333
321
  * @internal
334
322
  *
@@ -336,7 +324,7 @@ export default class Dream {
336
324
  *
337
325
  * @returns A string
338
326
  */
339
- protected get stiBaseClassOrOwnClassName(): string;
327
+ private get stiBaseClassOrOwnClassName();
340
328
  /**
341
329
  * this.constructor.name may be prefixed with an underscore during conversion to Javascript.
342
330
  * This method returns the constructor name without a leading underscore.
@@ -353,7 +341,7 @@ export default class Dream {
353
341
  * @param statement - the statement to couple to the provided hookType
354
342
  * @returns void
355
343
  */
356
- protected static addHook(hookType: keyof typeof this.hooks, statement: HookStatement): void;
344
+ private static addHook;
357
345
  /**
358
346
  * @internal
359
347
  *
@@ -372,12 +360,9 @@ export default class Dream {
372
360
  * name of that model.
373
361
  */
374
362
  private static setGlobalName;
375
- protected static serializationMap<T extends typeof Dream, I extends InstanceType<T>, SerializerKey extends DreamSerializerKey<I>>(this: T, serializerKey?: SerializerKey): RecursiveSerializerInfo;
376
- protected static displaySerialization<T extends typeof Dream, I extends InstanceType<T>, SerializerKey extends DreamSerializerKey<I>>(this: T, serializerKey?: SerializerKey): RecursiveSerializerInfo;
377
- protected static recursiveSerializationMap(serializer: DreamModelSerializerType | SimpleObjectSerializerType, { forDisplay, forDisplayDepth, }?: {
378
- forDisplay?: boolean;
379
- forDisplayDepth?: number;
380
- }): RecursiveSerializerInfo;
363
+ private static serializationMap;
364
+ private static displaySerialization;
365
+ private static recursiveSerializationMap;
381
366
  /**
382
367
  * Returns the column names for the given model
383
368
  *
@@ -400,7 +385,7 @@ export default class Dream {
400
385
  * @returns A subset of columns for the given dream class
401
386
  */
402
387
  static paramSafeColumnsOrFallback<T extends typeof Dream, I extends InstanceType<T>, ParamSafeColumnsOverride extends InstanceType<T>['paramSafeColumns' & keyof InstanceType<T>] extends never ? undefined : InstanceType<T>['paramSafeColumns' & keyof InstanceType<T>] & string[], ReturnVal extends ParamSafeColumnsOverride extends string[] ? Extract<DreamParamSafeColumnNames<I>, ParamSafeColumnsOverride[number] & DreamParamSafeColumnNames<I>>[] : DreamParamSafeColumnNames<I>[]>(this: T): ReturnVal;
403
- protected static defaultParamSafeColumns<T extends typeof Dream, I extends InstanceType<T>>(this: T): DreamParamSafeColumnNames<I>[];
388
+ private static defaultParamSafeColumns;
404
389
  /**
405
390
  * @internal
406
391
  *
@@ -453,11 +438,53 @@ export default class Dream {
453
438
  */
454
439
  private static associationMetadataMap;
455
440
  /**
456
- * @internal
441
+ * Checks whether the specified association has been defined on this Dream model.
457
442
  *
458
- * Returns all of the association names for this dream class
443
+ * ```ts
444
+ * const user = User.new()
445
+ *
446
+ * user.hasAssociation('posts')
447
+ * // true (if User has a posts association defined)
459
448
  *
460
- * @returns All of the association names for this dream class
449
+ * user.hasAssociation('nonExistentAssociation')
450
+ * // false
451
+ *
452
+ * // Useful for conditional association handling
453
+ * if (user.hasAssociation('posts')) {
454
+ * user = await user.load('posts').execute()
455
+ * }
456
+ * ```
457
+ *
458
+ * @param associationName - The name of the association to check for
459
+ * @returns `true` if the association exists on this model, `false` otherwise
460
+ */
461
+ hasAssociation(associationName: string): boolean;
462
+ /**
463
+ * Returns all of the association names for this Dream class.
464
+ * This includes all BelongsTo, HasOne, and HasMany associations
465
+ * defined on the model.
466
+ *
467
+ * This is useful for introspection, debugging, or dynamically working
468
+ * with all associations on a model.
469
+ *
470
+ * ```ts
471
+ * class User extends ApplicationModel {
472
+ * @deco.HasMany('Post')
473
+ * public posts: Post[]
474
+ *
475
+ * @deco.HasOne('Profile')
476
+ * public profile: Profile
477
+ *
478
+ * @deco.BelongsTo('Company')
479
+ * public company: Company
480
+ * }
481
+ *
482
+ * User.associationNames
483
+ * // ['posts', 'profile', 'company']
484
+ * })
485
+ * ```
486
+ *
487
+ * @returns An array containing all association names defined on this Dream class
461
488
  */
462
489
  static get associationNames(): string[];
463
490
  /**
@@ -1764,7 +1791,7 @@ export default class Dream {
1764
1791
  * @returns A boolean
1765
1792
  */
1766
1793
  get isPersisted(): boolean;
1767
- protected set isPersisted(val: boolean);
1794
+ private set isPersisted(value);
1768
1795
  /**
1769
1796
  * Since typescript prevents constructor functions
1770
1797
  * from absorbing type generics, we provide the `new`
@@ -1806,9 +1833,7 @@ export default class Dream {
1806
1833
  *
1807
1834
  * Used for determining which attributes to update
1808
1835
  */
1809
- protected static extractAttributesFromUpdateableProperties<T extends typeof Dream>(this: T, attributes: UpdateablePropertiesForClass<T>, dreamInstance?: InstanceType<T>, { bypassUserDefinedSetters }?: {
1810
- bypassUserDefinedSetters?: boolean;
1811
- }): WhereStatement<InstanceType<T>['DB'], InstanceType<T>['schema'], InstanceType<T>['table']>;
1836
+ private static extractAttributesFromUpdateableProperties;
1812
1837
  /**
1813
1838
  * @internal
1814
1839
  *
@@ -1824,8 +1849,8 @@ export default class Dream {
1824
1849
  * every Dream model is initialized to delete the instance accessors so that
1825
1850
  * the prototype accessors can be reached.
1826
1851
  */
1827
- protected unshadowColumnPropertyPrototypeAccessors(): void;
1828
- protected finalizeConstruction(): void;
1852
+ private unshadowColumnPropertyPrototypeAccessors;
1853
+ private finalizeConstruction;
1829
1854
  /**
1830
1855
  * @internal
1831
1856
  *
@@ -1923,7 +1948,7 @@ export default class Dream {
1923
1948
  *
1924
1949
  * Returns the db type stored within the database
1925
1950
  */
1926
- protected static cachedTypeFor<T extends typeof Dream, DB extends InstanceType<T>['DB'], TableName extends keyof DB = InstanceType<T>['table'] & keyof DB, Table extends DB[keyof DB] = DB[TableName]>(this: T, attribute: keyof Table): string;
1951
+ private static cachedTypeFor;
1927
1952
  /**
1928
1953
  * Returns the attributes that have changed since
1929
1954
  * being persisted to the database, with the values
@@ -2167,7 +2192,7 @@ export default class Dream {
2167
2192
  *
2168
2193
  * Used for changes API
2169
2194
  */
2170
- protected freezeAttributes(): void;
2195
+ private freezeAttributes;
2171
2196
  /**
2172
2197
  * Deep clones the model and its non-association attributes.
2173
2198
  * Unsets primaryKey, created and updated fields.
@@ -381,4 +381,5 @@ export default class KyselyQueryDriver<DreamInstance extends Dream> extends Quer
381
381
  * Applies a preload statement
382
382
  */
383
383
  private applyOnePreload;
384
+ private _applyOnePreload;
384
385
  }
@@ -0,0 +1,7 @@
1
+ import { DreamModelSerializerType, InternalAnyTypedSerializerDelegatedAttribute, InternalAnyTypedSerializerRendersMany, InternalAnyTypedSerializerRendersOne, SimpleObjectSerializerType } from '../../types/serializer.js';
2
+ export default function printSerializerHierarchyLevel({ serializerAssociationType, serializerAssociationName, associationSerializer, forDisplayDepth, }: {
3
+ serializerAssociationType: (InternalAnyTypedSerializerRendersMany<any> | InternalAnyTypedSerializerRendersOne<any> | InternalAnyTypedSerializerDelegatedAttribute)['type'];
4
+ serializerAssociationName: string;
5
+ associationSerializer: DreamModelSerializerType | SimpleObjectSerializerType;
6
+ forDisplayDepth: number;
7
+ }): void;
@@ -1,8 +1,9 @@
1
1
  import { PrimaryKeyType } from '../../types/dream.js';
2
- export default function generateMigrationContent({ table, columnsWithTypes, primaryKeyType, createOrAlter, }?: {
2
+ export default function generateMigrationContent({ table, columnsWithTypes, primaryKeyType, createOrAlter, stiChildClassName, }?: {
3
3
  table?: string | undefined;
4
4
  columnsWithTypes?: string[] | undefined;
5
5
  primaryKeyType?: PrimaryKeyType | undefined;
6
6
  createOrAlter?: 'create' | 'alter' | undefined;
7
+ stiChildClassName?: string | undefined;
7
8
  }): string;
8
9
  export declare function optionalFromDescriptors(descriptors: string[]): boolean;
@@ -1,6 +1,7 @@
1
1
  import { PrimaryKeyType } from '../../types/dream.js';
2
- export default function generateStiMigrationContent({ table, columnsWithTypes, primaryKeyType, }?: {
2
+ export default function generateStiMigrationContent({ table, columnsWithTypes, primaryKeyType, stiChildClassName, }: {
3
3
  table?: string;
4
4
  columnsWithTypes?: string[];
5
5
  primaryKeyType?: PrimaryKeyType;
6
+ stiChildClassName?: string;
6
7
  }): string;
@@ -36,7 +36,7 @@ export default class DreamSerializerBuilder<DataTypeForOpenapi extends typeof Dr
36
36
  *
37
37
  * See: {@link https://your-docs-url.com/docs/serializers/attributes | Serializer Attributes Documentation}
38
38
  */
39
- attribute<MaybeAttributeName extends NonJsonDreamColumnNames<DataType> | (keyof DataType & string), AttributeName extends MaybeAttributeName extends NonJsonDreamColumnNames<DataType> ? never : keyof DataType & string, Options extends NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption>(name: AttributeName, options: Options): DreamSerializerBuilder<DataTypeForOpenapi, MaybeNullDataType, PassthroughDataType, DataType>;
39
+ attribute<MaybeAttributeName extends NonJsonDreamColumnNames<DataType> | (keyof DataType & string), AttributeName extends MaybeAttributeName extends NonJsonDreamColumnNames<DataType> ? never : Exclude<keyof DataType, keyof Dream> & string, Options extends NonAutomaticSerializerAttributeOptionsWithPossibleDecimalRenderOption>(name: AttributeName, options: Options): DreamSerializerBuilder<DataTypeForOpenapi, MaybeNullDataType, PassthroughDataType, DataType>;
40
40
  attribute<AttributeName extends NonJsonDreamColumnNames<DataType> & keyof DataType & string, Options extends AutomaticSerializerAttributeOptions<DataType, AttributeName>>(name: AttributeName, options?: Options): DreamSerializerBuilder<DataTypeForOpenapi, MaybeNullDataType, PassthroughDataType, DataType>;
41
41
  /**
42
42
  * Includes an attribute from a nested object in the serialized output.
@@ -22,7 +22,7 @@ export interface SortableOptions<T extends Dream> {
22
22
  }
23
23
  export type PrimaryKeyForFind<I extends Dream, Schema extends I['schema'] = I['schema'], TableName extends keyof Schema = I['table'] & keyof Schema> = Schema[TableName]['columns'][I['primaryKey'] & keyof Schema[TableName]['columns']]['coercedType'] | string | null | undefined;
24
24
  export type DreamColumnNames<DreamInstance extends Dream, DB = DreamInstance['DB'], TableName extends keyof DB = DreamInstance['table'] & keyof DB, Table extends DB[keyof DB] = DB[TableName], AttributeName extends keyof Table & string = keyof Table & string> = AttributeName;
25
- export type NonJsonDreamColumnNames<DreamInstance extends Dream, Schema extends DreamInstance['schema'] = DreamInstance['schema'], TableName extends DreamInstance['table'] & keyof Schema = DreamInstance['table'] & keyof Schema, AttributeName extends Schema[TableName]['nonJsonColumnNames'][number] & string = Schema[TableName]['nonJsonColumnNames'][number] & string> = AttributeName;
25
+ export type NonJsonDreamColumnNames<DreamInstance extends Dream, Schema extends DreamInstance['schema'] = DreamInstance['schema'], TableName extends DreamInstance['table'] & keyof Schema = DreamInstance['table'] & keyof Schema, AttributeName extends Exclude<Schema[TableName]['nonJsonColumnNames'][number], keyof Dream> & string = Exclude<Schema[TableName]['nonJsonColumnNames'][number], keyof Dream> & string> = AttributeName;
26
26
  export type DreamParamSafeColumnNames<DreamInstance extends Dream, BelongsToForeignKeys = DreamBelongsToForeignKeys<DreamInstance>, Schema = DreamInstance['schema'], TableSchema = Schema[DreamInstance['table'] & keyof Schema]> = Exclude<keyof UpdateableProperties<DreamInstance>, BelongsToForeignKeys | TableSchema['primaryKey' & keyof TableSchema] | TableSchema['createdAtField' & keyof TableSchema] | TableSchema['updatedAtField' & keyof TableSchema] | TableSchema['deletedAtField' & keyof TableSchema] | 'type'>;
27
27
  export type DreamBelongsToForeignKeys<DreamInstance extends Dream, Schema = DreamInstance['schema'], TableSchema = Schema[DreamInstance['table'] & keyof Schema], AssociationSchema = TableSchema['associations' & keyof TableSchema], BelongsToAssociationSchema = AssociationSchema[keyof DreamBelongsToAssociationMetadata<DreamInstance> & keyof AssociationSchema], BelongsToForeignKeys = Exclude<BelongsToAssociationSchema['foreignKey' & keyof BelongsToAssociationSchema], null>> = BelongsToForeignKeys;
28
28
  export type TableColumnNames<DB, TableName extends keyof DB, Table extends DB[keyof DB] = DB[TableName]> = keyof Table & string;
@@ -61,8 +61,8 @@ export type NonJsonDreamColumnNames<
61
61
  DreamInstance extends Dream,
62
62
  Schema extends DreamInstance['schema'] = DreamInstance['schema'],
63
63
  TableName extends DreamInstance['table'] & keyof Schema = DreamInstance['table'] & keyof Schema,
64
- AttributeName extends Schema[TableName]['nonJsonColumnNames'][number] &
65
- string = Schema[TableName]['nonJsonColumnNames'][number] & string,
64
+ AttributeName extends Exclude<Schema[TableName]['nonJsonColumnNames'][number], keyof Dream> &
65
+ string = Exclude<Schema[TableName]['nonJsonColumnNames'][number], keyof Dream> & string,
66
66
  > = AttributeName
67
67
 
68
68
  export type DreamParamSafeColumnNames<