@rvoh/dream 2.9.1 → 2.10.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/QueryDriver/Kysely.js +7 -8
- package/dist/cjs/src/dream/QueryDriver/helpers/kysely/checkForNeedToBeRunMigrations.js +1 -1
- package/dist/cjs/src/dream/QueryDriver/helpers/kysely/runMigration.js +1 -1
- package/dist/cjs/src/dream-app/index.js +14 -6
- package/dist/cjs/src/errors/dream-app/MissingDbSslDirective.js +29 -0
- package/dist/cjs/src/helpers/comparisonKey.js +2 -0
- package/dist/esm/src/dream/QueryDriver/Kysely.js +7 -8
- package/dist/esm/src/dream/QueryDriver/helpers/kysely/checkForNeedToBeRunMigrations.js +1 -1
- package/dist/esm/src/dream/QueryDriver/helpers/kysely/runMigration.js +1 -1
- package/dist/esm/src/dream-app/index.js +14 -6
- package/dist/esm/src/errors/dream-app/MissingDbSslDirective.js +29 -0
- package/dist/esm/src/helpers/comparisonKey.js +2 -0
- package/dist/types/src/dream/QueryDriver/Kysely.d.ts +8 -9
- package/dist/types/src/dream-app/index.d.ts +23 -15
- package/dist/types/src/errors/dream-app/MissingDbSslDirective.d.ts +6 -0
- package/dist/types/src/helpers/comparisonKey.d.ts +1 -1
- package/docs/classes/db.DreamMigrationHelpers.html +9 -9
- package/docs/classes/db.KyselyQueryDriver.html +32 -32
- package/docs/classes/db.PostgresQueryDriver.html +33 -33
- package/docs/classes/db.QueryDriverBase.html +31 -31
- 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.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.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 +118 -118
- package/docs/classes/index.DreamApp.html +5 -5
- package/docs/classes/index.DreamTransaction.html +2 -2
- package/docs/classes/index.Env.html +2 -2
- package/docs/classes/index.Query.html +56 -56
- package/docs/classes/system.CliFileWriter.html +4 -4
- package/docs/classes/system.DreamBin.html +2 -2
- 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 +3 -3
- 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 +1 -1
- package/docs/functions/index.ObjectSerializer.html +1 -1
- 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.DreamAppInitOptions.html +2 -2
- package/docs/interfaces/types.DreamAppOpts.html +2 -2
- package/docs/interfaces/types.DurationObject.html +2 -2
- package/docs/interfaces/types.EncryptOptions.html +2 -2
- package/docs/interfaces/types.InternalAnyTypedSerializerRendersMany.html +2 -2
- package/docs/interfaces/types.InternalAnyTypedSerializerRendersOne.html +2 -2
- 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.OpenapiSchemaCommonFields.html +1 -1
- package/docs/types/openapi.OpenapiSchemaExpressionAllOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaExpressionAnyOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaExpressionOneOf.html +2 -2
- 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.OpenapiSchemaObjectAnyOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectAnyOfShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectBase.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectBaseShorthand.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectOneOf.html +1 -1
- package/docs/types/openapi.OpenapiSchemaObjectOneOfShorthand.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 +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionAnyOf.html +2 -2
- package/docs/types/openapi.OpenapiSchemaShorthandExpressionOneOf.html +2 -2
- 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.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 +5 -5
|
@@ -2047,15 +2047,14 @@ const associationStringToAssociationAndMaybeAlias = function ({ dreamClass, asso
|
|
|
2047
2047
|
* Resolve the value passed to `pg.Pool`'s `ssl` field for a given credential.
|
|
2048
2048
|
*
|
|
2049
2049
|
* Precedence:
|
|
2050
|
-
* 1. If `connectionConf.ssl` is set (
|
|
2051
|
-
*
|
|
2052
|
-
*
|
|
2053
|
-
* authenticated TLS against a private PKI, or `true` to use Node's
|
|
2054
|
-
* default verification against the system CA store.
|
|
2055
|
-
* 2. Else if `connectionConf.useSsl` is `true`, fall back to
|
|
2050
|
+
* 1. If `connectionConf.ssl` is set (object or explicit `false`), pass it
|
|
2051
|
+
* straight through to `pg`.
|
|
2052
|
+
* 2. Else if `connectionConf.useSsl` is `true` (deprecated), fall back to
|
|
2056
2053
|
* `{ rejectUnauthorized: false }` — encrypted but **not** authenticated.
|
|
2057
|
-
*
|
|
2058
|
-
*
|
|
2054
|
+
*
|
|
2055
|
+
* `assertDbCredentialTlsDirective` (in `dream-app`) throws at
|
|
2056
|
+
* `app.set('db', ...)` time when both `ssl` and `useSsl` are unset, so this
|
|
2057
|
+
* resolver never sees the "neither directive" state.
|
|
2059
2058
|
*/
|
|
2060
2059
|
export function resolvePostgresSsl(connectionConf) {
|
|
2061
2060
|
if (connectionConf.ssl !== undefined)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FileMigrationProvider, Migrator } from 'kysely';
|
|
1
|
+
import { FileMigrationProvider, Migrator } from 'kysely/migration';
|
|
2
2
|
import * as fs from 'node:fs/promises';
|
|
3
3
|
import { closeAllConnectionsForConnectionName } from '../../../../db/DreamDbConnection.js';
|
|
4
4
|
import db from '../../../../db/index.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FileMigrationProvider, Migrator } from 'kysely';
|
|
1
|
+
import { FileMigrationProvider, Migrator } from 'kysely/migration';
|
|
2
2
|
import * as fs from 'node:fs/promises';
|
|
3
3
|
import DreamCLI from '../../../../cli/index.js';
|
|
4
4
|
import colorize from '../../../../cli/logger/loggable/colorize.js';
|
|
@@ -6,6 +6,7 @@ import Encrypt from '../encrypt/index.js';
|
|
|
6
6
|
import DreamAppInitMissingCallToLoadModels from '../errors/dream-app/DreamAppInitMissingCallToLoadModels.js';
|
|
7
7
|
import DreamAppInitMissingMissingProjectRoot from '../errors/dream-app/DreamAppInitMissingMissingProjectRoot.js';
|
|
8
8
|
import DreamAppInitMissingPackageManager from '../errors/dream-app/DreamAppInitMissingPackageManager.js';
|
|
9
|
+
import MissingDbSslDirective from '../errors/dream-app/MissingDbSslDirective.js';
|
|
9
10
|
import autogeneratedFileDisclaimer from '../helpers/cli/autoGeneratedFileDisclaimer.js';
|
|
10
11
|
import modelClassNameFrom from '../helpers/cli/modelClassNameFrom.js';
|
|
11
12
|
import EnvInternal from '../helpers/EnvInternal.js';
|
|
@@ -345,14 +346,16 @@ A new key can also be generated from the CLI:
|
|
|
345
346
|
case 'bypassDeprecationChecks':
|
|
346
347
|
this._bypassDeprecationChecks = options;
|
|
347
348
|
break;
|
|
348
|
-
case 'db':
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
349
|
+
case 'db': {
|
|
350
|
+
const connectionName = typeof options === 'string' ? options : 'default';
|
|
351
|
+
const credentialOptions = (typeof options === 'string' ? secondaryOptions : options);
|
|
352
|
+
assertDbCredentialTlsDirective(credentialOptions.primary, connectionName, 'primary');
|
|
353
|
+
if (credentialOptions.replica) {
|
|
354
|
+
assertDbCredentialTlsDirective(credentialOptions.replica, connectionName, 'replica');
|
|
354
355
|
}
|
|
356
|
+
this._dbCredentials[connectionName] = credentialOptions;
|
|
355
357
|
break;
|
|
358
|
+
}
|
|
356
359
|
case 'encryption':
|
|
357
360
|
this._encryption = options;
|
|
358
361
|
break;
|
|
@@ -412,6 +415,11 @@ A new key can also be generated from the CLI:
|
|
|
412
415
|
}
|
|
413
416
|
}
|
|
414
417
|
}
|
|
418
|
+
function assertDbCredentialTlsDirective(credential, connectionName, credentialKey) {
|
|
419
|
+
if (credential.ssl === undefined && !credential.useSsl) {
|
|
420
|
+
throw new MissingDbSslDirective(connectionName, credentialKey);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
415
423
|
function loggerArgToString(arg) {
|
|
416
424
|
if (typeof arg === 'string')
|
|
417
425
|
return arg;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export default class MissingDbSslDirective extends Error {
|
|
2
|
+
connectionName;
|
|
3
|
+
credentialKey;
|
|
4
|
+
constructor(connectionName, credentialKey) {
|
|
5
|
+
super();
|
|
6
|
+
this.connectionName = connectionName;
|
|
7
|
+
this.credentialKey = credentialKey;
|
|
8
|
+
}
|
|
9
|
+
get message() {
|
|
10
|
+
return `
|
|
11
|
+
DreamApp refused to register a db credential without an explicit TLS
|
|
12
|
+
directive. Every \`SingleDbCredential\` passed to \`app.set('db', ...)\`
|
|
13
|
+
must set one of:
|
|
14
|
+
|
|
15
|
+
ssl: { rejectUnauthorized: true } // verified TLS (system CA)
|
|
16
|
+
ssl: { rejectUnauthorized: true, ca: <pem> } // verified TLS (private CA)
|
|
17
|
+
ssl: { rejectUnauthorized: false } // unverified TLS
|
|
18
|
+
ssl: false // TLS disabled
|
|
19
|
+
useSsl: true // legacy, deprecated
|
|
20
|
+
|
|
21
|
+
Omitting the directive used to silently disable TLS. Throwing here
|
|
22
|
+
turns the safety question into a deliberate decision at the call
|
|
23
|
+
site, so a credential cannot reach production with TLS off by accident.
|
|
24
|
+
|
|
25
|
+
connection: ${this.connectionName}
|
|
26
|
+
credential: ${this.credentialKey}
|
|
27
|
+
`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -2047,15 +2047,14 @@ const associationStringToAssociationAndMaybeAlias = function ({ dreamClass, asso
|
|
|
2047
2047
|
* Resolve the value passed to `pg.Pool`'s `ssl` field for a given credential.
|
|
2048
2048
|
*
|
|
2049
2049
|
* Precedence:
|
|
2050
|
-
* 1. If `connectionConf.ssl` is set (
|
|
2051
|
-
*
|
|
2052
|
-
*
|
|
2053
|
-
* authenticated TLS against a private PKI, or `true` to use Node's
|
|
2054
|
-
* default verification against the system CA store.
|
|
2055
|
-
* 2. Else if `connectionConf.useSsl` is `true`, fall back to
|
|
2050
|
+
* 1. If `connectionConf.ssl` is set (object or explicit `false`), pass it
|
|
2051
|
+
* straight through to `pg`.
|
|
2052
|
+
* 2. Else if `connectionConf.useSsl` is `true` (deprecated), fall back to
|
|
2056
2053
|
* `{ rejectUnauthorized: false }` — encrypted but **not** authenticated.
|
|
2057
|
-
*
|
|
2058
|
-
*
|
|
2054
|
+
*
|
|
2055
|
+
* `assertDbCredentialTlsDirective` (in `dream-app`) throws at
|
|
2056
|
+
* `app.set('db', ...)` time when both `ssl` and `useSsl` are unset, so this
|
|
2057
|
+
* resolver never sees the "neither directive" state.
|
|
2059
2058
|
*/
|
|
2060
2059
|
export function resolvePostgresSsl(connectionConf) {
|
|
2061
2060
|
if (connectionConf.ssl !== undefined)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FileMigrationProvider, Migrator } from 'kysely';
|
|
1
|
+
import { FileMigrationProvider, Migrator } from 'kysely/migration';
|
|
2
2
|
import * as fs from 'node:fs/promises';
|
|
3
3
|
import { closeAllConnectionsForConnectionName } from '../../../../db/DreamDbConnection.js';
|
|
4
4
|
import db from '../../../../db/index.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FileMigrationProvider, Migrator } from 'kysely';
|
|
1
|
+
import { FileMigrationProvider, Migrator } from 'kysely/migration';
|
|
2
2
|
import * as fs from 'node:fs/promises';
|
|
3
3
|
import DreamCLI from '../../../../cli/index.js';
|
|
4
4
|
import colorize from '../../../../cli/logger/loggable/colorize.js';
|
|
@@ -6,6 +6,7 @@ import Encrypt from '../encrypt/index.js';
|
|
|
6
6
|
import DreamAppInitMissingCallToLoadModels from '../errors/dream-app/DreamAppInitMissingCallToLoadModels.js';
|
|
7
7
|
import DreamAppInitMissingMissingProjectRoot from '../errors/dream-app/DreamAppInitMissingMissingProjectRoot.js';
|
|
8
8
|
import DreamAppInitMissingPackageManager from '../errors/dream-app/DreamAppInitMissingPackageManager.js';
|
|
9
|
+
import MissingDbSslDirective from '../errors/dream-app/MissingDbSslDirective.js';
|
|
9
10
|
import autogeneratedFileDisclaimer from '../helpers/cli/autoGeneratedFileDisclaimer.js';
|
|
10
11
|
import modelClassNameFrom from '../helpers/cli/modelClassNameFrom.js';
|
|
11
12
|
import EnvInternal from '../helpers/EnvInternal.js';
|
|
@@ -345,14 +346,16 @@ A new key can also be generated from the CLI:
|
|
|
345
346
|
case 'bypassDeprecationChecks':
|
|
346
347
|
this._bypassDeprecationChecks = options;
|
|
347
348
|
break;
|
|
348
|
-
case 'db':
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
349
|
+
case 'db': {
|
|
350
|
+
const connectionName = typeof options === 'string' ? options : 'default';
|
|
351
|
+
const credentialOptions = (typeof options === 'string' ? secondaryOptions : options);
|
|
352
|
+
assertDbCredentialTlsDirective(credentialOptions.primary, connectionName, 'primary');
|
|
353
|
+
if (credentialOptions.replica) {
|
|
354
|
+
assertDbCredentialTlsDirective(credentialOptions.replica, connectionName, 'replica');
|
|
354
355
|
}
|
|
356
|
+
this._dbCredentials[connectionName] = credentialOptions;
|
|
355
357
|
break;
|
|
358
|
+
}
|
|
356
359
|
case 'encryption':
|
|
357
360
|
this._encryption = options;
|
|
358
361
|
break;
|
|
@@ -412,6 +415,11 @@ A new key can also be generated from the CLI:
|
|
|
412
415
|
}
|
|
413
416
|
}
|
|
414
417
|
}
|
|
418
|
+
function assertDbCredentialTlsDirective(credential, connectionName, credentialKey) {
|
|
419
|
+
if (credential.ssl === undefined && !credential.useSsl) {
|
|
420
|
+
throw new MissingDbSslDirective(connectionName, credentialKey);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
415
423
|
function loggerArgToString(arg) {
|
|
416
424
|
if (typeof arg === 'string')
|
|
417
425
|
return arg;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export default class MissingDbSslDirective extends Error {
|
|
2
|
+
connectionName;
|
|
3
|
+
credentialKey;
|
|
4
|
+
constructor(connectionName, credentialKey) {
|
|
5
|
+
super();
|
|
6
|
+
this.connectionName = connectionName;
|
|
7
|
+
this.credentialKey = credentialKey;
|
|
8
|
+
}
|
|
9
|
+
get message() {
|
|
10
|
+
return `
|
|
11
|
+
DreamApp refused to register a db credential without an explicit TLS
|
|
12
|
+
directive. Every \`SingleDbCredential\` passed to \`app.set('db', ...)\`
|
|
13
|
+
must set one of:
|
|
14
|
+
|
|
15
|
+
ssl: { rejectUnauthorized: true } // verified TLS (system CA)
|
|
16
|
+
ssl: { rejectUnauthorized: true, ca: <pem> } // verified TLS (private CA)
|
|
17
|
+
ssl: { rejectUnauthorized: false } // unverified TLS
|
|
18
|
+
ssl: false // TLS disabled
|
|
19
|
+
useSsl: true // legacy, deprecated
|
|
20
|
+
|
|
21
|
+
Omitting the directive used to silently disable TLS. Throwing here
|
|
22
|
+
turns the safety question into a deliberate decision at the call
|
|
23
|
+
site, so a credential cannot reach production with TLS off by accident.
|
|
24
|
+
|
|
25
|
+
connection: ${this.connectionName}
|
|
26
|
+
credential: ${this.credentialKey}
|
|
27
|
+
`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -473,14 +473,13 @@ export default class KyselyQueryDriver<DreamInstance extends Dream> extends Quer
|
|
|
473
473
|
* Resolve the value passed to `pg.Pool`'s `ssl` field for a given credential.
|
|
474
474
|
*
|
|
475
475
|
* Precedence:
|
|
476
|
-
* 1. If `connectionConf.ssl` is set (
|
|
477
|
-
*
|
|
478
|
-
*
|
|
479
|
-
* authenticated TLS against a private PKI, or `true` to use Node's
|
|
480
|
-
* default verification against the system CA store.
|
|
481
|
-
* 2. Else if `connectionConf.useSsl` is `true`, fall back to
|
|
476
|
+
* 1. If `connectionConf.ssl` is set (object or explicit `false`), pass it
|
|
477
|
+
* straight through to `pg`.
|
|
478
|
+
* 2. Else if `connectionConf.useSsl` is `true` (deprecated), fall back to
|
|
482
479
|
* `{ rejectUnauthorized: false }` — encrypted but **not** authenticated.
|
|
483
|
-
*
|
|
484
|
-
*
|
|
480
|
+
*
|
|
481
|
+
* `assertDbCredentialTlsDirective` (in `dream-app`) throws at
|
|
482
|
+
* `app.set('db', ...)` time when both `ssl` and `useSsl` are unset, so this
|
|
483
|
+
* resolver never sees the "neither directive" state.
|
|
485
484
|
*/
|
|
486
|
-
export declare function resolvePostgresSsl(connectionConf: SingleDbCredential):
|
|
485
|
+
export declare function resolvePostgresSsl(connectionConf: SingleDbCredential): TlsConnectionOptions | false;
|
|
@@ -213,27 +213,35 @@ export interface SingleDbCredential {
|
|
|
213
213
|
/**
|
|
214
214
|
* @deprecated Use `ssl` instead.
|
|
215
215
|
*
|
|
216
|
-
*
|
|
216
|
+
* Legacy boolean opt-in for Postgres TLS. When `true` (and `ssl` is not
|
|
217
217
|
* set), Dream connects with `{ rejectUnauthorized: false }` — TLS is on but
|
|
218
|
-
* the server certificate is not verified.
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
* Node's defaults (`ssl: true`). This field is preserved for back-compat
|
|
222
|
-
* and will be removed in a future major version.
|
|
218
|
+
* the server certificate is not verified. Preserved for back-compat and
|
|
219
|
+
* will be removed in a future major version. New code should set `ssl`
|
|
220
|
+
* directly.
|
|
223
221
|
*/
|
|
224
222
|
useSsl?: boolean;
|
|
225
223
|
/**
|
|
226
|
-
*
|
|
227
|
-
*
|
|
224
|
+
* TLS configuration passed straight through to `pg.Pool`'s `ssl` field.
|
|
225
|
+
* Takes precedence over the deprecated `useSsl` when provided.
|
|
228
226
|
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
227
|
+
* Set `rejectUnauthorized: true` (Node's own default) for verified TLS
|
|
228
|
+
* against the system CA store — the right choice for managed providers that
|
|
229
|
+
* present a public-CA-signed certificate (Supabase, Neon, Render, Azure
|
|
230
|
+
* Database for PostgreSQL on Flexible Server, etc.).
|
|
231
|
+
*
|
|
232
|
+
* For providers that present a private-CA certificate (AWS RDS,
|
|
233
|
+
* GCP Cloud SQL), add a `ca` bundle:
|
|
234
|
+
* `ssl: { rejectUnauthorized: true, ca: readFileSync('rds-ca.pem') }`.
|
|
235
|
+
*
|
|
236
|
+
* For providers that present a self-signed certificate (Heroku Hobby,
|
|
237
|
+
* some local docker images), set `rejectUnauthorized: false` — encrypted
|
|
238
|
+
* but unauthenticated.
|
|
239
|
+
*
|
|
240
|
+
* Set `false` to disable TLS entirely. Omitting `ssl` (and `useSsl`) throws
|
|
241
|
+
* at `app.set('db', ...)` time so the safety question is a deliberate
|
|
242
|
+
* decision at the call site rather than a silent default.
|
|
235
243
|
*/
|
|
236
|
-
ssl?:
|
|
244
|
+
ssl?: TlsConnectionOptions | false;
|
|
237
245
|
}
|
|
238
246
|
export type DreamLogger = {
|
|
239
247
|
info: (...args: any[]) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function comparisonKey<ElementType>(val: ElementType, toKey?: ((a: ElementType) => string | number | bigint) | undefined): number | string | bigint | null | undefined;
|
|
1
|
+
export default function comparisonKey<ElementType>(val: ElementType, toKey?: ((a: ElementType) => string | number | bigint) | undefined): number | string | bigint | null | undefined | ((...args: any[]) => any);
|