@rvoh/dream 1.3.3 → 1.4.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 +76 -36
- package/dist/cjs/src/bin/helpers/sync.js +2 -3
- package/dist/cjs/src/decorators/class/SoftDelete.js +1 -1
- package/dist/cjs/src/decorators/field/association/shared.js +1 -1
- package/dist/cjs/src/decorators/field/sortable/helpers/decrementScopedRecordsGreaterThanPosition.js +1 -1
- package/dist/cjs/src/decorators/field/sortable/helpers/resortAllRecords.js +1 -1
- package/dist/cjs/src/decorators/field/sortable/helpers/setPosition.js +3 -3
- package/dist/cjs/src/decorators/field/sortable/helpers/sortableQueryExcludingDream.js +1 -1
- package/dist/cjs/src/dream/DreamInstanceTransactionBuilder.js +2 -2
- package/dist/cjs/src/dream/LeftJoinLoadBuilder.js +1 -1
- package/dist/cjs/src/dream/Query.js +6 -4
- package/dist/cjs/src/dream/QueryDriver/Kysely.js +6 -6
- package/dist/cjs/src/dream/internal/associations/associationQuery.js +1 -1
- package/dist/cjs/src/dream/internal/associations/associationUpdateQuery.js +1 -1
- package/dist/cjs/src/dream/internal/destroyDream.js +1 -1
- package/dist/cjs/src/dream/internal/reload.js +1 -1
- package/dist/cjs/src/dream/internal/softDeleteDream.js +3 -3
- package/dist/cjs/src/dream/internal/undestroyDream.js +2 -2
- package/dist/cjs/src/dream-app/index.js +4 -0
- package/dist/cjs/src/errors/MissingDeletedAtFieldForSoftDelete.js +1 -1
- package/dist/cjs/src/helpers/cli/SchemaBuilder.js +1 -9
- package/dist/cjs/src/helpers/cli/generateSerializerContent.js +5 -2
- package/dist/cjs/src/helpers/customPgParsers.js +10 -0
- package/dist/cjs/src/helpers/sort.js +1 -1
- package/dist/cjs/src/serializer/SerializerRenderer.js +2 -0
- package/dist/esm/src/Dream.js +76 -36
- package/dist/esm/src/bin/helpers/sync.js +2 -3
- package/dist/esm/src/decorators/class/SoftDelete.js +1 -1
- package/dist/esm/src/decorators/field/association/shared.js +1 -1
- package/dist/esm/src/decorators/field/sortable/helpers/decrementScopedRecordsGreaterThanPosition.js +1 -1
- package/dist/esm/src/decorators/field/sortable/helpers/resortAllRecords.js +1 -1
- package/dist/esm/src/decorators/field/sortable/helpers/setPosition.js +3 -3
- package/dist/esm/src/decorators/field/sortable/helpers/sortableQueryExcludingDream.js +1 -1
- package/dist/esm/src/dream/DreamInstanceTransactionBuilder.js +2 -2
- package/dist/esm/src/dream/LeftJoinLoadBuilder.js +1 -1
- package/dist/esm/src/dream/Query.js +6 -4
- package/dist/esm/src/dream/QueryDriver/Kysely.js +6 -6
- package/dist/esm/src/dream/internal/associations/associationQuery.js +1 -1
- package/dist/esm/src/dream/internal/associations/associationUpdateQuery.js +1 -1
- package/dist/esm/src/dream/internal/destroyDream.js +1 -1
- package/dist/esm/src/dream/internal/reload.js +1 -1
- package/dist/esm/src/dream/internal/softDeleteDream.js +3 -3
- package/dist/esm/src/dream/internal/undestroyDream.js +2 -2
- package/dist/esm/src/dream-app/index.js +5 -1
- package/dist/esm/src/errors/MissingDeletedAtFieldForSoftDelete.js +1 -1
- package/dist/esm/src/helpers/cli/SchemaBuilder.js +1 -9
- package/dist/esm/src/helpers/cli/generateSerializerContent.js +5 -2
- package/dist/esm/src/helpers/customPgParsers.js +9 -0
- package/dist/esm/src/helpers/sort.js +1 -1
- package/dist/esm/src/serializer/SerializerRenderer.js +2 -0
- package/dist/types/src/Dream.d.ts +44 -23
- package/dist/types/src/helpers/customPgParsers.d.ts +1 -0
- package/dist/types/src/helpers/sort.d.ts +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/serializer/builders/DreamSerializerBuilder.d.ts +2 -1
- package/dist/types/src/types/associations/shared.d.ts +9 -5
- package/dist/types/src/types/associations/shared.ts +33 -21
- package/dist/types/src/types/dream.d.ts +5 -4
- package/dist/types/src/types/dream.ts +41 -15
- package/dist/types/src/types/query.d.ts +4 -4
- package/dist/types/src/types/query.ts +4 -4
- package/dist/types/src/types/serializer.d.ts +7 -0
- package/dist/types/src/types/serializer.ts +8 -0
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/Benchmark.html +2 -2
- package/docs/classes/CalendarDate.html +2 -2
- package/docs/classes/CheckConstraintViolation.html +3 -3
- 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 +159 -181
- 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 +19 -19
- 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/NotNullViolation.html +3 -3
- package/docs/classes/ObjectSerializerBuilder.html +8 -8
- package/docs/classes/Query.html +63 -63
- 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 +2 -2
- 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/modules.html +0 -4
- 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/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/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/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/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 +3 -3
- package/docs/types/DreamTableSchema.html +0 -1
- package/docs/types/IdType.html +0 -1
- package/docs/types/PrimaryKeyType.html +0 -1
- package/docs/types/Timestamp.html +0 -1
package/dist/cjs/src/Dream.js
CHANGED
|
@@ -45,13 +45,16 @@ const CreateOrUpdateByFailedToCreateAndUpdate_js_1 = require("./errors/CreateOrU
|
|
|
45
45
|
const GlobalNameNotSet_js_1 = require("./errors/dream-app/GlobalNameNotSet.js");
|
|
46
46
|
const DreamMissingRequiredOverride_js_1 = require("./errors/DreamMissingRequiredOverride.js");
|
|
47
47
|
const NonExistentScopeProvidedToResort_js_1 = require("./errors/NonExistentScopeProvidedToResort.js");
|
|
48
|
+
const MissingSerializersDefinition_js_1 = require("./errors/serializers/MissingSerializersDefinition.js");
|
|
48
49
|
const CalendarDate_js_1 = require("./helpers/CalendarDate.js");
|
|
49
50
|
const cloneDeepSafe_js_1 = require("./helpers/cloneDeepSafe.js");
|
|
51
|
+
const compact_js_1 = require("./helpers/compact.js");
|
|
50
52
|
const DateTime_js_1 = require("./helpers/DateTime.js");
|
|
51
53
|
const cachedTypeForAttribute_js_1 = require("./helpers/db/cachedTypeForAttribute.js");
|
|
52
54
|
const isJsonColumn_js_1 = require("./helpers/db/types/isJsonColumn.js");
|
|
53
55
|
const notEqual_js_1 = require("./helpers/notEqual.js");
|
|
54
56
|
const inferSerializerFromDreamOrViewModel_js_1 = require("./serializer/helpers/inferSerializerFromDreamOrViewModel.js");
|
|
57
|
+
const RECURSIVE_SERIALIZATION_MAX_REPEATS = 4;
|
|
55
58
|
class Dream {
|
|
56
59
|
DB;
|
|
57
60
|
/**
|
|
@@ -155,7 +158,7 @@ class Dream {
|
|
|
155
158
|
* @returns string
|
|
156
159
|
*/
|
|
157
160
|
static get primaryKey() {
|
|
158
|
-
return this.prototype.
|
|
161
|
+
return this.prototype._primaryKey;
|
|
159
162
|
}
|
|
160
163
|
/**
|
|
161
164
|
* Shadows #table, a getter which can be overwritten to customize the table field
|
|
@@ -167,8 +170,9 @@ class Dream {
|
|
|
167
170
|
return this.prototype.table;
|
|
168
171
|
}
|
|
169
172
|
/**
|
|
170
|
-
*
|
|
171
|
-
*
|
|
173
|
+
* @internal
|
|
174
|
+
*
|
|
175
|
+
* The `createdAt` field may be customized on a Dream model:
|
|
172
176
|
*
|
|
173
177
|
* ```ts
|
|
174
178
|
* class User extends ApplicationModel {
|
|
@@ -182,12 +186,13 @@ class Dream {
|
|
|
182
186
|
*
|
|
183
187
|
* @returns string
|
|
184
188
|
*/
|
|
185
|
-
get
|
|
186
|
-
return 'createdAt';
|
|
189
|
+
get _createdAtField() {
|
|
190
|
+
return this.createdAtField || 'createdAt';
|
|
187
191
|
}
|
|
188
192
|
/**
|
|
189
|
-
*
|
|
190
|
-
*
|
|
193
|
+
* @internal
|
|
194
|
+
*
|
|
195
|
+
* The `updatedAt` field may be customized on a Dream model:
|
|
191
196
|
*
|
|
192
197
|
* ```ts
|
|
193
198
|
* class User extends ApplicationModel {
|
|
@@ -202,11 +207,30 @@ class Dream {
|
|
|
202
207
|
*
|
|
203
208
|
* @returns string
|
|
204
209
|
*/
|
|
205
|
-
get
|
|
206
|
-
return 'updatedAt';
|
|
210
|
+
get _updatedAtField() {
|
|
211
|
+
return this.updatedAtField || 'updatedAt';
|
|
207
212
|
}
|
|
208
|
-
|
|
209
|
-
|
|
213
|
+
/**
|
|
214
|
+
* @internal
|
|
215
|
+
*
|
|
216
|
+
* The `deletedAt` field may be customized on a Dream model:
|
|
217
|
+
*
|
|
218
|
+
* ```ts
|
|
219
|
+
* class User extends ApplicationModel {
|
|
220
|
+
* public get deletedAtField() {
|
|
221
|
+
* return 'deletedAtTimestamp' as const
|
|
222
|
+
* }
|
|
223
|
+
* }
|
|
224
|
+
*
|
|
225
|
+
* const user = await User.first()
|
|
226
|
+
* await user.destroy()
|
|
227
|
+
* user.deletedAtTimestamp // returns the DateTime that this user was soft-deleted
|
|
228
|
+
* ```
|
|
229
|
+
*
|
|
230
|
+
* @returns string
|
|
231
|
+
*/
|
|
232
|
+
get _deletedAtField() {
|
|
233
|
+
return this.deletedAtField || 'deletedAt';
|
|
210
234
|
}
|
|
211
235
|
/**
|
|
212
236
|
* @internal
|
|
@@ -379,7 +403,7 @@ class Dream {
|
|
|
379
403
|
* .whereAny(
|
|
380
404
|
* modelsWithTextAssociation.map(
|
|
381
405
|
* model => ({
|
|
382
|
-
* localizableId: model.primaryKeyValue,
|
|
406
|
+
* localizableId: model.primaryKeyValue(),
|
|
383
407
|
* localizableType: model.referenceTypeString,
|
|
384
408
|
* })
|
|
385
409
|
* )
|
|
@@ -441,7 +465,7 @@ class Dream {
|
|
|
441
465
|
* .whereAny(
|
|
442
466
|
* modelsWithTextAssociation.map(
|
|
443
467
|
* model => ({
|
|
444
|
-
* localizableId: model.primaryKeyValue,
|
|
468
|
+
* localizableId: model.primaryKeyValue(),
|
|
445
469
|
* localizableType: model.referenceTypeString,
|
|
446
470
|
* })
|
|
447
471
|
* )
|
|
@@ -528,10 +552,15 @@ class Dream {
|
|
|
528
552
|
forDisplay: true,
|
|
529
553
|
});
|
|
530
554
|
}
|
|
531
|
-
static recursiveSerializationMap(serializer, { forDisplay = false, forDisplayDepth = 0, } = {}) {
|
|
555
|
+
static recursiveSerializationMap(serializer, { forDisplay = false, forDisplayDepth = 0, repeatedAssociationTracker = {}, } = {}) {
|
|
556
|
+
const depthTrackerId = this.globalName;
|
|
557
|
+
repeatedAssociationTracker[depthTrackerId] ??= 0;
|
|
558
|
+
if (repeatedAssociationTracker[depthTrackerId] + 1 > RECURSIVE_SERIALIZATION_MAX_REPEATS)
|
|
559
|
+
return {};
|
|
560
|
+
repeatedAssociationTracker[depthTrackerId]++;
|
|
532
561
|
const serializerBuilder = serializer(undefined, undefined);
|
|
533
562
|
const serializerAssociations = serializerBuilder['attributes'].filter(attribute => ['rendersOne', 'rendersMany', 'delegatedAttribute'].includes(attribute.type));
|
|
534
|
-
|
|
563
|
+
const mappedAssociations = serializerAssociations.reduce((accumulator, serializerAssociation) => {
|
|
535
564
|
const serializerAssociationName = serializerAssociation.targetName ??
|
|
536
565
|
serializerAssociation.name;
|
|
537
566
|
const serializerAssociationType = serializerAssociation.type;
|
|
@@ -552,11 +581,17 @@ class Dream {
|
|
|
552
581
|
* `serializers` is an array because `associatedClass` may be an STI
|
|
553
582
|
* base, with each of its STI children having its own serializer
|
|
554
583
|
*/
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
584
|
+
let serializers = [];
|
|
585
|
+
try {
|
|
586
|
+
serializers = serializerAssociation.options.serializer
|
|
587
|
+
? (0, compact_js_1.default)([serializerAssociation.options.serializer])
|
|
588
|
+
: (0, compact_js_1.default)((0, inferSerializerFromDreamOrViewModel_js_1.inferSerializersFromDreamClassOrViewModelClass)(associatedClass, serializerAssociation.options.serializerKey));
|
|
589
|
+
}
|
|
590
|
+
catch (error) {
|
|
591
|
+
if (!(error instanceof MissingSerializersDefinition_js_1.default))
|
|
592
|
+
throw error;
|
|
593
|
+
serializers = [];
|
|
594
|
+
}
|
|
560
595
|
return serializers.map(serializer => [associatedClass, serializer]);
|
|
561
596
|
});
|
|
562
597
|
/////////////////////////////////////////////////////
|
|
@@ -579,6 +614,7 @@ class Dream {
|
|
|
579
614
|
...associatedClass['recursiveSerializationMap'](associatedSerializer, {
|
|
580
615
|
forDisplay,
|
|
581
616
|
forDisplayDepth: forDisplayDepth + 1,
|
|
617
|
+
repeatedAssociationTracker,
|
|
582
618
|
}),
|
|
583
619
|
};
|
|
584
620
|
}, {});
|
|
@@ -591,6 +627,10 @@ class Dream {
|
|
|
591
627
|
};
|
|
592
628
|
return accumulator;
|
|
593
629
|
}, {});
|
|
630
|
+
// reduce the depth as we're coming up so that other branches of the serialization tree don't stop
|
|
631
|
+
// rendering this association on this class
|
|
632
|
+
repeatedAssociationTracker[depthTrackerId]--;
|
|
633
|
+
return mappedAssociations;
|
|
594
634
|
}
|
|
595
635
|
/**
|
|
596
636
|
* Returns the column names for the given model
|
|
@@ -633,13 +673,13 @@ class Dream {
|
|
|
633
673
|
}
|
|
634
674
|
static defaultParamSafeColumns() {
|
|
635
675
|
const columns = [...this.columns()].filter(column => {
|
|
636
|
-
if (this.prototype.
|
|
676
|
+
if (this.prototype._primaryKey === column)
|
|
637
677
|
return false;
|
|
638
|
-
if (this.prototype.
|
|
678
|
+
if (this.prototype._createdAtField === column)
|
|
639
679
|
return false;
|
|
640
|
-
if (this.prototype.
|
|
680
|
+
if (this.prototype._updatedAtField === column)
|
|
641
681
|
return false;
|
|
642
|
-
if (this.prototype.
|
|
682
|
+
if (this.prototype._deletedAtField === column)
|
|
643
683
|
return false;
|
|
644
684
|
if (this.explicitUnsafeParamColumns.includes(column))
|
|
645
685
|
return false;
|
|
@@ -1138,7 +1178,7 @@ class Dream {
|
|
|
1138
1178
|
*/
|
|
1139
1179
|
query() {
|
|
1140
1180
|
const dreamClass = this.constructor;
|
|
1141
|
-
return dreamClass.where({ [this.
|
|
1181
|
+
return dreamClass.where({ [this._primaryKey]: this.primaryKeyValue() });
|
|
1142
1182
|
}
|
|
1143
1183
|
/**
|
|
1144
1184
|
* Finds the first record—ordered by primary key—matching
|
|
@@ -2119,9 +2159,9 @@ class Dream {
|
|
|
2119
2159
|
return !Object.keys(this.errors).filter(key => !!this.errors[key]?.length).length;
|
|
2120
2160
|
}
|
|
2121
2161
|
/**
|
|
2122
|
-
*
|
|
2123
|
-
*
|
|
2124
|
-
* primary key
|
|
2162
|
+
* @internal
|
|
2163
|
+
*
|
|
2164
|
+
* The primary key may be customized on a Dream model:
|
|
2125
2165
|
*
|
|
2126
2166
|
* ```ts
|
|
2127
2167
|
* class User extends ApplicationModel {
|
|
@@ -2135,16 +2175,16 @@ class Dream {
|
|
|
2135
2175
|
*
|
|
2136
2176
|
* @returns The primary key column name
|
|
2137
2177
|
*/
|
|
2138
|
-
get
|
|
2139
|
-
return 'id';
|
|
2178
|
+
get _primaryKey() {
|
|
2179
|
+
return this.primaryKey || 'id';
|
|
2140
2180
|
}
|
|
2141
2181
|
/**
|
|
2142
2182
|
* Returns the value of the primary key
|
|
2143
2183
|
*
|
|
2144
2184
|
* @returns The value of the primary key field for this Dream instance
|
|
2145
2185
|
*/
|
|
2146
|
-
|
|
2147
|
-
return this[this.
|
|
2186
|
+
primaryKeyValue() {
|
|
2187
|
+
return this[this._primaryKey] || null;
|
|
2148
2188
|
}
|
|
2149
2189
|
/**
|
|
2150
2190
|
* This must be defined on every model, and it must point
|
|
@@ -2916,7 +2956,7 @@ class Dream {
|
|
|
2916
2956
|
return this.comparisonKey === other.comparisonKey;
|
|
2917
2957
|
}
|
|
2918
2958
|
get comparisonKey() {
|
|
2919
|
-
return `${this.constructor.globalName}:${this.primaryKeyValue}`;
|
|
2959
|
+
return `${this.constructor.globalName}:${this.primaryKeyValue()}`;
|
|
2920
2960
|
}
|
|
2921
2961
|
/**
|
|
2922
2962
|
* @internal
|
|
@@ -2935,9 +2975,9 @@ class Dream {
|
|
|
2935
2975
|
dup() {
|
|
2936
2976
|
const clone = this.clone({ includeAssociations: false });
|
|
2937
2977
|
clone.isPersisted = false;
|
|
2938
|
-
clone[clone.
|
|
2939
|
-
clone[clone.
|
|
2940
|
-
clone[clone.
|
|
2978
|
+
clone[clone._primaryKey] = undefined;
|
|
2979
|
+
clone[clone._createdAtField] = undefined;
|
|
2980
|
+
clone[clone._updatedAtField] = undefined;
|
|
2941
2981
|
const dreamClass = this.constructor;
|
|
2942
2982
|
dreamClass.sortableFields.forEach(data => {
|
|
2943
2983
|
;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.default = writeSyncFile;
|
|
4
4
|
const fs = require("node:fs/promises");
|
|
5
5
|
const path = require("node:path");
|
|
6
|
+
const CliFileWriter_js_1 = require("../../cli/CliFileWriter.js");
|
|
6
7
|
const index_js_1 = require("../../cli/index.js");
|
|
7
8
|
const colorize_js_1 = require("../../cli/logger/loggable/colorize.js");
|
|
8
9
|
const index_js_2 = require("../../dream-app/index.js");
|
|
@@ -12,7 +13,6 @@ const EnvInternal_js_1 = require("../../helpers/EnvInternal.js");
|
|
|
12
13
|
const dreamPath_js_1 = require("../../helpers/path/dreamPath.js");
|
|
13
14
|
const snakeify_js_1 = require("../../helpers/snakeify.js");
|
|
14
15
|
const sspawn_js_1 = require("../../helpers/sspawn.js");
|
|
15
|
-
const CliFileWriter_js_1 = require("../../cli/CliFileWriter.js");
|
|
16
16
|
async function writeSyncFile() {
|
|
17
17
|
const dreamApp = index_js_2.default.getOrFail();
|
|
18
18
|
const dbConf = dreamApp.dbConnectionConfig('primary');
|
|
@@ -60,8 +60,7 @@ export class DBClass {
|
|
|
60
60
|
return sortedFileContents;
|
|
61
61
|
}
|
|
62
62
|
function removeUnwantedExports(file) {
|
|
63
|
-
return file.replace(/\nexport type Timestamp = ColumnType<.*/, `export type
|
|
64
|
-
export type Timestamp = ColumnType<DateTime | CalendarDate>`);
|
|
63
|
+
return file.replace(/\nexport type Timestamp = ColumnType<.*/, `export type Timestamp = ColumnType<DateTime | CalendarDate>`);
|
|
65
64
|
}
|
|
66
65
|
function addCustomImports(file) {
|
|
67
66
|
const customImports = EnvInternal_js_1.default.boolean('DREAM_CORE_DEVELOPMENT')
|
|
@@ -47,7 +47,7 @@ function SoftDelete() {
|
|
|
47
47
|
throw new StiChildIncompatibleWithSoftDeleteDecorator_js_1.default(dreamClass);
|
|
48
48
|
dreamClass['softDelete'] = true;
|
|
49
49
|
target[exports.SOFT_DELETE_SCOPE_NAME] = function (query) {
|
|
50
|
-
return query.where({ [dreamClass.prototype
|
|
50
|
+
return query.where({ [dreamClass.prototype['_deletedAtField']]: null });
|
|
51
51
|
};
|
|
52
52
|
(0, Scope_js_1.scopeImplementation)(target, exports.SOFT_DELETE_SCOPE_NAME, { default: true });
|
|
53
53
|
};
|
|
@@ -102,7 +102,7 @@ function associationPrimaryKeyAccessors(partialAssociation, dreamClass) {
|
|
|
102
102
|
if (this.primaryKeyOverride)
|
|
103
103
|
return this.primaryKeyOverride;
|
|
104
104
|
if (associationInstance)
|
|
105
|
-
return associationInstance
|
|
105
|
+
return associationInstance['_primaryKey'];
|
|
106
106
|
const associationClass = associatedClassOverride ?? this.modelCB();
|
|
107
107
|
if (Array.isArray(associationClass)) {
|
|
108
108
|
throw new Error(`
|
package/dist/cjs/src/decorators/field/sortable/helpers/decrementScopedRecordsGreaterThanPosition.js
CHANGED
|
@@ -6,7 +6,7 @@ const getColumnForSortableScope_js_1 = require("./getColumnForSortableScope.js")
|
|
|
6
6
|
const scopeArray_js_1 = require("./scopeArray.js");
|
|
7
7
|
async function decrementPositionForScopedRecordsGreaterThanPosition(position, { dream, positionField, query, scope, }) {
|
|
8
8
|
let kyselyQuery = query
|
|
9
|
-
.whereNot({ [dream
|
|
9
|
+
.whereNot({ [dream['_primaryKey']]: dream.primaryKeyValue() })
|
|
10
10
|
.where({
|
|
11
11
|
[positionField]: index_js_1.default.greaterThanOrEqualTo(position),
|
|
12
12
|
})
|
|
@@ -21,7 +21,7 @@ async function resortAllRecords(dreamClass, positionField, scope) {
|
|
|
21
21
|
for (const dream of dreams) {
|
|
22
22
|
await dreamClass
|
|
23
23
|
.txn(txn)
|
|
24
|
-
.where({ [dream
|
|
24
|
+
.where({ [dream['_primaryKey']]: dream.primaryKeyValue() })
|
|
25
25
|
.toKysely('update')
|
|
26
26
|
.set({
|
|
27
27
|
[positionField]: counter++,
|
|
@@ -82,7 +82,7 @@ async function setNewPosition({ dream, positionField, query, scope, previousPosi
|
|
|
82
82
|
const dbOrTxn = txn ? txn.kyselyTransaction : (0, index_js_1.default)('primary');
|
|
83
83
|
await dbOrTxn
|
|
84
84
|
.updateTable(dream.table)
|
|
85
|
-
.where(dream
|
|
85
|
+
.where(dream['_primaryKey'], '=', dream.primaryKeyValue())
|
|
86
86
|
.set({
|
|
87
87
|
[positionField]: newPosition,
|
|
88
88
|
})
|
|
@@ -123,7 +123,7 @@ async function updateConflictingRecords({ position, previousPosition, dream, pos
|
|
|
123
123
|
const increasing = newPosition === undefined || (previousPosition !== undefined && previousPosition < newPosition);
|
|
124
124
|
let kyselyQuery = query
|
|
125
125
|
.txn(txn)
|
|
126
|
-
.whereNot({ [dream
|
|
126
|
+
.whereNot({ [dream['_primaryKey']]: dream.primaryKeyValue() })
|
|
127
127
|
.where({
|
|
128
128
|
[positionField]: increasing
|
|
129
129
|
? (0, range_js_1.default)(previousPosition, newPosition)
|
|
@@ -150,7 +150,7 @@ function applySortableScopesToQuery(dream, kyselyQuery, whereValueCB, scope) {
|
|
|
150
150
|
async function updatePositionForRecord(txn, dream, positionField, position) {
|
|
151
151
|
await txn.kyselyTransaction
|
|
152
152
|
.updateTable(dream.table)
|
|
153
|
-
.where(dream
|
|
153
|
+
.where(dream['_primaryKey'], '=', dream.primaryKeyValue())
|
|
154
154
|
.set({
|
|
155
155
|
[positionField]: position,
|
|
156
156
|
})
|
|
@@ -4,7 +4,7 @@ exports.default = sortableQueryExcludingDream;
|
|
|
4
4
|
const applySortableScopeToQuery_js_1 = require("./applySortableScopeToQuery.js");
|
|
5
5
|
function sortableQueryExcludingDream(dream, query, scope) {
|
|
6
6
|
query = query.whereNot({
|
|
7
|
-
[dream
|
|
7
|
+
[dream['_primaryKey']]: dream.primaryKeyValue(),
|
|
8
8
|
});
|
|
9
9
|
return (0, applySortableScopeToQuery_js_1.default)(query, dream, scope);
|
|
10
10
|
}
|
|
@@ -591,8 +591,8 @@ class DreamInstanceTransactionBuilder {
|
|
|
591
591
|
*/
|
|
592
592
|
queryInstance() {
|
|
593
593
|
const dreamClass = this.dreamInstance.constructor;
|
|
594
|
-
const id = this.dreamInstance.primaryKeyValue;
|
|
595
|
-
return dreamClass.txn(this.dreamTransaction).where({ [this.dreamInstance
|
|
594
|
+
const id = this.dreamInstance.primaryKeyValue();
|
|
595
|
+
return dreamClass.txn(this.dreamTransaction).where({ [this.dreamInstance['_primaryKey']]: id });
|
|
596
596
|
}
|
|
597
597
|
}
|
|
598
598
|
exports.default = DreamInstanceTransactionBuilder;
|
|
@@ -119,7 +119,7 @@ class LeftJoinLoadBuilder {
|
|
|
119
119
|
if (associationMetadata === undefined)
|
|
120
120
|
throw new UnexpectedUndefined_js_1.default();
|
|
121
121
|
this.query.dbDriverInstance()['hydrateAssociation']([this.dream], associationMetadata, this.associationToPreloadedDreamsAndWhatTheyPointTo({
|
|
122
|
-
pointsToPrimaryKey: this.dream.primaryKeyValue,
|
|
122
|
+
pointsToPrimaryKey: this.dream.primaryKeyValue(),
|
|
123
123
|
associatedModels: dreamWithLoadedAssociations[associationName],
|
|
124
124
|
}));
|
|
125
125
|
});
|
|
@@ -327,7 +327,7 @@ class Query {
|
|
|
327
327
|
if (!primaryKey)
|
|
328
328
|
return null;
|
|
329
329
|
return await this.where({
|
|
330
|
-
[this.dreamInstance
|
|
330
|
+
[this.dreamInstance['_primaryKey']]: primaryKey,
|
|
331
331
|
}).first();
|
|
332
332
|
}
|
|
333
333
|
/**
|
|
@@ -414,13 +414,15 @@ class Query {
|
|
|
414
414
|
let lastId = null;
|
|
415
415
|
do {
|
|
416
416
|
if (lastId)
|
|
417
|
-
records = await query
|
|
417
|
+
records = await query
|
|
418
|
+
.where({ [this.dreamInstance['_primaryKey']]: index_js_2.default.greaterThan(lastId) })
|
|
419
|
+
.all();
|
|
418
420
|
else
|
|
419
421
|
records = await query.all();
|
|
420
422
|
for (const record of records) {
|
|
421
423
|
await cb(record);
|
|
422
424
|
}
|
|
423
|
-
lastId = records.at(-1)?.primaryKeyValue;
|
|
425
|
+
lastId = records.at(-1)?.primaryKeyValue?.();
|
|
424
426
|
} while (records.length > 0 && records.length === batchSize);
|
|
425
427
|
}
|
|
426
428
|
/**
|
|
@@ -1029,7 +1031,7 @@ class Query {
|
|
|
1029
1031
|
distinct(column = true) {
|
|
1030
1032
|
if (column === true) {
|
|
1031
1033
|
return this.clone({
|
|
1032
|
-
distinctColumn: this.namespaceColumn(this.dreamInstance
|
|
1034
|
+
distinctColumn: this.namespaceColumn(this.dreamInstance['_primaryKey']),
|
|
1033
1035
|
});
|
|
1034
1036
|
}
|
|
1035
1037
|
else if (column === false) {
|
|
@@ -343,7 +343,7 @@ class KyselyQueryDriver extends Base_js_1.default {
|
|
|
343
343
|
let kyselyQuery = new KyselyQueryDriver(query).buildSelect({ bypassSelectAll: true, bypassOrder: true });
|
|
344
344
|
const countClause = distinctColumn
|
|
345
345
|
? count((0, kysely_1.sql) `DISTINCT ${distinctColumn}`)
|
|
346
|
-
: count(query['namespaceColumn'](query.dreamInstance
|
|
346
|
+
: count(query['namespaceColumn'](query.dreamInstance['_primaryKey']));
|
|
347
347
|
kyselyQuery = kyselyQuery.select(countClause.as('tablecount'));
|
|
348
348
|
const data = await (0, executeDatabaseQuery_js_1.default)(kyselyQuery, 'executeTakeFirstOrThrow');
|
|
349
349
|
return parseInt(data.tablecount.toString());
|
|
@@ -425,7 +425,7 @@ class KyselyQueryDriver extends Base_js_1.default {
|
|
|
425
425
|
const query = db
|
|
426
426
|
.updateTable(dream.table)
|
|
427
427
|
.set(sqlifiedAttributes)
|
|
428
|
-
.where((0, namespaceColumn_js_1.default)(dream
|
|
428
|
+
.where((0, namespaceColumn_js_1.default)(dream['_primaryKey'], dream.table), '=', dream.primaryKeyValue());
|
|
429
429
|
return await (0, executeDatabaseQuery_js_1.default)(query.returning([...dream.columns()]), 'executeTakeFirstOrThrow');
|
|
430
430
|
}
|
|
431
431
|
else {
|
|
@@ -587,7 +587,7 @@ class KyselyQueryDriver extends Base_js_1.default {
|
|
|
587
587
|
// rating.rateable = loadedAssociation
|
|
588
588
|
preloadedDreamsAndWhatTheyPointTo.forEach(preloadedDreamAndWhatItPointsTo => {
|
|
589
589
|
dreams
|
|
590
|
-
.filter(dream => dream.primaryKeyValue === preloadedDreamAndWhatItPointsTo.pointsToPrimaryKey)
|
|
590
|
+
.filter(dream => dream.primaryKeyValue() === preloadedDreamAndWhatItPointsTo.pointsToPrimaryKey)
|
|
591
591
|
.forEach((dream) => {
|
|
592
592
|
if (association.type === 'HasMany') {
|
|
593
593
|
dream[association.as].push(preloadedDreamAndWhatItPointsTo.dream);
|
|
@@ -658,8 +658,8 @@ class KyselyQueryDriver extends Base_js_1.default {
|
|
|
658
658
|
attachLimitAndOrderStatementsToNonSelectQuery(kyselyQuery) {
|
|
659
659
|
if (this.query['limitStatement'] || this.query['orderStatements'].length) {
|
|
660
660
|
kyselyQuery = kyselyQuery.where((eb) => {
|
|
661
|
-
const subquery = this.query.nestedSelect(this.dreamInstance
|
|
662
|
-
return eb(this.dreamInstance
|
|
661
|
+
const subquery = this.query.nestedSelect(this.dreamInstance['_primaryKey']);
|
|
662
|
+
return eb(this.dreamInstance['_primaryKey'], 'in', subquery);
|
|
663
663
|
});
|
|
664
664
|
return {
|
|
665
665
|
kyselyQuery,
|
|
@@ -1825,7 +1825,7 @@ class KyselyQueryDriver extends Base_js_1.default {
|
|
|
1825
1825
|
// regardless of default scopes on that Dream's class.
|
|
1826
1826
|
bypassAllDefaultScopesExceptOnAssociations: true,
|
|
1827
1827
|
}).where({
|
|
1828
|
-
[dreamClass.primaryKey]: dreams.map(obj => obj.primaryKeyValue),
|
|
1828
|
+
[dreamClass.primaryKey]: dreams.map(obj => obj.primaryKeyValue()),
|
|
1829
1829
|
});
|
|
1830
1830
|
const hydrationData = await associationDataScope['_connection'](this.connectionOverride)
|
|
1831
1831
|
.innerJoin(associationName, (onStatement || {}))
|
|
@@ -8,7 +8,7 @@ function associationQuery(dream, txn = null, associationName, { joinAndStatement
|
|
|
8
8
|
const dreamClass = dream.constructor;
|
|
9
9
|
const dreamClassOrTransaction = (txn ? dreamClass.txn(txn) : dreamClass);
|
|
10
10
|
let baseSelectQuery = dreamClassOrTransaction.where({
|
|
11
|
-
[dream
|
|
11
|
+
[dream['_primaryKey']]: dream.primaryKeyValue(),
|
|
12
12
|
});
|
|
13
13
|
if (joinAndStatements && (joinAndStatements.and || joinAndStatements.andNot || joinAndStatements.andAny))
|
|
14
14
|
baseSelectQuery = baseSelectQuery.innerJoin(association.as, joinAndStatements);
|
|
@@ -25,7 +25,7 @@ function associationUpdateQuery(dream, txn = null, associationName, { joinAndSta
|
|
|
25
25
|
else
|
|
26
26
|
nestedScope = nestedScope.innerJoin(association.as);
|
|
27
27
|
const nestedSelect = nestedScope
|
|
28
|
-
.where({ [dream
|
|
28
|
+
.where({ [dream['_primaryKey']]: dream.primaryKeyValue() })
|
|
29
29
|
.nestedSelect((0, namespaceColumn_js_1.default)(associationClass.primaryKey, association.as));
|
|
30
30
|
const whereClause = {
|
|
31
31
|
[associationClass.primaryKey]: nestedSelect,
|
|
@@ -65,7 +65,7 @@ async function maybeDestroyDream(dream, txn, reallyDestroy) {
|
|
|
65
65
|
else if (!dream['_preventDeletion']) {
|
|
66
66
|
await txn.kyselyTransaction
|
|
67
67
|
.deleteFrom(dream.table)
|
|
68
|
-
.where(dream
|
|
68
|
+
.where(dream['_primaryKey'], '=', dream.primaryKeyValue())
|
|
69
69
|
.execute();
|
|
70
70
|
}
|
|
71
71
|
}
|
|
@@ -13,7 +13,7 @@ async function reload(dream, txn = null) {
|
|
|
13
13
|
// we have persisted are not yet propagated
|
|
14
14
|
else
|
|
15
15
|
query = query.connection('primary');
|
|
16
|
-
query = query.removeAllDefaultScopes().where({ [dream
|
|
16
|
+
query = query.removeAllDefaultScopes().where({ [dream['_primaryKey']]: dream.primaryKeyValue() });
|
|
17
17
|
const reloadedRecord = await query.firstOrFail();
|
|
18
18
|
dream.setAttributes(reloadedRecord.getAttributes());
|
|
19
19
|
dream['freezeAttributes']();
|
|
@@ -5,15 +5,15 @@ const MissingDeletedAtFieldForSoftDelete_js_1 = require("../../errors/MissingDel
|
|
|
5
5
|
const DateTime_js_1 = require("../../helpers/DateTime.js");
|
|
6
6
|
const isDatetimeOrDatetimeArrayColumn_js_1 = require("../../helpers/db/types/isDatetimeOrDatetimeArrayColumn.js");
|
|
7
7
|
async function softDeleteDream(dream, txn) {
|
|
8
|
-
const deletedAtField = dream
|
|
8
|
+
const deletedAtField = dream['_deletedAtField'];
|
|
9
9
|
const dreamClass = dream.constructor;
|
|
10
10
|
if (!(0, isDatetimeOrDatetimeArrayColumn_js_1.default)(dreamClass, deletedAtField)) {
|
|
11
11
|
throw new MissingDeletedAtFieldForSoftDelete_js_1.default(dream.constructor);
|
|
12
12
|
}
|
|
13
13
|
let query = txn.kyselyTransaction
|
|
14
14
|
.updateTable(dream.table)
|
|
15
|
-
.where(dream
|
|
16
|
-
.set(dream
|
|
15
|
+
.where(dream['_primaryKey'], '=', dream.primaryKeyValue())
|
|
16
|
+
.set(dream['_deletedAtField'], DateTime_js_1.DateTime.now());
|
|
17
17
|
dreamClass['sortableFields']?.forEach(sortableFieldMetadata => {
|
|
18
18
|
const positionColumn = sortableFieldMetadata.positionField;
|
|
19
19
|
query = query.set(positionColumn, null);
|
|
@@ -54,8 +54,8 @@ async function undestroyDreamWithTransaction(dream, txn, options) {
|
|
|
54
54
|
async function doUndestroyDream(dream, txn) {
|
|
55
55
|
let query = txn.kyselyTransaction
|
|
56
56
|
.updateTable(dream.table)
|
|
57
|
-
.where(dream
|
|
58
|
-
.set({ [dream
|
|
57
|
+
.where(dream['_primaryKey'], '=', dream.primaryKeyValue())
|
|
58
|
+
.set({ [dream['_deletedAtField']]: null });
|
|
59
59
|
const dreamClass = dream.constructor;
|
|
60
60
|
dreamClass['sortableFields']?.forEach(sortableFieldMetadata => {
|
|
61
61
|
const positionColumn = sortableFieldMetadata.positionField;
|
|
@@ -96,6 +96,7 @@ class DreamApp {
|
|
|
96
96
|
pgTypes.setTypeParser(pgTypes.builtins.TIMESTAMP, customPgParsers_js_1.parsePostgresDatetime);
|
|
97
97
|
pgTypes.setTypeParser(pgTypes.builtins.TIMESTAMPTZ, customPgParsers_js_1.parsePostgresDatetime);
|
|
98
98
|
pgTypes.setTypeParser(pgTypes.builtins.NUMERIC, customPgParsers_js_1.parsePostgresDecimal);
|
|
99
|
+
pgTypes.setTypeParser(pgTypes.builtins.INT8, customPgParsers_js_1.parsePostgresBigint);
|
|
99
100
|
const textArrayOid = await (0, customPgParsers_js_1.findCorrespondingArrayOid)(kyselyDb, pgTypes.builtins.TEXT);
|
|
100
101
|
if (textArrayOid) {
|
|
101
102
|
let oid;
|
|
@@ -123,6 +124,9 @@ class DreamApp {
|
|
|
123
124
|
oid = await (0, customPgParsers_js_1.findCorrespondingArrayOid)(kyselyDb, pgTypes.builtins.NUMERIC);
|
|
124
125
|
if (oid)
|
|
125
126
|
pgTypes.setTypeParser(oid, transformPostgresArray(customPgParsers_js_1.parsePostgresDecimal));
|
|
127
|
+
oid = await (0, customPgParsers_js_1.findCorrespondingArrayOid)(kyselyDb, pgTypes.builtins.INT8);
|
|
128
|
+
if (oid)
|
|
129
|
+
pgTypes.setTypeParser(oid, transformPostgresArray(customPgParsers_js_1.parsePostgresBigint));
|
|
126
130
|
}
|
|
127
131
|
}
|
|
128
132
|
static checkKey(encryptionIdentifier, key, algorithm) {
|
|
@@ -7,7 +7,7 @@ class MissingDeletedAtFieldForSoftDelete extends Error {
|
|
|
7
7
|
this.dreamClass = dreamClass;
|
|
8
8
|
}
|
|
9
9
|
get message() {
|
|
10
|
-
const deletedAtField = this.dreamClass.prototype
|
|
10
|
+
const deletedAtField = this.dreamClass.prototype['_deletedAtField'];
|
|
11
11
|
return `
|
|
12
12
|
Expected "${deletedAtField}" to be a valid column for the ${this.dreamClass.name} model.
|
|
13
13
|
Whenever the using SoftDelete decorator, you must have either a deletedAt column,
|
|
@@ -83,10 +83,6 @@ export const schema = {
|
|
|
83
83
|
return '';
|
|
84
84
|
return `\
|
|
85
85
|
${tableName}: {
|
|
86
|
-
primaryKey: '${tableData.primaryKey}',
|
|
87
|
-
createdAtField: '${tableData.createdAtField}',
|
|
88
|
-
updatedAtField: '${tableData.updatedAtField}',
|
|
89
|
-
deletedAtField: '${tableData.deletedAtField}',
|
|
90
86
|
serializerKeys: ${stringifyArray(tableData.serializerKeys)},
|
|
91
87
|
scopes: {
|
|
92
88
|
default: ${stringifyArray(defaultScopeNames)},
|
|
@@ -195,10 +191,6 @@ may need to update the table getter in the corresponding Dream.
|
|
|
195
191
|
});
|
|
196
192
|
const serializerKeys = (0, intersection_js_1.default)(...eachModelSerializerKeys);
|
|
197
193
|
return {
|
|
198
|
-
primaryKey: baseModel.prototype.primaryKey,
|
|
199
|
-
createdAtField: baseModel.prototype.createdAtField,
|
|
200
|
-
updatedAtField: baseModel.prototype.updatedAtField,
|
|
201
|
-
deletedAtField: baseModel.prototype.deletedAtField,
|
|
202
194
|
scopes: {
|
|
203
195
|
default: (0, uniq_js_1.default)(models.flatMap(model => model['scopes'].default.map(scopeStatement => scopeStatement.method))),
|
|
204
196
|
named: (0, uniq_js_1.default)(models.flatMap(model => model['scopes'].named.map(scopeStatement => scopeStatement.method))),
|
|
@@ -386,7 +378,7 @@ may need to update the table getter in the corresponding Dream.
|
|
|
386
378
|
return /^date[[\]]*$/.test(dbType) ? `CalendarDate${postfix}` : `DateTime${postfix}`;
|
|
387
379
|
case 'Int8':
|
|
388
380
|
case 'Int8[]':
|
|
389
|
-
return `
|
|
381
|
+
return `string${postfix}`;
|
|
390
382
|
default:
|
|
391
383
|
return individualType;
|
|
392
384
|
}
|
|
@@ -54,7 +54,7 @@ function generateSerializerContent({ fullyQualifiedModelName, columnsWithTypes =
|
|
|
54
54
|
return '';
|
|
55
55
|
if (['belongs_to', 'has_one', 'has_many'].includes(type))
|
|
56
56
|
return '';
|
|
57
|
-
return `\n ${attribute(name, type, attr)}`;
|
|
57
|
+
return `\n ${attribute(name, type, attr, stiBaseSerializer)}`;
|
|
58
58
|
})
|
|
59
59
|
.join('')}`;
|
|
60
60
|
return `${dreamImport}${additionalImportsStr}${relatedModelImport}${additionalModelImports.join('')}
|
|
@@ -69,7 +69,10 @@ ${summarySerializer.replace(summarySerializerClassName, adminSummarySerializerCl
|
|
|
69
69
|
${defaultSerializer.replace(serializerClassName, adminSerializerClassName).replace(summarySerializerClassName, adminSummarySerializerClassName)}`}
|
|
70
70
|
`;
|
|
71
71
|
}
|
|
72
|
-
function attribute(name, type, attr) {
|
|
72
|
+
function attribute(name, type, attr, stiBaseSerializer) {
|
|
73
|
+
if (name === 'type' && stiBaseSerializer) {
|
|
74
|
+
return `.attribute('type', { openapi: { type: 'string', enum: [StiChildClass.sanitizedName] } })`;
|
|
75
|
+
}
|
|
73
76
|
switch (type) {
|
|
74
77
|
case 'json':
|
|
75
78
|
case 'jsonb':
|
|
@@ -6,6 +6,7 @@ exports.findCorrespondingArrayOid = findCorrespondingArrayOid;
|
|
|
6
6
|
exports.parsePostgresDate = parsePostgresDate;
|
|
7
7
|
exports.parsePostgresDatetime = parsePostgresDatetime;
|
|
8
8
|
exports.parsePostgresDecimal = parsePostgresDecimal;
|
|
9
|
+
exports.parsePostgresBigint = parsePostgresBigint;
|
|
9
10
|
const CalendarDate_js_1 = require("./CalendarDate.js");
|
|
10
11
|
const DateTime_js_1 = require("./DateTime.js");
|
|
11
12
|
async function findEnumArrayOids(kyselyDb) {
|
|
@@ -37,3 +38,12 @@ function parsePostgresDatetime(datetimeString) {
|
|
|
37
38
|
function parsePostgresDecimal(numberString) {
|
|
38
39
|
return numberString ? parseFloat(numberString) : numberString;
|
|
39
40
|
}
|
|
41
|
+
function parsePostgresBigint(numberString) {
|
|
42
|
+
/**
|
|
43
|
+
* JSON.stringify() throws an error when it encounters a bigint anywhere, and they are
|
|
44
|
+
* troublesome overall to handle. Instead, we serialize bigints as strings, but allow
|
|
45
|
+
* numerical operations to be performed on them in the database (e.g. when passing an
|
|
46
|
+
* `ops` query ina `where` clause)
|
|
47
|
+
*/
|
|
48
|
+
return numberString;
|
|
49
|
+
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.default = sort;
|
|
4
4
|
const sortBy_js_1 = require("./sortBy.js");
|
|
5
5
|
/**
|
|
6
|
-
* Returns a copy of array containing strings, numbers, bigints,
|
|
6
|
+
* Returns a copy of array containing strings, numbers, bigints, sorted in ascending order.
|
|
7
7
|
* To sort other types use {@link sortBy}.
|
|
8
8
|
*
|
|
9
9
|
* ```ts
|