@rvoh/dream 0.43.1 → 0.44.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/Query.js +4 -3
- package/dist/cjs/src/errors/serializers/MissingSerializersDefinitionForKey.js +3 -4
- package/dist/cjs/src/helpers/cli/generateDreamContent.js +7 -14
- package/dist/cjs/src/helpers/cli/generateSerializerContent.js +1 -2
- package/dist/cjs/src/serializer/SerializerRenderer.js +14 -10
- package/dist/cjs/src/serializer/builders/DreamSerializerBuilder.js +0 -8
- package/dist/cjs/src/serializer/builders/ObjectSerializerBuilder.js +0 -8
- package/dist/esm/src/dream/Query.js +4 -3
- package/dist/esm/src/errors/serializers/MissingSerializersDefinitionForKey.js +3 -4
- package/dist/esm/src/helpers/cli/generateDreamContent.js +7 -14
- package/dist/esm/src/helpers/cli/generateSerializerContent.js +2 -2
- package/dist/esm/src/serializer/SerializerRenderer.js +14 -10
- package/dist/esm/src/serializer/builders/DreamSerializerBuilder.js +0 -8
- package/dist/esm/src/serializer/builders/ObjectSerializerBuilder.js +0 -8
- package/dist/types/src/Dream.d.ts +16 -4
- package/dist/types/src/decorators/field/sortable/helpers/applySortableScopeToQuery.d.ts +3 -0
- package/dist/types/src/decorators/field/sortable/helpers/sortableQueryExcludingDream.d.ts +3 -0
- package/dist/types/src/dream/DreamClassTransactionBuilder.d.ts +6 -0
- package/dist/types/src/dream/Query.d.ts +19 -4
- package/dist/types/src/dream/internal/applyScopeBypassingSettingsToQuery.d.ts +3 -0
- package/dist/types/src/helpers/cli/generateSerializerContent.d.ts +0 -1
- package/dist/types/src/serializer/builders/DreamSerializerBuilder.d.ts +3 -4
- package/dist/types/src/serializer/builders/ObjectSerializerBuilder.d.ts +0 -1
- package/dist/types/src/types/dream.d.ts +4 -1
- package/dist/types/src/types/dream.ts +9 -4
- package/dist/types/src/types/query.d.ts +6 -0
- package/dist/types/src/types/query.ts +6 -0
- package/dist/types/src/types/serializer.d.ts +2 -0
- package/dist/types/src/types/serializer.ts +2 -0
- package/dist/types/src/types/variadic.d.ts +3 -0
- package/dist/types/src/types/variadic.ts +3 -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/CreateOrFindByFailedToCreateAndFind.html +3 -3
- package/docs/classes/Decorators.html +20 -20
- package/docs/classes/Dream.html +158 -158
- 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 +2 -3
- 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 +2 -3
- package/docs/classes/Query.html +64 -64
- 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/DreamAssociationMetadata.html +1 -1
- package/docs/types/DreamAttributes.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/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 +2 -2
|
@@ -931,7 +931,7 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
931
931
|
* @returns A cloned Query with the limit clause applied
|
|
932
932
|
*/
|
|
933
933
|
limit(limit) {
|
|
934
|
-
return this.clone({ limit });
|
|
934
|
+
return this.clone({ limit: limit });
|
|
935
935
|
}
|
|
936
936
|
/**
|
|
937
937
|
* Returns a new Query instance, specifying an offset
|
|
@@ -944,7 +944,7 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
944
944
|
* @returns A cloned Query with the offset clause applied
|
|
945
945
|
*/
|
|
946
946
|
offset(offset) {
|
|
947
|
-
return this.clone({ offset });
|
|
947
|
+
return this.clone({ offset: offset });
|
|
948
948
|
}
|
|
949
949
|
/**
|
|
950
950
|
* Returns the sql that would be executed by this Query
|
|
@@ -1457,7 +1457,8 @@ class Query extends ConnectedToDB_js_1.default {
|
|
|
1457
1457
|
const recordCount = await this.count();
|
|
1458
1458
|
const pageSize = opts.pageSize || index_js_1.default.getOrFail().paginationPageSize;
|
|
1459
1459
|
const pageCount = Math.ceil(recordCount / pageSize);
|
|
1460
|
-
const results = await this
|
|
1460
|
+
const results = await this
|
|
1461
|
+
.limit(pageSize)
|
|
1461
1462
|
.offset((page - 1) * pageSize)
|
|
1462
1463
|
.all();
|
|
1463
1464
|
return {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const pascalize_js_1 = require("../../helpers/pascalize.js");
|
|
4
3
|
class MissingSerializersDefinitionForKey extends Error {
|
|
5
4
|
viewModel;
|
|
6
5
|
serializerKey;
|
|
@@ -17,10 +16,10 @@ Missing serializers definition for \`${this.serializerKey}\` on class \`${classN
|
|
|
17
16
|
Try something like this in your ${className}'s serializer getter:
|
|
18
17
|
|
|
19
18
|
class ${className} {
|
|
20
|
-
public get serializers() {
|
|
19
|
+
public get serializers(): DreamSerializers<${className}> {
|
|
21
20
|
return {
|
|
22
|
-
default: ${className}Serializer
|
|
23
|
-
${this.serializerKey}:
|
|
21
|
+
default: '${className}Serializer'
|
|
22
|
+
${this.serializerKey}: '<the_global_name_of_a_serializer>'
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
25
|
...
|
|
@@ -2,34 +2,30 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = generateDreamContent;
|
|
4
4
|
const pluralize_esm_1 = require("pluralize-esm");
|
|
5
|
-
const
|
|
5
|
+
const serializerGlobalNameFromFullyQualifiedModelName_js_1 = require("../../serializer/helpers/serializerGlobalNameFromFullyQualifiedModelName.js");
|
|
6
6
|
const camelize_js_1 = require("../camelize.js");
|
|
7
7
|
const globalClassNameFromFullyQualifiedModelName_js_1 = require("../globalClassNameFromFullyQualifiedModelName.js");
|
|
8
8
|
const relativeDreamPath_js_1 = require("../path/relativeDreamPath.js");
|
|
9
9
|
const snakeify_js_1 = require("../snakeify.js");
|
|
10
10
|
const standardizeFullyQualifiedModelName_js_1 = require("../standardizeFullyQualifiedModelName.js");
|
|
11
11
|
const uniq_js_1 = require("../uniq.js");
|
|
12
|
-
const generateSerializerContent_js_1 = require("./generateSerializerContent.js");
|
|
13
12
|
function generateDreamContent({ fullyQualifiedModelName, columnsWithTypes, fullyQualifiedParentName, serializer, }) {
|
|
14
13
|
fullyQualifiedModelName = (0, standardizeFullyQualifiedModelName_js_1.default)(fullyQualifiedModelName);
|
|
15
14
|
const modelClassName = (0, globalClassNameFromFullyQualifiedModelName_js_1.default)(fullyQualifiedModelName);
|
|
16
15
|
let parentModelClassName;
|
|
17
16
|
const dreamImports = ['Decorators', 'DreamColumn'];
|
|
17
|
+
if (serializer)
|
|
18
|
+
dreamImports.push('DreamSerializers');
|
|
18
19
|
const isSTI = !!fullyQualifiedParentName;
|
|
19
20
|
if (isSTI) {
|
|
20
21
|
fullyQualifiedParentName = (0, standardizeFullyQualifiedModelName_js_1.default)(fullyQualifiedParentName);
|
|
21
22
|
parentModelClassName = (0, globalClassNameFromFullyQualifiedModelName_js_1.default)(fullyQualifiedParentName);
|
|
22
23
|
dreamImports.push('STI');
|
|
23
24
|
}
|
|
24
|
-
const serialzerClassName = (0, serializerNameFromFullyQualifiedModelName_js_1.default)((0, generateSerializerContent_js_1.fullyQualifiedModelNameToSerializerBaseName)(fullyQualifiedModelName));
|
|
25
|
-
const summarySerialzerClassName = (0, serializerNameFromFullyQualifiedModelName_js_1.default)((0, generateSerializerContent_js_1.fullyQualifiedModelNameToSerializerBaseName)(fullyQualifiedModelName), 'summary');
|
|
26
25
|
const idTypescriptType = `DreamColumn<${modelClassName}, 'id'>`;
|
|
27
26
|
const modelImportStatements = isSTI
|
|
28
27
|
? [importStatementForModel(fullyQualifiedModelName, fullyQualifiedParentName)]
|
|
29
28
|
: [importStatementForModel(fullyQualifiedModelName, 'ApplicationModel')];
|
|
30
|
-
const serializerImportStatement = serializer
|
|
31
|
-
? importStatementForSerializers(fullyQualifiedModelName, serialzerClassName, summarySerialzerClassName)
|
|
32
|
-
: '';
|
|
33
29
|
const attributeStatements = columnsWithTypes.map(attribute => {
|
|
34
30
|
const [attributeName, attributeType, ...descriptors] = attribute.split(':');
|
|
35
31
|
if (attributeName === undefined)
|
|
@@ -80,7 +76,7 @@ public ${(0, camelize_js_1.default)(attributeName)}: ${getAttributeType(attribut
|
|
|
80
76
|
timestamps = timestamps.replace(/\n$/, '');
|
|
81
77
|
const tableName = (0, snakeify_js_1.default)((0, pluralize_esm_1.default)(fullyQualifiedModelName.replace(/\//g, '_')));
|
|
82
78
|
return `\
|
|
83
|
-
import { ${(0, uniq_js_1.default)(dreamImports).join(', ')} } from '@rvoh/dream'${(0, uniq_js_1.default)(modelImportStatements).join('')}
|
|
79
|
+
import { ${(0, uniq_js_1.default)(dreamImports).join(', ')} } from '@rvoh/dream'${(0, uniq_js_1.default)(modelImportStatements).join('')}
|
|
84
80
|
|
|
85
81
|
const deco = new Decorators<typeof ${modelClassName}>()
|
|
86
82
|
|
|
@@ -93,10 +89,10 @@ ${isSTI
|
|
|
93
89
|
}
|
|
94
90
|
|
|
95
91
|
`}${serializer
|
|
96
|
-
? ` public ${isSTI ? 'override ' : ''}get serializers() {
|
|
92
|
+
? ` public ${isSTI ? 'override ' : ''}get serializers(): DreamSerializers<${modelClassName}> {
|
|
97
93
|
return {
|
|
98
|
-
default: ${
|
|
99
|
-
summary: ${
|
|
94
|
+
default: '${(0, serializerGlobalNameFromFullyQualifiedModelName_js_1.default)(fullyQualifiedModelName)}',
|
|
95
|
+
summary: '${(0, serializerGlobalNameFromFullyQualifiedModelName_js_1.default)(fullyQualifiedModelName, 'summary')}',
|
|
100
96
|
}
|
|
101
97
|
}
|
|
102
98
|
|
|
@@ -111,6 +107,3 @@ function getAttributeType(attribute, modelClassName) {
|
|
|
111
107
|
function importStatementForModel(originModelName, destinationModelName = originModelName) {
|
|
112
108
|
return `\nimport ${(0, globalClassNameFromFullyQualifiedModelName_js_1.default)(destinationModelName)} from '${(0, relativeDreamPath_js_1.default)('models', 'models', originModelName, destinationModelName)}'`;
|
|
113
109
|
}
|
|
114
|
-
function importStatementForSerializers(originModelName, serialzerClassName, summarySerialzerClassName) {
|
|
115
|
-
return `\nimport { ${serialzerClassName}, ${summarySerialzerClassName} } from '${(0, relativeDreamPath_js_1.default)('models', 'serializers', originModelName)}'`;
|
|
116
|
-
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = generateSerializerContent;
|
|
4
|
-
exports.fullyQualifiedModelNameToSerializerBaseName = fullyQualifiedModelNameToSerializerBaseName;
|
|
5
4
|
const serializerNameFromFullyQualifiedModelName_js_1 = require("../../serializer/helpers/serializerNameFromFullyQualifiedModelName.js");
|
|
6
5
|
const camelize_js_1 = require("../camelize.js");
|
|
7
6
|
const globalClassNameFromFullyQualifiedModelName_js_1 = require("../globalClassNameFromFullyQualifiedModelName.js");
|
|
@@ -64,7 +63,7 @@ function attribute(name, type, attr) {
|
|
|
64
63
|
case 'jsonb':
|
|
65
64
|
case 'json[]':
|
|
66
65
|
case 'jsonb[]':
|
|
67
|
-
return `.
|
|
66
|
+
return `.attribute('${(0, camelize_js_1.default)(name)}', { openapi: { type: 'object', properties: { } } })`;
|
|
68
67
|
default:
|
|
69
68
|
return `.attribute('${(0, camelize_js_1.default)(name)}'${attributeOptionsSpecifier(type, attr)})`;
|
|
70
69
|
}
|
|
@@ -6,6 +6,8 @@ const compact_js_1 = require("../helpers/compact.js");
|
|
|
6
6
|
const DateTime_js_1 = require("../helpers/DateTime.js");
|
|
7
7
|
const round_js_1 = require("../helpers/round.js");
|
|
8
8
|
const snakeify_js_1 = require("../helpers/snakeify.js");
|
|
9
|
+
const DreamSerializerBuilder_js_1 = require("./builders/DreamSerializerBuilder.js");
|
|
10
|
+
const ObjectSerializerBuilder_js_1 = require("./builders/ObjectSerializerBuilder.js");
|
|
9
11
|
const inferSerializerFromDreamOrViewModel_js_1 = require("./helpers/inferSerializerFromDreamOrViewModel.js");
|
|
10
12
|
class SerializerRenderer {
|
|
11
13
|
serializerBuilder;
|
|
@@ -38,8 +40,8 @@ class SerializerRenderer {
|
|
|
38
40
|
////////////////
|
|
39
41
|
case 'attribute': {
|
|
40
42
|
const outputAttributeName = this.setCase(attribute.options?.as ?? attribute.name);
|
|
41
|
-
const value = data[attribute.name];
|
|
42
|
-
accumulator[outputAttributeName] = applyRenderingOptionsToAttribute(value, attribute.options);
|
|
43
|
+
const value = data[attribute.name] ?? attribute.options?.default;
|
|
44
|
+
accumulator[outputAttributeName] = applyRenderingOptionsToAttribute(value, attribute.options, this.passthroughData, this.renderOpts);
|
|
43
45
|
return accumulator;
|
|
44
46
|
}
|
|
45
47
|
/////////////////////
|
|
@@ -51,8 +53,8 @@ class SerializerRenderer {
|
|
|
51
53
|
case 'delegatedAttribute': {
|
|
52
54
|
const outputAttributeName = this.setCase(attribute.options?.as ?? attribute.name);
|
|
53
55
|
const target = data[attribute.targetName];
|
|
54
|
-
const value = target[attribute.name];
|
|
55
|
-
accumulator[outputAttributeName] = applyRenderingOptionsToAttribute(value, attribute.options);
|
|
56
|
+
const value = target[attribute.name] ?? attribute.options?.default;
|
|
57
|
+
accumulator[outputAttributeName] = applyRenderingOptionsToAttribute(value, attribute.options, this.passthroughData, this.renderOpts);
|
|
56
58
|
return accumulator;
|
|
57
59
|
}
|
|
58
60
|
//////////////////////////////
|
|
@@ -69,11 +71,11 @@ class SerializerRenderer {
|
|
|
69
71
|
if (attribute.options.flatten) {
|
|
70
72
|
return {
|
|
71
73
|
...accumulator,
|
|
72
|
-
...applyRenderingOptionsToAttribute(attribute.fn(), {}),
|
|
74
|
+
...applyRenderingOptionsToAttribute(attribute.fn(), {}, this.passthroughData, this.renderOpts),
|
|
73
75
|
};
|
|
74
76
|
}
|
|
75
77
|
else {
|
|
76
|
-
accumulator[outputAttributeName] = applyRenderingOptionsToAttribute(attribute.fn(), {});
|
|
78
|
+
accumulator[outputAttributeName] = applyRenderingOptionsToAttribute(attribute.fn(), {}, this.passthroughData, this.renderOpts);
|
|
77
79
|
return accumulator;
|
|
78
80
|
}
|
|
79
81
|
}
|
|
@@ -180,12 +182,14 @@ class SerializerRenderer {
|
|
|
180
182
|
}
|
|
181
183
|
}
|
|
182
184
|
exports.default = SerializerRenderer;
|
|
183
|
-
function applyRenderingOptionsToAttribute(value, options) {
|
|
185
|
+
function applyRenderingOptionsToAttribute(value, options, passthroughData, renderOptions) {
|
|
184
186
|
if (Array.isArray(value))
|
|
185
|
-
return value.map(val => _applyRenderingOptionsToAttribute(val, options));
|
|
186
|
-
return _applyRenderingOptionsToAttribute(value, options);
|
|
187
|
+
return value.map(val => _applyRenderingOptionsToAttribute(val, options, passthroughData, renderOptions));
|
|
188
|
+
return _applyRenderingOptionsToAttribute(value, options, passthroughData, renderOptions);
|
|
187
189
|
}
|
|
188
|
-
function _applyRenderingOptionsToAttribute(value, options) {
|
|
190
|
+
function _applyRenderingOptionsToAttribute(value, options, passthroughData, renderOptions) {
|
|
191
|
+
if (value instanceof DreamSerializerBuilder_js_1.default || value instanceof ObjectSerializerBuilder_js_1.default)
|
|
192
|
+
return value.render(passthroughData, renderOptions);
|
|
189
193
|
if (value instanceof DateTime_js_1.DateTime)
|
|
190
194
|
return value.toISO();
|
|
191
195
|
if (value instanceof CalendarDate_js_1.default)
|
|
@@ -31,14 +31,6 @@ class DreamSerializerBuilder {
|
|
|
31
31
|
});
|
|
32
32
|
return this;
|
|
33
33
|
}
|
|
34
|
-
jsonAttribute(name, options) {
|
|
35
|
-
this.attributes.push({
|
|
36
|
-
type: 'attribute',
|
|
37
|
-
name,
|
|
38
|
-
options,
|
|
39
|
-
});
|
|
40
|
-
return this;
|
|
41
|
-
}
|
|
42
34
|
customAttribute(name, fn, options) {
|
|
43
35
|
this.attributes.push({
|
|
44
36
|
type: 'customAttribute',
|
|
@@ -29,14 +29,6 @@ class ObjectSerializerBuilder {
|
|
|
29
29
|
});
|
|
30
30
|
return this;
|
|
31
31
|
}
|
|
32
|
-
jsonAttribute(name, options) {
|
|
33
|
-
this.attributes.push({
|
|
34
|
-
type: 'attribute',
|
|
35
|
-
name,
|
|
36
|
-
options,
|
|
37
|
-
});
|
|
38
|
-
return this;
|
|
39
|
-
}
|
|
40
32
|
customAttribute(name, fn, options) {
|
|
41
33
|
this.attributes.push({
|
|
42
34
|
type: 'customAttribute',
|
|
@@ -929,7 +929,7 @@ export default class Query extends ConnectedToDB {
|
|
|
929
929
|
* @returns A cloned Query with the limit clause applied
|
|
930
930
|
*/
|
|
931
931
|
limit(limit) {
|
|
932
|
-
return this.clone({ limit });
|
|
932
|
+
return this.clone({ limit: limit });
|
|
933
933
|
}
|
|
934
934
|
/**
|
|
935
935
|
* Returns a new Query instance, specifying an offset
|
|
@@ -942,7 +942,7 @@ export default class Query extends ConnectedToDB {
|
|
|
942
942
|
* @returns A cloned Query with the offset clause applied
|
|
943
943
|
*/
|
|
944
944
|
offset(offset) {
|
|
945
|
-
return this.clone({ offset });
|
|
945
|
+
return this.clone({ offset: offset });
|
|
946
946
|
}
|
|
947
947
|
/**
|
|
948
948
|
* Returns the sql that would be executed by this Query
|
|
@@ -1455,7 +1455,8 @@ export default class Query extends ConnectedToDB {
|
|
|
1455
1455
|
const recordCount = await this.count();
|
|
1456
1456
|
const pageSize = opts.pageSize || DreamApp.getOrFail().paginationPageSize;
|
|
1457
1457
|
const pageCount = Math.ceil(recordCount / pageSize);
|
|
1458
|
-
const results = await this
|
|
1458
|
+
const results = await this
|
|
1459
|
+
.limit(pageSize)
|
|
1459
1460
|
.offset((page - 1) * pageSize)
|
|
1460
1461
|
.all();
|
|
1461
1462
|
return {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import pascalize from '../../helpers/pascalize.js';
|
|
2
1
|
export default class MissingSerializersDefinitionForKey extends Error {
|
|
3
2
|
viewModel;
|
|
4
3
|
serializerKey;
|
|
@@ -15,10 +14,10 @@ Missing serializers definition for \`${this.serializerKey}\` on class \`${classN
|
|
|
15
14
|
Try something like this in your ${className}'s serializer getter:
|
|
16
15
|
|
|
17
16
|
class ${className} {
|
|
18
|
-
public get serializers() {
|
|
17
|
+
public get serializers(): DreamSerializers<${className}> {
|
|
19
18
|
return {
|
|
20
|
-
default: ${className}Serializer
|
|
21
|
-
${this.serializerKey}:
|
|
19
|
+
default: '${className}Serializer'
|
|
20
|
+
${this.serializerKey}: '<the_global_name_of_a_serializer>'
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
23
|
...
|
|
@@ -1,32 +1,28 @@
|
|
|
1
1
|
import pluralize from 'pluralize-esm';
|
|
2
|
-
import
|
|
2
|
+
import serializerGlobalNameFromFullyQualifiedModelName from '../../serializer/helpers/serializerGlobalNameFromFullyQualifiedModelName.js';
|
|
3
3
|
import camelize from '../camelize.js';
|
|
4
4
|
import globalClassNameFromFullyQualifiedModelName from '../globalClassNameFromFullyQualifiedModelName.js';
|
|
5
5
|
import relativeDreamPath from '../path/relativeDreamPath.js';
|
|
6
6
|
import snakeify from '../snakeify.js';
|
|
7
7
|
import standardizeFullyQualifiedModelName from '../standardizeFullyQualifiedModelName.js';
|
|
8
8
|
import uniq from '../uniq.js';
|
|
9
|
-
import { fullyQualifiedModelNameToSerializerBaseName } from './generateSerializerContent.js';
|
|
10
9
|
export default function generateDreamContent({ fullyQualifiedModelName, columnsWithTypes, fullyQualifiedParentName, serializer, }) {
|
|
11
10
|
fullyQualifiedModelName = standardizeFullyQualifiedModelName(fullyQualifiedModelName);
|
|
12
11
|
const modelClassName = globalClassNameFromFullyQualifiedModelName(fullyQualifiedModelName);
|
|
13
12
|
let parentModelClassName;
|
|
14
13
|
const dreamImports = ['Decorators', 'DreamColumn'];
|
|
14
|
+
if (serializer)
|
|
15
|
+
dreamImports.push('DreamSerializers');
|
|
15
16
|
const isSTI = !!fullyQualifiedParentName;
|
|
16
17
|
if (isSTI) {
|
|
17
18
|
fullyQualifiedParentName = standardizeFullyQualifiedModelName(fullyQualifiedParentName);
|
|
18
19
|
parentModelClassName = globalClassNameFromFullyQualifiedModelName(fullyQualifiedParentName);
|
|
19
20
|
dreamImports.push('STI');
|
|
20
21
|
}
|
|
21
|
-
const serialzerClassName = serializerNameFromFullyQualifiedModelName(fullyQualifiedModelNameToSerializerBaseName(fullyQualifiedModelName));
|
|
22
|
-
const summarySerialzerClassName = serializerNameFromFullyQualifiedModelName(fullyQualifiedModelNameToSerializerBaseName(fullyQualifiedModelName), 'summary');
|
|
23
22
|
const idTypescriptType = `DreamColumn<${modelClassName}, 'id'>`;
|
|
24
23
|
const modelImportStatements = isSTI
|
|
25
24
|
? [importStatementForModel(fullyQualifiedModelName, fullyQualifiedParentName)]
|
|
26
25
|
: [importStatementForModel(fullyQualifiedModelName, 'ApplicationModel')];
|
|
27
|
-
const serializerImportStatement = serializer
|
|
28
|
-
? importStatementForSerializers(fullyQualifiedModelName, serialzerClassName, summarySerialzerClassName)
|
|
29
|
-
: '';
|
|
30
26
|
const attributeStatements = columnsWithTypes.map(attribute => {
|
|
31
27
|
const [attributeName, attributeType, ...descriptors] = attribute.split(':');
|
|
32
28
|
if (attributeName === undefined)
|
|
@@ -77,7 +73,7 @@ public ${camelize(attributeName)}: ${getAttributeType(attribute, modelClassName)
|
|
|
77
73
|
timestamps = timestamps.replace(/\n$/, '');
|
|
78
74
|
const tableName = snakeify(pluralize(fullyQualifiedModelName.replace(/\//g, '_')));
|
|
79
75
|
return `\
|
|
80
|
-
import { ${uniq(dreamImports).join(', ')} } from '@rvoh/dream'${uniq(modelImportStatements).join('')}
|
|
76
|
+
import { ${uniq(dreamImports).join(', ')} } from '@rvoh/dream'${uniq(modelImportStatements).join('')}
|
|
81
77
|
|
|
82
78
|
const deco = new Decorators<typeof ${modelClassName}>()
|
|
83
79
|
|
|
@@ -90,10 +86,10 @@ ${isSTI
|
|
|
90
86
|
}
|
|
91
87
|
|
|
92
88
|
`}${serializer
|
|
93
|
-
? ` public ${isSTI ? 'override ' : ''}get serializers() {
|
|
89
|
+
? ` public ${isSTI ? 'override ' : ''}get serializers(): DreamSerializers<${modelClassName}> {
|
|
94
90
|
return {
|
|
95
|
-
default: ${
|
|
96
|
-
summary: ${
|
|
91
|
+
default: '${serializerGlobalNameFromFullyQualifiedModelName(fullyQualifiedModelName)}',
|
|
92
|
+
summary: '${serializerGlobalNameFromFullyQualifiedModelName(fullyQualifiedModelName, 'summary')}',
|
|
97
93
|
}
|
|
98
94
|
}
|
|
99
95
|
|
|
@@ -108,6 +104,3 @@ function getAttributeType(attribute, modelClassName) {
|
|
|
108
104
|
function importStatementForModel(originModelName, destinationModelName = originModelName) {
|
|
109
105
|
return `\nimport ${globalClassNameFromFullyQualifiedModelName(destinationModelName)} from '${relativeDreamPath('models', 'models', originModelName, destinationModelName)}'`;
|
|
110
106
|
}
|
|
111
|
-
function importStatementForSerializers(originModelName, serialzerClassName, summarySerialzerClassName) {
|
|
112
|
-
return `\nimport { ${serialzerClassName}, ${summarySerialzerClassName} } from '${relativeDreamPath('models', 'serializers', originModelName)}'`;
|
|
113
|
-
}
|
|
@@ -60,7 +60,7 @@ function attribute(name, type, attr) {
|
|
|
60
60
|
case 'jsonb':
|
|
61
61
|
case 'json[]':
|
|
62
62
|
case 'jsonb[]':
|
|
63
|
-
return `.
|
|
63
|
+
return `.attribute('${camelize(name)}', { openapi: { type: 'object', properties: { } } })`;
|
|
64
64
|
default:
|
|
65
65
|
return `.attribute('${camelize(name)}'${attributeOptionsSpecifier(type, attr)})`;
|
|
66
66
|
}
|
|
@@ -84,6 +84,6 @@ function importStatementForModel(originModelName, destinationModelName = originM
|
|
|
84
84
|
const importFrom = relativeDreamPath('serializers', 'models', originModelName, destinationModelName);
|
|
85
85
|
return `import ${modelName} from '${importFrom}'\n`;
|
|
86
86
|
}
|
|
87
|
-
|
|
87
|
+
function fullyQualifiedModelNameToSerializerBaseName(fullyQualifiedModelName) {
|
|
88
88
|
return fullyQualifiedModelName.replace(/\//g, '');
|
|
89
89
|
}
|
|
@@ -4,6 +4,8 @@ import compact from '../helpers/compact.js';
|
|
|
4
4
|
import { DateTime } from '../helpers/DateTime.js';
|
|
5
5
|
import round from '../helpers/round.js';
|
|
6
6
|
import snakeify from '../helpers/snakeify.js';
|
|
7
|
+
import DreamSerializerBuilder from './builders/DreamSerializerBuilder.js';
|
|
8
|
+
import ObjectSerializerBuilder from './builders/ObjectSerializerBuilder.js';
|
|
7
9
|
import inferSerializerFromDreamOrViewModel, { inferSerializersFromDreamClassOrViewModelClass, } from './helpers/inferSerializerFromDreamOrViewModel.js';
|
|
8
10
|
export default class SerializerRenderer {
|
|
9
11
|
serializerBuilder;
|
|
@@ -36,8 +38,8 @@ export default class SerializerRenderer {
|
|
|
36
38
|
////////////////
|
|
37
39
|
case 'attribute': {
|
|
38
40
|
const outputAttributeName = this.setCase(attribute.options?.as ?? attribute.name);
|
|
39
|
-
const value = data[attribute.name];
|
|
40
|
-
accumulator[outputAttributeName] = applyRenderingOptionsToAttribute(value, attribute.options);
|
|
41
|
+
const value = data[attribute.name] ?? attribute.options?.default;
|
|
42
|
+
accumulator[outputAttributeName] = applyRenderingOptionsToAttribute(value, attribute.options, this.passthroughData, this.renderOpts);
|
|
41
43
|
return accumulator;
|
|
42
44
|
}
|
|
43
45
|
/////////////////////
|
|
@@ -49,8 +51,8 @@ export default class SerializerRenderer {
|
|
|
49
51
|
case 'delegatedAttribute': {
|
|
50
52
|
const outputAttributeName = this.setCase(attribute.options?.as ?? attribute.name);
|
|
51
53
|
const target = data[attribute.targetName];
|
|
52
|
-
const value = target[attribute.name];
|
|
53
|
-
accumulator[outputAttributeName] = applyRenderingOptionsToAttribute(value, attribute.options);
|
|
54
|
+
const value = target[attribute.name] ?? attribute.options?.default;
|
|
55
|
+
accumulator[outputAttributeName] = applyRenderingOptionsToAttribute(value, attribute.options, this.passthroughData, this.renderOpts);
|
|
54
56
|
return accumulator;
|
|
55
57
|
}
|
|
56
58
|
//////////////////////////////
|
|
@@ -67,11 +69,11 @@ export default class SerializerRenderer {
|
|
|
67
69
|
if (attribute.options.flatten) {
|
|
68
70
|
return {
|
|
69
71
|
...accumulator,
|
|
70
|
-
...applyRenderingOptionsToAttribute(attribute.fn(), {}),
|
|
72
|
+
...applyRenderingOptionsToAttribute(attribute.fn(), {}, this.passthroughData, this.renderOpts),
|
|
71
73
|
};
|
|
72
74
|
}
|
|
73
75
|
else {
|
|
74
|
-
accumulator[outputAttributeName] = applyRenderingOptionsToAttribute(attribute.fn(), {});
|
|
76
|
+
accumulator[outputAttributeName] = applyRenderingOptionsToAttribute(attribute.fn(), {}, this.passthroughData, this.renderOpts);
|
|
75
77
|
return accumulator;
|
|
76
78
|
}
|
|
77
79
|
}
|
|
@@ -177,12 +179,14 @@ export default class SerializerRenderer {
|
|
|
177
179
|
}
|
|
178
180
|
}
|
|
179
181
|
}
|
|
180
|
-
function applyRenderingOptionsToAttribute(value, options) {
|
|
182
|
+
function applyRenderingOptionsToAttribute(value, options, passthroughData, renderOptions) {
|
|
181
183
|
if (Array.isArray(value))
|
|
182
|
-
return value.map(val => _applyRenderingOptionsToAttribute(val, options));
|
|
183
|
-
return _applyRenderingOptionsToAttribute(value, options);
|
|
184
|
+
return value.map(val => _applyRenderingOptionsToAttribute(val, options, passthroughData, renderOptions));
|
|
185
|
+
return _applyRenderingOptionsToAttribute(value, options, passthroughData, renderOptions);
|
|
184
186
|
}
|
|
185
|
-
function _applyRenderingOptionsToAttribute(value, options) {
|
|
187
|
+
function _applyRenderingOptionsToAttribute(value, options, passthroughData, renderOptions) {
|
|
188
|
+
if (value instanceof DreamSerializerBuilder || value instanceof ObjectSerializerBuilder)
|
|
189
|
+
return value.render(passthroughData, renderOptions);
|
|
186
190
|
if (value instanceof DateTime)
|
|
187
191
|
return value.toISO();
|
|
188
192
|
if (value instanceof CalendarDate)
|
|
@@ -29,14 +29,6 @@ export default class DreamSerializerBuilder {
|
|
|
29
29
|
});
|
|
30
30
|
return this;
|
|
31
31
|
}
|
|
32
|
-
jsonAttribute(name, options) {
|
|
33
|
-
this.attributes.push({
|
|
34
|
-
type: 'attribute',
|
|
35
|
-
name,
|
|
36
|
-
options,
|
|
37
|
-
});
|
|
38
|
-
return this;
|
|
39
|
-
}
|
|
40
32
|
customAttribute(name, fn, options) {
|
|
41
33
|
this.attributes.push({
|
|
42
34
|
type: 'customAttribute',
|
|
@@ -27,14 +27,6 @@ export default class ObjectSerializerBuilder {
|
|
|
27
27
|
});
|
|
28
28
|
return this;
|
|
29
29
|
}
|
|
30
|
-
jsonAttribute(name, options) {
|
|
31
|
-
this.attributes.push({
|
|
32
|
-
type: 'attribute',
|
|
33
|
-
name,
|
|
34
|
-
options,
|
|
35
|
-
});
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
30
|
customAttribute(name, fn, options) {
|
|
39
31
|
this.attributes.push({
|
|
40
32
|
type: 'customAttribute',
|
|
@@ -601,6 +601,9 @@ export default class Dream {
|
|
|
601
601
|
rootTableAlias: InstanceType<T> extends infer T_1 ? T_1 extends InstanceType<T> ? T_1 extends Dream ? T_1["table"] : T_1 : never : never;
|
|
602
602
|
allowPreload: true;
|
|
603
603
|
allowLeftJoinPreload: true;
|
|
604
|
+
allowLimit: true;
|
|
605
|
+
allowOffset: true;
|
|
606
|
+
allowPaginate: true;
|
|
604
607
|
}>>;
|
|
605
608
|
/**
|
|
606
609
|
* Finds a record for the corresponding model with the
|
|
@@ -790,6 +793,9 @@ export default class Dream {
|
|
|
790
793
|
rootTableAlias: InstanceType<T> extends infer T_1 ? T_1 extends InstanceType<T> ? T_1 extends Dream ? T_1["table"] : T_1 : never : never;
|
|
791
794
|
allowPreload: true;
|
|
792
795
|
allowLeftJoinPreload: false;
|
|
796
|
+
allowLimit: true;
|
|
797
|
+
allowOffset: true;
|
|
798
|
+
allowPaginate: true;
|
|
793
799
|
}>>;
|
|
794
800
|
/**
|
|
795
801
|
* Returns a new Query instance with the provided
|
|
@@ -912,11 +918,14 @@ export default class Dream {
|
|
|
912
918
|
* @returns A Query for this model with the limit clause applied
|
|
913
919
|
*/
|
|
914
920
|
static limit<T extends typeof Dream>(this: T, count: number | null): Query<InstanceType<T>, Readonly<{
|
|
915
|
-
joinedAssociations:
|
|
921
|
+
joinedAssociations: readonly [];
|
|
916
922
|
rootTableName: InstanceType<T>["table"];
|
|
917
923
|
rootTableAlias: InstanceType<T> extends infer T_1 ? T_1 extends InstanceType<T> ? T_1 extends Dream ? T_1["table"] : T_1 : never : never;
|
|
918
924
|
allowPreload: true;
|
|
919
|
-
allowLeftJoinPreload:
|
|
925
|
+
allowLeftJoinPreload: false;
|
|
926
|
+
allowLimit: true;
|
|
927
|
+
allowOffset: true;
|
|
928
|
+
allowPaginate: false;
|
|
920
929
|
}>>;
|
|
921
930
|
/**
|
|
922
931
|
* Returns a new Query instance, specifying an offset
|
|
@@ -929,11 +938,14 @@ export default class Dream {
|
|
|
929
938
|
* @returns A Query for this model with the offset clause applied
|
|
930
939
|
*/
|
|
931
940
|
static offset<T extends typeof Dream>(this: T, offset: number | null): Query<InstanceType<T>, Readonly<{
|
|
932
|
-
joinedAssociations:
|
|
941
|
+
joinedAssociations: readonly [];
|
|
933
942
|
rootTableName: InstanceType<T>["table"];
|
|
934
943
|
rootTableAlias: InstanceType<T> extends infer T_1 ? T_1 extends InstanceType<T> ? T_1 extends Dream ? T_1["table"] : T_1 : never : never;
|
|
935
944
|
allowPreload: true;
|
|
936
|
-
allowLeftJoinPreload:
|
|
945
|
+
allowLeftJoinPreload: false;
|
|
946
|
+
allowLimit: true;
|
|
947
|
+
allowOffset: true;
|
|
948
|
+
allowPaginate: false;
|
|
937
949
|
}>>;
|
|
938
950
|
/**
|
|
939
951
|
* Returns a new Query instance, attaching the provided
|
|
@@ -364,6 +364,9 @@ export default class DreamClassTransactionBuilder<DreamClass extends typeof Drea
|
|
|
364
364
|
rootTableAlias: DreamInstance extends Dream ? DreamInstance["table"] : DreamInstance;
|
|
365
365
|
allowPreload: true;
|
|
366
366
|
allowLeftJoinPreload: false;
|
|
367
|
+
allowLimit: true;
|
|
368
|
+
allowOffset: true;
|
|
369
|
+
allowPaginate: true;
|
|
367
370
|
}>>;
|
|
368
371
|
/**
|
|
369
372
|
* Returns a new Query instance with the provided
|
|
@@ -498,6 +501,9 @@ export default class DreamClassTransactionBuilder<DreamClass extends typeof Drea
|
|
|
498
501
|
rootTableAlias: DreamInstance extends Dream ? DreamInstance["table"] : DreamInstance;
|
|
499
502
|
allowPreload: true;
|
|
500
503
|
allowLeftJoinPreload: true;
|
|
504
|
+
allowLimit: true;
|
|
505
|
+
allowOffset: true;
|
|
506
|
+
allowPaginate: true;
|
|
501
507
|
}>>;
|
|
502
508
|
/**
|
|
503
509
|
* Plucks the provided fields from the corresponding model.
|
|
@@ -317,7 +317,10 @@ export default class Query<DreamInstance extends Dream, QueryTypeOpts extends Re
|
|
|
317
317
|
}> ? true : false, const JoinedAssociationsCandidate = JoinedAssociationsTypeFromAssociations<DB, Schema, TableName, Incompatible extends true ? [] : [...Arr, LastArg]>, const JoinedAssociations extends readonly JoinedAssociation[] = JoinedAssociationsCandidate extends readonly JoinedAssociation[] ? JoinedAssociationsCandidate : never, RetQuery = Query<DreamInstance, ExtendQueryType<QueryTypeOpts, Readonly<{
|
|
318
318
|
joinedAssociations: JoinedAssociations;
|
|
319
319
|
allowPreload: false;
|
|
320
|
-
|
|
320
|
+
allowLimit: false;
|
|
321
|
+
allowOffset: false;
|
|
322
|
+
allowPaginate: false;
|
|
323
|
+
}>>>>(this: Q, ...args: Incompatible extends true ? 'leftJoinPreload is incompatible with preload, limit, offset, and paginate'[] : [...Arr, LastArg]): RetQuery;
|
|
321
324
|
/**
|
|
322
325
|
* Load each specified association using a separate SQL query.
|
|
323
326
|
* See {@link #leftJoinPreload} for preloading in a single query.
|
|
@@ -577,7 +580,12 @@ export default class Query<DreamInstance extends Dream, QueryTypeOpts extends Re
|
|
|
577
580
|
*
|
|
578
581
|
* @returns A cloned Query with the limit clause applied
|
|
579
582
|
*/
|
|
580
|
-
limit
|
|
583
|
+
limit<Q extends Query<DreamInstance, any>, Incompatible extends Q['queryTypeOpts'] extends Readonly<{
|
|
584
|
+
allowLimit: false;
|
|
585
|
+
}> ? true : false, RetQuery = Query<DreamInstance, ExtendQueryType<QueryTypeOpts, Readonly<{
|
|
586
|
+
allowPaginate: false;
|
|
587
|
+
allowLeftJoinPreload: false;
|
|
588
|
+
}>>>>(this: Q, limit: Incompatible extends true ? 'limit is incompatible with paginate and leftJoinPreload'[] : number | null): RetQuery;
|
|
581
589
|
/**
|
|
582
590
|
* Returns a new Query instance, specifying an offset
|
|
583
591
|
*
|
|
@@ -588,7 +596,12 @@ export default class Query<DreamInstance extends Dream, QueryTypeOpts extends Re
|
|
|
588
596
|
*
|
|
589
597
|
* @returns A cloned Query with the offset clause applied
|
|
590
598
|
*/
|
|
591
|
-
offset
|
|
599
|
+
offset<Q extends Query<DreamInstance, any>, Incompatible extends Q['queryTypeOpts'] extends Readonly<{
|
|
600
|
+
allowOffset: false;
|
|
601
|
+
}> ? true : false, RetQuery = Query<DreamInstance, ExtendQueryType<QueryTypeOpts, Readonly<{
|
|
602
|
+
allowPaginate: false;
|
|
603
|
+
allowLeftJoinPreload: false;
|
|
604
|
+
}>>>>(this: Q, offset: Incompatible extends true ? 'offset is incompatible with paginate and leftJoinPreload'[] : number | null): RetQuery;
|
|
592
605
|
/**
|
|
593
606
|
* Returns the sql that would be executed by this Query
|
|
594
607
|
*
|
|
@@ -801,7 +814,9 @@ export default class Query<DreamInstance extends Dream, QueryTypeOpts extends Re
|
|
|
801
814
|
* @returns results.currentPage - The current page (same as what is provided in the paginate args)
|
|
802
815
|
* @returns results.results - An array of records matching the current record
|
|
803
816
|
*/
|
|
804
|
-
paginate
|
|
817
|
+
paginate<Q extends Query<DreamInstance, any>, Incompatible extends Q['queryTypeOpts'] extends Readonly<{
|
|
818
|
+
allowPaginate: false;
|
|
819
|
+
}> ? true : false>(this: Q, opts: Incompatible extends true ? 'paginate is incompatible with limit, offset, and leftJoinPreload'[] : PaginatedDreamQueryOptions): Promise<PaginatedDreamQueryResult<DreamInstance>>;
|
|
805
820
|
/**
|
|
806
821
|
* Forces use of a database connection (e.g. 'primary') during the query.
|
|
807
822
|
*
|
|
@@ -10,4 +10,7 @@ export default function applyScopeBypassingSettingsToQuery<DreamInstance extends
|
|
|
10
10
|
rootTableAlias: DreamInstance extends Dream ? DreamInstance["table"] : DreamInstance;
|
|
11
11
|
allowPreload: true;
|
|
12
12
|
allowLeftJoinPreload: true;
|
|
13
|
+
allowLimit: true;
|
|
14
|
+
allowOffset: true;
|
|
15
|
+
allowPaginate: true;
|
|
13
16
|
}>>;
|
|
@@ -4,4 +4,3 @@ export default function generateSerializerContent({ fullyQualifiedModelName, col
|
|
|
4
4
|
fullyQualifiedParentName?: string | undefined;
|
|
5
5
|
stiBaseSerializer?: boolean;
|
|
6
6
|
}): string;
|
|
7
|
-
export declare function fullyQualifiedModelNameToSerializerBaseName(fullyQualifiedModelName: string): string;
|