@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.
- package/dist/cjs/src/Dream.js +99 -31
- package/dist/cjs/src/dream/QueryDriver/Kysely.js +20 -19
- package/dist/cjs/src/dream/internal/printSerializerHierarchyLevel.js +17 -0
- package/dist/cjs/src/dream-app/cache.js +12 -2
- package/dist/cjs/src/helpers/cli/generateMigration.js +1 -0
- package/dist/cjs/src/helpers/cli/generateMigrationContent.js +20 -5
- package/dist/cjs/src/helpers/cli/generateStiMigrationContent.js +8 -2
- package/dist/cjs/src/serializer/helpers/serializerForAssociatedClass.js +3 -2
- package/dist/esm/src/Dream.js +99 -31
- package/dist/esm/src/dream/QueryDriver/Kysely.js +20 -19
- package/dist/esm/src/dream/internal/printSerializerHierarchyLevel.js +14 -0
- package/dist/esm/src/dream-app/cache.js +12 -2
- package/dist/esm/src/helpers/cli/generateMigration.js +1 -0
- package/dist/esm/src/helpers/cli/generateMigrationContent.js +20 -5
- package/dist/esm/src/helpers/cli/generateStiMigrationContent.js +8 -2
- package/dist/esm/src/serializer/helpers/serializerForAssociatedClass.js +3 -2
- package/dist/types/src/Dream.d.ts +77 -52
- package/dist/types/src/dream/QueryDriver/Kysely.d.ts +1 -0
- package/dist/types/src/dream/internal/printSerializerHierarchyLevel.d.ts +7 -0
- package/dist/types/src/helpers/cli/generateMigrationContent.d.ts +2 -1
- package/dist/types/src/helpers/cli/generateStiMigrationContent.d.ts +2 -1
- package/dist/types/src/serializer/builders/DreamSerializerBuilder.d.ts +1 -1
- package/dist/types/src/types/dream.d.ts +1 -1
- package/dist/types/src/types/dream.ts +2 -2
- package/docs/assets/search.js +1 -1
- package/docs/classes/Benchmark.html +2 -2
- package/docs/classes/CalendarDate.html +2 -2
- package/docs/classes/CliFileWriter.html +2 -2
- package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +3 -3
- package/docs/classes/DataTypeColumnTypeMismatch.html +3 -3
- package/docs/classes/Decorators.html +19 -19
- package/docs/classes/Dream.html +209 -308
- package/docs/classes/DreamApp.html +4 -4
- package/docs/classes/DreamBin.html +2 -2
- package/docs/classes/DreamCLI.html +4 -4
- package/docs/classes/DreamImporter.html +2 -2
- package/docs/classes/DreamLogos.html +2 -2
- package/docs/classes/DreamMigrationHelpers.html +7 -7
- package/docs/classes/DreamSerializerBuilder.html +8 -8
- package/docs/classes/DreamTransaction.html +2 -2
- package/docs/classes/Encrypt.html +2 -2
- package/docs/classes/Env.html +2 -2
- package/docs/classes/GlobalNameNotSet.html +3 -3
- package/docs/classes/NonLoadedAssociation.html +3 -3
- package/docs/classes/ObjectSerializerBuilder.html +8 -8
- package/docs/classes/Query.html +60 -60
- package/docs/classes/Range.html +2 -2
- package/docs/classes/RecordNotFound.html +3 -3
- package/docs/classes/ValidationError.html +3 -3
- package/docs/functions/DreamSerializer.html +1 -1
- package/docs/functions/ObjectSerializer.html +1 -1
- package/docs/functions/ReplicaSafe.html +1 -1
- package/docs/functions/STI.html +1 -1
- package/docs/functions/SoftDelete.html +1 -1
- package/docs/functions/camelize.html +1 -1
- package/docs/functions/capitalize.html +1 -1
- package/docs/functions/cloneDeepSafe.html +1 -1
- package/docs/functions/closeAllDbConnections.html +1 -1
- package/docs/functions/compact.html +1 -1
- package/docs/functions/dreamDbConnections.html +1 -1
- package/docs/functions/dreamPath.html +1 -1
- package/docs/functions/expandStiClasses.html +1 -1
- package/docs/functions/generateDream.html +1 -1
- package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -1
- package/docs/functions/groupBy.html +1 -1
- package/docs/functions/hyphenize.html +1 -1
- package/docs/functions/inferSerializerFromDreamOrViewModel.html +1 -1
- package/docs/functions/inferSerializersFromDreamClassOrViewModelClass.html +1 -1
- package/docs/functions/intersection.html +1 -1
- package/docs/functions/isDreamSerializer.html +1 -1
- package/docs/functions/isEmpty.html +1 -1
- package/docs/functions/loadRepl.html +1 -1
- package/docs/functions/lookupClassByGlobalName.html +1 -1
- package/docs/functions/normalizeUnicode.html +1 -1
- package/docs/functions/pascalize.html +1 -1
- package/docs/functions/pgErrorType.html +1 -1
- package/docs/functions/range-1.html +1 -1
- package/docs/functions/relativeDreamPath.html +1 -1
- package/docs/functions/round.html +1 -1
- package/docs/functions/serializerNameFromFullyQualifiedModelName.html +1 -1
- package/docs/functions/sharedPathPrefix.html +1 -1
- package/docs/functions/snakeify.html +1 -1
- package/docs/functions/sort.html +1 -1
- package/docs/functions/sortBy.html +1 -1
- package/docs/functions/sortObjectByKey.html +1 -1
- package/docs/functions/sortObjectByValue.html +1 -1
- package/docs/functions/standardizeFullyQualifiedModelName.html +1 -1
- package/docs/functions/uncapitalize.html +1 -1
- package/docs/functions/uniq.html +1 -1
- package/docs/functions/untypedDb.html +1 -1
- package/docs/functions/validateColumn.html +1 -1
- package/docs/functions/validateTable.html +1 -1
- package/docs/interfaces/BelongsToStatement.html +2 -2
- package/docs/interfaces/DecoratorContext.html +2 -2
- package/docs/interfaces/DreamAppInitOptions.html +2 -2
- package/docs/interfaces/DreamAppOpts.html +2 -2
- package/docs/interfaces/EncryptOptions.html +2 -2
- package/docs/interfaces/InternalAnyTypedSerializerRendersMany.html +2 -2
- package/docs/interfaces/InternalAnyTypedSerializerRendersOne.html +2 -2
- package/docs/interfaces/OpenapiDescription.html +2 -2
- package/docs/interfaces/OpenapiSchemaProperties.html +1 -1
- package/docs/interfaces/OpenapiSchemaPropertiesShorthand.html +1 -1
- package/docs/interfaces/OpenapiTypeFieldObject.html +1 -1
- package/docs/interfaces/SerializerRendererOpts.html +2 -2
- package/docs/types/Camelized.html +1 -1
- package/docs/types/CommonOpenapiSchemaObjectFields.html +1 -1
- package/docs/types/DateTime.html +1 -1
- package/docs/types/DbConnectionType.html +1 -1
- package/docs/types/DbTypes.html +1 -1
- package/docs/types/DreamAppAllowedPackageManagersEnum.html +1 -1
- package/docs/types/DreamAssociationMetadata.html +1 -1
- package/docs/types/DreamAttributes.html +1 -1
- package/docs/types/DreamClassAssociationAndStatement.html +1 -1
- package/docs/types/DreamClassColumn.html +1 -1
- package/docs/types/DreamColumn.html +1 -1
- package/docs/types/DreamColumnNames.html +1 -1
- package/docs/types/DreamLogLevel.html +1 -1
- package/docs/types/DreamLogger.html +1 -1
- package/docs/types/DreamModelSerializerType.html +1 -1
- package/docs/types/DreamOrViewModelClassSerializerKey.html +1 -1
- package/docs/types/DreamOrViewModelSerializerKey.html +1 -1
- package/docs/types/DreamParamSafeAttributes.html +1 -1
- package/docs/types/DreamParamSafeColumnNames.html +1 -1
- package/docs/types/DreamSerializable.html +1 -1
- package/docs/types/DreamSerializableArray.html +1 -1
- package/docs/types/DreamSerializerKey.html +1 -1
- package/docs/types/DreamSerializers.html +1 -1
- package/docs/types/DreamTableSchema.html +1 -1
- package/docs/types/DreamVirtualColumns.html +1 -1
- package/docs/types/EncryptAlgorithm.html +1 -1
- package/docs/types/HasManyStatement.html +1 -1
- package/docs/types/HasOneStatement.html +1 -1
- package/docs/types/Hyphenized.html +1 -1
- package/docs/types/IdType.html +1 -1
- package/docs/types/OpenapiAllTypes.html +1 -1
- package/docs/types/OpenapiFormats.html +1 -1
- package/docs/types/OpenapiNumberFormats.html +1 -1
- package/docs/types/OpenapiPrimitiveBaseTypes.html +1 -1
- package/docs/types/OpenapiPrimitiveTypes.html +1 -1
- package/docs/types/OpenapiSchemaArray.html +1 -1
- package/docs/types/OpenapiSchemaArrayShorthand.html +1 -1
- package/docs/types/OpenapiSchemaBase.html +1 -1
- package/docs/types/OpenapiSchemaBody.html +1 -1
- package/docs/types/OpenapiSchemaBodyShorthand.html +1 -1
- package/docs/types/OpenapiSchemaCommonFields.html +1 -1
- package/docs/types/OpenapiSchemaExpressionAllOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionOneOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionRef.html +1 -1
- package/docs/types/OpenapiSchemaExpressionRefSchemaShorthand.html +1 -1
- package/docs/types/OpenapiSchemaInteger.html +1 -1
- package/docs/types/OpenapiSchemaNull.html +1 -1
- package/docs/types/OpenapiSchemaNumber.html +1 -1
- package/docs/types/OpenapiSchemaObject.html +1 -1
- package/docs/types/OpenapiSchemaObjectAllOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectAllOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectAnyOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectBase.html +1 -1
- package/docs/types/OpenapiSchemaObjectBaseShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectOneOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectOneOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectShorthand.html +1 -1
- package/docs/types/OpenapiSchemaPrimitiveGeneric.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionAllOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionOneOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
- package/docs/types/OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
- package/docs/types/OpenapiSchemaString.html +1 -1
- package/docs/types/OpenapiShorthandAllTypes.html +1 -1
- package/docs/types/OpenapiShorthandPrimitiveBaseTypes.html +1 -1
- package/docs/types/OpenapiShorthandPrimitiveTypes.html +1 -1
- package/docs/types/OpenapiTypeField.html +1 -1
- package/docs/types/Pascalized.html +1 -1
- package/docs/types/PrimaryKeyType.html +1 -1
- package/docs/types/RoundingPrecision.html +1 -1
- package/docs/types/SerializerCasing.html +1 -1
- package/docs/types/SimpleObjectSerializerType.html +1 -1
- package/docs/types/Snakeified.html +1 -1
- package/docs/types/Timestamp.html +1 -1
- package/docs/types/UpdateableAssociationProperties.html +1 -1
- package/docs/types/UpdateableProperties.html +1 -1
- package/docs/types/ValidationType.html +1 -1
- package/docs/types/ViewModel.html +1 -1
- package/docs/types/ViewModelClass.html +1 -1
- package/docs/types/WhereStatementForDream.html +1 -1
- package/docs/types/WhereStatementForDreamClass.html +1 -1
- package/docs/variables/DateTime-1.html +1 -1
- package/docs/variables/DreamAppAllowedPackageManagersEnumValues.html +1 -1
- package/docs/variables/DreamConst.html +1 -1
- package/docs/variables/TRIGRAM_OPERATORS.html +1 -1
- package/docs/variables/openapiPrimitiveTypes-1.html +1 -1
- package/docs/variables/openapiShorthandPrimitiveTypes-1.html +1 -1
- package/docs/variables/ops.html +1 -1
- package/docs/variables/primaryKeyTypes.html +1 -1
- 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
|
-
|
|
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
|
|
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(
|
|
1776
|
+
async applyOnePreload(associationNameAndMaybeAlias, dreams, onStatement = {}) {
|
|
1784
1777
|
if (!Array.isArray(dreams))
|
|
1785
1778
|
dreams = [dreams];
|
|
1786
|
-
const
|
|
1787
|
-
|
|
1788
|
-
|
|
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 (
|
|
1797
|
-
|
|
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
|
-
|
|
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
|
|
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] =
|
|
14
|
-
const
|
|
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({
|
|
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
|
|
15
|
-
|
|
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 {
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
376
|
-
|
|
377
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
441
|
+
* Checks whether the specified association has been defined on this Dream model.
|
|
457
442
|
*
|
|
458
|
-
*
|
|
443
|
+
* ```ts
|
|
444
|
+
* const user = User.new()
|
|
445
|
+
*
|
|
446
|
+
* user.hasAssociation('posts')
|
|
447
|
+
* // true (if User has a posts association defined)
|
|
459
448
|
*
|
|
460
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1828
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2195
|
+
private freezeAttributes;
|
|
2171
2196
|
/**
|
|
2172
2197
|
* Deep clones the model and its non-association attributes.
|
|
2173
2198
|
* Unsets primaryKey, created and updated fields.
|
|
@@ -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<
|