@rvoh/dream 2.40.1 → 2.40.2
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-app/index.js +17 -10
- package/dist/cjs/src/serializer/DreamSerializer.js +15 -9
- package/dist/cjs/src/serializer/ObjectSerializer.js +15 -9
- package/dist/cjs/src/serializer/SerializerRenderer.js +2 -2
- package/dist/cjs/src/serializer/helpers/nullFlattenedSerializerKeys.js +6 -5
- package/dist/esm/src/dream-app/index.js +17 -10
- package/dist/esm/src/serializer/DreamSerializer.js +15 -9
- package/dist/esm/src/serializer/ObjectSerializer.js +15 -9
- package/dist/esm/src/serializer/SerializerRenderer.js +2 -2
- package/dist/esm/src/serializer/helpers/nullFlattenedSerializerKeys.js +6 -5
- package/dist/types/src/dream-app/index.d.ts +17 -10
- package/dist/types/src/serializer/DreamSerializer.d.ts +15 -9
- package/dist/types/src/serializer/ObjectSerializer.d.ts +15 -9
- package/dist/types/src/serializer/helpers/nullFlattenedSerializerKeys.d.ts +3 -3
- package/docs/classes/db.DreamMigrationHelpers.html +11 -11
- package/docs/classes/db.KyselyQueryDriver.html +49 -49
- package/docs/classes/db.PostgresQueryDriver.html +49 -49
- package/docs/classes/db.QueryDriverBase.html +49 -49
- package/docs/classes/errors.CannotSaveMissingDream.html +2 -2
- package/docs/classes/errors.CheckConstraintViolation.html +3 -3
- package/docs/classes/errors.ColumnOverflow.html +3 -3
- package/docs/classes/errors.CreateOrFindByFailedToCreateAndFind.html +3 -3
- package/docs/classes/errors.DataIncompatibleWithDatabaseField.html +3 -3
- package/docs/classes/errors.DataTypeColumnTypeMismatch.html +3 -3
- package/docs/classes/errors.DecryptionError.html +2 -2
- package/docs/classes/errors.DecryptionParseError.html +2 -2
- package/docs/classes/errors.DecryptionRotationError.html +3 -3
- package/docs/classes/errors.GlobalNameNotSet.html +3 -3
- package/docs/classes/errors.InvalidCalendarDate.html +2 -2
- package/docs/classes/errors.InvalidClockTime.html +2 -2
- package/docs/classes/errors.InvalidClockTimeTz.html +2 -2
- package/docs/classes/errors.InvalidDateTime.html +2 -2
- package/docs/classes/errors.MissingSerializersDefinition.html +3 -3
- package/docs/classes/errors.NonLoadedAssociation.html +3 -3
- package/docs/classes/errors.NotNullViolation.html +3 -3
- package/docs/classes/errors.RecordNotFound.html +3 -3
- package/docs/classes/errors.SortableScopeDidNotStabilize.html +3 -3
- package/docs/classes/errors.SortableScopeLockWaitTimedOut.html +3 -3
- package/docs/classes/errors.ValidationError.html +3 -3
- package/docs/classes/index.CalendarDate.html +33 -33
- package/docs/classes/index.ClockTime.html +32 -32
- package/docs/classes/index.ClockTimeTz.html +35 -35
- package/docs/classes/index.DateTime.html +86 -86
- package/docs/classes/index.Decorators.html +19 -19
- package/docs/classes/index.Dream.html +125 -125
- package/docs/classes/index.DreamApp.html +24 -21
- package/docs/classes/index.DreamTransaction.html +3 -3
- package/docs/classes/index.Env.html +5 -5
- package/docs/classes/index.Query.html +65 -65
- package/docs/classes/system.CliFileWriter.html +4 -4
- package/docs/classes/system.DreamBin.html +3 -3
- package/docs/classes/system.DreamCLI.html +7 -7
- package/docs/classes/system.DreamImporter.html +2 -2
- package/docs/classes/system.DreamLogos.html +2 -2
- package/docs/classes/system.DreamSerializerBuilder.html +11 -11
- package/docs/classes/system.ObjectSerializerBuilder.html +8 -8
- package/docs/classes/system.PathHelpers.html +3 -3
- package/docs/classes/utils.Encrypt.html +4 -4
- package/docs/classes/utils.Range.html +2 -2
- package/docs/functions/db.closeAllDbConnections.html +1 -1
- package/docs/functions/db.dreamDbConnections.html +1 -1
- package/docs/functions/db.untypedDb.html +1 -1
- package/docs/functions/db.validateColumn.html +1 -1
- package/docs/functions/db.validateTable.html +1 -1
- package/docs/functions/errors.pgErrorType.html +1 -1
- package/docs/functions/index.DreamSerializer.html +16 -10
- package/docs/functions/index.ObjectSerializer.html +16 -10
- package/docs/functions/index.ReplicaSafe.html +1 -1
- package/docs/functions/index.STI.html +1 -1
- package/docs/functions/index.SoftDelete.html +1 -1
- package/docs/functions/utils.camelize.html +1 -1
- package/docs/functions/utils.capitalize.html +1 -1
- package/docs/functions/utils.cloneDeepSafe.html +1 -1
- package/docs/functions/utils.compact.html +1 -1
- package/docs/functions/utils.groupBy.html +1 -1
- package/docs/functions/utils.hyphenize.html +1 -1
- package/docs/functions/utils.intersection.html +1 -1
- package/docs/functions/utils.isEmpty.html +1 -1
- package/docs/functions/utils.normalizeUnicode.html +1 -1
- package/docs/functions/utils.pascalize.html +1 -1
- package/docs/functions/utils.percent.html +1 -1
- package/docs/functions/utils.range.html +1 -1
- package/docs/functions/utils.round.html +1 -1
- package/docs/functions/utils.sanitizeString.html +1 -1
- package/docs/functions/utils.snakeify.html +1 -1
- package/docs/functions/utils.sort.html +1 -1
- package/docs/functions/utils.sortBy.html +1 -1
- package/docs/functions/utils.sortObjectByKey.html +1 -1
- package/docs/functions/utils.sortObjectByValue.html +1 -1
- package/docs/functions/utils.uncapitalize.html +1 -1
- package/docs/functions/utils.uniq.html +1 -1
- package/docs/interfaces/openapi.OpenapiDescription.html +2 -2
- package/docs/interfaces/openapi.OpenapiSchemaProperties.html +1 -1
- package/docs/interfaces/openapi.OpenapiSchemaPropertiesShorthand.html +1 -1
- package/docs/interfaces/openapi.OpenapiTypeFieldObject.html +1 -1
- package/docs/interfaces/types.BelongsToStatement.html +2 -2
- package/docs/interfaces/types.DecoratorContext.html +2 -2
- package/docs/interfaces/types.DecryptCallbacks.html +2 -2
- package/docs/interfaces/types.DreamAppInitOptions.html +2 -2
- package/docs/interfaces/types.DreamAppOpts.html +2 -2
- package/docs/interfaces/types.DreamDbConfig.html +6 -6
- package/docs/interfaces/types.DurationObject.html +2 -2
- package/docs/interfaces/types.EncryptOptions.html +2 -2
- package/docs/interfaces/types.EncryptionLegacyKeyUsedEvent.html +4 -4
- package/docs/interfaces/types.InternalAnyTypedSerializerRendersMany.html +2 -2
- package/docs/interfaces/types.InternalAnyTypedSerializerRendersOne.html +2 -2
- package/docs/interfaces/types.IntrospectedColumn.html +7 -7
- package/docs/interfaces/types.IntrospectedDatabase.html +2 -2
- package/docs/interfaces/types.IntrospectedEnum.html +2 -2
- package/docs/interfaces/types.IntrospectedTable.html +5 -5
- package/docs/interfaces/types.SerializerRendererOpts.html +2 -2
- package/docs/types/openapi.CommonOpenapiSchemaObjectFields.html +1 -1
- package/docs/types/openapi.OpenapiAllTypes.html +1 -1
- package/docs/types/openapi.OpenapiFormats.html +1 -1
- package/docs/types/openapi.OpenapiNumberFormats.html +1 -1
- package/docs/types/openapi.OpenapiPrimitiveBaseTypes.html +1 -1
- package/docs/types/openapi.OpenapiPrimitiveTypes.html +1 -1
- package/docs/types/openapi.OpenapiSchemaArray.html +1 -1
- package/docs/types/openapi.OpenapiSchemaArrayShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaBase.html +1 -1
- package/docs/types/openapi.OpenapiSchemaBody.html +1 -1
- package/docs/types/openapi.OpenapiSchemaBodyShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaCombinatorFields.html +1 -1
- package/docs/types/openapi.OpenapiSchemaCommonFields.html +1 -1
- package/docs/types/openapi.OpenapiSchemaExpressionAllOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaExpressionAnyOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaExpressionOneOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaExpressionRef.html +2 -2
- package/docs/types/openapi.OpenapiSchemaExpressionRefSchemaShorthand.html +2 -2
- package/docs/types/openapi.OpenapiSchemaInteger.html +1 -1
- package/docs/types/openapi.OpenapiSchemaNull.html +2 -2
- package/docs/types/openapi.OpenapiSchemaNumber.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObject.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAllOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAllOfShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectBase.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectBaseShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaPrimitiveGeneric.html +1 -1
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionAllOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionOneOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializableRef.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionSerializerRef.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
- package/docs/types/openapi.OpenapiSchemaString.html +1 -1
- package/docs/types/openapi.OpenapiShorthandAllTypes.html +1 -1
- package/docs/types/openapi.OpenapiShorthandPrimitiveBaseTypes.html +1 -1
- package/docs/types/openapi.OpenapiShorthandPrimitiveTypes.html +1 -1
- package/docs/types/openapi.OpenapiTypeField.html +1 -1
- package/docs/types/system.DreamAppAllowedPackageManagersEnum.html +1 -1
- package/docs/types/types.CalendarDateDurationUnit.html +1 -1
- package/docs/types/types.CalendarDateObject.html +1 -1
- package/docs/types/types.Camelized.html +1 -1
- package/docs/types/types.ClockTimeObject.html +1 -1
- package/docs/types/types.DbConnectionType.html +1 -1
- package/docs/types/types.DbTypes.html +1 -1
- package/docs/types/types.DreamAssociationMetadata.html +1 -1
- package/docs/types/types.DreamAttributes.html +1 -1
- package/docs/types/types.DreamClassAssociationAndStatement.html +1 -1
- package/docs/types/types.DreamClassColumn.html +1 -1
- package/docs/types/types.DreamColumn.html +1 -1
- package/docs/types/types.DreamColumnNames.html +1 -1
- package/docs/types/types.DreamLogLevel.html +1 -1
- package/docs/types/types.DreamLogger.html +2 -2
- package/docs/types/types.DreamModelSerializerType.html +1 -1
- package/docs/types/types.DreamOrViewModelClassSerializerKey.html +1 -1
- package/docs/types/types.DreamOrViewModelSerializerKey.html +1 -1
- package/docs/types/types.DreamParamSafeAttributes.html +1 -1
- package/docs/types/types.DreamParamSafeColumnNames.html +1 -1
- package/docs/types/types.DreamSerializable.html +1 -1
- package/docs/types/types.DreamSerializableArray.html +1 -1
- package/docs/types/types.DreamSerializerKey.html +1 -1
- package/docs/types/types.DreamSerializers.html +1 -1
- package/docs/types/types.DreamVirtualColumns.html +1 -1
- package/docs/types/types.DurationUnit.html +1 -1
- package/docs/types/types.EncryptAlgorithm.html +1 -1
- package/docs/types/types.HasManyStatement.html +1 -1
- package/docs/types/types.HasOneStatement.html +1 -1
- package/docs/types/types.Hyphenized.html +1 -1
- package/docs/types/types.IntrospectedValueType.html +1 -1
- package/docs/types/types.Pascalized.html +1 -1
- package/docs/types/types.PrimaryKeyType.html +1 -1
- package/docs/types/types.RoundingPrecision.html +1 -1
- package/docs/types/types.SerializerCasing.html +1 -1
- package/docs/types/types.SimpleObjectSerializerType.html +1 -1
- package/docs/types/types.Snakeified.html +1 -1
- package/docs/types/types.StrictInterface.html +1 -1
- package/docs/types/types.UpdateableAssociationProperties.html +1 -1
- package/docs/types/types.UpdateableProperties.html +1 -1
- package/docs/types/types.ValidationType.html +1 -1
- package/docs/types/types.ViewModel.html +2 -2
- package/docs/types/types.ViewModelClass.html +1 -1
- package/docs/types/types.WeekdayName.html +1 -1
- package/docs/types/types.WhereStatementForDream.html +1 -1
- package/docs/types/types.WhereStatementForDreamClass.html +1 -1
- package/docs/variables/index.DreamConst.html +1 -1
- package/docs/variables/index.ops.html +1 -1
- package/docs/variables/openapi.openapiPrimitiveTypes.html +1 -1
- package/docs/variables/openapi.openapiShorthandPrimitiveTypes.html +1 -1
- package/docs/variables/system.DreamAppAllowedPackageManagersEnumValues.html +1 -1
- package/docs/variables/system.primaryKeyTypes.html +1 -1
- package/package.json +1 -1
|
@@ -270,6 +270,16 @@ export default class DreamApp {
|
|
|
270
270
|
return this._packageManager;
|
|
271
271
|
}
|
|
272
272
|
_importExtension = '.js';
|
|
273
|
+
/**
|
|
274
|
+
* The import suffix the CLI generators write: `.js`, `.ts` or `none`.
|
|
275
|
+
*
|
|
276
|
+
* In a Psychic app, set it in conf/app.ts with
|
|
277
|
+
* `psy.set('importExtension', …)`. Psychic forwards it here, and a different
|
|
278
|
+
* value set in conf/dream.ts throws at boot. In a Dream-only app, set it in
|
|
279
|
+
* conf/dream.ts with `dreamApp.set('importExtension', …)`.
|
|
280
|
+
*
|
|
281
|
+
* Defaults to `.js`.
|
|
282
|
+
*/
|
|
273
283
|
get importExtension() {
|
|
274
284
|
return this._importExtension;
|
|
275
285
|
}
|
|
@@ -277,20 +287,17 @@ export default class DreamApp {
|
|
|
277
287
|
/**
|
|
278
288
|
* The prefix of the import aliases the CLI generators write: the `@` in
|
|
279
289
|
* `@models/User.js`, `@serializers/UserSerializer.js` and
|
|
280
|
-
* `@spec/factories/UserFactory.js`. Set
|
|
281
|
-
* `dreamApp.set('importAliasPrefix', '#')` to have them write
|
|
290
|
+
* `@spec/factories/UserFactory.js`. Set it to `#` to have them write
|
|
282
291
|
* `#models/User.js` and so on, which Node resolves as subpath imports
|
|
283
292
|
* declared under `imports` in the app's package.json.
|
|
284
293
|
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
294
|
+
* In a Psychic app, set it in conf/app.ts with
|
|
295
|
+
* `psy.set('importAliasPrefix', '#')`. Psychic forwards it here, and a
|
|
296
|
+
* different value set in conf/dream.ts throws at boot. In a Dream-only app,
|
|
297
|
+
* set it in conf/dream.ts with `dreamApp.set('importAliasPrefix', '#')`.
|
|
288
298
|
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
* Psychic reads this setting (planned for 3.17.0), so a Psychic app should
|
|
292
|
-
* keep its `@spec` alias, or wait for that release, before switching to
|
|
293
|
-
* `#` only.
|
|
299
|
+
* Defaults to `@`. The default becomes `#` in Dream 3; an app that wants
|
|
300
|
+
* to keep `@` should set it to `@` explicitly.
|
|
294
301
|
*/
|
|
295
302
|
get importAliasPrefix() {
|
|
296
303
|
return this._importAliasPrefix;
|
|
@@ -8,18 +8,24 @@ import DreamSerializerBuilder from './builders/DreamSerializerBuilder.js';
|
|
|
8
8
|
* DreamSerializer(User, user).attribute('email').rendersMany('posts')
|
|
9
9
|
* ```
|
|
10
10
|
*
|
|
11
|
-
* A serializer must not read its data while being built: what it
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
11
|
+
* A serializer must not read its data or its passthrough data while being built: what it
|
|
12
|
+
* declares (which keys, under which names, and which associations it renders) may not
|
|
13
|
+
* depend on either. Dream and Psychic build it without data to read its shape (the OpenAPI
|
|
14
|
+
* schema, the associations `preloadFor` loads, and the keys a flattened association or
|
|
15
|
+
* `customAttribute` that uses it renders as `null` where its value does not supply them),
|
|
16
|
+
* and without passthrough data when registering it, preloading and generating OpenAPI. A
|
|
17
|
+
* serializer that reads its data while being built throws when a flattened association or
|
|
18
|
+
* `customAttribute` that uses it is rendered; one that reads its passthrough data is never
|
|
19
|
+
* registered, or renders keys and associations its OpenAPI schema and `preloadFor` do not
|
|
20
|
+
* describe. Read either inside a `customAttribute` callback, which runs only when the
|
|
21
|
+
* serializer renders, not while it is built, and hand passthrough data on to the
|
|
22
|
+
* serializers it renders.
|
|
18
23
|
*
|
|
19
24
|
* @param dreamClass - The Dream model class the serializer renders
|
|
20
25
|
* @param data - The Dream instance to render
|
|
21
|
-
* @param passthroughData - Data available to this serializer
|
|
22
|
-
* it renders
|
|
26
|
+
* @param passthroughData - Data available to this serializer's callbacks when it renders,
|
|
27
|
+
* and passed down to the serializers it renders. It must not decide what the serializer
|
|
28
|
+
* declares.
|
|
23
29
|
* @returns The serializer builder for method chaining
|
|
24
30
|
*/
|
|
25
31
|
export default function DreamSerializer(dreamClass, data, passthroughData) {
|
|
@@ -8,17 +8,23 @@ import ObjectSerializerBuilder from './builders/ObjectSerializerBuilder.js';
|
|
|
8
8
|
* ObjectSerializer(address).attribute('city', { openapi: 'string' })
|
|
9
9
|
* ```
|
|
10
10
|
*
|
|
11
|
-
* A serializer must not read its data while being built: what it
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
11
|
+
* A serializer must not read its data or its passthrough data while being built: what it
|
|
12
|
+
* declares (which keys, under which names, and which associations it renders) may not
|
|
13
|
+
* depend on either. Dream and Psychic build it without data to read its shape (the OpenAPI
|
|
14
|
+
* schema, the associations `preloadFor` loads, and the keys a flattened association or
|
|
15
|
+
* `customAttribute` that uses it renders as `null` where its value does not supply them),
|
|
16
|
+
* and without passthrough data when registering it, preloading and generating OpenAPI. A
|
|
17
|
+
* serializer that reads its data while being built throws when a flattened association or
|
|
18
|
+
* `customAttribute` that uses it is rendered; one that reads its passthrough data is never
|
|
19
|
+
* registered, or renders keys and associations its OpenAPI schema and `preloadFor` do not
|
|
20
|
+
* describe. Read either inside a `customAttribute` callback, which runs only when the
|
|
21
|
+
* serializer renders, not while it is built, and hand passthrough data on to the
|
|
22
|
+
* serializers it renders.
|
|
18
23
|
*
|
|
19
24
|
* @param data - The object to render
|
|
20
|
-
* @param passthroughData - Data available to this serializer
|
|
21
|
-
* it renders
|
|
25
|
+
* @param passthroughData - Data available to this serializer's callbacks when it renders,
|
|
26
|
+
* and passed down to the serializers it renders. It must not decide what the serializer
|
|
27
|
+
* declares.
|
|
22
28
|
* @returns The serializer builder for method chaining
|
|
23
29
|
*/
|
|
24
30
|
export default function ObjectSerializer(data, passthroughData) {
|
|
@@ -78,7 +78,7 @@ export default class SerializerRenderer {
|
|
|
78
78
|
if (value === undefined && attribute.options?.required === false)
|
|
79
79
|
return accumulator;
|
|
80
80
|
if (attribute.options.flatten) {
|
|
81
|
-
const flattenOptions = { casing: this.renderOpts.casing
|
|
81
|
+
const flattenOptions = { casing: this.renderOpts.casing };
|
|
82
82
|
// a flattened customAttribute's keys are the parent's own keys, cased like them, and
|
|
83
83
|
// always include each key any shape of its openapi requires: a callback that returns
|
|
84
84
|
// null or undefined, or a serializer built over null or undefined data (which renders
|
|
@@ -130,7 +130,7 @@ export default class SerializerRenderer {
|
|
|
130
130
|
// render with (each STI child, each polymorphic target) requires: as null when the
|
|
131
131
|
// associated object is null, and beneath the rendered serializer's own keys when it is
|
|
132
132
|
// present, so a required key the rendered serializer leaves out renders as null
|
|
133
|
-
...nullFlattenedSerializerKeys(serializersForAssociatedClass(data instanceof Dream ? data.constructor : null, attribute.name, attribute.options), { casing: this.renderOpts.casing
|
|
133
|
+
...nullFlattenedSerializerKeys(serializersForAssociatedClass(data instanceof Dream ? data.constructor : null, attribute.name, attribute.options), { casing: this.renderOpts.casing }),
|
|
134
134
|
// passthrough data must be passed both into the serializer and render
|
|
135
135
|
// because, if the serializer does accept passthrough data, then passing it in is how
|
|
136
136
|
// it gets into the serializer, but if it does not accept passthrough data, and therefore
|
|
@@ -30,8 +30,9 @@ import { serializersForAssociatedClass } from './serializersForAssociatedClass.j
|
|
|
30
30
|
* flattens itself, adds nothing, so the walk always terminates; one reached again along another
|
|
31
31
|
* path is walked again, so each path adds its keys and their requirements.
|
|
32
32
|
*
|
|
33
|
-
*
|
|
34
|
-
* render
|
|
33
|
+
* Each serializer is built with empty passthrough data, as Psychic's OpenAPI generation builds it,
|
|
34
|
+
* so the keys are the same whatever passthrough data a render carries: what a serializer declares
|
|
35
|
+
* must not depend on its passthrough data.
|
|
35
36
|
*/
|
|
36
37
|
export function nullFlattenedSerializerKeys(serializers, options = {}) {
|
|
37
38
|
return nullRequiredKeys(walkSerializers(serializers, newWalk(options)));
|
|
@@ -105,8 +106,8 @@ export function flattenedOpenapiVariants(openapi) {
|
|
|
105
106
|
const sharedMembers = ('allOf' in openapi && openapi.allOf) || [];
|
|
106
107
|
return sharedMembers.length ? variants.map(variant => ({ allOf: [...sharedMembers, variant] })) : variants;
|
|
107
108
|
}
|
|
108
|
-
function newWalk({ casing = 'camel'
|
|
109
|
-
return { casing,
|
|
109
|
+
function newWalk({ casing = 'camel' }) {
|
|
110
|
+
return { casing, serializersBeingFlattened: new Set() };
|
|
110
111
|
}
|
|
111
112
|
function nullRequiredKeys(requirements) {
|
|
112
113
|
return Object.keys(requirements).reduce((keys, key) => {
|
|
@@ -139,7 +140,7 @@ function walkSerializers(serializers, walk) {
|
|
|
139
140
|
if (walk.serializersBeingFlattened.has(serializer))
|
|
140
141
|
return flattenedKeys;
|
|
141
142
|
walk.serializersBeingFlattened.add(serializer);
|
|
142
|
-
const serializerBuilder = serializer(undefined,
|
|
143
|
+
const serializerBuilder = serializer(undefined, {});
|
|
143
144
|
const serializerKeys = walkSerializerBuilder(serializerBuilder, walk);
|
|
144
145
|
walk.serializersBeingFlattened.delete(serializer);
|
|
145
146
|
return mergeRequirements(flattenedKeys, serializerKeys);
|
|
@@ -270,6 +270,16 @@ export default class DreamApp {
|
|
|
270
270
|
return this._packageManager;
|
|
271
271
|
}
|
|
272
272
|
_importExtension = '.js';
|
|
273
|
+
/**
|
|
274
|
+
* The import suffix the CLI generators write: `.js`, `.ts` or `none`.
|
|
275
|
+
*
|
|
276
|
+
* In a Psychic app, set it in conf/app.ts with
|
|
277
|
+
* `psy.set('importExtension', …)`. Psychic forwards it here, and a different
|
|
278
|
+
* value set in conf/dream.ts throws at boot. In a Dream-only app, set it in
|
|
279
|
+
* conf/dream.ts with `dreamApp.set('importExtension', …)`.
|
|
280
|
+
*
|
|
281
|
+
* Defaults to `.js`.
|
|
282
|
+
*/
|
|
273
283
|
get importExtension() {
|
|
274
284
|
return this._importExtension;
|
|
275
285
|
}
|
|
@@ -277,20 +287,17 @@ export default class DreamApp {
|
|
|
277
287
|
/**
|
|
278
288
|
* The prefix of the import aliases the CLI generators write: the `@` in
|
|
279
289
|
* `@models/User.js`, `@serializers/UserSerializer.js` and
|
|
280
|
-
* `@spec/factories/UserFactory.js`. Set
|
|
281
|
-
* `dreamApp.set('importAliasPrefix', '#')` to have them write
|
|
290
|
+
* `@spec/factories/UserFactory.js`. Set it to `#` to have them write
|
|
282
291
|
* `#models/User.js` and so on, which Node resolves as subpath imports
|
|
283
292
|
* declared under `imports` in the app's package.json.
|
|
284
293
|
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
294
|
+
* In a Psychic app, set it in conf/app.ts with
|
|
295
|
+
* `psy.set('importAliasPrefix', '#')`. Psychic forwards it here, and a
|
|
296
|
+
* different value set in conf/dream.ts throws at boot. In a Dream-only app,
|
|
297
|
+
* set it in conf/dream.ts with `dreamApp.set('importAliasPrefix', '#')`.
|
|
288
298
|
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
* Psychic reads this setting (planned for 3.17.0), so a Psychic app should
|
|
292
|
-
* keep its `@spec` alias, or wait for that release, before switching to
|
|
293
|
-
* `#` only.
|
|
299
|
+
* Defaults to `@`. The default becomes `#` in Dream 3; an app that wants
|
|
300
|
+
* to keep `@` should set it to `@` explicitly.
|
|
294
301
|
*/
|
|
295
302
|
get importAliasPrefix() {
|
|
296
303
|
return this._importAliasPrefix;
|
|
@@ -8,18 +8,24 @@ import DreamSerializerBuilder from './builders/DreamSerializerBuilder.js';
|
|
|
8
8
|
* DreamSerializer(User, user).attribute('email').rendersMany('posts')
|
|
9
9
|
* ```
|
|
10
10
|
*
|
|
11
|
-
* A serializer must not read its data while being built: what it
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
11
|
+
* A serializer must not read its data or its passthrough data while being built: what it
|
|
12
|
+
* declares (which keys, under which names, and which associations it renders) may not
|
|
13
|
+
* depend on either. Dream and Psychic build it without data to read its shape (the OpenAPI
|
|
14
|
+
* schema, the associations `preloadFor` loads, and the keys a flattened association or
|
|
15
|
+
* `customAttribute` that uses it renders as `null` where its value does not supply them),
|
|
16
|
+
* and without passthrough data when registering it, preloading and generating OpenAPI. A
|
|
17
|
+
* serializer that reads its data while being built throws when a flattened association or
|
|
18
|
+
* `customAttribute` that uses it is rendered; one that reads its passthrough data is never
|
|
19
|
+
* registered, or renders keys and associations its OpenAPI schema and `preloadFor` do not
|
|
20
|
+
* describe. Read either inside a `customAttribute` callback, which runs only when the
|
|
21
|
+
* serializer renders, not while it is built, and hand passthrough data on to the
|
|
22
|
+
* serializers it renders.
|
|
18
23
|
*
|
|
19
24
|
* @param dreamClass - The Dream model class the serializer renders
|
|
20
25
|
* @param data - The Dream instance to render
|
|
21
|
-
* @param passthroughData - Data available to this serializer
|
|
22
|
-
* it renders
|
|
26
|
+
* @param passthroughData - Data available to this serializer's callbacks when it renders,
|
|
27
|
+
* and passed down to the serializers it renders. It must not decide what the serializer
|
|
28
|
+
* declares.
|
|
23
29
|
* @returns The serializer builder for method chaining
|
|
24
30
|
*/
|
|
25
31
|
export default function DreamSerializer(dreamClass, data, passthroughData) {
|
|
@@ -8,17 +8,23 @@ import ObjectSerializerBuilder from './builders/ObjectSerializerBuilder.js';
|
|
|
8
8
|
* ObjectSerializer(address).attribute('city', { openapi: 'string' })
|
|
9
9
|
* ```
|
|
10
10
|
*
|
|
11
|
-
* A serializer must not read its data while being built: what it
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
11
|
+
* A serializer must not read its data or its passthrough data while being built: what it
|
|
12
|
+
* declares (which keys, under which names, and which associations it renders) may not
|
|
13
|
+
* depend on either. Dream and Psychic build it without data to read its shape (the OpenAPI
|
|
14
|
+
* schema, the associations `preloadFor` loads, and the keys a flattened association or
|
|
15
|
+
* `customAttribute` that uses it renders as `null` where its value does not supply them),
|
|
16
|
+
* and without passthrough data when registering it, preloading and generating OpenAPI. A
|
|
17
|
+
* serializer that reads its data while being built throws when a flattened association or
|
|
18
|
+
* `customAttribute` that uses it is rendered; one that reads its passthrough data is never
|
|
19
|
+
* registered, or renders keys and associations its OpenAPI schema and `preloadFor` do not
|
|
20
|
+
* describe. Read either inside a `customAttribute` callback, which runs only when the
|
|
21
|
+
* serializer renders, not while it is built, and hand passthrough data on to the
|
|
22
|
+
* serializers it renders.
|
|
18
23
|
*
|
|
19
24
|
* @param data - The object to render
|
|
20
|
-
* @param passthroughData - Data available to this serializer
|
|
21
|
-
* it renders
|
|
25
|
+
* @param passthroughData - Data available to this serializer's callbacks when it renders,
|
|
26
|
+
* and passed down to the serializers it renders. It must not decide what the serializer
|
|
27
|
+
* declares.
|
|
22
28
|
* @returns The serializer builder for method chaining
|
|
23
29
|
*/
|
|
24
30
|
export default function ObjectSerializer(data, passthroughData) {
|
|
@@ -78,7 +78,7 @@ export default class SerializerRenderer {
|
|
|
78
78
|
if (value === undefined && attribute.options?.required === false)
|
|
79
79
|
return accumulator;
|
|
80
80
|
if (attribute.options.flatten) {
|
|
81
|
-
const flattenOptions = { casing: this.renderOpts.casing
|
|
81
|
+
const flattenOptions = { casing: this.renderOpts.casing };
|
|
82
82
|
// a flattened customAttribute's keys are the parent's own keys, cased like them, and
|
|
83
83
|
// always include each key any shape of its openapi requires: a callback that returns
|
|
84
84
|
// null or undefined, or a serializer built over null or undefined data (which renders
|
|
@@ -130,7 +130,7 @@ export default class SerializerRenderer {
|
|
|
130
130
|
// render with (each STI child, each polymorphic target) requires: as null when the
|
|
131
131
|
// associated object is null, and beneath the rendered serializer's own keys when it is
|
|
132
132
|
// present, so a required key the rendered serializer leaves out renders as null
|
|
133
|
-
...nullFlattenedSerializerKeys(serializersForAssociatedClass(data instanceof Dream ? data.constructor : null, attribute.name, attribute.options), { casing: this.renderOpts.casing
|
|
133
|
+
...nullFlattenedSerializerKeys(serializersForAssociatedClass(data instanceof Dream ? data.constructor : null, attribute.name, attribute.options), { casing: this.renderOpts.casing }),
|
|
134
134
|
// passthrough data must be passed both into the serializer and render
|
|
135
135
|
// because, if the serializer does accept passthrough data, then passing it in is how
|
|
136
136
|
// it gets into the serializer, but if it does not accept passthrough data, and therefore
|
|
@@ -30,8 +30,9 @@ import { serializersForAssociatedClass } from './serializersForAssociatedClass.j
|
|
|
30
30
|
* flattens itself, adds nothing, so the walk always terminates; one reached again along another
|
|
31
31
|
* path is walked again, so each path adds its keys and their requirements.
|
|
32
32
|
*
|
|
33
|
-
*
|
|
34
|
-
* render
|
|
33
|
+
* Each serializer is built with empty passthrough data, as Psychic's OpenAPI generation builds it,
|
|
34
|
+
* so the keys are the same whatever passthrough data a render carries: what a serializer declares
|
|
35
|
+
* must not depend on its passthrough data.
|
|
35
36
|
*/
|
|
36
37
|
export function nullFlattenedSerializerKeys(serializers, options = {}) {
|
|
37
38
|
return nullRequiredKeys(walkSerializers(serializers, newWalk(options)));
|
|
@@ -105,8 +106,8 @@ export function flattenedOpenapiVariants(openapi) {
|
|
|
105
106
|
const sharedMembers = ('allOf' in openapi && openapi.allOf) || [];
|
|
106
107
|
return sharedMembers.length ? variants.map(variant => ({ allOf: [...sharedMembers, variant] })) : variants;
|
|
107
108
|
}
|
|
108
|
-
function newWalk({ casing = 'camel'
|
|
109
|
-
return { casing,
|
|
109
|
+
function newWalk({ casing = 'camel' }) {
|
|
110
|
+
return { casing, serializersBeingFlattened: new Set() };
|
|
110
111
|
}
|
|
111
112
|
function nullRequiredKeys(requirements) {
|
|
112
113
|
return Object.keys(requirements).reduce((keys, key) => {
|
|
@@ -139,7 +140,7 @@ function walkSerializers(serializers, walk) {
|
|
|
139
140
|
if (walk.serializersBeingFlattened.has(serializer))
|
|
140
141
|
return flattenedKeys;
|
|
141
142
|
walk.serializersBeingFlattened.add(serializer);
|
|
142
|
-
const serializerBuilder = serializer(undefined,
|
|
143
|
+
const serializerBuilder = serializer(undefined, {});
|
|
143
144
|
const serializerKeys = walkSerializerBuilder(serializerBuilder, walk);
|
|
144
145
|
walk.serializersBeingFlattened.delete(serializer);
|
|
145
146
|
return mergeRequirements(flattenedKeys, serializerKeys);
|
|
@@ -159,25 +159,32 @@ export default class DreamApp {
|
|
|
159
159
|
private _packageManager;
|
|
160
160
|
get packageManager(): "pnpm" | "yarn" | "npm" | "bun" | "deno";
|
|
161
161
|
private _importExtension;
|
|
162
|
+
/**
|
|
163
|
+
* The import suffix the CLI generators write: `.js`, `.ts` or `none`.
|
|
164
|
+
*
|
|
165
|
+
* In a Psychic app, set it in conf/app.ts with
|
|
166
|
+
* `psy.set('importExtension', …)`. Psychic forwards it here, and a different
|
|
167
|
+
* value set in conf/dream.ts throws at boot. In a Dream-only app, set it in
|
|
168
|
+
* conf/dream.ts with `dreamApp.set('importExtension', …)`.
|
|
169
|
+
*
|
|
170
|
+
* Defaults to `.js`.
|
|
171
|
+
*/
|
|
162
172
|
get importExtension(): ".js" | ".ts" | "none";
|
|
163
173
|
private _importAliasPrefix;
|
|
164
174
|
/**
|
|
165
175
|
* The prefix of the import aliases the CLI generators write: the `@` in
|
|
166
176
|
* `@models/User.js`, `@serializers/UserSerializer.js` and
|
|
167
|
-
* `@spec/factories/UserFactory.js`. Set
|
|
168
|
-
* `dreamApp.set('importAliasPrefix', '#')` to have them write
|
|
177
|
+
* `@spec/factories/UserFactory.js`. Set it to `#` to have them write
|
|
169
178
|
* `#models/User.js` and so on, which Node resolves as subpath imports
|
|
170
179
|
* declared under `imports` in the app's package.json.
|
|
171
180
|
*
|
|
181
|
+
* In a Psychic app, set it in conf/app.ts with
|
|
182
|
+
* `psy.set('importAliasPrefix', '#')`. Psychic forwards it here, and a
|
|
183
|
+
* different value set in conf/dream.ts throws at boot. In a Dream-only app,
|
|
184
|
+
* set it in conf/dream.ts with `dreamApp.set('importAliasPrefix', '#')`.
|
|
185
|
+
*
|
|
172
186
|
* Defaults to `@`. The default becomes `#` in Dream 3; an app that wants
|
|
173
|
-
* to keep `@` should set it explicitly
|
|
174
|
-
* `dreamApp.set('importAliasPrefix', '@')`.
|
|
175
|
-
*
|
|
176
|
-
* Psychic's resource controller-spec generator still writes its
|
|
177
|
-
* `@spec/unit/helpers/authentication.js` import with a literal `@` until
|
|
178
|
-
* Psychic reads this setting (planned for 3.17.0), so a Psychic app should
|
|
179
|
-
* keep its `@spec` alias, or wait for that release, before switching to
|
|
180
|
-
* `#` only.
|
|
187
|
+
* to keep `@` should set it to `@` explicitly.
|
|
181
188
|
*/
|
|
182
189
|
get importAliasPrefix(): "@" | "#";
|
|
183
190
|
/**
|
|
@@ -9,18 +9,24 @@ import DreamSerializerBuilder from './builders/DreamSerializerBuilder.js';
|
|
|
9
9
|
* DreamSerializer(User, user).attribute('email').rendersMany('posts')
|
|
10
10
|
* ```
|
|
11
11
|
*
|
|
12
|
-
* A serializer must not read its data while being built: what it
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
12
|
+
* A serializer must not read its data or its passthrough data while being built: what it
|
|
13
|
+
* declares (which keys, under which names, and which associations it renders) may not
|
|
14
|
+
* depend on either. Dream and Psychic build it without data to read its shape (the OpenAPI
|
|
15
|
+
* schema, the associations `preloadFor` loads, and the keys a flattened association or
|
|
16
|
+
* `customAttribute` that uses it renders as `null` where its value does not supply them),
|
|
17
|
+
* and without passthrough data when registering it, preloading and generating OpenAPI. A
|
|
18
|
+
* serializer that reads its data while being built throws when a flattened association or
|
|
19
|
+
* `customAttribute` that uses it is rendered; one that reads its passthrough data is never
|
|
20
|
+
* registered, or renders keys and associations its OpenAPI schema and `preloadFor` do not
|
|
21
|
+
* describe. Read either inside a `customAttribute` callback, which runs only when the
|
|
22
|
+
* serializer renders, not while it is built, and hand passthrough data on to the
|
|
23
|
+
* serializers it renders.
|
|
19
24
|
*
|
|
20
25
|
* @param dreamClass - The Dream model class the serializer renders
|
|
21
26
|
* @param data - The Dream instance to render
|
|
22
|
-
* @param passthroughData - Data available to this serializer
|
|
23
|
-
* it renders
|
|
27
|
+
* @param passthroughData - Data available to this serializer's callbacks when it renders,
|
|
28
|
+
* and passed down to the serializers it renders. It must not decide what the serializer
|
|
29
|
+
* declares.
|
|
24
30
|
* @returns The serializer builder for method chaining
|
|
25
31
|
*/
|
|
26
32
|
export default function DreamSerializer<DreamClass extends typeof Dream, DataType extends Dream | null, PassthroughDataType extends object | undefined = undefined>(dreamClass: DreamClass, data: DataType, passthroughData?: PassthroughDataType): DreamSerializerBuilder<DreamClass, DataType, PassthroughDataType, Exclude<DataType, null>>;
|
|
@@ -8,17 +8,23 @@ import ObjectSerializerBuilder from './builders/ObjectSerializerBuilder.js';
|
|
|
8
8
|
* ObjectSerializer(address).attribute('city', { openapi: 'string' })
|
|
9
9
|
* ```
|
|
10
10
|
*
|
|
11
|
-
* A serializer must not read its data while being built: what it
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
11
|
+
* A serializer must not read its data or its passthrough data while being built: what it
|
|
12
|
+
* declares (which keys, under which names, and which associations it renders) may not
|
|
13
|
+
* depend on either. Dream and Psychic build it without data to read its shape (the OpenAPI
|
|
14
|
+
* schema, the associations `preloadFor` loads, and the keys a flattened association or
|
|
15
|
+
* `customAttribute` that uses it renders as `null` where its value does not supply them),
|
|
16
|
+
* and without passthrough data when registering it, preloading and generating OpenAPI. A
|
|
17
|
+
* serializer that reads its data while being built throws when a flattened association or
|
|
18
|
+
* `customAttribute` that uses it is rendered; one that reads its passthrough data is never
|
|
19
|
+
* registered, or renders keys and associations its OpenAPI schema and `preloadFor` do not
|
|
20
|
+
* describe. Read either inside a `customAttribute` callback, which runs only when the
|
|
21
|
+
* serializer renders, not while it is built, and hand passthrough data on to the
|
|
22
|
+
* serializers it renders.
|
|
18
23
|
*
|
|
19
24
|
* @param data - The object to render
|
|
20
|
-
* @param passthroughData - Data available to this serializer
|
|
21
|
-
* it renders
|
|
25
|
+
* @param passthroughData - Data available to this serializer's callbacks when it renders,
|
|
26
|
+
* and passed down to the serializers it renders. It must not decide what the serializer
|
|
27
|
+
* declares.
|
|
22
28
|
* @returns The serializer builder for method chaining
|
|
23
29
|
*/
|
|
24
30
|
export default function ObjectSerializer<DataType extends object | null, PassthroughDataType extends object | undefined = undefined>(data: DataType, passthroughData?: PassthroughDataType): ObjectSerializerBuilder<DataType, PassthroughDataType, Exclude<DataType, null>>;
|
|
@@ -2,7 +2,6 @@ import { OpenapiSchemaBodyShorthand, OpenapiShorthandPrimitiveTypes } from '../.
|
|
|
2
2
|
import { DreamModelSerializerType, SerializerCasing, SimpleObjectSerializerType } from '../../types/serializer.js';
|
|
3
3
|
export interface NullFlattenedSerializerKeysOptions {
|
|
4
4
|
casing?: SerializerCasing;
|
|
5
|
-
passthroughData?: object;
|
|
6
5
|
}
|
|
7
6
|
/**
|
|
8
7
|
* The keys a flattened `rendersOne` always adds to the parent's payload, returned as an object
|
|
@@ -32,8 +31,9 @@ export interface NullFlattenedSerializerKeysOptions {
|
|
|
32
31
|
* flattens itself, adds nothing, so the walk always terminates; one reached again along another
|
|
33
32
|
* path is walked again, so each path adds its keys and their requirements.
|
|
34
33
|
*
|
|
35
|
-
*
|
|
36
|
-
* render
|
|
34
|
+
* Each serializer is built with empty passthrough data, as Psychic's OpenAPI generation builds it,
|
|
35
|
+
* so the keys are the same whatever passthrough data a render carries: what a serializer declares
|
|
36
|
+
* must not depend on its passthrough data.
|
|
37
37
|
*/
|
|
38
38
|
export declare function nullFlattenedSerializerKeys(serializers: (DreamModelSerializerType | SimpleObjectSerializerType)[], options?: NullFlattenedSerializerKeysOptions): Record<string, null>;
|
|
39
39
|
/**
|